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
28 Optional alignment check
45 #define DYNAMIC_PC 1 /* dynamic pc value */
46 #define JUMP_PC 2 /* dynamic pc value which takes only two values
47 according to jump_pc[T2] */
49 typedef struct DisasContext
{
50 target_ulong pc
; /* current Program Counter: integer or DYNAMIC_PC */
51 target_ulong npc
; /* next PC: integer or DYNAMIC_PC or JUMP_PC */
52 target_ulong jump_pc
[2]; /* used when JUMP_PC pc value is used */
55 struct TranslationBlock
*tb
;
58 static uint16_t *gen_opc_ptr
;
59 static uint32_t *gen_opparam_ptr
;
64 #define DEF(s,n,copy_size) INDEX_op_ ## s,
72 // This function uses non-native bit order
73 #define GET_FIELD(X, FROM, TO) \
74 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
76 // This function uses the order in the manuals, i.e. bit 0 is 2^0
77 #define GET_FIELD_SP(X, FROM, TO) \
78 GET_FIELD(X, 31 - (TO), 31 - (FROM))
80 #define GET_FIELDs(x,a,b) sign_extend (GET_FIELD(x,a,b), (b) - (a) + 1)
81 #define GET_FIELD_SPs(x,a,b) sign_extend (GET_FIELD_SP(x,a,b), 32 - ((b) - (a) + 1))
84 #define DFPREG(r) (((r & 1) << 6) | (r & 0x1e))
89 static int sign_extend(int x
, int len
)
92 return (x
<< len
) >> len
;
95 #define IS_IMM (insn & (1<<13))
97 static void disas_sparc_insn(DisasContext
* dc
);
99 static GenOpFunc
*gen_op_movl_TN_reg
[2][32] = {
170 static GenOpFunc
*gen_op_movl_reg_TN
[3][32] = {
275 static GenOpFunc1
*gen_op_movl_TN_im
[3] = {
281 // Sign extending version
282 static GenOpFunc1
* const gen_op_movl_TN_sim
[3] = {
288 #ifdef TARGET_SPARC64
289 #define GEN32(func, NAME) \
290 static GenOpFunc *NAME ## _table [64] = { \
291 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
292 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
293 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
294 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
295 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
296 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
297 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
298 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
299 NAME ## 32, 0, NAME ## 34, 0, NAME ## 36, 0, NAME ## 38, 0, \
300 NAME ## 40, 0, NAME ## 42, 0, NAME ## 44, 0, NAME ## 46, 0, \
301 NAME ## 48, 0, NAME ## 50, 0, NAME ## 52, 0, NAME ## 54, 0, \
302 NAME ## 56, 0, NAME ## 58, 0, NAME ## 60, 0, NAME ## 62, 0, \
304 static inline void func(int n) \
306 NAME ## _table[n](); \
309 #define GEN32(func, NAME) \
310 static GenOpFunc *NAME ## _table [32] = { \
311 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
312 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
313 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
314 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
315 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
316 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
317 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
318 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
320 static inline void func(int n) \
322 NAME ## _table[n](); \
326 /* floating point registers moves */
327 GEN32(gen_op_load_fpr_FT0
, gen_op_load_fpr_FT0_fprf
);
328 GEN32(gen_op_load_fpr_FT1
, gen_op_load_fpr_FT1_fprf
);
329 GEN32(gen_op_store_FT0_fpr
, gen_op_store_FT0_fpr_fprf
);
330 GEN32(gen_op_store_FT1_fpr
, gen_op_store_FT1_fpr_fprf
);
332 GEN32(gen_op_load_fpr_DT0
, gen_op_load_fpr_DT0_fprf
);
333 GEN32(gen_op_load_fpr_DT1
, gen_op_load_fpr_DT1_fprf
);
334 GEN32(gen_op_store_DT0_fpr
, gen_op_store_DT0_fpr_fprf
);
335 GEN32(gen_op_store_DT1_fpr
, gen_op_store_DT1_fpr_fprf
);
337 #ifdef TARGET_SPARC64
338 // 'a' versions allowed to user depending on asi
339 #if defined(CONFIG_USER_ONLY)
340 #define supervisor(dc) 0
341 #define gen_op_ldst(name) gen_op_##name##_raw()
342 #define OP_LD_TABLE(width) \
343 static void gen_op_##width##a(int insn, int is_ld, int size, int sign) \
348 offset = GET_FIELD(insn, 25, 31); \
350 gen_op_ld_asi_reg(offset, size, sign); \
352 gen_op_st_asi_reg(offset, size, sign); \
355 asi = GET_FIELD(insn, 19, 26); \
357 case 0x80: /* Primary address space */ \
358 gen_op_##width##_raw(); \
366 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
367 #define OP_LD_TABLE(width) \
368 static GenOpFunc *gen_op_##width[] = { \
369 &gen_op_##width##_user, \
370 &gen_op_##width##_kernel, \
373 static void gen_op_##width##a(int insn, int is_ld, int size, int sign) \
378 offset = GET_FIELD(insn, 25, 31); \
380 gen_op_ld_asi_reg(offset, size, sign); \
382 gen_op_st_asi_reg(offset, size, sign); \
385 asi = GET_FIELD(insn, 19, 26); \
387 gen_op_ld_asi(asi, size, sign); \
389 gen_op_st_asi(asi, size, sign); \
392 #define supervisor(dc) (dc->mem_idx == 1)
395 #if defined(CONFIG_USER_ONLY)
396 #define gen_op_ldst(name) gen_op_##name##_raw()
397 #define OP_LD_TABLE(width)
398 #define supervisor(dc) 0
400 #define gen_op_ldst(name) (*gen_op_##name[dc->mem_idx])()
401 #define OP_LD_TABLE(width) \
402 static GenOpFunc *gen_op_##width[] = { \
403 &gen_op_##width##_user, \
404 &gen_op_##width##_kernel, \
407 static void gen_op_##width##a(int insn, int is_ld, int size, int sign) \
411 asi = GET_FIELD(insn, 19, 26); \
413 case 10: /* User data access */ \
414 gen_op_##width##_user(); \
416 case 11: /* Supervisor data access */ \
417 gen_op_##width##_kernel(); \
419 case 0x20 ... 0x2f: /* MMU passthrough */ \
421 gen_op_ld_asi(asi, size, sign); \
423 gen_op_st_asi(asi, size, sign); \
427 gen_op_ld_asi(asi, size, sign); \
429 gen_op_st_asi(asi, size, sign); \
434 #define supervisor(dc) (dc->mem_idx == 1)
455 #ifdef TARGET_SPARC64
463 static inline void gen_movl_imm_TN(int reg
, uint32_t imm
)
465 gen_op_movl_TN_im
[reg
] (imm
);
468 static inline void gen_movl_imm_T1(uint32_t val
)
470 gen_movl_imm_TN(1, val
);
473 static inline void gen_movl_imm_T0(uint32_t val
)
475 gen_movl_imm_TN(0, val
);
478 static inline void gen_movl_simm_TN(int reg
, int32_t imm
)
480 gen_op_movl_TN_sim
[reg
](imm
);
483 static inline void gen_movl_simm_T1(int32_t val
)
485 gen_movl_simm_TN(1, val
);
488 static inline void gen_movl_simm_T0(int32_t val
)
490 gen_movl_simm_TN(0, val
);
493 static inline void gen_movl_reg_TN(int reg
, int t
)
496 gen_op_movl_reg_TN
[t
][reg
] ();
498 gen_movl_imm_TN(t
, 0);
501 static inline void gen_movl_reg_T0(int reg
)
503 gen_movl_reg_TN(reg
, 0);
506 static inline void gen_movl_reg_T1(int reg
)
508 gen_movl_reg_TN(reg
, 1);
511 static inline void gen_movl_reg_T2(int reg
)
513 gen_movl_reg_TN(reg
, 2);
516 static inline void gen_movl_TN_reg(int reg
, int t
)
519 gen_op_movl_TN_reg
[t
][reg
] ();
522 static inline void gen_movl_T0_reg(int reg
)
524 gen_movl_TN_reg(reg
, 0);
527 static inline void gen_movl_T1_reg(int reg
)
529 gen_movl_TN_reg(reg
, 1);
532 /* call this function before using T2 as it may have been set for a jump */
533 static inline void flush_T2(DisasContext
* dc
)
535 if (dc
->npc
== JUMP_PC
) {
536 gen_op_generic_branch(dc
->jump_pc
[0], dc
->jump_pc
[1]);
537 dc
->npc
= DYNAMIC_PC
;
541 static inline void gen_jmp_im(target_ulong pc
)
543 #ifdef TARGET_SPARC64
544 if (pc
== (uint32_t)pc
) {
547 gen_op_jmp_im64(pc
>> 32, pc
);
554 static inline void gen_movl_npc_im(target_ulong npc
)
556 #ifdef TARGET_SPARC64
557 if (npc
== (uint32_t)npc
) {
558 gen_op_movl_npc_im(npc
);
560 gen_op_movq_npc_im64(npc
>> 32, npc
);
563 gen_op_movl_npc_im(npc
);
567 static inline void save_npc(DisasContext
* dc
)
569 if (dc
->npc
== JUMP_PC
) {
570 gen_op_generic_branch(dc
->jump_pc
[0], dc
->jump_pc
[1]);
571 dc
->npc
= DYNAMIC_PC
;
572 } else if (dc
->npc
!= DYNAMIC_PC
) {
573 gen_movl_npc_im(dc
->npc
);
577 static inline void save_state(DisasContext
* dc
)
583 static inline void gen_mov_pc_npc(DisasContext
* dc
)
585 if (dc
->npc
== JUMP_PC
) {
586 gen_op_generic_branch(dc
->jump_pc
[0], dc
->jump_pc
[1]);
589 } else if (dc
->npc
== DYNAMIC_PC
) {
597 static GenOpFunc
* const gen_cond
[2][16] = {
617 #ifdef TARGET_SPARC64
638 static GenOpFunc
* const gen_fcond
[4][16] = {
657 #ifdef TARGET_SPARC64
660 gen_op_eval_fbne_fcc1
,
661 gen_op_eval_fblg_fcc1
,
662 gen_op_eval_fbul_fcc1
,
663 gen_op_eval_fbl_fcc1
,
664 gen_op_eval_fbug_fcc1
,
665 gen_op_eval_fbg_fcc1
,
666 gen_op_eval_fbu_fcc1
,
668 gen_op_eval_fbe_fcc1
,
669 gen_op_eval_fbue_fcc1
,
670 gen_op_eval_fbge_fcc1
,
671 gen_op_eval_fbuge_fcc1
,
672 gen_op_eval_fble_fcc1
,
673 gen_op_eval_fbule_fcc1
,
674 gen_op_eval_fbo_fcc1
,
678 gen_op_eval_fbne_fcc2
,
679 gen_op_eval_fblg_fcc2
,
680 gen_op_eval_fbul_fcc2
,
681 gen_op_eval_fbl_fcc2
,
682 gen_op_eval_fbug_fcc2
,
683 gen_op_eval_fbg_fcc2
,
684 gen_op_eval_fbu_fcc2
,
686 gen_op_eval_fbe_fcc2
,
687 gen_op_eval_fbue_fcc2
,
688 gen_op_eval_fbge_fcc2
,
689 gen_op_eval_fbuge_fcc2
,
690 gen_op_eval_fble_fcc2
,
691 gen_op_eval_fbule_fcc2
,
692 gen_op_eval_fbo_fcc2
,
696 gen_op_eval_fbne_fcc3
,
697 gen_op_eval_fblg_fcc3
,
698 gen_op_eval_fbul_fcc3
,
699 gen_op_eval_fbl_fcc3
,
700 gen_op_eval_fbug_fcc3
,
701 gen_op_eval_fbg_fcc3
,
702 gen_op_eval_fbu_fcc3
,
704 gen_op_eval_fbe_fcc3
,
705 gen_op_eval_fbue_fcc3
,
706 gen_op_eval_fbge_fcc3
,
707 gen_op_eval_fbuge_fcc3
,
708 gen_op_eval_fble_fcc3
,
709 gen_op_eval_fbule_fcc3
,
710 gen_op_eval_fbo_fcc3
,
717 #ifdef TARGET_SPARC64
718 static void gen_cond_reg(int cond
)
744 /* XXX: potentially incorrect if dynamic npc */
745 static void do_branch(DisasContext
* dc
, int32_t offset
, uint32_t insn
, int cc
)
747 unsigned int cond
= GET_FIELD(insn
, 3, 6), a
= (insn
& (1 << 29));
748 target_ulong target
= dc
->pc
+ offset
;
751 /* unconditional not taken */
753 dc
->pc
= dc
->npc
+ 4;
754 dc
->npc
= dc
->pc
+ 4;
757 dc
->npc
= dc
->pc
+ 4;
759 } else if (cond
== 0x8) {
760 /* unconditional taken */
763 dc
->npc
= dc
->pc
+ 4;
770 gen_cond
[cc
][cond
]();
772 gen_op_branch_a((long)dc
->tb
, target
, dc
->npc
);
776 dc
->jump_pc
[0] = target
;
777 dc
->jump_pc
[1] = dc
->npc
+ 4;
783 /* XXX: potentially incorrect if dynamic npc */
784 static void do_fbranch(DisasContext
* dc
, int32_t offset
, uint32_t insn
, int cc
)
786 unsigned int cond
= GET_FIELD(insn
, 3, 6), a
= (insn
& (1 << 29));
787 target_ulong target
= dc
->pc
+ offset
;
790 /* unconditional not taken */
792 dc
->pc
= dc
->npc
+ 4;
793 dc
->npc
= dc
->pc
+ 4;
796 dc
->npc
= dc
->pc
+ 4;
798 } else if (cond
== 0x8) {
799 /* unconditional taken */
802 dc
->npc
= dc
->pc
+ 4;
809 gen_fcond
[cc
][cond
]();
811 gen_op_branch_a((long)dc
->tb
, target
, dc
->npc
);
815 dc
->jump_pc
[0] = target
;
816 dc
->jump_pc
[1] = dc
->npc
+ 4;
822 #ifdef TARGET_SPARC64
823 /* XXX: potentially incorrect if dynamic npc */
824 static void do_branch_reg(DisasContext
* dc
, int32_t offset
, uint32_t insn
)
826 unsigned int cond
= GET_FIELD_SP(insn
, 25, 27), a
= (insn
& (1 << 29));
827 target_ulong target
= dc
->pc
+ offset
;
832 gen_op_branch_a((long)dc
->tb
, target
, dc
->npc
);
836 dc
->jump_pc
[0] = target
;
837 dc
->jump_pc
[1] = dc
->npc
+ 4;
842 static GenOpFunc
* const gen_fcmps
[4] = {
849 static GenOpFunc
* const gen_fcmpd
[4] = {
857 /* before an instruction, dc->pc must be static */
858 static void disas_sparc_insn(DisasContext
* dc
)
860 unsigned int insn
, opc
, rs1
, rs2
, rd
;
862 insn
= ldl_code(dc
->pc
);
863 opc
= GET_FIELD(insn
, 0, 1);
865 rd
= GET_FIELD(insn
, 2, 6);
867 case 0: /* branches/sethi */
869 unsigned int xop
= GET_FIELD(insn
, 7, 9);
872 #ifdef TARGET_SPARC64
873 case 0x1: /* V9 BPcc */
877 target
= GET_FIELD_SP(insn
, 0, 18);
879 target
= sign_extend(target
, 18);
880 cc
= GET_FIELD_SP(insn
, 20, 21);
882 do_branch(dc
, target
, insn
, 0);
884 do_branch(dc
, target
, insn
, 1);
889 case 0x3: /* V9 BPr */
891 target
= GET_FIELD_SP(insn
, 0, 13) |
892 (GET_FIELD_SP(insn
, 20, 21) >> 7);
894 target
= sign_extend(target
, 16);
895 rs1
= GET_FIELD(insn
, 13, 17);
896 gen_movl_T0_reg(rs1
);
897 do_branch_reg(dc
, target
, insn
);
900 case 0x5: /* V9 FBPcc */
902 int cc
= GET_FIELD_SP(insn
, 20, 21);
903 #if !defined(CONFIG_USER_ONLY)
904 gen_op_trap_ifnofpu();
906 target
= GET_FIELD_SP(insn
, 0, 18);
908 target
= sign_extend(target
, 19);
909 do_fbranch(dc
, target
, insn
, cc
);
915 target
= GET_FIELD(insn
, 10, 31);
917 target
= sign_extend(target
, 22);
918 do_branch(dc
, target
, insn
, 0);
921 case 0x6: /* FBN+x */
923 #if !defined(CONFIG_USER_ONLY)
924 gen_op_trap_ifnofpu();
926 target
= GET_FIELD(insn
, 10, 31);
928 target
= sign_extend(target
, 22);
929 do_fbranch(dc
, target
, insn
, 0);
932 case 0x4: /* SETHI */
937 uint32_t value
= GET_FIELD(insn
, 10, 31);
938 gen_movl_imm_T0(value
<< 10);
944 case 0x0: /* UNIMPL */
953 target_long target
= GET_FIELDs(insn
, 2, 31) << 2;
955 gen_op_movl_T0_im(dc
->pc
);
962 case 2: /* FPU & Logical Operations */
964 unsigned int xop
= GET_FIELD(insn
, 7, 12);
965 if (xop
== 0x3a) { /* generate trap */
968 rs1
= GET_FIELD(insn
, 13, 17);
969 gen_movl_reg_T0(rs1
);
971 rs2
= GET_FIELD(insn
, 25, 31);
975 gen_movl_simm_T1(rs2
);
981 rs2
= GET_FIELD(insn
, 27, 31);
985 gen_movl_reg_T1(rs2
);
992 cond
= GET_FIELD(insn
, 3, 6);
997 } else if (cond
!= 0) {
998 #ifdef TARGET_SPARC64
1000 int cc
= GET_FIELD_SP(insn
, 11, 12);
1002 gen_cond
[0][cond
]();
1004 gen_cond
[1][cond
]();
1008 gen_cond
[0][cond
]();
1012 } else if (xop
== 0x28) {
1013 rs1
= GET_FIELD(insn
, 13, 17);
1016 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, y
));
1017 gen_movl_T0_reg(rd
);
1019 case 15: /* stbar / V9 membar */
1020 break; /* no effect? */
1021 #ifdef TARGET_SPARC64
1022 case 0x2: /* V9 rdccr */
1024 gen_movl_T0_reg(rd
);
1026 case 0x3: /* V9 rdasi */
1027 gen_op_movl_T0_env(offsetof(CPUSPARCState
, asi
));
1028 gen_movl_T0_reg(rd
);
1030 case 0x4: /* V9 rdtick */
1032 gen_movl_T0_reg(rd
);
1034 case 0x5: /* V9 rdpc */
1035 gen_op_movl_T0_im(dc
->pc
);
1036 gen_movl_T0_reg(rd
);
1038 case 0x6: /* V9 rdfprs */
1039 gen_op_movl_T0_env(offsetof(CPUSPARCState
, fprs
));
1040 gen_movl_T0_reg(rd
);
1046 #if !defined(CONFIG_USER_ONLY)
1047 #ifndef TARGET_SPARC64
1048 } else if (xop
== 0x29) { /* rdpsr / V9 unimp */
1049 if (!supervisor(dc
))
1052 gen_movl_T0_reg(rd
);
1055 } else if (xop
== 0x2a) { /* rdwim / V9 rdpr */
1056 if (!supervisor(dc
))
1058 #ifdef TARGET_SPARC64
1059 rs1
= GET_FIELD(insn
, 13, 17);
1077 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, tbr
));
1083 gen_op_movl_T0_env(offsetof(CPUSPARCState
, tl
));
1086 gen_op_movl_T0_env(offsetof(CPUSPARCState
, psrpil
));
1092 gen_op_movl_T0_env(offsetof(CPUSPARCState
, cansave
));
1094 case 11: // canrestore
1095 gen_op_movl_T0_env(offsetof(CPUSPARCState
, canrestore
));
1097 case 12: // cleanwin
1098 gen_op_movl_T0_env(offsetof(CPUSPARCState
, cleanwin
));
1100 case 13: // otherwin
1101 gen_op_movl_T0_env(offsetof(CPUSPARCState
, otherwin
));
1104 gen_op_movl_T0_env(offsetof(CPUSPARCState
, wstate
));
1107 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, version
));
1114 gen_op_movl_T0_env(offsetof(CPUSPARCState
, wim
));
1116 gen_movl_T0_reg(rd
);
1118 } else if (xop
== 0x2b) { /* rdtbr / V9 flushw */
1119 #ifdef TARGET_SPARC64
1122 if (!supervisor(dc
))
1124 gen_op_movtl_T0_env(offsetof(CPUSPARCState
, tbr
));
1125 gen_movl_T0_reg(rd
);
1129 } else if (xop
== 0x34) { /* FPU Operations */
1130 #if !defined(CONFIG_USER_ONLY)
1131 gen_op_trap_ifnofpu();
1133 rs1
= GET_FIELD(insn
, 13, 17);
1134 rs2
= GET_FIELD(insn
, 27, 31);
1135 xop
= GET_FIELD(insn
, 18, 26);
1137 case 0x1: /* fmovs */
1138 gen_op_load_fpr_FT0(rs2
);
1139 gen_op_store_FT0_fpr(rd
);
1141 case 0x5: /* fnegs */
1142 gen_op_load_fpr_FT1(rs2
);
1144 gen_op_store_FT0_fpr(rd
);
1146 case 0x9: /* fabss */
1147 gen_op_load_fpr_FT1(rs2
);
1149 gen_op_store_FT0_fpr(rd
);
1151 case 0x29: /* fsqrts */
1152 gen_op_load_fpr_FT1(rs2
);
1154 gen_op_store_FT0_fpr(rd
);
1156 case 0x2a: /* fsqrtd */
1157 gen_op_load_fpr_DT1(DFPREG(rs2
));
1159 gen_op_store_DT0_fpr(DFPREG(rd
));
1161 case 0x2b: /* fsqrtq */
1164 gen_op_load_fpr_FT0(rs1
);
1165 gen_op_load_fpr_FT1(rs2
);
1167 gen_op_store_FT0_fpr(rd
);
1170 gen_op_load_fpr_DT0(DFPREG(rs1
));
1171 gen_op_load_fpr_DT1(DFPREG(rs2
));
1173 gen_op_store_DT0_fpr(DFPREG(rd
));
1175 case 0x43: /* faddq */
1178 gen_op_load_fpr_FT0(rs1
);
1179 gen_op_load_fpr_FT1(rs2
);
1181 gen_op_store_FT0_fpr(rd
);
1184 gen_op_load_fpr_DT0(DFPREG(rs1
));
1185 gen_op_load_fpr_DT1(DFPREG(rs2
));
1187 gen_op_store_DT0_fpr(DFPREG(rd
));
1189 case 0x47: /* fsubq */
1192 gen_op_load_fpr_FT0(rs1
);
1193 gen_op_load_fpr_FT1(rs2
);
1195 gen_op_store_FT0_fpr(rd
);
1198 gen_op_load_fpr_DT0(DFPREG(rs1
));
1199 gen_op_load_fpr_DT1(DFPREG(rs2
));
1201 gen_op_store_DT0_fpr(rd
);
1203 case 0x4b: /* fmulq */
1206 gen_op_load_fpr_FT0(rs1
);
1207 gen_op_load_fpr_FT1(rs2
);
1209 gen_op_store_FT0_fpr(rd
);
1212 gen_op_load_fpr_DT0(DFPREG(rs1
));
1213 gen_op_load_fpr_DT1(DFPREG(rs2
));
1215 gen_op_store_DT0_fpr(DFPREG(rd
));
1217 case 0x4f: /* fdivq */
1220 gen_op_load_fpr_FT0(rs1
);
1221 gen_op_load_fpr_FT1(rs2
);
1223 gen_op_store_DT0_fpr(DFPREG(rd
));
1225 case 0x6e: /* fdmulq */
1228 gen_op_load_fpr_FT1(rs2
);
1230 gen_op_store_FT0_fpr(rd
);
1233 gen_op_load_fpr_DT1(DFPREG(rs2
));
1235 gen_op_store_FT0_fpr(rd
);
1237 case 0xc7: /* fqtos */
1240 gen_op_load_fpr_FT1(rs2
);
1242 gen_op_store_DT0_fpr(DFPREG(rd
));
1245 gen_op_load_fpr_FT1(rs2
);
1247 gen_op_store_DT0_fpr(DFPREG(rd
));
1249 case 0xcb: /* fqtod */
1251 case 0xcc: /* fitoq */
1253 case 0xcd: /* fstoq */
1255 case 0xce: /* fdtoq */
1258 gen_op_load_fpr_FT1(rs2
);
1260 gen_op_store_FT0_fpr(rd
);
1263 gen_op_load_fpr_DT1(rs2
);
1265 gen_op_store_FT0_fpr(rd
);
1267 case 0xd3: /* fqtoi */
1269 #ifdef TARGET_SPARC64
1270 case 0x2: /* V9 fmovd */
1271 gen_op_load_fpr_DT0(DFPREG(rs2
));
1272 gen_op_store_DT0_fpr(DFPREG(rd
));
1274 case 0x6: /* V9 fnegd */
1275 gen_op_load_fpr_DT1(DFPREG(rs2
));
1277 gen_op_store_DT0_fpr(DFPREG(rd
));
1279 case 0xa: /* V9 fabsd */
1280 gen_op_load_fpr_DT1(DFPREG(rs2
));
1282 gen_op_store_DT0_fpr(DFPREG(rd
));
1284 case 0x81: /* V9 fstox */
1285 gen_op_load_fpr_FT1(rs2
);
1287 gen_op_store_DT0_fpr(DFPREG(rd
));
1289 case 0x82: /* V9 fdtox */
1290 gen_op_load_fpr_DT1(DFPREG(rs2
));
1292 gen_op_store_DT0_fpr(DFPREG(rd
));
1294 case 0x84: /* V9 fxtos */
1295 gen_op_load_fpr_DT1(DFPREG(rs2
));
1297 gen_op_store_FT0_fpr(rd
);
1299 case 0x88: /* V9 fxtod */
1300 gen_op_load_fpr_DT1(DFPREG(rs2
));
1302 gen_op_store_DT0_fpr(DFPREG(rd
));
1304 case 0x3: /* V9 fmovq */
1305 case 0x7: /* V9 fnegq */
1306 case 0xb: /* V9 fabsq */
1307 case 0x83: /* V9 fqtox */
1308 case 0x8c: /* V9 fxtoq */
1314 } else if (xop
== 0x35) { /* FPU Operations */
1315 #ifdef TARGET_SPARC64
1318 #if !defined(CONFIG_USER_ONLY)
1319 gen_op_trap_ifnofpu();
1321 rs1
= GET_FIELD(insn
, 13, 17);
1322 rs2
= GET_FIELD(insn
, 27, 31);
1323 xop
= GET_FIELD(insn
, 18, 26);
1324 #ifdef TARGET_SPARC64
1325 if ((xop
& 0x11f) == 0x005) { // V9 fmovsr
1326 cond
= GET_FIELD_SP(insn
, 14, 17);
1327 gen_op_load_fpr_FT0(rd
);
1328 gen_op_load_fpr_FT1(rs2
);
1329 rs1
= GET_FIELD(insn
, 13, 17);
1330 gen_movl_reg_T0(rs1
);
1334 gen_op_store_FT0_fpr(rd
);
1336 } else if ((xop
& 0x11f) == 0x006) { // V9 fmovdr
1337 cond
= GET_FIELD_SP(insn
, 14, 17);
1338 gen_op_load_fpr_DT0(rd
);
1339 gen_op_load_fpr_DT1(rs2
);
1341 rs1
= GET_FIELD(insn
, 13, 17);
1342 gen_movl_reg_T0(rs1
);
1345 gen_op_store_DT0_fpr(rd
);
1347 } else if ((xop
& 0x11f) == 0x007) { // V9 fmovqr
1352 #ifdef TARGET_SPARC64
1353 case 0x001: /* V9 fmovscc %fcc0 */
1354 cond
= GET_FIELD_SP(insn
, 14, 17);
1355 gen_op_load_fpr_FT0(rd
);
1356 gen_op_load_fpr_FT1(rs2
);
1358 gen_fcond
[0][cond
]();
1360 gen_op_store_FT0_fpr(rd
);
1362 case 0x002: /* V9 fmovdcc %fcc0 */
1363 cond
= GET_FIELD_SP(insn
, 14, 17);
1364 gen_op_load_fpr_DT0(rd
);
1365 gen_op_load_fpr_DT1(rs2
);
1367 gen_fcond
[0][cond
]();
1369 gen_op_store_DT0_fpr(rd
);
1371 case 0x003: /* V9 fmovqcc %fcc0 */
1373 case 0x041: /* V9 fmovscc %fcc1 */
1374 cond
= GET_FIELD_SP(insn
, 14, 17);
1375 gen_op_load_fpr_FT0(rd
);
1376 gen_op_load_fpr_FT1(rs2
);
1378 gen_fcond
[1][cond
]();
1380 gen_op_store_FT0_fpr(rd
);
1382 case 0x042: /* V9 fmovdcc %fcc1 */
1383 cond
= GET_FIELD_SP(insn
, 14, 17);
1384 gen_op_load_fpr_DT0(rd
);
1385 gen_op_load_fpr_DT1(rs2
);
1387 gen_fcond
[1][cond
]();
1389 gen_op_store_DT0_fpr(rd
);
1391 case 0x043: /* V9 fmovqcc %fcc1 */
1393 case 0x081: /* V9 fmovscc %fcc2 */
1394 cond
= GET_FIELD_SP(insn
, 14, 17);
1395 gen_op_load_fpr_FT0(rd
);
1396 gen_op_load_fpr_FT1(rs2
);
1398 gen_fcond
[2][cond
]();
1400 gen_op_store_FT0_fpr(rd
);
1402 case 0x082: /* V9 fmovdcc %fcc2 */
1403 cond
= GET_FIELD_SP(insn
, 14, 17);
1404 gen_op_load_fpr_DT0(rd
);
1405 gen_op_load_fpr_DT1(rs2
);
1407 gen_fcond
[2][cond
]();
1409 gen_op_store_DT0_fpr(rd
);
1411 case 0x083: /* V9 fmovqcc %fcc2 */
1413 case 0x0c1: /* V9 fmovscc %fcc3 */
1414 cond
= GET_FIELD_SP(insn
, 14, 17);
1415 gen_op_load_fpr_FT0(rd
);
1416 gen_op_load_fpr_FT1(rs2
);
1418 gen_fcond
[3][cond
]();
1420 gen_op_store_FT0_fpr(rd
);
1422 case 0x0c2: /* V9 fmovdcc %fcc3 */
1423 cond
= GET_FIELD_SP(insn
, 14, 17);
1424 gen_op_load_fpr_DT0(rd
);
1425 gen_op_load_fpr_DT1(rs2
);
1427 gen_fcond
[3][cond
]();
1429 gen_op_store_DT0_fpr(rd
);
1431 case 0x0c3: /* V9 fmovqcc %fcc3 */
1433 case 0x101: /* V9 fmovscc %icc */
1434 cond
= GET_FIELD_SP(insn
, 14, 17);
1435 gen_op_load_fpr_FT0(rd
);
1436 gen_op_load_fpr_FT1(rs2
);
1438 gen_cond
[0][cond
]();
1440 gen_op_store_FT0_fpr(rd
);
1442 case 0x102: /* V9 fmovdcc %icc */
1443 cond
= GET_FIELD_SP(insn
, 14, 17);
1444 gen_op_load_fpr_DT0(rd
);
1445 gen_op_load_fpr_DT1(rs2
);
1447 gen_cond
[0][cond
]();
1449 gen_op_store_DT0_fpr(rd
);
1451 case 0x103: /* V9 fmovqcc %icc */
1453 case 0x181: /* V9 fmovscc %xcc */
1454 cond
= GET_FIELD_SP(insn
, 14, 17);
1455 gen_op_load_fpr_FT0(rd
);
1456 gen_op_load_fpr_FT1(rs2
);
1458 gen_cond
[1][cond
]();
1460 gen_op_store_FT0_fpr(rd
);
1462 case 0x182: /* V9 fmovdcc %xcc */
1463 cond
= GET_FIELD_SP(insn
, 14, 17);
1464 gen_op_load_fpr_DT0(rd
);
1465 gen_op_load_fpr_DT1(rs2
);
1467 gen_cond
[1][cond
]();
1469 gen_op_store_DT0_fpr(rd
);
1471 case 0x183: /* V9 fmovqcc %xcc */
1474 case 0x51: /* V9 %fcc */
1475 gen_op_load_fpr_FT0(rs1
);
1476 gen_op_load_fpr_FT1(rs2
);
1477 #ifdef TARGET_SPARC64
1478 gen_fcmps
[rd
& 3]();
1483 case 0x52: /* V9 %fcc */
1484 gen_op_load_fpr_DT0(DFPREG(rs1
));
1485 gen_op_load_fpr_DT1(DFPREG(rs2
));
1486 #ifdef TARGET_SPARC64
1487 gen_fcmpd
[rd
& 3]();
1492 case 0x53: /* fcmpq */
1494 case 0x55: /* fcmpes, V9 %fcc */
1495 gen_op_load_fpr_FT0(rs1
);
1496 gen_op_load_fpr_FT1(rs2
);
1497 #ifdef TARGET_SPARC64
1498 gen_fcmps
[rd
& 3]();
1500 gen_op_fcmps(); /* XXX should trap if qNaN or sNaN */
1503 case 0x56: /* fcmped, V9 %fcc */
1504 gen_op_load_fpr_DT0(DFPREG(rs1
));
1505 gen_op_load_fpr_DT1(DFPREG(rs2
));
1506 #ifdef TARGET_SPARC64
1507 gen_fcmpd
[rd
& 3]();
1509 gen_op_fcmpd(); /* XXX should trap if qNaN or sNaN */
1512 case 0x57: /* fcmpeq */
1518 } else if (xop
== 0x2) {
1521 rs1
= GET_FIELD(insn
, 13, 17);
1523 // or %g0, x, y -> mov T1, x; mov y, T1
1524 if (IS_IMM
) { /* immediate */
1525 rs2
= GET_FIELDs(insn
, 19, 31);
1526 gen_movl_simm_T1(rs2
);
1527 } else { /* register */
1528 rs2
= GET_FIELD(insn
, 27, 31);
1529 gen_movl_reg_T1(rs2
);
1531 gen_movl_T1_reg(rd
);
1533 gen_movl_reg_T0(rs1
);
1534 if (IS_IMM
) { /* immediate */
1535 // or x, #0, y -> mov T1, x; mov y, T1
1536 rs2
= GET_FIELDs(insn
, 19, 31);
1538 gen_movl_simm_T1(rs2
);
1541 } else { /* register */
1542 // or x, %g0, y -> mov T1, x; mov y, T1
1543 rs2
= GET_FIELD(insn
, 27, 31);
1545 gen_movl_reg_T1(rs2
);
1549 gen_movl_T0_reg(rd
);
1552 } else if (xop
< 0x38) {
1553 rs1
= GET_FIELD(insn
, 13, 17);
1554 gen_movl_reg_T0(rs1
);
1555 if (IS_IMM
) { /* immediate */
1556 rs2
= GET_FIELDs(insn
, 19, 31);
1557 gen_movl_simm_T1(rs2
);
1558 } else { /* register */
1559 rs2
= GET_FIELD(insn
, 27, 31);
1560 gen_movl_reg_T1(rs2
);
1563 switch (xop
& ~0x10) {
1566 gen_op_add_T1_T0_cc();
1573 gen_op_logic_T0_cc();
1578 gen_op_logic_T0_cc();
1583 gen_op_logic_T0_cc();
1587 gen_op_sub_T1_T0_cc();
1592 gen_op_andn_T1_T0();
1594 gen_op_logic_T0_cc();
1599 gen_op_logic_T0_cc();
1602 gen_op_xnor_T1_T0();
1604 gen_op_logic_T0_cc();
1608 gen_op_addx_T1_T0_cc();
1610 gen_op_addx_T1_T0();
1613 gen_op_umul_T1_T0();
1615 gen_op_logic_T0_cc();
1618 gen_op_smul_T1_T0();
1620 gen_op_logic_T0_cc();
1624 gen_op_subx_T1_T0_cc();
1626 gen_op_subx_T1_T0();
1629 gen_op_udiv_T1_T0();
1634 gen_op_sdiv_T1_T0();
1641 gen_movl_T0_reg(rd
);
1644 #ifdef TARGET_SPARC64
1645 case 0x9: /* V9 mulx */
1646 gen_op_mulx_T1_T0();
1647 gen_movl_T0_reg(rd
);
1649 case 0xd: /* V9 udivx */
1650 gen_op_udivx_T1_T0();
1651 gen_movl_T0_reg(rd
);
1654 case 0x20: /* taddcc */
1655 case 0x21: /* tsubcc */
1656 case 0x22: /* taddcctv */
1657 case 0x23: /* tsubcctv */
1659 case 0x24: /* mulscc */
1660 gen_op_mulscc_T1_T0();
1661 gen_movl_T0_reg(rd
);
1663 case 0x25: /* sll, V9 sllx ( == sll) */
1665 gen_movl_T0_reg(rd
);
1667 case 0x26: /* srl, V9 srlx */
1668 #ifdef TARGET_SPARC64
1669 if (insn
& (1 << 12))
1676 gen_movl_T0_reg(rd
);
1678 case 0x27: /* sra, V9 srax */
1679 #ifdef TARGET_SPARC64
1680 if (insn
& (1 << 12))
1687 gen_movl_T0_reg(rd
);
1694 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, y
));
1696 #ifdef TARGET_SPARC64
1697 case 0x2: /* V9 wrccr */
1700 case 0x3: /* V9 wrasi */
1701 gen_op_movl_env_T0(offsetof(CPUSPARCState
, asi
));
1703 case 0x6: /* V9 wrfprs */
1704 gen_op_movl_env_T0(offsetof(CPUSPARCState
, fprs
));
1706 case 0xf: /* V9 sir, nop if user */
1707 #if !defined(CONFIG_USER_ONLY)
1713 case 0x10: /* Performance Control */
1714 case 0x11: /* Performance Instrumentation Counter */
1715 case 0x12: /* Dispatch Control */
1716 case 0x13: /* Graphics Status */
1717 case 0x14: /* Softint set */
1718 case 0x15: /* Softint clear */
1719 case 0x16: /* Softint write */
1720 case 0x17: /* Tick compare */
1721 case 0x18: /* System tick */
1722 case 0x19: /* System tick compare */
1728 #if !defined(CONFIG_USER_ONLY)
1729 case 0x31: /* wrpsr, V9 saved, restored */
1731 if (!supervisor(dc
))
1733 #ifdef TARGET_SPARC64
1750 case 0x32: /* wrwim, V9 wrpr */
1752 if (!supervisor(dc
))
1755 #ifdef TARGET_SPARC64
1773 gen_op_movl_env_T0(offsetof(CPUSPARCState
, tbr
));
1779 gen_op_movl_env_T0(offsetof(CPUSPARCState
, tl
));
1782 gen_op_movl_env_T0(offsetof(CPUSPARCState
, psrpil
));
1788 gen_op_movl_env_T0(offsetof(CPUSPARCState
, cansave
));
1790 case 11: // canrestore
1791 gen_op_movl_env_T0(offsetof(CPUSPARCState
, canrestore
));
1793 case 12: // cleanwin
1794 gen_op_movl_env_T0(offsetof(CPUSPARCState
, cleanwin
));
1796 case 13: // otherwin
1797 gen_op_movl_env_T0(offsetof(CPUSPARCState
, otherwin
));
1800 gen_op_movl_env_T0(offsetof(CPUSPARCState
, wstate
));
1806 gen_op_movl_env_T0(offsetof(CPUSPARCState
, wim
));
1810 #ifndef TARGET_SPARC64
1811 case 0x33: /* wrtbr, V9 unimp */
1813 if (!supervisor(dc
))
1816 gen_op_movtl_env_T0(offsetof(CPUSPARCState
, tbr
));
1821 #ifdef TARGET_SPARC64
1822 case 0x2c: /* V9 movcc */
1824 int cc
= GET_FIELD_SP(insn
, 11, 12);
1825 int cond
= GET_FIELD_SP(insn
, 14, 17);
1826 if (IS_IMM
) { /* immediate */
1827 rs2
= GET_FIELD_SPs(insn
, 0, 10);
1828 gen_movl_simm_T1(rs2
);
1831 rs2
= GET_FIELD_SP(insn
, 0, 4);
1832 gen_movl_reg_T1(rs2
);
1834 gen_movl_reg_T0(rd
);
1836 if (insn
& (1 << 18)) {
1838 gen_cond
[0][cond
]();
1840 gen_cond
[1][cond
]();
1844 gen_fcond
[cc
][cond
]();
1847 gen_movl_T0_reg(rd
);
1850 case 0x2d: /* V9 sdivx */
1851 gen_op_sdivx_T1_T0();
1852 gen_movl_T0_reg(rd
);
1854 case 0x2e: /* V9 popc */
1856 if (IS_IMM
) { /* immediate */
1857 rs2
= GET_FIELD_SPs(insn
, 0, 12);
1858 gen_movl_simm_T1(rs2
);
1859 // XXX optimize: popc(constant)
1862 rs2
= GET_FIELD_SP(insn
, 0, 4);
1863 gen_movl_reg_T1(rs2
);
1866 gen_movl_T0_reg(rd
);
1868 case 0x2f: /* V9 movr */
1870 int cond
= GET_FIELD_SP(insn
, 10, 12);
1871 rs1
= GET_FIELD(insn
, 13, 17);
1873 gen_movl_reg_T0(rs1
);
1875 if (IS_IMM
) { /* immediate */
1876 rs2
= GET_FIELD_SPs(insn
, 0, 10);
1877 gen_movl_simm_T1(rs2
);
1880 rs2
= GET_FIELD_SP(insn
, 0, 4);
1881 gen_movl_reg_T1(rs2
);
1883 gen_movl_reg_T0(rd
);
1885 gen_movl_T0_reg(rd
);
1888 case 0x36: /* UltraSparc shutdown, VIS */
1897 #ifdef TARGET_SPARC64
1898 } else if (xop
== 0x39) { /* V9 return */
1900 rs1
= GET_FIELD(insn
, 13, 17);
1901 gen_movl_reg_T0(rs1
);
1902 if (IS_IMM
) { /* immediate */
1903 rs2
= GET_FIELDs(insn
, 19, 31);
1907 gen_movl_simm_T1(rs2
);
1912 } else { /* register */
1913 rs2
= GET_FIELD(insn
, 27, 31);
1917 gen_movl_reg_T1(rs2
);
1924 gen_op_movl_npc_T0();
1925 dc
->npc
= DYNAMIC_PC
;
1929 rs1
= GET_FIELD(insn
, 13, 17);
1930 gen_movl_reg_T0(rs1
);
1931 if (IS_IMM
) { /* immediate */
1932 rs2
= GET_FIELDs(insn
, 19, 31);
1936 gen_movl_simm_T1(rs2
);
1941 } else { /* register */
1942 rs2
= GET_FIELD(insn
, 27, 31);
1946 gen_movl_reg_T1(rs2
);
1953 case 0x38: /* jmpl */
1956 gen_op_movl_T1_im(dc
->pc
);
1957 gen_movl_T1_reg(rd
);
1960 gen_op_movl_npc_T0();
1961 dc
->npc
= DYNAMIC_PC
;
1964 #if !defined(CONFIG_USER_ONLY) && !defined(TARGET_SPARC64)
1965 case 0x39: /* rett, V9 return */
1967 if (!supervisor(dc
))
1970 gen_op_movl_npc_T0();
1971 dc
->npc
= DYNAMIC_PC
;
1976 case 0x3b: /* flush */
1979 case 0x3c: /* save */
1982 gen_movl_T0_reg(rd
);
1984 case 0x3d: /* restore */
1987 gen_movl_T0_reg(rd
);
1989 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
1990 case 0x3e: /* V9 done/retry */
1994 if (!supervisor(dc
))
1999 if (!supervisor(dc
))
2016 case 3: /* load/store instructions */
2018 unsigned int xop
= GET_FIELD(insn
, 7, 12);
2019 rs1
= GET_FIELD(insn
, 13, 17);
2020 gen_movl_reg_T0(rs1
);
2021 if (IS_IMM
) { /* immediate */
2022 rs2
= GET_FIELDs(insn
, 19, 31);
2026 gen_movl_simm_T1(rs2
);
2031 } else { /* register */
2032 rs2
= GET_FIELD(insn
, 27, 31);
2036 gen_movl_reg_T1(rs2
);
2042 if (xop
< 4 || (xop
> 7 && xop
< 0x14 && xop
!= 0x0e) || \
2043 (xop
> 0x17 && xop
< 0x1d ) || \
2044 (xop
> 0x2c && xop
< 0x33) || xop
== 0x1f) {
2046 case 0x0: /* load word */
2049 case 0x1: /* load unsigned byte */
2052 case 0x2: /* load unsigned halfword */
2055 case 0x3: /* load double word */
2057 gen_movl_T0_reg(rd
+ 1);
2059 case 0x9: /* load signed byte */
2062 case 0xa: /* load signed halfword */
2065 case 0xd: /* ldstub -- XXX: should be atomically */
2066 gen_op_ldst(ldstub
);
2068 case 0x0f: /* swap register with memory. Also atomically */
2069 gen_movl_reg_T1(rd
);
2072 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2073 case 0x10: /* load word alternate */
2074 #ifndef TARGET_SPARC64
2075 if (!supervisor(dc
))
2078 gen_op_lda(insn
, 1, 4, 0);
2080 case 0x11: /* load unsigned byte alternate */
2081 #ifndef TARGET_SPARC64
2082 if (!supervisor(dc
))
2085 gen_op_lduba(insn
, 1, 1, 0);
2087 case 0x12: /* load unsigned halfword alternate */
2088 #ifndef TARGET_SPARC64
2089 if (!supervisor(dc
))
2092 gen_op_lduha(insn
, 1, 2, 0);
2094 case 0x13: /* load double word alternate */
2095 #ifndef TARGET_SPARC64
2096 if (!supervisor(dc
))
2099 gen_op_ldda(insn
, 1, 8, 0);
2100 gen_movl_T0_reg(rd
+ 1);
2102 case 0x19: /* load signed byte alternate */
2103 #ifndef TARGET_SPARC64
2104 if (!supervisor(dc
))
2107 gen_op_ldsba(insn
, 1, 1, 1);
2109 case 0x1a: /* load signed halfword alternate */
2110 #ifndef TARGET_SPARC64
2111 if (!supervisor(dc
))
2114 gen_op_ldsha(insn
, 1, 2 ,1);
2116 case 0x1d: /* ldstuba -- XXX: should be atomically */
2117 #ifndef TARGET_SPARC64
2118 if (!supervisor(dc
))
2121 gen_op_ldstuba(insn
, 1, 1, 0);
2123 case 0x1f: /* swap reg with alt. memory. Also atomically */
2124 #ifndef TARGET_SPARC64
2125 if (!supervisor(dc
))
2128 gen_movl_reg_T1(rd
);
2129 gen_op_swapa(insn
, 1, 4, 0);
2132 #ifndef TARGET_SPARC64
2133 /* avoid warnings */
2134 (void) &gen_op_stfa
;
2135 (void) &gen_op_stdfa
;
2136 (void) &gen_op_ldfa
;
2137 (void) &gen_op_lddfa
;
2139 #if !defined(CONFIG_USER_ONLY)
2141 (void) &gen_op_casx
;
2145 #ifdef TARGET_SPARC64
2146 case 0x08: /* V9 ldsw */
2149 case 0x0b: /* V9 ldx */
2152 case 0x18: /* V9 ldswa */
2153 gen_op_ldswa(insn
, 1, 4, 1);
2155 case 0x1b: /* V9 ldxa */
2156 gen_op_ldxa(insn
, 1, 8, 0);
2158 case 0x2d: /* V9 prefetch, no effect */
2160 case 0x30: /* V9 ldfa */
2161 gen_op_ldfa(insn
, 1, 8, 0); // XXX
2163 case 0x33: /* V9 lddfa */
2164 gen_op_lddfa(insn
, 1, 8, 0); // XXX
2167 case 0x3d: /* V9 prefetcha, no effect */
2169 case 0x32: /* V9 ldqfa */
2175 gen_movl_T1_reg(rd
);
2176 #ifdef TARGET_SPARC64
2179 } else if (xop
>= 0x20 && xop
< 0x24) {
2180 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2181 gen_op_trap_ifnofpu();
2184 case 0x20: /* load fpreg */
2186 gen_op_store_FT0_fpr(rd
);
2188 case 0x21: /* load fsr */
2190 gen_op_store_FT0_fpr(rd
);
2192 case 0x22: /* load quad fpreg */
2194 case 0x23: /* load double fpreg */
2196 gen_op_store_DT0_fpr(DFPREG(rd
));
2201 } else if (xop
< 8 || (xop
>= 0x14 && xop
< 0x18) || \
2202 xop
== 0xe || xop
== 0x1e) {
2203 gen_movl_reg_T1(rd
);
2216 gen_movl_reg_T2(rd
+ 1);
2219 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2221 #ifndef TARGET_SPARC64
2222 if (!supervisor(dc
))
2225 gen_op_sta(insn
, 0, 4, 0);
2228 #ifndef TARGET_SPARC64
2229 if (!supervisor(dc
))
2232 gen_op_stba(insn
, 0, 1, 0);
2235 #ifndef TARGET_SPARC64
2236 if (!supervisor(dc
))
2239 gen_op_stha(insn
, 0, 2, 0);
2242 #ifndef TARGET_SPARC64
2243 if (!supervisor(dc
))
2247 gen_movl_reg_T2(rd
+ 1);
2248 gen_op_stda(insn
, 0, 8, 0);
2251 #ifdef TARGET_SPARC64
2252 case 0x0e: /* V9 stx */
2255 case 0x1e: /* V9 stxa */
2256 gen_op_stxa(insn
, 0, 8, 0); // XXX
2262 } else if (xop
> 0x23 && xop
< 0x28) {
2263 #if !defined(CONFIG_USER_ONLY)
2264 gen_op_trap_ifnofpu();
2268 gen_op_load_fpr_FT0(rd
);
2271 case 0x25: /* stfsr, V9 stxfsr */
2272 gen_op_load_fpr_FT0(rd
);
2276 case 0x26: /* stdfq */
2279 gen_op_load_fpr_DT0(DFPREG(rd
));
2285 } else if (xop
> 0x33 && xop
< 0x3f) {
2286 #ifdef TARGET_SPARC64
2288 case 0x34: /* V9 stfa */
2289 gen_op_stfa(insn
, 0, 0, 0); // XXX
2291 case 0x37: /* V9 stdfa */
2292 gen_op_stdfa(insn
, 0, 0, 0); // XXX
2294 case 0x3c: /* V9 casa */
2295 gen_op_casa(insn
, 0, 4, 0); // XXX
2297 case 0x3e: /* V9 casxa */
2298 gen_op_casxa(insn
, 0, 8, 0); // XXX
2300 case 0x36: /* V9 stqfa */
2314 /* default case for non jump instructions */
2315 if (dc
->npc
== DYNAMIC_PC
) {
2316 dc
->pc
= DYNAMIC_PC
;
2318 } else if (dc
->npc
== JUMP_PC
) {
2319 /* we can do a static jump */
2320 gen_op_branch2((long)dc
->tb
, dc
->jump_pc
[0], dc
->jump_pc
[1]);
2324 dc
->npc
= dc
->npc
+ 4;
2330 gen_op_exception(TT_ILL_INSN
);
2333 #if !defined(CONFIG_USER_ONLY)
2336 gen_op_exception(TT_PRIV_INSN
);
2342 gen_op_fpexception_im(FSR_FTT_UNIMPFPOP
);
2346 static inline int gen_intermediate_code_internal(TranslationBlock
* tb
,
2347 int spc
, CPUSPARCState
*env
)
2349 target_ulong pc_start
, last_pc
;
2350 uint16_t *gen_opc_end
;
2351 DisasContext dc1
, *dc
= &dc1
;
2354 memset(dc
, 0, sizeof(DisasContext
));
2359 dc
->npc
= (target_ulong
) tb
->cs_base
;
2360 #if defined(CONFIG_USER_ONLY)
2363 dc
->mem_idx
= ((env
->psrs
) != 0);
2365 gen_opc_ptr
= gen_opc_buf
;
2366 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2367 gen_opparam_ptr
= gen_opparam_buf
;
2370 if (env
->nb_breakpoints
> 0) {
2371 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
2372 if (env
->breakpoints
[j
] == dc
->pc
) {
2373 if (dc
->pc
!= pc_start
)
2385 fprintf(logfile
, "Search PC...\n");
2386 j
= gen_opc_ptr
- gen_opc_buf
;
2390 gen_opc_instr_start
[lj
++] = 0;
2391 gen_opc_pc
[lj
] = dc
->pc
;
2392 gen_opc_npc
[lj
] = dc
->npc
;
2393 gen_opc_instr_start
[lj
] = 1;
2397 disas_sparc_insn(dc
);
2401 /* if the next PC is different, we abort now */
2402 if (dc
->pc
!= (last_pc
+ 4))
2404 /* if we reach a page boundary, we stop generation so that the
2405 PC of a TT_TFAULT exception is always in the right page */
2406 if ((dc
->pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
2408 /* if single step mode, we generate only one instruction and
2409 generate an exception */
2410 if (env
->singlestep_enabled
) {
2416 } while ((gen_opc_ptr
< gen_opc_end
) &&
2417 (dc
->pc
- pc_start
) < (TARGET_PAGE_SIZE
- 32));
2421 if (dc
->pc
!= DYNAMIC_PC
&&
2422 (dc
->npc
!= DYNAMIC_PC
&& dc
->npc
!= JUMP_PC
)) {
2423 /* static PC and NPC: we can use direct chaining */
2424 gen_op_branch((long)tb
, dc
->pc
, dc
->npc
);
2426 if (dc
->pc
!= DYNAMIC_PC
)
2433 *gen_opc_ptr
= INDEX_op_end
;
2435 j
= gen_opc_ptr
- gen_opc_buf
;
2438 gen_opc_instr_start
[lj
++] = 0;
2445 gen_opc_jump_pc
[0] = dc
->jump_pc
[0];
2446 gen_opc_jump_pc
[1] = dc
->jump_pc
[1];
2448 tb
->size
= last_pc
+ 4 - pc_start
;
2451 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2452 fprintf(logfile
, "--------------\n");
2453 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
2454 target_disas(logfile
, pc_start
, last_pc
+ 4 - pc_start
, 0);
2455 fprintf(logfile
, "\n");
2456 if (loglevel
& CPU_LOG_TB_OP
) {
2457 fprintf(logfile
, "OP:\n");
2458 dump_ops(gen_opc_buf
, gen_opparam_buf
);
2459 fprintf(logfile
, "\n");
2466 int gen_intermediate_code(CPUSPARCState
* env
, TranslationBlock
* tb
)
2468 return gen_intermediate_code_internal(tb
, 0, env
);
2471 int gen_intermediate_code_pc(CPUSPARCState
* env
, TranslationBlock
* tb
)
2473 return gen_intermediate_code_internal(tb
, 1, env
);
2476 extern int ram_size
;
2478 void cpu_reset(CPUSPARCState
*env
)
2480 memset(env
, 0, sizeof(*env
));
2484 env
->regwptr
= env
->regbase
+ (env
->cwp
* 16);
2485 #if defined(CONFIG_USER_ONLY)
2486 env
->user_mode_only
= 1;
2490 env
->pc
= 0xffd00000;
2491 env
->gregs
[1] = ram_size
;
2492 env
->npc
= env
->pc
+ 4;
2493 #ifdef TARGET_SPARC64
2494 env
->pstate
= PS_AM
| PS_PRIV
; // XXX: Force AM
2495 env
->version
= GET_VER(env
);
2497 env
->mmuregs
[0] = (0x04 << 24); /* Impl 0, ver 4, MMU disabled */
2502 CPUSPARCState
*cpu_sparc_init(void)
2508 if (!(env
= malloc(sizeof(CPUSPARCState
))))
2510 cpu_single_env
= env
;
2515 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
2517 void cpu_dump_state(CPUState
*env
, FILE *f
,
2518 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
2523 cpu_fprintf(f
, "pc: " TARGET_FMT_lx
" npc: " TARGET_FMT_lx
"\n", env
->pc
, env
->npc
);
2524 cpu_fprintf(f
, "General Registers:\n");
2525 for (i
= 0; i
< 4; i
++)
2526 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
2527 cpu_fprintf(f
, "\n");
2529 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
2530 cpu_fprintf(f
, "\nCurrent Register Window:\n");
2531 for (x
= 0; x
< 3; x
++) {
2532 for (i
= 0; i
< 4; i
++)
2533 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
2534 (x
== 0 ? 'o' : (x
== 1 ? 'l' : 'i')), i
,
2535 env
->regwptr
[i
+ x
* 8]);
2536 cpu_fprintf(f
, "\n");
2538 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
2539 (x
== 0 ? 'o' : x
== 1 ? 'l' : 'i'), i
,
2540 env
->regwptr
[i
+ x
* 8]);
2541 cpu_fprintf(f
, "\n");
2543 cpu_fprintf(f
, "\nFloating Point Registers:\n");
2544 for (i
= 0; i
< 32; i
++) {
2546 cpu_fprintf(f
, "%%f%02d:", i
);
2547 cpu_fprintf(f
, " %016lf", env
->fpr
[i
]);
2549 cpu_fprintf(f
, "\n");
2551 cpu_fprintf(f
, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env
),
2552 GET_FLAG(PSR_ZERO
, 'Z'), GET_FLAG(PSR_OVF
, 'V'),
2553 GET_FLAG(PSR_NEG
, 'N'), GET_FLAG(PSR_CARRY
, 'C'),
2554 env
->psrs
?'S':'-', env
->psrps
?'P':'-',
2555 env
->psret
?'E':'-', env
->wim
);
2556 cpu_fprintf(f
, "fsr: 0x%08x\n", GET_FSR32(env
));
2559 #if defined(CONFIG_USER_ONLY)
2560 target_ulong
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
2566 extern int get_physical_address (CPUState
*env
, target_phys_addr_t
*physical
, int *prot
,
2567 int *access_index
, target_ulong address
, int rw
,
2570 target_ulong
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
2572 target_phys_addr_t phys_addr
;
2573 int prot
, access_index
;
2575 if (get_physical_address(env
, &phys_addr
, &prot
, &access_index
, addr
, 2, 0) != 0)
2581 void helper_flush(target_ulong addr
)
2584 tb_invalidate_page_range(addr
, addr
+ 8);