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, 23);
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, 22);
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, 21);
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, 20);
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));
617 tcg_gen_discard_tl(r_temp);
620 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
622 tcg_gen_mov_tl(cpu_cc_src, src1);
623 tcg_gen_sub_tl(dst, src1, src2);
626 gen_cc_C_sub_icc(cpu_cc_src, src2);
627 gen_cc_V_sub_icc(dst, cpu_cc_src, src2);
628 #ifdef TARGET_SPARC64
631 gen_cc_C_sub_xcc(cpu_cc_src, src2);
632 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
636 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
638 tcg_gen_mov_tl(cpu_cc_src, src1);
639 gen_mov_reg_C(cpu_tmp0, cpu_psr);
640 tcg_gen_sub_tl(dst, src1, cpu_tmp0);
642 gen_cc_C_sub_icc(dst, cpu_cc_src);
643 #ifdef TARGET_SPARC64
645 gen_cc_C_sub_xcc(dst, cpu_cc_src);
647 tcg_gen_sub_tl(dst, dst, src2);
649 gen_cc_C_sub_icc(dst, cpu_cc_src);
650 gen_cc_V_sub_icc(dst, cpu_cc_src, src2);
651 #ifdef TARGET_SPARC64
653 gen_cc_C_sub_xcc(dst, cpu_cc_src);
654 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
658 static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
660 tcg_gen_mov_tl(cpu_cc_src, src1);
661 tcg_gen_sub_tl(dst, src1, src2);
664 gen_cc_C_sub_icc(cpu_cc_src, src2);
665 gen_cc_V_sub_icc(dst, cpu_cc_src, src2);
666 gen_cc_V_tag(cpu_cc_src, src2);
667 #ifdef TARGET_SPARC64
670 gen_cc_C_sub_xcc(cpu_cc_src, src2);
671 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
675 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
677 gen_tag_tv(src1, src2);
678 tcg_gen_mov_tl(cpu_cc_src, src1);
679 tcg_gen_sub_tl(dst, src1, src2);
680 gen_sub_tv(dst, cpu_cc_src, src2);
683 gen_cc_C_sub_icc(cpu_cc_src, src2);
684 #ifdef TARGET_SPARC64
687 gen_cc_C_sub_xcc(cpu_cc_src, src2);
688 gen_cc_V_sub_xcc(dst, cpu_cc_src, src2);
692 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
694 TCGv r_temp, r_temp2;
697 l1 = gen_new_label();
698 l2 = gen_new_label();
699 r_temp = tcg_temp_new(TCG_TYPE_TL);
700 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
706 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
707 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
708 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
709 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp2, tcg_const_i32(0), l1);
710 tcg_gen_mov_tl(cpu_cc_src2, src2);
713 tcg_gen_movi_tl(cpu_cc_src2, 0);
717 // env->y = (b2 << 31) | (env->y >> 1);
718 tcg_gen_trunc_tl_i32(r_temp2, src1);
719 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
720 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
721 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
722 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
723 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
724 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
727 gen_mov_reg_N(cpu_tmp0, cpu_psr);
728 gen_mov_reg_V(r_temp, cpu_psr);
729 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
731 // T0 = (b1 << 31) | (T0 >> 1);
733 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
734 tcg_gen_shri_tl(cpu_cc_src, src1, 1);
735 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
737 /* do addition and update flags */
738 tcg_gen_add_tl(dst, cpu_cc_src, cpu_cc_src2);
739 tcg_gen_discard_tl(r_temp);
743 gen_cc_V_add_icc(dst, cpu_cc_src, cpu_cc_src2);
744 gen_cc_C_add_icc(dst, cpu_cc_src);
747 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
749 TCGv r_temp, r_temp2;
751 r_temp = tcg_temp_new(TCG_TYPE_I64);
752 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
754 tcg_gen_extu_tl_i64(r_temp, src2);
755 tcg_gen_extu_tl_i64(r_temp2, src1);
756 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
758 tcg_gen_shri_i64(r_temp, r_temp2, 32);
759 tcg_gen_trunc_i64_i32(r_temp, r_temp);
760 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
761 #ifdef TARGET_SPARC64
762 tcg_gen_mov_i64(dst, r_temp2);
764 tcg_gen_trunc_i64_tl(dst, r_temp2);
767 tcg_gen_discard_i64(r_temp);
768 tcg_gen_discard_i64(r_temp2);
771 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
773 TCGv r_temp, r_temp2;
775 r_temp = tcg_temp_new(TCG_TYPE_I64);
776 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
778 tcg_gen_ext_tl_i64(r_temp, src2);
779 tcg_gen_ext_tl_i64(r_temp2, src1);
780 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
782 tcg_gen_shri_i64(r_temp, r_temp2, 32);
783 tcg_gen_trunc_i64_i32(r_temp, r_temp);
784 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
785 #ifdef TARGET_SPARC64
786 tcg_gen_mov_i64(dst, r_temp2);
788 tcg_gen_trunc_i64_tl(dst, r_temp2);
791 tcg_gen_discard_i64(r_temp);
792 tcg_gen_discard_i64(r_temp2);
795 #ifdef TARGET_SPARC64
796 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
800 l1 = gen_new_label();
801 tcg_gen_brcond_tl(TCG_COND_NE, divisor, tcg_const_tl(0), l1);
802 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_DIV_ZERO));
806 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
810 l1 = gen_new_label();
811 l2 = gen_new_label();
812 gen_trap_ifdivzero_tl(src2);
813 tcg_gen_brcond_tl(TCG_COND_NE, src1, tcg_const_tl(INT64_MIN), l1);
814 tcg_gen_brcond_tl(TCG_COND_NE, src2, tcg_const_tl(-1), l1);
815 tcg_gen_movi_i64(dst, INT64_MIN);
818 tcg_gen_div_i64(dst, src1, src2);
823 static inline void gen_op_div_cc(TCGv dst)
829 l1 = gen_new_label();
830 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, cc_src2));
831 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
832 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
836 static inline void gen_op_logic_cc(TCGv dst)
840 #ifdef TARGET_SPARC64
847 static inline void gen_op_eval_ba(TCGv dst)
849 tcg_gen_movi_tl(dst, 1);
853 static inline void gen_op_eval_be(TCGv dst, TCGv src)
855 gen_mov_reg_Z(dst, src);
859 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
861 gen_mov_reg_N(cpu_tmp0, src);
862 gen_mov_reg_V(dst, src);
863 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
864 gen_mov_reg_Z(cpu_tmp0, src);
865 tcg_gen_or_tl(dst, dst, cpu_tmp0);
869 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
871 gen_mov_reg_V(cpu_tmp0, src);
872 gen_mov_reg_N(dst, src);
873 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
877 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
879 gen_mov_reg_Z(cpu_tmp0, src);
880 gen_mov_reg_C(dst, src);
881 tcg_gen_or_tl(dst, dst, cpu_tmp0);
885 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
887 gen_mov_reg_C(dst, src);
891 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
893 gen_mov_reg_V(dst, src);
897 static inline void gen_op_eval_bn(TCGv dst)
899 tcg_gen_movi_tl(dst, 0);
903 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
905 gen_mov_reg_N(dst, src);
909 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
911 gen_mov_reg_Z(dst, src);
912 tcg_gen_xori_tl(dst, dst, 0x1);
916 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
918 gen_mov_reg_N(cpu_tmp0, src);
919 gen_mov_reg_V(dst, src);
920 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
921 gen_mov_reg_Z(cpu_tmp0, src);
922 tcg_gen_or_tl(dst, dst, cpu_tmp0);
923 tcg_gen_xori_tl(dst, dst, 0x1);
927 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
929 gen_mov_reg_V(cpu_tmp0, src);
930 gen_mov_reg_N(dst, src);
931 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
932 tcg_gen_xori_tl(dst, dst, 0x1);
936 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
938 gen_mov_reg_Z(cpu_tmp0, src);
939 gen_mov_reg_C(dst, src);
940 tcg_gen_or_tl(dst, dst, cpu_tmp0);
941 tcg_gen_xori_tl(dst, dst, 0x1);
945 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
947 gen_mov_reg_C(dst, src);
948 tcg_gen_xori_tl(dst, dst, 0x1);
952 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
954 gen_mov_reg_N(dst, src);
955 tcg_gen_xori_tl(dst, dst, 0x1);
959 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
961 gen_mov_reg_V(dst, src);
962 tcg_gen_xori_tl(dst, dst, 0x1);
966 FPSR bit field FCC1 | FCC0:
972 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
973 unsigned int fcc_offset)
975 tcg_gen_extu_i32_tl(reg, src);
976 tcg_gen_shri_tl(reg, reg, 10 + fcc_offset);
977 tcg_gen_andi_tl(reg, reg, 0x1);
980 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
981 unsigned int fcc_offset)
983 tcg_gen_extu_i32_tl(reg, src);
984 tcg_gen_shri_tl(reg, reg, 11 + fcc_offset);
985 tcg_gen_andi_tl(reg, reg, 0x1);
989 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
990 unsigned int fcc_offset)
992 gen_mov_reg_FCC0(dst, src, fcc_offset);
993 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
994 tcg_gen_or_tl(dst, dst, cpu_tmp0);
997 // 1 or 2: FCC0 ^ FCC1
998 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
999 unsigned int fcc_offset)
1001 gen_mov_reg_FCC0(dst, src, fcc_offset);
1002 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1003 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1007 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1008 unsigned int fcc_offset)
1010 gen_mov_reg_FCC0(dst, src, fcc_offset);
1014 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
1015 unsigned int fcc_offset)
1017 gen_mov_reg_FCC0(dst, src, fcc_offset);
1018 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1019 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1020 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1024 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1025 unsigned int fcc_offset)
1027 gen_mov_reg_FCC1(dst, src, fcc_offset);
1031 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1032 unsigned int fcc_offset)
1034 gen_mov_reg_FCC0(dst, src, fcc_offset);
1035 tcg_gen_xori_tl(dst, dst, 0x1);
1036 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1037 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1041 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1042 unsigned int fcc_offset)
1044 gen_mov_reg_FCC0(dst, src, fcc_offset);
1045 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1046 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1049 // 0: !(FCC0 | FCC1)
1050 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1051 unsigned int fcc_offset)
1053 gen_mov_reg_FCC0(dst, src, fcc_offset);
1054 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1055 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1056 tcg_gen_xori_tl(dst, dst, 0x1);
1059 // 0 or 3: !(FCC0 ^ FCC1)
1060 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1061 unsigned int fcc_offset)
1063 gen_mov_reg_FCC0(dst, src, fcc_offset);
1064 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1065 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1066 tcg_gen_xori_tl(dst, dst, 0x1);
1070 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1071 unsigned int fcc_offset)
1073 gen_mov_reg_FCC0(dst, src, fcc_offset);
1074 tcg_gen_xori_tl(dst, dst, 0x1);
1077 // !1: !(FCC0 & !FCC1)
1078 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1079 unsigned int fcc_offset)
1081 gen_mov_reg_FCC0(dst, src, fcc_offset);
1082 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1083 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1084 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1085 tcg_gen_xori_tl(dst, dst, 0x1);
1089 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1090 unsigned int fcc_offset)
1092 gen_mov_reg_FCC1(dst, src, fcc_offset);
1093 tcg_gen_xori_tl(dst, dst, 0x1);
1096 // !2: !(!FCC0 & FCC1)
1097 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1098 unsigned int fcc_offset)
1100 gen_mov_reg_FCC0(dst, src, fcc_offset);
1101 tcg_gen_xori_tl(dst, dst, 0x1);
1102 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1103 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1104 tcg_gen_xori_tl(dst, dst, 0x1);
1107 // !3: !(FCC0 & FCC1)
1108 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1109 unsigned int fcc_offset)
1111 gen_mov_reg_FCC0(dst, src, fcc_offset);
1112 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1113 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1114 tcg_gen_xori_tl(dst, dst, 0x1);
1117 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1118 target_ulong pc2, TCGv r_cond)
1122 l1 = gen_new_label();
1124 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1126 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1129 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1132 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1133 target_ulong pc2, TCGv r_cond)
1137 l1 = gen_new_label();
1139 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1141 gen_goto_tb(dc, 0, pc2, pc1);
1144 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1147 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1152 l1 = gen_new_label();
1153 l2 = gen_new_label();
1155 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1157 tcg_gen_movi_tl(cpu_npc, npc1);
1161 tcg_gen_movi_tl(cpu_npc, npc2);
1165 /* call this function before using the condition register as it may
1166 have been set for a jump */
1167 static inline void flush_cond(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;
1175 static inline void save_npc(DisasContext *dc, TCGv cond)
1177 if (dc->npc == JUMP_PC) {
1178 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1179 dc->npc = DYNAMIC_PC;
1180 } else if (dc->npc != DYNAMIC_PC) {
1181 tcg_gen_movi_tl(cpu_npc, dc->npc);
1185 static inline void save_state(DisasContext *dc, TCGv cond)
1187 tcg_gen_movi_tl(cpu_pc, dc->pc);
1191 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1193 if (dc->npc == JUMP_PC) {
1194 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1195 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1196 dc->pc = DYNAMIC_PC;
1197 } else if (dc->npc == DYNAMIC_PC) {
1198 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1199 dc->pc = DYNAMIC_PC;
1205 static inline void gen_op_next_insn(void)
1207 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1208 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1211 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1215 #ifdef TARGET_SPARC64
1225 gen_op_eval_bn(r_dst);
1228 gen_op_eval_be(r_dst, r_src);
1231 gen_op_eval_ble(r_dst, r_src);
1234 gen_op_eval_bl(r_dst, r_src);
1237 gen_op_eval_bleu(r_dst, r_src);
1240 gen_op_eval_bcs(r_dst, r_src);
1243 gen_op_eval_bneg(r_dst, r_src);
1246 gen_op_eval_bvs(r_dst, r_src);
1249 gen_op_eval_ba(r_dst);
1252 gen_op_eval_bne(r_dst, r_src);
1255 gen_op_eval_bg(r_dst, r_src);
1258 gen_op_eval_bge(r_dst, r_src);
1261 gen_op_eval_bgu(r_dst, r_src);
1264 gen_op_eval_bcc(r_dst, r_src);
1267 gen_op_eval_bpos(r_dst, r_src);
1270 gen_op_eval_bvc(r_dst, r_src);
1275 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1277 unsigned int offset;
1297 gen_op_eval_bn(r_dst);
1300 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1303 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1306 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1309 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1312 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1315 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1318 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1321 gen_op_eval_ba(r_dst);
1324 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1327 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1330 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1333 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1336 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1339 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1342 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1347 #ifdef TARGET_SPARC64
1349 static const int gen_tcg_cond_reg[8] = {
1360 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1364 l1 = gen_new_label();
1365 tcg_gen_movi_tl(r_dst, 0);
1366 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], r_src, tcg_const_tl(0), l1);
1367 tcg_gen_movi_tl(r_dst, 1);
1372 /* XXX: potentially incorrect if dynamic npc */
1373 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1376 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1377 target_ulong target = dc->pc + offset;
1380 /* unconditional not taken */
1382 dc->pc = dc->npc + 4;
1383 dc->npc = dc->pc + 4;
1386 dc->npc = dc->pc + 4;
1388 } else if (cond == 0x8) {
1389 /* unconditional taken */
1392 dc->npc = dc->pc + 4;
1398 flush_cond(dc, r_cond);
1399 gen_cond(r_cond, cc, cond);
1401 gen_branch_a(dc, target, dc->npc, r_cond);
1405 dc->jump_pc[0] = target;
1406 dc->jump_pc[1] = dc->npc + 4;
1412 /* XXX: potentially incorrect if dynamic npc */
1413 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1416 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1417 target_ulong target = dc->pc + offset;
1420 /* unconditional not taken */
1422 dc->pc = dc->npc + 4;
1423 dc->npc = dc->pc + 4;
1426 dc->npc = dc->pc + 4;
1428 } else if (cond == 0x8) {
1429 /* unconditional taken */
1432 dc->npc = dc->pc + 4;
1438 flush_cond(dc, r_cond);
1439 gen_fcond(r_cond, cc, cond);
1441 gen_branch_a(dc, target, dc->npc, r_cond);
1445 dc->jump_pc[0] = target;
1446 dc->jump_pc[1] = dc->npc + 4;
1452 #ifdef TARGET_SPARC64
1453 /* XXX: potentially incorrect if dynamic npc */
1454 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1455 TCGv r_cond, TCGv r_reg)
1457 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1458 target_ulong target = dc->pc + offset;
1460 flush_cond(dc, r_cond);
1461 gen_cond_reg(r_cond, cond, r_reg);
1463 gen_branch_a(dc, target, dc->npc, r_cond);
1467 dc->jump_pc[0] = target;
1468 dc->jump_pc[1] = dc->npc + 4;
1473 static GenOpFunc * const gen_fcmps[4] = {
1480 static GenOpFunc * const gen_fcmpd[4] = {
1487 #if defined(CONFIG_USER_ONLY)
1488 static GenOpFunc * const gen_fcmpq[4] = {
1496 static GenOpFunc * const gen_fcmpes[4] = {
1503 static GenOpFunc * const gen_fcmped[4] = {
1510 #if defined(CONFIG_USER_ONLY)
1511 static GenOpFunc * const gen_fcmpeq[4] = {
1519 static inline void gen_op_fcmps(int fccno)
1521 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1524 static inline void gen_op_fcmpd(int fccno)
1526 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1529 #if defined(CONFIG_USER_ONLY)
1530 static inline void gen_op_fcmpq(int fccno)
1532 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1536 static inline void gen_op_fcmpes(int fccno)
1538 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1541 static inline void gen_op_fcmped(int fccno)
1543 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1546 #if defined(CONFIG_USER_ONLY)
1547 static inline void gen_op_fcmpeq(int fccno)
1549 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1555 static inline void gen_op_fcmps(int fccno)
1557 tcg_gen_helper_0_0(helper_fcmps);
1560 static inline void gen_op_fcmpd(int fccno)
1562 tcg_gen_helper_0_0(helper_fcmpd);
1565 #if defined(CONFIG_USER_ONLY)
1566 static inline void gen_op_fcmpq(int fccno)
1568 tcg_gen_helper_0_0(helper_fcmpq);
1572 static inline void gen_op_fcmpes(int fccno)
1574 tcg_gen_helper_0_0(helper_fcmpes);
1577 static inline void gen_op_fcmped(int fccno)
1579 tcg_gen_helper_0_0(helper_fcmped);
1582 #if defined(CONFIG_USER_ONLY)
1583 static inline void gen_op_fcmpeq(int fccno)
1585 tcg_gen_helper_0_0(helper_fcmpeq);
1591 static inline void gen_op_fpexception_im(int fsr_flags)
1593 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1594 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1595 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_FP_EXCP));
1598 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1600 #if !defined(CONFIG_USER_ONLY)
1601 if (!dc->fpu_enabled) {
1602 save_state(dc, r_cond);
1603 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NFPU_INSN));
1611 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1613 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1616 static inline void gen_clear_float_exceptions(void)
1618 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1622 #ifdef TARGET_SPARC64
1623 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1629 r_asi = tcg_temp_new(TCG_TYPE_I32);
1630 offset = GET_FIELD(insn, 25, 31);
1631 tcg_gen_addi_tl(r_addr, r_addr, offset);
1632 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1634 asi = GET_FIELD(insn, 19, 26);
1635 r_asi = tcg_const_i32(asi);
1640 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size, int sign)
1644 r_asi = gen_get_asi(insn, addr);
1645 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi,
1646 tcg_const_i32(size), tcg_const_i32(sign));
1647 tcg_gen_discard_i32(r_asi);
1650 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1654 r_asi = gen_get_asi(insn, addr);
1655 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, tcg_const_i32(size));
1656 tcg_gen_discard_i32(r_asi);
1659 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1663 r_asi = gen_get_asi(insn, addr);
1664 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, tcg_const_i32(size),
1666 tcg_gen_discard_i32(r_asi);
1669 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1673 r_asi = gen_get_asi(insn, addr);
1674 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, tcg_const_i32(size),
1676 tcg_gen_discard_i32(r_asi);
1679 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1683 r_temp = tcg_temp_new(TCG_TYPE_I32);
1684 r_asi = gen_get_asi(insn, addr);
1685 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, r_asi,
1686 tcg_const_i32(4), tcg_const_i32(0));
1687 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi,
1689 tcg_gen_extu_i32_tl(dst, r_temp);
1690 tcg_gen_discard_i32(r_asi);
1691 tcg_gen_discard_i32(r_temp);
1694 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1698 r_asi = gen_get_asi(insn, addr);
1699 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi,
1700 tcg_const_i32(8), tcg_const_i32(0));
1701 tcg_gen_andi_i64(lo, cpu_tmp64, 0xffffffffULL);
1702 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1703 tcg_gen_andi_i64(hi, cpu_tmp64, 0xffffffffULL);
1704 tcg_gen_discard_i32(r_asi);
1707 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1711 r_temp = tcg_temp_new(TCG_TYPE_I32);
1712 gen_movl_reg_TN(rd + 1, r_temp);
1713 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1715 r_asi = gen_get_asi(insn, addr);
1716 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi,
1718 tcg_gen_discard_i32(r_asi);
1719 tcg_gen_discard_i32(r_temp);
1722 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn, int rd)
1726 r_val1 = tcg_temp_new(TCG_TYPE_I32);
1727 gen_movl_reg_TN(rd, r_val1);
1728 r_asi = gen_get_asi(insn, addr);
1729 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1730 tcg_gen_discard_i32(r_asi);
1731 tcg_gen_discard_i32(r_val1);
1734 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn, int rd)
1738 gen_movl_reg_TN(rd, cpu_tmp64);
1739 r_asi = gen_get_asi(insn, addr);
1740 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1741 tcg_gen_discard_i32(r_asi);
1744 #elif !defined(CONFIG_USER_ONLY)
1746 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size, int sign)
1750 asi = GET_FIELD(insn, 19, 26);
1751 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
1752 tcg_const_i32(size), tcg_const_i32(sign));
1753 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1756 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1760 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1761 asi = GET_FIELD(insn, 19, 26);
1762 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
1763 tcg_const_i32(size));
1766 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1771 r_temp = tcg_temp_new(TCG_TYPE_I32);
1772 asi = GET_FIELD(insn, 19, 26);
1773 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, tcg_const_i32(asi),
1774 tcg_const_i32(4), tcg_const_i32(0));
1775 tcg_gen_helper_0_4(helper_st_asi, addr, dst, tcg_const_i32(asi),
1777 tcg_gen_extu_i32_tl(dst, r_temp);
1778 tcg_gen_discard_i32(r_temp);
1781 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1785 asi = GET_FIELD(insn, 19, 26);
1786 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
1787 tcg_const_i32(8), tcg_const_i32(0));
1788 tcg_gen_trunc_i64_tl(lo, cpu_tmp64);
1789 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1790 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1793 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1798 r_temp = tcg_temp_new(TCG_TYPE_I32);
1799 gen_movl_reg_TN(rd + 1, r_temp);
1800 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1801 asi = GET_FIELD(insn, 19, 26);
1802 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
1807 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1808 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1812 gen_ld_asi(dst, addr, insn, 1, 0);
1814 asi = GET_FIELD(insn, 19, 26);
1815 tcg_gen_helper_0_4(helper_st_asi, addr, tcg_const_i64(0xffULL),
1816 tcg_const_i32(asi), tcg_const_i32(1));
1820 /* before an instruction, dc->pc must be static */
1821 static void disas_sparc_insn(DisasContext * dc)
1823 unsigned int insn, opc, rs1, rs2, rd;
1825 insn = ldl_code(dc->pc);
1826 opc = GET_FIELD(insn, 0, 1);
1828 rd = GET_FIELD(insn, 2, 6);
1831 cpu_src1 = cpu_T[0]; // const
1832 cpu_src2 = cpu_T[1]; // const
1835 cpu_addr = cpu_T[0];
1839 case 0: /* branches/sethi */
1841 unsigned int xop = GET_FIELD(insn, 7, 9);
1844 #ifdef TARGET_SPARC64
1845 case 0x1: /* V9 BPcc */
1849 target = GET_FIELD_SP(insn, 0, 18);
1850 target = sign_extend(target, 18);
1852 cc = GET_FIELD_SP(insn, 20, 21);
1854 do_branch(dc, target, insn, 0, cpu_cond);
1856 do_branch(dc, target, insn, 1, cpu_cond);
1861 case 0x3: /* V9 BPr */
1863 target = GET_FIELD_SP(insn, 0, 13) |
1864 (GET_FIELD_SP(insn, 20, 21) << 14);
1865 target = sign_extend(target, 16);
1867 rs1 = GET_FIELD(insn, 13, 17);
1868 gen_movl_reg_TN(rs1, cpu_src1);
1869 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1872 case 0x5: /* V9 FBPcc */
1874 int cc = GET_FIELD_SP(insn, 20, 21);
1875 if (gen_trap_ifnofpu(dc, cpu_cond))
1877 target = GET_FIELD_SP(insn, 0, 18);
1878 target = sign_extend(target, 19);
1880 do_fbranch(dc, target, insn, cc, cpu_cond);
1884 case 0x7: /* CBN+x */
1889 case 0x2: /* BN+x */
1891 target = GET_FIELD(insn, 10, 31);
1892 target = sign_extend(target, 22);
1894 do_branch(dc, target, insn, 0, cpu_cond);
1897 case 0x6: /* FBN+x */
1899 if (gen_trap_ifnofpu(dc, cpu_cond))
1901 target = GET_FIELD(insn, 10, 31);
1902 target = sign_extend(target, 22);
1904 do_fbranch(dc, target, insn, 0, cpu_cond);
1907 case 0x4: /* SETHI */
1912 uint32_t value = GET_FIELD(insn, 10, 31);
1913 tcg_gen_movi_tl(cpu_dst, value << 10);
1914 gen_movl_TN_reg(rd, cpu_dst);
1919 case 0x0: /* UNIMPL */
1928 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1930 gen_movl_TN_reg(15, tcg_const_tl(dc->pc));
1932 gen_mov_pc_npc(dc, cpu_cond);
1936 case 2: /* FPU & Logical Operations */
1938 unsigned int xop = GET_FIELD(insn, 7, 12);
1939 if (xop == 0x3a) { /* generate trap */
1942 rs1 = GET_FIELD(insn, 13, 17);
1943 gen_movl_reg_TN(rs1, cpu_src1);
1945 rs2 = GET_FIELD(insn, 25, 31);
1946 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
1948 rs2 = GET_FIELD(insn, 27, 31);
1952 gen_movl_reg_TN(rs2, cpu_src2);
1953 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
1958 cond = GET_FIELD(insn, 3, 6);
1960 save_state(dc, cpu_cond);
1961 tcg_gen_helper_0_1(helper_trap, cpu_dst);
1962 } else if (cond != 0) {
1963 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
1964 #ifdef TARGET_SPARC64
1966 int cc = GET_FIELD_SP(insn, 11, 12);
1968 save_state(dc, cpu_cond);
1970 gen_cond(r_cond, 0, cond);
1972 gen_cond(r_cond, 1, cond);
1976 save_state(dc, cpu_cond);
1977 gen_cond(r_cond, 0, cond);
1979 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
1980 tcg_gen_discard_tl(r_cond);
1986 } else if (xop == 0x28) {
1987 rs1 = GET_FIELD(insn, 13, 17);
1990 #ifndef TARGET_SPARC64
1991 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1992 manual, rdy on the microSPARC
1994 case 0x0f: /* stbar in the SPARCv8 manual,
1995 rdy on the microSPARC II */
1996 case 0x10 ... 0x1f: /* implementation-dependent in the
1997 SPARCv8 manual, rdy on the
2000 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
2001 gen_movl_TN_reg(rd, cpu_dst);
2003 #ifdef TARGET_SPARC64
2004 case 0x2: /* V9 rdccr */
2005 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2006 gen_movl_TN_reg(rd, cpu_dst);
2008 case 0x3: /* V9 rdasi */
2009 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
2010 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2011 gen_movl_TN_reg(rd, cpu_dst);
2013 case 0x4: /* V9 rdtick */
2017 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2018 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2019 offsetof(CPUState, tick));
2020 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2022 gen_movl_TN_reg(rd, cpu_dst);
2023 tcg_gen_discard_ptr(r_tickptr);
2026 case 0x5: /* V9 rdpc */
2027 tcg_gen_movi_tl(cpu_dst, dc->pc);
2028 gen_movl_TN_reg(rd, cpu_dst);
2030 case 0x6: /* V9 rdfprs */
2031 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
2032 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2033 gen_movl_TN_reg(rd, cpu_dst);
2035 case 0xf: /* V9 membar */
2036 break; /* no effect */
2037 case 0x13: /* Graphics Status */
2038 if (gen_trap_ifnofpu(dc, cpu_cond))
2040 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
2041 gen_movl_TN_reg(rd, cpu_dst);
2043 case 0x17: /* Tick compare */
2044 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tick_cmpr));
2045 gen_movl_TN_reg(rd, cpu_dst);
2047 case 0x18: /* System tick */
2051 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2052 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2053 offsetof(CPUState, stick));
2054 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2056 gen_movl_TN_reg(rd, cpu_dst);
2057 tcg_gen_discard_ptr(r_tickptr);
2060 case 0x19: /* System tick compare */
2061 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, stick_cmpr));
2062 gen_movl_TN_reg(rd, cpu_dst);
2064 case 0x10: /* Performance Control */
2065 case 0x11: /* Performance Instrumentation Counter */
2066 case 0x12: /* Dispatch Control */
2067 case 0x14: /* Softint set, WO */
2068 case 0x15: /* Softint clear, WO */
2069 case 0x16: /* Softint write */
2074 #if !defined(CONFIG_USER_ONLY)
2075 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2076 #ifndef TARGET_SPARC64
2077 if (!supervisor(dc))
2079 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2081 if (!hypervisor(dc))
2083 rs1 = GET_FIELD(insn, 13, 17);
2086 // gen_op_rdhpstate();
2089 // gen_op_rdhtstate();
2092 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
2093 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2096 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
2097 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2100 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hver));
2101 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2103 case 31: // hstick_cmpr
2104 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2105 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hstick_cmpr));
2111 gen_movl_TN_reg(rd, cpu_dst);
2113 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2114 if (!supervisor(dc))
2116 #ifdef TARGET_SPARC64
2117 rs1 = GET_FIELD(insn, 13, 17);
2123 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2124 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2125 offsetof(CPUState, tsptr));
2126 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2127 offsetof(trap_state, tpc));
2128 tcg_gen_discard_ptr(r_tsptr);
2135 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2136 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2137 offsetof(CPUState, tsptr));
2138 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2139 offsetof(trap_state, tnpc));
2140 tcg_gen_discard_ptr(r_tsptr);
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));
2152 tcg_gen_discard_ptr(r_tsptr);
2159 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2160 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2161 offsetof(CPUState, tsptr));
2162 tcg_gen_ld_i32(cpu_dst, r_tsptr,
2163 offsetof(trap_state, tt));
2164 tcg_gen_discard_ptr(r_tsptr);
2171 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2172 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2173 offsetof(CPUState, tick));
2174 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2176 gen_movl_TN_reg(rd, cpu_dst);
2177 tcg_gen_discard_ptr(r_tickptr);
2181 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2184 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, pstate));
2185 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2188 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
2189 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2192 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
2193 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2196 tcg_gen_helper_1_0(helper_rdcwp, cpu_dst);
2199 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
2200 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2202 case 11: // canrestore
2203 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
2204 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2206 case 12: // cleanwin
2207 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
2208 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2210 case 13: // otherwin
2211 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
2212 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2215 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
2216 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2218 case 16: // UA2005 gl
2219 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
2220 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2222 case 26: // UA2005 strand status
2223 if (!hypervisor(dc))
2225 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
2226 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2229 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, version));
2236 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
2237 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2239 gen_movl_TN_reg(rd, cpu_dst);
2241 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2242 #ifdef TARGET_SPARC64
2243 tcg_gen_helper_0_0(helper_flushw);
2245 if (!supervisor(dc))
2247 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2248 gen_movl_TN_reg(rd, cpu_dst);
2252 } else if (xop == 0x34) { /* FPU Operations */
2253 if (gen_trap_ifnofpu(dc, cpu_cond))
2255 gen_op_clear_ieee_excp_and_FTT();
2256 rs1 = GET_FIELD(insn, 13, 17);
2257 rs2 = GET_FIELD(insn, 27, 31);
2258 xop = GET_FIELD(insn, 18, 26);
2260 case 0x1: /* fmovs */
2261 gen_op_load_fpr_FT0(rs2);
2262 gen_op_store_FT0_fpr(rd);
2264 case 0x5: /* fnegs */
2265 gen_op_load_fpr_FT1(rs2);
2266 tcg_gen_helper_0_0(helper_fnegs);
2267 gen_op_store_FT0_fpr(rd);
2269 case 0x9: /* fabss */
2270 gen_op_load_fpr_FT1(rs2);
2271 tcg_gen_helper_0_0(helper_fabss);
2272 gen_op_store_FT0_fpr(rd);
2274 case 0x29: /* fsqrts */
2275 gen_op_load_fpr_FT1(rs2);
2276 gen_clear_float_exceptions();
2277 tcg_gen_helper_0_0(helper_fsqrts);
2278 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2279 gen_op_store_FT0_fpr(rd);
2281 case 0x2a: /* fsqrtd */
2282 gen_op_load_fpr_DT1(DFPREG(rs2));
2283 gen_clear_float_exceptions();
2284 tcg_gen_helper_0_0(helper_fsqrtd);
2285 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2286 gen_op_store_DT0_fpr(DFPREG(rd));
2288 case 0x2b: /* fsqrtq */
2289 #if defined(CONFIG_USER_ONLY)
2290 gen_op_load_fpr_QT1(QFPREG(rs2));
2291 gen_clear_float_exceptions();
2292 tcg_gen_helper_0_0(helper_fsqrtq);
2293 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2294 gen_op_store_QT0_fpr(QFPREG(rd));
2300 gen_op_load_fpr_FT0(rs1);
2301 gen_op_load_fpr_FT1(rs2);
2302 gen_clear_float_exceptions();
2303 tcg_gen_helper_0_0(helper_fadds);
2304 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2305 gen_op_store_FT0_fpr(rd);
2308 gen_op_load_fpr_DT0(DFPREG(rs1));
2309 gen_op_load_fpr_DT1(DFPREG(rs2));
2310 gen_clear_float_exceptions();
2311 tcg_gen_helper_0_0(helper_faddd);
2312 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2313 gen_op_store_DT0_fpr(DFPREG(rd));
2315 case 0x43: /* faddq */
2316 #if defined(CONFIG_USER_ONLY)
2317 gen_op_load_fpr_QT0(QFPREG(rs1));
2318 gen_op_load_fpr_QT1(QFPREG(rs2));
2319 gen_clear_float_exceptions();
2320 tcg_gen_helper_0_0(helper_faddq);
2321 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2322 gen_op_store_QT0_fpr(QFPREG(rd));
2328 gen_op_load_fpr_FT0(rs1);
2329 gen_op_load_fpr_FT1(rs2);
2330 gen_clear_float_exceptions();
2331 tcg_gen_helper_0_0(helper_fsubs);
2332 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2333 gen_op_store_FT0_fpr(rd);
2336 gen_op_load_fpr_DT0(DFPREG(rs1));
2337 gen_op_load_fpr_DT1(DFPREG(rs2));
2338 gen_clear_float_exceptions();
2339 tcg_gen_helper_0_0(helper_fsubd);
2340 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2341 gen_op_store_DT0_fpr(DFPREG(rd));
2343 case 0x47: /* fsubq */
2344 #if defined(CONFIG_USER_ONLY)
2345 gen_op_load_fpr_QT0(QFPREG(rs1));
2346 gen_op_load_fpr_QT1(QFPREG(rs2));
2347 gen_clear_float_exceptions();
2348 tcg_gen_helper_0_0(helper_fsubq);
2349 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2350 gen_op_store_QT0_fpr(QFPREG(rd));
2356 gen_op_load_fpr_FT0(rs1);
2357 gen_op_load_fpr_FT1(rs2);
2358 gen_clear_float_exceptions();
2359 tcg_gen_helper_0_0(helper_fmuls);
2360 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2361 gen_op_store_FT0_fpr(rd);
2364 gen_op_load_fpr_DT0(DFPREG(rs1));
2365 gen_op_load_fpr_DT1(DFPREG(rs2));
2366 gen_clear_float_exceptions();
2367 tcg_gen_helper_0_0(helper_fmuld);
2368 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2369 gen_op_store_DT0_fpr(DFPREG(rd));
2371 case 0x4b: /* fmulq */
2372 #if defined(CONFIG_USER_ONLY)
2373 gen_op_load_fpr_QT0(QFPREG(rs1));
2374 gen_op_load_fpr_QT1(QFPREG(rs2));
2375 gen_clear_float_exceptions();
2376 tcg_gen_helper_0_0(helper_fmulq);
2377 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2378 gen_op_store_QT0_fpr(QFPREG(rd));
2384 gen_op_load_fpr_FT0(rs1);
2385 gen_op_load_fpr_FT1(rs2);
2386 gen_clear_float_exceptions();
2387 tcg_gen_helper_0_0(helper_fdivs);
2388 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2389 gen_op_store_FT0_fpr(rd);
2392 gen_op_load_fpr_DT0(DFPREG(rs1));
2393 gen_op_load_fpr_DT1(DFPREG(rs2));
2394 gen_clear_float_exceptions();
2395 tcg_gen_helper_0_0(helper_fdivd);
2396 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2397 gen_op_store_DT0_fpr(DFPREG(rd));
2399 case 0x4f: /* fdivq */
2400 #if defined(CONFIG_USER_ONLY)
2401 gen_op_load_fpr_QT0(QFPREG(rs1));
2402 gen_op_load_fpr_QT1(QFPREG(rs2));
2403 gen_clear_float_exceptions();
2404 tcg_gen_helper_0_0(helper_fdivq);
2405 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2406 gen_op_store_QT0_fpr(QFPREG(rd));
2412 gen_op_load_fpr_FT0(rs1);
2413 gen_op_load_fpr_FT1(rs2);
2414 gen_clear_float_exceptions();
2415 tcg_gen_helper_0_0(helper_fsmuld);
2416 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2417 gen_op_store_DT0_fpr(DFPREG(rd));
2419 case 0x6e: /* fdmulq */
2420 #if defined(CONFIG_USER_ONLY)
2421 gen_op_load_fpr_DT0(DFPREG(rs1));
2422 gen_op_load_fpr_DT1(DFPREG(rs2));
2423 gen_clear_float_exceptions();
2424 tcg_gen_helper_0_0(helper_fdmulq);
2425 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2426 gen_op_store_QT0_fpr(QFPREG(rd));
2432 gen_op_load_fpr_FT1(rs2);
2433 gen_clear_float_exceptions();
2434 tcg_gen_helper_0_0(helper_fitos);
2435 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2436 gen_op_store_FT0_fpr(rd);
2439 gen_op_load_fpr_DT1(DFPREG(rs2));
2440 gen_clear_float_exceptions();
2441 tcg_gen_helper_0_0(helper_fdtos);
2442 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2443 gen_op_store_FT0_fpr(rd);
2445 case 0xc7: /* fqtos */
2446 #if defined(CONFIG_USER_ONLY)
2447 gen_op_load_fpr_QT1(QFPREG(rs2));
2448 gen_clear_float_exceptions();
2449 tcg_gen_helper_0_0(helper_fqtos);
2450 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2451 gen_op_store_FT0_fpr(rd);
2457 gen_op_load_fpr_FT1(rs2);
2458 tcg_gen_helper_0_0(helper_fitod);
2459 gen_op_store_DT0_fpr(DFPREG(rd));
2462 gen_op_load_fpr_FT1(rs2);
2463 tcg_gen_helper_0_0(helper_fstod);
2464 gen_op_store_DT0_fpr(DFPREG(rd));
2466 case 0xcb: /* fqtod */
2467 #if defined(CONFIG_USER_ONLY)
2468 gen_op_load_fpr_QT1(QFPREG(rs2));
2469 gen_clear_float_exceptions();
2470 tcg_gen_helper_0_0(helper_fqtod);
2471 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2472 gen_op_store_DT0_fpr(DFPREG(rd));
2477 case 0xcc: /* fitoq */
2478 #if defined(CONFIG_USER_ONLY)
2479 gen_op_load_fpr_FT1(rs2);
2480 tcg_gen_helper_0_0(helper_fitoq);
2481 gen_op_store_QT0_fpr(QFPREG(rd));
2486 case 0xcd: /* fstoq */
2487 #if defined(CONFIG_USER_ONLY)
2488 gen_op_load_fpr_FT1(rs2);
2489 tcg_gen_helper_0_0(helper_fstoq);
2490 gen_op_store_QT0_fpr(QFPREG(rd));
2495 case 0xce: /* fdtoq */
2496 #if defined(CONFIG_USER_ONLY)
2497 gen_op_load_fpr_DT1(DFPREG(rs2));
2498 tcg_gen_helper_0_0(helper_fdtoq);
2499 gen_op_store_QT0_fpr(QFPREG(rd));
2505 gen_op_load_fpr_FT1(rs2);
2506 gen_clear_float_exceptions();
2507 tcg_gen_helper_0_0(helper_fstoi);
2508 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2509 gen_op_store_FT0_fpr(rd);
2512 gen_op_load_fpr_DT1(DFPREG(rs2));
2513 gen_clear_float_exceptions();
2514 tcg_gen_helper_0_0(helper_fdtoi);
2515 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2516 gen_op_store_FT0_fpr(rd);
2518 case 0xd3: /* fqtoi */
2519 #if defined(CONFIG_USER_ONLY)
2520 gen_op_load_fpr_QT1(QFPREG(rs2));
2521 gen_clear_float_exceptions();
2522 tcg_gen_helper_0_0(helper_fqtoi);
2523 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2524 gen_op_store_FT0_fpr(rd);
2529 #ifdef TARGET_SPARC64
2530 case 0x2: /* V9 fmovd */
2531 gen_op_load_fpr_DT0(DFPREG(rs2));
2532 gen_op_store_DT0_fpr(DFPREG(rd));
2534 case 0x3: /* V9 fmovq */
2535 #if defined(CONFIG_USER_ONLY)
2536 gen_op_load_fpr_QT0(QFPREG(rs2));
2537 gen_op_store_QT0_fpr(QFPREG(rd));
2542 case 0x6: /* V9 fnegd */
2543 gen_op_load_fpr_DT1(DFPREG(rs2));
2544 tcg_gen_helper_0_0(helper_fnegd);
2545 gen_op_store_DT0_fpr(DFPREG(rd));
2547 case 0x7: /* V9 fnegq */
2548 #if defined(CONFIG_USER_ONLY)
2549 gen_op_load_fpr_QT1(QFPREG(rs2));
2550 tcg_gen_helper_0_0(helper_fnegq);
2551 gen_op_store_QT0_fpr(QFPREG(rd));
2556 case 0xa: /* V9 fabsd */
2557 gen_op_load_fpr_DT1(DFPREG(rs2));
2558 tcg_gen_helper_0_0(helper_fabsd);
2559 gen_op_store_DT0_fpr(DFPREG(rd));
2561 case 0xb: /* V9 fabsq */
2562 #if defined(CONFIG_USER_ONLY)
2563 gen_op_load_fpr_QT1(QFPREG(rs2));
2564 tcg_gen_helper_0_0(helper_fabsq);
2565 gen_op_store_QT0_fpr(QFPREG(rd));
2570 case 0x81: /* V9 fstox */
2571 gen_op_load_fpr_FT1(rs2);
2572 gen_clear_float_exceptions();
2573 tcg_gen_helper_0_0(helper_fstox);
2574 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2575 gen_op_store_DT0_fpr(DFPREG(rd));
2577 case 0x82: /* V9 fdtox */
2578 gen_op_load_fpr_DT1(DFPREG(rs2));
2579 gen_clear_float_exceptions();
2580 tcg_gen_helper_0_0(helper_fdtox);
2581 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2582 gen_op_store_DT0_fpr(DFPREG(rd));
2584 case 0x83: /* V9 fqtox */
2585 #if defined(CONFIG_USER_ONLY)
2586 gen_op_load_fpr_QT1(QFPREG(rs2));
2587 gen_clear_float_exceptions();
2588 tcg_gen_helper_0_0(helper_fqtox);
2589 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2590 gen_op_store_DT0_fpr(DFPREG(rd));
2595 case 0x84: /* V9 fxtos */
2596 gen_op_load_fpr_DT1(DFPREG(rs2));
2597 gen_clear_float_exceptions();
2598 tcg_gen_helper_0_0(helper_fxtos);
2599 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2600 gen_op_store_FT0_fpr(rd);
2602 case 0x88: /* V9 fxtod */
2603 gen_op_load_fpr_DT1(DFPREG(rs2));
2604 gen_clear_float_exceptions();
2605 tcg_gen_helper_0_0(helper_fxtod);
2606 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2607 gen_op_store_DT0_fpr(DFPREG(rd));
2609 case 0x8c: /* V9 fxtoq */
2610 #if defined(CONFIG_USER_ONLY)
2611 gen_op_load_fpr_DT1(DFPREG(rs2));
2612 gen_clear_float_exceptions();
2613 tcg_gen_helper_0_0(helper_fxtoq);
2614 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2615 gen_op_store_QT0_fpr(QFPREG(rd));
2624 } else if (xop == 0x35) { /* FPU Operations */
2625 #ifdef TARGET_SPARC64
2628 if (gen_trap_ifnofpu(dc, cpu_cond))
2630 gen_op_clear_ieee_excp_and_FTT();
2631 rs1 = GET_FIELD(insn, 13, 17);
2632 rs2 = GET_FIELD(insn, 27, 31);
2633 xop = GET_FIELD(insn, 18, 26);
2634 #ifdef TARGET_SPARC64
2635 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2638 l1 = gen_new_label();
2639 cond = GET_FIELD_SP(insn, 14, 17);
2640 rs1 = GET_FIELD(insn, 13, 17);
2641 gen_movl_reg_TN(rs1, cpu_src1);
2642 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2643 tcg_const_tl(0), l1);
2644 gen_op_load_fpr_FT0(rs2);
2645 gen_op_store_FT0_fpr(rd);
2648 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2651 l1 = gen_new_label();
2652 cond = GET_FIELD_SP(insn, 14, 17);
2653 rs1 = GET_FIELD(insn, 13, 17);
2654 gen_movl_reg_TN(rs1, cpu_src1);
2655 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2656 tcg_const_tl(0), l1);
2657 gen_op_load_fpr_DT0(DFPREG(rs2));
2658 gen_op_store_DT0_fpr(DFPREG(rd));
2661 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2662 #if defined(CONFIG_USER_ONLY)
2665 l1 = gen_new_label();
2666 cond = GET_FIELD_SP(insn, 14, 17);
2667 rs1 = GET_FIELD(insn, 13, 17);
2668 gen_movl_reg_TN(rs1, cpu_src1);
2669 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2670 tcg_const_tl(0), l1);
2671 gen_op_load_fpr_QT0(QFPREG(rs2));
2672 gen_op_store_QT0_fpr(QFPREG(rd));
2681 #ifdef TARGET_SPARC64
2682 #define FMOVCC(size_FDQ, fcc) \
2687 l1 = gen_new_label(); \
2688 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2689 cond = GET_FIELD_SP(insn, 14, 17); \
2690 gen_fcond(r_cond, fcc, cond); \
2691 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2692 tcg_const_tl(0), l1); \
2693 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2694 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2695 gen_set_label(l1); \
2696 tcg_gen_discard_tl(r_cond); \
2698 case 0x001: /* V9 fmovscc %fcc0 */
2701 case 0x002: /* V9 fmovdcc %fcc0 */
2704 case 0x003: /* V9 fmovqcc %fcc0 */
2705 #if defined(CONFIG_USER_ONLY)
2711 case 0x041: /* V9 fmovscc %fcc1 */
2714 case 0x042: /* V9 fmovdcc %fcc1 */
2717 case 0x043: /* V9 fmovqcc %fcc1 */
2718 #if defined(CONFIG_USER_ONLY)
2724 case 0x081: /* V9 fmovscc %fcc2 */
2727 case 0x082: /* V9 fmovdcc %fcc2 */
2730 case 0x083: /* V9 fmovqcc %fcc2 */
2731 #if defined(CONFIG_USER_ONLY)
2737 case 0x0c1: /* V9 fmovscc %fcc3 */
2740 case 0x0c2: /* V9 fmovdcc %fcc3 */
2743 case 0x0c3: /* V9 fmovqcc %fcc3 */
2744 #if defined(CONFIG_USER_ONLY)
2751 #define FMOVCC(size_FDQ, icc) \
2756 l1 = gen_new_label(); \
2757 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2758 cond = GET_FIELD_SP(insn, 14, 17); \
2759 gen_cond(r_cond, icc, cond); \
2760 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2761 tcg_const_tl(0), l1); \
2762 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2763 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2764 gen_set_label(l1); \
2765 tcg_gen_discard_tl(r_cond); \
2768 case 0x101: /* V9 fmovscc %icc */
2771 case 0x102: /* V9 fmovdcc %icc */
2773 case 0x103: /* V9 fmovqcc %icc */
2774 #if defined(CONFIG_USER_ONLY)
2780 case 0x181: /* V9 fmovscc %xcc */
2783 case 0x182: /* V9 fmovdcc %xcc */
2786 case 0x183: /* V9 fmovqcc %xcc */
2787 #if defined(CONFIG_USER_ONLY)
2795 case 0x51: /* fcmps, V9 %fcc */
2796 gen_op_load_fpr_FT0(rs1);
2797 gen_op_load_fpr_FT1(rs2);
2798 gen_op_fcmps(rd & 3);
2800 case 0x52: /* fcmpd, V9 %fcc */
2801 gen_op_load_fpr_DT0(DFPREG(rs1));
2802 gen_op_load_fpr_DT1(DFPREG(rs2));
2803 gen_op_fcmpd(rd & 3);
2805 case 0x53: /* fcmpq, V9 %fcc */
2806 #if defined(CONFIG_USER_ONLY)
2807 gen_op_load_fpr_QT0(QFPREG(rs1));
2808 gen_op_load_fpr_QT1(QFPREG(rs2));
2809 gen_op_fcmpq(rd & 3);
2811 #else /* !defined(CONFIG_USER_ONLY) */
2814 case 0x55: /* fcmpes, V9 %fcc */
2815 gen_op_load_fpr_FT0(rs1);
2816 gen_op_load_fpr_FT1(rs2);
2817 gen_op_fcmpes(rd & 3);
2819 case 0x56: /* fcmped, V9 %fcc */
2820 gen_op_load_fpr_DT0(DFPREG(rs1));
2821 gen_op_load_fpr_DT1(DFPREG(rs2));
2822 gen_op_fcmped(rd & 3);
2824 case 0x57: /* fcmpeq, V9 %fcc */
2825 #if defined(CONFIG_USER_ONLY)
2826 gen_op_load_fpr_QT0(QFPREG(rs1));
2827 gen_op_load_fpr_QT1(QFPREG(rs2));
2828 gen_op_fcmpeq(rd & 3);
2830 #else/* !defined(CONFIG_USER_ONLY) */
2837 } else if (xop == 0x2) {
2840 rs1 = GET_FIELD(insn, 13, 17);
2842 // or %g0, x, y -> mov T0, x; mov y, T0
2843 if (IS_IMM) { /* immediate */
2844 rs2 = GET_FIELDs(insn, 19, 31);
2845 tcg_gen_movi_tl(cpu_dst, (int)rs2);
2846 } else { /* register */
2847 rs2 = GET_FIELD(insn, 27, 31);
2848 gen_movl_reg_TN(rs2, cpu_dst);
2851 gen_movl_reg_TN(rs1, cpu_src1);
2852 if (IS_IMM) { /* immediate */
2853 rs2 = GET_FIELDs(insn, 19, 31);
2854 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2855 } else { /* register */
2856 // or x, %g0, y -> mov T1, x; mov y, T1
2857 rs2 = GET_FIELD(insn, 27, 31);
2859 gen_movl_reg_TN(rs2, cpu_src2);
2860 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2864 gen_movl_TN_reg(rd, cpu_dst);
2866 #ifdef TARGET_SPARC64
2867 } else if (xop == 0x25) { /* sll, V9 sllx */
2868 rs1 = GET_FIELD(insn, 13, 17);
2869 gen_movl_reg_TN(rs1, cpu_src1);
2870 if (IS_IMM) { /* immediate */
2871 rs2 = GET_FIELDs(insn, 20, 31);
2872 if (insn & (1 << 12)) {
2873 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2875 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2876 tcg_gen_shli_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2878 } else { /* register */
2879 rs2 = GET_FIELD(insn, 27, 31);
2880 gen_movl_reg_TN(rs2, cpu_src2);
2881 if (insn & (1 << 12)) {
2882 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2883 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2885 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2886 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2887 tcg_gen_shl_i64(cpu_dst, cpu_dst, cpu_tmp0);
2890 gen_movl_TN_reg(rd, cpu_dst);
2891 } else if (xop == 0x26) { /* srl, V9 srlx */
2892 rs1 = GET_FIELD(insn, 13, 17);
2893 gen_movl_reg_TN(rs1, cpu_src1);
2894 if (IS_IMM) { /* immediate */
2895 rs2 = GET_FIELDs(insn, 20, 31);
2896 if (insn & (1 << 12)) {
2897 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2899 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2900 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2902 } else { /* register */
2903 rs2 = GET_FIELD(insn, 27, 31);
2904 gen_movl_reg_TN(rs2, cpu_src2);
2905 if (insn & (1 << 12)) {
2906 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2907 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2909 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2910 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2911 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2914 gen_movl_TN_reg(rd, cpu_dst);
2915 } else if (xop == 0x27) { /* sra, V9 srax */
2916 rs1 = GET_FIELD(insn, 13, 17);
2917 gen_movl_reg_TN(rs1, cpu_src1);
2918 if (IS_IMM) { /* immediate */
2919 rs2 = GET_FIELDs(insn, 20, 31);
2920 if (insn & (1 << 12)) {
2921 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2923 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2924 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2925 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2927 } else { /* register */
2928 rs2 = GET_FIELD(insn, 27, 31);
2929 gen_movl_reg_TN(rs2, cpu_src2);
2930 if (insn & (1 << 12)) {
2931 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2932 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2934 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2935 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2936 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2939 gen_movl_TN_reg(rd, cpu_dst);
2941 } else if (xop < 0x36) {
2942 rs1 = GET_FIELD(insn, 13, 17);
2943 gen_movl_reg_TN(rs1, cpu_src1);
2944 if (IS_IMM) { /* immediate */
2945 rs2 = GET_FIELDs(insn, 19, 31);
2946 tcg_gen_movi_tl(cpu_src2, (int)rs2);
2947 } else { /* register */
2948 rs2 = GET_FIELD(insn, 27, 31);
2949 gen_movl_reg_TN(rs2, cpu_src2);
2952 switch (xop & ~0x10) {
2955 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2957 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2960 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
2962 gen_op_logic_cc(cpu_dst);
2965 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2967 gen_op_logic_cc(cpu_dst);
2970 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
2972 gen_op_logic_cc(cpu_dst);
2976 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
2978 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
2981 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2982 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
2984 gen_op_logic_cc(cpu_dst);
2987 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2988 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
2990 gen_op_logic_cc(cpu_dst);
2993 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2994 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
2996 gen_op_logic_cc(cpu_dst);
3000 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3002 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3003 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3004 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3007 #ifdef TARGET_SPARC64
3008 case 0x9: /* V9 mulx */
3009 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3013 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3015 gen_op_logic_cc(cpu_dst);
3018 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3020 gen_op_logic_cc(cpu_dst);
3024 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3026 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3027 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3028 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3031 #ifdef TARGET_SPARC64
3032 case 0xd: /* V9 udivx */
3033 gen_trap_ifdivzero_tl(cpu_src2);
3034 tcg_gen_divu_i64(cpu_dst, cpu_src1, cpu_src2);
3038 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1, cpu_src2);
3040 gen_op_div_cc(cpu_dst);
3043 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1, cpu_src2);
3045 gen_op_div_cc(cpu_dst);
3050 gen_movl_TN_reg(rd, cpu_dst);
3053 case 0x20: /* taddcc */
3054 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3055 gen_movl_TN_reg(rd, cpu_dst);
3057 case 0x21: /* tsubcc */
3058 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3059 gen_movl_TN_reg(rd, cpu_dst);
3061 case 0x22: /* taddcctv */
3062 save_state(dc, cpu_cond);
3063 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3064 gen_movl_TN_reg(rd, cpu_dst);
3066 case 0x23: /* tsubcctv */
3067 save_state(dc, cpu_cond);
3068 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3069 gen_movl_TN_reg(rd, cpu_dst);
3071 case 0x24: /* mulscc */
3072 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3073 gen_movl_TN_reg(rd, cpu_dst);
3075 #ifndef TARGET_SPARC64
3076 case 0x25: /* sll */
3077 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3078 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3079 gen_movl_TN_reg(rd, cpu_dst);
3081 case 0x26: /* srl */
3082 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3083 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3084 gen_movl_TN_reg(rd, cpu_dst);
3086 case 0x27: /* sra */
3087 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3088 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3089 gen_movl_TN_reg(rd, cpu_dst);
3096 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3097 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
3099 #ifndef TARGET_SPARC64
3100 case 0x01 ... 0x0f: /* undefined in the
3104 case 0x10 ... 0x1f: /* implementation-dependent
3110 case 0x2: /* V9 wrccr */
3111 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3112 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3114 case 0x3: /* V9 wrasi */
3115 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3116 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3117 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
3119 case 0x6: /* V9 wrfprs */
3120 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3121 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3122 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
3123 save_state(dc, cpu_cond);
3128 case 0xf: /* V9 sir, nop if user */
3129 #if !defined(CONFIG_USER_ONLY)
3134 case 0x13: /* Graphics Status */
3135 if (gen_trap_ifnofpu(dc, cpu_cond))
3137 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3138 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
3140 case 0x17: /* Tick compare */
3141 #if !defined(CONFIG_USER_ONLY)
3142 if (!supervisor(dc))
3148 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3150 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3152 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3153 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3154 offsetof(CPUState, tick));
3155 tcg_gen_helper_0_2(helper_tick_set_limit,
3156 r_tickptr, cpu_dst);
3157 tcg_gen_discard_ptr(r_tickptr);
3160 case 0x18: /* System tick */
3161 #if !defined(CONFIG_USER_ONLY)
3162 if (!supervisor(dc))
3168 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3170 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3171 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3172 offsetof(CPUState, stick));
3173 tcg_gen_helper_0_2(helper_tick_set_count,
3174 r_tickptr, cpu_dst);
3175 tcg_gen_discard_ptr(r_tickptr);
3178 case 0x19: /* System tick compare */
3179 #if !defined(CONFIG_USER_ONLY)
3180 if (!supervisor(dc))
3186 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3188 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3190 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3191 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3192 offsetof(CPUState, stick));
3193 tcg_gen_helper_0_2(helper_tick_set_limit,
3194 r_tickptr, cpu_dst);
3195 tcg_gen_discard_ptr(r_tickptr);
3199 case 0x10: /* Performance Control */
3200 case 0x11: /* Performance Instrumentation Counter */
3201 case 0x12: /* Dispatch Control */
3202 case 0x14: /* Softint set */
3203 case 0x15: /* Softint clear */
3204 case 0x16: /* Softint write */
3211 #if !defined(CONFIG_USER_ONLY)
3212 case 0x31: /* wrpsr, V9 saved, restored */
3214 if (!supervisor(dc))
3216 #ifdef TARGET_SPARC64
3219 tcg_gen_helper_0_0(helper_saved);
3222 tcg_gen_helper_0_0(helper_restored);
3224 case 2: /* UA2005 allclean */
3225 case 3: /* UA2005 otherw */
3226 case 4: /* UA2005 normalw */
3227 case 5: /* UA2005 invalw */
3233 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3234 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3235 save_state(dc, cpu_cond);
3242 case 0x32: /* wrwim, V9 wrpr */
3244 if (!supervisor(dc))
3246 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3247 #ifdef TARGET_SPARC64
3253 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3254 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3255 offsetof(CPUState, tsptr));
3256 tcg_gen_st_tl(cpu_dst, r_tsptr,
3257 offsetof(trap_state, tpc));
3258 tcg_gen_discard_ptr(r_tsptr);
3265 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3266 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3267 offsetof(CPUState, tsptr));
3268 tcg_gen_st_tl(cpu_dst, r_tsptr,
3269 offsetof(trap_state, tnpc));
3270 tcg_gen_discard_ptr(r_tsptr);
3277 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3278 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3279 offsetof(CPUState, tsptr));
3280 tcg_gen_st_tl(cpu_dst, r_tsptr,
3281 offsetof(trap_state, tstate));
3282 tcg_gen_discard_ptr(r_tsptr);
3289 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3290 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3291 offsetof(CPUState, tsptr));
3292 tcg_gen_st_i32(cpu_dst, r_tsptr,
3293 offsetof(trap_state, tt));
3294 tcg_gen_discard_ptr(r_tsptr);
3301 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3302 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3303 offsetof(CPUState, tick));
3304 tcg_gen_helper_0_2(helper_tick_set_count,
3305 r_tickptr, cpu_dst);
3306 tcg_gen_discard_ptr(r_tickptr);
3310 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
3313 save_state(dc, cpu_cond);
3314 tcg_gen_helper_0_1(helper_wrpstate, cpu_dst);
3320 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3321 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
3324 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3325 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
3328 tcg_gen_helper_0_1(helper_wrcwp, cpu_dst);
3331 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3332 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
3334 case 11: // canrestore
3335 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3336 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
3338 case 12: // cleanwin
3339 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3340 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
3342 case 13: // otherwin
3343 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3344 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
3347 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3348 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
3350 case 16: // UA2005 gl
3351 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3352 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
3354 case 26: // UA2005 strand status
3355 if (!hypervisor(dc))
3357 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3358 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
3364 tcg_gen_andi_tl(cpu_dst, cpu_dst, ((1 << NWINDOWS) - 1));
3365 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3366 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
3370 case 0x33: /* wrtbr, UA2005 wrhpr */
3372 #ifndef TARGET_SPARC64
3373 if (!supervisor(dc))
3375 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3376 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
3378 if (!hypervisor(dc))
3380 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3383 // XXX gen_op_wrhpstate();
3384 save_state(dc, cpu_cond);
3390 // XXX gen_op_wrhtstate();
3393 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3394 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
3397 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3398 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
3400 case 31: // hstick_cmpr
3404 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3406 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3407 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3408 offsetof(CPUState, hstick));
3409 tcg_gen_helper_0_2(helper_tick_set_limit,
3410 r_tickptr, cpu_dst);
3411 tcg_gen_discard_ptr(r_tickptr);
3414 case 6: // hver readonly
3422 #ifdef TARGET_SPARC64
3423 case 0x2c: /* V9 movcc */
3425 int cc = GET_FIELD_SP(insn, 11, 12);
3426 int cond = GET_FIELD_SP(insn, 14, 17);
3430 r_cond = tcg_temp_new(TCG_TYPE_TL);
3431 if (insn & (1 << 18)) {
3433 gen_cond(r_cond, 0, cond);
3435 gen_cond(r_cond, 1, cond);
3439 gen_fcond(r_cond, cc, cond);
3442 l1 = gen_new_label();
3444 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond,
3445 tcg_const_tl(0), l1);
3446 if (IS_IMM) { /* immediate */
3447 rs2 = GET_FIELD_SPs(insn, 0, 10);
3448 tcg_gen_movi_tl(cpu_dst, (int)rs2);
3450 rs2 = GET_FIELD_SP(insn, 0, 4);
3451 gen_movl_reg_TN(rs2, cpu_dst);
3453 gen_movl_TN_reg(rd, cpu_dst);
3455 tcg_gen_discard_tl(r_cond);
3458 case 0x2d: /* V9 sdivx */
3459 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3460 gen_movl_TN_reg(rd, cpu_dst);
3462 case 0x2e: /* V9 popc */
3464 if (IS_IMM) { /* immediate */
3465 rs2 = GET_FIELD_SPs(insn, 0, 12);
3466 tcg_gen_movi_tl(cpu_src2, (int)rs2);
3467 // XXX optimize: popc(constant)
3470 rs2 = GET_FIELD_SP(insn, 0, 4);
3471 gen_movl_reg_TN(rs2, cpu_src2);
3473 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3475 gen_movl_TN_reg(rd, cpu_dst);
3477 case 0x2f: /* V9 movr */
3479 int cond = GET_FIELD_SP(insn, 10, 12);
3482 rs1 = GET_FIELD(insn, 13, 17);
3483 gen_movl_reg_TN(rs1, cpu_src1);
3485 l1 = gen_new_label();
3487 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
3488 tcg_const_tl(0), l1);
3489 if (IS_IMM) { /* immediate */
3490 rs2 = GET_FIELD_SPs(insn, 0, 9);
3491 tcg_gen_movi_tl(cpu_dst, (int)rs2);
3493 rs2 = GET_FIELD_SP(insn, 0, 4);
3494 gen_movl_reg_TN(rs2, cpu_dst);
3496 gen_movl_TN_reg(rd, cpu_dst);
3505 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3506 #ifdef TARGET_SPARC64
3507 int opf = GET_FIELD_SP(insn, 5, 13);
3508 rs1 = GET_FIELD(insn, 13, 17);
3509 rs2 = GET_FIELD(insn, 27, 31);
3510 if (gen_trap_ifnofpu(dc, cpu_cond))
3514 case 0x000: /* VIS I edge8cc */
3515 case 0x001: /* VIS II edge8n */
3516 case 0x002: /* VIS I edge8lcc */
3517 case 0x003: /* VIS II edge8ln */
3518 case 0x004: /* VIS I edge16cc */
3519 case 0x005: /* VIS II edge16n */
3520 case 0x006: /* VIS I edge16lcc */
3521 case 0x007: /* VIS II edge16ln */
3522 case 0x008: /* VIS I edge32cc */
3523 case 0x009: /* VIS II edge32n */
3524 case 0x00a: /* VIS I edge32lcc */
3525 case 0x00b: /* VIS II edge32ln */
3528 case 0x010: /* VIS I array8 */
3529 gen_movl_reg_TN(rs1, cpu_src1);
3530 gen_movl_reg_TN(rs2, cpu_src2);
3531 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3533 gen_movl_TN_reg(rd, cpu_dst);
3535 case 0x012: /* VIS I array16 */
3536 gen_movl_reg_TN(rs1, cpu_src1);
3537 gen_movl_reg_TN(rs2, cpu_src2);
3538 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3540 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3541 gen_movl_TN_reg(rd, cpu_dst);
3543 case 0x014: /* VIS I array32 */
3544 gen_movl_reg_TN(rs1, cpu_src1);
3545 gen_movl_reg_TN(rs2, cpu_src2);
3546 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3548 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3549 gen_movl_TN_reg(rd, cpu_dst);
3551 case 0x018: /* VIS I alignaddr */
3552 gen_movl_reg_TN(rs1, cpu_src1);
3553 gen_movl_reg_TN(rs2, cpu_src2);
3554 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3556 gen_movl_TN_reg(rd, cpu_dst);
3558 case 0x019: /* VIS II bmask */
3559 case 0x01a: /* VIS I alignaddrl */
3562 case 0x020: /* VIS I fcmple16 */
3563 gen_op_load_fpr_DT0(DFPREG(rs1));
3564 gen_op_load_fpr_DT1(DFPREG(rs2));
3565 tcg_gen_helper_0_0(helper_fcmple16);
3566 gen_op_store_DT0_fpr(DFPREG(rd));
3568 case 0x022: /* VIS I fcmpne16 */
3569 gen_op_load_fpr_DT0(DFPREG(rs1));
3570 gen_op_load_fpr_DT1(DFPREG(rs2));
3571 tcg_gen_helper_0_0(helper_fcmpne16);
3572 gen_op_store_DT0_fpr(DFPREG(rd));
3574 case 0x024: /* VIS I fcmple32 */
3575 gen_op_load_fpr_DT0(DFPREG(rs1));
3576 gen_op_load_fpr_DT1(DFPREG(rs2));
3577 tcg_gen_helper_0_0(helper_fcmple32);
3578 gen_op_store_DT0_fpr(DFPREG(rd));
3580 case 0x026: /* VIS I fcmpne32 */
3581 gen_op_load_fpr_DT0(DFPREG(rs1));
3582 gen_op_load_fpr_DT1(DFPREG(rs2));
3583 tcg_gen_helper_0_0(helper_fcmpne32);
3584 gen_op_store_DT0_fpr(DFPREG(rd));
3586 case 0x028: /* VIS I fcmpgt16 */
3587 gen_op_load_fpr_DT0(DFPREG(rs1));
3588 gen_op_load_fpr_DT1(DFPREG(rs2));
3589 tcg_gen_helper_0_0(helper_fcmpgt16);
3590 gen_op_store_DT0_fpr(DFPREG(rd));
3592 case 0x02a: /* VIS I fcmpeq16 */
3593 gen_op_load_fpr_DT0(DFPREG(rs1));
3594 gen_op_load_fpr_DT1(DFPREG(rs2));
3595 tcg_gen_helper_0_0(helper_fcmpeq16);
3596 gen_op_store_DT0_fpr(DFPREG(rd));
3598 case 0x02c: /* VIS I fcmpgt32 */
3599 gen_op_load_fpr_DT0(DFPREG(rs1));
3600 gen_op_load_fpr_DT1(DFPREG(rs2));
3601 tcg_gen_helper_0_0(helper_fcmpgt32);
3602 gen_op_store_DT0_fpr(DFPREG(rd));
3604 case 0x02e: /* VIS I fcmpeq32 */
3605 gen_op_load_fpr_DT0(DFPREG(rs1));
3606 gen_op_load_fpr_DT1(DFPREG(rs2));
3607 tcg_gen_helper_0_0(helper_fcmpeq32);
3608 gen_op_store_DT0_fpr(DFPREG(rd));
3610 case 0x031: /* VIS I fmul8x16 */
3611 gen_op_load_fpr_DT0(DFPREG(rs1));
3612 gen_op_load_fpr_DT1(DFPREG(rs2));
3613 tcg_gen_helper_0_0(helper_fmul8x16);
3614 gen_op_store_DT0_fpr(DFPREG(rd));
3616 case 0x033: /* VIS I fmul8x16au */
3617 gen_op_load_fpr_DT0(DFPREG(rs1));
3618 gen_op_load_fpr_DT1(DFPREG(rs2));
3619 tcg_gen_helper_0_0(helper_fmul8x16au);
3620 gen_op_store_DT0_fpr(DFPREG(rd));
3622 case 0x035: /* VIS I fmul8x16al */
3623 gen_op_load_fpr_DT0(DFPREG(rs1));
3624 gen_op_load_fpr_DT1(DFPREG(rs2));
3625 tcg_gen_helper_0_0(helper_fmul8x16al);
3626 gen_op_store_DT0_fpr(DFPREG(rd));
3628 case 0x036: /* VIS I fmul8sux16 */
3629 gen_op_load_fpr_DT0(DFPREG(rs1));
3630 gen_op_load_fpr_DT1(DFPREG(rs2));
3631 tcg_gen_helper_0_0(helper_fmul8sux16);
3632 gen_op_store_DT0_fpr(DFPREG(rd));
3634 case 0x037: /* VIS I fmul8ulx16 */
3635 gen_op_load_fpr_DT0(DFPREG(rs1));
3636 gen_op_load_fpr_DT1(DFPREG(rs2));
3637 tcg_gen_helper_0_0(helper_fmul8ulx16);
3638 gen_op_store_DT0_fpr(DFPREG(rd));
3640 case 0x038: /* VIS I fmuld8sux16 */
3641 gen_op_load_fpr_DT0(DFPREG(rs1));
3642 gen_op_load_fpr_DT1(DFPREG(rs2));
3643 tcg_gen_helper_0_0(helper_fmuld8sux16);
3644 gen_op_store_DT0_fpr(DFPREG(rd));
3646 case 0x039: /* VIS I fmuld8ulx16 */
3647 gen_op_load_fpr_DT0(DFPREG(rs1));
3648 gen_op_load_fpr_DT1(DFPREG(rs2));
3649 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3650 gen_op_store_DT0_fpr(DFPREG(rd));
3652 case 0x03a: /* VIS I fpack32 */
3653 case 0x03b: /* VIS I fpack16 */
3654 case 0x03d: /* VIS I fpackfix */
3655 case 0x03e: /* VIS I pdist */
3658 case 0x048: /* VIS I faligndata */
3659 gen_op_load_fpr_DT0(DFPREG(rs1));
3660 gen_op_load_fpr_DT1(DFPREG(rs2));
3661 tcg_gen_helper_0_0(helper_faligndata);
3662 gen_op_store_DT0_fpr(DFPREG(rd));
3664 case 0x04b: /* VIS I fpmerge */
3665 gen_op_load_fpr_DT0(DFPREG(rs1));
3666 gen_op_load_fpr_DT1(DFPREG(rs2));
3667 tcg_gen_helper_0_0(helper_fpmerge);
3668 gen_op_store_DT0_fpr(DFPREG(rd));
3670 case 0x04c: /* VIS II bshuffle */
3673 case 0x04d: /* VIS I fexpand */
3674 gen_op_load_fpr_DT0(DFPREG(rs1));
3675 gen_op_load_fpr_DT1(DFPREG(rs2));
3676 tcg_gen_helper_0_0(helper_fexpand);
3677 gen_op_store_DT0_fpr(DFPREG(rd));
3679 case 0x050: /* VIS I fpadd16 */
3680 gen_op_load_fpr_DT0(DFPREG(rs1));
3681 gen_op_load_fpr_DT1(DFPREG(rs2));
3682 tcg_gen_helper_0_0(helper_fpadd16);
3683 gen_op_store_DT0_fpr(DFPREG(rd));
3685 case 0x051: /* VIS I fpadd16s */
3686 gen_op_load_fpr_FT0(rs1);
3687 gen_op_load_fpr_FT1(rs2);
3688 tcg_gen_helper_0_0(helper_fpadd16s);
3689 gen_op_store_FT0_fpr(rd);
3691 case 0x052: /* VIS I fpadd32 */
3692 gen_op_load_fpr_DT0(DFPREG(rs1));
3693 gen_op_load_fpr_DT1(DFPREG(rs2));
3694 tcg_gen_helper_0_0(helper_fpadd32);
3695 gen_op_store_DT0_fpr(DFPREG(rd));
3697 case 0x053: /* VIS I fpadd32s */
3698 gen_op_load_fpr_FT0(rs1);
3699 gen_op_load_fpr_FT1(rs2);
3700 tcg_gen_helper_0_0(helper_fpadd32s);
3701 gen_op_store_FT0_fpr(rd);
3703 case 0x054: /* VIS I fpsub16 */
3704 gen_op_load_fpr_DT0(DFPREG(rs1));
3705 gen_op_load_fpr_DT1(DFPREG(rs2));
3706 tcg_gen_helper_0_0(helper_fpsub16);
3707 gen_op_store_DT0_fpr(DFPREG(rd));
3709 case 0x055: /* VIS I fpsub16s */
3710 gen_op_load_fpr_FT0(rs1);
3711 gen_op_load_fpr_FT1(rs2);
3712 tcg_gen_helper_0_0(helper_fpsub16s);
3713 gen_op_store_FT0_fpr(rd);
3715 case 0x056: /* VIS I fpsub32 */
3716 gen_op_load_fpr_DT0(DFPREG(rs1));
3717 gen_op_load_fpr_DT1(DFPREG(rs2));
3718 tcg_gen_helper_0_0(helper_fpadd32);
3719 gen_op_store_DT0_fpr(DFPREG(rd));
3721 case 0x057: /* VIS I fpsub32s */
3722 gen_op_load_fpr_FT0(rs1);
3723 gen_op_load_fpr_FT1(rs2);
3724 tcg_gen_helper_0_0(helper_fpsub32s);
3725 gen_op_store_FT0_fpr(rd);
3727 case 0x060: /* VIS I fzero */
3728 tcg_gen_helper_0_0(helper_movl_DT0_0);
3729 gen_op_store_DT0_fpr(DFPREG(rd));
3731 case 0x061: /* VIS I fzeros */
3732 tcg_gen_helper_0_0(helper_movl_FT0_0);
3733 gen_op_store_FT0_fpr(rd);
3735 case 0x062: /* VIS I fnor */
3736 gen_op_load_fpr_DT0(DFPREG(rs1));
3737 gen_op_load_fpr_DT1(DFPREG(rs2));
3738 tcg_gen_helper_0_0(helper_fnor);
3739 gen_op_store_DT0_fpr(DFPREG(rd));
3741 case 0x063: /* VIS I fnors */
3742 gen_op_load_fpr_FT0(rs1);
3743 gen_op_load_fpr_FT1(rs2);
3744 tcg_gen_helper_0_0(helper_fnors);
3745 gen_op_store_FT0_fpr(rd);
3747 case 0x064: /* VIS I fandnot2 */
3748 gen_op_load_fpr_DT1(DFPREG(rs1));
3749 gen_op_load_fpr_DT0(DFPREG(rs2));
3750 tcg_gen_helper_0_0(helper_fandnot);
3751 gen_op_store_DT0_fpr(DFPREG(rd));
3753 case 0x065: /* VIS I fandnot2s */
3754 gen_op_load_fpr_FT1(rs1);
3755 gen_op_load_fpr_FT0(rs2);
3756 tcg_gen_helper_0_0(helper_fandnots);
3757 gen_op_store_FT0_fpr(rd);
3759 case 0x066: /* VIS I fnot2 */
3760 gen_op_load_fpr_DT1(DFPREG(rs2));
3761 tcg_gen_helper_0_0(helper_fnot);
3762 gen_op_store_DT0_fpr(DFPREG(rd));
3764 case 0x067: /* VIS I fnot2s */
3765 gen_op_load_fpr_FT1(rs2);
3766 tcg_gen_helper_0_0(helper_fnot);
3767 gen_op_store_FT0_fpr(rd);
3769 case 0x068: /* VIS I fandnot1 */
3770 gen_op_load_fpr_DT0(DFPREG(rs1));
3771 gen_op_load_fpr_DT1(DFPREG(rs2));
3772 tcg_gen_helper_0_0(helper_fandnot);
3773 gen_op_store_DT0_fpr(DFPREG(rd));
3775 case 0x069: /* VIS I fandnot1s */
3776 gen_op_load_fpr_FT0(rs1);
3777 gen_op_load_fpr_FT1(rs2);
3778 tcg_gen_helper_0_0(helper_fandnots);
3779 gen_op_store_FT0_fpr(rd);
3781 case 0x06a: /* VIS I fnot1 */
3782 gen_op_load_fpr_DT1(DFPREG(rs1));
3783 tcg_gen_helper_0_0(helper_fnot);
3784 gen_op_store_DT0_fpr(DFPREG(rd));
3786 case 0x06b: /* VIS I fnot1s */
3787 gen_op_load_fpr_FT1(rs1);
3788 tcg_gen_helper_0_0(helper_fnot);
3789 gen_op_store_FT0_fpr(rd);
3791 case 0x06c: /* VIS I fxor */
3792 gen_op_load_fpr_DT0(DFPREG(rs1));
3793 gen_op_load_fpr_DT1(DFPREG(rs2));
3794 tcg_gen_helper_0_0(helper_fxor);
3795 gen_op_store_DT0_fpr(DFPREG(rd));
3797 case 0x06d: /* VIS I fxors */
3798 gen_op_load_fpr_FT0(rs1);
3799 gen_op_load_fpr_FT1(rs2);
3800 tcg_gen_helper_0_0(helper_fxors);
3801 gen_op_store_FT0_fpr(rd);
3803 case 0x06e: /* VIS I fnand */
3804 gen_op_load_fpr_DT0(DFPREG(rs1));
3805 gen_op_load_fpr_DT1(DFPREG(rs2));
3806 tcg_gen_helper_0_0(helper_fnand);
3807 gen_op_store_DT0_fpr(DFPREG(rd));
3809 case 0x06f: /* VIS I fnands */
3810 gen_op_load_fpr_FT0(rs1);
3811 gen_op_load_fpr_FT1(rs2);
3812 tcg_gen_helper_0_0(helper_fnands);
3813 gen_op_store_FT0_fpr(rd);
3815 case 0x070: /* VIS I fand */
3816 gen_op_load_fpr_DT0(DFPREG(rs1));
3817 gen_op_load_fpr_DT1(DFPREG(rs2));
3818 tcg_gen_helper_0_0(helper_fand);
3819 gen_op_store_DT0_fpr(DFPREG(rd));
3821 case 0x071: /* VIS I fands */
3822 gen_op_load_fpr_FT0(rs1);
3823 gen_op_load_fpr_FT1(rs2);
3824 tcg_gen_helper_0_0(helper_fands);
3825 gen_op_store_FT0_fpr(rd);
3827 case 0x072: /* VIS I fxnor */
3828 gen_op_load_fpr_DT0(DFPREG(rs1));
3829 gen_op_load_fpr_DT1(DFPREG(rs2));
3830 tcg_gen_helper_0_0(helper_fxnor);
3831 gen_op_store_DT0_fpr(DFPREG(rd));
3833 case 0x073: /* VIS I fxnors */
3834 gen_op_load_fpr_FT0(rs1);
3835 gen_op_load_fpr_FT1(rs2);
3836 tcg_gen_helper_0_0(helper_fxnors);
3837 gen_op_store_FT0_fpr(rd);
3839 case 0x074: /* VIS I fsrc1 */
3840 gen_op_load_fpr_DT0(DFPREG(rs1));
3841 gen_op_store_DT0_fpr(DFPREG(rd));
3843 case 0x075: /* VIS I fsrc1s */
3844 gen_op_load_fpr_FT0(rs1);
3845 gen_op_store_FT0_fpr(rd);
3847 case 0x076: /* VIS I fornot2 */
3848 gen_op_load_fpr_DT1(DFPREG(rs1));
3849 gen_op_load_fpr_DT0(DFPREG(rs2));
3850 tcg_gen_helper_0_0(helper_fornot);
3851 gen_op_store_DT0_fpr(DFPREG(rd));
3853 case 0x077: /* VIS I fornot2s */
3854 gen_op_load_fpr_FT1(rs1);
3855 gen_op_load_fpr_FT0(rs2);
3856 tcg_gen_helper_0_0(helper_fornots);
3857 gen_op_store_FT0_fpr(rd);
3859 case 0x078: /* VIS I fsrc2 */
3860 gen_op_load_fpr_DT0(DFPREG(rs2));
3861 gen_op_store_DT0_fpr(DFPREG(rd));
3863 case 0x079: /* VIS I fsrc2s */
3864 gen_op_load_fpr_FT0(rs2);
3865 gen_op_store_FT0_fpr(rd);
3867 case 0x07a: /* VIS I fornot1 */
3868 gen_op_load_fpr_DT0(DFPREG(rs1));
3869 gen_op_load_fpr_DT1(DFPREG(rs2));
3870 tcg_gen_helper_0_0(helper_fornot);
3871 gen_op_store_DT0_fpr(DFPREG(rd));
3873 case 0x07b: /* VIS I fornot1s */
3874 gen_op_load_fpr_FT0(rs1);
3875 gen_op_load_fpr_FT1(rs2);
3876 tcg_gen_helper_0_0(helper_fornots);
3877 gen_op_store_FT0_fpr(rd);
3879 case 0x07c: /* VIS I for */
3880 gen_op_load_fpr_DT0(DFPREG(rs1));
3881 gen_op_load_fpr_DT1(DFPREG(rs2));
3882 tcg_gen_helper_0_0(helper_for);
3883 gen_op_store_DT0_fpr(DFPREG(rd));
3885 case 0x07d: /* VIS I fors */
3886 gen_op_load_fpr_FT0(rs1);
3887 gen_op_load_fpr_FT1(rs2);
3888 tcg_gen_helper_0_0(helper_fors);
3889 gen_op_store_FT0_fpr(rd);
3891 case 0x07e: /* VIS I fone */
3892 tcg_gen_helper_0_0(helper_movl_DT0_1);
3893 gen_op_store_DT0_fpr(DFPREG(rd));
3895 case 0x07f: /* VIS I fones */
3896 tcg_gen_helper_0_0(helper_movl_FT0_1);
3897 gen_op_store_FT0_fpr(rd);
3899 case 0x080: /* VIS I shutdown */
3900 case 0x081: /* VIS II siam */
3909 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
3910 #ifdef TARGET_SPARC64
3915 #ifdef TARGET_SPARC64
3916 } else if (xop == 0x39) { /* V9 return */
3917 rs1 = GET_FIELD(insn, 13, 17);
3918 save_state(dc, cpu_cond);
3919 gen_movl_reg_TN(rs1, cpu_src1);
3920 if (IS_IMM) { /* immediate */
3921 rs2 = GET_FIELDs(insn, 19, 31);
3922 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3923 } else { /* register */
3924 rs2 = GET_FIELD(insn, 27, 31);
3928 gen_movl_reg_TN(rs2, cpu_src2);
3929 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3934 tcg_gen_helper_0_0(helper_restore);
3935 gen_mov_pc_npc(dc, cpu_cond);
3936 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3937 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3938 dc->npc = DYNAMIC_PC;
3942 rs1 = GET_FIELD(insn, 13, 17);
3943 gen_movl_reg_TN(rs1, cpu_src1);
3944 if (IS_IMM) { /* immediate */
3945 rs2 = GET_FIELDs(insn, 19, 31);
3946 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3947 } else { /* register */
3948 rs2 = GET_FIELD(insn, 27, 31);
3952 gen_movl_reg_TN(rs2, cpu_src2);
3953 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3959 case 0x38: /* jmpl */
3962 tcg_gen_movi_tl(cpu_tmp0, dc->pc);
3963 gen_movl_TN_reg(rd, cpu_tmp0);
3965 gen_mov_pc_npc(dc, cpu_cond);
3966 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3967 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3968 dc->npc = DYNAMIC_PC;
3971 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
3972 case 0x39: /* rett, V9 return */
3974 if (!supervisor(dc))
3976 gen_mov_pc_npc(dc, cpu_cond);
3977 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3978 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3979 dc->npc = DYNAMIC_PC;
3980 tcg_gen_helper_0_0(helper_rett);
3984 case 0x3b: /* flush */
3985 tcg_gen_helper_0_1(helper_flush, cpu_dst);
3987 case 0x3c: /* save */
3988 save_state(dc, cpu_cond);
3989 tcg_gen_helper_0_0(helper_save);
3990 gen_movl_TN_reg(rd, cpu_dst);
3992 case 0x3d: /* restore */
3993 save_state(dc, cpu_cond);
3994 tcg_gen_helper_0_0(helper_restore);
3995 gen_movl_TN_reg(rd, cpu_dst);
3997 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
3998 case 0x3e: /* V9 done/retry */
4002 if (!supervisor(dc))
4004 dc->npc = DYNAMIC_PC;
4005 dc->pc = DYNAMIC_PC;
4006 tcg_gen_helper_0_0(helper_done);
4009 if (!supervisor(dc))
4011 dc->npc = DYNAMIC_PC;
4012 dc->pc = DYNAMIC_PC;
4013 tcg_gen_helper_0_0(helper_retry);
4028 case 3: /* load/store instructions */
4030 unsigned int xop = GET_FIELD(insn, 7, 12);
4031 rs1 = GET_FIELD(insn, 13, 17);
4032 save_state(dc, cpu_cond);
4033 gen_movl_reg_TN(rs1, cpu_src1);
4034 if (xop == 0x3c || xop == 0x3e)
4036 rs2 = GET_FIELD(insn, 27, 31);
4037 gen_movl_reg_TN(rs2, cpu_src2);
4039 else if (IS_IMM) { /* immediate */
4040 rs2 = GET_FIELDs(insn, 19, 31);
4041 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4042 } else { /* register */
4043 rs2 = GET_FIELD(insn, 27, 31);
4047 gen_movl_reg_TN(rs2, cpu_src2);
4048 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4053 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4054 (xop > 0x17 && xop <= 0x1d ) ||
4055 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4057 case 0x0: /* load unsigned word */
4058 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4059 ABI32_MASK(cpu_addr);
4060 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4062 case 0x1: /* load unsigned byte */
4063 ABI32_MASK(cpu_addr);
4064 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4066 case 0x2: /* load unsigned halfword */
4067 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4068 ABI32_MASK(cpu_addr);
4069 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4071 case 0x3: /* load double word */
4075 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4076 ABI32_MASK(cpu_addr);
4077 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4078 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4079 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4080 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4081 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4082 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4083 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4086 case 0x9: /* load signed byte */
4087 ABI32_MASK(cpu_addr);
4088 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4090 case 0xa: /* load signed halfword */
4091 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4092 ABI32_MASK(cpu_addr);
4093 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4095 case 0xd: /* ldstub -- XXX: should be atomically */
4096 ABI32_MASK(cpu_addr);
4097 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4098 tcg_gen_qemu_st8(tcg_const_tl(0xff), cpu_addr, dc->mem_idx);
4100 case 0x0f: /* swap register with memory. Also atomically */
4101 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4102 gen_movl_reg_TN(rd, cpu_val);
4103 ABI32_MASK(cpu_addr);
4104 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4105 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4106 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4108 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4109 case 0x10: /* load word alternate */
4110 #ifndef TARGET_SPARC64
4113 if (!supervisor(dc))
4116 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4117 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4119 case 0x11: /* load unsigned byte alternate */
4120 #ifndef TARGET_SPARC64
4123 if (!supervisor(dc))
4126 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4128 case 0x12: /* load unsigned halfword alternate */
4129 #ifndef TARGET_SPARC64
4132 if (!supervisor(dc))
4135 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4136 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4138 case 0x13: /* load double word alternate */
4139 #ifndef TARGET_SPARC64
4142 if (!supervisor(dc))
4147 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4148 gen_ldda_asi(cpu_tmp0, cpu_val, cpu_addr, insn);
4149 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4151 case 0x19: /* load signed byte alternate */
4152 #ifndef TARGET_SPARC64
4155 if (!supervisor(dc))
4158 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4160 case 0x1a: /* load signed halfword alternate */
4161 #ifndef TARGET_SPARC64
4164 if (!supervisor(dc))
4167 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4168 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4170 case 0x1d: /* ldstuba -- XXX: should be atomically */
4171 #ifndef TARGET_SPARC64
4174 if (!supervisor(dc))
4177 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4179 case 0x1f: /* swap reg with alt. memory. Also atomically */
4180 #ifndef TARGET_SPARC64
4183 if (!supervisor(dc))
4186 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4187 gen_movl_reg_TN(rd, cpu_val);
4188 gen_swap_asi(cpu_val, cpu_addr, insn);
4191 #ifndef TARGET_SPARC64
4192 case 0x30: /* ldc */
4193 case 0x31: /* ldcsr */
4194 case 0x33: /* lddc */
4198 #ifdef TARGET_SPARC64
4199 case 0x08: /* V9 ldsw */
4200 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4201 ABI32_MASK(cpu_addr);
4202 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4204 case 0x0b: /* V9 ldx */
4205 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4206 ABI32_MASK(cpu_addr);
4207 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4209 case 0x18: /* V9 ldswa */
4210 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4211 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4213 case 0x1b: /* V9 ldxa */
4214 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4215 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4217 case 0x2d: /* V9 prefetch, no effect */
4219 case 0x30: /* V9 ldfa */
4220 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4221 gen_ldf_asi(cpu_addr, insn, 4, rd);
4223 case 0x33: /* V9 lddfa */
4224 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4225 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4227 case 0x3d: /* V9 prefetcha, no effect */
4229 case 0x32: /* V9 ldqfa */
4230 #if defined(CONFIG_USER_ONLY)
4231 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4232 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4241 gen_movl_TN_reg(rd, cpu_val);
4242 #ifdef TARGET_SPARC64
4245 } else if (xop >= 0x20 && xop < 0x24) {
4246 if (gen_trap_ifnofpu(dc, cpu_cond))
4249 case 0x20: /* load fpreg */
4250 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4251 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4252 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4253 offsetof(CPUState, fpr[rd]));
4255 case 0x21: /* load fsr */
4256 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4257 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4258 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4259 offsetof(CPUState, ft0));
4260 tcg_gen_helper_0_0(helper_ldfsr);
4262 case 0x22: /* load quad fpreg */
4263 #if defined(CONFIG_USER_ONLY)
4264 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4266 gen_op_store_QT0_fpr(QFPREG(rd));
4271 case 0x23: /* load double fpreg */
4272 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4274 gen_op_store_DT0_fpr(DFPREG(rd));
4279 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4280 xop == 0xe || xop == 0x1e) {
4281 gen_movl_reg_TN(rd, cpu_val);
4283 case 0x4: /* store word */
4284 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4285 ABI32_MASK(cpu_addr);
4286 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4288 case 0x5: /* store byte */
4289 ABI32_MASK(cpu_addr);
4290 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4292 case 0x6: /* store halfword */
4293 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4294 ABI32_MASK(cpu_addr);
4295 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4297 case 0x7: /* store double word */
4304 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4305 r_low = tcg_temp_new(TCG_TYPE_I32);
4306 gen_movl_reg_TN(rd + 1, r_low);
4307 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4309 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4311 #else /* __i386__ */
4312 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4313 flush_cond(dc, cpu_cond);
4314 gen_movl_reg_TN(rd + 1, cpu_cond);
4316 #endif /* __i386__ */
4318 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4319 case 0x14: /* store word alternate */
4320 #ifndef TARGET_SPARC64
4323 if (!supervisor(dc))
4326 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4327 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4329 case 0x15: /* store byte alternate */
4330 #ifndef TARGET_SPARC64
4333 if (!supervisor(dc))
4336 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4338 case 0x16: /* store halfword alternate */
4339 #ifndef TARGET_SPARC64
4342 if (!supervisor(dc))
4345 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4346 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4348 case 0x17: /* store double word alternate */
4349 #ifndef TARGET_SPARC64
4352 if (!supervisor(dc))
4358 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4359 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4363 #ifdef TARGET_SPARC64
4364 case 0x0e: /* V9 stx */
4365 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4366 ABI32_MASK(cpu_addr);
4367 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4369 case 0x1e: /* V9 stxa */
4370 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4371 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4377 } else if (xop > 0x23 && xop < 0x28) {
4378 if (gen_trap_ifnofpu(dc, cpu_cond))
4381 case 0x24: /* store fpreg */
4382 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4383 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4384 offsetof(CPUState, fpr[rd]));
4385 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4387 case 0x25: /* stfsr, V9 stxfsr */
4388 #ifdef CONFIG_USER_ONLY
4389 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4391 tcg_gen_helper_0_0(helper_stfsr);
4392 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4393 offsetof(CPUState, ft0));
4394 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4397 #ifdef TARGET_SPARC64
4398 #if defined(CONFIG_USER_ONLY)
4399 /* V9 stqf, store quad fpreg */
4400 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4401 gen_op_load_fpr_QT0(QFPREG(rd));
4407 #else /* !TARGET_SPARC64 */
4408 /* stdfq, store floating point queue */
4409 #if defined(CONFIG_USER_ONLY)
4412 if (!supervisor(dc))
4414 if (gen_trap_ifnofpu(dc, cpu_cond))
4420 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4421 gen_op_load_fpr_DT0(DFPREG(rd));
4427 } else if (xop > 0x33 && xop < 0x3f) {
4429 #ifdef TARGET_SPARC64
4430 case 0x34: /* V9 stfa */
4431 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4432 gen_op_load_fpr_FT0(rd);
4433 gen_stf_asi(cpu_addr, insn, 4, rd);
4435 case 0x36: /* V9 stqfa */
4436 #if defined(CONFIG_USER_ONLY)
4437 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4438 gen_op_load_fpr_QT0(QFPREG(rd));
4439 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4444 case 0x37: /* V9 stdfa */
4445 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4446 gen_op_load_fpr_DT0(DFPREG(rd));
4447 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4449 case 0x3c: /* V9 casa */
4450 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4451 gen_cas_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4452 gen_movl_TN_reg(rd, cpu_val);
4454 case 0x3e: /* V9 casxa */
4455 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4456 gen_casx_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4457 gen_movl_TN_reg(rd, cpu_val);
4460 case 0x34: /* stc */
4461 case 0x35: /* stcsr */
4462 case 0x36: /* stdcq */
4463 case 0x37: /* stdc */
4475 /* default case for non jump instructions */
4476 if (dc->npc == DYNAMIC_PC) {
4477 dc->pc = DYNAMIC_PC;
4479 } else if (dc->npc == JUMP_PC) {
4480 /* we can do a static jump */
4481 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4485 dc->npc = dc->npc + 4;
4490 save_state(dc, cpu_cond);
4491 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_ILL_INSN));
4494 #if !defined(CONFIG_USER_ONLY)
4496 save_state(dc, cpu_cond);
4497 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_PRIV_INSN));
4501 save_state(dc, cpu_cond);
4502 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4505 #ifndef TARGET_SPARC64
4507 save_state(dc, cpu_cond);
4508 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4513 #ifndef TARGET_SPARC64
4515 save_state(dc, cpu_cond);
4516 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NCP_INSN));
4522 static void tcg_macro_func(TCGContext *s, int macro_id, const int *dead_args)
4526 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4527 int spc, CPUSPARCState *env)
4529 target_ulong pc_start, last_pc;
4530 uint16_t *gen_opc_end;
4531 DisasContext dc1, *dc = &dc1;
4534 memset(dc, 0, sizeof(DisasContext));
4539 dc->npc = (target_ulong) tb->cs_base;
4540 dc->mem_idx = cpu_mmu_index(env);
4541 dc->fpu_enabled = cpu_fpu_enabled(env);
4542 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4544 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4545 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4546 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4548 cpu_cond = cpu_T[2];
4551 if (env->nb_breakpoints > 0) {
4552 for(j = 0; j < env->nb_breakpoints; j++) {
4553 if (env->breakpoints[j] == dc->pc) {
4554 if (dc->pc != pc_start)
4555 save_state(dc, cpu_cond);
4556 tcg_gen_helper_0_0(helper_debug);
4565 fprintf(logfile, "Search PC...\n");
4566 j = gen_opc_ptr - gen_opc_buf;
4570 gen_opc_instr_start[lj++] = 0;
4571 gen_opc_pc[lj] = dc->pc;
4572 gen_opc_npc[lj] = dc->npc;
4573 gen_opc_instr_start[lj] = 1;
4577 disas_sparc_insn(dc);
4581 /* if the next PC is different, we abort now */
4582 if (dc->pc != (last_pc + 4))
4584 /* if we reach a page boundary, we stop generation so that the
4585 PC of a TT_TFAULT exception is always in the right page */
4586 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4588 /* if single step mode, we generate only one instruction and
4589 generate an exception */
4590 if (env->singlestep_enabled) {
4591 tcg_gen_movi_tl(cpu_pc, dc->pc);
4595 } while ((gen_opc_ptr < gen_opc_end) &&
4596 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
4600 if (dc->pc != DYNAMIC_PC &&
4601 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4602 /* static PC and NPC: we can use direct chaining */
4603 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4605 if (dc->pc != DYNAMIC_PC)
4606 tcg_gen_movi_tl(cpu_pc, dc->pc);
4607 save_npc(dc, cpu_cond);
4611 *gen_opc_ptr = INDEX_op_end;
4613 j = gen_opc_ptr - gen_opc_buf;
4616 gen_opc_instr_start[lj++] = 0;
4622 gen_opc_jump_pc[0] = dc->jump_pc[0];
4623 gen_opc_jump_pc[1] = dc->jump_pc[1];
4625 tb->size = last_pc + 4 - pc_start;
4628 if (loglevel & CPU_LOG_TB_IN_ASM) {
4629 fprintf(logfile, "--------------\n");
4630 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4631 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4632 fprintf(logfile, "\n");
4638 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4640 return gen_intermediate_code_internal(tb, 0, env);
4643 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4645 return gen_intermediate_code_internal(tb, 1, env);
4648 void gen_intermediate_code_init(CPUSPARCState *env)
4652 static const char * const gregnames[8] = {
4653 NULL, // g0 not used
4663 /* init various static tables */
4667 tcg_set_macro_func(&tcg_ctx, tcg_macro_func);
4668 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4669 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4670 offsetof(CPUState, regwptr),
4672 //#if TARGET_LONG_BITS > HOST_LONG_BITS
4673 #ifdef TARGET_SPARC64
4674 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
4675 TCG_AREG0, offsetof(CPUState, t0), "T0");
4676 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
4677 TCG_AREG0, offsetof(CPUState, t1), "T1");
4678 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
4679 TCG_AREG0, offsetof(CPUState, t2), "T2");
4680 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4681 TCG_AREG0, offsetof(CPUState, xcc),
4684 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
4685 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
4686 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
4688 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4689 TCG_AREG0, offsetof(CPUState, cc_src),
4691 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4692 offsetof(CPUState, cc_src2),
4694 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4695 TCG_AREG0, offsetof(CPUState, cc_dst),
4697 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4698 TCG_AREG0, offsetof(CPUState, psr),
4700 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4701 TCG_AREG0, offsetof(CPUState, fsr),
4703 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4704 TCG_AREG0, offsetof(CPUState, pc),
4706 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4707 TCG_AREG0, offsetof(CPUState, npc),
4709 for (i = 1; i < 8; i++)
4710 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4711 offsetof(CPUState, gregs[i]),