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, see <http://www.gnu.org/licenses/>.
28 #include "disas/disas.h"
29 #include "exec/helper-proto.h"
31 #include "exec/cpu_ldst.h"
33 #include "exec/helper-gen.h"
35 #include "trace-tcg.h"
40 #define DYNAMIC_PC 1 /* dynamic pc value */
41 #define JUMP_PC 2 /* dynamic pc value which takes only two values
42 according to jump_pc[T2] */
44 /* global register indexes */
45 static TCGv_ptr cpu_env, cpu_regwptr;
46 static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
47 static TCGv_i32 cpu_cc_op;
48 static TCGv_i32 cpu_psr;
49 static TCGv cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8];
51 #ifndef CONFIG_USER_ONLY
56 static TCGv_i32 cpu_xcc, cpu_asi, cpu_fprs;
58 static TCGv cpu_tick_cmpr, cpu_stick_cmpr, cpu_hstick_cmpr;
59 static TCGv cpu_hintp, cpu_htba, cpu_hver, cpu_ssr, cpu_ver;
60 static TCGv_i32 cpu_softint;
64 /* Floating point registers */
65 static TCGv_i64 cpu_fpr[TARGET_DPREGS];
67 static target_ulong gen_opc_npc[OPC_BUF_SIZE];
69 #include "exec/gen-icount.h"
71 typedef struct DisasContext {
72 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
73 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
74 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
78 int address_mask_32bit;
80 uint32_t cc_op; /* current CC operation */
81 struct TranslationBlock *tb;
96 // This function uses non-native bit order
97 #define GET_FIELD(X, FROM, TO) \
98 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
100 // This function uses the order in the manuals, i.e. bit 0 is 2^0
101 #define GET_FIELD_SP(X, FROM, TO) \
102 GET_FIELD(X, 31 - (TO), 31 - (FROM))
104 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
105 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
107 #ifdef TARGET_SPARC64
108 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
109 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
111 #define DFPREG(r) (r & 0x1e)
112 #define QFPREG(r) (r & 0x1c)
115 #define UA2005_HTRAP_MASK 0xff
116 #define V8_TRAP_MASK 0x7f
118 static int sign_extend(int x, int len)
121 return (x << len) >> len;
124 #define IS_IMM (insn & (1<<13))
126 static inline TCGv_i32 get_temp_i32(DisasContext *dc)
129 assert(dc->n_t32 < ARRAY_SIZE(dc->t32));
130 dc->t32[dc->n_t32++] = t = tcg_temp_new_i32();
134 static inline TCGv get_temp_tl(DisasContext *dc)
137 assert(dc->n_ttl < ARRAY_SIZE(dc->ttl));
138 dc->ttl[dc->n_ttl++] = t = tcg_temp_new();
142 static inline void gen_update_fprs_dirty(int rd)
144 #if defined(TARGET_SPARC64)
145 tcg_gen_ori_i32(cpu_fprs, cpu_fprs, (rd < 32) ? 1 : 2);
149 /* floating point registers moves */
150 static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
152 #if TCG_TARGET_REG_BITS == 32
154 return TCGV_LOW(cpu_fpr[src / 2]);
156 return TCGV_HIGH(cpu_fpr[src / 2]);
160 return MAKE_TCGV_I32(GET_TCGV_I64(cpu_fpr[src / 2]));
162 TCGv_i32 ret = get_temp_i32(dc);
163 TCGv_i64 t = tcg_temp_new_i64();
165 tcg_gen_shri_i64(t, cpu_fpr[src / 2], 32);
166 tcg_gen_extrl_i64_i32(ret, t);
167 tcg_temp_free_i64(t);
174 static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
176 #if TCG_TARGET_REG_BITS == 32
178 tcg_gen_mov_i32(TCGV_LOW(cpu_fpr[dst / 2]), v);
180 tcg_gen_mov_i32(TCGV_HIGH(cpu_fpr[dst / 2]), v);
183 TCGv_i64 t = MAKE_TCGV_I64(GET_TCGV_I32(v));
184 tcg_gen_deposit_i64(cpu_fpr[dst / 2], cpu_fpr[dst / 2], t,
185 (dst & 1 ? 0 : 32), 32);
187 gen_update_fprs_dirty(dst);
190 static TCGv_i32 gen_dest_fpr_F(DisasContext *dc)
192 return get_temp_i32(dc);
195 static TCGv_i64 gen_load_fpr_D(DisasContext *dc, unsigned int src)
198 return cpu_fpr[src / 2];
201 static void gen_store_fpr_D(DisasContext *dc, unsigned int dst, TCGv_i64 v)
204 tcg_gen_mov_i64(cpu_fpr[dst / 2], v);
205 gen_update_fprs_dirty(dst);
208 static TCGv_i64 gen_dest_fpr_D(DisasContext *dc, unsigned int dst)
210 return cpu_fpr[DFPREG(dst) / 2];
213 static void gen_op_load_fpr_QT0(unsigned int src)
215 tcg_gen_st_i64(cpu_fpr[src / 2], cpu_env, offsetof(CPUSPARCState, qt0) +
216 offsetof(CPU_QuadU, ll.upper));
217 tcg_gen_st_i64(cpu_fpr[src/2 + 1], cpu_env, offsetof(CPUSPARCState, qt0) +
218 offsetof(CPU_QuadU, ll.lower));
221 static void gen_op_load_fpr_QT1(unsigned int src)
223 tcg_gen_st_i64(cpu_fpr[src / 2], cpu_env, offsetof(CPUSPARCState, qt1) +
224 offsetof(CPU_QuadU, ll.upper));
225 tcg_gen_st_i64(cpu_fpr[src/2 + 1], cpu_env, offsetof(CPUSPARCState, qt1) +
226 offsetof(CPU_QuadU, ll.lower));
229 static void gen_op_store_QT0_fpr(unsigned int dst)
231 tcg_gen_ld_i64(cpu_fpr[dst / 2], cpu_env, offsetof(CPUSPARCState, qt0) +
232 offsetof(CPU_QuadU, ll.upper));
233 tcg_gen_ld_i64(cpu_fpr[dst/2 + 1], cpu_env, offsetof(CPUSPARCState, qt0) +
234 offsetof(CPU_QuadU, ll.lower));
237 #ifdef TARGET_SPARC64
238 static void gen_move_Q(unsigned int rd, unsigned int rs)
243 tcg_gen_mov_i64(cpu_fpr[rd / 2], cpu_fpr[rs / 2]);
244 tcg_gen_mov_i64(cpu_fpr[rd / 2 + 1], cpu_fpr[rs / 2 + 1]);
245 gen_update_fprs_dirty(rd);
250 #ifdef CONFIG_USER_ONLY
251 #define supervisor(dc) 0
252 #ifdef TARGET_SPARC64
253 #define hypervisor(dc) 0
256 #define supervisor(dc) (dc->mem_idx >= MMU_KERNEL_IDX)
257 #ifdef TARGET_SPARC64
258 #define hypervisor(dc) (dc->mem_idx == MMU_HYPV_IDX)
263 #ifdef TARGET_SPARC64
265 #define AM_CHECK(dc) ((dc)->address_mask_32bit)
267 #define AM_CHECK(dc) (1)
271 static inline void gen_address_mask(DisasContext *dc, TCGv addr)
273 #ifdef TARGET_SPARC64
275 tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
279 static inline TCGv gen_load_gpr(DisasContext *dc, int reg)
281 if (reg == 0 || reg >= 8) {
282 TCGv t = get_temp_tl(dc);
284 tcg_gen_movi_tl(t, 0);
286 tcg_gen_ld_tl(t, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
290 return cpu_gregs[reg];
294 static inline void gen_store_gpr(DisasContext *dc, int reg, TCGv v)
298 tcg_gen_mov_tl(cpu_gregs[reg], v);
300 tcg_gen_st_tl(v, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
305 static inline TCGv gen_dest_gpr(DisasContext *dc, int reg)
307 if (reg == 0 || reg >= 8) {
308 return get_temp_tl(dc);
310 return cpu_gregs[reg];
314 static inline void gen_goto_tb(DisasContext *s, int tb_num,
315 target_ulong pc, target_ulong npc)
317 TranslationBlock *tb;
320 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
321 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
323 /* jump to same page: we can use a direct jump */
324 tcg_gen_goto_tb(tb_num);
325 tcg_gen_movi_tl(cpu_pc, pc);
326 tcg_gen_movi_tl(cpu_npc, npc);
327 tcg_gen_exit_tb((uintptr_t)tb + tb_num);
329 /* jump to another page: currently not optimized */
330 tcg_gen_movi_tl(cpu_pc, pc);
331 tcg_gen_movi_tl(cpu_npc, npc);
337 static inline void gen_mov_reg_N(TCGv reg, TCGv_i32 src)
339 tcg_gen_extu_i32_tl(reg, src);
340 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
341 tcg_gen_andi_tl(reg, reg, 0x1);
344 static inline void gen_mov_reg_Z(TCGv reg, TCGv_i32 src)
346 tcg_gen_extu_i32_tl(reg, src);
347 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
348 tcg_gen_andi_tl(reg, reg, 0x1);
351 static inline void gen_mov_reg_V(TCGv reg, TCGv_i32 src)
353 tcg_gen_extu_i32_tl(reg, src);
354 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
355 tcg_gen_andi_tl(reg, reg, 0x1);
358 static inline void gen_mov_reg_C(TCGv reg, TCGv_i32 src)
360 tcg_gen_extu_i32_tl(reg, src);
361 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
362 tcg_gen_andi_tl(reg, reg, 0x1);
365 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
367 tcg_gen_mov_tl(cpu_cc_src, src1);
368 tcg_gen_mov_tl(cpu_cc_src2, src2);
369 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
370 tcg_gen_mov_tl(dst, cpu_cc_dst);
373 static TCGv_i32 gen_add32_carry32(void)
375 TCGv_i32 carry_32, cc_src1_32, cc_src2_32;
377 /* Carry is computed from a previous add: (dst < src) */
378 #if TARGET_LONG_BITS == 64
379 cc_src1_32 = tcg_temp_new_i32();
380 cc_src2_32 = tcg_temp_new_i32();
381 tcg_gen_extrl_i64_i32(cc_src1_32, cpu_cc_dst);
382 tcg_gen_extrl_i64_i32(cc_src2_32, cpu_cc_src);
384 cc_src1_32 = cpu_cc_dst;
385 cc_src2_32 = cpu_cc_src;
388 carry_32 = tcg_temp_new_i32();
389 tcg_gen_setcond_i32(TCG_COND_LTU, carry_32, cc_src1_32, cc_src2_32);
391 #if TARGET_LONG_BITS == 64
392 tcg_temp_free_i32(cc_src1_32);
393 tcg_temp_free_i32(cc_src2_32);
399 static TCGv_i32 gen_sub32_carry32(void)
401 TCGv_i32 carry_32, cc_src1_32, cc_src2_32;
403 /* Carry is computed from a previous borrow: (src1 < src2) */
404 #if TARGET_LONG_BITS == 64
405 cc_src1_32 = tcg_temp_new_i32();
406 cc_src2_32 = tcg_temp_new_i32();
407 tcg_gen_extrl_i64_i32(cc_src1_32, cpu_cc_src);
408 tcg_gen_extrl_i64_i32(cc_src2_32, cpu_cc_src2);
410 cc_src1_32 = cpu_cc_src;
411 cc_src2_32 = cpu_cc_src2;
414 carry_32 = tcg_temp_new_i32();
415 tcg_gen_setcond_i32(TCG_COND_LTU, carry_32, cc_src1_32, cc_src2_32);
417 #if TARGET_LONG_BITS == 64
418 tcg_temp_free_i32(cc_src1_32);
419 tcg_temp_free_i32(cc_src2_32);
425 static void gen_op_addx_int(DisasContext *dc, TCGv dst, TCGv src1,
426 TCGv src2, int update_cc)
434 /* Carry is known to be zero. Fall back to plain ADD. */
436 gen_op_add_cc(dst, src1, src2);
438 tcg_gen_add_tl(dst, src1, src2);
445 if (TARGET_LONG_BITS == 32) {
446 /* We can re-use the host's hardware carry generation by using
447 an ADD2 opcode. We discard the low part of the output.
448 Ideally we'd combine this operation with the add that
449 generated the carry in the first place. */
450 carry = tcg_temp_new();
451 tcg_gen_add2_tl(carry, dst, cpu_cc_src, src1, cpu_cc_src2, src2);
452 tcg_temp_free(carry);
455 carry_32 = gen_add32_carry32();
461 carry_32 = gen_sub32_carry32();
465 /* We need external help to produce the carry. */
466 carry_32 = tcg_temp_new_i32();
467 gen_helper_compute_C_icc(carry_32, cpu_env);
471 #if TARGET_LONG_BITS == 64
472 carry = tcg_temp_new();
473 tcg_gen_extu_i32_i64(carry, carry_32);
478 tcg_gen_add_tl(dst, src1, src2);
479 tcg_gen_add_tl(dst, dst, carry);
481 tcg_temp_free_i32(carry_32);
482 #if TARGET_LONG_BITS == 64
483 tcg_temp_free(carry);
488 tcg_gen_mov_tl(cpu_cc_src, src1);
489 tcg_gen_mov_tl(cpu_cc_src2, src2);
490 tcg_gen_mov_tl(cpu_cc_dst, dst);
491 tcg_gen_movi_i32(cpu_cc_op, CC_OP_ADDX);
492 dc->cc_op = CC_OP_ADDX;
496 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
498 tcg_gen_mov_tl(cpu_cc_src, src1);
499 tcg_gen_mov_tl(cpu_cc_src2, src2);
500 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
501 tcg_gen_mov_tl(dst, cpu_cc_dst);
504 static void gen_op_subx_int(DisasContext *dc, TCGv dst, TCGv src1,
505 TCGv src2, int update_cc)
513 /* Carry is known to be zero. Fall back to plain SUB. */
515 gen_op_sub_cc(dst, src1, src2);
517 tcg_gen_sub_tl(dst, src1, src2);
524 carry_32 = gen_add32_carry32();
530 if (TARGET_LONG_BITS == 32) {
531 /* We can re-use the host's hardware carry generation by using
532 a SUB2 opcode. We discard the low part of the output.
533 Ideally we'd combine this operation with the add that
534 generated the carry in the first place. */
535 carry = tcg_temp_new();
536 tcg_gen_sub2_tl(carry, dst, cpu_cc_src, src1, cpu_cc_src2, src2);
537 tcg_temp_free(carry);
540 carry_32 = gen_sub32_carry32();
544 /* We need external help to produce the carry. */
545 carry_32 = tcg_temp_new_i32();
546 gen_helper_compute_C_icc(carry_32, cpu_env);
550 #if TARGET_LONG_BITS == 64
551 carry = tcg_temp_new();
552 tcg_gen_extu_i32_i64(carry, carry_32);
557 tcg_gen_sub_tl(dst, src1, src2);
558 tcg_gen_sub_tl(dst, dst, carry);
560 tcg_temp_free_i32(carry_32);
561 #if TARGET_LONG_BITS == 64
562 tcg_temp_free(carry);
567 tcg_gen_mov_tl(cpu_cc_src, src1);
568 tcg_gen_mov_tl(cpu_cc_src2, src2);
569 tcg_gen_mov_tl(cpu_cc_dst, dst);
570 tcg_gen_movi_i32(cpu_cc_op, CC_OP_SUBX);
571 dc->cc_op = CC_OP_SUBX;
575 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
577 TCGv r_temp, zero, t0;
579 r_temp = tcg_temp_new();
586 zero = tcg_const_tl(0);
587 tcg_gen_andi_tl(cpu_cc_src, src1, 0xffffffff);
588 tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
589 tcg_gen_andi_tl(cpu_cc_src2, src2, 0xffffffff);
590 tcg_gen_movcond_tl(TCG_COND_EQ, cpu_cc_src2, r_temp, zero,
595 // env->y = (b2 << 31) | (env->y >> 1);
596 tcg_gen_andi_tl(r_temp, cpu_cc_src, 0x1);
597 tcg_gen_shli_tl(r_temp, r_temp, 31);
598 tcg_gen_shri_tl(t0, cpu_y, 1);
599 tcg_gen_andi_tl(t0, t0, 0x7fffffff);
600 tcg_gen_or_tl(t0, t0, r_temp);
601 tcg_gen_andi_tl(cpu_y, t0, 0xffffffff);
604 gen_mov_reg_N(t0, cpu_psr);
605 gen_mov_reg_V(r_temp, cpu_psr);
606 tcg_gen_xor_tl(t0, t0, r_temp);
607 tcg_temp_free(r_temp);
609 // T0 = (b1 << 31) | (T0 >> 1);
611 tcg_gen_shli_tl(t0, t0, 31);
612 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
613 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t0);
616 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
618 tcg_gen_mov_tl(dst, cpu_cc_dst);
621 static inline void gen_op_multiply(TCGv dst, TCGv src1, TCGv src2, int sign_ext)
623 #if TARGET_LONG_BITS == 32
625 tcg_gen_muls2_tl(dst, cpu_y, src1, src2);
627 tcg_gen_mulu2_tl(dst, cpu_y, src1, src2);
630 TCGv t0 = tcg_temp_new_i64();
631 TCGv t1 = tcg_temp_new_i64();
634 tcg_gen_ext32s_i64(t0, src1);
635 tcg_gen_ext32s_i64(t1, src2);
637 tcg_gen_ext32u_i64(t0, src1);
638 tcg_gen_ext32u_i64(t1, src2);
641 tcg_gen_mul_i64(dst, t0, t1);
645 tcg_gen_shri_i64(cpu_y, dst, 32);
649 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
651 /* zero-extend truncated operands before multiplication */
652 gen_op_multiply(dst, src1, src2, 0);
655 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
657 /* sign-extend truncated operands before multiplication */
658 gen_op_multiply(dst, src1, src2, 1);
662 static inline void gen_op_eval_ba(TCGv dst)
664 tcg_gen_movi_tl(dst, 1);
668 static inline void gen_op_eval_be(TCGv dst, TCGv_i32 src)
670 gen_mov_reg_Z(dst, src);
674 static inline void gen_op_eval_ble(TCGv dst, TCGv_i32 src)
676 TCGv t0 = tcg_temp_new();
677 gen_mov_reg_N(t0, src);
678 gen_mov_reg_V(dst, src);
679 tcg_gen_xor_tl(dst, dst, t0);
680 gen_mov_reg_Z(t0, src);
681 tcg_gen_or_tl(dst, dst, t0);
686 static inline void gen_op_eval_bl(TCGv dst, TCGv_i32 src)
688 TCGv t0 = tcg_temp_new();
689 gen_mov_reg_V(t0, src);
690 gen_mov_reg_N(dst, src);
691 tcg_gen_xor_tl(dst, dst, t0);
696 static inline void gen_op_eval_bleu(TCGv dst, TCGv_i32 src)
698 TCGv t0 = tcg_temp_new();
699 gen_mov_reg_Z(t0, src);
700 gen_mov_reg_C(dst, src);
701 tcg_gen_or_tl(dst, dst, t0);
706 static inline void gen_op_eval_bcs(TCGv dst, TCGv_i32 src)
708 gen_mov_reg_C(dst, src);
712 static inline void gen_op_eval_bvs(TCGv dst, TCGv_i32 src)
714 gen_mov_reg_V(dst, src);
718 static inline void gen_op_eval_bn(TCGv dst)
720 tcg_gen_movi_tl(dst, 0);
724 static inline void gen_op_eval_bneg(TCGv dst, TCGv_i32 src)
726 gen_mov_reg_N(dst, src);
730 static inline void gen_op_eval_bne(TCGv dst, TCGv_i32 src)
732 gen_mov_reg_Z(dst, src);
733 tcg_gen_xori_tl(dst, dst, 0x1);
737 static inline void gen_op_eval_bg(TCGv dst, TCGv_i32 src)
739 gen_op_eval_ble(dst, src);
740 tcg_gen_xori_tl(dst, dst, 0x1);
744 static inline void gen_op_eval_bge(TCGv dst, TCGv_i32 src)
746 gen_op_eval_bl(dst, src);
747 tcg_gen_xori_tl(dst, dst, 0x1);
751 static inline void gen_op_eval_bgu(TCGv dst, TCGv_i32 src)
753 gen_op_eval_bleu(dst, src);
754 tcg_gen_xori_tl(dst, dst, 0x1);
758 static inline void gen_op_eval_bcc(TCGv dst, TCGv_i32 src)
760 gen_mov_reg_C(dst, src);
761 tcg_gen_xori_tl(dst, dst, 0x1);
765 static inline void gen_op_eval_bpos(TCGv dst, TCGv_i32 src)
767 gen_mov_reg_N(dst, src);
768 tcg_gen_xori_tl(dst, dst, 0x1);
772 static inline void gen_op_eval_bvc(TCGv dst, TCGv_i32 src)
774 gen_mov_reg_V(dst, src);
775 tcg_gen_xori_tl(dst, dst, 0x1);
779 FPSR bit field FCC1 | FCC0:
785 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
786 unsigned int fcc_offset)
788 tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
789 tcg_gen_andi_tl(reg, reg, 0x1);
792 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
793 unsigned int fcc_offset)
795 tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
796 tcg_gen_andi_tl(reg, reg, 0x1);
800 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
801 unsigned int fcc_offset)
803 TCGv t0 = tcg_temp_new();
804 gen_mov_reg_FCC0(dst, src, fcc_offset);
805 gen_mov_reg_FCC1(t0, src, fcc_offset);
806 tcg_gen_or_tl(dst, dst, t0);
810 // 1 or 2: FCC0 ^ FCC1
811 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
812 unsigned int fcc_offset)
814 TCGv t0 = tcg_temp_new();
815 gen_mov_reg_FCC0(dst, src, fcc_offset);
816 gen_mov_reg_FCC1(t0, src, fcc_offset);
817 tcg_gen_xor_tl(dst, dst, t0);
822 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
823 unsigned int fcc_offset)
825 gen_mov_reg_FCC0(dst, src, fcc_offset);
829 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
830 unsigned int fcc_offset)
832 TCGv t0 = tcg_temp_new();
833 gen_mov_reg_FCC0(dst, src, fcc_offset);
834 gen_mov_reg_FCC1(t0, src, fcc_offset);
835 tcg_gen_andc_tl(dst, dst, t0);
840 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
841 unsigned int fcc_offset)
843 gen_mov_reg_FCC1(dst, src, fcc_offset);
847 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
848 unsigned int fcc_offset)
850 TCGv t0 = tcg_temp_new();
851 gen_mov_reg_FCC0(dst, src, fcc_offset);
852 gen_mov_reg_FCC1(t0, src, fcc_offset);
853 tcg_gen_andc_tl(dst, t0, dst);
858 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
859 unsigned int fcc_offset)
861 TCGv t0 = tcg_temp_new();
862 gen_mov_reg_FCC0(dst, src, fcc_offset);
863 gen_mov_reg_FCC1(t0, src, fcc_offset);
864 tcg_gen_and_tl(dst, dst, t0);
869 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
870 unsigned int fcc_offset)
872 TCGv t0 = tcg_temp_new();
873 gen_mov_reg_FCC0(dst, src, fcc_offset);
874 gen_mov_reg_FCC1(t0, src, fcc_offset);
875 tcg_gen_or_tl(dst, dst, t0);
876 tcg_gen_xori_tl(dst, dst, 0x1);
880 // 0 or 3: !(FCC0 ^ FCC1)
881 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
882 unsigned int fcc_offset)
884 TCGv t0 = tcg_temp_new();
885 gen_mov_reg_FCC0(dst, src, fcc_offset);
886 gen_mov_reg_FCC1(t0, src, fcc_offset);
887 tcg_gen_xor_tl(dst, dst, t0);
888 tcg_gen_xori_tl(dst, dst, 0x1);
893 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
894 unsigned int fcc_offset)
896 gen_mov_reg_FCC0(dst, src, fcc_offset);
897 tcg_gen_xori_tl(dst, dst, 0x1);
900 // !1: !(FCC0 & !FCC1)
901 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
902 unsigned int fcc_offset)
904 TCGv t0 = tcg_temp_new();
905 gen_mov_reg_FCC0(dst, src, fcc_offset);
906 gen_mov_reg_FCC1(t0, src, fcc_offset);
907 tcg_gen_andc_tl(dst, dst, t0);
908 tcg_gen_xori_tl(dst, dst, 0x1);
913 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
914 unsigned int fcc_offset)
916 gen_mov_reg_FCC1(dst, src, fcc_offset);
917 tcg_gen_xori_tl(dst, dst, 0x1);
920 // !2: !(!FCC0 & FCC1)
921 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
922 unsigned int fcc_offset)
924 TCGv t0 = tcg_temp_new();
925 gen_mov_reg_FCC0(dst, src, fcc_offset);
926 gen_mov_reg_FCC1(t0, src, fcc_offset);
927 tcg_gen_andc_tl(dst, t0, dst);
928 tcg_gen_xori_tl(dst, dst, 0x1);
932 // !3: !(FCC0 & FCC1)
933 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
934 unsigned int fcc_offset)
936 TCGv t0 = tcg_temp_new();
937 gen_mov_reg_FCC0(dst, src, fcc_offset);
938 gen_mov_reg_FCC1(t0, src, fcc_offset);
939 tcg_gen_and_tl(dst, dst, t0);
940 tcg_gen_xori_tl(dst, dst, 0x1);
944 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
945 target_ulong pc2, TCGv r_cond)
947 TCGLabel *l1 = gen_new_label();
949 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
951 gen_goto_tb(dc, 0, pc1, pc1 + 4);
954 gen_goto_tb(dc, 1, pc2, pc2 + 4);
957 static void gen_branch_a(DisasContext *dc, target_ulong pc1)
959 TCGLabel *l1 = gen_new_label();
960 target_ulong npc = dc->npc;
962 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cond, 0, l1);
964 gen_goto_tb(dc, 0, npc, pc1);
967 gen_goto_tb(dc, 1, npc + 4, npc + 8);
972 static void gen_branch_n(DisasContext *dc, target_ulong pc1)
974 target_ulong npc = dc->npc;
976 if (likely(npc != DYNAMIC_PC)) {
978 dc->jump_pc[0] = pc1;
979 dc->jump_pc[1] = npc + 4;
984 tcg_gen_mov_tl(cpu_pc, cpu_npc);
986 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
987 t = tcg_const_tl(pc1);
989 tcg_gen_movcond_tl(TCG_COND_NE, cpu_npc, cpu_cond, z, t, cpu_npc);
997 static inline void gen_generic_branch(DisasContext *dc)
999 TCGv npc0 = tcg_const_tl(dc->jump_pc[0]);
1000 TCGv npc1 = tcg_const_tl(dc->jump_pc[1]);
1001 TCGv zero = tcg_const_tl(0);
1003 tcg_gen_movcond_tl(TCG_COND_NE, cpu_npc, cpu_cond, zero, npc0, npc1);
1005 tcg_temp_free(npc0);
1006 tcg_temp_free(npc1);
1007 tcg_temp_free(zero);
1010 /* call this function before using the condition register as it may
1011 have been set for a jump */
1012 static inline void flush_cond(DisasContext *dc)
1014 if (dc->npc == JUMP_PC) {
1015 gen_generic_branch(dc);
1016 dc->npc = DYNAMIC_PC;
1020 static inline void save_npc(DisasContext *dc)
1022 if (dc->npc == JUMP_PC) {
1023 gen_generic_branch(dc);
1024 dc->npc = DYNAMIC_PC;
1025 } else if (dc->npc != DYNAMIC_PC) {
1026 tcg_gen_movi_tl(cpu_npc, dc->npc);
1030 static inline void update_psr(DisasContext *dc)
1032 if (dc->cc_op != CC_OP_FLAGS) {
1033 dc->cc_op = CC_OP_FLAGS;
1034 gen_helper_compute_psr(cpu_env);
1038 static inline void save_state(DisasContext *dc)
1040 tcg_gen_movi_tl(cpu_pc, dc->pc);
1044 static inline void gen_mov_pc_npc(DisasContext *dc)
1046 if (dc->npc == JUMP_PC) {
1047 gen_generic_branch(dc);
1048 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1049 dc->pc = DYNAMIC_PC;
1050 } else if (dc->npc == DYNAMIC_PC) {
1051 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1052 dc->pc = DYNAMIC_PC;
1058 static inline void gen_op_next_insn(void)
1060 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1061 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1064 static void free_compare(DisasCompare *cmp)
1067 tcg_temp_free(cmp->c1);
1070 tcg_temp_free(cmp->c2);
1074 static void gen_compare(DisasCompare *cmp, bool xcc, unsigned int cond,
1077 static int subcc_cond[16] = {
1093 -1, /* no overflow */
1096 static int logic_cond[16] = {
1098 TCG_COND_EQ, /* eq: Z */
1099 TCG_COND_LE, /* le: Z | (N ^ V) -> Z | N */
1100 TCG_COND_LT, /* lt: N ^ V -> N */
1101 TCG_COND_EQ, /* leu: C | Z -> Z */
1102 TCG_COND_NEVER, /* ltu: C -> 0 */
1103 TCG_COND_LT, /* neg: N */
1104 TCG_COND_NEVER, /* vs: V -> 0 */
1106 TCG_COND_NE, /* ne: !Z */
1107 TCG_COND_GT, /* gt: !(Z | (N ^ V)) -> !(Z | N) */
1108 TCG_COND_GE, /* ge: !(N ^ V) -> !N */
1109 TCG_COND_NE, /* gtu: !(C | Z) -> !Z */
1110 TCG_COND_ALWAYS, /* geu: !C -> 1 */
1111 TCG_COND_GE, /* pos: !N */
1112 TCG_COND_ALWAYS, /* vc: !V -> 1 */
1118 #ifdef TARGET_SPARC64
1128 switch (dc->cc_op) {
1130 cmp->cond = logic_cond[cond];
1132 cmp->is_bool = false;
1134 cmp->c2 = tcg_const_tl(0);
1135 #ifdef TARGET_SPARC64
1138 cmp->c1 = tcg_temp_new();
1139 tcg_gen_ext32s_tl(cmp->c1, cpu_cc_dst);
1144 cmp->c1 = cpu_cc_dst;
1151 cmp->cond = (cond == 6 ? TCG_COND_LT : TCG_COND_GE);
1152 goto do_compare_dst_0;
1154 case 7: /* overflow */
1155 case 15: /* !overflow */
1159 cmp->cond = subcc_cond[cond];
1160 cmp->is_bool = false;
1161 #ifdef TARGET_SPARC64
1163 /* Note that sign-extension works for unsigned compares as
1164 long as both operands are sign-extended. */
1165 cmp->g1 = cmp->g2 = false;
1166 cmp->c1 = tcg_temp_new();
1167 cmp->c2 = tcg_temp_new();
1168 tcg_gen_ext32s_tl(cmp->c1, cpu_cc_src);
1169 tcg_gen_ext32s_tl(cmp->c2, cpu_cc_src2);
1173 cmp->g1 = cmp->g2 = true;
1174 cmp->c1 = cpu_cc_src;
1175 cmp->c2 = cpu_cc_src2;
1182 gen_helper_compute_psr(cpu_env);
1183 dc->cc_op = CC_OP_FLAGS;
1187 /* We're going to generate a boolean result. */
1188 cmp->cond = TCG_COND_NE;
1189 cmp->is_bool = true;
1190 cmp->g1 = cmp->g2 = false;
1191 cmp->c1 = r_dst = tcg_temp_new();
1192 cmp->c2 = tcg_const_tl(0);
1196 gen_op_eval_bn(r_dst);
1199 gen_op_eval_be(r_dst, r_src);
1202 gen_op_eval_ble(r_dst, r_src);
1205 gen_op_eval_bl(r_dst, r_src);
1208 gen_op_eval_bleu(r_dst, r_src);
1211 gen_op_eval_bcs(r_dst, r_src);
1214 gen_op_eval_bneg(r_dst, r_src);
1217 gen_op_eval_bvs(r_dst, r_src);
1220 gen_op_eval_ba(r_dst);
1223 gen_op_eval_bne(r_dst, r_src);
1226 gen_op_eval_bg(r_dst, r_src);
1229 gen_op_eval_bge(r_dst, r_src);
1232 gen_op_eval_bgu(r_dst, r_src);
1235 gen_op_eval_bcc(r_dst, r_src);
1238 gen_op_eval_bpos(r_dst, r_src);
1241 gen_op_eval_bvc(r_dst, r_src);
1248 static void gen_fcompare(DisasCompare *cmp, unsigned int cc, unsigned int cond)
1250 unsigned int offset;
1253 /* For now we still generate a straight boolean result. */
1254 cmp->cond = TCG_COND_NE;
1255 cmp->is_bool = true;
1256 cmp->g1 = cmp->g2 = false;
1257 cmp->c1 = r_dst = tcg_temp_new();
1258 cmp->c2 = tcg_const_tl(0);
1278 gen_op_eval_bn(r_dst);
1281 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1284 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1287 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1290 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1293 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1296 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1299 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1302 gen_op_eval_ba(r_dst);
1305 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1308 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1311 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1314 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1317 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1320 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1323 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1328 static void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond,
1332 gen_compare(&cmp, cc, cond, dc);
1334 /* The interface is to return a boolean in r_dst. */
1336 tcg_gen_mov_tl(r_dst, cmp.c1);
1338 tcg_gen_setcond_tl(cmp.cond, r_dst, cmp.c1, cmp.c2);
1344 static void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1347 gen_fcompare(&cmp, cc, cond);
1349 /* The interface is to return a boolean in r_dst. */
1351 tcg_gen_mov_tl(r_dst, cmp.c1);
1353 tcg_gen_setcond_tl(cmp.cond, r_dst, cmp.c1, cmp.c2);
1359 #ifdef TARGET_SPARC64
1361 static const int gen_tcg_cond_reg[8] = {
1372 static void gen_compare_reg(DisasCompare *cmp, int cond, TCGv r_src)
1374 cmp->cond = tcg_invert_cond(gen_tcg_cond_reg[cond]);
1375 cmp->is_bool = false;
1379 cmp->c2 = tcg_const_tl(0);
1382 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1385 gen_compare_reg(&cmp, cond, r_src);
1387 /* The interface is to return a boolean in r_dst. */
1388 tcg_gen_setcond_tl(cmp.cond, r_dst, cmp.c1, cmp.c2);
1394 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc)
1396 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1397 target_ulong target = dc->pc + offset;
1399 #ifdef TARGET_SPARC64
1400 if (unlikely(AM_CHECK(dc))) {
1401 target &= 0xffffffffULL;
1405 /* unconditional not taken */
1407 dc->pc = dc->npc + 4;
1408 dc->npc = dc->pc + 4;
1411 dc->npc = dc->pc + 4;
1413 } else if (cond == 0x8) {
1414 /* unconditional taken */
1417 dc->npc = dc->pc + 4;
1421 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1425 gen_cond(cpu_cond, cc, cond, dc);
1427 gen_branch_a(dc, target);
1429 gen_branch_n(dc, target);
1434 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc)
1436 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1437 target_ulong target = dc->pc + offset;
1439 #ifdef TARGET_SPARC64
1440 if (unlikely(AM_CHECK(dc))) {
1441 target &= 0xffffffffULL;
1445 /* unconditional not taken */
1447 dc->pc = dc->npc + 4;
1448 dc->npc = dc->pc + 4;
1451 dc->npc = dc->pc + 4;
1453 } else if (cond == 0x8) {
1454 /* unconditional taken */
1457 dc->npc = dc->pc + 4;
1461 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1465 gen_fcond(cpu_cond, cc, cond);
1467 gen_branch_a(dc, target);
1469 gen_branch_n(dc, target);
1474 #ifdef TARGET_SPARC64
1475 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1478 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1479 target_ulong target = dc->pc + offset;
1481 if (unlikely(AM_CHECK(dc))) {
1482 target &= 0xffffffffULL;
1485 gen_cond_reg(cpu_cond, cond, r_reg);
1487 gen_branch_a(dc, target);
1489 gen_branch_n(dc, target);
1493 static inline void gen_op_fcmps(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1497 gen_helper_fcmps(cpu_env, r_rs1, r_rs2);
1500 gen_helper_fcmps_fcc1(cpu_env, r_rs1, r_rs2);
1503 gen_helper_fcmps_fcc2(cpu_env, r_rs1, r_rs2);
1506 gen_helper_fcmps_fcc3(cpu_env, r_rs1, r_rs2);
1511 static inline void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1515 gen_helper_fcmpd(cpu_env, r_rs1, r_rs2);
1518 gen_helper_fcmpd_fcc1(cpu_env, r_rs1, r_rs2);
1521 gen_helper_fcmpd_fcc2(cpu_env, r_rs1, r_rs2);
1524 gen_helper_fcmpd_fcc3(cpu_env, r_rs1, r_rs2);
1529 static inline void gen_op_fcmpq(int fccno)
1533 gen_helper_fcmpq(cpu_env);
1536 gen_helper_fcmpq_fcc1(cpu_env);
1539 gen_helper_fcmpq_fcc2(cpu_env);
1542 gen_helper_fcmpq_fcc3(cpu_env);
1547 static inline void gen_op_fcmpes(int fccno, TCGv_i32 r_rs1, TCGv_i32 r_rs2)
1551 gen_helper_fcmpes(cpu_env, r_rs1, r_rs2);
1554 gen_helper_fcmpes_fcc1(cpu_env, r_rs1, r_rs2);
1557 gen_helper_fcmpes_fcc2(cpu_env, r_rs1, r_rs2);
1560 gen_helper_fcmpes_fcc3(cpu_env, r_rs1, r_rs2);
1565 static inline void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1569 gen_helper_fcmped(cpu_env, r_rs1, r_rs2);
1572 gen_helper_fcmped_fcc1(cpu_env, r_rs1, r_rs2);
1575 gen_helper_fcmped_fcc2(cpu_env, r_rs1, r_rs2);
1578 gen_helper_fcmped_fcc3(cpu_env, r_rs1, r_rs2);
1583 static inline void gen_op_fcmpeq(int fccno)
1587 gen_helper_fcmpeq(cpu_env);
1590 gen_helper_fcmpeq_fcc1(cpu_env);
1593 gen_helper_fcmpeq_fcc2(cpu_env);
1596 gen_helper_fcmpeq_fcc3(cpu_env);
1603 static inline void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1605 gen_helper_fcmps(cpu_env, r_rs1, r_rs2);
1608 static inline void gen_op_fcmpd(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1610 gen_helper_fcmpd(cpu_env, r_rs1, r_rs2);
1613 static inline void gen_op_fcmpq(int fccno)
1615 gen_helper_fcmpq(cpu_env);
1618 static inline void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1620 gen_helper_fcmpes(cpu_env, r_rs1, r_rs2);
1623 static inline void gen_op_fcmped(int fccno, TCGv_i64 r_rs1, TCGv_i64 r_rs2)
1625 gen_helper_fcmped(cpu_env, r_rs1, r_rs2);
1628 static inline void gen_op_fcmpeq(int fccno)
1630 gen_helper_fcmpeq(cpu_env);
1634 static inline void gen_op_fpexception_im(int fsr_flags)
1638 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
1639 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1640 r_const = tcg_const_i32(TT_FP_EXCP);
1641 gen_helper_raise_exception(cpu_env, r_const);
1642 tcg_temp_free_i32(r_const);
1645 static int gen_trap_ifnofpu(DisasContext *dc)
1647 #if !defined(CONFIG_USER_ONLY)
1648 if (!dc->fpu_enabled) {
1652 r_const = tcg_const_i32(TT_NFPU_INSN);
1653 gen_helper_raise_exception(cpu_env, r_const);
1654 tcg_temp_free_i32(r_const);
1662 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1664 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1667 static inline void gen_fop_FF(DisasContext *dc, int rd, int rs,
1668 void (*gen)(TCGv_i32, TCGv_ptr, TCGv_i32))
1672 src = gen_load_fpr_F(dc, rs);
1673 dst = gen_dest_fpr_F(dc);
1675 gen(dst, cpu_env, src);
1677 gen_store_fpr_F(dc, rd, dst);
1680 static inline void gen_ne_fop_FF(DisasContext *dc, int rd, int rs,
1681 void (*gen)(TCGv_i32, TCGv_i32))
1685 src = gen_load_fpr_F(dc, rs);
1686 dst = gen_dest_fpr_F(dc);
1690 gen_store_fpr_F(dc, rd, dst);
1693 static inline void gen_fop_FFF(DisasContext *dc, int rd, int rs1, int rs2,
1694 void (*gen)(TCGv_i32, TCGv_ptr, TCGv_i32, TCGv_i32))
1696 TCGv_i32 dst, src1, src2;
1698 src1 = gen_load_fpr_F(dc, rs1);
1699 src2 = gen_load_fpr_F(dc, rs2);
1700 dst = gen_dest_fpr_F(dc);
1702 gen(dst, cpu_env, src1, src2);
1704 gen_store_fpr_F(dc, rd, dst);
1707 #ifdef TARGET_SPARC64
1708 static inline void gen_ne_fop_FFF(DisasContext *dc, int rd, int rs1, int rs2,
1709 void (*gen)(TCGv_i32, TCGv_i32, TCGv_i32))
1711 TCGv_i32 dst, src1, src2;
1713 src1 = gen_load_fpr_F(dc, rs1);
1714 src2 = gen_load_fpr_F(dc, rs2);
1715 dst = gen_dest_fpr_F(dc);
1717 gen(dst, src1, src2);
1719 gen_store_fpr_F(dc, rd, dst);
1723 static inline void gen_fop_DD(DisasContext *dc, int rd, int rs,
1724 void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i64))
1728 src = gen_load_fpr_D(dc, rs);
1729 dst = gen_dest_fpr_D(dc, rd);
1731 gen(dst, cpu_env, src);
1733 gen_store_fpr_D(dc, rd, dst);
1736 #ifdef TARGET_SPARC64
1737 static inline void gen_ne_fop_DD(DisasContext *dc, int rd, int rs,
1738 void (*gen)(TCGv_i64, TCGv_i64))
1742 src = gen_load_fpr_D(dc, rs);
1743 dst = gen_dest_fpr_D(dc, rd);
1747 gen_store_fpr_D(dc, rd, dst);
1751 static inline void gen_fop_DDD(DisasContext *dc, int rd, int rs1, int rs2,
1752 void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i64, TCGv_i64))
1754 TCGv_i64 dst, src1, src2;
1756 src1 = gen_load_fpr_D(dc, rs1);
1757 src2 = gen_load_fpr_D(dc, rs2);
1758 dst = gen_dest_fpr_D(dc, rd);
1760 gen(dst, cpu_env, src1, src2);
1762 gen_store_fpr_D(dc, rd, dst);
1765 #ifdef TARGET_SPARC64
1766 static inline void gen_ne_fop_DDD(DisasContext *dc, int rd, int rs1, int rs2,
1767 void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64))
1769 TCGv_i64 dst, src1, src2;
1771 src1 = gen_load_fpr_D(dc, rs1);
1772 src2 = gen_load_fpr_D(dc, rs2);
1773 dst = gen_dest_fpr_D(dc, rd);
1775 gen(dst, src1, src2);
1777 gen_store_fpr_D(dc, rd, dst);
1780 static inline void gen_gsr_fop_DDD(DisasContext *dc, int rd, int rs1, int rs2,
1781 void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
1783 TCGv_i64 dst, src1, src2;
1785 src1 = gen_load_fpr_D(dc, rs1);
1786 src2 = gen_load_fpr_D(dc, rs2);
1787 dst = gen_dest_fpr_D(dc, rd);
1789 gen(dst, cpu_gsr, src1, src2);
1791 gen_store_fpr_D(dc, rd, dst);
1794 static inline void gen_ne_fop_DDDD(DisasContext *dc, int rd, int rs1, int rs2,
1795 void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
1797 TCGv_i64 dst, src0, src1, src2;
1799 src1 = gen_load_fpr_D(dc, rs1);
1800 src2 = gen_load_fpr_D(dc, rs2);
1801 src0 = gen_load_fpr_D(dc, rd);
1802 dst = gen_dest_fpr_D(dc, rd);
1804 gen(dst, src0, src1, src2);
1806 gen_store_fpr_D(dc, rd, dst);
1810 static inline void gen_fop_QQ(DisasContext *dc, int rd, int rs,
1811 void (*gen)(TCGv_ptr))
1813 gen_op_load_fpr_QT1(QFPREG(rs));
1817 gen_op_store_QT0_fpr(QFPREG(rd));
1818 gen_update_fprs_dirty(QFPREG(rd));
1821 #ifdef TARGET_SPARC64
1822 static inline void gen_ne_fop_QQ(DisasContext *dc, int rd, int rs,
1823 void (*gen)(TCGv_ptr))
1825 gen_op_load_fpr_QT1(QFPREG(rs));
1829 gen_op_store_QT0_fpr(QFPREG(rd));
1830 gen_update_fprs_dirty(QFPREG(rd));
1834 static inline void gen_fop_QQQ(DisasContext *dc, int rd, int rs1, int rs2,
1835 void (*gen)(TCGv_ptr))
1837 gen_op_load_fpr_QT0(QFPREG(rs1));
1838 gen_op_load_fpr_QT1(QFPREG(rs2));
1842 gen_op_store_QT0_fpr(QFPREG(rd));
1843 gen_update_fprs_dirty(QFPREG(rd));
1846 static inline void gen_fop_DFF(DisasContext *dc, int rd, int rs1, int rs2,
1847 void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32, TCGv_i32))
1850 TCGv_i32 src1, src2;
1852 src1 = gen_load_fpr_F(dc, rs1);
1853 src2 = gen_load_fpr_F(dc, rs2);
1854 dst = gen_dest_fpr_D(dc, rd);
1856 gen(dst, cpu_env, src1, src2);
1858 gen_store_fpr_D(dc, rd, dst);
1861 static inline void gen_fop_QDD(DisasContext *dc, int rd, int rs1, int rs2,
1862 void (*gen)(TCGv_ptr, TCGv_i64, TCGv_i64))
1864 TCGv_i64 src1, src2;
1866 src1 = gen_load_fpr_D(dc, rs1);
1867 src2 = gen_load_fpr_D(dc, rs2);
1869 gen(cpu_env, src1, src2);
1871 gen_op_store_QT0_fpr(QFPREG(rd));
1872 gen_update_fprs_dirty(QFPREG(rd));
1875 #ifdef TARGET_SPARC64
1876 static inline void gen_fop_DF(DisasContext *dc, int rd, int rs,
1877 void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32))
1882 src = gen_load_fpr_F(dc, rs);
1883 dst = gen_dest_fpr_D(dc, rd);
1885 gen(dst, cpu_env, src);
1887 gen_store_fpr_D(dc, rd, dst);
1891 static inline void gen_ne_fop_DF(DisasContext *dc, int rd, int rs,
1892 void (*gen)(TCGv_i64, TCGv_ptr, TCGv_i32))
1897 src = gen_load_fpr_F(dc, rs);
1898 dst = gen_dest_fpr_D(dc, rd);
1900 gen(dst, cpu_env, src);
1902 gen_store_fpr_D(dc, rd, dst);
1905 static inline void gen_fop_FD(DisasContext *dc, int rd, int rs,
1906 void (*gen)(TCGv_i32, TCGv_ptr, TCGv_i64))
1911 src = gen_load_fpr_D(dc, rs);
1912 dst = gen_dest_fpr_F(dc);
1914 gen(dst, cpu_env, src);
1916 gen_store_fpr_F(dc, rd, dst);
1919 static inline void gen_fop_FQ(DisasContext *dc, int rd, int rs,
1920 void (*gen)(TCGv_i32, TCGv_ptr))
1924 gen_op_load_fpr_QT1(QFPREG(rs));
1925 dst = gen_dest_fpr_F(dc);
1929 gen_store_fpr_F(dc, rd, dst);
1932 static inline void gen_fop_DQ(DisasContext *dc, int rd, int rs,
1933 void (*gen)(TCGv_i64, TCGv_ptr))
1937 gen_op_load_fpr_QT1(QFPREG(rs));
1938 dst = gen_dest_fpr_D(dc, rd);
1942 gen_store_fpr_D(dc, rd, dst);
1945 static inline void gen_ne_fop_QF(DisasContext *dc, int rd, int rs,
1946 void (*gen)(TCGv_ptr, TCGv_i32))
1950 src = gen_load_fpr_F(dc, rs);
1954 gen_op_store_QT0_fpr(QFPREG(rd));
1955 gen_update_fprs_dirty(QFPREG(rd));
1958 static inline void gen_ne_fop_QD(DisasContext *dc, int rd, int rs,
1959 void (*gen)(TCGv_ptr, TCGv_i64))
1963 src = gen_load_fpr_D(dc, rs);
1967 gen_op_store_QT0_fpr(QFPREG(rd));
1968 gen_update_fprs_dirty(QFPREG(rd));
1972 #ifdef TARGET_SPARC64
1973 static inline TCGv_i32 gen_get_asi(int insn, TCGv r_addr)
1979 r_asi = tcg_temp_new_i32();
1980 tcg_gen_mov_i32(r_asi, cpu_asi);
1982 asi = GET_FIELD(insn, 19, 26);
1983 r_asi = tcg_const_i32(asi);
1988 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1991 TCGv_i32 r_asi, r_size, r_sign;
1993 r_asi = gen_get_asi(insn, addr);
1994 r_size = tcg_const_i32(size);
1995 r_sign = tcg_const_i32(sign);
1996 gen_helper_ld_asi(dst, cpu_env, addr, r_asi, r_size, r_sign);
1997 tcg_temp_free_i32(r_sign);
1998 tcg_temp_free_i32(r_size);
1999 tcg_temp_free_i32(r_asi);
2002 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
2004 TCGv_i32 r_asi, r_size;
2006 r_asi = gen_get_asi(insn, addr);
2007 r_size = tcg_const_i32(size);
2008 gen_helper_st_asi(cpu_env, addr, src, r_asi, r_size);
2009 tcg_temp_free_i32(r_size);
2010 tcg_temp_free_i32(r_asi);
2013 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
2015 TCGv_i32 r_asi, r_size, r_rd;
2017 r_asi = gen_get_asi(insn, addr);
2018 r_size = tcg_const_i32(size);
2019 r_rd = tcg_const_i32(rd);
2020 gen_helper_ldf_asi(cpu_env, addr, r_asi, r_size, r_rd);
2021 tcg_temp_free_i32(r_rd);
2022 tcg_temp_free_i32(r_size);
2023 tcg_temp_free_i32(r_asi);
2026 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
2028 TCGv_i32 r_asi, r_size, r_rd;
2030 r_asi = gen_get_asi(insn, addr);
2031 r_size = tcg_const_i32(size);
2032 r_rd = tcg_const_i32(rd);
2033 gen_helper_stf_asi(cpu_env, addr, r_asi, r_size, r_rd);
2034 tcg_temp_free_i32(r_rd);
2035 tcg_temp_free_i32(r_size);
2036 tcg_temp_free_i32(r_asi);
2039 static inline void gen_swap_asi(TCGv dst, TCGv src, TCGv addr, int insn)
2041 TCGv_i32 r_asi, r_size, r_sign;
2042 TCGv_i64 t64 = tcg_temp_new_i64();
2044 r_asi = gen_get_asi(insn, addr);
2045 r_size = tcg_const_i32(4);
2046 r_sign = tcg_const_i32(0);
2047 gen_helper_ld_asi(t64, cpu_env, addr, r_asi, r_size, r_sign);
2048 tcg_temp_free_i32(r_sign);
2049 gen_helper_st_asi(cpu_env, addr, src, r_asi, r_size);
2050 tcg_temp_free_i32(r_size);
2051 tcg_temp_free_i32(r_asi);
2052 tcg_gen_trunc_i64_tl(dst, t64);
2053 tcg_temp_free_i64(t64);
2056 static inline void gen_ldda_asi(DisasContext *dc, TCGv hi, TCGv addr,
2059 TCGv_i32 r_asi, r_rd;
2061 r_asi = gen_get_asi(insn, addr);
2062 r_rd = tcg_const_i32(rd);
2063 gen_helper_ldda_asi(cpu_env, addr, r_asi, r_rd);
2064 tcg_temp_free_i32(r_rd);
2065 tcg_temp_free_i32(r_asi);
2068 static inline void gen_stda_asi(DisasContext *dc, TCGv hi, TCGv addr,
2071 TCGv_i32 r_asi, r_size;
2072 TCGv lo = gen_load_gpr(dc, rd + 1);
2073 TCGv_i64 t64 = tcg_temp_new_i64();
2075 tcg_gen_concat_tl_i64(t64, lo, hi);
2076 r_asi = gen_get_asi(insn, addr);
2077 r_size = tcg_const_i32(8);
2078 gen_helper_st_asi(cpu_env, addr, t64, r_asi, r_size);
2079 tcg_temp_free_i32(r_size);
2080 tcg_temp_free_i32(r_asi);
2081 tcg_temp_free_i64(t64);
2084 static inline void gen_casx_asi(DisasContext *dc, TCGv addr,
2085 TCGv val2, int insn, int rd)
2087 TCGv val1 = gen_load_gpr(dc, rd);
2088 TCGv dst = gen_dest_gpr(dc, rd);
2089 TCGv_i32 r_asi = gen_get_asi(insn, addr);
2091 gen_helper_casx_asi(dst, cpu_env, addr, val1, val2, r_asi);
2092 tcg_temp_free_i32(r_asi);
2093 gen_store_gpr(dc, rd, dst);
2096 #elif !defined(CONFIG_USER_ONLY)
2098 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
2101 TCGv_i32 r_asi, r_size, r_sign;
2102 TCGv_i64 t64 = tcg_temp_new_i64();
2104 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
2105 r_size = tcg_const_i32(size);
2106 r_sign = tcg_const_i32(sign);
2107 gen_helper_ld_asi(t64, cpu_env, addr, r_asi, r_size, r_sign);
2108 tcg_temp_free_i32(r_sign);
2109 tcg_temp_free_i32(r_size);
2110 tcg_temp_free_i32(r_asi);
2111 tcg_gen_trunc_i64_tl(dst, t64);
2112 tcg_temp_free_i64(t64);
2115 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
2117 TCGv_i32 r_asi, r_size;
2118 TCGv_i64 t64 = tcg_temp_new_i64();
2120 tcg_gen_extu_tl_i64(t64, src);
2121 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
2122 r_size = tcg_const_i32(size);
2123 gen_helper_st_asi(cpu_env, addr, t64, r_asi, r_size);
2124 tcg_temp_free_i32(r_size);
2125 tcg_temp_free_i32(r_asi);
2126 tcg_temp_free_i64(t64);
2129 static inline void gen_swap_asi(TCGv dst, TCGv src, TCGv addr, int insn)
2131 TCGv_i32 r_asi, r_size, r_sign;
2132 TCGv_i64 r_val, t64;
2134 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
2135 r_size = tcg_const_i32(4);
2136 r_sign = tcg_const_i32(0);
2137 t64 = tcg_temp_new_i64();
2138 gen_helper_ld_asi(t64, cpu_env, addr, r_asi, r_size, r_sign);
2139 tcg_temp_free(r_sign);
2140 r_val = tcg_temp_new_i64();
2141 tcg_gen_extu_tl_i64(r_val, src);
2142 gen_helper_st_asi(cpu_env, addr, r_val, r_asi, r_size);
2143 tcg_temp_free_i64(r_val);
2144 tcg_temp_free_i32(r_size);
2145 tcg_temp_free_i32(r_asi);
2146 tcg_gen_trunc_i64_tl(dst, t64);
2147 tcg_temp_free_i64(t64);
2150 static inline void gen_ldda_asi(DisasContext *dc, TCGv hi, TCGv addr,
2153 TCGv_i32 r_asi, r_size, r_sign;
2157 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
2158 r_size = tcg_const_i32(8);
2159 r_sign = tcg_const_i32(0);
2160 t64 = tcg_temp_new_i64();
2161 gen_helper_ld_asi(t64, cpu_env, addr, r_asi, r_size, r_sign);
2162 tcg_temp_free_i32(r_sign);
2163 tcg_temp_free_i32(r_size);
2164 tcg_temp_free_i32(r_asi);
2166 t = gen_dest_gpr(dc, rd + 1);
2167 tcg_gen_trunc_i64_tl(t, t64);
2168 gen_store_gpr(dc, rd + 1, t);
2170 tcg_gen_shri_i64(t64, t64, 32);
2171 tcg_gen_trunc_i64_tl(hi, t64);
2172 tcg_temp_free_i64(t64);
2173 gen_store_gpr(dc, rd, hi);
2176 static inline void gen_stda_asi(DisasContext *dc, TCGv hi, TCGv addr,
2179 TCGv_i32 r_asi, r_size;
2180 TCGv lo = gen_load_gpr(dc, rd + 1);
2181 TCGv_i64 t64 = tcg_temp_new_i64();
2183 tcg_gen_concat_tl_i64(t64, lo, hi);
2184 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
2185 r_size = tcg_const_i32(8);
2186 gen_helper_st_asi(cpu_env, addr, t64, r_asi, r_size);
2187 tcg_temp_free_i32(r_size);
2188 tcg_temp_free_i32(r_asi);
2189 tcg_temp_free_i64(t64);
2193 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2194 static inline void gen_cas_asi(DisasContext *dc, TCGv addr,
2195 TCGv val2, int insn, int rd)
2197 TCGv val1 = gen_load_gpr(dc, rd);
2198 TCGv dst = gen_dest_gpr(dc, rd);
2199 #ifdef TARGET_SPARC64
2200 TCGv_i32 r_asi = gen_get_asi(insn, addr);
2202 TCGv_i32 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
2205 gen_helper_cas_asi(dst, cpu_env, addr, val1, val2, r_asi);
2206 tcg_temp_free_i32(r_asi);
2207 gen_store_gpr(dc, rd, dst);
2210 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
2213 TCGv_i32 r_asi, r_size;
2215 gen_ld_asi(dst, addr, insn, 1, 0);
2217 r_val = tcg_const_i64(0xffULL);
2218 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
2219 r_size = tcg_const_i32(1);
2220 gen_helper_st_asi(cpu_env, addr, r_val, r_asi, r_size);
2221 tcg_temp_free_i32(r_size);
2222 tcg_temp_free_i32(r_asi);
2223 tcg_temp_free_i64(r_val);
2227 static TCGv get_src1(DisasContext *dc, unsigned int insn)
2229 unsigned int rs1 = GET_FIELD(insn, 13, 17);
2230 return gen_load_gpr(dc, rs1);
2233 static TCGv get_src2(DisasContext *dc, unsigned int insn)
2235 if (IS_IMM) { /* immediate */
2236 target_long simm = GET_FIELDs(insn, 19, 31);
2237 TCGv t = get_temp_tl(dc);
2238 tcg_gen_movi_tl(t, simm);
2240 } else { /* register */
2241 unsigned int rs2 = GET_FIELD(insn, 27, 31);
2242 return gen_load_gpr(dc, rs2);
2246 #ifdef TARGET_SPARC64
2247 static void gen_fmovs(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2249 TCGv_i32 c32, zero, dst, s1, s2;
2251 /* We have two choices here: extend the 32 bit data and use movcond_i64,
2252 or fold the comparison down to 32 bits and use movcond_i32. Choose
2254 c32 = tcg_temp_new_i32();
2256 tcg_gen_extrl_i64_i32(c32, cmp->c1);
2258 TCGv_i64 c64 = tcg_temp_new_i64();
2259 tcg_gen_setcond_i64(cmp->cond, c64, cmp->c1, cmp->c2);
2260 tcg_gen_extrl_i64_i32(c32, c64);
2261 tcg_temp_free_i64(c64);
2264 s1 = gen_load_fpr_F(dc, rs);
2265 s2 = gen_load_fpr_F(dc, rd);
2266 dst = gen_dest_fpr_F(dc);
2267 zero = tcg_const_i32(0);
2269 tcg_gen_movcond_i32(TCG_COND_NE, dst, c32, zero, s1, s2);
2271 tcg_temp_free_i32(c32);
2272 tcg_temp_free_i32(zero);
2273 gen_store_fpr_F(dc, rd, dst);
2276 static void gen_fmovd(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2278 TCGv_i64 dst = gen_dest_fpr_D(dc, rd);
2279 tcg_gen_movcond_i64(cmp->cond, dst, cmp->c1, cmp->c2,
2280 gen_load_fpr_D(dc, rs),
2281 gen_load_fpr_D(dc, rd));
2282 gen_store_fpr_D(dc, rd, dst);
2285 static void gen_fmovq(DisasContext *dc, DisasCompare *cmp, int rd, int rs)
2287 int qd = QFPREG(rd);
2288 int qs = QFPREG(rs);
2290 tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2], cmp->c1, cmp->c2,
2291 cpu_fpr[qs / 2], cpu_fpr[qd / 2]);
2292 tcg_gen_movcond_i64(cmp->cond, cpu_fpr[qd / 2 + 1], cmp->c1, cmp->c2,
2293 cpu_fpr[qs / 2 + 1], cpu_fpr[qd / 2 + 1]);
2295 gen_update_fprs_dirty(qd);
2298 #ifndef CONFIG_USER_ONLY
2299 static inline void gen_load_trap_state_at_tl(TCGv_ptr r_tsptr, TCGv_ptr cpu_env)
2301 TCGv_i32 r_tl = tcg_temp_new_i32();
2303 /* load env->tl into r_tl */
2304 tcg_gen_ld_i32(r_tl, cpu_env, offsetof(CPUSPARCState, tl));
2306 /* tl = [0 ... MAXTL_MASK] where MAXTL_MASK must be power of 2 */
2307 tcg_gen_andi_i32(r_tl, r_tl, MAXTL_MASK);
2309 /* calculate offset to current trap state from env->ts, reuse r_tl */
2310 tcg_gen_muli_i32(r_tl, r_tl, sizeof (trap_state));
2311 tcg_gen_addi_ptr(r_tsptr, cpu_env, offsetof(CPUSPARCState, ts));
2313 /* tsptr = env->ts[env->tl & MAXTL_MASK] */
2315 TCGv_ptr r_tl_tmp = tcg_temp_new_ptr();
2316 tcg_gen_ext_i32_ptr(r_tl_tmp, r_tl);
2317 tcg_gen_add_ptr(r_tsptr, r_tsptr, r_tl_tmp);
2318 tcg_temp_free_ptr(r_tl_tmp);
2321 tcg_temp_free_i32(r_tl);
2325 static void gen_edge(DisasContext *dc, TCGv dst, TCGv s1, TCGv s2,
2326 int width, bool cc, bool left)
2328 TCGv lo1, lo2, t1, t2;
2329 uint64_t amask, tabl, tabr;
2330 int shift, imask, omask;
2333 tcg_gen_mov_tl(cpu_cc_src, s1);
2334 tcg_gen_mov_tl(cpu_cc_src2, s2);
2335 tcg_gen_sub_tl(cpu_cc_dst, s1, s2);
2336 tcg_gen_movi_i32(cpu_cc_op, CC_OP_SUB);
2337 dc->cc_op = CC_OP_SUB;
2340 /* Theory of operation: there are two tables, left and right (not to
2341 be confused with the left and right versions of the opcode). These
2342 are indexed by the low 3 bits of the inputs. To make things "easy",
2343 these tables are loaded into two constants, TABL and TABR below.
2344 The operation index = (input & imask) << shift calculates the index
2345 into the constant, while val = (table >> index) & omask calculates
2346 the value we're looking for. */
2353 tabl = 0x80c0e0f0f8fcfeffULL;
2354 tabr = 0xff7f3f1f0f070301ULL;
2356 tabl = 0x0103070f1f3f7fffULL;
2357 tabr = 0xfffefcf8f0e0c080ULL;
2377 tabl = (2 << 2) | 3;
2378 tabr = (3 << 2) | 1;
2380 tabl = (1 << 2) | 3;
2381 tabr = (3 << 2) | 2;
2388 lo1 = tcg_temp_new();
2389 lo2 = tcg_temp_new();
2390 tcg_gen_andi_tl(lo1, s1, imask);
2391 tcg_gen_andi_tl(lo2, s2, imask);
2392 tcg_gen_shli_tl(lo1, lo1, shift);
2393 tcg_gen_shli_tl(lo2, lo2, shift);
2395 t1 = tcg_const_tl(tabl);
2396 t2 = tcg_const_tl(tabr);
2397 tcg_gen_shr_tl(lo1, t1, lo1);
2398 tcg_gen_shr_tl(lo2, t2, lo2);
2399 tcg_gen_andi_tl(dst, lo1, omask);
2400 tcg_gen_andi_tl(lo2, lo2, omask);
2404 amask &= 0xffffffffULL;
2406 tcg_gen_andi_tl(s1, s1, amask);
2407 tcg_gen_andi_tl(s2, s2, amask);
2409 /* We want to compute
2410 dst = (s1 == s2 ? lo1 : lo1 & lo2).
2411 We've already done dst = lo1, so this reduces to
2412 dst &= (s1 == s2 ? -1 : lo2)
2417 tcg_gen_setcond_tl(TCG_COND_EQ, t1, s1, s2);
2418 tcg_gen_neg_tl(t1, t1);
2419 tcg_gen_or_tl(lo2, lo2, t1);
2420 tcg_gen_and_tl(dst, dst, lo2);
2428 static void gen_alignaddr(TCGv dst, TCGv s1, TCGv s2, bool left)
2430 TCGv tmp = tcg_temp_new();
2432 tcg_gen_add_tl(tmp, s1, s2);
2433 tcg_gen_andi_tl(dst, tmp, -8);
2435 tcg_gen_neg_tl(tmp, tmp);
2437 tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, tmp, 0, 3);
2442 static void gen_faligndata(TCGv dst, TCGv gsr, TCGv s1, TCGv s2)
2446 t1 = tcg_temp_new();
2447 t2 = tcg_temp_new();
2448 shift = tcg_temp_new();
2450 tcg_gen_andi_tl(shift, gsr, 7);
2451 tcg_gen_shli_tl(shift, shift, 3);
2452 tcg_gen_shl_tl(t1, s1, shift);
2454 /* A shift of 64 does not produce 0 in TCG. Divide this into a
2455 shift of (up to 63) followed by a constant shift of 1. */
2456 tcg_gen_xori_tl(shift, shift, 63);
2457 tcg_gen_shr_tl(t2, s2, shift);
2458 tcg_gen_shri_tl(t2, t2, 1);
2460 tcg_gen_or_tl(dst, t1, t2);
2464 tcg_temp_free(shift);
2468 #define CHECK_IU_FEATURE(dc, FEATURE) \
2469 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
2471 #define CHECK_FPU_FEATURE(dc, FEATURE) \
2472 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
2475 /* before an instruction, dc->pc must be static */
2476 static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
2478 unsigned int opc, rs1, rs2, rd;
2479 TCGv cpu_src1, cpu_src2;
2480 TCGv_i32 cpu_src1_32, cpu_src2_32, cpu_dst_32;
2481 TCGv_i64 cpu_src1_64, cpu_src2_64, cpu_dst_64;
2484 opc = GET_FIELD(insn, 0, 1);
2485 rd = GET_FIELD(insn, 2, 6);
2488 case 0: /* branches/sethi */
2490 unsigned int xop = GET_FIELD(insn, 7, 9);
2493 #ifdef TARGET_SPARC64
2494 case 0x1: /* V9 BPcc */
2498 target = GET_FIELD_SP(insn, 0, 18);
2499 target = sign_extend(target, 19);
2501 cc = GET_FIELD_SP(insn, 20, 21);
2503 do_branch(dc, target, insn, 0);
2505 do_branch(dc, target, insn, 1);
2510 case 0x3: /* V9 BPr */
2512 target = GET_FIELD_SP(insn, 0, 13) |
2513 (GET_FIELD_SP(insn, 20, 21) << 14);
2514 target = sign_extend(target, 16);
2516 cpu_src1 = get_src1(dc, insn);
2517 do_branch_reg(dc, target, insn, cpu_src1);
2520 case 0x5: /* V9 FBPcc */
2522 int cc = GET_FIELD_SP(insn, 20, 21);
2523 if (gen_trap_ifnofpu(dc)) {
2526 target = GET_FIELD_SP(insn, 0, 18);
2527 target = sign_extend(target, 19);
2529 do_fbranch(dc, target, insn, cc);
2533 case 0x7: /* CBN+x */
2538 case 0x2: /* BN+x */
2540 target = GET_FIELD(insn, 10, 31);
2541 target = sign_extend(target, 22);
2543 do_branch(dc, target, insn, 0);
2546 case 0x6: /* FBN+x */
2548 if (gen_trap_ifnofpu(dc)) {
2551 target = GET_FIELD(insn, 10, 31);
2552 target = sign_extend(target, 22);
2554 do_fbranch(dc, target, insn, 0);
2557 case 0x4: /* SETHI */
2558 /* Special-case %g0 because that's the canonical nop. */
2560 uint32_t value = GET_FIELD(insn, 10, 31);
2561 TCGv t = gen_dest_gpr(dc, rd);
2562 tcg_gen_movi_tl(t, value << 10);
2563 gen_store_gpr(dc, rd, t);
2566 case 0x0: /* UNIMPL */
2575 target_long target = GET_FIELDs(insn, 2, 31) << 2;
2576 TCGv o7 = gen_dest_gpr(dc, 15);
2578 tcg_gen_movi_tl(o7, dc->pc);
2579 gen_store_gpr(dc, 15, o7);
2582 #ifdef TARGET_SPARC64
2583 if (unlikely(AM_CHECK(dc))) {
2584 target &= 0xffffffffULL;
2590 case 2: /* FPU & Logical Operations */
2592 unsigned int xop = GET_FIELD(insn, 7, 12);
2593 TCGv cpu_dst = get_temp_tl(dc);
2596 if (xop == 0x3a) { /* generate trap */
2597 int cond = GET_FIELD(insn, 3, 6);
2599 TCGLabel *l1 = NULL;
2610 /* Conditional trap. */
2612 #ifdef TARGET_SPARC64
2614 int cc = GET_FIELD_SP(insn, 11, 12);
2616 gen_compare(&cmp, 0, cond, dc);
2617 } else if (cc == 2) {
2618 gen_compare(&cmp, 1, cond, dc);
2623 gen_compare(&cmp, 0, cond, dc);
2625 l1 = gen_new_label();
2626 tcg_gen_brcond_tl(tcg_invert_cond(cmp.cond),
2627 cmp.c1, cmp.c2, l1);
2631 mask = ((dc->def->features & CPU_FEATURE_HYPV) && supervisor(dc)
2632 ? UA2005_HTRAP_MASK : V8_TRAP_MASK);
2634 /* Don't use the normal temporaries, as they may well have
2635 gone out of scope with the branch above. While we're
2636 doing that we might as well pre-truncate to 32-bit. */
2637 trap = tcg_temp_new_i32();
2639 rs1 = GET_FIELD_SP(insn, 14, 18);
2641 rs2 = GET_FIELD_SP(insn, 0, 6);
2643 tcg_gen_movi_i32(trap, (rs2 & mask) + TT_TRAP);
2644 /* Signal that the trap value is fully constant. */
2647 TCGv t1 = gen_load_gpr(dc, rs1);
2648 tcg_gen_trunc_tl_i32(trap, t1);
2649 tcg_gen_addi_i32(trap, trap, rs2);
2653 rs2 = GET_FIELD_SP(insn, 0, 4);
2654 t1 = gen_load_gpr(dc, rs1);
2655 t2 = gen_load_gpr(dc, rs2);
2656 tcg_gen_add_tl(t1, t1, t2);
2657 tcg_gen_trunc_tl_i32(trap, t1);
2660 tcg_gen_andi_i32(trap, trap, mask);
2661 tcg_gen_addi_i32(trap, trap, TT_TRAP);
2664 gen_helper_raise_exception(cpu_env, trap);
2665 tcg_temp_free_i32(trap);
2668 /* An unconditional trap ends the TB. */
2672 /* A conditional trap falls through to the next insn. */
2676 } else if (xop == 0x28) {
2677 rs1 = GET_FIELD(insn, 13, 17);
2680 #ifndef TARGET_SPARC64
2681 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2682 manual, rdy on the microSPARC
2684 case 0x0f: /* stbar in the SPARCv8 manual,
2685 rdy on the microSPARC II */
2686 case 0x10 ... 0x1f: /* implementation-dependent in the
2687 SPARCv8 manual, rdy on the
2690 if (rs1 == 0x11 && dc->def->features & CPU_FEATURE_ASR17) {
2691 TCGv t = gen_dest_gpr(dc, rd);
2692 /* Read Asr17 for a Leon3 monoprocessor */
2693 tcg_gen_movi_tl(t, (1 << 8) | (dc->def->nwindows - 1));
2694 gen_store_gpr(dc, rd, t);
2698 gen_store_gpr(dc, rd, cpu_y);
2700 #ifdef TARGET_SPARC64
2701 case 0x2: /* V9 rdccr */
2703 gen_helper_rdccr(cpu_dst, cpu_env);
2704 gen_store_gpr(dc, rd, cpu_dst);
2706 case 0x3: /* V9 rdasi */
2707 tcg_gen_ext_i32_tl(cpu_dst, cpu_asi);
2708 gen_store_gpr(dc, rd, cpu_dst);
2710 case 0x4: /* V9 rdtick */
2714 r_tickptr = tcg_temp_new_ptr();
2715 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2716 offsetof(CPUSPARCState, tick));
2717 gen_helper_tick_get_count(cpu_dst, r_tickptr);
2718 tcg_temp_free_ptr(r_tickptr);
2719 gen_store_gpr(dc, rd, cpu_dst);
2722 case 0x5: /* V9 rdpc */
2724 TCGv t = gen_dest_gpr(dc, rd);
2725 if (unlikely(AM_CHECK(dc))) {
2726 tcg_gen_movi_tl(t, dc->pc & 0xffffffffULL);
2728 tcg_gen_movi_tl(t, dc->pc);
2730 gen_store_gpr(dc, rd, t);
2733 case 0x6: /* V9 rdfprs */
2734 tcg_gen_ext_i32_tl(cpu_dst, cpu_fprs);
2735 gen_store_gpr(dc, rd, cpu_dst);
2737 case 0xf: /* V9 membar */
2738 break; /* no effect */
2739 case 0x13: /* Graphics Status */
2740 if (gen_trap_ifnofpu(dc)) {
2743 gen_store_gpr(dc, rd, cpu_gsr);
2745 case 0x16: /* Softint */
2746 tcg_gen_ext_i32_tl(cpu_dst, cpu_softint);
2747 gen_store_gpr(dc, rd, cpu_dst);
2749 case 0x17: /* Tick compare */
2750 gen_store_gpr(dc, rd, cpu_tick_cmpr);
2752 case 0x18: /* System tick */
2756 r_tickptr = tcg_temp_new_ptr();
2757 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2758 offsetof(CPUSPARCState, stick));
2759 gen_helper_tick_get_count(cpu_dst, r_tickptr);
2760 tcg_temp_free_ptr(r_tickptr);
2761 gen_store_gpr(dc, rd, cpu_dst);
2764 case 0x19: /* System tick compare */
2765 gen_store_gpr(dc, rd, cpu_stick_cmpr);
2767 case 0x10: /* Performance Control */
2768 case 0x11: /* Performance Instrumentation Counter */
2769 case 0x12: /* Dispatch Control */
2770 case 0x14: /* Softint set, WO */
2771 case 0x15: /* Softint clear, WO */
2776 #if !defined(CONFIG_USER_ONLY)
2777 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2778 #ifndef TARGET_SPARC64
2779 if (!supervisor(dc)) {
2783 gen_helper_rdpsr(cpu_dst, cpu_env);
2785 CHECK_IU_FEATURE(dc, HYPV);
2786 if (!hypervisor(dc))
2788 rs1 = GET_FIELD(insn, 13, 17);
2791 // gen_op_rdhpstate();
2794 // gen_op_rdhtstate();
2797 tcg_gen_mov_tl(cpu_dst, cpu_hintp);
2800 tcg_gen_mov_tl(cpu_dst, cpu_htba);
2803 tcg_gen_mov_tl(cpu_dst, cpu_hver);
2805 case 31: // hstick_cmpr
2806 tcg_gen_mov_tl(cpu_dst, cpu_hstick_cmpr);
2812 gen_store_gpr(dc, rd, cpu_dst);
2814 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2815 if (!supervisor(dc)) {
2818 cpu_tmp0 = get_temp_tl(dc);
2819 #ifdef TARGET_SPARC64
2820 rs1 = GET_FIELD(insn, 13, 17);
2826 r_tsptr = tcg_temp_new_ptr();
2827 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
2828 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2829 offsetof(trap_state, tpc));
2830 tcg_temp_free_ptr(r_tsptr);
2837 r_tsptr = tcg_temp_new_ptr();
2838 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
2839 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2840 offsetof(trap_state, tnpc));
2841 tcg_temp_free_ptr(r_tsptr);
2848 r_tsptr = tcg_temp_new_ptr();
2849 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
2850 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2851 offsetof(trap_state, tstate));
2852 tcg_temp_free_ptr(r_tsptr);
2857 TCGv_ptr r_tsptr = tcg_temp_new_ptr();
2859 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
2860 tcg_gen_ld32s_tl(cpu_tmp0, r_tsptr,
2861 offsetof(trap_state, tt));
2862 tcg_temp_free_ptr(r_tsptr);
2869 r_tickptr = tcg_temp_new_ptr();
2870 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2871 offsetof(CPUSPARCState, tick));
2872 gen_helper_tick_get_count(cpu_tmp0, r_tickptr);
2873 tcg_temp_free_ptr(r_tickptr);
2877 tcg_gen_mov_tl(cpu_tmp0, cpu_tbr);
2880 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2881 offsetof(CPUSPARCState, pstate));
2884 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2885 offsetof(CPUSPARCState, tl));
2888 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2889 offsetof(CPUSPARCState, psrpil));
2892 gen_helper_rdcwp(cpu_tmp0, cpu_env);
2895 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2896 offsetof(CPUSPARCState, cansave));
2898 case 11: // canrestore
2899 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2900 offsetof(CPUSPARCState, canrestore));
2902 case 12: // cleanwin
2903 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2904 offsetof(CPUSPARCState, cleanwin));
2906 case 13: // otherwin
2907 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2908 offsetof(CPUSPARCState, otherwin));
2911 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2912 offsetof(CPUSPARCState, wstate));
2914 case 16: // UA2005 gl
2915 CHECK_IU_FEATURE(dc, GL);
2916 tcg_gen_ld32s_tl(cpu_tmp0, cpu_env,
2917 offsetof(CPUSPARCState, gl));
2919 case 26: // UA2005 strand status
2920 CHECK_IU_FEATURE(dc, HYPV);
2921 if (!hypervisor(dc))
2923 tcg_gen_mov_tl(cpu_tmp0, cpu_ssr);
2926 tcg_gen_mov_tl(cpu_tmp0, cpu_ver);
2933 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_wim);
2935 gen_store_gpr(dc, rd, cpu_tmp0);
2937 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2938 #ifdef TARGET_SPARC64
2940 gen_helper_flushw(cpu_env);
2942 if (!supervisor(dc))
2944 gen_store_gpr(dc, rd, cpu_tbr);
2948 } else if (xop == 0x34) { /* FPU Operations */
2949 if (gen_trap_ifnofpu(dc)) {
2952 gen_op_clear_ieee_excp_and_FTT();
2953 rs1 = GET_FIELD(insn, 13, 17);
2954 rs2 = GET_FIELD(insn, 27, 31);
2955 xop = GET_FIELD(insn, 18, 26);
2958 case 0x1: /* fmovs */
2959 cpu_src1_32 = gen_load_fpr_F(dc, rs2);
2960 gen_store_fpr_F(dc, rd, cpu_src1_32);
2962 case 0x5: /* fnegs */
2963 gen_ne_fop_FF(dc, rd, rs2, gen_helper_fnegs);
2965 case 0x9: /* fabss */
2966 gen_ne_fop_FF(dc, rd, rs2, gen_helper_fabss);
2968 case 0x29: /* fsqrts */
2969 CHECK_FPU_FEATURE(dc, FSQRT);
2970 gen_fop_FF(dc, rd, rs2, gen_helper_fsqrts);
2972 case 0x2a: /* fsqrtd */
2973 CHECK_FPU_FEATURE(dc, FSQRT);
2974 gen_fop_DD(dc, rd, rs2, gen_helper_fsqrtd);
2976 case 0x2b: /* fsqrtq */
2977 CHECK_FPU_FEATURE(dc, FLOAT128);
2978 gen_fop_QQ(dc, rd, rs2, gen_helper_fsqrtq);
2980 case 0x41: /* fadds */
2981 gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fadds);
2983 case 0x42: /* faddd */
2984 gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_faddd);
2986 case 0x43: /* faddq */
2987 CHECK_FPU_FEATURE(dc, FLOAT128);
2988 gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_faddq);
2990 case 0x45: /* fsubs */
2991 gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fsubs);
2993 case 0x46: /* fsubd */
2994 gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_fsubd);
2996 case 0x47: /* fsubq */
2997 CHECK_FPU_FEATURE(dc, FLOAT128);
2998 gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_fsubq);
3000 case 0x49: /* fmuls */
3001 CHECK_FPU_FEATURE(dc, FMUL);
3002 gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fmuls);
3004 case 0x4a: /* fmuld */
3005 CHECK_FPU_FEATURE(dc, FMUL);
3006 gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmuld);
3008 case 0x4b: /* fmulq */
3009 CHECK_FPU_FEATURE(dc, FLOAT128);
3010 CHECK_FPU_FEATURE(dc, FMUL);
3011 gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_fmulq);
3013 case 0x4d: /* fdivs */
3014 gen_fop_FFF(dc, rd, rs1, rs2, gen_helper_fdivs);
3016 case 0x4e: /* fdivd */
3017 gen_fop_DDD(dc, rd, rs1, rs2, gen_helper_fdivd);
3019 case 0x4f: /* fdivq */
3020 CHECK_FPU_FEATURE(dc, FLOAT128);
3021 gen_fop_QQQ(dc, rd, rs1, rs2, gen_helper_fdivq);
3023 case 0x69: /* fsmuld */
3024 CHECK_FPU_FEATURE(dc, FSMULD);
3025 gen_fop_DFF(dc, rd, rs1, rs2, gen_helper_fsmuld);
3027 case 0x6e: /* fdmulq */
3028 CHECK_FPU_FEATURE(dc, FLOAT128);
3029 gen_fop_QDD(dc, rd, rs1, rs2, gen_helper_fdmulq);
3031 case 0xc4: /* fitos */
3032 gen_fop_FF(dc, rd, rs2, gen_helper_fitos);
3034 case 0xc6: /* fdtos */
3035 gen_fop_FD(dc, rd, rs2, gen_helper_fdtos);
3037 case 0xc7: /* fqtos */
3038 CHECK_FPU_FEATURE(dc, FLOAT128);
3039 gen_fop_FQ(dc, rd, rs2, gen_helper_fqtos);
3041 case 0xc8: /* fitod */
3042 gen_ne_fop_DF(dc, rd, rs2, gen_helper_fitod);
3044 case 0xc9: /* fstod */
3045 gen_ne_fop_DF(dc, rd, rs2, gen_helper_fstod);
3047 case 0xcb: /* fqtod */
3048 CHECK_FPU_FEATURE(dc, FLOAT128);
3049 gen_fop_DQ(dc, rd, rs2, gen_helper_fqtod);
3051 case 0xcc: /* fitoq */
3052 CHECK_FPU_FEATURE(dc, FLOAT128);
3053 gen_ne_fop_QF(dc, rd, rs2, gen_helper_fitoq);
3055 case 0xcd: /* fstoq */
3056 CHECK_FPU_FEATURE(dc, FLOAT128);
3057 gen_ne_fop_QF(dc, rd, rs2, gen_helper_fstoq);
3059 case 0xce: /* fdtoq */
3060 CHECK_FPU_FEATURE(dc, FLOAT128);
3061 gen_ne_fop_QD(dc, rd, rs2, gen_helper_fdtoq);
3063 case 0xd1: /* fstoi */
3064 gen_fop_FF(dc, rd, rs2, gen_helper_fstoi);
3066 case 0xd2: /* fdtoi */
3067 gen_fop_FD(dc, rd, rs2, gen_helper_fdtoi);
3069 case 0xd3: /* fqtoi */
3070 CHECK_FPU_FEATURE(dc, FLOAT128);
3071 gen_fop_FQ(dc, rd, rs2, gen_helper_fqtoi);
3073 #ifdef TARGET_SPARC64
3074 case 0x2: /* V9 fmovd */
3075 cpu_src1_64 = gen_load_fpr_D(dc, rs2);
3076 gen_store_fpr_D(dc, rd, cpu_src1_64);
3078 case 0x3: /* V9 fmovq */
3079 CHECK_FPU_FEATURE(dc, FLOAT128);
3080 gen_move_Q(rd, rs2);
3082 case 0x6: /* V9 fnegd */
3083 gen_ne_fop_DD(dc, rd, rs2, gen_helper_fnegd);
3085 case 0x7: /* V9 fnegq */
3086 CHECK_FPU_FEATURE(dc, FLOAT128);
3087 gen_ne_fop_QQ(dc, rd, rs2, gen_helper_fnegq);
3089 case 0xa: /* V9 fabsd */
3090 gen_ne_fop_DD(dc, rd, rs2, gen_helper_fabsd);
3092 case 0xb: /* V9 fabsq */
3093 CHECK_FPU_FEATURE(dc, FLOAT128);
3094 gen_ne_fop_QQ(dc, rd, rs2, gen_helper_fabsq);
3096 case 0x81: /* V9 fstox */
3097 gen_fop_DF(dc, rd, rs2, gen_helper_fstox);
3099 case 0x82: /* V9 fdtox */
3100 gen_fop_DD(dc, rd, rs2, gen_helper_fdtox);
3102 case 0x83: /* V9 fqtox */
3103 CHECK_FPU_FEATURE(dc, FLOAT128);
3104 gen_fop_DQ(dc, rd, rs2, gen_helper_fqtox);
3106 case 0x84: /* V9 fxtos */
3107 gen_fop_FD(dc, rd, rs2, gen_helper_fxtos);
3109 case 0x88: /* V9 fxtod */
3110 gen_fop_DD(dc, rd, rs2, gen_helper_fxtod);
3112 case 0x8c: /* V9 fxtoq */
3113 CHECK_FPU_FEATURE(dc, FLOAT128);
3114 gen_ne_fop_QD(dc, rd, rs2, gen_helper_fxtoq);
3120 } else if (xop == 0x35) { /* FPU Operations */
3121 #ifdef TARGET_SPARC64
3124 if (gen_trap_ifnofpu(dc)) {
3127 gen_op_clear_ieee_excp_and_FTT();
3128 rs1 = GET_FIELD(insn, 13, 17);
3129 rs2 = GET_FIELD(insn, 27, 31);
3130 xop = GET_FIELD(insn, 18, 26);
3133 #ifdef TARGET_SPARC64
3137 cond = GET_FIELD_SP(insn, 10, 12); \
3138 cpu_src1 = get_src1(dc, insn); \
3139 gen_compare_reg(&cmp, cond, cpu_src1); \
3140 gen_fmov##sz(dc, &cmp, rd, rs2); \
3141 free_compare(&cmp); \
3144 if ((xop & 0x11f) == 0x005) { /* V9 fmovsr */
3147 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
3150 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
3151 CHECK_FPU_FEATURE(dc, FLOAT128);
3158 #ifdef TARGET_SPARC64
3159 #define FMOVCC(fcc, sz) \
3162 cond = GET_FIELD_SP(insn, 14, 17); \
3163 gen_fcompare(&cmp, fcc, cond); \
3164 gen_fmov##sz(dc, &cmp, rd, rs2); \
3165 free_compare(&cmp); \
3168 case 0x001: /* V9 fmovscc %fcc0 */
3171 case 0x002: /* V9 fmovdcc %fcc0 */
3174 case 0x003: /* V9 fmovqcc %fcc0 */
3175 CHECK_FPU_FEATURE(dc, FLOAT128);
3178 case 0x041: /* V9 fmovscc %fcc1 */
3181 case 0x042: /* V9 fmovdcc %fcc1 */
3184 case 0x043: /* V9 fmovqcc %fcc1 */
3185 CHECK_FPU_FEATURE(dc, FLOAT128);
3188 case 0x081: /* V9 fmovscc %fcc2 */
3191 case 0x082: /* V9 fmovdcc %fcc2 */
3194 case 0x083: /* V9 fmovqcc %fcc2 */
3195 CHECK_FPU_FEATURE(dc, FLOAT128);
3198 case 0x0c1: /* V9 fmovscc %fcc3 */
3201 case 0x0c2: /* V9 fmovdcc %fcc3 */
3204 case 0x0c3: /* V9 fmovqcc %fcc3 */
3205 CHECK_FPU_FEATURE(dc, FLOAT128);
3209 #define FMOVCC(xcc, sz) \
3212 cond = GET_FIELD_SP(insn, 14, 17); \
3213 gen_compare(&cmp, xcc, cond, dc); \
3214 gen_fmov##sz(dc, &cmp, rd, rs2); \
3215 free_compare(&cmp); \
3218 case 0x101: /* V9 fmovscc %icc */
3221 case 0x102: /* V9 fmovdcc %icc */
3224 case 0x103: /* V9 fmovqcc %icc */
3225 CHECK_FPU_FEATURE(dc, FLOAT128);
3228 case 0x181: /* V9 fmovscc %xcc */
3231 case 0x182: /* V9 fmovdcc %xcc */
3234 case 0x183: /* V9 fmovqcc %xcc */
3235 CHECK_FPU_FEATURE(dc, FLOAT128);
3240 case 0x51: /* fcmps, V9 %fcc */
3241 cpu_src1_32 = gen_load_fpr_F(dc, rs1);
3242 cpu_src2_32 = gen_load_fpr_F(dc, rs2);
3243 gen_op_fcmps(rd & 3, cpu_src1_32, cpu_src2_32);
3245 case 0x52: /* fcmpd, V9 %fcc */
3246 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
3247 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
3248 gen_op_fcmpd(rd & 3, cpu_src1_64, cpu_src2_64);
3250 case 0x53: /* fcmpq, V9 %fcc */
3251 CHECK_FPU_FEATURE(dc, FLOAT128);
3252 gen_op_load_fpr_QT0(QFPREG(rs1));
3253 gen_op_load_fpr_QT1(QFPREG(rs2));
3254 gen_op_fcmpq(rd & 3);
3256 case 0x55: /* fcmpes, V9 %fcc */
3257 cpu_src1_32 = gen_load_fpr_F(dc, rs1);
3258 cpu_src2_32 = gen_load_fpr_F(dc, rs2);
3259 gen_op_fcmpes(rd & 3, cpu_src1_32, cpu_src2_32);
3261 case 0x56: /* fcmped, V9 %fcc */
3262 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
3263 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
3264 gen_op_fcmped(rd & 3, cpu_src1_64, cpu_src2_64);
3266 case 0x57: /* fcmpeq, V9 %fcc */
3267 CHECK_FPU_FEATURE(dc, FLOAT128);
3268 gen_op_load_fpr_QT0(QFPREG(rs1));
3269 gen_op_load_fpr_QT1(QFPREG(rs2));
3270 gen_op_fcmpeq(rd & 3);
3275 } else if (xop == 0x2) {
3276 TCGv dst = gen_dest_gpr(dc, rd);
3277 rs1 = GET_FIELD(insn, 13, 17);
3279 /* clr/mov shortcut : or %g0, x, y -> mov x, y */
3280 if (IS_IMM) { /* immediate */
3281 simm = GET_FIELDs(insn, 19, 31);
3282 tcg_gen_movi_tl(dst, simm);
3283 gen_store_gpr(dc, rd, dst);
3284 } else { /* register */
3285 rs2 = GET_FIELD(insn, 27, 31);
3287 tcg_gen_movi_tl(dst, 0);
3288 gen_store_gpr(dc, rd, dst);
3290 cpu_src2 = gen_load_gpr(dc, rs2);
3291 gen_store_gpr(dc, rd, cpu_src2);
3295 cpu_src1 = get_src1(dc, insn);
3296 if (IS_IMM) { /* immediate */
3297 simm = GET_FIELDs(insn, 19, 31);
3298 tcg_gen_ori_tl(dst, cpu_src1, simm);
3299 gen_store_gpr(dc, rd, dst);
3300 } else { /* register */
3301 rs2 = GET_FIELD(insn, 27, 31);
3303 /* mov shortcut: or x, %g0, y -> mov x, y */
3304 gen_store_gpr(dc, rd, cpu_src1);
3306 cpu_src2 = gen_load_gpr(dc, rs2);
3307 tcg_gen_or_tl(dst, cpu_src1, cpu_src2);
3308 gen_store_gpr(dc, rd, dst);
3312 #ifdef TARGET_SPARC64
3313 } else if (xop == 0x25) { /* sll, V9 sllx */
3314 cpu_src1 = get_src1(dc, insn);
3315 if (IS_IMM) { /* immediate */
3316 simm = GET_FIELDs(insn, 20, 31);
3317 if (insn & (1 << 12)) {
3318 tcg_gen_shli_i64(cpu_dst, cpu_src1, simm & 0x3f);
3320 tcg_gen_shli_i64(cpu_dst, cpu_src1, simm & 0x1f);
3322 } else { /* register */
3323 rs2 = GET_FIELD(insn, 27, 31);
3324 cpu_src2 = gen_load_gpr(dc, rs2);
3325 cpu_tmp0 = get_temp_tl(dc);
3326 if (insn & (1 << 12)) {
3327 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
3329 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
3331 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
3333 gen_store_gpr(dc, rd, cpu_dst);
3334 } else if (xop == 0x26) { /* srl, V9 srlx */
3335 cpu_src1 = get_src1(dc, insn);
3336 if (IS_IMM) { /* immediate */
3337 simm = GET_FIELDs(insn, 20, 31);
3338 if (insn & (1 << 12)) {
3339 tcg_gen_shri_i64(cpu_dst, cpu_src1, simm & 0x3f);
3341 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
3342 tcg_gen_shri_i64(cpu_dst, cpu_dst, simm & 0x1f);
3344 } else { /* register */
3345 rs2 = GET_FIELD(insn, 27, 31);
3346 cpu_src2 = gen_load_gpr(dc, rs2);
3347 cpu_tmp0 = get_temp_tl(dc);
3348 if (insn & (1 << 12)) {
3349 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
3350 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
3352 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
3353 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
3354 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
3357 gen_store_gpr(dc, rd, cpu_dst);
3358 } else if (xop == 0x27) { /* sra, V9 srax */
3359 cpu_src1 = get_src1(dc, insn);
3360 if (IS_IMM) { /* immediate */
3361 simm = GET_FIELDs(insn, 20, 31);
3362 if (insn & (1 << 12)) {
3363 tcg_gen_sari_i64(cpu_dst, cpu_src1, simm & 0x3f);
3365 tcg_gen_ext32s_i64(cpu_dst, cpu_src1);
3366 tcg_gen_sari_i64(cpu_dst, cpu_dst, simm & 0x1f);
3368 } else { /* register */
3369 rs2 = GET_FIELD(insn, 27, 31);
3370 cpu_src2 = gen_load_gpr(dc, rs2);
3371 cpu_tmp0 = get_temp_tl(dc);
3372 if (insn & (1 << 12)) {
3373 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
3374 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
3376 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
3377 tcg_gen_ext32s_i64(cpu_dst, cpu_src1);
3378 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
3381 gen_store_gpr(dc, rd, cpu_dst);
3383 } else if (xop < 0x36) {
3385 cpu_src1 = get_src1(dc, insn);
3386 cpu_src2 = get_src2(dc, insn);
3387 switch (xop & ~0x10) {
3390 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
3391 tcg_gen_movi_i32(cpu_cc_op, CC_OP_ADD);
3392 dc->cc_op = CC_OP_ADD;
3394 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3398 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
3400 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3401 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3402 dc->cc_op = CC_OP_LOGIC;
3406 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
3408 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3409 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3410 dc->cc_op = CC_OP_LOGIC;
3414 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3416 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3417 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3418 dc->cc_op = CC_OP_LOGIC;
3423 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
3424 tcg_gen_movi_i32(cpu_cc_op, CC_OP_SUB);
3425 dc->cc_op = CC_OP_SUB;
3427 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
3430 case 0x5: /* andn */
3431 tcg_gen_andc_tl(cpu_dst, cpu_src1, cpu_src2);
3433 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3434 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3435 dc->cc_op = CC_OP_LOGIC;
3439 tcg_gen_orc_tl(cpu_dst, cpu_src1, cpu_src2);
3441 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3442 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3443 dc->cc_op = CC_OP_LOGIC;
3446 case 0x7: /* xorn */
3447 tcg_gen_eqv_tl(cpu_dst, cpu_src1, cpu_src2);
3449 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3450 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3451 dc->cc_op = CC_OP_LOGIC;
3454 case 0x8: /* addx, V9 addc */
3455 gen_op_addx_int(dc, cpu_dst, cpu_src1, cpu_src2,
3458 #ifdef TARGET_SPARC64
3459 case 0x9: /* V9 mulx */
3460 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3463 case 0xa: /* umul */
3464 CHECK_IU_FEATURE(dc, MUL);
3465 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3467 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3468 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3469 dc->cc_op = CC_OP_LOGIC;
3472 case 0xb: /* smul */
3473 CHECK_IU_FEATURE(dc, MUL);
3474 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3476 tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
3477 tcg_gen_movi_i32(cpu_cc_op, CC_OP_LOGIC);
3478 dc->cc_op = CC_OP_LOGIC;
3481 case 0xc: /* subx, V9 subc */
3482 gen_op_subx_int(dc, cpu_dst, cpu_src1, cpu_src2,
3485 #ifdef TARGET_SPARC64
3486 case 0xd: /* V9 udivx */
3487 gen_helper_udivx(cpu_dst, cpu_env, cpu_src1, cpu_src2);
3490 case 0xe: /* udiv */
3491 CHECK_IU_FEATURE(dc, DIV);
3493 gen_helper_udiv_cc(cpu_dst, cpu_env, cpu_src1,
3495 dc->cc_op = CC_OP_DIV;
3497 gen_helper_udiv(cpu_dst, cpu_env, cpu_src1,
3501 case 0xf: /* sdiv */
3502 CHECK_IU_FEATURE(dc, DIV);
3504 gen_helper_sdiv_cc(cpu_dst, cpu_env, cpu_src1,
3506 dc->cc_op = CC_OP_DIV;
3508 gen_helper_sdiv(cpu_dst, cpu_env, cpu_src1,
3515 gen_store_gpr(dc, rd, cpu_dst);
3517 cpu_src1 = get_src1(dc, insn);
3518 cpu_src2 = get_src2(dc, insn);
3520 case 0x20: /* taddcc */
3521 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
3522 gen_store_gpr(dc, rd, cpu_dst);
3523 tcg_gen_movi_i32(cpu_cc_op, CC_OP_TADD);
3524 dc->cc_op = CC_OP_TADD;
3526 case 0x21: /* tsubcc */
3527 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
3528 gen_store_gpr(dc, rd, cpu_dst);
3529 tcg_gen_movi_i32(cpu_cc_op, CC_OP_TSUB);
3530 dc->cc_op = CC_OP_TSUB;
3532 case 0x22: /* taddcctv */
3533 gen_helper_taddcctv(cpu_dst, cpu_env,
3534 cpu_src1, cpu_src2);
3535 gen_store_gpr(dc, rd, cpu_dst);
3536 dc->cc_op = CC_OP_TADDTV;
3538 case 0x23: /* tsubcctv */
3539 gen_helper_tsubcctv(cpu_dst, cpu_env,
3540 cpu_src1, cpu_src2);
3541 gen_store_gpr(dc, rd, cpu_dst);
3542 dc->cc_op = CC_OP_TSUBTV;
3544 case 0x24: /* mulscc */
3546 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3547 gen_store_gpr(dc, rd, cpu_dst);
3548 tcg_gen_movi_i32(cpu_cc_op, CC_OP_ADD);
3549 dc->cc_op = CC_OP_ADD;
3551 #ifndef TARGET_SPARC64
3552 case 0x25: /* sll */
3553 if (IS_IMM) { /* immediate */
3554 simm = GET_FIELDs(insn, 20, 31);
3555 tcg_gen_shli_tl(cpu_dst, cpu_src1, simm & 0x1f);
3556 } else { /* register */
3557 cpu_tmp0 = get_temp_tl(dc);
3558 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3559 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3561 gen_store_gpr(dc, rd, cpu_dst);
3563 case 0x26: /* srl */
3564 if (IS_IMM) { /* immediate */
3565 simm = GET_FIELDs(insn, 20, 31);
3566 tcg_gen_shri_tl(cpu_dst, cpu_src1, simm & 0x1f);
3567 } else { /* register */
3568 cpu_tmp0 = get_temp_tl(dc);
3569 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3570 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3572 gen_store_gpr(dc, rd, cpu_dst);
3574 case 0x27: /* sra */
3575 if (IS_IMM) { /* immediate */
3576 simm = GET_FIELDs(insn, 20, 31);
3577 tcg_gen_sari_tl(cpu_dst, cpu_src1, simm & 0x1f);
3578 } else { /* register */
3579 cpu_tmp0 = get_temp_tl(dc);
3580 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3581 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3583 gen_store_gpr(dc, rd, cpu_dst);
3588 cpu_tmp0 = get_temp_tl(dc);
3591 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3592 tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
3594 #ifndef TARGET_SPARC64
3595 case 0x01 ... 0x0f: /* undefined in the
3599 case 0x10 ... 0x1f: /* implementation-dependent
3603 if ((rd == 0x13) && (dc->def->features &
3604 CPU_FEATURE_POWERDOWN)) {
3605 /* LEON3 power-down */
3607 gen_helper_power_down(cpu_env);
3611 case 0x2: /* V9 wrccr */
3612 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3613 gen_helper_wrccr(cpu_env, cpu_tmp0);
3614 tcg_gen_movi_i32(cpu_cc_op, CC_OP_FLAGS);
3615 dc->cc_op = CC_OP_FLAGS;
3617 case 0x3: /* V9 wrasi */
3618 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3619 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xff);
3620 tcg_gen_trunc_tl_i32(cpu_asi, cpu_tmp0);
3622 case 0x6: /* V9 wrfprs */
3623 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3624 tcg_gen_trunc_tl_i32(cpu_fprs, cpu_tmp0);
3630 case 0xf: /* V9 sir, nop if user */
3631 #if !defined(CONFIG_USER_ONLY)
3632 if (supervisor(dc)) {
3637 case 0x13: /* Graphics Status */
3638 if (gen_trap_ifnofpu(dc)) {
3641 tcg_gen_xor_tl(cpu_gsr, cpu_src1, cpu_src2);
3643 case 0x14: /* Softint set */
3644 if (!supervisor(dc))
3646 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3647 gen_helper_set_softint(cpu_env, cpu_tmp0);
3649 case 0x15: /* Softint clear */
3650 if (!supervisor(dc))
3652 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3653 gen_helper_clear_softint(cpu_env, cpu_tmp0);
3655 case 0x16: /* Softint write */
3656 if (!supervisor(dc))
3658 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3659 gen_helper_write_softint(cpu_env, cpu_tmp0);
3661 case 0x17: /* Tick compare */
3662 #if !defined(CONFIG_USER_ONLY)
3663 if (!supervisor(dc))
3669 tcg_gen_xor_tl(cpu_tick_cmpr, cpu_src1,
3671 r_tickptr = tcg_temp_new_ptr();
3672 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3673 offsetof(CPUSPARCState, tick));
3674 gen_helper_tick_set_limit(r_tickptr,
3676 tcg_temp_free_ptr(r_tickptr);
3679 case 0x18: /* System tick */
3680 #if !defined(CONFIG_USER_ONLY)
3681 if (!supervisor(dc))
3687 tcg_gen_xor_tl(cpu_tmp0, cpu_src1,
3689 r_tickptr = tcg_temp_new_ptr();
3690 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3691 offsetof(CPUSPARCState, stick));
3692 gen_helper_tick_set_count(r_tickptr,
3694 tcg_temp_free_ptr(r_tickptr);
3697 case 0x19: /* System tick compare */
3698 #if !defined(CONFIG_USER_ONLY)
3699 if (!supervisor(dc))
3705 tcg_gen_xor_tl(cpu_stick_cmpr, cpu_src1,
3707 r_tickptr = tcg_temp_new_ptr();
3708 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3709 offsetof(CPUSPARCState, stick));
3710 gen_helper_tick_set_limit(r_tickptr,
3712 tcg_temp_free_ptr(r_tickptr);
3716 case 0x10: /* Performance Control */
3717 case 0x11: /* Performance Instrumentation
3719 case 0x12: /* Dispatch Control */
3726 #if !defined(CONFIG_USER_ONLY)
3727 case 0x31: /* wrpsr, V9 saved, restored */
3729 if (!supervisor(dc))
3731 #ifdef TARGET_SPARC64
3734 gen_helper_saved(cpu_env);
3737 gen_helper_restored(cpu_env);
3739 case 2: /* UA2005 allclean */
3740 case 3: /* UA2005 otherw */
3741 case 4: /* UA2005 normalw */
3742 case 5: /* UA2005 invalw */
3748 cpu_tmp0 = get_temp_tl(dc);
3749 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3750 gen_helper_wrpsr(cpu_env, cpu_tmp0);
3751 tcg_gen_movi_i32(cpu_cc_op, CC_OP_FLAGS);
3752 dc->cc_op = CC_OP_FLAGS;
3760 case 0x32: /* wrwim, V9 wrpr */
3762 if (!supervisor(dc))
3764 cpu_tmp0 = get_temp_tl(dc);
3765 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3766 #ifdef TARGET_SPARC64
3772 r_tsptr = tcg_temp_new_ptr();
3773 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
3774 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3775 offsetof(trap_state, tpc));
3776 tcg_temp_free_ptr(r_tsptr);
3783 r_tsptr = tcg_temp_new_ptr();
3784 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
3785 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3786 offsetof(trap_state, tnpc));
3787 tcg_temp_free_ptr(r_tsptr);
3794 r_tsptr = tcg_temp_new_ptr();
3795 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
3796 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3797 offsetof(trap_state,
3799 tcg_temp_free_ptr(r_tsptr);
3806 r_tsptr = tcg_temp_new_ptr();
3807 gen_load_trap_state_at_tl(r_tsptr, cpu_env);
3808 tcg_gen_st32_tl(cpu_tmp0, r_tsptr,
3809 offsetof(trap_state, tt));
3810 tcg_temp_free_ptr(r_tsptr);
3817 r_tickptr = tcg_temp_new_ptr();
3818 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3819 offsetof(CPUSPARCState, tick));
3820 gen_helper_tick_set_count(r_tickptr,
3822 tcg_temp_free_ptr(r_tickptr);
3826 tcg_gen_mov_tl(cpu_tbr, cpu_tmp0);
3830 gen_helper_wrpstate(cpu_env, cpu_tmp0);
3831 dc->npc = DYNAMIC_PC;
3835 tcg_gen_st32_tl(cpu_tmp0, cpu_env,
3836 offsetof(CPUSPARCState, tl));
3837 dc->npc = DYNAMIC_PC;
3840 gen_helper_wrpil(cpu_env, cpu_tmp0);
3843 gen_helper_wrcwp(cpu_env, cpu_tmp0);
3846 tcg_gen_st32_tl(cpu_tmp0, cpu_env,
3847 offsetof(CPUSPARCState,
3850 case 11: // canrestore
3851 tcg_gen_st32_tl(cpu_tmp0, cpu_env,
3852 offsetof(CPUSPARCState,
3855 case 12: // cleanwin
3856 tcg_gen_st32_tl(cpu_tmp0, cpu_env,
3857 offsetof(CPUSPARCState,
3860 case 13: // otherwin
3861 tcg_gen_st32_tl(cpu_tmp0, cpu_env,
3862 offsetof(CPUSPARCState,
3866 tcg_gen_st32_tl(cpu_tmp0, cpu_env,
3867 offsetof(CPUSPARCState,
3870 case 16: // UA2005 gl
3871 CHECK_IU_FEATURE(dc, GL);
3872 tcg_gen_st32_tl(cpu_tmp0, cpu_env,
3873 offsetof(CPUSPARCState, gl));
3875 case 26: // UA2005 strand status
3876 CHECK_IU_FEATURE(dc, HYPV);
3877 if (!hypervisor(dc))
3879 tcg_gen_mov_tl(cpu_ssr, cpu_tmp0);
3885 tcg_gen_trunc_tl_i32(cpu_wim, cpu_tmp0);
3886 if (dc->def->nwindows != 32) {
3887 tcg_gen_andi_tl(cpu_wim, cpu_wim,
3888 (1 << dc->def->nwindows) - 1);
3893 case 0x33: /* wrtbr, UA2005 wrhpr */
3895 #ifndef TARGET_SPARC64
3896 if (!supervisor(dc))
3898 tcg_gen_xor_tl(cpu_tbr, cpu_src1, cpu_src2);
3900 CHECK_IU_FEATURE(dc, HYPV);
3901 if (!hypervisor(dc))
3903 cpu_tmp0 = get_temp_tl(dc);
3904 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3907 // XXX gen_op_wrhpstate();
3914 // XXX gen_op_wrhtstate();
3917 tcg_gen_mov_tl(cpu_hintp, cpu_tmp0);
3920 tcg_gen_mov_tl(cpu_htba, cpu_tmp0);
3922 case 31: // hstick_cmpr
3926 tcg_gen_mov_tl(cpu_hstick_cmpr, cpu_tmp0);
3927 r_tickptr = tcg_temp_new_ptr();
3928 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3929 offsetof(CPUSPARCState, hstick));
3930 gen_helper_tick_set_limit(r_tickptr,
3932 tcg_temp_free_ptr(r_tickptr);
3935 case 6: // hver readonly
3943 #ifdef TARGET_SPARC64
3944 case 0x2c: /* V9 movcc */
3946 int cc = GET_FIELD_SP(insn, 11, 12);
3947 int cond = GET_FIELD_SP(insn, 14, 17);
3951 if (insn & (1 << 18)) {
3953 gen_compare(&cmp, 0, cond, dc);
3954 } else if (cc == 2) {
3955 gen_compare(&cmp, 1, cond, dc);
3960 gen_fcompare(&cmp, cc, cond);
3963 /* The get_src2 above loaded the normal 13-bit
3964 immediate field, not the 11-bit field we have
3965 in movcc. But it did handle the reg case. */
3967 simm = GET_FIELD_SPs(insn, 0, 10);
3968 tcg_gen_movi_tl(cpu_src2, simm);
3971 dst = gen_load_gpr(dc, rd);
3972 tcg_gen_movcond_tl(cmp.cond, dst,
3976 gen_store_gpr(dc, rd, dst);
3979 case 0x2d: /* V9 sdivx */
3980 gen_helper_sdivx(cpu_dst, cpu_env, cpu_src1, cpu_src2);
3981 gen_store_gpr(dc, rd, cpu_dst);
3983 case 0x2e: /* V9 popc */
3984 gen_helper_popc(cpu_dst, cpu_src2);
3985 gen_store_gpr(dc, rd, cpu_dst);
3987 case 0x2f: /* V9 movr */
3989 int cond = GET_FIELD_SP(insn, 10, 12);
3993 gen_compare_reg(&cmp, cond, cpu_src1);
3995 /* The get_src2 above loaded the normal 13-bit
3996 immediate field, not the 10-bit field we have
3997 in movr. But it did handle the reg case. */
3999 simm = GET_FIELD_SPs(insn, 0, 9);
4000 tcg_gen_movi_tl(cpu_src2, simm);
4003 dst = gen_load_gpr(dc, rd);
4004 tcg_gen_movcond_tl(cmp.cond, dst,
4008 gen_store_gpr(dc, rd, dst);
4016 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
4017 #ifdef TARGET_SPARC64
4018 int opf = GET_FIELD_SP(insn, 5, 13);
4019 rs1 = GET_FIELD(insn, 13, 17);
4020 rs2 = GET_FIELD(insn, 27, 31);
4021 if (gen_trap_ifnofpu(dc)) {
4026 case 0x000: /* VIS I edge8cc */
4027 CHECK_FPU_FEATURE(dc, VIS1);
4028 cpu_src1 = gen_load_gpr(dc, rs1);
4029 cpu_src2 = gen_load_gpr(dc, rs2);
4030 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 8, 1, 0);
4031 gen_store_gpr(dc, rd, cpu_dst);
4033 case 0x001: /* VIS II edge8n */
4034 CHECK_FPU_FEATURE(dc, VIS2);
4035 cpu_src1 = gen_load_gpr(dc, rs1);
4036 cpu_src2 = gen_load_gpr(dc, rs2);
4037 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 8, 0, 0);
4038 gen_store_gpr(dc, rd, cpu_dst);
4040 case 0x002: /* VIS I edge8lcc */
4041 CHECK_FPU_FEATURE(dc, VIS1);
4042 cpu_src1 = gen_load_gpr(dc, rs1);
4043 cpu_src2 = gen_load_gpr(dc, rs2);
4044 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 8, 1, 1);
4045 gen_store_gpr(dc, rd, cpu_dst);
4047 case 0x003: /* VIS II edge8ln */
4048 CHECK_FPU_FEATURE(dc, VIS2);
4049 cpu_src1 = gen_load_gpr(dc, rs1);
4050 cpu_src2 = gen_load_gpr(dc, rs2);
4051 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 8, 0, 1);
4052 gen_store_gpr(dc, rd, cpu_dst);
4054 case 0x004: /* VIS I edge16cc */
4055 CHECK_FPU_FEATURE(dc, VIS1);
4056 cpu_src1 = gen_load_gpr(dc, rs1);
4057 cpu_src2 = gen_load_gpr(dc, rs2);
4058 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 16, 1, 0);
4059 gen_store_gpr(dc, rd, cpu_dst);
4061 case 0x005: /* VIS II edge16n */
4062 CHECK_FPU_FEATURE(dc, VIS2);
4063 cpu_src1 = gen_load_gpr(dc, rs1);
4064 cpu_src2 = gen_load_gpr(dc, rs2);
4065 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 16, 0, 0);
4066 gen_store_gpr(dc, rd, cpu_dst);
4068 case 0x006: /* VIS I edge16lcc */
4069 CHECK_FPU_FEATURE(dc, VIS1);
4070 cpu_src1 = gen_load_gpr(dc, rs1);
4071 cpu_src2 = gen_load_gpr(dc, rs2);
4072 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 16, 1, 1);
4073 gen_store_gpr(dc, rd, cpu_dst);
4075 case 0x007: /* VIS II edge16ln */
4076 CHECK_FPU_FEATURE(dc, VIS2);
4077 cpu_src1 = gen_load_gpr(dc, rs1);
4078 cpu_src2 = gen_load_gpr(dc, rs2);
4079 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 16, 0, 1);
4080 gen_store_gpr(dc, rd, cpu_dst);
4082 case 0x008: /* VIS I edge32cc */
4083 CHECK_FPU_FEATURE(dc, VIS1);
4084 cpu_src1 = gen_load_gpr(dc, rs1);
4085 cpu_src2 = gen_load_gpr(dc, rs2);
4086 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 32, 1, 0);
4087 gen_store_gpr(dc, rd, cpu_dst);
4089 case 0x009: /* VIS II edge32n */
4090 CHECK_FPU_FEATURE(dc, VIS2);
4091 cpu_src1 = gen_load_gpr(dc, rs1);
4092 cpu_src2 = gen_load_gpr(dc, rs2);
4093 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 32, 0, 0);
4094 gen_store_gpr(dc, rd, cpu_dst);
4096 case 0x00a: /* VIS I edge32lcc */
4097 CHECK_FPU_FEATURE(dc, VIS1);
4098 cpu_src1 = gen_load_gpr(dc, rs1);
4099 cpu_src2 = gen_load_gpr(dc, rs2);
4100 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 32, 1, 1);
4101 gen_store_gpr(dc, rd, cpu_dst);
4103 case 0x00b: /* VIS II edge32ln */
4104 CHECK_FPU_FEATURE(dc, VIS2);
4105 cpu_src1 = gen_load_gpr(dc, rs1);
4106 cpu_src2 = gen_load_gpr(dc, rs2);
4107 gen_edge(dc, cpu_dst, cpu_src1, cpu_src2, 32, 0, 1);
4108 gen_store_gpr(dc, rd, cpu_dst);
4110 case 0x010: /* VIS I array8 */
4111 CHECK_FPU_FEATURE(dc, VIS1);
4112 cpu_src1 = gen_load_gpr(dc, rs1);
4113 cpu_src2 = gen_load_gpr(dc, rs2);
4114 gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
4115 gen_store_gpr(dc, rd, cpu_dst);
4117 case 0x012: /* VIS I array16 */
4118 CHECK_FPU_FEATURE(dc, VIS1);
4119 cpu_src1 = gen_load_gpr(dc, rs1);
4120 cpu_src2 = gen_load_gpr(dc, rs2);
4121 gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
4122 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
4123 gen_store_gpr(dc, rd, cpu_dst);
4125 case 0x014: /* VIS I array32 */
4126 CHECK_FPU_FEATURE(dc, VIS1);
4127 cpu_src1 = gen_load_gpr(dc, rs1);
4128 cpu_src2 = gen_load_gpr(dc, rs2);
4129 gen_helper_array8(cpu_dst, cpu_src1, cpu_src2);
4130 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
4131 gen_store_gpr(dc, rd, cpu_dst);
4133 case 0x018: /* VIS I alignaddr */
4134 CHECK_FPU_FEATURE(dc, VIS1);
4135 cpu_src1 = gen_load_gpr(dc, rs1);
4136 cpu_src2 = gen_load_gpr(dc, rs2);
4137 gen_alignaddr(cpu_dst, cpu_src1, cpu_src2, 0);
4138 gen_store_gpr(dc, rd, cpu_dst);
4140 case 0x01a: /* VIS I alignaddrl */
4141 CHECK_FPU_FEATURE(dc, VIS1);
4142 cpu_src1 = gen_load_gpr(dc, rs1);
4143 cpu_src2 = gen_load_gpr(dc, rs2);
4144 gen_alignaddr(cpu_dst, cpu_src1, cpu_src2, 1);
4145 gen_store_gpr(dc, rd, cpu_dst);
4147 case 0x019: /* VIS II bmask */
4148 CHECK_FPU_FEATURE(dc, VIS2);
4149 cpu_src1 = gen_load_gpr(dc, rs1);
4150 cpu_src2 = gen_load_gpr(dc, rs2);
4151 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4152 tcg_gen_deposit_tl(cpu_gsr, cpu_gsr, cpu_dst, 32, 32);
4153 gen_store_gpr(dc, rd, cpu_dst);
4155 case 0x020: /* VIS I fcmple16 */
4156 CHECK_FPU_FEATURE(dc, VIS1);
4157 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4158 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4159 gen_helper_fcmple16(cpu_dst, cpu_src1_64, cpu_src2_64);
4160 gen_store_gpr(dc, rd, cpu_dst);
4162 case 0x022: /* VIS I fcmpne16 */
4163 CHECK_FPU_FEATURE(dc, VIS1);
4164 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4165 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4166 gen_helper_fcmpne16(cpu_dst, cpu_src1_64, cpu_src2_64);
4167 gen_store_gpr(dc, rd, cpu_dst);
4169 case 0x024: /* VIS I fcmple32 */
4170 CHECK_FPU_FEATURE(dc, VIS1);
4171 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4172 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4173 gen_helper_fcmple32(cpu_dst, cpu_src1_64, cpu_src2_64);
4174 gen_store_gpr(dc, rd, cpu_dst);
4176 case 0x026: /* VIS I fcmpne32 */
4177 CHECK_FPU_FEATURE(dc, VIS1);
4178 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4179 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4180 gen_helper_fcmpne32(cpu_dst, cpu_src1_64, cpu_src2_64);
4181 gen_store_gpr(dc, rd, cpu_dst);
4183 case 0x028: /* VIS I fcmpgt16 */
4184 CHECK_FPU_FEATURE(dc, VIS1);
4185 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4186 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4187 gen_helper_fcmpgt16(cpu_dst, cpu_src1_64, cpu_src2_64);
4188 gen_store_gpr(dc, rd, cpu_dst);
4190 case 0x02a: /* VIS I fcmpeq16 */
4191 CHECK_FPU_FEATURE(dc, VIS1);
4192 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4193 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4194 gen_helper_fcmpeq16(cpu_dst, cpu_src1_64, cpu_src2_64);
4195 gen_store_gpr(dc, rd, cpu_dst);
4197 case 0x02c: /* VIS I fcmpgt32 */
4198 CHECK_FPU_FEATURE(dc, VIS1);
4199 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4200 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4201 gen_helper_fcmpgt32(cpu_dst, cpu_src1_64, cpu_src2_64);
4202 gen_store_gpr(dc, rd, cpu_dst);
4204 case 0x02e: /* VIS I fcmpeq32 */
4205 CHECK_FPU_FEATURE(dc, VIS1);
4206 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4207 cpu_src2_64 = gen_load_fpr_D(dc, rs2);
4208 gen_helper_fcmpeq32(cpu_dst, cpu_src1_64, cpu_src2_64);
4209 gen_store_gpr(dc, rd, cpu_dst);
4211 case 0x031: /* VIS I fmul8x16 */
4212 CHECK_FPU_FEATURE(dc, VIS1);
4213 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8x16);
4215 case 0x033: /* VIS I fmul8x16au */
4216 CHECK_FPU_FEATURE(dc, VIS1);
4217 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8x16au);
4219 case 0x035: /* VIS I fmul8x16al */
4220 CHECK_FPU_FEATURE(dc, VIS1);
4221 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8x16al);
4223 case 0x036: /* VIS I fmul8sux16 */
4224 CHECK_FPU_FEATURE(dc, VIS1);
4225 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8sux16);
4227 case 0x037: /* VIS I fmul8ulx16 */
4228 CHECK_FPU_FEATURE(dc, VIS1);
4229 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmul8ulx16);
4231 case 0x038: /* VIS I fmuld8sux16 */
4232 CHECK_FPU_FEATURE(dc, VIS1);
4233 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmuld8sux16);
4235 case 0x039: /* VIS I fmuld8ulx16 */
4236 CHECK_FPU_FEATURE(dc, VIS1);
4237 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fmuld8ulx16);
4239 case 0x03a: /* VIS I fpack32 */
4240 CHECK_FPU_FEATURE(dc, VIS1);
4241 gen_gsr_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpack32);
4243 case 0x03b: /* VIS I fpack16 */
4244 CHECK_FPU_FEATURE(dc, VIS1);
4245 cpu_src1_64 = gen_load_fpr_D(dc, rs2);
4246 cpu_dst_32 = gen_dest_fpr_F(dc);
4247 gen_helper_fpack16(cpu_dst_32, cpu_gsr, cpu_src1_64);
4248 gen_store_fpr_F(dc, rd, cpu_dst_32);
4250 case 0x03d: /* VIS I fpackfix */
4251 CHECK_FPU_FEATURE(dc, VIS1);
4252 cpu_src1_64 = gen_load_fpr_D(dc, rs2);
4253 cpu_dst_32 = gen_dest_fpr_F(dc);
4254 gen_helper_fpackfix(cpu_dst_32, cpu_gsr, cpu_src1_64);
4255 gen_store_fpr_F(dc, rd, cpu_dst_32);
4257 case 0x03e: /* VIS I pdist */
4258 CHECK_FPU_FEATURE(dc, VIS1);
4259 gen_ne_fop_DDDD(dc, rd, rs1, rs2, gen_helper_pdist);
4261 case 0x048: /* VIS I faligndata */
4262 CHECK_FPU_FEATURE(dc, VIS1);
4263 gen_gsr_fop_DDD(dc, rd, rs1, rs2, gen_faligndata);
4265 case 0x04b: /* VIS I fpmerge */
4266 CHECK_FPU_FEATURE(dc, VIS1);
4267 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpmerge);
4269 case 0x04c: /* VIS II bshuffle */
4270 CHECK_FPU_FEATURE(dc, VIS2);
4271 gen_gsr_fop_DDD(dc, rd, rs1, rs2, gen_helper_bshuffle);
4273 case 0x04d: /* VIS I fexpand */
4274 CHECK_FPU_FEATURE(dc, VIS1);
4275 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fexpand);
4277 case 0x050: /* VIS I fpadd16 */
4278 CHECK_FPU_FEATURE(dc, VIS1);
4279 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpadd16);
4281 case 0x051: /* VIS I fpadd16s */
4282 CHECK_FPU_FEATURE(dc, VIS1);
4283 gen_ne_fop_FFF(dc, rd, rs1, rs2, gen_helper_fpadd16s);
4285 case 0x052: /* VIS I fpadd32 */
4286 CHECK_FPU_FEATURE(dc, VIS1);
4287 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpadd32);
4289 case 0x053: /* VIS I fpadd32s */
4290 CHECK_FPU_FEATURE(dc, VIS1);
4291 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_add_i32);
4293 case 0x054: /* VIS I fpsub16 */
4294 CHECK_FPU_FEATURE(dc, VIS1);
4295 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpsub16);
4297 case 0x055: /* VIS I fpsub16s */
4298 CHECK_FPU_FEATURE(dc, VIS1);
4299 gen_ne_fop_FFF(dc, rd, rs1, rs2, gen_helper_fpsub16s);
4301 case 0x056: /* VIS I fpsub32 */
4302 CHECK_FPU_FEATURE(dc, VIS1);
4303 gen_ne_fop_DDD(dc, rd, rs1, rs2, gen_helper_fpsub32);
4305 case 0x057: /* VIS I fpsub32s */
4306 CHECK_FPU_FEATURE(dc, VIS1);
4307 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_sub_i32);
4309 case 0x060: /* VIS I fzero */
4310 CHECK_FPU_FEATURE(dc, VIS1);
4311 cpu_dst_64 = gen_dest_fpr_D(dc, rd);
4312 tcg_gen_movi_i64(cpu_dst_64, 0);
4313 gen_store_fpr_D(dc, rd, cpu_dst_64);
4315 case 0x061: /* VIS I fzeros */
4316 CHECK_FPU_FEATURE(dc, VIS1);
4317 cpu_dst_32 = gen_dest_fpr_F(dc);
4318 tcg_gen_movi_i32(cpu_dst_32, 0);
4319 gen_store_fpr_F(dc, rd, cpu_dst_32);
4321 case 0x062: /* VIS I fnor */
4322 CHECK_FPU_FEATURE(dc, VIS1);
4323 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_nor_i64);
4325 case 0x063: /* VIS I fnors */
4326 CHECK_FPU_FEATURE(dc, VIS1);
4327 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_nor_i32);
4329 case 0x064: /* VIS I fandnot2 */
4330 CHECK_FPU_FEATURE(dc, VIS1);
4331 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_andc_i64);
4333 case 0x065: /* VIS I fandnot2s */
4334 CHECK_FPU_FEATURE(dc, VIS1);
4335 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_andc_i32);
4337 case 0x066: /* VIS I fnot2 */
4338 CHECK_FPU_FEATURE(dc, VIS1);
4339 gen_ne_fop_DD(dc, rd, rs2, tcg_gen_not_i64);
4341 case 0x067: /* VIS I fnot2s */
4342 CHECK_FPU_FEATURE(dc, VIS1);
4343 gen_ne_fop_FF(dc, rd, rs2, tcg_gen_not_i32);
4345 case 0x068: /* VIS I fandnot1 */
4346 CHECK_FPU_FEATURE(dc, VIS1);
4347 gen_ne_fop_DDD(dc, rd, rs2, rs1, tcg_gen_andc_i64);
4349 case 0x069: /* VIS I fandnot1s */
4350 CHECK_FPU_FEATURE(dc, VIS1);
4351 gen_ne_fop_FFF(dc, rd, rs2, rs1, tcg_gen_andc_i32);
4353 case 0x06a: /* VIS I fnot1 */
4354 CHECK_FPU_FEATURE(dc, VIS1);
4355 gen_ne_fop_DD(dc, rd, rs1, tcg_gen_not_i64);
4357 case 0x06b: /* VIS I fnot1s */
4358 CHECK_FPU_FEATURE(dc, VIS1);
4359 gen_ne_fop_FF(dc, rd, rs1, tcg_gen_not_i32);
4361 case 0x06c: /* VIS I fxor */
4362 CHECK_FPU_FEATURE(dc, VIS1);
4363 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_xor_i64);
4365 case 0x06d: /* VIS I fxors */
4366 CHECK_FPU_FEATURE(dc, VIS1);
4367 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_xor_i32);
4369 case 0x06e: /* VIS I fnand */
4370 CHECK_FPU_FEATURE(dc, VIS1);
4371 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_nand_i64);
4373 case 0x06f: /* VIS I fnands */
4374 CHECK_FPU_FEATURE(dc, VIS1);
4375 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_nand_i32);
4377 case 0x070: /* VIS I fand */
4378 CHECK_FPU_FEATURE(dc, VIS1);
4379 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_and_i64);
4381 case 0x071: /* VIS I fands */
4382 CHECK_FPU_FEATURE(dc, VIS1);
4383 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_and_i32);
4385 case 0x072: /* VIS I fxnor */
4386 CHECK_FPU_FEATURE(dc, VIS1);
4387 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_eqv_i64);
4389 case 0x073: /* VIS I fxnors */
4390 CHECK_FPU_FEATURE(dc, VIS1);
4391 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_eqv_i32);
4393 case 0x074: /* VIS I fsrc1 */
4394 CHECK_FPU_FEATURE(dc, VIS1);
4395 cpu_src1_64 = gen_load_fpr_D(dc, rs1);
4396 gen_store_fpr_D(dc, rd, cpu_src1_64);
4398 case 0x075: /* VIS I fsrc1s */
4399 CHECK_FPU_FEATURE(dc, VIS1);
4400 cpu_src1_32 = gen_load_fpr_F(dc, rs1);
4401 gen_store_fpr_F(dc, rd, cpu_src1_32);
4403 case 0x076: /* VIS I fornot2 */
4404 CHECK_FPU_FEATURE(dc, VIS1);
4405 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_orc_i64);
4407 case 0x077: /* VIS I fornot2s */
4408 CHECK_FPU_FEATURE(dc, VIS1);
4409 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_orc_i32);
4411 case 0x078: /* VIS I fsrc2 */
4412 CHECK_FPU_FEATURE(dc, VIS1);
4413 cpu_src1_64 = gen_load_fpr_D(dc, rs2);
4414 gen_store_fpr_D(dc, rd, cpu_src1_64);
4416 case 0x079: /* VIS I fsrc2s */
4417 CHECK_FPU_FEATURE(dc, VIS1);
4418 cpu_src1_32 = gen_load_fpr_F(dc, rs2);
4419 gen_store_fpr_F(dc, rd, cpu_src1_32);
4421 case 0x07a: /* VIS I fornot1 */
4422 CHECK_FPU_FEATURE(dc, VIS1);
4423 gen_ne_fop_DDD(dc, rd, rs2, rs1, tcg_gen_orc_i64);
4425 case 0x07b: /* VIS I fornot1s */
4426 CHECK_FPU_FEATURE(dc, VIS1);
4427 gen_ne_fop_FFF(dc, rd, rs2, rs1, tcg_gen_orc_i32);
4429 case 0x07c: /* VIS I for */
4430 CHECK_FPU_FEATURE(dc, VIS1);
4431 gen_ne_fop_DDD(dc, rd, rs1, rs2, tcg_gen_or_i64);
4433 case 0x07d: /* VIS I fors */
4434 CHECK_FPU_FEATURE(dc, VIS1);
4435 gen_ne_fop_FFF(dc, rd, rs1, rs2, tcg_gen_or_i32);
4437 case 0x07e: /* VIS I fone */
4438 CHECK_FPU_FEATURE(dc, VIS1);
4439 cpu_dst_64 = gen_dest_fpr_D(dc, rd);
4440 tcg_gen_movi_i64(cpu_dst_64, -1);
4441 gen_store_fpr_D(dc, rd, cpu_dst_64);
4443 case 0x07f: /* VIS I fones */
4444 CHECK_FPU_FEATURE(dc, VIS1);
4445 cpu_dst_32 = gen_dest_fpr_F(dc);
4446 tcg_gen_movi_i32(cpu_dst_32, -1);
4447 gen_store_fpr_F(dc, rd, cpu_dst_32);
4449 case 0x080: /* VIS I shutdown */
4450 case 0x081: /* VIS II siam */
4459 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4460 #ifdef TARGET_SPARC64
4465 #ifdef TARGET_SPARC64
4466 } else if (xop == 0x39) { /* V9 return */
4470 cpu_src1 = get_src1(dc, insn);
4471 cpu_tmp0 = get_temp_tl(dc);
4472 if (IS_IMM) { /* immediate */
4473 simm = GET_FIELDs(insn, 19, 31);
4474 tcg_gen_addi_tl(cpu_tmp0, cpu_src1, simm);
4475 } else { /* register */
4476 rs2 = GET_FIELD(insn, 27, 31);
4478 cpu_src2 = gen_load_gpr(dc, rs2);
4479 tcg_gen_add_tl(cpu_tmp0, cpu_src1, cpu_src2);
4481 tcg_gen_mov_tl(cpu_tmp0, cpu_src1);
4484 gen_helper_restore(cpu_env);
4486 r_const = tcg_const_i32(3);
4487 gen_helper_check_align(cpu_env, cpu_tmp0, r_const);
4488 tcg_temp_free_i32(r_const);
4489 tcg_gen_mov_tl(cpu_npc, cpu_tmp0);
4490 dc->npc = DYNAMIC_PC;
4494 cpu_src1 = get_src1(dc, insn);
4495 cpu_tmp0 = get_temp_tl(dc);
4496 if (IS_IMM) { /* immediate */
4497 simm = GET_FIELDs(insn, 19, 31);
4498 tcg_gen_addi_tl(cpu_tmp0, cpu_src1, simm);
4499 } else { /* register */
4500 rs2 = GET_FIELD(insn, 27, 31);
4502 cpu_src2 = gen_load_gpr(dc, rs2);
4503 tcg_gen_add_tl(cpu_tmp0, cpu_src1, cpu_src2);
4505 tcg_gen_mov_tl(cpu_tmp0, cpu_src1);
4509 case 0x38: /* jmpl */
4514 t = gen_dest_gpr(dc, rd);
4515 tcg_gen_movi_tl(t, dc->pc);
4516 gen_store_gpr(dc, rd, t);
4518 r_const = tcg_const_i32(3);
4519 gen_helper_check_align(cpu_env, cpu_tmp0, r_const);
4520 tcg_temp_free_i32(r_const);
4521 gen_address_mask(dc, cpu_tmp0);
4522 tcg_gen_mov_tl(cpu_npc, cpu_tmp0);
4523 dc->npc = DYNAMIC_PC;
4526 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4527 case 0x39: /* rett, V9 return */
4531 if (!supervisor(dc))
4534 r_const = tcg_const_i32(3);
4535 gen_helper_check_align(cpu_env, cpu_tmp0, r_const);
4536 tcg_temp_free_i32(r_const);
4537 tcg_gen_mov_tl(cpu_npc, cpu_tmp0);
4538 dc->npc = DYNAMIC_PC;
4539 gen_helper_rett(cpu_env);
4543 case 0x3b: /* flush */
4544 if (!((dc)->def->features & CPU_FEATURE_FLUSH))
4548 case 0x3c: /* save */
4550 gen_helper_save(cpu_env);
4551 gen_store_gpr(dc, rd, cpu_tmp0);
4553 case 0x3d: /* restore */
4555 gen_helper_restore(cpu_env);
4556 gen_store_gpr(dc, rd, cpu_tmp0);
4558 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4559 case 0x3e: /* V9 done/retry */
4563 if (!supervisor(dc))
4565 dc->npc = DYNAMIC_PC;
4566 dc->pc = DYNAMIC_PC;
4567 gen_helper_done(cpu_env);
4570 if (!supervisor(dc))
4572 dc->npc = DYNAMIC_PC;
4573 dc->pc = DYNAMIC_PC;
4574 gen_helper_retry(cpu_env);
4589 case 3: /* load/store instructions */
4591 unsigned int xop = GET_FIELD(insn, 7, 12);
4592 /* ??? gen_address_mask prevents us from using a source
4593 register directly. Always generate a temporary. */
4594 TCGv cpu_addr = get_temp_tl(dc);
4596 tcg_gen_mov_tl(cpu_addr, get_src1(dc, insn));
4597 if (xop == 0x3c || xop == 0x3e) {
4598 /* V9 casa/casxa : no offset */
4599 } else if (IS_IMM) { /* immediate */
4600 simm = GET_FIELDs(insn, 19, 31);
4602 tcg_gen_addi_tl(cpu_addr, cpu_addr, simm);
4604 } else { /* register */
4605 rs2 = GET_FIELD(insn, 27, 31);
4607 tcg_gen_add_tl(cpu_addr, cpu_addr, gen_load_gpr(dc, rs2));
4610 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4611 (xop > 0x17 && xop <= 0x1d ) ||
4612 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4613 TCGv cpu_val = gen_dest_gpr(dc, rd);
4616 case 0x0: /* ld, V9 lduw, load unsigned word */
4617 gen_address_mask(dc, cpu_addr);
4618 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4620 case 0x1: /* ldub, load unsigned byte */
4621 gen_address_mask(dc, cpu_addr);
4622 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4624 case 0x2: /* lduh, load unsigned halfword */
4625 gen_address_mask(dc, cpu_addr);
4626 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4628 case 0x3: /* ldd, load double word */
4636 r_const = tcg_const_i32(7);
4637 /* XXX remove alignment check */
4638 gen_helper_check_align(cpu_env, cpu_addr, r_const);
4639 tcg_temp_free_i32(r_const);
4640 gen_address_mask(dc, cpu_addr);
4641 t64 = tcg_temp_new_i64();
4642 tcg_gen_qemu_ld64(t64, cpu_addr, dc->mem_idx);
4643 tcg_gen_trunc_i64_tl(cpu_val, t64);
4644 tcg_gen_ext32u_tl(cpu_val, cpu_val);
4645 gen_store_gpr(dc, rd + 1, cpu_val);
4646 tcg_gen_shri_i64(t64, t64, 32);
4647 tcg_gen_trunc_i64_tl(cpu_val, t64);
4648 tcg_temp_free_i64(t64);
4649 tcg_gen_ext32u_tl(cpu_val, cpu_val);
4652 case 0x9: /* ldsb, load signed byte */
4653 gen_address_mask(dc, cpu_addr);
4654 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4656 case 0xa: /* ldsh, load signed halfword */
4657 gen_address_mask(dc, cpu_addr);
4658 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4660 case 0xd: /* ldstub -- XXX: should be atomically */
4664 gen_address_mask(dc, cpu_addr);
4665 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4666 r_const = tcg_const_tl(0xff);
4667 tcg_gen_qemu_st8(r_const, cpu_addr, dc->mem_idx);
4668 tcg_temp_free(r_const);
4672 /* swap, swap register with memory. Also atomically */
4674 TCGv t0 = get_temp_tl(dc);
4675 CHECK_IU_FEATURE(dc, SWAP);
4676 cpu_src1 = gen_load_gpr(dc, rd);
4677 gen_address_mask(dc, cpu_addr);
4678 tcg_gen_qemu_ld32u(t0, cpu_addr, dc->mem_idx);
4679 tcg_gen_qemu_st32(cpu_src1, cpu_addr, dc->mem_idx);
4680 tcg_gen_mov_tl(cpu_val, t0);
4683 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4684 case 0x10: /* lda, V9 lduwa, load word alternate */
4685 #ifndef TARGET_SPARC64
4688 if (!supervisor(dc))
4692 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4694 case 0x11: /* lduba, load unsigned byte alternate */
4695 #ifndef TARGET_SPARC64
4698 if (!supervisor(dc))
4702 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4704 case 0x12: /* lduha, load unsigned halfword alternate */
4705 #ifndef TARGET_SPARC64
4708 if (!supervisor(dc))
4712 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4714 case 0x13: /* ldda, load double word alternate */
4715 #ifndef TARGET_SPARC64
4718 if (!supervisor(dc))
4724 gen_ldda_asi(dc, cpu_val, cpu_addr, insn, rd);
4726 case 0x19: /* ldsba, load signed byte alternate */
4727 #ifndef TARGET_SPARC64
4730 if (!supervisor(dc))
4734 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4736 case 0x1a: /* ldsha, load signed halfword alternate */
4737 #ifndef TARGET_SPARC64
4740 if (!supervisor(dc))
4744 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4746 case 0x1d: /* ldstuba -- XXX: should be atomically */
4747 #ifndef TARGET_SPARC64
4750 if (!supervisor(dc))
4754 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4756 case 0x1f: /* swapa, swap reg with alt. memory. Also
4758 CHECK_IU_FEATURE(dc, SWAP);
4759 #ifndef TARGET_SPARC64
4762 if (!supervisor(dc))
4766 cpu_src1 = gen_load_gpr(dc, rd);
4767 gen_swap_asi(cpu_val, cpu_src1, cpu_addr, insn);
4770 #ifndef TARGET_SPARC64
4771 case 0x30: /* ldc */
4772 case 0x31: /* ldcsr */
4773 case 0x33: /* lddc */
4777 #ifdef TARGET_SPARC64
4778 case 0x08: /* V9 ldsw */
4779 gen_address_mask(dc, cpu_addr);
4780 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4782 case 0x0b: /* V9 ldx */
4783 gen_address_mask(dc, cpu_addr);
4784 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4786 case 0x18: /* V9 ldswa */
4788 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4790 case 0x1b: /* V9 ldxa */
4792 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4794 case 0x2d: /* V9 prefetch, no effect */
4796 case 0x30: /* V9 ldfa */
4797 if (gen_trap_ifnofpu(dc)) {
4801 gen_ldf_asi(cpu_addr, insn, 4, rd);
4802 gen_update_fprs_dirty(rd);
4804 case 0x33: /* V9 lddfa */
4805 if (gen_trap_ifnofpu(dc)) {
4809 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4810 gen_update_fprs_dirty(DFPREG(rd));
4812 case 0x3d: /* V9 prefetcha, no effect */
4814 case 0x32: /* V9 ldqfa */
4815 CHECK_FPU_FEATURE(dc, FLOAT128);
4816 if (gen_trap_ifnofpu(dc)) {
4820 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4821 gen_update_fprs_dirty(QFPREG(rd));
4827 gen_store_gpr(dc, rd, cpu_val);
4828 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4831 } else if (xop >= 0x20 && xop < 0x24) {
4834 if (gen_trap_ifnofpu(dc)) {
4839 case 0x20: /* ldf, load fpreg */
4840 gen_address_mask(dc, cpu_addr);
4841 t0 = get_temp_tl(dc);
4842 tcg_gen_qemu_ld32u(t0, cpu_addr, dc->mem_idx);
4843 cpu_dst_32 = gen_dest_fpr_F(dc);
4844 tcg_gen_trunc_tl_i32(cpu_dst_32, t0);
4845 gen_store_fpr_F(dc, rd, cpu_dst_32);
4847 case 0x21: /* ldfsr, V9 ldxfsr */
4848 #ifdef TARGET_SPARC64
4849 gen_address_mask(dc, cpu_addr);
4851 TCGv_i64 t64 = tcg_temp_new_i64();
4852 tcg_gen_qemu_ld64(t64, cpu_addr, dc->mem_idx);
4853 gen_helper_ldxfsr(cpu_env, t64);
4854 tcg_temp_free_i64(t64);
4858 cpu_dst_32 = get_temp_i32(dc);
4859 t0 = get_temp_tl(dc);
4860 tcg_gen_qemu_ld32u(t0, cpu_addr, dc->mem_idx);
4861 tcg_gen_trunc_tl_i32(cpu_dst_32, t0);
4862 gen_helper_ldfsr(cpu_env, cpu_dst_32);
4864 case 0x22: /* ldqf, load quad fpreg */
4868 CHECK_FPU_FEATURE(dc, FLOAT128);
4869 r_const = tcg_const_i32(dc->mem_idx);
4870 gen_address_mask(dc, cpu_addr);
4871 gen_helper_ldqf(cpu_env, cpu_addr, r_const);
4872 tcg_temp_free_i32(r_const);
4873 gen_op_store_QT0_fpr(QFPREG(rd));
4874 gen_update_fprs_dirty(QFPREG(rd));
4877 case 0x23: /* lddf, load double fpreg */
4878 gen_address_mask(dc, cpu_addr);
4879 cpu_dst_64 = gen_dest_fpr_D(dc, rd);
4880 tcg_gen_qemu_ld64(cpu_dst_64, cpu_addr, dc->mem_idx);
4881 gen_store_fpr_D(dc, rd, cpu_dst_64);
4886 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) ||
4887 xop == 0xe || xop == 0x1e) {
4888 TCGv cpu_val = gen_load_gpr(dc, rd);
4891 case 0x4: /* st, store word */
4892 gen_address_mask(dc, cpu_addr);
4893 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4895 case 0x5: /* stb, store byte */
4896 gen_address_mask(dc, cpu_addr);
4897 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4899 case 0x6: /* sth, store halfword */
4900 gen_address_mask(dc, cpu_addr);
4901 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4903 case 0x7: /* std, store double word */
4912 gen_address_mask(dc, cpu_addr);
4913 r_const = tcg_const_i32(7);
4914 /* XXX remove alignment check */
4915 gen_helper_check_align(cpu_env, cpu_addr, r_const);
4916 tcg_temp_free_i32(r_const);
4917 lo = gen_load_gpr(dc, rd + 1);
4919 t64 = tcg_temp_new_i64();
4920 tcg_gen_concat_tl_i64(t64, lo, cpu_val);
4921 tcg_gen_qemu_st64(t64, cpu_addr, dc->mem_idx);
4922 tcg_temp_free_i64(t64);
4925 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4926 case 0x14: /* sta, V9 stwa, store word alternate */
4927 #ifndef TARGET_SPARC64
4930 if (!supervisor(dc))
4934 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4935 dc->npc = DYNAMIC_PC;
4937 case 0x15: /* stba, store byte alternate */
4938 #ifndef TARGET_SPARC64
4941 if (!supervisor(dc))
4945 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4946 dc->npc = DYNAMIC_PC;
4948 case 0x16: /* stha, store halfword alternate */
4949 #ifndef TARGET_SPARC64
4952 if (!supervisor(dc))
4956 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4957 dc->npc = DYNAMIC_PC;
4959 case 0x17: /* stda, store double word alternate */
4960 #ifndef TARGET_SPARC64
4963 if (!supervisor(dc))
4970 gen_stda_asi(dc, cpu_val, cpu_addr, insn, rd);
4974 #ifdef TARGET_SPARC64
4975 case 0x0e: /* V9 stx */
4976 gen_address_mask(dc, cpu_addr);
4977 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4979 case 0x1e: /* V9 stxa */
4981 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4982 dc->npc = DYNAMIC_PC;
4988 } else if (xop > 0x23 && xop < 0x28) {
4989 if (gen_trap_ifnofpu(dc)) {
4994 case 0x24: /* stf, store fpreg */
4996 TCGv t = get_temp_tl(dc);
4997 gen_address_mask(dc, cpu_addr);
4998 cpu_src1_32 = gen_load_fpr_F(dc, rd);
4999 tcg_gen_ext_i32_tl(t, cpu_src1_32);
5000 tcg_gen_qemu_st32(t, cpu_addr, dc->mem_idx);
5003 case 0x25: /* stfsr, V9 stxfsr */
5005 TCGv t = get_temp_tl(dc);
5007 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUSPARCState, fsr));
5008 #ifdef TARGET_SPARC64
5009 gen_address_mask(dc, cpu_addr);
5011 tcg_gen_qemu_st64(t, cpu_addr, dc->mem_idx);
5015 tcg_gen_qemu_st32(t, cpu_addr, dc->mem_idx);
5019 #ifdef TARGET_SPARC64
5020 /* V9 stqf, store quad fpreg */
5024 CHECK_FPU_FEATURE(dc, FLOAT128);
5025 gen_op_load_fpr_QT0(QFPREG(rd));
5026 r_const = tcg_const_i32(dc->mem_idx);
5027 gen_address_mask(dc, cpu_addr);
5028 gen_helper_stqf(cpu_env, cpu_addr, r_const);
5029 tcg_temp_free_i32(r_const);
5032 #else /* !TARGET_SPARC64 */
5033 /* stdfq, store floating point queue */
5034 #if defined(CONFIG_USER_ONLY)
5037 if (!supervisor(dc))
5039 if (gen_trap_ifnofpu(dc)) {
5045 case 0x27: /* stdf, store double fpreg */
5046 gen_address_mask(dc, cpu_addr);
5047 cpu_src1_64 = gen_load_fpr_D(dc, rd);
5048 tcg_gen_qemu_st64(cpu_src1_64, cpu_addr, dc->mem_idx);
5053 } else if (xop > 0x33 && xop < 0x3f) {
5056 #ifdef TARGET_SPARC64
5057 case 0x34: /* V9 stfa */
5058 if (gen_trap_ifnofpu(dc)) {
5061 gen_stf_asi(cpu_addr, insn, 4, rd);
5063 case 0x36: /* V9 stqfa */
5067 CHECK_FPU_FEATURE(dc, FLOAT128);
5068 if (gen_trap_ifnofpu(dc)) {
5071 r_const = tcg_const_i32(7);
5072 gen_helper_check_align(cpu_env, cpu_addr, r_const);
5073 tcg_temp_free_i32(r_const);
5074 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
5077 case 0x37: /* V9 stdfa */
5078 if (gen_trap_ifnofpu(dc)) {
5081 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
5083 case 0x3e: /* V9 casxa */
5084 rs2 = GET_FIELD(insn, 27, 31);
5085 cpu_src2 = gen_load_gpr(dc, rs2);
5086 gen_casx_asi(dc, cpu_addr, cpu_src2, insn, rd);
5089 case 0x34: /* stc */
5090 case 0x35: /* stcsr */
5091 case 0x36: /* stdcq */
5092 case 0x37: /* stdc */
5095 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
5096 case 0x3c: /* V9 or LEON3 casa */
5097 #ifndef TARGET_SPARC64
5098 CHECK_IU_FEATURE(dc, CASA);
5102 if (!supervisor(dc)) {
5106 rs2 = GET_FIELD(insn, 27, 31);
5107 cpu_src2 = gen_load_gpr(dc, rs2);
5108 gen_cas_asi(dc, cpu_addr, cpu_src2, insn, rd);
5120 /* default case for non jump instructions */
5121 if (dc->npc == DYNAMIC_PC) {
5122 dc->pc = DYNAMIC_PC;
5124 } else if (dc->npc == JUMP_PC) {
5125 /* we can do a static jump */
5126 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
5130 dc->npc = dc->npc + 4;
5139 r_const = tcg_const_i32(TT_ILL_INSN);
5140 gen_helper_raise_exception(cpu_env, r_const);
5141 tcg_temp_free_i32(r_const);
5150 r_const = tcg_const_i32(TT_UNIMP_FLUSH);
5151 gen_helper_raise_exception(cpu_env, r_const);
5152 tcg_temp_free_i32(r_const);
5156 #if !defined(CONFIG_USER_ONLY)
5162 r_const = tcg_const_i32(TT_PRIV_INSN);
5163 gen_helper_raise_exception(cpu_env, r_const);
5164 tcg_temp_free_i32(r_const);
5171 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
5174 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
5177 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
5181 #ifndef TARGET_SPARC64
5187 r_const = tcg_const_i32(TT_NCP_INSN);
5188 gen_helper_raise_exception(cpu_env, r_const);
5189 tcg_temp_free(r_const);
5195 if (dc->n_t32 != 0) {
5197 for (i = dc->n_t32 - 1; i >= 0; --i) {
5198 tcg_temp_free_i32(dc->t32[i]);
5202 if (dc->n_ttl != 0) {
5204 for (i = dc->n_ttl - 1; i >= 0; --i) {
5205 tcg_temp_free(dc->ttl[i]);
5211 static inline void gen_intermediate_code_internal(SPARCCPU *cpu,
5212 TranslationBlock *tb,
5215 CPUState *cs = CPU(cpu);
5216 CPUSPARCState *env = &cpu->env;
5217 target_ulong pc_start, last_pc;
5218 DisasContext dc1, *dc = &dc1;
5224 memset(dc, 0, sizeof(DisasContext));
5229 dc->npc = (target_ulong) tb->cs_base;
5230 dc->cc_op = CC_OP_DYNAMIC;
5231 dc->mem_idx = cpu_mmu_index(env, false);
5233 dc->fpu_enabled = tb_fpu_enabled(tb->flags);
5234 dc->address_mask_32bit = tb_am_enabled(tb->flags);
5235 dc->singlestep = (cs->singlestep_enabled || singlestep);
5238 max_insns = tb->cflags & CF_COUNT_MASK;
5239 if (max_insns == 0) {
5240 max_insns = CF_COUNT_MASK;
5242 if (max_insns > TCG_MAX_INSNS) {
5243 max_insns = TCG_MAX_INSNS;
5249 qemu_log("Search PC...\n");
5250 j = tcg_op_buf_count();
5254 tcg_ctx.gen_opc_instr_start[lj++] = 0;
5255 tcg_ctx.gen_opc_pc[lj] = dc->pc;
5256 gen_opc_npc[lj] = dc->npc;
5257 if (dc->npc & JUMP_PC) {
5258 assert(dc->jump_pc[1] == dc->pc + 4);
5259 gen_opc_npc[lj] = dc->jump_pc[0] | JUMP_PC;
5261 tcg_ctx.gen_opc_instr_start[lj] = 1;
5262 tcg_ctx.gen_opc_icount[lj] = num_insns;
5265 if (dc->npc & JUMP_PC) {
5266 assert(dc->jump_pc[1] == dc->pc + 4);
5267 tcg_gen_insn_start(dc->pc, dc->jump_pc[0] | JUMP_PC);
5269 tcg_gen_insn_start(dc->pc, dc->npc);
5273 if (unlikely(cpu_breakpoint_test(cs, dc->pc, BP_ANY))) {
5274 if (dc->pc != pc_start) {
5277 gen_helper_debug(cpu_env);
5283 if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {
5288 insn = cpu_ldl_code(env, dc->pc);
5290 disas_sparc_insn(dc, insn);
5294 /* if the next PC is different, we abort now */
5295 if (dc->pc != (last_pc + 4))
5297 /* if we reach a page boundary, we stop generation so that the
5298 PC of a TT_TFAULT exception is always in the right page */
5299 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
5301 /* if single step mode, we generate only one instruction and
5302 generate an exception */
5303 if (dc->singlestep) {
5306 } while (!tcg_op_buf_full() &&
5307 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
5308 num_insns < max_insns);
5311 if (tb->cflags & CF_LAST_IO) {
5315 if (dc->pc != DYNAMIC_PC &&
5316 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
5317 /* static PC and NPC: we can use direct chaining */
5318 gen_goto_tb(dc, 0, dc->pc, dc->npc);
5320 if (dc->pc != DYNAMIC_PC) {
5321 tcg_gen_movi_tl(cpu_pc, dc->pc);
5327 gen_tb_end(tb, num_insns);
5330 j = tcg_op_buf_count();
5333 tcg_ctx.gen_opc_instr_start[lj++] = 0;
5338 tb->size = last_pc + 4 - pc_start;
5339 tb->icount = num_insns;
5342 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
5343 qemu_log("--------------\n");
5344 qemu_log("IN: %s\n", lookup_symbol(pc_start));
5345 log_target_disas(cs, pc_start, last_pc + 4 - pc_start, 0);
5351 void gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
5353 gen_intermediate_code_internal(sparc_env_get_cpu(env), tb, false);
5356 void gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
5358 gen_intermediate_code_internal(sparc_env_get_cpu(env), tb, true);
5361 void gen_intermediate_code_init(CPUSPARCState *env)
5365 static const char * const gregnames[8] = {
5366 NULL, // g0 not used
5375 static const char * const fregnames[32] = {
5376 "f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14",
5377 "f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30",
5378 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
5379 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
5382 /* init various static tables */
5386 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
5387 cpu_regwptr = tcg_global_mem_new_ptr(TCG_AREG0,
5388 offsetof(CPUSPARCState, regwptr),
5390 #ifdef TARGET_SPARC64
5391 cpu_xcc = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUSPARCState, xcc),
5393 cpu_asi = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUSPARCState, asi),
5395 cpu_fprs = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUSPARCState, fprs),
5397 cpu_gsr = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, gsr),
5399 cpu_tick_cmpr = tcg_global_mem_new(TCG_AREG0,
5400 offsetof(CPUSPARCState, tick_cmpr),
5402 cpu_stick_cmpr = tcg_global_mem_new(TCG_AREG0,
5403 offsetof(CPUSPARCState, stick_cmpr),
5405 cpu_hstick_cmpr = tcg_global_mem_new(TCG_AREG0,
5406 offsetof(CPUSPARCState, hstick_cmpr),
5408 cpu_hintp = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, hintp),
5410 cpu_htba = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, htba),
5412 cpu_hver = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, hver),
5414 cpu_ssr = tcg_global_mem_new(TCG_AREG0,
5415 offsetof(CPUSPARCState, ssr), "ssr");
5416 cpu_ver = tcg_global_mem_new(TCG_AREG0,
5417 offsetof(CPUSPARCState, version), "ver");
5418 cpu_softint = tcg_global_mem_new_i32(TCG_AREG0,
5419 offsetof(CPUSPARCState, softint),
5422 cpu_wim = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, wim),
5425 cpu_cond = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, cond),
5427 cpu_cc_src = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, cc_src),
5429 cpu_cc_src2 = tcg_global_mem_new(TCG_AREG0,
5430 offsetof(CPUSPARCState, cc_src2),
5432 cpu_cc_dst = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, cc_dst),
5434 cpu_cc_op = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUSPARCState, cc_op),
5436 cpu_psr = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUSPARCState, psr),
5438 cpu_fsr = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, fsr),
5440 cpu_pc = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, pc),
5442 cpu_npc = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, npc),
5444 cpu_y = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, y), "y");
5445 #ifndef CONFIG_USER_ONLY
5446 cpu_tbr = tcg_global_mem_new(TCG_AREG0, offsetof(CPUSPARCState, tbr),
5449 for (i = 1; i < 8; i++) {
5450 cpu_gregs[i] = tcg_global_mem_new(TCG_AREG0,
5451 offsetof(CPUSPARCState, gregs[i]),
5454 for (i = 0; i < TARGET_DPREGS; i++) {
5455 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
5456 offsetof(CPUSPARCState, fpr[i]),
5462 void restore_state_to_opc(CPUSPARCState *env, TranslationBlock *tb,
5465 target_ulong pc = data[0];
5466 target_ulong npc = data[1];
5469 if (npc == DYNAMIC_PC) {
5470 /* dynamic NPC: already stored */
5471 } else if (npc & JUMP_PC) {
5472 /* jump PC: use 'cond' and the jump targets of the translation */
5474 env->npc = npc & ~3;