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
36 #define DYNAMIC_PC 1 /* dynamic pc value */
37 #define JUMP_PC 2 /* dynamic pc value which takes only two values
38 according to jump_pc[T2] */
40 /* global register indexes */
41 static TCGv cpu_env, cpu_T[2], cpu_regwptr;
42 static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
43 static TCGv cpu_psr, cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8];
44 static TCGv cpu_cond, cpu_src1, cpu_src2, cpu_dst, cpu_addr, cpu_val;
48 /* local register indexes (only used inside old micro ops) */
49 static TCGv cpu_tmp0, cpu_tmp32, cpu_tmp64;
51 typedef struct DisasContext {
52 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
53 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
54 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
58 struct TranslationBlock *tb;
62 // This function uses non-native bit order
63 #define GET_FIELD(X, FROM, TO) \
64 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
66 // This function uses the order in the manuals, i.e. bit 0 is 2^0
67 #define GET_FIELD_SP(X, FROM, TO) \
68 GET_FIELD(X, 31 - (TO), 31 - (FROM))
70 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
71 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
75 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
76 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
79 #define DFPREG(r) (r & 0x1e)
80 #define QFPREG(r) (r & 0x1c)
83 static int sign_extend(int x, int len)
86 return (x << len) >> len;
89 #define IS_IMM (insn & (1<<13))
91 /* floating point registers moves */
92 static void gen_op_load_fpr_FT0(unsigned int src)
94 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
95 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
98 static void gen_op_load_fpr_FT1(unsigned int src)
100 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
101 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
104 static void gen_op_store_FT0_fpr(unsigned int dst)
106 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
107 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
110 static void gen_op_load_fpr_DT0(unsigned int src)
112 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
113 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
114 offsetof(CPU_DoubleU, l.upper));
115 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
116 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
117 offsetof(CPU_DoubleU, l.lower));
120 static void gen_op_load_fpr_DT1(unsigned int src)
122 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
123 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
124 offsetof(CPU_DoubleU, l.upper));
125 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
126 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
127 offsetof(CPU_DoubleU, l.lower));
130 static void gen_op_store_DT0_fpr(unsigned int dst)
132 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
133 offsetof(CPU_DoubleU, l.upper));
134 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
135 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
136 offsetof(CPU_DoubleU, l.lower));
137 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
140 static void gen_op_load_fpr_QT0(unsigned int src)
142 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
143 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
144 offsetof(CPU_QuadU, l.upmost));
145 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
146 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
147 offsetof(CPU_QuadU, l.upper));
148 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
149 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
150 offsetof(CPU_QuadU, l.lower));
151 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
152 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
153 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) +
160 offsetof(CPU_QuadU, l.upmost));
161 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
162 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
163 offsetof(CPU_QuadU, l.upper));
164 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
165 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
166 offsetof(CPU_QuadU, l.lower));
167 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
168 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
169 offsetof(CPU_QuadU, l.lowest));
172 static void gen_op_store_QT0_fpr(unsigned int dst)
174 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
175 offsetof(CPU_QuadU, l.upmost));
176 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
177 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
178 offsetof(CPU_QuadU, l.upper));
179 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
180 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
181 offsetof(CPU_QuadU, l.lower));
182 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
183 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
184 offsetof(CPU_QuadU, l.lowest));
185 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
189 #ifdef CONFIG_USER_ONLY
190 #define supervisor(dc) 0
191 #ifdef TARGET_SPARC64
192 #define hypervisor(dc) 0
195 #define supervisor(dc) (dc->mem_idx >= 1)
196 #ifdef TARGET_SPARC64
197 #define hypervisor(dc) (dc->mem_idx == 2)
203 #define ABI32_MASK(addr) tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
205 #define ABI32_MASK(addr)
208 static inline void gen_movl_reg_TN(int reg, TCGv tn)
211 tcg_gen_movi_tl(tn, 0);
213 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
215 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
219 static inline void gen_movl_TN_reg(int reg, TCGv tn)
224 tcg_gen_mov_tl(cpu_gregs[reg], tn);
226 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
230 static inline void gen_goto_tb(DisasContext *s, int tb_num,
231 target_ulong pc, target_ulong npc)
233 TranslationBlock *tb;
236 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
237 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
238 /* jump to same page: we can use a direct jump */
239 tcg_gen_goto_tb(tb_num);
240 tcg_gen_movi_tl(cpu_pc, pc);
241 tcg_gen_movi_tl(cpu_npc, npc);
242 tcg_gen_exit_tb((long)tb + tb_num);
244 /* jump to another page: currently not optimized */
245 tcg_gen_movi_tl(cpu_pc, pc);
246 tcg_gen_movi_tl(cpu_npc, npc);
252 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
254 tcg_gen_extu_i32_tl(reg, src);
255 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
256 tcg_gen_andi_tl(reg, reg, 0x1);
259 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
261 tcg_gen_extu_i32_tl(reg, src);
262 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
263 tcg_gen_andi_tl(reg, reg, 0x1);
266 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
268 tcg_gen_extu_i32_tl(reg, src);
269 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
270 tcg_gen_andi_tl(reg, reg, 0x1);
273 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
275 tcg_gen_extu_i32_tl(reg, src);
276 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
277 tcg_gen_andi_tl(reg, reg, 0x1);
280 static inline void gen_cc_clear_icc(void)
282 tcg_gen_movi_i32(cpu_psr, 0);
285 #ifdef TARGET_SPARC64
286 static inline void gen_cc_clear_xcc(void)
288 tcg_gen_movi_i32(cpu_xcc, 0);
294 env->psr |= PSR_ZERO;
295 if ((int32_t) T0 < 0)
298 static inline void gen_cc_NZ_icc(TCGv dst)
303 l1 = gen_new_label();
304 l2 = gen_new_label();
305 r_temp = tcg_temp_new(TCG_TYPE_TL);
306 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
307 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
308 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
310 tcg_gen_ext_i32_tl(r_temp, dst);
311 tcg_gen_brcondi_tl(TCG_COND_GE, r_temp, 0, l2);
312 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
316 #ifdef TARGET_SPARC64
317 static inline void gen_cc_NZ_xcc(TCGv dst)
321 l1 = gen_new_label();
322 l2 = gen_new_label();
323 tcg_gen_brcondi_tl(TCG_COND_NE, dst, 0, l1);
324 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
326 tcg_gen_brcondi_tl(TCG_COND_GE, dst, 0, l2);
327 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
334 env->psr |= PSR_CARRY;
336 static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
341 l1 = gen_new_label();
342 r_temp = tcg_temp_new(TCG_TYPE_TL);
343 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
344 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
345 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
349 #ifdef TARGET_SPARC64
350 static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
354 l1 = gen_new_label();
355 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
356 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
362 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
365 static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
369 r_temp = tcg_temp_new(TCG_TYPE_TL);
370 tcg_gen_xor_tl(r_temp, src1, src2);
371 tcg_gen_xori_tl(r_temp, r_temp, -1);
372 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
373 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
374 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
375 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
376 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
377 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
380 #ifdef TARGET_SPARC64
381 static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
385 r_temp = tcg_temp_new(TCG_TYPE_TL);
386 tcg_gen_xor_tl(r_temp, src1, src2);
387 tcg_gen_xori_tl(r_temp, r_temp, -1);
388 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
389 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
390 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
391 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
392 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
393 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
397 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
402 l1 = gen_new_label();
404 r_temp = tcg_temp_new(TCG_TYPE_TL);
405 tcg_gen_xor_tl(r_temp, src1, src2);
406 tcg_gen_xori_tl(r_temp, r_temp, -1);
407 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
408 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
409 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
410 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
411 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
415 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
419 l1 = gen_new_label();
420 tcg_gen_or_tl(cpu_tmp0, src1, src2);
421 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
422 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
423 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
427 static inline void gen_tag_tv(TCGv src1, TCGv src2)
431 l1 = gen_new_label();
432 tcg_gen_or_tl(cpu_tmp0, src1, src2);
433 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
434 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
435 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
439 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
441 tcg_gen_mov_tl(cpu_cc_src, src1);
442 tcg_gen_mov_tl(cpu_cc_src2, src2);
443 tcg_gen_add_tl(dst, src1, src2);
444 tcg_gen_mov_tl(cpu_cc_dst, dst);
446 gen_cc_NZ_icc(cpu_cc_dst);
447 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
448 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
449 #ifdef TARGET_SPARC64
451 gen_cc_NZ_xcc(cpu_cc_dst);
452 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
453 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
457 static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
459 tcg_gen_mov_tl(cpu_cc_src, src1);
460 tcg_gen_mov_tl(cpu_cc_src2, src2);
461 gen_mov_reg_C(cpu_tmp0, cpu_psr);
462 tcg_gen_add_tl(dst, src1, cpu_tmp0);
464 gen_cc_C_add_icc(dst, cpu_cc_src);
465 #ifdef TARGET_SPARC64
467 gen_cc_C_add_xcc(dst, cpu_cc_src);
469 tcg_gen_add_tl(dst, dst, cpu_cc_src2);
470 tcg_gen_mov_tl(cpu_cc_dst, dst);
471 gen_cc_NZ_icc(cpu_cc_dst);
472 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
473 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
474 #ifdef TARGET_SPARC64
475 gen_cc_NZ_xcc(cpu_cc_dst);
476 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
477 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
481 static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
483 tcg_gen_mov_tl(cpu_cc_src, src1);
484 tcg_gen_mov_tl(cpu_cc_src2, src2);
485 tcg_gen_add_tl(dst, src1, src2);
486 tcg_gen_mov_tl(cpu_cc_dst, dst);
488 gen_cc_NZ_icc(cpu_cc_dst);
489 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
490 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
491 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
492 #ifdef TARGET_SPARC64
494 gen_cc_NZ_xcc(cpu_cc_dst);
495 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
496 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
500 static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
502 tcg_gen_mov_tl(cpu_cc_src, src1);
503 tcg_gen_mov_tl(cpu_cc_src2, src2);
504 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
505 tcg_gen_add_tl(dst, src1, src2);
506 tcg_gen_mov_tl(cpu_cc_dst, dst);
507 gen_add_tv(dst, cpu_cc_src, cpu_cc_src2);
509 gen_cc_NZ_icc(cpu_cc_dst);
510 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
511 #ifdef TARGET_SPARC64
513 gen_cc_NZ_xcc(cpu_cc_dst);
514 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
515 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
521 env->psr |= PSR_CARRY;
523 static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
525 TCGv r_temp1, r_temp2;
528 l1 = gen_new_label();
529 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
530 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
531 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
532 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
533 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
534 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
538 #ifdef TARGET_SPARC64
539 static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
543 l1 = gen_new_label();
544 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
545 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
551 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
554 static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
558 r_temp = tcg_temp_new(TCG_TYPE_TL);
559 tcg_gen_xor_tl(r_temp, src1, src2);
560 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
561 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
562 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
563 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
564 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
565 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
568 #ifdef TARGET_SPARC64
569 static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
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, (1ULL << 63));
578 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
579 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
580 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
584 static inline void gen_sub_tv(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, (1 << 31));
596 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
597 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
601 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
603 tcg_gen_mov_tl(cpu_cc_src, src1);
604 tcg_gen_mov_tl(cpu_cc_src2, src2);
605 tcg_gen_sub_tl(dst, src1, src2);
606 tcg_gen_mov_tl(cpu_cc_dst, dst);
608 gen_cc_NZ_icc(cpu_cc_dst);
609 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
610 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
611 #ifdef TARGET_SPARC64
613 gen_cc_NZ_xcc(cpu_cc_dst);
614 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
615 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
619 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
621 tcg_gen_mov_tl(cpu_cc_src, src1);
622 tcg_gen_mov_tl(cpu_cc_src2, src2);
623 gen_mov_reg_C(cpu_tmp0, cpu_psr);
624 tcg_gen_sub_tl(dst, src1, cpu_tmp0);
626 gen_cc_C_sub_icc(dst, cpu_cc_src);
627 #ifdef TARGET_SPARC64
629 gen_cc_C_sub_xcc(dst, cpu_cc_src);
631 tcg_gen_sub_tl(dst, dst, cpu_cc_src2);
632 tcg_gen_mov_tl(cpu_cc_dst, dst);
633 gen_cc_NZ_icc(cpu_cc_dst);
634 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
635 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
636 #ifdef TARGET_SPARC64
637 gen_cc_NZ_xcc(cpu_cc_dst);
638 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
639 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
643 static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
645 tcg_gen_mov_tl(cpu_cc_src, src1);
646 tcg_gen_mov_tl(cpu_cc_src2, src2);
647 tcg_gen_sub_tl(dst, src1, src2);
648 tcg_gen_mov_tl(cpu_cc_dst, dst);
650 gen_cc_NZ_icc(cpu_cc_dst);
651 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
652 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
653 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
654 #ifdef TARGET_SPARC64
656 gen_cc_NZ_xcc(cpu_cc_dst);
657 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
658 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
662 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
664 tcg_gen_mov_tl(cpu_cc_src, src1);
665 tcg_gen_mov_tl(cpu_cc_src2, src2);
666 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
667 tcg_gen_sub_tl(dst, src1, src2);
668 tcg_gen_mov_tl(cpu_cc_dst, dst);
669 gen_sub_tv(dst, cpu_cc_src, cpu_cc_src2);
671 gen_cc_NZ_icc(cpu_cc_dst);
672 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
673 #ifdef TARGET_SPARC64
675 gen_cc_NZ_xcc(cpu_cc_dst);
676 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
677 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
681 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
683 TCGv r_temp, r_temp2;
686 l1 = gen_new_label();
687 r_temp = tcg_temp_new(TCG_TYPE_TL);
688 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
694 tcg_gen_mov_tl(cpu_cc_src, src1);
695 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
696 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
697 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
698 tcg_gen_mov_tl(cpu_cc_src2, src2);
699 tcg_gen_brcondi_i32(TCG_COND_NE, r_temp2, 0, l1);
700 tcg_gen_movi_tl(cpu_cc_src2, 0);
704 // env->y = (b2 << 31) | (env->y >> 1);
705 tcg_gen_trunc_tl_i32(r_temp2, cpu_cc_src);
706 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
707 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
708 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
709 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
710 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
711 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
714 gen_mov_reg_N(cpu_tmp0, cpu_psr);
715 gen_mov_reg_V(r_temp, cpu_psr);
716 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
718 // T0 = (b1 << 31) | (T0 >> 1);
720 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
721 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
722 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
724 /* do addition and update flags */
725 tcg_gen_add_tl(dst, cpu_cc_src, cpu_cc_src2);
726 tcg_gen_mov_tl(cpu_cc_dst, dst);
729 gen_cc_NZ_icc(cpu_cc_dst);
730 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
731 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
734 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
736 TCGv r_temp, r_temp2;
738 r_temp = tcg_temp_new(TCG_TYPE_I64);
739 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
741 tcg_gen_extu_tl_i64(r_temp, src2);
742 tcg_gen_extu_tl_i64(r_temp2, src1);
743 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
745 tcg_gen_shri_i64(r_temp, r_temp2, 32);
746 tcg_gen_trunc_i64_i32(r_temp, r_temp);
747 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
748 #ifdef TARGET_SPARC64
749 tcg_gen_mov_i64(dst, r_temp2);
751 tcg_gen_trunc_i64_tl(dst, r_temp2);
755 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
757 TCGv r_temp, r_temp2;
759 r_temp = tcg_temp_new(TCG_TYPE_I64);
760 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
762 tcg_gen_ext_tl_i64(r_temp, src2);
763 tcg_gen_ext_tl_i64(r_temp2, src1);
764 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
766 tcg_gen_shri_i64(r_temp, r_temp2, 32);
767 tcg_gen_trunc_i64_i32(r_temp, r_temp);
768 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
769 #ifdef TARGET_SPARC64
770 tcg_gen_mov_i64(dst, r_temp2);
772 tcg_gen_trunc_i64_tl(dst, r_temp2);
776 #ifdef TARGET_SPARC64
777 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
781 l1 = gen_new_label();
782 tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
783 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_DIV_ZERO));
787 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
791 l1 = gen_new_label();
792 l2 = gen_new_label();
793 tcg_gen_mov_tl(cpu_cc_src, src1);
794 tcg_gen_mov_tl(cpu_cc_src2, src2);
795 gen_trap_ifdivzero_tl(src2);
796 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src, INT64_MIN, l1);
797 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src2, -1, l1);
798 tcg_gen_movi_i64(dst, INT64_MIN);
801 tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
806 static inline void gen_op_div_cc(TCGv dst)
810 tcg_gen_mov_tl(cpu_cc_dst, dst);
812 gen_cc_NZ_icc(cpu_cc_dst);
813 l1 = gen_new_label();
814 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, cc_src2));
815 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
816 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
820 static inline void gen_op_logic_cc(TCGv dst)
822 tcg_gen_mov_tl(cpu_cc_dst, dst);
825 gen_cc_NZ_icc(cpu_cc_dst);
826 #ifdef TARGET_SPARC64
828 gen_cc_NZ_xcc(cpu_cc_dst);
833 static inline void gen_op_eval_ba(TCGv dst)
835 tcg_gen_movi_tl(dst, 1);
839 static inline void gen_op_eval_be(TCGv dst, TCGv src)
841 gen_mov_reg_Z(dst, src);
845 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
847 gen_mov_reg_N(cpu_tmp0, src);
848 gen_mov_reg_V(dst, src);
849 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
850 gen_mov_reg_Z(cpu_tmp0, src);
851 tcg_gen_or_tl(dst, dst, cpu_tmp0);
855 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
857 gen_mov_reg_V(cpu_tmp0, src);
858 gen_mov_reg_N(dst, src);
859 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
863 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
865 gen_mov_reg_Z(cpu_tmp0, src);
866 gen_mov_reg_C(dst, src);
867 tcg_gen_or_tl(dst, dst, cpu_tmp0);
871 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
873 gen_mov_reg_C(dst, src);
877 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
879 gen_mov_reg_V(dst, src);
883 static inline void gen_op_eval_bn(TCGv dst)
885 tcg_gen_movi_tl(dst, 0);
889 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
891 gen_mov_reg_N(dst, src);
895 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
897 gen_mov_reg_Z(dst, src);
898 tcg_gen_xori_tl(dst, dst, 0x1);
902 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
904 gen_mov_reg_N(cpu_tmp0, src);
905 gen_mov_reg_V(dst, src);
906 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
907 gen_mov_reg_Z(cpu_tmp0, src);
908 tcg_gen_or_tl(dst, dst, cpu_tmp0);
909 tcg_gen_xori_tl(dst, dst, 0x1);
913 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
915 gen_mov_reg_V(cpu_tmp0, src);
916 gen_mov_reg_N(dst, src);
917 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
918 tcg_gen_xori_tl(dst, dst, 0x1);
922 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
924 gen_mov_reg_Z(cpu_tmp0, src);
925 gen_mov_reg_C(dst, src);
926 tcg_gen_or_tl(dst, dst, cpu_tmp0);
927 tcg_gen_xori_tl(dst, dst, 0x1);
931 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
933 gen_mov_reg_C(dst, src);
934 tcg_gen_xori_tl(dst, dst, 0x1);
938 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
940 gen_mov_reg_N(dst, src);
941 tcg_gen_xori_tl(dst, dst, 0x1);
945 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
947 gen_mov_reg_V(dst, src);
948 tcg_gen_xori_tl(dst, dst, 0x1);
952 FPSR bit field FCC1 | FCC0:
958 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
959 unsigned int fcc_offset)
961 tcg_gen_extu_i32_tl(reg, src);
962 tcg_gen_shri_tl(reg, reg, FSR_FCC0_SHIFT + fcc_offset);
963 tcg_gen_andi_tl(reg, reg, 0x1);
966 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
967 unsigned int fcc_offset)
969 tcg_gen_extu_i32_tl(reg, src);
970 tcg_gen_shri_tl(reg, reg, FSR_FCC1_SHIFT + fcc_offset);
971 tcg_gen_andi_tl(reg, reg, 0x1);
975 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
976 unsigned int fcc_offset)
978 gen_mov_reg_FCC0(dst, src, fcc_offset);
979 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
980 tcg_gen_or_tl(dst, dst, cpu_tmp0);
983 // 1 or 2: FCC0 ^ FCC1
984 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
985 unsigned int fcc_offset)
987 gen_mov_reg_FCC0(dst, src, fcc_offset);
988 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
989 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
993 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
994 unsigned int fcc_offset)
996 gen_mov_reg_FCC0(dst, src, fcc_offset);
1000 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
1001 unsigned int fcc_offset)
1003 gen_mov_reg_FCC0(dst, src, fcc_offset);
1004 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1005 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1006 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1010 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1011 unsigned int fcc_offset)
1013 gen_mov_reg_FCC1(dst, src, fcc_offset);
1017 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1018 unsigned int fcc_offset)
1020 gen_mov_reg_FCC0(dst, src, fcc_offset);
1021 tcg_gen_xori_tl(dst, dst, 0x1);
1022 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1023 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1027 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1028 unsigned int fcc_offset)
1030 gen_mov_reg_FCC0(dst, src, fcc_offset);
1031 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1032 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1035 // 0: !(FCC0 | FCC1)
1036 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1037 unsigned int fcc_offset)
1039 gen_mov_reg_FCC0(dst, src, fcc_offset);
1040 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1041 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1042 tcg_gen_xori_tl(dst, dst, 0x1);
1045 // 0 or 3: !(FCC0 ^ FCC1)
1046 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1047 unsigned int fcc_offset)
1049 gen_mov_reg_FCC0(dst, src, fcc_offset);
1050 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1051 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1052 tcg_gen_xori_tl(dst, dst, 0x1);
1056 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1057 unsigned int fcc_offset)
1059 gen_mov_reg_FCC0(dst, src, fcc_offset);
1060 tcg_gen_xori_tl(dst, dst, 0x1);
1063 // !1: !(FCC0 & !FCC1)
1064 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1065 unsigned int fcc_offset)
1067 gen_mov_reg_FCC0(dst, src, fcc_offset);
1068 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1069 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1070 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1071 tcg_gen_xori_tl(dst, dst, 0x1);
1075 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1076 unsigned int fcc_offset)
1078 gen_mov_reg_FCC1(dst, src, fcc_offset);
1079 tcg_gen_xori_tl(dst, dst, 0x1);
1082 // !2: !(!FCC0 & FCC1)
1083 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1084 unsigned int fcc_offset)
1086 gen_mov_reg_FCC0(dst, src, fcc_offset);
1087 tcg_gen_xori_tl(dst, dst, 0x1);
1088 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1089 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1090 tcg_gen_xori_tl(dst, dst, 0x1);
1093 // !3: !(FCC0 & FCC1)
1094 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1095 unsigned int fcc_offset)
1097 gen_mov_reg_FCC0(dst, src, fcc_offset);
1098 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1099 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1100 tcg_gen_xori_tl(dst, dst, 0x1);
1103 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1104 target_ulong pc2, TCGv r_cond)
1108 l1 = gen_new_label();
1110 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1112 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1115 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1118 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1119 target_ulong pc2, TCGv r_cond)
1123 l1 = gen_new_label();
1125 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1127 gen_goto_tb(dc, 0, pc2, pc1);
1130 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1133 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1138 l1 = gen_new_label();
1139 l2 = gen_new_label();
1141 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1143 tcg_gen_movi_tl(cpu_npc, npc1);
1147 tcg_gen_movi_tl(cpu_npc, npc2);
1151 /* call this function before using the condition register as it may
1152 have been set for a jump */
1153 static inline void flush_cond(DisasContext *dc, TCGv cond)
1155 if (dc->npc == JUMP_PC) {
1156 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1157 dc->npc = DYNAMIC_PC;
1161 static inline void save_npc(DisasContext *dc, TCGv cond)
1163 if (dc->npc == JUMP_PC) {
1164 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1165 dc->npc = DYNAMIC_PC;
1166 } else if (dc->npc != DYNAMIC_PC) {
1167 tcg_gen_movi_tl(cpu_npc, dc->npc);
1171 static inline void save_state(DisasContext *dc, TCGv cond)
1173 tcg_gen_movi_tl(cpu_pc, dc->pc);
1177 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1179 if (dc->npc == JUMP_PC) {
1180 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1181 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1182 dc->pc = DYNAMIC_PC;
1183 } else if (dc->npc == DYNAMIC_PC) {
1184 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1185 dc->pc = DYNAMIC_PC;
1191 static inline void gen_op_next_insn(void)
1193 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1194 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1197 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1201 #ifdef TARGET_SPARC64
1211 gen_op_eval_bn(r_dst);
1214 gen_op_eval_be(r_dst, r_src);
1217 gen_op_eval_ble(r_dst, r_src);
1220 gen_op_eval_bl(r_dst, r_src);
1223 gen_op_eval_bleu(r_dst, r_src);
1226 gen_op_eval_bcs(r_dst, r_src);
1229 gen_op_eval_bneg(r_dst, r_src);
1232 gen_op_eval_bvs(r_dst, r_src);
1235 gen_op_eval_ba(r_dst);
1238 gen_op_eval_bne(r_dst, r_src);
1241 gen_op_eval_bg(r_dst, r_src);
1244 gen_op_eval_bge(r_dst, r_src);
1247 gen_op_eval_bgu(r_dst, r_src);
1250 gen_op_eval_bcc(r_dst, r_src);
1253 gen_op_eval_bpos(r_dst, r_src);
1256 gen_op_eval_bvc(r_dst, r_src);
1261 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1263 unsigned int offset;
1283 gen_op_eval_bn(r_dst);
1286 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1289 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1292 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1295 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1298 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1301 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1304 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1307 gen_op_eval_ba(r_dst);
1310 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1313 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1316 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1319 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1322 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1325 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1328 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1333 #ifdef TARGET_SPARC64
1335 static const int gen_tcg_cond_reg[8] = {
1346 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1350 l1 = gen_new_label();
1351 tcg_gen_movi_tl(r_dst, 0);
1352 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1353 tcg_gen_movi_tl(r_dst, 1);
1358 /* XXX: potentially incorrect if dynamic npc */
1359 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1362 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1363 target_ulong target = dc->pc + offset;
1366 /* unconditional not taken */
1368 dc->pc = dc->npc + 4;
1369 dc->npc = dc->pc + 4;
1372 dc->npc = dc->pc + 4;
1374 } else if (cond == 0x8) {
1375 /* unconditional taken */
1378 dc->npc = dc->pc + 4;
1384 flush_cond(dc, r_cond);
1385 gen_cond(r_cond, cc, cond);
1387 gen_branch_a(dc, target, dc->npc, r_cond);
1391 dc->jump_pc[0] = target;
1392 dc->jump_pc[1] = dc->npc + 4;
1398 /* XXX: potentially incorrect if dynamic npc */
1399 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1402 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1403 target_ulong target = dc->pc + offset;
1406 /* unconditional not taken */
1408 dc->pc = dc->npc + 4;
1409 dc->npc = dc->pc + 4;
1412 dc->npc = dc->pc + 4;
1414 } else if (cond == 0x8) {
1415 /* unconditional taken */
1418 dc->npc = dc->pc + 4;
1424 flush_cond(dc, r_cond);
1425 gen_fcond(r_cond, cc, cond);
1427 gen_branch_a(dc, target, dc->npc, r_cond);
1431 dc->jump_pc[0] = target;
1432 dc->jump_pc[1] = dc->npc + 4;
1438 #ifdef TARGET_SPARC64
1439 /* XXX: potentially incorrect if dynamic npc */
1440 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1441 TCGv r_cond, TCGv r_reg)
1443 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1444 target_ulong target = dc->pc + offset;
1446 flush_cond(dc, r_cond);
1447 gen_cond_reg(r_cond, cond, r_reg);
1449 gen_branch_a(dc, target, dc->npc, r_cond);
1453 dc->jump_pc[0] = target;
1454 dc->jump_pc[1] = dc->npc + 4;
1459 static GenOpFunc * const gen_fcmps[4] = {
1466 static GenOpFunc * const gen_fcmpd[4] = {
1473 static GenOpFunc * const gen_fcmpq[4] = {
1480 static GenOpFunc * const gen_fcmpes[4] = {
1487 static GenOpFunc * const gen_fcmped[4] = {
1494 static GenOpFunc * const gen_fcmpeq[4] = {
1501 static inline void gen_op_fcmps(int fccno)
1503 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1506 static inline void gen_op_fcmpd(int fccno)
1508 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1511 static inline void gen_op_fcmpq(int fccno)
1513 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1516 static inline void gen_op_fcmpes(int fccno)
1518 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1521 static inline void gen_op_fcmped(int fccno)
1523 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1526 static inline void gen_op_fcmpeq(int fccno)
1528 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1533 static inline void gen_op_fcmps(int fccno)
1535 tcg_gen_helper_0_0(helper_fcmps);
1538 static inline void gen_op_fcmpd(int fccno)
1540 tcg_gen_helper_0_0(helper_fcmpd);
1543 static inline void gen_op_fcmpq(int fccno)
1545 tcg_gen_helper_0_0(helper_fcmpq);
1548 static inline void gen_op_fcmpes(int fccno)
1550 tcg_gen_helper_0_0(helper_fcmpes);
1553 static inline void gen_op_fcmped(int fccno)
1555 tcg_gen_helper_0_0(helper_fcmped);
1558 static inline void gen_op_fcmpeq(int fccno)
1560 tcg_gen_helper_0_0(helper_fcmpeq);
1564 static inline void gen_op_fpexception_im(int fsr_flags)
1566 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1567 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1568 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_FP_EXCP));
1571 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1573 #if !defined(CONFIG_USER_ONLY)
1574 if (!dc->fpu_enabled) {
1575 save_state(dc, r_cond);
1576 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NFPU_INSN));
1584 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1586 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1589 static inline void gen_clear_float_exceptions(void)
1591 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1595 #ifdef TARGET_SPARC64
1596 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1602 r_asi = tcg_temp_new(TCG_TYPE_I32);
1603 offset = GET_FIELD(insn, 25, 31);
1604 tcg_gen_addi_tl(r_addr, r_addr, offset);
1605 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1607 asi = GET_FIELD(insn, 19, 26);
1608 r_asi = tcg_const_i32(asi);
1613 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1618 r_asi = gen_get_asi(insn, addr);
1619 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi,
1620 tcg_const_i32(size), tcg_const_i32(sign));
1623 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1627 r_asi = gen_get_asi(insn, addr);
1628 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, tcg_const_i32(size));
1631 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1635 r_asi = gen_get_asi(insn, addr);
1636 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, tcg_const_i32(size),
1640 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1644 r_asi = gen_get_asi(insn, addr);
1645 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, tcg_const_i32(size),
1649 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1653 r_temp = tcg_temp_new(TCG_TYPE_I32);
1654 r_asi = gen_get_asi(insn, addr);
1655 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, r_asi,
1656 tcg_const_i32(4), tcg_const_i32(0));
1657 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi,
1659 tcg_gen_extu_i32_tl(dst, r_temp);
1662 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1666 r_asi = gen_get_asi(insn, addr);
1667 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi,
1668 tcg_const_i32(8), tcg_const_i32(0));
1669 tcg_gen_andi_i64(lo, cpu_tmp64, 0xffffffffULL);
1670 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1671 tcg_gen_andi_i64(hi, cpu_tmp64, 0xffffffffULL);
1674 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1678 r_temp = tcg_temp_new(TCG_TYPE_I32);
1679 gen_movl_reg_TN(rd + 1, r_temp);
1680 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1682 r_asi = gen_get_asi(insn, addr);
1683 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi,
1687 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1692 r_val1 = tcg_temp_new(TCG_TYPE_TL);
1693 gen_movl_reg_TN(rd, r_val1);
1694 r_asi = gen_get_asi(insn, addr);
1695 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1698 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1703 gen_movl_reg_TN(rd, cpu_tmp64);
1704 r_asi = gen_get_asi(insn, addr);
1705 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1708 #elif !defined(CONFIG_USER_ONLY)
1710 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1715 asi = GET_FIELD(insn, 19, 26);
1716 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
1717 tcg_const_i32(size), tcg_const_i32(sign));
1718 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1721 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1725 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1726 asi = GET_FIELD(insn, 19, 26);
1727 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
1728 tcg_const_i32(size));
1731 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1736 r_temp = tcg_temp_new(TCG_TYPE_I32);
1737 asi = GET_FIELD(insn, 19, 26);
1738 tcg_gen_helper_1_4(helper_ld_asi, r_temp, addr, tcg_const_i32(asi),
1739 tcg_const_i32(4), tcg_const_i32(0));
1740 tcg_gen_helper_0_4(helper_st_asi, addr, dst, tcg_const_i32(asi),
1742 tcg_gen_extu_i32_tl(dst, r_temp);
1745 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1749 asi = GET_FIELD(insn, 19, 26);
1750 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, tcg_const_i32(asi),
1751 tcg_const_i32(8), tcg_const_i32(0));
1752 tcg_gen_trunc_i64_tl(lo, cpu_tmp64);
1753 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1754 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1757 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1762 r_temp = tcg_temp_new(TCG_TYPE_I32);
1763 gen_movl_reg_TN(rd + 1, r_temp);
1764 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1765 asi = GET_FIELD(insn, 19, 26);
1766 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, tcg_const_i32(asi),
1771 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1772 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1776 gen_ld_asi(dst, addr, insn, 1, 0);
1778 asi = GET_FIELD(insn, 19, 26);
1779 tcg_gen_helper_0_4(helper_st_asi, addr, tcg_const_i64(0xffULL),
1780 tcg_const_i32(asi), tcg_const_i32(1));
1784 static inline TCGv get_src1(unsigned int insn, TCGv def)
1789 rs1 = GET_FIELD(insn, 13, 17);
1791 //r_rs1 = tcg_const_tl(0);
1792 tcg_gen_movi_tl(def, 0);
1794 //r_rs1 = cpu_gregs[rs1];
1795 tcg_gen_mov_tl(def, cpu_gregs[rs1]);
1797 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1801 static inline TCGv get_src2(unsigned int insn, TCGv def)
1806 if (IS_IMM) { /* immediate */
1807 rs2 = GET_FIELDs(insn, 19, 31);
1808 r_rs2 = tcg_const_tl((int)rs2);
1809 } else { /* register */
1810 rs2 = GET_FIELD(insn, 27, 31);
1812 r_rs2 = tcg_const_tl(0);
1814 r_rs2 = cpu_gregs[rs2];
1816 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1821 #define CHECK_IU_FEATURE(dc, FEATURE) \
1822 if (!((dc)->features & CPU_FEATURE_ ## FEATURE)) \
1824 #define CHECK_FPU_FEATURE(dc, FEATURE) \
1825 if (!((dc)->features & CPU_FEATURE_ ## FEATURE)) \
1828 /* before an instruction, dc->pc must be static */
1829 static void disas_sparc_insn(DisasContext * dc)
1831 unsigned int insn, opc, rs1, rs2, rd;
1833 if (unlikely(loglevel & CPU_LOG_TB_OP))
1834 tcg_gen_debug_insn_start(dc->pc);
1835 insn = ldl_code(dc->pc);
1836 opc = GET_FIELD(insn, 0, 1);
1838 rd = GET_FIELD(insn, 2, 6);
1841 cpu_src1 = cpu_T[0]; // const
1842 cpu_src2 = cpu_T[1]; // const
1845 cpu_addr = cpu_T[0];
1849 case 0: /* branches/sethi */
1851 unsigned int xop = GET_FIELD(insn, 7, 9);
1854 #ifdef TARGET_SPARC64
1855 case 0x1: /* V9 BPcc */
1859 target = GET_FIELD_SP(insn, 0, 18);
1860 target = sign_extend(target, 18);
1862 cc = GET_FIELD_SP(insn, 20, 21);
1864 do_branch(dc, target, insn, 0, cpu_cond);
1866 do_branch(dc, target, insn, 1, cpu_cond);
1871 case 0x3: /* V9 BPr */
1873 target = GET_FIELD_SP(insn, 0, 13) |
1874 (GET_FIELD_SP(insn, 20, 21) << 14);
1875 target = sign_extend(target, 16);
1877 cpu_src1 = get_src1(insn, cpu_src1);
1878 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1881 case 0x5: /* V9 FBPcc */
1883 int cc = GET_FIELD_SP(insn, 20, 21);
1884 if (gen_trap_ifnofpu(dc, cpu_cond))
1886 target = GET_FIELD_SP(insn, 0, 18);
1887 target = sign_extend(target, 19);
1889 do_fbranch(dc, target, insn, cc, cpu_cond);
1893 case 0x7: /* CBN+x */
1898 case 0x2: /* BN+x */
1900 target = GET_FIELD(insn, 10, 31);
1901 target = sign_extend(target, 22);
1903 do_branch(dc, target, insn, 0, cpu_cond);
1906 case 0x6: /* FBN+x */
1908 if (gen_trap_ifnofpu(dc, cpu_cond))
1910 target = GET_FIELD(insn, 10, 31);
1911 target = sign_extend(target, 22);
1913 do_fbranch(dc, target, insn, 0, cpu_cond);
1916 case 0x4: /* SETHI */
1918 uint32_t value = GET_FIELD(insn, 10, 31);
1919 gen_movl_TN_reg(rd, tcg_const_tl(value << 10));
1922 case 0x0: /* UNIMPL */
1931 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1933 gen_movl_TN_reg(15, tcg_const_tl(dc->pc));
1935 gen_mov_pc_npc(dc, cpu_cond);
1939 case 2: /* FPU & Logical Operations */
1941 unsigned int xop = GET_FIELD(insn, 7, 12);
1942 if (xop == 0x3a) { /* generate trap */
1945 cpu_src1 = get_src1(insn, cpu_src1);
1947 rs2 = GET_FIELD(insn, 25, 31);
1948 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
1950 rs2 = GET_FIELD(insn, 27, 31);
1952 gen_movl_reg_TN(rs2, cpu_src2);
1953 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
1955 tcg_gen_mov_tl(cpu_dst, cpu_src1);
1957 cond = GET_FIELD(insn, 3, 6);
1959 save_state(dc, cpu_cond);
1960 tcg_gen_helper_0_1(helper_trap, cpu_dst);
1961 } else if (cond != 0) {
1962 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
1963 #ifdef TARGET_SPARC64
1965 int cc = GET_FIELD_SP(insn, 11, 12);
1967 save_state(dc, cpu_cond);
1969 gen_cond(r_cond, 0, cond);
1971 gen_cond(r_cond, 1, cond);
1975 save_state(dc, cpu_cond);
1976 gen_cond(r_cond, 0, cond);
1978 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
1984 } else if (xop == 0x28) {
1985 rs1 = GET_FIELD(insn, 13, 17);
1988 #ifndef TARGET_SPARC64
1989 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1990 manual, rdy on the microSPARC
1992 case 0x0f: /* stbar in the SPARCv8 manual,
1993 rdy on the microSPARC II */
1994 case 0x10 ... 0x1f: /* implementation-dependent in the
1995 SPARCv8 manual, rdy on the
1998 tcg_gen_ld_tl(cpu_dst, cpu_env,
1999 offsetof(CPUSPARCState, y));
2000 gen_movl_TN_reg(rd, cpu_dst);
2002 #ifdef TARGET_SPARC64
2003 case 0x2: /* V9 rdccr */
2004 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2005 gen_movl_TN_reg(rd, cpu_dst);
2007 case 0x3: /* V9 rdasi */
2008 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2009 offsetof(CPUSPARCState, asi));
2010 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2011 gen_movl_TN_reg(rd, cpu_dst);
2013 case 0x4: /* V9 rdtick */
2017 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2018 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2019 offsetof(CPUState, tick));
2020 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2022 gen_movl_TN_reg(rd, cpu_dst);
2025 case 0x5: /* V9 rdpc */
2026 gen_movl_TN_reg(rd, tcg_const_tl(dc->pc));
2028 case 0x6: /* V9 rdfprs */
2029 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2030 offsetof(CPUSPARCState, fprs));
2031 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2032 gen_movl_TN_reg(rd, cpu_dst);
2034 case 0xf: /* V9 membar */
2035 break; /* no effect */
2036 case 0x13: /* Graphics Status */
2037 if (gen_trap_ifnofpu(dc, cpu_cond))
2039 tcg_gen_ld_tl(cpu_dst, cpu_env,
2040 offsetof(CPUSPARCState, gsr));
2041 gen_movl_TN_reg(rd, cpu_dst);
2043 case 0x17: /* Tick compare */
2044 tcg_gen_ld_tl(cpu_dst, cpu_env,
2045 offsetof(CPUSPARCState, tick_cmpr));
2046 gen_movl_TN_reg(rd, cpu_dst);
2048 case 0x18: /* System tick */
2052 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2053 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2054 offsetof(CPUState, stick));
2055 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2057 gen_movl_TN_reg(rd, cpu_dst);
2060 case 0x19: /* System tick compare */
2061 tcg_gen_ld_tl(cpu_dst, cpu_env,
2062 offsetof(CPUSPARCState, stick_cmpr));
2063 gen_movl_TN_reg(rd, cpu_dst);
2065 case 0x10: /* Performance Control */
2066 case 0x11: /* Performance Instrumentation Counter */
2067 case 0x12: /* Dispatch Control */
2068 case 0x14: /* Softint set, WO */
2069 case 0x15: /* Softint clear, WO */
2070 case 0x16: /* Softint write */
2075 #if !defined(CONFIG_USER_ONLY)
2076 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2077 #ifndef TARGET_SPARC64
2078 if (!supervisor(dc))
2080 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2082 if (!hypervisor(dc))
2084 rs1 = GET_FIELD(insn, 13, 17);
2087 // gen_op_rdhpstate();
2090 // gen_op_rdhtstate();
2093 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2094 offsetof(CPUSPARCState, hintp));
2095 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2098 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2099 offsetof(CPUSPARCState, htba));
2100 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2103 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2104 offsetof(CPUSPARCState, hver));
2105 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2107 case 31: // hstick_cmpr
2108 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2109 tcg_gen_st_i32(cpu_tmp32, cpu_env,
2110 offsetof(CPUSPARCState, hstick_cmpr));
2116 gen_movl_TN_reg(rd, cpu_dst);
2118 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2119 if (!supervisor(dc))
2121 #ifdef TARGET_SPARC64
2122 rs1 = GET_FIELD(insn, 13, 17);
2128 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2129 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2130 offsetof(CPUState, tsptr));
2131 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2132 offsetof(trap_state, tpc));
2139 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2140 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2141 offsetof(CPUState, tsptr));
2142 tcg_gen_ld_tl(cpu_dst, r_tsptr,
2143 offsetof(trap_state, tnpc));
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, tstate));
2161 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2162 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2163 offsetof(CPUState, tsptr));
2164 tcg_gen_ld_i32(cpu_dst, r_tsptr,
2165 offsetof(trap_state, tt));
2172 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2173 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2174 offsetof(CPUState, tick));
2175 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2177 gen_movl_TN_reg(rd, cpu_dst);
2181 tcg_gen_ld_tl(cpu_dst, cpu_env,
2182 offsetof(CPUSPARCState, tbr));
2185 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2186 offsetof(CPUSPARCState, pstate));
2187 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2190 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2191 offsetof(CPUSPARCState, tl));
2192 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2195 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2196 offsetof(CPUSPARCState, psrpil));
2197 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2200 tcg_gen_helper_1_0(helper_rdcwp, cpu_dst);
2203 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2204 offsetof(CPUSPARCState, cansave));
2205 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2207 case 11: // canrestore
2208 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2209 offsetof(CPUSPARCState, canrestore));
2210 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2212 case 12: // cleanwin
2213 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2214 offsetof(CPUSPARCState, cleanwin));
2215 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2217 case 13: // otherwin
2218 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2219 offsetof(CPUSPARCState, otherwin));
2220 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2223 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2224 offsetof(CPUSPARCState, wstate));
2225 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2227 case 16: // UA2005 gl
2228 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2229 offsetof(CPUSPARCState, gl));
2230 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2232 case 26: // UA2005 strand status
2233 if (!hypervisor(dc))
2235 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2236 offsetof(CPUSPARCState, ssr));
2237 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2240 tcg_gen_ld_tl(cpu_dst, cpu_env,
2241 offsetof(CPUSPARCState, version));
2248 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2249 offsetof(CPUSPARCState, wim));
2250 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2252 gen_movl_TN_reg(rd, cpu_dst);
2254 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2255 #ifdef TARGET_SPARC64
2256 tcg_gen_helper_0_0(helper_flushw);
2258 if (!supervisor(dc))
2260 tcg_gen_ld_tl(cpu_dst, cpu_env, offsetof(CPUSPARCState, tbr));
2261 gen_movl_TN_reg(rd, cpu_dst);
2265 } else if (xop == 0x34) { /* FPU Operations */
2266 if (gen_trap_ifnofpu(dc, cpu_cond))
2268 gen_op_clear_ieee_excp_and_FTT();
2269 rs1 = GET_FIELD(insn, 13, 17);
2270 rs2 = GET_FIELD(insn, 27, 31);
2271 xop = GET_FIELD(insn, 18, 26);
2273 case 0x1: /* fmovs */
2274 gen_op_load_fpr_FT0(rs2);
2275 gen_op_store_FT0_fpr(rd);
2277 case 0x5: /* fnegs */
2278 gen_op_load_fpr_FT1(rs2);
2279 tcg_gen_helper_0_0(helper_fnegs);
2280 gen_op_store_FT0_fpr(rd);
2282 case 0x9: /* fabss */
2283 gen_op_load_fpr_FT1(rs2);
2284 tcg_gen_helper_0_0(helper_fabss);
2285 gen_op_store_FT0_fpr(rd);
2287 case 0x29: /* fsqrts */
2288 CHECK_FPU_FEATURE(dc, FSQRT);
2289 gen_op_load_fpr_FT1(rs2);
2290 gen_clear_float_exceptions();
2291 tcg_gen_helper_0_0(helper_fsqrts);
2292 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2293 gen_op_store_FT0_fpr(rd);
2295 case 0x2a: /* fsqrtd */
2296 CHECK_FPU_FEATURE(dc, FSQRT);
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 CHECK_FPU_FEATURE(dc, FLOAT128);
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));
2312 gen_op_load_fpr_FT0(rs1);
2313 gen_op_load_fpr_FT1(rs2);
2314 gen_clear_float_exceptions();
2315 tcg_gen_helper_0_0(helper_fadds);
2316 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2317 gen_op_store_FT0_fpr(rd);
2320 gen_op_load_fpr_DT0(DFPREG(rs1));
2321 gen_op_load_fpr_DT1(DFPREG(rs2));
2322 gen_clear_float_exceptions();
2323 tcg_gen_helper_0_0(helper_faddd);
2324 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2325 gen_op_store_DT0_fpr(DFPREG(rd));
2327 case 0x43: /* faddq */
2328 CHECK_FPU_FEATURE(dc, FLOAT128);
2329 gen_op_load_fpr_QT0(QFPREG(rs1));
2330 gen_op_load_fpr_QT1(QFPREG(rs2));
2331 gen_clear_float_exceptions();
2332 tcg_gen_helper_0_0(helper_faddq);
2333 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2334 gen_op_store_QT0_fpr(QFPREG(rd));
2337 gen_op_load_fpr_FT0(rs1);
2338 gen_op_load_fpr_FT1(rs2);
2339 gen_clear_float_exceptions();
2340 tcg_gen_helper_0_0(helper_fsubs);
2341 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2342 gen_op_store_FT0_fpr(rd);
2345 gen_op_load_fpr_DT0(DFPREG(rs1));
2346 gen_op_load_fpr_DT1(DFPREG(rs2));
2347 gen_clear_float_exceptions();
2348 tcg_gen_helper_0_0(helper_fsubd);
2349 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2350 gen_op_store_DT0_fpr(DFPREG(rd));
2352 case 0x47: /* fsubq */
2353 CHECK_FPU_FEATURE(dc, FLOAT128);
2354 gen_op_load_fpr_QT0(QFPREG(rs1));
2355 gen_op_load_fpr_QT1(QFPREG(rs2));
2356 gen_clear_float_exceptions();
2357 tcg_gen_helper_0_0(helper_fsubq);
2358 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2359 gen_op_store_QT0_fpr(QFPREG(rd));
2361 case 0x49: /* fmuls */
2362 CHECK_FPU_FEATURE(dc, FMUL);
2363 gen_op_load_fpr_FT0(rs1);
2364 gen_op_load_fpr_FT1(rs2);
2365 gen_clear_float_exceptions();
2366 tcg_gen_helper_0_0(helper_fmuls);
2367 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2368 gen_op_store_FT0_fpr(rd);
2370 case 0x4a: /* fmuld */
2371 CHECK_FPU_FEATURE(dc, FMUL);
2372 gen_op_load_fpr_DT0(DFPREG(rs1));
2373 gen_op_load_fpr_DT1(DFPREG(rs2));
2374 gen_clear_float_exceptions();
2375 tcg_gen_helper_0_0(helper_fmuld);
2376 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2377 gen_op_store_DT0_fpr(DFPREG(rd));
2379 case 0x4b: /* fmulq */
2380 CHECK_FPU_FEATURE(dc, FLOAT128);
2381 CHECK_FPU_FEATURE(dc, FMUL);
2382 gen_op_load_fpr_QT0(QFPREG(rs1));
2383 gen_op_load_fpr_QT1(QFPREG(rs2));
2384 gen_clear_float_exceptions();
2385 tcg_gen_helper_0_0(helper_fmulq);
2386 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2387 gen_op_store_QT0_fpr(QFPREG(rd));
2390 gen_op_load_fpr_FT0(rs1);
2391 gen_op_load_fpr_FT1(rs2);
2392 gen_clear_float_exceptions();
2393 tcg_gen_helper_0_0(helper_fdivs);
2394 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2395 gen_op_store_FT0_fpr(rd);
2398 gen_op_load_fpr_DT0(DFPREG(rs1));
2399 gen_op_load_fpr_DT1(DFPREG(rs2));
2400 gen_clear_float_exceptions();
2401 tcg_gen_helper_0_0(helper_fdivd);
2402 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2403 gen_op_store_DT0_fpr(DFPREG(rd));
2405 case 0x4f: /* fdivq */
2406 CHECK_FPU_FEATURE(dc, FLOAT128);
2407 gen_op_load_fpr_QT0(QFPREG(rs1));
2408 gen_op_load_fpr_QT1(QFPREG(rs2));
2409 gen_clear_float_exceptions();
2410 tcg_gen_helper_0_0(helper_fdivq);
2411 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2412 gen_op_store_QT0_fpr(QFPREG(rd));
2415 gen_op_load_fpr_FT0(rs1);
2416 gen_op_load_fpr_FT1(rs2);
2417 gen_clear_float_exceptions();
2418 tcg_gen_helper_0_0(helper_fsmuld);
2419 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2420 gen_op_store_DT0_fpr(DFPREG(rd));
2422 case 0x6e: /* fdmulq */
2423 CHECK_FPU_FEATURE(dc, FLOAT128);
2424 gen_op_load_fpr_DT0(DFPREG(rs1));
2425 gen_op_load_fpr_DT1(DFPREG(rs2));
2426 gen_clear_float_exceptions();
2427 tcg_gen_helper_0_0(helper_fdmulq);
2428 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2429 gen_op_store_QT0_fpr(QFPREG(rd));
2432 gen_op_load_fpr_FT1(rs2);
2433 gen_clear_float_exceptions();
2434 tcg_gen_helper_0_0(helper_fitos);
2435 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2436 gen_op_store_FT0_fpr(rd);
2439 gen_op_load_fpr_DT1(DFPREG(rs2));
2440 gen_clear_float_exceptions();
2441 tcg_gen_helper_0_0(helper_fdtos);
2442 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2443 gen_op_store_FT0_fpr(rd);
2445 case 0xc7: /* fqtos */
2446 CHECK_FPU_FEATURE(dc, FLOAT128);
2447 gen_op_load_fpr_QT1(QFPREG(rs2));
2448 gen_clear_float_exceptions();
2449 tcg_gen_helper_0_0(helper_fqtos);
2450 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2451 gen_op_store_FT0_fpr(rd);
2454 gen_op_load_fpr_FT1(rs2);
2455 tcg_gen_helper_0_0(helper_fitod);
2456 gen_op_store_DT0_fpr(DFPREG(rd));
2459 gen_op_load_fpr_FT1(rs2);
2460 tcg_gen_helper_0_0(helper_fstod);
2461 gen_op_store_DT0_fpr(DFPREG(rd));
2463 case 0xcb: /* fqtod */
2464 CHECK_FPU_FEATURE(dc, FLOAT128);
2465 gen_op_load_fpr_QT1(QFPREG(rs2));
2466 gen_clear_float_exceptions();
2467 tcg_gen_helper_0_0(helper_fqtod);
2468 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2469 gen_op_store_DT0_fpr(DFPREG(rd));
2471 case 0xcc: /* fitoq */
2472 CHECK_FPU_FEATURE(dc, FLOAT128);
2473 gen_op_load_fpr_FT1(rs2);
2474 tcg_gen_helper_0_0(helper_fitoq);
2475 gen_op_store_QT0_fpr(QFPREG(rd));
2477 case 0xcd: /* fstoq */
2478 CHECK_FPU_FEATURE(dc, FLOAT128);
2479 gen_op_load_fpr_FT1(rs2);
2480 tcg_gen_helper_0_0(helper_fstoq);
2481 gen_op_store_QT0_fpr(QFPREG(rd));
2483 case 0xce: /* fdtoq */
2484 CHECK_FPU_FEATURE(dc, FLOAT128);
2485 gen_op_load_fpr_DT1(DFPREG(rs2));
2486 tcg_gen_helper_0_0(helper_fdtoq);
2487 gen_op_store_QT0_fpr(QFPREG(rd));
2490 gen_op_load_fpr_FT1(rs2);
2491 gen_clear_float_exceptions();
2492 tcg_gen_helper_0_0(helper_fstoi);
2493 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2494 gen_op_store_FT0_fpr(rd);
2497 gen_op_load_fpr_DT1(DFPREG(rs2));
2498 gen_clear_float_exceptions();
2499 tcg_gen_helper_0_0(helper_fdtoi);
2500 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2501 gen_op_store_FT0_fpr(rd);
2503 case 0xd3: /* fqtoi */
2504 CHECK_FPU_FEATURE(dc, FLOAT128);
2505 gen_op_load_fpr_QT1(QFPREG(rs2));
2506 gen_clear_float_exceptions();
2507 tcg_gen_helper_0_0(helper_fqtoi);
2508 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2509 gen_op_store_FT0_fpr(rd);
2511 #ifdef TARGET_SPARC64
2512 case 0x2: /* V9 fmovd */
2513 gen_op_load_fpr_DT0(DFPREG(rs2));
2514 gen_op_store_DT0_fpr(DFPREG(rd));
2516 case 0x3: /* V9 fmovq */
2517 CHECK_FPU_FEATURE(dc, FLOAT128);
2518 gen_op_load_fpr_QT0(QFPREG(rs2));
2519 gen_op_store_QT0_fpr(QFPREG(rd));
2521 case 0x6: /* V9 fnegd */
2522 gen_op_load_fpr_DT1(DFPREG(rs2));
2523 tcg_gen_helper_0_0(helper_fnegd);
2524 gen_op_store_DT0_fpr(DFPREG(rd));
2526 case 0x7: /* V9 fnegq */
2527 CHECK_FPU_FEATURE(dc, FLOAT128);
2528 gen_op_load_fpr_QT1(QFPREG(rs2));
2529 tcg_gen_helper_0_0(helper_fnegq);
2530 gen_op_store_QT0_fpr(QFPREG(rd));
2532 case 0xa: /* V9 fabsd */
2533 gen_op_load_fpr_DT1(DFPREG(rs2));
2534 tcg_gen_helper_0_0(helper_fabsd);
2535 gen_op_store_DT0_fpr(DFPREG(rd));
2537 case 0xb: /* V9 fabsq */
2538 CHECK_FPU_FEATURE(dc, FLOAT128);
2539 gen_op_load_fpr_QT1(QFPREG(rs2));
2540 tcg_gen_helper_0_0(helper_fabsq);
2541 gen_op_store_QT0_fpr(QFPREG(rd));
2543 case 0x81: /* V9 fstox */
2544 gen_op_load_fpr_FT1(rs2);
2545 gen_clear_float_exceptions();
2546 tcg_gen_helper_0_0(helper_fstox);
2547 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2548 gen_op_store_DT0_fpr(DFPREG(rd));
2550 case 0x82: /* V9 fdtox */
2551 gen_op_load_fpr_DT1(DFPREG(rs2));
2552 gen_clear_float_exceptions();
2553 tcg_gen_helper_0_0(helper_fdtox);
2554 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2555 gen_op_store_DT0_fpr(DFPREG(rd));
2557 case 0x83: /* V9 fqtox */
2558 CHECK_FPU_FEATURE(dc, FLOAT128);
2559 gen_op_load_fpr_QT1(QFPREG(rs2));
2560 gen_clear_float_exceptions();
2561 tcg_gen_helper_0_0(helper_fqtox);
2562 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2563 gen_op_store_DT0_fpr(DFPREG(rd));
2565 case 0x84: /* V9 fxtos */
2566 gen_op_load_fpr_DT1(DFPREG(rs2));
2567 gen_clear_float_exceptions();
2568 tcg_gen_helper_0_0(helper_fxtos);
2569 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2570 gen_op_store_FT0_fpr(rd);
2572 case 0x88: /* V9 fxtod */
2573 gen_op_load_fpr_DT1(DFPREG(rs2));
2574 gen_clear_float_exceptions();
2575 tcg_gen_helper_0_0(helper_fxtod);
2576 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2577 gen_op_store_DT0_fpr(DFPREG(rd));
2579 case 0x8c: /* V9 fxtoq */
2580 CHECK_FPU_FEATURE(dc, FLOAT128);
2581 gen_op_load_fpr_DT1(DFPREG(rs2));
2582 gen_clear_float_exceptions();
2583 tcg_gen_helper_0_0(helper_fxtoq);
2584 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2585 gen_op_store_QT0_fpr(QFPREG(rd));
2591 } else if (xop == 0x35) { /* FPU Operations */
2592 #ifdef TARGET_SPARC64
2595 if (gen_trap_ifnofpu(dc, cpu_cond))
2597 gen_op_clear_ieee_excp_and_FTT();
2598 rs1 = GET_FIELD(insn, 13, 17);
2599 rs2 = GET_FIELD(insn, 27, 31);
2600 xop = GET_FIELD(insn, 18, 26);
2601 #ifdef TARGET_SPARC64
2602 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2605 l1 = gen_new_label();
2606 cond = GET_FIELD_SP(insn, 14, 17);
2607 cpu_src1 = get_src1(insn, cpu_src1);
2608 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2610 gen_op_load_fpr_FT0(rs2);
2611 gen_op_store_FT0_fpr(rd);
2614 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2617 l1 = gen_new_label();
2618 cond = GET_FIELD_SP(insn, 14, 17);
2619 cpu_src1 = get_src1(insn, cpu_src1);
2620 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2622 gen_op_load_fpr_DT0(DFPREG(rs2));
2623 gen_op_store_DT0_fpr(DFPREG(rd));
2626 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2629 CHECK_FPU_FEATURE(dc, FLOAT128);
2630 l1 = gen_new_label();
2631 cond = GET_FIELD_SP(insn, 14, 17);
2632 cpu_src1 = get_src1(insn, cpu_src1);
2633 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2635 gen_op_load_fpr_QT0(QFPREG(rs2));
2636 gen_op_store_QT0_fpr(QFPREG(rd));
2642 #ifdef TARGET_SPARC64
2643 #define FMOVCC(size_FDQ, fcc) \
2648 l1 = gen_new_label(); \
2649 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2650 cond = GET_FIELD_SP(insn, 14, 17); \
2651 gen_fcond(r_cond, fcc, cond); \
2652 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2654 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2655 (glue(size_FDQ, FPREG(rs2))); \
2656 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2657 (glue(size_FDQ, FPREG(rd))); \
2658 gen_set_label(l1); \
2660 case 0x001: /* V9 fmovscc %fcc0 */
2663 case 0x002: /* V9 fmovdcc %fcc0 */
2666 case 0x003: /* V9 fmovqcc %fcc0 */
2667 CHECK_FPU_FEATURE(dc, FLOAT128);
2670 case 0x041: /* V9 fmovscc %fcc1 */
2673 case 0x042: /* V9 fmovdcc %fcc1 */
2676 case 0x043: /* V9 fmovqcc %fcc1 */
2677 CHECK_FPU_FEATURE(dc, FLOAT128);
2680 case 0x081: /* V9 fmovscc %fcc2 */
2683 case 0x082: /* V9 fmovdcc %fcc2 */
2686 case 0x083: /* V9 fmovqcc %fcc2 */
2687 CHECK_FPU_FEATURE(dc, FLOAT128);
2690 case 0x0c1: /* V9 fmovscc %fcc3 */
2693 case 0x0c2: /* V9 fmovdcc %fcc3 */
2696 case 0x0c3: /* V9 fmovqcc %fcc3 */
2697 CHECK_FPU_FEATURE(dc, FLOAT128);
2701 #define FMOVCC(size_FDQ, icc) \
2706 l1 = gen_new_label(); \
2707 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2708 cond = GET_FIELD_SP(insn, 14, 17); \
2709 gen_cond(r_cond, icc, cond); \
2710 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2712 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2713 (glue(size_FDQ, FPREG(rs2))); \
2714 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2715 (glue(size_FDQ, FPREG(rd))); \
2716 gen_set_label(l1); \
2719 case 0x101: /* V9 fmovscc %icc */
2722 case 0x102: /* V9 fmovdcc %icc */
2724 case 0x103: /* V9 fmovqcc %icc */
2725 CHECK_FPU_FEATURE(dc, FLOAT128);
2728 case 0x181: /* V9 fmovscc %xcc */
2731 case 0x182: /* V9 fmovdcc %xcc */
2734 case 0x183: /* V9 fmovqcc %xcc */
2735 CHECK_FPU_FEATURE(dc, FLOAT128);
2740 case 0x51: /* fcmps, V9 %fcc */
2741 gen_op_load_fpr_FT0(rs1);
2742 gen_op_load_fpr_FT1(rs2);
2743 gen_op_fcmps(rd & 3);
2745 case 0x52: /* fcmpd, V9 %fcc */
2746 gen_op_load_fpr_DT0(DFPREG(rs1));
2747 gen_op_load_fpr_DT1(DFPREG(rs2));
2748 gen_op_fcmpd(rd & 3);
2750 case 0x53: /* fcmpq, V9 %fcc */
2751 CHECK_FPU_FEATURE(dc, FLOAT128);
2752 gen_op_load_fpr_QT0(QFPREG(rs1));
2753 gen_op_load_fpr_QT1(QFPREG(rs2));
2754 gen_op_fcmpq(rd & 3);
2756 case 0x55: /* fcmpes, V9 %fcc */
2757 gen_op_load_fpr_FT0(rs1);
2758 gen_op_load_fpr_FT1(rs2);
2759 gen_op_fcmpes(rd & 3);
2761 case 0x56: /* fcmped, V9 %fcc */
2762 gen_op_load_fpr_DT0(DFPREG(rs1));
2763 gen_op_load_fpr_DT1(DFPREG(rs2));
2764 gen_op_fcmped(rd & 3);
2766 case 0x57: /* fcmpeq, V9 %fcc */
2767 CHECK_FPU_FEATURE(dc, FLOAT128);
2768 gen_op_load_fpr_QT0(QFPREG(rs1));
2769 gen_op_load_fpr_QT1(QFPREG(rs2));
2770 gen_op_fcmpeq(rd & 3);
2775 } else if (xop == 0x2) {
2778 rs1 = GET_FIELD(insn, 13, 17);
2780 // or %g0, x, y -> mov T0, x; mov y, T0
2781 if (IS_IMM) { /* immediate */
2782 rs2 = GET_FIELDs(insn, 19, 31);
2783 gen_movl_TN_reg(rd, tcg_const_tl((int)rs2));
2784 } else { /* register */
2785 rs2 = GET_FIELD(insn, 27, 31);
2786 gen_movl_reg_TN(rs2, cpu_dst);
2787 gen_movl_TN_reg(rd, cpu_dst);
2790 cpu_src1 = get_src1(insn, cpu_src1);
2791 if (IS_IMM) { /* immediate */
2792 rs2 = GET_FIELDs(insn, 19, 31);
2793 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2794 gen_movl_TN_reg(rd, cpu_dst);
2795 } else { /* register */
2796 // or x, %g0, y -> mov T1, x; mov y, T1
2797 rs2 = GET_FIELD(insn, 27, 31);
2799 gen_movl_reg_TN(rs2, cpu_src2);
2800 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2801 gen_movl_TN_reg(rd, cpu_dst);
2803 gen_movl_TN_reg(rd, cpu_src1);
2806 #ifdef TARGET_SPARC64
2807 } else if (xop == 0x25) { /* sll, V9 sllx */
2808 cpu_src1 = get_src1(insn, cpu_src1);
2809 if (IS_IMM) { /* immediate */
2810 rs2 = GET_FIELDs(insn, 20, 31);
2811 if (insn & (1 << 12)) {
2812 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2814 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2815 tcg_gen_shli_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2817 } else { /* register */
2818 rs2 = GET_FIELD(insn, 27, 31);
2819 gen_movl_reg_TN(rs2, cpu_src2);
2820 if (insn & (1 << 12)) {
2821 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2822 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2824 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2825 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2826 tcg_gen_shl_i64(cpu_dst, cpu_dst, cpu_tmp0);
2829 gen_movl_TN_reg(rd, cpu_dst);
2830 } else if (xop == 0x26) { /* srl, V9 srlx */
2831 cpu_src1 = get_src1(insn, cpu_src1);
2832 if (IS_IMM) { /* immediate */
2833 rs2 = GET_FIELDs(insn, 20, 31);
2834 if (insn & (1 << 12)) {
2835 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2837 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2838 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2840 } else { /* register */
2841 rs2 = GET_FIELD(insn, 27, 31);
2842 gen_movl_reg_TN(rs2, cpu_src2);
2843 if (insn & (1 << 12)) {
2844 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2845 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2847 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2848 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2849 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2852 gen_movl_TN_reg(rd, cpu_dst);
2853 } else if (xop == 0x27) { /* sra, V9 srax */
2854 cpu_src1 = get_src1(insn, cpu_src1);
2855 if (IS_IMM) { /* immediate */
2856 rs2 = GET_FIELDs(insn, 20, 31);
2857 if (insn & (1 << 12)) {
2858 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2860 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2861 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2862 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2864 } else { /* register */
2865 rs2 = GET_FIELD(insn, 27, 31);
2866 gen_movl_reg_TN(rs2, cpu_src2);
2867 if (insn & (1 << 12)) {
2868 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2869 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2871 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2872 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2873 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2876 gen_movl_TN_reg(rd, cpu_dst);
2878 } else if (xop < 0x36) {
2879 cpu_src1 = get_src1(insn, cpu_src1);
2880 cpu_src2 = get_src2(insn, cpu_src2);
2882 switch (xop & ~0x10) {
2885 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2887 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2890 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
2892 gen_op_logic_cc(cpu_dst);
2895 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2897 gen_op_logic_cc(cpu_dst);
2900 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
2902 gen_op_logic_cc(cpu_dst);
2906 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
2908 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
2911 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2912 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
2914 gen_op_logic_cc(cpu_dst);
2917 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2918 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
2920 gen_op_logic_cc(cpu_dst);
2923 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2924 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
2926 gen_op_logic_cc(cpu_dst);
2930 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
2932 gen_mov_reg_C(cpu_tmp0, cpu_psr);
2933 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
2934 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
2937 #ifdef TARGET_SPARC64
2938 case 0x9: /* V9 mulx */
2939 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
2943 CHECK_IU_FEATURE(dc, MUL);
2944 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
2946 gen_op_logic_cc(cpu_dst);
2949 CHECK_IU_FEATURE(dc, MUL);
2950 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
2952 gen_op_logic_cc(cpu_dst);
2956 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
2958 gen_mov_reg_C(cpu_tmp0, cpu_psr);
2959 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
2960 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
2963 #ifdef TARGET_SPARC64
2964 case 0xd: /* V9 udivx */
2965 gen_trap_ifdivzero_tl(cpu_src2);
2966 tcg_gen_divu_i64(cpu_dst, cpu_src1, cpu_src2);
2970 CHECK_IU_FEATURE(dc, DIV);
2971 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1,
2974 gen_op_div_cc(cpu_dst);
2977 CHECK_IU_FEATURE(dc, DIV);
2978 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1,
2981 gen_op_div_cc(cpu_dst);
2986 gen_movl_TN_reg(rd, cpu_dst);
2989 case 0x20: /* taddcc */
2990 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
2991 gen_movl_TN_reg(rd, cpu_dst);
2993 case 0x21: /* tsubcc */
2994 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
2995 gen_movl_TN_reg(rd, cpu_dst);
2997 case 0x22: /* taddcctv */
2998 save_state(dc, cpu_cond);
2999 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3000 gen_movl_TN_reg(rd, cpu_dst);
3002 case 0x23: /* tsubcctv */
3003 save_state(dc, cpu_cond);
3004 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3005 gen_movl_TN_reg(rd, cpu_dst);
3007 case 0x24: /* mulscc */
3008 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3009 gen_movl_TN_reg(rd, cpu_dst);
3011 #ifndef TARGET_SPARC64
3012 case 0x25: /* sll */
3013 if (IS_IMM) { /* immediate */
3014 rs2 = GET_FIELDs(insn, 20, 31);
3015 tcg_gen_shli_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3016 } else { /* register */
3017 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3018 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3020 gen_movl_TN_reg(rd, cpu_dst);
3022 case 0x26: /* srl */
3023 if (IS_IMM) { /* immediate */
3024 rs2 = GET_FIELDs(insn, 20, 31);
3025 tcg_gen_shri_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3026 } else { /* register */
3027 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3028 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3030 gen_movl_TN_reg(rd, cpu_dst);
3032 case 0x27: /* sra */
3033 if (IS_IMM) { /* immediate */
3034 rs2 = GET_FIELDs(insn, 20, 31);
3035 tcg_gen_sari_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3036 } else { /* register */
3037 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3038 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3040 gen_movl_TN_reg(rd, cpu_dst);
3047 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3048 tcg_gen_st_tl(cpu_dst, cpu_env,
3049 offsetof(CPUSPARCState, y));
3051 #ifndef TARGET_SPARC64
3052 case 0x01 ... 0x0f: /* undefined in the
3056 case 0x10 ... 0x1f: /* implementation-dependent
3062 case 0x2: /* V9 wrccr */
3063 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3064 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3066 case 0x3: /* V9 wrasi */
3067 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3068 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3069 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3070 offsetof(CPUSPARCState, asi));
3072 case 0x6: /* V9 wrfprs */
3073 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3074 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3075 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3076 offsetof(CPUSPARCState, fprs));
3077 save_state(dc, cpu_cond);
3082 case 0xf: /* V9 sir, nop if user */
3083 #if !defined(CONFIG_USER_ONLY)
3088 case 0x13: /* Graphics Status */
3089 if (gen_trap_ifnofpu(dc, cpu_cond))
3091 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3092 tcg_gen_st_tl(cpu_dst, cpu_env,
3093 offsetof(CPUSPARCState, gsr));
3095 case 0x17: /* Tick compare */
3096 #if !defined(CONFIG_USER_ONLY)
3097 if (!supervisor(dc))
3103 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3105 tcg_gen_st_tl(cpu_dst, cpu_env,
3106 offsetof(CPUSPARCState,
3108 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3109 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3110 offsetof(CPUState, tick));
3111 tcg_gen_helper_0_2(helper_tick_set_limit,
3112 r_tickptr, cpu_dst);
3115 case 0x18: /* System tick */
3116 #if !defined(CONFIG_USER_ONLY)
3117 if (!supervisor(dc))
3123 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3125 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3126 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3127 offsetof(CPUState, stick));
3128 tcg_gen_helper_0_2(helper_tick_set_count,
3129 r_tickptr, cpu_dst);
3132 case 0x19: /* System tick compare */
3133 #if !defined(CONFIG_USER_ONLY)
3134 if (!supervisor(dc))
3140 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3142 tcg_gen_st_tl(cpu_dst, cpu_env,
3143 offsetof(CPUSPARCState,
3145 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3146 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3147 offsetof(CPUState, stick));
3148 tcg_gen_helper_0_2(helper_tick_set_limit,
3149 r_tickptr, cpu_dst);
3153 case 0x10: /* Performance Control */
3154 case 0x11: /* Performance Instrumentation
3156 case 0x12: /* Dispatch Control */
3157 case 0x14: /* Softint set */
3158 case 0x15: /* Softint clear */
3159 case 0x16: /* Softint write */
3166 #if !defined(CONFIG_USER_ONLY)
3167 case 0x31: /* wrpsr, V9 saved, restored */
3169 if (!supervisor(dc))
3171 #ifdef TARGET_SPARC64
3174 tcg_gen_helper_0_0(helper_saved);
3177 tcg_gen_helper_0_0(helper_restored);
3179 case 2: /* UA2005 allclean */
3180 case 3: /* UA2005 otherw */
3181 case 4: /* UA2005 normalw */
3182 case 5: /* UA2005 invalw */
3188 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3189 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3190 save_state(dc, cpu_cond);
3197 case 0x32: /* wrwim, V9 wrpr */
3199 if (!supervisor(dc))
3201 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3202 #ifdef TARGET_SPARC64
3208 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3209 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3210 offsetof(CPUState, tsptr));
3211 tcg_gen_st_tl(cpu_dst, r_tsptr,
3212 offsetof(trap_state, tpc));
3219 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3220 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3221 offsetof(CPUState, tsptr));
3222 tcg_gen_st_tl(cpu_dst, r_tsptr,
3223 offsetof(trap_state, tnpc));
3230 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3231 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3232 offsetof(CPUState, tsptr));
3233 tcg_gen_st_tl(cpu_dst, r_tsptr,
3234 offsetof(trap_state,
3242 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3243 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3244 offsetof(CPUState, tsptr));
3245 tcg_gen_st_i32(cpu_dst, r_tsptr,
3246 offsetof(trap_state, tt));
3253 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3254 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3255 offsetof(CPUState, tick));
3256 tcg_gen_helper_0_2(helper_tick_set_count,
3257 r_tickptr, cpu_dst);
3261 tcg_gen_st_tl(cpu_dst, cpu_env,
3262 offsetof(CPUSPARCState, tbr));
3265 save_state(dc, cpu_cond);
3266 tcg_gen_helper_0_1(helper_wrpstate, cpu_dst);
3272 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3273 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3274 offsetof(CPUSPARCState, tl));
3277 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3278 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3279 offsetof(CPUSPARCState,
3283 tcg_gen_helper_0_1(helper_wrcwp, cpu_dst);
3286 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3287 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3288 offsetof(CPUSPARCState,
3291 case 11: // canrestore
3292 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3293 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3294 offsetof(CPUSPARCState,
3297 case 12: // cleanwin
3298 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3299 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3300 offsetof(CPUSPARCState,
3303 case 13: // otherwin
3304 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3305 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3306 offsetof(CPUSPARCState,
3310 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3311 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3312 offsetof(CPUSPARCState,
3315 case 16: // UA2005 gl
3316 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3317 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3318 offsetof(CPUSPARCState, gl));
3320 case 26: // UA2005 strand status
3321 if (!hypervisor(dc))
3323 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3324 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3325 offsetof(CPUSPARCState, ssr));
3331 tcg_gen_andi_tl(cpu_dst, cpu_dst,
3332 ((1 << NWINDOWS) - 1));
3333 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3334 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3335 offsetof(CPUSPARCState, wim));
3339 case 0x33: /* wrtbr, UA2005 wrhpr */
3341 #ifndef TARGET_SPARC64
3342 if (!supervisor(dc))
3344 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3345 tcg_gen_st_tl(cpu_dst, cpu_env,
3346 offsetof(CPUSPARCState, tbr));
3348 if (!hypervisor(dc))
3350 tcg_gen_xor_tl(cpu_dst, cpu_dst, cpu_src2);
3353 // XXX gen_op_wrhpstate();
3354 save_state(dc, cpu_cond);
3360 // XXX gen_op_wrhtstate();
3363 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3364 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3365 offsetof(CPUSPARCState, hintp));
3368 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3369 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3370 offsetof(CPUSPARCState, htba));
3372 case 31: // hstick_cmpr
3376 tcg_gen_st_tl(cpu_dst, cpu_env,
3377 offsetof(CPUSPARCState,
3379 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3380 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3381 offsetof(CPUState, hstick));
3382 tcg_gen_helper_0_2(helper_tick_set_limit,
3383 r_tickptr, cpu_dst);
3386 case 6: // hver readonly
3394 #ifdef TARGET_SPARC64
3395 case 0x2c: /* V9 movcc */
3397 int cc = GET_FIELD_SP(insn, 11, 12);
3398 int cond = GET_FIELD_SP(insn, 14, 17);
3402 r_cond = tcg_temp_new(TCG_TYPE_TL);
3403 if (insn & (1 << 18)) {
3405 gen_cond(r_cond, 0, cond);
3407 gen_cond(r_cond, 1, cond);
3411 gen_fcond(r_cond, cc, cond);
3414 l1 = gen_new_label();
3416 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3417 if (IS_IMM) { /* immediate */
3418 rs2 = GET_FIELD_SPs(insn, 0, 10);
3419 gen_movl_TN_reg(rd, tcg_const_tl((int)rs2));
3421 rs2 = GET_FIELD_SP(insn, 0, 4);
3422 gen_movl_reg_TN(rs2, cpu_tmp0);
3423 gen_movl_TN_reg(rd, cpu_tmp0);
3428 case 0x2d: /* V9 sdivx */
3429 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3430 gen_movl_TN_reg(rd, cpu_dst);
3432 case 0x2e: /* V9 popc */
3434 cpu_src2 = get_src2(insn, cpu_src2);
3435 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3437 gen_movl_TN_reg(rd, cpu_dst);
3439 case 0x2f: /* V9 movr */
3441 int cond = GET_FIELD_SP(insn, 10, 12);
3444 cpu_src1 = get_src1(insn, cpu_src1);
3446 l1 = gen_new_label();
3448 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
3450 if (IS_IMM) { /* immediate */
3451 rs2 = GET_FIELD_SPs(insn, 0, 9);
3452 gen_movl_TN_reg(rd, tcg_const_tl((int)rs2));
3454 rs2 = GET_FIELD_SP(insn, 0, 4);
3455 gen_movl_reg_TN(rs2, cpu_tmp0);
3456 gen_movl_TN_reg(rd, cpu_tmp0);
3466 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3467 #ifdef TARGET_SPARC64
3468 int opf = GET_FIELD_SP(insn, 5, 13);
3469 rs1 = GET_FIELD(insn, 13, 17);
3470 rs2 = GET_FIELD(insn, 27, 31);
3471 if (gen_trap_ifnofpu(dc, cpu_cond))
3475 case 0x000: /* VIS I edge8cc */
3476 case 0x001: /* VIS II edge8n */
3477 case 0x002: /* VIS I edge8lcc */
3478 case 0x003: /* VIS II edge8ln */
3479 case 0x004: /* VIS I edge16cc */
3480 case 0x005: /* VIS II edge16n */
3481 case 0x006: /* VIS I edge16lcc */
3482 case 0x007: /* VIS II edge16ln */
3483 case 0x008: /* VIS I edge32cc */
3484 case 0x009: /* VIS II edge32n */
3485 case 0x00a: /* VIS I edge32lcc */
3486 case 0x00b: /* VIS II edge32ln */
3489 case 0x010: /* VIS I array8 */
3490 CHECK_FPU_FEATURE(dc, VIS1);
3491 cpu_src1 = get_src1(insn, cpu_src1);
3492 gen_movl_reg_TN(rs2, cpu_src2);
3493 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3495 gen_movl_TN_reg(rd, cpu_dst);
3497 case 0x012: /* VIS I array16 */
3498 CHECK_FPU_FEATURE(dc, VIS1);
3499 cpu_src1 = get_src1(insn, cpu_src1);
3500 gen_movl_reg_TN(rs2, cpu_src2);
3501 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3503 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3504 gen_movl_TN_reg(rd, cpu_dst);
3506 case 0x014: /* VIS I array32 */
3507 CHECK_FPU_FEATURE(dc, VIS1);
3508 cpu_src1 = get_src1(insn, cpu_src1);
3509 gen_movl_reg_TN(rs2, cpu_src2);
3510 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3512 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3513 gen_movl_TN_reg(rd, cpu_dst);
3515 case 0x018: /* VIS I alignaddr */
3516 CHECK_FPU_FEATURE(dc, VIS1);
3517 cpu_src1 = get_src1(insn, cpu_src1);
3518 gen_movl_reg_TN(rs2, cpu_src2);
3519 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3521 gen_movl_TN_reg(rd, cpu_dst);
3523 case 0x019: /* VIS II bmask */
3524 case 0x01a: /* VIS I alignaddrl */
3527 case 0x020: /* VIS I fcmple16 */
3528 CHECK_FPU_FEATURE(dc, VIS1);
3529 gen_op_load_fpr_DT0(DFPREG(rs1));
3530 gen_op_load_fpr_DT1(DFPREG(rs2));
3531 tcg_gen_helper_0_0(helper_fcmple16);
3532 gen_op_store_DT0_fpr(DFPREG(rd));
3534 case 0x022: /* VIS I fcmpne16 */
3535 CHECK_FPU_FEATURE(dc, VIS1);
3536 gen_op_load_fpr_DT0(DFPREG(rs1));
3537 gen_op_load_fpr_DT1(DFPREG(rs2));
3538 tcg_gen_helper_0_0(helper_fcmpne16);
3539 gen_op_store_DT0_fpr(DFPREG(rd));
3541 case 0x024: /* VIS I fcmple32 */
3542 CHECK_FPU_FEATURE(dc, VIS1);
3543 gen_op_load_fpr_DT0(DFPREG(rs1));
3544 gen_op_load_fpr_DT1(DFPREG(rs2));
3545 tcg_gen_helper_0_0(helper_fcmple32);
3546 gen_op_store_DT0_fpr(DFPREG(rd));
3548 case 0x026: /* VIS I fcmpne32 */
3549 CHECK_FPU_FEATURE(dc, VIS1);
3550 gen_op_load_fpr_DT0(DFPREG(rs1));
3551 gen_op_load_fpr_DT1(DFPREG(rs2));
3552 tcg_gen_helper_0_0(helper_fcmpne32);
3553 gen_op_store_DT0_fpr(DFPREG(rd));
3555 case 0x028: /* VIS I fcmpgt16 */
3556 CHECK_FPU_FEATURE(dc, VIS1);
3557 gen_op_load_fpr_DT0(DFPREG(rs1));
3558 gen_op_load_fpr_DT1(DFPREG(rs2));
3559 tcg_gen_helper_0_0(helper_fcmpgt16);
3560 gen_op_store_DT0_fpr(DFPREG(rd));
3562 case 0x02a: /* VIS I fcmpeq16 */
3563 CHECK_FPU_FEATURE(dc, VIS1);
3564 gen_op_load_fpr_DT0(DFPREG(rs1));
3565 gen_op_load_fpr_DT1(DFPREG(rs2));
3566 tcg_gen_helper_0_0(helper_fcmpeq16);
3567 gen_op_store_DT0_fpr(DFPREG(rd));
3569 case 0x02c: /* VIS I fcmpgt32 */
3570 CHECK_FPU_FEATURE(dc, VIS1);
3571 gen_op_load_fpr_DT0(DFPREG(rs1));
3572 gen_op_load_fpr_DT1(DFPREG(rs2));
3573 tcg_gen_helper_0_0(helper_fcmpgt32);
3574 gen_op_store_DT0_fpr(DFPREG(rd));
3576 case 0x02e: /* VIS I fcmpeq32 */
3577 CHECK_FPU_FEATURE(dc, VIS1);
3578 gen_op_load_fpr_DT0(DFPREG(rs1));
3579 gen_op_load_fpr_DT1(DFPREG(rs2));
3580 tcg_gen_helper_0_0(helper_fcmpeq32);
3581 gen_op_store_DT0_fpr(DFPREG(rd));
3583 case 0x031: /* VIS I fmul8x16 */
3584 CHECK_FPU_FEATURE(dc, VIS1);
3585 gen_op_load_fpr_DT0(DFPREG(rs1));
3586 gen_op_load_fpr_DT1(DFPREG(rs2));
3587 tcg_gen_helper_0_0(helper_fmul8x16);
3588 gen_op_store_DT0_fpr(DFPREG(rd));
3590 case 0x033: /* VIS I fmul8x16au */
3591 CHECK_FPU_FEATURE(dc, VIS1);
3592 gen_op_load_fpr_DT0(DFPREG(rs1));
3593 gen_op_load_fpr_DT1(DFPREG(rs2));
3594 tcg_gen_helper_0_0(helper_fmul8x16au);
3595 gen_op_store_DT0_fpr(DFPREG(rd));
3597 case 0x035: /* VIS I fmul8x16al */
3598 CHECK_FPU_FEATURE(dc, VIS1);
3599 gen_op_load_fpr_DT0(DFPREG(rs1));
3600 gen_op_load_fpr_DT1(DFPREG(rs2));
3601 tcg_gen_helper_0_0(helper_fmul8x16al);
3602 gen_op_store_DT0_fpr(DFPREG(rd));
3604 case 0x036: /* VIS I fmul8sux16 */
3605 CHECK_FPU_FEATURE(dc, VIS1);
3606 gen_op_load_fpr_DT0(DFPREG(rs1));
3607 gen_op_load_fpr_DT1(DFPREG(rs2));
3608 tcg_gen_helper_0_0(helper_fmul8sux16);
3609 gen_op_store_DT0_fpr(DFPREG(rd));
3611 case 0x037: /* VIS I fmul8ulx16 */
3612 CHECK_FPU_FEATURE(dc, VIS1);
3613 gen_op_load_fpr_DT0(DFPREG(rs1));
3614 gen_op_load_fpr_DT1(DFPREG(rs2));
3615 tcg_gen_helper_0_0(helper_fmul8ulx16);
3616 gen_op_store_DT0_fpr(DFPREG(rd));
3618 case 0x038: /* VIS I fmuld8sux16 */
3619 CHECK_FPU_FEATURE(dc, VIS1);
3620 gen_op_load_fpr_DT0(DFPREG(rs1));
3621 gen_op_load_fpr_DT1(DFPREG(rs2));
3622 tcg_gen_helper_0_0(helper_fmuld8sux16);
3623 gen_op_store_DT0_fpr(DFPREG(rd));
3625 case 0x039: /* VIS I fmuld8ulx16 */
3626 CHECK_FPU_FEATURE(dc, VIS1);
3627 gen_op_load_fpr_DT0(DFPREG(rs1));
3628 gen_op_load_fpr_DT1(DFPREG(rs2));
3629 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3630 gen_op_store_DT0_fpr(DFPREG(rd));
3632 case 0x03a: /* VIS I fpack32 */
3633 case 0x03b: /* VIS I fpack16 */
3634 case 0x03d: /* VIS I fpackfix */
3635 case 0x03e: /* VIS I pdist */
3638 case 0x048: /* VIS I faligndata */
3639 CHECK_FPU_FEATURE(dc, VIS1);
3640 gen_op_load_fpr_DT0(DFPREG(rs1));
3641 gen_op_load_fpr_DT1(DFPREG(rs2));
3642 tcg_gen_helper_0_0(helper_faligndata);
3643 gen_op_store_DT0_fpr(DFPREG(rd));
3645 case 0x04b: /* VIS I fpmerge */
3646 CHECK_FPU_FEATURE(dc, VIS1);
3647 gen_op_load_fpr_DT0(DFPREG(rs1));
3648 gen_op_load_fpr_DT1(DFPREG(rs2));
3649 tcg_gen_helper_0_0(helper_fpmerge);
3650 gen_op_store_DT0_fpr(DFPREG(rd));
3652 case 0x04c: /* VIS II bshuffle */
3655 case 0x04d: /* VIS I fexpand */
3656 CHECK_FPU_FEATURE(dc, VIS1);
3657 gen_op_load_fpr_DT0(DFPREG(rs1));
3658 gen_op_load_fpr_DT1(DFPREG(rs2));
3659 tcg_gen_helper_0_0(helper_fexpand);
3660 gen_op_store_DT0_fpr(DFPREG(rd));
3662 case 0x050: /* VIS I fpadd16 */
3663 CHECK_FPU_FEATURE(dc, VIS1);
3664 gen_op_load_fpr_DT0(DFPREG(rs1));
3665 gen_op_load_fpr_DT1(DFPREG(rs2));
3666 tcg_gen_helper_0_0(helper_fpadd16);
3667 gen_op_store_DT0_fpr(DFPREG(rd));
3669 case 0x051: /* VIS I fpadd16s */
3670 CHECK_FPU_FEATURE(dc, VIS1);
3671 gen_op_load_fpr_FT0(rs1);
3672 gen_op_load_fpr_FT1(rs2);
3673 tcg_gen_helper_0_0(helper_fpadd16s);
3674 gen_op_store_FT0_fpr(rd);
3676 case 0x052: /* VIS I fpadd32 */
3677 CHECK_FPU_FEATURE(dc, VIS1);
3678 gen_op_load_fpr_DT0(DFPREG(rs1));
3679 gen_op_load_fpr_DT1(DFPREG(rs2));
3680 tcg_gen_helper_0_0(helper_fpadd32);
3681 gen_op_store_DT0_fpr(DFPREG(rd));
3683 case 0x053: /* VIS I fpadd32s */
3684 CHECK_FPU_FEATURE(dc, VIS1);
3685 gen_op_load_fpr_FT0(rs1);
3686 gen_op_load_fpr_FT1(rs2);
3687 tcg_gen_helper_0_0(helper_fpadd32s);
3688 gen_op_store_FT0_fpr(rd);
3690 case 0x054: /* VIS I fpsub16 */
3691 CHECK_FPU_FEATURE(dc, VIS1);
3692 gen_op_load_fpr_DT0(DFPREG(rs1));
3693 gen_op_load_fpr_DT1(DFPREG(rs2));
3694 tcg_gen_helper_0_0(helper_fpsub16);
3695 gen_op_store_DT0_fpr(DFPREG(rd));
3697 case 0x055: /* VIS I fpsub16s */
3698 CHECK_FPU_FEATURE(dc, VIS1);
3699 gen_op_load_fpr_FT0(rs1);
3700 gen_op_load_fpr_FT1(rs2);
3701 tcg_gen_helper_0_0(helper_fpsub16s);
3702 gen_op_store_FT0_fpr(rd);
3704 case 0x056: /* VIS I fpsub32 */
3705 CHECK_FPU_FEATURE(dc, VIS1);
3706 gen_op_load_fpr_DT0(DFPREG(rs1));
3707 gen_op_load_fpr_DT1(DFPREG(rs2));
3708 tcg_gen_helper_0_0(helper_fpadd32);
3709 gen_op_store_DT0_fpr(DFPREG(rd));
3711 case 0x057: /* VIS I fpsub32s */
3712 CHECK_FPU_FEATURE(dc, VIS1);
3713 gen_op_load_fpr_FT0(rs1);
3714 gen_op_load_fpr_FT1(rs2);
3715 tcg_gen_helper_0_0(helper_fpsub32s);
3716 gen_op_store_FT0_fpr(rd);
3718 case 0x060: /* VIS I fzero */
3719 CHECK_FPU_FEATURE(dc, VIS1);
3720 tcg_gen_helper_0_0(helper_movl_DT0_0);
3721 gen_op_store_DT0_fpr(DFPREG(rd));
3723 case 0x061: /* VIS I fzeros */
3724 CHECK_FPU_FEATURE(dc, VIS1);
3725 tcg_gen_helper_0_0(helper_movl_FT0_0);
3726 gen_op_store_FT0_fpr(rd);
3728 case 0x062: /* VIS I fnor */
3729 CHECK_FPU_FEATURE(dc, VIS1);
3730 gen_op_load_fpr_DT0(DFPREG(rs1));
3731 gen_op_load_fpr_DT1(DFPREG(rs2));
3732 tcg_gen_helper_0_0(helper_fnor);
3733 gen_op_store_DT0_fpr(DFPREG(rd));
3735 case 0x063: /* VIS I fnors */
3736 CHECK_FPU_FEATURE(dc, VIS1);
3737 gen_op_load_fpr_FT0(rs1);
3738 gen_op_load_fpr_FT1(rs2);
3739 tcg_gen_helper_0_0(helper_fnors);
3740 gen_op_store_FT0_fpr(rd);
3742 case 0x064: /* VIS I fandnot2 */
3743 CHECK_FPU_FEATURE(dc, VIS1);
3744 gen_op_load_fpr_DT1(DFPREG(rs1));
3745 gen_op_load_fpr_DT0(DFPREG(rs2));
3746 tcg_gen_helper_0_0(helper_fandnot);
3747 gen_op_store_DT0_fpr(DFPREG(rd));
3749 case 0x065: /* VIS I fandnot2s */
3750 CHECK_FPU_FEATURE(dc, VIS1);
3751 gen_op_load_fpr_FT1(rs1);
3752 gen_op_load_fpr_FT0(rs2);
3753 tcg_gen_helper_0_0(helper_fandnots);
3754 gen_op_store_FT0_fpr(rd);
3756 case 0x066: /* VIS I fnot2 */
3757 CHECK_FPU_FEATURE(dc, VIS1);
3758 gen_op_load_fpr_DT1(DFPREG(rs2));
3759 tcg_gen_helper_0_0(helper_fnot);
3760 gen_op_store_DT0_fpr(DFPREG(rd));
3762 case 0x067: /* VIS I fnot2s */
3763 CHECK_FPU_FEATURE(dc, VIS1);
3764 gen_op_load_fpr_FT1(rs2);
3765 tcg_gen_helper_0_0(helper_fnot);
3766 gen_op_store_FT0_fpr(rd);
3768 case 0x068: /* VIS I fandnot1 */
3769 CHECK_FPU_FEATURE(dc, VIS1);
3770 gen_op_load_fpr_DT0(DFPREG(rs1));
3771 gen_op_load_fpr_DT1(DFPREG(rs2));
3772 tcg_gen_helper_0_0(helper_fandnot);
3773 gen_op_store_DT0_fpr(DFPREG(rd));
3775 case 0x069: /* VIS I fandnot1s */
3776 CHECK_FPU_FEATURE(dc, VIS1);
3777 gen_op_load_fpr_FT0(rs1);
3778 gen_op_load_fpr_FT1(rs2);
3779 tcg_gen_helper_0_0(helper_fandnots);
3780 gen_op_store_FT0_fpr(rd);
3782 case 0x06a: /* VIS I fnot1 */
3783 CHECK_FPU_FEATURE(dc, VIS1);
3784 gen_op_load_fpr_DT1(DFPREG(rs1));
3785 tcg_gen_helper_0_0(helper_fnot);
3786 gen_op_store_DT0_fpr(DFPREG(rd));
3788 case 0x06b: /* VIS I fnot1s */
3789 CHECK_FPU_FEATURE(dc, VIS1);
3790 gen_op_load_fpr_FT1(rs1);
3791 tcg_gen_helper_0_0(helper_fnot);
3792 gen_op_store_FT0_fpr(rd);
3794 case 0x06c: /* VIS I fxor */
3795 CHECK_FPU_FEATURE(dc, VIS1);
3796 gen_op_load_fpr_DT0(DFPREG(rs1));
3797 gen_op_load_fpr_DT1(DFPREG(rs2));
3798 tcg_gen_helper_0_0(helper_fxor);
3799 gen_op_store_DT0_fpr(DFPREG(rd));
3801 case 0x06d: /* VIS I fxors */
3802 CHECK_FPU_FEATURE(dc, VIS1);
3803 gen_op_load_fpr_FT0(rs1);
3804 gen_op_load_fpr_FT1(rs2);
3805 tcg_gen_helper_0_0(helper_fxors);
3806 gen_op_store_FT0_fpr(rd);
3808 case 0x06e: /* VIS I fnand */
3809 CHECK_FPU_FEATURE(dc, VIS1);
3810 gen_op_load_fpr_DT0(DFPREG(rs1));
3811 gen_op_load_fpr_DT1(DFPREG(rs2));
3812 tcg_gen_helper_0_0(helper_fnand);
3813 gen_op_store_DT0_fpr(DFPREG(rd));
3815 case 0x06f: /* VIS I fnands */
3816 CHECK_FPU_FEATURE(dc, VIS1);
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 CHECK_FPU_FEATURE(dc, VIS1);
3824 gen_op_load_fpr_DT0(DFPREG(rs1));
3825 gen_op_load_fpr_DT1(DFPREG(rs2));
3826 tcg_gen_helper_0_0(helper_fand);
3827 gen_op_store_DT0_fpr(DFPREG(rd));
3829 case 0x071: /* VIS I fands */
3830 CHECK_FPU_FEATURE(dc, VIS1);
3831 gen_op_load_fpr_FT0(rs1);
3832 gen_op_load_fpr_FT1(rs2);
3833 tcg_gen_helper_0_0(helper_fands);
3834 gen_op_store_FT0_fpr(rd);
3836 case 0x072: /* VIS I fxnor */
3837 CHECK_FPU_FEATURE(dc, VIS1);
3838 gen_op_load_fpr_DT0(DFPREG(rs1));
3839 gen_op_load_fpr_DT1(DFPREG(rs2));
3840 tcg_gen_helper_0_0(helper_fxnor);
3841 gen_op_store_DT0_fpr(DFPREG(rd));
3843 case 0x073: /* VIS I fxnors */
3844 CHECK_FPU_FEATURE(dc, VIS1);
3845 gen_op_load_fpr_FT0(rs1);
3846 gen_op_load_fpr_FT1(rs2);
3847 tcg_gen_helper_0_0(helper_fxnors);
3848 gen_op_store_FT0_fpr(rd);
3850 case 0x074: /* VIS I fsrc1 */
3851 CHECK_FPU_FEATURE(dc, VIS1);
3852 gen_op_load_fpr_DT0(DFPREG(rs1));
3853 gen_op_store_DT0_fpr(DFPREG(rd));
3855 case 0x075: /* VIS I fsrc1s */
3856 CHECK_FPU_FEATURE(dc, VIS1);
3857 gen_op_load_fpr_FT0(rs1);
3858 gen_op_store_FT0_fpr(rd);
3860 case 0x076: /* VIS I fornot2 */
3861 CHECK_FPU_FEATURE(dc, VIS1);
3862 gen_op_load_fpr_DT1(DFPREG(rs1));
3863 gen_op_load_fpr_DT0(DFPREG(rs2));
3864 tcg_gen_helper_0_0(helper_fornot);
3865 gen_op_store_DT0_fpr(DFPREG(rd));
3867 case 0x077: /* VIS I fornot2s */
3868 CHECK_FPU_FEATURE(dc, VIS1);
3869 gen_op_load_fpr_FT1(rs1);
3870 gen_op_load_fpr_FT0(rs2);
3871 tcg_gen_helper_0_0(helper_fornots);
3872 gen_op_store_FT0_fpr(rd);
3874 case 0x078: /* VIS I fsrc2 */
3875 CHECK_FPU_FEATURE(dc, VIS1);
3876 gen_op_load_fpr_DT0(DFPREG(rs2));
3877 gen_op_store_DT0_fpr(DFPREG(rd));
3879 case 0x079: /* VIS I fsrc2s */
3880 CHECK_FPU_FEATURE(dc, VIS1);
3881 gen_op_load_fpr_FT0(rs2);
3882 gen_op_store_FT0_fpr(rd);
3884 case 0x07a: /* VIS I fornot1 */
3885 CHECK_FPU_FEATURE(dc, VIS1);
3886 gen_op_load_fpr_DT0(DFPREG(rs1));
3887 gen_op_load_fpr_DT1(DFPREG(rs2));
3888 tcg_gen_helper_0_0(helper_fornot);
3889 gen_op_store_DT0_fpr(DFPREG(rd));
3891 case 0x07b: /* VIS I fornot1s */
3892 CHECK_FPU_FEATURE(dc, VIS1);
3893 gen_op_load_fpr_FT0(rs1);
3894 gen_op_load_fpr_FT1(rs2);
3895 tcg_gen_helper_0_0(helper_fornots);
3896 gen_op_store_FT0_fpr(rd);
3898 case 0x07c: /* VIS I for */
3899 CHECK_FPU_FEATURE(dc, VIS1);
3900 gen_op_load_fpr_DT0(DFPREG(rs1));
3901 gen_op_load_fpr_DT1(DFPREG(rs2));
3902 tcg_gen_helper_0_0(helper_for);
3903 gen_op_store_DT0_fpr(DFPREG(rd));
3905 case 0x07d: /* VIS I fors */
3906 CHECK_FPU_FEATURE(dc, VIS1);
3907 gen_op_load_fpr_FT0(rs1);
3908 gen_op_load_fpr_FT1(rs2);
3909 tcg_gen_helper_0_0(helper_fors);
3910 gen_op_store_FT0_fpr(rd);
3912 case 0x07e: /* VIS I fone */
3913 CHECK_FPU_FEATURE(dc, VIS1);
3914 tcg_gen_helper_0_0(helper_movl_DT0_1);
3915 gen_op_store_DT0_fpr(DFPREG(rd));
3917 case 0x07f: /* VIS I fones */
3918 CHECK_FPU_FEATURE(dc, VIS1);
3919 tcg_gen_helper_0_0(helper_movl_FT0_1);
3920 gen_op_store_FT0_fpr(rd);
3922 case 0x080: /* VIS I shutdown */
3923 case 0x081: /* VIS II siam */
3932 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
3933 #ifdef TARGET_SPARC64
3938 #ifdef TARGET_SPARC64
3939 } else if (xop == 0x39) { /* V9 return */
3940 save_state(dc, cpu_cond);
3941 cpu_src1 = get_src1(insn, cpu_src1);
3942 if (IS_IMM) { /* immediate */
3943 rs2 = GET_FIELDs(insn, 19, 31);
3944 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3945 } else { /* register */
3946 rs2 = GET_FIELD(insn, 27, 31);
3948 gen_movl_reg_TN(rs2, cpu_src2);
3949 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3951 tcg_gen_mov_tl(cpu_dst, cpu_src1);
3953 tcg_gen_helper_0_0(helper_restore);
3954 gen_mov_pc_npc(dc, cpu_cond);
3955 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
3957 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3958 dc->npc = DYNAMIC_PC;
3962 cpu_src1 = get_src1(insn, cpu_src1);
3963 if (IS_IMM) { /* immediate */
3964 rs2 = GET_FIELDs(insn, 19, 31);
3965 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
3966 } else { /* register */
3967 rs2 = GET_FIELD(insn, 27, 31);
3969 gen_movl_reg_TN(rs2, cpu_src2);
3970 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3972 tcg_gen_mov_tl(cpu_dst, cpu_src1);
3975 case 0x38: /* jmpl */
3977 gen_movl_TN_reg(rd, tcg_const_tl(dc->pc));
3978 gen_mov_pc_npc(dc, cpu_cond);
3979 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
3981 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3982 dc->npc = DYNAMIC_PC;
3985 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
3986 case 0x39: /* rett, V9 return */
3988 if (!supervisor(dc))
3990 gen_mov_pc_npc(dc, cpu_cond);
3991 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
3993 tcg_gen_mov_tl(cpu_npc, cpu_dst);
3994 dc->npc = DYNAMIC_PC;
3995 tcg_gen_helper_0_0(helper_rett);
3999 case 0x3b: /* flush */
4000 if (!((dc)->features & CPU_FEATURE_FLUSH))
4002 tcg_gen_helper_0_1(helper_flush, cpu_dst);
4004 case 0x3c: /* save */
4005 save_state(dc, cpu_cond);
4006 tcg_gen_helper_0_0(helper_save);
4007 gen_movl_TN_reg(rd, cpu_dst);
4009 case 0x3d: /* restore */
4010 save_state(dc, cpu_cond);
4011 tcg_gen_helper_0_0(helper_restore);
4012 gen_movl_TN_reg(rd, cpu_dst);
4014 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4015 case 0x3e: /* V9 done/retry */
4019 if (!supervisor(dc))
4021 dc->npc = DYNAMIC_PC;
4022 dc->pc = DYNAMIC_PC;
4023 tcg_gen_helper_0_0(helper_done);
4026 if (!supervisor(dc))
4028 dc->npc = DYNAMIC_PC;
4029 dc->pc = DYNAMIC_PC;
4030 tcg_gen_helper_0_0(helper_retry);
4045 case 3: /* load/store instructions */
4047 unsigned int xop = GET_FIELD(insn, 7, 12);
4049 cpu_src1 = get_src1(insn, cpu_src1);
4050 if (xop == 0x3c || xop == 0x3e)
4052 rs2 = GET_FIELD(insn, 27, 31);
4053 gen_movl_reg_TN(rs2, cpu_src2);
4055 else if (IS_IMM) { /* immediate */
4056 rs2 = GET_FIELDs(insn, 19, 31);
4057 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4058 } else { /* register */
4059 rs2 = GET_FIELD(insn, 27, 31);
4061 gen_movl_reg_TN(rs2, cpu_src2);
4062 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4064 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4066 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4067 (xop > 0x17 && xop <= 0x1d ) ||
4068 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4070 case 0x0: /* load unsigned word */
4071 ABI32_MASK(cpu_addr);
4072 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4074 case 0x1: /* load unsigned byte */
4075 ABI32_MASK(cpu_addr);
4076 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4078 case 0x2: /* load unsigned halfword */
4079 ABI32_MASK(cpu_addr);
4080 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4082 case 0x3: /* load double word */
4086 save_state(dc, cpu_cond);
4087 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4088 tcg_const_i32(7)); // XXX remove
4089 ABI32_MASK(cpu_addr);
4090 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4091 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4092 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4093 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4094 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4095 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4096 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4099 case 0x9: /* load signed byte */
4100 ABI32_MASK(cpu_addr);
4101 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4103 case 0xa: /* load signed halfword */
4104 ABI32_MASK(cpu_addr);
4105 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4107 case 0xd: /* ldstub -- XXX: should be atomically */
4108 ABI32_MASK(cpu_addr);
4109 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4110 tcg_gen_qemu_st8(tcg_const_tl(0xff), cpu_addr,
4113 case 0x0f: /* swap register with memory. Also
4115 CHECK_IU_FEATURE(dc, SWAP);
4116 gen_movl_reg_TN(rd, cpu_val);
4117 ABI32_MASK(cpu_addr);
4118 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4119 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4120 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4122 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4123 case 0x10: /* load word alternate */
4124 #ifndef TARGET_SPARC64
4127 if (!supervisor(dc))
4130 save_state(dc, cpu_cond);
4131 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4133 case 0x11: /* load unsigned byte alternate */
4134 #ifndef TARGET_SPARC64
4137 if (!supervisor(dc))
4140 save_state(dc, cpu_cond);
4141 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4143 case 0x12: /* load unsigned halfword alternate */
4144 #ifndef TARGET_SPARC64
4147 if (!supervisor(dc))
4150 save_state(dc, cpu_cond);
4151 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4153 case 0x13: /* load double word alternate */
4154 #ifndef TARGET_SPARC64
4157 if (!supervisor(dc))
4162 save_state(dc, cpu_cond);
4163 gen_ldda_asi(cpu_tmp0, cpu_val, cpu_addr, insn);
4164 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4166 case 0x19: /* load signed byte alternate */
4167 #ifndef TARGET_SPARC64
4170 if (!supervisor(dc))
4173 save_state(dc, cpu_cond);
4174 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4176 case 0x1a: /* load signed halfword alternate */
4177 #ifndef TARGET_SPARC64
4180 if (!supervisor(dc))
4183 save_state(dc, cpu_cond);
4184 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4186 case 0x1d: /* ldstuba -- XXX: should be atomically */
4187 #ifndef TARGET_SPARC64
4190 if (!supervisor(dc))
4193 save_state(dc, cpu_cond);
4194 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4196 case 0x1f: /* swap reg with alt. memory. Also
4198 CHECK_IU_FEATURE(dc, SWAP);
4199 #ifndef TARGET_SPARC64
4202 if (!supervisor(dc))
4205 save_state(dc, cpu_cond);
4206 gen_movl_reg_TN(rd, cpu_val);
4207 gen_swap_asi(cpu_val, cpu_addr, insn);
4210 #ifndef TARGET_SPARC64
4211 case 0x30: /* ldc */
4212 case 0x31: /* ldcsr */
4213 case 0x33: /* lddc */
4217 #ifdef TARGET_SPARC64
4218 case 0x08: /* V9 ldsw */
4219 ABI32_MASK(cpu_addr);
4220 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4222 case 0x0b: /* V9 ldx */
4223 ABI32_MASK(cpu_addr);
4224 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4226 case 0x18: /* V9 ldswa */
4227 save_state(dc, cpu_cond);
4228 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4230 case 0x1b: /* V9 ldxa */
4231 save_state(dc, cpu_cond);
4232 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4234 case 0x2d: /* V9 prefetch, no effect */
4236 case 0x30: /* V9 ldfa */
4237 save_state(dc, cpu_cond);
4238 gen_ldf_asi(cpu_addr, insn, 4, rd);
4240 case 0x33: /* V9 lddfa */
4241 save_state(dc, cpu_cond);
4242 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4244 case 0x3d: /* V9 prefetcha, no effect */
4246 case 0x32: /* V9 ldqfa */
4247 CHECK_FPU_FEATURE(dc, FLOAT128);
4248 save_state(dc, cpu_cond);
4249 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4255 gen_movl_TN_reg(rd, cpu_val);
4256 #ifdef TARGET_SPARC64
4259 } else if (xop >= 0x20 && xop < 0x24) {
4260 if (gen_trap_ifnofpu(dc, cpu_cond))
4262 save_state(dc, cpu_cond);
4264 case 0x20: /* load fpreg */
4265 ABI32_MASK(cpu_addr);
4266 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4267 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4268 offsetof(CPUState, fpr[rd]));
4270 case 0x21: /* load fsr */
4271 ABI32_MASK(cpu_addr);
4272 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4273 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4274 offsetof(CPUState, ft0));
4275 tcg_gen_helper_0_0(helper_ldfsr);
4277 case 0x22: /* load quad fpreg */
4278 CHECK_FPU_FEATURE(dc, FLOAT128);
4279 tcg_gen_helper_0_2(helper_ldqf, cpu_addr,
4280 tcg_const_i32(dc->mem_idx));
4281 gen_op_store_QT0_fpr(QFPREG(rd));
4283 case 0x23: /* load double fpreg */
4284 tcg_gen_helper_0_2(helper_lddf, cpu_addr,
4285 tcg_const_i32(dc->mem_idx));
4286 gen_op_store_DT0_fpr(DFPREG(rd));
4291 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4292 xop == 0xe || xop == 0x1e) {
4293 gen_movl_reg_TN(rd, cpu_val);
4295 case 0x4: /* store word */
4296 ABI32_MASK(cpu_addr);
4297 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4299 case 0x5: /* store byte */
4300 ABI32_MASK(cpu_addr);
4301 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4303 case 0x6: /* store halfword */
4304 ABI32_MASK(cpu_addr);
4305 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4307 case 0x7: /* store double word */
4313 save_state(dc, cpu_cond);
4314 ABI32_MASK(cpu_addr);
4315 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4316 tcg_const_i32(7)); // XXX remove
4317 r_low = tcg_temp_new(TCG_TYPE_I32);
4318 gen_movl_reg_TN(rd + 1, r_low);
4319 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4321 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4324 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4325 case 0x14: /* store word alternate */
4326 #ifndef TARGET_SPARC64
4329 if (!supervisor(dc))
4332 save_state(dc, cpu_cond);
4333 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4335 case 0x15: /* store byte alternate */
4336 #ifndef TARGET_SPARC64
4339 if (!supervisor(dc))
4342 save_state(dc, cpu_cond);
4343 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4345 case 0x16: /* store halfword alternate */
4346 #ifndef TARGET_SPARC64
4349 if (!supervisor(dc))
4352 save_state(dc, cpu_cond);
4353 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4355 case 0x17: /* store double word alternate */
4356 #ifndef TARGET_SPARC64
4359 if (!supervisor(dc))
4365 save_state(dc, cpu_cond);
4366 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4370 #ifdef TARGET_SPARC64
4371 case 0x0e: /* V9 stx */
4372 ABI32_MASK(cpu_addr);
4373 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4375 case 0x1e: /* V9 stxa */
4376 save_state(dc, cpu_cond);
4377 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4383 } else if (xop > 0x23 && xop < 0x28) {
4384 if (gen_trap_ifnofpu(dc, cpu_cond))
4386 save_state(dc, cpu_cond);
4388 case 0x24: /* store fpreg */
4389 ABI32_MASK(cpu_addr);
4390 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4391 offsetof(CPUState, fpr[rd]));
4392 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4394 case 0x25: /* stfsr, V9 stxfsr */
4395 ABI32_MASK(cpu_addr);
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 /* V9 stqf, store quad fpreg */
4404 CHECK_FPU_FEATURE(dc, FLOAT128);
4405 gen_op_load_fpr_QT0(QFPREG(rd));
4406 tcg_gen_helper_0_2(helper_stqf, cpu_addr,
4407 tcg_const_i32(dc->mem_idx));
4409 #else /* !TARGET_SPARC64 */
4410 /* stdfq, store floating point queue */
4411 #if defined(CONFIG_USER_ONLY)
4414 if (!supervisor(dc))
4416 if (gen_trap_ifnofpu(dc, cpu_cond))
4421 case 0x27: /* store double fpreg */
4422 gen_op_load_fpr_DT0(DFPREG(rd));
4423 tcg_gen_helper_0_2(helper_stdf, cpu_addr,
4424 tcg_const_i32(dc->mem_idx));
4429 } else if (xop > 0x33 && xop < 0x3f) {
4430 save_state(dc, cpu_cond);
4432 #ifdef TARGET_SPARC64
4433 case 0x34: /* V9 stfa */
4434 gen_op_load_fpr_FT0(rd);
4435 gen_stf_asi(cpu_addr, insn, 4, rd);
4437 case 0x36: /* V9 stqfa */
4438 CHECK_FPU_FEATURE(dc, FLOAT128);
4439 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4441 gen_op_load_fpr_QT0(QFPREG(rd));
4442 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4444 case 0x37: /* V9 stdfa */
4445 gen_op_load_fpr_DT0(DFPREG(rd));
4446 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4448 case 0x3c: /* V9 casa */
4449 gen_cas_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4450 gen_movl_TN_reg(rd, cpu_val);
4452 case 0x3e: /* V9 casxa */
4453 gen_casx_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4454 gen_movl_TN_reg(rd, cpu_val);
4457 case 0x34: /* stc */
4458 case 0x35: /* stcsr */
4459 case 0x36: /* stdcq */
4460 case 0x37: /* stdc */
4472 /* default case for non jump instructions */
4473 if (dc->npc == DYNAMIC_PC) {
4474 dc->pc = DYNAMIC_PC;
4476 } else if (dc->npc == JUMP_PC) {
4477 /* we can do a static jump */
4478 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4482 dc->npc = dc->npc + 4;
4487 save_state(dc, cpu_cond);
4488 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_ILL_INSN));
4492 save_state(dc, cpu_cond);
4493 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_UNIMP_FLUSH));
4496 #if !defined(CONFIG_USER_ONLY)
4498 save_state(dc, cpu_cond);
4499 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_PRIV_INSN));
4504 save_state(dc, cpu_cond);
4505 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4508 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4510 save_state(dc, cpu_cond);
4511 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4515 #ifndef TARGET_SPARC64
4517 save_state(dc, cpu_cond);
4518 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NCP_INSN));
4524 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4525 int spc, CPUSPARCState *env)
4527 target_ulong pc_start, last_pc;
4528 uint16_t *gen_opc_end;
4529 DisasContext dc1, *dc = &dc1;
4532 memset(dc, 0, sizeof(DisasContext));
4537 dc->npc = (target_ulong) tb->cs_base;
4538 dc->mem_idx = cpu_mmu_index(env);
4539 dc->features = env->features;
4540 if ((dc->features & CPU_FEATURE_FLOAT)) {
4541 dc->fpu_enabled = cpu_fpu_enabled(env);
4542 #if defined(CONFIG_USER_ONLY)
4543 dc->features |= CPU_FEATURE_FLOAT128;
4546 dc->fpu_enabled = 0;
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);
4554 if (env->nb_breakpoints > 0) {
4555 for(j = 0; j < env->nb_breakpoints; j++) {
4556 if (env->breakpoints[j] == dc->pc) {
4557 if (dc->pc != pc_start)
4558 save_state(dc, cpu_cond);
4559 tcg_gen_helper_0_0(helper_debug);
4568 fprintf(logfile, "Search PC...\n");
4569 j = gen_opc_ptr - gen_opc_buf;
4573 gen_opc_instr_start[lj++] = 0;
4574 gen_opc_pc[lj] = dc->pc;
4575 gen_opc_npc[lj] = dc->npc;
4576 gen_opc_instr_start[lj] = 1;
4580 disas_sparc_insn(dc);
4584 /* if the next PC is different, we abort now */
4585 if (dc->pc != (last_pc + 4))
4587 /* if we reach a page boundary, we stop generation so that the
4588 PC of a TT_TFAULT exception is always in the right page */
4589 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4591 /* if single step mode, we generate only one instruction and
4592 generate an exception */
4593 if (env->singlestep_enabled) {
4594 tcg_gen_movi_tl(cpu_pc, dc->pc);
4598 } while ((gen_opc_ptr < gen_opc_end) &&
4599 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
4603 if (dc->pc != DYNAMIC_PC &&
4604 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4605 /* static PC and NPC: we can use direct chaining */
4606 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4608 if (dc->pc != DYNAMIC_PC)
4609 tcg_gen_movi_tl(cpu_pc, dc->pc);
4610 save_npc(dc, cpu_cond);
4614 *gen_opc_ptr = INDEX_op_end;
4616 j = gen_opc_ptr - gen_opc_buf;
4619 gen_opc_instr_start[lj++] = 0;
4625 gen_opc_jump_pc[0] = dc->jump_pc[0];
4626 gen_opc_jump_pc[1] = dc->jump_pc[1];
4628 tb->size = last_pc + 4 - pc_start;
4631 if (loglevel & CPU_LOG_TB_IN_ASM) {
4632 fprintf(logfile, "--------------\n");
4633 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4634 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4635 fprintf(logfile, "\n");
4641 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4643 return gen_intermediate_code_internal(tb, 0, env);
4646 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4648 return gen_intermediate_code_internal(tb, 1, env);
4651 void gen_intermediate_code_init(CPUSPARCState *env)
4655 static const char * const gregnames[8] = {
4656 NULL, // g0 not used
4666 /* init various static tables */
4670 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4671 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4672 offsetof(CPUState, regwptr),
4674 #ifdef TARGET_SPARC64
4675 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4676 TCG_AREG0, offsetof(CPUState, xcc),
4679 /* XXX: T0 and T1 should be temporaries */
4680 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
4681 TCG_AREG0, offsetof(CPUState, t0), "T0");
4682 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
4683 TCG_AREG0, offsetof(CPUState, t1), "T1");
4684 cpu_cond = tcg_global_mem_new(TCG_TYPE_TL,
4685 TCG_AREG0, offsetof(CPUState, cond),
4687 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4688 TCG_AREG0, offsetof(CPUState, cc_src),
4690 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4691 offsetof(CPUState, cc_src2),
4693 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4694 TCG_AREG0, offsetof(CPUState, cc_dst),
4696 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4697 TCG_AREG0, offsetof(CPUState, psr),
4699 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4700 TCG_AREG0, offsetof(CPUState, fsr),
4702 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4703 TCG_AREG0, offsetof(CPUState, pc),
4705 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4706 TCG_AREG0, offsetof(CPUState, npc),
4708 for (i = 1; i < 8; i++)
4709 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4710 offsetof(CPUState, gregs[i]),
4712 /* register helpers */
4715 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
4720 void gen_pc_load(CPUState *env, TranslationBlock *tb,
4721 unsigned long searched_pc, int pc_pos, void *puc)
4724 env->pc = gen_opc_pc[pc_pos];
4725 npc = gen_opc_npc[pc_pos];
4727 /* dynamic NPC: already stored */
4728 } else if (npc == 2) {
4729 target_ulong t2 = (target_ulong)(unsigned long)puc;
4730 /* jump PC: use T2 and the jump targets of the translation */
4732 env->npc = gen_opc_jump_pc[0];
4734 env->npc = gen_opc_jump_pc[1];