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
25 Rest of V9 instructions, VIS instructions
26 NPC/PC static optimisations (use JUMP_TB when possible)
27 Optimize synthetic instructions
44 #define DYNAMIC_PC 1 /* dynamic pc value */
45 #define JUMP_PC 2 /* dynamic pc value which takes only two values
46 according to jump_pc[T2] */
48 /* global register indexes */
49 static TCGv cpu_env, cpu_T[3], cpu_regwptr, cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
50 static TCGv cpu_psr, cpu_fsr, cpu_pc, cpu_npc, cpu_gregs[8];
54 /* local register indexes (only used inside old micro ops) */
55 static TCGv cpu_tmp0, cpu_tmp32, cpu_tmp64;
57 typedef struct DisasContext {
58 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
59 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
60 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
64 struct TranslationBlock *tb;
67 typedef struct sparc_def_t sparc_def_t;
70 const unsigned char *name;
71 target_ulong iu_version;
75 uint32_t mmu_ctpr_mask;
76 uint32_t mmu_cxr_mask;
77 uint32_t mmu_sfsr_mask;
78 uint32_t mmu_trcr_mask;
81 static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name);
86 // This function uses non-native bit order
87 #define GET_FIELD(X, FROM, TO) \
88 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
90 // This function uses the order in the manuals, i.e. bit 0 is 2^0
91 #define GET_FIELD_SP(X, FROM, TO) \
92 GET_FIELD(X, 31 - (TO), 31 - (FROM))
94 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
95 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
99 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
100 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
102 #define FFPREG(r) (r)
103 #define DFPREG(r) (r & 0x1e)
104 #define QFPREG(r) (r & 0x1c)
107 static int sign_extend(int x, int len)
110 return (x << len) >> len;
113 #define IS_IMM (insn & (1<<13))
115 /* floating point registers moves */
116 static void gen_op_load_fpr_FT0(unsigned int src)
118 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
119 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
122 static void gen_op_load_fpr_FT1(unsigned int src)
124 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
125 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft1));
128 static void gen_op_store_FT0_fpr(unsigned int dst)
130 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ft0));
131 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
134 static void gen_op_load_fpr_DT0(unsigned int src)
136 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
137 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper));
138 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
139 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower));
142 static void gen_op_load_fpr_DT1(unsigned int src)
144 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
145 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.upper));
146 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
147 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt1) + offsetof(CPU_DoubleU, l.lower));
150 static void gen_op_store_DT0_fpr(unsigned int dst)
152 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.upper));
153 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
154 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, dt0) + offsetof(CPU_DoubleU, l.lower));
155 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
158 #ifdef CONFIG_USER_ONLY
159 static void gen_op_load_fpr_QT0(unsigned int src)
161 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
162 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upmost));
163 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
164 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper));
165 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
166 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower));
167 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
168 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest));
171 static void gen_op_load_fpr_QT1(unsigned int src)
173 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src]));
174 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upmost));
175 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 1]));
176 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.upper));
177 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 2]));
178 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + offsetof(CPU_QuadU, l.lower));
179 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[src + 3]));
180 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt1) + 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) + offsetof(CPU_QuadU, l.upmost));
186 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst]));
187 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.upper));
188 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 1]));
189 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lower));
190 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 2]));
191 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, qt0) + offsetof(CPU_QuadU, l.lowest));
192 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fpr[dst + 3]));
197 #ifdef CONFIG_USER_ONLY
198 #define supervisor(dc) 0
199 #ifdef TARGET_SPARC64
200 #define hypervisor(dc) 0
202 #define gen_op_ldst(name) gen_op_##name##_raw()
204 #define supervisor(dc) (dc->mem_idx >= 1)
205 #ifdef TARGET_SPARC64
206 #define hypervisor(dc) (dc->mem_idx == 2)
207 #define OP_LD_TABLE(width) \
208 static GenOpFunc * const gen_op_##width[] = { \
209 &gen_op_##width##_user, \
210 &gen_op_##width##_kernel, \
211 &gen_op_##width##_hypv, \
214 #define OP_LD_TABLE(width) \
215 static GenOpFunc * const gen_op_##width[] = { \
216 &gen_op_##width##_user, \
217 &gen_op_##width##_kernel, \
220 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
223 #ifndef CONFIG_USER_ONLY
226 #endif /* __i386__ */
232 #define ABI32_MASK(addr) tcg_gen_andi_tl(addr, addr, 0xffffffffULL);
234 #define ABI32_MASK(addr)
237 static inline void gen_movl_reg_TN(int reg, TCGv tn)
240 tcg_gen_movi_tl(tn, 0);
242 tcg_gen_mov_tl(tn, cpu_gregs[reg]);
244 tcg_gen_ld_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
248 static inline void gen_movl_TN_reg(int reg, TCGv tn)
253 tcg_gen_mov_tl(cpu_gregs[reg], tn);
255 tcg_gen_st_tl(tn, cpu_regwptr, (reg - 8) * sizeof(target_ulong));
259 static inline void gen_goto_tb(DisasContext *s, int tb_num,
260 target_ulong pc, target_ulong npc)
262 TranslationBlock *tb;
265 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
266 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
267 /* jump to same page: we can use a direct jump */
268 tcg_gen_goto_tb(tb_num);
269 tcg_gen_movi_tl(cpu_pc, pc);
270 tcg_gen_movi_tl(cpu_npc, npc);
271 tcg_gen_exit_tb((long)tb + tb_num);
273 /* jump to another page: currently not optimized */
274 tcg_gen_movi_tl(cpu_pc, pc);
275 tcg_gen_movi_tl(cpu_npc, npc);
281 static inline void gen_mov_reg_N(TCGv reg, TCGv src)
283 tcg_gen_extu_i32_tl(reg, src);
284 tcg_gen_shri_tl(reg, reg, 23);
285 tcg_gen_andi_tl(reg, reg, 0x1);
288 static inline void gen_mov_reg_Z(TCGv reg, TCGv src)
290 tcg_gen_extu_i32_tl(reg, src);
291 tcg_gen_shri_tl(reg, reg, 22);
292 tcg_gen_andi_tl(reg, reg, 0x1);
295 static inline void gen_mov_reg_V(TCGv reg, TCGv src)
297 tcg_gen_extu_i32_tl(reg, src);
298 tcg_gen_shri_tl(reg, reg, 21);
299 tcg_gen_andi_tl(reg, reg, 0x1);
302 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
304 tcg_gen_extu_i32_tl(reg, src);
305 tcg_gen_shri_tl(reg, reg, 20);
306 tcg_gen_andi_tl(reg, reg, 0x1);
309 static inline void gen_cc_clear(void)
311 tcg_gen_movi_i32(cpu_psr, 0);
312 #ifdef TARGET_SPARC64
313 tcg_gen_movi_i32(cpu_xcc, 0);
319 env->psr |= PSR_ZERO;
320 if ((int32_t) T0 < 0)
323 static inline void gen_cc_NZ(TCGv dst)
328 l1 = gen_new_label();
329 l2 = gen_new_label();
330 r_temp = tcg_temp_new(TCG_TYPE_TL);
331 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
332 tcg_gen_brcond_tl(TCG_COND_NE, r_temp, tcg_const_tl(0), l1);
333 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_ZERO);
335 tcg_gen_ext_i32_tl(r_temp, dst);
336 tcg_gen_brcond_tl(TCG_COND_GE, r_temp, tcg_const_tl(0), l2);
337 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_NEG);
339 #ifdef TARGET_SPARC64
343 l3 = gen_new_label();
344 l4 = gen_new_label();
345 tcg_gen_brcond_tl(TCG_COND_NE, dst, tcg_const_tl(0), l3);
346 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_ZERO);
348 tcg_gen_brcond_tl(TCG_COND_GE, dst, tcg_const_tl(0), l4);
349 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_NEG);
357 env->psr |= PSR_CARRY;
359 static inline void gen_cc_C_add(TCGv dst, TCGv src1)
364 l1 = gen_new_label();
365 r_temp = tcg_temp_new(TCG_TYPE_TL);
366 tcg_gen_andi_tl(r_temp, dst, 0xffffffffULL);
367 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l1);
368 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
370 #ifdef TARGET_SPARC64
374 l2 = gen_new_label();
375 tcg_gen_brcond_tl(TCG_COND_GEU, dst, src1, l2);
376 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
383 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
386 static inline void gen_cc_V_add(TCGv dst, TCGv src1, TCGv src2)
391 l1 = gen_new_label();
393 r_temp = tcg_temp_new(TCG_TYPE_TL);
394 tcg_gen_xor_tl(r_temp, src1, src2);
395 tcg_gen_xori_tl(r_temp, r_temp, -1);
396 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
397 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
398 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
399 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
400 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
402 #ifdef TARGET_SPARC64
406 l2 = gen_new_label();
407 tcg_gen_xor_tl(r_temp, src1, src2);
408 tcg_gen_xori_tl(r_temp, r_temp, -1);
409 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
410 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
411 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
412 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
413 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF);
417 tcg_gen_discard_tl(r_temp);
420 static inline void gen_add_tv(TCGv dst, TCGv src1, TCGv src2)
425 l1 = gen_new_label();
427 r_temp = tcg_temp_new(TCG_TYPE_TL);
428 tcg_gen_xor_tl(r_temp, src1, src2);
429 tcg_gen_xori_tl(r_temp, r_temp, -1);
430 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
431 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
432 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
433 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
434 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
436 #ifdef TARGET_SPARC64
440 l2 = gen_new_label();
441 tcg_gen_xor_tl(r_temp, src1, src2);
442 tcg_gen_xori_tl(r_temp, r_temp, -1);
443 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
444 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
445 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
446 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
447 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
451 tcg_gen_discard_tl(r_temp);
454 static inline void gen_cc_V_tag(TCGv src1, TCGv src2)
458 l1 = gen_new_label();
459 tcg_gen_or_tl(cpu_tmp0, src1, src2);
460 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
461 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
462 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
466 static inline void gen_tag_tv(TCGv src1, TCGv src2)
470 l1 = gen_new_label();
471 tcg_gen_or_tl(cpu_tmp0, src1, src2);
472 tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x3);
473 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
474 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
478 static inline void gen_op_add_T1_T0_cc(void)
480 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
481 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
484 gen_cc_C_add(cpu_T[0], cpu_cc_src);
485 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]);
488 static inline void gen_op_addx_T1_T0_cc(void)
490 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
491 gen_mov_reg_C(cpu_tmp0, cpu_psr);
492 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_tmp0);
494 gen_cc_C_add(cpu_T[0], cpu_cc_src);
495 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
496 gen_cc_C_add(cpu_T[0], cpu_cc_src);
498 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]);
501 static inline void gen_op_tadd_T1_T0_cc(void)
503 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
504 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
507 gen_cc_C_add(cpu_T[0], cpu_cc_src);
508 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_T[1]);
509 gen_cc_V_tag(cpu_cc_src, cpu_T[1]);
512 static inline void gen_op_tadd_T1_T0_ccTV(void)
514 gen_tag_tv(cpu_T[0], cpu_T[1]);
515 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
516 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
517 gen_add_tv(cpu_T[0], cpu_cc_src, cpu_T[1]);
520 gen_cc_C_add(cpu_T[0], cpu_cc_src);
525 env->psr |= PSR_CARRY;
527 static inline void gen_cc_C_sub(TCGv src1, TCGv src2)
529 TCGv r_temp1, r_temp2;
532 l1 = gen_new_label();
533 r_temp1 = tcg_temp_new(TCG_TYPE_TL);
534 r_temp2 = tcg_temp_new(TCG_TYPE_TL);
535 tcg_gen_andi_tl(r_temp1, src1, 0xffffffffULL);
536 tcg_gen_andi_tl(r_temp2, src2, 0xffffffffULL);
537 tcg_gen_brcond_tl(TCG_COND_GEU, r_temp1, r_temp2, l1);
538 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_CARRY);
540 #ifdef TARGET_SPARC64
544 l2 = gen_new_label();
545 tcg_gen_brcond_tl(TCG_COND_GEU, src1, src2, l2);
546 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_CARRY);
553 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
556 static inline void gen_cc_V_sub(TCGv dst, TCGv src1, TCGv src2)
561 l1 = gen_new_label();
563 r_temp = tcg_temp_new(TCG_TYPE_TL);
564 tcg_gen_xor_tl(r_temp, src1, src2);
565 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
566 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
567 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
568 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
569 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
571 #ifdef TARGET_SPARC64
575 l2 = gen_new_label();
576 tcg_gen_xor_tl(r_temp, src1, src2);
577 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
578 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
579 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
580 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
581 tcg_gen_ori_i32(cpu_xcc, cpu_xcc, PSR_OVF);
585 tcg_gen_discard_tl(r_temp);
588 static inline void gen_sub_tv(TCGv dst, TCGv src1, TCGv src2)
593 l1 = gen_new_label();
595 r_temp = tcg_temp_new(TCG_TYPE_TL);
596 tcg_gen_xor_tl(r_temp, src1, src2);
597 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
598 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
599 tcg_gen_andi_tl(r_temp, r_temp, (1 << 31));
600 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l1);
601 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
603 #ifdef TARGET_SPARC64
607 l2 = gen_new_label();
608 tcg_gen_xor_tl(r_temp, src1, src2);
609 tcg_gen_xor_tl(cpu_tmp0, src1, dst);
610 tcg_gen_and_tl(r_temp, r_temp, cpu_tmp0);
611 tcg_gen_andi_tl(r_temp, r_temp, (1ULL << 63));
612 tcg_gen_brcond_tl(TCG_COND_EQ, r_temp, tcg_const_tl(0), l2);
613 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_TOVF));
617 tcg_gen_discard_tl(r_temp);
620 static inline void gen_op_sub_T1_T0_cc(void)
622 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
623 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
626 gen_cc_C_sub(cpu_cc_src, cpu_T[1]);
627 gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]);
630 static inline void gen_op_subx_T1_T0_cc(void)
632 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
633 gen_mov_reg_C(cpu_tmp0, cpu_psr);
634 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_tmp0);
636 gen_cc_C_sub(cpu_T[0], cpu_cc_src);
637 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
638 gen_cc_C_sub(cpu_T[0], cpu_cc_src);
640 gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]);
643 static inline void gen_op_tsub_T1_T0_cc(void)
645 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
646 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
649 gen_cc_C_sub(cpu_cc_src, cpu_T[1]);
650 gen_cc_V_sub(cpu_T[0], cpu_cc_src, cpu_T[1]);
651 gen_cc_V_tag(cpu_cc_src, cpu_T[1]);
654 static inline void gen_op_tsub_T1_T0_ccTV(void)
656 gen_tag_tv(cpu_T[0], cpu_T[1]);
657 tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
658 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
659 gen_sub_tv(cpu_T[0], cpu_cc_src, cpu_T[1]);
662 gen_cc_C_sub(cpu_cc_src, cpu_T[1]);
665 static inline void gen_op_mulscc_T1_T0(void)
667 TCGv r_temp, r_temp2;
670 l1 = gen_new_label();
671 l2 = gen_new_label();
672 r_temp = tcg_temp_new(TCG_TYPE_TL);
673 r_temp2 = tcg_temp_new(TCG_TYPE_I32);
679 tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
680 tcg_gen_trunc_tl_i32(r_temp2, r_temp);
681 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
682 tcg_gen_brcond_i32(TCG_COND_EQ, r_temp2, tcg_const_i32(0), l1);
683 tcg_gen_mov_tl(cpu_cc_src2, cpu_T[1]);
686 tcg_gen_movi_tl(cpu_cc_src2, 0);
690 // env->y = (b2 << 31) | (env->y >> 1);
691 tcg_gen_trunc_tl_i32(r_temp2, cpu_T[0]);
692 tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
693 tcg_gen_shli_i32(r_temp2, r_temp2, 31);
694 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
695 tcg_gen_shri_i32(cpu_tmp32, cpu_tmp32, 1);
696 tcg_gen_or_i32(cpu_tmp32, cpu_tmp32, r_temp2);
697 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
700 gen_mov_reg_N(cpu_tmp0, cpu_psr);
701 gen_mov_reg_V(r_temp, cpu_psr);
702 tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
704 // T0 = (b1 << 31) | (T0 >> 1);
706 tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
707 tcg_gen_shri_tl(cpu_cc_src, cpu_T[0], 1);
708 tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
710 /* do addition and update flags */
711 tcg_gen_add_tl(cpu_T[0], cpu_cc_src, cpu_cc_src2);
712 tcg_gen_discard_tl(r_temp);
716 gen_cc_V_add(cpu_T[0], cpu_cc_src, cpu_cc_src2);
717 gen_cc_C_add(cpu_T[0], cpu_cc_src);
720 static inline void gen_op_umul_T1_T0(void)
722 TCGv r_temp, r_temp2;
724 r_temp = tcg_temp_new(TCG_TYPE_I64);
725 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
727 tcg_gen_extu_tl_i64(r_temp, cpu_T[1]);
728 tcg_gen_extu_tl_i64(r_temp2, cpu_T[0]);
729 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
731 tcg_gen_shri_i64(r_temp, r_temp2, 32);
732 tcg_gen_trunc_i64_i32(r_temp, r_temp);
733 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
734 #ifdef TARGET_SPARC64
735 tcg_gen_mov_i64(cpu_T[0], r_temp2);
737 tcg_gen_trunc_i64_tl(cpu_T[0], r_temp2);
740 tcg_gen_discard_i64(r_temp);
741 tcg_gen_discard_i64(r_temp2);
744 static inline void gen_op_smul_T1_T0(void)
746 TCGv r_temp, r_temp2;
748 r_temp = tcg_temp_new(TCG_TYPE_I64);
749 r_temp2 = tcg_temp_new(TCG_TYPE_I64);
751 tcg_gen_ext_tl_i64(r_temp, cpu_T[1]);
752 tcg_gen_ext_tl_i64(r_temp2, cpu_T[0]);
753 tcg_gen_mul_i64(r_temp2, r_temp, r_temp2);
755 tcg_gen_shri_i64(r_temp, r_temp2, 32);
756 tcg_gen_trunc_i64_i32(r_temp, r_temp);
757 tcg_gen_st_i32(r_temp, cpu_env, offsetof(CPUSPARCState, y));
758 #ifdef TARGET_SPARC64
759 tcg_gen_mov_i64(cpu_T[0], r_temp2);
761 tcg_gen_trunc_i64_tl(cpu_T[0], r_temp2);
764 tcg_gen_discard_i64(r_temp);
765 tcg_gen_discard_i64(r_temp2);
768 #ifdef TARGET_SPARC64
769 static inline void gen_trap_ifdivzero_tl(TCGv divisor)
773 l1 = gen_new_label();
774 tcg_gen_brcond_tl(TCG_COND_NE, divisor, tcg_const_tl(0), l1);
775 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_DIV_ZERO));
779 static inline void gen_op_sdivx_T1_T0(void)
783 l1 = gen_new_label();
784 l2 = gen_new_label();
785 gen_trap_ifdivzero_tl(cpu_T[1]);
786 tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[0], tcg_const_tl(INT64_MIN), l1);
787 tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[1], tcg_const_tl(-1), l1);
788 tcg_gen_movi_i64(cpu_T[0], INT64_MIN);
791 tcg_gen_div_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
796 static inline void gen_op_div_cc(void)
802 l1 = gen_new_label();
803 tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUSPARCState, cc_src2));
804 tcg_gen_brcond_tl(TCG_COND_EQ, cpu_tmp0, tcg_const_tl(0), l1);
805 tcg_gen_ori_i32(cpu_psr, cpu_psr, PSR_OVF);
809 static inline void gen_op_logic_T0_cc(void)
816 static inline void gen_op_eval_ba(TCGv dst)
818 tcg_gen_movi_tl(dst, 1);
822 static inline void gen_op_eval_be(TCGv dst, TCGv src)
824 gen_mov_reg_Z(dst, src);
828 static inline void gen_op_eval_ble(TCGv dst, TCGv src)
830 gen_mov_reg_N(cpu_tmp0, src);
831 gen_mov_reg_V(dst, src);
832 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
833 gen_mov_reg_Z(cpu_tmp0, src);
834 tcg_gen_or_tl(dst, dst, cpu_tmp0);
838 static inline void gen_op_eval_bl(TCGv dst, TCGv src)
840 gen_mov_reg_V(cpu_tmp0, src);
841 gen_mov_reg_N(dst, src);
842 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
846 static inline void gen_op_eval_bleu(TCGv dst, TCGv src)
848 gen_mov_reg_Z(cpu_tmp0, src);
849 gen_mov_reg_C(dst, src);
850 tcg_gen_or_tl(dst, dst, cpu_tmp0);
854 static inline void gen_op_eval_bcs(TCGv dst, TCGv src)
856 gen_mov_reg_C(dst, src);
860 static inline void gen_op_eval_bvs(TCGv dst, TCGv src)
862 gen_mov_reg_V(dst, src);
866 static inline void gen_op_eval_bn(TCGv dst)
868 tcg_gen_movi_tl(dst, 0);
872 static inline void gen_op_eval_bneg(TCGv dst, TCGv src)
874 gen_mov_reg_N(dst, src);
878 static inline void gen_op_eval_bne(TCGv dst, TCGv src)
880 gen_mov_reg_Z(dst, src);
881 tcg_gen_xori_tl(dst, dst, 0x1);
885 static inline void gen_op_eval_bg(TCGv dst, TCGv src)
887 gen_mov_reg_N(cpu_tmp0, src);
888 gen_mov_reg_V(dst, src);
889 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
890 gen_mov_reg_Z(cpu_tmp0, src);
891 tcg_gen_or_tl(dst, dst, cpu_tmp0);
892 tcg_gen_xori_tl(dst, dst, 0x1);
896 static inline void gen_op_eval_bge(TCGv dst, TCGv src)
898 gen_mov_reg_V(cpu_tmp0, src);
899 gen_mov_reg_N(dst, src);
900 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
901 tcg_gen_xori_tl(dst, dst, 0x1);
905 static inline void gen_op_eval_bgu(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);
910 tcg_gen_xori_tl(dst, dst, 0x1);
914 static inline void gen_op_eval_bcc(TCGv dst, TCGv src)
916 gen_mov_reg_C(dst, src);
917 tcg_gen_xori_tl(dst, dst, 0x1);
921 static inline void gen_op_eval_bpos(TCGv dst, TCGv src)
923 gen_mov_reg_N(dst, src);
924 tcg_gen_xori_tl(dst, dst, 0x1);
928 static inline void gen_op_eval_bvc(TCGv dst, TCGv src)
930 gen_mov_reg_V(dst, src);
931 tcg_gen_xori_tl(dst, dst, 0x1);
935 FPSR bit field FCC1 | FCC0:
941 static inline void gen_mov_reg_FCC0(TCGv reg, TCGv src,
942 unsigned int fcc_offset)
944 tcg_gen_extu_i32_tl(reg, src);
945 tcg_gen_shri_tl(reg, reg, 10 + fcc_offset);
946 tcg_gen_andi_tl(reg, reg, 0x1);
949 static inline void gen_mov_reg_FCC1(TCGv reg, TCGv src,
950 unsigned int fcc_offset)
952 tcg_gen_extu_i32_tl(reg, src);
953 tcg_gen_shri_tl(reg, reg, 11 + fcc_offset);
954 tcg_gen_andi_tl(reg, reg, 0x1);
958 static inline void gen_op_eval_fbne(TCGv dst, TCGv src,
959 unsigned int fcc_offset)
961 gen_mov_reg_FCC0(dst, src, fcc_offset);
962 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
963 tcg_gen_or_tl(dst, dst, cpu_tmp0);
966 // 1 or 2: FCC0 ^ FCC1
967 static inline void gen_op_eval_fblg(TCGv dst, TCGv src,
968 unsigned int fcc_offset)
970 gen_mov_reg_FCC0(dst, src, fcc_offset);
971 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
972 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
976 static inline void gen_op_eval_fbul(TCGv dst, TCGv src,
977 unsigned int fcc_offset)
979 gen_mov_reg_FCC0(dst, src, fcc_offset);
983 static inline void gen_op_eval_fbl(TCGv dst, TCGv src,
984 unsigned int fcc_offset)
986 gen_mov_reg_FCC0(dst, src, fcc_offset);
987 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
988 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
989 tcg_gen_and_tl(dst, dst, cpu_tmp0);
993 static inline void gen_op_eval_fbug(TCGv dst, TCGv src,
994 unsigned int fcc_offset)
996 gen_mov_reg_FCC1(dst, src, fcc_offset);
1000 static inline void gen_op_eval_fbg(TCGv dst, TCGv src,
1001 unsigned int fcc_offset)
1003 gen_mov_reg_FCC0(dst, src, fcc_offset);
1004 tcg_gen_xori_tl(dst, dst, 0x1);
1005 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1006 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1010 static inline void gen_op_eval_fbu(TCGv dst, TCGv src,
1011 unsigned int fcc_offset)
1013 gen_mov_reg_FCC0(dst, src, fcc_offset);
1014 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1015 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1018 // 0: !(FCC0 | FCC1)
1019 static inline void gen_op_eval_fbe(TCGv dst, TCGv src,
1020 unsigned int fcc_offset)
1022 gen_mov_reg_FCC0(dst, src, fcc_offset);
1023 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1024 tcg_gen_or_tl(dst, dst, cpu_tmp0);
1025 tcg_gen_xori_tl(dst, dst, 0x1);
1028 // 0 or 3: !(FCC0 ^ FCC1)
1029 static inline void gen_op_eval_fbue(TCGv dst, TCGv src,
1030 unsigned int fcc_offset)
1032 gen_mov_reg_FCC0(dst, src, fcc_offset);
1033 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1034 tcg_gen_xor_tl(dst, dst, cpu_tmp0);
1035 tcg_gen_xori_tl(dst, dst, 0x1);
1039 static inline void gen_op_eval_fbge(TCGv dst, TCGv src,
1040 unsigned int fcc_offset)
1042 gen_mov_reg_FCC0(dst, src, fcc_offset);
1043 tcg_gen_xori_tl(dst, dst, 0x1);
1046 // !1: !(FCC0 & !FCC1)
1047 static inline void gen_op_eval_fbuge(TCGv dst, TCGv src,
1048 unsigned int fcc_offset)
1050 gen_mov_reg_FCC0(dst, src, fcc_offset);
1051 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1052 tcg_gen_xori_tl(cpu_tmp0, cpu_tmp0, 0x1);
1053 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1054 tcg_gen_xori_tl(dst, dst, 0x1);
1058 static inline void gen_op_eval_fble(TCGv dst, TCGv src,
1059 unsigned int fcc_offset)
1061 gen_mov_reg_FCC1(dst, src, fcc_offset);
1062 tcg_gen_xori_tl(dst, dst, 0x1);
1065 // !2: !(!FCC0 & FCC1)
1066 static inline void gen_op_eval_fbule(TCGv dst, TCGv src,
1067 unsigned int fcc_offset)
1069 gen_mov_reg_FCC0(dst, src, fcc_offset);
1070 tcg_gen_xori_tl(dst, dst, 0x1);
1071 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1072 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1073 tcg_gen_xori_tl(dst, dst, 0x1);
1076 // !3: !(FCC0 & FCC1)
1077 static inline void gen_op_eval_fbo(TCGv dst, TCGv src,
1078 unsigned int fcc_offset)
1080 gen_mov_reg_FCC0(dst, src, fcc_offset);
1081 gen_mov_reg_FCC1(cpu_tmp0, src, fcc_offset);
1082 tcg_gen_and_tl(dst, dst, cpu_tmp0);
1083 tcg_gen_xori_tl(dst, dst, 0x1);
1086 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
1087 target_ulong pc2, TCGv r_cond)
1091 l1 = gen_new_label();
1093 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1095 gen_goto_tb(dc, 0, pc1, pc1 + 4);
1098 gen_goto_tb(dc, 1, pc2, pc2 + 4);
1101 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
1102 target_ulong pc2, TCGv r_cond)
1106 l1 = gen_new_label();
1108 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1110 gen_goto_tb(dc, 0, pc2, pc1);
1113 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
1116 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2,
1121 l1 = gen_new_label();
1122 l2 = gen_new_label();
1124 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, tcg_const_tl(0), l1);
1126 tcg_gen_movi_tl(cpu_npc, npc1);
1130 tcg_gen_movi_tl(cpu_npc, npc2);
1134 /* call this function before using T2 as it may have been set for a jump */
1135 static inline void flush_T2(DisasContext * dc)
1137 if (dc->npc == JUMP_PC) {
1138 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
1139 dc->npc = DYNAMIC_PC;
1143 static inline void save_npc(DisasContext * dc)
1145 if (dc->npc == JUMP_PC) {
1146 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
1147 dc->npc = DYNAMIC_PC;
1148 } else if (dc->npc != DYNAMIC_PC) {
1149 tcg_gen_movi_tl(cpu_npc, dc->npc);
1153 static inline void save_state(DisasContext * dc)
1155 tcg_gen_movi_tl(cpu_pc, dc->pc);
1159 static inline void gen_mov_pc_npc(DisasContext * dc)
1161 if (dc->npc == JUMP_PC) {
1162 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
1163 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1164 dc->pc = DYNAMIC_PC;
1165 } else if (dc->npc == DYNAMIC_PC) {
1166 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1167 dc->pc = DYNAMIC_PC;
1173 static inline void gen_op_next_insn(void)
1175 tcg_gen_mov_tl(cpu_pc, cpu_npc);
1176 tcg_gen_addi_tl(cpu_npc, cpu_npc, 4);
1179 static inline void gen_cond(TCGv r_dst, unsigned int cc, unsigned int cond)
1183 #ifdef TARGET_SPARC64
1193 gen_op_eval_bn(r_dst);
1196 gen_op_eval_be(r_dst, r_src);
1199 gen_op_eval_ble(r_dst, r_src);
1202 gen_op_eval_bl(r_dst, r_src);
1205 gen_op_eval_bleu(r_dst, r_src);
1208 gen_op_eval_bcs(r_dst, r_src);
1211 gen_op_eval_bneg(r_dst, r_src);
1214 gen_op_eval_bvs(r_dst, r_src);
1217 gen_op_eval_ba(r_dst);
1220 gen_op_eval_bne(r_dst, r_src);
1223 gen_op_eval_bg(r_dst, r_src);
1226 gen_op_eval_bge(r_dst, r_src);
1229 gen_op_eval_bgu(r_dst, r_src);
1232 gen_op_eval_bcc(r_dst, r_src);
1235 gen_op_eval_bpos(r_dst, r_src);
1238 gen_op_eval_bvc(r_dst, r_src);
1243 static inline void gen_fcond(TCGv r_dst, unsigned int cc, unsigned int cond)
1245 unsigned int offset;
1265 gen_op_eval_bn(r_dst);
1268 gen_op_eval_fbne(r_dst, cpu_fsr, offset);
1271 gen_op_eval_fblg(r_dst, cpu_fsr, offset);
1274 gen_op_eval_fbul(r_dst, cpu_fsr, offset);
1277 gen_op_eval_fbl(r_dst, cpu_fsr, offset);
1280 gen_op_eval_fbug(r_dst, cpu_fsr, offset);
1283 gen_op_eval_fbg(r_dst, cpu_fsr, offset);
1286 gen_op_eval_fbu(r_dst, cpu_fsr, offset);
1289 gen_op_eval_ba(r_dst);
1292 gen_op_eval_fbe(r_dst, cpu_fsr, offset);
1295 gen_op_eval_fbue(r_dst, cpu_fsr, offset);
1298 gen_op_eval_fbge(r_dst, cpu_fsr, offset);
1301 gen_op_eval_fbuge(r_dst, cpu_fsr, offset);
1304 gen_op_eval_fble(r_dst, cpu_fsr, offset);
1307 gen_op_eval_fbule(r_dst, cpu_fsr, offset);
1310 gen_op_eval_fbo(r_dst, cpu_fsr, offset);
1315 #ifdef TARGET_SPARC64
1317 static const int gen_tcg_cond_reg[8] = {
1328 static inline void gen_cond_reg(TCGv r_dst, int cond)
1332 l1 = gen_new_label();
1333 tcg_gen_movi_tl(r_dst, 0);
1334 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0], tcg_const_tl(0), l1);
1335 tcg_gen_movi_tl(r_dst, 1);
1340 /* XXX: potentially incorrect if dynamic npc */
1341 static void do_branch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
1343 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1344 target_ulong target = dc->pc + offset;
1347 /* unconditional not taken */
1349 dc->pc = dc->npc + 4;
1350 dc->npc = dc->pc + 4;
1353 dc->npc = dc->pc + 4;
1355 } else if (cond == 0x8) {
1356 /* unconditional taken */
1359 dc->npc = dc->pc + 4;
1366 gen_cond(cpu_T[2], cc, cond);
1368 gen_branch_a(dc, target, dc->npc, cpu_T[2]);
1372 dc->jump_pc[0] = target;
1373 dc->jump_pc[1] = dc->npc + 4;
1379 /* XXX: potentially incorrect if dynamic npc */
1380 static void do_fbranch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
1382 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
1383 target_ulong target = dc->pc + offset;
1386 /* unconditional not taken */
1388 dc->pc = dc->npc + 4;
1389 dc->npc = dc->pc + 4;
1392 dc->npc = dc->pc + 4;
1394 } else if (cond == 0x8) {
1395 /* unconditional taken */
1398 dc->npc = dc->pc + 4;
1405 gen_fcond(cpu_T[2], cc, cond);
1407 gen_branch_a(dc, target, dc->npc, cpu_T[2]);
1411 dc->jump_pc[0] = target;
1412 dc->jump_pc[1] = dc->npc + 4;
1418 #ifdef TARGET_SPARC64
1419 /* XXX: potentially incorrect if dynamic npc */
1420 static void do_branch_reg(DisasContext * dc, int32_t offset, uint32_t insn)
1422 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1423 target_ulong target = dc->pc + offset;
1426 gen_cond_reg(cpu_T[2], cond);
1428 gen_branch_a(dc, target, dc->npc, cpu_T[2]);
1432 dc->jump_pc[0] = target;
1433 dc->jump_pc[1] = dc->npc + 4;
1438 static GenOpFunc * const gen_fcmps[4] = {
1445 static GenOpFunc * const gen_fcmpd[4] = {
1452 #if defined(CONFIG_USER_ONLY)
1453 static GenOpFunc * const gen_fcmpq[4] = {
1461 static GenOpFunc * const gen_fcmpes[4] = {
1468 static GenOpFunc * const gen_fcmped[4] = {
1475 #if defined(CONFIG_USER_ONLY)
1476 static GenOpFunc * const gen_fcmpeq[4] = {
1484 static inline void gen_op_fcmps(int fccno)
1486 tcg_gen_helper_0_0(gen_fcmps[fccno]);
1489 static inline void gen_op_fcmpd(int fccno)
1491 tcg_gen_helper_0_0(gen_fcmpd[fccno]);
1494 #if defined(CONFIG_USER_ONLY)
1495 static inline void gen_op_fcmpq(int fccno)
1497 tcg_gen_helper_0_0(gen_fcmpq[fccno]);
1501 static inline void gen_op_fcmpes(int fccno)
1503 tcg_gen_helper_0_0(gen_fcmpes[fccno]);
1506 static inline void gen_op_fcmped(int fccno)
1508 tcg_gen_helper_0_0(gen_fcmped[fccno]);
1511 #if defined(CONFIG_USER_ONLY)
1512 static inline void gen_op_fcmpeq(int fccno)
1514 tcg_gen_helper_0_0(gen_fcmpeq[fccno]);
1520 static inline void gen_op_fcmps(int fccno)
1522 tcg_gen_helper_0_0(helper_fcmps);
1525 static inline void gen_op_fcmpd(int fccno)
1527 tcg_gen_helper_0_0(helper_fcmpd);
1530 #if defined(CONFIG_USER_ONLY)
1531 static inline void gen_op_fcmpq(int fccno)
1533 tcg_gen_helper_0_0(helper_fcmpq);
1537 static inline void gen_op_fcmpes(int fccno)
1539 tcg_gen_helper_0_0(helper_fcmpes);
1542 static inline void gen_op_fcmped(int fccno)
1544 tcg_gen_helper_0_0(helper_fcmped);
1547 #if defined(CONFIG_USER_ONLY)
1548 static inline void gen_op_fcmpeq(int fccno)
1550 tcg_gen_helper_0_0(helper_fcmpeq);
1556 static inline void gen_op_fpexception_im(int fsr_flags)
1558 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~FSR_FTT_MASK);
1559 tcg_gen_ori_tl(cpu_fsr, cpu_fsr, fsr_flags);
1560 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_FP_EXCP));
1563 static int gen_trap_ifnofpu(DisasContext * dc)
1565 #if !defined(CONFIG_USER_ONLY)
1566 if (!dc->fpu_enabled) {
1568 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NFPU_INSN));
1576 static inline void gen_op_clear_ieee_excp_and_FTT(void)
1578 tcg_gen_andi_tl(cpu_fsr, cpu_fsr, ~(FSR_FTT_MASK | FSR_CEXC_MASK));
1581 static inline void gen_clear_float_exceptions(void)
1583 tcg_gen_helper_0_0(helper_clear_float_exceptions);
1586 static inline void gen_check_align(TCGv r_addr, int align)
1588 tcg_gen_helper_0_2(helper_check_align, r_addr, tcg_const_i32(align));
1591 static inline void gen_op_check_align_T0_1(void)
1593 gen_check_align(cpu_T[0], 1);
1596 static inline void gen_op_check_align_T0_3(void)
1598 gen_check_align(cpu_T[0], 3);
1601 static inline void gen_op_check_align_T0_7(void)
1603 gen_check_align(cpu_T[0], 7);
1607 #ifdef TARGET_SPARC64
1608 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
1614 r_asi = tcg_temp_new(TCG_TYPE_I32);
1615 offset = GET_FIELD(insn, 25, 31);
1616 tcg_gen_addi_tl(r_addr, r_addr, offset);
1617 tcg_gen_ld_i32(r_asi, cpu_env, offsetof(CPUSPARCState, asi));
1619 asi = GET_FIELD(insn, 19, 26);
1620 r_asi = tcg_const_i32(asi);
1625 static inline void gen_ld_asi(int insn, int size, int sign)
1629 r_asi = gen_get_asi(insn, cpu_T[0]);
1630 tcg_gen_helper_1_4(helper_ld_asi, cpu_T[1], cpu_T[0], r_asi,
1631 tcg_const_i32(size), tcg_const_i32(sign));
1632 tcg_gen_discard_i32(r_asi);
1635 static inline void gen_st_asi(int insn, int size)
1639 r_asi = gen_get_asi(insn, cpu_T[0]);
1640 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_T[1], r_asi,
1641 tcg_const_i32(size));
1642 tcg_gen_discard_i32(r_asi);
1645 static inline void gen_ldf_asi(int insn, int size, int rd)
1649 r_asi = gen_get_asi(insn, cpu_T[0]);
1650 tcg_gen_helper_0_4(helper_ldf_asi, cpu_T[0], r_asi, tcg_const_i32(size),
1652 tcg_gen_discard_i32(r_asi);
1655 static inline void gen_stf_asi(int insn, int size, int rd)
1659 r_asi = gen_get_asi(insn, cpu_T[0]);
1660 tcg_gen_helper_0_4(helper_stf_asi, cpu_T[0], r_asi, tcg_const_i32(size),
1662 tcg_gen_discard_i32(r_asi);
1665 static inline void gen_swap_asi(int insn)
1669 r_temp = tcg_temp_new(TCG_TYPE_I32);
1670 r_asi = gen_get_asi(insn, cpu_T[0]);
1671 tcg_gen_helper_1_4(helper_ld_asi, r_temp, cpu_T[0], r_asi,
1672 tcg_const_i32(4), tcg_const_i32(0));
1673 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], r_temp, r_asi,
1675 tcg_gen_extu_i32_tl(cpu_T[1], r_temp);
1676 tcg_gen_discard_i32(r_asi);
1677 tcg_gen_discard_i32(r_temp);
1680 static inline void gen_ldda_asi(int insn)
1684 r_asi = gen_get_asi(insn, cpu_T[0]);
1685 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, cpu_T[0], r_asi,
1686 tcg_const_i32(8), tcg_const_i32(0));
1687 tcg_gen_andi_i64(cpu_T[0], cpu_tmp64, 0xffffffffULL);
1688 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1689 tcg_gen_andi_i64(cpu_T[1], cpu_tmp64, 0xffffffffULL);
1690 tcg_gen_discard_i32(r_asi);
1693 static inline void gen_stda_asi(int insn, int rd)
1697 r_temp = tcg_temp_new(TCG_TYPE_I32);
1698 gen_movl_reg_TN(rd + 1, r_temp);
1699 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_T[1],
1701 r_asi = gen_get_asi(insn, cpu_T[0]);
1702 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_tmp64, r_asi,
1704 tcg_gen_discard_i32(r_asi);
1705 tcg_gen_discard_i32(r_temp);
1708 static inline void gen_cas_asi(int insn, int rd)
1712 r_val1 = tcg_temp_new(TCG_TYPE_I32);
1713 gen_movl_reg_TN(rd, r_val1);
1714 r_asi = gen_get_asi(insn, cpu_T[0]);
1715 tcg_gen_helper_1_4(helper_cas_asi, cpu_T[1], cpu_T[0], r_val1, cpu_T[1],
1717 tcg_gen_discard_i32(r_asi);
1718 tcg_gen_discard_i32(r_val1);
1721 static inline void gen_casx_asi(int insn, int rd)
1725 gen_movl_reg_TN(rd, cpu_tmp64);
1726 r_asi = gen_get_asi(insn, cpu_T[0]);
1727 tcg_gen_helper_1_4(helper_casx_asi, cpu_T[1], cpu_T[0], cpu_tmp64, cpu_T[1],
1729 tcg_gen_discard_i32(r_asi);
1732 #elif !defined(CONFIG_USER_ONLY)
1734 static inline void gen_ld_asi(int insn, int size, int sign)
1738 asi = GET_FIELD(insn, 19, 26);
1739 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, cpu_T[0], tcg_const_i32(asi),
1740 tcg_const_i32(size), tcg_const_i32(sign));
1741 tcg_gen_trunc_i64_tl(cpu_T[1], cpu_tmp64);
1744 static inline void gen_st_asi(int insn, int size)
1748 tcg_gen_extu_tl_i64(cpu_tmp64, cpu_T[1]);
1749 asi = GET_FIELD(insn, 19, 26);
1750 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_tmp64, tcg_const_i32(asi),
1751 tcg_const_i32(size));
1754 static inline void gen_swap_asi(int insn)
1759 r_temp = tcg_temp_new(TCG_TYPE_I32);
1760 asi = GET_FIELD(insn, 19, 26);
1761 tcg_gen_helper_1_4(helper_ld_asi, r_temp, cpu_T[0], tcg_const_i32(asi),
1762 tcg_const_i32(4), tcg_const_i32(0));
1763 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_T[1], tcg_const_i32(asi),
1765 tcg_gen_extu_i32_tl(cpu_T[1], r_temp);
1766 tcg_gen_discard_i32(r_temp);
1769 static inline void gen_ldda_asi(int insn)
1773 asi = GET_FIELD(insn, 19, 26);
1774 tcg_gen_helper_1_4(helper_ld_asi, cpu_tmp64, cpu_T[0], tcg_const_i32(asi),
1775 tcg_const_i32(8), tcg_const_i32(0));
1776 tcg_gen_trunc_i64_tl(cpu_T[0], cpu_tmp64);
1777 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
1778 tcg_gen_trunc_i64_tl(cpu_T[1], cpu_tmp64);
1781 static inline void gen_stda_asi(int insn, int rd)
1786 r_temp = tcg_temp_new(TCG_TYPE_I32);
1787 gen_movl_reg_TN(rd + 1, r_temp);
1788 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_T[1], r_temp);
1789 asi = GET_FIELD(insn, 19, 26);
1790 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], cpu_tmp64, tcg_const_i32(asi),
1795 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
1796 static inline void gen_ldstub_asi(int insn)
1800 gen_ld_asi(insn, 1, 0);
1802 asi = GET_FIELD(insn, 19, 26);
1803 tcg_gen_helper_0_4(helper_st_asi, cpu_T[0], tcg_const_i64(0xffULL),
1804 tcg_const_i32(asi), tcg_const_i32(1));
1808 /* before an instruction, dc->pc must be static */
1809 static void disas_sparc_insn(DisasContext * dc)
1811 unsigned int insn, opc, rs1, rs2, rd;
1813 insn = ldl_code(dc->pc);
1814 opc = GET_FIELD(insn, 0, 1);
1816 rd = GET_FIELD(insn, 2, 6);
1818 case 0: /* branches/sethi */
1820 unsigned int xop = GET_FIELD(insn, 7, 9);
1823 #ifdef TARGET_SPARC64
1824 case 0x1: /* V9 BPcc */
1828 target = GET_FIELD_SP(insn, 0, 18);
1829 target = sign_extend(target, 18);
1831 cc = GET_FIELD_SP(insn, 20, 21);
1833 do_branch(dc, target, insn, 0);
1835 do_branch(dc, target, insn, 1);
1840 case 0x3: /* V9 BPr */
1842 target = GET_FIELD_SP(insn, 0, 13) |
1843 (GET_FIELD_SP(insn, 20, 21) << 14);
1844 target = sign_extend(target, 16);
1846 rs1 = GET_FIELD(insn, 13, 17);
1847 gen_movl_reg_TN(rs1, cpu_T[0]);
1848 do_branch_reg(dc, target, insn);
1851 case 0x5: /* V9 FBPcc */
1853 int cc = GET_FIELD_SP(insn, 20, 21);
1854 if (gen_trap_ifnofpu(dc))
1856 target = GET_FIELD_SP(insn, 0, 18);
1857 target = sign_extend(target, 19);
1859 do_fbranch(dc, target, insn, cc);
1863 case 0x7: /* CBN+x */
1868 case 0x2: /* BN+x */
1870 target = GET_FIELD(insn, 10, 31);
1871 target = sign_extend(target, 22);
1873 do_branch(dc, target, insn, 0);
1876 case 0x6: /* FBN+x */
1878 if (gen_trap_ifnofpu(dc))
1880 target = GET_FIELD(insn, 10, 31);
1881 target = sign_extend(target, 22);
1883 do_fbranch(dc, target, insn, 0);
1886 case 0x4: /* SETHI */
1891 uint32_t value = GET_FIELD(insn, 10, 31);
1892 tcg_gen_movi_tl(cpu_T[0], value << 10);
1893 gen_movl_TN_reg(rd, cpu_T[0]);
1898 case 0x0: /* UNIMPL */
1907 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1909 gen_movl_TN_reg(15, tcg_const_tl(dc->pc));
1915 case 2: /* FPU & Logical Operations */
1917 unsigned int xop = GET_FIELD(insn, 7, 12);
1918 if (xop == 0x3a) { /* generate trap */
1921 rs1 = GET_FIELD(insn, 13, 17);
1922 gen_movl_reg_TN(rs1, cpu_T[0]);
1924 rs2 = GET_FIELD(insn, 25, 31);
1925 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], rs2);
1927 rs2 = GET_FIELD(insn, 27, 31);
1931 gen_movl_reg_TN(rs2, cpu_T[1]);
1932 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1937 cond = GET_FIELD(insn, 3, 6);
1940 tcg_gen_helper_0_1(helper_trap, cpu_T[0]);
1941 } else if (cond != 0) {
1942 TCGv r_cond = tcg_temp_new(TCG_TYPE_TL);
1943 #ifdef TARGET_SPARC64
1945 int cc = GET_FIELD_SP(insn, 11, 12);
1949 gen_cond(r_cond, 0, cond);
1951 gen_cond(r_cond, 1, cond);
1956 gen_cond(r_cond, 0, cond);
1958 tcg_gen_helper_0_2(helper_trapcc, cpu_T[0], r_cond);
1959 tcg_gen_discard_tl(r_cond);
1965 } else if (xop == 0x28) {
1966 rs1 = GET_FIELD(insn, 13, 17);
1969 #ifndef TARGET_SPARC64
1970 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1971 manual, rdy on the microSPARC
1973 case 0x0f: /* stbar in the SPARCv8 manual,
1974 rdy on the microSPARC II */
1975 case 0x10 ... 0x1f: /* implementation-dependent in the
1976 SPARCv8 manual, rdy on the
1979 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, y));
1980 gen_movl_TN_reg(rd, cpu_T[0]);
1982 #ifdef TARGET_SPARC64
1983 case 0x2: /* V9 rdccr */
1984 tcg_gen_helper_1_0(helper_rdccr, cpu_T[0]);
1985 gen_movl_TN_reg(rd, cpu_T[0]);
1987 case 0x3: /* V9 rdasi */
1988 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
1989 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
1990 gen_movl_TN_reg(rd, cpu_T[0]);
1992 case 0x4: /* V9 rdtick */
1996 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
1997 tcg_gen_ld_ptr(r_tickptr, cpu_env,
1998 offsetof(CPUState, tick));
1999 tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0],
2001 gen_movl_TN_reg(rd, cpu_T[0]);
2002 tcg_gen_discard_ptr(r_tickptr);
2005 case 0x5: /* V9 rdpc */
2006 tcg_gen_movi_tl(cpu_T[0], dc->pc);
2007 gen_movl_TN_reg(rd, cpu_T[0]);
2009 case 0x6: /* V9 rdfprs */
2010 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
2011 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2012 gen_movl_TN_reg(rd, cpu_T[0]);
2014 case 0xf: /* V9 membar */
2015 break; /* no effect */
2016 case 0x13: /* Graphics Status */
2017 if (gen_trap_ifnofpu(dc))
2019 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, gsr));
2020 gen_movl_TN_reg(rd, cpu_T[0]);
2022 case 0x17: /* Tick compare */
2023 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, tick_cmpr));
2024 gen_movl_TN_reg(rd, cpu_T[0]);
2026 case 0x18: /* System tick */
2030 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2031 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2032 offsetof(CPUState, stick));
2033 tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0],
2035 gen_movl_TN_reg(rd, cpu_T[0]);
2036 tcg_gen_discard_ptr(r_tickptr);
2039 case 0x19: /* System tick compare */
2040 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, stick_cmpr));
2041 gen_movl_TN_reg(rd, cpu_T[0]);
2043 case 0x10: /* Performance Control */
2044 case 0x11: /* Performance Instrumentation Counter */
2045 case 0x12: /* Dispatch Control */
2046 case 0x14: /* Softint set, WO */
2047 case 0x15: /* Softint clear, WO */
2048 case 0x16: /* Softint write */
2053 #if !defined(CONFIG_USER_ONLY)
2054 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
2055 #ifndef TARGET_SPARC64
2056 if (!supervisor(dc))
2058 tcg_gen_helper_1_0(helper_rdpsr, cpu_T[0]);
2060 if (!hypervisor(dc))
2062 rs1 = GET_FIELD(insn, 13, 17);
2065 // gen_op_rdhpstate();
2068 // gen_op_rdhtstate();
2071 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
2072 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2075 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
2076 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2079 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hver));
2080 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2082 case 31: // hstick_cmpr
2083 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
2084 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hstick_cmpr));
2090 gen_movl_TN_reg(rd, cpu_T[0]);
2092 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
2093 if (!supervisor(dc))
2095 #ifdef TARGET_SPARC64
2096 rs1 = GET_FIELD(insn, 13, 17);
2102 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2103 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2104 offsetof(CPUState, tsptr));
2105 tcg_gen_ld_tl(cpu_T[0], r_tsptr,
2106 offsetof(trap_state, tpc));
2107 tcg_gen_discard_ptr(r_tsptr);
2114 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2115 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2116 offsetof(CPUState, tsptr));
2117 tcg_gen_ld_tl(cpu_T[0], r_tsptr,
2118 offsetof(trap_state, tnpc));
2119 tcg_gen_discard_ptr(r_tsptr);
2126 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2127 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2128 offsetof(CPUState, tsptr));
2129 tcg_gen_ld_tl(cpu_T[0], r_tsptr,
2130 offsetof(trap_state, tstate));
2131 tcg_gen_discard_ptr(r_tsptr);
2138 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
2139 tcg_gen_ld_ptr(r_tsptr, cpu_env,
2140 offsetof(CPUState, tsptr));
2141 tcg_gen_ld_i32(cpu_T[0], r_tsptr,
2142 offsetof(trap_state, tt));
2143 tcg_gen_discard_ptr(r_tsptr);
2150 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
2151 tcg_gen_ld_ptr(r_tickptr, cpu_env,
2152 offsetof(CPUState, tick));
2153 tcg_gen_helper_1_1(helper_tick_get_count, cpu_T[0],
2155 gen_movl_TN_reg(rd, cpu_T[0]);
2156 tcg_gen_discard_ptr(r_tickptr);
2160 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, tbr));
2163 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, pstate));
2164 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2167 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
2168 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2171 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
2172 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2175 tcg_gen_helper_1_0(helper_rdcwp, cpu_T[0]);
2178 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
2179 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2181 case 11: // canrestore
2182 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
2183 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2185 case 12: // cleanwin
2186 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
2187 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2189 case 13: // otherwin
2190 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
2191 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2194 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
2195 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2197 case 16: // UA2005 gl
2198 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
2199 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2201 case 26: // UA2005 strand status
2202 if (!hypervisor(dc))
2204 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
2205 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2208 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, version));
2215 tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
2216 tcg_gen_ext_i32_tl(cpu_T[0], cpu_tmp32);
2218 gen_movl_TN_reg(rd, cpu_T[0]);
2220 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
2221 #ifdef TARGET_SPARC64
2222 tcg_gen_helper_0_0(helper_flushw);
2224 if (!supervisor(dc))
2226 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, tbr));
2227 gen_movl_TN_reg(rd, cpu_T[0]);
2231 } else if (xop == 0x34) { /* FPU Operations */
2232 if (gen_trap_ifnofpu(dc))
2234 gen_op_clear_ieee_excp_and_FTT();
2235 rs1 = GET_FIELD(insn, 13, 17);
2236 rs2 = GET_FIELD(insn, 27, 31);
2237 xop = GET_FIELD(insn, 18, 26);
2239 case 0x1: /* fmovs */
2240 gen_op_load_fpr_FT0(rs2);
2241 gen_op_store_FT0_fpr(rd);
2243 case 0x5: /* fnegs */
2244 gen_op_load_fpr_FT1(rs2);
2245 tcg_gen_helper_0_0(helper_fnegs);
2246 gen_op_store_FT0_fpr(rd);
2248 case 0x9: /* fabss */
2249 gen_op_load_fpr_FT1(rs2);
2250 tcg_gen_helper_0_0(helper_fabss);
2251 gen_op_store_FT0_fpr(rd);
2253 case 0x29: /* fsqrts */
2254 gen_op_load_fpr_FT1(rs2);
2255 gen_clear_float_exceptions();
2256 tcg_gen_helper_0_0(helper_fsqrts);
2257 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2258 gen_op_store_FT0_fpr(rd);
2260 case 0x2a: /* fsqrtd */
2261 gen_op_load_fpr_DT1(DFPREG(rs2));
2262 gen_clear_float_exceptions();
2263 tcg_gen_helper_0_0(helper_fsqrtd);
2264 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2265 gen_op_store_DT0_fpr(DFPREG(rd));
2267 case 0x2b: /* fsqrtq */
2268 #if defined(CONFIG_USER_ONLY)
2269 gen_op_load_fpr_QT1(QFPREG(rs2));
2270 gen_clear_float_exceptions();
2271 tcg_gen_helper_0_0(helper_fsqrtq);
2272 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2273 gen_op_store_QT0_fpr(QFPREG(rd));
2279 gen_op_load_fpr_FT0(rs1);
2280 gen_op_load_fpr_FT1(rs2);
2281 gen_clear_float_exceptions();
2282 tcg_gen_helper_0_0(helper_fadds);
2283 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2284 gen_op_store_FT0_fpr(rd);
2287 gen_op_load_fpr_DT0(DFPREG(rs1));
2288 gen_op_load_fpr_DT1(DFPREG(rs2));
2289 gen_clear_float_exceptions();
2290 tcg_gen_helper_0_0(helper_faddd);
2291 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2292 gen_op_store_DT0_fpr(DFPREG(rd));
2294 case 0x43: /* faddq */
2295 #if defined(CONFIG_USER_ONLY)
2296 gen_op_load_fpr_QT0(QFPREG(rs1));
2297 gen_op_load_fpr_QT1(QFPREG(rs2));
2298 gen_clear_float_exceptions();
2299 tcg_gen_helper_0_0(helper_faddq);
2300 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2301 gen_op_store_QT0_fpr(QFPREG(rd));
2307 gen_op_load_fpr_FT0(rs1);
2308 gen_op_load_fpr_FT1(rs2);
2309 gen_clear_float_exceptions();
2310 tcg_gen_helper_0_0(helper_fsubs);
2311 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2312 gen_op_store_FT0_fpr(rd);
2315 gen_op_load_fpr_DT0(DFPREG(rs1));
2316 gen_op_load_fpr_DT1(DFPREG(rs2));
2317 gen_clear_float_exceptions();
2318 tcg_gen_helper_0_0(helper_fsubd);
2319 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2320 gen_op_store_DT0_fpr(DFPREG(rd));
2322 case 0x47: /* fsubq */
2323 #if defined(CONFIG_USER_ONLY)
2324 gen_op_load_fpr_QT0(QFPREG(rs1));
2325 gen_op_load_fpr_QT1(QFPREG(rs2));
2326 gen_clear_float_exceptions();
2327 tcg_gen_helper_0_0(helper_fsubq);
2328 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2329 gen_op_store_QT0_fpr(QFPREG(rd));
2335 gen_op_load_fpr_FT0(rs1);
2336 gen_op_load_fpr_FT1(rs2);
2337 gen_clear_float_exceptions();
2338 tcg_gen_helper_0_0(helper_fmuls);
2339 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2340 gen_op_store_FT0_fpr(rd);
2343 gen_op_load_fpr_DT0(DFPREG(rs1));
2344 gen_op_load_fpr_DT1(DFPREG(rs2));
2345 gen_clear_float_exceptions();
2346 tcg_gen_helper_0_0(helper_fmuld);
2347 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2348 gen_op_store_DT0_fpr(DFPREG(rd));
2350 case 0x4b: /* fmulq */
2351 #if defined(CONFIG_USER_ONLY)
2352 gen_op_load_fpr_QT0(QFPREG(rs1));
2353 gen_op_load_fpr_QT1(QFPREG(rs2));
2354 gen_clear_float_exceptions();
2355 tcg_gen_helper_0_0(helper_fmulq);
2356 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2357 gen_op_store_QT0_fpr(QFPREG(rd));
2363 gen_op_load_fpr_FT0(rs1);
2364 gen_op_load_fpr_FT1(rs2);
2365 gen_clear_float_exceptions();
2366 tcg_gen_helper_0_0(helper_fdivs);
2367 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2368 gen_op_store_FT0_fpr(rd);
2371 gen_op_load_fpr_DT0(DFPREG(rs1));
2372 gen_op_load_fpr_DT1(DFPREG(rs2));
2373 gen_clear_float_exceptions();
2374 tcg_gen_helper_0_0(helper_fdivd);
2375 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2376 gen_op_store_DT0_fpr(DFPREG(rd));
2378 case 0x4f: /* fdivq */
2379 #if defined(CONFIG_USER_ONLY)
2380 gen_op_load_fpr_QT0(QFPREG(rs1));
2381 gen_op_load_fpr_QT1(QFPREG(rs2));
2382 gen_clear_float_exceptions();
2383 tcg_gen_helper_0_0(helper_fdivq);
2384 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2385 gen_op_store_QT0_fpr(QFPREG(rd));
2391 gen_op_load_fpr_FT0(rs1);
2392 gen_op_load_fpr_FT1(rs2);
2393 gen_clear_float_exceptions();
2394 tcg_gen_helper_0_0(helper_fsmuld);
2395 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2396 gen_op_store_DT0_fpr(DFPREG(rd));
2398 case 0x6e: /* fdmulq */
2399 #if defined(CONFIG_USER_ONLY)
2400 gen_op_load_fpr_DT0(DFPREG(rs1));
2401 gen_op_load_fpr_DT1(DFPREG(rs2));
2402 gen_clear_float_exceptions();
2403 tcg_gen_helper_0_0(helper_fdmulq);
2404 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2405 gen_op_store_QT0_fpr(QFPREG(rd));
2411 gen_op_load_fpr_FT1(rs2);
2412 gen_clear_float_exceptions();
2413 tcg_gen_helper_0_0(helper_fitos);
2414 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2415 gen_op_store_FT0_fpr(rd);
2418 gen_op_load_fpr_DT1(DFPREG(rs2));
2419 gen_clear_float_exceptions();
2420 tcg_gen_helper_0_0(helper_fdtos);
2421 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2422 gen_op_store_FT0_fpr(rd);
2424 case 0xc7: /* fqtos */
2425 #if defined(CONFIG_USER_ONLY)
2426 gen_op_load_fpr_QT1(QFPREG(rs2));
2427 gen_clear_float_exceptions();
2428 tcg_gen_helper_0_0(helper_fqtos);
2429 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2430 gen_op_store_FT0_fpr(rd);
2436 gen_op_load_fpr_FT1(rs2);
2437 tcg_gen_helper_0_0(helper_fitod);
2438 gen_op_store_DT0_fpr(DFPREG(rd));
2441 gen_op_load_fpr_FT1(rs2);
2442 tcg_gen_helper_0_0(helper_fstod);
2443 gen_op_store_DT0_fpr(DFPREG(rd));
2445 case 0xcb: /* fqtod */
2446 #if defined(CONFIG_USER_ONLY)
2447 gen_op_load_fpr_QT1(QFPREG(rs2));
2448 gen_clear_float_exceptions();
2449 tcg_gen_helper_0_0(helper_fqtod);
2450 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2451 gen_op_store_DT0_fpr(DFPREG(rd));
2456 case 0xcc: /* fitoq */
2457 #if defined(CONFIG_USER_ONLY)
2458 gen_op_load_fpr_FT1(rs2);
2459 tcg_gen_helper_0_0(helper_fitoq);
2460 gen_op_store_QT0_fpr(QFPREG(rd));
2465 case 0xcd: /* fstoq */
2466 #if defined(CONFIG_USER_ONLY)
2467 gen_op_load_fpr_FT1(rs2);
2468 tcg_gen_helper_0_0(helper_fstoq);
2469 gen_op_store_QT0_fpr(QFPREG(rd));
2474 case 0xce: /* fdtoq */
2475 #if defined(CONFIG_USER_ONLY)
2476 gen_op_load_fpr_DT1(DFPREG(rs2));
2477 tcg_gen_helper_0_0(helper_fdtoq);
2478 gen_op_store_QT0_fpr(QFPREG(rd));
2484 gen_op_load_fpr_FT1(rs2);
2485 gen_clear_float_exceptions();
2486 tcg_gen_helper_0_0(helper_fstoi);
2487 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2488 gen_op_store_FT0_fpr(rd);
2491 gen_op_load_fpr_DT1(DFPREG(rs2));
2492 gen_clear_float_exceptions();
2493 tcg_gen_helper_0_0(helper_fdtoi);
2494 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2495 gen_op_store_FT0_fpr(rd);
2497 case 0xd3: /* fqtoi */
2498 #if defined(CONFIG_USER_ONLY)
2499 gen_op_load_fpr_QT1(QFPREG(rs2));
2500 gen_clear_float_exceptions();
2501 tcg_gen_helper_0_0(helper_fqtoi);
2502 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2503 gen_op_store_FT0_fpr(rd);
2508 #ifdef TARGET_SPARC64
2509 case 0x2: /* V9 fmovd */
2510 gen_op_load_fpr_DT0(DFPREG(rs2));
2511 gen_op_store_DT0_fpr(DFPREG(rd));
2513 case 0x3: /* V9 fmovq */
2514 #if defined(CONFIG_USER_ONLY)
2515 gen_op_load_fpr_QT0(QFPREG(rs2));
2516 gen_op_store_QT0_fpr(QFPREG(rd));
2521 case 0x6: /* V9 fnegd */
2522 gen_op_load_fpr_DT1(DFPREG(rs2));
2523 tcg_gen_helper_0_0(helper_fnegd);
2524 gen_op_store_DT0_fpr(DFPREG(rd));
2526 case 0x7: /* V9 fnegq */
2527 #if defined(CONFIG_USER_ONLY)
2528 gen_op_load_fpr_QT1(QFPREG(rs2));
2529 tcg_gen_helper_0_0(helper_fnegq);
2530 gen_op_store_QT0_fpr(QFPREG(rd));
2535 case 0xa: /* V9 fabsd */
2536 gen_op_load_fpr_DT1(DFPREG(rs2));
2537 tcg_gen_helper_0_0(helper_fabsd);
2538 gen_op_store_DT0_fpr(DFPREG(rd));
2540 case 0xb: /* V9 fabsq */
2541 #if defined(CONFIG_USER_ONLY)
2542 gen_op_load_fpr_QT1(QFPREG(rs2));
2543 tcg_gen_helper_0_0(helper_fabsq);
2544 gen_op_store_QT0_fpr(QFPREG(rd));
2549 case 0x81: /* V9 fstox */
2550 gen_op_load_fpr_FT1(rs2);
2551 gen_clear_float_exceptions();
2552 tcg_gen_helper_0_0(helper_fstox);
2553 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2554 gen_op_store_DT0_fpr(DFPREG(rd));
2556 case 0x82: /* V9 fdtox */
2557 gen_op_load_fpr_DT1(DFPREG(rs2));
2558 gen_clear_float_exceptions();
2559 tcg_gen_helper_0_0(helper_fdtox);
2560 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2561 gen_op_store_DT0_fpr(DFPREG(rd));
2563 case 0x83: /* V9 fqtox */
2564 #if defined(CONFIG_USER_ONLY)
2565 gen_op_load_fpr_QT1(QFPREG(rs2));
2566 gen_clear_float_exceptions();
2567 tcg_gen_helper_0_0(helper_fqtox);
2568 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2569 gen_op_store_DT0_fpr(DFPREG(rd));
2574 case 0x84: /* V9 fxtos */
2575 gen_op_load_fpr_DT1(DFPREG(rs2));
2576 gen_clear_float_exceptions();
2577 tcg_gen_helper_0_0(helper_fxtos);
2578 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2579 gen_op_store_FT0_fpr(rd);
2581 case 0x88: /* V9 fxtod */
2582 gen_op_load_fpr_DT1(DFPREG(rs2));
2583 gen_clear_float_exceptions();
2584 tcg_gen_helper_0_0(helper_fxtod);
2585 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2586 gen_op_store_DT0_fpr(DFPREG(rd));
2588 case 0x8c: /* V9 fxtoq */
2589 #if defined(CONFIG_USER_ONLY)
2590 gen_op_load_fpr_DT1(DFPREG(rs2));
2591 gen_clear_float_exceptions();
2592 tcg_gen_helper_0_0(helper_fxtoq);
2593 tcg_gen_helper_0_0(helper_check_ieee_exceptions);
2594 gen_op_store_QT0_fpr(QFPREG(rd));
2603 } else if (xop == 0x35) { /* FPU Operations */
2604 #ifdef TARGET_SPARC64
2607 if (gen_trap_ifnofpu(dc))
2609 gen_op_clear_ieee_excp_and_FTT();
2610 rs1 = GET_FIELD(insn, 13, 17);
2611 rs2 = GET_FIELD(insn, 27, 31);
2612 xop = GET_FIELD(insn, 18, 26);
2613 #ifdef TARGET_SPARC64
2614 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
2617 l1 = gen_new_label();
2618 cond = GET_FIELD_SP(insn, 14, 17);
2619 rs1 = GET_FIELD(insn, 13, 17);
2620 gen_movl_reg_TN(rs1, cpu_T[0]);
2621 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
2622 tcg_const_tl(0), l1);
2623 gen_op_load_fpr_FT0(rs2);
2624 gen_op_store_FT0_fpr(rd);
2627 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
2630 l1 = gen_new_label();
2631 cond = GET_FIELD_SP(insn, 14, 17);
2632 rs1 = GET_FIELD(insn, 13, 17);
2633 gen_movl_reg_TN(rs1, cpu_T[0]);
2634 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
2635 tcg_const_tl(0), l1);
2636 gen_op_load_fpr_DT0(DFPREG(rs2));
2637 gen_op_store_DT0_fpr(DFPREG(rd));
2640 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
2641 #if defined(CONFIG_USER_ONLY)
2644 l1 = gen_new_label();
2645 cond = GET_FIELD_SP(insn, 14, 17);
2646 rs1 = GET_FIELD(insn, 13, 17);
2647 gen_movl_reg_TN(rs1, cpu_T[0]);
2648 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
2649 tcg_const_tl(0), l1);
2650 gen_op_load_fpr_QT0(QFPREG(rs2));
2651 gen_op_store_QT0_fpr(QFPREG(rd));
2660 #ifdef TARGET_SPARC64
2661 #define FMOVCC(size_FDQ, fcc) \
2666 l1 = gen_new_label(); \
2667 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2668 cond = GET_FIELD_SP(insn, 14, 17); \
2669 gen_fcond(r_cond, fcc, cond); \
2670 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2671 tcg_const_tl(0), l1); \
2672 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2673 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2674 gen_set_label(l1); \
2675 tcg_gen_discard_tl(r_cond); \
2677 case 0x001: /* V9 fmovscc %fcc0 */
2680 case 0x002: /* V9 fmovdcc %fcc0 */
2683 case 0x003: /* V9 fmovqcc %fcc0 */
2684 #if defined(CONFIG_USER_ONLY)
2690 case 0x041: /* V9 fmovscc %fcc1 */
2693 case 0x042: /* V9 fmovdcc %fcc1 */
2696 case 0x043: /* V9 fmovqcc %fcc1 */
2697 #if defined(CONFIG_USER_ONLY)
2703 case 0x081: /* V9 fmovscc %fcc2 */
2706 case 0x082: /* V9 fmovdcc %fcc2 */
2709 case 0x083: /* V9 fmovqcc %fcc2 */
2710 #if defined(CONFIG_USER_ONLY)
2716 case 0x0c1: /* V9 fmovscc %fcc3 */
2719 case 0x0c2: /* V9 fmovdcc %fcc3 */
2722 case 0x0c3: /* V9 fmovqcc %fcc3 */
2723 #if defined(CONFIG_USER_ONLY)
2730 #define FMOVCC(size_FDQ, icc) \
2735 l1 = gen_new_label(); \
2736 r_cond = tcg_temp_new(TCG_TYPE_TL); \
2737 cond = GET_FIELD_SP(insn, 14, 17); \
2738 gen_cond(r_cond, icc, cond); \
2739 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond, \
2740 tcg_const_tl(0), l1); \
2741 glue(glue(gen_op_load_fpr_, size_FDQ), T0)(glue(size_FDQ, FPREG(rs2))); \
2742 glue(glue(gen_op_store_, size_FDQ), T0_fpr)(glue(size_FDQ, FPREG(rd))); \
2743 gen_set_label(l1); \
2744 tcg_gen_discard_tl(r_cond); \
2747 case 0x101: /* V9 fmovscc %icc */
2750 case 0x102: /* V9 fmovdcc %icc */
2752 case 0x103: /* V9 fmovqcc %icc */
2753 #if defined(CONFIG_USER_ONLY)
2759 case 0x181: /* V9 fmovscc %xcc */
2762 case 0x182: /* V9 fmovdcc %xcc */
2765 case 0x183: /* V9 fmovqcc %xcc */
2766 #if defined(CONFIG_USER_ONLY)
2774 case 0x51: /* fcmps, V9 %fcc */
2775 gen_op_load_fpr_FT0(rs1);
2776 gen_op_load_fpr_FT1(rs2);
2777 gen_op_fcmps(rd & 3);
2779 case 0x52: /* fcmpd, V9 %fcc */
2780 gen_op_load_fpr_DT0(DFPREG(rs1));
2781 gen_op_load_fpr_DT1(DFPREG(rs2));
2782 gen_op_fcmpd(rd & 3);
2784 case 0x53: /* fcmpq, V9 %fcc */
2785 #if defined(CONFIG_USER_ONLY)
2786 gen_op_load_fpr_QT0(QFPREG(rs1));
2787 gen_op_load_fpr_QT1(QFPREG(rs2));
2788 gen_op_fcmpq(rd & 3);
2790 #else /* !defined(CONFIG_USER_ONLY) */
2793 case 0x55: /* fcmpes, V9 %fcc */
2794 gen_op_load_fpr_FT0(rs1);
2795 gen_op_load_fpr_FT1(rs2);
2796 gen_op_fcmpes(rd & 3);
2798 case 0x56: /* fcmped, V9 %fcc */
2799 gen_op_load_fpr_DT0(DFPREG(rs1));
2800 gen_op_load_fpr_DT1(DFPREG(rs2));
2801 gen_op_fcmped(rd & 3);
2803 case 0x57: /* fcmpeq, V9 %fcc */
2804 #if defined(CONFIG_USER_ONLY)
2805 gen_op_load_fpr_QT0(QFPREG(rs1));
2806 gen_op_load_fpr_QT1(QFPREG(rs2));
2807 gen_op_fcmpeq(rd & 3);
2809 #else/* !defined(CONFIG_USER_ONLY) */
2816 } else if (xop == 0x2) {
2819 rs1 = GET_FIELD(insn, 13, 17);
2821 // or %g0, x, y -> mov T0, x; mov y, T0
2822 if (IS_IMM) { /* immediate */
2823 rs2 = GET_FIELDs(insn, 19, 31);
2824 tcg_gen_movi_tl(cpu_T[0], (int)rs2);
2825 } else { /* register */
2826 rs2 = GET_FIELD(insn, 27, 31);
2827 gen_movl_reg_TN(rs2, cpu_T[0]);
2830 gen_movl_reg_TN(rs1, cpu_T[0]);
2831 if (IS_IMM) { /* immediate */
2832 rs2 = GET_FIELDs(insn, 19, 31);
2833 tcg_gen_ori_tl(cpu_T[0], cpu_T[0], (int)rs2);
2834 } else { /* register */
2835 // or x, %g0, y -> mov T1, x; mov y, T1
2836 rs2 = GET_FIELD(insn, 27, 31);
2838 gen_movl_reg_TN(rs2, cpu_T[1]);
2839 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2843 gen_movl_TN_reg(rd, cpu_T[0]);
2845 #ifdef TARGET_SPARC64
2846 } else if (xop == 0x25) { /* sll, V9 sllx */
2847 rs1 = GET_FIELD(insn, 13, 17);
2848 gen_movl_reg_TN(rs1, cpu_T[0]);
2849 if (IS_IMM) { /* immediate */
2850 rs2 = GET_FIELDs(insn, 20, 31);
2851 if (insn & (1 << 12)) {
2852 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f);
2854 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2855 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f);
2857 } else { /* register */
2858 rs2 = GET_FIELD(insn, 27, 31);
2859 gen_movl_reg_TN(rs2, cpu_T[1]);
2860 if (insn & (1 << 12)) {
2861 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f);
2862 tcg_gen_shl_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2864 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f);
2865 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2866 tcg_gen_shl_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2869 gen_movl_TN_reg(rd, cpu_T[0]);
2870 } else if (xop == 0x26) { /* srl, V9 srlx */
2871 rs1 = GET_FIELD(insn, 13, 17);
2872 gen_movl_reg_TN(rs1, cpu_T[0]);
2873 if (IS_IMM) { /* immediate */
2874 rs2 = GET_FIELDs(insn, 20, 31);
2875 if (insn & (1 << 12)) {
2876 tcg_gen_shri_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f);
2878 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2879 tcg_gen_shri_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f);
2881 } else { /* register */
2882 rs2 = GET_FIELD(insn, 27, 31);
2883 gen_movl_reg_TN(rs2, cpu_T[1]);
2884 if (insn & (1 << 12)) {
2885 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f);
2886 tcg_gen_shr_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2888 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f);
2889 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2890 tcg_gen_shr_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2893 gen_movl_TN_reg(rd, cpu_T[0]);
2894 } else if (xop == 0x27) { /* sra, V9 srax */
2895 rs1 = GET_FIELD(insn, 13, 17);
2896 gen_movl_reg_TN(rs1, cpu_T[0]);
2897 if (IS_IMM) { /* immediate */
2898 rs2 = GET_FIELDs(insn, 20, 31);
2899 if (insn & (1 << 12)) {
2900 tcg_gen_sari_i64(cpu_T[0], cpu_T[0], rs2 & 0x3f);
2902 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2903 tcg_gen_ext_i32_i64(cpu_T[0], cpu_T[0]);
2904 tcg_gen_sari_i64(cpu_T[0], cpu_T[0], rs2 & 0x1f);
2906 } else { /* register */
2907 rs2 = GET_FIELD(insn, 27, 31);
2908 gen_movl_reg_TN(rs2, cpu_T[1]);
2909 if (insn & (1 << 12)) {
2910 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x3f);
2911 tcg_gen_sar_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2913 tcg_gen_andi_i64(cpu_T[1], cpu_T[1], 0x1f);
2914 tcg_gen_andi_i64(cpu_T[0], cpu_T[0], 0xffffffffULL);
2915 tcg_gen_sar_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2918 gen_movl_TN_reg(rd, cpu_T[0]);
2920 } else if (xop < 0x36) {
2921 rs1 = GET_FIELD(insn, 13, 17);
2922 gen_movl_reg_TN(rs1, cpu_T[0]);
2923 if (IS_IMM) { /* immediate */
2924 rs2 = GET_FIELDs(insn, 19, 31);
2925 tcg_gen_movi_tl(cpu_T[1], (int)rs2);
2926 } else { /* register */
2927 rs2 = GET_FIELD(insn, 27, 31);
2928 gen_movl_reg_TN(rs2, cpu_T[1]);
2931 switch (xop & ~0x10) {
2934 gen_op_add_T1_T0_cc();
2936 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2939 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2941 gen_op_logic_T0_cc();
2944 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2946 gen_op_logic_T0_cc();
2949 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2951 gen_op_logic_T0_cc();
2955 gen_op_sub_T1_T0_cc();
2957 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2960 tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1);
2961 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2963 gen_op_logic_T0_cc();
2966 tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1);
2967 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2969 gen_op_logic_T0_cc();
2972 tcg_gen_xori_tl(cpu_T[1], cpu_T[1], -1);
2973 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2975 gen_op_logic_T0_cc();
2979 gen_op_addx_T1_T0_cc();
2981 gen_mov_reg_C(cpu_tmp0, cpu_psr);
2982 tcg_gen_add_tl(cpu_T[1], cpu_T[1], cpu_tmp0);
2983 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
2986 #ifdef TARGET_SPARC64
2987 case 0x9: /* V9 mulx */
2988 tcg_gen_mul_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
2992 gen_op_umul_T1_T0();
2994 gen_op_logic_T0_cc();
2997 gen_op_smul_T1_T0();
2999 gen_op_logic_T0_cc();
3003 gen_op_subx_T1_T0_cc();
3005 gen_mov_reg_C(cpu_tmp0, cpu_psr);
3006 tcg_gen_add_tl(cpu_T[1], cpu_T[1], cpu_tmp0);
3007 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3010 #ifdef TARGET_SPARC64
3011 case 0xd: /* V9 udivx */
3012 gen_trap_ifdivzero_tl(cpu_T[1]);
3013 tcg_gen_divu_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
3017 tcg_gen_helper_1_2(helper_udiv, cpu_T[0], cpu_T[0], cpu_T[1]);
3022 tcg_gen_helper_1_2(helper_sdiv, cpu_T[0], cpu_T[0], cpu_T[1]);
3029 gen_movl_TN_reg(rd, cpu_T[0]);
3032 case 0x20: /* taddcc */
3033 gen_op_tadd_T1_T0_cc();
3034 gen_movl_TN_reg(rd, cpu_T[0]);
3036 case 0x21: /* tsubcc */
3037 gen_op_tsub_T1_T0_cc();
3038 gen_movl_TN_reg(rd, cpu_T[0]);
3040 case 0x22: /* taddcctv */
3042 gen_op_tadd_T1_T0_ccTV();
3043 gen_movl_TN_reg(rd, cpu_T[0]);
3045 case 0x23: /* tsubcctv */
3047 gen_op_tsub_T1_T0_ccTV();
3048 gen_movl_TN_reg(rd, cpu_T[0]);
3050 case 0x24: /* mulscc */
3051 gen_op_mulscc_T1_T0();
3052 gen_movl_TN_reg(rd, cpu_T[0]);
3054 #ifndef TARGET_SPARC64
3055 case 0x25: /* sll */
3056 tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0x1f);
3057 tcg_gen_shl_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3058 gen_movl_TN_reg(rd, cpu_T[0]);
3060 case 0x26: /* srl */
3061 tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0x1f);
3062 tcg_gen_shr_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3063 gen_movl_TN_reg(rd, cpu_T[0]);
3065 case 0x27: /* sra */
3066 tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0x1f);
3067 tcg_gen_sar_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3068 gen_movl_TN_reg(rd, cpu_T[0]);
3075 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3076 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, y));
3078 #ifndef TARGET_SPARC64
3079 case 0x01 ... 0x0f: /* undefined in the
3083 case 0x10 ... 0x1f: /* implementation-dependent
3089 case 0x2: /* V9 wrccr */
3090 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3091 tcg_gen_helper_0_1(helper_wrccr, cpu_T[0]);
3093 case 0x3: /* V9 wrasi */
3094 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3095 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3096 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, asi));
3098 case 0x6: /* V9 wrfprs */
3099 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3100 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3101 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, fprs));
3107 case 0xf: /* V9 sir, nop if user */
3108 #if !defined(CONFIG_USER_ONLY)
3113 case 0x13: /* Graphics Status */
3114 if (gen_trap_ifnofpu(dc))
3116 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3117 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, gsr));
3119 case 0x17: /* Tick compare */
3120 #if !defined(CONFIG_USER_ONLY)
3121 if (!supervisor(dc))
3127 tcg_gen_xor_tl(cpu_T[0], cpu_T[0],
3129 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState,
3131 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3132 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3133 offsetof(CPUState, tick));
3134 tcg_gen_helper_0_2(helper_tick_set_limit,
3135 r_tickptr, cpu_T[0]);
3136 tcg_gen_discard_ptr(r_tickptr);
3139 case 0x18: /* System tick */
3140 #if !defined(CONFIG_USER_ONLY)
3141 if (!supervisor(dc))
3147 tcg_gen_xor_tl(cpu_T[0], cpu_T[0],
3149 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3150 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3151 offsetof(CPUState, stick));
3152 tcg_gen_helper_0_2(helper_tick_set_count,
3153 r_tickptr, cpu_T[0]);
3154 tcg_gen_discard_ptr(r_tickptr);
3157 case 0x19: /* System tick compare */
3158 #if !defined(CONFIG_USER_ONLY)
3159 if (!supervisor(dc))
3165 tcg_gen_xor_tl(cpu_T[0], cpu_T[0],
3167 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState,
3169 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3170 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3171 offsetof(CPUState, stick));
3172 tcg_gen_helper_0_2(helper_tick_set_limit,
3173 r_tickptr, cpu_T[0]);
3174 tcg_gen_discard_ptr(r_tickptr);
3178 case 0x10: /* Performance Control */
3179 case 0x11: /* Performance Instrumentation Counter */
3180 case 0x12: /* Dispatch Control */
3181 case 0x14: /* Softint set */
3182 case 0x15: /* Softint clear */
3183 case 0x16: /* Softint write */
3190 #if !defined(CONFIG_USER_ONLY)
3191 case 0x31: /* wrpsr, V9 saved, restored */
3193 if (!supervisor(dc))
3195 #ifdef TARGET_SPARC64
3198 tcg_gen_helper_0_0(helper_saved);
3201 tcg_gen_helper_0_0(helper_restored);
3203 case 2: /* UA2005 allclean */
3204 case 3: /* UA2005 otherw */
3205 case 4: /* UA2005 normalw */
3206 case 5: /* UA2005 invalw */
3212 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3213 tcg_gen_helper_0_1(helper_wrpsr, cpu_T[0]);
3221 case 0x32: /* wrwim, V9 wrpr */
3223 if (!supervisor(dc))
3225 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3226 #ifdef TARGET_SPARC64
3232 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3233 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3234 offsetof(CPUState, tsptr));
3235 tcg_gen_st_tl(cpu_T[0], r_tsptr,
3236 offsetof(trap_state, tpc));
3237 tcg_gen_discard_ptr(r_tsptr);
3244 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3245 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3246 offsetof(CPUState, tsptr));
3247 tcg_gen_st_tl(cpu_T[0], r_tsptr,
3248 offsetof(trap_state, tnpc));
3249 tcg_gen_discard_ptr(r_tsptr);
3256 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3257 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3258 offsetof(CPUState, tsptr));
3259 tcg_gen_st_tl(cpu_T[0], r_tsptr,
3260 offsetof(trap_state, tstate));
3261 tcg_gen_discard_ptr(r_tsptr);
3268 r_tsptr = tcg_temp_new(TCG_TYPE_PTR);
3269 tcg_gen_ld_ptr(r_tsptr, cpu_env,
3270 offsetof(CPUState, tsptr));
3271 tcg_gen_st_i32(cpu_T[0], r_tsptr,
3272 offsetof(trap_state, tt));
3273 tcg_gen_discard_ptr(r_tsptr);
3280 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3281 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3282 offsetof(CPUState, tick));
3283 tcg_gen_helper_0_2(helper_tick_set_count,
3284 r_tickptr, cpu_T[0]);
3285 tcg_gen_discard_ptr(r_tickptr);
3289 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, tbr));
3293 tcg_gen_helper_0_1(helper_wrpstate, cpu_T[0]);
3299 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3300 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, tl));
3303 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3304 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, psrpil));
3307 tcg_gen_helper_0_1(helper_wrcwp, cpu_T[0]);
3310 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3311 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cansave));
3313 case 11: // canrestore
3314 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3315 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, canrestore));
3317 case 12: // cleanwin
3318 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3319 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, cleanwin));
3321 case 13: // otherwin
3322 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3323 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, otherwin));
3326 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3327 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wstate));
3329 case 16: // UA2005 gl
3330 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3331 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, gl));
3333 case 26: // UA2005 strand status
3334 if (!hypervisor(dc))
3336 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3337 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, ssr));
3343 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], ((1 << NWINDOWS) - 1));
3344 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3345 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, wim));
3349 case 0x33: /* wrtbr, UA2005 wrhpr */
3351 #ifndef TARGET_SPARC64
3352 if (!supervisor(dc))
3354 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3355 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState, tbr));
3357 if (!hypervisor(dc))
3359 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3362 // XXX gen_op_wrhpstate();
3369 // XXX gen_op_wrhtstate();
3372 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3373 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, hintp));
3376 tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_T[0]);
3377 tcg_gen_st_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, htba));
3379 case 31: // hstick_cmpr
3383 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUSPARCState,
3385 r_tickptr = tcg_temp_new(TCG_TYPE_PTR);
3386 tcg_gen_ld_ptr(r_tickptr, cpu_env,
3387 offsetof(CPUState, hstick));
3388 tcg_gen_helper_0_2(helper_tick_set_limit,
3389 r_tickptr, cpu_T[0]);
3390 tcg_gen_discard_ptr(r_tickptr);
3393 case 6: // hver readonly
3401 #ifdef TARGET_SPARC64
3402 case 0x2c: /* V9 movcc */
3404 int cc = GET_FIELD_SP(insn, 11, 12);
3405 int cond = GET_FIELD_SP(insn, 14, 17);
3409 r_cond = tcg_temp_new(TCG_TYPE_TL);
3410 if (insn & (1 << 18)) {
3412 gen_cond(r_cond, 0, cond);
3414 gen_cond(r_cond, 1, cond);
3418 gen_fcond(r_cond, cc, cond);
3421 l1 = gen_new_label();
3423 tcg_gen_brcond_tl(TCG_COND_EQ, r_cond,
3424 tcg_const_tl(0), l1);
3425 if (IS_IMM) { /* immediate */
3426 rs2 = GET_FIELD_SPs(insn, 0, 10);
3427 tcg_gen_movi_tl(cpu_T[1], (int)rs2);
3429 rs2 = GET_FIELD_SP(insn, 0, 4);
3430 gen_movl_reg_TN(rs2, cpu_T[1]);
3432 gen_movl_TN_reg(rd, cpu_T[1]);
3434 tcg_gen_discard_tl(r_cond);
3437 case 0x2d: /* V9 sdivx */
3438 gen_op_sdivx_T1_T0();
3439 gen_movl_TN_reg(rd, cpu_T[0]);
3441 case 0x2e: /* V9 popc */
3443 if (IS_IMM) { /* immediate */
3444 rs2 = GET_FIELD_SPs(insn, 0, 12);
3445 tcg_gen_movi_tl(cpu_T[1], (int)rs2);
3446 // XXX optimize: popc(constant)
3449 rs2 = GET_FIELD_SP(insn, 0, 4);
3450 gen_movl_reg_TN(rs2, cpu_T[1]);
3452 tcg_gen_helper_1_1(helper_popc, cpu_T[0],
3454 gen_movl_TN_reg(rd, cpu_T[0]);
3456 case 0x2f: /* V9 movr */
3458 int cond = GET_FIELD_SP(insn, 10, 12);
3461 rs1 = GET_FIELD(insn, 13, 17);
3462 gen_movl_reg_TN(rs1, cpu_T[0]);
3464 l1 = gen_new_label();
3466 tcg_gen_brcond_tl(gen_tcg_cond_reg[cond], cpu_T[0],
3467 tcg_const_tl(0), l1);
3468 if (IS_IMM) { /* immediate */
3469 rs2 = GET_FIELD_SPs(insn, 0, 9);
3470 tcg_gen_movi_tl(cpu_T[1], (int)rs2);
3472 rs2 = GET_FIELD_SP(insn, 0, 4);
3473 gen_movl_reg_TN(rs2, cpu_T[1]);
3475 gen_movl_TN_reg(rd, cpu_T[1]);
3484 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
3485 #ifdef TARGET_SPARC64
3486 int opf = GET_FIELD_SP(insn, 5, 13);
3487 rs1 = GET_FIELD(insn, 13, 17);
3488 rs2 = GET_FIELD(insn, 27, 31);
3489 if (gen_trap_ifnofpu(dc))
3493 case 0x000: /* VIS I edge8cc */
3494 case 0x001: /* VIS II edge8n */
3495 case 0x002: /* VIS I edge8lcc */
3496 case 0x003: /* VIS II edge8ln */
3497 case 0x004: /* VIS I edge16cc */
3498 case 0x005: /* VIS II edge16n */
3499 case 0x006: /* VIS I edge16lcc */
3500 case 0x007: /* VIS II edge16ln */
3501 case 0x008: /* VIS I edge32cc */
3502 case 0x009: /* VIS II edge32n */
3503 case 0x00a: /* VIS I edge32lcc */
3504 case 0x00b: /* VIS II edge32ln */
3507 case 0x010: /* VIS I array8 */
3508 gen_movl_reg_TN(rs1, cpu_T[0]);
3509 gen_movl_reg_TN(rs2, cpu_T[1]);
3510 tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0],
3512 gen_movl_TN_reg(rd, cpu_T[0]);
3514 case 0x012: /* VIS I array16 */
3515 gen_movl_reg_TN(rs1, cpu_T[0]);
3516 gen_movl_reg_TN(rs2, cpu_T[1]);
3517 tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0],
3519 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], 1);
3520 gen_movl_TN_reg(rd, cpu_T[0]);
3522 case 0x014: /* VIS I array32 */
3523 gen_movl_reg_TN(rs1, cpu_T[0]);
3524 gen_movl_reg_TN(rs2, cpu_T[1]);
3525 tcg_gen_helper_1_2(helper_array8, cpu_T[0], cpu_T[0],
3527 tcg_gen_shli_i64(cpu_T[0], cpu_T[0], 2);
3528 gen_movl_TN_reg(rd, cpu_T[0]);
3530 case 0x018: /* VIS I alignaddr */
3531 gen_movl_reg_TN(rs1, cpu_T[0]);
3532 gen_movl_reg_TN(rs2, cpu_T[1]);
3533 tcg_gen_helper_1_2(helper_alignaddr, cpu_T[0], cpu_T[0],
3535 gen_movl_TN_reg(rd, cpu_T[0]);
3537 case 0x019: /* VIS II bmask */
3538 case 0x01a: /* VIS I alignaddrl */
3541 case 0x020: /* VIS I fcmple16 */
3542 gen_op_load_fpr_DT0(DFPREG(rs1));
3543 gen_op_load_fpr_DT1(DFPREG(rs2));
3544 tcg_gen_helper_0_0(helper_fcmple16);
3545 gen_op_store_DT0_fpr(DFPREG(rd));
3547 case 0x022: /* VIS I fcmpne16 */
3548 gen_op_load_fpr_DT0(DFPREG(rs1));
3549 gen_op_load_fpr_DT1(DFPREG(rs2));
3550 tcg_gen_helper_0_0(helper_fcmpne16);
3551 gen_op_store_DT0_fpr(DFPREG(rd));
3553 case 0x024: /* VIS I fcmple32 */
3554 gen_op_load_fpr_DT0(DFPREG(rs1));
3555 gen_op_load_fpr_DT1(DFPREG(rs2));
3556 tcg_gen_helper_0_0(helper_fcmple32);
3557 gen_op_store_DT0_fpr(DFPREG(rd));
3559 case 0x026: /* VIS I fcmpne32 */
3560 gen_op_load_fpr_DT0(DFPREG(rs1));
3561 gen_op_load_fpr_DT1(DFPREG(rs2));
3562 tcg_gen_helper_0_0(helper_fcmpne32);
3563 gen_op_store_DT0_fpr(DFPREG(rd));
3565 case 0x028: /* VIS I fcmpgt16 */
3566 gen_op_load_fpr_DT0(DFPREG(rs1));
3567 gen_op_load_fpr_DT1(DFPREG(rs2));
3568 tcg_gen_helper_0_0(helper_fcmpgt16);
3569 gen_op_store_DT0_fpr(DFPREG(rd));
3571 case 0x02a: /* VIS I fcmpeq16 */
3572 gen_op_load_fpr_DT0(DFPREG(rs1));
3573 gen_op_load_fpr_DT1(DFPREG(rs2));
3574 tcg_gen_helper_0_0(helper_fcmpeq16);
3575 gen_op_store_DT0_fpr(DFPREG(rd));
3577 case 0x02c: /* VIS I fcmpgt32 */
3578 gen_op_load_fpr_DT0(DFPREG(rs1));
3579 gen_op_load_fpr_DT1(DFPREG(rs2));
3580 tcg_gen_helper_0_0(helper_fcmpgt32);
3581 gen_op_store_DT0_fpr(DFPREG(rd));
3583 case 0x02e: /* VIS I fcmpeq32 */
3584 gen_op_load_fpr_DT0(DFPREG(rs1));
3585 gen_op_load_fpr_DT1(DFPREG(rs2));
3586 tcg_gen_helper_0_0(helper_fcmpeq32);
3587 gen_op_store_DT0_fpr(DFPREG(rd));
3589 case 0x031: /* VIS I fmul8x16 */
3590 gen_op_load_fpr_DT0(DFPREG(rs1));
3591 gen_op_load_fpr_DT1(DFPREG(rs2));
3592 tcg_gen_helper_0_0(helper_fmul8x16);
3593 gen_op_store_DT0_fpr(DFPREG(rd));
3595 case 0x033: /* VIS I fmul8x16au */
3596 gen_op_load_fpr_DT0(DFPREG(rs1));
3597 gen_op_load_fpr_DT1(DFPREG(rs2));
3598 tcg_gen_helper_0_0(helper_fmul8x16au);
3599 gen_op_store_DT0_fpr(DFPREG(rd));
3601 case 0x035: /* VIS I fmul8x16al */
3602 gen_op_load_fpr_DT0(DFPREG(rs1));
3603 gen_op_load_fpr_DT1(DFPREG(rs2));
3604 tcg_gen_helper_0_0(helper_fmul8x16al);
3605 gen_op_store_DT0_fpr(DFPREG(rd));
3607 case 0x036: /* VIS I fmul8sux16 */
3608 gen_op_load_fpr_DT0(DFPREG(rs1));
3609 gen_op_load_fpr_DT1(DFPREG(rs2));
3610 tcg_gen_helper_0_0(helper_fmul8sux16);
3611 gen_op_store_DT0_fpr(DFPREG(rd));
3613 case 0x037: /* VIS I fmul8ulx16 */
3614 gen_op_load_fpr_DT0(DFPREG(rs1));
3615 gen_op_load_fpr_DT1(DFPREG(rs2));
3616 tcg_gen_helper_0_0(helper_fmul8ulx16);
3617 gen_op_store_DT0_fpr(DFPREG(rd));
3619 case 0x038: /* VIS I fmuld8sux16 */
3620 gen_op_load_fpr_DT0(DFPREG(rs1));
3621 gen_op_load_fpr_DT1(DFPREG(rs2));
3622 tcg_gen_helper_0_0(helper_fmuld8sux16);
3623 gen_op_store_DT0_fpr(DFPREG(rd));
3625 case 0x039: /* VIS I fmuld8ulx16 */
3626 gen_op_load_fpr_DT0(DFPREG(rs1));
3627 gen_op_load_fpr_DT1(DFPREG(rs2));
3628 tcg_gen_helper_0_0(helper_fmuld8ulx16);
3629 gen_op_store_DT0_fpr(DFPREG(rd));
3631 case 0x03a: /* VIS I fpack32 */
3632 case 0x03b: /* VIS I fpack16 */
3633 case 0x03d: /* VIS I fpackfix */
3634 case 0x03e: /* VIS I pdist */
3637 case 0x048: /* VIS I faligndata */
3638 gen_op_load_fpr_DT0(DFPREG(rs1));
3639 gen_op_load_fpr_DT1(DFPREG(rs2));
3640 tcg_gen_helper_0_0(helper_faligndata);
3641 gen_op_store_DT0_fpr(DFPREG(rd));
3643 case 0x04b: /* VIS I fpmerge */
3644 gen_op_load_fpr_DT0(DFPREG(rs1));
3645 gen_op_load_fpr_DT1(DFPREG(rs2));
3646 tcg_gen_helper_0_0(helper_fpmerge);
3647 gen_op_store_DT0_fpr(DFPREG(rd));
3649 case 0x04c: /* VIS II bshuffle */
3652 case 0x04d: /* VIS I fexpand */
3653 gen_op_load_fpr_DT0(DFPREG(rs1));
3654 gen_op_load_fpr_DT1(DFPREG(rs2));
3655 tcg_gen_helper_0_0(helper_fexpand);
3656 gen_op_store_DT0_fpr(DFPREG(rd));
3658 case 0x050: /* VIS I fpadd16 */
3659 gen_op_load_fpr_DT0(DFPREG(rs1));
3660 gen_op_load_fpr_DT1(DFPREG(rs2));
3661 tcg_gen_helper_0_0(helper_fpadd16);
3662 gen_op_store_DT0_fpr(DFPREG(rd));
3664 case 0x051: /* VIS I fpadd16s */
3665 gen_op_load_fpr_FT0(rs1);
3666 gen_op_load_fpr_FT1(rs2);
3667 tcg_gen_helper_0_0(helper_fpadd16s);
3668 gen_op_store_FT0_fpr(rd);
3670 case 0x052: /* VIS I fpadd32 */
3671 gen_op_load_fpr_DT0(DFPREG(rs1));
3672 gen_op_load_fpr_DT1(DFPREG(rs2));
3673 tcg_gen_helper_0_0(helper_fpadd32);
3674 gen_op_store_DT0_fpr(DFPREG(rd));
3676 case 0x053: /* VIS I fpadd32s */
3677 gen_op_load_fpr_FT0(rs1);
3678 gen_op_load_fpr_FT1(rs2);
3679 tcg_gen_helper_0_0(helper_fpadd32s);
3680 gen_op_store_FT0_fpr(rd);
3682 case 0x054: /* VIS I fpsub16 */
3683 gen_op_load_fpr_DT0(DFPREG(rs1));
3684 gen_op_load_fpr_DT1(DFPREG(rs2));
3685 tcg_gen_helper_0_0(helper_fpsub16);
3686 gen_op_store_DT0_fpr(DFPREG(rd));
3688 case 0x055: /* VIS I fpsub16s */
3689 gen_op_load_fpr_FT0(rs1);
3690 gen_op_load_fpr_FT1(rs2);
3691 tcg_gen_helper_0_0(helper_fpsub16s);
3692 gen_op_store_FT0_fpr(rd);
3694 case 0x056: /* VIS I fpsub32 */
3695 gen_op_load_fpr_DT0(DFPREG(rs1));
3696 gen_op_load_fpr_DT1(DFPREG(rs2));
3697 tcg_gen_helper_0_0(helper_fpadd32);
3698 gen_op_store_DT0_fpr(DFPREG(rd));
3700 case 0x057: /* VIS I fpsub32s */
3701 gen_op_load_fpr_FT0(rs1);
3702 gen_op_load_fpr_FT1(rs2);
3703 tcg_gen_helper_0_0(helper_fpsub32s);
3704 gen_op_store_FT0_fpr(rd);
3706 case 0x060: /* VIS I fzero */
3707 tcg_gen_helper_0_0(helper_movl_DT0_0);
3708 gen_op_store_DT0_fpr(DFPREG(rd));
3710 case 0x061: /* VIS I fzeros */
3711 tcg_gen_helper_0_0(helper_movl_FT0_0);
3712 gen_op_store_FT0_fpr(rd);
3714 case 0x062: /* VIS I fnor */
3715 gen_op_load_fpr_DT0(DFPREG(rs1));
3716 gen_op_load_fpr_DT1(DFPREG(rs2));
3717 tcg_gen_helper_0_0(helper_fnor);
3718 gen_op_store_DT0_fpr(DFPREG(rd));
3720 case 0x063: /* VIS I fnors */
3721 gen_op_load_fpr_FT0(rs1);
3722 gen_op_load_fpr_FT1(rs2);
3723 tcg_gen_helper_0_0(helper_fnors);
3724 gen_op_store_FT0_fpr(rd);
3726 case 0x064: /* VIS I fandnot2 */
3727 gen_op_load_fpr_DT1(DFPREG(rs1));
3728 gen_op_load_fpr_DT0(DFPREG(rs2));
3729 tcg_gen_helper_0_0(helper_fandnot);
3730 gen_op_store_DT0_fpr(DFPREG(rd));
3732 case 0x065: /* VIS I fandnot2s */
3733 gen_op_load_fpr_FT1(rs1);
3734 gen_op_load_fpr_FT0(rs2);
3735 tcg_gen_helper_0_0(helper_fandnots);
3736 gen_op_store_FT0_fpr(rd);
3738 case 0x066: /* VIS I fnot2 */
3739 gen_op_load_fpr_DT1(DFPREG(rs2));
3740 tcg_gen_helper_0_0(helper_fnot);
3741 gen_op_store_DT0_fpr(DFPREG(rd));
3743 case 0x067: /* VIS I fnot2s */
3744 gen_op_load_fpr_FT1(rs2);
3745 tcg_gen_helper_0_0(helper_fnot);
3746 gen_op_store_FT0_fpr(rd);
3748 case 0x068: /* VIS I fandnot1 */
3749 gen_op_load_fpr_DT0(DFPREG(rs1));
3750 gen_op_load_fpr_DT1(DFPREG(rs2));
3751 tcg_gen_helper_0_0(helper_fandnot);
3752 gen_op_store_DT0_fpr(DFPREG(rd));
3754 case 0x069: /* VIS I fandnot1s */
3755 gen_op_load_fpr_FT0(rs1);
3756 gen_op_load_fpr_FT1(rs2);
3757 tcg_gen_helper_0_0(helper_fandnots);
3758 gen_op_store_FT0_fpr(rd);
3760 case 0x06a: /* VIS I fnot1 */
3761 gen_op_load_fpr_DT1(DFPREG(rs1));
3762 tcg_gen_helper_0_0(helper_fnot);
3763 gen_op_store_DT0_fpr(DFPREG(rd));
3765 case 0x06b: /* VIS I fnot1s */
3766 gen_op_load_fpr_FT1(rs1);
3767 tcg_gen_helper_0_0(helper_fnot);
3768 gen_op_store_FT0_fpr(rd);
3770 case 0x06c: /* VIS I fxor */
3771 gen_op_load_fpr_DT0(DFPREG(rs1));
3772 gen_op_load_fpr_DT1(DFPREG(rs2));
3773 tcg_gen_helper_0_0(helper_fxor);
3774 gen_op_store_DT0_fpr(DFPREG(rd));
3776 case 0x06d: /* VIS I fxors */
3777 gen_op_load_fpr_FT0(rs1);
3778 gen_op_load_fpr_FT1(rs2);
3779 tcg_gen_helper_0_0(helper_fxors);
3780 gen_op_store_FT0_fpr(rd);
3782 case 0x06e: /* VIS I fnand */
3783 gen_op_load_fpr_DT0(DFPREG(rs1));
3784 gen_op_load_fpr_DT1(DFPREG(rs2));
3785 tcg_gen_helper_0_0(helper_fnand);
3786 gen_op_store_DT0_fpr(DFPREG(rd));
3788 case 0x06f: /* VIS I fnands */
3789 gen_op_load_fpr_FT0(rs1);
3790 gen_op_load_fpr_FT1(rs2);
3791 tcg_gen_helper_0_0(helper_fnands);
3792 gen_op_store_FT0_fpr(rd);
3794 case 0x070: /* VIS I fand */
3795 gen_op_load_fpr_DT0(DFPREG(rs1));
3796 gen_op_load_fpr_DT1(DFPREG(rs2));
3797 tcg_gen_helper_0_0(helper_fand);
3798 gen_op_store_DT0_fpr(DFPREG(rd));
3800 case 0x071: /* VIS I fands */
3801 gen_op_load_fpr_FT0(rs1);
3802 gen_op_load_fpr_FT1(rs2);
3803 tcg_gen_helper_0_0(helper_fands);
3804 gen_op_store_FT0_fpr(rd);
3806 case 0x072: /* VIS I fxnor */
3807 gen_op_load_fpr_DT0(DFPREG(rs1));
3808 gen_op_load_fpr_DT1(DFPREG(rs2));
3809 tcg_gen_helper_0_0(helper_fxnor);
3810 gen_op_store_DT0_fpr(DFPREG(rd));
3812 case 0x073: /* VIS I fxnors */
3813 gen_op_load_fpr_FT0(rs1);
3814 gen_op_load_fpr_FT1(rs2);
3815 tcg_gen_helper_0_0(helper_fxnors);
3816 gen_op_store_FT0_fpr(rd);
3818 case 0x074: /* VIS I fsrc1 */
3819 gen_op_load_fpr_DT0(DFPREG(rs1));
3820 gen_op_store_DT0_fpr(DFPREG(rd));
3822 case 0x075: /* VIS I fsrc1s */
3823 gen_op_load_fpr_FT0(rs1);
3824 gen_op_store_FT0_fpr(rd);
3826 case 0x076: /* VIS I fornot2 */
3827 gen_op_load_fpr_DT1(DFPREG(rs1));
3828 gen_op_load_fpr_DT0(DFPREG(rs2));
3829 tcg_gen_helper_0_0(helper_fornot);
3830 gen_op_store_DT0_fpr(DFPREG(rd));
3832 case 0x077: /* VIS I fornot2s */
3833 gen_op_load_fpr_FT1(rs1);
3834 gen_op_load_fpr_FT0(rs2);
3835 tcg_gen_helper_0_0(helper_fornots);
3836 gen_op_store_FT0_fpr(rd);
3838 case 0x078: /* VIS I fsrc2 */
3839 gen_op_load_fpr_DT0(DFPREG(rs2));
3840 gen_op_store_DT0_fpr(DFPREG(rd));
3842 case 0x079: /* VIS I fsrc2s */
3843 gen_op_load_fpr_FT0(rs2);
3844 gen_op_store_FT0_fpr(rd);
3846 case 0x07a: /* VIS I fornot1 */
3847 gen_op_load_fpr_DT0(DFPREG(rs1));
3848 gen_op_load_fpr_DT1(DFPREG(rs2));
3849 tcg_gen_helper_0_0(helper_fornot);
3850 gen_op_store_DT0_fpr(DFPREG(rd));
3852 case 0x07b: /* VIS I fornot1s */
3853 gen_op_load_fpr_FT0(rs1);
3854 gen_op_load_fpr_FT1(rs2);
3855 tcg_gen_helper_0_0(helper_fornots);
3856 gen_op_store_FT0_fpr(rd);
3858 case 0x07c: /* VIS I for */
3859 gen_op_load_fpr_DT0(DFPREG(rs1));
3860 gen_op_load_fpr_DT1(DFPREG(rs2));
3861 tcg_gen_helper_0_0(helper_for);
3862 gen_op_store_DT0_fpr(DFPREG(rd));
3864 case 0x07d: /* VIS I fors */
3865 gen_op_load_fpr_FT0(rs1);
3866 gen_op_load_fpr_FT1(rs2);
3867 tcg_gen_helper_0_0(helper_fors);
3868 gen_op_store_FT0_fpr(rd);
3870 case 0x07e: /* VIS I fone */
3871 tcg_gen_helper_0_0(helper_movl_DT0_1);
3872 gen_op_store_DT0_fpr(DFPREG(rd));
3874 case 0x07f: /* VIS I fones */
3875 tcg_gen_helper_0_0(helper_movl_FT0_1);
3876 gen_op_store_FT0_fpr(rd);
3878 case 0x080: /* VIS I shutdown */
3879 case 0x081: /* VIS II siam */
3888 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
3889 #ifdef TARGET_SPARC64
3894 #ifdef TARGET_SPARC64
3895 } else if (xop == 0x39) { /* V9 return */
3896 rs1 = GET_FIELD(insn, 13, 17);
3898 gen_movl_reg_TN(rs1, cpu_T[0]);
3899 if (IS_IMM) { /* immediate */
3900 rs2 = GET_FIELDs(insn, 19, 31);
3901 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2);
3902 } else { /* register */
3903 rs2 = GET_FIELD(insn, 27, 31);
3907 gen_movl_reg_TN(rs2, cpu_T[1]);
3908 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3913 tcg_gen_helper_0_0(helper_restore);
3915 gen_op_check_align_T0_3();
3916 tcg_gen_mov_tl(cpu_npc, cpu_T[0]);
3917 dc->npc = DYNAMIC_PC;
3921 rs1 = GET_FIELD(insn, 13, 17);
3922 gen_movl_reg_TN(rs1, cpu_T[0]);
3923 if (IS_IMM) { /* immediate */
3924 rs2 = GET_FIELDs(insn, 19, 31);
3925 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2);
3926 } else { /* register */
3927 rs2 = GET_FIELD(insn, 27, 31);
3931 gen_movl_reg_TN(rs2, cpu_T[1]);
3932 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
3938 case 0x38: /* jmpl */
3941 tcg_gen_movi_tl(cpu_T[1], dc->pc);
3942 gen_movl_TN_reg(rd, cpu_T[1]);
3945 gen_op_check_align_T0_3();
3946 tcg_gen_mov_tl(cpu_npc, cpu_T[0]);
3947 dc->npc = DYNAMIC_PC;
3950 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
3951 case 0x39: /* rett, V9 return */
3953 if (!supervisor(dc))
3956 gen_op_check_align_T0_3();
3957 tcg_gen_mov_tl(cpu_npc, cpu_T[0]);
3958 dc->npc = DYNAMIC_PC;
3959 tcg_gen_helper_0_0(helper_rett);
3963 case 0x3b: /* flush */
3964 tcg_gen_helper_0_1(helper_flush, cpu_T[0]);
3966 case 0x3c: /* save */
3968 tcg_gen_helper_0_0(helper_save);
3969 gen_movl_TN_reg(rd, cpu_T[0]);
3971 case 0x3d: /* restore */
3973 tcg_gen_helper_0_0(helper_restore);
3974 gen_movl_TN_reg(rd, cpu_T[0]);
3976 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
3977 case 0x3e: /* V9 done/retry */
3981 if (!supervisor(dc))
3983 dc->npc = DYNAMIC_PC;
3984 dc->pc = DYNAMIC_PC;
3985 tcg_gen_helper_0_0(helper_done);
3988 if (!supervisor(dc))
3990 dc->npc = DYNAMIC_PC;
3991 dc->pc = DYNAMIC_PC;
3992 tcg_gen_helper_0_0(helper_retry);
4007 case 3: /* load/store instructions */
4009 unsigned int xop = GET_FIELD(insn, 7, 12);
4010 rs1 = GET_FIELD(insn, 13, 17);
4012 gen_movl_reg_TN(rs1, cpu_T[0]);
4013 if (xop == 0x3c || xop == 0x3e)
4015 rs2 = GET_FIELD(insn, 27, 31);
4016 gen_movl_reg_TN(rs2, cpu_T[1]);
4018 else if (IS_IMM) { /* immediate */
4019 rs2 = GET_FIELDs(insn, 19, 31);
4020 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], (int)rs2);
4021 } else { /* register */
4022 rs2 = GET_FIELD(insn, 27, 31);
4026 gen_movl_reg_TN(rs2, cpu_T[1]);
4027 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
4032 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
4033 (xop > 0x17 && xop <= 0x1d ) ||
4034 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
4036 case 0x0: /* load unsigned word */
4037 gen_op_check_align_T0_3();
4038 ABI32_MASK(cpu_T[0]);
4039 tcg_gen_qemu_ld32u(cpu_T[1], cpu_T[0], dc->mem_idx);
4041 case 0x1: /* load unsigned byte */
4042 ABI32_MASK(cpu_T[0]);
4043 tcg_gen_qemu_ld8u(cpu_T[1], cpu_T[0], dc->mem_idx);
4045 case 0x2: /* load unsigned halfword */
4046 gen_op_check_align_T0_1();
4047 ABI32_MASK(cpu_T[0]);
4048 tcg_gen_qemu_ld16u(cpu_T[1], cpu_T[0], dc->mem_idx);
4050 case 0x3: /* load double word */
4054 gen_op_check_align_T0_7();
4055 ABI32_MASK(cpu_T[0]);
4056 tcg_gen_qemu_ld64(cpu_tmp64, cpu_T[0], dc->mem_idx);
4057 tcg_gen_trunc_i64_tl(cpu_T[0], cpu_tmp64);
4058 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xffffffffULL);
4059 gen_movl_TN_reg(rd + 1, cpu_T[0]);
4060 tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
4061 tcg_gen_trunc_i64_tl(cpu_T[1], cpu_tmp64);
4062 tcg_gen_andi_tl(cpu_T[1], cpu_T[1], 0xffffffffULL);
4065 case 0x9: /* load signed byte */
4066 ABI32_MASK(cpu_T[0]);
4067 tcg_gen_qemu_ld8s(cpu_T[1], cpu_T[0], dc->mem_idx);
4069 case 0xa: /* load signed halfword */
4070 gen_op_check_align_T0_1();
4071 ABI32_MASK(cpu_T[0]);
4072 tcg_gen_qemu_ld16s(cpu_T[1], cpu_T[0], dc->mem_idx);
4074 case 0xd: /* ldstub -- XXX: should be atomically */
4075 ABI32_MASK(cpu_T[0]);
4076 tcg_gen_qemu_ld8s(cpu_T[1], cpu_T[0], dc->mem_idx);
4077 tcg_gen_qemu_st8(tcg_const_tl(0xff), cpu_T[0], dc->mem_idx);
4079 case 0x0f: /* swap register with memory. Also atomically */
4080 gen_op_check_align_T0_3();
4081 gen_movl_reg_TN(rd, cpu_T[1]);
4082 ABI32_MASK(cpu_T[0]);
4083 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_T[0], dc->mem_idx);
4084 tcg_gen_qemu_st32(cpu_T[1], cpu_T[0], dc->mem_idx);
4085 tcg_gen_extu_i32_tl(cpu_T[1], cpu_tmp32);
4087 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4088 case 0x10: /* load word alternate */
4089 #ifndef TARGET_SPARC64
4092 if (!supervisor(dc))
4095 gen_op_check_align_T0_3();
4096 gen_ld_asi(insn, 4, 0);
4098 case 0x11: /* load unsigned byte alternate */
4099 #ifndef TARGET_SPARC64
4102 if (!supervisor(dc))
4105 gen_ld_asi(insn, 1, 0);
4107 case 0x12: /* load unsigned halfword alternate */
4108 #ifndef TARGET_SPARC64
4111 if (!supervisor(dc))
4114 gen_op_check_align_T0_1();
4115 gen_ld_asi(insn, 2, 0);
4117 case 0x13: /* load double word alternate */
4118 #ifndef TARGET_SPARC64
4121 if (!supervisor(dc))
4126 gen_op_check_align_T0_7();
4128 gen_movl_TN_reg(rd + 1, cpu_T[0]);
4130 case 0x19: /* load signed byte alternate */
4131 #ifndef TARGET_SPARC64
4134 if (!supervisor(dc))
4137 gen_ld_asi(insn, 1, 1);
4139 case 0x1a: /* load signed halfword alternate */
4140 #ifndef TARGET_SPARC64
4143 if (!supervisor(dc))
4146 gen_op_check_align_T0_1();
4147 gen_ld_asi(insn, 2, 1);
4149 case 0x1d: /* ldstuba -- XXX: should be atomically */
4150 #ifndef TARGET_SPARC64
4153 if (!supervisor(dc))
4156 gen_ldstub_asi(insn);
4158 case 0x1f: /* swap reg with alt. memory. Also atomically */
4159 #ifndef TARGET_SPARC64
4162 if (!supervisor(dc))
4165 gen_op_check_align_T0_3();
4166 gen_movl_reg_TN(rd, cpu_T[1]);
4170 #ifndef TARGET_SPARC64
4171 case 0x30: /* ldc */
4172 case 0x31: /* ldcsr */
4173 case 0x33: /* lddc */
4177 #ifdef TARGET_SPARC64
4178 case 0x08: /* V9 ldsw */
4179 gen_op_check_align_T0_3();
4180 ABI32_MASK(cpu_T[0]);
4181 tcg_gen_qemu_ld32s(cpu_T[1], cpu_T[0], dc->mem_idx);
4183 case 0x0b: /* V9 ldx */
4184 gen_op_check_align_T0_7();
4185 ABI32_MASK(cpu_T[0]);
4186 tcg_gen_qemu_ld64(cpu_T[1], cpu_T[0], dc->mem_idx);
4188 case 0x18: /* V9 ldswa */
4189 gen_op_check_align_T0_3();
4190 gen_ld_asi(insn, 4, 1);
4192 case 0x1b: /* V9 ldxa */
4193 gen_op_check_align_T0_7();
4194 gen_ld_asi(insn, 8, 0);
4196 case 0x2d: /* V9 prefetch, no effect */
4198 case 0x30: /* V9 ldfa */
4199 gen_op_check_align_T0_3();
4200 gen_ldf_asi(insn, 4, rd);
4202 case 0x33: /* V9 lddfa */
4203 gen_op_check_align_T0_3();
4204 gen_ldf_asi(insn, 8, DFPREG(rd));
4206 case 0x3d: /* V9 prefetcha, no effect */
4208 case 0x32: /* V9 ldqfa */
4209 #if defined(CONFIG_USER_ONLY)
4210 gen_op_check_align_T0_3();
4211 gen_ldf_asi(insn, 16, QFPREG(rd));
4220 gen_movl_TN_reg(rd, cpu_T[1]);
4221 #ifdef TARGET_SPARC64
4224 } else if (xop >= 0x20 && xop < 0x24) {
4225 if (gen_trap_ifnofpu(dc))
4228 case 0x20: /* load fpreg */
4229 gen_op_check_align_T0_3();
4230 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_T[0], dc->mem_idx);
4231 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4232 offsetof(CPUState, fpr[rd]));
4234 case 0x21: /* load fsr */
4235 gen_op_check_align_T0_3();
4236 tcg_gen_qemu_ld32u(cpu_tmp32, cpu_T[0], dc->mem_idx);
4237 tcg_gen_st_i32(cpu_tmp32, cpu_env,
4238 offsetof(CPUState, ft0));
4239 tcg_gen_helper_0_0(helper_ldfsr);
4241 case 0x22: /* load quad fpreg */
4242 #if defined(CONFIG_USER_ONLY)
4243 gen_op_check_align_T0_7();
4245 gen_op_store_QT0_fpr(QFPREG(rd));
4250 case 0x23: /* load double fpreg */
4251 gen_op_check_align_T0_7();
4253 gen_op_store_DT0_fpr(DFPREG(rd));
4258 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
4259 xop == 0xe || xop == 0x1e) {
4260 gen_movl_reg_TN(rd, cpu_T[1]);
4262 case 0x4: /* store word */
4263 gen_op_check_align_T0_3();
4264 ABI32_MASK(cpu_T[0]);
4265 tcg_gen_qemu_st32(cpu_T[1], cpu_T[0], dc->mem_idx);
4267 case 0x5: /* store byte */
4268 ABI32_MASK(cpu_T[0]);
4269 tcg_gen_qemu_st8(cpu_T[1], cpu_T[0], dc->mem_idx);
4271 case 0x6: /* store halfword */
4272 gen_op_check_align_T0_1();
4273 ABI32_MASK(cpu_T[0]);
4274 tcg_gen_qemu_st16(cpu_T[1], cpu_T[0], dc->mem_idx);
4276 case 0x7: /* store double word */
4283 gen_op_check_align_T0_7();
4284 r_low = tcg_temp_new(TCG_TYPE_I32);
4285 gen_movl_reg_TN(rd + 1, r_low);
4286 tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_T[1],
4288 tcg_gen_qemu_st64(cpu_tmp64, cpu_T[0], dc->mem_idx);
4290 #else /* __i386__ */
4291 gen_op_check_align_T0_7();
4293 gen_movl_reg_TN(rd + 1, cpu_T[2]);
4295 #endif /* __i386__ */
4297 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
4298 case 0x14: /* store word alternate */
4299 #ifndef TARGET_SPARC64
4302 if (!supervisor(dc))
4305 gen_op_check_align_T0_3();
4306 gen_st_asi(insn, 4);
4308 case 0x15: /* store byte alternate */
4309 #ifndef TARGET_SPARC64
4312 if (!supervisor(dc))
4315 gen_st_asi(insn, 1);
4317 case 0x16: /* store halfword alternate */
4318 #ifndef TARGET_SPARC64
4321 if (!supervisor(dc))
4324 gen_op_check_align_T0_1();
4325 gen_st_asi(insn, 2);
4327 case 0x17: /* store double word alternate */
4328 #ifndef TARGET_SPARC64
4331 if (!supervisor(dc))
4337 gen_op_check_align_T0_7();
4338 gen_stda_asi(insn, rd);
4342 #ifdef TARGET_SPARC64
4343 case 0x0e: /* V9 stx */
4344 gen_op_check_align_T0_7();
4345 ABI32_MASK(cpu_T[0]);
4346 tcg_gen_qemu_st64(cpu_T[1], cpu_T[0], dc->mem_idx);
4348 case 0x1e: /* V9 stxa */
4349 gen_op_check_align_T0_7();
4350 gen_st_asi(insn, 8);
4356 } else if (xop > 0x23 && xop < 0x28) {
4357 if (gen_trap_ifnofpu(dc))
4360 case 0x24: /* store fpreg */
4361 gen_op_check_align_T0_3();
4362 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4363 offsetof(CPUState, fpr[rd]));
4364 tcg_gen_qemu_st32(cpu_tmp32, cpu_T[0], dc->mem_idx);
4366 case 0x25: /* stfsr, V9 stxfsr */
4367 #ifdef CONFIG_USER_ONLY
4368 gen_op_check_align_T0_3();
4370 tcg_gen_helper_0_0(helper_stfsr);
4371 tcg_gen_ld_i32(cpu_tmp32, cpu_env,
4372 offsetof(CPUState, ft0));
4373 tcg_gen_qemu_st32(cpu_tmp32, cpu_T[0], dc->mem_idx);
4376 #ifdef TARGET_SPARC64
4377 #if defined(CONFIG_USER_ONLY)
4378 /* V9 stqf, store quad fpreg */
4379 gen_op_check_align_T0_7();
4380 gen_op_load_fpr_QT0(QFPREG(rd));
4386 #else /* !TARGET_SPARC64 */
4387 /* stdfq, store floating point queue */
4388 #if defined(CONFIG_USER_ONLY)
4391 if (!supervisor(dc))
4393 if (gen_trap_ifnofpu(dc))
4399 gen_op_check_align_T0_7();
4400 gen_op_load_fpr_DT0(DFPREG(rd));
4406 } else if (xop > 0x33 && xop < 0x3f) {
4408 #ifdef TARGET_SPARC64
4409 case 0x34: /* V9 stfa */
4410 gen_op_check_align_T0_3();
4411 gen_op_load_fpr_FT0(rd);
4412 gen_stf_asi(insn, 4, rd);
4414 case 0x36: /* V9 stqfa */
4415 #if defined(CONFIG_USER_ONLY)
4416 gen_op_check_align_T0_7();
4417 gen_op_load_fpr_QT0(QFPREG(rd));
4418 gen_stf_asi(insn, 16, QFPREG(rd));
4423 case 0x37: /* V9 stdfa */
4424 gen_op_check_align_T0_3();
4425 gen_op_load_fpr_DT0(DFPREG(rd));
4426 gen_stf_asi(insn, 8, DFPREG(rd));
4428 case 0x3c: /* V9 casa */
4429 gen_op_check_align_T0_3();
4430 gen_cas_asi(insn, rd);
4431 gen_movl_TN_reg(rd, cpu_T[1]);
4433 case 0x3e: /* V9 casxa */
4434 gen_op_check_align_T0_7();
4435 gen_casx_asi(insn, rd);
4436 gen_movl_TN_reg(rd, cpu_T[1]);
4439 case 0x34: /* stc */
4440 case 0x35: /* stcsr */
4441 case 0x36: /* stdcq */
4442 case 0x37: /* stdc */
4454 /* default case for non jump instructions */
4455 if (dc->npc == DYNAMIC_PC) {
4456 dc->pc = DYNAMIC_PC;
4458 } else if (dc->npc == JUMP_PC) {
4459 /* we can do a static jump */
4460 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1], cpu_T[2]);
4464 dc->npc = dc->npc + 4;
4470 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_ILL_INSN));
4473 #if !defined(CONFIG_USER_ONLY)
4476 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_PRIV_INSN));
4481 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
4484 #ifndef TARGET_SPARC64
4487 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
4492 #ifndef TARGET_SPARC64
4495 tcg_gen_helper_0_1(raise_exception, tcg_const_i32(TT_NCP_INSN));
4501 static void tcg_macro_func(TCGContext *s, int macro_id, const int *dead_args)
4505 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
4506 int spc, CPUSPARCState *env)
4508 target_ulong pc_start, last_pc;
4509 uint16_t *gen_opc_end;
4510 DisasContext dc1, *dc = &dc1;
4513 memset(dc, 0, sizeof(DisasContext));
4518 dc->npc = (target_ulong) tb->cs_base;
4519 dc->mem_idx = cpu_mmu_index(env);
4520 dc->fpu_enabled = cpu_fpu_enabled(env);
4521 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
4523 cpu_tmp0 = tcg_temp_new(TCG_TYPE_TL);
4524 cpu_tmp32 = tcg_temp_new(TCG_TYPE_I32);
4525 cpu_tmp64 = tcg_temp_new(TCG_TYPE_I64);
4528 if (env->nb_breakpoints > 0) {
4529 for(j = 0; j < env->nb_breakpoints; j++) {
4530 if (env->breakpoints[j] == dc->pc) {
4531 if (dc->pc != pc_start)
4533 tcg_gen_helper_0_0(helper_debug);
4542 fprintf(logfile, "Search PC...\n");
4543 j = gen_opc_ptr - gen_opc_buf;
4547 gen_opc_instr_start[lj++] = 0;
4548 gen_opc_pc[lj] = dc->pc;
4549 gen_opc_npc[lj] = dc->npc;
4550 gen_opc_instr_start[lj] = 1;
4554 disas_sparc_insn(dc);
4558 /* if the next PC is different, we abort now */
4559 if (dc->pc != (last_pc + 4))
4561 /* if we reach a page boundary, we stop generation so that the
4562 PC of a TT_TFAULT exception is always in the right page */
4563 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
4565 /* if single step mode, we generate only one instruction and
4566 generate an exception */
4567 if (env->singlestep_enabled) {
4568 tcg_gen_movi_tl(cpu_pc, dc->pc);
4572 } while ((gen_opc_ptr < gen_opc_end) &&
4573 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
4577 if (dc->pc != DYNAMIC_PC &&
4578 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
4579 /* static PC and NPC: we can use direct chaining */
4580 gen_goto_tb(dc, 0, dc->pc, dc->npc);
4582 if (dc->pc != DYNAMIC_PC)
4583 tcg_gen_movi_tl(cpu_pc, dc->pc);
4588 *gen_opc_ptr = INDEX_op_end;
4590 j = gen_opc_ptr - gen_opc_buf;
4593 gen_opc_instr_start[lj++] = 0;
4599 gen_opc_jump_pc[0] = dc->jump_pc[0];
4600 gen_opc_jump_pc[1] = dc->jump_pc[1];
4602 tb->size = last_pc + 4 - pc_start;
4605 if (loglevel & CPU_LOG_TB_IN_ASM) {
4606 fprintf(logfile, "--------------\n");
4607 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
4608 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
4609 fprintf(logfile, "\n");
4615 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
4617 return gen_intermediate_code_internal(tb, 0, env);
4620 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
4622 return gen_intermediate_code_internal(tb, 1, env);
4625 void cpu_reset(CPUSPARCState *env)
4630 env->regwptr = env->regbase + (env->cwp * 16);
4631 #if defined(CONFIG_USER_ONLY)
4632 env->user_mode_only = 1;
4633 #ifdef TARGET_SPARC64
4634 env->cleanwin = NWINDOWS - 2;
4635 env->cansave = NWINDOWS - 2;
4636 env->pstate = PS_RMO | PS_PEF | PS_IE;
4637 env->asi = 0x82; // Primary no-fault
4643 #ifdef TARGET_SPARC64
4644 env->pstate = PS_PRIV;
4645 env->hpstate = HS_PRIV;
4646 env->pc = 0x1fff0000000ULL;
4647 env->tsptr = &env->ts[env->tl];
4650 env->mmuregs[0] &= ~(MMU_E | MMU_NF);
4651 env->mmuregs[0] |= env->mmu_bm;
4653 env->npc = env->pc + 4;
4657 CPUSPARCState *cpu_sparc_init(const char *cpu_model)
4660 const sparc_def_t *def;
4663 static const char * const gregnames[8] = {
4664 NULL, // g0 not used
4674 def = cpu_sparc_find_by_name(cpu_model);
4678 env = qemu_mallocz(sizeof(CPUSPARCState));
4682 env->cpu_model_str = cpu_model;
4683 env->version = def->iu_version;
4684 env->fsr = def->fpu_version;
4685 #if !defined(TARGET_SPARC64)
4686 env->mmu_bm = def->mmu_bm;
4687 env->mmu_ctpr_mask = def->mmu_ctpr_mask;
4688 env->mmu_cxr_mask = def->mmu_cxr_mask;
4689 env->mmu_sfsr_mask = def->mmu_sfsr_mask;
4690 env->mmu_trcr_mask = def->mmu_trcr_mask;
4691 env->mmuregs[0] |= def->mmu_version;
4692 cpu_sparc_set_id(env, 0);
4695 /* init various static tables */
4699 tcg_set_macro_func(&tcg_ctx, tcg_macro_func);
4700 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
4701 cpu_regwptr = tcg_global_mem_new(TCG_TYPE_PTR, TCG_AREG0,
4702 offsetof(CPUState, regwptr),
4704 //#if TARGET_LONG_BITS > HOST_LONG_BITS
4705 #ifdef TARGET_SPARC64
4706 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
4707 TCG_AREG0, offsetof(CPUState, t0), "T0");
4708 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
4709 TCG_AREG0, offsetof(CPUState, t1), "T1");
4710 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
4711 TCG_AREG0, offsetof(CPUState, t2), "T2");
4712 cpu_xcc = tcg_global_mem_new(TCG_TYPE_I32,
4713 TCG_AREG0, offsetof(CPUState, xcc),
4716 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
4717 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
4718 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
4720 cpu_cc_src = tcg_global_mem_new(TCG_TYPE_TL,
4721 TCG_AREG0, offsetof(CPUState, cc_src),
4723 cpu_cc_src2 = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4724 offsetof(CPUState, cc_src2),
4726 cpu_cc_dst = tcg_global_mem_new(TCG_TYPE_TL,
4727 TCG_AREG0, offsetof(CPUState, cc_dst),
4729 cpu_psr = tcg_global_mem_new(TCG_TYPE_I32,
4730 TCG_AREG0, offsetof(CPUState, psr),
4732 cpu_fsr = tcg_global_mem_new(TCG_TYPE_TL,
4733 TCG_AREG0, offsetof(CPUState, fsr),
4735 cpu_pc = tcg_global_mem_new(TCG_TYPE_TL,
4736 TCG_AREG0, offsetof(CPUState, pc),
4738 cpu_npc = tcg_global_mem_new(TCG_TYPE_TL,
4739 TCG_AREG0, offsetof(CPUState, npc),
4741 for (i = 1; i < 8; i++)
4742 cpu_gregs[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
4743 offsetof(CPUState, gregs[i]),
4752 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
4754 #if !defined(TARGET_SPARC64)
4755 env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
4759 static const sparc_def_t sparc_defs[] = {
4760 #ifdef TARGET_SPARC64
4762 .name = "Fujitsu Sparc64",
4763 .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)
4764 | (MAXTL << 8) | (NWINDOWS - 1)),
4765 .fpu_version = 0x00000000,
4769 .name = "Fujitsu Sparc64 III",
4770 .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)
4771 | (MAXTL << 8) | (NWINDOWS - 1)),
4772 .fpu_version = 0x00000000,
4776 .name = "Fujitsu Sparc64 IV",
4777 .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)
4778 | (MAXTL << 8) | (NWINDOWS - 1)),
4779 .fpu_version = 0x00000000,
4783 .name = "Fujitsu Sparc64 V",
4784 .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)
4785 | (MAXTL << 8) | (NWINDOWS - 1)),
4786 .fpu_version = 0x00000000,
4790 .name = "TI UltraSparc I",
4791 .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
4792 | (MAXTL << 8) | (NWINDOWS - 1)),
4793 .fpu_version = 0x00000000,
4797 .name = "TI UltraSparc II",
4798 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)
4799 | (MAXTL << 8) | (NWINDOWS - 1)),
4800 .fpu_version = 0x00000000,
4804 .name = "TI UltraSparc IIi",
4805 .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)
4806 | (MAXTL << 8) | (NWINDOWS - 1)),
4807 .fpu_version = 0x00000000,
4811 .name = "TI UltraSparc IIe",
4812 .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)
4813 | (MAXTL << 8) | (NWINDOWS - 1)),
4814 .fpu_version = 0x00000000,
4818 .name = "Sun UltraSparc III",
4819 .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)
4820 | (MAXTL << 8) | (NWINDOWS - 1)),
4821 .fpu_version = 0x00000000,
4825 .name = "Sun UltraSparc III Cu",
4826 .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)
4827 | (MAXTL << 8) | (NWINDOWS - 1)),
4828 .fpu_version = 0x00000000,
4832 .name = "Sun UltraSparc IIIi",
4833 .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)
4834 | (MAXTL << 8) | (NWINDOWS - 1)),
4835 .fpu_version = 0x00000000,
4839 .name = "Sun UltraSparc IV",
4840 .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)
4841 | (MAXTL << 8) | (NWINDOWS - 1)),
4842 .fpu_version = 0x00000000,
4846 .name = "Sun UltraSparc IV+",
4847 .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)
4848 | (MAXTL << 8) | (NWINDOWS - 1)),
4849 .fpu_version = 0x00000000,
4853 .name = "Sun UltraSparc IIIi+",
4854 .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)
4855 | (MAXTL << 8) | (NWINDOWS - 1)),
4856 .fpu_version = 0x00000000,
4860 .name = "NEC UltraSparc I",
4861 .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
4862 | (MAXTL << 8) | (NWINDOWS - 1)),
4863 .fpu_version = 0x00000000,
4868 .name = "Fujitsu MB86900",
4869 .iu_version = 0x00 << 24, /* Impl 0, ver 0 */
4870 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
4871 .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */
4872 .mmu_bm = 0x00004000,
4873 .mmu_ctpr_mask = 0x007ffff0,
4874 .mmu_cxr_mask = 0x0000003f,
4875 .mmu_sfsr_mask = 0xffffffff,
4876 .mmu_trcr_mask = 0xffffffff,
4879 .name = "Fujitsu MB86904",
4880 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
4881 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
4882 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
4883 .mmu_bm = 0x00004000,
4884 .mmu_ctpr_mask = 0x00ffffc0,
4885 .mmu_cxr_mask = 0x000000ff,
4886 .mmu_sfsr_mask = 0x00016fff,
4887 .mmu_trcr_mask = 0x00ffffff,
4890 .name = "Fujitsu MB86907",
4891 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
4892 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
4893 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
4894 .mmu_bm = 0x00004000,
4895 .mmu_ctpr_mask = 0xffffffc0,
4896 .mmu_cxr_mask = 0x000000ff,
4897 .mmu_sfsr_mask = 0x00016fff,
4898 .mmu_trcr_mask = 0xffffffff,
4901 .name = "LSI L64811",
4902 .iu_version = 0x10 << 24, /* Impl 1, ver 0 */
4903 .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */
4904 .mmu_version = 0x10 << 24,
4905 .mmu_bm = 0x00004000,
4906 .mmu_ctpr_mask = 0x007ffff0,
4907 .mmu_cxr_mask = 0x0000003f,
4908 .mmu_sfsr_mask = 0xffffffff,
4909 .mmu_trcr_mask = 0xffffffff,
4912 .name = "Cypress CY7C601",
4913 .iu_version = 0x11 << 24, /* Impl 1, ver 1 */
4914 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
4915 .mmu_version = 0x10 << 24,
4916 .mmu_bm = 0x00004000,
4917 .mmu_ctpr_mask = 0x007ffff0,
4918 .mmu_cxr_mask = 0x0000003f,
4919 .mmu_sfsr_mask = 0xffffffff,
4920 .mmu_trcr_mask = 0xffffffff,
4923 .name = "Cypress CY7C611",
4924 .iu_version = 0x13 << 24, /* Impl 1, ver 3 */
4925 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
4926 .mmu_version = 0x10 << 24,
4927 .mmu_bm = 0x00004000,
4928 .mmu_ctpr_mask = 0x007ffff0,
4929 .mmu_cxr_mask = 0x0000003f,
4930 .mmu_sfsr_mask = 0xffffffff,
4931 .mmu_trcr_mask = 0xffffffff,
4934 .name = "TI SuperSparc II",
4935 .iu_version = 0x40000000,
4936 .fpu_version = 0 << 17,
4937 .mmu_version = 0x04000000,
4938 .mmu_bm = 0x00002000,
4939 .mmu_ctpr_mask = 0xffffffc0,
4940 .mmu_cxr_mask = 0x0000ffff,
4941 .mmu_sfsr_mask = 0xffffffff,
4942 .mmu_trcr_mask = 0xffffffff,
4945 .name = "TI MicroSparc I",
4946 .iu_version = 0x41000000,
4947 .fpu_version = 4 << 17,
4948 .mmu_version = 0x41000000,
4949 .mmu_bm = 0x00004000,
4950 .mmu_ctpr_mask = 0x007ffff0,
4951 .mmu_cxr_mask = 0x0000003f,
4952 .mmu_sfsr_mask = 0x00016fff,
4953 .mmu_trcr_mask = 0x0000003f,
4956 .name = "TI MicroSparc II",
4957 .iu_version = 0x42000000,
4958 .fpu_version = 4 << 17,
4959 .mmu_version = 0x02000000,
4960 .mmu_bm = 0x00004000,
4961 .mmu_ctpr_mask = 0x00ffffc0,
4962 .mmu_cxr_mask = 0x000000ff,
4963 .mmu_sfsr_mask = 0x00016fff,
4964 .mmu_trcr_mask = 0x00ffffff,
4967 .name = "TI MicroSparc IIep",
4968 .iu_version = 0x42000000,
4969 .fpu_version = 4 << 17,
4970 .mmu_version = 0x04000000,
4971 .mmu_bm = 0x00004000,
4972 .mmu_ctpr_mask = 0x00ffffc0,
4973 .mmu_cxr_mask = 0x000000ff,
4974 .mmu_sfsr_mask = 0x00016bff,
4975 .mmu_trcr_mask = 0x00ffffff,
4978 .name = "TI SuperSparc 51",
4979 .iu_version = 0x43000000,
4980 .fpu_version = 0 << 17,
4981 .mmu_version = 0x04000000,
4982 .mmu_bm = 0x00002000,
4983 .mmu_ctpr_mask = 0xffffffc0,
4984 .mmu_cxr_mask = 0x0000ffff,
4985 .mmu_sfsr_mask = 0xffffffff,
4986 .mmu_trcr_mask = 0xffffffff,
4989 .name = "TI SuperSparc 61",
4990 .iu_version = 0x44000000,
4991 .fpu_version = 0 << 17,
4992 .mmu_version = 0x04000000,
4993 .mmu_bm = 0x00002000,
4994 .mmu_ctpr_mask = 0xffffffc0,
4995 .mmu_cxr_mask = 0x0000ffff,
4996 .mmu_sfsr_mask = 0xffffffff,
4997 .mmu_trcr_mask = 0xffffffff,
5000 .name = "Ross RT625",
5001 .iu_version = 0x1e000000,
5002 .fpu_version = 1 << 17,
5003 .mmu_version = 0x1e000000,
5004 .mmu_bm = 0x00004000,
5005 .mmu_ctpr_mask = 0x007ffff0,
5006 .mmu_cxr_mask = 0x0000003f,
5007 .mmu_sfsr_mask = 0xffffffff,
5008 .mmu_trcr_mask = 0xffffffff,
5011 .name = "Ross RT620",
5012 .iu_version = 0x1f000000,
5013 .fpu_version = 1 << 17,
5014 .mmu_version = 0x1f000000,
5015 .mmu_bm = 0x00004000,
5016 .mmu_ctpr_mask = 0x007ffff0,
5017 .mmu_cxr_mask = 0x0000003f,
5018 .mmu_sfsr_mask = 0xffffffff,
5019 .mmu_trcr_mask = 0xffffffff,
5022 .name = "BIT B5010",
5023 .iu_version = 0x20000000,
5024 .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */
5025 .mmu_version = 0x20000000,
5026 .mmu_bm = 0x00004000,
5027 .mmu_ctpr_mask = 0x007ffff0,
5028 .mmu_cxr_mask = 0x0000003f,
5029 .mmu_sfsr_mask = 0xffffffff,
5030 .mmu_trcr_mask = 0xffffffff,
5033 .name = "Matsushita MN10501",
5034 .iu_version = 0x50000000,
5035 .fpu_version = 0 << 17,
5036 .mmu_version = 0x50000000,
5037 .mmu_bm = 0x00004000,
5038 .mmu_ctpr_mask = 0x007ffff0,
5039 .mmu_cxr_mask = 0x0000003f,
5040 .mmu_sfsr_mask = 0xffffffff,
5041 .mmu_trcr_mask = 0xffffffff,
5044 .name = "Weitek W8601",
5045 .iu_version = 0x90 << 24, /* Impl 9, ver 0 */
5046 .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
5047 .mmu_version = 0x10 << 24,
5048 .mmu_bm = 0x00004000,
5049 .mmu_ctpr_mask = 0x007ffff0,
5050 .mmu_cxr_mask = 0x0000003f,
5051 .mmu_sfsr_mask = 0xffffffff,
5052 .mmu_trcr_mask = 0xffffffff,
5056 .iu_version = 0xf2000000,
5057 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
5058 .mmu_version = 0xf2000000,
5059 .mmu_bm = 0x00004000,
5060 .mmu_ctpr_mask = 0x007ffff0,
5061 .mmu_cxr_mask = 0x0000003f,
5062 .mmu_sfsr_mask = 0xffffffff,
5063 .mmu_trcr_mask = 0xffffffff,
5067 .iu_version = 0xf3000000,
5068 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
5069 .mmu_version = 0xf3000000,
5070 .mmu_bm = 0x00004000,
5071 .mmu_ctpr_mask = 0x007ffff0,
5072 .mmu_cxr_mask = 0x0000003f,
5073 .mmu_sfsr_mask = 0xffffffff,
5074 .mmu_trcr_mask = 0xffffffff,
5079 static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name)
5083 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
5084 if (strcasecmp(name, sparc_defs[i].name) == 0) {
5085 return &sparc_defs[i];
5091 void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
5095 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
5096 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x\n",
5098 sparc_defs[i].iu_version,
5099 sparc_defs[i].fpu_version,
5100 sparc_defs[i].mmu_version);
5104 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
5106 void cpu_dump_state(CPUState *env, FILE *f,
5107 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5112 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, env->npc);
5113 cpu_fprintf(f, "General Registers:\n");
5114 for (i = 0; i < 4; i++)
5115 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
5116 cpu_fprintf(f, "\n");
5118 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
5119 cpu_fprintf(f, "\nCurrent Register Window:\n");
5120 for (x = 0; x < 3; x++) {
5121 for (i = 0; i < 4; i++)
5122 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
5123 (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i,
5124 env->regwptr[i + x * 8]);
5125 cpu_fprintf(f, "\n");
5127 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
5128 (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i,
5129 env->regwptr[i + x * 8]);
5130 cpu_fprintf(f, "\n");
5132 cpu_fprintf(f, "\nFloating Point Registers:\n");
5133 for (i = 0; i < 32; i++) {
5135 cpu_fprintf(f, "%%f%02d:", i);
5136 cpu_fprintf(f, " %016lf", env->fpr[i]);
5138 cpu_fprintf(f, "\n");
5140 #ifdef TARGET_SPARC64
5141 cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
5142 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs);
5143 cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
5144 env->cansave, env->canrestore, env->otherwin, env->wstate,
5145 env->cleanwin, NWINDOWS - 1 - env->cwp);
5147 cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env),
5148 GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'),
5149 GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'),
5150 env->psrs?'S':'-', env->psrps?'P':'-',
5151 env->psret?'E':'-', env->wim);
5153 cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env));
5156 #if defined(CONFIG_USER_ONLY)
5157 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
5163 extern int get_physical_address (CPUState *env, target_phys_addr_t *physical, int *prot,
5164 int *access_index, target_ulong address, int rw,
5167 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
5169 target_phys_addr_t phys_addr;
5170 int prot, access_index;
5172 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2,
5173 MMU_KERNEL_IDX) != 0)
5174 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr,
5175 0, MMU_KERNEL_IDX) != 0)
5177 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED)
5183 void helper_flush(target_ulong addr)
5186 tb_invalidate_page_range(addr, addr + 8);