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];
45 #ifndef CONFIG_USER_ONLY
48 static TCGv cpu_cond, cpu_src1, cpu_src2, cpu_dst, cpu_addr, cpu_val;
50 static TCGv cpu_xcc, cpu_asi, cpu_fprs, cpu_gsr;
51 static TCGv cpu_tick_cmpr, cpu_stick_cmpr, cpu_hstick_cmpr;
52 static TCGv cpu_hintp, cpu_htba, cpu_hver, cpu_ssr, cpu_ver;
56 /* local register indexes (only used inside old micro ops) */
57 static TCGv cpu_tmp0, cpu_tmp32, cpu_tmp64;
58 /* Floating point registers */
59 static TCGv cpu_fpr[TARGET_FPREGS];
61 #include "gen-icount.h"
63 typedef struct DisasContext {
64 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
65 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
66 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
70 int address_mask_32bit;
71 struct TranslationBlock *tb;
75 // This function uses non-native bit order
76 #define GET_FIELD(X, FROM, TO) \
77 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
79 // This function uses the order in the manuals, i.e. bit 0 is 2^0
80 #define GET_FIELD_SP(X, FROM, TO) \
81 GET_FIELD(X, 31 - (TO), 31 - (FROM))
83 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
84 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
88 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
89 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
92 #define DFPREG(r) (r & 0x1e)
93 #define QFPREG(r) (r & 0x1c)
96 static int sign_extend(int x, int len)
99 return (x << len) >> len;
102 #define IS_IMM (insn & (1<<13))
104 /* floating point registers moves */
105 static void gen_op_load_fpr_DT0(unsigned int src)
107 tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, dt0) +
108 offsetof(CPU_DoubleU, l.upper));
109 tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, dt0) +
110 offsetof(CPU_DoubleU, l.lower));
113 static void gen_op_load_fpr_DT1(unsigned int src)
115 tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, dt1) +
116 offsetof(CPU_DoubleU, l.upper));
117 tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, dt1) +
118 offsetof(CPU_DoubleU, l.lower));
121 static void gen_op_store_DT0_fpr(unsigned int dst)
123 tcg_gen_ld_i32(cpu_fpr[dst], cpu_env, offsetof(CPUSPARCState, dt0) +
124 offsetof(CPU_DoubleU, l.upper));
125 tcg_gen_ld_i32(cpu_fpr[dst + 1], cpu_env, offsetof(CPUSPARCState, dt0) +
126 offsetof(CPU_DoubleU, l.lower));
129 static void gen_op_load_fpr_QT0(unsigned int src)
131 tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, qt0) +
132 offsetof(CPU_QuadU, l.upmost));
133 tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, qt0) +
134 offsetof(CPU_QuadU, l.upper));
135 tcg_gen_st_i32(cpu_fpr[src + 2], cpu_env, offsetof(CPUSPARCState, qt0) +
136 offsetof(CPU_QuadU, l.lower));
137 tcg_gen_st_i32(cpu_fpr[src + 3], cpu_env, offsetof(CPUSPARCState, qt0) +
138 offsetof(CPU_QuadU, l.lowest));
141 static void gen_op_load_fpr_QT1(unsigned int src)
143 tcg_gen_st_i32(cpu_fpr[src], cpu_env, offsetof(CPUSPARCState, qt1) +
144 offsetof(CPU_QuadU, l.upmost));
145 tcg_gen_st_i32(cpu_fpr[src + 1], cpu_env, offsetof(CPUSPARCState, qt1) +
146 offsetof(CPU_QuadU, l.upper));
147 tcg_gen_st_i32(cpu_fpr[src + 2], cpu_env, offsetof(CPUSPARCState, qt1) +
148 offsetof(CPU_QuadU, l.lower));
149 tcg_gen_st_i32(cpu_fpr[src + 3], cpu_env, offsetof(CPUSPARCState, qt1) +
150 offsetof(CPU_QuadU, l.lowest));
153 static void gen_op_store_QT0_fpr(unsigned int dst)
155 tcg_gen_ld_i32(cpu_fpr[dst], cpu_env, offsetof(CPUSPARCState, qt0) +
156 offsetof(CPU_QuadU, l.upmost));
157 tcg_gen_ld_i32(cpu_fpr[dst + 1], cpu_env, offsetof(CPUSPARCState, qt0) +
158 offsetof(CPU_QuadU, l.upper));
159 tcg_gen_ld_i32(cpu_fpr[dst + 2], cpu_env, offsetof(CPUSPARCState, qt0) +
160 offsetof(CPU_QuadU, l.lower));
161 tcg_gen_ld_i32(cpu_fpr[dst + 3], cpu_env, offsetof(CPUSPARCState, qt0) +
162 offsetof(CPU_QuadU, l.lowest));
166 #ifdef CONFIG_USER_ONLY
167 #define supervisor(dc) 0
168 #ifdef TARGET_SPARC64
169 #define hypervisor(dc) 0
172 #define supervisor(dc) (dc->mem_idx >= 1)
173 #ifdef TARGET_SPARC64
174 #define hypervisor(dc) (dc->mem_idx == 2)
179 #ifdef TARGET_SPARC64
181 #define AM_CHECK(dc) ((dc)->address_mask_32bit)
183 #define AM_CHECK(dc) (1)
187 static inline void gen_address_mask(DisasContext *dc, TCGv addr)
189 #ifdef TARGET_SPARC64
191 tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
195 static inline void gen_movl_reg_TN(int reg, TCGv tn)
198 tcg_gen_movi_tl(tn, 0);
200 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
202 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
206 static inline void gen_movl_TN_reg(int reg, TCGv tn)
211 tcg_gen_mov_tl(cpu_gregs[reg], tn);
213 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
217 static inline void gen_goto_tb(DisasContext *s, int tb_num,
218 target_ulong pc, target_ulong npc)
220 TranslationBlock *tb;
223 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
224 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
225 /* jump to same page: we can use a direct jump */
226 tcg_gen_goto_tb(tb_num);
227 tcg_gen_movi_tl(cpu_pc, pc);
228 tcg_gen_movi_tl(cpu_npc, npc);
229 tcg_gen_exit_tb((long)tb + tb_num);
231 /* jump to another page: currently not optimized */
232 tcg_gen_movi_tl(cpu_pc, pc);
233 tcg_gen_movi_tl(cpu_npc, npc);
239 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
241 tcg_gen_extu_i32_tl(reg, src);
242 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
243 tcg_gen_andi_tl(reg, reg, 0x1);
246 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
248 tcg_gen_extu_i32_tl(reg, src);
249 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
250 tcg_gen_andi_tl(reg, reg, 0x1);
253 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
255 tcg_gen_extu_i32_tl(reg, src);
256 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
257 tcg_gen_andi_tl(reg, reg, 0x1);
260 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
262 tcg_gen_extu_i32_tl(reg, src);
263 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
264 tcg_gen_andi_tl(reg, reg, 0x1);
267 static inline void gen_cc_clear_icc(void)
269 tcg_gen_movi_i32(cpu_psr, 0);
272 #ifdef TARGET_SPARC64
273 static inline void gen_cc_clear_xcc(void)
275 tcg_gen_movi_i32(cpu_xcc, 0);
281 env->psr |= PSR_ZERO;
282 if ((int32_t) T0 < 0)
285 static inline void gen_cc_NZ_icc(TCGv dst)
290 l1 = gen_new_label();
291 l2 = gen_new_label();
292 r_temp = tcg_temp_new(TCG_TYPE_TL);
293 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
294 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
295 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
297 tcg_gen_ext_i32_tl(r_temp, dst);
298 tcg_gen_brcondi_tl(TCG_COND_GE, r_temp, 0, l2);
299 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
301 tcg_temp_free(r_temp);
304 #ifdef TARGET_SPARC64
305 static inline void gen_cc_NZ_xcc(TCGv dst)
309 l1 = gen_new_label();
310 l2 = gen_new_label();
311 tcg_gen_brcondi_tl(TCG_COND_NE, dst, 0, l1);
312 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
314 tcg_gen_brcondi_tl(TCG_COND_GE, dst, 0, l2);
315 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
322 env->psr |= PSR_CARRY;
324 static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
326 TCGv r_temp1, r_temp2;
329 l1 = gen_new_label();
330 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
331 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
332 tcg_gen_andi_tl(r_temp1, dst, 0xffffffffULL);
333 tcg_gen_andi_tl(r_temp2, src1, 0xffffffffULL);
334 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
335 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
337 tcg_temp_free(r_temp1);
338 tcg_temp_free(r_temp2);
341 #ifdef TARGET_SPARC64
342 static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
346 l1 = gen_new_label();
347 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
348 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
354 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
357 static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
361 r_temp = tcg_temp_new(TCG_TYPE_TL);
362 tcg_gen_xor_tl(r_temp, src1, src2);
363 tcg_gen_xori_tl(r_temp, r_temp, -1);
364 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
365 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
366 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
367 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
368 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
369 tcg_temp_free(r_temp);
370 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
373 #ifdef TARGET_SPARC64
374 static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
378 r_temp = tcg_temp_new(TCG_TYPE_TL);
379 tcg_gen_xor_tl(r_temp, src1, src2);
380 tcg_gen_xori_tl(r_temp, r_temp, -1);
381 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
382 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
383 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
384 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
385 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
386 tcg_temp_free(r_temp);
387 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
391 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
393 TCGv r_temp, r_const;
396 l1 = gen_new_label();
398 r_temp = tcg_temp_new(TCG_TYPE_TL);
399 tcg_gen_xor_tl(r_temp, src1, src2);
400 tcg_gen_xori_tl(r_temp, r_temp, -1);
401 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
402 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
403 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
404 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
405 r_const = tcg_const_i32(TT_TOVF);
406 tcg_gen_helper_0_1(raise_exception, r_const);
407 tcg_temp_free(r_const);
409 tcg_temp_free(r_temp);
412 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
416 l1 = gen_new_label();
417 tcg_gen_or_tl(cpu_tmp0, src1, src2);
418 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
419 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
420 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
424 static inline void gen_tag_tv(TCGv src1, TCGv src2)
429 l1 = gen_new_label();
430 tcg_gen_or_tl(cpu_tmp0, src1, src2);
431 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
432 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
433 r_const = tcg_const_i32(TT_TOVF);
434 tcg_gen_helper_0_1(raise_exception, r_const);
435 tcg_temp_free(r_const);
439 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
441 tcg_gen_mov_tl(cpu_cc_src, src1);
442 tcg_gen_mov_tl(cpu_cc_src2, src2);
443 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
445 gen_cc_NZ_icc(cpu_cc_dst);
446 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
447 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
448 #ifdef TARGET_SPARC64
450 gen_cc_NZ_xcc(cpu_cc_dst);
451 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
452 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
454 tcg_gen_mov_tl(dst, cpu_cc_dst);
457 static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
459 tcg_gen_mov_tl(cpu_cc_src, src1);
460 tcg_gen_mov_tl(cpu_cc_src2, src2);
461 gen_mov_reg_C(cpu_tmp0, cpu_psr);
462 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
464 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
465 #ifdef TARGET_SPARC64
467 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
469 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
470 gen_cc_NZ_icc(cpu_cc_dst);
471 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
472 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
473 #ifdef TARGET_SPARC64
474 gen_cc_NZ_xcc(cpu_cc_dst);
475 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
476 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
478 tcg_gen_mov_tl(dst, cpu_cc_dst);
481 static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
483 tcg_gen_mov_tl(cpu_cc_src, src1);
484 tcg_gen_mov_tl(cpu_cc_src2, src2);
485 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
487 gen_cc_NZ_icc(cpu_cc_dst);
488 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
489 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
490 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
491 #ifdef TARGET_SPARC64
493 gen_cc_NZ_xcc(cpu_cc_dst);
494 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
495 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
497 tcg_gen_mov_tl(dst, cpu_cc_dst);
500 static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
502 tcg_gen_mov_tl(cpu_cc_src, src1);
503 tcg_gen_mov_tl(cpu_cc_src2, src2);
504 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
505 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
506 gen_add_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
508 gen_cc_NZ_icc(cpu_cc_dst);
509 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
510 #ifdef TARGET_SPARC64
512 gen_cc_NZ_xcc(cpu_cc_dst);
513 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
514 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
516 tcg_gen_mov_tl(dst, cpu_cc_dst);
521 env->psr |= PSR_CARRY;
523 static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
525 TCGv r_temp1, r_temp2;
528 l1 = gen_new_label();
529 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
530 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
531 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
532 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
533 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
534 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
536 tcg_temp_free(r_temp1);
537 tcg_temp_free(r_temp2);
540 #ifdef TARGET_SPARC64
541 static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
545 l1 = gen_new_label();
546 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
547 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
553 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
556 static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
560 r_temp = tcg_temp_new(TCG_TYPE_TL);
561 tcg_gen_xor_tl(r_temp, src1, src2);
562 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
563 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
564 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
565 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
566 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
567 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
568 tcg_temp_free(r_temp);
571 #ifdef TARGET_SPARC64
572 static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
576 r_temp = tcg_temp_new(TCG_TYPE_TL);
577 tcg_gen_xor_tl(r_temp, src1, src2);
578 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
579 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
580 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
581 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
582 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
583 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
584 tcg_temp_free(r_temp);
588 static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
590 TCGv r_temp, r_const;
593 l1 = gen_new_label();
595 r_temp = tcg_temp_new(TCG_TYPE_TL);
596 tcg_gen_xor_tl(r_temp, src1, src2);
597 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
598 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
599 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
600 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
601 r_const = tcg_const_i32(TT_TOVF);
602 tcg_gen_helper_0_1(raise_exception, r_const);
603 tcg_temp_free(r_const);
605 tcg_temp_free(r_temp);
608 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
610 tcg_gen_mov_tl(cpu_cc_src, src1);
611 tcg_gen_mov_tl(cpu_cc_src2, src2);
612 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
614 gen_cc_NZ_icc(cpu_cc_dst);
615 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
616 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
617 #ifdef TARGET_SPARC64
619 gen_cc_NZ_xcc(cpu_cc_dst);
620 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
621 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
623 tcg_gen_mov_tl(dst, cpu_cc_dst);
626 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
628 tcg_gen_mov_tl(cpu_cc_src, src1);
629 tcg_gen_mov_tl(cpu_cc_src2, src2);
630 gen_mov_reg_C(cpu_tmp0, cpu_psr);
631 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
633 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
634 #ifdef TARGET_SPARC64
636 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
638 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
639 gen_cc_NZ_icc(cpu_cc_dst);
640 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
641 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
642 #ifdef TARGET_SPARC64
643 gen_cc_NZ_xcc(cpu_cc_dst);
644 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
645 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
647 tcg_gen_mov_tl(dst, cpu_cc_dst);
650 static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
652 tcg_gen_mov_tl(cpu_cc_src, src1);
653 tcg_gen_mov_tl(cpu_cc_src2, src2);
654 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
656 gen_cc_NZ_icc(cpu_cc_dst);
657 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
658 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
659 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
660 #ifdef TARGET_SPARC64
662 gen_cc_NZ_xcc(cpu_cc_dst);
663 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
664 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
666 tcg_gen_mov_tl(dst, cpu_cc_dst);
669 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
671 tcg_gen_mov_tl(cpu_cc_src, src1);
672 tcg_gen_mov_tl(cpu_cc_src2, src2);
673 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
674 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
675 gen_sub_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
677 gen_cc_NZ_icc(cpu_cc_dst);
678 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
679 #ifdef TARGET_SPARC64
681 gen_cc_NZ_xcc(cpu_cc_dst);
682 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
683 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
685 tcg_gen_mov_tl(dst, cpu_cc_dst);
688 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
693 l1 = gen_new_label();
694 r_temp = tcg_temp_new(TCG_TYPE_TL);
700 tcg_gen_mov_tl(cpu_cc_src, src1);
701 tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
702 tcg_gen_mov_tl(cpu_cc_src2, src2);
703 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
704 tcg_gen_movi_tl(cpu_cc_src2, 0);
708 // env->y = (b2 << 31) | (env->y >> 1);
709 tcg_gen_andi_tl(r_temp, cpu_cc_src, 0x1);
710 tcg_gen_shli_tl(r_temp, r_temp, 31);
711 tcg_gen_shri_tl(cpu_tmp0, cpu_y, 1);
712 tcg_gen_or_tl(cpu_tmp0, cpu_tmp0, r_temp);
713 tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
716 gen_mov_reg_N(cpu_tmp0, cpu_psr);
717 gen_mov_reg_V(r_temp, cpu_psr);
718 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
719 tcg_temp_free(r_temp);
721 // T0 = (b1 << 31) | (T0 >> 1);
723 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
724 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
725 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
727 /* do addition and update flags */
728 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
731 gen_cc_NZ_icc(cpu_cc_dst);
732 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
733 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
734 tcg_gen_mov_tl(dst, cpu_cc_dst);
737 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
739 TCGv r_temp, r_temp2;
741 r_temp = tcg_temp_new(TCG_TYPE_I64);
742 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
744 tcg_gen_extu_i32_i64(r_temp, src2);
745 tcg_gen_extu_i32_i64(r_temp2, src1);
746 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
748 tcg_gen_shri_i64(r_temp, r_temp2, 32);
749 tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
750 tcg_temp_free(r_temp);
751 tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
752 #ifdef TARGET_SPARC64
753 tcg_gen_mov_i64(dst, r_temp2);
755 tcg_gen_trunc_i64_tl(dst, r_temp2);
757 tcg_temp_free(r_temp2);
760 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
762 TCGv r_temp, r_temp2;
764 r_temp = tcg_temp_new(TCG_TYPE_I64);
765 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
767 tcg_gen_ext_i32_i64(r_temp, src2);
768 tcg_gen_ext_i32_i64(r_temp2, src1);
769 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
771 tcg_gen_shri_i64(r_temp, r_temp2, 32);
772 tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
773 tcg_temp_free(r_temp);
774 tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
775 #ifdef TARGET_SPARC64
776 tcg_gen_mov_i64(dst, r_temp2);
778 tcg_gen_trunc_i64_tl(dst, r_temp2);
780 tcg_temp_free(r_temp2);
783 #ifdef TARGET_SPARC64
784 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
789 l1 = gen_new_label();
790 tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
791 r_const = tcg_const_i32(TT_DIV_ZERO);
792 tcg_gen_helper_0_1(raise_exception, r_const);
793 tcg_temp_free(r_const);
797 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
801 l1 = gen_new_label();
802 l2 = gen_new_label();
803 tcg_gen_mov_tl(cpu_cc_src, src1);
804 tcg_gen_mov_tl(cpu_cc_src2, src2);
805 gen_trap_ifdivzero_tl(cpu_cc_src2);
806 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src, INT64_MIN, l1);
807 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src2, -1, l1);
808 tcg_gen_movi_i64(dst, INT64_MIN);
811 tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
816 static inline void gen_op_div_cc(TCGv dst)
820 tcg_gen_mov_tl(cpu_cc_dst, dst);
822 gen_cc_NZ_icc(cpu_cc_dst);
823 l1 = gen_new_label();
824 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_src2, 0, l1);
825 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
829 static inline void gen_op_logic_cc(TCGv dst)
831 tcg_gen_mov_tl(cpu_cc_dst, dst);
834 gen_cc_NZ_icc(cpu_cc_dst);
835 #ifdef TARGET_SPARC64
837 gen_cc_NZ_xcc(cpu_cc_dst);
842 static inline void gen_op_eval_ba(TCGv dst)
844 tcg_gen_movi_tl(dst, 1);
848 static inline void gen_op_eval_be(TCGv dst, TCGv src)
850 gen_mov_reg_Z(dst, src);
854 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
856 gen_mov_reg_N(cpu_tmp0, src);
857 gen_mov_reg_V(dst, src);
858 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
859 gen_mov_reg_Z(cpu_tmp0, src);
860 tcg_gen_or_tl(dst, dst, cpu_tmp0);
864 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
866 gen_mov_reg_V(cpu_tmp0, src);
867 gen_mov_reg_N(dst, src);
868 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
872 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
874 gen_mov_reg_Z(cpu_tmp0, src);
875 gen_mov_reg_C(dst, src);
876 tcg_gen_or_tl(dst, dst, cpu_tmp0);
880 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
882 gen_mov_reg_C(dst, src);
886 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
888 gen_mov_reg_V(dst, src);
892 static inline void gen_op_eval_bn(TCGv dst)
894 tcg_gen_movi_tl(dst, 0);
898 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
900 gen_mov_reg_N(dst, src);
904 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
906 gen_mov_reg_Z(dst, src);
907 tcg_gen_xori_tl(dst, dst, 0x1);
911 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
913 gen_mov_reg_N(cpu_tmp0, src);
914 gen_mov_reg_V(dst, src);
915 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
916 gen_mov_reg_Z(cpu_tmp0, src);
917 tcg_gen_or_tl(dst, dst, cpu_tmp0);
918 tcg_gen_xori_tl(dst, dst, 0x1);
922 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
924 gen_mov_reg_V(cpu_tmp0, src);
925 gen_mov_reg_N(dst, src);
926 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
927 tcg_gen_xori_tl(dst, dst, 0x1);
931 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
933 gen_mov_reg_Z(cpu_tmp0, src);
934 gen_mov_reg_C(dst, src);
935 tcg_gen_or_tl(dst, dst, cpu_tmp0);
936 tcg_gen_xori_tl(dst, dst, 0x1);
940 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
942 gen_mov_reg_C(dst, src);
943 tcg_gen_xori_tl(dst, dst, 0x1);
947 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
949 gen_mov_reg_N(dst, src);
950 tcg_gen_xori_tl(dst, dst, 0x1);
954 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
956 gen_mov_reg_V(dst, src);
957 tcg_gen_xori_tl(dst, dst, 0x1);
961 FPSR bit field FCC1 | FCC0:
967 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
968 unsigned int fcc_offset)
970 tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
971 tcg_gen_andi_tl(reg, reg, 0x1);
974 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
975 unsigned int fcc_offset)
977 tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
978 tcg_gen_andi_tl(reg, reg, 0x1);
982 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
983 unsigned int fcc_offset)
985 gen_mov_reg_FCC0(dst, src, fcc_offset);
986 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
987 tcg_gen_or_tl(dst, dst, cpu_tmp0);
990 // 1 or 2: FCC0 ^ FCC1
991 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
992 unsigned int fcc_offset)
994 gen_mov_reg_FCC0(dst, src, fcc_offset);
995 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
996 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1000 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1001 unsigned int fcc_offset)
1003 gen_mov_reg_FCC0(dst, src, fcc_offset);
1007 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
1008 unsigned int fcc_offset)
1010 gen_mov_reg_FCC0(dst, src, fcc_offset);
1011 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1012 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1013 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1017 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1018 unsigned int fcc_offset)
1020 gen_mov_reg_FCC1(dst, src, fcc_offset);
1024 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1025 unsigned int fcc_offset)
1027 gen_mov_reg_FCC0(dst, src, fcc_offset);
1028 tcg_gen_xori_tl(dst, dst, 0x1);
1029 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1030 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1034 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1035 unsigned int fcc_offset)
1037 gen_mov_reg_FCC0(dst, src, fcc_offset);
1038 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1039 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1042 // 0: !(FCC0 | FCC1)
1043 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1044 unsigned int fcc_offset)
1046 gen_mov_reg_FCC0(dst, src, fcc_offset);
1047 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1048 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1049 tcg_gen_xori_tl(dst, dst, 0x1);
1052 // 0 or 3: !(FCC0 ^ FCC1)
1053 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1054 unsigned int fcc_offset)
1056 gen_mov_reg_FCC0(dst, src, fcc_offset);
1057 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1058 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1059 tcg_gen_xori_tl(dst, dst, 0x1);
1063 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1064 unsigned int fcc_offset)
1066 gen_mov_reg_FCC0(dst, src, fcc_offset);
1067 tcg_gen_xori_tl(dst, dst, 0x1);
1070 // !1: !(FCC0 & !FCC1)
1071 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1072 unsigned int fcc_offset)
1074 gen_mov_reg_FCC0(dst, src, fcc_offset);
1075 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1076 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1077 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1078 tcg_gen_xori_tl(dst, dst, 0x1);
1082 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1083 unsigned int fcc_offset)
1085 gen_mov_reg_FCC1(dst, src, fcc_offset);
1086 tcg_gen_xori_tl(dst, dst, 0x1);
1089 // !2: !(!FCC0 & FCC1)
1090 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1091 unsigned int fcc_offset)
1093 gen_mov_reg_FCC0(dst, src, fcc_offset);
1094 tcg_gen_xori_tl(dst, dst, 0x1);
1095 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1096 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1097 tcg_gen_xori_tl(dst, dst, 0x1);
1100 // !3: !(FCC0 & FCC1)
1101 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1102 unsigned int fcc_offset)
1104 gen_mov_reg_FCC0(dst, src, fcc_offset);
1105 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1106 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1107 tcg_gen_xori_tl(dst, dst, 0x1);
1110 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1111 target_ulong pc2, TCGv r_cond)
1115 l1 = gen_new_label();
1117 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1119 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1122 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1125 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1126 target_ulong pc2, TCGv r_cond)
1130 l1 = gen_new_label();
1132 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1134 gen_goto_tb(dc, 0, pc2, pc1);
1137 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1140 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1145 l1 = gen_new_label();
1146 l2 = gen_new_label();
1148 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1150 tcg_gen_movi_tl(cpu_npc, npc1);
1154 tcg_gen_movi_tl(cpu_npc, npc2);
1158 /* call this function before using the condition register as it may
1159 have been set for a jump */
1160 static inline void flush_cond(DisasContext *dc, TCGv cond)
1162 if (dc->npc == JUMP_PC) {
1163 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1164 dc->npc = DYNAMIC_PC;
1168 static inline void save_npc(DisasContext *dc, TCGv cond)
1170 if (dc->npc == JUMP_PC) {
1171 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1172 dc->npc = DYNAMIC_PC;
1173 } else if (dc->npc != DYNAMIC_PC) {
1174 tcg_gen_movi_tl(cpu_npc, dc->npc);
1178 static inline void save_state(DisasContext *dc, TCGv cond)
1180 tcg_gen_movi_tl(cpu_pc, dc->pc);
1184 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1186 if (dc->npc == JUMP_PC) {
1187 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1188 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1189 dc->pc = DYNAMIC_PC;
1190 } else if (dc->npc == DYNAMIC_PC) {
1191 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1192 dc->pc = DYNAMIC_PC;
1198 static inline void gen_op_next_insn(void)
1200 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1201 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1204 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1208 #ifdef TARGET_SPARC64
1218 gen_op_eval_bn(r_dst);
1221 gen_op_eval_be(r_dst, r_src);
1224 gen_op_eval_ble(r_dst, r_src);
1227 gen_op_eval_bl(r_dst, r_src);
1230 gen_op_eval_bleu(r_dst, r_src);
1233 gen_op_eval_bcs(r_dst, r_src);
1236 gen_op_eval_bneg(r_dst, r_src);
1239 gen_op_eval_bvs(r_dst, r_src);
1242 gen_op_eval_ba(r_dst);
1245 gen_op_eval_bne(r_dst, r_src);
1248 gen_op_eval_bg(r_dst, r_src);
1251 gen_op_eval_bge(r_dst, r_src);
1254 gen_op_eval_bgu(r_dst, r_src);
1257 gen_op_eval_bcc(r_dst, r_src);
1260 gen_op_eval_bpos(r_dst, r_src);
1263 gen_op_eval_bvc(r_dst, r_src);
1268 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1270 unsigned int offset;
1290 gen_op_eval_bn(r_dst);
1293 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1296 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1299 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1302 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1305 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1308 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1311 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1314 gen_op_eval_ba(r_dst);
1317 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1320 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1323 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1326 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1329 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1332 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1335 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1340 #ifdef TARGET_SPARC64
1342 static const int gen_tcg_cond_reg[8] = {
1353 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1357 l1 = gen_new_label();
1358 tcg_gen_movi_tl(r_dst, 0);
1359 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1360 tcg_gen_movi_tl(r_dst, 1);
1365 /* XXX: potentially incorrect if dynamic npc */
1366 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1369 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1370 target_ulong target = dc->pc + offset;
1373 /* unconditional not taken */
1375 dc->pc = dc->npc + 4;
1376 dc->npc = dc->pc + 4;
1379 dc->npc = dc->pc + 4;
1381 } else if (cond == 0x8) {
1382 /* unconditional taken */
1385 dc->npc = dc->pc + 4;
1391 flush_cond(dc, r_cond);
1392 gen_cond(r_cond, cc, cond);
1394 gen_branch_a(dc, target, dc->npc, r_cond);
1398 dc->jump_pc[0] = target;
1399 dc->jump_pc[1] = dc->npc + 4;
1405 /* XXX: potentially incorrect if dynamic npc */
1406 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1409 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1410 target_ulong target = dc->pc + offset;
1413 /* unconditional not taken */
1415 dc->pc = dc->npc + 4;
1416 dc->npc = dc->pc + 4;
1419 dc->npc = dc->pc + 4;
1421 } else if (cond == 0x8) {
1422 /* unconditional taken */
1425 dc->npc = dc->pc + 4;
1431 flush_cond(dc, r_cond);
1432 gen_fcond(r_cond, cc, cond);
1434 gen_branch_a(dc, target, dc->npc, r_cond);
1438 dc->jump_pc[0] = target;
1439 dc->jump_pc[1] = dc->npc + 4;
1445 #ifdef TARGET_SPARC64
1446 /* XXX: potentially incorrect if dynamic npc */
1447 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1448 TCGv r_cond, TCGv r_reg)
1450 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1451 target_ulong target = dc->pc + offset;
1453 flush_cond(dc, r_cond);
1454 gen_cond_reg(r_cond, cond, r_reg);
1456 gen_branch_a(dc, target, dc->npc, r_cond);
1460 dc->jump_pc[0] = target;
1461 dc->jump_pc[1] = dc->npc + 4;
1466 static GenOpFunc * const gen_fcmpd[4] = {
1473 static GenOpFunc * const gen_fcmpq[4] = {
1480 static GenOpFunc * const gen_fcmped[4] = {
1487 static GenOpFunc * const gen_fcmpeq[4] = {
1494 static inline void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1498 tcg_gen_helper_0_2(helper_fcmps, r_rs1, r_rs2);
1501 tcg_gen_helper_0_2(helper_fcmps_fcc1, r_rs1, r_rs2);
1504 tcg_gen_helper_0_2(helper_fcmps_fcc2, r_rs1, r_rs2);
1507 tcg_gen_helper_0_2(helper_fcmps_fcc3, r_rs1, r_rs2);
1512 static inline void gen_op_fcmpd(int fccno)
1514 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1517 static inline void gen_op_fcmpq(int fccno)
1519 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1522 static inline void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1526 tcg_gen_helper_0_2(helper_fcmpes, r_rs1, r_rs2);
1529 tcg_gen_helper_0_2(helper_fcmpes_fcc1, r_rs1, r_rs2);
1532 tcg_gen_helper_0_2(helper_fcmpes_fcc2, r_rs1, r_rs2);
1535 tcg_gen_helper_0_2(helper_fcmpes_fcc3, r_rs1, r_rs2);
1540 static inline void gen_op_fcmped(int fccno)
1542 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1545 static inline void gen_op_fcmpeq(int fccno)
1547 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1552 static inline void gen_op_fcmps(int fccno, TCGv r_rs1, TCGv r_rs2)
1554 tcg_gen_helper_0_2(helper_fcmps, r_rs1, r_rs2);
1557 static inline void gen_op_fcmpd(int fccno)
1559 tcg_gen_helper_0_0(helper_fcmpd);
1562 static inline void gen_op_fcmpq(int fccno)
1564 tcg_gen_helper_0_0(helper_fcmpq);
1567 static inline void gen_op_fcmpes(int fccno, TCGv r_rs1, TCGv r_rs2)
1569 tcg_gen_helper_0_2(helper_fcmpes, r_rs1, r_rs2);
1572 static inline void gen_op_fcmped(int fccno)
1574 tcg_gen_helper_0_0(helper_fcmped);
1577 static inline void gen_op_fcmpeq(int fccno)
1579 tcg_gen_helper_0_0(helper_fcmpeq);
1583 static inline void gen_op_fpexception_im(int fsr_flags)
1587 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
1588 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1589 r_const = tcg_const_i32(TT_FP_EXCP);
1590 tcg_gen_helper_0_1(raise_exception, r_const);
1591 tcg_temp_free(r_const);
1594 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1596 #if !defined(CONFIG_USER_ONLY)
1597 if (!dc->fpu_enabled) {
1600 save_state(dc, r_cond);
1601 r_const = tcg_const_i32(TT_NFPU_INSN);
1602 tcg_gen_helper_0_1(raise_exception, r_const);
1603 tcg_temp_free(r_const);
1611 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1613 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1616 static inline void gen_clear_float_exceptions(void)
1618 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1622 #ifdef TARGET_SPARC64
1623 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1629 r_asi = tcg_temp_new(TCG_TYPE_I32);
1630 tcg_gen_mov_i32(r_asi, cpu_asi);
1632 asi = GET_FIELD(insn, 19, 26);
1633 r_asi = tcg_const_i32(asi);
1638 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1641 TCGv r_asi, r_size, r_sign;
1643 r_asi = gen_get_asi(insn, addr);
1644 r_size = tcg_const_i32(size);
1645 r_sign = tcg_const_i32(sign);
1646 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi, r_size, r_sign);
1647 tcg_temp_free(r_sign);
1648 tcg_temp_free(r_size);
1649 tcg_temp_free(r_asi);
1652 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1656 r_asi = gen_get_asi(insn, addr);
1657 r_size = tcg_const_i32(size);
1658 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, r_size);
1659 tcg_temp_free(r_size);
1660 tcg_temp_free(r_asi);
1663 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1665 TCGv r_asi, r_size, r_rd;
1667 r_asi = gen_get_asi(insn, addr);
1668 r_size = tcg_const_i32(size);
1669 r_rd = tcg_const_i32(rd);
1670 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, r_size, r_rd);
1671 tcg_temp_free(r_rd);
1672 tcg_temp_free(r_size);
1673 tcg_temp_free(r_asi);
1676 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1678 TCGv r_asi, r_size, r_rd;
1680 r_asi = gen_get_asi(insn, addr);
1681 r_size = tcg_const_i32(size);
1682 r_rd = tcg_const_i32(rd);
1683 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, r_size, r_rd);
1684 tcg_temp_free(r_rd);
1685 tcg_temp_free(r_size);
1686 tcg_temp_free(r_asi);
1689 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1691 TCGv r_asi, r_size, r_sign;
1693 r_asi = gen_get_asi(insn, addr);
1694 r_size = tcg_const_i32(4);
1695 r_sign = tcg_const_i32(0);
1696 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1697 tcg_temp_free(r_sign);
1698 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1699 tcg_temp_free(r_size);
1700 tcg_temp_free(r_asi);
1701 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1704 static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
1708 r_asi = gen_get_asi(insn, addr);
1709 r_rd = tcg_const_i32(rd);
1710 tcg_gen_helper_0_3(helper_ldda_asi, addr, r_asi, r_rd);
1711 tcg_temp_free(r_rd);
1712 tcg_temp_free(r_asi);
1715 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1717 TCGv r_temp, r_asi, r_size;
1719 r_temp = tcg_temp_new(TCG_TYPE_TL);
1720 gen_movl_reg_TN(rd + 1, r_temp);
1721 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1723 tcg_temp_free(r_temp);
1724 r_asi = gen_get_asi(insn, addr);
1725 r_size = tcg_const_i32(8);
1726 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1727 tcg_temp_free(r_size);
1728 tcg_temp_free(r_asi);
1731 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1736 r_val1 = tcg_temp_new(TCG_TYPE_TL);
1737 gen_movl_reg_TN(rd, r_val1);
1738 r_asi = gen_get_asi(insn, addr);
1739 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1740 tcg_temp_free(r_asi);
1741 tcg_temp_free(r_val1);
1744 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1749 gen_movl_reg_TN(rd, cpu_tmp64);
1750 r_asi = gen_get_asi(insn, addr);
1751 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1752 tcg_temp_free(r_asi);
1755 #elif !defined(CONFIG_USER_ONLY)
1757 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1760 TCGv r_asi, r_size, r_sign;
1762 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1763 r_size = tcg_const_i32(size);
1764 r_sign = tcg_const_i32(sign);
1765 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1766 tcg_temp_free(r_sign);
1767 tcg_temp_free(r_size);
1768 tcg_temp_free(r_asi);
1769 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1772 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1776 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1777 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1778 r_size = tcg_const_i32(size);
1779 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1780 tcg_temp_free(r_size);
1781 tcg_temp_free(r_asi);
1784 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1786 TCGv r_asi, r_size, r_sign;
1788 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1789 r_size = tcg_const_i32(4);
1790 r_sign = tcg_const_i32(0);
1791 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1792 tcg_temp_free(r_sign);
1793 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1794 tcg_temp_free(r_size);
1795 tcg_temp_free(r_asi);
1796 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1799 static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
1801 TCGv r_asi, r_size, r_sign;
1803 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1804 r_size = tcg_const_i32(8);
1805 r_sign = tcg_const_i32(0);
1806 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1807 tcg_temp_free(r_sign);
1808 tcg_temp_free(r_size);
1809 tcg_temp_free(r_asi);
1810 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
1811 gen_movl_TN_reg(rd + 1, cpu_tmp0);
1812 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1813 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1814 gen_movl_TN_reg(rd, hi);
1817 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1819 TCGv r_temp, r_asi, r_size;
1821 r_temp = tcg_temp_new(TCG_TYPE_TL);
1822 gen_movl_reg_TN(rd + 1, r_temp);
1823 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1824 tcg_temp_free(r_temp);
1825 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1826 r_size = tcg_const_i32(8);
1827 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1828 tcg_temp_free(r_size);
1829 tcg_temp_free(r_asi);
1833 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1834 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1836 TCGv r_val, r_asi, r_size;
1838 gen_ld_asi(dst, addr, insn, 1, 0);
1840 r_val = tcg_const_i64(0xffULL);
1841 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1842 r_size = tcg_const_i32(1);
1843 tcg_gen_helper_0_4(helper_st_asi, addr, r_val, r_asi, r_size);
1844 tcg_temp_free(r_size);
1845 tcg_temp_free(r_asi);
1846 tcg_temp_free(r_val);
1850 static inline TCGv get_src1(unsigned int insn, TCGv def)
1855 rs1 = GET_FIELD(insn, 13, 17);
1857 r_rs1 = tcg_const_tl(0); // XXX how to free?
1859 r_rs1 = cpu_gregs[rs1];
1861 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1865 static inline TCGv get_src2(unsigned int insn, TCGv def)
1870 if (IS_IMM) { /* immediate */
1871 rs2 = GET_FIELDs(insn, 19, 31);
1872 r_rs2 = tcg_const_tl((int)rs2); // XXX how to free?
1873 } else { /* register */
1874 rs2 = GET_FIELD(insn, 27, 31);
1876 r_rs2 = tcg_const_tl(0); // XXX how to free?
1878 r_rs2 = cpu_gregs[rs2];
1880 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1885 #define CHECK_IU_FEATURE(dc, FEATURE) \
1886 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
1888 #define CHECK_FPU_FEATURE(dc, FEATURE) \
1889 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
1892 /* before an instruction, dc->pc must be static */
1893 static void disas_sparc_insn(DisasContext * dc)
1895 unsigned int insn, opc, rs1, rs2, rd;
1897 if (unlikely(loglevel & CPU_LOG_TB_OP))
1898 tcg_gen_debug_insn_start(dc->pc);
1899 insn = ldl_code(dc->pc);
1900 opc = GET_FIELD(insn, 0, 1);
1902 rd = GET_FIELD(insn, 2, 6);
1904 cpu_src1 = tcg_temp_new(TCG_TYPE_TL); // const
1905 cpu_src2 = tcg_temp_new(TCG_TYPE_TL); // const
1908 case 0: /* branches/sethi */
1910 unsigned int xop = GET_FIELD(insn, 7, 9);
1913 #ifdef TARGET_SPARC64
1914 case 0x1: /* V9 BPcc */
1918 target = GET_FIELD_SP(insn, 0, 18);
1919 target = sign_extend(target, 18);
1921 cc = GET_FIELD_SP(insn, 20, 21);
1923 do_branch(dc, target, insn, 0, cpu_cond);
1925 do_branch(dc, target, insn, 1, cpu_cond);
1930 case 0x3: /* V9 BPr */
1932 target = GET_FIELD_SP(insn, 0, 13) |
1933 (GET_FIELD_SP(insn, 20, 21) << 14);
1934 target = sign_extend(target, 16);
1936 cpu_src1 = get_src1(insn, cpu_src1);
1937 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1940 case 0x5: /* V9 FBPcc */
1942 int cc = GET_FIELD_SP(insn, 20, 21);
1943 if (gen_trap_ifnofpu(dc, cpu_cond))
1945 target = GET_FIELD_SP(insn, 0, 18);
1946 target = sign_extend(target, 19);
1948 do_fbranch(dc, target, insn, cc, cpu_cond);
1952 case 0x7: /* CBN+x */
1957 case 0x2: /* BN+x */
1959 target = GET_FIELD(insn, 10, 31);
1960 target = sign_extend(target, 22);
1962 do_branch(dc, target, insn, 0, cpu_cond);
1965 case 0x6: /* FBN+x */
1967 if (gen_trap_ifnofpu(dc, cpu_cond))
1969 target = GET_FIELD(insn, 10, 31);
1970 target = sign_extend(target, 22);
1972 do_fbranch(dc, target, insn, 0, cpu_cond);
1975 case 0x4: /* SETHI */
1977 uint32_t value = GET_FIELD(insn, 10, 31);
1980 r_const = tcg_const_tl(value << 10);
1981 gen_movl_TN_reg(rd, r_const);
1982 tcg_temp_free(r_const);
1985 case 0x0: /* UNIMPL */
1994 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1997 r_const = tcg_const_tl(dc->pc);
1998 gen_movl_TN_reg(15, r_const);
1999 tcg_temp_free(r_const);
2001 gen_mov_pc_npc(dc, cpu_cond);
2005 case 2: /* FPU & Logical Operations */
2007 unsigned int xop = GET_FIELD(insn, 7, 12);
2008 if (xop == 0x3a) { /* generate trap */
2011 cpu_src1 = get_src1(insn, cpu_src1);
2013 rs2 = GET_FIELD(insn, 25, 31);
2014 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
2016 rs2 = GET_FIELD(insn, 27, 31);
2018 gen_movl_reg_TN(rs2, cpu_src2);
2019 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2021 tcg_gen_mov_tl(cpu_dst, cpu_src1);
2023 cond = GET_FIELD(insn, 3, 6);
2025 save_state(dc, cpu_cond);
2026 tcg_gen_helper_0_1(helper_trap, cpu_dst);
2027 } else if (cond != 0) {
2028 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
2029 #ifdef TARGET_SPARC64
2031 int cc = GET_FIELD_SP(insn, 11, 12);
2033 save_state(dc, cpu_cond);
2035 gen_cond(r_cond, 0, cond);
2037 gen_cond(r_cond, 1, cond);
2041 save_state(dc, cpu_cond);
2042 gen_cond(r_cond, 0, cond);
2044 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
2045 tcg_temp_free(r_cond);
2051 } else if (xop == 0x28) {
2052 rs1 = GET_FIELD(insn, 13, 17);
2055 #ifndef TARGET_SPARC64
2056 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2057 manual, rdy on the microSPARC
2059 case 0x0f: /* stbar in the SPARCv8 manual,
2060 rdy on the microSPARC II */
2061 case 0x10 ... 0x1f: /* implementation-dependent in the
2062 SPARCv8 manual, rdy on the
2065 gen_movl_TN_reg(rd, cpu_y);
2067 #ifdef TARGET_SPARC64
2068 case 0x2: /* V9 rdccr */
2069 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2070 gen_movl_TN_reg(rd, cpu_dst);
2072 case 0x3: /* V9 rdasi */
2073 tcg_gen_ext_i32_tl(cpu_dst, cpu_asi);
2074 gen_movl_TN_reg(rd, cpu_dst);
2076 case 0x4: /* V9 rdtick */
2080 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2081 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2082 offsetof(CPUState, tick));
2083 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2085 tcg_temp_free(r_tickptr);
2086 gen_movl_TN_reg(rd, cpu_dst);
2089 case 0x5: /* V9 rdpc */
2093 r_const = tcg_const_tl(dc->pc);
2094 gen_movl_TN_reg(rd, r_const);
2095 tcg_temp_free(r_const);
2098 case 0x6: /* V9 rdfprs */
2099 tcg_gen_ext_i32_tl(cpu_dst, cpu_fprs);
2100 gen_movl_TN_reg(rd, cpu_dst);
2102 case 0xf: /* V9 membar */
2103 break; /* no effect */
2104 case 0x13: /* Graphics Status */
2105 if (gen_trap_ifnofpu(dc, cpu_cond))
2107 gen_movl_TN_reg(rd, cpu_gsr);
2109 case 0x17: /* Tick compare */
2110 gen_movl_TN_reg(rd, cpu_tick_cmpr);
2112 case 0x18: /* System tick */
2116 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2117 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2118 offsetof(CPUState, stick));
2119 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2121 tcg_temp_free(r_tickptr);
2122 gen_movl_TN_reg(rd, cpu_dst);
2125 case 0x19: /* System tick compare */
2126 gen_movl_TN_reg(rd, cpu_stick_cmpr);
2128 case 0x10: /* Performance Control */
2129 case 0x11: /* Performance Instrumentation Counter */
2130 case 0x12: /* Dispatch Control */
2131 case 0x14: /* Softint set, WO */
2132 case 0x15: /* Softint clear, WO */
2133 case 0x16: /* Softint write */
2138 #if !defined(CONFIG_USER_ONLY)
2139 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2140 #ifndef TARGET_SPARC64
2141 if (!supervisor(dc))
2143 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2145 CHECK_IU_FEATURE(dc, HYPV);
2146 if (!hypervisor(dc))
2148 rs1 = GET_FIELD(insn, 13, 17);
2151 // gen_op_rdhpstate();
2154 // gen_op_rdhtstate();
2157 tcg_gen_mov_tl(cpu_dst, cpu_hintp);
2160 tcg_gen_mov_tl(cpu_dst, cpu_htba);
2163 tcg_gen_mov_tl(cpu_dst, cpu_hver);
2165 case 31: // hstick_cmpr
2166 tcg_gen_mov_tl(cpu_dst, cpu_hstick_cmpr);
2172 gen_movl_TN_reg(rd, cpu_dst);
2174 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2175 if (!supervisor(dc))
2177 #ifdef TARGET_SPARC64
2178 rs1 = GET_FIELD(insn, 13, 17);
2184 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2185 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2186 offsetof(CPUState, tsptr));
2187 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2188 offsetof(trap_state, tpc));
2189 tcg_temp_free(r_tsptr);
2196 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2197 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2198 offsetof(CPUState, tsptr));
2199 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2200 offsetof(trap_state, tnpc));
2201 tcg_temp_free(r_tsptr);
2208 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2209 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2210 offsetof(CPUState, tsptr));
2211 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2212 offsetof(trap_state, tstate));
2213 tcg_temp_free(r_tsptr);
2220 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2221 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2222 offsetof(CPUState, tsptr));
2223 tcg_gen_ld_i32(cpu_tmp0, r_tsptr,
2224 offsetof(trap_state, tt));
2225 tcg_temp_free(r_tsptr);
2232 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2233 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2234 offsetof(CPUState, tick));
2235 tcg_gen_helper_1_1(helper_tick_get_count, cpu_tmp0,
2237 gen_movl_TN_reg(rd, cpu_tmp0);
2238 tcg_temp_free(r_tickptr);
2242 tcg_gen_mov_tl(cpu_tmp0, cpu_tbr);
2245 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2246 offsetof(CPUSPARCState, pstate));
2247 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2250 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2251 offsetof(CPUSPARCState, tl));
2252 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2255 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2256 offsetof(CPUSPARCState, psrpil));
2257 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2260 tcg_gen_helper_1_0(helper_rdcwp, cpu_tmp0);
2263 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2264 offsetof(CPUSPARCState, cansave));
2265 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2267 case 11: // canrestore
2268 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2269 offsetof(CPUSPARCState, canrestore));
2270 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2272 case 12: // cleanwin
2273 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2274 offsetof(CPUSPARCState, cleanwin));
2275 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2277 case 13: // otherwin
2278 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2279 offsetof(CPUSPARCState, otherwin));
2280 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2283 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2284 offsetof(CPUSPARCState, wstate));
2285 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2287 case 16: // UA2005 gl
2288 CHECK_IU_FEATURE(dc, GL);
2289 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2290 offsetof(CPUSPARCState, gl));
2291 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2293 case 26: // UA2005 strand status
2294 CHECK_IU_FEATURE(dc, HYPV);
2295 if (!hypervisor(dc))
2297 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_ssr);
2300 tcg_gen_mov_tl(cpu_tmp0, cpu_ver);
2307 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_wim);
2309 gen_movl_TN_reg(rd, cpu_tmp0);
2311 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2312 #ifdef TARGET_SPARC64
2313 save_state(dc, cpu_cond);
2314 tcg_gen_helper_0_0(helper_flushw);
2316 if (!supervisor(dc))
2318 gen_movl_TN_reg(rd, cpu_tbr);
2322 } else if (xop == 0x34) { /* FPU Operations */
2323 if (gen_trap_ifnofpu(dc, cpu_cond))
2325 gen_op_clear_ieee_excp_and_FTT();
2326 rs1 = GET_FIELD(insn, 13, 17);
2327 rs2 = GET_FIELD(insn, 27, 31);
2328 xop = GET_FIELD(insn, 18, 26);
2330 case 0x1: /* fmovs */
2331 tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
2333 case 0x5: /* fnegs */
2334 tcg_gen_helper_1_1(helper_fnegs, cpu_fpr[rd],
2337 case 0x9: /* fabss */
2338 tcg_gen_helper_1_1(helper_fabss, cpu_fpr[rd],
2341 case 0x29: /* fsqrts */
2342 CHECK_FPU_FEATURE(dc, FSQRT);
2343 gen_clear_float_exceptions();
2344 tcg_gen_helper_1_1(helper_fsqrts, cpu_tmp32,
2346 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2347 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2349 case 0x2a: /* fsqrtd */
2350 CHECK_FPU_FEATURE(dc, FSQRT);
2351 gen_op_load_fpr_DT1(DFPREG(rs2));
2352 gen_clear_float_exceptions();
2353 tcg_gen_helper_0_0(helper_fsqrtd);
2354 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2355 gen_op_store_DT0_fpr(DFPREG(rd));
2357 case 0x2b: /* fsqrtq */
2358 CHECK_FPU_FEATURE(dc, FLOAT128);
2359 gen_op_load_fpr_QT1(QFPREG(rs2));
2360 gen_clear_float_exceptions();
2361 tcg_gen_helper_0_0(helper_fsqrtq);
2362 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2363 gen_op_store_QT0_fpr(QFPREG(rd));
2365 case 0x41: /* fadds */
2366 gen_clear_float_exceptions();
2367 tcg_gen_helper_1_2(helper_fadds, cpu_tmp32,
2368 cpu_fpr[rs1], cpu_fpr[rs2]);
2369 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2370 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2373 gen_op_load_fpr_DT0(DFPREG(rs1));
2374 gen_op_load_fpr_DT1(DFPREG(rs2));
2375 gen_clear_float_exceptions();
2376 tcg_gen_helper_0_0(helper_faddd);
2377 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2378 gen_op_store_DT0_fpr(DFPREG(rd));
2380 case 0x43: /* faddq */
2381 CHECK_FPU_FEATURE(dc, FLOAT128);
2382 gen_op_load_fpr_QT0(QFPREG(rs1));
2383 gen_op_load_fpr_QT1(QFPREG(rs2));
2384 gen_clear_float_exceptions();
2385 tcg_gen_helper_0_0(helper_faddq);
2386 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2387 gen_op_store_QT0_fpr(QFPREG(rd));
2389 case 0x45: /* fsubs */
2390 gen_clear_float_exceptions();
2391 tcg_gen_helper_1_2(helper_fsubs, cpu_tmp32,
2392 cpu_fpr[rs1], cpu_fpr[rs2]);
2393 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2394 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2397 gen_op_load_fpr_DT0(DFPREG(rs1));
2398 gen_op_load_fpr_DT1(DFPREG(rs2));
2399 gen_clear_float_exceptions();
2400 tcg_gen_helper_0_0(helper_fsubd);
2401 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2402 gen_op_store_DT0_fpr(DFPREG(rd));
2404 case 0x47: /* fsubq */
2405 CHECK_FPU_FEATURE(dc, FLOAT128);
2406 gen_op_load_fpr_QT0(QFPREG(rs1));
2407 gen_op_load_fpr_QT1(QFPREG(rs2));
2408 gen_clear_float_exceptions();
2409 tcg_gen_helper_0_0(helper_fsubq);
2410 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2411 gen_op_store_QT0_fpr(QFPREG(rd));
2413 case 0x49: /* fmuls */
2414 CHECK_FPU_FEATURE(dc, FMUL);
2415 gen_clear_float_exceptions();
2416 tcg_gen_helper_1_2(helper_fmuls, cpu_tmp32,
2417 cpu_fpr[rs1], cpu_fpr[rs2]);
2418 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2419 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2421 case 0x4a: /* fmuld */
2422 CHECK_FPU_FEATURE(dc, FMUL);
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_fmuld);
2427 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2428 gen_op_store_DT0_fpr(DFPREG(rd));
2430 case 0x4b: /* fmulq */
2431 CHECK_FPU_FEATURE(dc, FLOAT128);
2432 CHECK_FPU_FEATURE(dc, FMUL);
2433 gen_op_load_fpr_QT0(QFPREG(rs1));
2434 gen_op_load_fpr_QT1(QFPREG(rs2));
2435 gen_clear_float_exceptions();
2436 tcg_gen_helper_0_0(helper_fmulq);
2437 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2438 gen_op_store_QT0_fpr(QFPREG(rd));
2440 case 0x4d: /* fdivs */
2441 gen_clear_float_exceptions();
2442 tcg_gen_helper_1_2(helper_fdivs, cpu_tmp32,
2443 cpu_fpr[rs1], cpu_fpr[rs2]);
2444 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2445 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
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_fdivd);
2452 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2453 gen_op_store_DT0_fpr(DFPREG(rd));
2455 case 0x4f: /* fdivq */
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_fdivq);
2461 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2462 gen_op_store_QT0_fpr(QFPREG(rd));
2464 case 0x69: /* fsmuld */
2465 CHECK_FPU_FEATURE(dc, FSMULD);
2466 gen_clear_float_exceptions();
2467 tcg_gen_helper_0_2(helper_fsmuld, cpu_fpr[rs1],
2469 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2470 gen_op_store_DT0_fpr(DFPREG(rd));
2472 case 0x6e: /* fdmulq */
2473 CHECK_FPU_FEATURE(dc, FLOAT128);
2474 gen_op_load_fpr_DT0(DFPREG(rs1));
2475 gen_op_load_fpr_DT1(DFPREG(rs2));
2476 gen_clear_float_exceptions();
2477 tcg_gen_helper_0_0(helper_fdmulq);
2478 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2479 gen_op_store_QT0_fpr(QFPREG(rd));
2481 case 0xc4: /* fitos */
2482 gen_clear_float_exceptions();
2483 tcg_gen_helper_1_1(helper_fitos, cpu_tmp32,
2485 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2486 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2488 case 0xc6: /* fdtos */
2489 gen_op_load_fpr_DT1(DFPREG(rs2));
2490 gen_clear_float_exceptions();
2491 tcg_gen_helper_1_0(helper_fdtos, cpu_tmp32);
2492 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2493 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2495 case 0xc7: /* fqtos */
2496 CHECK_FPU_FEATURE(dc, FLOAT128);
2497 gen_op_load_fpr_QT1(QFPREG(rs2));
2498 gen_clear_float_exceptions();
2499 tcg_gen_helper_1_0(helper_fqtos, cpu_tmp32);
2500 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2501 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2503 case 0xc8: /* fitod */
2504 tcg_gen_helper_0_1(helper_fitod, cpu_fpr[rs2]);
2505 gen_op_store_DT0_fpr(DFPREG(rd));
2507 case 0xc9: /* fstod */
2508 tcg_gen_helper_0_1(helper_fstod, cpu_fpr[rs2]);
2509 gen_op_store_DT0_fpr(DFPREG(rd));
2511 case 0xcb: /* fqtod */
2512 CHECK_FPU_FEATURE(dc, FLOAT128);
2513 gen_op_load_fpr_QT1(QFPREG(rs2));
2514 gen_clear_float_exceptions();
2515 tcg_gen_helper_0_0(helper_fqtod);
2516 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2517 gen_op_store_DT0_fpr(DFPREG(rd));
2519 case 0xcc: /* fitoq */
2520 CHECK_FPU_FEATURE(dc, FLOAT128);
2521 tcg_gen_helper_0_1(helper_fitoq, cpu_fpr[rs2]);
2522 gen_op_store_QT0_fpr(QFPREG(rd));
2524 case 0xcd: /* fstoq */
2525 CHECK_FPU_FEATURE(dc, FLOAT128);
2526 tcg_gen_helper_0_1(helper_fstoq, cpu_fpr[rs2]);
2527 gen_op_store_QT0_fpr(QFPREG(rd));
2529 case 0xce: /* fdtoq */
2530 CHECK_FPU_FEATURE(dc, FLOAT128);
2531 gen_op_load_fpr_DT1(DFPREG(rs2));
2532 tcg_gen_helper_0_0(helper_fdtoq);
2533 gen_op_store_QT0_fpr(QFPREG(rd));
2535 case 0xd1: /* fstoi */
2536 gen_clear_float_exceptions();
2537 tcg_gen_helper_1_1(helper_fstoi, cpu_tmp32,
2539 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2540 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2542 case 0xd2: /* fdtoi */
2543 gen_op_load_fpr_DT1(DFPREG(rs2));
2544 gen_clear_float_exceptions();
2545 tcg_gen_helper_1_0(helper_fdtoi, cpu_tmp32);
2546 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2547 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2549 case 0xd3: /* fqtoi */
2550 CHECK_FPU_FEATURE(dc, FLOAT128);
2551 gen_op_load_fpr_QT1(QFPREG(rs2));
2552 gen_clear_float_exceptions();
2553 tcg_gen_helper_1_0(helper_fqtoi, cpu_tmp32);
2554 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2555 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2557 #ifdef TARGET_SPARC64
2558 case 0x2: /* V9 fmovd */
2559 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)],
2560 cpu_fpr[DFPREG(rs2)]);
2561 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1],
2562 cpu_fpr[DFPREG(rs2) + 1]);
2564 case 0x3: /* V9 fmovq */
2565 CHECK_FPU_FEATURE(dc, FLOAT128);
2566 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)],
2567 cpu_fpr[QFPREG(rs2)]);
2568 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1],
2569 cpu_fpr[QFPREG(rs2) + 1]);
2570 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2],
2571 cpu_fpr[QFPREG(rs2) + 2]);
2572 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3],
2573 cpu_fpr[QFPREG(rs2) + 3]);
2575 case 0x6: /* V9 fnegd */
2576 gen_op_load_fpr_DT1(DFPREG(rs2));
2577 tcg_gen_helper_0_0(helper_fnegd);
2578 gen_op_store_DT0_fpr(DFPREG(rd));
2580 case 0x7: /* V9 fnegq */
2581 CHECK_FPU_FEATURE(dc, FLOAT128);
2582 gen_op_load_fpr_QT1(QFPREG(rs2));
2583 tcg_gen_helper_0_0(helper_fnegq);
2584 gen_op_store_QT0_fpr(QFPREG(rd));
2586 case 0xa: /* V9 fabsd */
2587 gen_op_load_fpr_DT1(DFPREG(rs2));
2588 tcg_gen_helper_0_0(helper_fabsd);
2589 gen_op_store_DT0_fpr(DFPREG(rd));
2591 case 0xb: /* V9 fabsq */
2592 CHECK_FPU_FEATURE(dc, FLOAT128);
2593 gen_op_load_fpr_QT1(QFPREG(rs2));
2594 tcg_gen_helper_0_0(helper_fabsq);
2595 gen_op_store_QT0_fpr(QFPREG(rd));
2597 case 0x81: /* V9 fstox */
2598 gen_clear_float_exceptions();
2599 tcg_gen_helper_0_1(helper_fstox, cpu_fpr[rs2]);
2600 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2601 gen_op_store_DT0_fpr(DFPREG(rd));
2603 case 0x82: /* V9 fdtox */
2604 gen_op_load_fpr_DT1(DFPREG(rs2));
2605 gen_clear_float_exceptions();
2606 tcg_gen_helper_0_0(helper_fdtox);
2607 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2608 gen_op_store_DT0_fpr(DFPREG(rd));
2610 case 0x83: /* V9 fqtox */
2611 CHECK_FPU_FEATURE(dc, FLOAT128);
2612 gen_op_load_fpr_QT1(QFPREG(rs2));
2613 gen_clear_float_exceptions();
2614 tcg_gen_helper_0_0(helper_fqtox);
2615 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2616 gen_op_store_DT0_fpr(DFPREG(rd));
2618 case 0x84: /* V9 fxtos */
2619 gen_op_load_fpr_DT1(DFPREG(rs2));
2620 gen_clear_float_exceptions();
2621 tcg_gen_helper_1_0(helper_fxtos, cpu_tmp32);
2622 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2623 tcg_gen_mov_i32(cpu_fpr[rd], cpu_tmp32);
2625 case 0x88: /* V9 fxtod */
2626 gen_op_load_fpr_DT1(DFPREG(rs2));
2627 gen_clear_float_exceptions();
2628 tcg_gen_helper_0_0(helper_fxtod);
2629 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2630 gen_op_store_DT0_fpr(DFPREG(rd));
2632 case 0x8c: /* V9 fxtoq */
2633 CHECK_FPU_FEATURE(dc, FLOAT128);
2634 gen_op_load_fpr_DT1(DFPREG(rs2));
2635 gen_clear_float_exceptions();
2636 tcg_gen_helper_0_0(helper_fxtoq);
2637 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2638 gen_op_store_QT0_fpr(QFPREG(rd));
2644 } else if (xop == 0x35) { /* FPU Operations */
2645 #ifdef TARGET_SPARC64
2648 if (gen_trap_ifnofpu(dc, cpu_cond))
2650 gen_op_clear_ieee_excp_and_FTT();
2651 rs1 = GET_FIELD(insn, 13, 17);
2652 rs2 = GET_FIELD(insn, 27, 31);
2653 xop = GET_FIELD(insn, 18, 26);
2654 #ifdef TARGET_SPARC64
2655 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2658 l1 = gen_new_label();
2659 cond = GET_FIELD_SP(insn, 14, 17);
2660 cpu_src1 = get_src1(insn, cpu_src1);
2661 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2663 tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
2666 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2669 l1 = gen_new_label();
2670 cond = GET_FIELD_SP(insn, 14, 17);
2671 cpu_src1 = get_src1(insn, cpu_src1);
2672 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2674 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs2)]);
2675 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1], cpu_fpr[DFPREG(rs2) + 1]);
2678 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2681 CHECK_FPU_FEATURE(dc, FLOAT128);
2682 l1 = gen_new_label();
2683 cond = GET_FIELD_SP(insn, 14, 17);
2684 cpu_src1 = get_src1(insn, cpu_src1);
2685 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2687 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)], cpu_fpr[QFPREG(rs2)]);
2688 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1], cpu_fpr[QFPREG(rs2) + 1]);
2689 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2], cpu_fpr[QFPREG(rs2) + 2]);
2690 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3], cpu_fpr[QFPREG(rs2) + 3]);
2696 #ifdef TARGET_SPARC64
2697 #define FMOVSCC(fcc) \
2702 l1 = gen_new_label(); \
2703 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2704 cond = GET_FIELD_SP(insn, 14, 17); \
2705 gen_fcond(r_cond, fcc, cond); \
2706 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2708 tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]); \
2709 gen_set_label(l1); \
2710 tcg_temp_free(r_cond); \
2712 #define FMOVDCC(fcc) \
2717 l1 = gen_new_label(); \
2718 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2719 cond = GET_FIELD_SP(insn, 14, 17); \
2720 gen_fcond(r_cond, fcc, cond); \
2721 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2723 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)], \
2724 cpu_fpr[DFPREG(rs2)]); \
2725 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1], \
2726 cpu_fpr[DFPREG(rs2) + 1]); \
2727 gen_set_label(l1); \
2728 tcg_temp_free(r_cond); \
2730 #define FMOVQCC(fcc) \
2735 l1 = gen_new_label(); \
2736 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2737 cond = GET_FIELD_SP(insn, 14, 17); \
2738 gen_fcond(r_cond, fcc, cond); \
2739 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2741 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)], \
2742 cpu_fpr[QFPREG(rs2)]); \
2743 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1], \
2744 cpu_fpr[QFPREG(rs2) + 1]); \
2745 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2], \
2746 cpu_fpr[QFPREG(rs2) + 2]); \
2747 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3], \
2748 cpu_fpr[QFPREG(rs2) + 3]); \
2749 gen_set_label(l1); \
2750 tcg_temp_free(r_cond); \
2752 case 0x001: /* V9 fmovscc %fcc0 */
2755 case 0x002: /* V9 fmovdcc %fcc0 */
2758 case 0x003: /* V9 fmovqcc %fcc0 */
2759 CHECK_FPU_FEATURE(dc, FLOAT128);
2762 case 0x041: /* V9 fmovscc %fcc1 */
2765 case 0x042: /* V9 fmovdcc %fcc1 */
2768 case 0x043: /* V9 fmovqcc %fcc1 */
2769 CHECK_FPU_FEATURE(dc, FLOAT128);
2772 case 0x081: /* V9 fmovscc %fcc2 */
2775 case 0x082: /* V9 fmovdcc %fcc2 */
2778 case 0x083: /* V9 fmovqcc %fcc2 */
2779 CHECK_FPU_FEATURE(dc, FLOAT128);
2782 case 0x0c1: /* V9 fmovscc %fcc3 */
2785 case 0x0c2: /* V9 fmovdcc %fcc3 */
2788 case 0x0c3: /* V9 fmovqcc %fcc3 */
2789 CHECK_FPU_FEATURE(dc, FLOAT128);
2795 #define FMOVCC(size_FDQ, icc) \
2800 l1 = gen_new_label(); \
2801 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2802 cond = GET_FIELD_SP(insn, 14, 17); \
2803 gen_cond(r_cond, icc, cond); \
2804 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2806 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2807 (glue(size_FDQ, FPREG(rs2))); \
2808 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2809 (glue(size_FDQ, FPREG(rd))); \
2810 gen_set_label(l1); \
2811 tcg_temp_free(r_cond); \
2813 #define FMOVSCC(icc) \
2818 l1 = gen_new_label(); \
2819 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2820 cond = GET_FIELD_SP(insn, 14, 17); \
2821 gen_cond(r_cond, icc, cond); \
2822 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2824 tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]); \
2825 gen_set_label(l1); \
2826 tcg_temp_free(r_cond); \
2828 #define FMOVDCC(icc) \
2833 l1 = gen_new_label(); \
2834 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2835 cond = GET_FIELD_SP(insn, 14, 17); \
2836 gen_cond(r_cond, icc, cond); \
2837 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2839 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)], \
2840 cpu_fpr[DFPREG(rs2)]); \
2841 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1], \
2842 cpu_fpr[DFPREG(rs2) + 1]); \
2843 gen_set_label(l1); \
2844 tcg_temp_free(r_cond); \
2846 #define FMOVQCC(icc) \
2851 l1 = gen_new_label(); \
2852 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2853 cond = GET_FIELD_SP(insn, 14, 17); \
2854 gen_cond(r_cond, icc, cond); \
2855 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2857 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd)], \
2858 cpu_fpr[QFPREG(rs2)]); \
2859 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 1], \
2860 cpu_fpr[QFPREG(rs2) + 1]); \
2861 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 2], \
2862 cpu_fpr[QFPREG(rs2) + 2]); \
2863 tcg_gen_mov_i32(cpu_fpr[QFPREG(rd) + 3], \
2864 cpu_fpr[QFPREG(rs2) + 3]); \
2865 gen_set_label(l1); \
2866 tcg_temp_free(r_cond); \
2869 case 0x101: /* V9 fmovscc %icc */
2872 case 0x102: /* V9 fmovdcc %icc */
2874 case 0x103: /* V9 fmovqcc %icc */
2875 CHECK_FPU_FEATURE(dc, FLOAT128);
2878 case 0x181: /* V9 fmovscc %xcc */
2881 case 0x182: /* V9 fmovdcc %xcc */
2884 case 0x183: /* V9 fmovqcc %xcc */
2885 CHECK_FPU_FEATURE(dc, FLOAT128);
2892 case 0x51: /* fcmps, V9 %fcc */
2893 gen_op_fcmps(rd & 3, cpu_fpr[rs1], cpu_fpr[rs2]);
2895 case 0x52: /* fcmpd, V9 %fcc */
2896 gen_op_load_fpr_DT0(DFPREG(rs1));
2897 gen_op_load_fpr_DT1(DFPREG(rs2));
2898 gen_op_fcmpd(rd & 3);
2900 case 0x53: /* fcmpq, V9 %fcc */
2901 CHECK_FPU_FEATURE(dc, FLOAT128);
2902 gen_op_load_fpr_QT0(QFPREG(rs1));
2903 gen_op_load_fpr_QT1(QFPREG(rs2));
2904 gen_op_fcmpq(rd & 3);
2906 case 0x55: /* fcmpes, V9 %fcc */
2907 gen_op_fcmpes(rd & 3, cpu_fpr[rs1], cpu_fpr[rs2]);
2909 case 0x56: /* fcmped, V9 %fcc */
2910 gen_op_load_fpr_DT0(DFPREG(rs1));
2911 gen_op_load_fpr_DT1(DFPREG(rs2));
2912 gen_op_fcmped(rd & 3);
2914 case 0x57: /* fcmpeq, V9 %fcc */
2915 CHECK_FPU_FEATURE(dc, FLOAT128);
2916 gen_op_load_fpr_QT0(QFPREG(rs1));
2917 gen_op_load_fpr_QT1(QFPREG(rs2));
2918 gen_op_fcmpeq(rd & 3);
2923 } else if (xop == 0x2) {
2926 rs1 = GET_FIELD(insn, 13, 17);
2928 // or %g0, x, y -> mov T0, x; mov y, T0
2929 if (IS_IMM) { /* immediate */
2932 rs2 = GET_FIELDs(insn, 19, 31);
2933 r_const = tcg_const_tl((int)rs2);
2934 gen_movl_TN_reg(rd, r_const);
2935 tcg_temp_free(r_const);
2936 } else { /* register */
2937 rs2 = GET_FIELD(insn, 27, 31);
2938 gen_movl_reg_TN(rs2, cpu_dst);
2939 gen_movl_TN_reg(rd, cpu_dst);
2942 cpu_src1 = get_src1(insn, cpu_src1);
2943 if (IS_IMM) { /* immediate */
2944 rs2 = GET_FIELDs(insn, 19, 31);
2945 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2946 gen_movl_TN_reg(rd, cpu_dst);
2947 } else { /* register */
2948 // or x, %g0, y -> mov T1, x; mov y, T1
2949 rs2 = GET_FIELD(insn, 27, 31);
2951 gen_movl_reg_TN(rs2, cpu_src2);
2952 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2953 gen_movl_TN_reg(rd, cpu_dst);
2955 gen_movl_TN_reg(rd, cpu_src1);
2958 #ifdef TARGET_SPARC64
2959 } else if (xop == 0x25) { /* sll, V9 sllx */
2960 cpu_src1 = get_src1(insn, cpu_src1);
2961 if (IS_IMM) { /* immediate */
2962 rs2 = GET_FIELDs(insn, 20, 31);
2963 if (insn & (1 << 12)) {
2964 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2966 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x1f);
2968 } else { /* register */
2969 rs2 = GET_FIELD(insn, 27, 31);
2970 gen_movl_reg_TN(rs2, cpu_src2);
2971 if (insn & (1 << 12)) {
2972 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2974 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2976 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2978 gen_movl_TN_reg(rd, cpu_dst);
2979 } else if (xop == 0x26) { /* srl, V9 srlx */
2980 cpu_src1 = get_src1(insn, cpu_src1);
2981 if (IS_IMM) { /* immediate */
2982 rs2 = GET_FIELDs(insn, 20, 31);
2983 if (insn & (1 << 12)) {
2984 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2986 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2987 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2989 } else { /* register */
2990 rs2 = GET_FIELD(insn, 27, 31);
2991 gen_movl_reg_TN(rs2, cpu_src2);
2992 if (insn & (1 << 12)) {
2993 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2994 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2996 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2997 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2998 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
3001 gen_movl_TN_reg(rd, cpu_dst);
3002 } else if (xop == 0x27) { /* sra, V9 srax */
3003 cpu_src1 = get_src1(insn, cpu_src1);
3004 if (IS_IMM) { /* immediate */
3005 rs2 = GET_FIELDs(insn, 20, 31);
3006 if (insn & (1 << 12)) {
3007 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
3009 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
3010 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
3011 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
3013 } else { /* register */
3014 rs2 = GET_FIELD(insn, 27, 31);
3015 gen_movl_reg_TN(rs2, cpu_src2);
3016 if (insn & (1 << 12)) {
3017 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
3018 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
3020 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
3021 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
3022 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
3023 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
3026 gen_movl_TN_reg(rd, cpu_dst);
3028 } else if (xop < 0x36) {
3029 cpu_src1 = get_src1(insn, cpu_src1);
3030 cpu_src2 = get_src2(insn, cpu_src2);
3032 switch (xop & ~0x10) {
3035 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
3037 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
3040 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
3042 gen_op_logic_cc(cpu_dst);
3045 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
3047 gen_op_logic_cc(cpu_dst);
3050 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3052 gen_op_logic_cc(cpu_dst);
3056 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
3058 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
3061 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3062 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
3064 gen_op_logic_cc(cpu_dst);
3067 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3068 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
3070 gen_op_logic_cc(cpu_dst);
3073 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3074 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
3076 gen_op_logic_cc(cpu_dst);
3080 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3082 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3083 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3084 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3087 #ifdef TARGET_SPARC64
3088 case 0x9: /* V9 mulx */
3089 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3093 CHECK_IU_FEATURE(dc, MUL);
3094 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3096 gen_op_logic_cc(cpu_dst);
3099 CHECK_IU_FEATURE(dc, MUL);
3100 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3102 gen_op_logic_cc(cpu_dst);
3106 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3108 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3109 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3110 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3113 #ifdef TARGET_SPARC64
3114 case 0xd: /* V9 udivx */
3115 tcg_gen_mov_tl(cpu_cc_src, cpu_src1);
3116 tcg_gen_mov_tl(cpu_cc_src2, cpu_src2);
3117 gen_trap_ifdivzero_tl(cpu_cc_src2);
3118 tcg_gen_divu_i64(cpu_dst, cpu_cc_src, cpu_cc_src2);
3122 CHECK_IU_FEATURE(dc, DIV);
3123 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1,
3126 gen_op_div_cc(cpu_dst);
3129 CHECK_IU_FEATURE(dc, DIV);
3130 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1,
3133 gen_op_div_cc(cpu_dst);
3138 gen_movl_TN_reg(rd, cpu_dst);
3141 case 0x20: /* taddcc */
3142 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3143 gen_movl_TN_reg(rd, cpu_dst);
3145 case 0x21: /* tsubcc */
3146 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3147 gen_movl_TN_reg(rd, cpu_dst);
3149 case 0x22: /* taddcctv */
3150 save_state(dc, cpu_cond);
3151 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3152 gen_movl_TN_reg(rd, cpu_dst);
3154 case 0x23: /* tsubcctv */
3155 save_state(dc, cpu_cond);
3156 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3157 gen_movl_TN_reg(rd, cpu_dst);
3159 case 0x24: /* mulscc */
3160 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3161 gen_movl_TN_reg(rd, cpu_dst);
3163 #ifndef TARGET_SPARC64
3164 case 0x25: /* sll */
3165 if (IS_IMM) { /* immediate */
3166 rs2 = GET_FIELDs(insn, 20, 31);
3167 tcg_gen_shli_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3168 } else { /* register */
3169 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3170 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3172 gen_movl_TN_reg(rd, cpu_dst);
3174 case 0x26: /* srl */
3175 if (IS_IMM) { /* immediate */
3176 rs2 = GET_FIELDs(insn, 20, 31);
3177 tcg_gen_shri_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3178 } else { /* register */
3179 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3180 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3182 gen_movl_TN_reg(rd, cpu_dst);
3184 case 0x27: /* sra */
3185 if (IS_IMM) { /* immediate */
3186 rs2 = GET_FIELDs(insn, 20, 31);
3187 tcg_gen_sari_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3188 } else { /* register */
3189 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3190 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3192 gen_movl_TN_reg(rd, cpu_dst);
3199 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3200 tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
3202 #ifndef TARGET_SPARC64
3203 case 0x01 ... 0x0f: /* undefined in the
3207 case 0x10 ... 0x1f: /* implementation-dependent
3213 case 0x2: /* V9 wrccr */
3214 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3215 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3217 case 0x3: /* V9 wrasi */
3218 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3219 tcg_gen_trunc_tl_i32(cpu_asi, cpu_dst);
3221 case 0x6: /* V9 wrfprs */
3222 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3223 tcg_gen_trunc_tl_i32(cpu_fprs, cpu_dst);
3224 save_state(dc, cpu_cond);
3229 case 0xf: /* V9 sir, nop if user */
3230 #if !defined(CONFIG_USER_ONLY)
3235 case 0x13: /* Graphics Status */
3236 if (gen_trap_ifnofpu(dc, cpu_cond))
3238 tcg_gen_xor_tl(cpu_gsr, cpu_src1, cpu_src2);
3240 case 0x17: /* Tick compare */
3241 #if !defined(CONFIG_USER_ONLY)
3242 if (!supervisor(dc))
3248 tcg_gen_xor_tl(cpu_tick_cmpr, cpu_src1,
3250 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3251 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3252 offsetof(CPUState, tick));
3253 tcg_gen_helper_0_2(helper_tick_set_limit,
3254 r_tickptr, cpu_tick_cmpr);
3255 tcg_temp_free(r_tickptr);
3258 case 0x18: /* System tick */
3259 #if !defined(CONFIG_USER_ONLY)
3260 if (!supervisor(dc))
3266 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3268 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3269 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3270 offsetof(CPUState, stick));
3271 tcg_gen_helper_0_2(helper_tick_set_count,
3272 r_tickptr, cpu_dst);
3273 tcg_temp_free(r_tickptr);
3276 case 0x19: /* System tick compare */
3277 #if !defined(CONFIG_USER_ONLY)
3278 if (!supervisor(dc))
3284 tcg_gen_xor_tl(cpu_stick_cmpr, cpu_src1,
3286 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3287 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3288 offsetof(CPUState, stick));
3289 tcg_gen_helper_0_2(helper_tick_set_limit,
3290 r_tickptr, cpu_stick_cmpr);
3291 tcg_temp_free(r_tickptr);
3295 case 0x10: /* Performance Control */
3296 case 0x11: /* Performance Instrumentation
3298 case 0x12: /* Dispatch Control */
3299 case 0x14: /* Softint set */
3300 case 0x15: /* Softint clear */
3301 case 0x16: /* Softint write */
3308 #if !defined(CONFIG_USER_ONLY)
3309 case 0x31: /* wrpsr, V9 saved, restored */
3311 if (!supervisor(dc))
3313 #ifdef TARGET_SPARC64
3316 tcg_gen_helper_0_0(helper_saved);
3319 tcg_gen_helper_0_0(helper_restored);
3321 case 2: /* UA2005 allclean */
3322 case 3: /* UA2005 otherw */
3323 case 4: /* UA2005 normalw */
3324 case 5: /* UA2005 invalw */
3330 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3331 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3332 save_state(dc, cpu_cond);
3339 case 0x32: /* wrwim, V9 wrpr */
3341 if (!supervisor(dc))
3343 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3344 #ifdef TARGET_SPARC64
3350 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3351 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3352 offsetof(CPUState, tsptr));
3353 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3354 offsetof(trap_state, tpc));
3355 tcg_temp_free(r_tsptr);
3362 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3363 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3364 offsetof(CPUState, tsptr));
3365 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3366 offsetof(trap_state, tnpc));
3367 tcg_temp_free(r_tsptr);
3374 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3375 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3376 offsetof(CPUState, tsptr));
3377 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3378 offsetof(trap_state,
3380 tcg_temp_free(r_tsptr);
3387 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3388 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3389 offsetof(CPUState, tsptr));
3390 tcg_gen_st_i32(cpu_tmp0, r_tsptr,
3391 offsetof(trap_state, tt));
3392 tcg_temp_free(r_tsptr);
3399 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3400 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3401 offsetof(CPUState, tick));
3402 tcg_gen_helper_0_2(helper_tick_set_count,
3403 r_tickptr, cpu_tmp0);
3404 tcg_temp_free(r_tickptr);
3408 tcg_gen_mov_tl(cpu_tbr, cpu_tmp0);
3411 save_state(dc, cpu_cond);
3412 tcg_gen_helper_0_1(helper_wrpstate, cpu_tmp0);
3418 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3419 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3420 offsetof(CPUSPARCState, tl));
3423 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3424 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3425 offsetof(CPUSPARCState,
3429 tcg_gen_helper_0_1(helper_wrcwp, cpu_tmp0);
3432 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3433 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3434 offsetof(CPUSPARCState,
3437 case 11: // canrestore
3438 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3439 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3440 offsetof(CPUSPARCState,
3443 case 12: // cleanwin
3444 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3445 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3446 offsetof(CPUSPARCState,
3449 case 13: // otherwin
3450 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3451 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3452 offsetof(CPUSPARCState,
3456 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3457 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3458 offsetof(CPUSPARCState,
3461 case 16: // UA2005 gl
3462 CHECK_IU_FEATURE(dc, GL);
3463 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3464 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3465 offsetof(CPUSPARCState, gl));
3467 case 26: // UA2005 strand status
3468 CHECK_IU_FEATURE(dc, HYPV);
3469 if (!hypervisor(dc))
3471 tcg_gen_trunc_tl_i32(cpu_ssr, cpu_tmp0);
3477 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3478 if (dc->def->nwindows != 32)
3479 tcg_gen_andi_tl(cpu_tmp32, cpu_tmp32,
3480 (1 << dc->def->nwindows) - 1);
3481 tcg_gen_mov_i32(cpu_wim, cpu_tmp32);
3485 case 0x33: /* wrtbr, UA2005 wrhpr */
3487 #ifndef TARGET_SPARC64
3488 if (!supervisor(dc))
3490 tcg_gen_xor_tl(cpu_tbr, cpu_src1, cpu_src2);
3492 CHECK_IU_FEATURE(dc, HYPV);
3493 if (!hypervisor(dc))
3495 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3498 // XXX gen_op_wrhpstate();
3499 save_state(dc, cpu_cond);
3505 // XXX gen_op_wrhtstate();
3508 tcg_gen_mov_tl(cpu_hintp, cpu_tmp0);
3511 tcg_gen_mov_tl(cpu_htba, cpu_tmp0);
3513 case 31: // hstick_cmpr
3517 tcg_gen_mov_tl(cpu_hstick_cmpr, cpu_tmp0);
3518 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3519 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3520 offsetof(CPUState, hstick));
3521 tcg_gen_helper_0_2(helper_tick_set_limit,
3522 r_tickptr, cpu_hstick_cmpr);
3523 tcg_temp_free(r_tickptr);
3526 case 6: // hver readonly
3534 #ifdef TARGET_SPARC64
3535 case 0x2c: /* V9 movcc */
3537 int cc = GET_FIELD_SP(insn, 11, 12);
3538 int cond = GET_FIELD_SP(insn, 14, 17);
3542 r_cond = tcg_temp_new(TCG_TYPE_TL);
3543 if (insn & (1 << 18)) {
3545 gen_cond(r_cond, 0, cond);
3547 gen_cond(r_cond, 1, cond);
3551 gen_fcond(r_cond, cc, cond);
3554 l1 = gen_new_label();
3556 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3557 if (IS_IMM) { /* immediate */
3560 rs2 = GET_FIELD_SPs(insn, 0, 10);
3561 r_const = tcg_const_tl((int)rs2);
3562 gen_movl_TN_reg(rd, r_const);
3563 tcg_temp_free(r_const);
3565 rs2 = GET_FIELD_SP(insn, 0, 4);
3566 gen_movl_reg_TN(rs2, cpu_tmp0);
3567 gen_movl_TN_reg(rd, cpu_tmp0);
3570 tcg_temp_free(r_cond);
3573 case 0x2d: /* V9 sdivx */
3574 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3575 gen_movl_TN_reg(rd, cpu_dst);
3577 case 0x2e: /* V9 popc */
3579 cpu_src2 = get_src2(insn, cpu_src2);
3580 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3582 gen_movl_TN_reg(rd, cpu_dst);
3584 case 0x2f: /* V9 movr */
3586 int cond = GET_FIELD_SP(insn, 10, 12);
3589 cpu_src1 = get_src1(insn, cpu_src1);
3591 l1 = gen_new_label();
3593 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
3595 if (IS_IMM) { /* immediate */
3598 rs2 = GET_FIELD_SPs(insn, 0, 9);
3599 r_const = tcg_const_tl((int)rs2);
3600 gen_movl_TN_reg(rd, r_const);
3601 tcg_temp_free(r_const);
3603 rs2 = GET_FIELD_SP(insn, 0, 4);
3604 gen_movl_reg_TN(rs2, cpu_tmp0);
3605 gen_movl_TN_reg(rd, cpu_tmp0);
3615 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3616 #ifdef TARGET_SPARC64
3617 int opf = GET_FIELD_SP(insn, 5, 13);
3618 rs1 = GET_FIELD(insn, 13, 17);
3619 rs2 = GET_FIELD(insn, 27, 31);
3620 if (gen_trap_ifnofpu(dc, cpu_cond))
3624 case 0x000: /* VIS I edge8cc */
3625 case 0x001: /* VIS II edge8n */
3626 case 0x002: /* VIS I edge8lcc */
3627 case 0x003: /* VIS II edge8ln */
3628 case 0x004: /* VIS I edge16cc */
3629 case 0x005: /* VIS II edge16n */
3630 case 0x006: /* VIS I edge16lcc */
3631 case 0x007: /* VIS II edge16ln */
3632 case 0x008: /* VIS I edge32cc */
3633 case 0x009: /* VIS II edge32n */
3634 case 0x00a: /* VIS I edge32lcc */
3635 case 0x00b: /* VIS II edge32ln */
3638 case 0x010: /* VIS I array8 */
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 gen_movl_TN_reg(rd, cpu_dst);
3646 case 0x012: /* VIS I array16 */
3647 CHECK_FPU_FEATURE(dc, VIS1);
3648 cpu_src1 = get_src1(insn, cpu_src1);
3649 gen_movl_reg_TN(rs2, cpu_src2);
3650 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3652 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3653 gen_movl_TN_reg(rd, cpu_dst);
3655 case 0x014: /* VIS I array32 */
3656 CHECK_FPU_FEATURE(dc, VIS1);
3657 cpu_src1 = get_src1(insn, cpu_src1);
3658 gen_movl_reg_TN(rs2, cpu_src2);
3659 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3661 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3662 gen_movl_TN_reg(rd, cpu_dst);
3664 case 0x018: /* VIS I alignaddr */
3665 CHECK_FPU_FEATURE(dc, VIS1);
3666 cpu_src1 = get_src1(insn, cpu_src1);
3667 gen_movl_reg_TN(rs2, cpu_src2);
3668 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3670 gen_movl_TN_reg(rd, cpu_dst);
3672 case 0x019: /* VIS II bmask */
3673 case 0x01a: /* VIS I alignaddrl */
3676 case 0x020: /* VIS I fcmple16 */
3677 CHECK_FPU_FEATURE(dc, VIS1);
3678 gen_op_load_fpr_DT0(DFPREG(rs1));
3679 gen_op_load_fpr_DT1(DFPREG(rs2));
3680 tcg_gen_helper_0_0(helper_fcmple16);
3681 gen_op_store_DT0_fpr(DFPREG(rd));
3683 case 0x022: /* VIS I fcmpne16 */
3684 CHECK_FPU_FEATURE(dc, VIS1);
3685 gen_op_load_fpr_DT0(DFPREG(rs1));
3686 gen_op_load_fpr_DT1(DFPREG(rs2));
3687 tcg_gen_helper_0_0(helper_fcmpne16);
3688 gen_op_store_DT0_fpr(DFPREG(rd));
3690 case 0x024: /* VIS I fcmple32 */
3691 CHECK_FPU_FEATURE(dc, VIS1);
3692 gen_op_load_fpr_DT0(DFPREG(rs1));
3693 gen_op_load_fpr_DT1(DFPREG(rs2));
3694 tcg_gen_helper_0_0(helper_fcmple32);
3695 gen_op_store_DT0_fpr(DFPREG(rd));
3697 case 0x026: /* VIS I fcmpne32 */
3698 CHECK_FPU_FEATURE(dc, VIS1);
3699 gen_op_load_fpr_DT0(DFPREG(rs1));
3700 gen_op_load_fpr_DT1(DFPREG(rs2));
3701 tcg_gen_helper_0_0(helper_fcmpne32);
3702 gen_op_store_DT0_fpr(DFPREG(rd));
3704 case 0x028: /* VIS I fcmpgt16 */
3705 CHECK_FPU_FEATURE(dc, VIS1);
3706 gen_op_load_fpr_DT0(DFPREG(rs1));
3707 gen_op_load_fpr_DT1(DFPREG(rs2));
3708 tcg_gen_helper_0_0(helper_fcmpgt16);
3709 gen_op_store_DT0_fpr(DFPREG(rd));
3711 case 0x02a: /* VIS I fcmpeq16 */
3712 CHECK_FPU_FEATURE(dc, VIS1);
3713 gen_op_load_fpr_DT0(DFPREG(rs1));
3714 gen_op_load_fpr_DT1(DFPREG(rs2));
3715 tcg_gen_helper_0_0(helper_fcmpeq16);
3716 gen_op_store_DT0_fpr(DFPREG(rd));
3718 case 0x02c: /* VIS I fcmpgt32 */
3719 CHECK_FPU_FEATURE(dc, VIS1);
3720 gen_op_load_fpr_DT0(DFPREG(rs1));
3721 gen_op_load_fpr_DT1(DFPREG(rs2));
3722 tcg_gen_helper_0_0(helper_fcmpgt32);
3723 gen_op_store_DT0_fpr(DFPREG(rd));
3725 case 0x02e: /* VIS I fcmpeq32 */
3726 CHECK_FPU_FEATURE(dc, VIS1);
3727 gen_op_load_fpr_DT0(DFPREG(rs1));
3728 gen_op_load_fpr_DT1(DFPREG(rs2));
3729 tcg_gen_helper_0_0(helper_fcmpeq32);
3730 gen_op_store_DT0_fpr(DFPREG(rd));
3732 case 0x031: /* VIS I fmul8x16 */
3733 CHECK_FPU_FEATURE(dc, VIS1);
3734 gen_op_load_fpr_DT0(DFPREG(rs1));
3735 gen_op_load_fpr_DT1(DFPREG(rs2));
3736 tcg_gen_helper_0_0(helper_fmul8x16);
3737 gen_op_store_DT0_fpr(DFPREG(rd));
3739 case 0x033: /* VIS I fmul8x16au */
3740 CHECK_FPU_FEATURE(dc, VIS1);
3741 gen_op_load_fpr_DT0(DFPREG(rs1));
3742 gen_op_load_fpr_DT1(DFPREG(rs2));
3743 tcg_gen_helper_0_0(helper_fmul8x16au);
3744 gen_op_store_DT0_fpr(DFPREG(rd));
3746 case 0x035: /* VIS I fmul8x16al */
3747 CHECK_FPU_FEATURE(dc, VIS1);
3748 gen_op_load_fpr_DT0(DFPREG(rs1));
3749 gen_op_load_fpr_DT1(DFPREG(rs2));
3750 tcg_gen_helper_0_0(helper_fmul8x16al);
3751 gen_op_store_DT0_fpr(DFPREG(rd));
3753 case 0x036: /* VIS I fmul8sux16 */
3754 CHECK_FPU_FEATURE(dc, VIS1);
3755 gen_op_load_fpr_DT0(DFPREG(rs1));
3756 gen_op_load_fpr_DT1(DFPREG(rs2));
3757 tcg_gen_helper_0_0(helper_fmul8sux16);
3758 gen_op_store_DT0_fpr(DFPREG(rd));
3760 case 0x037: /* VIS I fmul8ulx16 */
3761 CHECK_FPU_FEATURE(dc, VIS1);
3762 gen_op_load_fpr_DT0(DFPREG(rs1));
3763 gen_op_load_fpr_DT1(DFPREG(rs2));
3764 tcg_gen_helper_0_0(helper_fmul8ulx16);
3765 gen_op_store_DT0_fpr(DFPREG(rd));
3767 case 0x038: /* VIS I fmuld8sux16 */
3768 CHECK_FPU_FEATURE(dc, VIS1);
3769 gen_op_load_fpr_DT0(DFPREG(rs1));
3770 gen_op_load_fpr_DT1(DFPREG(rs2));
3771 tcg_gen_helper_0_0(helper_fmuld8sux16);
3772 gen_op_store_DT0_fpr(DFPREG(rd));
3774 case 0x039: /* VIS I fmuld8ulx16 */
3775 CHECK_FPU_FEATURE(dc, VIS1);
3776 gen_op_load_fpr_DT0(DFPREG(rs1));
3777 gen_op_load_fpr_DT1(DFPREG(rs2));
3778 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3779 gen_op_store_DT0_fpr(DFPREG(rd));
3781 case 0x03a: /* VIS I fpack32 */
3782 case 0x03b: /* VIS I fpack16 */
3783 case 0x03d: /* VIS I fpackfix */
3784 case 0x03e: /* VIS I pdist */
3787 case 0x048: /* VIS I faligndata */
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_faligndata);
3792 gen_op_store_DT0_fpr(DFPREG(rd));
3794 case 0x04b: /* VIS I fpmerge */
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_fpmerge);
3799 gen_op_store_DT0_fpr(DFPREG(rd));
3801 case 0x04c: /* VIS II bshuffle */
3804 case 0x04d: /* VIS I fexpand */
3805 CHECK_FPU_FEATURE(dc, VIS1);
3806 gen_op_load_fpr_DT0(DFPREG(rs1));
3807 gen_op_load_fpr_DT1(DFPREG(rs2));
3808 tcg_gen_helper_0_0(helper_fexpand);
3809 gen_op_store_DT0_fpr(DFPREG(rd));
3811 case 0x050: /* VIS I fpadd16 */
3812 CHECK_FPU_FEATURE(dc, VIS1);
3813 gen_op_load_fpr_DT0(DFPREG(rs1));
3814 gen_op_load_fpr_DT1(DFPREG(rs2));
3815 tcg_gen_helper_0_0(helper_fpadd16);
3816 gen_op_store_DT0_fpr(DFPREG(rd));
3818 case 0x051: /* VIS I fpadd16s */
3819 CHECK_FPU_FEATURE(dc, VIS1);
3820 tcg_gen_helper_1_2(helper_fpadd16s, cpu_fpr[rd],
3821 cpu_fpr[rs1], cpu_fpr[rs2]);
3823 case 0x052: /* VIS I fpadd32 */
3824 CHECK_FPU_FEATURE(dc, VIS1);
3825 gen_op_load_fpr_DT0(DFPREG(rs1));
3826 gen_op_load_fpr_DT1(DFPREG(rs2));
3827 tcg_gen_helper_0_0(helper_fpadd32);
3828 gen_op_store_DT0_fpr(DFPREG(rd));
3830 case 0x053: /* VIS I fpadd32s */
3831 CHECK_FPU_FEATURE(dc, VIS1);
3832 tcg_gen_helper_1_2(helper_fpadd32s, cpu_fpr[rd],
3833 cpu_fpr[rs1], cpu_fpr[rs2]);
3835 case 0x054: /* VIS I fpsub16 */
3836 CHECK_FPU_FEATURE(dc, VIS1);
3837 gen_op_load_fpr_DT0(DFPREG(rs1));
3838 gen_op_load_fpr_DT1(DFPREG(rs2));
3839 tcg_gen_helper_0_0(helper_fpsub16);
3840 gen_op_store_DT0_fpr(DFPREG(rd));
3842 case 0x055: /* VIS I fpsub16s */
3843 CHECK_FPU_FEATURE(dc, VIS1);
3844 tcg_gen_helper_1_2(helper_fpsub16s, cpu_fpr[rd],
3845 cpu_fpr[rs1], cpu_fpr[rs2]);
3847 case 0x056: /* VIS I fpsub32 */
3848 CHECK_FPU_FEATURE(dc, VIS1);
3849 gen_op_load_fpr_DT0(DFPREG(rs1));
3850 gen_op_load_fpr_DT1(DFPREG(rs2));
3851 tcg_gen_helper_0_0(helper_fpsub32);
3852 gen_op_store_DT0_fpr(DFPREG(rd));
3854 case 0x057: /* VIS I fpsub32s */
3855 CHECK_FPU_FEATURE(dc, VIS1);
3856 tcg_gen_helper_1_2(helper_fpsub32s, cpu_fpr[rd],
3857 cpu_fpr[rs1], cpu_fpr[rs2]);
3859 case 0x060: /* VIS I fzero */
3860 CHECK_FPU_FEATURE(dc, VIS1);
3861 tcg_gen_movi_i32(cpu_fpr[DFPREG(rd)], 0);
3862 tcg_gen_movi_i32(cpu_fpr[DFPREG(rd) + 1], 0);
3864 case 0x061: /* VIS I fzeros */
3865 CHECK_FPU_FEATURE(dc, VIS1);
3866 tcg_gen_movi_i32(cpu_fpr[rd], 0);
3868 case 0x062: /* VIS I fnor */
3869 CHECK_FPU_FEATURE(dc, VIS1);
3870 tcg_gen_or_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1)],
3871 cpu_fpr[DFPREG(rs2)]);
3872 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32, -1);
3873 tcg_gen_or_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1) + 1],
3874 cpu_fpr[DFPREG(rs2) + 1]);
3875 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32, -1);
3877 case 0x063: /* VIS I fnors */
3878 CHECK_FPU_FEATURE(dc, VIS1);
3879 tcg_gen_or_i32(cpu_tmp32, cpu_fpr[rs1], cpu_fpr[rs2]);
3880 tcg_gen_xori_i32(cpu_fpr[rd], cpu_tmp32, -1);
3882 case 0x064: /* VIS I fandnot2 */
3883 CHECK_FPU_FEATURE(dc, VIS1);
3884 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1)], -1);
3885 tcg_gen_and_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32,
3886 cpu_fpr[DFPREG(rs2)]);
3887 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1) + 1], -1);
3888 tcg_gen_and_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32,
3889 cpu_fpr[DFPREG(rs2) + 1]);
3891 case 0x065: /* VIS I fandnot2s */
3892 CHECK_FPU_FEATURE(dc, VIS1);
3893 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[rs1], -1);
3894 tcg_gen_and_i32(cpu_fpr[rd], cpu_tmp32, cpu_fpr[rs2]);
3896 case 0x066: /* VIS I fnot2 */
3897 CHECK_FPU_FEATURE(dc, VIS1);
3898 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs2)],
3900 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd) + 1],
3901 cpu_fpr[DFPREG(rs2) + 1], -1);
3903 case 0x067: /* VIS I fnot2s */
3904 CHECK_FPU_FEATURE(dc, VIS1);
3905 tcg_gen_xori_i32(cpu_fpr[rd], cpu_fpr[rs2], -1);
3907 case 0x068: /* VIS I fandnot1 */
3908 CHECK_FPU_FEATURE(dc, VIS1);
3909 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2)], -1);
3910 tcg_gen_and_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32,
3911 cpu_fpr[DFPREG(rs1)]);
3912 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2)], -1);
3913 tcg_gen_and_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32,
3914 cpu_fpr[DFPREG(rs1) + 1]);
3916 case 0x069: /* VIS I fandnot1s */
3917 CHECK_FPU_FEATURE(dc, VIS1);
3918 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[rs2], -1);
3919 tcg_gen_and_i32(cpu_fpr[rd], cpu_tmp32, cpu_fpr[rs1]);
3921 case 0x06a: /* VIS I fnot1 */
3922 CHECK_FPU_FEATURE(dc, VIS1);
3923 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
3925 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd) + 1],
3926 cpu_fpr[DFPREG(rs1) + 1], -1);
3928 case 0x06b: /* VIS I fnot1s */
3929 CHECK_FPU_FEATURE(dc, VIS1);
3930 tcg_gen_xori_i32(cpu_fpr[rd], cpu_fpr[rs1], -1);
3932 case 0x06c: /* VIS I fxor */
3933 CHECK_FPU_FEATURE(dc, VIS1);
3934 tcg_gen_xor_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
3935 cpu_fpr[DFPREG(rs2)]);
3936 tcg_gen_xor_i32(cpu_fpr[DFPREG(rd) + 1],
3937 cpu_fpr[DFPREG(rs1) + 1],
3938 cpu_fpr[DFPREG(rs2) + 1]);
3940 case 0x06d: /* VIS I fxors */
3941 CHECK_FPU_FEATURE(dc, VIS1);
3942 tcg_gen_xor_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
3944 case 0x06e: /* VIS I fnand */
3945 CHECK_FPU_FEATURE(dc, VIS1);
3946 tcg_gen_and_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1)],
3947 cpu_fpr[DFPREG(rs2)]);
3948 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32, -1);
3949 tcg_gen_and_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1) + 1],
3950 cpu_fpr[DFPREG(rs2) + 1]);
3951 tcg_gen_xori_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32, -1);
3953 case 0x06f: /* VIS I fnands */
3954 CHECK_FPU_FEATURE(dc, VIS1);
3955 tcg_gen_and_i32(cpu_tmp32, cpu_fpr[rs1], cpu_fpr[rs2]);
3956 tcg_gen_xori_i32(cpu_fpr[rd], cpu_tmp32, -1);
3958 case 0x070: /* VIS I fand */
3959 CHECK_FPU_FEATURE(dc, VIS1);
3960 tcg_gen_and_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
3961 cpu_fpr[DFPREG(rs2)]);
3962 tcg_gen_and_i32(cpu_fpr[DFPREG(rd) + 1],
3963 cpu_fpr[DFPREG(rs1) + 1],
3964 cpu_fpr[DFPREG(rs2) + 1]);
3966 case 0x071: /* VIS I fands */
3967 CHECK_FPU_FEATURE(dc, VIS1);
3968 tcg_gen_and_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
3970 case 0x072: /* VIS I fxnor */
3971 CHECK_FPU_FEATURE(dc, VIS1);
3972 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2)], -1);
3973 tcg_gen_xor_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32,
3974 cpu_fpr[DFPREG(rs1)]);
3975 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2) + 1], -1);
3976 tcg_gen_xor_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32,
3977 cpu_fpr[DFPREG(rs1) + 1]);
3979 case 0x073: /* VIS I fxnors */
3980 CHECK_FPU_FEATURE(dc, VIS1);
3981 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[rs2], -1);
3982 tcg_gen_xor_i32(cpu_fpr[rd], cpu_tmp32, cpu_fpr[rs1]);
3984 case 0x074: /* VIS I fsrc1 */
3985 CHECK_FPU_FEATURE(dc, VIS1);
3986 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)]);
3987 tcg_gen_mov_i32(cpu_fpr[DFPREG(rd) + 1],
3988 cpu_fpr[DFPREG(rs1) + 1]);
3990 case 0x075: /* VIS I fsrc1s */
3991 CHECK_FPU_FEATURE(dc, VIS1);
3992 tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs1]);
3994 case 0x076: /* VIS I fornot2 */
3995 CHECK_FPU_FEATURE(dc, VIS1);
3996 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1)], -1);
3997 tcg_gen_or_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32,
3998 cpu_fpr[DFPREG(rs2)]);
3999 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs1) + 1], -1);
4000 tcg_gen_or_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32,
4001 cpu_fpr[DFPREG(rs2) + 1]);
4003 case 0x077: /* VIS I fornot2s */
4004 CHECK_FPU_FEATURE(dc, VIS1);
4005 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[rs1], -1);
4006 tcg_gen_or_i32(cpu_fpr[rd], cpu_tmp32, cpu_fpr[rs2]);
4008 case 0x078: /* VIS I fsrc2 */
4009 CHECK_FPU_FEATURE(dc, VIS1);
4010 gen_op_load_fpr_DT0(DFPREG(rs2));
4011 gen_op_store_DT0_fpr(DFPREG(rd));
4013 case 0x079: /* VIS I fsrc2s */
4014 CHECK_FPU_FEATURE(dc, VIS1);
4015 tcg_gen_mov_i32(cpu_fpr[rd], cpu_fpr[rs2]);
4017 case 0x07a: /* VIS I fornot1 */
4018 CHECK_FPU_FEATURE(dc, VIS1);
4019 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2)], -1);
4020 tcg_gen_or_i32(cpu_fpr[DFPREG(rd)], cpu_tmp32,
4021 cpu_fpr[DFPREG(rs1)]);
4022 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[DFPREG(rs2) + 1], -1);
4023 tcg_gen_or_i32(cpu_fpr[DFPREG(rd) + 1], cpu_tmp32,
4024 cpu_fpr[DFPREG(rs1) + 1]);
4026 case 0x07b: /* VIS I fornot1s */
4027 CHECK_FPU_FEATURE(dc, VIS1);
4028 tcg_gen_xori_i32(cpu_tmp32, cpu_fpr[rs2], -1);
4029 tcg_gen_or_i32(cpu_fpr[rd], cpu_tmp32, cpu_fpr[rs1]);
4031 case 0x07c: /* VIS I for */
4032 CHECK_FPU_FEATURE(dc, VIS1);
4033 tcg_gen_or_i32(cpu_fpr[DFPREG(rd)], cpu_fpr[DFPREG(rs1)],
4034 cpu_fpr[DFPREG(rs2)]);
4035 tcg_gen_or_i32(cpu_fpr[DFPREG(rd) + 1],
4036 cpu_fpr[DFPREG(rs1) + 1],
4037 cpu_fpr[DFPREG(rs2) + 1]);
4039 case 0x07d: /* VIS I fors */
4040 CHECK_FPU_FEATURE(dc, VIS1);
4041 tcg_gen_or_i32(cpu_fpr[rd], cpu_fpr[rs1], cpu_fpr[rs2]);
4043 case 0x07e: /* VIS I fone */
4044 CHECK_FPU_FEATURE(dc, VIS1);
4045 tcg_gen_movi_i32(cpu_fpr[DFPREG(rd)], -1);
4046 tcg_gen_movi_i32(cpu_fpr[DFPREG(rd) + 1], -1);
4048 case 0x07f: /* VIS I fones */
4049 CHECK_FPU_FEATURE(dc, VIS1);
4050 tcg_gen_movi_i32(cpu_fpr[rd], -1);
4052 case 0x080: /* VIS I shutdown */
4053 case 0x081: /* VIS II siam */
4062 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4063 #ifdef TARGET_SPARC64
4068 #ifdef TARGET_SPARC64
4069 } else if (xop == 0x39) { /* V9 return */
4072 save_state(dc, cpu_cond);
4073 cpu_src1 = get_src1(insn, cpu_src1);
4074 if (IS_IMM) { /* immediate */
4075 rs2 = GET_FIELDs(insn, 19, 31);
4076 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4077 } else { /* register */
4078 rs2 = GET_FIELD(insn, 27, 31);
4080 gen_movl_reg_TN(rs2, cpu_src2);
4081 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4083 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4085 tcg_gen_helper_0_0(helper_restore);
4086 gen_mov_pc_npc(dc, cpu_cond);
4087 r_const = tcg_const_i32(3);
4088 tcg_gen_helper_0_2(helper_check_align, cpu_dst, r_const);
4089 tcg_temp_free(r_const);
4090 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4091 dc->npc = DYNAMIC_PC;
4095 cpu_src1 = get_src1(insn, cpu_src1);
4096 if (IS_IMM) { /* immediate */
4097 rs2 = GET_FIELDs(insn, 19, 31);
4098 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4099 } else { /* register */
4100 rs2 = GET_FIELD(insn, 27, 31);
4102 gen_movl_reg_TN(rs2, cpu_src2);
4103 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4105 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4108 case 0x38: /* jmpl */
4112 r_const = tcg_const_tl(dc->pc);
4113 gen_movl_TN_reg(rd, r_const);
4114 tcg_temp_free(r_const);
4115 gen_mov_pc_npc(dc, cpu_cond);
4116 r_const = tcg_const_i32(3);
4117 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4119 tcg_temp_free(r_const);
4120 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4121 dc->npc = DYNAMIC_PC;
4124 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4125 case 0x39: /* rett, V9 return */
4129 if (!supervisor(dc))
4131 gen_mov_pc_npc(dc, cpu_cond);
4132 r_const = tcg_const_i32(3);
4133 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4135 tcg_temp_free(r_const);
4136 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4137 dc->npc = DYNAMIC_PC;
4138 tcg_gen_helper_0_0(helper_rett);
4142 case 0x3b: /* flush */
4143 if (!((dc)->def->features & CPU_FEATURE_FLUSH))
4145 tcg_gen_helper_0_1(helper_flush, cpu_dst);
4147 case 0x3c: /* save */
4148 save_state(dc, cpu_cond);
4149 tcg_gen_helper_0_0(helper_save);
4150 gen_movl_TN_reg(rd, cpu_dst);
4152 case 0x3d: /* restore */
4153 save_state(dc, cpu_cond);
4154 tcg_gen_helper_0_0(helper_restore);
4155 gen_movl_TN_reg(rd, cpu_dst);
4157 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4158 case 0x3e: /* V9 done/retry */
4162 if (!supervisor(dc))
4164 dc->npc = DYNAMIC_PC;
4165 dc->pc = DYNAMIC_PC;
4166 tcg_gen_helper_0_0(helper_done);
4169 if (!supervisor(dc))
4171 dc->npc = DYNAMIC_PC;
4172 dc->pc = DYNAMIC_PC;
4173 tcg_gen_helper_0_0(helper_retry);
4188 case 3: /* load/store instructions */
4190 unsigned int xop = GET_FIELD(insn, 7, 12);
4192 cpu_src1 = get_src1(insn, cpu_src1);
4193 if (xop == 0x3c || xop == 0x3e) { // V9 casa/casxa
4194 rs2 = GET_FIELD(insn, 27, 31);
4195 gen_movl_reg_TN(rs2, cpu_src2);
4196 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4197 } else if (IS_IMM) { /* immediate */
4198 rs2 = GET_FIELDs(insn, 19, 31);
4199 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4200 } else { /* register */
4201 rs2 = GET_FIELD(insn, 27, 31);
4203 gen_movl_reg_TN(rs2, cpu_src2);
4204 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4206 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4208 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4209 (xop > 0x17 && xop <= 0x1d ) ||
4210 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4212 case 0x0: /* load unsigned word */
4213 gen_address_mask(dc, cpu_addr);
4214 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4216 case 0x1: /* load unsigned byte */
4217 gen_address_mask(dc, cpu_addr);
4218 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4220 case 0x2: /* load unsigned halfword */
4221 gen_address_mask(dc, cpu_addr);
4222 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4224 case 0x3: /* load double word */
4230 save_state(dc, cpu_cond);
4231 r_const = tcg_const_i32(7);
4232 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4233 r_const); // XXX remove
4234 tcg_temp_free(r_const);
4235 gen_address_mask(dc, cpu_addr);
4236 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4237 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4238 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4239 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4240 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4241 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4242 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4245 case 0x9: /* load signed byte */
4246 gen_address_mask(dc, cpu_addr);
4247 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4249 case 0xa: /* load signed halfword */
4250 gen_address_mask(dc, cpu_addr);
4251 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4253 case 0xd: /* ldstub -- XXX: should be atomically */
4257 gen_address_mask(dc, cpu_addr);
4258 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4259 r_const = tcg_const_tl(0xff);
4260 tcg_gen_qemu_st8(r_const, cpu_addr, dc->mem_idx);
4261 tcg_temp_free(r_const);
4264 case 0x0f: /* swap register with memory. Also
4266 CHECK_IU_FEATURE(dc, SWAP);
4267 gen_movl_reg_TN(rd, cpu_val);
4268 gen_address_mask(dc, cpu_addr);
4269 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4270 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4271 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4273 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4274 case 0x10: /* load word alternate */
4275 #ifndef TARGET_SPARC64
4278 if (!supervisor(dc))
4281 save_state(dc, cpu_cond);
4282 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4284 case 0x11: /* load unsigned byte alternate */
4285 #ifndef TARGET_SPARC64
4288 if (!supervisor(dc))
4291 save_state(dc, cpu_cond);
4292 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4294 case 0x12: /* load unsigned halfword alternate */
4295 #ifndef TARGET_SPARC64
4298 if (!supervisor(dc))
4301 save_state(dc, cpu_cond);
4302 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4304 case 0x13: /* load double word alternate */
4305 #ifndef TARGET_SPARC64
4308 if (!supervisor(dc))
4313 save_state(dc, cpu_cond);
4314 gen_ldda_asi(cpu_val, cpu_addr, insn, rd);
4316 case 0x19: /* load signed byte alternate */
4317 #ifndef TARGET_SPARC64
4320 if (!supervisor(dc))
4323 save_state(dc, cpu_cond);
4324 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4326 case 0x1a: /* load signed halfword alternate */
4327 #ifndef TARGET_SPARC64
4330 if (!supervisor(dc))
4333 save_state(dc, cpu_cond);
4334 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4336 case 0x1d: /* ldstuba -- XXX: should be atomically */
4337 #ifndef TARGET_SPARC64
4340 if (!supervisor(dc))
4343 save_state(dc, cpu_cond);
4344 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4346 case 0x1f: /* swap reg with alt. memory. Also
4348 CHECK_IU_FEATURE(dc, SWAP);
4349 #ifndef TARGET_SPARC64
4352 if (!supervisor(dc))
4355 save_state(dc, cpu_cond);
4356 gen_movl_reg_TN(rd, cpu_val);
4357 gen_swap_asi(cpu_val, cpu_addr, insn);
4360 #ifndef TARGET_SPARC64
4361 case 0x30: /* ldc */
4362 case 0x31: /* ldcsr */
4363 case 0x33: /* lddc */
4367 #ifdef TARGET_SPARC64
4368 case 0x08: /* V9 ldsw */
4369 gen_address_mask(dc, cpu_addr);
4370 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4372 case 0x0b: /* V9 ldx */
4373 gen_address_mask(dc, cpu_addr);
4374 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4376 case 0x18: /* V9 ldswa */
4377 save_state(dc, cpu_cond);
4378 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4380 case 0x1b: /* V9 ldxa */
4381 save_state(dc, cpu_cond);
4382 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4384 case 0x2d: /* V9 prefetch, no effect */
4386 case 0x30: /* V9 ldfa */
4387 save_state(dc, cpu_cond);
4388 gen_ldf_asi(cpu_addr, insn, 4, rd);
4390 case 0x33: /* V9 lddfa */
4391 save_state(dc, cpu_cond);
4392 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4394 case 0x3d: /* V9 prefetcha, no effect */
4396 case 0x32: /* V9 ldqfa */
4397 CHECK_FPU_FEATURE(dc, FLOAT128);
4398 save_state(dc, cpu_cond);
4399 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4405 gen_movl_TN_reg(rd, cpu_val);
4406 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4409 } else if (xop >= 0x20 && xop < 0x24) {
4410 if (gen_trap_ifnofpu(dc, cpu_cond))
4412 save_state(dc, cpu_cond);
4414 case 0x20: /* load fpreg */
4415 gen_address_mask(dc, cpu_addr);
4416 tcg_gen_qemu_ld32u(cpu_fpr[rd], cpu_addr, dc->mem_idx);
4418 case 0x21: /* ldfsr, V9 ldxfsr */
4419 #ifdef TARGET_SPARC64
4420 gen_address_mask(dc, cpu_addr);
4422 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4423 tcg_gen_helper_0_1(helper_ldxfsr, cpu_tmp64);
4427 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4428 tcg_gen_helper_0_1(helper_ldfsr, cpu_tmp32);
4432 case 0x22: /* load quad fpreg */
4436 CHECK_FPU_FEATURE(dc, FLOAT128);
4437 r_const = tcg_const_i32(dc->mem_idx);
4438 tcg_gen_helper_0_2(helper_ldqf, cpu_addr, r_const);
4439 tcg_temp_free(r_const);
4440 gen_op_store_QT0_fpr(QFPREG(rd));
4443 case 0x23: /* load double fpreg */
4447 r_const = tcg_const_i32(dc->mem_idx);
4448 tcg_gen_helper_0_2(helper_lddf, cpu_addr, r_const);
4449 tcg_temp_free(r_const);
4450 gen_op_store_DT0_fpr(DFPREG(rd));
4456 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4457 xop == 0xe || xop == 0x1e) {
4458 gen_movl_reg_TN(rd, cpu_val);
4460 case 0x4: /* store word */
4461 gen_address_mask(dc, cpu_addr);
4462 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4464 case 0x5: /* store byte */
4465 gen_address_mask(dc, cpu_addr);
4466 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4468 case 0x6: /* store halfword */
4469 gen_address_mask(dc, cpu_addr);
4470 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4472 case 0x7: /* store double word */
4476 TCGv r_low, r_const;
4478 save_state(dc, cpu_cond);
4479 gen_address_mask(dc, cpu_addr);
4480 r_const = tcg_const_i32(7);
4481 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4482 r_const); // XXX remove
4483 tcg_temp_free(r_const);
4484 r_low = tcg_temp_new(TCG_TYPE_TL);
4485 gen_movl_reg_TN(rd + 1, r_low);
4486 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4488 tcg_temp_free(r_low);
4489 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4492 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4493 case 0x14: /* store word alternate */
4494 #ifndef TARGET_SPARC64
4497 if (!supervisor(dc))
4500 save_state(dc, cpu_cond);
4501 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4503 case 0x15: /* store byte alternate */
4504 #ifndef TARGET_SPARC64
4507 if (!supervisor(dc))
4510 save_state(dc, cpu_cond);
4511 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4513 case 0x16: /* store halfword alternate */
4514 #ifndef TARGET_SPARC64
4517 if (!supervisor(dc))
4520 save_state(dc, cpu_cond);
4521 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4523 case 0x17: /* store double word alternate */
4524 #ifndef TARGET_SPARC64
4527 if (!supervisor(dc))
4533 save_state(dc, cpu_cond);
4534 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4538 #ifdef TARGET_SPARC64
4539 case 0x0e: /* V9 stx */
4540 gen_address_mask(dc, cpu_addr);
4541 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4543 case 0x1e: /* V9 stxa */
4544 save_state(dc, cpu_cond);
4545 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4551 } else if (xop > 0x23 && xop < 0x28) {
4552 if (gen_trap_ifnofpu(dc, cpu_cond))
4554 save_state(dc, cpu_cond);
4556 case 0x24: /* store fpreg */
4557 gen_address_mask(dc, cpu_addr);
4558 tcg_gen_qemu_st32(cpu_fpr[rd], cpu_addr, dc->mem_idx);
4560 case 0x25: /* stfsr, V9 stxfsr */
4561 #ifdef TARGET_SPARC64
4562 gen_address_mask(dc, cpu_addr);
4563 tcg_gen_ld_i64(cpu_tmp64, cpu_env, offsetof(CPUState, fsr));
4565 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4567 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp64);
4568 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4571 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUState, fsr));
4572 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4576 #ifdef TARGET_SPARC64
4577 /* V9 stqf, store quad fpreg */
4581 CHECK_FPU_FEATURE(dc, FLOAT128);
4582 gen_op_load_fpr_QT0(QFPREG(rd));
4583 r_const = tcg_const_i32(dc->mem_idx);
4584 tcg_gen_helper_0_2(helper_stqf, cpu_addr, r_const);
4585 tcg_temp_free(r_const);
4588 #else /* !TARGET_SPARC64 */
4589 /* stdfq, store floating point queue */
4590 #if defined(CONFIG_USER_ONLY)
4593 if (!supervisor(dc))
4595 if (gen_trap_ifnofpu(dc, cpu_cond))
4600 case 0x27: /* store double fpreg */
4604 gen_op_load_fpr_DT0(DFPREG(rd));
4605 r_const = tcg_const_i32(dc->mem_idx);
4606 tcg_gen_helper_0_2(helper_stdf, cpu_addr, r_const);
4607 tcg_temp_free(r_const);
4613 } else if (xop > 0x33 && xop < 0x3f) {
4614 save_state(dc, cpu_cond);
4616 #ifdef TARGET_SPARC64
4617 case 0x34: /* V9 stfa */
4618 gen_stf_asi(cpu_addr, insn, 4, rd);
4620 case 0x36: /* V9 stqfa */
4624 CHECK_FPU_FEATURE(dc, FLOAT128);
4625 r_const = tcg_const_i32(7);
4626 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4628 tcg_temp_free(r_const);
4629 gen_op_load_fpr_QT0(QFPREG(rd));
4630 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4633 case 0x37: /* V9 stdfa */
4634 gen_op_load_fpr_DT0(DFPREG(rd));
4635 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4637 case 0x3c: /* V9 casa */
4638 gen_cas_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4639 gen_movl_TN_reg(rd, cpu_val);
4641 case 0x3e: /* V9 casxa */
4642 gen_casx_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4643 gen_movl_TN_reg(rd, cpu_val);
4646 case 0x34: /* stc */
4647 case 0x35: /* stcsr */
4648 case 0x36: /* stdcq */
4649 case 0x37: /* stdc */
4661 /* default case for non jump instructions */
4662 if (dc->npc == DYNAMIC_PC) {
4663 dc->pc = DYNAMIC_PC;
4665 } else if (dc->npc == JUMP_PC) {
4666 /* we can do a static jump */
4667 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4671 dc->npc = dc->npc + 4;
4679 save_state(dc, cpu_cond);
4680 r_const = tcg_const_i32(TT_ILL_INSN);
4681 tcg_gen_helper_0_1(raise_exception, r_const);
4682 tcg_temp_free(r_const);
4690 save_state(dc, cpu_cond);
4691 r_const = tcg_const_i32(TT_UNIMP_FLUSH);
4692 tcg_gen_helper_0_1(raise_exception, r_const);
4693 tcg_temp_free(r_const);
4697 #if !defined(CONFIG_USER_ONLY)
4702 save_state(dc, cpu_cond);
4703 r_const = tcg_const_i32(TT_PRIV_INSN);
4704 tcg_gen_helper_0_1(raise_exception, r_const);
4705 tcg_temp_free(r_const);
4711 save_state(dc, cpu_cond);
4712 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4715 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4717 save_state(dc, cpu_cond);
4718 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4722 #ifndef TARGET_SPARC64
4727 save_state(dc, cpu_cond);
4728 r_const = tcg_const_i32(TT_NCP_INSN);
4729 tcg_gen_helper_0_1(raise_exception, r_const);
4730 tcg_temp_free(r_const);
4737 static inline void gen_intermediate_code_internal(TranslationBlock * tb,
4738 int spc, CPUSPARCState *env)
4740 target_ulong pc_start, last_pc;
4741 uint16_t *gen_opc_end;
4742 DisasContext dc1, *dc = &dc1;
4747 memset(dc, 0, sizeof(DisasContext));
4752 dc->npc = (target_ulong) tb->cs_base;
4753 dc->mem_idx = cpu_mmu_index(env);
4755 if ((dc->def->features & CPU_FEATURE_FLOAT))
4756 dc->fpu_enabled = cpu_fpu_enabled(env);
4758 dc->fpu_enabled = 0;
4759 #ifdef TARGET_SPARC64
4760 dc->address_mask_32bit = env->pstate & PS_AM;
4762 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4764 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4765 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4766 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4768 cpu_dst = tcg_temp_local_new(TCG_TYPE_TL);
4771 cpu_val = tcg_temp_local_new(TCG_TYPE_TL);
4772 cpu_addr = tcg_temp_local_new(TCG_TYPE_TL);
4775 max_insns = tb->cflags & CF_COUNT_MASK;
4777 max_insns = CF_COUNT_MASK;
4780 if (env->nb_breakpoints > 0) {
4781 for(j = 0; j < env->nb_breakpoints; j++) {
4782 if (env->breakpoints[j] == dc->pc) {
4783 if (dc->pc != pc_start)
4784 save_state(dc, cpu_cond);
4785 tcg_gen_helper_0_0(helper_debug);
4794 fprintf(logfile, "Search PC...\n");
4795 j = gen_opc_ptr - gen_opc_buf;
4799 gen_opc_instr_start[lj++] = 0;
4800 gen_opc_pc[lj] = dc->pc;
4801 gen_opc_npc[lj] = dc->npc;
4802 gen_opc_instr_start[lj] = 1;
4803 gen_opc_icount[lj] = num_insns;
4806 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
4809 disas_sparc_insn(dc);
4814 /* if the next PC is different, we abort now */
4815 if (dc->pc != (last_pc + 4))
4817 /* if we reach a page boundary, we stop generation so that the
4818 PC of a TT_TFAULT exception is always in the right page */
4819 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4821 /* if single step mode, we generate only one instruction and
4822 generate an exception */
4823 if (env->singlestep_enabled) {
4824 tcg_gen_movi_tl(cpu_pc, dc->pc);
4828 } while ((gen_opc_ptr < gen_opc_end) &&
4829 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
4830 num_insns < max_insns);
4833 tcg_temp_free(cpu_addr);
4834 tcg_temp_free(cpu_val);
4835 tcg_temp_free(cpu_dst);
4836 tcg_temp_free(cpu_tmp64);
4837 tcg_temp_free(cpu_tmp32);
4838 tcg_temp_free(cpu_tmp0);
4839 if (tb->cflags & CF_LAST_IO)
4842 if (dc->pc != DYNAMIC_PC &&
4843 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4844 /* static PC and NPC: we can use direct chaining */
4845 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4847 if (dc->pc != DYNAMIC_PC)
4848 tcg_gen_movi_tl(cpu_pc, dc->pc);
4849 save_npc(dc, cpu_cond);
4853 gen_icount_end(tb, num_insns);
4854 *gen_opc_ptr = INDEX_op_end;
4856 j = gen_opc_ptr - gen_opc_buf;
4859 gen_opc_instr_start[lj++] = 0;
4865 gen_opc_jump_pc[0] = dc->jump_pc[0];
4866 gen_opc_jump_pc[1] = dc->jump_pc[1];
4868 tb->size = last_pc + 4 - pc_start;
4869 tb->icount = num_insns;
4872 if (loglevel & CPU_LOG_TB_IN_ASM) {
4873 fprintf(logfile, "--------------\n");
4874 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4875 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4876 fprintf(logfile, "\n");
4881 void gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4883 gen_intermediate_code_internal(tb, 0, env);
4886 void gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4888 gen_intermediate_code_internal(tb, 1, env);
4891 void gen_intermediate_code_init(CPUSPARCState *env)
4895 static const char * const gregnames[8] = {
4896 NULL, // g0 not used
4905 static const char * const fregnames[64] = {
4906 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
4907 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
4908 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
4909 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
4910 "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
4911 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47",
4912 "f48", "f49", "f50", "f51", "f52", "f53", "f54", "f55",
4913 "f56", "f57", "f58", "f59", "f60", "f61", "f62", "f63",
4916 /* init various static tables */
4920 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4921 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4922 offsetof(CPUState, regwptr),
4924 #ifdef TARGET_SPARC64
4925 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4926 TCG_AREG0, offsetof(CPUState, xcc),
4928 cpu_asi = tcg_global_mem_new(TCG_TYPE_I32,
4929 TCG_AREG0, offsetof(CPUState, asi),
4931 cpu_fprs = tcg_global_mem_new(TCG_TYPE_I32,
4932 TCG_AREG0, offsetof(CPUState, fprs),
4934 cpu_gsr = tcg_global_mem_new(TCG_TYPE_TL,
4935 TCG_AREG0, offsetof(CPUState, gsr),
4937 cpu_tick_cmpr = tcg_global_mem_new(TCG_TYPE_TL,
4939 offsetof(CPUState, tick_cmpr),
4941 cpu_stick_cmpr = tcg_global_mem_new(TCG_TYPE_TL,
4943 offsetof(CPUState, stick_cmpr),
4945 cpu_hstick_cmpr = tcg_global_mem_new(TCG_TYPE_TL,
4947 offsetof(CPUState, hstick_cmpr),
4949 cpu_hintp = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4950 offsetof(CPUState, hintp),
4952 cpu_htba = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4953 offsetof(CPUState, htba),
4955 cpu_hver = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4956 offsetof(CPUState, hver),
4958 cpu_ssr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4959 offsetof(CPUState, ssr), "ssr");
4960 cpu_ver = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4961 offsetof(CPUState, version), "ver");
4963 cpu_wim = tcg_global_mem_new(TCG_TYPE_I32,
4964 TCG_AREG0, offsetof(CPUState, wim),
4967 cpu_cond = tcg_global_mem_new(TCG_TYPE_TL,
4968 TCG_AREG0, offsetof(CPUState, cond),
4970 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4971 TCG_AREG0, offsetof(CPUState, cc_src),
4973 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4974 offsetof(CPUState, cc_src2),
4976 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4977 TCG_AREG0, offsetof(CPUState, cc_dst),
4979 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4980 TCG_AREG0, offsetof(CPUState, psr),
4982 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4983 TCG_AREG0, offsetof(CPUState, fsr),
4985 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4986 TCG_AREG0, offsetof(CPUState, pc),
4988 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4989 TCG_AREG0, offsetof(CPUState, npc),
4991 cpu_y = tcg_global_mem_new(TCG_TYPE_TL,
4992 TCG_AREG0, offsetof(CPUState, y), "y");
4993 #ifndef CONFIG_USER_ONLY
4994 cpu_tbr = tcg_global_mem_new(TCG_TYPE_TL,
4995 TCG_AREG0, offsetof(CPUState, tbr),
4998 for (i = 1; i < 8; i++)
4999 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
5000 offsetof(CPUState, gregs[i]),
5002 for (i = 0; i < TARGET_FPREGS; i++)
5003 cpu_fpr[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
5004 offsetof(CPUState, fpr[i]),
5007 /* register helpers */
5010 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
5015 void gen_pc_load(CPUState *env, TranslationBlock *tb,
5016 unsigned long searched_pc, int pc_pos, void *puc)
5019 env->pc = gen_opc_pc[pc_pos];
5020 npc = gen_opc_npc[pc_pos];
5022 /* dynamic NPC: already stored */
5023 } else if (npc == 2) {
5024 target_ulong t2 = (target_ulong)(unsigned long)puc;
5025 /* jump PC: use T2 and the jump targets of the translation */
5027 env->npc = gen_opc_jump_pc[0];
5029 env->npc = gen_opc_jump_pc[1];