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 static inline TCGv get_src1(unsigned int insn, TCGv def)
1825 rs1 = GET_FIELD(insn, 13, 17);
1827 //r_rs1 = tcg_const_tl(0);
1828 tcg_gen_movi_tl(def, 0);
1830 //r_rs1 = cpu_gregs[rs1];
1831 tcg_gen_mov_tl(def, cpu_gregs[rs1]);
1833 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1837 /* before an instruction, dc->pc must be static */
1838 static void disas_sparc_insn(DisasContext * dc)
1840 unsigned int insn, opc, rs1, rs2, rd;
1842 insn = ldl_code(dc->pc);
1843 opc = GET_FIELD(insn, 0, 1);
1845 rd = GET_FIELD(insn, 2, 6);
1848 cpu_src1 = cpu_T[0]; // const
1849 cpu_src2 = cpu_T[1]; // const
1852 cpu_addr = cpu_T[0];
1856 case 0: /* branches/sethi */
1858 unsigned int xop = GET_FIELD(insn, 7, 9);
1861 #ifdef TARGET_SPARC64
1862 case 0x1: /* V9 BPcc */
1866 target = GET_FIELD_SP(insn, 0, 18);
1867 target = sign_extend(target, 18);
1869 cc = GET_FIELD_SP(insn, 20, 21);
1871 do_branch(dc, target, insn, 0, cpu_cond);
1873 do_branch(dc, target, insn, 1, cpu_cond);
1878 case 0x3: /* V9 BPr */
1880 target = GET_FIELD_SP(insn, 0, 13) |
1881 (GET_FIELD_SP(insn, 20, 21) << 14);
1882 target = sign_extend(target, 16);
1884 cpu_src1 = get_src1(insn, cpu_src1);
1885 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1888 case 0x5: /* V9 FBPcc */
1890 int cc = GET_FIELD_SP(insn, 20, 21);
1891 if (gen_trap_ifnofpu(dc, cpu_cond))
1893 target = GET_FIELD_SP(insn, 0, 18);
1894 target = sign_extend(target, 19);
1896 do_fbranch(dc, target, insn, cc, cpu_cond);
1900 case 0x7: /* CBN+x */
1905 case 0x2: /* BN+x */
1907 target = GET_FIELD(insn, 10, 31);
1908 target = sign_extend(target, 22);
1910 do_branch(dc, target, insn, 0, cpu_cond);
1913 case 0x6: /* FBN+x */
1915 if (gen_trap_ifnofpu(dc, cpu_cond))
1917 target = GET_FIELD(insn, 10, 31);
1918 target = sign_extend(target, 22);
1920 do_fbranch(dc, target, insn, 0, cpu_cond);
1923 case 0x4: /* SETHI */
1928 uint32_t value = GET_FIELD(insn, 10, 31);
1929 tcg_gen_movi_tl(cpu_dst, value << 10);
1930 gen_movl_TN_reg(rd, cpu_dst);
1935 case 0x0: /* UNIMPL */
1944 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1946 gen_movl_TN_reg(15, tcg_const_tl(dc->pc));
1948 gen_mov_pc_npc(dc, cpu_cond);
1952 case 2: /* FPU & Logical Operations */
1954 unsigned int xop = GET_FIELD(insn, 7, 12);
1955 if (xop == 0x3a) { /* generate trap */
1958 cpu_src1 = get_src1(insn, cpu_src1);
1960 rs2 = GET_FIELD(insn, 25, 31);
1961 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
1963 rs2 = GET_FIELD(insn, 27, 31);
1967 gen_movl_reg_TN(rs2, cpu_src2);
1968 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
1973 cond = GET_FIELD(insn, 3, 6);
1975 save_state(dc, cpu_cond);
1976 tcg_gen_helper_0_1(helper_trap, cpu_dst);
1977 } else if (cond != 0) {
1978 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
1979 #ifdef TARGET_SPARC64
1981 int cc = GET_FIELD_SP(insn, 11, 12);
1983 save_state(dc, cpu_cond);
1985 gen_cond(r_cond, 0, cond);
1987 gen_cond(r_cond, 1, cond);
1991 save_state(dc, cpu_cond);
1992 gen_cond(r_cond, 0, cond);
1994 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
1995 tcg_gen_discard_tl(r_cond);
2001 } else if (xop == 0x28) {
2002 rs1 = GET_FIELD(insn, 13, 17);
2005 #ifndef TARGET_SPARC64
2006 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2007 manual, rdy on the microSPARC
2009 case 0x0f: /* stbar in the SPARCv8 manual,
2010 rdy on the microSPARC II */
2011 case 0x10 ... 0x1f: /* implementation-dependent in the
2012 SPARCv8 manual, rdy on the
2015 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
2016 gen_movl_TN_reg(rd, cpu_dst);
2018 #ifdef TARGET_SPARC64
2019 case 0x2: /* V9 rdccr */
2020 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2021 gen_movl_TN_reg(rd, cpu_dst);
2023 case 0x3: /* V9 rdasi */
2024 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
2025 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2026 gen_movl_TN_reg(rd, cpu_dst);
2028 case 0x4: /* V9 rdtick */
2032 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2033 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2034 offsetof(CPUState, tick));
2035 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2037 gen_movl_TN_reg(rd, cpu_dst);
2038 tcg_gen_discard_ptr(r_tickptr);
2041 case 0x5: /* V9 rdpc */
2042 tcg_gen_movi_tl(cpu_dst, dc->pc);
2043 gen_movl_TN_reg(rd, cpu_dst);
2045 case 0x6: /* V9 rdfprs */
2046 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
2047 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2048 gen_movl_TN_reg(rd, cpu_dst);
2050 case 0xf: /* V9 membar */
2051 break; /* no effect */
2052 case 0x13: /* Graphics Status */
2053 if (gen_trap_ifnofpu(dc, cpu_cond))
2055 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
2056 gen_movl_TN_reg(rd, cpu_dst);
2058 case 0x17: /* Tick compare */
2059 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tick_cmpr));
2060 gen_movl_TN_reg(rd, cpu_dst);
2062 case 0x18: /* System tick */
2066 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2067 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2068 offsetof(CPUState, stick));
2069 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2071 gen_movl_TN_reg(rd, cpu_dst);
2072 tcg_gen_discard_ptr(r_tickptr);
2075 case 0x19: /* System tick compare */
2076 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, stick_cmpr));
2077 gen_movl_TN_reg(rd, cpu_dst);
2079 case 0x10: /* Performance Control */
2080 case 0x11: /* Performance Instrumentation Counter */
2081 case 0x12: /* Dispatch Control */
2082 case 0x14: /* Softint set, WO */
2083 case 0x15: /* Softint clear, WO */
2084 case 0x16: /* Softint write */
2089 #if !defined(CONFIG_USER_ONLY)
2090 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2091 #ifndef TARGET_SPARC64
2092 if (!supervisor(dc))
2094 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2096 if (!hypervisor(dc))
2098 rs1 = GET_FIELD(insn, 13, 17);
2101 // gen_op_rdhpstate();
2104 // gen_op_rdhtstate();
2107 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
2108 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2111 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
2112 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2115 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hver));
2116 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2118 case 31: // hstick_cmpr
2119 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2120 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hstick_cmpr));
2126 gen_movl_TN_reg(rd, cpu_dst);
2128 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2129 if (!supervisor(dc))
2131 #ifdef TARGET_SPARC64
2132 rs1 = GET_FIELD(insn, 13, 17);
2138 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2139 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2140 offsetof(CPUState, tsptr));
2141 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2142 offsetof(trap_state, tpc));
2143 tcg_gen_discard_ptr(r_tsptr);
2150 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2151 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2152 offsetof(CPUState, tsptr));
2153 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2154 offsetof(trap_state, tnpc));
2155 tcg_gen_discard_ptr(r_tsptr);
2162 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2163 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2164 offsetof(CPUState, tsptr));
2165 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2166 offsetof(trap_state, tstate));
2167 tcg_gen_discard_ptr(r_tsptr);
2174 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2175 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2176 offsetof(CPUState, tsptr));
2177 tcg_gen_ld_i32(cpu_dst, r_tsptr,
2178 offsetof(trap_state, tt));
2179 tcg_gen_discard_ptr(r_tsptr);
2186 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2187 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2188 offsetof(CPUState, tick));
2189 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2191 gen_movl_TN_reg(rd, cpu_dst);
2192 tcg_gen_discard_ptr(r_tickptr);
2196 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2199 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, pstate));
2200 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2203 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
2204 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2207 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
2208 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2211 tcg_gen_helper_1_0(helper_rdcwp, cpu_dst);
2214 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
2215 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2217 case 11: // canrestore
2218 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
2219 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2221 case 12: // cleanwin
2222 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
2223 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2225 case 13: // otherwin
2226 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
2227 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2230 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
2231 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2233 case 16: // UA2005 gl
2234 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
2235 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2237 case 26: // UA2005 strand status
2238 if (!hypervisor(dc))
2240 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
2241 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2244 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, version));
2251 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
2252 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2254 gen_movl_TN_reg(rd, cpu_dst);
2256 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2257 #ifdef TARGET_SPARC64
2258 tcg_gen_helper_0_0(helper_flushw);
2260 if (!supervisor(dc))
2262 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2263 gen_movl_TN_reg(rd, cpu_dst);
2267 } else if (xop == 0x34) { /* FPU Operations */
2268 if (gen_trap_ifnofpu(dc, cpu_cond))
2270 gen_op_clear_ieee_excp_and_FTT();
2271 rs1 = GET_FIELD(insn, 13, 17);
2272 rs2 = GET_FIELD(insn, 27, 31);
2273 xop = GET_FIELD(insn, 18, 26);
2275 case 0x1: /* fmovs */
2276 gen_op_load_fpr_FT0(rs2);
2277 gen_op_store_FT0_fpr(rd);
2279 case 0x5: /* fnegs */
2280 gen_op_load_fpr_FT1(rs2);
2281 tcg_gen_helper_0_0(helper_fnegs);
2282 gen_op_store_FT0_fpr(rd);
2284 case 0x9: /* fabss */
2285 gen_op_load_fpr_FT1(rs2);
2286 tcg_gen_helper_0_0(helper_fabss);
2287 gen_op_store_FT0_fpr(rd);
2289 case 0x29: /* fsqrts */
2290 gen_op_load_fpr_FT1(rs2);
2291 gen_clear_float_exceptions();
2292 tcg_gen_helper_0_0(helper_fsqrts);
2293 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2294 gen_op_store_FT0_fpr(rd);
2296 case 0x2a: /* fsqrtd */
2297 gen_op_load_fpr_DT1(DFPREG(rs2));
2298 gen_clear_float_exceptions();
2299 tcg_gen_helper_0_0(helper_fsqrtd);
2300 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2301 gen_op_store_DT0_fpr(DFPREG(rd));
2303 case 0x2b: /* fsqrtq */
2304 #if defined(CONFIG_USER_ONLY)
2305 gen_op_load_fpr_QT1(QFPREG(rs2));
2306 gen_clear_float_exceptions();
2307 tcg_gen_helper_0_0(helper_fsqrtq);
2308 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2309 gen_op_store_QT0_fpr(QFPREG(rd));
2315 gen_op_load_fpr_FT0(rs1);
2316 gen_op_load_fpr_FT1(rs2);
2317 gen_clear_float_exceptions();
2318 tcg_gen_helper_0_0(helper_fadds);
2319 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2320 gen_op_store_FT0_fpr(rd);
2323 gen_op_load_fpr_DT0(DFPREG(rs1));
2324 gen_op_load_fpr_DT1(DFPREG(rs2));
2325 gen_clear_float_exceptions();
2326 tcg_gen_helper_0_0(helper_faddd);
2327 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2328 gen_op_store_DT0_fpr(DFPREG(rd));
2330 case 0x43: /* faddq */
2331 #if defined(CONFIG_USER_ONLY)
2332 gen_op_load_fpr_QT0(QFPREG(rs1));
2333 gen_op_load_fpr_QT1(QFPREG(rs2));
2334 gen_clear_float_exceptions();
2335 tcg_gen_helper_0_0(helper_faddq);
2336 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2337 gen_op_store_QT0_fpr(QFPREG(rd));
2343 gen_op_load_fpr_FT0(rs1);
2344 gen_op_load_fpr_FT1(rs2);
2345 gen_clear_float_exceptions();
2346 tcg_gen_helper_0_0(helper_fsubs);
2347 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2348 gen_op_store_FT0_fpr(rd);
2351 gen_op_load_fpr_DT0(DFPREG(rs1));
2352 gen_op_load_fpr_DT1(DFPREG(rs2));
2353 gen_clear_float_exceptions();
2354 tcg_gen_helper_0_0(helper_fsubd);
2355 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2356 gen_op_store_DT0_fpr(DFPREG(rd));
2358 case 0x47: /* fsubq */
2359 #if defined(CONFIG_USER_ONLY)
2360 gen_op_load_fpr_QT0(QFPREG(rs1));
2361 gen_op_load_fpr_QT1(QFPREG(rs2));
2362 gen_clear_float_exceptions();
2363 tcg_gen_helper_0_0(helper_fsubq);
2364 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2365 gen_op_store_QT0_fpr(QFPREG(rd));
2371 gen_op_load_fpr_FT0(rs1);
2372 gen_op_load_fpr_FT1(rs2);
2373 gen_clear_float_exceptions();
2374 tcg_gen_helper_0_0(helper_fmuls);
2375 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2376 gen_op_store_FT0_fpr(rd);
2379 gen_op_load_fpr_DT0(DFPREG(rs1));
2380 gen_op_load_fpr_DT1(DFPREG(rs2));
2381 gen_clear_float_exceptions();
2382 tcg_gen_helper_0_0(helper_fmuld);
2383 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2384 gen_op_store_DT0_fpr(DFPREG(rd));
2386 case 0x4b: /* fmulq */
2387 #if defined(CONFIG_USER_ONLY)
2388 gen_op_load_fpr_QT0(QFPREG(rs1));
2389 gen_op_load_fpr_QT1(QFPREG(rs2));
2390 gen_clear_float_exceptions();
2391 tcg_gen_helper_0_0(helper_fmulq);
2392 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2393 gen_op_store_QT0_fpr(QFPREG(rd));
2399 gen_op_load_fpr_FT0(rs1);
2400 gen_op_load_fpr_FT1(rs2);
2401 gen_clear_float_exceptions();
2402 tcg_gen_helper_0_0(helper_fdivs);
2403 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2404 gen_op_store_FT0_fpr(rd);
2407 gen_op_load_fpr_DT0(DFPREG(rs1));
2408 gen_op_load_fpr_DT1(DFPREG(rs2));
2409 gen_clear_float_exceptions();
2410 tcg_gen_helper_0_0(helper_fdivd);
2411 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2412 gen_op_store_DT0_fpr(DFPREG(rd));
2414 case 0x4f: /* fdivq */
2415 #if defined(CONFIG_USER_ONLY)
2416 gen_op_load_fpr_QT0(QFPREG(rs1));
2417 gen_op_load_fpr_QT1(QFPREG(rs2));
2418 gen_clear_float_exceptions();
2419 tcg_gen_helper_0_0(helper_fdivq);
2420 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2421 gen_op_store_QT0_fpr(QFPREG(rd));
2427 gen_op_load_fpr_FT0(rs1);
2428 gen_op_load_fpr_FT1(rs2);
2429 gen_clear_float_exceptions();
2430 tcg_gen_helper_0_0(helper_fsmuld);
2431 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2432 gen_op_store_DT0_fpr(DFPREG(rd));
2434 case 0x6e: /* fdmulq */
2435 #if defined(CONFIG_USER_ONLY)
2436 gen_op_load_fpr_DT0(DFPREG(rs1));
2437 gen_op_load_fpr_DT1(DFPREG(rs2));
2438 gen_clear_float_exceptions();
2439 tcg_gen_helper_0_0(helper_fdmulq);
2440 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2441 gen_op_store_QT0_fpr(QFPREG(rd));
2447 gen_op_load_fpr_FT1(rs2);
2448 gen_clear_float_exceptions();
2449 tcg_gen_helper_0_0(helper_fitos);
2450 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2451 gen_op_store_FT0_fpr(rd);
2454 gen_op_load_fpr_DT1(DFPREG(rs2));
2455 gen_clear_float_exceptions();
2456 tcg_gen_helper_0_0(helper_fdtos);
2457 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2458 gen_op_store_FT0_fpr(rd);
2460 case 0xc7: /* fqtos */
2461 #if defined(CONFIG_USER_ONLY)
2462 gen_op_load_fpr_QT1(QFPREG(rs2));
2463 gen_clear_float_exceptions();
2464 tcg_gen_helper_0_0(helper_fqtos);
2465 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2466 gen_op_store_FT0_fpr(rd);
2472 gen_op_load_fpr_FT1(rs2);
2473 tcg_gen_helper_0_0(helper_fitod);
2474 gen_op_store_DT0_fpr(DFPREG(rd));
2477 gen_op_load_fpr_FT1(rs2);
2478 tcg_gen_helper_0_0(helper_fstod);
2479 gen_op_store_DT0_fpr(DFPREG(rd));
2481 case 0xcb: /* fqtod */
2482 #if defined(CONFIG_USER_ONLY)
2483 gen_op_load_fpr_QT1(QFPREG(rs2));
2484 gen_clear_float_exceptions();
2485 tcg_gen_helper_0_0(helper_fqtod);
2486 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2487 gen_op_store_DT0_fpr(DFPREG(rd));
2492 case 0xcc: /* fitoq */
2493 #if defined(CONFIG_USER_ONLY)
2494 gen_op_load_fpr_FT1(rs2);
2495 tcg_gen_helper_0_0(helper_fitoq);
2496 gen_op_store_QT0_fpr(QFPREG(rd));
2501 case 0xcd: /* fstoq */
2502 #if defined(CONFIG_USER_ONLY)
2503 gen_op_load_fpr_FT1(rs2);
2504 tcg_gen_helper_0_0(helper_fstoq);
2505 gen_op_store_QT0_fpr(QFPREG(rd));
2510 case 0xce: /* fdtoq */
2511 #if defined(CONFIG_USER_ONLY)
2512 gen_op_load_fpr_DT1(DFPREG(rs2));
2513 tcg_gen_helper_0_0(helper_fdtoq);
2514 gen_op_store_QT0_fpr(QFPREG(rd));
2520 gen_op_load_fpr_FT1(rs2);
2521 gen_clear_float_exceptions();
2522 tcg_gen_helper_0_0(helper_fstoi);
2523 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2524 gen_op_store_FT0_fpr(rd);
2527 gen_op_load_fpr_DT1(DFPREG(rs2));
2528 gen_clear_float_exceptions();
2529 tcg_gen_helper_0_0(helper_fdtoi);
2530 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2531 gen_op_store_FT0_fpr(rd);
2533 case 0xd3: /* fqtoi */
2534 #if defined(CONFIG_USER_ONLY)
2535 gen_op_load_fpr_QT1(QFPREG(rs2));
2536 gen_clear_float_exceptions();
2537 tcg_gen_helper_0_0(helper_fqtoi);
2538 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2539 gen_op_store_FT0_fpr(rd);
2544 #ifdef TARGET_SPARC64
2545 case 0x2: /* V9 fmovd */
2546 gen_op_load_fpr_DT0(DFPREG(rs2));
2547 gen_op_store_DT0_fpr(DFPREG(rd));
2549 case 0x3: /* V9 fmovq */
2550 #if defined(CONFIG_USER_ONLY)
2551 gen_op_load_fpr_QT0(QFPREG(rs2));
2552 gen_op_store_QT0_fpr(QFPREG(rd));
2557 case 0x6: /* V9 fnegd */
2558 gen_op_load_fpr_DT1(DFPREG(rs2));
2559 tcg_gen_helper_0_0(helper_fnegd);
2560 gen_op_store_DT0_fpr(DFPREG(rd));
2562 case 0x7: /* V9 fnegq */
2563 #if defined(CONFIG_USER_ONLY)
2564 gen_op_load_fpr_QT1(QFPREG(rs2));
2565 tcg_gen_helper_0_0(helper_fnegq);
2566 gen_op_store_QT0_fpr(QFPREG(rd));
2571 case 0xa: /* V9 fabsd */
2572 gen_op_load_fpr_DT1(DFPREG(rs2));
2573 tcg_gen_helper_0_0(helper_fabsd);
2574 gen_op_store_DT0_fpr(DFPREG(rd));
2576 case 0xb: /* V9 fabsq */
2577 #if defined(CONFIG_USER_ONLY)
2578 gen_op_load_fpr_QT1(QFPREG(rs2));
2579 tcg_gen_helper_0_0(helper_fabsq);
2580 gen_op_store_QT0_fpr(QFPREG(rd));
2585 case 0x81: /* V9 fstox */
2586 gen_op_load_fpr_FT1(rs2);
2587 gen_clear_float_exceptions();
2588 tcg_gen_helper_0_0(helper_fstox);
2589 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2590 gen_op_store_DT0_fpr(DFPREG(rd));
2592 case 0x82: /* V9 fdtox */
2593 gen_op_load_fpr_DT1(DFPREG(rs2));
2594 gen_clear_float_exceptions();
2595 tcg_gen_helper_0_0(helper_fdtox);
2596 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2597 gen_op_store_DT0_fpr(DFPREG(rd));
2599 case 0x83: /* V9 fqtox */
2600 #if defined(CONFIG_USER_ONLY)
2601 gen_op_load_fpr_QT1(QFPREG(rs2));
2602 gen_clear_float_exceptions();
2603 tcg_gen_helper_0_0(helper_fqtox);
2604 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2605 gen_op_store_DT0_fpr(DFPREG(rd));
2610 case 0x84: /* V9 fxtos */
2611 gen_op_load_fpr_DT1(DFPREG(rs2));
2612 gen_clear_float_exceptions();
2613 tcg_gen_helper_0_0(helper_fxtos);
2614 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2615 gen_op_store_FT0_fpr(rd);
2617 case 0x88: /* V9 fxtod */
2618 gen_op_load_fpr_DT1(DFPREG(rs2));
2619 gen_clear_float_exceptions();
2620 tcg_gen_helper_0_0(helper_fxtod);
2621 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2622 gen_op_store_DT0_fpr(DFPREG(rd));
2624 case 0x8c: /* V9 fxtoq */
2625 #if defined(CONFIG_USER_ONLY)
2626 gen_op_load_fpr_DT1(DFPREG(rs2));
2627 gen_clear_float_exceptions();
2628 tcg_gen_helper_0_0(helper_fxtoq);
2629 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2630 gen_op_store_QT0_fpr(QFPREG(rd));
2639 } else if (xop == 0x35) { /* FPU Operations */
2640 #ifdef TARGET_SPARC64
2643 if (gen_trap_ifnofpu(dc, cpu_cond))
2645 gen_op_clear_ieee_excp_and_FTT();
2646 rs1 = GET_FIELD(insn, 13, 17);
2647 rs2 = GET_FIELD(insn, 27, 31);
2648 xop = GET_FIELD(insn, 18, 26);
2649 #ifdef TARGET_SPARC64
2650 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2653 l1 = gen_new_label();
2654 cond = GET_FIELD_SP(insn, 14, 17);
2655 cpu_src1 = get_src1(insn, cpu_src1);
2656 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2657 tcg_const_tl(0), l1);
2658 gen_op_load_fpr_FT0(rs2);
2659 gen_op_store_FT0_fpr(rd);
2662 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2665 l1 = gen_new_label();
2666 cond = GET_FIELD_SP(insn, 14, 17);
2667 cpu_src1 = get_src1(insn, cpu_src1);
2668 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2669 tcg_const_tl(0), l1);
2670 gen_op_load_fpr_DT0(DFPREG(rs2));
2671 gen_op_store_DT0_fpr(DFPREG(rd));
2674 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2675 #if defined(CONFIG_USER_ONLY)
2678 l1 = gen_new_label();
2679 cond = GET_FIELD_SP(insn, 14, 17);
2680 cpu_src1 = get_src1(insn, cpu_src1);
2681 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
2682 tcg_const_tl(0), l1);
2683 gen_op_load_fpr_QT0(QFPREG(rs2));
2684 gen_op_store_QT0_fpr(QFPREG(rd));
2693 #ifdef TARGET_SPARC64
2694 #define FMOVCC(size_FDQ, fcc) \
2699 l1 = gen_new_label(); \
2700 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2701 cond = GET_FIELD_SP(insn, 14, 17); \
2702 gen_fcond(r_cond, fcc, cond); \
2703 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2704 tcg_const_tl(0), l1); \
2705 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2706 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2707 gen_set_label(l1); \
2708 tcg_gen_discard_tl(r_cond); \
2710 case 0x001: /* V9 fmovscc %fcc0 */
2713 case 0x002: /* V9 fmovdcc %fcc0 */
2716 case 0x003: /* V9 fmovqcc %fcc0 */
2717 #if defined(CONFIG_USER_ONLY)
2723 case 0x041: /* V9 fmovscc %fcc1 */
2726 case 0x042: /* V9 fmovdcc %fcc1 */
2729 case 0x043: /* V9 fmovqcc %fcc1 */
2730 #if defined(CONFIG_USER_ONLY)
2736 case 0x081: /* V9 fmovscc %fcc2 */
2739 case 0x082: /* V9 fmovdcc %fcc2 */
2742 case 0x083: /* V9 fmovqcc %fcc2 */
2743 #if defined(CONFIG_USER_ONLY)
2749 case 0x0c1: /* V9 fmovscc %fcc3 */
2752 case 0x0c2: /* V9 fmovdcc %fcc3 */
2755 case 0x0c3: /* V9 fmovqcc %fcc3 */
2756 #if defined(CONFIG_USER_ONLY)
2763 #define FMOVCC(size_FDQ, icc) \
2768 l1 = gen_new_label(); \
2769 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2770 cond = GET_FIELD_SP(insn, 14, 17); \
2771 gen_cond(r_cond, icc, cond); \
2772 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2773 tcg_const_tl(0), l1); \
2774 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2775 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2776 gen_set_label(l1); \
2777 tcg_gen_discard_tl(r_cond); \
2780 case 0x101: /* V9 fmovscc %icc */
2783 case 0x102: /* V9 fmovdcc %icc */
2785 case 0x103: /* V9 fmovqcc %icc */
2786 #if defined(CONFIG_USER_ONLY)
2792 case 0x181: /* V9 fmovscc %xcc */
2795 case 0x182: /* V9 fmovdcc %xcc */
2798 case 0x183: /* V9 fmovqcc %xcc */
2799 #if defined(CONFIG_USER_ONLY)
2807 case 0x51: /* fcmps, V9 %fcc */
2808 gen_op_load_fpr_FT0(rs1);
2809 gen_op_load_fpr_FT1(rs2);
2810 gen_op_fcmps(rd & 3);
2812 case 0x52: /* fcmpd, V9 %fcc */
2813 gen_op_load_fpr_DT0(DFPREG(rs1));
2814 gen_op_load_fpr_DT1(DFPREG(rs2));
2815 gen_op_fcmpd(rd & 3);
2817 case 0x53: /* fcmpq, V9 %fcc */
2818 #if defined(CONFIG_USER_ONLY)
2819 gen_op_load_fpr_QT0(QFPREG(rs1));
2820 gen_op_load_fpr_QT1(QFPREG(rs2));
2821 gen_op_fcmpq(rd & 3);
2823 #else /* !defined(CONFIG_USER_ONLY) */
2826 case 0x55: /* fcmpes, V9 %fcc */
2827 gen_op_load_fpr_FT0(rs1);
2828 gen_op_load_fpr_FT1(rs2);
2829 gen_op_fcmpes(rd & 3);
2831 case 0x56: /* fcmped, V9 %fcc */
2832 gen_op_load_fpr_DT0(DFPREG(rs1));
2833 gen_op_load_fpr_DT1(DFPREG(rs2));
2834 gen_op_fcmped(rd & 3);
2836 case 0x57: /* fcmpeq, V9 %fcc */
2837 #if defined(CONFIG_USER_ONLY)
2838 gen_op_load_fpr_QT0(QFPREG(rs1));
2839 gen_op_load_fpr_QT1(QFPREG(rs2));
2840 gen_op_fcmpeq(rd & 3);
2842 #else/* !defined(CONFIG_USER_ONLY) */
2849 } else if (xop == 0x2) {
2852 rs1 = GET_FIELD(insn, 13, 17);
2854 // or %g0, x, y -> mov T0, x; mov y, T0
2855 if (IS_IMM) { /* immediate */
2856 rs2 = GET_FIELDs(insn, 19, 31);
2857 tcg_gen_movi_tl(cpu_dst, (int)rs2);
2858 } else { /* register */
2859 rs2 = GET_FIELD(insn, 27, 31);
2860 gen_movl_reg_TN(rs2, cpu_dst);
2863 cpu_src1 = get_src1(insn, cpu_src1);
2864 if (IS_IMM) { /* immediate */
2865 rs2 = GET_FIELDs(insn, 19, 31);
2866 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2867 } else { /* register */
2868 // or x, %g0, y -> mov T1, x; mov y, T1
2869 rs2 = GET_FIELD(insn, 27, 31);
2871 gen_movl_reg_TN(rs2, cpu_src2);
2872 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2876 gen_movl_TN_reg(rd, cpu_dst);
2878 #ifdef TARGET_SPARC64
2879 } else if (xop == 0x25) { /* sll, V9 sllx */
2880 cpu_src1 = get_src1(insn, cpu_src1);
2881 if (IS_IMM) { /* immediate */
2882 rs2 = GET_FIELDs(insn, 20, 31);
2883 if (insn & (1 << 12)) {
2884 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2886 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2887 tcg_gen_shli_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2889 } else { /* register */
2890 rs2 = GET_FIELD(insn, 27, 31);
2891 gen_movl_reg_TN(rs2, cpu_src2);
2892 if (insn & (1 << 12)) {
2893 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2894 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2896 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2897 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2898 tcg_gen_shl_i64(cpu_dst, cpu_dst, cpu_tmp0);
2901 gen_movl_TN_reg(rd, cpu_dst);
2902 } else if (xop == 0x26) { /* srl, V9 srlx */
2903 cpu_src1 = get_src1(insn, cpu_src1);
2904 if (IS_IMM) { /* immediate */
2905 rs2 = GET_FIELDs(insn, 20, 31);
2906 if (insn & (1 << 12)) {
2907 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2909 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2910 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2912 } else { /* register */
2913 rs2 = GET_FIELD(insn, 27, 31);
2914 gen_movl_reg_TN(rs2, cpu_src2);
2915 if (insn & (1 << 12)) {
2916 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2917 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2919 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2920 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2921 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2924 gen_movl_TN_reg(rd, cpu_dst);
2925 } else if (xop == 0x27) { /* sra, V9 srax */
2926 cpu_src1 = get_src1(insn, cpu_src1);
2927 if (IS_IMM) { /* immediate */
2928 rs2 = GET_FIELDs(insn, 20, 31);
2929 if (insn & (1 << 12)) {
2930 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2932 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2933 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2934 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2936 } else { /* register */
2937 rs2 = GET_FIELD(insn, 27, 31);
2938 gen_movl_reg_TN(rs2, cpu_src2);
2939 if (insn & (1 << 12)) {
2940 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2941 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2943 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2944 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2945 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2948 gen_movl_TN_reg(rd, cpu_dst);
2950 } else if (xop < 0x36) {
2951 cpu_src1 = get_src1(insn, cpu_src1);
2952 if (IS_IMM) { /* immediate */
2953 rs2 = GET_FIELDs(insn, 19, 31);
2954 tcg_gen_movi_tl(cpu_src2, (int)rs2);
2955 } else { /* register */
2956 rs2 = GET_FIELD(insn, 27, 31);
2957 gen_movl_reg_TN(rs2, cpu_src2);
2960 switch (xop & ~0x10) {
2963 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2965 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2968 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
2970 gen_op_logic_cc(cpu_dst);
2973 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2975 gen_op_logic_cc(cpu_dst);
2978 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
2980 gen_op_logic_cc(cpu_dst);
2984 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
2986 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
2989 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2990 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
2992 gen_op_logic_cc(cpu_dst);
2995 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2996 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
2998 gen_op_logic_cc(cpu_dst);
3001 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3002 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
3004 gen_op_logic_cc(cpu_dst);
3008 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3010 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3011 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3012 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3015 #ifdef TARGET_SPARC64
3016 case 0x9: /* V9 mulx */
3017 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3021 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3023 gen_op_logic_cc(cpu_dst);
3026 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3028 gen_op_logic_cc(cpu_dst);
3032 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3034 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3035 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3036 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3039 #ifdef TARGET_SPARC64
3040 case 0xd: /* V9 udivx */
3041 gen_trap_ifdivzero_tl(cpu_src2);
3042 tcg_gen_divu_i64(cpu_dst, cpu_src1, cpu_src2);
3046 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1, cpu_src2);
3048 gen_op_div_cc(cpu_dst);
3051 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1, cpu_src2);
3053 gen_op_div_cc(cpu_dst);
3058 gen_movl_TN_reg(rd, cpu_dst);
3061 case 0x20: /* taddcc */
3062 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3063 gen_movl_TN_reg(rd, cpu_dst);
3065 case 0x21: /* tsubcc */
3066 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3067 gen_movl_TN_reg(rd, cpu_dst);
3069 case 0x22: /* taddcctv */
3070 save_state(dc, cpu_cond);
3071 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3072 gen_movl_TN_reg(rd, cpu_dst);
3074 case 0x23: /* tsubcctv */
3075 save_state(dc, cpu_cond);
3076 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3077 gen_movl_TN_reg(rd, cpu_dst);
3079 case 0x24: /* mulscc */
3080 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3081 gen_movl_TN_reg(rd, cpu_dst);
3083 #ifndef TARGET_SPARC64
3084 case 0x25: /* sll */
3085 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3086 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3087 gen_movl_TN_reg(rd, cpu_dst);
3089 case 0x26: /* srl */
3090 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3091 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3092 gen_movl_TN_reg(rd, cpu_dst);
3094 case 0x27: /* sra */
3095 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3096 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3097 gen_movl_TN_reg(rd, cpu_dst);
3104 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3105 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, y));
3107 #ifndef TARGET_SPARC64
3108 case 0x01 ... 0x0f: /* undefined in the
3112 case 0x10 ... 0x1f: /* implementation-dependent
3118 case 0x2: /* V9 wrccr */
3119 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3120 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3122 case 0x3: /* V9 wrasi */
3123 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3124 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3125 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
3127 case 0x6: /* V9 wrfprs */
3128 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3129 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3130 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
3131 save_state(dc, cpu_cond);
3136 case 0xf: /* V9 sir, nop if user */
3137 #if !defined(CONFIG_USER_ONLY)
3142 case 0x13: /* Graphics Status */
3143 if (gen_trap_ifnofpu(dc, cpu_cond))
3145 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3146 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, gsr));
3148 case 0x17: /* Tick compare */
3149 #if !defined(CONFIG_USER_ONLY)
3150 if (!supervisor(dc))
3156 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3158 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3160 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3161 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3162 offsetof(CPUState, tick));
3163 tcg_gen_helper_0_2(helper_tick_set_limit,
3164 r_tickptr, cpu_dst);
3165 tcg_gen_discard_ptr(r_tickptr);
3168 case 0x18: /* System tick */
3169 #if !defined(CONFIG_USER_ONLY)
3170 if (!supervisor(dc))
3176 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3178 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3179 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3180 offsetof(CPUState, stick));
3181 tcg_gen_helper_0_2(helper_tick_set_count,
3182 r_tickptr, cpu_dst);
3183 tcg_gen_discard_ptr(r_tickptr);
3186 case 0x19: /* System tick compare */
3187 #if !defined(CONFIG_USER_ONLY)
3188 if (!supervisor(dc))
3194 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3196 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3198 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3199 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3200 offsetof(CPUState, stick));
3201 tcg_gen_helper_0_2(helper_tick_set_limit,
3202 r_tickptr, cpu_dst);
3203 tcg_gen_discard_ptr(r_tickptr);
3207 case 0x10: /* Performance Control */
3208 case 0x11: /* Performance Instrumentation Counter */
3209 case 0x12: /* Dispatch Control */
3210 case 0x14: /* Softint set */
3211 case 0x15: /* Softint clear */
3212 case 0x16: /* Softint write */
3219 #if !defined(CONFIG_USER_ONLY)
3220 case 0x31: /* wrpsr, V9 saved, restored */
3222 if (!supervisor(dc))
3224 #ifdef TARGET_SPARC64
3227 tcg_gen_helper_0_0(helper_saved);
3230 tcg_gen_helper_0_0(helper_restored);
3232 case 2: /* UA2005 allclean */
3233 case 3: /* UA2005 otherw */
3234 case 4: /* UA2005 normalw */
3235 case 5: /* UA2005 invalw */
3241 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3242 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3243 save_state(dc, cpu_cond);
3250 case 0x32: /* wrwim, V9 wrpr */
3252 if (!supervisor(dc))
3254 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3255 #ifdef TARGET_SPARC64
3261 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3262 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3263 offsetof(CPUState, tsptr));
3264 tcg_gen_st_tl(cpu_dst, r_tsptr,
3265 offsetof(trap_state, tpc));
3266 tcg_gen_discard_ptr(r_tsptr);
3273 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3274 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3275 offsetof(CPUState, tsptr));
3276 tcg_gen_st_tl(cpu_dst, r_tsptr,
3277 offsetof(trap_state, tnpc));
3278 tcg_gen_discard_ptr(r_tsptr);
3285 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3286 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3287 offsetof(CPUState, tsptr));
3288 tcg_gen_st_tl(cpu_dst, r_tsptr,
3289 offsetof(trap_state, tstate));
3290 tcg_gen_discard_ptr(r_tsptr);
3297 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3298 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3299 offsetof(CPUState, tsptr));
3300 tcg_gen_st_i32(cpu_dst, r_tsptr,
3301 offsetof(trap_state, tt));
3302 tcg_gen_discard_ptr(r_tsptr);
3309 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3310 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3311 offsetof(CPUState, tick));
3312 tcg_gen_helper_0_2(helper_tick_set_count,
3313 r_tickptr, cpu_dst);
3314 tcg_gen_discard_ptr(r_tickptr);
3318 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
3321 save_state(dc, cpu_cond);
3322 tcg_gen_helper_0_1(helper_wrpstate, cpu_dst);
3328 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3329 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
3332 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3333 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
3336 tcg_gen_helper_0_1(helper_wrcwp, cpu_dst);
3339 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3340 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
3342 case 11: // canrestore
3343 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3344 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
3346 case 12: // cleanwin
3347 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3348 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
3350 case 13: // otherwin
3351 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3352 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
3355 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3356 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
3358 case 16: // UA2005 gl
3359 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3360 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
3362 case 26: // UA2005 strand status
3363 if (!hypervisor(dc))
3365 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3366 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
3372 tcg_gen_andi_tl(cpu_dst, cpu_dst, ((1 << NWINDOWS) - 1));
3373 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3374 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
3378 case 0x33: /* wrtbr, UA2005 wrhpr */
3380 #ifndef TARGET_SPARC64
3381 if (!supervisor(dc))
3383 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3384 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
3386 if (!hypervisor(dc))
3388 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3391 // XXX gen_op_wrhpstate();
3392 save_state(dc, cpu_cond);
3398 // XXX gen_op_wrhtstate();
3401 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3402 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
3405 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3406 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
3408 case 31: // hstick_cmpr
3412 tcg_gen_st_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState,
3414 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3415 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3416 offsetof(CPUState, hstick));
3417 tcg_gen_helper_0_2(helper_tick_set_limit,
3418 r_tickptr, cpu_dst);
3419 tcg_gen_discard_ptr(r_tickptr);
3422 case 6: // hver readonly
3430 #ifdef TARGET_SPARC64
3431 case 0x2c: /* V9 movcc */
3433 int cc = GET_FIELD_SP(insn, 11, 12);
3434 int cond = GET_FIELD_SP(insn, 14, 17);
3438 r_cond = tcg_temp_new(TCG_TYPE_TL);
3439 if (insn & (1 << 18)) {
3441 gen_cond(r_cond, 0, cond);
3443 gen_cond(r_cond, 1, cond);
3447 gen_fcond(r_cond, cc, cond);
3450 l1 = gen_new_label();
3452 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond,
3453 tcg_const_tl(0), l1);
3454 if (IS_IMM) { /* immediate */
3455 rs2 = GET_FIELD_SPs(insn, 0, 10);
3456 tcg_gen_movi_tl(cpu_dst, (int)rs2);
3458 rs2 = GET_FIELD_SP(insn, 0, 4);
3459 gen_movl_reg_TN(rs2, cpu_dst);
3461 gen_movl_TN_reg(rd, cpu_dst);
3463 tcg_gen_discard_tl(r_cond);
3466 case 0x2d: /* V9 sdivx */
3467 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3468 gen_movl_TN_reg(rd, cpu_dst);
3470 case 0x2e: /* V9 popc */
3472 if (IS_IMM) { /* immediate */
3473 rs2 = GET_FIELD_SPs(insn, 0, 12);
3474 tcg_gen_movi_tl(cpu_src2, (int)rs2);
3475 // XXX optimize: popc(constant)
3478 rs2 = GET_FIELD_SP(insn, 0, 4);
3479 gen_movl_reg_TN(rs2, cpu_src2);
3481 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3483 gen_movl_TN_reg(rd, cpu_dst);
3485 case 0x2f: /* V9 movr */
3487 int cond = GET_FIELD_SP(insn, 10, 12);
3490 cpu_src1 = get_src1(insn, cpu_src1);
3492 l1 = gen_new_label();
3494 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_src1,
3495 tcg_const_tl(0), l1);
3496 if (IS_IMM) { /* immediate */
3497 rs2 = GET_FIELD_SPs(insn, 0, 9);
3498 tcg_gen_movi_tl(cpu_dst, (int)rs2);
3500 rs2 = GET_FIELD_SP(insn, 0, 4);
3501 gen_movl_reg_TN(rs2, cpu_dst);
3503 gen_movl_TN_reg(rd, cpu_dst);
3512 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3513 #ifdef TARGET_SPARC64
3514 int opf = GET_FIELD_SP(insn, 5, 13);
3515 rs1 = GET_FIELD(insn, 13, 17);
3516 rs2 = GET_FIELD(insn, 27, 31);
3517 if (gen_trap_ifnofpu(dc, cpu_cond))
3521 case 0x000: /* VIS I edge8cc */
3522 case 0x001: /* VIS II edge8n */
3523 case 0x002: /* VIS I edge8lcc */
3524 case 0x003: /* VIS II edge8ln */
3525 case 0x004: /* VIS I edge16cc */
3526 case 0x005: /* VIS II edge16n */
3527 case 0x006: /* VIS I edge16lcc */
3528 case 0x007: /* VIS II edge16ln */
3529 case 0x008: /* VIS I edge32cc */
3530 case 0x009: /* VIS II edge32n */
3531 case 0x00a: /* VIS I edge32lcc */
3532 case 0x00b: /* VIS II edge32ln */
3535 case 0x010: /* VIS I array8 */
3536 cpu_src1 = get_src1(insn, cpu_src1);
3537 gen_movl_reg_TN(rs2, cpu_src2);
3538 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3540 gen_movl_TN_reg(rd, cpu_dst);
3542 case 0x012: /* VIS I array16 */
3543 cpu_src1 = get_src1(insn, cpu_src1);
3544 gen_movl_reg_TN(rs2, cpu_src2);
3545 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3547 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3548 gen_movl_TN_reg(rd, cpu_dst);
3550 case 0x014: /* VIS I array32 */
3551 cpu_src1 = get_src1(insn, cpu_src1);
3552 gen_movl_reg_TN(rs2, cpu_src2);
3553 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3555 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3556 gen_movl_TN_reg(rd, cpu_dst);
3558 case 0x018: /* VIS I alignaddr */
3559 cpu_src1 = get_src1(insn, cpu_src1);
3560 gen_movl_reg_TN(rs2, cpu_src2);
3561 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3563 gen_movl_TN_reg(rd, cpu_dst);
3565 case 0x019: /* VIS II bmask */
3566 case 0x01a: /* VIS I alignaddrl */
3569 case 0x020: /* VIS I fcmple16 */
3570 gen_op_load_fpr_DT0(DFPREG(rs1));
3571 gen_op_load_fpr_DT1(DFPREG(rs2));
3572 tcg_gen_helper_0_0(helper_fcmple16);
3573 gen_op_store_DT0_fpr(DFPREG(rd));
3575 case 0x022: /* VIS I fcmpne16 */
3576 gen_op_load_fpr_DT0(DFPREG(rs1));
3577 gen_op_load_fpr_DT1(DFPREG(rs2));
3578 tcg_gen_helper_0_0(helper_fcmpne16);
3579 gen_op_store_DT0_fpr(DFPREG(rd));
3581 case 0x024: /* VIS I fcmple32 */
3582 gen_op_load_fpr_DT0(DFPREG(rs1));
3583 gen_op_load_fpr_DT1(DFPREG(rs2));
3584 tcg_gen_helper_0_0(helper_fcmple32);
3585 gen_op_store_DT0_fpr(DFPREG(rd));
3587 case 0x026: /* VIS I fcmpne32 */
3588 gen_op_load_fpr_DT0(DFPREG(rs1));
3589 gen_op_load_fpr_DT1(DFPREG(rs2));
3590 tcg_gen_helper_0_0(helper_fcmpne32);
3591 gen_op_store_DT0_fpr(DFPREG(rd));
3593 case 0x028: /* VIS I fcmpgt16 */
3594 gen_op_load_fpr_DT0(DFPREG(rs1));
3595 gen_op_load_fpr_DT1(DFPREG(rs2));
3596 tcg_gen_helper_0_0(helper_fcmpgt16);
3597 gen_op_store_DT0_fpr(DFPREG(rd));
3599 case 0x02a: /* VIS I fcmpeq16 */
3600 gen_op_load_fpr_DT0(DFPREG(rs1));
3601 gen_op_load_fpr_DT1(DFPREG(rs2));
3602 tcg_gen_helper_0_0(helper_fcmpeq16);
3603 gen_op_store_DT0_fpr(DFPREG(rd));
3605 case 0x02c: /* VIS I fcmpgt32 */
3606 gen_op_load_fpr_DT0(DFPREG(rs1));
3607 gen_op_load_fpr_DT1(DFPREG(rs2));
3608 tcg_gen_helper_0_0(helper_fcmpgt32);
3609 gen_op_store_DT0_fpr(DFPREG(rd));
3611 case 0x02e: /* VIS I fcmpeq32 */
3612 gen_op_load_fpr_DT0(DFPREG(rs1));
3613 gen_op_load_fpr_DT1(DFPREG(rs2));
3614 tcg_gen_helper_0_0(helper_fcmpeq32);
3615 gen_op_store_DT0_fpr(DFPREG(rd));
3617 case 0x031: /* VIS I fmul8x16 */
3618 gen_op_load_fpr_DT0(DFPREG(rs1));
3619 gen_op_load_fpr_DT1(DFPREG(rs2));
3620 tcg_gen_helper_0_0(helper_fmul8x16);
3621 gen_op_store_DT0_fpr(DFPREG(rd));
3623 case 0x033: /* VIS I fmul8x16au */
3624 gen_op_load_fpr_DT0(DFPREG(rs1));
3625 gen_op_load_fpr_DT1(DFPREG(rs2));
3626 tcg_gen_helper_0_0(helper_fmul8x16au);
3627 gen_op_store_DT0_fpr(DFPREG(rd));
3629 case 0x035: /* VIS I fmul8x16al */
3630 gen_op_load_fpr_DT0(DFPREG(rs1));
3631 gen_op_load_fpr_DT1(DFPREG(rs2));
3632 tcg_gen_helper_0_0(helper_fmul8x16al);
3633 gen_op_store_DT0_fpr(DFPREG(rd));
3635 case 0x036: /* VIS I fmul8sux16 */
3636 gen_op_load_fpr_DT0(DFPREG(rs1));
3637 gen_op_load_fpr_DT1(DFPREG(rs2));
3638 tcg_gen_helper_0_0(helper_fmul8sux16);
3639 gen_op_store_DT0_fpr(DFPREG(rd));
3641 case 0x037: /* VIS I fmul8ulx16 */
3642 gen_op_load_fpr_DT0(DFPREG(rs1));
3643 gen_op_load_fpr_DT1(DFPREG(rs2));
3644 tcg_gen_helper_0_0(helper_fmul8ulx16);
3645 gen_op_store_DT0_fpr(DFPREG(rd));
3647 case 0x038: /* VIS I fmuld8sux16 */
3648 gen_op_load_fpr_DT0(DFPREG(rs1));
3649 gen_op_load_fpr_DT1(DFPREG(rs2));
3650 tcg_gen_helper_0_0(helper_fmuld8sux16);
3651 gen_op_store_DT0_fpr(DFPREG(rd));
3653 case 0x039: /* VIS I fmuld8ulx16 */
3654 gen_op_load_fpr_DT0(DFPREG(rs1));
3655 gen_op_load_fpr_DT1(DFPREG(rs2));
3656 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3657 gen_op_store_DT0_fpr(DFPREG(rd));
3659 case 0x03a: /* VIS I fpack32 */
3660 case 0x03b: /* VIS I fpack16 */
3661 case 0x03d: /* VIS I fpackfix */
3662 case 0x03e: /* VIS I pdist */
3665 case 0x048: /* VIS I faligndata */
3666 gen_op_load_fpr_DT0(DFPREG(rs1));
3667 gen_op_load_fpr_DT1(DFPREG(rs2));
3668 tcg_gen_helper_0_0(helper_faligndata);
3669 gen_op_store_DT0_fpr(DFPREG(rd));
3671 case 0x04b: /* VIS I fpmerge */
3672 gen_op_load_fpr_DT0(DFPREG(rs1));
3673 gen_op_load_fpr_DT1(DFPREG(rs2));
3674 tcg_gen_helper_0_0(helper_fpmerge);
3675 gen_op_store_DT0_fpr(DFPREG(rd));
3677 case 0x04c: /* VIS II bshuffle */
3680 case 0x04d: /* VIS I fexpand */
3681 gen_op_load_fpr_DT0(DFPREG(rs1));
3682 gen_op_load_fpr_DT1(DFPREG(rs2));
3683 tcg_gen_helper_0_0(helper_fexpand);
3684 gen_op_store_DT0_fpr(DFPREG(rd));
3686 case 0x050: /* VIS I fpadd16 */
3687 gen_op_load_fpr_DT0(DFPREG(rs1));
3688 gen_op_load_fpr_DT1(DFPREG(rs2));
3689 tcg_gen_helper_0_0(helper_fpadd16);
3690 gen_op_store_DT0_fpr(DFPREG(rd));
3692 case 0x051: /* VIS I fpadd16s */
3693 gen_op_load_fpr_FT0(rs1);
3694 gen_op_load_fpr_FT1(rs2);
3695 tcg_gen_helper_0_0(helper_fpadd16s);
3696 gen_op_store_FT0_fpr(rd);
3698 case 0x052: /* VIS I fpadd32 */
3699 gen_op_load_fpr_DT0(DFPREG(rs1));
3700 gen_op_load_fpr_DT1(DFPREG(rs2));
3701 tcg_gen_helper_0_0(helper_fpadd32);
3702 gen_op_store_DT0_fpr(DFPREG(rd));
3704 case 0x053: /* VIS I fpadd32s */
3705 gen_op_load_fpr_FT0(rs1);
3706 gen_op_load_fpr_FT1(rs2);
3707 tcg_gen_helper_0_0(helper_fpadd32s);
3708 gen_op_store_FT0_fpr(rd);
3710 case 0x054: /* VIS I fpsub16 */
3711 gen_op_load_fpr_DT0(DFPREG(rs1));
3712 gen_op_load_fpr_DT1(DFPREG(rs2));
3713 tcg_gen_helper_0_0(helper_fpsub16);
3714 gen_op_store_DT0_fpr(DFPREG(rd));
3716 case 0x055: /* VIS I fpsub16s */
3717 gen_op_load_fpr_FT0(rs1);
3718 gen_op_load_fpr_FT1(rs2);
3719 tcg_gen_helper_0_0(helper_fpsub16s);
3720 gen_op_store_FT0_fpr(rd);
3722 case 0x056: /* VIS I fpsub32 */
3723 gen_op_load_fpr_DT0(DFPREG(rs1));
3724 gen_op_load_fpr_DT1(DFPREG(rs2));
3725 tcg_gen_helper_0_0(helper_fpadd32);
3726 gen_op_store_DT0_fpr(DFPREG(rd));
3728 case 0x057: /* VIS I fpsub32s */
3729 gen_op_load_fpr_FT0(rs1);
3730 gen_op_load_fpr_FT1(rs2);
3731 tcg_gen_helper_0_0(helper_fpsub32s);
3732 gen_op_store_FT0_fpr(rd);
3734 case 0x060: /* VIS I fzero */
3735 tcg_gen_helper_0_0(helper_movl_DT0_0);
3736 gen_op_store_DT0_fpr(DFPREG(rd));
3738 case 0x061: /* VIS I fzeros */
3739 tcg_gen_helper_0_0(helper_movl_FT0_0);
3740 gen_op_store_FT0_fpr(rd);
3742 case 0x062: /* VIS I fnor */
3743 gen_op_load_fpr_DT0(DFPREG(rs1));
3744 gen_op_load_fpr_DT1(DFPREG(rs2));
3745 tcg_gen_helper_0_0(helper_fnor);
3746 gen_op_store_DT0_fpr(DFPREG(rd));
3748 case 0x063: /* VIS I fnors */
3749 gen_op_load_fpr_FT0(rs1);
3750 gen_op_load_fpr_FT1(rs2);
3751 tcg_gen_helper_0_0(helper_fnors);
3752 gen_op_store_FT0_fpr(rd);
3754 case 0x064: /* VIS I fandnot2 */
3755 gen_op_load_fpr_DT1(DFPREG(rs1));
3756 gen_op_load_fpr_DT0(DFPREG(rs2));
3757 tcg_gen_helper_0_0(helper_fandnot);
3758 gen_op_store_DT0_fpr(DFPREG(rd));
3760 case 0x065: /* VIS I fandnot2s */
3761 gen_op_load_fpr_FT1(rs1);
3762 gen_op_load_fpr_FT0(rs2);
3763 tcg_gen_helper_0_0(helper_fandnots);
3764 gen_op_store_FT0_fpr(rd);
3766 case 0x066: /* VIS I fnot2 */
3767 gen_op_load_fpr_DT1(DFPREG(rs2));
3768 tcg_gen_helper_0_0(helper_fnot);
3769 gen_op_store_DT0_fpr(DFPREG(rd));
3771 case 0x067: /* VIS I fnot2s */
3772 gen_op_load_fpr_FT1(rs2);
3773 tcg_gen_helper_0_0(helper_fnot);
3774 gen_op_store_FT0_fpr(rd);
3776 case 0x068: /* VIS I fandnot1 */
3777 gen_op_load_fpr_DT0(DFPREG(rs1));
3778 gen_op_load_fpr_DT1(DFPREG(rs2));
3779 tcg_gen_helper_0_0(helper_fandnot);
3780 gen_op_store_DT0_fpr(DFPREG(rd));
3782 case 0x069: /* VIS I fandnot1s */
3783 gen_op_load_fpr_FT0(rs1);
3784 gen_op_load_fpr_FT1(rs2);
3785 tcg_gen_helper_0_0(helper_fandnots);
3786 gen_op_store_FT0_fpr(rd);
3788 case 0x06a: /* VIS I fnot1 */
3789 gen_op_load_fpr_DT1(DFPREG(rs1));
3790 tcg_gen_helper_0_0(helper_fnot);
3791 gen_op_store_DT0_fpr(DFPREG(rd));
3793 case 0x06b: /* VIS I fnot1s */
3794 gen_op_load_fpr_FT1(rs1);
3795 tcg_gen_helper_0_0(helper_fnot);
3796 gen_op_store_FT0_fpr(rd);
3798 case 0x06c: /* VIS I fxor */
3799 gen_op_load_fpr_DT0(DFPREG(rs1));
3800 gen_op_load_fpr_DT1(DFPREG(rs2));
3801 tcg_gen_helper_0_0(helper_fxor);
3802 gen_op_store_DT0_fpr(DFPREG(rd));
3804 case 0x06d: /* VIS I fxors */
3805 gen_op_load_fpr_FT0(rs1);
3806 gen_op_load_fpr_FT1(rs2);
3807 tcg_gen_helper_0_0(helper_fxors);
3808 gen_op_store_FT0_fpr(rd);
3810 case 0x06e: /* VIS I fnand */
3811 gen_op_load_fpr_DT0(DFPREG(rs1));
3812 gen_op_load_fpr_DT1(DFPREG(rs2));
3813 tcg_gen_helper_0_0(helper_fnand);
3814 gen_op_store_DT0_fpr(DFPREG(rd));
3816 case 0x06f: /* VIS I fnands */
3817 gen_op_load_fpr_FT0(rs1);
3818 gen_op_load_fpr_FT1(rs2);
3819 tcg_gen_helper_0_0(helper_fnands);
3820 gen_op_store_FT0_fpr(rd);
3822 case 0x070: /* VIS I fand */
3823 gen_op_load_fpr_DT0(DFPREG(rs1));
3824 gen_op_load_fpr_DT1(DFPREG(rs2));
3825 tcg_gen_helper_0_0(helper_fand);
3826 gen_op_store_DT0_fpr(DFPREG(rd));
3828 case 0x071: /* VIS I fands */
3829 gen_op_load_fpr_FT0(rs1);
3830 gen_op_load_fpr_FT1(rs2);
3831 tcg_gen_helper_0_0(helper_fands);
3832 gen_op_store_FT0_fpr(rd);
3834 case 0x072: /* VIS I fxnor */
3835 gen_op_load_fpr_DT0(DFPREG(rs1));
3836 gen_op_load_fpr_DT1(DFPREG(rs2));
3837 tcg_gen_helper_0_0(helper_fxnor);
3838 gen_op_store_DT0_fpr(DFPREG(rd));
3840 case 0x073: /* VIS I fxnors */
3841 gen_op_load_fpr_FT0(rs1);
3842 gen_op_load_fpr_FT1(rs2);
3843 tcg_gen_helper_0_0(helper_fxnors);
3844 gen_op_store_FT0_fpr(rd);
3846 case 0x074: /* VIS I fsrc1 */
3847 gen_op_load_fpr_DT0(DFPREG(rs1));
3848 gen_op_store_DT0_fpr(DFPREG(rd));
3850 case 0x075: /* VIS I fsrc1s */
3851 gen_op_load_fpr_FT0(rs1);
3852 gen_op_store_FT0_fpr(rd);
3854 case 0x076: /* VIS I fornot2 */
3855 gen_op_load_fpr_DT1(DFPREG(rs1));
3856 gen_op_load_fpr_DT0(DFPREG(rs2));
3857 tcg_gen_helper_0_0(helper_fornot);
3858 gen_op_store_DT0_fpr(DFPREG(rd));
3860 case 0x077: /* VIS I fornot2s */
3861 gen_op_load_fpr_FT1(rs1);
3862 gen_op_load_fpr_FT0(rs2);
3863 tcg_gen_helper_0_0(helper_fornots);
3864 gen_op_store_FT0_fpr(rd);
3866 case 0x078: /* VIS I fsrc2 */
3867 gen_op_load_fpr_DT0(DFPREG(rs2));
3868 gen_op_store_DT0_fpr(DFPREG(rd));
3870 case 0x079: /* VIS I fsrc2s */
3871 gen_op_load_fpr_FT0(rs2);
3872 gen_op_store_FT0_fpr(rd);
3874 case 0x07a: /* VIS I fornot1 */
3875 gen_op_load_fpr_DT0(DFPREG(rs1));
3876 gen_op_load_fpr_DT1(DFPREG(rs2));
3877 tcg_gen_helper_0_0(helper_fornot);
3878 gen_op_store_DT0_fpr(DFPREG(rd));
3880 case 0x07b: /* VIS I fornot1s */
3881 gen_op_load_fpr_FT0(rs1);
3882 gen_op_load_fpr_FT1(rs2);
3883 tcg_gen_helper_0_0(helper_fornots);
3884 gen_op_store_FT0_fpr(rd);
3886 case 0x07c: /* VIS I for */
3887 gen_op_load_fpr_DT0(DFPREG(rs1));
3888 gen_op_load_fpr_DT1(DFPREG(rs2));
3889 tcg_gen_helper_0_0(helper_for);
3890 gen_op_store_DT0_fpr(DFPREG(rd));
3892 case 0x07d: /* VIS I fors */
3893 gen_op_load_fpr_FT0(rs1);
3894 gen_op_load_fpr_FT1(rs2);
3895 tcg_gen_helper_0_0(helper_fors);
3896 gen_op_store_FT0_fpr(rd);
3898 case 0x07e: /* VIS I fone */
3899 tcg_gen_helper_0_0(helper_movl_DT0_1);
3900 gen_op_store_DT0_fpr(DFPREG(rd));
3902 case 0x07f: /* VIS I fones */
3903 tcg_gen_helper_0_0(helper_movl_FT0_1);
3904 gen_op_store_FT0_fpr(rd);
3906 case 0x080: /* VIS I shutdown */
3907 case 0x081: /* VIS II siam */
3916 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
3917 #ifdef TARGET_SPARC64
3922 #ifdef TARGET_SPARC64
3923 } else if (xop == 0x39) { /* V9 return */
3924 save_state(dc, cpu_cond);
3925 cpu_src1 = get_src1(insn, cpu_src1);
3926 if (IS_IMM) { /* immediate */
3927 rs2 = GET_FIELDs(insn, 19, 31);
3928 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3929 } else { /* register */
3930 rs2 = GET_FIELD(insn, 27, 31);
3934 gen_movl_reg_TN(rs2, cpu_src2);
3935 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3940 tcg_gen_helper_0_0(helper_restore);
3941 gen_mov_pc_npc(dc, cpu_cond);
3942 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3943 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3944 dc->npc = DYNAMIC_PC;
3948 cpu_src1 = get_src1(insn, cpu_src1);
3949 if (IS_IMM) { /* immediate */
3950 rs2 = GET_FIELDs(insn, 19, 31);
3951 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3952 } else { /* register */
3953 rs2 = GET_FIELD(insn, 27, 31);
3957 gen_movl_reg_TN(rs2, cpu_src2);
3958 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3964 case 0x38: /* jmpl */
3967 tcg_gen_movi_tl(cpu_tmp0, dc->pc);
3968 gen_movl_TN_reg(rd, cpu_tmp0);
3970 gen_mov_pc_npc(dc, cpu_cond);
3971 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3972 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3973 dc->npc = DYNAMIC_PC;
3976 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
3977 case 0x39: /* rett, V9 return */
3979 if (!supervisor(dc))
3981 gen_mov_pc_npc(dc, cpu_cond);
3982 tcg_gen_helper_0_2(helper_check_align, cpu_dst, tcg_const_i32(3));
3983 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3984 dc->npc = DYNAMIC_PC;
3985 tcg_gen_helper_0_0(helper_rett);
3989 case 0x3b: /* flush */
3990 tcg_gen_helper_0_1(helper_flush, cpu_dst);
3992 case 0x3c: /* save */
3993 save_state(dc, cpu_cond);
3994 tcg_gen_helper_0_0(helper_save);
3995 gen_movl_TN_reg(rd, cpu_dst);
3997 case 0x3d: /* restore */
3998 save_state(dc, cpu_cond);
3999 tcg_gen_helper_0_0(helper_restore);
4000 gen_movl_TN_reg(rd, cpu_dst);
4002 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4003 case 0x3e: /* V9 done/retry */
4007 if (!supervisor(dc))
4009 dc->npc = DYNAMIC_PC;
4010 dc->pc = DYNAMIC_PC;
4011 tcg_gen_helper_0_0(helper_done);
4014 if (!supervisor(dc))
4016 dc->npc = DYNAMIC_PC;
4017 dc->pc = DYNAMIC_PC;
4018 tcg_gen_helper_0_0(helper_retry);
4033 case 3: /* load/store instructions */
4035 unsigned int xop = GET_FIELD(insn, 7, 12);
4037 save_state(dc, cpu_cond);
4038 cpu_src1 = get_src1(insn, cpu_src1);
4039 if (xop == 0x3c || xop == 0x3e)
4041 rs2 = GET_FIELD(insn, 27, 31);
4042 gen_movl_reg_TN(rs2, cpu_src2);
4044 else if (IS_IMM) { /* immediate */
4045 rs2 = GET_FIELDs(insn, 19, 31);
4046 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4047 } else { /* register */
4048 rs2 = GET_FIELD(insn, 27, 31);
4052 gen_movl_reg_TN(rs2, cpu_src2);
4053 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4058 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4059 (xop > 0x17 && xop <= 0x1d ) ||
4060 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4062 case 0x0: /* load unsigned word */
4063 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4064 ABI32_MASK(cpu_addr);
4065 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4067 case 0x1: /* load unsigned byte */
4068 ABI32_MASK(cpu_addr);
4069 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4071 case 0x2: /* load unsigned halfword */
4072 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4073 ABI32_MASK(cpu_addr);
4074 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4076 case 0x3: /* load double word */
4080 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4081 ABI32_MASK(cpu_addr);
4082 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4083 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4084 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4085 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4086 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4087 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4088 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4091 case 0x9: /* load signed byte */
4092 ABI32_MASK(cpu_addr);
4093 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4095 case 0xa: /* load signed halfword */
4096 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4097 ABI32_MASK(cpu_addr);
4098 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4100 case 0xd: /* ldstub -- XXX: should be atomically */
4101 ABI32_MASK(cpu_addr);
4102 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4103 tcg_gen_qemu_st8(tcg_const_tl(0xff), cpu_addr, dc->mem_idx);
4105 case 0x0f: /* swap register with memory. Also atomically */
4106 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4107 gen_movl_reg_TN(rd, cpu_val);
4108 ABI32_MASK(cpu_addr);
4109 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4110 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4111 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4113 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4114 case 0x10: /* load word alternate */
4115 #ifndef TARGET_SPARC64
4118 if (!supervisor(dc))
4121 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4122 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4124 case 0x11: /* load unsigned byte alternate */
4125 #ifndef TARGET_SPARC64
4128 if (!supervisor(dc))
4131 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4133 case 0x12: /* load unsigned halfword alternate */
4134 #ifndef TARGET_SPARC64
4137 if (!supervisor(dc))
4140 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4141 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4143 case 0x13: /* load double word alternate */
4144 #ifndef TARGET_SPARC64
4147 if (!supervisor(dc))
4152 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4153 gen_ldda_asi(cpu_tmp0, cpu_val, cpu_addr, insn);
4154 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4156 case 0x19: /* load signed byte alternate */
4157 #ifndef TARGET_SPARC64
4160 if (!supervisor(dc))
4163 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4165 case 0x1a: /* load signed halfword alternate */
4166 #ifndef TARGET_SPARC64
4169 if (!supervisor(dc))
4172 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4173 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4175 case 0x1d: /* ldstuba -- XXX: should be atomically */
4176 #ifndef TARGET_SPARC64
4179 if (!supervisor(dc))
4182 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4184 case 0x1f: /* swap reg with alt. memory. Also atomically */
4185 #ifndef TARGET_SPARC64
4188 if (!supervisor(dc))
4191 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4192 gen_movl_reg_TN(rd, cpu_val);
4193 gen_swap_asi(cpu_val, cpu_addr, insn);
4196 #ifndef TARGET_SPARC64
4197 case 0x30: /* ldc */
4198 case 0x31: /* ldcsr */
4199 case 0x33: /* lddc */
4203 #ifdef TARGET_SPARC64
4204 case 0x08: /* V9 ldsw */
4205 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4206 ABI32_MASK(cpu_addr);
4207 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4209 case 0x0b: /* V9 ldx */
4210 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4211 ABI32_MASK(cpu_addr);
4212 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4214 case 0x18: /* V9 ldswa */
4215 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4216 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4218 case 0x1b: /* V9 ldxa */
4219 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4220 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4222 case 0x2d: /* V9 prefetch, no effect */
4224 case 0x30: /* V9 ldfa */
4225 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4226 gen_ldf_asi(cpu_addr, insn, 4, rd);
4228 case 0x33: /* V9 lddfa */
4229 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4230 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4232 case 0x3d: /* V9 prefetcha, no effect */
4234 case 0x32: /* V9 ldqfa */
4235 #if defined(CONFIG_USER_ONLY)
4236 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4237 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4246 gen_movl_TN_reg(rd, cpu_val);
4247 #ifdef TARGET_SPARC64
4250 } else if (xop >= 0x20 && xop < 0x24) {
4251 if (gen_trap_ifnofpu(dc, cpu_cond))
4254 case 0x20: /* load fpreg */
4255 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4256 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4257 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4258 offsetof(CPUState, fpr[rd]));
4260 case 0x21: /* load fsr */
4261 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4262 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4263 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4264 offsetof(CPUState, ft0));
4265 tcg_gen_helper_0_0(helper_ldfsr);
4267 case 0x22: /* load quad fpreg */
4268 #if defined(CONFIG_USER_ONLY)
4269 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4271 gen_op_store_QT0_fpr(QFPREG(rd));
4276 case 0x23: /* load double fpreg */
4277 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4279 gen_op_store_DT0_fpr(DFPREG(rd));
4284 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4285 xop == 0xe || xop == 0x1e) {
4286 gen_movl_reg_TN(rd, cpu_val);
4288 case 0x4: /* store word */
4289 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4290 ABI32_MASK(cpu_addr);
4291 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4293 case 0x5: /* store byte */
4294 ABI32_MASK(cpu_addr);
4295 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4297 case 0x6: /* store halfword */
4298 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4299 ABI32_MASK(cpu_addr);
4300 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4302 case 0x7: /* store double word */
4309 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4310 r_low = tcg_temp_new(TCG_TYPE_I32);
4311 gen_movl_reg_TN(rd + 1, r_low);
4312 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4314 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4316 #else /* __i386__ */
4317 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4318 flush_cond(dc, cpu_cond);
4319 gen_movl_reg_TN(rd + 1, cpu_cond);
4321 #endif /* __i386__ */
4323 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4324 case 0x14: /* store word alternate */
4325 #ifndef TARGET_SPARC64
4328 if (!supervisor(dc))
4331 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4332 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4334 case 0x15: /* store byte alternate */
4335 #ifndef TARGET_SPARC64
4338 if (!supervisor(dc))
4341 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4343 case 0x16: /* store halfword alternate */
4344 #ifndef TARGET_SPARC64
4347 if (!supervisor(dc))
4350 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(1));
4351 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4353 case 0x17: /* store double word alternate */
4354 #ifndef TARGET_SPARC64
4357 if (!supervisor(dc))
4363 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4364 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4368 #ifdef TARGET_SPARC64
4369 case 0x0e: /* V9 stx */
4370 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4371 ABI32_MASK(cpu_addr);
4372 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4374 case 0x1e: /* V9 stxa */
4375 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4376 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4382 } else if (xop > 0x23 && xop < 0x28) {
4383 if (gen_trap_ifnofpu(dc, cpu_cond))
4386 case 0x24: /* store fpreg */
4387 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4388 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4389 offsetof(CPUState, fpr[rd]));
4390 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4392 case 0x25: /* stfsr, V9 stxfsr */
4393 #ifdef CONFIG_USER_ONLY
4394 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4396 tcg_gen_helper_0_0(helper_stfsr);
4397 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4398 offsetof(CPUState, ft0));
4399 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4402 #ifdef TARGET_SPARC64
4403 #if defined(CONFIG_USER_ONLY)
4404 /* V9 stqf, store quad fpreg */
4405 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4406 gen_op_load_fpr_QT0(QFPREG(rd));
4412 #else /* !TARGET_SPARC64 */
4413 /* stdfq, store floating point queue */
4414 #if defined(CONFIG_USER_ONLY)
4417 if (!supervisor(dc))
4419 if (gen_trap_ifnofpu(dc, cpu_cond))
4425 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4426 gen_op_load_fpr_DT0(DFPREG(rd));
4432 } else if (xop > 0x33 && xop < 0x3f) {
4434 #ifdef TARGET_SPARC64
4435 case 0x34: /* V9 stfa */
4436 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4437 gen_op_load_fpr_FT0(rd);
4438 gen_stf_asi(cpu_addr, insn, 4, rd);
4440 case 0x36: /* V9 stqfa */
4441 #if defined(CONFIG_USER_ONLY)
4442 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4443 gen_op_load_fpr_QT0(QFPREG(rd));
4444 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4449 case 0x37: /* V9 stdfa */
4450 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4451 gen_op_load_fpr_DT0(DFPREG(rd));
4452 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4454 case 0x3c: /* V9 casa */
4455 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(3));
4456 gen_cas_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4457 gen_movl_TN_reg(rd, cpu_val);
4459 case 0x3e: /* V9 casxa */
4460 tcg_gen_helper_0_2(helper_check_align, cpu_addr, tcg_const_i32(7));
4461 gen_casx_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4462 gen_movl_TN_reg(rd, cpu_val);
4465 case 0x34: /* stc */
4466 case 0x35: /* stcsr */
4467 case 0x36: /* stdcq */
4468 case 0x37: /* stdc */
4480 /* default case for non jump instructions */
4481 if (dc->npc == DYNAMIC_PC) {
4482 dc->pc = DYNAMIC_PC;
4484 } else if (dc->npc == JUMP_PC) {
4485 /* we can do a static jump */
4486 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4490 dc->npc = dc->npc + 4;
4495 save_state(dc, cpu_cond);
4496 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_ILL_INSN));
4499 #if !defined(CONFIG_USER_ONLY)
4501 save_state(dc, cpu_cond);
4502 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_PRIV_INSN));
4506 save_state(dc, cpu_cond);
4507 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4510 #ifndef TARGET_SPARC64
4512 save_state(dc, cpu_cond);
4513 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4518 #ifndef TARGET_SPARC64
4520 save_state(dc, cpu_cond);
4521 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NCP_INSN));
4527 static void tcg_macro_func(TCGContext *s, int macro_id, const int *dead_args)
4531 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4532 int spc, CPUSPARCState *env)
4534 target_ulong pc_start, last_pc;
4535 uint16_t *gen_opc_end;
4536 DisasContext dc1, *dc = &dc1;
4539 memset(dc, 0, sizeof(DisasContext));
4544 dc->npc = (target_ulong) tb->cs_base;
4545 dc->mem_idx = cpu_mmu_index(env);
4546 dc->fpu_enabled = cpu_fpu_enabled(env);
4547 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4549 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4550 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4551 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4553 cpu_cond = cpu_T[2];
4556 if (env->nb_breakpoints > 0) {
4557 for(j = 0; j < env->nb_breakpoints; j++) {
4558 if (env->breakpoints[j] == dc->pc) {
4559 if (dc->pc != pc_start)
4560 save_state(dc, cpu_cond);
4561 tcg_gen_helper_0_0(helper_debug);
4570 fprintf(logfile, "Search PC...\n");
4571 j = gen_opc_ptr - gen_opc_buf;
4575 gen_opc_instr_start[lj++] = 0;
4576 gen_opc_pc[lj] = dc->pc;
4577 gen_opc_npc[lj] = dc->npc;
4578 gen_opc_instr_start[lj] = 1;
4582 disas_sparc_insn(dc);
4586 /* if the next PC is different, we abort now */
4587 if (dc->pc != (last_pc + 4))
4589 /* if we reach a page boundary, we stop generation so that the
4590 PC of a TT_TFAULT exception is always in the right page */
4591 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4593 /* if single step mode, we generate only one instruction and
4594 generate an exception */
4595 if (env->singlestep_enabled) {
4596 tcg_gen_movi_tl(cpu_pc, dc->pc);
4600 } while ((gen_opc_ptr < gen_opc_end) &&
4601 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
4605 if (dc->pc != DYNAMIC_PC &&
4606 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4607 /* static PC and NPC: we can use direct chaining */
4608 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4610 if (dc->pc != DYNAMIC_PC)
4611 tcg_gen_movi_tl(cpu_pc, dc->pc);
4612 save_npc(dc, cpu_cond);
4616 *gen_opc_ptr = INDEX_op_end;
4618 j = gen_opc_ptr - gen_opc_buf;
4621 gen_opc_instr_start[lj++] = 0;
4627 gen_opc_jump_pc[0] = dc->jump_pc[0];
4628 gen_opc_jump_pc[1] = dc->jump_pc[1];
4630 tb->size = last_pc + 4 - pc_start;
4633 if (loglevel & CPU_LOG_TB_IN_ASM) {
4634 fprintf(logfile, "--------------\n");
4635 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4636 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4637 fprintf(logfile, "\n");
4643 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4645 return gen_intermediate_code_internal(tb, 0, env);
4648 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4650 return gen_intermediate_code_internal(tb, 1, env);
4653 void gen_intermediate_code_init(CPUSPARCState *env)
4657 static const char * const gregnames[8] = {
4658 NULL, // g0 not used
4668 /* init various static tables */
4672 tcg_set_macro_func(&tcg_ctx, tcg_macro_func);
4673 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4674 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4675 offsetof(CPUState, regwptr),
4677 //#if TARGET_LONG_BITS > HOST_LONG_BITS
4678 #ifdef TARGET_SPARC64
4679 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
4680 TCG_AREG0, offsetof(CPUState, t0), "T0");
4681 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
4682 TCG_AREG0, offsetof(CPUState, t1), "T1");
4683 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
4684 TCG_AREG0, offsetof(CPUState, t2), "T2");
4685 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4686 TCG_AREG0, offsetof(CPUState, xcc),
4689 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
4690 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
4691 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
4693 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4694 TCG_AREG0, offsetof(CPUState, cc_src),
4696 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4697 offsetof(CPUState, cc_src2),
4699 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4700 TCG_AREG0, offsetof(CPUState, cc_dst),
4702 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4703 TCG_AREG0, offsetof(CPUState, psr),
4705 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4706 TCG_AREG0, offsetof(CPUState, fsr),
4708 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4709 TCG_AREG0, offsetof(CPUState, pc),
4711 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4712 TCG_AREG0, offsetof(CPUState, npc),
4714 for (i = 1; i < 8; i++)
4715 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4716 offsetof(CPUState, gregs[i]),