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