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