5 Copyright (C) 2003-2005 Fabrice Bellard
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.
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.
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
36 #define DYNAMIC_PC 1 /* dynamic pc value */
37 #define JUMP_PC 2 /* dynamic pc value which takes only two values
38 according to jump_pc[T2] */
40 /* global register indexes */
41 static TCGv cpu_env, cpu_regwptr;
42 static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
43 static TCGv cpu_psr, cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8];
44 static TCGv cpu_cond, cpu_src1, cpu_src2, cpu_dst, cpu_addr, cpu_val;
48 /* local register indexes (only used inside old micro ops) */
49 static TCGv cpu_tmp0, cpu_tmp32, cpu_tmp64;
51 #include "gen-icount.h"
53 typedef struct DisasContext {
54 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
55 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
56 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
60 struct TranslationBlock *tb;
64 // This function uses non-native bit order
65 #define GET_FIELD(X, FROM, TO) \
66 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
68 // This function uses the order in the manuals, i.e. bit 0 is 2^0
69 #define GET_FIELD_SP(X, FROM, TO) \
70 GET_FIELD(X, 31 - (TO), 31 - (FROM))
72 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
73 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
77 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
78 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
81 #define DFPREG(r) (r & 0x1e)
82 #define QFPREG(r) (r & 0x1c)
85 static int sign_extend(int x, int len)
88 return (x << len) >> len;
91 #define IS_IMM (insn & (1<<13))
93 /* floating point registers moves */
94 static void gen_op_load_fpr_FT0(unsigned int src)
96 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
97 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
100 static void gen_op_load_fpr_FT1(unsigned int src)
102 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
103 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
106 static void gen_op_store_FT0_fpr(unsigned int dst)
108 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
109 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
112 static void gen_op_load_fpr_DT0(unsigned int src)
114 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
115 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
116 offsetof(CPU_DoubleU, l.upper));
117 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
118 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
119 offsetof(CPU_DoubleU, l.lower));
122 static void gen_op_load_fpr_DT1(unsigned int src)
124 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
125 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
126 offsetof(CPU_DoubleU, l.upper));
127 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
128 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
129 offsetof(CPU_DoubleU, l.lower));
132 static void gen_op_store_DT0_fpr(unsigned int dst)
134 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
135 offsetof(CPU_DoubleU, l.upper));
136 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
137 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
138 offsetof(CPU_DoubleU, l.lower));
139 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
142 static void gen_op_load_fpr_QT0(unsigned int src)
144 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
145 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
146 offsetof(CPU_QuadU, l.upmost));
147 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
148 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
149 offsetof(CPU_QuadU, l.upper));
150 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
151 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
152 offsetof(CPU_QuadU, l.lower));
153 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
154 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
155 offsetof(CPU_QuadU, l.lowest));
158 static void gen_op_load_fpr_QT1(unsigned int src)
160 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
161 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
162 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, qt1) +
165 offsetof(CPU_QuadU, l.upper));
166 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
167 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
168 offsetof(CPU_QuadU, l.lower));
169 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
170 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
171 offsetof(CPU_QuadU, l.lowest));
174 static void gen_op_store_QT0_fpr(unsigned int dst)
176 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
177 offsetof(CPU_QuadU, l.upmost));
178 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
179 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
180 offsetof(CPU_QuadU, l.upper));
181 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
182 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
183 offsetof(CPU_QuadU, l.lower));
184 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
185 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
186 offsetof(CPU_QuadU, l.lowest));
187 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
191 #ifdef CONFIG_USER_ONLY
192 #define supervisor(dc) 0
193 #ifdef TARGET_SPARC64
194 #define hypervisor(dc) 0
197 #define supervisor(dc) (dc->mem_idx >= 1)
198 #ifdef TARGET_SPARC64
199 #define hypervisor(dc) (dc->mem_idx == 2)
205 #define ABI32_MASK(addr) tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
207 #define ABI32_MASK(addr)
210 static inline void gen_movl_reg_TN(int reg, TCGv tn)
213 tcg_gen_movi_tl(tn, 0);
215 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
217 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
221 static inline void gen_movl_TN_reg(int reg, TCGv tn)
226 tcg_gen_mov_tl(cpu_gregs[reg], tn);
228 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
232 static inline void gen_goto_tb(DisasContext *s, int tb_num,
233 target_ulong pc, target_ulong npc)
235 TranslationBlock *tb;
238 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
239 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
240 /* jump to same page: we can use a direct jump */
241 tcg_gen_goto_tb(tb_num);
242 tcg_gen_movi_tl(cpu_pc, pc);
243 tcg_gen_movi_tl(cpu_npc, npc);
244 tcg_gen_exit_tb((long)tb + tb_num);
246 /* jump to another page: currently not optimized */
247 tcg_gen_movi_tl(cpu_pc, pc);
248 tcg_gen_movi_tl(cpu_npc, npc);
254 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
256 tcg_gen_extu_i32_tl(reg, src);
257 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
258 tcg_gen_andi_tl(reg, reg, 0x1);
261 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
263 tcg_gen_extu_i32_tl(reg, src);
264 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
265 tcg_gen_andi_tl(reg, reg, 0x1);
268 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
270 tcg_gen_extu_i32_tl(reg, src);
271 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
272 tcg_gen_andi_tl(reg, reg, 0x1);
275 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
277 tcg_gen_extu_i32_tl(reg, src);
278 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
279 tcg_gen_andi_tl(reg, reg, 0x1);
282 static inline void gen_cc_clear_icc(void)
284 tcg_gen_movi_i32(cpu_psr, 0);
287 #ifdef TARGET_SPARC64
288 static inline void gen_cc_clear_xcc(void)
290 tcg_gen_movi_i32(cpu_xcc, 0);
296 env->psr |= PSR_ZERO;
297 if ((int32_t) T0 < 0)
300 static inline void gen_cc_NZ_icc(TCGv dst)
305 l1 = gen_new_label();
306 l2 = gen_new_label();
307 r_temp = tcg_temp_new(TCG_TYPE_TL);
308 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
309 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
310 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
312 tcg_gen_ext_i32_tl(r_temp, dst);
313 tcg_gen_brcondi_tl(TCG_COND_GE, r_temp, 0, l2);
314 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
316 tcg_temp_free(r_temp);
319 #ifdef TARGET_SPARC64
320 static inline void gen_cc_NZ_xcc(TCGv dst)
324 l1 = gen_new_label();
325 l2 = gen_new_label();
326 tcg_gen_brcondi_tl(TCG_COND_NE, dst, 0, l1);
327 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
329 tcg_gen_brcondi_tl(TCG_COND_GE, dst, 0, l2);
330 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
337 env->psr |= PSR_CARRY;
339 static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
344 l1 = gen_new_label();
345 r_temp = tcg_temp_new(TCG_TYPE_TL);
346 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
347 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
348 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
350 tcg_temp_free(r_temp);
353 #ifdef TARGET_SPARC64
354 static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
358 l1 = gen_new_label();
359 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
360 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
366 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
369 static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
373 r_temp = tcg_temp_new(TCG_TYPE_TL);
374 tcg_gen_xor_tl(r_temp, src1, src2);
375 tcg_gen_xori_tl(r_temp, r_temp, -1);
376 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
377 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
378 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
379 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
380 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
381 tcg_temp_free(r_temp);
382 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
385 #ifdef TARGET_SPARC64
386 static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
390 r_temp = tcg_temp_new(TCG_TYPE_TL);
391 tcg_gen_xor_tl(r_temp, src1, src2);
392 tcg_gen_xori_tl(r_temp, r_temp, -1);
393 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
394 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
395 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
396 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
397 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
398 tcg_temp_free(r_temp);
399 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
403 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
405 TCGv r_temp, r_const;
408 l1 = gen_new_label();
410 r_temp = tcg_temp_new(TCG_TYPE_TL);
411 tcg_gen_xor_tl(r_temp, src1, src2);
412 tcg_gen_xori_tl(r_temp, r_temp, -1);
413 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
414 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
415 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
416 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
417 r_const = tcg_const_i32(TT_TOVF);
418 tcg_gen_helper_0_1(raise_exception, r_const);
419 tcg_temp_free(r_const);
421 tcg_temp_free(r_temp);
424 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
428 l1 = gen_new_label();
429 tcg_gen_or_tl(cpu_tmp0, src1, src2);
430 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
431 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
432 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
436 static inline void gen_tag_tv(TCGv src1, TCGv src2)
441 l1 = gen_new_label();
442 tcg_gen_or_tl(cpu_tmp0, src1, src2);
443 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
444 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
445 r_const = tcg_const_i32(TT_TOVF);
446 tcg_gen_helper_0_1(raise_exception, r_const);
447 tcg_temp_free(r_const);
451 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
453 tcg_gen_mov_tl(cpu_cc_src, src1);
454 tcg_gen_mov_tl(cpu_cc_src2, src2);
455 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
457 gen_cc_NZ_icc(cpu_cc_dst);
458 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
459 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
460 #ifdef TARGET_SPARC64
462 gen_cc_NZ_xcc(cpu_cc_dst);
463 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
464 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
466 tcg_gen_mov_tl(dst, cpu_cc_dst);
469 static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
471 tcg_gen_mov_tl(cpu_cc_src, src1);
472 tcg_gen_mov_tl(cpu_cc_src2, src2);
473 gen_mov_reg_C(cpu_tmp0, cpu_psr);
474 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
476 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
477 #ifdef TARGET_SPARC64
479 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
481 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
482 gen_cc_NZ_icc(cpu_cc_dst);
483 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
484 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
485 #ifdef TARGET_SPARC64
486 gen_cc_NZ_xcc(cpu_cc_dst);
487 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
488 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
490 tcg_gen_mov_tl(dst, cpu_cc_dst);
493 static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
495 tcg_gen_mov_tl(cpu_cc_src, src1);
496 tcg_gen_mov_tl(cpu_cc_src2, src2);
497 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
499 gen_cc_NZ_icc(cpu_cc_dst);
500 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
501 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
502 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
503 #ifdef TARGET_SPARC64
505 gen_cc_NZ_xcc(cpu_cc_dst);
506 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
507 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
509 tcg_gen_mov_tl(dst, cpu_cc_dst);
512 static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
514 tcg_gen_mov_tl(cpu_cc_src, src1);
515 tcg_gen_mov_tl(cpu_cc_src2, src2);
516 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
517 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
518 gen_add_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
520 gen_cc_NZ_icc(cpu_cc_dst);
521 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
522 #ifdef TARGET_SPARC64
524 gen_cc_NZ_xcc(cpu_cc_dst);
525 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
526 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
528 tcg_gen_mov_tl(dst, cpu_cc_dst);
533 env->psr |= PSR_CARRY;
535 static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
537 TCGv r_temp1, r_temp2;
540 l1 = gen_new_label();
541 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
542 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
543 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
544 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
545 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
546 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
548 tcg_temp_free(r_temp1);
549 tcg_temp_free(r_temp2);
552 #ifdef TARGET_SPARC64
553 static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
557 l1 = gen_new_label();
558 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
559 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
565 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
568 static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
572 r_temp = tcg_temp_new(TCG_TYPE_TL);
573 tcg_gen_xor_tl(r_temp, src1, src2);
574 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
575 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
576 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
577 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
578 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
579 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
580 tcg_temp_free(r_temp);
583 #ifdef TARGET_SPARC64
584 static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
588 r_temp = tcg_temp_new(TCG_TYPE_TL);
589 tcg_gen_xor_tl(r_temp, src1, src2);
590 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
591 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
592 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
593 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
594 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
595 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
596 tcg_temp_free(r_temp);
600 static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
602 TCGv r_temp, r_const;
605 l1 = gen_new_label();
607 r_temp = tcg_temp_new(TCG_TYPE_TL);
608 tcg_gen_xor_tl(r_temp, src1, src2);
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, (1 << 31));
612 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
613 r_const = tcg_const_i32(TT_TOVF);
614 tcg_gen_helper_0_1(raise_exception, r_const);
615 tcg_temp_free(r_const);
617 tcg_temp_free(r_temp);
620 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
622 tcg_gen_mov_tl(cpu_cc_src, src1);
623 tcg_gen_mov_tl(cpu_cc_src2, src2);
624 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
626 gen_cc_NZ_icc(cpu_cc_dst);
627 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
628 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
629 #ifdef TARGET_SPARC64
631 gen_cc_NZ_xcc(cpu_cc_dst);
632 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
633 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
635 tcg_gen_mov_tl(dst, cpu_cc_dst);
638 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
640 tcg_gen_mov_tl(cpu_cc_src, src1);
641 tcg_gen_mov_tl(cpu_cc_src2, src2);
642 gen_mov_reg_C(cpu_tmp0, cpu_psr);
643 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
645 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
646 #ifdef TARGET_SPARC64
648 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
650 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
651 gen_cc_NZ_icc(cpu_cc_dst);
652 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
653 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
654 #ifdef TARGET_SPARC64
655 gen_cc_NZ_xcc(cpu_cc_dst);
656 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
657 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
659 tcg_gen_mov_tl(dst, cpu_cc_dst);
662 static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
664 tcg_gen_mov_tl(cpu_cc_src, src1);
665 tcg_gen_mov_tl(cpu_cc_src2, src2);
666 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
668 gen_cc_NZ_icc(cpu_cc_dst);
669 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
670 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
671 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
672 #ifdef TARGET_SPARC64
674 gen_cc_NZ_xcc(cpu_cc_dst);
675 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
676 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
678 tcg_gen_mov_tl(dst, cpu_cc_dst);
681 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
683 tcg_gen_mov_tl(cpu_cc_src, src1);
684 tcg_gen_mov_tl(cpu_cc_src2, src2);
685 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
686 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
687 gen_sub_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
689 gen_cc_NZ_icc(cpu_cc_dst);
690 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
691 #ifdef TARGET_SPARC64
693 gen_cc_NZ_xcc(cpu_cc_dst);
694 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
695 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
697 tcg_gen_mov_tl(dst, cpu_cc_dst);
700 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
702 TCGv r_temp, r_temp2;
705 l1 = gen_new_label();
706 r_temp = tcg_temp_new(TCG_TYPE_TL);
707 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
713 tcg_gen_mov_tl(cpu_cc_src, src1);
714 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
715 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
716 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
717 tcg_gen_mov_tl(cpu_cc_src2, src2);
718 tcg_gen_brcondi_i32(TCG_COND_NE, r_temp2, 0, l1);
719 tcg_gen_movi_tl(cpu_cc_src2, 0);
723 // env->y = (b2 << 31) | (env->y >> 1);
724 tcg_gen_trunc_tl_i32(r_temp2, cpu_cc_src);
725 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
726 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
727 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
728 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
729 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
730 tcg_temp_free(r_temp2);
731 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
734 gen_mov_reg_N(cpu_tmp0, cpu_psr);
735 gen_mov_reg_V(r_temp, cpu_psr);
736 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
737 tcg_temp_free(r_temp);
739 // T0 = (b1 << 31) | (T0 >> 1);
741 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
742 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
743 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
745 /* do addition and update flags */
746 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
749 gen_cc_NZ_icc(cpu_cc_dst);
750 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
751 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
752 tcg_gen_mov_tl(dst, cpu_cc_dst);
755 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
757 TCGv r_temp, r_temp2;
759 r_temp = tcg_temp_new(TCG_TYPE_I64);
760 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
762 tcg_gen_extu_tl_i64(r_temp, src2);
763 tcg_gen_extu_tl_i64(r_temp2, src1);
764 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
766 tcg_gen_shri_i64(r_temp, r_temp2, 32);
767 tcg_gen_trunc_i64_i32(r_temp, r_temp);
768 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
769 tcg_temp_free(r_temp);
770 #ifdef TARGET_SPARC64
771 tcg_gen_mov_i64(dst, r_temp2);
773 tcg_gen_trunc_i64_tl(dst, r_temp2);
775 tcg_temp_free(r_temp2);
778 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
780 TCGv r_temp, r_temp2;
782 r_temp = tcg_temp_new(TCG_TYPE_I64);
783 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
785 tcg_gen_ext_tl_i64(r_temp, src2);
786 tcg_gen_ext_tl_i64(r_temp2, src1);
787 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
789 tcg_gen_shri_i64(r_temp, r_temp2, 32);
790 tcg_gen_trunc_i64_i32(r_temp, r_temp);
791 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
792 tcg_temp_free(r_temp);
793 #ifdef TARGET_SPARC64
794 tcg_gen_mov_i64(dst, r_temp2);
796 tcg_gen_trunc_i64_tl(dst, r_temp2);
798 tcg_temp_free(r_temp2);
801 #ifdef TARGET_SPARC64
802 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
807 l1 = gen_new_label();
808 tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
809 r_const = tcg_const_i32(TT_DIV_ZERO);
810 tcg_gen_helper_0_1(raise_exception, r_const);
811 tcg_temp_free(r_const);
815 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
819 l1 = gen_new_label();
820 l2 = gen_new_label();
821 tcg_gen_mov_tl(cpu_cc_src, src1);
822 tcg_gen_mov_tl(cpu_cc_src2, src2);
823 gen_trap_ifdivzero_tl(cpu_cc_src2);
824 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src, INT64_MIN, l1);
825 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src2, -1, l1);
826 tcg_gen_movi_i64(dst, INT64_MIN);
829 tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
834 static inline void gen_op_div_cc(TCGv dst)
838 tcg_gen_mov_tl(cpu_cc_dst, dst);
840 gen_cc_NZ_icc(cpu_cc_dst);
841 l1 = gen_new_label();
842 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_src2, 0, l1);
843 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
847 static inline void gen_op_logic_cc(TCGv dst)
849 tcg_gen_mov_tl(cpu_cc_dst, dst);
852 gen_cc_NZ_icc(cpu_cc_dst);
853 #ifdef TARGET_SPARC64
855 gen_cc_NZ_xcc(cpu_cc_dst);
860 static inline void gen_op_eval_ba(TCGv dst)
862 tcg_gen_movi_tl(dst, 1);
866 static inline void gen_op_eval_be(TCGv dst, TCGv src)
868 gen_mov_reg_Z(dst, src);
872 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
874 gen_mov_reg_N(cpu_tmp0, src);
875 gen_mov_reg_V(dst, src);
876 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
877 gen_mov_reg_Z(cpu_tmp0, src);
878 tcg_gen_or_tl(dst, dst, cpu_tmp0);
882 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
884 gen_mov_reg_V(cpu_tmp0, src);
885 gen_mov_reg_N(dst, src);
886 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
890 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
892 gen_mov_reg_Z(cpu_tmp0, src);
893 gen_mov_reg_C(dst, src);
894 tcg_gen_or_tl(dst, dst, cpu_tmp0);
898 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
900 gen_mov_reg_C(dst, src);
904 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
906 gen_mov_reg_V(dst, src);
910 static inline void gen_op_eval_bn(TCGv dst)
912 tcg_gen_movi_tl(dst, 0);
916 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
918 gen_mov_reg_N(dst, src);
922 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
924 gen_mov_reg_Z(dst, src);
925 tcg_gen_xori_tl(dst, dst, 0x1);
929 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
931 gen_mov_reg_N(cpu_tmp0, src);
932 gen_mov_reg_V(dst, src);
933 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
934 gen_mov_reg_Z(cpu_tmp0, src);
935 tcg_gen_or_tl(dst, dst, cpu_tmp0);
936 tcg_gen_xori_tl(dst, dst, 0x1);
940 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
942 gen_mov_reg_V(cpu_tmp0, src);
943 gen_mov_reg_N(dst, src);
944 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
945 tcg_gen_xori_tl(dst, dst, 0x1);
949 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
951 gen_mov_reg_Z(cpu_tmp0, src);
952 gen_mov_reg_C(dst, src);
953 tcg_gen_or_tl(dst, dst, cpu_tmp0);
954 tcg_gen_xori_tl(dst, dst, 0x1);
958 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
960 gen_mov_reg_C(dst, src);
961 tcg_gen_xori_tl(dst, dst, 0x1);
965 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
967 gen_mov_reg_N(dst, src);
968 tcg_gen_xori_tl(dst, dst, 0x1);
972 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
974 gen_mov_reg_V(dst, src);
975 tcg_gen_xori_tl(dst, dst, 0x1);
979 FPSR bit field FCC1 | FCC0:
985 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
986 unsigned int fcc_offset)
988 tcg_gen_extu_i32_tl(reg, src);
989 tcg_gen_shri_tl(reg, reg, FSR_FCC0_SHIFT + fcc_offset);
990 tcg_gen_andi_tl(reg, reg, 0x1);
993 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
994 unsigned int fcc_offset)
996 tcg_gen_extu_i32_tl(reg, src);
997 tcg_gen_shri_tl(reg, reg, FSR_FCC1_SHIFT + fcc_offset);
998 tcg_gen_andi_tl(reg, reg, 0x1);
1002 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
1003 unsigned int fcc_offset)
1005 gen_mov_reg_FCC0(dst, src, fcc_offset);
1006 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1007 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1010 // 1 or 2: FCC0 ^ FCC1
1011 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
1012 unsigned int fcc_offset)
1014 gen_mov_reg_FCC0(dst, src, fcc_offset);
1015 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1016 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1020 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1021 unsigned int fcc_offset)
1023 gen_mov_reg_FCC0(dst, src, fcc_offset);
1027 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
1028 unsigned int fcc_offset)
1030 gen_mov_reg_FCC0(dst, src, fcc_offset);
1031 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1032 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1033 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1037 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1038 unsigned int fcc_offset)
1040 gen_mov_reg_FCC1(dst, src, fcc_offset);
1044 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1045 unsigned int fcc_offset)
1047 gen_mov_reg_FCC0(dst, src, fcc_offset);
1048 tcg_gen_xori_tl(dst, dst, 0x1);
1049 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1050 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1054 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1055 unsigned int fcc_offset)
1057 gen_mov_reg_FCC0(dst, src, fcc_offset);
1058 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1059 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1062 // 0: !(FCC0 | FCC1)
1063 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1064 unsigned int fcc_offset)
1066 gen_mov_reg_FCC0(dst, src, fcc_offset);
1067 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1068 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1069 tcg_gen_xori_tl(dst, dst, 0x1);
1072 // 0 or 3: !(FCC0 ^ FCC1)
1073 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1074 unsigned int fcc_offset)
1076 gen_mov_reg_FCC0(dst, src, fcc_offset);
1077 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1078 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1079 tcg_gen_xori_tl(dst, dst, 0x1);
1083 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1084 unsigned int fcc_offset)
1086 gen_mov_reg_FCC0(dst, src, fcc_offset);
1087 tcg_gen_xori_tl(dst, dst, 0x1);
1090 // !1: !(FCC0 & !FCC1)
1091 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1092 unsigned int fcc_offset)
1094 gen_mov_reg_FCC0(dst, src, fcc_offset);
1095 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1096 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1097 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1098 tcg_gen_xori_tl(dst, dst, 0x1);
1102 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1103 unsigned int fcc_offset)
1105 gen_mov_reg_FCC1(dst, src, fcc_offset);
1106 tcg_gen_xori_tl(dst, dst, 0x1);
1109 // !2: !(!FCC0 & FCC1)
1110 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1111 unsigned int fcc_offset)
1113 gen_mov_reg_FCC0(dst, src, fcc_offset);
1114 tcg_gen_xori_tl(dst, dst, 0x1);
1115 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1116 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1117 tcg_gen_xori_tl(dst, dst, 0x1);
1120 // !3: !(FCC0 & FCC1)
1121 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1122 unsigned int fcc_offset)
1124 gen_mov_reg_FCC0(dst, src, fcc_offset);
1125 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1126 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1127 tcg_gen_xori_tl(dst, dst, 0x1);
1130 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1131 target_ulong pc2, TCGv r_cond)
1135 l1 = gen_new_label();
1137 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1139 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1142 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1145 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1146 target_ulong pc2, TCGv r_cond)
1150 l1 = gen_new_label();
1152 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1154 gen_goto_tb(dc, 0, pc2, pc1);
1157 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1160 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1165 l1 = gen_new_label();
1166 l2 = gen_new_label();
1168 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1170 tcg_gen_movi_tl(cpu_npc, npc1);
1174 tcg_gen_movi_tl(cpu_npc, npc2);
1178 /* call this function before using the condition register as it may
1179 have been set for a jump */
1180 static inline void flush_cond(DisasContext *dc, TCGv cond)
1182 if (dc->npc == JUMP_PC) {
1183 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1184 dc->npc = DYNAMIC_PC;
1188 static inline void save_npc(DisasContext *dc, TCGv cond)
1190 if (dc->npc == JUMP_PC) {
1191 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1192 dc->npc = DYNAMIC_PC;
1193 } else if (dc->npc != DYNAMIC_PC) {
1194 tcg_gen_movi_tl(cpu_npc, dc->npc);
1198 static inline void save_state(DisasContext *dc, TCGv cond)
1200 tcg_gen_movi_tl(cpu_pc, dc->pc);
1204 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1206 if (dc->npc == JUMP_PC) {
1207 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1208 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1209 dc->pc = DYNAMIC_PC;
1210 } else if (dc->npc == DYNAMIC_PC) {
1211 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1212 dc->pc = DYNAMIC_PC;
1218 static inline void gen_op_next_insn(void)
1220 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1221 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1224 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1228 #ifdef TARGET_SPARC64
1238 gen_op_eval_bn(r_dst);
1241 gen_op_eval_be(r_dst, r_src);
1244 gen_op_eval_ble(r_dst, r_src);
1247 gen_op_eval_bl(r_dst, r_src);
1250 gen_op_eval_bleu(r_dst, r_src);
1253 gen_op_eval_bcs(r_dst, r_src);
1256 gen_op_eval_bneg(r_dst, r_src);
1259 gen_op_eval_bvs(r_dst, r_src);
1262 gen_op_eval_ba(r_dst);
1265 gen_op_eval_bne(r_dst, r_src);
1268 gen_op_eval_bg(r_dst, r_src);
1271 gen_op_eval_bge(r_dst, r_src);
1274 gen_op_eval_bgu(r_dst, r_src);
1277 gen_op_eval_bcc(r_dst, r_src);
1280 gen_op_eval_bpos(r_dst, r_src);
1283 gen_op_eval_bvc(r_dst, r_src);
1288 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1290 unsigned int offset;
1310 gen_op_eval_bn(r_dst);
1313 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1316 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1319 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1322 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1325 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1328 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1331 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1334 gen_op_eval_ba(r_dst);
1337 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1340 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1343 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1346 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1349 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1352 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1355 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1360 #ifdef TARGET_SPARC64
1362 static const int gen_tcg_cond_reg[8] = {
1373 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1377 l1 = gen_new_label();
1378 tcg_gen_movi_tl(r_dst, 0);
1379 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1380 tcg_gen_movi_tl(r_dst, 1);
1385 /* XXX: potentially incorrect if dynamic npc */
1386 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1389 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1390 target_ulong target = dc->pc + offset;
1393 /* unconditional not taken */
1395 dc->pc = dc->npc + 4;
1396 dc->npc = dc->pc + 4;
1399 dc->npc = dc->pc + 4;
1401 } else if (cond == 0x8) {
1402 /* unconditional taken */
1405 dc->npc = dc->pc + 4;
1411 flush_cond(dc, r_cond);
1412 gen_cond(r_cond, cc, cond);
1414 gen_branch_a(dc, target, dc->npc, r_cond);
1418 dc->jump_pc[0] = target;
1419 dc->jump_pc[1] = dc->npc + 4;
1425 /* XXX: potentially incorrect if dynamic npc */
1426 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1429 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1430 target_ulong target = dc->pc + offset;
1433 /* unconditional not taken */
1435 dc->pc = dc->npc + 4;
1436 dc->npc = dc->pc + 4;
1439 dc->npc = dc->pc + 4;
1441 } else if (cond == 0x8) {
1442 /* unconditional taken */
1445 dc->npc = dc->pc + 4;
1451 flush_cond(dc, r_cond);
1452 gen_fcond(r_cond, cc, cond);
1454 gen_branch_a(dc, target, dc->npc, r_cond);
1458 dc->jump_pc[0] = target;
1459 dc->jump_pc[1] = dc->npc + 4;
1465 #ifdef TARGET_SPARC64
1466 /* XXX: potentially incorrect if dynamic npc */
1467 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1468 TCGv r_cond, TCGv r_reg)
1470 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1471 target_ulong target = dc->pc + offset;
1473 flush_cond(dc, r_cond);
1474 gen_cond_reg(r_cond, cond, r_reg);
1476 gen_branch_a(dc, target, dc->npc, r_cond);
1480 dc->jump_pc[0] = target;
1481 dc->jump_pc[1] = dc->npc + 4;
1486 static GenOpFunc * const gen_fcmps[4] = {
1493 static GenOpFunc * const gen_fcmpd[4] = {
1500 static GenOpFunc * const gen_fcmpq[4] = {
1507 static GenOpFunc * const gen_fcmpes[4] = {
1514 static GenOpFunc * const gen_fcmped[4] = {
1521 static GenOpFunc * const gen_fcmpeq[4] = {
1528 static inline void gen_op_fcmps(int fccno)
1530 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1533 static inline void gen_op_fcmpd(int fccno)
1535 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1538 static inline void gen_op_fcmpq(int fccno)
1540 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1543 static inline void gen_op_fcmpes(int fccno)
1545 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1548 static inline void gen_op_fcmped(int fccno)
1550 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1553 static inline void gen_op_fcmpeq(int fccno)
1555 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1560 static inline void gen_op_fcmps(int fccno)
1562 tcg_gen_helper_0_0(helper_fcmps);
1565 static inline void gen_op_fcmpd(int fccno)
1567 tcg_gen_helper_0_0(helper_fcmpd);
1570 static inline void gen_op_fcmpq(int fccno)
1572 tcg_gen_helper_0_0(helper_fcmpq);
1575 static inline void gen_op_fcmpes(int fccno)
1577 tcg_gen_helper_0_0(helper_fcmpes);
1580 static inline void gen_op_fcmped(int fccno)
1582 tcg_gen_helper_0_0(helper_fcmped);
1585 static inline void gen_op_fcmpeq(int fccno)
1587 tcg_gen_helper_0_0(helper_fcmpeq);
1591 static inline void gen_op_fpexception_im(int fsr_flags)
1595 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1596 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1597 r_const = tcg_const_i32(TT_FP_EXCP);
1598 tcg_gen_helper_0_1(raise_exception, r_const);
1599 tcg_temp_free(r_const);
1602 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1604 #if !defined(CONFIG_USER_ONLY)
1605 if (!dc->fpu_enabled) {
1608 save_state(dc, r_cond);
1609 r_const = tcg_const_i32(TT_NFPU_INSN);
1610 tcg_gen_helper_0_1(raise_exception, r_const);
1611 tcg_temp_free(r_const);
1619 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1621 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1624 static inline void gen_clear_float_exceptions(void)
1626 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1630 #ifdef TARGET_SPARC64
1631 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1637 r_asi = tcg_temp_new(TCG_TYPE_I32);
1638 offset = GET_FIELD(insn, 25, 31);
1639 tcg_gen_addi_tl(r_addr, r_addr, offset);
1640 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1642 asi = GET_FIELD(insn, 19, 26);
1643 r_asi = tcg_const_i32(asi);
1648 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1651 TCGv r_asi, r_size, r_sign;
1653 r_asi = gen_get_asi(insn, addr);
1654 r_size = tcg_const_i32(size);
1655 r_sign = tcg_const_i32(sign);
1656 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi, r_size, r_sign);
1657 tcg_temp_free(r_sign);
1658 tcg_temp_free(r_size);
1659 tcg_temp_free(r_asi);
1662 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1666 r_asi = gen_get_asi(insn, addr);
1667 r_size = tcg_const_i32(size);
1668 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, r_size);
1669 tcg_temp_free(r_size);
1670 tcg_temp_free(r_asi);
1673 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1675 TCGv r_asi, r_size, r_rd;
1677 r_asi = gen_get_asi(insn, addr);
1678 r_size = tcg_const_i32(size);
1679 r_rd = tcg_const_i32(rd);
1680 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, r_size, r_rd);
1681 tcg_temp_free(r_rd);
1682 tcg_temp_free(r_size);
1683 tcg_temp_free(r_asi);
1686 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1688 TCGv r_asi, r_size, r_rd;
1690 r_asi = gen_get_asi(insn, addr);
1691 r_size = tcg_const_i32(size);
1692 r_rd = tcg_const_i32(rd);
1693 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, r_size, r_rd);
1694 tcg_temp_free(r_rd);
1695 tcg_temp_free(r_size);
1696 tcg_temp_free(r_asi);
1699 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1701 TCGv r_asi, r_size, r_sign;
1703 r_asi = gen_get_asi(insn, addr);
1704 r_size = tcg_const_i32(4);
1705 r_sign = tcg_const_i32(0);
1706 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1707 tcg_temp_free(r_sign);
1708 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1709 tcg_temp_free(r_size);
1710 tcg_temp_free(r_asi);
1711 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1714 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1716 TCGv r_asi, r_size, r_sign;
1718 r_asi = gen_get_asi(insn, addr);
1719 r_size = tcg_const_i32(8);
1720 r_sign = tcg_const_i32(0);
1721 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1722 tcg_temp_free(r_sign);
1723 tcg_temp_free(r_size);
1724 tcg_temp_free(r_asi);
1725 tcg_gen_andi_i64(lo, cpu_tmp64, 0xffffffffULL);
1726 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1727 tcg_gen_andi_i64(hi, cpu_tmp64, 0xffffffffULL);
1730 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1732 TCGv r_temp, r_asi, r_size;
1734 r_temp = tcg_temp_new(TCG_TYPE_TL);
1735 gen_movl_reg_TN(rd + 1, r_temp);
1736 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1738 tcg_temp_free(r_temp);
1739 r_asi = gen_get_asi(insn, addr);
1740 r_size = tcg_const_i32(8);
1741 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1742 tcg_temp_free(r_size);
1743 tcg_temp_free(r_asi);
1746 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1751 r_val1 = tcg_temp_new(TCG_TYPE_TL);
1752 gen_movl_reg_TN(rd, r_val1);
1753 r_asi = gen_get_asi(insn, addr);
1754 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1755 tcg_temp_free(r_asi);
1756 tcg_temp_free(r_val1);
1759 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1764 gen_movl_reg_TN(rd, cpu_tmp64);
1765 r_asi = gen_get_asi(insn, addr);
1766 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1767 tcg_temp_free(r_asi);
1770 #elif !defined(CONFIG_USER_ONLY)
1772 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1775 TCGv r_asi, r_size, r_sign;
1777 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1778 r_size = tcg_const_i32(size);
1779 r_sign = tcg_const_i32(sign);
1780 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1781 tcg_temp_free(r_sign);
1782 tcg_temp_free(r_size);
1783 tcg_temp_free(r_asi);
1784 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1787 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1791 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1792 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1793 r_size = tcg_const_i32(size);
1794 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1795 tcg_temp_free(r_size);
1796 tcg_temp_free(r_asi);
1799 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1801 TCGv r_asi, r_size, r_sign;
1803 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1804 r_size = tcg_const_i32(4);
1805 r_sign = tcg_const_i32(0);
1806 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1807 tcg_temp_free(r_sign);
1808 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1809 tcg_temp_free(r_size);
1810 tcg_temp_free(r_asi);
1811 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1814 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1816 TCGv r_asi, r_size, r_sign;
1818 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1819 r_size = tcg_const_i32(8);
1820 r_sign = tcg_const_i32(0);
1821 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1822 tcg_temp_free(r_sign);
1823 tcg_temp_free(r_size);
1824 tcg_temp_free(r_asi);
1825 tcg_gen_trunc_i64_tl(lo, cpu_tmp64);
1826 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1827 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1830 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1832 TCGv r_temp, r_asi, r_size;
1834 r_temp = tcg_temp_new(TCG_TYPE_TL);
1835 gen_movl_reg_TN(rd + 1, r_temp);
1836 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1837 tcg_temp_free(r_temp);
1838 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1839 r_size = tcg_const_i32(8);
1840 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1841 tcg_temp_free(r_size);
1842 tcg_temp_free(r_asi);
1846 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1847 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1849 TCGv r_val, r_asi, r_size;
1851 gen_ld_asi(dst, addr, insn, 1, 0);
1853 r_val = tcg_const_i64(0xffULL);
1854 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1855 r_size = tcg_const_i32(1);
1856 tcg_gen_helper_0_4(helper_st_asi, addr, r_val, r_asi, r_size);
1857 tcg_temp_free(r_size);
1858 tcg_temp_free(r_asi);
1859 tcg_temp_free(r_val);
1863 static inline TCGv get_src1(unsigned int insn, TCGv def)
1868 rs1 = GET_FIELD(insn, 13, 17);
1870 r_rs1 = tcg_const_tl(0); // XXX how to free?
1872 r_rs1 = cpu_gregs[rs1];
1874 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1878 static inline TCGv get_src2(unsigned int insn, TCGv def)
1883 if (IS_IMM) { /* immediate */
1884 rs2 = GET_FIELDs(insn, 19, 31);
1885 r_rs2 = tcg_const_tl((int)rs2); // XXX how to free?
1886 } else { /* register */
1887 rs2 = GET_FIELD(insn, 27, 31);
1889 r_rs2 = tcg_const_tl(0); // XXX how to free?
1891 r_rs2 = cpu_gregs[rs2];
1893 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1898 #define CHECK_IU_FEATURE(dc, FEATURE) \
1899 if (!((dc)->features & CPU_FEATURE_ ## FEATURE)) \
1901 #define CHECK_FPU_FEATURE(dc, FEATURE) \
1902 if (!((dc)->features & CPU_FEATURE_ ## FEATURE)) \
1905 /* before an instruction, dc->pc must be static */
1906 static void disas_sparc_insn(DisasContext * dc)
1908 unsigned int insn, opc, rs1, rs2, rd;
1910 if (unlikely(loglevel & CPU_LOG_TB_OP))
1911 tcg_gen_debug_insn_start(dc->pc);
1912 insn = ldl_code(dc->pc);
1913 opc = GET_FIELD(insn, 0, 1);
1915 rd = GET_FIELD(insn, 2, 6);
1917 cpu_src1 = tcg_temp_new(TCG_TYPE_TL); // const
1918 cpu_src2 = tcg_temp_new(TCG_TYPE_TL); // const
1921 case 0: /* branches/sethi */
1923 unsigned int xop = GET_FIELD(insn, 7, 9);
1926 #ifdef TARGET_SPARC64
1927 case 0x1: /* V9 BPcc */
1931 target = GET_FIELD_SP(insn, 0, 18);
1932 target = sign_extend(target, 18);
1934 cc = GET_FIELD_SP(insn, 20, 21);
1936 do_branch(dc, target, insn, 0, cpu_cond);
1938 do_branch(dc, target, insn, 1, cpu_cond);
1943 case 0x3: /* V9 BPr */
1945 target = GET_FIELD_SP(insn, 0, 13) |
1946 (GET_FIELD_SP(insn, 20, 21) << 14);
1947 target = sign_extend(target, 16);
1949 cpu_src1 = get_src1(insn, cpu_src1);
1950 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1953 case 0x5: /* V9 FBPcc */
1955 int cc = GET_FIELD_SP(insn, 20, 21);
1956 if (gen_trap_ifnofpu(dc, cpu_cond))
1958 target = GET_FIELD_SP(insn, 0, 18);
1959 target = sign_extend(target, 19);
1961 do_fbranch(dc, target, insn, cc, cpu_cond);
1965 case 0x7: /* CBN+x */
1970 case 0x2: /* BN+x */
1972 target = GET_FIELD(insn, 10, 31);
1973 target = sign_extend(target, 22);
1975 do_branch(dc, target, insn, 0, cpu_cond);
1978 case 0x6: /* FBN+x */
1980 if (gen_trap_ifnofpu(dc, cpu_cond))
1982 target = GET_FIELD(insn, 10, 31);
1983 target = sign_extend(target, 22);
1985 do_fbranch(dc, target, insn, 0, cpu_cond);
1988 case 0x4: /* SETHI */
1990 uint32_t value = GET_FIELD(insn, 10, 31);
1993 r_const = tcg_const_tl(value << 10);
1994 gen_movl_TN_reg(rd, r_const);
1995 tcg_temp_free(r_const);
1998 case 0x0: /* UNIMPL */
2007 target_long target = GET_FIELDs(insn, 2, 31) << 2;
2010 r_const = tcg_const_tl(dc->pc);
2011 gen_movl_TN_reg(15, r_const);
2012 tcg_temp_free(r_const);
2014 gen_mov_pc_npc(dc, cpu_cond);
2018 case 2: /* FPU & Logical Operations */
2020 unsigned int xop = GET_FIELD(insn, 7, 12);
2021 if (xop == 0x3a) { /* generate trap */
2024 cpu_src1 = get_src1(insn, cpu_src1);
2026 rs2 = GET_FIELD(insn, 25, 31);
2027 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
2029 rs2 = GET_FIELD(insn, 27, 31);
2031 gen_movl_reg_TN(rs2, cpu_src2);
2032 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2034 tcg_gen_mov_tl(cpu_dst, cpu_src1);
2036 cond = GET_FIELD(insn, 3, 6);
2038 save_state(dc, cpu_cond);
2039 tcg_gen_helper_0_1(helper_trap, cpu_dst);
2040 } else if (cond != 0) {
2041 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
2042 #ifdef TARGET_SPARC64
2044 int cc = GET_FIELD_SP(insn, 11, 12);
2046 save_state(dc, cpu_cond);
2048 gen_cond(r_cond, 0, cond);
2050 gen_cond(r_cond, 1, cond);
2054 save_state(dc, cpu_cond);
2055 gen_cond(r_cond, 0, cond);
2057 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
2058 tcg_temp_free(r_cond);
2064 } else if (xop == 0x28) {
2065 rs1 = GET_FIELD(insn, 13, 17);
2068 #ifndef TARGET_SPARC64
2069 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2070 manual, rdy on the microSPARC
2072 case 0x0f: /* stbar in the SPARCv8 manual,
2073 rdy on the microSPARC II */
2074 case 0x10 ... 0x1f: /* implementation-dependent in the
2075 SPARCv8 manual, rdy on the
2078 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2079 offsetof(CPUSPARCState, y));
2080 gen_movl_TN_reg(rd, cpu_tmp0);
2082 #ifdef TARGET_SPARC64
2083 case 0x2: /* V9 rdccr */
2084 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2085 gen_movl_TN_reg(rd, cpu_dst);
2087 case 0x3: /* V9 rdasi */
2088 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2089 offsetof(CPUSPARCState, asi));
2090 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2091 gen_movl_TN_reg(rd, cpu_dst);
2093 case 0x4: /* V9 rdtick */
2097 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2098 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2099 offsetof(CPUState, tick));
2100 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2102 tcg_temp_free(r_tickptr);
2103 gen_movl_TN_reg(rd, cpu_dst);
2106 case 0x5: /* V9 rdpc */
2110 r_const = tcg_const_tl(dc->pc);
2111 gen_movl_TN_reg(rd, r_const);
2112 tcg_temp_free(r_const);
2115 case 0x6: /* V9 rdfprs */
2116 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2117 offsetof(CPUSPARCState, fprs));
2118 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2119 gen_movl_TN_reg(rd, cpu_dst);
2121 case 0xf: /* V9 membar */
2122 break; /* no effect */
2123 case 0x13: /* Graphics Status */
2124 if (gen_trap_ifnofpu(dc, cpu_cond))
2126 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2127 offsetof(CPUSPARCState, gsr));
2128 gen_movl_TN_reg(rd, cpu_tmp0);
2130 case 0x17: /* Tick compare */
2131 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2132 offsetof(CPUSPARCState, tick_cmpr));
2133 gen_movl_TN_reg(rd, cpu_tmp0);
2135 case 0x18: /* System tick */
2139 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2140 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2141 offsetof(CPUState, stick));
2142 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2144 tcg_temp_free(r_tickptr);
2145 gen_movl_TN_reg(rd, cpu_dst);
2148 case 0x19: /* System tick compare */
2149 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2150 offsetof(CPUSPARCState, stick_cmpr));
2151 gen_movl_TN_reg(rd, cpu_tmp0);
2153 case 0x10: /* Performance Control */
2154 case 0x11: /* Performance Instrumentation Counter */
2155 case 0x12: /* Dispatch Control */
2156 case 0x14: /* Softint set, WO */
2157 case 0x15: /* Softint clear, WO */
2158 case 0x16: /* Softint write */
2163 #if !defined(CONFIG_USER_ONLY)
2164 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2165 #ifndef TARGET_SPARC64
2166 if (!supervisor(dc))
2168 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2170 if (!hypervisor(dc))
2172 rs1 = GET_FIELD(insn, 13, 17);
2175 // gen_op_rdhpstate();
2178 // gen_op_rdhtstate();
2181 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2182 offsetof(CPUSPARCState, hintp));
2183 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2186 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2187 offsetof(CPUSPARCState, htba));
2188 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2191 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2192 offsetof(CPUSPARCState, hver));
2193 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2195 case 31: // hstick_cmpr
2196 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2197 tcg_gen_st_i32(cpu_tmp32, cpu_env,
2198 offsetof(CPUSPARCState, hstick_cmpr));
2204 gen_movl_TN_reg(rd, cpu_dst);
2206 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2207 if (!supervisor(dc))
2209 #ifdef TARGET_SPARC64
2210 rs1 = GET_FIELD(insn, 13, 17);
2216 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2217 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2218 offsetof(CPUState, tsptr));
2219 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2220 offsetof(trap_state, tpc));
2221 tcg_temp_free(r_tsptr);
2228 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2229 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2230 offsetof(CPUState, tsptr));
2231 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2232 offsetof(trap_state, tnpc));
2233 tcg_temp_free(r_tsptr);
2240 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2241 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2242 offsetof(CPUState, tsptr));
2243 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2244 offsetof(trap_state, tstate));
2245 tcg_temp_free(r_tsptr);
2252 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2253 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2254 offsetof(CPUState, tsptr));
2255 tcg_gen_ld_i32(cpu_tmp0, r_tsptr,
2256 offsetof(trap_state, tt));
2257 tcg_temp_free(r_tsptr);
2264 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2265 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2266 offsetof(CPUState, tick));
2267 tcg_gen_helper_1_1(helper_tick_get_count, cpu_tmp0,
2269 gen_movl_TN_reg(rd, cpu_tmp0);
2270 tcg_temp_free(r_tickptr);
2274 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2275 offsetof(CPUSPARCState, tbr));
2278 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2279 offsetof(CPUSPARCState, pstate));
2280 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2283 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2284 offsetof(CPUSPARCState, tl));
2285 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2288 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2289 offsetof(CPUSPARCState, psrpil));
2290 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2293 tcg_gen_helper_1_0(helper_rdcwp, cpu_tmp0);
2296 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2297 offsetof(CPUSPARCState, cansave));
2298 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2300 case 11: // canrestore
2301 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2302 offsetof(CPUSPARCState, canrestore));
2303 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2305 case 12: // cleanwin
2306 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2307 offsetof(CPUSPARCState, cleanwin));
2308 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2310 case 13: // otherwin
2311 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2312 offsetof(CPUSPARCState, otherwin));
2313 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2316 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2317 offsetof(CPUSPARCState, wstate));
2318 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2320 case 16: // UA2005 gl
2321 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2322 offsetof(CPUSPARCState, gl));
2323 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2325 case 26: // UA2005 strand status
2326 if (!hypervisor(dc))
2328 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2329 offsetof(CPUSPARCState, ssr));
2330 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2333 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2334 offsetof(CPUSPARCState, version));
2341 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2342 offsetof(CPUSPARCState, wim));
2343 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2345 gen_movl_TN_reg(rd, cpu_tmp0);
2347 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2348 #ifdef TARGET_SPARC64
2349 save_state(dc, cpu_cond);
2350 tcg_gen_helper_0_0(helper_flushw);
2352 if (!supervisor(dc))
2354 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, tbr));
2355 gen_movl_TN_reg(rd, cpu_tmp0);
2359 } else if (xop == 0x34) { /* FPU Operations */
2360 if (gen_trap_ifnofpu(dc, cpu_cond))
2362 gen_op_clear_ieee_excp_and_FTT();
2363 rs1 = GET_FIELD(insn, 13, 17);
2364 rs2 = GET_FIELD(insn, 27, 31);
2365 xop = GET_FIELD(insn, 18, 26);
2367 case 0x1: /* fmovs */
2368 gen_op_load_fpr_FT0(rs2);
2369 gen_op_store_FT0_fpr(rd);
2371 case 0x5: /* fnegs */
2372 gen_op_load_fpr_FT1(rs2);
2373 tcg_gen_helper_0_0(helper_fnegs);
2374 gen_op_store_FT0_fpr(rd);
2376 case 0x9: /* fabss */
2377 gen_op_load_fpr_FT1(rs2);
2378 tcg_gen_helper_0_0(helper_fabss);
2379 gen_op_store_FT0_fpr(rd);
2381 case 0x29: /* fsqrts */
2382 CHECK_FPU_FEATURE(dc, FSQRT);
2383 gen_op_load_fpr_FT1(rs2);
2384 gen_clear_float_exceptions();
2385 tcg_gen_helper_0_0(helper_fsqrts);
2386 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2387 gen_op_store_FT0_fpr(rd);
2389 case 0x2a: /* fsqrtd */
2390 CHECK_FPU_FEATURE(dc, FSQRT);
2391 gen_op_load_fpr_DT1(DFPREG(rs2));
2392 gen_clear_float_exceptions();
2393 tcg_gen_helper_0_0(helper_fsqrtd);
2394 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2395 gen_op_store_DT0_fpr(DFPREG(rd));
2397 case 0x2b: /* fsqrtq */
2398 CHECK_FPU_FEATURE(dc, FLOAT128);
2399 gen_op_load_fpr_QT1(QFPREG(rs2));
2400 gen_clear_float_exceptions();
2401 tcg_gen_helper_0_0(helper_fsqrtq);
2402 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2403 gen_op_store_QT0_fpr(QFPREG(rd));
2406 gen_op_load_fpr_FT0(rs1);
2407 gen_op_load_fpr_FT1(rs2);
2408 gen_clear_float_exceptions();
2409 tcg_gen_helper_0_0(helper_fadds);
2410 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2411 gen_op_store_FT0_fpr(rd);
2414 gen_op_load_fpr_DT0(DFPREG(rs1));
2415 gen_op_load_fpr_DT1(DFPREG(rs2));
2416 gen_clear_float_exceptions();
2417 tcg_gen_helper_0_0(helper_faddd);
2418 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2419 gen_op_store_DT0_fpr(DFPREG(rd));
2421 case 0x43: /* faddq */
2422 CHECK_FPU_FEATURE(dc, FLOAT128);
2423 gen_op_load_fpr_QT0(QFPREG(rs1));
2424 gen_op_load_fpr_QT1(QFPREG(rs2));
2425 gen_clear_float_exceptions();
2426 tcg_gen_helper_0_0(helper_faddq);
2427 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2428 gen_op_store_QT0_fpr(QFPREG(rd));
2431 gen_op_load_fpr_FT0(rs1);
2432 gen_op_load_fpr_FT1(rs2);
2433 gen_clear_float_exceptions();
2434 tcg_gen_helper_0_0(helper_fsubs);
2435 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2436 gen_op_store_FT0_fpr(rd);
2439 gen_op_load_fpr_DT0(DFPREG(rs1));
2440 gen_op_load_fpr_DT1(DFPREG(rs2));
2441 gen_clear_float_exceptions();
2442 tcg_gen_helper_0_0(helper_fsubd);
2443 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2444 gen_op_store_DT0_fpr(DFPREG(rd));
2446 case 0x47: /* fsubq */
2447 CHECK_FPU_FEATURE(dc, FLOAT128);
2448 gen_op_load_fpr_QT0(QFPREG(rs1));
2449 gen_op_load_fpr_QT1(QFPREG(rs2));
2450 gen_clear_float_exceptions();
2451 tcg_gen_helper_0_0(helper_fsubq);
2452 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2453 gen_op_store_QT0_fpr(QFPREG(rd));
2455 case 0x49: /* fmuls */
2456 CHECK_FPU_FEATURE(dc, FMUL);
2457 gen_op_load_fpr_FT0(rs1);
2458 gen_op_load_fpr_FT1(rs2);
2459 gen_clear_float_exceptions();
2460 tcg_gen_helper_0_0(helper_fmuls);
2461 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2462 gen_op_store_FT0_fpr(rd);
2464 case 0x4a: /* fmuld */
2465 CHECK_FPU_FEATURE(dc, FMUL);
2466 gen_op_load_fpr_DT0(DFPREG(rs1));
2467 gen_op_load_fpr_DT1(DFPREG(rs2));
2468 gen_clear_float_exceptions();
2469 tcg_gen_helper_0_0(helper_fmuld);
2470 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2471 gen_op_store_DT0_fpr(DFPREG(rd));
2473 case 0x4b: /* fmulq */
2474 CHECK_FPU_FEATURE(dc, FLOAT128);
2475 CHECK_FPU_FEATURE(dc, FMUL);
2476 gen_op_load_fpr_QT0(QFPREG(rs1));
2477 gen_op_load_fpr_QT1(QFPREG(rs2));
2478 gen_clear_float_exceptions();
2479 tcg_gen_helper_0_0(helper_fmulq);
2480 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2481 gen_op_store_QT0_fpr(QFPREG(rd));
2484 gen_op_load_fpr_FT0(rs1);
2485 gen_op_load_fpr_FT1(rs2);
2486 gen_clear_float_exceptions();
2487 tcg_gen_helper_0_0(helper_fdivs);
2488 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2489 gen_op_store_FT0_fpr(rd);
2492 gen_op_load_fpr_DT0(DFPREG(rs1));
2493 gen_op_load_fpr_DT1(DFPREG(rs2));
2494 gen_clear_float_exceptions();
2495 tcg_gen_helper_0_0(helper_fdivd);
2496 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2497 gen_op_store_DT0_fpr(DFPREG(rd));
2499 case 0x4f: /* fdivq */
2500 CHECK_FPU_FEATURE(dc, FLOAT128);
2501 gen_op_load_fpr_QT0(QFPREG(rs1));
2502 gen_op_load_fpr_QT1(QFPREG(rs2));
2503 gen_clear_float_exceptions();
2504 tcg_gen_helper_0_0(helper_fdivq);
2505 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2506 gen_op_store_QT0_fpr(QFPREG(rd));
2509 CHECK_FPU_FEATURE(dc, FSMULD);
2510 gen_op_load_fpr_FT0(rs1);
2511 gen_op_load_fpr_FT1(rs2);
2512 gen_clear_float_exceptions();
2513 tcg_gen_helper_0_0(helper_fsmuld);
2514 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2515 gen_op_store_DT0_fpr(DFPREG(rd));
2517 case 0x6e: /* fdmulq */
2518 CHECK_FPU_FEATURE(dc, FLOAT128);
2519 gen_op_load_fpr_DT0(DFPREG(rs1));
2520 gen_op_load_fpr_DT1(DFPREG(rs2));
2521 gen_clear_float_exceptions();
2522 tcg_gen_helper_0_0(helper_fdmulq);
2523 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2524 gen_op_store_QT0_fpr(QFPREG(rd));
2527 gen_op_load_fpr_FT1(rs2);
2528 gen_clear_float_exceptions();
2529 tcg_gen_helper_0_0(helper_fitos);
2530 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2531 gen_op_store_FT0_fpr(rd);
2534 gen_op_load_fpr_DT1(DFPREG(rs2));
2535 gen_clear_float_exceptions();
2536 tcg_gen_helper_0_0(helper_fdtos);
2537 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2538 gen_op_store_FT0_fpr(rd);
2540 case 0xc7: /* fqtos */
2541 CHECK_FPU_FEATURE(dc, FLOAT128);
2542 gen_op_load_fpr_QT1(QFPREG(rs2));
2543 gen_clear_float_exceptions();
2544 tcg_gen_helper_0_0(helper_fqtos);
2545 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2546 gen_op_store_FT0_fpr(rd);
2549 gen_op_load_fpr_FT1(rs2);
2550 tcg_gen_helper_0_0(helper_fitod);
2551 gen_op_store_DT0_fpr(DFPREG(rd));
2554 gen_op_load_fpr_FT1(rs2);
2555 tcg_gen_helper_0_0(helper_fstod);
2556 gen_op_store_DT0_fpr(DFPREG(rd));
2558 case 0xcb: /* fqtod */
2559 CHECK_FPU_FEATURE(dc, FLOAT128);
2560 gen_op_load_fpr_QT1(QFPREG(rs2));
2561 gen_clear_float_exceptions();
2562 tcg_gen_helper_0_0(helper_fqtod);
2563 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2564 gen_op_store_DT0_fpr(DFPREG(rd));
2566 case 0xcc: /* fitoq */
2567 CHECK_FPU_FEATURE(dc, FLOAT128);
2568 gen_op_load_fpr_FT1(rs2);
2569 tcg_gen_helper_0_0(helper_fitoq);
2570 gen_op_store_QT0_fpr(QFPREG(rd));
2572 case 0xcd: /* fstoq */
2573 CHECK_FPU_FEATURE(dc, FLOAT128);
2574 gen_op_load_fpr_FT1(rs2);
2575 tcg_gen_helper_0_0(helper_fstoq);
2576 gen_op_store_QT0_fpr(QFPREG(rd));
2578 case 0xce: /* fdtoq */
2579 CHECK_FPU_FEATURE(dc, FLOAT128);
2580 gen_op_load_fpr_DT1(DFPREG(rs2));
2581 tcg_gen_helper_0_0(helper_fdtoq);
2582 gen_op_store_QT0_fpr(QFPREG(rd));
2585 gen_op_load_fpr_FT1(rs2);
2586 gen_clear_float_exceptions();
2587 tcg_gen_helper_0_0(helper_fstoi);
2588 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2589 gen_op_store_FT0_fpr(rd);
2592 gen_op_load_fpr_DT1(DFPREG(rs2));
2593 gen_clear_float_exceptions();
2594 tcg_gen_helper_0_0(helper_fdtoi);
2595 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2596 gen_op_store_FT0_fpr(rd);
2598 case 0xd3: /* fqtoi */
2599 CHECK_FPU_FEATURE(dc, FLOAT128);
2600 gen_op_load_fpr_QT1(QFPREG(rs2));
2601 gen_clear_float_exceptions();
2602 tcg_gen_helper_0_0(helper_fqtoi);
2603 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2604 gen_op_store_FT0_fpr(rd);
2606 #ifdef TARGET_SPARC64
2607 case 0x2: /* V9 fmovd */
2608 gen_op_load_fpr_DT0(DFPREG(rs2));
2609 gen_op_store_DT0_fpr(DFPREG(rd));
2611 case 0x3: /* V9 fmovq */
2612 CHECK_FPU_FEATURE(dc, FLOAT128);
2613 gen_op_load_fpr_QT0(QFPREG(rs2));
2614 gen_op_store_QT0_fpr(QFPREG(rd));
2616 case 0x6: /* V9 fnegd */
2617 gen_op_load_fpr_DT1(DFPREG(rs2));
2618 tcg_gen_helper_0_0(helper_fnegd);
2619 gen_op_store_DT0_fpr(DFPREG(rd));
2621 case 0x7: /* V9 fnegq */
2622 CHECK_FPU_FEATURE(dc, FLOAT128);
2623 gen_op_load_fpr_QT1(QFPREG(rs2));
2624 tcg_gen_helper_0_0(helper_fnegq);
2625 gen_op_store_QT0_fpr(QFPREG(rd));
2627 case 0xa: /* V9 fabsd */
2628 gen_op_load_fpr_DT1(DFPREG(rs2));
2629 tcg_gen_helper_0_0(helper_fabsd);
2630 gen_op_store_DT0_fpr(DFPREG(rd));
2632 case 0xb: /* V9 fabsq */
2633 CHECK_FPU_FEATURE(dc, FLOAT128);
2634 gen_op_load_fpr_QT1(QFPREG(rs2));
2635 tcg_gen_helper_0_0(helper_fabsq);
2636 gen_op_store_QT0_fpr(QFPREG(rd));
2638 case 0x81: /* V9 fstox */
2639 gen_op_load_fpr_FT1(rs2);
2640 gen_clear_float_exceptions();
2641 tcg_gen_helper_0_0(helper_fstox);
2642 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2643 gen_op_store_DT0_fpr(DFPREG(rd));
2645 case 0x82: /* V9 fdtox */
2646 gen_op_load_fpr_DT1(DFPREG(rs2));
2647 gen_clear_float_exceptions();
2648 tcg_gen_helper_0_0(helper_fdtox);
2649 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2650 gen_op_store_DT0_fpr(DFPREG(rd));
2652 case 0x83: /* V9 fqtox */
2653 CHECK_FPU_FEATURE(dc, FLOAT128);
2654 gen_op_load_fpr_QT1(QFPREG(rs2));
2655 gen_clear_float_exceptions();
2656 tcg_gen_helper_0_0(helper_fqtox);
2657 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2658 gen_op_store_DT0_fpr(DFPREG(rd));
2660 case 0x84: /* V9 fxtos */
2661 gen_op_load_fpr_DT1(DFPREG(rs2));
2662 gen_clear_float_exceptions();
2663 tcg_gen_helper_0_0(helper_fxtos);
2664 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2665 gen_op_store_FT0_fpr(rd);
2667 case 0x88: /* V9 fxtod */
2668 gen_op_load_fpr_DT1(DFPREG(rs2));
2669 gen_clear_float_exceptions();
2670 tcg_gen_helper_0_0(helper_fxtod);
2671 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2672 gen_op_store_DT0_fpr(DFPREG(rd));
2674 case 0x8c: /* V9 fxtoq */
2675 CHECK_FPU_FEATURE(dc, FLOAT128);
2676 gen_op_load_fpr_DT1(DFPREG(rs2));
2677 gen_clear_float_exceptions();
2678 tcg_gen_helper_0_0(helper_fxtoq);
2679 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2680 gen_op_store_QT0_fpr(QFPREG(rd));
2686 } else if (xop == 0x35) { /* FPU Operations */
2687 #ifdef TARGET_SPARC64
2690 if (gen_trap_ifnofpu(dc, cpu_cond))
2692 gen_op_clear_ieee_excp_and_FTT();
2693 rs1 = GET_FIELD(insn, 13, 17);
2694 rs2 = GET_FIELD(insn, 27, 31);
2695 xop = GET_FIELD(insn, 18, 26);
2696 #ifdef TARGET_SPARC64
2697 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2700 l1 = gen_new_label();
2701 cond = GET_FIELD_SP(insn, 14, 17);
2702 cpu_src1 = get_src1(insn, cpu_src1);
2703 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2705 gen_op_load_fpr_FT0(rs2);
2706 gen_op_store_FT0_fpr(rd);
2709 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2712 l1 = gen_new_label();
2713 cond = GET_FIELD_SP(insn, 14, 17);
2714 cpu_src1 = get_src1(insn, cpu_src1);
2715 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2717 gen_op_load_fpr_DT0(DFPREG(rs2));
2718 gen_op_store_DT0_fpr(DFPREG(rd));
2721 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2724 CHECK_FPU_FEATURE(dc, FLOAT128);
2725 l1 = gen_new_label();
2726 cond = GET_FIELD_SP(insn, 14, 17);
2727 cpu_src1 = get_src1(insn, cpu_src1);
2728 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2730 gen_op_load_fpr_QT0(QFPREG(rs2));
2731 gen_op_store_QT0_fpr(QFPREG(rd));
2737 #ifdef TARGET_SPARC64
2738 #define FMOVCC(size_FDQ, fcc) \
2743 l1 = gen_new_label(); \
2744 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2745 cond = GET_FIELD_SP(insn, 14, 17); \
2746 gen_fcond(r_cond, fcc, cond); \
2747 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2749 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2750 (glue(size_FDQ, FPREG(rs2))); \
2751 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2752 (glue(size_FDQ, FPREG(rd))); \
2753 gen_set_label(l1); \
2754 tcg_temp_free(r_cond); \
2756 case 0x001: /* V9 fmovscc %fcc0 */
2759 case 0x002: /* V9 fmovdcc %fcc0 */
2762 case 0x003: /* V9 fmovqcc %fcc0 */
2763 CHECK_FPU_FEATURE(dc, FLOAT128);
2766 case 0x041: /* V9 fmovscc %fcc1 */
2769 case 0x042: /* V9 fmovdcc %fcc1 */
2772 case 0x043: /* V9 fmovqcc %fcc1 */
2773 CHECK_FPU_FEATURE(dc, FLOAT128);
2776 case 0x081: /* V9 fmovscc %fcc2 */
2779 case 0x082: /* V9 fmovdcc %fcc2 */
2782 case 0x083: /* V9 fmovqcc %fcc2 */
2783 CHECK_FPU_FEATURE(dc, FLOAT128);
2786 case 0x0c1: /* V9 fmovscc %fcc3 */
2789 case 0x0c2: /* V9 fmovdcc %fcc3 */
2792 case 0x0c3: /* V9 fmovqcc %fcc3 */
2793 CHECK_FPU_FEATURE(dc, FLOAT128);
2797 #define FMOVCC(size_FDQ, icc) \
2802 l1 = gen_new_label(); \
2803 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2804 cond = GET_FIELD_SP(insn, 14, 17); \
2805 gen_cond(r_cond, icc, cond); \
2806 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2808 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2809 (glue(size_FDQ, FPREG(rs2))); \
2810 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2811 (glue(size_FDQ, FPREG(rd))); \
2812 gen_set_label(l1); \
2813 tcg_temp_free(r_cond); \
2816 case 0x101: /* V9 fmovscc %icc */
2819 case 0x102: /* V9 fmovdcc %icc */
2821 case 0x103: /* V9 fmovqcc %icc */
2822 CHECK_FPU_FEATURE(dc, FLOAT128);
2825 case 0x181: /* V9 fmovscc %xcc */
2828 case 0x182: /* V9 fmovdcc %xcc */
2831 case 0x183: /* V9 fmovqcc %xcc */
2832 CHECK_FPU_FEATURE(dc, FLOAT128);
2837 case 0x51: /* fcmps, V9 %fcc */
2838 gen_op_load_fpr_FT0(rs1);
2839 gen_op_load_fpr_FT1(rs2);
2840 gen_op_fcmps(rd & 3);
2842 case 0x52: /* fcmpd, V9 %fcc */
2843 gen_op_load_fpr_DT0(DFPREG(rs1));
2844 gen_op_load_fpr_DT1(DFPREG(rs2));
2845 gen_op_fcmpd(rd & 3);
2847 case 0x53: /* fcmpq, V9 %fcc */
2848 CHECK_FPU_FEATURE(dc, FLOAT128);
2849 gen_op_load_fpr_QT0(QFPREG(rs1));
2850 gen_op_load_fpr_QT1(QFPREG(rs2));
2851 gen_op_fcmpq(rd & 3);
2853 case 0x55: /* fcmpes, V9 %fcc */
2854 gen_op_load_fpr_FT0(rs1);
2855 gen_op_load_fpr_FT1(rs2);
2856 gen_op_fcmpes(rd & 3);
2858 case 0x56: /* fcmped, V9 %fcc */
2859 gen_op_load_fpr_DT0(DFPREG(rs1));
2860 gen_op_load_fpr_DT1(DFPREG(rs2));
2861 gen_op_fcmped(rd & 3);
2863 case 0x57: /* fcmpeq, V9 %fcc */
2864 CHECK_FPU_FEATURE(dc, FLOAT128);
2865 gen_op_load_fpr_QT0(QFPREG(rs1));
2866 gen_op_load_fpr_QT1(QFPREG(rs2));
2867 gen_op_fcmpeq(rd & 3);
2872 } else if (xop == 0x2) {
2875 rs1 = GET_FIELD(insn, 13, 17);
2877 // or %g0, x, y -> mov T0, x; mov y, T0
2878 if (IS_IMM) { /* immediate */
2881 rs2 = GET_FIELDs(insn, 19, 31);
2882 r_const = tcg_const_tl((int)rs2);
2883 gen_movl_TN_reg(rd, r_const);
2884 tcg_temp_free(r_const);
2885 } else { /* register */
2886 rs2 = GET_FIELD(insn, 27, 31);
2887 gen_movl_reg_TN(rs2, cpu_dst);
2888 gen_movl_TN_reg(rd, cpu_dst);
2891 cpu_src1 = get_src1(insn, cpu_src1);
2892 if (IS_IMM) { /* immediate */
2893 rs2 = GET_FIELDs(insn, 19, 31);
2894 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2895 gen_movl_TN_reg(rd, cpu_dst);
2896 } else { /* register */
2897 // or x, %g0, y -> mov T1, x; mov y, T1
2898 rs2 = GET_FIELD(insn, 27, 31);
2900 gen_movl_reg_TN(rs2, cpu_src2);
2901 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2902 gen_movl_TN_reg(rd, cpu_dst);
2904 gen_movl_TN_reg(rd, cpu_src1);
2907 #ifdef TARGET_SPARC64
2908 } else if (xop == 0x25) { /* sll, V9 sllx */
2909 cpu_src1 = get_src1(insn, cpu_src1);
2910 if (IS_IMM) { /* immediate */
2911 rs2 = GET_FIELDs(insn, 20, 31);
2912 if (insn & (1 << 12)) {
2913 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2915 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2916 tcg_gen_shli_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2918 } else { /* register */
2919 rs2 = GET_FIELD(insn, 27, 31);
2920 gen_movl_reg_TN(rs2, cpu_src2);
2921 if (insn & (1 << 12)) {
2922 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2923 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2925 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2926 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2927 tcg_gen_shl_i64(cpu_dst, cpu_dst, cpu_tmp0);
2930 gen_movl_TN_reg(rd, cpu_dst);
2931 } else if (xop == 0x26) { /* srl, V9 srlx */
2932 cpu_src1 = get_src1(insn, cpu_src1);
2933 if (IS_IMM) { /* immediate */
2934 rs2 = GET_FIELDs(insn, 20, 31);
2935 if (insn & (1 << 12)) {
2936 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2938 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2939 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2941 } else { /* register */
2942 rs2 = GET_FIELD(insn, 27, 31);
2943 gen_movl_reg_TN(rs2, cpu_src2);
2944 if (insn & (1 << 12)) {
2945 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2946 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2948 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2949 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2950 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2953 gen_movl_TN_reg(rd, cpu_dst);
2954 } else if (xop == 0x27) { /* sra, V9 srax */
2955 cpu_src1 = get_src1(insn, cpu_src1);
2956 if (IS_IMM) { /* immediate */
2957 rs2 = GET_FIELDs(insn, 20, 31);
2958 if (insn & (1 << 12)) {
2959 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2961 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2962 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2963 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2965 } else { /* register */
2966 rs2 = GET_FIELD(insn, 27, 31);
2967 gen_movl_reg_TN(rs2, cpu_src2);
2968 if (insn & (1 << 12)) {
2969 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2970 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2972 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2973 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2974 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2977 gen_movl_TN_reg(rd, cpu_dst);
2979 } else if (xop < 0x36) {
2980 cpu_src1 = get_src1(insn, cpu_src1);
2981 cpu_src2 = get_src2(insn, cpu_src2);
2983 switch (xop & ~0x10) {
2986 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2988 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2991 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
2993 gen_op_logic_cc(cpu_dst);
2996 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2998 gen_op_logic_cc(cpu_dst);
3001 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3003 gen_op_logic_cc(cpu_dst);
3007 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
3009 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
3012 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3013 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
3015 gen_op_logic_cc(cpu_dst);
3018 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3019 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
3021 gen_op_logic_cc(cpu_dst);
3024 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3025 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
3027 gen_op_logic_cc(cpu_dst);
3031 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3033 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3034 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3035 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3038 #ifdef TARGET_SPARC64
3039 case 0x9: /* V9 mulx */
3040 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3044 CHECK_IU_FEATURE(dc, MUL);
3045 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3047 gen_op_logic_cc(cpu_dst);
3050 CHECK_IU_FEATURE(dc, MUL);
3051 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3053 gen_op_logic_cc(cpu_dst);
3057 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3059 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3060 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3061 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3064 #ifdef TARGET_SPARC64
3065 case 0xd: /* V9 udivx */
3066 tcg_gen_mov_tl(cpu_cc_src, cpu_src1);
3067 tcg_gen_mov_tl(cpu_cc_src2, cpu_src2);
3068 gen_trap_ifdivzero_tl(cpu_cc_src2);
3069 tcg_gen_divu_i64(cpu_dst, cpu_cc_src, cpu_cc_src2);
3073 CHECK_IU_FEATURE(dc, DIV);
3074 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1,
3077 gen_op_div_cc(cpu_dst);
3080 CHECK_IU_FEATURE(dc, DIV);
3081 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1,
3084 gen_op_div_cc(cpu_dst);
3089 gen_movl_TN_reg(rd, cpu_dst);
3092 case 0x20: /* taddcc */
3093 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3094 gen_movl_TN_reg(rd, cpu_dst);
3096 case 0x21: /* tsubcc */
3097 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3098 gen_movl_TN_reg(rd, cpu_dst);
3100 case 0x22: /* taddcctv */
3101 save_state(dc, cpu_cond);
3102 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3103 gen_movl_TN_reg(rd, cpu_dst);
3105 case 0x23: /* tsubcctv */
3106 save_state(dc, cpu_cond);
3107 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3108 gen_movl_TN_reg(rd, cpu_dst);
3110 case 0x24: /* mulscc */
3111 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3112 gen_movl_TN_reg(rd, cpu_dst);
3114 #ifndef TARGET_SPARC64
3115 case 0x25: /* sll */
3116 if (IS_IMM) { /* immediate */
3117 rs2 = GET_FIELDs(insn, 20, 31);
3118 tcg_gen_shli_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3119 } else { /* register */
3120 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3121 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3123 gen_movl_TN_reg(rd, cpu_dst);
3125 case 0x26: /* srl */
3126 if (IS_IMM) { /* immediate */
3127 rs2 = GET_FIELDs(insn, 20, 31);
3128 tcg_gen_shri_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3129 } else { /* register */
3130 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3131 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3133 gen_movl_TN_reg(rd, cpu_dst);
3135 case 0x27: /* sra */
3136 if (IS_IMM) { /* immediate */
3137 rs2 = GET_FIELDs(insn, 20, 31);
3138 tcg_gen_sari_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3139 } else { /* register */
3140 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3141 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3143 gen_movl_TN_reg(rd, cpu_dst);
3150 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3151 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3152 offsetof(CPUSPARCState, y));
3154 #ifndef TARGET_SPARC64
3155 case 0x01 ... 0x0f: /* undefined in the
3159 case 0x10 ... 0x1f: /* implementation-dependent
3165 case 0x2: /* V9 wrccr */
3166 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3167 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3169 case 0x3: /* V9 wrasi */
3170 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3171 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3172 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3173 offsetof(CPUSPARCState, asi));
3175 case 0x6: /* V9 wrfprs */
3176 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3177 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3178 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3179 offsetof(CPUSPARCState, fprs));
3180 save_state(dc, cpu_cond);
3185 case 0xf: /* V9 sir, nop if user */
3186 #if !defined(CONFIG_USER_ONLY)
3191 case 0x13: /* Graphics Status */
3192 if (gen_trap_ifnofpu(dc, cpu_cond))
3194 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3195 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3196 offsetof(CPUSPARCState, gsr));
3198 case 0x17: /* Tick compare */
3199 #if !defined(CONFIG_USER_ONLY)
3200 if (!supervisor(dc))
3206 tcg_gen_xor_tl(cpu_tmp0, cpu_src1,
3208 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3209 offsetof(CPUSPARCState,
3211 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3212 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3213 offsetof(CPUState, tick));
3214 tcg_gen_helper_0_2(helper_tick_set_limit,
3215 r_tickptr, cpu_tmp0);
3216 tcg_temp_free(r_tickptr);
3219 case 0x18: /* System tick */
3220 #if !defined(CONFIG_USER_ONLY)
3221 if (!supervisor(dc))
3227 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3229 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3230 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3231 offsetof(CPUState, stick));
3232 tcg_gen_helper_0_2(helper_tick_set_count,
3233 r_tickptr, cpu_dst);
3234 tcg_temp_free(r_tickptr);
3237 case 0x19: /* System tick compare */
3238 #if !defined(CONFIG_USER_ONLY)
3239 if (!supervisor(dc))
3245 tcg_gen_xor_tl(cpu_tmp0, cpu_src1,
3247 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3248 offsetof(CPUSPARCState,
3250 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3251 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3252 offsetof(CPUState, stick));
3253 tcg_gen_helper_0_2(helper_tick_set_limit,
3254 r_tickptr, cpu_tmp0);
3255 tcg_temp_free(r_tickptr);
3259 case 0x10: /* Performance Control */
3260 case 0x11: /* Performance Instrumentation
3262 case 0x12: /* Dispatch Control */
3263 case 0x14: /* Softint set */
3264 case 0x15: /* Softint clear */
3265 case 0x16: /* Softint write */
3272 #if !defined(CONFIG_USER_ONLY)
3273 case 0x31: /* wrpsr, V9 saved, restored */
3275 if (!supervisor(dc))
3277 #ifdef TARGET_SPARC64
3280 tcg_gen_helper_0_0(helper_saved);
3283 tcg_gen_helper_0_0(helper_restored);
3285 case 2: /* UA2005 allclean */
3286 case 3: /* UA2005 otherw */
3287 case 4: /* UA2005 normalw */
3288 case 5: /* UA2005 invalw */
3294 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3295 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3296 save_state(dc, cpu_cond);
3303 case 0x32: /* wrwim, V9 wrpr */
3305 if (!supervisor(dc))
3307 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3308 #ifdef TARGET_SPARC64
3314 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3315 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3316 offsetof(CPUState, tsptr));
3317 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3318 offsetof(trap_state, tpc));
3319 tcg_temp_free(r_tsptr);
3326 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3327 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3328 offsetof(CPUState, tsptr));
3329 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3330 offsetof(trap_state, tnpc));
3331 tcg_temp_free(r_tsptr);
3338 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3339 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3340 offsetof(CPUState, tsptr));
3341 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3342 offsetof(trap_state,
3344 tcg_temp_free(r_tsptr);
3351 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3352 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3353 offsetof(CPUState, tsptr));
3354 tcg_gen_st_i32(cpu_tmp0, r_tsptr,
3355 offsetof(trap_state, tt));
3356 tcg_temp_free(r_tsptr);
3363 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3364 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3365 offsetof(CPUState, tick));
3366 tcg_gen_helper_0_2(helper_tick_set_count,
3367 r_tickptr, cpu_tmp0);
3368 tcg_temp_free(r_tickptr);
3372 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3373 offsetof(CPUSPARCState, tbr));
3376 save_state(dc, cpu_cond);
3377 tcg_gen_helper_0_1(helper_wrpstate, cpu_tmp0);
3383 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3384 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3385 offsetof(CPUSPARCState, tl));
3388 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3389 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3390 offsetof(CPUSPARCState,
3394 tcg_gen_helper_0_1(helper_wrcwp, cpu_tmp0);
3397 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3398 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3399 offsetof(CPUSPARCState,
3402 case 11: // canrestore
3403 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3404 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3405 offsetof(CPUSPARCState,
3408 case 12: // cleanwin
3409 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3410 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3411 offsetof(CPUSPARCState,
3414 case 13: // otherwin
3415 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3416 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3417 offsetof(CPUSPARCState,
3421 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3422 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3423 offsetof(CPUSPARCState,
3426 case 16: // UA2005 gl
3427 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3428 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3429 offsetof(CPUSPARCState, gl));
3431 case 26: // UA2005 strand status
3432 if (!hypervisor(dc))
3434 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3435 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3436 offsetof(CPUSPARCState, ssr));
3442 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3443 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3444 offsetof(CPUSPARCState, wim));
3448 case 0x33: /* wrtbr, UA2005 wrhpr */
3450 #ifndef TARGET_SPARC64
3451 if (!supervisor(dc))
3453 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3454 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3455 offsetof(CPUSPARCState, tbr));
3457 if (!hypervisor(dc))
3459 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3462 // XXX gen_op_wrhpstate();
3463 save_state(dc, cpu_cond);
3469 // XXX gen_op_wrhtstate();
3472 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3473 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3474 offsetof(CPUSPARCState, hintp));
3477 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3478 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3479 offsetof(CPUSPARCState, htba));
3481 case 31: // hstick_cmpr
3485 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3486 offsetof(CPUSPARCState,
3488 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3489 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3490 offsetof(CPUState, hstick));
3491 tcg_gen_helper_0_2(helper_tick_set_limit,
3492 r_tickptr, cpu_tmp0);
3493 tcg_temp_free(r_tickptr);
3496 case 6: // hver readonly
3504 #ifdef TARGET_SPARC64
3505 case 0x2c: /* V9 movcc */
3507 int cc = GET_FIELD_SP(insn, 11, 12);
3508 int cond = GET_FIELD_SP(insn, 14, 17);
3512 r_cond = tcg_temp_new(TCG_TYPE_TL);
3513 if (insn & (1 << 18)) {
3515 gen_cond(r_cond, 0, cond);
3517 gen_cond(r_cond, 1, cond);
3521 gen_fcond(r_cond, cc, cond);
3524 l1 = gen_new_label();
3526 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3527 if (IS_IMM) { /* immediate */
3530 rs2 = GET_FIELD_SPs(insn, 0, 10);
3531 r_const = tcg_const_tl((int)rs2);
3532 gen_movl_TN_reg(rd, r_const);
3533 tcg_temp_free(r_const);
3535 rs2 = GET_FIELD_SP(insn, 0, 4);
3536 gen_movl_reg_TN(rs2, cpu_tmp0);
3537 gen_movl_TN_reg(rd, cpu_tmp0);
3540 tcg_temp_free(r_cond);
3543 case 0x2d: /* V9 sdivx */
3544 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3545 gen_movl_TN_reg(rd, cpu_dst);
3547 case 0x2e: /* V9 popc */
3549 cpu_src2 = get_src2(insn, cpu_src2);
3550 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3552 gen_movl_TN_reg(rd, cpu_dst);
3554 case 0x2f: /* V9 movr */
3556 int cond = GET_FIELD_SP(insn, 10, 12);
3559 cpu_src1 = get_src1(insn, cpu_src1);
3561 l1 = gen_new_label();
3563 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
3565 if (IS_IMM) { /* immediate */
3568 rs2 = GET_FIELD_SPs(insn, 0, 9);
3569 r_const = tcg_const_tl((int)rs2);
3570 gen_movl_TN_reg(rd, r_const);
3571 tcg_temp_free(r_const);
3573 rs2 = GET_FIELD_SP(insn, 0, 4);
3574 gen_movl_reg_TN(rs2, cpu_tmp0);
3575 gen_movl_TN_reg(rd, cpu_tmp0);
3585 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3586 #ifdef TARGET_SPARC64
3587 int opf = GET_FIELD_SP(insn, 5, 13);
3588 rs1 = GET_FIELD(insn, 13, 17);
3589 rs2 = GET_FIELD(insn, 27, 31);
3590 if (gen_trap_ifnofpu(dc, cpu_cond))
3594 case 0x000: /* VIS I edge8cc */
3595 case 0x001: /* VIS II edge8n */
3596 case 0x002: /* VIS I edge8lcc */
3597 case 0x003: /* VIS II edge8ln */
3598 case 0x004: /* VIS I edge16cc */
3599 case 0x005: /* VIS II edge16n */
3600 case 0x006: /* VIS I edge16lcc */
3601 case 0x007: /* VIS II edge16ln */
3602 case 0x008: /* VIS I edge32cc */
3603 case 0x009: /* VIS II edge32n */
3604 case 0x00a: /* VIS I edge32lcc */
3605 case 0x00b: /* VIS II edge32ln */
3608 case 0x010: /* VIS I array8 */
3609 CHECK_FPU_FEATURE(dc, VIS1);
3610 cpu_src1 = get_src1(insn, cpu_src1);
3611 gen_movl_reg_TN(rs2, cpu_src2);
3612 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3614 gen_movl_TN_reg(rd, cpu_dst);
3616 case 0x012: /* VIS I array16 */
3617 CHECK_FPU_FEATURE(dc, VIS1);
3618 cpu_src1 = get_src1(insn, cpu_src1);
3619 gen_movl_reg_TN(rs2, cpu_src2);
3620 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3622 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3623 gen_movl_TN_reg(rd, cpu_dst);
3625 case 0x014: /* VIS I array32 */
3626 CHECK_FPU_FEATURE(dc, VIS1);
3627 cpu_src1 = get_src1(insn, cpu_src1);
3628 gen_movl_reg_TN(rs2, cpu_src2);
3629 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3631 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3632 gen_movl_TN_reg(rd, cpu_dst);
3634 case 0x018: /* VIS I alignaddr */
3635 CHECK_FPU_FEATURE(dc, VIS1);
3636 cpu_src1 = get_src1(insn, cpu_src1);
3637 gen_movl_reg_TN(rs2, cpu_src2);
3638 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3640 gen_movl_TN_reg(rd, cpu_dst);
3642 case 0x019: /* VIS II bmask */
3643 case 0x01a: /* VIS I alignaddrl */
3646 case 0x020: /* VIS I fcmple16 */
3647 CHECK_FPU_FEATURE(dc, VIS1);
3648 gen_op_load_fpr_DT0(DFPREG(rs1));
3649 gen_op_load_fpr_DT1(DFPREG(rs2));
3650 tcg_gen_helper_0_0(helper_fcmple16);
3651 gen_op_store_DT0_fpr(DFPREG(rd));
3653 case 0x022: /* VIS I fcmpne16 */
3654 CHECK_FPU_FEATURE(dc, VIS1);
3655 gen_op_load_fpr_DT0(DFPREG(rs1));
3656 gen_op_load_fpr_DT1(DFPREG(rs2));
3657 tcg_gen_helper_0_0(helper_fcmpne16);
3658 gen_op_store_DT0_fpr(DFPREG(rd));
3660 case 0x024: /* VIS I fcmple32 */
3661 CHECK_FPU_FEATURE(dc, VIS1);
3662 gen_op_load_fpr_DT0(DFPREG(rs1));
3663 gen_op_load_fpr_DT1(DFPREG(rs2));
3664 tcg_gen_helper_0_0(helper_fcmple32);
3665 gen_op_store_DT0_fpr(DFPREG(rd));
3667 case 0x026: /* VIS I fcmpne32 */
3668 CHECK_FPU_FEATURE(dc, VIS1);
3669 gen_op_load_fpr_DT0(DFPREG(rs1));
3670 gen_op_load_fpr_DT1(DFPREG(rs2));
3671 tcg_gen_helper_0_0(helper_fcmpne32);
3672 gen_op_store_DT0_fpr(DFPREG(rd));
3674 case 0x028: /* VIS I fcmpgt16 */
3675 CHECK_FPU_FEATURE(dc, VIS1);
3676 gen_op_load_fpr_DT0(DFPREG(rs1));
3677 gen_op_load_fpr_DT1(DFPREG(rs2));
3678 tcg_gen_helper_0_0(helper_fcmpgt16);
3679 gen_op_store_DT0_fpr(DFPREG(rd));
3681 case 0x02a: /* VIS I fcmpeq16 */
3682 CHECK_FPU_FEATURE(dc, VIS1);
3683 gen_op_load_fpr_DT0(DFPREG(rs1));
3684 gen_op_load_fpr_DT1(DFPREG(rs2));
3685 tcg_gen_helper_0_0(helper_fcmpeq16);
3686 gen_op_store_DT0_fpr(DFPREG(rd));
3688 case 0x02c: /* VIS I fcmpgt32 */
3689 CHECK_FPU_FEATURE(dc, VIS1);
3690 gen_op_load_fpr_DT0(DFPREG(rs1));
3691 gen_op_load_fpr_DT1(DFPREG(rs2));
3692 tcg_gen_helper_0_0(helper_fcmpgt32);
3693 gen_op_store_DT0_fpr(DFPREG(rd));
3695 case 0x02e: /* VIS I fcmpeq32 */
3696 CHECK_FPU_FEATURE(dc, VIS1);
3697 gen_op_load_fpr_DT0(DFPREG(rs1));
3698 gen_op_load_fpr_DT1(DFPREG(rs2));
3699 tcg_gen_helper_0_0(helper_fcmpeq32);
3700 gen_op_store_DT0_fpr(DFPREG(rd));
3702 case 0x031: /* VIS I fmul8x16 */
3703 CHECK_FPU_FEATURE(dc, VIS1);
3704 gen_op_load_fpr_DT0(DFPREG(rs1));
3705 gen_op_load_fpr_DT1(DFPREG(rs2));
3706 tcg_gen_helper_0_0(helper_fmul8x16);
3707 gen_op_store_DT0_fpr(DFPREG(rd));
3709 case 0x033: /* VIS I fmul8x16au */
3710 CHECK_FPU_FEATURE(dc, VIS1);
3711 gen_op_load_fpr_DT0(DFPREG(rs1));
3712 gen_op_load_fpr_DT1(DFPREG(rs2));
3713 tcg_gen_helper_0_0(helper_fmul8x16au);
3714 gen_op_store_DT0_fpr(DFPREG(rd));
3716 case 0x035: /* VIS I fmul8x16al */
3717 CHECK_FPU_FEATURE(dc, VIS1);
3718 gen_op_load_fpr_DT0(DFPREG(rs1));
3719 gen_op_load_fpr_DT1(DFPREG(rs2));
3720 tcg_gen_helper_0_0(helper_fmul8x16al);
3721 gen_op_store_DT0_fpr(DFPREG(rd));
3723 case 0x036: /* VIS I fmul8sux16 */
3724 CHECK_FPU_FEATURE(dc, VIS1);
3725 gen_op_load_fpr_DT0(DFPREG(rs1));
3726 gen_op_load_fpr_DT1(DFPREG(rs2));
3727 tcg_gen_helper_0_0(helper_fmul8sux16);
3728 gen_op_store_DT0_fpr(DFPREG(rd));
3730 case 0x037: /* VIS I fmul8ulx16 */
3731 CHECK_FPU_FEATURE(dc, VIS1);
3732 gen_op_load_fpr_DT0(DFPREG(rs1));
3733 gen_op_load_fpr_DT1(DFPREG(rs2));
3734 tcg_gen_helper_0_0(helper_fmul8ulx16);
3735 gen_op_store_DT0_fpr(DFPREG(rd));
3737 case 0x038: /* VIS I fmuld8sux16 */
3738 CHECK_FPU_FEATURE(dc, VIS1);
3739 gen_op_load_fpr_DT0(DFPREG(rs1));
3740 gen_op_load_fpr_DT1(DFPREG(rs2));
3741 tcg_gen_helper_0_0(helper_fmuld8sux16);
3742 gen_op_store_DT0_fpr(DFPREG(rd));
3744 case 0x039: /* VIS I fmuld8ulx16 */
3745 CHECK_FPU_FEATURE(dc, VIS1);
3746 gen_op_load_fpr_DT0(DFPREG(rs1));
3747 gen_op_load_fpr_DT1(DFPREG(rs2));
3748 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3749 gen_op_store_DT0_fpr(DFPREG(rd));
3751 case 0x03a: /* VIS I fpack32 */
3752 case 0x03b: /* VIS I fpack16 */
3753 case 0x03d: /* VIS I fpackfix */
3754 case 0x03e: /* VIS I pdist */
3757 case 0x048: /* VIS I faligndata */
3758 CHECK_FPU_FEATURE(dc, VIS1);
3759 gen_op_load_fpr_DT0(DFPREG(rs1));
3760 gen_op_load_fpr_DT1(DFPREG(rs2));
3761 tcg_gen_helper_0_0(helper_faligndata);
3762 gen_op_store_DT0_fpr(DFPREG(rd));
3764 case 0x04b: /* VIS I fpmerge */
3765 CHECK_FPU_FEATURE(dc, VIS1);
3766 gen_op_load_fpr_DT0(DFPREG(rs1));
3767 gen_op_load_fpr_DT1(DFPREG(rs2));
3768 tcg_gen_helper_0_0(helper_fpmerge);
3769 gen_op_store_DT0_fpr(DFPREG(rd));
3771 case 0x04c: /* VIS II bshuffle */
3774 case 0x04d: /* VIS I fexpand */
3775 CHECK_FPU_FEATURE(dc, VIS1);
3776 gen_op_load_fpr_DT0(DFPREG(rs1));
3777 gen_op_load_fpr_DT1(DFPREG(rs2));
3778 tcg_gen_helper_0_0(helper_fexpand);
3779 gen_op_store_DT0_fpr(DFPREG(rd));
3781 case 0x050: /* VIS I fpadd16 */
3782 CHECK_FPU_FEATURE(dc, VIS1);
3783 gen_op_load_fpr_DT0(DFPREG(rs1));
3784 gen_op_load_fpr_DT1(DFPREG(rs2));
3785 tcg_gen_helper_0_0(helper_fpadd16);
3786 gen_op_store_DT0_fpr(DFPREG(rd));
3788 case 0x051: /* VIS I fpadd16s */
3789 CHECK_FPU_FEATURE(dc, VIS1);
3790 gen_op_load_fpr_FT0(rs1);
3791 gen_op_load_fpr_FT1(rs2);
3792 tcg_gen_helper_0_0(helper_fpadd16s);
3793 gen_op_store_FT0_fpr(rd);
3795 case 0x052: /* VIS I fpadd32 */
3796 CHECK_FPU_FEATURE(dc, VIS1);
3797 gen_op_load_fpr_DT0(DFPREG(rs1));
3798 gen_op_load_fpr_DT1(DFPREG(rs2));
3799 tcg_gen_helper_0_0(helper_fpadd32);
3800 gen_op_store_DT0_fpr(DFPREG(rd));
3802 case 0x053: /* VIS I fpadd32s */
3803 CHECK_FPU_FEATURE(dc, VIS1);
3804 gen_op_load_fpr_FT0(rs1);
3805 gen_op_load_fpr_FT1(rs2);
3806 tcg_gen_helper_0_0(helper_fpadd32s);
3807 gen_op_store_FT0_fpr(rd);
3809 case 0x054: /* VIS I fpsub16 */
3810 CHECK_FPU_FEATURE(dc, VIS1);
3811 gen_op_load_fpr_DT0(DFPREG(rs1));
3812 gen_op_load_fpr_DT1(DFPREG(rs2));
3813 tcg_gen_helper_0_0(helper_fpsub16);
3814 gen_op_store_DT0_fpr(DFPREG(rd));
3816 case 0x055: /* VIS I fpsub16s */
3817 CHECK_FPU_FEATURE(dc, VIS1);
3818 gen_op_load_fpr_FT0(rs1);
3819 gen_op_load_fpr_FT1(rs2);
3820 tcg_gen_helper_0_0(helper_fpsub16s);
3821 gen_op_store_FT0_fpr(rd);
3823 case 0x056: /* VIS I fpsub32 */
3824 CHECK_FPU_FEATURE(dc, VIS1);
3825 gen_op_load_fpr_DT0(DFPREG(rs1));
3826 gen_op_load_fpr_DT1(DFPREG(rs2));
3827 tcg_gen_helper_0_0(helper_fpadd32);
3828 gen_op_store_DT0_fpr(DFPREG(rd));
3830 case 0x057: /* VIS I fpsub32s */
3831 CHECK_FPU_FEATURE(dc, VIS1);
3832 gen_op_load_fpr_FT0(rs1);
3833 gen_op_load_fpr_FT1(rs2);
3834 tcg_gen_helper_0_0(helper_fpsub32s);
3835 gen_op_store_FT0_fpr(rd);
3837 case 0x060: /* VIS I fzero */
3838 CHECK_FPU_FEATURE(dc, VIS1);
3839 tcg_gen_helper_0_0(helper_movl_DT0_0);
3840 gen_op_store_DT0_fpr(DFPREG(rd));
3842 case 0x061: /* VIS I fzeros */
3843 CHECK_FPU_FEATURE(dc, VIS1);
3844 tcg_gen_helper_0_0(helper_movl_FT0_0);
3845 gen_op_store_FT0_fpr(rd);
3847 case 0x062: /* VIS I fnor */
3848 CHECK_FPU_FEATURE(dc, VIS1);
3849 gen_op_load_fpr_DT0(DFPREG(rs1));
3850 gen_op_load_fpr_DT1(DFPREG(rs2));
3851 tcg_gen_helper_0_0(helper_fnor);
3852 gen_op_store_DT0_fpr(DFPREG(rd));
3854 case 0x063: /* VIS I fnors */
3855 CHECK_FPU_FEATURE(dc, VIS1);
3856 gen_op_load_fpr_FT0(rs1);
3857 gen_op_load_fpr_FT1(rs2);
3858 tcg_gen_helper_0_0(helper_fnors);
3859 gen_op_store_FT0_fpr(rd);
3861 case 0x064: /* VIS I fandnot2 */
3862 CHECK_FPU_FEATURE(dc, VIS1);
3863 gen_op_load_fpr_DT1(DFPREG(rs1));
3864 gen_op_load_fpr_DT0(DFPREG(rs2));
3865 tcg_gen_helper_0_0(helper_fandnot);
3866 gen_op_store_DT0_fpr(DFPREG(rd));
3868 case 0x065: /* VIS I fandnot2s */
3869 CHECK_FPU_FEATURE(dc, VIS1);
3870 gen_op_load_fpr_FT1(rs1);
3871 gen_op_load_fpr_FT0(rs2);
3872 tcg_gen_helper_0_0(helper_fandnots);
3873 gen_op_store_FT0_fpr(rd);
3875 case 0x066: /* VIS I fnot2 */
3876 CHECK_FPU_FEATURE(dc, VIS1);
3877 gen_op_load_fpr_DT1(DFPREG(rs2));
3878 tcg_gen_helper_0_0(helper_fnot);
3879 gen_op_store_DT0_fpr(DFPREG(rd));
3881 case 0x067: /* VIS I fnot2s */
3882 CHECK_FPU_FEATURE(dc, VIS1);
3883 gen_op_load_fpr_FT1(rs2);
3884 tcg_gen_helper_0_0(helper_fnot);
3885 gen_op_store_FT0_fpr(rd);
3887 case 0x068: /* VIS I fandnot1 */
3888 CHECK_FPU_FEATURE(dc, VIS1);
3889 gen_op_load_fpr_DT0(DFPREG(rs1));
3890 gen_op_load_fpr_DT1(DFPREG(rs2));
3891 tcg_gen_helper_0_0(helper_fandnot);
3892 gen_op_store_DT0_fpr(DFPREG(rd));
3894 case 0x069: /* VIS I fandnot1s */
3895 CHECK_FPU_FEATURE(dc, VIS1);
3896 gen_op_load_fpr_FT0(rs1);
3897 gen_op_load_fpr_FT1(rs2);
3898 tcg_gen_helper_0_0(helper_fandnots);
3899 gen_op_store_FT0_fpr(rd);
3901 case 0x06a: /* VIS I fnot1 */
3902 CHECK_FPU_FEATURE(dc, VIS1);
3903 gen_op_load_fpr_DT1(DFPREG(rs1));
3904 tcg_gen_helper_0_0(helper_fnot);
3905 gen_op_store_DT0_fpr(DFPREG(rd));
3907 case 0x06b: /* VIS I fnot1s */
3908 CHECK_FPU_FEATURE(dc, VIS1);
3909 gen_op_load_fpr_FT1(rs1);
3910 tcg_gen_helper_0_0(helper_fnot);
3911 gen_op_store_FT0_fpr(rd);
3913 case 0x06c: /* VIS I fxor */
3914 CHECK_FPU_FEATURE(dc, VIS1);
3915 gen_op_load_fpr_DT0(DFPREG(rs1));
3916 gen_op_load_fpr_DT1(DFPREG(rs2));
3917 tcg_gen_helper_0_0(helper_fxor);
3918 gen_op_store_DT0_fpr(DFPREG(rd));
3920 case 0x06d: /* VIS I fxors */
3921 CHECK_FPU_FEATURE(dc, VIS1);
3922 gen_op_load_fpr_FT0(rs1);
3923 gen_op_load_fpr_FT1(rs2);
3924 tcg_gen_helper_0_0(helper_fxors);
3925 gen_op_store_FT0_fpr(rd);
3927 case 0x06e: /* VIS I fnand */
3928 CHECK_FPU_FEATURE(dc, VIS1);
3929 gen_op_load_fpr_DT0(DFPREG(rs1));
3930 gen_op_load_fpr_DT1(DFPREG(rs2));
3931 tcg_gen_helper_0_0(helper_fnand);
3932 gen_op_store_DT0_fpr(DFPREG(rd));
3934 case 0x06f: /* VIS I fnands */
3935 CHECK_FPU_FEATURE(dc, VIS1);
3936 gen_op_load_fpr_FT0(rs1);
3937 gen_op_load_fpr_FT1(rs2);
3938 tcg_gen_helper_0_0(helper_fnands);
3939 gen_op_store_FT0_fpr(rd);
3941 case 0x070: /* VIS I fand */
3942 CHECK_FPU_FEATURE(dc, VIS1);
3943 gen_op_load_fpr_DT0(DFPREG(rs1));
3944 gen_op_load_fpr_DT1(DFPREG(rs2));
3945 tcg_gen_helper_0_0(helper_fand);
3946 gen_op_store_DT0_fpr(DFPREG(rd));
3948 case 0x071: /* VIS I fands */
3949 CHECK_FPU_FEATURE(dc, VIS1);
3950 gen_op_load_fpr_FT0(rs1);
3951 gen_op_load_fpr_FT1(rs2);
3952 tcg_gen_helper_0_0(helper_fands);
3953 gen_op_store_FT0_fpr(rd);
3955 case 0x072: /* VIS I fxnor */
3956 CHECK_FPU_FEATURE(dc, VIS1);
3957 gen_op_load_fpr_DT0(DFPREG(rs1));
3958 gen_op_load_fpr_DT1(DFPREG(rs2));
3959 tcg_gen_helper_0_0(helper_fxnor);
3960 gen_op_store_DT0_fpr(DFPREG(rd));
3962 case 0x073: /* VIS I fxnors */
3963 CHECK_FPU_FEATURE(dc, VIS1);
3964 gen_op_load_fpr_FT0(rs1);
3965 gen_op_load_fpr_FT1(rs2);
3966 tcg_gen_helper_0_0(helper_fxnors);
3967 gen_op_store_FT0_fpr(rd);
3969 case 0x074: /* VIS I fsrc1 */
3970 CHECK_FPU_FEATURE(dc, VIS1);
3971 gen_op_load_fpr_DT0(DFPREG(rs1));
3972 gen_op_store_DT0_fpr(DFPREG(rd));
3974 case 0x075: /* VIS I fsrc1s */
3975 CHECK_FPU_FEATURE(dc, VIS1);
3976 gen_op_load_fpr_FT0(rs1);
3977 gen_op_store_FT0_fpr(rd);
3979 case 0x076: /* VIS I fornot2 */
3980 CHECK_FPU_FEATURE(dc, VIS1);
3981 gen_op_load_fpr_DT1(DFPREG(rs1));
3982 gen_op_load_fpr_DT0(DFPREG(rs2));
3983 tcg_gen_helper_0_0(helper_fornot);
3984 gen_op_store_DT0_fpr(DFPREG(rd));
3986 case 0x077: /* VIS I fornot2s */
3987 CHECK_FPU_FEATURE(dc, VIS1);
3988 gen_op_load_fpr_FT1(rs1);
3989 gen_op_load_fpr_FT0(rs2);
3990 tcg_gen_helper_0_0(helper_fornots);
3991 gen_op_store_FT0_fpr(rd);
3993 case 0x078: /* VIS I fsrc2 */
3994 CHECK_FPU_FEATURE(dc, VIS1);
3995 gen_op_load_fpr_DT0(DFPREG(rs2));
3996 gen_op_store_DT0_fpr(DFPREG(rd));
3998 case 0x079: /* VIS I fsrc2s */
3999 CHECK_FPU_FEATURE(dc, VIS1);
4000 gen_op_load_fpr_FT0(rs2);
4001 gen_op_store_FT0_fpr(rd);
4003 case 0x07a: /* VIS I fornot1 */
4004 CHECK_FPU_FEATURE(dc, VIS1);
4005 gen_op_load_fpr_DT0(DFPREG(rs1));
4006 gen_op_load_fpr_DT1(DFPREG(rs2));
4007 tcg_gen_helper_0_0(helper_fornot);
4008 gen_op_store_DT0_fpr(DFPREG(rd));
4010 case 0x07b: /* VIS I fornot1s */
4011 CHECK_FPU_FEATURE(dc, VIS1);
4012 gen_op_load_fpr_FT0(rs1);
4013 gen_op_load_fpr_FT1(rs2);
4014 tcg_gen_helper_0_0(helper_fornots);
4015 gen_op_store_FT0_fpr(rd);
4017 case 0x07c: /* VIS I for */
4018 CHECK_FPU_FEATURE(dc, VIS1);
4019 gen_op_load_fpr_DT0(DFPREG(rs1));
4020 gen_op_load_fpr_DT1(DFPREG(rs2));
4021 tcg_gen_helper_0_0(helper_for);
4022 gen_op_store_DT0_fpr(DFPREG(rd));
4024 case 0x07d: /* VIS I fors */
4025 CHECK_FPU_FEATURE(dc, VIS1);
4026 gen_op_load_fpr_FT0(rs1);
4027 gen_op_load_fpr_FT1(rs2);
4028 tcg_gen_helper_0_0(helper_fors);
4029 gen_op_store_FT0_fpr(rd);
4031 case 0x07e: /* VIS I fone */
4032 CHECK_FPU_FEATURE(dc, VIS1);
4033 tcg_gen_helper_0_0(helper_movl_DT0_1);
4034 gen_op_store_DT0_fpr(DFPREG(rd));
4036 case 0x07f: /* VIS I fones */
4037 CHECK_FPU_FEATURE(dc, VIS1);
4038 tcg_gen_helper_0_0(helper_movl_FT0_1);
4039 gen_op_store_FT0_fpr(rd);
4041 case 0x080: /* VIS I shutdown */
4042 case 0x081: /* VIS II siam */
4051 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4052 #ifdef TARGET_SPARC64
4057 #ifdef TARGET_SPARC64
4058 } else if (xop == 0x39) { /* V9 return */
4061 save_state(dc, cpu_cond);
4062 cpu_src1 = get_src1(insn, cpu_src1);
4063 if (IS_IMM) { /* immediate */
4064 rs2 = GET_FIELDs(insn, 19, 31);
4065 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4066 } else { /* register */
4067 rs2 = GET_FIELD(insn, 27, 31);
4069 gen_movl_reg_TN(rs2, cpu_src2);
4070 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4072 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4074 tcg_gen_helper_0_0(helper_restore);
4075 gen_mov_pc_npc(dc, cpu_cond);
4076 r_const = tcg_const_i32(3);
4077 tcg_gen_helper_0_2(helper_check_align, cpu_dst, r_const);
4078 tcg_temp_free(r_const);
4079 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4080 dc->npc = DYNAMIC_PC;
4084 cpu_src1 = get_src1(insn, cpu_src1);
4085 if (IS_IMM) { /* immediate */
4086 rs2 = GET_FIELDs(insn, 19, 31);
4087 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4088 } else { /* register */
4089 rs2 = GET_FIELD(insn, 27, 31);
4091 gen_movl_reg_TN(rs2, cpu_src2);
4092 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4094 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4097 case 0x38: /* jmpl */
4101 r_const = tcg_const_tl(dc->pc);
4102 gen_movl_TN_reg(rd, r_const);
4103 tcg_temp_free(r_const);
4104 gen_mov_pc_npc(dc, cpu_cond);
4105 r_const = tcg_const_i32(3);
4106 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4108 tcg_temp_free(r_const);
4109 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4110 dc->npc = DYNAMIC_PC;
4113 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4114 case 0x39: /* rett, V9 return */
4118 if (!supervisor(dc))
4120 gen_mov_pc_npc(dc, cpu_cond);
4121 r_const = tcg_const_i32(3);
4122 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4124 tcg_temp_free(r_const);
4125 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4126 dc->npc = DYNAMIC_PC;
4127 tcg_gen_helper_0_0(helper_rett);
4131 case 0x3b: /* flush */
4132 if (!((dc)->features & CPU_FEATURE_FLUSH))
4134 tcg_gen_helper_0_1(helper_flush, cpu_dst);
4136 case 0x3c: /* save */
4137 save_state(dc, cpu_cond);
4138 tcg_gen_helper_0_0(helper_save);
4139 gen_movl_TN_reg(rd, cpu_dst);
4141 case 0x3d: /* restore */
4142 save_state(dc, cpu_cond);
4143 tcg_gen_helper_0_0(helper_restore);
4144 gen_movl_TN_reg(rd, cpu_dst);
4146 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4147 case 0x3e: /* V9 done/retry */
4151 if (!supervisor(dc))
4153 dc->npc = DYNAMIC_PC;
4154 dc->pc = DYNAMIC_PC;
4155 tcg_gen_helper_0_0(helper_done);
4158 if (!supervisor(dc))
4160 dc->npc = DYNAMIC_PC;
4161 dc->pc = DYNAMIC_PC;
4162 tcg_gen_helper_0_0(helper_retry);
4177 case 3: /* load/store instructions */
4179 unsigned int xop = GET_FIELD(insn, 7, 12);
4181 cpu_src1 = get_src1(insn, cpu_src1);
4182 if (xop == 0x3c || xop == 0x3e) { // V9 casa/casxa
4183 rs2 = GET_FIELD(insn, 27, 31);
4184 gen_movl_reg_TN(rs2, cpu_src2);
4185 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4186 } else if (IS_IMM) { /* immediate */
4187 rs2 = GET_FIELDs(insn, 19, 31);
4188 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4189 } else { /* register */
4190 rs2 = GET_FIELD(insn, 27, 31);
4192 gen_movl_reg_TN(rs2, cpu_src2);
4193 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4195 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4197 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4198 (xop > 0x17 && xop <= 0x1d ) ||
4199 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4201 case 0x0: /* load unsigned word */
4202 ABI32_MASK(cpu_addr);
4203 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4205 case 0x1: /* load unsigned byte */
4206 ABI32_MASK(cpu_addr);
4207 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4209 case 0x2: /* load unsigned halfword */
4210 ABI32_MASK(cpu_addr);
4211 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4213 case 0x3: /* load double word */
4219 save_state(dc, cpu_cond);
4220 r_const = tcg_const_i32(7);
4221 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4222 r_const); // XXX remove
4223 tcg_temp_free(r_const);
4224 ABI32_MASK(cpu_addr);
4225 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4226 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4227 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4228 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4229 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4230 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4231 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4234 case 0x9: /* load signed byte */
4235 ABI32_MASK(cpu_addr);
4236 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4238 case 0xa: /* load signed halfword */
4239 ABI32_MASK(cpu_addr);
4240 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4242 case 0xd: /* ldstub -- XXX: should be atomically */
4246 ABI32_MASK(cpu_addr);
4247 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4248 r_const = tcg_const_tl(0xff);
4249 tcg_gen_qemu_st8(r_const, cpu_addr, dc->mem_idx);
4250 tcg_temp_free(r_const);
4253 case 0x0f: /* swap register with memory. Also
4255 CHECK_IU_FEATURE(dc, SWAP);
4256 gen_movl_reg_TN(rd, cpu_val);
4257 ABI32_MASK(cpu_addr);
4258 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4259 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4260 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4262 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4263 case 0x10: /* load word alternate */
4264 #ifndef TARGET_SPARC64
4267 if (!supervisor(dc))
4270 save_state(dc, cpu_cond);
4271 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4273 case 0x11: /* load unsigned byte alternate */
4274 #ifndef TARGET_SPARC64
4277 if (!supervisor(dc))
4280 save_state(dc, cpu_cond);
4281 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4283 case 0x12: /* load unsigned halfword alternate */
4284 #ifndef TARGET_SPARC64
4287 if (!supervisor(dc))
4290 save_state(dc, cpu_cond);
4291 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4293 case 0x13: /* load double word alternate */
4294 #ifndef TARGET_SPARC64
4297 if (!supervisor(dc))
4302 save_state(dc, cpu_cond);
4303 gen_ldda_asi(cpu_tmp0, cpu_val, cpu_addr, insn);
4304 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4306 case 0x19: /* load signed byte alternate */
4307 #ifndef TARGET_SPARC64
4310 if (!supervisor(dc))
4313 save_state(dc, cpu_cond);
4314 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4316 case 0x1a: /* load signed halfword alternate */
4317 #ifndef TARGET_SPARC64
4320 if (!supervisor(dc))
4323 save_state(dc, cpu_cond);
4324 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4326 case 0x1d: /* ldstuba -- XXX: should be atomically */
4327 #ifndef TARGET_SPARC64
4330 if (!supervisor(dc))
4333 save_state(dc, cpu_cond);
4334 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4336 case 0x1f: /* swap reg with alt. memory. Also
4338 CHECK_IU_FEATURE(dc, SWAP);
4339 #ifndef TARGET_SPARC64
4342 if (!supervisor(dc))
4345 save_state(dc, cpu_cond);
4346 gen_movl_reg_TN(rd, cpu_val);
4347 gen_swap_asi(cpu_val, cpu_addr, insn);
4350 #ifndef TARGET_SPARC64
4351 case 0x30: /* ldc */
4352 case 0x31: /* ldcsr */
4353 case 0x33: /* lddc */
4357 #ifdef TARGET_SPARC64
4358 case 0x08: /* V9 ldsw */
4359 ABI32_MASK(cpu_addr);
4360 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4362 case 0x0b: /* V9 ldx */
4363 ABI32_MASK(cpu_addr);
4364 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4366 case 0x18: /* V9 ldswa */
4367 save_state(dc, cpu_cond);
4368 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4370 case 0x1b: /* V9 ldxa */
4371 save_state(dc, cpu_cond);
4372 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4374 case 0x2d: /* V9 prefetch, no effect */
4376 case 0x30: /* V9 ldfa */
4377 save_state(dc, cpu_cond);
4378 gen_ldf_asi(cpu_addr, insn, 4, rd);
4380 case 0x33: /* V9 lddfa */
4381 save_state(dc, cpu_cond);
4382 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4384 case 0x3d: /* V9 prefetcha, no effect */
4386 case 0x32: /* V9 ldqfa */
4387 CHECK_FPU_FEATURE(dc, FLOAT128);
4388 save_state(dc, cpu_cond);
4389 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4395 gen_movl_TN_reg(rd, cpu_val);
4396 #ifdef TARGET_SPARC64
4399 } else if (xop >= 0x20 && xop < 0x24) {
4400 if (gen_trap_ifnofpu(dc, cpu_cond))
4402 save_state(dc, cpu_cond);
4404 case 0x20: /* load fpreg */
4405 ABI32_MASK(cpu_addr);
4406 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4407 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4408 offsetof(CPUState, fpr[rd]));
4410 case 0x21: /* load fsr */
4411 ABI32_MASK(cpu_addr);
4412 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4413 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4414 offsetof(CPUState, ft0));
4415 tcg_gen_helper_0_0(helper_ldfsr);
4417 case 0x22: /* load quad fpreg */
4421 CHECK_FPU_FEATURE(dc, FLOAT128);
4422 r_const = tcg_const_i32(dc->mem_idx);
4423 tcg_gen_helper_0_2(helper_ldqf, cpu_addr, r_const);
4424 tcg_temp_free(r_const);
4425 gen_op_store_QT0_fpr(QFPREG(rd));
4428 case 0x23: /* load double fpreg */
4432 r_const = tcg_const_i32(dc->mem_idx);
4433 tcg_gen_helper_0_2(helper_lddf, cpu_addr, r_const);
4434 tcg_temp_free(r_const);
4435 gen_op_store_DT0_fpr(DFPREG(rd));
4441 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4442 xop == 0xe || xop == 0x1e) {
4443 gen_movl_reg_TN(rd, cpu_val);
4445 case 0x4: /* store word */
4446 ABI32_MASK(cpu_addr);
4447 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4449 case 0x5: /* store byte */
4450 ABI32_MASK(cpu_addr);
4451 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4453 case 0x6: /* store halfword */
4454 ABI32_MASK(cpu_addr);
4455 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4457 case 0x7: /* store double word */
4461 TCGv r_low, r_const;
4463 save_state(dc, cpu_cond);
4464 ABI32_MASK(cpu_addr);
4465 r_const = tcg_const_i32(7);
4466 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4467 r_const); // XXX remove
4468 tcg_temp_free(r_const);
4469 r_low = tcg_temp_new(TCG_TYPE_TL);
4470 gen_movl_reg_TN(rd + 1, r_low);
4471 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4473 tcg_temp_free(r_low);
4474 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4477 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4478 case 0x14: /* store word alternate */
4479 #ifndef TARGET_SPARC64
4482 if (!supervisor(dc))
4485 save_state(dc, cpu_cond);
4486 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4488 case 0x15: /* store byte alternate */
4489 #ifndef TARGET_SPARC64
4492 if (!supervisor(dc))
4495 save_state(dc, cpu_cond);
4496 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4498 case 0x16: /* store halfword alternate */
4499 #ifndef TARGET_SPARC64
4502 if (!supervisor(dc))
4505 save_state(dc, cpu_cond);
4506 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4508 case 0x17: /* store double word alternate */
4509 #ifndef TARGET_SPARC64
4512 if (!supervisor(dc))
4518 save_state(dc, cpu_cond);
4519 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4523 #ifdef TARGET_SPARC64
4524 case 0x0e: /* V9 stx */
4525 ABI32_MASK(cpu_addr);
4526 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4528 case 0x1e: /* V9 stxa */
4529 save_state(dc, cpu_cond);
4530 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4536 } else if (xop > 0x23 && xop < 0x28) {
4537 if (gen_trap_ifnofpu(dc, cpu_cond))
4539 save_state(dc, cpu_cond);
4541 case 0x24: /* store fpreg */
4542 ABI32_MASK(cpu_addr);
4543 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4544 offsetof(CPUState, fpr[rd]));
4545 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4547 case 0x25: /* stfsr, V9 stxfsr */
4548 ABI32_MASK(cpu_addr);
4549 tcg_gen_helper_0_0(helper_stfsr);
4550 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4551 offsetof(CPUState, ft0));
4552 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4555 #ifdef TARGET_SPARC64
4556 /* V9 stqf, store quad fpreg */
4560 CHECK_FPU_FEATURE(dc, FLOAT128);
4561 gen_op_load_fpr_QT0(QFPREG(rd));
4562 r_const = tcg_const_i32(dc->mem_idx);
4563 tcg_gen_helper_0_2(helper_stqf, cpu_addr, r_const);
4564 tcg_temp_free(r_const);
4567 #else /* !TARGET_SPARC64 */
4568 /* stdfq, store floating point queue */
4569 #if defined(CONFIG_USER_ONLY)
4572 if (!supervisor(dc))
4574 if (gen_trap_ifnofpu(dc, cpu_cond))
4579 case 0x27: /* store double fpreg */
4583 gen_op_load_fpr_DT0(DFPREG(rd));
4584 r_const = tcg_const_i32(dc->mem_idx);
4585 tcg_gen_helper_0_2(helper_stdf, cpu_addr, r_const);
4586 tcg_temp_free(r_const);
4592 } else if (xop > 0x33 && xop < 0x3f) {
4593 save_state(dc, cpu_cond);
4595 #ifdef TARGET_SPARC64
4596 case 0x34: /* V9 stfa */
4597 gen_op_load_fpr_FT0(rd);
4598 gen_stf_asi(cpu_addr, insn, 4, rd);
4600 case 0x36: /* V9 stqfa */
4604 CHECK_FPU_FEATURE(dc, FLOAT128);
4605 r_const = tcg_const_i32(7);
4606 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4608 tcg_temp_free(r_const);
4609 gen_op_load_fpr_QT0(QFPREG(rd));
4610 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4613 case 0x37: /* V9 stdfa */
4614 gen_op_load_fpr_DT0(DFPREG(rd));
4615 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4617 case 0x3c: /* V9 casa */
4618 gen_cas_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4619 gen_movl_TN_reg(rd, cpu_val);
4621 case 0x3e: /* V9 casxa */
4622 gen_casx_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4623 gen_movl_TN_reg(rd, cpu_val);
4626 case 0x34: /* stc */
4627 case 0x35: /* stcsr */
4628 case 0x36: /* stdcq */
4629 case 0x37: /* stdc */
4641 /* default case for non jump instructions */
4642 if (dc->npc == DYNAMIC_PC) {
4643 dc->pc = DYNAMIC_PC;
4645 } else if (dc->npc == JUMP_PC) {
4646 /* we can do a static jump */
4647 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4651 dc->npc = dc->npc + 4;
4659 save_state(dc, cpu_cond);
4660 r_const = tcg_const_i32(TT_ILL_INSN);
4661 tcg_gen_helper_0_1(raise_exception, r_const);
4662 tcg_temp_free(r_const);
4670 save_state(dc, cpu_cond);
4671 r_const = tcg_const_i32(TT_UNIMP_FLUSH);
4672 tcg_gen_helper_0_1(raise_exception, r_const);
4673 tcg_temp_free(r_const);
4677 #if !defined(CONFIG_USER_ONLY)
4682 save_state(dc, cpu_cond);
4683 r_const = tcg_const_i32(TT_PRIV_INSN);
4684 tcg_gen_helper_0_1(raise_exception, r_const);
4685 tcg_temp_free(r_const);
4691 save_state(dc, cpu_cond);
4692 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4695 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4697 save_state(dc, cpu_cond);
4698 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4702 #ifndef TARGET_SPARC64
4707 save_state(dc, cpu_cond);
4708 r_const = tcg_const_i32(TT_NCP_INSN);
4709 tcg_gen_helper_0_1(raise_exception, r_const);
4710 tcg_temp_free(r_const);
4717 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4718 int spc, CPUSPARCState *env)
4720 target_ulong pc_start, last_pc;
4721 uint16_t *gen_opc_end;
4722 DisasContext dc1, *dc = &dc1;
4727 memset(dc, 0, sizeof(DisasContext));
4732 dc->npc = (target_ulong) tb->cs_base;
4733 dc->mem_idx = cpu_mmu_index(env);
4734 dc->features = env->features;
4735 if ((dc->features & CPU_FEATURE_FLOAT)) {
4736 dc->fpu_enabled = cpu_fpu_enabled(env);
4737 #if defined(CONFIG_USER_ONLY)
4738 dc->features |= CPU_FEATURE_FLOAT128;
4741 dc->fpu_enabled = 0;
4742 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4744 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4745 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4746 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4748 cpu_dst = tcg_temp_local_new(TCG_TYPE_TL);
4751 cpu_val = tcg_temp_local_new(TCG_TYPE_TL);
4752 cpu_addr = tcg_temp_local_new(TCG_TYPE_TL);
4755 max_insns = tb->cflags & CF_COUNT_MASK;
4757 max_insns = CF_COUNT_MASK;
4760 if (env->nb_breakpoints > 0) {
4761 for(j = 0; j < env->nb_breakpoints; j++) {
4762 if (env->breakpoints[j] == dc->pc) {
4763 if (dc->pc != pc_start)
4764 save_state(dc, cpu_cond);
4765 tcg_gen_helper_0_0(helper_debug);
4774 fprintf(logfile, "Search PC...\n");
4775 j = gen_opc_ptr - gen_opc_buf;
4779 gen_opc_instr_start[lj++] = 0;
4780 gen_opc_pc[lj] = dc->pc;
4781 gen_opc_npc[lj] = dc->npc;
4782 gen_opc_instr_start[lj] = 1;
4783 gen_opc_icount[lj] = num_insns;
4786 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
4789 disas_sparc_insn(dc);
4794 /* if the next PC is different, we abort now */
4795 if (dc->pc != (last_pc + 4))
4797 /* if we reach a page boundary, we stop generation so that the
4798 PC of a TT_TFAULT exception is always in the right page */
4799 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4801 /* if single step mode, we generate only one instruction and
4802 generate an exception */
4803 if (env->singlestep_enabled) {
4804 tcg_gen_movi_tl(cpu_pc, dc->pc);
4808 } while ((gen_opc_ptr < gen_opc_end) &&
4809 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
4810 num_insns < max_insns);
4813 tcg_temp_free(cpu_addr);
4814 tcg_temp_free(cpu_val);
4815 tcg_temp_free(cpu_dst);
4816 tcg_temp_free(cpu_tmp64);
4817 tcg_temp_free(cpu_tmp32);
4818 tcg_temp_free(cpu_tmp0);
4819 if (tb->cflags & CF_LAST_IO)
4822 if (dc->pc != DYNAMIC_PC &&
4823 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4824 /* static PC and NPC: we can use direct chaining */
4825 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4827 if (dc->pc != DYNAMIC_PC)
4828 tcg_gen_movi_tl(cpu_pc, dc->pc);
4829 save_npc(dc, cpu_cond);
4833 gen_icount_end(tb, num_insns);
4834 *gen_opc_ptr = INDEX_op_end;
4836 j = gen_opc_ptr - gen_opc_buf;
4839 gen_opc_instr_start[lj++] = 0;
4845 gen_opc_jump_pc[0] = dc->jump_pc[0];
4846 gen_opc_jump_pc[1] = dc->jump_pc[1];
4848 tb->size = last_pc + 4 - pc_start;
4849 tb->icount = num_insns;
4852 if (loglevel & CPU_LOG_TB_IN_ASM) {
4853 fprintf(logfile, "--------------\n");
4854 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4855 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4856 fprintf(logfile, "\n");
4862 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4864 return gen_intermediate_code_internal(tb, 0, env);
4867 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4869 return gen_intermediate_code_internal(tb, 1, env);
4872 void gen_intermediate_code_init(CPUSPARCState *env)
4876 static const char * const gregnames[8] = {
4877 NULL, // g0 not used
4887 /* init various static tables */
4891 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4892 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4893 offsetof(CPUState, regwptr),
4895 #ifdef TARGET_SPARC64
4896 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4897 TCG_AREG0, offsetof(CPUState, xcc),
4900 cpu_cond = tcg_global_mem_new(TCG_TYPE_TL,
4901 TCG_AREG0, offsetof(CPUState, cond),
4903 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4904 TCG_AREG0, offsetof(CPUState, cc_src),
4906 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4907 offsetof(CPUState, cc_src2),
4909 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4910 TCG_AREG0, offsetof(CPUState, cc_dst),
4912 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4913 TCG_AREG0, offsetof(CPUState, psr),
4915 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4916 TCG_AREG0, offsetof(CPUState, fsr),
4918 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4919 TCG_AREG0, offsetof(CPUState, pc),
4921 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4922 TCG_AREG0, offsetof(CPUState, npc),
4924 for (i = 1; i < 8; i++)
4925 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4926 offsetof(CPUState, gregs[i]),
4928 /* register helpers */
4931 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
4936 void gen_pc_load(CPUState *env, TranslationBlock *tb,
4937 unsigned long searched_pc, int pc_pos, void *puc)
4940 env->pc = gen_opc_pc[pc_pos];
4941 npc = gen_opc_npc[pc_pos];
4943 /* dynamic NPC: already stored */
4944 } else if (npc == 2) {
4945 target_ulong t2 = (target_ulong)(unsigned long)puc;
4946 /* jump PC: use T2 and the jump targets of the translation */
4948 env->npc = gen_opc_jump_pc[0];
4950 env->npc = gen_opc_jump_pc[1];