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 int address_mask_32bit;
61 struct TranslationBlock *tb;
65 // This function uses non-native bit order
66 #define GET_FIELD(X, FROM, TO) \
67 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
69 // This function uses the order in the manuals, i.e. bit 0 is 2^0
70 #define GET_FIELD_SP(X, FROM, TO) \
71 GET_FIELD(X, 31 - (TO), 31 - (FROM))
73 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
74 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
78 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
79 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
82 #define DFPREG(r) (r & 0x1e)
83 #define QFPREG(r) (r & 0x1c)
86 static int sign_extend(int x, int len)
89 return (x << len) >> len;
92 #define IS_IMM (insn & (1<<13))
94 /* floating point registers moves */
95 static void gen_op_load_fpr_FT0(unsigned int src)
97 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
98 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
101 static void gen_op_load_fpr_FT1(unsigned int src)
103 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
104 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
107 static void gen_op_store_FT0_fpr(unsigned int dst)
109 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
110 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
113 static void gen_op_load_fpr_DT0(unsigned int src)
115 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
116 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
117 offsetof(CPU_DoubleU, l.upper));
118 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
119 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
120 offsetof(CPU_DoubleU, l.lower));
123 static void gen_op_load_fpr_DT1(unsigned int src)
125 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
126 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
127 offsetof(CPU_DoubleU, l.upper));
128 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
129 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
130 offsetof(CPU_DoubleU, l.lower));
133 static void gen_op_store_DT0_fpr(unsigned int dst)
135 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
136 offsetof(CPU_DoubleU, l.upper));
137 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
138 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
139 offsetof(CPU_DoubleU, l.lower));
140 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
143 static void gen_op_load_fpr_QT0(unsigned int src)
145 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
146 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
147 offsetof(CPU_QuadU, l.upmost));
148 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
149 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
150 offsetof(CPU_QuadU, l.upper));
151 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
152 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
153 offsetof(CPU_QuadU, l.lower));
154 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
155 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
156 offsetof(CPU_QuadU, l.lowest));
159 static void gen_op_load_fpr_QT1(unsigned int src)
161 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
162 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
163 offsetof(CPU_QuadU, l.upmost));
164 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
165 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
166 offsetof(CPU_QuadU, l.upper));
167 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
168 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
169 offsetof(CPU_QuadU, l.lower));
170 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
171 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
172 offsetof(CPU_QuadU, l.lowest));
175 static void gen_op_store_QT0_fpr(unsigned int dst)
177 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
178 offsetof(CPU_QuadU, l.upmost));
179 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
180 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
181 offsetof(CPU_QuadU, l.upper));
182 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
183 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
184 offsetof(CPU_QuadU, l.lower));
185 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
186 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
187 offsetof(CPU_QuadU, l.lowest));
188 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
192 #ifdef CONFIG_USER_ONLY
193 #define supervisor(dc) 0
194 #ifdef TARGET_SPARC64
195 #define hypervisor(dc) 0
198 #define supervisor(dc) (dc->mem_idx >= 1)
199 #ifdef TARGET_SPARC64
200 #define hypervisor(dc) (dc->mem_idx == 2)
205 #ifdef TARGET_SPARC64
207 #define AM_CHECK(dc) ((dc)->address_mask_32bit)
209 #define AM_CHECK(dc) (1)
213 static inline void gen_address_mask(DisasContext *dc, TCGv addr)
215 #ifdef TARGET_SPARC64
217 tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
221 static inline void gen_movl_reg_TN(int reg, TCGv tn)
224 tcg_gen_movi_tl(tn, 0);
226 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
228 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
232 static inline void gen_movl_TN_reg(int reg, TCGv tn)
237 tcg_gen_mov_tl(cpu_gregs[reg], tn);
239 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
243 static inline void gen_goto_tb(DisasContext *s, int tb_num,
244 target_ulong pc, target_ulong npc)
246 TranslationBlock *tb;
249 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
250 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
251 /* jump to same page: we can use a direct jump */
252 tcg_gen_goto_tb(tb_num);
253 tcg_gen_movi_tl(cpu_pc, pc);
254 tcg_gen_movi_tl(cpu_npc, npc);
255 tcg_gen_exit_tb((long)tb + tb_num);
257 /* jump to another page: currently not optimized */
258 tcg_gen_movi_tl(cpu_pc, pc);
259 tcg_gen_movi_tl(cpu_npc, npc);
265 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
267 tcg_gen_extu_i32_tl(reg, src);
268 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
269 tcg_gen_andi_tl(reg, reg, 0x1);
272 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
274 tcg_gen_extu_i32_tl(reg, src);
275 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
276 tcg_gen_andi_tl(reg, reg, 0x1);
279 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
281 tcg_gen_extu_i32_tl(reg, src);
282 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
283 tcg_gen_andi_tl(reg, reg, 0x1);
286 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
288 tcg_gen_extu_i32_tl(reg, src);
289 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
290 tcg_gen_andi_tl(reg, reg, 0x1);
293 static inline void gen_cc_clear_icc(void)
295 tcg_gen_movi_i32(cpu_psr, 0);
298 #ifdef TARGET_SPARC64
299 static inline void gen_cc_clear_xcc(void)
301 tcg_gen_movi_i32(cpu_xcc, 0);
307 env->psr |= PSR_ZERO;
308 if ((int32_t) T0 < 0)
311 static inline void gen_cc_NZ_icc(TCGv dst)
316 l1 = gen_new_label();
317 l2 = gen_new_label();
318 r_temp = tcg_temp_new(TCG_TYPE_TL);
319 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
320 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
321 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
323 tcg_gen_ext_i32_tl(r_temp, dst);
324 tcg_gen_brcondi_tl(TCG_COND_GE, r_temp, 0, l2);
325 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
327 tcg_temp_free(r_temp);
330 #ifdef TARGET_SPARC64
331 static inline void gen_cc_NZ_xcc(TCGv dst)
335 l1 = gen_new_label();
336 l2 = gen_new_label();
337 tcg_gen_brcondi_tl(TCG_COND_NE, dst, 0, l1);
338 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
340 tcg_gen_brcondi_tl(TCG_COND_GE, dst, 0, l2);
341 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
348 env->psr |= PSR_CARRY;
350 static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
352 TCGv r_temp1, r_temp2;
355 l1 = gen_new_label();
356 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
357 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
358 tcg_gen_andi_tl(r_temp1, dst, 0xffffffffULL);
359 tcg_gen_andi_tl(r_temp2, src1, 0xffffffffULL);
360 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
361 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
363 tcg_temp_free(r_temp1);
364 tcg_temp_free(r_temp2);
367 #ifdef TARGET_SPARC64
368 static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
372 l1 = gen_new_label();
373 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
374 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
380 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
383 static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
387 r_temp = tcg_temp_new(TCG_TYPE_TL);
388 tcg_gen_xor_tl(r_temp, src1, src2);
389 tcg_gen_xori_tl(r_temp, r_temp, -1);
390 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
391 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
392 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
393 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
394 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
395 tcg_temp_free(r_temp);
396 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
399 #ifdef TARGET_SPARC64
400 static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
404 r_temp = tcg_temp_new(TCG_TYPE_TL);
405 tcg_gen_xor_tl(r_temp, src1, src2);
406 tcg_gen_xori_tl(r_temp, r_temp, -1);
407 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
408 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
409 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
410 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
411 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
412 tcg_temp_free(r_temp);
413 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
417 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
419 TCGv r_temp, r_const;
422 l1 = gen_new_label();
424 r_temp = tcg_temp_new(TCG_TYPE_TL);
425 tcg_gen_xor_tl(r_temp, src1, src2);
426 tcg_gen_xori_tl(r_temp, r_temp, -1);
427 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
428 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
429 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
430 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
431 r_const = tcg_const_i32(TT_TOVF);
432 tcg_gen_helper_0_1(raise_exception, r_const);
433 tcg_temp_free(r_const);
435 tcg_temp_free(r_temp);
438 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
442 l1 = gen_new_label();
443 tcg_gen_or_tl(cpu_tmp0, src1, src2);
444 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
445 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
446 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
450 static inline void gen_tag_tv(TCGv src1, TCGv src2)
455 l1 = gen_new_label();
456 tcg_gen_or_tl(cpu_tmp0, src1, src2);
457 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
458 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
459 r_const = tcg_const_i32(TT_TOVF);
460 tcg_gen_helper_0_1(raise_exception, r_const);
461 tcg_temp_free(r_const);
465 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
467 tcg_gen_mov_tl(cpu_cc_src, src1);
468 tcg_gen_mov_tl(cpu_cc_src2, src2);
469 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
471 gen_cc_NZ_icc(cpu_cc_dst);
472 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
473 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
474 #ifdef TARGET_SPARC64
476 gen_cc_NZ_xcc(cpu_cc_dst);
477 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
478 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
480 tcg_gen_mov_tl(dst, cpu_cc_dst);
483 static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
485 tcg_gen_mov_tl(cpu_cc_src, src1);
486 tcg_gen_mov_tl(cpu_cc_src2, src2);
487 gen_mov_reg_C(cpu_tmp0, cpu_psr);
488 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
490 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
491 #ifdef TARGET_SPARC64
493 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
495 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
496 gen_cc_NZ_icc(cpu_cc_dst);
497 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
498 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
499 #ifdef TARGET_SPARC64
500 gen_cc_NZ_xcc(cpu_cc_dst);
501 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
502 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
504 tcg_gen_mov_tl(dst, cpu_cc_dst);
507 static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
509 tcg_gen_mov_tl(cpu_cc_src, src1);
510 tcg_gen_mov_tl(cpu_cc_src2, src2);
511 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
513 gen_cc_NZ_icc(cpu_cc_dst);
514 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
515 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
516 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
517 #ifdef TARGET_SPARC64
519 gen_cc_NZ_xcc(cpu_cc_dst);
520 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
521 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
523 tcg_gen_mov_tl(dst, cpu_cc_dst);
526 static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
528 tcg_gen_mov_tl(cpu_cc_src, src1);
529 tcg_gen_mov_tl(cpu_cc_src2, src2);
530 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
531 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
532 gen_add_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
534 gen_cc_NZ_icc(cpu_cc_dst);
535 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
536 #ifdef TARGET_SPARC64
538 gen_cc_NZ_xcc(cpu_cc_dst);
539 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
540 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
542 tcg_gen_mov_tl(dst, cpu_cc_dst);
547 env->psr |= PSR_CARRY;
549 static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
551 TCGv r_temp1, r_temp2;
554 l1 = gen_new_label();
555 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
556 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
557 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
558 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
559 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
560 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
562 tcg_temp_free(r_temp1);
563 tcg_temp_free(r_temp2);
566 #ifdef TARGET_SPARC64
567 static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
571 l1 = gen_new_label();
572 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
573 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
579 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
582 static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
586 r_temp = tcg_temp_new(TCG_TYPE_TL);
587 tcg_gen_xor_tl(r_temp, src1, src2);
588 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
589 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
590 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
591 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
592 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
593 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
594 tcg_temp_free(r_temp);
597 #ifdef TARGET_SPARC64
598 static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
602 r_temp = tcg_temp_new(TCG_TYPE_TL);
603 tcg_gen_xor_tl(r_temp, src1, src2);
604 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
605 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
606 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
607 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
608 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
609 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
610 tcg_temp_free(r_temp);
614 static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
616 TCGv r_temp, r_const;
619 l1 = gen_new_label();
621 r_temp = tcg_temp_new(TCG_TYPE_TL);
622 tcg_gen_xor_tl(r_temp, src1, src2);
623 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
624 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
625 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
626 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
627 r_const = tcg_const_i32(TT_TOVF);
628 tcg_gen_helper_0_1(raise_exception, r_const);
629 tcg_temp_free(r_const);
631 tcg_temp_free(r_temp);
634 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
636 tcg_gen_mov_tl(cpu_cc_src, src1);
637 tcg_gen_mov_tl(cpu_cc_src2, src2);
638 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
640 gen_cc_NZ_icc(cpu_cc_dst);
641 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
642 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
643 #ifdef TARGET_SPARC64
645 gen_cc_NZ_xcc(cpu_cc_dst);
646 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
647 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
649 tcg_gen_mov_tl(dst, cpu_cc_dst);
652 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
654 tcg_gen_mov_tl(cpu_cc_src, src1);
655 tcg_gen_mov_tl(cpu_cc_src2, src2);
656 gen_mov_reg_C(cpu_tmp0, cpu_psr);
657 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
659 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
660 #ifdef TARGET_SPARC64
662 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
664 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
665 gen_cc_NZ_icc(cpu_cc_dst);
666 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
667 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
668 #ifdef TARGET_SPARC64
669 gen_cc_NZ_xcc(cpu_cc_dst);
670 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
671 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
673 tcg_gen_mov_tl(dst, cpu_cc_dst);
676 static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
678 tcg_gen_mov_tl(cpu_cc_src, src1);
679 tcg_gen_mov_tl(cpu_cc_src2, src2);
680 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
682 gen_cc_NZ_icc(cpu_cc_dst);
683 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
684 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
685 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
686 #ifdef TARGET_SPARC64
688 gen_cc_NZ_xcc(cpu_cc_dst);
689 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
690 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
692 tcg_gen_mov_tl(dst, cpu_cc_dst);
695 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
697 tcg_gen_mov_tl(cpu_cc_src, src1);
698 tcg_gen_mov_tl(cpu_cc_src2, src2);
699 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
700 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
701 gen_sub_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
703 gen_cc_NZ_icc(cpu_cc_dst);
704 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
705 #ifdef TARGET_SPARC64
707 gen_cc_NZ_xcc(cpu_cc_dst);
708 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
709 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
711 tcg_gen_mov_tl(dst, cpu_cc_dst);
714 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
716 TCGv r_temp, r_temp2;
719 l1 = gen_new_label();
720 r_temp = tcg_temp_new(TCG_TYPE_TL);
721 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
727 tcg_gen_mov_tl(cpu_cc_src, src1);
728 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
729 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
730 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
731 tcg_gen_mov_tl(cpu_cc_src2, src2);
732 tcg_gen_brcondi_i32(TCG_COND_NE, r_temp2, 0, l1);
733 tcg_gen_movi_tl(cpu_cc_src2, 0);
737 // env->y = (b2 << 31) | (env->y >> 1);
738 tcg_gen_trunc_tl_i32(r_temp2, cpu_cc_src);
739 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
740 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
741 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
742 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
743 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
744 tcg_temp_free(r_temp2);
745 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
748 gen_mov_reg_N(cpu_tmp0, cpu_psr);
749 gen_mov_reg_V(r_temp, cpu_psr);
750 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
751 tcg_temp_free(r_temp);
753 // T0 = (b1 << 31) | (T0 >> 1);
755 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
756 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
757 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
759 /* do addition and update flags */
760 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
763 gen_cc_NZ_icc(cpu_cc_dst);
764 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
765 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
766 tcg_gen_mov_tl(dst, cpu_cc_dst);
769 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
771 TCGv r_temp, r_temp2;
773 r_temp = tcg_temp_new(TCG_TYPE_I64);
774 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
776 tcg_gen_extu_tl_i64(r_temp, src2);
777 tcg_gen_extu_tl_i64(r_temp2, src1);
778 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
780 tcg_gen_shri_i64(r_temp, r_temp2, 32);
781 tcg_gen_trunc_i64_i32(r_temp, r_temp);
782 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
783 tcg_temp_free(r_temp);
784 #ifdef TARGET_SPARC64
785 tcg_gen_mov_i64(dst, r_temp2);
787 tcg_gen_trunc_i64_tl(dst, r_temp2);
789 tcg_temp_free(r_temp2);
792 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
794 TCGv r_temp, r_temp2;
796 r_temp = tcg_temp_new(TCG_TYPE_I64);
797 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
799 tcg_gen_ext_tl_i64(r_temp, src2);
800 tcg_gen_ext_tl_i64(r_temp2, src1);
801 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
803 tcg_gen_shri_i64(r_temp, r_temp2, 32);
804 tcg_gen_trunc_i64_i32(r_temp, r_temp);
805 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
806 tcg_temp_free(r_temp);
807 #ifdef TARGET_SPARC64
808 tcg_gen_mov_i64(dst, r_temp2);
810 tcg_gen_trunc_i64_tl(dst, r_temp2);
812 tcg_temp_free(r_temp2);
815 #ifdef TARGET_SPARC64
816 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
821 l1 = gen_new_label();
822 tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
823 r_const = tcg_const_i32(TT_DIV_ZERO);
824 tcg_gen_helper_0_1(raise_exception, r_const);
825 tcg_temp_free(r_const);
829 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
833 l1 = gen_new_label();
834 l2 = gen_new_label();
835 tcg_gen_mov_tl(cpu_cc_src, src1);
836 tcg_gen_mov_tl(cpu_cc_src2, src2);
837 gen_trap_ifdivzero_tl(cpu_cc_src2);
838 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src, INT64_MIN, l1);
839 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src2, -1, l1);
840 tcg_gen_movi_i64(dst, INT64_MIN);
843 tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
848 static inline void gen_op_div_cc(TCGv dst)
852 tcg_gen_mov_tl(cpu_cc_dst, dst);
854 gen_cc_NZ_icc(cpu_cc_dst);
855 l1 = gen_new_label();
856 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_src2, 0, l1);
857 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
861 static inline void gen_op_logic_cc(TCGv dst)
863 tcg_gen_mov_tl(cpu_cc_dst, dst);
866 gen_cc_NZ_icc(cpu_cc_dst);
867 #ifdef TARGET_SPARC64
869 gen_cc_NZ_xcc(cpu_cc_dst);
874 static inline void gen_op_eval_ba(TCGv dst)
876 tcg_gen_movi_tl(dst, 1);
880 static inline void gen_op_eval_be(TCGv dst, TCGv src)
882 gen_mov_reg_Z(dst, src);
886 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
888 gen_mov_reg_N(cpu_tmp0, src);
889 gen_mov_reg_V(dst, src);
890 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
891 gen_mov_reg_Z(cpu_tmp0, src);
892 tcg_gen_or_tl(dst, dst, cpu_tmp0);
896 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
898 gen_mov_reg_V(cpu_tmp0, src);
899 gen_mov_reg_N(dst, src);
900 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
904 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
906 gen_mov_reg_Z(cpu_tmp0, src);
907 gen_mov_reg_C(dst, src);
908 tcg_gen_or_tl(dst, dst, cpu_tmp0);
912 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
914 gen_mov_reg_C(dst, src);
918 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
920 gen_mov_reg_V(dst, src);
924 static inline void gen_op_eval_bn(TCGv dst)
926 tcg_gen_movi_tl(dst, 0);
930 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
932 gen_mov_reg_N(dst, src);
936 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
938 gen_mov_reg_Z(dst, src);
939 tcg_gen_xori_tl(dst, dst, 0x1);
943 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
945 gen_mov_reg_N(cpu_tmp0, src);
946 gen_mov_reg_V(dst, src);
947 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
948 gen_mov_reg_Z(cpu_tmp0, src);
949 tcg_gen_or_tl(dst, dst, cpu_tmp0);
950 tcg_gen_xori_tl(dst, dst, 0x1);
954 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
956 gen_mov_reg_V(cpu_tmp0, src);
957 gen_mov_reg_N(dst, src);
958 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
959 tcg_gen_xori_tl(dst, dst, 0x1);
963 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
965 gen_mov_reg_Z(cpu_tmp0, src);
966 gen_mov_reg_C(dst, src);
967 tcg_gen_or_tl(dst, dst, cpu_tmp0);
968 tcg_gen_xori_tl(dst, dst, 0x1);
972 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
974 gen_mov_reg_C(dst, src);
975 tcg_gen_xori_tl(dst, dst, 0x1);
979 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
981 gen_mov_reg_N(dst, src);
982 tcg_gen_xori_tl(dst, dst, 0x1);
986 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
988 gen_mov_reg_V(dst, src);
989 tcg_gen_xori_tl(dst, dst, 0x1);
993 FPSR bit field FCC1 | FCC0:
999 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
1000 unsigned int fcc_offset)
1002 tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
1003 tcg_gen_andi_tl(reg, reg, 0x1);
1006 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
1007 unsigned int fcc_offset)
1009 tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
1010 tcg_gen_andi_tl(reg, reg, 0x1);
1014 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
1015 unsigned int fcc_offset)
1017 gen_mov_reg_FCC0(dst, src, fcc_offset);
1018 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1019 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1022 // 1 or 2: FCC0 ^ FCC1
1023 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
1024 unsigned int fcc_offset)
1026 gen_mov_reg_FCC0(dst, src, fcc_offset);
1027 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1028 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1032 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1033 unsigned int fcc_offset)
1035 gen_mov_reg_FCC0(dst, src, fcc_offset);
1039 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
1040 unsigned int fcc_offset)
1042 gen_mov_reg_FCC0(dst, src, fcc_offset);
1043 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1044 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1045 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1049 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1050 unsigned int fcc_offset)
1052 gen_mov_reg_FCC1(dst, src, fcc_offset);
1056 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1057 unsigned int fcc_offset)
1059 gen_mov_reg_FCC0(dst, src, fcc_offset);
1060 tcg_gen_xori_tl(dst, dst, 0x1);
1061 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1062 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1066 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1067 unsigned int fcc_offset)
1069 gen_mov_reg_FCC0(dst, src, fcc_offset);
1070 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1071 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1074 // 0: !(FCC0 | FCC1)
1075 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1076 unsigned int fcc_offset)
1078 gen_mov_reg_FCC0(dst, src, fcc_offset);
1079 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1080 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1081 tcg_gen_xori_tl(dst, dst, 0x1);
1084 // 0 or 3: !(FCC0 ^ FCC1)
1085 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1086 unsigned int fcc_offset)
1088 gen_mov_reg_FCC0(dst, src, fcc_offset);
1089 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1090 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1091 tcg_gen_xori_tl(dst, dst, 0x1);
1095 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1096 unsigned int fcc_offset)
1098 gen_mov_reg_FCC0(dst, src, fcc_offset);
1099 tcg_gen_xori_tl(dst, dst, 0x1);
1102 // !1: !(FCC0 & !FCC1)
1103 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1104 unsigned int fcc_offset)
1106 gen_mov_reg_FCC0(dst, src, fcc_offset);
1107 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1108 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1109 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1110 tcg_gen_xori_tl(dst, dst, 0x1);
1114 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1115 unsigned int fcc_offset)
1117 gen_mov_reg_FCC1(dst, src, fcc_offset);
1118 tcg_gen_xori_tl(dst, dst, 0x1);
1121 // !2: !(!FCC0 & FCC1)
1122 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1123 unsigned int fcc_offset)
1125 gen_mov_reg_FCC0(dst, src, fcc_offset);
1126 tcg_gen_xori_tl(dst, dst, 0x1);
1127 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1128 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1129 tcg_gen_xori_tl(dst, dst, 0x1);
1132 // !3: !(FCC0 & FCC1)
1133 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1134 unsigned int fcc_offset)
1136 gen_mov_reg_FCC0(dst, src, fcc_offset);
1137 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1138 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1139 tcg_gen_xori_tl(dst, dst, 0x1);
1142 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1143 target_ulong pc2, TCGv r_cond)
1147 l1 = gen_new_label();
1149 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1151 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1154 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1157 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1158 target_ulong pc2, TCGv r_cond)
1162 l1 = gen_new_label();
1164 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1166 gen_goto_tb(dc, 0, pc2, pc1);
1169 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1172 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1177 l1 = gen_new_label();
1178 l2 = gen_new_label();
1180 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1182 tcg_gen_movi_tl(cpu_npc, npc1);
1186 tcg_gen_movi_tl(cpu_npc, npc2);
1190 /* call this function before using the condition register as it may
1191 have been set for a jump */
1192 static inline void flush_cond(DisasContext *dc, TCGv cond)
1194 if (dc->npc == JUMP_PC) {
1195 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1196 dc->npc = DYNAMIC_PC;
1200 static inline void save_npc(DisasContext *dc, TCGv cond)
1202 if (dc->npc == JUMP_PC) {
1203 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1204 dc->npc = DYNAMIC_PC;
1205 } else if (dc->npc != DYNAMIC_PC) {
1206 tcg_gen_movi_tl(cpu_npc, dc->npc);
1210 static inline void save_state(DisasContext *dc, TCGv cond)
1212 tcg_gen_movi_tl(cpu_pc, dc->pc);
1216 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1218 if (dc->npc == JUMP_PC) {
1219 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1220 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1221 dc->pc = DYNAMIC_PC;
1222 } else if (dc->npc == DYNAMIC_PC) {
1223 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1224 dc->pc = DYNAMIC_PC;
1230 static inline void gen_op_next_insn(void)
1232 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1233 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1236 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1240 #ifdef TARGET_SPARC64
1250 gen_op_eval_bn(r_dst);
1253 gen_op_eval_be(r_dst, r_src);
1256 gen_op_eval_ble(r_dst, r_src);
1259 gen_op_eval_bl(r_dst, r_src);
1262 gen_op_eval_bleu(r_dst, r_src);
1265 gen_op_eval_bcs(r_dst, r_src);
1268 gen_op_eval_bneg(r_dst, r_src);
1271 gen_op_eval_bvs(r_dst, r_src);
1274 gen_op_eval_ba(r_dst);
1277 gen_op_eval_bne(r_dst, r_src);
1280 gen_op_eval_bg(r_dst, r_src);
1283 gen_op_eval_bge(r_dst, r_src);
1286 gen_op_eval_bgu(r_dst, r_src);
1289 gen_op_eval_bcc(r_dst, r_src);
1292 gen_op_eval_bpos(r_dst, r_src);
1295 gen_op_eval_bvc(r_dst, r_src);
1300 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1302 unsigned int offset;
1322 gen_op_eval_bn(r_dst);
1325 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1328 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1331 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1334 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1337 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1340 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1343 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1346 gen_op_eval_ba(r_dst);
1349 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1352 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1355 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1358 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1361 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1364 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1367 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1372 #ifdef TARGET_SPARC64
1374 static const int gen_tcg_cond_reg[8] = {
1385 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1389 l1 = gen_new_label();
1390 tcg_gen_movi_tl(r_dst, 0);
1391 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1392 tcg_gen_movi_tl(r_dst, 1);
1397 /* XXX: potentially incorrect if dynamic npc */
1398 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1401 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1402 target_ulong target = dc->pc + offset;
1405 /* unconditional not taken */
1407 dc->pc = dc->npc + 4;
1408 dc->npc = dc->pc + 4;
1411 dc->npc = dc->pc + 4;
1413 } else if (cond == 0x8) {
1414 /* unconditional taken */
1417 dc->npc = dc->pc + 4;
1423 flush_cond(dc, r_cond);
1424 gen_cond(r_cond, cc, cond);
1426 gen_branch_a(dc, target, dc->npc, r_cond);
1430 dc->jump_pc[0] = target;
1431 dc->jump_pc[1] = dc->npc + 4;
1437 /* XXX: potentially incorrect if dynamic npc */
1438 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1441 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1442 target_ulong target = dc->pc + offset;
1445 /* unconditional not taken */
1447 dc->pc = dc->npc + 4;
1448 dc->npc = dc->pc + 4;
1451 dc->npc = dc->pc + 4;
1453 } else if (cond == 0x8) {
1454 /* unconditional taken */
1457 dc->npc = dc->pc + 4;
1463 flush_cond(dc, r_cond);
1464 gen_fcond(r_cond, cc, cond);
1466 gen_branch_a(dc, target, dc->npc, r_cond);
1470 dc->jump_pc[0] = target;
1471 dc->jump_pc[1] = dc->npc + 4;
1477 #ifdef TARGET_SPARC64
1478 /* XXX: potentially incorrect if dynamic npc */
1479 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1480 TCGv r_cond, TCGv r_reg)
1482 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1483 target_ulong target = dc->pc + offset;
1485 flush_cond(dc, r_cond);
1486 gen_cond_reg(r_cond, cond, r_reg);
1488 gen_branch_a(dc, target, dc->npc, r_cond);
1492 dc->jump_pc[0] = target;
1493 dc->jump_pc[1] = dc->npc + 4;
1498 static GenOpFunc * const gen_fcmps[4] = {
1505 static GenOpFunc * const gen_fcmpd[4] = {
1512 static GenOpFunc * const gen_fcmpq[4] = {
1519 static GenOpFunc * const gen_fcmpes[4] = {
1526 static GenOpFunc * const gen_fcmped[4] = {
1533 static GenOpFunc * const gen_fcmpeq[4] = {
1540 static inline void gen_op_fcmps(int fccno)
1542 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1545 static inline void gen_op_fcmpd(int fccno)
1547 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1550 static inline void gen_op_fcmpq(int fccno)
1552 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1555 static inline void gen_op_fcmpes(int fccno)
1557 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1560 static inline void gen_op_fcmped(int fccno)
1562 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1565 static inline void gen_op_fcmpeq(int fccno)
1567 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1572 static inline void gen_op_fcmps(int fccno)
1574 tcg_gen_helper_0_0(helper_fcmps);
1577 static inline void gen_op_fcmpd(int fccno)
1579 tcg_gen_helper_0_0(helper_fcmpd);
1582 static inline void gen_op_fcmpq(int fccno)
1584 tcg_gen_helper_0_0(helper_fcmpq);
1587 static inline void gen_op_fcmpes(int fccno)
1589 tcg_gen_helper_0_0(helper_fcmpes);
1592 static inline void gen_op_fcmped(int fccno)
1594 tcg_gen_helper_0_0(helper_fcmped);
1597 static inline void gen_op_fcmpeq(int fccno)
1599 tcg_gen_helper_0_0(helper_fcmpeq);
1603 static inline void gen_op_fpexception_im(int fsr_flags)
1607 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1608 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1609 r_const = tcg_const_i32(TT_FP_EXCP);
1610 tcg_gen_helper_0_1(raise_exception, r_const);
1611 tcg_temp_free(r_const);
1614 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1616 #if !defined(CONFIG_USER_ONLY)
1617 if (!dc->fpu_enabled) {
1620 save_state(dc, r_cond);
1621 r_const = tcg_const_i32(TT_NFPU_INSN);
1622 tcg_gen_helper_0_1(raise_exception, r_const);
1623 tcg_temp_free(r_const);
1631 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1633 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1636 static inline void gen_clear_float_exceptions(void)
1638 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1642 #ifdef TARGET_SPARC64
1643 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1649 r_asi = tcg_temp_new(TCG_TYPE_I32);
1650 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1652 asi = GET_FIELD(insn, 19, 26);
1653 r_asi = tcg_const_i32(asi);
1658 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1661 TCGv r_asi, r_size, r_sign;
1663 r_asi = gen_get_asi(insn, addr);
1664 r_size = tcg_const_i32(size);
1665 r_sign = tcg_const_i32(sign);
1666 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi, r_size, r_sign);
1667 tcg_temp_free(r_sign);
1668 tcg_temp_free(r_size);
1669 tcg_temp_free(r_asi);
1672 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1676 r_asi = gen_get_asi(insn, addr);
1677 r_size = tcg_const_i32(size);
1678 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, r_size);
1679 tcg_temp_free(r_size);
1680 tcg_temp_free(r_asi);
1683 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1685 TCGv r_asi, r_size, r_rd;
1687 r_asi = gen_get_asi(insn, addr);
1688 r_size = tcg_const_i32(size);
1689 r_rd = tcg_const_i32(rd);
1690 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, r_size, r_rd);
1691 tcg_temp_free(r_rd);
1692 tcg_temp_free(r_size);
1693 tcg_temp_free(r_asi);
1696 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1698 TCGv r_asi, r_size, r_rd;
1700 r_asi = gen_get_asi(insn, addr);
1701 r_size = tcg_const_i32(size);
1702 r_rd = tcg_const_i32(rd);
1703 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, r_size, r_rd);
1704 tcg_temp_free(r_rd);
1705 tcg_temp_free(r_size);
1706 tcg_temp_free(r_asi);
1709 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1711 TCGv r_asi, r_size, r_sign;
1713 r_asi = gen_get_asi(insn, addr);
1714 r_size = tcg_const_i32(4);
1715 r_sign = tcg_const_i32(0);
1716 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1717 tcg_temp_free(r_sign);
1718 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1719 tcg_temp_free(r_size);
1720 tcg_temp_free(r_asi);
1721 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1724 static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
1728 r_asi = gen_get_asi(insn, addr);
1729 r_rd = tcg_const_i32(rd);
1730 tcg_gen_helper_0_3(helper_ldda_asi, addr, r_asi, r_rd);
1731 tcg_temp_free(r_rd);
1732 tcg_temp_free(r_asi);
1735 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1737 TCGv r_temp, r_asi, r_size;
1739 r_temp = tcg_temp_new(TCG_TYPE_TL);
1740 gen_movl_reg_TN(rd + 1, r_temp);
1741 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1743 tcg_temp_free(r_temp);
1744 r_asi = gen_get_asi(insn, addr);
1745 r_size = tcg_const_i32(8);
1746 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1747 tcg_temp_free(r_size);
1748 tcg_temp_free(r_asi);
1751 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1756 r_val1 = tcg_temp_new(TCG_TYPE_TL);
1757 gen_movl_reg_TN(rd, r_val1);
1758 r_asi = gen_get_asi(insn, addr);
1759 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1760 tcg_temp_free(r_asi);
1761 tcg_temp_free(r_val1);
1764 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1769 gen_movl_reg_TN(rd, cpu_tmp64);
1770 r_asi = gen_get_asi(insn, addr);
1771 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1772 tcg_temp_free(r_asi);
1775 #elif !defined(CONFIG_USER_ONLY)
1777 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1780 TCGv r_asi, r_size, r_sign;
1782 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1783 r_size = tcg_const_i32(size);
1784 r_sign = tcg_const_i32(sign);
1785 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1786 tcg_temp_free(r_sign);
1787 tcg_temp_free(r_size);
1788 tcg_temp_free(r_asi);
1789 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1792 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1796 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1797 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1798 r_size = tcg_const_i32(size);
1799 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1800 tcg_temp_free(r_size);
1801 tcg_temp_free(r_asi);
1804 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1806 TCGv r_asi, r_size, r_sign;
1808 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1809 r_size = tcg_const_i32(4);
1810 r_sign = tcg_const_i32(0);
1811 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1812 tcg_temp_free(r_sign);
1813 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1814 tcg_temp_free(r_size);
1815 tcg_temp_free(r_asi);
1816 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1819 static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
1821 TCGv r_asi, r_size, r_sign;
1823 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1824 r_size = tcg_const_i32(8);
1825 r_sign = tcg_const_i32(0);
1826 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1827 tcg_temp_free(r_sign);
1828 tcg_temp_free(r_size);
1829 tcg_temp_free(r_asi);
1830 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
1831 gen_movl_TN_reg(rd + 1, cpu_tmp0);
1832 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1833 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1834 gen_movl_TN_reg(rd, hi);
1837 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1839 TCGv r_temp, r_asi, r_size;
1841 r_temp = tcg_temp_new(TCG_TYPE_TL);
1842 gen_movl_reg_TN(rd + 1, r_temp);
1843 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1844 tcg_temp_free(r_temp);
1845 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1846 r_size = tcg_const_i32(8);
1847 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1848 tcg_temp_free(r_size);
1849 tcg_temp_free(r_asi);
1853 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1854 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1856 TCGv r_val, r_asi, r_size;
1858 gen_ld_asi(dst, addr, insn, 1, 0);
1860 r_val = tcg_const_i64(0xffULL);
1861 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1862 r_size = tcg_const_i32(1);
1863 tcg_gen_helper_0_4(helper_st_asi, addr, r_val, r_asi, r_size);
1864 tcg_temp_free(r_size);
1865 tcg_temp_free(r_asi);
1866 tcg_temp_free(r_val);
1870 static inline TCGv get_src1(unsigned int insn, TCGv def)
1875 rs1 = GET_FIELD(insn, 13, 17);
1877 r_rs1 = tcg_const_tl(0); // XXX how to free?
1879 r_rs1 = cpu_gregs[rs1];
1881 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1885 static inline TCGv get_src2(unsigned int insn, TCGv def)
1890 if (IS_IMM) { /* immediate */
1891 rs2 = GET_FIELDs(insn, 19, 31);
1892 r_rs2 = tcg_const_tl((int)rs2); // XXX how to free?
1893 } else { /* register */
1894 rs2 = GET_FIELD(insn, 27, 31);
1896 r_rs2 = tcg_const_tl(0); // XXX how to free?
1898 r_rs2 = cpu_gregs[rs2];
1900 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1905 #define CHECK_IU_FEATURE(dc, FEATURE) \
1906 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
1908 #define CHECK_FPU_FEATURE(dc, FEATURE) \
1909 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
1912 /* before an instruction, dc->pc must be static */
1913 static void disas_sparc_insn(DisasContext * dc)
1915 unsigned int insn, opc, rs1, rs2, rd;
1917 if (unlikely(loglevel & CPU_LOG_TB_OP))
1918 tcg_gen_debug_insn_start(dc->pc);
1919 insn = ldl_code(dc->pc);
1920 opc = GET_FIELD(insn, 0, 1);
1922 rd = GET_FIELD(insn, 2, 6);
1924 cpu_src1 = tcg_temp_new(TCG_TYPE_TL); // const
1925 cpu_src2 = tcg_temp_new(TCG_TYPE_TL); // const
1928 case 0: /* branches/sethi */
1930 unsigned int xop = GET_FIELD(insn, 7, 9);
1933 #ifdef TARGET_SPARC64
1934 case 0x1: /* V9 BPcc */
1938 target = GET_FIELD_SP(insn, 0, 18);
1939 target = sign_extend(target, 18);
1941 cc = GET_FIELD_SP(insn, 20, 21);
1943 do_branch(dc, target, insn, 0, cpu_cond);
1945 do_branch(dc, target, insn, 1, cpu_cond);
1950 case 0x3: /* V9 BPr */
1952 target = GET_FIELD_SP(insn, 0, 13) |
1953 (GET_FIELD_SP(insn, 20, 21) << 14);
1954 target = sign_extend(target, 16);
1956 cpu_src1 = get_src1(insn, cpu_src1);
1957 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1960 case 0x5: /* V9 FBPcc */
1962 int cc = GET_FIELD_SP(insn, 20, 21);
1963 if (gen_trap_ifnofpu(dc, cpu_cond))
1965 target = GET_FIELD_SP(insn, 0, 18);
1966 target = sign_extend(target, 19);
1968 do_fbranch(dc, target, insn, cc, cpu_cond);
1972 case 0x7: /* CBN+x */
1977 case 0x2: /* BN+x */
1979 target = GET_FIELD(insn, 10, 31);
1980 target = sign_extend(target, 22);
1982 do_branch(dc, target, insn, 0, cpu_cond);
1985 case 0x6: /* FBN+x */
1987 if (gen_trap_ifnofpu(dc, cpu_cond))
1989 target = GET_FIELD(insn, 10, 31);
1990 target = sign_extend(target, 22);
1992 do_fbranch(dc, target, insn, 0, cpu_cond);
1995 case 0x4: /* SETHI */
1997 uint32_t value = GET_FIELD(insn, 10, 31);
2000 r_const = tcg_const_tl(value << 10);
2001 gen_movl_TN_reg(rd, r_const);
2002 tcg_temp_free(r_const);
2005 case 0x0: /* UNIMPL */
2014 target_long target = GET_FIELDs(insn, 2, 31) << 2;
2017 r_const = tcg_const_tl(dc->pc);
2018 gen_movl_TN_reg(15, r_const);
2019 tcg_temp_free(r_const);
2021 gen_mov_pc_npc(dc, cpu_cond);
2025 case 2: /* FPU & Logical Operations */
2027 unsigned int xop = GET_FIELD(insn, 7, 12);
2028 if (xop == 0x3a) { /* generate trap */
2031 cpu_src1 = get_src1(insn, cpu_src1);
2033 rs2 = GET_FIELD(insn, 25, 31);
2034 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
2036 rs2 = GET_FIELD(insn, 27, 31);
2038 gen_movl_reg_TN(rs2, cpu_src2);
2039 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2041 tcg_gen_mov_tl(cpu_dst, cpu_src1);
2043 cond = GET_FIELD(insn, 3, 6);
2045 save_state(dc, cpu_cond);
2046 tcg_gen_helper_0_1(helper_trap, cpu_dst);
2047 } else if (cond != 0) {
2048 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
2049 #ifdef TARGET_SPARC64
2051 int cc = GET_FIELD_SP(insn, 11, 12);
2053 save_state(dc, cpu_cond);
2055 gen_cond(r_cond, 0, cond);
2057 gen_cond(r_cond, 1, cond);
2061 save_state(dc, cpu_cond);
2062 gen_cond(r_cond, 0, cond);
2064 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
2065 tcg_temp_free(r_cond);
2071 } else if (xop == 0x28) {
2072 rs1 = GET_FIELD(insn, 13, 17);
2075 #ifndef TARGET_SPARC64
2076 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2077 manual, rdy on the microSPARC
2079 case 0x0f: /* stbar in the SPARCv8 manual,
2080 rdy on the microSPARC II */
2081 case 0x10 ... 0x1f: /* implementation-dependent in the
2082 SPARCv8 manual, rdy on the
2085 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2086 offsetof(CPUSPARCState, y));
2087 gen_movl_TN_reg(rd, cpu_tmp0);
2089 #ifdef TARGET_SPARC64
2090 case 0x2: /* V9 rdccr */
2091 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2092 gen_movl_TN_reg(rd, cpu_dst);
2094 case 0x3: /* V9 rdasi */
2095 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2096 offsetof(CPUSPARCState, asi));
2097 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2098 gen_movl_TN_reg(rd, cpu_dst);
2100 case 0x4: /* V9 rdtick */
2104 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2105 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2106 offsetof(CPUState, tick));
2107 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2109 tcg_temp_free(r_tickptr);
2110 gen_movl_TN_reg(rd, cpu_dst);
2113 case 0x5: /* V9 rdpc */
2117 r_const = tcg_const_tl(dc->pc);
2118 gen_movl_TN_reg(rd, r_const);
2119 tcg_temp_free(r_const);
2122 case 0x6: /* V9 rdfprs */
2123 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2124 offsetof(CPUSPARCState, fprs));
2125 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2126 gen_movl_TN_reg(rd, cpu_dst);
2128 case 0xf: /* V9 membar */
2129 break; /* no effect */
2130 case 0x13: /* Graphics Status */
2131 if (gen_trap_ifnofpu(dc, cpu_cond))
2133 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2134 offsetof(CPUSPARCState, gsr));
2135 gen_movl_TN_reg(rd, cpu_tmp0);
2137 case 0x17: /* Tick compare */
2138 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2139 offsetof(CPUSPARCState, tick_cmpr));
2140 gen_movl_TN_reg(rd, cpu_tmp0);
2142 case 0x18: /* System tick */
2146 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2147 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2148 offsetof(CPUState, stick));
2149 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2151 tcg_temp_free(r_tickptr);
2152 gen_movl_TN_reg(rd, cpu_dst);
2155 case 0x19: /* System tick compare */
2156 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2157 offsetof(CPUSPARCState, stick_cmpr));
2158 gen_movl_TN_reg(rd, cpu_tmp0);
2160 case 0x10: /* Performance Control */
2161 case 0x11: /* Performance Instrumentation Counter */
2162 case 0x12: /* Dispatch Control */
2163 case 0x14: /* Softint set, WO */
2164 case 0x15: /* Softint clear, WO */
2165 case 0x16: /* Softint write */
2170 #if !defined(CONFIG_USER_ONLY)
2171 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2172 #ifndef TARGET_SPARC64
2173 if (!supervisor(dc))
2175 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2177 CHECK_IU_FEATURE(dc, HYPV);
2178 if (!hypervisor(dc))
2180 rs1 = GET_FIELD(insn, 13, 17);
2183 // gen_op_rdhpstate();
2186 // gen_op_rdhtstate();
2189 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2190 offsetof(CPUSPARCState, hintp));
2191 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2194 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2195 offsetof(CPUSPARCState, htba));
2196 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2199 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2200 offsetof(CPUSPARCState, hver));
2201 tcg_gen_ext_i32_tl(cpu_dst, cpu_tmp32);
2203 case 31: // hstick_cmpr
2204 tcg_gen_ld_tl(cpu_dst, cpu_env,
2205 offsetof(CPUSPARCState, hstick_cmpr));
2211 gen_movl_TN_reg(rd, cpu_dst);
2213 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2214 if (!supervisor(dc))
2216 #ifdef TARGET_SPARC64
2217 rs1 = GET_FIELD(insn, 13, 17);
2223 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2224 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2225 offsetof(CPUState, tsptr));
2226 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2227 offsetof(trap_state, tpc));
2228 tcg_temp_free(r_tsptr);
2235 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2236 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2237 offsetof(CPUState, tsptr));
2238 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2239 offsetof(trap_state, tnpc));
2240 tcg_temp_free(r_tsptr);
2247 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2248 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2249 offsetof(CPUState, tsptr));
2250 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2251 offsetof(trap_state, tstate));
2252 tcg_temp_free(r_tsptr);
2259 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2260 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2261 offsetof(CPUState, tsptr));
2262 tcg_gen_ld_i32(cpu_tmp0, r_tsptr,
2263 offsetof(trap_state, tt));
2264 tcg_temp_free(r_tsptr);
2271 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2272 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2273 offsetof(CPUState, tick));
2274 tcg_gen_helper_1_1(helper_tick_get_count, cpu_tmp0,
2276 gen_movl_TN_reg(rd, cpu_tmp0);
2277 tcg_temp_free(r_tickptr);
2281 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2282 offsetof(CPUSPARCState, tbr));
2285 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2286 offsetof(CPUSPARCState, pstate));
2287 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2290 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2291 offsetof(CPUSPARCState, tl));
2292 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2295 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2296 offsetof(CPUSPARCState, psrpil));
2297 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2300 tcg_gen_helper_1_0(helper_rdcwp, cpu_tmp0);
2303 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2304 offsetof(CPUSPARCState, cansave));
2305 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2307 case 11: // canrestore
2308 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2309 offsetof(CPUSPARCState, canrestore));
2310 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2312 case 12: // cleanwin
2313 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2314 offsetof(CPUSPARCState, cleanwin));
2315 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2317 case 13: // otherwin
2318 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2319 offsetof(CPUSPARCState, otherwin));
2320 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2323 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2324 offsetof(CPUSPARCState, wstate));
2325 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2327 case 16: // UA2005 gl
2328 CHECK_IU_FEATURE(dc, GL);
2329 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2330 offsetof(CPUSPARCState, gl));
2331 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2333 case 26: // UA2005 strand status
2334 CHECK_IU_FEATURE(dc, HYPV);
2335 if (!hypervisor(dc))
2337 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2338 offsetof(CPUSPARCState, ssr));
2339 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2342 tcg_gen_ld_tl(cpu_tmp0, cpu_env,
2343 offsetof(CPUSPARCState, version));
2350 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2351 offsetof(CPUSPARCState, wim));
2352 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2354 gen_movl_TN_reg(rd, cpu_tmp0);
2356 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2357 #ifdef TARGET_SPARC64
2358 save_state(dc, cpu_cond);
2359 tcg_gen_helper_0_0(helper_flushw);
2361 if (!supervisor(dc))
2363 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, tbr));
2364 gen_movl_TN_reg(rd, cpu_tmp0);
2368 } else if (xop == 0x34) { /* FPU Operations */
2369 if (gen_trap_ifnofpu(dc, cpu_cond))
2371 gen_op_clear_ieee_excp_and_FTT();
2372 rs1 = GET_FIELD(insn, 13, 17);
2373 rs2 = GET_FIELD(insn, 27, 31);
2374 xop = GET_FIELD(insn, 18, 26);
2376 case 0x1: /* fmovs */
2377 gen_op_load_fpr_FT0(rs2);
2378 gen_op_store_FT0_fpr(rd);
2380 case 0x5: /* fnegs */
2381 gen_op_load_fpr_FT1(rs2);
2382 tcg_gen_helper_0_0(helper_fnegs);
2383 gen_op_store_FT0_fpr(rd);
2385 case 0x9: /* fabss */
2386 gen_op_load_fpr_FT1(rs2);
2387 tcg_gen_helper_0_0(helper_fabss);
2388 gen_op_store_FT0_fpr(rd);
2390 case 0x29: /* fsqrts */
2391 CHECK_FPU_FEATURE(dc, FSQRT);
2392 gen_op_load_fpr_FT1(rs2);
2393 gen_clear_float_exceptions();
2394 tcg_gen_helper_0_0(helper_fsqrts);
2395 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2396 gen_op_store_FT0_fpr(rd);
2398 case 0x2a: /* fsqrtd */
2399 CHECK_FPU_FEATURE(dc, FSQRT);
2400 gen_op_load_fpr_DT1(DFPREG(rs2));
2401 gen_clear_float_exceptions();
2402 tcg_gen_helper_0_0(helper_fsqrtd);
2403 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2404 gen_op_store_DT0_fpr(DFPREG(rd));
2406 case 0x2b: /* fsqrtq */
2407 CHECK_FPU_FEATURE(dc, FLOAT128);
2408 gen_op_load_fpr_QT1(QFPREG(rs2));
2409 gen_clear_float_exceptions();
2410 tcg_gen_helper_0_0(helper_fsqrtq);
2411 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2412 gen_op_store_QT0_fpr(QFPREG(rd));
2415 gen_op_load_fpr_FT0(rs1);
2416 gen_op_load_fpr_FT1(rs2);
2417 gen_clear_float_exceptions();
2418 tcg_gen_helper_0_0(helper_fadds);
2419 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2420 gen_op_store_FT0_fpr(rd);
2423 gen_op_load_fpr_DT0(DFPREG(rs1));
2424 gen_op_load_fpr_DT1(DFPREG(rs2));
2425 gen_clear_float_exceptions();
2426 tcg_gen_helper_0_0(helper_faddd);
2427 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2428 gen_op_store_DT0_fpr(DFPREG(rd));
2430 case 0x43: /* faddq */
2431 CHECK_FPU_FEATURE(dc, FLOAT128);
2432 gen_op_load_fpr_QT0(QFPREG(rs1));
2433 gen_op_load_fpr_QT1(QFPREG(rs2));
2434 gen_clear_float_exceptions();
2435 tcg_gen_helper_0_0(helper_faddq);
2436 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2437 gen_op_store_QT0_fpr(QFPREG(rd));
2440 gen_op_load_fpr_FT0(rs1);
2441 gen_op_load_fpr_FT1(rs2);
2442 gen_clear_float_exceptions();
2443 tcg_gen_helper_0_0(helper_fsubs);
2444 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2445 gen_op_store_FT0_fpr(rd);
2448 gen_op_load_fpr_DT0(DFPREG(rs1));
2449 gen_op_load_fpr_DT1(DFPREG(rs2));
2450 gen_clear_float_exceptions();
2451 tcg_gen_helper_0_0(helper_fsubd);
2452 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2453 gen_op_store_DT0_fpr(DFPREG(rd));
2455 case 0x47: /* fsubq */
2456 CHECK_FPU_FEATURE(dc, FLOAT128);
2457 gen_op_load_fpr_QT0(QFPREG(rs1));
2458 gen_op_load_fpr_QT1(QFPREG(rs2));
2459 gen_clear_float_exceptions();
2460 tcg_gen_helper_0_0(helper_fsubq);
2461 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2462 gen_op_store_QT0_fpr(QFPREG(rd));
2464 case 0x49: /* fmuls */
2465 CHECK_FPU_FEATURE(dc, FMUL);
2466 gen_op_load_fpr_FT0(rs1);
2467 gen_op_load_fpr_FT1(rs2);
2468 gen_clear_float_exceptions();
2469 tcg_gen_helper_0_0(helper_fmuls);
2470 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2471 gen_op_store_FT0_fpr(rd);
2473 case 0x4a: /* fmuld */
2474 CHECK_FPU_FEATURE(dc, FMUL);
2475 gen_op_load_fpr_DT0(DFPREG(rs1));
2476 gen_op_load_fpr_DT1(DFPREG(rs2));
2477 gen_clear_float_exceptions();
2478 tcg_gen_helper_0_0(helper_fmuld);
2479 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2480 gen_op_store_DT0_fpr(DFPREG(rd));
2482 case 0x4b: /* fmulq */
2483 CHECK_FPU_FEATURE(dc, FLOAT128);
2484 CHECK_FPU_FEATURE(dc, FMUL);
2485 gen_op_load_fpr_QT0(QFPREG(rs1));
2486 gen_op_load_fpr_QT1(QFPREG(rs2));
2487 gen_clear_float_exceptions();
2488 tcg_gen_helper_0_0(helper_fmulq);
2489 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2490 gen_op_store_QT0_fpr(QFPREG(rd));
2493 gen_op_load_fpr_FT0(rs1);
2494 gen_op_load_fpr_FT1(rs2);
2495 gen_clear_float_exceptions();
2496 tcg_gen_helper_0_0(helper_fdivs);
2497 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2498 gen_op_store_FT0_fpr(rd);
2501 gen_op_load_fpr_DT0(DFPREG(rs1));
2502 gen_op_load_fpr_DT1(DFPREG(rs2));
2503 gen_clear_float_exceptions();
2504 tcg_gen_helper_0_0(helper_fdivd);
2505 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2506 gen_op_store_DT0_fpr(DFPREG(rd));
2508 case 0x4f: /* fdivq */
2509 CHECK_FPU_FEATURE(dc, FLOAT128);
2510 gen_op_load_fpr_QT0(QFPREG(rs1));
2511 gen_op_load_fpr_QT1(QFPREG(rs2));
2512 gen_clear_float_exceptions();
2513 tcg_gen_helper_0_0(helper_fdivq);
2514 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2515 gen_op_store_QT0_fpr(QFPREG(rd));
2518 CHECK_FPU_FEATURE(dc, FSMULD);
2519 gen_op_load_fpr_FT0(rs1);
2520 gen_op_load_fpr_FT1(rs2);
2521 gen_clear_float_exceptions();
2522 tcg_gen_helper_0_0(helper_fsmuld);
2523 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2524 gen_op_store_DT0_fpr(DFPREG(rd));
2526 case 0x6e: /* fdmulq */
2527 CHECK_FPU_FEATURE(dc, FLOAT128);
2528 gen_op_load_fpr_DT0(DFPREG(rs1));
2529 gen_op_load_fpr_DT1(DFPREG(rs2));
2530 gen_clear_float_exceptions();
2531 tcg_gen_helper_0_0(helper_fdmulq);
2532 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2533 gen_op_store_QT0_fpr(QFPREG(rd));
2536 gen_op_load_fpr_FT1(rs2);
2537 gen_clear_float_exceptions();
2538 tcg_gen_helper_0_0(helper_fitos);
2539 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2540 gen_op_store_FT0_fpr(rd);
2543 gen_op_load_fpr_DT1(DFPREG(rs2));
2544 gen_clear_float_exceptions();
2545 tcg_gen_helper_0_0(helper_fdtos);
2546 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2547 gen_op_store_FT0_fpr(rd);
2549 case 0xc7: /* fqtos */
2550 CHECK_FPU_FEATURE(dc, FLOAT128);
2551 gen_op_load_fpr_QT1(QFPREG(rs2));
2552 gen_clear_float_exceptions();
2553 tcg_gen_helper_0_0(helper_fqtos);
2554 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2555 gen_op_store_FT0_fpr(rd);
2558 gen_op_load_fpr_FT1(rs2);
2559 tcg_gen_helper_0_0(helper_fitod);
2560 gen_op_store_DT0_fpr(DFPREG(rd));
2563 gen_op_load_fpr_FT1(rs2);
2564 tcg_gen_helper_0_0(helper_fstod);
2565 gen_op_store_DT0_fpr(DFPREG(rd));
2567 case 0xcb: /* fqtod */
2568 CHECK_FPU_FEATURE(dc, FLOAT128);
2569 gen_op_load_fpr_QT1(QFPREG(rs2));
2570 gen_clear_float_exceptions();
2571 tcg_gen_helper_0_0(helper_fqtod);
2572 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2573 gen_op_store_DT0_fpr(DFPREG(rd));
2575 case 0xcc: /* fitoq */
2576 CHECK_FPU_FEATURE(dc, FLOAT128);
2577 gen_op_load_fpr_FT1(rs2);
2578 tcg_gen_helper_0_0(helper_fitoq);
2579 gen_op_store_QT0_fpr(QFPREG(rd));
2581 case 0xcd: /* fstoq */
2582 CHECK_FPU_FEATURE(dc, FLOAT128);
2583 gen_op_load_fpr_FT1(rs2);
2584 tcg_gen_helper_0_0(helper_fstoq);
2585 gen_op_store_QT0_fpr(QFPREG(rd));
2587 case 0xce: /* fdtoq */
2588 CHECK_FPU_FEATURE(dc, FLOAT128);
2589 gen_op_load_fpr_DT1(DFPREG(rs2));
2590 tcg_gen_helper_0_0(helper_fdtoq);
2591 gen_op_store_QT0_fpr(QFPREG(rd));
2594 gen_op_load_fpr_FT1(rs2);
2595 gen_clear_float_exceptions();
2596 tcg_gen_helper_0_0(helper_fstoi);
2597 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2598 gen_op_store_FT0_fpr(rd);
2601 gen_op_load_fpr_DT1(DFPREG(rs2));
2602 gen_clear_float_exceptions();
2603 tcg_gen_helper_0_0(helper_fdtoi);
2604 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2605 gen_op_store_FT0_fpr(rd);
2607 case 0xd3: /* fqtoi */
2608 CHECK_FPU_FEATURE(dc, FLOAT128);
2609 gen_op_load_fpr_QT1(QFPREG(rs2));
2610 gen_clear_float_exceptions();
2611 tcg_gen_helper_0_0(helper_fqtoi);
2612 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2613 gen_op_store_FT0_fpr(rd);
2615 #ifdef TARGET_SPARC64
2616 case 0x2: /* V9 fmovd */
2617 gen_op_load_fpr_DT0(DFPREG(rs2));
2618 gen_op_store_DT0_fpr(DFPREG(rd));
2620 case 0x3: /* V9 fmovq */
2621 CHECK_FPU_FEATURE(dc, FLOAT128);
2622 gen_op_load_fpr_QT0(QFPREG(rs2));
2623 gen_op_store_QT0_fpr(QFPREG(rd));
2625 case 0x6: /* V9 fnegd */
2626 gen_op_load_fpr_DT1(DFPREG(rs2));
2627 tcg_gen_helper_0_0(helper_fnegd);
2628 gen_op_store_DT0_fpr(DFPREG(rd));
2630 case 0x7: /* V9 fnegq */
2631 CHECK_FPU_FEATURE(dc, FLOAT128);
2632 gen_op_load_fpr_QT1(QFPREG(rs2));
2633 tcg_gen_helper_0_0(helper_fnegq);
2634 gen_op_store_QT0_fpr(QFPREG(rd));
2636 case 0xa: /* V9 fabsd */
2637 gen_op_load_fpr_DT1(DFPREG(rs2));
2638 tcg_gen_helper_0_0(helper_fabsd);
2639 gen_op_store_DT0_fpr(DFPREG(rd));
2641 case 0xb: /* V9 fabsq */
2642 CHECK_FPU_FEATURE(dc, FLOAT128);
2643 gen_op_load_fpr_QT1(QFPREG(rs2));
2644 tcg_gen_helper_0_0(helper_fabsq);
2645 gen_op_store_QT0_fpr(QFPREG(rd));
2647 case 0x81: /* V9 fstox */
2648 gen_op_load_fpr_FT1(rs2);
2649 gen_clear_float_exceptions();
2650 tcg_gen_helper_0_0(helper_fstox);
2651 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2652 gen_op_store_DT0_fpr(DFPREG(rd));
2654 case 0x82: /* V9 fdtox */
2655 gen_op_load_fpr_DT1(DFPREG(rs2));
2656 gen_clear_float_exceptions();
2657 tcg_gen_helper_0_0(helper_fdtox);
2658 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2659 gen_op_store_DT0_fpr(DFPREG(rd));
2661 case 0x83: /* V9 fqtox */
2662 CHECK_FPU_FEATURE(dc, FLOAT128);
2663 gen_op_load_fpr_QT1(QFPREG(rs2));
2664 gen_clear_float_exceptions();
2665 tcg_gen_helper_0_0(helper_fqtox);
2666 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2667 gen_op_store_DT0_fpr(DFPREG(rd));
2669 case 0x84: /* V9 fxtos */
2670 gen_op_load_fpr_DT1(DFPREG(rs2));
2671 gen_clear_float_exceptions();
2672 tcg_gen_helper_0_0(helper_fxtos);
2673 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2674 gen_op_store_FT0_fpr(rd);
2676 case 0x88: /* V9 fxtod */
2677 gen_op_load_fpr_DT1(DFPREG(rs2));
2678 gen_clear_float_exceptions();
2679 tcg_gen_helper_0_0(helper_fxtod);
2680 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2681 gen_op_store_DT0_fpr(DFPREG(rd));
2683 case 0x8c: /* V9 fxtoq */
2684 CHECK_FPU_FEATURE(dc, FLOAT128);
2685 gen_op_load_fpr_DT1(DFPREG(rs2));
2686 gen_clear_float_exceptions();
2687 tcg_gen_helper_0_0(helper_fxtoq);
2688 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2689 gen_op_store_QT0_fpr(QFPREG(rd));
2695 } else if (xop == 0x35) { /* FPU Operations */
2696 #ifdef TARGET_SPARC64
2699 if (gen_trap_ifnofpu(dc, cpu_cond))
2701 gen_op_clear_ieee_excp_and_FTT();
2702 rs1 = GET_FIELD(insn, 13, 17);
2703 rs2 = GET_FIELD(insn, 27, 31);
2704 xop = GET_FIELD(insn, 18, 26);
2705 #ifdef TARGET_SPARC64
2706 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2709 l1 = gen_new_label();
2710 cond = GET_FIELD_SP(insn, 14, 17);
2711 cpu_src1 = get_src1(insn, cpu_src1);
2712 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2714 gen_op_load_fpr_FT0(rs2);
2715 gen_op_store_FT0_fpr(rd);
2718 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2721 l1 = gen_new_label();
2722 cond = GET_FIELD_SP(insn, 14, 17);
2723 cpu_src1 = get_src1(insn, cpu_src1);
2724 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2726 gen_op_load_fpr_DT0(DFPREG(rs2));
2727 gen_op_store_DT0_fpr(DFPREG(rd));
2730 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2733 CHECK_FPU_FEATURE(dc, FLOAT128);
2734 l1 = gen_new_label();
2735 cond = GET_FIELD_SP(insn, 14, 17);
2736 cpu_src1 = get_src1(insn, cpu_src1);
2737 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2739 gen_op_load_fpr_QT0(QFPREG(rs2));
2740 gen_op_store_QT0_fpr(QFPREG(rd));
2746 #ifdef TARGET_SPARC64
2747 #define FMOVCC(size_FDQ, fcc) \
2752 l1 = gen_new_label(); \
2753 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2754 cond = GET_FIELD_SP(insn, 14, 17); \
2755 gen_fcond(r_cond, fcc, cond); \
2756 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2758 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2759 (glue(size_FDQ, FPREG(rs2))); \
2760 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2761 (glue(size_FDQ, FPREG(rd))); \
2762 gen_set_label(l1); \
2763 tcg_temp_free(r_cond); \
2765 case 0x001: /* V9 fmovscc %fcc0 */
2768 case 0x002: /* V9 fmovdcc %fcc0 */
2771 case 0x003: /* V9 fmovqcc %fcc0 */
2772 CHECK_FPU_FEATURE(dc, FLOAT128);
2775 case 0x041: /* V9 fmovscc %fcc1 */
2778 case 0x042: /* V9 fmovdcc %fcc1 */
2781 case 0x043: /* V9 fmovqcc %fcc1 */
2782 CHECK_FPU_FEATURE(dc, FLOAT128);
2785 case 0x081: /* V9 fmovscc %fcc2 */
2788 case 0x082: /* V9 fmovdcc %fcc2 */
2791 case 0x083: /* V9 fmovqcc %fcc2 */
2792 CHECK_FPU_FEATURE(dc, FLOAT128);
2795 case 0x0c1: /* V9 fmovscc %fcc3 */
2798 case 0x0c2: /* V9 fmovdcc %fcc3 */
2801 case 0x0c3: /* V9 fmovqcc %fcc3 */
2802 CHECK_FPU_FEATURE(dc, FLOAT128);
2806 #define FMOVCC(size_FDQ, icc) \
2811 l1 = gen_new_label(); \
2812 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2813 cond = GET_FIELD_SP(insn, 14, 17); \
2814 gen_cond(r_cond, icc, cond); \
2815 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2817 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2818 (glue(size_FDQ, FPREG(rs2))); \
2819 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2820 (glue(size_FDQ, FPREG(rd))); \
2821 gen_set_label(l1); \
2822 tcg_temp_free(r_cond); \
2825 case 0x101: /* V9 fmovscc %icc */
2828 case 0x102: /* V9 fmovdcc %icc */
2830 case 0x103: /* V9 fmovqcc %icc */
2831 CHECK_FPU_FEATURE(dc, FLOAT128);
2834 case 0x181: /* V9 fmovscc %xcc */
2837 case 0x182: /* V9 fmovdcc %xcc */
2840 case 0x183: /* V9 fmovqcc %xcc */
2841 CHECK_FPU_FEATURE(dc, FLOAT128);
2846 case 0x51: /* fcmps, V9 %fcc */
2847 gen_op_load_fpr_FT0(rs1);
2848 gen_op_load_fpr_FT1(rs2);
2849 gen_op_fcmps(rd & 3);
2851 case 0x52: /* fcmpd, V9 %fcc */
2852 gen_op_load_fpr_DT0(DFPREG(rs1));
2853 gen_op_load_fpr_DT1(DFPREG(rs2));
2854 gen_op_fcmpd(rd & 3);
2856 case 0x53: /* fcmpq, V9 %fcc */
2857 CHECK_FPU_FEATURE(dc, FLOAT128);
2858 gen_op_load_fpr_QT0(QFPREG(rs1));
2859 gen_op_load_fpr_QT1(QFPREG(rs2));
2860 gen_op_fcmpq(rd & 3);
2862 case 0x55: /* fcmpes, V9 %fcc */
2863 gen_op_load_fpr_FT0(rs1);
2864 gen_op_load_fpr_FT1(rs2);
2865 gen_op_fcmpes(rd & 3);
2867 case 0x56: /* fcmped, V9 %fcc */
2868 gen_op_load_fpr_DT0(DFPREG(rs1));
2869 gen_op_load_fpr_DT1(DFPREG(rs2));
2870 gen_op_fcmped(rd & 3);
2872 case 0x57: /* fcmpeq, V9 %fcc */
2873 CHECK_FPU_FEATURE(dc, FLOAT128);
2874 gen_op_load_fpr_QT0(QFPREG(rs1));
2875 gen_op_load_fpr_QT1(QFPREG(rs2));
2876 gen_op_fcmpeq(rd & 3);
2881 } else if (xop == 0x2) {
2884 rs1 = GET_FIELD(insn, 13, 17);
2886 // or %g0, x, y -> mov T0, x; mov y, T0
2887 if (IS_IMM) { /* immediate */
2890 rs2 = GET_FIELDs(insn, 19, 31);
2891 r_const = tcg_const_tl((int)rs2);
2892 gen_movl_TN_reg(rd, r_const);
2893 tcg_temp_free(r_const);
2894 } else { /* register */
2895 rs2 = GET_FIELD(insn, 27, 31);
2896 gen_movl_reg_TN(rs2, cpu_dst);
2897 gen_movl_TN_reg(rd, cpu_dst);
2900 cpu_src1 = get_src1(insn, cpu_src1);
2901 if (IS_IMM) { /* immediate */
2902 rs2 = GET_FIELDs(insn, 19, 31);
2903 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2904 gen_movl_TN_reg(rd, cpu_dst);
2905 } else { /* register */
2906 // or x, %g0, y -> mov T1, x; mov y, T1
2907 rs2 = GET_FIELD(insn, 27, 31);
2909 gen_movl_reg_TN(rs2, cpu_src2);
2910 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2911 gen_movl_TN_reg(rd, cpu_dst);
2913 gen_movl_TN_reg(rd, cpu_src1);
2916 #ifdef TARGET_SPARC64
2917 } else if (xop == 0x25) { /* sll, V9 sllx */
2918 cpu_src1 = get_src1(insn, cpu_src1);
2919 if (IS_IMM) { /* immediate */
2920 rs2 = GET_FIELDs(insn, 20, 31);
2921 if (insn & (1 << 12)) {
2922 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2924 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x1f);
2926 } else { /* register */
2927 rs2 = GET_FIELD(insn, 27, 31);
2928 gen_movl_reg_TN(rs2, cpu_src2);
2929 if (insn & (1 << 12)) {
2930 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2932 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2934 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2936 gen_movl_TN_reg(rd, cpu_dst);
2937 } else if (xop == 0x26) { /* srl, V9 srlx */
2938 cpu_src1 = get_src1(insn, cpu_src1);
2939 if (IS_IMM) { /* immediate */
2940 rs2 = GET_FIELDs(insn, 20, 31);
2941 if (insn & (1 << 12)) {
2942 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2944 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2945 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2947 } else { /* register */
2948 rs2 = GET_FIELD(insn, 27, 31);
2949 gen_movl_reg_TN(rs2, cpu_src2);
2950 if (insn & (1 << 12)) {
2951 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2952 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2954 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2955 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2956 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2959 gen_movl_TN_reg(rd, cpu_dst);
2960 } else if (xop == 0x27) { /* sra, V9 srax */
2961 cpu_src1 = get_src1(insn, cpu_src1);
2962 if (IS_IMM) { /* immediate */
2963 rs2 = GET_FIELDs(insn, 20, 31);
2964 if (insn & (1 << 12)) {
2965 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2967 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2968 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2969 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2971 } else { /* register */
2972 rs2 = GET_FIELD(insn, 27, 31);
2973 gen_movl_reg_TN(rs2, cpu_src2);
2974 if (insn & (1 << 12)) {
2975 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2976 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2978 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2979 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2980 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2981 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2984 gen_movl_TN_reg(rd, cpu_dst);
2986 } else if (xop < 0x36) {
2987 cpu_src1 = get_src1(insn, cpu_src1);
2988 cpu_src2 = get_src2(insn, cpu_src2);
2990 switch (xop & ~0x10) {
2993 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2995 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2998 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
3000 gen_op_logic_cc(cpu_dst);
3003 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
3005 gen_op_logic_cc(cpu_dst);
3008 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3010 gen_op_logic_cc(cpu_dst);
3014 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
3016 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
3019 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3020 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
3022 gen_op_logic_cc(cpu_dst);
3025 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3026 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
3028 gen_op_logic_cc(cpu_dst);
3031 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3032 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
3034 gen_op_logic_cc(cpu_dst);
3038 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3040 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3041 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3042 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3045 #ifdef TARGET_SPARC64
3046 case 0x9: /* V9 mulx */
3047 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3051 CHECK_IU_FEATURE(dc, MUL);
3052 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3054 gen_op_logic_cc(cpu_dst);
3057 CHECK_IU_FEATURE(dc, MUL);
3058 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3060 gen_op_logic_cc(cpu_dst);
3064 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3066 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3067 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3068 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3071 #ifdef TARGET_SPARC64
3072 case 0xd: /* V9 udivx */
3073 tcg_gen_mov_tl(cpu_cc_src, cpu_src1);
3074 tcg_gen_mov_tl(cpu_cc_src2, cpu_src2);
3075 gen_trap_ifdivzero_tl(cpu_cc_src2);
3076 tcg_gen_divu_i64(cpu_dst, cpu_cc_src, cpu_cc_src2);
3080 CHECK_IU_FEATURE(dc, DIV);
3081 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1,
3084 gen_op_div_cc(cpu_dst);
3087 CHECK_IU_FEATURE(dc, DIV);
3088 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1,
3091 gen_op_div_cc(cpu_dst);
3096 gen_movl_TN_reg(rd, cpu_dst);
3099 case 0x20: /* taddcc */
3100 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3101 gen_movl_TN_reg(rd, cpu_dst);
3103 case 0x21: /* tsubcc */
3104 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3105 gen_movl_TN_reg(rd, cpu_dst);
3107 case 0x22: /* taddcctv */
3108 save_state(dc, cpu_cond);
3109 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3110 gen_movl_TN_reg(rd, cpu_dst);
3112 case 0x23: /* tsubcctv */
3113 save_state(dc, cpu_cond);
3114 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3115 gen_movl_TN_reg(rd, cpu_dst);
3117 case 0x24: /* mulscc */
3118 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3119 gen_movl_TN_reg(rd, cpu_dst);
3121 #ifndef TARGET_SPARC64
3122 case 0x25: /* sll */
3123 if (IS_IMM) { /* immediate */
3124 rs2 = GET_FIELDs(insn, 20, 31);
3125 tcg_gen_shli_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3126 } else { /* register */
3127 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3128 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3130 gen_movl_TN_reg(rd, cpu_dst);
3132 case 0x26: /* srl */
3133 if (IS_IMM) { /* immediate */
3134 rs2 = GET_FIELDs(insn, 20, 31);
3135 tcg_gen_shri_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3136 } else { /* register */
3137 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3138 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3140 gen_movl_TN_reg(rd, cpu_dst);
3142 case 0x27: /* sra */
3143 if (IS_IMM) { /* immediate */
3144 rs2 = GET_FIELDs(insn, 20, 31);
3145 tcg_gen_sari_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3146 } else { /* register */
3147 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3148 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3150 gen_movl_TN_reg(rd, cpu_dst);
3157 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3158 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3159 offsetof(CPUSPARCState, y));
3161 #ifndef TARGET_SPARC64
3162 case 0x01 ... 0x0f: /* undefined in the
3166 case 0x10 ... 0x1f: /* implementation-dependent
3172 case 0x2: /* V9 wrccr */
3173 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3174 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3176 case 0x3: /* V9 wrasi */
3177 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3178 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3179 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3180 offsetof(CPUSPARCState, asi));
3182 case 0x6: /* V9 wrfprs */
3183 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3184 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_dst);
3185 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3186 offsetof(CPUSPARCState, fprs));
3187 save_state(dc, cpu_cond);
3192 case 0xf: /* V9 sir, nop if user */
3193 #if !defined(CONFIG_USER_ONLY)
3198 case 0x13: /* Graphics Status */
3199 if (gen_trap_ifnofpu(dc, cpu_cond))
3201 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3202 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3203 offsetof(CPUSPARCState, gsr));
3205 case 0x17: /* Tick compare */
3206 #if !defined(CONFIG_USER_ONLY)
3207 if (!supervisor(dc))
3213 tcg_gen_xor_tl(cpu_tmp0, cpu_src1,
3215 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3216 offsetof(CPUSPARCState,
3218 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3219 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3220 offsetof(CPUState, tick));
3221 tcg_gen_helper_0_2(helper_tick_set_limit,
3222 r_tickptr, cpu_tmp0);
3223 tcg_temp_free(r_tickptr);
3226 case 0x18: /* System tick */
3227 #if !defined(CONFIG_USER_ONLY)
3228 if (!supervisor(dc))
3234 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3236 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3237 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3238 offsetof(CPUState, stick));
3239 tcg_gen_helper_0_2(helper_tick_set_count,
3240 r_tickptr, cpu_dst);
3241 tcg_temp_free(r_tickptr);
3244 case 0x19: /* System tick compare */
3245 #if !defined(CONFIG_USER_ONLY)
3246 if (!supervisor(dc))
3252 tcg_gen_xor_tl(cpu_tmp0, cpu_src1,
3254 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3255 offsetof(CPUSPARCState,
3257 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3258 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3259 offsetof(CPUState, stick));
3260 tcg_gen_helper_0_2(helper_tick_set_limit,
3261 r_tickptr, cpu_tmp0);
3262 tcg_temp_free(r_tickptr);
3266 case 0x10: /* Performance Control */
3267 case 0x11: /* Performance Instrumentation
3269 case 0x12: /* Dispatch Control */
3270 case 0x14: /* Softint set */
3271 case 0x15: /* Softint clear */
3272 case 0x16: /* Softint write */
3279 #if !defined(CONFIG_USER_ONLY)
3280 case 0x31: /* wrpsr, V9 saved, restored */
3282 if (!supervisor(dc))
3284 #ifdef TARGET_SPARC64
3287 tcg_gen_helper_0_0(helper_saved);
3290 tcg_gen_helper_0_0(helper_restored);
3292 case 2: /* UA2005 allclean */
3293 case 3: /* UA2005 otherw */
3294 case 4: /* UA2005 normalw */
3295 case 5: /* UA2005 invalw */
3301 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3302 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3303 save_state(dc, cpu_cond);
3310 case 0x32: /* wrwim, V9 wrpr */
3312 if (!supervisor(dc))
3314 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3315 #ifdef TARGET_SPARC64
3321 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3322 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3323 offsetof(CPUState, tsptr));
3324 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3325 offsetof(trap_state, tpc));
3326 tcg_temp_free(r_tsptr);
3333 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3334 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3335 offsetof(CPUState, tsptr));
3336 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3337 offsetof(trap_state, tnpc));
3338 tcg_temp_free(r_tsptr);
3345 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3346 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3347 offsetof(CPUState, tsptr));
3348 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3349 offsetof(trap_state,
3351 tcg_temp_free(r_tsptr);
3358 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3359 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3360 offsetof(CPUState, tsptr));
3361 tcg_gen_st_i32(cpu_tmp0, r_tsptr,
3362 offsetof(trap_state, tt));
3363 tcg_temp_free(r_tsptr);
3370 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3371 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3372 offsetof(CPUState, tick));
3373 tcg_gen_helper_0_2(helper_tick_set_count,
3374 r_tickptr, cpu_tmp0);
3375 tcg_temp_free(r_tickptr);
3379 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3380 offsetof(CPUSPARCState, tbr));
3383 save_state(dc, cpu_cond);
3384 tcg_gen_helper_0_1(helper_wrpstate, cpu_tmp0);
3390 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3391 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3392 offsetof(CPUSPARCState, tl));
3395 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3396 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3397 offsetof(CPUSPARCState,
3401 tcg_gen_helper_0_1(helper_wrcwp, cpu_tmp0);
3404 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3405 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3406 offsetof(CPUSPARCState,
3409 case 11: // canrestore
3410 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3411 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3412 offsetof(CPUSPARCState,
3415 case 12: // cleanwin
3416 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3417 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3418 offsetof(CPUSPARCState,
3421 case 13: // otherwin
3422 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3423 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3424 offsetof(CPUSPARCState,
3428 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3429 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3430 offsetof(CPUSPARCState,
3433 case 16: // UA2005 gl
3434 CHECK_IU_FEATURE(dc, GL);
3435 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3436 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3437 offsetof(CPUSPARCState, gl));
3439 case 26: // UA2005 strand status
3440 CHECK_IU_FEATURE(dc, HYPV);
3441 if (!hypervisor(dc))
3443 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3444 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3445 offsetof(CPUSPARCState, ssr));
3451 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3452 if (dc->def->nwindows != 32)
3453 tcg_gen_andi_tl(cpu_tmp32, cpu_tmp32,
3454 (1 << dc->def->nwindows) - 1);
3455 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3456 offsetof(CPUSPARCState, wim));
3460 case 0x33: /* wrtbr, UA2005 wrhpr */
3462 #ifndef TARGET_SPARC64
3463 if (!supervisor(dc))
3465 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3466 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3467 offsetof(CPUSPARCState, tbr));
3469 CHECK_IU_FEATURE(dc, HYPV);
3470 if (!hypervisor(dc))
3472 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3475 // XXX gen_op_wrhpstate();
3476 save_state(dc, cpu_cond);
3482 // XXX gen_op_wrhtstate();
3485 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3486 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3487 offsetof(CPUSPARCState, hintp));
3490 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3491 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3492 offsetof(CPUSPARCState, htba));
3494 case 31: // hstick_cmpr
3498 tcg_gen_st_tl(cpu_tmp0, cpu_env,
3499 offsetof(CPUSPARCState,
3501 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3502 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3503 offsetof(CPUState, hstick));
3504 tcg_gen_helper_0_2(helper_tick_set_limit,
3505 r_tickptr, cpu_tmp0);
3506 tcg_temp_free(r_tickptr);
3509 case 6: // hver readonly
3517 #ifdef TARGET_SPARC64
3518 case 0x2c: /* V9 movcc */
3520 int cc = GET_FIELD_SP(insn, 11, 12);
3521 int cond = GET_FIELD_SP(insn, 14, 17);
3525 r_cond = tcg_temp_new(TCG_TYPE_TL);
3526 if (insn & (1 << 18)) {
3528 gen_cond(r_cond, 0, cond);
3530 gen_cond(r_cond, 1, cond);
3534 gen_fcond(r_cond, cc, cond);
3537 l1 = gen_new_label();
3539 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3540 if (IS_IMM) { /* immediate */
3543 rs2 = GET_FIELD_SPs(insn, 0, 10);
3544 r_const = tcg_const_tl((int)rs2);
3545 gen_movl_TN_reg(rd, r_const);
3546 tcg_temp_free(r_const);
3548 rs2 = GET_FIELD_SP(insn, 0, 4);
3549 gen_movl_reg_TN(rs2, cpu_tmp0);
3550 gen_movl_TN_reg(rd, cpu_tmp0);
3553 tcg_temp_free(r_cond);
3556 case 0x2d: /* V9 sdivx */
3557 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3558 gen_movl_TN_reg(rd, cpu_dst);
3560 case 0x2e: /* V9 popc */
3562 cpu_src2 = get_src2(insn, cpu_src2);
3563 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3565 gen_movl_TN_reg(rd, cpu_dst);
3567 case 0x2f: /* V9 movr */
3569 int cond = GET_FIELD_SP(insn, 10, 12);
3572 cpu_src1 = get_src1(insn, cpu_src1);
3574 l1 = gen_new_label();
3576 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
3578 if (IS_IMM) { /* immediate */
3581 rs2 = GET_FIELD_SPs(insn, 0, 9);
3582 r_const = tcg_const_tl((int)rs2);
3583 gen_movl_TN_reg(rd, r_const);
3584 tcg_temp_free(r_const);
3586 rs2 = GET_FIELD_SP(insn, 0, 4);
3587 gen_movl_reg_TN(rs2, cpu_tmp0);
3588 gen_movl_TN_reg(rd, cpu_tmp0);
3598 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3599 #ifdef TARGET_SPARC64
3600 int opf = GET_FIELD_SP(insn, 5, 13);
3601 rs1 = GET_FIELD(insn, 13, 17);
3602 rs2 = GET_FIELD(insn, 27, 31);
3603 if (gen_trap_ifnofpu(dc, cpu_cond))
3607 case 0x000: /* VIS I edge8cc */
3608 case 0x001: /* VIS II edge8n */
3609 case 0x002: /* VIS I edge8lcc */
3610 case 0x003: /* VIS II edge8ln */
3611 case 0x004: /* VIS I edge16cc */
3612 case 0x005: /* VIS II edge16n */
3613 case 0x006: /* VIS I edge16lcc */
3614 case 0x007: /* VIS II edge16ln */
3615 case 0x008: /* VIS I edge32cc */
3616 case 0x009: /* VIS II edge32n */
3617 case 0x00a: /* VIS I edge32lcc */
3618 case 0x00b: /* VIS II edge32ln */
3621 case 0x010: /* VIS I array8 */
3622 CHECK_FPU_FEATURE(dc, VIS1);
3623 cpu_src1 = get_src1(insn, cpu_src1);
3624 gen_movl_reg_TN(rs2, cpu_src2);
3625 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3627 gen_movl_TN_reg(rd, cpu_dst);
3629 case 0x012: /* VIS I array16 */
3630 CHECK_FPU_FEATURE(dc, VIS1);
3631 cpu_src1 = get_src1(insn, cpu_src1);
3632 gen_movl_reg_TN(rs2, cpu_src2);
3633 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3635 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3636 gen_movl_TN_reg(rd, cpu_dst);
3638 case 0x014: /* VIS I array32 */
3639 CHECK_FPU_FEATURE(dc, VIS1);
3640 cpu_src1 = get_src1(insn, cpu_src1);
3641 gen_movl_reg_TN(rs2, cpu_src2);
3642 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3644 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3645 gen_movl_TN_reg(rd, cpu_dst);
3647 case 0x018: /* VIS I alignaddr */
3648 CHECK_FPU_FEATURE(dc, VIS1);
3649 cpu_src1 = get_src1(insn, cpu_src1);
3650 gen_movl_reg_TN(rs2, cpu_src2);
3651 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3653 gen_movl_TN_reg(rd, cpu_dst);
3655 case 0x019: /* VIS II bmask */
3656 case 0x01a: /* VIS I alignaddrl */
3659 case 0x020: /* VIS I fcmple16 */
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_fcmple16);
3664 gen_op_store_DT0_fpr(DFPREG(rd));
3666 case 0x022: /* VIS I fcmpne16 */
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_fcmpne16);
3671 gen_op_store_DT0_fpr(DFPREG(rd));
3673 case 0x024: /* VIS I fcmple32 */
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_fcmple32);
3678 gen_op_store_DT0_fpr(DFPREG(rd));
3680 case 0x026: /* VIS I fcmpne32 */
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_fcmpne32);
3685 gen_op_store_DT0_fpr(DFPREG(rd));
3687 case 0x028: /* VIS I fcmpgt16 */
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_fcmpgt16);
3692 gen_op_store_DT0_fpr(DFPREG(rd));
3694 case 0x02a: /* VIS I fcmpeq16 */
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_fcmpeq16);
3699 gen_op_store_DT0_fpr(DFPREG(rd));
3701 case 0x02c: /* VIS I fcmpgt32 */
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_fcmpgt32);
3706 gen_op_store_DT0_fpr(DFPREG(rd));
3708 case 0x02e: /* VIS I fcmpeq32 */
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_fcmpeq32);
3713 gen_op_store_DT0_fpr(DFPREG(rd));
3715 case 0x031: /* VIS I fmul8x16 */
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_fmul8x16);
3720 gen_op_store_DT0_fpr(DFPREG(rd));
3722 case 0x033: /* VIS I fmul8x16au */
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_fmul8x16au);
3727 gen_op_store_DT0_fpr(DFPREG(rd));
3729 case 0x035: /* VIS I fmul8x16al */
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_fmul8x16al);
3734 gen_op_store_DT0_fpr(DFPREG(rd));
3736 case 0x036: /* VIS I fmul8sux16 */
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_fmul8sux16);
3741 gen_op_store_DT0_fpr(DFPREG(rd));
3743 case 0x037: /* VIS I fmul8ulx16 */
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_fmul8ulx16);
3748 gen_op_store_DT0_fpr(DFPREG(rd));
3750 case 0x038: /* VIS I fmuld8sux16 */
3751 CHECK_FPU_FEATURE(dc, VIS1);
3752 gen_op_load_fpr_DT0(DFPREG(rs1));
3753 gen_op_load_fpr_DT1(DFPREG(rs2));
3754 tcg_gen_helper_0_0(helper_fmuld8sux16);
3755 gen_op_store_DT0_fpr(DFPREG(rd));
3757 case 0x039: /* VIS I fmuld8ulx16 */
3758 CHECK_FPU_FEATURE(dc, VIS1);
3759 gen_op_load_fpr_DT0(DFPREG(rs1));
3760 gen_op_load_fpr_DT1(DFPREG(rs2));
3761 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3762 gen_op_store_DT0_fpr(DFPREG(rd));
3764 case 0x03a: /* VIS I fpack32 */
3765 case 0x03b: /* VIS I fpack16 */
3766 case 0x03d: /* VIS I fpackfix */
3767 case 0x03e: /* VIS I pdist */
3770 case 0x048: /* VIS I faligndata */
3771 CHECK_FPU_FEATURE(dc, VIS1);
3772 gen_op_load_fpr_DT0(DFPREG(rs1));
3773 gen_op_load_fpr_DT1(DFPREG(rs2));
3774 tcg_gen_helper_0_0(helper_faligndata);
3775 gen_op_store_DT0_fpr(DFPREG(rd));
3777 case 0x04b: /* VIS I fpmerge */
3778 CHECK_FPU_FEATURE(dc, VIS1);
3779 gen_op_load_fpr_DT0(DFPREG(rs1));
3780 gen_op_load_fpr_DT1(DFPREG(rs2));
3781 tcg_gen_helper_0_0(helper_fpmerge);
3782 gen_op_store_DT0_fpr(DFPREG(rd));
3784 case 0x04c: /* VIS II bshuffle */
3787 case 0x04d: /* VIS I fexpand */
3788 CHECK_FPU_FEATURE(dc, VIS1);
3789 gen_op_load_fpr_DT0(DFPREG(rs1));
3790 gen_op_load_fpr_DT1(DFPREG(rs2));
3791 tcg_gen_helper_0_0(helper_fexpand);
3792 gen_op_store_DT0_fpr(DFPREG(rd));
3794 case 0x050: /* VIS I fpadd16 */
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_fpadd16);
3799 gen_op_store_DT0_fpr(DFPREG(rd));
3801 case 0x051: /* VIS I fpadd16s */
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_fpadd16s);
3806 gen_op_store_FT0_fpr(rd);
3808 case 0x052: /* VIS I fpadd32 */
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_fpadd32);
3813 gen_op_store_DT0_fpr(DFPREG(rd));
3815 case 0x053: /* VIS I fpadd32s */
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_fpadd32s);
3820 gen_op_store_FT0_fpr(rd);
3822 case 0x054: /* VIS I fpsub16 */
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_fpsub16);
3827 gen_op_store_DT0_fpr(DFPREG(rd));
3829 case 0x055: /* VIS I fpsub16s */
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_fpsub16s);
3834 gen_op_store_FT0_fpr(rd);
3836 case 0x056: /* VIS I fpsub32 */
3837 CHECK_FPU_FEATURE(dc, VIS1);
3838 gen_op_load_fpr_DT0(DFPREG(rs1));
3839 gen_op_load_fpr_DT1(DFPREG(rs2));
3840 tcg_gen_helper_0_0(helper_fpadd32);
3841 gen_op_store_DT0_fpr(DFPREG(rd));
3843 case 0x057: /* VIS I fpsub32s */
3844 CHECK_FPU_FEATURE(dc, VIS1);
3845 gen_op_load_fpr_FT0(rs1);
3846 gen_op_load_fpr_FT1(rs2);
3847 tcg_gen_helper_0_0(helper_fpsub32s);
3848 gen_op_store_FT0_fpr(rd);
3850 case 0x060: /* VIS I fzero */
3851 CHECK_FPU_FEATURE(dc, VIS1);
3852 tcg_gen_helper_0_0(helper_movl_DT0_0);
3853 gen_op_store_DT0_fpr(DFPREG(rd));
3855 case 0x061: /* VIS I fzeros */
3856 CHECK_FPU_FEATURE(dc, VIS1);
3857 tcg_gen_helper_0_0(helper_movl_FT0_0);
3858 gen_op_store_FT0_fpr(rd);
3860 case 0x062: /* VIS I fnor */
3861 CHECK_FPU_FEATURE(dc, VIS1);
3862 gen_op_load_fpr_DT0(DFPREG(rs1));
3863 gen_op_load_fpr_DT1(DFPREG(rs2));
3864 tcg_gen_helper_0_0(helper_fnor);
3865 gen_op_store_DT0_fpr(DFPREG(rd));
3867 case 0x063: /* VIS I fnors */
3868 CHECK_FPU_FEATURE(dc, VIS1);
3869 gen_op_load_fpr_FT0(rs1);
3870 gen_op_load_fpr_FT1(rs2);
3871 tcg_gen_helper_0_0(helper_fnors);
3872 gen_op_store_FT0_fpr(rd);
3874 case 0x064: /* VIS I fandnot2 */
3875 CHECK_FPU_FEATURE(dc, VIS1);
3876 gen_op_load_fpr_DT1(DFPREG(rs1));
3877 gen_op_load_fpr_DT0(DFPREG(rs2));
3878 tcg_gen_helper_0_0(helper_fandnot);
3879 gen_op_store_DT0_fpr(DFPREG(rd));
3881 case 0x065: /* VIS I fandnot2s */
3882 CHECK_FPU_FEATURE(dc, VIS1);
3883 gen_op_load_fpr_FT1(rs1);
3884 gen_op_load_fpr_FT0(rs2);
3885 tcg_gen_helper_0_0(helper_fandnots);
3886 gen_op_store_FT0_fpr(rd);
3888 case 0x066: /* VIS I fnot2 */
3889 CHECK_FPU_FEATURE(dc, VIS1);
3890 gen_op_load_fpr_DT1(DFPREG(rs2));
3891 tcg_gen_helper_0_0(helper_fnot);
3892 gen_op_store_DT0_fpr(DFPREG(rd));
3894 case 0x067: /* VIS I fnot2s */
3895 CHECK_FPU_FEATURE(dc, VIS1);
3896 gen_op_load_fpr_FT1(rs2);
3897 tcg_gen_helper_0_0(helper_fnot);
3898 gen_op_store_FT0_fpr(rd);
3900 case 0x068: /* VIS I fandnot1 */
3901 CHECK_FPU_FEATURE(dc, VIS1);
3902 gen_op_load_fpr_DT0(DFPREG(rs1));
3903 gen_op_load_fpr_DT1(DFPREG(rs2));
3904 tcg_gen_helper_0_0(helper_fandnot);
3905 gen_op_store_DT0_fpr(DFPREG(rd));
3907 case 0x069: /* VIS I fandnot1s */
3908 CHECK_FPU_FEATURE(dc, VIS1);
3909 gen_op_load_fpr_FT0(rs1);
3910 gen_op_load_fpr_FT1(rs2);
3911 tcg_gen_helper_0_0(helper_fandnots);
3912 gen_op_store_FT0_fpr(rd);
3914 case 0x06a: /* VIS I fnot1 */
3915 CHECK_FPU_FEATURE(dc, VIS1);
3916 gen_op_load_fpr_DT1(DFPREG(rs1));
3917 tcg_gen_helper_0_0(helper_fnot);
3918 gen_op_store_DT0_fpr(DFPREG(rd));
3920 case 0x06b: /* VIS I fnot1s */
3921 CHECK_FPU_FEATURE(dc, VIS1);
3922 gen_op_load_fpr_FT1(rs1);
3923 tcg_gen_helper_0_0(helper_fnot);
3924 gen_op_store_FT0_fpr(rd);
3926 case 0x06c: /* VIS I fxor */
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_fxor);
3931 gen_op_store_DT0_fpr(DFPREG(rd));
3933 case 0x06d: /* VIS I fxors */
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_fxors);
3938 gen_op_store_FT0_fpr(rd);
3940 case 0x06e: /* VIS I fnand */
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_fnand);
3945 gen_op_store_DT0_fpr(DFPREG(rd));
3947 case 0x06f: /* VIS I fnands */
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_fnands);
3952 gen_op_store_FT0_fpr(rd);
3954 case 0x070: /* VIS I fand */
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_fand);
3959 gen_op_store_DT0_fpr(DFPREG(rd));
3961 case 0x071: /* VIS I fands */
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_fands);
3966 gen_op_store_FT0_fpr(rd);
3968 case 0x072: /* VIS I fxnor */
3969 CHECK_FPU_FEATURE(dc, VIS1);
3970 gen_op_load_fpr_DT0(DFPREG(rs1));
3971 gen_op_load_fpr_DT1(DFPREG(rs2));
3972 tcg_gen_helper_0_0(helper_fxnor);
3973 gen_op_store_DT0_fpr(DFPREG(rd));
3975 case 0x073: /* VIS I fxnors */
3976 CHECK_FPU_FEATURE(dc, VIS1);
3977 gen_op_load_fpr_FT0(rs1);
3978 gen_op_load_fpr_FT1(rs2);
3979 tcg_gen_helper_0_0(helper_fxnors);
3980 gen_op_store_FT0_fpr(rd);
3982 case 0x074: /* VIS I fsrc1 */
3983 CHECK_FPU_FEATURE(dc, VIS1);
3984 gen_op_load_fpr_DT0(DFPREG(rs1));
3985 gen_op_store_DT0_fpr(DFPREG(rd));
3987 case 0x075: /* VIS I fsrc1s */
3988 CHECK_FPU_FEATURE(dc, VIS1);
3989 gen_op_load_fpr_FT0(rs1);
3990 gen_op_store_FT0_fpr(rd);
3992 case 0x076: /* VIS I fornot2 */
3993 CHECK_FPU_FEATURE(dc, VIS1);
3994 gen_op_load_fpr_DT1(DFPREG(rs1));
3995 gen_op_load_fpr_DT0(DFPREG(rs2));
3996 tcg_gen_helper_0_0(helper_fornot);
3997 gen_op_store_DT0_fpr(DFPREG(rd));
3999 case 0x077: /* VIS I fornot2s */
4000 CHECK_FPU_FEATURE(dc, VIS1);
4001 gen_op_load_fpr_FT1(rs1);
4002 gen_op_load_fpr_FT0(rs2);
4003 tcg_gen_helper_0_0(helper_fornots);
4004 gen_op_store_FT0_fpr(rd);
4006 case 0x078: /* VIS I fsrc2 */
4007 CHECK_FPU_FEATURE(dc, VIS1);
4008 gen_op_load_fpr_DT0(DFPREG(rs2));
4009 gen_op_store_DT0_fpr(DFPREG(rd));
4011 case 0x079: /* VIS I fsrc2s */
4012 CHECK_FPU_FEATURE(dc, VIS1);
4013 gen_op_load_fpr_FT0(rs2);
4014 gen_op_store_FT0_fpr(rd);
4016 case 0x07a: /* VIS I fornot1 */
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_fornot);
4021 gen_op_store_DT0_fpr(DFPREG(rd));
4023 case 0x07b: /* VIS I fornot1s */
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_fornots);
4028 gen_op_store_FT0_fpr(rd);
4030 case 0x07c: /* VIS I for */
4031 CHECK_FPU_FEATURE(dc, VIS1);
4032 gen_op_load_fpr_DT0(DFPREG(rs1));
4033 gen_op_load_fpr_DT1(DFPREG(rs2));
4034 tcg_gen_helper_0_0(helper_for);
4035 gen_op_store_DT0_fpr(DFPREG(rd));
4037 case 0x07d: /* VIS I fors */
4038 CHECK_FPU_FEATURE(dc, VIS1);
4039 gen_op_load_fpr_FT0(rs1);
4040 gen_op_load_fpr_FT1(rs2);
4041 tcg_gen_helper_0_0(helper_fors);
4042 gen_op_store_FT0_fpr(rd);
4044 case 0x07e: /* VIS I fone */
4045 CHECK_FPU_FEATURE(dc, VIS1);
4046 tcg_gen_helper_0_0(helper_movl_DT0_1);
4047 gen_op_store_DT0_fpr(DFPREG(rd));
4049 case 0x07f: /* VIS I fones */
4050 CHECK_FPU_FEATURE(dc, VIS1);
4051 tcg_gen_helper_0_0(helper_movl_FT0_1);
4052 gen_op_store_FT0_fpr(rd);
4054 case 0x080: /* VIS I shutdown */
4055 case 0x081: /* VIS II siam */
4064 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4065 #ifdef TARGET_SPARC64
4070 #ifdef TARGET_SPARC64
4071 } else if (xop == 0x39) { /* V9 return */
4074 save_state(dc, cpu_cond);
4075 cpu_src1 = get_src1(insn, cpu_src1);
4076 if (IS_IMM) { /* immediate */
4077 rs2 = GET_FIELDs(insn, 19, 31);
4078 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4079 } else { /* register */
4080 rs2 = GET_FIELD(insn, 27, 31);
4082 gen_movl_reg_TN(rs2, cpu_src2);
4083 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4085 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4087 tcg_gen_helper_0_0(helper_restore);
4088 gen_mov_pc_npc(dc, cpu_cond);
4089 r_const = tcg_const_i32(3);
4090 tcg_gen_helper_0_2(helper_check_align, cpu_dst, r_const);
4091 tcg_temp_free(r_const);
4092 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4093 dc->npc = DYNAMIC_PC;
4097 cpu_src1 = get_src1(insn, cpu_src1);
4098 if (IS_IMM) { /* immediate */
4099 rs2 = GET_FIELDs(insn, 19, 31);
4100 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4101 } else { /* register */
4102 rs2 = GET_FIELD(insn, 27, 31);
4104 gen_movl_reg_TN(rs2, cpu_src2);
4105 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4107 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4110 case 0x38: /* jmpl */
4114 r_const = tcg_const_tl(dc->pc);
4115 gen_movl_TN_reg(rd, r_const);
4116 tcg_temp_free(r_const);
4117 gen_mov_pc_npc(dc, cpu_cond);
4118 r_const = tcg_const_i32(3);
4119 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4121 tcg_temp_free(r_const);
4122 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4123 dc->npc = DYNAMIC_PC;
4126 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4127 case 0x39: /* rett, V9 return */
4131 if (!supervisor(dc))
4133 gen_mov_pc_npc(dc, cpu_cond);
4134 r_const = tcg_const_i32(3);
4135 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4137 tcg_temp_free(r_const);
4138 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4139 dc->npc = DYNAMIC_PC;
4140 tcg_gen_helper_0_0(helper_rett);
4144 case 0x3b: /* flush */
4145 if (!((dc)->def->features & CPU_FEATURE_FLUSH))
4147 tcg_gen_helper_0_1(helper_flush, cpu_dst);
4149 case 0x3c: /* save */
4150 save_state(dc, cpu_cond);
4151 tcg_gen_helper_0_0(helper_save);
4152 gen_movl_TN_reg(rd, cpu_dst);
4154 case 0x3d: /* restore */
4155 save_state(dc, cpu_cond);
4156 tcg_gen_helper_0_0(helper_restore);
4157 gen_movl_TN_reg(rd, cpu_dst);
4159 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4160 case 0x3e: /* V9 done/retry */
4164 if (!supervisor(dc))
4166 dc->npc = DYNAMIC_PC;
4167 dc->pc = DYNAMIC_PC;
4168 tcg_gen_helper_0_0(helper_done);
4171 if (!supervisor(dc))
4173 dc->npc = DYNAMIC_PC;
4174 dc->pc = DYNAMIC_PC;
4175 tcg_gen_helper_0_0(helper_retry);
4190 case 3: /* load/store instructions */
4192 unsigned int xop = GET_FIELD(insn, 7, 12);
4194 cpu_src1 = get_src1(insn, cpu_src1);
4195 if (xop == 0x3c || xop == 0x3e) { // V9 casa/casxa
4196 rs2 = GET_FIELD(insn, 27, 31);
4197 gen_movl_reg_TN(rs2, cpu_src2);
4198 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4199 } else if (IS_IMM) { /* immediate */
4200 rs2 = GET_FIELDs(insn, 19, 31);
4201 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4202 } else { /* register */
4203 rs2 = GET_FIELD(insn, 27, 31);
4205 gen_movl_reg_TN(rs2, cpu_src2);
4206 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4208 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4210 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4211 (xop > 0x17 && xop <= 0x1d ) ||
4212 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4214 case 0x0: /* load unsigned word */
4215 gen_address_mask(dc, cpu_addr);
4216 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4218 case 0x1: /* load unsigned byte */
4219 gen_address_mask(dc, cpu_addr);
4220 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4222 case 0x2: /* load unsigned halfword */
4223 gen_address_mask(dc, cpu_addr);
4224 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4226 case 0x3: /* load double word */
4232 save_state(dc, cpu_cond);
4233 r_const = tcg_const_i32(7);
4234 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4235 r_const); // XXX remove
4236 tcg_temp_free(r_const);
4237 gen_address_mask(dc, cpu_addr);
4238 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4239 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4240 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4241 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4242 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4243 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4244 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4247 case 0x9: /* load signed byte */
4248 gen_address_mask(dc, cpu_addr);
4249 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4251 case 0xa: /* load signed halfword */
4252 gen_address_mask(dc, cpu_addr);
4253 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4255 case 0xd: /* ldstub -- XXX: should be atomically */
4259 gen_address_mask(dc, cpu_addr);
4260 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4261 r_const = tcg_const_tl(0xff);
4262 tcg_gen_qemu_st8(r_const, cpu_addr, dc->mem_idx);
4263 tcg_temp_free(r_const);
4266 case 0x0f: /* swap register with memory. Also
4268 CHECK_IU_FEATURE(dc, SWAP);
4269 gen_movl_reg_TN(rd, cpu_val);
4270 gen_address_mask(dc, cpu_addr);
4271 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4272 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4273 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4275 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4276 case 0x10: /* load word alternate */
4277 #ifndef TARGET_SPARC64
4280 if (!supervisor(dc))
4283 save_state(dc, cpu_cond);
4284 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4286 case 0x11: /* load unsigned byte alternate */
4287 #ifndef TARGET_SPARC64
4290 if (!supervisor(dc))
4293 save_state(dc, cpu_cond);
4294 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4296 case 0x12: /* load unsigned halfword alternate */
4297 #ifndef TARGET_SPARC64
4300 if (!supervisor(dc))
4303 save_state(dc, cpu_cond);
4304 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4306 case 0x13: /* load double word alternate */
4307 #ifndef TARGET_SPARC64
4310 if (!supervisor(dc))
4315 save_state(dc, cpu_cond);
4316 gen_ldda_asi(cpu_val, cpu_addr, insn, rd);
4318 case 0x19: /* load signed byte alternate */
4319 #ifndef TARGET_SPARC64
4322 if (!supervisor(dc))
4325 save_state(dc, cpu_cond);
4326 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4328 case 0x1a: /* load signed halfword alternate */
4329 #ifndef TARGET_SPARC64
4332 if (!supervisor(dc))
4335 save_state(dc, cpu_cond);
4336 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4338 case 0x1d: /* ldstuba -- XXX: should be atomically */
4339 #ifndef TARGET_SPARC64
4342 if (!supervisor(dc))
4345 save_state(dc, cpu_cond);
4346 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4348 case 0x1f: /* swap reg with alt. memory. Also
4350 CHECK_IU_FEATURE(dc, SWAP);
4351 #ifndef TARGET_SPARC64
4354 if (!supervisor(dc))
4357 save_state(dc, cpu_cond);
4358 gen_movl_reg_TN(rd, cpu_val);
4359 gen_swap_asi(cpu_val, cpu_addr, insn);
4362 #ifndef TARGET_SPARC64
4363 case 0x30: /* ldc */
4364 case 0x31: /* ldcsr */
4365 case 0x33: /* lddc */
4369 #ifdef TARGET_SPARC64
4370 case 0x08: /* V9 ldsw */
4371 gen_address_mask(dc, cpu_addr);
4372 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4374 case 0x0b: /* V9 ldx */
4375 gen_address_mask(dc, cpu_addr);
4376 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4378 case 0x18: /* V9 ldswa */
4379 save_state(dc, cpu_cond);
4380 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4382 case 0x1b: /* V9 ldxa */
4383 save_state(dc, cpu_cond);
4384 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4386 case 0x2d: /* V9 prefetch, no effect */
4388 case 0x30: /* V9 ldfa */
4389 save_state(dc, cpu_cond);
4390 gen_ldf_asi(cpu_addr, insn, 4, rd);
4392 case 0x33: /* V9 lddfa */
4393 save_state(dc, cpu_cond);
4394 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4396 case 0x3d: /* V9 prefetcha, no effect */
4398 case 0x32: /* V9 ldqfa */
4399 CHECK_FPU_FEATURE(dc, FLOAT128);
4400 save_state(dc, cpu_cond);
4401 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4407 gen_movl_TN_reg(rd, cpu_val);
4408 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4411 } else if (xop >= 0x20 && xop < 0x24) {
4412 if (gen_trap_ifnofpu(dc, cpu_cond))
4414 save_state(dc, cpu_cond);
4416 case 0x20: /* load fpreg */
4417 gen_address_mask(dc, cpu_addr);
4418 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4419 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4420 offsetof(CPUState, fpr[rd]));
4422 case 0x21: /* load fsr */
4423 gen_address_mask(dc, cpu_addr);
4424 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4425 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4426 offsetof(CPUState, ft0));
4427 tcg_gen_helper_0_0(helper_ldfsr);
4429 case 0x22: /* load quad fpreg */
4433 CHECK_FPU_FEATURE(dc, FLOAT128);
4434 r_const = tcg_const_i32(dc->mem_idx);
4435 tcg_gen_helper_0_2(helper_ldqf, cpu_addr, r_const);
4436 tcg_temp_free(r_const);
4437 gen_op_store_QT0_fpr(QFPREG(rd));
4440 case 0x23: /* load double fpreg */
4444 r_const = tcg_const_i32(dc->mem_idx);
4445 tcg_gen_helper_0_2(helper_lddf, cpu_addr, r_const);
4446 tcg_temp_free(r_const);
4447 gen_op_store_DT0_fpr(DFPREG(rd));
4453 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4454 xop == 0xe || xop == 0x1e) {
4455 gen_movl_reg_TN(rd, cpu_val);
4457 case 0x4: /* store word */
4458 gen_address_mask(dc, cpu_addr);
4459 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4461 case 0x5: /* store byte */
4462 gen_address_mask(dc, cpu_addr);
4463 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4465 case 0x6: /* store halfword */
4466 gen_address_mask(dc, cpu_addr);
4467 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4469 case 0x7: /* store double word */
4473 TCGv r_low, r_const;
4475 save_state(dc, cpu_cond);
4476 gen_address_mask(dc, cpu_addr);
4477 r_const = tcg_const_i32(7);
4478 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4479 r_const); // XXX remove
4480 tcg_temp_free(r_const);
4481 r_low = tcg_temp_new(TCG_TYPE_TL);
4482 gen_movl_reg_TN(rd + 1, r_low);
4483 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4485 tcg_temp_free(r_low);
4486 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4489 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4490 case 0x14: /* store word alternate */
4491 #ifndef TARGET_SPARC64
4494 if (!supervisor(dc))
4497 save_state(dc, cpu_cond);
4498 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4500 case 0x15: /* store byte alternate */
4501 #ifndef TARGET_SPARC64
4504 if (!supervisor(dc))
4507 save_state(dc, cpu_cond);
4508 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4510 case 0x16: /* store halfword alternate */
4511 #ifndef TARGET_SPARC64
4514 if (!supervisor(dc))
4517 save_state(dc, cpu_cond);
4518 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4520 case 0x17: /* store double word alternate */
4521 #ifndef TARGET_SPARC64
4524 if (!supervisor(dc))
4530 save_state(dc, cpu_cond);
4531 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4535 #ifdef TARGET_SPARC64
4536 case 0x0e: /* V9 stx */
4537 gen_address_mask(dc, cpu_addr);
4538 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4540 case 0x1e: /* V9 stxa */
4541 save_state(dc, cpu_cond);
4542 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4548 } else if (xop > 0x23 && xop < 0x28) {
4549 if (gen_trap_ifnofpu(dc, cpu_cond))
4551 save_state(dc, cpu_cond);
4553 case 0x24: /* store fpreg */
4554 gen_address_mask(dc, cpu_addr);
4555 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4556 offsetof(CPUState, fpr[rd]));
4557 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4559 case 0x25: /* stfsr, V9 stxfsr */
4560 gen_address_mask(dc, cpu_addr);
4561 tcg_gen_helper_0_0(helper_stfsr);
4562 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4563 offsetof(CPUState, ft0));
4564 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4567 #ifdef TARGET_SPARC64
4568 /* V9 stqf, store quad fpreg */
4572 CHECK_FPU_FEATURE(dc, FLOAT128);
4573 gen_op_load_fpr_QT0(QFPREG(rd));
4574 r_const = tcg_const_i32(dc->mem_idx);
4575 tcg_gen_helper_0_2(helper_stqf, cpu_addr, r_const);
4576 tcg_temp_free(r_const);
4579 #else /* !TARGET_SPARC64 */
4580 /* stdfq, store floating point queue */
4581 #if defined(CONFIG_USER_ONLY)
4584 if (!supervisor(dc))
4586 if (gen_trap_ifnofpu(dc, cpu_cond))
4591 case 0x27: /* store double fpreg */
4595 gen_op_load_fpr_DT0(DFPREG(rd));
4596 r_const = tcg_const_i32(dc->mem_idx);
4597 tcg_gen_helper_0_2(helper_stdf, cpu_addr, r_const);
4598 tcg_temp_free(r_const);
4604 } else if (xop > 0x33 && xop < 0x3f) {
4605 save_state(dc, cpu_cond);
4607 #ifdef TARGET_SPARC64
4608 case 0x34: /* V9 stfa */
4609 gen_op_load_fpr_FT0(rd);
4610 gen_stf_asi(cpu_addr, insn, 4, rd);
4612 case 0x36: /* V9 stqfa */
4616 CHECK_FPU_FEATURE(dc, FLOAT128);
4617 r_const = tcg_const_i32(7);
4618 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4620 tcg_temp_free(r_const);
4621 gen_op_load_fpr_QT0(QFPREG(rd));
4622 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4625 case 0x37: /* V9 stdfa */
4626 gen_op_load_fpr_DT0(DFPREG(rd));
4627 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4629 case 0x3c: /* V9 casa */
4630 gen_cas_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4631 gen_movl_TN_reg(rd, cpu_val);
4633 case 0x3e: /* V9 casxa */
4634 gen_casx_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4635 gen_movl_TN_reg(rd, cpu_val);
4638 case 0x34: /* stc */
4639 case 0x35: /* stcsr */
4640 case 0x36: /* stdcq */
4641 case 0x37: /* stdc */
4653 /* default case for non jump instructions */
4654 if (dc->npc == DYNAMIC_PC) {
4655 dc->pc = DYNAMIC_PC;
4657 } else if (dc->npc == JUMP_PC) {
4658 /* we can do a static jump */
4659 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4663 dc->npc = dc->npc + 4;
4671 save_state(dc, cpu_cond);
4672 r_const = tcg_const_i32(TT_ILL_INSN);
4673 tcg_gen_helper_0_1(raise_exception, r_const);
4674 tcg_temp_free(r_const);
4682 save_state(dc, cpu_cond);
4683 r_const = tcg_const_i32(TT_UNIMP_FLUSH);
4684 tcg_gen_helper_0_1(raise_exception, r_const);
4685 tcg_temp_free(r_const);
4689 #if !defined(CONFIG_USER_ONLY)
4694 save_state(dc, cpu_cond);
4695 r_const = tcg_const_i32(TT_PRIV_INSN);
4696 tcg_gen_helper_0_1(raise_exception, r_const);
4697 tcg_temp_free(r_const);
4703 save_state(dc, cpu_cond);
4704 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4707 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4709 save_state(dc, cpu_cond);
4710 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4714 #ifndef TARGET_SPARC64
4719 save_state(dc, cpu_cond);
4720 r_const = tcg_const_i32(TT_NCP_INSN);
4721 tcg_gen_helper_0_1(raise_exception, r_const);
4722 tcg_temp_free(r_const);
4729 static inline void gen_intermediate_code_internal(TranslationBlock * tb,
4730 int spc, CPUSPARCState *env)
4732 target_ulong pc_start, last_pc;
4733 uint16_t *gen_opc_end;
4734 DisasContext dc1, *dc = &dc1;
4739 memset(dc, 0, sizeof(DisasContext));
4744 dc->npc = (target_ulong) tb->cs_base;
4745 dc->mem_idx = cpu_mmu_index(env);
4747 if ((dc->def->features & CPU_FEATURE_FLOAT))
4748 dc->fpu_enabled = cpu_fpu_enabled(env);
4750 dc->fpu_enabled = 0;
4751 #ifdef TARGET_SPARC64
4752 dc->address_mask_32bit = env->pstate & PS_AM;
4754 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4756 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4757 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4758 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4760 cpu_dst = tcg_temp_local_new(TCG_TYPE_TL);
4763 cpu_val = tcg_temp_local_new(TCG_TYPE_TL);
4764 cpu_addr = tcg_temp_local_new(TCG_TYPE_TL);
4767 max_insns = tb->cflags & CF_COUNT_MASK;
4769 max_insns = CF_COUNT_MASK;
4772 if (env->nb_breakpoints > 0) {
4773 for(j = 0; j < env->nb_breakpoints; j++) {
4774 if (env->breakpoints[j] == dc->pc) {
4775 if (dc->pc != pc_start)
4776 save_state(dc, cpu_cond);
4777 tcg_gen_helper_0_0(helper_debug);
4786 fprintf(logfile, "Search PC...\n");
4787 j = gen_opc_ptr - gen_opc_buf;
4791 gen_opc_instr_start[lj++] = 0;
4792 gen_opc_pc[lj] = dc->pc;
4793 gen_opc_npc[lj] = dc->npc;
4794 gen_opc_instr_start[lj] = 1;
4795 gen_opc_icount[lj] = num_insns;
4798 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
4801 disas_sparc_insn(dc);
4806 /* if the next PC is different, we abort now */
4807 if (dc->pc != (last_pc + 4))
4809 /* if we reach a page boundary, we stop generation so that the
4810 PC of a TT_TFAULT exception is always in the right page */
4811 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4813 /* if single step mode, we generate only one instruction and
4814 generate an exception */
4815 if (env->singlestep_enabled) {
4816 tcg_gen_movi_tl(cpu_pc, dc->pc);
4820 } while ((gen_opc_ptr < gen_opc_end) &&
4821 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
4822 num_insns < max_insns);
4825 tcg_temp_free(cpu_addr);
4826 tcg_temp_free(cpu_val);
4827 tcg_temp_free(cpu_dst);
4828 tcg_temp_free(cpu_tmp64);
4829 tcg_temp_free(cpu_tmp32);
4830 tcg_temp_free(cpu_tmp0);
4831 if (tb->cflags & CF_LAST_IO)
4834 if (dc->pc != DYNAMIC_PC &&
4835 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4836 /* static PC and NPC: we can use direct chaining */
4837 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4839 if (dc->pc != DYNAMIC_PC)
4840 tcg_gen_movi_tl(cpu_pc, dc->pc);
4841 save_npc(dc, cpu_cond);
4845 gen_icount_end(tb, num_insns);
4846 *gen_opc_ptr = INDEX_op_end;
4848 j = gen_opc_ptr - gen_opc_buf;
4851 gen_opc_instr_start[lj++] = 0;
4857 gen_opc_jump_pc[0] = dc->jump_pc[0];
4858 gen_opc_jump_pc[1] = dc->jump_pc[1];
4860 tb->size = last_pc + 4 - pc_start;
4861 tb->icount = num_insns;
4864 if (loglevel & CPU_LOG_TB_IN_ASM) {
4865 fprintf(logfile, "--------------\n");
4866 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4867 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4868 fprintf(logfile, "\n");
4873 void gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4875 gen_intermediate_code_internal(tb, 0, env);
4878 void gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4880 gen_intermediate_code_internal(tb, 1, env);
4883 void gen_intermediate_code_init(CPUSPARCState *env)
4887 static const char * const gregnames[8] = {
4888 NULL, // g0 not used
4898 /* init various static tables */
4902 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4903 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4904 offsetof(CPUState, regwptr),
4906 #ifdef TARGET_SPARC64
4907 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4908 TCG_AREG0, offsetof(CPUState, xcc),
4911 cpu_cond = tcg_global_mem_new(TCG_TYPE_TL,
4912 TCG_AREG0, offsetof(CPUState, cond),
4914 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4915 TCG_AREG0, offsetof(CPUState, cc_src),
4917 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4918 offsetof(CPUState, cc_src2),
4920 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4921 TCG_AREG0, offsetof(CPUState, cc_dst),
4923 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4924 TCG_AREG0, offsetof(CPUState, psr),
4926 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4927 TCG_AREG0, offsetof(CPUState, fsr),
4929 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4930 TCG_AREG0, offsetof(CPUState, pc),
4932 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4933 TCG_AREG0, offsetof(CPUState, npc),
4935 for (i = 1; i < 8; i++)
4936 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4937 offsetof(CPUState, gregs[i]),
4939 /* register helpers */
4942 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
4947 void gen_pc_load(CPUState *env, TranslationBlock *tb,
4948 unsigned long searched_pc, int pc_pos, void *puc)
4951 env->pc = gen_opc_pc[pc_pos];
4952 npc = gen_opc_npc[pc_pos];
4954 /* dynamic NPC: already stored */
4955 } else if (npc == 2) {
4956 target_ulong t2 = (target_ulong)(unsigned long)puc;
4957 /* jump PC: use T2 and the jump targets of the translation */
4959 env->npc = gen_opc_jump_pc[0];
4961 env->npc = gen_opc_jump_pc[1];