2 #include "host-utils.h"
4 #if !defined(CONFIG_USER_ONLY)
5 #include "softmmu_exec.h"
6 #endif /* !defined(CONFIG_USER_ONLY) */
10 //#define DEBUG_UNALIGNED
11 //#define DEBUG_UNASSIGNED
16 #define DPRINTF_MMU(fmt, ...) \
17 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
19 #define DPRINTF_MMU(fmt, ...) do {} while (0)
23 #define DPRINTF_MXCC(fmt, ...) \
24 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
26 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
30 #define DPRINTF_ASI(fmt, ...) \
31 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
36 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
38 #define AM_CHECK(env1) (1)
42 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
43 // Calculates TSB pointer value for fault page size 8k or 64k
44 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
45 uint64_t tag_access_register
,
48 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
49 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
50 int tsb_size
= tsb_register
& 0xf;
52 // discard lower 13 bits which hold tag access context
53 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
56 uint64_t tsb_base_mask
= ~0x1fffULL
;
57 uint64_t va
= tag_access_va
;
59 // move va bits to correct position
60 if (page_size
== 8*1024) {
62 } else if (page_size
== 64*1024) {
67 tsb_base_mask
<<= tsb_size
;
70 // calculate tsb_base mask and adjust va if split is in use
72 if (page_size
== 8*1024) {
73 va
&= ~(1ULL << (13 + tsb_size
));
74 } else if (page_size
== 64*1024) {
75 va
|= (1ULL << (13 + tsb_size
));
80 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
83 // Calculates tag target register value by reordering bits
84 // in tag access register
85 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
87 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
90 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
91 uint64_t tlb_tag
, uint64_t tlb_tte
,
94 target_ulong mask
, size
, va
, offset
;
96 // flush page range if translation is valid
97 if (TTE_IS_VALID(tlb
->tte
)) {
99 mask
= 0xffffffffffffe000ULL
;
100 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
103 va
= tlb
->tag
& mask
;
105 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
106 tlb_flush_page(env1
, va
+ offset
);
114 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
115 const char* strmmu
, CPUState
*env1
)
120 for (i
= 0; i
< 64; i
++) {
121 if (TTE_IS_VALID(tlb
[i
].tte
)) {
123 mask
= 0xffffffffffffe000ULL
;
124 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
126 if ((demap_addr
& mask
) == (tlb
[i
].tag
& mask
)) {
127 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
129 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
139 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
140 uint64_t tlb_tag
, uint64_t tlb_tte
,
141 const char* strmmu
, CPUState
*env1
)
143 unsigned int i
, replace_used
;
145 // Try replacing invalid entry
146 for (i
= 0; i
< 64; i
++) {
147 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
148 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
150 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
157 // All entries are valid, try replacing unlocked entry
159 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
161 // Used entries are not replaced on first pass
163 for (i
= 0; i
< 64; i
++) {
164 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
166 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
168 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
169 strmmu
, (replace_used
?"used":"unused"), i
);
176 // Now reset used bit and search for unused entries again
178 for (i
= 0; i
< 64; i
++) {
179 TTE_SET_UNUSED(tlb
[i
].tte
);
184 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
191 static inline void address_mask(CPUState
*env1
, target_ulong
*addr
)
193 #ifdef TARGET_SPARC64
195 *addr
&= 0xffffffffULL
;
199 static void raise_exception(int tt
)
201 env
->exception_index
= tt
;
205 void HELPER(raise_exception
)(int tt
)
210 static inline void set_cwp(int new_cwp
)
212 cpu_set_cwp(env
, new_cwp
);
215 void helper_check_align(target_ulong addr
, uint32_t align
)
218 #ifdef DEBUG_UNALIGNED
219 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
220 "\n", addr
, env
->pc
);
222 raise_exception(TT_UNALIGNED
);
226 #define F_HELPER(name, p) void helper_f##name##p(void)
228 #define F_BINOP(name) \
229 float32 helper_f ## name ## s (float32 src1, float32 src2) \
231 return float32_ ## name (src1, src2, &env->fp_status); \
235 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
239 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
248 void helper_fsmuld(float32 src1
, float32 src2
)
250 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
251 float32_to_float64(src2
, &env
->fp_status
),
255 void helper_fdmulq(void)
257 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
258 float64_to_float128(DT1
, &env
->fp_status
),
262 float32
helper_fnegs(float32 src
)
264 return float32_chs(src
);
267 #ifdef TARGET_SPARC64
270 DT0
= float64_chs(DT1
);
275 QT0
= float128_chs(QT1
);
279 /* Integer to float conversion. */
280 float32
helper_fitos(int32_t src
)
282 return int32_to_float32(src
, &env
->fp_status
);
285 void helper_fitod(int32_t src
)
287 DT0
= int32_to_float64(src
, &env
->fp_status
);
290 void helper_fitoq(int32_t src
)
292 QT0
= int32_to_float128(src
, &env
->fp_status
);
295 #ifdef TARGET_SPARC64
296 float32
helper_fxtos(void)
298 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
303 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
308 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
313 /* floating point conversion */
314 float32
helper_fdtos(void)
316 return float64_to_float32(DT1
, &env
->fp_status
);
319 void helper_fstod(float32 src
)
321 DT0
= float32_to_float64(src
, &env
->fp_status
);
324 float32
helper_fqtos(void)
326 return float128_to_float32(QT1
, &env
->fp_status
);
329 void helper_fstoq(float32 src
)
331 QT0
= float32_to_float128(src
, &env
->fp_status
);
334 void helper_fqtod(void)
336 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
339 void helper_fdtoq(void)
341 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
344 /* Float to integer conversion. */
345 int32_t helper_fstoi(float32 src
)
347 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
350 int32_t helper_fdtoi(void)
352 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
355 int32_t helper_fqtoi(void)
357 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
360 #ifdef TARGET_SPARC64
361 void helper_fstox(float32 src
)
363 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
366 void helper_fdtox(void)
368 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
371 void helper_fqtox(void)
373 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
376 void helper_faligndata(void)
380 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
381 /* on many architectures a shift of 64 does nothing */
382 if ((env
->gsr
& 7) != 0) {
383 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
385 *((uint64_t *)&DT0
) = tmp
;
388 #ifdef HOST_WORDS_BIGENDIAN
389 #define VIS_B64(n) b[7 - (n)]
390 #define VIS_W64(n) w[3 - (n)]
391 #define VIS_SW64(n) sw[3 - (n)]
392 #define VIS_L64(n) l[1 - (n)]
393 #define VIS_B32(n) b[3 - (n)]
394 #define VIS_W32(n) w[1 - (n)]
396 #define VIS_B64(n) b[n]
397 #define VIS_W64(n) w[n]
398 #define VIS_SW64(n) sw[n]
399 #define VIS_L64(n) l[n]
400 #define VIS_B32(n) b[n]
401 #define VIS_W32(n) w[n]
419 void helper_fpmerge(void)
426 // Reverse calculation order to handle overlap
427 d
.VIS_B64(7) = s
.VIS_B64(3);
428 d
.VIS_B64(6) = d
.VIS_B64(3);
429 d
.VIS_B64(5) = s
.VIS_B64(2);
430 d
.VIS_B64(4) = d
.VIS_B64(2);
431 d
.VIS_B64(3) = s
.VIS_B64(1);
432 d
.VIS_B64(2) = d
.VIS_B64(1);
433 d
.VIS_B64(1) = s
.VIS_B64(0);
434 //d.VIS_B64(0) = d.VIS_B64(0);
439 void helper_fmul8x16(void)
448 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
449 if ((tmp & 0xff) > 0x7f) \
451 d.VIS_W64(r) = tmp >> 8;
462 void helper_fmul8x16al(void)
471 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
472 if ((tmp & 0xff) > 0x7f) \
474 d.VIS_W64(r) = tmp >> 8;
485 void helper_fmul8x16au(void)
494 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
495 if ((tmp & 0xff) > 0x7f) \
497 d.VIS_W64(r) = tmp >> 8;
508 void helper_fmul8sux16(void)
517 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
518 if ((tmp & 0xff) > 0x7f) \
520 d.VIS_W64(r) = tmp >> 8;
531 void helper_fmul8ulx16(void)
540 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
541 if ((tmp & 0xff) > 0x7f) \
543 d.VIS_W64(r) = tmp >> 8;
554 void helper_fmuld8sux16(void)
563 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
564 if ((tmp & 0xff) > 0x7f) \
568 // Reverse calculation order to handle overlap
576 void helper_fmuld8ulx16(void)
585 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
586 if ((tmp & 0xff) > 0x7f) \
590 // Reverse calculation order to handle overlap
598 void helper_fexpand(void)
603 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
605 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
606 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
607 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
608 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
613 #define VIS_HELPER(name, F) \
614 void name##16(void) \
621 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
622 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
623 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
624 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
629 uint32_t name##16s(uint32_t src1, uint32_t src2) \
636 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
637 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
642 void name##32(void) \
649 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
650 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
655 uint32_t name##32s(uint32_t src1, uint32_t src2) \
667 #define FADD(a, b) ((a) + (b))
668 #define FSUB(a, b) ((a) - (b))
669 VIS_HELPER(helper_fpadd
, FADD
)
670 VIS_HELPER(helper_fpsub
, FSUB
)
672 #define VIS_CMPHELPER(name, F) \
673 void name##16(void) \
680 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
681 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
682 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
683 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
688 void name##32(void) \
695 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
696 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
701 #define FCMPGT(a, b) ((a) > (b))
702 #define FCMPEQ(a, b) ((a) == (b))
703 #define FCMPLE(a, b) ((a) <= (b))
704 #define FCMPNE(a, b) ((a) != (b))
706 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
707 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
708 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
709 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
712 void helper_check_ieee_exceptions(void)
716 status
= get_float_exception_flags(&env
->fp_status
);
718 /* Copy IEEE 754 flags into FSR */
719 if (status
& float_flag_invalid
)
721 if (status
& float_flag_overflow
)
723 if (status
& float_flag_underflow
)
725 if (status
& float_flag_divbyzero
)
727 if (status
& float_flag_inexact
)
730 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
731 /* Unmasked exception, generate a trap */
732 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
733 raise_exception(TT_FP_EXCP
);
735 /* Accumulate exceptions */
736 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
741 void helper_clear_float_exceptions(void)
743 set_float_exception_flags(0, &env
->fp_status
);
746 float32
helper_fabss(float32 src
)
748 return float32_abs(src
);
751 #ifdef TARGET_SPARC64
752 void helper_fabsd(void)
754 DT0
= float64_abs(DT1
);
757 void helper_fabsq(void)
759 QT0
= float128_abs(QT1
);
763 float32
helper_fsqrts(float32 src
)
765 return float32_sqrt(src
, &env
->fp_status
);
768 void helper_fsqrtd(void)
770 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
773 void helper_fsqrtq(void)
775 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
778 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
779 void glue(helper_, name) (void) \
781 target_ulong new_fsr; \
783 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
784 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
785 case float_relation_unordered: \
786 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
787 if ((env->fsr & FSR_NVM) || TRAP) { \
788 env->fsr |= new_fsr; \
789 env->fsr |= FSR_NVC; \
790 env->fsr |= FSR_FTT_IEEE_EXCP; \
791 raise_exception(TT_FP_EXCP); \
793 env->fsr |= FSR_NVA; \
796 case float_relation_less: \
797 new_fsr = FSR_FCC0 << FS; \
799 case float_relation_greater: \
800 new_fsr = FSR_FCC1 << FS; \
806 env->fsr |= new_fsr; \
808 #define GEN_FCMPS(name, size, FS, TRAP) \
809 void glue(helper_, name)(float32 src1, float32 src2) \
811 target_ulong new_fsr; \
813 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
814 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
815 case float_relation_unordered: \
816 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
817 if ((env->fsr & FSR_NVM) || TRAP) { \
818 env->fsr |= new_fsr; \
819 env->fsr |= FSR_NVC; \
820 env->fsr |= FSR_FTT_IEEE_EXCP; \
821 raise_exception(TT_FP_EXCP); \
823 env->fsr |= FSR_NVA; \
826 case float_relation_less: \
827 new_fsr = FSR_FCC0 << FS; \
829 case float_relation_greater: \
830 new_fsr = FSR_FCC1 << FS; \
836 env->fsr |= new_fsr; \
839 GEN_FCMPS(fcmps
, float32
, 0, 0);
840 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
842 GEN_FCMPS(fcmpes
, float32
, 0, 1);
843 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
845 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
846 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
848 static uint32_t compute_all_flags(void)
850 return env
->psr
& PSR_ICC
;
853 static uint32_t compute_C_flags(void)
855 return env
->psr
& PSR_CARRY
;
858 static inline uint32_t get_NZ_icc(target_ulong dst
)
862 if (!(dst
& 0xffffffffULL
))
864 if ((int32_t) (dst
& 0xffffffffULL
) < 0)
869 #ifdef TARGET_SPARC64
870 static uint32_t compute_all_flags_xcc(void)
872 return env
->xcc
& PSR_ICC
;
875 static uint32_t compute_C_flags_xcc(void)
877 return env
->xcc
& PSR_CARRY
;
880 static inline uint32_t get_NZ_xcc(target_ulong dst
)
886 if ((int64_t)dst
< 0)
892 static inline uint32_t get_V_div_icc(target_ulong src2
)
901 static uint32_t compute_all_div(void)
905 ret
= get_NZ_icc(CC_DST
);
906 ret
|= get_V_div_icc(CC_SRC2
);
910 static uint32_t compute_C_div(void)
915 static inline uint32_t get_C_add_icc(target_ulong dst
, target_ulong src1
)
919 if ((dst
& 0xffffffffULL
) < (src1
& 0xffffffffULL
))
924 static inline uint32_t get_V_add_icc(target_ulong dst
, target_ulong src1
,
929 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 31))
934 static uint32_t compute_all_add(void)
938 ret
= get_NZ_icc(CC_DST
);
939 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
940 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
944 static uint32_t compute_C_add(void)
946 return get_C_add_icc(CC_DST
, CC_SRC
);
949 #ifdef TARGET_SPARC64
950 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
959 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
964 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63))
969 static uint32_t compute_all_add_xcc(void)
973 ret
= get_NZ_xcc(CC_DST
);
974 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
975 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
979 static uint32_t compute_C_add_xcc(void)
981 return get_C_add_xcc(CC_DST
, CC_SRC
);
985 static uint32_t compute_all_addx(void)
989 ret
= get_NZ_icc(CC_DST
);
990 ret
|= get_C_add_icc(CC_DST
- CC_SRC2
, CC_SRC
);
991 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
992 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
996 static uint32_t compute_C_addx(void)
1000 ret
= get_C_add_icc(CC_DST
- CC_SRC2
, CC_SRC
);
1001 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1005 #ifdef TARGET_SPARC64
1006 static uint32_t compute_all_addx_xcc(void)
1010 ret
= get_NZ_xcc(CC_DST
);
1011 ret
|= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1012 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1013 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1017 static uint32_t compute_C_addx_xcc(void)
1021 ret
= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1022 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1027 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1031 if ((src1
| src2
) & 0x3)
1036 static uint32_t compute_all_tadd(void)
1040 ret
= get_NZ_icc(CC_DST
);
1041 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1042 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1043 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1047 static uint32_t compute_C_tadd(void)
1049 return get_C_add_icc(CC_DST
, CC_SRC
);
1052 static uint32_t compute_all_taddtv(void)
1056 ret
= get_NZ_icc(CC_DST
);
1057 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1061 static uint32_t compute_C_taddtv(void)
1063 return get_C_add_icc(CC_DST
, CC_SRC
);
1066 static inline uint32_t get_C_sub_icc(target_ulong src1
, target_ulong src2
)
1070 if ((src1
& 0xffffffffULL
) < (src2
& 0xffffffffULL
))
1075 static inline uint32_t get_V_sub_icc(target_ulong dst
, target_ulong src1
,
1080 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 31))
1085 static uint32_t compute_all_sub(void)
1089 ret
= get_NZ_icc(CC_DST
);
1090 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1091 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1095 static uint32_t compute_C_sub(void)
1097 return get_C_sub_icc(CC_SRC
, CC_SRC2
);
1100 #ifdef TARGET_SPARC64
1101 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1110 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1115 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63))
1120 static uint32_t compute_all_sub_xcc(void)
1124 ret
= get_NZ_xcc(CC_DST
);
1125 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1126 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1130 static uint32_t compute_C_sub_xcc(void)
1132 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1136 static uint32_t compute_all_subx(void)
1140 ret
= get_NZ_icc(CC_DST
);
1141 ret
|= get_C_sub_icc(CC_DST
- CC_SRC2
, CC_SRC
);
1142 ret
|= get_C_sub_icc(CC_DST
, CC_SRC2
);
1143 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1147 static uint32_t compute_C_subx(void)
1151 ret
= get_C_sub_icc(CC_DST
- CC_SRC2
, CC_SRC
);
1152 ret
|= get_C_sub_icc(CC_DST
, CC_SRC2
);
1156 #ifdef TARGET_SPARC64
1157 static uint32_t compute_all_subx_xcc(void)
1161 ret
= get_NZ_xcc(CC_DST
);
1162 ret
|= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1163 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1164 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1168 static uint32_t compute_C_subx_xcc(void)
1172 ret
= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1173 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1178 static uint32_t compute_all_tsub(void)
1182 ret
= get_NZ_icc(CC_DST
);
1183 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
);
1184 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1185 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1189 static uint32_t compute_C_tsub(void)
1191 return get_C_sub_icc(CC_DST
, CC_SRC
);
1194 static uint32_t compute_all_tsubtv(void)
1198 ret
= get_NZ_icc(CC_DST
);
1199 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
);
1203 static uint32_t compute_C_tsubtv(void)
1205 return get_C_sub_icc(CC_DST
, CC_SRC
);
1208 static uint32_t compute_all_logic(void)
1210 return get_NZ_icc(CC_DST
);
1213 static uint32_t compute_C_logic(void)
1218 #ifdef TARGET_SPARC64
1219 static uint32_t compute_all_logic_xcc(void)
1221 return get_NZ_xcc(CC_DST
);
1225 typedef struct CCTable
{
1226 uint32_t (*compute_all
)(void); /* return all the flags */
1227 uint32_t (*compute_c
)(void); /* return the C flag */
1230 static const CCTable icc_table
[CC_OP_NB
] = {
1231 /* CC_OP_DYNAMIC should never happen */
1232 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1233 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1234 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1235 [CC_OP_ADDX
] = { compute_all_addx
, compute_C_addx
},
1236 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_tadd
},
1237 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_taddtv
},
1238 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1239 [CC_OP_SUBX
] = { compute_all_subx
, compute_C_subx
},
1240 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_tsub
},
1241 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_tsubtv
},
1242 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1245 #ifdef TARGET_SPARC64
1246 static const CCTable xcc_table
[CC_OP_NB
] = {
1247 /* CC_OP_DYNAMIC should never happen */
1248 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1249 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1250 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1251 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1252 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1253 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1254 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1255 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1256 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1257 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1258 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1262 void helper_compute_psr(void)
1266 new_psr
= icc_table
[CC_OP
].compute_all();
1268 #ifdef TARGET_SPARC64
1269 new_psr
= xcc_table
[CC_OP
].compute_all();
1272 CC_OP
= CC_OP_FLAGS
;
1275 uint32_t helper_compute_C_icc(void)
1279 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1283 #ifdef TARGET_SPARC64
1284 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1285 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1286 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1288 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1289 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1290 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1292 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1293 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1294 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1296 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1297 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1298 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1300 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1301 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1302 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1304 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1305 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1306 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1310 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1312 static void dump_mxcc(CPUState
*env
)
1314 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1316 env
->mxccdata
[0], env
->mxccdata
[1],
1317 env
->mxccdata
[2], env
->mxccdata
[3]);
1318 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1320 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1322 env
->mxccregs
[0], env
->mxccregs
[1],
1323 env
->mxccregs
[2], env
->mxccregs
[3],
1324 env
->mxccregs
[4], env
->mxccregs
[5],
1325 env
->mxccregs
[6], env
->mxccregs
[7]);
1329 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1330 && defined(DEBUG_ASI)
1331 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1337 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1338 addr
, asi
, r1
& 0xff);
1341 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1342 addr
, asi
, r1
& 0xffff);
1345 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1346 addr
, asi
, r1
& 0xffffffff);
1349 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1356 #ifndef TARGET_SPARC64
1357 #ifndef CONFIG_USER_ONLY
1358 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1361 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1362 uint32_t last_addr
= addr
;
1365 helper_check_align(addr
, size
- 1);
1367 case 2: /* SuperSparc MXCC registers */
1369 case 0x01c00a00: /* MXCC control register */
1371 ret
= env
->mxccregs
[3];
1373 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1376 case 0x01c00a04: /* MXCC control register */
1378 ret
= env
->mxccregs
[3];
1380 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1383 case 0x01c00c00: /* Module reset register */
1385 ret
= env
->mxccregs
[5];
1386 // should we do something here?
1388 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1391 case 0x01c00f00: /* MBus port address register */
1393 ret
= env
->mxccregs
[7];
1395 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1399 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1403 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1404 "addr = %08x -> ret = %" PRIx64
","
1405 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1410 case 3: /* MMU probe */
1414 mmulev
= (addr
>> 8) & 15;
1418 ret
= mmu_probe(env
, addr
, mmulev
);
1419 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1423 case 4: /* read MMU regs */
1425 int reg
= (addr
>> 8) & 0x1f;
1427 ret
= env
->mmuregs
[reg
];
1428 if (reg
== 3) /* Fault status cleared on read */
1429 env
->mmuregs
[3] = 0;
1430 else if (reg
== 0x13) /* Fault status read */
1431 ret
= env
->mmuregs
[3];
1432 else if (reg
== 0x14) /* Fault address read */
1433 ret
= env
->mmuregs
[4];
1434 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1437 case 5: // Turbosparc ITLB Diagnostic
1438 case 6: // Turbosparc DTLB Diagnostic
1439 case 7: // Turbosparc IOTLB Diagnostic
1441 case 9: /* Supervisor code access */
1444 ret
= ldub_code(addr
);
1447 ret
= lduw_code(addr
);
1451 ret
= ldl_code(addr
);
1454 ret
= ldq_code(addr
);
1458 case 0xa: /* User data access */
1461 ret
= ldub_user(addr
);
1464 ret
= lduw_user(addr
);
1468 ret
= ldl_user(addr
);
1471 ret
= ldq_user(addr
);
1475 case 0xb: /* Supervisor data access */
1478 ret
= ldub_kernel(addr
);
1481 ret
= lduw_kernel(addr
);
1485 ret
= ldl_kernel(addr
);
1488 ret
= ldq_kernel(addr
);
1492 case 0xc: /* I-cache tag */
1493 case 0xd: /* I-cache data */
1494 case 0xe: /* D-cache tag */
1495 case 0xf: /* D-cache data */
1497 case 0x20: /* MMU passthrough */
1500 ret
= ldub_phys(addr
);
1503 ret
= lduw_phys(addr
);
1507 ret
= ldl_phys(addr
);
1510 ret
= ldq_phys(addr
);
1514 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1517 ret
= ldub_phys((target_phys_addr_t
)addr
1518 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1521 ret
= lduw_phys((target_phys_addr_t
)addr
1522 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1526 ret
= ldl_phys((target_phys_addr_t
)addr
1527 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1530 ret
= ldq_phys((target_phys_addr_t
)addr
1531 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1535 case 0x30: // Turbosparc secondary cache diagnostic
1536 case 0x31: // Turbosparc RAM snoop
1537 case 0x32: // Turbosparc page table descriptor diagnostic
1538 case 0x39: /* data cache diagnostic register */
1541 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1543 int reg
= (addr
>> 8) & 3;
1546 case 0: /* Breakpoint Value (Addr) */
1547 ret
= env
->mmubpregs
[reg
];
1549 case 1: /* Breakpoint Mask */
1550 ret
= env
->mmubpregs
[reg
];
1552 case 2: /* Breakpoint Control */
1553 ret
= env
->mmubpregs
[reg
];
1555 case 3: /* Breakpoint Status */
1556 ret
= env
->mmubpregs
[reg
];
1557 env
->mmubpregs
[reg
] = 0ULL;
1560 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1564 case 8: /* User code access, XXX */
1566 do_unassigned_access(addr
, 0, 0, asi
, size
);
1576 ret
= (int16_t) ret
;
1579 ret
= (int32_t) ret
;
1586 dump_asi("read ", last_addr
, asi
, size
, ret
);
1591 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1593 helper_check_align(addr
, size
- 1);
1595 case 2: /* SuperSparc MXCC registers */
1597 case 0x01c00000: /* MXCC stream data register 0 */
1599 env
->mxccdata
[0] = val
;
1601 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1604 case 0x01c00008: /* MXCC stream data register 1 */
1606 env
->mxccdata
[1] = val
;
1608 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1611 case 0x01c00010: /* MXCC stream data register 2 */
1613 env
->mxccdata
[2] = val
;
1615 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1618 case 0x01c00018: /* MXCC stream data register 3 */
1620 env
->mxccdata
[3] = val
;
1622 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1625 case 0x01c00100: /* MXCC stream source */
1627 env
->mxccregs
[0] = val
;
1629 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1631 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1633 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1635 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1637 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1640 case 0x01c00200: /* MXCC stream destination */
1642 env
->mxccregs
[1] = val
;
1644 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1646 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1648 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1650 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1652 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1655 case 0x01c00a00: /* MXCC control register */
1657 env
->mxccregs
[3] = val
;
1659 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1662 case 0x01c00a04: /* MXCC control register */
1664 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1667 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1670 case 0x01c00e00: /* MXCC error register */
1671 // writing a 1 bit clears the error
1673 env
->mxccregs
[6] &= ~val
;
1675 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1678 case 0x01c00f00: /* MBus port address register */
1680 env
->mxccregs
[7] = val
;
1682 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1686 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1690 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1691 asi
, size
, addr
, val
);
1696 case 3: /* MMU flush */
1700 mmulev
= (addr
>> 8) & 15;
1701 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1703 case 0: // flush page
1704 tlb_flush_page(env
, addr
& 0xfffff000);
1706 case 1: // flush segment (256k)
1707 case 2: // flush region (16M)
1708 case 3: // flush context (4G)
1709 case 4: // flush entire
1720 case 4: /* write MMU regs */
1722 int reg
= (addr
>> 8) & 0x1f;
1725 oldreg
= env
->mmuregs
[reg
];
1727 case 0: // Control Register
1728 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1730 // Mappings generated during no-fault mode or MMU
1731 // disabled mode are invalid in normal mode
1732 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1733 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1736 case 1: // Context Table Pointer Register
1737 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1739 case 2: // Context Register
1740 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1741 if (oldreg
!= env
->mmuregs
[reg
]) {
1742 /* we flush when the MMU context changes because
1743 QEMU has no MMU context support */
1747 case 3: // Synchronous Fault Status Register with Clear
1748 case 4: // Synchronous Fault Address Register
1750 case 0x10: // TLB Replacement Control Register
1751 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1753 case 0x13: // Synchronous Fault Status Register with Read and Clear
1754 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1756 case 0x14: // Synchronous Fault Address Register
1757 env
->mmuregs
[4] = val
;
1760 env
->mmuregs
[reg
] = val
;
1763 if (oldreg
!= env
->mmuregs
[reg
]) {
1764 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1765 reg
, oldreg
, env
->mmuregs
[reg
]);
1772 case 5: // Turbosparc ITLB Diagnostic
1773 case 6: // Turbosparc DTLB Diagnostic
1774 case 7: // Turbosparc IOTLB Diagnostic
1776 case 0xa: /* User data access */
1779 stb_user(addr
, val
);
1782 stw_user(addr
, val
);
1786 stl_user(addr
, val
);
1789 stq_user(addr
, val
);
1793 case 0xb: /* Supervisor data access */
1796 stb_kernel(addr
, val
);
1799 stw_kernel(addr
, val
);
1803 stl_kernel(addr
, val
);
1806 stq_kernel(addr
, val
);
1810 case 0xc: /* I-cache tag */
1811 case 0xd: /* I-cache data */
1812 case 0xe: /* D-cache tag */
1813 case 0xf: /* D-cache data */
1814 case 0x10: /* I/D-cache flush page */
1815 case 0x11: /* I/D-cache flush segment */
1816 case 0x12: /* I/D-cache flush region */
1817 case 0x13: /* I/D-cache flush context */
1818 case 0x14: /* I/D-cache flush user */
1820 case 0x17: /* Block copy, sta access */
1826 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1828 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1829 temp
= ldl_kernel(src
);
1830 stl_kernel(dst
, temp
);
1834 case 0x1f: /* Block fill, stda access */
1837 // fill 32 bytes with val
1839 uint32_t dst
= addr
& 7;
1841 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1842 stq_kernel(dst
, val
);
1845 case 0x20: /* MMU passthrough */
1849 stb_phys(addr
, val
);
1852 stw_phys(addr
, val
);
1856 stl_phys(addr
, val
);
1859 stq_phys(addr
, val
);
1864 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1868 stb_phys((target_phys_addr_t
)addr
1869 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1872 stw_phys((target_phys_addr_t
)addr
1873 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1877 stl_phys((target_phys_addr_t
)addr
1878 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1881 stq_phys((target_phys_addr_t
)addr
1882 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1887 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1888 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1889 // Turbosparc snoop RAM
1890 case 0x32: // store buffer control or Turbosparc page table
1891 // descriptor diagnostic
1892 case 0x36: /* I-cache flash clear */
1893 case 0x37: /* D-cache flash clear */
1894 case 0x4c: /* breakpoint action */
1896 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1898 int reg
= (addr
>> 8) & 3;
1901 case 0: /* Breakpoint Value (Addr) */
1902 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1904 case 1: /* Breakpoint Mask */
1905 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1907 case 2: /* Breakpoint Control */
1908 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1910 case 3: /* Breakpoint Status */
1911 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1914 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1918 case 8: /* User code access, XXX */
1919 case 9: /* Supervisor code access, XXX */
1921 do_unassigned_access(addr
, 1, 0, asi
, size
);
1925 dump_asi("write", addr
, asi
, size
, val
);
1929 #endif /* CONFIG_USER_ONLY */
1930 #else /* TARGET_SPARC64 */
1932 #ifdef CONFIG_USER_ONLY
1933 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1936 #if defined(DEBUG_ASI)
1937 target_ulong last_addr
= addr
;
1941 raise_exception(TT_PRIV_ACT
);
1943 helper_check_align(addr
, size
- 1);
1944 address_mask(env
, &addr
);
1947 case 0x82: // Primary no-fault
1948 case 0x8a: // Primary no-fault LE
1949 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1951 dump_asi("read ", last_addr
, asi
, size
, ret
);
1956 case 0x80: // Primary
1957 case 0x88: // Primary LE
1961 ret
= ldub_raw(addr
);
1964 ret
= lduw_raw(addr
);
1967 ret
= ldl_raw(addr
);
1971 ret
= ldq_raw(addr
);
1976 case 0x83: // Secondary no-fault
1977 case 0x8b: // Secondary no-fault LE
1978 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1980 dump_asi("read ", last_addr
, asi
, size
, ret
);
1985 case 0x81: // Secondary
1986 case 0x89: // Secondary LE
1993 /* Convert from little endian */
1995 case 0x88: // Primary LE
1996 case 0x89: // Secondary LE
1997 case 0x8a: // Primary no-fault LE
1998 case 0x8b: // Secondary no-fault LE
2016 /* Convert to signed number */
2023 ret
= (int16_t) ret
;
2026 ret
= (int32_t) ret
;
2033 dump_asi("read ", last_addr
, asi
, size
, ret
);
2038 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2041 dump_asi("write", addr
, asi
, size
, val
);
2044 raise_exception(TT_PRIV_ACT
);
2046 helper_check_align(addr
, size
- 1);
2047 address_mask(env
, &addr
);
2049 /* Convert to little endian */
2051 case 0x88: // Primary LE
2052 case 0x89: // Secondary LE
2071 case 0x80: // Primary
2072 case 0x88: // Primary LE
2091 case 0x81: // Secondary
2092 case 0x89: // Secondary LE
2096 case 0x82: // Primary no-fault, RO
2097 case 0x83: // Secondary no-fault, RO
2098 case 0x8a: // Primary no-fault LE, RO
2099 case 0x8b: // Secondary no-fault LE, RO
2101 do_unassigned_access(addr
, 1, 0, 1, size
);
2106 #else /* CONFIG_USER_ONLY */
2108 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2111 #if defined(DEBUG_ASI)
2112 target_ulong last_addr
= addr
;
2117 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2118 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2119 && asi
>= 0x30 && asi
< 0x80
2120 && !(env
->hpstate
& HS_PRIV
)))
2121 raise_exception(TT_PRIV_ACT
);
2123 helper_check_align(addr
, size
- 1);
2125 case 0x82: // Primary no-fault
2126 case 0x8a: // Primary no-fault LE
2127 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2129 dump_asi("read ", last_addr
, asi
, size
, ret
);
2134 case 0x10: // As if user primary
2135 case 0x18: // As if user primary LE
2136 case 0x80: // Primary
2137 case 0x88: // Primary LE
2138 case 0xe2: // UA2007 Primary block init
2139 case 0xe3: // UA2007 Secondary block init
2140 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2141 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2142 && env
->hpstate
& HS_PRIV
) {
2145 ret
= ldub_hypv(addr
);
2148 ret
= lduw_hypv(addr
);
2151 ret
= ldl_hypv(addr
);
2155 ret
= ldq_hypv(addr
);
2161 ret
= ldub_kernel(addr
);
2164 ret
= lduw_kernel(addr
);
2167 ret
= ldl_kernel(addr
);
2171 ret
= ldq_kernel(addr
);
2178 ret
= ldub_user(addr
);
2181 ret
= lduw_user(addr
);
2184 ret
= ldl_user(addr
);
2188 ret
= ldq_user(addr
);
2193 case 0x14: // Bypass
2194 case 0x15: // Bypass, non-cacheable
2195 case 0x1c: // Bypass LE
2196 case 0x1d: // Bypass, non-cacheable LE
2200 ret
= ldub_phys(addr
);
2203 ret
= lduw_phys(addr
);
2206 ret
= ldl_phys(addr
);
2210 ret
= ldq_phys(addr
);
2215 case 0x24: // Nucleus quad LDD 128 bit atomic
2216 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2217 // Only ldda allowed
2218 raise_exception(TT_ILL_INSN
);
2220 case 0x83: // Secondary no-fault
2221 case 0x8b: // Secondary no-fault LE
2222 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
2224 dump_asi("read ", last_addr
, asi
, size
, ret
);
2229 case 0x04: // Nucleus
2230 case 0x0c: // Nucleus Little Endian (LE)
2231 case 0x11: // As if user secondary
2232 case 0x19: // As if user secondary LE
2233 case 0x4a: // UPA config
2234 case 0x81: // Secondary
2235 case 0x89: // Secondary LE
2241 case 0x50: // I-MMU regs
2243 int reg
= (addr
>> 3) & 0xf;
2246 // I-TSB Tag Target register
2247 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2249 ret
= env
->immuregs
[reg
];
2254 case 0x51: // I-MMU 8k TSB pointer
2256 // env->immuregs[5] holds I-MMU TSB register value
2257 // env->immuregs[6] holds I-MMU Tag Access register value
2258 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2262 case 0x52: // I-MMU 64k TSB pointer
2264 // env->immuregs[5] holds I-MMU TSB register value
2265 // env->immuregs[6] holds I-MMU Tag Access register value
2266 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2270 case 0x55: // I-MMU data access
2272 int reg
= (addr
>> 3) & 0x3f;
2274 ret
= env
->itlb
[reg
].tte
;
2277 case 0x56: // I-MMU tag read
2279 int reg
= (addr
>> 3) & 0x3f;
2281 ret
= env
->itlb
[reg
].tag
;
2284 case 0x58: // D-MMU regs
2286 int reg
= (addr
>> 3) & 0xf;
2289 // D-TSB Tag Target register
2290 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2292 ret
= env
->dmmuregs
[reg
];
2296 case 0x59: // D-MMU 8k TSB pointer
2298 // env->dmmuregs[5] holds D-MMU TSB register value
2299 // env->dmmuregs[6] holds D-MMU Tag Access register value
2300 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2304 case 0x5a: // D-MMU 64k TSB pointer
2306 // env->dmmuregs[5] holds D-MMU TSB register value
2307 // env->dmmuregs[6] holds D-MMU Tag Access register value
2308 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2312 case 0x5d: // D-MMU data access
2314 int reg
= (addr
>> 3) & 0x3f;
2316 ret
= env
->dtlb
[reg
].tte
;
2319 case 0x5e: // D-MMU tag read
2321 int reg
= (addr
>> 3) & 0x3f;
2323 ret
= env
->dtlb
[reg
].tag
;
2326 case 0x46: // D-cache data
2327 case 0x47: // D-cache tag access
2328 case 0x4b: // E-cache error enable
2329 case 0x4c: // E-cache asynchronous fault status
2330 case 0x4d: // E-cache asynchronous fault address
2331 case 0x4e: // E-cache tag data
2332 case 0x66: // I-cache instruction access
2333 case 0x67: // I-cache tag access
2334 case 0x6e: // I-cache predecode
2335 case 0x6f: // I-cache LRU etc.
2336 case 0x76: // E-cache tag
2337 case 0x7e: // E-cache tag
2339 case 0x5b: // D-MMU data pointer
2340 case 0x48: // Interrupt dispatch, RO
2341 case 0x49: // Interrupt data receive
2342 case 0x7f: // Incoming interrupt vector, RO
2345 case 0x54: // I-MMU data in, WO
2346 case 0x57: // I-MMU demap, WO
2347 case 0x5c: // D-MMU data in, WO
2348 case 0x5f: // D-MMU demap, WO
2349 case 0x77: // Interrupt vector, WO
2351 do_unassigned_access(addr
, 0, 0, 1, size
);
2356 /* Convert from little endian */
2358 case 0x0c: // Nucleus Little Endian (LE)
2359 case 0x18: // As if user primary LE
2360 case 0x19: // As if user secondary LE
2361 case 0x1c: // Bypass LE
2362 case 0x1d: // Bypass, non-cacheable LE
2363 case 0x88: // Primary LE
2364 case 0x89: // Secondary LE
2365 case 0x8a: // Primary no-fault LE
2366 case 0x8b: // Secondary no-fault LE
2384 /* Convert to signed number */
2391 ret
= (int16_t) ret
;
2394 ret
= (int32_t) ret
;
2401 dump_asi("read ", last_addr
, asi
, size
, ret
);
2406 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2409 dump_asi("write", addr
, asi
, size
, val
);
2414 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2415 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2416 && asi
>= 0x30 && asi
< 0x80
2417 && !(env
->hpstate
& HS_PRIV
)))
2418 raise_exception(TT_PRIV_ACT
);
2420 helper_check_align(addr
, size
- 1);
2421 /* Convert to little endian */
2423 case 0x0c: // Nucleus Little Endian (LE)
2424 case 0x18: // As if user primary LE
2425 case 0x19: // As if user secondary LE
2426 case 0x1c: // Bypass LE
2427 case 0x1d: // Bypass, non-cacheable LE
2428 case 0x88: // Primary LE
2429 case 0x89: // Secondary LE
2448 case 0x10: // As if user primary
2449 case 0x18: // As if user primary LE
2450 case 0x80: // Primary
2451 case 0x88: // Primary LE
2452 case 0xe2: // UA2007 Primary block init
2453 case 0xe3: // UA2007 Secondary block init
2454 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2455 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2456 && env
->hpstate
& HS_PRIV
) {
2459 stb_hypv(addr
, val
);
2462 stw_hypv(addr
, val
);
2465 stl_hypv(addr
, val
);
2469 stq_hypv(addr
, val
);
2475 stb_kernel(addr
, val
);
2478 stw_kernel(addr
, val
);
2481 stl_kernel(addr
, val
);
2485 stq_kernel(addr
, val
);
2492 stb_user(addr
, val
);
2495 stw_user(addr
, val
);
2498 stl_user(addr
, val
);
2502 stq_user(addr
, val
);
2507 case 0x14: // Bypass
2508 case 0x15: // Bypass, non-cacheable
2509 case 0x1c: // Bypass LE
2510 case 0x1d: // Bypass, non-cacheable LE
2514 stb_phys(addr
, val
);
2517 stw_phys(addr
, val
);
2520 stl_phys(addr
, val
);
2524 stq_phys(addr
, val
);
2529 case 0x24: // Nucleus quad LDD 128 bit atomic
2530 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2531 // Only ldda allowed
2532 raise_exception(TT_ILL_INSN
);
2534 case 0x04: // Nucleus
2535 case 0x0c: // Nucleus Little Endian (LE)
2536 case 0x11: // As if user secondary
2537 case 0x19: // As if user secondary LE
2538 case 0x4a: // UPA config
2539 case 0x81: // Secondary
2540 case 0x89: // Secondary LE
2548 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
2549 // Mappings generated during D/I MMU disabled mode are
2550 // invalid in normal mode
2551 if (oldreg
!= env
->lsu
) {
2552 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
2561 case 0x50: // I-MMU regs
2563 int reg
= (addr
>> 3) & 0xf;
2566 oldreg
= env
->immuregs
[reg
];
2570 case 1: // Not in I-MMU
2575 val
= 0; // Clear SFSR
2576 env
->immu
.sfsr
= val
;
2580 case 5: // TSB access
2581 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
2582 PRIx64
"\n", env
->immu
.tsb
, val
);
2583 env
->immu
.tsb
= val
;
2585 case 6: // Tag access
2586 env
->immu
.tag_access
= val
;
2595 if (oldreg
!= env
->immuregs
[reg
]) {
2596 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2597 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2604 case 0x54: // I-MMU data in
2605 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
2607 case 0x55: // I-MMU data access
2611 unsigned int i
= (addr
>> 3) & 0x3f;
2613 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
2616 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
2621 case 0x57: // I-MMU demap
2622 demap_tlb(env
->itlb
, val
, "immu", env
);
2624 case 0x58: // D-MMU regs
2626 int reg
= (addr
>> 3) & 0xf;
2629 oldreg
= env
->dmmuregs
[reg
];
2635 if ((val
& 1) == 0) {
2636 val
= 0; // Clear SFSR, Fault address
2639 env
->dmmu
.sfsr
= val
;
2641 case 1: // Primary context
2642 env
->dmmu
.mmu_primary_context
= val
;
2644 case 2: // Secondary context
2645 env
->dmmu
.mmu_secondary_context
= val
;
2647 case 5: // TSB access
2648 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
2649 PRIx64
"\n", env
->dmmu
.tsb
, val
);
2650 env
->dmmu
.tsb
= val
;
2652 case 6: // Tag access
2653 env
->dmmu
.tag_access
= val
;
2655 case 7: // Virtual Watchpoint
2656 case 8: // Physical Watchpoint
2658 env
->dmmuregs
[reg
] = val
;
2662 if (oldreg
!= env
->dmmuregs
[reg
]) {
2663 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2664 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2671 case 0x5c: // D-MMU data in
2672 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
2674 case 0x5d: // D-MMU data access
2676 unsigned int i
= (addr
>> 3) & 0x3f;
2678 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
2681 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
2686 case 0x5f: // D-MMU demap
2687 demap_tlb(env
->dtlb
, val
, "dmmu", env
);
2689 case 0x49: // Interrupt data receive
2692 case 0x46: // D-cache data
2693 case 0x47: // D-cache tag access
2694 case 0x4b: // E-cache error enable
2695 case 0x4c: // E-cache asynchronous fault status
2696 case 0x4d: // E-cache asynchronous fault address
2697 case 0x4e: // E-cache tag data
2698 case 0x66: // I-cache instruction access
2699 case 0x67: // I-cache tag access
2700 case 0x6e: // I-cache predecode
2701 case 0x6f: // I-cache LRU etc.
2702 case 0x76: // E-cache tag
2703 case 0x7e: // E-cache tag
2705 case 0x51: // I-MMU 8k TSB pointer, RO
2706 case 0x52: // I-MMU 64k TSB pointer, RO
2707 case 0x56: // I-MMU tag read, RO
2708 case 0x59: // D-MMU 8k TSB pointer, RO
2709 case 0x5a: // D-MMU 64k TSB pointer, RO
2710 case 0x5b: // D-MMU data pointer, RO
2711 case 0x5e: // D-MMU tag read, RO
2712 case 0x48: // Interrupt dispatch, RO
2713 case 0x7f: // Incoming interrupt vector, RO
2714 case 0x82: // Primary no-fault, RO
2715 case 0x83: // Secondary no-fault, RO
2716 case 0x8a: // Primary no-fault LE, RO
2717 case 0x8b: // Secondary no-fault LE, RO
2719 do_unassigned_access(addr
, 1, 0, 1, size
);
2723 #endif /* CONFIG_USER_ONLY */
2725 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2727 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2728 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2729 && asi
>= 0x30 && asi
< 0x80
2730 && !(env
->hpstate
& HS_PRIV
)))
2731 raise_exception(TT_PRIV_ACT
);
2734 case 0x24: // Nucleus quad LDD 128 bit atomic
2735 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2736 helper_check_align(addr
, 0xf);
2738 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2740 bswap64s(&env
->gregs
[1]);
2741 } else if (rd
< 8) {
2742 env
->gregs
[rd
] = ldq_kernel(addr
);
2743 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2745 bswap64s(&env
->gregs
[rd
]);
2746 bswap64s(&env
->gregs
[rd
+ 1]);
2749 env
->regwptr
[rd
] = ldq_kernel(addr
);
2750 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2752 bswap64s(&env
->regwptr
[rd
]);
2753 bswap64s(&env
->regwptr
[rd
+ 1]);
2758 helper_check_align(addr
, 0x3);
2760 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2762 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2763 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2765 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2766 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2772 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2777 helper_check_align(addr
, 3);
2779 case 0xf0: // Block load primary
2780 case 0xf1: // Block load secondary
2781 case 0xf8: // Block load primary LE
2782 case 0xf9: // Block load secondary LE
2784 raise_exception(TT_ILL_INSN
);
2787 helper_check_align(addr
, 0x3f);
2788 for (i
= 0; i
< 16; i
++) {
2789 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2799 val
= helper_ld_asi(addr
, asi
, size
, 0);
2803 *((uint32_t *)&env
->fpr
[rd
]) = val
;
2806 *((int64_t *)&DT0
) = val
;
2814 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2817 target_ulong val
= 0;
2819 helper_check_align(addr
, 3);
2821 case 0xe0: // UA2007 Block commit store primary (cache flush)
2822 case 0xe1: // UA2007 Block commit store secondary (cache flush)
2823 case 0xf0: // Block store primary
2824 case 0xf1: // Block store secondary
2825 case 0xf8: // Block store primary LE
2826 case 0xf9: // Block store secondary LE
2828 raise_exception(TT_ILL_INSN
);
2831 helper_check_align(addr
, 0x3f);
2832 for (i
= 0; i
< 16; i
++) {
2833 val
= *(uint32_t *)&env
->fpr
[rd
++];
2834 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2846 val
= *((uint32_t *)&env
->fpr
[rd
]);
2849 val
= *((int64_t *)&DT0
);
2855 helper_st_asi(addr
, val
, asi
, size
);
2858 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2859 target_ulong val2
, uint32_t asi
)
2863 val2
&= 0xffffffffUL
;
2864 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2865 ret
&= 0xffffffffUL
;
2867 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
2871 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2872 target_ulong val2
, uint32_t asi
)
2876 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2878 helper_st_asi(addr
, val1
, asi
, 8);
2881 #endif /* TARGET_SPARC64 */
2883 #ifndef TARGET_SPARC64
2884 void helper_rett(void)
2888 if (env
->psret
== 1)
2889 raise_exception(TT_ILL_INSN
);
2892 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2893 if (env
->wim
& (1 << cwp
)) {
2894 raise_exception(TT_WIN_UNF
);
2897 env
->psrs
= env
->psrps
;
2901 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2906 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2910 raise_exception(TT_DIV_ZERO
);
2914 if (x0
> 0xffffffff) {
2923 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2928 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2932 raise_exception(TT_DIV_ZERO
);
2936 if ((int32_t) x0
!= x0
) {
2938 return x0
< 0? 0x80000000: 0x7fffffff;
2945 void helper_stdf(target_ulong addr
, int mem_idx
)
2947 helper_check_align(addr
, 7);
2948 #if !defined(CONFIG_USER_ONLY)
2951 stfq_user(addr
, DT0
);
2954 stfq_kernel(addr
, DT0
);
2956 #ifdef TARGET_SPARC64
2958 stfq_hypv(addr
, DT0
);
2965 address_mask(env
, &addr
);
2966 stfq_raw(addr
, DT0
);
2970 void helper_lddf(target_ulong addr
, int mem_idx
)
2972 helper_check_align(addr
, 7);
2973 #if !defined(CONFIG_USER_ONLY)
2976 DT0
= ldfq_user(addr
);
2979 DT0
= ldfq_kernel(addr
);
2981 #ifdef TARGET_SPARC64
2983 DT0
= ldfq_hypv(addr
);
2990 address_mask(env
, &addr
);
2991 DT0
= ldfq_raw(addr
);
2995 void helper_ldqf(target_ulong addr
, int mem_idx
)
2997 // XXX add 128 bit load
3000 helper_check_align(addr
, 7);
3001 #if !defined(CONFIG_USER_ONLY)
3004 u
.ll
.upper
= ldq_user(addr
);
3005 u
.ll
.lower
= ldq_user(addr
+ 8);
3009 u
.ll
.upper
= ldq_kernel(addr
);
3010 u
.ll
.lower
= ldq_kernel(addr
+ 8);
3013 #ifdef TARGET_SPARC64
3015 u
.ll
.upper
= ldq_hypv(addr
);
3016 u
.ll
.lower
= ldq_hypv(addr
+ 8);
3024 address_mask(env
, &addr
);
3025 u
.ll
.upper
= ldq_raw(addr
);
3026 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
3031 void helper_stqf(target_ulong addr
, int mem_idx
)
3033 // XXX add 128 bit store
3036 helper_check_align(addr
, 7);
3037 #if !defined(CONFIG_USER_ONLY)
3041 stq_user(addr
, u
.ll
.upper
);
3042 stq_user(addr
+ 8, u
.ll
.lower
);
3046 stq_kernel(addr
, u
.ll
.upper
);
3047 stq_kernel(addr
+ 8, u
.ll
.lower
);
3049 #ifdef TARGET_SPARC64
3052 stq_hypv(addr
, u
.ll
.upper
);
3053 stq_hypv(addr
+ 8, u
.ll
.lower
);
3061 address_mask(env
, &addr
);
3062 stq_raw(addr
, u
.ll
.upper
);
3063 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
3067 static inline void set_fsr(void)
3071 switch (env
->fsr
& FSR_RD_MASK
) {
3072 case FSR_RD_NEAREST
:
3073 rnd_mode
= float_round_nearest_even
;
3077 rnd_mode
= float_round_to_zero
;
3080 rnd_mode
= float_round_up
;
3083 rnd_mode
= float_round_down
;
3086 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3089 void helper_ldfsr(uint32_t new_fsr
)
3091 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3095 #ifdef TARGET_SPARC64
3096 void helper_ldxfsr(uint64_t new_fsr
)
3098 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3103 void helper_debug(void)
3105 env
->exception_index
= EXCP_DEBUG
;
3109 #ifndef TARGET_SPARC64
3110 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3112 void helper_save(void)
3116 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3117 if (env
->wim
& (1 << cwp
)) {
3118 raise_exception(TT_WIN_OVF
);
3123 void helper_restore(void)
3127 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3128 if (env
->wim
& (1 << cwp
)) {
3129 raise_exception(TT_WIN_UNF
);
3134 void helper_wrpsr(target_ulong new_psr
)
3136 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
3137 raise_exception(TT_ILL_INSN
);
3139 PUT_PSR(env
, new_psr
);
3142 target_ulong
helper_rdpsr(void)
3144 return GET_PSR(env
);
3148 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3150 void helper_save(void)
3154 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3155 if (env
->cansave
== 0) {
3156 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3157 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3158 ((env
->wstate
& 0x7) << 2)));
3160 if (env
->cleanwin
- env
->canrestore
== 0) {
3161 // XXX Clean windows without trap
3162 raise_exception(TT_CLRWIN
);
3171 void helper_restore(void)
3175 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
3176 if (env
->canrestore
== 0) {
3177 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3178 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3179 ((env
->wstate
& 0x7) << 2)));
3187 void helper_flushw(void)
3189 if (env
->cansave
!= env
->nwindows
- 2) {
3190 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3191 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3192 ((env
->wstate
& 0x7) << 2)));
3196 void helper_saved(void)
3199 if (env
->otherwin
== 0)
3205 void helper_restored(void)
3208 if (env
->cleanwin
< env
->nwindows
- 1)
3210 if (env
->otherwin
== 0)
3216 target_ulong
helper_rdccr(void)
3218 return GET_CCR(env
);
3221 void helper_wrccr(target_ulong new_ccr
)
3223 PUT_CCR(env
, new_ccr
);
3226 // CWP handling is reversed in V9, but we still use the V8 register
3228 target_ulong
helper_rdcwp(void)
3230 return GET_CWP64(env
);
3233 void helper_wrcwp(target_ulong new_cwp
)
3235 PUT_CWP64(env
, new_cwp
);
3238 // This function uses non-native bit order
3239 #define GET_FIELD(X, FROM, TO) \
3240 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3242 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3243 #define GET_FIELD_SP(X, FROM, TO) \
3244 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3246 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3248 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3249 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3250 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3251 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3252 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3253 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3254 (((pixel_addr
>> 55) & 1) << 4) |
3255 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3256 GET_FIELD_SP(pixel_addr
, 11, 12);
3259 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3263 tmp
= addr
+ offset
;
3265 env
->gsr
|= tmp
& 7ULL;
3269 target_ulong
helper_popc(target_ulong val
)
3271 return ctpop64(val
);
3274 static inline uint64_t *get_gregset(uint64_t pstate
)
3289 static inline void change_pstate(uint64_t new_pstate
)
3291 uint64_t pstate_regs
, new_pstate_regs
;
3292 uint64_t *src
, *dst
;
3294 if (env
->def
->features
& CPU_FEATURE_GL
) {
3295 // PS_AG is not implemented in this case
3296 new_pstate
&= ~PS_AG
;
3299 pstate_regs
= env
->pstate
& 0xc01;
3300 new_pstate_regs
= new_pstate
& 0xc01;
3302 if (new_pstate_regs
!= pstate_regs
) {
3303 // Switch global register bank
3304 src
= get_gregset(new_pstate_regs
);
3305 dst
= get_gregset(pstate_regs
);
3306 memcpy32(dst
, env
->gregs
);
3307 memcpy32(env
->gregs
, src
);
3309 env
->pstate
= new_pstate
;
3312 void helper_wrpstate(target_ulong new_state
)
3314 change_pstate(new_state
& 0xf3f);
3317 void helper_done(void)
3319 trap_state
* tsptr
= cpu_tsptr(env
);
3321 env
->pc
= tsptr
->tnpc
;
3322 env
->npc
= tsptr
->tnpc
+ 4;
3323 PUT_CCR(env
, tsptr
->tstate
>> 32);
3324 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3325 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3326 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3330 void helper_retry(void)
3332 trap_state
* tsptr
= cpu_tsptr(env
);
3334 env
->pc
= tsptr
->tpc
;
3335 env
->npc
= tsptr
->tnpc
;
3336 PUT_CCR(env
, tsptr
->tstate
>> 32);
3337 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3338 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3339 PUT_CWP64(env
, tsptr
->tstate
& 0xff);
3343 void helper_set_softint(uint64_t value
)
3345 env
->softint
|= (uint32_t)value
;
3348 void helper_clear_softint(uint64_t value
)
3350 env
->softint
&= (uint32_t)~value
;
3353 void helper_write_softint(uint64_t value
)
3355 env
->softint
= (uint32_t)value
;
3359 void helper_flush(target_ulong addr
)
3362 tb_invalidate_page_range(addr
, addr
+ 8);
3365 #ifdef TARGET_SPARC64
3367 static const char * const excp_names
[0x80] = {
3368 [TT_TFAULT
] = "Instruction Access Fault",
3369 [TT_TMISS
] = "Instruction Access MMU Miss",
3370 [TT_CODE_ACCESS
] = "Instruction Access Error",
3371 [TT_ILL_INSN
] = "Illegal Instruction",
3372 [TT_PRIV_INSN
] = "Privileged Instruction",
3373 [TT_NFPU_INSN
] = "FPU Disabled",
3374 [TT_FP_EXCP
] = "FPU Exception",
3375 [TT_TOVF
] = "Tag Overflow",
3376 [TT_CLRWIN
] = "Clean Windows",
3377 [TT_DIV_ZERO
] = "Division By Zero",
3378 [TT_DFAULT
] = "Data Access Fault",
3379 [TT_DMISS
] = "Data Access MMU Miss",
3380 [TT_DATA_ACCESS
] = "Data Access Error",
3381 [TT_DPROT
] = "Data Protection Error",
3382 [TT_UNALIGNED
] = "Unaligned Memory Access",
3383 [TT_PRIV_ACT
] = "Privileged Action",
3384 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3385 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3386 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3387 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3388 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3389 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3390 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3391 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3392 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3393 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3394 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3395 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3396 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3397 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3398 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3402 trap_state
* cpu_tsptr(CPUState
* env
)
3404 return &env
->ts
[env
->tl
& MAXTL_MASK
];
3407 void do_interrupt(CPUState
*env
)
3409 int intno
= env
->exception_index
;
3413 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3417 if (intno
< 0 || intno
>= 0x180)
3419 else if (intno
>= 0x100)
3420 name
= "Trap Instruction";
3421 else if (intno
>= 0xc0)
3422 name
= "Window Fill";
3423 else if (intno
>= 0x80)
3424 name
= "Window Spill";
3426 name
= excp_names
[intno
];
3431 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
3432 " SP=%016" PRIx64
"\n",
3435 env
->npc
, env
->regwptr
[6]);
3436 log_cpu_state(env
, 0);
3443 ptr
= (uint8_t *)env
->pc
;
3444 for(i
= 0; i
< 16; i
++) {
3445 qemu_log(" %02x", ldub(ptr
+ i
));
3453 #if !defined(CONFIG_USER_ONLY)
3454 if (env
->tl
>= env
->maxtl
) {
3455 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
3456 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
3460 if (env
->tl
< env
->maxtl
- 1) {
3463 env
->pstate
|= PS_RED
;
3464 if (env
->tl
< env
->maxtl
)
3467 tsptr
= cpu_tsptr(env
);
3469 tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
3470 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
3472 tsptr
->tpc
= env
->pc
;
3473 tsptr
->tnpc
= env
->npc
;
3478 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
3485 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
3488 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
3492 if (intno
== TT_CLRWIN
)
3493 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
3494 else if ((intno
& 0x1c0) == TT_SPILL
)
3495 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
3496 else if ((intno
& 0x1c0) == TT_FILL
)
3497 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
3498 env
->tbr
&= ~0x7fffULL
;
3499 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
3501 env
->npc
= env
->pc
+ 4;
3502 env
->exception_index
= 0;
3506 static const char * const excp_names
[0x80] = {
3507 [TT_TFAULT
] = "Instruction Access Fault",
3508 [TT_ILL_INSN
] = "Illegal Instruction",
3509 [TT_PRIV_INSN
] = "Privileged Instruction",
3510 [TT_NFPU_INSN
] = "FPU Disabled",
3511 [TT_WIN_OVF
] = "Window Overflow",
3512 [TT_WIN_UNF
] = "Window Underflow",
3513 [TT_UNALIGNED
] = "Unaligned Memory Access",
3514 [TT_FP_EXCP
] = "FPU Exception",
3515 [TT_DFAULT
] = "Data Access Fault",
3516 [TT_TOVF
] = "Tag Overflow",
3517 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3518 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3519 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3520 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3521 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3522 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3523 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3524 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3525 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3526 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3527 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3528 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3529 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3530 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3531 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3532 [TT_TOVF
] = "Tag Overflow",
3533 [TT_CODE_ACCESS
] = "Instruction Access Error",
3534 [TT_DATA_ACCESS
] = "Data Access Error",
3535 [TT_DIV_ZERO
] = "Division By Zero",
3536 [TT_NCP_INSN
] = "Coprocessor Disabled",
3540 void do_interrupt(CPUState
*env
)
3542 int cwp
, intno
= env
->exception_index
;
3545 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3549 if (intno
< 0 || intno
>= 0x100)
3551 else if (intno
>= 0x80)
3552 name
= "Trap Instruction";
3554 name
= excp_names
[intno
];
3559 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
3562 env
->npc
, env
->regwptr
[6]);
3563 log_cpu_state(env
, 0);
3570 ptr
= (uint8_t *)env
->pc
;
3571 for(i
= 0; i
< 16; i
++) {
3572 qemu_log(" %02x", ldub(ptr
+ i
));
3580 #if !defined(CONFIG_USER_ONLY)
3581 if (env
->psret
== 0) {
3582 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
3583 env
->exception_index
);
3588 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
3589 cpu_set_cwp(env
, cwp
);
3590 env
->regwptr
[9] = env
->pc
;
3591 env
->regwptr
[10] = env
->npc
;
3592 env
->psrps
= env
->psrs
;
3594 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
3596 env
->npc
= env
->pc
+ 4;
3597 env
->exception_index
= 0;
3601 #if !defined(CONFIG_USER_ONLY)
3603 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3606 #define MMUSUFFIX _mmu
3607 #define ALIGNED_ONLY
3610 #include "softmmu_template.h"
3613 #include "softmmu_template.h"
3616 #include "softmmu_template.h"
3619 #include "softmmu_template.h"
3621 /* XXX: make it generic ? */
3622 static void cpu_restore_state2(void *retaddr
)
3624 TranslationBlock
*tb
;
3628 /* now we have a real cpu fault */
3629 pc
= (unsigned long)retaddr
;
3630 tb
= tb_find_pc(pc
);
3632 /* the PC is inside the translated code. It means that we have
3633 a virtual CPU fault */
3634 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
3639 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3642 #ifdef DEBUG_UNALIGNED
3643 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3644 "\n", addr
, env
->pc
);
3646 cpu_restore_state2(retaddr
);
3647 raise_exception(TT_UNALIGNED
);
3650 /* try to fill the TLB and return an exception if error. If retaddr is
3651 NULL, it means that the function was called in C code (i.e. not
3652 from generated code or from helper.c) */
3653 /* XXX: fix it to restore all registers */
3654 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3657 CPUState
*saved_env
;
3659 /* XXX: hack to restore env in all cases, even if not called from
3662 env
= cpu_single_env
;
3664 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3666 cpu_restore_state2(retaddr
);
3674 #ifndef TARGET_SPARC64
3675 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3676 int is_asi
, int size
)
3678 CPUState
*saved_env
;
3680 /* XXX: hack to restore env in all cases, even if not called from
3683 env
= cpu_single_env
;
3684 #ifdef DEBUG_UNASSIGNED
3686 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3687 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3688 is_exec
? "exec" : is_write
? "write" : "read", size
,
3689 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
3691 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3692 " from " TARGET_FMT_lx
"\n",
3693 is_exec
? "exec" : is_write
? "write" : "read", size
,
3694 size
== 1 ? "" : "s", addr
, env
->pc
);
3696 if (env
->mmuregs
[3]) /* Fault status register */
3697 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
3699 env
->mmuregs
[3] |= 1 << 16;
3701 env
->mmuregs
[3] |= 1 << 5;
3703 env
->mmuregs
[3] |= 1 << 6;
3705 env
->mmuregs
[3] |= 1 << 7;
3706 env
->mmuregs
[3] |= (5 << 2) | 2;
3707 env
->mmuregs
[4] = addr
; /* Fault address register */
3708 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3710 raise_exception(TT_CODE_ACCESS
);
3712 raise_exception(TT_DATA_ACCESS
);
3717 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3718 int is_asi
, int size
)
3720 #ifdef DEBUG_UNASSIGNED
3721 CPUState
*saved_env
;
3723 /* XXX: hack to restore env in all cases, even if not called from
3726 env
= cpu_single_env
;
3727 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3728 "\n", addr
, env
->pc
);
3732 raise_exception(TT_CODE_ACCESS
);
3734 raise_exception(TT_DATA_ACCESS
);
3738 #ifdef TARGET_SPARC64
3739 void helper_tick_set_count(void *opaque
, uint64_t count
)
3741 #if !defined(CONFIG_USER_ONLY)
3742 cpu_tick_set_count(opaque
, count
);
3746 uint64_t helper_tick_get_count(void *opaque
)
3748 #if !defined(CONFIG_USER_ONLY)
3749 return cpu_tick_get_count(opaque
);
3755 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
3757 #if !defined(CONFIG_USER_ONLY)
3758 cpu_tick_set_limit(opaque
, limit
);