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
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
50 int tsb_size
= tsb_register
& 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);
90 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
91 uint64_t tlb_tag
, uint64_t tlb_tte
,
94 target_ulong mask
, size
, va
, offset
;
96 // flush page range if translation is valid
97 if (TTE_IS_VALID(tlb
->tte
)) {
99 mask
= 0xffffffffffffe000ULL
;
100 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
103 va
= tlb
->tag
& mask
;
105 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
106 tlb_flush_page(env1
, va
+ offset
);
114 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
115 const char* strmmu
, CPUState
*env1
)
120 for (i
= 0; i
< 64; i
++) {
121 if (TTE_IS_VALID(tlb
[i
].tte
)) {
123 mask
= 0xffffffffffffe000ULL
;
124 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
126 if ((demap_addr
& mask
) == (tlb
[i
].tag
& mask
)) {
127 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
129 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
139 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
140 uint64_t tlb_tag
, uint64_t tlb_tte
,
141 const char* strmmu
, CPUState
*env1
)
143 unsigned int i
, replace_used
;
145 // Try replacing invalid entry
146 for (i
= 0; i
< 64; i
++) {
147 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
148 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
150 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
157 // All entries are valid, try replacing unlocked entry
159 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
161 // Used entries are not replaced on first pass
163 for (i
= 0; i
< 64; i
++) {
164 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
166 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
168 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
169 strmmu
, (replace_used
?"used":"unused"), i
);
176 // Now reset used bit and search for unused entries again
178 for (i
= 0; i
< 64; i
++) {
179 TTE_SET_UNUSED(tlb
[i
].tte
);
184 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
191 static inline void address_mask(CPUState
*env1
, target_ulong
*addr
)
193 #ifdef TARGET_SPARC64
195 *addr
&= 0xffffffffULL
;
199 static void raise_exception(int tt
)
201 env
->exception_index
= tt
;
205 void HELPER(raise_exception
)(int tt
)
210 static inline void set_cwp(int new_cwp
)
212 cpu_set_cwp(env
, new_cwp
);
215 void helper_check_align(target_ulong addr
, uint32_t align
)
218 #ifdef DEBUG_UNALIGNED
219 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
220 "\n", addr
, env
->pc
);
222 raise_exception(TT_UNALIGNED
);
226 #define F_HELPER(name, p) void helper_f##name##p(void)
228 #define F_BINOP(name) \
229 float32 helper_f ## name ## s (float32 src1, float32 src2) \
231 return float32_ ## name (src1, src2, &env->fp_status); \
235 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
239 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
248 void helper_fsmuld(float32 src1
, float32 src2
)
250 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
251 float32_to_float64(src2
, &env
->fp_status
),
255 void helper_fdmulq(void)
257 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
258 float64_to_float128(DT1
, &env
->fp_status
),
262 float32
helper_fnegs(float32 src
)
264 return float32_chs(src
);
267 #ifdef TARGET_SPARC64
270 DT0
= float64_chs(DT1
);
275 QT0
= float128_chs(QT1
);
279 /* Integer to float conversion. */
280 float32
helper_fitos(int32_t src
)
282 return int32_to_float32(src
, &env
->fp_status
);
285 void helper_fitod(int32_t src
)
287 DT0
= int32_to_float64(src
, &env
->fp_status
);
290 void helper_fitoq(int32_t src
)
292 QT0
= int32_to_float128(src
, &env
->fp_status
);
295 #ifdef TARGET_SPARC64
296 float32
helper_fxtos(void)
298 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
303 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
308 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
313 /* floating point conversion */
314 float32
helper_fdtos(void)
316 return float64_to_float32(DT1
, &env
->fp_status
);
319 void helper_fstod(float32 src
)
321 DT0
= float32_to_float64(src
, &env
->fp_status
);
324 float32
helper_fqtos(void)
326 return float128_to_float32(QT1
, &env
->fp_status
);
329 void helper_fstoq(float32 src
)
331 QT0
= float32_to_float128(src
, &env
->fp_status
);
334 void helper_fqtod(void)
336 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
339 void helper_fdtoq(void)
341 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
344 /* Float to integer conversion. */
345 int32_t helper_fstoi(float32 src
)
347 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
350 int32_t helper_fdtoi(void)
352 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
355 int32_t helper_fqtoi(void)
357 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
360 #ifdef TARGET_SPARC64
361 void helper_fstox(float32 src
)
363 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
366 void helper_fdtox(void)
368 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
371 void helper_fqtox(void)
373 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
376 void helper_faligndata(void)
380 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
381 /* on many architectures a shift of 64 does nothing */
382 if ((env
->gsr
& 7) != 0) {
383 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
385 *((uint64_t *)&DT0
) = tmp
;
388 #ifdef HOST_WORDS_BIGENDIAN
389 #define VIS_B64(n) b[7 - (n)]
390 #define VIS_W64(n) w[3 - (n)]
391 #define VIS_SW64(n) sw[3 - (n)]
392 #define VIS_L64(n) l[1 - (n)]
393 #define VIS_B32(n) b[3 - (n)]
394 #define VIS_W32(n) w[1 - (n)]
396 #define VIS_B64(n) b[n]
397 #define VIS_W64(n) w[n]
398 #define VIS_SW64(n) sw[n]
399 #define VIS_L64(n) l[n]
400 #define VIS_B32(n) b[n]
401 #define VIS_W32(n) w[n]
419 void helper_fpmerge(void)
426 // Reverse calculation order to handle overlap
427 d
.VIS_B64(7) = s
.VIS_B64(3);
428 d
.VIS_B64(6) = d
.VIS_B64(3);
429 d
.VIS_B64(5) = s
.VIS_B64(2);
430 d
.VIS_B64(4) = d
.VIS_B64(2);
431 d
.VIS_B64(3) = s
.VIS_B64(1);
432 d
.VIS_B64(2) = d
.VIS_B64(1);
433 d
.VIS_B64(1) = s
.VIS_B64(0);
434 //d.VIS_B64(0) = d.VIS_B64(0);
439 void helper_fmul8x16(void)
448 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
449 if ((tmp & 0xff) > 0x7f) \
451 d.VIS_W64(r) = tmp >> 8;
462 void helper_fmul8x16al(void)
471 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
472 if ((tmp & 0xff) > 0x7f) \
474 d.VIS_W64(r) = tmp >> 8;
485 void helper_fmul8x16au(void)
494 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
495 if ((tmp & 0xff) > 0x7f) \
497 d.VIS_W64(r) = tmp >> 8;
508 void helper_fmul8sux16(void)
517 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
518 if ((tmp & 0xff) > 0x7f) \
520 d.VIS_W64(r) = tmp >> 8;
531 void helper_fmul8ulx16(void)
540 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
541 if ((tmp & 0xff) > 0x7f) \
543 d.VIS_W64(r) = tmp >> 8;
554 void helper_fmuld8sux16(void)
563 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
564 if ((tmp & 0xff) > 0x7f) \
568 // Reverse calculation order to handle overlap
576 void helper_fmuld8ulx16(void)
585 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
586 if ((tmp & 0xff) > 0x7f) \
590 // Reverse calculation order to handle overlap
598 void helper_fexpand(void)
603 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
605 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
606 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
607 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
608 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
613 #define VIS_HELPER(name, F) \
614 void name##16(void) \
621 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
622 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
623 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
624 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
629 uint32_t name##16s(uint32_t src1, uint32_t src2) \
636 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
637 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
642 void name##32(void) \
649 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
650 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
655 uint32_t name##32s(uint32_t src1, uint32_t src2) \
667 #define FADD(a, b) ((a) + (b))
668 #define FSUB(a, b) ((a) - (b))
669 VIS_HELPER(helper_fpadd
, FADD
)
670 VIS_HELPER(helper_fpsub
, FSUB
)
672 #define VIS_CMPHELPER(name, F) \
673 void name##16(void) \
680 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
681 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
682 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
683 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
688 void name##32(void) \
695 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
696 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
701 #define FCMPGT(a, b) ((a) > (b))
702 #define FCMPEQ(a, b) ((a) == (b))
703 #define FCMPLE(a, b) ((a) <= (b))
704 #define FCMPNE(a, b) ((a) != (b))
706 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
707 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
708 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
709 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
712 void helper_check_ieee_exceptions(void)
716 status
= get_float_exception_flags(&env
->fp_status
);
718 /* Copy IEEE 754 flags into FSR */
719 if (status
& float_flag_invalid
)
721 if (status
& float_flag_overflow
)
723 if (status
& float_flag_underflow
)
725 if (status
& float_flag_divbyzero
)
727 if (status
& float_flag_inexact
)
730 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
731 /* Unmasked exception, generate a trap */
732 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
733 raise_exception(TT_FP_EXCP
);
735 /* Accumulate exceptions */
736 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
741 void helper_clear_float_exceptions(void)
743 set_float_exception_flags(0, &env
->fp_status
);
746 float32
helper_fabss(float32 src
)
748 return float32_abs(src
);
751 #ifdef TARGET_SPARC64
752 void helper_fabsd(void)
754 DT0
= float64_abs(DT1
);
757 void helper_fabsq(void)
759 QT0
= float128_abs(QT1
);
763 float32
helper_fsqrts(float32 src
)
765 return float32_sqrt(src
, &env
->fp_status
);
768 void helper_fsqrtd(void)
770 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
773 void helper_fsqrtq(void)
775 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
778 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
779 void glue(helper_, name) (void) \
781 target_ulong new_fsr; \
783 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
784 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
785 case float_relation_unordered: \
786 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
787 if ((env->fsr & FSR_NVM) || TRAP) { \
788 env->fsr |= new_fsr; \
789 env->fsr |= FSR_NVC; \
790 env->fsr |= FSR_FTT_IEEE_EXCP; \
791 raise_exception(TT_FP_EXCP); \
793 env->fsr |= FSR_NVA; \
796 case float_relation_less: \
797 new_fsr = FSR_FCC0 << FS; \
799 case float_relation_greater: \
800 new_fsr = FSR_FCC1 << FS; \
806 env->fsr |= new_fsr; \
808 #define GEN_FCMPS(name, size, FS, TRAP) \
809 void glue(helper_, name)(float32 src1, float32 src2) \
811 target_ulong new_fsr; \
813 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
814 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
815 case float_relation_unordered: \
816 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
817 if ((env->fsr & FSR_NVM) || TRAP) { \
818 env->fsr |= new_fsr; \
819 env->fsr |= FSR_NVC; \
820 env->fsr |= FSR_FTT_IEEE_EXCP; \
821 raise_exception(TT_FP_EXCP); \
823 env->fsr |= FSR_NVA; \
826 case float_relation_less: \
827 new_fsr = FSR_FCC0 << FS; \
829 case float_relation_greater: \
830 new_fsr = FSR_FCC1 << FS; \
836 env->fsr |= new_fsr; \
839 GEN_FCMPS(fcmps
, float32
, 0, 0);
840 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
842 GEN_FCMPS(fcmpes
, float32
, 0, 1);
843 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
845 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
846 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
848 static uint32_t compute_all_flags(void)
850 return env
->psr
& PSR_ICC
;
853 static uint32_t compute_C_flags(void)
855 return env
->psr
& PSR_CARRY
;
858 static inline uint32_t get_NZ_icc(target_ulong dst
)
862 if (!(dst
& 0xffffffffULL
))
864 if ((int32_t) (dst
& 0xffffffffULL
) < 0)
869 #ifdef TARGET_SPARC64
870 static uint32_t compute_all_flags_xcc(void)
872 return env
->xcc
& PSR_ICC
;
875 static uint32_t compute_C_flags_xcc(void)
877 return env
->xcc
& PSR_CARRY
;
880 static inline uint32_t get_NZ_xcc(target_ulong dst
)
886 if ((int64_t)dst
< 0)
892 static inline uint32_t get_V_div_icc(target_ulong src2
)
901 static uint32_t compute_all_div(void)
905 ret
= get_NZ_icc(CC_DST
);
906 ret
|= get_V_div_icc(CC_SRC2
);
910 static uint32_t compute_C_div(void)
915 /* carry = (src1[31] & src2[31]) | ( ~dst[31] & (src1[31] | src2[31])) */
916 static inline uint32_t get_C_add_icc(target_ulong dst
, target_ulong src1
,
921 if (((src1
& (1ULL << 31)) & (src2
& (1ULL << 31)))
922 | ((~(dst
& (1ULL << 31)))
923 & ((src1
& (1ULL << 31)) | (src2
& (1ULL << 31)))))
928 static inline uint32_t get_V_add_icc(target_ulong dst
, target_ulong src1
,
933 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 31))
938 #ifdef TARGET_SPARC64
939 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
948 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
953 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63))
958 static uint32_t compute_all_add_xcc(void)
962 ret
= get_NZ_xcc(CC_DST
);
963 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
964 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
968 static uint32_t compute_C_add_xcc(void)
970 return get_C_add_xcc(CC_DST
, CC_SRC
);
974 static uint32_t compute_all_add(void)
978 ret
= get_NZ_icc(CC_DST
);
979 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
980 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
984 static uint32_t compute_C_add(void)
986 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
989 #ifdef TARGET_SPARC64
990 static uint32_t compute_all_addx_xcc(void)
994 ret
= get_NZ_xcc(CC_DST
);
995 ret
|= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
996 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
997 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1001 static uint32_t compute_C_addx_xcc(void)
1005 ret
= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1006 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1011 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1015 if ((src1
| src2
) & 0x3)
1020 static uint32_t compute_all_tadd(void)
1024 ret
= get_NZ_icc(CC_DST
);
1025 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1026 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1027 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1031 static uint32_t compute_C_tadd(void)
1033 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1036 static uint32_t compute_all_taddtv(void)
1040 ret
= get_NZ_icc(CC_DST
);
1041 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1045 static uint32_t compute_C_taddtv(void)
1047 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1050 /* carry = (~src1[31] & src2[31]) | ( dst[31] & (~src1[31] | src2[31])) */
1051 static inline uint32_t get_C_sub_icc(target_ulong dst
, target_ulong src1
,
1056 if (((~(src1
& (1ULL << 31))) & (src2
& (1ULL << 31)))
1057 | ((dst
& (1ULL << 31)) & (( ~(src1
& (1ULL << 31)))
1058 | (src2
& (1ULL << 31)))))
1063 static inline uint32_t get_V_sub_icc(target_ulong dst
, target_ulong src1
,
1068 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 31))
1074 #ifdef TARGET_SPARC64
1075 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1084 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1089 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63))
1094 static uint32_t compute_all_sub_xcc(void)
1098 ret
= get_NZ_xcc(CC_DST
);
1099 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1100 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1104 static uint32_t compute_C_sub_xcc(void)
1106 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1110 static uint32_t compute_all_sub(void)
1114 ret
= get_NZ_icc(CC_DST
);
1115 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1116 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1120 static uint32_t compute_C_sub(void)
1122 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1125 #ifdef TARGET_SPARC64
1126 static uint32_t compute_all_subx_xcc(void)
1130 ret
= get_NZ_xcc(CC_DST
);
1131 ret
|= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1132 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1133 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1137 static uint32_t compute_C_subx_xcc(void)
1141 ret
= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1142 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1147 static uint32_t compute_all_tsub(void)
1151 ret
= get_NZ_icc(CC_DST
);
1152 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1153 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1154 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1158 static uint32_t compute_C_tsub(void)
1160 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1163 static uint32_t compute_all_tsubtv(void)
1167 ret
= get_NZ_icc(CC_DST
);
1168 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1172 static uint32_t compute_C_tsubtv(void)
1174 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1177 static uint32_t compute_all_logic(void)
1179 return get_NZ_icc(CC_DST
);
1182 static uint32_t compute_C_logic(void)
1187 #ifdef TARGET_SPARC64
1188 static uint32_t compute_all_logic_xcc(void)
1190 return get_NZ_xcc(CC_DST
);
1194 typedef struct CCTable
{
1195 uint32_t (*compute_all
)(void); /* return all the flags */
1196 uint32_t (*compute_c
)(void); /* return the C flag */
1199 static const CCTable icc_table
[CC_OP_NB
] = {
1200 /* CC_OP_DYNAMIC should never happen */
1201 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1202 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1203 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1204 [CC_OP_ADDX
] = { compute_all_add
, compute_C_add
},
1205 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_tadd
},
1206 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_taddtv
},
1207 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1208 [CC_OP_SUBX
] = { compute_all_sub
, compute_C_sub
},
1209 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_tsub
},
1210 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_tsubtv
},
1211 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1214 #ifdef TARGET_SPARC64
1215 static const CCTable xcc_table
[CC_OP_NB
] = {
1216 /* CC_OP_DYNAMIC should never happen */
1217 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1218 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1219 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1220 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1221 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1222 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1223 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1224 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1225 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1226 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1227 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1231 void helper_compute_psr(void)
1235 new_psr
= icc_table
[CC_OP
].compute_all();
1237 #ifdef TARGET_SPARC64
1238 new_psr
= xcc_table
[CC_OP
].compute_all();
1241 CC_OP
= CC_OP_FLAGS
;
1244 uint32_t helper_compute_C_icc(void)
1248 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1252 #ifdef TARGET_SPARC64
1253 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1254 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1255 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1257 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1258 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1259 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1261 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1262 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1263 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1265 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1266 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1267 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1269 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1270 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1271 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1273 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1274 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1275 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1279 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1281 static void dump_mxcc(CPUState
*env
)
1283 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1285 env
->mxccdata
[0], env
->mxccdata
[1],
1286 env
->mxccdata
[2], env
->mxccdata
[3]);
1287 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1289 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1291 env
->mxccregs
[0], env
->mxccregs
[1],
1292 env
->mxccregs
[2], env
->mxccregs
[3],
1293 env
->mxccregs
[4], env
->mxccregs
[5],
1294 env
->mxccregs
[6], env
->mxccregs
[7]);
1298 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1299 && defined(DEBUG_ASI)
1300 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1306 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1307 addr
, asi
, r1
& 0xff);
1310 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1311 addr
, asi
, r1
& 0xffff);
1314 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1315 addr
, asi
, r1
& 0xffffffff);
1318 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1325 #ifndef TARGET_SPARC64
1326 #ifndef CONFIG_USER_ONLY
1327 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1330 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1331 uint32_t last_addr
= addr
;
1334 helper_check_align(addr
, size
- 1);
1336 case 2: /* SuperSparc MXCC registers */
1338 case 0x01c00a00: /* MXCC control register */
1340 ret
= env
->mxccregs
[3];
1342 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1345 case 0x01c00a04: /* MXCC control register */
1347 ret
= env
->mxccregs
[3];
1349 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1352 case 0x01c00c00: /* Module reset register */
1354 ret
= env
->mxccregs
[5];
1355 // should we do something here?
1357 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1360 case 0x01c00f00: /* MBus port address register */
1362 ret
= env
->mxccregs
[7];
1364 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1368 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1372 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1373 "addr = %08x -> ret = %" PRIx64
","
1374 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1379 case 3: /* MMU probe */
1383 mmulev
= (addr
>> 8) & 15;
1387 ret
= mmu_probe(env
, addr
, mmulev
);
1388 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1392 case 4: /* read MMU regs */
1394 int reg
= (addr
>> 8) & 0x1f;
1396 ret
= env
->mmuregs
[reg
];
1397 if (reg
== 3) /* Fault status cleared on read */
1398 env
->mmuregs
[3] = 0;
1399 else if (reg
== 0x13) /* Fault status read */
1400 ret
= env
->mmuregs
[3];
1401 else if (reg
== 0x14) /* Fault address read */
1402 ret
= env
->mmuregs
[4];
1403 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1406 case 5: // Turbosparc ITLB Diagnostic
1407 case 6: // Turbosparc DTLB Diagnostic
1408 case 7: // Turbosparc IOTLB Diagnostic
1410 case 9: /* Supervisor code access */
1413 ret
= ldub_code(addr
);
1416 ret
= lduw_code(addr
);
1420 ret
= ldl_code(addr
);
1423 ret
= ldq_code(addr
);
1427 case 0xa: /* User data access */
1430 ret
= ldub_user(addr
);
1433 ret
= lduw_user(addr
);
1437 ret
= ldl_user(addr
);
1440 ret
= ldq_user(addr
);
1444 case 0xb: /* Supervisor data access */
1447 ret
= ldub_kernel(addr
);
1450 ret
= lduw_kernel(addr
);
1454 ret
= ldl_kernel(addr
);
1457 ret
= ldq_kernel(addr
);
1461 case 0xc: /* I-cache tag */
1462 case 0xd: /* I-cache data */
1463 case 0xe: /* D-cache tag */
1464 case 0xf: /* D-cache data */
1466 case 0x20: /* MMU passthrough */
1469 ret
= ldub_phys(addr
);
1472 ret
= lduw_phys(addr
);
1476 ret
= ldl_phys(addr
);
1479 ret
= ldq_phys(addr
);
1483 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1486 ret
= ldub_phys((target_phys_addr_t
)addr
1487 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1490 ret
= lduw_phys((target_phys_addr_t
)addr
1491 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1495 ret
= ldl_phys((target_phys_addr_t
)addr
1496 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1499 ret
= ldq_phys((target_phys_addr_t
)addr
1500 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1504 case 0x30: // Turbosparc secondary cache diagnostic
1505 case 0x31: // Turbosparc RAM snoop
1506 case 0x32: // Turbosparc page table descriptor diagnostic
1507 case 0x39: /* data cache diagnostic register */
1510 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1512 int reg
= (addr
>> 8) & 3;
1515 case 0: /* Breakpoint Value (Addr) */
1516 ret
= env
->mmubpregs
[reg
];
1518 case 1: /* Breakpoint Mask */
1519 ret
= env
->mmubpregs
[reg
];
1521 case 2: /* Breakpoint Control */
1522 ret
= env
->mmubpregs
[reg
];
1524 case 3: /* Breakpoint Status */
1525 ret
= env
->mmubpregs
[reg
];
1526 env
->mmubpregs
[reg
] = 0ULL;
1529 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1533 case 8: /* User code access, XXX */
1535 do_unassigned_access(addr
, 0, 0, asi
, size
);
1545 ret
= (int16_t) ret
;
1548 ret
= (int32_t) ret
;
1555 dump_asi("read ", last_addr
, asi
, size
, ret
);
1560 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1562 helper_check_align(addr
, size
- 1);
1564 case 2: /* SuperSparc MXCC registers */
1566 case 0x01c00000: /* MXCC stream data register 0 */
1568 env
->mxccdata
[0] = val
;
1570 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1573 case 0x01c00008: /* MXCC stream data register 1 */
1575 env
->mxccdata
[1] = val
;
1577 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1580 case 0x01c00010: /* MXCC stream data register 2 */
1582 env
->mxccdata
[2] = val
;
1584 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1587 case 0x01c00018: /* MXCC stream data register 3 */
1589 env
->mxccdata
[3] = val
;
1591 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1594 case 0x01c00100: /* MXCC stream source */
1596 env
->mxccregs
[0] = val
;
1598 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1600 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1602 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1604 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1606 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1609 case 0x01c00200: /* MXCC stream destination */
1611 env
->mxccregs
[1] = val
;
1613 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1615 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1617 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1619 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1621 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1624 case 0x01c00a00: /* MXCC control register */
1626 env
->mxccregs
[3] = val
;
1628 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1631 case 0x01c00a04: /* MXCC control register */
1633 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1636 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1639 case 0x01c00e00: /* MXCC error register */
1640 // writing a 1 bit clears the error
1642 env
->mxccregs
[6] &= ~val
;
1644 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1647 case 0x01c00f00: /* MBus port address register */
1649 env
->mxccregs
[7] = val
;
1651 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1655 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1659 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1660 asi
, size
, addr
, val
);
1665 case 3: /* MMU flush */
1669 mmulev
= (addr
>> 8) & 15;
1670 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1672 case 0: // flush page
1673 tlb_flush_page(env
, addr
& 0xfffff000);
1675 case 1: // flush segment (256k)
1676 case 2: // flush region (16M)
1677 case 3: // flush context (4G)
1678 case 4: // flush entire
1689 case 4: /* write MMU regs */
1691 int reg
= (addr
>> 8) & 0x1f;
1694 oldreg
= env
->mmuregs
[reg
];
1696 case 0: // Control Register
1697 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1699 // Mappings generated during no-fault mode or MMU
1700 // disabled mode are invalid in normal mode
1701 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1702 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1705 case 1: // Context Table Pointer Register
1706 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1708 case 2: // Context Register
1709 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1710 if (oldreg
!= env
->mmuregs
[reg
]) {
1711 /* we flush when the MMU context changes because
1712 QEMU has no MMU context support */
1716 case 3: // Synchronous Fault Status Register with Clear
1717 case 4: // Synchronous Fault Address Register
1719 case 0x10: // TLB Replacement Control Register
1720 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1722 case 0x13: // Synchronous Fault Status Register with Read and Clear
1723 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1725 case 0x14: // Synchronous Fault Address Register
1726 env
->mmuregs
[4] = val
;
1729 env
->mmuregs
[reg
] = val
;
1732 if (oldreg
!= env
->mmuregs
[reg
]) {
1733 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1734 reg
, oldreg
, env
->mmuregs
[reg
]);
1741 case 5: // Turbosparc ITLB Diagnostic
1742 case 6: // Turbosparc DTLB Diagnostic
1743 case 7: // Turbosparc IOTLB Diagnostic
1745 case 0xa: /* User data access */
1748 stb_user(addr
, val
);
1751 stw_user(addr
, val
);
1755 stl_user(addr
, val
);
1758 stq_user(addr
, val
);
1762 case 0xb: /* Supervisor data access */
1765 stb_kernel(addr
, val
);
1768 stw_kernel(addr
, val
);
1772 stl_kernel(addr
, val
);
1775 stq_kernel(addr
, val
);
1779 case 0xc: /* I-cache tag */
1780 case 0xd: /* I-cache data */
1781 case 0xe: /* D-cache tag */
1782 case 0xf: /* D-cache data */
1783 case 0x10: /* I/D-cache flush page */
1784 case 0x11: /* I/D-cache flush segment */
1785 case 0x12: /* I/D-cache flush region */
1786 case 0x13: /* I/D-cache flush context */
1787 case 0x14: /* I/D-cache flush user */
1789 case 0x17: /* Block copy, sta access */
1795 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1797 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1798 temp
= ldl_kernel(src
);
1799 stl_kernel(dst
, temp
);
1803 case 0x1f: /* Block fill, stda access */
1806 // fill 32 bytes with val
1808 uint32_t dst
= addr
& 7;
1810 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1811 stq_kernel(dst
, val
);
1814 case 0x20: /* MMU passthrough */
1818 stb_phys(addr
, val
);
1821 stw_phys(addr
, val
);
1825 stl_phys(addr
, val
);
1828 stq_phys(addr
, val
);
1833 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1837 stb_phys((target_phys_addr_t
)addr
1838 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1841 stw_phys((target_phys_addr_t
)addr
1842 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1846 stl_phys((target_phys_addr_t
)addr
1847 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1850 stq_phys((target_phys_addr_t
)addr
1851 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1856 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1857 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1858 // Turbosparc snoop RAM
1859 case 0x32: // store buffer control or Turbosparc page table
1860 // descriptor diagnostic
1861 case 0x36: /* I-cache flash clear */
1862 case 0x37: /* D-cache flash clear */
1863 case 0x4c: /* breakpoint action */
1865 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1867 int reg
= (addr
>> 8) & 3;
1870 case 0: /* Breakpoint Value (Addr) */
1871 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1873 case 1: /* Breakpoint Mask */
1874 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1876 case 2: /* Breakpoint Control */
1877 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1879 case 3: /* Breakpoint Status */
1880 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1883 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1887 case 8: /* User code access, XXX */
1888 case 9: /* Supervisor code access, XXX */
1890 do_unassigned_access(addr
, 1, 0, asi
, size
);
1894 dump_asi("write", addr
, asi
, size
, val
);
1898 #endif /* CONFIG_USER_ONLY */
1899 #else /* TARGET_SPARC64 */
1901 #ifdef CONFIG_USER_ONLY
1902 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1905 #if defined(DEBUG_ASI)
1906 target_ulong last_addr
= addr
;
1910 raise_exception(TT_PRIV_ACT
);
1912 helper_check_align(addr
, size
- 1);
1913 address_mask(env
, &addr
);
1916 case 0x82: // Primary no-fault
1917 case 0x8a: // Primary no-fault LE
1918 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1920 dump_asi("read ", last_addr
, asi
, size
, ret
);
1925 case 0x80: // Primary
1926 case 0x88: // Primary LE
1930 ret
= ldub_raw(addr
);
1933 ret
= lduw_raw(addr
);
1936 ret
= ldl_raw(addr
);
1940 ret
= ldq_raw(addr
);
1945 case 0x83: // Secondary no-fault
1946 case 0x8b: // Secondary no-fault LE
1947 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1949 dump_asi("read ", last_addr
, asi
, size
, ret
);
1954 case 0x81: // Secondary
1955 case 0x89: // Secondary LE
1962 /* Convert from little endian */
1964 case 0x88: // Primary LE
1965 case 0x89: // Secondary LE
1966 case 0x8a: // Primary no-fault LE
1967 case 0x8b: // Secondary no-fault LE
1985 /* Convert to signed number */
1992 ret
= (int16_t) ret
;
1995 ret
= (int32_t) ret
;
2002 dump_asi("read ", last_addr
, asi
, size
, ret
);
2007 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2010 dump_asi("write", addr
, asi
, size
, val
);
2013 raise_exception(TT_PRIV_ACT
);
2015 helper_check_align(addr
, size
- 1);
2016 address_mask(env
, &addr
);
2018 /* Convert to little endian */
2020 case 0x88: // Primary LE
2021 case 0x89: // Secondary LE
2040 case 0x80: // Primary
2041 case 0x88: // Primary LE
2060 case 0x81: // Secondary
2061 case 0x89: // Secondary LE
2065 case 0x82: // Primary no-fault, RO
2066 case 0x83: // Secondary no-fault, RO
2067 case 0x8a: // Primary no-fault LE, RO
2068 case 0x8b: // Secondary no-fault LE, RO
2070 do_unassigned_access(addr
, 1, 0, 1, size
);
2075 #else /* CONFIG_USER_ONLY */
2077 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2080 #if defined(DEBUG_ASI)
2081 target_ulong last_addr
= addr
;
2086 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2087 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2088 && asi
>= 0x30 && asi
< 0x80
2089 && !(env
->hpstate
& HS_PRIV
)))
2090 raise_exception(TT_PRIV_ACT
);
2092 helper_check_align(addr
, size
- 1);
2094 case 0x82: // Primary no-fault
2095 case 0x8a: // Primary no-fault LE
2096 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2098 dump_asi("read ", last_addr
, asi
, size
, ret
);
2103 case 0x10: // As if user primary
2104 case 0x18: // As if user primary LE
2105 case 0x80: // Primary
2106 case 0x88: // Primary LE
2107 case 0xe2: // UA2007 Primary block init
2108 case 0xe3: // UA2007 Secondary block init
2109 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2110 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2111 && env
->hpstate
& HS_PRIV
) {
2114 ret
= ldub_hypv(addr
);
2117 ret
= lduw_hypv(addr
);
2120 ret
= ldl_hypv(addr
);
2124 ret
= ldq_hypv(addr
);
2130 ret
= ldub_kernel(addr
);
2133 ret
= lduw_kernel(addr
);
2136 ret
= ldl_kernel(addr
);
2140 ret
= ldq_kernel(addr
);
2147 ret
= ldub_user(addr
);
2150 ret
= lduw_user(addr
);
2153 ret
= ldl_user(addr
);
2157 ret
= ldq_user(addr
);
2162 case 0x14: // Bypass
2163 case 0x15: // Bypass, non-cacheable
2164 case 0x1c: // Bypass LE
2165 case 0x1d: // Bypass, non-cacheable LE
2169 ret
= ldub_phys(addr
);
2172 ret
= lduw_phys(addr
);
2175 ret
= ldl_phys(addr
);
2179 ret
= ldq_phys(addr
);
2184 case 0x24: // Nucleus quad LDD 128 bit atomic
2185 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2186 // Only ldda allowed
2187 raise_exception(TT_ILL_INSN
);
2189 case 0x83: // Secondary no-fault
2190 case 0x8b: // Secondary no-fault LE
2191 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2193 dump_asi("read ", last_addr
, asi
, size
, ret
);
2198 case 0x04: // Nucleus
2199 case 0x0c: // Nucleus Little Endian (LE)
2200 case 0x11: // As if user secondary
2201 case 0x19: // As if user secondary LE
2202 case 0x4a: // UPA config
2203 case 0x81: // Secondary
2204 case 0x89: // Secondary LE
2210 case 0x50: // I-MMU regs
2212 int reg
= (addr
>> 3) & 0xf;
2215 // I-TSB Tag Target register
2216 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2218 ret
= env
->immuregs
[reg
];
2223 case 0x51: // I-MMU 8k TSB pointer
2225 // env->immuregs[5] holds I-MMU TSB register value
2226 // env->immuregs[6] holds I-MMU Tag Access register value
2227 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2231 case 0x52: // I-MMU 64k TSB pointer
2233 // env->immuregs[5] holds I-MMU TSB register value
2234 // env->immuregs[6] holds I-MMU Tag Access register value
2235 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2239 case 0x55: // I-MMU data access
2241 int reg
= (addr
>> 3) & 0x3f;
2243 ret
= env
->itlb
[reg
].tte
;
2246 case 0x56: // I-MMU tag read
2248 int reg
= (addr
>> 3) & 0x3f;
2250 ret
= env
->itlb
[reg
].tag
;
2253 case 0x58: // D-MMU regs
2255 int reg
= (addr
>> 3) & 0xf;
2258 // D-TSB Tag Target register
2259 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2261 ret
= env
->dmmuregs
[reg
];
2265 case 0x59: // D-MMU 8k TSB pointer
2267 // env->dmmuregs[5] holds D-MMU TSB register value
2268 // env->dmmuregs[6] holds D-MMU Tag Access register value
2269 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2273 case 0x5a: // D-MMU 64k TSB pointer
2275 // env->dmmuregs[5] holds D-MMU TSB register value
2276 // env->dmmuregs[6] holds D-MMU Tag Access register value
2277 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2281 case 0x5d: // D-MMU data access
2283 int reg
= (addr
>> 3) & 0x3f;
2285 ret
= env
->dtlb
[reg
].tte
;
2288 case 0x5e: // D-MMU tag read
2290 int reg
= (addr
>> 3) & 0x3f;
2292 ret
= env
->dtlb
[reg
].tag
;
2295 case 0x46: // D-cache data
2296 case 0x47: // D-cache tag access
2297 case 0x4b: // E-cache error enable
2298 case 0x4c: // E-cache asynchronous fault status
2299 case 0x4d: // E-cache asynchronous fault address
2300 case 0x4e: // E-cache tag data
2301 case 0x66: // I-cache instruction access
2302 case 0x67: // I-cache tag access
2303 case 0x6e: // I-cache predecode
2304 case 0x6f: // I-cache LRU etc.
2305 case 0x76: // E-cache tag
2306 case 0x7e: // E-cache tag
2308 case 0x5b: // D-MMU data pointer
2309 case 0x48: // Interrupt dispatch, RO
2310 case 0x49: // Interrupt data receive
2311 case 0x7f: // Incoming interrupt vector, RO
2314 case 0x54: // I-MMU data in, WO
2315 case 0x57: // I-MMU demap, WO
2316 case 0x5c: // D-MMU data in, WO
2317 case 0x5f: // D-MMU demap, WO
2318 case 0x77: // Interrupt vector, WO
2320 do_unassigned_access(addr
, 0, 0, 1, size
);
2325 /* Convert from little endian */
2327 case 0x0c: // Nucleus Little Endian (LE)
2328 case 0x18: // As if user primary LE
2329 case 0x19: // As if user secondary LE
2330 case 0x1c: // Bypass LE
2331 case 0x1d: // Bypass, non-cacheable LE
2332 case 0x88: // Primary LE
2333 case 0x89: // Secondary LE
2334 case 0x8a: // Primary no-fault LE
2335 case 0x8b: // Secondary no-fault LE
2353 /* Convert to signed number */
2360 ret
= (int16_t) ret
;
2363 ret
= (int32_t) ret
;
2370 dump_asi("read ", last_addr
, asi
, size
, ret
);
2375 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2378 dump_asi("write", addr
, asi
, size
, val
);
2383 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2384 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2385 && asi
>= 0x30 && asi
< 0x80
2386 && !(env
->hpstate
& HS_PRIV
)))
2387 raise_exception(TT_PRIV_ACT
);
2389 helper_check_align(addr
, size
- 1);
2390 /* Convert to little endian */
2392 case 0x0c: // Nucleus Little Endian (LE)
2393 case 0x18: // As if user primary LE
2394 case 0x19: // As if user secondary LE
2395 case 0x1c: // Bypass LE
2396 case 0x1d: // Bypass, non-cacheable LE
2397 case 0x88: // Primary LE
2398 case 0x89: // Secondary LE
2417 case 0x10: // As if user primary
2418 case 0x18: // As if user primary LE
2419 case 0x80: // Primary
2420 case 0x88: // Primary LE
2421 case 0xe2: // UA2007 Primary block init
2422 case 0xe3: // UA2007 Secondary block init
2423 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2424 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2425 && env
->hpstate
& HS_PRIV
) {
2428 stb_hypv(addr
, val
);
2431 stw_hypv(addr
, val
);
2434 stl_hypv(addr
, val
);
2438 stq_hypv(addr
, val
);
2444 stb_kernel(addr
, val
);
2447 stw_kernel(addr
, val
);
2450 stl_kernel(addr
, val
);
2454 stq_kernel(addr
, val
);
2461 stb_user(addr
, val
);
2464 stw_user(addr
, val
);
2467 stl_user(addr
, val
);
2471 stq_user(addr
, val
);
2476 case 0x14: // Bypass
2477 case 0x15: // Bypass, non-cacheable
2478 case 0x1c: // Bypass LE
2479 case 0x1d: // Bypass, non-cacheable LE
2483 stb_phys(addr
, val
);
2486 stw_phys(addr
, val
);
2489 stl_phys(addr
, val
);
2493 stq_phys(addr
, val
);
2498 case 0x24: // Nucleus quad LDD 128 bit atomic
2499 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2500 // Only ldda allowed
2501 raise_exception(TT_ILL_INSN
);
2503 case 0x04: // Nucleus
2504 case 0x0c: // Nucleus Little Endian (LE)
2505 case 0x11: // As if user secondary
2506 case 0x19: // As if user secondary LE
2507 case 0x4a: // UPA config
2508 case 0x81: // Secondary
2509 case 0x89: // Secondary LE
2517 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
2518 // Mappings generated during D/I MMU disabled mode are
2519 // invalid in normal mode
2520 if (oldreg
!= env
->lsu
) {
2521 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
2530 case 0x50: // I-MMU regs
2532 int reg
= (addr
>> 3) & 0xf;
2535 oldreg
= env
->immuregs
[reg
];
2539 case 1: // Not in I-MMU
2544 val
= 0; // Clear SFSR
2545 env
->immu
.sfsr
= val
;
2549 case 5: // TSB access
2550 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
2551 PRIx64
"\n", env
->immu
.tsb
, val
);
2552 env
->immu
.tsb
= val
;
2554 case 6: // Tag access
2555 env
->immu
.tag_access
= val
;
2564 if (oldreg
!= env
->immuregs
[reg
]) {
2565 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2566 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2573 case 0x54: // I-MMU data in
2574 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
2576 case 0x55: // I-MMU data access
2580 unsigned int i
= (addr
>> 3) & 0x3f;
2582 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
2585 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
2590 case 0x57: // I-MMU demap
2591 demap_tlb(env
->itlb
, val
, "immu", env
);
2593 case 0x58: // D-MMU regs
2595 int reg
= (addr
>> 3) & 0xf;
2598 oldreg
= env
->dmmuregs
[reg
];
2604 if ((val
& 1) == 0) {
2605 val
= 0; // Clear SFSR, Fault address
2608 env
->dmmu
.sfsr
= val
;
2610 case 1: // Primary context
2611 env
->dmmu
.mmu_primary_context
= val
;
2613 case 2: // Secondary context
2614 env
->dmmu
.mmu_secondary_context
= val
;
2616 case 5: // TSB access
2617 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
2618 PRIx64
"\n", env
->dmmu
.tsb
, val
);
2619 env
->dmmu
.tsb
= val
;
2621 case 6: // Tag access
2622 env
->dmmu
.tag_access
= val
;
2624 case 7: // Virtual Watchpoint
2625 case 8: // Physical Watchpoint
2627 env
->dmmuregs
[reg
] = val
;
2631 if (oldreg
!= env
->dmmuregs
[reg
]) {
2632 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2633 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2640 case 0x5c: // D-MMU data in
2641 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
2643 case 0x5d: // D-MMU data access
2645 unsigned int i
= (addr
>> 3) & 0x3f;
2647 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
2650 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
2655 case 0x5f: // D-MMU demap
2656 demap_tlb(env
->dtlb
, val
, "dmmu", env
);
2658 case 0x49: // Interrupt data receive
2661 case 0x46: // D-cache data
2662 case 0x47: // D-cache tag access
2663 case 0x4b: // E-cache error enable
2664 case 0x4c: // E-cache asynchronous fault status
2665 case 0x4d: // E-cache asynchronous fault address
2666 case 0x4e: // E-cache tag data
2667 case 0x66: // I-cache instruction access
2668 case 0x67: // I-cache tag access
2669 case 0x6e: // I-cache predecode
2670 case 0x6f: // I-cache LRU etc.
2671 case 0x76: // E-cache tag
2672 case 0x7e: // E-cache tag
2674 case 0x51: // I-MMU 8k TSB pointer, RO
2675 case 0x52: // I-MMU 64k TSB pointer, RO
2676 case 0x56: // I-MMU tag read, RO
2677 case 0x59: // D-MMU 8k TSB pointer, RO
2678 case 0x5a: // D-MMU 64k TSB pointer, RO
2679 case 0x5b: // D-MMU data pointer, RO
2680 case 0x5e: // D-MMU tag read, RO
2681 case 0x48: // Interrupt dispatch, RO
2682 case 0x7f: // Incoming interrupt vector, RO
2683 case 0x82: // Primary no-fault, RO
2684 case 0x83: // Secondary no-fault, RO
2685 case 0x8a: // Primary no-fault LE, RO
2686 case 0x8b: // Secondary no-fault LE, RO
2688 do_unassigned_access(addr
, 1, 0, 1, size
);
2692 #endif /* CONFIG_USER_ONLY */
2694 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2696 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2697 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2698 && asi
>= 0x30 && asi
< 0x80
2699 && !(env
->hpstate
& HS_PRIV
)))
2700 raise_exception(TT_PRIV_ACT
);
2703 case 0x24: // Nucleus quad LDD 128 bit atomic
2704 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2705 helper_check_align(addr
, 0xf);
2707 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2709 bswap64s(&env
->gregs
[1]);
2710 } else if (rd
< 8) {
2711 env
->gregs
[rd
] = ldq_kernel(addr
);
2712 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2714 bswap64s(&env
->gregs
[rd
]);
2715 bswap64s(&env
->gregs
[rd
+ 1]);
2718 env
->regwptr
[rd
] = ldq_kernel(addr
);
2719 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2721 bswap64s(&env
->regwptr
[rd
]);
2722 bswap64s(&env
->regwptr
[rd
+ 1]);
2727 helper_check_align(addr
, 0x3);
2729 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2731 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2732 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2734 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2735 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2741 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2746 helper_check_align(addr
, 3);
2748 case 0xf0: // Block load primary
2749 case 0xf1: // Block load secondary
2750 case 0xf8: // Block load primary LE
2751 case 0xf9: // Block load secondary LE
2753 raise_exception(TT_ILL_INSN
);
2756 helper_check_align(addr
, 0x3f);
2757 for (i
= 0; i
< 16; i
++) {
2758 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2768 val
= helper_ld_asi(addr
, asi
, size
, 0);
2772 *((uint32_t *)&env
->fpr
[rd
]) = val
;
2775 *((int64_t *)&DT0
) = val
;
2783 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2786 target_ulong val
= 0;
2788 helper_check_align(addr
, 3);
2790 case 0xe0: // UA2007 Block commit store primary (cache flush)
2791 case 0xe1: // UA2007 Block commit store secondary (cache flush)
2792 case 0xf0: // Block store primary
2793 case 0xf1: // Block store secondary
2794 case 0xf8: // Block store primary LE
2795 case 0xf9: // Block store secondary LE
2797 raise_exception(TT_ILL_INSN
);
2800 helper_check_align(addr
, 0x3f);
2801 for (i
= 0; i
< 16; i
++) {
2802 val
= *(uint32_t *)&env
->fpr
[rd
++];
2803 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2815 val
= *((uint32_t *)&env
->fpr
[rd
]);
2818 val
= *((int64_t *)&DT0
);
2824 helper_st_asi(addr
, val
, asi
, size
);
2827 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2828 target_ulong val2
, uint32_t asi
)
2832 val2
&= 0xffffffffUL
;
2833 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2834 ret
&= 0xffffffffUL
;
2836 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
2840 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2841 target_ulong val2
, uint32_t asi
)
2845 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2847 helper_st_asi(addr
, val1
, asi
, 8);
2850 #endif /* TARGET_SPARC64 */
2852 #ifndef TARGET_SPARC64
2853 void helper_rett(void)
2857 if (env
->psret
== 1)
2858 raise_exception(TT_ILL_INSN
);
2861 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2862 if (env
->wim
& (1 << cwp
)) {
2863 raise_exception(TT_WIN_UNF
);
2866 env
->psrs
= env
->psrps
;
2870 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2875 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2879 raise_exception(TT_DIV_ZERO
);
2883 if (x0
> 0xffffffff) {
2892 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2897 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2901 raise_exception(TT_DIV_ZERO
);
2905 if ((int32_t) x0
!= x0
) {
2907 return x0
< 0? 0x80000000: 0x7fffffff;
2914 void helper_stdf(target_ulong addr
, int mem_idx
)
2916 helper_check_align(addr
, 7);
2917 #if !defined(CONFIG_USER_ONLY)
2920 stfq_user(addr
, DT0
);
2923 stfq_kernel(addr
, DT0
);
2925 #ifdef TARGET_SPARC64
2927 stfq_hypv(addr
, DT0
);
2934 address_mask(env
, &addr
);
2935 stfq_raw(addr
, DT0
);
2939 void helper_lddf(target_ulong addr
, int mem_idx
)
2941 helper_check_align(addr
, 7);
2942 #if !defined(CONFIG_USER_ONLY)
2945 DT0
= ldfq_user(addr
);
2948 DT0
= ldfq_kernel(addr
);
2950 #ifdef TARGET_SPARC64
2952 DT0
= ldfq_hypv(addr
);
2959 address_mask(env
, &addr
);
2960 DT0
= ldfq_raw(addr
);
2964 void helper_ldqf(target_ulong addr
, int mem_idx
)
2966 // XXX add 128 bit load
2969 helper_check_align(addr
, 7);
2970 #if !defined(CONFIG_USER_ONLY)
2973 u
.ll
.upper
= ldq_user(addr
);
2974 u
.ll
.lower
= ldq_user(addr
+ 8);
2978 u
.ll
.upper
= ldq_kernel(addr
);
2979 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2982 #ifdef TARGET_SPARC64
2984 u
.ll
.upper
= ldq_hypv(addr
);
2985 u
.ll
.lower
= ldq_hypv(addr
+ 8);
2993 address_mask(env
, &addr
);
2994 u
.ll
.upper
= ldq_raw(addr
);
2995 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
3000 void helper_stqf(target_ulong addr
, int mem_idx
)
3002 // XXX add 128 bit store
3005 helper_check_align(addr
, 7);
3006 #if !defined(CONFIG_USER_ONLY)
3010 stq_user(addr
, u
.ll
.upper
);
3011 stq_user(addr
+ 8, u
.ll
.lower
);
3015 stq_kernel(addr
, u
.ll
.upper
);
3016 stq_kernel(addr
+ 8, u
.ll
.lower
);
3018 #ifdef TARGET_SPARC64
3021 stq_hypv(addr
, u
.ll
.upper
);
3022 stq_hypv(addr
+ 8, u
.ll
.lower
);
3030 address_mask(env
, &addr
);
3031 stq_raw(addr
, u
.ll
.upper
);
3032 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
3036 static inline void set_fsr(void)
3040 switch (env
->fsr
& FSR_RD_MASK
) {
3041 case FSR_RD_NEAREST
:
3042 rnd_mode
= float_round_nearest_even
;
3046 rnd_mode
= float_round_to_zero
;
3049 rnd_mode
= float_round_up
;
3052 rnd_mode
= float_round_down
;
3055 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3058 void helper_ldfsr(uint32_t new_fsr
)
3060 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3064 #ifdef TARGET_SPARC64
3065 void helper_ldxfsr(uint64_t new_fsr
)
3067 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3072 void helper_debug(void)
3074 env
->exception_index
= EXCP_DEBUG
;
3078 #ifndef TARGET_SPARC64
3079 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3081 void helper_save(void)
3085 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3086 if (env
->wim
& (1 << cwp
)) {
3087 raise_exception(TT_WIN_OVF
);
3092 void helper_restore(void)
3096 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3097 if (env
->wim
& (1 << cwp
)) {
3098 raise_exception(TT_WIN_UNF
);
3103 void helper_wrpsr(target_ulong new_psr
)
3105 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
3106 raise_exception(TT_ILL_INSN
);
3108 PUT_PSR(env
, new_psr
);
3111 target_ulong
helper_rdpsr(void)
3113 return GET_PSR(env
);
3117 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3119 void helper_save(void)
3123 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3124 if (env
->cansave
== 0) {
3125 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3126 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3127 ((env
->wstate
& 0x7) << 2)));
3129 if (env
->cleanwin
- env
->canrestore
== 0) {
3130 // XXX Clean windows without trap
3131 raise_exception(TT_CLRWIN
);
3140 void helper_restore(void)
3144 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3145 if (env
->canrestore
== 0) {
3146 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3147 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3148 ((env
->wstate
& 0x7) << 2)));
3156 void helper_flushw(void)
3158 if (env
->cansave
!= env
->nwindows
- 2) {
3159 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3160 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3161 ((env
->wstate
& 0x7) << 2)));
3165 void helper_saved(void)
3168 if (env
->otherwin
== 0)
3174 void helper_restored(void)
3177 if (env
->cleanwin
< env
->nwindows
- 1)
3179 if (env
->otherwin
== 0)
3185 target_ulong
helper_rdccr(void)
3187 return GET_CCR(env
);
3190 void helper_wrccr(target_ulong new_ccr
)
3192 PUT_CCR(env
, new_ccr
);
3195 // CWP handling is reversed in V9, but we still use the V8 register
3197 target_ulong
helper_rdcwp(void)
3199 return GET_CWP64(env
);
3202 void helper_wrcwp(target_ulong new_cwp
)
3204 PUT_CWP64(env
, new_cwp
);
3207 // This function uses non-native bit order
3208 #define GET_FIELD(X, FROM, TO) \
3209 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3211 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3212 #define GET_FIELD_SP(X, FROM, TO) \
3213 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3215 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3217 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3218 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3219 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3220 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3221 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3222 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3223 (((pixel_addr
>> 55) & 1) << 4) |
3224 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3225 GET_FIELD_SP(pixel_addr
, 11, 12);
3228 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3232 tmp
= addr
+ offset
;
3234 env
->gsr
|= tmp
& 7ULL;
3238 target_ulong
helper_popc(target_ulong val
)
3240 return ctpop64(val
);
3243 static inline uint64_t *get_gregset(uint64_t pstate
)
3258 static inline void change_pstate(uint64_t new_pstate
)
3260 uint64_t pstate_regs
, new_pstate_regs
;
3261 uint64_t *src
, *dst
;
3263 if (env
->def
->features
& CPU_FEATURE_GL
) {
3264 // PS_AG is not implemented in this case
3265 new_pstate
&= ~PS_AG
;
3268 pstate_regs
= env
->pstate
& 0xc01;
3269 new_pstate_regs
= new_pstate
& 0xc01;
3271 if (new_pstate_regs
!= pstate_regs
) {
3272 // Switch global register bank
3273 src
= get_gregset(new_pstate_regs
);
3274 dst
= get_gregset(pstate_regs
);
3275 memcpy32(dst
, env
->gregs
);
3276 memcpy32(env
->gregs
, src
);
3278 env
->pstate
= new_pstate
;
3281 void helper_wrpstate(target_ulong new_state
)
3283 change_pstate(new_state
& 0xf3f);
3286 void helper_done(void)
3288 trap_state
* tsptr
= cpu_tsptr(env
);
3290 env
->pc
= tsptr
->tnpc
;
3291 env
->npc
= tsptr
->tnpc
+ 4;
3292 PUT_CCR(env
, tsptr
->tstate
>> 32);
3293 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3294 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3295 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3299 void helper_retry(void)
3301 trap_state
* tsptr
= cpu_tsptr(env
);
3303 env
->pc
= tsptr
->tpc
;
3304 env
->npc
= tsptr
->tnpc
;
3305 PUT_CCR(env
, tsptr
->tstate
>> 32);
3306 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3307 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3308 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3312 void helper_set_softint(uint64_t value
)
3314 env
->softint
|= (uint32_t)value
;
3317 void helper_clear_softint(uint64_t value
)
3319 env
->softint
&= (uint32_t)~value
;
3322 void helper_write_softint(uint64_t value
)
3324 env
->softint
= (uint32_t)value
;
3328 void helper_flush(target_ulong addr
)
3331 tb_invalidate_page_range(addr
, addr
+ 8);
3334 #ifdef TARGET_SPARC64
3336 static const char * const excp_names
[0x80] = {
3337 [TT_TFAULT
] = "Instruction Access Fault",
3338 [TT_TMISS
] = "Instruction Access MMU Miss",
3339 [TT_CODE_ACCESS
] = "Instruction Access Error",
3340 [TT_ILL_INSN
] = "Illegal Instruction",
3341 [TT_PRIV_INSN
] = "Privileged Instruction",
3342 [TT_NFPU_INSN
] = "FPU Disabled",
3343 [TT_FP_EXCP
] = "FPU Exception",
3344 [TT_TOVF
] = "Tag Overflow",
3345 [TT_CLRWIN
] = "Clean Windows",
3346 [TT_DIV_ZERO
] = "Division By Zero",
3347 [TT_DFAULT
] = "Data Access Fault",
3348 [TT_DMISS
] = "Data Access MMU Miss",
3349 [TT_DATA_ACCESS
] = "Data Access Error",
3350 [TT_DPROT
] = "Data Protection Error",
3351 [TT_UNALIGNED
] = "Unaligned Memory Access",
3352 [TT_PRIV_ACT
] = "Privileged Action",
3353 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3354 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3355 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3356 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3357 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3358 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3359 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3360 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3361 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3362 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3363 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3364 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3365 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3366 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3367 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3371 trap_state
* cpu_tsptr(CPUState
* env
)
3373 return &env
->ts
[env
->tl
& MAXTL_MASK
];
3376 void do_interrupt(CPUState
*env
)
3378 int intno
= env
->exception_index
;
3382 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3386 if (intno
< 0 || intno
>= 0x180)
3388 else if (intno
>= 0x100)
3389 name
= "Trap Instruction";
3390 else if (intno
>= 0xc0)
3391 name
= "Window Fill";
3392 else if (intno
>= 0x80)
3393 name
= "Window Spill";
3395 name
= excp_names
[intno
];
3400 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
3401 " SP=%016" PRIx64
"\n",
3404 env
->npc
, env
->regwptr
[6]);
3405 log_cpu_state(env
, 0);
3412 ptr
= (uint8_t *)env
->pc
;
3413 for(i
= 0; i
< 16; i
++) {
3414 qemu_log(" %02x", ldub(ptr
+ i
));
3422 #if !defined(CONFIG_USER_ONLY)
3423 if (env
->tl
>= env
->maxtl
) {
3424 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
3425 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
3429 if (env
->tl
< env
->maxtl
- 1) {
3432 env
->pstate
|= PS_RED
;
3433 if (env
->tl
< env
->maxtl
)
3436 tsptr
= cpu_tsptr(env
);
3438 tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
3439 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
3441 tsptr
->tpc
= env
->pc
;
3442 tsptr
->tnpc
= env
->npc
;
3447 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
3454 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
3457 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
3461 if (intno
== TT_CLRWIN
)
3462 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
3463 else if ((intno
& 0x1c0) == TT_SPILL
)
3464 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
3465 else if ((intno
& 0x1c0) == TT_FILL
)
3466 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
3467 env
->tbr
&= ~0x7fffULL
;
3468 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
3470 env
->npc
= env
->pc
+ 4;
3471 env
->exception_index
= 0;
3475 static const char * const excp_names
[0x80] = {
3476 [TT_TFAULT
] = "Instruction Access Fault",
3477 [TT_ILL_INSN
] = "Illegal Instruction",
3478 [TT_PRIV_INSN
] = "Privileged Instruction",
3479 [TT_NFPU_INSN
] = "FPU Disabled",
3480 [TT_WIN_OVF
] = "Window Overflow",
3481 [TT_WIN_UNF
] = "Window Underflow",
3482 [TT_UNALIGNED
] = "Unaligned Memory Access",
3483 [TT_FP_EXCP
] = "FPU Exception",
3484 [TT_DFAULT
] = "Data Access Fault",
3485 [TT_TOVF
] = "Tag Overflow",
3486 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3487 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3488 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3489 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3490 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3491 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3492 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3493 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3494 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3495 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3496 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3497 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3498 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3499 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3500 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3501 [TT_TOVF
] = "Tag Overflow",
3502 [TT_CODE_ACCESS
] = "Instruction Access Error",
3503 [TT_DATA_ACCESS
] = "Data Access Error",
3504 [TT_DIV_ZERO
] = "Division By Zero",
3505 [TT_NCP_INSN
] = "Coprocessor Disabled",
3509 void do_interrupt(CPUState
*env
)
3511 int cwp
, intno
= env
->exception_index
;
3514 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3518 if (intno
< 0 || intno
>= 0x100)
3520 else if (intno
>= 0x80)
3521 name
= "Trap Instruction";
3523 name
= excp_names
[intno
];
3528 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
3531 env
->npc
, env
->regwptr
[6]);
3532 log_cpu_state(env
, 0);
3539 ptr
= (uint8_t *)env
->pc
;
3540 for(i
= 0; i
< 16; i
++) {
3541 qemu_log(" %02x", ldub(ptr
+ i
));
3549 #if !defined(CONFIG_USER_ONLY)
3550 if (env
->psret
== 0) {
3551 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
3552 env
->exception_index
);
3557 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3558 cpu_set_cwp(env
, cwp
);
3559 env
->regwptr
[9] = env
->pc
;
3560 env
->regwptr
[10] = env
->npc
;
3561 env
->psrps
= env
->psrs
;
3563 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
3565 env
->npc
= env
->pc
+ 4;
3566 env
->exception_index
= 0;
3570 #if !defined(CONFIG_USER_ONLY)
3572 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3575 #define MMUSUFFIX _mmu
3576 #define ALIGNED_ONLY
3579 #include "softmmu_template.h"
3582 #include "softmmu_template.h"
3585 #include "softmmu_template.h"
3588 #include "softmmu_template.h"
3590 /* XXX: make it generic ? */
3591 static void cpu_restore_state2(void *retaddr
)
3593 TranslationBlock
*tb
;
3597 /* now we have a real cpu fault */
3598 pc
= (unsigned long)retaddr
;
3599 tb
= tb_find_pc(pc
);
3601 /* the PC is inside the translated code. It means that we have
3602 a virtual CPU fault */
3603 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
3608 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3611 #ifdef DEBUG_UNALIGNED
3612 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3613 "\n", addr
, env
->pc
);
3615 cpu_restore_state2(retaddr
);
3616 raise_exception(TT_UNALIGNED
);
3619 /* try to fill the TLB and return an exception if error. If retaddr is
3620 NULL, it means that the function was called in C code (i.e. not
3621 from generated code or from helper.c) */
3622 /* XXX: fix it to restore all registers */
3623 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3626 CPUState
*saved_env
;
3628 /* XXX: hack to restore env in all cases, even if not called from
3631 env
= cpu_single_env
;
3633 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3635 cpu_restore_state2(retaddr
);
3643 #ifndef TARGET_SPARC64
3644 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3645 int is_asi
, int size
)
3647 CPUState
*saved_env
;
3649 /* XXX: hack to restore env in all cases, even if not called from
3652 env
= cpu_single_env
;
3653 #ifdef DEBUG_UNASSIGNED
3655 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3656 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3657 is_exec
? "exec" : is_write
? "write" : "read", size
,
3658 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
3660 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3661 " from " TARGET_FMT_lx
"\n",
3662 is_exec
? "exec" : is_write
? "write" : "read", size
,
3663 size
== 1 ? "" : "s", addr
, env
->pc
);
3665 if (env
->mmuregs
[3]) /* Fault status register */
3666 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
3668 env
->mmuregs
[3] |= 1 << 16;
3670 env
->mmuregs
[3] |= 1 << 5;
3672 env
->mmuregs
[3] |= 1 << 6;
3674 env
->mmuregs
[3] |= 1 << 7;
3675 env
->mmuregs
[3] |= (5 << 2) | 2;
3676 env
->mmuregs
[4] = addr
; /* Fault address register */
3677 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3679 raise_exception(TT_CODE_ACCESS
);
3681 raise_exception(TT_DATA_ACCESS
);
3686 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3687 int is_asi
, int size
)
3689 #ifdef DEBUG_UNASSIGNED
3690 CPUState
*saved_env
;
3692 /* XXX: hack to restore env in all cases, even if not called from
3695 env
= cpu_single_env
;
3696 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3697 "\n", addr
, env
->pc
);
3701 raise_exception(TT_CODE_ACCESS
);
3703 raise_exception(TT_DATA_ACCESS
);
3707 #ifdef TARGET_SPARC64
3708 void helper_tick_set_count(void *opaque
, uint64_t count
)
3710 #if !defined(CONFIG_USER_ONLY)
3711 cpu_tick_set_count(opaque
, count
);
3715 uint64_t helper_tick_get_count(void *opaque
)
3717 #if !defined(CONFIG_USER_ONLY)
3718 return cpu_tick_get_count(opaque
);
3724 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
3726 #if !defined(CONFIG_USER_ONLY)
3727 cpu_tick_set_limit(opaque
, limit
);