5 Copyright (C) 2003-2005 Fabrice Bellard
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 Rest of V9 instructions, VIS instructions
26 NPC/PC static optimisations (use JUMP_TB when possible)
27 Optimize synthetic instructions
44 #define DYNAMIC_PC 1 /* dynamic pc value */
45 #define JUMP_PC 2 /* dynamic pc value which takes only two values
46 according to jump_pc[T2] */
48 /* global register indexes */
49 static TCGv cpu_env, cpu_T[3], cpu_regwptr, cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
50 static TCGv cpu_psr, cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8];
54 /* local register indexes (only used inside old micro ops) */
57 typedef struct DisasContext {
58 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
59 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
60 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
64 struct TranslationBlock *tb;
67 typedef struct sparc_def_t sparc_def_t;
70 const unsigned char *name;
71 target_ulong iu_version;
75 uint32_t mmu_ctpr_mask;
76 uint32_t mmu_cxr_mask;
77 uint32_t mmu_sfsr_mask;
78 uint32_t mmu_trcr_mask;
81 static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name);
86 // This function uses non-native bit order
87 #define GET_FIELD(X, FROM, TO) \
88 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
90 // This function uses the order in the manuals, i.e. bit 0 is 2^0
91 #define GET_FIELD_SP(X, FROM, TO) \
92 GET_FIELD(X, 31 - (TO), 31 - (FROM))
94 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
95 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
99 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
100 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
102 #define FFPREG(r) (r)
103 #define DFPREG(r) (r & 0x1e)
104 #define QFPREG(r) (r & 0x1c)
107 static int sign_extend(int x, int len)
110 return (x << len) >> len;
113 #define IS_IMM (insn & (1<<13))
115 static void disas_sparc_insn(DisasContext * dc);
117 #ifdef TARGET_SPARC64
118 #define GEN32(func, NAME) \
119 static GenOpFunc * const NAME ## _table [64] = { \
120 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
121 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
122 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
123 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
124 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
125 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
126 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
127 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
128 NAME ## 32, 0, NAME ## 34, 0, NAME ## 36, 0, NAME ## 38, 0, \
129 NAME ## 40, 0, NAME ## 42, 0, NAME ## 44, 0, NAME ## 46, 0, \
130 NAME ## 48, 0, NAME ## 50, 0, NAME ## 52, 0, NAME ## 54, 0, \
131 NAME ## 56, 0, NAME ## 58, 0, NAME ## 60, 0, NAME ## 62, 0, \
133 static inline void func(int n) \
135 NAME ## _table[n](); \
138 #define GEN32(func, NAME) \
139 static GenOpFunc *const NAME ## _table [32] = { \
140 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
141 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
142 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
143 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
144 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
145 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
146 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
147 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
149 static inline void func(int n) \
151 NAME ## _table[n](); \
155 /* floating point registers moves */
156 GEN32(gen_op_load_fpr_FT0, gen_op_load_fpr_FT0_fprf);
157 GEN32(gen_op_load_fpr_FT1, gen_op_load_fpr_FT1_fprf);
158 GEN32(gen_op_store_FT0_fpr, gen_op_store_FT0_fpr_fprf);
159 GEN32(gen_op_store_FT1_fpr, gen_op_store_FT1_fpr_fprf);
161 GEN32(gen_op_load_fpr_DT0, gen_op_load_fpr_DT0_fprf);
162 GEN32(gen_op_load_fpr_DT1, gen_op_load_fpr_DT1_fprf);
163 GEN32(gen_op_store_DT0_fpr, gen_op_store_DT0_fpr_fprf);
164 GEN32(gen_op_store_DT1_fpr, gen_op_store_DT1_fpr_fprf);
166 #if defined(CONFIG_USER_ONLY)
167 GEN32(gen_op_load_fpr_QT0, gen_op_load_fpr_QT0_fprf);
168 GEN32(gen_op_load_fpr_QT1, gen_op_load_fpr_QT1_fprf);
169 GEN32(gen_op_store_QT0_fpr, gen_op_store_QT0_fpr_fprf);
170 GEN32(gen_op_store_QT1_fpr, gen_op_store_QT1_fpr_fprf);
174 #ifdef CONFIG_USER_ONLY
175 #define supervisor(dc) 0
176 #ifdef TARGET_SPARC64
177 #define hypervisor(dc) 0
179 #define gen_op_ldst(name) gen_op_##name##_raw()
181 #define supervisor(dc) (dc->mem_idx >= 1)
182 #ifdef TARGET_SPARC64
183 #define hypervisor(dc) (dc->mem_idx == 2)
184 #define OP_LD_TABLE(width) \
185 static GenOpFunc * const gen_op_##width[] = { \
186 &gen_op_##width##_user, \
187 &gen_op_##width##_kernel, \
188 &gen_op_##width##_hypv, \
191 #define OP_LD_TABLE(width) \
192 static GenOpFunc * const gen_op_##width[] = { \
193 &gen_op_##width##_user, \
194 &gen_op_##width##_kernel, \
197 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
200 #ifndef CONFIG_USER_ONLY
203 #endif /* __i386__ */
211 #define ABI32_MASK(addr) tcg_gen_andi_i64(addr, addr, 0xffffffffULL);
213 #define ABI32_MASK(addr)
216 static inline void gen_movl_simm_T1(int32_t val)
218 tcg_gen_movi_tl(cpu_T[1], val);
221 static inline void gen_movl_reg_TN(int reg, TCGv tn)
224 tcg_gen_movi_tl(tn, 0);
226 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
228 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
232 static inline void gen_movl_reg_T0(int reg)
234 gen_movl_reg_TN(reg, cpu_T[0]);
237 static inline void gen_movl_reg_T1(int reg)
239 gen_movl_reg_TN(reg, cpu_T[1]);
243 static inline void gen_movl_reg_T2(int reg)
245 gen_movl_reg_TN(reg, cpu_T[2]);
248 #endif /* __i386__ */
249 static inline void gen_movl_TN_reg(int reg, TCGv tn)
254 tcg_gen_mov_tl(cpu_gregs[reg], tn);
256 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
260 static inline void gen_movl_T0_reg(int reg)
262 gen_movl_TN_reg(reg, cpu_T[0]);
265 static inline void gen_movl_T1_reg(int reg)
267 gen_movl_TN_reg(reg, cpu_T[1]);
270 static inline void gen_op_movl_T0_env(size_t offset)
272 tcg_gen_ld_i32(cpu_T[0], cpu_env, offset);
275 static inline void gen_op_movl_env_T0(size_t offset)
277 tcg_gen_st_i32(cpu_T[0], cpu_env, offset);
280 static inline void gen_op_movtl_T0_env(size_t offset)
282 tcg_gen_ld_tl(cpu_T[0], cpu_env, offset);
285 static inline void gen_op_movtl_env_T0(size_t offset)
287 tcg_gen_st_tl(cpu_T[0], cpu_env, offset);
290 static inline void gen_op_add_T1_T0(void)
292 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
295 static inline void gen_op_or_T1_T0(void)
297 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
300 static inline void gen_op_xor_T1_T0(void)
302 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
305 static inline void gen_jmp_im(target_ulong pc)
307 tcg_gen_movi_tl(cpu_pc, pc);
310 static inline void gen_movl_npc_im(target_ulong npc)
312 tcg_gen_movi_tl(cpu_npc, npc);
315 static inline void gen_goto_tb(DisasContext *s, int tb_num,
316 target_ulong pc, target_ulong npc)
318 TranslationBlock *tb;
321 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
322 (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);
326 gen_movl_npc_im(npc);
327 tcg_gen_exit_tb((long)tb + tb_num);
329 /* jump to another page: currently not optimized */
331 gen_movl_npc_im(npc);
337 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
339 tcg_gen_shri_i32(reg, src, 23);
340 tcg_gen_andi_tl(reg, reg, 0x1);
343 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
345 tcg_gen_shri_i32(reg, src, 22);
346 tcg_gen_andi_tl(reg, reg, 0x1);
349 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
351 tcg_gen_shri_i32(reg, src, 21);
352 tcg_gen_andi_tl(reg, reg, 0x1);
355 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
357 tcg_gen_shri_i32(reg, src, 20);
358 tcg_gen_andi_tl(reg, reg, 0x1);
361 static inline void gen_op_exception(int exception)
363 tcg_gen_movi_i32(cpu_tmp0, exception);
364 tcg_gen_helper_0_1(raise_exception, cpu_tmp0);
367 static inline void gen_cc_clear(void)
369 tcg_gen_movi_i32(cpu_psr, 0);
370 #ifdef TARGET_SPARC64
371 tcg_gen_movi_i32(cpu_xcc, 0);
377 env->psr |= PSR_ZERO;
378 if ((int32_t) T0 < 0)
381 static inline void gen_cc_NZ(TCGv dst)
385 l1 = gen_new_label();
386 l2 = gen_new_label();
387 tcg_gen_brcond_i32(TCG_COND_NE, dst, tcg_const_i32(0), l1);
388 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
390 tcg_gen_brcond_i32(TCG_COND_GE, dst, tcg_const_i32(0), l2);
391 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
393 #ifdef TARGET_SPARC64
397 l3 = gen_new_label();
398 l4 = gen_new_label();
399 tcg_gen_brcond_tl(TCG_COND_NE, dst, tcg_const_tl(0), l3);
400 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
402 tcg_gen_brcond_tl(TCG_COND_GE, dst, tcg_const_tl(0), l4);
403 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
411 env->psr |= PSR_CARRY;
413 static inline void gen_cc_C_add(TCGv dst, TCGv src1)
417 l1 = gen_new_label();
418 tcg_gen_brcond_i32(TCG_COND_GEU, dst, src1, l1);
419 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
421 #ifdef TARGET_SPARC64
425 l2 = gen_new_label();
426 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l2);
427 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
434 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
437 static inline void gen_cc_V_add(TCGv dst, TCGv src1, TCGv src2)
442 l1 = gen_new_label();
444 r_temp = tcg_temp_new(TCG_TYPE_TL);
445 tcg_gen_xor_tl(r_temp, src1, src2);
446 tcg_gen_xori_tl(r_temp, r_temp, -1);
447 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
448 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
449 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
450 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp, tcg_const_i32(0), l1);
451 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
453 #ifdef TARGET_SPARC64
457 l2 = gen_new_label();
458 tcg_gen_xor_tl(r_temp, src1, src2);
459 tcg_gen_xori_tl(r_temp, r_temp, -1);
460 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
461 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
462 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
463 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
464 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF);
468 tcg_gen_discard_tl(r_temp);
471 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
476 l1 = gen_new_label();
478 r_temp = tcg_temp_new(TCG_TYPE_TL);
479 tcg_gen_xor_tl(r_temp, src1, src2);
480 tcg_gen_xori_tl(r_temp, r_temp, -1);
481 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
482 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
483 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
484 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp, tcg_const_i32(0), l1);
485 gen_op_exception(TT_TOVF);
487 #ifdef TARGET_SPARC64
491 l2 = gen_new_label();
492 tcg_gen_xor_tl(r_temp, src1, src2);
493 tcg_gen_xori_tl(r_temp, r_temp, -1);
494 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
495 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
496 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
497 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
498 gen_op_exception(TT_TOVF);
502 tcg_gen_discard_tl(r_temp);
505 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
509 l1 = gen_new_label();
510 tcg_gen_or_tl(cpu_tmp0, src1, src2);
511 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
512 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
513 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
517 static inline void gen_tag_tv(TCGv src1, TCGv src2)
521 l1 = gen_new_label();
522 tcg_gen_or_tl(cpu_tmp0, src1, src2);
523 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
524 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
525 gen_op_exception(TT_TOVF);
529 static inline void gen_op_add_T1_T0_cc(void)
531 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
532 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
535 gen_cc_C_add(cpu_T[0], cpu_cc_src);
536 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]);
539 static inline void gen_op_addx_T1_T0_cc(void)
541 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
542 gen_mov_reg_C(cpu_tmp0, cpu_psr);
543 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_tmp0);
545 gen_cc_C_add(cpu_T[0], cpu_cc_src);
546 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
547 gen_cc_C_add(cpu_T[0], cpu_cc_src);
549 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]);
552 static inline void gen_op_tadd_T1_T0_cc(void)
554 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
555 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
558 gen_cc_C_add(cpu_T[0], cpu_cc_src);
559 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]);
560 gen_cc_V_tag(cpu_cc_src, cpu_T[1]);
563 static inline void gen_op_tadd_T1_T0_ccTV(void)
565 gen_tag_tv(cpu_T[0], cpu_T[1]);
566 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
567 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
568 gen_add_tv(cpu_T[0], cpu_cc_src, cpu_T[1]);
571 gen_cc_C_add(cpu_T[0], cpu_cc_src);
576 env->psr |= PSR_CARRY;
578 static inline void gen_cc_C_sub(TCGv src1, TCGv src2)
582 l1 = gen_new_label();
583 tcg_gen_brcond_i32(TCG_COND_GEU, src1, src2, l1);
584 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
586 #ifdef TARGET_SPARC64
590 l2 = gen_new_label();
591 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l2);
592 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
599 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
602 static inline void gen_cc_V_sub(TCGv dst, TCGv src1, TCGv src2)
607 l1 = gen_new_label();
609 r_temp = tcg_temp_new(TCG_TYPE_TL);
610 tcg_gen_xor_tl(r_temp, src1, src2);
611 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
612 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
613 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
614 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp, tcg_const_i32(0), l1);
615 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
617 #ifdef TARGET_SPARC64
621 l2 = gen_new_label();
622 tcg_gen_xor_tl(r_temp, src1, src2);
623 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
624 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
625 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
626 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
627 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF);
631 tcg_gen_discard_tl(r_temp);
634 static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
639 l1 = gen_new_label();
641 r_temp = tcg_temp_new(TCG_TYPE_TL);
642 tcg_gen_xor_tl(r_temp, src1, src2);
643 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
644 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
645 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
646 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp, tcg_const_i32(0), l1);
647 gen_op_exception(TT_TOVF);
649 #ifdef TARGET_SPARC64
653 l2 = gen_new_label();
654 tcg_gen_xor_tl(r_temp, src1, src2);
655 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
656 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
657 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
658 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
659 gen_op_exception(TT_TOVF);
663 tcg_gen_discard_tl(r_temp);
666 static inline void gen_op_sub_T1_T0_cc(void)
668 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
669 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
672 gen_cc_C_sub(cpu_cc_src, cpu_T[1]);
673 gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]);
676 static inline void gen_op_subx_T1_T0_cc(void)
678 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
679 gen_mov_reg_C(cpu_tmp0, cpu_psr);
680 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_tmp0);
682 gen_cc_C_sub(cpu_T[0], cpu_cc_src);
683 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
684 gen_cc_C_sub(cpu_T[0], cpu_cc_src);
686 gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]);
689 static inline void gen_op_tsub_T1_T0_cc(void)
691 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
692 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
695 gen_cc_C_sub(cpu_cc_src, cpu_T[1]);
696 gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]);
697 gen_cc_V_tag(cpu_cc_src, cpu_T[1]);
700 static inline void gen_op_tsub_T1_T0_ccTV(void)
702 gen_tag_tv(cpu_T[0], cpu_T[1]);
703 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
704 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
705 gen_sub_tv(cpu_T[0], cpu_cc_src, cpu_T[1]);
708 gen_cc_C_sub(cpu_cc_src, cpu_T[1]);
711 static inline void gen_op_mulscc_T1_T0(void)
716 l1 = gen_new_label();
717 l2 = gen_new_label();
718 r_temp = tcg_temp_new(TCG_TYPE_TL);
724 tcg_gen_ld_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
725 tcg_gen_andi_i32(r_temp, r_temp, 0x1);
726 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
727 tcg_gen_mov_tl(cpu_cc_src2, cpu_T[1]);
728 gen_op_jmp_label(l2);
730 tcg_gen_movi_tl(cpu_cc_src2, 0);
734 // env->y = (b2 << 31) | (env->y >> 1);
735 tcg_gen_shli_i32(r_temp, cpu_T[0], 31);
736 tcg_gen_ld_i32(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, y));
737 tcg_gen_shri_i32(cpu_tmp0, cpu_tmp0, 1);
738 tcg_gen_or_i32(cpu_tmp0, cpu_tmp0, r_temp);
739 tcg_gen_st_i32(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, y));
742 gen_mov_reg_N(cpu_tmp0, cpu_psr);
743 gen_mov_reg_V(r_temp, cpu_psr);
744 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
746 // T0 = (b1 << 31) | (T0 >> 1);
748 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
749 tcg_gen_shri_tl(cpu_cc_src, cpu_T[0], 1);
750 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
752 /* do addition and update flags */
753 tcg_gen_add_tl(cpu_T[0], cpu_cc_src, cpu_cc_src2);
754 tcg_gen_discard_tl(r_temp);
758 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_cc_src2);
759 gen_cc_C_add(cpu_T[0], cpu_cc_src);
762 static inline void gen_op_umul_T1_T0(void)
764 TCGv r_temp, r_temp2;
766 r_temp = tcg_temp_new(TCG_TYPE_I64);
767 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
769 tcg_gen_extu_i32_i64(r_temp, cpu_T[1]);
770 tcg_gen_extu_i32_i64(r_temp2, cpu_T[0]);
771 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
773 tcg_gen_shri_i64(r_temp, r_temp2, 32);
774 tcg_gen_trunc_i64_i32(r_temp, r_temp);
775 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
776 #ifdef TARGET_SPARC64
777 tcg_gen_mov_i64(cpu_T[0], r_temp2);
779 tcg_gen_trunc_i64_i32(cpu_T[0], r_temp2);
782 tcg_gen_discard_i64(r_temp);
783 tcg_gen_discard_i64(r_temp2);
786 static inline void gen_op_smul_T1_T0(void)
788 TCGv r_temp, r_temp2;
790 r_temp = tcg_temp_new(TCG_TYPE_I64);
791 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
793 tcg_gen_ext32s_i64(r_temp, cpu_T[1]);
794 tcg_gen_ext32s_i64(r_temp2, cpu_T[0]);
795 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
797 tcg_gen_shri_i64(r_temp, r_temp2, 32);
798 tcg_gen_trunc_i64_i32(r_temp, r_temp);
799 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
800 #ifdef TARGET_SPARC64
801 tcg_gen_mov_i64(cpu_T[0], r_temp2);
803 tcg_gen_trunc_i64_i32(cpu_T[0], r_temp2);
806 tcg_gen_discard_i64(r_temp);
807 tcg_gen_discard_i64(r_temp2);
810 #ifdef TARGET_SPARC64
811 static inline void gen_trap_ifdivzero_i64(TCGv divisor)
815 l1 = gen_new_label();
816 tcg_gen_brcond_i64(TCG_COND_NE, divisor, tcg_const_tl(0), l1);
817 gen_op_exception(TT_DIV_ZERO);
821 static inline void gen_op_sdivx_T1_T0(void)
825 l1 = gen_new_label();
826 l2 = gen_new_label();
827 gen_trap_ifdivzero_i64(cpu_T[1]);
828 tcg_gen_brcond_i64(TCG_COND_NE, cpu_T[0], tcg_const_i64(INT64_MIN), l1);
829 tcg_gen_brcond_i64(TCG_COND_NE, cpu_T[1], tcg_const_i64(-1), l1);
830 tcg_gen_movi_i64(cpu_T[0], INT64_MIN);
831 gen_op_jmp_label(l2);
833 tcg_gen_div_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
838 static inline void gen_op_div_cc(void)
844 l1 = gen_new_label();
845 tcg_gen_brcond_i32(TCG_COND_EQ, cpu_T[1], tcg_const_i32(0), l1);
846 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
850 static inline void gen_op_logic_T0_cc(void)
857 static inline void gen_op_eval_ba(TCGv dst)
859 tcg_gen_movi_tl(dst, 1);
863 static inline void gen_op_eval_be(TCGv dst, TCGv src)
865 gen_mov_reg_Z(dst, src);
869 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
871 gen_mov_reg_N(cpu_tmp0, src);
872 gen_mov_reg_V(dst, src);
873 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
874 gen_mov_reg_Z(cpu_tmp0, src);
875 tcg_gen_or_tl(dst, dst, cpu_tmp0);
879 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
881 gen_mov_reg_V(cpu_tmp0, src);
882 gen_mov_reg_N(dst, src);
883 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
887 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
889 gen_mov_reg_Z(cpu_tmp0, src);
890 gen_mov_reg_C(dst, src);
891 tcg_gen_or_tl(dst, dst, cpu_tmp0);
895 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
897 gen_mov_reg_C(dst, src);
901 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
903 gen_mov_reg_V(dst, src);
907 static inline void gen_op_eval_bn(TCGv dst)
909 tcg_gen_movi_tl(dst, 0);
913 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
915 gen_mov_reg_N(dst, src);
919 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
921 gen_mov_reg_Z(dst, src);
922 tcg_gen_xori_tl(dst, dst, 0x1);
926 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
928 gen_mov_reg_N(cpu_tmp0, src);
929 gen_mov_reg_V(dst, src);
930 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
931 gen_mov_reg_Z(cpu_tmp0, src);
932 tcg_gen_or_tl(dst, dst, cpu_tmp0);
933 tcg_gen_xori_tl(dst, dst, 0x1);
937 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
939 gen_mov_reg_V(cpu_tmp0, src);
940 gen_mov_reg_N(dst, src);
941 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
942 tcg_gen_xori_tl(dst, dst, 0x1);
946 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
948 gen_mov_reg_Z(cpu_tmp0, src);
949 gen_mov_reg_C(dst, src);
950 tcg_gen_or_tl(dst, dst, cpu_tmp0);
951 tcg_gen_xori_tl(dst, dst, 0x1);
955 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
957 gen_mov_reg_C(dst, src);
958 tcg_gen_xori_tl(dst, dst, 0x1);
962 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
964 gen_mov_reg_N(dst, src);
965 tcg_gen_xori_tl(dst, dst, 0x1);
969 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
971 gen_mov_reg_V(dst, src);
972 tcg_gen_xori_tl(dst, dst, 0x1);
976 FPSR bit field FCC1 | FCC0:
982 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
983 unsigned int fcc_offset)
985 tcg_gen_shri_i32(reg, src, 10 + fcc_offset);
986 tcg_gen_andi_tl(reg, reg, 0x1);
989 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
990 unsigned int fcc_offset)
992 tcg_gen_shri_i32(reg, src, 11 + fcc_offset);
993 tcg_gen_andi_tl(reg, reg, 0x1);
997 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
998 unsigned int fcc_offset)
1000 gen_mov_reg_FCC0(dst, src, fcc_offset);
1001 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1002 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1005 // 1 or 2: FCC0 ^ FCC1
1006 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
1007 unsigned int fcc_offset)
1009 gen_mov_reg_FCC0(dst, src, fcc_offset);
1010 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1011 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1015 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1016 unsigned int fcc_offset)
1018 gen_mov_reg_FCC0(dst, src, fcc_offset);
1022 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
1023 unsigned int fcc_offset)
1025 gen_mov_reg_FCC0(dst, src, fcc_offset);
1026 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1027 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1028 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1032 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1033 unsigned int fcc_offset)
1035 gen_mov_reg_FCC1(dst, src, fcc_offset);
1039 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1040 unsigned int fcc_offset)
1042 gen_mov_reg_FCC0(dst, src, fcc_offset);
1043 tcg_gen_xori_tl(dst, dst, 0x1);
1044 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1045 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1049 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1050 unsigned int fcc_offset)
1052 gen_mov_reg_FCC0(dst, src, fcc_offset);
1053 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1054 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1057 // 0: !(FCC0 | FCC1)
1058 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1059 unsigned int fcc_offset)
1061 gen_mov_reg_FCC0(dst, src, fcc_offset);
1062 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1063 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1064 tcg_gen_xori_tl(dst, dst, 0x1);
1067 // 0 or 3: !(FCC0 ^ FCC1)
1068 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1069 unsigned int fcc_offset)
1071 gen_mov_reg_FCC0(dst, src, fcc_offset);
1072 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1073 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1074 tcg_gen_xori_tl(dst, dst, 0x1);
1078 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1079 unsigned int fcc_offset)
1081 gen_mov_reg_FCC0(dst, src, fcc_offset);
1082 tcg_gen_xori_tl(dst, dst, 0x1);
1085 // !1: !(FCC0 & !FCC1)
1086 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1087 unsigned int fcc_offset)
1089 gen_mov_reg_FCC0(dst, src, fcc_offset);
1090 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1091 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1092 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1093 tcg_gen_xori_tl(dst, dst, 0x1);
1097 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1098 unsigned int fcc_offset)
1100 gen_mov_reg_FCC1(dst, src, fcc_offset);
1101 tcg_gen_xori_tl(dst, dst, 0x1);
1104 // !2: !(!FCC0 & FCC1)
1105 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1106 unsigned int fcc_offset)
1108 gen_mov_reg_FCC0(dst, src, fcc_offset);
1109 tcg_gen_xori_tl(dst, dst, 0x1);
1110 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1111 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1112 tcg_gen_xori_tl(dst, dst, 0x1);
1115 // !3: !(FCC0 & FCC1)
1116 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1117 unsigned int fcc_offset)
1119 gen_mov_reg_FCC0(dst, src, fcc_offset);
1120 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1121 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1122 tcg_gen_xori_tl(dst, dst, 0x1);
1125 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1126 target_ulong pc2, TCGv r_cond)
1130 l1 = gen_new_label();
1132 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1134 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1137 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1140 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1141 target_ulong pc2, TCGv r_cond)
1145 l1 = gen_new_label();
1147 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1149 gen_goto_tb(dc, 0, pc2, pc1);
1152 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1155 static inline void gen_branch(DisasContext *dc, target_ulong pc,
1158 gen_goto_tb(dc, 0, pc, npc);
1161 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1166 l1 = gen_new_label();
1167 l2 = gen_new_label();
1169 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1171 gen_movl_npc_im(npc1);
1172 gen_op_jmp_label(l2);
1175 gen_movl_npc_im(npc2);
1179 /* call this function before using T2 as it may have been set for a jump */
1180 static inline void flush_T2(DisasContext * dc)
1182 if (dc->npc == JUMP_PC) {
1183 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
1184 dc->npc = DYNAMIC_PC;
1188 static inline void save_npc(DisasContext * dc)
1190 if (dc->npc == JUMP_PC) {
1191 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
1192 dc->npc = DYNAMIC_PC;
1193 } else if (dc->npc != DYNAMIC_PC) {
1194 gen_movl_npc_im(dc->npc);
1198 static inline void save_state(DisasContext * dc)
1204 static inline void gen_mov_pc_npc(DisasContext * dc)
1206 if (dc->npc == JUMP_PC) {
1207 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
1208 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1209 dc->pc = DYNAMIC_PC;
1210 } else if (dc->npc == DYNAMIC_PC) {
1211 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1212 dc->pc = DYNAMIC_PC;
1218 static inline void gen_op_next_insn(void)
1220 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1221 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1224 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1228 #ifdef TARGET_SPARC64
1238 gen_op_eval_bn(r_dst);
1241 gen_op_eval_be(r_dst, r_src);
1244 gen_op_eval_ble(r_dst, r_src);
1247 gen_op_eval_bl(r_dst, r_src);
1250 gen_op_eval_bleu(r_dst, r_src);
1253 gen_op_eval_bcs(r_dst, r_src);
1256 gen_op_eval_bneg(r_dst, r_src);
1259 gen_op_eval_bvs(r_dst, r_src);
1262 gen_op_eval_ba(r_dst);
1265 gen_op_eval_bne(r_dst, r_src);
1268 gen_op_eval_bg(r_dst, r_src);
1271 gen_op_eval_bge(r_dst, r_src);
1274 gen_op_eval_bgu(r_dst, r_src);
1277 gen_op_eval_bcc(r_dst, r_src);
1280 gen_op_eval_bpos(r_dst, r_src);
1283 gen_op_eval_bvc(r_dst, r_src);
1288 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1290 unsigned int offset;
1310 gen_op_eval_bn(r_dst);
1313 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1316 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1319 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1322 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1325 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1328 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1331 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1334 gen_op_eval_ba(r_dst);
1337 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1340 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1343 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1346 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1349 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1352 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1355 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1360 #ifdef TARGET_SPARC64
1362 static const int gen_tcg_cond_reg[8] = {
1373 static inline void gen_cond_reg(TCGv r_dst, int cond)
1377 l1 = gen_new_label();
1378 tcg_gen_movi_tl(r_dst, 0);
1379 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0], tcg_const_tl(0), l1);
1380 tcg_gen_movi_tl(r_dst, 1);
1385 /* XXX: potentially incorrect if dynamic npc */
1386 static void do_branch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
1388 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1389 target_ulong target = dc->pc + offset;
1392 /* unconditional not taken */
1394 dc->pc = dc->npc + 4;
1395 dc->npc = dc->pc + 4;
1398 dc->npc = dc->pc + 4;
1400 } else if (cond == 0x8) {
1401 /* unconditional taken */
1404 dc->npc = dc->pc + 4;
1411 gen_cond(cpu_T[2], cc, cond);
1413 gen_branch_a(dc, target, dc->npc, cpu_T[2]);
1417 dc->jump_pc[0] = target;
1418 dc->jump_pc[1] = dc->npc + 4;
1424 /* XXX: potentially incorrect if dynamic npc */
1425 static void do_fbranch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
1427 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1428 target_ulong target = dc->pc + offset;
1431 /* unconditional not taken */
1433 dc->pc = dc->npc + 4;
1434 dc->npc = dc->pc + 4;
1437 dc->npc = dc->pc + 4;
1439 } else if (cond == 0x8) {
1440 /* unconditional taken */
1443 dc->npc = dc->pc + 4;
1450 gen_fcond(cpu_T[2], cc, cond);
1452 gen_branch_a(dc, target, dc->npc, cpu_T[2]);
1456 dc->jump_pc[0] = target;
1457 dc->jump_pc[1] = dc->npc + 4;
1463 #ifdef TARGET_SPARC64
1464 /* XXX: potentially incorrect if dynamic npc */
1465 static void do_branch_reg(DisasContext * dc, int32_t offset, uint32_t insn)
1467 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1468 target_ulong target = dc->pc + offset;
1471 gen_cond_reg(cpu_T[2], cond);
1473 gen_branch_a(dc, target, dc->npc, cpu_T[2]);
1477 dc->jump_pc[0] = target;
1478 dc->jump_pc[1] = dc->npc + 4;
1483 static GenOpFunc * const gen_fcmps[4] = {
1490 static GenOpFunc * const gen_fcmpd[4] = {
1497 #if defined(CONFIG_USER_ONLY)
1498 static GenOpFunc * const gen_fcmpq[4] = {
1506 static GenOpFunc * const gen_fcmpes[4] = {
1513 static GenOpFunc * const gen_fcmped[4] = {
1520 #if defined(CONFIG_USER_ONLY)
1521 static GenOpFunc * const gen_fcmpeq[4] = {
1529 static inline void gen_op_fcmps(int fccno)
1531 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1534 static inline void gen_op_fcmpd(int fccno)
1536 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1539 #if defined(CONFIG_USER_ONLY)
1540 static inline void gen_op_fcmpq(int fccno)
1542 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1546 static inline void gen_op_fcmpes(int fccno)
1548 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1551 static inline void gen_op_fcmped(int fccno)
1553 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1556 #if defined(CONFIG_USER_ONLY)
1557 static inline void gen_op_fcmpeq(int fccno)
1559 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1565 static inline void gen_op_fcmps(int fccno)
1567 tcg_gen_helper_0_0(helper_fcmps);
1570 static inline void gen_op_fcmpd(int fccno)
1572 tcg_gen_helper_0_0(helper_fcmpd);
1575 #if defined(CONFIG_USER_ONLY)
1576 static inline void gen_op_fcmpq(int fccno)
1578 tcg_gen_helper_0_0(helper_fcmpq);
1582 static inline void gen_op_fcmpes(int fccno)
1584 tcg_gen_helper_0_0(helper_fcmpes);
1587 static inline void gen_op_fcmped(int fccno)
1589 tcg_gen_helper_0_0(helper_fcmped);
1592 #if defined(CONFIG_USER_ONLY)
1593 static inline void gen_op_fcmpeq(int fccno)
1595 tcg_gen_helper_0_0(helper_fcmpeq);
1601 static inline void gen_op_fpexception_im(int fsr_flags)
1603 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1604 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1605 gen_op_exception(TT_FP_EXCP);
1608 static int gen_trap_ifnofpu(DisasContext * dc)
1610 #if !defined(CONFIG_USER_ONLY)
1611 if (!dc->fpu_enabled) {
1613 gen_op_exception(TT_NFPU_INSN);
1621 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1623 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1626 static inline void gen_clear_float_exceptions(void)
1628 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1632 #ifdef TARGET_SPARC64
1633 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1639 r_asi = tcg_temp_new(TCG_TYPE_I32);
1640 offset = GET_FIELD(insn, 25, 31);
1641 tcg_gen_addi_tl(r_addr, r_addr, offset);
1642 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1644 asi = GET_FIELD(insn, 19, 26);
1645 r_asi = tcg_const_i32(asi);
1650 static inline void gen_ld_asi(int insn, int size, int sign)
1654 r_asi = gen_get_asi(insn, cpu_T[0]);
1655 tcg_gen_helper_1_4(helper_ld_asi, cpu_T[1], cpu_T[0], r_asi,
1656 tcg_const_i32(size), tcg_const_i32(sign));
1657 tcg_gen_discard_i32(r_asi);
1660 static inline void gen_st_asi(int insn, int size)
1664 r_asi = gen_get_asi(insn, cpu_T[0]);
1665 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_T[1], r_asi,
1666 tcg_const_i32(size));
1667 tcg_gen_discard_i32(r_asi);
1670 static inline void gen_ldf_asi(int insn, int size, int rd)
1674 r_asi = gen_get_asi(insn, cpu_T[0]);
1675 tcg_gen_helper_0_4(helper_ldf_asi, cpu_T[0], r_asi, tcg_const_i32(size),
1677 tcg_gen_discard_i32(r_asi);
1680 static inline void gen_stf_asi(int insn, int size, int rd)
1684 r_asi = gen_get_asi(insn, cpu_T[0]);
1685 tcg_gen_helper_0_4(helper_stf_asi, cpu_T[0], r_asi, tcg_const_i32(size),
1687 tcg_gen_discard_i32(r_asi);
1690 static inline void gen_swap_asi(int insn)
1694 r_temp = tcg_temp_new(TCG_TYPE_I32);
1695 r_asi = gen_get_asi(insn, cpu_T[0]);
1696 tcg_gen_helper_1_4(helper_ld_asi, r_temp, cpu_T[0], r_asi,
1697 tcg_const_i32(4), tcg_const_i32(0));
1698 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], r_temp, r_asi,
1700 tcg_gen_mov_i32(cpu_T[1], r_temp);
1701 tcg_gen_discard_i32(r_asi);
1702 tcg_gen_discard_i32(r_temp);
1705 static inline void gen_ldda_asi(int insn)
1707 TCGv r_dword, r_asi;
1709 r_dword = tcg_temp_new(TCG_TYPE_I64);
1710 r_asi = gen_get_asi(insn, cpu_T[0]);
1711 tcg_gen_helper_1_4(helper_ld_asi, r_dword, cpu_T[0], r_asi,
1712 tcg_const_i32(8), tcg_const_i32(0));
1713 tcg_gen_trunc_i64_i32(cpu_T[0], r_dword);
1714 tcg_gen_shri_i64(r_dword, r_dword, 32);
1715 tcg_gen_trunc_i64_i32(cpu_T[1], r_dword);
1716 tcg_gen_discard_i32(r_asi);
1717 tcg_gen_discard_i64(r_dword);
1720 static inline void gen_stda_asi(int insn, int rd)
1722 TCGv r_dword, r_temp, r_asi;
1724 r_dword = tcg_temp_new(TCG_TYPE_I64);
1725 r_temp = tcg_temp_new(TCG_TYPE_I32);
1726 gen_movl_reg_TN(rd + 1, r_temp);
1727 tcg_gen_helper_1_2(helper_pack64, r_dword, cpu_T[1],
1729 r_asi = gen_get_asi(insn, cpu_T[0]);
1730 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], r_dword, r_asi,
1732 tcg_gen_discard_i32(r_asi);
1733 tcg_gen_discard_i32(r_temp);
1734 tcg_gen_discard_i64(r_dword);
1737 static inline void gen_cas_asi(int insn, int rd)
1741 r_val1 = tcg_temp_new(TCG_TYPE_I32);
1742 gen_movl_reg_TN(rd, r_val1);
1743 r_asi = gen_get_asi(insn, cpu_T[0]);
1744 tcg_gen_helper_1_4(helper_cas_asi, cpu_T[1], cpu_T[0], r_val1, cpu_T[1],
1746 tcg_gen_discard_i32(r_asi);
1747 tcg_gen_discard_i32(r_val1);
1750 static inline void gen_casx_asi(int insn, int rd)
1754 r_val1 = tcg_temp_new(TCG_TYPE_I64);
1755 gen_movl_reg_TN(rd, r_val1);
1756 r_asi = gen_get_asi(insn, cpu_T[0]);
1757 tcg_gen_helper_1_4(helper_casx_asi, cpu_T[1], cpu_T[0], r_val1, cpu_T[1],
1759 tcg_gen_discard_i32(r_asi);
1760 tcg_gen_discard_i32(r_val1);
1763 #elif !defined(CONFIG_USER_ONLY)
1765 static inline void gen_ld_asi(int insn, int size, int sign)
1770 r_dword = tcg_temp_new(TCG_TYPE_I64);
1771 asi = GET_FIELD(insn, 19, 26);
1772 tcg_gen_helper_1_4(helper_ld_asi, r_dword, cpu_T[0], tcg_const_i32(asi),
1773 tcg_const_i32(size), tcg_const_i32(sign));
1774 tcg_gen_trunc_i64_i32(cpu_T[1], r_dword);
1775 tcg_gen_discard_i64(r_dword);
1778 static inline void gen_st_asi(int insn, int size)
1783 r_dword = tcg_temp_new(TCG_TYPE_I64);
1784 tcg_gen_extu_i32_i64(r_dword, cpu_T[1]);
1785 asi = GET_FIELD(insn, 19, 26);
1786 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], r_dword, tcg_const_i32(asi),
1787 tcg_const_i32(size));
1788 tcg_gen_discard_i64(r_dword);
1791 static inline void gen_swap_asi(int insn)
1796 r_temp = tcg_temp_new(TCG_TYPE_I32);
1797 asi = GET_FIELD(insn, 19, 26);
1798 tcg_gen_helper_1_4(helper_ld_asi, r_temp, cpu_T[0], tcg_const_i32(asi),
1799 tcg_const_i32(4), tcg_const_i32(0));
1800 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_T[1], tcg_const_i32(asi),
1802 tcg_gen_mov_i32(cpu_T[1], r_temp);
1803 tcg_gen_discard_i32(r_temp);
1806 static inline void gen_ldda_asi(int insn)
1811 r_dword = tcg_temp_new(TCG_TYPE_I64);
1812 asi = GET_FIELD(insn, 19, 26);
1813 tcg_gen_helper_1_4(helper_ld_asi, r_dword, cpu_T[0], tcg_const_i32(asi),
1814 tcg_const_i32(8), tcg_const_i32(0));
1815 tcg_gen_trunc_i64_i32(cpu_T[0], r_dword);
1816 tcg_gen_shri_i64(r_dword, r_dword, 32);
1817 tcg_gen_trunc_i64_i32(cpu_T[1], r_dword);
1818 tcg_gen_discard_i64(r_dword);
1821 static inline void gen_stda_asi(int insn, int rd)
1824 TCGv r_dword, r_temp;
1826 r_dword = tcg_temp_new(TCG_TYPE_I64);
1827 r_temp = tcg_temp_new(TCG_TYPE_I32);
1828 gen_movl_reg_TN(rd + 1, r_temp);
1829 tcg_gen_helper_1_2(helper_pack64, r_dword, cpu_T[1], r_temp);
1830 asi = GET_FIELD(insn, 19, 26);
1831 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], r_dword, tcg_const_i32(asi),
1833 tcg_gen_discard_i64(r_dword);
1837 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1838 static inline void gen_ldstub_asi(int insn)
1842 gen_ld_asi(insn, 1, 0);
1844 asi = GET_FIELD(insn, 19, 26);
1845 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], tcg_const_i64(0xff),
1846 tcg_const_i32(asi), tcg_const_i32(1));
1850 /* before an instruction, dc->pc must be static */
1851 static void disas_sparc_insn(DisasContext * dc)
1853 unsigned int insn, opc, rs1, rs2, rd;
1855 insn = ldl_code(dc->pc);
1856 opc = GET_FIELD(insn, 0, 1);
1858 rd = GET_FIELD(insn, 2, 6);
1860 case 0: /* branches/sethi */
1862 unsigned int xop = GET_FIELD(insn, 7, 9);
1865 #ifdef TARGET_SPARC64
1866 case 0x1: /* V9 BPcc */
1870 target = GET_FIELD_SP(insn, 0, 18);
1871 target = sign_extend(target, 18);
1873 cc = GET_FIELD_SP(insn, 20, 21);
1875 do_branch(dc, target, insn, 0);
1877 do_branch(dc, target, insn, 1);
1882 case 0x3: /* V9 BPr */
1884 target = GET_FIELD_SP(insn, 0, 13) |
1885 (GET_FIELD_SP(insn, 20, 21) << 14);
1886 target = sign_extend(target, 16);
1888 rs1 = GET_FIELD(insn, 13, 17);
1889 gen_movl_reg_T0(rs1);
1890 do_branch_reg(dc, target, insn);
1893 case 0x5: /* V9 FBPcc */
1895 int cc = GET_FIELD_SP(insn, 20, 21);
1896 if (gen_trap_ifnofpu(dc))
1898 target = GET_FIELD_SP(insn, 0, 18);
1899 target = sign_extend(target, 19);
1901 do_fbranch(dc, target, insn, cc);
1905 case 0x7: /* CBN+x */
1910 case 0x2: /* BN+x */
1912 target = GET_FIELD(insn, 10, 31);
1913 target = sign_extend(target, 22);
1915 do_branch(dc, target, insn, 0);
1918 case 0x6: /* FBN+x */
1920 if (gen_trap_ifnofpu(dc))
1922 target = GET_FIELD(insn, 10, 31);
1923 target = sign_extend(target, 22);
1925 do_fbranch(dc, target, insn, 0);
1928 case 0x4: /* SETHI */
1933 uint32_t value = GET_FIELD(insn, 10, 31);
1934 tcg_gen_movi_tl(cpu_T[0], value << 10);
1935 gen_movl_T0_reg(rd);
1940 case 0x0: /* UNIMPL */
1949 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1951 gen_movl_TN_reg(15, tcg_const_tl(dc->pc));
1957 case 2: /* FPU & Logical Operations */
1959 unsigned int xop = GET_FIELD(insn, 7, 12);
1960 if (xop == 0x3a) { /* generate trap */
1963 rs1 = GET_FIELD(insn, 13, 17);
1964 gen_movl_reg_T0(rs1);
1966 rs2 = GET_FIELD(insn, 25, 31);
1967 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], rs2);
1969 rs2 = GET_FIELD(insn, 27, 31);
1973 gen_movl_reg_T1(rs2);
1979 cond = GET_FIELD(insn, 3, 6);
1982 tcg_gen_helper_0_1(helper_trap, cpu_T[0]);
1983 } else if (cond != 0) {
1984 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
1985 #ifdef TARGET_SPARC64
1987 int cc = GET_FIELD_SP(insn, 11, 12);
1991 gen_cond(r_cond, 0, cond);
1993 gen_cond(r_cond, 1, cond);
1998 gen_cond(r_cond, 0, cond);
2000 tcg_gen_helper_0_2(helper_trapcc, cpu_T[0], r_cond);
2001 tcg_gen_discard_tl(r_cond);
2007 } else if (xop == 0x28) {
2008 rs1 = GET_FIELD(insn, 13, 17);
2011 #ifndef TARGET_SPARC64
2012 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2013 manual, rdy on the microSPARC
2015 case 0x0f: /* stbar in the SPARCv8 manual,
2016 rdy on the microSPARC II */
2017 case 0x10 ... 0x1f: /* implementation-dependent in the
2018 SPARCv8 manual, rdy on the
2021 gen_op_movtl_T0_env(offsetof(CPUSPARCState, y));
2022 gen_movl_T0_reg(rd);
2024 #ifdef TARGET_SPARC64
2025 case 0x2: /* V9 rdccr */
2026 tcg_gen_helper_1_0(helper_rdccr, cpu_T[0]);
2027 gen_movl_T0_reg(rd);
2029 case 0x3: /* V9 rdasi */
2030 gen_op_movl_T0_env(offsetof(CPUSPARCState, asi));
2031 gen_movl_T0_reg(rd);
2033 case 0x4: /* V9 rdtick */
2037 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2038 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2039 offsetof(CPUState, tick));
2040 tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0],
2042 gen_movl_T0_reg(rd);
2043 tcg_gen_discard_ptr(r_tickptr);
2046 case 0x5: /* V9 rdpc */
2047 tcg_gen_movi_tl(cpu_T[0], dc->pc);
2048 gen_movl_T0_reg(rd);
2050 case 0x6: /* V9 rdfprs */
2051 gen_op_movl_T0_env(offsetof(CPUSPARCState, fprs));
2052 gen_movl_T0_reg(rd);
2054 case 0xf: /* V9 membar */
2055 break; /* no effect */
2056 case 0x13: /* Graphics Status */
2057 if (gen_trap_ifnofpu(dc))
2059 gen_op_movtl_T0_env(offsetof(CPUSPARCState, gsr));
2060 gen_movl_T0_reg(rd);
2062 case 0x17: /* Tick compare */
2063 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tick_cmpr));
2064 gen_movl_T0_reg(rd);
2066 case 0x18: /* System tick */
2070 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2071 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2072 offsetof(CPUState, stick));
2073 tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0],
2075 gen_movl_T0_reg(rd);
2076 tcg_gen_discard_ptr(r_tickptr);
2079 case 0x19: /* System tick compare */
2080 gen_op_movtl_T0_env(offsetof(CPUSPARCState, stick_cmpr));
2081 gen_movl_T0_reg(rd);
2083 case 0x10: /* Performance Control */
2084 case 0x11: /* Performance Instrumentation Counter */
2085 case 0x12: /* Dispatch Control */
2086 case 0x14: /* Softint set, WO */
2087 case 0x15: /* Softint clear, WO */
2088 case 0x16: /* Softint write */
2093 #if !defined(CONFIG_USER_ONLY)
2094 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2095 #ifndef TARGET_SPARC64
2096 if (!supervisor(dc))
2098 tcg_gen_helper_1_0(helper_rdpsr, cpu_T[0]);
2100 if (!hypervisor(dc))
2102 rs1 = GET_FIELD(insn, 13, 17);
2105 // gen_op_rdhpstate();
2108 // gen_op_rdhtstate();
2111 gen_op_movl_T0_env(offsetof(CPUSPARCState, hintp));
2114 gen_op_movl_T0_env(offsetof(CPUSPARCState, htba));
2117 gen_op_movl_T0_env(offsetof(CPUSPARCState, hver));
2119 case 31: // hstick_cmpr
2120 gen_op_movl_env_T0(offsetof(CPUSPARCState, hstick_cmpr));
2126 gen_movl_T0_reg(rd);
2128 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2129 if (!supervisor(dc))
2131 #ifdef TARGET_SPARC64
2132 rs1 = GET_FIELD(insn, 13, 17);
2138 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2139 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2140 offsetof(CPUState, tsptr));
2141 tcg_gen_ld_tl(cpu_T[0], r_tsptr,
2142 offsetof(trap_state, tpc));
2143 tcg_gen_discard_ptr(r_tsptr);
2150 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2151 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2152 offsetof(CPUState, tsptr));
2153 tcg_gen_ld_tl(cpu_T[0], r_tsptr,
2154 offsetof(trap_state, tnpc));
2155 tcg_gen_discard_ptr(r_tsptr);
2162 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2163 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2164 offsetof(CPUState, tsptr));
2165 tcg_gen_ld_tl(cpu_T[0], r_tsptr,
2166 offsetof(trap_state, tstate));
2167 tcg_gen_discard_ptr(r_tsptr);
2174 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2175 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2176 offsetof(CPUState, tsptr));
2177 tcg_gen_ld_i32(cpu_T[0], r_tsptr,
2178 offsetof(trap_state, tt));
2179 tcg_gen_discard_ptr(r_tsptr);
2186 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2187 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2188 offsetof(CPUState, tick));
2189 tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0],
2191 gen_movl_T0_reg(rd);
2192 tcg_gen_discard_ptr(r_tickptr);
2196 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr));
2199 gen_op_movl_T0_env(offsetof(CPUSPARCState, pstate));
2202 gen_op_movl_T0_env(offsetof(CPUSPARCState, tl));
2205 gen_op_movl_T0_env(offsetof(CPUSPARCState, psrpil));
2208 tcg_gen_helper_1_0(helper_rdcwp, cpu_T[0]);
2211 gen_op_movl_T0_env(offsetof(CPUSPARCState, cansave));
2213 case 11: // canrestore
2214 gen_op_movl_T0_env(offsetof(CPUSPARCState, canrestore));
2216 case 12: // cleanwin
2217 gen_op_movl_T0_env(offsetof(CPUSPARCState, cleanwin));
2219 case 13: // otherwin
2220 gen_op_movl_T0_env(offsetof(CPUSPARCState, otherwin));
2223 gen_op_movl_T0_env(offsetof(CPUSPARCState, wstate));
2225 case 16: // UA2005 gl
2226 gen_op_movl_T0_env(offsetof(CPUSPARCState, gl));
2228 case 26: // UA2005 strand status
2229 if (!hypervisor(dc))
2231 gen_op_movl_T0_env(offsetof(CPUSPARCState, ssr));
2234 gen_op_movtl_T0_env(offsetof(CPUSPARCState, version));
2241 gen_op_movl_T0_env(offsetof(CPUSPARCState, wim));
2243 gen_movl_T0_reg(rd);
2245 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2246 #ifdef TARGET_SPARC64
2249 if (!supervisor(dc))
2251 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr));
2252 gen_movl_T0_reg(rd);
2256 } else if (xop == 0x34) { /* FPU Operations */
2257 if (gen_trap_ifnofpu(dc))
2259 gen_op_clear_ieee_excp_and_FTT();
2260 rs1 = GET_FIELD(insn, 13, 17);
2261 rs2 = GET_FIELD(insn, 27, 31);
2262 xop = GET_FIELD(insn, 18, 26);
2264 case 0x1: /* fmovs */
2265 gen_op_load_fpr_FT0(rs2);
2266 gen_op_store_FT0_fpr(rd);
2268 case 0x5: /* fnegs */
2269 gen_op_load_fpr_FT1(rs2);
2271 gen_op_store_FT0_fpr(rd);
2273 case 0x9: /* fabss */
2274 gen_op_load_fpr_FT1(rs2);
2275 tcg_gen_helper_0_0(helper_fabss);
2276 gen_op_store_FT0_fpr(rd);
2278 case 0x29: /* fsqrts */
2279 gen_op_load_fpr_FT1(rs2);
2280 gen_clear_float_exceptions();
2281 tcg_gen_helper_0_0(helper_fsqrts);
2282 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2283 gen_op_store_FT0_fpr(rd);
2285 case 0x2a: /* fsqrtd */
2286 gen_op_load_fpr_DT1(DFPREG(rs2));
2287 gen_clear_float_exceptions();
2288 tcg_gen_helper_0_0(helper_fsqrtd);
2289 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2290 gen_op_store_DT0_fpr(DFPREG(rd));
2292 case 0x2b: /* fsqrtq */
2293 #if defined(CONFIG_USER_ONLY)
2294 gen_op_load_fpr_QT1(QFPREG(rs2));
2295 gen_clear_float_exceptions();
2296 tcg_gen_helper_0_0(helper_fsqrtq);
2297 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2298 gen_op_store_QT0_fpr(QFPREG(rd));
2304 gen_op_load_fpr_FT0(rs1);
2305 gen_op_load_fpr_FT1(rs2);
2306 gen_clear_float_exceptions();
2308 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2309 gen_op_store_FT0_fpr(rd);
2312 gen_op_load_fpr_DT0(DFPREG(rs1));
2313 gen_op_load_fpr_DT1(DFPREG(rs2));
2314 gen_clear_float_exceptions();
2316 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2317 gen_op_store_DT0_fpr(DFPREG(rd));
2319 case 0x43: /* faddq */
2320 #if defined(CONFIG_USER_ONLY)
2321 gen_op_load_fpr_QT0(QFPREG(rs1));
2322 gen_op_load_fpr_QT1(QFPREG(rs2));
2323 gen_clear_float_exceptions();
2325 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2326 gen_op_store_QT0_fpr(QFPREG(rd));
2332 gen_op_load_fpr_FT0(rs1);
2333 gen_op_load_fpr_FT1(rs2);
2334 gen_clear_float_exceptions();
2336 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2337 gen_op_store_FT0_fpr(rd);
2340 gen_op_load_fpr_DT0(DFPREG(rs1));
2341 gen_op_load_fpr_DT1(DFPREG(rs2));
2342 gen_clear_float_exceptions();
2344 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2345 gen_op_store_DT0_fpr(DFPREG(rd));
2347 case 0x47: /* fsubq */
2348 #if defined(CONFIG_USER_ONLY)
2349 gen_op_load_fpr_QT0(QFPREG(rs1));
2350 gen_op_load_fpr_QT1(QFPREG(rs2));
2351 gen_clear_float_exceptions();
2353 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2354 gen_op_store_QT0_fpr(QFPREG(rd));
2360 gen_op_load_fpr_FT0(rs1);
2361 gen_op_load_fpr_FT1(rs2);
2362 gen_clear_float_exceptions();
2364 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2365 gen_op_store_FT0_fpr(rd);
2368 gen_op_load_fpr_DT0(DFPREG(rs1));
2369 gen_op_load_fpr_DT1(DFPREG(rs2));
2370 gen_clear_float_exceptions();
2372 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2373 gen_op_store_DT0_fpr(DFPREG(rd));
2375 case 0x4b: /* fmulq */
2376 #if defined(CONFIG_USER_ONLY)
2377 gen_op_load_fpr_QT0(QFPREG(rs1));
2378 gen_op_load_fpr_QT1(QFPREG(rs2));
2379 gen_clear_float_exceptions();
2381 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2382 gen_op_store_QT0_fpr(QFPREG(rd));
2388 gen_op_load_fpr_FT0(rs1);
2389 gen_op_load_fpr_FT1(rs2);
2390 gen_clear_float_exceptions();
2392 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2393 gen_op_store_FT0_fpr(rd);
2396 gen_op_load_fpr_DT0(DFPREG(rs1));
2397 gen_op_load_fpr_DT1(DFPREG(rs2));
2398 gen_clear_float_exceptions();
2400 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2401 gen_op_store_DT0_fpr(DFPREG(rd));
2403 case 0x4f: /* fdivq */
2404 #if defined(CONFIG_USER_ONLY)
2405 gen_op_load_fpr_QT0(QFPREG(rs1));
2406 gen_op_load_fpr_QT1(QFPREG(rs2));
2407 gen_clear_float_exceptions();
2409 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2410 gen_op_store_QT0_fpr(QFPREG(rd));
2416 gen_op_load_fpr_FT0(rs1);
2417 gen_op_load_fpr_FT1(rs2);
2418 gen_clear_float_exceptions();
2420 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2421 gen_op_store_DT0_fpr(DFPREG(rd));
2423 case 0x6e: /* fdmulq */
2424 #if defined(CONFIG_USER_ONLY)
2425 gen_op_load_fpr_DT0(DFPREG(rs1));
2426 gen_op_load_fpr_DT1(DFPREG(rs2));
2427 gen_clear_float_exceptions();
2429 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2430 gen_op_store_QT0_fpr(QFPREG(rd));
2436 gen_op_load_fpr_FT1(rs2);
2437 gen_clear_float_exceptions();
2439 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2440 gen_op_store_FT0_fpr(rd);
2443 gen_op_load_fpr_DT1(DFPREG(rs2));
2444 gen_clear_float_exceptions();
2446 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2447 gen_op_store_FT0_fpr(rd);
2449 case 0xc7: /* fqtos */
2450 #if defined(CONFIG_USER_ONLY)
2451 gen_op_load_fpr_QT1(QFPREG(rs2));
2452 gen_clear_float_exceptions();
2454 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2455 gen_op_store_FT0_fpr(rd);
2461 gen_op_load_fpr_FT1(rs2);
2463 gen_op_store_DT0_fpr(DFPREG(rd));
2466 gen_op_load_fpr_FT1(rs2);
2468 gen_op_store_DT0_fpr(DFPREG(rd));
2470 case 0xcb: /* fqtod */
2471 #if defined(CONFIG_USER_ONLY)
2472 gen_op_load_fpr_QT1(QFPREG(rs2));
2473 gen_clear_float_exceptions();
2475 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2476 gen_op_store_DT0_fpr(DFPREG(rd));
2481 case 0xcc: /* fitoq */
2482 #if defined(CONFIG_USER_ONLY)
2483 gen_op_load_fpr_FT1(rs2);
2485 gen_op_store_QT0_fpr(QFPREG(rd));
2490 case 0xcd: /* fstoq */
2491 #if defined(CONFIG_USER_ONLY)
2492 gen_op_load_fpr_FT1(rs2);
2494 gen_op_store_QT0_fpr(QFPREG(rd));
2499 case 0xce: /* fdtoq */
2500 #if defined(CONFIG_USER_ONLY)
2501 gen_op_load_fpr_DT1(DFPREG(rs2));
2503 gen_op_store_QT0_fpr(QFPREG(rd));
2509 gen_op_load_fpr_FT1(rs2);
2510 gen_clear_float_exceptions();
2512 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2513 gen_op_store_FT0_fpr(rd);
2516 gen_op_load_fpr_DT1(DFPREG(rs2));
2517 gen_clear_float_exceptions();
2519 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2520 gen_op_store_FT0_fpr(rd);
2522 case 0xd3: /* fqtoi */
2523 #if defined(CONFIG_USER_ONLY)
2524 gen_op_load_fpr_QT1(QFPREG(rs2));
2525 gen_clear_float_exceptions();
2527 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2528 gen_op_store_FT0_fpr(rd);
2533 #ifdef TARGET_SPARC64
2534 case 0x2: /* V9 fmovd */
2535 gen_op_load_fpr_DT0(DFPREG(rs2));
2536 gen_op_store_DT0_fpr(DFPREG(rd));
2538 case 0x3: /* V9 fmovq */
2539 #if defined(CONFIG_USER_ONLY)
2540 gen_op_load_fpr_QT0(QFPREG(rs2));
2541 gen_op_store_QT0_fpr(QFPREG(rd));
2546 case 0x6: /* V9 fnegd */
2547 gen_op_load_fpr_DT1(DFPREG(rs2));
2549 gen_op_store_DT0_fpr(DFPREG(rd));
2551 case 0x7: /* V9 fnegq */
2552 #if defined(CONFIG_USER_ONLY)
2553 gen_op_load_fpr_QT1(QFPREG(rs2));
2555 gen_op_store_QT0_fpr(QFPREG(rd));
2560 case 0xa: /* V9 fabsd */
2561 gen_op_load_fpr_DT1(DFPREG(rs2));
2562 tcg_gen_helper_0_0(helper_fabsd);
2563 gen_op_store_DT0_fpr(DFPREG(rd));
2565 case 0xb: /* V9 fabsq */
2566 #if defined(CONFIG_USER_ONLY)
2567 gen_op_load_fpr_QT1(QFPREG(rs2));
2568 tcg_gen_helper_0_0(helper_fabsq);
2569 gen_op_store_QT0_fpr(QFPREG(rd));
2574 case 0x81: /* V9 fstox */
2575 gen_op_load_fpr_FT1(rs2);
2576 gen_clear_float_exceptions();
2578 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2579 gen_op_store_DT0_fpr(DFPREG(rd));
2581 case 0x82: /* V9 fdtox */
2582 gen_op_load_fpr_DT1(DFPREG(rs2));
2583 gen_clear_float_exceptions();
2585 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2586 gen_op_store_DT0_fpr(DFPREG(rd));
2588 case 0x83: /* V9 fqtox */
2589 #if defined(CONFIG_USER_ONLY)
2590 gen_op_load_fpr_QT1(QFPREG(rs2));
2591 gen_clear_float_exceptions();
2593 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2594 gen_op_store_DT0_fpr(DFPREG(rd));
2599 case 0x84: /* V9 fxtos */
2600 gen_op_load_fpr_DT1(DFPREG(rs2));
2601 gen_clear_float_exceptions();
2603 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2604 gen_op_store_FT0_fpr(rd);
2606 case 0x88: /* V9 fxtod */
2607 gen_op_load_fpr_DT1(DFPREG(rs2));
2608 gen_clear_float_exceptions();
2610 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2611 gen_op_store_DT0_fpr(DFPREG(rd));
2613 case 0x8c: /* V9 fxtoq */
2614 #if defined(CONFIG_USER_ONLY)
2615 gen_op_load_fpr_DT1(DFPREG(rs2));
2616 gen_clear_float_exceptions();
2618 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2619 gen_op_store_QT0_fpr(QFPREG(rd));
2628 } else if (xop == 0x35) { /* FPU Operations */
2629 #ifdef TARGET_SPARC64
2632 if (gen_trap_ifnofpu(dc))
2634 gen_op_clear_ieee_excp_and_FTT();
2635 rs1 = GET_FIELD(insn, 13, 17);
2636 rs2 = GET_FIELD(insn, 27, 31);
2637 xop = GET_FIELD(insn, 18, 26);
2638 #ifdef TARGET_SPARC64
2639 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2642 l1 = gen_new_label();
2643 cond = GET_FIELD_SP(insn, 14, 17);
2644 rs1 = GET_FIELD(insn, 13, 17);
2645 gen_movl_reg_T0(rs1);
2646 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
2647 tcg_const_tl(0), l1);
2648 gen_op_load_fpr_FT0(rs2);
2649 gen_op_store_FT0_fpr(rd);
2652 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2655 l1 = gen_new_label();
2656 cond = GET_FIELD_SP(insn, 14, 17);
2657 rs1 = GET_FIELD(insn, 13, 17);
2658 gen_movl_reg_T0(rs1);
2659 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
2660 tcg_const_tl(0), l1);
2661 gen_op_load_fpr_DT0(DFPREG(rs2));
2662 gen_op_store_DT0_fpr(DFPREG(rd));
2665 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2666 #if defined(CONFIG_USER_ONLY)
2669 l1 = gen_new_label();
2670 cond = GET_FIELD_SP(insn, 14, 17);
2671 rs1 = GET_FIELD(insn, 13, 17);
2672 gen_movl_reg_T0(rs1);
2673 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
2674 tcg_const_tl(0), l1);
2675 gen_op_load_fpr_QT0(QFPREG(rs2));
2676 gen_op_store_QT0_fpr(QFPREG(rd));
2685 #ifdef TARGET_SPARC64
2686 #define FMOVCC(size_FDQ, fcc) \
2691 l1 = gen_new_label(); \
2692 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2693 cond = GET_FIELD_SP(insn, 14, 17); \
2694 gen_fcond(r_cond, fcc, cond); \
2695 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2696 tcg_const_tl(0), l1); \
2697 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2698 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2699 gen_set_label(l1); \
2700 tcg_gen_discard_tl(r_cond); \
2702 case 0x001: /* V9 fmovscc %fcc0 */
2705 case 0x002: /* V9 fmovdcc %fcc0 */
2708 case 0x003: /* V9 fmovqcc %fcc0 */
2709 #if defined(CONFIG_USER_ONLY)
2715 case 0x041: /* V9 fmovscc %fcc1 */
2718 case 0x042: /* V9 fmovdcc %fcc1 */
2721 case 0x043: /* V9 fmovqcc %fcc1 */
2722 #if defined(CONFIG_USER_ONLY)
2728 case 0x081: /* V9 fmovscc %fcc2 */
2731 case 0x082: /* V9 fmovdcc %fcc2 */
2734 case 0x083: /* V9 fmovqcc %fcc2 */
2735 #if defined(CONFIG_USER_ONLY)
2741 case 0x0c1: /* V9 fmovscc %fcc3 */
2744 case 0x0c2: /* V9 fmovdcc %fcc3 */
2747 case 0x0c3: /* V9 fmovqcc %fcc3 */
2748 #if defined(CONFIG_USER_ONLY)
2755 #define FMOVCC(size_FDQ, icc) \
2760 l1 = gen_new_label(); \
2761 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2762 cond = GET_FIELD_SP(insn, 14, 17); \
2763 gen_cond(r_cond, icc, cond); \
2764 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2765 tcg_const_tl(0), l1); \
2766 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2767 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2768 gen_set_label(l1); \
2769 tcg_gen_discard_tl(r_cond); \
2772 case 0x101: /* V9 fmovscc %icc */
2775 case 0x102: /* V9 fmovdcc %icc */
2777 case 0x103: /* V9 fmovqcc %icc */
2778 #if defined(CONFIG_USER_ONLY)
2784 case 0x181: /* V9 fmovscc %xcc */
2787 case 0x182: /* V9 fmovdcc %xcc */
2790 case 0x183: /* V9 fmovqcc %xcc */
2791 #if defined(CONFIG_USER_ONLY)
2799 case 0x51: /* fcmps, V9 %fcc */
2800 gen_op_load_fpr_FT0(rs1);
2801 gen_op_load_fpr_FT1(rs2);
2802 gen_op_fcmps(rd & 3);
2804 case 0x52: /* fcmpd, V9 %fcc */
2805 gen_op_load_fpr_DT0(DFPREG(rs1));
2806 gen_op_load_fpr_DT1(DFPREG(rs2));
2807 gen_op_fcmpd(rd & 3);
2809 case 0x53: /* fcmpq, V9 %fcc */
2810 #if defined(CONFIG_USER_ONLY)
2811 gen_op_load_fpr_QT0(QFPREG(rs1));
2812 gen_op_load_fpr_QT1(QFPREG(rs2));
2813 gen_op_fcmpq(rd & 3);
2815 #else /* !defined(CONFIG_USER_ONLY) */
2818 case 0x55: /* fcmpes, V9 %fcc */
2819 gen_op_load_fpr_FT0(rs1);
2820 gen_op_load_fpr_FT1(rs2);
2821 gen_op_fcmpes(rd & 3);
2823 case 0x56: /* fcmped, V9 %fcc */
2824 gen_op_load_fpr_DT0(DFPREG(rs1));
2825 gen_op_load_fpr_DT1(DFPREG(rs2));
2826 gen_op_fcmped(rd & 3);
2828 case 0x57: /* fcmpeq, V9 %fcc */
2829 #if defined(CONFIG_USER_ONLY)
2830 gen_op_load_fpr_QT0(QFPREG(rs1));
2831 gen_op_load_fpr_QT1(QFPREG(rs2));
2832 gen_op_fcmpeq(rd & 3);
2834 #else/* !defined(CONFIG_USER_ONLY) */
2841 } else if (xop == 0x2) {
2844 rs1 = GET_FIELD(insn, 13, 17);
2846 // or %g0, x, y -> mov T0, x; mov y, T0
2847 if (IS_IMM) { /* immediate */
2848 rs2 = GET_FIELDs(insn, 19, 31);
2849 tcg_gen_movi_tl(cpu_T[0], (int)rs2);
2850 } else { /* register */
2851 rs2 = GET_FIELD(insn, 27, 31);
2852 gen_movl_reg_T0(rs2);
2855 gen_movl_reg_T0(rs1);
2856 if (IS_IMM) { /* immediate */
2857 rs2 = GET_FIELDs(insn, 19, 31);
2858 tcg_gen_ori_tl(cpu_T[0], cpu_T[0], (int)rs2);
2859 } else { /* register */
2860 // or x, %g0, y -> mov T1, x; mov y, T1
2861 rs2 = GET_FIELD(insn, 27, 31);
2863 gen_movl_reg_T1(rs2);
2868 gen_movl_T0_reg(rd);
2870 #ifdef TARGET_SPARC64
2871 } else if (xop == 0x25) { /* sll, V9 sllx */
2872 rs1 = GET_FIELD(insn, 13, 17);
2873 gen_movl_reg_T0(rs1);
2874 if (IS_IMM) { /* immediate */
2875 rs2 = GET_FIELDs(insn, 20, 31);
2876 if (insn & (1 << 12)) {
2877 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f);
2879 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2880 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f);
2882 } else { /* register */
2883 rs2 = GET_FIELD(insn, 27, 31);
2884 gen_movl_reg_T1(rs2);
2885 if (insn & (1 << 12)) {
2886 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f);
2887 tcg_gen_shl_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2889 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f);
2890 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2891 tcg_gen_shl_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2894 gen_movl_T0_reg(rd);
2895 } else if (xop == 0x26) { /* srl, V9 srlx */
2896 rs1 = GET_FIELD(insn, 13, 17);
2897 gen_movl_reg_T0(rs1);
2898 if (IS_IMM) { /* immediate */
2899 rs2 = GET_FIELDs(insn, 20, 31);
2900 if (insn & (1 << 12)) {
2901 tcg_gen_shri_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f);
2903 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2904 tcg_gen_shri_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f);
2906 } else { /* register */
2907 rs2 = GET_FIELD(insn, 27, 31);
2908 gen_movl_reg_T1(rs2);
2909 if (insn & (1 << 12)) {
2910 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f);
2911 tcg_gen_shr_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2913 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f);
2914 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2915 tcg_gen_shr_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2918 gen_movl_T0_reg(rd);
2919 } else if (xop == 0x27) { /* sra, V9 srax */
2920 rs1 = GET_FIELD(insn, 13, 17);
2921 gen_movl_reg_T0(rs1);
2922 if (IS_IMM) { /* immediate */
2923 rs2 = GET_FIELDs(insn, 20, 31);
2924 if (insn & (1 << 12)) {
2925 tcg_gen_sari_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f);
2927 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2928 tcg_gen_ext_i32_i64(cpu_T[0], cpu_T[0]);
2929 tcg_gen_sari_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f);
2931 } else { /* register */
2932 rs2 = GET_FIELD(insn, 27, 31);
2933 gen_movl_reg_T1(rs2);
2934 if (insn & (1 << 12)) {
2935 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f);
2936 tcg_gen_sar_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2938 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f);
2939 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2940 tcg_gen_sar_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2943 gen_movl_T0_reg(rd);
2945 } else if (xop < 0x36) {
2946 rs1 = GET_FIELD(insn, 13, 17);
2947 gen_movl_reg_T0(rs1);
2948 if (IS_IMM) { /* immediate */
2949 rs2 = GET_FIELDs(insn, 19, 31);
2950 gen_movl_simm_T1(rs2);
2951 } else { /* register */
2952 rs2 = GET_FIELD(insn, 27, 31);
2953 gen_movl_reg_T1(rs2);
2956 switch (xop & ~0x10) {
2959 gen_op_add_T1_T0_cc();
2964 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2966 gen_op_logic_T0_cc();
2969 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2971 gen_op_logic_T0_cc();
2974 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2976 gen_op_logic_T0_cc();
2980 gen_op_sub_T1_T0_cc();
2982 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2985 tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1);
2986 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2988 gen_op_logic_T0_cc();
2991 tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1);
2992 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2994 gen_op_logic_T0_cc();
2997 tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1);
2998 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3000 gen_op_logic_T0_cc();
3004 gen_op_addx_T1_T0_cc();
3006 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3007 tcg_gen_add_tl(cpu_T[1], cpu_T[1], cpu_tmp0);
3008 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3011 #ifdef TARGET_SPARC64
3012 case 0x9: /* V9 mulx */
3013 tcg_gen_mul_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
3017 gen_op_umul_T1_T0();
3019 gen_op_logic_T0_cc();
3022 gen_op_smul_T1_T0();
3024 gen_op_logic_T0_cc();
3028 gen_op_subx_T1_T0_cc();
3030 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3031 tcg_gen_add_tl(cpu_T[1], cpu_T[1], cpu_tmp0);
3032 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3035 #ifdef TARGET_SPARC64
3036 case 0xd: /* V9 udivx */
3037 gen_trap_ifdivzero_i64(cpu_T[1]);
3038 tcg_gen_divu_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
3042 gen_op_udiv_T1_T0();
3047 gen_op_sdiv_T1_T0();
3054 gen_movl_T0_reg(rd);
3057 case 0x20: /* taddcc */
3058 gen_op_tadd_T1_T0_cc();
3059 gen_movl_T0_reg(rd);
3061 case 0x21: /* tsubcc */
3062 gen_op_tsub_T1_T0_cc();
3063 gen_movl_T0_reg(rd);
3065 case 0x22: /* taddcctv */
3067 gen_op_tadd_T1_T0_ccTV();
3068 gen_movl_T0_reg(rd);
3070 case 0x23: /* tsubcctv */
3072 gen_op_tsub_T1_T0_ccTV();
3073 gen_movl_T0_reg(rd);
3075 case 0x24: /* mulscc */
3076 gen_op_mulscc_T1_T0();
3077 gen_movl_T0_reg(rd);
3079 #ifndef TARGET_SPARC64
3080 case 0x25: /* sll */
3081 tcg_gen_andi_i32(cpu_T[1], cpu_T[1], 0x1f);
3082 tcg_gen_shl_i32(cpu_T[0], cpu_T[0], cpu_T[1]);
3083 gen_movl_T0_reg(rd);
3085 case 0x26: /* srl */
3086 tcg_gen_andi_i32(cpu_T[1], cpu_T[1], 0x1f);
3087 tcg_gen_shr_i32(cpu_T[0], cpu_T[0], cpu_T[1]);
3088 gen_movl_T0_reg(rd);
3090 case 0x27: /* sra */
3091 tcg_gen_andi_i32(cpu_T[1], cpu_T[1], 0x1f);
3092 tcg_gen_sar_i32(cpu_T[0], cpu_T[0], cpu_T[1]);
3093 gen_movl_T0_reg(rd);
3101 gen_op_movtl_env_T0(offsetof(CPUSPARCState, y));
3103 #ifndef TARGET_SPARC64
3104 case 0x01 ... 0x0f: /* undefined in the
3108 case 0x10 ... 0x1f: /* implementation-dependent
3114 case 0x2: /* V9 wrccr */
3116 tcg_gen_helper_0_1(helper_wrccr, cpu_T[0]);
3118 case 0x3: /* V9 wrasi */
3120 gen_op_movl_env_T0(offsetof(CPUSPARCState, asi));
3122 case 0x6: /* V9 wrfprs */
3124 gen_op_movl_env_T0(offsetof(CPUSPARCState, fprs));
3130 case 0xf: /* V9 sir, nop if user */
3131 #if !defined(CONFIG_USER_ONLY)
3136 case 0x13: /* Graphics Status */
3137 if (gen_trap_ifnofpu(dc))
3140 gen_op_movtl_env_T0(offsetof(CPUSPARCState, gsr));
3142 case 0x17: /* Tick compare */
3143 #if !defined(CONFIG_USER_ONLY)
3144 if (!supervisor(dc))
3151 gen_op_movtl_env_T0(offsetof(CPUSPARCState,
3153 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3154 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3155 offsetof(CPUState, tick));
3156 tcg_gen_helper_0_2(helper_tick_set_limit,
3157 r_tickptr, cpu_T[0]);
3158 tcg_gen_discard_ptr(r_tickptr);
3161 case 0x18: /* System tick */
3162 #if !defined(CONFIG_USER_ONLY)
3163 if (!supervisor(dc))
3170 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3171 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3172 offsetof(CPUState, stick));
3173 tcg_gen_helper_0_2(helper_tick_set_count,
3174 r_tickptr, cpu_T[0]);
3175 tcg_gen_discard_ptr(r_tickptr);
3178 case 0x19: /* System tick compare */
3179 #if !defined(CONFIG_USER_ONLY)
3180 if (!supervisor(dc))
3187 gen_op_movtl_env_T0(offsetof(CPUSPARCState,
3189 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3190 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3191 offsetof(CPUState, stick));
3192 tcg_gen_helper_0_2(helper_tick_set_limit,
3193 r_tickptr, cpu_T[0]);
3194 tcg_gen_discard_ptr(r_tickptr);
3198 case 0x10: /* Performance Control */
3199 case 0x11: /* Performance Instrumentation Counter */
3200 case 0x12: /* Dispatch Control */
3201 case 0x14: /* Softint set */
3202 case 0x15: /* Softint clear */
3203 case 0x16: /* Softint write */
3210 #if !defined(CONFIG_USER_ONLY)
3211 case 0x31: /* wrpsr, V9 saved, restored */
3213 if (!supervisor(dc))
3215 #ifdef TARGET_SPARC64
3223 case 2: /* UA2005 allclean */
3224 case 3: /* UA2005 otherw */
3225 case 4: /* UA2005 normalw */
3226 case 5: /* UA2005 invalw */
3233 tcg_gen_helper_0_1(helper_wrpsr, cpu_T[0]);
3241 case 0x32: /* wrwim, V9 wrpr */
3243 if (!supervisor(dc))
3246 #ifdef TARGET_SPARC64
3252 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3253 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3254 offsetof(CPUState, tsptr));
3255 tcg_gen_st_tl(cpu_T[0], r_tsptr,
3256 offsetof(trap_state, tpc));
3257 tcg_gen_discard_ptr(r_tsptr);
3264 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3265 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3266 offsetof(CPUState, tsptr));
3267 tcg_gen_st_tl(cpu_T[0], r_tsptr,
3268 offsetof(trap_state, tnpc));
3269 tcg_gen_discard_ptr(r_tsptr);
3276 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3277 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3278 offsetof(CPUState, tsptr));
3279 tcg_gen_st_tl(cpu_T[0], r_tsptr,
3280 offsetof(trap_state, tstate));
3281 tcg_gen_discard_ptr(r_tsptr);
3288 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3289 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3290 offsetof(CPUState, tsptr));
3291 tcg_gen_st_i32(cpu_T[0], r_tsptr,
3292 offsetof(trap_state, tt));
3293 tcg_gen_discard_ptr(r_tsptr);
3300 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3301 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3302 offsetof(CPUState, tick));
3303 tcg_gen_helper_0_2(helper_tick_set_count,
3304 r_tickptr, cpu_T[0]);
3305 tcg_gen_discard_ptr(r_tickptr);
3309 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr));
3313 tcg_gen_helper_0_1(helper_wrpstate, cpu_T[0]);
3319 gen_op_movl_env_T0(offsetof(CPUSPARCState, tl));
3322 gen_op_movl_env_T0(offsetof(CPUSPARCState, psrpil));
3325 tcg_gen_helper_0_1(helper_wrcwp, cpu_T[0]);
3328 gen_op_movl_env_T0(offsetof(CPUSPARCState, cansave));
3330 case 11: // canrestore
3331 gen_op_movl_env_T0(offsetof(CPUSPARCState, canrestore));
3333 case 12: // cleanwin
3334 gen_op_movl_env_T0(offsetof(CPUSPARCState, cleanwin));
3336 case 13: // otherwin
3337 gen_op_movl_env_T0(offsetof(CPUSPARCState, otherwin));
3340 gen_op_movl_env_T0(offsetof(CPUSPARCState, wstate));
3342 case 16: // UA2005 gl
3343 gen_op_movl_env_T0(offsetof(CPUSPARCState, gl));
3345 case 26: // UA2005 strand status
3346 if (!hypervisor(dc))
3348 gen_op_movl_env_T0(offsetof(CPUSPARCState, ssr));
3354 tcg_gen_andi_i32(cpu_T[0], cpu_T[0], ((1 << NWINDOWS) - 1));
3355 gen_op_movl_env_T0(offsetof(CPUSPARCState, wim));
3359 case 0x33: /* wrtbr, UA2005 wrhpr */
3361 #ifndef TARGET_SPARC64
3362 if (!supervisor(dc))
3365 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr));
3367 if (!hypervisor(dc))
3372 // XXX gen_op_wrhpstate();
3379 // XXX gen_op_wrhtstate();
3382 gen_op_movl_env_T0(offsetof(CPUSPARCState, hintp));
3385 gen_op_movl_env_T0(offsetof(CPUSPARCState, htba));
3387 case 31: // hstick_cmpr
3391 gen_op_movtl_env_T0(offsetof(CPUSPARCState,
3393 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3394 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3395 offsetof(CPUState, hstick));
3396 tcg_gen_helper_0_2(helper_tick_set_limit,
3397 r_tickptr, cpu_T[0]);
3398 tcg_gen_discard_ptr(r_tickptr);
3401 case 6: // hver readonly
3409 #ifdef TARGET_SPARC64
3410 case 0x2c: /* V9 movcc */
3412 int cc = GET_FIELD_SP(insn, 11, 12);
3413 int cond = GET_FIELD_SP(insn, 14, 17);
3417 r_cond = tcg_temp_new(TCG_TYPE_TL);
3418 if (insn & (1 << 18)) {
3420 gen_cond(r_cond, 0, cond);
3422 gen_cond(r_cond, 1, cond);
3426 gen_fcond(r_cond, cc, cond);
3429 l1 = gen_new_label();
3431 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond,
3432 tcg_const_tl(0), l1);
3433 if (IS_IMM) { /* immediate */
3434 rs2 = GET_FIELD_SPs(insn, 0, 10);
3435 gen_movl_simm_T1(rs2);
3437 rs2 = GET_FIELD_SP(insn, 0, 4);
3438 gen_movl_reg_T1(rs2);
3440 gen_movl_T1_reg(rd);
3442 tcg_gen_discard_tl(r_cond);
3445 case 0x2d: /* V9 sdivx */
3446 gen_op_sdivx_T1_T0();
3447 gen_movl_T0_reg(rd);
3449 case 0x2e: /* V9 popc */
3451 if (IS_IMM) { /* immediate */
3452 rs2 = GET_FIELD_SPs(insn, 0, 12);
3453 gen_movl_simm_T1(rs2);
3454 // XXX optimize: popc(constant)
3457 rs2 = GET_FIELD_SP(insn, 0, 4);
3458 gen_movl_reg_T1(rs2);
3460 tcg_gen_helper_1_1(helper_popc, cpu_T[0],
3462 gen_movl_T0_reg(rd);
3464 case 0x2f: /* V9 movr */
3466 int cond = GET_FIELD_SP(insn, 10, 12);
3469 rs1 = GET_FIELD(insn, 13, 17);
3470 gen_movl_reg_T0(rs1);
3472 l1 = gen_new_label();
3474 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
3475 tcg_const_tl(0), l1);
3476 if (IS_IMM) { /* immediate */
3477 rs2 = GET_FIELD_SPs(insn, 0, 9);
3478 gen_movl_simm_T1(rs2);
3480 rs2 = GET_FIELD_SP(insn, 0, 4);
3481 gen_movl_reg_T1(rs2);
3483 gen_movl_T1_reg(rd);
3492 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3493 #ifdef TARGET_SPARC64
3494 int opf = GET_FIELD_SP(insn, 5, 13);
3495 rs1 = GET_FIELD(insn, 13, 17);
3496 rs2 = GET_FIELD(insn, 27, 31);
3497 if (gen_trap_ifnofpu(dc))
3501 case 0x000: /* VIS I edge8cc */
3502 case 0x001: /* VIS II edge8n */
3503 case 0x002: /* VIS I edge8lcc */
3504 case 0x003: /* VIS II edge8ln */
3505 case 0x004: /* VIS I edge16cc */
3506 case 0x005: /* VIS II edge16n */
3507 case 0x006: /* VIS I edge16lcc */
3508 case 0x007: /* VIS II edge16ln */
3509 case 0x008: /* VIS I edge32cc */
3510 case 0x009: /* VIS II edge32n */
3511 case 0x00a: /* VIS I edge32lcc */
3512 case 0x00b: /* VIS II edge32ln */
3515 case 0x010: /* VIS I array8 */
3516 gen_movl_reg_T0(rs1);
3517 gen_movl_reg_T1(rs2);
3518 tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0],
3520 gen_movl_T0_reg(rd);
3522 case 0x012: /* VIS I array16 */
3523 gen_movl_reg_T0(rs1);
3524 gen_movl_reg_T1(rs2);
3525 tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0],
3527 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], 1);
3528 gen_movl_T0_reg(rd);
3530 case 0x014: /* VIS I array32 */
3531 gen_movl_reg_T0(rs1);
3532 gen_movl_reg_T1(rs2);
3533 tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0],
3535 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], 2);
3536 gen_movl_T0_reg(rd);
3538 case 0x018: /* VIS I alignaddr */
3539 gen_movl_reg_T0(rs1);
3540 gen_movl_reg_T1(rs2);
3541 tcg_gen_helper_1_2(helper_alignaddr, cpu_T[0], cpu_T[0],
3543 gen_movl_T0_reg(rd);
3545 case 0x019: /* VIS II bmask */
3546 case 0x01a: /* VIS I alignaddrl */
3549 case 0x020: /* VIS I fcmple16 */
3550 gen_op_load_fpr_DT0(DFPREG(rs1));
3551 gen_op_load_fpr_DT1(DFPREG(rs2));
3553 gen_op_store_DT0_fpr(DFPREG(rd));
3555 case 0x022: /* VIS I fcmpne16 */
3556 gen_op_load_fpr_DT0(DFPREG(rs1));
3557 gen_op_load_fpr_DT1(DFPREG(rs2));
3559 gen_op_store_DT0_fpr(DFPREG(rd));
3561 case 0x024: /* VIS I fcmple32 */
3562 gen_op_load_fpr_DT0(DFPREG(rs1));
3563 gen_op_load_fpr_DT1(DFPREG(rs2));
3565 gen_op_store_DT0_fpr(DFPREG(rd));
3567 case 0x026: /* VIS I fcmpne32 */
3568 gen_op_load_fpr_DT0(DFPREG(rs1));
3569 gen_op_load_fpr_DT1(DFPREG(rs2));
3571 gen_op_store_DT0_fpr(DFPREG(rd));
3573 case 0x028: /* VIS I fcmpgt16 */
3574 gen_op_load_fpr_DT0(DFPREG(rs1));
3575 gen_op_load_fpr_DT1(DFPREG(rs2));
3577 gen_op_store_DT0_fpr(DFPREG(rd));
3579 case 0x02a: /* VIS I fcmpeq16 */
3580 gen_op_load_fpr_DT0(DFPREG(rs1));
3581 gen_op_load_fpr_DT1(DFPREG(rs2));
3583 gen_op_store_DT0_fpr(DFPREG(rd));
3585 case 0x02c: /* VIS I fcmpgt32 */
3586 gen_op_load_fpr_DT0(DFPREG(rs1));
3587 gen_op_load_fpr_DT1(DFPREG(rs2));
3589 gen_op_store_DT0_fpr(DFPREG(rd));
3591 case 0x02e: /* VIS I fcmpeq32 */
3592 gen_op_load_fpr_DT0(DFPREG(rs1));
3593 gen_op_load_fpr_DT1(DFPREG(rs2));
3595 gen_op_store_DT0_fpr(DFPREG(rd));
3597 case 0x031: /* VIS I fmul8x16 */
3598 gen_op_load_fpr_DT0(DFPREG(rs1));
3599 gen_op_load_fpr_DT1(DFPREG(rs2));
3601 gen_op_store_DT0_fpr(DFPREG(rd));
3603 case 0x033: /* VIS I fmul8x16au */
3604 gen_op_load_fpr_DT0(DFPREG(rs1));
3605 gen_op_load_fpr_DT1(DFPREG(rs2));
3606 gen_op_fmul8x16au();
3607 gen_op_store_DT0_fpr(DFPREG(rd));
3609 case 0x035: /* VIS I fmul8x16al */
3610 gen_op_load_fpr_DT0(DFPREG(rs1));
3611 gen_op_load_fpr_DT1(DFPREG(rs2));
3612 gen_op_fmul8x16al();
3613 gen_op_store_DT0_fpr(DFPREG(rd));
3615 case 0x036: /* VIS I fmul8sux16 */
3616 gen_op_load_fpr_DT0(DFPREG(rs1));
3617 gen_op_load_fpr_DT1(DFPREG(rs2));
3618 gen_op_fmul8sux16();
3619 gen_op_store_DT0_fpr(DFPREG(rd));
3621 case 0x037: /* VIS I fmul8ulx16 */
3622 gen_op_load_fpr_DT0(DFPREG(rs1));
3623 gen_op_load_fpr_DT1(DFPREG(rs2));
3624 gen_op_fmul8ulx16();
3625 gen_op_store_DT0_fpr(DFPREG(rd));
3627 case 0x038: /* VIS I fmuld8sux16 */
3628 gen_op_load_fpr_DT0(DFPREG(rs1));
3629 gen_op_load_fpr_DT1(DFPREG(rs2));
3630 gen_op_fmuld8sux16();
3631 gen_op_store_DT0_fpr(DFPREG(rd));
3633 case 0x039: /* VIS I fmuld8ulx16 */
3634 gen_op_load_fpr_DT0(DFPREG(rs1));
3635 gen_op_load_fpr_DT1(DFPREG(rs2));
3636 gen_op_fmuld8ulx16();
3637 gen_op_store_DT0_fpr(DFPREG(rd));
3639 case 0x03a: /* VIS I fpack32 */
3640 case 0x03b: /* VIS I fpack16 */
3641 case 0x03d: /* VIS I fpackfix */
3642 case 0x03e: /* VIS I pdist */
3645 case 0x048: /* VIS I faligndata */
3646 gen_op_load_fpr_DT0(DFPREG(rs1));
3647 gen_op_load_fpr_DT1(DFPREG(rs2));
3648 gen_op_faligndata();
3649 gen_op_store_DT0_fpr(DFPREG(rd));
3651 case 0x04b: /* VIS I fpmerge */
3652 gen_op_load_fpr_DT0(DFPREG(rs1));
3653 gen_op_load_fpr_DT1(DFPREG(rs2));
3655 gen_op_store_DT0_fpr(DFPREG(rd));
3657 case 0x04c: /* VIS II bshuffle */
3660 case 0x04d: /* VIS I fexpand */
3661 gen_op_load_fpr_DT0(DFPREG(rs1));
3662 gen_op_load_fpr_DT1(DFPREG(rs2));
3664 gen_op_store_DT0_fpr(DFPREG(rd));
3666 case 0x050: /* VIS I fpadd16 */
3667 gen_op_load_fpr_DT0(DFPREG(rs1));
3668 gen_op_load_fpr_DT1(DFPREG(rs2));
3670 gen_op_store_DT0_fpr(DFPREG(rd));
3672 case 0x051: /* VIS I fpadd16s */
3673 gen_op_load_fpr_FT0(rs1);
3674 gen_op_load_fpr_FT1(rs2);
3676 gen_op_store_FT0_fpr(rd);
3678 case 0x052: /* VIS I fpadd32 */
3679 gen_op_load_fpr_DT0(DFPREG(rs1));
3680 gen_op_load_fpr_DT1(DFPREG(rs2));
3682 gen_op_store_DT0_fpr(DFPREG(rd));
3684 case 0x053: /* VIS I fpadd32s */
3685 gen_op_load_fpr_FT0(rs1);
3686 gen_op_load_fpr_FT1(rs2);
3688 gen_op_store_FT0_fpr(rd);
3690 case 0x054: /* VIS I fpsub16 */
3691 gen_op_load_fpr_DT0(DFPREG(rs1));
3692 gen_op_load_fpr_DT1(DFPREG(rs2));
3694 gen_op_store_DT0_fpr(DFPREG(rd));
3696 case 0x055: /* VIS I fpsub16s */
3697 gen_op_load_fpr_FT0(rs1);
3698 gen_op_load_fpr_FT1(rs2);
3700 gen_op_store_FT0_fpr(rd);
3702 case 0x056: /* VIS I fpsub32 */
3703 gen_op_load_fpr_DT0(DFPREG(rs1));
3704 gen_op_load_fpr_DT1(DFPREG(rs2));
3706 gen_op_store_DT0_fpr(DFPREG(rd));
3708 case 0x057: /* VIS I fpsub32s */
3709 gen_op_load_fpr_FT0(rs1);
3710 gen_op_load_fpr_FT1(rs2);
3712 gen_op_store_FT0_fpr(rd);
3714 case 0x060: /* VIS I fzero */
3715 gen_op_movl_DT0_0();
3716 gen_op_store_DT0_fpr(DFPREG(rd));
3718 case 0x061: /* VIS I fzeros */
3719 gen_op_movl_FT0_0();
3720 gen_op_store_FT0_fpr(rd);
3722 case 0x062: /* VIS I fnor */
3723 gen_op_load_fpr_DT0(DFPREG(rs1));
3724 gen_op_load_fpr_DT1(DFPREG(rs2));
3726 gen_op_store_DT0_fpr(DFPREG(rd));
3728 case 0x063: /* VIS I fnors */
3729 gen_op_load_fpr_FT0(rs1);
3730 gen_op_load_fpr_FT1(rs2);
3732 gen_op_store_FT0_fpr(rd);
3734 case 0x064: /* VIS I fandnot2 */
3735 gen_op_load_fpr_DT1(DFPREG(rs1));
3736 gen_op_load_fpr_DT0(DFPREG(rs2));
3738 gen_op_store_DT0_fpr(DFPREG(rd));
3740 case 0x065: /* VIS I fandnot2s */
3741 gen_op_load_fpr_FT1(rs1);
3742 gen_op_load_fpr_FT0(rs2);
3744 gen_op_store_FT0_fpr(rd);
3746 case 0x066: /* VIS I fnot2 */
3747 gen_op_load_fpr_DT1(DFPREG(rs2));
3749 gen_op_store_DT0_fpr(DFPREG(rd));
3751 case 0x067: /* VIS I fnot2s */
3752 gen_op_load_fpr_FT1(rs2);
3754 gen_op_store_FT0_fpr(rd);
3756 case 0x068: /* VIS I fandnot1 */
3757 gen_op_load_fpr_DT0(DFPREG(rs1));
3758 gen_op_load_fpr_DT1(DFPREG(rs2));
3760 gen_op_store_DT0_fpr(DFPREG(rd));
3762 case 0x069: /* VIS I fandnot1s */
3763 gen_op_load_fpr_FT0(rs1);
3764 gen_op_load_fpr_FT1(rs2);
3766 gen_op_store_FT0_fpr(rd);
3768 case 0x06a: /* VIS I fnot1 */
3769 gen_op_load_fpr_DT1(DFPREG(rs1));
3771 gen_op_store_DT0_fpr(DFPREG(rd));
3773 case 0x06b: /* VIS I fnot1s */
3774 gen_op_load_fpr_FT1(rs1);
3776 gen_op_store_FT0_fpr(rd);
3778 case 0x06c: /* VIS I fxor */
3779 gen_op_load_fpr_DT0(DFPREG(rs1));
3780 gen_op_load_fpr_DT1(DFPREG(rs2));
3782 gen_op_store_DT0_fpr(DFPREG(rd));
3784 case 0x06d: /* VIS I fxors */
3785 gen_op_load_fpr_FT0(rs1);
3786 gen_op_load_fpr_FT1(rs2);
3788 gen_op_store_FT0_fpr(rd);
3790 case 0x06e: /* VIS I fnand */
3791 gen_op_load_fpr_DT0(DFPREG(rs1));
3792 gen_op_load_fpr_DT1(DFPREG(rs2));
3794 gen_op_store_DT0_fpr(DFPREG(rd));
3796 case 0x06f: /* VIS I fnands */
3797 gen_op_load_fpr_FT0(rs1);
3798 gen_op_load_fpr_FT1(rs2);
3800 gen_op_store_FT0_fpr(rd);
3802 case 0x070: /* VIS I fand */
3803 gen_op_load_fpr_DT0(DFPREG(rs1));
3804 gen_op_load_fpr_DT1(DFPREG(rs2));
3806 gen_op_store_DT0_fpr(DFPREG(rd));
3808 case 0x071: /* VIS I fands */
3809 gen_op_load_fpr_FT0(rs1);
3810 gen_op_load_fpr_FT1(rs2);
3812 gen_op_store_FT0_fpr(rd);
3814 case 0x072: /* VIS I fxnor */
3815 gen_op_load_fpr_DT0(DFPREG(rs1));
3816 gen_op_load_fpr_DT1(DFPREG(rs2));
3818 gen_op_store_DT0_fpr(DFPREG(rd));
3820 case 0x073: /* VIS I fxnors */
3821 gen_op_load_fpr_FT0(rs1);
3822 gen_op_load_fpr_FT1(rs2);
3824 gen_op_store_FT0_fpr(rd);
3826 case 0x074: /* VIS I fsrc1 */
3827 gen_op_load_fpr_DT0(DFPREG(rs1));
3828 gen_op_store_DT0_fpr(DFPREG(rd));
3830 case 0x075: /* VIS I fsrc1s */
3831 gen_op_load_fpr_FT0(rs1);
3832 gen_op_store_FT0_fpr(rd);
3834 case 0x076: /* VIS I fornot2 */
3835 gen_op_load_fpr_DT1(DFPREG(rs1));
3836 gen_op_load_fpr_DT0(DFPREG(rs2));
3838 gen_op_store_DT0_fpr(DFPREG(rd));
3840 case 0x077: /* VIS I fornot2s */
3841 gen_op_load_fpr_FT1(rs1);
3842 gen_op_load_fpr_FT0(rs2);
3844 gen_op_store_FT0_fpr(rd);
3846 case 0x078: /* VIS I fsrc2 */
3847 gen_op_load_fpr_DT0(DFPREG(rs2));
3848 gen_op_store_DT0_fpr(DFPREG(rd));
3850 case 0x079: /* VIS I fsrc2s */
3851 gen_op_load_fpr_FT0(rs2);
3852 gen_op_store_FT0_fpr(rd);
3854 case 0x07a: /* VIS I fornot1 */
3855 gen_op_load_fpr_DT0(DFPREG(rs1));
3856 gen_op_load_fpr_DT1(DFPREG(rs2));
3858 gen_op_store_DT0_fpr(DFPREG(rd));
3860 case 0x07b: /* VIS I fornot1s */
3861 gen_op_load_fpr_FT0(rs1);
3862 gen_op_load_fpr_FT1(rs2);
3864 gen_op_store_FT0_fpr(rd);
3866 case 0x07c: /* VIS I for */
3867 gen_op_load_fpr_DT0(DFPREG(rs1));
3868 gen_op_load_fpr_DT1(DFPREG(rs2));
3870 gen_op_store_DT0_fpr(DFPREG(rd));
3872 case 0x07d: /* VIS I fors */
3873 gen_op_load_fpr_FT0(rs1);
3874 gen_op_load_fpr_FT1(rs2);
3876 gen_op_store_FT0_fpr(rd);
3878 case 0x07e: /* VIS I fone */
3879 gen_op_movl_DT0_1();
3880 gen_op_store_DT0_fpr(DFPREG(rd));
3882 case 0x07f: /* VIS I fones */
3883 gen_op_movl_FT0_1();
3884 gen_op_store_FT0_fpr(rd);
3886 case 0x080: /* VIS I shutdown */
3887 case 0x081: /* VIS II siam */
3896 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
3897 #ifdef TARGET_SPARC64
3902 #ifdef TARGET_SPARC64
3903 } else if (xop == 0x39) { /* V9 return */
3904 rs1 = GET_FIELD(insn, 13, 17);
3906 gen_movl_reg_T0(rs1);
3907 if (IS_IMM) { /* immediate */
3908 rs2 = GET_FIELDs(insn, 19, 31);
3909 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2);
3910 } else { /* register */
3911 rs2 = GET_FIELD(insn, 27, 31);
3915 gen_movl_reg_T1(rs2);
3923 gen_op_check_align_T0_3();
3924 tcg_gen_mov_tl(cpu_npc, cpu_T[0]);
3925 dc->npc = DYNAMIC_PC;
3929 rs1 = GET_FIELD(insn, 13, 17);
3930 gen_movl_reg_T0(rs1);
3931 if (IS_IMM) { /* immediate */
3932 rs2 = GET_FIELDs(insn, 19, 31);
3933 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2);
3934 } else { /* register */
3935 rs2 = GET_FIELD(insn, 27, 31);
3939 gen_movl_reg_T1(rs2);
3946 case 0x38: /* jmpl */
3949 tcg_gen_movi_tl(cpu_T[1], dc->pc);
3950 gen_movl_T1_reg(rd);
3953 gen_op_check_align_T0_3();
3954 tcg_gen_mov_tl(cpu_npc, cpu_T[0]);
3955 dc->npc = DYNAMIC_PC;
3958 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
3959 case 0x39: /* rett, V9 return */
3961 if (!supervisor(dc))
3964 gen_op_check_align_T0_3();
3965 tcg_gen_mov_tl(cpu_npc, cpu_T[0]);
3966 dc->npc = DYNAMIC_PC;
3967 tcg_gen_helper_0_0(helper_rett);
3971 case 0x3b: /* flush */
3972 tcg_gen_helper_0_1(helper_flush, cpu_T[0]);
3974 case 0x3c: /* save */
3977 gen_movl_T0_reg(rd);
3979 case 0x3d: /* restore */
3982 gen_movl_T0_reg(rd);
3984 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
3985 case 0x3e: /* V9 done/retry */
3989 if (!supervisor(dc))
3991 dc->npc = DYNAMIC_PC;
3992 dc->pc = DYNAMIC_PC;
3993 tcg_gen_helper_0_0(helper_done);
3996 if (!supervisor(dc))
3998 dc->npc = DYNAMIC_PC;
3999 dc->pc = DYNAMIC_PC;
4000 tcg_gen_helper_0_0(helper_retry);
4015 case 3: /* load/store instructions */
4017 unsigned int xop = GET_FIELD(insn, 7, 12);
4018 rs1 = GET_FIELD(insn, 13, 17);
4020 gen_movl_reg_T0(rs1);
4021 if (xop == 0x3c || xop == 0x3e)
4023 rs2 = GET_FIELD(insn, 27, 31);
4024 gen_movl_reg_T1(rs2);
4026 else if (IS_IMM) { /* immediate */
4027 rs2 = GET_FIELDs(insn, 19, 31);
4028 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2);
4029 } else { /* register */
4030 rs2 = GET_FIELD(insn, 27, 31);
4034 gen_movl_reg_T1(rs2);
4040 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4041 (xop > 0x17 && xop <= 0x1d ) ||
4042 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4044 case 0x0: /* load unsigned word */
4045 gen_op_check_align_T0_3();
4046 ABI32_MASK(cpu_T[0]);
4047 tcg_gen_qemu_ld32u(cpu_T[1], cpu_T[0], dc->mem_idx);
4049 case 0x1: /* load unsigned byte */
4050 ABI32_MASK(cpu_T[0]);
4051 tcg_gen_qemu_ld8u(cpu_T[1], cpu_T[0], dc->mem_idx);
4053 case 0x2: /* load unsigned halfword */
4054 gen_op_check_align_T0_1();
4055 ABI32_MASK(cpu_T[0]);
4056 tcg_gen_qemu_ld16u(cpu_T[1], cpu_T[0], dc->mem_idx);
4058 case 0x3: /* load double word */
4064 r_dword = tcg_temp_new(TCG_TYPE_I64);
4065 gen_op_check_align_T0_7();
4066 ABI32_MASK(cpu_T[0]);
4067 tcg_gen_qemu_ld64(r_dword, cpu_T[0], dc->mem_idx);
4068 tcg_gen_trunc_i64_i32(cpu_T[0], r_dword);
4069 gen_movl_T0_reg(rd + 1);
4070 tcg_gen_shri_i64(r_dword, r_dword, 32);
4071 tcg_gen_trunc_i64_i32(cpu_T[1], r_dword);
4072 tcg_gen_discard_i64(r_dword);
4075 case 0x9: /* load signed byte */
4076 ABI32_MASK(cpu_T[0]);
4077 tcg_gen_qemu_ld8s(cpu_T[1], cpu_T[0], dc->mem_idx);
4079 case 0xa: /* load signed halfword */
4080 gen_op_check_align_T0_1();
4081 ABI32_MASK(cpu_T[0]);
4082 tcg_gen_qemu_ld16s(cpu_T[1], cpu_T[0], dc->mem_idx);
4084 case 0xd: /* ldstub -- XXX: should be atomically */
4085 tcg_gen_movi_i32(cpu_tmp0, 0xff);
4086 ABI32_MASK(cpu_T[0]);
4087 tcg_gen_qemu_ld8s(cpu_T[1], cpu_T[0], dc->mem_idx);
4088 tcg_gen_qemu_st8(cpu_tmp0, cpu_T[0], dc->mem_idx);
4090 case 0x0f: /* swap register with memory. Also atomically */
4091 gen_op_check_align_T0_3();
4092 gen_movl_reg_T1(rd);
4093 ABI32_MASK(cpu_T[0]);
4094 tcg_gen_qemu_ld32u(cpu_tmp0, cpu_T[0], dc->mem_idx);
4095 tcg_gen_qemu_st32(cpu_T[1], cpu_T[0], dc->mem_idx);
4096 tcg_gen_mov_i32(cpu_T[1], cpu_tmp0);
4098 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4099 case 0x10: /* load word alternate */
4100 #ifndef TARGET_SPARC64
4103 if (!supervisor(dc))
4106 gen_op_check_align_T0_3();
4107 gen_ld_asi(insn, 4, 0);
4109 case 0x11: /* load unsigned byte alternate */
4110 #ifndef TARGET_SPARC64
4113 if (!supervisor(dc))
4116 gen_ld_asi(insn, 1, 0);
4118 case 0x12: /* load unsigned halfword alternate */
4119 #ifndef TARGET_SPARC64
4122 if (!supervisor(dc))
4125 gen_op_check_align_T0_1();
4126 gen_ld_asi(insn, 2, 0);
4128 case 0x13: /* load double word alternate */
4129 #ifndef TARGET_SPARC64
4132 if (!supervisor(dc))
4137 gen_op_check_align_T0_7();
4139 gen_movl_T0_reg(rd + 1);
4141 case 0x19: /* load signed byte alternate */
4142 #ifndef TARGET_SPARC64
4145 if (!supervisor(dc))
4148 gen_ld_asi(insn, 1, 1);
4150 case 0x1a: /* load signed halfword alternate */
4151 #ifndef TARGET_SPARC64
4154 if (!supervisor(dc))
4157 gen_op_check_align_T0_1();
4158 gen_ld_asi(insn, 2, 1);
4160 case 0x1d: /* ldstuba -- XXX: should be atomically */
4161 #ifndef TARGET_SPARC64
4164 if (!supervisor(dc))
4167 gen_ldstub_asi(insn);
4169 case 0x1f: /* swap reg with alt. memory. Also atomically */
4170 #ifndef TARGET_SPARC64
4173 if (!supervisor(dc))
4176 gen_op_check_align_T0_3();
4177 gen_movl_reg_T1(rd);
4181 #ifndef TARGET_SPARC64
4182 case 0x30: /* ldc */
4183 case 0x31: /* ldcsr */
4184 case 0x33: /* lddc */
4188 #ifdef TARGET_SPARC64
4189 case 0x08: /* V9 ldsw */
4190 gen_op_check_align_T0_3();
4191 ABI32_MASK(cpu_T[0]);
4192 tcg_gen_qemu_ld32s(cpu_T[1], cpu_T[0], dc->mem_idx);
4194 case 0x0b: /* V9 ldx */
4195 gen_op_check_align_T0_7();
4196 ABI32_MASK(cpu_T[0]);
4197 tcg_gen_qemu_ld64(cpu_T[1], cpu_T[0], dc->mem_idx);
4199 case 0x18: /* V9 ldswa */
4200 gen_op_check_align_T0_3();
4201 gen_ld_asi(insn, 4, 1);
4203 case 0x1b: /* V9 ldxa */
4204 gen_op_check_align_T0_7();
4205 gen_ld_asi(insn, 8, 0);
4207 case 0x2d: /* V9 prefetch, no effect */
4209 case 0x30: /* V9 ldfa */
4210 gen_op_check_align_T0_3();
4211 gen_ldf_asi(insn, 4, rd);
4213 case 0x33: /* V9 lddfa */
4214 gen_op_check_align_T0_3();
4215 gen_ldf_asi(insn, 8, DFPREG(rd));
4217 case 0x3d: /* V9 prefetcha, no effect */
4219 case 0x32: /* V9 ldqfa */
4220 #if defined(CONFIG_USER_ONLY)
4221 gen_op_check_align_T0_3();
4222 gen_ldf_asi(insn, 16, QFPREG(rd));
4231 gen_movl_T1_reg(rd);
4232 #ifdef TARGET_SPARC64
4235 } else if (xop >= 0x20 && xop < 0x24) {
4236 if (gen_trap_ifnofpu(dc))
4239 case 0x20: /* load fpreg */
4240 gen_op_check_align_T0_3();
4242 gen_op_store_FT0_fpr(rd);
4244 case 0x21: /* load fsr */
4245 gen_op_check_align_T0_3();
4247 tcg_gen_helper_0_0(helper_ldfsr);
4249 case 0x22: /* load quad fpreg */
4250 #if defined(CONFIG_USER_ONLY)
4251 gen_op_check_align_T0_7();
4253 gen_op_store_QT0_fpr(QFPREG(rd));
4258 case 0x23: /* load double fpreg */
4259 gen_op_check_align_T0_7();
4261 gen_op_store_DT0_fpr(DFPREG(rd));
4266 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4267 xop == 0xe || xop == 0x1e) {
4268 gen_movl_reg_T1(rd);
4270 case 0x4: /* store word */
4271 gen_op_check_align_T0_3();
4272 ABI32_MASK(cpu_T[0]);
4273 tcg_gen_qemu_st32(cpu_T[1], cpu_T[0], dc->mem_idx);
4275 case 0x5: /* store byte */
4276 ABI32_MASK(cpu_T[0]);
4277 tcg_gen_qemu_st8(cpu_T[1], cpu_T[0], dc->mem_idx);
4279 case 0x6: /* store halfword */
4280 gen_op_check_align_T0_1();
4281 ABI32_MASK(cpu_T[0]);
4282 tcg_gen_qemu_st16(cpu_T[1], cpu_T[0], dc->mem_idx);
4284 case 0x7: /* store double word */
4289 TCGv r_dword, r_low;
4291 gen_op_check_align_T0_7();
4292 r_dword = tcg_temp_new(TCG_TYPE_I64);
4293 r_low = tcg_temp_new(TCG_TYPE_I32);
4294 gen_movl_reg_TN(rd + 1, r_low);
4295 tcg_gen_helper_1_2(helper_pack64, r_dword, cpu_T[1],
4297 tcg_gen_qemu_st64(r_dword, cpu_T[0], dc->mem_idx);
4298 tcg_gen_discard_i64(r_dword);
4300 #else /* __i386__ */
4301 gen_op_check_align_T0_7();
4303 gen_movl_reg_T2(rd + 1);
4305 #endif /* __i386__ */
4307 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4308 case 0x14: /* store word alternate */
4309 #ifndef TARGET_SPARC64
4312 if (!supervisor(dc))
4315 gen_op_check_align_T0_3();
4316 gen_st_asi(insn, 4);
4318 case 0x15: /* store byte alternate */
4319 #ifndef TARGET_SPARC64
4322 if (!supervisor(dc))
4325 gen_st_asi(insn, 1);
4327 case 0x16: /* store halfword alternate */
4328 #ifndef TARGET_SPARC64
4331 if (!supervisor(dc))
4334 gen_op_check_align_T0_1();
4335 gen_st_asi(insn, 2);
4337 case 0x17: /* store double word alternate */
4338 #ifndef TARGET_SPARC64
4341 if (!supervisor(dc))
4347 gen_op_check_align_T0_7();
4348 gen_stda_asi(insn, rd);
4352 #ifdef TARGET_SPARC64
4353 case 0x0e: /* V9 stx */
4354 gen_op_check_align_T0_7();
4355 ABI32_MASK(cpu_T[0]);
4356 tcg_gen_qemu_st64(cpu_T[1], cpu_T[0], dc->mem_idx);
4358 case 0x1e: /* V9 stxa */
4359 gen_op_check_align_T0_7();
4360 gen_st_asi(insn, 8);
4366 } else if (xop > 0x23 && xop < 0x28) {
4367 if (gen_trap_ifnofpu(dc))
4371 gen_op_check_align_T0_3();
4372 gen_op_load_fpr_FT0(rd);
4375 case 0x25: /* stfsr, V9 stxfsr */
4376 #ifdef CONFIG_USER_ONLY
4377 gen_op_check_align_T0_3();
4379 tcg_gen_helper_0_0(helper_stfsr);
4383 #ifdef TARGET_SPARC64
4384 #if defined(CONFIG_USER_ONLY)
4385 /* V9 stqf, store quad fpreg */
4386 gen_op_check_align_T0_7();
4387 gen_op_load_fpr_QT0(QFPREG(rd));
4393 #else /* !TARGET_SPARC64 */
4394 /* stdfq, store floating point queue */
4395 #if defined(CONFIG_USER_ONLY)
4398 if (!supervisor(dc))
4400 if (gen_trap_ifnofpu(dc))
4406 gen_op_check_align_T0_7();
4407 gen_op_load_fpr_DT0(DFPREG(rd));
4413 } else if (xop > 0x33 && xop < 0x3f) {
4415 #ifdef TARGET_SPARC64
4416 case 0x34: /* V9 stfa */
4417 gen_op_check_align_T0_3();
4418 gen_op_load_fpr_FT0(rd);
4419 gen_stf_asi(insn, 4, rd);
4421 case 0x36: /* V9 stqfa */
4422 #if defined(CONFIG_USER_ONLY)
4423 gen_op_check_align_T0_7();
4424 gen_op_load_fpr_QT0(QFPREG(rd));
4425 gen_stf_asi(insn, 16, QFPREG(rd));
4430 case 0x37: /* V9 stdfa */
4431 gen_op_check_align_T0_3();
4432 gen_op_load_fpr_DT0(DFPREG(rd));
4433 gen_stf_asi(insn, 8, DFPREG(rd));
4435 case 0x3c: /* V9 casa */
4436 gen_op_check_align_T0_3();
4437 gen_cas_asi(insn, rd);
4438 gen_movl_T1_reg(rd);
4440 case 0x3e: /* V9 casxa */
4441 gen_op_check_align_T0_7();
4442 gen_casx_asi(insn, rd);
4443 gen_movl_T1_reg(rd);
4446 case 0x34: /* stc */
4447 case 0x35: /* stcsr */
4448 case 0x36: /* stdcq */
4449 case 0x37: /* stdc */
4461 /* default case for non jump instructions */
4462 if (dc->npc == DYNAMIC_PC) {
4463 dc->pc = DYNAMIC_PC;
4465 } else if (dc->npc == JUMP_PC) {
4466 /* we can do a static jump */
4467 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
4471 dc->npc = dc->npc + 4;
4477 gen_op_exception(TT_ILL_INSN);
4480 #if !defined(CONFIG_USER_ONLY)
4483 gen_op_exception(TT_PRIV_INSN);
4488 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4491 #ifndef TARGET_SPARC64
4494 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4499 #ifndef TARGET_SPARC64
4502 gen_op_exception(TT_NCP_INSN);
4508 static void tcg_macro_func(TCGContext *s, int macro_id, const int *dead_args)
4512 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4513 int spc, CPUSPARCState *env)
4515 target_ulong pc_start, last_pc;
4516 uint16_t *gen_opc_end;
4517 DisasContext dc1, *dc = &dc1;
4520 memset(dc, 0, sizeof(DisasContext));
4525 dc->npc = (target_ulong) tb->cs_base;
4526 dc->mem_idx = cpu_mmu_index(env);
4527 dc->fpu_enabled = cpu_fpu_enabled(env);
4528 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4530 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4533 if (env->nb_breakpoints > 0) {
4534 for(j = 0; j < env->nb_breakpoints; j++) {
4535 if (env->breakpoints[j] == dc->pc) {
4536 if (dc->pc != pc_start)
4538 tcg_gen_helper_0_0(helper_debug);
4547 fprintf(logfile, "Search PC...\n");
4548 j = gen_opc_ptr - gen_opc_buf;
4552 gen_opc_instr_start[lj++] = 0;
4553 gen_opc_pc[lj] = dc->pc;
4554 gen_opc_npc[lj] = dc->npc;
4555 gen_opc_instr_start[lj] = 1;
4559 disas_sparc_insn(dc);
4563 /* if the next PC is different, we abort now */
4564 if (dc->pc != (last_pc + 4))
4566 /* if we reach a page boundary, we stop generation so that the
4567 PC of a TT_TFAULT exception is always in the right page */
4568 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4570 /* if single step mode, we generate only one instruction and
4571 generate an exception */
4572 if (env->singlestep_enabled) {
4577 } while ((gen_opc_ptr < gen_opc_end) &&
4578 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
4582 if (dc->pc != DYNAMIC_PC &&
4583 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4584 /* static PC and NPC: we can use direct chaining */
4585 gen_branch(dc, dc->pc, dc->npc);
4587 if (dc->pc != DYNAMIC_PC)
4593 *gen_opc_ptr = INDEX_op_end;
4595 j = gen_opc_ptr - gen_opc_buf;
4598 gen_opc_instr_start[lj++] = 0;
4604 gen_opc_jump_pc[0] = dc->jump_pc[0];
4605 gen_opc_jump_pc[1] = dc->jump_pc[1];
4607 tb->size = last_pc + 4 - pc_start;
4610 if (loglevel & CPU_LOG_TB_IN_ASM) {
4611 fprintf(logfile, "--------------\n");
4612 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4613 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4614 fprintf(logfile, "\n");
4620 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4622 return gen_intermediate_code_internal(tb, 0, env);
4625 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4627 return gen_intermediate_code_internal(tb, 1, env);
4630 void cpu_reset(CPUSPARCState *env)
4635 env->regwptr = env->regbase + (env->cwp * 16);
4636 #if defined(CONFIG_USER_ONLY)
4637 env->user_mode_only = 1;
4638 #ifdef TARGET_SPARC64
4639 env->cleanwin = NWINDOWS - 2;
4640 env->cansave = NWINDOWS - 2;
4641 env->pstate = PS_RMO | PS_PEF | PS_IE;
4642 env->asi = 0x82; // Primary no-fault
4648 #ifdef TARGET_SPARC64
4649 env->pstate = PS_PRIV;
4650 env->hpstate = HS_PRIV;
4651 env->pc = 0x1fff0000000ULL;
4652 env->tsptr = &env->ts[env->tl];
4655 env->mmuregs[0] &= ~(MMU_E | MMU_NF);
4656 env->mmuregs[0] |= env->mmu_bm;
4658 env->npc = env->pc + 4;
4662 CPUSPARCState *cpu_sparc_init(const char *cpu_model)
4665 const sparc_def_t *def;
4668 static const char * const gregnames[8] = {
4669 NULL, // g0 not used
4679 def = cpu_sparc_find_by_name(cpu_model);
4683 env = qemu_mallocz(sizeof(CPUSPARCState));
4687 env->cpu_model_str = cpu_model;
4688 env->version = def->iu_version;
4689 env->fsr = def->fpu_version;
4690 #if !defined(TARGET_SPARC64)
4691 env->mmu_bm = def->mmu_bm;
4692 env->mmu_ctpr_mask = def->mmu_ctpr_mask;
4693 env->mmu_cxr_mask = def->mmu_cxr_mask;
4694 env->mmu_sfsr_mask = def->mmu_sfsr_mask;
4695 env->mmu_trcr_mask = def->mmu_trcr_mask;
4696 env->mmuregs[0] |= def->mmu_version;
4697 cpu_sparc_set_id(env, 0);
4700 /* init various static tables */
4704 tcg_set_macro_func(&tcg_ctx, tcg_macro_func);
4705 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4706 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4707 offsetof(CPUState, regwptr),
4709 //#if TARGET_LONG_BITS > HOST_LONG_BITS
4710 #ifdef TARGET_SPARC64
4711 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
4712 TCG_AREG0, offsetof(CPUState, t0), "T0");
4713 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
4714 TCG_AREG0, offsetof(CPUState, t1), "T1");
4715 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
4716 TCG_AREG0, offsetof(CPUState, t2), "T2");
4717 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4718 TCG_AREG0, offsetof(CPUState, xcc),
4721 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
4722 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
4723 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
4725 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4726 TCG_AREG0, offsetof(CPUState, cc_src),
4728 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4729 offsetof(CPUState, cc_src2),
4731 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4732 TCG_AREG0, offsetof(CPUState, cc_dst),
4734 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4735 TCG_AREG0, offsetof(CPUState, psr),
4737 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4738 TCG_AREG0, offsetof(CPUState, fsr),
4740 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4741 TCG_AREG0, offsetof(CPUState, pc),
4743 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4744 TCG_AREG0, offsetof(CPUState, npc),
4746 for (i = 1; i < 8; i++)
4747 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4748 offsetof(CPUState, gregs[i]),
4757 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
4759 #if !defined(TARGET_SPARC64)
4760 env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
4764 static const sparc_def_t sparc_defs[] = {
4765 #ifdef TARGET_SPARC64
4767 .name = "Fujitsu Sparc64",
4768 .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)
4769 | (MAXTL << 8) | (NWINDOWS - 1)),
4770 .fpu_version = 0x00000000,
4774 .name = "Fujitsu Sparc64 III",
4775 .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)
4776 | (MAXTL << 8) | (NWINDOWS - 1)),
4777 .fpu_version = 0x00000000,
4781 .name = "Fujitsu Sparc64 IV",
4782 .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)
4783 | (MAXTL << 8) | (NWINDOWS - 1)),
4784 .fpu_version = 0x00000000,
4788 .name = "Fujitsu Sparc64 V",
4789 .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)
4790 | (MAXTL << 8) | (NWINDOWS - 1)),
4791 .fpu_version = 0x00000000,
4795 .name = "TI UltraSparc I",
4796 .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
4797 | (MAXTL << 8) | (NWINDOWS - 1)),
4798 .fpu_version = 0x00000000,
4802 .name = "TI UltraSparc II",
4803 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)
4804 | (MAXTL << 8) | (NWINDOWS - 1)),
4805 .fpu_version = 0x00000000,
4809 .name = "TI UltraSparc IIi",
4810 .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)
4811 | (MAXTL << 8) | (NWINDOWS - 1)),
4812 .fpu_version = 0x00000000,
4816 .name = "TI UltraSparc IIe",
4817 .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)
4818 | (MAXTL << 8) | (NWINDOWS - 1)),
4819 .fpu_version = 0x00000000,
4823 .name = "Sun UltraSparc III",
4824 .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)
4825 | (MAXTL << 8) | (NWINDOWS - 1)),
4826 .fpu_version = 0x00000000,
4830 .name = "Sun UltraSparc III Cu",
4831 .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)
4832 | (MAXTL << 8) | (NWINDOWS - 1)),
4833 .fpu_version = 0x00000000,
4837 .name = "Sun UltraSparc IIIi",
4838 .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)
4839 | (MAXTL << 8) | (NWINDOWS - 1)),
4840 .fpu_version = 0x00000000,
4844 .name = "Sun UltraSparc IV",
4845 .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)
4846 | (MAXTL << 8) | (NWINDOWS - 1)),
4847 .fpu_version = 0x00000000,
4851 .name = "Sun UltraSparc IV+",
4852 .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)
4853 | (MAXTL << 8) | (NWINDOWS - 1)),
4854 .fpu_version = 0x00000000,
4858 .name = "Sun UltraSparc IIIi+",
4859 .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)
4860 | (MAXTL << 8) | (NWINDOWS - 1)),
4861 .fpu_version = 0x00000000,
4865 .name = "NEC UltraSparc I",
4866 .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
4867 | (MAXTL << 8) | (NWINDOWS - 1)),
4868 .fpu_version = 0x00000000,
4873 .name = "Fujitsu MB86900",
4874 .iu_version = 0x00 << 24, /* Impl 0, ver 0 */
4875 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
4876 .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */
4877 .mmu_bm = 0x00004000,
4878 .mmu_ctpr_mask = 0x007ffff0,
4879 .mmu_cxr_mask = 0x0000003f,
4880 .mmu_sfsr_mask = 0xffffffff,
4881 .mmu_trcr_mask = 0xffffffff,
4884 .name = "Fujitsu MB86904",
4885 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
4886 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
4887 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
4888 .mmu_bm = 0x00004000,
4889 .mmu_ctpr_mask = 0x00ffffc0,
4890 .mmu_cxr_mask = 0x000000ff,
4891 .mmu_sfsr_mask = 0x00016fff,
4892 .mmu_trcr_mask = 0x00ffffff,
4895 .name = "Fujitsu MB86907",
4896 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
4897 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
4898 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
4899 .mmu_bm = 0x00004000,
4900 .mmu_ctpr_mask = 0xffffffc0,
4901 .mmu_cxr_mask = 0x000000ff,
4902 .mmu_sfsr_mask = 0x00016fff,
4903 .mmu_trcr_mask = 0xffffffff,
4906 .name = "LSI L64811",
4907 .iu_version = 0x10 << 24, /* Impl 1, ver 0 */
4908 .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */
4909 .mmu_version = 0x10 << 24,
4910 .mmu_bm = 0x00004000,
4911 .mmu_ctpr_mask = 0x007ffff0,
4912 .mmu_cxr_mask = 0x0000003f,
4913 .mmu_sfsr_mask = 0xffffffff,
4914 .mmu_trcr_mask = 0xffffffff,
4917 .name = "Cypress CY7C601",
4918 .iu_version = 0x11 << 24, /* Impl 1, ver 1 */
4919 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
4920 .mmu_version = 0x10 << 24,
4921 .mmu_bm = 0x00004000,
4922 .mmu_ctpr_mask = 0x007ffff0,
4923 .mmu_cxr_mask = 0x0000003f,
4924 .mmu_sfsr_mask = 0xffffffff,
4925 .mmu_trcr_mask = 0xffffffff,
4928 .name = "Cypress CY7C611",
4929 .iu_version = 0x13 << 24, /* Impl 1, ver 3 */
4930 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
4931 .mmu_version = 0x10 << 24,
4932 .mmu_bm = 0x00004000,
4933 .mmu_ctpr_mask = 0x007ffff0,
4934 .mmu_cxr_mask = 0x0000003f,
4935 .mmu_sfsr_mask = 0xffffffff,
4936 .mmu_trcr_mask = 0xffffffff,
4939 .name = "TI SuperSparc II",
4940 .iu_version = 0x40000000,
4941 .fpu_version = 0 << 17,
4942 .mmu_version = 0x04000000,
4943 .mmu_bm = 0x00002000,
4944 .mmu_ctpr_mask = 0xffffffc0,
4945 .mmu_cxr_mask = 0x0000ffff,
4946 .mmu_sfsr_mask = 0xffffffff,
4947 .mmu_trcr_mask = 0xffffffff,
4950 .name = "TI MicroSparc I",
4951 .iu_version = 0x41000000,
4952 .fpu_version = 4 << 17,
4953 .mmu_version = 0x41000000,
4954 .mmu_bm = 0x00004000,
4955 .mmu_ctpr_mask = 0x007ffff0,
4956 .mmu_cxr_mask = 0x0000003f,
4957 .mmu_sfsr_mask = 0x00016fff,
4958 .mmu_trcr_mask = 0x0000003f,
4961 .name = "TI MicroSparc II",
4962 .iu_version = 0x42000000,
4963 .fpu_version = 4 << 17,
4964 .mmu_version = 0x02000000,
4965 .mmu_bm = 0x00004000,
4966 .mmu_ctpr_mask = 0x00ffffc0,
4967 .mmu_cxr_mask = 0x000000ff,
4968 .mmu_sfsr_mask = 0x00016fff,
4969 .mmu_trcr_mask = 0x00ffffff,
4972 .name = "TI MicroSparc IIep",
4973 .iu_version = 0x42000000,
4974 .fpu_version = 4 << 17,
4975 .mmu_version = 0x04000000,
4976 .mmu_bm = 0x00004000,
4977 .mmu_ctpr_mask = 0x00ffffc0,
4978 .mmu_cxr_mask = 0x000000ff,
4979 .mmu_sfsr_mask = 0x00016bff,
4980 .mmu_trcr_mask = 0x00ffffff,
4983 .name = "TI SuperSparc 51",
4984 .iu_version = 0x43000000,
4985 .fpu_version = 0 << 17,
4986 .mmu_version = 0x04000000,
4987 .mmu_bm = 0x00002000,
4988 .mmu_ctpr_mask = 0xffffffc0,
4989 .mmu_cxr_mask = 0x0000ffff,
4990 .mmu_sfsr_mask = 0xffffffff,
4991 .mmu_trcr_mask = 0xffffffff,
4994 .name = "TI SuperSparc 61",
4995 .iu_version = 0x44000000,
4996 .fpu_version = 0 << 17,
4997 .mmu_version = 0x04000000,
4998 .mmu_bm = 0x00002000,
4999 .mmu_ctpr_mask = 0xffffffc0,
5000 .mmu_cxr_mask = 0x0000ffff,
5001 .mmu_sfsr_mask = 0xffffffff,
5002 .mmu_trcr_mask = 0xffffffff,
5005 .name = "Ross RT625",
5006 .iu_version = 0x1e000000,
5007 .fpu_version = 1 << 17,
5008 .mmu_version = 0x1e000000,
5009 .mmu_bm = 0x00004000,
5010 .mmu_ctpr_mask = 0x007ffff0,
5011 .mmu_cxr_mask = 0x0000003f,
5012 .mmu_sfsr_mask = 0xffffffff,
5013 .mmu_trcr_mask = 0xffffffff,
5016 .name = "Ross RT620",
5017 .iu_version = 0x1f000000,
5018 .fpu_version = 1 << 17,
5019 .mmu_version = 0x1f000000,
5020 .mmu_bm = 0x00004000,
5021 .mmu_ctpr_mask = 0x007ffff0,
5022 .mmu_cxr_mask = 0x0000003f,
5023 .mmu_sfsr_mask = 0xffffffff,
5024 .mmu_trcr_mask = 0xffffffff,
5027 .name = "BIT B5010",
5028 .iu_version = 0x20000000,
5029 .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */
5030 .mmu_version = 0x20000000,
5031 .mmu_bm = 0x00004000,
5032 .mmu_ctpr_mask = 0x007ffff0,
5033 .mmu_cxr_mask = 0x0000003f,
5034 .mmu_sfsr_mask = 0xffffffff,
5035 .mmu_trcr_mask = 0xffffffff,
5038 .name = "Matsushita MN10501",
5039 .iu_version = 0x50000000,
5040 .fpu_version = 0 << 17,
5041 .mmu_version = 0x50000000,
5042 .mmu_bm = 0x00004000,
5043 .mmu_ctpr_mask = 0x007ffff0,
5044 .mmu_cxr_mask = 0x0000003f,
5045 .mmu_sfsr_mask = 0xffffffff,
5046 .mmu_trcr_mask = 0xffffffff,
5049 .name = "Weitek W8601",
5050 .iu_version = 0x90 << 24, /* Impl 9, ver 0 */
5051 .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
5052 .mmu_version = 0x10 << 24,
5053 .mmu_bm = 0x00004000,
5054 .mmu_ctpr_mask = 0x007ffff0,
5055 .mmu_cxr_mask = 0x0000003f,
5056 .mmu_sfsr_mask = 0xffffffff,
5057 .mmu_trcr_mask = 0xffffffff,
5061 .iu_version = 0xf2000000,
5062 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
5063 .mmu_version = 0xf2000000,
5064 .mmu_bm = 0x00004000,
5065 .mmu_ctpr_mask = 0x007ffff0,
5066 .mmu_cxr_mask = 0x0000003f,
5067 .mmu_sfsr_mask = 0xffffffff,
5068 .mmu_trcr_mask = 0xffffffff,
5072 .iu_version = 0xf3000000,
5073 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
5074 .mmu_version = 0xf3000000,
5075 .mmu_bm = 0x00004000,
5076 .mmu_ctpr_mask = 0x007ffff0,
5077 .mmu_cxr_mask = 0x0000003f,
5078 .mmu_sfsr_mask = 0xffffffff,
5079 .mmu_trcr_mask = 0xffffffff,
5084 static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name)
5088 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
5089 if (strcasecmp(name, sparc_defs[i].name) == 0) {
5090 return &sparc_defs[i];
5096 void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
5100 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
5101 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x\n",
5103 sparc_defs[i].iu_version,
5104 sparc_defs[i].fpu_version,
5105 sparc_defs[i].mmu_version);
5109 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
5111 void cpu_dump_state(CPUState *env, FILE *f,
5112 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5117 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, env->npc);
5118 cpu_fprintf(f, "General Registers:\n");
5119 for (i = 0; i < 4; i++)
5120 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
5121 cpu_fprintf(f, "\n");
5123 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
5124 cpu_fprintf(f, "\nCurrent Register Window:\n");
5125 for (x = 0; x < 3; x++) {
5126 for (i = 0; i < 4; i++)
5127 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
5128 (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i,
5129 env->regwptr[i + x * 8]);
5130 cpu_fprintf(f, "\n");
5132 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
5133 (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i,
5134 env->regwptr[i + x * 8]);
5135 cpu_fprintf(f, "\n");
5137 cpu_fprintf(f, "\nFloating Point Registers:\n");
5138 for (i = 0; i < 32; i++) {
5140 cpu_fprintf(f, "%%f%02d:", i);
5141 cpu_fprintf(f, " %016lf", env->fpr[i]);
5143 cpu_fprintf(f, "\n");
5145 #ifdef TARGET_SPARC64
5146 cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
5147 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs);
5148 cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
5149 env->cansave, env->canrestore, env->otherwin, env->wstate,
5150 env->cleanwin, NWINDOWS - 1 - env->cwp);
5152 cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env),
5153 GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'),
5154 GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'),
5155 env->psrs?'S':'-', env->psrps?'P':'-',
5156 env->psret?'E':'-', env->wim);
5158 cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env));
5161 #if defined(CONFIG_USER_ONLY)
5162 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
5168 extern int get_physical_address (CPUState *env, target_phys_addr_t *physical, int *prot,
5169 int *access_index, target_ulong address, int rw,
5172 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
5174 target_phys_addr_t phys_addr;
5175 int prot, access_index;
5177 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2,
5178 MMU_KERNEL_IDX) != 0)
5179 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr,
5180 0, MMU_KERNEL_IDX) != 0)
5182 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED)
5188 void helper_flush(target_ulong addr)
5191 tb_invalidate_page_range(addr, addr + 8);