2 #include "host-utils.h"
7 //#define DEBUG_UNALIGNED
8 //#define DEBUG_UNASSIGNED
11 //#define DEBUG_PSTATE
14 #define DPRINTF_MMU(fmt, ...) \
15 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
17 #define DPRINTF_MMU(fmt, ...) do {} while (0)
21 #define DPRINTF_MXCC(fmt, ...) \
22 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
24 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
28 #define DPRINTF_ASI(fmt, ...) \
29 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
33 #define DPRINTF_PSTATE(fmt, ...) \
34 do { printf("PSTATE: " fmt , ## __VA_ARGS__); } while (0)
36 #define DPRINTF_PSTATE(fmt, ...) do {} while (0)
41 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
43 #define AM_CHECK(env1) (1)
47 #define DT0 (env->dt0)
48 #define DT1 (env->dt1)
49 #define QT0 (env->qt0)
50 #define QT1 (env->qt1)
52 #if defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
53 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
54 int is_asi
, int size
);
57 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
58 // Calculates TSB pointer value for fault page size 8k or 64k
59 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
60 uint64_t tag_access_register
,
63 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
64 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
65 int tsb_size
= tsb_register
& 0xf;
67 // discard lower 13 bits which hold tag access context
68 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
71 uint64_t tsb_base_mask
= ~0x1fffULL
;
72 uint64_t va
= tag_access_va
;
74 // move va bits to correct position
75 if (page_size
== 8*1024) {
77 } else if (page_size
== 64*1024) {
82 tsb_base_mask
<<= tsb_size
;
85 // calculate tsb_base mask and adjust va if split is in use
87 if (page_size
== 8*1024) {
88 va
&= ~(1ULL << (13 + tsb_size
));
89 } else if (page_size
== 64*1024) {
90 va
|= (1ULL << (13 + tsb_size
));
95 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
98 // Calculates tag target register value by reordering bits
99 // in tag access register
100 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
102 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
105 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
106 uint64_t tlb_tag
, uint64_t tlb_tte
,
109 target_ulong mask
, size
, va
, offset
;
111 // flush page range if translation is valid
112 if (TTE_IS_VALID(tlb
->tte
)) {
114 mask
= 0xffffffffffffe000ULL
;
115 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
118 va
= tlb
->tag
& mask
;
120 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
121 tlb_flush_page(env1
, va
+ offset
);
129 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
130 const char* strmmu
, CPUState
*env1
)
136 int is_demap_context
= (demap_addr
>> 6) & 1;
139 switch ((demap_addr
>> 4) & 3) {
141 context
= env1
->dmmu
.mmu_primary_context
;
144 context
= env1
->dmmu
.mmu_secondary_context
;
154 for (i
= 0; i
< 64; i
++) {
155 if (TTE_IS_VALID(tlb
[i
].tte
)) {
157 if (is_demap_context
) {
158 // will remove non-global entries matching context value
159 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
160 !tlb_compare_context(&tlb
[i
], context
)) {
165 // will remove any entry matching VA
166 mask
= 0xffffffffffffe000ULL
;
167 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
169 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
173 // entry should be global or matching context value
174 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
175 !tlb_compare_context(&tlb
[i
], context
)) {
180 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
182 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
189 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
190 uint64_t tlb_tag
, uint64_t tlb_tte
,
191 const char* strmmu
, CPUState
*env1
)
193 unsigned int i
, replace_used
;
195 // Try replacing invalid entry
196 for (i
= 0; i
< 64; i
++) {
197 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
198 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
200 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
207 // All entries are valid, try replacing unlocked entry
209 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
211 // Used entries are not replaced on first pass
213 for (i
= 0; i
< 64; i
++) {
214 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
216 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
218 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
219 strmmu
, (replace_used
?"used":"unused"), i
);
226 // Now reset used bit and search for unused entries again
228 for (i
= 0; i
< 64; i
++) {
229 TTE_SET_UNUSED(tlb
[i
].tte
);
234 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
241 static inline target_ulong
address_mask(CPUState
*env1
, target_ulong addr
)
243 #ifdef TARGET_SPARC64
245 addr
&= 0xffffffffULL
;
250 static void raise_exception(int tt
)
252 env
->exception_index
= tt
;
256 void HELPER(raise_exception
)(int tt
)
261 void helper_check_align(target_ulong addr
, uint32_t align
)
264 #ifdef DEBUG_UNALIGNED
265 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
266 "\n", addr
, env
->pc
);
268 raise_exception(TT_UNALIGNED
);
272 #define F_HELPER(name, p) void helper_f##name##p(void)
274 #define F_BINOP(name) \
275 float32 helper_f ## name ## s (float32 src1, float32 src2) \
277 return float32_ ## name (src1, src2, &env->fp_status); \
281 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
285 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
294 void helper_fsmuld(float32 src1
, float32 src2
)
296 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
297 float32_to_float64(src2
, &env
->fp_status
),
301 void helper_fdmulq(void)
303 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
304 float64_to_float128(DT1
, &env
->fp_status
),
308 float32
helper_fnegs(float32 src
)
310 return float32_chs(src
);
313 #ifdef TARGET_SPARC64
316 DT0
= float64_chs(DT1
);
321 QT0
= float128_chs(QT1
);
325 /* Integer to float conversion. */
326 float32
helper_fitos(int32_t src
)
328 return int32_to_float32(src
, &env
->fp_status
);
331 void helper_fitod(int32_t src
)
333 DT0
= int32_to_float64(src
, &env
->fp_status
);
336 void helper_fitoq(int32_t src
)
338 QT0
= int32_to_float128(src
, &env
->fp_status
);
341 #ifdef TARGET_SPARC64
342 float32
helper_fxtos(void)
344 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
349 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
354 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
359 /* floating point conversion */
360 float32
helper_fdtos(void)
362 return float64_to_float32(DT1
, &env
->fp_status
);
365 void helper_fstod(float32 src
)
367 DT0
= float32_to_float64(src
, &env
->fp_status
);
370 float32
helper_fqtos(void)
372 return float128_to_float32(QT1
, &env
->fp_status
);
375 void helper_fstoq(float32 src
)
377 QT0
= float32_to_float128(src
, &env
->fp_status
);
380 void helper_fqtod(void)
382 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
385 void helper_fdtoq(void)
387 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
390 /* Float to integer conversion. */
391 int32_t helper_fstoi(float32 src
)
393 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
396 int32_t helper_fdtoi(void)
398 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
401 int32_t helper_fqtoi(void)
403 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
406 #ifdef TARGET_SPARC64
407 void helper_fstox(float32 src
)
409 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
412 void helper_fdtox(void)
414 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
417 void helper_fqtox(void)
419 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
422 void helper_faligndata(void)
426 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
427 /* on many architectures a shift of 64 does nothing */
428 if ((env
->gsr
& 7) != 0) {
429 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
431 *((uint64_t *)&DT0
) = tmp
;
434 #ifdef HOST_WORDS_BIGENDIAN
435 #define VIS_B64(n) b[7 - (n)]
436 #define VIS_W64(n) w[3 - (n)]
437 #define VIS_SW64(n) sw[3 - (n)]
438 #define VIS_L64(n) l[1 - (n)]
439 #define VIS_B32(n) b[3 - (n)]
440 #define VIS_W32(n) w[1 - (n)]
442 #define VIS_B64(n) b[n]
443 #define VIS_W64(n) w[n]
444 #define VIS_SW64(n) sw[n]
445 #define VIS_L64(n) l[n]
446 #define VIS_B32(n) b[n]
447 #define VIS_W32(n) w[n]
465 void helper_fpmerge(void)
472 // Reverse calculation order to handle overlap
473 d
.VIS_B64(7) = s
.VIS_B64(3);
474 d
.VIS_B64(6) = d
.VIS_B64(3);
475 d
.VIS_B64(5) = s
.VIS_B64(2);
476 d
.VIS_B64(4) = d
.VIS_B64(2);
477 d
.VIS_B64(3) = s
.VIS_B64(1);
478 d
.VIS_B64(2) = d
.VIS_B64(1);
479 d
.VIS_B64(1) = s
.VIS_B64(0);
480 //d.VIS_B64(0) = d.VIS_B64(0);
485 void helper_fmul8x16(void)
494 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
495 if ((tmp & 0xff) > 0x7f) \
497 d.VIS_W64(r) = tmp >> 8;
508 void helper_fmul8x16al(void)
517 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
518 if ((tmp & 0xff) > 0x7f) \
520 d.VIS_W64(r) = tmp >> 8;
531 void helper_fmul8x16au(void)
540 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
541 if ((tmp & 0xff) > 0x7f) \
543 d.VIS_W64(r) = tmp >> 8;
554 void helper_fmul8sux16(void)
563 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
564 if ((tmp & 0xff) > 0x7f) \
566 d.VIS_W64(r) = tmp >> 8;
577 void helper_fmul8ulx16(void)
586 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
587 if ((tmp & 0xff) > 0x7f) \
589 d.VIS_W64(r) = tmp >> 8;
600 void helper_fmuld8sux16(void)
609 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
610 if ((tmp & 0xff) > 0x7f) \
614 // Reverse calculation order to handle overlap
622 void helper_fmuld8ulx16(void)
631 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
632 if ((tmp & 0xff) > 0x7f) \
636 // Reverse calculation order to handle overlap
644 void helper_fexpand(void)
649 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
651 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
652 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
653 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
654 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
659 #define VIS_HELPER(name, F) \
660 void name##16(void) \
667 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
668 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
669 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
670 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
675 uint32_t name##16s(uint32_t src1, uint32_t src2) \
682 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
683 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
688 void name##32(void) \
695 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
696 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
701 uint32_t name##32s(uint32_t src1, uint32_t src2) \
713 #define FADD(a, b) ((a) + (b))
714 #define FSUB(a, b) ((a) - (b))
715 VIS_HELPER(helper_fpadd
, FADD
)
716 VIS_HELPER(helper_fpsub
, FSUB
)
718 #define VIS_CMPHELPER(name, F) \
719 void name##16(void) \
726 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
727 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
728 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
729 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
734 void name##32(void) \
741 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
742 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
747 #define FCMPGT(a, b) ((a) > (b))
748 #define FCMPEQ(a, b) ((a) == (b))
749 #define FCMPLE(a, b) ((a) <= (b))
750 #define FCMPNE(a, b) ((a) != (b))
752 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
753 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
754 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
755 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
758 void helper_check_ieee_exceptions(void)
762 status
= get_float_exception_flags(&env
->fp_status
);
764 /* Copy IEEE 754 flags into FSR */
765 if (status
& float_flag_invalid
)
767 if (status
& float_flag_overflow
)
769 if (status
& float_flag_underflow
)
771 if (status
& float_flag_divbyzero
)
773 if (status
& float_flag_inexact
)
776 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
777 /* Unmasked exception, generate a trap */
778 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
779 raise_exception(TT_FP_EXCP
);
781 /* Accumulate exceptions */
782 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
787 void helper_clear_float_exceptions(void)
789 set_float_exception_flags(0, &env
->fp_status
);
792 float32
helper_fabss(float32 src
)
794 return float32_abs(src
);
797 #ifdef TARGET_SPARC64
798 void helper_fabsd(void)
800 DT0
= float64_abs(DT1
);
803 void helper_fabsq(void)
805 QT0
= float128_abs(QT1
);
809 float32
helper_fsqrts(float32 src
)
811 return float32_sqrt(src
, &env
->fp_status
);
814 void helper_fsqrtd(void)
816 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
819 void helper_fsqrtq(void)
821 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
824 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
825 void glue(helper_, name) (void) \
827 target_ulong new_fsr; \
829 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
830 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
831 case float_relation_unordered: \
832 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
833 if ((env->fsr & FSR_NVM) || TRAP) { \
834 env->fsr |= new_fsr; \
835 env->fsr |= FSR_NVC; \
836 env->fsr |= FSR_FTT_IEEE_EXCP; \
837 raise_exception(TT_FP_EXCP); \
839 env->fsr |= FSR_NVA; \
842 case float_relation_less: \
843 new_fsr = FSR_FCC0 << FS; \
845 case float_relation_greater: \
846 new_fsr = FSR_FCC1 << FS; \
852 env->fsr |= new_fsr; \
854 #define GEN_FCMPS(name, size, FS, TRAP) \
855 void glue(helper_, name)(float32 src1, float32 src2) \
857 target_ulong new_fsr; \
859 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
860 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
861 case float_relation_unordered: \
862 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
863 if ((env->fsr & FSR_NVM) || TRAP) { \
864 env->fsr |= new_fsr; \
865 env->fsr |= FSR_NVC; \
866 env->fsr |= FSR_FTT_IEEE_EXCP; \
867 raise_exception(TT_FP_EXCP); \
869 env->fsr |= FSR_NVA; \
872 case float_relation_less: \
873 new_fsr = FSR_FCC0 << FS; \
875 case float_relation_greater: \
876 new_fsr = FSR_FCC1 << FS; \
882 env->fsr |= new_fsr; \
885 GEN_FCMPS(fcmps
, float32
, 0, 0);
886 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
888 GEN_FCMPS(fcmpes
, float32
, 0, 1);
889 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
891 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
892 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
894 static uint32_t compute_all_flags(void)
896 return env
->psr
& PSR_ICC
;
899 static uint32_t compute_C_flags(void)
901 return env
->psr
& PSR_CARRY
;
904 static inline uint32_t get_NZ_icc(target_ulong dst
)
908 if (!(dst
& 0xffffffffULL
))
910 if ((int32_t) (dst
& 0xffffffffULL
) < 0)
915 #ifdef TARGET_SPARC64
916 static uint32_t compute_all_flags_xcc(void)
918 return env
->xcc
& PSR_ICC
;
921 static uint32_t compute_C_flags_xcc(void)
923 return env
->xcc
& PSR_CARRY
;
926 static inline uint32_t get_NZ_xcc(target_ulong dst
)
932 if ((int64_t)dst
< 0)
938 static inline uint32_t get_V_div_icc(target_ulong src2
)
947 static uint32_t compute_all_div(void)
951 ret
= get_NZ_icc(CC_DST
);
952 ret
|= get_V_div_icc(CC_SRC2
);
956 static uint32_t compute_C_div(void)
961 /* carry = (src1[31] & src2[31]) | ( ~dst[31] & (src1[31] | src2[31])) */
962 static inline uint32_t get_C_add_icc(target_ulong dst
, target_ulong src1
,
967 if (((src1
& (1ULL << 31)) & (src2
& (1ULL << 31)))
968 | ((~(dst
& (1ULL << 31)))
969 & ((src1
& (1ULL << 31)) | (src2
& (1ULL << 31)))))
974 static inline uint32_t get_V_add_icc(target_ulong dst
, target_ulong src1
,
979 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 31))
984 #ifdef TARGET_SPARC64
985 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
994 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
999 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63))
1004 static uint32_t compute_all_add_xcc(void)
1008 ret
= get_NZ_xcc(CC_DST
);
1009 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1010 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1014 static uint32_t compute_C_add_xcc(void)
1016 return get_C_add_xcc(CC_DST
, CC_SRC
);
1020 static uint32_t compute_all_add(void)
1024 ret
= get_NZ_icc(CC_DST
);
1025 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1026 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1030 static uint32_t compute_C_add(void)
1032 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1035 #ifdef TARGET_SPARC64
1036 static uint32_t compute_all_addx_xcc(void)
1040 ret
= get_NZ_xcc(CC_DST
);
1041 ret
|= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1042 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1043 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1047 static uint32_t compute_C_addx_xcc(void)
1051 ret
= get_C_add_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1052 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1057 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1061 if ((src1
| src2
) & 0x3)
1066 static uint32_t compute_all_tadd(void)
1070 ret
= get_NZ_icc(CC_DST
);
1071 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1072 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1073 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1077 static uint32_t compute_C_tadd(void)
1079 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1082 static uint32_t compute_all_taddtv(void)
1086 ret
= get_NZ_icc(CC_DST
);
1087 ret
|= get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1091 static uint32_t compute_C_taddtv(void)
1093 return get_C_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1096 /* carry = (~src1[31] & src2[31]) | ( dst[31] & (~src1[31] | src2[31])) */
1097 static inline uint32_t get_C_sub_icc(target_ulong dst
, target_ulong src1
,
1102 if (((~(src1
& (1ULL << 31))) & (src2
& (1ULL << 31)))
1103 | ((dst
& (1ULL << 31)) & (( ~(src1
& (1ULL << 31)))
1104 | (src2
& (1ULL << 31)))))
1109 static inline uint32_t get_V_sub_icc(target_ulong dst
, target_ulong src1
,
1114 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 31))
1120 #ifdef TARGET_SPARC64
1121 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1130 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1135 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63))
1140 static uint32_t compute_all_sub_xcc(void)
1144 ret
= get_NZ_xcc(CC_DST
);
1145 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1146 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1150 static uint32_t compute_C_sub_xcc(void)
1152 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1156 static uint32_t compute_all_sub(void)
1160 ret
= get_NZ_icc(CC_DST
);
1161 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1162 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1166 static uint32_t compute_C_sub(void)
1168 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1171 #ifdef TARGET_SPARC64
1172 static uint32_t compute_all_subx_xcc(void)
1176 ret
= get_NZ_xcc(CC_DST
);
1177 ret
|= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1178 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1179 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1183 static uint32_t compute_C_subx_xcc(void)
1187 ret
= get_C_sub_xcc(CC_DST
- CC_SRC2
, CC_SRC
);
1188 ret
|= get_C_sub_xcc(CC_DST
, CC_SRC2
);
1193 static uint32_t compute_all_tsub(void)
1197 ret
= get_NZ_icc(CC_DST
);
1198 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1199 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1200 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1204 static uint32_t compute_C_tsub(void)
1206 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1209 static uint32_t compute_all_tsubtv(void)
1213 ret
= get_NZ_icc(CC_DST
);
1214 ret
|= get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1218 static uint32_t compute_C_tsubtv(void)
1220 return get_C_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1223 static uint32_t compute_all_logic(void)
1225 return get_NZ_icc(CC_DST
);
1228 static uint32_t compute_C_logic(void)
1233 #ifdef TARGET_SPARC64
1234 static uint32_t compute_all_logic_xcc(void)
1236 return get_NZ_xcc(CC_DST
);
1240 typedef struct CCTable
{
1241 uint32_t (*compute_all
)(void); /* return all the flags */
1242 uint32_t (*compute_c
)(void); /* return the C flag */
1245 static const CCTable icc_table
[CC_OP_NB
] = {
1246 /* CC_OP_DYNAMIC should never happen */
1247 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1248 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1249 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1250 [CC_OP_ADDX
] = { compute_all_add
, compute_C_add
},
1251 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_tadd
},
1252 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_taddtv
},
1253 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1254 [CC_OP_SUBX
] = { compute_all_sub
, compute_C_sub
},
1255 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_tsub
},
1256 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_tsubtv
},
1257 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1260 #ifdef TARGET_SPARC64
1261 static const CCTable xcc_table
[CC_OP_NB
] = {
1262 /* CC_OP_DYNAMIC should never happen */
1263 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1264 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1265 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1266 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1267 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1268 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1269 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1270 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1271 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1272 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1273 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1277 void helper_compute_psr(void)
1281 new_psr
= icc_table
[CC_OP
].compute_all();
1283 #ifdef TARGET_SPARC64
1284 new_psr
= xcc_table
[CC_OP
].compute_all();
1287 CC_OP
= CC_OP_FLAGS
;
1290 uint32_t helper_compute_C_icc(void)
1294 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1298 static inline void memcpy32(target_ulong
*dst
, const target_ulong
*src
)
1310 static void set_cwp(int new_cwp
)
1312 /* put the modified wrap registers at their proper location */
1313 if (env
->cwp
== env
->nwindows
- 1) {
1314 memcpy32(env
->regbase
, env
->regbase
+ env
->nwindows
* 16);
1318 /* put the wrap registers at their temporary location */
1319 if (new_cwp
== env
->nwindows
- 1) {
1320 memcpy32(env
->regbase
+ env
->nwindows
* 16, env
->regbase
);
1322 env
->regwptr
= env
->regbase
+ (new_cwp
* 16);
1325 void cpu_set_cwp(CPUState
*env1
, int new_cwp
)
1327 CPUState
*saved_env
;
1335 static target_ulong
get_psr(void)
1337 helper_compute_psr();
1339 #if !defined (TARGET_SPARC64)
1340 return env
->version
| (env
->psr
& PSR_ICC
) |
1341 (env
->psref
? PSR_EF
: 0) |
1342 (env
->psrpil
<< 8) |
1343 (env
->psrs
? PSR_S
: 0) |
1344 (env
->psrps
? PSR_PS
: 0) |
1345 (env
->psret
? PSR_ET
: 0) | env
->cwp
;
1347 return env
->version
| (env
->psr
& PSR_ICC
) |
1348 (env
->psref
? PSR_EF
: 0) |
1349 (env
->psrpil
<< 8) |
1350 (env
->psrs
? PSR_S
: 0) |
1351 (env
->psrps
? PSR_PS
: 0) | env
->cwp
;
1355 target_ulong
cpu_get_psr(CPUState
*env1
)
1357 CPUState
*saved_env
;
1367 static void put_psr(target_ulong val
)
1369 env
->psr
= val
& PSR_ICC
;
1370 env
->psref
= (val
& PSR_EF
)? 1 : 0;
1371 env
->psrpil
= (val
& PSR_PIL
) >> 8;
1372 #if ((!defined (TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
1373 cpu_check_irqs(env
);
1375 env
->psrs
= (val
& PSR_S
)? 1 : 0;
1376 env
->psrps
= (val
& PSR_PS
)? 1 : 0;
1377 #if !defined (TARGET_SPARC64)
1378 env
->psret
= (val
& PSR_ET
)? 1 : 0;
1380 set_cwp(val
& PSR_CWP
);
1381 env
->cc_op
= CC_OP_FLAGS
;
1384 void cpu_put_psr(CPUState
*env1
, target_ulong val
)
1386 CPUState
*saved_env
;
1394 static int cwp_inc(int cwp
)
1396 if (unlikely(cwp
>= env
->nwindows
)) {
1397 cwp
-= env
->nwindows
;
1402 int cpu_cwp_inc(CPUState
*env1
, int cwp
)
1404 CPUState
*saved_env
;
1414 static int cwp_dec(int cwp
)
1416 if (unlikely(cwp
< 0)) {
1417 cwp
+= env
->nwindows
;
1422 int cpu_cwp_dec(CPUState
*env1
, int cwp
)
1424 CPUState
*saved_env
;
1434 #ifdef TARGET_SPARC64
1435 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1436 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1437 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1439 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1440 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1441 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1443 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1444 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1445 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1447 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1448 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1449 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1451 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1452 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1453 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1455 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1456 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1457 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1461 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1463 static void dump_mxcc(CPUState
*env
)
1465 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1467 env
->mxccdata
[0], env
->mxccdata
[1],
1468 env
->mxccdata
[2], env
->mxccdata
[3]);
1469 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1471 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1473 env
->mxccregs
[0], env
->mxccregs
[1],
1474 env
->mxccregs
[2], env
->mxccregs
[3],
1475 env
->mxccregs
[4], env
->mxccregs
[5],
1476 env
->mxccregs
[6], env
->mxccregs
[7]);
1480 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1481 && defined(DEBUG_ASI)
1482 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1488 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1489 addr
, asi
, r1
& 0xff);
1492 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1493 addr
, asi
, r1
& 0xffff);
1496 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1497 addr
, asi
, r1
& 0xffffffff);
1500 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1507 #ifndef TARGET_SPARC64
1508 #ifndef CONFIG_USER_ONLY
1509 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1512 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1513 uint32_t last_addr
= addr
;
1516 helper_check_align(addr
, size
- 1);
1518 case 2: /* SuperSparc MXCC registers */
1520 case 0x01c00a00: /* MXCC control register */
1522 ret
= env
->mxccregs
[3];
1524 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1527 case 0x01c00a04: /* MXCC control register */
1529 ret
= env
->mxccregs
[3];
1531 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1534 case 0x01c00c00: /* Module reset register */
1536 ret
= env
->mxccregs
[5];
1537 // should we do something here?
1539 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1542 case 0x01c00f00: /* MBus port address register */
1544 ret
= env
->mxccregs
[7];
1546 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1550 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1554 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1555 "addr = %08x -> ret = %" PRIx64
","
1556 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1561 case 3: /* MMU probe */
1565 mmulev
= (addr
>> 8) & 15;
1569 ret
= mmu_probe(env
, addr
, mmulev
);
1570 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1574 case 4: /* read MMU regs */
1576 int reg
= (addr
>> 8) & 0x1f;
1578 ret
= env
->mmuregs
[reg
];
1579 if (reg
== 3) /* Fault status cleared on read */
1580 env
->mmuregs
[3] = 0;
1581 else if (reg
== 0x13) /* Fault status read */
1582 ret
= env
->mmuregs
[3];
1583 else if (reg
== 0x14) /* Fault address read */
1584 ret
= env
->mmuregs
[4];
1585 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1588 case 5: // Turbosparc ITLB Diagnostic
1589 case 6: // Turbosparc DTLB Diagnostic
1590 case 7: // Turbosparc IOTLB Diagnostic
1592 case 9: /* Supervisor code access */
1595 ret
= ldub_code(addr
);
1598 ret
= lduw_code(addr
);
1602 ret
= ldl_code(addr
);
1605 ret
= ldq_code(addr
);
1609 case 0xa: /* User data access */
1612 ret
= ldub_user(addr
);
1615 ret
= lduw_user(addr
);
1619 ret
= ldl_user(addr
);
1622 ret
= ldq_user(addr
);
1626 case 0xb: /* Supervisor data access */
1629 ret
= ldub_kernel(addr
);
1632 ret
= lduw_kernel(addr
);
1636 ret
= ldl_kernel(addr
);
1639 ret
= ldq_kernel(addr
);
1643 case 0xc: /* I-cache tag */
1644 case 0xd: /* I-cache data */
1645 case 0xe: /* D-cache tag */
1646 case 0xf: /* D-cache data */
1648 case 0x20: /* MMU passthrough */
1651 ret
= ldub_phys(addr
);
1654 ret
= lduw_phys(addr
);
1658 ret
= ldl_phys(addr
);
1661 ret
= ldq_phys(addr
);
1665 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1668 ret
= ldub_phys((target_phys_addr_t
)addr
1669 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1672 ret
= lduw_phys((target_phys_addr_t
)addr
1673 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1677 ret
= ldl_phys((target_phys_addr_t
)addr
1678 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1681 ret
= ldq_phys((target_phys_addr_t
)addr
1682 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1686 case 0x30: // Turbosparc secondary cache diagnostic
1687 case 0x31: // Turbosparc RAM snoop
1688 case 0x32: // Turbosparc page table descriptor diagnostic
1689 case 0x39: /* data cache diagnostic register */
1692 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1694 int reg
= (addr
>> 8) & 3;
1697 case 0: /* Breakpoint Value (Addr) */
1698 ret
= env
->mmubpregs
[reg
];
1700 case 1: /* Breakpoint Mask */
1701 ret
= env
->mmubpregs
[reg
];
1703 case 2: /* Breakpoint Control */
1704 ret
= env
->mmubpregs
[reg
];
1706 case 3: /* Breakpoint Status */
1707 ret
= env
->mmubpregs
[reg
];
1708 env
->mmubpregs
[reg
] = 0ULL;
1711 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1715 case 8: /* User code access, XXX */
1717 do_unassigned_access(addr
, 0, 0, asi
, size
);
1727 ret
= (int16_t) ret
;
1730 ret
= (int32_t) ret
;
1737 dump_asi("read ", last_addr
, asi
, size
, ret
);
1742 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1744 helper_check_align(addr
, size
- 1);
1746 case 2: /* SuperSparc MXCC registers */
1748 case 0x01c00000: /* MXCC stream data register 0 */
1750 env
->mxccdata
[0] = val
;
1752 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1755 case 0x01c00008: /* MXCC stream data register 1 */
1757 env
->mxccdata
[1] = val
;
1759 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1762 case 0x01c00010: /* MXCC stream data register 2 */
1764 env
->mxccdata
[2] = val
;
1766 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1769 case 0x01c00018: /* MXCC stream data register 3 */
1771 env
->mxccdata
[3] = val
;
1773 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1776 case 0x01c00100: /* MXCC stream source */
1778 env
->mxccregs
[0] = val
;
1780 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1782 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1784 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1786 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1788 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1791 case 0x01c00200: /* MXCC stream destination */
1793 env
->mxccregs
[1] = val
;
1795 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1797 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1799 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1801 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1803 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1806 case 0x01c00a00: /* MXCC control register */
1808 env
->mxccregs
[3] = val
;
1810 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1813 case 0x01c00a04: /* MXCC control register */
1815 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1818 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1821 case 0x01c00e00: /* MXCC error register */
1822 // writing a 1 bit clears the error
1824 env
->mxccregs
[6] &= ~val
;
1826 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1829 case 0x01c00f00: /* MBus port address register */
1831 env
->mxccregs
[7] = val
;
1833 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1837 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1841 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1842 asi
, size
, addr
, val
);
1847 case 3: /* MMU flush */
1851 mmulev
= (addr
>> 8) & 15;
1852 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1854 case 0: // flush page
1855 tlb_flush_page(env
, addr
& 0xfffff000);
1857 case 1: // flush segment (256k)
1858 case 2: // flush region (16M)
1859 case 3: // flush context (4G)
1860 case 4: // flush entire
1871 case 4: /* write MMU regs */
1873 int reg
= (addr
>> 8) & 0x1f;
1876 oldreg
= env
->mmuregs
[reg
];
1878 case 0: // Control Register
1879 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1881 // Mappings generated during no-fault mode or MMU
1882 // disabled mode are invalid in normal mode
1883 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1884 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1887 case 1: // Context Table Pointer Register
1888 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1890 case 2: // Context Register
1891 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1892 if (oldreg
!= env
->mmuregs
[reg
]) {
1893 /* we flush when the MMU context changes because
1894 QEMU has no MMU context support */
1898 case 3: // Synchronous Fault Status Register with Clear
1899 case 4: // Synchronous Fault Address Register
1901 case 0x10: // TLB Replacement Control Register
1902 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1904 case 0x13: // Synchronous Fault Status Register with Read and Clear
1905 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1907 case 0x14: // Synchronous Fault Address Register
1908 env
->mmuregs
[4] = val
;
1911 env
->mmuregs
[reg
] = val
;
1914 if (oldreg
!= env
->mmuregs
[reg
]) {
1915 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1916 reg
, oldreg
, env
->mmuregs
[reg
]);
1923 case 5: // Turbosparc ITLB Diagnostic
1924 case 6: // Turbosparc DTLB Diagnostic
1925 case 7: // Turbosparc IOTLB Diagnostic
1927 case 0xa: /* User data access */
1930 stb_user(addr
, val
);
1933 stw_user(addr
, val
);
1937 stl_user(addr
, val
);
1940 stq_user(addr
, val
);
1944 case 0xb: /* Supervisor data access */
1947 stb_kernel(addr
, val
);
1950 stw_kernel(addr
, val
);
1954 stl_kernel(addr
, val
);
1957 stq_kernel(addr
, val
);
1961 case 0xc: /* I-cache tag */
1962 case 0xd: /* I-cache data */
1963 case 0xe: /* D-cache tag */
1964 case 0xf: /* D-cache data */
1965 case 0x10: /* I/D-cache flush page */
1966 case 0x11: /* I/D-cache flush segment */
1967 case 0x12: /* I/D-cache flush region */
1968 case 0x13: /* I/D-cache flush context */
1969 case 0x14: /* I/D-cache flush user */
1971 case 0x17: /* Block copy, sta access */
1977 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1979 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1980 temp
= ldl_kernel(src
);
1981 stl_kernel(dst
, temp
);
1985 case 0x1f: /* Block fill, stda access */
1988 // fill 32 bytes with val
1990 uint32_t dst
= addr
& 7;
1992 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1993 stq_kernel(dst
, val
);
1996 case 0x20: /* MMU passthrough */
2000 stb_phys(addr
, val
);
2003 stw_phys(addr
, val
);
2007 stl_phys(addr
, val
);
2010 stq_phys(addr
, val
);
2015 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
2019 stb_phys((target_phys_addr_t
)addr
2020 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2023 stw_phys((target_phys_addr_t
)addr
2024 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2028 stl_phys((target_phys_addr_t
)addr
2029 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2032 stq_phys((target_phys_addr_t
)addr
2033 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2038 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
2039 case 0x31: // store buffer data, Ross RT620 I-cache flush or
2040 // Turbosparc snoop RAM
2041 case 0x32: // store buffer control or Turbosparc page table
2042 // descriptor diagnostic
2043 case 0x36: /* I-cache flash clear */
2044 case 0x37: /* D-cache flash clear */
2045 case 0x4c: /* breakpoint action */
2047 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
2049 int reg
= (addr
>> 8) & 3;
2052 case 0: /* Breakpoint Value (Addr) */
2053 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2055 case 1: /* Breakpoint Mask */
2056 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2058 case 2: /* Breakpoint Control */
2059 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
2061 case 3: /* Breakpoint Status */
2062 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
2065 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
2069 case 8: /* User code access, XXX */
2070 case 9: /* Supervisor code access, XXX */
2072 do_unassigned_access(addr
, 1, 0, asi
, size
);
2076 dump_asi("write", addr
, asi
, size
, val
);
2080 #endif /* CONFIG_USER_ONLY */
2081 #else /* TARGET_SPARC64 */
2083 #ifdef CONFIG_USER_ONLY
2084 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2087 #if defined(DEBUG_ASI)
2088 target_ulong last_addr
= addr
;
2092 raise_exception(TT_PRIV_ACT
);
2094 helper_check_align(addr
, size
- 1);
2095 addr
= address_mask(env
, addr
);
2098 case 0x82: // Primary no-fault
2099 case 0x8a: // Primary no-fault LE
2100 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2102 dump_asi("read ", last_addr
, asi
, size
, ret
);
2107 case 0x80: // Primary
2108 case 0x88: // Primary LE
2112 ret
= ldub_raw(addr
);
2115 ret
= lduw_raw(addr
);
2118 ret
= ldl_raw(addr
);
2122 ret
= ldq_raw(addr
);
2127 case 0x83: // Secondary no-fault
2128 case 0x8b: // Secondary no-fault LE
2129 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2131 dump_asi("read ", last_addr
, asi
, size
, ret
);
2136 case 0x81: // Secondary
2137 case 0x89: // Secondary LE
2144 /* Convert from little endian */
2146 case 0x88: // Primary LE
2147 case 0x89: // Secondary LE
2148 case 0x8a: // Primary no-fault LE
2149 case 0x8b: // Secondary no-fault LE
2167 /* Convert to signed number */
2174 ret
= (int16_t) ret
;
2177 ret
= (int32_t) ret
;
2184 dump_asi("read ", last_addr
, asi
, size
, ret
);
2189 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2192 dump_asi("write", addr
, asi
, size
, val
);
2195 raise_exception(TT_PRIV_ACT
);
2197 helper_check_align(addr
, size
- 1);
2198 addr
= address_mask(env
, addr
);
2200 /* Convert to little endian */
2202 case 0x88: // Primary LE
2203 case 0x89: // Secondary LE
2222 case 0x80: // Primary
2223 case 0x88: // Primary LE
2242 case 0x81: // Secondary
2243 case 0x89: // Secondary LE
2247 case 0x82: // Primary no-fault, RO
2248 case 0x83: // Secondary no-fault, RO
2249 case 0x8a: // Primary no-fault LE, RO
2250 case 0x8b: // Secondary no-fault LE, RO
2252 do_unassigned_access(addr
, 1, 0, 1, size
);
2257 #else /* CONFIG_USER_ONLY */
2259 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2262 #if defined(DEBUG_ASI)
2263 target_ulong last_addr
= addr
;
2268 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2269 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2270 && asi
>= 0x30 && asi
< 0x80
2271 && !(env
->hpstate
& HS_PRIV
)))
2272 raise_exception(TT_PRIV_ACT
);
2274 helper_check_align(addr
, size
- 1);
2276 case 0x82: // Primary no-fault
2277 case 0x8a: // Primary no-fault LE
2278 case 0x83: // Secondary no-fault
2279 case 0x8b: // Secondary no-fault LE
2281 /* secondary space access has lowest asi bit equal to 1 */
2282 int access_mmu_idx
= ( asi
& 1 ) ? MMU_KERNEL_IDX
2283 : MMU_KERNEL_SECONDARY_IDX
;
2285 if (cpu_get_phys_page_nofault(env
, addr
, access_mmu_idx
) == -1ULL) {
2287 dump_asi("read ", last_addr
, asi
, size
, ret
);
2293 case 0x10: // As if user primary
2294 case 0x11: // As if user secondary
2295 case 0x18: // As if user primary LE
2296 case 0x19: // As if user secondary LE
2297 case 0x80: // Primary
2298 case 0x81: // Secondary
2299 case 0x88: // Primary LE
2300 case 0x89: // Secondary LE
2301 case 0xe2: // UA2007 Primary block init
2302 case 0xe3: // UA2007 Secondary block init
2303 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2304 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2305 && env
->hpstate
& HS_PRIV
) {
2308 ret
= ldub_hypv(addr
);
2311 ret
= lduw_hypv(addr
);
2314 ret
= ldl_hypv(addr
);
2318 ret
= ldq_hypv(addr
);
2322 /* secondary space access has lowest asi bit equal to 1 */
2326 ret
= ldub_kernel_secondary(addr
);
2329 ret
= lduw_kernel_secondary(addr
);
2332 ret
= ldl_kernel_secondary(addr
);
2336 ret
= ldq_kernel_secondary(addr
);
2342 ret
= ldub_kernel(addr
);
2345 ret
= lduw_kernel(addr
);
2348 ret
= ldl_kernel(addr
);
2352 ret
= ldq_kernel(addr
);
2358 /* secondary space access has lowest asi bit equal to 1 */
2362 ret
= ldub_user_secondary(addr
);
2365 ret
= lduw_user_secondary(addr
);
2368 ret
= ldl_user_secondary(addr
);
2372 ret
= ldq_user_secondary(addr
);
2378 ret
= ldub_user(addr
);
2381 ret
= lduw_user(addr
);
2384 ret
= ldl_user(addr
);
2388 ret
= ldq_user(addr
);
2394 case 0x14: // Bypass
2395 case 0x15: // Bypass, non-cacheable
2396 case 0x1c: // Bypass LE
2397 case 0x1d: // Bypass, non-cacheable LE
2401 ret
= ldub_phys(addr
);
2404 ret
= lduw_phys(addr
);
2407 ret
= ldl_phys(addr
);
2411 ret
= ldq_phys(addr
);
2416 case 0x24: // Nucleus quad LDD 128 bit atomic
2417 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2418 // Only ldda allowed
2419 raise_exception(TT_ILL_INSN
);
2421 case 0x04: // Nucleus
2422 case 0x0c: // Nucleus Little Endian (LE)
2426 ret
= ldub_nucleus(addr
);
2429 ret
= lduw_nucleus(addr
);
2432 ret
= ldl_nucleus(addr
);
2436 ret
= ldq_nucleus(addr
);
2441 case 0x4a: // UPA config
2447 case 0x50: // I-MMU regs
2449 int reg
= (addr
>> 3) & 0xf;
2452 // I-TSB Tag Target register
2453 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2455 ret
= env
->immuregs
[reg
];
2460 case 0x51: // I-MMU 8k TSB pointer
2462 // env->immuregs[5] holds I-MMU TSB register value
2463 // env->immuregs[6] holds I-MMU Tag Access register value
2464 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2468 case 0x52: // I-MMU 64k TSB pointer
2470 // env->immuregs[5] holds I-MMU TSB register value
2471 // env->immuregs[6] holds I-MMU Tag Access register value
2472 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2476 case 0x55: // I-MMU data access
2478 int reg
= (addr
>> 3) & 0x3f;
2480 ret
= env
->itlb
[reg
].tte
;
2483 case 0x56: // I-MMU tag read
2485 int reg
= (addr
>> 3) & 0x3f;
2487 ret
= env
->itlb
[reg
].tag
;
2490 case 0x58: // D-MMU regs
2492 int reg
= (addr
>> 3) & 0xf;
2495 // D-TSB Tag Target register
2496 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2498 ret
= env
->dmmuregs
[reg
];
2502 case 0x59: // D-MMU 8k TSB pointer
2504 // env->dmmuregs[5] holds D-MMU TSB register value
2505 // env->dmmuregs[6] holds D-MMU Tag Access register value
2506 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2510 case 0x5a: // D-MMU 64k TSB pointer
2512 // env->dmmuregs[5] holds D-MMU TSB register value
2513 // env->dmmuregs[6] holds D-MMU Tag Access register value
2514 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2518 case 0x5d: // D-MMU data access
2520 int reg
= (addr
>> 3) & 0x3f;
2522 ret
= env
->dtlb
[reg
].tte
;
2525 case 0x5e: // D-MMU tag read
2527 int reg
= (addr
>> 3) & 0x3f;
2529 ret
= env
->dtlb
[reg
].tag
;
2532 case 0x46: // D-cache data
2533 case 0x47: // D-cache tag access
2534 case 0x4b: // E-cache error enable
2535 case 0x4c: // E-cache asynchronous fault status
2536 case 0x4d: // E-cache asynchronous fault address
2537 case 0x4e: // E-cache tag data
2538 case 0x66: // I-cache instruction access
2539 case 0x67: // I-cache tag access
2540 case 0x6e: // I-cache predecode
2541 case 0x6f: // I-cache LRU etc.
2542 case 0x76: // E-cache tag
2543 case 0x7e: // E-cache tag
2545 case 0x5b: // D-MMU data pointer
2546 case 0x48: // Interrupt dispatch, RO
2547 case 0x49: // Interrupt data receive
2548 case 0x7f: // Incoming interrupt vector, RO
2551 case 0x54: // I-MMU data in, WO
2552 case 0x57: // I-MMU demap, WO
2553 case 0x5c: // D-MMU data in, WO
2554 case 0x5f: // D-MMU demap, WO
2555 case 0x77: // Interrupt vector, WO
2557 do_unassigned_access(addr
, 0, 0, 1, size
);
2562 /* Convert from little endian */
2564 case 0x0c: // Nucleus Little Endian (LE)
2565 case 0x18: // As if user primary LE
2566 case 0x19: // As if user secondary LE
2567 case 0x1c: // Bypass LE
2568 case 0x1d: // Bypass, non-cacheable LE
2569 case 0x88: // Primary LE
2570 case 0x89: // Secondary LE
2571 case 0x8a: // Primary no-fault LE
2572 case 0x8b: // Secondary no-fault LE
2590 /* Convert to signed number */
2597 ret
= (int16_t) ret
;
2600 ret
= (int32_t) ret
;
2607 dump_asi("read ", last_addr
, asi
, size
, ret
);
2612 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2615 dump_asi("write", addr
, asi
, size
, val
);
2620 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2621 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2622 && asi
>= 0x30 && asi
< 0x80
2623 && !(env
->hpstate
& HS_PRIV
)))
2624 raise_exception(TT_PRIV_ACT
);
2626 helper_check_align(addr
, size
- 1);
2627 /* Convert to little endian */
2629 case 0x0c: // Nucleus Little Endian (LE)
2630 case 0x18: // As if user primary LE
2631 case 0x19: // As if user secondary LE
2632 case 0x1c: // Bypass LE
2633 case 0x1d: // Bypass, non-cacheable LE
2634 case 0x88: // Primary LE
2635 case 0x89: // Secondary LE
2654 case 0x10: // As if user primary
2655 case 0x11: // As if user secondary
2656 case 0x18: // As if user primary LE
2657 case 0x19: // As if user secondary LE
2658 case 0x80: // Primary
2659 case 0x81: // Secondary
2660 case 0x88: // Primary LE
2661 case 0x89: // Secondary LE
2662 case 0xe2: // UA2007 Primary block init
2663 case 0xe3: // UA2007 Secondary block init
2664 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2665 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
2666 && env
->hpstate
& HS_PRIV
) {
2669 stb_hypv(addr
, val
);
2672 stw_hypv(addr
, val
);
2675 stl_hypv(addr
, val
);
2679 stq_hypv(addr
, val
);
2683 /* secondary space access has lowest asi bit equal to 1 */
2687 stb_kernel_secondary(addr
, val
);
2690 stw_kernel_secondary(addr
, val
);
2693 stl_kernel_secondary(addr
, val
);
2697 stq_kernel_secondary(addr
, val
);
2703 stb_kernel(addr
, val
);
2706 stw_kernel(addr
, val
);
2709 stl_kernel(addr
, val
);
2713 stq_kernel(addr
, val
);
2719 /* secondary space access has lowest asi bit equal to 1 */
2723 stb_user_secondary(addr
, val
);
2726 stw_user_secondary(addr
, val
);
2729 stl_user_secondary(addr
, val
);
2733 stq_user_secondary(addr
, val
);
2739 stb_user(addr
, val
);
2742 stw_user(addr
, val
);
2745 stl_user(addr
, val
);
2749 stq_user(addr
, val
);
2755 case 0x14: // Bypass
2756 case 0x15: // Bypass, non-cacheable
2757 case 0x1c: // Bypass LE
2758 case 0x1d: // Bypass, non-cacheable LE
2762 stb_phys(addr
, val
);
2765 stw_phys(addr
, val
);
2768 stl_phys(addr
, val
);
2772 stq_phys(addr
, val
);
2777 case 0x24: // Nucleus quad LDD 128 bit atomic
2778 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2779 // Only ldda allowed
2780 raise_exception(TT_ILL_INSN
);
2782 case 0x04: // Nucleus
2783 case 0x0c: // Nucleus Little Endian (LE)
2787 stb_nucleus(addr
, val
);
2790 stw_nucleus(addr
, val
);
2793 stl_nucleus(addr
, val
);
2797 stq_nucleus(addr
, val
);
2803 case 0x4a: // UPA config
2811 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
2812 // Mappings generated during D/I MMU disabled mode are
2813 // invalid in normal mode
2814 if (oldreg
!= env
->lsu
) {
2815 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
2824 case 0x50: // I-MMU regs
2826 int reg
= (addr
>> 3) & 0xf;
2829 oldreg
= env
->immuregs
[reg
];
2833 case 1: // Not in I-MMU
2838 val
= 0; // Clear SFSR
2839 env
->immu
.sfsr
= val
;
2843 case 5: // TSB access
2844 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
2845 PRIx64
"\n", env
->immu
.tsb
, val
);
2846 env
->immu
.tsb
= val
;
2848 case 6: // Tag access
2849 env
->immu
.tag_access
= val
;
2858 if (oldreg
!= env
->immuregs
[reg
]) {
2859 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2860 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2867 case 0x54: // I-MMU data in
2868 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
2870 case 0x55: // I-MMU data access
2874 unsigned int i
= (addr
>> 3) & 0x3f;
2876 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
2879 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
2884 case 0x57: // I-MMU demap
2885 demap_tlb(env
->itlb
, addr
, "immu", env
);
2887 case 0x58: // D-MMU regs
2889 int reg
= (addr
>> 3) & 0xf;
2892 oldreg
= env
->dmmuregs
[reg
];
2898 if ((val
& 1) == 0) {
2899 val
= 0; // Clear SFSR, Fault address
2902 env
->dmmu
.sfsr
= val
;
2904 case 1: // Primary context
2905 env
->dmmu
.mmu_primary_context
= val
;
2907 case 2: // Secondary context
2908 env
->dmmu
.mmu_secondary_context
= val
;
2910 case 5: // TSB access
2911 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
2912 PRIx64
"\n", env
->dmmu
.tsb
, val
);
2913 env
->dmmu
.tsb
= val
;
2915 case 6: // Tag access
2916 env
->dmmu
.tag_access
= val
;
2918 case 7: // Virtual Watchpoint
2919 case 8: // Physical Watchpoint
2921 env
->dmmuregs
[reg
] = val
;
2925 if (oldreg
!= env
->dmmuregs
[reg
]) {
2926 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2927 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2934 case 0x5c: // D-MMU data in
2935 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
2937 case 0x5d: // D-MMU data access
2939 unsigned int i
= (addr
>> 3) & 0x3f;
2941 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
2944 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
2949 case 0x5f: // D-MMU demap
2950 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
2952 case 0x49: // Interrupt data receive
2955 case 0x46: // D-cache data
2956 case 0x47: // D-cache tag access
2957 case 0x4b: // E-cache error enable
2958 case 0x4c: // E-cache asynchronous fault status
2959 case 0x4d: // E-cache asynchronous fault address
2960 case 0x4e: // E-cache tag data
2961 case 0x66: // I-cache instruction access
2962 case 0x67: // I-cache tag access
2963 case 0x6e: // I-cache predecode
2964 case 0x6f: // I-cache LRU etc.
2965 case 0x76: // E-cache tag
2966 case 0x7e: // E-cache tag
2968 case 0x51: // I-MMU 8k TSB pointer, RO
2969 case 0x52: // I-MMU 64k TSB pointer, RO
2970 case 0x56: // I-MMU tag read, RO
2971 case 0x59: // D-MMU 8k TSB pointer, RO
2972 case 0x5a: // D-MMU 64k TSB pointer, RO
2973 case 0x5b: // D-MMU data pointer, RO
2974 case 0x5e: // D-MMU tag read, RO
2975 case 0x48: // Interrupt dispatch, RO
2976 case 0x7f: // Incoming interrupt vector, RO
2977 case 0x82: // Primary no-fault, RO
2978 case 0x83: // Secondary no-fault, RO
2979 case 0x8a: // Primary no-fault LE, RO
2980 case 0x8b: // Secondary no-fault LE, RO
2982 do_unassigned_access(addr
, 1, 0, 1, size
);
2986 #endif /* CONFIG_USER_ONLY */
2988 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2990 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2991 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2992 && asi
>= 0x30 && asi
< 0x80
2993 && !(env
->hpstate
& HS_PRIV
)))
2994 raise_exception(TT_PRIV_ACT
);
2997 case 0x24: // Nucleus quad LDD 128 bit atomic
2998 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2999 helper_check_align(addr
, 0xf);
3001 env
->gregs
[1] = ldq_kernel(addr
+ 8);
3003 bswap64s(&env
->gregs
[1]);
3004 } else if (rd
< 8) {
3005 env
->gregs
[rd
] = ldq_kernel(addr
);
3006 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
3008 bswap64s(&env
->gregs
[rd
]);
3009 bswap64s(&env
->gregs
[rd
+ 1]);
3012 env
->regwptr
[rd
] = ldq_kernel(addr
);
3013 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
3015 bswap64s(&env
->regwptr
[rd
]);
3016 bswap64s(&env
->regwptr
[rd
+ 1]);
3021 helper_check_align(addr
, 0x3);
3023 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3025 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3026 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3028 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3029 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3035 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3040 helper_check_align(addr
, 3);
3042 case 0xf0: // Block load primary
3043 case 0xf1: // Block load secondary
3044 case 0xf8: // Block load primary LE
3045 case 0xf9: // Block load secondary LE
3047 raise_exception(TT_ILL_INSN
);
3050 helper_check_align(addr
, 0x3f);
3051 for (i
= 0; i
< 16; i
++) {
3052 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
3062 val
= helper_ld_asi(addr
, asi
, size
, 0);
3066 *((uint32_t *)&env
->fpr
[rd
]) = val
;
3069 *((int64_t *)&DT0
) = val
;
3077 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3080 target_ulong val
= 0;
3082 helper_check_align(addr
, 3);
3084 case 0xe0: // UA2007 Block commit store primary (cache flush)
3085 case 0xe1: // UA2007 Block commit store secondary (cache flush)
3086 case 0xf0: // Block store primary
3087 case 0xf1: // Block store secondary
3088 case 0xf8: // Block store primary LE
3089 case 0xf9: // Block store secondary LE
3091 raise_exception(TT_ILL_INSN
);
3094 helper_check_align(addr
, 0x3f);
3095 for (i
= 0; i
< 16; i
++) {
3096 val
= *(uint32_t *)&env
->fpr
[rd
++];
3097 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
3109 val
= *((uint32_t *)&env
->fpr
[rd
]);
3112 val
= *((int64_t *)&DT0
);
3118 helper_st_asi(addr
, val
, asi
, size
);
3121 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
3122 target_ulong val2
, uint32_t asi
)
3126 val2
&= 0xffffffffUL
;
3127 ret
= helper_ld_asi(addr
, asi
, 4, 0);
3128 ret
&= 0xffffffffUL
;
3130 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
3134 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
3135 target_ulong val2
, uint32_t asi
)
3139 ret
= helper_ld_asi(addr
, asi
, 8, 0);
3141 helper_st_asi(addr
, val1
, asi
, 8);
3144 #endif /* TARGET_SPARC64 */
3146 #ifndef TARGET_SPARC64
3147 void helper_rett(void)
3151 if (env
->psret
== 1)
3152 raise_exception(TT_ILL_INSN
);
3155 cwp
= cwp_inc(env
->cwp
+ 1) ;
3156 if (env
->wim
& (1 << cwp
)) {
3157 raise_exception(TT_WIN_UNF
);
3160 env
->psrs
= env
->psrps
;
3164 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
3169 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3173 raise_exception(TT_DIV_ZERO
);
3177 if (x0
> 0xffffffff) {
3186 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
3191 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3195 raise_exception(TT_DIV_ZERO
);
3199 if ((int32_t) x0
!= x0
) {
3201 return x0
< 0? 0x80000000: 0x7fffffff;
3208 void helper_stdf(target_ulong addr
, int mem_idx
)
3210 helper_check_align(addr
, 7);
3211 #if !defined(CONFIG_USER_ONLY)
3214 stfq_user(addr
, DT0
);
3217 stfq_kernel(addr
, DT0
);
3219 #ifdef TARGET_SPARC64
3221 stfq_hypv(addr
, DT0
);
3228 stfq_raw(address_mask(env
, addr
), DT0
);
3232 void helper_lddf(target_ulong addr
, int mem_idx
)
3234 helper_check_align(addr
, 7);
3235 #if !defined(CONFIG_USER_ONLY)
3238 DT0
= ldfq_user(addr
);
3241 DT0
= ldfq_kernel(addr
);
3243 #ifdef TARGET_SPARC64
3245 DT0
= ldfq_hypv(addr
);
3252 DT0
= ldfq_raw(address_mask(env
, addr
));
3256 void helper_ldqf(target_ulong addr
, int mem_idx
)
3258 // XXX add 128 bit load
3261 helper_check_align(addr
, 7);
3262 #if !defined(CONFIG_USER_ONLY)
3265 u
.ll
.upper
= ldq_user(addr
);
3266 u
.ll
.lower
= ldq_user(addr
+ 8);
3270 u
.ll
.upper
= ldq_kernel(addr
);
3271 u
.ll
.lower
= ldq_kernel(addr
+ 8);
3274 #ifdef TARGET_SPARC64
3276 u
.ll
.upper
= ldq_hypv(addr
);
3277 u
.ll
.lower
= ldq_hypv(addr
+ 8);
3285 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
3286 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
3291 void helper_stqf(target_ulong addr
, int mem_idx
)
3293 // XXX add 128 bit store
3296 helper_check_align(addr
, 7);
3297 #if !defined(CONFIG_USER_ONLY)
3301 stq_user(addr
, u
.ll
.upper
);
3302 stq_user(addr
+ 8, u
.ll
.lower
);
3306 stq_kernel(addr
, u
.ll
.upper
);
3307 stq_kernel(addr
+ 8, u
.ll
.lower
);
3309 #ifdef TARGET_SPARC64
3312 stq_hypv(addr
, u
.ll
.upper
);
3313 stq_hypv(addr
+ 8, u
.ll
.lower
);
3321 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
3322 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
3326 static inline void set_fsr(void)
3330 switch (env
->fsr
& FSR_RD_MASK
) {
3331 case FSR_RD_NEAREST
:
3332 rnd_mode
= float_round_nearest_even
;
3336 rnd_mode
= float_round_to_zero
;
3339 rnd_mode
= float_round_up
;
3342 rnd_mode
= float_round_down
;
3345 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3348 void helper_ldfsr(uint32_t new_fsr
)
3350 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3354 #ifdef TARGET_SPARC64
3355 void helper_ldxfsr(uint64_t new_fsr
)
3357 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3362 void helper_debug(void)
3364 env
->exception_index
= EXCP_DEBUG
;
3368 #ifndef TARGET_SPARC64
3369 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3371 void helper_save(void)
3375 cwp
= cwp_dec(env
->cwp
- 1);
3376 if (env
->wim
& (1 << cwp
)) {
3377 raise_exception(TT_WIN_OVF
);
3382 void helper_restore(void)
3386 cwp
= cwp_inc(env
->cwp
+ 1);
3387 if (env
->wim
& (1 << cwp
)) {
3388 raise_exception(TT_WIN_UNF
);
3393 void helper_wrpsr(target_ulong new_psr
)
3395 if ((new_psr
& PSR_CWP
) >= env
->nwindows
) {
3396 raise_exception(TT_ILL_INSN
);
3398 cpu_put_psr(env
, new_psr
);
3402 target_ulong
helper_rdpsr(void)
3408 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3410 void helper_save(void)
3414 cwp
= cwp_dec(env
->cwp
- 1);
3415 if (env
->cansave
== 0) {
3416 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3417 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3418 ((env
->wstate
& 0x7) << 2)));
3420 if (env
->cleanwin
- env
->canrestore
== 0) {
3421 // XXX Clean windows without trap
3422 raise_exception(TT_CLRWIN
);
3431 void helper_restore(void)
3435 cwp
= cwp_inc(env
->cwp
+ 1);
3436 if (env
->canrestore
== 0) {
3437 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3438 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3439 ((env
->wstate
& 0x7) << 2)));
3447 void helper_flushw(void)
3449 if (env
->cansave
!= env
->nwindows
- 2) {
3450 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3451 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3452 ((env
->wstate
& 0x7) << 2)));
3456 void helper_saved(void)
3459 if (env
->otherwin
== 0)
3465 void helper_restored(void)
3468 if (env
->cleanwin
< env
->nwindows
- 1)
3470 if (env
->otherwin
== 0)
3476 static target_ulong
get_ccr(void)
3482 return ((env
->xcc
>> 20) << 4) | ((psr
& PSR_ICC
) >> 20);
3485 target_ulong
cpu_get_ccr(CPUState
*env1
)
3487 CPUState
*saved_env
;
3497 static void put_ccr(target_ulong val
)
3499 target_ulong tmp
= val
;
3501 env
->xcc
= (tmp
>> 4) << 20;
3502 env
->psr
= (tmp
& 0xf) << 20;
3503 CC_OP
= CC_OP_FLAGS
;
3506 void cpu_put_ccr(CPUState
*env1
, target_ulong val
)
3508 CPUState
*saved_env
;
3516 static target_ulong
get_cwp64(void)
3518 return env
->nwindows
- 1 - env
->cwp
;
3521 target_ulong
cpu_get_cwp64(CPUState
*env1
)
3523 CPUState
*saved_env
;
3533 static void put_cwp64(int cwp
)
3535 if (unlikely(cwp
>= env
->nwindows
|| cwp
< 0)) {
3536 cwp
%= env
->nwindows
;
3538 set_cwp(env
->nwindows
- 1 - cwp
);
3541 void cpu_put_cwp64(CPUState
*env1
, int cwp
)
3543 CPUState
*saved_env
;
3551 target_ulong
helper_rdccr(void)
3556 void helper_wrccr(target_ulong new_ccr
)
3561 // CWP handling is reversed in V9, but we still use the V8 register
3563 target_ulong
helper_rdcwp(void)
3568 void helper_wrcwp(target_ulong new_cwp
)
3573 // This function uses non-native bit order
3574 #define GET_FIELD(X, FROM, TO) \
3575 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3577 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3578 #define GET_FIELD_SP(X, FROM, TO) \
3579 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3581 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3583 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3584 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3585 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3586 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3587 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3588 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3589 (((pixel_addr
>> 55) & 1) << 4) |
3590 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3591 GET_FIELD_SP(pixel_addr
, 11, 12);
3594 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3598 tmp
= addr
+ offset
;
3600 env
->gsr
|= tmp
& 7ULL;
3604 target_ulong
helper_popc(target_ulong val
)
3606 return ctpop64(val
);
3609 static inline uint64_t *get_gregset(uint32_t pstate
)
3613 DPRINTF_PSTATE("ERROR in get_gregset: active pstate bits=%x%s%s%s\n",
3615 (pstate
& PS_IG
) ? " IG" : "",
3616 (pstate
& PS_MG
) ? " MG" : "",
3617 (pstate
& PS_AG
) ? " AG" : "");
3618 /* pass through to normal set of global registers */
3630 static inline void change_pstate(uint32_t new_pstate
)
3632 uint32_t pstate_regs
, new_pstate_regs
;
3633 uint64_t *src
, *dst
;
3635 if (env
->def
->features
& CPU_FEATURE_GL
) {
3636 // PS_AG is not implemented in this case
3637 new_pstate
&= ~PS_AG
;
3640 pstate_regs
= env
->pstate
& 0xc01;
3641 new_pstate_regs
= new_pstate
& 0xc01;
3643 if (new_pstate_regs
!= pstate_regs
) {
3644 DPRINTF_PSTATE("change_pstate: switching regs old=%x new=%x\n",
3645 pstate_regs
, new_pstate_regs
);
3646 // Switch global register bank
3647 src
= get_gregset(new_pstate_regs
);
3648 dst
= get_gregset(pstate_regs
);
3649 memcpy32(dst
, env
->gregs
);
3650 memcpy32(env
->gregs
, src
);
3653 DPRINTF_PSTATE("change_pstate: regs new=%x (unchanged)\n",
3656 env
->pstate
= new_pstate
;
3659 void helper_wrpstate(target_ulong new_state
)
3661 change_pstate(new_state
& 0xf3f);
3663 #if !defined(CONFIG_USER_ONLY)
3664 if (cpu_interrupts_enabled(env
)) {
3665 cpu_check_irqs(env
);
3670 void helper_wrpil(target_ulong new_pil
)
3672 #if !defined(CONFIG_USER_ONLY)
3673 DPRINTF_PSTATE("helper_wrpil old=%x new=%x\n",
3674 env
->psrpil
, (uint32_t)new_pil
);
3676 env
->psrpil
= new_pil
;
3678 if (cpu_interrupts_enabled(env
)) {
3679 cpu_check_irqs(env
);
3684 void helper_done(void)
3686 trap_state
* tsptr
= cpu_tsptr(env
);
3688 env
->pc
= tsptr
->tnpc
;
3689 env
->npc
= tsptr
->tnpc
+ 4;
3690 put_ccr(tsptr
->tstate
>> 32);
3691 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3692 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3693 put_cwp64(tsptr
->tstate
& 0xff);
3696 DPRINTF_PSTATE("... helper_done tl=%d\n", env
->tl
);
3698 #if !defined(CONFIG_USER_ONLY)
3699 if (cpu_interrupts_enabled(env
)) {
3700 cpu_check_irqs(env
);
3705 void helper_retry(void)
3707 trap_state
* tsptr
= cpu_tsptr(env
);
3709 env
->pc
= tsptr
->tpc
;
3710 env
->npc
= tsptr
->tnpc
;
3711 put_ccr(tsptr
->tstate
>> 32);
3712 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3713 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3714 put_cwp64(tsptr
->tstate
& 0xff);
3717 DPRINTF_PSTATE("... helper_retry tl=%d\n", env
->tl
);
3719 #if !defined(CONFIG_USER_ONLY)
3720 if (cpu_interrupts_enabled(env
)) {
3721 cpu_check_irqs(env
);
3726 static void do_modify_softint(const char* operation
, uint32_t value
)
3728 if (env
->softint
!= value
) {
3729 env
->softint
= value
;
3730 DPRINTF_PSTATE(": %s new %08x\n", operation
, env
->softint
);
3731 #if !defined(CONFIG_USER_ONLY)
3732 if (cpu_interrupts_enabled(env
)) {
3733 cpu_check_irqs(env
);
3739 void helper_set_softint(uint64_t value
)
3741 do_modify_softint("helper_set_softint", env
->softint
| (uint32_t)value
);
3744 void helper_clear_softint(uint64_t value
)
3746 do_modify_softint("helper_clear_softint", env
->softint
& (uint32_t)~value
);
3749 void helper_write_softint(uint64_t value
)
3751 do_modify_softint("helper_write_softint", (uint32_t)value
);
3755 void helper_flush(target_ulong addr
)
3758 tb_invalidate_page_range(addr
, addr
+ 8);
3761 #ifdef TARGET_SPARC64
3763 static const char * const excp_names
[0x80] = {
3764 [TT_TFAULT
] = "Instruction Access Fault",
3765 [TT_TMISS
] = "Instruction Access MMU Miss",
3766 [TT_CODE_ACCESS
] = "Instruction Access Error",
3767 [TT_ILL_INSN
] = "Illegal Instruction",
3768 [TT_PRIV_INSN
] = "Privileged Instruction",
3769 [TT_NFPU_INSN
] = "FPU Disabled",
3770 [TT_FP_EXCP
] = "FPU Exception",
3771 [TT_TOVF
] = "Tag Overflow",
3772 [TT_CLRWIN
] = "Clean Windows",
3773 [TT_DIV_ZERO
] = "Division By Zero",
3774 [TT_DFAULT
] = "Data Access Fault",
3775 [TT_DMISS
] = "Data Access MMU Miss",
3776 [TT_DATA_ACCESS
] = "Data Access Error",
3777 [TT_DPROT
] = "Data Protection Error",
3778 [TT_UNALIGNED
] = "Unaligned Memory Access",
3779 [TT_PRIV_ACT
] = "Privileged Action",
3780 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3781 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3782 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3783 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3784 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3785 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3786 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3787 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3788 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3789 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3790 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3791 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3792 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3793 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3794 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3798 trap_state
* cpu_tsptr(CPUState
* env
)
3800 return &env
->ts
[env
->tl
& MAXTL_MASK
];
3803 void do_interrupt(CPUState
*env
)
3805 int intno
= env
->exception_index
;
3809 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3813 if (intno
< 0 || intno
>= 0x180)
3815 else if (intno
>= 0x100)
3816 name
= "Trap Instruction";
3817 else if (intno
>= 0xc0)
3818 name
= "Window Fill";
3819 else if (intno
>= 0x80)
3820 name
= "Window Spill";
3822 name
= excp_names
[intno
];
3827 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
3828 " SP=%016" PRIx64
"\n",
3831 env
->npc
, env
->regwptr
[6]);
3832 log_cpu_state(env
, 0);
3839 ptr
= (uint8_t *)env
->pc
;
3840 for(i
= 0; i
< 16; i
++) {
3841 qemu_log(" %02x", ldub(ptr
+ i
));
3849 #if !defined(CONFIG_USER_ONLY)
3850 if (env
->tl
>= env
->maxtl
) {
3851 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
3852 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
3856 if (env
->tl
< env
->maxtl
- 1) {
3859 env
->pstate
|= PS_RED
;
3860 if (env
->tl
< env
->maxtl
)
3863 tsptr
= cpu_tsptr(env
);
3865 tsptr
->tstate
= (get_ccr() << 32) |
3866 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
3868 tsptr
->tpc
= env
->pc
;
3869 tsptr
->tnpc
= env
->npc
;
3874 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
3878 case TT_TMISS
... TT_TMISS
+ 3:
3879 case TT_DMISS
... TT_DMISS
+ 3:
3880 case TT_DPROT
... TT_DPROT
+ 3:
3881 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
3884 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
3888 if (intno
== TT_CLRWIN
) {
3889 set_cwp(cwp_dec(env
->cwp
- 1));
3890 } else if ((intno
& 0x1c0) == TT_SPILL
) {
3891 set_cwp(cwp_dec(env
->cwp
- env
->cansave
- 2));
3892 } else if ((intno
& 0x1c0) == TT_FILL
) {
3893 set_cwp(cwp_inc(env
->cwp
+ 1));
3895 env
->tbr
&= ~0x7fffULL
;
3896 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
3898 env
->npc
= env
->pc
+ 4;
3899 env
->exception_index
= -1;
3903 static const char * const excp_names
[0x80] = {
3904 [TT_TFAULT
] = "Instruction Access Fault",
3905 [TT_ILL_INSN
] = "Illegal Instruction",
3906 [TT_PRIV_INSN
] = "Privileged Instruction",
3907 [TT_NFPU_INSN
] = "FPU Disabled",
3908 [TT_WIN_OVF
] = "Window Overflow",
3909 [TT_WIN_UNF
] = "Window Underflow",
3910 [TT_UNALIGNED
] = "Unaligned Memory Access",
3911 [TT_FP_EXCP
] = "FPU Exception",
3912 [TT_DFAULT
] = "Data Access Fault",
3913 [TT_TOVF
] = "Tag Overflow",
3914 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3915 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3916 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3917 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3918 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3919 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3920 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3921 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3922 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3923 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3924 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3925 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3926 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3927 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3928 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3929 [TT_TOVF
] = "Tag Overflow",
3930 [TT_CODE_ACCESS
] = "Instruction Access Error",
3931 [TT_DATA_ACCESS
] = "Data Access Error",
3932 [TT_DIV_ZERO
] = "Division By Zero",
3933 [TT_NCP_INSN
] = "Coprocessor Disabled",
3937 void do_interrupt(CPUState
*env
)
3939 int cwp
, intno
= env
->exception_index
;
3942 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3946 if (intno
< 0 || intno
>= 0x100)
3948 else if (intno
>= 0x80)
3949 name
= "Trap Instruction";
3951 name
= excp_names
[intno
];
3956 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
3959 env
->npc
, env
->regwptr
[6]);
3960 log_cpu_state(env
, 0);
3967 ptr
= (uint8_t *)env
->pc
;
3968 for(i
= 0; i
< 16; i
++) {
3969 qemu_log(" %02x", ldub(ptr
+ i
));
3977 #if !defined(CONFIG_USER_ONLY)
3978 if (env
->psret
== 0) {
3979 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
3980 env
->exception_index
);
3985 cwp
= cwp_dec(env
->cwp
- 1);
3987 env
->regwptr
[9] = env
->pc
;
3988 env
->regwptr
[10] = env
->npc
;
3989 env
->psrps
= env
->psrs
;
3991 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
3993 env
->npc
= env
->pc
+ 4;
3994 env
->exception_index
= -1;
3998 #if !defined(CONFIG_USER_ONLY)
4000 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4003 #define MMUSUFFIX _mmu
4004 #define ALIGNED_ONLY
4007 #include "softmmu_template.h"
4010 #include "softmmu_template.h"
4013 #include "softmmu_template.h"
4016 #include "softmmu_template.h"
4018 /* XXX: make it generic ? */
4019 static void cpu_restore_state2(void *retaddr
)
4021 TranslationBlock
*tb
;
4025 /* now we have a real cpu fault */
4026 pc
= (unsigned long)retaddr
;
4027 tb
= tb_find_pc(pc
);
4029 /* the PC is inside the translated code. It means that we have
4030 a virtual CPU fault */
4031 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
4036 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4039 #ifdef DEBUG_UNALIGNED
4040 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
4041 "\n", addr
, env
->pc
);
4043 cpu_restore_state2(retaddr
);
4044 raise_exception(TT_UNALIGNED
);
4047 /* try to fill the TLB and return an exception if error. If retaddr is
4048 NULL, it means that the function was called in C code (i.e. not
4049 from generated code or from helper.c) */
4050 /* XXX: fix it to restore all registers */
4051 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
4054 CPUState
*saved_env
;
4056 /* XXX: hack to restore env in all cases, even if not called from
4059 env
= cpu_single_env
;
4061 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
4063 cpu_restore_state2(retaddr
);
4069 #endif /* !CONFIG_USER_ONLY */
4071 #ifndef TARGET_SPARC64
4072 #if !defined(CONFIG_USER_ONLY)
4073 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
4074 int is_asi
, int size
)
4076 CPUState
*saved_env
;
4079 /* XXX: hack to restore env in all cases, even if not called from
4082 env
= cpu_single_env
;
4083 #ifdef DEBUG_UNASSIGNED
4085 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4086 " asi 0x%02x from " TARGET_FMT_lx
"\n",
4087 is_exec
? "exec" : is_write
? "write" : "read", size
,
4088 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
4090 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4091 " from " TARGET_FMT_lx
"\n",
4092 is_exec
? "exec" : is_write
? "write" : "read", size
,
4093 size
== 1 ? "" : "s", addr
, env
->pc
);
4095 /* Don't overwrite translation and access faults */
4096 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
4097 if ((fault_type
> 4) || (fault_type
== 0)) {
4098 env
->mmuregs
[3] = 0; /* Fault status register */
4100 env
->mmuregs
[3] |= 1 << 16;
4102 env
->mmuregs
[3] |= 1 << 5;
4104 env
->mmuregs
[3] |= 1 << 6;
4106 env
->mmuregs
[3] |= 1 << 7;
4107 env
->mmuregs
[3] |= (5 << 2) | 2;
4108 /* SuperSPARC will never place instruction fault addresses in the FAR */
4110 env
->mmuregs
[4] = addr
; /* Fault address register */
4113 /* overflow (same type fault was not read before another fault) */
4114 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
4115 env
->mmuregs
[3] |= 1;
4118 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
4120 raise_exception(TT_CODE_ACCESS
);
4122 raise_exception(TT_DATA_ACCESS
);
4125 /* flush neverland mappings created during no-fault mode,
4126 so the sequential MMU faults report proper fault types */
4127 if (env
->mmuregs
[0] & MMU_NF
) {
4135 #if defined(CONFIG_USER_ONLY)
4136 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
4137 int is_asi
, int size
)
4139 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
4140 int is_asi
, int size
)
4143 CPUState
*saved_env
;
4145 /* XXX: hack to restore env in all cases, even if not called from
4148 env
= cpu_single_env
;
4150 #ifdef DEBUG_UNASSIGNED
4151 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
4152 "\n", addr
, env
->pc
);
4156 raise_exception(TT_CODE_ACCESS
);
4158 raise_exception(TT_DATA_ACCESS
);
4165 #ifdef TARGET_SPARC64
4166 void helper_tick_set_count(void *opaque
, uint64_t count
)
4168 #if !defined(CONFIG_USER_ONLY)
4169 cpu_tick_set_count(opaque
, count
);
4173 uint64_t helper_tick_get_count(void *opaque
)
4175 #if !defined(CONFIG_USER_ONLY)
4176 return cpu_tick_get_count(opaque
);
4182 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
4184 #if !defined(CONFIG_USER_ONLY)
4185 cpu_tick_set_limit(opaque
, limit
);