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;
59 #include "gen-icount.h"
61 typedef struct DisasContext {
62 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
63 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
64 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
68 int address_mask_32bit;
69 struct TranslationBlock *tb;
73 // This function uses non-native bit order
74 #define GET_FIELD(X, FROM, TO) \
75 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
77 // This function uses the order in the manuals, i.e. bit 0 is 2^0
78 #define GET_FIELD_SP(X, FROM, TO) \
79 GET_FIELD(X, 31 - (TO), 31 - (FROM))
81 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
82 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
86 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
87 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
90 #define DFPREG(r) (r & 0x1e)
91 #define QFPREG(r) (r & 0x1c)
94 static int sign_extend(int x, int len)
97 return (x << len) >> len;
100 #define IS_IMM (insn & (1<<13))
102 /* floating point registers moves */
103 static void gen_op_load_fpr_FT0(unsigned int src)
105 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
106 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
109 static void gen_op_load_fpr_FT1(unsigned int src)
111 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
112 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
115 static void gen_op_store_FT0_fpr(unsigned int dst)
117 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
118 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
121 static void gen_op_load_fpr_DT0(unsigned int src)
123 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
124 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
125 offsetof(CPU_DoubleU, l.upper));
126 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
127 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
128 offsetof(CPU_DoubleU, l.lower));
131 static void gen_op_load_fpr_DT1(unsigned int src)
133 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
134 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
135 offsetof(CPU_DoubleU, l.upper));
136 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
137 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) +
138 offsetof(CPU_DoubleU, l.lower));
141 static void gen_op_store_DT0_fpr(unsigned int dst)
143 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
144 offsetof(CPU_DoubleU, l.upper));
145 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
146 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) +
147 offsetof(CPU_DoubleU, l.lower));
148 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
151 static void gen_op_load_fpr_QT0(unsigned int src)
153 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
154 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
155 offsetof(CPU_QuadU, l.upmost));
156 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
157 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
158 offsetof(CPU_QuadU, l.upper));
159 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
160 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
161 offsetof(CPU_QuadU, l.lower));
162 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
163 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
164 offsetof(CPU_QuadU, l.lowest));
167 static void gen_op_load_fpr_QT1(unsigned int src)
169 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
170 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
171 offsetof(CPU_QuadU, l.upmost));
172 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
173 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
174 offsetof(CPU_QuadU, l.upper));
175 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
176 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
177 offsetof(CPU_QuadU, l.lower));
178 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
179 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) +
180 offsetof(CPU_QuadU, l.lowest));
183 static void gen_op_store_QT0_fpr(unsigned int dst)
185 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
186 offsetof(CPU_QuadU, l.upmost));
187 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
188 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
189 offsetof(CPU_QuadU, l.upper));
190 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
191 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
192 offsetof(CPU_QuadU, l.lower));
193 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
194 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) +
195 offsetof(CPU_QuadU, l.lowest));
196 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
200 #ifdef CONFIG_USER_ONLY
201 #define supervisor(dc) 0
202 #ifdef TARGET_SPARC64
203 #define hypervisor(dc) 0
206 #define supervisor(dc) (dc->mem_idx >= 1)
207 #ifdef TARGET_SPARC64
208 #define hypervisor(dc) (dc->mem_idx == 2)
213 #ifdef TARGET_SPARC64
215 #define AM_CHECK(dc) ((dc)->address_mask_32bit)
217 #define AM_CHECK(dc) (1)
221 static inline void gen_address_mask(DisasContext *dc, TCGv addr)
223 #ifdef TARGET_SPARC64
225 tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
229 static inline void gen_movl_reg_TN(int reg, TCGv tn)
232 tcg_gen_movi_tl(tn, 0);
234 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
236 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
240 static inline void gen_movl_TN_reg(int reg, TCGv tn)
245 tcg_gen_mov_tl(cpu_gregs[reg], tn);
247 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
251 static inline void gen_goto_tb(DisasContext *s, int tb_num,
252 target_ulong pc, target_ulong npc)
254 TranslationBlock *tb;
257 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
258 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
259 /* jump to same page: we can use a direct jump */
260 tcg_gen_goto_tb(tb_num);
261 tcg_gen_movi_tl(cpu_pc, pc);
262 tcg_gen_movi_tl(cpu_npc, npc);
263 tcg_gen_exit_tb((long)tb + tb_num);
265 /* jump to another page: currently not optimized */
266 tcg_gen_movi_tl(cpu_pc, pc);
267 tcg_gen_movi_tl(cpu_npc, npc);
273 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
275 tcg_gen_extu_i32_tl(reg, src);
276 tcg_gen_shri_tl(reg, reg, PSR_NEG_SHIFT);
277 tcg_gen_andi_tl(reg, reg, 0x1);
280 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
282 tcg_gen_extu_i32_tl(reg, src);
283 tcg_gen_shri_tl(reg, reg, PSR_ZERO_SHIFT);
284 tcg_gen_andi_tl(reg, reg, 0x1);
287 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
289 tcg_gen_extu_i32_tl(reg, src);
290 tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
291 tcg_gen_andi_tl(reg, reg, 0x1);
294 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
296 tcg_gen_extu_i32_tl(reg, src);
297 tcg_gen_shri_tl(reg, reg, PSR_CARRY_SHIFT);
298 tcg_gen_andi_tl(reg, reg, 0x1);
301 static inline void gen_cc_clear_icc(void)
303 tcg_gen_movi_i32(cpu_psr, 0);
306 #ifdef TARGET_SPARC64
307 static inline void gen_cc_clear_xcc(void)
309 tcg_gen_movi_i32(cpu_xcc, 0);
315 env->psr |= PSR_ZERO;
316 if ((int32_t) T0 < 0)
319 static inline void gen_cc_NZ_icc(TCGv dst)
324 l1 = gen_new_label();
325 l2 = gen_new_label();
326 r_temp = tcg_temp_new(TCG_TYPE_TL);
327 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
328 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
329 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
331 tcg_gen_ext_i32_tl(r_temp, dst);
332 tcg_gen_brcondi_tl(TCG_COND_GE, r_temp, 0, l2);
333 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
335 tcg_temp_free(r_temp);
338 #ifdef TARGET_SPARC64
339 static inline void gen_cc_NZ_xcc(TCGv dst)
343 l1 = gen_new_label();
344 l2 = gen_new_label();
345 tcg_gen_brcondi_tl(TCG_COND_NE, dst, 0, l1);
346 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
348 tcg_gen_brcondi_tl(TCG_COND_GE, dst, 0, l2);
349 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
356 env->psr |= PSR_CARRY;
358 static inline void gen_cc_C_add_icc(TCGv dst, TCGv src1)
360 TCGv r_temp1, r_temp2;
363 l1 = gen_new_label();
364 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
365 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
366 tcg_gen_andi_tl(r_temp1, dst, 0xffffffffULL);
367 tcg_gen_andi_tl(r_temp2, src1, 0xffffffffULL);
368 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
369 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
371 tcg_temp_free(r_temp1);
372 tcg_temp_free(r_temp2);
375 #ifdef TARGET_SPARC64
376 static inline void gen_cc_C_add_xcc(TCGv dst, TCGv src1)
380 l1 = gen_new_label();
381 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
382 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
388 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
391 static inline void gen_cc_V_add_icc(TCGv dst, TCGv src1, TCGv src2)
395 r_temp = tcg_temp_new(TCG_TYPE_TL);
396 tcg_gen_xor_tl(r_temp, src1, src2);
397 tcg_gen_xori_tl(r_temp, r_temp, -1);
398 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
399 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
400 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
401 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
402 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
403 tcg_temp_free(r_temp);
404 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
407 #ifdef TARGET_SPARC64
408 static inline void gen_cc_V_add_xcc(TCGv dst, TCGv src1, TCGv src2)
412 r_temp = tcg_temp_new(TCG_TYPE_TL);
413 tcg_gen_xor_tl(r_temp, src1, src2);
414 tcg_gen_xori_tl(r_temp, r_temp, -1);
415 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
416 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
417 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
418 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
419 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
420 tcg_temp_free(r_temp);
421 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
425 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
427 TCGv r_temp, r_const;
430 l1 = gen_new_label();
432 r_temp = tcg_temp_new(TCG_TYPE_TL);
433 tcg_gen_xor_tl(r_temp, src1, src2);
434 tcg_gen_xori_tl(r_temp, r_temp, -1);
435 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
436 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
437 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
438 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
439 r_const = tcg_const_i32(TT_TOVF);
440 tcg_gen_helper_0_1(raise_exception, r_const);
441 tcg_temp_free(r_const);
443 tcg_temp_free(r_temp);
446 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
450 l1 = gen_new_label();
451 tcg_gen_or_tl(cpu_tmp0, src1, src2);
452 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
453 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
454 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
458 static inline void gen_tag_tv(TCGv src1, TCGv src2)
463 l1 = gen_new_label();
464 tcg_gen_or_tl(cpu_tmp0, src1, src2);
465 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
466 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
467 r_const = tcg_const_i32(TT_TOVF);
468 tcg_gen_helper_0_1(raise_exception, r_const);
469 tcg_temp_free(r_const);
473 static inline void gen_op_add_cc(TCGv dst, TCGv src1, TCGv src2)
475 tcg_gen_mov_tl(cpu_cc_src, src1);
476 tcg_gen_mov_tl(cpu_cc_src2, src2);
477 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
479 gen_cc_NZ_icc(cpu_cc_dst);
480 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
481 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
482 #ifdef TARGET_SPARC64
484 gen_cc_NZ_xcc(cpu_cc_dst);
485 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
486 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
488 tcg_gen_mov_tl(dst, cpu_cc_dst);
491 static inline void gen_op_addx_cc(TCGv dst, TCGv src1, TCGv src2)
493 tcg_gen_mov_tl(cpu_cc_src, src1);
494 tcg_gen_mov_tl(cpu_cc_src2, src2);
495 gen_mov_reg_C(cpu_tmp0, cpu_psr);
496 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
498 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
499 #ifdef TARGET_SPARC64
501 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
503 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
504 gen_cc_NZ_icc(cpu_cc_dst);
505 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
506 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
507 #ifdef TARGET_SPARC64
508 gen_cc_NZ_xcc(cpu_cc_dst);
509 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
510 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
512 tcg_gen_mov_tl(dst, cpu_cc_dst);
515 static inline void gen_op_tadd_cc(TCGv dst, TCGv src1, TCGv src2)
517 tcg_gen_mov_tl(cpu_cc_src, src1);
518 tcg_gen_mov_tl(cpu_cc_src2, src2);
519 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
521 gen_cc_NZ_icc(cpu_cc_dst);
522 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
523 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
524 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
525 #ifdef TARGET_SPARC64
527 gen_cc_NZ_xcc(cpu_cc_dst);
528 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
529 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
531 tcg_gen_mov_tl(dst, cpu_cc_dst);
534 static inline void gen_op_tadd_ccTV(TCGv dst, TCGv src1, TCGv src2)
536 tcg_gen_mov_tl(cpu_cc_src, src1);
537 tcg_gen_mov_tl(cpu_cc_src2, src2);
538 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
539 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
540 gen_add_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
542 gen_cc_NZ_icc(cpu_cc_dst);
543 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
544 #ifdef TARGET_SPARC64
546 gen_cc_NZ_xcc(cpu_cc_dst);
547 gen_cc_C_add_xcc(cpu_cc_dst, cpu_cc_src);
548 gen_cc_V_add_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
550 tcg_gen_mov_tl(dst, cpu_cc_dst);
555 env->psr |= PSR_CARRY;
557 static inline void gen_cc_C_sub_icc(TCGv src1, TCGv src2)
559 TCGv r_temp1, r_temp2;
562 l1 = gen_new_label();
563 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
564 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
565 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
566 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
567 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
568 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
570 tcg_temp_free(r_temp1);
571 tcg_temp_free(r_temp2);
574 #ifdef TARGET_SPARC64
575 static inline void gen_cc_C_sub_xcc(TCGv src1, TCGv src2)
579 l1 = gen_new_label();
580 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l1);
581 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
587 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
590 static inline void gen_cc_V_sub_icc(TCGv dst, TCGv src1, TCGv src2)
594 r_temp = tcg_temp_new(TCG_TYPE_TL);
595 tcg_gen_xor_tl(r_temp, src1, src2);
596 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
597 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
598 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
599 tcg_gen_shri_tl(r_temp, r_temp, 31 - PSR_OVF_SHIFT);
600 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
601 tcg_gen_or_i32(cpu_psr, cpu_psr, cpu_tmp32);
602 tcg_temp_free(r_temp);
605 #ifdef TARGET_SPARC64
606 static inline void gen_cc_V_sub_xcc(TCGv dst, TCGv src1, TCGv src2)
610 r_temp = tcg_temp_new(TCG_TYPE_TL);
611 tcg_gen_xor_tl(r_temp, src1, src2);
612 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
613 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
614 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
615 tcg_gen_shri_tl(r_temp, r_temp, 63 - PSR_OVF_SHIFT);
616 tcg_gen_trunc_tl_i32(cpu_tmp32, r_temp);
617 tcg_gen_or_i32(cpu_xcc, cpu_xcc, cpu_tmp32);
618 tcg_temp_free(r_temp);
622 static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
624 TCGv r_temp, r_const;
627 l1 = gen_new_label();
629 r_temp = tcg_temp_new(TCG_TYPE_TL);
630 tcg_gen_xor_tl(r_temp, src1, src2);
631 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
632 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
633 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 31));
634 tcg_gen_brcondi_tl(TCG_COND_EQ, r_temp, 0, l1);
635 r_const = tcg_const_i32(TT_TOVF);
636 tcg_gen_helper_0_1(raise_exception, r_const);
637 tcg_temp_free(r_const);
639 tcg_temp_free(r_temp);
642 static inline void gen_op_sub_cc(TCGv dst, TCGv src1, TCGv src2)
644 tcg_gen_mov_tl(cpu_cc_src, src1);
645 tcg_gen_mov_tl(cpu_cc_src2, src2);
646 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
648 gen_cc_NZ_icc(cpu_cc_dst);
649 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
650 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
651 #ifdef TARGET_SPARC64
653 gen_cc_NZ_xcc(cpu_cc_dst);
654 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
655 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
657 tcg_gen_mov_tl(dst, cpu_cc_dst);
660 static inline void gen_op_subx_cc(TCGv dst, TCGv src1, TCGv src2)
662 tcg_gen_mov_tl(cpu_cc_src, src1);
663 tcg_gen_mov_tl(cpu_cc_src2, src2);
664 gen_mov_reg_C(cpu_tmp0, cpu_psr);
665 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_tmp0);
667 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
668 #ifdef TARGET_SPARC64
670 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
672 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_dst, cpu_cc_src2);
673 gen_cc_NZ_icc(cpu_cc_dst);
674 gen_cc_C_sub_icc(cpu_cc_dst, cpu_cc_src);
675 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
676 #ifdef TARGET_SPARC64
677 gen_cc_NZ_xcc(cpu_cc_dst);
678 gen_cc_C_sub_xcc(cpu_cc_dst, cpu_cc_src);
679 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
681 tcg_gen_mov_tl(dst, cpu_cc_dst);
684 static inline void gen_op_tsub_cc(TCGv dst, TCGv src1, TCGv src2)
686 tcg_gen_mov_tl(cpu_cc_src, src1);
687 tcg_gen_mov_tl(cpu_cc_src2, src2);
688 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
690 gen_cc_NZ_icc(cpu_cc_dst);
691 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
692 gen_cc_V_sub_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
693 gen_cc_V_tag(cpu_cc_src, cpu_cc_src2);
694 #ifdef TARGET_SPARC64
696 gen_cc_NZ_xcc(cpu_cc_dst);
697 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
698 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
700 tcg_gen_mov_tl(dst, cpu_cc_dst);
703 static inline void gen_op_tsub_ccTV(TCGv dst, TCGv src1, TCGv src2)
705 tcg_gen_mov_tl(cpu_cc_src, src1);
706 tcg_gen_mov_tl(cpu_cc_src2, src2);
707 gen_tag_tv(cpu_cc_src, cpu_cc_src2);
708 tcg_gen_sub_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
709 gen_sub_tv(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
711 gen_cc_NZ_icc(cpu_cc_dst);
712 gen_cc_C_sub_icc(cpu_cc_src, cpu_cc_src2);
713 #ifdef TARGET_SPARC64
715 gen_cc_NZ_xcc(cpu_cc_dst);
716 gen_cc_C_sub_xcc(cpu_cc_src, cpu_cc_src2);
717 gen_cc_V_sub_xcc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
719 tcg_gen_mov_tl(dst, cpu_cc_dst);
722 static inline void gen_op_mulscc(TCGv dst, TCGv src1, TCGv src2)
727 l1 = gen_new_label();
728 r_temp = tcg_temp_new(TCG_TYPE_TL);
734 tcg_gen_mov_tl(cpu_cc_src, src1);
735 tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
736 tcg_gen_mov_tl(cpu_cc_src2, src2);
737 tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
738 tcg_gen_movi_tl(cpu_cc_src2, 0);
742 // env->y = (b2 << 31) | (env->y >> 1);
743 tcg_gen_andi_tl(r_temp, cpu_cc_src, 0x1);
744 tcg_gen_shli_tl(r_temp, r_temp, 31);
745 tcg_gen_shri_tl(cpu_tmp0, cpu_y, 1);
746 tcg_gen_or_tl(cpu_y, cpu_tmp0, r_temp);
749 gen_mov_reg_N(cpu_tmp0, cpu_psr);
750 gen_mov_reg_V(r_temp, cpu_psr);
751 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
752 tcg_temp_free(r_temp);
754 // T0 = (b1 << 31) | (T0 >> 1);
756 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
757 tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
758 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
760 /* do addition and update flags */
761 tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
764 gen_cc_NZ_icc(cpu_cc_dst);
765 gen_cc_V_add_icc(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
766 gen_cc_C_add_icc(cpu_cc_dst, cpu_cc_src);
767 tcg_gen_mov_tl(dst, cpu_cc_dst);
770 static inline void gen_op_umul(TCGv dst, TCGv src1, TCGv src2)
772 TCGv r_temp, r_temp2;
774 r_temp = tcg_temp_new(TCG_TYPE_I64);
775 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
777 tcg_gen_extu_i32_i64(r_temp, src2);
778 tcg_gen_extu_i32_i64(r_temp2, src1);
779 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
781 tcg_gen_shri_i64(r_temp, r_temp2, 32);
782 tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
783 tcg_temp_free(r_temp);
784 tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
785 #ifdef TARGET_SPARC64
786 tcg_gen_mov_i64(dst, r_temp2);
788 tcg_gen_trunc_i64_tl(dst, r_temp2);
790 tcg_temp_free(r_temp2);
793 static inline void gen_op_smul(TCGv dst, TCGv src1, TCGv src2)
795 TCGv r_temp, r_temp2;
797 r_temp = tcg_temp_new(TCG_TYPE_I64);
798 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
800 tcg_gen_ext_i32_i64(r_temp, src2);
801 tcg_gen_ext_i32_i64(r_temp2, src1);
802 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
804 tcg_gen_shri_i64(r_temp, r_temp2, 32);
805 tcg_gen_trunc_i64_tl(cpu_tmp0, r_temp);
806 tcg_temp_free(r_temp);
807 tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
808 #ifdef TARGET_SPARC64
809 tcg_gen_mov_i64(dst, r_temp2);
811 tcg_gen_trunc_i64_tl(dst, r_temp2);
813 tcg_temp_free(r_temp2);
816 #ifdef TARGET_SPARC64
817 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
822 l1 = gen_new_label();
823 tcg_gen_brcondi_tl(TCG_COND_NE, divisor, 0, l1);
824 r_const = tcg_const_i32(TT_DIV_ZERO);
825 tcg_gen_helper_0_1(raise_exception, r_const);
826 tcg_temp_free(r_const);
830 static inline void gen_op_sdivx(TCGv dst, TCGv src1, TCGv src2)
834 l1 = gen_new_label();
835 l2 = gen_new_label();
836 tcg_gen_mov_tl(cpu_cc_src, src1);
837 tcg_gen_mov_tl(cpu_cc_src2, src2);
838 gen_trap_ifdivzero_tl(cpu_cc_src2);
839 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src, INT64_MIN, l1);
840 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_cc_src2, -1, l1);
841 tcg_gen_movi_i64(dst, INT64_MIN);
844 tcg_gen_div_i64(dst, cpu_cc_src, cpu_cc_src2);
849 static inline void gen_op_div_cc(TCGv dst)
853 tcg_gen_mov_tl(cpu_cc_dst, dst);
855 gen_cc_NZ_icc(cpu_cc_dst);
856 l1 = gen_new_label();
857 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_src2, 0, l1);
858 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
862 static inline void gen_op_logic_cc(TCGv dst)
864 tcg_gen_mov_tl(cpu_cc_dst, dst);
867 gen_cc_NZ_icc(cpu_cc_dst);
868 #ifdef TARGET_SPARC64
870 gen_cc_NZ_xcc(cpu_cc_dst);
875 static inline void gen_op_eval_ba(TCGv dst)
877 tcg_gen_movi_tl(dst, 1);
881 static inline void gen_op_eval_be(TCGv dst, TCGv src)
883 gen_mov_reg_Z(dst, src);
887 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
889 gen_mov_reg_N(cpu_tmp0, src);
890 gen_mov_reg_V(dst, src);
891 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
892 gen_mov_reg_Z(cpu_tmp0, src);
893 tcg_gen_or_tl(dst, dst, cpu_tmp0);
897 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
899 gen_mov_reg_V(cpu_tmp0, src);
900 gen_mov_reg_N(dst, src);
901 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
905 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
907 gen_mov_reg_Z(cpu_tmp0, src);
908 gen_mov_reg_C(dst, src);
909 tcg_gen_or_tl(dst, dst, cpu_tmp0);
913 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
915 gen_mov_reg_C(dst, src);
919 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
921 gen_mov_reg_V(dst, src);
925 static inline void gen_op_eval_bn(TCGv dst)
927 tcg_gen_movi_tl(dst, 0);
931 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
933 gen_mov_reg_N(dst, src);
937 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
939 gen_mov_reg_Z(dst, src);
940 tcg_gen_xori_tl(dst, dst, 0x1);
944 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
946 gen_mov_reg_N(cpu_tmp0, src);
947 gen_mov_reg_V(dst, src);
948 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
949 gen_mov_reg_Z(cpu_tmp0, src);
950 tcg_gen_or_tl(dst, dst, cpu_tmp0);
951 tcg_gen_xori_tl(dst, dst, 0x1);
955 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
957 gen_mov_reg_V(cpu_tmp0, src);
958 gen_mov_reg_N(dst, src);
959 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
960 tcg_gen_xori_tl(dst, dst, 0x1);
964 static inline void gen_op_eval_bgu(TCGv dst, TCGv src)
966 gen_mov_reg_Z(cpu_tmp0, src);
967 gen_mov_reg_C(dst, src);
968 tcg_gen_or_tl(dst, dst, cpu_tmp0);
969 tcg_gen_xori_tl(dst, dst, 0x1);
973 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
975 gen_mov_reg_C(dst, src);
976 tcg_gen_xori_tl(dst, dst, 0x1);
980 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
982 gen_mov_reg_N(dst, src);
983 tcg_gen_xori_tl(dst, dst, 0x1);
987 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
989 gen_mov_reg_V(dst, src);
990 tcg_gen_xori_tl(dst, dst, 0x1);
994 FPSR bit field FCC1 | FCC0:
1000 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
1001 unsigned int fcc_offset)
1003 tcg_gen_shri_tl(reg, src, FSR_FCC0_SHIFT + fcc_offset);
1004 tcg_gen_andi_tl(reg, reg, 0x1);
1007 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
1008 unsigned int fcc_offset)
1010 tcg_gen_shri_tl(reg, src, FSR_FCC1_SHIFT + fcc_offset);
1011 tcg_gen_andi_tl(reg, reg, 0x1);
1015 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
1016 unsigned int fcc_offset)
1018 gen_mov_reg_FCC0(dst, src, fcc_offset);
1019 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1020 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1023 // 1 or 2: FCC0 ^ FCC1
1024 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
1025 unsigned int fcc_offset)
1027 gen_mov_reg_FCC0(dst, src, fcc_offset);
1028 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1029 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1033 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
1034 unsigned int fcc_offset)
1036 gen_mov_reg_FCC0(dst, src, fcc_offset);
1040 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
1041 unsigned int fcc_offset)
1043 gen_mov_reg_FCC0(dst, src, fcc_offset);
1044 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1045 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1046 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1050 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
1051 unsigned int fcc_offset)
1053 gen_mov_reg_FCC1(dst, src, fcc_offset);
1057 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1058 unsigned int fcc_offset)
1060 gen_mov_reg_FCC0(dst, src, fcc_offset);
1061 tcg_gen_xori_tl(dst, dst, 0x1);
1062 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1063 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1067 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1068 unsigned int fcc_offset)
1070 gen_mov_reg_FCC0(dst, src, fcc_offset);
1071 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1072 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1075 // 0: !(FCC0 | FCC1)
1076 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1077 unsigned int fcc_offset)
1079 gen_mov_reg_FCC0(dst, src, fcc_offset);
1080 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1081 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1082 tcg_gen_xori_tl(dst, dst, 0x1);
1085 // 0 or 3: !(FCC0 ^ FCC1)
1086 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1087 unsigned int fcc_offset)
1089 gen_mov_reg_FCC0(dst, src, fcc_offset);
1090 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1091 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1092 tcg_gen_xori_tl(dst, dst, 0x1);
1096 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1097 unsigned int fcc_offset)
1099 gen_mov_reg_FCC0(dst, src, fcc_offset);
1100 tcg_gen_xori_tl(dst, dst, 0x1);
1103 // !1: !(FCC0 & !FCC1)
1104 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1105 unsigned int fcc_offset)
1107 gen_mov_reg_FCC0(dst, src, fcc_offset);
1108 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1109 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1110 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1111 tcg_gen_xori_tl(dst, dst, 0x1);
1115 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1116 unsigned int fcc_offset)
1118 gen_mov_reg_FCC1(dst, src, fcc_offset);
1119 tcg_gen_xori_tl(dst, dst, 0x1);
1122 // !2: !(!FCC0 & FCC1)
1123 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1124 unsigned int fcc_offset)
1126 gen_mov_reg_FCC0(dst, src, fcc_offset);
1127 tcg_gen_xori_tl(dst, dst, 0x1);
1128 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1129 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1130 tcg_gen_xori_tl(dst, dst, 0x1);
1133 // !3: !(FCC0 & FCC1)
1134 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1135 unsigned int fcc_offset)
1137 gen_mov_reg_FCC0(dst, src, fcc_offset);
1138 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1139 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1140 tcg_gen_xori_tl(dst, dst, 0x1);
1143 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1144 target_ulong pc2, TCGv r_cond)
1148 l1 = gen_new_label();
1150 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1152 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1155 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1158 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1159 target_ulong pc2, TCGv r_cond)
1163 l1 = gen_new_label();
1165 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1167 gen_goto_tb(dc, 0, pc2, pc1);
1170 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1173 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1178 l1 = gen_new_label();
1179 l2 = gen_new_label();
1181 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
1183 tcg_gen_movi_tl(cpu_npc, npc1);
1187 tcg_gen_movi_tl(cpu_npc, npc2);
1191 /* call this function before using the condition register as it may
1192 have been set for a jump */
1193 static inline void flush_cond(DisasContext *dc, TCGv cond)
1195 if (dc->npc == JUMP_PC) {
1196 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1197 dc->npc = DYNAMIC_PC;
1201 static inline void save_npc(DisasContext *dc, TCGv cond)
1203 if (dc->npc == JUMP_PC) {
1204 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1205 dc->npc = DYNAMIC_PC;
1206 } else if (dc->npc != DYNAMIC_PC) {
1207 tcg_gen_movi_tl(cpu_npc, dc->npc);
1211 static inline void save_state(DisasContext *dc, TCGv cond)
1213 tcg_gen_movi_tl(cpu_pc, dc->pc);
1217 static inline void gen_mov_pc_npc(DisasContext *dc, TCGv cond)
1219 if (dc->npc == JUMP_PC) {
1220 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cond);
1221 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1222 dc->pc = DYNAMIC_PC;
1223 } else if (dc->npc == DYNAMIC_PC) {
1224 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1225 dc->pc = DYNAMIC_PC;
1231 static inline void gen_op_next_insn(void)
1233 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1234 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1237 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1241 #ifdef TARGET_SPARC64
1251 gen_op_eval_bn(r_dst);
1254 gen_op_eval_be(r_dst, r_src);
1257 gen_op_eval_ble(r_dst, r_src);
1260 gen_op_eval_bl(r_dst, r_src);
1263 gen_op_eval_bleu(r_dst, r_src);
1266 gen_op_eval_bcs(r_dst, r_src);
1269 gen_op_eval_bneg(r_dst, r_src);
1272 gen_op_eval_bvs(r_dst, r_src);
1275 gen_op_eval_ba(r_dst);
1278 gen_op_eval_bne(r_dst, r_src);
1281 gen_op_eval_bg(r_dst, r_src);
1284 gen_op_eval_bge(r_dst, r_src);
1287 gen_op_eval_bgu(r_dst, r_src);
1290 gen_op_eval_bcc(r_dst, r_src);
1293 gen_op_eval_bpos(r_dst, r_src);
1296 gen_op_eval_bvc(r_dst, r_src);
1301 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1303 unsigned int offset;
1323 gen_op_eval_bn(r_dst);
1326 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1329 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1332 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1335 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1338 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1341 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1344 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1347 gen_op_eval_ba(r_dst);
1350 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1353 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1356 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1359 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1362 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1365 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1368 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1373 #ifdef TARGET_SPARC64
1375 static const int gen_tcg_cond_reg[8] = {
1386 static inline void gen_cond_reg(TCGv r_dst, int cond, TCGv r_src)
1390 l1 = gen_new_label();
1391 tcg_gen_movi_tl(r_dst, 0);
1392 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], r_src, 0, l1);
1393 tcg_gen_movi_tl(r_dst, 1);
1398 /* XXX: potentially incorrect if dynamic npc */
1399 static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1402 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1403 target_ulong target = dc->pc + offset;
1406 /* unconditional not taken */
1408 dc->pc = dc->npc + 4;
1409 dc->npc = dc->pc + 4;
1412 dc->npc = dc->pc + 4;
1414 } else if (cond == 0x8) {
1415 /* unconditional taken */
1418 dc->npc = dc->pc + 4;
1424 flush_cond(dc, r_cond);
1425 gen_cond(r_cond, cc, cond);
1427 gen_branch_a(dc, target, dc->npc, r_cond);
1431 dc->jump_pc[0] = target;
1432 dc->jump_pc[1] = dc->npc + 4;
1438 /* XXX: potentially incorrect if dynamic npc */
1439 static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc,
1442 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1443 target_ulong target = dc->pc + offset;
1446 /* unconditional not taken */
1448 dc->pc = dc->npc + 4;
1449 dc->npc = dc->pc + 4;
1452 dc->npc = dc->pc + 4;
1454 } else if (cond == 0x8) {
1455 /* unconditional taken */
1458 dc->npc = dc->pc + 4;
1464 flush_cond(dc, r_cond);
1465 gen_fcond(r_cond, cc, cond);
1467 gen_branch_a(dc, target, dc->npc, r_cond);
1471 dc->jump_pc[0] = target;
1472 dc->jump_pc[1] = dc->npc + 4;
1478 #ifdef TARGET_SPARC64
1479 /* XXX: potentially incorrect if dynamic npc */
1480 static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,
1481 TCGv r_cond, TCGv r_reg)
1483 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1484 target_ulong target = dc->pc + offset;
1486 flush_cond(dc, r_cond);
1487 gen_cond_reg(r_cond, cond, r_reg);
1489 gen_branch_a(dc, target, dc->npc, r_cond);
1493 dc->jump_pc[0] = target;
1494 dc->jump_pc[1] = dc->npc + 4;
1499 static GenOpFunc * const gen_fcmps[4] = {
1506 static GenOpFunc * const gen_fcmpd[4] = {
1513 static GenOpFunc * const gen_fcmpq[4] = {
1520 static GenOpFunc * const gen_fcmpes[4] = {
1527 static GenOpFunc * const gen_fcmped[4] = {
1534 static GenOpFunc * const gen_fcmpeq[4] = {
1541 static inline void gen_op_fcmps(int fccno)
1543 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1546 static inline void gen_op_fcmpd(int fccno)
1548 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1551 static inline void gen_op_fcmpq(int fccno)
1553 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1556 static inline void gen_op_fcmpes(int fccno)
1558 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1561 static inline void gen_op_fcmped(int fccno)
1563 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1566 static inline void gen_op_fcmpeq(int fccno)
1568 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1573 static inline void gen_op_fcmps(int fccno)
1575 tcg_gen_helper_0_0(helper_fcmps);
1578 static inline void gen_op_fcmpd(int fccno)
1580 tcg_gen_helper_0_0(helper_fcmpd);
1583 static inline void gen_op_fcmpq(int fccno)
1585 tcg_gen_helper_0_0(helper_fcmpq);
1588 static inline void gen_op_fcmpes(int fccno)
1590 tcg_gen_helper_0_0(helper_fcmpes);
1593 static inline void gen_op_fcmped(int fccno)
1595 tcg_gen_helper_0_0(helper_fcmped);
1598 static inline void gen_op_fcmpeq(int fccno)
1600 tcg_gen_helper_0_0(helper_fcmpeq);
1604 static inline void gen_op_fpexception_im(int fsr_flags)
1608 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_NMASK);
1609 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1610 r_const = tcg_const_i32(TT_FP_EXCP);
1611 tcg_gen_helper_0_1(raise_exception, r_const);
1612 tcg_temp_free(r_const);
1615 static int gen_trap_ifnofpu(DisasContext *dc, TCGv r_cond)
1617 #if !defined(CONFIG_USER_ONLY)
1618 if (!dc->fpu_enabled) {
1621 save_state(dc, r_cond);
1622 r_const = tcg_const_i32(TT_NFPU_INSN);
1623 tcg_gen_helper_0_1(raise_exception, r_const);
1624 tcg_temp_free(r_const);
1632 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1634 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, FSR_FTT_CEXC_NMASK);
1637 static inline void gen_clear_float_exceptions(void)
1639 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1643 #ifdef TARGET_SPARC64
1644 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1650 r_asi = tcg_temp_new(TCG_TYPE_I32);
1651 tcg_gen_mov_i32(r_asi, cpu_asi);
1653 asi = GET_FIELD(insn, 19, 26);
1654 r_asi = tcg_const_i32(asi);
1659 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1662 TCGv r_asi, r_size, r_sign;
1664 r_asi = gen_get_asi(insn, addr);
1665 r_size = tcg_const_i32(size);
1666 r_sign = tcg_const_i32(sign);
1667 tcg_gen_helper_1_4(helper_ld_asi, dst, addr, r_asi, r_size, r_sign);
1668 tcg_temp_free(r_sign);
1669 tcg_temp_free(r_size);
1670 tcg_temp_free(r_asi);
1673 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1677 r_asi = gen_get_asi(insn, addr);
1678 r_size = tcg_const_i32(size);
1679 tcg_gen_helper_0_4(helper_st_asi, addr, src, r_asi, r_size);
1680 tcg_temp_free(r_size);
1681 tcg_temp_free(r_asi);
1684 static inline void gen_ldf_asi(TCGv addr, int insn, int size, int rd)
1686 TCGv r_asi, r_size, r_rd;
1688 r_asi = gen_get_asi(insn, addr);
1689 r_size = tcg_const_i32(size);
1690 r_rd = tcg_const_i32(rd);
1691 tcg_gen_helper_0_4(helper_ldf_asi, addr, r_asi, r_size, r_rd);
1692 tcg_temp_free(r_rd);
1693 tcg_temp_free(r_size);
1694 tcg_temp_free(r_asi);
1697 static inline void gen_stf_asi(TCGv addr, int insn, int size, int rd)
1699 TCGv r_asi, r_size, r_rd;
1701 r_asi = gen_get_asi(insn, addr);
1702 r_size = tcg_const_i32(size);
1703 r_rd = tcg_const_i32(rd);
1704 tcg_gen_helper_0_4(helper_stf_asi, addr, r_asi, r_size, r_rd);
1705 tcg_temp_free(r_rd);
1706 tcg_temp_free(r_size);
1707 tcg_temp_free(r_asi);
1710 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1712 TCGv r_asi, r_size, r_sign;
1714 r_asi = gen_get_asi(insn, addr);
1715 r_size = tcg_const_i32(4);
1716 r_sign = tcg_const_i32(0);
1717 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1718 tcg_temp_free(r_sign);
1719 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1720 tcg_temp_free(r_size);
1721 tcg_temp_free(r_asi);
1722 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1725 static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
1729 r_asi = gen_get_asi(insn, addr);
1730 r_rd = tcg_const_i32(rd);
1731 tcg_gen_helper_0_3(helper_ldda_asi, addr, r_asi, r_rd);
1732 tcg_temp_free(r_rd);
1733 tcg_temp_free(r_asi);
1736 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1738 TCGv r_temp, r_asi, r_size;
1740 r_temp = tcg_temp_new(TCG_TYPE_TL);
1741 gen_movl_reg_TN(rd + 1, r_temp);
1742 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
1744 tcg_temp_free(r_temp);
1745 r_asi = gen_get_asi(insn, addr);
1746 r_size = tcg_const_i32(8);
1747 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1748 tcg_temp_free(r_size);
1749 tcg_temp_free(r_asi);
1752 static inline void gen_cas_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1757 r_val1 = tcg_temp_new(TCG_TYPE_TL);
1758 gen_movl_reg_TN(rd, r_val1);
1759 r_asi = gen_get_asi(insn, addr);
1760 tcg_gen_helper_1_4(helper_cas_asi, dst, addr, r_val1, val2, r_asi);
1761 tcg_temp_free(r_asi);
1762 tcg_temp_free(r_val1);
1765 static inline void gen_casx_asi(TCGv dst, TCGv addr, TCGv val2, int insn,
1770 gen_movl_reg_TN(rd, cpu_tmp64);
1771 r_asi = gen_get_asi(insn, addr);
1772 tcg_gen_helper_1_4(helper_casx_asi, dst, addr, cpu_tmp64, val2, r_asi);
1773 tcg_temp_free(r_asi);
1776 #elif !defined(CONFIG_USER_ONLY)
1778 static inline void gen_ld_asi(TCGv dst, TCGv addr, int insn, int size,
1781 TCGv r_asi, r_size, r_sign;
1783 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1784 r_size = tcg_const_i32(size);
1785 r_sign = tcg_const_i32(sign);
1786 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1787 tcg_temp_free(r_sign);
1788 tcg_temp_free(r_size);
1789 tcg_temp_free(r_asi);
1790 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1793 static inline void gen_st_asi(TCGv src, TCGv addr, int insn, int size)
1797 tcg_gen_extu_tl_i64(cpu_tmp64, src);
1798 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1799 r_size = tcg_const_i32(size);
1800 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1801 tcg_temp_free(r_size);
1802 tcg_temp_free(r_asi);
1805 static inline void gen_swap_asi(TCGv dst, TCGv addr, int insn)
1807 TCGv r_asi, r_size, r_sign;
1809 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1810 r_size = tcg_const_i32(4);
1811 r_sign = tcg_const_i32(0);
1812 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1813 tcg_temp_free(r_sign);
1814 tcg_gen_helper_0_4(helper_st_asi, addr, dst, r_asi, r_size);
1815 tcg_temp_free(r_size);
1816 tcg_temp_free(r_asi);
1817 tcg_gen_trunc_i64_tl(dst, cpu_tmp64);
1820 static inline void gen_ldda_asi(TCGv hi, TCGv addr, int insn, int rd)
1822 TCGv r_asi, r_size, r_sign;
1824 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1825 r_size = tcg_const_i32(8);
1826 r_sign = tcg_const_i32(0);
1827 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, addr, r_asi, r_size, r_sign);
1828 tcg_temp_free(r_sign);
1829 tcg_temp_free(r_size);
1830 tcg_temp_free(r_asi);
1831 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
1832 gen_movl_TN_reg(rd + 1, cpu_tmp0);
1833 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1834 tcg_gen_trunc_i64_tl(hi, cpu_tmp64);
1835 gen_movl_TN_reg(rd, hi);
1838 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
1840 TCGv r_temp, r_asi, r_size;
1842 r_temp = tcg_temp_new(TCG_TYPE_TL);
1843 gen_movl_reg_TN(rd + 1, r_temp);
1844 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
1845 tcg_temp_free(r_temp);
1846 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1847 r_size = tcg_const_i32(8);
1848 tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
1849 tcg_temp_free(r_size);
1850 tcg_temp_free(r_asi);
1854 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1855 static inline void gen_ldstub_asi(TCGv dst, TCGv addr, int insn)
1857 TCGv r_val, r_asi, r_size;
1859 gen_ld_asi(dst, addr, insn, 1, 0);
1861 r_val = tcg_const_i64(0xffULL);
1862 r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
1863 r_size = tcg_const_i32(1);
1864 tcg_gen_helper_0_4(helper_st_asi, addr, r_val, r_asi, r_size);
1865 tcg_temp_free(r_size);
1866 tcg_temp_free(r_asi);
1867 tcg_temp_free(r_val);
1871 static inline TCGv get_src1(unsigned int insn, TCGv def)
1876 rs1 = GET_FIELD(insn, 13, 17);
1878 r_rs1 = tcg_const_tl(0); // XXX how to free?
1880 r_rs1 = cpu_gregs[rs1];
1882 tcg_gen_ld_tl(def, cpu_regwptr, (rs1 - 8) * sizeof(target_ulong));
1886 static inline TCGv get_src2(unsigned int insn, TCGv def)
1891 if (IS_IMM) { /* immediate */
1892 rs2 = GET_FIELDs(insn, 19, 31);
1893 r_rs2 = tcg_const_tl((int)rs2); // XXX how to free?
1894 } else { /* register */
1895 rs2 = GET_FIELD(insn, 27, 31);
1897 r_rs2 = tcg_const_tl(0); // XXX how to free?
1899 r_rs2 = cpu_gregs[rs2];
1901 tcg_gen_ld_tl(def, cpu_regwptr, (rs2 - 8) * sizeof(target_ulong));
1906 #define CHECK_IU_FEATURE(dc, FEATURE) \
1907 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
1909 #define CHECK_FPU_FEATURE(dc, FEATURE) \
1910 if (!((dc)->def->features & CPU_FEATURE_ ## FEATURE)) \
1913 /* before an instruction, dc->pc must be static */
1914 static void disas_sparc_insn(DisasContext * dc)
1916 unsigned int insn, opc, rs1, rs2, rd;
1918 if (unlikely(loglevel & CPU_LOG_TB_OP))
1919 tcg_gen_debug_insn_start(dc->pc);
1920 insn = ldl_code(dc->pc);
1921 opc = GET_FIELD(insn, 0, 1);
1923 rd = GET_FIELD(insn, 2, 6);
1925 cpu_src1 = tcg_temp_new(TCG_TYPE_TL); // const
1926 cpu_src2 = tcg_temp_new(TCG_TYPE_TL); // const
1929 case 0: /* branches/sethi */
1931 unsigned int xop = GET_FIELD(insn, 7, 9);
1934 #ifdef TARGET_SPARC64
1935 case 0x1: /* V9 BPcc */
1939 target = GET_FIELD_SP(insn, 0, 18);
1940 target = sign_extend(target, 18);
1942 cc = GET_FIELD_SP(insn, 20, 21);
1944 do_branch(dc, target, insn, 0, cpu_cond);
1946 do_branch(dc, target, insn, 1, cpu_cond);
1951 case 0x3: /* V9 BPr */
1953 target = GET_FIELD_SP(insn, 0, 13) |
1954 (GET_FIELD_SP(insn, 20, 21) << 14);
1955 target = sign_extend(target, 16);
1957 cpu_src1 = get_src1(insn, cpu_src1);
1958 do_branch_reg(dc, target, insn, cpu_cond, cpu_src1);
1961 case 0x5: /* V9 FBPcc */
1963 int cc = GET_FIELD_SP(insn, 20, 21);
1964 if (gen_trap_ifnofpu(dc, cpu_cond))
1966 target = GET_FIELD_SP(insn, 0, 18);
1967 target = sign_extend(target, 19);
1969 do_fbranch(dc, target, insn, cc, cpu_cond);
1973 case 0x7: /* CBN+x */
1978 case 0x2: /* BN+x */
1980 target = GET_FIELD(insn, 10, 31);
1981 target = sign_extend(target, 22);
1983 do_branch(dc, target, insn, 0, cpu_cond);
1986 case 0x6: /* FBN+x */
1988 if (gen_trap_ifnofpu(dc, cpu_cond))
1990 target = GET_FIELD(insn, 10, 31);
1991 target = sign_extend(target, 22);
1993 do_fbranch(dc, target, insn, 0, cpu_cond);
1996 case 0x4: /* SETHI */
1998 uint32_t value = GET_FIELD(insn, 10, 31);
2001 r_const = tcg_const_tl(value << 10);
2002 gen_movl_TN_reg(rd, r_const);
2003 tcg_temp_free(r_const);
2006 case 0x0: /* UNIMPL */
2015 target_long target = GET_FIELDs(insn, 2, 31) << 2;
2018 r_const = tcg_const_tl(dc->pc);
2019 gen_movl_TN_reg(15, r_const);
2020 tcg_temp_free(r_const);
2022 gen_mov_pc_npc(dc, cpu_cond);
2026 case 2: /* FPU & Logical Operations */
2028 unsigned int xop = GET_FIELD(insn, 7, 12);
2029 if (xop == 0x3a) { /* generate trap */
2032 cpu_src1 = get_src1(insn, cpu_src1);
2034 rs2 = GET_FIELD(insn, 25, 31);
2035 tcg_gen_addi_tl(cpu_dst, cpu_src1, rs2);
2037 rs2 = GET_FIELD(insn, 27, 31);
2039 gen_movl_reg_TN(rs2, cpu_src2);
2040 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2042 tcg_gen_mov_tl(cpu_dst, cpu_src1);
2044 cond = GET_FIELD(insn, 3, 6);
2046 save_state(dc, cpu_cond);
2047 tcg_gen_helper_0_1(helper_trap, cpu_dst);
2048 } else if (cond != 0) {
2049 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
2050 #ifdef TARGET_SPARC64
2052 int cc = GET_FIELD_SP(insn, 11, 12);
2054 save_state(dc, cpu_cond);
2056 gen_cond(r_cond, 0, cond);
2058 gen_cond(r_cond, 1, cond);
2062 save_state(dc, cpu_cond);
2063 gen_cond(r_cond, 0, cond);
2065 tcg_gen_helper_0_2(helper_trapcc, cpu_dst, r_cond);
2066 tcg_temp_free(r_cond);
2072 } else if (xop == 0x28) {
2073 rs1 = GET_FIELD(insn, 13, 17);
2076 #ifndef TARGET_SPARC64
2077 case 0x01 ... 0x0e: /* undefined in the SPARCv8
2078 manual, rdy on the microSPARC
2080 case 0x0f: /* stbar in the SPARCv8 manual,
2081 rdy on the microSPARC II */
2082 case 0x10 ... 0x1f: /* implementation-dependent in the
2083 SPARCv8 manual, rdy on the
2086 gen_movl_TN_reg(rd, cpu_y);
2088 #ifdef TARGET_SPARC64
2089 case 0x2: /* V9 rdccr */
2090 tcg_gen_helper_1_0(helper_rdccr, cpu_dst);
2091 gen_movl_TN_reg(rd, cpu_dst);
2093 case 0x3: /* V9 rdasi */
2094 tcg_gen_ext_i32_tl(cpu_dst, cpu_asi);
2095 gen_movl_TN_reg(rd, cpu_dst);
2097 case 0x4: /* V9 rdtick */
2101 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2102 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2103 offsetof(CPUState, tick));
2104 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2106 tcg_temp_free(r_tickptr);
2107 gen_movl_TN_reg(rd, cpu_dst);
2110 case 0x5: /* V9 rdpc */
2114 r_const = tcg_const_tl(dc->pc);
2115 gen_movl_TN_reg(rd, r_const);
2116 tcg_temp_free(r_const);
2119 case 0x6: /* V9 rdfprs */
2120 tcg_gen_ext_i32_tl(cpu_dst, cpu_fprs);
2121 gen_movl_TN_reg(rd, cpu_dst);
2123 case 0xf: /* V9 membar */
2124 break; /* no effect */
2125 case 0x13: /* Graphics Status */
2126 if (gen_trap_ifnofpu(dc, cpu_cond))
2128 gen_movl_TN_reg(rd, cpu_gsr);
2130 case 0x17: /* Tick compare */
2131 gen_movl_TN_reg(rd, cpu_tick_cmpr);
2133 case 0x18: /* System tick */
2137 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2138 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2139 offsetof(CPUState, stick));
2140 tcg_gen_helper_1_1(helper_tick_get_count, cpu_dst,
2142 tcg_temp_free(r_tickptr);
2143 gen_movl_TN_reg(rd, cpu_dst);
2146 case 0x19: /* System tick compare */
2147 gen_movl_TN_reg(rd, cpu_stick_cmpr);
2149 case 0x10: /* Performance Control */
2150 case 0x11: /* Performance Instrumentation Counter */
2151 case 0x12: /* Dispatch Control */
2152 case 0x14: /* Softint set, WO */
2153 case 0x15: /* Softint clear, WO */
2154 case 0x16: /* Softint write */
2159 #if !defined(CONFIG_USER_ONLY)
2160 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2161 #ifndef TARGET_SPARC64
2162 if (!supervisor(dc))
2164 tcg_gen_helper_1_0(helper_rdpsr, cpu_dst);
2166 CHECK_IU_FEATURE(dc, HYPV);
2167 if (!hypervisor(dc))
2169 rs1 = GET_FIELD(insn, 13, 17);
2172 // gen_op_rdhpstate();
2175 // gen_op_rdhtstate();
2178 tcg_gen_mov_tl(cpu_dst, cpu_hintp);
2181 tcg_gen_mov_tl(cpu_dst, cpu_htba);
2184 tcg_gen_mov_tl(cpu_dst, cpu_hver);
2186 case 31: // hstick_cmpr
2187 tcg_gen_mov_tl(cpu_dst, cpu_hstick_cmpr);
2193 gen_movl_TN_reg(rd, cpu_dst);
2195 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2196 if (!supervisor(dc))
2198 #ifdef TARGET_SPARC64
2199 rs1 = GET_FIELD(insn, 13, 17);
2205 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2206 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2207 offsetof(CPUState, tsptr));
2208 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2209 offsetof(trap_state, tpc));
2210 tcg_temp_free(r_tsptr);
2217 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2218 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2219 offsetof(CPUState, tsptr));
2220 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2221 offsetof(trap_state, tnpc));
2222 tcg_temp_free(r_tsptr);
2229 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2230 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2231 offsetof(CPUState, tsptr));
2232 tcg_gen_ld_tl(cpu_tmp0, r_tsptr,
2233 offsetof(trap_state, tstate));
2234 tcg_temp_free(r_tsptr);
2241 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2242 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2243 offsetof(CPUState, tsptr));
2244 tcg_gen_ld_i32(cpu_tmp0, r_tsptr,
2245 offsetof(trap_state, tt));
2246 tcg_temp_free(r_tsptr);
2253 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2254 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2255 offsetof(CPUState, tick));
2256 tcg_gen_helper_1_1(helper_tick_get_count, cpu_tmp0,
2258 gen_movl_TN_reg(rd, cpu_tmp0);
2259 tcg_temp_free(r_tickptr);
2263 tcg_gen_mov_tl(cpu_tmp0, cpu_tbr);
2266 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2267 offsetof(CPUSPARCState, pstate));
2268 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2271 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2272 offsetof(CPUSPARCState, tl));
2273 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2276 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2277 offsetof(CPUSPARCState, psrpil));
2278 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2281 tcg_gen_helper_1_0(helper_rdcwp, cpu_tmp0);
2284 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2285 offsetof(CPUSPARCState, cansave));
2286 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2288 case 11: // canrestore
2289 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2290 offsetof(CPUSPARCState, canrestore));
2291 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2293 case 12: // cleanwin
2294 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2295 offsetof(CPUSPARCState, cleanwin));
2296 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2298 case 13: // otherwin
2299 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2300 offsetof(CPUSPARCState, otherwin));
2301 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2304 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2305 offsetof(CPUSPARCState, wstate));
2306 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2308 case 16: // UA2005 gl
2309 CHECK_IU_FEATURE(dc, GL);
2310 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
2311 offsetof(CPUSPARCState, gl));
2312 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_tmp32);
2314 case 26: // UA2005 strand status
2315 CHECK_IU_FEATURE(dc, HYPV);
2316 if (!hypervisor(dc))
2318 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_ssr);
2321 tcg_gen_mov_tl(cpu_tmp0, cpu_ver);
2328 tcg_gen_ext_i32_tl(cpu_tmp0, cpu_wim);
2330 gen_movl_TN_reg(rd, cpu_tmp0);
2332 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2333 #ifdef TARGET_SPARC64
2334 save_state(dc, cpu_cond);
2335 tcg_gen_helper_0_0(helper_flushw);
2337 if (!supervisor(dc))
2339 gen_movl_TN_reg(rd, cpu_tbr);
2343 } else if (xop == 0x34) { /* FPU Operations */
2344 if (gen_trap_ifnofpu(dc, cpu_cond))
2346 gen_op_clear_ieee_excp_and_FTT();
2347 rs1 = GET_FIELD(insn, 13, 17);
2348 rs2 = GET_FIELD(insn, 27, 31);
2349 xop = GET_FIELD(insn, 18, 26);
2351 case 0x1: /* fmovs */
2352 gen_op_load_fpr_FT0(rs2);
2353 gen_op_store_FT0_fpr(rd);
2355 case 0x5: /* fnegs */
2356 gen_op_load_fpr_FT1(rs2);
2357 tcg_gen_helper_0_0(helper_fnegs);
2358 gen_op_store_FT0_fpr(rd);
2360 case 0x9: /* fabss */
2361 gen_op_load_fpr_FT1(rs2);
2362 tcg_gen_helper_0_0(helper_fabss);
2363 gen_op_store_FT0_fpr(rd);
2365 case 0x29: /* fsqrts */
2366 CHECK_FPU_FEATURE(dc, FSQRT);
2367 gen_op_load_fpr_FT1(rs2);
2368 gen_clear_float_exceptions();
2369 tcg_gen_helper_0_0(helper_fsqrts);
2370 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2371 gen_op_store_FT0_fpr(rd);
2373 case 0x2a: /* fsqrtd */
2374 CHECK_FPU_FEATURE(dc, FSQRT);
2375 gen_op_load_fpr_DT1(DFPREG(rs2));
2376 gen_clear_float_exceptions();
2377 tcg_gen_helper_0_0(helper_fsqrtd);
2378 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2379 gen_op_store_DT0_fpr(DFPREG(rd));
2381 case 0x2b: /* fsqrtq */
2382 CHECK_FPU_FEATURE(dc, FLOAT128);
2383 gen_op_load_fpr_QT1(QFPREG(rs2));
2384 gen_clear_float_exceptions();
2385 tcg_gen_helper_0_0(helper_fsqrtq);
2386 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2387 gen_op_store_QT0_fpr(QFPREG(rd));
2390 gen_op_load_fpr_FT0(rs1);
2391 gen_op_load_fpr_FT1(rs2);
2392 gen_clear_float_exceptions();
2393 tcg_gen_helper_0_0(helper_fadds);
2394 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2395 gen_op_store_FT0_fpr(rd);
2398 gen_op_load_fpr_DT0(DFPREG(rs1));
2399 gen_op_load_fpr_DT1(DFPREG(rs2));
2400 gen_clear_float_exceptions();
2401 tcg_gen_helper_0_0(helper_faddd);
2402 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2403 gen_op_store_DT0_fpr(DFPREG(rd));
2405 case 0x43: /* faddq */
2406 CHECK_FPU_FEATURE(dc, FLOAT128);
2407 gen_op_load_fpr_QT0(QFPREG(rs1));
2408 gen_op_load_fpr_QT1(QFPREG(rs2));
2409 gen_clear_float_exceptions();
2410 tcg_gen_helper_0_0(helper_faddq);
2411 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2412 gen_op_store_QT0_fpr(QFPREG(rd));
2415 gen_op_load_fpr_FT0(rs1);
2416 gen_op_load_fpr_FT1(rs2);
2417 gen_clear_float_exceptions();
2418 tcg_gen_helper_0_0(helper_fsubs);
2419 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2420 gen_op_store_FT0_fpr(rd);
2423 gen_op_load_fpr_DT0(DFPREG(rs1));
2424 gen_op_load_fpr_DT1(DFPREG(rs2));
2425 gen_clear_float_exceptions();
2426 tcg_gen_helper_0_0(helper_fsubd);
2427 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2428 gen_op_store_DT0_fpr(DFPREG(rd));
2430 case 0x47: /* fsubq */
2431 CHECK_FPU_FEATURE(dc, FLOAT128);
2432 gen_op_load_fpr_QT0(QFPREG(rs1));
2433 gen_op_load_fpr_QT1(QFPREG(rs2));
2434 gen_clear_float_exceptions();
2435 tcg_gen_helper_0_0(helper_fsubq);
2436 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2437 gen_op_store_QT0_fpr(QFPREG(rd));
2439 case 0x49: /* fmuls */
2440 CHECK_FPU_FEATURE(dc, FMUL);
2441 gen_op_load_fpr_FT0(rs1);
2442 gen_op_load_fpr_FT1(rs2);
2443 gen_clear_float_exceptions();
2444 tcg_gen_helper_0_0(helper_fmuls);
2445 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2446 gen_op_store_FT0_fpr(rd);
2448 case 0x4a: /* fmuld */
2449 CHECK_FPU_FEATURE(dc, FMUL);
2450 gen_op_load_fpr_DT0(DFPREG(rs1));
2451 gen_op_load_fpr_DT1(DFPREG(rs2));
2452 gen_clear_float_exceptions();
2453 tcg_gen_helper_0_0(helper_fmuld);
2454 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2455 gen_op_store_DT0_fpr(DFPREG(rd));
2457 case 0x4b: /* fmulq */
2458 CHECK_FPU_FEATURE(dc, FLOAT128);
2459 CHECK_FPU_FEATURE(dc, FMUL);
2460 gen_op_load_fpr_QT0(QFPREG(rs1));
2461 gen_op_load_fpr_QT1(QFPREG(rs2));
2462 gen_clear_float_exceptions();
2463 tcg_gen_helper_0_0(helper_fmulq);
2464 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2465 gen_op_store_QT0_fpr(QFPREG(rd));
2468 gen_op_load_fpr_FT0(rs1);
2469 gen_op_load_fpr_FT1(rs2);
2470 gen_clear_float_exceptions();
2471 tcg_gen_helper_0_0(helper_fdivs);
2472 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2473 gen_op_store_FT0_fpr(rd);
2476 gen_op_load_fpr_DT0(DFPREG(rs1));
2477 gen_op_load_fpr_DT1(DFPREG(rs2));
2478 gen_clear_float_exceptions();
2479 tcg_gen_helper_0_0(helper_fdivd);
2480 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2481 gen_op_store_DT0_fpr(DFPREG(rd));
2483 case 0x4f: /* fdivq */
2484 CHECK_FPU_FEATURE(dc, FLOAT128);
2485 gen_op_load_fpr_QT0(QFPREG(rs1));
2486 gen_op_load_fpr_QT1(QFPREG(rs2));
2487 gen_clear_float_exceptions();
2488 tcg_gen_helper_0_0(helper_fdivq);
2489 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2490 gen_op_store_QT0_fpr(QFPREG(rd));
2493 CHECK_FPU_FEATURE(dc, FSMULD);
2494 gen_op_load_fpr_FT0(rs1);
2495 gen_op_load_fpr_FT1(rs2);
2496 gen_clear_float_exceptions();
2497 tcg_gen_helper_0_0(helper_fsmuld);
2498 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2499 gen_op_store_DT0_fpr(DFPREG(rd));
2501 case 0x6e: /* fdmulq */
2502 CHECK_FPU_FEATURE(dc, FLOAT128);
2503 gen_op_load_fpr_DT0(DFPREG(rs1));
2504 gen_op_load_fpr_DT1(DFPREG(rs2));
2505 gen_clear_float_exceptions();
2506 tcg_gen_helper_0_0(helper_fdmulq);
2507 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2508 gen_op_store_QT0_fpr(QFPREG(rd));
2511 gen_op_load_fpr_FT1(rs2);
2512 gen_clear_float_exceptions();
2513 tcg_gen_helper_0_0(helper_fitos);
2514 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2515 gen_op_store_FT0_fpr(rd);
2518 gen_op_load_fpr_DT1(DFPREG(rs2));
2519 gen_clear_float_exceptions();
2520 tcg_gen_helper_0_0(helper_fdtos);
2521 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2522 gen_op_store_FT0_fpr(rd);
2524 case 0xc7: /* fqtos */
2525 CHECK_FPU_FEATURE(dc, FLOAT128);
2526 gen_op_load_fpr_QT1(QFPREG(rs2));
2527 gen_clear_float_exceptions();
2528 tcg_gen_helper_0_0(helper_fqtos);
2529 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2530 gen_op_store_FT0_fpr(rd);
2533 gen_op_load_fpr_FT1(rs2);
2534 tcg_gen_helper_0_0(helper_fitod);
2535 gen_op_store_DT0_fpr(DFPREG(rd));
2538 gen_op_load_fpr_FT1(rs2);
2539 tcg_gen_helper_0_0(helper_fstod);
2540 gen_op_store_DT0_fpr(DFPREG(rd));
2542 case 0xcb: /* fqtod */
2543 CHECK_FPU_FEATURE(dc, FLOAT128);
2544 gen_op_load_fpr_QT1(QFPREG(rs2));
2545 gen_clear_float_exceptions();
2546 tcg_gen_helper_0_0(helper_fqtod);
2547 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2548 gen_op_store_DT0_fpr(DFPREG(rd));
2550 case 0xcc: /* fitoq */
2551 CHECK_FPU_FEATURE(dc, FLOAT128);
2552 gen_op_load_fpr_FT1(rs2);
2553 tcg_gen_helper_0_0(helper_fitoq);
2554 gen_op_store_QT0_fpr(QFPREG(rd));
2556 case 0xcd: /* fstoq */
2557 CHECK_FPU_FEATURE(dc, FLOAT128);
2558 gen_op_load_fpr_FT1(rs2);
2559 tcg_gen_helper_0_0(helper_fstoq);
2560 gen_op_store_QT0_fpr(QFPREG(rd));
2562 case 0xce: /* fdtoq */
2563 CHECK_FPU_FEATURE(dc, FLOAT128);
2564 gen_op_load_fpr_DT1(DFPREG(rs2));
2565 tcg_gen_helper_0_0(helper_fdtoq);
2566 gen_op_store_QT0_fpr(QFPREG(rd));
2569 gen_op_load_fpr_FT1(rs2);
2570 gen_clear_float_exceptions();
2571 tcg_gen_helper_0_0(helper_fstoi);
2572 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2573 gen_op_store_FT0_fpr(rd);
2576 gen_op_load_fpr_DT1(DFPREG(rs2));
2577 gen_clear_float_exceptions();
2578 tcg_gen_helper_0_0(helper_fdtoi);
2579 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2580 gen_op_store_FT0_fpr(rd);
2582 case 0xd3: /* fqtoi */
2583 CHECK_FPU_FEATURE(dc, FLOAT128);
2584 gen_op_load_fpr_QT1(QFPREG(rs2));
2585 gen_clear_float_exceptions();
2586 tcg_gen_helper_0_0(helper_fqtoi);
2587 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2588 gen_op_store_FT0_fpr(rd);
2590 #ifdef TARGET_SPARC64
2591 case 0x2: /* V9 fmovd */
2592 gen_op_load_fpr_DT0(DFPREG(rs2));
2593 gen_op_store_DT0_fpr(DFPREG(rd));
2595 case 0x3: /* V9 fmovq */
2596 CHECK_FPU_FEATURE(dc, FLOAT128);
2597 gen_op_load_fpr_QT0(QFPREG(rs2));
2598 gen_op_store_QT0_fpr(QFPREG(rd));
2600 case 0x6: /* V9 fnegd */
2601 gen_op_load_fpr_DT1(DFPREG(rs2));
2602 tcg_gen_helper_0_0(helper_fnegd);
2603 gen_op_store_DT0_fpr(DFPREG(rd));
2605 case 0x7: /* V9 fnegq */
2606 CHECK_FPU_FEATURE(dc, FLOAT128);
2607 gen_op_load_fpr_QT1(QFPREG(rs2));
2608 tcg_gen_helper_0_0(helper_fnegq);
2609 gen_op_store_QT0_fpr(QFPREG(rd));
2611 case 0xa: /* V9 fabsd */
2612 gen_op_load_fpr_DT1(DFPREG(rs2));
2613 tcg_gen_helper_0_0(helper_fabsd);
2614 gen_op_store_DT0_fpr(DFPREG(rd));
2616 case 0xb: /* V9 fabsq */
2617 CHECK_FPU_FEATURE(dc, FLOAT128);
2618 gen_op_load_fpr_QT1(QFPREG(rs2));
2619 tcg_gen_helper_0_0(helper_fabsq);
2620 gen_op_store_QT0_fpr(QFPREG(rd));
2622 case 0x81: /* V9 fstox */
2623 gen_op_load_fpr_FT1(rs2);
2624 gen_clear_float_exceptions();
2625 tcg_gen_helper_0_0(helper_fstox);
2626 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2627 gen_op_store_DT0_fpr(DFPREG(rd));
2629 case 0x82: /* V9 fdtox */
2630 gen_op_load_fpr_DT1(DFPREG(rs2));
2631 gen_clear_float_exceptions();
2632 tcg_gen_helper_0_0(helper_fdtox);
2633 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2634 gen_op_store_DT0_fpr(DFPREG(rd));
2636 case 0x83: /* V9 fqtox */
2637 CHECK_FPU_FEATURE(dc, FLOAT128);
2638 gen_op_load_fpr_QT1(QFPREG(rs2));
2639 gen_clear_float_exceptions();
2640 tcg_gen_helper_0_0(helper_fqtox);
2641 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2642 gen_op_store_DT0_fpr(DFPREG(rd));
2644 case 0x84: /* V9 fxtos */
2645 gen_op_load_fpr_DT1(DFPREG(rs2));
2646 gen_clear_float_exceptions();
2647 tcg_gen_helper_0_0(helper_fxtos);
2648 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2649 gen_op_store_FT0_fpr(rd);
2651 case 0x88: /* V9 fxtod */
2652 gen_op_load_fpr_DT1(DFPREG(rs2));
2653 gen_clear_float_exceptions();
2654 tcg_gen_helper_0_0(helper_fxtod);
2655 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2656 gen_op_store_DT0_fpr(DFPREG(rd));
2658 case 0x8c: /* V9 fxtoq */
2659 CHECK_FPU_FEATURE(dc, FLOAT128);
2660 gen_op_load_fpr_DT1(DFPREG(rs2));
2661 gen_clear_float_exceptions();
2662 tcg_gen_helper_0_0(helper_fxtoq);
2663 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2664 gen_op_store_QT0_fpr(QFPREG(rd));
2670 } else if (xop == 0x35) { /* FPU Operations */
2671 #ifdef TARGET_SPARC64
2674 if (gen_trap_ifnofpu(dc, cpu_cond))
2676 gen_op_clear_ieee_excp_and_FTT();
2677 rs1 = GET_FIELD(insn, 13, 17);
2678 rs2 = GET_FIELD(insn, 27, 31);
2679 xop = GET_FIELD(insn, 18, 26);
2680 #ifdef TARGET_SPARC64
2681 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2684 l1 = gen_new_label();
2685 cond = GET_FIELD_SP(insn, 14, 17);
2686 cpu_src1 = get_src1(insn, cpu_src1);
2687 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2689 gen_op_load_fpr_FT0(rs2);
2690 gen_op_store_FT0_fpr(rd);
2693 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2696 l1 = gen_new_label();
2697 cond = GET_FIELD_SP(insn, 14, 17);
2698 cpu_src1 = get_src1(insn, cpu_src1);
2699 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2701 gen_op_load_fpr_DT0(DFPREG(rs2));
2702 gen_op_store_DT0_fpr(DFPREG(rd));
2705 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2708 CHECK_FPU_FEATURE(dc, FLOAT128);
2709 l1 = gen_new_label();
2710 cond = GET_FIELD_SP(insn, 14, 17);
2711 cpu_src1 = get_src1(insn, cpu_src1);
2712 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond], cpu_src1,
2714 gen_op_load_fpr_QT0(QFPREG(rs2));
2715 gen_op_store_QT0_fpr(QFPREG(rd));
2721 #ifdef TARGET_SPARC64
2722 #define FMOVCC(size_FDQ, fcc) \
2727 l1 = gen_new_label(); \
2728 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2729 cond = GET_FIELD_SP(insn, 14, 17); \
2730 gen_fcond(r_cond, fcc, cond); \
2731 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2733 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2734 (glue(size_FDQ, FPREG(rs2))); \
2735 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2736 (glue(size_FDQ, FPREG(rd))); \
2737 gen_set_label(l1); \
2738 tcg_temp_free(r_cond); \
2740 case 0x001: /* V9 fmovscc %fcc0 */
2743 case 0x002: /* V9 fmovdcc %fcc0 */
2746 case 0x003: /* V9 fmovqcc %fcc0 */
2747 CHECK_FPU_FEATURE(dc, FLOAT128);
2750 case 0x041: /* V9 fmovscc %fcc1 */
2753 case 0x042: /* V9 fmovdcc %fcc1 */
2756 case 0x043: /* V9 fmovqcc %fcc1 */
2757 CHECK_FPU_FEATURE(dc, FLOAT128);
2760 case 0x081: /* V9 fmovscc %fcc2 */
2763 case 0x082: /* V9 fmovdcc %fcc2 */
2766 case 0x083: /* V9 fmovqcc %fcc2 */
2767 CHECK_FPU_FEATURE(dc, FLOAT128);
2770 case 0x0c1: /* V9 fmovscc %fcc3 */
2773 case 0x0c2: /* V9 fmovdcc %fcc3 */
2776 case 0x0c3: /* V9 fmovqcc %fcc3 */
2777 CHECK_FPU_FEATURE(dc, FLOAT128);
2781 #define FMOVCC(size_FDQ, icc) \
2786 l1 = gen_new_label(); \
2787 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2788 cond = GET_FIELD_SP(insn, 14, 17); \
2789 gen_cond(r_cond, icc, cond); \
2790 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, \
2792 glue(glue(gen_op_load_fpr_, size_FDQ), T0) \
2793 (glue(size_FDQ, FPREG(rs2))); \
2794 glue(glue(gen_op_store_, size_FDQ), T0_fpr) \
2795 (glue(size_FDQ, FPREG(rd))); \
2796 gen_set_label(l1); \
2797 tcg_temp_free(r_cond); \
2800 case 0x101: /* V9 fmovscc %icc */
2803 case 0x102: /* V9 fmovdcc %icc */
2805 case 0x103: /* V9 fmovqcc %icc */
2806 CHECK_FPU_FEATURE(dc, FLOAT128);
2809 case 0x181: /* V9 fmovscc %xcc */
2812 case 0x182: /* V9 fmovdcc %xcc */
2815 case 0x183: /* V9 fmovqcc %xcc */
2816 CHECK_FPU_FEATURE(dc, FLOAT128);
2821 case 0x51: /* fcmps, V9 %fcc */
2822 gen_op_load_fpr_FT0(rs1);
2823 gen_op_load_fpr_FT1(rs2);
2824 gen_op_fcmps(rd & 3);
2826 case 0x52: /* fcmpd, V9 %fcc */
2827 gen_op_load_fpr_DT0(DFPREG(rs1));
2828 gen_op_load_fpr_DT1(DFPREG(rs2));
2829 gen_op_fcmpd(rd & 3);
2831 case 0x53: /* fcmpq, V9 %fcc */
2832 CHECK_FPU_FEATURE(dc, FLOAT128);
2833 gen_op_load_fpr_QT0(QFPREG(rs1));
2834 gen_op_load_fpr_QT1(QFPREG(rs2));
2835 gen_op_fcmpq(rd & 3);
2837 case 0x55: /* fcmpes, V9 %fcc */
2838 gen_op_load_fpr_FT0(rs1);
2839 gen_op_load_fpr_FT1(rs2);
2840 gen_op_fcmpes(rd & 3);
2842 case 0x56: /* fcmped, V9 %fcc */
2843 gen_op_load_fpr_DT0(DFPREG(rs1));
2844 gen_op_load_fpr_DT1(DFPREG(rs2));
2845 gen_op_fcmped(rd & 3);
2847 case 0x57: /* fcmpeq, V9 %fcc */
2848 CHECK_FPU_FEATURE(dc, FLOAT128);
2849 gen_op_load_fpr_QT0(QFPREG(rs1));
2850 gen_op_load_fpr_QT1(QFPREG(rs2));
2851 gen_op_fcmpeq(rd & 3);
2856 } else if (xop == 0x2) {
2859 rs1 = GET_FIELD(insn, 13, 17);
2861 // or %g0, x, y -> mov T0, x; mov y, T0
2862 if (IS_IMM) { /* immediate */
2865 rs2 = GET_FIELDs(insn, 19, 31);
2866 r_const = tcg_const_tl((int)rs2);
2867 gen_movl_TN_reg(rd, r_const);
2868 tcg_temp_free(r_const);
2869 } else { /* register */
2870 rs2 = GET_FIELD(insn, 27, 31);
2871 gen_movl_reg_TN(rs2, cpu_dst);
2872 gen_movl_TN_reg(rd, cpu_dst);
2875 cpu_src1 = get_src1(insn, cpu_src1);
2876 if (IS_IMM) { /* immediate */
2877 rs2 = GET_FIELDs(insn, 19, 31);
2878 tcg_gen_ori_tl(cpu_dst, cpu_src1, (int)rs2);
2879 gen_movl_TN_reg(rd, cpu_dst);
2880 } else { /* register */
2881 // or x, %g0, y -> mov T1, x; mov y, T1
2882 rs2 = GET_FIELD(insn, 27, 31);
2884 gen_movl_reg_TN(rs2, cpu_src2);
2885 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2886 gen_movl_TN_reg(rd, cpu_dst);
2888 gen_movl_TN_reg(rd, cpu_src1);
2891 #ifdef TARGET_SPARC64
2892 } else if (xop == 0x25) { /* sll, V9 sllx */
2893 cpu_src1 = get_src1(insn, cpu_src1);
2894 if (IS_IMM) { /* immediate */
2895 rs2 = GET_FIELDs(insn, 20, 31);
2896 if (insn & (1 << 12)) {
2897 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2899 tcg_gen_shli_i64(cpu_dst, cpu_src1, rs2 & 0x1f);
2901 } else { /* register */
2902 rs2 = GET_FIELD(insn, 27, 31);
2903 gen_movl_reg_TN(rs2, cpu_src2);
2904 if (insn & (1 << 12)) {
2905 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2907 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2909 tcg_gen_shl_i64(cpu_dst, cpu_src1, cpu_tmp0);
2911 gen_movl_TN_reg(rd, cpu_dst);
2912 } else if (xop == 0x26) { /* srl, V9 srlx */
2913 cpu_src1 = get_src1(insn, cpu_src1);
2914 if (IS_IMM) { /* immediate */
2915 rs2 = GET_FIELDs(insn, 20, 31);
2916 if (insn & (1 << 12)) {
2917 tcg_gen_shri_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2919 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2920 tcg_gen_shri_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2922 } else { /* register */
2923 rs2 = GET_FIELD(insn, 27, 31);
2924 gen_movl_reg_TN(rs2, cpu_src2);
2925 if (insn & (1 << 12)) {
2926 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2927 tcg_gen_shr_i64(cpu_dst, cpu_src1, cpu_tmp0);
2929 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2930 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2931 tcg_gen_shr_i64(cpu_dst, cpu_dst, cpu_tmp0);
2934 gen_movl_TN_reg(rd, cpu_dst);
2935 } else if (xop == 0x27) { /* sra, V9 srax */
2936 cpu_src1 = get_src1(insn, cpu_src1);
2937 if (IS_IMM) { /* immediate */
2938 rs2 = GET_FIELDs(insn, 20, 31);
2939 if (insn & (1 << 12)) {
2940 tcg_gen_sari_i64(cpu_dst, cpu_src1, rs2 & 0x3f);
2942 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2943 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2944 tcg_gen_sari_i64(cpu_dst, cpu_dst, rs2 & 0x1f);
2946 } else { /* register */
2947 rs2 = GET_FIELD(insn, 27, 31);
2948 gen_movl_reg_TN(rs2, cpu_src2);
2949 if (insn & (1 << 12)) {
2950 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x3f);
2951 tcg_gen_sar_i64(cpu_dst, cpu_src1, cpu_tmp0);
2953 tcg_gen_andi_i64(cpu_tmp0, cpu_src2, 0x1f);
2954 tcg_gen_andi_i64(cpu_dst, cpu_src1, 0xffffffffULL);
2955 tcg_gen_ext_i32_i64(cpu_dst, cpu_dst);
2956 tcg_gen_sar_i64(cpu_dst, cpu_dst, cpu_tmp0);
2959 gen_movl_TN_reg(rd, cpu_dst);
2961 } else if (xop < 0x36) {
2962 cpu_src1 = get_src1(insn, cpu_src1);
2963 cpu_src2 = get_src2(insn, cpu_src2);
2965 switch (xop & ~0x10) {
2968 gen_op_add_cc(cpu_dst, cpu_src1, cpu_src2);
2970 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
2973 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_src2);
2975 gen_op_logic_cc(cpu_dst);
2978 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_src2);
2980 gen_op_logic_cc(cpu_dst);
2983 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
2985 gen_op_logic_cc(cpu_dst);
2989 gen_op_sub_cc(cpu_dst, cpu_src1, cpu_src2);
2991 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_src2);
2994 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
2995 tcg_gen_and_tl(cpu_dst, cpu_src1, cpu_tmp0);
2997 gen_op_logic_cc(cpu_dst);
3000 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3001 tcg_gen_or_tl(cpu_dst, cpu_src1, cpu_tmp0);
3003 gen_op_logic_cc(cpu_dst);
3006 tcg_gen_xori_tl(cpu_tmp0, cpu_src2, -1);
3007 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_tmp0);
3009 gen_op_logic_cc(cpu_dst);
3013 gen_op_addx_cc(cpu_dst, cpu_src1, cpu_src2);
3015 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3016 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3017 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_tmp0);
3020 #ifdef TARGET_SPARC64
3021 case 0x9: /* V9 mulx */
3022 tcg_gen_mul_i64(cpu_dst, cpu_src1, cpu_src2);
3026 CHECK_IU_FEATURE(dc, MUL);
3027 gen_op_umul(cpu_dst, cpu_src1, cpu_src2);
3029 gen_op_logic_cc(cpu_dst);
3032 CHECK_IU_FEATURE(dc, MUL);
3033 gen_op_smul(cpu_dst, cpu_src1, cpu_src2);
3035 gen_op_logic_cc(cpu_dst);
3039 gen_op_subx_cc(cpu_dst, cpu_src1, cpu_src2);
3041 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3042 tcg_gen_add_tl(cpu_tmp0, cpu_src2, cpu_tmp0);
3043 tcg_gen_sub_tl(cpu_dst, cpu_src1, cpu_tmp0);
3046 #ifdef TARGET_SPARC64
3047 case 0xd: /* V9 udivx */
3048 tcg_gen_mov_tl(cpu_cc_src, cpu_src1);
3049 tcg_gen_mov_tl(cpu_cc_src2, cpu_src2);
3050 gen_trap_ifdivzero_tl(cpu_cc_src2);
3051 tcg_gen_divu_i64(cpu_dst, cpu_cc_src, cpu_cc_src2);
3055 CHECK_IU_FEATURE(dc, DIV);
3056 tcg_gen_helper_1_2(helper_udiv, cpu_dst, cpu_src1,
3059 gen_op_div_cc(cpu_dst);
3062 CHECK_IU_FEATURE(dc, DIV);
3063 tcg_gen_helper_1_2(helper_sdiv, cpu_dst, cpu_src1,
3066 gen_op_div_cc(cpu_dst);
3071 gen_movl_TN_reg(rd, cpu_dst);
3074 case 0x20: /* taddcc */
3075 gen_op_tadd_cc(cpu_dst, cpu_src1, cpu_src2);
3076 gen_movl_TN_reg(rd, cpu_dst);
3078 case 0x21: /* tsubcc */
3079 gen_op_tsub_cc(cpu_dst, cpu_src1, cpu_src2);
3080 gen_movl_TN_reg(rd, cpu_dst);
3082 case 0x22: /* taddcctv */
3083 save_state(dc, cpu_cond);
3084 gen_op_tadd_ccTV(cpu_dst, cpu_src1, cpu_src2);
3085 gen_movl_TN_reg(rd, cpu_dst);
3087 case 0x23: /* tsubcctv */
3088 save_state(dc, cpu_cond);
3089 gen_op_tsub_ccTV(cpu_dst, cpu_src1, cpu_src2);
3090 gen_movl_TN_reg(rd, cpu_dst);
3092 case 0x24: /* mulscc */
3093 gen_op_mulscc(cpu_dst, cpu_src1, cpu_src2);
3094 gen_movl_TN_reg(rd, cpu_dst);
3096 #ifndef TARGET_SPARC64
3097 case 0x25: /* sll */
3098 if (IS_IMM) { /* immediate */
3099 rs2 = GET_FIELDs(insn, 20, 31);
3100 tcg_gen_shli_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3101 } else { /* register */
3102 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3103 tcg_gen_shl_tl(cpu_dst, cpu_src1, cpu_tmp0);
3105 gen_movl_TN_reg(rd, cpu_dst);
3107 case 0x26: /* srl */
3108 if (IS_IMM) { /* immediate */
3109 rs2 = GET_FIELDs(insn, 20, 31);
3110 tcg_gen_shri_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3111 } else { /* register */
3112 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3113 tcg_gen_shr_tl(cpu_dst, cpu_src1, cpu_tmp0);
3115 gen_movl_TN_reg(rd, cpu_dst);
3117 case 0x27: /* sra */
3118 if (IS_IMM) { /* immediate */
3119 rs2 = GET_FIELDs(insn, 20, 31);
3120 tcg_gen_sari_tl(cpu_dst, cpu_src1, rs2 & 0x1f);
3121 } else { /* register */
3122 tcg_gen_andi_tl(cpu_tmp0, cpu_src2, 0x1f);
3123 tcg_gen_sar_tl(cpu_dst, cpu_src1, cpu_tmp0);
3125 gen_movl_TN_reg(rd, cpu_dst);
3132 tcg_gen_xor_tl(cpu_y, cpu_src1, cpu_src2);
3134 #ifndef TARGET_SPARC64
3135 case 0x01 ... 0x0f: /* undefined in the
3139 case 0x10 ... 0x1f: /* implementation-dependent
3145 case 0x2: /* V9 wrccr */
3146 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3147 tcg_gen_helper_0_1(helper_wrccr, cpu_dst);
3149 case 0x3: /* V9 wrasi */
3150 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3151 tcg_gen_trunc_tl_i32(cpu_asi, cpu_dst);
3153 case 0x6: /* V9 wrfprs */
3154 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3155 tcg_gen_trunc_tl_i32(cpu_fprs, cpu_dst);
3156 save_state(dc, cpu_cond);
3161 case 0xf: /* V9 sir, nop if user */
3162 #if !defined(CONFIG_USER_ONLY)
3167 case 0x13: /* Graphics Status */
3168 if (gen_trap_ifnofpu(dc, cpu_cond))
3170 tcg_gen_xor_tl(cpu_gsr, cpu_src1, cpu_src2);
3172 case 0x17: /* Tick compare */
3173 #if !defined(CONFIG_USER_ONLY)
3174 if (!supervisor(dc))
3180 tcg_gen_xor_tl(cpu_tick_cmpr, cpu_src1,
3182 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3183 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3184 offsetof(CPUState, tick));
3185 tcg_gen_helper_0_2(helper_tick_set_limit,
3186 r_tickptr, cpu_tick_cmpr);
3187 tcg_temp_free(r_tickptr);
3190 case 0x18: /* System tick */
3191 #if !defined(CONFIG_USER_ONLY)
3192 if (!supervisor(dc))
3198 tcg_gen_xor_tl(cpu_dst, cpu_src1,
3200 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3201 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3202 offsetof(CPUState, stick));
3203 tcg_gen_helper_0_2(helper_tick_set_count,
3204 r_tickptr, cpu_dst);
3205 tcg_temp_free(r_tickptr);
3208 case 0x19: /* System tick compare */
3209 #if !defined(CONFIG_USER_ONLY)
3210 if (!supervisor(dc))
3216 tcg_gen_xor_tl(cpu_stick_cmpr, cpu_src1,
3218 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3219 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3220 offsetof(CPUState, stick));
3221 tcg_gen_helper_0_2(helper_tick_set_limit,
3222 r_tickptr, cpu_stick_cmpr);
3223 tcg_temp_free(r_tickptr);
3227 case 0x10: /* Performance Control */
3228 case 0x11: /* Performance Instrumentation
3230 case 0x12: /* Dispatch Control */
3231 case 0x14: /* Softint set */
3232 case 0x15: /* Softint clear */
3233 case 0x16: /* Softint write */
3240 #if !defined(CONFIG_USER_ONLY)
3241 case 0x31: /* wrpsr, V9 saved, restored */
3243 if (!supervisor(dc))
3245 #ifdef TARGET_SPARC64
3248 tcg_gen_helper_0_0(helper_saved);
3251 tcg_gen_helper_0_0(helper_restored);
3253 case 2: /* UA2005 allclean */
3254 case 3: /* UA2005 otherw */
3255 case 4: /* UA2005 normalw */
3256 case 5: /* UA2005 invalw */
3262 tcg_gen_xor_tl(cpu_dst, cpu_src1, cpu_src2);
3263 tcg_gen_helper_0_1(helper_wrpsr, cpu_dst);
3264 save_state(dc, cpu_cond);
3271 case 0x32: /* wrwim, V9 wrpr */
3273 if (!supervisor(dc))
3275 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3276 #ifdef TARGET_SPARC64
3282 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3283 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3284 offsetof(CPUState, tsptr));
3285 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3286 offsetof(trap_state, tpc));
3287 tcg_temp_free(r_tsptr);
3294 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3295 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3296 offsetof(CPUState, tsptr));
3297 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3298 offsetof(trap_state, tnpc));
3299 tcg_temp_free(r_tsptr);
3306 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3307 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3308 offsetof(CPUState, tsptr));
3309 tcg_gen_st_tl(cpu_tmp0, r_tsptr,
3310 offsetof(trap_state,
3312 tcg_temp_free(r_tsptr);
3319 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3320 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3321 offsetof(CPUState, tsptr));
3322 tcg_gen_st_i32(cpu_tmp0, r_tsptr,
3323 offsetof(trap_state, tt));
3324 tcg_temp_free(r_tsptr);
3331 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3332 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3333 offsetof(CPUState, tick));
3334 tcg_gen_helper_0_2(helper_tick_set_count,
3335 r_tickptr, cpu_tmp0);
3336 tcg_temp_free(r_tickptr);
3340 tcg_gen_mov_tl(cpu_tbr, cpu_tmp0);
3343 save_state(dc, cpu_cond);
3344 tcg_gen_helper_0_1(helper_wrpstate, cpu_tmp0);
3350 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3351 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3352 offsetof(CPUSPARCState, tl));
3355 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3356 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3357 offsetof(CPUSPARCState,
3361 tcg_gen_helper_0_1(helper_wrcwp, cpu_tmp0);
3364 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3365 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3366 offsetof(CPUSPARCState,
3369 case 11: // canrestore
3370 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3371 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3372 offsetof(CPUSPARCState,
3375 case 12: // cleanwin
3376 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3377 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3378 offsetof(CPUSPARCState,
3381 case 13: // otherwin
3382 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3383 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3384 offsetof(CPUSPARCState,
3388 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3389 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3390 offsetof(CPUSPARCState,
3393 case 16: // UA2005 gl
3394 CHECK_IU_FEATURE(dc, GL);
3395 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3396 tcg_gen_st_i32(cpu_tmp32, cpu_env,
3397 offsetof(CPUSPARCState, gl));
3399 case 26: // UA2005 strand status
3400 CHECK_IU_FEATURE(dc, HYPV);
3401 if (!hypervisor(dc))
3403 tcg_gen_trunc_tl_i32(cpu_ssr, cpu_tmp0);
3409 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_tmp0);
3410 if (dc->def->nwindows != 32)
3411 tcg_gen_andi_tl(cpu_tmp32, cpu_tmp32,
3412 (1 << dc->def->nwindows) - 1);
3413 tcg_gen_mov_i32(cpu_wim, cpu_tmp32);
3417 case 0x33: /* wrtbr, UA2005 wrhpr */
3419 #ifndef TARGET_SPARC64
3420 if (!supervisor(dc))
3422 tcg_gen_xor_tl(cpu_tbr, cpu_src1, cpu_src2);
3424 CHECK_IU_FEATURE(dc, HYPV);
3425 if (!hypervisor(dc))
3427 tcg_gen_xor_tl(cpu_tmp0, cpu_src1, cpu_src2);
3430 // XXX gen_op_wrhpstate();
3431 save_state(dc, cpu_cond);
3437 // XXX gen_op_wrhtstate();
3440 tcg_gen_mov_tl(cpu_hintp, cpu_tmp0);
3443 tcg_gen_mov_tl(cpu_htba, cpu_tmp0);
3445 case 31: // hstick_cmpr
3449 tcg_gen_mov_tl(cpu_hstick_cmpr, cpu_tmp0);
3450 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3451 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3452 offsetof(CPUState, hstick));
3453 tcg_gen_helper_0_2(helper_tick_set_limit,
3454 r_tickptr, cpu_hstick_cmpr);
3455 tcg_temp_free(r_tickptr);
3458 case 6: // hver readonly
3466 #ifdef TARGET_SPARC64
3467 case 0x2c: /* V9 movcc */
3469 int cc = GET_FIELD_SP(insn, 11, 12);
3470 int cond = GET_FIELD_SP(insn, 14, 17);
3474 r_cond = tcg_temp_new(TCG_TYPE_TL);
3475 if (insn & (1 << 18)) {
3477 gen_cond(r_cond, 0, cond);
3479 gen_cond(r_cond, 1, cond);
3483 gen_fcond(r_cond, cc, cond);
3486 l1 = gen_new_label();
3488 tcg_gen_brcondi_tl(TCG_COND_EQ, r_cond, 0, l1);
3489 if (IS_IMM) { /* immediate */
3492 rs2 = GET_FIELD_SPs(insn, 0, 10);
3493 r_const = tcg_const_tl((int)rs2);
3494 gen_movl_TN_reg(rd, r_const);
3495 tcg_temp_free(r_const);
3497 rs2 = GET_FIELD_SP(insn, 0, 4);
3498 gen_movl_reg_TN(rs2, cpu_tmp0);
3499 gen_movl_TN_reg(rd, cpu_tmp0);
3502 tcg_temp_free(r_cond);
3505 case 0x2d: /* V9 sdivx */
3506 gen_op_sdivx(cpu_dst, cpu_src1, cpu_src2);
3507 gen_movl_TN_reg(rd, cpu_dst);
3509 case 0x2e: /* V9 popc */
3511 cpu_src2 = get_src2(insn, cpu_src2);
3512 tcg_gen_helper_1_1(helper_popc, cpu_dst,
3514 gen_movl_TN_reg(rd, cpu_dst);
3516 case 0x2f: /* V9 movr */
3518 int cond = GET_FIELD_SP(insn, 10, 12);
3521 cpu_src1 = get_src1(insn, cpu_src1);
3523 l1 = gen_new_label();
3525 tcg_gen_brcondi_tl(gen_tcg_cond_reg[cond],
3527 if (IS_IMM) { /* immediate */
3530 rs2 = GET_FIELD_SPs(insn, 0, 9);
3531 r_const = tcg_const_tl((int)rs2);
3532 gen_movl_TN_reg(rd, r_const);
3533 tcg_temp_free(r_const);
3535 rs2 = GET_FIELD_SP(insn, 0, 4);
3536 gen_movl_reg_TN(rs2, cpu_tmp0);
3537 gen_movl_TN_reg(rd, cpu_tmp0);
3547 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3548 #ifdef TARGET_SPARC64
3549 int opf = GET_FIELD_SP(insn, 5, 13);
3550 rs1 = GET_FIELD(insn, 13, 17);
3551 rs2 = GET_FIELD(insn, 27, 31);
3552 if (gen_trap_ifnofpu(dc, cpu_cond))
3556 case 0x000: /* VIS I edge8cc */
3557 case 0x001: /* VIS II edge8n */
3558 case 0x002: /* VIS I edge8lcc */
3559 case 0x003: /* VIS II edge8ln */
3560 case 0x004: /* VIS I edge16cc */
3561 case 0x005: /* VIS II edge16n */
3562 case 0x006: /* VIS I edge16lcc */
3563 case 0x007: /* VIS II edge16ln */
3564 case 0x008: /* VIS I edge32cc */
3565 case 0x009: /* VIS II edge32n */
3566 case 0x00a: /* VIS I edge32lcc */
3567 case 0x00b: /* VIS II edge32ln */
3570 case 0x010: /* VIS I array8 */
3571 CHECK_FPU_FEATURE(dc, VIS1);
3572 cpu_src1 = get_src1(insn, cpu_src1);
3573 gen_movl_reg_TN(rs2, cpu_src2);
3574 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3576 gen_movl_TN_reg(rd, cpu_dst);
3578 case 0x012: /* VIS I array16 */
3579 CHECK_FPU_FEATURE(dc, VIS1);
3580 cpu_src1 = get_src1(insn, cpu_src1);
3581 gen_movl_reg_TN(rs2, cpu_src2);
3582 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3584 tcg_gen_shli_i64(cpu_dst, cpu_dst, 1);
3585 gen_movl_TN_reg(rd, cpu_dst);
3587 case 0x014: /* VIS I array32 */
3588 CHECK_FPU_FEATURE(dc, VIS1);
3589 cpu_src1 = get_src1(insn, cpu_src1);
3590 gen_movl_reg_TN(rs2, cpu_src2);
3591 tcg_gen_helper_1_2(helper_array8, cpu_dst, cpu_src1,
3593 tcg_gen_shli_i64(cpu_dst, cpu_dst, 2);
3594 gen_movl_TN_reg(rd, cpu_dst);
3596 case 0x018: /* VIS I alignaddr */
3597 CHECK_FPU_FEATURE(dc, VIS1);
3598 cpu_src1 = get_src1(insn, cpu_src1);
3599 gen_movl_reg_TN(rs2, cpu_src2);
3600 tcg_gen_helper_1_2(helper_alignaddr, cpu_dst, cpu_src1,
3602 gen_movl_TN_reg(rd, cpu_dst);
3604 case 0x019: /* VIS II bmask */
3605 case 0x01a: /* VIS I alignaddrl */
3608 case 0x020: /* VIS I fcmple16 */
3609 CHECK_FPU_FEATURE(dc, VIS1);
3610 gen_op_load_fpr_DT0(DFPREG(rs1));
3611 gen_op_load_fpr_DT1(DFPREG(rs2));
3612 tcg_gen_helper_0_0(helper_fcmple16);
3613 gen_op_store_DT0_fpr(DFPREG(rd));
3615 case 0x022: /* VIS I fcmpne16 */
3616 CHECK_FPU_FEATURE(dc, VIS1);
3617 gen_op_load_fpr_DT0(DFPREG(rs1));
3618 gen_op_load_fpr_DT1(DFPREG(rs2));
3619 tcg_gen_helper_0_0(helper_fcmpne16);
3620 gen_op_store_DT0_fpr(DFPREG(rd));
3622 case 0x024: /* VIS I fcmple32 */
3623 CHECK_FPU_FEATURE(dc, VIS1);
3624 gen_op_load_fpr_DT0(DFPREG(rs1));
3625 gen_op_load_fpr_DT1(DFPREG(rs2));
3626 tcg_gen_helper_0_0(helper_fcmple32);
3627 gen_op_store_DT0_fpr(DFPREG(rd));
3629 case 0x026: /* VIS I fcmpne32 */
3630 CHECK_FPU_FEATURE(dc, VIS1);
3631 gen_op_load_fpr_DT0(DFPREG(rs1));
3632 gen_op_load_fpr_DT1(DFPREG(rs2));
3633 tcg_gen_helper_0_0(helper_fcmpne32);
3634 gen_op_store_DT0_fpr(DFPREG(rd));
3636 case 0x028: /* VIS I fcmpgt16 */
3637 CHECK_FPU_FEATURE(dc, VIS1);
3638 gen_op_load_fpr_DT0(DFPREG(rs1));
3639 gen_op_load_fpr_DT1(DFPREG(rs2));
3640 tcg_gen_helper_0_0(helper_fcmpgt16);
3641 gen_op_store_DT0_fpr(DFPREG(rd));
3643 case 0x02a: /* VIS I fcmpeq16 */
3644 CHECK_FPU_FEATURE(dc, VIS1);
3645 gen_op_load_fpr_DT0(DFPREG(rs1));
3646 gen_op_load_fpr_DT1(DFPREG(rs2));
3647 tcg_gen_helper_0_0(helper_fcmpeq16);
3648 gen_op_store_DT0_fpr(DFPREG(rd));
3650 case 0x02c: /* VIS I fcmpgt32 */
3651 CHECK_FPU_FEATURE(dc, VIS1);
3652 gen_op_load_fpr_DT0(DFPREG(rs1));
3653 gen_op_load_fpr_DT1(DFPREG(rs2));
3654 tcg_gen_helper_0_0(helper_fcmpgt32);
3655 gen_op_store_DT0_fpr(DFPREG(rd));
3657 case 0x02e: /* VIS I fcmpeq32 */
3658 CHECK_FPU_FEATURE(dc, VIS1);
3659 gen_op_load_fpr_DT0(DFPREG(rs1));
3660 gen_op_load_fpr_DT1(DFPREG(rs2));
3661 tcg_gen_helper_0_0(helper_fcmpeq32);
3662 gen_op_store_DT0_fpr(DFPREG(rd));
3664 case 0x031: /* VIS I fmul8x16 */
3665 CHECK_FPU_FEATURE(dc, VIS1);
3666 gen_op_load_fpr_DT0(DFPREG(rs1));
3667 gen_op_load_fpr_DT1(DFPREG(rs2));
3668 tcg_gen_helper_0_0(helper_fmul8x16);
3669 gen_op_store_DT0_fpr(DFPREG(rd));
3671 case 0x033: /* VIS I fmul8x16au */
3672 CHECK_FPU_FEATURE(dc, VIS1);
3673 gen_op_load_fpr_DT0(DFPREG(rs1));
3674 gen_op_load_fpr_DT1(DFPREG(rs2));
3675 tcg_gen_helper_0_0(helper_fmul8x16au);
3676 gen_op_store_DT0_fpr(DFPREG(rd));
3678 case 0x035: /* VIS I fmul8x16al */
3679 CHECK_FPU_FEATURE(dc, VIS1);
3680 gen_op_load_fpr_DT0(DFPREG(rs1));
3681 gen_op_load_fpr_DT1(DFPREG(rs2));
3682 tcg_gen_helper_0_0(helper_fmul8x16al);
3683 gen_op_store_DT0_fpr(DFPREG(rd));
3685 case 0x036: /* VIS I fmul8sux16 */
3686 CHECK_FPU_FEATURE(dc, VIS1);
3687 gen_op_load_fpr_DT0(DFPREG(rs1));
3688 gen_op_load_fpr_DT1(DFPREG(rs2));
3689 tcg_gen_helper_0_0(helper_fmul8sux16);
3690 gen_op_store_DT0_fpr(DFPREG(rd));
3692 case 0x037: /* VIS I fmul8ulx16 */
3693 CHECK_FPU_FEATURE(dc, VIS1);
3694 gen_op_load_fpr_DT0(DFPREG(rs1));
3695 gen_op_load_fpr_DT1(DFPREG(rs2));
3696 tcg_gen_helper_0_0(helper_fmul8ulx16);
3697 gen_op_store_DT0_fpr(DFPREG(rd));
3699 case 0x038: /* VIS I fmuld8sux16 */
3700 CHECK_FPU_FEATURE(dc, VIS1);
3701 gen_op_load_fpr_DT0(DFPREG(rs1));
3702 gen_op_load_fpr_DT1(DFPREG(rs2));
3703 tcg_gen_helper_0_0(helper_fmuld8sux16);
3704 gen_op_store_DT0_fpr(DFPREG(rd));
3706 case 0x039: /* VIS I fmuld8ulx16 */
3707 CHECK_FPU_FEATURE(dc, VIS1);
3708 gen_op_load_fpr_DT0(DFPREG(rs1));
3709 gen_op_load_fpr_DT1(DFPREG(rs2));
3710 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3711 gen_op_store_DT0_fpr(DFPREG(rd));
3713 case 0x03a: /* VIS I fpack32 */
3714 case 0x03b: /* VIS I fpack16 */
3715 case 0x03d: /* VIS I fpackfix */
3716 case 0x03e: /* VIS I pdist */
3719 case 0x048: /* VIS I faligndata */
3720 CHECK_FPU_FEATURE(dc, VIS1);
3721 gen_op_load_fpr_DT0(DFPREG(rs1));
3722 gen_op_load_fpr_DT1(DFPREG(rs2));
3723 tcg_gen_helper_0_0(helper_faligndata);
3724 gen_op_store_DT0_fpr(DFPREG(rd));
3726 case 0x04b: /* VIS I fpmerge */
3727 CHECK_FPU_FEATURE(dc, VIS1);
3728 gen_op_load_fpr_DT0(DFPREG(rs1));
3729 gen_op_load_fpr_DT1(DFPREG(rs2));
3730 tcg_gen_helper_0_0(helper_fpmerge);
3731 gen_op_store_DT0_fpr(DFPREG(rd));
3733 case 0x04c: /* VIS II bshuffle */
3736 case 0x04d: /* VIS I fexpand */
3737 CHECK_FPU_FEATURE(dc, VIS1);
3738 gen_op_load_fpr_DT0(DFPREG(rs1));
3739 gen_op_load_fpr_DT1(DFPREG(rs2));
3740 tcg_gen_helper_0_0(helper_fexpand);
3741 gen_op_store_DT0_fpr(DFPREG(rd));
3743 case 0x050: /* VIS I fpadd16 */
3744 CHECK_FPU_FEATURE(dc, VIS1);
3745 gen_op_load_fpr_DT0(DFPREG(rs1));
3746 gen_op_load_fpr_DT1(DFPREG(rs2));
3747 tcg_gen_helper_0_0(helper_fpadd16);
3748 gen_op_store_DT0_fpr(DFPREG(rd));
3750 case 0x051: /* VIS I fpadd16s */
3751 CHECK_FPU_FEATURE(dc, VIS1);
3752 gen_op_load_fpr_FT0(rs1);
3753 gen_op_load_fpr_FT1(rs2);
3754 tcg_gen_helper_0_0(helper_fpadd16s);
3755 gen_op_store_FT0_fpr(rd);
3757 case 0x052: /* VIS I fpadd32 */
3758 CHECK_FPU_FEATURE(dc, VIS1);
3759 gen_op_load_fpr_DT0(DFPREG(rs1));
3760 gen_op_load_fpr_DT1(DFPREG(rs2));
3761 tcg_gen_helper_0_0(helper_fpadd32);
3762 gen_op_store_DT0_fpr(DFPREG(rd));
3764 case 0x053: /* VIS I fpadd32s */
3765 CHECK_FPU_FEATURE(dc, VIS1);
3766 gen_op_load_fpr_FT0(rs1);
3767 gen_op_load_fpr_FT1(rs2);
3768 tcg_gen_helper_0_0(helper_fpadd32s);
3769 gen_op_store_FT0_fpr(rd);
3771 case 0x054: /* VIS I fpsub16 */
3772 CHECK_FPU_FEATURE(dc, VIS1);
3773 gen_op_load_fpr_DT0(DFPREG(rs1));
3774 gen_op_load_fpr_DT1(DFPREG(rs2));
3775 tcg_gen_helper_0_0(helper_fpsub16);
3776 gen_op_store_DT0_fpr(DFPREG(rd));
3778 case 0x055: /* VIS I fpsub16s */
3779 CHECK_FPU_FEATURE(dc, VIS1);
3780 gen_op_load_fpr_FT0(rs1);
3781 gen_op_load_fpr_FT1(rs2);
3782 tcg_gen_helper_0_0(helper_fpsub16s);
3783 gen_op_store_FT0_fpr(rd);
3785 case 0x056: /* VIS I fpsub32 */
3786 CHECK_FPU_FEATURE(dc, VIS1);
3787 gen_op_load_fpr_DT0(DFPREG(rs1));
3788 gen_op_load_fpr_DT1(DFPREG(rs2));
3789 tcg_gen_helper_0_0(helper_fpadd32);
3790 gen_op_store_DT0_fpr(DFPREG(rd));
3792 case 0x057: /* VIS I fpsub32s */
3793 CHECK_FPU_FEATURE(dc, VIS1);
3794 gen_op_load_fpr_FT0(rs1);
3795 gen_op_load_fpr_FT1(rs2);
3796 tcg_gen_helper_0_0(helper_fpsub32s);
3797 gen_op_store_FT0_fpr(rd);
3799 case 0x060: /* VIS I fzero */
3800 CHECK_FPU_FEATURE(dc, VIS1);
3801 tcg_gen_helper_0_0(helper_movl_DT0_0);
3802 gen_op_store_DT0_fpr(DFPREG(rd));
3804 case 0x061: /* VIS I fzeros */
3805 CHECK_FPU_FEATURE(dc, VIS1);
3806 tcg_gen_helper_0_0(helper_movl_FT0_0);
3807 gen_op_store_FT0_fpr(rd);
3809 case 0x062: /* VIS I fnor */
3810 CHECK_FPU_FEATURE(dc, VIS1);
3811 gen_op_load_fpr_DT0(DFPREG(rs1));
3812 gen_op_load_fpr_DT1(DFPREG(rs2));
3813 tcg_gen_helper_0_0(helper_fnor);
3814 gen_op_store_DT0_fpr(DFPREG(rd));
3816 case 0x063: /* VIS I fnors */
3817 CHECK_FPU_FEATURE(dc, VIS1);
3818 gen_op_load_fpr_FT0(rs1);
3819 gen_op_load_fpr_FT1(rs2);
3820 tcg_gen_helper_0_0(helper_fnors);
3821 gen_op_store_FT0_fpr(rd);
3823 case 0x064: /* VIS I fandnot2 */
3824 CHECK_FPU_FEATURE(dc, VIS1);
3825 gen_op_load_fpr_DT1(DFPREG(rs1));
3826 gen_op_load_fpr_DT0(DFPREG(rs2));
3827 tcg_gen_helper_0_0(helper_fandnot);
3828 gen_op_store_DT0_fpr(DFPREG(rd));
3830 case 0x065: /* VIS I fandnot2s */
3831 CHECK_FPU_FEATURE(dc, VIS1);
3832 gen_op_load_fpr_FT1(rs1);
3833 gen_op_load_fpr_FT0(rs2);
3834 tcg_gen_helper_0_0(helper_fandnots);
3835 gen_op_store_FT0_fpr(rd);
3837 case 0x066: /* VIS I fnot2 */
3838 CHECK_FPU_FEATURE(dc, VIS1);
3839 gen_op_load_fpr_DT1(DFPREG(rs2));
3840 tcg_gen_helper_0_0(helper_fnot);
3841 gen_op_store_DT0_fpr(DFPREG(rd));
3843 case 0x067: /* VIS I fnot2s */
3844 CHECK_FPU_FEATURE(dc, VIS1);
3845 gen_op_load_fpr_FT1(rs2);
3846 tcg_gen_helper_0_0(helper_fnot);
3847 gen_op_store_FT0_fpr(rd);
3849 case 0x068: /* VIS I fandnot1 */
3850 CHECK_FPU_FEATURE(dc, VIS1);
3851 gen_op_load_fpr_DT0(DFPREG(rs1));
3852 gen_op_load_fpr_DT1(DFPREG(rs2));
3853 tcg_gen_helper_0_0(helper_fandnot);
3854 gen_op_store_DT0_fpr(DFPREG(rd));
3856 case 0x069: /* VIS I fandnot1s */
3857 CHECK_FPU_FEATURE(dc, VIS1);
3858 gen_op_load_fpr_FT0(rs1);
3859 gen_op_load_fpr_FT1(rs2);
3860 tcg_gen_helper_0_0(helper_fandnots);
3861 gen_op_store_FT0_fpr(rd);
3863 case 0x06a: /* VIS I fnot1 */
3864 CHECK_FPU_FEATURE(dc, VIS1);
3865 gen_op_load_fpr_DT1(DFPREG(rs1));
3866 tcg_gen_helper_0_0(helper_fnot);
3867 gen_op_store_DT0_fpr(DFPREG(rd));
3869 case 0x06b: /* VIS I fnot1s */
3870 CHECK_FPU_FEATURE(dc, VIS1);
3871 gen_op_load_fpr_FT1(rs1);
3872 tcg_gen_helper_0_0(helper_fnot);
3873 gen_op_store_FT0_fpr(rd);
3875 case 0x06c: /* VIS I fxor */
3876 CHECK_FPU_FEATURE(dc, VIS1);
3877 gen_op_load_fpr_DT0(DFPREG(rs1));
3878 gen_op_load_fpr_DT1(DFPREG(rs2));
3879 tcg_gen_helper_0_0(helper_fxor);
3880 gen_op_store_DT0_fpr(DFPREG(rd));
3882 case 0x06d: /* VIS I fxors */
3883 CHECK_FPU_FEATURE(dc, VIS1);
3884 gen_op_load_fpr_FT0(rs1);
3885 gen_op_load_fpr_FT1(rs2);
3886 tcg_gen_helper_0_0(helper_fxors);
3887 gen_op_store_FT0_fpr(rd);
3889 case 0x06e: /* VIS I fnand */
3890 CHECK_FPU_FEATURE(dc, VIS1);
3891 gen_op_load_fpr_DT0(DFPREG(rs1));
3892 gen_op_load_fpr_DT1(DFPREG(rs2));
3893 tcg_gen_helper_0_0(helper_fnand);
3894 gen_op_store_DT0_fpr(DFPREG(rd));
3896 case 0x06f: /* VIS I fnands */
3897 CHECK_FPU_FEATURE(dc, VIS1);
3898 gen_op_load_fpr_FT0(rs1);
3899 gen_op_load_fpr_FT1(rs2);
3900 tcg_gen_helper_0_0(helper_fnands);
3901 gen_op_store_FT0_fpr(rd);
3903 case 0x070: /* VIS I fand */
3904 CHECK_FPU_FEATURE(dc, VIS1);
3905 gen_op_load_fpr_DT0(DFPREG(rs1));
3906 gen_op_load_fpr_DT1(DFPREG(rs2));
3907 tcg_gen_helper_0_0(helper_fand);
3908 gen_op_store_DT0_fpr(DFPREG(rd));
3910 case 0x071: /* VIS I fands */
3911 CHECK_FPU_FEATURE(dc, VIS1);
3912 gen_op_load_fpr_FT0(rs1);
3913 gen_op_load_fpr_FT1(rs2);
3914 tcg_gen_helper_0_0(helper_fands);
3915 gen_op_store_FT0_fpr(rd);
3917 case 0x072: /* VIS I fxnor */
3918 CHECK_FPU_FEATURE(dc, VIS1);
3919 gen_op_load_fpr_DT0(DFPREG(rs1));
3920 gen_op_load_fpr_DT1(DFPREG(rs2));
3921 tcg_gen_helper_0_0(helper_fxnor);
3922 gen_op_store_DT0_fpr(DFPREG(rd));
3924 case 0x073: /* VIS I fxnors */
3925 CHECK_FPU_FEATURE(dc, VIS1);
3926 gen_op_load_fpr_FT0(rs1);
3927 gen_op_load_fpr_FT1(rs2);
3928 tcg_gen_helper_0_0(helper_fxnors);
3929 gen_op_store_FT0_fpr(rd);
3931 case 0x074: /* VIS I fsrc1 */
3932 CHECK_FPU_FEATURE(dc, VIS1);
3933 gen_op_load_fpr_DT0(DFPREG(rs1));
3934 gen_op_store_DT0_fpr(DFPREG(rd));
3936 case 0x075: /* VIS I fsrc1s */
3937 CHECK_FPU_FEATURE(dc, VIS1);
3938 gen_op_load_fpr_FT0(rs1);
3939 gen_op_store_FT0_fpr(rd);
3941 case 0x076: /* VIS I fornot2 */
3942 CHECK_FPU_FEATURE(dc, VIS1);
3943 gen_op_load_fpr_DT1(DFPREG(rs1));
3944 gen_op_load_fpr_DT0(DFPREG(rs2));
3945 tcg_gen_helper_0_0(helper_fornot);
3946 gen_op_store_DT0_fpr(DFPREG(rd));
3948 case 0x077: /* VIS I fornot2s */
3949 CHECK_FPU_FEATURE(dc, VIS1);
3950 gen_op_load_fpr_FT1(rs1);
3951 gen_op_load_fpr_FT0(rs2);
3952 tcg_gen_helper_0_0(helper_fornots);
3953 gen_op_store_FT0_fpr(rd);
3955 case 0x078: /* VIS I fsrc2 */
3956 CHECK_FPU_FEATURE(dc, VIS1);
3957 gen_op_load_fpr_DT0(DFPREG(rs2));
3958 gen_op_store_DT0_fpr(DFPREG(rd));
3960 case 0x079: /* VIS I fsrc2s */
3961 CHECK_FPU_FEATURE(dc, VIS1);
3962 gen_op_load_fpr_FT0(rs2);
3963 gen_op_store_FT0_fpr(rd);
3965 case 0x07a: /* VIS I fornot1 */
3966 CHECK_FPU_FEATURE(dc, VIS1);
3967 gen_op_load_fpr_DT0(DFPREG(rs1));
3968 gen_op_load_fpr_DT1(DFPREG(rs2));
3969 tcg_gen_helper_0_0(helper_fornot);
3970 gen_op_store_DT0_fpr(DFPREG(rd));
3972 case 0x07b: /* VIS I fornot1s */
3973 CHECK_FPU_FEATURE(dc, VIS1);
3974 gen_op_load_fpr_FT0(rs1);
3975 gen_op_load_fpr_FT1(rs2);
3976 tcg_gen_helper_0_0(helper_fornots);
3977 gen_op_store_FT0_fpr(rd);
3979 case 0x07c: /* VIS I for */
3980 CHECK_FPU_FEATURE(dc, VIS1);
3981 gen_op_load_fpr_DT0(DFPREG(rs1));
3982 gen_op_load_fpr_DT1(DFPREG(rs2));
3983 tcg_gen_helper_0_0(helper_for);
3984 gen_op_store_DT0_fpr(DFPREG(rd));
3986 case 0x07d: /* VIS I fors */
3987 CHECK_FPU_FEATURE(dc, VIS1);
3988 gen_op_load_fpr_FT0(rs1);
3989 gen_op_load_fpr_FT1(rs2);
3990 tcg_gen_helper_0_0(helper_fors);
3991 gen_op_store_FT0_fpr(rd);
3993 case 0x07e: /* VIS I fone */
3994 CHECK_FPU_FEATURE(dc, VIS1);
3995 tcg_gen_helper_0_0(helper_movl_DT0_1);
3996 gen_op_store_DT0_fpr(DFPREG(rd));
3998 case 0x07f: /* VIS I fones */
3999 CHECK_FPU_FEATURE(dc, VIS1);
4000 tcg_gen_helper_0_0(helper_movl_FT0_1);
4001 gen_op_store_FT0_fpr(rd);
4003 case 0x080: /* VIS I shutdown */
4004 case 0x081: /* VIS II siam */
4013 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
4014 #ifdef TARGET_SPARC64
4019 #ifdef TARGET_SPARC64
4020 } else if (xop == 0x39) { /* V9 return */
4023 save_state(dc, cpu_cond);
4024 cpu_src1 = get_src1(insn, cpu_src1);
4025 if (IS_IMM) { /* immediate */
4026 rs2 = GET_FIELDs(insn, 19, 31);
4027 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4028 } else { /* register */
4029 rs2 = GET_FIELD(insn, 27, 31);
4031 gen_movl_reg_TN(rs2, cpu_src2);
4032 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4034 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4036 tcg_gen_helper_0_0(helper_restore);
4037 gen_mov_pc_npc(dc, cpu_cond);
4038 r_const = tcg_const_i32(3);
4039 tcg_gen_helper_0_2(helper_check_align, cpu_dst, r_const);
4040 tcg_temp_free(r_const);
4041 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4042 dc->npc = DYNAMIC_PC;
4046 cpu_src1 = get_src1(insn, cpu_src1);
4047 if (IS_IMM) { /* immediate */
4048 rs2 = GET_FIELDs(insn, 19, 31);
4049 tcg_gen_addi_tl(cpu_dst, cpu_src1, (int)rs2);
4050 } else { /* register */
4051 rs2 = GET_FIELD(insn, 27, 31);
4053 gen_movl_reg_TN(rs2, cpu_src2);
4054 tcg_gen_add_tl(cpu_dst, cpu_src1, cpu_src2);
4056 tcg_gen_mov_tl(cpu_dst, cpu_src1);
4059 case 0x38: /* jmpl */
4063 r_const = tcg_const_tl(dc->pc);
4064 gen_movl_TN_reg(rd, r_const);
4065 tcg_temp_free(r_const);
4066 gen_mov_pc_npc(dc, cpu_cond);
4067 r_const = tcg_const_i32(3);
4068 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4070 tcg_temp_free(r_const);
4071 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4072 dc->npc = DYNAMIC_PC;
4075 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4076 case 0x39: /* rett, V9 return */
4080 if (!supervisor(dc))
4082 gen_mov_pc_npc(dc, cpu_cond);
4083 r_const = tcg_const_i32(3);
4084 tcg_gen_helper_0_2(helper_check_align, cpu_dst,
4086 tcg_temp_free(r_const);
4087 tcg_gen_mov_tl(cpu_npc, cpu_dst);
4088 dc->npc = DYNAMIC_PC;
4089 tcg_gen_helper_0_0(helper_rett);
4093 case 0x3b: /* flush */
4094 if (!((dc)->def->features & CPU_FEATURE_FLUSH))
4096 tcg_gen_helper_0_1(helper_flush, cpu_dst);
4098 case 0x3c: /* save */
4099 save_state(dc, cpu_cond);
4100 tcg_gen_helper_0_0(helper_save);
4101 gen_movl_TN_reg(rd, cpu_dst);
4103 case 0x3d: /* restore */
4104 save_state(dc, cpu_cond);
4105 tcg_gen_helper_0_0(helper_restore);
4106 gen_movl_TN_reg(rd, cpu_dst);
4108 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
4109 case 0x3e: /* V9 done/retry */
4113 if (!supervisor(dc))
4115 dc->npc = DYNAMIC_PC;
4116 dc->pc = DYNAMIC_PC;
4117 tcg_gen_helper_0_0(helper_done);
4120 if (!supervisor(dc))
4122 dc->npc = DYNAMIC_PC;
4123 dc->pc = DYNAMIC_PC;
4124 tcg_gen_helper_0_0(helper_retry);
4139 case 3: /* load/store instructions */
4141 unsigned int xop = GET_FIELD(insn, 7, 12);
4143 cpu_src1 = get_src1(insn, cpu_src1);
4144 if (xop == 0x3c || xop == 0x3e) { // V9 casa/casxa
4145 rs2 = GET_FIELD(insn, 27, 31);
4146 gen_movl_reg_TN(rs2, cpu_src2);
4147 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4148 } else if (IS_IMM) { /* immediate */
4149 rs2 = GET_FIELDs(insn, 19, 31);
4150 tcg_gen_addi_tl(cpu_addr, cpu_src1, (int)rs2);
4151 } else { /* register */
4152 rs2 = GET_FIELD(insn, 27, 31);
4154 gen_movl_reg_TN(rs2, cpu_src2);
4155 tcg_gen_add_tl(cpu_addr, cpu_src1, cpu_src2);
4157 tcg_gen_mov_tl(cpu_addr, cpu_src1);
4159 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4160 (xop > 0x17 && xop <= 0x1d ) ||
4161 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4163 case 0x0: /* load unsigned word */
4164 gen_address_mask(dc, cpu_addr);
4165 tcg_gen_qemu_ld32u(cpu_val, cpu_addr, dc->mem_idx);
4167 case 0x1: /* load unsigned byte */
4168 gen_address_mask(dc, cpu_addr);
4169 tcg_gen_qemu_ld8u(cpu_val, cpu_addr, dc->mem_idx);
4171 case 0x2: /* load unsigned halfword */
4172 gen_address_mask(dc, cpu_addr);
4173 tcg_gen_qemu_ld16u(cpu_val, cpu_addr, dc->mem_idx);
4175 case 0x3: /* load double word */
4181 save_state(dc, cpu_cond);
4182 r_const = tcg_const_i32(7);
4183 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4184 r_const); // XXX remove
4185 tcg_temp_free(r_const);
4186 gen_address_mask(dc, cpu_addr);
4187 tcg_gen_qemu_ld64(cpu_tmp64, cpu_addr, dc->mem_idx);
4188 tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
4189 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
4190 gen_movl_TN_reg(rd + 1, cpu_tmp0);
4191 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4192 tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
4193 tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
4196 case 0x9: /* load signed byte */
4197 gen_address_mask(dc, cpu_addr);
4198 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4200 case 0xa: /* load signed halfword */
4201 gen_address_mask(dc, cpu_addr);
4202 tcg_gen_qemu_ld16s(cpu_val, cpu_addr, dc->mem_idx);
4204 case 0xd: /* ldstub -- XXX: should be atomically */
4208 gen_address_mask(dc, cpu_addr);
4209 tcg_gen_qemu_ld8s(cpu_val, cpu_addr, dc->mem_idx);
4210 r_const = tcg_const_tl(0xff);
4211 tcg_gen_qemu_st8(r_const, cpu_addr, dc->mem_idx);
4212 tcg_temp_free(r_const);
4215 case 0x0f: /* swap register with memory. Also
4217 CHECK_IU_FEATURE(dc, SWAP);
4218 gen_movl_reg_TN(rd, cpu_val);
4219 gen_address_mask(dc, cpu_addr);
4220 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4221 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4222 tcg_gen_extu_i32_tl(cpu_val, cpu_tmp32);
4224 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4225 case 0x10: /* load word alternate */
4226 #ifndef TARGET_SPARC64
4229 if (!supervisor(dc))
4232 save_state(dc, cpu_cond);
4233 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 0);
4235 case 0x11: /* load unsigned byte alternate */
4236 #ifndef TARGET_SPARC64
4239 if (!supervisor(dc))
4242 save_state(dc, cpu_cond);
4243 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 0);
4245 case 0x12: /* load unsigned halfword alternate */
4246 #ifndef TARGET_SPARC64
4249 if (!supervisor(dc))
4252 save_state(dc, cpu_cond);
4253 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 0);
4255 case 0x13: /* load double word alternate */
4256 #ifndef TARGET_SPARC64
4259 if (!supervisor(dc))
4264 save_state(dc, cpu_cond);
4265 gen_ldda_asi(cpu_val, cpu_addr, insn, rd);
4267 case 0x19: /* load signed byte alternate */
4268 #ifndef TARGET_SPARC64
4271 if (!supervisor(dc))
4274 save_state(dc, cpu_cond);
4275 gen_ld_asi(cpu_val, cpu_addr, insn, 1, 1);
4277 case 0x1a: /* load signed halfword alternate */
4278 #ifndef TARGET_SPARC64
4281 if (!supervisor(dc))
4284 save_state(dc, cpu_cond);
4285 gen_ld_asi(cpu_val, cpu_addr, insn, 2, 1);
4287 case 0x1d: /* ldstuba -- XXX: should be atomically */
4288 #ifndef TARGET_SPARC64
4291 if (!supervisor(dc))
4294 save_state(dc, cpu_cond);
4295 gen_ldstub_asi(cpu_val, cpu_addr, insn);
4297 case 0x1f: /* swap reg with alt. memory. Also
4299 CHECK_IU_FEATURE(dc, SWAP);
4300 #ifndef TARGET_SPARC64
4303 if (!supervisor(dc))
4306 save_state(dc, cpu_cond);
4307 gen_movl_reg_TN(rd, cpu_val);
4308 gen_swap_asi(cpu_val, cpu_addr, insn);
4311 #ifndef TARGET_SPARC64
4312 case 0x30: /* ldc */
4313 case 0x31: /* ldcsr */
4314 case 0x33: /* lddc */
4318 #ifdef TARGET_SPARC64
4319 case 0x08: /* V9 ldsw */
4320 gen_address_mask(dc, cpu_addr);
4321 tcg_gen_qemu_ld32s(cpu_val, cpu_addr, dc->mem_idx);
4323 case 0x0b: /* V9 ldx */
4324 gen_address_mask(dc, cpu_addr);
4325 tcg_gen_qemu_ld64(cpu_val, cpu_addr, dc->mem_idx);
4327 case 0x18: /* V9 ldswa */
4328 save_state(dc, cpu_cond);
4329 gen_ld_asi(cpu_val, cpu_addr, insn, 4, 1);
4331 case 0x1b: /* V9 ldxa */
4332 save_state(dc, cpu_cond);
4333 gen_ld_asi(cpu_val, cpu_addr, insn, 8, 0);
4335 case 0x2d: /* V9 prefetch, no effect */
4337 case 0x30: /* V9 ldfa */
4338 save_state(dc, cpu_cond);
4339 gen_ldf_asi(cpu_addr, insn, 4, rd);
4341 case 0x33: /* V9 lddfa */
4342 save_state(dc, cpu_cond);
4343 gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
4345 case 0x3d: /* V9 prefetcha, no effect */
4347 case 0x32: /* V9 ldqfa */
4348 CHECK_FPU_FEATURE(dc, FLOAT128);
4349 save_state(dc, cpu_cond);
4350 gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
4356 gen_movl_TN_reg(rd, cpu_val);
4357 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4360 } else if (xop >= 0x20 && xop < 0x24) {
4361 if (gen_trap_ifnofpu(dc, cpu_cond))
4363 save_state(dc, cpu_cond);
4365 case 0x20: /* load fpreg */
4366 gen_address_mask(dc, cpu_addr);
4367 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4368 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4369 offsetof(CPUState, fpr[rd]));
4371 case 0x21: /* load fsr */
4372 gen_address_mask(dc, cpu_addr);
4373 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_addr, dc->mem_idx);
4374 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4375 offsetof(CPUState, ft0));
4376 tcg_gen_helper_0_0(helper_ldfsr);
4378 case 0x22: /* load quad fpreg */
4382 CHECK_FPU_FEATURE(dc, FLOAT128);
4383 r_const = tcg_const_i32(dc->mem_idx);
4384 tcg_gen_helper_0_2(helper_ldqf, cpu_addr, r_const);
4385 tcg_temp_free(r_const);
4386 gen_op_store_QT0_fpr(QFPREG(rd));
4389 case 0x23: /* load double fpreg */
4393 r_const = tcg_const_i32(dc->mem_idx);
4394 tcg_gen_helper_0_2(helper_lddf, cpu_addr, r_const);
4395 tcg_temp_free(r_const);
4396 gen_op_store_DT0_fpr(DFPREG(rd));
4402 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4403 xop == 0xe || xop == 0x1e) {
4404 gen_movl_reg_TN(rd, cpu_val);
4406 case 0x4: /* store word */
4407 gen_address_mask(dc, cpu_addr);
4408 tcg_gen_qemu_st32(cpu_val, cpu_addr, dc->mem_idx);
4410 case 0x5: /* store byte */
4411 gen_address_mask(dc, cpu_addr);
4412 tcg_gen_qemu_st8(cpu_val, cpu_addr, dc->mem_idx);
4414 case 0x6: /* store halfword */
4415 gen_address_mask(dc, cpu_addr);
4416 tcg_gen_qemu_st16(cpu_val, cpu_addr, dc->mem_idx);
4418 case 0x7: /* store double word */
4422 TCGv r_low, r_const;
4424 save_state(dc, cpu_cond);
4425 gen_address_mask(dc, cpu_addr);
4426 r_const = tcg_const_i32(7);
4427 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4428 r_const); // XXX remove
4429 tcg_temp_free(r_const);
4430 r_low = tcg_temp_new(TCG_TYPE_TL);
4431 gen_movl_reg_TN(rd + 1, r_low);
4432 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
4434 tcg_temp_free(r_low);
4435 tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
4438 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4439 case 0x14: /* store word alternate */
4440 #ifndef TARGET_SPARC64
4443 if (!supervisor(dc))
4446 save_state(dc, cpu_cond);
4447 gen_st_asi(cpu_val, cpu_addr, insn, 4);
4449 case 0x15: /* store byte alternate */
4450 #ifndef TARGET_SPARC64
4453 if (!supervisor(dc))
4456 save_state(dc, cpu_cond);
4457 gen_st_asi(cpu_val, cpu_addr, insn, 1);
4459 case 0x16: /* store halfword alternate */
4460 #ifndef TARGET_SPARC64
4463 if (!supervisor(dc))
4466 save_state(dc, cpu_cond);
4467 gen_st_asi(cpu_val, cpu_addr, insn, 2);
4469 case 0x17: /* store double word alternate */
4470 #ifndef TARGET_SPARC64
4473 if (!supervisor(dc))
4479 save_state(dc, cpu_cond);
4480 gen_stda_asi(cpu_val, cpu_addr, insn, rd);
4484 #ifdef TARGET_SPARC64
4485 case 0x0e: /* V9 stx */
4486 gen_address_mask(dc, cpu_addr);
4487 tcg_gen_qemu_st64(cpu_val, cpu_addr, dc->mem_idx);
4489 case 0x1e: /* V9 stxa */
4490 save_state(dc, cpu_cond);
4491 gen_st_asi(cpu_val, cpu_addr, insn, 8);
4497 } else if (xop > 0x23 && xop < 0x28) {
4498 if (gen_trap_ifnofpu(dc, cpu_cond))
4500 save_state(dc, cpu_cond);
4502 case 0x24: /* store fpreg */
4503 gen_address_mask(dc, cpu_addr);
4504 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4505 offsetof(CPUState, fpr[rd]));
4506 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4508 case 0x25: /* stfsr, V9 stxfsr */
4509 gen_address_mask(dc, cpu_addr);
4510 tcg_gen_helper_0_0(helper_stfsr);
4511 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4512 offsetof(CPUState, ft0));
4513 tcg_gen_qemu_st32(cpu_tmp32, cpu_addr, dc->mem_idx);
4516 #ifdef TARGET_SPARC64
4517 /* V9 stqf, store quad fpreg */
4521 CHECK_FPU_FEATURE(dc, FLOAT128);
4522 gen_op_load_fpr_QT0(QFPREG(rd));
4523 r_const = tcg_const_i32(dc->mem_idx);
4524 tcg_gen_helper_0_2(helper_stqf, cpu_addr, r_const);
4525 tcg_temp_free(r_const);
4528 #else /* !TARGET_SPARC64 */
4529 /* stdfq, store floating point queue */
4530 #if defined(CONFIG_USER_ONLY)
4533 if (!supervisor(dc))
4535 if (gen_trap_ifnofpu(dc, cpu_cond))
4540 case 0x27: /* store double fpreg */
4544 gen_op_load_fpr_DT0(DFPREG(rd));
4545 r_const = tcg_const_i32(dc->mem_idx);
4546 tcg_gen_helper_0_2(helper_stdf, cpu_addr, r_const);
4547 tcg_temp_free(r_const);
4553 } else if (xop > 0x33 && xop < 0x3f) {
4554 save_state(dc, cpu_cond);
4556 #ifdef TARGET_SPARC64
4557 case 0x34: /* V9 stfa */
4558 gen_op_load_fpr_FT0(rd);
4559 gen_stf_asi(cpu_addr, insn, 4, rd);
4561 case 0x36: /* V9 stqfa */
4565 CHECK_FPU_FEATURE(dc, FLOAT128);
4566 r_const = tcg_const_i32(7);
4567 tcg_gen_helper_0_2(helper_check_align, cpu_addr,
4569 tcg_temp_free(r_const);
4570 gen_op_load_fpr_QT0(QFPREG(rd));
4571 gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
4574 case 0x37: /* V9 stdfa */
4575 gen_op_load_fpr_DT0(DFPREG(rd));
4576 gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
4578 case 0x3c: /* V9 casa */
4579 gen_cas_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4580 gen_movl_TN_reg(rd, cpu_val);
4582 case 0x3e: /* V9 casxa */
4583 gen_casx_asi(cpu_val, cpu_addr, cpu_src2, insn, rd);
4584 gen_movl_TN_reg(rd, cpu_val);
4587 case 0x34: /* stc */
4588 case 0x35: /* stcsr */
4589 case 0x36: /* stdcq */
4590 case 0x37: /* stdc */
4602 /* default case for non jump instructions */
4603 if (dc->npc == DYNAMIC_PC) {
4604 dc->pc = DYNAMIC_PC;
4606 } else if (dc->npc == JUMP_PC) {
4607 /* we can do a static jump */
4608 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_cond);
4612 dc->npc = dc->npc + 4;
4620 save_state(dc, cpu_cond);
4621 r_const = tcg_const_i32(TT_ILL_INSN);
4622 tcg_gen_helper_0_1(raise_exception, r_const);
4623 tcg_temp_free(r_const);
4631 save_state(dc, cpu_cond);
4632 r_const = tcg_const_i32(TT_UNIMP_FLUSH);
4633 tcg_gen_helper_0_1(raise_exception, r_const);
4634 tcg_temp_free(r_const);
4638 #if !defined(CONFIG_USER_ONLY)
4643 save_state(dc, cpu_cond);
4644 r_const = tcg_const_i32(TT_PRIV_INSN);
4645 tcg_gen_helper_0_1(raise_exception, r_const);
4646 tcg_temp_free(r_const);
4652 save_state(dc, cpu_cond);
4653 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4656 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
4658 save_state(dc, cpu_cond);
4659 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4663 #ifndef TARGET_SPARC64
4668 save_state(dc, cpu_cond);
4669 r_const = tcg_const_i32(TT_NCP_INSN);
4670 tcg_gen_helper_0_1(raise_exception, r_const);
4671 tcg_temp_free(r_const);
4678 static inline void gen_intermediate_code_internal(TranslationBlock * tb,
4679 int spc, CPUSPARCState *env)
4681 target_ulong pc_start, last_pc;
4682 uint16_t *gen_opc_end;
4683 DisasContext dc1, *dc = &dc1;
4688 memset(dc, 0, sizeof(DisasContext));
4693 dc->npc = (target_ulong) tb->cs_base;
4694 dc->mem_idx = cpu_mmu_index(env);
4696 if ((dc->def->features & CPU_FEATURE_FLOAT))
4697 dc->fpu_enabled = cpu_fpu_enabled(env);
4699 dc->fpu_enabled = 0;
4700 #ifdef TARGET_SPARC64
4701 dc->address_mask_32bit = env->pstate & PS_AM;
4703 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4705 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4706 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4707 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4709 cpu_dst = tcg_temp_local_new(TCG_TYPE_TL);
4712 cpu_val = tcg_temp_local_new(TCG_TYPE_TL);
4713 cpu_addr = tcg_temp_local_new(TCG_TYPE_TL);
4716 max_insns = tb->cflags & CF_COUNT_MASK;
4718 max_insns = CF_COUNT_MASK;
4721 if (env->nb_breakpoints > 0) {
4722 for(j = 0; j < env->nb_breakpoints; j++) {
4723 if (env->breakpoints[j] == dc->pc) {
4724 if (dc->pc != pc_start)
4725 save_state(dc, cpu_cond);
4726 tcg_gen_helper_0_0(helper_debug);
4735 fprintf(logfile, "Search PC...\n");
4736 j = gen_opc_ptr - gen_opc_buf;
4740 gen_opc_instr_start[lj++] = 0;
4741 gen_opc_pc[lj] = dc->pc;
4742 gen_opc_npc[lj] = dc->npc;
4743 gen_opc_instr_start[lj] = 1;
4744 gen_opc_icount[lj] = num_insns;
4747 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
4750 disas_sparc_insn(dc);
4755 /* if the next PC is different, we abort now */
4756 if (dc->pc != (last_pc + 4))
4758 /* if we reach a page boundary, we stop generation so that the
4759 PC of a TT_TFAULT exception is always in the right page */
4760 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4762 /* if single step mode, we generate only one instruction and
4763 generate an exception */
4764 if (env->singlestep_enabled) {
4765 tcg_gen_movi_tl(cpu_pc, dc->pc);
4769 } while ((gen_opc_ptr < gen_opc_end) &&
4770 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
4771 num_insns < max_insns);
4774 tcg_temp_free(cpu_addr);
4775 tcg_temp_free(cpu_val);
4776 tcg_temp_free(cpu_dst);
4777 tcg_temp_free(cpu_tmp64);
4778 tcg_temp_free(cpu_tmp32);
4779 tcg_temp_free(cpu_tmp0);
4780 if (tb->cflags & CF_LAST_IO)
4783 if (dc->pc != DYNAMIC_PC &&
4784 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4785 /* static PC and NPC: we can use direct chaining */
4786 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4788 if (dc->pc != DYNAMIC_PC)
4789 tcg_gen_movi_tl(cpu_pc, dc->pc);
4790 save_npc(dc, cpu_cond);
4794 gen_icount_end(tb, num_insns);
4795 *gen_opc_ptr = INDEX_op_end;
4797 j = gen_opc_ptr - gen_opc_buf;
4800 gen_opc_instr_start[lj++] = 0;
4806 gen_opc_jump_pc[0] = dc->jump_pc[0];
4807 gen_opc_jump_pc[1] = dc->jump_pc[1];
4809 tb->size = last_pc + 4 - pc_start;
4810 tb->icount = num_insns;
4813 if (loglevel & CPU_LOG_TB_IN_ASM) {
4814 fprintf(logfile, "--------------\n");
4815 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4816 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4817 fprintf(logfile, "\n");
4822 void gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4824 gen_intermediate_code_internal(tb, 0, env);
4827 void gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4829 gen_intermediate_code_internal(tb, 1, env);
4832 void gen_intermediate_code_init(CPUSPARCState *env)
4836 static const char * const gregnames[8] = {
4837 NULL, // g0 not used
4847 /* init various static tables */
4851 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4852 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4853 offsetof(CPUState, regwptr),
4855 #ifdef TARGET_SPARC64
4856 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4857 TCG_AREG0, offsetof(CPUState, xcc),
4859 cpu_asi = tcg_global_mem_new(TCG_TYPE_I32,
4860 TCG_AREG0, offsetof(CPUState, asi),
4862 cpu_fprs = tcg_global_mem_new(TCG_TYPE_I32,
4863 TCG_AREG0, offsetof(CPUState, fprs),
4865 cpu_gsr = tcg_global_mem_new(TCG_TYPE_TL,
4866 TCG_AREG0, offsetof(CPUState, gsr),
4868 cpu_tick_cmpr = tcg_global_mem_new(TCG_TYPE_TL,
4870 offsetof(CPUState, tick_cmpr),
4872 cpu_stick_cmpr = tcg_global_mem_new(TCG_TYPE_TL,
4874 offsetof(CPUState, stick_cmpr),
4876 cpu_hstick_cmpr = tcg_global_mem_new(TCG_TYPE_TL,
4878 offsetof(CPUState, hstick_cmpr),
4880 cpu_hintp = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4881 offsetof(CPUState, hintp),
4883 cpu_htba = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4884 offsetof(CPUState, htba),
4886 cpu_hver = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4887 offsetof(CPUState, hver),
4889 cpu_ssr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4890 offsetof(CPUState, ssr), "ssr");
4891 cpu_ver = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4892 offsetof(CPUState, version), "ver");
4894 cpu_wim = tcg_global_mem_new(TCG_TYPE_I32,
4895 TCG_AREG0, offsetof(CPUState, wim),
4898 cpu_cond = tcg_global_mem_new(TCG_TYPE_TL,
4899 TCG_AREG0, offsetof(CPUState, cond),
4901 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4902 TCG_AREG0, offsetof(CPUState, cc_src),
4904 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4905 offsetof(CPUState, cc_src2),
4907 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4908 TCG_AREG0, offsetof(CPUState, cc_dst),
4910 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4911 TCG_AREG0, offsetof(CPUState, psr),
4913 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4914 TCG_AREG0, offsetof(CPUState, fsr),
4916 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4917 TCG_AREG0, offsetof(CPUState, pc),
4919 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4920 TCG_AREG0, offsetof(CPUState, npc),
4922 cpu_y = tcg_global_mem_new(TCG_TYPE_TL,
4923 TCG_AREG0, offsetof(CPUState, y), "y");
4924 #ifndef CONFIG_USER_ONLY
4925 cpu_tbr = tcg_global_mem_new(TCG_TYPE_TL,
4926 TCG_AREG0, offsetof(CPUState, tbr),
4929 for (i = 1; i < 8; i++)
4930 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4931 offsetof(CPUState, gregs[i]),
4933 /* register helpers */
4936 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
4941 void gen_pc_load(CPUState *env, TranslationBlock *tb,
4942 unsigned long searched_pc, int pc_pos, void *puc)
4945 env->pc = gen_opc_pc[pc_pos];
4946 npc = gen_opc_npc[pc_pos];
4948 /* dynamic NPC: already stored */
4949 } else if (npc == 2) {
4950 target_ulong t2 = (target_ulong)(unsigned long)puc;
4951 /* jump PC: use T2 and the jump targets of the translation */
4953 env->npc = gen_opc_jump_pc[0];
4955 env->npc = gen_opc_jump_pc[1];