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_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 #include "gen-icount.h"
53 typedef struct DisasContext {
54 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
55 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
56 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
60 struct TranslationBlock *tb;
64 // This function uses non-native bit order
65 #define GET_FIELD(X, FROM, TO) \
66 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
68 // This function uses the order in the manuals, i.e. bit 0 is 2^0
69 #define GET_FIELD_SP(X, FROM, TO) \
70 GET_FIELD(X, 31 - (TO), 31 - (FROM))
72 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
73 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
77 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
78 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
81 #define DFPREG(r) (r & 0x1e)
82 #define QFPREG(r) (r & 0x1c)
85 static int sign_extend(int x, int len)
88 return (x << len) >> len;
91 #define IS_IMM (insn & (1<<13))
93 /* floating point registers moves */
94 static void gen_op_load_fpr_FT0(unsigned int src)
96 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
97 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
100 static void gen_op_load_fpr_FT1(unsigned int src)
102 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
103 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
106 static void gen_op_store_FT0_fpr(unsigned int dst)
108 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
109 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
112 static void gen_op_load_fpr_DT0(unsigned int src)
114 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
115 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
116 offsetof(CPU_DoubleU, l.upper));
117 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
118 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
119 offsetof(CPU_DoubleU, l.lower));
122 static void gen_op_load_fpr_DT1(unsigned int src)
124 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
125 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
126 offsetof(CPU_DoubleU, l.upper));
127 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
128 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
129 offsetof(CPU_DoubleU, l.lower));
132 static void gen_op_store_DT0_fpr(unsigned int dst)
134 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
135 offsetof(CPU_DoubleU, l.upper));
136 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
137 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
138 offsetof(CPU_DoubleU, l.lower));
139 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
142 static void gen_op_load_fpr_QT0(unsigned int src)
144 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
145 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
146 offsetof(CPU_QuadU, l.upmost));
147 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
148 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
149 offsetof(CPU_QuadU, l.upper));
150 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
151 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
152 offsetof(CPU_QuadU, l.lower));
153 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
154 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
155 offsetof(CPU_QuadU, l.lowest));
158 static void gen_op_load_fpr_QT1(unsigned int src)
160 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
161 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
162 offsetof(CPU_QuadU, l.upmost));
163 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
164 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
165 offsetof(CPU_QuadU, l.upper));
166 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
167 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
168 offsetof(CPU_QuadU, l.lower));
169 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
170 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
171 offsetof(CPU_QuadU, l.lowest));
174 static void gen_op_store_QT0_fpr(unsigned int dst)
176 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
177 offsetof(CPU_QuadU, l.upmost));
178 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
179 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
180 offsetof(CPU_QuadU, l.upper));
181 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
182 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
183 offsetof(CPU_QuadU, l.lower));
184 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
185 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
186 offsetof(CPU_QuadU, l.lowest));
187 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
191 #ifdef CONFIG_USER_ONLY
192 #define supervisor(dc) 0
193 #ifdef TARGET_SPARC64
194 #define hypervisor(dc) 0
197 #define supervisor(dc) (dc->mem_idx >= 1)
198 #ifdef TARGET_SPARC64
199 #define hypervisor(dc) (dc->mem_idx == 2)
205 #define ABI32_MASK(addr) tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
207 #define ABI32_MASK(addr)
210 static inline void gen_movl_reg_TN(int reg, TCGv tn)
213 tcg_gen_movi_tl(tn, 0);
215 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
217 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
221 static inline void gen_movl_TN_reg(int reg, TCGv tn)
226 tcg_gen_mov_tl(cpu_gregs[reg], tn);
228 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
232 static inline void gen_goto_tb(DisasContext *s, int tb_num,
233 target_ulong pc, target_ulong npc)
235 TranslationBlock *tb;
238 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
239 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
240 /* jump to same page: we can use a direct jump */
241 tcg_gen_goto_tb(tb_num);
242 tcg_gen_movi_tl(cpu_pc, pc);
243 tcg_gen_movi_tl(cpu_npc, npc);
244 tcg_gen_exit_tb((long)tb + tb_num);
246 /* jump to another page: currently not optimized */
247 tcg_gen_movi_tl(cpu_pc, pc);
248 tcg_gen_movi_tl(cpu_npc, npc);
254 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
256 tcg_gen_extu_i32_tl(reg, src);
257 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
258 tcg_gen_andi_tl(reg, reg, 0x1);
261 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
263 tcg_gen_extu_i32_tl(reg, src);
264 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
265 tcg_gen_andi_tl(reg, reg, 0x1);
268 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
270 tcg_gen_extu_i32_tl(reg, src);
271 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
272 tcg_gen_andi_tl(reg, reg, 0x1);
275 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
277 tcg_gen_extu_i32_tl(reg, src);
278 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
279 tcg_gen_andi_tl(reg, reg, 0x1);
282 static inline void gen_cc_clear_icc(void)
284 tcg_gen_movi_i32(cpu_psr, 0);
287 #ifdef TARGET_SPARC64
288 static inline void gen_cc_clear_xcc(void)
290 tcg_gen_movi_i32(cpu_xcc, 0);
296 env->psr |= PSR_ZERO;
297 if ((int32_t) T0 < 0)
300 static inline void gen_cc_NZ_icc(TCGv dst)
305 l1 = gen_new_label();
306 l2 = gen_new_label();
307 r_temp = tcg_temp_new(TCG_TYPE_TL);
308 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
309 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
310 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
312 tcg_gen_ext_i32_tl(r_temp, dst);
313 tcg_gen_brcondi_tl(TCG_COND_GE, r_temp, 0, l2);
314 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
316 tcg_temp_free(r_temp);
319 #ifdef TARGET_SPARC64
320 static inline void gen_cc_NZ_xcc(TCGv dst)
324 l1 = gen_new_label();
325 l2 = gen_new_label();
326 tcg_gen_brcondi_tl(TCG_COND_NE, dst, 0, l1);
327 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
329 tcg_gen_brcondi_tl(TCG_COND_GE, dst, 0, l2);
330 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
337 env->psr |= PSR_CARRY;
339 static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
344 l1 = gen_new_label();
345 r_temp = tcg_temp_new(TCG_TYPE_TL);
346 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
347 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
348 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
350 tcg_temp_free(r_temp);
353 #ifdef TARGET_SPARC64
354 static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
358 l1 = gen_new_label();
359 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
360 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
366 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
369 static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
373 r_temp = tcg_temp_new(TCG_TYPE_TL);
374 tcg_gen_xor_tl(r_temp, src1, src2);
375 tcg_gen_xori_tl(r_temp, r_temp, -1);
376 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
377 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
378 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
379 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
380 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
381 tcg_temp_free(r_temp);
382 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
385 #ifdef TARGET_SPARC64
386 static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
390 r_temp = tcg_temp_new(TCG_TYPE_TL);
391 tcg_gen_xor_tl(r_temp, src1, src2);
392 tcg_gen_xori_tl(r_temp, r_temp, -1);
393 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
394 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
395 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
396 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
397 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
398 tcg_temp_free(r_temp);
399 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
403 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
405 TCGv r_temp, r_const;
408 l1 = gen_new_label();
410 r_temp = tcg_temp_new(TCG_TYPE_TL);
411 tcg_gen_xor_tl(r_temp, src1, src2);
412 tcg_gen_xori_tl(r_temp, r_temp, -1);
413 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
414 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
415 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
416 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
417 r_const = tcg_const_i32(TT_TOVF);
418 tcg_gen_helper_0_1(raise_exception, r_const);
419 tcg_temp_free(r_const);
421 tcg_temp_free(r_temp);
424 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
428 l1 = gen_new_label();
429 tcg_gen_or_tl(cpu_tmp0, src1, src2);
430 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
431 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
432 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
436 static inline void gen_tag_tv(TCGv src1, TCGv src2)
441 l1 = gen_new_label();
442 tcg_gen_or_tl(cpu_tmp0, src1, src2);
443 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
444 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
445 r_const = tcg_const_i32(TT_TOVF);
446 tcg_gen_helper_0_1(raise_exception, r_const);
447 tcg_temp_free(r_const);
451 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
453 tcg_gen_mov_tl(cpu_cc_src, src1);
454 tcg_gen_mov_tl(cpu_cc_src2, src2);
455 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
457 gen_cc_NZ_icc(cpu_cc_dst);
458 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
459 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
460 #ifdef TARGET_SPARC64
462 gen_cc_NZ_xcc(cpu_cc_dst);
463 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
464 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
466 tcg_gen_mov_tl(dst, cpu_cc_dst);
469 static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
471 tcg_gen_mov_tl(cpu_cc_src, src1);
472 tcg_gen_mov_tl(cpu_cc_src2, src2);
473 gen_mov_reg_C(cpu_tmp0, cpu_psr);
474 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
476 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
477 #ifdef TARGET_SPARC64
479 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
481 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
482 gen_cc_NZ_icc(cpu_cc_dst);
483 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
484 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
485 #ifdef TARGET_SPARC64
486 gen_cc_NZ_xcc(cpu_cc_dst);
487 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
488 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
490 tcg_gen_mov_tl(dst, cpu_cc_dst);
493 static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
495 tcg_gen_mov_tl(cpu_cc_src, src1);
496 tcg_gen_mov_tl(cpu_cc_src2, src2);
497 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
499 gen_cc_NZ_icc(cpu_cc_dst);
500 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
501 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
502 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
503 #ifdef TARGET_SPARC64
505 gen_cc_NZ_xcc(cpu_cc_dst);
506 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
507 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
509 tcg_gen_mov_tl(dst, cpu_cc_dst);
512 static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
514 tcg_gen_mov_tl(cpu_cc_src, src1);
515 tcg_gen_mov_tl(cpu_cc_src2, src2);
516 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
517 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
518 gen_add_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
520 gen_cc_NZ_icc(cpu_cc_dst);
521 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
522 #ifdef TARGET_SPARC64
524 gen_cc_NZ_xcc(cpu_cc_dst);
525 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
526 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
528 tcg_gen_mov_tl(dst, cpu_cc_dst);
533 env->psr |= PSR_CARRY;
535 static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
537 TCGv r_temp1, r_temp2;
540 l1 = gen_new_label();
541 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
542 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
543 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
544 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
545 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
546 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
548 tcg_temp_free(r_temp1);
549 tcg_temp_free(r_temp2);
552 #ifdef TARGET_SPARC64
553 static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
557 l1 = gen_new_label();
558 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
559 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
565 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
568 static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
572 r_temp = tcg_temp_new(TCG_TYPE_TL);
573 tcg_gen_xor_tl(r_temp, src1, src2);
574 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
575 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
576 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
577 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
578 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
579 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
580 tcg_temp_free(r_temp);
583 #ifdef TARGET_SPARC64
584 static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
588 r_temp = tcg_temp_new(TCG_TYPE_TL);
589 tcg_gen_xor_tl(r_temp, src1, src2);
590 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
591 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
592 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
593 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
594 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
595 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
596 tcg_temp_free(r_temp);
600 static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
602 TCGv r_temp, r_const;
605 l1 = gen_new_label();
607 r_temp = tcg_temp_new(TCG_TYPE_TL);
608 tcg_gen_xor_tl(r_temp, src1, src2);
609 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
610 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
611 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
612 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
613 r_const = tcg_const_i32(TT_TOVF);
614 tcg_gen_helper_0_1(raise_exception, r_const);
615 tcg_temp_free(r_const);
617 tcg_temp_free(r_temp);
620 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
622 tcg_gen_mov_tl(cpu_cc_src, src1);
623 tcg_gen_mov_tl(cpu_cc_src2, src2);
624 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
626 gen_cc_NZ_icc(cpu_cc_dst);
627 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
628 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
629 #ifdef TARGET_SPARC64
631 gen_cc_NZ_xcc(cpu_cc_dst);
632 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
633 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
635 tcg_gen_mov_tl(dst, cpu_cc_dst);
638 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
640 tcg_gen_mov_tl(cpu_cc_src, src1);
641 tcg_gen_mov_tl(cpu_cc_src2, src2);
642 gen_mov_reg_C(cpu_tmp0, cpu_psr);
643 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
645 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
646 #ifdef TARGET_SPARC64
648 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
650 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
651 gen_cc_NZ_icc(cpu_cc_dst);
652 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
653 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
654 #ifdef TARGET_SPARC64
655 gen_cc_NZ_xcc(cpu_cc_dst);
656 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
657 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
659 tcg_gen_mov_tl(dst, cpu_cc_dst);
662 static inline void gen_op_tsub_cc(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 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
668 gen_cc_NZ_icc(cpu_cc_dst);
669 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
670 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
671 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
672 #ifdef TARGET_SPARC64
674 gen_cc_NZ_xcc(cpu_cc_dst);
675 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
676 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
678 tcg_gen_mov_tl(dst, cpu_cc_dst);
681 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
683 tcg_gen_mov_tl(cpu_cc_src, src1);
684 tcg_gen_mov_tl(cpu_cc_src2, src2);
685 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
686 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
687 gen_sub_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
689 gen_cc_NZ_icc(cpu_cc_dst);
690 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
691 #ifdef TARGET_SPARC64
693 gen_cc_NZ_xcc(cpu_cc_dst);
694 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
695 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
697 tcg_gen_mov_tl(dst, cpu_cc_dst);
700 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
702 TCGv r_temp, r_temp2;
705 l1 = gen_new_label();
706 r_temp = tcg_temp_new(TCG_TYPE_TL);
707 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
713 tcg_gen_mov_tl(cpu_cc_src, src1);
714 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
715 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
716 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
717 tcg_gen_mov_tl(cpu_cc_src2, src2);
718 tcg_gen_brcondi_i32(TCG_COND_NE, r_temp2, 0, l1);
719 tcg_gen_movi_tl(cpu_cc_src2, 0);
723 // env->y = (b2 << 31) | (env->y >> 1);
724 tcg_gen_trunc_tl_i32(r_temp2, cpu_cc_src);
725 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
726 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
727 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
728 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
729 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
730 tcg_temp_free(r_temp2);
731 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
734 gen_mov_reg_N(cpu_tmp0, cpu_psr);
735 gen_mov_reg_V(r_temp, cpu_psr);
736 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
737 tcg_temp_free(r_temp);
739 // T0 = (b1 << 31) | (T0 >> 1);
741 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
742 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
743 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
745 /* do addition and update flags */
746 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
749 gen_cc_NZ_icc(cpu_cc_dst);
750 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
751 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
752 tcg_gen_mov_tl(dst, cpu_cc_dst);
755 static inline void gen_op_umul(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_extu_tl_i64(r_temp, src2);
763 tcg_gen_extu_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 tcg_temp_free(r_temp);
770 #ifdef TARGET_SPARC64
771 tcg_gen_mov_i64(dst, r_temp2);
773 tcg_gen_trunc_i64_tl(dst, r_temp2);
775 tcg_temp_free(r_temp2);
778 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
780 TCGv r_temp, r_temp2;
782 r_temp = tcg_temp_new(TCG_TYPE_I64);
783 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
785 tcg_gen_ext_tl_i64(r_temp, src2);
786 tcg_gen_ext_tl_i64(r_temp2, src1);
787 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
789 tcg_gen_shri_i64(r_temp, r_temp2, 32);
790 tcg_gen_trunc_i64_i32(r_temp, r_temp);
791 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
792 tcg_temp_free(r_temp);
793 #ifdef TARGET_SPARC64
794 tcg_gen_mov_i64(dst, r_temp2);
796 tcg_gen_trunc_i64_tl(dst, r_temp2);
798 tcg_temp_free(r_temp2);
801 #ifdef TARGET_SPARC64
802 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
807 l1 = gen_new_label();
808 tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
809 r_const = tcg_const_i32(TT_DIV_ZERO);
810 tcg_gen_helper_0_1(raise_exception, r_const);
811 tcg_temp_free(r_const);
815 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
819 l1 = gen_new_label();
820 l2 = gen_new_label();
821 tcg_gen_mov_tl(cpu_cc_src, src1);
822 tcg_gen_mov_tl(cpu_cc_src2, src2);
823 gen_trap_ifdivzero_tl(cpu_cc_src2);
824 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src, INT64_MIN, l1);
825 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src2, -1, l1);
826 tcg_gen_movi_i64(dst, INT64_MIN);
829 tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
834 static inline void gen_op_div_cc(TCGv dst)
838 tcg_gen_mov_tl(cpu_cc_dst, dst);
840 gen_cc_NZ_icc(cpu_cc_dst);
841 l1 = gen_new_label();
842 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_src2, 0, l1);
843 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
847 static inline void gen_op_logic_cc(TCGv dst)
849 tcg_gen_mov_tl(cpu_cc_dst, dst);
852 gen_cc_NZ_icc(cpu_cc_dst);
853 #ifdef TARGET_SPARC64
855 gen_cc_NZ_xcc(cpu_cc_dst);
860 static inline void gen_op_eval_ba(TCGv dst)
862 tcg_gen_movi_tl(dst, 1);
866 static inline void gen_op_eval_be(TCGv dst, TCGv src)
868 gen_mov_reg_Z(dst, src);
872 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
874 gen_mov_reg_N(cpu_tmp0, src);
875 gen_mov_reg_V(dst, src);
876 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
877 gen_mov_reg_Z(cpu_tmp0, src);
878 tcg_gen_or_tl(dst, dst, cpu_tmp0);
882 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
884 gen_mov_reg_V(cpu_tmp0, src);
885 gen_mov_reg_N(dst, src);
886 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
890 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
892 gen_mov_reg_Z(cpu_tmp0, src);
893 gen_mov_reg_C(dst, src);
894 tcg_gen_or_tl(dst, dst, cpu_tmp0);
898 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
900 gen_mov_reg_C(dst, src);
904 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
906 gen_mov_reg_V(dst, src);
910 static inline void gen_op_eval_bn(TCGv dst)
912 tcg_gen_movi_tl(dst, 0);
916 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
918 gen_mov_reg_N(dst, src);
922 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
924 gen_mov_reg_Z(dst, src);
925 tcg_gen_xori_tl(dst, dst, 0x1);
929 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
931 gen_mov_reg_N(cpu_tmp0, src);
932 gen_mov_reg_V(dst, src);
933 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
934 gen_mov_reg_Z(cpu_tmp0, src);
935 tcg_gen_or_tl(dst, dst, cpu_tmp0);
936 tcg_gen_xori_tl(dst, dst, 0x1);
940 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
942 gen_mov_reg_V(cpu_tmp0, src);
943 gen_mov_reg_N(dst, src);
944 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
945 tcg_gen_xori_tl(dst, dst, 0x1);
949 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
951 gen_mov_reg_Z(cpu_tmp0, src);
952 gen_mov_reg_C(dst, src);
953 tcg_gen_or_tl(dst, dst, cpu_tmp0);
954 tcg_gen_xori_tl(dst, dst, 0x1);
958 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
960 gen_mov_reg_C(dst, src);
961 tcg_gen_xori_tl(dst, dst, 0x1);
965 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
967 gen_mov_reg_N(dst, src);
968 tcg_gen_xori_tl(dst, dst, 0x1);
972 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
974 gen_mov_reg_V(dst, src);
975 tcg_gen_xori_tl(dst, dst, 0x1);
979 FPSR bit field FCC1 | FCC0:
985 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
986 unsigned int fcc_offset)
988 tcg_gen_extu_i32_tl(reg, src);
989 tcg_gen_shri_tl(reg, reg, FSR_FCC0_SHIFT + fcc_offset);
990 tcg_gen_andi_tl(reg, reg, 0x1);
993 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
994 unsigned int fcc_offset)
996 tcg_gen_extu_i32_tl(reg, src);
997 tcg_gen_shri_tl(reg, reg, FSR_FCC1_SHIFT + fcc_offset);
998 tcg_gen_andi_tl(reg, reg, 0x1);
1002 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
1003 unsigned int fcc_offset)
1005 gen_mov_reg_FCC0(dst, src, fcc_offset);
1006 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1007 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1010 // 1 or 2: FCC0 ^ FCC1
1011 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
1012 unsigned int fcc_offset)
1014 gen_mov_reg_FCC0(dst, src, fcc_offset);
1015 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1016 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1020 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1021 unsigned int fcc_offset)
1023 gen_mov_reg_FCC0(dst, src, fcc_offset);
1027 static inline void gen_op_eval_fbl(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_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1033 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1037 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1038 unsigned int fcc_offset)
1040 gen_mov_reg_FCC1(dst, src, fcc_offset);
1044 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1045 unsigned int fcc_offset)
1047 gen_mov_reg_FCC0(dst, src, fcc_offset);
1048 tcg_gen_xori_tl(dst, dst, 0x1);
1049 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1050 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1054 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1055 unsigned int fcc_offset)
1057 gen_mov_reg_FCC0(dst, src, fcc_offset);
1058 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1059 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1062 // 0: !(FCC0 | FCC1)
1063 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1064 unsigned int fcc_offset)
1066 gen_mov_reg_FCC0(dst, src, fcc_offset);
1067 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1068 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1069 tcg_gen_xori_tl(dst, dst, 0x1);
1072 // 0 or 3: !(FCC0 ^ FCC1)
1073 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1074 unsigned int fcc_offset)
1076 gen_mov_reg_FCC0(dst, src, fcc_offset);
1077 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1078 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1079 tcg_gen_xori_tl(dst, dst, 0x1);
1083 static inline void gen_op_eval_fbge(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);
1090 // !1: !(FCC0 & !FCC1)
1091 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1092 unsigned int fcc_offset)
1094 gen_mov_reg_FCC0(dst, src, fcc_offset);
1095 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1096 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1097 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1098 tcg_gen_xori_tl(dst, dst, 0x1);
1102 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1103 unsigned int fcc_offset)
1105 gen_mov_reg_FCC1(dst, src, fcc_offset);
1106 tcg_gen_xori_tl(dst, dst, 0x1);
1109 // !2: !(!FCC0 & FCC1)
1110 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1111 unsigned int fcc_offset)
1113 gen_mov_reg_FCC0(dst, src, fcc_offset);
1114 tcg_gen_xori_tl(dst, dst, 0x1);
1115 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1116 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1117 tcg_gen_xori_tl(dst, dst, 0x1);
1120 // !3: !(FCC0 & FCC1)
1121 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1122 unsigned int fcc_offset)
1124 gen_mov_reg_FCC0(dst, src, fcc_offset);
1125 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1126 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1127 tcg_gen_xori_tl(dst, dst, 0x1);
1130 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1131 target_ulong pc2, TCGv r_cond)
1135 l1 = gen_new_label();
1137 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1139 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1142 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1145 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1146 target_ulong pc2, TCGv r_cond)
1150 l1 = gen_new_label();
1152 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1154 gen_goto_tb(dc, 0, pc2, pc1);
1157 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1160 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1165 l1 = gen_new_label();
1166 l2 = gen_new_label();
1168 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1170 tcg_gen_movi_tl(cpu_npc, npc1);
1174 tcg_gen_movi_tl(cpu_npc, npc2);
1178 /* call this function before using the condition register as it may
1179 have been set for a jump */
1180 static inline void flush_cond(DisasContext *dc, TCGv cond)
1182 if (dc->npc == JUMP_PC) {
1183 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1184 dc->npc = DYNAMIC_PC;
1188 static inline void save_npc(DisasContext *dc, TCGv cond)
1190 if (dc->npc == JUMP_PC) {
1191 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1192 dc->npc = DYNAMIC_PC;
1193 } else if (dc->npc != DYNAMIC_PC) {
1194 tcg_gen_movi_tl(cpu_npc, dc->npc);
1198 static inline void save_state(DisasContext *dc, TCGv cond)
1200 tcg_gen_movi_tl(cpu_pc, dc->pc);
1204 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1206 if (dc->npc == JUMP_PC) {
1207 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1208 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1209 dc->pc = DYNAMIC_PC;
1210 } else if (dc->npc == DYNAMIC_PC) {
1211 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1212 dc->pc = DYNAMIC_PC;
1218 static inline void gen_op_next_insn(void)
1220 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1221 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1224 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1228 #ifdef TARGET_SPARC64
1238 gen_op_eval_bn(r_dst);
1241 gen_op_eval_be(r_dst, r_src);
1244 gen_op_eval_ble(r_dst, r_src);
1247 gen_op_eval_bl(r_dst, r_src);
1250 gen_op_eval_bleu(r_dst, r_src);
1253 gen_op_eval_bcs(r_dst, r_src);
1256 gen_op_eval_bneg(r_dst, r_src);
1259 gen_op_eval_bvs(r_dst, r_src);
1262 gen_op_eval_ba(r_dst);
1265 gen_op_eval_bne(r_dst, r_src);
1268 gen_op_eval_bg(r_dst, r_src);
1271 gen_op_eval_bge(r_dst, r_src);
1274 gen_op_eval_bgu(r_dst, r_src);
1277 gen_op_eval_bcc(r_dst, r_src);
1280 gen_op_eval_bpos(r_dst, r_src);
1283 gen_op_eval_bvc(r_dst, r_src);
1288 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1290 unsigned int offset;
1310 gen_op_eval_bn(r_dst);
1313 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1316 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1319 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1322 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1325 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1328 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1331 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1334 gen_op_eval_ba(r_dst);
1337 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1340 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1343 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1346 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1349 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1352 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1355 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1360 #ifdef TARGET_SPARC64
1362 static const int gen_tcg_cond_reg[8] = {
1373 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1377 l1 = gen_new_label();
1378 tcg_gen_movi_tl(r_dst, 0);
1379 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1380 tcg_gen_movi_tl(r_dst, 1);
1385 /* XXX: potentially incorrect if dynamic npc */
1386 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1389 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1390 target_ulong target = dc->pc + offset;
1393 /* unconditional not taken */
1395 dc->pc = dc->npc + 4;
1396 dc->npc = dc->pc + 4;
1399 dc->npc = dc->pc + 4;
1401 } else if (cond == 0x8) {
1402 /* unconditional taken */
1405 dc->npc = dc->pc + 4;
1411 flush_cond(dc, r_cond);
1412 gen_cond(r_cond, cc, cond);
1414 gen_branch_a(dc, target, dc->npc, r_cond);
1418 dc->jump_pc[0] = target;
1419 dc->jump_pc[1] = dc->npc + 4;
1425 /* XXX: potentially incorrect if dynamic npc */
1426 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1429 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1430 target_ulong target = dc->pc + offset;
1433 /* unconditional not taken */
1435 dc->pc = dc->npc + 4;
1436 dc->npc = dc->pc + 4;
1439 dc->npc = dc->pc + 4;
1441 } else if (cond == 0x8) {
1442 /* unconditional taken */
1445 dc->npc = dc->pc + 4;
1451 flush_cond(dc, r_cond);
1452 gen_fcond(r_cond, cc, cond);
1454 gen_branch_a(dc, target, dc->npc, r_cond);
1458 dc->jump_pc[0] = target;
1459 dc->jump_pc[1] = dc->npc + 4;
1465 #ifdef TARGET_SPARC64
1466 /* XXX: potentially incorrect if dynamic npc */
1467 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1468 TCGv r_cond, TCGv r_reg)
1470 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1471 target_ulong target = dc->pc + offset;
1473 flush_cond(dc, r_cond);
1474 gen_cond_reg(r_cond, cond, r_reg);
1476 gen_branch_a(dc, target, dc->npc, r_cond);
1480 dc->jump_pc[0] = target;
1481 dc->jump_pc[1] = dc->npc + 4;
1486 static GenOpFunc * const gen_fcmps[4] = {
1493 static GenOpFunc * const gen_fcmpd[4] = {
1500 static GenOpFunc * const gen_fcmpq[4] = {
1507 static GenOpFunc * const gen_fcmpes[4] = {
1514 static GenOpFunc * const gen_fcmped[4] = {
1521 static GenOpFunc * const gen_fcmpeq[4] = {
1528 static inline void gen_op_fcmps(int fccno)
1530 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1533 static inline void gen_op_fcmpd(int fccno)
1535 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1538 static inline void gen_op_fcmpq(int fccno)
1540 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1543 static inline void gen_op_fcmpes(int fccno)
1545 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1548 static inline void gen_op_fcmped(int fccno)
1550 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1553 static inline void gen_op_fcmpeq(int fccno)
1555 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1560 static inline void gen_op_fcmps(int fccno)
1562 tcg_gen_helper_0_0(helper_fcmps);
1565 static inline void gen_op_fcmpd(int fccno)
1567 tcg_gen_helper_0_0(helper_fcmpd);
1570 static inline void gen_op_fcmpq(int fccno)
1572 tcg_gen_helper_0_0(helper_fcmpq);
1575 static inline void gen_op_fcmpes(int fccno)
1577 tcg_gen_helper_0_0(helper_fcmpes);
1580 static inline void gen_op_fcmped(int fccno)
1582 tcg_gen_helper_0_0(helper_fcmped);
1585 static inline void gen_op_fcmpeq(int fccno)
1587 tcg_gen_helper_0_0(helper_fcmpeq);
1591 static inline void gen_op_fpexception_im(int fsr_flags)
1595 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1596 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1597 r_const = tcg_const_i32(TT_FP_EXCP);
1598 tcg_gen_helper_0_1(raise_exception, r_const);
1599 tcg_temp_free(r_const);
1602 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1604 #if !defined(CONFIG_USER_ONLY)
1605 if (!dc->fpu_enabled) {
1608 save_state(dc, r_cond);
1609 r_const = tcg_const_i32(TT_NFPU_INSN);
1610 tcg_gen_helper_0_1(raise_exception, r_const);
1611 tcg_temp_free(r_const);
1619 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1621 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1624 static inline void gen_clear_float_exceptions(void)
1626 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1630 #ifdef TARGET_SPARC64
1631 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1637 r_asi = tcg_temp_new(TCG_TYPE_I32);
1638 offset = GET_FIELD(insn, 25, 31);
1639 tcg_gen_addi_tl(r_addr, r_addr, offset);
1640 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1642 asi = GET_FIELD(insn, 19, 26);
1643 r_asi = tcg_const_i32(asi);
1648 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1651 TCGv r_asi, r_size, r_sign;
1653 r_asi = gen_get_asi(insn, addr);
1654 r_size = tcg_const_i32(size);
1655 r_sign = tcg_const_i32(sign);
1656 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi, r_size, r_sign);
1657 tcg_temp_free(r_sign);
1658 tcg_temp_free(r_size);
1659 tcg_temp_free(r_asi);
1662 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1666 r_asi = gen_get_asi(insn, addr);
1667 r_size = tcg_const_i32(size);
1668 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, r_size);
1669 tcg_temp_free(r_size);
1670 tcg_temp_free(r_asi);
1673 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1675 TCGv r_asi, r_size, r_rd;
1677 r_asi = gen_get_asi(insn, addr);
1678 r_size = tcg_const_i32(size);
1679 r_rd = tcg_const_i32(rd);
1680 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, r_size, r_rd);
1681 tcg_temp_free(r_rd);
1682 tcg_temp_free(r_size);
1683 tcg_temp_free(r_asi);
1686 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1688 TCGv r_asi, r_size, r_rd;
1690 r_asi = gen_get_asi(insn, addr);
1691 r_size = tcg_const_i32(size);
1692 r_rd = tcg_const_i32(rd);
1693 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, r_size, r_rd);
1694 tcg_temp_free(r_rd);
1695 tcg_temp_free(r_size);
1696 tcg_temp_free(r_asi);
1699 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1701 TCGv r_asi, r_size, r_sign;
1703 r_asi = gen_get_asi(insn, addr);
1704 r_size = tcg_const_i32(4);
1705 r_sign = tcg_const_i32(0);
1706 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1707 tcg_temp_free(r_sign);
1708 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1709 tcg_temp_free(r_size);
1710 tcg_temp_free(r_asi);
1711 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1714 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1716 TCGv r_asi, r_size, r_sign;
1718 r_asi = gen_get_asi(insn, addr);
1719 r_size = tcg_const_i32(8);
1720 r_sign = tcg_const_i32(0);
1721 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1722 tcg_temp_free(r_sign);
1723 tcg_temp_free(r_size);
1724 tcg_temp_free(r_asi);
1725 tcg_gen_andi_i64(lo, cpu_tmp64, 0xffffffffULL);
1726 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1727 tcg_gen_andi_i64(hi, cpu_tmp64, 0xffffffffULL);
1730 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1732 TCGv r_temp, r_asi, r_size;
1734 r_temp = tcg_temp_new(TCG_TYPE_TL);
1735 gen_movl_reg_TN(rd + 1, r_temp);
1736 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1738 tcg_temp_free(r_temp);
1739 r_asi = gen_get_asi(insn, addr);
1740 r_size = tcg_const_i32(8);
1741 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1742 tcg_temp_free(r_size);
1743 tcg_temp_free(r_asi);
1746 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1751 r_val1 = tcg_temp_new(TCG_TYPE_TL);
1752 gen_movl_reg_TN(rd, r_val1);
1753 r_asi = gen_get_asi(insn, addr);
1754 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1755 tcg_temp_free(r_asi);
1756 tcg_temp_free(r_val1);
1759 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1764 gen_movl_reg_TN(rd, cpu_tmp64);
1765 r_asi = gen_get_asi(insn, addr);
1766 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1767 tcg_temp_free(r_asi);
1770 #elif !defined(CONFIG_USER_ONLY)
1772 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1775 TCGv r_asi, r_size, r_sign;
1777 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1778 r_size = tcg_const_i32(size);
1779 r_sign = tcg_const_i32(sign);
1780 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1781 tcg_temp_free(r_sign);
1782 tcg_temp_free(r_size);
1783 tcg_temp_free(r_asi);
1784 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1787 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1791 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1792 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1793 r_size = tcg_const_i32(size);
1794 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1795 tcg_temp_free(r_size);
1796 tcg_temp_free(r_asi);
1799 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1801 TCGv r_asi, r_size, r_sign;
1803 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1804 r_size = tcg_const_i32(4);
1805 r_sign = tcg_const_i32(0);
1806 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1807 tcg_temp_free(r_sign);
1808 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1809 tcg_temp_free(r_size);
1810 tcg_temp_free(r_asi);
1811 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1814 static inline void gen_ldda_asi(TCGv lo, TCGv hi, TCGv addr, int insn)
1816 TCGv r_asi, r_size, r_sign;
1818 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1819 r_size = tcg_const_i32(8);
1820 r_sign = tcg_const_i32(0);
1821 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1822 tcg_temp_free(r_sign);
1823 tcg_temp_free(r_size);
1824 tcg_temp_free(r_asi);
1825 tcg_gen_trunc_i64_tl(lo, cpu_tmp64);
1826 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1827 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1830 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1832 TCGv r_temp, r_asi, r_size;
1834 r_temp = tcg_temp_new(TCG_TYPE_TL);
1835 gen_movl_reg_TN(rd + 1, r_temp);
1836 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1837 tcg_temp_free(r_temp);
1838 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1839 r_size = tcg_const_i32(8);
1840 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1841 tcg_temp_free(r_size);
1842 tcg_temp_free(r_asi);
1846 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1847 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1849 TCGv r_val, r_asi, r_size;
1851 gen_ld_asi(dst, addr, insn, 1, 0);
1853 r_val = tcg_const_i64(0xffULL);
1854 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1855 r_size = tcg_const_i32(1);
1856 tcg_gen_helper_0_4(helper_st_asi, addr, r_val, r_asi, r_size);
1857 tcg_temp_free(r_size);
1858 tcg_temp_free(r_asi);
1859 tcg_temp_free(r_val);
1863 static inline TCGv get_src1(unsigned int insn, TCGv def)
1868 rs1 = GET_FIELD(insn, 13, 17);
1870 r_rs1 = tcg_const_tl(0); // XXX how to free?
1872 r_rs1 = cpu_gregs[rs1];
1874 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1878 static inline TCGv get_src2(unsigned int insn, TCGv def)
1883 if (IS_IMM) { /* immediate */
1884 rs2 = GET_FIELDs(insn, 19, 31);
1885 r_rs2 = tcg_const_tl((int)rs2); // XXX how to free?
1886 } else { /* register */
1887 rs2 = GET_FIELD(insn, 27, 31);
1889 r_rs2 = tcg_const_tl(0); // XXX how to free?
1891 r_rs2 = cpu_gregs[rs2];
1893 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1898 #define CHECK_IU_FEATURE(dc, FEATURE) \
1899 if (!((dc)->features & CPU_FEATURE_ ## FEATURE)) \
1901 #define CHECK_FPU_FEATURE(dc, FEATURE) \
1902 if (!((dc)->features & CPU_FEATURE_ ## FEATURE)) \
1905 /* before an instruction, dc->pc must be static */
1906 static void disas_sparc_insn(DisasContext * dc)
1908 unsigned int insn, opc, rs1, rs2, rd;
1910 if (unlikely(loglevel & CPU_LOG_TB_OP))
1911 tcg_gen_debug_insn_start(dc->pc);
1912 insn = ldl_code(dc->pc);
1913 opc = GET_FIELD(insn, 0, 1);
1915 rd = GET_FIELD(insn, 2, 6);
1917 cpu_src1 = tcg_temp_new(TCG_TYPE_TL); // const
1918 cpu_src2 = tcg_temp_new(TCG_TYPE_TL); // const
1921 case 0: /* branches/sethi */
1923 unsigned int xop = GET_FIELD(insn, 7, 9);
1926 #ifdef TARGET_SPARC64
1927 case 0x1: /* V9 BPcc */
1931 target = GET_FIELD_SP(insn, 0, 18);
1932 target = sign_extend(target, 18);
1934 cc = GET_FIELD_SP(insn, 20, 21);
1936 do_branch(dc, target, insn, 0, cpu_cond);
1938 do_branch(dc, target, insn, 1, cpu_cond);
1943 case 0x3: /* V9 BPr */
1945 target = GET_FIELD_SP(insn, 0, 13) |
1946 (GET_FIELD_SP(insn, 20, 21) << 14);
1947 target = sign_extend(target, 16);
1949 cpu_src1 = get_src1(insn, cpu_src1);
1950 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1953 case 0x5: /* V9 FBPcc */
1955 int cc = GET_FIELD_SP(insn, 20, 21);
1956 if (gen_trap_ifnofpu(dc, cpu_cond))
1958 target = GET_FIELD_SP(insn, 0, 18);
1959 target = sign_extend(target, 19);
1961 do_fbranch(dc, target, insn, cc, cpu_cond);
1965 case 0x7: /* CBN+x */
1970 case 0x2: /* BN+x */
1972 target = GET_FIELD(insn, 10, 31);
1973 target = sign_extend(target, 22);
1975 do_branch(dc, target, insn, 0, cpu_cond);
1978 case 0x6: /* FBN+x */
1980 if (gen_trap_ifnofpu(dc, cpu_cond))
1982 target = GET_FIELD(insn, 10, 31);
1983 target = sign_extend(target, 22);
1985 do_fbranch(dc, target, insn, 0, cpu_cond);
1988 case 0x4: /* SETHI */
1990 uint32_t value = GET_FIELD(insn, 10, 31);
1993 r_const = tcg_const_tl(value << 10);
1994 gen_movl_TN_reg(rd, r_const);
1995 tcg_temp_free(r_const);
1998 case 0x0: /* UNIMPL */
2007 target_long target = GET_FIELDs(insn, 2, 31) << 2;
2010 r_const = tcg_const_tl(dc->pc);
2011 gen_movl_TN_reg(15, r_const);
2012 tcg_temp_free(r_const);
2014 gen_mov_pc_npc(dc, cpu_cond);
2018 case 2: /* FPU & Logical Operations */
2020 unsigned int xop = GET_FIELD(insn, 7, 12);
2021 if (xop == 0x3a) { /* generate trap */
2024 cpu_src1 = get_src1(insn, cpu_src1);
2026 rs2 = GET_FIELD(insn, 25, 31);
2027 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
2029 rs2 = GET_FIELD(insn, 27, 31);
2031 gen_movl_reg_TN(rs2, cpu_src2);
2032 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2034 tcg_gen_mov_tl(cpu_dst, cpu_src1);
2036 cond = GET_FIELD(insn, 3, 6);
2038 save_state(dc, cpu_cond);
2039 tcg_gen_helper_0_1(helper_trap, cpu_dst);
2040 } else if (cond != 0) {
2041 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
2042 #ifdef TARGET_SPARC64
2044 int cc = GET_FIELD_SP(insn, 11, 12);
2046 save_state(dc, cpu_cond);
2048 gen_cond(r_cond, 0, cond);
2050 gen_cond(r_cond, 1, cond);
2054 save_state(dc, cpu_cond);
2055 gen_cond(r_cond, 0, cond);
2057 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
2058 tcg_temp_free(r_cond);
2064 } else if (xop == 0x28) {
2065 rs1 = GET_FIELD(insn, 13, 17);
2068 #ifndef TARGET_SPARC64
2069 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2070 manual, rdy on the microSPARC
2072 case 0x0f: /* stbar in the SPARCv8 manual,
2073 rdy on the microSPARC II */
2074 case 0x10 ... 0x1f: /* implementation-dependent in the
2075 SPARCv8 manual, rdy on the
2078 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2079 offsetof(CPUSPARCState, y));
2080 gen_movl_TN_reg(rd, cpu_tmp0);
2082 #ifdef TARGET_SPARC64
2083 case 0x2: /* V9 rdccr */
2084 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2085 gen_movl_TN_reg(rd, cpu_dst);
2087 case 0x3: /* V9 rdasi */
2088 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2089 offsetof(CPUSPARCState, asi));
2090 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2091 gen_movl_TN_reg(rd, cpu_dst);
2093 case 0x4: /* V9 rdtick */
2097 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2098 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2099 offsetof(CPUState, tick));
2100 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2102 tcg_temp_free(r_tickptr);
2103 gen_movl_TN_reg(rd, cpu_dst);
2106 case 0x5: /* V9 rdpc */
2110 r_const = tcg_const_tl(dc->pc);
2111 gen_movl_TN_reg(rd, r_const);
2112 tcg_temp_free(r_const);
2115 case 0x6: /* V9 rdfprs */
2116 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2117 offsetof(CPUSPARCState, fprs));
2118 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2119 gen_movl_TN_reg(rd, cpu_dst);
2121 case 0xf: /* V9 membar */
2122 break; /* no effect */
2123 case 0x13: /* Graphics Status */
2124 if (gen_trap_ifnofpu(dc, cpu_cond))
2126 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2127 offsetof(CPUSPARCState, gsr));
2128 gen_movl_TN_reg(rd, cpu_tmp0);
2130 case 0x17: /* Tick compare */
2131 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2132 offsetof(CPUSPARCState, tick_cmpr));
2133 gen_movl_TN_reg(rd, cpu_tmp0);
2135 case 0x18: /* System tick */
2139 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2140 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2141 offsetof(CPUState, stick));
2142 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2144 tcg_temp_free(r_tickptr);
2145 gen_movl_TN_reg(rd, cpu_dst);
2148 case 0x19: /* System tick compare */
2149 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2150 offsetof(CPUSPARCState, stick_cmpr));
2151 gen_movl_TN_reg(rd, cpu_tmp0);
2153 case 0x10: /* Performance Control */
2154 case 0x11: /* Performance Instrumentation Counter */
2155 case 0x12: /* Dispatch Control */
2156 case 0x14: /* Softint set, WO */
2157 case 0x15: /* Softint clear, WO */
2158 case 0x16: /* Softint write */
2163 #if !defined(CONFIG_USER_ONLY)
2164 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2165 #ifndef TARGET_SPARC64
2166 if (!supervisor(dc))
2168 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2170 if (!hypervisor(dc))
2172 rs1 = GET_FIELD(insn, 13, 17);
2175 // gen_op_rdhpstate();
2178 // gen_op_rdhtstate();
2181 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2182 offsetof(CPUSPARCState, hintp));
2183 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2186 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2187 offsetof(CPUSPARCState, htba));
2188 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2191 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2192 offsetof(CPUSPARCState, hver));
2193 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2195 case 31: // hstick_cmpr
2196 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
2197 tcg_gen_st_i32(cpu_tmp32, cpu_env,
2198 offsetof(CPUSPARCState, hstick_cmpr));
2204 gen_movl_TN_reg(rd, cpu_dst);
2206 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2207 if (!supervisor(dc))
2209 #ifdef TARGET_SPARC64
2210 rs1 = GET_FIELD(insn, 13, 17);
2216 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2217 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2218 offsetof(CPUState, tsptr));
2219 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2220 offsetof(trap_state, tpc));
2221 tcg_temp_free(r_tsptr);
2228 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2229 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2230 offsetof(CPUState, tsptr));
2231 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2232 offsetof(trap_state, tnpc));
2233 tcg_temp_free(r_tsptr);
2240 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2241 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2242 offsetof(CPUState, tsptr));
2243 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2244 offsetof(trap_state, tstate));
2245 tcg_temp_free(r_tsptr);
2252 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2253 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2254 offsetof(CPUState, tsptr));
2255 tcg_gen_ld_i32(cpu_tmp0, r_tsptr,
2256 offsetof(trap_state, tt));
2257 tcg_temp_free(r_tsptr);
2264 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2265 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2266 offsetof(CPUState, tick));
2267 tcg_gen_helper_1_1(helper_tick_get_count, cpu_tmp0,
2269 gen_movl_TN_reg(rd, cpu_tmp0);
2270 tcg_temp_free(r_tickptr);
2274 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2275 offsetof(CPUSPARCState, tbr));
2278 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2279 offsetof(CPUSPARCState, pstate));
2280 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2283 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2284 offsetof(CPUSPARCState, tl));
2285 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2288 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2289 offsetof(CPUSPARCState, psrpil));
2290 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2293 tcg_gen_helper_1_0(helper_rdcwp, cpu_tmp0);
2296 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2297 offsetof(CPUSPARCState, cansave));
2298 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2300 case 11: // canrestore
2301 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2302 offsetof(CPUSPARCState, canrestore));
2303 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2305 case 12: // cleanwin
2306 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2307 offsetof(CPUSPARCState, cleanwin));
2308 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2310 case 13: // otherwin
2311 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2312 offsetof(CPUSPARCState, otherwin));
2313 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2316 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2317 offsetof(CPUSPARCState, wstate));
2318 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2320 case 16: // UA2005 gl
2321 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2322 offsetof(CPUSPARCState, gl));
2323 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2325 case 26: // UA2005 strand status
2326 if (!hypervisor(dc))
2328 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2329 offsetof(CPUSPARCState, ssr));
2330 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2333 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2334 offsetof(CPUSPARCState, version));
2341 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2342 offsetof(CPUSPARCState, wim));
2343 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2345 gen_movl_TN_reg(rd, cpu_tmp0);
2347 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2348 #ifdef TARGET_SPARC64
2349 tcg_gen_helper_0_0(helper_flushw);
2351 if (!supervisor(dc))
2353 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, tbr));
2354 gen_movl_TN_reg(rd, cpu_tmp0);
2358 } else if (xop == 0x34) { /* FPU Operations */
2359 if (gen_trap_ifnofpu(dc, cpu_cond))
2361 gen_op_clear_ieee_excp_and_FTT();
2362 rs1 = GET_FIELD(insn, 13, 17);
2363 rs2 = GET_FIELD(insn, 27, 31);
2364 xop = GET_FIELD(insn, 18, 26);
2366 case 0x1: /* fmovs */
2367 gen_op_load_fpr_FT0(rs2);
2368 gen_op_store_FT0_fpr(rd);
2370 case 0x5: /* fnegs */
2371 gen_op_load_fpr_FT1(rs2);
2372 tcg_gen_helper_0_0(helper_fnegs);
2373 gen_op_store_FT0_fpr(rd);
2375 case 0x9: /* fabss */
2376 gen_op_load_fpr_FT1(rs2);
2377 tcg_gen_helper_0_0(helper_fabss);
2378 gen_op_store_FT0_fpr(rd);
2380 case 0x29: /* fsqrts */
2381 CHECK_FPU_FEATURE(dc, FSQRT);
2382 gen_op_load_fpr_FT1(rs2);
2383 gen_clear_float_exceptions();
2384 tcg_gen_helper_0_0(helper_fsqrts);
2385 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2386 gen_op_store_FT0_fpr(rd);
2388 case 0x2a: /* fsqrtd */
2389 CHECK_FPU_FEATURE(dc, FSQRT);
2390 gen_op_load_fpr_DT1(DFPREG(rs2));
2391 gen_clear_float_exceptions();
2392 tcg_gen_helper_0_0(helper_fsqrtd);
2393 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2394 gen_op_store_DT0_fpr(DFPREG(rd));
2396 case 0x2b: /* fsqrtq */
2397 CHECK_FPU_FEATURE(dc, FLOAT128);
2398 gen_op_load_fpr_QT1(QFPREG(rs2));
2399 gen_clear_float_exceptions();
2400 tcg_gen_helper_0_0(helper_fsqrtq);
2401 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2402 gen_op_store_QT0_fpr(QFPREG(rd));
2405 gen_op_load_fpr_FT0(rs1);
2406 gen_op_load_fpr_FT1(rs2);
2407 gen_clear_float_exceptions();
2408 tcg_gen_helper_0_0(helper_fadds);
2409 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2410 gen_op_store_FT0_fpr(rd);
2413 gen_op_load_fpr_DT0(DFPREG(rs1));
2414 gen_op_load_fpr_DT1(DFPREG(rs2));
2415 gen_clear_float_exceptions();
2416 tcg_gen_helper_0_0(helper_faddd);
2417 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2418 gen_op_store_DT0_fpr(DFPREG(rd));
2420 case 0x43: /* faddq */
2421 CHECK_FPU_FEATURE(dc, FLOAT128);
2422 gen_op_load_fpr_QT0(QFPREG(rs1));
2423 gen_op_load_fpr_QT1(QFPREG(rs2));
2424 gen_clear_float_exceptions();
2425 tcg_gen_helper_0_0(helper_faddq);
2426 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2427 gen_op_store_QT0_fpr(QFPREG(rd));
2430 gen_op_load_fpr_FT0(rs1);
2431 gen_op_load_fpr_FT1(rs2);
2432 gen_clear_float_exceptions();
2433 tcg_gen_helper_0_0(helper_fsubs);
2434 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2435 gen_op_store_FT0_fpr(rd);
2438 gen_op_load_fpr_DT0(DFPREG(rs1));
2439 gen_op_load_fpr_DT1(DFPREG(rs2));
2440 gen_clear_float_exceptions();
2441 tcg_gen_helper_0_0(helper_fsubd);
2442 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2443 gen_op_store_DT0_fpr(DFPREG(rd));
2445 case 0x47: /* fsubq */
2446 CHECK_FPU_FEATURE(dc, FLOAT128);
2447 gen_op_load_fpr_QT0(QFPREG(rs1));
2448 gen_op_load_fpr_QT1(QFPREG(rs2));
2449 gen_clear_float_exceptions();
2450 tcg_gen_helper_0_0(helper_fsubq);
2451 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2452 gen_op_store_QT0_fpr(QFPREG(rd));
2454 case 0x49: /* fmuls */
2455 CHECK_FPU_FEATURE(dc, FMUL);
2456 gen_op_load_fpr_FT0(rs1);
2457 gen_op_load_fpr_FT1(rs2);
2458 gen_clear_float_exceptions();
2459 tcg_gen_helper_0_0(helper_fmuls);
2460 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2461 gen_op_store_FT0_fpr(rd);
2463 case 0x4a: /* fmuld */
2464 CHECK_FPU_FEATURE(dc, FMUL);
2465 gen_op_load_fpr_DT0(DFPREG(rs1));
2466 gen_op_load_fpr_DT1(DFPREG(rs2));
2467 gen_clear_float_exceptions();
2468 tcg_gen_helper_0_0(helper_fmuld);
2469 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2470 gen_op_store_DT0_fpr(DFPREG(rd));
2472 case 0x4b: /* fmulq */
2473 CHECK_FPU_FEATURE(dc, FLOAT128);
2474 CHECK_FPU_FEATURE(dc, FMUL);
2475 gen_op_load_fpr_QT0(QFPREG(rs1));
2476 gen_op_load_fpr_QT1(QFPREG(rs2));
2477 gen_clear_float_exceptions();
2478 tcg_gen_helper_0_0(helper_fmulq);
2479 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2480 gen_op_store_QT0_fpr(QFPREG(rd));
2483 gen_op_load_fpr_FT0(rs1);
2484 gen_op_load_fpr_FT1(rs2);
2485 gen_clear_float_exceptions();
2486 tcg_gen_helper_0_0(helper_fdivs);
2487 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2488 gen_op_store_FT0_fpr(rd);
2491 gen_op_load_fpr_DT0(DFPREG(rs1));
2492 gen_op_load_fpr_DT1(DFPREG(rs2));
2493 gen_clear_float_exceptions();
2494 tcg_gen_helper_0_0(helper_fdivd);
2495 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2496 gen_op_store_DT0_fpr(DFPREG(rd));
2498 case 0x4f: /* fdivq */
2499 CHECK_FPU_FEATURE(dc, FLOAT128);
2500 gen_op_load_fpr_QT0(QFPREG(rs1));
2501 gen_op_load_fpr_QT1(QFPREG(rs2));
2502 gen_clear_float_exceptions();
2503 tcg_gen_helper_0_0(helper_fdivq);
2504 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2505 gen_op_store_QT0_fpr(QFPREG(rd));
2508 CHECK_FPU_FEATURE(dc, FSMULD);
2509 gen_op_load_fpr_FT0(rs1);
2510 gen_op_load_fpr_FT1(rs2);
2511 gen_clear_float_exceptions();
2512 tcg_gen_helper_0_0(helper_fsmuld);
2513 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2514 gen_op_store_DT0_fpr(DFPREG(rd));
2516 case 0x6e: /* fdmulq */
2517 CHECK_FPU_FEATURE(dc, FLOAT128);
2518 gen_op_load_fpr_DT0(DFPREG(rs1));
2519 gen_op_load_fpr_DT1(DFPREG(rs2));
2520 gen_clear_float_exceptions();
2521 tcg_gen_helper_0_0(helper_fdmulq);
2522 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2523 gen_op_store_QT0_fpr(QFPREG(rd));
2526 gen_op_load_fpr_FT1(rs2);
2527 gen_clear_float_exceptions();
2528 tcg_gen_helper_0_0(helper_fitos);
2529 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2530 gen_op_store_FT0_fpr(rd);
2533 gen_op_load_fpr_DT1(DFPREG(rs2));
2534 gen_clear_float_exceptions();
2535 tcg_gen_helper_0_0(helper_fdtos);
2536 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2537 gen_op_store_FT0_fpr(rd);
2539 case 0xc7: /* fqtos */
2540 CHECK_FPU_FEATURE(dc, FLOAT128);
2541 gen_op_load_fpr_QT1(QFPREG(rs2));
2542 gen_clear_float_exceptions();
2543 tcg_gen_helper_0_0(helper_fqtos);
2544 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2545 gen_op_store_FT0_fpr(rd);
2548 gen_op_load_fpr_FT1(rs2);
2549 tcg_gen_helper_0_0(helper_fitod);
2550 gen_op_store_DT0_fpr(DFPREG(rd));
2553 gen_op_load_fpr_FT1(rs2);
2554 tcg_gen_helper_0_0(helper_fstod);
2555 gen_op_store_DT0_fpr(DFPREG(rd));
2557 case 0xcb: /* fqtod */
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_fqtod);
2562 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2563 gen_op_store_DT0_fpr(DFPREG(rd));
2565 case 0xcc: /* fitoq */
2566 CHECK_FPU_FEATURE(dc, FLOAT128);
2567 gen_op_load_fpr_FT1(rs2);
2568 tcg_gen_helper_0_0(helper_fitoq);
2569 gen_op_store_QT0_fpr(QFPREG(rd));
2571 case 0xcd: /* fstoq */
2572 CHECK_FPU_FEATURE(dc, FLOAT128);
2573 gen_op_load_fpr_FT1(rs2);
2574 tcg_gen_helper_0_0(helper_fstoq);
2575 gen_op_store_QT0_fpr(QFPREG(rd));
2577 case 0xce: /* fdtoq */
2578 CHECK_FPU_FEATURE(dc, FLOAT128);
2579 gen_op_load_fpr_DT1(DFPREG(rs2));
2580 tcg_gen_helper_0_0(helper_fdtoq);
2581 gen_op_store_QT0_fpr(QFPREG(rd));
2584 gen_op_load_fpr_FT1(rs2);
2585 gen_clear_float_exceptions();
2586 tcg_gen_helper_0_0(helper_fstoi);
2587 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2588 gen_op_store_FT0_fpr(rd);
2591 gen_op_load_fpr_DT1(DFPREG(rs2));
2592 gen_clear_float_exceptions();
2593 tcg_gen_helper_0_0(helper_fdtoi);
2594 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2595 gen_op_store_FT0_fpr(rd);
2597 case 0xd3: /* fqtoi */
2598 CHECK_FPU_FEATURE(dc, FLOAT128);
2599 gen_op_load_fpr_QT1(QFPREG(rs2));
2600 gen_clear_float_exceptions();
2601 tcg_gen_helper_0_0(helper_fqtoi);
2602 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2603 gen_op_store_FT0_fpr(rd);
2605 #ifdef TARGET_SPARC64
2606 case 0x2: /* V9 fmovd */
2607 gen_op_load_fpr_DT0(DFPREG(rs2));
2608 gen_op_store_DT0_fpr(DFPREG(rd));
2610 case 0x3: /* V9 fmovq */
2611 CHECK_FPU_FEATURE(dc, FLOAT128);
2612 gen_op_load_fpr_QT0(QFPREG(rs2));
2613 gen_op_store_QT0_fpr(QFPREG(rd));
2615 case 0x6: /* V9 fnegd */
2616 gen_op_load_fpr_DT1(DFPREG(rs2));
2617 tcg_gen_helper_0_0(helper_fnegd);
2618 gen_op_store_DT0_fpr(DFPREG(rd));
2620 case 0x7: /* V9 fnegq */
2621 CHECK_FPU_FEATURE(dc, FLOAT128);
2622 gen_op_load_fpr_QT1(QFPREG(rs2));
2623 tcg_gen_helper_0_0(helper_fnegq);
2624 gen_op_store_QT0_fpr(QFPREG(rd));
2626 case 0xa: /* V9 fabsd */
2627 gen_op_load_fpr_DT1(DFPREG(rs2));
2628 tcg_gen_helper_0_0(helper_fabsd);
2629 gen_op_store_DT0_fpr(DFPREG(rd));
2631 case 0xb: /* V9 fabsq */
2632 CHECK_FPU_FEATURE(dc, FLOAT128);
2633 gen_op_load_fpr_QT1(QFPREG(rs2));
2634 tcg_gen_helper_0_0(helper_fabsq);
2635 gen_op_store_QT0_fpr(QFPREG(rd));
2637 case 0x81: /* V9 fstox */
2638 gen_op_load_fpr_FT1(rs2);
2639 gen_clear_float_exceptions();
2640 tcg_gen_helper_0_0(helper_fstox);
2641 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2642 gen_op_store_DT0_fpr(DFPREG(rd));
2644 case 0x82: /* V9 fdtox */
2645 gen_op_load_fpr_DT1(DFPREG(rs2));
2646 gen_clear_float_exceptions();
2647 tcg_gen_helper_0_0(helper_fdtox);
2648 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2649 gen_op_store_DT0_fpr(DFPREG(rd));
2651 case 0x83: /* V9 fqtox */
2652 CHECK_FPU_FEATURE(dc, FLOAT128);
2653 gen_op_load_fpr_QT1(QFPREG(rs2));
2654 gen_clear_float_exceptions();
2655 tcg_gen_helper_0_0(helper_fqtox);
2656 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2657 gen_op_store_DT0_fpr(DFPREG(rd));
2659 case 0x84: /* V9 fxtos */
2660 gen_op_load_fpr_DT1(DFPREG(rs2));
2661 gen_clear_float_exceptions();
2662 tcg_gen_helper_0_0(helper_fxtos);
2663 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2664 gen_op_store_FT0_fpr(rd);
2666 case 0x88: /* V9 fxtod */
2667 gen_op_load_fpr_DT1(DFPREG(rs2));
2668 gen_clear_float_exceptions();
2669 tcg_gen_helper_0_0(helper_fxtod);
2670 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2671 gen_op_store_DT0_fpr(DFPREG(rd));
2673 case 0x8c: /* V9 fxtoq */
2674 CHECK_FPU_FEATURE(dc, FLOAT128);
2675 gen_op_load_fpr_DT1(DFPREG(rs2));
2676 gen_clear_float_exceptions();
2677 tcg_gen_helper_0_0(helper_fxtoq);
2678 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2679 gen_op_store_QT0_fpr(QFPREG(rd));
2685 } else if (xop == 0x35) { /* FPU Operations */
2686 #ifdef TARGET_SPARC64
2689 if (gen_trap_ifnofpu(dc, cpu_cond))
2691 gen_op_clear_ieee_excp_and_FTT();
2692 rs1 = GET_FIELD(insn, 13, 17);
2693 rs2 = GET_FIELD(insn, 27, 31);
2694 xop = GET_FIELD(insn, 18, 26);
2695 #ifdef TARGET_SPARC64
2696 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2699 l1 = gen_new_label();
2700 cond = GET_FIELD_SP(insn, 14, 17);
2701 cpu_src1 = get_src1(insn, cpu_src1);
2702 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2704 gen_op_load_fpr_FT0(rs2);
2705 gen_op_store_FT0_fpr(rd);
2708 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2711 l1 = gen_new_label();
2712 cond = GET_FIELD_SP(insn, 14, 17);
2713 cpu_src1 = get_src1(insn, cpu_src1);
2714 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2716 gen_op_load_fpr_DT0(DFPREG(rs2));
2717 gen_op_store_DT0_fpr(DFPREG(rd));
2720 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2723 CHECK_FPU_FEATURE(dc, FLOAT128);
2724 l1 = gen_new_label();
2725 cond = GET_FIELD_SP(insn, 14, 17);
2726 cpu_src1 = get_src1(insn, cpu_src1);
2727 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2729 gen_op_load_fpr_QT0(QFPREG(rs2));
2730 gen_op_store_QT0_fpr(QFPREG(rd));
2736 #ifdef TARGET_SPARC64
2737 #define FMOVCC(size_FDQ, fcc) \
2742 l1 = gen_new_label(); \
2743 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2744 cond = GET_FIELD_SP(insn, 14, 17); \
2745 gen_fcond(r_cond, fcc, cond); \
2746 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2748 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2749 (glue(size_FDQ, FPREG(rs2))); \
2750 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2751 (glue(size_FDQ, FPREG(rd))); \
2752 gen_set_label(l1); \
2753 tcg_temp_free(r_cond); \
2755 case 0x001: /* V9 fmovscc %fcc0 */
2758 case 0x002: /* V9 fmovdcc %fcc0 */
2761 case 0x003: /* V9 fmovqcc %fcc0 */
2762 CHECK_FPU_FEATURE(dc, FLOAT128);
2765 case 0x041: /* V9 fmovscc %fcc1 */
2768 case 0x042: /* V9 fmovdcc %fcc1 */
2771 case 0x043: /* V9 fmovqcc %fcc1 */
2772 CHECK_FPU_FEATURE(dc, FLOAT128);
2775 case 0x081: /* V9 fmovscc %fcc2 */
2778 case 0x082: /* V9 fmovdcc %fcc2 */
2781 case 0x083: /* V9 fmovqcc %fcc2 */
2782 CHECK_FPU_FEATURE(dc, FLOAT128);
2785 case 0x0c1: /* V9 fmovscc %fcc3 */
2788 case 0x0c2: /* V9 fmovdcc %fcc3 */
2791 case 0x0c3: /* V9 fmovqcc %fcc3 */
2792 CHECK_FPU_FEATURE(dc, FLOAT128);
2796 #define FMOVCC(size_FDQ, icc) \
2801 l1 = gen_new_label(); \
2802 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2803 cond = GET_FIELD_SP(insn, 14, 17); \
2804 gen_cond(r_cond, icc, cond); \
2805 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2807 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2808 (glue(size_FDQ, FPREG(rs2))); \
2809 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2810 (glue(size_FDQ, FPREG(rd))); \
2811 gen_set_label(l1); \
2812 tcg_temp_free(r_cond); \
2815 case 0x101: /* V9 fmovscc %icc */
2818 case 0x102: /* V9 fmovdcc %icc */
2820 case 0x103: /* V9 fmovqcc %icc */
2821 CHECK_FPU_FEATURE(dc, FLOAT128);
2824 case 0x181: /* V9 fmovscc %xcc */
2827 case 0x182: /* V9 fmovdcc %xcc */
2830 case 0x183: /* V9 fmovqcc %xcc */
2831 CHECK_FPU_FEATURE(dc, FLOAT128);
2836 case 0x51: /* fcmps, V9 %fcc */
2837 gen_op_load_fpr_FT0(rs1);
2838 gen_op_load_fpr_FT1(rs2);
2839 gen_op_fcmps(rd & 3);
2841 case 0x52: /* fcmpd, V9 %fcc */
2842 gen_op_load_fpr_DT0(DFPREG(rs1));
2843 gen_op_load_fpr_DT1(DFPREG(rs2));
2844 gen_op_fcmpd(rd & 3);
2846 case 0x53: /* fcmpq, V9 %fcc */
2847 CHECK_FPU_FEATURE(dc, FLOAT128);
2848 gen_op_load_fpr_QT0(QFPREG(rs1));
2849 gen_op_load_fpr_QT1(QFPREG(rs2));
2850 gen_op_fcmpq(rd & 3);
2852 case 0x55: /* fcmpes, V9 %fcc */
2853 gen_op_load_fpr_FT0(rs1);
2854 gen_op_load_fpr_FT1(rs2);
2855 gen_op_fcmpes(rd & 3);
2857 case 0x56: /* fcmped, V9 %fcc */
2858 gen_op_load_fpr_DT0(DFPREG(rs1));
2859 gen_op_load_fpr_DT1(DFPREG(rs2));
2860 gen_op_fcmped(rd & 3);
2862 case 0x57: /* fcmpeq, V9 %fcc */
2863 CHECK_FPU_FEATURE(dc, FLOAT128);
2864 gen_op_load_fpr_QT0(QFPREG(rs1));
2865 gen_op_load_fpr_QT1(QFPREG(rs2));
2866 gen_op_fcmpeq(rd & 3);
2871 } else if (xop == 0x2) {
2874 rs1 = GET_FIELD(insn, 13, 17);
2876 // or %g0, x, y -> mov T0, x; mov y, T0
2877 if (IS_IMM) { /* immediate */
2880 rs2 = GET_FIELDs(insn, 19, 31);
2881 r_const = tcg_const_tl((int)rs2);
2882 gen_movl_TN_reg(rd, r_const);
2883 tcg_temp_free(r_const);
2884 } else { /* register */
2885 rs2 = GET_FIELD(insn, 27, 31);
2886 gen_movl_reg_TN(rs2, cpu_dst);
2887 gen_movl_TN_reg(rd, cpu_dst);
2890 cpu_src1 = get_src1(insn, cpu_src1);
2891 if (IS_IMM) { /* immediate */
2892 rs2 = GET_FIELDs(insn, 19, 31);
2893 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2894 gen_movl_TN_reg(rd, cpu_dst);
2895 } else { /* register */
2896 // or x, %g0, y -> mov T1, x; mov y, T1
2897 rs2 = GET_FIELD(insn, 27, 31);
2899 gen_movl_reg_TN(rs2, cpu_src2);
2900 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2901 gen_movl_TN_reg(rd, cpu_dst);
2903 gen_movl_TN_reg(rd, cpu_src1);
2906 #ifdef TARGET_SPARC64
2907 } else if (xop == 0x25) { /* sll, V9 sllx */
2908 cpu_src1 = get_src1(insn, cpu_src1);
2909 if (IS_IMM) { /* immediate */
2910 rs2 = GET_FIELDs(insn, 20, 31);
2911 if (insn & (1 << 12)) {
2912 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2914 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2915 tcg_gen_shli_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2917 } else { /* register */
2918 rs2 = GET_FIELD(insn, 27, 31);
2919 gen_movl_reg_TN(rs2, cpu_src2);
2920 if (insn & (1 << 12)) {
2921 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2922 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2924 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2925 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2926 tcg_gen_shl_i64(cpu_dst, cpu_dst, cpu_tmp0);
2929 gen_movl_TN_reg(rd, cpu_dst);
2930 } else if (xop == 0x26) { /* srl, V9 srlx */
2931 cpu_src1 = get_src1(insn, cpu_src1);
2932 if (IS_IMM) { /* immediate */
2933 rs2 = GET_FIELDs(insn, 20, 31);
2934 if (insn & (1 << 12)) {
2935 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2937 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2938 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2940 } else { /* register */
2941 rs2 = GET_FIELD(insn, 27, 31);
2942 gen_movl_reg_TN(rs2, cpu_src2);
2943 if (insn & (1 << 12)) {
2944 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2945 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2947 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2948 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2949 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2952 gen_movl_TN_reg(rd, cpu_dst);
2953 } else if (xop == 0x27) { /* sra, V9 srax */
2954 cpu_src1 = get_src1(insn, cpu_src1);
2955 if (IS_IMM) { /* immediate */
2956 rs2 = GET_FIELDs(insn, 20, 31);
2957 if (insn & (1 << 12)) {
2958 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2960 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2961 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2962 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2964 } else { /* register */
2965 rs2 = GET_FIELD(insn, 27, 31);
2966 gen_movl_reg_TN(rs2, cpu_src2);
2967 if (insn & (1 << 12)) {
2968 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2969 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2971 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2972 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2973 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2976 gen_movl_TN_reg(rd, cpu_dst);
2978 } else if (xop < 0x36) {
2979 cpu_src1 = get_src1(insn, cpu_src1);
2980 cpu_src2 = get_src2(insn, cpu_src2);
2982 switch (xop & ~0x10) {
2985 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2987 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2990 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
2992 gen_op_logic_cc(cpu_dst);
2995 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2997 gen_op_logic_cc(cpu_dst);
3000 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3002 gen_op_logic_cc(cpu_dst);
3006 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
3008 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
3011 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3012 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
3014 gen_op_logic_cc(cpu_dst);
3017 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3018 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
3020 gen_op_logic_cc(cpu_dst);
3023 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3024 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
3026 gen_op_logic_cc(cpu_dst);
3030 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3032 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3033 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3034 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3037 #ifdef TARGET_SPARC64
3038 case 0x9: /* V9 mulx */
3039 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3043 CHECK_IU_FEATURE(dc, MUL);
3044 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3046 gen_op_logic_cc(cpu_dst);
3049 CHECK_IU_FEATURE(dc, MUL);
3050 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3052 gen_op_logic_cc(cpu_dst);
3056 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3058 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3059 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3060 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3063 #ifdef TARGET_SPARC64
3064 case 0xd: /* V9 udivx */
3065 tcg_gen_mov_tl(cpu_cc_src, cpu_src1);
3066 tcg_gen_mov_tl(cpu_cc_src2, cpu_src2);
3067 gen_trap_ifdivzero_tl(cpu_cc_src2);
3068 tcg_gen_divu_i64(cpu_dst, cpu_cc_src, cpu_cc_src2);
3072 CHECK_IU_FEATURE(dc, DIV);
3073 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1,
3076 gen_op_div_cc(cpu_dst);
3079 CHECK_IU_FEATURE(dc, DIV);
3080 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1,
3083 gen_op_div_cc(cpu_dst);
3088 gen_movl_TN_reg(rd, cpu_dst);
3091 case 0x20: /* taddcc */
3092 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3093 gen_movl_TN_reg(rd, cpu_dst);
3095 case 0x21: /* tsubcc */
3096 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3097 gen_movl_TN_reg(rd, cpu_dst);
3099 case 0x22: /* taddcctv */
3100 save_state(dc, cpu_cond);
3101 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3102 gen_movl_TN_reg(rd, cpu_dst);
3104 case 0x23: /* tsubcctv */
3105 save_state(dc, cpu_cond);
3106 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3107 gen_movl_TN_reg(rd, cpu_dst);
3109 case 0x24: /* mulscc */
3110 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3111 gen_movl_TN_reg(rd, cpu_dst);
3113 #ifndef TARGET_SPARC64
3114 case 0x25: /* sll */
3115 if (IS_IMM) { /* immediate */
3116 rs2 = GET_FIELDs(insn, 20, 31);
3117 tcg_gen_shli_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3118 } else { /* register */
3119 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3120 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3122 gen_movl_TN_reg(rd, cpu_dst);
3124 case 0x26: /* srl */
3125 if (IS_IMM) { /* immediate */
3126 rs2 = GET_FIELDs(insn, 20, 31);
3127 tcg_gen_shri_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3128 } else { /* register */
3129 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3130 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3132 gen_movl_TN_reg(rd, cpu_dst);
3134 case 0x27: /* sra */
3135 if (IS_IMM) { /* immediate */
3136 rs2 = GET_FIELDs(insn, 20, 31);
3137 tcg_gen_sari_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3138 } else { /* register */
3139 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3140 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3142 gen_movl_TN_reg(rd, cpu_dst);
3149 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3150 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3151 offsetof(CPUSPARCState, y));
3153 #ifndef TARGET_SPARC64
3154 case 0x01 ... 0x0f: /* undefined in the
3158 case 0x10 ... 0x1f: /* implementation-dependent
3164 case 0x2: /* V9 wrccr */
3165 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3166 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3168 case 0x3: /* V9 wrasi */
3169 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3170 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3171 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3172 offsetof(CPUSPARCState, asi));
3174 case 0x6: /* V9 wrfprs */
3175 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3176 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3177 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3178 offsetof(CPUSPARCState, fprs));
3179 save_state(dc, cpu_cond);
3184 case 0xf: /* V9 sir, nop if user */
3185 #if !defined(CONFIG_USER_ONLY)
3190 case 0x13: /* Graphics Status */
3191 if (gen_trap_ifnofpu(dc, cpu_cond))
3193 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3194 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3195 offsetof(CPUSPARCState, gsr));
3197 case 0x17: /* Tick compare */
3198 #if !defined(CONFIG_USER_ONLY)
3199 if (!supervisor(dc))
3205 tcg_gen_xor_tl(cpu_tmp0, cpu_src1,
3207 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3208 offsetof(CPUSPARCState,
3210 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3211 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3212 offsetof(CPUState, tick));
3213 tcg_gen_helper_0_2(helper_tick_set_limit,
3214 r_tickptr, cpu_tmp0);
3215 tcg_temp_free(r_tickptr);
3218 case 0x18: /* System tick */
3219 #if !defined(CONFIG_USER_ONLY)
3220 if (!supervisor(dc))
3226 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3228 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3229 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3230 offsetof(CPUState, stick));
3231 tcg_gen_helper_0_2(helper_tick_set_count,
3232 r_tickptr, cpu_dst);
3233 tcg_temp_free(r_tickptr);
3236 case 0x19: /* System tick compare */
3237 #if !defined(CONFIG_USER_ONLY)
3238 if (!supervisor(dc))
3244 tcg_gen_xor_tl(cpu_tmp0, cpu_src1,
3246 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3247 offsetof(CPUSPARCState,
3249 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3250 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3251 offsetof(CPUState, stick));
3252 tcg_gen_helper_0_2(helper_tick_set_limit,
3253 r_tickptr, cpu_tmp0);
3254 tcg_temp_free(r_tickptr);
3258 case 0x10: /* Performance Control */
3259 case 0x11: /* Performance Instrumentation
3261 case 0x12: /* Dispatch Control */
3262 case 0x14: /* Softint set */
3263 case 0x15: /* Softint clear */
3264 case 0x16: /* Softint write */
3271 #if !defined(CONFIG_USER_ONLY)
3272 case 0x31: /* wrpsr, V9 saved, restored */
3274 if (!supervisor(dc))
3276 #ifdef TARGET_SPARC64
3279 tcg_gen_helper_0_0(helper_saved);
3282 tcg_gen_helper_0_0(helper_restored);
3284 case 2: /* UA2005 allclean */
3285 case 3: /* UA2005 otherw */
3286 case 4: /* UA2005 normalw */
3287 case 5: /* UA2005 invalw */
3293 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3294 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3295 save_state(dc, cpu_cond);
3302 case 0x32: /* wrwim, V9 wrpr */
3304 if (!supervisor(dc))
3306 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3307 #ifdef TARGET_SPARC64
3313 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3314 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3315 offsetof(CPUState, tsptr));
3316 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3317 offsetof(trap_state, tpc));
3318 tcg_temp_free(r_tsptr);
3325 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3326 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3327 offsetof(CPUState, tsptr));
3328 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3329 offsetof(trap_state, tnpc));
3330 tcg_temp_free(r_tsptr);
3337 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3338 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3339 offsetof(CPUState, tsptr));
3340 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3341 offsetof(trap_state,
3343 tcg_temp_free(r_tsptr);
3350 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3351 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3352 offsetof(CPUState, tsptr));
3353 tcg_gen_st_i32(cpu_tmp0, r_tsptr,
3354 offsetof(trap_state, tt));
3355 tcg_temp_free(r_tsptr);
3362 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3363 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3364 offsetof(CPUState, tick));
3365 tcg_gen_helper_0_2(helper_tick_set_count,
3366 r_tickptr, cpu_tmp0);
3367 tcg_temp_free(r_tickptr);
3371 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3372 offsetof(CPUSPARCState, tbr));
3375 save_state(dc, cpu_cond);
3376 tcg_gen_helper_0_1(helper_wrpstate, cpu_tmp0);
3382 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3383 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3384 offsetof(CPUSPARCState, tl));
3387 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3388 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3389 offsetof(CPUSPARCState,
3393 tcg_gen_helper_0_1(helper_wrcwp, cpu_tmp0);
3396 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3397 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3398 offsetof(CPUSPARCState,
3401 case 11: // canrestore
3402 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3403 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3404 offsetof(CPUSPARCState,
3407 case 12: // cleanwin
3408 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3409 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3410 offsetof(CPUSPARCState,
3413 case 13: // otherwin
3414 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3415 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3416 offsetof(CPUSPARCState,
3420 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3421 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3422 offsetof(CPUSPARCState,
3425 case 16: // UA2005 gl
3426 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3427 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3428 offsetof(CPUSPARCState, gl));
3430 case 26: // UA2005 strand status
3431 if (!hypervisor(dc))
3433 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3434 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3435 offsetof(CPUSPARCState, ssr));
3441 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3442 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3443 offsetof(CPUSPARCState, wim));
3447 case 0x33: /* wrtbr, UA2005 wrhpr */
3449 #ifndef TARGET_SPARC64
3450 if (!supervisor(dc))
3452 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3453 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3454 offsetof(CPUSPARCState, tbr));
3456 if (!hypervisor(dc))
3458 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3461 // XXX gen_op_wrhpstate();
3462 save_state(dc, cpu_cond);
3468 // XXX gen_op_wrhtstate();
3471 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3472 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3473 offsetof(CPUSPARCState, hintp));
3476 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3477 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3478 offsetof(CPUSPARCState, htba));
3480 case 31: // hstick_cmpr
3484 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3485 offsetof(CPUSPARCState,
3487 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3488 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3489 offsetof(CPUState, hstick));
3490 tcg_gen_helper_0_2(helper_tick_set_limit,
3491 r_tickptr, cpu_tmp0);
3492 tcg_temp_free(r_tickptr);
3495 case 6: // hver readonly
3503 #ifdef TARGET_SPARC64
3504 case 0x2c: /* V9 movcc */
3506 int cc = GET_FIELD_SP(insn, 11, 12);
3507 int cond = GET_FIELD_SP(insn, 14, 17);
3511 r_cond = tcg_temp_new(TCG_TYPE_TL);
3512 if (insn & (1 << 18)) {
3514 gen_cond(r_cond, 0, cond);
3516 gen_cond(r_cond, 1, cond);
3520 gen_fcond(r_cond, cc, cond);
3523 l1 = gen_new_label();
3525 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3526 if (IS_IMM) { /* immediate */
3529 rs2 = GET_FIELD_SPs(insn, 0, 10);
3530 r_const = tcg_const_tl((int)rs2);
3531 gen_movl_TN_reg(rd, r_const);
3532 tcg_temp_free(r_const);
3534 rs2 = GET_FIELD_SP(insn, 0, 4);
3535 gen_movl_reg_TN(rs2, cpu_tmp0);
3536 gen_movl_TN_reg(rd, cpu_tmp0);
3539 tcg_temp_free(r_cond);
3542 case 0x2d: /* V9 sdivx */
3543 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3544 gen_movl_TN_reg(rd, cpu_dst);
3546 case 0x2e: /* V9 popc */
3548 cpu_src2 = get_src2(insn, cpu_src2);
3549 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3551 gen_movl_TN_reg(rd, cpu_dst);
3553 case 0x2f: /* V9 movr */
3555 int cond = GET_FIELD_SP(insn, 10, 12);
3558 cpu_src1 = get_src1(insn, cpu_src1);
3560 l1 = gen_new_label();
3562 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
3564 if (IS_IMM) { /* immediate */
3567 rs2 = GET_FIELD_SPs(insn, 0, 9);
3568 r_const = tcg_const_tl((int)rs2);
3569 gen_movl_TN_reg(rd, r_const);
3570 tcg_temp_free(r_const);
3572 rs2 = GET_FIELD_SP(insn, 0, 4);
3573 gen_movl_reg_TN(rs2, cpu_tmp0);
3574 gen_movl_TN_reg(rd, cpu_tmp0);
3584 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3585 #ifdef TARGET_SPARC64
3586 int opf = GET_FIELD_SP(insn, 5, 13);
3587 rs1 = GET_FIELD(insn, 13, 17);
3588 rs2 = GET_FIELD(insn, 27, 31);
3589 if (gen_trap_ifnofpu(dc, cpu_cond))
3593 case 0x000: /* VIS I edge8cc */
3594 case 0x001: /* VIS II edge8n */
3595 case 0x002: /* VIS I edge8lcc */
3596 case 0x003: /* VIS II edge8ln */
3597 case 0x004: /* VIS I edge16cc */
3598 case 0x005: /* VIS II edge16n */
3599 case 0x006: /* VIS I edge16lcc */
3600 case 0x007: /* VIS II edge16ln */
3601 case 0x008: /* VIS I edge32cc */
3602 case 0x009: /* VIS II edge32n */
3603 case 0x00a: /* VIS I edge32lcc */
3604 case 0x00b: /* VIS II edge32ln */
3607 case 0x010: /* VIS I array8 */
3608 CHECK_FPU_FEATURE(dc, VIS1);
3609 cpu_src1 = get_src1(insn, cpu_src1);
3610 gen_movl_reg_TN(rs2, cpu_src2);
3611 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3613 gen_movl_TN_reg(rd, cpu_dst);
3615 case 0x012: /* VIS I array16 */
3616 CHECK_FPU_FEATURE(dc, VIS1);
3617 cpu_src1 = get_src1(insn, cpu_src1);
3618 gen_movl_reg_TN(rs2, cpu_src2);
3619 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3621 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3622 gen_movl_TN_reg(rd, cpu_dst);
3624 case 0x014: /* VIS I array32 */
3625 CHECK_FPU_FEATURE(dc, VIS1);
3626 cpu_src1 = get_src1(insn, cpu_src1);
3627 gen_movl_reg_TN(rs2, cpu_src2);
3628 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3630 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3631 gen_movl_TN_reg(rd, cpu_dst);
3633 case 0x018: /* VIS I alignaddr */
3634 CHECK_FPU_FEATURE(dc, VIS1);
3635 cpu_src1 = get_src1(insn, cpu_src1);
3636 gen_movl_reg_TN(rs2, cpu_src2);
3637 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3639 gen_movl_TN_reg(rd, cpu_dst);
3641 case 0x019: /* VIS II bmask */
3642 case 0x01a: /* VIS I alignaddrl */
3645 case 0x020: /* VIS I fcmple16 */
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_fcmple16);
3650 gen_op_store_DT0_fpr(DFPREG(rd));
3652 case 0x022: /* VIS I fcmpne16 */
3653 CHECK_FPU_FEATURE(dc, VIS1);
3654 gen_op_load_fpr_DT0(DFPREG(rs1));
3655 gen_op_load_fpr_DT1(DFPREG(rs2));
3656 tcg_gen_helper_0_0(helper_fcmpne16);
3657 gen_op_store_DT0_fpr(DFPREG(rd));
3659 case 0x024: /* VIS I fcmple32 */
3660 CHECK_FPU_FEATURE(dc, VIS1);
3661 gen_op_load_fpr_DT0(DFPREG(rs1));
3662 gen_op_load_fpr_DT1(DFPREG(rs2));
3663 tcg_gen_helper_0_0(helper_fcmple32);
3664 gen_op_store_DT0_fpr(DFPREG(rd));
3666 case 0x026: /* VIS I fcmpne32 */
3667 CHECK_FPU_FEATURE(dc, VIS1);
3668 gen_op_load_fpr_DT0(DFPREG(rs1));
3669 gen_op_load_fpr_DT1(DFPREG(rs2));
3670 tcg_gen_helper_0_0(helper_fcmpne32);
3671 gen_op_store_DT0_fpr(DFPREG(rd));
3673 case 0x028: /* VIS I fcmpgt16 */
3674 CHECK_FPU_FEATURE(dc, VIS1);
3675 gen_op_load_fpr_DT0(DFPREG(rs1));
3676 gen_op_load_fpr_DT1(DFPREG(rs2));
3677 tcg_gen_helper_0_0(helper_fcmpgt16);
3678 gen_op_store_DT0_fpr(DFPREG(rd));
3680 case 0x02a: /* VIS I fcmpeq16 */
3681 CHECK_FPU_FEATURE(dc, VIS1);
3682 gen_op_load_fpr_DT0(DFPREG(rs1));
3683 gen_op_load_fpr_DT1(DFPREG(rs2));
3684 tcg_gen_helper_0_0(helper_fcmpeq16);
3685 gen_op_store_DT0_fpr(DFPREG(rd));
3687 case 0x02c: /* VIS I fcmpgt32 */
3688 CHECK_FPU_FEATURE(dc, VIS1);
3689 gen_op_load_fpr_DT0(DFPREG(rs1));
3690 gen_op_load_fpr_DT1(DFPREG(rs2));
3691 tcg_gen_helper_0_0(helper_fcmpgt32);
3692 gen_op_store_DT0_fpr(DFPREG(rd));
3694 case 0x02e: /* VIS I fcmpeq32 */
3695 CHECK_FPU_FEATURE(dc, VIS1);
3696 gen_op_load_fpr_DT0(DFPREG(rs1));
3697 gen_op_load_fpr_DT1(DFPREG(rs2));
3698 tcg_gen_helper_0_0(helper_fcmpeq32);
3699 gen_op_store_DT0_fpr(DFPREG(rd));
3701 case 0x031: /* VIS I fmul8x16 */
3702 CHECK_FPU_FEATURE(dc, VIS1);
3703 gen_op_load_fpr_DT0(DFPREG(rs1));
3704 gen_op_load_fpr_DT1(DFPREG(rs2));
3705 tcg_gen_helper_0_0(helper_fmul8x16);
3706 gen_op_store_DT0_fpr(DFPREG(rd));
3708 case 0x033: /* VIS I fmul8x16au */
3709 CHECK_FPU_FEATURE(dc, VIS1);
3710 gen_op_load_fpr_DT0(DFPREG(rs1));
3711 gen_op_load_fpr_DT1(DFPREG(rs2));
3712 tcg_gen_helper_0_0(helper_fmul8x16au);
3713 gen_op_store_DT0_fpr(DFPREG(rd));
3715 case 0x035: /* VIS I fmul8x16al */
3716 CHECK_FPU_FEATURE(dc, VIS1);
3717 gen_op_load_fpr_DT0(DFPREG(rs1));
3718 gen_op_load_fpr_DT1(DFPREG(rs2));
3719 tcg_gen_helper_0_0(helper_fmul8x16al);
3720 gen_op_store_DT0_fpr(DFPREG(rd));
3722 case 0x036: /* VIS I fmul8sux16 */
3723 CHECK_FPU_FEATURE(dc, VIS1);
3724 gen_op_load_fpr_DT0(DFPREG(rs1));
3725 gen_op_load_fpr_DT1(DFPREG(rs2));
3726 tcg_gen_helper_0_0(helper_fmul8sux16);
3727 gen_op_store_DT0_fpr(DFPREG(rd));
3729 case 0x037: /* VIS I fmul8ulx16 */
3730 CHECK_FPU_FEATURE(dc, VIS1);
3731 gen_op_load_fpr_DT0(DFPREG(rs1));
3732 gen_op_load_fpr_DT1(DFPREG(rs2));
3733 tcg_gen_helper_0_0(helper_fmul8ulx16);
3734 gen_op_store_DT0_fpr(DFPREG(rd));
3736 case 0x038: /* VIS I fmuld8sux16 */
3737 CHECK_FPU_FEATURE(dc, VIS1);
3738 gen_op_load_fpr_DT0(DFPREG(rs1));
3739 gen_op_load_fpr_DT1(DFPREG(rs2));
3740 tcg_gen_helper_0_0(helper_fmuld8sux16);
3741 gen_op_store_DT0_fpr(DFPREG(rd));
3743 case 0x039: /* VIS I fmuld8ulx16 */
3744 CHECK_FPU_FEATURE(dc, VIS1);
3745 gen_op_load_fpr_DT0(DFPREG(rs1));
3746 gen_op_load_fpr_DT1(DFPREG(rs2));
3747 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3748 gen_op_store_DT0_fpr(DFPREG(rd));
3750 case 0x03a: /* VIS I fpack32 */
3751 case 0x03b: /* VIS I fpack16 */
3752 case 0x03d: /* VIS I fpackfix */
3753 case 0x03e: /* VIS I pdist */
3756 case 0x048: /* VIS I faligndata */
3757 CHECK_FPU_FEATURE(dc, VIS1);
3758 gen_op_load_fpr_DT0(DFPREG(rs1));
3759 gen_op_load_fpr_DT1(DFPREG(rs2));
3760 tcg_gen_helper_0_0(helper_faligndata);
3761 gen_op_store_DT0_fpr(DFPREG(rd));
3763 case 0x04b: /* VIS I fpmerge */
3764 CHECK_FPU_FEATURE(dc, VIS1);
3765 gen_op_load_fpr_DT0(DFPREG(rs1));
3766 gen_op_load_fpr_DT1(DFPREG(rs2));
3767 tcg_gen_helper_0_0(helper_fpmerge);
3768 gen_op_store_DT0_fpr(DFPREG(rd));
3770 case 0x04c: /* VIS II bshuffle */
3773 case 0x04d: /* VIS I fexpand */
3774 CHECK_FPU_FEATURE(dc, VIS1);
3775 gen_op_load_fpr_DT0(DFPREG(rs1));
3776 gen_op_load_fpr_DT1(DFPREG(rs2));
3777 tcg_gen_helper_0_0(helper_fexpand);
3778 gen_op_store_DT0_fpr(DFPREG(rd));
3780 case 0x050: /* VIS I fpadd16 */
3781 CHECK_FPU_FEATURE(dc, VIS1);
3782 gen_op_load_fpr_DT0(DFPREG(rs1));
3783 gen_op_load_fpr_DT1(DFPREG(rs2));
3784 tcg_gen_helper_0_0(helper_fpadd16);
3785 gen_op_store_DT0_fpr(DFPREG(rd));
3787 case 0x051: /* VIS I fpadd16s */
3788 CHECK_FPU_FEATURE(dc, VIS1);
3789 gen_op_load_fpr_FT0(rs1);
3790 gen_op_load_fpr_FT1(rs2);
3791 tcg_gen_helper_0_0(helper_fpadd16s);
3792 gen_op_store_FT0_fpr(rd);
3794 case 0x052: /* VIS I fpadd32 */
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_fpadd32);
3799 gen_op_store_DT0_fpr(DFPREG(rd));
3801 case 0x053: /* VIS I fpadd32s */
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_fpadd32s);
3806 gen_op_store_FT0_fpr(rd);
3808 case 0x054: /* VIS I fpsub16 */
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_fpsub16);
3813 gen_op_store_DT0_fpr(DFPREG(rd));
3815 case 0x055: /* VIS I fpsub16s */
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_fpsub16s);
3820 gen_op_store_FT0_fpr(rd);
3822 case 0x056: /* VIS I fpsub32 */
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_fpadd32);
3827 gen_op_store_DT0_fpr(DFPREG(rd));
3829 case 0x057: /* VIS I fpsub32s */
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_fpsub32s);
3834 gen_op_store_FT0_fpr(rd);
3836 case 0x060: /* VIS I fzero */
3837 CHECK_FPU_FEATURE(dc, VIS1);
3838 tcg_gen_helper_0_0(helper_movl_DT0_0);
3839 gen_op_store_DT0_fpr(DFPREG(rd));
3841 case 0x061: /* VIS I fzeros */
3842 CHECK_FPU_FEATURE(dc, VIS1);
3843 tcg_gen_helper_0_0(helper_movl_FT0_0);
3844 gen_op_store_FT0_fpr(rd);
3846 case 0x062: /* VIS I fnor */
3847 CHECK_FPU_FEATURE(dc, VIS1);
3848 gen_op_load_fpr_DT0(DFPREG(rs1));
3849 gen_op_load_fpr_DT1(DFPREG(rs2));
3850 tcg_gen_helper_0_0(helper_fnor);
3851 gen_op_store_DT0_fpr(DFPREG(rd));
3853 case 0x063: /* VIS I fnors */
3854 CHECK_FPU_FEATURE(dc, VIS1);
3855 gen_op_load_fpr_FT0(rs1);
3856 gen_op_load_fpr_FT1(rs2);
3857 tcg_gen_helper_0_0(helper_fnors);
3858 gen_op_store_FT0_fpr(rd);
3860 case 0x064: /* VIS I fandnot2 */
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_fandnot);
3865 gen_op_store_DT0_fpr(DFPREG(rd));
3867 case 0x065: /* VIS I fandnot2s */
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_fandnots);
3872 gen_op_store_FT0_fpr(rd);
3874 case 0x066: /* VIS I fnot2 */
3875 CHECK_FPU_FEATURE(dc, VIS1);
3876 gen_op_load_fpr_DT1(DFPREG(rs2));
3877 tcg_gen_helper_0_0(helper_fnot);
3878 gen_op_store_DT0_fpr(DFPREG(rd));
3880 case 0x067: /* VIS I fnot2s */
3881 CHECK_FPU_FEATURE(dc, VIS1);
3882 gen_op_load_fpr_FT1(rs2);
3883 tcg_gen_helper_0_0(helper_fnot);
3884 gen_op_store_FT0_fpr(rd);
3886 case 0x068: /* VIS I fandnot1 */
3887 CHECK_FPU_FEATURE(dc, VIS1);
3888 gen_op_load_fpr_DT0(DFPREG(rs1));
3889 gen_op_load_fpr_DT1(DFPREG(rs2));
3890 tcg_gen_helper_0_0(helper_fandnot);
3891 gen_op_store_DT0_fpr(DFPREG(rd));
3893 case 0x069: /* VIS I fandnot1s */
3894 CHECK_FPU_FEATURE(dc, VIS1);
3895 gen_op_load_fpr_FT0(rs1);
3896 gen_op_load_fpr_FT1(rs2);
3897 tcg_gen_helper_0_0(helper_fandnots);
3898 gen_op_store_FT0_fpr(rd);
3900 case 0x06a: /* VIS I fnot1 */
3901 CHECK_FPU_FEATURE(dc, VIS1);
3902 gen_op_load_fpr_DT1(DFPREG(rs1));
3903 tcg_gen_helper_0_0(helper_fnot);
3904 gen_op_store_DT0_fpr(DFPREG(rd));
3906 case 0x06b: /* VIS I fnot1s */
3907 CHECK_FPU_FEATURE(dc, VIS1);
3908 gen_op_load_fpr_FT1(rs1);
3909 tcg_gen_helper_0_0(helper_fnot);
3910 gen_op_store_FT0_fpr(rd);
3912 case 0x06c: /* VIS I fxor */
3913 CHECK_FPU_FEATURE(dc, VIS1);
3914 gen_op_load_fpr_DT0(DFPREG(rs1));
3915 gen_op_load_fpr_DT1(DFPREG(rs2));
3916 tcg_gen_helper_0_0(helper_fxor);
3917 gen_op_store_DT0_fpr(DFPREG(rd));
3919 case 0x06d: /* VIS I fxors */
3920 CHECK_FPU_FEATURE(dc, VIS1);
3921 gen_op_load_fpr_FT0(rs1);
3922 gen_op_load_fpr_FT1(rs2);
3923 tcg_gen_helper_0_0(helper_fxors);
3924 gen_op_store_FT0_fpr(rd);
3926 case 0x06e: /* VIS I fnand */
3927 CHECK_FPU_FEATURE(dc, VIS1);
3928 gen_op_load_fpr_DT0(DFPREG(rs1));
3929 gen_op_load_fpr_DT1(DFPREG(rs2));
3930 tcg_gen_helper_0_0(helper_fnand);
3931 gen_op_store_DT0_fpr(DFPREG(rd));
3933 case 0x06f: /* VIS I fnands */
3934 CHECK_FPU_FEATURE(dc, VIS1);
3935 gen_op_load_fpr_FT0(rs1);
3936 gen_op_load_fpr_FT1(rs2);
3937 tcg_gen_helper_0_0(helper_fnands);
3938 gen_op_store_FT0_fpr(rd);
3940 case 0x070: /* VIS I fand */
3941 CHECK_FPU_FEATURE(dc, VIS1);
3942 gen_op_load_fpr_DT0(DFPREG(rs1));
3943 gen_op_load_fpr_DT1(DFPREG(rs2));
3944 tcg_gen_helper_0_0(helper_fand);
3945 gen_op_store_DT0_fpr(DFPREG(rd));
3947 case 0x071: /* VIS I fands */
3948 CHECK_FPU_FEATURE(dc, VIS1);
3949 gen_op_load_fpr_FT0(rs1);
3950 gen_op_load_fpr_FT1(rs2);
3951 tcg_gen_helper_0_0(helper_fands);
3952 gen_op_store_FT0_fpr(rd);
3954 case 0x072: /* VIS I fxnor */
3955 CHECK_FPU_FEATURE(dc, VIS1);
3956 gen_op_load_fpr_DT0(DFPREG(rs1));
3957 gen_op_load_fpr_DT1(DFPREG(rs2));
3958 tcg_gen_helper_0_0(helper_fxnor);
3959 gen_op_store_DT0_fpr(DFPREG(rd));
3961 case 0x073: /* VIS I fxnors */
3962 CHECK_FPU_FEATURE(dc, VIS1);
3963 gen_op_load_fpr_FT0(rs1);
3964 gen_op_load_fpr_FT1(rs2);
3965 tcg_gen_helper_0_0(helper_fxnors);
3966 gen_op_store_FT0_fpr(rd);
3968 case 0x074: /* VIS I fsrc1 */
3969 CHECK_FPU_FEATURE(dc, VIS1);
3970 gen_op_load_fpr_DT0(DFPREG(rs1));
3971 gen_op_store_DT0_fpr(DFPREG(rd));
3973 case 0x075: /* VIS I fsrc1s */
3974 CHECK_FPU_FEATURE(dc, VIS1);
3975 gen_op_load_fpr_FT0(rs1);
3976 gen_op_store_FT0_fpr(rd);
3978 case 0x076: /* VIS I fornot2 */
3979 CHECK_FPU_FEATURE(dc, VIS1);
3980 gen_op_load_fpr_DT1(DFPREG(rs1));
3981 gen_op_load_fpr_DT0(DFPREG(rs2));
3982 tcg_gen_helper_0_0(helper_fornot);
3983 gen_op_store_DT0_fpr(DFPREG(rd));
3985 case 0x077: /* VIS I fornot2s */
3986 CHECK_FPU_FEATURE(dc, VIS1);
3987 gen_op_load_fpr_FT1(rs1);
3988 gen_op_load_fpr_FT0(rs2);
3989 tcg_gen_helper_0_0(helper_fornots);
3990 gen_op_store_FT0_fpr(rd);
3992 case 0x078: /* VIS I fsrc2 */
3993 CHECK_FPU_FEATURE(dc, VIS1);
3994 gen_op_load_fpr_DT0(DFPREG(rs2));
3995 gen_op_store_DT0_fpr(DFPREG(rd));
3997 case 0x079: /* VIS I fsrc2s */
3998 CHECK_FPU_FEATURE(dc, VIS1);
3999 gen_op_load_fpr_FT0(rs2);
4000 gen_op_store_FT0_fpr(rd);
4002 case 0x07a: /* VIS I fornot1 */
4003 CHECK_FPU_FEATURE(dc, VIS1);
4004 gen_op_load_fpr_DT0(DFPREG(rs1));
4005 gen_op_load_fpr_DT1(DFPREG(rs2));
4006 tcg_gen_helper_0_0(helper_fornot);
4007 gen_op_store_DT0_fpr(DFPREG(rd));
4009 case 0x07b: /* VIS I fornot1s */
4010 CHECK_FPU_FEATURE(dc, VIS1);
4011 gen_op_load_fpr_FT0(rs1);
4012 gen_op_load_fpr_FT1(rs2);
4013 tcg_gen_helper_0_0(helper_fornots);
4014 gen_op_store_FT0_fpr(rd);
4016 case 0x07c: /* VIS I for */
4017 CHECK_FPU_FEATURE(dc, VIS1);
4018 gen_op_load_fpr_DT0(DFPREG(rs1));
4019 gen_op_load_fpr_DT1(DFPREG(rs2));
4020 tcg_gen_helper_0_0(helper_for);
4021 gen_op_store_DT0_fpr(DFPREG(rd));
4023 case 0x07d: /* VIS I fors */
4024 CHECK_FPU_FEATURE(dc, VIS1);
4025 gen_op_load_fpr_FT0(rs1);
4026 gen_op_load_fpr_FT1(rs2);
4027 tcg_gen_helper_0_0(helper_fors);
4028 gen_op_store_FT0_fpr(rd);
4030 case 0x07e: /* VIS I fone */
4031 CHECK_FPU_FEATURE(dc, VIS1);
4032 tcg_gen_helper_0_0(helper_movl_DT0_1);
4033 gen_op_store_DT0_fpr(DFPREG(rd));
4035 case 0x07f: /* VIS I fones */
4036 CHECK_FPU_FEATURE(dc, VIS1);
4037 tcg_gen_helper_0_0(helper_movl_FT0_1);
4038 gen_op_store_FT0_fpr(rd);
4040 case 0x080: /* VIS I shutdown */
4041 case 0x081: /* VIS II siam */
4050 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4051 #ifdef TARGET_SPARC64
4056 #ifdef TARGET_SPARC64
4057 } else if (xop == 0x39) { /* V9 return */
4060 save_state(dc, cpu_cond);
4061 cpu_src1 = get_src1(insn, cpu_src1);
4062 if (IS_IMM) { /* immediate */
4063 rs2 = GET_FIELDs(insn, 19, 31);
4064 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4065 } else { /* register */
4066 rs2 = GET_FIELD(insn, 27, 31);
4068 gen_movl_reg_TN(rs2, cpu_src2);
4069 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4071 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4073 tcg_gen_helper_0_0(helper_restore);
4074 gen_mov_pc_npc(dc, cpu_cond);
4075 r_const = tcg_const_i32(3);
4076 tcg_gen_helper_0_2(helper_check_align, cpu_dst, r_const);
4077 tcg_temp_free(r_const);
4078 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4079 dc->npc = DYNAMIC_PC;
4083 cpu_src1 = get_src1(insn, cpu_src1);
4084 if (IS_IMM) { /* immediate */
4085 rs2 = GET_FIELDs(insn, 19, 31);
4086 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4087 } else { /* register */
4088 rs2 = GET_FIELD(insn, 27, 31);
4090 gen_movl_reg_TN(rs2, cpu_src2);
4091 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4093 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4096 case 0x38: /* jmpl */
4100 r_const = tcg_const_tl(dc->pc);
4101 gen_movl_TN_reg(rd, r_const);
4102 tcg_temp_free(r_const);
4103 gen_mov_pc_npc(dc, cpu_cond);
4104 r_const = tcg_const_i32(3);
4105 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4107 tcg_temp_free(r_const);
4108 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4109 dc->npc = DYNAMIC_PC;
4112 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4113 case 0x39: /* rett, V9 return */
4117 if (!supervisor(dc))
4119 gen_mov_pc_npc(dc, cpu_cond);
4120 r_const = tcg_const_i32(3);
4121 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4123 tcg_temp_free(r_const);
4124 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4125 dc->npc = DYNAMIC_PC;
4126 tcg_gen_helper_0_0(helper_rett);
4130 case 0x3b: /* flush */
4131 if (!((dc)->features & CPU_FEATURE_FLUSH))
4133 tcg_gen_helper_0_1(helper_flush, cpu_dst);
4135 case 0x3c: /* save */
4136 save_state(dc, cpu_cond);
4137 tcg_gen_helper_0_0(helper_save);
4138 gen_movl_TN_reg(rd, cpu_dst);
4140 case 0x3d: /* restore */
4141 save_state(dc, cpu_cond);
4142 tcg_gen_helper_0_0(helper_restore);
4143 gen_movl_TN_reg(rd, cpu_dst);
4145 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4146 case 0x3e: /* V9 done/retry */
4150 if (!supervisor(dc))
4152 dc->npc = DYNAMIC_PC;
4153 dc->pc = DYNAMIC_PC;
4154 tcg_gen_helper_0_0(helper_done);
4157 if (!supervisor(dc))
4159 dc->npc = DYNAMIC_PC;
4160 dc->pc = DYNAMIC_PC;
4161 tcg_gen_helper_0_0(helper_retry);
4176 case 3: /* load/store instructions */
4178 unsigned int xop = GET_FIELD(insn, 7, 12);
4180 cpu_src1 = get_src1(insn, cpu_src1);
4181 if (xop == 0x3c || xop == 0x3e)
4183 rs2 = GET_FIELD(insn, 27, 31);
4184 gen_movl_reg_TN(rs2, cpu_src2);
4186 else if (IS_IMM) { /* immediate */
4187 rs2 = GET_FIELDs(insn, 19, 31);
4188 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4189 } else { /* register */
4190 rs2 = GET_FIELD(insn, 27, 31);
4192 gen_movl_reg_TN(rs2, cpu_src2);
4193 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4195 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4197 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4198 (xop > 0x17 && xop <= 0x1d ) ||
4199 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4201 case 0x0: /* load unsigned word */
4202 ABI32_MASK(cpu_addr);
4203 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4205 case 0x1: /* load unsigned byte */
4206 ABI32_MASK(cpu_addr);
4207 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4209 case 0x2: /* load unsigned halfword */
4210 ABI32_MASK(cpu_addr);
4211 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4213 case 0x3: /* load double word */
4219 save_state(dc, cpu_cond);
4220 r_const = tcg_const_i32(7);
4221 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4222 r_const); // XXX remove
4223 tcg_temp_free(r_const);
4224 ABI32_MASK(cpu_addr);
4225 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4226 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4227 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4228 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4229 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4230 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4231 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4234 case 0x9: /* load signed byte */
4235 ABI32_MASK(cpu_addr);
4236 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4238 case 0xa: /* load signed halfword */
4239 ABI32_MASK(cpu_addr);
4240 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4242 case 0xd: /* ldstub -- XXX: should be atomically */
4246 ABI32_MASK(cpu_addr);
4247 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4248 r_const = tcg_const_tl(0xff);
4249 tcg_gen_qemu_st8(r_const, cpu_addr, dc->mem_idx);
4250 tcg_temp_free(r_const);
4253 case 0x0f: /* swap register with memory. Also
4255 CHECK_IU_FEATURE(dc, SWAP);
4256 gen_movl_reg_TN(rd, cpu_val);
4257 ABI32_MASK(cpu_addr);
4258 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4259 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4260 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4262 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4263 case 0x10: /* load word alternate */
4264 #ifndef TARGET_SPARC64
4267 if (!supervisor(dc))
4270 save_state(dc, cpu_cond);
4271 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4273 case 0x11: /* load unsigned byte alternate */
4274 #ifndef TARGET_SPARC64
4277 if (!supervisor(dc))
4280 save_state(dc, cpu_cond);
4281 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4283 case 0x12: /* load unsigned halfword alternate */
4284 #ifndef TARGET_SPARC64
4287 if (!supervisor(dc))
4290 save_state(dc, cpu_cond);
4291 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4293 case 0x13: /* load double word alternate */
4294 #ifndef TARGET_SPARC64
4297 if (!supervisor(dc))
4302 save_state(dc, cpu_cond);
4303 gen_ldda_asi(cpu_tmp0, cpu_val, cpu_addr, insn);
4304 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4306 case 0x19: /* load signed byte alternate */
4307 #ifndef TARGET_SPARC64
4310 if (!supervisor(dc))
4313 save_state(dc, cpu_cond);
4314 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4316 case 0x1a: /* load signed halfword alternate */
4317 #ifndef TARGET_SPARC64
4320 if (!supervisor(dc))
4323 save_state(dc, cpu_cond);
4324 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4326 case 0x1d: /* ldstuba -- XXX: should be atomically */
4327 #ifndef TARGET_SPARC64
4330 if (!supervisor(dc))
4333 save_state(dc, cpu_cond);
4334 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4336 case 0x1f: /* swap reg with alt. memory. Also
4338 CHECK_IU_FEATURE(dc, SWAP);
4339 #ifndef TARGET_SPARC64
4342 if (!supervisor(dc))
4345 save_state(dc, cpu_cond);
4346 gen_movl_reg_TN(rd, cpu_val);
4347 gen_swap_asi(cpu_val, cpu_addr, insn);
4350 #ifndef TARGET_SPARC64
4351 case 0x30: /* ldc */
4352 case 0x31: /* ldcsr */
4353 case 0x33: /* lddc */
4357 #ifdef TARGET_SPARC64
4358 case 0x08: /* V9 ldsw */
4359 ABI32_MASK(cpu_addr);
4360 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4362 case 0x0b: /* V9 ldx */
4363 ABI32_MASK(cpu_addr);
4364 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4366 case 0x18: /* V9 ldswa */
4367 save_state(dc, cpu_cond);
4368 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4370 case 0x1b: /* V9 ldxa */
4371 save_state(dc, cpu_cond);
4372 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4374 case 0x2d: /* V9 prefetch, no effect */
4376 case 0x30: /* V9 ldfa */
4377 save_state(dc, cpu_cond);
4378 gen_ldf_asi(cpu_addr, insn, 4, rd);
4380 case 0x33: /* V9 lddfa */
4381 save_state(dc, cpu_cond);
4382 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4384 case 0x3d: /* V9 prefetcha, no effect */
4386 case 0x32: /* V9 ldqfa */
4387 CHECK_FPU_FEATURE(dc, FLOAT128);
4388 save_state(dc, cpu_cond);
4389 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4395 gen_movl_TN_reg(rd, cpu_val);
4396 #ifdef TARGET_SPARC64
4399 } else if (xop >= 0x20 && xop < 0x24) {
4400 if (gen_trap_ifnofpu(dc, cpu_cond))
4402 save_state(dc, cpu_cond);
4404 case 0x20: /* load fpreg */
4405 ABI32_MASK(cpu_addr);
4406 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4407 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4408 offsetof(CPUState, fpr[rd]));
4410 case 0x21: /* load fsr */
4411 ABI32_MASK(cpu_addr);
4412 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4413 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4414 offsetof(CPUState, ft0));
4415 tcg_gen_helper_0_0(helper_ldfsr);
4417 case 0x22: /* load quad fpreg */
4421 CHECK_FPU_FEATURE(dc, FLOAT128);
4422 r_const = tcg_const_i32(dc->mem_idx);
4423 tcg_gen_helper_0_2(helper_ldqf, cpu_addr, r_const);
4424 tcg_temp_free(r_const);
4425 gen_op_store_QT0_fpr(QFPREG(rd));
4428 case 0x23: /* load double fpreg */
4432 r_const = tcg_const_i32(dc->mem_idx);
4433 tcg_gen_helper_0_2(helper_lddf, cpu_addr, r_const);
4434 tcg_temp_free(r_const);
4435 gen_op_store_DT0_fpr(DFPREG(rd));
4441 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4442 xop == 0xe || xop == 0x1e) {
4443 gen_movl_reg_TN(rd, cpu_val);
4445 case 0x4: /* store word */
4446 ABI32_MASK(cpu_addr);
4447 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4449 case 0x5: /* store byte */
4450 ABI32_MASK(cpu_addr);
4451 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4453 case 0x6: /* store halfword */
4454 ABI32_MASK(cpu_addr);
4455 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4457 case 0x7: /* store double word */
4461 TCGv r_low, r_const;
4463 save_state(dc, cpu_cond);
4464 ABI32_MASK(cpu_addr);
4465 r_const = tcg_const_i32(7);
4466 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4467 r_const); // XXX remove
4468 tcg_temp_free(r_const);
4469 r_low = tcg_temp_new(TCG_TYPE_TL);
4470 gen_movl_reg_TN(rd + 1, r_low);
4471 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4473 tcg_temp_free(r_low);
4474 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4477 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4478 case 0x14: /* store word alternate */
4479 #ifndef TARGET_SPARC64
4482 if (!supervisor(dc))
4485 save_state(dc, cpu_cond);
4486 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4488 case 0x15: /* store byte alternate */
4489 #ifndef TARGET_SPARC64
4492 if (!supervisor(dc))
4495 save_state(dc, cpu_cond);
4496 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4498 case 0x16: /* store halfword alternate */
4499 #ifndef TARGET_SPARC64
4502 if (!supervisor(dc))
4505 save_state(dc, cpu_cond);
4506 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4508 case 0x17: /* store double word alternate */
4509 #ifndef TARGET_SPARC64
4512 if (!supervisor(dc))
4518 save_state(dc, cpu_cond);
4519 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4523 #ifdef TARGET_SPARC64
4524 case 0x0e: /* V9 stx */
4525 ABI32_MASK(cpu_addr);
4526 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4528 case 0x1e: /* V9 stxa */
4529 save_state(dc, cpu_cond);
4530 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4536 } else if (xop > 0x23 && xop < 0x28) {
4537 if (gen_trap_ifnofpu(dc, cpu_cond))
4539 save_state(dc, cpu_cond);
4541 case 0x24: /* store fpreg */
4542 ABI32_MASK(cpu_addr);
4543 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4544 offsetof(CPUState, fpr[rd]));
4545 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4547 case 0x25: /* stfsr, V9 stxfsr */
4548 ABI32_MASK(cpu_addr);
4549 tcg_gen_helper_0_0(helper_stfsr);
4550 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4551 offsetof(CPUState, ft0));
4552 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4555 #ifdef TARGET_SPARC64
4556 /* V9 stqf, store quad fpreg */
4560 CHECK_FPU_FEATURE(dc, FLOAT128);
4561 gen_op_load_fpr_QT0(QFPREG(rd));
4562 r_const = tcg_const_i32(dc->mem_idx);
4563 tcg_gen_helper_0_2(helper_stqf, cpu_addr, r_const);
4564 tcg_temp_free(r_const);
4567 #else /* !TARGET_SPARC64 */
4568 /* stdfq, store floating point queue */
4569 #if defined(CONFIG_USER_ONLY)
4572 if (!supervisor(dc))
4574 if (gen_trap_ifnofpu(dc, cpu_cond))
4579 case 0x27: /* store double fpreg */
4583 gen_op_load_fpr_DT0(DFPREG(rd));
4584 r_const = tcg_const_i32(dc->mem_idx);
4585 tcg_gen_helper_0_2(helper_stdf, cpu_addr, r_const);
4586 tcg_temp_free(r_const);
4592 } else if (xop > 0x33 && xop < 0x3f) {
4593 save_state(dc, cpu_cond);
4595 #ifdef TARGET_SPARC64
4596 case 0x34: /* V9 stfa */
4597 gen_op_load_fpr_FT0(rd);
4598 gen_stf_asi(cpu_addr, insn, 4, rd);
4600 case 0x36: /* V9 stqfa */
4604 CHECK_FPU_FEATURE(dc, FLOAT128);
4605 r_const = tcg_const_i32(7);
4606 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4608 tcg_temp_free(r_const);
4609 gen_op_load_fpr_QT0(QFPREG(rd));
4610 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4613 case 0x37: /* V9 stdfa */
4614 gen_op_load_fpr_DT0(DFPREG(rd));
4615 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4617 case 0x3c: /* V9 casa */
4618 gen_cas_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4619 gen_movl_TN_reg(rd, cpu_val);
4621 case 0x3e: /* V9 casxa */
4622 gen_casx_asi(cpu_val, cpu_addr, cpu_val, insn, rd);
4623 gen_movl_TN_reg(rd, cpu_val);
4626 case 0x34: /* stc */
4627 case 0x35: /* stcsr */
4628 case 0x36: /* stdcq */
4629 case 0x37: /* stdc */
4641 /* default case for non jump instructions */
4642 if (dc->npc == DYNAMIC_PC) {
4643 dc->pc = DYNAMIC_PC;
4645 } else if (dc->npc == JUMP_PC) {
4646 /* we can do a static jump */
4647 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4651 dc->npc = dc->npc + 4;
4659 save_state(dc, cpu_cond);
4660 r_const = tcg_const_i32(TT_ILL_INSN);
4661 tcg_gen_helper_0_1(raise_exception, r_const);
4662 tcg_temp_free(r_const);
4670 save_state(dc, cpu_cond);
4671 r_const = tcg_const_i32(TT_UNIMP_FLUSH);
4672 tcg_gen_helper_0_1(raise_exception, r_const);
4673 tcg_temp_free(r_const);
4677 #if !defined(CONFIG_USER_ONLY)
4682 save_state(dc, cpu_cond);
4683 r_const = tcg_const_i32(TT_PRIV_INSN);
4684 tcg_gen_helper_0_1(raise_exception, r_const);
4685 tcg_temp_free(r_const);
4691 save_state(dc, cpu_cond);
4692 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4695 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4697 save_state(dc, cpu_cond);
4698 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4702 #ifndef TARGET_SPARC64
4707 save_state(dc, cpu_cond);
4708 r_const = tcg_const_i32(TT_NCP_INSN);
4709 tcg_gen_helper_0_1(raise_exception, r_const);
4710 tcg_temp_free(r_const);
4717 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4718 int spc, CPUSPARCState *env)
4720 target_ulong pc_start, last_pc;
4721 uint16_t *gen_opc_end;
4722 DisasContext dc1, *dc = &dc1;
4727 memset(dc, 0, sizeof(DisasContext));
4732 dc->npc = (target_ulong) tb->cs_base;
4733 dc->mem_idx = cpu_mmu_index(env);
4734 dc->features = env->features;
4735 if ((dc->features & CPU_FEATURE_FLOAT)) {
4736 dc->fpu_enabled = cpu_fpu_enabled(env);
4737 #if defined(CONFIG_USER_ONLY)
4738 dc->features |= CPU_FEATURE_FLOAT128;
4741 dc->fpu_enabled = 0;
4742 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4744 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4745 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4746 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4748 cpu_dst = tcg_temp_local_new(TCG_TYPE_TL);
4751 cpu_val = tcg_temp_local_new(TCG_TYPE_TL);
4752 cpu_addr = tcg_temp_local_new(TCG_TYPE_TL);
4755 max_insns = tb->cflags & CF_COUNT_MASK;
4757 max_insns = CF_COUNT_MASK;
4760 if (env->nb_breakpoints > 0) {
4761 for(j = 0; j < env->nb_breakpoints; j++) {
4762 if (env->breakpoints[j] == dc->pc) {
4763 if (dc->pc != pc_start)
4764 save_state(dc, cpu_cond);
4765 tcg_gen_helper_0_0(helper_debug);
4774 fprintf(logfile, "Search PC...\n");
4775 j = gen_opc_ptr - gen_opc_buf;
4779 gen_opc_instr_start[lj++] = 0;
4780 gen_opc_pc[lj] = dc->pc;
4781 gen_opc_npc[lj] = dc->npc;
4782 gen_opc_instr_start[lj] = 1;
4783 gen_opc_icount[lj] = num_insns;
4786 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
4789 disas_sparc_insn(dc);
4794 /* if the next PC is different, we abort now */
4795 if (dc->pc != (last_pc + 4))
4797 /* if we reach a page boundary, we stop generation so that the
4798 PC of a TT_TFAULT exception is always in the right page */
4799 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4801 /* if single step mode, we generate only one instruction and
4802 generate an exception */
4803 if (env->singlestep_enabled) {
4804 tcg_gen_movi_tl(cpu_pc, dc->pc);
4808 } while ((gen_opc_ptr < gen_opc_end) &&
4809 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
4810 num_insns < max_insns);
4813 tcg_temp_free(cpu_addr);
4814 tcg_temp_free(cpu_val);
4815 tcg_temp_free(cpu_dst);
4816 tcg_temp_free(cpu_tmp64);
4817 tcg_temp_free(cpu_tmp32);
4818 tcg_temp_free(cpu_tmp0);
4819 if (tb->cflags & CF_LAST_IO)
4822 if (dc->pc != DYNAMIC_PC &&
4823 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4824 /* static PC and NPC: we can use direct chaining */
4825 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4827 if (dc->pc != DYNAMIC_PC)
4828 tcg_gen_movi_tl(cpu_pc, dc->pc);
4829 save_npc(dc, cpu_cond);
4833 gen_icount_end(tb, num_insns);
4834 *gen_opc_ptr = INDEX_op_end;
4836 j = gen_opc_ptr - gen_opc_buf;
4839 gen_opc_instr_start[lj++] = 0;
4845 gen_opc_jump_pc[0] = dc->jump_pc[0];
4846 gen_opc_jump_pc[1] = dc->jump_pc[1];
4848 tb->size = last_pc + 4 - pc_start;
4849 tb->icount = num_insns;
4852 if (loglevel & CPU_LOG_TB_IN_ASM) {
4853 fprintf(logfile, "--------------\n");
4854 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4855 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4856 fprintf(logfile, "\n");
4862 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4864 return gen_intermediate_code_internal(tb, 0, env);
4867 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4869 return gen_intermediate_code_internal(tb, 1, env);
4872 void gen_intermediate_code_init(CPUSPARCState *env)
4876 static const char * const gregnames[8] = {
4877 NULL, // g0 not used
4887 /* init various static tables */
4891 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4892 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4893 offsetof(CPUState, regwptr),
4895 #ifdef TARGET_SPARC64
4896 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4897 TCG_AREG0, offsetof(CPUState, xcc),
4900 cpu_cond = tcg_global_mem_new(TCG_TYPE_TL,
4901 TCG_AREG0, offsetof(CPUState, cond),
4903 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4904 TCG_AREG0, offsetof(CPUState, cc_src),
4906 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4907 offsetof(CPUState, cc_src2),
4909 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4910 TCG_AREG0, offsetof(CPUState, cc_dst),
4912 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4913 TCG_AREG0, offsetof(CPUState, psr),
4915 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4916 TCG_AREG0, offsetof(CPUState, fsr),
4918 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4919 TCG_AREG0, offsetof(CPUState, pc),
4921 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4922 TCG_AREG0, offsetof(CPUState, npc),
4924 for (i = 1; i < 8; i++)
4925 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4926 offsetof(CPUState, gregs[i]),
4928 /* register helpers */
4931 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
4936 void gen_pc_load(CPUState *env, TranslationBlock *tb,
4937 unsigned long searched_pc, int pc_pos, void *puc)
4940 env->pc = gen_opc_pc[pc_pos];
4941 npc = gen_opc_npc[pc_pos];
4943 /* dynamic NPC: already stored */
4944 } else if (npc == 2) {
4945 target_ulong t2 = (target_ulong)(unsigned long)puc;
4946 /* jump PC: use T2 and the jump targets of the translation */
4948 env->npc = gen_opc_jump_pc[0];
4950 env->npc = gen_opc_jump_pc[1];