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
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;
64 static uint16_t *gen_opc_ptr;
65 static uint32_t *gen_opparam_ptr;
70 #define DEF(s,n,copy_size) INDEX_op_ ## s,
78 // This function uses non-native bit order
79 #define GET_FIELD(X, FROM, TO) \
80 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
82 // This function uses the order in the manuals, i.e. bit 0 is 2^0
83 #define GET_FIELD_SP(X, FROM, TO) \
84 GET_FIELD(X, 31 - (TO), 31 - (FROM))
86 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
87 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
90 #define DFPREG(r) (((r & 1) << 6) | (r & 0x1e))
92 #define DFPREG(r) (r & 0x1e)
95 #ifdef USE_DIRECT_JUMP
98 #define TBPARAM(x) (long)(x)
101 static int sign_extend(int x, int len)
104 return (x << len) >> len;
107 #define IS_IMM (insn & (1<<13))
109 static void disas_sparc_insn(DisasContext * dc);
111 static GenOpFunc * const gen_op_movl_TN_reg[2][32] = {
182 static GenOpFunc * const gen_op_movl_reg_TN[3][32] = {
287 static GenOpFunc1 * const gen_op_movl_TN_im[3] = {
293 // Sign extending version
294 static GenOpFunc1 * const gen_op_movl_TN_sim[3] = {
300 #ifdef TARGET_SPARC64
301 #define GEN32(func, NAME) \
302 static GenOpFunc * const NAME ## _table [64] = { \
303 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
304 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
305 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
306 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
307 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
308 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
309 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
310 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
311 NAME ## 32, 0, NAME ## 34, 0, NAME ## 36, 0, NAME ## 38, 0, \
312 NAME ## 40, 0, NAME ## 42, 0, NAME ## 44, 0, NAME ## 46, 0, \
313 NAME ## 48, 0, NAME ## 50, 0, NAME ## 52, 0, NAME ## 54, 0, \
314 NAME ## 56, 0, NAME ## 58, 0, NAME ## 60, 0, NAME ## 62, 0, \
316 static inline void func(int n) \
318 NAME ## _table[n](); \
321 #define GEN32(func, NAME) \
322 static GenOpFunc *const NAME ## _table [32] = { \
323 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
324 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
325 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
326 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
327 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
328 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
329 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
330 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
332 static inline void func(int n) \
334 NAME ## _table[n](); \
338 /* floating point registers moves */
339 GEN32(gen_op_load_fpr_FT0, gen_op_load_fpr_FT0_fprf);
340 GEN32(gen_op_load_fpr_FT1, gen_op_load_fpr_FT1_fprf);
341 GEN32(gen_op_store_FT0_fpr, gen_op_store_FT0_fpr_fprf);
342 GEN32(gen_op_store_FT1_fpr, gen_op_store_FT1_fpr_fprf);
344 GEN32(gen_op_load_fpr_DT0, gen_op_load_fpr_DT0_fprf);
345 GEN32(gen_op_load_fpr_DT1, gen_op_load_fpr_DT1_fprf);
346 GEN32(gen_op_store_DT0_fpr, gen_op_store_DT0_fpr_fprf);
347 GEN32(gen_op_store_DT1_fpr, gen_op_store_DT1_fpr_fprf);
349 #ifdef ALIGN_7_BUGS_FIXED
351 #ifndef CONFIG_USER_ONLY
352 #define gen_op_check_align_T0_7()
357 #ifdef CONFIG_USER_ONLY
358 #define supervisor(dc) 0
359 #ifdef TARGET_SPARC64
360 #define hypervisor(dc) 0
362 #define gen_op_ldst(name) gen_op_##name##_raw()
364 #define supervisor(dc) (dc->mem_idx == 1)
365 #ifdef TARGET_SPARC64
366 #define hypervisor(dc) (dc->mem_idx == 2)
368 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
369 #define OP_LD_TABLE(width) \
370 static GenOpFunc * const gen_op_##width[] = { \
371 &gen_op_##width##_user, \
372 &gen_op_##width##_kernel, \
376 #ifndef CONFIG_USER_ONLY
394 #ifdef TARGET_SPARC64
403 #ifdef TARGET_SPARC64
404 static inline void gen_ld_asi(int insn, int size, int sign)
409 offset = GET_FIELD(insn, 25, 31);
410 gen_op_ld_asi_reg(offset, size, sign);
412 asi = GET_FIELD(insn, 19, 26);
413 gen_op_ld_asi(asi, size, sign);
417 static inline void gen_st_asi(int insn, int size)
422 offset = GET_FIELD(insn, 25, 31);
423 gen_op_st_asi_reg(offset, size);
425 asi = GET_FIELD(insn, 19, 26);
426 gen_op_st_asi(asi, size);
430 static inline void gen_swap_asi(int insn)
435 offset = GET_FIELD(insn, 25, 31);
436 gen_op_swap_asi_reg(offset);
438 asi = GET_FIELD(insn, 19, 26);
439 gen_op_swap_asi(asi);
443 static inline void gen_ldstub_asi(int insn)
448 offset = GET_FIELD(insn, 25, 31);
449 gen_op_ldstub_asi_reg(offset);
451 asi = GET_FIELD(insn, 19, 26);
452 gen_op_ldstub_asi(asi);
456 static inline void gen_ldda_asi(int insn)
461 offset = GET_FIELD(insn, 25, 31);
462 gen_op_ldda_asi_reg(offset);
464 asi = GET_FIELD(insn, 19, 26);
465 gen_op_ldda_asi(asi);
469 static inline void gen_stda_asi(int insn)
474 offset = GET_FIELD(insn, 25, 31);
475 gen_op_stda_asi_reg(offset);
477 asi = GET_FIELD(insn, 19, 26);
478 gen_op_stda_asi(asi);
482 static inline void gen_cas_asi(int insn)
487 offset = GET_FIELD(insn, 25, 31);
488 gen_op_cas_asi_reg(offset);
490 asi = GET_FIELD(insn, 19, 26);
495 static inline void gen_casx_asi(int insn)
500 offset = GET_FIELD(insn, 25, 31);
501 gen_op_casx_asi_reg(offset);
503 asi = GET_FIELD(insn, 19, 26);
504 gen_op_casx_asi(asi);
508 #elif !defined(CONFIG_USER_ONLY)
510 static inline void gen_ld_asi(int insn, int size, int sign)
514 asi = GET_FIELD(insn, 19, 26);
515 gen_op_ld_asi(asi, size, sign);
518 static inline void gen_st_asi(int insn, int size)
522 asi = GET_FIELD(insn, 19, 26);
523 gen_op_st_asi(asi, size);
526 static inline void gen_ldstub_asi(int insn)
530 asi = GET_FIELD(insn, 19, 26);
531 gen_op_ldstub_asi(asi);
534 static inline void gen_swap_asi(int insn)
538 asi = GET_FIELD(insn, 19, 26);
539 gen_op_swap_asi(asi);
542 static inline void gen_ldda_asi(int insn)
546 asi = GET_FIELD(insn, 19, 26);
547 gen_op_ld_asi(asi, 8, 0);
550 static inline void gen_stda_asi(int insn)
554 asi = GET_FIELD(insn, 19, 26);
555 gen_op_st_asi(asi, 8);
559 static inline void gen_movl_imm_TN(int reg, uint32_t imm)
561 gen_op_movl_TN_im[reg](imm);
564 static inline void gen_movl_imm_T1(uint32_t val)
566 gen_movl_imm_TN(1, val);
569 static inline void gen_movl_imm_T0(uint32_t val)
571 gen_movl_imm_TN(0, val);
574 static inline void gen_movl_simm_TN(int reg, int32_t imm)
576 gen_op_movl_TN_sim[reg](imm);
579 static inline void gen_movl_simm_T1(int32_t val)
581 gen_movl_simm_TN(1, val);
584 static inline void gen_movl_simm_T0(int32_t val)
586 gen_movl_simm_TN(0, val);
589 static inline void gen_movl_reg_TN(int reg, int t)
592 gen_op_movl_reg_TN[t][reg] ();
594 gen_movl_imm_TN(t, 0);
597 static inline void gen_movl_reg_T0(int reg)
599 gen_movl_reg_TN(reg, 0);
602 static inline void gen_movl_reg_T1(int reg)
604 gen_movl_reg_TN(reg, 1);
607 static inline void gen_movl_reg_T2(int reg)
609 gen_movl_reg_TN(reg, 2);
612 static inline void gen_movl_TN_reg(int reg, int t)
615 gen_op_movl_TN_reg[t][reg] ();
618 static inline void gen_movl_T0_reg(int reg)
620 gen_movl_TN_reg(reg, 0);
623 static inline void gen_movl_T1_reg(int reg)
625 gen_movl_TN_reg(reg, 1);
628 static inline void gen_jmp_im(target_ulong pc)
630 #ifdef TARGET_SPARC64
631 if (pc == (uint32_t)pc) {
634 gen_op_jmp_im64(pc >> 32, pc);
641 static inline void gen_movl_npc_im(target_ulong npc)
643 #ifdef TARGET_SPARC64
644 if (npc == (uint32_t)npc) {
645 gen_op_movl_npc_im(npc);
647 gen_op_movq_npc_im64(npc >> 32, npc);
650 gen_op_movl_npc_im(npc);
654 static inline void gen_goto_tb(DisasContext *s, int tb_num,
655 target_ulong pc, target_ulong npc)
657 TranslationBlock *tb;
660 if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) &&
661 (npc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK)) {
662 /* jump to same page: we can use a direct jump */
664 gen_op_goto_tb0(TBPARAM(tb));
666 gen_op_goto_tb1(TBPARAM(tb));
668 gen_movl_npc_im(npc);
669 gen_op_movl_T0_im((long)tb + tb_num);
672 /* jump to another page: currently not optimized */
674 gen_movl_npc_im(npc);
680 static inline void gen_branch2(DisasContext *dc, target_ulong pc1,
685 l1 = gen_new_label();
687 gen_op_jz_T2_label(l1);
689 gen_goto_tb(dc, 0, pc1, pc1 + 4);
692 gen_goto_tb(dc, 1, pc2, pc2 + 4);
695 static inline void gen_branch_a(DisasContext *dc, target_ulong pc1,
700 l1 = gen_new_label();
702 gen_op_jz_T2_label(l1);
704 gen_goto_tb(dc, 0, pc2, pc1);
707 gen_goto_tb(dc, 1, pc2 + 4, pc2 + 8);
710 static inline void gen_branch(DisasContext *dc, target_ulong pc,
713 gen_goto_tb(dc, 0, pc, npc);
716 static inline void gen_generic_branch(target_ulong npc1, target_ulong npc2)
720 l1 = gen_new_label();
721 l2 = gen_new_label();
722 gen_op_jz_T2_label(l1);
724 gen_movl_npc_im(npc1);
725 gen_op_jmp_label(l2);
728 gen_movl_npc_im(npc2);
732 /* call this function before using T2 as it may have been set for a jump */
733 static inline void flush_T2(DisasContext * dc)
735 if (dc->npc == JUMP_PC) {
736 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
737 dc->npc = DYNAMIC_PC;
741 static inline void save_npc(DisasContext * dc)
743 if (dc->npc == JUMP_PC) {
744 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
745 dc->npc = DYNAMIC_PC;
746 } else if (dc->npc != DYNAMIC_PC) {
747 gen_movl_npc_im(dc->npc);
751 static inline void save_state(DisasContext * dc)
757 static inline void gen_mov_pc_npc(DisasContext * dc)
759 if (dc->npc == JUMP_PC) {
760 gen_generic_branch(dc->jump_pc[0], dc->jump_pc[1]);
763 } else if (dc->npc == DYNAMIC_PC) {
771 static GenOpFunc * const gen_cond[2][16] = {
791 #ifdef TARGET_SPARC64
812 static GenOpFunc * const gen_fcond[4][16] = {
831 #ifdef TARGET_SPARC64
834 gen_op_eval_fbne_fcc1,
835 gen_op_eval_fblg_fcc1,
836 gen_op_eval_fbul_fcc1,
837 gen_op_eval_fbl_fcc1,
838 gen_op_eval_fbug_fcc1,
839 gen_op_eval_fbg_fcc1,
840 gen_op_eval_fbu_fcc1,
842 gen_op_eval_fbe_fcc1,
843 gen_op_eval_fbue_fcc1,
844 gen_op_eval_fbge_fcc1,
845 gen_op_eval_fbuge_fcc1,
846 gen_op_eval_fble_fcc1,
847 gen_op_eval_fbule_fcc1,
848 gen_op_eval_fbo_fcc1,
852 gen_op_eval_fbne_fcc2,
853 gen_op_eval_fblg_fcc2,
854 gen_op_eval_fbul_fcc2,
855 gen_op_eval_fbl_fcc2,
856 gen_op_eval_fbug_fcc2,
857 gen_op_eval_fbg_fcc2,
858 gen_op_eval_fbu_fcc2,
860 gen_op_eval_fbe_fcc2,
861 gen_op_eval_fbue_fcc2,
862 gen_op_eval_fbge_fcc2,
863 gen_op_eval_fbuge_fcc2,
864 gen_op_eval_fble_fcc2,
865 gen_op_eval_fbule_fcc2,
866 gen_op_eval_fbo_fcc2,
870 gen_op_eval_fbne_fcc3,
871 gen_op_eval_fblg_fcc3,
872 gen_op_eval_fbul_fcc3,
873 gen_op_eval_fbl_fcc3,
874 gen_op_eval_fbug_fcc3,
875 gen_op_eval_fbg_fcc3,
876 gen_op_eval_fbu_fcc3,
878 gen_op_eval_fbe_fcc3,
879 gen_op_eval_fbue_fcc3,
880 gen_op_eval_fbge_fcc3,
881 gen_op_eval_fbuge_fcc3,
882 gen_op_eval_fble_fcc3,
883 gen_op_eval_fbule_fcc3,
884 gen_op_eval_fbo_fcc3,
891 #ifdef TARGET_SPARC64
892 static void gen_cond_reg(int cond)
918 /* XXX: potentially incorrect if dynamic npc */
919 static void do_branch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
921 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
922 target_ulong target = dc->pc + offset;
925 /* unconditional not taken */
927 dc->pc = dc->npc + 4;
928 dc->npc = dc->pc + 4;
931 dc->npc = dc->pc + 4;
933 } else if (cond == 0x8) {
934 /* unconditional taken */
937 dc->npc = dc->pc + 4;
944 gen_cond[cc][cond]();
946 gen_branch_a(dc, target, dc->npc);
950 dc->jump_pc[0] = target;
951 dc->jump_pc[1] = dc->npc + 4;
957 /* XXX: potentially incorrect if dynamic npc */
958 static void do_fbranch(DisasContext * dc, int32_t offset, uint32_t insn, int cc)
960 unsigned int cond = GET_FIELD(insn, 3, 6), a = (insn & (1 << 29));
961 target_ulong target = dc->pc + offset;
964 /* unconditional not taken */
966 dc->pc = dc->npc + 4;
967 dc->npc = dc->pc + 4;
970 dc->npc = dc->pc + 4;
972 } else if (cond == 0x8) {
973 /* unconditional taken */
976 dc->npc = dc->pc + 4;
983 gen_fcond[cc][cond]();
985 gen_branch_a(dc, target, dc->npc);
989 dc->jump_pc[0] = target;
990 dc->jump_pc[1] = dc->npc + 4;
996 #ifdef TARGET_SPARC64
997 /* XXX: potentially incorrect if dynamic npc */
998 static void do_branch_reg(DisasContext * dc, int32_t offset, uint32_t insn)
1000 unsigned int cond = GET_FIELD_SP(insn, 25, 27), a = (insn & (1 << 29));
1001 target_ulong target = dc->pc + offset;
1006 gen_branch_a(dc, target, dc->npc);
1010 dc->jump_pc[0] = target;
1011 dc->jump_pc[1] = dc->npc + 4;
1016 static GenOpFunc * const gen_fcmps[4] = {
1023 static GenOpFunc * const gen_fcmpd[4] = {
1030 static GenOpFunc * const gen_fcmpes[4] = {
1037 static GenOpFunc * const gen_fcmped[4] = {
1046 static int gen_trap_ifnofpu(DisasContext * dc)
1048 #if !defined(CONFIG_USER_ONLY)
1049 if (!dc->fpu_enabled) {
1051 gen_op_exception(TT_NFPU_INSN);
1059 /* before an instruction, dc->pc must be static */
1060 static void disas_sparc_insn(DisasContext * dc)
1062 unsigned int insn, opc, rs1, rs2, rd;
1064 insn = ldl_code(dc->pc);
1065 opc = GET_FIELD(insn, 0, 1);
1067 rd = GET_FIELD(insn, 2, 6);
1069 case 0: /* branches/sethi */
1071 unsigned int xop = GET_FIELD(insn, 7, 9);
1074 #ifdef TARGET_SPARC64
1075 case 0x1: /* V9 BPcc */
1079 target = GET_FIELD_SP(insn, 0, 18);
1080 target = sign_extend(target, 18);
1082 cc = GET_FIELD_SP(insn, 20, 21);
1084 do_branch(dc, target, insn, 0);
1086 do_branch(dc, target, insn, 1);
1091 case 0x3: /* V9 BPr */
1093 target = GET_FIELD_SP(insn, 0, 13) |
1094 (GET_FIELD_SP(insn, 20, 21) << 14);
1095 target = sign_extend(target, 16);
1097 rs1 = GET_FIELD(insn, 13, 17);
1098 gen_movl_reg_T0(rs1);
1099 do_branch_reg(dc, target, insn);
1102 case 0x5: /* V9 FBPcc */
1104 int cc = GET_FIELD_SP(insn, 20, 21);
1105 if (gen_trap_ifnofpu(dc))
1107 target = GET_FIELD_SP(insn, 0, 18);
1108 target = sign_extend(target, 19);
1110 do_fbranch(dc, target, insn, cc);
1114 case 0x7: /* CBN+x */
1119 case 0x2: /* BN+x */
1121 target = GET_FIELD(insn, 10, 31);
1122 target = sign_extend(target, 22);
1124 do_branch(dc, target, insn, 0);
1127 case 0x6: /* FBN+x */
1129 if (gen_trap_ifnofpu(dc))
1131 target = GET_FIELD(insn, 10, 31);
1132 target = sign_extend(target, 22);
1134 do_fbranch(dc, target, insn, 0);
1137 case 0x4: /* SETHI */
1142 uint32_t value = GET_FIELD(insn, 10, 31);
1143 gen_movl_imm_T0(value << 10);
1144 gen_movl_T0_reg(rd);
1149 case 0x0: /* UNIMPL */
1158 target_long target = GET_FIELDs(insn, 2, 31) << 2;
1160 #ifdef TARGET_SPARC64
1161 if (dc->pc == (uint32_t)dc->pc) {
1162 gen_op_movl_T0_im(dc->pc);
1164 gen_op_movq_T0_im64(dc->pc >> 32, dc->pc);
1167 gen_op_movl_T0_im(dc->pc);
1169 gen_movl_T0_reg(15);
1175 case 2: /* FPU & Logical Operations */
1177 unsigned int xop = GET_FIELD(insn, 7, 12);
1178 if (xop == 0x3a) { /* generate trap */
1181 rs1 = GET_FIELD(insn, 13, 17);
1182 gen_movl_reg_T0(rs1);
1184 rs2 = GET_FIELD(insn, 25, 31);
1188 gen_movl_simm_T1(rs2);
1194 rs2 = GET_FIELD(insn, 27, 31);
1198 gen_movl_reg_T1(rs2);
1204 cond = GET_FIELD(insn, 3, 6);
1208 } else if (cond != 0) {
1209 #ifdef TARGET_SPARC64
1211 int cc = GET_FIELD_SP(insn, 11, 12);
1215 gen_cond[0][cond]();
1217 gen_cond[1][cond]();
1223 gen_cond[0][cond]();
1232 } else if (xop == 0x28) {
1233 rs1 = GET_FIELD(insn, 13, 17);
1236 #ifndef TARGET_SPARC64
1237 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1238 manual, rdy on the microSPARC
1240 case 0x0f: /* stbar in the SPARCv8 manual,
1241 rdy on the microSPARC II */
1242 case 0x10 ... 0x1f: /* implementation-dependent in the
1243 SPARCv8 manual, rdy on the
1246 gen_op_movtl_T0_env(offsetof(CPUSPARCState, y));
1247 gen_movl_T0_reg(rd);
1249 #ifdef TARGET_SPARC64
1250 case 0x2: /* V9 rdccr */
1252 gen_movl_T0_reg(rd);
1254 case 0x3: /* V9 rdasi */
1255 gen_op_movl_T0_env(offsetof(CPUSPARCState, asi));
1256 gen_movl_T0_reg(rd);
1258 case 0x4: /* V9 rdtick */
1260 gen_movl_T0_reg(rd);
1262 case 0x5: /* V9 rdpc */
1263 if (dc->pc == (uint32_t)dc->pc) {
1264 gen_op_movl_T0_im(dc->pc);
1266 gen_op_movq_T0_im64(dc->pc >> 32, dc->pc);
1268 gen_movl_T0_reg(rd);
1270 case 0x6: /* V9 rdfprs */
1271 gen_op_movl_T0_env(offsetof(CPUSPARCState, fprs));
1272 gen_movl_T0_reg(rd);
1274 case 0xf: /* V9 membar */
1275 break; /* no effect */
1276 case 0x13: /* Graphics Status */
1277 if (gen_trap_ifnofpu(dc))
1279 gen_op_movtl_T0_env(offsetof(CPUSPARCState, gsr));
1280 gen_movl_T0_reg(rd);
1282 case 0x17: /* Tick compare */
1283 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tick_cmpr));
1284 gen_movl_T0_reg(rd);
1286 case 0x18: /* System tick */
1288 gen_movl_T0_reg(rd);
1290 case 0x19: /* System tick compare */
1291 gen_op_movtl_T0_env(offsetof(CPUSPARCState, stick_cmpr));
1292 gen_movl_T0_reg(rd);
1294 case 0x10: /* Performance Control */
1295 case 0x11: /* Performance Instrumentation Counter */
1296 case 0x12: /* Dispatch Control */
1297 case 0x14: /* Softint set, WO */
1298 case 0x15: /* Softint clear, WO */
1299 case 0x16: /* Softint write */
1304 #if !defined(CONFIG_USER_ONLY)
1305 } else if (xop == 0x29) { /* rdpsr / UA2005 rdhpr */
1306 #ifndef TARGET_SPARC64
1307 if (!supervisor(dc))
1311 if (!hypervisor(dc))
1313 rs1 = GET_FIELD(insn, 13, 17);
1316 // gen_op_rdhpstate();
1319 // gen_op_rdhtstate();
1322 gen_op_movl_T0_env(offsetof(CPUSPARCState, hintp));
1325 gen_op_movl_T0_env(offsetof(CPUSPARCState, htba));
1328 gen_op_movl_T0_env(offsetof(CPUSPARCState, hver));
1330 case 31: // hstick_cmpr
1331 gen_op_movl_env_T0(offsetof(CPUSPARCState, hstick_cmpr));
1337 gen_movl_T0_reg(rd);
1339 } else if (xop == 0x2a) { /* rdwim / V9 rdpr */
1340 if (!supervisor(dc))
1342 #ifdef TARGET_SPARC64
1343 rs1 = GET_FIELD(insn, 13, 17);
1361 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr));
1367 gen_op_movl_T0_env(offsetof(CPUSPARCState, tl));
1370 gen_op_movl_T0_env(offsetof(CPUSPARCState, psrpil));
1376 gen_op_movl_T0_env(offsetof(CPUSPARCState, cansave));
1378 case 11: // canrestore
1379 gen_op_movl_T0_env(offsetof(CPUSPARCState, canrestore));
1381 case 12: // cleanwin
1382 gen_op_movl_T0_env(offsetof(CPUSPARCState, cleanwin));
1384 case 13: // otherwin
1385 gen_op_movl_T0_env(offsetof(CPUSPARCState, otherwin));
1388 gen_op_movl_T0_env(offsetof(CPUSPARCState, wstate));
1390 case 16: // UA2005 gl
1391 gen_op_movl_T0_env(offsetof(CPUSPARCState, gl));
1393 case 26: // UA2005 strand status
1394 if (!hypervisor(dc))
1396 gen_op_movl_T0_env(offsetof(CPUSPARCState, ssr));
1399 gen_op_movtl_T0_env(offsetof(CPUSPARCState, version));
1406 gen_op_movl_T0_env(offsetof(CPUSPARCState, wim));
1408 gen_movl_T0_reg(rd);
1410 } else if (xop == 0x2b) { /* rdtbr / V9 flushw */
1411 #ifdef TARGET_SPARC64
1414 if (!supervisor(dc))
1416 gen_op_movtl_T0_env(offsetof(CPUSPARCState, tbr));
1417 gen_movl_T0_reg(rd);
1421 } else if (xop == 0x34) { /* FPU Operations */
1422 if (gen_trap_ifnofpu(dc))
1424 gen_op_clear_ieee_excp_and_FTT();
1425 rs1 = GET_FIELD(insn, 13, 17);
1426 rs2 = GET_FIELD(insn, 27, 31);
1427 xop = GET_FIELD(insn, 18, 26);
1429 case 0x1: /* fmovs */
1430 gen_op_load_fpr_FT0(rs2);
1431 gen_op_store_FT0_fpr(rd);
1433 case 0x5: /* fnegs */
1434 gen_op_load_fpr_FT1(rs2);
1436 gen_op_store_FT0_fpr(rd);
1438 case 0x9: /* fabss */
1439 gen_op_load_fpr_FT1(rs2);
1441 gen_op_store_FT0_fpr(rd);
1443 case 0x29: /* fsqrts */
1444 gen_op_load_fpr_FT1(rs2);
1446 gen_op_store_FT0_fpr(rd);
1448 case 0x2a: /* fsqrtd */
1449 gen_op_load_fpr_DT1(DFPREG(rs2));
1451 gen_op_store_DT0_fpr(DFPREG(rd));
1453 case 0x2b: /* fsqrtq */
1456 gen_op_load_fpr_FT0(rs1);
1457 gen_op_load_fpr_FT1(rs2);
1459 gen_op_store_FT0_fpr(rd);
1462 gen_op_load_fpr_DT0(DFPREG(rs1));
1463 gen_op_load_fpr_DT1(DFPREG(rs2));
1465 gen_op_store_DT0_fpr(DFPREG(rd));
1467 case 0x43: /* faddq */
1470 gen_op_load_fpr_FT0(rs1);
1471 gen_op_load_fpr_FT1(rs2);
1473 gen_op_store_FT0_fpr(rd);
1476 gen_op_load_fpr_DT0(DFPREG(rs1));
1477 gen_op_load_fpr_DT1(DFPREG(rs2));
1479 gen_op_store_DT0_fpr(DFPREG(rd));
1481 case 0x47: /* fsubq */
1484 gen_op_load_fpr_FT0(rs1);
1485 gen_op_load_fpr_FT1(rs2);
1487 gen_op_store_FT0_fpr(rd);
1490 gen_op_load_fpr_DT0(DFPREG(rs1));
1491 gen_op_load_fpr_DT1(DFPREG(rs2));
1493 gen_op_store_DT0_fpr(rd);
1495 case 0x4b: /* fmulq */
1498 gen_op_load_fpr_FT0(rs1);
1499 gen_op_load_fpr_FT1(rs2);
1501 gen_op_store_FT0_fpr(rd);
1504 gen_op_load_fpr_DT0(DFPREG(rs1));
1505 gen_op_load_fpr_DT1(DFPREG(rs2));
1507 gen_op_store_DT0_fpr(DFPREG(rd));
1509 case 0x4f: /* fdivq */
1512 gen_op_load_fpr_FT0(rs1);
1513 gen_op_load_fpr_FT1(rs2);
1515 gen_op_store_DT0_fpr(DFPREG(rd));
1517 case 0x6e: /* fdmulq */
1520 gen_op_load_fpr_FT1(rs2);
1522 gen_op_store_FT0_fpr(rd);
1525 gen_op_load_fpr_DT1(DFPREG(rs2));
1527 gen_op_store_FT0_fpr(rd);
1529 case 0xc7: /* fqtos */
1532 gen_op_load_fpr_FT1(rs2);
1534 gen_op_store_DT0_fpr(DFPREG(rd));
1537 gen_op_load_fpr_FT1(rs2);
1539 gen_op_store_DT0_fpr(DFPREG(rd));
1541 case 0xcb: /* fqtod */
1543 case 0xcc: /* fitoq */
1545 case 0xcd: /* fstoq */
1547 case 0xce: /* fdtoq */
1550 gen_op_load_fpr_FT1(rs2);
1552 gen_op_store_FT0_fpr(rd);
1555 gen_op_load_fpr_DT1(rs2);
1557 gen_op_store_FT0_fpr(rd);
1559 case 0xd3: /* fqtoi */
1561 #ifdef TARGET_SPARC64
1562 case 0x2: /* V9 fmovd */
1563 gen_op_load_fpr_DT0(DFPREG(rs2));
1564 gen_op_store_DT0_fpr(DFPREG(rd));
1566 case 0x6: /* V9 fnegd */
1567 gen_op_load_fpr_DT1(DFPREG(rs2));
1569 gen_op_store_DT0_fpr(DFPREG(rd));
1571 case 0xa: /* V9 fabsd */
1572 gen_op_load_fpr_DT1(DFPREG(rs2));
1574 gen_op_store_DT0_fpr(DFPREG(rd));
1576 case 0x81: /* V9 fstox */
1577 gen_op_load_fpr_FT1(rs2);
1579 gen_op_store_DT0_fpr(DFPREG(rd));
1581 case 0x82: /* V9 fdtox */
1582 gen_op_load_fpr_DT1(DFPREG(rs2));
1584 gen_op_store_DT0_fpr(DFPREG(rd));
1586 case 0x84: /* V9 fxtos */
1587 gen_op_load_fpr_DT1(DFPREG(rs2));
1589 gen_op_store_FT0_fpr(rd);
1591 case 0x88: /* V9 fxtod */
1592 gen_op_load_fpr_DT1(DFPREG(rs2));
1594 gen_op_store_DT0_fpr(DFPREG(rd));
1596 case 0x3: /* V9 fmovq */
1597 case 0x7: /* V9 fnegq */
1598 case 0xb: /* V9 fabsq */
1599 case 0x83: /* V9 fqtox */
1600 case 0x8c: /* V9 fxtoq */
1606 } else if (xop == 0x35) { /* FPU Operations */
1607 #ifdef TARGET_SPARC64
1610 if (gen_trap_ifnofpu(dc))
1612 gen_op_clear_ieee_excp_and_FTT();
1613 rs1 = GET_FIELD(insn, 13, 17);
1614 rs2 = GET_FIELD(insn, 27, 31);
1615 xop = GET_FIELD(insn, 18, 26);
1616 #ifdef TARGET_SPARC64
1617 if ((xop & 0x11f) == 0x005) { // V9 fmovsr
1618 cond = GET_FIELD_SP(insn, 14, 17);
1619 gen_op_load_fpr_FT0(rd);
1620 gen_op_load_fpr_FT1(rs2);
1621 rs1 = GET_FIELD(insn, 13, 17);
1622 gen_movl_reg_T0(rs1);
1626 gen_op_store_FT0_fpr(rd);
1628 } else if ((xop & 0x11f) == 0x006) { // V9 fmovdr
1629 cond = GET_FIELD_SP(insn, 14, 17);
1630 gen_op_load_fpr_DT0(rd);
1631 gen_op_load_fpr_DT1(rs2);
1633 rs1 = GET_FIELD(insn, 13, 17);
1634 gen_movl_reg_T0(rs1);
1637 gen_op_store_DT0_fpr(rd);
1639 } else if ((xop & 0x11f) == 0x007) { // V9 fmovqr
1644 #ifdef TARGET_SPARC64
1645 case 0x001: /* V9 fmovscc %fcc0 */
1646 cond = GET_FIELD_SP(insn, 14, 17);
1647 gen_op_load_fpr_FT0(rd);
1648 gen_op_load_fpr_FT1(rs2);
1650 gen_fcond[0][cond]();
1652 gen_op_store_FT0_fpr(rd);
1654 case 0x002: /* V9 fmovdcc %fcc0 */
1655 cond = GET_FIELD_SP(insn, 14, 17);
1656 gen_op_load_fpr_DT0(rd);
1657 gen_op_load_fpr_DT1(rs2);
1659 gen_fcond[0][cond]();
1661 gen_op_store_DT0_fpr(rd);
1663 case 0x003: /* V9 fmovqcc %fcc0 */
1665 case 0x041: /* V9 fmovscc %fcc1 */
1666 cond = GET_FIELD_SP(insn, 14, 17);
1667 gen_op_load_fpr_FT0(rd);
1668 gen_op_load_fpr_FT1(rs2);
1670 gen_fcond[1][cond]();
1672 gen_op_store_FT0_fpr(rd);
1674 case 0x042: /* V9 fmovdcc %fcc1 */
1675 cond = GET_FIELD_SP(insn, 14, 17);
1676 gen_op_load_fpr_DT0(rd);
1677 gen_op_load_fpr_DT1(rs2);
1679 gen_fcond[1][cond]();
1681 gen_op_store_DT0_fpr(rd);
1683 case 0x043: /* V9 fmovqcc %fcc1 */
1685 case 0x081: /* V9 fmovscc %fcc2 */
1686 cond = GET_FIELD_SP(insn, 14, 17);
1687 gen_op_load_fpr_FT0(rd);
1688 gen_op_load_fpr_FT1(rs2);
1690 gen_fcond[2][cond]();
1692 gen_op_store_FT0_fpr(rd);
1694 case 0x082: /* V9 fmovdcc %fcc2 */
1695 cond = GET_FIELD_SP(insn, 14, 17);
1696 gen_op_load_fpr_DT0(rd);
1697 gen_op_load_fpr_DT1(rs2);
1699 gen_fcond[2][cond]();
1701 gen_op_store_DT0_fpr(rd);
1703 case 0x083: /* V9 fmovqcc %fcc2 */
1705 case 0x0c1: /* V9 fmovscc %fcc3 */
1706 cond = GET_FIELD_SP(insn, 14, 17);
1707 gen_op_load_fpr_FT0(rd);
1708 gen_op_load_fpr_FT1(rs2);
1710 gen_fcond[3][cond]();
1712 gen_op_store_FT0_fpr(rd);
1714 case 0x0c2: /* V9 fmovdcc %fcc3 */
1715 cond = GET_FIELD_SP(insn, 14, 17);
1716 gen_op_load_fpr_DT0(rd);
1717 gen_op_load_fpr_DT1(rs2);
1719 gen_fcond[3][cond]();
1721 gen_op_store_DT0_fpr(rd);
1723 case 0x0c3: /* V9 fmovqcc %fcc3 */
1725 case 0x101: /* V9 fmovscc %icc */
1726 cond = GET_FIELD_SP(insn, 14, 17);
1727 gen_op_load_fpr_FT0(rd);
1728 gen_op_load_fpr_FT1(rs2);
1730 gen_cond[0][cond]();
1732 gen_op_store_FT0_fpr(rd);
1734 case 0x102: /* V9 fmovdcc %icc */
1735 cond = GET_FIELD_SP(insn, 14, 17);
1736 gen_op_load_fpr_DT0(rd);
1737 gen_op_load_fpr_DT1(rs2);
1739 gen_cond[0][cond]();
1741 gen_op_store_DT0_fpr(rd);
1743 case 0x103: /* V9 fmovqcc %icc */
1745 case 0x181: /* V9 fmovscc %xcc */
1746 cond = GET_FIELD_SP(insn, 14, 17);
1747 gen_op_load_fpr_FT0(rd);
1748 gen_op_load_fpr_FT1(rs2);
1750 gen_cond[1][cond]();
1752 gen_op_store_FT0_fpr(rd);
1754 case 0x182: /* V9 fmovdcc %xcc */
1755 cond = GET_FIELD_SP(insn, 14, 17);
1756 gen_op_load_fpr_DT0(rd);
1757 gen_op_load_fpr_DT1(rs2);
1759 gen_cond[1][cond]();
1761 gen_op_store_DT0_fpr(rd);
1763 case 0x183: /* V9 fmovqcc %xcc */
1766 case 0x51: /* V9 %fcc */
1767 gen_op_load_fpr_FT0(rs1);
1768 gen_op_load_fpr_FT1(rs2);
1769 #ifdef TARGET_SPARC64
1770 gen_fcmps[rd & 3]();
1775 case 0x52: /* V9 %fcc */
1776 gen_op_load_fpr_DT0(DFPREG(rs1));
1777 gen_op_load_fpr_DT1(DFPREG(rs2));
1778 #ifdef TARGET_SPARC64
1779 gen_fcmpd[rd & 3]();
1784 case 0x53: /* fcmpq */
1786 case 0x55: /* fcmpes, V9 %fcc */
1787 gen_op_load_fpr_FT0(rs1);
1788 gen_op_load_fpr_FT1(rs2);
1789 #ifdef TARGET_SPARC64
1790 gen_fcmpes[rd & 3]();
1795 case 0x56: /* fcmped, V9 %fcc */
1796 gen_op_load_fpr_DT0(DFPREG(rs1));
1797 gen_op_load_fpr_DT1(DFPREG(rs2));
1798 #ifdef TARGET_SPARC64
1799 gen_fcmped[rd & 3]();
1804 case 0x57: /* fcmpeq */
1810 } else if (xop == 0x2) {
1813 rs1 = GET_FIELD(insn, 13, 17);
1815 // or %g0, x, y -> mov T1, x; mov y, T1
1816 if (IS_IMM) { /* immediate */
1817 rs2 = GET_FIELDs(insn, 19, 31);
1818 gen_movl_simm_T1(rs2);
1819 } else { /* register */
1820 rs2 = GET_FIELD(insn, 27, 31);
1821 gen_movl_reg_T1(rs2);
1823 gen_movl_T1_reg(rd);
1825 gen_movl_reg_T0(rs1);
1826 if (IS_IMM) { /* immediate */
1827 // or x, #0, y -> mov T1, x; mov y, T1
1828 rs2 = GET_FIELDs(insn, 19, 31);
1830 gen_movl_simm_T1(rs2);
1833 } else { /* register */
1834 // or x, %g0, y -> mov T1, x; mov y, T1
1835 rs2 = GET_FIELD(insn, 27, 31);
1837 gen_movl_reg_T1(rs2);
1841 gen_movl_T0_reg(rd);
1844 #ifdef TARGET_SPARC64
1845 } else if (xop == 0x25) { /* sll, V9 sllx */
1846 rs1 = GET_FIELD(insn, 13, 17);
1847 gen_movl_reg_T0(rs1);
1848 if (IS_IMM) { /* immediate */
1849 rs2 = GET_FIELDs(insn, 20, 31);
1850 gen_movl_simm_T1(rs2);
1851 } else { /* register */
1852 rs2 = GET_FIELD(insn, 27, 31);
1853 gen_movl_reg_T1(rs2);
1855 if (insn & (1 << 12))
1859 gen_movl_T0_reg(rd);
1860 } else if (xop == 0x26) { /* srl, V9 srlx */
1861 rs1 = GET_FIELD(insn, 13, 17);
1862 gen_movl_reg_T0(rs1);
1863 if (IS_IMM) { /* immediate */
1864 rs2 = GET_FIELDs(insn, 20, 31);
1865 gen_movl_simm_T1(rs2);
1866 } else { /* register */
1867 rs2 = GET_FIELD(insn, 27, 31);
1868 gen_movl_reg_T1(rs2);
1870 if (insn & (1 << 12))
1874 gen_movl_T0_reg(rd);
1875 } else if (xop == 0x27) { /* sra, V9 srax */
1876 rs1 = GET_FIELD(insn, 13, 17);
1877 gen_movl_reg_T0(rs1);
1878 if (IS_IMM) { /* immediate */
1879 rs2 = GET_FIELDs(insn, 20, 31);
1880 gen_movl_simm_T1(rs2);
1881 } else { /* register */
1882 rs2 = GET_FIELD(insn, 27, 31);
1883 gen_movl_reg_T1(rs2);
1885 if (insn & (1 << 12))
1889 gen_movl_T0_reg(rd);
1891 } else if (xop < 0x36) {
1892 rs1 = GET_FIELD(insn, 13, 17);
1893 gen_movl_reg_T0(rs1);
1894 if (IS_IMM) { /* immediate */
1895 rs2 = GET_FIELDs(insn, 19, 31);
1896 gen_movl_simm_T1(rs2);
1897 } else { /* register */
1898 rs2 = GET_FIELD(insn, 27, 31);
1899 gen_movl_reg_T1(rs2);
1902 switch (xop & ~0x10) {
1905 gen_op_add_T1_T0_cc();
1912 gen_op_logic_T0_cc();
1917 gen_op_logic_T0_cc();
1922 gen_op_logic_T0_cc();
1926 gen_op_sub_T1_T0_cc();
1931 gen_op_andn_T1_T0();
1933 gen_op_logic_T0_cc();
1938 gen_op_logic_T0_cc();
1941 gen_op_xnor_T1_T0();
1943 gen_op_logic_T0_cc();
1947 gen_op_addx_T1_T0_cc();
1949 gen_op_addx_T1_T0();
1951 #ifdef TARGET_SPARC64
1952 case 0x9: /* V9 mulx */
1953 gen_op_mulx_T1_T0();
1957 gen_op_umul_T1_T0();
1959 gen_op_logic_T0_cc();
1962 gen_op_smul_T1_T0();
1964 gen_op_logic_T0_cc();
1968 gen_op_subx_T1_T0_cc();
1970 gen_op_subx_T1_T0();
1972 #ifdef TARGET_SPARC64
1973 case 0xd: /* V9 udivx */
1974 gen_op_udivx_T1_T0();
1978 gen_op_udiv_T1_T0();
1983 gen_op_sdiv_T1_T0();
1990 gen_movl_T0_reg(rd);
1993 case 0x20: /* taddcc */
1994 gen_op_tadd_T1_T0_cc();
1995 gen_movl_T0_reg(rd);
1997 case 0x21: /* tsubcc */
1998 gen_op_tsub_T1_T0_cc();
1999 gen_movl_T0_reg(rd);
2001 case 0x22: /* taddcctv */
2002 gen_op_tadd_T1_T0_ccTV();
2003 gen_movl_T0_reg(rd);
2005 case 0x23: /* tsubcctv */
2006 gen_op_tsub_T1_T0_ccTV();
2007 gen_movl_T0_reg(rd);
2009 case 0x24: /* mulscc */
2010 gen_op_mulscc_T1_T0();
2011 gen_movl_T0_reg(rd);
2013 #ifndef TARGET_SPARC64
2014 case 0x25: /* sll */
2016 gen_movl_T0_reg(rd);
2018 case 0x26: /* srl */
2020 gen_movl_T0_reg(rd);
2022 case 0x27: /* sra */
2024 gen_movl_T0_reg(rd);
2032 gen_op_movtl_env_T0(offsetof(CPUSPARCState, y));
2034 #ifndef TARGET_SPARC64
2035 case 0x01 ... 0x0f: /* undefined in the
2039 case 0x10 ... 0x1f: /* implementation-dependent
2045 case 0x2: /* V9 wrccr */
2048 case 0x3: /* V9 wrasi */
2049 gen_op_movl_env_T0(offsetof(CPUSPARCState, asi));
2051 case 0x6: /* V9 wrfprs */
2053 gen_op_movl_env_T0(offsetof(CPUSPARCState, fprs));
2060 case 0xf: /* V9 sir, nop if user */
2061 #if !defined(CONFIG_USER_ONLY)
2066 case 0x13: /* Graphics Status */
2067 if (gen_trap_ifnofpu(dc))
2069 gen_op_movtl_env_T0(offsetof(CPUSPARCState, gsr));
2071 case 0x17: /* Tick compare */
2072 #if !defined(CONFIG_USER_ONLY)
2073 if (!supervisor(dc))
2076 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tick_cmpr));
2077 gen_op_wrtick_cmpr();
2079 case 0x18: /* System tick */
2080 #if !defined(CONFIG_USER_ONLY)
2081 if (!supervisor(dc))
2086 case 0x19: /* System tick compare */
2087 #if !defined(CONFIG_USER_ONLY)
2088 if (!supervisor(dc))
2091 gen_op_movtl_env_T0(offsetof(CPUSPARCState, stick_cmpr));
2092 gen_op_wrstick_cmpr();
2095 case 0x10: /* Performance Control */
2096 case 0x11: /* Performance Instrumentation Counter */
2097 case 0x12: /* Dispatch Control */
2098 case 0x14: /* Softint set */
2099 case 0x15: /* Softint clear */
2100 case 0x16: /* Softint write */
2107 #if !defined(CONFIG_USER_ONLY)
2108 case 0x31: /* wrpsr, V9 saved, restored */
2110 if (!supervisor(dc))
2112 #ifdef TARGET_SPARC64
2120 case 2: /* UA2005 allclean */
2121 case 3: /* UA2005 otherw */
2122 case 4: /* UA2005 normalw */
2123 case 5: /* UA2005 invalw */
2139 case 0x32: /* wrwim, V9 wrpr */
2141 if (!supervisor(dc))
2144 #ifdef TARGET_SPARC64
2162 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr));
2173 gen_op_movl_env_T0(offsetof(CPUSPARCState, tl));
2176 gen_op_movl_env_T0(offsetof(CPUSPARCState, psrpil));
2182 gen_op_movl_env_T0(offsetof(CPUSPARCState, cansave));
2184 case 11: // canrestore
2185 gen_op_movl_env_T0(offsetof(CPUSPARCState, canrestore));
2187 case 12: // cleanwin
2188 gen_op_movl_env_T0(offsetof(CPUSPARCState, cleanwin));
2190 case 13: // otherwin
2191 gen_op_movl_env_T0(offsetof(CPUSPARCState, otherwin));
2194 gen_op_movl_env_T0(offsetof(CPUSPARCState, wstate));
2196 case 16: // UA2005 gl
2197 gen_op_movl_env_T0(offsetof(CPUSPARCState, gl));
2199 case 26: // UA2005 strand status
2200 if (!hypervisor(dc))
2202 gen_op_movl_env_T0(offsetof(CPUSPARCState, ssr));
2212 case 0x33: /* wrtbr, UA2005 wrhpr */
2214 #ifndef TARGET_SPARC64
2215 if (!supervisor(dc))
2218 gen_op_movtl_env_T0(offsetof(CPUSPARCState, tbr));
2220 if (!hypervisor(dc))
2225 // XXX gen_op_wrhpstate();
2233 // XXX gen_op_wrhtstate();
2236 gen_op_movl_env_T0(offsetof(CPUSPARCState, hintp));
2239 gen_op_movl_env_T0(offsetof(CPUSPARCState, htba));
2241 case 31: // hstick_cmpr
2242 gen_op_movtl_env_T0(offsetof(CPUSPARCState, hstick_cmpr));
2243 gen_op_wrhstick_cmpr();
2245 case 6: // hver readonly
2253 #ifdef TARGET_SPARC64
2254 case 0x2c: /* V9 movcc */
2256 int cc = GET_FIELD_SP(insn, 11, 12);
2257 int cond = GET_FIELD_SP(insn, 14, 17);
2258 if (IS_IMM) { /* immediate */
2259 rs2 = GET_FIELD_SPs(insn, 0, 10);
2260 gen_movl_simm_T1(rs2);
2263 rs2 = GET_FIELD_SP(insn, 0, 4);
2264 gen_movl_reg_T1(rs2);
2266 gen_movl_reg_T0(rd);
2268 if (insn & (1 << 18)) {
2270 gen_cond[0][cond]();
2272 gen_cond[1][cond]();
2276 gen_fcond[cc][cond]();
2279 gen_movl_T0_reg(rd);
2282 case 0x2d: /* V9 sdivx */
2283 gen_op_sdivx_T1_T0();
2284 gen_movl_T0_reg(rd);
2286 case 0x2e: /* V9 popc */
2288 if (IS_IMM) { /* immediate */
2289 rs2 = GET_FIELD_SPs(insn, 0, 12);
2290 gen_movl_simm_T1(rs2);
2291 // XXX optimize: popc(constant)
2294 rs2 = GET_FIELD_SP(insn, 0, 4);
2295 gen_movl_reg_T1(rs2);
2298 gen_movl_T0_reg(rd);
2300 case 0x2f: /* V9 movr */
2302 int cond = GET_FIELD_SP(insn, 10, 12);
2303 rs1 = GET_FIELD(insn, 13, 17);
2305 gen_movl_reg_T0(rs1);
2307 if (IS_IMM) { /* immediate */
2308 rs2 = GET_FIELD_SPs(insn, 0, 9);
2309 gen_movl_simm_T1(rs2);
2312 rs2 = GET_FIELD_SP(insn, 0, 4);
2313 gen_movl_reg_T1(rs2);
2315 gen_movl_reg_T0(rd);
2317 gen_movl_T0_reg(rd);
2325 } else if (xop == 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
2326 #ifdef TARGET_SPARC64
2327 int opf = GET_FIELD_SP(insn, 5, 13);
2328 rs1 = GET_FIELD(insn, 13, 17);
2329 rs2 = GET_FIELD(insn, 27, 31);
2330 if (gen_trap_ifnofpu(dc))
2334 case 0x000: /* VIS I edge8cc */
2335 case 0x001: /* VIS II edge8n */
2336 case 0x002: /* VIS I edge8lcc */
2337 case 0x003: /* VIS II edge8ln */
2338 case 0x004: /* VIS I edge16cc */
2339 case 0x005: /* VIS II edge16n */
2340 case 0x006: /* VIS I edge16lcc */
2341 case 0x007: /* VIS II edge16ln */
2342 case 0x008: /* VIS I edge32cc */
2343 case 0x009: /* VIS II edge32n */
2344 case 0x00a: /* VIS I edge32lcc */
2345 case 0x00b: /* VIS II edge32ln */
2348 case 0x010: /* VIS I array8 */
2349 gen_movl_reg_T0(rs1);
2350 gen_movl_reg_T1(rs2);
2352 gen_movl_T0_reg(rd);
2354 case 0x012: /* VIS I array16 */
2355 gen_movl_reg_T0(rs1);
2356 gen_movl_reg_T1(rs2);
2358 gen_movl_T0_reg(rd);
2360 case 0x014: /* VIS I array32 */
2361 gen_movl_reg_T0(rs1);
2362 gen_movl_reg_T1(rs2);
2364 gen_movl_T0_reg(rd);
2366 case 0x018: /* VIS I alignaddr */
2367 gen_movl_reg_T0(rs1);
2368 gen_movl_reg_T1(rs2);
2370 gen_movl_T0_reg(rd);
2372 case 0x019: /* VIS II bmask */
2373 case 0x01a: /* VIS I alignaddrl */
2376 case 0x020: /* VIS I fcmple16 */
2377 gen_op_load_fpr_DT0(rs1);
2378 gen_op_load_fpr_DT1(rs2);
2380 gen_op_store_DT0_fpr(rd);
2382 case 0x022: /* VIS I fcmpne16 */
2383 gen_op_load_fpr_DT0(rs1);
2384 gen_op_load_fpr_DT1(rs2);
2386 gen_op_store_DT0_fpr(rd);
2388 case 0x024: /* VIS I fcmple32 */
2389 gen_op_load_fpr_DT0(rs1);
2390 gen_op_load_fpr_DT1(rs2);
2392 gen_op_store_DT0_fpr(rd);
2394 case 0x026: /* VIS I fcmpne32 */
2395 gen_op_load_fpr_DT0(rs1);
2396 gen_op_load_fpr_DT1(rs2);
2398 gen_op_store_DT0_fpr(rd);
2400 case 0x028: /* VIS I fcmpgt16 */
2401 gen_op_load_fpr_DT0(rs1);
2402 gen_op_load_fpr_DT1(rs2);
2404 gen_op_store_DT0_fpr(rd);
2406 case 0x02a: /* VIS I fcmpeq16 */
2407 gen_op_load_fpr_DT0(rs1);
2408 gen_op_load_fpr_DT1(rs2);
2410 gen_op_store_DT0_fpr(rd);
2412 case 0x02c: /* VIS I fcmpgt32 */
2413 gen_op_load_fpr_DT0(rs1);
2414 gen_op_load_fpr_DT1(rs2);
2416 gen_op_store_DT0_fpr(rd);
2418 case 0x02e: /* VIS I fcmpeq32 */
2419 gen_op_load_fpr_DT0(rs1);
2420 gen_op_load_fpr_DT1(rs2);
2422 gen_op_store_DT0_fpr(rd);
2424 case 0x031: /* VIS I fmul8x16 */
2425 gen_op_load_fpr_DT0(rs1);
2426 gen_op_load_fpr_DT1(rs2);
2428 gen_op_store_DT0_fpr(rd);
2430 case 0x033: /* VIS I fmul8x16au */
2431 gen_op_load_fpr_DT0(rs1);
2432 gen_op_load_fpr_DT1(rs2);
2433 gen_op_fmul8x16au();
2434 gen_op_store_DT0_fpr(rd);
2436 case 0x035: /* VIS I fmul8x16al */
2437 gen_op_load_fpr_DT0(rs1);
2438 gen_op_load_fpr_DT1(rs2);
2439 gen_op_fmul8x16al();
2440 gen_op_store_DT0_fpr(rd);
2442 case 0x036: /* VIS I fmul8sux16 */
2443 gen_op_load_fpr_DT0(rs1);
2444 gen_op_load_fpr_DT1(rs2);
2445 gen_op_fmul8sux16();
2446 gen_op_store_DT0_fpr(rd);
2448 case 0x037: /* VIS I fmul8ulx16 */
2449 gen_op_load_fpr_DT0(rs1);
2450 gen_op_load_fpr_DT1(rs2);
2451 gen_op_fmul8ulx16();
2452 gen_op_store_DT0_fpr(rd);
2454 case 0x038: /* VIS I fmuld8sux16 */
2455 gen_op_load_fpr_DT0(rs1);
2456 gen_op_load_fpr_DT1(rs2);
2457 gen_op_fmuld8sux16();
2458 gen_op_store_DT0_fpr(rd);
2460 case 0x039: /* VIS I fmuld8ulx16 */
2461 gen_op_load_fpr_DT0(rs1);
2462 gen_op_load_fpr_DT1(rs2);
2463 gen_op_fmuld8ulx16();
2464 gen_op_store_DT0_fpr(rd);
2466 case 0x03a: /* VIS I fpack32 */
2467 case 0x03b: /* VIS I fpack16 */
2468 case 0x03d: /* VIS I fpackfix */
2469 case 0x03e: /* VIS I pdist */
2472 case 0x048: /* VIS I faligndata */
2473 gen_op_load_fpr_DT0(rs1);
2474 gen_op_load_fpr_DT1(rs2);
2475 gen_op_faligndata();
2476 gen_op_store_DT0_fpr(rd);
2478 case 0x04b: /* VIS I fpmerge */
2479 gen_op_load_fpr_DT0(rs1);
2480 gen_op_load_fpr_DT1(rs2);
2482 gen_op_store_DT0_fpr(rd);
2484 case 0x04c: /* VIS II bshuffle */
2487 case 0x04d: /* VIS I fexpand */
2488 gen_op_load_fpr_DT0(rs1);
2489 gen_op_load_fpr_DT1(rs2);
2491 gen_op_store_DT0_fpr(rd);
2493 case 0x050: /* VIS I fpadd16 */
2494 gen_op_load_fpr_DT0(rs1);
2495 gen_op_load_fpr_DT1(rs2);
2497 gen_op_store_DT0_fpr(rd);
2499 case 0x051: /* VIS I fpadd16s */
2500 gen_op_load_fpr_FT0(rs1);
2501 gen_op_load_fpr_FT1(rs2);
2503 gen_op_store_FT0_fpr(rd);
2505 case 0x052: /* VIS I fpadd32 */
2506 gen_op_load_fpr_DT0(rs1);
2507 gen_op_load_fpr_DT1(rs2);
2509 gen_op_store_DT0_fpr(rd);
2511 case 0x053: /* VIS I fpadd32s */
2512 gen_op_load_fpr_FT0(rs1);
2513 gen_op_load_fpr_FT1(rs2);
2515 gen_op_store_FT0_fpr(rd);
2517 case 0x054: /* VIS I fpsub16 */
2518 gen_op_load_fpr_DT0(rs1);
2519 gen_op_load_fpr_DT1(rs2);
2521 gen_op_store_DT0_fpr(rd);
2523 case 0x055: /* VIS I fpsub16s */
2524 gen_op_load_fpr_FT0(rs1);
2525 gen_op_load_fpr_FT1(rs2);
2527 gen_op_store_FT0_fpr(rd);
2529 case 0x056: /* VIS I fpsub32 */
2530 gen_op_load_fpr_DT0(rs1);
2531 gen_op_load_fpr_DT1(rs2);
2533 gen_op_store_DT0_fpr(rd);
2535 case 0x057: /* VIS I fpsub32s */
2536 gen_op_load_fpr_FT0(rs1);
2537 gen_op_load_fpr_FT1(rs2);
2539 gen_op_store_FT0_fpr(rd);
2541 case 0x060: /* VIS I fzero */
2542 gen_op_movl_DT0_0();
2543 gen_op_store_DT0_fpr(rd);
2545 case 0x061: /* VIS I fzeros */
2546 gen_op_movl_FT0_0();
2547 gen_op_store_FT0_fpr(rd);
2549 case 0x062: /* VIS I fnor */
2550 gen_op_load_fpr_DT0(rs1);
2551 gen_op_load_fpr_DT1(rs2);
2553 gen_op_store_DT0_fpr(rd);
2555 case 0x063: /* VIS I fnors */
2556 gen_op_load_fpr_FT0(rs1);
2557 gen_op_load_fpr_FT1(rs2);
2559 gen_op_store_FT0_fpr(rd);
2561 case 0x064: /* VIS I fandnot2 */
2562 gen_op_load_fpr_DT1(rs1);
2563 gen_op_load_fpr_DT0(rs2);
2565 gen_op_store_DT0_fpr(rd);
2567 case 0x065: /* VIS I fandnot2s */
2568 gen_op_load_fpr_FT1(rs1);
2569 gen_op_load_fpr_FT0(rs2);
2571 gen_op_store_FT0_fpr(rd);
2573 case 0x066: /* VIS I fnot2 */
2574 gen_op_load_fpr_DT1(rs2);
2576 gen_op_store_DT0_fpr(rd);
2578 case 0x067: /* VIS I fnot2s */
2579 gen_op_load_fpr_FT1(rs2);
2581 gen_op_store_FT0_fpr(rd);
2583 case 0x068: /* VIS I fandnot1 */
2584 gen_op_load_fpr_DT0(rs1);
2585 gen_op_load_fpr_DT1(rs2);
2587 gen_op_store_DT0_fpr(rd);
2589 case 0x069: /* VIS I fandnot1s */
2590 gen_op_load_fpr_FT0(rs1);
2591 gen_op_load_fpr_FT1(rs2);
2593 gen_op_store_FT0_fpr(rd);
2595 case 0x06a: /* VIS I fnot1 */
2596 gen_op_load_fpr_DT1(rs1);
2598 gen_op_store_DT0_fpr(rd);
2600 case 0x06b: /* VIS I fnot1s */
2601 gen_op_load_fpr_FT1(rs1);
2603 gen_op_store_FT0_fpr(rd);
2605 case 0x06c: /* VIS I fxor */
2606 gen_op_load_fpr_DT0(rs1);
2607 gen_op_load_fpr_DT1(rs2);
2609 gen_op_store_DT0_fpr(rd);
2611 case 0x06d: /* VIS I fxors */
2612 gen_op_load_fpr_FT0(rs1);
2613 gen_op_load_fpr_FT1(rs2);
2615 gen_op_store_FT0_fpr(rd);
2617 case 0x06e: /* VIS I fnand */
2618 gen_op_load_fpr_DT0(rs1);
2619 gen_op_load_fpr_DT1(rs2);
2621 gen_op_store_DT0_fpr(rd);
2623 case 0x06f: /* VIS I fnands */
2624 gen_op_load_fpr_FT0(rs1);
2625 gen_op_load_fpr_FT1(rs2);
2627 gen_op_store_FT0_fpr(rd);
2629 case 0x070: /* VIS I fand */
2630 gen_op_load_fpr_DT0(rs1);
2631 gen_op_load_fpr_DT1(rs2);
2633 gen_op_store_DT0_fpr(rd);
2635 case 0x071: /* VIS I fands */
2636 gen_op_load_fpr_FT0(rs1);
2637 gen_op_load_fpr_FT1(rs2);
2639 gen_op_store_FT0_fpr(rd);
2641 case 0x072: /* VIS I fxnor */
2642 gen_op_load_fpr_DT0(rs1);
2643 gen_op_load_fpr_DT1(rs2);
2645 gen_op_store_DT0_fpr(rd);
2647 case 0x073: /* VIS I fxnors */
2648 gen_op_load_fpr_FT0(rs1);
2649 gen_op_load_fpr_FT1(rs2);
2651 gen_op_store_FT0_fpr(rd);
2653 case 0x074: /* VIS I fsrc1 */
2654 gen_op_load_fpr_DT0(rs1);
2655 gen_op_store_DT0_fpr(rd);
2657 case 0x075: /* VIS I fsrc1s */
2658 gen_op_load_fpr_FT0(rs1);
2659 gen_op_store_FT0_fpr(rd);
2661 case 0x076: /* VIS I fornot2 */
2662 gen_op_load_fpr_DT1(rs1);
2663 gen_op_load_fpr_DT0(rs2);
2665 gen_op_store_DT0_fpr(rd);
2667 case 0x077: /* VIS I fornot2s */
2668 gen_op_load_fpr_FT1(rs1);
2669 gen_op_load_fpr_FT0(rs2);
2671 gen_op_store_FT0_fpr(rd);
2673 case 0x078: /* VIS I fsrc2 */
2674 gen_op_load_fpr_DT0(rs2);
2675 gen_op_store_DT0_fpr(rd);
2677 case 0x079: /* VIS I fsrc2s */
2678 gen_op_load_fpr_FT0(rs2);
2679 gen_op_store_FT0_fpr(rd);
2681 case 0x07a: /* VIS I fornot1 */
2682 gen_op_load_fpr_DT0(rs1);
2683 gen_op_load_fpr_DT1(rs2);
2685 gen_op_store_DT0_fpr(rd);
2687 case 0x07b: /* VIS I fornot1s */
2688 gen_op_load_fpr_FT0(rs1);
2689 gen_op_load_fpr_FT1(rs2);
2691 gen_op_store_FT0_fpr(rd);
2693 case 0x07c: /* VIS I for */
2694 gen_op_load_fpr_DT0(rs1);
2695 gen_op_load_fpr_DT1(rs2);
2697 gen_op_store_DT0_fpr(rd);
2699 case 0x07d: /* VIS I fors */
2700 gen_op_load_fpr_FT0(rs1);
2701 gen_op_load_fpr_FT1(rs2);
2703 gen_op_store_FT0_fpr(rd);
2705 case 0x07e: /* VIS I fone */
2706 gen_op_movl_DT0_1();
2707 gen_op_store_DT0_fpr(rd);
2709 case 0x07f: /* VIS I fones */
2710 gen_op_movl_FT0_1();
2711 gen_op_store_FT0_fpr(rd);
2713 case 0x080: /* VIS I shutdown */
2714 case 0x081: /* VIS II siam */
2723 } else if (xop == 0x37) { /* V8 CPop2, V9 impdep2 */
2724 #ifdef TARGET_SPARC64
2729 #ifdef TARGET_SPARC64
2730 } else if (xop == 0x39) { /* V9 return */
2731 rs1 = GET_FIELD(insn, 13, 17);
2733 gen_movl_reg_T0(rs1);
2734 if (IS_IMM) { /* immediate */
2735 rs2 = GET_FIELDs(insn, 19, 31);
2739 gen_movl_simm_T1(rs2);
2744 } else { /* register */
2745 rs2 = GET_FIELD(insn, 27, 31);
2749 gen_movl_reg_T1(rs2);
2757 gen_op_check_align_T0_3();
2758 gen_op_movl_npc_T0();
2759 dc->npc = DYNAMIC_PC;
2763 rs1 = GET_FIELD(insn, 13, 17);
2764 gen_movl_reg_T0(rs1);
2765 if (IS_IMM) { /* immediate */
2766 rs2 = GET_FIELDs(insn, 19, 31);
2770 gen_movl_simm_T1(rs2);
2775 } else { /* register */
2776 rs2 = GET_FIELD(insn, 27, 31);
2780 gen_movl_reg_T1(rs2);
2787 case 0x38: /* jmpl */
2790 #ifdef TARGET_SPARC64
2791 if (dc->pc == (uint32_t)dc->pc) {
2792 gen_op_movl_T1_im(dc->pc);
2794 gen_op_movq_T1_im64(dc->pc >> 32, dc->pc);
2797 gen_op_movl_T1_im(dc->pc);
2799 gen_movl_T1_reg(rd);
2802 gen_op_check_align_T0_3();
2803 gen_op_movl_npc_T0();
2804 dc->npc = DYNAMIC_PC;
2807 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
2808 case 0x39: /* rett, V9 return */
2810 if (!supervisor(dc))
2813 gen_op_check_align_T0_3();
2814 gen_op_movl_npc_T0();
2815 dc->npc = DYNAMIC_PC;
2820 case 0x3b: /* flush */
2823 case 0x3c: /* save */
2826 gen_movl_T0_reg(rd);
2828 case 0x3d: /* restore */
2831 gen_movl_T0_reg(rd);
2833 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
2834 case 0x3e: /* V9 done/retry */
2838 if (!supervisor(dc))
2840 dc->npc = DYNAMIC_PC;
2841 dc->pc = DYNAMIC_PC;
2845 if (!supervisor(dc))
2847 dc->npc = DYNAMIC_PC;
2848 dc->pc = DYNAMIC_PC;
2864 case 3: /* load/store instructions */
2866 unsigned int xop = GET_FIELD(insn, 7, 12);
2867 rs1 = GET_FIELD(insn, 13, 17);
2869 gen_movl_reg_T0(rs1);
2870 if (xop == 0x3c || xop == 0x3e)
2872 rs2 = GET_FIELD(insn, 27, 31);
2873 gen_movl_reg_T1(rs2);
2875 else if (IS_IMM) { /* immediate */
2876 rs2 = GET_FIELDs(insn, 19, 31);
2880 gen_movl_simm_T1(rs2);
2885 } else { /* register */
2886 rs2 = GET_FIELD(insn, 27, 31);
2890 gen_movl_reg_T1(rs2);
2896 if (xop < 4 || (xop > 7 && xop < 0x14 && xop != 0x0e) ||
2897 (xop > 0x17 && xop <= 0x1d ) ||
2898 (xop > 0x2c && xop <= 0x33) || xop == 0x1f || xop == 0x3d) {
2900 case 0x0: /* load word */
2901 #ifdef CONFIG_USER_ONLY
2902 gen_op_check_align_T0_3();
2904 #ifndef TARGET_SPARC64
2910 case 0x1: /* load unsigned byte */
2913 case 0x2: /* load unsigned halfword */
2914 #ifdef CONFIG_USER_ONLY
2915 gen_op_check_align_T0_1();
2919 case 0x3: /* load double word */
2920 gen_op_check_align_T0_7();
2924 gen_movl_T0_reg(rd + 1);
2926 case 0x9: /* load signed byte */
2929 case 0xa: /* load signed halfword */
2930 #ifdef CONFIG_USER_ONLY
2931 gen_op_check_align_T0_1();
2935 case 0xd: /* ldstub -- XXX: should be atomically */
2936 gen_op_ldst(ldstub);
2938 case 0x0f: /* swap register with memory. Also atomically */
2939 #ifdef CONFIG_USER_ONLY
2940 gen_op_check_align_T0_3();
2942 gen_movl_reg_T1(rd);
2945 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2946 case 0x10: /* load word alternate */
2947 #ifndef TARGET_SPARC64
2950 if (!supervisor(dc))
2952 #elif CONFIG_USER_ONLY
2953 gen_op_check_align_T0_3();
2955 gen_ld_asi(insn, 4, 0);
2957 case 0x11: /* load unsigned byte alternate */
2958 #ifndef TARGET_SPARC64
2961 if (!supervisor(dc))
2964 gen_ld_asi(insn, 1, 0);
2966 case 0x12: /* load unsigned halfword alternate */
2967 #ifndef TARGET_SPARC64
2970 if (!supervisor(dc))
2972 #elif CONFIG_USER_ONLY
2973 gen_op_check_align_T0_1();
2975 gen_ld_asi(insn, 2, 0);
2977 case 0x13: /* load double word alternate */
2978 #ifndef TARGET_SPARC64
2981 if (!supervisor(dc))
2986 gen_op_check_align_T0_7();
2988 gen_movl_T0_reg(rd + 1);
2990 case 0x19: /* load signed byte alternate */
2991 #ifndef TARGET_SPARC64
2994 if (!supervisor(dc))
2997 gen_ld_asi(insn, 1, 1);
2999 case 0x1a: /* load signed halfword alternate */
3000 #ifndef TARGET_SPARC64
3003 if (!supervisor(dc))
3005 #elif CONFIG_USER_ONLY
3006 gen_op_check_align_T0_1();
3008 gen_ld_asi(insn, 2, 1);
3010 case 0x1d: /* ldstuba -- XXX: should be atomically */
3011 #ifndef TARGET_SPARC64
3014 if (!supervisor(dc))
3017 gen_ldstub_asi(insn);
3019 case 0x1f: /* swap reg with alt. memory. Also atomically */
3020 #ifndef TARGET_SPARC64
3023 if (!supervisor(dc))
3025 #elif CONFIG_USER_ONLY
3026 gen_op_check_align_T0_3();
3028 gen_movl_reg_T1(rd);
3032 #ifndef TARGET_SPARC64
3033 case 0x30: /* ldc */
3034 case 0x31: /* ldcsr */
3035 case 0x33: /* lddc */
3039 #ifdef TARGET_SPARC64
3040 case 0x08: /* V9 ldsw */
3041 #ifdef CONFIG_USER_ONLY
3042 gen_op_check_align_T0_3();
3046 case 0x0b: /* V9 ldx */
3047 gen_op_check_align_T0_7();
3050 case 0x18: /* V9 ldswa */
3051 #ifdef CONFIG_USER_ONLY
3052 gen_op_check_align_T0_3();
3054 gen_ld_asi(insn, 4, 1);
3056 case 0x1b: /* V9 ldxa */
3057 gen_op_check_align_T0_7();
3058 gen_ld_asi(insn, 8, 0);
3060 case 0x2d: /* V9 prefetch, no effect */
3062 case 0x30: /* V9 ldfa */
3063 #ifdef CONFIG_USER_ONLY
3064 gen_op_check_align_T0_3();
3066 gen_ld_asi(insn, 8, 0); // XXX
3068 case 0x33: /* V9 lddfa */
3069 gen_op_check_align_T0_7();
3070 gen_ld_asi(insn, 8, 0); // XXX
3072 case 0x3d: /* V9 prefetcha, no effect */
3074 case 0x32: /* V9 ldqfa */
3080 gen_movl_T1_reg(rd);
3081 #ifdef TARGET_SPARC64
3084 } else if (xop >= 0x20 && xop < 0x24) {
3085 if (gen_trap_ifnofpu(dc))
3088 case 0x20: /* load fpreg */
3089 #ifdef CONFIG_USER_ONLY
3090 gen_op_check_align_T0_3();
3093 gen_op_store_FT0_fpr(rd);
3095 case 0x21: /* load fsr */
3096 #ifdef CONFIG_USER_ONLY
3097 gen_op_check_align_T0_3();
3102 case 0x22: /* load quad fpreg */
3104 case 0x23: /* load double fpreg */
3105 gen_op_check_align_T0_7();
3107 gen_op_store_DT0_fpr(DFPREG(rd));
3112 } else if (xop < 8 || (xop >= 0x14 && xop < 0x18) || \
3113 xop == 0xe || xop == 0x1e) {
3114 gen_movl_reg_T1(rd);
3117 #ifdef CONFIG_USER_ONLY
3118 gen_op_check_align_T0_3();
3126 #ifdef CONFIG_USER_ONLY
3127 gen_op_check_align_T0_1();
3134 gen_op_check_align_T0_7();
3136 gen_movl_reg_T2(rd + 1);
3139 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
3141 #ifndef TARGET_SPARC64
3144 if (!supervisor(dc))
3147 #ifdef CONFIG_USER_ONLY
3148 gen_op_check_align_T0_3();
3150 gen_st_asi(insn, 4);
3153 #ifndef TARGET_SPARC64
3156 if (!supervisor(dc))
3159 gen_st_asi(insn, 1);
3162 #ifndef TARGET_SPARC64
3165 if (!supervisor(dc))
3168 #ifdef CONFIG_USER_ONLY
3169 gen_op_check_align_T0_1();
3171 gen_st_asi(insn, 2);
3174 #ifndef TARGET_SPARC64
3177 if (!supervisor(dc))
3182 gen_op_check_align_T0_7();
3184 gen_movl_reg_T2(rd + 1);
3188 #ifdef TARGET_SPARC64
3189 case 0x0e: /* V9 stx */
3190 gen_op_check_align_T0_7();
3193 case 0x1e: /* V9 stxa */
3194 gen_op_check_align_T0_7();
3195 gen_st_asi(insn, 8);
3201 } else if (xop > 0x23 && xop < 0x28) {
3202 if (gen_trap_ifnofpu(dc))
3206 #ifdef CONFIG_USER_ONLY
3207 gen_op_check_align_T0_3();
3209 gen_op_load_fpr_FT0(rd);
3212 case 0x25: /* stfsr, V9 stxfsr */
3213 #ifdef CONFIG_USER_ONLY
3214 gen_op_check_align_T0_3();
3219 #if !defined(CONFIG_USER_ONLY)
3220 case 0x26: /* stdfq */
3221 if (!supervisor(dc))
3223 if (gen_trap_ifnofpu(dc))
3228 gen_op_check_align_T0_7();
3229 gen_op_load_fpr_DT0(DFPREG(rd));
3235 } else if (xop > 0x33 && xop < 0x3f) {
3237 #ifdef TARGET_SPARC64
3238 case 0x34: /* V9 stfa */
3239 #ifdef CONFIG_USER_ONLY
3240 gen_op_check_align_T0_3();
3242 gen_st_asi(insn, 0); // XXX
3244 case 0x37: /* V9 stdfa */
3245 gen_op_check_align_T0_7();
3246 gen_st_asi(insn, 0); // XXX
3248 case 0x3c: /* V9 casa */
3249 #ifdef CONFIG_USER_ONLY
3250 gen_op_check_align_T0_3();
3253 gen_movl_reg_T2(rd);
3255 gen_movl_T1_reg(rd);
3257 case 0x3e: /* V9 casxa */
3258 gen_op_check_align_T0_7();
3260 gen_movl_reg_T2(rd);
3262 gen_movl_T1_reg(rd);
3264 case 0x36: /* V9 stqfa */
3267 case 0x34: /* stc */
3268 case 0x35: /* stcsr */
3269 case 0x36: /* stdcq */
3270 case 0x37: /* stdc */
3282 /* default case for non jump instructions */
3283 if (dc->npc == DYNAMIC_PC) {
3284 dc->pc = DYNAMIC_PC;
3286 } else if (dc->npc == JUMP_PC) {
3287 /* we can do a static jump */
3288 gen_branch2(dc, dc->jump_pc[0], dc->jump_pc[1]);
3292 dc->npc = dc->npc + 4;
3298 gen_op_exception(TT_ILL_INSN);
3301 #if !defined(CONFIG_USER_ONLY)
3304 gen_op_exception(TT_PRIV_INSN);
3310 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP);
3313 #if !defined(CONFIG_USER_ONLY)
3316 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR);
3320 #ifndef TARGET_SPARC64
3323 gen_op_exception(TT_NCP_INSN);
3329 static inline int gen_intermediate_code_internal(TranslationBlock * tb,
3330 int spc, CPUSPARCState *env)
3332 target_ulong pc_start, last_pc;
3333 uint16_t *gen_opc_end;
3334 DisasContext dc1, *dc = &dc1;
3337 memset(dc, 0, sizeof(DisasContext));
3342 dc->npc = (target_ulong) tb->cs_base;
3343 #if defined(CONFIG_USER_ONLY)
3345 dc->fpu_enabled = 1;
3347 dc->mem_idx = ((env->psrs) != 0);
3348 #ifdef TARGET_SPARC64
3349 dc->fpu_enabled = (((env->pstate & PS_PEF) != 0) && ((env->fprs & FPRS_FEF) != 0));
3351 dc->fpu_enabled = ((env->psref) != 0);
3354 gen_opc_ptr = gen_opc_buf;
3355 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
3356 gen_opparam_ptr = gen_opparam_buf;
3360 if (env->nb_breakpoints > 0) {
3361 for(j = 0; j < env->nb_breakpoints; j++) {
3362 if (env->breakpoints[j] == dc->pc) {
3363 if (dc->pc != pc_start)
3375 fprintf(logfile, "Search PC...\n");
3376 j = gen_opc_ptr - gen_opc_buf;
3380 gen_opc_instr_start[lj++] = 0;
3381 gen_opc_pc[lj] = dc->pc;
3382 gen_opc_npc[lj] = dc->npc;
3383 gen_opc_instr_start[lj] = 1;
3387 disas_sparc_insn(dc);
3391 /* if the next PC is different, we abort now */
3392 if (dc->pc != (last_pc + 4))
3394 /* if we reach a page boundary, we stop generation so that the
3395 PC of a TT_TFAULT exception is always in the right page */
3396 if ((dc->pc & (TARGET_PAGE_SIZE - 1)) == 0)
3398 /* if single step mode, we generate only one instruction and
3399 generate an exception */
3400 if (env->singlestep_enabled) {
3406 } while ((gen_opc_ptr < gen_opc_end) &&
3407 (dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32));
3411 if (dc->pc != DYNAMIC_PC &&
3412 (dc->npc != DYNAMIC_PC && dc->npc != JUMP_PC)) {
3413 /* static PC and NPC: we can use direct chaining */
3414 gen_branch(dc, dc->pc, dc->npc);
3416 if (dc->pc != DYNAMIC_PC)
3423 *gen_opc_ptr = INDEX_op_end;
3425 j = gen_opc_ptr - gen_opc_buf;
3428 gen_opc_instr_start[lj++] = 0;
3434 gen_opc_jump_pc[0] = dc->jump_pc[0];
3435 gen_opc_jump_pc[1] = dc->jump_pc[1];
3437 tb->size = last_pc + 4 - pc_start;
3440 if (loglevel & CPU_LOG_TB_IN_ASM) {
3441 fprintf(logfile, "--------------\n");
3442 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
3443 target_disas(logfile, pc_start, last_pc + 4 - pc_start, 0);
3444 fprintf(logfile, "\n");
3445 if (loglevel & CPU_LOG_TB_OP) {
3446 fprintf(logfile, "OP:\n");
3447 dump_ops(gen_opc_buf, gen_opparam_buf);
3448 fprintf(logfile, "\n");
3455 int gen_intermediate_code(CPUSPARCState * env, TranslationBlock * tb)
3457 return gen_intermediate_code_internal(tb, 0, env);
3460 int gen_intermediate_code_pc(CPUSPARCState * env, TranslationBlock * tb)
3462 return gen_intermediate_code_internal(tb, 1, env);
3465 extern int ram_size;
3467 void cpu_reset(CPUSPARCState *env)
3472 env->regwptr = env->regbase + (env->cwp * 16);
3473 #if defined(CONFIG_USER_ONLY)
3474 env->user_mode_only = 1;
3475 #ifdef TARGET_SPARC64
3476 env->cleanwin = NWINDOWS - 2;
3477 env->cansave = NWINDOWS - 2;
3478 env->pstate = PS_RMO | PS_PEF | PS_IE;
3479 env->asi = 0x82; // Primary no-fault
3485 #ifdef TARGET_SPARC64
3486 env->pstate = PS_PRIV;
3487 env->pc = 0x1fff0000000ULL;
3490 env->mmuregs[0] &= ~(MMU_E | MMU_NF);
3491 env->mmuregs[0] |= MMU_BM;
3493 env->npc = env->pc + 4;
3497 CPUSPARCState *cpu_sparc_init(void)
3501 env = qemu_mallocz(sizeof(CPUSPARCState));
3509 static const sparc_def_t sparc_defs[] = {
3510 #ifdef TARGET_SPARC64
3512 .name = "TI UltraSparc II",
3513 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0 << 24)
3514 | (MAXTL << 8) | (NWINDOWS - 1)),
3515 .fpu_version = 0x00000000,
3520 .name = "Fujitsu MB86904",
3521 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
3522 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
3523 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
3526 .name = "Fujitsu MB86907",
3527 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
3528 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
3529 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
3532 .name = "TI MicroSparc I",
3533 .iu_version = 0x41000000,
3534 .fpu_version = 4 << 17,
3535 .mmu_version = 0x41000000,
3538 .name = "TI SuperSparc II",
3539 .iu_version = 0x40000000,
3540 .fpu_version = 0 << 17,
3541 .mmu_version = 0x04000000,
3544 .name = "Ross RT620",
3545 .iu_version = 0x1e000000,
3546 .fpu_version = 1 << 17,
3547 .mmu_version = 0x17000000,
3552 int sparc_find_by_name(const unsigned char *name, const sparc_def_t **def)
3559 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
3560 if (strcasecmp(name, sparc_defs[i].name) == 0) {
3561 *def = &sparc_defs[i];
3570 void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
3574 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
3575 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x\n",
3577 sparc_defs[i].iu_version,
3578 sparc_defs[i].fpu_version,
3579 sparc_defs[i].mmu_version);
3583 int cpu_sparc_register (CPUSPARCState *env, const sparc_def_t *def)
3585 env->version = def->iu_version;
3586 env->fsr = def->fpu_version;
3587 #if !defined(TARGET_SPARC64)
3588 env->mmuregs[0] |= def->mmu_version;
3593 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
3595 void cpu_dump_state(CPUState *env, FILE *f,
3596 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
3601 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, env->npc);
3602 cpu_fprintf(f, "General Registers:\n");
3603 for (i = 0; i < 4; i++)
3604 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
3605 cpu_fprintf(f, "\n");
3607 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
3608 cpu_fprintf(f, "\nCurrent Register Window:\n");
3609 for (x = 0; x < 3; x++) {
3610 for (i = 0; i < 4; i++)
3611 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
3612 (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i,
3613 env->regwptr[i + x * 8]);
3614 cpu_fprintf(f, "\n");
3616 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
3617 (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i,
3618 env->regwptr[i + x * 8]);
3619 cpu_fprintf(f, "\n");
3621 cpu_fprintf(f, "\nFloating Point Registers:\n");
3622 for (i = 0; i < 32; i++) {
3624 cpu_fprintf(f, "%%f%02d:", i);
3625 cpu_fprintf(f, " %016lf", env->fpr[i]);
3627 cpu_fprintf(f, "\n");
3629 #ifdef TARGET_SPARC64
3630 cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
3631 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs);
3632 cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
3633 env->cansave, env->canrestore, env->otherwin, env->wstate,
3634 env->cleanwin, NWINDOWS - 1 - env->cwp);
3636 cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env),
3637 GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'),
3638 GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'),
3639 env->psrs?'S':'-', env->psrps?'P':'-',
3640 env->psret?'E':'-', env->wim);
3642 cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env));
3645 #if defined(CONFIG_USER_ONLY)
3646 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
3652 extern int get_physical_address (CPUState *env, target_phys_addr_t *physical, int *prot,
3653 int *access_index, target_ulong address, int rw,
3656 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
3658 target_phys_addr_t phys_addr;
3659 int prot, access_index;
3661 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2, 0) != 0)
3662 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 0, 0) != 0)
3664 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED)
3670 void helper_flush(target_ulong addr)
3673 tb_invalidate_page_range(addr, addr + 8);