4 Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
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];
51 static TCGv cpu_cond, cpu_src1, cpu_src2, cpu_dst, cpu_addr, cpu_val;
55 /* local register indexes (only used inside old micro ops) */
56 static TCGv cpu_tmp0, cpu_tmp32, cpu_tmp64;
58 typedef struct DisasContext {
59 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
60 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
61 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
65 struct TranslationBlock *tb;
71 // This function uses non-native bit order
72 #define GET_FIELD(X, FROM, TO) \
73 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
75 // This function uses the order in the manuals, i.e. bit 0 is 2^0
76 #define GET_FIELD_SP(X, FROM, TO) \
77 GET_FIELD(X, 31 - (TO), 31 - (FROM))
79 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
80 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
84 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
85 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
88 #define DFPREG(r) (r & 0x1e)
89 #define QFPREG(r) (r & 0x1c)
92 static int sign_extend(int x, int len)
95 return (x << len) >> len;
98 #define IS_IMM (insn & (1<<13))
100 /* floating point registers moves */
101 static void gen_op_load_fpr_FT0(unsigned int src)
103 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
104 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
107 static void gen_op_load_fpr_FT1(unsigned int src)
109 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
110 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
113 static void gen_op_store_FT0_fpr(unsigned int dst)
115 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
116 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
119 static void gen_op_load_fpr_DT0(unsigned int src)
121 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
122 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper));
123 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
124 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower));
127 static void gen_op_load_fpr_DT1(unsigned int src)
129 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
130 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.upper));
131 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
132 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.lower));
135 static void gen_op_store_DT0_fpr(unsigned int dst)
137 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper));
138 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
139 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower));
140 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
143 #ifdef CONFIG_USER_ONLY
144 static void gen_op_load_fpr_QT0(unsigned int src)
146 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
147 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upmost));
148 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
149 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper));
150 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
151 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower));
152 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
153 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest));
156 static void gen_op_load_fpr_QT1(unsigned int src)
158 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
159 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upmost));
160 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
161 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upper));
162 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
163 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.lower));
164 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
165 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.lowest));
168 static void gen_op_store_QT0_fpr(unsigned int dst)
170 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upmost));
171 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
172 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper));
173 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
174 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower));
175 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
176 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest));
177 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
182 #ifdef CONFIG_USER_ONLY
183 #define supervisor(dc) 0
184 #ifdef TARGET_SPARC64
185 #define hypervisor(dc) 0
187 #define gen_op_ldst(name) gen_op_##name##_raw()
189 #define supervisor(dc) (dc->mem_idx >= 1)
190 #ifdef TARGET_SPARC64
191 #define hypervisor(dc) (dc->mem_idx == 2)
192 #define OP_LD_TABLE(width) \
193 static GenOpFunc * const gen_op_##width[] = { \
194 &gen_op_##width##_user, \
195 &gen_op_##width##_kernel, \
196 &gen_op_##width##_hypv, \
199 #define OP_LD_TABLE(width) \
200 static GenOpFunc * const gen_op_##width[] = { \
201 &gen_op_##width##_user, \
202 &gen_op_##width##_kernel, \
205 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
208 #ifndef CONFIG_USER_ONLY
211 #endif /* __i386__ */
217 #define ABI32_MASK(addr) tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
219 #define ABI32_MASK(addr)
222 static inline void gen_movl_reg_TN(int reg, TCGv tn)
225 tcg_gen_movi_tl(tn, 0);
227 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
229 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
233 static inline void gen_movl_TN_reg(int reg, TCGv tn)
238 tcg_gen_mov_tl(cpu_gregs[reg], tn);
240 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
244 static inline void gen_goto_tb(DisasContext *s, int tb_num,
245 target_ulong pc, target_ulong npc)
247 TranslationBlock *tb;
250 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
251 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
252 /* jump to same page: we can use a direct jump */
253 tcg_gen_goto_tb(tb_num);
254 tcg_gen_movi_tl(cpu_pc, pc);
255 tcg_gen_movi_tl(cpu_npc, npc);
256 tcg_gen_exit_tb((long)tb + tb_num);
258 /* jump to another page: currently not optimized */
259 tcg_gen_movi_tl(cpu_pc, pc);
260 tcg_gen_movi_tl(cpu_npc, npc);
266 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
268 tcg_gen_extu_i32_tl(reg, src);
269 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
270 tcg_gen_andi_tl(reg, reg, 0x1);
273 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
275 tcg_gen_extu_i32_tl(reg, src);
276 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
277 tcg_gen_andi_tl(reg, reg, 0x1);
280 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
282 tcg_gen_extu_i32_tl(reg, src);
283 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
284 tcg_gen_andi_tl(reg, reg, 0x1);
287 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
289 tcg_gen_extu_i32_tl(reg, src);
290 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
291 tcg_gen_andi_tl(reg, reg, 0x1);
294 static inline void gen_cc_clear_icc(void)
296 tcg_gen_movi_i32(cpu_psr, 0);
299 #ifdef TARGET_SPARC64
300 static inline void gen_cc_clear_xcc(void)
302 tcg_gen_movi_i32(cpu_xcc, 0);
308 env->psr |= PSR_ZERO;
309 if ((int32_t) T0 < 0)
312 static inline void gen_cc_NZ_icc(TCGv dst)
317 l1 = gen_new_label();
318 l2 = gen_new_label();
319 r_temp = tcg_temp_new(TCG_TYPE_TL);
320 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
321 tcg_gen_brcond_tl(TCG_COND_NE, r_temp, tcg_const_tl(0), l1);
322 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
324 tcg_gen_ext_i32_tl(r_temp, dst);
325 tcg_gen_brcond_tl(TCG_COND_GE, r_temp, tcg_const_tl(0), l2);
326 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
330 #ifdef TARGET_SPARC64
331 static inline void gen_cc_NZ_xcc(TCGv dst)
335 l1 = gen_new_label();
336 l2 = gen_new_label();
337 tcg_gen_brcond_tl(TCG_COND_NE, dst, tcg_const_tl(0), l1);
338 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
340 tcg_gen_brcond_tl(TCG_COND_GE, dst, tcg_const_tl(0), l2);
341 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
348 env->psr |= PSR_CARRY;
350 static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
355 l1 = gen_new_label();
356 r_temp = tcg_temp_new(TCG_TYPE_TL);
357 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
358 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
359 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
363 #ifdef TARGET_SPARC64
364 static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
368 l1 = gen_new_label();
369 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
370 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
376 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
379 static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
384 l1 = gen_new_label();
386 r_temp = tcg_temp_new(TCG_TYPE_TL);
387 tcg_gen_xor_tl(r_temp, src1, src2);
388 tcg_gen_xori_tl(r_temp, r_temp, -1);
389 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
390 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
391 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
392 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
393 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
397 #ifdef TARGET_SPARC64
398 static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
403 l1 = gen_new_label();
405 r_temp = tcg_temp_new(TCG_TYPE_TL);
406 tcg_gen_xor_tl(r_temp, src1, src2);
407 tcg_gen_xori_tl(r_temp, r_temp, -1);
408 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
409 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
410 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
411 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
412 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF);
417 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
422 l1 = gen_new_label();
424 r_temp = tcg_temp_new(TCG_TYPE_TL);
425 tcg_gen_xor_tl(r_temp, src1, src2);
426 tcg_gen_xori_tl(r_temp, r_temp, -1);
427 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
428 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
429 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
430 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
431 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
435 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
439 l1 = gen_new_label();
440 tcg_gen_or_tl(cpu_tmp0, src1, src2);
441 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
442 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
443 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
447 static inline void gen_tag_tv(TCGv src1, TCGv src2)
451 l1 = gen_new_label();
452 tcg_gen_or_tl(cpu_tmp0, src1, src2);
453 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
454 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
455 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
459 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
461 tcg_gen_mov_tl(cpu_cc_src, src1);
462 tcg_gen_add_tl(dst, src1, src2);
465 gen_cc_C_add_icc(dst, cpu_cc_src);
466 gen_cc_V_add_icc(dst, cpu_cc_src, src2);
467 #ifdef TARGET_SPARC64
470 gen_cc_C_add_xcc(dst, cpu_cc_src);
471 gen_cc_V_add_xcc(dst, cpu_cc_src, src2);
475 static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
477 tcg_gen_mov_tl(cpu_cc_src, src1);
478 gen_mov_reg_C(cpu_tmp0, cpu_psr);
479 tcg_gen_add_tl(dst, src1, cpu_tmp0);
481 gen_cc_C_add_icc(dst, cpu_cc_src);
482 #ifdef TARGET_SPARC64
484 gen_cc_C_add_xcc(dst, cpu_cc_src);
486 tcg_gen_add_tl(dst, dst, src2);
488 gen_cc_C_add_icc(dst, cpu_cc_src);
489 gen_cc_V_add_icc(dst, cpu_cc_src, src2);
490 #ifdef TARGET_SPARC64
492 gen_cc_C_add_xcc(dst, cpu_cc_src);
493 gen_cc_V_add_xcc(dst, cpu_cc_src, src2);
497 static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
499 tcg_gen_mov_tl(cpu_cc_src, src1);
500 tcg_gen_add_tl(dst, src1, src2);
503 gen_cc_C_add_icc(dst, cpu_cc_src);
504 gen_cc_V_add_icc(dst, cpu_cc_src, src2);
505 gen_cc_V_tag(cpu_cc_src, src2);
506 #ifdef TARGET_SPARC64
509 gen_cc_C_add_xcc(dst, cpu_cc_src);
510 gen_cc_V_add_xcc(dst, cpu_cc_src, src2);
514 static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
516 gen_tag_tv(src1, src2);
517 tcg_gen_mov_tl(cpu_cc_src, src1);
518 tcg_gen_add_tl(dst, src1, src2);
519 gen_add_tv(dst, cpu_cc_src, src2);
522 gen_cc_C_add_icc(dst, cpu_cc_src);
523 #ifdef TARGET_SPARC64
526 gen_cc_C_add_xcc(dst, cpu_cc_src);
527 gen_cc_V_add_xcc(dst, cpu_cc_src, src2);
533 env->psr |= PSR_CARRY;
535 static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
537 TCGv r_temp1, r_temp2;
540 l1 = gen_new_label();
541 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
542 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
543 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
544 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
545 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
546 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
550 #ifdef TARGET_SPARC64
551 static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
555 l1 = gen_new_label();
556 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
557 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
563 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
566 static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
571 l1 = gen_new_label();
573 r_temp = tcg_temp_new(TCG_TYPE_TL);
574 tcg_gen_xor_tl(r_temp, src1, src2);
575 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
576 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
577 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
578 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
579 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
583 #ifdef TARGET_SPARC64
584 static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
589 l1 = gen_new_label();
591 r_temp = tcg_temp_new(TCG_TYPE_TL);
592 tcg_gen_xor_tl(r_temp, src1, src2);
593 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
594 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
595 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
596 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
597 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF);
602 static inline void gen_sub_tv(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_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
615 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
619 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
621 tcg_gen_mov_tl(cpu_cc_src, src1);
622 tcg_gen_sub_tl(dst, src1, src2);
625 gen_cc_C_sub_icc(cpu_cc_src, src2);
626 gen_cc_V_sub_icc(dst, cpu_cc_src, src2);
627 #ifdef TARGET_SPARC64
630 gen_cc_C_sub_xcc(cpu_cc_src, src2);
631 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
635 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
637 tcg_gen_mov_tl(cpu_cc_src, src1);
638 gen_mov_reg_C(cpu_tmp0, cpu_psr);
639 tcg_gen_sub_tl(dst, src1, cpu_tmp0);
641 gen_cc_C_sub_icc(dst, cpu_cc_src);
642 #ifdef TARGET_SPARC64
644 gen_cc_C_sub_xcc(dst, cpu_cc_src);
646 tcg_gen_sub_tl(dst, dst, src2);
648 gen_cc_C_sub_icc(dst, cpu_cc_src);
649 gen_cc_V_sub_icc(dst, cpu_cc_src, src2);
650 #ifdef TARGET_SPARC64
652 gen_cc_C_sub_xcc(dst, cpu_cc_src);
653 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
657 static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
659 tcg_gen_mov_tl(cpu_cc_src, src1);
660 tcg_gen_sub_tl(dst, src1, src2);
663 gen_cc_C_sub_icc(cpu_cc_src, src2);
664 gen_cc_V_sub_icc(dst, cpu_cc_src, src2);
665 gen_cc_V_tag(cpu_cc_src, src2);
666 #ifdef TARGET_SPARC64
669 gen_cc_C_sub_xcc(cpu_cc_src, src2);
670 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
674 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
676 gen_tag_tv(src1, src2);
677 tcg_gen_mov_tl(cpu_cc_src, src1);
678 tcg_gen_sub_tl(dst, src1, src2);
679 gen_sub_tv(dst, cpu_cc_src, src2);
682 gen_cc_C_sub_icc(cpu_cc_src, src2);
683 #ifdef TARGET_SPARC64
686 gen_cc_C_sub_xcc(cpu_cc_src, src2);
687 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
691 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
693 TCGv r_temp, r_temp2;
696 l1 = gen_new_label();
697 l2 = gen_new_label();
698 r_temp = tcg_temp_new(TCG_TYPE_TL);
699 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
705 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
706 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
707 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
708 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp2, tcg_const_i32(0), l1);
709 tcg_gen_mov_tl(cpu_cc_src2, src2);
712 tcg_gen_movi_tl(cpu_cc_src2, 0);
716 // env->y = (b2 << 31) | (env->y >> 1);
717 tcg_gen_trunc_tl_i32(r_temp2, src1);
718 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
719 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
720 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
721 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
722 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
723 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
726 gen_mov_reg_N(cpu_tmp0, cpu_psr);
727 gen_mov_reg_V(r_temp, cpu_psr);
728 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
730 // T0 = (b1 << 31) | (T0 >> 1);
732 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
733 tcg_gen_shri_tl(cpu_cc_src, src1, 1);
734 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
736 /* do addition and update flags */
737 tcg_gen_add_tl(dst, cpu_cc_src, cpu_cc_src2);
741 gen_cc_V_add_icc(dst, cpu_cc_src, cpu_cc_src2);
742 gen_cc_C_add_icc(dst, cpu_cc_src);
745 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
747 TCGv r_temp, r_temp2;
749 r_temp = tcg_temp_new(TCG_TYPE_I64);
750 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
752 tcg_gen_extu_tl_i64(r_temp, src2);
753 tcg_gen_extu_tl_i64(r_temp2, src1);
754 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
756 tcg_gen_shri_i64(r_temp, r_temp2, 32);
757 tcg_gen_trunc_i64_i32(r_temp, r_temp);
758 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
759 #ifdef TARGET_SPARC64
760 tcg_gen_mov_i64(dst, r_temp2);
762 tcg_gen_trunc_i64_tl(dst, r_temp2);
766 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
768 TCGv r_temp, r_temp2;
770 r_temp = tcg_temp_new(TCG_TYPE_I64);
771 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
773 tcg_gen_ext_tl_i64(r_temp, src2);
774 tcg_gen_ext_tl_i64(r_temp2, src1);
775 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
777 tcg_gen_shri_i64(r_temp, r_temp2, 32);
778 tcg_gen_trunc_i64_i32(r_temp, r_temp);
779 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
780 #ifdef TARGET_SPARC64
781 tcg_gen_mov_i64(dst, r_temp2);
783 tcg_gen_trunc_i64_tl(dst, r_temp2);
787 #ifdef TARGET_SPARC64
788 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
792 l1 = gen_new_label();
793 tcg_gen_brcond_tl(TCG_COND_NE, divisor, tcg_const_tl(0), l1);
794 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_DIV_ZERO));
798 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
802 l1 = gen_new_label();
803 l2 = gen_new_label();
804 gen_trap_ifdivzero_tl(src2);
805 tcg_gen_brcond_tl(TCG_COND_NE, src1, tcg_const_tl(INT64_MIN), l1);
806 tcg_gen_brcond_tl(TCG_COND_NE, src2, tcg_const_tl(-1), l1);
807 tcg_gen_movi_i64(dst, INT64_MIN);
810 tcg_gen_div_i64(dst, src1, src2);
815 static inline void gen_op_div_cc(TCGv dst)
821 l1 = gen_new_label();
822 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, cc_src2));
823 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
824 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
828 static inline void gen_op_logic_cc(TCGv dst)
832 #ifdef TARGET_SPARC64
839 static inline void gen_op_eval_ba(TCGv dst)
841 tcg_gen_movi_tl(dst, 1);
845 static inline void gen_op_eval_be(TCGv dst, TCGv src)
847 gen_mov_reg_Z(dst, src);
851 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
853 gen_mov_reg_N(cpu_tmp0, src);
854 gen_mov_reg_V(dst, src);
855 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
856 gen_mov_reg_Z(cpu_tmp0, src);
857 tcg_gen_or_tl(dst, dst, cpu_tmp0);
861 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
863 gen_mov_reg_V(cpu_tmp0, src);
864 gen_mov_reg_N(dst, src);
865 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
869 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
871 gen_mov_reg_Z(cpu_tmp0, src);
872 gen_mov_reg_C(dst, src);
873 tcg_gen_or_tl(dst, dst, cpu_tmp0);
877 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
879 gen_mov_reg_C(dst, src);
883 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
885 gen_mov_reg_V(dst, src);
889 static inline void gen_op_eval_bn(TCGv dst)
891 tcg_gen_movi_tl(dst, 0);
895 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
897 gen_mov_reg_N(dst, src);
901 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
903 gen_mov_reg_Z(dst, src);
904 tcg_gen_xori_tl(dst, dst, 0x1);
908 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
910 gen_mov_reg_N(cpu_tmp0, src);
911 gen_mov_reg_V(dst, src);
912 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
913 gen_mov_reg_Z(cpu_tmp0, src);
914 tcg_gen_or_tl(dst, dst, cpu_tmp0);
915 tcg_gen_xori_tl(dst, dst, 0x1);
919 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
921 gen_mov_reg_V(cpu_tmp0, src);
922 gen_mov_reg_N(dst, src);
923 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
924 tcg_gen_xori_tl(dst, dst, 0x1);
928 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
930 gen_mov_reg_Z(cpu_tmp0, src);
931 gen_mov_reg_C(dst, 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_bcc(TCGv dst, TCGv src)
939 gen_mov_reg_C(dst, src);
940 tcg_gen_xori_tl(dst, dst, 0x1);
944 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
946 gen_mov_reg_N(dst, src);
947 tcg_gen_xori_tl(dst, dst, 0x1);
951 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
953 gen_mov_reg_V(dst, src);
954 tcg_gen_xori_tl(dst, dst, 0x1);
958 FPSR bit field FCC1 | FCC0:
964 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
965 unsigned int fcc_offset)
967 tcg_gen_extu_i32_tl(reg, src);
968 tcg_gen_shri_tl(reg, reg, FSR_FCC0_SHIFT + fcc_offset);
969 tcg_gen_andi_tl(reg, reg, 0x1);
972 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
973 unsigned int fcc_offset)
975 tcg_gen_extu_i32_tl(reg, src);
976 tcg_gen_shri_tl(reg, reg, FSR_FCC1_SHIFT + fcc_offset);
977 tcg_gen_andi_tl(reg, reg, 0x1);
981 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
982 unsigned int fcc_offset)
984 gen_mov_reg_FCC0(dst, src, fcc_offset);
985 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
986 tcg_gen_or_tl(dst, dst, cpu_tmp0);
989 // 1 or 2: FCC0 ^ FCC1
990 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
991 unsigned int fcc_offset)
993 gen_mov_reg_FCC0(dst, src, fcc_offset);
994 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
995 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
999 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1000 unsigned int fcc_offset)
1002 gen_mov_reg_FCC0(dst, src, fcc_offset);
1006 static inline void gen_op_eval_fbl(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_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1012 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1016 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1017 unsigned int fcc_offset)
1019 gen_mov_reg_FCC1(dst, src, fcc_offset);
1023 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1024 unsigned int fcc_offset)
1026 gen_mov_reg_FCC0(dst, src, fcc_offset);
1027 tcg_gen_xori_tl(dst, dst, 0x1);
1028 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1029 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1033 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1034 unsigned int fcc_offset)
1036 gen_mov_reg_FCC0(dst, src, fcc_offset);
1037 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1038 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1041 // 0: !(FCC0 | FCC1)
1042 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1043 unsigned int fcc_offset)
1045 gen_mov_reg_FCC0(dst, src, fcc_offset);
1046 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1047 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1048 tcg_gen_xori_tl(dst, dst, 0x1);
1051 // 0 or 3: !(FCC0 ^ FCC1)
1052 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1053 unsigned int fcc_offset)
1055 gen_mov_reg_FCC0(dst, src, fcc_offset);
1056 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1057 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1058 tcg_gen_xori_tl(dst, dst, 0x1);
1062 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1063 unsigned int fcc_offset)
1065 gen_mov_reg_FCC0(dst, src, fcc_offset);
1066 tcg_gen_xori_tl(dst, dst, 0x1);
1069 // !1: !(FCC0 & !FCC1)
1070 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1071 unsigned int fcc_offset)
1073 gen_mov_reg_FCC0(dst, src, fcc_offset);
1074 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1075 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1076 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1077 tcg_gen_xori_tl(dst, dst, 0x1);
1081 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1082 unsigned int fcc_offset)
1084 gen_mov_reg_FCC1(dst, src, fcc_offset);
1085 tcg_gen_xori_tl(dst, dst, 0x1);
1088 // !2: !(!FCC0 & FCC1)
1089 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1090 unsigned int fcc_offset)
1092 gen_mov_reg_FCC0(dst, src, fcc_offset);
1093 tcg_gen_xori_tl(dst, dst, 0x1);
1094 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1095 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1096 tcg_gen_xori_tl(dst, dst, 0x1);
1099 // !3: !(FCC0 & FCC1)
1100 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1101 unsigned int fcc_offset)
1103 gen_mov_reg_FCC0(dst, src, fcc_offset);
1104 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1105 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1106 tcg_gen_xori_tl(dst, dst, 0x1);
1109 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1110 target_ulong pc2, TCGv r_cond)
1114 l1 = gen_new_label();
1116 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1118 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1121 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1124 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1125 target_ulong pc2, TCGv r_cond)
1129 l1 = gen_new_label();
1131 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1133 gen_goto_tb(dc, 0, pc2, pc1);
1136 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1139 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1144 l1 = gen_new_label();
1145 l2 = gen_new_label();
1147 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1149 tcg_gen_movi_tl(cpu_npc, npc1);
1153 tcg_gen_movi_tl(cpu_npc, npc2);
1157 /* call this function before using the condition register as it may
1158 have been set for a jump */
1159 static inline void flush_cond(DisasContext *dc, TCGv cond)
1161 if (dc->npc == JUMP_PC) {
1162 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1163 dc->npc = DYNAMIC_PC;
1167 static inline void save_npc(DisasContext *dc, TCGv cond)
1169 if (dc->npc == JUMP_PC) {
1170 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1171 dc->npc = DYNAMIC_PC;
1172 } else if (dc->npc != DYNAMIC_PC) {
1173 tcg_gen_movi_tl(cpu_npc, dc->npc);
1177 static inline void save_state(DisasContext *dc, TCGv cond)
1179 tcg_gen_movi_tl(cpu_pc, dc->pc);
1183 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1185 if (dc->npc == JUMP_PC) {
1186 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1187 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1188 dc->pc = DYNAMIC_PC;
1189 } else if (dc->npc == DYNAMIC_PC) {
1190 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1191 dc->pc = DYNAMIC_PC;
1197 static inline void gen_op_next_insn(void)
1199 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1200 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1203 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1207 #ifdef TARGET_SPARC64
1217 gen_op_eval_bn(r_dst);
1220 gen_op_eval_be(r_dst, r_src);
1223 gen_op_eval_ble(r_dst, r_src);
1226 gen_op_eval_bl(r_dst, r_src);
1229 gen_op_eval_bleu(r_dst, r_src);
1232 gen_op_eval_bcs(r_dst, r_src);
1235 gen_op_eval_bneg(r_dst, r_src);
1238 gen_op_eval_bvs(r_dst, r_src);
1241 gen_op_eval_ba(r_dst);
1244 gen_op_eval_bne(r_dst, r_src);
1247 gen_op_eval_bg(r_dst, r_src);
1250 gen_op_eval_bge(r_dst, r_src);
1253 gen_op_eval_bgu(r_dst, r_src);
1256 gen_op_eval_bcc(r_dst, r_src);
1259 gen_op_eval_bpos(r_dst, r_src);
1262 gen_op_eval_bvc(r_dst, r_src);
1267 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1269 unsigned int offset;
1289 gen_op_eval_bn(r_dst);
1292 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1295 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1298 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1301 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1304 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1307 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1310 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1313 gen_op_eval_ba(r_dst);
1316 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1319 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1322 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1325 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1328 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1331 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1334 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1339 #ifdef TARGET_SPARC64
1341 static const int gen_tcg_cond_reg[8] = {
1352 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1356 l1 = gen_new_label();
1357 tcg_gen_movi_tl(r_dst, 0);
1358 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], r_src, tcg_const_tl(0), l1);
1359 tcg_gen_movi_tl(r_dst, 1);
1364 /* XXX: potentially incorrect if dynamic npc */
1365 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1368 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1369 target_ulong target = dc->pc + offset;
1372 /* unconditional not taken */
1374 dc->pc = dc->npc + 4;
1375 dc->npc = dc->pc + 4;
1378 dc->npc = dc->pc + 4;
1380 } else if (cond == 0x8) {
1381 /* unconditional taken */
1384 dc->npc = dc->pc + 4;
1390 flush_cond(dc, r_cond);
1391 gen_cond(r_cond, cc, cond);
1393 gen_branch_a(dc, target, dc->npc, r_cond);
1397 dc->jump_pc[0] = target;
1398 dc->jump_pc[1] = dc->npc + 4;
1404 /* XXX: potentially incorrect if dynamic npc */
1405 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1408 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1409 target_ulong target = dc->pc + offset;
1412 /* unconditional not taken */
1414 dc->pc = dc->npc + 4;
1415 dc->npc = dc->pc + 4;
1418 dc->npc = dc->pc + 4;
1420 } else if (cond == 0x8) {
1421 /* unconditional taken */
1424 dc->npc = dc->pc + 4;
1430 flush_cond(dc, r_cond);
1431 gen_fcond(r_cond, cc, cond);
1433 gen_branch_a(dc, target, dc->npc, r_cond);
1437 dc->jump_pc[0] = target;
1438 dc->jump_pc[1] = dc->npc + 4;
1444 #ifdef TARGET_SPARC64
1445 /* XXX: potentially incorrect if dynamic npc */
1446 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1447 TCGv r_cond, TCGv r_reg)
1449 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1450 target_ulong target = dc->pc + offset;
1452 flush_cond(dc, r_cond);
1453 gen_cond_reg(r_cond, cond, r_reg);
1455 gen_branch_a(dc, target, dc->npc, r_cond);
1459 dc->jump_pc[0] = target;
1460 dc->jump_pc[1] = dc->npc + 4;
1465 static GenOpFunc * const gen_fcmps[4] = {
1472 static GenOpFunc * const gen_fcmpd[4] = {
1479 #if defined(CONFIG_USER_ONLY)
1480 static GenOpFunc * const gen_fcmpq[4] = {
1488 static GenOpFunc * const gen_fcmpes[4] = {
1495 static GenOpFunc * const gen_fcmped[4] = {
1502 #if defined(CONFIG_USER_ONLY)
1503 static GenOpFunc * const gen_fcmpeq[4] = {
1511 static inline void gen_op_fcmps(int fccno)
1513 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1516 static inline void gen_op_fcmpd(int fccno)
1518 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1521 #if defined(CONFIG_USER_ONLY)
1522 static inline void gen_op_fcmpq(int fccno)
1524 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1528 static inline void gen_op_fcmpes(int fccno)
1530 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1533 static inline void gen_op_fcmped(int fccno)
1535 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1538 #if defined(CONFIG_USER_ONLY)
1539 static inline void gen_op_fcmpeq(int fccno)
1541 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1547 static inline void gen_op_fcmps(int fccno)
1549 tcg_gen_helper_0_0(helper_fcmps);
1552 static inline void gen_op_fcmpd(int fccno)
1554 tcg_gen_helper_0_0(helper_fcmpd);
1557 #if defined(CONFIG_USER_ONLY)
1558 static inline void gen_op_fcmpq(int fccno)
1560 tcg_gen_helper_0_0(helper_fcmpq);
1564 static inline void gen_op_fcmpes(int fccno)
1566 tcg_gen_helper_0_0(helper_fcmpes);
1569 static inline void gen_op_fcmped(int fccno)
1571 tcg_gen_helper_0_0(helper_fcmped);
1574 #if defined(CONFIG_USER_ONLY)
1575 static inline void gen_op_fcmpeq(int fccno)
1577 tcg_gen_helper_0_0(helper_fcmpeq);
1583 static inline void gen_op_fpexception_im(int fsr_flags)
1585 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1586 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1587 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_FP_EXCP));
1590 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1592 #if !defined(CONFIG_USER_ONLY)
1593 if (!dc->fpu_enabled) {
1594 save_state(dc, r_cond);
1595 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NFPU_INSN));
1603 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1605 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1608 static inline void gen_clear_float_exceptions(void)
1610 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1614 #ifdef TARGET_SPARC64
1615 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1621 r_asi = tcg_temp_new(TCG_TYPE_I32);
1622 offset = GET_FIELD(insn, 25, 31);
1623 tcg_gen_addi_tl(r_addr, r_addr, offset);
1624 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1626 asi = GET_FIELD(insn, 19, 26);
1627 r_asi = tcg_const_i32(asi);
1632 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size, int sign)
1636 r_asi = gen_get_asi(insn, addr);
1637 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi,
1638 tcg_const_i32(size), tcg_const_i32(sign));
1641 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1645 r_asi = gen_get_asi(insn, addr);
1646 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, tcg_const_i32(size));
1649 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1653 r_asi = gen_get_asi(insn, addr);
1654 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, tcg_const_i32(size),
1658 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1662 r_asi = gen_get_asi(insn, addr);
1663 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, tcg_const_i32(size),
1667 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1671 r_temp = tcg_temp_new(TCG_TYPE_I32);
1672 r_asi = gen_get_asi(insn, addr);
1673 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, r_asi,
1674 tcg_const_i32(4), tcg_const_i32(0));
1675 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi,
1677 tcg_gen_extu_i32_tl(dst, r_temp);
1680 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1684 r_asi = gen_get_asi(insn, addr);
1685 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi,
1686 tcg_const_i32(8), tcg_const_i32(0));
1687 tcg_gen_andi_i64(lo, cpu_tmp64, 0xffffffffULL);
1688 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1689 tcg_gen_andi_i64(hi, cpu_tmp64, 0xffffffffULL);
1692 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1696 r_temp = tcg_temp_new(TCG_TYPE_I32);
1697 gen_movl_reg_TN(rd + 1, r_temp);
1698 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1700 r_asi = gen_get_asi(insn, addr);
1701 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi,
1705 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn, int rd)
1709 r_val1 = tcg_temp_new(TCG_TYPE_I32);
1710 gen_movl_reg_TN(rd, r_val1);
1711 r_asi = gen_get_asi(insn, addr);
1712 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1715 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn, int rd)
1719 gen_movl_reg_TN(rd, cpu_tmp64);
1720 r_asi = gen_get_asi(insn, addr);
1721 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1724 #elif !defined(CONFIG_USER_ONLY)
1726 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size, int sign)
1730 asi = GET_FIELD(insn, 19, 26);
1731 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
1732 tcg_const_i32(size), tcg_const_i32(sign));
1733 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1736 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1740 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1741 asi = GET_FIELD(insn, 19, 26);
1742 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
1743 tcg_const_i32(size));
1746 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1751 r_temp = tcg_temp_new(TCG_TYPE_I32);
1752 asi = GET_FIELD(insn, 19, 26);
1753 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, tcg_const_i32(asi),
1754 tcg_const_i32(4), tcg_const_i32(0));
1755 tcg_gen_helper_0_4(helper_st_asi, addr, dst, tcg_const_i32(asi),
1757 tcg_gen_extu_i32_tl(dst, r_temp);
1760 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1764 asi = GET_FIELD(insn, 19, 26);
1765 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
1766 tcg_const_i32(8), tcg_const_i32(0));
1767 tcg_gen_trunc_i64_tl(lo, cpu_tmp64);
1768 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1769 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1772 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1777 r_temp = tcg_temp_new(TCG_TYPE_I32);
1778 gen_movl_reg_TN(rd + 1, r_temp);
1779 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1780 asi = GET_FIELD(insn, 19, 26);
1781 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
1786 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1787 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1791 gen_ld_asi(dst, addr, insn, 1, 0);
1793 asi = GET_FIELD(insn, 19, 26);
1794 tcg_gen_helper_0_4(helper_st_asi, addr, tcg_const_i64(0xffULL),
1795 tcg_const_i32(asi), tcg_const_i32(1));
1799 static inline TCGv get_src1(unsigned int insn, TCGv def)
1804 rs1 = GET_FIELD(insn, 13, 17);
1806 //r_rs1 = tcg_const_tl(0);
1807 tcg_gen_movi_tl(def, 0);
1809 //r_rs1 = cpu_gregs[rs1];
1810 tcg_gen_mov_tl(def, cpu_gregs[rs1]);
1812 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1816 static inline TCGv get_src2(unsigned int insn, TCGv def)
1821 if (IS_IMM) { /* immediate */
1822 rs2 = GET_FIELDs(insn, 19, 31);
1823 r_rs2 = tcg_const_tl((int)rs2);
1824 } else { /* register */
1825 rs2 = GET_FIELD(insn, 27, 31);
1827 r_rs2 = tcg_const_tl(0);
1829 r_rs2 = cpu_gregs[rs2];
1831 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1836 /* before an instruction, dc->pc must be static */
1837 static void disas_sparc_insn(DisasContext * dc)
1839 unsigned int insn, opc, rs1, rs2, rd;
1841 insn = ldl_code(dc->pc);
1842 opc = GET_FIELD(insn, 0, 1);
1844 rd = GET_FIELD(insn, 2, 6);
1847 cpu_src1 = cpu_T[0]; // const
1848 cpu_src2 = cpu_T[1]; // const
1851 cpu_addr = cpu_T[0];
1855 case 0: /* branches/sethi */
1857 unsigned int xop = GET_FIELD(insn, 7, 9);
1860 #ifdef TARGET_SPARC64
1861 case 0x1: /* V9 BPcc */
1865 target = GET_FIELD_SP(insn, 0, 18);
1866 target = sign_extend(target, 18);
1868 cc = GET_FIELD_SP(insn, 20, 21);
1870 do_branch(dc, target, insn, 0, cpu_cond);
1872 do_branch(dc, target, insn, 1, cpu_cond);
1877 case 0x3: /* V9 BPr */
1879 target = GET_FIELD_SP(insn, 0, 13) |
1880 (GET_FIELD_SP(insn, 20, 21) << 14);
1881 target = sign_extend(target, 16);
1883 cpu_src1 = get_src1(insn, cpu_src1);
1884 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1887 case 0x5: /* V9 FBPcc */
1889 int cc = GET_FIELD_SP(insn, 20, 21);
1890 if (gen_trap_ifnofpu(dc, cpu_cond))
1892 target = GET_FIELD_SP(insn, 0, 18);
1893 target = sign_extend(target, 19);
1895 do_fbranch(dc, target, insn, cc, cpu_cond);
1899 case 0x7: /* CBN+x */
1904 case 0x2: /* BN+x */
1906 target = GET_FIELD(insn, 10, 31);
1907 target = sign_extend(target, 22);
1909 do_branch(dc, target, insn, 0, cpu_cond);
1912 case 0x6: /* FBN+x */
1914 if (gen_trap_ifnofpu(dc, cpu_cond))
1916 target = GET_FIELD(insn, 10, 31);
1917 target = sign_extend(target, 22);
1919 do_fbranch(dc, target, insn, 0, cpu_cond);
1922 case 0x4: /* SETHI */
1924 uint32_t value = GET_FIELD(insn, 10, 31);
1925 tcg_gen_movi_tl(cpu_dst, value << 10);
1926 gen_movl_TN_reg(rd, cpu_dst);
1929 case 0x0: /* UNIMPL */
1938 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1940 gen_movl_TN_reg(15, tcg_const_tl(dc->pc));
1942 gen_mov_pc_npc(dc, cpu_cond);
1946 case 2: /* FPU & Logical Operations */
1948 unsigned int xop = GET_FIELD(insn, 7, 12);
1949 if (xop == 0x3a) { /* generate trap */
1952 cpu_src1 = get_src1(insn, cpu_src1);
1954 rs2 = GET_FIELD(insn, 25, 31);
1955 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
1957 rs2 = GET_FIELD(insn, 27, 31);
1959 gen_movl_reg_TN(rs2, cpu_src2);
1960 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
1963 cond = GET_FIELD(insn, 3, 6);
1965 save_state(dc, cpu_cond);
1966 tcg_gen_helper_0_1(helper_trap, cpu_dst);
1967 } else if (cond != 0) {
1968 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
1969 #ifdef TARGET_SPARC64
1971 int cc = GET_FIELD_SP(insn, 11, 12);
1973 save_state(dc, cpu_cond);
1975 gen_cond(r_cond, 0, cond);
1977 gen_cond(r_cond, 1, cond);
1981 save_state(dc, cpu_cond);
1982 gen_cond(r_cond, 0, cond);
1984 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
1990 } else if (xop == 0x28) {
1991 rs1 = GET_FIELD(insn, 13, 17);
1994 #ifndef TARGET_SPARC64
1995 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1996 manual, rdy on the microSPARC
1998 case 0x0f: /* stbar in the SPARCv8 manual,
1999 rdy on the microSPARC II */
2000 case 0x10 ... 0x1f: /* implementation-dependent in the
2001 SPARCv8 manual, rdy on the
2004 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
2005 gen_movl_TN_reg(rd, cpu_dst);
2007 #ifdef TARGET_SPARC64
2008 case 0x2: /* V9 rdccr */
2009 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2010 gen_movl_TN_reg(rd, cpu_dst);
2012 case 0x3: /* V9 rdasi */
2013 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
2014 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2015 gen_movl_TN_reg(rd, cpu_dst);
2017 case 0x4: /* V9 rdtick */
2021 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2022 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2023 offsetof(CPUState, tick));
2024 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2026 gen_movl_TN_reg(rd, cpu_dst);
2029 case 0x5: /* V9 rdpc */
2030 tcg_gen_movi_tl(cpu_dst, dc->pc);
2031 gen_movl_TN_reg(rd, cpu_dst);
2033 case 0x6: /* V9 rdfprs */
2034 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
2035 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2036 gen_movl_TN_reg(rd, cpu_dst);
2038 case 0xf: /* V9 membar */
2039 break; /* no effect */
2040 case 0x13: /* Graphics Status */
2041 if (gen_trap_ifnofpu(dc, cpu_cond))
2043 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
2044 gen_movl_TN_reg(rd, cpu_dst);
2046 case 0x17: /* Tick compare */
2047 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tick_cmpr));
2048 gen_movl_TN_reg(rd, cpu_dst);
2050 case 0x18: /* System tick */
2054 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2055 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2056 offsetof(CPUState, stick));
2057 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2059 gen_movl_TN_reg(rd, cpu_dst);
2062 case 0x19: /* System tick compare */
2063 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, stick_cmpr));
2064 gen_movl_TN_reg(rd, cpu_dst);
2066 case 0x10: /* Performance Control */
2067 case 0x11: /* Performance Instrumentation Counter */
2068 case 0x12: /* Dispatch Control */
2069 case 0x14: /* Softint set, WO */
2070 case 0x15: /* Softint clear, WO */
2071 case 0x16: /* Softint write */
2076 #if !defined(CONFIG_USER_ONLY)
2077 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2078 #ifndef TARGET_SPARC64
2079 if (!supervisor(dc))
2081 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2083 if (!hypervisor(dc))
2085 rs1 = GET_FIELD(insn, 13, 17);
2088 // gen_op_rdhpstate();
2091 // gen_op_rdhtstate();
2094 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
2095 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2098 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
2099 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2102 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hver));
2103 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2105 case 31: // hstick_cmpr
2106 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2107 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hstick_cmpr));
2113 gen_movl_TN_reg(rd, cpu_dst);
2115 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2116 if (!supervisor(dc))
2118 #ifdef TARGET_SPARC64
2119 rs1 = GET_FIELD(insn, 13, 17);
2125 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2126 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2127 offsetof(CPUState, tsptr));
2128 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2129 offsetof(trap_state, tpc));
2136 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2137 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2138 offsetof(CPUState, tsptr));
2139 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2140 offsetof(trap_state, tnpc));
2147 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2148 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2149 offsetof(CPUState, tsptr));
2150 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2151 offsetof(trap_state, tstate));
2158 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2159 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2160 offsetof(CPUState, tsptr));
2161 tcg_gen_ld_i32(cpu_dst, r_tsptr,
2162 offsetof(trap_state, tt));
2169 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2170 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2171 offsetof(CPUState, tick));
2172 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2174 gen_movl_TN_reg(rd, cpu_dst);
2178 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2181 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, pstate));
2182 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2185 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
2186 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2189 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
2190 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2193 tcg_gen_helper_1_0(helper_rdcwp, cpu_dst);
2196 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
2197 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2199 case 11: // canrestore
2200 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
2201 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2203 case 12: // cleanwin
2204 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
2205 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2207 case 13: // otherwin
2208 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
2209 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2212 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
2213 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2215 case 16: // UA2005 gl
2216 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
2217 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2219 case 26: // UA2005 strand status
2220 if (!hypervisor(dc))
2222 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
2223 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2226 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, version));
2233 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
2234 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2236 gen_movl_TN_reg(rd, cpu_dst);
2238 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2239 #ifdef TARGET_SPARC64
2240 tcg_gen_helper_0_0(helper_flushw);
2242 if (!supervisor(dc))
2244 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2245 gen_movl_TN_reg(rd, cpu_dst);
2249 } else if (xop == 0x34) { /* FPU Operations */
2250 if (gen_trap_ifnofpu(dc, cpu_cond))
2252 gen_op_clear_ieee_excp_and_FTT();
2253 rs1 = GET_FIELD(insn, 13, 17);
2254 rs2 = GET_FIELD(insn, 27, 31);
2255 xop = GET_FIELD(insn, 18, 26);
2257 case 0x1: /* fmovs */
2258 gen_op_load_fpr_FT0(rs2);
2259 gen_op_store_FT0_fpr(rd);
2261 case 0x5: /* fnegs */
2262 gen_op_load_fpr_FT1(rs2);
2263 tcg_gen_helper_0_0(helper_fnegs);
2264 gen_op_store_FT0_fpr(rd);
2266 case 0x9: /* fabss */
2267 gen_op_load_fpr_FT1(rs2);
2268 tcg_gen_helper_0_0(helper_fabss);
2269 gen_op_store_FT0_fpr(rd);
2271 case 0x29: /* fsqrts */
2272 gen_op_load_fpr_FT1(rs2);
2273 gen_clear_float_exceptions();
2274 tcg_gen_helper_0_0(helper_fsqrts);
2275 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2276 gen_op_store_FT0_fpr(rd);
2278 case 0x2a: /* fsqrtd */
2279 gen_op_load_fpr_DT1(DFPREG(rs2));
2280 gen_clear_float_exceptions();
2281 tcg_gen_helper_0_0(helper_fsqrtd);
2282 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2283 gen_op_store_DT0_fpr(DFPREG(rd));
2285 case 0x2b: /* fsqrtq */
2286 #if defined(CONFIG_USER_ONLY)
2287 gen_op_load_fpr_QT1(QFPREG(rs2));
2288 gen_clear_float_exceptions();
2289 tcg_gen_helper_0_0(helper_fsqrtq);
2290 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2291 gen_op_store_QT0_fpr(QFPREG(rd));
2297 gen_op_load_fpr_FT0(rs1);
2298 gen_op_load_fpr_FT1(rs2);
2299 gen_clear_float_exceptions();
2300 tcg_gen_helper_0_0(helper_fadds);
2301 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2302 gen_op_store_FT0_fpr(rd);
2305 gen_op_load_fpr_DT0(DFPREG(rs1));
2306 gen_op_load_fpr_DT1(DFPREG(rs2));
2307 gen_clear_float_exceptions();
2308 tcg_gen_helper_0_0(helper_faddd);
2309 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2310 gen_op_store_DT0_fpr(DFPREG(rd));
2312 case 0x43: /* faddq */
2313 #if defined(CONFIG_USER_ONLY)
2314 gen_op_load_fpr_QT0(QFPREG(rs1));
2315 gen_op_load_fpr_QT1(QFPREG(rs2));
2316 gen_clear_float_exceptions();
2317 tcg_gen_helper_0_0(helper_faddq);
2318 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2319 gen_op_store_QT0_fpr(QFPREG(rd));
2325 gen_op_load_fpr_FT0(rs1);
2326 gen_op_load_fpr_FT1(rs2);
2327 gen_clear_float_exceptions();
2328 tcg_gen_helper_0_0(helper_fsubs);
2329 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2330 gen_op_store_FT0_fpr(rd);
2333 gen_op_load_fpr_DT0(DFPREG(rs1));
2334 gen_op_load_fpr_DT1(DFPREG(rs2));
2335 gen_clear_float_exceptions();
2336 tcg_gen_helper_0_0(helper_fsubd);
2337 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2338 gen_op_store_DT0_fpr(DFPREG(rd));
2340 case 0x47: /* fsubq */
2341 #if defined(CONFIG_USER_ONLY)
2342 gen_op_load_fpr_QT0(QFPREG(rs1));
2343 gen_op_load_fpr_QT1(QFPREG(rs2));
2344 gen_clear_float_exceptions();
2345 tcg_gen_helper_0_0(helper_fsubq);
2346 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2347 gen_op_store_QT0_fpr(QFPREG(rd));
2353 gen_op_load_fpr_FT0(rs1);
2354 gen_op_load_fpr_FT1(rs2);
2355 gen_clear_float_exceptions();
2356 tcg_gen_helper_0_0(helper_fmuls);
2357 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2358 gen_op_store_FT0_fpr(rd);
2361 gen_op_load_fpr_DT0(DFPREG(rs1));
2362 gen_op_load_fpr_DT1(DFPREG(rs2));
2363 gen_clear_float_exceptions();
2364 tcg_gen_helper_0_0(helper_fmuld);
2365 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2366 gen_op_store_DT0_fpr(DFPREG(rd));
2368 case 0x4b: /* fmulq */
2369 #if defined(CONFIG_USER_ONLY)
2370 gen_op_load_fpr_QT0(QFPREG(rs1));
2371 gen_op_load_fpr_QT1(QFPREG(rs2));
2372 gen_clear_float_exceptions();
2373 tcg_gen_helper_0_0(helper_fmulq);
2374 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2375 gen_op_store_QT0_fpr(QFPREG(rd));
2381 gen_op_load_fpr_FT0(rs1);
2382 gen_op_load_fpr_FT1(rs2);
2383 gen_clear_float_exceptions();
2384 tcg_gen_helper_0_0(helper_fdivs);
2385 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2386 gen_op_store_FT0_fpr(rd);
2389 gen_op_load_fpr_DT0(DFPREG(rs1));
2390 gen_op_load_fpr_DT1(DFPREG(rs2));
2391 gen_clear_float_exceptions();
2392 tcg_gen_helper_0_0(helper_fdivd);
2393 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2394 gen_op_store_DT0_fpr(DFPREG(rd));
2396 case 0x4f: /* fdivq */
2397 #if defined(CONFIG_USER_ONLY)
2398 gen_op_load_fpr_QT0(QFPREG(rs1));
2399 gen_op_load_fpr_QT1(QFPREG(rs2));
2400 gen_clear_float_exceptions();
2401 tcg_gen_helper_0_0(helper_fdivq);
2402 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2403 gen_op_store_QT0_fpr(QFPREG(rd));
2409 gen_op_load_fpr_FT0(rs1);
2410 gen_op_load_fpr_FT1(rs2);
2411 gen_clear_float_exceptions();
2412 tcg_gen_helper_0_0(helper_fsmuld);
2413 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2414 gen_op_store_DT0_fpr(DFPREG(rd));
2416 case 0x6e: /* fdmulq */
2417 #if defined(CONFIG_USER_ONLY)
2418 gen_op_load_fpr_DT0(DFPREG(rs1));
2419 gen_op_load_fpr_DT1(DFPREG(rs2));
2420 gen_clear_float_exceptions();
2421 tcg_gen_helper_0_0(helper_fdmulq);
2422 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2423 gen_op_store_QT0_fpr(QFPREG(rd));
2429 gen_op_load_fpr_FT1(rs2);
2430 gen_clear_float_exceptions();
2431 tcg_gen_helper_0_0(helper_fitos);
2432 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2433 gen_op_store_FT0_fpr(rd);
2436 gen_op_load_fpr_DT1(DFPREG(rs2));
2437 gen_clear_float_exceptions();
2438 tcg_gen_helper_0_0(helper_fdtos);
2439 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2440 gen_op_store_FT0_fpr(rd);
2442 case 0xc7: /* fqtos */
2443 #if defined(CONFIG_USER_ONLY)
2444 gen_op_load_fpr_QT1(QFPREG(rs2));
2445 gen_clear_float_exceptions();
2446 tcg_gen_helper_0_0(helper_fqtos);
2447 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2448 gen_op_store_FT0_fpr(rd);
2454 gen_op_load_fpr_FT1(rs2);
2455 tcg_gen_helper_0_0(helper_fitod);
2456 gen_op_store_DT0_fpr(DFPREG(rd));
2459 gen_op_load_fpr_FT1(rs2);
2460 tcg_gen_helper_0_0(helper_fstod);
2461 gen_op_store_DT0_fpr(DFPREG(rd));
2463 case 0xcb: /* fqtod */
2464 #if defined(CONFIG_USER_ONLY)
2465 gen_op_load_fpr_QT1(QFPREG(rs2));
2466 gen_clear_float_exceptions();
2467 tcg_gen_helper_0_0(helper_fqtod);
2468 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2469 gen_op_store_DT0_fpr(DFPREG(rd));
2474 case 0xcc: /* fitoq */
2475 #if defined(CONFIG_USER_ONLY)
2476 gen_op_load_fpr_FT1(rs2);
2477 tcg_gen_helper_0_0(helper_fitoq);
2478 gen_op_store_QT0_fpr(QFPREG(rd));
2483 case 0xcd: /* fstoq */
2484 #if defined(CONFIG_USER_ONLY)
2485 gen_op_load_fpr_FT1(rs2);
2486 tcg_gen_helper_0_0(helper_fstoq);
2487 gen_op_store_QT0_fpr(QFPREG(rd));
2492 case 0xce: /* fdtoq */
2493 #if defined(CONFIG_USER_ONLY)
2494 gen_op_load_fpr_DT1(DFPREG(rs2));
2495 tcg_gen_helper_0_0(helper_fdtoq);
2496 gen_op_store_QT0_fpr(QFPREG(rd));
2502 gen_op_load_fpr_FT1(rs2);
2503 gen_clear_float_exceptions();
2504 tcg_gen_helper_0_0(helper_fstoi);
2505 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2506 gen_op_store_FT0_fpr(rd);
2509 gen_op_load_fpr_DT1(DFPREG(rs2));
2510 gen_clear_float_exceptions();
2511 tcg_gen_helper_0_0(helper_fdtoi);
2512 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2513 gen_op_store_FT0_fpr(rd);
2515 case 0xd3: /* fqtoi */
2516 #if defined(CONFIG_USER_ONLY)
2517 gen_op_load_fpr_QT1(QFPREG(rs2));
2518 gen_clear_float_exceptions();
2519 tcg_gen_helper_0_0(helper_fqtoi);
2520 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2521 gen_op_store_FT0_fpr(rd);
2526 #ifdef TARGET_SPARC64
2527 case 0x2: /* V9 fmovd */
2528 gen_op_load_fpr_DT0(DFPREG(rs2));
2529 gen_op_store_DT0_fpr(DFPREG(rd));
2531 case 0x3: /* V9 fmovq */
2532 #if defined(CONFIG_USER_ONLY)
2533 gen_op_load_fpr_QT0(QFPREG(rs2));
2534 gen_op_store_QT0_fpr(QFPREG(rd));
2539 case 0x6: /* V9 fnegd */
2540 gen_op_load_fpr_DT1(DFPREG(rs2));
2541 tcg_gen_helper_0_0(helper_fnegd);
2542 gen_op_store_DT0_fpr(DFPREG(rd));
2544 case 0x7: /* V9 fnegq */
2545 #if defined(CONFIG_USER_ONLY)
2546 gen_op_load_fpr_QT1(QFPREG(rs2));
2547 tcg_gen_helper_0_0(helper_fnegq);
2548 gen_op_store_QT0_fpr(QFPREG(rd));
2553 case 0xa: /* V9 fabsd */
2554 gen_op_load_fpr_DT1(DFPREG(rs2));
2555 tcg_gen_helper_0_0(helper_fabsd);
2556 gen_op_store_DT0_fpr(DFPREG(rd));
2558 case 0xb: /* V9 fabsq */
2559 #if defined(CONFIG_USER_ONLY)
2560 gen_op_load_fpr_QT1(QFPREG(rs2));
2561 tcg_gen_helper_0_0(helper_fabsq);
2562 gen_op_store_QT0_fpr(QFPREG(rd));
2567 case 0x81: /* V9 fstox */
2568 gen_op_load_fpr_FT1(rs2);
2569 gen_clear_float_exceptions();
2570 tcg_gen_helper_0_0(helper_fstox);
2571 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2572 gen_op_store_DT0_fpr(DFPREG(rd));
2574 case 0x82: /* V9 fdtox */
2575 gen_op_load_fpr_DT1(DFPREG(rs2));
2576 gen_clear_float_exceptions();
2577 tcg_gen_helper_0_0(helper_fdtox);
2578 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2579 gen_op_store_DT0_fpr(DFPREG(rd));
2581 case 0x83: /* V9 fqtox */
2582 #if defined(CONFIG_USER_ONLY)
2583 gen_op_load_fpr_QT1(QFPREG(rs2));
2584 gen_clear_float_exceptions();
2585 tcg_gen_helper_0_0(helper_fqtox);
2586 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2587 gen_op_store_DT0_fpr(DFPREG(rd));
2592 case 0x84: /* V9 fxtos */
2593 gen_op_load_fpr_DT1(DFPREG(rs2));
2594 gen_clear_float_exceptions();
2595 tcg_gen_helper_0_0(helper_fxtos);
2596 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2597 gen_op_store_FT0_fpr(rd);
2599 case 0x88: /* V9 fxtod */
2600 gen_op_load_fpr_DT1(DFPREG(rs2));
2601 gen_clear_float_exceptions();
2602 tcg_gen_helper_0_0(helper_fxtod);
2603 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2604 gen_op_store_DT0_fpr(DFPREG(rd));
2606 case 0x8c: /* V9 fxtoq */
2607 #if defined(CONFIG_USER_ONLY)
2608 gen_op_load_fpr_DT1(DFPREG(rs2));
2609 gen_clear_float_exceptions();
2610 tcg_gen_helper_0_0(helper_fxtoq);
2611 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2612 gen_op_store_QT0_fpr(QFPREG(rd));
2621 } else if (xop == 0x35) { /* FPU Operations */
2622 #ifdef TARGET_SPARC64
2625 if (gen_trap_ifnofpu(dc, cpu_cond))
2627 gen_op_clear_ieee_excp_and_FTT();
2628 rs1 = GET_FIELD(insn, 13, 17);
2629 rs2 = GET_FIELD(insn, 27, 31);
2630 xop = GET_FIELD(insn, 18, 26);
2631 #ifdef TARGET_SPARC64
2632 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2635 l1 = gen_new_label();
2636 cond = GET_FIELD_SP(insn, 14, 17);
2637 cpu_src1 = get_src1(insn, cpu_src1);
2638 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2639 tcg_const_tl(0), l1);
2640 gen_op_load_fpr_FT0(rs2);
2641 gen_op_store_FT0_fpr(rd);
2644 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2647 l1 = gen_new_label();
2648 cond = GET_FIELD_SP(insn, 14, 17);
2649 cpu_src1 = get_src1(insn, cpu_src1);
2650 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2651 tcg_const_tl(0), l1);
2652 gen_op_load_fpr_DT0(DFPREG(rs2));
2653 gen_op_store_DT0_fpr(DFPREG(rd));
2656 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2657 #if defined(CONFIG_USER_ONLY)
2660 l1 = gen_new_label();
2661 cond = GET_FIELD_SP(insn, 14, 17);
2662 cpu_src1 = get_src1(insn, cpu_src1);
2663 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2664 tcg_const_tl(0), l1);
2665 gen_op_load_fpr_QT0(QFPREG(rs2));
2666 gen_op_store_QT0_fpr(QFPREG(rd));
2675 #ifdef TARGET_SPARC64
2676 #define FMOVCC(size_FDQ, fcc) \
2681 l1 = gen_new_label(); \
2682 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2683 cond = GET_FIELD_SP(insn, 14, 17); \
2684 gen_fcond(r_cond, fcc, cond); \
2685 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2686 tcg_const_tl(0), l1); \
2687 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2688 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2689 gen_set_label(l1); \
2691 case 0x001: /* V9 fmovscc %fcc0 */
2694 case 0x002: /* V9 fmovdcc %fcc0 */
2697 case 0x003: /* V9 fmovqcc %fcc0 */
2698 #if defined(CONFIG_USER_ONLY)
2704 case 0x041: /* V9 fmovscc %fcc1 */
2707 case 0x042: /* V9 fmovdcc %fcc1 */
2710 case 0x043: /* V9 fmovqcc %fcc1 */
2711 #if defined(CONFIG_USER_ONLY)
2717 case 0x081: /* V9 fmovscc %fcc2 */
2720 case 0x082: /* V9 fmovdcc %fcc2 */
2723 case 0x083: /* V9 fmovqcc %fcc2 */
2724 #if defined(CONFIG_USER_ONLY)
2730 case 0x0c1: /* V9 fmovscc %fcc3 */
2733 case 0x0c2: /* V9 fmovdcc %fcc3 */
2736 case 0x0c3: /* V9 fmovqcc %fcc3 */
2737 #if defined(CONFIG_USER_ONLY)
2744 #define FMOVCC(size_FDQ, icc) \
2749 l1 = gen_new_label(); \
2750 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2751 cond = GET_FIELD_SP(insn, 14, 17); \
2752 gen_cond(r_cond, icc, cond); \
2753 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2754 tcg_const_tl(0), l1); \
2755 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2756 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2757 gen_set_label(l1); \
2760 case 0x101: /* V9 fmovscc %icc */
2763 case 0x102: /* V9 fmovdcc %icc */
2765 case 0x103: /* V9 fmovqcc %icc */
2766 #if defined(CONFIG_USER_ONLY)
2772 case 0x181: /* V9 fmovscc %xcc */
2775 case 0x182: /* V9 fmovdcc %xcc */
2778 case 0x183: /* V9 fmovqcc %xcc */
2779 #if defined(CONFIG_USER_ONLY)
2787 case 0x51: /* fcmps, V9 %fcc */
2788 gen_op_load_fpr_FT0(rs1);
2789 gen_op_load_fpr_FT1(rs2);
2790 gen_op_fcmps(rd & 3);
2792 case 0x52: /* fcmpd, V9 %fcc */
2793 gen_op_load_fpr_DT0(DFPREG(rs1));
2794 gen_op_load_fpr_DT1(DFPREG(rs2));
2795 gen_op_fcmpd(rd & 3);
2797 case 0x53: /* fcmpq, V9 %fcc */
2798 #if defined(CONFIG_USER_ONLY)
2799 gen_op_load_fpr_QT0(QFPREG(rs1));
2800 gen_op_load_fpr_QT1(QFPREG(rs2));
2801 gen_op_fcmpq(rd & 3);
2803 #else /* !defined(CONFIG_USER_ONLY) */
2806 case 0x55: /* fcmpes, V9 %fcc */
2807 gen_op_load_fpr_FT0(rs1);
2808 gen_op_load_fpr_FT1(rs2);
2809 gen_op_fcmpes(rd & 3);
2811 case 0x56: /* fcmped, V9 %fcc */
2812 gen_op_load_fpr_DT0(DFPREG(rs1));
2813 gen_op_load_fpr_DT1(DFPREG(rs2));
2814 gen_op_fcmped(rd & 3);
2816 case 0x57: /* fcmpeq, V9 %fcc */
2817 #if defined(CONFIG_USER_ONLY)
2818 gen_op_load_fpr_QT0(QFPREG(rs1));
2819 gen_op_load_fpr_QT1(QFPREG(rs2));
2820 gen_op_fcmpeq(rd & 3);
2822 #else/* !defined(CONFIG_USER_ONLY) */
2828 } else if (xop == 0x2) {
2831 rs1 = GET_FIELD(insn, 13, 17);
2833 // or %g0, x, y -> mov T0, x; mov y, T0
2834 if (IS_IMM) { /* immediate */
2835 rs2 = GET_FIELDs(insn, 19, 31);
2836 tcg_gen_movi_tl(cpu_dst, (int)rs2);
2837 } else { /* register */
2838 rs2 = GET_FIELD(insn, 27, 31);
2839 gen_movl_reg_TN(rs2, cpu_dst);
2842 cpu_src1 = get_src1(insn, cpu_src1);
2843 if (IS_IMM) { /* immediate */
2844 rs2 = GET_FIELDs(insn, 19, 31);
2845 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2846 } else { /* register */
2847 // or x, %g0, y -> mov T1, x; mov y, T1
2848 rs2 = GET_FIELD(insn, 27, 31);
2850 gen_movl_reg_TN(rs2, cpu_src2);
2851 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2855 gen_movl_TN_reg(rd, cpu_dst);
2856 #ifdef TARGET_SPARC64
2857 } else if (xop == 0x25) { /* sll, V9 sllx */
2858 cpu_src1 = get_src1(insn, cpu_src1);
2859 if (IS_IMM) { /* immediate */
2860 rs2 = GET_FIELDs(insn, 20, 31);
2861 if (insn & (1 << 12)) {
2862 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2864 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2865 tcg_gen_shli_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2867 } else { /* register */
2868 rs2 = GET_FIELD(insn, 27, 31);
2869 gen_movl_reg_TN(rs2, cpu_src2);
2870 if (insn & (1 << 12)) {
2871 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2872 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2874 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2875 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2876 tcg_gen_shl_i64(cpu_dst, cpu_dst, cpu_tmp0);
2879 gen_movl_TN_reg(rd, cpu_dst);
2880 } else if (xop == 0x26) { /* srl, V9 srlx */
2881 cpu_src1 = get_src1(insn, cpu_src1);
2882 if (IS_IMM) { /* immediate */
2883 rs2 = GET_FIELDs(insn, 20, 31);
2884 if (insn & (1 << 12)) {
2885 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2887 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2888 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2890 } else { /* register */
2891 rs2 = GET_FIELD(insn, 27, 31);
2892 gen_movl_reg_TN(rs2, cpu_src2);
2893 if (insn & (1 << 12)) {
2894 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2895 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2897 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2898 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2899 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2902 gen_movl_TN_reg(rd, cpu_dst);
2903 } else if (xop == 0x27) { /* sra, V9 srax */
2904 cpu_src1 = get_src1(insn, cpu_src1);
2905 if (IS_IMM) { /* immediate */
2906 rs2 = GET_FIELDs(insn, 20, 31);
2907 if (insn & (1 << 12)) {
2908 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2910 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2911 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2912 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2914 } else { /* register */
2915 rs2 = GET_FIELD(insn, 27, 31);
2916 gen_movl_reg_TN(rs2, cpu_src2);
2917 if (insn & (1 << 12)) {
2918 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2919 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2921 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2922 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2923 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2926 gen_movl_TN_reg(rd, cpu_dst);
2928 } else if (xop < 0x36) {
2929 cpu_src1 = get_src1(insn, cpu_src1);
2930 cpu_src2 = get_src2(insn, cpu_src2);
2932 switch (xop & ~0x10) {
2935 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2937 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2940 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
2942 gen_op_logic_cc(cpu_dst);
2945 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2947 gen_op_logic_cc(cpu_dst);
2950 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
2952 gen_op_logic_cc(cpu_dst);
2956 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
2958 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
2961 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2962 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
2964 gen_op_logic_cc(cpu_dst);
2967 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2968 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
2970 gen_op_logic_cc(cpu_dst);
2973 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2974 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
2976 gen_op_logic_cc(cpu_dst);
2980 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
2982 gen_mov_reg_C(cpu_tmp0, cpu_psr);
2983 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
2984 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
2987 #ifdef TARGET_SPARC64
2988 case 0x9: /* V9 mulx */
2989 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
2993 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
2995 gen_op_logic_cc(cpu_dst);
2998 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3000 gen_op_logic_cc(cpu_dst);
3004 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3006 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3007 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3008 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3011 #ifdef TARGET_SPARC64
3012 case 0xd: /* V9 udivx */
3013 gen_trap_ifdivzero_tl(cpu_src2);
3014 tcg_gen_divu_i64(cpu_dst, cpu_src1, cpu_src2);
3018 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1, cpu_src2);
3020 gen_op_div_cc(cpu_dst);
3023 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1, cpu_src2);
3025 gen_op_div_cc(cpu_dst);
3030 gen_movl_TN_reg(rd, cpu_dst);
3033 case 0x20: /* taddcc */
3034 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3035 gen_movl_TN_reg(rd, cpu_dst);
3037 case 0x21: /* tsubcc */
3038 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3039 gen_movl_TN_reg(rd, cpu_dst);
3041 case 0x22: /* taddcctv */
3042 save_state(dc, cpu_cond);
3043 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3044 gen_movl_TN_reg(rd, cpu_dst);
3046 case 0x23: /* tsubcctv */
3047 save_state(dc, cpu_cond);
3048 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3049 gen_movl_TN_reg(rd, cpu_dst);
3051 case 0x24: /* mulscc */
3052 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3053 gen_movl_TN_reg(rd, cpu_dst);
3055 #ifndef TARGET_SPARC64
3056 case 0x25: /* sll */
3057 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3058 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3059 gen_movl_TN_reg(rd, cpu_dst);
3061 case 0x26: /* srl */
3062 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3063 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3064 gen_movl_TN_reg(rd, cpu_dst);
3066 case 0x27: /* sra */
3067 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3068 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3069 gen_movl_TN_reg(rd, cpu_dst);
3076 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3077 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
3079 #ifndef TARGET_SPARC64
3080 case 0x01 ... 0x0f: /* undefined in the
3084 case 0x10 ... 0x1f: /* implementation-dependent
3090 case 0x2: /* V9 wrccr */
3091 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3092 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3094 case 0x3: /* V9 wrasi */
3095 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3096 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3097 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
3099 case 0x6: /* V9 wrfprs */
3100 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3101 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3102 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
3103 save_state(dc, cpu_cond);
3108 case 0xf: /* V9 sir, nop if user */
3109 #if !defined(CONFIG_USER_ONLY)
3114 case 0x13: /* Graphics Status */
3115 if (gen_trap_ifnofpu(dc, cpu_cond))
3117 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3118 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
3120 case 0x17: /* Tick compare */
3121 #if !defined(CONFIG_USER_ONLY)
3122 if (!supervisor(dc))
3128 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3130 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3132 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3133 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3134 offsetof(CPUState, tick));
3135 tcg_gen_helper_0_2(helper_tick_set_limit,
3136 r_tickptr, cpu_dst);
3139 case 0x18: /* System tick */
3140 #if !defined(CONFIG_USER_ONLY)
3141 if (!supervisor(dc))
3147 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3149 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3150 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3151 offsetof(CPUState, stick));
3152 tcg_gen_helper_0_2(helper_tick_set_count,
3153 r_tickptr, cpu_dst);
3156 case 0x19: /* System tick compare */
3157 #if !defined(CONFIG_USER_ONLY)
3158 if (!supervisor(dc))
3164 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3166 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3168 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3169 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3170 offsetof(CPUState, stick));
3171 tcg_gen_helper_0_2(helper_tick_set_limit,
3172 r_tickptr, cpu_dst);
3176 case 0x10: /* Performance Control */
3177 case 0x11: /* Performance Instrumentation Counter */
3178 case 0x12: /* Dispatch Control */
3179 case 0x14: /* Softint set */
3180 case 0x15: /* Softint clear */
3181 case 0x16: /* Softint write */
3188 #if !defined(CONFIG_USER_ONLY)
3189 case 0x31: /* wrpsr, V9 saved, restored */
3191 if (!supervisor(dc))
3193 #ifdef TARGET_SPARC64
3196 tcg_gen_helper_0_0(helper_saved);
3199 tcg_gen_helper_0_0(helper_restored);
3201 case 2: /* UA2005 allclean */
3202 case 3: /* UA2005 otherw */
3203 case 4: /* UA2005 normalw */
3204 case 5: /* UA2005 invalw */
3210 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3211 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3212 save_state(dc, cpu_cond);
3219 case 0x32: /* wrwim, V9 wrpr */
3221 if (!supervisor(dc))
3223 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3224 #ifdef TARGET_SPARC64
3230 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3231 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3232 offsetof(CPUState, tsptr));
3233 tcg_gen_st_tl(cpu_dst, r_tsptr,
3234 offsetof(trap_state, tpc));
3241 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3242 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3243 offsetof(CPUState, tsptr));
3244 tcg_gen_st_tl(cpu_dst, r_tsptr,
3245 offsetof(trap_state, tnpc));
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_dst, r_tsptr,
3256 offsetof(trap_state, tstate));
3263 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3264 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3265 offsetof(CPUState, tsptr));
3266 tcg_gen_st_i32(cpu_dst, r_tsptr,
3267 offsetof(trap_state, tt));
3274 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3275 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3276 offsetof(CPUState, tick));
3277 tcg_gen_helper_0_2(helper_tick_set_count,
3278 r_tickptr, cpu_dst);
3282 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
3285 save_state(dc, cpu_cond);
3286 tcg_gen_helper_0_1(helper_wrpstate, cpu_dst);
3292 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3293 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
3296 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3297 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
3300 tcg_gen_helper_0_1(helper_wrcwp, cpu_dst);
3303 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3304 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
3306 case 11: // canrestore
3307 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3308 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
3310 case 12: // cleanwin
3311 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3312 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
3314 case 13: // otherwin
3315 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3316 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
3319 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3320 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
3322 case 16: // UA2005 gl
3323 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3324 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
3326 case 26: // UA2005 strand status
3327 if (!hypervisor(dc))
3329 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3330 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
3336 tcg_gen_andi_tl(cpu_dst, cpu_dst, ((1 << NWINDOWS) - 1));
3337 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3338 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
3342 case 0x33: /* wrtbr, UA2005 wrhpr */
3344 #ifndef TARGET_SPARC64
3345 if (!supervisor(dc))
3347 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3348 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
3350 if (!hypervisor(dc))
3352 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3355 // XXX gen_op_wrhpstate();
3356 save_state(dc, cpu_cond);
3362 // XXX gen_op_wrhtstate();
3365 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3366 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
3369 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3370 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
3372 case 31: // hstick_cmpr
3376 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3378 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3379 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3380 offsetof(CPUState, hstick));
3381 tcg_gen_helper_0_2(helper_tick_set_limit,
3382 r_tickptr, cpu_dst);
3385 case 6: // hver readonly
3393 #ifdef TARGET_SPARC64
3394 case 0x2c: /* V9 movcc */
3396 int cc = GET_FIELD_SP(insn, 11, 12);
3397 int cond = GET_FIELD_SP(insn, 14, 17);
3401 r_cond = tcg_temp_new(TCG_TYPE_TL);
3402 if (insn & (1 << 18)) {
3404 gen_cond(r_cond, 0, cond);
3406 gen_cond(r_cond, 1, cond);
3410 gen_fcond(r_cond, cc, cond);
3413 l1 = gen_new_label();
3415 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond,
3416 tcg_const_tl(0), l1);
3417 if (IS_IMM) { /* immediate */
3418 rs2 = GET_FIELD_SPs(insn, 0, 10);
3419 tcg_gen_movi_tl(cpu_dst, (int)rs2);
3421 rs2 = GET_FIELD_SP(insn, 0, 4);
3422 gen_movl_reg_TN(rs2, cpu_dst);
3424 gen_movl_TN_reg(rd, cpu_dst);
3428 case 0x2d: /* V9 sdivx */
3429 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3430 gen_movl_TN_reg(rd, cpu_dst);
3432 case 0x2e: /* V9 popc */
3434 cpu_src2 = get_src2(insn, cpu_src2);
3435 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3437 gen_movl_TN_reg(rd, cpu_dst);
3439 case 0x2f: /* V9 movr */
3441 int cond = GET_FIELD_SP(insn, 10, 12);
3444 cpu_src1 = get_src1(insn, cpu_src1);
3446 l1 = gen_new_label();
3448 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
3449 tcg_const_tl(0), l1);
3450 if (IS_IMM) { /* immediate */
3451 rs2 = GET_FIELD_SPs(insn, 0, 9);
3452 tcg_gen_movi_tl(cpu_dst, (int)rs2);
3454 rs2 = GET_FIELD_SP(insn, 0, 4);
3455 gen_movl_reg_TN(rs2, cpu_dst);
3457 gen_movl_TN_reg(rd, cpu_dst);
3466 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3467 #ifdef TARGET_SPARC64
3468 int opf = GET_FIELD_SP(insn, 5, 13);
3469 rs1 = GET_FIELD(insn, 13, 17);
3470 rs2 = GET_FIELD(insn, 27, 31);
3471 if (gen_trap_ifnofpu(dc, cpu_cond))
3475 case 0x000: /* VIS I edge8cc */
3476 case 0x001: /* VIS II edge8n */
3477 case 0x002: /* VIS I edge8lcc */
3478 case 0x003: /* VIS II edge8ln */
3479 case 0x004: /* VIS I edge16cc */
3480 case 0x005: /* VIS II edge16n */
3481 case 0x006: /* VIS I edge16lcc */
3482 case 0x007: /* VIS II edge16ln */
3483 case 0x008: /* VIS I edge32cc */
3484 case 0x009: /* VIS II edge32n */
3485 case 0x00a: /* VIS I edge32lcc */
3486 case 0x00b: /* VIS II edge32ln */
3489 case 0x010: /* VIS I array8 */
3490 cpu_src1 = get_src1(insn, cpu_src1);
3491 gen_movl_reg_TN(rs2, cpu_src2);
3492 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3494 gen_movl_TN_reg(rd, cpu_dst);
3496 case 0x012: /* VIS I array16 */
3497 cpu_src1 = get_src1(insn, cpu_src1);
3498 gen_movl_reg_TN(rs2, cpu_src2);
3499 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3501 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3502 gen_movl_TN_reg(rd, cpu_dst);
3504 case 0x014: /* VIS I array32 */
3505 cpu_src1 = get_src1(insn, cpu_src1);
3506 gen_movl_reg_TN(rs2, cpu_src2);
3507 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3509 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3510 gen_movl_TN_reg(rd, cpu_dst);
3512 case 0x018: /* VIS I alignaddr */
3513 cpu_src1 = get_src1(insn, cpu_src1);
3514 gen_movl_reg_TN(rs2, cpu_src2);
3515 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3517 gen_movl_TN_reg(rd, cpu_dst);
3519 case 0x019: /* VIS II bmask */
3520 case 0x01a: /* VIS I alignaddrl */
3523 case 0x020: /* VIS I fcmple16 */
3524 gen_op_load_fpr_DT0(DFPREG(rs1));
3525 gen_op_load_fpr_DT1(DFPREG(rs2));
3526 tcg_gen_helper_0_0(helper_fcmple16);
3527 gen_op_store_DT0_fpr(DFPREG(rd));
3529 case 0x022: /* VIS I fcmpne16 */
3530 gen_op_load_fpr_DT0(DFPREG(rs1));
3531 gen_op_load_fpr_DT1(DFPREG(rs2));
3532 tcg_gen_helper_0_0(helper_fcmpne16);
3533 gen_op_store_DT0_fpr(DFPREG(rd));
3535 case 0x024: /* VIS I fcmple32 */
3536 gen_op_load_fpr_DT0(DFPREG(rs1));
3537 gen_op_load_fpr_DT1(DFPREG(rs2));
3538 tcg_gen_helper_0_0(helper_fcmple32);
3539 gen_op_store_DT0_fpr(DFPREG(rd));
3541 case 0x026: /* VIS I fcmpne32 */
3542 gen_op_load_fpr_DT0(DFPREG(rs1));
3543 gen_op_load_fpr_DT1(DFPREG(rs2));
3544 tcg_gen_helper_0_0(helper_fcmpne32);
3545 gen_op_store_DT0_fpr(DFPREG(rd));
3547 case 0x028: /* VIS I fcmpgt16 */
3548 gen_op_load_fpr_DT0(DFPREG(rs1));
3549 gen_op_load_fpr_DT1(DFPREG(rs2));
3550 tcg_gen_helper_0_0(helper_fcmpgt16);
3551 gen_op_store_DT0_fpr(DFPREG(rd));
3553 case 0x02a: /* VIS I fcmpeq16 */
3554 gen_op_load_fpr_DT0(DFPREG(rs1));
3555 gen_op_load_fpr_DT1(DFPREG(rs2));
3556 tcg_gen_helper_0_0(helper_fcmpeq16);
3557 gen_op_store_DT0_fpr(DFPREG(rd));
3559 case 0x02c: /* VIS I fcmpgt32 */
3560 gen_op_load_fpr_DT0(DFPREG(rs1));
3561 gen_op_load_fpr_DT1(DFPREG(rs2));
3562 tcg_gen_helper_0_0(helper_fcmpgt32);
3563 gen_op_store_DT0_fpr(DFPREG(rd));
3565 case 0x02e: /* VIS I fcmpeq32 */
3566 gen_op_load_fpr_DT0(DFPREG(rs1));
3567 gen_op_load_fpr_DT1(DFPREG(rs2));
3568 tcg_gen_helper_0_0(helper_fcmpeq32);
3569 gen_op_store_DT0_fpr(DFPREG(rd));
3571 case 0x031: /* VIS I fmul8x16 */
3572 gen_op_load_fpr_DT0(DFPREG(rs1));
3573 gen_op_load_fpr_DT1(DFPREG(rs2));
3574 tcg_gen_helper_0_0(helper_fmul8x16);
3575 gen_op_store_DT0_fpr(DFPREG(rd));
3577 case 0x033: /* VIS I fmul8x16au */
3578 gen_op_load_fpr_DT0(DFPREG(rs1));
3579 gen_op_load_fpr_DT1(DFPREG(rs2));
3580 tcg_gen_helper_0_0(helper_fmul8x16au);
3581 gen_op_store_DT0_fpr(DFPREG(rd));
3583 case 0x035: /* VIS I fmul8x16al */
3584 gen_op_load_fpr_DT0(DFPREG(rs1));
3585 gen_op_load_fpr_DT1(DFPREG(rs2));
3586 tcg_gen_helper_0_0(helper_fmul8x16al);
3587 gen_op_store_DT0_fpr(DFPREG(rd));
3589 case 0x036: /* VIS I fmul8sux16 */
3590 gen_op_load_fpr_DT0(DFPREG(rs1));
3591 gen_op_load_fpr_DT1(DFPREG(rs2));
3592 tcg_gen_helper_0_0(helper_fmul8sux16);
3593 gen_op_store_DT0_fpr(DFPREG(rd));
3595 case 0x037: /* VIS I fmul8ulx16 */
3596 gen_op_load_fpr_DT0(DFPREG(rs1));
3597 gen_op_load_fpr_DT1(DFPREG(rs2));
3598 tcg_gen_helper_0_0(helper_fmul8ulx16);
3599 gen_op_store_DT0_fpr(DFPREG(rd));
3601 case 0x038: /* VIS I fmuld8sux16 */
3602 gen_op_load_fpr_DT0(DFPREG(rs1));
3603 gen_op_load_fpr_DT1(DFPREG(rs2));
3604 tcg_gen_helper_0_0(helper_fmuld8sux16);
3605 gen_op_store_DT0_fpr(DFPREG(rd));
3607 case 0x039: /* VIS I fmuld8ulx16 */
3608 gen_op_load_fpr_DT0(DFPREG(rs1));
3609 gen_op_load_fpr_DT1(DFPREG(rs2));
3610 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3611 gen_op_store_DT0_fpr(DFPREG(rd));
3613 case 0x03a: /* VIS I fpack32 */
3614 case 0x03b: /* VIS I fpack16 */
3615 case 0x03d: /* VIS I fpackfix */
3616 case 0x03e: /* VIS I pdist */
3619 case 0x048: /* VIS I faligndata */
3620 gen_op_load_fpr_DT0(DFPREG(rs1));
3621 gen_op_load_fpr_DT1(DFPREG(rs2));
3622 tcg_gen_helper_0_0(helper_faligndata);
3623 gen_op_store_DT0_fpr(DFPREG(rd));
3625 case 0x04b: /* VIS I fpmerge */
3626 gen_op_load_fpr_DT0(DFPREG(rs1));
3627 gen_op_load_fpr_DT1(DFPREG(rs2));
3628 tcg_gen_helper_0_0(helper_fpmerge);
3629 gen_op_store_DT0_fpr(DFPREG(rd));
3631 case 0x04c: /* VIS II bshuffle */
3634 case 0x04d: /* VIS I fexpand */
3635 gen_op_load_fpr_DT0(DFPREG(rs1));
3636 gen_op_load_fpr_DT1(DFPREG(rs2));
3637 tcg_gen_helper_0_0(helper_fexpand);
3638 gen_op_store_DT0_fpr(DFPREG(rd));
3640 case 0x050: /* VIS I fpadd16 */
3641 gen_op_load_fpr_DT0(DFPREG(rs1));
3642 gen_op_load_fpr_DT1(DFPREG(rs2));
3643 tcg_gen_helper_0_0(helper_fpadd16);
3644 gen_op_store_DT0_fpr(DFPREG(rd));
3646 case 0x051: /* VIS I fpadd16s */
3647 gen_op_load_fpr_FT0(rs1);
3648 gen_op_load_fpr_FT1(rs2);
3649 tcg_gen_helper_0_0(helper_fpadd16s);
3650 gen_op_store_FT0_fpr(rd);
3652 case 0x052: /* VIS I fpadd32 */
3653 gen_op_load_fpr_DT0(DFPREG(rs1));
3654 gen_op_load_fpr_DT1(DFPREG(rs2));
3655 tcg_gen_helper_0_0(helper_fpadd32);
3656 gen_op_store_DT0_fpr(DFPREG(rd));
3658 case 0x053: /* VIS I fpadd32s */
3659 gen_op_load_fpr_FT0(rs1);
3660 gen_op_load_fpr_FT1(rs2);
3661 tcg_gen_helper_0_0(helper_fpadd32s);
3662 gen_op_store_FT0_fpr(rd);
3664 case 0x054: /* VIS I fpsub16 */
3665 gen_op_load_fpr_DT0(DFPREG(rs1));
3666 gen_op_load_fpr_DT1(DFPREG(rs2));
3667 tcg_gen_helper_0_0(helper_fpsub16);
3668 gen_op_store_DT0_fpr(DFPREG(rd));
3670 case 0x055: /* VIS I fpsub16s */
3671 gen_op_load_fpr_FT0(rs1);
3672 gen_op_load_fpr_FT1(rs2);
3673 tcg_gen_helper_0_0(helper_fpsub16s);
3674 gen_op_store_FT0_fpr(rd);
3676 case 0x056: /* VIS I fpsub32 */
3677 gen_op_load_fpr_DT0(DFPREG(rs1));
3678 gen_op_load_fpr_DT1(DFPREG(rs2));
3679 tcg_gen_helper_0_0(helper_fpadd32);
3680 gen_op_store_DT0_fpr(DFPREG(rd));
3682 case 0x057: /* VIS I fpsub32s */
3683 gen_op_load_fpr_FT0(rs1);
3684 gen_op_load_fpr_FT1(rs2);
3685 tcg_gen_helper_0_0(helper_fpsub32s);
3686 gen_op_store_FT0_fpr(rd);
3688 case 0x060: /* VIS I fzero */
3689 tcg_gen_helper_0_0(helper_movl_DT0_0);
3690 gen_op_store_DT0_fpr(DFPREG(rd));
3692 case 0x061: /* VIS I fzeros */
3693 tcg_gen_helper_0_0(helper_movl_FT0_0);
3694 gen_op_store_FT0_fpr(rd);
3696 case 0x062: /* VIS I fnor */
3697 gen_op_load_fpr_DT0(DFPREG(rs1));
3698 gen_op_load_fpr_DT1(DFPREG(rs2));
3699 tcg_gen_helper_0_0(helper_fnor);
3700 gen_op_store_DT0_fpr(DFPREG(rd));
3702 case 0x063: /* VIS I fnors */
3703 gen_op_load_fpr_FT0(rs1);
3704 gen_op_load_fpr_FT1(rs2);
3705 tcg_gen_helper_0_0(helper_fnors);
3706 gen_op_store_FT0_fpr(rd);
3708 case 0x064: /* VIS I fandnot2 */
3709 gen_op_load_fpr_DT1(DFPREG(rs1));
3710 gen_op_load_fpr_DT0(DFPREG(rs2));
3711 tcg_gen_helper_0_0(helper_fandnot);
3712 gen_op_store_DT0_fpr(DFPREG(rd));
3714 case 0x065: /* VIS I fandnot2s */
3715 gen_op_load_fpr_FT1(rs1);
3716 gen_op_load_fpr_FT0(rs2);
3717 tcg_gen_helper_0_0(helper_fandnots);
3718 gen_op_store_FT0_fpr(rd);
3720 case 0x066: /* VIS I fnot2 */
3721 gen_op_load_fpr_DT1(DFPREG(rs2));
3722 tcg_gen_helper_0_0(helper_fnot);
3723 gen_op_store_DT0_fpr(DFPREG(rd));
3725 case 0x067: /* VIS I fnot2s */
3726 gen_op_load_fpr_FT1(rs2);
3727 tcg_gen_helper_0_0(helper_fnot);
3728 gen_op_store_FT0_fpr(rd);
3730 case 0x068: /* VIS I fandnot1 */
3731 gen_op_load_fpr_DT0(DFPREG(rs1));
3732 gen_op_load_fpr_DT1(DFPREG(rs2));
3733 tcg_gen_helper_0_0(helper_fandnot);
3734 gen_op_store_DT0_fpr(DFPREG(rd));
3736 case 0x069: /* VIS I fandnot1s */
3737 gen_op_load_fpr_FT0(rs1);
3738 gen_op_load_fpr_FT1(rs2);
3739 tcg_gen_helper_0_0(helper_fandnots);
3740 gen_op_store_FT0_fpr(rd);
3742 case 0x06a: /* VIS I fnot1 */
3743 gen_op_load_fpr_DT1(DFPREG(rs1));
3744 tcg_gen_helper_0_0(helper_fnot);
3745 gen_op_store_DT0_fpr(DFPREG(rd));
3747 case 0x06b: /* VIS I fnot1s */
3748 gen_op_load_fpr_FT1(rs1);
3749 tcg_gen_helper_0_0(helper_fnot);
3750 gen_op_store_FT0_fpr(rd);
3752 case 0x06c: /* VIS I fxor */
3753 gen_op_load_fpr_DT0(DFPREG(rs1));
3754 gen_op_load_fpr_DT1(DFPREG(rs2));
3755 tcg_gen_helper_0_0(helper_fxor);
3756 gen_op_store_DT0_fpr(DFPREG(rd));
3758 case 0x06d: /* VIS I fxors */
3759 gen_op_load_fpr_FT0(rs1);
3760 gen_op_load_fpr_FT1(rs2);
3761 tcg_gen_helper_0_0(helper_fxors);
3762 gen_op_store_FT0_fpr(rd);
3764 case 0x06e: /* VIS I fnand */
3765 gen_op_load_fpr_DT0(DFPREG(rs1));
3766 gen_op_load_fpr_DT1(DFPREG(rs2));
3767 tcg_gen_helper_0_0(helper_fnand);
3768 gen_op_store_DT0_fpr(DFPREG(rd));
3770 case 0x06f: /* VIS I fnands */
3771 gen_op_load_fpr_FT0(rs1);
3772 gen_op_load_fpr_FT1(rs2);
3773 tcg_gen_helper_0_0(helper_fnands);
3774 gen_op_store_FT0_fpr(rd);
3776 case 0x070: /* VIS I fand */
3777 gen_op_load_fpr_DT0(DFPREG(rs1));
3778 gen_op_load_fpr_DT1(DFPREG(rs2));
3779 tcg_gen_helper_0_0(helper_fand);
3780 gen_op_store_DT0_fpr(DFPREG(rd));
3782 case 0x071: /* VIS I fands */
3783 gen_op_load_fpr_FT0(rs1);
3784 gen_op_load_fpr_FT1(rs2);
3785 tcg_gen_helper_0_0(helper_fands);
3786 gen_op_store_FT0_fpr(rd);
3788 case 0x072: /* VIS I fxnor */
3789 gen_op_load_fpr_DT0(DFPREG(rs1));
3790 gen_op_load_fpr_DT1(DFPREG(rs2));
3791 tcg_gen_helper_0_0(helper_fxnor);
3792 gen_op_store_DT0_fpr(DFPREG(rd));
3794 case 0x073: /* VIS I fxnors */
3795 gen_op_load_fpr_FT0(rs1);
3796 gen_op_load_fpr_FT1(rs2);
3797 tcg_gen_helper_0_0(helper_fxnors);
3798 gen_op_store_FT0_fpr(rd);
3800 case 0x074: /* VIS I fsrc1 */
3801 gen_op_load_fpr_DT0(DFPREG(rs1));
3802 gen_op_store_DT0_fpr(DFPREG(rd));
3804 case 0x075: /* VIS I fsrc1s */
3805 gen_op_load_fpr_FT0(rs1);
3806 gen_op_store_FT0_fpr(rd);
3808 case 0x076: /* VIS I fornot2 */
3809 gen_op_load_fpr_DT1(DFPREG(rs1));
3810 gen_op_load_fpr_DT0(DFPREG(rs2));
3811 tcg_gen_helper_0_0(helper_fornot);
3812 gen_op_store_DT0_fpr(DFPREG(rd));
3814 case 0x077: /* VIS I fornot2s */
3815 gen_op_load_fpr_FT1(rs1);
3816 gen_op_load_fpr_FT0(rs2);
3817 tcg_gen_helper_0_0(helper_fornots);
3818 gen_op_store_FT0_fpr(rd);
3820 case 0x078: /* VIS I fsrc2 */
3821 gen_op_load_fpr_DT0(DFPREG(rs2));
3822 gen_op_store_DT0_fpr(DFPREG(rd));
3824 case 0x079: /* VIS I fsrc2s */
3825 gen_op_load_fpr_FT0(rs2);
3826 gen_op_store_FT0_fpr(rd);
3828 case 0x07a: /* VIS I fornot1 */
3829 gen_op_load_fpr_DT0(DFPREG(rs1));
3830 gen_op_load_fpr_DT1(DFPREG(rs2));
3831 tcg_gen_helper_0_0(helper_fornot);
3832 gen_op_store_DT0_fpr(DFPREG(rd));
3834 case 0x07b: /* VIS I fornot1s */
3835 gen_op_load_fpr_FT0(rs1);
3836 gen_op_load_fpr_FT1(rs2);
3837 tcg_gen_helper_0_0(helper_fornots);
3838 gen_op_store_FT0_fpr(rd);
3840 case 0x07c: /* VIS I for */
3841 gen_op_load_fpr_DT0(DFPREG(rs1));
3842 gen_op_load_fpr_DT1(DFPREG(rs2));
3843 tcg_gen_helper_0_0(helper_for);
3844 gen_op_store_DT0_fpr(DFPREG(rd));
3846 case 0x07d: /* VIS I fors */
3847 gen_op_load_fpr_FT0(rs1);
3848 gen_op_load_fpr_FT1(rs2);
3849 tcg_gen_helper_0_0(helper_fors);
3850 gen_op_store_FT0_fpr(rd);
3852 case 0x07e: /* VIS I fone */
3853 tcg_gen_helper_0_0(helper_movl_DT0_1);
3854 gen_op_store_DT0_fpr(DFPREG(rd));
3856 case 0x07f: /* VIS I fones */
3857 tcg_gen_helper_0_0(helper_movl_FT0_1);
3858 gen_op_store_FT0_fpr(rd);
3860 case 0x080: /* VIS I shutdown */
3861 case 0x081: /* VIS II siam */
3870 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
3871 #ifdef TARGET_SPARC64
3876 #ifdef TARGET_SPARC64
3877 } else if (xop == 0x39) { /* V9 return */
3878 save_state(dc, cpu_cond);
3879 cpu_src1 = get_src1(insn, cpu_src1);
3880 if (IS_IMM) { /* immediate */
3881 rs2 = GET_FIELDs(insn, 19, 31);
3882 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3883 } else { /* register */
3884 rs2 = GET_FIELD(insn, 27, 31);
3886 gen_movl_reg_TN(rs2, cpu_src2);
3887 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3890 tcg_gen_helper_0_0(helper_restore);
3891 gen_mov_pc_npc(dc, cpu_cond);
3892 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3893 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3894 dc->npc = DYNAMIC_PC;
3898 cpu_src1 = get_src1(insn, cpu_src1);
3899 if (IS_IMM) { /* immediate */
3900 rs2 = GET_FIELDs(insn, 19, 31);
3901 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3902 } else { /* register */
3903 rs2 = GET_FIELD(insn, 27, 31);
3905 gen_movl_reg_TN(rs2, cpu_src2);
3906 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3910 case 0x38: /* jmpl */
3913 tcg_gen_movi_tl(cpu_tmp0, dc->pc);
3914 gen_movl_TN_reg(rd, cpu_tmp0);
3916 gen_mov_pc_npc(dc, cpu_cond);
3917 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3918 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3919 dc->npc = DYNAMIC_PC;
3922 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
3923 case 0x39: /* rett, V9 return */
3925 if (!supervisor(dc))
3927 gen_mov_pc_npc(dc, cpu_cond);
3928 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3929 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3930 dc->npc = DYNAMIC_PC;
3931 tcg_gen_helper_0_0(helper_rett);
3935 case 0x3b: /* flush */
3936 tcg_gen_helper_0_1(helper_flush, cpu_dst);
3938 case 0x3c: /* save */
3939 save_state(dc, cpu_cond);
3940 tcg_gen_helper_0_0(helper_save);
3941 gen_movl_TN_reg(rd, cpu_dst);
3943 case 0x3d: /* restore */
3944 save_state(dc, cpu_cond);
3945 tcg_gen_helper_0_0(helper_restore);
3946 gen_movl_TN_reg(rd, cpu_dst);
3948 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
3949 case 0x3e: /* V9 done/retry */
3953 if (!supervisor(dc))
3955 dc->npc = DYNAMIC_PC;
3956 dc->pc = DYNAMIC_PC;
3957 tcg_gen_helper_0_0(helper_done);
3960 if (!supervisor(dc))
3962 dc->npc = DYNAMIC_PC;
3963 dc->pc = DYNAMIC_PC;
3964 tcg_gen_helper_0_0(helper_retry);
3979 case 3: /* load/store instructions */
3981 unsigned int xop = GET_FIELD(insn, 7, 12);
3983 save_state(dc, cpu_cond);
3984 cpu_src1 = get_src1(insn, cpu_src1);
3985 if (xop == 0x3c || xop == 0x3e)
3987 rs2 = GET_FIELD(insn, 27, 31);
3988 gen_movl_reg_TN(rs2, cpu_src2);
3990 else if (IS_IMM) { /* immediate */
3991 rs2 = GET_FIELDs(insn, 19, 31);
3992 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
3993 } else { /* register */
3994 rs2 = GET_FIELD(insn, 27, 31);
3996 gen_movl_reg_TN(rs2, cpu_src2);
3997 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4000 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4001 (xop > 0x17 && xop <= 0x1d ) ||
4002 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4004 case 0x0: /* load unsigned word */
4005 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4006 ABI32_MASK(cpu_addr);
4007 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4009 case 0x1: /* load unsigned byte */
4010 ABI32_MASK(cpu_addr);
4011 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4013 case 0x2: /* load unsigned halfword */
4014 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4015 ABI32_MASK(cpu_addr);
4016 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4018 case 0x3: /* load double word */
4022 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4023 ABI32_MASK(cpu_addr);
4024 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4025 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4026 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4027 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4028 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4029 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4030 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4033 case 0x9: /* load signed byte */
4034 ABI32_MASK(cpu_addr);
4035 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4037 case 0xa: /* load signed halfword */
4038 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4039 ABI32_MASK(cpu_addr);
4040 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4042 case 0xd: /* ldstub -- XXX: should be atomically */
4043 ABI32_MASK(cpu_addr);
4044 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4045 tcg_gen_qemu_st8(tcg_const_tl(0xff), cpu_addr, dc->mem_idx);
4047 case 0x0f: /* swap register with memory. Also atomically */
4048 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4049 gen_movl_reg_TN(rd, cpu_val);
4050 ABI32_MASK(cpu_addr);
4051 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4052 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4053 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4055 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4056 case 0x10: /* load word alternate */
4057 #ifndef TARGET_SPARC64
4060 if (!supervisor(dc))
4063 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4064 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4066 case 0x11: /* load unsigned byte alternate */
4067 #ifndef TARGET_SPARC64
4070 if (!supervisor(dc))
4073 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4075 case 0x12: /* load unsigned halfword alternate */
4076 #ifndef TARGET_SPARC64
4079 if (!supervisor(dc))
4082 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4083 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4085 case 0x13: /* load double word alternate */
4086 #ifndef TARGET_SPARC64
4089 if (!supervisor(dc))
4094 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4095 gen_ldda_asi(cpu_tmp0, cpu_val, cpu_addr, insn);
4096 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4098 case 0x19: /* load signed byte alternate */
4099 #ifndef TARGET_SPARC64
4102 if (!supervisor(dc))
4105 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4107 case 0x1a: /* load signed halfword alternate */
4108 #ifndef TARGET_SPARC64
4111 if (!supervisor(dc))
4114 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4115 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4117 case 0x1d: /* ldstuba -- XXX: should be atomically */
4118 #ifndef TARGET_SPARC64
4121 if (!supervisor(dc))
4124 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4126 case 0x1f: /* swap reg with alt. memory. Also atomically */
4127 #ifndef TARGET_SPARC64
4130 if (!supervisor(dc))
4133 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4134 gen_movl_reg_TN(rd, cpu_val);
4135 gen_swap_asi(cpu_val, cpu_addr, insn);
4138 #ifndef TARGET_SPARC64
4139 case 0x30: /* ldc */
4140 case 0x31: /* ldcsr */
4141 case 0x33: /* lddc */
4145 #ifdef TARGET_SPARC64
4146 case 0x08: /* V9 ldsw */
4147 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4148 ABI32_MASK(cpu_addr);
4149 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4151 case 0x0b: /* V9 ldx */
4152 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4153 ABI32_MASK(cpu_addr);
4154 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4156 case 0x18: /* V9 ldswa */
4157 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4158 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4160 case 0x1b: /* V9 ldxa */
4161 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4162 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4164 case 0x2d: /* V9 prefetch, no effect */
4166 case 0x30: /* V9 ldfa */
4167 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4168 gen_ldf_asi(cpu_addr, insn, 4, rd);
4170 case 0x33: /* V9 lddfa */
4171 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4172 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4174 case 0x3d: /* V9 prefetcha, no effect */
4176 case 0x32: /* V9 ldqfa */
4177 #if defined(CONFIG_USER_ONLY)
4178 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4179 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4188 gen_movl_TN_reg(rd, cpu_val);
4189 #ifdef TARGET_SPARC64
4192 } else if (xop >= 0x20 && xop < 0x24) {
4193 if (gen_trap_ifnofpu(dc, cpu_cond))
4196 case 0x20: /* load fpreg */
4197 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4198 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4199 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4200 offsetof(CPUState, fpr[rd]));
4202 case 0x21: /* load fsr */
4203 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4204 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4205 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4206 offsetof(CPUState, ft0));
4207 tcg_gen_helper_0_0(helper_ldfsr);
4209 case 0x22: /* load quad fpreg */
4210 #if defined(CONFIG_USER_ONLY)
4211 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4213 gen_op_store_QT0_fpr(QFPREG(rd));
4218 case 0x23: /* load double fpreg */
4219 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4221 gen_op_store_DT0_fpr(DFPREG(rd));
4226 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4227 xop == 0xe || xop == 0x1e) {
4228 gen_movl_reg_TN(rd, cpu_val);
4230 case 0x4: /* store word */
4231 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4232 ABI32_MASK(cpu_addr);
4233 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4235 case 0x5: /* store byte */
4236 ABI32_MASK(cpu_addr);
4237 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4239 case 0x6: /* store halfword */
4240 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4241 ABI32_MASK(cpu_addr);
4242 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4244 case 0x7: /* store double word */
4251 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4252 r_low = tcg_temp_new(TCG_TYPE_I32);
4253 gen_movl_reg_TN(rd + 1, r_low);
4254 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4256 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4258 #else /* __i386__ */
4259 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4260 flush_cond(dc, cpu_cond);
4261 gen_movl_reg_TN(rd + 1, cpu_cond);
4263 #endif /* __i386__ */
4265 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4266 case 0x14: /* store word alternate */
4267 #ifndef TARGET_SPARC64
4270 if (!supervisor(dc))
4273 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4274 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4276 case 0x15: /* store byte alternate */
4277 #ifndef TARGET_SPARC64
4280 if (!supervisor(dc))
4283 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4285 case 0x16: /* store halfword alternate */
4286 #ifndef TARGET_SPARC64
4289 if (!supervisor(dc))
4292 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4293 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4295 case 0x17: /* store double word alternate */
4296 #ifndef TARGET_SPARC64
4299 if (!supervisor(dc))
4305 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4306 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4310 #ifdef TARGET_SPARC64
4311 case 0x0e: /* V9 stx */
4312 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4313 ABI32_MASK(cpu_addr);
4314 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4316 case 0x1e: /* V9 stxa */
4317 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4318 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4324 } else if (xop > 0x23 && xop < 0x28) {
4325 if (gen_trap_ifnofpu(dc, cpu_cond))
4328 case 0x24: /* store fpreg */
4329 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4330 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4331 offsetof(CPUState, fpr[rd]));
4332 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4334 case 0x25: /* stfsr, V9 stxfsr */
4335 #ifdef CONFIG_USER_ONLY
4336 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4338 tcg_gen_helper_0_0(helper_stfsr);
4339 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4340 offsetof(CPUState, ft0));
4341 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4344 #ifdef TARGET_SPARC64
4345 #if defined(CONFIG_USER_ONLY)
4346 /* V9 stqf, store quad fpreg */
4347 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4348 gen_op_load_fpr_QT0(QFPREG(rd));
4354 #else /* !TARGET_SPARC64 */
4355 /* stdfq, store floating point queue */
4356 #if defined(CONFIG_USER_ONLY)
4359 if (!supervisor(dc))
4361 if (gen_trap_ifnofpu(dc, cpu_cond))
4367 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4368 gen_op_load_fpr_DT0(DFPREG(rd));
4374 } else if (xop > 0x33 && xop < 0x3f) {
4376 #ifdef TARGET_SPARC64
4377 case 0x34: /* V9 stfa */
4378 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4379 gen_op_load_fpr_FT0(rd);
4380 gen_stf_asi(cpu_addr, insn, 4, rd);
4382 case 0x36: /* V9 stqfa */
4383 #if defined(CONFIG_USER_ONLY)
4384 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4385 gen_op_load_fpr_QT0(QFPREG(rd));
4386 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4391 case 0x37: /* V9 stdfa */
4392 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4393 gen_op_load_fpr_DT0(DFPREG(rd));
4394 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4396 case 0x3c: /* V9 casa */
4397 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4398 gen_cas_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4399 gen_movl_TN_reg(rd, cpu_val);
4401 case 0x3e: /* V9 casxa */
4402 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4403 gen_casx_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4404 gen_movl_TN_reg(rd, cpu_val);
4407 case 0x34: /* stc */
4408 case 0x35: /* stcsr */
4409 case 0x36: /* stdcq */
4410 case 0x37: /* stdc */
4422 /* default case for non jump instructions */
4423 if (dc->npc == DYNAMIC_PC) {
4424 dc->pc = DYNAMIC_PC;
4426 } else if (dc->npc == JUMP_PC) {
4427 /* we can do a static jump */
4428 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4432 dc->npc = dc->npc + 4;
4437 save_state(dc, cpu_cond);
4438 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_ILL_INSN));
4441 #if !defined(CONFIG_USER_ONLY)
4443 save_state(dc, cpu_cond);
4444 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_PRIV_INSN));
4448 save_state(dc, cpu_cond);
4449 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4452 #ifndef TARGET_SPARC64
4454 save_state(dc, cpu_cond);
4455 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4460 #ifndef TARGET_SPARC64
4462 save_state(dc, cpu_cond);
4463 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NCP_INSN));
4469 static void tcg_macro_func(TCGContext *s, int macro_id, const int *dead_args)
4473 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4474 int spc, CPUSPARCState *env)
4476 target_ulong pc_start, last_pc;
4477 uint16_t *gen_opc_end;
4478 DisasContext dc1, *dc = &dc1;
4481 memset(dc, 0, sizeof(DisasContext));
4486 dc->npc = (target_ulong) tb->cs_base;
4487 dc->mem_idx = cpu_mmu_index(env);
4488 dc->fpu_enabled = cpu_fpu_enabled(env);
4489 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4491 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4492 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4493 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4495 cpu_cond = cpu_T[2];
4498 if (env->nb_breakpoints > 0) {
4499 for(j = 0; j < env->nb_breakpoints; j++) {
4500 if (env->breakpoints[j] == dc->pc) {
4501 if (dc->pc != pc_start)
4502 save_state(dc, cpu_cond);
4503 tcg_gen_helper_0_0(helper_debug);
4512 fprintf(logfile, "Search PC...\n");
4513 j = gen_opc_ptr - gen_opc_buf;
4517 gen_opc_instr_start[lj++] = 0;
4518 gen_opc_pc[lj] = dc->pc;
4519 gen_opc_npc[lj] = dc->npc;
4520 gen_opc_instr_start[lj] = 1;
4524 disas_sparc_insn(dc);
4528 /* if the next PC is different, we abort now */
4529 if (dc->pc != (last_pc + 4))
4531 /* if we reach a page boundary, we stop generation so that the
4532 PC of a TT_TFAULT exception is always in the right page */
4533 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4535 /* if single step mode, we generate only one instruction and
4536 generate an exception */
4537 if (env->singlestep_enabled) {
4538 tcg_gen_movi_tl(cpu_pc, dc->pc);
4542 } while ((gen_opc_ptr < gen_opc_end) &&
4543 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
4547 if (dc->pc != DYNAMIC_PC &&
4548 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4549 /* static PC and NPC: we can use direct chaining */
4550 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4552 if (dc->pc != DYNAMIC_PC)
4553 tcg_gen_movi_tl(cpu_pc, dc->pc);
4554 save_npc(dc, cpu_cond);
4558 *gen_opc_ptr = INDEX_op_end;
4560 j = gen_opc_ptr - gen_opc_buf;
4563 gen_opc_instr_start[lj++] = 0;
4569 gen_opc_jump_pc[0] = dc->jump_pc[0];
4570 gen_opc_jump_pc[1] = dc->jump_pc[1];
4572 tb->size = last_pc + 4 - pc_start;
4575 if (loglevel & CPU_LOG_TB_IN_ASM) {
4576 fprintf(logfile, "--------------\n");
4577 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4578 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4579 fprintf(logfile, "\n");
4585 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4587 return gen_intermediate_code_internal(tb, 0, env);
4590 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4592 return gen_intermediate_code_internal(tb, 1, env);
4595 void gen_intermediate_code_init(CPUSPARCState *env)
4599 static const char * const gregnames[8] = {
4600 NULL, // g0 not used
4610 /* init various static tables */
4614 tcg_set_macro_func(&tcg_ctx, tcg_macro_func);
4615 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4616 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4617 offsetof(CPUState, regwptr),
4619 //#if TARGET_LONG_BITS > HOST_LONG_BITS
4620 #ifdef TARGET_SPARC64
4621 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
4622 TCG_AREG0, offsetof(CPUState, t0), "T0");
4623 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
4624 TCG_AREG0, offsetof(CPUState, t1), "T1");
4625 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
4626 TCG_AREG0, offsetof(CPUState, t2), "T2");
4627 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4628 TCG_AREG0, offsetof(CPUState, xcc),
4631 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
4632 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
4633 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
4635 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4636 TCG_AREG0, offsetof(CPUState, cc_src),
4638 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4639 offsetof(CPUState, cc_src2),
4641 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4642 TCG_AREG0, offsetof(CPUState, cc_dst),
4644 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4645 TCG_AREG0, offsetof(CPUState, psr),
4647 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4648 TCG_AREG0, offsetof(CPUState, fsr),
4650 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4651 TCG_AREG0, offsetof(CPUState, pc),
4653 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4654 TCG_AREG0, offsetof(CPUState, npc),
4656 for (i = 1; i < 8; i++)
4657 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4658 offsetof(CPUState, gregs[i]),