translate.c 192.6 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 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
static inline void gen_op_add_cc2(TCGv dst)
{
    gen_cc_clear_icc();
    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);
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
    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);
#endif
    tcg_gen_mov_tl(dst, cpu_cc_dst);
}

static inline void gen_op_addi_cc(TCGv dst, TCGv src1, target_long src2)
{
    tcg_gen_mov_tl(cpu_cc_src, src1);
    tcg_gen_movi_tl(cpu_cc_src2, src2);
    tcg_gen_addi_tl(cpu_cc_dst, cpu_cc_src, src2);
    gen_op_add_cc2(dst);
}

472
static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
473
{
474
    tcg_gen_mov_tl(cpu_cc_src, src1);
475
    tcg_gen_mov_tl(cpu_cc_src2, src2);
476
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
477 478 479 480 481
    gen_op_add_cc2(dst);
}

static inline void gen_op_addx_cc2(TCGv dst)
{
482 483 484
    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);
485
#ifdef TARGET_SPARC64
486 487 488
    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);
489
#endif
490
    tcg_gen_mov_tl(dst, cpu_cc_dst);
491 492
}

493
static inline void gen_op_addxi_cc(TCGv dst, TCGv src1, target_long src2)
494
{
495
    tcg_gen_mov_tl(cpu_cc_src, src1);
496
    tcg_gen_movi_tl(cpu_cc_src2, src2);
497
    gen_mov_reg_C(cpu_tmp0, cpu_psr);
498
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
499
    gen_cc_clear_icc();
500
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
501 502
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
503
    gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
504
#endif
505 506 507 508 509 510 511 512 513 514 515
    tcg_gen_addi_tl(cpu_cc_dst, cpu_cc_dst, src2);
    gen_op_addx_cc2(dst);
}

static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
{
    tcg_gen_mov_tl(cpu_cc_src, src1);
    tcg_gen_mov_tl(cpu_cc_src2, src2);
    gen_mov_reg_C(cpu_tmp0, cpu_psr);
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
    gen_cc_clear_icc();
516
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
517
#ifdef TARGET_SPARC64
518
    gen_cc_clear_xcc();
519
    gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
520
#endif
521 522
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
    gen_op_addx_cc2(dst);
523 524
}

525
static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
526
{
527
    tcg_gen_mov_tl(cpu_cc_src, src1);
528
    tcg_gen_mov_tl(cpu_cc_src2, src2);
529
    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
530
    gen_cc_clear_icc();
531 532 533
    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);
534
    gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
535 536
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
537 538 539
    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);
540
#endif
541
    tcg_gen_mov_tl(dst, cpu_cc_dst);
542 543
}

544
static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
545
{
546
    tcg_gen_mov_tl(cpu_cc_src, src1);
547 548
    tcg_gen_mov_tl(cpu_cc_src2, src2);
    gen_tag_tv(cpu_cc_src, cpu_cc_src2);
549 550
    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);
551
    gen_cc_clear_icc();
552 553
    gen_cc_NZ_icc(cpu_cc_dst);
    gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
554 555
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
556 557 558
    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);
559
#endif
560
    tcg_gen_mov_tl(dst, cpu_cc_dst);
561 562 563 564 565 566
}

/* old op:
    if (src1 < T1)
        env->psr |= PSR_CARRY;
*/
567
static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
568
{
B
blueswir1 已提交
569
    TCGv r_temp1, r_temp2;
570 571 572
    int l1;

    l1 = gen_new_label();
P
pbrook 已提交
573 574
    r_temp1 = tcg_temp_new();
    r_temp2 = tcg_temp_new();
B
blueswir1 已提交
575 576 577
    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);
578 579
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
    gen_set_label(l1);
B
blueswir1 已提交
580 581
    tcg_temp_free(r_temp1);
    tcg_temp_free(r_temp2);
582 583
}

584
#ifdef TARGET_SPARC64
585 586 587
static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
{
    int l1;
588

589 590 591 592
    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);
593
}
594
#endif
595 596 597 598 599

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

P
pbrook 已提交
604
    r_temp = tcg_temp_new();
605
    tcg_gen_xor_tl(r_temp, src1, src2);
606 607
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
608
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
B
blueswir1 已提交
609 610 611
    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 已提交
612
    tcg_temp_free(r_temp);
613 614
}

615
#ifdef TARGET_SPARC64
616 617 618 619
static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
{
    TCGv r_temp;

P
pbrook 已提交
620
    r_temp = tcg_temp_new();
621 622 623 624
    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 已提交
625 626 627
    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 已提交
628
    tcg_temp_free(r_temp);
629
}
630
#endif
631 632 633

static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
{
P
pbrook 已提交
634 635
    TCGv r_temp;
    TCGv_i32 r_const;
636 637 638 639
    int l1;

    l1 = gen_new_label();

P
pbrook 已提交
640
    r_temp = tcg_temp_new();
641
    tcg_gen_xor_tl(r_temp, src1, src2);
642 643
    tcg_gen_xor_tl(cpu_tmp0, src1, dst);
    tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
644
    tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
P
pbrook 已提交
645
    tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
B
blueswir1 已提交
646
    r_const = tcg_const_i32(TT_TOVF);
P
pbrook 已提交
647 648
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
649
    gen_set_label(l1);
B
blueswir1 已提交
650
    tcg_temp_free(r_temp);
651 652
}

653
static inline void gen_op_sub_cc2(TCGv dst)
654
{
655
    gen_cc_clear_icc();
656
    gen_cc_NZ_icc(cpu_cc_dst);
657
    gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
658
    gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
659 660
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
661
    gen_cc_NZ_xcc(cpu_cc_dst);
662
    gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
663
    gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
664
#endif
665
    tcg_gen_mov_tl(dst, cpu_cc_dst);
666 667
}

668 669 670 671 672 673 674 675 676
static inline void gen_op_subi_cc(TCGv dst, TCGv src1, target_long src2)
{
    tcg_gen_mov_tl(cpu_cc_src, src1);
    tcg_gen_movi_tl(cpu_cc_src2, src2);
    tcg_gen_subi_tl(cpu_cc_dst, cpu_cc_src, src2);
    gen_op_sub_cc2(dst);
}

static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
677
{
678
    tcg_gen_mov_tl(cpu_cc_src, src1);
679
    tcg_gen_mov_tl(cpu_cc_src2, src2);
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
    gen_op_sub_cc2(dst);
}

static inline void gen_op_subx_cc2(TCGv dst)
{
    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);
#ifdef TARGET_SPARC64
    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);
#endif
    tcg_gen_mov_tl(dst, cpu_cc_dst);
}

static inline void gen_op_subxi_cc(TCGv dst, TCGv src1, target_long src2)
{
    tcg_gen_mov_tl(cpu_cc_src, src1);
    tcg_gen_movi_tl(cpu_cc_src2, src2);
701
    gen_mov_reg_C(cpu_tmp0, cpu_psr);
702
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
703
    gen_cc_clear_icc();
704
    gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
705 706
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
707
    gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
708
#endif
709 710 711 712 713 714 715 716 717 718 719
    tcg_gen_subi_tl(cpu_cc_dst, cpu_cc_dst, src2);
    gen_op_subx_cc2(dst);
}

static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
{
    tcg_gen_mov_tl(cpu_cc_src, src1);
    tcg_gen_mov_tl(cpu_cc_src2, src2);
    gen_mov_reg_C(cpu_tmp0, cpu_psr);
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
    gen_cc_clear_icc();
720
    gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
721
#ifdef TARGET_SPARC64
722
    gen_cc_clear_xcc();
723
    gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
724
#endif
725 726
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
    gen_op_subx_cc2(dst);
727 728
}

729
static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
730
{
731
    tcg_gen_mov_tl(cpu_cc_src, src1);
732
    tcg_gen_mov_tl(cpu_cc_src2, src2);
733
    tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
734
    gen_cc_clear_icc();
735
    gen_cc_NZ_icc(cpu_cc_dst);
736
    gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
737
    gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
738
    gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
739 740
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
741
    gen_cc_NZ_xcc(cpu_cc_dst);
742
    gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
743
    gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
744
#endif
745
    tcg_gen_mov_tl(dst, cpu_cc_dst);
746 747
}

748
static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
749
{
750
    tcg_gen_mov_tl(cpu_cc_src, src1);
751 752
    tcg_gen_mov_tl(cpu_cc_src2, src2);
    gen_tag_tv(cpu_cc_src, cpu_cc_src2);
753 754
    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);
755
    gen_cc_clear_icc();
756
    gen_cc_NZ_icc(cpu_cc_dst);
757
    gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
758 759
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
760
    gen_cc_NZ_xcc(cpu_cc_dst);
761
    gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
762
    gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
763
#endif
764
    tcg_gen_mov_tl(dst, cpu_cc_dst);
765 766
}

767
static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
768
{
B
blueswir1 已提交
769
    TCGv r_temp;
770
    int l1;
B
blueswir1 已提交
771 772

    l1 = gen_new_label();
P
pbrook 已提交
773
    r_temp = tcg_temp_new();
B
blueswir1 已提交
774 775 776 777 778

    /* old op:
    if (!(env->y & 1))
        T1 = 0;
    */
779
    tcg_gen_andi_tl(cpu_cc_src, src1, 0xffffffff);
780
    tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
781
    tcg_gen_andi_tl(cpu_cc_src2, src2, 0xffffffff);
B
blueswir1 已提交
782
    tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
B
blueswir1 已提交
783
    tcg_gen_movi_tl(cpu_cc_src2, 0);
784
    gen_set_label(l1);
B
blueswir1 已提交
785 786 787

    // b2 = T0 & 1;
    // env->y = (b2 << 31) | (env->y >> 1);
B
blueswir1 已提交
788 789
    tcg_gen_andi_tl(r_temp, cpu_cc_src, 0x1);
    tcg_gen_shli_tl(r_temp, r_temp, 31);
790
    tcg_gen_shri_tl(cpu_tmp0, cpu_y, 1);
791
    tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x7fffffff);
792 793
    tcg_gen_or_tl(cpu_tmp0, cpu_tmp0, r_temp);
    tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
B
blueswir1 已提交
794 795 796 797 798

    // 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 已提交
799
    tcg_temp_free(r_temp);
B
blueswir1 已提交
800 801 802 803

    // T0 = (b1 << 31) | (T0 >> 1);
    // src1 = T0;
    tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
804
    tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
B
blueswir1 已提交
805 806 807
    tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);

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

810
    gen_cc_clear_icc();
811 812 813
    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);
814
    tcg_gen_mov_tl(dst, cpu_cc_dst);
B
blueswir1 已提交
815 816
}

817
static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
818
{
P
pbrook 已提交
819
    TCGv_i64 r_temp, r_temp2;
B
blueswir1 已提交
820

P
pbrook 已提交
821 822
    r_temp = tcg_temp_new_i64();
    r_temp2 = tcg_temp_new_i64();
B
blueswir1 已提交
823

B
blueswir1 已提交
824 825
    tcg_gen_extu_tl_i64(r_temp, src2);
    tcg_gen_extu_tl_i64(r_temp2, src1);
B
blueswir1 已提交
826 827 828
    tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);

    tcg_gen_shri_i64(r_temp, r_temp2, 32);
B
blueswir1 已提交
829
    tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
P
pbrook 已提交
830
    tcg_temp_free_i64(r_temp);
831
    tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
B
blueswir1 已提交
832
#ifdef TARGET_SPARC64
833
    tcg_gen_mov_i64(dst, r_temp2);
B
blueswir1 已提交
834
#else
835
    tcg_gen_trunc_i64_tl(dst, r_temp2);
B
blueswir1 已提交
836
#endif
P
pbrook 已提交
837
    tcg_temp_free_i64(r_temp2);
B
blueswir1 已提交
838 839
}

840
static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
841
{
P
pbrook 已提交
842
    TCGv_i64 r_temp, r_temp2;
B
blueswir1 已提交
843

P
pbrook 已提交
844 845
    r_temp = tcg_temp_new_i64();
    r_temp2 = tcg_temp_new_i64();
B
blueswir1 已提交
846

B
blueswir1 已提交
847 848
    tcg_gen_ext_tl_i64(r_temp, src2);
    tcg_gen_ext_tl_i64(r_temp2, src1);
B
blueswir1 已提交
849 850 851
    tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);

    tcg_gen_shri_i64(r_temp, r_temp2, 32);
B
blueswir1 已提交
852
    tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
P
pbrook 已提交
853
    tcg_temp_free_i64(r_temp);
854
    tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
B
blueswir1 已提交
855
#ifdef TARGET_SPARC64
856
    tcg_gen_mov_i64(dst, r_temp2);
B
blueswir1 已提交
857
#else
858
    tcg_gen_trunc_i64_tl(dst, r_temp2);
B
blueswir1 已提交
859
#endif
P
pbrook 已提交
860
    tcg_temp_free_i64(r_temp2);
B
blueswir1 已提交
861 862
}

B
blueswir1 已提交
863
#ifdef TARGET_SPARC64
B
blueswir1 已提交
864
static inline void gen_trap_ifdivzero_tl(TCGv divisor)
B
blueswir1 已提交
865
{
P
pbrook 已提交
866
    TCGv_i32 r_const;
B
blueswir1 已提交
867 868 869
    int l1;

    l1 = gen_new_label();
P
pbrook 已提交
870
    tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
B
blueswir1 已提交
871
    r_const = tcg_const_i32(TT_DIV_ZERO);
P
pbrook 已提交
872 873
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
B
blueswir1 已提交
874 875 876
    gen_set_label(l1);
}

877
static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
B
blueswir1 已提交
878 879 880 881 882
{
    int l1, l2;

    l1 = gen_new_label();
    l2 = gen_new_label();
883 884
    tcg_gen_mov_tl(cpu_cc_src, src1);
    tcg_gen_mov_tl(cpu_cc_src2, src2);
885
    gen_trap_ifdivzero_tl(cpu_cc_src2);
P
pbrook 已提交
886 887
    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);
888
    tcg_gen_movi_i64(dst, INT64_MIN);
B
blueswir1 已提交
889
    tcg_gen_br(l2);
B
blueswir1 已提交
890
    gen_set_label(l1);
891
    tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
B
blueswir1 已提交
892 893 894 895
    gen_set_label(l2);
}
#endif

896
static inline void gen_op_div_cc(TCGv dst)
897 898 899
{
    int l1;

900
    tcg_gen_mov_tl(cpu_cc_dst, dst);
901
    gen_cc_clear_icc();
902
    gen_cc_NZ_icc(cpu_cc_dst);
903
    l1 = gen_new_label();
904
    tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_src2, 0, l1);
905 906 907 908
    tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
    gen_set_label(l1);
}

909
static inline void gen_op_logic_cc(TCGv dst)
910
{
911 912
    tcg_gen_mov_tl(cpu_cc_dst, dst);

913
    gen_cc_clear_icc();
914
    gen_cc_NZ_icc(cpu_cc_dst);
915 916
#ifdef TARGET_SPARC64
    gen_cc_clear_xcc();
917
    gen_cc_NZ_xcc(cpu_cc_dst);
918
#endif
919 920
}

921 922 923 924 925 926 927
// 1
static inline void gen_op_eval_ba(TCGv dst)
{
    tcg_gen_movi_tl(dst, 1);
}

// Z
P
pbrook 已提交
928
static inline void gen_op_eval_be(TCGv dst, TCGv_i32 src)
929 930 931 932 933
{
    gen_mov_reg_Z(dst, src);
}

// Z | (N ^ V)
P
pbrook 已提交
934
static inline void gen_op_eval_ble(TCGv dst, TCGv_i32 src)
935
{
936
    gen_mov_reg_N(cpu_tmp0, src);
937
    gen_mov_reg_V(dst, src);
938 939 940
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
    gen_mov_reg_Z(cpu_tmp0, src);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
941 942 943
}

// N ^ V
P
pbrook 已提交
944
static inline void gen_op_eval_bl(TCGv dst, TCGv_i32 src)
945
{
946
    gen_mov_reg_V(cpu_tmp0, src);
947
    gen_mov_reg_N(dst, src);
948
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
949 950 951
}

// C | Z
P
pbrook 已提交
952
static inline void gen_op_eval_bleu(TCGv dst, TCGv_i32 src)
953
{
954
    gen_mov_reg_Z(cpu_tmp0, src);
955
    gen_mov_reg_C(dst, src);
956
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
957 958 959
}

// C
P
pbrook 已提交
960
static inline void gen_op_eval_bcs(TCGv dst, TCGv_i32 src)
961 962 963 964 965
{
    gen_mov_reg_C(dst, src);
}

// V
P
pbrook 已提交
966
static inline void gen_op_eval_bvs(TCGv dst, TCGv_i32 src)
967 968 969 970 971 972 973 974 975 976 977
{
    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 已提交
978
static inline void gen_op_eval_bneg(TCGv dst, TCGv_i32 src)
979 980 981 982 983
{
    gen_mov_reg_N(dst, src);
}

// !Z
P
pbrook 已提交
984
static inline void gen_op_eval_bne(TCGv dst, TCGv_i32 src)
985 986 987 988 989 990
{
    gen_mov_reg_Z(dst, src);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !(Z | (N ^ V))
P
pbrook 已提交
991
static inline void gen_op_eval_bg(TCGv dst, TCGv_i32 src)
992
{
993
    gen_mov_reg_N(cpu_tmp0, src);
994
    gen_mov_reg_V(dst, src);
995 996 997
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
    gen_mov_reg_Z(cpu_tmp0, src);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
998 999 1000 1001
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !(N ^ V)
P
pbrook 已提交
1002
static inline void gen_op_eval_bge(TCGv dst, TCGv_i32 src)
1003
{
1004
    gen_mov_reg_V(cpu_tmp0, src);
1005
    gen_mov_reg_N(dst, src);
1006
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1007 1008 1009 1010
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !(C | Z)
P
pbrook 已提交
1011
static inline void gen_op_eval_bgu(TCGv dst, TCGv_i32 src)
1012
{
1013
    gen_mov_reg_Z(cpu_tmp0, src);
1014
    gen_mov_reg_C(dst, src);
1015
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
1016 1017 1018 1019
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !C
P
pbrook 已提交
1020
static inline void gen_op_eval_bcc(TCGv dst, TCGv_i32 src)
1021 1022 1023 1024 1025 1026
{
    gen_mov_reg_C(dst, src);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !N
P
pbrook 已提交
1027
static inline void gen_op_eval_bpos(TCGv dst, TCGv_i32 src)
1028 1029 1030 1031 1032 1033
{
    gen_mov_reg_N(dst, src);
    tcg_gen_xori_tl(dst, dst, 0x1);
}

// !V
P
pbrook 已提交
1034
static inline void gen_op_eval_bvc(TCGv dst, TCGv_i32 src)
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
{
    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)
{
1050
    tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
1051 1052 1053 1054 1055 1056
    tcg_gen_andi_tl(reg, reg, 0x1);
}

static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
                                    unsigned int fcc_offset)
{
1057
    tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
1058 1059 1060 1061 1062 1063 1064 1065
    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);
1066 1067
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
1068 1069 1070 1071 1072 1073 1074
}

// 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);
1075 1076
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
}

// 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);
1091 1092 1093
    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);
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
}

// 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);
1109 1110
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1111 1112 1113 1114 1115 1116 1117
}

// 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);
1118 1119
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1120 1121 1122 1123 1124 1125 1126
}

// 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);
1127 1128
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_or_tl(dst, dst, cpu_tmp0);
1129 1130 1131 1132 1133 1134 1135 1136
    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);
1137 1138
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
    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);
1155 1156 1157
    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);
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
    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);
1175 1176
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1177 1178 1179 1180 1181 1182 1183 1184
    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);
1185 1186
    gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
    tcg_gen_and_tl(dst, dst, cpu_tmp0);
1187 1188 1189
    tcg_gen_xori_tl(dst, dst, 0x1);
}

B
blueswir1 已提交
1190
static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1191
                               target_ulong pc2, TCGv r_cond)
B
bellard 已提交
1192 1193 1194 1195 1196
{
    int l1;

    l1 = gen_new_label();

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

1199
    gen_goto_tb(dc, 0, pc1, pc1 + 4);
B
bellard 已提交
1200 1201

    gen_set_label(l1);
1202
    gen_goto_tb(dc, 1, pc2, pc2 + 4);
B
bellard 已提交
1203 1204
}

B
blueswir1 已提交
1205
static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1206
                                target_ulong pc2, TCGv r_cond)
B
bellard 已提交
1207 1208 1209 1210 1211
{
    int l1;

    l1 = gen_new_label();

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

1214
    gen_goto_tb(dc, 0, pc2, pc1);
B
bellard 已提交
1215 1216

    gen_set_label(l1);
1217
    gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
B
bellard 已提交
1218 1219
}

1220 1221
static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
                                      TCGv r_cond)
B
bellard 已提交
1222 1223 1224 1225 1226
{
    int l1, l2;

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

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

B
blueswir1 已提交
1230
    tcg_gen_movi_tl(cpu_npc, npc1);
B
blueswir1 已提交
1231
    tcg_gen_br(l2);
B
bellard 已提交
1232 1233

    gen_set_label(l1);
B
blueswir1 已提交
1234
    tcg_gen_movi_tl(cpu_npc, npc2);
B
bellard 已提交
1235 1236 1237
    gen_set_label(l2);
}

1238 1239 1240
/* 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 已提交
1241 1242
{
    if (dc->npc == JUMP_PC) {
1243
        gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
B
bellard 已提交
1244 1245 1246 1247
        dc->npc = DYNAMIC_PC;
    }
}

1248
static inline void save_npc(DisasContext *dc, TCGv cond)
B
bellard 已提交
1249 1250
{
    if (dc->npc == JUMP_PC) {
1251
        gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
B
bellard 已提交
1252 1253
        dc->npc = DYNAMIC_PC;
    } else if (dc->npc != DYNAMIC_PC) {
B
blueswir1 已提交
1254
        tcg_gen_movi_tl(cpu_npc, dc->npc);
B
bellard 已提交
1255 1256 1257
    }
}

1258
static inline void save_state(DisasContext *dc, TCGv cond)
B
bellard 已提交
1259
{
B
blueswir1 已提交
1260
    tcg_gen_movi_tl(cpu_pc, dc->pc);
1261
    save_npc(dc, cond);
B
bellard 已提交
1262 1263
}

1264
static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
B
bellard 已提交
1265 1266
{
    if (dc->npc == JUMP_PC) {
1267
        gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
B
blueswir1 已提交
1268
        tcg_gen_mov_tl(cpu_pc, cpu_npc);
B
bellard 已提交
1269 1270
        dc->pc = DYNAMIC_PC;
    } else if (dc->npc == DYNAMIC_PC) {
B
blueswir1 已提交
1271
        tcg_gen_mov_tl(cpu_pc, cpu_npc);
B
bellard 已提交
1272 1273 1274 1275 1276 1277
        dc->pc = DYNAMIC_PC;
    } else {
        dc->pc = dc->npc;
    }
}

1278 1279
static inline void gen_op_next_insn(void)
{
B
blueswir1 已提交
1280 1281
    tcg_gen_mov_tl(cpu_pc, cpu_npc);
    tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1282 1283
}

1284 1285
static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
{
P
pbrook 已提交
1286
    TCGv_i32 r_src;
B
bellard 已提交
1287 1288

#ifdef TARGET_SPARC64
1289
    if (cc)
1290
        r_src = cpu_xcc;
1291
    else
1292
        r_src = cpu_psr;
B
bellard 已提交
1293
#else
1294
    r_src = cpu_psr;
B
bellard 已提交
1295
#endif
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
    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;
    }
}
1347

1348
static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1349
{
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
    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 已提交
1373
        gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1374 1375
        break;
    case 0x2:
B
blueswir1 已提交
1376
        gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1377 1378
        break;
    case 0x3:
B
blueswir1 已提交
1379
        gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1380 1381
        break;
    case 0x4:
B
blueswir1 已提交
1382
        gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1383 1384
        break;
    case 0x5:
B
blueswir1 已提交
1385
        gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1386 1387
        break;
    case 0x6:
B
blueswir1 已提交
1388
        gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1389 1390
        break;
    case 0x7:
B
blueswir1 已提交
1391
        gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1392 1393 1394 1395 1396
        break;
    case 0x8:
        gen_op_eval_ba(r_dst);
        break;
    case 0x9:
B
blueswir1 已提交
1397
        gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1398 1399
        break;
    case 0xa:
B
blueswir1 已提交
1400
        gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1401 1402
        break;
    case 0xb:
B
blueswir1 已提交
1403
        gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1404 1405
        break;
    case 0xc:
B
blueswir1 已提交
1406
        gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1407 1408
        break;
    case 0xd:
B
blueswir1 已提交
1409
        gen_op_eval_fble(r_dst, cpu_fsr, offset);
1410 1411
        break;
    case 0xe:
B
blueswir1 已提交
1412
        gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1413 1414
        break;
    case 0xf:
B
blueswir1 已提交
1415
        gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1416 1417
        break;
    }
1418
}
1419

1420
#ifdef TARGET_SPARC64
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
// 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,
};
1432

1433
static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1434 1435 1436 1437
{
    int l1;

    l1 = gen_new_label();
1438
    tcg_gen_movi_tl(r_dst, 0);
P
pbrook 已提交
1439
    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1440 1441 1442
    tcg_gen_movi_tl(r_dst, 1);
    gen_set_label(l1);
}
B
bellard 已提交
1443
#endif
1444

B
bellard 已提交
1445
/* XXX: potentially incorrect if dynamic npc */
1446 1447
static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
                      TCGv r_cond)
1448
{
1449
    unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1450
    target_ulong target = dc->pc + offset;
1451

1452
    if (cond == 0x0) {
B
blueswir1 已提交
1453 1454 1455 1456 1457 1458 1459 1460
        /* 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;
        }
1461
    } else if (cond == 0x8) {
B
blueswir1 已提交
1462 1463 1464 1465 1466 1467 1468 1469
        /* unconditional taken */
        if (a) {
            dc->pc = target;
            dc->npc = dc->pc + 4;
        } else {
            dc->pc = dc->npc;
            dc->npc = target;
        }
1470
    } else {
1471 1472
        flush_cond(dc, r_cond);
        gen_cond(r_cond, cc, cond);
B
blueswir1 已提交
1473
        if (a) {
1474
            gen_branch_a(dc, target, dc->npc, r_cond);
1475
            dc->is_br = 1;
B
blueswir1 已提交
1476
        } else {
1477
            dc->pc = dc->npc;
B
bellard 已提交
1478 1479 1480
            dc->jump_pc[0] = target;
            dc->jump_pc[1] = dc->npc + 4;
            dc->npc = JUMP_PC;
B
blueswir1 已提交
1481
        }
1482
    }
1483 1484
}

B
bellard 已提交
1485
/* XXX: potentially incorrect if dynamic npc */
1486 1487
static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
                      TCGv r_cond)
1488 1489
{
    unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1490 1491
    target_ulong target = dc->pc + offset;

1492
    if (cond == 0x0) {
B
blueswir1 已提交
1493 1494 1495 1496 1497 1498 1499 1500
        /* 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;
        }
1501
    } else if (cond == 0x8) {
B
blueswir1 已提交
1502 1503 1504 1505 1506 1507 1508 1509
        /* unconditional taken */
        if (a) {
            dc->pc = target;
            dc->npc = dc->pc + 4;
        } else {
            dc->pc = dc->npc;
            dc->npc = target;
        }
1510
    } else {
1511 1512
        flush_cond(dc, r_cond);
        gen_fcond(r_cond, cc, cond);
B
blueswir1 已提交
1513
        if (a) {
1514
            gen_branch_a(dc, target, dc->npc, r_cond);
1515
            dc->is_br = 1;
B
blueswir1 已提交
1516
        } else {
1517 1518 1519 1520
            dc->pc = dc->npc;
            dc->jump_pc[0] = target;
            dc->jump_pc[1] = dc->npc + 4;
            dc->npc = JUMP_PC;
B
blueswir1 已提交
1521
        }
1522 1523 1524
    }
}

B
bellard 已提交
1525 1526
#ifdef TARGET_SPARC64
/* XXX: potentially incorrect if dynamic npc */
1527 1528
static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
                          TCGv r_cond, TCGv r_reg)
1529
{
B
bellard 已提交
1530 1531 1532
    unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
    target_ulong target = dc->pc + offset;

1533 1534
    flush_cond(dc, r_cond);
    gen_cond_reg(r_cond, cond, r_reg);
B
bellard 已提交
1535
    if (a) {
1536
        gen_branch_a(dc, target, dc->npc, r_cond);
B
blueswir1 已提交
1537
        dc->is_br = 1;
B
bellard 已提交
1538
    } else {
B
blueswir1 已提交
1539 1540 1541 1542
        dc->pc = dc->npc;
        dc->jump_pc[0] = target;
        dc->jump_pc[1] = dc->npc + 4;
        dc->npc = JUMP_PC;
B
bellard 已提交
1543
    }
1544 1545
}

P
pbrook 已提交
1546
static inline void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1547
{
B
blueswir1 已提交
1548 1549
    switch (fccno) {
    case 0:
P
pbrook 已提交
1550
        gen_helper_fcmps(r_rs1, r_rs2);
B
blueswir1 已提交
1551 1552
        break;
    case 1:
P
pbrook 已提交
1553
        gen_helper_fcmps_fcc1(r_rs1, r_rs2);
B
blueswir1 已提交
1554 1555
        break;
    case 2:
P
pbrook 已提交
1556
        gen_helper_fcmps_fcc2(r_rs1, r_rs2);
B
blueswir1 已提交
1557 1558
        break;
    case 3:
P
pbrook 已提交
1559
        gen_helper_fcmps_fcc3(r_rs1, r_rs2);
B
blueswir1 已提交
1560 1561
        break;
    }
1562 1563 1564 1565
}

static inline void gen_op_fcmpd(int fccno)
{
P
pbrook 已提交
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
    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;
    }
1580 1581 1582 1583
}

static inline void gen_op_fcmpq(int fccno)
{
P
pbrook 已提交
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
    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;
    }
1598 1599
}

P
pbrook 已提交
1600
static inline void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1601
{
B
blueswir1 已提交
1602 1603
    switch (fccno) {
    case 0:
P
pbrook 已提交
1604
        gen_helper_fcmpes(r_rs1, r_rs2);
B
blueswir1 已提交
1605 1606
        break;
    case 1:
P
pbrook 已提交
1607
        gen_helper_fcmpes_fcc1(r_rs1, r_rs2);
B
blueswir1 已提交
1608 1609
        break;
    case 2:
P
pbrook 已提交
1610
        gen_helper_fcmpes_fcc2(r_rs1, r_rs2);
B
blueswir1 已提交
1611 1612
        break;
    case 3:
P
pbrook 已提交
1613
        gen_helper_fcmpes_fcc3(r_rs1, r_rs2);
B
blueswir1 已提交
1614 1615
        break;
    }
1616 1617 1618 1619
}

static inline void gen_op_fcmped(int fccno)
{
P
pbrook 已提交
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
    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;
    }
1634 1635 1636 1637
}

static inline void gen_op_fcmpeq(int fccno)
{
P
pbrook 已提交
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
    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;
    }
1652 1653 1654 1655
}

#else

B
blueswir1 已提交
1656
static inline void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1657
{
P
pbrook 已提交
1658
    gen_helper_fcmps(r_rs1, r_rs2);
1659 1660 1661 1662
}

static inline void gen_op_fcmpd(int fccno)
{
P
pbrook 已提交
1663
    gen_helper_fcmpd();
1664 1665 1666 1667
}

static inline void gen_op_fcmpq(int fccno)
{
P
pbrook 已提交
1668
    gen_helper_fcmpq();
1669 1670
}

B
blueswir1 已提交
1671
static inline void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1672
{
P
pbrook 已提交
1673
    gen_helper_fcmpes(r_rs1, r_rs2);
1674 1675 1676 1677
}

static inline void gen_op_fcmped(int fccno)
{
P
pbrook 已提交
1678
    gen_helper_fcmped();
1679 1680 1681 1682
}

static inline void gen_op_fcmpeq(int fccno)
{
P
pbrook 已提交
1683
    gen_helper_fcmpeq();
1684 1685 1686
}
#endif

B
blueswir1 已提交
1687 1688
static inline void gen_op_fpexception_im(int fsr_flags)
{
P
pbrook 已提交
1689
    TCGv_i32 r_const;
B
blueswir1 已提交
1690

1691
    tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
B
blueswir1 已提交
1692
    tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
B
blueswir1 已提交
1693
    r_const = tcg_const_i32(TT_FP_EXCP);
P
pbrook 已提交
1694 1695
    gen_helper_raise_exception(r_const);
    tcg_temp_free_i32(r_const);
B
blueswir1 已提交
1696 1697
}

1698
static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
B
bellard 已提交
1699 1700 1701
{
#if !defined(CONFIG_USER_ONLY)
    if (!dc->fpu_enabled) {
P
pbrook 已提交
1702
        TCGv_i32 r_const;
B
blueswir1 已提交
1703

1704
        save_state(dc, r_cond);
B
blueswir1 已提交
1705
        r_const = tcg_const_i32(TT_NFPU_INSN);
P
pbrook 已提交
1706 1707
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
bellard 已提交
1708 1709 1710 1711 1712 1713 1714
        dc->is_br = 1;
        return 1;
    }
#endif
    return 0;
}

1715 1716
static inline void gen_op_clear_ieee_excp_and_FTT(void)
{
1717
    tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1718 1719 1720 1721
}

static inline void gen_clear_float_exceptions(void)
{
P
pbrook 已提交
1722
    gen_helper_clear_float_exceptions();
1723 1724
}

B
blueswir1 已提交
1725 1726
/* asi moves */
#ifdef TARGET_SPARC64
P
pbrook 已提交
1727
static inline TCGv_i32 gen_get_asi(int insn, TCGv r_addr)
B
blueswir1 已提交
1728
{
1729
    int asi;
P
pbrook 已提交
1730
    TCGv_i32 r_asi;
B
blueswir1 已提交
1731 1732

    if (IS_IMM) {
P
pbrook 已提交
1733
        r_asi = tcg_temp_new_i32();
1734
        tcg_gen_mov_i32(r_asi, cpu_asi);
B
blueswir1 已提交
1735 1736
    } else {
        asi = GET_FIELD(insn, 19, 26);
1737
        r_asi = tcg_const_i32(asi);
B
blueswir1 已提交
1738
    }
1739 1740 1741
    return r_asi;
}

B
blueswir1 已提交
1742 1743
static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
                              int sign)
1744
{
P
pbrook 已提交
1745
    TCGv_i32 r_asi, r_size, r_sign;
1746

1747
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1748 1749
    r_size = tcg_const_i32(size);
    r_sign = tcg_const_i32(sign);
P
pbrook 已提交
1750 1751 1752 1753
    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 已提交
1754 1755
}

1756
static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
B
blueswir1 已提交
1757
{
P
pbrook 已提交
1758
    TCGv_i32 r_asi, r_size;
B
blueswir1 已提交
1759

1760
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1761
    r_size = tcg_const_i32(size);
P
pbrook 已提交
1762 1763 1764
    gen_helper_st_asi(addr, src, r_asi, r_size);
    tcg_temp_free_i32(r_size);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1765 1766
}

1767
static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
B
blueswir1 已提交
1768
{
P
pbrook 已提交
1769
    TCGv_i32 r_asi, r_size, r_rd;
B
blueswir1 已提交
1770

1771
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1772 1773
    r_size = tcg_const_i32(size);
    r_rd = tcg_const_i32(rd);
P
pbrook 已提交
1774 1775 1776 1777
    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 已提交
1778 1779
}

1780
static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
B
blueswir1 已提交
1781
{
P
pbrook 已提交
1782
    TCGv_i32 r_asi, r_size, r_rd;
B
blueswir1 已提交
1783

1784
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1785 1786
    r_size = tcg_const_i32(size);
    r_rd = tcg_const_i32(rd);
P
pbrook 已提交
1787 1788 1789 1790
    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 已提交
1791 1792
}

1793
static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
B
blueswir1 已提交
1794
{
P
pbrook 已提交
1795
    TCGv_i32 r_asi, r_size, r_sign;
B
blueswir1 已提交
1796

1797
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1798 1799
    r_size = tcg_const_i32(4);
    r_sign = tcg_const_i32(0);
P
pbrook 已提交
1800 1801 1802 1803 1804
    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 已提交
1805
    tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
B
blueswir1 已提交
1806 1807
}

B
blueswir1 已提交
1808
static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
B
blueswir1 已提交
1809
{
P
pbrook 已提交
1810
    TCGv_i32 r_asi, r_rd;
B
blueswir1 已提交
1811

1812
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1813
    r_rd = tcg_const_i32(rd);
P
pbrook 已提交
1814 1815 1816
    gen_helper_ldda_asi(addr, r_asi, r_rd);
    tcg_temp_free_i32(r_rd);
    tcg_temp_free_i32(r_asi);
1817 1818
}

1819
static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1820
{
P
pbrook 已提交
1821
    TCGv_i32 r_asi, r_size;
1822 1823

    gen_movl_reg_TN(rd + 1, cpu_tmp0);
1824
    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
1825
    r_asi = gen_get_asi(insn, addr);
B
blueswir1 已提交
1826
    r_size = tcg_const_i32(8);
P
pbrook 已提交
1827 1828 1829
    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 已提交
1830 1831
}

B
blueswir1 已提交
1832 1833
static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
                               int rd)
B
blueswir1 已提交
1834
{
P
pbrook 已提交
1835 1836
    TCGv r_val1;
    TCGv_i32 r_asi;
B
blueswir1 已提交
1837

P
pbrook 已提交
1838
    r_val1 = tcg_temp_new();
B
blueswir1 已提交
1839
    gen_movl_reg_TN(rd, r_val1);
1840
    r_asi = gen_get_asi(insn, addr);
P
pbrook 已提交
1841 1842
    gen_helper_cas_asi(dst, addr, r_val1, val2, r_asi);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1843
    tcg_temp_free(r_val1);
B
blueswir1 已提交
1844 1845
}

B
blueswir1 已提交
1846 1847
static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
                                int rd)
B
blueswir1 已提交
1848
{
P
pbrook 已提交
1849
    TCGv_i32 r_asi;
B
blueswir1 已提交
1850

B
blueswir1 已提交
1851
    gen_movl_reg_TN(rd, cpu_tmp64);
1852
    r_asi = gen_get_asi(insn, addr);
P
pbrook 已提交
1853 1854
    gen_helper_casx_asi(dst, addr, cpu_tmp64, val2, r_asi);
    tcg_temp_free_i32(r_asi);
B
blueswir1 已提交
1855 1856 1857 1858
}

#elif !defined(CONFIG_USER_ONLY)

B
blueswir1 已提交
1859 1860
static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
                              int sign)
B
blueswir1 已提交
1861
{
P
pbrook 已提交
1862
    TCGv_i32 r_asi, r_size, r_sign;
B
blueswir1 已提交
1863

B
blueswir1 已提交
1864 1865 1866
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(size);
    r_sign = tcg_const_i32(sign);
P
pbrook 已提交
1867
    gen_helper_ld_asi(cpu_tmp64, addr, r_asi, r_size, r_sign);
B
blueswir1 已提交
1868 1869 1870
    tcg_temp_free(r_sign);
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
1871
    tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
B
blueswir1 已提交
1872 1873
}

1874
static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
B
blueswir1 已提交
1875
{
P
pbrook 已提交
1876
    TCGv_i32 r_asi, r_size;
B
blueswir1 已提交
1877

1878
    tcg_gen_extu_tl_i64(cpu_tmp64, src);
B
blueswir1 已提交
1879 1880
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(size);
P
pbrook 已提交
1881
    gen_helper_st_asi(addr, cpu_tmp64, r_asi, r_size);
B
blueswir1 已提交
1882 1883
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1884 1885
}

1886
static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
B
blueswir1 已提交
1887
{
P
pbrook 已提交
1888 1889
    TCGv_i32 r_asi, r_size, r_sign;
    TCGv_i64 r_val;
B
blueswir1 已提交
1890

B
blueswir1 已提交
1891 1892 1893
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(4);
    r_sign = tcg_const_i32(0);
P
pbrook 已提交
1894
    gen_helper_ld_asi(cpu_tmp64, addr, r_asi, r_size, r_sign);
B
blueswir1 已提交
1895
    tcg_temp_free(r_sign);
P
pbrook 已提交
1896 1897 1898 1899
    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 已提交
1900 1901
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1902
    tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
B
blueswir1 已提交
1903 1904
}

B
blueswir1 已提交
1905
static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
B
blueswir1 已提交
1906
{
P
pbrook 已提交
1907
    TCGv_i32 r_asi, r_size, r_sign;
B
blueswir1 已提交
1908

B
blueswir1 已提交
1909 1910 1911
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(8);
    r_sign = tcg_const_i32(0);
P
pbrook 已提交
1912
    gen_helper_ld_asi(cpu_tmp64, addr, r_asi, r_size, r_sign);
B
blueswir1 已提交
1913 1914 1915
    tcg_temp_free(r_sign);
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1916 1917
    tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
    gen_movl_TN_reg(rd + 1, cpu_tmp0);
B
blueswir1 已提交
1918
    tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1919
    tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
B
blueswir1 已提交
1920
    gen_movl_TN_reg(rd, hi);
1921 1922
}

1923
static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1924
{
P
pbrook 已提交
1925
    TCGv_i32 r_asi, r_size;
1926 1927

    gen_movl_reg_TN(rd + 1, cpu_tmp0);
1928
    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
B
blueswir1 已提交
1929 1930
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(8);
P
pbrook 已提交
1931
    gen_helper_st_asi(addr, cpu_tmp64, r_asi, r_size);
B
blueswir1 已提交
1932 1933
    tcg_temp_free(r_size);
    tcg_temp_free(r_asi);
B
blueswir1 已提交
1934 1935 1936 1937
}
#endif

#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1938
static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
B
blueswir1 已提交
1939
{
P
pbrook 已提交
1940 1941
    TCGv_i64 r_val;
    TCGv_i32 r_asi, r_size;
B
blueswir1 已提交
1942

1943
    gen_ld_asi(dst, addr, insn, 1, 0);
B
blueswir1 已提交
1944

B
blueswir1 已提交
1945 1946 1947
    r_val = tcg_const_i64(0xffULL);
    r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
    r_size = tcg_const_i32(1);
P
pbrook 已提交
1948 1949 1950 1951
    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 已提交
1952 1953 1954
}
#endif

1955 1956 1957 1958 1959 1960 1961
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)
1962
        r_rs1 = tcg_const_tl(0); // XXX how to free?
1963
    else if (rs1 < 8)
1964
        r_rs1 = cpu_gregs[rs1];
1965 1966 1967 1968 1969
    else
        tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
    return r_rs1;
}

B
blueswir1 已提交
1970 1971 1972 1973 1974
static inline TCGv get_src2(unsigned int insn, TCGv def)
{
    TCGv r_rs2 = def;

    if (IS_IMM) { /* immediate */
B
Blue Swirl 已提交
1975 1976 1977 1978
        target_long simm;

        simm = GET_FIELDs(insn, 19, 31);
        r_rs2 = tcg_const_tl(simm); // XXX how to free?
B
blueswir1 已提交
1979
    } else { /* register */
B
Blue Swirl 已提交
1980 1981
        unsigned int rs2;

B
blueswir1 已提交
1982 1983
        rs2 = GET_FIELD(insn, 27, 31);
        if (rs2 == 0)
B
blueswir1 已提交
1984
            r_rs2 = tcg_const_tl(0); // XXX how to free?
B
blueswir1 已提交
1985 1986 1987 1988 1989 1990 1991 1992
        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 已提交
1993
#define CHECK_IU_FEATURE(dc, FEATURE)                      \
1994
    if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
B
blueswir1 已提交
1995 1996
        goto illegal_insn;
#define CHECK_FPU_FEATURE(dc, FEATURE)                     \
1997
    if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE))  \
B
blueswir1 已提交
1998 1999
        goto nfpu_insn;

B
bellard 已提交
2000
/* before an instruction, dc->pc must be static */
2001 2002 2003
static void disas_sparc_insn(DisasContext * dc)
{
    unsigned int insn, opc, rs1, rs2, rd;
B
Blue Swirl 已提交
2004
    target_long simm;
2005

2006
    if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
B
blueswir1 已提交
2007
        tcg_gen_debug_insn_start(dc->pc);
B
bellard 已提交
2008
    insn = ldl_code(dc->pc);
2009
    opc = GET_FIELD(insn, 0, 1);
2010

2011
    rd = GET_FIELD(insn, 2, 6);
2012

P
pbrook 已提交
2013 2014
    cpu_src1 = tcg_temp_new(); // const
    cpu_src2 = tcg_temp_new(); // const
2015

2016
    switch (opc) {
B
blueswir1 已提交
2017 2018 2019 2020 2021
    case 0:                     /* branches/sethi */
        {
            unsigned int xop = GET_FIELD(insn, 7, 9);
            int32_t target;
            switch (xop) {
B
bellard 已提交
2022
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2023 2024 2025 2026 2027 2028 2029 2030 2031
            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)
2032
                        do_branch(dc, target, insn, 0, cpu_cond);
B
blueswir1 已提交
2033
                    else if (cc == 2)
2034
                        do_branch(dc, target, insn, 1, cpu_cond);
B
blueswir1 已提交
2035 2036 2037 2038 2039 2040 2041
                    else
                        goto illegal_insn;
                    goto jmp_insn;
                }
            case 0x3:           /* V9 BPr */
                {
                    target = GET_FIELD_SP(insn, 0, 13) |
2042
                        (GET_FIELD_SP(insn, 20, 21) << 14);
B
blueswir1 已提交
2043 2044
                    target = sign_extend(target, 16);
                    target <<= 2;
2045
                    cpu_src1 = get_src1(insn, cpu_src1);
2046
                    do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
B
blueswir1 已提交
2047 2048 2049 2050 2051
                    goto jmp_insn;
                }
            case 0x5:           /* V9 FBPcc */
                {
                    int cc = GET_FIELD_SP(insn, 20, 21);
2052
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2053
                        goto jmp_insn;
B
blueswir1 已提交
2054 2055 2056
                    target = GET_FIELD_SP(insn, 0, 18);
                    target = sign_extend(target, 19);
                    target <<= 2;
2057
                    do_fbranch(dc, target, insn, cc, cpu_cond);
B
blueswir1 已提交
2058 2059
                    goto jmp_insn;
                }
2060
#else
B
blueswir1 已提交
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
            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;
2071
                    do_branch(dc, target, insn, 0, cpu_cond);
B
blueswir1 已提交
2072 2073 2074 2075
                    goto jmp_insn;
                }
            case 0x6:           /* FBN+x */
                {
2076
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2077
                        goto jmp_insn;
B
blueswir1 已提交
2078 2079 2080
                    target = GET_FIELD(insn, 10, 31);
                    target = sign_extend(target, 22);
                    target <<= 2;
2081
                    do_fbranch(dc, target, insn, 0, cpu_cond);
B
blueswir1 已提交
2082 2083 2084 2085 2086
                    goto jmp_insn;
                }
            case 0x4:           /* SETHI */
                if (rd) { // nop
                    uint32_t value = GET_FIELD(insn, 10, 31);
B
blueswir1 已提交
2087 2088 2089 2090 2091
                    TCGv r_const;

                    r_const = tcg_const_tl(value << 10);
                    gen_movl_TN_reg(rd, r_const);
                    tcg_temp_free(r_const);
B
blueswir1 已提交
2092 2093 2094 2095
                }
                break;
            case 0x0:           /* UNIMPL */
            default:
B
bellard 已提交
2096
                goto illegal_insn;
B
blueswir1 已提交
2097 2098 2099 2100
            }
            break;
        }
        break;
2101
    case 1:
B
blueswir1 已提交
2102 2103
        /*CALL*/ {
            target_long target = GET_FIELDs(insn, 2, 31) << 2;
B
blueswir1 已提交
2104
            TCGv r_const;
2105

B
blueswir1 已提交
2106 2107 2108
            r_const = tcg_const_tl(dc->pc);
            gen_movl_TN_reg(15, r_const);
            tcg_temp_free(r_const);
B
blueswir1 已提交
2109
            target += dc->pc;
2110
            gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
2111 2112 2113 2114 2115 2116 2117
            dc->npc = target;
        }
        goto jmp_insn;
    case 2:                     /* FPU & Logical Operations */
        {
            unsigned int xop = GET_FIELD(insn, 7, 12);
            if (xop == 0x3a) {  /* generate trap */
2118
                int cond;
B
bellard 已提交
2119

2120
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
2121 2122
                if (IS_IMM) {
                    rs2 = GET_FIELD(insn, 25, 31);
2123
                    tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
2124 2125
                } else {
                    rs2 = GET_FIELD(insn, 27, 31);
B
blueswir1 已提交
2126
                    if (rs2 != 0) {
2127 2128
                        gen_movl_reg_TN(rs2, cpu_src2);
                        tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2129 2130
                    } else
                        tcg_gen_mov_tl(cpu_dst, cpu_src1);
2131 2132 2133
                }
                cond = GET_FIELD(insn, 3, 6);
                if (cond == 0x8) {
2134
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
2135 2136 2137 2138 2139 2140
                    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 已提交
2141 2142
                    tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
                    gen_helper_raise_exception(cpu_tmp32);
2143
                } else if (cond != 0) {
P
pbrook 已提交
2144
                    TCGv r_cond = tcg_temp_new();
B
blueswir1 已提交
2145
                    int l1;
B
bellard 已提交
2146
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2147 2148
                    /* V9 icc/xcc */
                    int cc = GET_FIELD_SP(insn, 11, 12);
B
blueswir1 已提交
2149

2150
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
2151
                    if (cc == 0)
B
blueswir1 已提交
2152
                        gen_cond(r_cond, 0, cond);
B
blueswir1 已提交
2153
                    else if (cc == 2)
B
blueswir1 已提交
2154
                        gen_cond(r_cond, 1, cond);
B
blueswir1 已提交
2155 2156
                    else
                        goto illegal_insn;
B
bellard 已提交
2157
#else
2158
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
2159
                    gen_cond(r_cond, 0, cond);
B
bellard 已提交
2160
#endif
B
blueswir1 已提交
2161 2162 2163 2164 2165 2166 2167 2168 2169
                    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 已提交
2170 2171
                    tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
                    gen_helper_raise_exception(cpu_tmp32);
B
blueswir1 已提交
2172 2173

                    gen_set_label(l1);
B
blueswir1 已提交
2174
                    tcg_temp_free(r_cond);
2175
                }
B
bellard 已提交
2176
                gen_op_next_insn();
B
bellard 已提交
2177
                tcg_gen_exit_tb(0);
B
bellard 已提交
2178 2179
                dc->is_br = 1;
                goto jmp_insn;
2180 2181 2182 2183
            } else if (xop == 0x28) {
                rs1 = GET_FIELD(insn, 13, 17);
                switch(rs1) {
                case 0: /* rdy */
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193
#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
2194
                    gen_movl_TN_reg(rd, cpu_y);
2195
                    break;
B
bellard 已提交
2196
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2197
                case 0x2: /* V9 rdccr */
P
pbrook 已提交
2198
                    gen_helper_rdccr(cpu_dst);
2199
                    gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
2200
                    break;
B
blueswir1 已提交
2201
                case 0x3: /* V9 rdasi */
2202
                    tcg_gen_ext_i32_tl(cpu_dst, cpu_asi);
2203
                    gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
2204
                    break;
B
blueswir1 已提交
2205
                case 0x4: /* V9 rdtick */
B
blueswir1 已提交
2206
                    {
P
pbrook 已提交
2207
                        TCGv_ptr r_tickptr;
B
blueswir1 已提交
2208

P
pbrook 已提交
2209
                        r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
2210 2211
                        tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                       offsetof(CPUState, tick));
P
pbrook 已提交
2212 2213
                        gen_helper_tick_get_count(cpu_dst, r_tickptr);
                        tcg_temp_free_ptr(r_tickptr);
2214
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
2215
                    }
B
bellard 已提交
2216
                    break;
B
blueswir1 已提交
2217
                case 0x5: /* V9 rdpc */
B
blueswir1 已提交
2218 2219 2220 2221 2222 2223 2224
                    {
                        TCGv r_const;

                        r_const = tcg_const_tl(dc->pc);
                        gen_movl_TN_reg(rd, r_const);
                        tcg_temp_free(r_const);
                    }
B
blueswir1 已提交
2225 2226
                    break;
                case 0x6: /* V9 rdfprs */
2227
                    tcg_gen_ext_i32_tl(cpu_dst, cpu_fprs);
2228
                    gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
2229
                    break;
2230 2231
                case 0xf: /* V9 membar */
                    break; /* no effect */
B
blueswir1 已提交
2232
                case 0x13: /* Graphics Status */
2233
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2234
                        goto jmp_insn;
2235
                    gen_movl_TN_reg(rd, cpu_gsr);
B
bellard 已提交
2236
                    break;
2237 2238 2239 2240
                case 0x16: /* Softint */
                    tcg_gen_ext_i32_tl(cpu_dst, cpu_softint);
                    gen_movl_TN_reg(rd, cpu_dst);
                    break;
B
blueswir1 已提交
2241
                case 0x17: /* Tick compare */
2242
                    gen_movl_TN_reg(rd, cpu_tick_cmpr);
B
bellard 已提交
2243
                    break;
B
blueswir1 已提交
2244
                case 0x18: /* System tick */
B
blueswir1 已提交
2245
                    {
P
pbrook 已提交
2246
                        TCGv_ptr r_tickptr;
B
blueswir1 已提交
2247

P
pbrook 已提交
2248
                        r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
2249 2250
                        tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                       offsetof(CPUState, stick));
P
pbrook 已提交
2251 2252
                        gen_helper_tick_get_count(cpu_dst, r_tickptr);
                        tcg_temp_free_ptr(r_tickptr);
2253
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
2254
                    }
B
bellard 已提交
2255
                    break;
B
blueswir1 已提交
2256
                case 0x19: /* System tick compare */
2257
                    gen_movl_TN_reg(rd, cpu_stick_cmpr);
B
bellard 已提交
2258
                    break;
B
blueswir1 已提交
2259 2260 2261 2262 2263
                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 已提交
2264 2265
#endif
                default:
2266 2267
                    goto illegal_insn;
                }
2268
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
2269
            } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
B
bellard 已提交
2270
#ifndef TARGET_SPARC64
B
blueswir1 已提交
2271 2272
                if (!supervisor(dc))
                    goto priv_insn;
P
pbrook 已提交
2273
                gen_helper_rdpsr(cpu_dst);
B
blueswir1 已提交
2274
#else
2275
                CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286
                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
2287
                    tcg_gen_mov_tl(cpu_dst, cpu_hintp);
B
blueswir1 已提交
2288 2289
                    break;
                case 5: // htba
2290
                    tcg_gen_mov_tl(cpu_dst, cpu_htba);
B
blueswir1 已提交
2291 2292
                    break;
                case 6: // hver
2293
                    tcg_gen_mov_tl(cpu_dst, cpu_hver);
B
blueswir1 已提交
2294 2295
                    break;
                case 31: // hstick_cmpr
2296
                    tcg_gen_mov_tl(cpu_dst, cpu_hstick_cmpr);
B
blueswir1 已提交
2297 2298 2299 2300 2301
                    break;
                default:
                    goto illegal_insn;
                }
#endif
2302
                gen_movl_TN_reg(rd, cpu_dst);
2303
                break;
B
bellard 已提交
2304
            } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
B
blueswir1 已提交
2305 2306
                if (!supervisor(dc))
                    goto priv_insn;
B
bellard 已提交
2307 2308
#ifdef TARGET_SPARC64
                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
2309 2310
                switch (rs1) {
                case 0: // tpc
2311
                    {
P
pbrook 已提交
2312
                        TCGv_ptr r_tsptr;
2313

P
pbrook 已提交
2314
                        r_tsptr = tcg_temp_new_ptr();
2315 2316
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
P
pbrook 已提交
2317
                        tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2318
                                      offsetof(trap_state, tpc));
P
pbrook 已提交
2319
                        tcg_temp_free_ptr(r_tsptr);
2320
                    }
B
blueswir1 已提交
2321 2322
                    break;
                case 1: // tnpc
2323
                    {
P
pbrook 已提交
2324
                        TCGv_ptr r_tsptr;
2325

P
pbrook 已提交
2326
                        r_tsptr = tcg_temp_new_ptr();
2327 2328
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
2329
                        tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2330
                                      offsetof(trap_state, tnpc));
P
pbrook 已提交
2331
                        tcg_temp_free_ptr(r_tsptr);
2332
                    }
B
blueswir1 已提交
2333 2334
                    break;
                case 2: // tstate
2335
                    {
P
pbrook 已提交
2336
                        TCGv_ptr r_tsptr;
2337

P
pbrook 已提交
2338
                        r_tsptr = tcg_temp_new_ptr();
2339 2340
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
2341
                        tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2342
                                      offsetof(trap_state, tstate));
P
pbrook 已提交
2343
                        tcg_temp_free_ptr(r_tsptr);
2344
                    }
B
blueswir1 已提交
2345 2346
                    break;
                case 3: // tt
2347
                    {
P
pbrook 已提交
2348
                        TCGv_ptr r_tsptr;
2349

P
pbrook 已提交
2350
                        r_tsptr = tcg_temp_new_ptr();
2351 2352
                        tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                       offsetof(CPUState, tsptr));
P
pbrook 已提交
2353
                        tcg_gen_ld_i32(cpu_tmp32, r_tsptr,
2354
                                       offsetof(trap_state, tt));
P
pbrook 已提交
2355 2356
                        tcg_temp_free_ptr(r_tsptr);
                        tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2357
                    }
B
blueswir1 已提交
2358 2359
                    break;
                case 4: // tick
B
blueswir1 已提交
2360
                    {
P
pbrook 已提交
2361
                        TCGv_ptr r_tickptr;
B
blueswir1 已提交
2362

P
pbrook 已提交
2363
                        r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
2364 2365
                        tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                       offsetof(CPUState, tick));
P
pbrook 已提交
2366
                        gen_helper_tick_get_count(cpu_tmp0, r_tickptr);
2367
                        gen_movl_TN_reg(rd, cpu_tmp0);
P
pbrook 已提交
2368
                        tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
2369
                    }
B
blueswir1 已提交
2370 2371
                    break;
                case 5: // tba
2372
                    tcg_gen_mov_tl(cpu_tmp0, cpu_tbr);
B
blueswir1 已提交
2373 2374
                    break;
                case 6: // pstate
B
blueswir1 已提交
2375 2376
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, pstate));
2377
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2378 2379
                    break;
                case 7: // tl
B
blueswir1 已提交
2380 2381
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, tl));
2382
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2383 2384
                    break;
                case 8: // pil
B
blueswir1 已提交
2385 2386
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, psrpil));
2387
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2388 2389
                    break;
                case 9: // cwp
P
pbrook 已提交
2390
                    gen_helper_rdcwp(cpu_tmp0);
B
blueswir1 已提交
2391 2392
                    break;
                case 10: // cansave
B
blueswir1 已提交
2393 2394
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, cansave));
2395
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2396 2397
                    break;
                case 11: // canrestore
B
blueswir1 已提交
2398 2399
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, canrestore));
2400
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2401 2402
                    break;
                case 12: // cleanwin
B
blueswir1 已提交
2403 2404
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, cleanwin));
2405
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2406 2407
                    break;
                case 13: // otherwin
B
blueswir1 已提交
2408 2409
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, otherwin));
2410
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2411 2412
                    break;
                case 14: // wstate
B
blueswir1 已提交
2413 2414
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, wstate));
2415
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2416
                    break;
B
blueswir1 已提交
2417
                case 16: // UA2005 gl
2418
                    CHECK_IU_FEATURE(dc, GL);
B
blueswir1 已提交
2419 2420
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env,
                                   offsetof(CPUSPARCState, gl));
2421
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
B
blueswir1 已提交
2422 2423
                    break;
                case 26: // UA2005 strand status
2424
                    CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
2425 2426
                    if (!hypervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
2427
                    tcg_gen_mov_tl(cpu_tmp0, cpu_ssr);
B
blueswir1 已提交
2428
                    break;
B
blueswir1 已提交
2429
                case 31: // ver
2430
                    tcg_gen_mov_tl(cpu_tmp0, cpu_ver);
B
blueswir1 已提交
2431 2432 2433 2434 2435
                    break;
                case 15: // fq
                default:
                    goto illegal_insn;
                }
B
bellard 已提交
2436
#else
2437
                tcg_gen_ext_i32_tl(cpu_tmp0, cpu_wim);
B
bellard 已提交
2438
#endif
2439
                gen_movl_TN_reg(rd, cpu_tmp0);
2440
                break;
B
bellard 已提交
2441 2442
            } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
#ifdef TARGET_SPARC64
2443
                save_state(dc, cpu_cond);
P
pbrook 已提交
2444
                gen_helper_flushw();
B
bellard 已提交
2445
#else
B
blueswir1 已提交
2446 2447
                if (!supervisor(dc))
                    goto priv_insn;
2448
                gen_movl_TN_reg(rd, cpu_tbr);
B
bellard 已提交
2449
#endif
2450 2451
                break;
#endif
B
blueswir1 已提交
2452
            } else if (xop == 0x34) {   /* FPU Operations */
2453
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2454
                    goto jmp_insn;
B
blueswir1 已提交
2455
                gen_op_clear_ieee_excp_and_FTT();
2456
                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
2457 2458 2459 2460
                rs2 = GET_FIELD(insn, 27, 31);
                xop = GET_FIELD(insn, 18, 26);
                switch (xop) {
                    case 0x1: /* fmovs */
B
blueswir1 已提交
2461
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2462 2463
                        break;
                    case 0x5: /* fnegs */
P
pbrook 已提交
2464
                        gen_helper_fnegs(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2465 2466
                        break;
                    case 0x9: /* fabss */
P
pbrook 已提交
2467
                        gen_helper_fabss(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2468 2469
                        break;
                    case 0x29: /* fsqrts */
B
blueswir1 已提交
2470
                        CHECK_FPU_FEATURE(dc, FSQRT);
2471
                        gen_clear_float_exceptions();
P
pbrook 已提交
2472 2473
                        gen_helper_fsqrts(cpu_tmp32, cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2474
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2475 2476
                        break;
                    case 0x2a: /* fsqrtd */
B
blueswir1 已提交
2477
                        CHECK_FPU_FEATURE(dc, FSQRT);
B
blueswir1 已提交
2478
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2479
                        gen_clear_float_exceptions();
P
pbrook 已提交
2480 2481
                        gen_helper_fsqrtd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2482 2483 2484
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x2b: /* fsqrtq */
B
blueswir1 已提交
2485
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2486
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2487
                        gen_clear_float_exceptions();
P
pbrook 已提交
2488 2489
                        gen_helper_fsqrtq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2490 2491
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2492
                    case 0x41: /* fadds */
2493
                        gen_clear_float_exceptions();
P
pbrook 已提交
2494 2495 2496
                        gen_helper_fadds(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2497
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2498 2499 2500 2501
                        break;
                    case 0x42:
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2502
                        gen_clear_float_exceptions();
P
pbrook 已提交
2503 2504
                        gen_helper_faddd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2505 2506 2507
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x43: /* faddq */
B
blueswir1 已提交
2508
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2509 2510
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2511
                        gen_clear_float_exceptions();
P
pbrook 已提交
2512 2513
                        gen_helper_faddq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2514 2515
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2516
                    case 0x45: /* fsubs */
2517
                        gen_clear_float_exceptions();
P
pbrook 已提交
2518 2519 2520
                        gen_helper_fsubs(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2521
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2522 2523 2524 2525
                        break;
                    case 0x46:
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2526
                        gen_clear_float_exceptions();
P
pbrook 已提交
2527 2528
                        gen_helper_fsubd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2529 2530 2531
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x47: /* fsubq */
B
blueswir1 已提交
2532
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2533 2534
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2535
                        gen_clear_float_exceptions();
P
pbrook 已提交
2536 2537
                        gen_helper_fsubq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2538 2539
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2540 2541
                    case 0x49: /* fmuls */
                        CHECK_FPU_FEATURE(dc, FMUL);
2542
                        gen_clear_float_exceptions();
P
pbrook 已提交
2543 2544 2545
                        gen_helper_fmuls(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2546
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2547
                        break;
B
blueswir1 已提交
2548 2549
                    case 0x4a: /* fmuld */
                        CHECK_FPU_FEATURE(dc, FMUL);
B
blueswir1 已提交
2550 2551
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2552
                        gen_clear_float_exceptions();
P
pbrook 已提交
2553 2554
                        gen_helper_fmuld();
                        gen_helper_check_ieee_exceptions();
2555
                        gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
2556 2557
                        break;
                    case 0x4b: /* fmulq */
B
blueswir1 已提交
2558 2559
                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        CHECK_FPU_FEATURE(dc, FMUL);
B
blueswir1 已提交
2560 2561
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2562
                        gen_clear_float_exceptions();
P
pbrook 已提交
2563 2564
                        gen_helper_fmulq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2565 2566
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2567
                    case 0x4d: /* fdivs */
2568
                        gen_clear_float_exceptions();
P
pbrook 已提交
2569 2570 2571
                        gen_helper_fdivs(cpu_tmp32,
                                         cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2572
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2573 2574 2575 2576
                        break;
                    case 0x4e:
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2577
                        gen_clear_float_exceptions();
P
pbrook 已提交
2578 2579
                        gen_helper_fdivd();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2580 2581 2582
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x4f: /* fdivq */
B
blueswir1 已提交
2583
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2584 2585
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2586
                        gen_clear_float_exceptions();
P
pbrook 已提交
2587 2588
                        gen_helper_fdivq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2589 2590
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
2591
                    case 0x69: /* fsmuld */
B
blueswir1 已提交
2592
                        CHECK_FPU_FEATURE(dc, FSMULD);
2593
                        gen_clear_float_exceptions();
P
pbrook 已提交
2594 2595
                        gen_helper_fsmuld(cpu_fpr[rs1], cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2596 2597 2598
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x6e: /* fdmulq */
B
blueswir1 已提交
2599
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2600 2601
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2602
                        gen_clear_float_exceptions();
P
pbrook 已提交
2603 2604
                        gen_helper_fdmulq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2605 2606
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2607
                    case 0xc4: /* fitos */
2608
                        gen_clear_float_exceptions();
P
pbrook 已提交
2609 2610
                        gen_helper_fitos(cpu_tmp32, cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2611
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2612
                        break;
2613
                    case 0xc6: /* fdtos */
B
blueswir1 已提交
2614
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2615
                        gen_clear_float_exceptions();
P
pbrook 已提交
2616 2617
                        gen_helper_fdtos(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2618
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2619 2620
                        break;
                    case 0xc7: /* fqtos */
B
blueswir1 已提交
2621
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2622
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2623
                        gen_clear_float_exceptions();
P
pbrook 已提交
2624 2625
                        gen_helper_fqtos(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2626
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2627
                        break;
2628
                    case 0xc8: /* fitod */
P
pbrook 已提交
2629
                        gen_helper_fitod(cpu_fpr[rs2]);
B
blueswir1 已提交
2630 2631
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
2632
                    case 0xc9: /* fstod */
P
pbrook 已提交
2633
                        gen_helper_fstod(cpu_fpr[rs2]);
B
blueswir1 已提交
2634 2635 2636
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0xcb: /* fqtod */
B
blueswir1 已提交
2637
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2638
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2639
                        gen_clear_float_exceptions();
P
pbrook 已提交
2640 2641
                        gen_helper_fqtod();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2642 2643
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2644
                    case 0xcc: /* fitoq */
B
blueswir1 已提交
2645
                        CHECK_FPU_FEATURE(dc, FLOAT128);
P
pbrook 已提交
2646
                        gen_helper_fitoq(cpu_fpr[rs2]);
B
blueswir1 已提交
2647 2648
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2649
                    case 0xcd: /* fstoq */
B
blueswir1 已提交
2650
                        CHECK_FPU_FEATURE(dc, FLOAT128);
P
pbrook 已提交
2651
                        gen_helper_fstoq(cpu_fpr[rs2]);
B
blueswir1 已提交
2652 2653
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2654
                    case 0xce: /* fdtoq */
B
blueswir1 已提交
2655
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2656
                        gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
2657
                        gen_helper_fdtoq();
B
blueswir1 已提交
2658 2659
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2660
                    case 0xd1: /* fstoi */
2661
                        gen_clear_float_exceptions();
P
pbrook 已提交
2662 2663
                        gen_helper_fstoi(cpu_tmp32, cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2664
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2665
                        break;
2666
                    case 0xd2: /* fdtoi */
2667
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2668
                        gen_clear_float_exceptions();
P
pbrook 已提交
2669 2670
                        gen_helper_fdtoi(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2671
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2672 2673
                        break;
                    case 0xd3: /* fqtoi */
B
blueswir1 已提交
2674
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2675
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2676
                        gen_clear_float_exceptions();
P
pbrook 已提交
2677 2678
                        gen_helper_fqtoi(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2679
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2680
                        break;
B
bellard 已提交
2681
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2682
                    case 0x2: /* V9 fmovd */
B
blueswir1 已提交
2683 2684 2685 2686
                        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 已提交
2687
                        break;
B
blueswir1 已提交
2688
                    case 0x3: /* V9 fmovq */
B
blueswir1 已提交
2689
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2690 2691 2692 2693 2694 2695 2696 2697
                        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 已提交
2698
                        break;
B
blueswir1 已提交
2699 2700
                    case 0x6: /* V9 fnegd */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
2701
                        gen_helper_fnegd();
B
blueswir1 已提交
2702 2703
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2704
                    case 0x7: /* V9 fnegq */
B
blueswir1 已提交
2705
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2706
                        gen_op_load_fpr_QT1(QFPREG(rs2));
P
pbrook 已提交
2707
                        gen_helper_fnegq();
B
blueswir1 已提交
2708 2709
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2710 2711
                    case 0xa: /* V9 fabsd */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
2712
                        gen_helper_fabsd();
B
blueswir1 已提交
2713 2714
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2715
                    case 0xb: /* V9 fabsq */
B
blueswir1 已提交
2716
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2717
                        gen_op_load_fpr_QT1(QFPREG(rs2));
P
pbrook 已提交
2718
                        gen_helper_fabsq();
B
blueswir1 已提交
2719 2720
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2721
                    case 0x81: /* V9 fstox */
2722
                        gen_clear_float_exceptions();
P
pbrook 已提交
2723 2724
                        gen_helper_fstox(cpu_fpr[rs2]);
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2725 2726 2727 2728
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x82: /* V9 fdtox */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2729
                        gen_clear_float_exceptions();
P
pbrook 已提交
2730 2731
                        gen_helper_fdtox();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2732 2733
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2734
                    case 0x83: /* V9 fqtox */
B
blueswir1 已提交
2735
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2736
                        gen_op_load_fpr_QT1(QFPREG(rs2));
2737
                        gen_clear_float_exceptions();
P
pbrook 已提交
2738 2739
                        gen_helper_fqtox();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2740 2741
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
B
blueswir1 已提交
2742 2743
                    case 0x84: /* V9 fxtos */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2744
                        gen_clear_float_exceptions();
P
pbrook 已提交
2745 2746
                        gen_helper_fxtos(cpu_tmp32);
                        gen_helper_check_ieee_exceptions();
2747
                        tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
B
blueswir1 已提交
2748 2749 2750
                        break;
                    case 0x88: /* V9 fxtod */
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2751
                        gen_clear_float_exceptions();
P
pbrook 已提交
2752 2753
                        gen_helper_fxtod();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2754 2755 2756
                        gen_op_store_DT0_fpr(DFPREG(rd));
                        break;
                    case 0x8c: /* V9 fxtoq */
B
blueswir1 已提交
2757
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2758
                        gen_op_load_fpr_DT1(DFPREG(rs2));
2759
                        gen_clear_float_exceptions();
P
pbrook 已提交
2760 2761
                        gen_helper_fxtoq();
                        gen_helper_check_ieee_exceptions();
B
blueswir1 已提交
2762 2763
                        gen_op_store_QT0_fpr(QFPREG(rd));
                        break;
B
blueswir1 已提交
2764 2765 2766 2767 2768
#endif
                    default:
                        goto illegal_insn;
                }
            } else if (xop == 0x35) {   /* FPU Operations */
B
bellard 已提交
2769
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2770
                int cond;
B
bellard 已提交
2771
#endif
2772
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
2773
                    goto jmp_insn;
B
blueswir1 已提交
2774
                gen_op_clear_ieee_excp_and_FTT();
2775
                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
2776 2777
                rs2 = GET_FIELD(insn, 27, 31);
                xop = GET_FIELD(insn, 18, 26);
B
bellard 已提交
2778
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2779
                if ((xop & 0x11f) == 0x005) { // V9 fmovsr
B
blueswir1 已提交
2780 2781 2782
                    int l1;

                    l1 = gen_new_label();
B
blueswir1 已提交
2783
                    cond = GET_FIELD_SP(insn, 14, 17);
2784
                    cpu_src1 = get_src1(insn, cpu_src1);
P
pbrook 已提交
2785 2786
                    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
                                       0, l1);
B
blueswir1 已提交
2787
                    tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
2788
                    gen_set_label(l1);
B
blueswir1 已提交
2789 2790
                    break;
                } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
B
blueswir1 已提交
2791 2792 2793
                    int l1;

                    l1 = gen_new_label();
B
blueswir1 已提交
2794
                    cond = GET_FIELD_SP(insn, 14, 17);
2795
                    cpu_src1 = get_src1(insn, cpu_src1);
P
pbrook 已提交
2796 2797
                    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
                                       0, l1);
B
blueswir1 已提交
2798 2799
                    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 已提交
2800
                    gen_set_label(l1);
B
blueswir1 已提交
2801 2802
                    break;
                } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
B
blueswir1 已提交
2803 2804
                    int l1;

B
blueswir1 已提交
2805
                    CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2806
                    l1 = gen_new_label();
B
blueswir1 已提交
2807
                    cond = GET_FIELD_SP(insn, 14, 17);
2808
                    cpu_src1 = get_src1(insn, cpu_src1);
P
pbrook 已提交
2809 2810
                    tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
                                       0, l1);
B
blueswir1 已提交
2811 2812 2813 2814
                    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 已提交
2815
                    gen_set_label(l1);
B
blueswir1 已提交
2816
                    break;
B
blueswir1 已提交
2817 2818 2819
                }
#endif
                switch (xop) {
B
bellard 已提交
2820
#ifdef TARGET_SPARC64
B
blueswir1 已提交
2821
#define FMOVSCC(fcc)                                                    \
2822
                    {                                                   \
2823
                        TCGv r_cond;                                    \
2824 2825 2826
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2827
                        r_cond = tcg_temp_new();             \
2828 2829
                        cond = GET_FIELD_SP(insn, 14, 17);              \
                        gen_fcond(r_cond, fcc, cond);                   \
P
pbrook 已提交
2830 2831
                        tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond,         \
                                           0, l1);                      \
B
blueswir1 已提交
2832 2833 2834 2835 2836 2837 2838 2839 2840 2841
                        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 已提交
2842
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
                        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 已提交
2860
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872
                        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]);      \
2873
                        gen_set_label(l1);                              \
B
blueswir1 已提交
2874
                        tcg_temp_free(r_cond);                          \
2875
                    }
B
blueswir1 已提交
2876
                    case 0x001: /* V9 fmovscc %fcc0 */
B
blueswir1 已提交
2877
                        FMOVSCC(0);
B
blueswir1 已提交
2878 2879
                        break;
                    case 0x002: /* V9 fmovdcc %fcc0 */
B
blueswir1 已提交
2880
                        FMOVDCC(0);
B
blueswir1 已提交
2881 2882
                        break;
                    case 0x003: /* V9 fmovqcc %fcc0 */
B
blueswir1 已提交
2883
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2884
                        FMOVQCC(0);
B
blueswir1 已提交
2885
                        break;
B
blueswir1 已提交
2886
                    case 0x041: /* V9 fmovscc %fcc1 */
B
blueswir1 已提交
2887
                        FMOVSCC(1);
B
blueswir1 已提交
2888 2889
                        break;
                    case 0x042: /* V9 fmovdcc %fcc1 */
B
blueswir1 已提交
2890
                        FMOVDCC(1);
B
blueswir1 已提交
2891 2892
                        break;
                    case 0x043: /* V9 fmovqcc %fcc1 */
B
blueswir1 已提交
2893
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2894
                        FMOVQCC(1);
B
blueswir1 已提交
2895
                        break;
B
blueswir1 已提交
2896
                    case 0x081: /* V9 fmovscc %fcc2 */
B
blueswir1 已提交
2897
                        FMOVSCC(2);
B
blueswir1 已提交
2898 2899
                        break;
                    case 0x082: /* V9 fmovdcc %fcc2 */
B
blueswir1 已提交
2900
                        FMOVDCC(2);
B
blueswir1 已提交
2901 2902
                        break;
                    case 0x083: /* V9 fmovqcc %fcc2 */
B
blueswir1 已提交
2903
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2904
                        FMOVQCC(2);
B
blueswir1 已提交
2905
                        break;
B
blueswir1 已提交
2906
                    case 0x0c1: /* V9 fmovscc %fcc3 */
B
blueswir1 已提交
2907
                        FMOVSCC(3);
B
blueswir1 已提交
2908 2909
                        break;
                    case 0x0c2: /* V9 fmovdcc %fcc3 */
B
blueswir1 已提交
2910
                        FMOVDCC(3);
B
blueswir1 已提交
2911 2912
                        break;
                    case 0x0c3: /* V9 fmovqcc %fcc3 */
B
blueswir1 已提交
2913
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2914
                        FMOVQCC(3);
B
blueswir1 已提交
2915
                        break;
B
blueswir1 已提交
2916 2917 2918 2919 2920 2921 2922 2923 2924
#undef FMOVSCC
#undef FMOVDCC
#undef FMOVQCC
#define FMOVSCC(icc)                                                    \
                    {                                                   \
                        TCGv r_cond;                                    \
                        int l1;                                         \
                                                                        \
                        l1 = gen_new_label();                           \
P
pbrook 已提交
2925
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939
                        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 已提交
2940
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957
                        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 已提交
2958
                        r_cond = tcg_temp_new();             \
B
blueswir1 已提交
2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973
                        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);                          \
                    }
2974

B
blueswir1 已提交
2975
                    case 0x101: /* V9 fmovscc %icc */
B
blueswir1 已提交
2976
                        FMOVSCC(0);
B
blueswir1 已提交
2977 2978
                        break;
                    case 0x102: /* V9 fmovdcc %icc */
B
blueswir1 已提交
2979
                        FMOVDCC(0);
B
blueswir1 已提交
2980
                    case 0x103: /* V9 fmovqcc %icc */
B
blueswir1 已提交
2981
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2982
                        FMOVQCC(0);
B
blueswir1 已提交
2983
                        break;
B
blueswir1 已提交
2984
                    case 0x181: /* V9 fmovscc %xcc */
B
blueswir1 已提交
2985
                        FMOVSCC(1);
B
blueswir1 已提交
2986 2987
                        break;
                    case 0x182: /* V9 fmovdcc %xcc */
B
blueswir1 已提交
2988
                        FMOVDCC(1);
B
blueswir1 已提交
2989 2990
                        break;
                    case 0x183: /* V9 fmovqcc %xcc */
B
blueswir1 已提交
2991
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
2992
                        FMOVQCC(1);
B
blueswir1 已提交
2993
                        break;
B
blueswir1 已提交
2994 2995 2996
#undef FMOVSCC
#undef FMOVDCC
#undef FMOVQCC
B
blueswir1 已提交
2997 2998
#endif
                    case 0x51: /* fcmps, V9 %fcc */
B
blueswir1 已提交
2999
                        gen_op_fcmps(rd & 3, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3000
                        break;
B
blueswir1 已提交
3001
                    case 0x52: /* fcmpd, V9 %fcc */
B
blueswir1 已提交
3002 3003
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
3004
                        gen_op_fcmpd(rd & 3);
B
blueswir1 已提交
3005
                        break;
B
blueswir1 已提交
3006
                    case 0x53: /* fcmpq, V9 %fcc */
B
blueswir1 已提交
3007
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
3008 3009
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
3010
                        gen_op_fcmpq(rd & 3);
B
blueswir1 已提交
3011
                        break;
B
blueswir1 已提交
3012
                    case 0x55: /* fcmpes, V9 %fcc */
B
blueswir1 已提交
3013
                        gen_op_fcmpes(rd & 3, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
3014 3015 3016 3017
                        break;
                    case 0x56: /* fcmped, V9 %fcc */
                        gen_op_load_fpr_DT0(DFPREG(rs1));
                        gen_op_load_fpr_DT1(DFPREG(rs2));
3018
                        gen_op_fcmped(rd & 3);
B
blueswir1 已提交
3019
                        break;
B
blueswir1 已提交
3020
                    case 0x57: /* fcmpeq, V9 %fcc */
B
blueswir1 已提交
3021
                        CHECK_FPU_FEATURE(dc, FLOAT128);
B
blueswir1 已提交
3022 3023
                        gen_op_load_fpr_QT0(QFPREG(rs1));
                        gen_op_load_fpr_QT1(QFPREG(rs2));
3024
                        gen_op_fcmpeq(rd & 3);
B
blueswir1 已提交
3025
                        break;
B
blueswir1 已提交
3026 3027 3028 3029 3030
                    default:
                        goto illegal_insn;
                }
            } else if (xop == 0x2) {
                // clr/mov shortcut
B
bellard 已提交
3031 3032

                rs1 = GET_FIELD(insn, 13, 17);
B
blueswir1 已提交
3033
                if (rs1 == 0) {
B
blueswir1 已提交
3034
                    // or %g0, x, y -> mov T0, x; mov y, T0
B
blueswir1 已提交
3035
                    if (IS_IMM) {       /* immediate */
B
blueswir1 已提交
3036 3037
                        TCGv r_const;

B
Blue Swirl 已提交
3038 3039
                        simm = GET_FIELDs(insn, 19, 31);
                        r_const = tcg_const_tl(simm);
B
blueswir1 已提交
3040 3041
                        gen_movl_TN_reg(rd, r_const);
                        tcg_temp_free(r_const);
B
blueswir1 已提交
3042 3043
                    } else {            /* register */
                        rs2 = GET_FIELD(insn, 27, 31);
3044
                        gen_movl_reg_TN(rs2, cpu_dst);
B
blueswir1 已提交
3045
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3046 3047
                    }
                } else {
3048
                    cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
3049
                    if (IS_IMM) {       /* immediate */
B
Blue Swirl 已提交
3050 3051
                        simm = GET_FIELDs(insn, 19, 31);
                        tcg_gen_ori_tl(cpu_dst, cpu_src1, simm);
B
blueswir1 已提交
3052
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3053 3054 3055 3056
                    } else {            /* register */
                        // or x, %g0, y -> mov T1, x; mov y, T1
                        rs2 = GET_FIELD(insn, 27, 31);
                        if (rs2 != 0) {
3057 3058
                            gen_movl_reg_TN(rs2, cpu_src2);
                            tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
B
blueswir1 已提交
3059
                            gen_movl_TN_reg(rd, cpu_dst);
3060
                        } else
B
blueswir1 已提交
3061
                            gen_movl_TN_reg(rd, cpu_src1);
B
blueswir1 已提交
3062 3063
                    }
                }
B
bellard 已提交
3064
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3065
            } else if (xop == 0x25) { /* sll, V9 sllx */
3066
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
3067
                if (IS_IMM) {   /* immediate */
B
Blue Swirl 已提交
3068
                    simm = GET_FIELDs(insn, 20, 31);
B
blueswir1 已提交
3069
                    if (insn & (1 << 12)) {
B
Blue Swirl 已提交
3070
                        tcg_gen_shli_i64(cpu_dst, cpu_src1, simm & 0x3f);
B
blueswir1 已提交
3071
                    } else {
B
Blue Swirl 已提交
3072
                        tcg_gen_shli_i64(cpu_dst, cpu_src1, simm & 0x1f);
B
blueswir1 已提交
3073
                    }
B
blueswir1 已提交
3074
                } else {                /* register */
B
bellard 已提交
3075
                    rs2 = GET_FIELD(insn, 27, 31);
3076
                    gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
3077
                    if (insn & (1 << 12)) {
3078
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
B
blueswir1 已提交
3079
                    } else {
3080
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
B
blueswir1 已提交
3081
                    }
B
blueswir1 已提交
3082
                    tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
B
bellard 已提交
3083
                }
3084
                gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3085
            } else if (xop == 0x26) { /* srl, V9 srlx */
3086
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
3087
                if (IS_IMM) {   /* immediate */
B
Blue Swirl 已提交
3088
                    simm = GET_FIELDs(insn, 20, 31);
B
blueswir1 已提交
3089
                    if (insn & (1 << 12)) {
B
Blue Swirl 已提交
3090
                        tcg_gen_shri_i64(cpu_dst, cpu_src1, simm & 0x3f);
B
blueswir1 已提交
3091
                    } else {
3092
                        tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
B
Blue Swirl 已提交
3093
                        tcg_gen_shri_i64(cpu_dst, cpu_dst, simm & 0x1f);
B
blueswir1 已提交
3094
                    }
B
blueswir1 已提交
3095
                } else {                /* register */
B
bellard 已提交
3096
                    rs2 = GET_FIELD(insn, 27, 31);
3097
                    gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
3098
                    if (insn & (1 << 12)) {
3099 3100
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
                        tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
B
blueswir1 已提交
3101
                    } else {
3102 3103 3104
                        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 已提交
3105
                    }
B
bellard 已提交
3106
                }
3107
                gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3108
            } else if (xop == 0x27) { /* sra, V9 srax */
3109
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
3110
                if (IS_IMM) {   /* immediate */
B
Blue Swirl 已提交
3111
                    simm = GET_FIELDs(insn, 20, 31);
B
blueswir1 已提交
3112
                    if (insn & (1 << 12)) {
B
Blue Swirl 已提交
3113
                        tcg_gen_sari_i64(cpu_dst, cpu_src1, simm & 0x3f);
B
blueswir1 已提交
3114
                    } else {
3115
                        tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
B
blueswir1 已提交
3116
                        tcg_gen_ext32s_i64(cpu_dst, cpu_dst);
B
Blue Swirl 已提交
3117
                        tcg_gen_sari_i64(cpu_dst, cpu_dst, simm & 0x1f);
B
blueswir1 已提交
3118
                    }
B
blueswir1 已提交
3119
                } else {                /* register */
B
bellard 已提交
3120
                    rs2 = GET_FIELD(insn, 27, 31);
3121
                    gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
3122
                    if (insn & (1 << 12)) {
3123 3124
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
                        tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
B
blueswir1 已提交
3125
                    } else {
3126 3127
                        tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
                        tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
B
blueswir1 已提交
3128
                        tcg_gen_ext32s_i64(cpu_dst, cpu_dst);
3129
                        tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
B
blueswir1 已提交
3130
                    }
B
bellard 已提交
3131
                }
3132
                gen_movl_TN_reg(rd, cpu_dst);
B
bellard 已提交
3133
#endif
3134
            } else if (xop < 0x36) {
3135
                if (xop < 0x20) {
3136 3137
                    cpu_src1 = get_src1(insn, cpu_src1);
                    cpu_src2 = get_src2(insn, cpu_src2);
3138 3139
                    switch (xop & ~0x10) {
                    case 0x0:
3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            if (xop & 0x10) {
                                gen_op_addi_cc(cpu_dst, cpu_src1, simm);
                            } else {
                                tcg_gen_addi_tl(cpu_dst, cpu_src1, simm);
                            }
                        } else {
                            if (xop & 0x10) {
                                gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
                            } else {
                                tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
                            }
                        }
3154 3155
                        break;
                    case 0x1:
3156 3157 3158 3159 3160 3161 3162
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            tcg_gen_andi_tl(cpu_dst, cpu_src1, simm);
                        } else {
                            tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
                        }
                        if (xop & 0x10) {
3163
                            gen_op_logic_cc(cpu_dst);
3164
                        }
3165 3166
                        break;
                    case 0x2:
3167 3168 3169 3170 3171 3172
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            tcg_gen_ori_tl(cpu_dst, cpu_src1, simm);
                        } else {
                            tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
                        }
B
blueswir1 已提交
3173
                        if (xop & 0x10)
3174
                            gen_op_logic_cc(cpu_dst);
B
blueswir1 已提交
3175
                        break;
3176
                    case 0x3:
3177 3178 3179 3180 3181 3182
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            tcg_gen_xori_tl(cpu_dst, cpu_src1, simm);
                        } else {
                            tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
                        }
3183
                        if (xop & 0x10)
3184
                            gen_op_logic_cc(cpu_dst);
3185 3186
                        break;
                    case 0x4:
3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            if (xop & 0x10) {
                                gen_op_subi_cc(cpu_dst, cpu_src1, simm);
                            } else {
                                tcg_gen_subi_tl(cpu_dst, cpu_src1, simm);
                            }
                        } else {
                            if (xop & 0x10) {
                                gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
                            } else {
                                tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
                            }
                        }
3201 3202
                        break;
                    case 0x5:
3203 3204 3205 3206 3207 3208
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            tcg_gen_andi_tl(cpu_dst, cpu_src1, ~simm);
                        } else {
                            tcg_gen_andc_tl(cpu_dst, cpu_src1, cpu_src2);
                        }
3209
                        if (xop & 0x10)
3210
                            gen_op_logic_cc(cpu_dst);
3211 3212
                        break;
                    case 0x6:
3213 3214 3215 3216 3217 3218
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            tcg_gen_ori_tl(cpu_dst, cpu_src1, ~simm);
                        } else {
                            tcg_gen_orc_tl(cpu_dst, cpu_src1, cpu_src2);
                        }
3219
                        if (xop & 0x10)
3220
                            gen_op_logic_cc(cpu_dst);
3221 3222
                        break;
                    case 0x7:
3223 3224 3225 3226 3227 3228 3229
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            tcg_gen_xori_tl(cpu_dst, cpu_src1, ~simm);
                        } else {
                            tcg_gen_not_tl(cpu_tmp0, cpu_src2);
                            tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
                        }
3230
                        if (xop & 0x10)
3231
                            gen_op_logic_cc(cpu_dst);
3232 3233
                        break;
                    case 0x8:
3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            if (xop & 0x10)
                                gen_op_addxi_cc(cpu_dst, cpu_src1, simm);
                            else {
                                gen_mov_reg_C(cpu_tmp0, cpu_psr);
                                tcg_gen_addi_tl(cpu_tmp0, cpu_tmp0, simm);
                                tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
                            }
                        } else {
                            if (xop & 0x10)
                                gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
                            else {
                                gen_mov_reg_C(cpu_tmp0, cpu_psr);
                                tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
                                tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
                            }
3251
                        }
3252
                        break;
P
pbrook 已提交
3253
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3254
                    case 0x9: /* V9 mulx */
3255 3256 3257 3258 3259 3260
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            tcg_gen_muli_i64(cpu_dst, cpu_src1, simm);
                        } else {
                            tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
                        }
P
pbrook 已提交
3261 3262
                        break;
#endif
3263
                    case 0xa:
B
blueswir1 已提交
3264
                        CHECK_IU_FEATURE(dc, MUL);
3265
                        gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3266
                        if (xop & 0x10)
3267
                            gen_op_logic_cc(cpu_dst);
3268 3269
                        break;
                    case 0xb:
B
blueswir1 已提交
3270
                        CHECK_IU_FEATURE(dc, MUL);
3271
                        gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3272
                        if (xop & 0x10)
3273
                            gen_op_logic_cc(cpu_dst);
3274 3275
                        break;
                    case 0xc:
3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292
                        if (IS_IMM) {
                            simm = GET_FIELDs(insn, 19, 31);
                            if (xop & 0x10) {
                                gen_op_subxi_cc(cpu_dst, cpu_src1, simm);
                            } else {
                                gen_mov_reg_C(cpu_tmp0, cpu_psr);
                                tcg_gen_addi_tl(cpu_tmp0, cpu_tmp0, simm);
                                tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
                            }
                        } else {
                            if (xop & 0x10) {
                                gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
                            } else {
                                gen_mov_reg_C(cpu_tmp0, cpu_psr);
                                tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
                                tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
                            }
3293
                        }
3294
                        break;
P
pbrook 已提交
3295
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3296
                    case 0xd: /* V9 udivx */
3297 3298 3299 3300
                        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 已提交
3301 3302
                        break;
#endif
3303
                    case 0xe:
B
blueswir1 已提交
3304
                        CHECK_IU_FEATURE(dc, DIV);
P
pbrook 已提交
3305
                        gen_helper_udiv(cpu_dst, cpu_src1, cpu_src2);
3306
                        if (xop & 0x10)
3307
                            gen_op_div_cc(cpu_dst);
3308 3309
                        break;
                    case 0xf:
B
blueswir1 已提交
3310
                        CHECK_IU_FEATURE(dc, DIV);
P
pbrook 已提交
3311
                        gen_helper_sdiv(cpu_dst, cpu_src1, cpu_src2);
3312
                        if (xop & 0x10)
3313
                            gen_op_div_cc(cpu_dst);
3314 3315 3316 3317
                        break;
                    default:
                        goto illegal_insn;
                    }
3318
                    gen_movl_TN_reg(rd, cpu_dst);
3319
                } else {
3320 3321
                    cpu_src1 = get_src1(insn, cpu_src1);
                    cpu_src2 = get_src2(insn, cpu_src2);
3322
                    switch (xop) {
B
blueswir1 已提交
3323
                    case 0x20: /* taddcc */
3324 3325
                        gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3326 3327
                        break;
                    case 0x21: /* tsubcc */
3328 3329
                        gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3330 3331
                        break;
                    case 0x22: /* taddcctv */
3332 3333 3334
                        save_state(dc, cpu_cond);
                        gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3335 3336
                        break;
                    case 0x23: /* tsubcctv */
3337 3338 3339
                        save_state(dc, cpu_cond);
                        gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3340
                        break;
3341
                    case 0x24: /* mulscc */
3342 3343
                        gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
3344
                        break;
B
bellard 已提交
3345
#ifndef TARGET_SPARC64
B
blueswir1 已提交
3346
                    case 0x25:  /* sll */
3347
                        if (IS_IMM) { /* immediate */
B
Blue Swirl 已提交
3348 3349
                            simm = GET_FIELDs(insn, 20, 31);
                            tcg_gen_shli_tl(cpu_dst, cpu_src1, simm & 0x1f);
3350 3351 3352 3353
                        } else { /* register */
                            tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
                            tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
                        }
3354
                        gen_movl_TN_reg(rd, cpu_dst);
3355
                        break;
B
bellard 已提交
3356
                    case 0x26:  /* srl */
3357
                        if (IS_IMM) { /* immediate */
B
Blue Swirl 已提交
3358 3359
                            simm = GET_FIELDs(insn, 20, 31);
                            tcg_gen_shri_tl(cpu_dst, cpu_src1, simm & 0x1f);
3360 3361 3362 3363
                        } else { /* register */
                            tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
                            tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
                        }
3364
                        gen_movl_TN_reg(rd, cpu_dst);
3365
                        break;
B
bellard 已提交
3366
                    case 0x27:  /* sra */
3367
                        if (IS_IMM) { /* immediate */
B
Blue Swirl 已提交
3368 3369
                            simm = GET_FIELDs(insn, 20, 31);
                            tcg_gen_sari_tl(cpu_dst, cpu_src1, simm & 0x1f);
3370 3371 3372 3373
                        } else { /* register */
                            tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
                            tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
                        }
3374
                        gen_movl_TN_reg(rd, cpu_dst);
3375
                        break;
B
bellard 已提交
3376
#endif
3377 3378 3379
                    case 0x30:
                        {
                            switch(rd) {
B
bellard 已提交
3380
                            case 0: /* wry */
3381 3382
                                tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
                                tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
3383
                                break;
3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394
#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 已提交
3395
                            case 0x2: /* V9 wrccr */
3396
                                tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
P
pbrook 已提交
3397
                                gen_helper_wrccr(cpu_dst);
B
blueswir1 已提交
3398 3399
                                break;
                            case 0x3: /* V9 wrasi */
3400
                                tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3401
                                tcg_gen_trunc_tl_i32(cpu_asi, cpu_dst);
B
blueswir1 已提交
3402 3403
                                break;
                            case 0x6: /* V9 wrfprs */
3404
                                tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3405
                                tcg_gen_trunc_tl_i32(cpu_fprs, cpu_dst);
3406
                                save_state(dc, cpu_cond);
3407
                                gen_op_next_insn();
B
bellard 已提交
3408
                                tcg_gen_exit_tb(0);
3409
                                dc->is_br = 1;
B
blueswir1 已提交
3410 3411
                                break;
                            case 0xf: /* V9 sir, nop if user */
B
bellard 已提交
3412
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3413
                                if (supervisor(dc))
B
blueswir1 已提交
3414
                                    ; // XXX
B
bellard 已提交
3415
#endif
B
blueswir1 已提交
3416 3417
                                break;
                            case 0x13: /* Graphics Status */
3418
                                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
3419
                                    goto jmp_insn;
3420
                                tcg_gen_xor_tl(cpu_gsr, cpu_src1, cpu_src2);
B
blueswir1 已提交
3421
                                break;
3422 3423 3424 3425
                            case 0x14: /* Softint set */
                                if (!supervisor(dc))
                                    goto illegal_insn;
                                tcg_gen_xor_tl(cpu_tmp64, cpu_src1, cpu_src2);
P
pbrook 已提交
3426
                                gen_helper_set_softint(cpu_tmp64);
3427 3428 3429 3430 3431
                                break;
                            case 0x15: /* Softint clear */
                                if (!supervisor(dc))
                                    goto illegal_insn;
                                tcg_gen_xor_tl(cpu_tmp64, cpu_src1, cpu_src2);
P
pbrook 已提交
3432
                                gen_helper_clear_softint(cpu_tmp64);
3433 3434 3435 3436 3437
                                break;
                            case 0x16: /* Softint write */
                                if (!supervisor(dc))
                                    goto illegal_insn;
                                tcg_gen_xor_tl(cpu_tmp64, cpu_src1, cpu_src2);
P
pbrook 已提交
3438
                                gen_helper_write_softint(cpu_tmp64);
3439
                                break;
B
blueswir1 已提交
3440
                            case 0x17: /* Tick compare */
B
bellard 已提交
3441
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3442 3443
                                if (!supervisor(dc))
                                    goto illegal_insn;
B
bellard 已提交
3444
#endif
B
blueswir1 已提交
3445
                                {
P
pbrook 已提交
3446
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3447

3448
                                    tcg_gen_xor_tl(cpu_tick_cmpr, cpu_src1,
3449
                                                   cpu_src2);
P
pbrook 已提交
3450
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3451 3452
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, tick));
P
pbrook 已提交
3453 3454 3455
                                    gen_helper_tick_set_limit(r_tickptr,
                                                              cpu_tick_cmpr);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3456
                                }
B
blueswir1 已提交
3457 3458
                                break;
                            case 0x18: /* System tick */
B
bellard 已提交
3459
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3460 3461
                                if (!supervisor(dc))
                                    goto illegal_insn;
B
bellard 已提交
3462
#endif
B
blueswir1 已提交
3463
                                {
P
pbrook 已提交
3464
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3465

3466 3467
                                    tcg_gen_xor_tl(cpu_dst, cpu_src1,
                                                   cpu_src2);
P
pbrook 已提交
3468
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3469 3470
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, stick));
P
pbrook 已提交
3471 3472 3473
                                    gen_helper_tick_set_count(r_tickptr,
                                                              cpu_dst);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3474
                                }
B
blueswir1 已提交
3475 3476
                                break;
                            case 0x19: /* System tick compare */
B
bellard 已提交
3477
#if !defined(CONFIG_USER_ONLY)
B
blueswir1 已提交
3478 3479
                                if (!supervisor(dc))
                                    goto illegal_insn;
B
bellard 已提交
3480
#endif
B
blueswir1 已提交
3481
                                {
P
pbrook 已提交
3482
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3483

3484
                                    tcg_gen_xor_tl(cpu_stick_cmpr, cpu_src1,
3485
                                                   cpu_src2);
P
pbrook 已提交
3486
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3487 3488
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, stick));
P
pbrook 已提交
3489 3490 3491
                                    gen_helper_tick_set_limit(r_tickptr,
                                                              cpu_stick_cmpr);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3492
                                }
B
blueswir1 已提交
3493
                                break;
B
bellard 已提交
3494

B
blueswir1 已提交
3495
                            case 0x10: /* Performance Control */
B
blueswir1 已提交
3496 3497
                            case 0x11: /* Performance Instrumentation
                                          Counter */
B
blueswir1 已提交
3498
                            case 0x12: /* Dispatch Control */
B
bellard 已提交
3499
#endif
B
bellard 已提交
3500
                            default:
3501 3502 3503 3504
                                goto illegal_insn;
                            }
                        }
                        break;
3505
#if !defined(CONFIG_USER_ONLY)
3506
                    case 0x31: /* wrpsr, V9 saved, restored */
3507
                        {
B
blueswir1 已提交
3508 3509
                            if (!supervisor(dc))
                                goto priv_insn;
B
bellard 已提交
3510
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3511 3512
                            switch (rd) {
                            case 0:
P
pbrook 已提交
3513
                                gen_helper_saved();
B
blueswir1 已提交
3514 3515
                                break;
                            case 1:
P
pbrook 已提交
3516
                                gen_helper_restored();
B
blueswir1 已提交
3517
                                break;
B
blueswir1 已提交
3518 3519 3520 3521 3522
                            case 2: /* UA2005 allclean */
                            case 3: /* UA2005 otherw */
                            case 4: /* UA2005 normalw */
                            case 5: /* UA2005 invalw */
                                // XXX
B
blueswir1 已提交
3523
                            default:
B
bellard 已提交
3524 3525 3526
                                goto illegal_insn;
                            }
#else
3527
                            tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
P
pbrook 已提交
3528
                            gen_helper_wrpsr(cpu_dst);
3529
                            save_state(dc, cpu_cond);
B
bellard 已提交
3530
                            gen_op_next_insn();
B
bellard 已提交
3531
                            tcg_gen_exit_tb(0);
B
blueswir1 已提交
3532
                            dc->is_br = 1;
B
bellard 已提交
3533
#endif
3534 3535
                        }
                        break;
3536
                    case 0x32: /* wrwim, V9 wrpr */
3537
                        {
B
blueswir1 已提交
3538 3539
                            if (!supervisor(dc))
                                goto priv_insn;
3540
                            tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
B
bellard 已提交
3541
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3542 3543
                            switch (rd) {
                            case 0: // tpc
3544
                                {
P
pbrook 已提交
3545
                                    TCGv_ptr r_tsptr;
3546

P
pbrook 已提交
3547
                                    r_tsptr = tcg_temp_new_ptr();
3548 3549
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
3550
                                    tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3551
                                                  offsetof(trap_state, tpc));
P
pbrook 已提交
3552
                                    tcg_temp_free_ptr(r_tsptr);
3553
                                }
B
blueswir1 已提交
3554 3555
                                break;
                            case 1: // tnpc
3556
                                {
P
pbrook 已提交
3557
                                    TCGv_ptr r_tsptr;
3558

P
pbrook 已提交
3559
                                    r_tsptr = tcg_temp_new_ptr();
3560 3561
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
3562
                                    tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3563
                                                  offsetof(trap_state, tnpc));
P
pbrook 已提交
3564
                                    tcg_temp_free_ptr(r_tsptr);
3565
                                }
B
blueswir1 已提交
3566 3567
                                break;
                            case 2: // tstate
3568
                                {
P
pbrook 已提交
3569
                                    TCGv_ptr r_tsptr;
3570

P
pbrook 已提交
3571
                                    r_tsptr = tcg_temp_new_ptr();
3572 3573
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
3574
                                    tcg_gen_st_tl(cpu_tmp0, r_tsptr,
B
blueswir1 已提交
3575 3576
                                                  offsetof(trap_state,
                                                           tstate));
P
pbrook 已提交
3577
                                    tcg_temp_free_ptr(r_tsptr);
3578
                                }
B
blueswir1 已提交
3579 3580
                                break;
                            case 3: // tt
3581
                                {
P
pbrook 已提交
3582
                                    TCGv_ptr r_tsptr;
3583

P
pbrook 已提交
3584
                                    r_tsptr = tcg_temp_new_ptr();
3585 3586
                                    tcg_gen_ld_ptr(r_tsptr, cpu_env,
                                                   offsetof(CPUState, tsptr));
B
blueswir1 已提交
3587 3588
                                    tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
                                    tcg_gen_st_i32(cpu_tmp32, r_tsptr,
3589
                                                   offsetof(trap_state, tt));
P
pbrook 已提交
3590
                                    tcg_temp_free_ptr(r_tsptr);
3591
                                }
B
blueswir1 已提交
3592 3593
                                break;
                            case 4: // tick
B
blueswir1 已提交
3594
                                {
P
pbrook 已提交
3595
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3596

P
pbrook 已提交
3597
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3598 3599
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, tick));
P
pbrook 已提交
3600 3601 3602
                                    gen_helper_tick_set_count(r_tickptr,
                                                              cpu_tmp0);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3603
                                }
B
blueswir1 已提交
3604 3605
                                break;
                            case 5: // tba
3606
                                tcg_gen_mov_tl(cpu_tbr, cpu_tmp0);
B
blueswir1 已提交
3607 3608
                                break;
                            case 6: // pstate
3609
                                save_state(dc, cpu_cond);
P
pbrook 已提交
3610
                                gen_helper_wrpstate(cpu_tmp0);
P
pbrook 已提交
3611
                                gen_op_next_insn();
B
bellard 已提交
3612
                                tcg_gen_exit_tb(0);
P
pbrook 已提交
3613
                                dc->is_br = 1;
B
blueswir1 已提交
3614 3615
                                break;
                            case 7: // tl
3616
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3617 3618
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState, tl));
B
blueswir1 已提交
3619 3620
                                break;
                            case 8: // pil
3621
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3622 3623 3624
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        psrpil));
B
blueswir1 已提交
3625 3626
                                break;
                            case 9: // cwp
P
pbrook 已提交
3627
                                gen_helper_wrcwp(cpu_tmp0);
B
blueswir1 已提交
3628 3629
                                break;
                            case 10: // cansave
3630
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3631 3632 3633
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        cansave));
B
blueswir1 已提交
3634 3635
                                break;
                            case 11: // canrestore
3636
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3637 3638 3639
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        canrestore));
B
blueswir1 已提交
3640 3641
                                break;
                            case 12: // cleanwin
3642
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3643 3644 3645
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        cleanwin));
B
blueswir1 已提交
3646 3647
                                break;
                            case 13: // otherwin
3648
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3649 3650 3651
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        otherwin));
B
blueswir1 已提交
3652 3653
                                break;
                            case 14: // wstate
3654
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3655 3656 3657
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState,
                                                        wstate));
B
blueswir1 已提交
3658
                                break;
B
blueswir1 已提交
3659
                            case 16: // UA2005 gl
3660
                                CHECK_IU_FEATURE(dc, GL);
3661
                                tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3662 3663
                                tcg_gen_st_i32(cpu_tmp32, cpu_env,
                                               offsetof(CPUSPARCState, gl));
B
blueswir1 已提交
3664 3665
                                break;
                            case 26: // UA2005 strand status
3666
                                CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
3667 3668
                                if (!hypervisor(dc))
                                    goto priv_insn;
B
blueswir1 已提交
3669
                                tcg_gen_mov_tl(cpu_ssr, cpu_tmp0);
B
blueswir1 已提交
3670
                                break;
B
blueswir1 已提交
3671 3672 3673
                            default:
                                goto illegal_insn;
                            }
B
bellard 已提交
3674
#else
3675
                            tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
B
blueswir1 已提交
3676 3677 3678
                            if (dc->def->nwindows != 32)
                                tcg_gen_andi_tl(cpu_tmp32, cpu_tmp32,
                                                (1 << dc->def->nwindows) - 1);
3679
                            tcg_gen_mov_i32(cpu_wim, cpu_tmp32);
B
bellard 已提交
3680
#endif
3681 3682
                        }
                        break;
B
blueswir1 已提交
3683
                    case 0x33: /* wrtbr, UA2005 wrhpr */
3684
                        {
B
blueswir1 已提交
3685
#ifndef TARGET_SPARC64
B
blueswir1 已提交
3686 3687
                            if (!supervisor(dc))
                                goto priv_insn;
3688
                            tcg_gen_xor_tl(cpu_tbr, cpu_src1, cpu_src2);
B
blueswir1 已提交
3689
#else
3690
                            CHECK_IU_FEATURE(dc, HYPV);
B
blueswir1 已提交
3691 3692
                            if (!hypervisor(dc))
                                goto priv_insn;
3693
                            tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
B
blueswir1 已提交
3694 3695 3696
                            switch (rd) {
                            case 0: // hpstate
                                // XXX gen_op_wrhpstate();
3697
                                save_state(dc, cpu_cond);
B
blueswir1 已提交
3698
                                gen_op_next_insn();
B
bellard 已提交
3699
                                tcg_gen_exit_tb(0);
B
blueswir1 已提交
3700 3701 3702 3703 3704 3705
                                dc->is_br = 1;
                                break;
                            case 1: // htstate
                                // XXX gen_op_wrhtstate();
                                break;
                            case 3: // hintp
3706
                                tcg_gen_mov_tl(cpu_hintp, cpu_tmp0);
B
blueswir1 已提交
3707 3708
                                break;
                            case 5: // htba
3709
                                tcg_gen_mov_tl(cpu_htba, cpu_tmp0);
B
blueswir1 已提交
3710 3711
                                break;
                            case 31: // hstick_cmpr
B
blueswir1 已提交
3712
                                {
P
pbrook 已提交
3713
                                    TCGv_ptr r_tickptr;
B
blueswir1 已提交
3714

3715
                                    tcg_gen_mov_tl(cpu_hstick_cmpr, cpu_tmp0);
P
pbrook 已提交
3716
                                    r_tickptr = tcg_temp_new_ptr();
B
blueswir1 已提交
3717 3718
                                    tcg_gen_ld_ptr(r_tickptr, cpu_env,
                                                   offsetof(CPUState, hstick));
P
pbrook 已提交
3719 3720 3721
                                    gen_helper_tick_set_limit(r_tickptr,
                                                              cpu_hstick_cmpr);
                                    tcg_temp_free_ptr(r_tickptr);
B
blueswir1 已提交
3722
                                }
B
blueswir1 已提交
3723 3724 3725 3726 3727 3728
                                break;
                            case 6: // hver readonly
                            default:
                                goto illegal_insn;
                            }
#endif
3729 3730 3731
                        }
                        break;
#endif
B
bellard 已提交
3732
#ifdef TARGET_SPARC64
B
blueswir1 已提交
3733 3734 3735 3736
                    case 0x2c: /* V9 movcc */
                        {
                            int cc = GET_FIELD_SP(insn, 11, 12);
                            int cond = GET_FIELD_SP(insn, 14, 17);
B
blueswir1 已提交
3737
                            TCGv r_cond;
3738 3739
                            int l1;

P
pbrook 已提交
3740
                            r_cond = tcg_temp_new();
B
blueswir1 已提交
3741 3742
                            if (insn & (1 << 18)) {
                                if (cc == 0)
B
blueswir1 已提交
3743
                                    gen_cond(r_cond, 0, cond);
B
blueswir1 已提交
3744
                                else if (cc == 2)
B
blueswir1 已提交
3745
                                    gen_cond(r_cond, 1, cond);
B
blueswir1 已提交
3746 3747 3748
                                else
                                    goto illegal_insn;
                            } else {
B
blueswir1 已提交
3749
                                gen_fcond(r_cond, cc, cond);
B
blueswir1 已提交
3750
                            }
3751 3752 3753

                            l1 = gen_new_label();

P
pbrook 已提交
3754
                            tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3755
                            if (IS_IMM) {       /* immediate */
B
blueswir1 已提交
3756 3757
                                TCGv r_const;

B
Blue Swirl 已提交
3758 3759
                                simm = GET_FIELD_SPs(insn, 0, 10);
                                r_const = tcg_const_tl(simm);
B
blueswir1 已提交
3760 3761
                                gen_movl_TN_reg(rd, r_const);
                                tcg_temp_free(r_const);
3762 3763
                            } else {
                                rs2 = GET_FIELD_SP(insn, 0, 4);
B
blueswir1 已提交
3764 3765
                                gen_movl_reg_TN(rs2, cpu_tmp0);
                                gen_movl_TN_reg(rd, cpu_tmp0);
3766 3767
                            }
                            gen_set_label(l1);
B
blueswir1 已提交
3768
                            tcg_temp_free(r_cond);
B
blueswir1 已提交
3769 3770 3771
                            break;
                        }
                    case 0x2d: /* V9 sdivx */
3772 3773
                        gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
                        gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3774 3775 3776
                        break;
                    case 0x2e: /* V9 popc */
                        {
B
blueswir1 已提交
3777
                            cpu_src2 = get_src2(insn, cpu_src2);
P
pbrook 已提交
3778
                            gen_helper_popc(cpu_dst, cpu_src2);
3779
                            gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3780 3781 3782 3783
                        }
                    case 0x2f: /* V9 movr */
                        {
                            int cond = GET_FIELD_SP(insn, 10, 12);
3784 3785
                            int l1;

3786
                            cpu_src1 = get_src1(insn, cpu_src1);
3787 3788 3789

                            l1 = gen_new_label();

P
pbrook 已提交
3790 3791
                            tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
                                              cpu_src1, 0, l1);
B
blueswir1 已提交
3792
                            if (IS_IMM) {       /* immediate */
B
blueswir1 已提交
3793 3794
                                TCGv r_const;

B
Blue Swirl 已提交
3795 3796
                                simm = GET_FIELD_SPs(insn, 0, 9);
                                r_const = tcg_const_tl(simm);
B
blueswir1 已提交
3797 3798
                                gen_movl_TN_reg(rd, r_const);
                                tcg_temp_free(r_const);
3799
                            } else {
B
blueswir1 已提交
3800
                                rs2 = GET_FIELD_SP(insn, 0, 4);
B
blueswir1 已提交
3801 3802
                                gen_movl_reg_TN(rs2, cpu_tmp0);
                                gen_movl_TN_reg(rd, cpu_tmp0);
B
blueswir1 已提交
3803
                            }
3804
                            gen_set_label(l1);
B
blueswir1 已提交
3805 3806 3807 3808 3809 3810 3811
                            break;
                        }
#endif
                    default:
                        goto illegal_insn;
                    }
                }
3812 3813 3814 3815 3816
            } 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);
3817
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
blueswir1 已提交
3818
                    goto jmp_insn;
3819 3820

                switch (opf) {
B
blueswir1 已提交
3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835
                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 已提交
3836
                    CHECK_FPU_FEATURE(dc, VIS1);
3837
                    cpu_src1 = get_src1(insn, cpu_src1);
3838
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3839
                    gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
3840
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3841 3842
                    break;
                case 0x012: /* VIS I array16 */
B
blueswir1 已提交
3843
                    CHECK_FPU_FEATURE(dc, VIS1);
3844
                    cpu_src1 = get_src1(insn, cpu_src1);
3845
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3846
                    gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
3847 3848
                    tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3849 3850
                    break;
                case 0x014: /* VIS I array32 */
B
blueswir1 已提交
3851
                    CHECK_FPU_FEATURE(dc, VIS1);
3852
                    cpu_src1 = get_src1(insn, cpu_src1);
3853
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3854
                    gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
3855 3856
                    tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
3857
                    break;
3858
                case 0x018: /* VIS I alignaddr */
B
blueswir1 已提交
3859
                    CHECK_FPU_FEATURE(dc, VIS1);
3860
                    cpu_src1 = get_src1(insn, cpu_src1);
3861
                    gen_movl_reg_TN(rs2, cpu_src2);
P
pbrook 已提交
3862
                    gen_helper_alignaddr(cpu_dst, cpu_src1, cpu_src2);
3863
                    gen_movl_TN_reg(rd, cpu_dst);
3864
                    break;
B
blueswir1 已提交
3865
                case 0x019: /* VIS II bmask */
3866 3867
                case 0x01a: /* VIS I alignaddrl */
                    // XXX
B
blueswir1 已提交
3868 3869
                    goto illegal_insn;
                case 0x020: /* VIS I fcmple16 */
B
blueswir1 已提交
3870
                    CHECK_FPU_FEATURE(dc, VIS1);
3871 3872
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3873
                    gen_helper_fcmple16();
3874
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3875 3876
                    break;
                case 0x022: /* VIS I fcmpne16 */
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_fcmpne16();
3881
                    gen_op_store_DT0_fpr(DFPREG(rd));
3882
                    break;
B
blueswir1 已提交
3883
                case 0x024: /* VIS I fcmple32 */
B
blueswir1 已提交
3884
                    CHECK_FPU_FEATURE(dc, VIS1);
3885 3886
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3887
                    gen_helper_fcmple32();
3888
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3889 3890
                    break;
                case 0x026: /* VIS I fcmpne32 */
B
blueswir1 已提交
3891
                    CHECK_FPU_FEATURE(dc, VIS1);
3892 3893
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3894
                    gen_helper_fcmpne32();
3895
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3896 3897
                    break;
                case 0x028: /* VIS I fcmpgt16 */
B
blueswir1 已提交
3898
                    CHECK_FPU_FEATURE(dc, VIS1);
3899 3900
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3901
                    gen_helper_fcmpgt16();
3902
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3903 3904
                    break;
                case 0x02a: /* VIS I fcmpeq16 */
B
blueswir1 已提交
3905
                    CHECK_FPU_FEATURE(dc, VIS1);
3906 3907
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3908
                    gen_helper_fcmpeq16();
3909
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3910 3911
                    break;
                case 0x02c: /* VIS I fcmpgt32 */
B
blueswir1 已提交
3912
                    CHECK_FPU_FEATURE(dc, VIS1);
3913 3914
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3915
                    gen_helper_fcmpgt32();
3916
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3917 3918
                    break;
                case 0x02e: /* VIS I fcmpeq32 */
B
blueswir1 已提交
3919
                    CHECK_FPU_FEATURE(dc, VIS1);
3920 3921
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3922
                    gen_helper_fcmpeq32();
3923
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3924 3925
                    break;
                case 0x031: /* VIS I fmul8x16 */
B
blueswir1 已提交
3926
                    CHECK_FPU_FEATURE(dc, VIS1);
3927 3928
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3929
                    gen_helper_fmul8x16();
3930
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3931 3932
                    break;
                case 0x033: /* VIS I fmul8x16au */
B
blueswir1 已提交
3933
                    CHECK_FPU_FEATURE(dc, VIS1);
3934 3935
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3936
                    gen_helper_fmul8x16au();
3937
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3938 3939
                    break;
                case 0x035: /* VIS I fmul8x16al */
B
blueswir1 已提交
3940
                    CHECK_FPU_FEATURE(dc, VIS1);
3941 3942
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3943
                    gen_helper_fmul8x16al();
3944
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3945 3946
                    break;
                case 0x036: /* VIS I fmul8sux16 */
B
blueswir1 已提交
3947
                    CHECK_FPU_FEATURE(dc, VIS1);
3948 3949
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3950
                    gen_helper_fmul8sux16();
3951
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3952 3953
                    break;
                case 0x037: /* VIS I fmul8ulx16 */
B
blueswir1 已提交
3954
                    CHECK_FPU_FEATURE(dc, VIS1);
3955 3956
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3957
                    gen_helper_fmul8ulx16();
3958
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3959 3960
                    break;
                case 0x038: /* VIS I fmuld8sux16 */
B
blueswir1 已提交
3961
                    CHECK_FPU_FEATURE(dc, VIS1);
3962 3963
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3964
                    gen_helper_fmuld8sux16();
3965
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3966 3967
                    break;
                case 0x039: /* VIS I fmuld8ulx16 */
B
blueswir1 已提交
3968
                    CHECK_FPU_FEATURE(dc, VIS1);
3969 3970
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3971
                    gen_helper_fmuld8ulx16();
3972
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3973 3974 3975 3976 3977 3978 3979
                    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;
3980
                case 0x048: /* VIS I faligndata */
B
blueswir1 已提交
3981
                    CHECK_FPU_FEATURE(dc, VIS1);
3982 3983
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3984
                    gen_helper_faligndata();
3985
                    gen_op_store_DT0_fpr(DFPREG(rd));
3986
                    break;
B
blueswir1 已提交
3987
                case 0x04b: /* VIS I fpmerge */
B
blueswir1 已提交
3988
                    CHECK_FPU_FEATURE(dc, VIS1);
3989 3990
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
3991
                    gen_helper_fpmerge();
3992
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
3993 3994 3995 3996 3997
                    break;
                case 0x04c: /* VIS II bshuffle */
                    // XXX
                    goto illegal_insn;
                case 0x04d: /* VIS I fexpand */
B
blueswir1 已提交
3998
                    CHECK_FPU_FEATURE(dc, VIS1);
3999 4000
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
4001
                    gen_helper_fexpand();
4002
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
4003 4004
                    break;
                case 0x050: /* VIS I fpadd16 */
B
blueswir1 已提交
4005
                    CHECK_FPU_FEATURE(dc, VIS1);
4006 4007
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
4008
                    gen_helper_fpadd16();
4009
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
4010 4011
                    break;
                case 0x051: /* VIS I fpadd16s */
B
blueswir1 已提交
4012
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
4013 4014
                    gen_helper_fpadd16s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4015 4016
                    break;
                case 0x052: /* VIS I fpadd32 */
B
blueswir1 已提交
4017
                    CHECK_FPU_FEATURE(dc, VIS1);
4018 4019
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
4020
                    gen_helper_fpadd32();
4021
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
4022 4023
                    break;
                case 0x053: /* VIS I fpadd32s */
B
blueswir1 已提交
4024
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
4025 4026
                    gen_helper_fpadd32s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4027 4028
                    break;
                case 0x054: /* VIS I fpsub16 */
B
blueswir1 已提交
4029
                    CHECK_FPU_FEATURE(dc, VIS1);
4030 4031
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
4032
                    gen_helper_fpsub16();
4033
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
4034 4035
                    break;
                case 0x055: /* VIS I fpsub16s */
B
blueswir1 已提交
4036
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
4037 4038
                    gen_helper_fpsub16s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4039 4040
                    break;
                case 0x056: /* VIS I fpsub32 */
B
blueswir1 已提交
4041
                    CHECK_FPU_FEATURE(dc, VIS1);
4042 4043
                    gen_op_load_fpr_DT0(DFPREG(rs1));
                    gen_op_load_fpr_DT1(DFPREG(rs2));
P
pbrook 已提交
4044
                    gen_helper_fpsub32();
4045
                    gen_op_store_DT0_fpr(DFPREG(rd));
B
blueswir1 已提交
4046 4047
                    break;
                case 0x057: /* VIS I fpsub32s */
B
blueswir1 已提交
4048
                    CHECK_FPU_FEATURE(dc, VIS1);
P
pbrook 已提交
4049 4050
                    gen_helper_fpsub32s(cpu_fpr[rd],
                                        cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4051
                    break;
4052
                case 0x060: /* VIS I fzero */
B
blueswir1 已提交
4053
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4054 4055
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd)], 0);
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd) + 1], 0);
4056 4057
                    break;
                case 0x061: /* VIS I fzeros */
B
blueswir1 已提交
4058
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4059
                    tcg_gen_movi_i32(cpu_fpr[rd], 0);
4060
                    break;
B
blueswir1 已提交
4061
                case 0x062: /* VIS I fnor */
B
blueswir1 已提交
4062
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4063 4064 4065 4066
                    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 已提交
4067 4068
                    break;
                case 0x063: /* VIS I fnors */
B
blueswir1 已提交
4069
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4070
                    tcg_gen_nor_i32(cpu_tmp32, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4071 4072
                    break;
                case 0x064: /* VIS I fandnot2 */
B
blueswir1 已提交
4073
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4074 4075 4076 4077 4078
                    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 已提交
4079 4080
                    break;
                case 0x065: /* VIS I fandnot2s */
B
blueswir1 已提交
4081
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4082
                    tcg_gen_andc_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4083 4084
                    break;
                case 0x066: /* VIS I fnot2 */
B
blueswir1 已提交
4085
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4086 4087 4088
                    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 已提交
4089 4090
                    break;
                case 0x067: /* VIS I fnot2s */
B
blueswir1 已提交
4091
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4092
                    tcg_gen_not_i32(cpu_fpr[rd], cpu_fpr[rs2]);
B
blueswir1 已提交
4093 4094
                    break;
                case 0x068: /* VIS I fandnot1 */
B
blueswir1 已提交
4095
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4096 4097 4098 4099 4100
                    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 已提交
4101 4102
                    break;
                case 0x069: /* VIS I fandnot1s */
B
blueswir1 已提交
4103
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4104
                    tcg_gen_andc_i32(cpu_fpr[rd], cpu_fpr[rs2], cpu_fpr[rs1]);
B
blueswir1 已提交
4105 4106
                    break;
                case 0x06a: /* VIS I fnot1 */
B
blueswir1 已提交
4107
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4108 4109 4110
                    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 已提交
4111 4112
                    break;
                case 0x06b: /* VIS I fnot1s */
B
blueswir1 已提交
4113
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4114
                    tcg_gen_not_i32(cpu_fpr[rd], cpu_fpr[rs1]);
B
blueswir1 已提交
4115 4116
                    break;
                case 0x06c: /* VIS I fxor */
B
blueswir1 已提交
4117
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4118 4119 4120 4121 4122
                    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 已提交
4123 4124
                    break;
                case 0x06d: /* VIS I fxors */
B
blueswir1 已提交
4125
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4126
                    tcg_gen_xor_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4127 4128
                    break;
                case 0x06e: /* VIS I fnand */
B
blueswir1 已提交
4129
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4130 4131 4132 4133
                    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 已提交
4134 4135
                    break;
                case 0x06f: /* VIS I fnands */
B
blueswir1 已提交
4136
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4137
                    tcg_gen_nand_i32(cpu_tmp32, cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4138 4139
                    break;
                case 0x070: /* VIS I fand */
B
blueswir1 已提交
4140
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4141 4142 4143 4144 4145
                    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 已提交
4146 4147
                    break;
                case 0x071: /* VIS I fands */
B
blueswir1 已提交
4148
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4149
                    tcg_gen_and_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4150 4151
                    break;
                case 0x072: /* VIS I fxnor */
B
blueswir1 已提交
4152
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4153 4154 4155 4156 4157 4158
                    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 已提交
4159 4160
                    break;
                case 0x073: /* VIS I fxnors */
B
blueswir1 已提交
4161
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4162 4163
                    tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[rs2], -1);
                    tcg_gen_xor_i32(cpu_fpr[rd], cpu_tmp32, cpu_fpr[rs1]);
B
blueswir1 已提交
4164
                    break;
4165
                case 0x074: /* VIS I fsrc1 */
B
blueswir1 已提交
4166
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4167 4168 4169
                    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]);
4170 4171
                    break;
                case 0x075: /* VIS I fsrc1s */
B
blueswir1 已提交
4172
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4173
                    tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs1]);
4174
                    break;
B
blueswir1 已提交
4175
                case 0x076: /* VIS I fornot2 */
B
blueswir1 已提交
4176
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4177 4178 4179 4180 4181
                    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 已提交
4182 4183
                    break;
                case 0x077: /* VIS I fornot2s */
B
blueswir1 已提交
4184
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4185
                    tcg_gen_orc_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4186
                    break;
4187
                case 0x078: /* VIS I fsrc2 */
B
blueswir1 已提交
4188
                    CHECK_FPU_FEATURE(dc, VIS1);
4189 4190
                    gen_op_load_fpr_DT0(DFPREG(rs2));
                    gen_op_store_DT0_fpr(DFPREG(rd));
4191 4192
                    break;
                case 0x079: /* VIS I fsrc2s */
B
blueswir1 已提交
4193
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4194
                    tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
4195
                    break;
B
blueswir1 已提交
4196
                case 0x07a: /* VIS I fornot1 */
B
blueswir1 已提交
4197
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4198 4199 4200 4201 4202
                    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 已提交
4203 4204
                    break;
                case 0x07b: /* VIS I fornot1s */
B
blueswir1 已提交
4205
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4206
                    tcg_gen_orc_i32(cpu_fpr[rd], cpu_fpr[rs2], cpu_fpr[rs1]);
B
blueswir1 已提交
4207 4208
                    break;
                case 0x07c: /* VIS I for */
B
blueswir1 已提交
4209
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4210 4211 4212 4213 4214
                    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 已提交
4215 4216
                    break;
                case 0x07d: /* VIS I fors */
B
blueswir1 已提交
4217
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4218
                    tcg_gen_or_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
B
blueswir1 已提交
4219
                    break;
4220
                case 0x07e: /* VIS I fone */
B
blueswir1 已提交
4221
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4222 4223
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd)], -1);
                    tcg_gen_movi_i32(cpu_fpr[DFPREG(rd) + 1], -1);
4224 4225
                    break;
                case 0x07f: /* VIS I fones */
B
blueswir1 已提交
4226
                    CHECK_FPU_FEATURE(dc, VIS1);
B
blueswir1 已提交
4227
                    tcg_gen_movi_i32(cpu_fpr[rd], -1);
4228
                    break;
B
blueswir1 已提交
4229 4230 4231 4232
                case 0x080: /* VIS I shutdown */
                case 0x081: /* VIS II siam */
                    // XXX
                    goto illegal_insn;
4233 4234 4235 4236
                default:
                    goto illegal_insn;
                }
#else
B
blueswir1 已提交
4237
                goto ncp_insn;
4238 4239
#endif
            } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4240
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4241
                goto illegal_insn;
4242
#else
B
blueswir1 已提交
4243
                goto ncp_insn;
4244
#endif
B
bellard 已提交
4245
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4246
            } else if (xop == 0x39) { /* V9 return */
P
pbrook 已提交
4247
                TCGv_i32 r_const;
B
blueswir1 已提交
4248

4249
                save_state(dc, cpu_cond);
4250
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
4251
                if (IS_IMM) {   /* immediate */
B
Blue Swirl 已提交
4252 4253
                    simm = GET_FIELDs(insn, 19, 31);
                    tcg_gen_addi_tl(cpu_dst, cpu_src1, simm);
B
blueswir1 已提交
4254
                } else {                /* register */
B
bellard 已提交
4255
                    rs2 = GET_FIELD(insn, 27, 31);
B
blueswir1 已提交
4256
                    if (rs2) {
4257 4258
                        gen_movl_reg_TN(rs2, cpu_src2);
                        tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4259 4260
                    } else
                        tcg_gen_mov_tl(cpu_dst, cpu_src1);
B
bellard 已提交
4261
                }
P
pbrook 已提交
4262
                gen_helper_restore();
4263
                gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
4264
                r_const = tcg_const_i32(3);
P
pbrook 已提交
4265 4266
                gen_helper_check_align(cpu_dst, r_const);
                tcg_temp_free_i32(r_const);
4267
                tcg_gen_mov_tl(cpu_npc, cpu_dst);
B
blueswir1 已提交
4268 4269
                dc->npc = DYNAMIC_PC;
                goto jmp_insn;
B
bellard 已提交
4270
#endif
B
blueswir1 已提交
4271
            } else {
4272
                cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
4273
                if (IS_IMM) {   /* immediate */
B
Blue Swirl 已提交
4274 4275
                    simm = GET_FIELDs(insn, 19, 31);
                    tcg_gen_addi_tl(cpu_dst, cpu_src1, simm);
B
blueswir1 已提交
4276
                } else {                /* register */
B
bellard 已提交
4277
                    rs2 = GET_FIELD(insn, 27, 31);
B
blueswir1 已提交
4278
                    if (rs2) {
4279 4280
                        gen_movl_reg_TN(rs2, cpu_src2);
                        tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4281 4282
                    } else
                        tcg_gen_mov_tl(cpu_dst, cpu_src1);
4283
                }
B
blueswir1 已提交
4284 4285 4286
                switch (xop) {
                case 0x38:      /* jmpl */
                    {
P
pbrook 已提交
4287 4288
                        TCGv r_pc;
                        TCGv_i32 r_const;
B
blueswir1 已提交
4289

P
pbrook 已提交
4290 4291 4292
                        r_pc = tcg_const_tl(dc->pc);
                        gen_movl_TN_reg(rd, r_pc);
                        tcg_temp_free(r_pc);
4293
                        gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
4294
                        r_const = tcg_const_i32(3);
P
pbrook 已提交
4295 4296
                        gen_helper_check_align(cpu_dst, r_const);
                        tcg_temp_free_i32(r_const);
4297
                        tcg_gen_mov_tl(cpu_npc, cpu_dst);
B
blueswir1 已提交
4298 4299 4300
                        dc->npc = DYNAMIC_PC;
                    }
                    goto jmp_insn;
B
bellard 已提交
4301
#if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
B
blueswir1 已提交
4302 4303
                case 0x39:      /* rett, V9 return */
                    {
P
pbrook 已提交
4304
                        TCGv_i32 r_const;
B
blueswir1 已提交
4305

B
blueswir1 已提交
4306 4307
                        if (!supervisor(dc))
                            goto priv_insn;
4308
                        gen_mov_pc_npc(dc, cpu_cond);
B
blueswir1 已提交
4309
                        r_const = tcg_const_i32(3);
P
pbrook 已提交
4310 4311
                        gen_helper_check_align(cpu_dst, r_const);
                        tcg_temp_free_i32(r_const);
4312
                        tcg_gen_mov_tl(cpu_npc, cpu_dst);
B
blueswir1 已提交
4313
                        dc->npc = DYNAMIC_PC;
P
pbrook 已提交
4314
                        gen_helper_rett();
B
blueswir1 已提交
4315 4316 4317 4318
                    }
                    goto jmp_insn;
#endif
                case 0x3b: /* flush */
4319
                    if (!((dc)->def->features & CPU_FEATURE_FLUSH))
B
blueswir1 已提交
4320
                        goto unimp_flush;
P
pbrook 已提交
4321
                    gen_helper_flush(cpu_dst);
B
blueswir1 已提交
4322 4323
                    break;
                case 0x3c:      /* save */
4324
                    save_state(dc, cpu_cond);
P
pbrook 已提交
4325
                    gen_helper_save();
4326
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
4327 4328
                    break;
                case 0x3d:      /* restore */
4329
                    save_state(dc, cpu_cond);
P
pbrook 已提交
4330
                    gen_helper_restore();
4331
                    gen_movl_TN_reg(rd, cpu_dst);
B
blueswir1 已提交
4332
                    break;
B
bellard 已提交
4333
#if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
B
blueswir1 已提交
4334 4335 4336 4337 4338 4339 4340 4341
                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 已提交
4342
                            gen_helper_done();
B
blueswir1 已提交
4343 4344 4345 4346 4347 4348
                            goto jmp_insn;
                        case 1:
                            if (!supervisor(dc))
                                goto priv_insn;
                            dc->npc = DYNAMIC_PC;
                            dc->pc = DYNAMIC_PC;
P
pbrook 已提交
4349
                            gen_helper_retry();
B
blueswir1 已提交
4350 4351 4352 4353 4354 4355 4356 4357 4358 4359
                            goto jmp_insn;
                        default:
                            goto illegal_insn;
                        }
                    }
                    break;
#endif
                default:
                    goto illegal_insn;
                }
4360
            }
B
blueswir1 已提交
4361 4362 4363 4364 4365 4366
            break;
        }
        break;
    case 3:                     /* load/store instructions */
        {
            unsigned int xop = GET_FIELD(insn, 7, 12);
4367 4368

            cpu_src1 = get_src1(insn, cpu_src1);
B
blueswir1 已提交
4369
            if (xop == 0x3c || xop == 0x3e) { // V9 casa/casxa
4370
                rs2 = GET_FIELD(insn, 27, 31);
4371
                gen_movl_reg_TN(rs2, cpu_src2);
B
blueswir1 已提交
4372 4373
                tcg_gen_mov_tl(cpu_addr, cpu_src1);
            } else if (IS_IMM) {     /* immediate */
B
Blue Swirl 已提交
4374 4375
                simm = GET_FIELDs(insn, 19, 31);
                tcg_gen_addi_tl(cpu_addr, cpu_src1, simm);
B
blueswir1 已提交
4376 4377 4378
            } else {            /* register */
                rs2 = GET_FIELD(insn, 27, 31);
                if (rs2 != 0) {
4379 4380
                    gen_movl_reg_TN(rs2, cpu_src2);
                    tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4381 4382
                } else
                    tcg_gen_mov_tl(cpu_addr, cpu_src1);
B
blueswir1 已提交
4383
            }
B
blueswir1 已提交
4384 4385 4386
            if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
                (xop > 0x17 && xop <= 0x1d ) ||
                (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
B
blueswir1 已提交
4387
                switch (xop) {
B
blueswir1 已提交
4388
                case 0x0:       /* load unsigned word */
B
blueswir1 已提交
4389
                    gen_address_mask(dc, cpu_addr);
4390
                    tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4391 4392
                    break;
                case 0x1:       /* load unsigned byte */
B
blueswir1 已提交
4393
                    gen_address_mask(dc, cpu_addr);
4394
                    tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4395 4396
                    break;
                case 0x2:       /* load unsigned halfword */
B
blueswir1 已提交
4397
                    gen_address_mask(dc, cpu_addr);
4398
                    tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4399 4400 4401
                    break;
                case 0x3:       /* load double word */
                    if (rd & 1)
4402
                        goto illegal_insn;
B
blueswir1 已提交
4403
                    else {
P
pbrook 已提交
4404
                        TCGv_i32 r_const;
B
blueswir1 已提交
4405

4406
                        save_state(dc, cpu_cond);
B
blueswir1 已提交
4407
                        r_const = tcg_const_i32(7);
P
pbrook 已提交
4408 4409
                        gen_helper_check_align(cpu_addr, r_const); // XXX remove
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4410
                        gen_address_mask(dc, cpu_addr);
4411
                        tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4412 4413 4414
                        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 已提交
4415
                        tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4416 4417
                        tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
                        tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
B
blueswir1 已提交
4418
                    }
B
blueswir1 已提交
4419 4420
                    break;
                case 0x9:       /* load signed byte */
B
blueswir1 已提交
4421
                    gen_address_mask(dc, cpu_addr);
4422
                    tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4423 4424
                    break;
                case 0xa:       /* load signed halfword */
B
blueswir1 已提交
4425
                    gen_address_mask(dc, cpu_addr);
4426
                    tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4427 4428
                    break;
                case 0xd:       /* ldstub -- XXX: should be atomically */
B
blueswir1 已提交
4429 4430 4431
                    {
                        TCGv r_const;

B
blueswir1 已提交
4432
                        gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4433 4434 4435 4436 4437
                        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 已提交
4438
                    break;
B
blueswir1 已提交
4439 4440
                case 0x0f:      /* swap register with memory. Also
                                   atomically */
B
blueswir1 已提交
4441
                    CHECK_IU_FEATURE(dc, SWAP);
4442
                    gen_movl_reg_TN(rd, cpu_val);
B
blueswir1 已提交
4443
                    gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4444
                    tcg_gen_qemu_ld32u(cpu_tmp0, cpu_addr, dc->mem_idx);
4445
                    tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4446
                    tcg_gen_mov_tl(cpu_val, cpu_tmp0);
B
blueswir1 已提交
4447
                    break;
B
bellard 已提交
4448
#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
B
blueswir1 已提交
4449
                case 0x10:      /* load word alternate */
B
bellard 已提交
4450
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4451 4452 4453 4454
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
4455
#endif
4456
                    save_state(dc, cpu_cond);
4457
                    gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
B
blueswir1 已提交
4458 4459
                    break;
                case 0x11:      /* load unsigned byte alternate */
B
bellard 已提交
4460
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4461 4462 4463 4464 4465
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
#endif
4466
                    save_state(dc, cpu_cond);
4467
                    gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
B
blueswir1 已提交
4468 4469
                    break;
                case 0x12:      /* load unsigned halfword alternate */
B
bellard 已提交
4470
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4471 4472 4473 4474
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4475
#endif
4476
                    save_state(dc, cpu_cond);
4477
                    gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
B
blueswir1 已提交
4478 4479
                    break;
                case 0x13:      /* load double word alternate */
B
bellard 已提交
4480
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4481 4482 4483 4484
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4485
#endif
B
blueswir1 已提交
4486
                    if (rd & 1)
4487
                        goto illegal_insn;
4488
                    save_state(dc, cpu_cond);
B
blueswir1 已提交
4489 4490
                    gen_ldda_asi(cpu_val, cpu_addr, insn, rd);
                    goto skip_move;
B
blueswir1 已提交
4491
                case 0x19:      /* load signed byte alternate */
B
bellard 已提交
4492
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4493 4494 4495 4496 4497
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
#endif
4498
                    save_state(dc, cpu_cond);
4499
                    gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
B
blueswir1 已提交
4500 4501
                    break;
                case 0x1a:      /* load signed halfword alternate */
B
bellard 已提交
4502
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4503 4504 4505 4506
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4507
#endif
4508
                    save_state(dc, cpu_cond);
4509
                    gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
B
blueswir1 已提交
4510 4511
                    break;
                case 0x1d:      /* ldstuba -- XXX: should be atomically */
B
bellard 已提交
4512
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4513 4514 4515 4516 4517
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
#endif
4518
                    save_state(dc, cpu_cond);
4519
                    gen_ldstub_asi(cpu_val, cpu_addr, insn);
B
blueswir1 已提交
4520
                    break;
B
blueswir1 已提交
4521 4522
                case 0x1f:      /* swap reg with alt. memory. Also
                                   atomically */
B
blueswir1 已提交
4523
                    CHECK_IU_FEATURE(dc, SWAP);
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
blueswir1 已提交
4529
#endif
4530
                    save_state(dc, cpu_cond);
4531 4532
                    gen_movl_reg_TN(rd, cpu_val);
                    gen_swap_asi(cpu_val, cpu_addr, insn);
B
blueswir1 已提交
4533
                    break;
B
bellard 已提交
4534 4535

#ifndef TARGET_SPARC64
B
blueswir1 已提交
4536 4537 4538 4539
                case 0x30: /* ldc */
                case 0x31: /* ldcsr */
                case 0x33: /* lddc */
                    goto ncp_insn;
B
bellard 已提交
4540 4541 4542
#endif
#endif
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4543
                case 0x08: /* V9 ldsw */
B
blueswir1 已提交
4544
                    gen_address_mask(dc, cpu_addr);
4545
                    tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4546 4547
                    break;
                case 0x0b: /* V9 ldx */
B
blueswir1 已提交
4548
                    gen_address_mask(dc, cpu_addr);
4549
                    tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4550 4551
                    break;
                case 0x18: /* V9 ldswa */
4552
                    save_state(dc, cpu_cond);
4553
                    gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
B
blueswir1 已提交
4554 4555
                    break;
                case 0x1b: /* V9 ldxa */
4556
                    save_state(dc, cpu_cond);
4557
                    gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
B
blueswir1 已提交
4558 4559 4560 4561
                    break;
                case 0x2d: /* V9 prefetch, no effect */
                    goto skip_move;
                case 0x30: /* V9 ldfa */
4562
                    save_state(dc, cpu_cond);
4563
                    gen_ldf_asi(cpu_addr, insn, 4, rd);
4564
                    goto skip_move;
B
blueswir1 已提交
4565
                case 0x33: /* V9 lddfa */
4566
                    save_state(dc, cpu_cond);
4567
                    gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4568
                    goto skip_move;
B
blueswir1 已提交
4569 4570 4571
                case 0x3d: /* V9 prefetcha, no effect */
                    goto skip_move;
                case 0x32: /* V9 ldqfa */
B
blueswir1 已提交
4572
                    CHECK_FPU_FEATURE(dc, FLOAT128);
4573
                    save_state(dc, cpu_cond);
4574
                    gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
B
blueswir1 已提交
4575
                    goto skip_move;
B
blueswir1 已提交
4576 4577 4578 4579
#endif
                default:
                    goto illegal_insn;
                }
4580
                gen_movl_TN_reg(rd, cpu_val);
B
blueswir1 已提交
4581
#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
B
blueswir1 已提交
4582
            skip_move: ;
B
bellard 已提交
4583
#endif
B
blueswir1 已提交
4584
            } else if (xop >= 0x20 && xop < 0x24) {
4585
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
4586
                    goto jmp_insn;
4587
                save_state(dc, cpu_cond);
B
blueswir1 已提交
4588 4589
                switch (xop) {
                case 0x20:      /* load fpreg */
B
blueswir1 已提交
4590
                    gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4591 4592
                    tcg_gen_qemu_ld32u(cpu_tmp0, cpu_addr, dc->mem_idx);
                    tcg_gen_trunc_tl_i32(cpu_fpr[rd], cpu_tmp0);
B
blueswir1 已提交
4593
                    break;
4594 4595
                case 0x21:      /* ldfsr, V9 ldxfsr */
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4596
                    gen_address_mask(dc, cpu_addr);
4597 4598
                    if (rd == 1) {
                        tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
P
pbrook 已提交
4599
                        gen_helper_ldxfsr(cpu_tmp64);
4600 4601 4602 4603
                    } else
#else
                    {
                        tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
P
pbrook 已提交
4604
                        gen_helper_ldfsr(cpu_tmp32);
4605 4606
                    }
#endif
B
blueswir1 已提交
4607 4608
                    break;
                case 0x22:      /* load quad fpreg */
B
blueswir1 已提交
4609
                    {
P
pbrook 已提交
4610
                        TCGv_i32 r_const;
B
blueswir1 已提交
4611 4612 4613

                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4614 4615
                        gen_helper_ldqf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4616 4617
                        gen_op_store_QT0_fpr(QFPREG(rd));
                    }
B
blueswir1 已提交
4618
                    break;
B
blueswir1 已提交
4619
                case 0x23:      /* load double fpreg */
B
blueswir1 已提交
4620
                    {
P
pbrook 已提交
4621
                        TCGv_i32 r_const;
B
blueswir1 已提交
4622 4623

                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4624 4625
                        gen_helper_lddf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4626 4627
                        gen_op_store_DT0_fpr(DFPREG(rd));
                    }
B
blueswir1 已提交
4628 4629 4630 4631 4632 4633
                    break;
                default:
                    goto illegal_insn;
                }
            } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
                       xop == 0xe || xop == 0x1e) {
4634
                gen_movl_reg_TN(rd, cpu_val);
B
blueswir1 已提交
4635
                switch (xop) {
B
blueswir1 已提交
4636
                case 0x4: /* store word */
B
blueswir1 已提交
4637
                    gen_address_mask(dc, cpu_addr);
4638
                    tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4639
                    break;
B
blueswir1 已提交
4640
                case 0x5: /* store byte */
B
blueswir1 已提交
4641
                    gen_address_mask(dc, cpu_addr);
4642
                    tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4643
                    break;
B
blueswir1 已提交
4644
                case 0x6: /* store halfword */
B
blueswir1 已提交
4645
                    gen_address_mask(dc, cpu_addr);
4646
                    tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4647
                    break;
B
blueswir1 已提交
4648
                case 0x7: /* store double word */
B
blueswir1 已提交
4649
                    if (rd & 1)
4650
                        goto illegal_insn;
B
blueswir1 已提交
4651
                    else {
P
pbrook 已提交
4652
                        TCGv_i32 r_const;
B
blueswir1 已提交
4653

4654
                        save_state(dc, cpu_cond);
B
blueswir1 已提交
4655
                        gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4656
                        r_const = tcg_const_i32(7);
P
pbrook 已提交
4657 4658
                        gen_helper_check_align(cpu_addr, r_const); // XXX remove
                        tcg_temp_free_i32(r_const);
4659
                        gen_movl_reg_TN(rd + 1, cpu_tmp0);
4660
                        tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, cpu_val);
4661
                        tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4662
                    }
B
blueswir1 已提交
4663
                    break;
B
bellard 已提交
4664
#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
B
blueswir1 已提交
4665
                case 0x14: /* store word alternate */
B
bellard 已提交
4666
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4667 4668 4669 4670
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
4671
#endif
4672
                    save_state(dc, cpu_cond);
4673
                    gen_st_asi(cpu_val, cpu_addr, insn, 4);
B
bellard 已提交
4674
                    break;
B
blueswir1 已提交
4675
                case 0x15: /* store byte alternate */
B
bellard 已提交
4676
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4677 4678 4679 4680
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4681
#endif
4682
                    save_state(dc, cpu_cond);
4683
                    gen_st_asi(cpu_val, cpu_addr, insn, 1);
B
bellard 已提交
4684
                    break;
B
blueswir1 已提交
4685
                case 0x16: /* store halfword alternate */
B
bellard 已提交
4686
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4687 4688 4689 4690
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
blueswir1 已提交
4691
#endif
4692
                    save_state(dc, cpu_cond);
4693
                    gen_st_asi(cpu_val, cpu_addr, insn, 2);
B
bellard 已提交
4694
                    break;
B
blueswir1 已提交
4695
                case 0x17: /* store double word alternate */
B
bellard 已提交
4696
#ifndef TARGET_SPARC64
B
blueswir1 已提交
4697 4698 4699 4700
                    if (IS_IMM)
                        goto illegal_insn;
                    if (!supervisor(dc))
                        goto priv_insn;
B
bellard 已提交
4701
#endif
B
blueswir1 已提交
4702
                    if (rd & 1)
4703
                        goto illegal_insn;
B
blueswir1 已提交
4704
                    else {
4705
                        save_state(dc, cpu_cond);
4706
                        gen_stda_asi(cpu_val, cpu_addr, insn, rd);
B
blueswir1 已提交
4707
                    }
B
bellard 已提交
4708
                    break;
B
bellard 已提交
4709
#endif
B
bellard 已提交
4710
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4711
                case 0x0e: /* V9 stx */
B
blueswir1 已提交
4712
                    gen_address_mask(dc, cpu_addr);
4713
                    tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4714 4715
                    break;
                case 0x1e: /* V9 stxa */
4716
                    save_state(dc, cpu_cond);
4717
                    gen_st_asi(cpu_val, cpu_addr, insn, 8);
B
blueswir1 已提交
4718
                    break;
B
bellard 已提交
4719
#endif
B
blueswir1 已提交
4720 4721 4722 4723
                default:
                    goto illegal_insn;
                }
            } else if (xop > 0x23 && xop < 0x28) {
4724
                if (gen_trap_ifnofpu(dc, cpu_cond))
B
bellard 已提交
4725
                    goto jmp_insn;
4726
                save_state(dc, cpu_cond);
B
blueswir1 已提交
4727
                switch (xop) {
4728
                case 0x24: /* store fpreg */
B
blueswir1 已提交
4729
                    gen_address_mask(dc, cpu_addr);
B
blueswir1 已提交
4730 4731
                    tcg_gen_ext_i32_tl(cpu_tmp0, cpu_fpr[rd]);
                    tcg_gen_qemu_st32(cpu_tmp0, cpu_addr, dc->mem_idx);
B
blueswir1 已提交
4732 4733
                    break;
                case 0x25: /* stfsr, V9 stxfsr */
4734
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4735
                    gen_address_mask(dc, cpu_addr);
4736 4737 4738
                    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 已提交
4739 4740
                    else
                        tcg_gen_qemu_st32(cpu_tmp64, cpu_addr, dc->mem_idx);
4741 4742
#else
                    tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUState, fsr));
4743
                    tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4744
#endif
B
blueswir1 已提交
4745
                    break;
B
blueswir1 已提交
4746 4747 4748
                case 0x26:
#ifdef TARGET_SPARC64
                    /* V9 stqf, store quad fpreg */
B
blueswir1 已提交
4749
                    {
P
pbrook 已提交
4750
                        TCGv_i32 r_const;
B
blueswir1 已提交
4751 4752 4753 4754

                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        gen_op_load_fpr_QT0(QFPREG(rd));
                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4755 4756
                        gen_helper_stqf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4757
                    }
B
blueswir1 已提交
4758 4759 4760 4761 4762 4763
                    break;
#else /* !TARGET_SPARC64 */
                    /* stdfq, store floating point queue */
#if defined(CONFIG_USER_ONLY)
                    goto illegal_insn;
#else
B
blueswir1 已提交
4764 4765
                    if (!supervisor(dc))
                        goto priv_insn;
4766
                    if (gen_trap_ifnofpu(dc, cpu_cond))
B
blueswir1 已提交
4767 4768
                        goto jmp_insn;
                    goto nfq_insn;
B
blueswir1 已提交
4769
#endif
B
blueswir1 已提交
4770
#endif
B
blueswir1 已提交
4771
                case 0x27: /* store double fpreg */
B
blueswir1 已提交
4772
                    {
P
pbrook 已提交
4773
                        TCGv_i32 r_const;
B
blueswir1 已提交
4774 4775 4776

                        gen_op_load_fpr_DT0(DFPREG(rd));
                        r_const = tcg_const_i32(dc->mem_idx);
P
pbrook 已提交
4777 4778
                        gen_helper_stdf(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4779
                    }
B
blueswir1 已提交
4780 4781 4782 4783 4784
                    break;
                default:
                    goto illegal_insn;
                }
            } else if (xop > 0x33 && xop < 0x3f) {
4785
                save_state(dc, cpu_cond);
B
blueswir1 已提交
4786
                switch (xop) {
4787
#ifdef TARGET_SPARC64
B
blueswir1 已提交
4788
                case 0x34: /* V9 stfa */
4789
                    gen_stf_asi(cpu_addr, insn, 4, rd);
B
blueswir1 已提交
4790
                    break;
B
blueswir1 已提交
4791
                case 0x36: /* V9 stqfa */
B
blueswir1 已提交
4792
                    {
P
pbrook 已提交
4793
                        TCGv_i32 r_const;
B
blueswir1 已提交
4794 4795 4796

                        CHECK_FPU_FEATURE(dc, FLOAT128);
                        r_const = tcg_const_i32(7);
P
pbrook 已提交
4797 4798
                        gen_helper_check_align(cpu_addr, r_const);
                        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4799 4800 4801
                        gen_op_load_fpr_QT0(QFPREG(rd));
                        gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
                    }
B
blueswir1 已提交
4802
                    break;
B
blueswir1 已提交
4803
                case 0x37: /* V9 stdfa */
4804
                    gen_op_load_fpr_DT0(DFPREG(rd));
4805
                    gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
B
blueswir1 已提交
4806 4807
                    break;
                case 0x3c: /* V9 casa */
B
blueswir1 已提交
4808
                    gen_cas_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4809
                    gen_movl_TN_reg(rd, cpu_val);
B
blueswir1 已提交
4810 4811
                    break;
                case 0x3e: /* V9 casxa */
B
blueswir1 已提交
4812
                    gen_casx_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4813
                    gen_movl_TN_reg(rd, cpu_val);
B
blueswir1 已提交
4814
                    break;
4815
#else
B
blueswir1 已提交
4816 4817 4818 4819 4820 4821 4822 4823 4824
                case 0x34: /* stc */
                case 0x35: /* stcsr */
                case 0x36: /* stdcq */
                case 0x37: /* stdc */
                    goto ncp_insn;
#endif
                default:
                    goto illegal_insn;
                }
4825
            }
B
blueswir1 已提交
4826 4827 4828 4829
            else
                goto illegal_insn;
        }
        break;
4830 4831
    }
    /* default case for non jump instructions */
B
bellard 已提交
4832
    if (dc->npc == DYNAMIC_PC) {
B
blueswir1 已提交
4833 4834
        dc->pc = DYNAMIC_PC;
        gen_op_next_insn();
B
bellard 已提交
4835 4836
    } else if (dc->npc == JUMP_PC) {
        /* we can do a static jump */
4837
        gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
B
bellard 已提交
4838 4839
        dc->is_br = 1;
    } else {
B
blueswir1 已提交
4840 4841
        dc->pc = dc->npc;
        dc->npc = dc->npc + 4;
4842
    }
B
bellard 已提交
4843
 jmp_insn:
4844 4845
    return;
 illegal_insn:
B
blueswir1 已提交
4846
    {
P
pbrook 已提交
4847
        TCGv_i32 r_const;
B
blueswir1 已提交
4848 4849 4850

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_ILL_INSN);
P
pbrook 已提交
4851 4852
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4853 4854
        dc->is_br = 1;
    }
4855
    return;
B
blueswir1 已提交
4856
 unimp_flush:
B
blueswir1 已提交
4857
    {
P
pbrook 已提交
4858
        TCGv_i32 r_const;
B
blueswir1 已提交
4859 4860 4861

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_UNIMP_FLUSH);
P
pbrook 已提交
4862 4863
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4864 4865
        dc->is_br = 1;
    }
B
blueswir1 已提交
4866
    return;
B
bellard 已提交
4867
#if !defined(CONFIG_USER_ONLY)
4868
 priv_insn:
B
blueswir1 已提交
4869
    {
P
pbrook 已提交
4870
        TCGv_i32 r_const;
B
blueswir1 已提交
4871 4872 4873

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_PRIV_INSN);
P
pbrook 已提交
4874 4875
        gen_helper_raise_exception(r_const);
        tcg_temp_free_i32(r_const);
B
blueswir1 已提交
4876 4877
        dc->is_br = 1;
    }
B
bellard 已提交
4878
    return;
B
blueswir1 已提交
4879
#endif
B
bellard 已提交
4880
 nfpu_insn:
4881
    save_state(dc, cpu_cond);
B
bellard 已提交
4882 4883
    gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
    dc->is_br = 1;
4884
    return;
B
blueswir1 已提交
4885
#if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
B
blueswir1 已提交
4886
 nfq_insn:
4887
    save_state(dc, cpu_cond);
B
blueswir1 已提交
4888 4889 4890 4891
    gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
    dc->is_br = 1;
    return;
#endif
4892 4893
#ifndef TARGET_SPARC64
 ncp_insn:
B
blueswir1 已提交
4894 4895 4896 4897 4898
    {
        TCGv r_const;

        save_state(dc, cpu_cond);
        r_const = tcg_const_i32(TT_NCP_INSN);
P
pbrook 已提交
4899
        gen_helper_raise_exception(r_const);
B
blueswir1 已提交
4900 4901 4902
        tcg_temp_free(r_const);
        dc->is_br = 1;
    }
4903 4904
    return;
#endif
4905 4906
}

4907 4908
static inline void gen_intermediate_code_internal(TranslationBlock * tb,
                                                  int spc, CPUSPARCState *env)
4909
{
B
bellard 已提交
4910
    target_ulong pc_start, last_pc;
4911 4912
    uint16_t *gen_opc_end;
    DisasContext dc1, *dc = &dc1;
4913
    CPUBreakpoint *bp;
4914
    int j, lj = -1;
P
pbrook 已提交
4915 4916
    int num_insns;
    int max_insns;
4917 4918 4919

    memset(dc, 0, sizeof(DisasContext));
    dc->tb = tb;
B
bellard 已提交
4920
    pc_start = tb->pc;
4921
    dc->pc = pc_start;
B
bellard 已提交
4922
    last_pc = dc->pc;
B
bellard 已提交
4923
    dc->npc = (target_ulong) tb->cs_base;
B
blueswir1 已提交
4924
    dc->mem_idx = cpu_mmu_index(env);
4925 4926
    dc->def = env->def;
    if ((dc->def->features & CPU_FEATURE_FLOAT))
B
blueswir1 已提交
4927
        dc->fpu_enabled = cpu_fpu_enabled(env);
4928
    else
B
blueswir1 已提交
4929
        dc->fpu_enabled = 0;
B
blueswir1 已提交
4930 4931 4932
#ifdef TARGET_SPARC64
    dc->address_mask_32bit = env->pstate & PS_AM;
#endif
4933 4934
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;

P
pbrook 已提交
4935 4936 4937
    cpu_tmp0 = tcg_temp_new();
    cpu_tmp32 = tcg_temp_new_i32();
    cpu_tmp64 = tcg_temp_new_i64();
B
blueswir1 已提交
4938

P
pbrook 已提交
4939
    cpu_dst = tcg_temp_local_new();
B
blueswir1 已提交
4940 4941

    // loads and stores
P
pbrook 已提交
4942 4943
    cpu_val = tcg_temp_local_new();
    cpu_addr = tcg_temp_local_new();
B
blueswir1 已提交
4944

P
pbrook 已提交
4945 4946 4947 4948 4949
    num_insns = 0;
    max_insns = tb->cflags & CF_COUNT_MASK;
    if (max_insns == 0)
        max_insns = CF_COUNT_MASK;
    gen_icount_start();
4950
    do {
4951 4952
        if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
            TAILQ_FOREACH(bp, &env->breakpoints, entry) {
4953
                if (bp->pc == dc->pc) {
B
blueswir1 已提交
4954
                    if (dc->pc != pc_start)
4955
                        save_state(dc, cpu_cond);
P
pbrook 已提交
4956
                    gen_helper_debug();
B
bellard 已提交
4957
                    tcg_gen_exit_tb(0);
B
blueswir1 已提交
4958
                    dc->is_br = 1;
B
bellard 已提交
4959
                    goto exit_gen_loop;
4960 4961 4962 4963
                }
            }
        }
        if (spc) {
4964
            qemu_log("Search PC...\n");
4965 4966 4967 4968 4969 4970 4971 4972
            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 已提交
4973
                gen_opc_icount[lj] = num_insns;
4974 4975
            }
        }
P
pbrook 已提交
4976 4977
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
            gen_io_start();
B
blueswir1 已提交
4978 4979
        last_pc = dc->pc;
        disas_sparc_insn(dc);
P
pbrook 已提交
4980
        num_insns++;
B
blueswir1 已提交
4981 4982 4983 4984 4985 4986

        if (dc->is_br)
            break;
        /* if the next PC is different, we abort now */
        if (dc->pc != (last_pc + 4))
            break;
B
bellard 已提交
4987 4988 4989 4990
        /* 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 已提交
4991 4992
        /* if single step mode, we generate only one instruction and
           generate an exception */
4993
        if (env->singlestep_enabled || singlestep) {
B
blueswir1 已提交
4994
            tcg_gen_movi_tl(cpu_pc, dc->pc);
B
bellard 已提交
4995
            tcg_gen_exit_tb(0);
B
bellard 已提交
4996 4997
            break;
        }
4998
    } while ((gen_opc_ptr < gen_opc_end) &&
P
pbrook 已提交
4999 5000
             (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
             num_insns < max_insns);
B
bellard 已提交
5001 5002

 exit_gen_loop:
B
blueswir1 已提交
5003
    tcg_temp_free(cpu_addr);
B
blueswir1 已提交
5004
    tcg_temp_free(cpu_val);
B
blueswir1 已提交
5005
    tcg_temp_free(cpu_dst);
P
pbrook 已提交
5006 5007
    tcg_temp_free_i64(cpu_tmp64);
    tcg_temp_free_i32(cpu_tmp32);
B
blueswir1 已提交
5008
    tcg_temp_free(cpu_tmp0);
P
pbrook 已提交
5009 5010
    if (tb->cflags & CF_LAST_IO)
        gen_io_end();
B
bellard 已提交
5011
    if (!dc->is_br) {
5012
        if (dc->pc != DYNAMIC_PC &&
B
bellard 已提交
5013 5014
            (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
            /* static PC and NPC: we can use direct chaining */
B
blueswir1 已提交
5015
            gen_goto_tb(dc, 0, dc->pc, dc->npc);
B
bellard 已提交
5016 5017
        } else {
            if (dc->pc != DYNAMIC_PC)
B
blueswir1 已提交
5018
                tcg_gen_movi_tl(cpu_pc, dc->pc);
5019
            save_npc(dc, cpu_cond);
B
bellard 已提交
5020
            tcg_gen_exit_tb(0);
B
bellard 已提交
5021 5022
        }
    }
P
pbrook 已提交
5023
    gen_icount_end(tb, num_insns);
5024
    *gen_opc_ptr = INDEX_op_end;
5025 5026 5027 5028 5029 5030
    if (spc) {
        j = gen_opc_ptr - gen_opc_buf;
        lj++;
        while (lj <= j)
            gen_opc_instr_start[lj++] = 0;
#if 0
5031
        log_page_dump();
5032
#endif
5033 5034
        gen_opc_jump_pc[0] = dc->jump_pc[0];
        gen_opc_jump_pc[1] = dc->jump_pc[1];
5035
    } else {
B
bellard 已提交
5036
        tb->size = last_pc + 4 - pc_start;
P
pbrook 已提交
5037
        tb->icount = num_insns;
5038
    }
5039
#ifdef DEBUG_DISAS
5040
    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
5041 5042 5043 5044
        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");
5045
    }
5046 5047 5048
#endif
}

5049
void gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
5050
{
5051
    gen_intermediate_code_internal(tb, 0, env);
5052 5053
}

5054
void gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
5055
{
5056
    gen_intermediate_code_internal(tb, 1, env);
5057 5058
}

5059
void gen_intermediate_code_init(CPUSPARCState *env)
B
bellard 已提交
5060
{
B
blueswir1 已提交
5061
    unsigned int i;
5062
    static int inited;
B
blueswir1 已提交
5063 5064 5065 5066 5067 5068 5069 5070 5071 5072
    static const char * const gregnames[8] = {
        NULL, // g0 not used
        "g1",
        "g2",
        "g3",
        "g4",
        "g5",
        "g6",
        "g7",
    };
B
blueswir1 已提交
5073 5074 5075 5076 5077 5078 5079 5080 5081 5082
    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 已提交
5083

B
blueswir1 已提交
5084 5085 5086 5087
    /* init various static tables */
    if (!inited) {
        inited = 1;

P
pbrook 已提交
5088 5089 5090 5091
        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 已提交
5092
#ifdef TARGET_SPARC64
P
pbrook 已提交
5093 5094 5095 5096 5097 5098 5099
        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),
5100
                                     "gsr");
P
pbrook 已提交
5101
        cpu_tick_cmpr = tcg_global_mem_new(TCG_AREG0,
5102 5103
                                           offsetof(CPUState, tick_cmpr),
                                           "tick_cmpr");
P
pbrook 已提交
5104
        cpu_stick_cmpr = tcg_global_mem_new(TCG_AREG0,
5105 5106
                                            offsetof(CPUState, stick_cmpr),
                                            "stick_cmpr");
P
pbrook 已提交
5107
        cpu_hstick_cmpr = tcg_global_mem_new(TCG_AREG0,
5108 5109
                                             offsetof(CPUState, hstick_cmpr),
                                             "hstick_cmpr");
P
pbrook 已提交
5110
        cpu_hintp = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, hintp),
5111
                                       "hintp");
P
pbrook 已提交
5112 5113 5114 5115 5116
        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,
5117
                                     offsetof(CPUState, ssr), "ssr");
P
pbrook 已提交
5118
        cpu_ver = tcg_global_mem_new(TCG_AREG0,
5119
                                     offsetof(CPUState, version), "ver");
P
pbrook 已提交
5120 5121 5122
        cpu_softint = tcg_global_mem_new_i32(TCG_AREG0,
                                             offsetof(CPUState, softint),
                                             "softint");
5123
#else
P
pbrook 已提交
5124
        cpu_wim = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, wim),
5125
                                     "wim");
B
blueswir1 已提交
5126
#endif
P
pbrook 已提交
5127
        cpu_cond = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cond),
B
blueswir1 已提交
5128
                                      "cond");
P
pbrook 已提交
5129
        cpu_cc_src = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cc_src),
5130
                                        "cc_src");
P
pbrook 已提交
5131
        cpu_cc_src2 = tcg_global_mem_new(TCG_AREG0,
B
blueswir1 已提交
5132 5133
                                         offsetof(CPUState, cc_src2),
                                         "cc_src2");
P
pbrook 已提交
5134
        cpu_cc_dst = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cc_dst),
5135
                                        "cc_dst");
P
pbrook 已提交
5136 5137 5138
        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 已提交
5139
                                     "fsr");
P
pbrook 已提交
5140
        cpu_pc = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, pc),
B
blueswir1 已提交
5141
                                    "pc");
P
pbrook 已提交
5142 5143 5144
        cpu_npc = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, npc),
                                     "npc");
        cpu_y = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, y), "y");
5145
#ifndef CONFIG_USER_ONLY
P
pbrook 已提交
5146
        cpu_tbr = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, tbr),
5147 5148
                                     "tbr");
#endif
B
blueswir1 已提交
5149
        for (i = 1; i < 8; i++)
P
pbrook 已提交
5150
            cpu_gregs[i] = tcg_global_mem_new(TCG_AREG0,
B
blueswir1 已提交
5151 5152
                                              offsetof(CPUState, gregs[i]),
                                              gregnames[i]);
B
blueswir1 已提交
5153
        for (i = 0; i < TARGET_FPREGS; i++)
P
pbrook 已提交
5154 5155 5156
            cpu_fpr[i] = tcg_global_mem_new_i32(TCG_AREG0,
                                                offsetof(CPUState, fpr[i]),
                                                fregnames[i]);
B
blueswir1 已提交
5157

B
blueswir1 已提交
5158 5159
        /* register helpers */

P
pbrook 已提交
5160
#define GEN_HELPER 2
B
blueswir1 已提交
5161
#include "helper.h"
B
blueswir1 已提交
5162
    }
B
bellard 已提交
5163
}
A
aurel32 已提交
5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183

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