]> Git Repo - qemu.git/blame - target-sparc/translate.c
Fix potential condition code problems
[qemu.git] / target-sparc / translate.c
CommitLineData
7a3f1944
FB
1/*
2 SPARC translation
3
4 Copyright (C) 2003 Thomas M. Ogrisegg <[email protected]>
3475187d 5 Copyright (C) 2003-2005 Fabrice Bellard
7a3f1944
FB
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/*
7a3f1944
FB
23 TODO-list:
24
3475187d 25 Rest of V9 instructions, VIS instructions
bd497938 26 NPC/PC static optimisations (use JUMP_TB when possible)
7a3f1944 27 Optimize synthetic instructions
bd497938 28*/
7a3f1944
FB
29
30#include <stdarg.h>
31#include <stdlib.h>
32#include <stdio.h>
33#include <string.h>
34#include <inttypes.h>
35
36#include "cpu.h"
37#include "exec-all.h"
38#include "disas.h"
1a2fb1c0 39#include "helper.h"
57fec1fe 40#include "tcg-op.h"
7a3f1944
FB
41
42#define DEBUG_DISAS
43
72cbca10
FB
44#define DYNAMIC_PC 1 /* dynamic pc value */
45#define JUMP_PC 2 /* dynamic pc value which takes only two values
46 according to jump_pc[T2] */
47
1a2fb1c0 48/* global register indexes */
d9bdab86 49static TCGv cpu_env, cpu_T[3], cpu_regwptr, cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
48d5c82b 50static TCGv cpu_psr, cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8];
6ae20372 51static TCGv cpu_cond, cpu_src1, cpu_src2, cpu_dst, cpu_addr, cpu_val;
dc99a3f2
BS
52#ifdef TARGET_SPARC64
53static TCGv cpu_xcc;
54#endif
1a2fb1c0 55/* local register indexes (only used inside old micro ops) */
8911f501 56static TCGv cpu_tmp0, cpu_tmp32, cpu_tmp64;
1a2fb1c0 57
7a3f1944 58typedef struct DisasContext {
0f8a249a
BS
59 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
60 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
72cbca10 61 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
cf495bcf 62 int is_br;
e8af50a3 63 int mem_idx;
a80dde08 64 int fpu_enabled;
cf495bcf 65 struct TranslationBlock *tb;
7a3f1944
FB
66} DisasContext;
67
7a3f1944
FB
68extern FILE *logfile;
69extern int loglevel;
70
3475187d 71// This function uses non-native bit order
7a3f1944
FB
72#define GET_FIELD(X, FROM, TO) \
73 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
74
3475187d
FB
75// This function uses the order in the manuals, i.e. bit 0 is 2^0
76#define GET_FIELD_SP(X, FROM, TO) \
77 GET_FIELD(X, 31 - (TO), 31 - (FROM))
78
79#define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
46d38ba8 80#define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
3475187d
FB
81
82#ifdef TARGET_SPARC64
19f329ad 83#define FFPREG(r) (r)
0387d928 84#define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
1f587329 85#define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
3475187d 86#else
19f329ad 87#define FFPREG(r) (r)
c185970a 88#define DFPREG(r) (r & 0x1e)
1f587329 89#define QFPREG(r) (r & 0x1c)
3475187d
FB
90#endif
91
92static int sign_extend(int x, int len)
93{
94 len = 32 - len;
95 return (x << len) >> len;
96}
97
7a3f1944
FB
98#define IS_IMM (insn & (1<<13))
99
ff07ec83
BS
100/* floating point registers moves */
101static void gen_op_load_fpr_FT0(unsigned int src)
102{
8911f501
BS
103 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
104 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
3475187d 105}
ff07ec83
BS
106
107static void gen_op_load_fpr_FT1(unsigned int src)
108{
8911f501
BS
109 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
110 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
e8af50a3
FB
111}
112
ff07ec83
BS
113static void gen_op_store_FT0_fpr(unsigned int dst)
114{
8911f501
BS
115 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
116 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
ff07ec83
BS
117}
118
119static void gen_op_load_fpr_DT0(unsigned int src)
120{
8911f501
BS
121 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
122 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper));
123 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
124 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower));
ff07ec83
BS
125}
126
127static void gen_op_load_fpr_DT1(unsigned int src)
128{
8911f501
BS
129 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
130 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.upper));
131 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
132 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.lower));
ff07ec83
BS
133}
134
135static void gen_op_store_DT0_fpr(unsigned int dst)
136{
8911f501
BS
137 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper));
138 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
139 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower));
140 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
ff07ec83
BS
141}
142
143#ifdef CONFIG_USER_ONLY
144static void gen_op_load_fpr_QT0(unsigned int src)
145{
8911f501
BS
146 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
147 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upmost));
148 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
149 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper));
150 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
151 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower));
152 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
153 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest));
ff07ec83
BS
154}
155
156static void gen_op_load_fpr_QT1(unsigned int src)
157{
8911f501
BS
158 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
159 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upmost));
160 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
161 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upper));
162 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
163 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.lower));
164 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
165 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.lowest));
ff07ec83
BS
166}
167
168static void gen_op_store_QT0_fpr(unsigned int dst)
169{
8911f501
BS
170 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upmost));
171 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
172 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper));
173 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
174 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower));
175 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
176 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest));
177 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
ff07ec83 178}
1f587329
BS
179#endif
180
81ad8ba2
BS
181/* moves */
182#ifdef CONFIG_USER_ONLY
3475187d 183#define supervisor(dc) 0
81ad8ba2 184#ifdef TARGET_SPARC64
e9ebed4d 185#define hypervisor(dc) 0
81ad8ba2 186#endif
3475187d 187#else
6f27aba6 188#define supervisor(dc) (dc->mem_idx >= 1)
81ad8ba2
BS
189#ifdef TARGET_SPARC64
190#define hypervisor(dc) (dc->mem_idx == 2)
6f27aba6 191#else
3475187d 192#endif
81ad8ba2
BS
193#endif
194
1a2fb1c0 195#ifdef TARGET_ABI32
8911f501 196#define ABI32_MASK(addr) tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
1a2fb1c0
BS
197#else
198#define ABI32_MASK(addr)
199#endif
3391c818 200
1a2fb1c0 201static inline void gen_movl_reg_TN(int reg, TCGv tn)
81ad8ba2 202{
1a2fb1c0
BS
203 if (reg == 0)
204 tcg_gen_movi_tl(tn, 0);
205 else if (reg < 8)
f5069b26 206 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
1a2fb1c0 207 else {
1a2fb1c0 208 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
81ad8ba2
BS
209 }
210}
211
1a2fb1c0 212static inline void gen_movl_TN_reg(int reg, TCGv tn)
81ad8ba2 213{
1a2fb1c0
BS
214 if (reg == 0)
215 return;
216 else if (reg < 8)
f5069b26 217 tcg_gen_mov_tl(cpu_gregs[reg], tn);
1a2fb1c0 218 else {
1a2fb1c0 219 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
81ad8ba2
BS
220 }
221}
222
5fafdf24 223static inline void gen_goto_tb(DisasContext *s, int tb_num,
6e256c93
FB
224 target_ulong pc, target_ulong npc)
225{
226 TranslationBlock *tb;
227
228 tb = s->tb;
229 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
230 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
231 /* jump to same page: we can use a direct jump */
57fec1fe 232 tcg_gen_goto_tb(tb_num);
2f5680ee
BS
233 tcg_gen_movi_tl(cpu_pc, pc);
234 tcg_gen_movi_tl(cpu_npc, npc);
57fec1fe 235 tcg_gen_exit_tb((long)tb + tb_num);
6e256c93
FB
236 } else {
237 /* jump to another page: currently not optimized */
2f5680ee
BS
238 tcg_gen_movi_tl(cpu_pc, pc);
239 tcg_gen_movi_tl(cpu_npc, npc);
57fec1fe 240 tcg_gen_exit_tb(0);
6e256c93
FB
241 }
242}
243
19f329ad
BS
244// XXX suboptimal
245static inline void gen_mov_reg_N(TCGv reg, TCGv src)
246{
8911f501 247 tcg_gen_extu_i32_tl(reg, src);
4b8b8b76 248 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
19f329ad
BS
249 tcg_gen_andi_tl(reg, reg, 0x1);
250}
251
252static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
253{
8911f501 254 tcg_gen_extu_i32_tl(reg, src);
4b8b8b76 255 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
19f329ad
BS
256 tcg_gen_andi_tl(reg, reg, 0x1);
257}
258
259static inline void gen_mov_reg_V(TCGv reg, TCGv src)
260{
8911f501 261 tcg_gen_extu_i32_tl(reg, src);
4b8b8b76 262 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
19f329ad
BS
263 tcg_gen_andi_tl(reg, reg, 0x1);
264}
265
266static inline void gen_mov_reg_C(TCGv reg, TCGv src)
267{
8911f501 268 tcg_gen_extu_i32_tl(reg, src);
4b8b8b76 269 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
19f329ad
BS
270 tcg_gen_andi_tl(reg, reg, 0x1);
271}
272
ce5b3c3d 273static inline void gen_cc_clear_icc(void)
dc99a3f2
BS
274{
275 tcg_gen_movi_i32(cpu_psr, 0);
ce5b3c3d
BS
276}
277
dc99a3f2 278#ifdef TARGET_SPARC64
ce5b3c3d
BS
279static inline void gen_cc_clear_xcc(void)
280{
dc99a3f2 281 tcg_gen_movi_i32(cpu_xcc, 0);
dc99a3f2 282}
ce5b3c3d 283#endif
dc99a3f2
BS
284
285/* old op:
286 if (!T0)
287 env->psr |= PSR_ZERO;
288 if ((int32_t) T0 < 0)
289 env->psr |= PSR_NEG;
290*/
ce5b3c3d 291static inline void gen_cc_NZ_icc(TCGv dst)
dc99a3f2 292{
8911f501 293 TCGv r_temp;
dc99a3f2 294 int l1, l2;
dc99a3f2
BS
295
296 l1 = gen_new_label();
297 l2 = gen_new_label();
8911f501
BS
298 r_temp = tcg_temp_new(TCG_TYPE_TL);
299 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
300 tcg_gen_brcond_tl(TCG_COND_NE, r_temp, tcg_const_tl(0), l1);
dc99a3f2
BS
301 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
302 gen_set_label(l1);
bdf46ea2 303 tcg_gen_ext_i32_tl(r_temp, dst);
8911f501 304 tcg_gen_brcond_tl(TCG_COND_GE, r_temp, tcg_const_tl(0), l2);
dc99a3f2
BS
305 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
306 gen_set_label(l2);
ce5b3c3d
BS
307}
308
dc99a3f2 309#ifdef TARGET_SPARC64
ce5b3c3d
BS
310static inline void gen_cc_NZ_xcc(TCGv dst)
311{
312 int l1, l2;
313
314 l1 = gen_new_label();
315 l2 = gen_new_label();
316 tcg_gen_brcond_tl(TCG_COND_NE, dst, tcg_const_tl(0), l1);
317 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
318 gen_set_label(l1);
319 tcg_gen_brcond_tl(TCG_COND_GE, dst, tcg_const_tl(0), l2);
320 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
321 gen_set_label(l2);
dc99a3f2 322}
ce5b3c3d 323#endif
dc99a3f2
BS
324
325/* old op:
326 if (T0 < src1)
327 env->psr |= PSR_CARRY;
328*/
ce5b3c3d 329static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
dc99a3f2 330{
8911f501 331 TCGv r_temp;
dc99a3f2
BS
332 int l1;
333
334 l1 = gen_new_label();
8911f501
BS
335 r_temp = tcg_temp_new(TCG_TYPE_TL);
336 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
337 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
dc99a3f2
BS
338 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
339 gen_set_label(l1);
ce5b3c3d
BS
340}
341
dc99a3f2 342#ifdef TARGET_SPARC64
ce5b3c3d
BS
343static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
344{
345 int l1;
dc99a3f2 346
ce5b3c3d
BS
347 l1 = gen_new_label();
348 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
349 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
350 gen_set_label(l1);
dc99a3f2 351}
ce5b3c3d 352#endif
dc99a3f2
BS
353
354/* old op:
355 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
356 env->psr |= PSR_OVF;
357*/
ce5b3c3d 358static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 359{
0425bee5 360 TCGv r_temp;
dc99a3f2
BS
361
362 r_temp = tcg_temp_new(TCG_TYPE_TL);
dc99a3f2
BS
363 tcg_gen_xor_tl(r_temp, src1, src2);
364 tcg_gen_xori_tl(r_temp, r_temp, -1);
0425bee5
BS
365 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
366 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
367 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
653ccb80
BS
368 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
369 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
370 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
ce5b3c3d
BS
371}
372
dc99a3f2 373#ifdef TARGET_SPARC64
ce5b3c3d
BS
374static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
375{
376 TCGv r_temp;
ce5b3c3d
BS
377
378 r_temp = tcg_temp_new(TCG_TYPE_TL);
379 tcg_gen_xor_tl(r_temp, src1, src2);
380 tcg_gen_xori_tl(r_temp, r_temp, -1);
381 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
382 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
383 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
653ccb80
BS
384 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
385 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
386 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
dc99a3f2 387}
ce5b3c3d 388#endif
dc99a3f2
BS
389
390static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
391{
0425bee5 392 TCGv r_temp;
dc99a3f2
BS
393 int l1;
394
395 l1 = gen_new_label();
396
397 r_temp = tcg_temp_new(TCG_TYPE_TL);
dc99a3f2
BS
398 tcg_gen_xor_tl(r_temp, src1, src2);
399 tcg_gen_xori_tl(r_temp, r_temp, -1);
0425bee5
BS
400 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
401 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
402 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
8911f501 403 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
2f5680ee 404 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
dc99a3f2 405 gen_set_label(l1);
dc99a3f2
BS
406}
407
408static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
409{
410 int l1;
dc99a3f2
BS
411
412 l1 = gen_new_label();
0425bee5
BS
413 tcg_gen_or_tl(cpu_tmp0, src1, src2);
414 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
415 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
dc99a3f2
BS
416 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
417 gen_set_label(l1);
418}
419
420static inline void gen_tag_tv(TCGv src1, TCGv src2)
421{
422 int l1;
dc99a3f2
BS
423
424 l1 = gen_new_label();
0425bee5
BS
425 tcg_gen_or_tl(cpu_tmp0, src1, src2);
426 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
427 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
2f5680ee 428 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
dc99a3f2
BS
429 gen_set_label(l1);
430}
431
4af984a7 432static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 433{
4af984a7 434 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262 435 tcg_gen_mov_tl(cpu_cc_src2, src2);
4af984a7 436 tcg_gen_add_tl(dst, src1, src2);
ba28189b 437 tcg_gen_mov_tl(cpu_cc_dst, dst);
ce5b3c3d 438 gen_cc_clear_icc();
ba28189b
BS
439 gen_cc_NZ_icc(cpu_cc_dst);
440 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
441 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d
BS
442#ifdef TARGET_SPARC64
443 gen_cc_clear_xcc();
ba28189b
BS
444 gen_cc_NZ_xcc(cpu_cc_dst);
445 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
446 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 447#endif
dc99a3f2
BS
448}
449
4af984a7 450static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 451{
4af984a7 452 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262 453 tcg_gen_mov_tl(cpu_cc_src2, src2);
dc99a3f2 454 gen_mov_reg_C(cpu_tmp0, cpu_psr);
4af984a7 455 tcg_gen_add_tl(dst, src1, cpu_tmp0);
ce5b3c3d 456 gen_cc_clear_icc();
4af984a7 457 gen_cc_C_add_icc(dst, cpu_cc_src);
ce5b3c3d
BS
458#ifdef TARGET_SPARC64
459 gen_cc_clear_xcc();
4af984a7 460 gen_cc_C_add_xcc(dst, cpu_cc_src);
ce5b3c3d 461#endif
6f551262 462 tcg_gen_add_tl(dst, dst, cpu_cc_src2);
ba28189b
BS
463 tcg_gen_mov_tl(cpu_cc_dst, dst);
464 gen_cc_NZ_icc(cpu_cc_dst);
465 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
466 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 467#ifdef TARGET_SPARC64
ba28189b
BS
468 gen_cc_NZ_xcc(cpu_cc_dst);
469 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
470 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 471#endif
dc99a3f2
BS
472}
473
4af984a7 474static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 475{
4af984a7 476 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262 477 tcg_gen_mov_tl(cpu_cc_src2, src2);
4af984a7 478 tcg_gen_add_tl(dst, src1, src2);
ba28189b 479 tcg_gen_mov_tl(cpu_cc_dst, dst);
ce5b3c3d 480 gen_cc_clear_icc();
ba28189b
BS
481 gen_cc_NZ_icc(cpu_cc_dst);
482 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
483 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
6f551262 484 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
ce5b3c3d
BS
485#ifdef TARGET_SPARC64
486 gen_cc_clear_xcc();
ba28189b
BS
487 gen_cc_NZ_xcc(cpu_cc_dst);
488 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
489 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 490#endif
dc99a3f2
BS
491}
492
4af984a7 493static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 494{
4af984a7 495 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262
BS
496 tcg_gen_mov_tl(cpu_cc_src2, src2);
497 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
4af984a7 498 tcg_gen_add_tl(dst, src1, src2);
ba28189b 499 tcg_gen_mov_tl(cpu_cc_dst, dst);
6f551262 500 gen_add_tv(dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 501 gen_cc_clear_icc();
ba28189b
BS
502 gen_cc_NZ_icc(cpu_cc_dst);
503 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
ce5b3c3d
BS
504#ifdef TARGET_SPARC64
505 gen_cc_clear_xcc();
ba28189b
BS
506 gen_cc_NZ_xcc(cpu_cc_dst);
507 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
508 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 509#endif
dc99a3f2
BS
510}
511
512/* old op:
513 if (src1 < T1)
514 env->psr |= PSR_CARRY;
515*/
ce5b3c3d 516static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
dc99a3f2 517{
8911f501 518 TCGv r_temp1, r_temp2;
dc99a3f2
BS
519 int l1;
520
521 l1 = gen_new_label();
8911f501
BS
522 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
523 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
524 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
525 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
526 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
dc99a3f2
BS
527 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
528 gen_set_label(l1);
ce5b3c3d
BS
529}
530
dc99a3f2 531#ifdef TARGET_SPARC64
ce5b3c3d
BS
532static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
533{
534 int l1;
dc99a3f2 535
ce5b3c3d
BS
536 l1 = gen_new_label();
537 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
538 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
539 gen_set_label(l1);
dc99a3f2 540}
ce5b3c3d 541#endif
dc99a3f2
BS
542
543/* old op:
544 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
545 env->psr |= PSR_OVF;
546*/
ce5b3c3d 547static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 548{
0425bee5 549 TCGv r_temp;
dc99a3f2
BS
550
551 r_temp = tcg_temp_new(TCG_TYPE_TL);
dc99a3f2 552 tcg_gen_xor_tl(r_temp, src1, src2);
0425bee5
BS
553 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
554 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
555 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
653ccb80
BS
556 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
557 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
558 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
ce5b3c3d
BS
559}
560
dc99a3f2 561#ifdef TARGET_SPARC64
ce5b3c3d
BS
562static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
563{
564 TCGv r_temp;
ce5b3c3d
BS
565
566 r_temp = tcg_temp_new(TCG_TYPE_TL);
567 tcg_gen_xor_tl(r_temp, src1, src2);
568 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
569 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
570 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
653ccb80
BS
571 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
572 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
573 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
dc99a3f2 574}
ce5b3c3d 575#endif
dc99a3f2
BS
576
577static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
578{
0425bee5 579 TCGv r_temp;
dc99a3f2
BS
580 int l1;
581
582 l1 = gen_new_label();
583
584 r_temp = tcg_temp_new(TCG_TYPE_TL);
dc99a3f2 585 tcg_gen_xor_tl(r_temp, src1, src2);
0425bee5
BS
586 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
587 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
588 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
8911f501 589 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
2f5680ee 590 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
dc99a3f2 591 gen_set_label(l1);
dc99a3f2
BS
592}
593
4af984a7 594static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 595{
4af984a7 596 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262 597 tcg_gen_mov_tl(cpu_cc_src2, src2);
4af984a7 598 tcg_gen_sub_tl(dst, src1, src2);
ba28189b 599 tcg_gen_mov_tl(cpu_cc_dst, dst);
ce5b3c3d 600 gen_cc_clear_icc();
ba28189b 601 gen_cc_NZ_icc(cpu_cc_dst);
6f551262 602 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
ba28189b 603 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d
BS
604#ifdef TARGET_SPARC64
605 gen_cc_clear_xcc();
ba28189b 606 gen_cc_NZ_xcc(cpu_cc_dst);
6f551262 607 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
ba28189b 608 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 609#endif
dc99a3f2
BS
610}
611
4af984a7 612static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 613{
4af984a7 614 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262 615 tcg_gen_mov_tl(cpu_cc_src2, src2);
dc99a3f2 616 gen_mov_reg_C(cpu_tmp0, cpu_psr);
4af984a7 617 tcg_gen_sub_tl(dst, src1, cpu_tmp0);
ce5b3c3d 618 gen_cc_clear_icc();
4af984a7 619 gen_cc_C_sub_icc(dst, cpu_cc_src);
ce5b3c3d
BS
620#ifdef TARGET_SPARC64
621 gen_cc_clear_xcc();
4af984a7 622 gen_cc_C_sub_xcc(dst, cpu_cc_src);
ce5b3c3d 623#endif
6f551262 624 tcg_gen_sub_tl(dst, dst, cpu_cc_src2);
ba28189b
BS
625 tcg_gen_mov_tl(cpu_cc_dst, dst);
626 gen_cc_NZ_icc(cpu_cc_dst);
627 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
628 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 629#ifdef TARGET_SPARC64
ba28189b
BS
630 gen_cc_NZ_xcc(cpu_cc_dst);
631 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
632 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 633#endif
dc99a3f2
BS
634}
635
4af984a7 636static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 637{
4af984a7 638 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262 639 tcg_gen_mov_tl(cpu_cc_src2, src2);
4af984a7 640 tcg_gen_sub_tl(dst, src1, src2);
ba28189b 641 tcg_gen_mov_tl(cpu_cc_dst, dst);
ce5b3c3d 642 gen_cc_clear_icc();
ba28189b 643 gen_cc_NZ_icc(cpu_cc_dst);
6f551262 644 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
ba28189b 645 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
6f551262 646 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
ce5b3c3d
BS
647#ifdef TARGET_SPARC64
648 gen_cc_clear_xcc();
ba28189b 649 gen_cc_NZ_xcc(cpu_cc_dst);
6f551262 650 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
ba28189b 651 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 652#endif
dc99a3f2
BS
653}
654
4af984a7 655static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
dc99a3f2 656{
4af984a7 657 tcg_gen_mov_tl(cpu_cc_src, src1);
6f551262
BS
658 tcg_gen_mov_tl(cpu_cc_src2, src2);
659 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
4af984a7 660 tcg_gen_sub_tl(dst, src1, src2);
ba28189b 661 tcg_gen_mov_tl(cpu_cc_dst, dst);
6f551262 662 gen_sub_tv(dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 663 gen_cc_clear_icc();
ba28189b 664 gen_cc_NZ_icc(cpu_cc_dst);
6f551262 665 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
ce5b3c3d
BS
666#ifdef TARGET_SPARC64
667 gen_cc_clear_xcc();
ba28189b 668 gen_cc_NZ_xcc(cpu_cc_dst);
6f551262 669 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
ba28189b 670 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
ce5b3c3d 671#endif
dc99a3f2
BS
672}
673
4af984a7 674static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
d9bdab86 675{
7127fe84 676 TCGv r_temp, r_temp2;
6f551262 677 int l1;
d9bdab86
BS
678
679 l1 = gen_new_label();
d9bdab86 680 r_temp = tcg_temp_new(TCG_TYPE_TL);
7127fe84 681 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
d9bdab86
BS
682
683 /* old op:
684 if (!(env->y & 1))
685 T1 = 0;
686 */
6f551262 687 tcg_gen_mov_tl(cpu_cc_src, src1);
7127fe84
BS
688 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
689 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
690 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
4af984a7 691 tcg_gen_mov_tl(cpu_cc_src2, src2);
6f551262 692 tcg_gen_brcond_i32(TCG_COND_NE, r_temp2, tcg_const_i32(0), l1);
d9bdab86 693 tcg_gen_movi_tl(cpu_cc_src2, 0);
6f551262 694 gen_set_label(l1);
d9bdab86
BS
695
696 // b2 = T0 & 1;
697 // env->y = (b2 << 31) | (env->y >> 1);
6f551262 698 tcg_gen_trunc_tl_i32(r_temp2, cpu_cc_src);
7127fe84
BS
699 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
700 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
8911f501
BS
701 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
702 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
7127fe84 703 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
8911f501 704 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
d9bdab86
BS
705
706 // b1 = N ^ V;
707 gen_mov_reg_N(cpu_tmp0, cpu_psr);
708 gen_mov_reg_V(r_temp, cpu_psr);
709 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
710
711 // T0 = (b1 << 31) | (T0 >> 1);
712 // src1 = T0;
713 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
6f551262 714 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
d9bdab86
BS
715 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
716
717 /* do addition and update flags */
4af984a7 718 tcg_gen_add_tl(dst, cpu_cc_src, cpu_cc_src2);
ba28189b 719 tcg_gen_mov_tl(cpu_cc_dst, dst);
d9bdab86 720
ce5b3c3d 721 gen_cc_clear_icc();
ba28189b
BS
722 gen_cc_NZ_icc(cpu_cc_dst);
723 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
724 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
d9bdab86
BS
725}
726
4af984a7 727static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
8879d139
BS
728{
729 TCGv r_temp, r_temp2;
730
731 r_temp = tcg_temp_new(TCG_TYPE_I64);
732 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
733
4af984a7
BS
734 tcg_gen_extu_tl_i64(r_temp, src2);
735 tcg_gen_extu_tl_i64(r_temp2, src1);
8879d139
BS
736 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
737
738 tcg_gen_shri_i64(r_temp, r_temp2, 32);
739 tcg_gen_trunc_i64_i32(r_temp, r_temp);
740 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
741#ifdef TARGET_SPARC64
4af984a7 742 tcg_gen_mov_i64(dst, r_temp2);
8879d139 743#else
4af984a7 744 tcg_gen_trunc_i64_tl(dst, r_temp2);
8879d139 745#endif
8879d139
BS
746}
747
4af984a7 748static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
8879d139
BS
749{
750 TCGv r_temp, r_temp2;
751
752 r_temp = tcg_temp_new(TCG_TYPE_I64);
753 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
754
4af984a7
BS
755 tcg_gen_ext_tl_i64(r_temp, src2);
756 tcg_gen_ext_tl_i64(r_temp2, src1);
8879d139
BS
757 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
758
759 tcg_gen_shri_i64(r_temp, r_temp2, 32);
760 tcg_gen_trunc_i64_i32(r_temp, r_temp);
761 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
762#ifdef TARGET_SPARC64
4af984a7 763 tcg_gen_mov_i64(dst, r_temp2);
8879d139 764#else
4af984a7 765 tcg_gen_trunc_i64_tl(dst, r_temp2);
8879d139 766#endif
8879d139
BS
767}
768
1a7b60e7 769#ifdef TARGET_SPARC64
8911f501 770static inline void gen_trap_ifdivzero_tl(TCGv divisor)
1a7b60e7
BS
771{
772 int l1;
773
774 l1 = gen_new_label();
8911f501 775 tcg_gen_brcond_tl(TCG_COND_NE, divisor, tcg_const_tl(0), l1);
2f5680ee 776 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_DIV_ZERO));
1a7b60e7
BS
777 gen_set_label(l1);
778}
779
4af984a7 780static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
1a7b60e7
BS
781{
782 int l1, l2;
783
784 l1 = gen_new_label();
785 l2 = gen_new_label();
6f551262
BS
786 tcg_gen_mov_tl(cpu_cc_src, src1);
787 tcg_gen_mov_tl(cpu_cc_src2, src2);
4af984a7 788 gen_trap_ifdivzero_tl(src2);
6f551262
BS
789 tcg_gen_brcond_tl(TCG_COND_NE, cpu_cc_src, tcg_const_tl(INT64_MIN), l1);
790 tcg_gen_brcond_tl(TCG_COND_NE, cpu_cc_src2, tcg_const_tl(-1), l1);
4af984a7 791 tcg_gen_movi_i64(dst, INT64_MIN);
06b3e1b3 792 tcg_gen_br(l2);
1a7b60e7 793 gen_set_label(l1);
6f551262 794 tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
1a7b60e7
BS
795 gen_set_label(l2);
796}
797#endif
798
4af984a7 799static inline void gen_op_div_cc(TCGv dst)
dc99a3f2
BS
800{
801 int l1;
dc99a3f2 802
ba28189b 803 tcg_gen_mov_tl(cpu_cc_dst, dst);
ce5b3c3d 804 gen_cc_clear_icc();
ba28189b 805 gen_cc_NZ_icc(cpu_cc_dst);
dc99a3f2 806 l1 = gen_new_label();
3b89f26c
BS
807 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, cc_src2));
808 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
dc99a3f2
BS
809 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
810 gen_set_label(l1);
811}
812
4af984a7 813static inline void gen_op_logic_cc(TCGv dst)
dc99a3f2 814{
ba28189b
BS
815 tcg_gen_mov_tl(cpu_cc_dst, dst);
816
ce5b3c3d 817 gen_cc_clear_icc();
ba28189b 818 gen_cc_NZ_icc(cpu_cc_dst);
ce5b3c3d
BS
819#ifdef TARGET_SPARC64
820 gen_cc_clear_xcc();
ba28189b 821 gen_cc_NZ_xcc(cpu_cc_dst);
ce5b3c3d 822#endif
dc99a3f2
BS
823}
824
19f329ad
BS
825// 1
826static inline void gen_op_eval_ba(TCGv dst)
827{
828 tcg_gen_movi_tl(dst, 1);
829}
830
831// Z
832static inline void gen_op_eval_be(TCGv dst, TCGv src)
833{
834 gen_mov_reg_Z(dst, src);
835}
836
837// Z | (N ^ V)
838static inline void gen_op_eval_ble(TCGv dst, TCGv src)
839{
0425bee5 840 gen_mov_reg_N(cpu_tmp0, src);
19f329ad 841 gen_mov_reg_V(dst, src);
0425bee5
BS
842 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
843 gen_mov_reg_Z(cpu_tmp0, src);
844 tcg_gen_or_tl(dst, dst, cpu_tmp0);
19f329ad
BS
845}
846
847// N ^ V
848static inline void gen_op_eval_bl(TCGv dst, TCGv src)
849{
0425bee5 850 gen_mov_reg_V(cpu_tmp0, src);
19f329ad 851 gen_mov_reg_N(dst, src);
0425bee5 852 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
19f329ad
BS
853}
854
855// C | Z
856static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
857{
0425bee5 858 gen_mov_reg_Z(cpu_tmp0, src);
19f329ad 859 gen_mov_reg_C(dst, src);
0425bee5 860 tcg_gen_or_tl(dst, dst, cpu_tmp0);
19f329ad
BS
861}
862
863// C
864static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
865{
866 gen_mov_reg_C(dst, src);
867}
868
869// V
870static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
871{
872 gen_mov_reg_V(dst, src);
873}
874
875// 0
876static inline void gen_op_eval_bn(TCGv dst)
877{
878 tcg_gen_movi_tl(dst, 0);
879}
880
881// N
882static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
883{
884 gen_mov_reg_N(dst, src);
885}
886
887// !Z
888static inline void gen_op_eval_bne(TCGv dst, TCGv src)
889{
890 gen_mov_reg_Z(dst, src);
891 tcg_gen_xori_tl(dst, dst, 0x1);
892}
893
894// !(Z | (N ^ V))
895static inline void gen_op_eval_bg(TCGv dst, TCGv src)
896{
0425bee5 897 gen_mov_reg_N(cpu_tmp0, src);
19f329ad 898 gen_mov_reg_V(dst, src);
0425bee5
BS
899 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
900 gen_mov_reg_Z(cpu_tmp0, src);
901 tcg_gen_or_tl(dst, dst, cpu_tmp0);
19f329ad
BS
902 tcg_gen_xori_tl(dst, dst, 0x1);
903}
904
905// !(N ^ V)
906static inline void gen_op_eval_bge(TCGv dst, TCGv src)
907{
0425bee5 908 gen_mov_reg_V(cpu_tmp0, src);
19f329ad 909 gen_mov_reg_N(dst, src);
0425bee5 910 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
19f329ad
BS
911 tcg_gen_xori_tl(dst, dst, 0x1);
912}
913
914// !(C | Z)
915static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
916{
0425bee5 917 gen_mov_reg_Z(cpu_tmp0, src);
19f329ad 918 gen_mov_reg_C(dst, src);
0425bee5 919 tcg_gen_or_tl(dst, dst, cpu_tmp0);
19f329ad
BS
920 tcg_gen_xori_tl(dst, dst, 0x1);
921}
922
923// !C
924static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
925{
926 gen_mov_reg_C(dst, src);
927 tcg_gen_xori_tl(dst, dst, 0x1);
928}
929
930// !N
931static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
932{
933 gen_mov_reg_N(dst, src);
934 tcg_gen_xori_tl(dst, dst, 0x1);
935}
936
937// !V
938static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
939{
940 gen_mov_reg_V(dst, src);
941 tcg_gen_xori_tl(dst, dst, 0x1);
942}
943
944/*
945 FPSR bit field FCC1 | FCC0:
946 0 =
947 1 <
948 2 >
949 3 unordered
950*/
951static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
952 unsigned int fcc_offset)
953{
8911f501 954 tcg_gen_extu_i32_tl(reg, src);
4b8b8b76 955 tcg_gen_shri_tl(reg, reg, FSR_FCC0_SHIFT + fcc_offset);
19f329ad
BS
956 tcg_gen_andi_tl(reg, reg, 0x1);
957}
958
959static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
960 unsigned int fcc_offset)
961{
8911f501 962 tcg_gen_extu_i32_tl(reg, src);
4b8b8b76 963 tcg_gen_shri_tl(reg, reg, FSR_FCC1_SHIFT + fcc_offset);
19f329ad
BS
964 tcg_gen_andi_tl(reg, reg, 0x1);
965}
966
967// !0: FCC0 | FCC1
968static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
969 unsigned int fcc_offset)
970{
19f329ad 971 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
972 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
973 tcg_gen_or_tl(dst, dst, cpu_tmp0);
19f329ad
BS
974}
975
976// 1 or 2: FCC0 ^ FCC1
977static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
978 unsigned int fcc_offset)
979{
19f329ad 980 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
981 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
982 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
19f329ad
BS
983}
984
985// 1 or 3: FCC0
986static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
987 unsigned int fcc_offset)
988{
989 gen_mov_reg_FCC0(dst, src, fcc_offset);
990}
991
992// 1: FCC0 & !FCC1
993static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
994 unsigned int fcc_offset)
995{
19f329ad 996 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
997 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
998 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
999 tcg_gen_and_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1000}
1001
1002// 2 or 3: FCC1
1003static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1004 unsigned int fcc_offset)
1005{
1006 gen_mov_reg_FCC1(dst, src, fcc_offset);
1007}
1008
1009// 2: !FCC0 & FCC1
1010static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1011 unsigned int fcc_offset)
1012{
19f329ad
BS
1013 gen_mov_reg_FCC0(dst, src, fcc_offset);
1014 tcg_gen_xori_tl(dst, dst, 0x1);
0425bee5
BS
1015 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1016 tcg_gen_and_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1017}
1018
1019// 3: FCC0 & FCC1
1020static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1021 unsigned int fcc_offset)
1022{
19f329ad 1023 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
1024 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1025 tcg_gen_and_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1026}
1027
1028// 0: !(FCC0 | FCC1)
1029static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1030 unsigned int fcc_offset)
1031{
19f329ad 1032 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
1033 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1034 tcg_gen_or_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1035 tcg_gen_xori_tl(dst, dst, 0x1);
1036}
1037
1038// 0 or 3: !(FCC0 ^ FCC1)
1039static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1040 unsigned int fcc_offset)
1041{
19f329ad 1042 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
1043 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1044 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1045 tcg_gen_xori_tl(dst, dst, 0x1);
1046}
1047
1048// 0 or 2: !FCC0
1049static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1050 unsigned int fcc_offset)
1051{
1052 gen_mov_reg_FCC0(dst, src, fcc_offset);
1053 tcg_gen_xori_tl(dst, dst, 0x1);
1054}
1055
1056// !1: !(FCC0 & !FCC1)
1057static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1058 unsigned int fcc_offset)
1059{
19f329ad 1060 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
1061 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1062 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1063 tcg_gen_and_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1064 tcg_gen_xori_tl(dst, dst, 0x1);
1065}
1066
1067// 0 or 1: !FCC1
1068static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1069 unsigned int fcc_offset)
1070{
1071 gen_mov_reg_FCC1(dst, src, fcc_offset);
1072 tcg_gen_xori_tl(dst, dst, 0x1);
1073}
1074
1075// !2: !(!FCC0 & FCC1)
1076static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1077 unsigned int fcc_offset)
1078{
19f329ad
BS
1079 gen_mov_reg_FCC0(dst, src, fcc_offset);
1080 tcg_gen_xori_tl(dst, dst, 0x1);
0425bee5
BS
1081 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1082 tcg_gen_and_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1083 tcg_gen_xori_tl(dst, dst, 0x1);
1084}
1085
1086// !3: !(FCC0 & FCC1)
1087static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1088 unsigned int fcc_offset)
1089{
19f329ad 1090 gen_mov_reg_FCC0(dst, src, fcc_offset);
0425bee5
BS
1091 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1092 tcg_gen_and_tl(dst, dst, cpu_tmp0);
19f329ad
BS
1093 tcg_gen_xori_tl(dst, dst, 0x1);
1094}
1095
46525e1f 1096static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
19f329ad 1097 target_ulong pc2, TCGv r_cond)
83469015
FB
1098{
1099 int l1;
1100
1101 l1 = gen_new_label();
1102
0425bee5 1103 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
83469015 1104
6e256c93 1105 gen_goto_tb(dc, 0, pc1, pc1 + 4);
83469015
FB
1106
1107 gen_set_label(l1);
6e256c93 1108 gen_goto_tb(dc, 1, pc2, pc2 + 4);
83469015
FB
1109}
1110
46525e1f 1111static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
19f329ad 1112 target_ulong pc2, TCGv r_cond)
83469015
FB
1113{
1114 int l1;
1115
1116 l1 = gen_new_label();
1117
0425bee5 1118 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
83469015 1119
6e256c93 1120 gen_goto_tb(dc, 0, pc2, pc1);
83469015
FB
1121
1122 gen_set_label(l1);
6e256c93 1123 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
83469015
FB
1124}
1125
19f329ad
BS
1126static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1127 TCGv r_cond)
83469015
FB
1128{
1129 int l1, l2;
1130
1131 l1 = gen_new_label();
1132 l2 = gen_new_label();
19f329ad 1133
0425bee5 1134 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
83469015 1135
2f5680ee 1136 tcg_gen_movi_tl(cpu_npc, npc1);
06b3e1b3 1137 tcg_gen_br(l2);
83469015
FB
1138
1139 gen_set_label(l1);
2f5680ee 1140 tcg_gen_movi_tl(cpu_npc, npc2);
83469015
FB
1141 gen_set_label(l2);
1142}
1143
4af984a7
BS
1144/* call this function before using the condition register as it may
1145 have been set for a jump */
1146static inline void flush_cond(DisasContext *dc, TCGv cond)
83469015
FB
1147{
1148 if (dc->npc == JUMP_PC) {
4af984a7 1149 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
83469015
FB
1150 dc->npc = DYNAMIC_PC;
1151 }
1152}
1153
4af984a7 1154static inline void save_npc(DisasContext *dc, TCGv cond)
72cbca10
FB
1155{
1156 if (dc->npc == JUMP_PC) {
4af984a7 1157 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
72cbca10
FB
1158 dc->npc = DYNAMIC_PC;
1159 } else if (dc->npc != DYNAMIC_PC) {
2f5680ee 1160 tcg_gen_movi_tl(cpu_npc, dc->npc);
72cbca10
FB
1161 }
1162}
1163
4af984a7 1164static inline void save_state(DisasContext *dc, TCGv cond)
72cbca10 1165{
2f5680ee 1166 tcg_gen_movi_tl(cpu_pc, dc->pc);
4af984a7 1167 save_npc(dc, cond);
72cbca10
FB
1168}
1169
4af984a7 1170static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
0bee699e
FB
1171{
1172 if (dc->npc == JUMP_PC) {
4af984a7 1173 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
48d5c82b 1174 tcg_gen_mov_tl(cpu_pc, cpu_npc);
0bee699e
FB
1175 dc->pc = DYNAMIC_PC;
1176 } else if (dc->npc == DYNAMIC_PC) {
48d5c82b 1177 tcg_gen_mov_tl(cpu_pc, cpu_npc);
0bee699e
FB
1178 dc->pc = DYNAMIC_PC;
1179 } else {
1180 dc->pc = dc->npc;
1181 }
1182}
1183
38bc628b
BS
1184static inline void gen_op_next_insn(void)
1185{
48d5c82b
BS
1186 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1187 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
38bc628b
BS
1188}
1189
19f329ad
BS
1190static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1191{
1192 TCGv r_src;
3475187d 1193
3475187d 1194#ifdef TARGET_SPARC64
19f329ad 1195 if (cc)
dc99a3f2 1196 r_src = cpu_xcc;
19f329ad 1197 else
dc99a3f2 1198 r_src = cpu_psr;
3475187d 1199#else
dc99a3f2 1200 r_src = cpu_psr;
3475187d 1201#endif
19f329ad
BS
1202 switch (cond) {
1203 case 0x0:
1204 gen_op_eval_bn(r_dst);
1205 break;
1206 case 0x1:
1207 gen_op_eval_be(r_dst, r_src);
1208 break;
1209 case 0x2:
1210 gen_op_eval_ble(r_dst, r_src);
1211 break;
1212 case 0x3:
1213 gen_op_eval_bl(r_dst, r_src);
1214 break;
1215 case 0x4:
1216 gen_op_eval_bleu(r_dst, r_src);
1217 break;
1218 case 0x5:
1219 gen_op_eval_bcs(r_dst, r_src);
1220 break;
1221 case 0x6:
1222 gen_op_eval_bneg(r_dst, r_src);
1223 break;
1224 case 0x7:
1225 gen_op_eval_bvs(r_dst, r_src);
1226 break;
1227 case 0x8:
1228 gen_op_eval_ba(r_dst);
1229 break;
1230 case 0x9:
1231 gen_op_eval_bne(r_dst, r_src);
1232 break;
1233 case 0xa:
1234 gen_op_eval_bg(r_dst, r_src);
1235 break;
1236 case 0xb:
1237 gen_op_eval_bge(r_dst, r_src);
1238 break;
1239 case 0xc:
1240 gen_op_eval_bgu(r_dst, r_src);
1241 break;
1242 case 0xd:
1243 gen_op_eval_bcc(r_dst, r_src);
1244 break;
1245 case 0xe:
1246 gen_op_eval_bpos(r_dst, r_src);
1247 break;
1248 case 0xf:
1249 gen_op_eval_bvc(r_dst, r_src);
1250 break;
1251 }
1252}
7a3f1944 1253
19f329ad 1254static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
e8af50a3 1255{
19f329ad
BS
1256 unsigned int offset;
1257
19f329ad
BS
1258 switch (cc) {
1259 default:
1260 case 0x0:
1261 offset = 0;
1262 break;
1263 case 0x1:
1264 offset = 32 - 10;
1265 break;
1266 case 0x2:
1267 offset = 34 - 10;
1268 break;
1269 case 0x3:
1270 offset = 36 - 10;
1271 break;
1272 }
1273
1274 switch (cond) {
1275 case 0x0:
1276 gen_op_eval_bn(r_dst);
1277 break;
1278 case 0x1:
87e92502 1279 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
19f329ad
BS
1280 break;
1281 case 0x2:
87e92502 1282 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
19f329ad
BS
1283 break;
1284 case 0x3:
87e92502 1285 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
19f329ad
BS
1286 break;
1287 case 0x4:
87e92502 1288 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
19f329ad
BS
1289 break;
1290 case 0x5:
87e92502 1291 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
19f329ad
BS
1292 break;
1293 case 0x6:
87e92502 1294 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
19f329ad
BS
1295 break;
1296 case 0x7:
87e92502 1297 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
19f329ad
BS
1298 break;
1299 case 0x8:
1300 gen_op_eval_ba(r_dst);
1301 break;
1302 case 0x9:
87e92502 1303 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
19f329ad
BS
1304 break;
1305 case 0xa:
87e92502 1306 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
19f329ad
BS
1307 break;
1308 case 0xb:
87e92502 1309 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
19f329ad
BS
1310 break;
1311 case 0xc:
87e92502 1312 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
19f329ad
BS
1313 break;
1314 case 0xd:
87e92502 1315 gen_op_eval_fble(r_dst, cpu_fsr, offset);
19f329ad
BS
1316 break;
1317 case 0xe:
87e92502 1318 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
19f329ad
BS
1319 break;
1320 case 0xf:
87e92502 1321 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
19f329ad
BS
1322 break;
1323 }
e8af50a3 1324}
00f219bf 1325
19f329ad 1326#ifdef TARGET_SPARC64
00f219bf
BS
1327// Inverted logic
1328static const int gen_tcg_cond_reg[8] = {
1329 -1,
1330 TCG_COND_NE,
1331 TCG_COND_GT,
1332 TCG_COND_GE,
1333 -1,
1334 TCG_COND_EQ,
1335 TCG_COND_LE,
1336 TCG_COND_LT,
1337};
19f329ad 1338
4af984a7 1339static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
19f329ad 1340{
19f329ad
BS
1341 int l1;
1342
1343 l1 = gen_new_label();
0425bee5 1344 tcg_gen_movi_tl(r_dst, 0);
4af984a7 1345 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], r_src, tcg_const_tl(0), l1);
19f329ad
BS
1346 tcg_gen_movi_tl(r_dst, 1);
1347 gen_set_label(l1);
1348}
3475187d 1349#endif
cf495bcf 1350
0bee699e 1351/* XXX: potentially incorrect if dynamic npc */
4af984a7
BS
1352static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1353 TCGv r_cond)
7a3f1944 1354{
cf495bcf 1355 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
af7bf89b 1356 target_ulong target = dc->pc + offset;
5fafdf24 1357
cf495bcf 1358 if (cond == 0x0) {
0f8a249a
BS
1359 /* unconditional not taken */
1360 if (a) {
1361 dc->pc = dc->npc + 4;
1362 dc->npc = dc->pc + 4;
1363 } else {
1364 dc->pc = dc->npc;
1365 dc->npc = dc->pc + 4;
1366 }
cf495bcf 1367 } else if (cond == 0x8) {
0f8a249a
BS
1368 /* unconditional taken */
1369 if (a) {
1370 dc->pc = target;
1371 dc->npc = dc->pc + 4;
1372 } else {
1373 dc->pc = dc->npc;
1374 dc->npc = target;
1375 }
cf495bcf 1376 } else {
4af984a7
BS
1377 flush_cond(dc, r_cond);
1378 gen_cond(r_cond, cc, cond);
0f8a249a 1379 if (a) {
4af984a7 1380 gen_branch_a(dc, target, dc->npc, r_cond);
cf495bcf 1381 dc->is_br = 1;
0f8a249a 1382 } else {
cf495bcf 1383 dc->pc = dc->npc;
72cbca10
FB
1384 dc->jump_pc[0] = target;
1385 dc->jump_pc[1] = dc->npc + 4;
1386 dc->npc = JUMP_PC;
0f8a249a 1387 }
cf495bcf 1388 }
7a3f1944
FB
1389}
1390
0bee699e 1391/* XXX: potentially incorrect if dynamic npc */
4af984a7
BS
1392static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1393 TCGv r_cond)
e8af50a3
FB
1394{
1395 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
af7bf89b
FB
1396 target_ulong target = dc->pc + offset;
1397
e8af50a3 1398 if (cond == 0x0) {
0f8a249a
BS
1399 /* unconditional not taken */
1400 if (a) {
1401 dc->pc = dc->npc + 4;
1402 dc->npc = dc->pc + 4;
1403 } else {
1404 dc->pc = dc->npc;
1405 dc->npc = dc->pc + 4;
1406 }
e8af50a3 1407 } else if (cond == 0x8) {
0f8a249a
BS
1408 /* unconditional taken */
1409 if (a) {
1410 dc->pc = target;
1411 dc->npc = dc->pc + 4;
1412 } else {
1413 dc->pc = dc->npc;
1414 dc->npc = target;
1415 }
e8af50a3 1416 } else {
4af984a7
BS
1417 flush_cond(dc, r_cond);
1418 gen_fcond(r_cond, cc, cond);
0f8a249a 1419 if (a) {
4af984a7 1420 gen_branch_a(dc, target, dc->npc, r_cond);
e8af50a3 1421 dc->is_br = 1;
0f8a249a 1422 } else {
e8af50a3
FB
1423 dc->pc = dc->npc;
1424 dc->jump_pc[0] = target;
1425 dc->jump_pc[1] = dc->npc + 4;
1426 dc->npc = JUMP_PC;
0f8a249a 1427 }
e8af50a3
FB
1428 }
1429}
1430
3475187d
FB
1431#ifdef TARGET_SPARC64
1432/* XXX: potentially incorrect if dynamic npc */
4af984a7
BS
1433static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1434 TCGv r_cond, TCGv r_reg)
7a3f1944 1435{
3475187d
FB
1436 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1437 target_ulong target = dc->pc + offset;
1438
4af984a7
BS
1439 flush_cond(dc, r_cond);
1440 gen_cond_reg(r_cond, cond, r_reg);
3475187d 1441 if (a) {
4af984a7 1442 gen_branch_a(dc, target, dc->npc, r_cond);
0f8a249a 1443 dc->is_br = 1;
3475187d 1444 } else {
0f8a249a
BS
1445 dc->pc = dc->npc;
1446 dc->jump_pc[0] = target;
1447 dc->jump_pc[1] = dc->npc + 4;
1448 dc->npc = JUMP_PC;
3475187d 1449 }
7a3f1944
FB
1450}
1451
3475187d 1452static GenOpFunc * const gen_fcmps[4] = {
7e8c2b6c
BS
1453 helper_fcmps,
1454 helper_fcmps_fcc1,
1455 helper_fcmps_fcc2,
1456 helper_fcmps_fcc3,
3475187d
FB
1457};
1458
1459static GenOpFunc * const gen_fcmpd[4] = {
7e8c2b6c
BS
1460 helper_fcmpd,
1461 helper_fcmpd_fcc1,
1462 helper_fcmpd_fcc2,
1463 helper_fcmpd_fcc3,
3475187d 1464};
417454b0 1465
1f587329
BS
1466#if defined(CONFIG_USER_ONLY)
1467static GenOpFunc * const gen_fcmpq[4] = {
7e8c2b6c
BS
1468 helper_fcmpq,
1469 helper_fcmpq_fcc1,
1470 helper_fcmpq_fcc2,
1471 helper_fcmpq_fcc3,
1f587329
BS
1472};
1473#endif
1474
417454b0 1475static GenOpFunc * const gen_fcmpes[4] = {
7e8c2b6c
BS
1476 helper_fcmpes,
1477 helper_fcmpes_fcc1,
1478 helper_fcmpes_fcc2,
1479 helper_fcmpes_fcc3,
417454b0
BS
1480};
1481
1482static GenOpFunc * const gen_fcmped[4] = {
7e8c2b6c
BS
1483 helper_fcmped,
1484 helper_fcmped_fcc1,
1485 helper_fcmped_fcc2,
1486 helper_fcmped_fcc3,
417454b0
BS
1487};
1488
1f587329
BS
1489#if defined(CONFIG_USER_ONLY)
1490static GenOpFunc * const gen_fcmpeq[4] = {
7e8c2b6c
BS
1491 helper_fcmpeq,
1492 helper_fcmpeq_fcc1,
1493 helper_fcmpeq_fcc2,
1494 helper_fcmpeq_fcc3,
1f587329
BS
1495};
1496#endif
7e8c2b6c
BS
1497
1498static inline void gen_op_fcmps(int fccno)
1499{
1500 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1501}
1502
1503static inline void gen_op_fcmpd(int fccno)
1504{
1505 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1506}
1507
1508#if defined(CONFIG_USER_ONLY)
1509static inline void gen_op_fcmpq(int fccno)
1510{
1511 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1512}
1513#endif
1514
1515static inline void gen_op_fcmpes(int fccno)
1516{
1517 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1518}
1519
1520static inline void gen_op_fcmped(int fccno)
1521{
1522 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1523}
1524
1525#if defined(CONFIG_USER_ONLY)
1526static inline void gen_op_fcmpeq(int fccno)
1527{
1528 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1529}
1530#endif
1531
1532#else
1533
1534static inline void gen_op_fcmps(int fccno)
1535{
1536 tcg_gen_helper_0_0(helper_fcmps);
1537}
1538
1539static inline void gen_op_fcmpd(int fccno)
1540{
1541 tcg_gen_helper_0_0(helper_fcmpd);
1542}
1543
1544#if defined(CONFIG_USER_ONLY)
1545static inline void gen_op_fcmpq(int fccno)
1546{
1547 tcg_gen_helper_0_0(helper_fcmpq);
1548}
1549#endif
1550
1551static inline void gen_op_fcmpes(int fccno)
1552{
1553 tcg_gen_helper_0_0(helper_fcmpes);
1554}
1555
1556static inline void gen_op_fcmped(int fccno)
1557{
1558 tcg_gen_helper_0_0(helper_fcmped);
1559}
1560
1561#if defined(CONFIG_USER_ONLY)
1562static inline void gen_op_fcmpeq(int fccno)
1563{
1564 tcg_gen_helper_0_0(helper_fcmpeq);
1565}
1566#endif
1567
3475187d
FB
1568#endif
1569
134d77a1
BS
1570static inline void gen_op_fpexception_im(int fsr_flags)
1571{
87e92502
BS
1572 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1573 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
2f5680ee 1574 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_FP_EXCP));
134d77a1
BS
1575}
1576
4af984a7 1577static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
a80dde08
FB
1578{
1579#if !defined(CONFIG_USER_ONLY)
1580 if (!dc->fpu_enabled) {
4af984a7 1581 save_state(dc, r_cond);
2f5680ee 1582 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NFPU_INSN));
a80dde08
FB
1583 dc->is_br = 1;
1584 return 1;
1585 }
1586#endif
1587 return 0;
1588}
1589
7e8c2b6c
BS
1590static inline void gen_op_clear_ieee_excp_and_FTT(void)
1591{
87e92502 1592 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
7e8c2b6c
BS
1593}
1594
1595static inline void gen_clear_float_exceptions(void)
1596{
1597 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1598}
1599
1a2fb1c0
BS
1600/* asi moves */
1601#ifdef TARGET_SPARC64
0425bee5 1602static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1a2fb1c0
BS
1603{
1604 int asi, offset;
0425bee5 1605 TCGv r_asi;
1a2fb1c0 1606
1a2fb1c0 1607 if (IS_IMM) {
0425bee5 1608 r_asi = tcg_temp_new(TCG_TYPE_I32);
1a2fb1c0 1609 offset = GET_FIELD(insn, 25, 31);
0425bee5
BS
1610 tcg_gen_addi_tl(r_addr, r_addr, offset);
1611 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1a2fb1c0
BS
1612 } else {
1613 asi = GET_FIELD(insn, 19, 26);
0425bee5 1614 r_asi = tcg_const_i32(asi);
1a2fb1c0 1615 }
0425bee5
BS
1616 return r_asi;
1617}
1618
4af984a7 1619static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size, int sign)
0425bee5
BS
1620{
1621 TCGv r_asi;
1622
4af984a7
BS
1623 r_asi = gen_get_asi(insn, addr);
1624 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi,
0425bee5 1625 tcg_const_i32(size), tcg_const_i32(sign));
1a2fb1c0
BS
1626}
1627
4af984a7 1628static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1a2fb1c0 1629{
0425bee5 1630 TCGv r_asi;
1a2fb1c0 1631
4af984a7
BS
1632 r_asi = gen_get_asi(insn, addr);
1633 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, tcg_const_i32(size));
1a2fb1c0
BS
1634}
1635
4af984a7 1636static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1a2fb1c0 1637{
0425bee5 1638 TCGv r_asi;
1a2fb1c0 1639
4af984a7
BS
1640 r_asi = gen_get_asi(insn, addr);
1641 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, tcg_const_i32(size),
0425bee5 1642 tcg_const_i32(rd));
1a2fb1c0
BS
1643}
1644
4af984a7 1645static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1a2fb1c0 1646{
0425bee5 1647 TCGv r_asi;
1a2fb1c0 1648
31741a27
BS
1649 r_asi = gen_get_asi(insn, addr);
1650 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, tcg_const_i32(size),
0425bee5 1651 tcg_const_i32(rd));
1a2fb1c0
BS
1652}
1653
4af984a7 1654static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1a2fb1c0 1655{
0425bee5 1656 TCGv r_temp, r_asi;
1a2fb1c0 1657
1a2fb1c0 1658 r_temp = tcg_temp_new(TCG_TYPE_I32);
4af984a7
BS
1659 r_asi = gen_get_asi(insn, addr);
1660 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, r_asi,
0425bee5 1661 tcg_const_i32(4), tcg_const_i32(0));
4af984a7 1662 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi,
0425bee5 1663 tcg_const_i32(4));
4af984a7 1664 tcg_gen_extu_i32_tl(dst, r_temp);
1a2fb1c0
BS
1665}
1666
4af984a7 1667static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1a2fb1c0 1668{
8911f501 1669 TCGv r_asi;
1a2fb1c0 1670
4af984a7
BS
1671 r_asi = gen_get_asi(insn, addr);
1672 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi,
0425bee5 1673 tcg_const_i32(8), tcg_const_i32(0));
4af984a7 1674 tcg_gen_andi_i64(lo, cpu_tmp64, 0xffffffffULL);
8911f501 1675 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4af984a7 1676 tcg_gen_andi_i64(hi, cpu_tmp64, 0xffffffffULL);
0425bee5
BS
1677}
1678
4af984a7 1679static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
0425bee5 1680{
8911f501 1681 TCGv r_temp, r_asi;
0425bee5 1682
0425bee5
BS
1683 r_temp = tcg_temp_new(TCG_TYPE_I32);
1684 gen_movl_reg_TN(rd + 1, r_temp);
4af984a7 1685 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
0425bee5 1686 r_temp);
4af984a7
BS
1687 r_asi = gen_get_asi(insn, addr);
1688 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi,
0425bee5 1689 tcg_const_i32(8));
1a2fb1c0
BS
1690}
1691
4af984a7 1692static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn, int rd)
1a2fb1c0 1693{
1a2fb1c0
BS
1694 TCGv r_val1, r_asi;
1695
1696 r_val1 = tcg_temp_new(TCG_TYPE_I32);
1a2fb1c0 1697 gen_movl_reg_TN(rd, r_val1);
4af984a7
BS
1698 r_asi = gen_get_asi(insn, addr);
1699 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1a2fb1c0
BS
1700}
1701
4af984a7 1702static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn, int rd)
1a2fb1c0 1703{
8911f501 1704 TCGv r_asi;
1a2fb1c0 1705
8911f501 1706 gen_movl_reg_TN(rd, cpu_tmp64);
4af984a7
BS
1707 r_asi = gen_get_asi(insn, addr);
1708 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1a2fb1c0
BS
1709}
1710
1711#elif !defined(CONFIG_USER_ONLY)
1712
4af984a7 1713static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size, int sign)
1a2fb1c0
BS
1714{
1715 int asi;
1a2fb1c0 1716
1a2fb1c0 1717 asi = GET_FIELD(insn, 19, 26);
4af984a7 1718 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
0425bee5 1719 tcg_const_i32(size), tcg_const_i32(sign));
4af984a7 1720 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1a2fb1c0
BS
1721}
1722
4af984a7 1723static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1a2fb1c0
BS
1724{
1725 int asi;
1a2fb1c0 1726
4af984a7 1727 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1a2fb1c0 1728 asi = GET_FIELD(insn, 19, 26);
4af984a7 1729 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
0425bee5 1730 tcg_const_i32(size));
1a2fb1c0
BS
1731}
1732
4af984a7 1733static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1a2fb1c0
BS
1734{
1735 int asi;
0425bee5 1736 TCGv r_temp;
1a2fb1c0 1737
1a2fb1c0 1738 r_temp = tcg_temp_new(TCG_TYPE_I32);
1a2fb1c0 1739 asi = GET_FIELD(insn, 19, 26);
4af984a7 1740 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, tcg_const_i32(asi),
0425bee5 1741 tcg_const_i32(4), tcg_const_i32(0));
4af984a7 1742 tcg_gen_helper_0_4(helper_st_asi, addr, dst, tcg_const_i32(asi),
0425bee5 1743 tcg_const_i32(4));
4af984a7 1744 tcg_gen_extu_i32_tl(dst, r_temp);
1a2fb1c0
BS
1745}
1746
4af984a7 1747static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1a2fb1c0
BS
1748{
1749 int asi;
1a2fb1c0 1750
1a2fb1c0 1751 asi = GET_FIELD(insn, 19, 26);
4af984a7 1752 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
0425bee5 1753 tcg_const_i32(8), tcg_const_i32(0));
4af984a7 1754 tcg_gen_trunc_i64_tl(lo, cpu_tmp64);
8911f501 1755 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4af984a7 1756 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
0425bee5
BS
1757}
1758
4af984a7 1759static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
0425bee5
BS
1760{
1761 int asi;
8911f501 1762 TCGv r_temp;
0425bee5 1763
0425bee5
BS
1764 r_temp = tcg_temp_new(TCG_TYPE_I32);
1765 gen_movl_reg_TN(rd + 1, r_temp);
4af984a7 1766 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
0425bee5 1767 asi = GET_FIELD(insn, 19, 26);
4af984a7 1768 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
0425bee5 1769 tcg_const_i32(8));
1a2fb1c0
BS
1770}
1771#endif
1772
1773#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4af984a7 1774static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1a2fb1c0
BS
1775{
1776 int asi;
1a2fb1c0 1777
4af984a7 1778 gen_ld_asi(dst, addr, insn, 1, 0);
1a2fb1c0 1779
1a2fb1c0 1780 asi = GET_FIELD(insn, 19, 26);
4af984a7 1781 tcg_gen_helper_0_4(helper_st_asi, addr, tcg_const_i64(0xffULL),
0425bee5 1782 tcg_const_i32(asi), tcg_const_i32(1));
1a2fb1c0
BS
1783}
1784#endif
1785
9322a4bf
BS
1786static inline TCGv get_src1(unsigned int insn, TCGv def)
1787{
1788 TCGv r_rs1 = def;
1789 unsigned int rs1;
1790
1791 rs1 = GET_FIELD(insn, 13, 17);
1792 if (rs1 == 0)
1793 //r_rs1 = tcg_const_tl(0);
1794 tcg_gen_movi_tl(def, 0);
1795 else if (rs1 < 8)
1796 //r_rs1 = cpu_gregs[rs1];
1797 tcg_gen_mov_tl(def, cpu_gregs[rs1]);
1798 else
1799 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1800 return r_rs1;
1801}
1802
a49d9390
BS
1803static inline TCGv get_src2(unsigned int insn, TCGv def)
1804{
1805 TCGv r_rs2 = def;
1806 unsigned int rs2;
1807
1808 if (IS_IMM) { /* immediate */
1809 rs2 = GET_FIELDs(insn, 19, 31);
1810 r_rs2 = tcg_const_tl((int)rs2);
1811 } else { /* register */
1812 rs2 = GET_FIELD(insn, 27, 31);
1813 if (rs2 == 0)
1814 r_rs2 = tcg_const_tl(0);
1815 else if (rs2 < 8)
1816 r_rs2 = cpu_gregs[rs2];
1817 else
1818 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1819 }
1820 return r_rs2;
1821}
1822
0bee699e 1823/* before an instruction, dc->pc must be static */
cf495bcf
FB
1824static void disas_sparc_insn(DisasContext * dc)
1825{
1826 unsigned int insn, opc, rs1, rs2, rd;
7a3f1944 1827
0fa85d43 1828 insn = ldl_code(dc->pc);
cf495bcf 1829 opc = GET_FIELD(insn, 0, 1);
7a3f1944 1830
cf495bcf 1831 rd = GET_FIELD(insn, 2, 6);
6ae20372
BS
1832
1833 cpu_dst = cpu_T[0];
1834 cpu_src1 = cpu_T[0]; // const
1835 cpu_src2 = cpu_T[1]; // const
1836
1837 // loads and stores
1838 cpu_addr = cpu_T[0];
1839 cpu_val = cpu_T[1];
1840
cf495bcf 1841 switch (opc) {
0f8a249a
BS
1842 case 0: /* branches/sethi */
1843 {
1844 unsigned int xop = GET_FIELD(insn, 7, 9);
1845 int32_t target;
1846 switch (xop) {
3475187d 1847#ifdef TARGET_SPARC64
0f8a249a
BS
1848 case 0x1: /* V9 BPcc */
1849 {
1850 int cc;
1851
1852 target = GET_FIELD_SP(insn, 0, 18);
1853 target = sign_extend(target, 18);
1854 target <<= 2;
1855 cc = GET_FIELD_SP(insn, 20, 21);
1856 if (cc == 0)
6ae20372 1857 do_branch(dc, target, insn, 0, cpu_cond);
0f8a249a 1858 else if (cc == 2)
6ae20372 1859 do_branch(dc, target, insn, 1, cpu_cond);
0f8a249a
BS
1860 else
1861 goto illegal_insn;
1862 goto jmp_insn;
1863 }
1864 case 0x3: /* V9 BPr */
1865 {
1866 target = GET_FIELD_SP(insn, 0, 13) |
13846e70 1867 (GET_FIELD_SP(insn, 20, 21) << 14);
0f8a249a
BS
1868 target = sign_extend(target, 16);
1869 target <<= 2;
9322a4bf 1870 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372 1871 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
0f8a249a
BS
1872 goto jmp_insn;
1873 }
1874 case 0x5: /* V9 FBPcc */
1875 {
1876 int cc = GET_FIELD_SP(insn, 20, 21);
6ae20372 1877 if (gen_trap_ifnofpu(dc, cpu_cond))
a80dde08 1878 goto jmp_insn;
0f8a249a
BS
1879 target = GET_FIELD_SP(insn, 0, 18);
1880 target = sign_extend(target, 19);
1881 target <<= 2;
6ae20372 1882 do_fbranch(dc, target, insn, cc, cpu_cond);
0f8a249a
BS
1883 goto jmp_insn;
1884 }
a4d17f19 1885#else
0f8a249a
BS
1886 case 0x7: /* CBN+x */
1887 {
1888 goto ncp_insn;
1889 }
1890#endif
1891 case 0x2: /* BN+x */
1892 {
1893 target = GET_FIELD(insn, 10, 31);
1894 target = sign_extend(target, 22);
1895 target <<= 2;
6ae20372 1896 do_branch(dc, target, insn, 0, cpu_cond);
0f8a249a
BS
1897 goto jmp_insn;
1898 }
1899 case 0x6: /* FBN+x */
1900 {
6ae20372 1901 if (gen_trap_ifnofpu(dc, cpu_cond))
a80dde08 1902 goto jmp_insn;
0f8a249a
BS
1903 target = GET_FIELD(insn, 10, 31);
1904 target = sign_extend(target, 22);
1905 target <<= 2;
6ae20372 1906 do_fbranch(dc, target, insn, 0, cpu_cond);
0f8a249a
BS
1907 goto jmp_insn;
1908 }
1909 case 0x4: /* SETHI */
0f8a249a 1910 if (rd) { // nop
0f8a249a 1911 uint32_t value = GET_FIELD(insn, 10, 31);
6ae20372
BS
1912 tcg_gen_movi_tl(cpu_dst, value << 10);
1913 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a 1914 }
0f8a249a
BS
1915 break;
1916 case 0x0: /* UNIMPL */
1917 default:
3475187d 1918 goto illegal_insn;
0f8a249a
BS
1919 }
1920 break;
1921 }
1922 break;
cf495bcf 1923 case 1:
0f8a249a
BS
1924 /*CALL*/ {
1925 target_long target = GET_FIELDs(insn, 2, 31) << 2;
cf495bcf 1926
48d5c82b 1927 gen_movl_TN_reg(15, tcg_const_tl(dc->pc));
0f8a249a 1928 target += dc->pc;
6ae20372 1929 gen_mov_pc_npc(dc, cpu_cond);
0f8a249a
BS
1930 dc->npc = target;
1931 }
1932 goto jmp_insn;
1933 case 2: /* FPU & Logical Operations */
1934 {
1935 unsigned int xop = GET_FIELD(insn, 7, 12);
1936 if (xop == 0x3a) { /* generate trap */
cf495bcf 1937 int cond;
3475187d 1938
9322a4bf 1939 cpu_src1 = get_src1(insn, cpu_src1);
0f8a249a
BS
1940 if (IS_IMM) {
1941 rs2 = GET_FIELD(insn, 25, 31);
6ae20372 1942 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
cf495bcf
FB
1943 } else {
1944 rs2 = GET_FIELD(insn, 27, 31);
0f8a249a 1945 if (rs2 != 0) {
6ae20372
BS
1946 gen_movl_reg_TN(rs2, cpu_src2);
1947 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
6f551262
BS
1948 } else
1949 tcg_gen_mov_tl(cpu_dst, cpu_src1);
cf495bcf 1950 }
cf495bcf
FB
1951 cond = GET_FIELD(insn, 3, 6);
1952 if (cond == 0x8) {
6ae20372
BS
1953 save_state(dc, cpu_cond);
1954 tcg_gen_helper_0_1(helper_trap, cpu_dst);
af7bf89b 1955 } else if (cond != 0) {
748b9d8e 1956 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
3475187d 1957#ifdef TARGET_SPARC64
0f8a249a
BS
1958 /* V9 icc/xcc */
1959 int cc = GET_FIELD_SP(insn, 11, 12);
748b9d8e 1960
6ae20372 1961 save_state(dc, cpu_cond);
0f8a249a 1962 if (cc == 0)
748b9d8e 1963 gen_cond(r_cond, 0, cond);
0f8a249a 1964 else if (cc == 2)
748b9d8e 1965 gen_cond(r_cond, 1, cond);
0f8a249a
BS
1966 else
1967 goto illegal_insn;
3475187d 1968#else
6ae20372 1969 save_state(dc, cpu_cond);
748b9d8e 1970 gen_cond(r_cond, 0, cond);
3475187d 1971#endif
6ae20372 1972 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
cf495bcf 1973 }
a80dde08 1974 gen_op_next_insn();
57fec1fe 1975 tcg_gen_exit_tb(0);
a80dde08
FB
1976 dc->is_br = 1;
1977 goto jmp_insn;
cf495bcf
FB
1978 } else if (xop == 0x28) {
1979 rs1 = GET_FIELD(insn, 13, 17);
1980 switch(rs1) {
1981 case 0: /* rdy */
65fe7b09
BS
1982#ifndef TARGET_SPARC64
1983 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1984 manual, rdy on the microSPARC
1985 II */
1986 case 0x0f: /* stbar in the SPARCv8 manual,
1987 rdy on the microSPARC II */
1988 case 0x10 ... 0x1f: /* implementation-dependent in the
1989 SPARCv8 manual, rdy on the
1990 microSPARC II */
1991#endif
6ae20372
BS
1992 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
1993 gen_movl_TN_reg(rd, cpu_dst);
cf495bcf 1994 break;
3475187d 1995#ifdef TARGET_SPARC64
0f8a249a 1996 case 0x2: /* V9 rdccr */
6ae20372
BS
1997 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
1998 gen_movl_TN_reg(rd, cpu_dst);
3475187d 1999 break;
0f8a249a 2000 case 0x3: /* V9 rdasi */
2f5680ee 2001 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
6ae20372
BS
2002 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2003 gen_movl_TN_reg(rd, cpu_dst);
3475187d 2004 break;
0f8a249a 2005 case 0x4: /* V9 rdtick */
ccd4a219
BS
2006 {
2007 TCGv r_tickptr;
2008
2009 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2010 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2011 offsetof(CPUState, tick));
6ae20372 2012 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
ccd4a219 2013 r_tickptr);
6ae20372 2014 gen_movl_TN_reg(rd, cpu_dst);
ccd4a219 2015 }
3475187d 2016 break;
0f8a249a 2017 case 0x5: /* V9 rdpc */
6ae20372
BS
2018 tcg_gen_movi_tl(cpu_dst, dc->pc);
2019 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a
BS
2020 break;
2021 case 0x6: /* V9 rdfprs */
2f5680ee 2022 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
6ae20372
BS
2023 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2024 gen_movl_TN_reg(rd, cpu_dst);
3475187d 2025 break;
65fe7b09
BS
2026 case 0xf: /* V9 membar */
2027 break; /* no effect */
0f8a249a 2028 case 0x13: /* Graphics Status */
6ae20372 2029 if (gen_trap_ifnofpu(dc, cpu_cond))
725cb90b 2030 goto jmp_insn;
6ae20372
BS
2031 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
2032 gen_movl_TN_reg(rd, cpu_dst);
725cb90b 2033 break;
0f8a249a 2034 case 0x17: /* Tick compare */
6ae20372
BS
2035 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tick_cmpr));
2036 gen_movl_TN_reg(rd, cpu_dst);
83469015 2037 break;
0f8a249a 2038 case 0x18: /* System tick */
ccd4a219
BS
2039 {
2040 TCGv r_tickptr;
2041
2042 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2043 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2044 offsetof(CPUState, stick));
6ae20372 2045 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
ccd4a219 2046 r_tickptr);
6ae20372 2047 gen_movl_TN_reg(rd, cpu_dst);
ccd4a219 2048 }
83469015 2049 break;
0f8a249a 2050 case 0x19: /* System tick compare */
6ae20372
BS
2051 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, stick_cmpr));
2052 gen_movl_TN_reg(rd, cpu_dst);
83469015 2053 break;
0f8a249a
BS
2054 case 0x10: /* Performance Control */
2055 case 0x11: /* Performance Instrumentation Counter */
2056 case 0x12: /* Dispatch Control */
2057 case 0x14: /* Softint set, WO */
2058 case 0x15: /* Softint clear, WO */
2059 case 0x16: /* Softint write */
3475187d
FB
2060#endif
2061 default:
cf495bcf
FB
2062 goto illegal_insn;
2063 }
e8af50a3 2064#if !defined(CONFIG_USER_ONLY)
e9ebed4d 2065 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
3475187d 2066#ifndef TARGET_SPARC64
0f8a249a
BS
2067 if (!supervisor(dc))
2068 goto priv_insn;
6ae20372 2069 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
e9ebed4d
BS
2070#else
2071 if (!hypervisor(dc))
2072 goto priv_insn;
2073 rs1 = GET_FIELD(insn, 13, 17);
2074 switch (rs1) {
2075 case 0: // hpstate
2076 // gen_op_rdhpstate();
2077 break;
2078 case 1: // htstate
2079 // gen_op_rdhtstate();
2080 break;
2081 case 3: // hintp
2f5680ee 2082 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
6ae20372 2083 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
e9ebed4d
BS
2084 break;
2085 case 5: // htba
2f5680ee 2086 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
6ae20372 2087 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
e9ebed4d
BS
2088 break;
2089 case 6: // hver
2f5680ee 2090 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hver));
6ae20372 2091 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
e9ebed4d
BS
2092 break;
2093 case 31: // hstick_cmpr
6ae20372 2094 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 2095 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hstick_cmpr));
e9ebed4d
BS
2096 break;
2097 default:
2098 goto illegal_insn;
2099 }
2100#endif
6ae20372 2101 gen_movl_TN_reg(rd, cpu_dst);
e8af50a3 2102 break;
3475187d 2103 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
0f8a249a
BS
2104 if (!supervisor(dc))
2105 goto priv_insn;
3475187d
FB
2106#ifdef TARGET_SPARC64
2107 rs1 = GET_FIELD(insn, 13, 17);
0f8a249a
BS
2108 switch (rs1) {
2109 case 0: // tpc
375ee38b
BS
2110 {
2111 TCGv r_tsptr;
2112
2113 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2114 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2115 offsetof(CPUState, tsptr));
6ae20372 2116 tcg_gen_ld_tl(cpu_dst, r_tsptr,
375ee38b
BS
2117 offsetof(trap_state, tpc));
2118 }
0f8a249a
BS
2119 break;
2120 case 1: // tnpc
375ee38b
BS
2121 {
2122 TCGv r_tsptr;
2123
2124 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2125 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2126 offsetof(CPUState, tsptr));
6ae20372 2127 tcg_gen_ld_tl(cpu_dst, r_tsptr,
375ee38b
BS
2128 offsetof(trap_state, tnpc));
2129 }
0f8a249a
BS
2130 break;
2131 case 2: // tstate
375ee38b
BS
2132 {
2133 TCGv r_tsptr;
2134
2135 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2136 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2137 offsetof(CPUState, tsptr));
6ae20372 2138 tcg_gen_ld_tl(cpu_dst, r_tsptr,
375ee38b
BS
2139 offsetof(trap_state, tstate));
2140 }
0f8a249a
BS
2141 break;
2142 case 3: // tt
375ee38b
BS
2143 {
2144 TCGv r_tsptr;
2145
2146 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2147 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2148 offsetof(CPUState, tsptr));
6ae20372 2149 tcg_gen_ld_i32(cpu_dst, r_tsptr,
375ee38b
BS
2150 offsetof(trap_state, tt));
2151 }
0f8a249a
BS
2152 break;
2153 case 4: // tick
ccd4a219
BS
2154 {
2155 TCGv r_tickptr;
2156
2157 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2158 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2159 offsetof(CPUState, tick));
6ae20372 2160 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
ccd4a219 2161 r_tickptr);
6ae20372 2162 gen_movl_TN_reg(rd, cpu_dst);
ccd4a219 2163 }
0f8a249a
BS
2164 break;
2165 case 5: // tba
6ae20372 2166 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
0f8a249a
BS
2167 break;
2168 case 6: // pstate
2f5680ee 2169 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, pstate));
6ae20372 2170 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a
BS
2171 break;
2172 case 7: // tl
2f5680ee 2173 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
6ae20372 2174 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a
BS
2175 break;
2176 case 8: // pil
2f5680ee 2177 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
6ae20372 2178 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a
BS
2179 break;
2180 case 9: // cwp
6ae20372 2181 tcg_gen_helper_1_0(helper_rdcwp, cpu_dst);
0f8a249a
BS
2182 break;
2183 case 10: // cansave
2f5680ee 2184 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
6ae20372 2185 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a
BS
2186 break;
2187 case 11: // canrestore
2f5680ee 2188 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
6ae20372 2189 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a
BS
2190 break;
2191 case 12: // cleanwin
2f5680ee 2192 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
6ae20372 2193 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a
BS
2194 break;
2195 case 13: // otherwin
2f5680ee 2196 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
6ae20372 2197 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a
BS
2198 break;
2199 case 14: // wstate
2f5680ee 2200 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
6ae20372 2201 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
0f8a249a 2202 break;
e9ebed4d 2203 case 16: // UA2005 gl
2f5680ee 2204 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
6ae20372 2205 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
e9ebed4d
BS
2206 break;
2207 case 26: // UA2005 strand status
2208 if (!hypervisor(dc))
2209 goto priv_insn;
2f5680ee 2210 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
6ae20372 2211 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
e9ebed4d 2212 break;
0f8a249a 2213 case 31: // ver
6ae20372 2214 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, version));
0f8a249a
BS
2215 break;
2216 case 15: // fq
2217 default:
2218 goto illegal_insn;
2219 }
3475187d 2220#else
2f5680ee 2221 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
6ae20372 2222 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
3475187d 2223#endif
6ae20372 2224 gen_movl_TN_reg(rd, cpu_dst);
e8af50a3 2225 break;
3475187d
FB
2226 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2227#ifdef TARGET_SPARC64
72a9747b 2228 tcg_gen_helper_0_0(helper_flushw);
3475187d 2229#else
0f8a249a
BS
2230 if (!supervisor(dc))
2231 goto priv_insn;
6ae20372
BS
2232 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2233 gen_movl_TN_reg(rd, cpu_dst);
3475187d 2234#endif
e8af50a3
FB
2235 break;
2236#endif
0f8a249a 2237 } else if (xop == 0x34) { /* FPU Operations */
6ae20372 2238 if (gen_trap_ifnofpu(dc, cpu_cond))
a80dde08 2239 goto jmp_insn;
0f8a249a 2240 gen_op_clear_ieee_excp_and_FTT();
e8af50a3 2241 rs1 = GET_FIELD(insn, 13, 17);
0f8a249a
BS
2242 rs2 = GET_FIELD(insn, 27, 31);
2243 xop = GET_FIELD(insn, 18, 26);
2244 switch (xop) {
2245 case 0x1: /* fmovs */
2246 gen_op_load_fpr_FT0(rs2);
2247 gen_op_store_FT0_fpr(rd);
2248 break;
2249 case 0x5: /* fnegs */
2250 gen_op_load_fpr_FT1(rs2);
44e7757c 2251 tcg_gen_helper_0_0(helper_fnegs);
0f8a249a
BS
2252 gen_op_store_FT0_fpr(rd);
2253 break;
2254 case 0x9: /* fabss */
2255 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2256 tcg_gen_helper_0_0(helper_fabss);
0f8a249a
BS
2257 gen_op_store_FT0_fpr(rd);
2258 break;
2259 case 0x29: /* fsqrts */
2260 gen_op_load_fpr_FT1(rs2);
7e8c2b6c
BS
2261 gen_clear_float_exceptions();
2262 tcg_gen_helper_0_0(helper_fsqrts);
2263 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2264 gen_op_store_FT0_fpr(rd);
2265 break;
2266 case 0x2a: /* fsqrtd */
2267 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c
BS
2268 gen_clear_float_exceptions();
2269 tcg_gen_helper_0_0(helper_fsqrtd);
2270 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2271 gen_op_store_DT0_fpr(DFPREG(rd));
2272 break;
2273 case 0x2b: /* fsqrtq */
1f587329
BS
2274#if defined(CONFIG_USER_ONLY)
2275 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c
BS
2276 gen_clear_float_exceptions();
2277 tcg_gen_helper_0_0(helper_fsqrtq);
2278 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2279 gen_op_store_QT0_fpr(QFPREG(rd));
2280 break;
2281#else
0f8a249a 2282 goto nfpu_insn;
1f587329 2283#endif
0f8a249a
BS
2284 case 0x41:
2285 gen_op_load_fpr_FT0(rs1);
2286 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2287 gen_clear_float_exceptions();
44e7757c 2288 tcg_gen_helper_0_0(helper_fadds);
7e8c2b6c 2289 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2290 gen_op_store_FT0_fpr(rd);
2291 break;
2292 case 0x42:
2293 gen_op_load_fpr_DT0(DFPREG(rs1));
2294 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2295 gen_clear_float_exceptions();
44e7757c 2296 tcg_gen_helper_0_0(helper_faddd);
7e8c2b6c 2297 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2298 gen_op_store_DT0_fpr(DFPREG(rd));
2299 break;
2300 case 0x43: /* faddq */
1f587329
BS
2301#if defined(CONFIG_USER_ONLY)
2302 gen_op_load_fpr_QT0(QFPREG(rs1));
2303 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2304 gen_clear_float_exceptions();
44e7757c 2305 tcg_gen_helper_0_0(helper_faddq);
7e8c2b6c 2306 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2307 gen_op_store_QT0_fpr(QFPREG(rd));
2308 break;
2309#else
0f8a249a 2310 goto nfpu_insn;
1f587329 2311#endif
0f8a249a
BS
2312 case 0x45:
2313 gen_op_load_fpr_FT0(rs1);
2314 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2315 gen_clear_float_exceptions();
44e7757c 2316 tcg_gen_helper_0_0(helper_fsubs);
7e8c2b6c 2317 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2318 gen_op_store_FT0_fpr(rd);
2319 break;
2320 case 0x46:
2321 gen_op_load_fpr_DT0(DFPREG(rs1));
2322 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2323 gen_clear_float_exceptions();
44e7757c 2324 tcg_gen_helper_0_0(helper_fsubd);
7e8c2b6c 2325 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2326 gen_op_store_DT0_fpr(DFPREG(rd));
2327 break;
2328 case 0x47: /* fsubq */
1f587329
BS
2329#if defined(CONFIG_USER_ONLY)
2330 gen_op_load_fpr_QT0(QFPREG(rs1));
2331 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2332 gen_clear_float_exceptions();
44e7757c 2333 tcg_gen_helper_0_0(helper_fsubq);
7e8c2b6c 2334 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2335 gen_op_store_QT0_fpr(QFPREG(rd));
2336 break;
2337#else
0f8a249a 2338 goto nfpu_insn;
1f587329 2339#endif
0f8a249a
BS
2340 case 0x49:
2341 gen_op_load_fpr_FT0(rs1);
2342 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2343 gen_clear_float_exceptions();
44e7757c 2344 tcg_gen_helper_0_0(helper_fmuls);
7e8c2b6c 2345 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2346 gen_op_store_FT0_fpr(rd);
2347 break;
2348 case 0x4a:
2349 gen_op_load_fpr_DT0(DFPREG(rs1));
2350 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2351 gen_clear_float_exceptions();
44e7757c 2352 tcg_gen_helper_0_0(helper_fmuld);
7e8c2b6c 2353 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2382dc6b 2354 gen_op_store_DT0_fpr(DFPREG(rd));
0f8a249a
BS
2355 break;
2356 case 0x4b: /* fmulq */
1f587329
BS
2357#if defined(CONFIG_USER_ONLY)
2358 gen_op_load_fpr_QT0(QFPREG(rs1));
2359 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2360 gen_clear_float_exceptions();
44e7757c 2361 tcg_gen_helper_0_0(helper_fmulq);
7e8c2b6c 2362 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2363 gen_op_store_QT0_fpr(QFPREG(rd));
2364 break;
2365#else
0f8a249a 2366 goto nfpu_insn;
1f587329 2367#endif
0f8a249a
BS
2368 case 0x4d:
2369 gen_op_load_fpr_FT0(rs1);
2370 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2371 gen_clear_float_exceptions();
44e7757c 2372 tcg_gen_helper_0_0(helper_fdivs);
7e8c2b6c 2373 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2374 gen_op_store_FT0_fpr(rd);
2375 break;
2376 case 0x4e:
2377 gen_op_load_fpr_DT0(DFPREG(rs1));
2378 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2379 gen_clear_float_exceptions();
44e7757c 2380 tcg_gen_helper_0_0(helper_fdivd);
7e8c2b6c 2381 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2382 gen_op_store_DT0_fpr(DFPREG(rd));
2383 break;
2384 case 0x4f: /* fdivq */
1f587329
BS
2385#if defined(CONFIG_USER_ONLY)
2386 gen_op_load_fpr_QT0(QFPREG(rs1));
2387 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2388 gen_clear_float_exceptions();
44e7757c 2389 tcg_gen_helper_0_0(helper_fdivq);
7e8c2b6c 2390 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2391 gen_op_store_QT0_fpr(QFPREG(rd));
2392 break;
2393#else
0f8a249a 2394 goto nfpu_insn;
1f587329 2395#endif
0f8a249a
BS
2396 case 0x69:
2397 gen_op_load_fpr_FT0(rs1);
2398 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2399 gen_clear_float_exceptions();
44e7757c 2400 tcg_gen_helper_0_0(helper_fsmuld);
7e8c2b6c 2401 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2402 gen_op_store_DT0_fpr(DFPREG(rd));
2403 break;
2404 case 0x6e: /* fdmulq */
1f587329
BS
2405#if defined(CONFIG_USER_ONLY)
2406 gen_op_load_fpr_DT0(DFPREG(rs1));
2407 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2408 gen_clear_float_exceptions();
44e7757c 2409 tcg_gen_helper_0_0(helper_fdmulq);
7e8c2b6c 2410 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2411 gen_op_store_QT0_fpr(QFPREG(rd));
2412 break;
2413#else
0f8a249a 2414 goto nfpu_insn;
1f587329 2415#endif
0f8a249a
BS
2416 case 0xc4:
2417 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2418 gen_clear_float_exceptions();
44e7757c 2419 tcg_gen_helper_0_0(helper_fitos);
7e8c2b6c 2420 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2421 gen_op_store_FT0_fpr(rd);
2422 break;
2423 case 0xc6:
2424 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2425 gen_clear_float_exceptions();
44e7757c 2426 tcg_gen_helper_0_0(helper_fdtos);
7e8c2b6c 2427 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2428 gen_op_store_FT0_fpr(rd);
2429 break;
2430 case 0xc7: /* fqtos */
1f587329
BS
2431#if defined(CONFIG_USER_ONLY)
2432 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2433 gen_clear_float_exceptions();
44e7757c 2434 tcg_gen_helper_0_0(helper_fqtos);
7e8c2b6c 2435 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2436 gen_op_store_FT0_fpr(rd);
2437 break;
2438#else
0f8a249a 2439 goto nfpu_insn;
1f587329 2440#endif
0f8a249a
BS
2441 case 0xc8:
2442 gen_op_load_fpr_FT1(rs2);
44e7757c 2443 tcg_gen_helper_0_0(helper_fitod);
0f8a249a
BS
2444 gen_op_store_DT0_fpr(DFPREG(rd));
2445 break;
2446 case 0xc9:
2447 gen_op_load_fpr_FT1(rs2);
44e7757c 2448 tcg_gen_helper_0_0(helper_fstod);
0f8a249a
BS
2449 gen_op_store_DT0_fpr(DFPREG(rd));
2450 break;
2451 case 0xcb: /* fqtod */
1f587329
BS
2452#if defined(CONFIG_USER_ONLY)
2453 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2454 gen_clear_float_exceptions();
44e7757c 2455 tcg_gen_helper_0_0(helper_fqtod);
7e8c2b6c 2456 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2457 gen_op_store_DT0_fpr(DFPREG(rd));
2458 break;
2459#else
0f8a249a 2460 goto nfpu_insn;
1f587329 2461#endif
0f8a249a 2462 case 0xcc: /* fitoq */
1f587329
BS
2463#if defined(CONFIG_USER_ONLY)
2464 gen_op_load_fpr_FT1(rs2);
44e7757c 2465 tcg_gen_helper_0_0(helper_fitoq);
1f587329
BS
2466 gen_op_store_QT0_fpr(QFPREG(rd));
2467 break;
2468#else
0f8a249a 2469 goto nfpu_insn;
1f587329 2470#endif
0f8a249a 2471 case 0xcd: /* fstoq */
1f587329
BS
2472#if defined(CONFIG_USER_ONLY)
2473 gen_op_load_fpr_FT1(rs2);
44e7757c 2474 tcg_gen_helper_0_0(helper_fstoq);
1f587329
BS
2475 gen_op_store_QT0_fpr(QFPREG(rd));
2476 break;
2477#else
0f8a249a 2478 goto nfpu_insn;
1f587329 2479#endif
0f8a249a 2480 case 0xce: /* fdtoq */
1f587329
BS
2481#if defined(CONFIG_USER_ONLY)
2482 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 2483 tcg_gen_helper_0_0(helper_fdtoq);
1f587329
BS
2484 gen_op_store_QT0_fpr(QFPREG(rd));
2485 break;
2486#else
0f8a249a 2487 goto nfpu_insn;
1f587329 2488#endif
0f8a249a
BS
2489 case 0xd1:
2490 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2491 gen_clear_float_exceptions();
44e7757c 2492 tcg_gen_helper_0_0(helper_fstoi);
7e8c2b6c 2493 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2494 gen_op_store_FT0_fpr(rd);
2495 break;
2496 case 0xd2:
2382dc6b 2497 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2498 gen_clear_float_exceptions();
44e7757c 2499 tcg_gen_helper_0_0(helper_fdtoi);
7e8c2b6c 2500 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2501 gen_op_store_FT0_fpr(rd);
2502 break;
2503 case 0xd3: /* fqtoi */
1f587329
BS
2504#if defined(CONFIG_USER_ONLY)
2505 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2506 gen_clear_float_exceptions();
44e7757c 2507 tcg_gen_helper_0_0(helper_fqtoi);
7e8c2b6c 2508 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2509 gen_op_store_FT0_fpr(rd);
2510 break;
2511#else
0f8a249a 2512 goto nfpu_insn;
1f587329 2513#endif
3475187d 2514#ifdef TARGET_SPARC64
0f8a249a
BS
2515 case 0x2: /* V9 fmovd */
2516 gen_op_load_fpr_DT0(DFPREG(rs2));
2517 gen_op_store_DT0_fpr(DFPREG(rd));
2518 break;
1f587329
BS
2519 case 0x3: /* V9 fmovq */
2520#if defined(CONFIG_USER_ONLY)
2521 gen_op_load_fpr_QT0(QFPREG(rs2));
2522 gen_op_store_QT0_fpr(QFPREG(rd));
2523 break;
2524#else
2525 goto nfpu_insn;
2526#endif
0f8a249a
BS
2527 case 0x6: /* V9 fnegd */
2528 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 2529 tcg_gen_helper_0_0(helper_fnegd);
0f8a249a
BS
2530 gen_op_store_DT0_fpr(DFPREG(rd));
2531 break;
1f587329
BS
2532 case 0x7: /* V9 fnegq */
2533#if defined(CONFIG_USER_ONLY)
2534 gen_op_load_fpr_QT1(QFPREG(rs2));
44e7757c 2535 tcg_gen_helper_0_0(helper_fnegq);
1f587329
BS
2536 gen_op_store_QT0_fpr(QFPREG(rd));
2537 break;
2538#else
2539 goto nfpu_insn;
2540#endif
0f8a249a
BS
2541 case 0xa: /* V9 fabsd */
2542 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2543 tcg_gen_helper_0_0(helper_fabsd);
0f8a249a
BS
2544 gen_op_store_DT0_fpr(DFPREG(rd));
2545 break;
1f587329
BS
2546 case 0xb: /* V9 fabsq */
2547#if defined(CONFIG_USER_ONLY)
2548 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2549 tcg_gen_helper_0_0(helper_fabsq);
1f587329
BS
2550 gen_op_store_QT0_fpr(QFPREG(rd));
2551 break;
2552#else
2553 goto nfpu_insn;
2554#endif
0f8a249a
BS
2555 case 0x81: /* V9 fstox */
2556 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2557 gen_clear_float_exceptions();
44e7757c 2558 tcg_gen_helper_0_0(helper_fstox);
7e8c2b6c 2559 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2560 gen_op_store_DT0_fpr(DFPREG(rd));
2561 break;
2562 case 0x82: /* V9 fdtox */
2563 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2564 gen_clear_float_exceptions();
44e7757c 2565 tcg_gen_helper_0_0(helper_fdtox);
7e8c2b6c 2566 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2567 gen_op_store_DT0_fpr(DFPREG(rd));
2568 break;
1f587329
BS
2569 case 0x83: /* V9 fqtox */
2570#if defined(CONFIG_USER_ONLY)
2571 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2572 gen_clear_float_exceptions();
44e7757c 2573 tcg_gen_helper_0_0(helper_fqtox);
7e8c2b6c 2574 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2575 gen_op_store_DT0_fpr(DFPREG(rd));
2576 break;
2577#else
2578 goto nfpu_insn;
2579#endif
0f8a249a
BS
2580 case 0x84: /* V9 fxtos */
2581 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2582 gen_clear_float_exceptions();
44e7757c 2583 tcg_gen_helper_0_0(helper_fxtos);
7e8c2b6c 2584 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2585 gen_op_store_FT0_fpr(rd);
2586 break;
2587 case 0x88: /* V9 fxtod */
2588 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2589 gen_clear_float_exceptions();
44e7757c 2590 tcg_gen_helper_0_0(helper_fxtod);
7e8c2b6c 2591 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
0f8a249a
BS
2592 gen_op_store_DT0_fpr(DFPREG(rd));
2593 break;
0f8a249a 2594 case 0x8c: /* V9 fxtoq */
1f587329
BS
2595#if defined(CONFIG_USER_ONLY)
2596 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2597 gen_clear_float_exceptions();
44e7757c 2598 tcg_gen_helper_0_0(helper_fxtoq);
7e8c2b6c 2599 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
1f587329
BS
2600 gen_op_store_QT0_fpr(QFPREG(rd));
2601 break;
2602#else
0f8a249a 2603 goto nfpu_insn;
1f587329 2604#endif
0f8a249a
BS
2605#endif
2606 default:
2607 goto illegal_insn;
2608 }
2609 } else if (xop == 0x35) { /* FPU Operations */
3475187d 2610#ifdef TARGET_SPARC64
0f8a249a 2611 int cond;
3475187d 2612#endif
6ae20372 2613 if (gen_trap_ifnofpu(dc, cpu_cond))
a80dde08 2614 goto jmp_insn;
0f8a249a 2615 gen_op_clear_ieee_excp_and_FTT();
cf495bcf 2616 rs1 = GET_FIELD(insn, 13, 17);
0f8a249a
BS
2617 rs2 = GET_FIELD(insn, 27, 31);
2618 xop = GET_FIELD(insn, 18, 26);
3475187d 2619#ifdef TARGET_SPARC64
0f8a249a 2620 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
dcf24905
BS
2621 int l1;
2622
2623 l1 = gen_new_label();
0f8a249a 2624 cond = GET_FIELD_SP(insn, 14, 17);
9322a4bf 2625 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372 2626 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
0425bee5 2627 tcg_const_tl(0), l1);
19f329ad 2628 gen_op_load_fpr_FT0(rs2);
0f8a249a 2629 gen_op_store_FT0_fpr(rd);
dcf24905 2630 gen_set_label(l1);
0f8a249a
BS
2631 break;
2632 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
dcf24905
BS
2633 int l1;
2634
2635 l1 = gen_new_label();
0f8a249a 2636 cond = GET_FIELD_SP(insn, 14, 17);
9322a4bf 2637 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372 2638 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
0425bee5 2639 tcg_const_tl(0), l1);
19f329ad 2640 gen_op_load_fpr_DT0(DFPREG(rs2));
2382dc6b 2641 gen_op_store_DT0_fpr(DFPREG(rd));
dcf24905 2642 gen_set_label(l1);
0f8a249a
BS
2643 break;
2644 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
1f587329 2645#if defined(CONFIG_USER_ONLY)
dcf24905
BS
2646 int l1;
2647
2648 l1 = gen_new_label();
1f587329 2649 cond = GET_FIELD_SP(insn, 14, 17);
9322a4bf 2650 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372 2651 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
0425bee5 2652 tcg_const_tl(0), l1);
19f329ad 2653 gen_op_load_fpr_QT0(QFPREG(rs2));
1f587329 2654 gen_op_store_QT0_fpr(QFPREG(rd));
dcf24905 2655 gen_set_label(l1);
1f587329
BS
2656 break;
2657#else
0f8a249a 2658 goto nfpu_insn;
1f587329 2659#endif
0f8a249a
BS
2660 }
2661#endif
2662 switch (xop) {
3475187d 2663#ifdef TARGET_SPARC64
19f329ad
BS
2664#define FMOVCC(size_FDQ, fcc) \
2665 { \
0425bee5 2666 TCGv r_cond; \
19f329ad
BS
2667 int l1; \
2668 \
2669 l1 = gen_new_label(); \
19f329ad 2670 r_cond = tcg_temp_new(TCG_TYPE_TL); \
19f329ad
BS
2671 cond = GET_FIELD_SP(insn, 14, 17); \
2672 gen_fcond(r_cond, fcc, cond); \
0425bee5
BS
2673 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2674 tcg_const_tl(0), l1); \
19f329ad
BS
2675 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2676 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2677 gen_set_label(l1); \
2678 }
0f8a249a 2679 case 0x001: /* V9 fmovscc %fcc0 */
19f329ad 2680 FMOVCC(F, 0);
0f8a249a
BS
2681 break;
2682 case 0x002: /* V9 fmovdcc %fcc0 */
19f329ad 2683 FMOVCC(D, 0);
0f8a249a
BS
2684 break;
2685 case 0x003: /* V9 fmovqcc %fcc0 */
1f587329 2686#if defined(CONFIG_USER_ONLY)
19f329ad 2687 FMOVCC(Q, 0);
1f587329
BS
2688 break;
2689#else
0f8a249a 2690 goto nfpu_insn;
1f587329 2691#endif
0f8a249a 2692 case 0x041: /* V9 fmovscc %fcc1 */
19f329ad 2693 FMOVCC(F, 1);
0f8a249a
BS
2694 break;
2695 case 0x042: /* V9 fmovdcc %fcc1 */
19f329ad 2696 FMOVCC(D, 1);
0f8a249a
BS
2697 break;
2698 case 0x043: /* V9 fmovqcc %fcc1 */
1f587329 2699#if defined(CONFIG_USER_ONLY)
19f329ad 2700 FMOVCC(Q, 1);
1f587329
BS
2701 break;
2702#else
0f8a249a 2703 goto nfpu_insn;
1f587329 2704#endif
0f8a249a 2705 case 0x081: /* V9 fmovscc %fcc2 */
19f329ad 2706 FMOVCC(F, 2);
0f8a249a
BS
2707 break;
2708 case 0x082: /* V9 fmovdcc %fcc2 */
19f329ad 2709 FMOVCC(D, 2);
0f8a249a
BS
2710 break;
2711 case 0x083: /* V9 fmovqcc %fcc2 */
1f587329 2712#if defined(CONFIG_USER_ONLY)
19f329ad 2713 FMOVCC(Q, 2);
1f587329
BS
2714 break;
2715#else
0f8a249a 2716 goto nfpu_insn;
1f587329 2717#endif
0f8a249a 2718 case 0x0c1: /* V9 fmovscc %fcc3 */
19f329ad 2719 FMOVCC(F, 3);
0f8a249a
BS
2720 break;
2721 case 0x0c2: /* V9 fmovdcc %fcc3 */
19f329ad 2722 FMOVCC(D, 3);
0f8a249a
BS
2723 break;
2724 case 0x0c3: /* V9 fmovqcc %fcc3 */
1f587329 2725#if defined(CONFIG_USER_ONLY)
19f329ad 2726 FMOVCC(Q, 3);
1f587329
BS
2727 break;
2728#else
0f8a249a 2729 goto nfpu_insn;
1f587329 2730#endif
19f329ad
BS
2731#undef FMOVCC
2732#define FMOVCC(size_FDQ, icc) \
2733 { \
0425bee5 2734 TCGv r_cond; \
19f329ad
BS
2735 int l1; \
2736 \
2737 l1 = gen_new_label(); \
19f329ad 2738 r_cond = tcg_temp_new(TCG_TYPE_TL); \
19f329ad
BS
2739 cond = GET_FIELD_SP(insn, 14, 17); \
2740 gen_cond(r_cond, icc, cond); \
0425bee5
BS
2741 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2742 tcg_const_tl(0), l1); \
19f329ad
BS
2743 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2744 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2745 gen_set_label(l1); \
2746 }
2747
0f8a249a 2748 case 0x101: /* V9 fmovscc %icc */
19f329ad 2749 FMOVCC(F, 0);
0f8a249a
BS
2750 break;
2751 case 0x102: /* V9 fmovdcc %icc */
19f329ad 2752 FMOVCC(D, 0);
0f8a249a 2753 case 0x103: /* V9 fmovqcc %icc */
1f587329 2754#if defined(CONFIG_USER_ONLY)
19f329ad 2755 FMOVCC(D, 0);
1f587329
BS
2756 break;
2757#else
0f8a249a 2758 goto nfpu_insn;
1f587329 2759#endif
0f8a249a 2760 case 0x181: /* V9 fmovscc %xcc */
19f329ad 2761 FMOVCC(F, 1);
0f8a249a
BS
2762 break;
2763 case 0x182: /* V9 fmovdcc %xcc */
19f329ad 2764 FMOVCC(D, 1);
0f8a249a
BS
2765 break;
2766 case 0x183: /* V9 fmovqcc %xcc */
1f587329 2767#if defined(CONFIG_USER_ONLY)
19f329ad 2768 FMOVCC(Q, 1);
1f587329
BS
2769 break;
2770#else
0f8a249a
BS
2771 goto nfpu_insn;
2772#endif
19f329ad 2773#undef FMOVCC
1f587329
BS
2774#endif
2775 case 0x51: /* fcmps, V9 %fcc */
0f8a249a
BS
2776 gen_op_load_fpr_FT0(rs1);
2777 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2778 gen_op_fcmps(rd & 3);
0f8a249a 2779 break;
1f587329 2780 case 0x52: /* fcmpd, V9 %fcc */
0f8a249a
BS
2781 gen_op_load_fpr_DT0(DFPREG(rs1));
2782 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2783 gen_op_fcmpd(rd & 3);
0f8a249a 2784 break;
1f587329
BS
2785 case 0x53: /* fcmpq, V9 %fcc */
2786#if defined(CONFIG_USER_ONLY)
2787 gen_op_load_fpr_QT0(QFPREG(rs1));
2788 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2789 gen_op_fcmpq(rd & 3);
1f587329
BS
2790 break;
2791#else /* !defined(CONFIG_USER_ONLY) */
0f8a249a 2792 goto nfpu_insn;
1f587329 2793#endif
0f8a249a
BS
2794 case 0x55: /* fcmpes, V9 %fcc */
2795 gen_op_load_fpr_FT0(rs1);
2796 gen_op_load_fpr_FT1(rs2);
7e8c2b6c 2797 gen_op_fcmpes(rd & 3);
0f8a249a
BS
2798 break;
2799 case 0x56: /* fcmped, V9 %fcc */
2800 gen_op_load_fpr_DT0(DFPREG(rs1));
2801 gen_op_load_fpr_DT1(DFPREG(rs2));
7e8c2b6c 2802 gen_op_fcmped(rd & 3);
0f8a249a 2803 break;
1f587329
BS
2804 case 0x57: /* fcmpeq, V9 %fcc */
2805#if defined(CONFIG_USER_ONLY)
2806 gen_op_load_fpr_QT0(QFPREG(rs1));
2807 gen_op_load_fpr_QT1(QFPREG(rs2));
7e8c2b6c 2808 gen_op_fcmpeq(rd & 3);
1f587329
BS
2809 break;
2810#else/* !defined(CONFIG_USER_ONLY) */
0f8a249a 2811 goto nfpu_insn;
1f587329 2812#endif
0f8a249a
BS
2813 default:
2814 goto illegal_insn;
2815 }
0f8a249a
BS
2816 } else if (xop == 0x2) {
2817 // clr/mov shortcut
e80cfcfc
FB
2818
2819 rs1 = GET_FIELD(insn, 13, 17);
0f8a249a 2820 if (rs1 == 0) {
1a2fb1c0 2821 // or %g0, x, y -> mov T0, x; mov y, T0
0f8a249a
BS
2822 if (IS_IMM) { /* immediate */
2823 rs2 = GET_FIELDs(insn, 19, 31);
6ae20372 2824 tcg_gen_movi_tl(cpu_dst, (int)rs2);
0f8a249a
BS
2825 } else { /* register */
2826 rs2 = GET_FIELD(insn, 27, 31);
6ae20372 2827 gen_movl_reg_TN(rs2, cpu_dst);
0f8a249a 2828 }
0f8a249a 2829 } else {
9322a4bf 2830 cpu_src1 = get_src1(insn, cpu_src1);
0f8a249a 2831 if (IS_IMM) { /* immediate */
0f8a249a 2832 rs2 = GET_FIELDs(insn, 19, 31);
6ae20372 2833 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
0f8a249a
BS
2834 } else { /* register */
2835 // or x, %g0, y -> mov T1, x; mov y, T1
2836 rs2 = GET_FIELD(insn, 27, 31);
2837 if (rs2 != 0) {
6ae20372
BS
2838 gen_movl_reg_TN(rs2, cpu_src2);
2839 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
6f551262
BS
2840 } else
2841 tcg_gen_mov_tl(cpu_dst, cpu_src1);
0f8a249a 2842 }
0f8a249a 2843 }
6ae20372 2844 gen_movl_TN_reg(rd, cpu_dst);
83469015 2845#ifdef TARGET_SPARC64
0f8a249a 2846 } else if (xop == 0x25) { /* sll, V9 sllx */
9322a4bf 2847 cpu_src1 = get_src1(insn, cpu_src1);
0f8a249a 2848 if (IS_IMM) { /* immediate */
83469015 2849 rs2 = GET_FIELDs(insn, 20, 31);
1a2fb1c0 2850 if (insn & (1 << 12)) {
6ae20372 2851 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
1a2fb1c0 2852 } else {
6ae20372
BS
2853 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2854 tcg_gen_shli_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
1a2fb1c0 2855 }
0f8a249a 2856 } else { /* register */
83469015 2857 rs2 = GET_FIELD(insn, 27, 31);
6ae20372 2858 gen_movl_reg_TN(rs2, cpu_src2);
1a2fb1c0 2859 if (insn & (1 << 12)) {
6ae20372
BS
2860 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2861 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
1a2fb1c0 2862 } else {
6ae20372
BS
2863 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2864 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2865 tcg_gen_shl_i64(cpu_dst, cpu_dst, cpu_tmp0);
1a2fb1c0 2866 }
83469015 2867 }
6ae20372 2868 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a 2869 } else if (xop == 0x26) { /* srl, V9 srlx */
9322a4bf 2870 cpu_src1 = get_src1(insn, cpu_src1);
0f8a249a 2871 if (IS_IMM) { /* immediate */
83469015 2872 rs2 = GET_FIELDs(insn, 20, 31);
1a2fb1c0 2873 if (insn & (1 << 12)) {
6ae20372 2874 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
1a2fb1c0 2875 } else {
6ae20372
BS
2876 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2877 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
1a2fb1c0 2878 }
0f8a249a 2879 } else { /* register */
83469015 2880 rs2 = GET_FIELD(insn, 27, 31);
6ae20372 2881 gen_movl_reg_TN(rs2, cpu_src2);
1a2fb1c0 2882 if (insn & (1 << 12)) {
6ae20372
BS
2883 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2884 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
1a2fb1c0 2885 } else {
6ae20372
BS
2886 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2887 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2888 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
1a2fb1c0 2889 }
83469015 2890 }
6ae20372 2891 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a 2892 } else if (xop == 0x27) { /* sra, V9 srax */
9322a4bf 2893 cpu_src1 = get_src1(insn, cpu_src1);
0f8a249a 2894 if (IS_IMM) { /* immediate */
83469015 2895 rs2 = GET_FIELDs(insn, 20, 31);
1a2fb1c0 2896 if (insn & (1 << 12)) {
6ae20372 2897 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
1a2fb1c0 2898 } else {
6ae20372
BS
2899 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2900 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2901 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
1a2fb1c0 2902 }
0f8a249a 2903 } else { /* register */
83469015 2904 rs2 = GET_FIELD(insn, 27, 31);
6ae20372 2905 gen_movl_reg_TN(rs2, cpu_src2);
1a2fb1c0 2906 if (insn & (1 << 12)) {
6ae20372
BS
2907 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2908 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
1a2fb1c0 2909 } else {
6ae20372
BS
2910 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2911 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2912 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
1a2fb1c0 2913 }
83469015 2914 }
6ae20372 2915 gen_movl_TN_reg(rd, cpu_dst);
e80cfcfc 2916#endif
fcc72045 2917 } else if (xop < 0x36) {
9322a4bf 2918 cpu_src1 = get_src1(insn, cpu_src1);
a49d9390 2919 cpu_src2 = get_src2(insn, cpu_src2);
cf495bcf
FB
2920 if (xop < 0x20) {
2921 switch (xop & ~0x10) {
2922 case 0x0:
2923 if (xop & 0x10)
6ae20372 2924 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
cf495bcf 2925 else
6ae20372 2926 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
cf495bcf
FB
2927 break;
2928 case 0x1:
6ae20372 2929 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
cf495bcf 2930 if (xop & 0x10)
6ae20372 2931 gen_op_logic_cc(cpu_dst);
cf495bcf
FB
2932 break;
2933 case 0x2:
6ae20372 2934 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
0f8a249a 2935 if (xop & 0x10)
6ae20372 2936 gen_op_logic_cc(cpu_dst);
0f8a249a 2937 break;
cf495bcf 2938 case 0x3:
6ae20372 2939 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
cf495bcf 2940 if (xop & 0x10)
6ae20372 2941 gen_op_logic_cc(cpu_dst);
cf495bcf
FB
2942 break;
2943 case 0x4:
2944 if (xop & 0x10)
6ae20372 2945 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
cf495bcf 2946 else
6ae20372 2947 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
cf495bcf
FB
2948 break;
2949 case 0x5:
6ae20372
BS
2950 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2951 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
cf495bcf 2952 if (xop & 0x10)
6ae20372 2953 gen_op_logic_cc(cpu_dst);
cf495bcf
FB
2954 break;
2955 case 0x6:
6ae20372
BS
2956 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2957 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
cf495bcf 2958 if (xop & 0x10)
6ae20372 2959 gen_op_logic_cc(cpu_dst);
cf495bcf
FB
2960 break;
2961 case 0x7:
6ae20372
BS
2962 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2963 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
cf495bcf 2964 if (xop & 0x10)
6ae20372 2965 gen_op_logic_cc(cpu_dst);
cf495bcf
FB
2966 break;
2967 case 0x8:
cf495bcf 2968 if (xop & 0x10)
6ae20372 2969 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
38bc628b 2970 else {
dc99a3f2 2971 gen_mov_reg_C(cpu_tmp0, cpu_psr);
6ae20372
BS
2972 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
2973 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
38bc628b 2974 }
cf495bcf 2975 break;
ded3ab80 2976#ifdef TARGET_SPARC64
0f8a249a 2977 case 0x9: /* V9 mulx */
6ae20372 2978 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
ded3ab80
PB
2979 break;
2980#endif
cf495bcf 2981 case 0xa:
6ae20372 2982 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
cf495bcf 2983 if (xop & 0x10)
6ae20372 2984 gen_op_logic_cc(cpu_dst);
cf495bcf
FB
2985 break;
2986 case 0xb:
6ae20372 2987 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
cf495bcf 2988 if (xop & 0x10)
6ae20372 2989 gen_op_logic_cc(cpu_dst);
cf495bcf
FB
2990 break;
2991 case 0xc:
cf495bcf 2992 if (xop & 0x10)
6ae20372 2993 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
38bc628b 2994 else {
dc99a3f2 2995 gen_mov_reg_C(cpu_tmp0, cpu_psr);
6ae20372
BS
2996 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
2997 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
38bc628b 2998 }
cf495bcf 2999 break;
ded3ab80 3000#ifdef TARGET_SPARC64
0f8a249a 3001 case 0xd: /* V9 udivx */
6ae20372
BS
3002 gen_trap_ifdivzero_tl(cpu_src2);
3003 tcg_gen_divu_i64(cpu_dst, cpu_src1, cpu_src2);
ded3ab80
PB
3004 break;
3005#endif
cf495bcf 3006 case 0xe:
6ae20372 3007 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1, cpu_src2);
cf495bcf 3008 if (xop & 0x10)
6ae20372 3009 gen_op_div_cc(cpu_dst);
cf495bcf
FB
3010 break;
3011 case 0xf:
6ae20372 3012 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1, cpu_src2);
cf495bcf 3013 if (xop & 0x10)
6ae20372 3014 gen_op_div_cc(cpu_dst);
cf495bcf
FB
3015 break;
3016 default:
3017 goto illegal_insn;
3018 }
6ae20372 3019 gen_movl_TN_reg(rd, cpu_dst);
cf495bcf
FB
3020 } else {
3021 switch (xop) {
0f8a249a 3022 case 0x20: /* taddcc */
6ae20372
BS
3023 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3024 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a
BS
3025 break;
3026 case 0x21: /* tsubcc */
6ae20372
BS
3027 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3028 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a
BS
3029 break;
3030 case 0x22: /* taddcctv */
6ae20372
BS
3031 save_state(dc, cpu_cond);
3032 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3033 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a
BS
3034 break;
3035 case 0x23: /* tsubcctv */
6ae20372
BS
3036 save_state(dc, cpu_cond);
3037 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3038 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a 3039 break;
cf495bcf 3040 case 0x24: /* mulscc */
6ae20372
BS
3041 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3042 gen_movl_TN_reg(rd, cpu_dst);
cf495bcf 3043 break;
83469015 3044#ifndef TARGET_SPARC64
0f8a249a 3045 case 0x25: /* sll */
6ae20372
BS
3046 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3047 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3048 gen_movl_TN_reg(rd, cpu_dst);
cf495bcf 3049 break;
83469015 3050 case 0x26: /* srl */
6ae20372
BS
3051 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3052 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3053 gen_movl_TN_reg(rd, cpu_dst);
cf495bcf 3054 break;
83469015 3055 case 0x27: /* sra */
6ae20372
BS
3056 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3057 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3058 gen_movl_TN_reg(rd, cpu_dst);
cf495bcf 3059 break;
83469015 3060#endif
cf495bcf
FB
3061 case 0x30:
3062 {
cf495bcf 3063 switch(rd) {
3475187d 3064 case 0: /* wry */
6ae20372
BS
3065 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3066 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
cf495bcf 3067 break;
65fe7b09
BS
3068#ifndef TARGET_SPARC64
3069 case 0x01 ... 0x0f: /* undefined in the
3070 SPARCv8 manual, nop
3071 on the microSPARC
3072 II */
3073 case 0x10 ... 0x1f: /* implementation-dependent
3074 in the SPARCv8
3075 manual, nop on the
3076 microSPARC II */
3077 break;
3078#else
0f8a249a 3079 case 0x2: /* V9 wrccr */
6ae20372
BS
3080 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3081 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
0f8a249a
BS
3082 break;
3083 case 0x3: /* V9 wrasi */
6ae20372
BS
3084 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3085 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3086 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
0f8a249a
BS
3087 break;
3088 case 0x6: /* V9 wrfprs */
6ae20372
BS
3089 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3090 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3091 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
6ae20372 3092 save_state(dc, cpu_cond);
3299908c 3093 gen_op_next_insn();
57fec1fe 3094 tcg_gen_exit_tb(0);
3299908c 3095 dc->is_br = 1;
0f8a249a
BS
3096 break;
3097 case 0xf: /* V9 sir, nop if user */
3475187d 3098#if !defined(CONFIG_USER_ONLY)
0f8a249a 3099 if (supervisor(dc))
1a2fb1c0 3100 ; // XXX
3475187d 3101#endif
0f8a249a
BS
3102 break;
3103 case 0x13: /* Graphics Status */
6ae20372 3104 if (gen_trap_ifnofpu(dc, cpu_cond))
725cb90b 3105 goto jmp_insn;
6ae20372
BS
3106 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3107 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
0f8a249a
BS
3108 break;
3109 case 0x17: /* Tick compare */
83469015 3110#if !defined(CONFIG_USER_ONLY)
0f8a249a
BS
3111 if (!supervisor(dc))
3112 goto illegal_insn;
83469015 3113#endif
ccd4a219
BS
3114 {
3115 TCGv r_tickptr;
3116
6ae20372
BS
3117 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3118 cpu_src2);
3119 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
ccd4a219
BS
3120 tick_cmpr));
3121 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3122 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3123 offsetof(CPUState, tick));
3124 tcg_gen_helper_0_2(helper_tick_set_limit,
6ae20372 3125 r_tickptr, cpu_dst);
ccd4a219 3126 }
0f8a249a
BS
3127 break;
3128 case 0x18: /* System tick */
83469015 3129#if !defined(CONFIG_USER_ONLY)
0f8a249a
BS
3130 if (!supervisor(dc))
3131 goto illegal_insn;
83469015 3132#endif
ccd4a219
BS
3133 {
3134 TCGv r_tickptr;
3135
6ae20372
BS
3136 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3137 cpu_src2);
ccd4a219
BS
3138 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3139 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3140 offsetof(CPUState, stick));
3141 tcg_gen_helper_0_2(helper_tick_set_count,
6ae20372 3142 r_tickptr, cpu_dst);
ccd4a219 3143 }
0f8a249a
BS
3144 break;
3145 case 0x19: /* System tick compare */
83469015 3146#if !defined(CONFIG_USER_ONLY)
0f8a249a
BS
3147 if (!supervisor(dc))
3148 goto illegal_insn;
3475187d 3149#endif
ccd4a219
BS
3150 {
3151 TCGv r_tickptr;
3152
6ae20372
BS
3153 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3154 cpu_src2);
3155 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
ccd4a219
BS
3156 stick_cmpr));
3157 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3158 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3159 offsetof(CPUState, stick));
3160 tcg_gen_helper_0_2(helper_tick_set_limit,
6ae20372 3161 r_tickptr, cpu_dst);
ccd4a219 3162 }
0f8a249a 3163 break;
83469015 3164
0f8a249a
BS
3165 case 0x10: /* Performance Control */
3166 case 0x11: /* Performance Instrumentation Counter */
3167 case 0x12: /* Dispatch Control */
3168 case 0x14: /* Softint set */
3169 case 0x15: /* Softint clear */
3170 case 0x16: /* Softint write */
83469015 3171#endif
3475187d 3172 default:
cf495bcf
FB
3173 goto illegal_insn;
3174 }
3175 }
3176 break;
e8af50a3 3177#if !defined(CONFIG_USER_ONLY)
af7bf89b 3178 case 0x31: /* wrpsr, V9 saved, restored */
e8af50a3 3179 {
0f8a249a
BS
3180 if (!supervisor(dc))
3181 goto priv_insn;
3475187d 3182#ifdef TARGET_SPARC64
0f8a249a
BS
3183 switch (rd) {
3184 case 0:
72a9747b 3185 tcg_gen_helper_0_0(helper_saved);
0f8a249a
BS
3186 break;
3187 case 1:
72a9747b 3188 tcg_gen_helper_0_0(helper_restored);
0f8a249a 3189 break;
e9ebed4d
BS
3190 case 2: /* UA2005 allclean */
3191 case 3: /* UA2005 otherw */
3192 case 4: /* UA2005 normalw */
3193 case 5: /* UA2005 invalw */
3194 // XXX
0f8a249a 3195 default:
3475187d
FB
3196 goto illegal_insn;
3197 }
3198#else
6ae20372
BS
3199 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3200 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3201 save_state(dc, cpu_cond);
9e61bde5 3202 gen_op_next_insn();
57fec1fe 3203 tcg_gen_exit_tb(0);
0f8a249a 3204 dc->is_br = 1;
3475187d 3205#endif
e8af50a3
FB
3206 }
3207 break;
af7bf89b 3208 case 0x32: /* wrwim, V9 wrpr */
e8af50a3 3209 {
0f8a249a
BS
3210 if (!supervisor(dc))
3211 goto priv_insn;
6ae20372 3212 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3475187d 3213#ifdef TARGET_SPARC64
0f8a249a
BS
3214 switch (rd) {
3215 case 0: // tpc
375ee38b
BS
3216 {
3217 TCGv r_tsptr;
3218
3219 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3220 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3221 offsetof(CPUState, tsptr));
6ae20372 3222 tcg_gen_st_tl(cpu_dst, r_tsptr,
375ee38b
BS
3223 offsetof(trap_state, tpc));
3224 }
0f8a249a
BS
3225 break;
3226 case 1: // tnpc
375ee38b
BS
3227 {
3228 TCGv r_tsptr;
3229
3230 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3231 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3232 offsetof(CPUState, tsptr));
6ae20372 3233 tcg_gen_st_tl(cpu_dst, r_tsptr,
375ee38b
BS
3234 offsetof(trap_state, tnpc));
3235 }
0f8a249a
BS
3236 break;
3237 case 2: // tstate
375ee38b
BS
3238 {
3239 TCGv r_tsptr;
3240
3241 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3242 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3243 offsetof(CPUState, tsptr));
6ae20372 3244 tcg_gen_st_tl(cpu_dst, r_tsptr,
375ee38b
BS
3245 offsetof(trap_state, tstate));
3246 }
0f8a249a
BS
3247 break;
3248 case 3: // tt
375ee38b
BS
3249 {
3250 TCGv r_tsptr;
3251
3252 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3253 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3254 offsetof(CPUState, tsptr));
6ae20372 3255 tcg_gen_st_i32(cpu_dst, r_tsptr,
375ee38b
BS
3256 offsetof(trap_state, tt));
3257 }
0f8a249a
BS
3258 break;
3259 case 4: // tick
ccd4a219
BS
3260 {
3261 TCGv r_tickptr;
3262
3263 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3264 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3265 offsetof(CPUState, tick));
3266 tcg_gen_helper_0_2(helper_tick_set_count,
6ae20372 3267 r_tickptr, cpu_dst);
ccd4a219 3268 }
0f8a249a
BS
3269 break;
3270 case 5: // tba
6ae20372 3271 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
0f8a249a
BS
3272 break;
3273 case 6: // pstate
6ae20372
BS
3274 save_state(dc, cpu_cond);
3275 tcg_gen_helper_0_1(helper_wrpstate, cpu_dst);
ded3ab80 3276 gen_op_next_insn();
57fec1fe 3277 tcg_gen_exit_tb(0);
ded3ab80 3278 dc->is_br = 1;
0f8a249a
BS
3279 break;
3280 case 7: // tl
6ae20372 3281 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3282 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
0f8a249a
BS
3283 break;
3284 case 8: // pil
6ae20372 3285 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3286 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
0f8a249a
BS
3287 break;
3288 case 9: // cwp
6ae20372 3289 tcg_gen_helper_0_1(helper_wrcwp, cpu_dst);
0f8a249a
BS
3290 break;
3291 case 10: // cansave
6ae20372 3292 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3293 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
0f8a249a
BS
3294 break;
3295 case 11: // canrestore
6ae20372 3296 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3297 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
0f8a249a
BS
3298 break;
3299 case 12: // cleanwin
6ae20372 3300 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3301 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
0f8a249a
BS
3302 break;
3303 case 13: // otherwin
6ae20372 3304 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3305 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
0f8a249a
BS
3306 break;
3307 case 14: // wstate
6ae20372 3308 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3309 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
0f8a249a 3310 break;
e9ebed4d 3311 case 16: // UA2005 gl
6ae20372 3312 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3313 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
e9ebed4d
BS
3314 break;
3315 case 26: // UA2005 strand status
3316 if (!hypervisor(dc))
3317 goto priv_insn;
6ae20372 3318 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3319 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
e9ebed4d 3320 break;
0f8a249a
BS
3321 default:
3322 goto illegal_insn;
3323 }
3475187d 3324#else
6ae20372
BS
3325 tcg_gen_andi_tl(cpu_dst, cpu_dst, ((1 << NWINDOWS) - 1));
3326 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3327 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
3475187d 3328#endif
e8af50a3
FB
3329 }
3330 break;
e9ebed4d 3331 case 0x33: /* wrtbr, UA2005 wrhpr */
e8af50a3 3332 {
e9ebed4d 3333#ifndef TARGET_SPARC64
0f8a249a
BS
3334 if (!supervisor(dc))
3335 goto priv_insn;
6ae20372
BS
3336 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3337 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
e9ebed4d
BS
3338#else
3339 if (!hypervisor(dc))
3340 goto priv_insn;
6ae20372 3341 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
e9ebed4d
BS
3342 switch (rd) {
3343 case 0: // hpstate
3344 // XXX gen_op_wrhpstate();
6ae20372 3345 save_state(dc, cpu_cond);
e9ebed4d 3346 gen_op_next_insn();
57fec1fe 3347 tcg_gen_exit_tb(0);
e9ebed4d
BS
3348 dc->is_br = 1;
3349 break;
3350 case 1: // htstate
3351 // XXX gen_op_wrhtstate();
3352 break;
3353 case 3: // hintp
6ae20372 3354 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3355 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
e9ebed4d
BS
3356 break;
3357 case 5: // htba
6ae20372 3358 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2f5680ee 3359 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
e9ebed4d
BS
3360 break;
3361 case 31: // hstick_cmpr
ccd4a219
BS
3362 {
3363 TCGv r_tickptr;
3364
6ae20372 3365 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
ccd4a219
BS
3366 hstick_cmpr));
3367 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3368 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3369 offsetof(CPUState, hstick));
3370 tcg_gen_helper_0_2(helper_tick_set_limit,
6ae20372 3371 r_tickptr, cpu_dst);
ccd4a219 3372 }
e9ebed4d
BS
3373 break;
3374 case 6: // hver readonly
3375 default:
3376 goto illegal_insn;
3377 }
3378#endif
e8af50a3
FB
3379 }
3380 break;
3381#endif
3475187d 3382#ifdef TARGET_SPARC64
0f8a249a
BS
3383 case 0x2c: /* V9 movcc */
3384 {
3385 int cc = GET_FIELD_SP(insn, 11, 12);
3386 int cond = GET_FIELD_SP(insn, 14, 17);
748b9d8e 3387 TCGv r_cond;
00f219bf
BS
3388 int l1;
3389
748b9d8e 3390 r_cond = tcg_temp_new(TCG_TYPE_TL);
0f8a249a
BS
3391 if (insn & (1 << 18)) {
3392 if (cc == 0)
748b9d8e 3393 gen_cond(r_cond, 0, cond);
0f8a249a 3394 else if (cc == 2)
748b9d8e 3395 gen_cond(r_cond, 1, cond);
0f8a249a
BS
3396 else
3397 goto illegal_insn;
3398 } else {
748b9d8e 3399 gen_fcond(r_cond, cc, cond);
0f8a249a 3400 }
00f219bf
BS
3401
3402 l1 = gen_new_label();
3403
748b9d8e
BS
3404 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond,
3405 tcg_const_tl(0), l1);
00f219bf
BS
3406 if (IS_IMM) { /* immediate */
3407 rs2 = GET_FIELD_SPs(insn, 0, 10);
6ae20372 3408 tcg_gen_movi_tl(cpu_dst, (int)rs2);
00f219bf
BS
3409 } else {
3410 rs2 = GET_FIELD_SP(insn, 0, 4);
6ae20372 3411 gen_movl_reg_TN(rs2, cpu_dst);
00f219bf 3412 }
6ae20372 3413 gen_movl_TN_reg(rd, cpu_dst);
00f219bf 3414 gen_set_label(l1);
0f8a249a
BS
3415 break;
3416 }
3417 case 0x2d: /* V9 sdivx */
6ae20372
BS
3418 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3419 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a
BS
3420 break;
3421 case 0x2e: /* V9 popc */
3422 {
a49d9390 3423 cpu_src2 = get_src2(insn, cpu_src2);
6ae20372
BS
3424 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3425 cpu_src2);
3426 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a
BS
3427 }
3428 case 0x2f: /* V9 movr */
3429 {
3430 int cond = GET_FIELD_SP(insn, 10, 12);
00f219bf
BS
3431 int l1;
3432
9322a4bf 3433 cpu_src1 = get_src1(insn, cpu_src1);
00f219bf
BS
3434
3435 l1 = gen_new_label();
3436
6ae20372 3437 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
0425bee5 3438 tcg_const_tl(0), l1);
0f8a249a
BS
3439 if (IS_IMM) { /* immediate */
3440 rs2 = GET_FIELD_SPs(insn, 0, 9);
6ae20372 3441 tcg_gen_movi_tl(cpu_dst, (int)rs2);
00f219bf 3442 } else {
0f8a249a 3443 rs2 = GET_FIELD_SP(insn, 0, 4);
6ae20372 3444 gen_movl_reg_TN(rs2, cpu_dst);
0f8a249a 3445 }
6ae20372 3446 gen_movl_TN_reg(rd, cpu_dst);
00f219bf 3447 gen_set_label(l1);
0f8a249a
BS
3448 break;
3449 }
3450#endif
3451 default:
3452 goto illegal_insn;
3453 }
3454 }
3299908c
BS
3455 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3456#ifdef TARGET_SPARC64
3457 int opf = GET_FIELD_SP(insn, 5, 13);
3458 rs1 = GET_FIELD(insn, 13, 17);
3459 rs2 = GET_FIELD(insn, 27, 31);
6ae20372 3460 if (gen_trap_ifnofpu(dc, cpu_cond))
e9ebed4d 3461 goto jmp_insn;
3299908c
BS
3462
3463 switch (opf) {
e9ebed4d
BS
3464 case 0x000: /* VIS I edge8cc */
3465 case 0x001: /* VIS II edge8n */
3466 case 0x002: /* VIS I edge8lcc */
3467 case 0x003: /* VIS II edge8ln */
3468 case 0x004: /* VIS I edge16cc */
3469 case 0x005: /* VIS II edge16n */
3470 case 0x006: /* VIS I edge16lcc */
3471 case 0x007: /* VIS II edge16ln */
3472 case 0x008: /* VIS I edge32cc */
3473 case 0x009: /* VIS II edge32n */
3474 case 0x00a: /* VIS I edge32lcc */
3475 case 0x00b: /* VIS II edge32ln */
3476 // XXX
3477 goto illegal_insn;
3478 case 0x010: /* VIS I array8 */
9322a4bf 3479 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372
BS
3480 gen_movl_reg_TN(rs2, cpu_src2);
3481 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3482 cpu_src2);
3483 gen_movl_TN_reg(rd, cpu_dst);
e9ebed4d
BS
3484 break;
3485 case 0x012: /* VIS I array16 */
9322a4bf 3486 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372
BS
3487 gen_movl_reg_TN(rs2, cpu_src2);
3488 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3489 cpu_src2);
3490 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3491 gen_movl_TN_reg(rd, cpu_dst);
e9ebed4d
BS
3492 break;
3493 case 0x014: /* VIS I array32 */
9322a4bf 3494 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372
BS
3495 gen_movl_reg_TN(rs2, cpu_src2);
3496 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3497 cpu_src2);
3498 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3499 gen_movl_TN_reg(rd, cpu_dst);
e9ebed4d 3500 break;
3299908c 3501 case 0x018: /* VIS I alignaddr */
9322a4bf 3502 cpu_src1 = get_src1(insn, cpu_src1);
6ae20372
BS
3503 gen_movl_reg_TN(rs2, cpu_src2);
3504 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3505 cpu_src2);
3506 gen_movl_TN_reg(rd, cpu_dst);
3299908c 3507 break;
e9ebed4d 3508 case 0x019: /* VIS II bmask */
3299908c 3509 case 0x01a: /* VIS I alignaddrl */
3299908c 3510 // XXX
e9ebed4d
BS
3511 goto illegal_insn;
3512 case 0x020: /* VIS I fcmple16 */
2382dc6b
BS
3513 gen_op_load_fpr_DT0(DFPREG(rs1));
3514 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3515 tcg_gen_helper_0_0(helper_fcmple16);
2382dc6b 3516 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3517 break;
3518 case 0x022: /* VIS I fcmpne16 */
2382dc6b
BS
3519 gen_op_load_fpr_DT0(DFPREG(rs1));
3520 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3521 tcg_gen_helper_0_0(helper_fcmpne16);
2382dc6b 3522 gen_op_store_DT0_fpr(DFPREG(rd));
3299908c 3523 break;
e9ebed4d 3524 case 0x024: /* VIS I fcmple32 */
2382dc6b
BS
3525 gen_op_load_fpr_DT0(DFPREG(rs1));
3526 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3527 tcg_gen_helper_0_0(helper_fcmple32);
2382dc6b 3528 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3529 break;
3530 case 0x026: /* VIS I fcmpne32 */
2382dc6b
BS
3531 gen_op_load_fpr_DT0(DFPREG(rs1));
3532 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3533 tcg_gen_helper_0_0(helper_fcmpne32);
2382dc6b 3534 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3535 break;
3536 case 0x028: /* VIS I fcmpgt16 */
2382dc6b
BS
3537 gen_op_load_fpr_DT0(DFPREG(rs1));
3538 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3539 tcg_gen_helper_0_0(helper_fcmpgt16);
2382dc6b 3540 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3541 break;
3542 case 0x02a: /* VIS I fcmpeq16 */
2382dc6b
BS
3543 gen_op_load_fpr_DT0(DFPREG(rs1));
3544 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3545 tcg_gen_helper_0_0(helper_fcmpeq16);
2382dc6b 3546 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3547 break;
3548 case 0x02c: /* VIS I fcmpgt32 */
2382dc6b
BS
3549 gen_op_load_fpr_DT0(DFPREG(rs1));
3550 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3551 tcg_gen_helper_0_0(helper_fcmpgt32);
2382dc6b 3552 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3553 break;
3554 case 0x02e: /* VIS I fcmpeq32 */
2382dc6b
BS
3555 gen_op_load_fpr_DT0(DFPREG(rs1));
3556 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3557 tcg_gen_helper_0_0(helper_fcmpeq32);
2382dc6b 3558 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3559 break;
3560 case 0x031: /* VIS I fmul8x16 */
2382dc6b
BS
3561 gen_op_load_fpr_DT0(DFPREG(rs1));
3562 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3563 tcg_gen_helper_0_0(helper_fmul8x16);
2382dc6b 3564 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3565 break;
3566 case 0x033: /* VIS I fmul8x16au */
2382dc6b
BS
3567 gen_op_load_fpr_DT0(DFPREG(rs1));
3568 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3569 tcg_gen_helper_0_0(helper_fmul8x16au);
2382dc6b 3570 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3571 break;
3572 case 0x035: /* VIS I fmul8x16al */
2382dc6b
BS
3573 gen_op_load_fpr_DT0(DFPREG(rs1));
3574 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3575 tcg_gen_helper_0_0(helper_fmul8x16al);
2382dc6b 3576 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3577 break;
3578 case 0x036: /* VIS I fmul8sux16 */
2382dc6b
BS
3579 gen_op_load_fpr_DT0(DFPREG(rs1));
3580 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3581 tcg_gen_helper_0_0(helper_fmul8sux16);
2382dc6b 3582 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3583 break;
3584 case 0x037: /* VIS I fmul8ulx16 */
2382dc6b
BS
3585 gen_op_load_fpr_DT0(DFPREG(rs1));
3586 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3587 tcg_gen_helper_0_0(helper_fmul8ulx16);
2382dc6b 3588 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3589 break;
3590 case 0x038: /* VIS I fmuld8sux16 */
2382dc6b
BS
3591 gen_op_load_fpr_DT0(DFPREG(rs1));
3592 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3593 tcg_gen_helper_0_0(helper_fmuld8sux16);
2382dc6b 3594 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3595 break;
3596 case 0x039: /* VIS I fmuld8ulx16 */
2382dc6b
BS
3597 gen_op_load_fpr_DT0(DFPREG(rs1));
3598 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3599 tcg_gen_helper_0_0(helper_fmuld8ulx16);
2382dc6b 3600 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3601 break;
3602 case 0x03a: /* VIS I fpack32 */
3603 case 0x03b: /* VIS I fpack16 */
3604 case 0x03d: /* VIS I fpackfix */
3605 case 0x03e: /* VIS I pdist */
3606 // XXX
3607 goto illegal_insn;
3299908c 3608 case 0x048: /* VIS I faligndata */
2382dc6b
BS
3609 gen_op_load_fpr_DT0(DFPREG(rs1));
3610 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3611 tcg_gen_helper_0_0(helper_faligndata);
2382dc6b 3612 gen_op_store_DT0_fpr(DFPREG(rd));
3299908c 3613 break;
e9ebed4d 3614 case 0x04b: /* VIS I fpmerge */
2382dc6b
BS
3615 gen_op_load_fpr_DT0(DFPREG(rs1));
3616 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3617 tcg_gen_helper_0_0(helper_fpmerge);
2382dc6b 3618 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3619 break;
3620 case 0x04c: /* VIS II bshuffle */
3621 // XXX
3622 goto illegal_insn;
3623 case 0x04d: /* VIS I fexpand */
2382dc6b
BS
3624 gen_op_load_fpr_DT0(DFPREG(rs1));
3625 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3626 tcg_gen_helper_0_0(helper_fexpand);
2382dc6b 3627 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3628 break;
3629 case 0x050: /* VIS I fpadd16 */
2382dc6b
BS
3630 gen_op_load_fpr_DT0(DFPREG(rs1));
3631 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3632 tcg_gen_helper_0_0(helper_fpadd16);
2382dc6b 3633 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3634 break;
3635 case 0x051: /* VIS I fpadd16s */
3636 gen_op_load_fpr_FT0(rs1);
3637 gen_op_load_fpr_FT1(rs2);
44e7757c 3638 tcg_gen_helper_0_0(helper_fpadd16s);
e9ebed4d
BS
3639 gen_op_store_FT0_fpr(rd);
3640 break;
3641 case 0x052: /* VIS I fpadd32 */
2382dc6b
BS
3642 gen_op_load_fpr_DT0(DFPREG(rs1));
3643 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3644 tcg_gen_helper_0_0(helper_fpadd32);
2382dc6b 3645 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3646 break;
3647 case 0x053: /* VIS I fpadd32s */
3648 gen_op_load_fpr_FT0(rs1);
3649 gen_op_load_fpr_FT1(rs2);
44e7757c 3650 tcg_gen_helper_0_0(helper_fpadd32s);
e9ebed4d
BS
3651 gen_op_store_FT0_fpr(rd);
3652 break;
3653 case 0x054: /* VIS I fpsub16 */
2382dc6b
BS
3654 gen_op_load_fpr_DT0(DFPREG(rs1));
3655 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3656 tcg_gen_helper_0_0(helper_fpsub16);
2382dc6b 3657 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3658 break;
3659 case 0x055: /* VIS I fpsub16s */
3660 gen_op_load_fpr_FT0(rs1);
3661 gen_op_load_fpr_FT1(rs2);
44e7757c 3662 tcg_gen_helper_0_0(helper_fpsub16s);
e9ebed4d
BS
3663 gen_op_store_FT0_fpr(rd);
3664 break;
3665 case 0x056: /* VIS I fpsub32 */
2382dc6b
BS
3666 gen_op_load_fpr_DT0(DFPREG(rs1));
3667 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3668 tcg_gen_helper_0_0(helper_fpadd32);
2382dc6b 3669 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3670 break;
3671 case 0x057: /* VIS I fpsub32s */
3672 gen_op_load_fpr_FT0(rs1);
3673 gen_op_load_fpr_FT1(rs2);
44e7757c 3674 tcg_gen_helper_0_0(helper_fpsub32s);
e9ebed4d
BS
3675 gen_op_store_FT0_fpr(rd);
3676 break;
3299908c 3677 case 0x060: /* VIS I fzero */
44e7757c 3678 tcg_gen_helper_0_0(helper_movl_DT0_0);
2382dc6b 3679 gen_op_store_DT0_fpr(DFPREG(rd));
3299908c
BS
3680 break;
3681 case 0x061: /* VIS I fzeros */
44e7757c 3682 tcg_gen_helper_0_0(helper_movl_FT0_0);
3299908c
BS
3683 gen_op_store_FT0_fpr(rd);
3684 break;
e9ebed4d 3685 case 0x062: /* VIS I fnor */
2382dc6b
BS
3686 gen_op_load_fpr_DT0(DFPREG(rs1));
3687 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3688 tcg_gen_helper_0_0(helper_fnor);
2382dc6b 3689 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3690 break;
3691 case 0x063: /* VIS I fnors */
3692 gen_op_load_fpr_FT0(rs1);
3693 gen_op_load_fpr_FT1(rs2);
44e7757c 3694 tcg_gen_helper_0_0(helper_fnors);
e9ebed4d
BS
3695 gen_op_store_FT0_fpr(rd);
3696 break;
3697 case 0x064: /* VIS I fandnot2 */
2382dc6b
BS
3698 gen_op_load_fpr_DT1(DFPREG(rs1));
3699 gen_op_load_fpr_DT0(DFPREG(rs2));
44e7757c 3700 tcg_gen_helper_0_0(helper_fandnot);
2382dc6b 3701 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3702 break;
3703 case 0x065: /* VIS I fandnot2s */
3704 gen_op_load_fpr_FT1(rs1);
3705 gen_op_load_fpr_FT0(rs2);
44e7757c 3706 tcg_gen_helper_0_0(helper_fandnots);
e9ebed4d
BS
3707 gen_op_store_FT0_fpr(rd);
3708 break;
3709 case 0x066: /* VIS I fnot2 */
2382dc6b 3710 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3711 tcg_gen_helper_0_0(helper_fnot);
2382dc6b 3712 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3713 break;
3714 case 0x067: /* VIS I fnot2s */
3715 gen_op_load_fpr_FT1(rs2);
44e7757c 3716 tcg_gen_helper_0_0(helper_fnot);
e9ebed4d
BS
3717 gen_op_store_FT0_fpr(rd);
3718 break;
3719 case 0x068: /* VIS I fandnot1 */
2382dc6b
BS
3720 gen_op_load_fpr_DT0(DFPREG(rs1));
3721 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3722 tcg_gen_helper_0_0(helper_fandnot);
2382dc6b 3723 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3724 break;
3725 case 0x069: /* VIS I fandnot1s */
3726 gen_op_load_fpr_FT0(rs1);
3727 gen_op_load_fpr_FT1(rs2);
44e7757c 3728 tcg_gen_helper_0_0(helper_fandnots);
e9ebed4d
BS
3729 gen_op_store_FT0_fpr(rd);
3730 break;
3731 case 0x06a: /* VIS I fnot1 */
2382dc6b 3732 gen_op_load_fpr_DT1(DFPREG(rs1));
44e7757c 3733 tcg_gen_helper_0_0(helper_fnot);
2382dc6b 3734 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3735 break;
3736 case 0x06b: /* VIS I fnot1s */
3737 gen_op_load_fpr_FT1(rs1);
44e7757c 3738 tcg_gen_helper_0_0(helper_fnot);
e9ebed4d
BS
3739 gen_op_store_FT0_fpr(rd);
3740 break;
3741 case 0x06c: /* VIS I fxor */
2382dc6b
BS
3742 gen_op_load_fpr_DT0(DFPREG(rs1));
3743 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3744 tcg_gen_helper_0_0(helper_fxor);
2382dc6b 3745 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3746 break;
3747 case 0x06d: /* VIS I fxors */
3748 gen_op_load_fpr_FT0(rs1);
3749 gen_op_load_fpr_FT1(rs2);
44e7757c 3750 tcg_gen_helper_0_0(helper_fxors);
e9ebed4d
BS
3751 gen_op_store_FT0_fpr(rd);
3752 break;
3753 case 0x06e: /* VIS I fnand */
2382dc6b
BS
3754 gen_op_load_fpr_DT0(DFPREG(rs1));
3755 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3756 tcg_gen_helper_0_0(helper_fnand);
2382dc6b 3757 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3758 break;
3759 case 0x06f: /* VIS I fnands */
3760 gen_op_load_fpr_FT0(rs1);
3761 gen_op_load_fpr_FT1(rs2);
44e7757c 3762 tcg_gen_helper_0_0(helper_fnands);
e9ebed4d
BS
3763 gen_op_store_FT0_fpr(rd);
3764 break;
3765 case 0x070: /* VIS I fand */
2382dc6b
BS
3766 gen_op_load_fpr_DT0(DFPREG(rs1));
3767 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3768 tcg_gen_helper_0_0(helper_fand);
2382dc6b 3769 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3770 break;
3771 case 0x071: /* VIS I fands */
3772 gen_op_load_fpr_FT0(rs1);
3773 gen_op_load_fpr_FT1(rs2);
44e7757c 3774 tcg_gen_helper_0_0(helper_fands);
e9ebed4d
BS
3775 gen_op_store_FT0_fpr(rd);
3776 break;
3777 case 0x072: /* VIS I fxnor */
2382dc6b
BS
3778 gen_op_load_fpr_DT0(DFPREG(rs1));
3779 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3780 tcg_gen_helper_0_0(helper_fxnor);
2382dc6b 3781 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3782 break;
3783 case 0x073: /* VIS I fxnors */
3784 gen_op_load_fpr_FT0(rs1);
3785 gen_op_load_fpr_FT1(rs2);
44e7757c 3786 tcg_gen_helper_0_0(helper_fxnors);
e9ebed4d
BS
3787 gen_op_store_FT0_fpr(rd);
3788 break;
3299908c 3789 case 0x074: /* VIS I fsrc1 */
2382dc6b
BS
3790 gen_op_load_fpr_DT0(DFPREG(rs1));
3791 gen_op_store_DT0_fpr(DFPREG(rd));
3299908c
BS
3792 break;
3793 case 0x075: /* VIS I fsrc1s */
3299908c
BS
3794 gen_op_load_fpr_FT0(rs1);
3795 gen_op_store_FT0_fpr(rd);
3796 break;
e9ebed4d 3797 case 0x076: /* VIS I fornot2 */
2382dc6b
BS
3798 gen_op_load_fpr_DT1(DFPREG(rs1));
3799 gen_op_load_fpr_DT0(DFPREG(rs2));
44e7757c 3800 tcg_gen_helper_0_0(helper_fornot);
2382dc6b 3801 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3802 break;
3803 case 0x077: /* VIS I fornot2s */
3804 gen_op_load_fpr_FT1(rs1);
3805 gen_op_load_fpr_FT0(rs2);
44e7757c 3806 tcg_gen_helper_0_0(helper_fornots);
e9ebed4d
BS
3807 gen_op_store_FT0_fpr(rd);
3808 break;
3299908c 3809 case 0x078: /* VIS I fsrc2 */
2382dc6b
BS
3810 gen_op_load_fpr_DT0(DFPREG(rs2));
3811 gen_op_store_DT0_fpr(DFPREG(rd));
3299908c
BS
3812 break;
3813 case 0x079: /* VIS I fsrc2s */
3299908c
BS
3814 gen_op_load_fpr_FT0(rs2);
3815 gen_op_store_FT0_fpr(rd);
3816 break;
e9ebed4d 3817 case 0x07a: /* VIS I fornot1 */
2382dc6b
BS
3818 gen_op_load_fpr_DT0(DFPREG(rs1));
3819 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3820 tcg_gen_helper_0_0(helper_fornot);
2382dc6b 3821 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3822 break;
3823 case 0x07b: /* VIS I fornot1s */
3824 gen_op_load_fpr_FT0(rs1);
3825 gen_op_load_fpr_FT1(rs2);
44e7757c 3826 tcg_gen_helper_0_0(helper_fornots);
e9ebed4d
BS
3827 gen_op_store_FT0_fpr(rd);
3828 break;
3829 case 0x07c: /* VIS I for */
2382dc6b
BS
3830 gen_op_load_fpr_DT0(DFPREG(rs1));
3831 gen_op_load_fpr_DT1(DFPREG(rs2));
44e7757c 3832 tcg_gen_helper_0_0(helper_for);
2382dc6b 3833 gen_op_store_DT0_fpr(DFPREG(rd));
e9ebed4d
BS
3834 break;
3835 case 0x07d: /* VIS I fors */
3836 gen_op_load_fpr_FT0(rs1);
3837 gen_op_load_fpr_FT1(rs2);
44e7757c 3838 tcg_gen_helper_0_0(helper_fors);
e9ebed4d
BS
3839 gen_op_store_FT0_fpr(rd);
3840 break;
3299908c 3841 case 0x07e: /* VIS I fone */
44e7757c 3842 tcg_gen_helper_0_0(helper_movl_DT0_1);
2382dc6b 3843 gen_op_store_DT0_fpr(DFPREG(rd));
3299908c
BS
3844 break;
3845 case 0x07f: /* VIS I fones */
44e7757c 3846 tcg_gen_helper_0_0(helper_movl_FT0_1);
3299908c
BS
3847 gen_op_store_FT0_fpr(rd);
3848 break;
e9ebed4d
BS
3849 case 0x080: /* VIS I shutdown */
3850 case 0x081: /* VIS II siam */
3851 // XXX
3852 goto illegal_insn;
3299908c
BS
3853 default:
3854 goto illegal_insn;
3855 }
3856#else
0f8a249a 3857 goto ncp_insn;
3299908c
BS
3858#endif
3859 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
fcc72045 3860#ifdef TARGET_SPARC64
0f8a249a 3861 goto illegal_insn;
fcc72045 3862#else
0f8a249a 3863 goto ncp_insn;
fcc72045 3864#endif
3475187d 3865#ifdef TARGET_SPARC64
0f8a249a 3866 } else if (xop == 0x39) { /* V9 return */
6ae20372 3867 save_state(dc, cpu_cond);
9322a4bf 3868 cpu_src1 = get_src1(insn, cpu_src1);
0f8a249a
BS
3869 if (IS_IMM) { /* immediate */
3870 rs2 = GET_FIELDs(insn, 19, 31);
6ae20372 3871 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
0f8a249a 3872 } else { /* register */
3475187d 3873 rs2 = GET_FIELD(insn, 27, 31);
0f8a249a 3874 if (rs2) {
6ae20372
BS
3875 gen_movl_reg_TN(rs2, cpu_src2);
3876 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
6f551262
BS
3877 } else
3878 tcg_gen_mov_tl(cpu_dst, cpu_src1);
3475187d 3879 }
72a9747b 3880 tcg_gen_helper_0_0(helper_restore);
6ae20372
BS
3881 gen_mov_pc_npc(dc, cpu_cond);
3882 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3883 tcg_gen_mov_tl(cpu_npc, cpu_dst);
0f8a249a
BS
3884 dc->npc = DYNAMIC_PC;
3885 goto jmp_insn;
3475187d 3886#endif
0f8a249a 3887 } else {
9322a4bf 3888 cpu_src1 = get_src1(insn, cpu_src1);
0f8a249a
BS
3889 if (IS_IMM) { /* immediate */
3890 rs2 = GET_FIELDs(insn, 19, 31);
6ae20372 3891 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
0f8a249a 3892 } else { /* register */
e80cfcfc 3893 rs2 = GET_FIELD(insn, 27, 31);
0f8a249a 3894 if (rs2) {
6ae20372
BS
3895 gen_movl_reg_TN(rs2, cpu_src2);
3896 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
6f551262
BS
3897 } else
3898 tcg_gen_mov_tl(cpu_dst, cpu_src1);
cf495bcf 3899 }
0f8a249a
BS
3900 switch (xop) {
3901 case 0x38: /* jmpl */
3902 {
3903 if (rd != 0) {
32b6c812
BS
3904 tcg_gen_movi_tl(cpu_tmp0, dc->pc);
3905 gen_movl_TN_reg(rd, cpu_tmp0);
0f8a249a 3906 }
6ae20372
BS
3907 gen_mov_pc_npc(dc, cpu_cond);
3908 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3909 tcg_gen_mov_tl(cpu_npc, cpu_dst);
0f8a249a
BS
3910 dc->npc = DYNAMIC_PC;
3911 }
3912 goto jmp_insn;
3475187d 3913#if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
0f8a249a
BS
3914 case 0x39: /* rett, V9 return */
3915 {
3916 if (!supervisor(dc))
3917 goto priv_insn;
6ae20372
BS
3918 gen_mov_pc_npc(dc, cpu_cond);
3919 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3920 tcg_gen_mov_tl(cpu_npc, cpu_dst);
0f8a249a 3921 dc->npc = DYNAMIC_PC;
1a2fb1c0 3922 tcg_gen_helper_0_0(helper_rett);
0f8a249a
BS
3923 }
3924 goto jmp_insn;
3925#endif
3926 case 0x3b: /* flush */
6ae20372 3927 tcg_gen_helper_0_1(helper_flush, cpu_dst);
0f8a249a
BS
3928 break;
3929 case 0x3c: /* save */
6ae20372 3930 save_state(dc, cpu_cond);
72a9747b 3931 tcg_gen_helper_0_0(helper_save);
6ae20372 3932 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a
BS
3933 break;
3934 case 0x3d: /* restore */
6ae20372 3935 save_state(dc, cpu_cond);
72a9747b 3936 tcg_gen_helper_0_0(helper_restore);
6ae20372 3937 gen_movl_TN_reg(rd, cpu_dst);
0f8a249a 3938 break;
3475187d 3939#if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
0f8a249a
BS
3940 case 0x3e: /* V9 done/retry */
3941 {
3942 switch (rd) {
3943 case 0:
3944 if (!supervisor(dc))
3945 goto priv_insn;
3946 dc->npc = DYNAMIC_PC;
3947 dc->pc = DYNAMIC_PC;
1a2fb1c0 3948 tcg_gen_helper_0_0(helper_done);
0f8a249a
BS
3949 goto jmp_insn;
3950 case 1:
3951 if (!supervisor(dc))
3952 goto priv_insn;
3953 dc->npc = DYNAMIC_PC;
3954 dc->pc = DYNAMIC_PC;
1a2fb1c0 3955 tcg_gen_helper_0_0(helper_retry);
0f8a249a
BS
3956 goto jmp_insn;
3957 default:
3958 goto illegal_insn;
3959 }
3960 }
3961 break;
3962#endif
3963 default:
3964 goto illegal_insn;
3965 }
cf495bcf 3966 }
0f8a249a
BS
3967 break;
3968 }
3969 break;
3970 case 3: /* load/store instructions */
3971 {
3972 unsigned int xop = GET_FIELD(insn, 7, 12);
9322a4bf 3973
6ae20372 3974 save_state(dc, cpu_cond);
9322a4bf 3975 cpu_src1 = get_src1(insn, cpu_src1);
81ad8ba2
BS
3976 if (xop == 0x3c || xop == 0x3e)
3977 {
3978 rs2 = GET_FIELD(insn, 27, 31);
6ae20372 3979 gen_movl_reg_TN(rs2, cpu_src2);
81ad8ba2
BS
3980 }
3981 else if (IS_IMM) { /* immediate */
0f8a249a 3982 rs2 = GET_FIELDs(insn, 19, 31);
6ae20372 3983 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
0f8a249a
BS
3984 } else { /* register */
3985 rs2 = GET_FIELD(insn, 27, 31);
0f8a249a 3986 if (rs2 != 0) {
6ae20372
BS
3987 gen_movl_reg_TN(rs2, cpu_src2);
3988 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
6f551262
BS
3989 } else
3990 tcg_gen_mov_tl(cpu_addr, cpu_src1);
0f8a249a 3991 }
2f2ecb83
BS
3992 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
3993 (xop > 0x17 && xop <= 0x1d ) ||
3994 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
0f8a249a 3995 switch (xop) {
1a2fb1c0 3996 case 0x0: /* load unsigned word */
6ae20372
BS
3997 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
3998 ABI32_MASK(cpu_addr);
3999 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4000 break;
4001 case 0x1: /* load unsigned byte */
6ae20372
BS
4002 ABI32_MASK(cpu_addr);
4003 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4004 break;
4005 case 0x2: /* load unsigned halfword */
6ae20372
BS
4006 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4007 ABI32_MASK(cpu_addr);
4008 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4009 break;
4010 case 0x3: /* load double word */
0f8a249a 4011 if (rd & 1)
d4218d99 4012 goto illegal_insn;
1a2fb1c0 4013 else {
6ae20372
BS
4014 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4015 ABI32_MASK(cpu_addr);
4016 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
32b6c812
BS
4017 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4018 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4019 gen_movl_TN_reg(rd + 1, cpu_tmp0);
8911f501 4020 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
6ae20372
BS
4021 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4022 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
1a2fb1c0 4023 }
0f8a249a
BS
4024 break;
4025 case 0x9: /* load signed byte */
6ae20372
BS
4026 ABI32_MASK(cpu_addr);
4027 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4028 break;
4029 case 0xa: /* load signed halfword */
6ae20372
BS
4030 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4031 ABI32_MASK(cpu_addr);
4032 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4033 break;
4034 case 0xd: /* ldstub -- XXX: should be atomically */
6ae20372
BS
4035 ABI32_MASK(cpu_addr);
4036 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4037 tcg_gen_qemu_st8(tcg_const_tl(0xff), cpu_addr, dc->mem_idx);
0f8a249a
BS
4038 break;
4039 case 0x0f: /* swap register with memory. Also atomically */
6ae20372
BS
4040 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4041 gen_movl_reg_TN(rd, cpu_val);
4042 ABI32_MASK(cpu_addr);
4043 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4044 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4045 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
0f8a249a 4046 break;
3475187d 4047#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
0f8a249a 4048 case 0x10: /* load word alternate */
3475187d 4049#ifndef TARGET_SPARC64
0f8a249a
BS
4050 if (IS_IMM)
4051 goto illegal_insn;
4052 if (!supervisor(dc))
4053 goto priv_insn;
6ea4a6c8 4054#endif
6ae20372
BS
4055 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4056 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
0f8a249a
BS
4057 break;
4058 case 0x11: /* load unsigned byte alternate */
3475187d 4059#ifndef TARGET_SPARC64
0f8a249a
BS
4060 if (IS_IMM)
4061 goto illegal_insn;
4062 if (!supervisor(dc))
4063 goto priv_insn;
4064#endif
6ae20372 4065 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
0f8a249a
BS
4066 break;
4067 case 0x12: /* load unsigned halfword alternate */
3475187d 4068#ifndef TARGET_SPARC64
0f8a249a
BS
4069 if (IS_IMM)
4070 goto illegal_insn;
4071 if (!supervisor(dc))
4072 goto priv_insn;
3475187d 4073#endif
6ae20372
BS
4074 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4075 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
0f8a249a
BS
4076 break;
4077 case 0x13: /* load double word alternate */
3475187d 4078#ifndef TARGET_SPARC64
0f8a249a
BS
4079 if (IS_IMM)
4080 goto illegal_insn;
4081 if (!supervisor(dc))
4082 goto priv_insn;
3475187d 4083#endif
0f8a249a 4084 if (rd & 1)
d4218d99 4085 goto illegal_insn;
6ae20372
BS
4086 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4087 gen_ldda_asi(cpu_tmp0, cpu_val, cpu_addr, insn);
32b6c812 4088 gen_movl_TN_reg(rd + 1, cpu_tmp0);
0f8a249a
BS
4089 break;
4090 case 0x19: /* load signed byte alternate */
3475187d 4091#ifndef TARGET_SPARC64
0f8a249a
BS
4092 if (IS_IMM)
4093 goto illegal_insn;
4094 if (!supervisor(dc))
4095 goto priv_insn;
4096#endif
6ae20372 4097 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
0f8a249a
BS
4098 break;
4099 case 0x1a: /* load signed halfword alternate */
3475187d 4100#ifndef TARGET_SPARC64
0f8a249a
BS
4101 if (IS_IMM)
4102 goto illegal_insn;
4103 if (!supervisor(dc))
4104 goto priv_insn;
3475187d 4105#endif
6ae20372
BS
4106 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4107 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
0f8a249a
BS
4108 break;
4109 case 0x1d: /* ldstuba -- XXX: should be atomically */
3475187d 4110#ifndef TARGET_SPARC64
0f8a249a
BS
4111 if (IS_IMM)
4112 goto illegal_insn;
4113 if (!supervisor(dc))
4114 goto priv_insn;
4115#endif
6ae20372 4116 gen_ldstub_asi(cpu_val, cpu_addr, insn);
0f8a249a
BS
4117 break;
4118 case 0x1f: /* swap reg with alt. memory. Also atomically */
3475187d 4119#ifndef TARGET_SPARC64
0f8a249a
BS
4120 if (IS_IMM)
4121 goto illegal_insn;
4122 if (!supervisor(dc))
4123 goto priv_insn;
6ea4a6c8 4124#endif
6ae20372
BS
4125 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4126 gen_movl_reg_TN(rd, cpu_val);
4127 gen_swap_asi(cpu_val, cpu_addr, insn);
0f8a249a 4128 break;
3475187d
FB
4129
4130#ifndef TARGET_SPARC64
0f8a249a
BS
4131 case 0x30: /* ldc */
4132 case 0x31: /* ldcsr */
4133 case 0x33: /* lddc */
4134 goto ncp_insn;
3475187d
FB
4135#endif
4136#endif
4137#ifdef TARGET_SPARC64
0f8a249a 4138 case 0x08: /* V9 ldsw */
6ae20372
BS
4139 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4140 ABI32_MASK(cpu_addr);
4141 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4142 break;
4143 case 0x0b: /* V9 ldx */
6ae20372
BS
4144 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4145 ABI32_MASK(cpu_addr);
4146 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4147 break;
4148 case 0x18: /* V9 ldswa */
6ae20372
BS
4149 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4150 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
0f8a249a
BS
4151 break;
4152 case 0x1b: /* V9 ldxa */
6ae20372
BS
4153 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4154 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
0f8a249a
BS
4155 break;
4156 case 0x2d: /* V9 prefetch, no effect */
4157 goto skip_move;
4158 case 0x30: /* V9 ldfa */
6ae20372
BS
4159 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4160 gen_ldf_asi(cpu_addr, insn, 4, rd);
81ad8ba2 4161 goto skip_move;
0f8a249a 4162 case 0x33: /* V9 lddfa */
6ae20372
BS
4163 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4164 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
81ad8ba2 4165 goto skip_move;
0f8a249a
BS
4166 case 0x3d: /* V9 prefetcha, no effect */
4167 goto skip_move;
4168 case 0x32: /* V9 ldqfa */
1f587329 4169#if defined(CONFIG_USER_ONLY)
6ae20372
BS
4170 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4171 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
1f587329
BS
4172 goto skip_move;
4173#else
0f8a249a 4174 goto nfpu_insn;
1f587329 4175#endif
0f8a249a
BS
4176#endif
4177 default:
4178 goto illegal_insn;
4179 }
6ae20372 4180 gen_movl_TN_reg(rd, cpu_val);
3475187d 4181#ifdef TARGET_SPARC64
0f8a249a 4182 skip_move: ;
3475187d 4183#endif
0f8a249a 4184 } else if (xop >= 0x20 && xop < 0x24) {
6ae20372 4185 if (gen_trap_ifnofpu(dc, cpu_cond))
a80dde08 4186 goto jmp_insn;
0f8a249a
BS
4187 switch (xop) {
4188 case 0x20: /* load fpreg */
6ae20372
BS
4189 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4190 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
ce8536e2
BS
4191 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4192 offsetof(CPUState, fpr[rd]));
0f8a249a
BS
4193 break;
4194 case 0x21: /* load fsr */
6ae20372
BS
4195 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4196 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
ce8536e2
BS
4197 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4198 offsetof(CPUState, ft0));
7e8c2b6c 4199 tcg_gen_helper_0_0(helper_ldfsr);
0f8a249a
BS
4200 break;
4201 case 0x22: /* load quad fpreg */
1f587329 4202#if defined(CONFIG_USER_ONLY)
7fa76c0b
BS
4203 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4204 tcg_const_i32(7));
4205 tcg_gen_helper_0_1(helper_ldqf, cpu_addr);
1f587329
BS
4206 gen_op_store_QT0_fpr(QFPREG(rd));
4207 break;
4208#else
0f8a249a 4209 goto nfpu_insn;
1f587329 4210#endif
0f8a249a 4211 case 0x23: /* load double fpreg */
7fa76c0b
BS
4212 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4213 tcg_const_i32(7));
4214 tcg_gen_helper_0_2(helper_lddf, cpu_addr,
4215 tcg_const_i32(dc->mem_idx));
0f8a249a
BS
4216 gen_op_store_DT0_fpr(DFPREG(rd));
4217 break;
4218 default:
4219 goto illegal_insn;
4220 }
4221 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4222 xop == 0xe || xop == 0x1e) {
6ae20372 4223 gen_movl_reg_TN(rd, cpu_val);
0f8a249a 4224 switch (xop) {
1a2fb1c0 4225 case 0x4: /* store word */
6ae20372
BS
4226 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4227 ABI32_MASK(cpu_addr);
4228 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a 4229 break;
1a2fb1c0 4230 case 0x5: /* store byte */
6ae20372
BS
4231 ABI32_MASK(cpu_addr);
4232 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a 4233 break;
1a2fb1c0 4234 case 0x6: /* store halfword */
6ae20372
BS
4235 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4236 ABI32_MASK(cpu_addr);
4237 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a 4238 break;
1a2fb1c0 4239 case 0x7: /* store double word */
0f8a249a 4240 if (rd & 1)
d4218d99 4241 goto illegal_insn;
1a2fb1c0 4242 else {
8911f501 4243 TCGv r_low;
1a2fb1c0 4244
6ae20372 4245 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
1a2fb1c0
BS
4246 r_low = tcg_temp_new(TCG_TYPE_I32);
4247 gen_movl_reg_TN(rd + 1, r_low);
7fa76c0b 4248#ifndef __i386__
6ae20372 4249 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
1a2fb1c0 4250 r_low);
6ae20372 4251 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
b25deda7 4252#else /* __i386__ */
7fa76c0b
BS
4253 tcg_gen_st_tl(cpu_val, cpu_env, offsetof(CPUState, t1));
4254 tcg_gen_st_tl(r_low, cpu_env, offsetof(CPUState, t2));
4255 tcg_gen_helper_0_2(helper_std_i386, cpu_addr,
4256 tcg_const_i32(dc->mem_idx));
b25deda7 4257#endif /* __i386__ */
7fa76c0b 4258 }
0f8a249a 4259 break;
3475187d 4260#if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1a2fb1c0 4261 case 0x14: /* store word alternate */
3475187d 4262#ifndef TARGET_SPARC64
0f8a249a
BS
4263 if (IS_IMM)
4264 goto illegal_insn;
4265 if (!supervisor(dc))
4266 goto priv_insn;
6ea4a6c8 4267#endif
6ae20372
BS
4268 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4269 gen_st_asi(cpu_val, cpu_addr, insn, 4);
d39c0b99 4270 break;
1a2fb1c0 4271 case 0x15: /* store byte alternate */
3475187d 4272#ifndef TARGET_SPARC64
0f8a249a
BS
4273 if (IS_IMM)
4274 goto illegal_insn;
4275 if (!supervisor(dc))
4276 goto priv_insn;
3475187d 4277#endif
6ae20372 4278 gen_st_asi(cpu_val, cpu_addr, insn, 1);
d39c0b99 4279 break;
1a2fb1c0 4280 case 0x16: /* store halfword alternate */
3475187d 4281#ifndef TARGET_SPARC64
0f8a249a
BS
4282 if (IS_IMM)
4283 goto illegal_insn;
4284 if (!supervisor(dc))
4285 goto priv_insn;
6ea4a6c8 4286#endif
6ae20372
BS
4287 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4288 gen_st_asi(cpu_val, cpu_addr, insn, 2);
d39c0b99 4289 break;
1a2fb1c0 4290 case 0x17: /* store double word alternate */
3475187d 4291#ifndef TARGET_SPARC64
0f8a249a
BS
4292 if (IS_IMM)
4293 goto illegal_insn;
4294 if (!supervisor(dc))
4295 goto priv_insn;
3475187d 4296#endif
0f8a249a 4297 if (rd & 1)
d4218d99 4298 goto illegal_insn;
1a2fb1c0 4299 else {
6ae20372
BS
4300 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4301 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
1a2fb1c0 4302 }
d39c0b99 4303 break;
e80cfcfc 4304#endif
3475187d 4305#ifdef TARGET_SPARC64
0f8a249a 4306 case 0x0e: /* V9 stx */
6ae20372
BS
4307 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4308 ABI32_MASK(cpu_addr);
4309 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
0f8a249a
BS
4310 break;
4311 case 0x1e: /* V9 stxa */
6ae20372
BS
4312 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4313 gen_st_asi(cpu_val, cpu_addr, insn, 8);
0f8a249a 4314 break;
3475187d 4315#endif
0f8a249a
BS
4316 default:
4317 goto illegal_insn;
4318 }
4319 } else if (xop > 0x23 && xop < 0x28) {
6ae20372 4320 if (gen_trap_ifnofpu(dc, cpu_cond))
a80dde08 4321 goto jmp_insn;
0f8a249a 4322 switch (xop) {
ce8536e2 4323 case 0x24: /* store fpreg */
6ae20372 4324 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
ce8536e2
BS
4325 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4326 offsetof(CPUState, fpr[rd]));
6ae20372 4327 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
0f8a249a
BS
4328 break;
4329 case 0x25: /* stfsr, V9 stxfsr */
6ea4a6c8 4330#ifdef CONFIG_USER_ONLY
6ae20372 4331 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
6ea4a6c8 4332#endif
bb5529bb 4333 tcg_gen_helper_0_0(helper_stfsr);
ce8536e2
BS
4334 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4335 offsetof(CPUState, ft0));
6ae20372 4336 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
0f8a249a 4337 break;
1f587329
BS
4338 case 0x26:
4339#ifdef TARGET_SPARC64
4340#if defined(CONFIG_USER_ONLY)
4341 /* V9 stqf, store quad fpreg */
7fa76c0b
BS
4342 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4343 tcg_const_i32(7));
1f587329 4344 gen_op_load_fpr_QT0(QFPREG(rd));
7fa76c0b 4345 tcg_gen_helper_0_1(helper_stqf, cpu_addr);
1f587329
BS
4346 break;
4347#else
4348 goto nfpu_insn;
4349#endif
4350#else /* !TARGET_SPARC64 */
4351 /* stdfq, store floating point queue */
4352#if defined(CONFIG_USER_ONLY)
4353 goto illegal_insn;
4354#else
0f8a249a
BS
4355 if (!supervisor(dc))
4356 goto priv_insn;
6ae20372 4357 if (gen_trap_ifnofpu(dc, cpu_cond))
0f8a249a
BS
4358 goto jmp_insn;
4359 goto nfq_insn;
1f587329 4360#endif
0f8a249a 4361#endif
7fa76c0b
BS
4362 case 0x27: /* store double fpreg */
4363 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4364 tcg_const_i32(7));
3475187d 4365 gen_op_load_fpr_DT0(DFPREG(rd));
7fa76c0b
BS
4366 tcg_gen_helper_0_2(helper_stdf, cpu_addr,
4367 tcg_const_i32(dc->mem_idx));
0f8a249a
BS
4368 break;
4369 default:
4370 goto illegal_insn;
4371 }
4372 } else if (xop > 0x33 && xop < 0x3f) {
4373 switch (xop) {
a4d17f19 4374#ifdef TARGET_SPARC64
0f8a249a 4375 case 0x34: /* V9 stfa */
6ae20372 4376 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
3391c818 4377 gen_op_load_fpr_FT0(rd);
6ae20372 4378 gen_stf_asi(cpu_addr, insn, 4, rd);
0f8a249a 4379 break;
1f587329
BS
4380 case 0x36: /* V9 stqfa */
4381#if defined(CONFIG_USER_ONLY)
6ae20372 4382 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
1f587329 4383 gen_op_load_fpr_QT0(QFPREG(rd));
6ae20372 4384 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
1f587329
BS
4385 break;
4386#else
4387 goto nfpu_insn;
4388#endif
0f8a249a 4389 case 0x37: /* V9 stdfa */
6ae20372 4390 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
3391c818 4391 gen_op_load_fpr_DT0(DFPREG(rd));
6ae20372 4392 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
0f8a249a
BS
4393 break;
4394 case 0x3c: /* V9 casa */
6ae20372
BS
4395 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4396 gen_cas_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4397 gen_movl_TN_reg(rd, cpu_val);
0f8a249a
BS
4398 break;
4399 case 0x3e: /* V9 casxa */
6ae20372
BS
4400 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4401 gen_casx_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4402 gen_movl_TN_reg(rd, cpu_val);
0f8a249a 4403 break;
a4d17f19 4404#else
0f8a249a
BS
4405 case 0x34: /* stc */
4406 case 0x35: /* stcsr */
4407 case 0x36: /* stdcq */
4408 case 0x37: /* stdc */
4409 goto ncp_insn;
4410#endif
4411 default:
4412 goto illegal_insn;
4413 }
e8af50a3 4414 }
0f8a249a
BS
4415 else
4416 goto illegal_insn;
4417 }
4418 break;
cf495bcf
FB
4419 }
4420 /* default case for non jump instructions */
72cbca10 4421 if (dc->npc == DYNAMIC_PC) {
0f8a249a
BS
4422 dc->pc = DYNAMIC_PC;
4423 gen_op_next_insn();
72cbca10
FB
4424 } else if (dc->npc == JUMP_PC) {
4425 /* we can do a static jump */
6ae20372 4426 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
72cbca10
FB
4427 dc->is_br = 1;
4428 } else {
0f8a249a
BS
4429 dc->pc = dc->npc;
4430 dc->npc = dc->npc + 4;
cf495bcf 4431 }
e80cfcfc 4432 jmp_insn:
cf495bcf
FB
4433 return;
4434 illegal_insn:
6ae20372 4435 save_state(dc, cpu_cond);
2f5680ee 4436 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_ILL_INSN));
cf495bcf 4437 dc->is_br = 1;
e8af50a3 4438 return;
e80cfcfc 4439#if !defined(CONFIG_USER_ONLY)
e8af50a3 4440 priv_insn:
6ae20372 4441 save_state(dc, cpu_cond);
2f5680ee 4442 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_PRIV_INSN));
e8af50a3 4443 dc->is_br = 1;
e80cfcfc 4444 return;
e80cfcfc 4445 nfpu_insn:
6ae20372 4446 save_state(dc, cpu_cond);
e80cfcfc
FB
4447 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4448 dc->is_br = 1;
fcc72045 4449 return;
1f587329 4450#ifndef TARGET_SPARC64
9143e598 4451 nfq_insn:
6ae20372 4452 save_state(dc, cpu_cond);
9143e598
BS
4453 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4454 dc->is_br = 1;
4455 return;
4456#endif
1f587329 4457#endif
fcc72045
BS
4458#ifndef TARGET_SPARC64
4459 ncp_insn:
6ae20372 4460 save_state(dc, cpu_cond);
2f5680ee 4461 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NCP_INSN));
fcc72045
BS
4462 dc->is_br = 1;
4463 return;
4464#endif
7a3f1944
FB
4465}
4466
1a2fb1c0
BS
4467static void tcg_macro_func(TCGContext *s, int macro_id, const int *dead_args)
4468{
4469}
4470
cf495bcf 4471static inline int gen_intermediate_code_internal(TranslationBlock * tb,
0f8a249a 4472 int spc, CPUSPARCState *env)
7a3f1944 4473{
72cbca10 4474 target_ulong pc_start, last_pc;
cf495bcf
FB
4475 uint16_t *gen_opc_end;
4476 DisasContext dc1, *dc = &dc1;
e8af50a3 4477 int j, lj = -1;
cf495bcf
FB
4478
4479 memset(dc, 0, sizeof(DisasContext));
cf495bcf 4480 dc->tb = tb;
72cbca10 4481 pc_start = tb->pc;
cf495bcf 4482 dc->pc = pc_start;
e80cfcfc 4483 last_pc = dc->pc;
72cbca10 4484 dc->npc = (target_ulong) tb->cs_base;
6f27aba6
BS
4485 dc->mem_idx = cpu_mmu_index(env);
4486 dc->fpu_enabled = cpu_fpu_enabled(env);
cf495bcf 4487 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
cf495bcf 4488
1a2fb1c0 4489 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
8911f501
BS
4490 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4491 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
1a2fb1c0 4492
6ae20372
BS
4493 cpu_cond = cpu_T[2];
4494
cf495bcf 4495 do {
e8af50a3
FB
4496 if (env->nb_breakpoints > 0) {
4497 for(j = 0; j < env->nb_breakpoints; j++) {
4498 if (env->breakpoints[j] == dc->pc) {
0f8a249a 4499 if (dc->pc != pc_start)
6ae20372 4500 save_state(dc, cpu_cond);
1a2fb1c0 4501 tcg_gen_helper_0_0(helper_debug);
57fec1fe 4502 tcg_gen_exit_tb(0);
0f8a249a 4503 dc->is_br = 1;
e80cfcfc 4504 goto exit_gen_loop;
e8af50a3
FB
4505 }
4506 }
4507 }
4508 if (spc) {
4509 if (loglevel > 0)
4510 fprintf(logfile, "Search PC...\n");
4511 j = gen_opc_ptr - gen_opc_buf;
4512 if (lj < j) {
4513 lj++;
4514 while (lj < j)
4515 gen_opc_instr_start[lj++] = 0;
4516 gen_opc_pc[lj] = dc->pc;
4517 gen_opc_npc[lj] = dc->npc;
4518 gen_opc_instr_start[lj] = 1;
4519 }
4520 }
0f8a249a
BS
4521 last_pc = dc->pc;
4522 disas_sparc_insn(dc);
4523
4524 if (dc->is_br)
4525 break;
4526 /* if the next PC is different, we abort now */
4527 if (dc->pc != (last_pc + 4))
4528 break;
d39c0b99
FB
4529 /* if we reach a page boundary, we stop generation so that the
4530 PC of a TT_TFAULT exception is always in the right page */
4531 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4532 break;
e80cfcfc
FB
4533 /* if single step mode, we generate only one instruction and
4534 generate an exception */
4535 if (env->singlestep_enabled) {
2f5680ee 4536 tcg_gen_movi_tl(cpu_pc, dc->pc);
57fec1fe 4537 tcg_gen_exit_tb(0);
e80cfcfc
FB
4538 break;
4539 }
cf495bcf 4540 } while ((gen_opc_ptr < gen_opc_end) &&
0f8a249a 4541 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
e80cfcfc
FB
4542
4543 exit_gen_loop:
72cbca10 4544 if (!dc->is_br) {
5fafdf24 4545 if (dc->pc != DYNAMIC_PC &&
72cbca10
FB
4546 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4547 /* static PC and NPC: we can use direct chaining */
2f5680ee 4548 gen_goto_tb(dc, 0, dc->pc, dc->npc);
72cbca10
FB
4549 } else {
4550 if (dc->pc != DYNAMIC_PC)
2f5680ee 4551 tcg_gen_movi_tl(cpu_pc, dc->pc);
6ae20372 4552 save_npc(dc, cpu_cond);
57fec1fe 4553 tcg_gen_exit_tb(0);
72cbca10
FB
4554 }
4555 }
cf495bcf 4556 *gen_opc_ptr = INDEX_op_end;
e8af50a3
FB
4557 if (spc) {
4558 j = gen_opc_ptr - gen_opc_buf;
4559 lj++;
4560 while (lj <= j)
4561 gen_opc_instr_start[lj++] = 0;
e8af50a3
FB
4562#if 0
4563 if (loglevel > 0) {
4564 page_dump(logfile);
4565 }
4566#endif
c3278b7b
FB
4567 gen_opc_jump_pc[0] = dc->jump_pc[0];
4568 gen_opc_jump_pc[1] = dc->jump_pc[1];
e8af50a3 4569 } else {
e80cfcfc 4570 tb->size = last_pc + 4 - pc_start;
e8af50a3 4571 }
7a3f1944 4572#ifdef DEBUG_DISAS
e19e89a5 4573 if (loglevel & CPU_LOG_TB_IN_ASM) {
0f8a249a
BS
4574 fprintf(logfile, "--------------\n");
4575 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4576 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4577 fprintf(logfile, "\n");
cf495bcf 4578 }
7a3f1944 4579#endif
cf495bcf 4580 return 0;
7a3f1944
FB
4581}
4582
cf495bcf 4583int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
7a3f1944 4584{
e8af50a3 4585 return gen_intermediate_code_internal(tb, 0, env);
7a3f1944
FB
4586}
4587
cf495bcf 4588int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
7a3f1944 4589{
e8af50a3 4590 return gen_intermediate_code_internal(tb, 1, env);
7a3f1944
FB
4591}
4592
c48fcb47 4593void gen_intermediate_code_init(CPUSPARCState *env)
e80cfcfc 4594{
f5069b26 4595 unsigned int i;
c48fcb47 4596 static int inited;
f5069b26
BS
4597 static const char * const gregnames[8] = {
4598 NULL, // g0 not used
4599 "g1",
4600 "g2",
4601 "g3",
4602 "g4",
4603 "g5",
4604 "g6",
4605 "g7",
4606 };
aaed909a 4607
1a2fb1c0
BS
4608 /* init various static tables */
4609 if (!inited) {
4610 inited = 1;
4611
4612 tcg_set_macro_func(&tcg_ctx, tcg_macro_func);
4613 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
db4a4ea4
BS
4614 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4615 offsetof(CPUState, regwptr),
4616 "regwptr");
1a2fb1c0
BS
4617 //#if TARGET_LONG_BITS > HOST_LONG_BITS
4618#ifdef TARGET_SPARC64
4619 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
4620 TCG_AREG0, offsetof(CPUState, t0), "T0");
4621 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
4622 TCG_AREG0, offsetof(CPUState, t1), "T1");
4623 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
4624 TCG_AREG0, offsetof(CPUState, t2), "T2");
dc99a3f2
BS
4625 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4626 TCG_AREG0, offsetof(CPUState, xcc),
4627 "xcc");
1a2fb1c0
BS
4628#else
4629 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
4630 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
4631 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
4632#endif
dc99a3f2
BS
4633 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4634 TCG_AREG0, offsetof(CPUState, cc_src),
4635 "cc_src");
d9bdab86
BS
4636 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4637 offsetof(CPUState, cc_src2),
4638 "cc_src2");
dc99a3f2
BS
4639 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4640 TCG_AREG0, offsetof(CPUState, cc_dst),
4641 "cc_dst");
4642 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4643 TCG_AREG0, offsetof(CPUState, psr),
4644 "psr");
87e92502
BS
4645 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4646 TCG_AREG0, offsetof(CPUState, fsr),
4647 "fsr");
48d5c82b
BS
4648 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4649 TCG_AREG0, offsetof(CPUState, pc),
4650 "pc");
4651 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4652 TCG_AREG0, offsetof(CPUState, npc),
4653 "npc");
f5069b26
BS
4654 for (i = 1; i < 8; i++)
4655 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4656 offsetof(CPUState, gregs[i]),
4657 gregnames[i]);
1a2fb1c0 4658 }
658138bc 4659}
d2856f1a
AJ
4660
4661void gen_pc_load(CPUState *env, TranslationBlock *tb,
4662 unsigned long searched_pc, int pc_pos, void *puc)
4663{
4664 target_ulong npc;
4665 env->pc = gen_opc_pc[pc_pos];
4666 npc = gen_opc_npc[pc_pos];
4667 if (npc == 1) {
4668 /* dynamic NPC: already stored */
4669 } else if (npc == 2) {
4670 target_ulong t2 = (target_ulong)(unsigned long)puc;
4671 /* jump PC: use T2 and the jump targets of the translation */
4672 if (t2)
4673 env->npc = gen_opc_jump_pc[0];
4674 else
4675 env->npc = gen_opc_jump_pc[1];
4676 } else {
4677 env->npc = npc;
4678 }
4679}
This page took 0.899524 seconds and 4 git commands to generate.