2 #include "host-utils.h"
4 #if !defined(CONFIG_USER_ONLY)
5 #include "softmmu_exec.h"
6 #endif /* !defined(CONFIG_USER_ONLY) */
10 //#define DEBUG_UNALIGNED
11 //#define DEBUG_UNASSIGNED
16 #define DPRINTF_MMU(fmt, ...) \
17 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
19 #define DPRINTF_MMU(fmt, ...) do {} while (0)
23 #define DPRINTF_MXCC(fmt, ...) \
24 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
26 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
30 #define DPRINTF_ASI(fmt, ...) \
31 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
36 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
38 #define AM_CHECK(env1) (1)
42 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
43 // Calculates TSB pointer value for fault page size 8k or 64k
44 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
45 uint64_t tag_access_register
,
48 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
49 int tsb_split
= (env
->dmmuregs
[5] & 0x1000ULL
) ? 1 : 0;
50 int tsb_size
= env
->dmmuregs
[5] & 0xf;
52 // discard lower 13 bits which hold tag access context
53 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
56 uint64_t tsb_base_mask
= ~0x1fffULL
;
57 uint64_t va
= tag_access_va
;
59 // move va bits to correct position
60 if (page_size
== 8*1024) {
62 } else if (page_size
== 64*1024) {
67 tsb_base_mask
<<= tsb_size
;
70 // calculate tsb_base mask and adjust va if split is in use
72 if (page_size
== 8*1024) {
73 va
&= ~(1ULL << (13 + tsb_size
));
74 } else if (page_size
== 64*1024) {
75 va
|= (1ULL << (13 + tsb_size
));
80 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
83 // Calculates tag target register value by reordering bits
84 // in tag access register
85 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
87 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
92 static inline void address_mask(CPUState
*env1
, target_ulong
*addr
)
96 *addr
&= 0xffffffffULL
;
100 static void raise_exception(int tt
)
102 env
->exception_index
= tt
;
106 void HELPER(raise_exception
)(int tt
)
111 static inline void set_cwp(int new_cwp
)
113 cpu_set_cwp(env
, new_cwp
);
116 void helper_check_align(target_ulong addr
, uint32_t align
)
119 #ifdef DEBUG_UNALIGNED
120 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
121 "\n", addr
, env
->pc
);
123 raise_exception(TT_UNALIGNED
);
127 #define F_HELPER(name, p) void helper_f##name##p(void)
129 #define F_BINOP(name) \
130 float32 helper_f ## name ## s (float32 src1, float32 src2) \
132 return float32_ ## name (src1, src2, &env->fp_status); \
136 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
140 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
149 void helper_fsmuld(float32 src1
, float32 src2
)
151 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
152 float32_to_float64(src2
, &env
->fp_status
),
156 void helper_fdmulq(void)
158 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
159 float64_to_float128(DT1
, &env
->fp_status
),
163 float32
helper_fnegs(float32 src
)
165 return float32_chs(src
);
168 #ifdef TARGET_SPARC64
171 DT0
= float64_chs(DT1
);
176 QT0
= float128_chs(QT1
);
180 /* Integer to float conversion. */
181 float32
helper_fitos(int32_t src
)
183 return int32_to_float32(src
, &env
->fp_status
);
186 void helper_fitod(int32_t src
)
188 DT0
= int32_to_float64(src
, &env
->fp_status
);
191 void helper_fitoq(int32_t src
)
193 QT0
= int32_to_float128(src
, &env
->fp_status
);
196 #ifdef TARGET_SPARC64
197 float32
helper_fxtos(void)
199 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
204 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
209 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
214 /* floating point conversion */
215 float32
helper_fdtos(void)
217 return float64_to_float32(DT1
, &env
->fp_status
);
220 void helper_fstod(float32 src
)
222 DT0
= float32_to_float64(src
, &env
->fp_status
);
225 float32
helper_fqtos(void)
227 return float128_to_float32(QT1
, &env
->fp_status
);
230 void helper_fstoq(float32 src
)
232 QT0
= float32_to_float128(src
, &env
->fp_status
);
235 void helper_fqtod(void)
237 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
240 void helper_fdtoq(void)
242 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
245 /* Float to integer conversion. */
246 int32_t helper_fstoi(float32 src
)
248 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
251 int32_t helper_fdtoi(void)
253 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
256 int32_t helper_fqtoi(void)
258 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
261 #ifdef TARGET_SPARC64
262 void helper_fstox(float32 src
)
264 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
267 void helper_fdtox(void)
269 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
272 void helper_fqtox(void)
274 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
277 void helper_faligndata(void)
281 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
282 /* on many architectures a shift of 64 does nothing */
283 if ((env
->gsr
& 7) != 0) {
284 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
286 *((uint64_t *)&DT0
) = tmp
;
289 #ifdef WORDS_BIGENDIAN
290 #define VIS_B64(n) b[7 - (n)]
291 #define VIS_W64(n) w[3 - (n)]
292 #define VIS_SW64(n) sw[3 - (n)]
293 #define VIS_L64(n) l[1 - (n)]
294 #define VIS_B32(n) b[3 - (n)]
295 #define VIS_W32(n) w[1 - (n)]
297 #define VIS_B64(n) b[n]
298 #define VIS_W64(n) w[n]
299 #define VIS_SW64(n) sw[n]
300 #define VIS_L64(n) l[n]
301 #define VIS_B32(n) b[n]
302 #define VIS_W32(n) w[n]
320 void helper_fpmerge(void)
327 // Reverse calculation order to handle overlap
328 d
.VIS_B64(7) = s
.VIS_B64(3);
329 d
.VIS_B64(6) = d
.VIS_B64(3);
330 d
.VIS_B64(5) = s
.VIS_B64(2);
331 d
.VIS_B64(4) = d
.VIS_B64(2);
332 d
.VIS_B64(3) = s
.VIS_B64(1);
333 d
.VIS_B64(2) = d
.VIS_B64(1);
334 d
.VIS_B64(1) = s
.VIS_B64(0);
335 //d.VIS_B64(0) = d.VIS_B64(0);
340 void helper_fmul8x16(void)
349 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
350 if ((tmp & 0xff) > 0x7f) \
352 d.VIS_W64(r) = tmp >> 8;
363 void helper_fmul8x16al(void)
372 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
373 if ((tmp & 0xff) > 0x7f) \
375 d.VIS_W64(r) = tmp >> 8;
386 void helper_fmul8x16au(void)
395 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
396 if ((tmp & 0xff) > 0x7f) \
398 d.VIS_W64(r) = tmp >> 8;
409 void helper_fmul8sux16(void)
418 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
419 if ((tmp & 0xff) > 0x7f) \
421 d.VIS_W64(r) = tmp >> 8;
432 void helper_fmul8ulx16(void)
441 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
442 if ((tmp & 0xff) > 0x7f) \
444 d.VIS_W64(r) = tmp >> 8;
455 void helper_fmuld8sux16(void)
464 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
465 if ((tmp & 0xff) > 0x7f) \
469 // Reverse calculation order to handle overlap
477 void helper_fmuld8ulx16(void)
486 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
487 if ((tmp & 0xff) > 0x7f) \
491 // Reverse calculation order to handle overlap
499 void helper_fexpand(void)
504 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
506 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
507 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
508 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
509 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
514 #define VIS_HELPER(name, F) \
515 void name##16(void) \
522 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
523 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
524 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
525 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
530 uint32_t name##16s(uint32_t src1, uint32_t src2) \
537 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
538 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
543 void name##32(void) \
550 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
551 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
556 uint32_t name##32s(uint32_t src1, uint32_t src2) \
568 #define FADD(a, b) ((a) + (b))
569 #define FSUB(a, b) ((a) - (b))
570 VIS_HELPER(helper_fpadd
, FADD
)
571 VIS_HELPER(helper_fpsub
, FSUB
)
573 #define VIS_CMPHELPER(name, F) \
574 void name##16(void) \
581 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
582 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
583 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
584 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
589 void name##32(void) \
596 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
597 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
602 #define FCMPGT(a, b) ((a) > (b))
603 #define FCMPEQ(a, b) ((a) == (b))
604 #define FCMPLE(a, b) ((a) <= (b))
605 #define FCMPNE(a, b) ((a) != (b))
607 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
608 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
609 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
610 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
613 void helper_check_ieee_exceptions(void)
617 status
= get_float_exception_flags(&env
->fp_status
);
619 /* Copy IEEE 754 flags into FSR */
620 if (status
& float_flag_invalid
)
622 if (status
& float_flag_overflow
)
624 if (status
& float_flag_underflow
)
626 if (status
& float_flag_divbyzero
)
628 if (status
& float_flag_inexact
)
631 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
632 /* Unmasked exception, generate a trap */
633 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
634 raise_exception(TT_FP_EXCP
);
636 /* Accumulate exceptions */
637 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
642 void helper_clear_float_exceptions(void)
644 set_float_exception_flags(0, &env
->fp_status
);
647 float32
helper_fabss(float32 src
)
649 return float32_abs(src
);
652 #ifdef TARGET_SPARC64
653 void helper_fabsd(void)
655 DT0
= float64_abs(DT1
);
658 void helper_fabsq(void)
660 QT0
= float128_abs(QT1
);
664 float32
helper_fsqrts(float32 src
)
666 return float32_sqrt(src
, &env
->fp_status
);
669 void helper_fsqrtd(void)
671 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
674 void helper_fsqrtq(void)
676 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
679 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
680 void glue(helper_, name) (void) \
682 target_ulong new_fsr; \
684 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
685 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
686 case float_relation_unordered: \
687 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
688 if ((env->fsr & FSR_NVM) || TRAP) { \
689 env->fsr |= new_fsr; \
690 env->fsr |= FSR_NVC; \
691 env->fsr |= FSR_FTT_IEEE_EXCP; \
692 raise_exception(TT_FP_EXCP); \
694 env->fsr |= FSR_NVA; \
697 case float_relation_less: \
698 new_fsr = FSR_FCC0 << FS; \
700 case float_relation_greater: \
701 new_fsr = FSR_FCC1 << FS; \
707 env->fsr |= new_fsr; \
709 #define GEN_FCMPS(name, size, FS, TRAP) \
710 void glue(helper_, name)(float32 src1, float32 src2) \
712 target_ulong new_fsr; \
714 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
715 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
716 case float_relation_unordered: \
717 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
718 if ((env->fsr & FSR_NVM) || TRAP) { \
719 env->fsr |= new_fsr; \
720 env->fsr |= FSR_NVC; \
721 env->fsr |= FSR_FTT_IEEE_EXCP; \
722 raise_exception(TT_FP_EXCP); \
724 env->fsr |= FSR_NVA; \
727 case float_relation_less: \
728 new_fsr = FSR_FCC0 << FS; \
730 case float_relation_greater: \
731 new_fsr = FSR_FCC1 << FS; \
737 env->fsr |= new_fsr; \
740 GEN_FCMPS(fcmps
, float32
, 0, 0);
741 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
743 GEN_FCMPS(fcmpes
, float32
, 0, 1);
744 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
746 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
747 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
749 static uint32_t compute_all_flags(void)
751 return env
->psr
& PSR_ICC
;
754 static uint32_t compute_C_flags(void)
756 return env
->psr
& PSR_CARRY
;
759 static inline uint32_t get_NZ_icc(target_ulong dst
)
763 if (!(dst
& 0xffffffffULL
))
765 if ((int32_t) (dst
& 0xffffffffULL
) < 0)
770 #ifdef TARGET_SPARC64
771 static uint32_t compute_all_flags_xcc(void)
773 return env
->xcc
& PSR_ICC
;
776 static uint32_t compute_C_flags_xcc(void)
778 return env
->xcc
& PSR_CARRY
;
781 static inline uint32_t get_NZ_xcc(target_ulong dst
)
787 if ((int64_t)dst
< 0)
793 static inline uint32_t get_V_div_icc(target_ulong src2
)
802 static uint32_t compute_all_div(void)
806 ret
= get_NZ_icc(CC_DST
);
807 ret
|= get_V_div_icc(CC_SRC2
);
811 static uint32_t compute_C_div(void)
816 static inline uint32_t get_C_add_icc(target_ulong dst
, target_ulong src1
)
820 if ((dst
& 0xffffffffULL
) < (src1
& 0xffffffffULL
))
825 static inline uint32_t get_V_add_icc(target_ulong dst
, target_ulong src1
,
830 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 31))
835 static uint32_t compute_all_add(void)
839 ret
= get_NZ_icc(CC_DST
);
840 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
841 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
845 static uint32_t compute_C_add(void)
847 return get_C_add_icc(CC_DST
, CC_SRC
);
850 #ifdef TARGET_SPARC64
851 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
860 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
865 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63))
870 static uint32_t compute_all_add_xcc(void)
874 ret
= get_NZ_xcc(CC_DST
);
875 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
876 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
880 static uint32_t compute_C_add_xcc(void)
882 return get_C_add_xcc(CC_DST
, CC_SRC
);
886 static uint32_t compute_all_addx(void)
890 ret
= get_NZ_icc(CC_DST
);
891 ret
|= get_C_add_icc(CC_DST
- CC_SRC2
, CC_SRC
);
892 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
893 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
897 static uint32_t compute_C_addx(void)
901 ret
= get_C_add_icc(CC_DST
- CC_SRC2
, CC_SRC
);
902 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
906 #ifdef TARGET_SPARC64
907 static uint32_t compute_all_addx_xcc(void)
911 ret
= get_NZ_xcc(CC_DST
);
912 ret
|= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
913 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
914 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
918 static uint32_t compute_C_addx_xcc(void)
922 ret
= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
923 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
928 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
932 if ((src1
| src2
) & 0x3)
937 static uint32_t compute_all_tadd(void)
941 ret
= get_NZ_icc(CC_DST
);
942 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
943 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
944 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
948 static uint32_t compute_C_tadd(void)
950 return get_C_add_icc(CC_DST
, CC_SRC
);
953 static uint32_t compute_all_taddtv(void)
957 ret
= get_NZ_icc(CC_DST
);
958 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
962 static uint32_t compute_C_taddtv(void)
964 return get_C_add_icc(CC_DST
, CC_SRC
);
967 static inline uint32_t get_C_sub_icc(target_ulong src1
, target_ulong src2
)
971 if ((src1
& 0xffffffffULL
) < (src2
& 0xffffffffULL
))
976 static inline uint32_t get_V_sub_icc(target_ulong dst
, target_ulong src1
,
981 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 31))
986 static uint32_t compute_all_sub(void)
990 ret
= get_NZ_icc(CC_DST
);
991 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
992 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
996 static uint32_t compute_C_sub(void)
998 return get_C_sub_icc(CC_SRC
, CC_SRC2
);
1001 #ifdef TARGET_SPARC64
1002 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1011 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1016 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63))
1021 static uint32_t compute_all_sub_xcc(void)
1025 ret
= get_NZ_xcc(CC_DST
);
1026 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1027 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1031 static uint32_t compute_C_sub_xcc(void)
1033 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1037 static uint32_t compute_all_subx(void)
1041 ret
= get_NZ_icc(CC_DST
);
1042 ret
|= get_C_sub_icc(CC_DST
- CC_SRC2
, CC_SRC
);
1043 ret
|= get_C_sub_icc(CC_DST
, CC_SRC2
);
1044 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1048 static uint32_t compute_C_subx(void)
1052 ret
= get_C_sub_icc(CC_DST
- CC_SRC2
, CC_SRC
);
1053 ret
|= get_C_sub_icc(CC_DST
, CC_SRC2
);
1057 #ifdef TARGET_SPARC64
1058 static uint32_t compute_all_subx_xcc(void)
1062 ret
= get_NZ_xcc(CC_DST
);
1063 ret
|= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1064 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1065 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1069 static uint32_t compute_C_subx_xcc(void)
1073 ret
= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1074 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1079 static uint32_t compute_all_tsub(void)
1083 ret
= get_NZ_icc(CC_DST
);
1084 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
);
1085 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1086 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1090 static uint32_t compute_C_tsub(void)
1092 return get_C_sub_icc(CC_DST
, CC_SRC
);
1095 static uint32_t compute_all_tsubtv(void)
1099 ret
= get_NZ_icc(CC_DST
);
1100 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
);
1104 static uint32_t compute_C_tsubtv(void)
1106 return get_C_sub_icc(CC_DST
, CC_SRC
);
1109 static uint32_t compute_all_logic(void)
1111 return get_NZ_icc(CC_DST
);
1114 static uint32_t compute_C_logic(void)
1119 #ifdef TARGET_SPARC64
1120 static uint32_t compute_all_logic_xcc(void)
1122 return get_NZ_xcc(CC_DST
);
1126 typedef struct CCTable
{
1127 uint32_t (*compute_all
)(void); /* return all the flags */
1128 uint32_t (*compute_c
)(void); /* return the C flag */
1131 static const CCTable icc_table
[CC_OP_NB
] = {
1132 /* CC_OP_DYNAMIC should never happen */
1133 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1134 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1135 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1136 [CC_OP_ADDX
] = { compute_all_addx
, compute_C_addx
},
1137 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_tadd
},
1138 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_taddtv
},
1139 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1140 [CC_OP_SUBX
] = { compute_all_subx
, compute_C_subx
},
1141 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_tsub
},
1142 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_tsubtv
},
1143 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1146 #ifdef TARGET_SPARC64
1147 static const CCTable xcc_table
[CC_OP_NB
] = {
1148 /* CC_OP_DYNAMIC should never happen */
1149 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1150 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1151 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1152 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1153 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1154 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1155 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1156 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1157 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1158 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1159 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1163 void helper_compute_psr(void)
1167 new_psr
= icc_table
[CC_OP
].compute_all();
1169 #ifdef TARGET_SPARC64
1170 new_psr
= xcc_table
[CC_OP
].compute_all();
1173 CC_OP
= CC_OP_FLAGS
;
1176 uint32_t helper_compute_C_icc(void)
1180 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1184 #ifdef TARGET_SPARC64
1185 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1186 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1187 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1189 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1190 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1191 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1193 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1194 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1195 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1197 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1198 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1199 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1201 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1202 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1203 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1205 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1206 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1207 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1211 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1213 static void dump_mxcc(CPUState
*env
)
1215 printf("mxccdata: %016llx %016llx %016llx %016llx\n",
1216 env
->mxccdata
[0], env
->mxccdata
[1],
1217 env
->mxccdata
[2], env
->mxccdata
[3]);
1218 printf("mxccregs: %016llx %016llx %016llx %016llx\n"
1219 " %016llx %016llx %016llx %016llx\n",
1220 env
->mxccregs
[0], env
->mxccregs
[1],
1221 env
->mxccregs
[2], env
->mxccregs
[3],
1222 env
->mxccregs
[4], env
->mxccregs
[5],
1223 env
->mxccregs
[6], env
->mxccregs
[7]);
1227 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1228 && defined(DEBUG_ASI)
1229 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1235 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1236 addr
, asi
, r1
& 0xff);
1239 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1240 addr
, asi
, r1
& 0xffff);
1243 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1244 addr
, asi
, r1
& 0xffffffff);
1247 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1254 #ifndef TARGET_SPARC64
1255 #ifndef CONFIG_USER_ONLY
1256 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1259 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1260 uint32_t last_addr
= addr
;
1263 helper_check_align(addr
, size
- 1);
1265 case 2: /* SuperSparc MXCC registers */
1267 case 0x01c00a00: /* MXCC control register */
1269 ret
= env
->mxccregs
[3];
1271 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1274 case 0x01c00a04: /* MXCC control register */
1276 ret
= env
->mxccregs
[3];
1278 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1281 case 0x01c00c00: /* Module reset register */
1283 ret
= env
->mxccregs
[5];
1284 // should we do something here?
1286 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1289 case 0x01c00f00: /* MBus port address register */
1291 ret
= env
->mxccregs
[7];
1293 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1297 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1301 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1302 "addr = %08x -> ret = %" PRIx64
","
1303 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1308 case 3: /* MMU probe */
1312 mmulev
= (addr
>> 8) & 15;
1316 ret
= mmu_probe(env
, addr
, mmulev
);
1317 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1321 case 4: /* read MMU regs */
1323 int reg
= (addr
>> 8) & 0x1f;
1325 ret
= env
->mmuregs
[reg
];
1326 if (reg
== 3) /* Fault status cleared on read */
1327 env
->mmuregs
[3] = 0;
1328 else if (reg
== 0x13) /* Fault status read */
1329 ret
= env
->mmuregs
[3];
1330 else if (reg
== 0x14) /* Fault address read */
1331 ret
= env
->mmuregs
[4];
1332 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1335 case 5: // Turbosparc ITLB Diagnostic
1336 case 6: // Turbosparc DTLB Diagnostic
1337 case 7: // Turbosparc IOTLB Diagnostic
1339 case 9: /* Supervisor code access */
1342 ret
= ldub_code(addr
);
1345 ret
= lduw_code(addr
);
1349 ret
= ldl_code(addr
);
1352 ret
= ldq_code(addr
);
1356 case 0xa: /* User data access */
1359 ret
= ldub_user(addr
);
1362 ret
= lduw_user(addr
);
1366 ret
= ldl_user(addr
);
1369 ret
= ldq_user(addr
);
1373 case 0xb: /* Supervisor data access */
1376 ret
= ldub_kernel(addr
);
1379 ret
= lduw_kernel(addr
);
1383 ret
= ldl_kernel(addr
);
1386 ret
= ldq_kernel(addr
);
1390 case 0xc: /* I-cache tag */
1391 case 0xd: /* I-cache data */
1392 case 0xe: /* D-cache tag */
1393 case 0xf: /* D-cache data */
1395 case 0x20: /* MMU passthrough */
1398 ret
= ldub_phys(addr
);
1401 ret
= lduw_phys(addr
);
1405 ret
= ldl_phys(addr
);
1408 ret
= ldq_phys(addr
);
1412 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1415 ret
= ldub_phys((target_phys_addr_t
)addr
1416 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1419 ret
= lduw_phys((target_phys_addr_t
)addr
1420 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1424 ret
= ldl_phys((target_phys_addr_t
)addr
1425 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1428 ret
= ldq_phys((target_phys_addr_t
)addr
1429 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1433 case 0x30: // Turbosparc secondary cache diagnostic
1434 case 0x31: // Turbosparc RAM snoop
1435 case 0x32: // Turbosparc page table descriptor diagnostic
1436 case 0x39: /* data cache diagnostic register */
1439 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1441 int reg
= (addr
>> 8) & 3;
1444 case 0: /* Breakpoint Value (Addr) */
1445 ret
= env
->mmubpregs
[reg
];
1447 case 1: /* Breakpoint Mask */
1448 ret
= env
->mmubpregs
[reg
];
1450 case 2: /* Breakpoint Control */
1451 ret
= env
->mmubpregs
[reg
];
1453 case 3: /* Breakpoint Status */
1454 ret
= env
->mmubpregs
[reg
];
1455 env
->mmubpregs
[reg
] = 0ULL;
1458 DPRINTF_MMU("read breakpoint reg[%d] 0x%016llx\n", reg
, ret
);
1461 case 8: /* User code access, XXX */
1463 do_unassigned_access(addr
, 0, 0, asi
, size
);
1473 ret
= (int16_t) ret
;
1476 ret
= (int32_t) ret
;
1483 dump_asi("read ", last_addr
, asi
, size
, ret
);
1488 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1490 helper_check_align(addr
, size
- 1);
1492 case 2: /* SuperSparc MXCC registers */
1494 case 0x01c00000: /* MXCC stream data register 0 */
1496 env
->mxccdata
[0] = val
;
1498 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1501 case 0x01c00008: /* MXCC stream data register 1 */
1503 env
->mxccdata
[1] = val
;
1505 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1508 case 0x01c00010: /* MXCC stream data register 2 */
1510 env
->mxccdata
[2] = val
;
1512 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1515 case 0x01c00018: /* MXCC stream data register 3 */
1517 env
->mxccdata
[3] = val
;
1519 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1522 case 0x01c00100: /* MXCC stream source */
1524 env
->mxccregs
[0] = val
;
1526 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1528 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1530 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1532 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1534 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1537 case 0x01c00200: /* MXCC stream destination */
1539 env
->mxccregs
[1] = val
;
1541 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1543 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1545 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1547 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1549 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1552 case 0x01c00a00: /* MXCC control register */
1554 env
->mxccregs
[3] = val
;
1556 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1559 case 0x01c00a04: /* MXCC control register */
1561 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1564 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1567 case 0x01c00e00: /* MXCC error register */
1568 // writing a 1 bit clears the error
1570 env
->mxccregs
[6] &= ~val
;
1572 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1575 case 0x01c00f00: /* MBus port address register */
1577 env
->mxccregs
[7] = val
;
1579 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1583 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1587 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1588 asi
, size
, addr
, val
);
1593 case 3: /* MMU flush */
1597 mmulev
= (addr
>> 8) & 15;
1598 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1600 case 0: // flush page
1601 tlb_flush_page(env
, addr
& 0xfffff000);
1603 case 1: // flush segment (256k)
1604 case 2: // flush region (16M)
1605 case 3: // flush context (4G)
1606 case 4: // flush entire
1617 case 4: /* write MMU regs */
1619 int reg
= (addr
>> 8) & 0x1f;
1622 oldreg
= env
->mmuregs
[reg
];
1624 case 0: // Control Register
1625 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1627 // Mappings generated during no-fault mode or MMU
1628 // disabled mode are invalid in normal mode
1629 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1630 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1633 case 1: // Context Table Pointer Register
1634 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1636 case 2: // Context Register
1637 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1638 if (oldreg
!= env
->mmuregs
[reg
]) {
1639 /* we flush when the MMU context changes because
1640 QEMU has no MMU context support */
1644 case 3: // Synchronous Fault Status Register with Clear
1645 case 4: // Synchronous Fault Address Register
1647 case 0x10: // TLB Replacement Control Register
1648 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1650 case 0x13: // Synchronous Fault Status Register with Read and Clear
1651 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1653 case 0x14: // Synchronous Fault Address Register
1654 env
->mmuregs
[4] = val
;
1657 env
->mmuregs
[reg
] = val
;
1660 if (oldreg
!= env
->mmuregs
[reg
]) {
1661 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1662 reg
, oldreg
, env
->mmuregs
[reg
]);
1669 case 5: // Turbosparc ITLB Diagnostic
1670 case 6: // Turbosparc DTLB Diagnostic
1671 case 7: // Turbosparc IOTLB Diagnostic
1673 case 0xa: /* User data access */
1676 stb_user(addr
, val
);
1679 stw_user(addr
, val
);
1683 stl_user(addr
, val
);
1686 stq_user(addr
, val
);
1690 case 0xb: /* Supervisor data access */
1693 stb_kernel(addr
, val
);
1696 stw_kernel(addr
, val
);
1700 stl_kernel(addr
, val
);
1703 stq_kernel(addr
, val
);
1707 case 0xc: /* I-cache tag */
1708 case 0xd: /* I-cache data */
1709 case 0xe: /* D-cache tag */
1710 case 0xf: /* D-cache data */
1711 case 0x10: /* I/D-cache flush page */
1712 case 0x11: /* I/D-cache flush segment */
1713 case 0x12: /* I/D-cache flush region */
1714 case 0x13: /* I/D-cache flush context */
1715 case 0x14: /* I/D-cache flush user */
1717 case 0x17: /* Block copy, sta access */
1723 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1725 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1726 temp
= ldl_kernel(src
);
1727 stl_kernel(dst
, temp
);
1731 case 0x1f: /* Block fill, stda access */
1734 // fill 32 bytes with val
1736 uint32_t dst
= addr
& 7;
1738 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1739 stq_kernel(dst
, val
);
1742 case 0x20: /* MMU passthrough */
1746 stb_phys(addr
, val
);
1749 stw_phys(addr
, val
);
1753 stl_phys(addr
, val
);
1756 stq_phys(addr
, val
);
1761 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1765 stb_phys((target_phys_addr_t
)addr
1766 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1769 stw_phys((target_phys_addr_t
)addr
1770 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1774 stl_phys((target_phys_addr_t
)addr
1775 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1778 stq_phys((target_phys_addr_t
)addr
1779 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1784 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1785 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1786 // Turbosparc snoop RAM
1787 case 0x32: // store buffer control or Turbosparc page table
1788 // descriptor diagnostic
1789 case 0x36: /* I-cache flash clear */
1790 case 0x37: /* D-cache flash clear */
1791 case 0x4c: /* breakpoint action */
1793 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1795 int reg
= (addr
>> 8) & 3;
1798 case 0: /* Breakpoint Value (Addr) */
1799 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1801 case 1: /* Breakpoint Mask */
1802 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1804 case 2: /* Breakpoint Control */
1805 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1807 case 3: /* Breakpoint Status */
1808 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1811 DPRINTF_MMU("write breakpoint reg[%d] 0x%016llx\n", reg
,
1815 case 8: /* User code access, XXX */
1816 case 9: /* Supervisor code access, XXX */
1818 do_unassigned_access(addr
, 1, 0, asi
, size
);
1822 dump_asi("write", addr
, asi
, size
, val
);
1826 #endif /* CONFIG_USER_ONLY */
1827 #else /* TARGET_SPARC64 */
1829 #ifdef CONFIG_USER_ONLY
1830 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1833 #if defined(DEBUG_ASI)
1834 target_ulong last_addr
= addr
;
1838 raise_exception(TT_PRIV_ACT
);
1840 helper_check_align(addr
, size
- 1);
1841 address_mask(env
, &addr
);
1844 case 0x82: // Primary no-fault
1845 case 0x8a: // Primary no-fault LE
1846 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1848 dump_asi("read ", last_addr
, asi
, size
, ret
);
1853 case 0x80: // Primary
1854 case 0x88: // Primary LE
1858 ret
= ldub_raw(addr
);
1861 ret
= lduw_raw(addr
);
1864 ret
= ldl_raw(addr
);
1868 ret
= ldq_raw(addr
);
1873 case 0x83: // Secondary no-fault
1874 case 0x8b: // Secondary no-fault LE
1875 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1877 dump_asi("read ", last_addr
, asi
, size
, ret
);
1882 case 0x81: // Secondary
1883 case 0x89: // Secondary LE
1890 /* Convert from little endian */
1892 case 0x88: // Primary LE
1893 case 0x89: // Secondary LE
1894 case 0x8a: // Primary no-fault LE
1895 case 0x8b: // Secondary no-fault LE
1913 /* Convert to signed number */
1920 ret
= (int16_t) ret
;
1923 ret
= (int32_t) ret
;
1930 dump_asi("read ", last_addr
, asi
, size
, ret
);
1935 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1938 dump_asi("write", addr
, asi
, size
, val
);
1941 raise_exception(TT_PRIV_ACT
);
1943 helper_check_align(addr
, size
- 1);
1944 address_mask(env
, &addr
);
1946 /* Convert to little endian */
1948 case 0x88: // Primary LE
1949 case 0x89: // Secondary LE
1952 addr
= bswap16(addr
);
1955 addr
= bswap32(addr
);
1958 addr
= bswap64(addr
);
1968 case 0x80: // Primary
1969 case 0x88: // Primary LE
1988 case 0x81: // Secondary
1989 case 0x89: // Secondary LE
1993 case 0x82: // Primary no-fault, RO
1994 case 0x83: // Secondary no-fault, RO
1995 case 0x8a: // Primary no-fault LE, RO
1996 case 0x8b: // Secondary no-fault LE, RO
1998 do_unassigned_access(addr
, 1, 0, 1, size
);
2003 #else /* CONFIG_USER_ONLY */
2005 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2008 #if defined(DEBUG_ASI)
2009 target_ulong last_addr
= addr
;
2012 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2013 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2014 && asi
>= 0x30 && asi
< 0x80
2015 && !(env
->hpstate
& HS_PRIV
)))
2016 raise_exception(TT_PRIV_ACT
);
2018 helper_check_align(addr
, size
- 1);
2020 case 0x82: // Primary no-fault
2021 case 0x8a: // Primary no-fault LE
2022 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2024 dump_asi("read ", last_addr
, asi
, size
, ret
);
2029 case 0x10: // As if user primary
2030 case 0x18: // As if user primary LE
2031 case 0x80: // Primary
2032 case 0x88: // Primary LE
2033 case 0xe2: // UA2007 Primary block init
2034 case 0xe3: // UA2007 Secondary block init
2035 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2036 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2037 && env
->hpstate
& HS_PRIV
) {
2040 ret
= ldub_hypv(addr
);
2043 ret
= lduw_hypv(addr
);
2046 ret
= ldl_hypv(addr
);
2050 ret
= ldq_hypv(addr
);
2056 ret
= ldub_kernel(addr
);
2059 ret
= lduw_kernel(addr
);
2062 ret
= ldl_kernel(addr
);
2066 ret
= ldq_kernel(addr
);
2073 ret
= ldub_user(addr
);
2076 ret
= lduw_user(addr
);
2079 ret
= ldl_user(addr
);
2083 ret
= ldq_user(addr
);
2088 case 0x14: // Bypass
2089 case 0x15: // Bypass, non-cacheable
2090 case 0x1c: // Bypass LE
2091 case 0x1d: // Bypass, non-cacheable LE
2095 ret
= ldub_phys(addr
);
2098 ret
= lduw_phys(addr
);
2101 ret
= ldl_phys(addr
);
2105 ret
= ldq_phys(addr
);
2110 case 0x24: // Nucleus quad LDD 128 bit atomic
2111 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2112 // Only ldda allowed
2113 raise_exception(TT_ILL_INSN
);
2115 case 0x83: // Secondary no-fault
2116 case 0x8b: // Secondary no-fault LE
2117 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2119 dump_asi("read ", last_addr
, asi
, size
, ret
);
2124 case 0x04: // Nucleus
2125 case 0x0c: // Nucleus Little Endian (LE)
2126 case 0x11: // As if user secondary
2127 case 0x19: // As if user secondary LE
2128 case 0x4a: // UPA config
2129 case 0x81: // Secondary
2130 case 0x89: // Secondary LE
2136 case 0x50: // I-MMU regs
2138 int reg
= (addr
>> 3) & 0xf;
2141 // I-TSB Tag Target register
2142 ret
= ultrasparc_tag_target(env
->immuregs
[6]);
2144 ret
= env
->immuregs
[reg
];
2149 case 0x51: // I-MMU 8k TSB pointer
2151 // env->immuregs[5] holds I-MMU TSB register value
2152 // env->immuregs[6] holds I-MMU Tag Access register value
2153 ret
= ultrasparc_tsb_pointer(env
->immuregs
[5], env
->immuregs
[6],
2157 case 0x52: // I-MMU 64k TSB pointer
2159 // env->immuregs[5] holds I-MMU TSB register value
2160 // env->immuregs[6] holds I-MMU Tag Access register value
2161 ret
= ultrasparc_tsb_pointer(env
->immuregs
[5], env
->immuregs
[6],
2165 case 0x55: // I-MMU data access
2167 int reg
= (addr
>> 3) & 0x3f;
2169 ret
= env
->itlb_tte
[reg
];
2172 case 0x56: // I-MMU tag read
2174 int reg
= (addr
>> 3) & 0x3f;
2176 ret
= env
->itlb_tag
[reg
];
2179 case 0x58: // D-MMU regs
2181 int reg
= (addr
>> 3) & 0xf;
2184 // D-TSB Tag Target register
2185 ret
= ultrasparc_tag_target(env
->dmmuregs
[6]);
2187 ret
= env
->dmmuregs
[reg
];
2191 case 0x59: // D-MMU 8k TSB pointer
2193 // env->dmmuregs[5] holds D-MMU TSB register value
2194 // env->dmmuregs[6] holds D-MMU Tag Access register value
2195 ret
= ultrasparc_tsb_pointer(env
->dmmuregs
[5], env
->dmmuregs
[6],
2199 case 0x5a: // D-MMU 64k TSB pointer
2201 // env->dmmuregs[5] holds D-MMU TSB register value
2202 // env->dmmuregs[6] holds D-MMU Tag Access register value
2203 ret
= ultrasparc_tsb_pointer(env
->dmmuregs
[5], env
->dmmuregs
[6],
2207 case 0x5d: // D-MMU data access
2209 int reg
= (addr
>> 3) & 0x3f;
2211 ret
= env
->dtlb_tte
[reg
];
2214 case 0x5e: // D-MMU tag read
2216 int reg
= (addr
>> 3) & 0x3f;
2218 ret
= env
->dtlb_tag
[reg
];
2221 case 0x46: // D-cache data
2222 case 0x47: // D-cache tag access
2223 case 0x4b: // E-cache error enable
2224 case 0x4c: // E-cache asynchronous fault status
2225 case 0x4d: // E-cache asynchronous fault address
2226 case 0x4e: // E-cache tag data
2227 case 0x66: // I-cache instruction access
2228 case 0x67: // I-cache tag access
2229 case 0x6e: // I-cache predecode
2230 case 0x6f: // I-cache LRU etc.
2231 case 0x76: // E-cache tag
2232 case 0x7e: // E-cache tag
2234 case 0x5b: // D-MMU data pointer
2235 case 0x48: // Interrupt dispatch, RO
2236 case 0x49: // Interrupt data receive
2237 case 0x7f: // Incoming interrupt vector, RO
2240 case 0x54: // I-MMU data in, WO
2241 case 0x57: // I-MMU demap, WO
2242 case 0x5c: // D-MMU data in, WO
2243 case 0x5f: // D-MMU demap, WO
2244 case 0x77: // Interrupt vector, WO
2246 do_unassigned_access(addr
, 0, 0, 1, size
);
2251 /* Convert from little endian */
2253 case 0x0c: // Nucleus Little Endian (LE)
2254 case 0x18: // As if user primary LE
2255 case 0x19: // As if user secondary LE
2256 case 0x1c: // Bypass LE
2257 case 0x1d: // Bypass, non-cacheable LE
2258 case 0x88: // Primary LE
2259 case 0x89: // Secondary LE
2260 case 0x8a: // Primary no-fault LE
2261 case 0x8b: // Secondary no-fault LE
2279 /* Convert to signed number */
2286 ret
= (int16_t) ret
;
2289 ret
= (int32_t) ret
;
2296 dump_asi("read ", last_addr
, asi
, size
, ret
);
2301 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2304 dump_asi("write", addr
, asi
, size
, val
);
2306 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2307 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2308 && asi
>= 0x30 && asi
< 0x80
2309 && !(env
->hpstate
& HS_PRIV
)))
2310 raise_exception(TT_PRIV_ACT
);
2312 helper_check_align(addr
, size
- 1);
2313 /* Convert to little endian */
2315 case 0x0c: // Nucleus Little Endian (LE)
2316 case 0x18: // As if user primary LE
2317 case 0x19: // As if user secondary LE
2318 case 0x1c: // Bypass LE
2319 case 0x1d: // Bypass, non-cacheable LE
2320 case 0x88: // Primary LE
2321 case 0x89: // Secondary LE
2324 addr
= bswap16(addr
);
2327 addr
= bswap32(addr
);
2330 addr
= bswap64(addr
);
2340 case 0x10: // As if user primary
2341 case 0x18: // As if user primary LE
2342 case 0x80: // Primary
2343 case 0x88: // Primary LE
2344 case 0xe2: // UA2007 Primary block init
2345 case 0xe3: // UA2007 Secondary block init
2346 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2347 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2348 && env
->hpstate
& HS_PRIV
) {
2351 stb_hypv(addr
, val
);
2354 stw_hypv(addr
, val
);
2357 stl_hypv(addr
, val
);
2361 stq_hypv(addr
, val
);
2367 stb_kernel(addr
, val
);
2370 stw_kernel(addr
, val
);
2373 stl_kernel(addr
, val
);
2377 stq_kernel(addr
, val
);
2384 stb_user(addr
, val
);
2387 stw_user(addr
, val
);
2390 stl_user(addr
, val
);
2394 stq_user(addr
, val
);
2399 case 0x14: // Bypass
2400 case 0x15: // Bypass, non-cacheable
2401 case 0x1c: // Bypass LE
2402 case 0x1d: // Bypass, non-cacheable LE
2406 stb_phys(addr
, val
);
2409 stw_phys(addr
, val
);
2412 stl_phys(addr
, val
);
2416 stq_phys(addr
, val
);
2421 case 0x24: // Nucleus quad LDD 128 bit atomic
2422 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2423 // Only ldda allowed
2424 raise_exception(TT_ILL_INSN
);
2426 case 0x04: // Nucleus
2427 case 0x0c: // Nucleus Little Endian (LE)
2428 case 0x11: // As if user secondary
2429 case 0x19: // As if user secondary LE
2430 case 0x4a: // UPA config
2431 case 0x81: // Secondary
2432 case 0x89: // Secondary LE
2440 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
2441 // Mappings generated during D/I MMU disabled mode are
2442 // invalid in normal mode
2443 if (oldreg
!= env
->lsu
) {
2444 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
2453 case 0x50: // I-MMU regs
2455 int reg
= (addr
>> 3) & 0xf;
2458 oldreg
= env
->immuregs
[reg
];
2463 case 1: // Not in I-MMU
2470 val
= 0; // Clear SFSR
2472 case 5: // TSB access
2473 case 6: // Tag access
2477 env
->immuregs
[reg
] = val
;
2478 if (oldreg
!= env
->immuregs
[reg
]) {
2479 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
2480 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2487 case 0x54: // I-MMU data in
2491 // Try finding an invalid entry
2492 for (i
= 0; i
< 64; i
++) {
2493 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
2494 env
->itlb_tag
[i
] = env
->immuregs
[6];
2495 env
->itlb_tte
[i
] = val
;
2499 // Try finding an unlocked entry
2500 for (i
= 0; i
< 64; i
++) {
2501 if ((env
->itlb_tte
[i
] & 0x40) == 0) {
2502 env
->itlb_tag
[i
] = env
->immuregs
[6];
2503 env
->itlb_tte
[i
] = val
;
2510 case 0x55: // I-MMU data access
2514 unsigned int i
= (addr
>> 3) & 0x3f;
2516 env
->itlb_tag
[i
] = env
->immuregs
[6];
2517 env
->itlb_tte
[i
] = val
;
2520 case 0x57: // I-MMU demap
2524 for (i
= 0; i
< 64; i
++) {
2525 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
2526 target_ulong mask
= 0xffffffffffffe000ULL
;
2528 mask
<<= 3 * ((env
->itlb_tte
[i
] >> 61) & 3);
2529 if ((val
& mask
) == (env
->itlb_tag
[i
] & mask
)) {
2530 env
->itlb_tag
[i
] = 0;
2531 env
->itlb_tte
[i
] = 0;
2538 case 0x58: // D-MMU regs
2540 int reg
= (addr
>> 3) & 0xf;
2543 oldreg
= env
->dmmuregs
[reg
];
2549 if ((val
& 1) == 0) {
2550 val
= 0; // Clear SFSR, Fault address
2551 env
->dmmuregs
[4] = 0;
2553 env
->dmmuregs
[reg
] = val
;
2555 case 1: // Primary context
2556 case 2: // Secondary context
2557 case 5: // TSB access
2558 case 6: // Tag access
2559 case 7: // Virtual Watchpoint
2560 case 8: // Physical Watchpoint
2564 env
->dmmuregs
[reg
] = val
;
2565 if (oldreg
!= env
->dmmuregs
[reg
]) {
2566 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
2567 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2574 case 0x5c: // D-MMU data in
2578 // Try finding an invalid entry
2579 for (i
= 0; i
< 64; i
++) {
2580 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
2581 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2582 env
->dtlb_tte
[i
] = val
;
2586 // Try finding an unlocked entry
2587 for (i
= 0; i
< 64; i
++) {
2588 if ((env
->dtlb_tte
[i
] & 0x40) == 0) {
2589 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2590 env
->dtlb_tte
[i
] = val
;
2597 case 0x5d: // D-MMU data access
2599 unsigned int i
= (addr
>> 3) & 0x3f;
2601 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2602 env
->dtlb_tte
[i
] = val
;
2605 case 0x5f: // D-MMU demap
2609 for (i
= 0; i
< 64; i
++) {
2610 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
2611 target_ulong mask
= 0xffffffffffffe000ULL
;
2613 mask
<<= 3 * ((env
->dtlb_tte
[i
] >> 61) & 3);
2614 if ((val
& mask
) == (env
->dtlb_tag
[i
] & mask
)) {
2615 env
->dtlb_tag
[i
] = 0;
2616 env
->dtlb_tte
[i
] = 0;
2623 case 0x49: // Interrupt data receive
2626 case 0x46: // D-cache data
2627 case 0x47: // D-cache tag access
2628 case 0x4b: // E-cache error enable
2629 case 0x4c: // E-cache asynchronous fault status
2630 case 0x4d: // E-cache asynchronous fault address
2631 case 0x4e: // E-cache tag data
2632 case 0x66: // I-cache instruction access
2633 case 0x67: // I-cache tag access
2634 case 0x6e: // I-cache predecode
2635 case 0x6f: // I-cache LRU etc.
2636 case 0x76: // E-cache tag
2637 case 0x7e: // E-cache tag
2639 case 0x51: // I-MMU 8k TSB pointer, RO
2640 case 0x52: // I-MMU 64k TSB pointer, RO
2641 case 0x56: // I-MMU tag read, RO
2642 case 0x59: // D-MMU 8k TSB pointer, RO
2643 case 0x5a: // D-MMU 64k TSB pointer, RO
2644 case 0x5b: // D-MMU data pointer, RO
2645 case 0x5e: // D-MMU tag read, RO
2646 case 0x48: // Interrupt dispatch, RO
2647 case 0x7f: // Incoming interrupt vector, RO
2648 case 0x82: // Primary no-fault, RO
2649 case 0x83: // Secondary no-fault, RO
2650 case 0x8a: // Primary no-fault LE, RO
2651 case 0x8b: // Secondary no-fault LE, RO
2653 do_unassigned_access(addr
, 1, 0, 1, size
);
2657 #endif /* CONFIG_USER_ONLY */
2659 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2661 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2662 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2663 && asi
>= 0x30 && asi
< 0x80
2664 && !(env
->hpstate
& HS_PRIV
)))
2665 raise_exception(TT_PRIV_ACT
);
2668 case 0x24: // Nucleus quad LDD 128 bit atomic
2669 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2670 helper_check_align(addr
, 0xf);
2672 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2674 bswap64s(&env
->gregs
[1]);
2675 } else if (rd
< 8) {
2676 env
->gregs
[rd
] = ldq_kernel(addr
);
2677 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2679 bswap64s(&env
->gregs
[rd
]);
2680 bswap64s(&env
->gregs
[rd
+ 1]);
2683 env
->regwptr
[rd
] = ldq_kernel(addr
);
2684 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2686 bswap64s(&env
->regwptr
[rd
]);
2687 bswap64s(&env
->regwptr
[rd
+ 1]);
2692 helper_check_align(addr
, 0x3);
2694 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2696 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2697 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2699 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2700 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2706 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2711 helper_check_align(addr
, 3);
2713 case 0xf0: // Block load primary
2714 case 0xf1: // Block load secondary
2715 case 0xf8: // Block load primary LE
2716 case 0xf9: // Block load secondary LE
2718 raise_exception(TT_ILL_INSN
);
2721 helper_check_align(addr
, 0x3f);
2722 for (i
= 0; i
< 16; i
++) {
2723 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2733 val
= helper_ld_asi(addr
, asi
, size
, 0);
2737 *((uint32_t *)&env
->fpr
[rd
]) = val
;
2740 *((int64_t *)&DT0
) = val
;
2748 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2751 target_ulong val
= 0;
2753 helper_check_align(addr
, 3);
2755 case 0xe0: // UA2007 Block commit store primary (cache flush)
2756 case 0xe1: // UA2007 Block commit store secondary (cache flush)
2757 case 0xf0: // Block store primary
2758 case 0xf1: // Block store secondary
2759 case 0xf8: // Block store primary LE
2760 case 0xf9: // Block store secondary LE
2762 raise_exception(TT_ILL_INSN
);
2765 helper_check_align(addr
, 0x3f);
2766 for (i
= 0; i
< 16; i
++) {
2767 val
= *(uint32_t *)&env
->fpr
[rd
++];
2768 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2780 val
= *((uint32_t *)&env
->fpr
[rd
]);
2783 val
= *((int64_t *)&DT0
);
2789 helper_st_asi(addr
, val
, asi
, size
);
2792 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2793 target_ulong val2
, uint32_t asi
)
2797 val2
&= 0xffffffffUL
;
2798 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2799 ret
&= 0xffffffffUL
;
2801 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
2805 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2806 target_ulong val2
, uint32_t asi
)
2810 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2812 helper_st_asi(addr
, val1
, asi
, 8);
2815 #endif /* TARGET_SPARC64 */
2817 #ifndef TARGET_SPARC64
2818 void helper_rett(void)
2822 if (env
->psret
== 1)
2823 raise_exception(TT_ILL_INSN
);
2826 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2827 if (env
->wim
& (1 << cwp
)) {
2828 raise_exception(TT_WIN_UNF
);
2831 env
->psrs
= env
->psrps
;
2835 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2840 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2844 raise_exception(TT_DIV_ZERO
);
2848 if (x0
> 0xffffffff) {
2857 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2862 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2866 raise_exception(TT_DIV_ZERO
);
2870 if ((int32_t) x0
!= x0
) {
2872 return x0
< 0? 0x80000000: 0x7fffffff;
2879 void helper_stdf(target_ulong addr
, int mem_idx
)
2881 helper_check_align(addr
, 7);
2882 #if !defined(CONFIG_USER_ONLY)
2885 stfq_user(addr
, DT0
);
2888 stfq_kernel(addr
, DT0
);
2890 #ifdef TARGET_SPARC64
2892 stfq_hypv(addr
, DT0
);
2899 address_mask(env
, &addr
);
2900 stfq_raw(addr
, DT0
);
2904 void helper_lddf(target_ulong addr
, int mem_idx
)
2906 helper_check_align(addr
, 7);
2907 #if !defined(CONFIG_USER_ONLY)
2910 DT0
= ldfq_user(addr
);
2913 DT0
= ldfq_kernel(addr
);
2915 #ifdef TARGET_SPARC64
2917 DT0
= ldfq_hypv(addr
);
2924 address_mask(env
, &addr
);
2925 DT0
= ldfq_raw(addr
);
2929 void helper_ldqf(target_ulong addr
, int mem_idx
)
2931 // XXX add 128 bit load
2934 helper_check_align(addr
, 7);
2935 #if !defined(CONFIG_USER_ONLY)
2938 u
.ll
.upper
= ldq_user(addr
);
2939 u
.ll
.lower
= ldq_user(addr
+ 8);
2943 u
.ll
.upper
= ldq_kernel(addr
);
2944 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2947 #ifdef TARGET_SPARC64
2949 u
.ll
.upper
= ldq_hypv(addr
);
2950 u
.ll
.lower
= ldq_hypv(addr
+ 8);
2958 address_mask(env
, &addr
);
2959 u
.ll
.upper
= ldq_raw(addr
);
2960 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
2965 void helper_stqf(target_ulong addr
, int mem_idx
)
2967 // XXX add 128 bit store
2970 helper_check_align(addr
, 7);
2971 #if !defined(CONFIG_USER_ONLY)
2975 stq_user(addr
, u
.ll
.upper
);
2976 stq_user(addr
+ 8, u
.ll
.lower
);
2980 stq_kernel(addr
, u
.ll
.upper
);
2981 stq_kernel(addr
+ 8, u
.ll
.lower
);
2983 #ifdef TARGET_SPARC64
2986 stq_hypv(addr
, u
.ll
.upper
);
2987 stq_hypv(addr
+ 8, u
.ll
.lower
);
2995 address_mask(env
, &addr
);
2996 stq_raw(addr
, u
.ll
.upper
);
2997 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
3001 static inline void set_fsr(void)
3005 switch (env
->fsr
& FSR_RD_MASK
) {
3006 case FSR_RD_NEAREST
:
3007 rnd_mode
= float_round_nearest_even
;
3011 rnd_mode
= float_round_to_zero
;
3014 rnd_mode
= float_round_up
;
3017 rnd_mode
= float_round_down
;
3020 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3023 void helper_ldfsr(uint32_t new_fsr
)
3025 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3029 #ifdef TARGET_SPARC64
3030 void helper_ldxfsr(uint64_t new_fsr
)
3032 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3037 void helper_debug(void)
3039 env
->exception_index
= EXCP_DEBUG
;
3043 #ifndef TARGET_SPARC64
3044 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3046 void helper_save(void)
3050 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3051 if (env
->wim
& (1 << cwp
)) {
3052 raise_exception(TT_WIN_OVF
);
3057 void helper_restore(void)
3061 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3062 if (env
->wim
& (1 << cwp
)) {
3063 raise_exception(TT_WIN_UNF
);
3068 void helper_wrpsr(target_ulong new_psr
)
3070 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
3071 raise_exception(TT_ILL_INSN
);
3073 PUT_PSR(env
, new_psr
);
3076 target_ulong
helper_rdpsr(void)
3078 return GET_PSR(env
);
3082 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3084 void helper_save(void)
3088 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3089 if (env
->cansave
== 0) {
3090 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3091 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3092 ((env
->wstate
& 0x7) << 2)));
3094 if (env
->cleanwin
- env
->canrestore
== 0) {
3095 // XXX Clean windows without trap
3096 raise_exception(TT_CLRWIN
);
3105 void helper_restore(void)
3109 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3110 if (env
->canrestore
== 0) {
3111 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3112 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3113 ((env
->wstate
& 0x7) << 2)));
3121 void helper_flushw(void)
3123 if (env
->cansave
!= env
->nwindows
- 2) {
3124 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3125 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3126 ((env
->wstate
& 0x7) << 2)));
3130 void helper_saved(void)
3133 if (env
->otherwin
== 0)
3139 void helper_restored(void)
3142 if (env
->cleanwin
< env
->nwindows
- 1)
3144 if (env
->otherwin
== 0)
3150 target_ulong
helper_rdccr(void)
3152 return GET_CCR(env
);
3155 void helper_wrccr(target_ulong new_ccr
)
3157 PUT_CCR(env
, new_ccr
);
3160 // CWP handling is reversed in V9, but we still use the V8 register
3162 target_ulong
helper_rdcwp(void)
3164 return GET_CWP64(env
);
3167 void helper_wrcwp(target_ulong new_cwp
)
3169 PUT_CWP64(env
, new_cwp
);
3172 // This function uses non-native bit order
3173 #define GET_FIELD(X, FROM, TO) \
3174 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3176 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3177 #define GET_FIELD_SP(X, FROM, TO) \
3178 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3180 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3182 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3183 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3184 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3185 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3186 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3187 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3188 (((pixel_addr
>> 55) & 1) << 4) |
3189 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3190 GET_FIELD_SP(pixel_addr
, 11, 12);
3193 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3197 tmp
= addr
+ offset
;
3199 env
->gsr
|= tmp
& 7ULL;
3203 target_ulong
helper_popc(target_ulong val
)
3205 return ctpop64(val
);
3208 static inline uint64_t *get_gregset(uint64_t pstate
)
3223 static inline void change_pstate(uint64_t new_pstate
)
3225 uint64_t pstate_regs
, new_pstate_regs
;
3226 uint64_t *src
, *dst
;
3228 pstate_regs
= env
->pstate
& 0xc01;
3229 new_pstate_regs
= new_pstate
& 0xc01;
3230 if (new_pstate_regs
!= pstate_regs
) {
3231 // Switch global register bank
3232 src
= get_gregset(new_pstate_regs
);
3233 dst
= get_gregset(pstate_regs
);
3234 memcpy32(dst
, env
->gregs
);
3235 memcpy32(env
->gregs
, src
);
3237 env
->pstate
= new_pstate
;
3240 void helper_wrpstate(target_ulong new_state
)
3242 if (!(env
->def
->features
& CPU_FEATURE_GL
))
3243 change_pstate(new_state
& 0xf3f);
3246 void helper_done(void)
3248 env
->pc
= env
->tsptr
->tpc
;
3249 env
->npc
= env
->tsptr
->tnpc
+ 4;
3250 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
3251 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
3252 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
3253 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
3255 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
3258 void helper_retry(void)
3260 env
->pc
= env
->tsptr
->tpc
;
3261 env
->npc
= env
->tsptr
->tnpc
;
3262 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
3263 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
3264 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
3265 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
3267 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
3270 void helper_set_softint(uint64_t value
)
3272 env
->softint
|= (uint32_t)value
;
3275 void helper_clear_softint(uint64_t value
)
3277 env
->softint
&= (uint32_t)~value
;
3280 void helper_write_softint(uint64_t value
)
3282 env
->softint
= (uint32_t)value
;
3286 void helper_flush(target_ulong addr
)
3289 tb_invalidate_page_range(addr
, addr
+ 8);
3292 #ifdef TARGET_SPARC64
3294 static const char * const excp_names
[0x80] = {
3295 [TT_TFAULT
] = "Instruction Access Fault",
3296 [TT_TMISS
] = "Instruction Access MMU Miss",
3297 [TT_CODE_ACCESS
] = "Instruction Access Error",
3298 [TT_ILL_INSN
] = "Illegal Instruction",
3299 [TT_PRIV_INSN
] = "Privileged Instruction",
3300 [TT_NFPU_INSN
] = "FPU Disabled",
3301 [TT_FP_EXCP
] = "FPU Exception",
3302 [TT_TOVF
] = "Tag Overflow",
3303 [TT_CLRWIN
] = "Clean Windows",
3304 [TT_DIV_ZERO
] = "Division By Zero",
3305 [TT_DFAULT
] = "Data Access Fault",
3306 [TT_DMISS
] = "Data Access MMU Miss",
3307 [TT_DATA_ACCESS
] = "Data Access Error",
3308 [TT_DPROT
] = "Data Protection Error",
3309 [TT_UNALIGNED
] = "Unaligned Memory Access",
3310 [TT_PRIV_ACT
] = "Privileged Action",
3311 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3312 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3313 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3314 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3315 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3316 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3317 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3318 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3319 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3320 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3321 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3322 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3323 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3324 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3325 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3329 void do_interrupt(CPUState
*env
)
3331 int intno
= env
->exception_index
;
3334 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3338 if (intno
< 0 || intno
>= 0x180)
3340 else if (intno
>= 0x100)
3341 name
= "Trap Instruction";
3342 else if (intno
>= 0xc0)
3343 name
= "Window Fill";
3344 else if (intno
>= 0x80)
3345 name
= "Window Spill";
3347 name
= excp_names
[intno
];
3352 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
3353 " SP=%016" PRIx64
"\n",
3356 env
->npc
, env
->regwptr
[6]);
3357 log_cpu_state(env
, 0);
3364 ptr
= (uint8_t *)env
->pc
;
3365 for(i
= 0; i
< 16; i
++) {
3366 qemu_log(" %02x", ldub(ptr
+ i
));
3374 #if !defined(CONFIG_USER_ONLY)
3375 if (env
->tl
>= env
->maxtl
) {
3376 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
3377 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
3381 if (env
->tl
< env
->maxtl
- 1) {
3384 env
->pstate
|= PS_RED
;
3385 if (env
->tl
< env
->maxtl
)
3388 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
3389 env
->tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
3390 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
3392 env
->tsptr
->tpc
= env
->pc
;
3393 env
->tsptr
->tnpc
= env
->npc
;
3394 env
->tsptr
->tt
= intno
;
3395 if (!(env
->def
->features
& CPU_FEATURE_GL
)) {
3398 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
3405 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
3408 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
3412 if (intno
== TT_CLRWIN
)
3413 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
3414 else if ((intno
& 0x1c0) == TT_SPILL
)
3415 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
3416 else if ((intno
& 0x1c0) == TT_FILL
)
3417 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
3418 env
->tbr
&= ~0x7fffULL
;
3419 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
3421 env
->npc
= env
->pc
+ 4;
3422 env
->exception_index
= 0;
3426 static const char * const excp_names
[0x80] = {
3427 [TT_TFAULT
] = "Instruction Access Fault",
3428 [TT_ILL_INSN
] = "Illegal Instruction",
3429 [TT_PRIV_INSN
] = "Privileged Instruction",
3430 [TT_NFPU_INSN
] = "FPU Disabled",
3431 [TT_WIN_OVF
] = "Window Overflow",
3432 [TT_WIN_UNF
] = "Window Underflow",
3433 [TT_UNALIGNED
] = "Unaligned Memory Access",
3434 [TT_FP_EXCP
] = "FPU Exception",
3435 [TT_DFAULT
] = "Data Access Fault",
3436 [TT_TOVF
] = "Tag Overflow",
3437 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3438 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3439 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3440 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3441 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3442 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3443 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3444 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3445 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3446 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3447 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3448 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3449 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3450 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3451 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3452 [TT_TOVF
] = "Tag Overflow",
3453 [TT_CODE_ACCESS
] = "Instruction Access Error",
3454 [TT_DATA_ACCESS
] = "Data Access Error",
3455 [TT_DIV_ZERO
] = "Division By Zero",
3456 [TT_NCP_INSN
] = "Coprocessor Disabled",
3460 void do_interrupt(CPUState
*env
)
3462 int cwp
, intno
= env
->exception_index
;
3465 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3469 if (intno
< 0 || intno
>= 0x100)
3471 else if (intno
>= 0x80)
3472 name
= "Trap Instruction";
3474 name
= excp_names
[intno
];
3479 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
3482 env
->npc
, env
->regwptr
[6]);
3483 log_cpu_state(env
, 0);
3490 ptr
= (uint8_t *)env
->pc
;
3491 for(i
= 0; i
< 16; i
++) {
3492 qemu_log(" %02x", ldub(ptr
+ i
));
3500 #if !defined(CONFIG_USER_ONLY)
3501 if (env
->psret
== 0) {
3502 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
3503 env
->exception_index
);
3508 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3509 cpu_set_cwp(env
, cwp
);
3510 env
->regwptr
[9] = env
->pc
;
3511 env
->regwptr
[10] = env
->npc
;
3512 env
->psrps
= env
->psrs
;
3514 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
3516 env
->npc
= env
->pc
+ 4;
3517 env
->exception_index
= 0;
3521 #if !defined(CONFIG_USER_ONLY)
3523 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3526 #define MMUSUFFIX _mmu
3527 #define ALIGNED_ONLY
3530 #include "softmmu_template.h"
3533 #include "softmmu_template.h"
3536 #include "softmmu_template.h"
3539 #include "softmmu_template.h"
3541 /* XXX: make it generic ? */
3542 static void cpu_restore_state2(void *retaddr
)
3544 TranslationBlock
*tb
;
3548 /* now we have a real cpu fault */
3549 pc
= (unsigned long)retaddr
;
3550 tb
= tb_find_pc(pc
);
3552 /* the PC is inside the translated code. It means that we have
3553 a virtual CPU fault */
3554 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
3559 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3562 #ifdef DEBUG_UNALIGNED
3563 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3564 "\n", addr
, env
->pc
);
3566 cpu_restore_state2(retaddr
);
3567 raise_exception(TT_UNALIGNED
);
3570 /* try to fill the TLB and return an exception if error. If retaddr is
3571 NULL, it means that the function was called in C code (i.e. not
3572 from generated code or from helper.c) */
3573 /* XXX: fix it to restore all registers */
3574 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3577 CPUState
*saved_env
;
3579 /* XXX: hack to restore env in all cases, even if not called from
3582 env
= cpu_single_env
;
3584 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3586 cpu_restore_state2(retaddr
);
3594 #ifndef TARGET_SPARC64
3595 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3596 int is_asi
, int size
)
3598 CPUState
*saved_env
;
3600 /* XXX: hack to restore env in all cases, even if not called from
3603 env
= cpu_single_env
;
3604 #ifdef DEBUG_UNASSIGNED
3606 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3607 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3608 is_exec
? "exec" : is_write
? "write" : "read", size
,
3609 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
3611 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3612 " from " TARGET_FMT_lx
"\n",
3613 is_exec
? "exec" : is_write
? "write" : "read", size
,
3614 size
== 1 ? "" : "s", addr
, env
->pc
);
3616 if (env
->mmuregs
[3]) /* Fault status register */
3617 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
3619 env
->mmuregs
[3] |= 1 << 16;
3621 env
->mmuregs
[3] |= 1 << 5;
3623 env
->mmuregs
[3] |= 1 << 6;
3625 env
->mmuregs
[3] |= 1 << 7;
3626 env
->mmuregs
[3] |= (5 << 2) | 2;
3627 env
->mmuregs
[4] = addr
; /* Fault address register */
3628 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3630 raise_exception(TT_CODE_ACCESS
);
3632 raise_exception(TT_DATA_ACCESS
);
3637 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3638 int is_asi
, int size
)
3640 #ifdef DEBUG_UNASSIGNED
3641 CPUState
*saved_env
;
3643 /* XXX: hack to restore env in all cases, even if not called from
3646 env
= cpu_single_env
;
3647 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3648 "\n", addr
, env
->pc
);
3652 raise_exception(TT_CODE_ACCESS
);
3654 raise_exception(TT_DATA_ACCESS
);
3658 #ifdef TARGET_SPARC64
3659 void helper_tick_set_count(void *opaque
, uint64_t count
)
3661 #if !defined(CONFIG_USER_ONLY)
3662 cpu_tick_set_count(opaque
, count
);
3666 uint64_t helper_tick_get_count(void *opaque
)
3668 #if !defined(CONFIG_USER_ONLY)
3669 return cpu_tick_get_count(opaque
);
3675 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
3677 #if !defined(CONFIG_USER_ONLY)
3678 cpu_tick_set_limit(opaque
, limit
);