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
42 #define DYNAMIC_PC 1 /* dynamic pc value */
43 #define JUMP_PC 2 /* dynamic pc value which takes only two values
44 according to jump_pc[T2] */
46 typedef struct DisasContext
{
47 target_ulong pc
; /* current Program Counter: integer or DYNAMIC_PC */
48 target_ulong npc
; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
49 target_ulong jump_pc
[2]; /* used when JUMP_PC pc value is used */
53 struct TranslationBlock
*tb
;
56 typedef struct sparc_def_t sparc_def_t
;
59 const unsigned char *name
;
60 target_ulong iu_version
;
66 static const sparc_def_t
*cpu_sparc_find_by_name(const unsigned char *name
);
68 static uint16_t *gen_opc_ptr
;
69 static uint32_t *gen_opparam_ptr
;
74 #define DEF(s,n,copy_size) INDEX_op_ ## s,
82 // This function uses non-native bit order
83 #define GET_FIELD(X, FROM, TO) \
84 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
86 // This function uses the order in the manuals, i.e. bit 0 is 2^0
87 #define GET_FIELD_SP(X, FROM, TO) \
88 GET_FIELD(X, 31 - (TO), 31 - (FROM))
90 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
91 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), ((b) - (a) + 1))
94 #define DFPREG(r) (((r & 1) << 5) | (r & 0x1e))
95 #define QFPREG(r) (((r & 1) << 5) | (r & 0x1c))
97 #define DFPREG(r) (r & 0x1e)
98 #define QFPREG(r) (r & 0x1c)
101 #ifdef USE_DIRECT_JUMP
104 #define TBPARAM(x) (long)(x)
107 static int sign_extend(int x
, int len
)
110 return (x
<< len
) >> len
;
113 #define IS_IMM (insn & (1<<13))
115 static void disas_sparc_insn(DisasContext
* dc
);
117 static GenOpFunc
* const gen_op_movl_TN_reg
[2][32] = {
188 static GenOpFunc
* const gen_op_movl_reg_TN
[3][32] = {
293 static GenOpFunc1
* const gen_op_movl_TN_im
[3] = {
299 // Sign extending version
300 static GenOpFunc1
* const gen_op_movl_TN_sim
[3] = {
306 #ifdef TARGET_SPARC64
307 #define GEN32(func, NAME) \
308 static GenOpFunc * const NAME ## _table [64] = { \
309 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
310 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
311 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
312 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
313 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
314 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
315 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
316 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
317 NAME ## 32, 0, NAME ## 34, 0, NAME ## 36, 0, NAME ## 38, 0, \
318 NAME ## 40, 0, NAME ## 42, 0, NAME ## 44, 0, NAME ## 46, 0, \
319 NAME ## 48, 0, NAME ## 50, 0, NAME ## 52, 0, NAME ## 54, 0, \
320 NAME ## 56, 0, NAME ## 58, 0, NAME ## 60, 0, NAME ## 62, 0, \
322 static inline void func(int n) \
324 NAME ## _table[n](); \
327 #define GEN32(func, NAME) \
328 static GenOpFunc *const NAME ## _table [32] = { \
329 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
330 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
331 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
332 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
333 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
334 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
335 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
336 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
338 static inline void func(int n) \
340 NAME ## _table[n](); \
344 /* floating point registers moves */
345 GEN32(gen_op_load_fpr_FT0
, gen_op_load_fpr_FT0_fprf
);
346 GEN32(gen_op_load_fpr_FT1
, gen_op_load_fpr_FT1_fprf
);
347 GEN32(gen_op_store_FT0_fpr
, gen_op_store_FT0_fpr_fprf
);
348 GEN32(gen_op_store_FT1_fpr
, gen_op_store_FT1_fpr_fprf
);
350 GEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fprf
);
351 GEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fprf
);
352 GEN32(gen_op_store_DT0_fpr
, gen_op_store_DT0_fpr_fprf
);
353 GEN32(gen_op_store_DT1_fpr
, gen_op_store_DT1_fpr_fprf
);
355 #if defined(CONFIG_USER_ONLY)
356 GEN32(gen_op_load_fpr_QT0
, gen_op_load_fpr_QT0_fprf
);
357 GEN32(gen_op_load_fpr_QT1
, gen_op_load_fpr_QT1_fprf
);
358 GEN32(gen_op_store_QT0_fpr
, gen_op_store_QT0_fpr_fprf
);
359 GEN32(gen_op_store_QT1_fpr
, gen_op_store_QT1_fpr_fprf
);
363 #ifdef CONFIG_USER_ONLY
364 #define supervisor(dc) 0
365 #ifdef TARGET_SPARC64
366 #define hypervisor(dc) 0
368 #define gen_op_ldst(name) gen_op_##name##_raw()
370 #define supervisor(dc) (dc->mem_idx >= 1)
371 #ifdef TARGET_SPARC64
372 #define hypervisor(dc) (dc->mem_idx == 2)
373 #define OP_LD_TABLE(width) \
374 static GenOpFunc * const gen_op_##width[] = { \
375 &gen_op_##width##_user, \
376 &gen_op_##width##_kernel, \
377 &gen_op_##width##_hypv, \
380 #define OP_LD_TABLE(width) \
381 static GenOpFunc * const gen_op_##width[] = { \
382 &gen_op_##width##_user, \
383 &gen_op_##width##_kernel, \
386 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
389 #ifndef CONFIG_USER_ONLY
407 #ifdef TARGET_SPARC64
416 #ifdef TARGET_SPARC64
417 static inline void gen_ld_asi(int insn
, int size
, int sign
)
422 offset
= GET_FIELD(insn
, 25, 31);
423 gen_op_ld_asi_reg(offset
, size
, sign
);
425 asi
= GET_FIELD(insn
, 19, 26);
426 gen_op_ld_asi(asi
, size
, sign
);
430 static inline void gen_st_asi(int insn
, int size
)
435 offset
= GET_FIELD(insn
, 25, 31);
436 gen_op_st_asi_reg(offset
, size
);
438 asi
= GET_FIELD(insn
, 19, 26);
439 gen_op_st_asi(asi
, size
);
443 static inline void gen_ldf_asi(int insn
, int size
, int rd
)
448 offset
= GET_FIELD(insn
, 25, 31);
449 gen_op_ldf_asi_reg(offset
, size
, rd
);
451 asi
= GET_FIELD(insn
, 19, 26);
452 gen_op_ldf_asi(asi
, size
, rd
);
456 static inline void gen_stf_asi(int insn
, int size
, int rd
)
461 offset
= GET_FIELD(insn
, 25, 31);
462 gen_op_stf_asi_reg(offset
, size
, rd
);
464 asi
= GET_FIELD(insn
, 19, 26);
465 gen_op_stf_asi(asi
, size
, rd
);
469 static inline void gen_swap_asi(int insn
)
474 offset
= GET_FIELD(insn
, 25, 31);
475 gen_op_swap_asi_reg(offset
);
477 asi
= GET_FIELD(insn
, 19, 26);
478 gen_op_swap_asi(asi
);
482 static inline void gen_ldstub_asi(int insn
)
487 offset
= GET_FIELD(insn
, 25, 31);
488 gen_op_ldstub_asi_reg(offset
);
490 asi
= GET_FIELD(insn
, 19, 26);
491 gen_op_ldstub_asi(asi
);
495 static inline void gen_ldda_asi(int insn
)
500 offset
= GET_FIELD(insn
, 25, 31);
501 gen_op_ldda_asi_reg(offset
);
503 asi
= GET_FIELD(insn
, 19, 26);
504 gen_op_ldda_asi(asi
);
508 static inline void gen_stda_asi(int insn
)
513 offset
= GET_FIELD(insn
, 25, 31);
514 gen_op_stda_asi_reg(offset
);
516 asi
= GET_FIELD(insn
, 19, 26);
517 gen_op_stda_asi(asi
);
521 static inline void gen_cas_asi(int insn
)
526 offset
= GET_FIELD(insn
, 25, 31);
527 gen_op_cas_asi_reg(offset
);
529 asi
= GET_FIELD(insn
, 19, 26);
534 static inline void gen_casx_asi(int insn
)
539 offset
= GET_FIELD(insn
, 25, 31);
540 gen_op_casx_asi_reg(offset
);
542 asi
= GET_FIELD(insn
, 19, 26);
543 gen_op_casx_asi(asi
);
547 #elif !defined(CONFIG_USER_ONLY)
549 static inline void gen_ld_asi(int insn
, int size
, int sign
)
553 asi
= GET_FIELD(insn
, 19, 26);
554 gen_op_ld_asi(asi
, size
, sign
);
557 static inline void gen_st_asi(int insn
, int size
)
561 asi
= GET_FIELD(insn
, 19, 26);
562 gen_op_st_asi(asi
, size
);
565 static inline void gen_ldstub_asi(int insn
)
569 asi
= GET_FIELD(insn
, 19, 26);
570 gen_op_ldstub_asi(asi
);
573 static inline void gen_swap_asi(int insn
)
577 asi
= GET_FIELD(insn
, 19, 26);
578 gen_op_swap_asi(asi
);
581 static inline void gen_ldda_asi(int insn
)
585 asi
= GET_FIELD(insn
, 19, 26);
586 gen_op_ld_asi(asi
, 8, 0);
589 static inline void gen_stda_asi(int insn
)
593 asi
= GET_FIELD(insn
, 19, 26);
594 gen_op_st_asi(asi
, 8);
598 static inline void gen_movl_imm_TN(int reg
, uint32_t imm
)
600 gen_op_movl_TN_im
[reg
](imm
);
603 static inline void gen_movl_imm_T1(uint32_t val
)
605 gen_movl_imm_TN(1, val
);
608 static inline void gen_movl_imm_T0(uint32_t val
)
610 gen_movl_imm_TN(0, val
);
613 static inline void gen_movl_simm_TN(int reg
, int32_t imm
)
615 gen_op_movl_TN_sim
[reg
](imm
);
618 static inline void gen_movl_simm_T1(int32_t val
)
620 gen_movl_simm_TN(1, val
);
623 static inline void gen_movl_simm_T0(int32_t val
)
625 gen_movl_simm_TN(0, val
);
628 static inline void gen_movl_reg_TN(int reg
, int t
)
631 gen_op_movl_reg_TN
[t
][reg
] ();
633 gen_movl_imm_TN(t
, 0);
636 static inline void gen_movl_reg_T0(int reg
)
638 gen_movl_reg_TN(reg
, 0);
641 static inline void gen_movl_reg_T1(int reg
)
643 gen_movl_reg_TN(reg
, 1);
646 static inline void gen_movl_reg_T2(int reg
)
648 gen_movl_reg_TN(reg
, 2);
651 static inline void gen_movl_TN_reg(int reg
, int t
)
654 gen_op_movl_TN_reg
[t
][reg
] ();
657 static inline void gen_movl_T0_reg(int reg
)
659 gen_movl_TN_reg(reg
, 0);
662 static inline void gen_movl_T1_reg(int reg
)
664 gen_movl_TN_reg(reg
, 1);
667 static inline void gen_jmp_im(target_ulong pc
)
669 #ifdef TARGET_SPARC64
670 if (pc
== (uint32_t)pc
) {
673 gen_op_jmp_im64(pc
>> 32, pc
);
680 static inline void gen_movl_npc_im(target_ulong npc
)
682 #ifdef TARGET_SPARC64
683 if (npc
== (uint32_t)npc
) {
684 gen_op_movl_npc_im(npc
);
686 gen_op_movq_npc_im64(npc
>> 32, npc
);
689 gen_op_movl_npc_im(npc
);
693 static inline void gen_goto_tb(DisasContext
*s
, int tb_num
,
694 target_ulong pc
, target_ulong npc
)
696 TranslationBlock
*tb
;
699 if ((pc
& TARGET_PAGE_MASK
) == (tb
->pc
& TARGET_PAGE_MASK
) &&
700 (npc
& TARGET_PAGE_MASK
) == (tb
->pc
& TARGET_PAGE_MASK
)) {
701 /* jump to same page: we can use a direct jump */
703 gen_op_goto_tb0(TBPARAM(tb
));
705 gen_op_goto_tb1(TBPARAM(tb
));
707 gen_movl_npc_im(npc
);
708 gen_op_movl_T0_im((long)tb
+ tb_num
);
711 /* jump to another page: currently not optimized */
713 gen_movl_npc_im(npc
);
719 static inline void gen_branch2(DisasContext
*dc
, target_ulong pc1
,
724 l1
= gen_new_label();
726 gen_op_jz_T2_label(l1
);
728 gen_goto_tb(dc
, 0, pc1
, pc1
+ 4);
731 gen_goto_tb(dc
, 1, pc2
, pc2
+ 4);
734 static inline void gen_branch_a(DisasContext
*dc
, target_ulong pc1
,
739 l1
= gen_new_label();
741 gen_op_jz_T2_label(l1
);
743 gen_goto_tb(dc
, 0, pc2
, pc1
);
746 gen_goto_tb(dc
, 1, pc2
+ 4, pc2
+ 8);
749 static inline void gen_branch(DisasContext
*dc
, target_ulong pc
,
752 gen_goto_tb(dc
, 0, pc
, npc
);
755 static inline void gen_generic_branch(target_ulong npc1
, target_ulong npc2
)
759 l1
= gen_new_label();
760 l2
= gen_new_label();
761 gen_op_jz_T2_label(l1
);
763 gen_movl_npc_im(npc1
);
764 gen_op_jmp_label(l2
);
767 gen_movl_npc_im(npc2
);
771 /* call this function before using T2 as it may have been set for a jump */
772 static inline void flush_T2(DisasContext
* dc
)
774 if (dc
->npc
== JUMP_PC
) {
775 gen_generic_branch(dc
->jump_pc
[0], dc
->jump_pc
[1]);
776 dc
->npc
= DYNAMIC_PC
;
780 static inline void save_npc(DisasContext
* dc
)
782 if (dc
->npc
== JUMP_PC
) {
783 gen_generic_branch(dc
->jump_pc
[0], dc
->jump_pc
[1]);
784 dc
->npc
= DYNAMIC_PC
;
785 } else if (dc
->npc
!= DYNAMIC_PC
) {
786 gen_movl_npc_im(dc
->npc
);
790 static inline void save_state(DisasContext
* dc
)
796 static inline void gen_mov_pc_npc(DisasContext
* dc
)
798 if (dc
->npc
== JUMP_PC
) {
799 gen_generic_branch(dc
->jump_pc
[0], dc
->jump_pc
[1]);
802 } else if (dc
->npc
== DYNAMIC_PC
) {
810 static GenOpFunc
* const gen_cond
[2][16] = {
830 #ifdef TARGET_SPARC64
851 static GenOpFunc
* const gen_fcond
[4][16] = {
870 #ifdef TARGET_SPARC64
873 gen_op_eval_fbne_fcc1
,
874 gen_op_eval_fblg_fcc1
,
875 gen_op_eval_fbul_fcc1
,
876 gen_op_eval_fbl_fcc1
,
877 gen_op_eval_fbug_fcc1
,
878 gen_op_eval_fbg_fcc1
,
879 gen_op_eval_fbu_fcc1
,
881 gen_op_eval_fbe_fcc1
,
882 gen_op_eval_fbue_fcc1
,
883 gen_op_eval_fbge_fcc1
,
884 gen_op_eval_fbuge_fcc1
,
885 gen_op_eval_fble_fcc1
,
886 gen_op_eval_fbule_fcc1
,
887 gen_op_eval_fbo_fcc1
,
891 gen_op_eval_fbne_fcc2
,
892 gen_op_eval_fblg_fcc2
,
893 gen_op_eval_fbul_fcc2
,
894 gen_op_eval_fbl_fcc2
,
895 gen_op_eval_fbug_fcc2
,
896 gen_op_eval_fbg_fcc2
,
897 gen_op_eval_fbu_fcc2
,
899 gen_op_eval_fbe_fcc2
,
900 gen_op_eval_fbue_fcc2
,
901 gen_op_eval_fbge_fcc2
,
902 gen_op_eval_fbuge_fcc2
,
903 gen_op_eval_fble_fcc2
,
904 gen_op_eval_fbule_fcc2
,
905 gen_op_eval_fbo_fcc2
,
909 gen_op_eval_fbne_fcc3
,
910 gen_op_eval_fblg_fcc3
,
911 gen_op_eval_fbul_fcc3
,
912 gen_op_eval_fbl_fcc3
,
913 gen_op_eval_fbug_fcc3
,
914 gen_op_eval_fbg_fcc3
,
915 gen_op_eval_fbu_fcc3
,
917 gen_op_eval_fbe_fcc3
,
918 gen_op_eval_fbue_fcc3
,
919 gen_op_eval_fbge_fcc3
,
920 gen_op_eval_fbuge_fcc3
,
921 gen_op_eval_fble_fcc3
,
922 gen_op_eval_fbule_fcc3
,
923 gen_op_eval_fbo_fcc3
,
930 #ifdef TARGET_SPARC64
931 static void gen_cond_reg(int cond
)
957 /* XXX: potentially incorrect if dynamic npc */
958 static void do_branch(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_cond
[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 /* XXX: potentially incorrect if dynamic npc */
997 static void do_fbranch(DisasContext
* dc
, int32_t offset
, uint32_t insn
, int cc
)
999 unsigned int cond
= GET_FIELD(insn
, 3, 6), a
= (insn
& (1 << 29));
1000 target_ulong target
= dc
->pc
+ offset
;
1003 /* unconditional not taken */
1005 dc
->pc
= dc
->npc
+ 4;
1006 dc
->npc
= dc
->pc
+ 4;
1009 dc
->npc
= dc
->pc
+ 4;
1011 } else if (cond
== 0x8) {
1012 /* unconditional taken */
1015 dc
->npc
= dc
->pc
+ 4;
1022 gen_fcond
[cc
][cond
]();
1024 gen_branch_a(dc
, target
, dc
->npc
);
1028 dc
->jump_pc
[0] = target
;
1029 dc
->jump_pc
[1] = dc
->npc
+ 4;
1035 #ifdef TARGET_SPARC64
1036 /* XXX: potentially incorrect if dynamic npc */
1037 static void do_branch_reg(DisasContext
* dc
, int32_t offset
, uint32_t insn
)
1039 unsigned int cond
= GET_FIELD_SP(insn
, 25, 27), a
= (insn
& (1 << 29));
1040 target_ulong target
= dc
->pc
+ offset
;
1045 gen_branch_a(dc
, target
, dc
->npc
);
1049 dc
->jump_pc
[0] = target
;
1050 dc
->jump_pc
[1] = dc
->npc
+ 4;
1055 static GenOpFunc
* const gen_fcmps
[4] = {
1062 static GenOpFunc
* const gen_fcmpd
[4] = {
1069 #if defined(CONFIG_USER_ONLY)
1070 static GenOpFunc
* const gen_fcmpq
[4] = {
1078 static GenOpFunc
* const gen_fcmpes
[4] = {
1085 static GenOpFunc
* const gen_fcmped
[4] = {
1092 #if defined(CONFIG_USER_ONLY)
1093 static GenOpFunc
* const gen_fcmpeq
[4] = {
1102 static int gen_trap_ifnofpu(DisasContext
* dc
)
1104 #if !defined(CONFIG_USER_ONLY)
1105 if (!dc
->fpu_enabled
) {
1107 gen_op_exception(TT_NFPU_INSN
);
1115 /* before an instruction, dc->pc must be static */
1116 static void disas_sparc_insn(DisasContext
* dc
)
1118 unsigned int insn
, opc
, rs1
, rs2
, rd
;
1120 insn
= ldl_code(dc
->pc
);
1121 opc
= GET_FIELD(insn
, 0, 1);
1123 rd
= GET_FIELD(insn
, 2, 6);
1125 case 0: /* branches/sethi */
1127 unsigned int xop
= GET_FIELD(insn
, 7, 9);
1130 #ifdef TARGET_SPARC64
1131 case 0x1: /* V9 BPcc */
1135 target
= GET_FIELD_SP(insn
, 0, 18);
1136 target
= sign_extend(target
, 18);
1138 cc
= GET_FIELD_SP(insn
, 20, 21);
1140 do_branch(dc
, target
, insn
, 0);
1142 do_branch(dc
, target
, insn
, 1);
1147 case 0x3: /* V9 BPr */
1149 target
= GET_FIELD_SP(insn
, 0, 13) |
1150 (GET_FIELD_SP(insn
, 20, 21) << 14);
1151 target
= sign_extend(target
, 16);
1153 rs1
= GET_FIELD(insn
, 13, 17);
1154 gen_movl_reg_T0(rs1
);
1155 do_branch_reg(dc
, target
, insn
);
1158 case 0x5: /* V9 FBPcc */
1160 int cc
= GET_FIELD_SP(insn
, 20, 21);
1161 if (gen_trap_ifnofpu(dc
))
1163 target
= GET_FIELD_SP(insn
, 0, 18);
1164 target
= sign_extend(target
, 19);
1166 do_fbranch(dc
, target
, insn
, cc
);
1170 case 0x7: /* CBN+x */
1175 case 0x2: /* BN+x */
1177 target
= GET_FIELD(insn
, 10, 31);
1178 target
= sign_extend(target
, 22);
1180 do_branch(dc
, target
, insn
, 0);
1183 case 0x6: /* FBN+x */
1185 if (gen_trap_ifnofpu(dc
))
1187 target
= GET_FIELD(insn
, 10, 31);
1188 target
= sign_extend(target
, 22);
1190 do_fbranch(dc
, target
, insn
, 0);
1193 case 0x4: /* SETHI */
1198 uint32_t value
= GET_FIELD(insn
, 10, 31);
1199 gen_movl_imm_T0(value
<< 10);
1200 gen_movl_T0_reg(rd
);
1205 case 0x0: /* UNIMPL */
1214 target_long target
= GET_FIELDs(insn
, 2, 31) << 2;
1216 #ifdef TARGET_SPARC64
1217 if (dc
->pc
== (uint32_t)dc
->pc
) {
1218 gen_op_movl_T0_im(dc
->pc
);
1220 gen_op_movq_T0_im64(dc
->pc
>> 32, dc
->pc
);
1223 gen_op_movl_T0_im(dc
->pc
);
1225 gen_movl_T0_reg(15);
1231 case 2: /* FPU & Logical Operations */
1233 unsigned int xop
= GET_FIELD(insn
, 7, 12);
1234 if (xop
== 0x3a) { /* generate trap */
1237 rs1
= GET_FIELD(insn
, 13, 17);
1238 gen_movl_reg_T0(rs1
);
1240 rs2
= GET_FIELD(insn
, 25, 31);
1244 gen_movl_simm_T1(rs2
);
1250 rs2
= GET_FIELD(insn
, 27, 31);
1254 gen_movl_reg_T1(rs2
);
1260 cond
= GET_FIELD(insn
, 3, 6);
1264 } else if (cond
!= 0) {
1265 #ifdef TARGET_SPARC64
1267 int cc
= GET_FIELD_SP(insn
, 11, 12);
1271 gen_cond
[0][cond
]();
1273 gen_cond
[1][cond
]();
1279 gen_cond
[0][cond
]();
1288 } else if (xop
== 0x28) {
1289 rs1
= GET_FIELD(insn
, 13, 17);
1292 #ifndef TARGET_SPARC64
1293 case 0x01 ... 0x0e: /* undefined in the SPARCv8
1294 manual, rdy on the microSPARC
1296 case 0x0f: /* stbar in the SPARCv8 manual,
1297 rdy on the microSPARC II */
1298 case 0x10 ... 0x1f: /* implementation-dependent in the
1299 SPARCv8 manual, rdy on the
1302 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, y
));
1303 gen_movl_T0_reg(rd
);
1305 #ifdef TARGET_SPARC64
1306 case 0x2: /* V9 rdccr */
1308 gen_movl_T0_reg(rd
);
1310 case 0x3: /* V9 rdasi */
1311 gen_op_movl_T0_env(offsetof(CPUSPARCState
, asi
));
1312 gen_movl_T0_reg(rd
);
1314 case 0x4: /* V9 rdtick */
1316 gen_movl_T0_reg(rd
);
1318 case 0x5: /* V9 rdpc */
1319 if (dc
->pc
== (uint32_t)dc
->pc
) {
1320 gen_op_movl_T0_im(dc
->pc
);
1322 gen_op_movq_T0_im64(dc
->pc
>> 32, dc
->pc
);
1324 gen_movl_T0_reg(rd
);
1326 case 0x6: /* V9 rdfprs */
1327 gen_op_movl_T0_env(offsetof(CPUSPARCState
, fprs
));
1328 gen_movl_T0_reg(rd
);
1330 case 0xf: /* V9 membar */
1331 break; /* no effect */
1332 case 0x13: /* Graphics Status */
1333 if (gen_trap_ifnofpu(dc
))
1335 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, gsr
));
1336 gen_movl_T0_reg(rd
);
1338 case 0x17: /* Tick compare */
1339 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, tick_cmpr
));
1340 gen_movl_T0_reg(rd
);
1342 case 0x18: /* System tick */
1344 gen_movl_T0_reg(rd
);
1346 case 0x19: /* System tick compare */
1347 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, stick_cmpr
));
1348 gen_movl_T0_reg(rd
);
1350 case 0x10: /* Performance Control */
1351 case 0x11: /* Performance Instrumentation Counter */
1352 case 0x12: /* Dispatch Control */
1353 case 0x14: /* Softint set, WO */
1354 case 0x15: /* Softint clear, WO */
1355 case 0x16: /* Softint write */
1360 #if !defined(CONFIG_USER_ONLY)
1361 } else if (xop
== 0x29) { /* rdpsr / UA2005 rdhpr */
1362 #ifndef TARGET_SPARC64
1363 if (!supervisor(dc
))
1367 if (!hypervisor(dc
))
1369 rs1
= GET_FIELD(insn
, 13, 17);
1372 // gen_op_rdhpstate();
1375 // gen_op_rdhtstate();
1378 gen_op_movl_T0_env(offsetof(CPUSPARCState
, hintp
));
1381 gen_op_movl_T0_env(offsetof(CPUSPARCState
, htba
));
1384 gen_op_movl_T0_env(offsetof(CPUSPARCState
, hver
));
1386 case 31: // hstick_cmpr
1387 gen_op_movl_env_T0(offsetof(CPUSPARCState
, hstick_cmpr
));
1393 gen_movl_T0_reg(rd
);
1395 } else if (xop
== 0x2a) { /* rdwim / V9 rdpr */
1396 if (!supervisor(dc
))
1398 #ifdef TARGET_SPARC64
1399 rs1
= GET_FIELD(insn
, 13, 17);
1417 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, tbr
));
1423 gen_op_movl_T0_env(offsetof(CPUSPARCState
, tl
));
1426 gen_op_movl_T0_env(offsetof(CPUSPARCState
, psrpil
));
1432 gen_op_movl_T0_env(offsetof(CPUSPARCState
, cansave
));
1434 case 11: // canrestore
1435 gen_op_movl_T0_env(offsetof(CPUSPARCState
, canrestore
));
1437 case 12: // cleanwin
1438 gen_op_movl_T0_env(offsetof(CPUSPARCState
, cleanwin
));
1440 case 13: // otherwin
1441 gen_op_movl_T0_env(offsetof(CPUSPARCState
, otherwin
));
1444 gen_op_movl_T0_env(offsetof(CPUSPARCState
, wstate
));
1446 case 16: // UA2005 gl
1447 gen_op_movl_T0_env(offsetof(CPUSPARCState
, gl
));
1449 case 26: // UA2005 strand status
1450 if (!hypervisor(dc
))
1452 gen_op_movl_T0_env(offsetof(CPUSPARCState
, ssr
));
1455 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, version
));
1462 gen_op_movl_T0_env(offsetof(CPUSPARCState
, wim
));
1464 gen_movl_T0_reg(rd
);
1466 } else if (xop
== 0x2b) { /* rdtbr / V9 flushw */
1467 #ifdef TARGET_SPARC64
1470 if (!supervisor(dc
))
1472 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, tbr
));
1473 gen_movl_T0_reg(rd
);
1477 } else if (xop
== 0x34) { /* FPU Operations */
1478 if (gen_trap_ifnofpu(dc
))
1480 gen_op_clear_ieee_excp_and_FTT();
1481 rs1
= GET_FIELD(insn
, 13, 17);
1482 rs2
= GET_FIELD(insn
, 27, 31);
1483 xop
= GET_FIELD(insn
, 18, 26);
1485 case 0x1: /* fmovs */
1486 gen_op_load_fpr_FT0(rs2
);
1487 gen_op_store_FT0_fpr(rd
);
1489 case 0x5: /* fnegs */
1490 gen_op_load_fpr_FT1(rs2
);
1492 gen_op_store_FT0_fpr(rd
);
1494 case 0x9: /* fabss */
1495 gen_op_load_fpr_FT1(rs2
);
1497 gen_op_store_FT0_fpr(rd
);
1499 case 0x29: /* fsqrts */
1500 gen_op_load_fpr_FT1(rs2
);
1502 gen_op_store_FT0_fpr(rd
);
1504 case 0x2a: /* fsqrtd */
1505 gen_op_load_fpr_DT1(DFPREG(rs2
));
1507 gen_op_store_DT0_fpr(DFPREG(rd
));
1509 case 0x2b: /* fsqrtq */
1510 #if defined(CONFIG_USER_ONLY)
1511 gen_op_load_fpr_QT1(QFPREG(rs2
));
1513 gen_op_store_QT0_fpr(QFPREG(rd
));
1519 gen_op_load_fpr_FT0(rs1
);
1520 gen_op_load_fpr_FT1(rs2
);
1522 gen_op_store_FT0_fpr(rd
);
1525 gen_op_load_fpr_DT0(DFPREG(rs1
));
1526 gen_op_load_fpr_DT1(DFPREG(rs2
));
1528 gen_op_store_DT0_fpr(DFPREG(rd
));
1530 case 0x43: /* faddq */
1531 #if defined(CONFIG_USER_ONLY)
1532 gen_op_load_fpr_QT0(QFPREG(rs1
));
1533 gen_op_load_fpr_QT1(QFPREG(rs2
));
1535 gen_op_store_QT0_fpr(QFPREG(rd
));
1541 gen_op_load_fpr_FT0(rs1
);
1542 gen_op_load_fpr_FT1(rs2
);
1544 gen_op_store_FT0_fpr(rd
);
1547 gen_op_load_fpr_DT0(DFPREG(rs1
));
1548 gen_op_load_fpr_DT1(DFPREG(rs2
));
1550 gen_op_store_DT0_fpr(DFPREG(rd
));
1552 case 0x47: /* fsubq */
1553 #if defined(CONFIG_USER_ONLY)
1554 gen_op_load_fpr_QT0(QFPREG(rs1
));
1555 gen_op_load_fpr_QT1(QFPREG(rs2
));
1557 gen_op_store_QT0_fpr(QFPREG(rd
));
1563 gen_op_load_fpr_FT0(rs1
);
1564 gen_op_load_fpr_FT1(rs2
);
1566 gen_op_store_FT0_fpr(rd
);
1569 gen_op_load_fpr_DT0(DFPREG(rs1
));
1570 gen_op_load_fpr_DT1(DFPREG(rs2
));
1572 gen_op_store_DT0_fpr(DFPREG(rd
));
1574 case 0x4b: /* fmulq */
1575 #if defined(CONFIG_USER_ONLY)
1576 gen_op_load_fpr_QT0(QFPREG(rs1
));
1577 gen_op_load_fpr_QT1(QFPREG(rs2
));
1579 gen_op_store_QT0_fpr(QFPREG(rd
));
1585 gen_op_load_fpr_FT0(rs1
);
1586 gen_op_load_fpr_FT1(rs2
);
1588 gen_op_store_FT0_fpr(rd
);
1591 gen_op_load_fpr_DT0(DFPREG(rs1
));
1592 gen_op_load_fpr_DT1(DFPREG(rs2
));
1594 gen_op_store_DT0_fpr(DFPREG(rd
));
1596 case 0x4f: /* fdivq */
1597 #if defined(CONFIG_USER_ONLY)
1598 gen_op_load_fpr_QT0(QFPREG(rs1
));
1599 gen_op_load_fpr_QT1(QFPREG(rs2
));
1601 gen_op_store_QT0_fpr(QFPREG(rd
));
1607 gen_op_load_fpr_FT0(rs1
);
1608 gen_op_load_fpr_FT1(rs2
);
1610 gen_op_store_DT0_fpr(DFPREG(rd
));
1612 case 0x6e: /* fdmulq */
1613 #if defined(CONFIG_USER_ONLY)
1614 gen_op_load_fpr_DT0(DFPREG(rs1
));
1615 gen_op_load_fpr_DT1(DFPREG(rs2
));
1617 gen_op_store_QT0_fpr(QFPREG(rd
));
1623 gen_op_load_fpr_FT1(rs2
);
1625 gen_op_store_FT0_fpr(rd
);
1628 gen_op_load_fpr_DT1(DFPREG(rs2
));
1630 gen_op_store_FT0_fpr(rd
);
1632 case 0xc7: /* fqtos */
1633 #if defined(CONFIG_USER_ONLY)
1634 gen_op_load_fpr_QT1(QFPREG(rs2
));
1636 gen_op_store_FT0_fpr(rd
);
1642 gen_op_load_fpr_FT1(rs2
);
1644 gen_op_store_DT0_fpr(DFPREG(rd
));
1647 gen_op_load_fpr_FT1(rs2
);
1649 gen_op_store_DT0_fpr(DFPREG(rd
));
1651 case 0xcb: /* fqtod */
1652 #if defined(CONFIG_USER_ONLY)
1653 gen_op_load_fpr_QT1(QFPREG(rs2
));
1655 gen_op_store_DT0_fpr(DFPREG(rd
));
1660 case 0xcc: /* fitoq */
1661 #if defined(CONFIG_USER_ONLY)
1662 gen_op_load_fpr_FT1(rs2
);
1664 gen_op_store_QT0_fpr(QFPREG(rd
));
1669 case 0xcd: /* fstoq */
1670 #if defined(CONFIG_USER_ONLY)
1671 gen_op_load_fpr_FT1(rs2
);
1673 gen_op_store_QT0_fpr(QFPREG(rd
));
1678 case 0xce: /* fdtoq */
1679 #if defined(CONFIG_USER_ONLY)
1680 gen_op_load_fpr_DT1(DFPREG(rs2
));
1682 gen_op_store_QT0_fpr(QFPREG(rd
));
1688 gen_op_load_fpr_FT1(rs2
);
1690 gen_op_store_FT0_fpr(rd
);
1693 gen_op_load_fpr_DT1(DFPREG(rs2
));
1695 gen_op_store_FT0_fpr(rd
);
1697 case 0xd3: /* fqtoi */
1698 #if defined(CONFIG_USER_ONLY)
1699 gen_op_load_fpr_QT1(QFPREG(rs2
));
1701 gen_op_store_FT0_fpr(rd
);
1706 #ifdef TARGET_SPARC64
1707 case 0x2: /* V9 fmovd */
1708 gen_op_load_fpr_DT0(DFPREG(rs2
));
1709 gen_op_store_DT0_fpr(DFPREG(rd
));
1711 case 0x3: /* V9 fmovq */
1712 #if defined(CONFIG_USER_ONLY)
1713 gen_op_load_fpr_QT0(QFPREG(rs2
));
1714 gen_op_store_QT0_fpr(QFPREG(rd
));
1719 case 0x6: /* V9 fnegd */
1720 gen_op_load_fpr_DT1(DFPREG(rs2
));
1722 gen_op_store_DT0_fpr(DFPREG(rd
));
1724 case 0x7: /* V9 fnegq */
1725 #if defined(CONFIG_USER_ONLY)
1726 gen_op_load_fpr_QT1(QFPREG(rs2
));
1728 gen_op_store_QT0_fpr(QFPREG(rd
));
1733 case 0xa: /* V9 fabsd */
1734 gen_op_load_fpr_DT1(DFPREG(rs2
));
1736 gen_op_store_DT0_fpr(DFPREG(rd
));
1738 case 0xb: /* V9 fabsq */
1739 #if defined(CONFIG_USER_ONLY)
1740 gen_op_load_fpr_QT1(QFPREG(rs2
));
1742 gen_op_store_QT0_fpr(QFPREG(rd
));
1747 case 0x81: /* V9 fstox */
1748 gen_op_load_fpr_FT1(rs2
);
1750 gen_op_store_DT0_fpr(DFPREG(rd
));
1752 case 0x82: /* V9 fdtox */
1753 gen_op_load_fpr_DT1(DFPREG(rs2
));
1755 gen_op_store_DT0_fpr(DFPREG(rd
));
1757 case 0x83: /* V9 fqtox */
1758 #if defined(CONFIG_USER_ONLY)
1759 gen_op_load_fpr_QT1(QFPREG(rs2
));
1761 gen_op_store_DT0_fpr(DFPREG(rd
));
1766 case 0x84: /* V9 fxtos */
1767 gen_op_load_fpr_DT1(DFPREG(rs2
));
1769 gen_op_store_FT0_fpr(rd
);
1771 case 0x88: /* V9 fxtod */
1772 gen_op_load_fpr_DT1(DFPREG(rs2
));
1774 gen_op_store_DT0_fpr(DFPREG(rd
));
1776 case 0x8c: /* V9 fxtoq */
1777 #if defined(CONFIG_USER_ONLY)
1778 gen_op_load_fpr_DT1(DFPREG(rs2
));
1780 gen_op_store_QT0_fpr(QFPREG(rd
));
1789 } else if (xop
== 0x35) { /* FPU Operations */
1790 #ifdef TARGET_SPARC64
1793 if (gen_trap_ifnofpu(dc
))
1795 gen_op_clear_ieee_excp_and_FTT();
1796 rs1
= GET_FIELD(insn
, 13, 17);
1797 rs2
= GET_FIELD(insn
, 27, 31);
1798 xop
= GET_FIELD(insn
, 18, 26);
1799 #ifdef TARGET_SPARC64
1800 if ((xop
& 0x11f) == 0x005) { // V9 fmovsr
1801 cond
= GET_FIELD_SP(insn
, 14, 17);
1802 gen_op_load_fpr_FT0(rd
);
1803 gen_op_load_fpr_FT1(rs2
);
1804 rs1
= GET_FIELD(insn
, 13, 17);
1805 gen_movl_reg_T0(rs1
);
1809 gen_op_store_FT0_fpr(rd
);
1811 } else if ((xop
& 0x11f) == 0x006) { // V9 fmovdr
1812 cond
= GET_FIELD_SP(insn
, 14, 17);
1813 gen_op_load_fpr_DT0(DFPREG(rd
));
1814 gen_op_load_fpr_DT1(DFPREG(rs2
));
1816 rs1
= GET_FIELD(insn
, 13, 17);
1817 gen_movl_reg_T0(rs1
);
1820 gen_op_store_DT0_fpr(DFPREG(rd
));
1822 } else if ((xop
& 0x11f) == 0x007) { // V9 fmovqr
1823 #if defined(CONFIG_USER_ONLY)
1824 cond
= GET_FIELD_SP(insn
, 14, 17);
1825 gen_op_load_fpr_QT0(QFPREG(rd
));
1826 gen_op_load_fpr_QT1(QFPREG(rs2
));
1828 rs1
= GET_FIELD(insn
, 13, 17);
1829 gen_movl_reg_T0(rs1
);
1832 gen_op_store_QT0_fpr(QFPREG(rd
));
1840 #ifdef TARGET_SPARC64
1841 case 0x001: /* V9 fmovscc %fcc0 */
1842 cond
= GET_FIELD_SP(insn
, 14, 17);
1843 gen_op_load_fpr_FT0(rd
);
1844 gen_op_load_fpr_FT1(rs2
);
1846 gen_fcond
[0][cond
]();
1848 gen_op_store_FT0_fpr(rd
);
1850 case 0x002: /* V9 fmovdcc %fcc0 */
1851 cond
= GET_FIELD_SP(insn
, 14, 17);
1852 gen_op_load_fpr_DT0(DFPREG(rd
));
1853 gen_op_load_fpr_DT1(DFPREG(rs2
));
1855 gen_fcond
[0][cond
]();
1857 gen_op_store_DT0_fpr(DFPREG(rd
));
1859 case 0x003: /* V9 fmovqcc %fcc0 */
1860 #if defined(CONFIG_USER_ONLY)
1861 cond
= GET_FIELD_SP(insn
, 14, 17);
1862 gen_op_load_fpr_QT0(QFPREG(rd
));
1863 gen_op_load_fpr_QT1(QFPREG(rs2
));
1865 gen_fcond
[0][cond
]();
1867 gen_op_store_QT0_fpr(QFPREG(rd
));
1872 case 0x041: /* V9 fmovscc %fcc1 */
1873 cond
= GET_FIELD_SP(insn
, 14, 17);
1874 gen_op_load_fpr_FT0(rd
);
1875 gen_op_load_fpr_FT1(rs2
);
1877 gen_fcond
[1][cond
]();
1879 gen_op_store_FT0_fpr(rd
);
1881 case 0x042: /* V9 fmovdcc %fcc1 */
1882 cond
= GET_FIELD_SP(insn
, 14, 17);
1883 gen_op_load_fpr_DT0(DFPREG(rd
));
1884 gen_op_load_fpr_DT1(DFPREG(rs2
));
1886 gen_fcond
[1][cond
]();
1888 gen_op_store_DT0_fpr(DFPREG(rd
));
1890 case 0x043: /* V9 fmovqcc %fcc1 */
1891 #if defined(CONFIG_USER_ONLY)
1892 cond
= GET_FIELD_SP(insn
, 14, 17);
1893 gen_op_load_fpr_QT0(QFPREG(rd
));
1894 gen_op_load_fpr_QT1(QFPREG(rs2
));
1896 gen_fcond
[1][cond
]();
1898 gen_op_store_QT0_fpr(QFPREG(rd
));
1903 case 0x081: /* V9 fmovscc %fcc2 */
1904 cond
= GET_FIELD_SP(insn
, 14, 17);
1905 gen_op_load_fpr_FT0(rd
);
1906 gen_op_load_fpr_FT1(rs2
);
1908 gen_fcond
[2][cond
]();
1910 gen_op_store_FT0_fpr(rd
);
1912 case 0x082: /* V9 fmovdcc %fcc2 */
1913 cond
= GET_FIELD_SP(insn
, 14, 17);
1914 gen_op_load_fpr_DT0(DFPREG(rd
));
1915 gen_op_load_fpr_DT1(DFPREG(rs2
));
1917 gen_fcond
[2][cond
]();
1919 gen_op_store_DT0_fpr(DFPREG(rd
));
1921 case 0x083: /* V9 fmovqcc %fcc2 */
1922 #if defined(CONFIG_USER_ONLY)
1923 cond
= GET_FIELD_SP(insn
, 14, 17);
1924 gen_op_load_fpr_QT0(rd
);
1925 gen_op_load_fpr_QT1(rs2
);
1927 gen_fcond
[2][cond
]();
1929 gen_op_store_QT0_fpr(rd
);
1934 case 0x0c1: /* V9 fmovscc %fcc3 */
1935 cond
= GET_FIELD_SP(insn
, 14, 17);
1936 gen_op_load_fpr_FT0(rd
);
1937 gen_op_load_fpr_FT1(rs2
);
1939 gen_fcond
[3][cond
]();
1941 gen_op_store_FT0_fpr(rd
);
1943 case 0x0c2: /* V9 fmovdcc %fcc3 */
1944 cond
= GET_FIELD_SP(insn
, 14, 17);
1945 gen_op_load_fpr_DT0(DFPREG(rd
));
1946 gen_op_load_fpr_DT1(DFPREG(rs2
));
1948 gen_fcond
[3][cond
]();
1950 gen_op_store_DT0_fpr(DFPREG(rd
));
1952 case 0x0c3: /* V9 fmovqcc %fcc3 */
1953 #if defined(CONFIG_USER_ONLY)
1954 cond
= GET_FIELD_SP(insn
, 14, 17);
1955 gen_op_load_fpr_QT0(QFPREG(rd
));
1956 gen_op_load_fpr_QT1(QFPREG(rs2
));
1958 gen_fcond
[3][cond
]();
1960 gen_op_store_QT0_fpr(QFPREG(rd
));
1965 case 0x101: /* V9 fmovscc %icc */
1966 cond
= GET_FIELD_SP(insn
, 14, 17);
1967 gen_op_load_fpr_FT0(rd
);
1968 gen_op_load_fpr_FT1(rs2
);
1970 gen_cond
[0][cond
]();
1972 gen_op_store_FT0_fpr(rd
);
1974 case 0x102: /* V9 fmovdcc %icc */
1975 cond
= GET_FIELD_SP(insn
, 14, 17);
1976 gen_op_load_fpr_DT0(DFPREG(rd
));
1977 gen_op_load_fpr_DT1(DFPREG(rs2
));
1979 gen_cond
[0][cond
]();
1981 gen_op_store_DT0_fpr(DFPREG(rd
));
1983 case 0x103: /* V9 fmovqcc %icc */
1984 #if defined(CONFIG_USER_ONLY)
1985 cond
= GET_FIELD_SP(insn
, 14, 17);
1986 gen_op_load_fpr_QT0(rd
);
1987 gen_op_load_fpr_QT1(rs2
);
1989 gen_cond
[0][cond
]();
1991 gen_op_store_QT0_fpr(rd
);
1996 case 0x181: /* V9 fmovscc %xcc */
1997 cond
= GET_FIELD_SP(insn
, 14, 17);
1998 gen_op_load_fpr_FT0(rd
);
1999 gen_op_load_fpr_FT1(rs2
);
2001 gen_cond
[1][cond
]();
2003 gen_op_store_FT0_fpr(rd
);
2005 case 0x182: /* V9 fmovdcc %xcc */
2006 cond
= GET_FIELD_SP(insn
, 14, 17);
2007 gen_op_load_fpr_DT0(DFPREG(rd
));
2008 gen_op_load_fpr_DT1(DFPREG(rs2
));
2010 gen_cond
[1][cond
]();
2012 gen_op_store_DT0_fpr(DFPREG(rd
));
2014 case 0x183: /* V9 fmovqcc %xcc */
2015 #if defined(CONFIG_USER_ONLY)
2016 cond
= GET_FIELD_SP(insn
, 14, 17);
2017 gen_op_load_fpr_QT0(rd
);
2018 gen_op_load_fpr_QT1(rs2
);
2020 gen_cond
[1][cond
]();
2022 gen_op_store_QT0_fpr(rd
);
2028 case 0x51: /* fcmps, V9 %fcc */
2029 gen_op_load_fpr_FT0(rs1
);
2030 gen_op_load_fpr_FT1(rs2
);
2031 #ifdef TARGET_SPARC64
2032 gen_fcmps
[rd
& 3]();
2037 case 0x52: /* fcmpd, V9 %fcc */
2038 gen_op_load_fpr_DT0(DFPREG(rs1
));
2039 gen_op_load_fpr_DT1(DFPREG(rs2
));
2040 #ifdef TARGET_SPARC64
2041 gen_fcmpd
[rd
& 3]();
2046 case 0x53: /* fcmpq, V9 %fcc */
2047 #if defined(CONFIG_USER_ONLY)
2048 gen_op_load_fpr_QT0(QFPREG(rs1
));
2049 gen_op_load_fpr_QT1(QFPREG(rs2
));
2050 #ifdef TARGET_SPARC64
2051 gen_fcmpq
[rd
& 3]();
2056 #else /* !defined(CONFIG_USER_ONLY) */
2059 case 0x55: /* fcmpes, V9 %fcc */
2060 gen_op_load_fpr_FT0(rs1
);
2061 gen_op_load_fpr_FT1(rs2
);
2062 #ifdef TARGET_SPARC64
2063 gen_fcmpes
[rd
& 3]();
2068 case 0x56: /* fcmped, V9 %fcc */
2069 gen_op_load_fpr_DT0(DFPREG(rs1
));
2070 gen_op_load_fpr_DT1(DFPREG(rs2
));
2071 #ifdef TARGET_SPARC64
2072 gen_fcmped
[rd
& 3]();
2077 case 0x57: /* fcmpeq, V9 %fcc */
2078 #if defined(CONFIG_USER_ONLY)
2079 gen_op_load_fpr_QT0(QFPREG(rs1
));
2080 gen_op_load_fpr_QT1(QFPREG(rs2
));
2081 #ifdef TARGET_SPARC64
2082 gen_fcmpeq
[rd
& 3]();
2087 #else/* !defined(CONFIG_USER_ONLY) */
2094 } else if (xop
== 0x2) {
2097 rs1
= GET_FIELD(insn
, 13, 17);
2099 // or %g0, x, y -> mov T1, x; mov y, T1
2100 if (IS_IMM
) { /* immediate */
2101 rs2
= GET_FIELDs(insn
, 19, 31);
2102 gen_movl_simm_T1(rs2
);
2103 } else { /* register */
2104 rs2
= GET_FIELD(insn
, 27, 31);
2105 gen_movl_reg_T1(rs2
);
2107 gen_movl_T1_reg(rd
);
2109 gen_movl_reg_T0(rs1
);
2110 if (IS_IMM
) { /* immediate */
2111 // or x, #0, y -> mov T1, x; mov y, T1
2112 rs2
= GET_FIELDs(insn
, 19, 31);
2114 gen_movl_simm_T1(rs2
);
2117 } else { /* register */
2118 // or x, %g0, y -> mov T1, x; mov y, T1
2119 rs2
= GET_FIELD(insn
, 27, 31);
2121 gen_movl_reg_T1(rs2
);
2125 gen_movl_T0_reg(rd
);
2128 #ifdef TARGET_SPARC64
2129 } else if (xop
== 0x25) { /* sll, V9 sllx */
2130 rs1
= GET_FIELD(insn
, 13, 17);
2131 gen_movl_reg_T0(rs1
);
2132 if (IS_IMM
) { /* immediate */
2133 rs2
= GET_FIELDs(insn
, 20, 31);
2134 gen_movl_simm_T1(rs2
);
2135 } else { /* register */
2136 rs2
= GET_FIELD(insn
, 27, 31);
2137 gen_movl_reg_T1(rs2
);
2139 if (insn
& (1 << 12))
2143 gen_movl_T0_reg(rd
);
2144 } else if (xop
== 0x26) { /* srl, V9 srlx */
2145 rs1
= GET_FIELD(insn
, 13, 17);
2146 gen_movl_reg_T0(rs1
);
2147 if (IS_IMM
) { /* immediate */
2148 rs2
= GET_FIELDs(insn
, 20, 31);
2149 gen_movl_simm_T1(rs2
);
2150 } else { /* register */
2151 rs2
= GET_FIELD(insn
, 27, 31);
2152 gen_movl_reg_T1(rs2
);
2154 if (insn
& (1 << 12))
2158 gen_movl_T0_reg(rd
);
2159 } else if (xop
== 0x27) { /* sra, V9 srax */
2160 rs1
= GET_FIELD(insn
, 13, 17);
2161 gen_movl_reg_T0(rs1
);
2162 if (IS_IMM
) { /* immediate */
2163 rs2
= GET_FIELDs(insn
, 20, 31);
2164 gen_movl_simm_T1(rs2
);
2165 } else { /* register */
2166 rs2
= GET_FIELD(insn
, 27, 31);
2167 gen_movl_reg_T1(rs2
);
2169 if (insn
& (1 << 12))
2173 gen_movl_T0_reg(rd
);
2175 } else if (xop
< 0x36) {
2176 rs1
= GET_FIELD(insn
, 13, 17);
2177 gen_movl_reg_T0(rs1
);
2178 if (IS_IMM
) { /* immediate */
2179 rs2
= GET_FIELDs(insn
, 19, 31);
2180 gen_movl_simm_T1(rs2
);
2181 } else { /* register */
2182 rs2
= GET_FIELD(insn
, 27, 31);
2183 gen_movl_reg_T1(rs2
);
2186 switch (xop
& ~0x10) {
2189 gen_op_add_T1_T0_cc();
2196 gen_op_logic_T0_cc();
2201 gen_op_logic_T0_cc();
2206 gen_op_logic_T0_cc();
2210 gen_op_sub_T1_T0_cc();
2215 gen_op_andn_T1_T0();
2217 gen_op_logic_T0_cc();
2222 gen_op_logic_T0_cc();
2225 gen_op_xnor_T1_T0();
2227 gen_op_logic_T0_cc();
2231 gen_op_addx_T1_T0_cc();
2233 gen_op_addx_T1_T0();
2235 #ifdef TARGET_SPARC64
2236 case 0x9: /* V9 mulx */
2237 gen_op_mulx_T1_T0();
2241 gen_op_umul_T1_T0();
2243 gen_op_logic_T0_cc();
2246 gen_op_smul_T1_T0();
2248 gen_op_logic_T0_cc();
2252 gen_op_subx_T1_T0_cc();
2254 gen_op_subx_T1_T0();
2256 #ifdef TARGET_SPARC64
2257 case 0xd: /* V9 udivx */
2258 gen_op_udivx_T1_T0();
2262 gen_op_udiv_T1_T0();
2267 gen_op_sdiv_T1_T0();
2274 gen_movl_T0_reg(rd
);
2277 case 0x20: /* taddcc */
2278 gen_op_tadd_T1_T0_cc();
2279 gen_movl_T0_reg(rd
);
2281 case 0x21: /* tsubcc */
2282 gen_op_tsub_T1_T0_cc();
2283 gen_movl_T0_reg(rd
);
2285 case 0x22: /* taddcctv */
2287 gen_op_tadd_T1_T0_ccTV();
2288 gen_movl_T0_reg(rd
);
2290 case 0x23: /* tsubcctv */
2292 gen_op_tsub_T1_T0_ccTV();
2293 gen_movl_T0_reg(rd
);
2295 case 0x24: /* mulscc */
2296 gen_op_mulscc_T1_T0();
2297 gen_movl_T0_reg(rd
);
2299 #ifndef TARGET_SPARC64
2300 case 0x25: /* sll */
2302 gen_movl_T0_reg(rd
);
2304 case 0x26: /* srl */
2306 gen_movl_T0_reg(rd
);
2308 case 0x27: /* sra */
2310 gen_movl_T0_reg(rd
);
2318 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, y
));
2320 #ifndef TARGET_SPARC64
2321 case 0x01 ... 0x0f: /* undefined in the
2325 case 0x10 ... 0x1f: /* implementation-dependent
2331 case 0x2: /* V9 wrccr */
2335 case 0x3: /* V9 wrasi */
2337 gen_op_movl_env_T0(offsetof(CPUSPARCState
, asi
));
2339 case 0x6: /* V9 wrfprs */
2341 gen_op_movl_env_T0(offsetof(CPUSPARCState
, fprs
));
2348 case 0xf: /* V9 sir, nop if user */
2349 #if !defined(CONFIG_USER_ONLY)
2354 case 0x13: /* Graphics Status */
2355 if (gen_trap_ifnofpu(dc
))
2358 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, gsr
));
2360 case 0x17: /* Tick compare */
2361 #if !defined(CONFIG_USER_ONLY)
2362 if (!supervisor(dc
))
2366 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, tick_cmpr
));
2367 gen_op_wrtick_cmpr();
2369 case 0x18: /* System tick */
2370 #if !defined(CONFIG_USER_ONLY)
2371 if (!supervisor(dc
))
2377 case 0x19: /* System tick compare */
2378 #if !defined(CONFIG_USER_ONLY)
2379 if (!supervisor(dc
))
2383 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, stick_cmpr
));
2384 gen_op_wrstick_cmpr();
2387 case 0x10: /* Performance Control */
2388 case 0x11: /* Performance Instrumentation Counter */
2389 case 0x12: /* Dispatch Control */
2390 case 0x14: /* Softint set */
2391 case 0x15: /* Softint clear */
2392 case 0x16: /* Softint write */
2399 #if !defined(CONFIG_USER_ONLY)
2400 case 0x31: /* wrpsr, V9 saved, restored */
2402 if (!supervisor(dc
))
2404 #ifdef TARGET_SPARC64
2412 case 2: /* UA2005 allclean */
2413 case 3: /* UA2005 otherw */
2414 case 4: /* UA2005 normalw */
2415 case 5: /* UA2005 invalw */
2431 case 0x32: /* wrwim, V9 wrpr */
2433 if (!supervisor(dc
))
2436 #ifdef TARGET_SPARC64
2454 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, tbr
));
2465 gen_op_movl_env_T0(offsetof(CPUSPARCState
, tl
));
2468 gen_op_movl_env_T0(offsetof(CPUSPARCState
, psrpil
));
2474 gen_op_movl_env_T0(offsetof(CPUSPARCState
, cansave
));
2476 case 11: // canrestore
2477 gen_op_movl_env_T0(offsetof(CPUSPARCState
, canrestore
));
2479 case 12: // cleanwin
2480 gen_op_movl_env_T0(offsetof(CPUSPARCState
, cleanwin
));
2482 case 13: // otherwin
2483 gen_op_movl_env_T0(offsetof(CPUSPARCState
, otherwin
));
2486 gen_op_movl_env_T0(offsetof(CPUSPARCState
, wstate
));
2488 case 16: // UA2005 gl
2489 gen_op_movl_env_T0(offsetof(CPUSPARCState
, gl
));
2491 case 26: // UA2005 strand status
2492 if (!hypervisor(dc
))
2494 gen_op_movl_env_T0(offsetof(CPUSPARCState
, ssr
));
2504 case 0x33: /* wrtbr, UA2005 wrhpr */
2506 #ifndef TARGET_SPARC64
2507 if (!supervisor(dc
))
2510 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, tbr
));
2512 if (!hypervisor(dc
))
2517 // XXX gen_op_wrhpstate();
2525 // XXX gen_op_wrhtstate();
2528 gen_op_movl_env_T0(offsetof(CPUSPARCState
, hintp
));
2531 gen_op_movl_env_T0(offsetof(CPUSPARCState
, htba
));
2533 case 31: // hstick_cmpr
2534 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, hstick_cmpr
));
2535 gen_op_wrhstick_cmpr();
2537 case 6: // hver readonly
2545 #ifdef TARGET_SPARC64
2546 case 0x2c: /* V9 movcc */
2548 int cc
= GET_FIELD_SP(insn
, 11, 12);
2549 int cond
= GET_FIELD_SP(insn
, 14, 17);
2550 if (IS_IMM
) { /* immediate */
2551 rs2
= GET_FIELD_SPs(insn
, 0, 10);
2552 gen_movl_simm_T1(rs2
);
2555 rs2
= GET_FIELD_SP(insn
, 0, 4);
2556 gen_movl_reg_T1(rs2
);
2558 gen_movl_reg_T0(rd
);
2560 if (insn
& (1 << 18)) {
2562 gen_cond
[0][cond
]();
2564 gen_cond
[1][cond
]();
2568 gen_fcond
[cc
][cond
]();
2571 gen_movl_T0_reg(rd
);
2574 case 0x2d: /* V9 sdivx */
2575 gen_op_sdivx_T1_T0();
2576 gen_movl_T0_reg(rd
);
2578 case 0x2e: /* V9 popc */
2580 if (IS_IMM
) { /* immediate */
2581 rs2
= GET_FIELD_SPs(insn
, 0, 12);
2582 gen_movl_simm_T1(rs2
);
2583 // XXX optimize: popc(constant)
2586 rs2
= GET_FIELD_SP(insn
, 0, 4);
2587 gen_movl_reg_T1(rs2
);
2590 gen_movl_T0_reg(rd
);
2592 case 0x2f: /* V9 movr */
2594 int cond
= GET_FIELD_SP(insn
, 10, 12);
2595 rs1
= GET_FIELD(insn
, 13, 17);
2597 gen_movl_reg_T0(rs1
);
2599 if (IS_IMM
) { /* immediate */
2600 rs2
= GET_FIELD_SPs(insn
, 0, 9);
2601 gen_movl_simm_T1(rs2
);
2604 rs2
= GET_FIELD_SP(insn
, 0, 4);
2605 gen_movl_reg_T1(rs2
);
2607 gen_movl_reg_T0(rd
);
2609 gen_movl_T0_reg(rd
);
2617 } else if (xop
== 0x36) { /* UltraSparc shutdown, VIS, V8 CPop1 */
2618 #ifdef TARGET_SPARC64
2619 int opf
= GET_FIELD_SP(insn
, 5, 13);
2620 rs1
= GET_FIELD(insn
, 13, 17);
2621 rs2
= GET_FIELD(insn
, 27, 31);
2622 if (gen_trap_ifnofpu(dc
))
2626 case 0x000: /* VIS I edge8cc */
2627 case 0x001: /* VIS II edge8n */
2628 case 0x002: /* VIS I edge8lcc */
2629 case 0x003: /* VIS II edge8ln */
2630 case 0x004: /* VIS I edge16cc */
2631 case 0x005: /* VIS II edge16n */
2632 case 0x006: /* VIS I edge16lcc */
2633 case 0x007: /* VIS II edge16ln */
2634 case 0x008: /* VIS I edge32cc */
2635 case 0x009: /* VIS II edge32n */
2636 case 0x00a: /* VIS I edge32lcc */
2637 case 0x00b: /* VIS II edge32ln */
2640 case 0x010: /* VIS I array8 */
2641 gen_movl_reg_T0(rs1
);
2642 gen_movl_reg_T1(rs2
);
2644 gen_movl_T0_reg(rd
);
2646 case 0x012: /* VIS I array16 */
2647 gen_movl_reg_T0(rs1
);
2648 gen_movl_reg_T1(rs2
);
2650 gen_movl_T0_reg(rd
);
2652 case 0x014: /* VIS I array32 */
2653 gen_movl_reg_T0(rs1
);
2654 gen_movl_reg_T1(rs2
);
2656 gen_movl_T0_reg(rd
);
2658 case 0x018: /* VIS I alignaddr */
2659 gen_movl_reg_T0(rs1
);
2660 gen_movl_reg_T1(rs2
);
2662 gen_movl_T0_reg(rd
);
2664 case 0x019: /* VIS II bmask */
2665 case 0x01a: /* VIS I alignaddrl */
2668 case 0x020: /* VIS I fcmple16 */
2669 gen_op_load_fpr_DT0(DFPREG(rs1
));
2670 gen_op_load_fpr_DT1(DFPREG(rs2
));
2672 gen_op_store_DT0_fpr(DFPREG(rd
));
2674 case 0x022: /* VIS I fcmpne16 */
2675 gen_op_load_fpr_DT0(DFPREG(rs1
));
2676 gen_op_load_fpr_DT1(DFPREG(rs2
));
2678 gen_op_store_DT0_fpr(DFPREG(rd
));
2680 case 0x024: /* VIS I fcmple32 */
2681 gen_op_load_fpr_DT0(DFPREG(rs1
));
2682 gen_op_load_fpr_DT1(DFPREG(rs2
));
2684 gen_op_store_DT0_fpr(DFPREG(rd
));
2686 case 0x026: /* VIS I fcmpne32 */
2687 gen_op_load_fpr_DT0(DFPREG(rs1
));
2688 gen_op_load_fpr_DT1(DFPREG(rs2
));
2690 gen_op_store_DT0_fpr(DFPREG(rd
));
2692 case 0x028: /* VIS I fcmpgt16 */
2693 gen_op_load_fpr_DT0(DFPREG(rs1
));
2694 gen_op_load_fpr_DT1(DFPREG(rs2
));
2696 gen_op_store_DT0_fpr(DFPREG(rd
));
2698 case 0x02a: /* VIS I fcmpeq16 */
2699 gen_op_load_fpr_DT0(DFPREG(rs1
));
2700 gen_op_load_fpr_DT1(DFPREG(rs2
));
2702 gen_op_store_DT0_fpr(DFPREG(rd
));
2704 case 0x02c: /* VIS I fcmpgt32 */
2705 gen_op_load_fpr_DT0(DFPREG(rs1
));
2706 gen_op_load_fpr_DT1(DFPREG(rs2
));
2708 gen_op_store_DT0_fpr(DFPREG(rd
));
2710 case 0x02e: /* VIS I fcmpeq32 */
2711 gen_op_load_fpr_DT0(DFPREG(rs1
));
2712 gen_op_load_fpr_DT1(DFPREG(rs2
));
2714 gen_op_store_DT0_fpr(DFPREG(rd
));
2716 case 0x031: /* VIS I fmul8x16 */
2717 gen_op_load_fpr_DT0(DFPREG(rs1
));
2718 gen_op_load_fpr_DT1(DFPREG(rs2
));
2720 gen_op_store_DT0_fpr(DFPREG(rd
));
2722 case 0x033: /* VIS I fmul8x16au */
2723 gen_op_load_fpr_DT0(DFPREG(rs1
));
2724 gen_op_load_fpr_DT1(DFPREG(rs2
));
2725 gen_op_fmul8x16au();
2726 gen_op_store_DT0_fpr(DFPREG(rd
));
2728 case 0x035: /* VIS I fmul8x16al */
2729 gen_op_load_fpr_DT0(DFPREG(rs1
));
2730 gen_op_load_fpr_DT1(DFPREG(rs2
));
2731 gen_op_fmul8x16al();
2732 gen_op_store_DT0_fpr(DFPREG(rd
));
2734 case 0x036: /* VIS I fmul8sux16 */
2735 gen_op_load_fpr_DT0(DFPREG(rs1
));
2736 gen_op_load_fpr_DT1(DFPREG(rs2
));
2737 gen_op_fmul8sux16();
2738 gen_op_store_DT0_fpr(DFPREG(rd
));
2740 case 0x037: /* VIS I fmul8ulx16 */
2741 gen_op_load_fpr_DT0(DFPREG(rs1
));
2742 gen_op_load_fpr_DT1(DFPREG(rs2
));
2743 gen_op_fmul8ulx16();
2744 gen_op_store_DT0_fpr(DFPREG(rd
));
2746 case 0x038: /* VIS I fmuld8sux16 */
2747 gen_op_load_fpr_DT0(DFPREG(rs1
));
2748 gen_op_load_fpr_DT1(DFPREG(rs2
));
2749 gen_op_fmuld8sux16();
2750 gen_op_store_DT0_fpr(DFPREG(rd
));
2752 case 0x039: /* VIS I fmuld8ulx16 */
2753 gen_op_load_fpr_DT0(DFPREG(rs1
));
2754 gen_op_load_fpr_DT1(DFPREG(rs2
));
2755 gen_op_fmuld8ulx16();
2756 gen_op_store_DT0_fpr(DFPREG(rd
));
2758 case 0x03a: /* VIS I fpack32 */
2759 case 0x03b: /* VIS I fpack16 */
2760 case 0x03d: /* VIS I fpackfix */
2761 case 0x03e: /* VIS I pdist */
2764 case 0x048: /* VIS I faligndata */
2765 gen_op_load_fpr_DT0(DFPREG(rs1
));
2766 gen_op_load_fpr_DT1(DFPREG(rs2
));
2767 gen_op_faligndata();
2768 gen_op_store_DT0_fpr(DFPREG(rd
));
2770 case 0x04b: /* VIS I fpmerge */
2771 gen_op_load_fpr_DT0(DFPREG(rs1
));
2772 gen_op_load_fpr_DT1(DFPREG(rs2
));
2774 gen_op_store_DT0_fpr(DFPREG(rd
));
2776 case 0x04c: /* VIS II bshuffle */
2779 case 0x04d: /* VIS I fexpand */
2780 gen_op_load_fpr_DT0(DFPREG(rs1
));
2781 gen_op_load_fpr_DT1(DFPREG(rs2
));
2783 gen_op_store_DT0_fpr(DFPREG(rd
));
2785 case 0x050: /* VIS I fpadd16 */
2786 gen_op_load_fpr_DT0(DFPREG(rs1
));
2787 gen_op_load_fpr_DT1(DFPREG(rs2
));
2789 gen_op_store_DT0_fpr(DFPREG(rd
));
2791 case 0x051: /* VIS I fpadd16s */
2792 gen_op_load_fpr_FT0(rs1
);
2793 gen_op_load_fpr_FT1(rs2
);
2795 gen_op_store_FT0_fpr(rd
);
2797 case 0x052: /* VIS I fpadd32 */
2798 gen_op_load_fpr_DT0(DFPREG(rs1
));
2799 gen_op_load_fpr_DT1(DFPREG(rs2
));
2801 gen_op_store_DT0_fpr(DFPREG(rd
));
2803 case 0x053: /* VIS I fpadd32s */
2804 gen_op_load_fpr_FT0(rs1
);
2805 gen_op_load_fpr_FT1(rs2
);
2807 gen_op_store_FT0_fpr(rd
);
2809 case 0x054: /* VIS I fpsub16 */
2810 gen_op_load_fpr_DT0(DFPREG(rs1
));
2811 gen_op_load_fpr_DT1(DFPREG(rs2
));
2813 gen_op_store_DT0_fpr(DFPREG(rd
));
2815 case 0x055: /* VIS I fpsub16s */
2816 gen_op_load_fpr_FT0(rs1
);
2817 gen_op_load_fpr_FT1(rs2
);
2819 gen_op_store_FT0_fpr(rd
);
2821 case 0x056: /* VIS I fpsub32 */
2822 gen_op_load_fpr_DT0(DFPREG(rs1
));
2823 gen_op_load_fpr_DT1(DFPREG(rs2
));
2825 gen_op_store_DT0_fpr(DFPREG(rd
));
2827 case 0x057: /* VIS I fpsub32s */
2828 gen_op_load_fpr_FT0(rs1
);
2829 gen_op_load_fpr_FT1(rs2
);
2831 gen_op_store_FT0_fpr(rd
);
2833 case 0x060: /* VIS I fzero */
2834 gen_op_movl_DT0_0();
2835 gen_op_store_DT0_fpr(DFPREG(rd
));
2837 case 0x061: /* VIS I fzeros */
2838 gen_op_movl_FT0_0();
2839 gen_op_store_FT0_fpr(rd
);
2841 case 0x062: /* VIS I fnor */
2842 gen_op_load_fpr_DT0(DFPREG(rs1
));
2843 gen_op_load_fpr_DT1(DFPREG(rs2
));
2845 gen_op_store_DT0_fpr(DFPREG(rd
));
2847 case 0x063: /* VIS I fnors */
2848 gen_op_load_fpr_FT0(rs1
);
2849 gen_op_load_fpr_FT1(rs2
);
2851 gen_op_store_FT0_fpr(rd
);
2853 case 0x064: /* VIS I fandnot2 */
2854 gen_op_load_fpr_DT1(DFPREG(rs1
));
2855 gen_op_load_fpr_DT0(DFPREG(rs2
));
2857 gen_op_store_DT0_fpr(DFPREG(rd
));
2859 case 0x065: /* VIS I fandnot2s */
2860 gen_op_load_fpr_FT1(rs1
);
2861 gen_op_load_fpr_FT0(rs2
);
2863 gen_op_store_FT0_fpr(rd
);
2865 case 0x066: /* VIS I fnot2 */
2866 gen_op_load_fpr_DT1(DFPREG(rs2
));
2868 gen_op_store_DT0_fpr(DFPREG(rd
));
2870 case 0x067: /* VIS I fnot2s */
2871 gen_op_load_fpr_FT1(rs2
);
2873 gen_op_store_FT0_fpr(rd
);
2875 case 0x068: /* VIS I fandnot1 */
2876 gen_op_load_fpr_DT0(DFPREG(rs1
));
2877 gen_op_load_fpr_DT1(DFPREG(rs2
));
2879 gen_op_store_DT0_fpr(DFPREG(rd
));
2881 case 0x069: /* VIS I fandnot1s */
2882 gen_op_load_fpr_FT0(rs1
);
2883 gen_op_load_fpr_FT1(rs2
);
2885 gen_op_store_FT0_fpr(rd
);
2887 case 0x06a: /* VIS I fnot1 */
2888 gen_op_load_fpr_DT1(DFPREG(rs1
));
2890 gen_op_store_DT0_fpr(DFPREG(rd
));
2892 case 0x06b: /* VIS I fnot1s */
2893 gen_op_load_fpr_FT1(rs1
);
2895 gen_op_store_FT0_fpr(rd
);
2897 case 0x06c: /* VIS I fxor */
2898 gen_op_load_fpr_DT0(DFPREG(rs1
));
2899 gen_op_load_fpr_DT1(DFPREG(rs2
));
2901 gen_op_store_DT0_fpr(DFPREG(rd
));
2903 case 0x06d: /* VIS I fxors */
2904 gen_op_load_fpr_FT0(rs1
);
2905 gen_op_load_fpr_FT1(rs2
);
2907 gen_op_store_FT0_fpr(rd
);
2909 case 0x06e: /* VIS I fnand */
2910 gen_op_load_fpr_DT0(DFPREG(rs1
));
2911 gen_op_load_fpr_DT1(DFPREG(rs2
));
2913 gen_op_store_DT0_fpr(DFPREG(rd
));
2915 case 0x06f: /* VIS I fnands */
2916 gen_op_load_fpr_FT0(rs1
);
2917 gen_op_load_fpr_FT1(rs2
);
2919 gen_op_store_FT0_fpr(rd
);
2921 case 0x070: /* VIS I fand */
2922 gen_op_load_fpr_DT0(DFPREG(rs1
));
2923 gen_op_load_fpr_DT1(DFPREG(rs2
));
2925 gen_op_store_DT0_fpr(DFPREG(rd
));
2927 case 0x071: /* VIS I fands */
2928 gen_op_load_fpr_FT0(rs1
);
2929 gen_op_load_fpr_FT1(rs2
);
2931 gen_op_store_FT0_fpr(rd
);
2933 case 0x072: /* VIS I fxnor */
2934 gen_op_load_fpr_DT0(DFPREG(rs1
));
2935 gen_op_load_fpr_DT1(DFPREG(rs2
));
2937 gen_op_store_DT0_fpr(DFPREG(rd
));
2939 case 0x073: /* VIS I fxnors */
2940 gen_op_load_fpr_FT0(rs1
);
2941 gen_op_load_fpr_FT1(rs2
);
2943 gen_op_store_FT0_fpr(rd
);
2945 case 0x074: /* VIS I fsrc1 */
2946 gen_op_load_fpr_DT0(DFPREG(rs1
));
2947 gen_op_store_DT0_fpr(DFPREG(rd
));
2949 case 0x075: /* VIS I fsrc1s */
2950 gen_op_load_fpr_FT0(rs1
);
2951 gen_op_store_FT0_fpr(rd
);
2953 case 0x076: /* VIS I fornot2 */
2954 gen_op_load_fpr_DT1(DFPREG(rs1
));
2955 gen_op_load_fpr_DT0(DFPREG(rs2
));
2957 gen_op_store_DT0_fpr(DFPREG(rd
));
2959 case 0x077: /* VIS I fornot2s */
2960 gen_op_load_fpr_FT1(rs1
);
2961 gen_op_load_fpr_FT0(rs2
);
2963 gen_op_store_FT0_fpr(rd
);
2965 case 0x078: /* VIS I fsrc2 */
2966 gen_op_load_fpr_DT0(DFPREG(rs2
));
2967 gen_op_store_DT0_fpr(DFPREG(rd
));
2969 case 0x079: /* VIS I fsrc2s */
2970 gen_op_load_fpr_FT0(rs2
);
2971 gen_op_store_FT0_fpr(rd
);
2973 case 0x07a: /* VIS I fornot1 */
2974 gen_op_load_fpr_DT0(DFPREG(rs1
));
2975 gen_op_load_fpr_DT1(DFPREG(rs2
));
2977 gen_op_store_DT0_fpr(DFPREG(rd
));
2979 case 0x07b: /* VIS I fornot1s */
2980 gen_op_load_fpr_FT0(rs1
);
2981 gen_op_load_fpr_FT1(rs2
);
2983 gen_op_store_FT0_fpr(rd
);
2985 case 0x07c: /* VIS I for */
2986 gen_op_load_fpr_DT0(DFPREG(rs1
));
2987 gen_op_load_fpr_DT1(DFPREG(rs2
));
2989 gen_op_store_DT0_fpr(DFPREG(rd
));
2991 case 0x07d: /* VIS I fors */
2992 gen_op_load_fpr_FT0(rs1
);
2993 gen_op_load_fpr_FT1(rs2
);
2995 gen_op_store_FT0_fpr(rd
);
2997 case 0x07e: /* VIS I fone */
2998 gen_op_movl_DT0_1();
2999 gen_op_store_DT0_fpr(DFPREG(rd
));
3001 case 0x07f: /* VIS I fones */
3002 gen_op_movl_FT0_1();
3003 gen_op_store_FT0_fpr(rd
);
3005 case 0x080: /* VIS I shutdown */
3006 case 0x081: /* VIS II siam */
3015 } else if (xop
== 0x37) { /* V8 CPop2, V9 impdep2 */
3016 #ifdef TARGET_SPARC64
3021 #ifdef TARGET_SPARC64
3022 } else if (xop
== 0x39) { /* V9 return */
3023 rs1
= GET_FIELD(insn
, 13, 17);
3025 gen_movl_reg_T0(rs1
);
3026 if (IS_IMM
) { /* immediate */
3027 rs2
= GET_FIELDs(insn
, 19, 31);
3031 gen_movl_simm_T1(rs2
);
3036 } else { /* register */
3037 rs2
= GET_FIELD(insn
, 27, 31);
3041 gen_movl_reg_T1(rs2
);
3049 gen_op_check_align_T0_3();
3050 gen_op_movl_npc_T0();
3051 dc
->npc
= DYNAMIC_PC
;
3055 rs1
= GET_FIELD(insn
, 13, 17);
3056 gen_movl_reg_T0(rs1
);
3057 if (IS_IMM
) { /* immediate */
3058 rs2
= GET_FIELDs(insn
, 19, 31);
3062 gen_movl_simm_T1(rs2
);
3067 } else { /* register */
3068 rs2
= GET_FIELD(insn
, 27, 31);
3072 gen_movl_reg_T1(rs2
);
3079 case 0x38: /* jmpl */
3082 #ifdef TARGET_SPARC64
3083 if (dc
->pc
== (uint32_t)dc
->pc
) {
3084 gen_op_movl_T1_im(dc
->pc
);
3086 gen_op_movq_T1_im64(dc
->pc
>> 32, dc
->pc
);
3089 gen_op_movl_T1_im(dc
->pc
);
3091 gen_movl_T1_reg(rd
);
3094 gen_op_check_align_T0_3();
3095 gen_op_movl_npc_T0();
3096 dc
->npc
= DYNAMIC_PC
;
3099 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
3100 case 0x39: /* rett, V9 return */
3102 if (!supervisor(dc
))
3105 gen_op_check_align_T0_3();
3106 gen_op_movl_npc_T0();
3107 dc
->npc
= DYNAMIC_PC
;
3112 case 0x3b: /* flush */
3115 case 0x3c: /* save */
3118 gen_movl_T0_reg(rd
);
3120 case 0x3d: /* restore */
3123 gen_movl_T0_reg(rd
);
3125 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
3126 case 0x3e: /* V9 done/retry */
3130 if (!supervisor(dc
))
3132 dc
->npc
= DYNAMIC_PC
;
3133 dc
->pc
= DYNAMIC_PC
;
3137 if (!supervisor(dc
))
3139 dc
->npc
= DYNAMIC_PC
;
3140 dc
->pc
= DYNAMIC_PC
;
3156 case 3: /* load/store instructions */
3158 unsigned int xop
= GET_FIELD(insn
, 7, 12);
3159 rs1
= GET_FIELD(insn
, 13, 17);
3161 gen_movl_reg_T0(rs1
);
3162 if (xop
== 0x3c || xop
== 0x3e)
3164 rs2
= GET_FIELD(insn
, 27, 31);
3165 gen_movl_reg_T1(rs2
);
3167 else if (IS_IMM
) { /* immediate */
3168 rs2
= GET_FIELDs(insn
, 19, 31);
3172 gen_movl_simm_T1(rs2
);
3177 } else { /* register */
3178 rs2
= GET_FIELD(insn
, 27, 31);
3182 gen_movl_reg_T1(rs2
);
3188 if (xop
< 4 || (xop
> 7 && xop
< 0x14 && xop
!= 0x0e) ||
3189 (xop
> 0x17 && xop
<= 0x1d ) ||
3190 (xop
> 0x2c && xop
<= 0x33) || xop
== 0x1f || xop
== 0x3d) {
3192 case 0x0: /* load word */
3193 gen_op_check_align_T0_3();
3194 #ifndef TARGET_SPARC64
3200 case 0x1: /* load unsigned byte */
3203 case 0x2: /* load unsigned halfword */
3204 gen_op_check_align_T0_1();
3207 case 0x3: /* load double word */
3210 gen_op_check_align_T0_7();
3212 gen_movl_T0_reg(rd
+ 1);
3214 case 0x9: /* load signed byte */
3217 case 0xa: /* load signed halfword */
3218 gen_op_check_align_T0_1();
3221 case 0xd: /* ldstub -- XXX: should be atomically */
3222 gen_op_ldst(ldstub
);
3224 case 0x0f: /* swap register with memory. Also atomically */
3225 gen_op_check_align_T0_3();
3226 gen_movl_reg_T1(rd
);
3229 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
3230 case 0x10: /* load word alternate */
3231 #ifndef TARGET_SPARC64
3234 if (!supervisor(dc
))
3237 gen_op_check_align_T0_3();
3238 gen_ld_asi(insn
, 4, 0);
3240 case 0x11: /* load unsigned byte alternate */
3241 #ifndef TARGET_SPARC64
3244 if (!supervisor(dc
))
3247 gen_ld_asi(insn
, 1, 0);
3249 case 0x12: /* load unsigned halfword alternate */
3250 #ifndef TARGET_SPARC64
3253 if (!supervisor(dc
))
3256 gen_op_check_align_T0_1();
3257 gen_ld_asi(insn
, 2, 0);
3259 case 0x13: /* load double word alternate */
3260 #ifndef TARGET_SPARC64
3263 if (!supervisor(dc
))
3268 gen_op_check_align_T0_7();
3270 gen_movl_T0_reg(rd
+ 1);
3272 case 0x19: /* load signed byte alternate */
3273 #ifndef TARGET_SPARC64
3276 if (!supervisor(dc
))
3279 gen_ld_asi(insn
, 1, 1);
3281 case 0x1a: /* load signed halfword alternate */
3282 #ifndef TARGET_SPARC64
3285 if (!supervisor(dc
))
3288 gen_op_check_align_T0_1();
3289 gen_ld_asi(insn
, 2, 1);
3291 case 0x1d: /* ldstuba -- XXX: should be atomically */
3292 #ifndef TARGET_SPARC64
3295 if (!supervisor(dc
))
3298 gen_ldstub_asi(insn
);
3300 case 0x1f: /* swap reg with alt. memory. Also atomically */
3301 #ifndef TARGET_SPARC64
3304 if (!supervisor(dc
))
3307 gen_op_check_align_T0_3();
3308 gen_movl_reg_T1(rd
);
3312 #ifndef TARGET_SPARC64
3313 case 0x30: /* ldc */
3314 case 0x31: /* ldcsr */
3315 case 0x33: /* lddc */
3319 #ifdef TARGET_SPARC64
3320 case 0x08: /* V9 ldsw */
3321 gen_op_check_align_T0_3();
3324 case 0x0b: /* V9 ldx */
3325 gen_op_check_align_T0_7();
3328 case 0x18: /* V9 ldswa */
3329 gen_op_check_align_T0_3();
3330 gen_ld_asi(insn
, 4, 1);
3332 case 0x1b: /* V9 ldxa */
3333 gen_op_check_align_T0_7();
3334 gen_ld_asi(insn
, 8, 0);
3336 case 0x2d: /* V9 prefetch, no effect */
3338 case 0x30: /* V9 ldfa */
3339 gen_op_check_align_T0_3();
3340 gen_ldf_asi(insn
, 4, rd
);
3342 case 0x33: /* V9 lddfa */
3343 gen_op_check_align_T0_3();
3344 gen_ldf_asi(insn
, 8, DFPREG(rd
));
3346 case 0x3d: /* V9 prefetcha, no effect */
3348 case 0x32: /* V9 ldqfa */
3349 #if defined(CONFIG_USER_ONLY)
3350 gen_op_check_align_T0_3();
3351 gen_ldf_asi(insn
, 16, QFPREG(rd
));
3360 gen_movl_T1_reg(rd
);
3361 #ifdef TARGET_SPARC64
3364 } else if (xop
>= 0x20 && xop
< 0x24) {
3365 if (gen_trap_ifnofpu(dc
))
3368 case 0x20: /* load fpreg */
3369 gen_op_check_align_T0_3();
3371 gen_op_store_FT0_fpr(rd
);
3373 case 0x21: /* load fsr */
3374 gen_op_check_align_T0_3();
3378 case 0x22: /* load quad fpreg */
3379 #if defined(CONFIG_USER_ONLY)
3380 gen_op_check_align_T0_7();
3382 gen_op_store_QT0_fpr(QFPREG(rd
));
3387 case 0x23: /* load double fpreg */
3388 gen_op_check_align_T0_7();
3390 gen_op_store_DT0_fpr(DFPREG(rd
));
3395 } else if (xop
< 8 || (xop
>= 0x14 && xop
< 0x18) || \
3396 xop
== 0xe || xop
== 0x1e) {
3397 gen_movl_reg_T1(rd
);
3400 gen_op_check_align_T0_3();
3407 gen_op_check_align_T0_1();
3413 gen_op_check_align_T0_7();
3415 gen_movl_reg_T2(rd
+ 1);
3418 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
3420 #ifndef TARGET_SPARC64
3423 if (!supervisor(dc
))
3426 gen_op_check_align_T0_3();
3427 gen_st_asi(insn
, 4);
3430 #ifndef TARGET_SPARC64
3433 if (!supervisor(dc
))
3436 gen_st_asi(insn
, 1);
3439 #ifndef TARGET_SPARC64
3442 if (!supervisor(dc
))
3445 gen_op_check_align_T0_1();
3446 gen_st_asi(insn
, 2);
3449 #ifndef TARGET_SPARC64
3452 if (!supervisor(dc
))
3457 gen_op_check_align_T0_7();
3459 gen_movl_reg_T2(rd
+ 1);
3463 #ifdef TARGET_SPARC64
3464 case 0x0e: /* V9 stx */
3465 gen_op_check_align_T0_7();
3468 case 0x1e: /* V9 stxa */
3469 gen_op_check_align_T0_7();
3470 gen_st_asi(insn
, 8);
3476 } else if (xop
> 0x23 && xop
< 0x28) {
3477 if (gen_trap_ifnofpu(dc
))
3481 gen_op_check_align_T0_3();
3482 gen_op_load_fpr_FT0(rd
);
3485 case 0x25: /* stfsr, V9 stxfsr */
3486 #ifdef CONFIG_USER_ONLY
3487 gen_op_check_align_T0_3();
3493 #ifdef TARGET_SPARC64
3494 #if defined(CONFIG_USER_ONLY)
3495 /* V9 stqf, store quad fpreg */
3496 gen_op_check_align_T0_7();
3497 gen_op_load_fpr_QT0(QFPREG(rd
));
3503 #else /* !TARGET_SPARC64 */
3504 /* stdfq, store floating point queue */
3505 #if defined(CONFIG_USER_ONLY)
3508 if (!supervisor(dc
))
3510 if (gen_trap_ifnofpu(dc
))
3516 gen_op_check_align_T0_7();
3517 gen_op_load_fpr_DT0(DFPREG(rd
));
3523 } else if (xop
> 0x33 && xop
< 0x3f) {
3525 #ifdef TARGET_SPARC64
3526 case 0x34: /* V9 stfa */
3527 gen_op_check_align_T0_3();
3528 gen_op_load_fpr_FT0(rd
);
3529 gen_stf_asi(insn
, 4, rd
);
3531 case 0x36: /* V9 stqfa */
3532 #if defined(CONFIG_USER_ONLY)
3533 gen_op_check_align_T0_7();
3534 gen_op_load_fpr_QT0(QFPREG(rd
));
3535 gen_stf_asi(insn
, 16, QFPREG(rd
));
3540 case 0x37: /* V9 stdfa */
3541 gen_op_check_align_T0_3();
3542 gen_op_load_fpr_DT0(DFPREG(rd
));
3543 gen_stf_asi(insn
, 8, DFPREG(rd
));
3545 case 0x3c: /* V9 casa */
3546 gen_op_check_align_T0_3();
3548 gen_movl_reg_T2(rd
);
3550 gen_movl_T1_reg(rd
);
3552 case 0x3e: /* V9 casxa */
3553 gen_op_check_align_T0_7();
3555 gen_movl_reg_T2(rd
);
3557 gen_movl_T1_reg(rd
);
3560 case 0x34: /* stc */
3561 case 0x35: /* stcsr */
3562 case 0x36: /* stdcq */
3563 case 0x37: /* stdc */
3575 /* default case for non jump instructions */
3576 if (dc
->npc
== DYNAMIC_PC
) {
3577 dc
->pc
= DYNAMIC_PC
;
3579 } else if (dc
->npc
== JUMP_PC
) {
3580 /* we can do a static jump */
3581 gen_branch2(dc
, dc
->jump_pc
[0], dc
->jump_pc
[1]);
3585 dc
->npc
= dc
->npc
+ 4;
3591 gen_op_exception(TT_ILL_INSN
);
3594 #if !defined(CONFIG_USER_ONLY)
3597 gen_op_exception(TT_PRIV_INSN
);
3602 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP
);
3605 #ifndef TARGET_SPARC64
3608 gen_op_fpexception_im(FSR_FTT_SEQ_ERROR
);
3613 #ifndef TARGET_SPARC64
3616 gen_op_exception(TT_NCP_INSN
);
3622 static inline int gen_intermediate_code_internal(TranslationBlock
* tb
,
3623 int spc
, CPUSPARCState
*env
)
3625 target_ulong pc_start
, last_pc
;
3626 uint16_t *gen_opc_end
;
3627 DisasContext dc1
, *dc
= &dc1
;
3630 memset(dc
, 0, sizeof(DisasContext
));
3635 dc
->npc
= (target_ulong
) tb
->cs_base
;
3636 dc
->mem_idx
= cpu_mmu_index(env
);
3637 dc
->fpu_enabled
= cpu_fpu_enabled(env
);
3638 gen_opc_ptr
= gen_opc_buf
;
3639 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
3640 gen_opparam_ptr
= gen_opparam_buf
;
3644 if (env
->nb_breakpoints
> 0) {
3645 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
3646 if (env
->breakpoints
[j
] == dc
->pc
) {
3647 if (dc
->pc
!= pc_start
)
3659 fprintf(logfile
, "Search PC...\n");
3660 j
= gen_opc_ptr
- gen_opc_buf
;
3664 gen_opc_instr_start
[lj
++] = 0;
3665 gen_opc_pc
[lj
] = dc
->pc
;
3666 gen_opc_npc
[lj
] = dc
->npc
;
3667 gen_opc_instr_start
[lj
] = 1;
3671 disas_sparc_insn(dc
);
3675 /* if the next PC is different, we abort now */
3676 if (dc
->pc
!= (last_pc
+ 4))
3678 /* if we reach a page boundary, we stop generation so that the
3679 PC of a TT_TFAULT exception is always in the right page */
3680 if ((dc
->pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
3682 /* if single step mode, we generate only one instruction and
3683 generate an exception */
3684 if (env
->singlestep_enabled
) {
3690 } while ((gen_opc_ptr
< gen_opc_end
) &&
3691 (dc
->pc
- pc_start
) < (TARGET_PAGE_SIZE
- 32));
3695 if (dc
->pc
!= DYNAMIC_PC
&&
3696 (dc
->npc
!= DYNAMIC_PC
&& dc
->npc
!= JUMP_PC
)) {
3697 /* static PC and NPC: we can use direct chaining */
3698 gen_branch(dc
, dc
->pc
, dc
->npc
);
3700 if (dc
->pc
!= DYNAMIC_PC
)
3707 *gen_opc_ptr
= INDEX_op_end
;
3709 j
= gen_opc_ptr
- gen_opc_buf
;
3712 gen_opc_instr_start
[lj
++] = 0;
3718 gen_opc_jump_pc
[0] = dc
->jump_pc
[0];
3719 gen_opc_jump_pc
[1] = dc
->jump_pc
[1];
3721 tb
->size
= last_pc
+ 4 - pc_start
;
3724 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3725 fprintf(logfile
, "--------------\n");
3726 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
3727 target_disas(logfile
, pc_start
, last_pc
+ 4 - pc_start
, 0);
3728 fprintf(logfile
, "\n");
3729 if (loglevel
& CPU_LOG_TB_OP
) {
3730 fprintf(logfile
, "OP:\n");
3731 dump_ops(gen_opc_buf
, gen_opparam_buf
);
3732 fprintf(logfile
, "\n");
3739 int gen_intermediate_code(CPUSPARCState
* env
, TranslationBlock
* tb
)
3741 return gen_intermediate_code_internal(tb
, 0, env
);
3744 int gen_intermediate_code_pc(CPUSPARCState
* env
, TranslationBlock
* tb
)
3746 return gen_intermediate_code_internal(tb
, 1, env
);
3749 extern int ram_size
;
3751 void cpu_reset(CPUSPARCState
*env
)
3756 env
->regwptr
= env
->regbase
+ (env
->cwp
* 16);
3757 #if defined(CONFIG_USER_ONLY)
3758 env
->user_mode_only
= 1;
3759 #ifdef TARGET_SPARC64
3760 env
->cleanwin
= NWINDOWS
- 2;
3761 env
->cansave
= NWINDOWS
- 2;
3762 env
->pstate
= PS_RMO
| PS_PEF
| PS_IE
;
3763 env
->asi
= 0x82; // Primary no-fault
3769 #ifdef TARGET_SPARC64
3770 env
->pstate
= PS_PRIV
;
3771 env
->hpstate
= HS_PRIV
;
3772 env
->pc
= 0x1fff0000000ULL
;
3775 env
->mmuregs
[0] &= ~(MMU_E
| MMU_NF
);
3776 env
->mmuregs
[0] |= env
->mmu_bm
;
3778 env
->npc
= env
->pc
+ 4;
3782 CPUSPARCState
*cpu_sparc_init(const char *cpu_model
)
3785 const sparc_def_t
*def
;
3787 def
= cpu_sparc_find_by_name(cpu_model
);
3791 env
= qemu_mallocz(sizeof(CPUSPARCState
));
3795 env
->version
= def
->iu_version
;
3796 env
->fsr
= def
->fpu_version
;
3797 #if !defined(TARGET_SPARC64)
3798 env
->mmu_bm
= def
->mmu_bm
;
3799 env
->mmuregs
[0] |= def
->mmu_version
;
3800 cpu_sparc_set_id(env
, 0);
3807 void cpu_sparc_set_id(CPUSPARCState
*env
, unsigned int cpu
)
3809 #if !defined(TARGET_SPARC64)
3810 env
->mxccregs
[7] = ((cpu
+ 8) & 0xf) << 24;
3814 static const sparc_def_t sparc_defs
[] = {
3815 #ifdef TARGET_SPARC64
3817 .name
= "Fujitsu Sparc64",
3818 .iu_version
= ((0x04ULL
<< 48) | (0x02ULL
<< 32) | (0ULL << 24)
3819 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3820 .fpu_version
= 0x00000000,
3824 .name
= "Fujitsu Sparc64 III",
3825 .iu_version
= ((0x04ULL
<< 48) | (0x03ULL
<< 32) | (0ULL << 24)
3826 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3827 .fpu_version
= 0x00000000,
3831 .name
= "Fujitsu Sparc64 IV",
3832 .iu_version
= ((0x04ULL
<< 48) | (0x04ULL
<< 32) | (0ULL << 24)
3833 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3834 .fpu_version
= 0x00000000,
3838 .name
= "Fujitsu Sparc64 V",
3839 .iu_version
= ((0x04ULL
<< 48) | (0x05ULL
<< 32) | (0x51ULL
<< 24)
3840 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3841 .fpu_version
= 0x00000000,
3845 .name
= "TI UltraSparc I",
3846 .iu_version
= ((0x17ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)
3847 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3848 .fpu_version
= 0x00000000,
3852 .name
= "TI UltraSparc II",
3853 .iu_version
= ((0x17ULL
<< 48) | (0x11ULL
<< 32) | (0x20ULL
<< 24)
3854 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3855 .fpu_version
= 0x00000000,
3859 .name
= "TI UltraSparc IIi",
3860 .iu_version
= ((0x17ULL
<< 48) | (0x12ULL
<< 32) | (0x91ULL
<< 24)
3861 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3862 .fpu_version
= 0x00000000,
3866 .name
= "TI UltraSparc IIe",
3867 .iu_version
= ((0x17ULL
<< 48) | (0x13ULL
<< 32) | (0x14ULL
<< 24)
3868 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3869 .fpu_version
= 0x00000000,
3873 .name
= "Sun UltraSparc III",
3874 .iu_version
= ((0x3eULL
<< 48) | (0x14ULL
<< 32) | (0x34ULL
<< 24)
3875 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3876 .fpu_version
= 0x00000000,
3880 .name
= "Sun UltraSparc III Cu",
3881 .iu_version
= ((0x3eULL
<< 48) | (0x15ULL
<< 32) | (0x41ULL
<< 24)
3882 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3883 .fpu_version
= 0x00000000,
3887 .name
= "Sun UltraSparc IIIi",
3888 .iu_version
= ((0x3eULL
<< 48) | (0x16ULL
<< 32) | (0x34ULL
<< 24)
3889 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3890 .fpu_version
= 0x00000000,
3894 .name
= "Sun UltraSparc IV",
3895 .iu_version
= ((0x3eULL
<< 48) | (0x18ULL
<< 32) | (0x31ULL
<< 24)
3896 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3897 .fpu_version
= 0x00000000,
3901 .name
= "Sun UltraSparc IV+",
3902 .iu_version
= ((0x3eULL
<< 48) | (0x19ULL
<< 32) | (0x22ULL
<< 24)
3903 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3904 .fpu_version
= 0x00000000,
3908 .name
= "Sun UltraSparc IIIi+",
3909 .iu_version
= ((0x3eULL
<< 48) | (0x22ULL
<< 32) | (0ULL << 24)
3910 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3911 .fpu_version
= 0x00000000,
3915 .name
= "NEC UltraSparc I",
3916 .iu_version
= ((0x22ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)
3917 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
3918 .fpu_version
= 0x00000000,
3923 .name
= "Fujitsu MB86900",
3924 .iu_version
= 0x00 << 24, /* Impl 0, ver 0 */
3925 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
3926 .mmu_version
= 0x00 << 24, /* Impl 0, ver 0 */
3927 .mmu_bm
= 0x00004000,
3930 .name
= "Fujitsu MB86904",
3931 .iu_version
= 0x04 << 24, /* Impl 0, ver 4 */
3932 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
3933 .mmu_version
= 0x04 << 24, /* Impl 0, ver 4 */
3934 .mmu_bm
= 0x00004000,
3937 .name
= "Fujitsu MB86907",
3938 .iu_version
= 0x05 << 24, /* Impl 0, ver 5 */
3939 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
3940 .mmu_version
= 0x05 << 24, /* Impl 0, ver 5 */
3941 .mmu_bm
= 0x00004000,
3944 .name
= "LSI L64811",
3945 .iu_version
= 0x10 << 24, /* Impl 1, ver 0 */
3946 .fpu_version
= 1 << 17, /* FPU version 1 (LSI L64814) */
3947 .mmu_version
= 0x10 << 24,
3948 .mmu_bm
= 0x00004000,
3951 .name
= "Cypress CY7C601",
3952 .iu_version
= 0x11 << 24, /* Impl 1, ver 1 */
3953 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
3954 .mmu_version
= 0x10 << 24,
3955 .mmu_bm
= 0x00004000,
3958 .name
= "Cypress CY7C611",
3959 .iu_version
= 0x13 << 24, /* Impl 1, ver 3 */
3960 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
3961 .mmu_version
= 0x10 << 24,
3962 .mmu_bm
= 0x00004000,
3965 .name
= "TI SuperSparc II",
3966 .iu_version
= 0x40000000,
3967 .fpu_version
= 0 << 17,
3968 .mmu_version
= 0x04000000,
3969 .mmu_bm
= 0x00002000,
3972 .name
= "TI MicroSparc I",
3973 .iu_version
= 0x41000000,
3974 .fpu_version
= 4 << 17,
3975 .mmu_version
= 0x41000000,
3976 .mmu_bm
= 0x00004000,
3979 .name
= "TI MicroSparc II",
3980 .iu_version
= 0x42000000,
3981 .fpu_version
= 4 << 17,
3982 .mmu_version
= 0x02000000,
3983 .mmu_bm
= 0x00004000,
3986 .name
= "TI MicroSparc IIep",
3987 .iu_version
= 0x42000000,
3988 .fpu_version
= 4 << 17,
3989 .mmu_version
= 0x04000000,
3990 .mmu_bm
= 0x00004000,
3993 .name
= "TI SuperSparc 51",
3994 .iu_version
= 0x43000000,
3995 .fpu_version
= 0 << 17,
3996 .mmu_version
= 0x04000000,
3997 .mmu_bm
= 0x00002000,
4000 .name
= "TI SuperSparc 61",
4001 .iu_version
= 0x44000000,
4002 .fpu_version
= 0 << 17,
4003 .mmu_version
= 0x04000000,
4004 .mmu_bm
= 0x00002000,
4007 .name
= "Ross RT625",
4008 .iu_version
= 0x1e000000,
4009 .fpu_version
= 1 << 17,
4010 .mmu_version
= 0x1e000000,
4011 .mmu_bm
= 0x00004000,
4014 .name
= "Ross RT620",
4015 .iu_version
= 0x1f000000,
4016 .fpu_version
= 1 << 17,
4017 .mmu_version
= 0x1f000000,
4018 .mmu_bm
= 0x00004000,
4021 .name
= "BIT B5010",
4022 .iu_version
= 0x20000000,
4023 .fpu_version
= 0 << 17, /* B5010/B5110/B5120/B5210 */
4024 .mmu_version
= 0x20000000,
4025 .mmu_bm
= 0x00004000,
4028 .name
= "Matsushita MN10501",
4029 .iu_version
= 0x50000000,
4030 .fpu_version
= 0 << 17,
4031 .mmu_version
= 0x50000000,
4032 .mmu_bm
= 0x00004000,
4035 .name
= "Weitek W8601",
4036 .iu_version
= 0x90 << 24, /* Impl 9, ver 0 */
4037 .fpu_version
= 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
4038 .mmu_version
= 0x10 << 24,
4039 .mmu_bm
= 0x00004000,
4043 .iu_version
= 0xf2000000,
4044 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
4045 .mmu_version
= 0xf2000000,
4046 .mmu_bm
= 0x00004000,
4050 .iu_version
= 0xf3000000,
4051 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
4052 .mmu_version
= 0xf3000000,
4053 .mmu_bm
= 0x00004000,
4058 static const sparc_def_t
*cpu_sparc_find_by_name(const unsigned char *name
)
4062 for (i
= 0; i
< sizeof(sparc_defs
) / sizeof(sparc_def_t
); i
++) {
4063 if (strcasecmp(name
, sparc_defs
[i
].name
) == 0) {
4064 return &sparc_defs
[i
];
4070 void sparc_cpu_list (FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
4074 for (i
= 0; i
< sizeof(sparc_defs
) / sizeof(sparc_def_t
); i
++) {
4075 (*cpu_fprintf
)(f
, "Sparc %16s IU " TARGET_FMT_lx
" FPU %08x MMU %08x\n",
4077 sparc_defs
[i
].iu_version
,
4078 sparc_defs
[i
].fpu_version
,
4079 sparc_defs
[i
].mmu_version
);
4083 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
4085 void cpu_dump_state(CPUState
*env
, FILE *f
,
4086 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
4091 cpu_fprintf(f
, "pc: " TARGET_FMT_lx
" npc: " TARGET_FMT_lx
"\n", env
->pc
, env
->npc
);
4092 cpu_fprintf(f
, "General Registers:\n");
4093 for (i
= 0; i
< 4; i
++)
4094 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
4095 cpu_fprintf(f
, "\n");
4097 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
4098 cpu_fprintf(f
, "\nCurrent Register Window:\n");
4099 for (x
= 0; x
< 3; x
++) {
4100 for (i
= 0; i
< 4; i
++)
4101 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
4102 (x
== 0 ? 'o' : (x
== 1 ? 'l' : 'i')), i
,
4103 env
->regwptr
[i
+ x
* 8]);
4104 cpu_fprintf(f
, "\n");
4106 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
4107 (x
== 0 ? 'o' : x
== 1 ? 'l' : 'i'), i
,
4108 env
->regwptr
[i
+ x
* 8]);
4109 cpu_fprintf(f
, "\n");
4111 cpu_fprintf(f
, "\nFloating Point Registers:\n");
4112 for (i
= 0; i
< 32; i
++) {
4114 cpu_fprintf(f
, "%%f%02d:", i
);
4115 cpu_fprintf(f
, " %016lf", env
->fpr
[i
]);
4117 cpu_fprintf(f
, "\n");
4119 #ifdef TARGET_SPARC64
4120 cpu_fprintf(f
, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
4121 env
->pstate
, GET_CCR(env
), env
->asi
, env
->tl
, env
->fprs
);
4122 cpu_fprintf(f
, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
4123 env
->cansave
, env
->canrestore
, env
->otherwin
, env
->wstate
,
4124 env
->cleanwin
, NWINDOWS
- 1 - env
->cwp
);
4126 cpu_fprintf(f
, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env
),
4127 GET_FLAG(PSR_ZERO
, 'Z'), GET_FLAG(PSR_OVF
, 'V'),
4128 GET_FLAG(PSR_NEG
, 'N'), GET_FLAG(PSR_CARRY
, 'C'),
4129 env
->psrs
?'S':'-', env
->psrps
?'P':'-',
4130 env
->psret
?'E':'-', env
->wim
);
4132 cpu_fprintf(f
, "fsr: 0x%08x\n", GET_FSR32(env
));
4135 #if defined(CONFIG_USER_ONLY)
4136 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
4142 extern int get_physical_address (CPUState
*env
, target_phys_addr_t
*physical
, int *prot
,
4143 int *access_index
, target_ulong address
, int rw
,
4146 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
4148 target_phys_addr_t phys_addr
;
4149 int prot
, access_index
;
4151 if (get_physical_address(env
, &phys_addr
, &prot
, &access_index
, addr
, 2, 0) != 0)
4152 if (get_physical_address(env
, &phys_addr
, &prot
, &access_index
, addr
, 0, 0) != 0)
4154 if (cpu_get_physical_page_desc(phys_addr
) == IO_MEM_UNASSIGNED
)
4160 void helper_flush(target_ulong addr
)
4163 tb_invalidate_page_range(addr
, addr
+ 8);