translate.c 187.0 KB
Newer Older
1 2 3 4
/*
   SPARC translation

   Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
B
bellard 已提交
5
   Copyright (C) 2003-2005 Fabrice Bellard
6 7 8 9 10 11 12 13 14 15 16 17 18

   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
19
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 USA
20 21 22 23 24 25 26 27 28 29 30
 */

#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#include "cpu.h"
#include "exec-all.h"
#include "disas.h"
B
blueswir1 已提交
31
#include "helper.h"
B
bellard 已提交
32
#include "tcg-op.h"
33

P
pbrook 已提交
34 35 36
#define GEN_HELPER 1
#include "helper.h"

37 38
#define DEBUG_DISAS

B
bellard 已提交
39 40 41 42
#define DYNAMIC_PC  1 /* dynamic pc value */
#define JUMP_PC     2 /* dynamic pc value which takes only two values
                         according to jump_pc[T2] */

B
blueswir1 已提交
43
/* global register indexes */
P
pbrook 已提交
44
static TCGv_ptr cpu_env, cpu_regwptr;
B
blueswir1 已提交
45
static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
P
pbrook 已提交
46 47
static TCGv_i32 cpu_psr;
static TCGv cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8];
48 49 50 51
static TCGv cpu_y;
#ifndef CONFIG_USER_ONLY
static TCGv cpu_tbr;
#endif
52
static TCGv cpu_cond, cpu_src1, cpu_src2, cpu_dst, cpu_addr, cpu_val;
53
#ifdef TARGET_SPARC64
P
pbrook 已提交
54 55
static TCGv_i32 cpu_xcc, cpu_asi, cpu_fprs;
static TCGv cpu_gsr;
56
static TCGv cpu_tick_cmpr, cpu_stick_cmpr, cpu_hstick_cmpr;
P
pbrook 已提交
57 58
static TCGv cpu_hintp, cpu_htba, cpu_hver, cpu_ssr, cpu_ver;
static TCGv_i32 cpu_softint;
59 60
#else
static TCGv cpu_wim;
61
#endif
B
blueswir1 已提交
62
/* local register indexes (only used inside old micro ops) */
P
pbrook 已提交
63 64 65
static TCGv cpu_tmp0;
static TCGv_i32 cpu_tmp32;
static TCGv_i64 cpu_tmp64;
B
blueswir1 已提交
66
/* Floating point registers */
P
pbrook 已提交
67
static TCGv_i32 cpu_fpr[TARGET_FPREGS];
B
blueswir1 已提交
68

P
pbrook 已提交
69 70
#include "gen-icount.h"

71
typedef struct DisasContext {
B
blueswir1 已提交
72 73
    target_ulong pc;    /* current Program Counter: integer or DYNAMIC_PC */
    target_ulong npc;   /* next PC: integer or DYNAMIC_PC or JUMP_PC */
B
bellard 已提交
74
    target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
75
    int is_br;
76
    int mem_idx;
B
bellard 已提交
77
    int fpu_enabled;
B
blueswir1 已提交
78
    int address_mask_32bit;
79
    struct TranslationBlock *tb;
80
    sparc_def_t *def;
81 82
} DisasContext;

B
bellard 已提交
83
// This function uses non-native bit order
84 85 86
#define GET_FIELD(X, FROM, TO) \
  ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))

B
bellard 已提交
87 88 89 90 91
// This function uses the order in the manuals, i.e. bit 0 is 2^0
#define GET_FIELD_SP(X, FROM, TO) \
    GET_FIELD(X, 31 - (TO), 31 - (FROM))

#define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
B
blueswir1 已提交
92
#define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
B
bellard 已提交
93 94

#ifdef TARGET_SPARC64
95
#define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
B
blueswir1 已提交
96
#define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
B
bellard 已提交
97
#else
98
#define DFPREG(r) (r & 0x1e)
B
blueswir1 已提交
99
#define QFPREG(r) (r & 0x1c)
B
bellard 已提交
100 101
#endif

B
blueswir1 已提交
102 103 104
#define UA2005_HTRAP_MASK 0xff
#define V8_TRAP_MASK 0x7f

B
bellard 已提交
105 106 107 108 109 110
static int sign_extend(int x, int len)
{
    len = 32 - len;
    return (x << len) >> len;
}

111 112
#define IS_IMM (insn & (1<<13))

B
blueswir1 已提交
113 114 115
/* floating point registers moves */
static void gen_op_load_fpr_DT0(unsigned int src)
{
B
blueswir1 已提交
116
    tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, dt0) +
B
blueswir1 已提交
117
                   offsetof(CPU_DoubleU, l.upper));
B
blueswir1 已提交
118
    tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, dt0) +
B
blueswir1 已提交
119
                   offsetof(CPU_DoubleU, l.lower));
B
blueswir1 已提交
120 121 122 123
}

static void gen_op_load_fpr_DT1(unsigned int src)
{
B
blueswir1 已提交
124
    tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, dt1) +
B
blueswir1 已提交
125
                   offsetof(CPU_DoubleU, l.upper));
B
blueswir1 已提交
126
    tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, dt1) +
B
blueswir1 已提交
127
                   offsetof(CPU_DoubleU, l.lower));
B
blueswir1 已提交
128 129 130 131
}

static void gen_op_store_DT0_fpr(unsigned int dst)
{
B
blueswir1 已提交
132
    tcg_gen_ld_i32(cpu_fpr[dst], cpu_env, offsetof(CPUSPARCState, dt0) +
B
blueswir1 已提交
133
                   offsetof(CPU_DoubleU, l.upper));
B
blueswir1 已提交
134
    tcg_gen_ld_i32(cpu_fpr[dst + 1], cpu_env, offsetof(CPUSPARCState, dt0) +
B
blueswir1 已提交
135
                   offsetof(CPU_DoubleU, l.lower));
B
blueswir1 已提交
136 137 138 139
}

static void gen_op_load_fpr_QT0(unsigned int src)
{
B
blueswir1 已提交
140
    tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
141
                   offsetof(CPU_QuadU, l.upmost));
B
blueswir1 已提交
142
    tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
143
                   offsetof(CPU_QuadU, l.upper));
B
blueswir1 已提交
144
    tcg_gen_st_i32(cpu_fpr[src + 2], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
145
                   offsetof(CPU_QuadU, l.lower));
B
blueswir1 已提交
146
    tcg_gen_st_i32(cpu_fpr[src + 3], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
147
                   offsetof(CPU_QuadU, l.lowest));
B
blueswir1 已提交
148 149 150 151
}

static void gen_op_load_fpr_QT1(unsigned int src)
{
B
blueswir1 已提交
152
    tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, qt1) +
B
blueswir1 已提交
153
                   offsetof(CPU_QuadU, l.upmost));
B
blueswir1 已提交
154
    tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, qt1) +
B
blueswir1 已提交
155
                   offsetof(CPU_QuadU, l.upper));
B
blueswir1 已提交
156
    tcg_gen_st_i32(cpu_fpr[src + 2], cpu_env, offsetof(CPUSPARCState, qt1) +
B
blueswir1 已提交
157
                   offsetof(CPU_QuadU, l.lower));
B
blueswir1 已提交
158
    tcg_gen_st_i32(cpu_fpr[src + 3], cpu_env, offsetof(CPUSPARCState, qt1) +
B
blueswir1 已提交
159
                   offsetof(CPU_QuadU, l.lowest));
B
blueswir1 已提交
160 161 162 163
}

static void gen_op_store_QT0_fpr(unsigned int dst)
{
B
blueswir1 已提交
164
    tcg_gen_ld_i32(cpu_fpr[dst], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
165
                   offsetof(CPU_QuadU, l.upmost));
B
blueswir1 已提交
166
    tcg_gen_ld_i32(cpu_fpr[dst + 1], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
167
                   offsetof(CPU_QuadU, l.upper));
B
blueswir1 已提交
168
    tcg_gen_ld_i32(cpu_fpr[dst + 2], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
169
                   offsetof(CPU_QuadU, l.lower));
B
blueswir1 已提交
170
    tcg_gen_ld_i32(cpu_fpr[dst + 3], cpu_env, offsetof(CPUSPARCState, qt0) +
B
blueswir1 已提交
171
                   offsetof(CPU_QuadU, l.lowest));
B
blueswir1 已提交
172
}
B
blueswir1 已提交
173

174 175
/* moves */
#ifdef CONFIG_USER_ONLY
B
bellard 已提交
176
#define supervisor(dc) 0
177
#ifdef TARGET_SPARC64
B
blueswir1 已提交
178
#define hypervisor(dc) 0
179
#endif
B
bellard 已提交
180
#else
B
blueswir1 已提交
181
#define supervisor(dc) (dc->mem_idx >= 1)
182 183
#ifdef TARGET_SPARC64
#define hypervisor(dc) (dc->mem_idx == 2)
B
blueswir1 已提交
184
#else
B
bellard 已提交
185
#endif
186 187
#endif

B
blueswir1 已提交
188 189 190
#ifdef TARGET_SPARC64
#ifndef TARGET_ABI32
#define AM_CHECK(dc) ((dc)->address_mask_32bit)
B
blueswir1 已提交
191
#else
B
blueswir1 已提交
192 193
#define AM_CHECK(dc) (1)
#endif
B
blueswir1 已提交
194
#endif
195

B
blueswir1 已提交
196 197 198 199 200 201 202 203
static inline void gen_address_mask(DisasContext *dc, TCGv addr)
{
#ifdef TARGET_SPARC64
    if (AM_CHECK(dc))
        tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
#endif
}

B
blueswir1 已提交
204
static inline void gen_movl_reg_TN(int reg, TCGv tn)
205
{
B
blueswir1 已提交
206 207 208
    if (reg == 0)
        tcg_gen_movi_tl(tn, 0);
    else if (reg < 8)
B
blueswir1 已提交
209
        tcg_gen_mov_tl(tn, cpu_gregs[reg]);
B
blueswir1 已提交
210 211
    else {
        tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
212 213 214
    }
}

B
blueswir1 已提交
215
static inline void gen_movl_TN_reg(int reg, TCGv tn)
216
{
B
blueswir1 已提交
217 218 219
    if (reg == 0)
        return;
    else if (reg < 8)
B
blueswir1 已提交
220
        tcg_gen_mov_tl(cpu_gregs[reg], tn);
B
blueswir1 已提交
221 222
    else {
        tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
223 224 225
    }
}

226
static inline void gen_goto_tb(DisasContext *s, int tb_num,
227 228 229 230 231 232 233 234
                               target_ulong pc, target_ulong npc)
{
    TranslationBlock *tb;

    tb = s->tb;
    if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
        (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK))  {
        /* jump to same page: we can use a direct jump */
B
bellard 已提交
235
        tcg_gen_goto_tb(tb_num);
B
blueswir1 已提交
236 237
        tcg_gen_movi_tl(cpu_pc, pc);
        tcg_gen_movi_tl(cpu_npc, npc);
B
bellard 已提交
238
        tcg_gen_exit_tb((long)tb + tb_num);
239 240
    } else {
        /* jump to another page: currently not optimized */
B
blueswir1 已提交
241 242
        tcg_gen_movi_tl(cpu_pc, pc);
        tcg_gen_movi_tl(cpu_npc, npc);
B
bellard 已提交
243
        tcg_gen_exit_tb(0);
244 245 246
    }
}

247
// XXX suboptimal
P
pbrook 已提交
248
static inline void gen_mov_reg_N(TCGv reg, TCGv_i32 src)
249
{
B
blueswir1 已提交
250
    tcg_gen_extu_i32_tl(reg, src);
B
blueswir1 已提交
251
    tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
252 253 254
    tcg_gen_andi_tl(reg, reg, 0x1);
}

P
pbrook 已提交
255
static inline void gen_mov_reg_Z(TCGv reg, TCGv_i32 src)
256
{
B
blueswir1 已提交
257
    tcg_gen_extu_i32_tl(reg, src);
B
blueswir1 已提交
258
    tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
259 260 261
    tcg_gen_andi_tl(reg, reg, 0x1);
}

P
pbrook 已提交
262
static inline void gen_mov_reg_V(TCGv reg, TCGv_i32 src)
263
{
B
blueswir1 已提交
264
    tcg_gen_extu_i32_tl(reg, src);
B
blueswir1 已提交
265
    tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
266 267 268
    tcg_gen_andi_tl(reg, reg, 0x1);
}

P
pbrook 已提交
269
static inline void gen_mov_reg_C(TCGv reg, TCGv_i32 src)
270
{
B
blueswir1 已提交
271
    tcg_gen_extu_i32_tl(reg, src);
B
blueswir1 已提交
272
    tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
273 274 275
    tcg_gen_andi_tl(reg, reg, 0x1);
}

276
static inline void gen_cc_clear_icc(void)
277 278
{
    tcg_gen_movi_i32(cpu_psr, 0);
279 280
}

281
#ifdef TARGET_SPARC64
282 283
static inline void gen_cc_clear_xcc(void)
{
284 285
    tcg_gen_movi_i32(cpu_xcc, 0);
}
286
#endif
287 288 289 290 291 292 293

/* old op:
    if (!T0)
        env->psr |= PSR_ZERO;
    if ((int32_t) T0 < 0)
        env->psr |= PSR_NEG;
*/
294
static inline void gen_cc_NZ_icc(TCGv dst)
295
{
B
blueswir1 已提交
296
    TCGv r_temp;
297 298 299 300
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
P
pbrook 已提交
301
    r_temp = tcg_temp_new();
B
blueswir1 已提交
302
    tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
P
pbrook 已提交
303
    tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
304 305
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
    gen_set_label(l1);
B
blueswir1 已提交
306
    tcg_gen_ext32s_tl(r_temp, dst);
P
pbrook 已提交
307
    tcg_gen_brcondi_tl(TCG_COND_GE, r_temp, 0, l2);
308 309
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
    gen_set_label(l2);
B
blueswir1 已提交
310
    tcg_temp_free(r_temp);
311 312
}

313
#ifdef TARGET_SPARC64
314 315 316 317 318 319
static inline void gen_cc_NZ_xcc(TCGv dst)
{
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
P
pbrook 已提交
320
    tcg_gen_brcondi_tl(TCG_COND_NE, dst, 0, l1);
321 322
    tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
    gen_set_label(l1);
P
pbrook 已提交
323
    tcg_gen_brcondi_tl(TCG_COND_GE, dst, 0, l2);
324 325
    tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
    gen_set_label(l2);
326
}
327
#endif
328 329 330 331 332

/* old op:
    if (T0 < src1)
        env->psr |= PSR_CARRY;
*/
333
static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
334
{
335
    TCGv r_temp1, r_temp2;
336 337 338
    int l1;

    l1 = gen_new_label();
P
pbrook 已提交
339 340
    r_temp1 = tcg_temp_new();
    r_temp2 = tcg_temp_new();
341 342 343
    tcg_gen_andi_tl(r_temp1, dst, 0xffffffffULL);
    tcg_gen_andi_tl(r_temp2, src1, 0xffffffffULL);
    tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
344 345
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
    gen_set_label(l1);
346 347
    tcg_temp_free(r_temp1);
    tcg_temp_free(r_temp2);
348 349
}

350
#ifdef TARGET_SPARC64
351 352 353
static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
{
    int l1;
354

355 356 357 358
    l1 = gen_new_label();
    tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
    tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
    gen_set_label(l1);
359
}
360
#endif
361 362 363 364 365

/* old op:
    if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
        env->psr |= PSR_OVF;
*/
366
static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
367
{
368
    TCGv r_temp;
369

P
pbrook 已提交
370
    r_temp = tcg_temp_new();
371
    tcg_gen_xor_tl(r_temp, src1, src2);
B
blueswir1 已提交
372
    tcg_gen_not_tl(r_temp, r_temp);
373 374
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
375
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
B
blueswir1 已提交
376 377
    tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
    tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
B
blueswir1 已提交
378
    tcg_temp_free(r_temp);
B
blueswir1 已提交
379
    tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
380 381
}

382
#ifdef TARGET_SPARC64
383 384 385 386
static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
{
    TCGv r_temp;

P
pbrook 已提交
387
    r_temp = tcg_temp_new();
388
    tcg_gen_xor_tl(r_temp, src1, src2);
B
blueswir1 已提交
389
    tcg_gen_not_tl(r_temp, r_temp);
390 391 392
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
B
blueswir1 已提交
393 394
    tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
    tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
B
blueswir1 已提交
395
    tcg_temp_free(r_temp);
B
blueswir1 已提交
396
    tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
397
}
398
#endif
399 400 401

static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
{
P
pbrook 已提交
402 403
    TCGv r_temp;
    TCGv_i32 r_const;
404 405 406 407
    int l1;

    l1 = gen_new_label();

P
pbrook 已提交
408
    r_temp = tcg_temp_new();
409
    tcg_gen_xor_tl(r_temp, src1, src2);
B
blueswir1 已提交
410
    tcg_gen_not_tl(r_temp, r_temp);
411 412
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
413
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
P
pbrook 已提交
414
    tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
B
blueswir1 已提交
415
    r_const = tcg_const_i32(TT_TOVF);
P
pbrook 已提交
416 417
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
418
    gen_set_label(l1);
B
blueswir1 已提交
419
    tcg_temp_free(r_temp);
420 421 422 423 424 425 426
}

static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
{
    int l1;

    l1 = gen_new_label();
427 428
    tcg_gen_or_tl(cpu_tmp0, src1, src2);
    tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
P
pbrook 已提交
429
    tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
430 431 432 433 434 435 436
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
    gen_set_label(l1);
}

static inline void gen_tag_tv(TCGv src1, TCGv src2)
{
    int l1;
P
pbrook 已提交
437
    TCGv_i32 r_const;
438 439

    l1 = gen_new_label();
440 441
    tcg_gen_or_tl(cpu_tmp0, src1, src2);
    tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
P
pbrook 已提交
442
    tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
B
blueswir1 已提交
443
    r_const = tcg_const_i32(TT_TOVF);
P
pbrook 已提交
444 445
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
446 447 448
    gen_set_label(l1);
}

449
static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
450
{
451
    tcg_gen_mov_tl(cpu_cc_src, src1);
452
    tcg_gen_mov_tl(cpu_cc_src2, src2);
453
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
454
    gen_cc_clear_icc();
455 456 457
    gen_cc_NZ_icc(cpu_cc_dst);
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
458 459
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
460 461 462
    gen_cc_NZ_xcc(cpu_cc_dst);
    gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
463
#endif
464
    tcg_gen_mov_tl(dst, cpu_cc_dst);
465 466
}

467
static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
468
{
469
    tcg_gen_mov_tl(cpu_cc_src, src1);
470
    tcg_gen_mov_tl(cpu_cc_src2, src2);
471
    gen_mov_reg_C(cpu_tmp0, cpu_psr);
472
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
473
    gen_cc_clear_icc();
474
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
475 476
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
477
    gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
478
#endif
479
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
480 481 482
    gen_cc_NZ_icc(cpu_cc_dst);
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
483
#ifdef TARGET_SPARC64
484 485 486
    gen_cc_NZ_xcc(cpu_cc_dst);
    gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
487
#endif
488
    tcg_gen_mov_tl(dst, cpu_cc_dst);
489 490
}

491
static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
492
{
493
    tcg_gen_mov_tl(cpu_cc_src, src1);
494
    tcg_gen_mov_tl(cpu_cc_src2, src2);
495
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
496
    gen_cc_clear_icc();
497 498 499
    gen_cc_NZ_icc(cpu_cc_dst);
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
500
    gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
501 502
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
503 504 505
    gen_cc_NZ_xcc(cpu_cc_dst);
    gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
506
#endif
507
    tcg_gen_mov_tl(dst, cpu_cc_dst);
508 509
}

510
static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
511
{
512
    tcg_gen_mov_tl(cpu_cc_src, src1);
513 514
    tcg_gen_mov_tl(cpu_cc_src2, src2);
    gen_tag_tv(cpu_cc_src, cpu_cc_src2);
515 516
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
    gen_add_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
517
    gen_cc_clear_icc();
518 519
    gen_cc_NZ_icc(cpu_cc_dst);
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
520 521
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
522 523 524
    gen_cc_NZ_xcc(cpu_cc_dst);
    gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
525
#endif
526
    tcg_gen_mov_tl(dst, cpu_cc_dst);
527 528 529 530 531 532
}

/* old op:
    if (src1 < T1)
        env->psr |= PSR_CARRY;
*/
533
static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
534
{
B
blueswir1 已提交
535
    TCGv r_temp1, r_temp2;
536 537 538
    int l1;

    l1 = gen_new_label();
P
pbrook 已提交
539 540
    r_temp1 = tcg_temp_new();
    r_temp2 = tcg_temp_new();
B
blueswir1 已提交
541 542 543
    tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
    tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
    tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
544 545
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
    gen_set_label(l1);
B
blueswir1 已提交
546 547
    tcg_temp_free(r_temp1);
    tcg_temp_free(r_temp2);
548 549
}

550
#ifdef TARGET_SPARC64
551 552 553
static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
{
    int l1;
554

555 556 557 558
    l1 = gen_new_label();
    tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
    tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
    gen_set_label(l1);
559
}
560
#endif
561 562 563 564 565

/* old op:
    if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
        env->psr |= PSR_OVF;
*/
566
static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
567
{
568
    TCGv r_temp;
569

P
pbrook 已提交
570
    r_temp = tcg_temp_new();
571
    tcg_gen_xor_tl(r_temp, src1, src2);
572 573
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
574
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
B
blueswir1 已提交
575 576 577
    tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
    tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
    tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
B
blueswir1 已提交
578
    tcg_temp_free(r_temp);
579 580
}

581
#ifdef TARGET_SPARC64
582 583 584 585
static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
{
    TCGv r_temp;

P
pbrook 已提交
586
    r_temp = tcg_temp_new();
587 588 589 590
    tcg_gen_xor_tl(r_temp, src1, src2);
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
B
blueswir1 已提交
591 592 593
    tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
    tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
    tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
B
blueswir1 已提交
594
    tcg_temp_free(r_temp);
595
}
596
#endif
597 598 599

static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
{
P
pbrook 已提交
600 601
    TCGv r_temp;
    TCGv_i32 r_const;
602 603 604 605
    int l1;

    l1 = gen_new_label();

P
pbrook 已提交
606
    r_temp = tcg_temp_new();
607
    tcg_gen_xor_tl(r_temp, src1, src2);
608 609
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
610
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
P
pbrook 已提交
611
    tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
B
blueswir1 已提交
612
    r_const = tcg_const_i32(TT_TOVF);
P
pbrook 已提交
613 614
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
615
    gen_set_label(l1);
B
blueswir1 已提交
616
    tcg_temp_free(r_temp);
617 618
}

619
static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
620
{
621
    tcg_gen_mov_tl(cpu_cc_src, src1);
622
    tcg_gen_mov_tl(cpu_cc_src2, src2);
623
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
624
    gen_cc_clear_icc();
625
    gen_cc_NZ_icc(cpu_cc_dst);
626
    gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
627
    gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
628 629
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
630
    gen_cc_NZ_xcc(cpu_cc_dst);
631
    gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
632
    gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
633
#endif
634
    tcg_gen_mov_tl(dst, cpu_cc_dst);
635 636
}

637
static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
638
{
639
    tcg_gen_mov_tl(cpu_cc_src, src1);
640
    tcg_gen_mov_tl(cpu_cc_src2, src2);
641
    gen_mov_reg_C(cpu_tmp0, cpu_psr);
642
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
643
    gen_cc_clear_icc();
644
    gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
645 646
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
647
    gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
648
#endif
649
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
650 651 652
    gen_cc_NZ_icc(cpu_cc_dst);
    gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
653
#ifdef TARGET_SPARC64
654 655 656
    gen_cc_NZ_xcc(cpu_cc_dst);
    gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
    gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
657
#endif
658
    tcg_gen_mov_tl(dst, cpu_cc_dst);
659 660
}

661
static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
662
{
663
    tcg_gen_mov_tl(cpu_cc_src, src1);
664
    tcg_gen_mov_tl(cpu_cc_src2, src2);
665
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
666
    gen_cc_clear_icc();
667
    gen_cc_NZ_icc(cpu_cc_dst);
668
    gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
669
    gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
670
    gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
671 672
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
673
    gen_cc_NZ_xcc(cpu_cc_dst);
674
    gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
675
    gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
676
#endif
677
    tcg_gen_mov_tl(dst, cpu_cc_dst);
678 679
}

680
static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
681
{
682
    tcg_gen_mov_tl(cpu_cc_src, src1);
683 684
    tcg_gen_mov_tl(cpu_cc_src2, src2);
    gen_tag_tv(cpu_cc_src, cpu_cc_src2);
685 686
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
    gen_sub_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
687
    gen_cc_clear_icc();
688
    gen_cc_NZ_icc(cpu_cc_dst);
689
    gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
690 691
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
692
    gen_cc_NZ_xcc(cpu_cc_dst);
693
    gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
694
    gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
695
#endif
696
    tcg_gen_mov_tl(dst, cpu_cc_dst);
697 698
}

699
static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
700
{
B
blueswir1 已提交
701
    TCGv r_temp;
702
    int l1;
B
blueswir1 已提交
703 704

    l1 = gen_new_label();
P
pbrook 已提交
705
    r_temp = tcg_temp_new();
B
blueswir1 已提交
706 707 708 709 710

    /* old op:
    if (!(env->y & 1))
        T1 = 0;
    */
711
    tcg_gen_andi_tl(cpu_cc_src, src1, 0xffffffff);
712
    tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
713
    tcg_gen_andi_tl(cpu_cc_src2, src2, 0xffffffff);
B
blueswir1 已提交
714
    tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
B
blueswir1 已提交
715
    tcg_gen_movi_tl(cpu_cc_src2, 0);
716
    gen_set_label(l1);
B
blueswir1 已提交
717 718 719

    // b2 = T0 & 1;
    // env->y = (b2 << 31) | (env->y >> 1);
B
blueswir1 已提交
720 721
    tcg_gen_andi_tl(r_temp, cpu_cc_src, 0x1);
    tcg_gen_shli_tl(r_temp, r_temp, 31);
722
    tcg_gen_shri_tl(cpu_tmp0, cpu_y, 1);
723
    tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x7fffffff);
724 725
    tcg_gen_or_tl(cpu_tmp0, cpu_tmp0, r_temp);
    tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
B
blueswir1 已提交
726 727 728 729 730

    // b1 = N ^ V;
    gen_mov_reg_N(cpu_tmp0, cpu_psr);
    gen_mov_reg_V(r_temp, cpu_psr);
    tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
B
blueswir1 已提交
731
    tcg_temp_free(r_temp);
B
blueswir1 已提交
732 733 734 735

    // T0 = (b1 << 31) | (T0 >> 1);
    // src1 = T0;
    tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
736
    tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
B
blueswir1 已提交
737 738 739
    tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);

    /* do addition and update flags */
740
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
B
blueswir1 已提交
741

742
    gen_cc_clear_icc();
743 744 745
    gen_cc_NZ_icc(cpu_cc_dst);
    gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
746
    tcg_gen_mov_tl(dst, cpu_cc_dst);
B
blueswir1 已提交
747 748
}

749
static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
750
{
P
pbrook 已提交
751
    TCGv_i64 r_temp, r_temp2;
B
blueswir1 已提交
752

P
pbrook 已提交
753 754
    r_temp = tcg_temp_new_i64();
    r_temp2 = tcg_temp_new_i64();
B
blueswir1 已提交
755

B
blueswir1 已提交
756 757
    tcg_gen_extu_tl_i64(r_temp, src2);
    tcg_gen_extu_tl_i64(r_temp2, src1);
B
blueswir1 已提交
758 759 760
    tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);

    tcg_gen_shri_i64(r_temp, r_temp2, 32);
B
blueswir1 已提交
761
    tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
P
pbrook 已提交
762
    tcg_temp_free_i64(r_temp);
763
    tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
B
blueswir1 已提交
764
#ifdef TARGET_SPARC64
765
    tcg_gen_mov_i64(dst, r_temp2);
B
blueswir1 已提交
766
#else
767
    tcg_gen_trunc_i64_tl(dst, r_temp2);
B
blueswir1 已提交
768
#endif
P
pbrook 已提交
769
    tcg_temp_free_i64(r_temp2);
B
blueswir1 已提交
770 771
}

772
static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
773
{
P
pbrook 已提交
774
    TCGv_i64 r_temp, r_temp2;
B
blueswir1 已提交
775

P
pbrook 已提交
776 777
    r_temp = tcg_temp_new_i64();
    r_temp2 = tcg_temp_new_i64();
B
blueswir1 已提交
778

B
blueswir1 已提交
779 780
    tcg_gen_ext_tl_i64(r_temp, src2);
    tcg_gen_ext_tl_i64(r_temp2, src1);
B
blueswir1 已提交
781 782 783
    tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);

    tcg_gen_shri_i64(r_temp, r_temp2, 32);
B
blueswir1 已提交
784
    tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
P
pbrook 已提交
785
    tcg_temp_free_i64(r_temp);
786
    tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
B
blueswir1 已提交
787
#ifdef TARGET_SPARC64
788
    tcg_gen_mov_i64(dst, r_temp2);
B
blueswir1 已提交
789
#else
790
    tcg_gen_trunc_i64_tl(dst, r_temp2);
B
blueswir1 已提交
791
#endif
P
pbrook 已提交
792
    tcg_temp_free_i64(r_temp2);
B
blueswir1 已提交
793 794
}

B
blueswir1 已提交
795
#ifdef TARGET_SPARC64
B
blueswir1 已提交
796
static inline void gen_trap_ifdivzero_tl(TCGv divisor)
B
blueswir1 已提交
797
{
P
pbrook 已提交
798
    TCGv_i32 r_const;
B
blueswir1 已提交
799 800 801
    int l1;

    l1 = gen_new_label();
P
pbrook 已提交
802
    tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
B
blueswir1 已提交
803
    r_const = tcg_const_i32(TT_DIV_ZERO);
P
pbrook 已提交
804 805
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
B
blueswir1 已提交
806 807 808
    gen_set_label(l1);
}

809
static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
810 811 812 813 814
{
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
815 816
    tcg_gen_mov_tl(cpu_cc_src, src1);
    tcg_gen_mov_tl(cpu_cc_src2, src2);
817
    gen_trap_ifdivzero_tl(cpu_cc_src2);
P
pbrook 已提交
818 819
    tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src, INT64_MIN, l1);
    tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src2, -1, l1);
820
    tcg_gen_movi_i64(dst, INT64_MIN);
B
blueswir1 已提交
821
    tcg_gen_br(l2);
B
blueswir1 已提交
822
    gen_set_label(l1);
823
    tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
B
blueswir1 已提交
824 825 826 827
    gen_set_label(l2);
}
#endif

828
static inline void gen_op_div_cc(TCGv dst)
829 830 831
{
    int l1;

832
    tcg_gen_mov_tl(cpu_cc_dst, dst);
833
    gen_cc_clear_icc();
834
    gen_cc_NZ_icc(cpu_cc_dst);
835
    l1 = gen_new_label();
836
    tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_src2, 0, l1);
837 838 839 840
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
    gen_set_label(l1);
}

841
static inline void gen_op_logic_cc(TCGv dst)
842
{
843 844
    tcg_gen_mov_tl(cpu_cc_dst, dst);

845
    gen_cc_clear_icc();
846
    gen_cc_NZ_icc(cpu_cc_dst);
847 848
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
849
    gen_cc_NZ_xcc(cpu_cc_dst);
850
#endif
851 852
}

853 854 855 856 857 858 859
// 1
static inline void gen_op_eval_ba(TCGv dst)
{
    tcg_gen_movi_tl(dst, 1);
}

// Z
P
pbrook 已提交
860
static inline void gen_op_eval_be(TCGv dst, TCGv_i32 src)
861 862 863 864 865
{
    gen_mov_reg_Z(dst, src);
}

// Z | (N ^ V)
P
pbrook 已提交
866
static inline void gen_op_eval_ble(TCGv dst, TCGv_i32 src)
867
{
868
    gen_mov_reg_N(cpu_tmp0, src);
869
    gen_mov_reg_V(dst, src);
870 871 872
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
    gen_mov_reg_Z(cpu_tmp0, src);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
873 874 875
}

// N ^ V
P
pbrook 已提交
876
static inline void gen_op_eval_bl(TCGv dst, TCGv_i32 src)
877
{
878
    gen_mov_reg_V(cpu_tmp0, src);
879
    gen_mov_reg_N(dst, src);
880
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
881 882 883
}

// C | Z
P
pbrook 已提交
884
static inline void gen_op_eval_bleu(TCGv dst, TCGv_i32 src)
885
{
886
    gen_mov_reg_Z(cpu_tmp0, src);
887
    gen_mov_reg_C(dst, src);
888
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
889 890 891
}

// C
P
pbrook 已提交
892
static inline void gen_op_eval_bcs(TCGv dst, TCGv_i32 src)
893 894 895 896 897
{
    gen_mov_reg_C(dst, src);
}

// V
P
pbrook 已提交
898
static inline void gen_op_eval_bvs(TCGv dst, TCGv_i32 src)
899 900 901 902 903 904 905 906 907 908 909
{
    gen_mov_reg_V(dst, src);
}

// 0
static inline void gen_op_eval_bn(TCGv dst)
{
    tcg_gen_movi_tl(dst, 0);
}

// N
P
pbrook 已提交
910
static inline void gen_op_eval_bneg(TCGv dst, TCGv_i32 src)
911 912 913 914 915
{
    gen_mov_reg_N(dst, src);
}

// !Z
P
pbrook 已提交
916
static inline void gen_op_eval_bne(TCGv dst, TCGv_i32 src)
917 918 919 920 921 922
{
    gen_mov_reg_Z(dst, src);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !(Z | (N ^ V))
P
pbrook 已提交
923
static inline void gen_op_eval_bg(TCGv dst, TCGv_i32 src)
924
{
925
    gen_mov_reg_N(cpu_tmp0, src);
926
    gen_mov_reg_V(dst, src);
927 928 929
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
    gen_mov_reg_Z(cpu_tmp0, src);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
930 931 932 933
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !(N ^ V)
P
pbrook 已提交
934
static inline void gen_op_eval_bge(TCGv dst, TCGv_i32 src)
935
{
936
    gen_mov_reg_V(cpu_tmp0, src);
937
    gen_mov_reg_N(dst, src);
938
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
939 940 941 942
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !(C | Z)
P
pbrook 已提交
943
static inline void gen_op_eval_bgu(TCGv dst, TCGv_i32 src)
944
{
945
    gen_mov_reg_Z(cpu_tmp0, src);
946
    gen_mov_reg_C(dst, src);
947
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
948 949 950 951
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !C
P
pbrook 已提交
952
static inline void gen_op_eval_bcc(TCGv dst, TCGv_i32 src)
953 954 955 956 957 958
{
    gen_mov_reg_C(dst, src);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !N
P
pbrook 已提交
959
static inline void gen_op_eval_bpos(TCGv dst, TCGv_i32 src)
960 961 962 963 964 965
{
    gen_mov_reg_N(dst, src);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !V
P
pbrook 已提交
966
static inline void gen_op_eval_bvc(TCGv dst, TCGv_i32 src)
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
{
    gen_mov_reg_V(dst, src);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

/*
  FPSR bit field FCC1 | FCC0:
   0 =
   1 <
   2 >
   3 unordered
*/
static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
                                    unsigned int fcc_offset)
{
982
    tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
983 984 985 986 987 988
    tcg_gen_andi_tl(reg, reg, 0x1);
}

static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
                                    unsigned int fcc_offset)
{
989
    tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
990 991 992 993 994 995 996 997
    tcg_gen_andi_tl(reg, reg, 0x1);
}

// !0: FCC0 | FCC1
static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
998 999
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
1000 1001 1002 1003 1004 1005 1006
}

// 1 or 2: FCC0 ^ FCC1
static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
1007 1008
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
}

// 1 or 3: FCC0
static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
}

// 1: FCC0 & !FCC1
static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
1023 1024 1025
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
}

// 2 or 3: FCC1
static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC1(dst, src, fcc_offset);
}

// 2: !FCC0 & FCC1
static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
    tcg_gen_xori_tl(dst, dst, 0x1);
1041 1042
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1043 1044 1045 1046 1047 1048 1049
}

// 3: FCC0 & FCC1
static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
1050 1051
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1052 1053 1054 1055 1056 1057 1058
}

// 0: !(FCC0 | FCC1)
static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
1059 1060
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
1061 1062 1063 1064 1065 1066 1067 1068
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// 0 or 3: !(FCC0 ^ FCC1)
static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
1069 1070
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// 0 or 2: !FCC0
static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !1: !(FCC0 & !FCC1)
static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
1087 1088 1089
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// 0 or 1: !FCC1
static inline void gen_op_eval_fble(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC1(dst, src, fcc_offset);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !2: !(!FCC0 & FCC1)
static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
    tcg_gen_xori_tl(dst, dst, 0x1);
1107 1108
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1109 1110 1111 1112 1113 1114 1115 1116
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !3: !(FCC0 & FCC1)
static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
                                    unsigned int fcc_offset)
{
    gen_mov_reg_FCC0(dst, src, fcc_offset);
1117 1118
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1119 1120 1121
    tcg_gen_xori_tl(dst, dst, 0x1);
}

B
blueswir1 已提交
1122
static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1123
                               target_ulong pc2, TCGv r_cond)
B
bellard 已提交
1124 1125 1126 1127 1128
{
    int l1;

    l1 = gen_new_label();

P
pbrook 已提交
1129
    tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
B
bellard 已提交
1130

1131
    gen_goto_tb(dc, 0, pc1, pc1 + 4);
B
bellard 已提交
1132 1133

    gen_set_label(l1);
1134
    gen_goto_tb(dc, 1, pc2, pc2 + 4);
B
bellard 已提交
1135 1136
}

B
blueswir1 已提交
1137
static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1138
                                target_ulong pc2, TCGv r_cond)
B
bellard 已提交
1139 1140 1141 1142 1143
{
    int l1;

    l1 = gen_new_label();

P
pbrook 已提交
1144
    tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
B
bellard 已提交
1145

1146
    gen_goto_tb(dc, 0, pc2, pc1);
B
bellard 已提交
1147 1148

    gen_set_label(l1);
1149
    gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
B
bellard 已提交
1150 1151
}

1152 1153
static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
                                      TCGv r_cond)
B
bellard 已提交
1154 1155 1156 1157 1158
{
    int l1, l2;

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

P
pbrook 已提交
1160
    tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
B
bellard 已提交
1161

B
blueswir1 已提交
1162
    tcg_gen_movi_tl(cpu_npc, npc1);
B
blueswir1 已提交
1163
    tcg_gen_br(l2);
B
bellard 已提交
1164 1165

    gen_set_label(l1);
B
blueswir1 已提交
1166
    tcg_gen_movi_tl(cpu_npc, npc2);
B
bellard 已提交
1167 1168 1169
    gen_set_label(l2);
}

1170 1171 1172
/* call this function before using the condition register as it may
   have been set for a jump */
static inline void flush_cond(DisasContext *dc, TCGv cond)
B
bellard 已提交
1173 1174
{
    if (dc->npc == JUMP_PC) {
1175
        gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
B
bellard 已提交
1176 1177 1178 1179
        dc->npc = DYNAMIC_PC;
    }
}

1180
static inline void save_npc(DisasContext *dc, TCGv cond)
B
bellard 已提交
1181 1182
{
    if (dc->npc == JUMP_PC) {
1183
        gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
B
bellard 已提交
1184 1185
        dc->npc = DYNAMIC_PC;
    } else if (dc->npc != DYNAMIC_PC) {
B
blueswir1 已提交
1186
        tcg_gen_movi_tl(cpu_npc, dc->npc);
B
bellard 已提交
1187 1188 1189
    }
}

1190
static inline void save_state(DisasContext *dc, TCGv cond)
B
bellard 已提交
1191
{
B
blueswir1 已提交
1192
    tcg_gen_movi_tl(cpu_pc, dc->pc);
1193
    save_npc(dc, cond);
B
bellard 已提交
1194 1195
}

1196
static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
B
bellard 已提交
1197 1198
{
    if (dc->npc == JUMP_PC) {
1199
        gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
B
blueswir1 已提交
1200
        tcg_gen_mov_tl(cpu_pc, cpu_npc);
B
bellard 已提交
1201 1202
        dc->pc = DYNAMIC_PC;
    } else if (dc->npc == DYNAMIC_PC) {
B
blueswir1 已提交
1203
        tcg_gen_mov_tl(cpu_pc, cpu_npc);
B
bellard 已提交
1204 1205 1206 1207 1208 1209
        dc->pc = DYNAMIC_PC;
    } else {
        dc->pc = dc->npc;
    }
}

1210 1211
static inline void gen_op_next_insn(void)
{
B
blueswir1 已提交
1212 1213
    tcg_gen_mov_tl(cpu_pc, cpu_npc);
    tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1214 1215
}

1216 1217
static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
{
P
pbrook 已提交
1218
    TCGv_i32 r_src;
B
bellard 已提交
1219 1220

#ifdef TARGET_SPARC64
1221
    if (cc)
1222
        r_src = cpu_xcc;
1223
    else
1224
        r_src = cpu_psr;
B
bellard 已提交
1225
#else
1226
    r_src = cpu_psr;
B
bellard 已提交
1227
#endif
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
    switch (cond) {
    case 0x0:
        gen_op_eval_bn(r_dst);
        break;
    case 0x1:
        gen_op_eval_be(r_dst, r_src);
        break;
    case 0x2:
        gen_op_eval_ble(r_dst, r_src);
        break;
    case 0x3:
        gen_op_eval_bl(r_dst, r_src);
        break;
    case 0x4:
        gen_op_eval_bleu(r_dst, r_src);
        break;
    case 0x5:
        gen_op_eval_bcs(r_dst, r_src);
        break;
    case 0x6:
        gen_op_eval_bneg(r_dst, r_src);
        break;
    case 0x7:
        gen_op_eval_bvs(r_dst, r_src);
        break;
    case 0x8:
        gen_op_eval_ba(r_dst);
        break;
    case 0x9:
        gen_op_eval_bne(r_dst, r_src);
        break;
    case 0xa:
        gen_op_eval_bg(r_dst, r_src);
        break;
    case 0xb:
        gen_op_eval_bge(r_dst, r_src);
        break;
    case 0xc:
        gen_op_eval_bgu(r_dst, r_src);
        break;
    case 0xd:
        gen_op_eval_bcc(r_dst, r_src);
        break;
    case 0xe:
        gen_op_eval_bpos(r_dst, r_src);
        break;
    case 0xf:
        gen_op_eval_bvc(r_dst, r_src);
        break;
    }
}
1279

1280
static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1281
{
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
    unsigned int offset;

    switch (cc) {
    default:
    case 0x0:
        offset = 0;
        break;
    case 0x1:
        offset = 32 - 10;
        break;
    case 0x2:
        offset = 34 - 10;
        break;
    case 0x3:
        offset = 36 - 10;
        break;
    }

    switch (cond) {
    case 0x0:
        gen_op_eval_bn(r_dst);
        break;
    case 0x1:
B
blueswir1 已提交
1305
        gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1306 1307
        break;
    case 0x2:
B
blueswir1 已提交
1308
        gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1309 1310
        break;
    case 0x3:
B
blueswir1 已提交
1311
        gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1312 1313
        break;
    case 0x4:
B
blueswir1 已提交
1314
        gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1315 1316
        break;
    case 0x5:
B
blueswir1 已提交
1317
        gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1318 1319
        break;
    case 0x6:
B
blueswir1 已提交
1320
        gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1321 1322
        break;
    case 0x7:
B
blueswir1 已提交
1323
        gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1324 1325 1326 1327 1328
        break;
    case 0x8:
        gen_op_eval_ba(r_dst);
        break;
    case 0x9:
B
blueswir1 已提交
1329
        gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1330 1331
        break;
    case 0xa:
B
blueswir1 已提交
1332
        gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1333 1334
        break;
    case 0xb:
B
blueswir1 已提交
1335
        gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1336 1337
        break;
    case 0xc:
B
blueswir1 已提交
1338
        gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1339 1340
        break;
    case 0xd:
B
blueswir1 已提交
1341
        gen_op_eval_fble(r_dst, cpu_fsr, offset);
1342 1343
        break;
    case 0xe:
B
blueswir1 已提交
1344
        gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1345 1346
        break;
    case 0xf:
B
blueswir1 已提交
1347
        gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1348 1349
        break;
    }
1350
}
1351

1352
#ifdef TARGET_SPARC64
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
// Inverted logic
static const int gen_tcg_cond_reg[8] = {
    -1,
    TCG_COND_NE,
    TCG_COND_GT,
    TCG_COND_GE,
    -1,
    TCG_COND_EQ,
    TCG_COND_LE,
    TCG_COND_LT,
};
1364

1365
static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1366 1367 1368 1369
{
    int l1;

    l1 = gen_new_label();
1370
    tcg_gen_movi_tl(r_dst, 0);
P
pbrook 已提交
1371
    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1372 1373 1374
    tcg_gen_movi_tl(r_dst, 1);
    gen_set_label(l1);
}
B
bellard 已提交
1375
#endif
1376

B
bellard 已提交
1377
/* XXX: potentially incorrect if dynamic npc */
1378 1379
static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
                      TCGv r_cond)
1380
{
1381
    unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1382
    target_ulong target = dc->pc + offset;
1383

1384
    if (cond == 0x0) {
B
blueswir1 已提交
1385 1386 1387 1388 1389 1390 1391 1392
        /* unconditional not taken */
        if (a) {
            dc->pc = dc->npc + 4;
            dc->npc = dc->pc + 4;
        } else {
            dc->pc = dc->npc;
            dc->npc = dc->pc + 4;
        }
1393
    } else if (cond == 0x8) {
B
blueswir1 已提交
1394 1395 1396 1397 1398 1399 1400 1401
        /* unconditional taken */
        if (a) {
            dc->pc = target;
            dc->npc = dc->pc + 4;
        } else {
            dc->pc = dc->npc;
            dc->npc = target;
        }
1402
    } else {
1403 1404
        flush_cond(dc, r_cond);
        gen_cond(r_cond, cc, cond);
B
blueswir1 已提交
1405
        if (a) {
1406
            gen_branch_a(dc, target, dc->npc, r_cond);
1407
            dc->is_br = 1;
B
blueswir1 已提交
1408
        } else {
1409
            dc->pc = dc->npc;
B
bellard 已提交
1410 1411 1412
            dc->jump_pc[0] = target;
            dc->jump_pc[1] = dc->npc + 4;
            dc->npc = JUMP_PC;
B
blueswir1 已提交
1413
        }
1414
    }
1415 1416
}

B
bellard 已提交
1417
/* XXX: potentially incorrect if dynamic npc */
1418 1419
static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
                      TCGv r_cond)
1420 1421
{
    unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1422 1423
    target_ulong target = dc->pc + offset;

1424
    if (cond == 0x0) {
B
blueswir1 已提交
1425 1426 1427 1428 1429 1430 1431 1432
        /* unconditional not taken */
        if (a) {
            dc->pc = dc->npc + 4;
            dc->npc = dc->pc + 4;
        } else {
            dc->pc = dc->npc;
            dc->npc = dc->pc + 4;
        }
1433
    } else if (cond == 0x8) {
B
blueswir1 已提交
1434 1435 1436 1437 1438 1439 1440 1441
        /* unconditional taken */
        if (a) {
            dc->pc = target;
            dc->npc = dc->pc + 4;
        } else {
            dc->pc = dc->npc;
            dc->npc = target;
        }
1442
    } else {
1443 1444
        flush_cond(dc, r_cond);
        gen_fcond(r_cond, cc, cond);
B
blueswir1 已提交
1445
        if (a) {
1446
            gen_branch_a(dc, target, dc->npc, r_cond);
1447
            dc->is_br = 1;
B
blueswir1 已提交
1448
        } else {
1449 1450 1451 1452
            dc->pc = dc->npc;
            dc->jump_pc[0] = target;
            dc->jump_pc[1] = dc->npc + 4;
            dc->npc = JUMP_PC;
B
blueswir1 已提交
1453
        }
1454 1455 1456
    }
}

B
bellard 已提交
1457 1458
#ifdef TARGET_SPARC64
/* XXX: potentially incorrect if dynamic npc */
1459 1460
static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
                          TCGv r_cond, TCGv r_reg)
1461
{
B
bellard 已提交
1462 1463 1464
    unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
    target_ulong target = dc->pc + offset;

1465 1466
    flush_cond(dc, r_cond);
    gen_cond_reg(r_cond, cond, r_reg);
B
bellard 已提交
1467
    if (a) {
1468
        gen_branch_a(dc, target, dc->npc, r_cond);
B
blueswir1 已提交
1469
        dc->is_br = 1;
B
bellard 已提交
1470
    } else {
B
blueswir1 已提交
1471 1472 1473 1474
        dc->pc = dc->npc;
        dc->jump_pc[0] = target;
        dc->jump_pc[1] = dc->npc + 4;
        dc->npc = JUMP_PC;
B
bellard 已提交
1475
    }
1476 1477
}

P
pbrook 已提交
1478
static inline void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1479
{
B
blueswir1 已提交
1480 1481
    switch (fccno) {
    case 0:
P
pbrook 已提交
1482
        gen_helper_fcmps(r_rs1, r_rs2);
B
blueswir1 已提交
1483 1484
        break;
    case 1:
P
pbrook 已提交
1485
        gen_helper_fcmps_fcc1(r_rs1, r_rs2);
B
blueswir1 已提交
1486 1487
        break;
    case 2:
P
pbrook 已提交
1488
        gen_helper_fcmps_fcc2(r_rs1, r_rs2);
B
blueswir1 已提交
1489 1490
        break;
    case 3:
P
pbrook 已提交
1491
        gen_helper_fcmps_fcc3(r_rs1, r_rs2);
B
blueswir1 已提交
1492 1493
        break;
    }
1494 1495 1496 1497
}

static inline void gen_op_fcmpd(int fccno)
{
P
pbrook 已提交
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
    switch (fccno) {
    case 0:
        gen_helper_fcmpd();
        break;
    case 1:
        gen_helper_fcmpd_fcc1();
        break;
    case 2:
        gen_helper_fcmpd_fcc2();
        break;
    case 3:
        gen_helper_fcmpd_fcc3();
        break;
    }
1512 1513 1514 1515
}

static inline void gen_op_fcmpq(int fccno)
{
P
pbrook 已提交
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
    switch (fccno) {
    case 0:
        gen_helper_fcmpq();
        break;
    case 1:
        gen_helper_fcmpq_fcc1();
        break;
    case 2:
        gen_helper_fcmpq_fcc2();
        break;
    case 3:
        gen_helper_fcmpq_fcc3();
        break;
    }
1530 1531
}

P
pbrook 已提交
1532
static inline void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1533
{
B
blueswir1 已提交
1534 1535
    switch (fccno) {
    case 0:
P
pbrook 已提交
1536
        gen_helper_fcmpes(r_rs1, r_rs2);
B
blueswir1 已提交
1537 1538
        break;
    case 1:
P
pbrook 已提交
1539
        gen_helper_fcmpes_fcc1(r_rs1, r_rs2);
B
blueswir1 已提交
1540 1541
        break;
    case 2:
P
pbrook 已提交
1542
        gen_helper_fcmpes_fcc2(r_rs1, r_rs2);
B
blueswir1 已提交
1543 1544
        break;
    case 3:
P
pbrook 已提交
1545
        gen_helper_fcmpes_fcc3(r_rs1, r_rs2);
B
blueswir1 已提交
1546 1547
        break;
    }
1548 1549 1550 1551
}

static inline void gen_op_fcmped(int fccno)
{
P
pbrook 已提交
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
    switch (fccno) {
    case 0:
        gen_helper_fcmped();
        break;
    case 1:
        gen_helper_fcmped_fcc1();
        break;
    case 2:
        gen_helper_fcmped_fcc2();
        break;
    case 3:
        gen_helper_fcmped_fcc3();
        break;
    }
1566 1567 1568 1569
}

static inline void gen_op_fcmpeq(int fccno)
{
P
pbrook 已提交
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
    switch (fccno) {
    case 0:
        gen_helper_fcmpeq();
        break;
    case 1:
        gen_helper_fcmpeq_fcc1();
        break;
    case 2:
        gen_helper_fcmpeq_fcc2();
        break;
    case 3:
        gen_helper_fcmpeq_fcc3();
        break;
    }
1584 1585 1586 1587
}

#else

B
blueswir1 已提交
1588
static inline void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1589
{
P
pbrook 已提交
1590
    gen_helper_fcmps(r_rs1, r_rs2);
1591 1592 1593 1594
}

static inline void gen_op_fcmpd(int fccno)
{
P
pbrook 已提交
1595
    gen_helper_fcmpd();
1596 1597 1598 1599
}

static inline void gen_op_fcmpq(int fccno)
{
P
pbrook 已提交
1600
    gen_helper_fcmpq();
1601 1602
}

B
blueswir1 已提交
1603
static inline void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1604
{
P
pbrook 已提交
1605
    gen_helper_fcmpes(r_rs1, r_rs2);
1606 1607 1608 1609
}

static inline void gen_op_fcmped(int fccno)
{
P
pbrook 已提交
1610
    gen_helper_fcmped();
1611 1612 1613 1614
}

static inline void gen_op_fcmpeq(int fccno)
{
P
pbrook 已提交
1615
    gen_helper_fcmpeq();
1616 1617 1618
}
#endif

B
blueswir1 已提交
1619 1620
static inline void gen_op_fpexception_im(int fsr_flags)
{
P
pbrook 已提交
1621
    TCGv_i32 r_const;
B
blueswir1 已提交
1622

1623
    tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
B
blueswir1 已提交
1624
    tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
B
blueswir1 已提交
1625
    r_const = tcg_const_i32(TT_FP_EXCP);
P
pbrook 已提交
1626 1627
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
B
blueswir1 已提交
1628 1629
}

1630
static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
B
bellard 已提交
1631 1632 1633
{
#if !defined(CONFIG_USER_ONLY)
    if (!dc->fpu_enabled) {
P
pbrook 已提交
1634
        TCGv_i32 r_const;
B
blueswir1 已提交
1635

1636
        save_state(dc, r_cond);
B
blueswir1 已提交
1637
        r_const = tcg_const_i32(TT_NFPU_INSN);
P
pbrook 已提交
1638 1639
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
bellard 已提交
1640 1641 1642 1643 1644 1645 1646
        dc->is_br = 1;
        return 1;
    }
#endif
    return 0;
}

1647 1648
static inline void gen_op_clear_ieee_excp_and_FTT(void)
{
1649
    tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1650 1651 1652 1653
}

static inline void gen_clear_float_exceptions(void)
{
P
pbrook 已提交
1654
    gen_helper_clear_float_exceptions();
1655 1656
}

B
blueswir1 已提交
1657 1658
/* asi moves */
#ifdef TARGET_SPARC64
P
pbrook 已提交
1659
static inline TCGv_i32 gen_get_asi(int insn, TCGv r_addr)
B
blueswir1 已提交
1660
{
1661
    int asi;
P
pbrook 已提交
1662
    TCGv_i32 r_asi;
B
blueswir1 已提交
1663 1664

    if (IS_IMM) {
P
pbrook 已提交
1665
        r_asi = tcg_temp_new_i32();
1666
        tcg_gen_mov_i32(r_asi, cpu_asi);
B
blueswir1 已提交
1667 1668
    } else {
        asi = GET_FIELD(insn, 19, 26);
1669
        r_asi = tcg_const_i32(asi);
B
blueswir1 已提交
1670
    }
1671 1672 1673
    return r_asi;
}

B
blueswir1 已提交
1674 1675
static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
                              int sign)
1676
{
P
pbrook 已提交
1677
    TCGv_i32 r_asi, r_size, r_sign;
1678

1679
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1680 1681
    r_size = tcg_const_i32(size);
    r_sign = tcg_const_i32(sign);
P
pbrook 已提交
1682 1683 1684 1685
    gen_helper_ld_asi(dst, addr, r_asi, r_size, r_sign);
    tcg_temp_free_i32(r_sign);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1686 1687
}

1688
static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
B
blueswir1 已提交
1689
{
P
pbrook 已提交
1690
    TCGv_i32 r_asi, r_size;
B
blueswir1 已提交
1691

1692
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1693
    r_size = tcg_const_i32(size);
P
pbrook 已提交
1694 1695 1696
    gen_helper_st_asi(addr, src, r_asi, r_size);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1697 1698
}

1699
static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
B
blueswir1 已提交
1700
{
P
pbrook 已提交
1701
    TCGv_i32 r_asi, r_size, r_rd;
B
blueswir1 已提交
1702

1703
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1704 1705
    r_size = tcg_const_i32(size);
    r_rd = tcg_const_i32(rd);
P
pbrook 已提交
1706 1707 1708 1709
    gen_helper_ldf_asi(addr, r_asi, r_size, r_rd);
    tcg_temp_free_i32(r_rd);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1710 1711
}

1712
static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
B
blueswir1 已提交
1713
{
P
pbrook 已提交
1714
    TCGv_i32 r_asi, r_size, r_rd;
B
blueswir1 已提交
1715

1716
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1717 1718
    r_size = tcg_const_i32(size);
    r_rd = tcg_const_i32(rd);
P
pbrook 已提交
1719 1720 1721 1722
    gen_helper_stf_asi(addr, r_asi, r_size, r_rd);
    tcg_temp_free_i32(r_rd);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1723 1724
}

1725
static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
B
blueswir1 已提交
1726
{
P
pbrook 已提交
1727
    TCGv_i32 r_asi, r_size, r_sign;
B
blueswir1 已提交
1728

1729
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1730 1731
    r_size = tcg_const_i32(4);
    r_sign = tcg_const_i32(0);
P
pbrook 已提交
1732 1733 1734 1735 1736
    gen_helper_ld_asi(cpu_tmp64, addr, r_asi, r_size, r_sign);
    tcg_temp_free_i32(r_sign);
    gen_helper_st_asi(addr, dst, r_asi, r_size);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1737
    tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
B
blueswir1 已提交
1738 1739
}

B
blueswir1 已提交
1740
static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
B
blueswir1 已提交
1741
{
P
pbrook 已提交
1742
    TCGv_i32 r_asi, r_rd;
B
blueswir1 已提交
1743

1744
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1745
    r_rd = tcg_const_i32(rd);
P
pbrook 已提交
1746 1747 1748
    gen_helper_ldda_asi(addr, r_asi, r_rd);
    tcg_temp_free_i32(r_rd);
    tcg_temp_free_i32(r_asi);
1749 1750
}

1751
static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1752
{
P
pbrook 已提交
1753
    TCGv_i32 r_asi, r_size;
1754 1755

    gen_movl_reg_TN(rd + 1, cpu_tmp0);
1756
    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
1757
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1758
    r_size = tcg_const_i32(8);
P
pbrook 已提交
1759 1760 1761
    gen_helper_st_asi(addr, cpu_tmp64, r_asi, r_size);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1762 1763
}

B
blueswir1 已提交
1764 1765
static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
                               int rd)
B
blueswir1 已提交
1766
{
P
pbrook 已提交
1767 1768
    TCGv r_val1;
    TCGv_i32 r_asi;
B
blueswir1 已提交
1769

P
pbrook 已提交
1770
    r_val1 = tcg_temp_new();
B
blueswir1 已提交
1771
    gen_movl_reg_TN(rd, r_val1);
1772
    r_asi = gen_get_asi(insn, addr);
P
pbrook 已提交
1773 1774
    gen_helper_cas_asi(dst, addr, r_val1, val2, r_asi);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1775
    tcg_temp_free(r_val1);
B
blueswir1 已提交
1776 1777
}

B
blueswir1 已提交
1778 1779
static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
                                int rd)
B
blueswir1 已提交
1780
{
P
pbrook 已提交
1781
    TCGv_i32 r_asi;
B
blueswir1 已提交
1782

B
blueswir1 已提交
1783
    gen_movl_reg_TN(rd, cpu_tmp64);
1784
    r_asi = gen_get_asi(insn, addr);
P
pbrook 已提交
1785 1786
    gen_helper_casx_asi(dst, addr, cpu_tmp64, val2, r_asi);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1787 1788 1789 1790
}

#elif !defined(CONFIG_USER_ONLY)

B
blueswir1 已提交
1791 1792
static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
                              int sign)
B
blueswir1 已提交
1793
{
P
pbrook 已提交
1794
    TCGv_i32 r_asi, r_size, r_sign;
B
blueswir1 已提交
1795

B
blueswir1 已提交
1796 1797 1798
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(size);
    r_sign = tcg_const_i32(sign);
P
pbrook 已提交
1799
    gen_helper_ld_asi(cpu_tmp64, addr, r_asi, r_size, r_sign);
B
blueswir1 已提交
1800 1801 1802
    tcg_temp_free(r_sign);
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
1803
    tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
B
blueswir1 已提交
1804 1805
}

1806
static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
B
blueswir1 已提交
1807
{
P
pbrook 已提交
1808
    TCGv_i32 r_asi, r_size;
B
blueswir1 已提交
1809

1810
    tcg_gen_extu_tl_i64(cpu_tmp64, src);
B
blueswir1 已提交
1811 1812
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(size);
P
pbrook 已提交
1813
    gen_helper_st_asi(addr, cpu_tmp64, r_asi, r_size);
B
blueswir1 已提交
1814 1815
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1816 1817
}

1818
static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
B
blueswir1 已提交
1819
{
P
pbrook 已提交
1820 1821
    TCGv_i32 r_asi, r_size, r_sign;
    TCGv_i64 r_val;
B
blueswir1 已提交
1822

B
blueswir1 已提交
1823 1824 1825
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(4);
    r_sign = tcg_const_i32(0);
P
pbrook 已提交
1826
    gen_helper_ld_asi(cpu_tmp64, addr, r_asi, r_size, r_sign);
B
blueswir1 已提交
1827
    tcg_temp_free(r_sign);
P
pbrook 已提交
1828 1829 1830 1831
    r_val = tcg_temp_new_i64();
    tcg_gen_extu_tl_i64(r_val, dst);
    gen_helper_st_asi(addr, r_val, r_asi, r_size);
    tcg_temp_free_i64(r_val);
B
blueswir1 已提交
1832 1833
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1834
    tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
B
blueswir1 已提交
1835 1836
}

B
blueswir1 已提交
1837
static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
B
blueswir1 已提交
1838
{
P
pbrook 已提交
1839
    TCGv_i32 r_asi, r_size, r_sign;
B
blueswir1 已提交
1840

B
blueswir1 已提交
1841 1842 1843
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(8);
    r_sign = tcg_const_i32(0);
P
pbrook 已提交
1844
    gen_helper_ld_asi(cpu_tmp64, addr, r_asi, r_size, r_sign);
B
blueswir1 已提交
1845 1846 1847
    tcg_temp_free(r_sign);
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1848 1849
    tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
    gen_movl_TN_reg(rd + 1, cpu_tmp0);
B
blueswir1 已提交
1850
    tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1851
    tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
B
blueswir1 已提交
1852
    gen_movl_TN_reg(rd, hi);
1853 1854
}

1855
static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1856
{
P
pbrook 已提交
1857
    TCGv_i32 r_asi, r_size;
1858 1859

    gen_movl_reg_TN(rd + 1, cpu_tmp0);
1860
    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
B
blueswir1 已提交
1861 1862
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(8);
P
pbrook 已提交
1863
    gen_helper_st_asi(addr, cpu_tmp64, r_asi, r_size);
B
blueswir1 已提交
1864 1865
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1866 1867 1868 1869
}
#endif

#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1870
static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
B
blueswir1 已提交
1871
{
P
pbrook 已提交
1872 1873
    TCGv_i64 r_val;
    TCGv_i32 r_asi, r_size;
B
blueswir1 已提交
1874

1875
    gen_ld_asi(dst, addr, insn, 1, 0);
B
blueswir1 已提交
1876

B
blueswir1 已提交
1877 1878 1879
    r_val = tcg_const_i64(0xffULL);
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(1);
P
pbrook 已提交
1880 1881 1882 1883
    gen_helper_st_asi(addr, r_val, r_asi, r_size);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
    tcg_temp_free_i64(r_val);
B
blueswir1 已提交
1884 1885 1886
}
#endif

1887 1888 1889 1890 1891 1892 1893
static inline TCGv get_src1(unsigned int insn, TCGv def)
{
    TCGv r_rs1 = def;
    unsigned int rs1;

    rs1 = GET_FIELD(insn, 13, 17);
    if (rs1 == 0)
1894
        r_rs1 = tcg_const_tl(0); // XXX how to free?
1895
    else if (rs1 < 8)
1896
        r_rs1 = cpu_gregs[rs1];
1897 1898 1899 1900 1901
    else
        tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
    return r_rs1;
}

B
blueswir1 已提交
1902 1903 1904 1905 1906 1907 1908
static inline TCGv get_src2(unsigned int insn, TCGv def)
{
    TCGv r_rs2 = def;
    unsigned int rs2;

    if (IS_IMM) { /* immediate */
        rs2 = GET_FIELDs(insn, 19, 31);
B
blueswir1 已提交
1909
        r_rs2 = tcg_const_tl((int)rs2); // XXX how to free?
B
blueswir1 已提交
1910 1911 1912
    } else { /* register */
        rs2 = GET_FIELD(insn, 27, 31);
        if (rs2 == 0)
B
blueswir1 已提交
1913
            r_rs2 = tcg_const_tl(0); // XXX how to free?
B
blueswir1 已提交
1914 1915 1916 1917 1918 1919 1920 1921
        else if (rs2 < 8)
            r_rs2 = cpu_gregs[rs2];
        else
            tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
    }
    return r_rs2;
}

B
blueswir1 已提交
1922
#define CHECK_IU_FEATURE(dc, FEATURE)                      \
1923
    if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
B
blueswir1 已提交
1924 1925
        goto illegal_insn;
#define CHECK_FPU_FEATURE(dc, FEATURE)                     \
1926
    if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
B
blueswir1 已提交
1927 1928
        goto nfpu_insn;

B
bellard 已提交
1929
/* before an instruction, dc->pc must be static */
1930 1931 1932
static void disas_sparc_insn(DisasContext * dc)
{
    unsigned int insn, opc, rs1, rs2, rd;
1933

1934
    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
B
blueswir1 已提交
1935
        tcg_gen_debug_insn_start(dc->pc);
B
bellard 已提交
1936
    insn = ldl_code(dc->pc);
1937
    opc = GET_FIELD(insn, 0, 1);
1938

1939
    rd = GET_FIELD(insn, 2, 6);
1940

P
pbrook 已提交
1941 1942
    cpu_src1 = tcg_temp_new(); // const
    cpu_src2 = tcg_temp_new(); // const
1943

1944
    switch (opc) {
B
blueswir1 已提交
1945 1946 1947 1948 1949
    case 0:                     /* branches/sethi */
        {
            unsigned int xop = GET_FIELD(insn, 7, 9);
            int32_t target;
            switch (xop) {
B
bellard 已提交
1950
#ifdef TARGET_SPARC64
B
blueswir1 已提交
1951 1952 1953 1954 1955 1956 1957 1958 1959
            case 0x1:           /* V9 BPcc */
                {
                    int cc;

                    target = GET_FIELD_SP(insn, 0, 18);
                    target = sign_extend(target, 18);
                    target <<= 2;
                    cc = GET_FIELD_SP(insn, 20, 21);
                    if (cc == 0)
1960
                        do_branch(dc, target, insn, 0, cpu_cond);
B
blueswir1 已提交
1961
                    else if (cc == 2)
1962
                        do_branch(dc, target, insn, 1, cpu_cond);
B
blueswir1 已提交
1963 1964 1965 1966 1967 1968 1969
                    else
                        goto illegal_insn;
                    goto jmp_insn;
                }
            case 0x3:           /* V9 BPr */
                {
                    target = GET_FIELD_SP(insn, 0, 13) |
1970
                        (GET_FIELD_SP(insn, 20, 21) << 14);
B
blueswir1 已提交
1971 1972
                    target = sign_extend(target, 16);
                    target <<= 2;
1973
                    cpu_src1 = get_src1(insn, cpu_src1);
1974
                    do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
B
blueswir1 已提交
1975 1976 1977 1978 1979
                    goto jmp_insn;
                }
            case 0x5:           /* V9 FBPcc */
                {
                    int cc = GET_FIELD_SP(insn, 20, 21);
1980
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
1981
                        goto jmp_insn;
B
blueswir1 已提交
1982 1983 1984
                    target = GET_FIELD_SP(insn, 0, 18);
                    target = sign_extend(target, 19);
                    target <<= 2;
1985
                    do_fbranch(dc, target, insn, cc, cpu_cond);
B
blueswir1 已提交
1986 1987
                    goto jmp_insn;
                }
1988
#else
B
blueswir1 已提交
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
            case 0x7:           /* CBN+x */
                {
                    goto ncp_insn;
                }
#endif
            case 0x2:           /* BN+x */
                {
                    target = GET_FIELD(insn, 10, 31);
                    target = sign_extend(target, 22);
                    target <<= 2;
1999
                    do_branch(dc, target, insn, 0, cpu_cond);
B
blueswir1 已提交
2000 2001 2002 2003
                    goto jmp_insn;
                }
            case 0x6:           /* FBN+x */
                {
2004
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2005
                        goto jmp_insn;
B
blueswir1 已提交
2006 2007 2008
                    target = GET_FIELD(insn, 10, 31);
                    target = sign_extend(target, 22);
                    target <<= 2;
2009
                    do_fbranch(dc, target, insn, 0, cpu_cond);
B
blueswir1 已提交
2010 2011 2012 2013 2014
                    goto jmp_insn;
                }
            case 0x4:           /* SETHI */
                if (rd) { // nop
                    uint32_t value = GET_FIELD(insn, 10, 31);
B
blueswir1 已提交
2015 2016 2017 2018 2019
                    TCGv r_const;

                    r_const = tcg_const_tl(value << 10);
                    gen_movl_TN_reg(rd, r_const);
                    tcg_temp_free(r_const);
B
blueswir1 已提交
2020 2021 2022 2023
                }
                break;
            case 0x0:           /* UNIMPL */
            default:
B
bellard 已提交
2024
                goto illegal_insn;
B
blueswir1 已提交
2025 2026 2027 2028
            }
            break;
        }
        break;
2029
    case 1:
B
blueswir1 已提交
2030 2031
        /*CALL*/ {
            target_long target = GET_FIELDs(insn, 2, 31) << 2;
B
blueswir1 已提交
2032
            TCGv r_const;
2033

B
blueswir1 已提交
2034 2035 2036
            r_const = tcg_const_tl(dc->pc);
            gen_movl_TN_reg(15, r_const);
            tcg_temp_free(r_const);
B
blueswir1 已提交
2037
            target += dc->pc;
2038
            gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
2039 2040 2041 2042 2043 2044 2045
            dc->npc = target;
        }
        goto jmp_insn;
    case 2:                     /* FPU & Logical Operations */
        {
            unsigned int xop = GET_FIELD(insn, 7, 12);
            if (xop == 0x3a) {  /* generate trap */
2046
                int cond;
B
bellard 已提交
2047

2048
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
2049 2050
                if (IS_IMM) {
                    rs2 = GET_FIELD(insn, 25, 31);
2051
                    tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
2052 2053
                } else {
                    rs2 = GET_FIELD(insn, 27, 31);
B
blueswir1 已提交
2054
                    if (rs2 != 0) {
2055 2056
                        gen_movl_reg_TN(rs2, cpu_src2);
                        tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2057 2058
                    } else
                        tcg_gen_mov_tl(cpu_dst, cpu_src1);
2059 2060 2061
                }
                cond = GET_FIELD(insn, 3, 6);
                if (cond == 0x8) {
2062
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
2063 2064 2065 2066 2067 2068
                    if ((dc->def->features & CPU_FEATURE_HYPV) &&
                        supervisor(dc))
                        tcg_gen_andi_tl(cpu_dst, cpu_dst, UA2005_HTRAP_MASK);
                    else
                        tcg_gen_andi_tl(cpu_dst, cpu_dst, V8_TRAP_MASK);
                    tcg_gen_addi_tl(cpu_dst, cpu_dst, TT_TRAP);
P
pbrook 已提交
2069 2070
                    tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
                    gen_helper_raise_exception(cpu_tmp32);
2071
                } else if (cond != 0) {
P
pbrook 已提交
2072
                    TCGv r_cond = tcg_temp_new();
B
blueswir1 已提交
2073
                    int l1;
B
bellard 已提交
2074
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2075 2076
                    /* V9 icc/xcc */
                    int cc = GET_FIELD_SP(insn, 11, 12);
B
blueswir1 已提交
2077

2078
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
2079
                    if (cc == 0)
B
blueswir1 已提交
2080
                        gen_cond(r_cond, 0, cond);
B
blueswir1 已提交
2081
                    else if (cc == 2)
B
blueswir1 已提交
2082
                        gen_cond(r_cond, 1, cond);
B
blueswir1 已提交
2083 2084
                    else
                        goto illegal_insn;
B
bellard 已提交
2085
#else
2086
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
2087
                    gen_cond(r_cond, 0, cond);
B
bellard 已提交
2088
#endif
B
blueswir1 已提交
2089 2090 2091 2092 2093 2094 2095 2096 2097
                    l1 = gen_new_label();
                    tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);

                    if ((dc->def->features & CPU_FEATURE_HYPV) &&
                        supervisor(dc))
                        tcg_gen_andi_tl(cpu_dst, cpu_dst, UA2005_HTRAP_MASK);
                    else
                        tcg_gen_andi_tl(cpu_dst, cpu_dst, V8_TRAP_MASK);
                    tcg_gen_addi_tl(cpu_dst, cpu_dst, TT_TRAP);
P
pbrook 已提交
2098 2099
                    tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
                    gen_helper_raise_exception(cpu_tmp32);
B
blueswir1 已提交
2100 2101

                    gen_set_label(l1);
B
blueswir1 已提交
2102
                    tcg_temp_free(r_cond);
2103
                }
B
bellard 已提交
2104
                gen_op_next_insn();
B
bellard 已提交
2105
                tcg_gen_exit_tb(0);
B
bellard 已提交
2106 2107
                dc->is_br = 1;
                goto jmp_insn;
2108 2109 2110 2111
            } else if (xop == 0x28) {
                rs1 = GET_FIELD(insn, 13, 17);
                switch(rs1) {
                case 0: /* rdy */
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121
#ifndef TARGET_SPARC64
                case 0x01 ... 0x0e: /* undefined in the SPARCv8
                                       manual, rdy on the microSPARC
                                       II */
                case 0x0f:          /* stbar in the SPARCv8 manual,
                                       rdy on the microSPARC II */
                case 0x10 ... 0x1f: /* implementation-dependent in the
                                       SPARCv8 manual, rdy on the
                                       microSPARC II */
#endif
2122
                    gen_movl_TN_reg(rd, cpu_y);
2123
                    break;
B
bellard 已提交
2124
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2125
                case 0x2: /* V9 rdccr */
P
pbrook 已提交
2126
                    gen_helper_rdccr(cpu_dst);
2127
                    gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
2128
                    break;
B
blueswir1 已提交
2129
                case 0x3: /* V9 rdasi */
2130
                    tcg_gen_ext_i32_tl(cpu_dst, cpu_asi);
2131
                    gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
2132
                    break;
B
blueswir1 已提交
2133
                case 0x4: /* V9 rdtick */
B
blueswir1 已提交
2134
                    {
P
pbrook 已提交
2135
                        TCGv_ptr r_tickptr;
B
blueswir1 已提交
2136

P
pbrook 已提交
2137
                        r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
2138 2139
                        tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                       offsetof(CPUState, tick));
P
pbrook 已提交
2140 2141
                        gen_helper_tick_get_count(cpu_dst, r_tickptr);
                        tcg_temp_free_ptr(r_tickptr);
2142
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
2143
                    }
B
bellard 已提交
2144
                    break;
B
blueswir1 已提交
2145
                case 0x5: /* V9 rdpc */
B
blueswir1 已提交
2146 2147 2148 2149 2150 2151 2152
                    {
                        TCGv r_const;

                        r_const = tcg_const_tl(dc->pc);
                        gen_movl_TN_reg(rd, r_const);
                        tcg_temp_free(r_const);
                    }
B
blueswir1 已提交
2153 2154
                    break;
                case 0x6: /* V9 rdfprs */
2155
                    tcg_gen_ext_i32_tl(cpu_dst, cpu_fprs);
2156
                    gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
2157
                    break;
2158 2159
                case 0xf: /* V9 membar */
                    break; /* no effect */
B
blueswir1 已提交
2160
                case 0x13: /* Graphics Status */
2161
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2162
                        goto jmp_insn;
2163
                    gen_movl_TN_reg(rd, cpu_gsr);
B
bellard 已提交
2164
                    break;
2165 2166 2167 2168
                case 0x16: /* Softint */
                    tcg_gen_ext_i32_tl(cpu_dst, cpu_softint);
                    gen_movl_TN_reg(rd, cpu_dst);
                    break;
B
blueswir1 已提交
2169
                case 0x17: /* Tick compare */
2170
                    gen_movl_TN_reg(rd, cpu_tick_cmpr);
B
bellard 已提交
2171
                    break;
B
blueswir1 已提交
2172
                case 0x18: /* System tick */
B
blueswir1 已提交
2173
                    {
P
pbrook 已提交
2174
                        TCGv_ptr r_tickptr;
B
blueswir1 已提交
2175

P
pbrook 已提交
2176
                        r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
2177 2178
                        tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                       offsetof(CPUState, stick));
P
pbrook 已提交
2179 2180
                        gen_helper_tick_get_count(cpu_dst, r_tickptr);
                        tcg_temp_free_ptr(r_tickptr);
2181
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
2182
                    }
B
bellard 已提交
2183
                    break;
B
blueswir1 已提交
2184
                case 0x19: /* System tick compare */
2185
                    gen_movl_TN_reg(rd, cpu_stick_cmpr);
B
bellard 已提交
2186
                    break;
B
blueswir1 已提交
2187 2188 2189 2190 2191
                case 0x10: /* Performance Control */
                case 0x11: /* Performance Instrumentation Counter */
                case 0x12: /* Dispatch Control */
                case 0x14: /* Softint set, WO */
                case 0x15: /* Softint clear, WO */
B
bellard 已提交
2192 2193
#endif
                default:
2194 2195
                    goto illegal_insn;
                }
2196
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
2197
            } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
B
bellard 已提交
2198
#ifndef TARGET_SPARC64
B
blueswir1 已提交
2199 2200
                if (!supervisor(dc))
                    goto priv_insn;
P
pbrook 已提交
2201
                gen_helper_rdpsr(cpu_dst);
B
blueswir1 已提交
2202
#else
2203
                CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214
                if (!hypervisor(dc))
                    goto priv_insn;
                rs1 = GET_FIELD(insn, 13, 17);
                switch (rs1) {
                case 0: // hpstate
                    // gen_op_rdhpstate();
                    break;
                case 1: // htstate
                    // gen_op_rdhtstate();
                    break;
                case 3: // hintp
2215
                    tcg_gen_mov_tl(cpu_dst, cpu_hintp);
B
blueswir1 已提交
2216 2217
                    break;
                case 5: // htba
2218
                    tcg_gen_mov_tl(cpu_dst, cpu_htba);
B
blueswir1 已提交
2219 2220
                    break;
                case 6: // hver
2221
                    tcg_gen_mov_tl(cpu_dst, cpu_hver);
B
blueswir1 已提交
2222 2223
                    break;
                case 31: // hstick_cmpr
2224
                    tcg_gen_mov_tl(cpu_dst, cpu_hstick_cmpr);
B
blueswir1 已提交
2225 2226 2227 2228 2229
                    break;
                default:
                    goto illegal_insn;
                }
#endif
2230
                gen_movl_TN_reg(rd, cpu_dst);
2231
                break;
B
bellard 已提交
2232
            } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
B
blueswir1 已提交
2233 2234
                if (!supervisor(dc))
                    goto priv_insn;
B
bellard 已提交
2235 2236
#ifdef TARGET_SPARC64
                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
2237 2238
                switch (rs1) {
                case 0: // tpc
2239
                    {
P
pbrook 已提交
2240
                        TCGv_ptr r_tsptr;
2241

P
pbrook 已提交
2242
                        r_tsptr = tcg_temp_new_ptr();
2243 2244
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
P
pbrook 已提交
2245
                        tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2246
                                      offsetof(trap_state, tpc));
P
pbrook 已提交
2247
                        tcg_temp_free_ptr(r_tsptr);
2248
                    }
B
blueswir1 已提交
2249 2250
                    break;
                case 1: // tnpc
2251
                    {
P
pbrook 已提交
2252
                        TCGv_ptr r_tsptr;
2253

P
pbrook 已提交
2254
                        r_tsptr = tcg_temp_new_ptr();
2255 2256
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
2257
                        tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2258
                                      offsetof(trap_state, tnpc));
P
pbrook 已提交
2259
                        tcg_temp_free_ptr(r_tsptr);
2260
                    }
B
blueswir1 已提交
2261 2262
                    break;
                case 2: // tstate
2263
                    {
P
pbrook 已提交
2264
                        TCGv_ptr r_tsptr;
2265

P
pbrook 已提交
2266
                        r_tsptr = tcg_temp_new_ptr();
2267 2268
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
2269
                        tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2270
                                      offsetof(trap_state, tstate));
P
pbrook 已提交
2271
                        tcg_temp_free_ptr(r_tsptr);
2272
                    }
B
blueswir1 已提交
2273 2274
                    break;
                case 3: // tt
2275
                    {
P
pbrook 已提交
2276
                        TCGv_ptr r_tsptr;
2277

P
pbrook 已提交
2278
                        r_tsptr = tcg_temp_new_ptr();
2279 2280
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
P
pbrook 已提交
2281
                        tcg_gen_ld_i32(cpu_tmp32, r_tsptr,
2282
                                       offsetof(trap_state, tt));
P
pbrook 已提交
2283 2284
                        tcg_temp_free_ptr(r_tsptr);
                        tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2285
                    }
B
blueswir1 已提交
2286 2287
                    break;
                case 4: // tick
B
blueswir1 已提交
2288
                    {
P
pbrook 已提交
2289
                        TCGv_ptr r_tickptr;
B
blueswir1 已提交
2290

P
pbrook 已提交
2291
                        r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
2292 2293
                        tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                       offsetof(CPUState, tick));
P
pbrook 已提交
2294
                        gen_helper_tick_get_count(cpu_tmp0, r_tickptr);
2295
                        gen_movl_TN_reg(rd, cpu_tmp0);
P
pbrook 已提交
2296
                        tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
2297
                    }
B
blueswir1 已提交
2298 2299
                    break;
                case 5: // tba
2300
                    tcg_gen_mov_tl(cpu_tmp0, cpu_tbr);
B
blueswir1 已提交
2301 2302
                    break;
                case 6: // pstate
B
blueswir1 已提交
2303 2304
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, pstate));
2305
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2306 2307
                    break;
                case 7: // tl
B
blueswir1 已提交
2308 2309
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, tl));
2310
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2311 2312
                    break;
                case 8: // pil
B
blueswir1 已提交
2313 2314
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, psrpil));
2315
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2316 2317
                    break;
                case 9: // cwp
P
pbrook 已提交
2318
                    gen_helper_rdcwp(cpu_tmp0);
B
blueswir1 已提交
2319 2320
                    break;
                case 10: // cansave
B
blueswir1 已提交
2321 2322
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, cansave));
2323
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2324 2325
                    break;
                case 11: // canrestore
B
blueswir1 已提交
2326 2327
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, canrestore));
2328
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2329 2330
                    break;
                case 12: // cleanwin
B
blueswir1 已提交
2331 2332
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, cleanwin));
2333
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2334 2335
                    break;
                case 13: // otherwin
B
blueswir1 已提交
2336 2337
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, otherwin));
2338
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2339 2340
                    break;
                case 14: // wstate
B
blueswir1 已提交
2341 2342
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, wstate));
2343
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2344
                    break;
B
blueswir1 已提交
2345
                case 16: // UA2005 gl
2346
                    CHECK_IU_FEATURE(dc, GL);
B
blueswir1 已提交
2347 2348
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, gl));
2349
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2350 2351
                    break;
                case 26: // UA2005 strand status
2352
                    CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
2353 2354
                    if (!hypervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
2355
                    tcg_gen_mov_tl(cpu_tmp0, cpu_ssr);
B
blueswir1 已提交
2356
                    break;
B
blueswir1 已提交
2357
                case 31: // ver
2358
                    tcg_gen_mov_tl(cpu_tmp0, cpu_ver);
B
blueswir1 已提交
2359 2360 2361 2362 2363
                    break;
                case 15: // fq
                default:
                    goto illegal_insn;
                }
B
bellard 已提交
2364
#else
2365
                tcg_gen_ext_i32_tl(cpu_tmp0, cpu_wim);
B
bellard 已提交
2366
#endif
2367
                gen_movl_TN_reg(rd, cpu_tmp0);
2368
                break;
B
bellard 已提交
2369 2370
            } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
#ifdef TARGET_SPARC64
2371
                save_state(dc, cpu_cond);
P
pbrook 已提交
2372
                gen_helper_flushw();
B
bellard 已提交
2373
#else
B
blueswir1 已提交
2374 2375
                if (!supervisor(dc))
                    goto priv_insn;
2376
                gen_movl_TN_reg(rd, cpu_tbr);
B
bellard 已提交
2377
#endif
2378 2379
                break;
#endif
B
blueswir1 已提交
2380
            } else if (xop == 0x34) {   /* FPU Operations */
2381
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2382
                    goto jmp_insn;
B
blueswir1 已提交
2383
                gen_op_clear_ieee_excp_and_FTT();
2384
                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
2385 2386 2387 2388
                rs2 = GET_FIELD(insn, 27, 31);
                xop = GET_FIELD(insn, 18, 26);
                switch (xop) {
                    case 0x1: /* fmovs */
B
blueswir1 已提交
2389
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2390 2391
                        break;
                    case 0x5: /* fnegs */
P
pbrook 已提交
2392
                        gen_helper_fnegs(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2393 2394
                        break;
                    case 0x9: /* fabss */
P
pbrook 已提交
2395
                        gen_helper_fabss(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2396 2397
                        break;
                    case 0x29: /* fsqrts */
B
blueswir1 已提交
2398
                        CHECK_FPU_FEATURE(dc, FSQRT);
2399
                        gen_clear_float_exceptions();
P
pbrook 已提交
2400 2401
                        gen_helper_fsqrts(cpu_tmp32, cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2402
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2403 2404
                        break;
                    case 0x2a: /* fsqrtd */
B
blueswir1 已提交
2405
                        CHECK_FPU_FEATURE(dc, FSQRT);
B
blueswir1 已提交
2406
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2407
                        gen_clear_float_exceptions();
P
pbrook 已提交
2408 2409
                        gen_helper_fsqrtd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2410 2411 2412
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x2b: /* fsqrtq */
B
blueswir1 已提交
2413
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2414
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2415
                        gen_clear_float_exceptions();
P
pbrook 已提交
2416 2417
                        gen_helper_fsqrtq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2418 2419
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2420
                    case 0x41: /* fadds */
2421
                        gen_clear_float_exceptions();
P
pbrook 已提交
2422 2423 2424
                        gen_helper_fadds(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2425
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2426 2427 2428 2429
                        break;
                    case 0x42:
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2430
                        gen_clear_float_exceptions();
P
pbrook 已提交
2431 2432
                        gen_helper_faddd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2433 2434 2435
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x43: /* faddq */
B
blueswir1 已提交
2436
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2437 2438
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2439
                        gen_clear_float_exceptions();
P
pbrook 已提交
2440 2441
                        gen_helper_faddq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2442 2443
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2444
                    case 0x45: /* fsubs */
2445
                        gen_clear_float_exceptions();
P
pbrook 已提交
2446 2447 2448
                        gen_helper_fsubs(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2449
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2450 2451 2452 2453
                        break;
                    case 0x46:
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2454
                        gen_clear_float_exceptions();
P
pbrook 已提交
2455 2456
                        gen_helper_fsubd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2457 2458 2459
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x47: /* fsubq */
B
blueswir1 已提交
2460
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2461 2462
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2463
                        gen_clear_float_exceptions();
P
pbrook 已提交
2464 2465
                        gen_helper_fsubq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2466 2467
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2468 2469
                    case 0x49: /* fmuls */
                        CHECK_FPU_FEATURE(dc, FMUL);
2470
                        gen_clear_float_exceptions();
P
pbrook 已提交
2471 2472 2473
                        gen_helper_fmuls(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2474
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2475
                        break;
B
blueswir1 已提交
2476 2477
                    case 0x4a: /* fmuld */
                        CHECK_FPU_FEATURE(dc, FMUL);
B
blueswir1 已提交
2478 2479
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2480
                        gen_clear_float_exceptions();
P
pbrook 已提交
2481 2482
                        gen_helper_fmuld();
                        gen_helper_check_ieee_exceptions();
2483
                        gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
2484 2485
                        break;
                    case 0x4b: /* fmulq */
B
blueswir1 已提交
2486 2487
                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        CHECK_FPU_FEATURE(dc, FMUL);
B
blueswir1 已提交
2488 2489
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2490
                        gen_clear_float_exceptions();
P
pbrook 已提交
2491 2492
                        gen_helper_fmulq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2493 2494
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2495
                    case 0x4d: /* fdivs */
2496
                        gen_clear_float_exceptions();
P
pbrook 已提交
2497 2498 2499
                        gen_helper_fdivs(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2500
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2501 2502 2503 2504
                        break;
                    case 0x4e:
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2505
                        gen_clear_float_exceptions();
P
pbrook 已提交
2506 2507
                        gen_helper_fdivd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2508 2509 2510
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x4f: /* fdivq */
B
blueswir1 已提交
2511
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2512 2513
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2514
                        gen_clear_float_exceptions();
P
pbrook 已提交
2515 2516
                        gen_helper_fdivq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2517 2518
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
2519
                    case 0x69: /* fsmuld */
B
blueswir1 已提交
2520
                        CHECK_FPU_FEATURE(dc, FSMULD);
2521
                        gen_clear_float_exceptions();
P
pbrook 已提交
2522 2523
                        gen_helper_fsmuld(cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2524 2525 2526
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x6e: /* fdmulq */
B
blueswir1 已提交
2527
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2528 2529
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2530
                        gen_clear_float_exceptions();
P
pbrook 已提交
2531 2532
                        gen_helper_fdmulq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2533 2534
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2535
                    case 0xc4: /* fitos */
2536
                        gen_clear_float_exceptions();
P
pbrook 已提交
2537 2538
                        gen_helper_fitos(cpu_tmp32, cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2539
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2540
                        break;
2541
                    case 0xc6: /* fdtos */
B
blueswir1 已提交
2542
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2543
                        gen_clear_float_exceptions();
P
pbrook 已提交
2544 2545
                        gen_helper_fdtos(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2546
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2547 2548
                        break;
                    case 0xc7: /* fqtos */
B
blueswir1 已提交
2549
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2550
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2551
                        gen_clear_float_exceptions();
P
pbrook 已提交
2552 2553
                        gen_helper_fqtos(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2554
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2555
                        break;
2556
                    case 0xc8: /* fitod */
P
pbrook 已提交
2557
                        gen_helper_fitod(cpu_fpr[rs2]);
B
blueswir1 已提交
2558 2559
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
2560
                    case 0xc9: /* fstod */
P
pbrook 已提交
2561
                        gen_helper_fstod(cpu_fpr[rs2]);
B
blueswir1 已提交
2562 2563 2564
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0xcb: /* fqtod */
B
blueswir1 已提交
2565
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2566
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2567
                        gen_clear_float_exceptions();
P
pbrook 已提交
2568 2569
                        gen_helper_fqtod();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2570 2571
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2572
                    case 0xcc: /* fitoq */
B
blueswir1 已提交
2573
                        CHECK_FPU_FEATURE(dc, FLOAT128);
P
pbrook 已提交
2574
                        gen_helper_fitoq(cpu_fpr[rs2]);
B
blueswir1 已提交
2575 2576
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2577
                    case 0xcd: /* fstoq */
B
blueswir1 已提交
2578
                        CHECK_FPU_FEATURE(dc, FLOAT128);
P
pbrook 已提交
2579
                        gen_helper_fstoq(cpu_fpr[rs2]);
B
blueswir1 已提交
2580 2581
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2582
                    case 0xce: /* fdtoq */
B
blueswir1 已提交
2583
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2584
                        gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
2585
                        gen_helper_fdtoq();
B
blueswir1 已提交
2586 2587
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2588
                    case 0xd1: /* fstoi */
2589
                        gen_clear_float_exceptions();
P
pbrook 已提交
2590 2591
                        gen_helper_fstoi(cpu_tmp32, cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2592
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2593
                        break;
2594
                    case 0xd2: /* fdtoi */
2595
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2596
                        gen_clear_float_exceptions();
P
pbrook 已提交
2597 2598
                        gen_helper_fdtoi(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2599
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2600 2601
                        break;
                    case 0xd3: /* fqtoi */
B
blueswir1 已提交
2602
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2603
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2604
                        gen_clear_float_exceptions();
P
pbrook 已提交
2605 2606
                        gen_helper_fqtoi(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2607
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2608
                        break;
B
bellard 已提交
2609
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2610
                    case 0x2: /* V9 fmovd */
B
blueswir1 已提交
2611 2612 2613 2614
                        tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)],
                                        cpu_fpr[DFPREG(rs2)]);
                        tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1],
                                        cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
2615
                        break;
B
blueswir1 已提交
2616
                    case 0x3: /* V9 fmovq */
B
blueswir1 已提交
2617
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2618 2619 2620 2621 2622 2623 2624 2625
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)],
                                        cpu_fpr[QFPREG(rs2)]);
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1],
                                        cpu_fpr[QFPREG(rs2) + 1]);
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2],
                                        cpu_fpr[QFPREG(rs2) + 2]);
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3],
                                        cpu_fpr[QFPREG(rs2) + 3]);
B
blueswir1 已提交
2626
                        break;
B
blueswir1 已提交
2627 2628
                    case 0x6: /* V9 fnegd */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
2629
                        gen_helper_fnegd();
B
blueswir1 已提交
2630 2631
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2632
                    case 0x7: /* V9 fnegq */
B
blueswir1 已提交
2633
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2634
                        gen_op_load_fpr_QT1(QFPREG(rs2));
P
pbrook 已提交
2635
                        gen_helper_fnegq();
B
blueswir1 已提交
2636 2637
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2638 2639
                    case 0xa: /* V9 fabsd */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
2640
                        gen_helper_fabsd();
B
blueswir1 已提交
2641 2642
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2643
                    case 0xb: /* V9 fabsq */
B
blueswir1 已提交
2644
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2645
                        gen_op_load_fpr_QT1(QFPREG(rs2));
P
pbrook 已提交
2646
                        gen_helper_fabsq();
B
blueswir1 已提交
2647 2648
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2649
                    case 0x81: /* V9 fstox */
2650
                        gen_clear_float_exceptions();
P
pbrook 已提交
2651 2652
                        gen_helper_fstox(cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2653 2654 2655 2656
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x82: /* V9 fdtox */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2657
                        gen_clear_float_exceptions();
P
pbrook 已提交
2658 2659
                        gen_helper_fdtox();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2660 2661
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2662
                    case 0x83: /* V9 fqtox */
B
blueswir1 已提交
2663
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2664
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2665
                        gen_clear_float_exceptions();
P
pbrook 已提交
2666 2667
                        gen_helper_fqtox();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2668 2669
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2670 2671
                    case 0x84: /* V9 fxtos */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2672
                        gen_clear_float_exceptions();
P
pbrook 已提交
2673 2674
                        gen_helper_fxtos(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2675
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2676 2677 2678
                        break;
                    case 0x88: /* V9 fxtod */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2679
                        gen_clear_float_exceptions();
P
pbrook 已提交
2680 2681
                        gen_helper_fxtod();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2682 2683 2684
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x8c: /* V9 fxtoq */
B
blueswir1 已提交
2685
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2686
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2687
                        gen_clear_float_exceptions();
P
pbrook 已提交
2688 2689
                        gen_helper_fxtoq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2690 2691
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2692 2693 2694 2695 2696
#endif
                    default:
                        goto illegal_insn;
                }
            } else if (xop == 0x35) {   /* FPU Operations */
B
bellard 已提交
2697
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2698
                int cond;
B
bellard 已提交
2699
#endif
2700
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2701
                    goto jmp_insn;
B
blueswir1 已提交
2702
                gen_op_clear_ieee_excp_and_FTT();
2703
                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
2704 2705
                rs2 = GET_FIELD(insn, 27, 31);
                xop = GET_FIELD(insn, 18, 26);
B
bellard 已提交
2706
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2707
                if ((xop & 0x11f) == 0x005) { // V9 fmovsr
B
blueswir1 已提交
2708 2709 2710
                    int l1;

                    l1 = gen_new_label();
B
blueswir1 已提交
2711
                    cond = GET_FIELD_SP(insn, 14, 17);
2712
                    cpu_src1 = get_src1(insn, cpu_src1);
P
pbrook 已提交
2713 2714
                    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
                                       0, l1);
B
blueswir1 已提交
2715
                    tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2716
                    gen_set_label(l1);
B
blueswir1 已提交
2717 2718
                    break;
                } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
B
blueswir1 已提交
2719 2720 2721
                    int l1;

                    l1 = gen_new_label();
B
blueswir1 已提交
2722
                    cond = GET_FIELD_SP(insn, 14, 17);
2723
                    cpu_src1 = get_src1(insn, cpu_src1);
P
pbrook 已提交
2724 2725
                    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
                                       0, l1);
B
blueswir1 已提交
2726 2727
                    tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1], cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
2728
                    gen_set_label(l1);
B
blueswir1 已提交
2729 2730
                    break;
                } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
B
blueswir1 已提交
2731 2732
                    int l1;

B
blueswir1 已提交
2733
                    CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2734
                    l1 = gen_new_label();
B
blueswir1 已提交
2735
                    cond = GET_FIELD_SP(insn, 14, 17);
2736
                    cpu_src1 = get_src1(insn, cpu_src1);
P
pbrook 已提交
2737 2738
                    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
                                       0, l1);
B
blueswir1 已提交
2739 2740 2741 2742
                    tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)], cpu_fpr[QFPREG(rs2)]);
                    tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1], cpu_fpr[QFPREG(rs2) + 1]);
                    tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2], cpu_fpr[QFPREG(rs2) + 2]);
                    tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3], cpu_fpr[QFPREG(rs2) + 3]);
B
blueswir1 已提交
2743
                    gen_set_label(l1);
B
blueswir1 已提交
2744
                    break;
B
blueswir1 已提交
2745 2746 2747
                }
#endif
                switch (xop) {
B
bellard 已提交
2748
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2749
#define FMOVSCC(fcc)                                                    \
2750
                    {                                                   \
2751
                        TCGv r_cond;                                    \
2752 2753 2754
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2755
                        r_cond = tcg_temp_new();             \
2756 2757
                        cond = GET_FIELD_SP(insn, 14, 17);              \
                        gen_fcond(r_cond, fcc, cond);                   \
P
pbrook 已提交
2758 2759
                        tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond,         \
                                           0, l1);                      \
B
blueswir1 已提交
2760 2761 2762 2763 2764 2765 2766 2767 2768 2769
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);     \
                        gen_set_label(l1);                              \
                        tcg_temp_free(r_cond);                          \
                    }
#define FMOVDCC(fcc)                                                    \
                    {                                                   \
                        TCGv r_cond;                                    \
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2770
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787
                        cond = GET_FIELD_SP(insn, 14, 17);              \
                        gen_fcond(r_cond, fcc, cond);                   \
                        tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond,         \
                                           0, l1);                      \
                        tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)],            \
                                        cpu_fpr[DFPREG(rs2)]);          \
                        tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1],        \
                                        cpu_fpr[DFPREG(rs2) + 1]);      \
                        gen_set_label(l1);                              \
                        tcg_temp_free(r_cond);                          \
                    }
#define FMOVQCC(fcc)                                                    \
                    {                                                   \
                        TCGv r_cond;                                    \
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2788
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800
                        cond = GET_FIELD_SP(insn, 14, 17);              \
                        gen_fcond(r_cond, fcc, cond);                   \
                        tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond,         \
                                           0, l1);                      \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)],            \
                                        cpu_fpr[QFPREG(rs2)]);          \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1],        \
                                        cpu_fpr[QFPREG(rs2) + 1]);      \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2],        \
                                        cpu_fpr[QFPREG(rs2) + 2]);      \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3],        \
                                        cpu_fpr[QFPREG(rs2) + 3]);      \
2801
                        gen_set_label(l1);                              \
B
blueswir1 已提交
2802
                        tcg_temp_free(r_cond);                          \
2803
                    }
B
blueswir1 已提交
2804
                    case 0x001: /* V9 fmovscc %fcc0 */
B
blueswir1 已提交
2805
                        FMOVSCC(0);
B
blueswir1 已提交
2806 2807
                        break;
                    case 0x002: /* V9 fmovdcc %fcc0 */
B
blueswir1 已提交
2808
                        FMOVDCC(0);
B
blueswir1 已提交
2809 2810
                        break;
                    case 0x003: /* V9 fmovqcc %fcc0 */
B
blueswir1 已提交
2811
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2812
                        FMOVQCC(0);
B
blueswir1 已提交
2813
                        break;
B
blueswir1 已提交
2814
                    case 0x041: /* V9 fmovscc %fcc1 */
B
blueswir1 已提交
2815
                        FMOVSCC(1);
B
blueswir1 已提交
2816 2817
                        break;
                    case 0x042: /* V9 fmovdcc %fcc1 */
B
blueswir1 已提交
2818
                        FMOVDCC(1);
B
blueswir1 已提交
2819 2820
                        break;
                    case 0x043: /* V9 fmovqcc %fcc1 */
B
blueswir1 已提交
2821
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2822
                        FMOVQCC(1);
B
blueswir1 已提交
2823
                        break;
B
blueswir1 已提交
2824
                    case 0x081: /* V9 fmovscc %fcc2 */
B
blueswir1 已提交
2825
                        FMOVSCC(2);
B
blueswir1 已提交
2826 2827
                        break;
                    case 0x082: /* V9 fmovdcc %fcc2 */
B
blueswir1 已提交
2828
                        FMOVDCC(2);
B
blueswir1 已提交
2829 2830
                        break;
                    case 0x083: /* V9 fmovqcc %fcc2 */
B
blueswir1 已提交
2831
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2832
                        FMOVQCC(2);
B
blueswir1 已提交
2833
                        break;
B
blueswir1 已提交
2834
                    case 0x0c1: /* V9 fmovscc %fcc3 */
B
blueswir1 已提交
2835
                        FMOVSCC(3);
B
blueswir1 已提交
2836 2837
                        break;
                    case 0x0c2: /* V9 fmovdcc %fcc3 */
B
blueswir1 已提交
2838
                        FMOVDCC(3);
B
blueswir1 已提交
2839 2840
                        break;
                    case 0x0c3: /* V9 fmovqcc %fcc3 */
B
blueswir1 已提交
2841
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2842
                        FMOVQCC(3);
B
blueswir1 已提交
2843
                        break;
B
blueswir1 已提交
2844 2845 2846 2847 2848 2849 2850 2851 2852
#undef FMOVSCC
#undef FMOVDCC
#undef FMOVQCC
#define FMOVSCC(icc)                                                    \
                    {                                                   \
                        TCGv r_cond;                                    \
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2853
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867
                        cond = GET_FIELD_SP(insn, 14, 17);              \
                        gen_cond(r_cond, icc, cond);                    \
                        tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond,         \
                                           0, l1);                      \
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);     \
                        gen_set_label(l1);                              \
                        tcg_temp_free(r_cond);                          \
                    }
#define FMOVDCC(icc)                                                    \
                    {                                                   \
                        TCGv r_cond;                                    \
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2868
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885
                        cond = GET_FIELD_SP(insn, 14, 17);              \
                        gen_cond(r_cond, icc, cond);                    \
                        tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond,         \
                                           0, l1);                      \
                        tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)],            \
                                        cpu_fpr[DFPREG(rs2)]);          \
                        tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1],        \
                                        cpu_fpr[DFPREG(rs2) + 1]);      \
                        gen_set_label(l1);                              \
                        tcg_temp_free(r_cond);                          \
                    }
#define FMOVQCC(icc)                                                    \
                    {                                                   \
                        TCGv r_cond;                                    \
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2886
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901
                        cond = GET_FIELD_SP(insn, 14, 17);              \
                        gen_cond(r_cond, icc, cond);                    \
                        tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond,         \
                                           0, l1);                      \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)],            \
                                        cpu_fpr[QFPREG(rs2)]);          \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1],        \
                                        cpu_fpr[QFPREG(rs2) + 1]);      \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2],        \
                                        cpu_fpr[QFPREG(rs2) + 2]);      \
                        tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3],        \
                                        cpu_fpr[QFPREG(rs2) + 3]);      \
                        gen_set_label(l1);                              \
                        tcg_temp_free(r_cond);                          \
                    }
2902

B
blueswir1 已提交
2903
                    case 0x101: /* V9 fmovscc %icc */
B
blueswir1 已提交
2904
                        FMOVSCC(0);
B
blueswir1 已提交
2905 2906
                        break;
                    case 0x102: /* V9 fmovdcc %icc */
B
blueswir1 已提交
2907
                        FMOVDCC(0);
B
blueswir1 已提交
2908
                    case 0x103: /* V9 fmovqcc %icc */
B
blueswir1 已提交
2909
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2910
                        FMOVQCC(0);
B
blueswir1 已提交
2911
                        break;
B
blueswir1 已提交
2912
                    case 0x181: /* V9 fmovscc %xcc */
B
blueswir1 已提交
2913
                        FMOVSCC(1);
B
blueswir1 已提交
2914 2915
                        break;
                    case 0x182: /* V9 fmovdcc %xcc */
B
blueswir1 已提交
2916
                        FMOVDCC(1);
B
blueswir1 已提交
2917 2918
                        break;
                    case 0x183: /* V9 fmovqcc %xcc */
B
blueswir1 已提交
2919
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2920
                        FMOVQCC(1);
B
blueswir1 已提交
2921
                        break;
B
blueswir1 已提交
2922 2923 2924
#undef FMOVSCC
#undef FMOVDCC
#undef FMOVQCC
B
blueswir1 已提交
2925 2926
#endif
                    case 0x51: /* fcmps, V9 %fcc */
B
blueswir1 已提交
2927
                        gen_op_fcmps(rd & 3, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
2928
                        break;
B
blueswir1 已提交
2929
                    case 0x52: /* fcmpd, V9 %fcc */
B
blueswir1 已提交
2930 2931
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2932
                        gen_op_fcmpd(rd & 3);
B
blueswir1 已提交
2933
                        break;
B
blueswir1 已提交
2934
                    case 0x53: /* fcmpq, V9 %fcc */
B
blueswir1 已提交
2935
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2936 2937
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2938
                        gen_op_fcmpq(rd & 3);
B
blueswir1 已提交
2939
                        break;
B
blueswir1 已提交
2940
                    case 0x55: /* fcmpes, V9 %fcc */
B
blueswir1 已提交
2941
                        gen_op_fcmpes(rd & 3, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
2942 2943 2944 2945
                        break;
                    case 0x56: /* fcmped, V9 %fcc */
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2946
                        gen_op_fcmped(rd & 3);
B
blueswir1 已提交
2947
                        break;
B
blueswir1 已提交
2948
                    case 0x57: /* fcmpeq, V9 %fcc */
B
blueswir1 已提交
2949
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2950 2951
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2952
                        gen_op_fcmpeq(rd & 3);
B
blueswir1 已提交
2953
                        break;
B
blueswir1 已提交
2954 2955 2956 2957 2958
                    default:
                        goto illegal_insn;
                }
            } else if (xop == 0x2) {
                // clr/mov shortcut
B
bellard 已提交
2959 2960

                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
2961
                if (rs1 == 0) {
B
blueswir1 已提交
2962
                    // or %g0, x, y -> mov T0, x; mov y, T0
B
blueswir1 已提交
2963
                    if (IS_IMM) {       /* immediate */
B
blueswir1 已提交
2964 2965
                        TCGv r_const;

B
blueswir1 已提交
2966
                        rs2 = GET_FIELDs(insn, 19, 31);
B
blueswir1 已提交
2967 2968 2969
                        r_const = tcg_const_tl((int)rs2);
                        gen_movl_TN_reg(rd, r_const);
                        tcg_temp_free(r_const);
B
blueswir1 已提交
2970 2971
                    } else {            /* register */
                        rs2 = GET_FIELD(insn, 27, 31);
2972
                        gen_movl_reg_TN(rs2, cpu_dst);
B
blueswir1 已提交
2973
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
2974 2975
                    }
                } else {
2976
                    cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
2977 2978
                    if (IS_IMM) {       /* immediate */
                        rs2 = GET_FIELDs(insn, 19, 31);
2979
                        tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
B
blueswir1 已提交
2980
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
2981 2982 2983 2984
                    } else {            /* register */
                        // or x, %g0, y -> mov T1, x; mov y, T1
                        rs2 = GET_FIELD(insn, 27, 31);
                        if (rs2 != 0) {
2985 2986
                            gen_movl_reg_TN(rs2, cpu_src2);
                            tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
B
blueswir1 已提交
2987
                            gen_movl_TN_reg(rd, cpu_dst);
2988
                        } else
B
blueswir1 已提交
2989
                            gen_movl_TN_reg(rd, cpu_src1);
B
blueswir1 已提交
2990 2991
                    }
                }
B
bellard 已提交
2992
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2993
            } else if (xop == 0x25) { /* sll, V9 sllx */
2994
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
2995
                if (IS_IMM) {   /* immediate */
B
bellard 已提交
2996
                    rs2 = GET_FIELDs(insn, 20, 31);
B
blueswir1 已提交
2997
                    if (insn & (1 << 12)) {
2998
                        tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
B
blueswir1 已提交
2999
                    } else {
B
blueswir1 已提交
3000
                        tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x1f);
B
blueswir1 已提交
3001
                    }
B
blueswir1 已提交
3002
                } else {                /* register */
B
bellard 已提交
3003
                    rs2 = GET_FIELD(insn, 27, 31);
3004
                    gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
3005
                    if (insn & (1 << 12)) {
3006
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
B
blueswir1 已提交
3007
                    } else {
3008
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
B
blueswir1 已提交
3009
                    }
B
blueswir1 已提交
3010
                    tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
B
bellard 已提交
3011
                }
3012
                gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3013
            } else if (xop == 0x26) { /* srl, V9 srlx */
3014
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
3015
                if (IS_IMM) {   /* immediate */
B
bellard 已提交
3016
                    rs2 = GET_FIELDs(insn, 20, 31);
B
blueswir1 已提交
3017
                    if (insn & (1 << 12)) {
3018
                        tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
B
blueswir1 已提交
3019
                    } else {
3020 3021
                        tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
                        tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
B
blueswir1 已提交
3022
                    }
B
blueswir1 已提交
3023
                } else {                /* register */
B
bellard 已提交
3024
                    rs2 = GET_FIELD(insn, 27, 31);
3025
                    gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
3026
                    if (insn & (1 << 12)) {
3027 3028
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
                        tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
B
blueswir1 已提交
3029
                    } else {
3030 3031 3032
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
                        tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
                        tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
B
blueswir1 已提交
3033
                    }
B
bellard 已提交
3034
                }
3035
                gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3036
            } else if (xop == 0x27) { /* sra, V9 srax */
3037
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
3038
                if (IS_IMM) {   /* immediate */
B
bellard 已提交
3039
                    rs2 = GET_FIELDs(insn, 20, 31);
B
blueswir1 已提交
3040
                    if (insn & (1 << 12)) {
3041
                        tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
B
blueswir1 已提交
3042
                    } else {
3043
                        tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
B
blueswir1 已提交
3044
                        tcg_gen_ext32s_i64(cpu_dst, cpu_dst);
3045
                        tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
B
blueswir1 已提交
3046
                    }
B
blueswir1 已提交
3047
                } else {                /* register */
B
bellard 已提交
3048
                    rs2 = GET_FIELD(insn, 27, 31);
3049
                    gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
3050
                    if (insn & (1 << 12)) {
3051 3052
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
                        tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
B
blueswir1 已提交
3053
                    } else {
3054 3055
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
                        tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
B
blueswir1 已提交
3056
                        tcg_gen_ext32s_i64(cpu_dst, cpu_dst);
3057
                        tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
B
blueswir1 已提交
3058
                    }
B
bellard 已提交
3059
                }
3060
                gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
3061
#endif
3062
            } else if (xop < 0x36) {
3063
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
3064
                cpu_src2 = get_src2(insn, cpu_src2);
3065 3066 3067 3068
                if (xop < 0x20) {
                    switch (xop & ~0x10) {
                    case 0x0:
                        if (xop & 0x10)
3069
                            gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
3070
                        else
3071
                            tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3072 3073
                        break;
                    case 0x1:
3074
                        tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
3075
                        if (xop & 0x10)
3076
                            gen_op_logic_cc(cpu_dst);
3077 3078
                        break;
                    case 0x2:
3079
                        tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
B
blueswir1 已提交
3080
                        if (xop & 0x10)
3081
                            gen_op_logic_cc(cpu_dst);
B
blueswir1 已提交
3082
                        break;
3083
                    case 0x3:
3084
                        tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3085
                        if (xop & 0x10)
3086
                            gen_op_logic_cc(cpu_dst);
3087 3088 3089
                        break;
                    case 0x4:
                        if (xop & 0x10)
3090
                            gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
3091
                        else
3092
                            tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
3093 3094
                        break;
                    case 0x5:
B
blueswir1 已提交
3095
                        tcg_gen_andc_tl(cpu_dst, cpu_src1, cpu_src2);
3096
                        if (xop & 0x10)
3097
                            gen_op_logic_cc(cpu_dst);
3098 3099
                        break;
                    case 0x6:
B
blueswir1 已提交
3100
                        tcg_gen_orc_tl(cpu_dst, cpu_src1, cpu_src2);
3101
                        if (xop & 0x10)
3102
                            gen_op_logic_cc(cpu_dst);
3103 3104
                        break;
                    case 0x7:
B
blueswir1 已提交
3105
                        tcg_gen_not_tl(cpu_tmp0, cpu_src2);
3106
                        tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
3107
                        if (xop & 0x10)
3108
                            gen_op_logic_cc(cpu_dst);
3109 3110 3111
                        break;
                    case 0x8:
                        if (xop & 0x10)
3112
                            gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3113
                        else {
3114
                            gen_mov_reg_C(cpu_tmp0, cpu_psr);
3115 3116
                            tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
                            tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3117
                        }
3118
                        break;
P
pbrook 已提交
3119
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3120
                    case 0x9: /* V9 mulx */
3121
                        tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
P
pbrook 已提交
3122 3123
                        break;
#endif
3124
                    case 0xa:
B
blueswir1 已提交
3125
                        CHECK_IU_FEATURE(dc, MUL);
3126
                        gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3127
                        if (xop & 0x10)
3128
                            gen_op_logic_cc(cpu_dst);
3129 3130
                        break;
                    case 0xb:
B
blueswir1 已提交
3131
                        CHECK_IU_FEATURE(dc, MUL);
3132
                        gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3133
                        if (xop & 0x10)
3134
                            gen_op_logic_cc(cpu_dst);
3135 3136 3137
                        break;
                    case 0xc:
                        if (xop & 0x10)
3138
                            gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3139
                        else {
3140
                            gen_mov_reg_C(cpu_tmp0, cpu_psr);
3141 3142
                            tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
                            tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3143
                        }
3144
                        break;
P
pbrook 已提交
3145
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3146
                    case 0xd: /* V9 udivx */
3147 3148 3149 3150
                        tcg_gen_mov_tl(cpu_cc_src, cpu_src1);
                        tcg_gen_mov_tl(cpu_cc_src2, cpu_src2);
                        gen_trap_ifdivzero_tl(cpu_cc_src2);
                        tcg_gen_divu_i64(cpu_dst, cpu_cc_src, cpu_cc_src2);
P
pbrook 已提交
3151 3152
                        break;
#endif
3153
                    case 0xe:
B
blueswir1 已提交
3154
                        CHECK_IU_FEATURE(dc, DIV);
P
pbrook 已提交
3155
                        gen_helper_udiv(cpu_dst, cpu_src1, cpu_src2);
3156
                        if (xop & 0x10)
3157
                            gen_op_div_cc(cpu_dst);
3158 3159
                        break;
                    case 0xf:
B
blueswir1 已提交
3160
                        CHECK_IU_FEATURE(dc, DIV);
P
pbrook 已提交
3161
                        gen_helper_sdiv(cpu_dst, cpu_src1, cpu_src2);
3162
                        if (xop & 0x10)
3163
                            gen_op_div_cc(cpu_dst);
3164 3165 3166 3167
                        break;
                    default:
                        goto illegal_insn;
                    }
3168
                    gen_movl_TN_reg(rd, cpu_dst);
3169 3170
                } else {
                    switch (xop) {
B
blueswir1 已提交
3171
                    case 0x20: /* taddcc */
3172 3173
                        gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3174 3175
                        break;
                    case 0x21: /* tsubcc */
3176 3177
                        gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3178 3179
                        break;
                    case 0x22: /* taddcctv */
3180 3181 3182
                        save_state(dc, cpu_cond);
                        gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3183 3184
                        break;
                    case 0x23: /* tsubcctv */
3185 3186 3187
                        save_state(dc, cpu_cond);
                        gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3188
                        break;
3189
                    case 0x24: /* mulscc */
3190 3191
                        gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
3192
                        break;
B
bellard 已提交
3193
#ifndef TARGET_SPARC64
B
blueswir1 已提交
3194
                    case 0x25:  /* sll */
3195 3196 3197 3198 3199 3200 3201
                        if (IS_IMM) { /* immediate */
                            rs2 = GET_FIELDs(insn, 20, 31);
                            tcg_gen_shli_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
                        } else { /* register */
                            tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
                            tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
                        }
3202
                        gen_movl_TN_reg(rd, cpu_dst);
3203
                        break;
B
bellard 已提交
3204
                    case 0x26:  /* srl */
3205 3206 3207 3208 3209 3210 3211
                        if (IS_IMM) { /* immediate */
                            rs2 = GET_FIELDs(insn, 20, 31);
                            tcg_gen_shri_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
                        } else { /* register */
                            tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
                            tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
                        }
3212
                        gen_movl_TN_reg(rd, cpu_dst);
3213
                        break;
B
bellard 已提交
3214
                    case 0x27:  /* sra */
3215 3216 3217 3218 3219 3220 3221
                        if (IS_IMM) { /* immediate */
                            rs2 = GET_FIELDs(insn, 20, 31);
                            tcg_gen_sari_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
                        } else { /* register */
                            tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
                            tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
                        }
3222
                        gen_movl_TN_reg(rd, cpu_dst);
3223
                        break;
B
bellard 已提交
3224
#endif
3225 3226 3227
                    case 0x30:
                        {
                            switch(rd) {
B
bellard 已提交
3228
                            case 0: /* wry */
3229 3230
                                tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
                                tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
3231
                                break;
3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242
#ifndef TARGET_SPARC64
                            case 0x01 ... 0x0f: /* undefined in the
                                                   SPARCv8 manual, nop
                                                   on the microSPARC
                                                   II */
                            case 0x10 ... 0x1f: /* implementation-dependent
                                                   in the SPARCv8
                                                   manual, nop on the
                                                   microSPARC II */
                                break;
#else
B
blueswir1 已提交
3243
                            case 0x2: /* V9 wrccr */
3244
                                tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
P
pbrook 已提交
3245
                                gen_helper_wrccr(cpu_dst);
B
blueswir1 已提交
3246 3247
                                break;
                            case 0x3: /* V9 wrasi */
3248
                                tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3249
                                tcg_gen_trunc_tl_i32(cpu_asi, cpu_dst);
B
blueswir1 已提交
3250 3251
                                break;
                            case 0x6: /* V9 wrfprs */
3252
                                tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3253
                                tcg_gen_trunc_tl_i32(cpu_fprs, cpu_dst);
3254
                                save_state(dc, cpu_cond);
3255
                                gen_op_next_insn();
B
bellard 已提交
3256
                                tcg_gen_exit_tb(0);
3257
                                dc->is_br = 1;
B
blueswir1 已提交
3258 3259
                                break;
                            case 0xf: /* V9 sir, nop if user */
B
bellard 已提交
3260
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3261
                                if (supervisor(dc))
B
blueswir1 已提交
3262
                                    ; // XXX
B
bellard 已提交
3263
#endif
B
blueswir1 已提交
3264 3265
                                break;
                            case 0x13: /* Graphics Status */
3266
                                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
3267
                                    goto jmp_insn;
3268
                                tcg_gen_xor_tl(cpu_gsr, cpu_src1, cpu_src2);
B
blueswir1 已提交
3269
                                break;
3270 3271 3272 3273
                            case 0x14: /* Softint set */
                                if (!supervisor(dc))
                                    goto illegal_insn;
                                tcg_gen_xor_tl(cpu_tmp64, cpu_src1, cpu_src2);
P
pbrook 已提交
3274
                                gen_helper_set_softint(cpu_tmp64);
3275 3276 3277 3278 3279
                                break;
                            case 0x15: /* Softint clear */
                                if (!supervisor(dc))
                                    goto illegal_insn;
                                tcg_gen_xor_tl(cpu_tmp64, cpu_src1, cpu_src2);
P
pbrook 已提交
3280
                                gen_helper_clear_softint(cpu_tmp64);
3281 3282 3283 3284 3285
                                break;
                            case 0x16: /* Softint write */
                                if (!supervisor(dc))
                                    goto illegal_insn;
                                tcg_gen_xor_tl(cpu_tmp64, cpu_src1, cpu_src2);
P
pbrook 已提交
3286
                                gen_helper_write_softint(cpu_tmp64);
3287
                                break;
B
blueswir1 已提交
3288
                            case 0x17: /* Tick compare */
B
bellard 已提交
3289
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3290 3291
                                if (!supervisor(dc))
                                    goto illegal_insn;
B
bellard 已提交
3292
#endif
B
blueswir1 已提交
3293
                                {
P
pbrook 已提交
3294
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3295

3296
                                    tcg_gen_xor_tl(cpu_tick_cmpr, cpu_src1,
3297
                                                   cpu_src2);
P
pbrook 已提交
3298
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3299 3300
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, tick));
P
pbrook 已提交
3301 3302 3303
                                    gen_helper_tick_set_limit(r_tickptr,
                                                              cpu_tick_cmpr);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3304
                                }
B
blueswir1 已提交
3305 3306
                                break;
                            case 0x18: /* System tick */
B
bellard 已提交
3307
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3308 3309
                                if (!supervisor(dc))
                                    goto illegal_insn;
B
bellard 已提交
3310
#endif
B
blueswir1 已提交
3311
                                {
P
pbrook 已提交
3312
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3313

3314 3315
                                    tcg_gen_xor_tl(cpu_dst, cpu_src1,
                                                   cpu_src2);
P
pbrook 已提交
3316
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3317 3318
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, stick));
P
pbrook 已提交
3319 3320 3321
                                    gen_helper_tick_set_count(r_tickptr,
                                                              cpu_dst);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3322
                                }
B
blueswir1 已提交
3323 3324
                                break;
                            case 0x19: /* System tick compare */
B
bellard 已提交
3325
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3326 3327
                                if (!supervisor(dc))
                                    goto illegal_insn;
B
bellard 已提交
3328
#endif
B
blueswir1 已提交
3329
                                {
P
pbrook 已提交
3330
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3331

3332
                                    tcg_gen_xor_tl(cpu_stick_cmpr, cpu_src1,
3333
                                                   cpu_src2);
P
pbrook 已提交
3334
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3335 3336
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, stick));
P
pbrook 已提交
3337 3338 3339
                                    gen_helper_tick_set_limit(r_tickptr,
                                                              cpu_stick_cmpr);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3340
                                }
B
blueswir1 已提交
3341
                                break;
B
bellard 已提交
3342

B
blueswir1 已提交
3343
                            case 0x10: /* Performance Control */
B
blueswir1 已提交
3344 3345
                            case 0x11: /* Performance Instrumentation
                                          Counter */
B
blueswir1 已提交
3346
                            case 0x12: /* Dispatch Control */
B
bellard 已提交
3347
#endif
B
bellard 已提交
3348
                            default:
3349 3350 3351 3352
                                goto illegal_insn;
                            }
                        }
                        break;
3353
#if !defined(CONFIG_USER_ONLY)
3354
                    case 0x31: /* wrpsr, V9 saved, restored */
3355
                        {
B
blueswir1 已提交
3356 3357
                            if (!supervisor(dc))
                                goto priv_insn;
B
bellard 已提交
3358
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3359 3360
                            switch (rd) {
                            case 0:
P
pbrook 已提交
3361
                                gen_helper_saved();
B
blueswir1 已提交
3362 3363
                                break;
                            case 1:
P
pbrook 已提交
3364
                                gen_helper_restored();
B
blueswir1 已提交
3365
                                break;
B
blueswir1 已提交
3366 3367 3368 3369 3370
                            case 2: /* UA2005 allclean */
                            case 3: /* UA2005 otherw */
                            case 4: /* UA2005 normalw */
                            case 5: /* UA2005 invalw */
                                // XXX
B
blueswir1 已提交
3371
                            default:
B
bellard 已提交
3372 3373 3374
                                goto illegal_insn;
                            }
#else
3375
                            tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
P
pbrook 已提交
3376
                            gen_helper_wrpsr(cpu_dst);
3377
                            save_state(dc, cpu_cond);
B
bellard 已提交
3378
                            gen_op_next_insn();
B
bellard 已提交
3379
                            tcg_gen_exit_tb(0);
B
blueswir1 已提交
3380
                            dc->is_br = 1;
B
bellard 已提交
3381
#endif
3382 3383
                        }
                        break;
3384
                    case 0x32: /* wrwim, V9 wrpr */
3385
                        {
B
blueswir1 已提交
3386 3387
                            if (!supervisor(dc))
                                goto priv_insn;
3388
                            tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
B
bellard 已提交
3389
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3390 3391
                            switch (rd) {
                            case 0: // tpc
3392
                                {
P
pbrook 已提交
3393
                                    TCGv_ptr r_tsptr;
3394

P
pbrook 已提交
3395
                                    r_tsptr = tcg_temp_new_ptr();
3396 3397
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
3398
                                    tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3399
                                                  offsetof(trap_state, tpc));
P
pbrook 已提交
3400
                                    tcg_temp_free_ptr(r_tsptr);
3401
                                }
B
blueswir1 已提交
3402 3403
                                break;
                            case 1: // tnpc
3404
                                {
P
pbrook 已提交
3405
                                    TCGv_ptr r_tsptr;
3406

P
pbrook 已提交
3407
                                    r_tsptr = tcg_temp_new_ptr();
3408 3409
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
3410
                                    tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3411
                                                  offsetof(trap_state, tnpc));
P
pbrook 已提交
3412
                                    tcg_temp_free_ptr(r_tsptr);
3413
                                }
B
blueswir1 已提交
3414 3415
                                break;
                            case 2: // tstate
3416
                                {
P
pbrook 已提交
3417
                                    TCGv_ptr r_tsptr;
3418

P
pbrook 已提交
3419
                                    r_tsptr = tcg_temp_new_ptr();
3420 3421
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
3422
                                    tcg_gen_st_tl(cpu_tmp0, r_tsptr,
B
blueswir1 已提交
3423 3424
                                                  offsetof(trap_state,
                                                           tstate));
P
pbrook 已提交
3425
                                    tcg_temp_free_ptr(r_tsptr);
3426
                                }
B
blueswir1 已提交
3427 3428
                                break;
                            case 3: // tt
3429
                                {
P
pbrook 已提交
3430
                                    TCGv_ptr r_tsptr;
3431

P
pbrook 已提交
3432
                                    r_tsptr = tcg_temp_new_ptr();
3433 3434
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
B
blueswir1 已提交
3435 3436
                                    tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
                                    tcg_gen_st_i32(cpu_tmp32, r_tsptr,
3437
                                                   offsetof(trap_state, tt));
P
pbrook 已提交
3438
                                    tcg_temp_free_ptr(r_tsptr);
3439
                                }
B
blueswir1 已提交
3440 3441
                                break;
                            case 4: // tick
B
blueswir1 已提交
3442
                                {
P
pbrook 已提交
3443
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3444

P
pbrook 已提交
3445
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3446 3447
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, tick));
P
pbrook 已提交
3448 3449 3450
                                    gen_helper_tick_set_count(r_tickptr,
                                                              cpu_tmp0);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3451
                                }
B
blueswir1 已提交
3452 3453
                                break;
                            case 5: // tba
3454
                                tcg_gen_mov_tl(cpu_tbr, cpu_tmp0);
B
blueswir1 已提交
3455 3456
                                break;
                            case 6: // pstate
3457
                                save_state(dc, cpu_cond);
P
pbrook 已提交
3458
                                gen_helper_wrpstate(cpu_tmp0);
P
pbrook 已提交
3459
                                gen_op_next_insn();
B
bellard 已提交
3460
                                tcg_gen_exit_tb(0);
P
pbrook 已提交
3461
                                dc->is_br = 1;
B
blueswir1 已提交
3462 3463
                                break;
                            case 7: // tl
3464
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3465 3466
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState, tl));
B
blueswir1 已提交
3467 3468
                                break;
                            case 8: // pil
3469
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3470 3471 3472
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        psrpil));
B
blueswir1 已提交
3473 3474
                                break;
                            case 9: // cwp
P
pbrook 已提交
3475
                                gen_helper_wrcwp(cpu_tmp0);
B
blueswir1 已提交
3476 3477
                                break;
                            case 10: // cansave
3478
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3479 3480 3481
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        cansave));
B
blueswir1 已提交
3482 3483
                                break;
                            case 11: // canrestore
3484
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3485 3486 3487
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        canrestore));
B
blueswir1 已提交
3488 3489
                                break;
                            case 12: // cleanwin
3490
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3491 3492 3493
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        cleanwin));
B
blueswir1 已提交
3494 3495
                                break;
                            case 13: // otherwin
3496
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3497 3498 3499
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        otherwin));
B
blueswir1 已提交
3500 3501
                                break;
                            case 14: // wstate
3502
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3503 3504 3505
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        wstate));
B
blueswir1 已提交
3506
                                break;
B
blueswir1 已提交
3507
                            case 16: // UA2005 gl
3508
                                CHECK_IU_FEATURE(dc, GL);
3509
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3510 3511
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState, gl));
B
blueswir1 已提交
3512 3513
                                break;
                            case 26: // UA2005 strand status
3514
                                CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
3515 3516
                                if (!hypervisor(dc))
                                    goto priv_insn;
B
blueswir1 已提交
3517
                                tcg_gen_mov_tl(cpu_ssr, cpu_tmp0);
B
blueswir1 已提交
3518
                                break;
B
blueswir1 已提交
3519 3520 3521
                            default:
                                goto illegal_insn;
                            }
B
bellard 已提交
3522
#else
3523
                            tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3524 3525 3526
                            if (dc->def->nwindows != 32)
                                tcg_gen_andi_tl(cpu_tmp32, cpu_tmp32,
                                                (1 << dc->def->nwindows) - 1);
3527
                            tcg_gen_mov_i32(cpu_wim, cpu_tmp32);
B
bellard 已提交
3528
#endif
3529 3530
                        }
                        break;
B
blueswir1 已提交
3531
                    case 0x33: /* wrtbr, UA2005 wrhpr */
3532
                        {
B
blueswir1 已提交
3533
#ifndef TARGET_SPARC64
B
blueswir1 已提交
3534 3535
                            if (!supervisor(dc))
                                goto priv_insn;
3536
                            tcg_gen_xor_tl(cpu_tbr, cpu_src1, cpu_src2);
B
blueswir1 已提交
3537
#else
3538
                            CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
3539 3540
                            if (!hypervisor(dc))
                                goto priv_insn;
3541
                            tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
B
blueswir1 已提交
3542 3543 3544
                            switch (rd) {
                            case 0: // hpstate
                                // XXX gen_op_wrhpstate();
3545
                                save_state(dc, cpu_cond);
B
blueswir1 已提交
3546
                                gen_op_next_insn();
B
bellard 已提交
3547
                                tcg_gen_exit_tb(0);
B
blueswir1 已提交
3548 3549 3550 3551 3552 3553
                                dc->is_br = 1;
                                break;
                            case 1: // htstate
                                // XXX gen_op_wrhtstate();
                                break;
                            case 3: // hintp
3554
                                tcg_gen_mov_tl(cpu_hintp, cpu_tmp0);
B
blueswir1 已提交
3555 3556
                                break;
                            case 5: // htba
3557
                                tcg_gen_mov_tl(cpu_htba, cpu_tmp0);
B
blueswir1 已提交
3558 3559
                                break;
                            case 31: // hstick_cmpr
B
blueswir1 已提交
3560
                                {
P
pbrook 已提交
3561
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3562

3563
                                    tcg_gen_mov_tl(cpu_hstick_cmpr, cpu_tmp0);
P
pbrook 已提交
3564
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3565 3566
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, hstick));
P
pbrook 已提交
3567 3568 3569
                                    gen_helper_tick_set_limit(r_tickptr,
                                                              cpu_hstick_cmpr);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3570
                                }
B
blueswir1 已提交
3571 3572 3573 3574 3575 3576
                                break;
                            case 6: // hver readonly
                            default:
                                goto illegal_insn;
                            }
#endif
3577 3578 3579
                        }
                        break;
#endif
B
bellard 已提交
3580
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3581 3582 3583 3584
                    case 0x2c: /* V9 movcc */
                        {
                            int cc = GET_FIELD_SP(insn, 11, 12);
                            int cond = GET_FIELD_SP(insn, 14, 17);
B
blueswir1 已提交
3585
                            TCGv r_cond;
3586 3587
                            int l1;

P
pbrook 已提交
3588
                            r_cond = tcg_temp_new();
B
blueswir1 已提交
3589 3590
                            if (insn & (1 << 18)) {
                                if (cc == 0)
B
blueswir1 已提交
3591
                                    gen_cond(r_cond, 0, cond);
B
blueswir1 已提交
3592
                                else if (cc == 2)
B
blueswir1 已提交
3593
                                    gen_cond(r_cond, 1, cond);
B
blueswir1 已提交
3594 3595 3596
                                else
                                    goto illegal_insn;
                            } else {
B
blueswir1 已提交
3597
                                gen_fcond(r_cond, cc, cond);
B
blueswir1 已提交
3598
                            }
3599 3600 3601

                            l1 = gen_new_label();

P
pbrook 已提交
3602
                            tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3603
                            if (IS_IMM) {       /* immediate */
B
blueswir1 已提交
3604 3605
                                TCGv r_const;

3606
                                rs2 = GET_FIELD_SPs(insn, 0, 10);
B
blueswir1 已提交
3607 3608 3609
                                r_const = tcg_const_tl((int)rs2);
                                gen_movl_TN_reg(rd, r_const);
                                tcg_temp_free(r_const);
3610 3611
                            } else {
                                rs2 = GET_FIELD_SP(insn, 0, 4);
B
blueswir1 已提交
3612 3613
                                gen_movl_reg_TN(rs2, cpu_tmp0);
                                gen_movl_TN_reg(rd, cpu_tmp0);
3614 3615
                            }
                            gen_set_label(l1);
B
blueswir1 已提交
3616
                            tcg_temp_free(r_cond);
B
blueswir1 已提交
3617 3618 3619
                            break;
                        }
                    case 0x2d: /* V9 sdivx */
3620 3621
                        gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3622 3623 3624
                        break;
                    case 0x2e: /* V9 popc */
                        {
B
blueswir1 已提交
3625
                            cpu_src2 = get_src2(insn, cpu_src2);
P
pbrook 已提交
3626
                            gen_helper_popc(cpu_dst, cpu_src2);
3627
                            gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3628 3629 3630 3631
                        }
                    case 0x2f: /* V9 movr */
                        {
                            int cond = GET_FIELD_SP(insn, 10, 12);
3632 3633
                            int l1;

3634
                            cpu_src1 = get_src1(insn, cpu_src1);
3635 3636 3637

                            l1 = gen_new_label();

P
pbrook 已提交
3638 3639
                            tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
                                              cpu_src1, 0, l1);
B
blueswir1 已提交
3640
                            if (IS_IMM) {       /* immediate */
B
blueswir1 已提交
3641 3642
                                TCGv r_const;

B
blueswir1 已提交
3643
                                rs2 = GET_FIELD_SPs(insn, 0, 9);
B
blueswir1 已提交
3644 3645 3646
                                r_const = tcg_const_tl((int)rs2);
                                gen_movl_TN_reg(rd, r_const);
                                tcg_temp_free(r_const);
3647
                            } else {
B
blueswir1 已提交
3648
                                rs2 = GET_FIELD_SP(insn, 0, 4);
B
blueswir1 已提交
3649 3650
                                gen_movl_reg_TN(rs2, cpu_tmp0);
                                gen_movl_TN_reg(rd, cpu_tmp0);
B
blueswir1 已提交
3651
                            }
3652
                            gen_set_label(l1);
B
blueswir1 已提交
3653 3654 3655 3656 3657 3658 3659
                            break;
                        }
#endif
                    default:
                        goto illegal_insn;
                    }
                }
3660 3661 3662 3663 3664
            } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
#ifdef TARGET_SPARC64
                int opf = GET_FIELD_SP(insn, 5, 13);
                rs1 = GET_FIELD(insn, 13, 17);
                rs2 = GET_FIELD(insn, 27, 31);
3665
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
blueswir1 已提交
3666
                    goto jmp_insn;
3667 3668

                switch (opf) {
B
blueswir1 已提交
3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683
                case 0x000: /* VIS I edge8cc */
                case 0x001: /* VIS II edge8n */
                case 0x002: /* VIS I edge8lcc */
                case 0x003: /* VIS II edge8ln */
                case 0x004: /* VIS I edge16cc */
                case 0x005: /* VIS II edge16n */
                case 0x006: /* VIS I edge16lcc */
                case 0x007: /* VIS II edge16ln */
                case 0x008: /* VIS I edge32cc */
                case 0x009: /* VIS II edge32n */
                case 0x00a: /* VIS I edge32lcc */
                case 0x00b: /* VIS II edge32ln */
                    // XXX
                    goto illegal_insn;
                case 0x010: /* VIS I array8 */
B
blueswir1 已提交
3684
                    CHECK_FPU_FEATURE(dc, VIS1);
3685
                    cpu_src1 = get_src1(insn, cpu_src1);
3686
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3687
                    gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
3688
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3689 3690
                    break;
                case 0x012: /* VIS I array16 */
B
blueswir1 已提交
3691
                    CHECK_FPU_FEATURE(dc, VIS1);
3692
                    cpu_src1 = get_src1(insn, cpu_src1);
3693
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3694
                    gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
3695 3696
                    tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3697 3698
                    break;
                case 0x014: /* VIS I array32 */
B
blueswir1 已提交
3699
                    CHECK_FPU_FEATURE(dc, VIS1);
3700
                    cpu_src1 = get_src1(insn, cpu_src1);
3701
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3702
                    gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
3703 3704
                    tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3705
                    break;
3706
                case 0x018: /* VIS I alignaddr */
B
blueswir1 已提交
3707
                    CHECK_FPU_FEATURE(dc, VIS1);
3708
                    cpu_src1 = get_src1(insn, cpu_src1);
3709
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3710
                    gen_helper_alignaddr(cpu_dst, cpu_src1, cpu_src2);
3711
                    gen_movl_TN_reg(rd, cpu_dst);
3712
                    break;
B
blueswir1 已提交
3713
                case 0x019: /* VIS II bmask */
3714 3715
                case 0x01a: /* VIS I alignaddrl */
                    // XXX
B
blueswir1 已提交
3716 3717
                    goto illegal_insn;
                case 0x020: /* VIS I fcmple16 */
B
blueswir1 已提交
3718
                    CHECK_FPU_FEATURE(dc, VIS1);
3719 3720
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3721
                    gen_helper_fcmple16();
3722
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3723 3724
                    break;
                case 0x022: /* VIS I fcmpne16 */
B
blueswir1 已提交
3725
                    CHECK_FPU_FEATURE(dc, VIS1);
3726 3727
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3728
                    gen_helper_fcmpne16();
3729
                    gen_op_store_DT0_fpr(DFPREG(rd));
3730
                    break;
B
blueswir1 已提交
3731
                case 0x024: /* VIS I fcmple32 */
B
blueswir1 已提交
3732
                    CHECK_FPU_FEATURE(dc, VIS1);
3733 3734
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3735
                    gen_helper_fcmple32();
3736
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3737 3738
                    break;
                case 0x026: /* VIS I fcmpne32 */
B
blueswir1 已提交
3739
                    CHECK_FPU_FEATURE(dc, VIS1);
3740 3741
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3742
                    gen_helper_fcmpne32();
3743
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3744 3745
                    break;
                case 0x028: /* VIS I fcmpgt16 */
B
blueswir1 已提交
3746
                    CHECK_FPU_FEATURE(dc, VIS1);
3747 3748
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3749
                    gen_helper_fcmpgt16();
3750
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3751 3752
                    break;
                case 0x02a: /* VIS I fcmpeq16 */
B
blueswir1 已提交
3753
                    CHECK_FPU_FEATURE(dc, VIS1);
3754 3755
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3756
                    gen_helper_fcmpeq16();
3757
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3758 3759
                    break;
                case 0x02c: /* VIS I fcmpgt32 */
B
blueswir1 已提交
3760
                    CHECK_FPU_FEATURE(dc, VIS1);
3761 3762
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3763
                    gen_helper_fcmpgt32();
3764
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3765 3766
                    break;
                case 0x02e: /* VIS I fcmpeq32 */
B
blueswir1 已提交
3767
                    CHECK_FPU_FEATURE(dc, VIS1);
3768 3769
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3770
                    gen_helper_fcmpeq32();
3771
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3772 3773
                    break;
                case 0x031: /* VIS I fmul8x16 */
B
blueswir1 已提交
3774
                    CHECK_FPU_FEATURE(dc, VIS1);
3775 3776
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3777
                    gen_helper_fmul8x16();
3778
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3779 3780
                    break;
                case 0x033: /* VIS I fmul8x16au */
B
blueswir1 已提交
3781
                    CHECK_FPU_FEATURE(dc, VIS1);
3782 3783
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3784
                    gen_helper_fmul8x16au();
3785
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3786 3787
                    break;
                case 0x035: /* VIS I fmul8x16al */
B
blueswir1 已提交
3788
                    CHECK_FPU_FEATURE(dc, VIS1);
3789 3790
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3791
                    gen_helper_fmul8x16al();
3792
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3793 3794
                    break;
                case 0x036: /* VIS I fmul8sux16 */
B
blueswir1 已提交
3795
                    CHECK_FPU_FEATURE(dc, VIS1);
3796 3797
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3798
                    gen_helper_fmul8sux16();
3799
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3800 3801
                    break;
                case 0x037: /* VIS I fmul8ulx16 */
B
blueswir1 已提交
3802
                    CHECK_FPU_FEATURE(dc, VIS1);
3803 3804
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3805
                    gen_helper_fmul8ulx16();
3806
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3807 3808
                    break;
                case 0x038: /* VIS I fmuld8sux16 */
B
blueswir1 已提交
3809
                    CHECK_FPU_FEATURE(dc, VIS1);
3810 3811
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3812
                    gen_helper_fmuld8sux16();
3813
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3814 3815
                    break;
                case 0x039: /* VIS I fmuld8ulx16 */
B
blueswir1 已提交
3816
                    CHECK_FPU_FEATURE(dc, VIS1);
3817 3818
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3819
                    gen_helper_fmuld8ulx16();
3820
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3821 3822 3823 3824 3825 3826 3827
                    break;
                case 0x03a: /* VIS I fpack32 */
                case 0x03b: /* VIS I fpack16 */
                case 0x03d: /* VIS I fpackfix */
                case 0x03e: /* VIS I pdist */
                    // XXX
                    goto illegal_insn;
3828
                case 0x048: /* VIS I faligndata */
B
blueswir1 已提交
3829
                    CHECK_FPU_FEATURE(dc, VIS1);
3830 3831
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3832
                    gen_helper_faligndata();
3833
                    gen_op_store_DT0_fpr(DFPREG(rd));
3834
                    break;
B
blueswir1 已提交
3835
                case 0x04b: /* VIS I fpmerge */
B
blueswir1 已提交
3836
                    CHECK_FPU_FEATURE(dc, VIS1);
3837 3838
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3839
                    gen_helper_fpmerge();
3840
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3841 3842 3843 3844 3845
                    break;
                case 0x04c: /* VIS II bshuffle */
                    // XXX
                    goto illegal_insn;
                case 0x04d: /* VIS I fexpand */
B
blueswir1 已提交
3846
                    CHECK_FPU_FEATURE(dc, VIS1);
3847 3848
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3849
                    gen_helper_fexpand();
3850
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3851 3852
                    break;
                case 0x050: /* VIS I fpadd16 */
B
blueswir1 已提交
3853
                    CHECK_FPU_FEATURE(dc, VIS1);
3854 3855
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3856
                    gen_helper_fpadd16();
3857
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3858 3859
                    break;
                case 0x051: /* VIS I fpadd16s */
B
blueswir1 已提交
3860
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
3861 3862
                    gen_helper_fpadd16s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3863 3864
                    break;
                case 0x052: /* VIS I fpadd32 */
B
blueswir1 已提交
3865
                    CHECK_FPU_FEATURE(dc, VIS1);
3866 3867
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3868
                    gen_helper_fpadd32();
3869
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3870 3871
                    break;
                case 0x053: /* VIS I fpadd32s */
B
blueswir1 已提交
3872
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
3873 3874
                    gen_helper_fpadd32s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3875 3876
                    break;
                case 0x054: /* VIS I fpsub16 */
B
blueswir1 已提交
3877
                    CHECK_FPU_FEATURE(dc, VIS1);
3878 3879
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3880
                    gen_helper_fpsub16();
3881
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3882 3883
                    break;
                case 0x055: /* VIS I fpsub16s */
B
blueswir1 已提交
3884
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
3885 3886
                    gen_helper_fpsub16s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3887 3888
                    break;
                case 0x056: /* VIS I fpsub32 */
B
blueswir1 已提交
3889
                    CHECK_FPU_FEATURE(dc, VIS1);
3890 3891
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3892
                    gen_helper_fpsub32();
3893
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3894 3895
                    break;
                case 0x057: /* VIS I fpsub32s */
B
blueswir1 已提交
3896
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
3897 3898
                    gen_helper_fpsub32s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3899
                    break;
3900
                case 0x060: /* VIS I fzero */
B
blueswir1 已提交
3901
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3902 3903
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd)], 0);
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd) + 1], 0);
3904 3905
                    break;
                case 0x061: /* VIS I fzeros */
B
blueswir1 已提交
3906
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3907
                    tcg_gen_movi_i32(cpu_fpr[rd], 0);
3908
                    break;
B
blueswir1 已提交
3909
                case 0x062: /* VIS I fnor */
B
blueswir1 已提交
3910
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3911 3912 3913 3914
                    tcg_gen_nor_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1)],
                                    cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_nor_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1) + 1],
                                    cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
3915 3916
                    break;
                case 0x063: /* VIS I fnors */
B
blueswir1 已提交
3917
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3918
                    tcg_gen_nor_i32(cpu_tmp32, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3919 3920
                    break;
                case 0x064: /* VIS I fandnot2 */
B
blueswir1 已提交
3921
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3922 3923 3924 3925 3926
                    tcg_gen_andc_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
                                     cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_andc_i32(cpu_fpr[DFPREG(rd) + 1],
                                     cpu_fpr[DFPREG(rs1) + 1],
                                     cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
3927 3928
                    break;
                case 0x065: /* VIS I fandnot2s */
B
blueswir1 已提交
3929
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3930
                    tcg_gen_andc_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3931 3932
                    break;
                case 0x066: /* VIS I fnot2 */
B
blueswir1 已提交
3933
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3934 3935 3936
                    tcg_gen_not_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_not_i32(cpu_fpr[DFPREG(rd) + 1],
                                    cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
3937 3938
                    break;
                case 0x067: /* VIS I fnot2s */
B
blueswir1 已提交
3939
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3940
                    tcg_gen_not_i32(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
3941 3942
                    break;
                case 0x068: /* VIS I fandnot1 */
B
blueswir1 已提交
3943
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3944 3945 3946 3947 3948
                    tcg_gen_andc_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs2)],
                                     cpu_fpr[DFPREG(rs1)]);
                    tcg_gen_andc_i32(cpu_fpr[DFPREG(rd) + 1],
                                     cpu_fpr[DFPREG(rs2) + 1],
                                     cpu_fpr[DFPREG(rs1) + 1]);
B
blueswir1 已提交
3949 3950
                    break;
                case 0x069: /* VIS I fandnot1s */
B
blueswir1 已提交
3951
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3952
                    tcg_gen_andc_i32(cpu_fpr[rd], cpu_fpr[rs2], cpu_fpr[rs1]);
B
blueswir1 已提交
3953 3954
                    break;
                case 0x06a: /* VIS I fnot1 */
B
blueswir1 已提交
3955
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3956 3957 3958
                    tcg_gen_not_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)]);
                    tcg_gen_not_i32(cpu_fpr[DFPREG(rd) + 1],
                                    cpu_fpr[DFPREG(rs1) + 1]);
B
blueswir1 已提交
3959 3960
                    break;
                case 0x06b: /* VIS I fnot1s */
B
blueswir1 已提交
3961
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3962
                    tcg_gen_not_i32(cpu_fpr[rd], cpu_fpr[rs1]);
B
blueswir1 已提交
3963 3964
                    break;
                case 0x06c: /* VIS I fxor */
B
blueswir1 已提交
3965
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3966 3967 3968 3969 3970
                    tcg_gen_xor_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
                                    cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_xor_i32(cpu_fpr[DFPREG(rd) + 1],
                                    cpu_fpr[DFPREG(rs1) + 1],
                                    cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
3971 3972
                    break;
                case 0x06d: /* VIS I fxors */
B
blueswir1 已提交
3973
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3974
                    tcg_gen_xor_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3975 3976
                    break;
                case 0x06e: /* VIS I fnand */
B
blueswir1 已提交
3977
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3978 3979 3980 3981
                    tcg_gen_nand_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1)],
                                     cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_nand_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1) + 1],
                                     cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
3982 3983
                    break;
                case 0x06f: /* VIS I fnands */
B
blueswir1 已提交
3984
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3985
                    tcg_gen_nand_i32(cpu_tmp32, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3986 3987
                    break;
                case 0x070: /* VIS I fand */
B
blueswir1 已提交
3988
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3989 3990 3991 3992 3993
                    tcg_gen_and_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
                                    cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_and_i32(cpu_fpr[DFPREG(rd) + 1],
                                    cpu_fpr[DFPREG(rs1) + 1],
                                    cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
3994 3995
                    break;
                case 0x071: /* VIS I fands */
B
blueswir1 已提交
3996
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
3997
                    tcg_gen_and_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3998 3999
                    break;
                case 0x072: /* VIS I fxnor */
B
blueswir1 已提交
4000
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4001 4002 4003 4004 4005 4006
                    tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2)], -1);
                    tcg_gen_xor_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32,
                                    cpu_fpr[DFPREG(rs1)]);
                    tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2) + 1], -1);
                    tcg_gen_xor_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32,
                                    cpu_fpr[DFPREG(rs1) + 1]);
B
blueswir1 已提交
4007 4008
                    break;
                case 0x073: /* VIS I fxnors */
B
blueswir1 已提交
4009
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4010 4011
                    tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[rs2], -1);
                    tcg_gen_xor_i32(cpu_fpr[rd], cpu_tmp32, cpu_fpr[rs1]);
B
blueswir1 已提交
4012
                    break;
4013
                case 0x074: /* VIS I fsrc1 */
B
blueswir1 已提交
4014
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4015 4016 4017
                    tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)]);
                    tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1],
                                    cpu_fpr[DFPREG(rs1) + 1]);
4018 4019
                    break;
                case 0x075: /* VIS I fsrc1s */
B
blueswir1 已提交
4020
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4021
                    tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs1]);
4022
                    break;
B
blueswir1 已提交
4023
                case 0x076: /* VIS I fornot2 */
B
blueswir1 已提交
4024
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4025 4026 4027 4028 4029
                    tcg_gen_orc_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
                                    cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_orc_i32(cpu_fpr[DFPREG(rd) + 1],
                                    cpu_fpr[DFPREG(rs1) + 1],
                                    cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
4030 4031
                    break;
                case 0x077: /* VIS I fornot2s */
B
blueswir1 已提交
4032
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4033
                    tcg_gen_orc_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4034
                    break;
4035
                case 0x078: /* VIS I fsrc2 */
B
blueswir1 已提交
4036
                    CHECK_FPU_FEATURE(dc, VIS1);
4037 4038
                    gen_op_load_fpr_DT0(DFPREG(rs2));
                    gen_op_store_DT0_fpr(DFPREG(rd));
4039 4040
                    break;
                case 0x079: /* VIS I fsrc2s */
B
blueswir1 已提交
4041
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4042
                    tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
4043
                    break;
B
blueswir1 已提交
4044
                case 0x07a: /* VIS I fornot1 */
B
blueswir1 已提交
4045
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4046 4047 4048 4049 4050
                    tcg_gen_orc_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs2)],
                                    cpu_fpr[DFPREG(rs1)]);
                    tcg_gen_orc_i32(cpu_fpr[DFPREG(rd) + 1],
                                    cpu_fpr[DFPREG(rs2) + 1],
                                    cpu_fpr[DFPREG(rs1) + 1]);
B
blueswir1 已提交
4051 4052
                    break;
                case 0x07b: /* VIS I fornot1s */
B
blueswir1 已提交
4053
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4054
                    tcg_gen_orc_i32(cpu_fpr[rd], cpu_fpr[rs2], cpu_fpr[rs1]);
B
blueswir1 已提交
4055 4056
                    break;
                case 0x07c: /* VIS I for */
B
blueswir1 已提交
4057
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4058 4059 4060 4061 4062
                    tcg_gen_or_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
                                   cpu_fpr[DFPREG(rs2)]);
                    tcg_gen_or_i32(cpu_fpr[DFPREG(rd) + 1],
                                   cpu_fpr[DFPREG(rs1) + 1],
                                   cpu_fpr[DFPREG(rs2) + 1]);
B
blueswir1 已提交
4063 4064
                    break;
                case 0x07d: /* VIS I fors */
B
blueswir1 已提交
4065
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4066
                    tcg_gen_or_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4067
                    break;
4068
                case 0x07e: /* VIS I fone */
B
blueswir1 已提交
4069
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4070 4071
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd)], -1);
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd) + 1], -1);
4072 4073
                    break;
                case 0x07f: /* VIS I fones */
B
blueswir1 已提交
4074
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4075
                    tcg_gen_movi_i32(cpu_fpr[rd], -1);
4076
                    break;
B
blueswir1 已提交
4077 4078 4079 4080
                case 0x080: /* VIS I shutdown */
                case 0x081: /* VIS II siam */
                    // XXX
                    goto illegal_insn;
4081 4082 4083 4084
                default:
                    goto illegal_insn;
                }
#else
B
blueswir1 已提交
4085
                goto ncp_insn;
4086 4087
#endif
            } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4088
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4089
                goto illegal_insn;
4090
#else
B
blueswir1 已提交
4091
                goto ncp_insn;
4092
#endif
B
bellard 已提交
4093
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4094
            } else if (xop == 0x39) { /* V9 return */
P
pbrook 已提交
4095
                TCGv_i32 r_const;
B
blueswir1 已提交
4096

4097
                save_state(dc, cpu_cond);
4098
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
4099 4100
                if (IS_IMM) {   /* immediate */
                    rs2 = GET_FIELDs(insn, 19, 31);
4101
                    tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
B
blueswir1 已提交
4102
                } else {                /* register */
B
bellard 已提交
4103
                    rs2 = GET_FIELD(insn, 27, 31);
B
blueswir1 已提交
4104
                    if (rs2) {
4105 4106
                        gen_movl_reg_TN(rs2, cpu_src2);
                        tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4107 4108
                    } else
                        tcg_gen_mov_tl(cpu_dst, cpu_src1);
B
bellard 已提交
4109
                }
P
pbrook 已提交
4110
                gen_helper_restore();
4111
                gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
4112
                r_const = tcg_const_i32(3);
P
pbrook 已提交
4113 4114
                gen_helper_check_align(cpu_dst, r_const);
                tcg_temp_free_i32(r_const);
4115
                tcg_gen_mov_tl(cpu_npc, cpu_dst);
B
blueswir1 已提交
4116 4117
                dc->npc = DYNAMIC_PC;
                goto jmp_insn;
B
bellard 已提交
4118
#endif
B
blueswir1 已提交
4119
            } else {
4120
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
4121 4122
                if (IS_IMM) {   /* immediate */
                    rs2 = GET_FIELDs(insn, 19, 31);
4123
                    tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
B
blueswir1 已提交
4124
                } else {                /* register */
B
bellard 已提交
4125
                    rs2 = GET_FIELD(insn, 27, 31);
B
blueswir1 已提交
4126
                    if (rs2) {
4127 4128
                        gen_movl_reg_TN(rs2, cpu_src2);
                        tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4129 4130
                    } else
                        tcg_gen_mov_tl(cpu_dst, cpu_src1);
4131
                }
B
blueswir1 已提交
4132 4133 4134
                switch (xop) {
                case 0x38:      /* jmpl */
                    {
P
pbrook 已提交
4135 4136
                        TCGv r_pc;
                        TCGv_i32 r_const;
B
blueswir1 已提交
4137

P
pbrook 已提交
4138 4139 4140
                        r_pc = tcg_const_tl(dc->pc);
                        gen_movl_TN_reg(rd, r_pc);
                        tcg_temp_free(r_pc);
4141
                        gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
4142
                        r_const = tcg_const_i32(3);
P
pbrook 已提交
4143 4144
                        gen_helper_check_align(cpu_dst, r_const);
                        tcg_temp_free_i32(r_const);
4145
                        tcg_gen_mov_tl(cpu_npc, cpu_dst);
B
blueswir1 已提交
4146 4147 4148
                        dc->npc = DYNAMIC_PC;
                    }
                    goto jmp_insn;
B
bellard 已提交
4149
#if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
B
blueswir1 已提交
4150 4151
                case 0x39:      /* rett, V9 return */
                    {
P
pbrook 已提交
4152
                        TCGv_i32 r_const;
B
blueswir1 已提交
4153

B
blueswir1 已提交
4154 4155
                        if (!supervisor(dc))
                            goto priv_insn;
4156
                        gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
4157
                        r_const = tcg_const_i32(3);
P
pbrook 已提交
4158 4159
                        gen_helper_check_align(cpu_dst, r_const);
                        tcg_temp_free_i32(r_const);
4160
                        tcg_gen_mov_tl(cpu_npc, cpu_dst);
B
blueswir1 已提交
4161
                        dc->npc = DYNAMIC_PC;
P
pbrook 已提交
4162
                        gen_helper_rett();
B
blueswir1 已提交
4163 4164 4165 4166
                    }
                    goto jmp_insn;
#endif
                case 0x3b: /* flush */
4167
                    if (!((dc)->def->features & CPU_FEATURE_FLUSH))
B
blueswir1 已提交
4168
                        goto unimp_flush;
P
pbrook 已提交
4169
                    gen_helper_flush(cpu_dst);
B
blueswir1 已提交
4170 4171
                    break;
                case 0x3c:      /* save */
4172
                    save_state(dc, cpu_cond);
P
pbrook 已提交
4173
                    gen_helper_save();
4174
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
4175 4176
                    break;
                case 0x3d:      /* restore */
4177
                    save_state(dc, cpu_cond);
P
pbrook 已提交
4178
                    gen_helper_restore();
4179
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
4180
                    break;
B
bellard 已提交
4181
#if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
B
blueswir1 已提交
4182 4183 4184 4185 4186 4187 4188 4189
                case 0x3e:      /* V9 done/retry */
                    {
                        switch (rd) {
                        case 0:
                            if (!supervisor(dc))
                                goto priv_insn;
                            dc->npc = DYNAMIC_PC;
                            dc->pc = DYNAMIC_PC;
P
pbrook 已提交
4190
                            gen_helper_done();
B
blueswir1 已提交
4191 4192 4193 4194 4195 4196
                            goto jmp_insn;
                        case 1:
                            if (!supervisor(dc))
                                goto priv_insn;
                            dc->npc = DYNAMIC_PC;
                            dc->pc = DYNAMIC_PC;
P
pbrook 已提交
4197
                            gen_helper_retry();
B
blueswir1 已提交
4198 4199 4200 4201 4202 4203 4204 4205 4206 4207
                            goto jmp_insn;
                        default:
                            goto illegal_insn;
                        }
                    }
                    break;
#endif
                default:
                    goto illegal_insn;
                }
4208
            }
B
blueswir1 已提交
4209 4210 4211 4212 4213 4214
            break;
        }
        break;
    case 3:                     /* load/store instructions */
        {
            unsigned int xop = GET_FIELD(insn, 7, 12);
4215 4216

            cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
4217
            if (xop == 0x3c || xop == 0x3e) { // V9 casa/casxa
4218
                rs2 = GET_FIELD(insn, 27, 31);
4219
                gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
4220 4221
                tcg_gen_mov_tl(cpu_addr, cpu_src1);
            } else if (IS_IMM) {     /* immediate */
B
blueswir1 已提交
4222
                rs2 = GET_FIELDs(insn, 19, 31);
4223
                tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
B
blueswir1 已提交
4224 4225 4226
            } else {            /* register */
                rs2 = GET_FIELD(insn, 27, 31);
                if (rs2 != 0) {
4227 4228
                    gen_movl_reg_TN(rs2, cpu_src2);
                    tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4229 4230
                } else
                    tcg_gen_mov_tl(cpu_addr, cpu_src1);
B
blueswir1 已提交
4231
            }
B
blueswir1 已提交
4232 4233 4234
            if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
                (xop > 0x17 && xop <= 0x1d ) ||
                (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
B
blueswir1 已提交
4235
                switch (xop) {
B
blueswir1 已提交
4236
                case 0x0:       /* load unsigned word */
B
blueswir1 已提交
4237
                    gen_address_mask(dc, cpu_addr);
4238
                    tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4239 4240
                    break;
                case 0x1:       /* load unsigned byte */
B
blueswir1 已提交
4241
                    gen_address_mask(dc, cpu_addr);
4242
                    tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4243 4244
                    break;
                case 0x2:       /* load unsigned halfword */
B
blueswir1 已提交
4245
                    gen_address_mask(dc, cpu_addr);
4246
                    tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4247 4248 4249
                    break;
                case 0x3:       /* load double word */
                    if (rd & 1)
4250
                        goto illegal_insn;
B
blueswir1 已提交
4251
                    else {
P
pbrook 已提交
4252
                        TCGv_i32 r_const;
B
blueswir1 已提交
4253

4254
                        save_state(dc, cpu_cond);
B
blueswir1 已提交
4255
                        r_const = tcg_const_i32(7);
P
pbrook 已提交
4256 4257
                        gen_helper_check_align(cpu_addr, r_const); // XXX remove
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4258
                        gen_address_mask(dc, cpu_addr);
4259
                        tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4260 4261 4262
                        tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
                        tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
                        gen_movl_TN_reg(rd + 1, cpu_tmp0);
B
blueswir1 已提交
4263
                        tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4264 4265
                        tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
                        tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
B
blueswir1 已提交
4266
                    }
B
blueswir1 已提交
4267 4268
                    break;
                case 0x9:       /* load signed byte */
B
blueswir1 已提交
4269
                    gen_address_mask(dc, cpu_addr);
4270
                    tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4271 4272
                    break;
                case 0xa:       /* load signed halfword */
B
blueswir1 已提交
4273
                    gen_address_mask(dc, cpu_addr);
4274
                    tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4275 4276
                    break;
                case 0xd:       /* ldstub -- XXX: should be atomically */
B
blueswir1 已提交
4277 4278 4279
                    {
                        TCGv r_const;

B
blueswir1 已提交
4280
                        gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4281 4282 4283 4284 4285
                        tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
                        r_const = tcg_const_tl(0xff);
                        tcg_gen_qemu_st8(r_const, cpu_addr, dc->mem_idx);
                        tcg_temp_free(r_const);
                    }
B
blueswir1 已提交
4286
                    break;
B
blueswir1 已提交
4287 4288
                case 0x0f:      /* swap register with memory. Also
                                   atomically */
B
blueswir1 已提交
4289
                    CHECK_IU_FEATURE(dc, SWAP);
4290
                    gen_movl_reg_TN(rd, cpu_val);
B
blueswir1 已提交
4291
                    gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4292
                    tcg_gen_qemu_ld32u(cpu_tmp0, cpu_addr, dc->mem_idx);
4293
                    tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4294
                    tcg_gen_mov_tl(cpu_val, cpu_tmp0);
B
blueswir1 已提交
4295
                    break;
B
bellard 已提交
4296
#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
B
blueswir1 已提交
4297
                case 0x10:      /* load word alternate */
B
bellard 已提交
4298
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4299 4300 4301 4302
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
4303
#endif
4304
                    save_state(dc, cpu_cond);
4305
                    gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
B
blueswir1 已提交
4306 4307
                    break;
                case 0x11:      /* load unsigned byte alternate */
B
bellard 已提交
4308
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4309 4310 4311 4312 4313
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
#endif
4314
                    save_state(dc, cpu_cond);
4315
                    gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
B
blueswir1 已提交
4316 4317
                    break;
                case 0x12:      /* load unsigned halfword alternate */
B
bellard 已提交
4318
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4319 4320 4321 4322
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4323
#endif
4324
                    save_state(dc, cpu_cond);
4325
                    gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
B
blueswir1 已提交
4326 4327
                    break;
                case 0x13:      /* load double word alternate */
B
bellard 已提交
4328
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4329 4330 4331 4332
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4333
#endif
B
blueswir1 已提交
4334
                    if (rd & 1)
4335
                        goto illegal_insn;
4336
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
4337 4338
                    gen_ldda_asi(cpu_val, cpu_addr, insn, rd);
                    goto skip_move;
B
blueswir1 已提交
4339
                case 0x19:      /* load signed byte alternate */
B
bellard 已提交
4340
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4341 4342 4343 4344 4345
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
#endif
4346
                    save_state(dc, cpu_cond);
4347
                    gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
B
blueswir1 已提交
4348 4349
                    break;
                case 0x1a:      /* load signed halfword alternate */
B
bellard 已提交
4350
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4351 4352 4353 4354
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4355
#endif
4356
                    save_state(dc, cpu_cond);
4357
                    gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
B
blueswir1 已提交
4358 4359
                    break;
                case 0x1d:      /* ldstuba -- XXX: should be atomically */
B
bellard 已提交
4360
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4361 4362 4363 4364 4365
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
#endif
4366
                    save_state(dc, cpu_cond);
4367
                    gen_ldstub_asi(cpu_val, cpu_addr, insn);
B
blueswir1 已提交
4368
                    break;
B
blueswir1 已提交
4369 4370
                case 0x1f:      /* swap reg with alt. memory. Also
                                   atomically */
B
blueswir1 已提交
4371
                    CHECK_IU_FEATURE(dc, SWAP);
B
bellard 已提交
4372
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4373 4374 4375 4376
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
4377
#endif
4378
                    save_state(dc, cpu_cond);
4379 4380
                    gen_movl_reg_TN(rd, cpu_val);
                    gen_swap_asi(cpu_val, cpu_addr, insn);
B
blueswir1 已提交
4381
                    break;
B
bellard 已提交
4382 4383

#ifndef TARGET_SPARC64
B
blueswir1 已提交
4384 4385 4386 4387
                case 0x30: /* ldc */
                case 0x31: /* ldcsr */
                case 0x33: /* lddc */
                    goto ncp_insn;
B
bellard 已提交
4388 4389 4390
#endif
#endif
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4391
                case 0x08: /* V9 ldsw */
B
blueswir1 已提交
4392
                    gen_address_mask(dc, cpu_addr);
4393
                    tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4394 4395
                    break;
                case 0x0b: /* V9 ldx */
B
blueswir1 已提交
4396
                    gen_address_mask(dc, cpu_addr);
4397
                    tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4398 4399
                    break;
                case 0x18: /* V9 ldswa */
4400
                    save_state(dc, cpu_cond);
4401
                    gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
B
blueswir1 已提交
4402 4403
                    break;
                case 0x1b: /* V9 ldxa */
4404
                    save_state(dc, cpu_cond);
4405
                    gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
B
blueswir1 已提交
4406 4407 4408 4409
                    break;
                case 0x2d: /* V9 prefetch, no effect */
                    goto skip_move;
                case 0x30: /* V9 ldfa */
4410
                    save_state(dc, cpu_cond);
4411
                    gen_ldf_asi(cpu_addr, insn, 4, rd);
4412
                    goto skip_move;
B
blueswir1 已提交
4413
                case 0x33: /* V9 lddfa */
4414
                    save_state(dc, cpu_cond);
4415
                    gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4416
                    goto skip_move;
B
blueswir1 已提交
4417 4418 4419
                case 0x3d: /* V9 prefetcha, no effect */
                    goto skip_move;
                case 0x32: /* V9 ldqfa */
B
blueswir1 已提交
4420
                    CHECK_FPU_FEATURE(dc, FLOAT128);
4421
                    save_state(dc, cpu_cond);
4422
                    gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
B
blueswir1 已提交
4423
                    goto skip_move;
B
blueswir1 已提交
4424 4425 4426 4427
#endif
                default:
                    goto illegal_insn;
                }
4428
                gen_movl_TN_reg(rd, cpu_val);
B
blueswir1 已提交
4429
#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
B
blueswir1 已提交
4430
            skip_move: ;
B
bellard 已提交
4431
#endif
B
blueswir1 已提交
4432
            } else if (xop >= 0x20 && xop < 0x24) {
4433
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
4434
                    goto jmp_insn;
4435
                save_state(dc, cpu_cond);
B
blueswir1 已提交
4436 4437
                switch (xop) {
                case 0x20:      /* load fpreg */
B
blueswir1 已提交
4438
                    gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4439 4440
                    tcg_gen_qemu_ld32u(cpu_tmp0, cpu_addr, dc->mem_idx);
                    tcg_gen_trunc_tl_i32(cpu_fpr[rd], cpu_tmp0);
B
blueswir1 已提交
4441
                    break;
4442 4443
                case 0x21:      /* ldfsr, V9 ldxfsr */
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4444
                    gen_address_mask(dc, cpu_addr);
4445 4446
                    if (rd == 1) {
                        tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
P
pbrook 已提交
4447
                        gen_helper_ldxfsr(cpu_tmp64);
4448 4449 4450 4451
                    } else
#else
                    {
                        tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
P
pbrook 已提交
4452
                        gen_helper_ldfsr(cpu_tmp32);
4453 4454
                    }
#endif
B
blueswir1 已提交
4455 4456
                    break;
                case 0x22:      /* load quad fpreg */
B
blueswir1 已提交
4457
                    {
P
pbrook 已提交
4458
                        TCGv_i32 r_const;
B
blueswir1 已提交
4459 4460 4461

                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4462 4463
                        gen_helper_ldqf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4464 4465
                        gen_op_store_QT0_fpr(QFPREG(rd));
                    }
B
blueswir1 已提交
4466
                    break;
B
blueswir1 已提交
4467
                case 0x23:      /* load double fpreg */
B
blueswir1 已提交
4468
                    {
P
pbrook 已提交
4469
                        TCGv_i32 r_const;
B
blueswir1 已提交
4470 4471

                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4472 4473
                        gen_helper_lddf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4474 4475
                        gen_op_store_DT0_fpr(DFPREG(rd));
                    }
B
blueswir1 已提交
4476 4477 4478 4479 4480 4481
                    break;
                default:
                    goto illegal_insn;
                }
            } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
                       xop == 0xe || xop == 0x1e) {
4482
                gen_movl_reg_TN(rd, cpu_val);
B
blueswir1 已提交
4483
                switch (xop) {
B
blueswir1 已提交
4484
                case 0x4: /* store word */
B
blueswir1 已提交
4485
                    gen_address_mask(dc, cpu_addr);
4486
                    tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4487
                    break;
B
blueswir1 已提交
4488
                case 0x5: /* store byte */
B
blueswir1 已提交
4489
                    gen_address_mask(dc, cpu_addr);
4490
                    tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4491
                    break;
B
blueswir1 已提交
4492
                case 0x6: /* store halfword */
B
blueswir1 已提交
4493
                    gen_address_mask(dc, cpu_addr);
4494
                    tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4495
                    break;
B
blueswir1 已提交
4496
                case 0x7: /* store double word */
B
blueswir1 已提交
4497
                    if (rd & 1)
4498
                        goto illegal_insn;
B
blueswir1 已提交
4499
                    else {
P
pbrook 已提交
4500
                        TCGv_i32 r_const;
B
blueswir1 已提交
4501

4502
                        save_state(dc, cpu_cond);
B
blueswir1 已提交
4503
                        gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4504
                        r_const = tcg_const_i32(7);
P
pbrook 已提交
4505 4506
                        gen_helper_check_align(cpu_addr, r_const); // XXX remove
                        tcg_temp_free_i32(r_const);
4507
                        gen_movl_reg_TN(rd + 1, cpu_tmp0);
4508
                        tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, cpu_val);
4509
                        tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4510
                    }
B
blueswir1 已提交
4511
                    break;
B
bellard 已提交
4512
#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
B
blueswir1 已提交
4513
                case 0x14: /* store word alternate */
B
bellard 已提交
4514
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4515 4516 4517 4518
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
4519
#endif
4520
                    save_state(dc, cpu_cond);
4521
                    gen_st_asi(cpu_val, cpu_addr, insn, 4);
B
bellard 已提交
4522
                    break;
B
blueswir1 已提交
4523
                case 0x15: /* store byte alternate */
B
bellard 已提交
4524
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4525 4526 4527 4528
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4529
#endif
4530
                    save_state(dc, cpu_cond);
4531
                    gen_st_asi(cpu_val, cpu_addr, insn, 1);
B
bellard 已提交
4532
                    break;
B
blueswir1 已提交
4533
                case 0x16: /* store halfword alternate */
B
bellard 已提交
4534
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4535 4536 4537 4538
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
4539
#endif
4540
                    save_state(dc, cpu_cond);
4541
                    gen_st_asi(cpu_val, cpu_addr, insn, 2);
B
bellard 已提交
4542
                    break;
B
blueswir1 已提交
4543
                case 0x17: /* store double word alternate */
B
bellard 已提交
4544
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4545 4546 4547 4548
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4549
#endif
B
blueswir1 已提交
4550
                    if (rd & 1)
4551
                        goto illegal_insn;
B
blueswir1 已提交
4552
                    else {
4553
                        save_state(dc, cpu_cond);
4554
                        gen_stda_asi(cpu_val, cpu_addr, insn, rd);
B
blueswir1 已提交
4555
                    }
B
bellard 已提交
4556
                    break;
B
bellard 已提交
4557
#endif
B
bellard 已提交
4558
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4559
                case 0x0e: /* V9 stx */
B
blueswir1 已提交
4560
                    gen_address_mask(dc, cpu_addr);
4561
                    tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4562 4563
                    break;
                case 0x1e: /* V9 stxa */
4564
                    save_state(dc, cpu_cond);
4565
                    gen_st_asi(cpu_val, cpu_addr, insn, 8);
B
blueswir1 已提交
4566
                    break;
B
bellard 已提交
4567
#endif
B
blueswir1 已提交
4568 4569 4570 4571
                default:
                    goto illegal_insn;
                }
            } else if (xop > 0x23 && xop < 0x28) {
4572
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
4573
                    goto jmp_insn;
4574
                save_state(dc, cpu_cond);
B
blueswir1 已提交
4575
                switch (xop) {
4576
                case 0x24: /* store fpreg */
B
blueswir1 已提交
4577
                    gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4578 4579
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_fpr[rd]);
                    tcg_gen_qemu_st32(cpu_tmp0, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4580 4581
                    break;
                case 0x25: /* stfsr, V9 stxfsr */
4582
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4583
                    gen_address_mask(dc, cpu_addr);
4584 4585 4586
                    tcg_gen_ld_i64(cpu_tmp64, cpu_env, offsetof(CPUState, fsr));
                    if (rd == 1)
                        tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4587 4588
                    else
                        tcg_gen_qemu_st32(cpu_tmp64, cpu_addr, dc->mem_idx);
4589 4590
#else
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUState, fsr));
4591
                    tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4592
#endif
B
blueswir1 已提交
4593
                    break;
B
blueswir1 已提交
4594 4595 4596
                case 0x26:
#ifdef TARGET_SPARC64
                    /* V9 stqf, store quad fpreg */
B
blueswir1 已提交
4597
                    {
P
pbrook 已提交
4598
                        TCGv_i32 r_const;
B
blueswir1 已提交
4599 4600 4601 4602

                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        gen_op_load_fpr_QT0(QFPREG(rd));
                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4603 4604
                        gen_helper_stqf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4605
                    }
B
blueswir1 已提交
4606 4607 4608 4609 4610 4611
                    break;
#else /* !TARGET_SPARC64 */
                    /* stdfq, store floating point queue */
#if defined(CONFIG_USER_ONLY)
                    goto illegal_insn;
#else
B
blueswir1 已提交
4612 4613
                    if (!supervisor(dc))
                        goto priv_insn;
4614
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
blueswir1 已提交
4615 4616
                        goto jmp_insn;
                    goto nfq_insn;
B
blueswir1 已提交
4617
#endif
B
blueswir1 已提交
4618
#endif
B
blueswir1 已提交
4619
                case 0x27: /* store double fpreg */
B
blueswir1 已提交
4620
                    {
P
pbrook 已提交
4621
                        TCGv_i32 r_const;
B
blueswir1 已提交
4622 4623 4624

                        gen_op_load_fpr_DT0(DFPREG(rd));
                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4625 4626
                        gen_helper_stdf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4627
                    }
B
blueswir1 已提交
4628 4629 4630 4631 4632
                    break;
                default:
                    goto illegal_insn;
                }
            } else if (xop > 0x33 && xop < 0x3f) {
4633
                save_state(dc, cpu_cond);
B
blueswir1 已提交
4634
                switch (xop) {
4635
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4636
                case 0x34: /* V9 stfa */
4637
                    gen_stf_asi(cpu_addr, insn, 4, rd);
B
blueswir1 已提交
4638
                    break;
B
blueswir1 已提交
4639
                case 0x36: /* V9 stqfa */
B
blueswir1 已提交
4640
                    {
P
pbrook 已提交
4641
                        TCGv_i32 r_const;
B
blueswir1 已提交
4642 4643 4644

                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        r_const = tcg_const_i32(7);
P
pbrook 已提交
4645 4646
                        gen_helper_check_align(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4647 4648 4649
                        gen_op_load_fpr_QT0(QFPREG(rd));
                        gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
                    }
B
blueswir1 已提交
4650
                    break;
B
blueswir1 已提交
4651
                case 0x37: /* V9 stdfa */
4652
                    gen_op_load_fpr_DT0(DFPREG(rd));
4653
                    gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
B
blueswir1 已提交
4654 4655
                    break;
                case 0x3c: /* V9 casa */
B
blueswir1 已提交
4656
                    gen_cas_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4657
                    gen_movl_TN_reg(rd, cpu_val);
B
blueswir1 已提交
4658 4659
                    break;
                case 0x3e: /* V9 casxa */
B
blueswir1 已提交
4660
                    gen_casx_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4661
                    gen_movl_TN_reg(rd, cpu_val);
B
blueswir1 已提交
4662
                    break;
4663
#else
B
blueswir1 已提交
4664 4665 4666 4667 4668 4669 4670 4671 4672
                case 0x34: /* stc */
                case 0x35: /* stcsr */
                case 0x36: /* stdcq */
                case 0x37: /* stdc */
                    goto ncp_insn;
#endif
                default:
                    goto illegal_insn;
                }
4673
            }
B
blueswir1 已提交
4674 4675 4676 4677
            else
                goto illegal_insn;
        }
        break;
4678 4679
    }
    /* default case for non jump instructions */
B
bellard 已提交
4680
    if (dc->npc == DYNAMIC_PC) {
B
blueswir1 已提交
4681 4682
        dc->pc = DYNAMIC_PC;
        gen_op_next_insn();
B
bellard 已提交
4683 4684
    } else if (dc->npc == JUMP_PC) {
        /* we can do a static jump */
4685
        gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
B
bellard 已提交
4686 4687
        dc->is_br = 1;
    } else {
B
blueswir1 已提交
4688 4689
        dc->pc = dc->npc;
        dc->npc = dc->npc + 4;
4690
    }
B
bellard 已提交
4691
 jmp_insn:
4692 4693
    return;
 illegal_insn:
B
blueswir1 已提交
4694
    {
P
pbrook 已提交
4695
        TCGv_i32 r_const;
B
blueswir1 已提交
4696 4697 4698

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_ILL_INSN);
P
pbrook 已提交
4699 4700
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4701 4702
        dc->is_br = 1;
    }
4703
    return;
B
blueswir1 已提交
4704
 unimp_flush:
B
blueswir1 已提交
4705
    {
P
pbrook 已提交
4706
        TCGv_i32 r_const;
B
blueswir1 已提交
4707 4708 4709

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_UNIMP_FLUSH);
P
pbrook 已提交
4710 4711
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4712 4713
        dc->is_br = 1;
    }
B
blueswir1 已提交
4714
    return;
B
bellard 已提交
4715
#if !defined(CONFIG_USER_ONLY)
4716
 priv_insn:
B
blueswir1 已提交
4717
    {
P
pbrook 已提交
4718
        TCGv_i32 r_const;
B
blueswir1 已提交
4719 4720 4721

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_PRIV_INSN);
P
pbrook 已提交
4722 4723
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4724 4725
        dc->is_br = 1;
    }
B
bellard 已提交
4726
    return;
B
blueswir1 已提交
4727
#endif
B
bellard 已提交
4728
 nfpu_insn:
4729
    save_state(dc, cpu_cond);
B
bellard 已提交
4730 4731
    gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
    dc->is_br = 1;
4732
    return;
B
blueswir1 已提交
4733
#if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
B
blueswir1 已提交
4734
 nfq_insn:
4735
    save_state(dc, cpu_cond);
B
blueswir1 已提交
4736 4737 4738 4739
    gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
    dc->is_br = 1;
    return;
#endif
4740 4741
#ifndef TARGET_SPARC64
 ncp_insn:
B
blueswir1 已提交
4742 4743 4744 4745 4746
    {
        TCGv r_const;

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_NCP_INSN);
P
pbrook 已提交
4747
        gen_helper_raise_exception(r_const);
B
blueswir1 已提交
4748 4749 4750
        tcg_temp_free(r_const);
        dc->is_br = 1;
    }
4751 4752
    return;
#endif
4753 4754
}

4755 4756
static inline void gen_intermediate_code_internal(TranslationBlock * tb,
                                                  int spc, CPUSPARCState *env)
4757
{
B
bellard 已提交
4758
    target_ulong pc_start, last_pc;
4759 4760
    uint16_t *gen_opc_end;
    DisasContext dc1, *dc = &dc1;
4761
    CPUBreakpoint *bp;
4762
    int j, lj = -1;
P
pbrook 已提交
4763 4764
    int num_insns;
    int max_insns;
4765 4766 4767

    memset(dc, 0, sizeof(DisasContext));
    dc->tb = tb;
B
bellard 已提交
4768
    pc_start = tb->pc;
4769
    dc->pc = pc_start;
B
bellard 已提交
4770
    last_pc = dc->pc;
B
bellard 已提交
4771
    dc->npc = (target_ulong) tb->cs_base;
B
blueswir1 已提交
4772
    dc->mem_idx = cpu_mmu_index(env);
4773 4774
    dc->def = env->def;
    if ((dc->def->features & CPU_FEATURE_FLOAT))
B
blueswir1 已提交
4775
        dc->fpu_enabled = cpu_fpu_enabled(env);
4776
    else
B
blueswir1 已提交
4777
        dc->fpu_enabled = 0;
B
blueswir1 已提交
4778 4779 4780
#ifdef TARGET_SPARC64
    dc->address_mask_32bit = env->pstate & PS_AM;
#endif
4781 4782
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;

P
pbrook 已提交
4783 4784 4785
    cpu_tmp0 = tcg_temp_new();
    cpu_tmp32 = tcg_temp_new_i32();
    cpu_tmp64 = tcg_temp_new_i64();
B
blueswir1 已提交
4786

P
pbrook 已提交
4787
    cpu_dst = tcg_temp_local_new();
B
blueswir1 已提交
4788 4789

    // loads and stores
P
pbrook 已提交
4790 4791
    cpu_val = tcg_temp_local_new();
    cpu_addr = tcg_temp_local_new();
B
blueswir1 已提交
4792

P
pbrook 已提交
4793 4794 4795 4796 4797
    num_insns = 0;
    max_insns = tb->cflags & CF_COUNT_MASK;
    if (max_insns == 0)
        max_insns = CF_COUNT_MASK;
    gen_icount_start();
4798
    do {
4799 4800
        if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
            TAILQ_FOREACH(bp, &env->breakpoints, entry) {
4801
                if (bp->pc == dc->pc) {
B
blueswir1 已提交
4802
                    if (dc->pc != pc_start)
4803
                        save_state(dc, cpu_cond);
P
pbrook 已提交
4804
                    gen_helper_debug();
B
bellard 已提交
4805
                    tcg_gen_exit_tb(0);
B
blueswir1 已提交
4806
                    dc->is_br = 1;
B
bellard 已提交
4807
                    goto exit_gen_loop;
4808 4809 4810 4811
                }
            }
        }
        if (spc) {
4812
            qemu_log("Search PC...\n");
4813 4814 4815 4816 4817 4818 4819 4820
            j = gen_opc_ptr - gen_opc_buf;
            if (lj < j) {
                lj++;
                while (lj < j)
                    gen_opc_instr_start[lj++] = 0;
                gen_opc_pc[lj] = dc->pc;
                gen_opc_npc[lj] = dc->npc;
                gen_opc_instr_start[lj] = 1;
P
pbrook 已提交
4821
                gen_opc_icount[lj] = num_insns;
4822 4823
            }
        }
P
pbrook 已提交
4824 4825
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
            gen_io_start();
B
blueswir1 已提交
4826 4827
        last_pc = dc->pc;
        disas_sparc_insn(dc);
P
pbrook 已提交
4828
        num_insns++;
B
blueswir1 已提交
4829 4830 4831 4832 4833 4834

        if (dc->is_br)
            break;
        /* if the next PC is different, we abort now */
        if (dc->pc != (last_pc + 4))
            break;
B
bellard 已提交
4835 4836 4837 4838
        /* if we reach a page boundary, we stop generation so that the
           PC of a TT_TFAULT exception is always in the right page */
        if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
            break;
B
bellard 已提交
4839 4840 4841
        /* if single step mode, we generate only one instruction and
           generate an exception */
        if (env->singlestep_enabled) {
B
blueswir1 已提交
4842
            tcg_gen_movi_tl(cpu_pc, dc->pc);
B
bellard 已提交
4843
            tcg_gen_exit_tb(0);
B
bellard 已提交
4844 4845
            break;
        }
4846
    } while ((gen_opc_ptr < gen_opc_end) &&
P
pbrook 已提交
4847 4848
             (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
             num_insns < max_insns);
B
bellard 已提交
4849 4850

 exit_gen_loop:
B
blueswir1 已提交
4851
    tcg_temp_free(cpu_addr);
B
blueswir1 已提交
4852
    tcg_temp_free(cpu_val);
B
blueswir1 已提交
4853
    tcg_temp_free(cpu_dst);
P
pbrook 已提交
4854 4855
    tcg_temp_free_i64(cpu_tmp64);
    tcg_temp_free_i32(cpu_tmp32);
B
blueswir1 已提交
4856
    tcg_temp_free(cpu_tmp0);
P
pbrook 已提交
4857 4858
    if (tb->cflags & CF_LAST_IO)
        gen_io_end();
B
bellard 已提交
4859
    if (!dc->is_br) {
4860
        if (dc->pc != DYNAMIC_PC &&
B
bellard 已提交
4861 4862
            (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
            /* static PC and NPC: we can use direct chaining */
B
blueswir1 已提交
4863
            gen_goto_tb(dc, 0, dc->pc, dc->npc);
B
bellard 已提交
4864 4865
        } else {
            if (dc->pc != DYNAMIC_PC)
B
blueswir1 已提交
4866
                tcg_gen_movi_tl(cpu_pc, dc->pc);
4867
            save_npc(dc, cpu_cond);
B
bellard 已提交
4868
            tcg_gen_exit_tb(0);
B
bellard 已提交
4869 4870
        }
    }
P
pbrook 已提交
4871
    gen_icount_end(tb, num_insns);
4872
    *gen_opc_ptr = INDEX_op_end;
4873 4874 4875 4876 4877 4878
    if (spc) {
        j = gen_opc_ptr - gen_opc_buf;
        lj++;
        while (lj <= j)
            gen_opc_instr_start[lj++] = 0;
#if 0
4879
        log_page_dump();
4880
#endif
4881 4882
        gen_opc_jump_pc[0] = dc->jump_pc[0];
        gen_opc_jump_pc[1] = dc->jump_pc[1];
4883
    } else {
B
bellard 已提交
4884
        tb->size = last_pc + 4 - pc_start;
P
pbrook 已提交
4885
        tb->icount = num_insns;
4886
    }
4887
#ifdef DEBUG_DISAS
4888
    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
4889 4890 4891 4892
        qemu_log("--------------\n");
        qemu_log("IN: %s\n", lookup_symbol(pc_start));
        log_target_disas(pc_start, last_pc + 4 - pc_start, 0);
        qemu_log("\n");
4893
    }
4894 4895 4896
#endif
}

4897
void gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4898
{
4899
    gen_intermediate_code_internal(tb, 0, env);
4900 4901
}

4902
void gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4903
{
4904
    gen_intermediate_code_internal(tb, 1, env);
4905 4906
}

4907
void gen_intermediate_code_init(CPUSPARCState *env)
B
bellard 已提交
4908
{
B
blueswir1 已提交
4909
    unsigned int i;
4910
    static int inited;
B
blueswir1 已提交
4911 4912 4913 4914 4915 4916 4917 4918 4919 4920
    static const char * const gregnames[8] = {
        NULL, // g0 not used
        "g1",
        "g2",
        "g3",
        "g4",
        "g5",
        "g6",
        "g7",
    };
B
blueswir1 已提交
4921 4922 4923 4924 4925 4926 4927 4928 4929 4930
    static const char * const fregnames[64] = {
        "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
        "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
        "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
        "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
        "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
        "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47",
        "f48", "f49", "f50", "f51", "f52", "f53", "f54", "f55",
        "f56", "f57", "f58", "f59", "f60", "f61", "f62", "f63",
    };
B
bellard 已提交
4931

B
blueswir1 已提交
4932 4933 4934 4935
    /* init various static tables */
    if (!inited) {
        inited = 1;

P
pbrook 已提交
4936 4937 4938 4939
        cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
        cpu_regwptr = tcg_global_mem_new_ptr(TCG_AREG0,
                                             offsetof(CPUState, regwptr),
                                             "regwptr");
B
blueswir1 已提交
4940
#ifdef TARGET_SPARC64
P
pbrook 已提交
4941 4942 4943 4944 4945 4946 4947
        cpu_xcc = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUState, xcc),
                                         "xcc");
        cpu_asi = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUState, asi),
                                         "asi");
        cpu_fprs = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUState, fprs),
                                          "fprs");
        cpu_gsr = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, gsr),
4948
                                     "gsr");
P
pbrook 已提交
4949
        cpu_tick_cmpr = tcg_global_mem_new(TCG_AREG0,
4950 4951
                                           offsetof(CPUState, tick_cmpr),
                                           "tick_cmpr");
P
pbrook 已提交
4952
        cpu_stick_cmpr = tcg_global_mem_new(TCG_AREG0,
4953 4954
                                            offsetof(CPUState, stick_cmpr),
                                            "stick_cmpr");
P
pbrook 已提交
4955
        cpu_hstick_cmpr = tcg_global_mem_new(TCG_AREG0,
4956 4957
                                             offsetof(CPUState, hstick_cmpr),
                                             "hstick_cmpr");
P
pbrook 已提交
4958
        cpu_hintp = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, hintp),
4959
                                       "hintp");
P
pbrook 已提交
4960 4961 4962 4963 4964
        cpu_htba = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, htba),
                                      "htba");
        cpu_hver = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, hver),
                                      "hver");
        cpu_ssr = tcg_global_mem_new(TCG_AREG0,
4965
                                     offsetof(CPUState, ssr), "ssr");
P
pbrook 已提交
4966
        cpu_ver = tcg_global_mem_new(TCG_AREG0,
4967
                                     offsetof(CPUState, version), "ver");
P
pbrook 已提交
4968 4969 4970
        cpu_softint = tcg_global_mem_new_i32(TCG_AREG0,
                                             offsetof(CPUState, softint),
                                             "softint");
4971
#else
P
pbrook 已提交
4972
        cpu_wim = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, wim),
4973
                                     "wim");
B
blueswir1 已提交
4974
#endif
P
pbrook 已提交
4975
        cpu_cond = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cond),
B
blueswir1 已提交
4976
                                      "cond");
P
pbrook 已提交
4977
        cpu_cc_src = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cc_src),
4978
                                        "cc_src");
P
pbrook 已提交
4979
        cpu_cc_src2 = tcg_global_mem_new(TCG_AREG0,
B
blueswir1 已提交
4980 4981
                                         offsetof(CPUState, cc_src2),
                                         "cc_src2");
P
pbrook 已提交
4982
        cpu_cc_dst = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cc_dst),
4983
                                        "cc_dst");
P
pbrook 已提交
4984 4985 4986
        cpu_psr = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUState, psr),
                                         "psr");
        cpu_fsr = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, fsr),
B
blueswir1 已提交
4987
                                     "fsr");
P
pbrook 已提交
4988
        cpu_pc = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, pc),
B
blueswir1 已提交
4989
                                    "pc");
P
pbrook 已提交
4990 4991 4992
        cpu_npc = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, npc),
                                     "npc");
        cpu_y = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, y), "y");
4993
#ifndef CONFIG_USER_ONLY
P
pbrook 已提交
4994
        cpu_tbr = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, tbr),
4995 4996
                                     "tbr");
#endif
B
blueswir1 已提交
4997
        for (i = 1; i < 8; i++)
P
pbrook 已提交
4998
            cpu_gregs[i] = tcg_global_mem_new(TCG_AREG0,
B
blueswir1 已提交
4999 5000
                                              offsetof(CPUState, gregs[i]),
                                              gregnames[i]);
B
blueswir1 已提交
5001
        for (i = 0; i < TARGET_FPREGS; i++)
P
pbrook 已提交
5002 5003 5004
            cpu_fpr[i] = tcg_global_mem_new_i32(TCG_AREG0,
                                                offsetof(CPUState, fpr[i]),
                                                fregnames[i]);
B
blueswir1 已提交
5005

B
blueswir1 已提交
5006 5007
        /* register helpers */

P
pbrook 已提交
5008
#define GEN_HELPER 2
B
blueswir1 已提交
5009
#include "helper.h"
B
blueswir1 已提交
5010
    }
B
bellard 已提交
5011
}
A
aurel32 已提交
5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031

void gen_pc_load(CPUState *env, TranslationBlock *tb,
                unsigned long searched_pc, int pc_pos, void *puc)
{
    target_ulong npc;
    env->pc = gen_opc_pc[pc_pos];
    npc = gen_opc_npc[pc_pos];
    if (npc == 1) {
        /* dynamic NPC: already stored */
    } else if (npc == 2) {
        target_ulong t2 = (target_ulong)(unsigned long)puc;
        /* jump PC: use T2 and the jump targets of the translation */
        if (t2)
            env->npc = gen_opc_jump_pc[0];
        else
            env->npc = gen_opc_jump_pc[1];
    } else {
        env->npc = npc;
    }
}