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 target_ulong
address_mask(CPUState
*env1
, target_ulong addr
)
206 #ifdef TARGET_SPARC64
208 addr
&= 0xffffffffULL
;
213 static void raise_exception(int tt
)
215 env
->exception_index
= tt
;
219 void HELPER(raise_exception
)(int tt
)
224 static inline void set_cwp(int new_cwp
)
226 cpu_set_cwp(env
, new_cwp
);
229 void helper_check_align(target_ulong addr
, uint32_t align
)
232 #ifdef DEBUG_UNALIGNED
233 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
234 "\n", addr
, env
->pc
);
236 raise_exception(TT_UNALIGNED
);
240 #define F_HELPER(name, p) void helper_f##name##p(void)
242 #define F_BINOP(name) \
243 float32 helper_f ## name ## s (float32 src1, float32 src2) \
245 return float32_ ## name (src1, src2, &env->fp_status); \
249 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
253 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
262 void helper_fsmuld(float32 src1
, float32 src2
)
264 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
265 float32_to_float64(src2
, &env
->fp_status
),
269 void helper_fdmulq(void)
271 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
272 float64_to_float128(DT1
, &env
->fp_status
),
276 float32
helper_fnegs(float32 src
)
278 return float32_chs(src
);
281 #ifdef TARGET_SPARC64
284 DT0
= float64_chs(DT1
);
289 QT0
= float128_chs(QT1
);
293 /* Integer to float conversion. */
294 float32
helper_fitos(int32_t src
)
296 return int32_to_float32(src
, &env
->fp_status
);
299 void helper_fitod(int32_t src
)
301 DT0
= int32_to_float64(src
, &env
->fp_status
);
304 void helper_fitoq(int32_t src
)
306 QT0
= int32_to_float128(src
, &env
->fp_status
);
309 #ifdef TARGET_SPARC64
310 float32
helper_fxtos(void)
312 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
317 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
322 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
327 /* floating point conversion */
328 float32
helper_fdtos(void)
330 return float64_to_float32(DT1
, &env
->fp_status
);
333 void helper_fstod(float32 src
)
335 DT0
= float32_to_float64(src
, &env
->fp_status
);
338 float32
helper_fqtos(void)
340 return float128_to_float32(QT1
, &env
->fp_status
);
343 void helper_fstoq(float32 src
)
345 QT0
= float32_to_float128(src
, &env
->fp_status
);
348 void helper_fqtod(void)
350 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
353 void helper_fdtoq(void)
355 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
358 /* Float to integer conversion. */
359 int32_t helper_fstoi(float32 src
)
361 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
364 int32_t helper_fdtoi(void)
366 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
369 int32_t helper_fqtoi(void)
371 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
374 #ifdef TARGET_SPARC64
375 void helper_fstox(float32 src
)
377 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
380 void helper_fdtox(void)
382 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
385 void helper_fqtox(void)
387 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
390 void helper_faligndata(void)
394 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
395 /* on many architectures a shift of 64 does nothing */
396 if ((env
->gsr
& 7) != 0) {
397 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
399 *((uint64_t *)&DT0
) = tmp
;
402 #ifdef HOST_WORDS_BIGENDIAN
403 #define VIS_B64(n) b[7 - (n)]
404 #define VIS_W64(n) w[3 - (n)]
405 #define VIS_SW64(n) sw[3 - (n)]
406 #define VIS_L64(n) l[1 - (n)]
407 #define VIS_B32(n) b[3 - (n)]
408 #define VIS_W32(n) w[1 - (n)]
410 #define VIS_B64(n) b[n]
411 #define VIS_W64(n) w[n]
412 #define VIS_SW64(n) sw[n]
413 #define VIS_L64(n) l[n]
414 #define VIS_B32(n) b[n]
415 #define VIS_W32(n) w[n]
433 void helper_fpmerge(void)
440 // Reverse calculation order to handle overlap
441 d
.VIS_B64(7) = s
.VIS_B64(3);
442 d
.VIS_B64(6) = d
.VIS_B64(3);
443 d
.VIS_B64(5) = s
.VIS_B64(2);
444 d
.VIS_B64(4) = d
.VIS_B64(2);
445 d
.VIS_B64(3) = s
.VIS_B64(1);
446 d
.VIS_B64(2) = d
.VIS_B64(1);
447 d
.VIS_B64(1) = s
.VIS_B64(0);
448 //d.VIS_B64(0) = d.VIS_B64(0);
453 void helper_fmul8x16(void)
462 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
463 if ((tmp & 0xff) > 0x7f) \
465 d.VIS_W64(r) = tmp >> 8;
476 void helper_fmul8x16al(void)
485 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
486 if ((tmp & 0xff) > 0x7f) \
488 d.VIS_W64(r) = tmp >> 8;
499 void helper_fmul8x16au(void)
508 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
509 if ((tmp & 0xff) > 0x7f) \
511 d.VIS_W64(r) = tmp >> 8;
522 void helper_fmul8sux16(void)
531 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
532 if ((tmp & 0xff) > 0x7f) \
534 d.VIS_W64(r) = tmp >> 8;
545 void helper_fmul8ulx16(void)
554 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
555 if ((tmp & 0xff) > 0x7f) \
557 d.VIS_W64(r) = tmp >> 8;
568 void helper_fmuld8sux16(void)
577 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
578 if ((tmp & 0xff) > 0x7f) \
582 // Reverse calculation order to handle overlap
590 void helper_fmuld8ulx16(void)
599 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
600 if ((tmp & 0xff) > 0x7f) \
604 // Reverse calculation order to handle overlap
612 void helper_fexpand(void)
617 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
619 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
620 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
621 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
622 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
627 #define VIS_HELPER(name, F) \
628 void name##16(void) \
635 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
636 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
637 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
638 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
643 uint32_t name##16s(uint32_t src1, uint32_t src2) \
650 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
651 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
656 void name##32(void) \
663 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
664 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
669 uint32_t name##32s(uint32_t src1, uint32_t src2) \
681 #define FADD(a, b) ((a) + (b))
682 #define FSUB(a, b) ((a) - (b))
683 VIS_HELPER(helper_fpadd
, FADD
)
684 VIS_HELPER(helper_fpsub
, FSUB
)
686 #define VIS_CMPHELPER(name, F) \
687 void name##16(void) \
694 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
695 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
696 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
697 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
702 void name##32(void) \
709 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
710 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
715 #define FCMPGT(a, b) ((a) > (b))
716 #define FCMPEQ(a, b) ((a) == (b))
717 #define FCMPLE(a, b) ((a) <= (b))
718 #define FCMPNE(a, b) ((a) != (b))
720 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
721 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
722 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
723 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
726 void helper_check_ieee_exceptions(void)
730 status
= get_float_exception_flags(&env
->fp_status
);
732 /* Copy IEEE 754 flags into FSR */
733 if (status
& float_flag_invalid
)
735 if (status
& float_flag_overflow
)
737 if (status
& float_flag_underflow
)
739 if (status
& float_flag_divbyzero
)
741 if (status
& float_flag_inexact
)
744 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
745 /* Unmasked exception, generate a trap */
746 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
747 raise_exception(TT_FP_EXCP
);
749 /* Accumulate exceptions */
750 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
755 void helper_clear_float_exceptions(void)
757 set_float_exception_flags(0, &env
->fp_status
);
760 float32
helper_fabss(float32 src
)
762 return float32_abs(src
);
765 #ifdef TARGET_SPARC64
766 void helper_fabsd(void)
768 DT0
= float64_abs(DT1
);
771 void helper_fabsq(void)
773 QT0
= float128_abs(QT1
);
777 float32
helper_fsqrts(float32 src
)
779 return float32_sqrt(src
, &env
->fp_status
);
782 void helper_fsqrtd(void)
784 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
787 void helper_fsqrtq(void)
789 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
792 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
793 void glue(helper_, name) (void) \
795 target_ulong new_fsr; \
797 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
798 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
799 case float_relation_unordered: \
800 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
801 if ((env->fsr & FSR_NVM) || TRAP) { \
802 env->fsr |= new_fsr; \
803 env->fsr |= FSR_NVC; \
804 env->fsr |= FSR_FTT_IEEE_EXCP; \
805 raise_exception(TT_FP_EXCP); \
807 env->fsr |= FSR_NVA; \
810 case float_relation_less: \
811 new_fsr = FSR_FCC0 << FS; \
813 case float_relation_greater: \
814 new_fsr = FSR_FCC1 << FS; \
820 env->fsr |= new_fsr; \
822 #define GEN_FCMPS(name, size, FS, TRAP) \
823 void glue(helper_, name)(float32 src1, float32 src2) \
825 target_ulong new_fsr; \
827 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
828 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
829 case float_relation_unordered: \
830 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
831 if ((env->fsr & FSR_NVM) || TRAP) { \
832 env->fsr |= new_fsr; \
833 env->fsr |= FSR_NVC; \
834 env->fsr |= FSR_FTT_IEEE_EXCP; \
835 raise_exception(TT_FP_EXCP); \
837 env->fsr |= FSR_NVA; \
840 case float_relation_less: \
841 new_fsr = FSR_FCC0 << FS; \
843 case float_relation_greater: \
844 new_fsr = FSR_FCC1 << FS; \
850 env->fsr |= new_fsr; \
853 GEN_FCMPS(fcmps
, float32
, 0, 0);
854 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
856 GEN_FCMPS(fcmpes
, float32
, 0, 1);
857 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
859 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
860 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
862 static uint32_t compute_all_flags(void)
864 return env
->psr
& PSR_ICC
;
867 static uint32_t compute_C_flags(void)
869 return env
->psr
& PSR_CARRY
;
872 static inline uint32_t get_NZ_icc(target_ulong dst
)
876 if (!(dst
& 0xffffffffULL
))
878 if ((int32_t) (dst
& 0xffffffffULL
) < 0)
883 #ifdef TARGET_SPARC64
884 static uint32_t compute_all_flags_xcc(void)
886 return env
->xcc
& PSR_ICC
;
889 static uint32_t compute_C_flags_xcc(void)
891 return env
->xcc
& PSR_CARRY
;
894 static inline uint32_t get_NZ_xcc(target_ulong dst
)
900 if ((int64_t)dst
< 0)
906 static inline uint32_t get_V_div_icc(target_ulong src2
)
915 static uint32_t compute_all_div(void)
919 ret
= get_NZ_icc(CC_DST
);
920 ret
|= get_V_div_icc(CC_SRC2
);
924 static uint32_t compute_C_div(void)
929 /* carry = (src1[31] & src2[31]) | ( ~dst[31] & (src1[31] | src2[31])) */
930 static inline uint32_t get_C_add_icc(target_ulong dst
, target_ulong src1
,
935 if (((src1
& (1ULL << 31)) & (src2
& (1ULL << 31)))
936 | ((~(dst
& (1ULL << 31)))
937 & ((src1
& (1ULL << 31)) | (src2
& (1ULL << 31)))))
942 static inline uint32_t get_V_add_icc(target_ulong dst
, target_ulong src1
,
947 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 31))
952 #ifdef TARGET_SPARC64
953 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
962 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
967 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63))
972 static uint32_t compute_all_add_xcc(void)
976 ret
= get_NZ_xcc(CC_DST
);
977 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
978 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
982 static uint32_t compute_C_add_xcc(void)
984 return get_C_add_xcc(CC_DST
, CC_SRC
);
988 static uint32_t compute_all_add(void)
992 ret
= get_NZ_icc(CC_DST
);
993 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
994 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
998 static uint32_t compute_C_add(void)
1000 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1003 #ifdef TARGET_SPARC64
1004 static uint32_t compute_all_addx_xcc(void)
1008 ret
= get_NZ_xcc(CC_DST
);
1009 ret
|= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1010 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1011 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1015 static uint32_t compute_C_addx_xcc(void)
1019 ret
= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1020 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1025 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1029 if ((src1
| src2
) & 0x3)
1034 static uint32_t compute_all_tadd(void)
1038 ret
= get_NZ_icc(CC_DST
);
1039 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1040 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1041 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1045 static uint32_t compute_C_tadd(void)
1047 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1050 static uint32_t compute_all_taddtv(void)
1054 ret
= get_NZ_icc(CC_DST
);
1055 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1059 static uint32_t compute_C_taddtv(void)
1061 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1064 /* carry = (~src1[31] & src2[31]) | ( dst[31] & (~src1[31] | src2[31])) */
1065 static inline uint32_t get_C_sub_icc(target_ulong dst
, target_ulong src1
,
1070 if (((~(src1
& (1ULL << 31))) & (src2
& (1ULL << 31)))
1071 | ((dst
& (1ULL << 31)) & (( ~(src1
& (1ULL << 31)))
1072 | (src2
& (1ULL << 31)))))
1077 static inline uint32_t get_V_sub_icc(target_ulong dst
, target_ulong src1
,
1082 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 31))
1088 #ifdef TARGET_SPARC64
1089 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1098 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1103 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63))
1108 static uint32_t compute_all_sub_xcc(void)
1112 ret
= get_NZ_xcc(CC_DST
);
1113 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1114 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1118 static uint32_t compute_C_sub_xcc(void)
1120 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1124 static uint32_t compute_all_sub(void)
1128 ret
= get_NZ_icc(CC_DST
);
1129 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1130 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1134 static uint32_t compute_C_sub(void)
1136 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1139 #ifdef TARGET_SPARC64
1140 static uint32_t compute_all_subx_xcc(void)
1144 ret
= get_NZ_xcc(CC_DST
);
1145 ret
|= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1146 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1147 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1151 static uint32_t compute_C_subx_xcc(void)
1155 ret
= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1156 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1161 static uint32_t compute_all_tsub(void)
1165 ret
= get_NZ_icc(CC_DST
);
1166 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1167 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1168 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1172 static uint32_t compute_C_tsub(void)
1174 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1177 static uint32_t compute_all_tsubtv(void)
1181 ret
= get_NZ_icc(CC_DST
);
1182 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1186 static uint32_t compute_C_tsubtv(void)
1188 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1191 static uint32_t compute_all_logic(void)
1193 return get_NZ_icc(CC_DST
);
1196 static uint32_t compute_C_logic(void)
1201 #ifdef TARGET_SPARC64
1202 static uint32_t compute_all_logic_xcc(void)
1204 return get_NZ_xcc(CC_DST
);
1208 typedef struct CCTable
{
1209 uint32_t (*compute_all
)(void); /* return all the flags */
1210 uint32_t (*compute_c
)(void); /* return the C flag */
1213 static const CCTable icc_table
[CC_OP_NB
] = {
1214 /* CC_OP_DYNAMIC should never happen */
1215 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1216 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1217 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1218 [CC_OP_ADDX
] = { compute_all_add
, compute_C_add
},
1219 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_tadd
},
1220 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_taddtv
},
1221 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1222 [CC_OP_SUBX
] = { compute_all_sub
, compute_C_sub
},
1223 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_tsub
},
1224 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_tsubtv
},
1225 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1228 #ifdef TARGET_SPARC64
1229 static const CCTable xcc_table
[CC_OP_NB
] = {
1230 /* CC_OP_DYNAMIC should never happen */
1231 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1232 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1233 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1234 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1235 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1236 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1237 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1238 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1239 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1240 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1241 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1245 void helper_compute_psr(void)
1249 new_psr
= icc_table
[CC_OP
].compute_all();
1251 #ifdef TARGET_SPARC64
1252 new_psr
= xcc_table
[CC_OP
].compute_all();
1255 CC_OP
= CC_OP_FLAGS
;
1258 uint32_t helper_compute_C_icc(void)
1262 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1266 #ifdef TARGET_SPARC64
1267 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1268 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1269 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1271 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1272 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1273 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1275 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1276 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1277 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1279 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1280 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1281 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1283 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1284 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1285 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1287 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1288 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1289 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1293 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1295 static void dump_mxcc(CPUState
*env
)
1297 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1299 env
->mxccdata
[0], env
->mxccdata
[1],
1300 env
->mxccdata
[2], env
->mxccdata
[3]);
1301 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1303 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1305 env
->mxccregs
[0], env
->mxccregs
[1],
1306 env
->mxccregs
[2], env
->mxccregs
[3],
1307 env
->mxccregs
[4], env
->mxccregs
[5],
1308 env
->mxccregs
[6], env
->mxccregs
[7]);
1312 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1313 && defined(DEBUG_ASI)
1314 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1320 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1321 addr
, asi
, r1
& 0xff);
1324 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1325 addr
, asi
, r1
& 0xffff);
1328 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1329 addr
, asi
, r1
& 0xffffffff);
1332 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1339 #ifndef TARGET_SPARC64
1340 #ifndef CONFIG_USER_ONLY
1341 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1344 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1345 uint32_t last_addr
= addr
;
1348 helper_check_align(addr
, size
- 1);
1350 case 2: /* SuperSparc MXCC registers */
1352 case 0x01c00a00: /* MXCC control register */
1354 ret
= env
->mxccregs
[3];
1356 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1359 case 0x01c00a04: /* MXCC control register */
1361 ret
= env
->mxccregs
[3];
1363 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1366 case 0x01c00c00: /* Module reset register */
1368 ret
= env
->mxccregs
[5];
1369 // should we do something here?
1371 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1374 case 0x01c00f00: /* MBus port address register */
1376 ret
= env
->mxccregs
[7];
1378 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1382 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1386 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1387 "addr = %08x -> ret = %" PRIx64
","
1388 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1393 case 3: /* MMU probe */
1397 mmulev
= (addr
>> 8) & 15;
1401 ret
= mmu_probe(env
, addr
, mmulev
);
1402 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1406 case 4: /* read MMU regs */
1408 int reg
= (addr
>> 8) & 0x1f;
1410 ret
= env
->mmuregs
[reg
];
1411 if (reg
== 3) /* Fault status cleared on read */
1412 env
->mmuregs
[3] = 0;
1413 else if (reg
== 0x13) /* Fault status read */
1414 ret
= env
->mmuregs
[3];
1415 else if (reg
== 0x14) /* Fault address read */
1416 ret
= env
->mmuregs
[4];
1417 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1420 case 5: // Turbosparc ITLB Diagnostic
1421 case 6: // Turbosparc DTLB Diagnostic
1422 case 7: // Turbosparc IOTLB Diagnostic
1424 case 9: /* Supervisor code access */
1427 ret
= ldub_code(addr
);
1430 ret
= lduw_code(addr
);
1434 ret
= ldl_code(addr
);
1437 ret
= ldq_code(addr
);
1441 case 0xa: /* User data access */
1444 ret
= ldub_user(addr
);
1447 ret
= lduw_user(addr
);
1451 ret
= ldl_user(addr
);
1454 ret
= ldq_user(addr
);
1458 case 0xb: /* Supervisor data access */
1461 ret
= ldub_kernel(addr
);
1464 ret
= lduw_kernel(addr
);
1468 ret
= ldl_kernel(addr
);
1471 ret
= ldq_kernel(addr
);
1475 case 0xc: /* I-cache tag */
1476 case 0xd: /* I-cache data */
1477 case 0xe: /* D-cache tag */
1478 case 0xf: /* D-cache data */
1480 case 0x20: /* MMU passthrough */
1483 ret
= ldub_phys(addr
);
1486 ret
= lduw_phys(addr
);
1490 ret
= ldl_phys(addr
);
1493 ret
= ldq_phys(addr
);
1497 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1500 ret
= ldub_phys((target_phys_addr_t
)addr
1501 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1504 ret
= lduw_phys((target_phys_addr_t
)addr
1505 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1509 ret
= ldl_phys((target_phys_addr_t
)addr
1510 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1513 ret
= ldq_phys((target_phys_addr_t
)addr
1514 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1518 case 0x30: // Turbosparc secondary cache diagnostic
1519 case 0x31: // Turbosparc RAM snoop
1520 case 0x32: // Turbosparc page table descriptor diagnostic
1521 case 0x39: /* data cache diagnostic register */
1524 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1526 int reg
= (addr
>> 8) & 3;
1529 case 0: /* Breakpoint Value (Addr) */
1530 ret
= env
->mmubpregs
[reg
];
1532 case 1: /* Breakpoint Mask */
1533 ret
= env
->mmubpregs
[reg
];
1535 case 2: /* Breakpoint Control */
1536 ret
= env
->mmubpregs
[reg
];
1538 case 3: /* Breakpoint Status */
1539 ret
= env
->mmubpregs
[reg
];
1540 env
->mmubpregs
[reg
] = 0ULL;
1543 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1547 case 8: /* User code access, XXX */
1549 do_unassigned_access(addr
, 0, 0, asi
, size
);
1559 ret
= (int16_t) ret
;
1562 ret
= (int32_t) ret
;
1569 dump_asi("read ", last_addr
, asi
, size
, ret
);
1574 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1576 helper_check_align(addr
, size
- 1);
1578 case 2: /* SuperSparc MXCC registers */
1580 case 0x01c00000: /* MXCC stream data register 0 */
1582 env
->mxccdata
[0] = val
;
1584 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1587 case 0x01c00008: /* MXCC stream data register 1 */
1589 env
->mxccdata
[1] = val
;
1591 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1594 case 0x01c00010: /* MXCC stream data register 2 */
1596 env
->mxccdata
[2] = val
;
1598 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1601 case 0x01c00018: /* MXCC stream data register 3 */
1603 env
->mxccdata
[3] = val
;
1605 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1608 case 0x01c00100: /* MXCC stream source */
1610 env
->mxccregs
[0] = val
;
1612 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1614 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1616 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1618 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1620 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1623 case 0x01c00200: /* MXCC stream destination */
1625 env
->mxccregs
[1] = val
;
1627 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1629 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1631 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1633 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1635 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1638 case 0x01c00a00: /* MXCC control register */
1640 env
->mxccregs
[3] = val
;
1642 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1645 case 0x01c00a04: /* MXCC control register */
1647 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1650 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1653 case 0x01c00e00: /* MXCC error register */
1654 // writing a 1 bit clears the error
1656 env
->mxccregs
[6] &= ~val
;
1658 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1661 case 0x01c00f00: /* MBus port address register */
1663 env
->mxccregs
[7] = val
;
1665 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1669 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1673 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1674 asi
, size
, addr
, val
);
1679 case 3: /* MMU flush */
1683 mmulev
= (addr
>> 8) & 15;
1684 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1686 case 0: // flush page
1687 tlb_flush_page(env
, addr
& 0xfffff000);
1689 case 1: // flush segment (256k)
1690 case 2: // flush region (16M)
1691 case 3: // flush context (4G)
1692 case 4: // flush entire
1703 case 4: /* write MMU regs */
1705 int reg
= (addr
>> 8) & 0x1f;
1708 oldreg
= env
->mmuregs
[reg
];
1710 case 0: // Control Register
1711 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1713 // Mappings generated during no-fault mode or MMU
1714 // disabled mode are invalid in normal mode
1715 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1716 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1719 case 1: // Context Table Pointer Register
1720 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1722 case 2: // Context Register
1723 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1724 if (oldreg
!= env
->mmuregs
[reg
]) {
1725 /* we flush when the MMU context changes because
1726 QEMU has no MMU context support */
1730 case 3: // Synchronous Fault Status Register with Clear
1731 case 4: // Synchronous Fault Address Register
1733 case 0x10: // TLB Replacement Control Register
1734 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1736 case 0x13: // Synchronous Fault Status Register with Read and Clear
1737 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1739 case 0x14: // Synchronous Fault Address Register
1740 env
->mmuregs
[4] = val
;
1743 env
->mmuregs
[reg
] = val
;
1746 if (oldreg
!= env
->mmuregs
[reg
]) {
1747 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1748 reg
, oldreg
, env
->mmuregs
[reg
]);
1755 case 5: // Turbosparc ITLB Diagnostic
1756 case 6: // Turbosparc DTLB Diagnostic
1757 case 7: // Turbosparc IOTLB Diagnostic
1759 case 0xa: /* User data access */
1762 stb_user(addr
, val
);
1765 stw_user(addr
, val
);
1769 stl_user(addr
, val
);
1772 stq_user(addr
, val
);
1776 case 0xb: /* Supervisor data access */
1779 stb_kernel(addr
, val
);
1782 stw_kernel(addr
, val
);
1786 stl_kernel(addr
, val
);
1789 stq_kernel(addr
, val
);
1793 case 0xc: /* I-cache tag */
1794 case 0xd: /* I-cache data */
1795 case 0xe: /* D-cache tag */
1796 case 0xf: /* D-cache data */
1797 case 0x10: /* I/D-cache flush page */
1798 case 0x11: /* I/D-cache flush segment */
1799 case 0x12: /* I/D-cache flush region */
1800 case 0x13: /* I/D-cache flush context */
1801 case 0x14: /* I/D-cache flush user */
1803 case 0x17: /* Block copy, sta access */
1809 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1811 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1812 temp
= ldl_kernel(src
);
1813 stl_kernel(dst
, temp
);
1817 case 0x1f: /* Block fill, stda access */
1820 // fill 32 bytes with val
1822 uint32_t dst
= addr
& 7;
1824 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1825 stq_kernel(dst
, val
);
1828 case 0x20: /* MMU passthrough */
1832 stb_phys(addr
, val
);
1835 stw_phys(addr
, val
);
1839 stl_phys(addr
, val
);
1842 stq_phys(addr
, val
);
1847 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1851 stb_phys((target_phys_addr_t
)addr
1852 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1855 stw_phys((target_phys_addr_t
)addr
1856 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1860 stl_phys((target_phys_addr_t
)addr
1861 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1864 stq_phys((target_phys_addr_t
)addr
1865 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1870 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1871 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1872 // Turbosparc snoop RAM
1873 case 0x32: // store buffer control or Turbosparc page table
1874 // descriptor diagnostic
1875 case 0x36: /* I-cache flash clear */
1876 case 0x37: /* D-cache flash clear */
1877 case 0x4c: /* breakpoint action */
1879 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1881 int reg
= (addr
>> 8) & 3;
1884 case 0: /* Breakpoint Value (Addr) */
1885 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1887 case 1: /* Breakpoint Mask */
1888 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1890 case 2: /* Breakpoint Control */
1891 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1893 case 3: /* Breakpoint Status */
1894 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1897 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1901 case 8: /* User code access, XXX */
1902 case 9: /* Supervisor code access, XXX */
1904 do_unassigned_access(addr
, 1, 0, asi
, size
);
1908 dump_asi("write", addr
, asi
, size
, val
);
1912 #endif /* CONFIG_USER_ONLY */
1913 #else /* TARGET_SPARC64 */
1915 #ifdef CONFIG_USER_ONLY
1916 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1919 #if defined(DEBUG_ASI)
1920 target_ulong last_addr
= addr
;
1924 raise_exception(TT_PRIV_ACT
);
1926 helper_check_align(addr
, size
- 1);
1927 addr
= address_mask(env
, addr
);
1930 case 0x82: // Primary no-fault
1931 case 0x8a: // Primary no-fault LE
1932 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1934 dump_asi("read ", last_addr
, asi
, size
, ret
);
1939 case 0x80: // Primary
1940 case 0x88: // Primary LE
1944 ret
= ldub_raw(addr
);
1947 ret
= lduw_raw(addr
);
1950 ret
= ldl_raw(addr
);
1954 ret
= ldq_raw(addr
);
1959 case 0x83: // Secondary no-fault
1960 case 0x8b: // Secondary no-fault LE
1961 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1963 dump_asi("read ", last_addr
, asi
, size
, ret
);
1968 case 0x81: // Secondary
1969 case 0x89: // Secondary LE
1976 /* Convert from little endian */
1978 case 0x88: // Primary LE
1979 case 0x89: // Secondary LE
1980 case 0x8a: // Primary no-fault LE
1981 case 0x8b: // Secondary no-fault LE
1999 /* Convert to signed number */
2006 ret
= (int16_t) ret
;
2009 ret
= (int32_t) ret
;
2016 dump_asi("read ", last_addr
, asi
, size
, ret
);
2021 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2024 dump_asi("write", addr
, asi
, size
, val
);
2027 raise_exception(TT_PRIV_ACT
);
2029 helper_check_align(addr
, size
- 1);
2030 addr
= address_mask(env
, addr
);
2032 /* Convert to little endian */
2034 case 0x88: // Primary LE
2035 case 0x89: // Secondary LE
2054 case 0x80: // Primary
2055 case 0x88: // Primary LE
2074 case 0x81: // Secondary
2075 case 0x89: // Secondary LE
2079 case 0x82: // Primary no-fault, RO
2080 case 0x83: // Secondary no-fault, RO
2081 case 0x8a: // Primary no-fault LE, RO
2082 case 0x8b: // Secondary no-fault LE, RO
2084 do_unassigned_access(addr
, 1, 0, 1, size
);
2089 #else /* CONFIG_USER_ONLY */
2091 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2094 #if defined(DEBUG_ASI)
2095 target_ulong last_addr
= addr
;
2100 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2101 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2102 && asi
>= 0x30 && asi
< 0x80
2103 && !(env
->hpstate
& HS_PRIV
)))
2104 raise_exception(TT_PRIV_ACT
);
2106 helper_check_align(addr
, size
- 1);
2108 case 0x82: // Primary no-fault
2109 case 0x8a: // Primary no-fault LE
2110 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2112 dump_asi("read ", last_addr
, asi
, size
, ret
);
2117 case 0x10: // As if user primary
2118 case 0x18: // As if user primary LE
2119 case 0x80: // Primary
2120 case 0x88: // Primary LE
2121 case 0xe2: // UA2007 Primary block init
2122 case 0xe3: // UA2007 Secondary block init
2123 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2124 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2125 && env
->hpstate
& HS_PRIV
) {
2128 ret
= ldub_hypv(addr
);
2131 ret
= lduw_hypv(addr
);
2134 ret
= ldl_hypv(addr
);
2138 ret
= ldq_hypv(addr
);
2144 ret
= ldub_kernel(addr
);
2147 ret
= lduw_kernel(addr
);
2150 ret
= ldl_kernel(addr
);
2154 ret
= ldq_kernel(addr
);
2161 ret
= ldub_user(addr
);
2164 ret
= lduw_user(addr
);
2167 ret
= ldl_user(addr
);
2171 ret
= ldq_user(addr
);
2176 case 0x14: // Bypass
2177 case 0x15: // Bypass, non-cacheable
2178 case 0x1c: // Bypass LE
2179 case 0x1d: // Bypass, non-cacheable LE
2183 ret
= ldub_phys(addr
);
2186 ret
= lduw_phys(addr
);
2189 ret
= ldl_phys(addr
);
2193 ret
= ldq_phys(addr
);
2198 case 0x24: // Nucleus quad LDD 128 bit atomic
2199 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2200 // Only ldda allowed
2201 raise_exception(TT_ILL_INSN
);
2203 case 0x83: // Secondary no-fault
2204 case 0x8b: // Secondary no-fault LE
2205 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2207 dump_asi("read ", last_addr
, asi
, size
, ret
);
2212 case 0x04: // Nucleus
2213 case 0x0c: // Nucleus Little Endian (LE)
2214 case 0x11: // As if user secondary
2215 case 0x19: // As if user secondary LE
2216 case 0x4a: // UPA config
2217 case 0x81: // Secondary
2218 case 0x89: // Secondary LE
2224 case 0x50: // I-MMU regs
2226 int reg
= (addr
>> 3) & 0xf;
2229 // I-TSB Tag Target register
2230 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2232 ret
= env
->immuregs
[reg
];
2237 case 0x51: // I-MMU 8k TSB pointer
2239 // env->immuregs[5] holds I-MMU TSB register value
2240 // env->immuregs[6] holds I-MMU Tag Access register value
2241 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2245 case 0x52: // I-MMU 64k TSB pointer
2247 // env->immuregs[5] holds I-MMU TSB register value
2248 // env->immuregs[6] holds I-MMU Tag Access register value
2249 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2253 case 0x55: // I-MMU data access
2255 int reg
= (addr
>> 3) & 0x3f;
2257 ret
= env
->itlb
[reg
].tte
;
2260 case 0x56: // I-MMU tag read
2262 int reg
= (addr
>> 3) & 0x3f;
2264 ret
= env
->itlb
[reg
].tag
;
2267 case 0x58: // D-MMU regs
2269 int reg
= (addr
>> 3) & 0xf;
2272 // D-TSB Tag Target register
2273 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2275 ret
= env
->dmmuregs
[reg
];
2279 case 0x59: // D-MMU 8k TSB pointer
2281 // env->dmmuregs[5] holds D-MMU TSB register value
2282 // env->dmmuregs[6] holds D-MMU Tag Access register value
2283 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2287 case 0x5a: // D-MMU 64k TSB pointer
2289 // env->dmmuregs[5] holds D-MMU TSB register value
2290 // env->dmmuregs[6] holds D-MMU Tag Access register value
2291 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2295 case 0x5d: // D-MMU data access
2297 int reg
= (addr
>> 3) & 0x3f;
2299 ret
= env
->dtlb
[reg
].tte
;
2302 case 0x5e: // D-MMU tag read
2304 int reg
= (addr
>> 3) & 0x3f;
2306 ret
= env
->dtlb
[reg
].tag
;
2309 case 0x46: // D-cache data
2310 case 0x47: // D-cache tag access
2311 case 0x4b: // E-cache error enable
2312 case 0x4c: // E-cache asynchronous fault status
2313 case 0x4d: // E-cache asynchronous fault address
2314 case 0x4e: // E-cache tag data
2315 case 0x66: // I-cache instruction access
2316 case 0x67: // I-cache tag access
2317 case 0x6e: // I-cache predecode
2318 case 0x6f: // I-cache LRU etc.
2319 case 0x76: // E-cache tag
2320 case 0x7e: // E-cache tag
2322 case 0x5b: // D-MMU data pointer
2323 case 0x48: // Interrupt dispatch, RO
2324 case 0x49: // Interrupt data receive
2325 case 0x7f: // Incoming interrupt vector, RO
2328 case 0x54: // I-MMU data in, WO
2329 case 0x57: // I-MMU demap, WO
2330 case 0x5c: // D-MMU data in, WO
2331 case 0x5f: // D-MMU demap, WO
2332 case 0x77: // Interrupt vector, WO
2334 do_unassigned_access(addr
, 0, 0, 1, size
);
2339 /* Convert from little endian */
2341 case 0x0c: // Nucleus Little Endian (LE)
2342 case 0x18: // As if user primary LE
2343 case 0x19: // As if user secondary LE
2344 case 0x1c: // Bypass LE
2345 case 0x1d: // Bypass, non-cacheable LE
2346 case 0x88: // Primary LE
2347 case 0x89: // Secondary LE
2348 case 0x8a: // Primary no-fault LE
2349 case 0x8b: // Secondary no-fault LE
2367 /* Convert to signed number */
2374 ret
= (int16_t) ret
;
2377 ret
= (int32_t) ret
;
2384 dump_asi("read ", last_addr
, asi
, size
, ret
);
2389 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2392 dump_asi("write", addr
, asi
, size
, val
);
2397 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2398 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2399 && asi
>= 0x30 && asi
< 0x80
2400 && !(env
->hpstate
& HS_PRIV
)))
2401 raise_exception(TT_PRIV_ACT
);
2403 helper_check_align(addr
, size
- 1);
2404 /* Convert to little endian */
2406 case 0x0c: // Nucleus Little Endian (LE)
2407 case 0x18: // As if user primary LE
2408 case 0x19: // As if user secondary LE
2409 case 0x1c: // Bypass LE
2410 case 0x1d: // Bypass, non-cacheable LE
2411 case 0x88: // Primary LE
2412 case 0x89: // Secondary LE
2431 case 0x10: // As if user primary
2432 case 0x18: // As if user primary LE
2433 case 0x80: // Primary
2434 case 0x88: // Primary LE
2435 case 0xe2: // UA2007 Primary block init
2436 case 0xe3: // UA2007 Secondary block init
2437 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2438 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2439 && env
->hpstate
& HS_PRIV
) {
2442 stb_hypv(addr
, val
);
2445 stw_hypv(addr
, val
);
2448 stl_hypv(addr
, val
);
2452 stq_hypv(addr
, val
);
2458 stb_kernel(addr
, val
);
2461 stw_kernel(addr
, val
);
2464 stl_kernel(addr
, val
);
2468 stq_kernel(addr
, val
);
2475 stb_user(addr
, val
);
2478 stw_user(addr
, val
);
2481 stl_user(addr
, val
);
2485 stq_user(addr
, val
);
2490 case 0x14: // Bypass
2491 case 0x15: // Bypass, non-cacheable
2492 case 0x1c: // Bypass LE
2493 case 0x1d: // Bypass, non-cacheable LE
2497 stb_phys(addr
, val
);
2500 stw_phys(addr
, val
);
2503 stl_phys(addr
, val
);
2507 stq_phys(addr
, val
);
2512 case 0x24: // Nucleus quad LDD 128 bit atomic
2513 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2514 // Only ldda allowed
2515 raise_exception(TT_ILL_INSN
);
2517 case 0x04: // Nucleus
2518 case 0x0c: // Nucleus Little Endian (LE)
2519 case 0x11: // As if user secondary
2520 case 0x19: // As if user secondary LE
2521 case 0x4a: // UPA config
2522 case 0x81: // Secondary
2523 case 0x89: // Secondary LE
2531 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
2532 // Mappings generated during D/I MMU disabled mode are
2533 // invalid in normal mode
2534 if (oldreg
!= env
->lsu
) {
2535 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
2544 case 0x50: // I-MMU regs
2546 int reg
= (addr
>> 3) & 0xf;
2549 oldreg
= env
->immuregs
[reg
];
2553 case 1: // Not in I-MMU
2558 val
= 0; // Clear SFSR
2559 env
->immu
.sfsr
= val
;
2563 case 5: // TSB access
2564 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
2565 PRIx64
"\n", env
->immu
.tsb
, val
);
2566 env
->immu
.tsb
= val
;
2568 case 6: // Tag access
2569 env
->immu
.tag_access
= val
;
2578 if (oldreg
!= env
->immuregs
[reg
]) {
2579 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2580 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2587 case 0x54: // I-MMU data in
2588 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
2590 case 0x55: // I-MMU data access
2594 unsigned int i
= (addr
>> 3) & 0x3f;
2596 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
2599 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
2604 case 0x57: // I-MMU demap
2605 demap_tlb(env
->itlb
, val
, "immu", env
);
2607 case 0x58: // D-MMU regs
2609 int reg
= (addr
>> 3) & 0xf;
2612 oldreg
= env
->dmmuregs
[reg
];
2618 if ((val
& 1) == 0) {
2619 val
= 0; // Clear SFSR, Fault address
2622 env
->dmmu
.sfsr
= val
;
2624 case 1: // Primary context
2625 env
->dmmu
.mmu_primary_context
= val
;
2627 case 2: // Secondary context
2628 env
->dmmu
.mmu_secondary_context
= val
;
2630 case 5: // TSB access
2631 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
2632 PRIx64
"\n", env
->dmmu
.tsb
, val
);
2633 env
->dmmu
.tsb
= val
;
2635 case 6: // Tag access
2636 env
->dmmu
.tag_access
= val
;
2638 case 7: // Virtual Watchpoint
2639 case 8: // Physical Watchpoint
2641 env
->dmmuregs
[reg
] = val
;
2645 if (oldreg
!= env
->dmmuregs
[reg
]) {
2646 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2647 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2654 case 0x5c: // D-MMU data in
2655 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
2657 case 0x5d: // D-MMU data access
2659 unsigned int i
= (addr
>> 3) & 0x3f;
2661 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
2664 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
2669 case 0x5f: // D-MMU demap
2670 demap_tlb(env
->dtlb
, val
, "dmmu", env
);
2672 case 0x49: // Interrupt data receive
2675 case 0x46: // D-cache data
2676 case 0x47: // D-cache tag access
2677 case 0x4b: // E-cache error enable
2678 case 0x4c: // E-cache asynchronous fault status
2679 case 0x4d: // E-cache asynchronous fault address
2680 case 0x4e: // E-cache tag data
2681 case 0x66: // I-cache instruction access
2682 case 0x67: // I-cache tag access
2683 case 0x6e: // I-cache predecode
2684 case 0x6f: // I-cache LRU etc.
2685 case 0x76: // E-cache tag
2686 case 0x7e: // E-cache tag
2688 case 0x51: // I-MMU 8k TSB pointer, RO
2689 case 0x52: // I-MMU 64k TSB pointer, RO
2690 case 0x56: // I-MMU tag read, RO
2691 case 0x59: // D-MMU 8k TSB pointer, RO
2692 case 0x5a: // D-MMU 64k TSB pointer, RO
2693 case 0x5b: // D-MMU data pointer, RO
2694 case 0x5e: // D-MMU tag read, RO
2695 case 0x48: // Interrupt dispatch, RO
2696 case 0x7f: // Incoming interrupt vector, RO
2697 case 0x82: // Primary no-fault, RO
2698 case 0x83: // Secondary no-fault, RO
2699 case 0x8a: // Primary no-fault LE, RO
2700 case 0x8b: // Secondary no-fault LE, RO
2702 do_unassigned_access(addr
, 1, 0, 1, size
);
2706 #endif /* CONFIG_USER_ONLY */
2708 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2710 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2711 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2712 && asi
>= 0x30 && asi
< 0x80
2713 && !(env
->hpstate
& HS_PRIV
)))
2714 raise_exception(TT_PRIV_ACT
);
2717 case 0x24: // Nucleus quad LDD 128 bit atomic
2718 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2719 helper_check_align(addr
, 0xf);
2721 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2723 bswap64s(&env
->gregs
[1]);
2724 } else if (rd
< 8) {
2725 env
->gregs
[rd
] = ldq_kernel(addr
);
2726 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2728 bswap64s(&env
->gregs
[rd
]);
2729 bswap64s(&env
->gregs
[rd
+ 1]);
2732 env
->regwptr
[rd
] = ldq_kernel(addr
);
2733 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2735 bswap64s(&env
->regwptr
[rd
]);
2736 bswap64s(&env
->regwptr
[rd
+ 1]);
2741 helper_check_align(addr
, 0x3);
2743 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2745 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2746 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2748 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2749 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2755 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2760 helper_check_align(addr
, 3);
2762 case 0xf0: // Block load primary
2763 case 0xf1: // Block load secondary
2764 case 0xf8: // Block load primary LE
2765 case 0xf9: // Block load secondary LE
2767 raise_exception(TT_ILL_INSN
);
2770 helper_check_align(addr
, 0x3f);
2771 for (i
= 0; i
< 16; i
++) {
2772 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2782 val
= helper_ld_asi(addr
, asi
, size
, 0);
2786 *((uint32_t *)&env
->fpr
[rd
]) = val
;
2789 *((int64_t *)&DT0
) = val
;
2797 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2800 target_ulong val
= 0;
2802 helper_check_align(addr
, 3);
2804 case 0xe0: // UA2007 Block commit store primary (cache flush)
2805 case 0xe1: // UA2007 Block commit store secondary (cache flush)
2806 case 0xf0: // Block store primary
2807 case 0xf1: // Block store secondary
2808 case 0xf8: // Block store primary LE
2809 case 0xf9: // Block store secondary LE
2811 raise_exception(TT_ILL_INSN
);
2814 helper_check_align(addr
, 0x3f);
2815 for (i
= 0; i
< 16; i
++) {
2816 val
= *(uint32_t *)&env
->fpr
[rd
++];
2817 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2829 val
= *((uint32_t *)&env
->fpr
[rd
]);
2832 val
= *((int64_t *)&DT0
);
2838 helper_st_asi(addr
, val
, asi
, size
);
2841 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2842 target_ulong val2
, uint32_t asi
)
2846 val2
&= 0xffffffffUL
;
2847 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2848 ret
&= 0xffffffffUL
;
2850 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
2854 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2855 target_ulong val2
, uint32_t asi
)
2859 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2861 helper_st_asi(addr
, val1
, asi
, 8);
2864 #endif /* TARGET_SPARC64 */
2866 #ifndef TARGET_SPARC64
2867 void helper_rett(void)
2871 if (env
->psret
== 1)
2872 raise_exception(TT_ILL_INSN
);
2875 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2876 if (env
->wim
& (1 << cwp
)) {
2877 raise_exception(TT_WIN_UNF
);
2880 env
->psrs
= env
->psrps
;
2884 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2889 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2893 raise_exception(TT_DIV_ZERO
);
2897 if (x0
> 0xffffffff) {
2906 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2911 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2915 raise_exception(TT_DIV_ZERO
);
2919 if ((int32_t) x0
!= x0
) {
2921 return x0
< 0? 0x80000000: 0x7fffffff;
2928 void helper_stdf(target_ulong addr
, int mem_idx
)
2930 helper_check_align(addr
, 7);
2931 #if !defined(CONFIG_USER_ONLY)
2934 stfq_user(addr
, DT0
);
2937 stfq_kernel(addr
, DT0
);
2939 #ifdef TARGET_SPARC64
2941 stfq_hypv(addr
, DT0
);
2948 stfq_raw(address_mask(env
, 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 DT0
= ldfq_raw(address_mask(env
, addr
));
2976 void helper_ldqf(target_ulong addr
, int mem_idx
)
2978 // XXX add 128 bit load
2981 helper_check_align(addr
, 7);
2982 #if !defined(CONFIG_USER_ONLY)
2985 u
.ll
.upper
= ldq_user(addr
);
2986 u
.ll
.lower
= ldq_user(addr
+ 8);
2990 u
.ll
.upper
= ldq_kernel(addr
);
2991 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2994 #ifdef TARGET_SPARC64
2996 u
.ll
.upper
= ldq_hypv(addr
);
2997 u
.ll
.lower
= ldq_hypv(addr
+ 8);
3005 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
3006 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
3011 void helper_stqf(target_ulong addr
, int mem_idx
)
3013 // XXX add 128 bit store
3016 helper_check_align(addr
, 7);
3017 #if !defined(CONFIG_USER_ONLY)
3021 stq_user(addr
, u
.ll
.upper
);
3022 stq_user(addr
+ 8, u
.ll
.lower
);
3026 stq_kernel(addr
, u
.ll
.upper
);
3027 stq_kernel(addr
+ 8, u
.ll
.lower
);
3029 #ifdef TARGET_SPARC64
3032 stq_hypv(addr
, u
.ll
.upper
);
3033 stq_hypv(addr
+ 8, u
.ll
.lower
);
3041 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
3042 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
3046 static inline void set_fsr(void)
3050 switch (env
->fsr
& FSR_RD_MASK
) {
3051 case FSR_RD_NEAREST
:
3052 rnd_mode
= float_round_nearest_even
;
3056 rnd_mode
= float_round_to_zero
;
3059 rnd_mode
= float_round_up
;
3062 rnd_mode
= float_round_down
;
3065 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3068 void helper_ldfsr(uint32_t new_fsr
)
3070 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3074 #ifdef TARGET_SPARC64
3075 void helper_ldxfsr(uint64_t new_fsr
)
3077 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3082 void helper_debug(void)
3084 env
->exception_index
= EXCP_DEBUG
;
3088 #ifndef TARGET_SPARC64
3089 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3091 void helper_save(void)
3095 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3096 if (env
->wim
& (1 << cwp
)) {
3097 raise_exception(TT_WIN_OVF
);
3102 void helper_restore(void)
3106 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3107 if (env
->wim
& (1 << cwp
)) {
3108 raise_exception(TT_WIN_UNF
);
3113 void helper_wrpsr(target_ulong new_psr
)
3115 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
3116 raise_exception(TT_ILL_INSN
);
3118 PUT_PSR(env
, new_psr
);
3121 target_ulong
helper_rdpsr(void)
3123 return GET_PSR(env
);
3127 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3129 void helper_save(void)
3133 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3134 if (env
->cansave
== 0) {
3135 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3136 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3137 ((env
->wstate
& 0x7) << 2)));
3139 if (env
->cleanwin
- env
->canrestore
== 0) {
3140 // XXX Clean windows without trap
3141 raise_exception(TT_CLRWIN
);
3150 void helper_restore(void)
3154 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3155 if (env
->canrestore
== 0) {
3156 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3157 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3158 ((env
->wstate
& 0x7) << 2)));
3166 void helper_flushw(void)
3168 if (env
->cansave
!= env
->nwindows
- 2) {
3169 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3170 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3171 ((env
->wstate
& 0x7) << 2)));
3175 void helper_saved(void)
3178 if (env
->otherwin
== 0)
3184 void helper_restored(void)
3187 if (env
->cleanwin
< env
->nwindows
- 1)
3189 if (env
->otherwin
== 0)
3195 target_ulong
helper_rdccr(void)
3197 return GET_CCR(env
);
3200 void helper_wrccr(target_ulong new_ccr
)
3202 PUT_CCR(env
, new_ccr
);
3205 // CWP handling is reversed in V9, but we still use the V8 register
3207 target_ulong
helper_rdcwp(void)
3209 return GET_CWP64(env
);
3212 void helper_wrcwp(target_ulong new_cwp
)
3214 PUT_CWP64(env
, new_cwp
);
3217 // This function uses non-native bit order
3218 #define GET_FIELD(X, FROM, TO) \
3219 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3221 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3222 #define GET_FIELD_SP(X, FROM, TO) \
3223 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3225 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3227 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3228 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3229 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3230 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3231 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3232 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3233 (((pixel_addr
>> 55) & 1) << 4) |
3234 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3235 GET_FIELD_SP(pixel_addr
, 11, 12);
3238 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3242 tmp
= addr
+ offset
;
3244 env
->gsr
|= tmp
& 7ULL;
3248 target_ulong
helper_popc(target_ulong val
)
3250 return ctpop64(val
);
3253 static inline uint64_t *get_gregset(uint32_t pstate
)
3257 DPRINTF_PSTATE("ERROR in get_gregset: active pstate bits=%x%s%s%s\n",
3259 (pstate
& PS_IG
) ? " IG" : "",
3260 (pstate
& PS_MG
) ? " MG" : "",
3261 (pstate
& PS_AG
) ? " AG" : "");
3262 /* pass through to normal set of global registers */
3274 static inline void change_pstate(uint32_t new_pstate
)
3276 uint32_t pstate_regs
, new_pstate_regs
;
3277 uint64_t *src
, *dst
;
3279 if (env
->def
->features
& CPU_FEATURE_GL
) {
3280 // PS_AG is not implemented in this case
3281 new_pstate
&= ~PS_AG
;
3284 pstate_regs
= env
->pstate
& 0xc01;
3285 new_pstate_regs
= new_pstate
& 0xc01;
3287 if (new_pstate_regs
!= pstate_regs
) {
3288 DPRINTF_PSTATE("change_pstate: switching regs old=%x new=%x\n",
3289 pstate_regs
, new_pstate_regs
);
3290 // Switch global register bank
3291 src
= get_gregset(new_pstate_regs
);
3292 dst
= get_gregset(pstate_regs
);
3293 memcpy32(dst
, env
->gregs
);
3294 memcpy32(env
->gregs
, src
);
3297 DPRINTF_PSTATE("change_pstate: regs new=%x (unchanged)\n",
3300 env
->pstate
= new_pstate
;
3303 void helper_wrpstate(target_ulong new_state
)
3305 change_pstate(new_state
& 0xf3f);
3307 #if !defined(CONFIG_USER_ONLY)
3308 if (cpu_interrupts_enabled(env
)) {
3309 cpu_check_irqs(env
);
3314 void helper_wrpil(target_ulong new_pil
)
3316 #if !defined(CONFIG_USER_ONLY)
3317 DPRINTF_PSTATE("helper_wrpil old=%x new=%x\n",
3318 env
->psrpil
, (uint32_t)new_pil
);
3320 env
->psrpil
= new_pil
;
3322 if (cpu_interrupts_enabled(env
)) {
3323 cpu_check_irqs(env
);
3328 void helper_done(void)
3330 trap_state
* tsptr
= cpu_tsptr(env
);
3332 env
->pc
= tsptr
->tnpc
;
3333 env
->npc
= tsptr
->tnpc
+ 4;
3334 PUT_CCR(env
, tsptr
->tstate
>> 32);
3335 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3336 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3337 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3340 DPRINTF_PSTATE("... helper_done tl=%d\n", env
->tl
);
3342 #if !defined(CONFIG_USER_ONLY)
3343 if (cpu_interrupts_enabled(env
)) {
3344 cpu_check_irqs(env
);
3349 void helper_retry(void)
3351 trap_state
* tsptr
= cpu_tsptr(env
);
3353 env
->pc
= tsptr
->tpc
;
3354 env
->npc
= tsptr
->tnpc
;
3355 PUT_CCR(env
, tsptr
->tstate
>> 32);
3356 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3357 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3358 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3361 DPRINTF_PSTATE("... helper_retry tl=%d\n", env
->tl
);
3363 #if !defined(CONFIG_USER_ONLY)
3364 if (cpu_interrupts_enabled(env
)) {
3365 cpu_check_irqs(env
);
3370 static void do_modify_softint(const char* operation
, uint32_t value
)
3372 if (env
->softint
!= value
) {
3373 env
->softint
= value
;
3374 DPRINTF_PSTATE(": %s new %08x\n", operation
, env
->softint
);
3375 #if !defined(CONFIG_USER_ONLY)
3376 if (cpu_interrupts_enabled(env
)) {
3377 cpu_check_irqs(env
);
3383 void helper_set_softint(uint64_t value
)
3385 do_modify_softint("helper_set_softint", env
->softint
| (uint32_t)value
);
3388 void helper_clear_softint(uint64_t value
)
3390 do_modify_softint("helper_clear_softint", env
->softint
& (uint32_t)~value
);
3393 void helper_write_softint(uint64_t value
)
3395 do_modify_softint("helper_write_softint", (uint32_t)value
);
3399 void helper_flush(target_ulong addr
)
3402 tb_invalidate_page_range(addr
, addr
+ 8);
3405 #ifdef TARGET_SPARC64
3407 static const char * const excp_names
[0x80] = {
3408 [TT_TFAULT
] = "Instruction Access Fault",
3409 [TT_TMISS
] = "Instruction Access MMU Miss",
3410 [TT_CODE_ACCESS
] = "Instruction Access Error",
3411 [TT_ILL_INSN
] = "Illegal Instruction",
3412 [TT_PRIV_INSN
] = "Privileged Instruction",
3413 [TT_NFPU_INSN
] = "FPU Disabled",
3414 [TT_FP_EXCP
] = "FPU Exception",
3415 [TT_TOVF
] = "Tag Overflow",
3416 [TT_CLRWIN
] = "Clean Windows",
3417 [TT_DIV_ZERO
] = "Division By Zero",
3418 [TT_DFAULT
] = "Data Access Fault",
3419 [TT_DMISS
] = "Data Access MMU Miss",
3420 [TT_DATA_ACCESS
] = "Data Access Error",
3421 [TT_DPROT
] = "Data Protection Error",
3422 [TT_UNALIGNED
] = "Unaligned Memory Access",
3423 [TT_PRIV_ACT
] = "Privileged Action",
3424 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3425 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3426 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3427 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3428 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3429 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3430 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3431 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3432 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3433 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3434 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3435 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3436 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3437 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3438 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3442 trap_state
* cpu_tsptr(CPUState
* env
)
3444 return &env
->ts
[env
->tl
& MAXTL_MASK
];
3447 void do_interrupt(CPUState
*env
)
3449 int intno
= env
->exception_index
;
3453 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3457 if (intno
< 0 || intno
>= 0x180)
3459 else if (intno
>= 0x100)
3460 name
= "Trap Instruction";
3461 else if (intno
>= 0xc0)
3462 name
= "Window Fill";
3463 else if (intno
>= 0x80)
3464 name
= "Window Spill";
3466 name
= excp_names
[intno
];
3471 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
3472 " SP=%016" PRIx64
"\n",
3475 env
->npc
, env
->regwptr
[6]);
3476 log_cpu_state(env
, 0);
3483 ptr
= (uint8_t *)env
->pc
;
3484 for(i
= 0; i
< 16; i
++) {
3485 qemu_log(" %02x", ldub(ptr
+ i
));
3493 #if !defined(CONFIG_USER_ONLY)
3494 if (env
->tl
>= env
->maxtl
) {
3495 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
3496 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
3500 if (env
->tl
< env
->maxtl
- 1) {
3503 env
->pstate
|= PS_RED
;
3504 if (env
->tl
< env
->maxtl
)
3507 tsptr
= cpu_tsptr(env
);
3509 tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
3510 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
3512 tsptr
->tpc
= env
->pc
;
3513 tsptr
->tnpc
= env
->npc
;
3518 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
3522 case TT_TMISS
... TT_TMISS
+ 3:
3523 case TT_DMISS
... TT_DMISS
+ 3:
3524 case TT_DPROT
... TT_DPROT
+ 3:
3525 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
3528 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
3532 if (intno
== TT_CLRWIN
)
3533 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
3534 else if ((intno
& 0x1c0) == TT_SPILL
)
3535 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
3536 else if ((intno
& 0x1c0) == TT_FILL
)
3537 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
3538 env
->tbr
&= ~0x7fffULL
;
3539 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
3541 env
->npc
= env
->pc
+ 4;
3542 env
->exception_index
= -1;
3546 static const char * const excp_names
[0x80] = {
3547 [TT_TFAULT
] = "Instruction Access Fault",
3548 [TT_ILL_INSN
] = "Illegal Instruction",
3549 [TT_PRIV_INSN
] = "Privileged Instruction",
3550 [TT_NFPU_INSN
] = "FPU Disabled",
3551 [TT_WIN_OVF
] = "Window Overflow",
3552 [TT_WIN_UNF
] = "Window Underflow",
3553 [TT_UNALIGNED
] = "Unaligned Memory Access",
3554 [TT_FP_EXCP
] = "FPU Exception",
3555 [TT_DFAULT
] = "Data Access Fault",
3556 [TT_TOVF
] = "Tag Overflow",
3557 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3558 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3559 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3560 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3561 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3562 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3563 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3564 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3565 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3566 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3567 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3568 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3569 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3570 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3571 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3572 [TT_TOVF
] = "Tag Overflow",
3573 [TT_CODE_ACCESS
] = "Instruction Access Error",
3574 [TT_DATA_ACCESS
] = "Data Access Error",
3575 [TT_DIV_ZERO
] = "Division By Zero",
3576 [TT_NCP_INSN
] = "Coprocessor Disabled",
3580 void do_interrupt(CPUState
*env
)
3582 int cwp
, intno
= env
->exception_index
;
3585 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3589 if (intno
< 0 || intno
>= 0x100)
3591 else if (intno
>= 0x80)
3592 name
= "Trap Instruction";
3594 name
= excp_names
[intno
];
3599 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
3602 env
->npc
, env
->regwptr
[6]);
3603 log_cpu_state(env
, 0);
3610 ptr
= (uint8_t *)env
->pc
;
3611 for(i
= 0; i
< 16; i
++) {
3612 qemu_log(" %02x", ldub(ptr
+ i
));
3620 #if !defined(CONFIG_USER_ONLY)
3621 if (env
->psret
== 0) {
3622 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
3623 env
->exception_index
);
3628 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3629 cpu_set_cwp(env
, cwp
);
3630 env
->regwptr
[9] = env
->pc
;
3631 env
->regwptr
[10] = env
->npc
;
3632 env
->psrps
= env
->psrs
;
3634 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
3636 env
->npc
= env
->pc
+ 4;
3637 env
->exception_index
= -1;
3641 #if !defined(CONFIG_USER_ONLY)
3643 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3646 #define MMUSUFFIX _mmu
3647 #define ALIGNED_ONLY
3650 #include "softmmu_template.h"
3653 #include "softmmu_template.h"
3656 #include "softmmu_template.h"
3659 #include "softmmu_template.h"
3661 /* XXX: make it generic ? */
3662 static void cpu_restore_state2(void *retaddr
)
3664 TranslationBlock
*tb
;
3668 /* now we have a real cpu fault */
3669 pc
= (unsigned long)retaddr
;
3670 tb
= tb_find_pc(pc
);
3672 /* the PC is inside the translated code. It means that we have
3673 a virtual CPU fault */
3674 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
3679 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3682 #ifdef DEBUG_UNALIGNED
3683 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3684 "\n", addr
, env
->pc
);
3686 cpu_restore_state2(retaddr
);
3687 raise_exception(TT_UNALIGNED
);
3690 /* try to fill the TLB and return an exception if error. If retaddr is
3691 NULL, it means that the function was called in C code (i.e. not
3692 from generated code or from helper.c) */
3693 /* XXX: fix it to restore all registers */
3694 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3697 CPUState
*saved_env
;
3699 /* XXX: hack to restore env in all cases, even if not called from
3702 env
= cpu_single_env
;
3704 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3706 cpu_restore_state2(retaddr
);
3712 #endif /* !CONFIG_USER_ONLY */
3714 #ifndef TARGET_SPARC64
3715 #if !defined(CONFIG_USER_ONLY)
3716 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3717 int is_asi
, int size
)
3719 CPUState
*saved_env
;
3722 /* XXX: hack to restore env in all cases, even if not called from
3725 env
= cpu_single_env
;
3726 #ifdef DEBUG_UNASSIGNED
3728 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3729 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3730 is_exec
? "exec" : is_write
? "write" : "read", size
,
3731 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
3733 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3734 " from " TARGET_FMT_lx
"\n",
3735 is_exec
? "exec" : is_write
? "write" : "read", size
,
3736 size
== 1 ? "" : "s", addr
, env
->pc
);
3738 /* Don't overwrite translation and access faults */
3739 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
3740 if ((fault_type
> 4) || (fault_type
== 0)) {
3741 env
->mmuregs
[3] = 0; /* Fault status register */
3743 env
->mmuregs
[3] |= 1 << 16;
3745 env
->mmuregs
[3] |= 1 << 5;
3747 env
->mmuregs
[3] |= 1 << 6;
3749 env
->mmuregs
[3] |= 1 << 7;
3750 env
->mmuregs
[3] |= (5 << 2) | 2;
3751 /* SuperSPARC will never place instruction fault addresses in the FAR */
3753 env
->mmuregs
[4] = addr
; /* Fault address register */
3756 /* overflow (same type fault was not read before another fault) */
3757 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
3758 env
->mmuregs
[3] |= 1;
3761 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3763 raise_exception(TT_CODE_ACCESS
);
3765 raise_exception(TT_DATA_ACCESS
);
3768 /* flush neverland mappings created during no-fault mode,
3769 so the sequential MMU faults report proper fault types */
3770 if (env
->mmuregs
[0] & MMU_NF
) {
3778 #if defined(CONFIG_USER_ONLY)
3779 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
3780 int is_asi
, int size
)
3782 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3783 int is_asi
, int size
)
3786 CPUState
*saved_env
;
3788 /* XXX: hack to restore env in all cases, even if not called from
3791 env
= cpu_single_env
;
3793 #ifdef DEBUG_UNASSIGNED
3794 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3795 "\n", addr
, env
->pc
);
3799 raise_exception(TT_CODE_ACCESS
);
3801 raise_exception(TT_DATA_ACCESS
);
3808 #ifdef TARGET_SPARC64
3809 void helper_tick_set_count(void *opaque
, uint64_t count
)
3811 #if !defined(CONFIG_USER_ONLY)
3812 cpu_tick_set_count(opaque
, count
);
3816 uint64_t helper_tick_get_count(void *opaque
)
3818 #if !defined(CONFIG_USER_ONLY)
3819 return cpu_tick_get_count(opaque
);
3825 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
3827 #if !defined(CONFIG_USER_ONLY)
3828 cpu_tick_set_limit(opaque
, limit
);