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