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
14 //#define DEBUG_PSTATE
17 #define DPRINTF_MMU(fmt, ...) \
18 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
20 #define DPRINTF_MMU(fmt, ...) do {} while (0)
24 #define DPRINTF_MXCC(fmt, ...) \
25 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
27 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
31 #define DPRINTF_ASI(fmt, ...) \
32 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
36 #define DPRINTF_PSTATE(fmt, ...) \
37 do { printf("PSTATE: " fmt , ## __VA_ARGS__); } while (0)
39 #define DPRINTF_PSTATE(fmt, ...) do {} while (0)
44 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
46 #define AM_CHECK(env1) (1)
50 #if defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
51 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
52 int is_asi
, int size
);
55 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
56 // Calculates TSB pointer value for fault page size 8k or 64k
57 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
58 uint64_t tag_access_register
,
61 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
62 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
63 int tsb_size
= tsb_register
& 0xf;
65 // discard lower 13 bits which hold tag access context
66 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
69 uint64_t tsb_base_mask
= ~0x1fffULL
;
70 uint64_t va
= tag_access_va
;
72 // move va bits to correct position
73 if (page_size
== 8*1024) {
75 } else if (page_size
== 64*1024) {
80 tsb_base_mask
<<= tsb_size
;
83 // calculate tsb_base mask and adjust va if split is in use
85 if (page_size
== 8*1024) {
86 va
&= ~(1ULL << (13 + tsb_size
));
87 } else if (page_size
== 64*1024) {
88 va
|= (1ULL << (13 + tsb_size
));
93 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
96 // Calculates tag target register value by reordering bits
97 // in tag access register
98 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
100 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
103 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
104 uint64_t tlb_tag
, uint64_t tlb_tte
,
107 target_ulong mask
, size
, va
, offset
;
109 // flush page range if translation is valid
110 if (TTE_IS_VALID(tlb
->tte
)) {
112 mask
= 0xffffffffffffe000ULL
;
113 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
116 va
= tlb
->tag
& mask
;
118 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
119 tlb_flush_page(env1
, va
+ offset
);
127 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
128 const char* strmmu
, CPUState
*env1
)
133 for (i
= 0; i
< 64; i
++) {
134 if (TTE_IS_VALID(tlb
[i
].tte
)) {
136 mask
= 0xffffffffffffe000ULL
;
137 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
139 if ((demap_addr
& mask
) == (tlb
[i
].tag
& mask
)) {
140 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
142 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
152 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
153 uint64_t tlb_tag
, uint64_t tlb_tte
,
154 const char* strmmu
, CPUState
*env1
)
156 unsigned int i
, replace_used
;
158 // Try replacing invalid entry
159 for (i
= 0; i
< 64; i
++) {
160 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
161 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
163 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
170 // All entries are valid, try replacing unlocked entry
172 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
174 // Used entries are not replaced on first pass
176 for (i
= 0; i
< 64; i
++) {
177 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
179 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
181 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
182 strmmu
, (replace_used
?"used":"unused"), i
);
189 // Now reset used bit and search for unused entries again
191 for (i
= 0; i
< 64; i
++) {
192 TTE_SET_UNUSED(tlb
[i
].tte
);
197 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
204 static inline void address_mask(CPUState
*env1
, target_ulong
*addr
)
206 #ifdef TARGET_SPARC64
208 *addr
&= 0xffffffffULL
;
212 static void raise_exception(int tt
)
214 env
->exception_index
= tt
;
218 void HELPER(raise_exception
)(int tt
)
223 static inline void set_cwp(int new_cwp
)
225 cpu_set_cwp(env
, new_cwp
);
228 void helper_check_align(target_ulong addr
, uint32_t align
)
231 #ifdef DEBUG_UNALIGNED
232 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
233 "\n", addr
, env
->pc
);
235 raise_exception(TT_UNALIGNED
);
239 #define F_HELPER(name, p) void helper_f##name##p(void)
241 #define F_BINOP(name) \
242 float32 helper_f ## name ## s (float32 src1, float32 src2) \
244 return float32_ ## name (src1, src2, &env->fp_status); \
248 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
252 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
261 void helper_fsmuld(float32 src1
, float32 src2
)
263 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
264 float32_to_float64(src2
, &env
->fp_status
),
268 void helper_fdmulq(void)
270 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
271 float64_to_float128(DT1
, &env
->fp_status
),
275 float32
helper_fnegs(float32 src
)
277 return float32_chs(src
);
280 #ifdef TARGET_SPARC64
283 DT0
= float64_chs(DT1
);
288 QT0
= float128_chs(QT1
);
292 /* Integer to float conversion. */
293 float32
helper_fitos(int32_t src
)
295 return int32_to_float32(src
, &env
->fp_status
);
298 void helper_fitod(int32_t src
)
300 DT0
= int32_to_float64(src
, &env
->fp_status
);
303 void helper_fitoq(int32_t src
)
305 QT0
= int32_to_float128(src
, &env
->fp_status
);
308 #ifdef TARGET_SPARC64
309 float32
helper_fxtos(void)
311 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
316 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
321 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
326 /* floating point conversion */
327 float32
helper_fdtos(void)
329 return float64_to_float32(DT1
, &env
->fp_status
);
332 void helper_fstod(float32 src
)
334 DT0
= float32_to_float64(src
, &env
->fp_status
);
337 float32
helper_fqtos(void)
339 return float128_to_float32(QT1
, &env
->fp_status
);
342 void helper_fstoq(float32 src
)
344 QT0
= float32_to_float128(src
, &env
->fp_status
);
347 void helper_fqtod(void)
349 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
352 void helper_fdtoq(void)
354 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
357 /* Float to integer conversion. */
358 int32_t helper_fstoi(float32 src
)
360 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
363 int32_t helper_fdtoi(void)
365 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
368 int32_t helper_fqtoi(void)
370 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
373 #ifdef TARGET_SPARC64
374 void helper_fstox(float32 src
)
376 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
379 void helper_fdtox(void)
381 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
384 void helper_fqtox(void)
386 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
389 void helper_faligndata(void)
393 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
394 /* on many architectures a shift of 64 does nothing */
395 if ((env
->gsr
& 7) != 0) {
396 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
398 *((uint64_t *)&DT0
) = tmp
;
401 #ifdef HOST_WORDS_BIGENDIAN
402 #define VIS_B64(n) b[7 - (n)]
403 #define VIS_W64(n) w[3 - (n)]
404 #define VIS_SW64(n) sw[3 - (n)]
405 #define VIS_L64(n) l[1 - (n)]
406 #define VIS_B32(n) b[3 - (n)]
407 #define VIS_W32(n) w[1 - (n)]
409 #define VIS_B64(n) b[n]
410 #define VIS_W64(n) w[n]
411 #define VIS_SW64(n) sw[n]
412 #define VIS_L64(n) l[n]
413 #define VIS_B32(n) b[n]
414 #define VIS_W32(n) w[n]
432 void helper_fpmerge(void)
439 // Reverse calculation order to handle overlap
440 d
.VIS_B64(7) = s
.VIS_B64(3);
441 d
.VIS_B64(6) = d
.VIS_B64(3);
442 d
.VIS_B64(5) = s
.VIS_B64(2);
443 d
.VIS_B64(4) = d
.VIS_B64(2);
444 d
.VIS_B64(3) = s
.VIS_B64(1);
445 d
.VIS_B64(2) = d
.VIS_B64(1);
446 d
.VIS_B64(1) = s
.VIS_B64(0);
447 //d.VIS_B64(0) = d.VIS_B64(0);
452 void helper_fmul8x16(void)
461 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
462 if ((tmp & 0xff) > 0x7f) \
464 d.VIS_W64(r) = tmp >> 8;
475 void helper_fmul8x16al(void)
484 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
485 if ((tmp & 0xff) > 0x7f) \
487 d.VIS_W64(r) = tmp >> 8;
498 void helper_fmul8x16au(void)
507 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
508 if ((tmp & 0xff) > 0x7f) \
510 d.VIS_W64(r) = tmp >> 8;
521 void helper_fmul8sux16(void)
530 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
531 if ((tmp & 0xff) > 0x7f) \
533 d.VIS_W64(r) = tmp >> 8;
544 void helper_fmul8ulx16(void)
553 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
554 if ((tmp & 0xff) > 0x7f) \
556 d.VIS_W64(r) = tmp >> 8;
567 void helper_fmuld8sux16(void)
576 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
577 if ((tmp & 0xff) > 0x7f) \
581 // Reverse calculation order to handle overlap
589 void helper_fmuld8ulx16(void)
598 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
599 if ((tmp & 0xff) > 0x7f) \
603 // Reverse calculation order to handle overlap
611 void helper_fexpand(void)
616 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
618 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
619 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
620 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
621 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
626 #define VIS_HELPER(name, F) \
627 void name##16(void) \
634 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
635 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
636 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
637 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
642 uint32_t name##16s(uint32_t src1, uint32_t src2) \
649 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
650 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
655 void name##32(void) \
662 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
663 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
668 uint32_t name##32s(uint32_t src1, uint32_t src2) \
680 #define FADD(a, b) ((a) + (b))
681 #define FSUB(a, b) ((a) - (b))
682 VIS_HELPER(helper_fpadd
, FADD
)
683 VIS_HELPER(helper_fpsub
, FSUB
)
685 #define VIS_CMPHELPER(name, F) \
686 void name##16(void) \
693 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
694 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
695 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
696 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
701 void name##32(void) \
708 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
709 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
714 #define FCMPGT(a, b) ((a) > (b))
715 #define FCMPEQ(a, b) ((a) == (b))
716 #define FCMPLE(a, b) ((a) <= (b))
717 #define FCMPNE(a, b) ((a) != (b))
719 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
720 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
721 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
722 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
725 void helper_check_ieee_exceptions(void)
729 status
= get_float_exception_flags(&env
->fp_status
);
731 /* Copy IEEE 754 flags into FSR */
732 if (status
& float_flag_invalid
)
734 if (status
& float_flag_overflow
)
736 if (status
& float_flag_underflow
)
738 if (status
& float_flag_divbyzero
)
740 if (status
& float_flag_inexact
)
743 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
744 /* Unmasked exception, generate a trap */
745 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
746 raise_exception(TT_FP_EXCP
);
748 /* Accumulate exceptions */
749 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
754 void helper_clear_float_exceptions(void)
756 set_float_exception_flags(0, &env
->fp_status
);
759 float32
helper_fabss(float32 src
)
761 return float32_abs(src
);
764 #ifdef TARGET_SPARC64
765 void helper_fabsd(void)
767 DT0
= float64_abs(DT1
);
770 void helper_fabsq(void)
772 QT0
= float128_abs(QT1
);
776 float32
helper_fsqrts(float32 src
)
778 return float32_sqrt(src
, &env
->fp_status
);
781 void helper_fsqrtd(void)
783 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
786 void helper_fsqrtq(void)
788 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
791 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
792 void glue(helper_, name) (void) \
794 target_ulong new_fsr; \
796 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
797 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
798 case float_relation_unordered: \
799 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
800 if ((env->fsr & FSR_NVM) || TRAP) { \
801 env->fsr |= new_fsr; \
802 env->fsr |= FSR_NVC; \
803 env->fsr |= FSR_FTT_IEEE_EXCP; \
804 raise_exception(TT_FP_EXCP); \
806 env->fsr |= FSR_NVA; \
809 case float_relation_less: \
810 new_fsr = FSR_FCC0 << FS; \
812 case float_relation_greater: \
813 new_fsr = FSR_FCC1 << FS; \
819 env->fsr |= new_fsr; \
821 #define GEN_FCMPS(name, size, FS, TRAP) \
822 void glue(helper_, name)(float32 src1, float32 src2) \
824 target_ulong new_fsr; \
826 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
827 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
828 case float_relation_unordered: \
829 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
830 if ((env->fsr & FSR_NVM) || TRAP) { \
831 env->fsr |= new_fsr; \
832 env->fsr |= FSR_NVC; \
833 env->fsr |= FSR_FTT_IEEE_EXCP; \
834 raise_exception(TT_FP_EXCP); \
836 env->fsr |= FSR_NVA; \
839 case float_relation_less: \
840 new_fsr = FSR_FCC0 << FS; \
842 case float_relation_greater: \
843 new_fsr = FSR_FCC1 << FS; \
849 env->fsr |= new_fsr; \
852 GEN_FCMPS(fcmps
, float32
, 0, 0);
853 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
855 GEN_FCMPS(fcmpes
, float32
, 0, 1);
856 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
858 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
859 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
861 static uint32_t compute_all_flags(void)
863 return env
->psr
& PSR_ICC
;
866 static uint32_t compute_C_flags(void)
868 return env
->psr
& PSR_CARRY
;
871 static inline uint32_t get_NZ_icc(target_ulong dst
)
875 if (!(dst
& 0xffffffffULL
))
877 if ((int32_t) (dst
& 0xffffffffULL
) < 0)
882 #ifdef TARGET_SPARC64
883 static uint32_t compute_all_flags_xcc(void)
885 return env
->xcc
& PSR_ICC
;
888 static uint32_t compute_C_flags_xcc(void)
890 return env
->xcc
& PSR_CARRY
;
893 static inline uint32_t get_NZ_xcc(target_ulong dst
)
899 if ((int64_t)dst
< 0)
905 static inline uint32_t get_V_div_icc(target_ulong src2
)
914 static uint32_t compute_all_div(void)
918 ret
= get_NZ_icc(CC_DST
);
919 ret
|= get_V_div_icc(CC_SRC2
);
923 static uint32_t compute_C_div(void)
928 /* carry = (src1[31] & src2[31]) | ( ~dst[31] & (src1[31] | src2[31])) */
929 static inline uint32_t get_C_add_icc(target_ulong dst
, target_ulong src1
,
934 if (((src1
& (1ULL << 31)) & (src2
& (1ULL << 31)))
935 | ((~(dst
& (1ULL << 31)))
936 & ((src1
& (1ULL << 31)) | (src2
& (1ULL << 31)))))
941 static inline uint32_t get_V_add_icc(target_ulong dst
, target_ulong src1
,
946 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 31))
951 #ifdef TARGET_SPARC64
952 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
961 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
966 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63))
971 static uint32_t compute_all_add_xcc(void)
975 ret
= get_NZ_xcc(CC_DST
);
976 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
977 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
981 static uint32_t compute_C_add_xcc(void)
983 return get_C_add_xcc(CC_DST
, CC_SRC
);
987 static uint32_t compute_all_add(void)
991 ret
= get_NZ_icc(CC_DST
);
992 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
993 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
997 static uint32_t compute_C_add(void)
999 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1002 #ifdef TARGET_SPARC64
1003 static uint32_t compute_all_addx_xcc(void)
1007 ret
= get_NZ_xcc(CC_DST
);
1008 ret
|= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1009 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1010 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1014 static uint32_t compute_C_addx_xcc(void)
1018 ret
= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1019 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1024 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1028 if ((src1
| src2
) & 0x3)
1033 static uint32_t compute_all_tadd(void)
1037 ret
= get_NZ_icc(CC_DST
);
1038 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1039 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1040 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1044 static uint32_t compute_C_tadd(void)
1046 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1049 static uint32_t compute_all_taddtv(void)
1053 ret
= get_NZ_icc(CC_DST
);
1054 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1058 static uint32_t compute_C_taddtv(void)
1060 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1063 /* carry = (~src1[31] & src2[31]) | ( dst[31] & (~src1[31] | src2[31])) */
1064 static inline uint32_t get_C_sub_icc(target_ulong dst
, target_ulong src1
,
1069 if (((~(src1
& (1ULL << 31))) & (src2
& (1ULL << 31)))
1070 | ((dst
& (1ULL << 31)) & (( ~(src1
& (1ULL << 31)))
1071 | (src2
& (1ULL << 31)))))
1076 static inline uint32_t get_V_sub_icc(target_ulong dst
, target_ulong src1
,
1081 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 31))
1087 #ifdef TARGET_SPARC64
1088 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1097 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1102 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63))
1107 static uint32_t compute_all_sub_xcc(void)
1111 ret
= get_NZ_xcc(CC_DST
);
1112 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1113 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1117 static uint32_t compute_C_sub_xcc(void)
1119 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1123 static uint32_t compute_all_sub(void)
1127 ret
= get_NZ_icc(CC_DST
);
1128 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1129 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1133 static uint32_t compute_C_sub(void)
1135 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1138 #ifdef TARGET_SPARC64
1139 static uint32_t compute_all_subx_xcc(void)
1143 ret
= get_NZ_xcc(CC_DST
);
1144 ret
|= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1145 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1146 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1150 static uint32_t compute_C_subx_xcc(void)
1154 ret
= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1155 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1160 static uint32_t compute_all_tsub(void)
1164 ret
= get_NZ_icc(CC_DST
);
1165 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1166 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1167 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1171 static uint32_t compute_C_tsub(void)
1173 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1176 static uint32_t compute_all_tsubtv(void)
1180 ret
= get_NZ_icc(CC_DST
);
1181 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1185 static uint32_t compute_C_tsubtv(void)
1187 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1190 static uint32_t compute_all_logic(void)
1192 return get_NZ_icc(CC_DST
);
1195 static uint32_t compute_C_logic(void)
1200 #ifdef TARGET_SPARC64
1201 static uint32_t compute_all_logic_xcc(void)
1203 return get_NZ_xcc(CC_DST
);
1207 typedef struct CCTable
{
1208 uint32_t (*compute_all
)(void); /* return all the flags */
1209 uint32_t (*compute_c
)(void); /* return the C flag */
1212 static const CCTable icc_table
[CC_OP_NB
] = {
1213 /* CC_OP_DYNAMIC should never happen */
1214 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1215 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1216 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1217 [CC_OP_ADDX
] = { compute_all_add
, compute_C_add
},
1218 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_tadd
},
1219 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_taddtv
},
1220 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1221 [CC_OP_SUBX
] = { compute_all_sub
, compute_C_sub
},
1222 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_tsub
},
1223 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_tsubtv
},
1224 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1227 #ifdef TARGET_SPARC64
1228 static const CCTable xcc_table
[CC_OP_NB
] = {
1229 /* CC_OP_DYNAMIC should never happen */
1230 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1231 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1232 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1233 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1234 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1235 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1236 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1237 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1238 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1239 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1240 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1244 void helper_compute_psr(void)
1248 new_psr
= icc_table
[CC_OP
].compute_all();
1250 #ifdef TARGET_SPARC64
1251 new_psr
= xcc_table
[CC_OP
].compute_all();
1254 CC_OP
= CC_OP_FLAGS
;
1257 uint32_t helper_compute_C_icc(void)
1261 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1265 #ifdef TARGET_SPARC64
1266 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1267 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1268 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1270 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1271 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1272 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1274 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1275 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1276 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1278 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1279 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1280 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1282 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1283 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1284 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1286 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1287 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1288 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1292 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1294 static void dump_mxcc(CPUState
*env
)
1296 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1298 env
->mxccdata
[0], env
->mxccdata
[1],
1299 env
->mxccdata
[2], env
->mxccdata
[3]);
1300 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1302 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1304 env
->mxccregs
[0], env
->mxccregs
[1],
1305 env
->mxccregs
[2], env
->mxccregs
[3],
1306 env
->mxccregs
[4], env
->mxccregs
[5],
1307 env
->mxccregs
[6], env
->mxccregs
[7]);
1311 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1312 && defined(DEBUG_ASI)
1313 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1319 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1320 addr
, asi
, r1
& 0xff);
1323 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1324 addr
, asi
, r1
& 0xffff);
1327 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1328 addr
, asi
, r1
& 0xffffffff);
1331 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1338 #ifndef TARGET_SPARC64
1339 #ifndef CONFIG_USER_ONLY
1340 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1343 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1344 uint32_t last_addr
= addr
;
1347 helper_check_align(addr
, size
- 1);
1349 case 2: /* SuperSparc MXCC registers */
1351 case 0x01c00a00: /* MXCC control register */
1353 ret
= env
->mxccregs
[3];
1355 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1358 case 0x01c00a04: /* MXCC control register */
1360 ret
= env
->mxccregs
[3];
1362 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1365 case 0x01c00c00: /* Module reset register */
1367 ret
= env
->mxccregs
[5];
1368 // should we do something here?
1370 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1373 case 0x01c00f00: /* MBus port address register */
1375 ret
= env
->mxccregs
[7];
1377 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1381 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1385 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1386 "addr = %08x -> ret = %" PRIx64
","
1387 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1392 case 3: /* MMU probe */
1396 mmulev
= (addr
>> 8) & 15;
1400 ret
= mmu_probe(env
, addr
, mmulev
);
1401 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1405 case 4: /* read MMU regs */
1407 int reg
= (addr
>> 8) & 0x1f;
1409 ret
= env
->mmuregs
[reg
];
1410 if (reg
== 3) /* Fault status cleared on read */
1411 env
->mmuregs
[3] = 0;
1412 else if (reg
== 0x13) /* Fault status read */
1413 ret
= env
->mmuregs
[3];
1414 else if (reg
== 0x14) /* Fault address read */
1415 ret
= env
->mmuregs
[4];
1416 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1419 case 5: // Turbosparc ITLB Diagnostic
1420 case 6: // Turbosparc DTLB Diagnostic
1421 case 7: // Turbosparc IOTLB Diagnostic
1423 case 9: /* Supervisor code access */
1426 ret
= ldub_code(addr
);
1429 ret
= lduw_code(addr
);
1433 ret
= ldl_code(addr
);
1436 ret
= ldq_code(addr
);
1440 case 0xa: /* User data access */
1443 ret
= ldub_user(addr
);
1446 ret
= lduw_user(addr
);
1450 ret
= ldl_user(addr
);
1453 ret
= ldq_user(addr
);
1457 case 0xb: /* Supervisor data access */
1460 ret
= ldub_kernel(addr
);
1463 ret
= lduw_kernel(addr
);
1467 ret
= ldl_kernel(addr
);
1470 ret
= ldq_kernel(addr
);
1474 case 0xc: /* I-cache tag */
1475 case 0xd: /* I-cache data */
1476 case 0xe: /* D-cache tag */
1477 case 0xf: /* D-cache data */
1479 case 0x20: /* MMU passthrough */
1482 ret
= ldub_phys(addr
);
1485 ret
= lduw_phys(addr
);
1489 ret
= ldl_phys(addr
);
1492 ret
= ldq_phys(addr
);
1496 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1499 ret
= ldub_phys((target_phys_addr_t
)addr
1500 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1503 ret
= lduw_phys((target_phys_addr_t
)addr
1504 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1508 ret
= ldl_phys((target_phys_addr_t
)addr
1509 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1512 ret
= ldq_phys((target_phys_addr_t
)addr
1513 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1517 case 0x30: // Turbosparc secondary cache diagnostic
1518 case 0x31: // Turbosparc RAM snoop
1519 case 0x32: // Turbosparc page table descriptor diagnostic
1520 case 0x39: /* data cache diagnostic register */
1523 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1525 int reg
= (addr
>> 8) & 3;
1528 case 0: /* Breakpoint Value (Addr) */
1529 ret
= env
->mmubpregs
[reg
];
1531 case 1: /* Breakpoint Mask */
1532 ret
= env
->mmubpregs
[reg
];
1534 case 2: /* Breakpoint Control */
1535 ret
= env
->mmubpregs
[reg
];
1537 case 3: /* Breakpoint Status */
1538 ret
= env
->mmubpregs
[reg
];
1539 env
->mmubpregs
[reg
] = 0ULL;
1542 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1546 case 8: /* User code access, XXX */
1548 do_unassigned_access(addr
, 0, 0, asi
, size
);
1558 ret
= (int16_t) ret
;
1561 ret
= (int32_t) ret
;
1568 dump_asi("read ", last_addr
, asi
, size
, ret
);
1573 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1575 helper_check_align(addr
, size
- 1);
1577 case 2: /* SuperSparc MXCC registers */
1579 case 0x01c00000: /* MXCC stream data register 0 */
1581 env
->mxccdata
[0] = val
;
1583 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1586 case 0x01c00008: /* MXCC stream data register 1 */
1588 env
->mxccdata
[1] = val
;
1590 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1593 case 0x01c00010: /* MXCC stream data register 2 */
1595 env
->mxccdata
[2] = val
;
1597 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1600 case 0x01c00018: /* MXCC stream data register 3 */
1602 env
->mxccdata
[3] = val
;
1604 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1607 case 0x01c00100: /* MXCC stream source */
1609 env
->mxccregs
[0] = val
;
1611 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1613 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1615 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1617 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1619 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1622 case 0x01c00200: /* MXCC stream destination */
1624 env
->mxccregs
[1] = val
;
1626 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1628 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1630 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1632 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1634 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1637 case 0x01c00a00: /* MXCC control register */
1639 env
->mxccregs
[3] = val
;
1641 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1644 case 0x01c00a04: /* MXCC control register */
1646 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1649 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1652 case 0x01c00e00: /* MXCC error register */
1653 // writing a 1 bit clears the error
1655 env
->mxccregs
[6] &= ~val
;
1657 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1660 case 0x01c00f00: /* MBus port address register */
1662 env
->mxccregs
[7] = val
;
1664 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1668 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1672 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1673 asi
, size
, addr
, val
);
1678 case 3: /* MMU flush */
1682 mmulev
= (addr
>> 8) & 15;
1683 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1685 case 0: // flush page
1686 tlb_flush_page(env
, addr
& 0xfffff000);
1688 case 1: // flush segment (256k)
1689 case 2: // flush region (16M)
1690 case 3: // flush context (4G)
1691 case 4: // flush entire
1702 case 4: /* write MMU regs */
1704 int reg
= (addr
>> 8) & 0x1f;
1707 oldreg
= env
->mmuregs
[reg
];
1709 case 0: // Control Register
1710 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1712 // Mappings generated during no-fault mode or MMU
1713 // disabled mode are invalid in normal mode
1714 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1715 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1718 case 1: // Context Table Pointer Register
1719 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1721 case 2: // Context Register
1722 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1723 if (oldreg
!= env
->mmuregs
[reg
]) {
1724 /* we flush when the MMU context changes because
1725 QEMU has no MMU context support */
1729 case 3: // Synchronous Fault Status Register with Clear
1730 case 4: // Synchronous Fault Address Register
1732 case 0x10: // TLB Replacement Control Register
1733 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1735 case 0x13: // Synchronous Fault Status Register with Read and Clear
1736 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1738 case 0x14: // Synchronous Fault Address Register
1739 env
->mmuregs
[4] = val
;
1742 env
->mmuregs
[reg
] = val
;
1745 if (oldreg
!= env
->mmuregs
[reg
]) {
1746 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1747 reg
, oldreg
, env
->mmuregs
[reg
]);
1754 case 5: // Turbosparc ITLB Diagnostic
1755 case 6: // Turbosparc DTLB Diagnostic
1756 case 7: // Turbosparc IOTLB Diagnostic
1758 case 0xa: /* User data access */
1761 stb_user(addr
, val
);
1764 stw_user(addr
, val
);
1768 stl_user(addr
, val
);
1771 stq_user(addr
, val
);
1775 case 0xb: /* Supervisor data access */
1778 stb_kernel(addr
, val
);
1781 stw_kernel(addr
, val
);
1785 stl_kernel(addr
, val
);
1788 stq_kernel(addr
, val
);
1792 case 0xc: /* I-cache tag */
1793 case 0xd: /* I-cache data */
1794 case 0xe: /* D-cache tag */
1795 case 0xf: /* D-cache data */
1796 case 0x10: /* I/D-cache flush page */
1797 case 0x11: /* I/D-cache flush segment */
1798 case 0x12: /* I/D-cache flush region */
1799 case 0x13: /* I/D-cache flush context */
1800 case 0x14: /* I/D-cache flush user */
1802 case 0x17: /* Block copy, sta access */
1808 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1810 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1811 temp
= ldl_kernel(src
);
1812 stl_kernel(dst
, temp
);
1816 case 0x1f: /* Block fill, stda access */
1819 // fill 32 bytes with val
1821 uint32_t dst
= addr
& 7;
1823 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1824 stq_kernel(dst
, val
);
1827 case 0x20: /* MMU passthrough */
1831 stb_phys(addr
, val
);
1834 stw_phys(addr
, val
);
1838 stl_phys(addr
, val
);
1841 stq_phys(addr
, val
);
1846 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1850 stb_phys((target_phys_addr_t
)addr
1851 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1854 stw_phys((target_phys_addr_t
)addr
1855 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1859 stl_phys((target_phys_addr_t
)addr
1860 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1863 stq_phys((target_phys_addr_t
)addr
1864 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1869 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1870 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1871 // Turbosparc snoop RAM
1872 case 0x32: // store buffer control or Turbosparc page table
1873 // descriptor diagnostic
1874 case 0x36: /* I-cache flash clear */
1875 case 0x37: /* D-cache flash clear */
1876 case 0x4c: /* breakpoint action */
1878 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1880 int reg
= (addr
>> 8) & 3;
1883 case 0: /* Breakpoint Value (Addr) */
1884 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1886 case 1: /* Breakpoint Mask */
1887 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1889 case 2: /* Breakpoint Control */
1890 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1892 case 3: /* Breakpoint Status */
1893 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1896 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1900 case 8: /* User code access, XXX */
1901 case 9: /* Supervisor code access, XXX */
1903 do_unassigned_access(addr
, 1, 0, asi
, size
);
1907 dump_asi("write", addr
, asi
, size
, val
);
1911 #endif /* CONFIG_USER_ONLY */
1912 #else /* TARGET_SPARC64 */
1914 #ifdef CONFIG_USER_ONLY
1915 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1918 #if defined(DEBUG_ASI)
1919 target_ulong last_addr
= addr
;
1923 raise_exception(TT_PRIV_ACT
);
1925 helper_check_align(addr
, size
- 1);
1926 address_mask(env
, &addr
);
1929 case 0x82: // Primary no-fault
1930 case 0x8a: // Primary no-fault LE
1931 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1933 dump_asi("read ", last_addr
, asi
, size
, ret
);
1938 case 0x80: // Primary
1939 case 0x88: // Primary LE
1943 ret
= ldub_raw(addr
);
1946 ret
= lduw_raw(addr
);
1949 ret
= ldl_raw(addr
);
1953 ret
= ldq_raw(addr
);
1958 case 0x83: // Secondary no-fault
1959 case 0x8b: // Secondary no-fault LE
1960 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1962 dump_asi("read ", last_addr
, asi
, size
, ret
);
1967 case 0x81: // Secondary
1968 case 0x89: // Secondary LE
1975 /* Convert from little endian */
1977 case 0x88: // Primary LE
1978 case 0x89: // Secondary LE
1979 case 0x8a: // Primary no-fault LE
1980 case 0x8b: // Secondary no-fault LE
1998 /* Convert to signed number */
2005 ret
= (int16_t) ret
;
2008 ret
= (int32_t) ret
;
2015 dump_asi("read ", last_addr
, asi
, size
, ret
);
2020 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2023 dump_asi("write", addr
, asi
, size
, val
);
2026 raise_exception(TT_PRIV_ACT
);
2028 helper_check_align(addr
, size
- 1);
2029 address_mask(env
, &addr
);
2031 /* Convert to little endian */
2033 case 0x88: // Primary LE
2034 case 0x89: // Secondary LE
2053 case 0x80: // Primary
2054 case 0x88: // Primary LE
2073 case 0x81: // Secondary
2074 case 0x89: // Secondary LE
2078 case 0x82: // Primary no-fault, RO
2079 case 0x83: // Secondary no-fault, RO
2080 case 0x8a: // Primary no-fault LE, RO
2081 case 0x8b: // Secondary no-fault LE, RO
2083 do_unassigned_access(addr
, 1, 0, 1, size
);
2088 #else /* CONFIG_USER_ONLY */
2090 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2093 #if defined(DEBUG_ASI)
2094 target_ulong last_addr
= addr
;
2099 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2100 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2101 && asi
>= 0x30 && asi
< 0x80
2102 && !(env
->hpstate
& HS_PRIV
)))
2103 raise_exception(TT_PRIV_ACT
);
2105 helper_check_align(addr
, size
- 1);
2107 case 0x82: // Primary no-fault
2108 case 0x8a: // Primary no-fault LE
2109 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2111 dump_asi("read ", last_addr
, asi
, size
, ret
);
2116 case 0x10: // As if user primary
2117 case 0x18: // As if user primary LE
2118 case 0x80: // Primary
2119 case 0x88: // Primary LE
2120 case 0xe2: // UA2007 Primary block init
2121 case 0xe3: // UA2007 Secondary block init
2122 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2123 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2124 && env
->hpstate
& HS_PRIV
) {
2127 ret
= ldub_hypv(addr
);
2130 ret
= lduw_hypv(addr
);
2133 ret
= ldl_hypv(addr
);
2137 ret
= ldq_hypv(addr
);
2143 ret
= ldub_kernel(addr
);
2146 ret
= lduw_kernel(addr
);
2149 ret
= ldl_kernel(addr
);
2153 ret
= ldq_kernel(addr
);
2160 ret
= ldub_user(addr
);
2163 ret
= lduw_user(addr
);
2166 ret
= ldl_user(addr
);
2170 ret
= ldq_user(addr
);
2175 case 0x14: // Bypass
2176 case 0x15: // Bypass, non-cacheable
2177 case 0x1c: // Bypass LE
2178 case 0x1d: // Bypass, non-cacheable LE
2182 ret
= ldub_phys(addr
);
2185 ret
= lduw_phys(addr
);
2188 ret
= ldl_phys(addr
);
2192 ret
= ldq_phys(addr
);
2197 case 0x24: // Nucleus quad LDD 128 bit atomic
2198 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2199 // Only ldda allowed
2200 raise_exception(TT_ILL_INSN
);
2202 case 0x83: // Secondary no-fault
2203 case 0x8b: // Secondary no-fault LE
2204 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2206 dump_asi("read ", last_addr
, asi
, size
, ret
);
2211 case 0x04: // Nucleus
2212 case 0x0c: // Nucleus Little Endian (LE)
2213 case 0x11: // As if user secondary
2214 case 0x19: // As if user secondary LE
2215 case 0x4a: // UPA config
2216 case 0x81: // Secondary
2217 case 0x89: // Secondary LE
2223 case 0x50: // I-MMU regs
2225 int reg
= (addr
>> 3) & 0xf;
2228 // I-TSB Tag Target register
2229 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2231 ret
= env
->immuregs
[reg
];
2236 case 0x51: // I-MMU 8k TSB pointer
2238 // env->immuregs[5] holds I-MMU TSB register value
2239 // env->immuregs[6] holds I-MMU Tag Access register value
2240 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2244 case 0x52: // I-MMU 64k TSB pointer
2246 // env->immuregs[5] holds I-MMU TSB register value
2247 // env->immuregs[6] holds I-MMU Tag Access register value
2248 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2252 case 0x55: // I-MMU data access
2254 int reg
= (addr
>> 3) & 0x3f;
2256 ret
= env
->itlb
[reg
].tte
;
2259 case 0x56: // I-MMU tag read
2261 int reg
= (addr
>> 3) & 0x3f;
2263 ret
= env
->itlb
[reg
].tag
;
2266 case 0x58: // D-MMU regs
2268 int reg
= (addr
>> 3) & 0xf;
2271 // D-TSB Tag Target register
2272 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2274 ret
= env
->dmmuregs
[reg
];
2278 case 0x59: // D-MMU 8k TSB pointer
2280 // env->dmmuregs[5] holds D-MMU TSB register value
2281 // env->dmmuregs[6] holds D-MMU Tag Access register value
2282 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2286 case 0x5a: // D-MMU 64k TSB pointer
2288 // env->dmmuregs[5] holds D-MMU TSB register value
2289 // env->dmmuregs[6] holds D-MMU Tag Access register value
2290 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2294 case 0x5d: // D-MMU data access
2296 int reg
= (addr
>> 3) & 0x3f;
2298 ret
= env
->dtlb
[reg
].tte
;
2301 case 0x5e: // D-MMU tag read
2303 int reg
= (addr
>> 3) & 0x3f;
2305 ret
= env
->dtlb
[reg
].tag
;
2308 case 0x46: // D-cache data
2309 case 0x47: // D-cache tag access
2310 case 0x4b: // E-cache error enable
2311 case 0x4c: // E-cache asynchronous fault status
2312 case 0x4d: // E-cache asynchronous fault address
2313 case 0x4e: // E-cache tag data
2314 case 0x66: // I-cache instruction access
2315 case 0x67: // I-cache tag access
2316 case 0x6e: // I-cache predecode
2317 case 0x6f: // I-cache LRU etc.
2318 case 0x76: // E-cache tag
2319 case 0x7e: // E-cache tag
2321 case 0x5b: // D-MMU data pointer
2322 case 0x48: // Interrupt dispatch, RO
2323 case 0x49: // Interrupt data receive
2324 case 0x7f: // Incoming interrupt vector, RO
2327 case 0x54: // I-MMU data in, WO
2328 case 0x57: // I-MMU demap, WO
2329 case 0x5c: // D-MMU data in, WO
2330 case 0x5f: // D-MMU demap, WO
2331 case 0x77: // Interrupt vector, WO
2333 do_unassigned_access(addr
, 0, 0, 1, size
);
2338 /* Convert from little endian */
2340 case 0x0c: // Nucleus Little Endian (LE)
2341 case 0x18: // As if user primary LE
2342 case 0x19: // As if user secondary LE
2343 case 0x1c: // Bypass LE
2344 case 0x1d: // Bypass, non-cacheable LE
2345 case 0x88: // Primary LE
2346 case 0x89: // Secondary LE
2347 case 0x8a: // Primary no-fault LE
2348 case 0x8b: // Secondary no-fault LE
2366 /* Convert to signed number */
2373 ret
= (int16_t) ret
;
2376 ret
= (int32_t) ret
;
2383 dump_asi("read ", last_addr
, asi
, size
, ret
);
2388 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2391 dump_asi("write", addr
, asi
, size
, val
);
2396 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2397 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2398 && asi
>= 0x30 && asi
< 0x80
2399 && !(env
->hpstate
& HS_PRIV
)))
2400 raise_exception(TT_PRIV_ACT
);
2402 helper_check_align(addr
, size
- 1);
2403 /* Convert to little endian */
2405 case 0x0c: // Nucleus Little Endian (LE)
2406 case 0x18: // As if user primary LE
2407 case 0x19: // As if user secondary LE
2408 case 0x1c: // Bypass LE
2409 case 0x1d: // Bypass, non-cacheable LE
2410 case 0x88: // Primary LE
2411 case 0x89: // Secondary LE
2430 case 0x10: // As if user primary
2431 case 0x18: // As if user primary LE
2432 case 0x80: // Primary
2433 case 0x88: // Primary LE
2434 case 0xe2: // UA2007 Primary block init
2435 case 0xe3: // UA2007 Secondary block init
2436 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2437 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2438 && env
->hpstate
& HS_PRIV
) {
2441 stb_hypv(addr
, val
);
2444 stw_hypv(addr
, val
);
2447 stl_hypv(addr
, val
);
2451 stq_hypv(addr
, val
);
2457 stb_kernel(addr
, val
);
2460 stw_kernel(addr
, val
);
2463 stl_kernel(addr
, val
);
2467 stq_kernel(addr
, val
);
2474 stb_user(addr
, val
);
2477 stw_user(addr
, val
);
2480 stl_user(addr
, val
);
2484 stq_user(addr
, val
);
2489 case 0x14: // Bypass
2490 case 0x15: // Bypass, non-cacheable
2491 case 0x1c: // Bypass LE
2492 case 0x1d: // Bypass, non-cacheable LE
2496 stb_phys(addr
, val
);
2499 stw_phys(addr
, val
);
2502 stl_phys(addr
, val
);
2506 stq_phys(addr
, val
);
2511 case 0x24: // Nucleus quad LDD 128 bit atomic
2512 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2513 // Only ldda allowed
2514 raise_exception(TT_ILL_INSN
);
2516 case 0x04: // Nucleus
2517 case 0x0c: // Nucleus Little Endian (LE)
2518 case 0x11: // As if user secondary
2519 case 0x19: // As if user secondary LE
2520 case 0x4a: // UPA config
2521 case 0x81: // Secondary
2522 case 0x89: // Secondary LE
2530 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
2531 // Mappings generated during D/I MMU disabled mode are
2532 // invalid in normal mode
2533 if (oldreg
!= env
->lsu
) {
2534 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
2543 case 0x50: // I-MMU regs
2545 int reg
= (addr
>> 3) & 0xf;
2548 oldreg
= env
->immuregs
[reg
];
2552 case 1: // Not in I-MMU
2557 val
= 0; // Clear SFSR
2558 env
->immu
.sfsr
= val
;
2562 case 5: // TSB access
2563 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
2564 PRIx64
"\n", env
->immu
.tsb
, val
);
2565 env
->immu
.tsb
= val
;
2567 case 6: // Tag access
2568 env
->immu
.tag_access
= val
;
2577 if (oldreg
!= env
->immuregs
[reg
]) {
2578 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2579 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2586 case 0x54: // I-MMU data in
2587 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
2589 case 0x55: // I-MMU data access
2593 unsigned int i
= (addr
>> 3) & 0x3f;
2595 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
2598 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
2603 case 0x57: // I-MMU demap
2604 demap_tlb(env
->itlb
, val
, "immu", env
);
2606 case 0x58: // D-MMU regs
2608 int reg
= (addr
>> 3) & 0xf;
2611 oldreg
= env
->dmmuregs
[reg
];
2617 if ((val
& 1) == 0) {
2618 val
= 0; // Clear SFSR, Fault address
2621 env
->dmmu
.sfsr
= val
;
2623 case 1: // Primary context
2624 env
->dmmu
.mmu_primary_context
= val
;
2626 case 2: // Secondary context
2627 env
->dmmu
.mmu_secondary_context
= val
;
2629 case 5: // TSB access
2630 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
2631 PRIx64
"\n", env
->dmmu
.tsb
, val
);
2632 env
->dmmu
.tsb
= val
;
2634 case 6: // Tag access
2635 env
->dmmu
.tag_access
= val
;
2637 case 7: // Virtual Watchpoint
2638 case 8: // Physical Watchpoint
2640 env
->dmmuregs
[reg
] = val
;
2644 if (oldreg
!= env
->dmmuregs
[reg
]) {
2645 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2646 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2653 case 0x5c: // D-MMU data in
2654 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
2656 case 0x5d: // D-MMU data access
2658 unsigned int i
= (addr
>> 3) & 0x3f;
2660 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
2663 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
2668 case 0x5f: // D-MMU demap
2669 demap_tlb(env
->dtlb
, val
, "dmmu", env
);
2671 case 0x49: // Interrupt data receive
2674 case 0x46: // D-cache data
2675 case 0x47: // D-cache tag access
2676 case 0x4b: // E-cache error enable
2677 case 0x4c: // E-cache asynchronous fault status
2678 case 0x4d: // E-cache asynchronous fault address
2679 case 0x4e: // E-cache tag data
2680 case 0x66: // I-cache instruction access
2681 case 0x67: // I-cache tag access
2682 case 0x6e: // I-cache predecode
2683 case 0x6f: // I-cache LRU etc.
2684 case 0x76: // E-cache tag
2685 case 0x7e: // E-cache tag
2687 case 0x51: // I-MMU 8k TSB pointer, RO
2688 case 0x52: // I-MMU 64k TSB pointer, RO
2689 case 0x56: // I-MMU tag read, RO
2690 case 0x59: // D-MMU 8k TSB pointer, RO
2691 case 0x5a: // D-MMU 64k TSB pointer, RO
2692 case 0x5b: // D-MMU data pointer, RO
2693 case 0x5e: // D-MMU tag read, RO
2694 case 0x48: // Interrupt dispatch, RO
2695 case 0x7f: // Incoming interrupt vector, RO
2696 case 0x82: // Primary no-fault, RO
2697 case 0x83: // Secondary no-fault, RO
2698 case 0x8a: // Primary no-fault LE, RO
2699 case 0x8b: // Secondary no-fault LE, RO
2701 do_unassigned_access(addr
, 1, 0, 1, size
);
2705 #endif /* CONFIG_USER_ONLY */
2707 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2709 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2710 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2711 && asi
>= 0x30 && asi
< 0x80
2712 && !(env
->hpstate
& HS_PRIV
)))
2713 raise_exception(TT_PRIV_ACT
);
2716 case 0x24: // Nucleus quad LDD 128 bit atomic
2717 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2718 helper_check_align(addr
, 0xf);
2720 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2722 bswap64s(&env
->gregs
[1]);
2723 } else if (rd
< 8) {
2724 env
->gregs
[rd
] = ldq_kernel(addr
);
2725 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2727 bswap64s(&env
->gregs
[rd
]);
2728 bswap64s(&env
->gregs
[rd
+ 1]);
2731 env
->regwptr
[rd
] = ldq_kernel(addr
);
2732 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2734 bswap64s(&env
->regwptr
[rd
]);
2735 bswap64s(&env
->regwptr
[rd
+ 1]);
2740 helper_check_align(addr
, 0x3);
2742 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2744 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2745 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2747 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2748 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2754 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2759 helper_check_align(addr
, 3);
2761 case 0xf0: // Block load primary
2762 case 0xf1: // Block load secondary
2763 case 0xf8: // Block load primary LE
2764 case 0xf9: // Block load secondary LE
2766 raise_exception(TT_ILL_INSN
);
2769 helper_check_align(addr
, 0x3f);
2770 for (i
= 0; i
< 16; i
++) {
2771 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2781 val
= helper_ld_asi(addr
, asi
, size
, 0);
2785 *((uint32_t *)&env
->fpr
[rd
]) = val
;
2788 *((int64_t *)&DT0
) = val
;
2796 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2799 target_ulong val
= 0;
2801 helper_check_align(addr
, 3);
2803 case 0xe0: // UA2007 Block commit store primary (cache flush)
2804 case 0xe1: // UA2007 Block commit store secondary (cache flush)
2805 case 0xf0: // Block store primary
2806 case 0xf1: // Block store secondary
2807 case 0xf8: // Block store primary LE
2808 case 0xf9: // Block store secondary LE
2810 raise_exception(TT_ILL_INSN
);
2813 helper_check_align(addr
, 0x3f);
2814 for (i
= 0; i
< 16; i
++) {
2815 val
= *(uint32_t *)&env
->fpr
[rd
++];
2816 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2828 val
= *((uint32_t *)&env
->fpr
[rd
]);
2831 val
= *((int64_t *)&DT0
);
2837 helper_st_asi(addr
, val
, asi
, size
);
2840 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2841 target_ulong val2
, uint32_t asi
)
2845 val2
&= 0xffffffffUL
;
2846 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2847 ret
&= 0xffffffffUL
;
2849 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
2853 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2854 target_ulong val2
, uint32_t asi
)
2858 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2860 helper_st_asi(addr
, val1
, asi
, 8);
2863 #endif /* TARGET_SPARC64 */
2865 #ifndef TARGET_SPARC64
2866 void helper_rett(void)
2870 if (env
->psret
== 1)
2871 raise_exception(TT_ILL_INSN
);
2874 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2875 if (env
->wim
& (1 << cwp
)) {
2876 raise_exception(TT_WIN_UNF
);
2879 env
->psrs
= env
->psrps
;
2883 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2888 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2892 raise_exception(TT_DIV_ZERO
);
2896 if (x0
> 0xffffffff) {
2905 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2910 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2914 raise_exception(TT_DIV_ZERO
);
2918 if ((int32_t) x0
!= x0
) {
2920 return x0
< 0? 0x80000000: 0x7fffffff;
2927 void helper_stdf(target_ulong addr
, int mem_idx
)
2929 helper_check_align(addr
, 7);
2930 #if !defined(CONFIG_USER_ONLY)
2933 stfq_user(addr
, DT0
);
2936 stfq_kernel(addr
, DT0
);
2938 #ifdef TARGET_SPARC64
2940 stfq_hypv(addr
, DT0
);
2947 address_mask(env
, &addr
);
2948 stfq_raw(addr
, DT0
);
2952 void helper_lddf(target_ulong addr
, int mem_idx
)
2954 helper_check_align(addr
, 7);
2955 #if !defined(CONFIG_USER_ONLY)
2958 DT0
= ldfq_user(addr
);
2961 DT0
= ldfq_kernel(addr
);
2963 #ifdef TARGET_SPARC64
2965 DT0
= ldfq_hypv(addr
);
2972 address_mask(env
, &addr
);
2973 DT0
= ldfq_raw(addr
);
2977 void helper_ldqf(target_ulong addr
, int mem_idx
)
2979 // XXX add 128 bit load
2982 helper_check_align(addr
, 7);
2983 #if !defined(CONFIG_USER_ONLY)
2986 u
.ll
.upper
= ldq_user(addr
);
2987 u
.ll
.lower
= ldq_user(addr
+ 8);
2991 u
.ll
.upper
= ldq_kernel(addr
);
2992 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2995 #ifdef TARGET_SPARC64
2997 u
.ll
.upper
= ldq_hypv(addr
);
2998 u
.ll
.lower
= ldq_hypv(addr
+ 8);
3006 address_mask(env
, &addr
);
3007 u
.ll
.upper
= ldq_raw(addr
);
3008 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
3013 void helper_stqf(target_ulong addr
, int mem_idx
)
3015 // XXX add 128 bit store
3018 helper_check_align(addr
, 7);
3019 #if !defined(CONFIG_USER_ONLY)
3023 stq_user(addr
, u
.ll
.upper
);
3024 stq_user(addr
+ 8, u
.ll
.lower
);
3028 stq_kernel(addr
, u
.ll
.upper
);
3029 stq_kernel(addr
+ 8, u
.ll
.lower
);
3031 #ifdef TARGET_SPARC64
3034 stq_hypv(addr
, u
.ll
.upper
);
3035 stq_hypv(addr
+ 8, u
.ll
.lower
);
3043 address_mask(env
, &addr
);
3044 stq_raw(addr
, u
.ll
.upper
);
3045 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
3049 static inline void set_fsr(void)
3053 switch (env
->fsr
& FSR_RD_MASK
) {
3054 case FSR_RD_NEAREST
:
3055 rnd_mode
= float_round_nearest_even
;
3059 rnd_mode
= float_round_to_zero
;
3062 rnd_mode
= float_round_up
;
3065 rnd_mode
= float_round_down
;
3068 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3071 void helper_ldfsr(uint32_t new_fsr
)
3073 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3077 #ifdef TARGET_SPARC64
3078 void helper_ldxfsr(uint64_t new_fsr
)
3080 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3085 void helper_debug(void)
3087 env
->exception_index
= EXCP_DEBUG
;
3091 #ifndef TARGET_SPARC64
3092 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3094 void helper_save(void)
3098 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3099 if (env
->wim
& (1 << cwp
)) {
3100 raise_exception(TT_WIN_OVF
);
3105 void helper_restore(void)
3109 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3110 if (env
->wim
& (1 << cwp
)) {
3111 raise_exception(TT_WIN_UNF
);
3116 void helper_wrpsr(target_ulong new_psr
)
3118 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
3119 raise_exception(TT_ILL_INSN
);
3121 PUT_PSR(env
, new_psr
);
3124 target_ulong
helper_rdpsr(void)
3126 return GET_PSR(env
);
3130 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3132 void helper_save(void)
3136 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3137 if (env
->cansave
== 0) {
3138 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3139 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3140 ((env
->wstate
& 0x7) << 2)));
3142 if (env
->cleanwin
- env
->canrestore
== 0) {
3143 // XXX Clean windows without trap
3144 raise_exception(TT_CLRWIN
);
3153 void helper_restore(void)
3157 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3158 if (env
->canrestore
== 0) {
3159 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3160 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3161 ((env
->wstate
& 0x7) << 2)));
3169 void helper_flushw(void)
3171 if (env
->cansave
!= env
->nwindows
- 2) {
3172 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3173 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3174 ((env
->wstate
& 0x7) << 2)));
3178 void helper_saved(void)
3181 if (env
->otherwin
== 0)
3187 void helper_restored(void)
3190 if (env
->cleanwin
< env
->nwindows
- 1)
3192 if (env
->otherwin
== 0)
3198 target_ulong
helper_rdccr(void)
3200 return GET_CCR(env
);
3203 void helper_wrccr(target_ulong new_ccr
)
3205 PUT_CCR(env
, new_ccr
);
3208 // CWP handling is reversed in V9, but we still use the V8 register
3210 target_ulong
helper_rdcwp(void)
3212 return GET_CWP64(env
);
3215 void helper_wrcwp(target_ulong new_cwp
)
3217 PUT_CWP64(env
, new_cwp
);
3220 // This function uses non-native bit order
3221 #define GET_FIELD(X, FROM, TO) \
3222 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3224 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3225 #define GET_FIELD_SP(X, FROM, TO) \
3226 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3228 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3230 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3231 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3232 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3233 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3234 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3235 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3236 (((pixel_addr
>> 55) & 1) << 4) |
3237 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3238 GET_FIELD_SP(pixel_addr
, 11, 12);
3241 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3245 tmp
= addr
+ offset
;
3247 env
->gsr
|= tmp
& 7ULL;
3251 target_ulong
helper_popc(target_ulong val
)
3253 return ctpop64(val
);
3256 static inline uint64_t *get_gregset(uint32_t pstate
)
3260 DPRINTF_PSTATE("ERROR in get_gregset: active pstate bits=%x%s%s%s\n",
3262 (pstate
& PS_IG
) ? " IG" : "",
3263 (pstate
& PS_MG
) ? " MG" : "",
3264 (pstate
& PS_AG
) ? " AG" : "");
3265 /* pass through to normal set of global registers */
3277 static inline void change_pstate(uint32_t new_pstate
)
3279 uint32_t pstate_regs
, new_pstate_regs
;
3280 uint64_t *src
, *dst
;
3282 if (env
->def
->features
& CPU_FEATURE_GL
) {
3283 // PS_AG is not implemented in this case
3284 new_pstate
&= ~PS_AG
;
3287 pstate_regs
= env
->pstate
& 0xc01;
3288 new_pstate_regs
= new_pstate
& 0xc01;
3290 if (new_pstate_regs
!= pstate_regs
) {
3291 DPRINTF_PSTATE("change_pstate: switching regs old=%x new=%x\n",
3292 pstate_regs
, new_pstate_regs
);
3293 // Switch global register bank
3294 src
= get_gregset(new_pstate_regs
);
3295 dst
= get_gregset(pstate_regs
);
3296 memcpy32(dst
, env
->gregs
);
3297 memcpy32(env
->gregs
, src
);
3300 DPRINTF_PSTATE("change_pstate: regs new=%x (unchanged)\n",
3303 env
->pstate
= new_pstate
;
3306 void helper_wrpstate(target_ulong new_state
)
3308 change_pstate(new_state
& 0xf3f);
3310 #if !defined(CONFIG_USER_ONLY)
3311 if (cpu_interrupts_enabled(env
)) {
3312 cpu_check_irqs(env
);
3317 void helper_wrpil(target_ulong new_pil
)
3319 #if !defined(CONFIG_USER_ONLY)
3320 DPRINTF_PSTATE("helper_wrpil old=%x new=%x\n",
3321 env
->psrpil
, (uint32_t)new_pil
);
3323 env
->psrpil
= new_pil
;
3325 if (cpu_interrupts_enabled(env
)) {
3326 cpu_check_irqs(env
);
3331 void helper_done(void)
3333 trap_state
* tsptr
= cpu_tsptr(env
);
3335 env
->pc
= tsptr
->tnpc
;
3336 env
->npc
= tsptr
->tnpc
+ 4;
3337 PUT_CCR(env
, tsptr
->tstate
>> 32);
3338 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3339 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3340 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3343 DPRINTF_PSTATE("... helper_done tl=%d\n", env
->tl
);
3345 #if !defined(CONFIG_USER_ONLY)
3346 if (cpu_interrupts_enabled(env
)) {
3347 cpu_check_irqs(env
);
3352 void helper_retry(void)
3354 trap_state
* tsptr
= cpu_tsptr(env
);
3356 env
->pc
= tsptr
->tpc
;
3357 env
->npc
= tsptr
->tnpc
;
3358 PUT_CCR(env
, tsptr
->tstate
>> 32);
3359 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3360 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3361 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3364 DPRINTF_PSTATE("... helper_retry tl=%d\n", env
->tl
);
3366 #if !defined(CONFIG_USER_ONLY)
3367 if (cpu_interrupts_enabled(env
)) {
3368 cpu_check_irqs(env
);
3373 static void do_modify_softint(const char* operation
, uint32_t value
)
3375 if (env
->softint
!= value
) {
3376 env
->softint
= value
;
3377 DPRINTF_PSTATE(": %s new %08x\n", operation
, env
->softint
);
3378 #if !defined(CONFIG_USER_ONLY)
3379 if (cpu_interrupts_enabled(env
)) {
3380 cpu_check_irqs(env
);
3386 void helper_set_softint(uint64_t value
)
3388 do_modify_softint("helper_set_softint", env
->softint
| (uint32_t)value
);
3391 void helper_clear_softint(uint64_t value
)
3393 do_modify_softint("helper_clear_softint", env
->softint
& (uint32_t)~value
);
3396 void helper_write_softint(uint64_t value
)
3398 do_modify_softint("helper_write_softint", (uint32_t)value
);
3402 void helper_flush(target_ulong addr
)
3405 tb_invalidate_page_range(addr
, addr
+ 8);
3408 #ifdef TARGET_SPARC64
3410 static const char * const excp_names
[0x80] = {
3411 [TT_TFAULT
] = "Instruction Access Fault",
3412 [TT_TMISS
] = "Instruction Access MMU Miss",
3413 [TT_CODE_ACCESS
] = "Instruction Access Error",
3414 [TT_ILL_INSN
] = "Illegal Instruction",
3415 [TT_PRIV_INSN
] = "Privileged Instruction",
3416 [TT_NFPU_INSN
] = "FPU Disabled",
3417 [TT_FP_EXCP
] = "FPU Exception",
3418 [TT_TOVF
] = "Tag Overflow",
3419 [TT_CLRWIN
] = "Clean Windows",
3420 [TT_DIV_ZERO
] = "Division By Zero",
3421 [TT_DFAULT
] = "Data Access Fault",
3422 [TT_DMISS
] = "Data Access MMU Miss",
3423 [TT_DATA_ACCESS
] = "Data Access Error",
3424 [TT_DPROT
] = "Data Protection Error",
3425 [TT_UNALIGNED
] = "Unaligned Memory Access",
3426 [TT_PRIV_ACT
] = "Privileged Action",
3427 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3428 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3429 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3430 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3431 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3432 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3433 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3434 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3435 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3436 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3437 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3438 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3439 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3440 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3441 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3445 trap_state
* cpu_tsptr(CPUState
* env
)
3447 return &env
->ts
[env
->tl
& MAXTL_MASK
];
3450 void do_interrupt(CPUState
*env
)
3452 int intno
= env
->exception_index
;
3456 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3460 if (intno
< 0 || intno
>= 0x180)
3462 else if (intno
>= 0x100)
3463 name
= "Trap Instruction";
3464 else if (intno
>= 0xc0)
3465 name
= "Window Fill";
3466 else if (intno
>= 0x80)
3467 name
= "Window Spill";
3469 name
= excp_names
[intno
];
3474 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
3475 " SP=%016" PRIx64
"\n",
3478 env
->npc
, env
->regwptr
[6]);
3479 log_cpu_state(env
, 0);
3486 ptr
= (uint8_t *)env
->pc
;
3487 for(i
= 0; i
< 16; i
++) {
3488 qemu_log(" %02x", ldub(ptr
+ i
));
3496 #if !defined(CONFIG_USER_ONLY)
3497 if (env
->tl
>= env
->maxtl
) {
3498 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
3499 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
3503 if (env
->tl
< env
->maxtl
- 1) {
3506 env
->pstate
|= PS_RED
;
3507 if (env
->tl
< env
->maxtl
)
3510 tsptr
= cpu_tsptr(env
);
3512 tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
3513 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
3515 tsptr
->tpc
= env
->pc
;
3516 tsptr
->tnpc
= env
->npc
;
3521 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
3525 case TT_TMISS
... TT_TMISS
+ 3:
3526 case TT_DMISS
... TT_DMISS
+ 3:
3527 case TT_DPROT
... TT_DPROT
+ 3:
3528 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
3531 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
3535 if (intno
== TT_CLRWIN
)
3536 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
3537 else if ((intno
& 0x1c0) == TT_SPILL
)
3538 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
3539 else if ((intno
& 0x1c0) == TT_FILL
)
3540 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
3541 env
->tbr
&= ~0x7fffULL
;
3542 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
3544 env
->npc
= env
->pc
+ 4;
3545 env
->exception_index
= -1;
3549 static const char * const excp_names
[0x80] = {
3550 [TT_TFAULT
] = "Instruction Access Fault",
3551 [TT_ILL_INSN
] = "Illegal Instruction",
3552 [TT_PRIV_INSN
] = "Privileged Instruction",
3553 [TT_NFPU_INSN
] = "FPU Disabled",
3554 [TT_WIN_OVF
] = "Window Overflow",
3555 [TT_WIN_UNF
] = "Window Underflow",
3556 [TT_UNALIGNED
] = "Unaligned Memory Access",
3557 [TT_FP_EXCP
] = "FPU Exception",
3558 [TT_DFAULT
] = "Data Access Fault",
3559 [TT_TOVF
] = "Tag Overflow",
3560 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3561 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3562 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3563 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3564 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3565 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3566 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3567 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3568 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3569 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3570 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3571 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3572 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3573 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3574 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3575 [TT_TOVF
] = "Tag Overflow",
3576 [TT_CODE_ACCESS
] = "Instruction Access Error",
3577 [TT_DATA_ACCESS
] = "Data Access Error",
3578 [TT_DIV_ZERO
] = "Division By Zero",
3579 [TT_NCP_INSN
] = "Coprocessor Disabled",
3583 void do_interrupt(CPUState
*env
)
3585 int cwp
, intno
= env
->exception_index
;
3588 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3592 if (intno
< 0 || intno
>= 0x100)
3594 else if (intno
>= 0x80)
3595 name
= "Trap Instruction";
3597 name
= excp_names
[intno
];
3602 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
3605 env
->npc
, env
->regwptr
[6]);
3606 log_cpu_state(env
, 0);
3613 ptr
= (uint8_t *)env
->pc
;
3614 for(i
= 0; i
< 16; i
++) {
3615 qemu_log(" %02x", ldub(ptr
+ i
));
3623 #if !defined(CONFIG_USER_ONLY)
3624 if (env
->psret
== 0) {
3625 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
3626 env
->exception_index
);
3631 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3632 cpu_set_cwp(env
, cwp
);
3633 env
->regwptr
[9] = env
->pc
;
3634 env
->regwptr
[10] = env
->npc
;
3635 env
->psrps
= env
->psrs
;
3637 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
3639 env
->npc
= env
->pc
+ 4;
3640 env
->exception_index
= -1;
3644 #if !defined(CONFIG_USER_ONLY)
3646 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3649 #define MMUSUFFIX _mmu
3650 #define ALIGNED_ONLY
3653 #include "softmmu_template.h"
3656 #include "softmmu_template.h"
3659 #include "softmmu_template.h"
3662 #include "softmmu_template.h"
3664 /* XXX: make it generic ? */
3665 static void cpu_restore_state2(void *retaddr
)
3667 TranslationBlock
*tb
;
3671 /* now we have a real cpu fault */
3672 pc
= (unsigned long)retaddr
;
3673 tb
= tb_find_pc(pc
);
3675 /* the PC is inside the translated code. It means that we have
3676 a virtual CPU fault */
3677 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
3682 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3685 #ifdef DEBUG_UNALIGNED
3686 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3687 "\n", addr
, env
->pc
);
3689 cpu_restore_state2(retaddr
);
3690 raise_exception(TT_UNALIGNED
);
3693 /* try to fill the TLB and return an exception if error. If retaddr is
3694 NULL, it means that the function was called in C code (i.e. not
3695 from generated code or from helper.c) */
3696 /* XXX: fix it to restore all registers */
3697 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3700 CPUState
*saved_env
;
3702 /* XXX: hack to restore env in all cases, even if not called from
3705 env
= cpu_single_env
;
3707 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3709 cpu_restore_state2(retaddr
);
3715 #endif /* !CONFIG_USER_ONLY */
3717 #ifndef TARGET_SPARC64
3718 #if !defined(CONFIG_USER_ONLY)
3719 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3720 int is_asi
, int size
)
3722 CPUState
*saved_env
;
3725 /* XXX: hack to restore env in all cases, even if not called from
3728 env
= cpu_single_env
;
3729 #ifdef DEBUG_UNASSIGNED
3731 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3732 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3733 is_exec
? "exec" : is_write
? "write" : "read", size
,
3734 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
3736 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3737 " from " TARGET_FMT_lx
"\n",
3738 is_exec
? "exec" : is_write
? "write" : "read", size
,
3739 size
== 1 ? "" : "s", addr
, env
->pc
);
3741 /* Don't overwrite translation and access faults */
3742 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
3743 if ((fault_type
> 4) || (fault_type
== 0)) {
3744 env
->mmuregs
[3] = 0; /* Fault status register */
3746 env
->mmuregs
[3] |= 1 << 16;
3748 env
->mmuregs
[3] |= 1 << 5;
3750 env
->mmuregs
[3] |= 1 << 6;
3752 env
->mmuregs
[3] |= 1 << 7;
3753 env
->mmuregs
[3] |= (5 << 2) | 2;
3754 /* SuperSPARC will never place instruction fault addresses in the FAR */
3756 env
->mmuregs
[4] = addr
; /* Fault address register */
3759 /* overflow (same type fault was not read before another fault) */
3760 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
3761 env
->mmuregs
[3] |= 1;
3764 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3766 raise_exception(TT_CODE_ACCESS
);
3768 raise_exception(TT_DATA_ACCESS
);
3771 /* flush neverland mappings created during no-fault mode,
3772 so the sequential MMU faults report proper fault types */
3773 if (env
->mmuregs
[0] & MMU_NF
) {
3781 #if defined(CONFIG_USER_ONLY)
3782 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
3783 int is_asi
, int size
)
3785 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3786 int is_asi
, int size
)
3789 CPUState
*saved_env
;
3791 /* XXX: hack to restore env in all cases, even if not called from
3794 env
= cpu_single_env
;
3796 #ifdef DEBUG_UNASSIGNED
3797 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3798 "\n", addr
, env
->pc
);
3802 raise_exception(TT_CODE_ACCESS
);
3804 raise_exception(TT_DATA_ACCESS
);
3811 #ifdef TARGET_SPARC64
3812 void helper_tick_set_count(void *opaque
, uint64_t count
)
3814 #if !defined(CONFIG_USER_ONLY)
3815 cpu_tick_set_count(opaque
, count
);
3819 uint64_t helper_tick_get_count(void *opaque
)
3821 #if !defined(CONFIG_USER_ONLY)
3822 return cpu_tick_get_count(opaque
);
3828 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
3830 #if !defined(CONFIG_USER_ONLY)
3831 cpu_tick_set_limit(opaque
, limit
);