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
43 #define DYNAMIC_PC 1 /* dynamic pc value */
44 #define JUMP_PC 2 /* dynamic pc value which takes only two values
45 according to jump_pc[T2] */
47 typedef struct DisasContext {
48 target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */
49 target_ulong npc; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
50 target_ulong jump_pc[2]; /* used when JUMP_PC pc value is used */
54 struct TranslationBlock *tb;
58 const unsigned char *name;
59 target_ulong iu_version;
65 static uint16_t *gen_opc_ptr;
66 static uint32_t *gen_opparam_ptr;
71 #define DEF(s,n,copy_size) INDEX_op_ ## s,
79 // This function uses non-native bit order
80 #define GET_FIELD(X, FROM, TO) \
81 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
83 // This function uses the order in the manuals, i.e. bit 0 is 2^0
84 #define GET_FIELD_SP(X, FROM, TO) \
85 GET_FIELD(X, 31 - (TO), 31 - (FROM))
87 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
88 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
91 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
93 #define DFPREG(r) (r & 0x1e)
96 #ifdef USE_DIRECT_JUMP
99 #define TBPARAM(x) (long)(x)
102 static int sign_extend(int x, int len)
105 return (x << len) >> len;
108 #define IS_IMM (insn & (1<<13))
110 static void disas_sparc_insn(DisasContext * dc);
112 static GenOpFunc * const gen_op_movl_TN_reg[2][32] = {
183 static GenOpFunc * const gen_op_movl_reg_TN[3][32] = {
288 static GenOpFunc1 * const gen_op_movl_TN_im[3] = {
294 // Sign extending version
295 static GenOpFunc1 * const gen_op_movl_TN_sim[3] = {
301 #ifdef TARGET_SPARC64
302 #define GEN32(func, NAME) \
303 static GenOpFunc * const NAME ## _table [64] = { \
304 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
305 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
306 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
307 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
308 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
309 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
310 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
311 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
312 NAME ## 32, 0, NAME ## 34, 0, NAME ## 36, 0, NAME ## 38, 0, \
313 NAME ## 40, 0, NAME ## 42, 0, NAME ## 44, 0, NAME ## 46, 0, \
314 NAME ## 48, 0, NAME ## 50, 0, NAME ## 52, 0, NAME ## 54, 0, \
315 NAME ## 56, 0, NAME ## 58, 0, NAME ## 60, 0, NAME ## 62, 0, \
317 static inline void func(int n) \
319 NAME ## _table[n](); \
322 #define GEN32(func, NAME) \
323 static GenOpFunc *const NAME ## _table [32] = { \
324 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
325 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
326 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
327 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
328 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
329 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
330 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
331 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
333 static inline void func(int n) \
335 NAME ## _table[n](); \
339 /* floating point registers moves */
340 GEN32(gen_op_load_fpr_FT0, gen_op_load_fpr_FT0_fprf);
341 GEN32(gen_op_load_fpr_FT1, gen_op_load_fpr_FT1_fprf);
342 GEN32(gen_op_store_FT0_fpr, gen_op_store_FT0_fpr_fprf);
343 GEN32(gen_op_store_FT1_fpr, gen_op_store_FT1_fpr_fprf);
345 GEN32(gen_op_load_fpr_DT0, gen_op_load_fpr_DT0_fprf);
346 GEN32(gen_op_load_fpr_DT1, gen_op_load_fpr_DT1_fprf);
347 GEN32(gen_op_store_DT0_fpr, gen_op_store_DT0_fpr_fprf);
348 GEN32(gen_op_store_DT1_fpr, gen_op_store_DT1_fpr_fprf);
351 #ifdef CONFIG_USER_ONLY
352 #define supervisor(dc) 0
353 #ifdef TARGET_SPARC64
354 #define hypervisor(dc) 0
356 #define gen_op_ldst(name) gen_op_##name##_raw()
358 #define supervisor(dc) (dc->mem_idx >= 1)
359 #ifdef TARGET_SPARC64
360 #define hypervisor(dc) (dc->mem_idx == 2)
361 #define OP_LD_TABLE(width) \
362 static GenOpFunc * const gen_op_##width[] = { \
363 &gen_op_##width##_user, \
364 &gen_op_##width##_kernel, \
365 &gen_op_##width##_hypv, \
368 #define OP_LD_TABLE(width) \
369 static GenOpFunc * const gen_op_##width[] = { \
370 &gen_op_##width##_user, \
371 &gen_op_##width##_kernel, \
374 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
377 #ifndef CONFIG_USER_ONLY
395 #ifdef TARGET_SPARC64
404 #ifdef TARGET_SPARC64
405 static inline void gen_ld_asi(int insn, int size, int sign)
410 offset = GET_FIELD(insn, 25, 31);
411 gen_op_ld_asi_reg(offset, size, sign);
413 asi = GET_FIELD(insn, 19, 26);
414 gen_op_ld_asi(asi, size, sign);
418 static inline void gen_st_asi(int insn, int size)
423 offset = GET_FIELD(insn, 25, 31);
424 gen_op_st_asi_reg(offset, size);
426 asi = GET_FIELD(insn, 19, 26);
427 gen_op_st_asi(asi, size);
431 static inline void gen_ldf_asi(int insn, int size)
435 rd = DFPREG(GET_FIELD(insn, 2, 6));
437 offset = GET_FIELD(insn, 25, 31);
438 gen_op_ldf_asi_reg(offset, size, rd);
440 asi = GET_FIELD(insn, 19, 26);
441 gen_op_ldf_asi(asi, size, rd);
445 static inline void gen_stf_asi(int insn, int size)
449 rd = DFPREG(GET_FIELD(insn, 2, 6));
451 offset = GET_FIELD(insn, 25, 31);
452 gen_op_stf_asi_reg(offset, size, rd);
454 asi = GET_FIELD(insn, 19, 26);
455 gen_op_stf_asi(asi, size, rd);
459 static inline void gen_swap_asi(int insn)
464 offset = GET_FIELD(insn, 25, 31);
465 gen_op_swap_asi_reg(offset);
467 asi = GET_FIELD(insn, 19, 26);
468 gen_op_swap_asi(asi);
472 static inline void gen_ldstub_asi(int insn)
477 offset = GET_FIELD(insn, 25, 31);
478 gen_op_ldstub_asi_reg(offset);
480 asi = GET_FIELD(insn, 19, 26);
481 gen_op_ldstub_asi(asi);
485 static inline void gen_ldda_asi(int insn)
490 offset = GET_FIELD(insn, 25, 31);
491 gen_op_ldda_asi_reg(offset);
493 asi = GET_FIELD(insn, 19, 26);
494 gen_op_ldda_asi(asi);
498 static inline void gen_stda_asi(int insn)
503 offset = GET_FIELD(insn, 25, 31);
504 gen_op_stda_asi_reg(offset);
506 asi = GET_FIELD(insn, 19, 26);
507 gen_op_stda_asi(asi);
511 static inline void gen_cas_asi(int insn)
516 offset = GET_FIELD(insn, 25, 31);
517 gen_op_cas_asi_reg(offset);
519 asi = GET_FIELD(insn, 19, 26);
524 static inline void gen_casx_asi(int insn)
529 offset = GET_FIELD(insn, 25, 31);
530 gen_op_casx_asi_reg(offset);
532 asi = GET_FIELD(insn, 19, 26);
533 gen_op_casx_asi(asi);
537 #elif !defined(CONFIG_USER_ONLY)
539 static inline void gen_ld_asi(int insn, int size, int sign)
543 asi = GET_FIELD(insn, 19, 26);
544 gen_op_ld_asi(asi, size, sign);
547 static inline void gen_st_asi(int insn, int size)
551 asi = GET_FIELD(insn, 19, 26);
552 gen_op_st_asi(asi, size);
555 static inline void gen_ldstub_asi(int insn)
559 asi = GET_FIELD(insn, 19, 26);
560 gen_op_ldstub_asi(asi);
563 static inline void gen_swap_asi(int insn)
567 asi = GET_FIELD(insn, 19, 26);
568 gen_op_swap_asi(asi);
571 static inline void gen_ldda_asi(int insn)
575 asi = GET_FIELD(insn, 19, 26);
576 gen_op_ld_asi(asi, 8, 0);
579 static inline void gen_stda_asi(int insn)
583 asi = GET_FIELD(insn, 19, 26);
584 gen_op_st_asi(asi, 8);
588 static inline void gen_movl_imm_TN(int reg, uint32_t imm)
590 gen_op_movl_TN_im[reg](imm);
593 static inline void gen_movl_imm_T1(uint32_t val)
595 gen_movl_imm_TN(1, val);
598 static inline void gen_movl_imm_T0(uint32_t val)
600 gen_movl_imm_TN(0, val);
603 static inline void gen_movl_simm_TN(int reg, int32_t imm)
605 gen_op_movl_TN_sim[reg](imm);
608 static inline void gen_movl_simm_T1(int32_t val)
610 gen_movl_simm_TN(1, val);
613 static inline void gen_movl_simm_T0(int32_t val)
615 gen_movl_simm_TN(0, val);
618 static inline void gen_movl_reg_TN(int reg, int t)
621 gen_op_movl_reg_TN[t][reg] ();
623 gen_movl_imm_TN(t, 0);
626 static inline void gen_movl_reg_T0(int reg)
628 gen_movl_reg_TN(reg, 0);
631 static inline void gen_movl_reg_T1(int reg)
633 gen_movl_reg_TN(reg, 1);
636 static inline void gen_movl_reg_T2(int reg)
638 gen_movl_reg_TN(reg, 2);
641 static inline void gen_movl_TN_reg(int reg, int t)
644 gen_op_movl_TN_reg[t][reg] ();
647 static inline void gen_movl_T0_reg(int reg)
649 gen_movl_TN_reg(reg, 0);
652 static inline void gen_movl_T1_reg(int reg)
654 gen_movl_TN_reg(reg, 1);
657 static inline void gen_jmp_im(target_ulong pc)
659 #ifdef TARGET_SPARC64
660 if (pc == (uint32_t)pc) {
663 gen_op_jmp_im64(pc >> 32, pc);
670 static inline void gen_movl_npc_im(target_ulong npc)
672 #ifdef TARGET_SPARC64
673 if (npc == (uint32_t)npc) {
674 gen_op_movl_npc_im(npc);
676 gen_op_movq_npc_im64(npc >> 32, npc);
679 gen_op_movl_npc_im(npc);
683 static inline void gen_goto_tb(DisasContext *s, int tb_num,
684 target_ulong pc, target_ulong npc)
686 TranslationBlock *tb;
689 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
690 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
691 /* jump to same page: we can use a direct jump */
693 gen_op_goto_tb0(TBPARAM(tb));
695 gen_op_goto_tb1(TBPARAM(tb));
697 gen_movl_npc_im(npc);
698 gen_op_movl_T0_im((long)tb + tb_num);
701 /* jump to another page: currently not optimized */
703 gen_movl_npc_im(npc);
709 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
714 l1 = gen_new_label();
716 gen_op_jz_T2_label(l1);
718 gen_goto_tb(dc, 0, pc1, pc1 + 4);
721 gen_goto_tb(dc, 1, pc2, pc2 + 4);
724 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
729 l1 = gen_new_label();
731 gen_op_jz_T2_label(l1);
733 gen_goto_tb(dc, 0, pc2, pc1);
736 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
739 static inline void gen_branch(DisasContext *dc, target_ulong pc,
742 gen_goto_tb(dc, 0, pc, npc);
745 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2)
749 l1 = gen_new_label();
750 l2 = gen_new_label();
751 gen_op_jz_T2_label(l1);
753 gen_movl_npc_im(npc1);
754 gen_op_jmp_label(l2);
757 gen_movl_npc_im(npc2);
761 /* call this function before using T2 as it may have been set for a jump */
762 static inline void flush_T2(DisasContext * dc)
764 if (dc->npc == JUMP_PC) {
765 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
766 dc->npc = DYNAMIC_PC;
770 static inline void save_npc(DisasContext * dc)
772 if (dc->npc == JUMP_PC) {
773 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
774 dc->npc = DYNAMIC_PC;
775 } else if (dc->npc != DYNAMIC_PC) {
776 gen_movl_npc_im(dc->npc);
780 static inline void save_state(DisasContext * dc)
786 static inline void gen_mov_pc_npc(DisasContext * dc)
788 if (dc->npc == JUMP_PC) {
789 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
792 } else if (dc->npc == DYNAMIC_PC) {
800 static GenOpFunc * const gen_cond[2][16] = {
820 #ifdef TARGET_SPARC64
841 static GenOpFunc * const gen_fcond[4][16] = {
860 #ifdef TARGET_SPARC64
863 gen_op_eval_fbne_fcc1,
864 gen_op_eval_fblg_fcc1,
865 gen_op_eval_fbul_fcc1,
866 gen_op_eval_fbl_fcc1,
867 gen_op_eval_fbug_fcc1,
868 gen_op_eval_fbg_fcc1,
869 gen_op_eval_fbu_fcc1,
871 gen_op_eval_fbe_fcc1,
872 gen_op_eval_fbue_fcc1,
873 gen_op_eval_fbge_fcc1,
874 gen_op_eval_fbuge_fcc1,
875 gen_op_eval_fble_fcc1,
876 gen_op_eval_fbule_fcc1,
877 gen_op_eval_fbo_fcc1,
881 gen_op_eval_fbne_fcc2,
882 gen_op_eval_fblg_fcc2,
883 gen_op_eval_fbul_fcc2,
884 gen_op_eval_fbl_fcc2,
885 gen_op_eval_fbug_fcc2,
886 gen_op_eval_fbg_fcc2,
887 gen_op_eval_fbu_fcc2,
889 gen_op_eval_fbe_fcc2,
890 gen_op_eval_fbue_fcc2,
891 gen_op_eval_fbge_fcc2,
892 gen_op_eval_fbuge_fcc2,
893 gen_op_eval_fble_fcc2,
894 gen_op_eval_fbule_fcc2,
895 gen_op_eval_fbo_fcc2,
899 gen_op_eval_fbne_fcc3,
900 gen_op_eval_fblg_fcc3,
901 gen_op_eval_fbul_fcc3,
902 gen_op_eval_fbl_fcc3,
903 gen_op_eval_fbug_fcc3,
904 gen_op_eval_fbg_fcc3,
905 gen_op_eval_fbu_fcc3,
907 gen_op_eval_fbe_fcc3,
908 gen_op_eval_fbue_fcc3,
909 gen_op_eval_fbge_fcc3,
910 gen_op_eval_fbuge_fcc3,
911 gen_op_eval_fble_fcc3,
912 gen_op_eval_fbule_fcc3,
913 gen_op_eval_fbo_fcc3,
920 #ifdef TARGET_SPARC64
921 static void gen_cond_reg(int cond)
947 /* XXX: potentially incorrect if dynamic npc */
948 static void do_branch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
950 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
951 target_ulong target = dc->pc + offset;
954 /* unconditional not taken */
956 dc->pc = dc->npc + 4;
957 dc->npc = dc->pc + 4;
960 dc->npc = dc->pc + 4;
962 } else if (cond == 0x8) {
963 /* unconditional taken */
966 dc->npc = dc->pc + 4;
973 gen_cond[cc][cond]();
975 gen_branch_a(dc, target, dc->npc);
979 dc->jump_pc[0] = target;
980 dc->jump_pc[1] = dc->npc + 4;
986 /* XXX: potentially incorrect if dynamic npc */
987 static void do_fbranch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
989 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
990 target_ulong target = dc->pc + offset;
993 /* unconditional not taken */
995 dc->pc = dc->npc + 4;
996 dc->npc = dc->pc + 4;
999 dc->npc = dc->pc + 4;
1001 } else if (cond == 0x8) {
1002 /* unconditional taken */
1005 dc->npc = dc->pc + 4;
1012 gen_fcond[cc][cond]();
1014 gen_branch_a(dc, target, dc->npc);
1018 dc->jump_pc[0] = target;
1019 dc->jump_pc[1] = dc->npc + 4;
1025 #ifdef TARGET_SPARC64
1026 /* XXX: potentially incorrect if dynamic npc */
1027 static void do_branch_reg(DisasContext * dc, int32_t offset, uint32_t insn)
1029 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1030 target_ulong target = dc->pc + offset;
1035 gen_branch_a(dc, target, dc->npc);
1039 dc->jump_pc[0] = target;
1040 dc->jump_pc[1] = dc->npc + 4;
1045 static GenOpFunc * const gen_fcmps[4] = {
1052 static GenOpFunc * const gen_fcmpd[4] = {
1059 static GenOpFunc * const gen_fcmpes[4] = {
1066 static GenOpFunc * const gen_fcmped[4] = {
1075 static int gen_trap_ifnofpu(DisasContext * dc)
1077 #if !defined(CONFIG_USER_ONLY)
1078 if (!dc->fpu_enabled) {
1080 gen_op_exception(TT_NFPU_INSN);
1088 /* before an instruction, dc->pc must be static */
1089 static void disas_sparc_insn(DisasContext * dc)
1091 unsigned int insn, opc, rs1, rs2, rd;
1093 insn = ldl_code(dc->pc);
1094 opc = GET_FIELD(insn, 0, 1);
1096 rd = GET_FIELD(insn, 2, 6);
1098 case 0: /* branches/sethi */
1100 unsigned int xop = GET_FIELD(insn, 7, 9);
1103 #ifdef TARGET_SPARC64
1104 case 0x1: /* V9 BPcc */
1108 target = GET_FIELD_SP(insn, 0, 18);
1109 target = sign_extend(target, 18);
1111 cc = GET_FIELD_SP(insn, 20, 21);
1113 do_branch(dc, target, insn, 0);
1115 do_branch(dc, target, insn, 1);
1120 case 0x3: /* V9 BPr */
1122 target = GET_FIELD_SP(insn, 0, 13) |
1123 (GET_FIELD_SP(insn, 20, 21) << 14);
1124 target = sign_extend(target, 16);
1126 rs1 = GET_FIELD(insn, 13, 17);
1127 gen_movl_reg_T0(rs1);
1128 do_branch_reg(dc, target, insn);
1131 case 0x5: /* V9 FBPcc */
1133 int cc = GET_FIELD_SP(insn, 20, 21);
1134 if (gen_trap_ifnofpu(dc))
1136 target = GET_FIELD_SP(insn, 0, 18);
1137 target = sign_extend(target, 19);
1139 do_fbranch(dc, target, insn, cc);
1143 case 0x7: /* CBN+x */
1148 case 0x2: /* BN+x */
1150 target = GET_FIELD(insn, 10, 31);
1151 target = sign_extend(target, 22);
1153 do_branch(dc, target, insn, 0);
1156 case 0x6: /* FBN+x */
1158 if (gen_trap_ifnofpu(dc))
1160 target = GET_FIELD(insn, 10, 31);
1161 target = sign_extend(target, 22);
1163 do_fbranch(dc, target, insn, 0);
1166 case 0x4: /* SETHI */
1171 uint32_t value = GET_FIELD(insn, 10, 31);
1172 gen_movl_imm_T0(value << 10);
1173 gen_movl_T0_reg(rd);
1178 case 0x0: /* UNIMPL */
1187 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1189 #ifdef TARGET_SPARC64
1190 if (dc->pc == (uint32_t)dc->pc) {
1191 gen_op_movl_T0_im(dc->pc);
1193 gen_op_movq_T0_im64(dc->pc >> 32, dc->pc);
1196 gen_op_movl_T0_im(dc->pc);
1198 gen_movl_T0_reg(15);
1204 case 2: /* FPU & Logical Operations */
1206 unsigned int xop = GET_FIELD(insn, 7, 12);
1207 if (xop == 0x3a) { /* generate trap */
1210 rs1 = GET_FIELD(insn, 13, 17);
1211 gen_movl_reg_T0(rs1);
1213 rs2 = GET_FIELD(insn, 25, 31);
1217 gen_movl_simm_T1(rs2);
1223 rs2 = GET_FIELD(insn, 27, 31);
1227 gen_movl_reg_T1(rs2);
1233 cond = GET_FIELD(insn, 3, 6);
1237 } else if (cond != 0) {
1238 #ifdef TARGET_SPARC64
1240 int cc = GET_FIELD_SP(insn, 11, 12);
1244 gen_cond[0][cond]();
1246 gen_cond[1][cond]();
1252 gen_cond[0][cond]();
1261 } else if (xop == 0x28) {
1262 rs1 = GET_FIELD(insn, 13, 17);
1265 #ifndef TARGET_SPARC64
1266 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1267 manual, rdy on the microSPARC
1269 case 0x0f: /* stbar in the SPARCv8 manual,
1270 rdy on the microSPARC II */
1271 case 0x10 ... 0x1f: /* implementation-dependent in the
1272 SPARCv8 manual, rdy on the
1275 gen_op_movtl_T0_env(offsetof(CPUSPARCState, y));
1276 gen_movl_T0_reg(rd);
1278 #ifdef TARGET_SPARC64
1279 case 0x2: /* V9 rdccr */
1281 gen_movl_T0_reg(rd);
1283 case 0x3: /* V9 rdasi */
1284 gen_op_movl_T0_env(offsetof(CPUSPARCState, asi));
1285 gen_movl_T0_reg(rd);
1287 case 0x4: /* V9 rdtick */
1289 gen_movl_T0_reg(rd);
1291 case 0x5: /* V9 rdpc */
1292 if (dc->pc == (uint32_t)dc->pc) {
1293 gen_op_movl_T0_im(dc->pc);
1295 gen_op_movq_T0_im64(dc->pc >> 32, dc->pc);
1297 gen_movl_T0_reg(rd);
1299 case 0x6: /* V9 rdfprs */
1300 gen_op_movl_T0_env(offsetof(CPUSPARCState, fprs));
1301 gen_movl_T0_reg(rd);
1303 case 0xf: /* V9 membar */
1304 break; /* no effect */
1305 case 0x13: /* Graphics Status */
1306 if (gen_trap_ifnofpu(dc))
1308 gen_op_movtl_T0_env(offsetof(CPUSPARCState, gsr));
1309 gen_movl_T0_reg(rd);
1311 case 0x17: /* Tick compare */
1312 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tick_cmpr));
1313 gen_movl_T0_reg(rd);
1315 case 0x18: /* System tick */
1317 gen_movl_T0_reg(rd);
1319 case 0x19: /* System tick compare */
1320 gen_op_movtl_T0_env(offsetof(CPUSPARCState, stick_cmpr));
1321 gen_movl_T0_reg(rd);
1323 case 0x10: /* Performance Control */
1324 case 0x11: /* Performance Instrumentation Counter */
1325 case 0x12: /* Dispatch Control */
1326 case 0x14: /* Softint set, WO */
1327 case 0x15: /* Softint clear, WO */
1328 case 0x16: /* Softint write */
1333 #if !defined(CONFIG_USER_ONLY)
1334 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
1335 #ifndef TARGET_SPARC64
1336 if (!supervisor(dc))
1340 if (!hypervisor(dc))
1342 rs1 = GET_FIELD(insn, 13, 17);
1345 // gen_op_rdhpstate();
1348 // gen_op_rdhtstate();
1351 gen_op_movl_T0_env(offsetof(CPUSPARCState, hintp));
1354 gen_op_movl_T0_env(offsetof(CPUSPARCState, htba));
1357 gen_op_movl_T0_env(offsetof(CPUSPARCState, hver));
1359 case 31: // hstick_cmpr
1360 gen_op_movl_env_T0(offsetof(CPUSPARCState, hstick_cmpr));
1366 gen_movl_T0_reg(rd);
1368 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
1369 if (!supervisor(dc))
1371 #ifdef TARGET_SPARC64
1372 rs1 = GET_FIELD(insn, 13, 17);
1390 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr));
1396 gen_op_movl_T0_env(offsetof(CPUSPARCState, tl));
1399 gen_op_movl_T0_env(offsetof(CPUSPARCState, psrpil));
1405 gen_op_movl_T0_env(offsetof(CPUSPARCState, cansave));
1407 case 11: // canrestore
1408 gen_op_movl_T0_env(offsetof(CPUSPARCState, canrestore));
1410 case 12: // cleanwin
1411 gen_op_movl_T0_env(offsetof(CPUSPARCState, cleanwin));
1413 case 13: // otherwin
1414 gen_op_movl_T0_env(offsetof(CPUSPARCState, otherwin));
1417 gen_op_movl_T0_env(offsetof(CPUSPARCState, wstate));
1419 case 16: // UA2005 gl
1420 gen_op_movl_T0_env(offsetof(CPUSPARCState, gl));
1422 case 26: // UA2005 strand status
1423 if (!hypervisor(dc))
1425 gen_op_movl_T0_env(offsetof(CPUSPARCState, ssr));
1428 gen_op_movtl_T0_env(offsetof(CPUSPARCState, version));
1435 gen_op_movl_T0_env(offsetof(CPUSPARCState, wim));
1437 gen_movl_T0_reg(rd);
1439 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
1440 #ifdef TARGET_SPARC64
1443 if (!supervisor(dc))
1445 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr));
1446 gen_movl_T0_reg(rd);
1450 } else if (xop == 0x34) { /* FPU Operations */
1451 if (gen_trap_ifnofpu(dc))
1453 gen_op_clear_ieee_excp_and_FTT();
1454 rs1 = GET_FIELD(insn, 13, 17);
1455 rs2 = GET_FIELD(insn, 27, 31);
1456 xop = GET_FIELD(insn, 18, 26);
1458 case 0x1: /* fmovs */
1459 gen_op_load_fpr_FT0(rs2);
1460 gen_op_store_FT0_fpr(rd);
1462 case 0x5: /* fnegs */
1463 gen_op_load_fpr_FT1(rs2);
1465 gen_op_store_FT0_fpr(rd);
1467 case 0x9: /* fabss */
1468 gen_op_load_fpr_FT1(rs2);
1470 gen_op_store_FT0_fpr(rd);
1472 case 0x29: /* fsqrts */
1473 gen_op_load_fpr_FT1(rs2);
1475 gen_op_store_FT0_fpr(rd);
1477 case 0x2a: /* fsqrtd */
1478 gen_op_load_fpr_DT1(DFPREG(rs2));
1480 gen_op_store_DT0_fpr(DFPREG(rd));
1482 case 0x2b: /* fsqrtq */
1485 gen_op_load_fpr_FT0(rs1);
1486 gen_op_load_fpr_FT1(rs2);
1488 gen_op_store_FT0_fpr(rd);
1491 gen_op_load_fpr_DT0(DFPREG(rs1));
1492 gen_op_load_fpr_DT1(DFPREG(rs2));
1494 gen_op_store_DT0_fpr(DFPREG(rd));
1496 case 0x43: /* faddq */
1499 gen_op_load_fpr_FT0(rs1);
1500 gen_op_load_fpr_FT1(rs2);
1502 gen_op_store_FT0_fpr(rd);
1505 gen_op_load_fpr_DT0(DFPREG(rs1));
1506 gen_op_load_fpr_DT1(DFPREG(rs2));
1508 gen_op_store_DT0_fpr(DFPREG(rd));
1510 case 0x47: /* fsubq */
1513 gen_op_load_fpr_FT0(rs1);
1514 gen_op_load_fpr_FT1(rs2);
1516 gen_op_store_FT0_fpr(rd);
1519 gen_op_load_fpr_DT0(DFPREG(rs1));
1520 gen_op_load_fpr_DT1(DFPREG(rs2));
1522 gen_op_store_DT0_fpr(rd);
1524 case 0x4b: /* fmulq */
1527 gen_op_load_fpr_FT0(rs1);
1528 gen_op_load_fpr_FT1(rs2);
1530 gen_op_store_FT0_fpr(rd);
1533 gen_op_load_fpr_DT0(DFPREG(rs1));
1534 gen_op_load_fpr_DT1(DFPREG(rs2));
1536 gen_op_store_DT0_fpr(DFPREG(rd));
1538 case 0x4f: /* fdivq */
1541 gen_op_load_fpr_FT0(rs1);
1542 gen_op_load_fpr_FT1(rs2);
1544 gen_op_store_DT0_fpr(DFPREG(rd));
1546 case 0x6e: /* fdmulq */
1549 gen_op_load_fpr_FT1(rs2);
1551 gen_op_store_FT0_fpr(rd);
1554 gen_op_load_fpr_DT1(DFPREG(rs2));
1556 gen_op_store_FT0_fpr(rd);
1558 case 0xc7: /* fqtos */
1561 gen_op_load_fpr_FT1(rs2);
1563 gen_op_store_DT0_fpr(DFPREG(rd));
1566 gen_op_load_fpr_FT1(rs2);
1568 gen_op_store_DT0_fpr(DFPREG(rd));
1570 case 0xcb: /* fqtod */
1572 case 0xcc: /* fitoq */
1574 case 0xcd: /* fstoq */
1576 case 0xce: /* fdtoq */
1579 gen_op_load_fpr_FT1(rs2);
1581 gen_op_store_FT0_fpr(rd);
1584 gen_op_load_fpr_DT1(rs2);
1586 gen_op_store_FT0_fpr(rd);
1588 case 0xd3: /* fqtoi */
1590 #ifdef TARGET_SPARC64
1591 case 0x2: /* V9 fmovd */
1592 gen_op_load_fpr_DT0(DFPREG(rs2));
1593 gen_op_store_DT0_fpr(DFPREG(rd));
1595 case 0x6: /* V9 fnegd */
1596 gen_op_load_fpr_DT1(DFPREG(rs2));
1598 gen_op_store_DT0_fpr(DFPREG(rd));
1600 case 0xa: /* V9 fabsd */
1601 gen_op_load_fpr_DT1(DFPREG(rs2));
1603 gen_op_store_DT0_fpr(DFPREG(rd));
1605 case 0x81: /* V9 fstox */
1606 gen_op_load_fpr_FT1(rs2);
1608 gen_op_store_DT0_fpr(DFPREG(rd));
1610 case 0x82: /* V9 fdtox */
1611 gen_op_load_fpr_DT1(DFPREG(rs2));
1613 gen_op_store_DT0_fpr(DFPREG(rd));
1615 case 0x84: /* V9 fxtos */
1616 gen_op_load_fpr_DT1(DFPREG(rs2));
1618 gen_op_store_FT0_fpr(rd);
1620 case 0x88: /* V9 fxtod */
1621 gen_op_load_fpr_DT1(DFPREG(rs2));
1623 gen_op_store_DT0_fpr(DFPREG(rd));
1625 case 0x3: /* V9 fmovq */
1626 case 0x7: /* V9 fnegq */
1627 case 0xb: /* V9 fabsq */
1628 case 0x83: /* V9 fqtox */
1629 case 0x8c: /* V9 fxtoq */
1635 } else if (xop == 0x35) { /* FPU Operations */
1636 #ifdef TARGET_SPARC64
1639 if (gen_trap_ifnofpu(dc))
1641 gen_op_clear_ieee_excp_and_FTT();
1642 rs1 = GET_FIELD(insn, 13, 17);
1643 rs2 = GET_FIELD(insn, 27, 31);
1644 xop = GET_FIELD(insn, 18, 26);
1645 #ifdef TARGET_SPARC64
1646 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
1647 cond = GET_FIELD_SP(insn, 14, 17);
1648 gen_op_load_fpr_FT0(rd);
1649 gen_op_load_fpr_FT1(rs2);
1650 rs1 = GET_FIELD(insn, 13, 17);
1651 gen_movl_reg_T0(rs1);
1655 gen_op_store_FT0_fpr(rd);
1657 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
1658 cond = GET_FIELD_SP(insn, 14, 17);
1659 gen_op_load_fpr_DT0(rd);
1660 gen_op_load_fpr_DT1(rs2);
1662 rs1 = GET_FIELD(insn, 13, 17);
1663 gen_movl_reg_T0(rs1);
1666 gen_op_store_DT0_fpr(rd);
1668 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
1673 #ifdef TARGET_SPARC64
1674 case 0x001: /* V9 fmovscc %fcc0 */
1675 cond = GET_FIELD_SP(insn, 14, 17);
1676 gen_op_load_fpr_FT0(rd);
1677 gen_op_load_fpr_FT1(rs2);
1679 gen_fcond[0][cond]();
1681 gen_op_store_FT0_fpr(rd);
1683 case 0x002: /* V9 fmovdcc %fcc0 */
1684 cond = GET_FIELD_SP(insn, 14, 17);
1685 gen_op_load_fpr_DT0(rd);
1686 gen_op_load_fpr_DT1(rs2);
1688 gen_fcond[0][cond]();
1690 gen_op_store_DT0_fpr(rd);
1692 case 0x003: /* V9 fmovqcc %fcc0 */
1694 case 0x041: /* V9 fmovscc %fcc1 */
1695 cond = GET_FIELD_SP(insn, 14, 17);
1696 gen_op_load_fpr_FT0(rd);
1697 gen_op_load_fpr_FT1(rs2);
1699 gen_fcond[1][cond]();
1701 gen_op_store_FT0_fpr(rd);
1703 case 0x042: /* V9 fmovdcc %fcc1 */
1704 cond = GET_FIELD_SP(insn, 14, 17);
1705 gen_op_load_fpr_DT0(rd);
1706 gen_op_load_fpr_DT1(rs2);
1708 gen_fcond[1][cond]();
1710 gen_op_store_DT0_fpr(rd);
1712 case 0x043: /* V9 fmovqcc %fcc1 */
1714 case 0x081: /* V9 fmovscc %fcc2 */
1715 cond = GET_FIELD_SP(insn, 14, 17);
1716 gen_op_load_fpr_FT0(rd);
1717 gen_op_load_fpr_FT1(rs2);
1719 gen_fcond[2][cond]();
1721 gen_op_store_FT0_fpr(rd);
1723 case 0x082: /* V9 fmovdcc %fcc2 */
1724 cond = GET_FIELD_SP(insn, 14, 17);
1725 gen_op_load_fpr_DT0(rd);
1726 gen_op_load_fpr_DT1(rs2);
1728 gen_fcond[2][cond]();
1730 gen_op_store_DT0_fpr(rd);
1732 case 0x083: /* V9 fmovqcc %fcc2 */
1734 case 0x0c1: /* V9 fmovscc %fcc3 */
1735 cond = GET_FIELD_SP(insn, 14, 17);
1736 gen_op_load_fpr_FT0(rd);
1737 gen_op_load_fpr_FT1(rs2);
1739 gen_fcond[3][cond]();
1741 gen_op_store_FT0_fpr(rd);
1743 case 0x0c2: /* V9 fmovdcc %fcc3 */
1744 cond = GET_FIELD_SP(insn, 14, 17);
1745 gen_op_load_fpr_DT0(rd);
1746 gen_op_load_fpr_DT1(rs2);
1748 gen_fcond[3][cond]();
1750 gen_op_store_DT0_fpr(rd);
1752 case 0x0c3: /* V9 fmovqcc %fcc3 */
1754 case 0x101: /* V9 fmovscc %icc */
1755 cond = GET_FIELD_SP(insn, 14, 17);
1756 gen_op_load_fpr_FT0(rd);
1757 gen_op_load_fpr_FT1(rs2);
1759 gen_cond[0][cond]();
1761 gen_op_store_FT0_fpr(rd);
1763 case 0x102: /* V9 fmovdcc %icc */
1764 cond = GET_FIELD_SP(insn, 14, 17);
1765 gen_op_load_fpr_DT0(rd);
1766 gen_op_load_fpr_DT1(rs2);
1768 gen_cond[0][cond]();
1770 gen_op_store_DT0_fpr(rd);
1772 case 0x103: /* V9 fmovqcc %icc */
1774 case 0x181: /* V9 fmovscc %xcc */
1775 cond = GET_FIELD_SP(insn, 14, 17);
1776 gen_op_load_fpr_FT0(rd);
1777 gen_op_load_fpr_FT1(rs2);
1779 gen_cond[1][cond]();
1781 gen_op_store_FT0_fpr(rd);
1783 case 0x182: /* V9 fmovdcc %xcc */
1784 cond = GET_FIELD_SP(insn, 14, 17);
1785 gen_op_load_fpr_DT0(rd);
1786 gen_op_load_fpr_DT1(rs2);
1788 gen_cond[1][cond]();
1790 gen_op_store_DT0_fpr(rd);
1792 case 0x183: /* V9 fmovqcc %xcc */
1795 case 0x51: /* V9 %fcc */
1796 gen_op_load_fpr_FT0(rs1);
1797 gen_op_load_fpr_FT1(rs2);
1798 #ifdef TARGET_SPARC64
1799 gen_fcmps[rd & 3]();
1804 case 0x52: /* V9 %fcc */
1805 gen_op_load_fpr_DT0(DFPREG(rs1));
1806 gen_op_load_fpr_DT1(DFPREG(rs2));
1807 #ifdef TARGET_SPARC64
1808 gen_fcmpd[rd & 3]();
1813 case 0x53: /* fcmpq */
1815 case 0x55: /* fcmpes, V9 %fcc */
1816 gen_op_load_fpr_FT0(rs1);
1817 gen_op_load_fpr_FT1(rs2);
1818 #ifdef TARGET_SPARC64
1819 gen_fcmpes[rd & 3]();
1824 case 0x56: /* fcmped, V9 %fcc */
1825 gen_op_load_fpr_DT0(DFPREG(rs1));
1826 gen_op_load_fpr_DT1(DFPREG(rs2));
1827 #ifdef TARGET_SPARC64
1828 gen_fcmped[rd & 3]();
1833 case 0x57: /* fcmpeq */
1839 } else if (xop == 0x2) {
1842 rs1 = GET_FIELD(insn, 13, 17);
1844 // or %g0, x, y -> mov T1, x; mov y, T1
1845 if (IS_IMM) { /* immediate */
1846 rs2 = GET_FIELDs(insn, 19, 31);
1847 gen_movl_simm_T1(rs2);
1848 } else { /* register */
1849 rs2 = GET_FIELD(insn, 27, 31);
1850 gen_movl_reg_T1(rs2);
1852 gen_movl_T1_reg(rd);
1854 gen_movl_reg_T0(rs1);
1855 if (IS_IMM) { /* immediate */
1856 // or x, #0, y -> mov T1, x; mov y, T1
1857 rs2 = GET_FIELDs(insn, 19, 31);
1859 gen_movl_simm_T1(rs2);
1862 } else { /* register */
1863 // or x, %g0, y -> mov T1, x; mov y, T1
1864 rs2 = GET_FIELD(insn, 27, 31);
1866 gen_movl_reg_T1(rs2);
1870 gen_movl_T0_reg(rd);
1873 #ifdef TARGET_SPARC64
1874 } else if (xop == 0x25) { /* sll, V9 sllx */
1875 rs1 = GET_FIELD(insn, 13, 17);
1876 gen_movl_reg_T0(rs1);
1877 if (IS_IMM) { /* immediate */
1878 rs2 = GET_FIELDs(insn, 20, 31);
1879 gen_movl_simm_T1(rs2);
1880 } else { /* register */
1881 rs2 = GET_FIELD(insn, 27, 31);
1882 gen_movl_reg_T1(rs2);
1884 if (insn & (1 << 12))
1888 gen_movl_T0_reg(rd);
1889 } else if (xop == 0x26) { /* srl, V9 srlx */
1890 rs1 = GET_FIELD(insn, 13, 17);
1891 gen_movl_reg_T0(rs1);
1892 if (IS_IMM) { /* immediate */
1893 rs2 = GET_FIELDs(insn, 20, 31);
1894 gen_movl_simm_T1(rs2);
1895 } else { /* register */
1896 rs2 = GET_FIELD(insn, 27, 31);
1897 gen_movl_reg_T1(rs2);
1899 if (insn & (1 << 12))
1903 gen_movl_T0_reg(rd);
1904 } else if (xop == 0x27) { /* sra, V9 srax */
1905 rs1 = GET_FIELD(insn, 13, 17);
1906 gen_movl_reg_T0(rs1);
1907 if (IS_IMM) { /* immediate */
1908 rs2 = GET_FIELDs(insn, 20, 31);
1909 gen_movl_simm_T1(rs2);
1910 } else { /* register */
1911 rs2 = GET_FIELD(insn, 27, 31);
1912 gen_movl_reg_T1(rs2);
1914 if (insn & (1 << 12))
1918 gen_movl_T0_reg(rd);
1920 } else if (xop < 0x36) {
1921 rs1 = GET_FIELD(insn, 13, 17);
1922 gen_movl_reg_T0(rs1);
1923 if (IS_IMM) { /* immediate */
1924 rs2 = GET_FIELDs(insn, 19, 31);
1925 gen_movl_simm_T1(rs2);
1926 } else { /* register */
1927 rs2 = GET_FIELD(insn, 27, 31);
1928 gen_movl_reg_T1(rs2);
1931 switch (xop & ~0x10) {
1934 gen_op_add_T1_T0_cc();
1941 gen_op_logic_T0_cc();
1946 gen_op_logic_T0_cc();
1951 gen_op_logic_T0_cc();
1955 gen_op_sub_T1_T0_cc();
1960 gen_op_andn_T1_T0();
1962 gen_op_logic_T0_cc();
1967 gen_op_logic_T0_cc();
1970 gen_op_xnor_T1_T0();
1972 gen_op_logic_T0_cc();
1976 gen_op_addx_T1_T0_cc();
1978 gen_op_addx_T1_T0();
1980 #ifdef TARGET_SPARC64
1981 case 0x9: /* V9 mulx */
1982 gen_op_mulx_T1_T0();
1986 gen_op_umul_T1_T0();
1988 gen_op_logic_T0_cc();
1991 gen_op_smul_T1_T0();
1993 gen_op_logic_T0_cc();
1997 gen_op_subx_T1_T0_cc();
1999 gen_op_subx_T1_T0();
2001 #ifdef TARGET_SPARC64
2002 case 0xd: /* V9 udivx */
2003 gen_op_udivx_T1_T0();
2007 gen_op_udiv_T1_T0();
2012 gen_op_sdiv_T1_T0();
2019 gen_movl_T0_reg(rd);
2022 case 0x20: /* taddcc */
2023 gen_op_tadd_T1_T0_cc();
2024 gen_movl_T0_reg(rd);
2026 case 0x21: /* tsubcc */
2027 gen_op_tsub_T1_T0_cc();
2028 gen_movl_T0_reg(rd);
2030 case 0x22: /* taddcctv */
2032 gen_op_tadd_T1_T0_ccTV();
2033 gen_movl_T0_reg(rd);
2035 case 0x23: /* tsubcctv */
2037 gen_op_tsub_T1_T0_ccTV();
2038 gen_movl_T0_reg(rd);
2040 case 0x24: /* mulscc */
2041 gen_op_mulscc_T1_T0();
2042 gen_movl_T0_reg(rd);
2044 #ifndef TARGET_SPARC64
2045 case 0x25: /* sll */
2047 gen_movl_T0_reg(rd);
2049 case 0x26: /* srl */
2051 gen_movl_T0_reg(rd);
2053 case 0x27: /* sra */
2055 gen_movl_T0_reg(rd);
2063 gen_op_movtl_env_T0(offsetof(CPUSPARCState, y));
2065 #ifndef TARGET_SPARC64
2066 case 0x01 ... 0x0f: /* undefined in the
2070 case 0x10 ... 0x1f: /* implementation-dependent
2076 case 0x2: /* V9 wrccr */
2080 case 0x3: /* V9 wrasi */
2082 gen_op_movl_env_T0(offsetof(CPUSPARCState, asi));
2084 case 0x6: /* V9 wrfprs */
2086 gen_op_movl_env_T0(offsetof(CPUSPARCState, fprs));
2093 case 0xf: /* V9 sir, nop if user */
2094 #if !defined(CONFIG_USER_ONLY)
2099 case 0x13: /* Graphics Status */
2100 if (gen_trap_ifnofpu(dc))
2103 gen_op_movtl_env_T0(offsetof(CPUSPARCState, gsr));
2105 case 0x17: /* Tick compare */
2106 #if !defined(CONFIG_USER_ONLY)
2107 if (!supervisor(dc))
2111 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tick_cmpr));
2112 gen_op_wrtick_cmpr();
2114 case 0x18: /* System tick */
2115 #if !defined(CONFIG_USER_ONLY)
2116 if (!supervisor(dc))
2122 case 0x19: /* System tick compare */
2123 #if !defined(CONFIG_USER_ONLY)
2124 if (!supervisor(dc))
2128 gen_op_movtl_env_T0(offsetof(CPUSPARCState, stick_cmpr));
2129 gen_op_wrstick_cmpr();
2132 case 0x10: /* Performance Control */
2133 case 0x11: /* Performance Instrumentation Counter */
2134 case 0x12: /* Dispatch Control */
2135 case 0x14: /* Softint set */
2136 case 0x15: /* Softint clear */
2137 case 0x16: /* Softint write */
2144 #if !defined(CONFIG_USER_ONLY)
2145 case 0x31: /* wrpsr, V9 saved, restored */
2147 if (!supervisor(dc))
2149 #ifdef TARGET_SPARC64
2157 case 2: /* UA2005 allclean */
2158 case 3: /* UA2005 otherw */
2159 case 4: /* UA2005 normalw */
2160 case 5: /* UA2005 invalw */
2176 case 0x32: /* wrwim, V9 wrpr */
2178 if (!supervisor(dc))
2181 #ifdef TARGET_SPARC64
2199 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr));
2210 gen_op_movl_env_T0(offsetof(CPUSPARCState, tl));
2213 gen_op_movl_env_T0(offsetof(CPUSPARCState, psrpil));
2219 gen_op_movl_env_T0(offsetof(CPUSPARCState, cansave));
2221 case 11: // canrestore
2222 gen_op_movl_env_T0(offsetof(CPUSPARCState, canrestore));
2224 case 12: // cleanwin
2225 gen_op_movl_env_T0(offsetof(CPUSPARCState, cleanwin));
2227 case 13: // otherwin
2228 gen_op_movl_env_T0(offsetof(CPUSPARCState, otherwin));
2231 gen_op_movl_env_T0(offsetof(CPUSPARCState, wstate));
2233 case 16: // UA2005 gl
2234 gen_op_movl_env_T0(offsetof(CPUSPARCState, gl));
2236 case 26: // UA2005 strand status
2237 if (!hypervisor(dc))
2239 gen_op_movl_env_T0(offsetof(CPUSPARCState, ssr));
2249 case 0x33: /* wrtbr, UA2005 wrhpr */
2251 #ifndef TARGET_SPARC64
2252 if (!supervisor(dc))
2255 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr));
2257 if (!hypervisor(dc))
2262 // XXX gen_op_wrhpstate();
2270 // XXX gen_op_wrhtstate();
2273 gen_op_movl_env_T0(offsetof(CPUSPARCState, hintp));
2276 gen_op_movl_env_T0(offsetof(CPUSPARCState, htba));
2278 case 31: // hstick_cmpr
2279 gen_op_movtl_env_T0(offsetof(CPUSPARCState, hstick_cmpr));
2280 gen_op_wrhstick_cmpr();
2282 case 6: // hver readonly
2290 #ifdef TARGET_SPARC64
2291 case 0x2c: /* V9 movcc */
2293 int cc = GET_FIELD_SP(insn, 11, 12);
2294 int cond = GET_FIELD_SP(insn, 14, 17);
2295 if (IS_IMM) { /* immediate */
2296 rs2 = GET_FIELD_SPs(insn, 0, 10);
2297 gen_movl_simm_T1(rs2);
2300 rs2 = GET_FIELD_SP(insn, 0, 4);
2301 gen_movl_reg_T1(rs2);
2303 gen_movl_reg_T0(rd);
2305 if (insn & (1 << 18)) {
2307 gen_cond[0][cond]();
2309 gen_cond[1][cond]();
2313 gen_fcond[cc][cond]();
2316 gen_movl_T0_reg(rd);
2319 case 0x2d: /* V9 sdivx */
2320 gen_op_sdivx_T1_T0();
2321 gen_movl_T0_reg(rd);
2323 case 0x2e: /* V9 popc */
2325 if (IS_IMM) { /* immediate */
2326 rs2 = GET_FIELD_SPs(insn, 0, 12);
2327 gen_movl_simm_T1(rs2);
2328 // XXX optimize: popc(constant)
2331 rs2 = GET_FIELD_SP(insn, 0, 4);
2332 gen_movl_reg_T1(rs2);
2335 gen_movl_T0_reg(rd);
2337 case 0x2f: /* V9 movr */
2339 int cond = GET_FIELD_SP(insn, 10, 12);
2340 rs1 = GET_FIELD(insn, 13, 17);
2342 gen_movl_reg_T0(rs1);
2344 if (IS_IMM) { /* immediate */
2345 rs2 = GET_FIELD_SPs(insn, 0, 9);
2346 gen_movl_simm_T1(rs2);
2349 rs2 = GET_FIELD_SP(insn, 0, 4);
2350 gen_movl_reg_T1(rs2);
2352 gen_movl_reg_T0(rd);
2354 gen_movl_T0_reg(rd);
2362 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
2363 #ifdef TARGET_SPARC64
2364 int opf = GET_FIELD_SP(insn, 5, 13);
2365 rs1 = GET_FIELD(insn, 13, 17);
2366 rs2 = GET_FIELD(insn, 27, 31);
2367 if (gen_trap_ifnofpu(dc))
2371 case 0x000: /* VIS I edge8cc */
2372 case 0x001: /* VIS II edge8n */
2373 case 0x002: /* VIS I edge8lcc */
2374 case 0x003: /* VIS II edge8ln */
2375 case 0x004: /* VIS I edge16cc */
2376 case 0x005: /* VIS II edge16n */
2377 case 0x006: /* VIS I edge16lcc */
2378 case 0x007: /* VIS II edge16ln */
2379 case 0x008: /* VIS I edge32cc */
2380 case 0x009: /* VIS II edge32n */
2381 case 0x00a: /* VIS I edge32lcc */
2382 case 0x00b: /* VIS II edge32ln */
2385 case 0x010: /* VIS I array8 */
2386 gen_movl_reg_T0(rs1);
2387 gen_movl_reg_T1(rs2);
2389 gen_movl_T0_reg(rd);
2391 case 0x012: /* VIS I array16 */
2392 gen_movl_reg_T0(rs1);
2393 gen_movl_reg_T1(rs2);
2395 gen_movl_T0_reg(rd);
2397 case 0x014: /* VIS I array32 */
2398 gen_movl_reg_T0(rs1);
2399 gen_movl_reg_T1(rs2);
2401 gen_movl_T0_reg(rd);
2403 case 0x018: /* VIS I alignaddr */
2404 gen_movl_reg_T0(rs1);
2405 gen_movl_reg_T1(rs2);
2407 gen_movl_T0_reg(rd);
2409 case 0x019: /* VIS II bmask */
2410 case 0x01a: /* VIS I alignaddrl */
2413 case 0x020: /* VIS I fcmple16 */
2414 gen_op_load_fpr_DT0(rs1);
2415 gen_op_load_fpr_DT1(rs2);
2417 gen_op_store_DT0_fpr(rd);
2419 case 0x022: /* VIS I fcmpne16 */
2420 gen_op_load_fpr_DT0(rs1);
2421 gen_op_load_fpr_DT1(rs2);
2423 gen_op_store_DT0_fpr(rd);
2425 case 0x024: /* VIS I fcmple32 */
2426 gen_op_load_fpr_DT0(rs1);
2427 gen_op_load_fpr_DT1(rs2);
2429 gen_op_store_DT0_fpr(rd);
2431 case 0x026: /* VIS I fcmpne32 */
2432 gen_op_load_fpr_DT0(rs1);
2433 gen_op_load_fpr_DT1(rs2);
2435 gen_op_store_DT0_fpr(rd);
2437 case 0x028: /* VIS I fcmpgt16 */
2438 gen_op_load_fpr_DT0(rs1);
2439 gen_op_load_fpr_DT1(rs2);
2441 gen_op_store_DT0_fpr(rd);
2443 case 0x02a: /* VIS I fcmpeq16 */
2444 gen_op_load_fpr_DT0(rs1);
2445 gen_op_load_fpr_DT1(rs2);
2447 gen_op_store_DT0_fpr(rd);
2449 case 0x02c: /* VIS I fcmpgt32 */
2450 gen_op_load_fpr_DT0(rs1);
2451 gen_op_load_fpr_DT1(rs2);
2453 gen_op_store_DT0_fpr(rd);
2455 case 0x02e: /* VIS I fcmpeq32 */
2456 gen_op_load_fpr_DT0(rs1);
2457 gen_op_load_fpr_DT1(rs2);
2459 gen_op_store_DT0_fpr(rd);
2461 case 0x031: /* VIS I fmul8x16 */
2462 gen_op_load_fpr_DT0(rs1);
2463 gen_op_load_fpr_DT1(rs2);
2465 gen_op_store_DT0_fpr(rd);
2467 case 0x033: /* VIS I fmul8x16au */
2468 gen_op_load_fpr_DT0(rs1);
2469 gen_op_load_fpr_DT1(rs2);
2470 gen_op_fmul8x16au();
2471 gen_op_store_DT0_fpr(rd);
2473 case 0x035: /* VIS I fmul8x16al */
2474 gen_op_load_fpr_DT0(rs1);
2475 gen_op_load_fpr_DT1(rs2);
2476 gen_op_fmul8x16al();
2477 gen_op_store_DT0_fpr(rd);
2479 case 0x036: /* VIS I fmul8sux16 */
2480 gen_op_load_fpr_DT0(rs1);
2481 gen_op_load_fpr_DT1(rs2);
2482 gen_op_fmul8sux16();
2483 gen_op_store_DT0_fpr(rd);
2485 case 0x037: /* VIS I fmul8ulx16 */
2486 gen_op_load_fpr_DT0(rs1);
2487 gen_op_load_fpr_DT1(rs2);
2488 gen_op_fmul8ulx16();
2489 gen_op_store_DT0_fpr(rd);
2491 case 0x038: /* VIS I fmuld8sux16 */
2492 gen_op_load_fpr_DT0(rs1);
2493 gen_op_load_fpr_DT1(rs2);
2494 gen_op_fmuld8sux16();
2495 gen_op_store_DT0_fpr(rd);
2497 case 0x039: /* VIS I fmuld8ulx16 */
2498 gen_op_load_fpr_DT0(rs1);
2499 gen_op_load_fpr_DT1(rs2);
2500 gen_op_fmuld8ulx16();
2501 gen_op_store_DT0_fpr(rd);
2503 case 0x03a: /* VIS I fpack32 */
2504 case 0x03b: /* VIS I fpack16 */
2505 case 0x03d: /* VIS I fpackfix */
2506 case 0x03e: /* VIS I pdist */
2509 case 0x048: /* VIS I faligndata */
2510 gen_op_load_fpr_DT0(rs1);
2511 gen_op_load_fpr_DT1(rs2);
2512 gen_op_faligndata();
2513 gen_op_store_DT0_fpr(rd);
2515 case 0x04b: /* VIS I fpmerge */
2516 gen_op_load_fpr_DT0(rs1);
2517 gen_op_load_fpr_DT1(rs2);
2519 gen_op_store_DT0_fpr(rd);
2521 case 0x04c: /* VIS II bshuffle */
2524 case 0x04d: /* VIS I fexpand */
2525 gen_op_load_fpr_DT0(rs1);
2526 gen_op_load_fpr_DT1(rs2);
2528 gen_op_store_DT0_fpr(rd);
2530 case 0x050: /* VIS I fpadd16 */
2531 gen_op_load_fpr_DT0(rs1);
2532 gen_op_load_fpr_DT1(rs2);
2534 gen_op_store_DT0_fpr(rd);
2536 case 0x051: /* VIS I fpadd16s */
2537 gen_op_load_fpr_FT0(rs1);
2538 gen_op_load_fpr_FT1(rs2);
2540 gen_op_store_FT0_fpr(rd);
2542 case 0x052: /* VIS I fpadd32 */
2543 gen_op_load_fpr_DT0(rs1);
2544 gen_op_load_fpr_DT1(rs2);
2546 gen_op_store_DT0_fpr(rd);
2548 case 0x053: /* VIS I fpadd32s */
2549 gen_op_load_fpr_FT0(rs1);
2550 gen_op_load_fpr_FT1(rs2);
2552 gen_op_store_FT0_fpr(rd);
2554 case 0x054: /* VIS I fpsub16 */
2555 gen_op_load_fpr_DT0(rs1);
2556 gen_op_load_fpr_DT1(rs2);
2558 gen_op_store_DT0_fpr(rd);
2560 case 0x055: /* VIS I fpsub16s */
2561 gen_op_load_fpr_FT0(rs1);
2562 gen_op_load_fpr_FT1(rs2);
2564 gen_op_store_FT0_fpr(rd);
2566 case 0x056: /* VIS I fpsub32 */
2567 gen_op_load_fpr_DT0(rs1);
2568 gen_op_load_fpr_DT1(rs2);
2570 gen_op_store_DT0_fpr(rd);
2572 case 0x057: /* VIS I fpsub32s */
2573 gen_op_load_fpr_FT0(rs1);
2574 gen_op_load_fpr_FT1(rs2);
2576 gen_op_store_FT0_fpr(rd);
2578 case 0x060: /* VIS I fzero */
2579 gen_op_movl_DT0_0();
2580 gen_op_store_DT0_fpr(rd);
2582 case 0x061: /* VIS I fzeros */
2583 gen_op_movl_FT0_0();
2584 gen_op_store_FT0_fpr(rd);
2586 case 0x062: /* VIS I fnor */
2587 gen_op_load_fpr_DT0(rs1);
2588 gen_op_load_fpr_DT1(rs2);
2590 gen_op_store_DT0_fpr(rd);
2592 case 0x063: /* VIS I fnors */
2593 gen_op_load_fpr_FT0(rs1);
2594 gen_op_load_fpr_FT1(rs2);
2596 gen_op_store_FT0_fpr(rd);
2598 case 0x064: /* VIS I fandnot2 */
2599 gen_op_load_fpr_DT1(rs1);
2600 gen_op_load_fpr_DT0(rs2);
2602 gen_op_store_DT0_fpr(rd);
2604 case 0x065: /* VIS I fandnot2s */
2605 gen_op_load_fpr_FT1(rs1);
2606 gen_op_load_fpr_FT0(rs2);
2608 gen_op_store_FT0_fpr(rd);
2610 case 0x066: /* VIS I fnot2 */
2611 gen_op_load_fpr_DT1(rs2);
2613 gen_op_store_DT0_fpr(rd);
2615 case 0x067: /* VIS I fnot2s */
2616 gen_op_load_fpr_FT1(rs2);
2618 gen_op_store_FT0_fpr(rd);
2620 case 0x068: /* VIS I fandnot1 */
2621 gen_op_load_fpr_DT0(rs1);
2622 gen_op_load_fpr_DT1(rs2);
2624 gen_op_store_DT0_fpr(rd);
2626 case 0x069: /* VIS I fandnot1s */
2627 gen_op_load_fpr_FT0(rs1);
2628 gen_op_load_fpr_FT1(rs2);
2630 gen_op_store_FT0_fpr(rd);
2632 case 0x06a: /* VIS I fnot1 */
2633 gen_op_load_fpr_DT1(rs1);
2635 gen_op_store_DT0_fpr(rd);
2637 case 0x06b: /* VIS I fnot1s */
2638 gen_op_load_fpr_FT1(rs1);
2640 gen_op_store_FT0_fpr(rd);
2642 case 0x06c: /* VIS I fxor */
2643 gen_op_load_fpr_DT0(rs1);
2644 gen_op_load_fpr_DT1(rs2);
2646 gen_op_store_DT0_fpr(rd);
2648 case 0x06d: /* VIS I fxors */
2649 gen_op_load_fpr_FT0(rs1);
2650 gen_op_load_fpr_FT1(rs2);
2652 gen_op_store_FT0_fpr(rd);
2654 case 0x06e: /* VIS I fnand */
2655 gen_op_load_fpr_DT0(rs1);
2656 gen_op_load_fpr_DT1(rs2);
2658 gen_op_store_DT0_fpr(rd);
2660 case 0x06f: /* VIS I fnands */
2661 gen_op_load_fpr_FT0(rs1);
2662 gen_op_load_fpr_FT1(rs2);
2664 gen_op_store_FT0_fpr(rd);
2666 case 0x070: /* VIS I fand */
2667 gen_op_load_fpr_DT0(rs1);
2668 gen_op_load_fpr_DT1(rs2);
2670 gen_op_store_DT0_fpr(rd);
2672 case 0x071: /* VIS I fands */
2673 gen_op_load_fpr_FT0(rs1);
2674 gen_op_load_fpr_FT1(rs2);
2676 gen_op_store_FT0_fpr(rd);
2678 case 0x072: /* VIS I fxnor */
2679 gen_op_load_fpr_DT0(rs1);
2680 gen_op_load_fpr_DT1(rs2);
2682 gen_op_store_DT0_fpr(rd);
2684 case 0x073: /* VIS I fxnors */
2685 gen_op_load_fpr_FT0(rs1);
2686 gen_op_load_fpr_FT1(rs2);
2688 gen_op_store_FT0_fpr(rd);
2690 case 0x074: /* VIS I fsrc1 */
2691 gen_op_load_fpr_DT0(rs1);
2692 gen_op_store_DT0_fpr(rd);
2694 case 0x075: /* VIS I fsrc1s */
2695 gen_op_load_fpr_FT0(rs1);
2696 gen_op_store_FT0_fpr(rd);
2698 case 0x076: /* VIS I fornot2 */
2699 gen_op_load_fpr_DT1(rs1);
2700 gen_op_load_fpr_DT0(rs2);
2702 gen_op_store_DT0_fpr(rd);
2704 case 0x077: /* VIS I fornot2s */
2705 gen_op_load_fpr_FT1(rs1);
2706 gen_op_load_fpr_FT0(rs2);
2708 gen_op_store_FT0_fpr(rd);
2710 case 0x078: /* VIS I fsrc2 */
2711 gen_op_load_fpr_DT0(rs2);
2712 gen_op_store_DT0_fpr(rd);
2714 case 0x079: /* VIS I fsrc2s */
2715 gen_op_load_fpr_FT0(rs2);
2716 gen_op_store_FT0_fpr(rd);
2718 case 0x07a: /* VIS I fornot1 */
2719 gen_op_load_fpr_DT0(rs1);
2720 gen_op_load_fpr_DT1(rs2);
2722 gen_op_store_DT0_fpr(rd);
2724 case 0x07b: /* VIS I fornot1s */
2725 gen_op_load_fpr_FT0(rs1);
2726 gen_op_load_fpr_FT1(rs2);
2728 gen_op_store_FT0_fpr(rd);
2730 case 0x07c: /* VIS I for */
2731 gen_op_load_fpr_DT0(rs1);
2732 gen_op_load_fpr_DT1(rs2);
2734 gen_op_store_DT0_fpr(rd);
2736 case 0x07d: /* VIS I fors */
2737 gen_op_load_fpr_FT0(rs1);
2738 gen_op_load_fpr_FT1(rs2);
2740 gen_op_store_FT0_fpr(rd);
2742 case 0x07e: /* VIS I fone */
2743 gen_op_movl_DT0_1();
2744 gen_op_store_DT0_fpr(rd);
2746 case 0x07f: /* VIS I fones */
2747 gen_op_movl_FT0_1();
2748 gen_op_store_FT0_fpr(rd);
2750 case 0x080: /* VIS I shutdown */
2751 case 0x081: /* VIS II siam */
2760 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
2761 #ifdef TARGET_SPARC64
2766 #ifdef TARGET_SPARC64
2767 } else if (xop == 0x39) { /* V9 return */
2768 rs1 = GET_FIELD(insn, 13, 17);
2770 gen_movl_reg_T0(rs1);
2771 if (IS_IMM) { /* immediate */
2772 rs2 = GET_FIELDs(insn, 19, 31);
2776 gen_movl_simm_T1(rs2);
2781 } else { /* register */
2782 rs2 = GET_FIELD(insn, 27, 31);
2786 gen_movl_reg_T1(rs2);
2794 gen_op_check_align_T0_3();
2795 gen_op_movl_npc_T0();
2796 dc->npc = DYNAMIC_PC;
2800 rs1 = GET_FIELD(insn, 13, 17);
2801 gen_movl_reg_T0(rs1);
2802 if (IS_IMM) { /* immediate */
2803 rs2 = GET_FIELDs(insn, 19, 31);
2807 gen_movl_simm_T1(rs2);
2812 } else { /* register */
2813 rs2 = GET_FIELD(insn, 27, 31);
2817 gen_movl_reg_T1(rs2);
2824 case 0x38: /* jmpl */
2827 #ifdef TARGET_SPARC64
2828 if (dc->pc == (uint32_t)dc->pc) {
2829 gen_op_movl_T1_im(dc->pc);
2831 gen_op_movq_T1_im64(dc->pc >> 32, dc->pc);
2834 gen_op_movl_T1_im(dc->pc);
2836 gen_movl_T1_reg(rd);
2839 gen_op_check_align_T0_3();
2840 gen_op_movl_npc_T0();
2841 dc->npc = DYNAMIC_PC;
2844 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
2845 case 0x39: /* rett, V9 return */
2847 if (!supervisor(dc))
2850 gen_op_check_align_T0_3();
2851 gen_op_movl_npc_T0();
2852 dc->npc = DYNAMIC_PC;
2857 case 0x3b: /* flush */
2860 case 0x3c: /* save */
2863 gen_movl_T0_reg(rd);
2865 case 0x3d: /* restore */
2868 gen_movl_T0_reg(rd);
2870 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
2871 case 0x3e: /* V9 done/retry */
2875 if (!supervisor(dc))
2877 dc->npc = DYNAMIC_PC;
2878 dc->pc = DYNAMIC_PC;
2882 if (!supervisor(dc))
2884 dc->npc = DYNAMIC_PC;
2885 dc->pc = DYNAMIC_PC;
2901 case 3: /* load/store instructions */
2903 unsigned int xop = GET_FIELD(insn, 7, 12);
2904 rs1 = GET_FIELD(insn, 13, 17);
2906 gen_movl_reg_T0(rs1);
2907 if (xop == 0x3c || xop == 0x3e)
2909 rs2 = GET_FIELD(insn, 27, 31);
2910 gen_movl_reg_T1(rs2);
2912 else if (IS_IMM) { /* immediate */
2913 rs2 = GET_FIELDs(insn, 19, 31);
2917 gen_movl_simm_T1(rs2);
2922 } else { /* register */
2923 rs2 = GET_FIELD(insn, 27, 31);
2927 gen_movl_reg_T1(rs2);
2933 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
2934 (xop > 0x17 && xop <= 0x1d ) ||
2935 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
2937 case 0x0: /* load word */
2938 gen_op_check_align_T0_3();
2939 #ifndef TARGET_SPARC64
2945 case 0x1: /* load unsigned byte */
2948 case 0x2: /* load unsigned halfword */
2949 gen_op_check_align_T0_1();
2952 case 0x3: /* load double word */
2955 gen_op_check_align_T0_7();
2957 gen_movl_T0_reg(rd + 1);
2959 case 0x9: /* load signed byte */
2962 case 0xa: /* load signed halfword */
2963 gen_op_check_align_T0_1();
2966 case 0xd: /* ldstub -- XXX: should be atomically */
2967 gen_op_ldst(ldstub);
2969 case 0x0f: /* swap register with memory. Also atomically */
2970 gen_op_check_align_T0_3();
2971 gen_movl_reg_T1(rd);
2974 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2975 case 0x10: /* load word alternate */
2976 #ifndef TARGET_SPARC64
2979 if (!supervisor(dc))
2982 gen_op_check_align_T0_3();
2983 gen_ld_asi(insn, 4, 0);
2985 case 0x11: /* load unsigned byte alternate */
2986 #ifndef TARGET_SPARC64
2989 if (!supervisor(dc))
2992 gen_ld_asi(insn, 1, 0);
2994 case 0x12: /* load unsigned halfword alternate */
2995 #ifndef TARGET_SPARC64
2998 if (!supervisor(dc))
3001 gen_op_check_align_T0_1();
3002 gen_ld_asi(insn, 2, 0);
3004 case 0x13: /* load double word alternate */
3005 #ifndef TARGET_SPARC64
3008 if (!supervisor(dc))
3013 gen_op_check_align_T0_7();
3015 gen_movl_T0_reg(rd + 1);
3017 case 0x19: /* load signed byte alternate */
3018 #ifndef TARGET_SPARC64
3021 if (!supervisor(dc))
3024 gen_ld_asi(insn, 1, 1);
3026 case 0x1a: /* load signed halfword alternate */
3027 #ifndef TARGET_SPARC64
3030 if (!supervisor(dc))
3033 gen_op_check_align_T0_1();
3034 gen_ld_asi(insn, 2, 1);
3036 case 0x1d: /* ldstuba -- XXX: should be atomically */
3037 #ifndef TARGET_SPARC64
3040 if (!supervisor(dc))
3043 gen_ldstub_asi(insn);
3045 case 0x1f: /* swap reg with alt. memory. Also atomically */
3046 #ifndef TARGET_SPARC64
3049 if (!supervisor(dc))
3052 gen_op_check_align_T0_3();
3053 gen_movl_reg_T1(rd);
3057 #ifndef TARGET_SPARC64
3058 case 0x30: /* ldc */
3059 case 0x31: /* ldcsr */
3060 case 0x33: /* lddc */
3064 #ifdef TARGET_SPARC64
3065 case 0x08: /* V9 ldsw */
3066 gen_op_check_align_T0_3();
3069 case 0x0b: /* V9 ldx */
3070 gen_op_check_align_T0_7();
3073 case 0x18: /* V9 ldswa */
3074 gen_op_check_align_T0_3();
3075 gen_ld_asi(insn, 4, 1);
3077 case 0x1b: /* V9 ldxa */
3078 gen_op_check_align_T0_7();
3079 gen_ld_asi(insn, 8, 0);
3081 case 0x2d: /* V9 prefetch, no effect */
3083 case 0x30: /* V9 ldfa */
3084 gen_op_check_align_T0_3();
3085 gen_ldf_asi(insn, 4);
3087 case 0x33: /* V9 lddfa */
3088 gen_op_check_align_T0_3();
3089 gen_ldf_asi(insn, 8);
3091 case 0x3d: /* V9 prefetcha, no effect */
3093 case 0x32: /* V9 ldqfa */
3099 gen_movl_T1_reg(rd);
3100 #ifdef TARGET_SPARC64
3103 } else if (xop >= 0x20 && xop < 0x24) {
3104 if (gen_trap_ifnofpu(dc))
3107 case 0x20: /* load fpreg */
3108 gen_op_check_align_T0_3();
3110 gen_op_store_FT0_fpr(rd);
3112 case 0x21: /* load fsr */
3113 gen_op_check_align_T0_3();
3117 case 0x22: /* load quad fpreg */
3119 case 0x23: /* load double fpreg */
3120 gen_op_check_align_T0_7();
3122 gen_op_store_DT0_fpr(DFPREG(rd));
3127 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
3128 xop == 0xe || xop == 0x1e) {
3129 gen_movl_reg_T1(rd);
3132 gen_op_check_align_T0_3();
3139 gen_op_check_align_T0_1();
3145 gen_op_check_align_T0_7();
3147 gen_movl_reg_T2(rd + 1);
3150 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
3152 #ifndef TARGET_SPARC64
3155 if (!supervisor(dc))
3158 gen_op_check_align_T0_3();
3159 gen_st_asi(insn, 4);
3162 #ifndef TARGET_SPARC64
3165 if (!supervisor(dc))
3168 gen_st_asi(insn, 1);
3171 #ifndef TARGET_SPARC64
3174 if (!supervisor(dc))
3177 gen_op_check_align_T0_1();
3178 gen_st_asi(insn, 2);
3181 #ifndef TARGET_SPARC64
3184 if (!supervisor(dc))
3189 gen_op_check_align_T0_7();
3191 gen_movl_reg_T2(rd + 1);
3195 #ifdef TARGET_SPARC64
3196 case 0x0e: /* V9 stx */
3197 gen_op_check_align_T0_7();
3200 case 0x1e: /* V9 stxa */
3201 gen_op_check_align_T0_7();
3202 gen_st_asi(insn, 8);
3208 } else if (xop > 0x23 && xop < 0x28) {
3209 if (gen_trap_ifnofpu(dc))
3213 gen_op_check_align_T0_3();
3214 gen_op_load_fpr_FT0(rd);
3217 case 0x25: /* stfsr, V9 stxfsr */
3218 #ifdef CONFIG_USER_ONLY
3219 gen_op_check_align_T0_3();
3224 #if !defined(CONFIG_USER_ONLY)
3225 case 0x26: /* stdfq */
3226 if (!supervisor(dc))
3228 if (gen_trap_ifnofpu(dc))
3233 gen_op_check_align_T0_7();
3234 gen_op_load_fpr_DT0(DFPREG(rd));
3240 } else if (xop > 0x33 && xop < 0x3f) {
3242 #ifdef TARGET_SPARC64
3243 case 0x34: /* V9 stfa */
3244 gen_op_check_align_T0_3();
3245 gen_op_load_fpr_FT0(rd);
3246 gen_stf_asi(insn, 4);
3248 case 0x37: /* V9 stdfa */
3249 gen_op_check_align_T0_3();
3250 gen_op_load_fpr_DT0(DFPREG(rd));
3251 gen_stf_asi(insn, 8);
3253 case 0x3c: /* V9 casa */
3254 gen_op_check_align_T0_3();
3256 gen_movl_reg_T2(rd);
3258 gen_movl_T1_reg(rd);
3260 case 0x3e: /* V9 casxa */
3261 gen_op_check_align_T0_7();
3263 gen_movl_reg_T2(rd);
3265 gen_movl_T1_reg(rd);
3267 case 0x36: /* V9 stqfa */
3270 case 0x34: /* stc */
3271 case 0x35: /* stcsr */
3272 case 0x36: /* stdcq */
3273 case 0x37: /* stdc */
3285 /* default case for non jump instructions */
3286 if (dc->npc == DYNAMIC_PC) {
3287 dc->pc = DYNAMIC_PC;
3289 } else if (dc->npc == JUMP_PC) {
3290 /* we can do a static jump */
3291 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1]);
3295 dc->npc = dc->npc + 4;
3301 gen_op_exception(TT_ILL_INSN);
3304 #if !defined(CONFIG_USER_ONLY)
3307 gen_op_exception(TT_PRIV_INSN);
3313 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
3316 #if !defined(CONFIG_USER_ONLY)
3319 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
3323 #ifndef TARGET_SPARC64
3326 gen_op_exception(TT_NCP_INSN);
3332 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
3333 int spc, CPUSPARCState *env)
3335 target_ulong pc_start, last_pc;
3336 uint16_t *gen_opc_end;
3337 DisasContext dc1, *dc = &dc1;
3340 memset(dc, 0, sizeof(DisasContext));
3345 dc->npc = (target_ulong) tb->cs_base;
3346 dc->mem_idx = cpu_mmu_index(env);
3347 dc->fpu_enabled = cpu_fpu_enabled(env);
3348 gen_opc_ptr = gen_opc_buf;
3349 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
3350 gen_opparam_ptr = gen_opparam_buf;
3354 if (env->nb_breakpoints > 0) {
3355 for(j = 0; j < env->nb_breakpoints; j++) {
3356 if (env->breakpoints[j] == dc->pc) {
3357 if (dc->pc != pc_start)
3369 fprintf(logfile, "Search PC...\n");
3370 j = gen_opc_ptr - gen_opc_buf;
3374 gen_opc_instr_start[lj++] = 0;
3375 gen_opc_pc[lj] = dc->pc;
3376 gen_opc_npc[lj] = dc->npc;
3377 gen_opc_instr_start[lj] = 1;
3381 disas_sparc_insn(dc);
3385 /* if the next PC is different, we abort now */
3386 if (dc->pc != (last_pc + 4))
3388 /* if we reach a page boundary, we stop generation so that the
3389 PC of a TT_TFAULT exception is always in the right page */
3390 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
3392 /* if single step mode, we generate only one instruction and
3393 generate an exception */
3394 if (env->singlestep_enabled) {
3400 } while ((gen_opc_ptr < gen_opc_end) &&
3401 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
3405 if (dc->pc != DYNAMIC_PC &&
3406 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
3407 /* static PC and NPC: we can use direct chaining */
3408 gen_branch(dc, dc->pc, dc->npc);
3410 if (dc->pc != DYNAMIC_PC)
3417 *gen_opc_ptr = INDEX_op_end;
3419 j = gen_opc_ptr - gen_opc_buf;
3422 gen_opc_instr_start[lj++] = 0;
3428 gen_opc_jump_pc[0] = dc->jump_pc[0];
3429 gen_opc_jump_pc[1] = dc->jump_pc[1];
3431 tb->size = last_pc + 4 - pc_start;
3434 if (loglevel & CPU_LOG_TB_IN_ASM) {
3435 fprintf(logfile, "--------------\n");
3436 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
3437 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
3438 fprintf(logfile, "\n");
3439 if (loglevel & CPU_LOG_TB_OP) {
3440 fprintf(logfile, "OP:\n");
3441 dump_ops(gen_opc_buf, gen_opparam_buf);
3442 fprintf(logfile, "\n");
3449 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
3451 return gen_intermediate_code_internal(tb, 0, env);
3454 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
3456 return gen_intermediate_code_internal(tb, 1, env);
3459 extern int ram_size;
3461 void cpu_reset(CPUSPARCState *env)
3466 env->regwptr = env->regbase + (env->cwp * 16);
3467 #if defined(CONFIG_USER_ONLY)
3468 env->user_mode_only = 1;
3469 #ifdef TARGET_SPARC64
3470 env->cleanwin = NWINDOWS - 2;
3471 env->cansave = NWINDOWS - 2;
3472 env->pstate = PS_RMO | PS_PEF | PS_IE;
3473 env->asi = 0x82; // Primary no-fault
3479 #ifdef TARGET_SPARC64
3480 env->pstate = PS_PRIV;
3481 env->hpstate = HS_PRIV;
3482 env->pc = 0x1fff0000000ULL;
3485 env->mmuregs[0] &= ~(MMU_E | MMU_NF);
3486 env->mmuregs[0] |= env->mmu_bm;
3488 env->npc = env->pc + 4;
3492 CPUSPARCState *cpu_sparc_init(void)
3496 env = qemu_mallocz(sizeof(CPUSPARCState));
3503 static const sparc_def_t sparc_defs[] = {
3504 #ifdef TARGET_SPARC64
3506 .name = "Fujitsu Sparc64",
3507 .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)
3508 | (MAXTL << 8) | (NWINDOWS - 1)),
3509 .fpu_version = 0x00000000,
3513 .name = "Fujitsu Sparc64 III",
3514 .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)
3515 | (MAXTL << 8) | (NWINDOWS - 1)),
3516 .fpu_version = 0x00000000,
3520 .name = "Fujitsu Sparc64 IV",
3521 .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)
3522 | (MAXTL << 8) | (NWINDOWS - 1)),
3523 .fpu_version = 0x00000000,
3527 .name = "Fujitsu Sparc64 V",
3528 .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)
3529 | (MAXTL << 8) | (NWINDOWS - 1)),
3530 .fpu_version = 0x00000000,
3534 .name = "TI UltraSparc I",
3535 .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
3536 | (MAXTL << 8) | (NWINDOWS - 1)),
3537 .fpu_version = 0x00000000,
3541 .name = "TI UltraSparc II",
3542 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)
3543 | (MAXTL << 8) | (NWINDOWS - 1)),
3544 .fpu_version = 0x00000000,
3548 .name = "TI UltraSparc IIi",
3549 .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)
3550 | (MAXTL << 8) | (NWINDOWS - 1)),
3551 .fpu_version = 0x00000000,
3555 .name = "TI UltraSparc IIe",
3556 .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)
3557 | (MAXTL << 8) | (NWINDOWS - 1)),
3558 .fpu_version = 0x00000000,
3562 .name = "Sun UltraSparc III",
3563 .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)
3564 | (MAXTL << 8) | (NWINDOWS - 1)),
3565 .fpu_version = 0x00000000,
3569 .name = "Sun UltraSparc III Cu",
3570 .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)
3571 | (MAXTL << 8) | (NWINDOWS - 1)),
3572 .fpu_version = 0x00000000,
3576 .name = "Sun UltraSparc IIIi",
3577 .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)
3578 | (MAXTL << 8) | (NWINDOWS - 1)),
3579 .fpu_version = 0x00000000,
3583 .name = "Sun UltraSparc IV",
3584 .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)
3585 | (MAXTL << 8) | (NWINDOWS - 1)),
3586 .fpu_version = 0x00000000,
3590 .name = "Sun UltraSparc IV+",
3591 .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)
3592 | (MAXTL << 8) | (NWINDOWS - 1)),
3593 .fpu_version = 0x00000000,
3597 .name = "Sun UltraSparc IIIi+",
3598 .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)
3599 | (MAXTL << 8) | (NWINDOWS - 1)),
3600 .fpu_version = 0x00000000,
3604 .name = "NEC UltraSparc I",
3605 .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
3606 | (MAXTL << 8) | (NWINDOWS - 1)),
3607 .fpu_version = 0x00000000,
3612 .name = "Fujitsu MB86900",
3613 .iu_version = 0x00 << 24, /* Impl 0, ver 0 */
3614 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
3615 .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */
3616 .mmu_bm = 0x00004000,
3619 .name = "Fujitsu MB86904",
3620 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
3621 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
3622 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
3623 .mmu_bm = 0x00004000,
3626 .name = "Fujitsu MB86907",
3627 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
3628 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
3629 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
3630 .mmu_bm = 0x00004000,
3633 .name = "LSI L64811",
3634 .iu_version = 0x10 << 24, /* Impl 1, ver 0 */
3635 .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */
3636 .mmu_version = 0x10 << 24,
3637 .mmu_bm = 0x00004000,
3640 .name = "Cypress CY7C601",
3641 .iu_version = 0x11 << 24, /* Impl 1, ver 1 */
3642 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
3643 .mmu_version = 0x10 << 24,
3644 .mmu_bm = 0x00004000,
3647 .name = "Cypress CY7C611",
3648 .iu_version = 0x13 << 24, /* Impl 1, ver 3 */
3649 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
3650 .mmu_version = 0x10 << 24,
3651 .mmu_bm = 0x00004000,
3654 .name = "TI SuperSparc II",
3655 .iu_version = 0x40000000,
3656 .fpu_version = 0 << 17,
3657 .mmu_version = 0x04000000,
3658 .mmu_bm = 0x00002000,
3661 .name = "TI MicroSparc I",
3662 .iu_version = 0x41000000,
3663 .fpu_version = 4 << 17,
3664 .mmu_version = 0x41000000,
3665 .mmu_bm = 0x00004000,
3668 .name = "TI MicroSparc II",
3669 .iu_version = 0x42000000,
3670 .fpu_version = 4 << 17,
3671 .mmu_version = 0x02000000,
3672 .mmu_bm = 0x00004000,
3675 .name = "TI MicroSparc IIep",
3676 .iu_version = 0x42000000,
3677 .fpu_version = 4 << 17,
3678 .mmu_version = 0x04000000,
3679 .mmu_bm = 0x00004000,
3682 .name = "TI SuperSparc 51",
3683 .iu_version = 0x43000000,
3684 .fpu_version = 0 << 17,
3685 .mmu_version = 0x04000000,
3686 .mmu_bm = 0x00002000,
3689 .name = "TI SuperSparc 61",
3690 .iu_version = 0x44000000,
3691 .fpu_version = 0 << 17,
3692 .mmu_version = 0x04000000,
3693 .mmu_bm = 0x00002000,
3696 .name = "Ross RT625",
3697 .iu_version = 0x1e000000,
3698 .fpu_version = 1 << 17,
3699 .mmu_version = 0x1e000000,
3700 .mmu_bm = 0x00004000,
3703 .name = "Ross RT620",
3704 .iu_version = 0x1f000000,
3705 .fpu_version = 1 << 17,
3706 .mmu_version = 0x1f000000,
3707 .mmu_bm = 0x00004000,
3710 .name = "BIT B5010",
3711 .iu_version = 0x20000000,
3712 .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */
3713 .mmu_version = 0x20000000,
3714 .mmu_bm = 0x00004000,
3717 .name = "Matsushita MN10501",
3718 .iu_version = 0x50000000,
3719 .fpu_version = 0 << 17,
3720 .mmu_version = 0x50000000,
3721 .mmu_bm = 0x00004000,
3724 .name = "Weitek W8601",
3725 .iu_version = 0x90 << 24, /* Impl 9, ver 0 */
3726 .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
3727 .mmu_version = 0x10 << 24,
3728 .mmu_bm = 0x00004000,
3732 .iu_version = 0xf2000000,
3733 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
3734 .mmu_version = 0xf2000000,
3735 .mmu_bm = 0x00004000,
3739 .iu_version = 0xf3000000,
3740 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
3741 .mmu_version = 0xf3000000,
3742 .mmu_bm = 0x00004000,
3747 int sparc_find_by_name(const unsigned char *name, const sparc_def_t **def)
3754 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
3755 if (strcasecmp(name, sparc_defs[i].name) == 0) {
3756 *def = &sparc_defs[i];
3765 void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
3769 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
3770 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x\n",
3772 sparc_defs[i].iu_version,
3773 sparc_defs[i].fpu_version,
3774 sparc_defs[i].mmu_version);
3778 int cpu_sparc_register (CPUSPARCState *env, const sparc_def_t *def, unsigned int cpu)
3780 env->version = def->iu_version;
3781 env->fsr = def->fpu_version;
3782 #if !defined(TARGET_SPARC64)
3783 env->mmu_bm = def->mmu_bm;
3784 env->mmuregs[0] |= def->mmu_version;
3785 env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
3791 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
3793 void cpu_dump_state(CPUState *env, FILE *f,
3794 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
3799 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, env->npc);
3800 cpu_fprintf(f, "General Registers:\n");
3801 for (i = 0; i < 4; i++)
3802 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
3803 cpu_fprintf(f, "\n");
3805 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
3806 cpu_fprintf(f, "\nCurrent Register Window:\n");
3807 for (x = 0; x < 3; x++) {
3808 for (i = 0; i < 4; i++)
3809 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
3810 (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i,
3811 env->regwptr[i + x * 8]);
3812 cpu_fprintf(f, "\n");
3814 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
3815 (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i,
3816 env->regwptr[i + x * 8]);
3817 cpu_fprintf(f, "\n");
3819 cpu_fprintf(f, "\nFloating Point Registers:\n");
3820 for (i = 0; i < 32; i++) {
3822 cpu_fprintf(f, "%%f%02d:", i);
3823 cpu_fprintf(f, " %016lf", env->fpr[i]);
3825 cpu_fprintf(f, "\n");
3827 #ifdef TARGET_SPARC64
3828 cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
3829 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs);
3830 cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
3831 env->cansave, env->canrestore, env->otherwin, env->wstate,
3832 env->cleanwin, NWINDOWS - 1 - env->cwp);
3834 cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env),
3835 GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'),
3836 GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'),
3837 env->psrs?'S':'-', env->psrps?'P':'-',
3838 env->psret?'E':'-', env->wim);
3840 cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env));
3843 #if defined(CONFIG_USER_ONLY)
3844 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
3850 extern int get_physical_address (CPUState *env, target_phys_addr_t *physical, int *prot,
3851 int *access_index, target_ulong address, int rw,
3854 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
3856 target_phys_addr_t phys_addr;
3857 int prot, access_index;
3859 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2, 0) != 0)
3860 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 0, 0) != 0)
3862 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED)
3868 void helper_flush(target_ulong addr)
3871 tb_invalidate_page_range(addr, addr + 8);