]>
git.proxmox.com Git - qemu.git/blob - target-sparc/op_helper.c
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 /* returns true if access using this ASI is to have address translated by MMU
251 otherwise access is to raw physical address */
252 static inline int is_translating_asi(int asi
)
254 #ifdef TARGET_SPARC64
255 /* Ultrasparc IIi translating asi
256 - note this list is defined by cpu implementation
271 /* TODO: check sparc32 bits */
276 static inline target_ulong
asi_address_mask(CPUState
*env1
,
277 int asi
, target_ulong addr
)
279 if (is_translating_asi(asi
)) {
280 return address_mask(env
, addr
);
286 static void raise_exception(int tt
)
288 env
->exception_index
= tt
;
292 void HELPER(raise_exception
)(int tt
)
297 void helper_check_align(target_ulong addr
, uint32_t align
)
300 #ifdef DEBUG_UNALIGNED
301 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
302 "\n", addr
, env
->pc
);
304 raise_exception(TT_UNALIGNED
);
308 #define F_HELPER(name, p) void helper_f##name##p(void)
310 #define F_BINOP(name) \
311 float32 helper_f ## name ## s (float32 src1, float32 src2) \
313 return float32_ ## name (src1, src2, &env->fp_status); \
317 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
321 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
330 void helper_fsmuld(float32 src1
, float32 src2
)
332 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
333 float32_to_float64(src2
, &env
->fp_status
),
337 void helper_fdmulq(void)
339 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
340 float64_to_float128(DT1
, &env
->fp_status
),
344 float32
helper_fnegs(float32 src
)
346 return float32_chs(src
);
349 #ifdef TARGET_SPARC64
352 DT0
= float64_chs(DT1
);
357 QT0
= float128_chs(QT1
);
361 /* Integer to float conversion. */
362 float32
helper_fitos(int32_t src
)
364 return int32_to_float32(src
, &env
->fp_status
);
367 void helper_fitod(int32_t src
)
369 DT0
= int32_to_float64(src
, &env
->fp_status
);
372 void helper_fitoq(int32_t src
)
374 QT0
= int32_to_float128(src
, &env
->fp_status
);
377 #ifdef TARGET_SPARC64
378 float32
helper_fxtos(void)
380 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
385 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
390 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
395 /* floating point conversion */
396 float32
helper_fdtos(void)
398 return float64_to_float32(DT1
, &env
->fp_status
);
401 void helper_fstod(float32 src
)
403 DT0
= float32_to_float64(src
, &env
->fp_status
);
406 float32
helper_fqtos(void)
408 return float128_to_float32(QT1
, &env
->fp_status
);
411 void helper_fstoq(float32 src
)
413 QT0
= float32_to_float128(src
, &env
->fp_status
);
416 void helper_fqtod(void)
418 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
421 void helper_fdtoq(void)
423 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
426 /* Float to integer conversion. */
427 int32_t helper_fstoi(float32 src
)
429 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
432 int32_t helper_fdtoi(void)
434 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
437 int32_t helper_fqtoi(void)
439 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
442 #ifdef TARGET_SPARC64
443 void helper_fstox(float32 src
)
445 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
448 void helper_fdtox(void)
450 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
453 void helper_fqtox(void)
455 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
458 void helper_faligndata(void)
462 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
463 /* on many architectures a shift of 64 does nothing */
464 if ((env
->gsr
& 7) != 0) {
465 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
467 *((uint64_t *)&DT0
) = tmp
;
470 #ifdef HOST_WORDS_BIGENDIAN
471 #define VIS_B64(n) b[7 - (n)]
472 #define VIS_W64(n) w[3 - (n)]
473 #define VIS_SW64(n) sw[3 - (n)]
474 #define VIS_L64(n) l[1 - (n)]
475 #define VIS_B32(n) b[3 - (n)]
476 #define VIS_W32(n) w[1 - (n)]
478 #define VIS_B64(n) b[n]
479 #define VIS_W64(n) w[n]
480 #define VIS_SW64(n) sw[n]
481 #define VIS_L64(n) l[n]
482 #define VIS_B32(n) b[n]
483 #define VIS_W32(n) w[n]
501 void helper_fpmerge(void)
508 // Reverse calculation order to handle overlap
509 d
.VIS_B64(7) = s
.VIS_B64(3);
510 d
.VIS_B64(6) = d
.VIS_B64(3);
511 d
.VIS_B64(5) = s
.VIS_B64(2);
512 d
.VIS_B64(4) = d
.VIS_B64(2);
513 d
.VIS_B64(3) = s
.VIS_B64(1);
514 d
.VIS_B64(2) = d
.VIS_B64(1);
515 d
.VIS_B64(1) = s
.VIS_B64(0);
516 //d.VIS_B64(0) = d.VIS_B64(0);
521 void helper_fmul8x16(void)
530 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
531 if ((tmp & 0xff) > 0x7f) \
533 d.VIS_W64(r) = tmp >> 8;
544 void helper_fmul8x16al(void)
553 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
554 if ((tmp & 0xff) > 0x7f) \
556 d.VIS_W64(r) = tmp >> 8;
567 void helper_fmul8x16au(void)
576 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
577 if ((tmp & 0xff) > 0x7f) \
579 d.VIS_W64(r) = tmp >> 8;
590 void helper_fmul8sux16(void)
599 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
600 if ((tmp & 0xff) > 0x7f) \
602 d.VIS_W64(r) = tmp >> 8;
613 void helper_fmul8ulx16(void)
622 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
623 if ((tmp & 0xff) > 0x7f) \
625 d.VIS_W64(r) = tmp >> 8;
636 void helper_fmuld8sux16(void)
645 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
646 if ((tmp & 0xff) > 0x7f) \
650 // Reverse calculation order to handle overlap
658 void helper_fmuld8ulx16(void)
667 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
668 if ((tmp & 0xff) > 0x7f) \
672 // Reverse calculation order to handle overlap
680 void helper_fexpand(void)
685 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
687 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
688 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
689 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
690 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
695 #define VIS_HELPER(name, F) \
696 void name##16(void) \
703 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
704 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
705 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
706 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
711 uint32_t name##16s(uint32_t src1, uint32_t src2) \
718 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
719 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
724 void name##32(void) \
731 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
732 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
737 uint32_t name##32s(uint32_t src1, uint32_t src2) \
749 #define FADD(a, b) ((a) + (b))
750 #define FSUB(a, b) ((a) - (b))
751 VIS_HELPER(helper_fpadd
, FADD
)
752 VIS_HELPER(helper_fpsub
, FSUB
)
754 #define VIS_CMPHELPER(name, F) \
755 void name##16(void) \
762 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
763 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
764 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
765 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
770 void name##32(void) \
777 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
778 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
783 #define FCMPGT(a, b) ((a) > (b))
784 #define FCMPEQ(a, b) ((a) == (b))
785 #define FCMPLE(a, b) ((a) <= (b))
786 #define FCMPNE(a, b) ((a) != (b))
788 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
789 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
790 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
791 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
794 void helper_check_ieee_exceptions(void)
798 status
= get_float_exception_flags(&env
->fp_status
);
800 /* Copy IEEE 754 flags into FSR */
801 if (status
& float_flag_invalid
)
803 if (status
& float_flag_overflow
)
805 if (status
& float_flag_underflow
)
807 if (status
& float_flag_divbyzero
)
809 if (status
& float_flag_inexact
)
812 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
813 /* Unmasked exception, generate a trap */
814 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
815 raise_exception(TT_FP_EXCP
);
817 /* Accumulate exceptions */
818 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
823 void helper_clear_float_exceptions(void)
825 set_float_exception_flags(0, &env
->fp_status
);
828 float32
helper_fabss(float32 src
)
830 return float32_abs(src
);
833 #ifdef TARGET_SPARC64
834 void helper_fabsd(void)
836 DT0
= float64_abs(DT1
);
839 void helper_fabsq(void)
841 QT0
= float128_abs(QT1
);
845 float32
helper_fsqrts(float32 src
)
847 return float32_sqrt(src
, &env
->fp_status
);
850 void helper_fsqrtd(void)
852 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
855 void helper_fsqrtq(void)
857 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
860 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
861 void glue(helper_, name) (void) \
863 target_ulong new_fsr; \
865 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
866 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
867 case float_relation_unordered: \
868 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
869 if ((env->fsr & FSR_NVM) || TRAP) { \
870 env->fsr |= new_fsr; \
871 env->fsr |= FSR_NVC; \
872 env->fsr |= FSR_FTT_IEEE_EXCP; \
873 raise_exception(TT_FP_EXCP); \
875 env->fsr |= FSR_NVA; \
878 case float_relation_less: \
879 new_fsr = FSR_FCC0 << FS; \
881 case float_relation_greater: \
882 new_fsr = FSR_FCC1 << FS; \
888 env->fsr |= new_fsr; \
890 #define GEN_FCMPS(name, size, FS, TRAP) \
891 void glue(helper_, name)(float32 src1, float32 src2) \
893 target_ulong new_fsr; \
895 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
896 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
897 case float_relation_unordered: \
898 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
899 if ((env->fsr & FSR_NVM) || TRAP) { \
900 env->fsr |= new_fsr; \
901 env->fsr |= FSR_NVC; \
902 env->fsr |= FSR_FTT_IEEE_EXCP; \
903 raise_exception(TT_FP_EXCP); \
905 env->fsr |= FSR_NVA; \
908 case float_relation_less: \
909 new_fsr = FSR_FCC0 << FS; \
911 case float_relation_greater: \
912 new_fsr = FSR_FCC1 << FS; \
918 env->fsr |= new_fsr; \
921 GEN_FCMPS(fcmps
, float32
, 0, 0);
922 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
924 GEN_FCMPS(fcmpes
, float32
, 0, 1);
925 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
927 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
928 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
930 static uint32_t compute_all_flags(void)
932 return env
->psr
& PSR_ICC
;
935 static uint32_t compute_C_flags(void)
937 return env
->psr
& PSR_CARRY
;
940 static inline uint32_t get_NZ_icc(int32_t dst
)
946 } else if (dst
< 0) {
952 #ifdef TARGET_SPARC64
953 static uint32_t compute_all_flags_xcc(void)
955 return env
->xcc
& PSR_ICC
;
958 static uint32_t compute_C_flags_xcc(void)
960 return env
->xcc
& PSR_CARRY
;
963 static inline uint32_t get_NZ_xcc(target_long dst
)
969 } else if (dst
< 0) {
976 static inline uint32_t get_V_div_icc(target_ulong src2
)
986 static uint32_t compute_all_div(void)
990 ret
= get_NZ_icc(CC_DST
);
991 ret
|= get_V_div_icc(CC_SRC2
);
995 static uint32_t compute_C_div(void)
1000 static inline uint32_t get_C_add_icc(uint32_t dst
, uint32_t src1
)
1010 static inline uint32_t get_C_addx_icc(uint32_t dst
, uint32_t src1
,
1015 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1U << 31)) {
1021 static inline uint32_t get_V_add_icc(uint32_t dst
, uint32_t src1
,
1026 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1U << 31)) {
1032 #ifdef TARGET_SPARC64
1033 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
1043 static inline uint32_t get_C_addx_xcc(target_ulong dst
, target_ulong src1
,
1048 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1ULL << 63)) {
1054 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
1059 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63)) {
1065 static uint32_t compute_all_add_xcc(void)
1069 ret
= get_NZ_xcc(CC_DST
);
1070 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1071 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1075 static uint32_t compute_C_add_xcc(void)
1077 return get_C_add_xcc(CC_DST
, CC_SRC
);
1081 static uint32_t compute_all_add(void)
1085 ret
= get_NZ_icc(CC_DST
);
1086 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1087 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1091 static uint32_t compute_C_add(void)
1093 return get_C_add_icc(CC_DST
, CC_SRC
);
1096 #ifdef TARGET_SPARC64
1097 static uint32_t compute_all_addx_xcc(void)
1101 ret
= get_NZ_xcc(CC_DST
);
1102 ret
|= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1103 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1107 static uint32_t compute_C_addx_xcc(void)
1111 ret
= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1116 static uint32_t compute_all_addx(void)
1120 ret
= get_NZ_icc(CC_DST
);
1121 ret
|= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1122 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1126 static uint32_t compute_C_addx(void)
1130 ret
= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1134 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1138 if ((src1
| src2
) & 0x3) {
1144 static uint32_t compute_all_tadd(void)
1148 ret
= get_NZ_icc(CC_DST
);
1149 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1150 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1151 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1155 static uint32_t compute_all_taddtv(void)
1159 ret
= get_NZ_icc(CC_DST
);
1160 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1164 static inline uint32_t get_C_sub_icc(uint32_t src1
, uint32_t src2
)
1174 static inline uint32_t get_C_subx_icc(uint32_t dst
, uint32_t src1
,
1179 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1U << 31)) {
1185 static inline uint32_t get_V_sub_icc(uint32_t dst
, uint32_t src1
,
1190 if (((src1
^ src2
) & (src1
^ dst
)) & (1U << 31)) {
1197 #ifdef TARGET_SPARC64
1198 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1208 static inline uint32_t get_C_subx_xcc(target_ulong dst
, target_ulong src1
,
1213 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1ULL << 63)) {
1219 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1224 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63)) {
1230 static uint32_t compute_all_sub_xcc(void)
1234 ret
= get_NZ_xcc(CC_DST
);
1235 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1236 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1240 static uint32_t compute_C_sub_xcc(void)
1242 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1246 static uint32_t compute_all_sub(void)
1250 ret
= get_NZ_icc(CC_DST
);
1251 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1252 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1256 static uint32_t compute_C_sub(void)
1258 return get_C_sub_icc(CC_SRC
, CC_SRC2
);
1261 #ifdef TARGET_SPARC64
1262 static uint32_t compute_all_subx_xcc(void)
1266 ret
= get_NZ_xcc(CC_DST
);
1267 ret
|= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1268 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1272 static uint32_t compute_C_subx_xcc(void)
1276 ret
= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1281 static uint32_t compute_all_subx(void)
1285 ret
= get_NZ_icc(CC_DST
);
1286 ret
|= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1287 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1291 static uint32_t compute_C_subx(void)
1295 ret
= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1299 static uint32_t compute_all_tsub(void)
1303 ret
= get_NZ_icc(CC_DST
);
1304 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1305 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1306 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1310 static uint32_t compute_all_tsubtv(void)
1314 ret
= get_NZ_icc(CC_DST
);
1315 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1319 static uint32_t compute_all_logic(void)
1321 return get_NZ_icc(CC_DST
);
1324 static uint32_t compute_C_logic(void)
1329 #ifdef TARGET_SPARC64
1330 static uint32_t compute_all_logic_xcc(void)
1332 return get_NZ_xcc(CC_DST
);
1336 typedef struct CCTable
{
1337 uint32_t (*compute_all
)(void); /* return all the flags */
1338 uint32_t (*compute_c
)(void); /* return the C flag */
1341 static const CCTable icc_table
[CC_OP_NB
] = {
1342 /* CC_OP_DYNAMIC should never happen */
1343 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1344 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1345 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1346 [CC_OP_ADDX
] = { compute_all_addx
, compute_C_addx
},
1347 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_add
},
1348 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_add
},
1349 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1350 [CC_OP_SUBX
] = { compute_all_subx
, compute_C_subx
},
1351 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_sub
},
1352 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_sub
},
1353 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1356 #ifdef TARGET_SPARC64
1357 static const CCTable xcc_table
[CC_OP_NB
] = {
1358 /* CC_OP_DYNAMIC should never happen */
1359 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1360 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1361 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1362 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1363 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1364 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1365 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1366 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1367 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1368 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1369 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1373 void helper_compute_psr(void)
1377 new_psr
= icc_table
[CC_OP
].compute_all();
1379 #ifdef TARGET_SPARC64
1380 new_psr
= xcc_table
[CC_OP
].compute_all();
1383 CC_OP
= CC_OP_FLAGS
;
1386 uint32_t helper_compute_C_icc(void)
1390 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1394 static inline void memcpy32(target_ulong
*dst
, const target_ulong
*src
)
1406 static void set_cwp(int new_cwp
)
1408 /* put the modified wrap registers at their proper location */
1409 if (env
->cwp
== env
->nwindows
- 1) {
1410 memcpy32(env
->regbase
, env
->regbase
+ env
->nwindows
* 16);
1414 /* put the wrap registers at their temporary location */
1415 if (new_cwp
== env
->nwindows
- 1) {
1416 memcpy32(env
->regbase
+ env
->nwindows
* 16, env
->regbase
);
1418 env
->regwptr
= env
->regbase
+ (new_cwp
* 16);
1421 void cpu_set_cwp(CPUState
*env1
, int new_cwp
)
1423 CPUState
*saved_env
;
1431 static target_ulong
get_psr(void)
1433 helper_compute_psr();
1435 #if !defined (TARGET_SPARC64)
1436 return env
->version
| (env
->psr
& PSR_ICC
) |
1437 (env
->psref
? PSR_EF
: 0) |
1438 (env
->psrpil
<< 8) |
1439 (env
->psrs
? PSR_S
: 0) |
1440 (env
->psrps
? PSR_PS
: 0) |
1441 (env
->psret
? PSR_ET
: 0) | env
->cwp
;
1443 return env
->psr
& PSR_ICC
;
1447 target_ulong
cpu_get_psr(CPUState
*env1
)
1449 CPUState
*saved_env
;
1459 static void put_psr(target_ulong val
)
1461 env
->psr
= val
& PSR_ICC
;
1462 #if !defined (TARGET_SPARC64)
1463 env
->psref
= (val
& PSR_EF
)? 1 : 0;
1464 env
->psrpil
= (val
& PSR_PIL
) >> 8;
1466 #if ((!defined (TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
1467 cpu_check_irqs(env
);
1469 #if !defined (TARGET_SPARC64)
1470 env
->psrs
= (val
& PSR_S
)? 1 : 0;
1471 env
->psrps
= (val
& PSR_PS
)? 1 : 0;
1472 env
->psret
= (val
& PSR_ET
)? 1 : 0;
1473 set_cwp(val
& PSR_CWP
);
1475 env
->cc_op
= CC_OP_FLAGS
;
1478 void cpu_put_psr(CPUState
*env1
, target_ulong val
)
1480 CPUState
*saved_env
;
1488 static int cwp_inc(int cwp
)
1490 if (unlikely(cwp
>= env
->nwindows
)) {
1491 cwp
-= env
->nwindows
;
1496 int cpu_cwp_inc(CPUState
*env1
, int cwp
)
1498 CPUState
*saved_env
;
1508 static int cwp_dec(int cwp
)
1510 if (unlikely(cwp
< 0)) {
1511 cwp
+= env
->nwindows
;
1516 int cpu_cwp_dec(CPUState
*env1
, int cwp
)
1518 CPUState
*saved_env
;
1528 #ifdef TARGET_SPARC64
1529 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1530 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1531 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1533 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1534 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1535 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1537 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1538 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1539 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1541 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1542 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1543 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1545 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1546 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1547 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1549 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1550 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1551 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1555 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1557 static void dump_mxcc(CPUState
*env
)
1559 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1561 env
->mxccdata
[0], env
->mxccdata
[1],
1562 env
->mxccdata
[2], env
->mxccdata
[3]);
1563 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1565 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1567 env
->mxccregs
[0], env
->mxccregs
[1],
1568 env
->mxccregs
[2], env
->mxccregs
[3],
1569 env
->mxccregs
[4], env
->mxccregs
[5],
1570 env
->mxccregs
[6], env
->mxccregs
[7]);
1574 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1575 && defined(DEBUG_ASI)
1576 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1582 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1583 addr
, asi
, r1
& 0xff);
1586 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1587 addr
, asi
, r1
& 0xffff);
1590 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1591 addr
, asi
, r1
& 0xffffffff);
1594 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1601 #ifndef TARGET_SPARC64
1602 #ifndef CONFIG_USER_ONLY
1603 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1606 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1607 uint32_t last_addr
= addr
;
1610 helper_check_align(addr
, size
- 1);
1612 case 2: /* SuperSparc MXCC registers */
1614 case 0x01c00a00: /* MXCC control register */
1616 ret
= env
->mxccregs
[3];
1618 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1621 case 0x01c00a04: /* MXCC control register */
1623 ret
= env
->mxccregs
[3];
1625 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1628 case 0x01c00c00: /* Module reset register */
1630 ret
= env
->mxccregs
[5];
1631 // should we do something here?
1633 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1636 case 0x01c00f00: /* MBus port address register */
1638 ret
= env
->mxccregs
[7];
1640 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1644 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1648 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1649 "addr = %08x -> ret = %" PRIx64
","
1650 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1655 case 3: /* MMU probe */
1659 mmulev
= (addr
>> 8) & 15;
1663 ret
= mmu_probe(env
, addr
, mmulev
);
1664 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1668 case 4: /* read MMU regs */
1670 int reg
= (addr
>> 8) & 0x1f;
1672 ret
= env
->mmuregs
[reg
];
1673 if (reg
== 3) /* Fault status cleared on read */
1674 env
->mmuregs
[3] = 0;
1675 else if (reg
== 0x13) /* Fault status read */
1676 ret
= env
->mmuregs
[3];
1677 else if (reg
== 0x14) /* Fault address read */
1678 ret
= env
->mmuregs
[4];
1679 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1682 case 5: // Turbosparc ITLB Diagnostic
1683 case 6: // Turbosparc DTLB Diagnostic
1684 case 7: // Turbosparc IOTLB Diagnostic
1686 case 9: /* Supervisor code access */
1689 ret
= ldub_code(addr
);
1692 ret
= lduw_code(addr
);
1696 ret
= ldl_code(addr
);
1699 ret
= ldq_code(addr
);
1703 case 0xa: /* User data access */
1706 ret
= ldub_user(addr
);
1709 ret
= lduw_user(addr
);
1713 ret
= ldl_user(addr
);
1716 ret
= ldq_user(addr
);
1720 case 0xb: /* Supervisor data access */
1723 ret
= ldub_kernel(addr
);
1726 ret
= lduw_kernel(addr
);
1730 ret
= ldl_kernel(addr
);
1733 ret
= ldq_kernel(addr
);
1737 case 0xc: /* I-cache tag */
1738 case 0xd: /* I-cache data */
1739 case 0xe: /* D-cache tag */
1740 case 0xf: /* D-cache data */
1742 case 0x20: /* MMU passthrough */
1745 ret
= ldub_phys(addr
);
1748 ret
= lduw_phys(addr
);
1752 ret
= ldl_phys(addr
);
1755 ret
= ldq_phys(addr
);
1759 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1762 ret
= ldub_phys((target_phys_addr_t
)addr
1763 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1766 ret
= lduw_phys((target_phys_addr_t
)addr
1767 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1771 ret
= ldl_phys((target_phys_addr_t
)addr
1772 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1775 ret
= ldq_phys((target_phys_addr_t
)addr
1776 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1780 case 0x30: // Turbosparc secondary cache diagnostic
1781 case 0x31: // Turbosparc RAM snoop
1782 case 0x32: // Turbosparc page table descriptor diagnostic
1783 case 0x39: /* data cache diagnostic register */
1784 case 0x4c: /* SuperSPARC MMU Breakpoint Action register */
1787 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1789 int reg
= (addr
>> 8) & 3;
1792 case 0: /* Breakpoint Value (Addr) */
1793 ret
= env
->mmubpregs
[reg
];
1795 case 1: /* Breakpoint Mask */
1796 ret
= env
->mmubpregs
[reg
];
1798 case 2: /* Breakpoint Control */
1799 ret
= env
->mmubpregs
[reg
];
1801 case 3: /* Breakpoint Status */
1802 ret
= env
->mmubpregs
[reg
];
1803 env
->mmubpregs
[reg
] = 0ULL;
1806 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1810 case 8: /* User code access, XXX */
1812 do_unassigned_access(addr
, 0, 0, asi
, size
);
1822 ret
= (int16_t) ret
;
1825 ret
= (int32_t) ret
;
1832 dump_asi("read ", last_addr
, asi
, size
, ret
);
1837 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1839 helper_check_align(addr
, size
- 1);
1841 case 2: /* SuperSparc MXCC registers */
1843 case 0x01c00000: /* MXCC stream data register 0 */
1845 env
->mxccdata
[0] = val
;
1847 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1850 case 0x01c00008: /* MXCC stream data register 1 */
1852 env
->mxccdata
[1] = val
;
1854 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1857 case 0x01c00010: /* MXCC stream data register 2 */
1859 env
->mxccdata
[2] = val
;
1861 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1864 case 0x01c00018: /* MXCC stream data register 3 */
1866 env
->mxccdata
[3] = val
;
1868 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1871 case 0x01c00100: /* MXCC stream source */
1873 env
->mxccregs
[0] = val
;
1875 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1877 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1879 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1881 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1883 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1886 case 0x01c00200: /* MXCC stream destination */
1888 env
->mxccregs
[1] = val
;
1890 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1892 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1894 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1896 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1898 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1901 case 0x01c00a00: /* MXCC control register */
1903 env
->mxccregs
[3] = val
;
1905 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1908 case 0x01c00a04: /* MXCC control register */
1910 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1913 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1916 case 0x01c00e00: /* MXCC error register */
1917 // writing a 1 bit clears the error
1919 env
->mxccregs
[6] &= ~val
;
1921 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1924 case 0x01c00f00: /* MBus port address register */
1926 env
->mxccregs
[7] = val
;
1928 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1932 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1936 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1937 asi
, size
, addr
, val
);
1942 case 3: /* MMU flush */
1946 mmulev
= (addr
>> 8) & 15;
1947 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1949 case 0: // flush page
1950 tlb_flush_page(env
, addr
& 0xfffff000);
1952 case 1: // flush segment (256k)
1953 case 2: // flush region (16M)
1954 case 3: // flush context (4G)
1955 case 4: // flush entire
1966 case 4: /* write MMU regs */
1968 int reg
= (addr
>> 8) & 0x1f;
1971 oldreg
= env
->mmuregs
[reg
];
1973 case 0: // Control Register
1974 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1976 // Mappings generated during no-fault mode or MMU
1977 // disabled mode are invalid in normal mode
1978 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1979 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1982 case 1: // Context Table Pointer Register
1983 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1985 case 2: // Context Register
1986 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1987 if (oldreg
!= env
->mmuregs
[reg
]) {
1988 /* we flush when the MMU context changes because
1989 QEMU has no MMU context support */
1993 case 3: // Synchronous Fault Status Register with Clear
1994 case 4: // Synchronous Fault Address Register
1996 case 0x10: // TLB Replacement Control Register
1997 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1999 case 0x13: // Synchronous Fault Status Register with Read and Clear
2000 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
2002 case 0x14: // Synchronous Fault Address Register
2003 env
->mmuregs
[4] = val
;
2006 env
->mmuregs
[reg
] = val
;
2009 if (oldreg
!= env
->mmuregs
[reg
]) {
2010 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
2011 reg
, oldreg
, env
->mmuregs
[reg
]);
2018 case 5: // Turbosparc ITLB Diagnostic
2019 case 6: // Turbosparc DTLB Diagnostic
2020 case 7: // Turbosparc IOTLB Diagnostic
2022 case 0xa: /* User data access */
2025 stb_user(addr
, val
);
2028 stw_user(addr
, val
);
2032 stl_user(addr
, val
);
2035 stq_user(addr
, val
);
2039 case 0xb: /* Supervisor data access */
2042 stb_kernel(addr
, val
);
2045 stw_kernel(addr
, val
);
2049 stl_kernel(addr
, val
);
2052 stq_kernel(addr
, val
);
2056 case 0xc: /* I-cache tag */
2057 case 0xd: /* I-cache data */
2058 case 0xe: /* D-cache tag */
2059 case 0xf: /* D-cache data */
2060 case 0x10: /* I/D-cache flush page */
2061 case 0x11: /* I/D-cache flush segment */
2062 case 0x12: /* I/D-cache flush region */
2063 case 0x13: /* I/D-cache flush context */
2064 case 0x14: /* I/D-cache flush user */
2066 case 0x17: /* Block copy, sta access */
2072 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
2074 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
2075 temp
= ldl_kernel(src
);
2076 stl_kernel(dst
, temp
);
2080 case 0x1f: /* Block fill, stda access */
2083 // fill 32 bytes with val
2085 uint32_t dst
= addr
& 7;
2087 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
2088 stq_kernel(dst
, val
);
2091 case 0x20: /* MMU passthrough */
2095 stb_phys(addr
, val
);
2098 stw_phys(addr
, val
);
2102 stl_phys(addr
, val
);
2105 stq_phys(addr
, val
);
2110 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
2114 stb_phys((target_phys_addr_t
)addr
2115 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2118 stw_phys((target_phys_addr_t
)addr
2119 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2123 stl_phys((target_phys_addr_t
)addr
2124 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2127 stq_phys((target_phys_addr_t
)addr
2128 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2133 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
2134 case 0x31: // store buffer data, Ross RT620 I-cache flush or
2135 // Turbosparc snoop RAM
2136 case 0x32: // store buffer control or Turbosparc page table
2137 // descriptor diagnostic
2138 case 0x36: /* I-cache flash clear */
2139 case 0x37: /* D-cache flash clear */
2140 case 0x4c: /* breakpoint action */
2142 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
2144 int reg
= (addr
>> 8) & 3;
2147 case 0: /* Breakpoint Value (Addr) */
2148 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2150 case 1: /* Breakpoint Mask */
2151 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2153 case 2: /* Breakpoint Control */
2154 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
2156 case 3: /* Breakpoint Status */
2157 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
2160 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
2164 case 8: /* User code access, XXX */
2165 case 9: /* Supervisor code access, XXX */
2167 do_unassigned_access(addr
, 1, 0, asi
, size
);
2171 dump_asi("write", addr
, asi
, size
, val
);
2175 #endif /* CONFIG_USER_ONLY */
2176 #else /* TARGET_SPARC64 */
2178 #ifdef CONFIG_USER_ONLY
2179 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2182 #if defined(DEBUG_ASI)
2183 target_ulong last_addr
= addr
;
2187 raise_exception(TT_PRIV_ACT
);
2189 helper_check_align(addr
, size
- 1);
2190 addr
= asi_address_mask(env
, asi
, addr
);
2193 case 0x82: // Primary no-fault
2194 case 0x8a: // Primary no-fault LE
2195 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2197 dump_asi("read ", last_addr
, asi
, size
, ret
);
2202 case 0x80: // Primary
2203 case 0x88: // Primary LE
2207 ret
= ldub_raw(addr
);
2210 ret
= lduw_raw(addr
);
2213 ret
= ldl_raw(addr
);
2217 ret
= ldq_raw(addr
);
2222 case 0x83: // Secondary no-fault
2223 case 0x8b: // Secondary no-fault LE
2224 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2226 dump_asi("read ", last_addr
, asi
, size
, ret
);
2231 case 0x81: // Secondary
2232 case 0x89: // Secondary LE
2239 /* Convert from little endian */
2241 case 0x88: // Primary LE
2242 case 0x89: // Secondary LE
2243 case 0x8a: // Primary no-fault LE
2244 case 0x8b: // Secondary no-fault LE
2262 /* Convert to signed number */
2269 ret
= (int16_t) ret
;
2272 ret
= (int32_t) ret
;
2279 dump_asi("read ", last_addr
, asi
, size
, ret
);
2284 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2287 dump_asi("write", addr
, asi
, size
, val
);
2290 raise_exception(TT_PRIV_ACT
);
2292 helper_check_align(addr
, size
- 1);
2293 addr
= asi_address_mask(env
, asi
, addr
);
2295 /* Convert to little endian */
2297 case 0x88: // Primary LE
2298 case 0x89: // Secondary LE
2317 case 0x80: // Primary
2318 case 0x88: // Primary LE
2337 case 0x81: // Secondary
2338 case 0x89: // Secondary LE
2342 case 0x82: // Primary no-fault, RO
2343 case 0x83: // Secondary no-fault, RO
2344 case 0x8a: // Primary no-fault LE, RO
2345 case 0x8b: // Secondary no-fault LE, RO
2347 do_unassigned_access(addr
, 1, 0, 1, size
);
2352 #else /* CONFIG_USER_ONLY */
2354 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2357 #if defined(DEBUG_ASI)
2358 target_ulong last_addr
= addr
;
2363 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2364 || (cpu_has_hypervisor(env
)
2365 && asi
>= 0x30 && asi
< 0x80
2366 && !(env
->hpstate
& HS_PRIV
)))
2367 raise_exception(TT_PRIV_ACT
);
2369 helper_check_align(addr
, size
- 1);
2370 addr
= asi_address_mask(env
, asi
, addr
);
2373 case 0x82: // Primary no-fault
2374 case 0x8a: // Primary no-fault LE
2375 case 0x83: // Secondary no-fault
2376 case 0x8b: // Secondary no-fault LE
2378 /* secondary space access has lowest asi bit equal to 1 */
2379 int access_mmu_idx
= ( asi
& 1 ) ? MMU_KERNEL_IDX
2380 : MMU_KERNEL_SECONDARY_IDX
;
2382 if (cpu_get_phys_page_nofault(env
, addr
, access_mmu_idx
) == -1ULL) {
2384 dump_asi("read ", last_addr
, asi
, size
, ret
);
2390 case 0x10: // As if user primary
2391 case 0x11: // As if user secondary
2392 case 0x18: // As if user primary LE
2393 case 0x19: // As if user secondary LE
2394 case 0x80: // Primary
2395 case 0x81: // Secondary
2396 case 0x88: // Primary LE
2397 case 0x89: // Secondary LE
2398 case 0xe2: // UA2007 Primary block init
2399 case 0xe3: // UA2007 Secondary block init
2400 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2401 if (cpu_hypervisor_mode(env
)) {
2404 ret
= ldub_hypv(addr
);
2407 ret
= lduw_hypv(addr
);
2410 ret
= ldl_hypv(addr
);
2414 ret
= ldq_hypv(addr
);
2418 /* secondary space access has lowest asi bit equal to 1 */
2422 ret
= ldub_kernel_secondary(addr
);
2425 ret
= lduw_kernel_secondary(addr
);
2428 ret
= ldl_kernel_secondary(addr
);
2432 ret
= ldq_kernel_secondary(addr
);
2438 ret
= ldub_kernel(addr
);
2441 ret
= lduw_kernel(addr
);
2444 ret
= ldl_kernel(addr
);
2448 ret
= ldq_kernel(addr
);
2454 /* secondary space access has lowest asi bit equal to 1 */
2458 ret
= ldub_user_secondary(addr
);
2461 ret
= lduw_user_secondary(addr
);
2464 ret
= ldl_user_secondary(addr
);
2468 ret
= ldq_user_secondary(addr
);
2474 ret
= ldub_user(addr
);
2477 ret
= lduw_user(addr
);
2480 ret
= ldl_user(addr
);
2484 ret
= ldq_user(addr
);
2490 case 0x14: // Bypass
2491 case 0x15: // Bypass, non-cacheable
2492 case 0x1c: // Bypass LE
2493 case 0x1d: // Bypass, non-cacheable LE
2497 ret
= ldub_phys(addr
);
2500 ret
= lduw_phys(addr
);
2503 ret
= ldl_phys(addr
);
2507 ret
= ldq_phys(addr
);
2512 case 0x24: // Nucleus quad LDD 128 bit atomic
2513 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2514 // Only ldda allowed
2515 raise_exception(TT_ILL_INSN
);
2517 case 0x04: // Nucleus
2518 case 0x0c: // Nucleus Little Endian (LE)
2522 ret
= ldub_nucleus(addr
);
2525 ret
= lduw_nucleus(addr
);
2528 ret
= ldl_nucleus(addr
);
2532 ret
= ldq_nucleus(addr
);
2537 case 0x4a: // UPA config
2543 case 0x50: // I-MMU regs
2545 int reg
= (addr
>> 3) & 0xf;
2548 // I-TSB Tag Target register
2549 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2551 ret
= env
->immuregs
[reg
];
2556 case 0x51: // I-MMU 8k TSB pointer
2558 // env->immuregs[5] holds I-MMU TSB register value
2559 // env->immuregs[6] holds I-MMU Tag Access register value
2560 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2564 case 0x52: // I-MMU 64k TSB pointer
2566 // env->immuregs[5] holds I-MMU TSB register value
2567 // env->immuregs[6] holds I-MMU Tag Access register value
2568 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2572 case 0x55: // I-MMU data access
2574 int reg
= (addr
>> 3) & 0x3f;
2576 ret
= env
->itlb
[reg
].tte
;
2579 case 0x56: // I-MMU tag read
2581 int reg
= (addr
>> 3) & 0x3f;
2583 ret
= env
->itlb
[reg
].tag
;
2586 case 0x58: // D-MMU regs
2588 int reg
= (addr
>> 3) & 0xf;
2591 // D-TSB Tag Target register
2592 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2594 ret
= env
->dmmuregs
[reg
];
2598 case 0x59: // D-MMU 8k TSB pointer
2600 // env->dmmuregs[5] holds D-MMU TSB register value
2601 // env->dmmuregs[6] holds D-MMU Tag Access register value
2602 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2606 case 0x5a: // D-MMU 64k TSB pointer
2608 // env->dmmuregs[5] holds D-MMU TSB register value
2609 // env->dmmuregs[6] holds D-MMU Tag Access register value
2610 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2614 case 0x5d: // D-MMU data access
2616 int reg
= (addr
>> 3) & 0x3f;
2618 ret
= env
->dtlb
[reg
].tte
;
2621 case 0x5e: // D-MMU tag read
2623 int reg
= (addr
>> 3) & 0x3f;
2625 ret
= env
->dtlb
[reg
].tag
;
2628 case 0x46: // D-cache data
2629 case 0x47: // D-cache tag access
2630 case 0x4b: // E-cache error enable
2631 case 0x4c: // E-cache asynchronous fault status
2632 case 0x4d: // E-cache asynchronous fault address
2633 case 0x4e: // E-cache tag data
2634 case 0x66: // I-cache instruction access
2635 case 0x67: // I-cache tag access
2636 case 0x6e: // I-cache predecode
2637 case 0x6f: // I-cache LRU etc.
2638 case 0x76: // E-cache tag
2639 case 0x7e: // E-cache tag
2641 case 0x5b: // D-MMU data pointer
2642 case 0x48: // Interrupt dispatch, RO
2643 case 0x49: // Interrupt data receive
2644 case 0x7f: // Incoming interrupt vector, RO
2647 case 0x54: // I-MMU data in, WO
2648 case 0x57: // I-MMU demap, WO
2649 case 0x5c: // D-MMU data in, WO
2650 case 0x5f: // D-MMU demap, WO
2651 case 0x77: // Interrupt vector, WO
2653 do_unassigned_access(addr
, 0, 0, 1, size
);
2658 /* Convert from little endian */
2660 case 0x0c: // Nucleus Little Endian (LE)
2661 case 0x18: // As if user primary LE
2662 case 0x19: // As if user secondary LE
2663 case 0x1c: // Bypass LE
2664 case 0x1d: // Bypass, non-cacheable LE
2665 case 0x88: // Primary LE
2666 case 0x89: // Secondary LE
2667 case 0x8a: // Primary no-fault LE
2668 case 0x8b: // Secondary no-fault LE
2686 /* Convert to signed number */
2693 ret
= (int16_t) ret
;
2696 ret
= (int32_t) ret
;
2703 dump_asi("read ", last_addr
, asi
, size
, ret
);
2708 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2711 dump_asi("write", addr
, asi
, size
, val
);
2716 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2717 || (cpu_has_hypervisor(env
)
2718 && asi
>= 0x30 && asi
< 0x80
2719 && !(env
->hpstate
& HS_PRIV
)))
2720 raise_exception(TT_PRIV_ACT
);
2722 helper_check_align(addr
, size
- 1);
2723 addr
= asi_address_mask(env
, asi
, addr
);
2725 /* Convert to little endian */
2727 case 0x0c: // Nucleus Little Endian (LE)
2728 case 0x18: // As if user primary LE
2729 case 0x19: // As if user secondary LE
2730 case 0x1c: // Bypass LE
2731 case 0x1d: // Bypass, non-cacheable LE
2732 case 0x88: // Primary LE
2733 case 0x89: // Secondary LE
2752 case 0x10: // As if user primary
2753 case 0x11: // As if user secondary
2754 case 0x18: // As if user primary LE
2755 case 0x19: // As if user secondary LE
2756 case 0x80: // Primary
2757 case 0x81: // Secondary
2758 case 0x88: // Primary LE
2759 case 0x89: // Secondary LE
2760 case 0xe2: // UA2007 Primary block init
2761 case 0xe3: // UA2007 Secondary block init
2762 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2763 if (cpu_hypervisor_mode(env
)) {
2766 stb_hypv(addr
, val
);
2769 stw_hypv(addr
, val
);
2772 stl_hypv(addr
, val
);
2776 stq_hypv(addr
, val
);
2780 /* secondary space access has lowest asi bit equal to 1 */
2784 stb_kernel_secondary(addr
, val
);
2787 stw_kernel_secondary(addr
, val
);
2790 stl_kernel_secondary(addr
, val
);
2794 stq_kernel_secondary(addr
, val
);
2800 stb_kernel(addr
, val
);
2803 stw_kernel(addr
, val
);
2806 stl_kernel(addr
, val
);
2810 stq_kernel(addr
, val
);
2816 /* secondary space access has lowest asi bit equal to 1 */
2820 stb_user_secondary(addr
, val
);
2823 stw_user_secondary(addr
, val
);
2826 stl_user_secondary(addr
, val
);
2830 stq_user_secondary(addr
, val
);
2836 stb_user(addr
, val
);
2839 stw_user(addr
, val
);
2842 stl_user(addr
, val
);
2846 stq_user(addr
, val
);
2852 case 0x14: // Bypass
2853 case 0x15: // Bypass, non-cacheable
2854 case 0x1c: // Bypass LE
2855 case 0x1d: // Bypass, non-cacheable LE
2859 stb_phys(addr
, val
);
2862 stw_phys(addr
, val
);
2865 stl_phys(addr
, val
);
2869 stq_phys(addr
, val
);
2874 case 0x24: // Nucleus quad LDD 128 bit atomic
2875 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2876 // Only ldda allowed
2877 raise_exception(TT_ILL_INSN
);
2879 case 0x04: // Nucleus
2880 case 0x0c: // Nucleus Little Endian (LE)
2884 stb_nucleus(addr
, val
);
2887 stw_nucleus(addr
, val
);
2890 stl_nucleus(addr
, val
);
2894 stq_nucleus(addr
, val
);
2900 case 0x4a: // UPA config
2908 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
2909 // Mappings generated during D/I MMU disabled mode are
2910 // invalid in normal mode
2911 if (oldreg
!= env
->lsu
) {
2912 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
2921 case 0x50: // I-MMU regs
2923 int reg
= (addr
>> 3) & 0xf;
2926 oldreg
= env
->immuregs
[reg
];
2930 case 1: // Not in I-MMU
2935 val
= 0; // Clear SFSR
2936 env
->immu
.sfsr
= val
;
2940 case 5: // TSB access
2941 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
2942 PRIx64
"\n", env
->immu
.tsb
, val
);
2943 env
->immu
.tsb
= val
;
2945 case 6: // Tag access
2946 env
->immu
.tag_access
= val
;
2955 if (oldreg
!= env
->immuregs
[reg
]) {
2956 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
2957 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2964 case 0x54: // I-MMU data in
2965 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
2967 case 0x55: // I-MMU data access
2971 unsigned int i
= (addr
>> 3) & 0x3f;
2973 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
2976 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
2981 case 0x57: // I-MMU demap
2982 demap_tlb(env
->itlb
, addr
, "immu", env
);
2984 case 0x58: // D-MMU regs
2986 int reg
= (addr
>> 3) & 0xf;
2989 oldreg
= env
->dmmuregs
[reg
];
2995 if ((val
& 1) == 0) {
2996 val
= 0; // Clear SFSR, Fault address
2999 env
->dmmu
.sfsr
= val
;
3001 case 1: // Primary context
3002 env
->dmmu
.mmu_primary_context
= val
;
3003 /* can be optimized to only flush MMU_USER_IDX
3004 and MMU_KERNEL_IDX entries */
3007 case 2: // Secondary context
3008 env
->dmmu
.mmu_secondary_context
= val
;
3009 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
3010 and MMU_KERNEL_SECONDARY_IDX entries */
3013 case 5: // TSB access
3014 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
3015 PRIx64
"\n", env
->dmmu
.tsb
, val
);
3016 env
->dmmu
.tsb
= val
;
3018 case 6: // Tag access
3019 env
->dmmu
.tag_access
= val
;
3021 case 7: // Virtual Watchpoint
3022 case 8: // Physical Watchpoint
3024 env
->dmmuregs
[reg
] = val
;
3028 if (oldreg
!= env
->dmmuregs
[reg
]) {
3029 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
3030 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
3037 case 0x5c: // D-MMU data in
3038 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
3040 case 0x5d: // D-MMU data access
3042 unsigned int i
= (addr
>> 3) & 0x3f;
3044 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
3047 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
3052 case 0x5f: // D-MMU demap
3053 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
3055 case 0x49: // Interrupt data receive
3058 case 0x46: // D-cache data
3059 case 0x47: // D-cache tag access
3060 case 0x4b: // E-cache error enable
3061 case 0x4c: // E-cache asynchronous fault status
3062 case 0x4d: // E-cache asynchronous fault address
3063 case 0x4e: // E-cache tag data
3064 case 0x66: // I-cache instruction access
3065 case 0x67: // I-cache tag access
3066 case 0x6e: // I-cache predecode
3067 case 0x6f: // I-cache LRU etc.
3068 case 0x76: // E-cache tag
3069 case 0x7e: // E-cache tag
3071 case 0x51: // I-MMU 8k TSB pointer, RO
3072 case 0x52: // I-MMU 64k TSB pointer, RO
3073 case 0x56: // I-MMU tag read, RO
3074 case 0x59: // D-MMU 8k TSB pointer, RO
3075 case 0x5a: // D-MMU 64k TSB pointer, RO
3076 case 0x5b: // D-MMU data pointer, RO
3077 case 0x5e: // D-MMU tag read, RO
3078 case 0x48: // Interrupt dispatch, RO
3079 case 0x7f: // Incoming interrupt vector, RO
3080 case 0x82: // Primary no-fault, RO
3081 case 0x83: // Secondary no-fault, RO
3082 case 0x8a: // Primary no-fault LE, RO
3083 case 0x8b: // Secondary no-fault LE, RO
3085 do_unassigned_access(addr
, 1, 0, 1, size
);
3089 #endif /* CONFIG_USER_ONLY */
3091 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
3093 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
3094 || (cpu_has_hypervisor(env
)
3095 && asi
>= 0x30 && asi
< 0x80
3096 && !(env
->hpstate
& HS_PRIV
)))
3097 raise_exception(TT_PRIV_ACT
);
3099 addr
= asi_address_mask(env
, asi
, addr
);
3102 #if !defined(CONFIG_USER_ONLY)
3103 case 0x24: // Nucleus quad LDD 128 bit atomic
3104 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
3105 helper_check_align(addr
, 0xf);
3107 env
->gregs
[1] = ldq_nucleus(addr
+ 8);
3109 bswap64s(&env
->gregs
[1]);
3110 } else if (rd
< 8) {
3111 env
->gregs
[rd
] = ldq_nucleus(addr
);
3112 env
->gregs
[rd
+ 1] = ldq_nucleus(addr
+ 8);
3114 bswap64s(&env
->gregs
[rd
]);
3115 bswap64s(&env
->gregs
[rd
+ 1]);
3118 env
->regwptr
[rd
] = ldq_nucleus(addr
);
3119 env
->regwptr
[rd
+ 1] = ldq_nucleus(addr
+ 8);
3121 bswap64s(&env
->regwptr
[rd
]);
3122 bswap64s(&env
->regwptr
[rd
+ 1]);
3128 helper_check_align(addr
, 0x3);
3130 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3132 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3133 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3135 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3136 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3142 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3147 helper_check_align(addr
, 3);
3148 addr
= asi_address_mask(env
, asi
, addr
);
3151 case 0xf0: // Block load primary
3152 case 0xf1: // Block load secondary
3153 case 0xf8: // Block load primary LE
3154 case 0xf9: // Block load secondary LE
3156 raise_exception(TT_ILL_INSN
);
3159 helper_check_align(addr
, 0x3f);
3160 for (i
= 0; i
< 16; i
++) {
3161 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
3171 val
= helper_ld_asi(addr
, asi
, size
, 0);
3175 *((uint32_t *)&env
->fpr
[rd
]) = val
;
3178 *((int64_t *)&DT0
) = val
;
3186 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3189 target_ulong val
= 0;
3191 helper_check_align(addr
, 3);
3192 addr
= asi_address_mask(env
, asi
, addr
);
3195 case 0xe0: // UA2007 Block commit store primary (cache flush)
3196 case 0xe1: // UA2007 Block commit store secondary (cache flush)
3197 case 0xf0: // Block store primary
3198 case 0xf1: // Block store secondary
3199 case 0xf8: // Block store primary LE
3200 case 0xf9: // Block store secondary LE
3202 raise_exception(TT_ILL_INSN
);
3205 helper_check_align(addr
, 0x3f);
3206 for (i
= 0; i
< 16; i
++) {
3207 val
= *(uint32_t *)&env
->fpr
[rd
++];
3208 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
3220 val
= *((uint32_t *)&env
->fpr
[rd
]);
3223 val
= *((int64_t *)&DT0
);
3229 helper_st_asi(addr
, val
, asi
, size
);
3232 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
3233 target_ulong val2
, uint32_t asi
)
3237 val2
&= 0xffffffffUL
;
3238 ret
= helper_ld_asi(addr
, asi
, 4, 0);
3239 ret
&= 0xffffffffUL
;
3241 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
3245 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
3246 target_ulong val2
, uint32_t asi
)
3250 ret
= helper_ld_asi(addr
, asi
, 8, 0);
3252 helper_st_asi(addr
, val1
, asi
, 8);
3255 #endif /* TARGET_SPARC64 */
3257 #ifndef TARGET_SPARC64
3258 void helper_rett(void)
3262 if (env
->psret
== 1)
3263 raise_exception(TT_ILL_INSN
);
3266 cwp
= cwp_inc(env
->cwp
+ 1) ;
3267 if (env
->wim
& (1 << cwp
)) {
3268 raise_exception(TT_WIN_UNF
);
3271 env
->psrs
= env
->psrps
;
3275 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
3280 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3284 raise_exception(TT_DIV_ZERO
);
3288 if (x0
> 0xffffffff) {
3297 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
3302 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3306 raise_exception(TT_DIV_ZERO
);
3310 if ((int32_t) x0
!= x0
) {
3312 return x0
< 0? 0x80000000: 0x7fffffff;
3319 void helper_stdf(target_ulong addr
, int mem_idx
)
3321 helper_check_align(addr
, 7);
3322 #if !defined(CONFIG_USER_ONLY)
3325 stfq_user(addr
, DT0
);
3328 stfq_kernel(addr
, DT0
);
3330 #ifdef TARGET_SPARC64
3332 stfq_hypv(addr
, DT0
);
3339 stfq_raw(address_mask(env
, addr
), DT0
);
3343 void helper_lddf(target_ulong addr
, int mem_idx
)
3345 helper_check_align(addr
, 7);
3346 #if !defined(CONFIG_USER_ONLY)
3349 DT0
= ldfq_user(addr
);
3352 DT0
= ldfq_kernel(addr
);
3354 #ifdef TARGET_SPARC64
3356 DT0
= ldfq_hypv(addr
);
3363 DT0
= ldfq_raw(address_mask(env
, addr
));
3367 void helper_ldqf(target_ulong addr
, int mem_idx
)
3369 // XXX add 128 bit load
3372 helper_check_align(addr
, 7);
3373 #if !defined(CONFIG_USER_ONLY)
3376 u
.ll
.upper
= ldq_user(addr
);
3377 u
.ll
.lower
= ldq_user(addr
+ 8);
3381 u
.ll
.upper
= ldq_kernel(addr
);
3382 u
.ll
.lower
= ldq_kernel(addr
+ 8);
3385 #ifdef TARGET_SPARC64
3387 u
.ll
.upper
= ldq_hypv(addr
);
3388 u
.ll
.lower
= ldq_hypv(addr
+ 8);
3396 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
3397 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
3402 void helper_stqf(target_ulong addr
, int mem_idx
)
3404 // XXX add 128 bit store
3407 helper_check_align(addr
, 7);
3408 #if !defined(CONFIG_USER_ONLY)
3412 stq_user(addr
, u
.ll
.upper
);
3413 stq_user(addr
+ 8, u
.ll
.lower
);
3417 stq_kernel(addr
, u
.ll
.upper
);
3418 stq_kernel(addr
+ 8, u
.ll
.lower
);
3420 #ifdef TARGET_SPARC64
3423 stq_hypv(addr
, u
.ll
.upper
);
3424 stq_hypv(addr
+ 8, u
.ll
.lower
);
3432 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
3433 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
3437 static inline void set_fsr(void)
3441 switch (env
->fsr
& FSR_RD_MASK
) {
3442 case FSR_RD_NEAREST
:
3443 rnd_mode
= float_round_nearest_even
;
3447 rnd_mode
= float_round_to_zero
;
3450 rnd_mode
= float_round_up
;
3453 rnd_mode
= float_round_down
;
3456 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3459 void helper_ldfsr(uint32_t new_fsr
)
3461 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3465 #ifdef TARGET_SPARC64
3466 void helper_ldxfsr(uint64_t new_fsr
)
3468 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3473 void helper_debug(void)
3475 env
->exception_index
= EXCP_DEBUG
;
3479 #ifndef TARGET_SPARC64
3480 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3482 void helper_save(void)
3486 cwp
= cwp_dec(env
->cwp
- 1);
3487 if (env
->wim
& (1 << cwp
)) {
3488 raise_exception(TT_WIN_OVF
);
3493 void helper_restore(void)
3497 cwp
= cwp_inc(env
->cwp
+ 1);
3498 if (env
->wim
& (1 << cwp
)) {
3499 raise_exception(TT_WIN_UNF
);
3504 void helper_wrpsr(target_ulong new_psr
)
3506 if ((new_psr
& PSR_CWP
) >= env
->nwindows
) {
3507 raise_exception(TT_ILL_INSN
);
3509 cpu_put_psr(env
, new_psr
);
3513 target_ulong
helper_rdpsr(void)
3519 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3521 void helper_save(void)
3525 cwp
= cwp_dec(env
->cwp
- 1);
3526 if (env
->cansave
== 0) {
3527 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3528 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3529 ((env
->wstate
& 0x7) << 2)));
3531 if (env
->cleanwin
- env
->canrestore
== 0) {
3532 // XXX Clean windows without trap
3533 raise_exception(TT_CLRWIN
);
3542 void helper_restore(void)
3546 cwp
= cwp_inc(env
->cwp
+ 1);
3547 if (env
->canrestore
== 0) {
3548 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3549 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3550 ((env
->wstate
& 0x7) << 2)));
3558 void helper_flushw(void)
3560 if (env
->cansave
!= env
->nwindows
- 2) {
3561 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3562 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3563 ((env
->wstate
& 0x7) << 2)));
3567 void helper_saved(void)
3570 if (env
->otherwin
== 0)
3576 void helper_restored(void)
3579 if (env
->cleanwin
< env
->nwindows
- 1)
3581 if (env
->otherwin
== 0)
3587 static target_ulong
get_ccr(void)
3593 return ((env
->xcc
>> 20) << 4) | ((psr
& PSR_ICC
) >> 20);
3596 target_ulong
cpu_get_ccr(CPUState
*env1
)
3598 CPUState
*saved_env
;
3608 static void put_ccr(target_ulong val
)
3610 target_ulong tmp
= val
;
3612 env
->xcc
= (tmp
>> 4) << 20;
3613 env
->psr
= (tmp
& 0xf) << 20;
3614 CC_OP
= CC_OP_FLAGS
;
3617 void cpu_put_ccr(CPUState
*env1
, target_ulong val
)
3619 CPUState
*saved_env
;
3627 static target_ulong
get_cwp64(void)
3629 return env
->nwindows
- 1 - env
->cwp
;
3632 target_ulong
cpu_get_cwp64(CPUState
*env1
)
3634 CPUState
*saved_env
;
3644 static void put_cwp64(int cwp
)
3646 if (unlikely(cwp
>= env
->nwindows
|| cwp
< 0)) {
3647 cwp
%= env
->nwindows
;
3649 set_cwp(env
->nwindows
- 1 - cwp
);
3652 void cpu_put_cwp64(CPUState
*env1
, int cwp
)
3654 CPUState
*saved_env
;
3662 target_ulong
helper_rdccr(void)
3667 void helper_wrccr(target_ulong new_ccr
)
3672 // CWP handling is reversed in V9, but we still use the V8 register
3674 target_ulong
helper_rdcwp(void)
3679 void helper_wrcwp(target_ulong new_cwp
)
3684 // This function uses non-native bit order
3685 #define GET_FIELD(X, FROM, TO) \
3686 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3688 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3689 #define GET_FIELD_SP(X, FROM, TO) \
3690 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3692 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3694 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3695 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3696 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3697 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3698 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3699 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3700 (((pixel_addr
>> 55) & 1) << 4) |
3701 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3702 GET_FIELD_SP(pixel_addr
, 11, 12);
3705 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3709 tmp
= addr
+ offset
;
3711 env
->gsr
|= tmp
& 7ULL;
3715 target_ulong
helper_popc(target_ulong val
)
3717 return ctpop64(val
);
3720 static inline uint64_t *get_gregset(uint32_t pstate
)
3724 DPRINTF_PSTATE("ERROR in get_gregset: active pstate bits=%x%s%s%s\n",
3726 (pstate
& PS_IG
) ? " IG" : "",
3727 (pstate
& PS_MG
) ? " MG" : "",
3728 (pstate
& PS_AG
) ? " AG" : "");
3729 /* pass through to normal set of global registers */
3741 static inline void change_pstate(uint32_t new_pstate
)
3743 uint32_t pstate_regs
, new_pstate_regs
;
3744 uint64_t *src
, *dst
;
3746 if (env
->def
->features
& CPU_FEATURE_GL
) {
3747 // PS_AG is not implemented in this case
3748 new_pstate
&= ~PS_AG
;
3751 pstate_regs
= env
->pstate
& 0xc01;
3752 new_pstate_regs
= new_pstate
& 0xc01;
3754 if (new_pstate_regs
!= pstate_regs
) {
3755 DPRINTF_PSTATE("change_pstate: switching regs old=%x new=%x\n",
3756 pstate_regs
, new_pstate_regs
);
3757 // Switch global register bank
3758 src
= get_gregset(new_pstate_regs
);
3759 dst
= get_gregset(pstate_regs
);
3760 memcpy32(dst
, env
->gregs
);
3761 memcpy32(env
->gregs
, src
);
3764 DPRINTF_PSTATE("change_pstate: regs new=%x (unchanged)\n",
3767 env
->pstate
= new_pstate
;
3770 void helper_wrpstate(target_ulong new_state
)
3772 change_pstate(new_state
& 0xf3f);
3774 #if !defined(CONFIG_USER_ONLY)
3775 if (cpu_interrupts_enabled(env
)) {
3776 cpu_check_irqs(env
);
3781 void helper_wrpil(target_ulong new_pil
)
3783 #if !defined(CONFIG_USER_ONLY)
3784 DPRINTF_PSTATE("helper_wrpil old=%x new=%x\n",
3785 env
->psrpil
, (uint32_t)new_pil
);
3787 env
->psrpil
= new_pil
;
3789 if (cpu_interrupts_enabled(env
)) {
3790 cpu_check_irqs(env
);
3795 void helper_done(void)
3797 trap_state
* tsptr
= cpu_tsptr(env
);
3799 env
->pc
= tsptr
->tnpc
;
3800 env
->npc
= tsptr
->tnpc
+ 4;
3801 put_ccr(tsptr
->tstate
>> 32);
3802 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3803 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3804 put_cwp64(tsptr
->tstate
& 0xff);
3807 DPRINTF_PSTATE("... helper_done tl=%d\n", env
->tl
);
3809 #if !defined(CONFIG_USER_ONLY)
3810 if (cpu_interrupts_enabled(env
)) {
3811 cpu_check_irqs(env
);
3816 void helper_retry(void)
3818 trap_state
* tsptr
= cpu_tsptr(env
);
3820 env
->pc
= tsptr
->tpc
;
3821 env
->npc
= tsptr
->tnpc
;
3822 put_ccr(tsptr
->tstate
>> 32);
3823 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
3824 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
3825 put_cwp64(tsptr
->tstate
& 0xff);
3828 DPRINTF_PSTATE("... helper_retry tl=%d\n", env
->tl
);
3830 #if !defined(CONFIG_USER_ONLY)
3831 if (cpu_interrupts_enabled(env
)) {
3832 cpu_check_irqs(env
);
3837 static void do_modify_softint(const char* operation
, uint32_t value
)
3839 if (env
->softint
!= value
) {
3840 env
->softint
= value
;
3841 DPRINTF_PSTATE(": %s new %08x\n", operation
, env
->softint
);
3842 #if !defined(CONFIG_USER_ONLY)
3843 if (cpu_interrupts_enabled(env
)) {
3844 cpu_check_irqs(env
);
3850 void helper_set_softint(uint64_t value
)
3852 do_modify_softint("helper_set_softint", env
->softint
| (uint32_t)value
);
3855 void helper_clear_softint(uint64_t value
)
3857 do_modify_softint("helper_clear_softint", env
->softint
& (uint32_t)~value
);
3860 void helper_write_softint(uint64_t value
)
3862 do_modify_softint("helper_write_softint", (uint32_t)value
);
3866 void helper_flush(target_ulong addr
)
3869 tb_invalidate_page_range(addr
, addr
+ 8);
3872 #ifdef TARGET_SPARC64
3874 static const char * const excp_names
[0x80] = {
3875 [TT_TFAULT
] = "Instruction Access Fault",
3876 [TT_TMISS
] = "Instruction Access MMU Miss",
3877 [TT_CODE_ACCESS
] = "Instruction Access Error",
3878 [TT_ILL_INSN
] = "Illegal Instruction",
3879 [TT_PRIV_INSN
] = "Privileged Instruction",
3880 [TT_NFPU_INSN
] = "FPU Disabled",
3881 [TT_FP_EXCP
] = "FPU Exception",
3882 [TT_TOVF
] = "Tag Overflow",
3883 [TT_CLRWIN
] = "Clean Windows",
3884 [TT_DIV_ZERO
] = "Division By Zero",
3885 [TT_DFAULT
] = "Data Access Fault",
3886 [TT_DMISS
] = "Data Access MMU Miss",
3887 [TT_DATA_ACCESS
] = "Data Access Error",
3888 [TT_DPROT
] = "Data Protection Error",
3889 [TT_UNALIGNED
] = "Unaligned Memory Access",
3890 [TT_PRIV_ACT
] = "Privileged Action",
3891 [TT_EXTINT
| 0x1] = "External Interrupt 1",
3892 [TT_EXTINT
| 0x2] = "External Interrupt 2",
3893 [TT_EXTINT
| 0x3] = "External Interrupt 3",
3894 [TT_EXTINT
| 0x4] = "External Interrupt 4",
3895 [TT_EXTINT
| 0x5] = "External Interrupt 5",
3896 [TT_EXTINT
| 0x6] = "External Interrupt 6",
3897 [TT_EXTINT
| 0x7] = "External Interrupt 7",
3898 [TT_EXTINT
| 0x8] = "External Interrupt 8",
3899 [TT_EXTINT
| 0x9] = "External Interrupt 9",
3900 [TT_EXTINT
| 0xa] = "External Interrupt 10",
3901 [TT_EXTINT
| 0xb] = "External Interrupt 11",
3902 [TT_EXTINT
| 0xc] = "External Interrupt 12",
3903 [TT_EXTINT
| 0xd] = "External Interrupt 13",
3904 [TT_EXTINT
| 0xe] = "External Interrupt 14",
3905 [TT_EXTINT
| 0xf] = "External Interrupt 15",
3909 trap_state
* cpu_tsptr(CPUState
* env
)
3911 return &env
->ts
[env
->tl
& MAXTL_MASK
];
3914 void do_interrupt(CPUState
*env
)
3916 int intno
= env
->exception_index
;
3920 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
3924 if (intno
< 0 || intno
>= 0x180)
3926 else if (intno
>= 0x100)
3927 name
= "Trap Instruction";
3928 else if (intno
>= 0xc0)
3929 name
= "Window Fill";
3930 else if (intno
>= 0x80)
3931 name
= "Window Spill";
3933 name
= excp_names
[intno
];
3938 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
3939 " SP=%016" PRIx64
"\n",
3942 env
->npc
, env
->regwptr
[6]);
3943 log_cpu_state(env
, 0);
3950 ptr
= (uint8_t *)env
->pc
;
3951 for(i
= 0; i
< 16; i
++) {
3952 qemu_log(" %02x", ldub(ptr
+ i
));
3960 #if !defined(CONFIG_USER_ONLY)
3961 if (env
->tl
>= env
->maxtl
) {
3962 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
3963 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
3967 if (env
->tl
< env
->maxtl
- 1) {
3970 env
->pstate
|= PS_RED
;
3971 if (env
->tl
< env
->maxtl
)
3974 tsptr
= cpu_tsptr(env
);
3976 tsptr
->tstate
= (get_ccr() << 32) |
3977 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
3979 tsptr
->tpc
= env
->pc
;
3980 tsptr
->tnpc
= env
->npc
;
3985 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
3989 case TT_TMISS
... TT_TMISS
+ 3:
3990 case TT_DMISS
... TT_DMISS
+ 3:
3991 case TT_DPROT
... TT_DPROT
+ 3:
3992 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
3995 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
3999 if (intno
== TT_CLRWIN
) {
4000 set_cwp(cwp_dec(env
->cwp
- 1));
4001 } else if ((intno
& 0x1c0) == TT_SPILL
) {
4002 set_cwp(cwp_dec(env
->cwp
- env
->cansave
- 2));
4003 } else if ((intno
& 0x1c0) == TT_FILL
) {
4004 set_cwp(cwp_inc(env
->cwp
+ 1));
4006 env
->tbr
&= ~0x7fffULL
;
4007 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
4009 env
->npc
= env
->pc
+ 4;
4010 env
->exception_index
= -1;
4014 static const char * const excp_names
[0x80] = {
4015 [TT_TFAULT
] = "Instruction Access Fault",
4016 [TT_ILL_INSN
] = "Illegal Instruction",
4017 [TT_PRIV_INSN
] = "Privileged Instruction",
4018 [TT_NFPU_INSN
] = "FPU Disabled",
4019 [TT_WIN_OVF
] = "Window Overflow",
4020 [TT_WIN_UNF
] = "Window Underflow",
4021 [TT_UNALIGNED
] = "Unaligned Memory Access",
4022 [TT_FP_EXCP
] = "FPU Exception",
4023 [TT_DFAULT
] = "Data Access Fault",
4024 [TT_TOVF
] = "Tag Overflow",
4025 [TT_EXTINT
| 0x1] = "External Interrupt 1",
4026 [TT_EXTINT
| 0x2] = "External Interrupt 2",
4027 [TT_EXTINT
| 0x3] = "External Interrupt 3",
4028 [TT_EXTINT
| 0x4] = "External Interrupt 4",
4029 [TT_EXTINT
| 0x5] = "External Interrupt 5",
4030 [TT_EXTINT
| 0x6] = "External Interrupt 6",
4031 [TT_EXTINT
| 0x7] = "External Interrupt 7",
4032 [TT_EXTINT
| 0x8] = "External Interrupt 8",
4033 [TT_EXTINT
| 0x9] = "External Interrupt 9",
4034 [TT_EXTINT
| 0xa] = "External Interrupt 10",
4035 [TT_EXTINT
| 0xb] = "External Interrupt 11",
4036 [TT_EXTINT
| 0xc] = "External Interrupt 12",
4037 [TT_EXTINT
| 0xd] = "External Interrupt 13",
4038 [TT_EXTINT
| 0xe] = "External Interrupt 14",
4039 [TT_EXTINT
| 0xf] = "External Interrupt 15",
4040 [TT_TOVF
] = "Tag Overflow",
4041 [TT_CODE_ACCESS
] = "Instruction Access Error",
4042 [TT_DATA_ACCESS
] = "Data Access Error",
4043 [TT_DIV_ZERO
] = "Division By Zero",
4044 [TT_NCP_INSN
] = "Coprocessor Disabled",
4048 void do_interrupt(CPUState
*env
)
4050 int cwp
, intno
= env
->exception_index
;
4053 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
4057 if (intno
< 0 || intno
>= 0x100)
4059 else if (intno
>= 0x80)
4060 name
= "Trap Instruction";
4062 name
= excp_names
[intno
];
4067 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
4070 env
->npc
, env
->regwptr
[6]);
4071 log_cpu_state(env
, 0);
4078 ptr
= (uint8_t *)env
->pc
;
4079 for(i
= 0; i
< 16; i
++) {
4080 qemu_log(" %02x", ldub(ptr
+ i
));
4088 #if !defined(CONFIG_USER_ONLY)
4089 if (env
->psret
== 0) {
4090 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
4091 env
->exception_index
);
4096 cwp
= cwp_dec(env
->cwp
- 1);
4098 env
->regwptr
[9] = env
->pc
;
4099 env
->regwptr
[10] = env
->npc
;
4100 env
->psrps
= env
->psrs
;
4102 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
4104 env
->npc
= env
->pc
+ 4;
4105 env
->exception_index
= -1;
4109 #if !defined(CONFIG_USER_ONLY)
4111 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4114 #define MMUSUFFIX _mmu
4115 #define ALIGNED_ONLY
4118 #include "softmmu_template.h"
4121 #include "softmmu_template.h"
4124 #include "softmmu_template.h"
4127 #include "softmmu_template.h"
4129 /* XXX: make it generic ? */
4130 static void cpu_restore_state2(void *retaddr
)
4132 TranslationBlock
*tb
;
4136 /* now we have a real cpu fault */
4137 pc
= (unsigned long)retaddr
;
4138 tb
= tb_find_pc(pc
);
4140 /* the PC is inside the translated code. It means that we have
4141 a virtual CPU fault */
4142 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
4147 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4150 #ifdef DEBUG_UNALIGNED
4151 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
4152 "\n", addr
, env
->pc
);
4154 cpu_restore_state2(retaddr
);
4155 raise_exception(TT_UNALIGNED
);
4158 /* try to fill the TLB and return an exception if error. If retaddr is
4159 NULL, it means that the function was called in C code (i.e. not
4160 from generated code or from helper.c) */
4161 /* XXX: fix it to restore all registers */
4162 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
4165 CPUState
*saved_env
;
4167 /* XXX: hack to restore env in all cases, even if not called from
4170 env
= cpu_single_env
;
4172 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
4174 cpu_restore_state2(retaddr
);
4180 #endif /* !CONFIG_USER_ONLY */
4182 #ifndef TARGET_SPARC64
4183 #if !defined(CONFIG_USER_ONLY)
4184 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
4185 int is_asi
, int size
)
4187 CPUState
*saved_env
;
4190 /* XXX: hack to restore env in all cases, even if not called from
4193 env
= cpu_single_env
;
4194 #ifdef DEBUG_UNASSIGNED
4196 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4197 " asi 0x%02x from " TARGET_FMT_lx
"\n",
4198 is_exec
? "exec" : is_write
? "write" : "read", size
,
4199 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
4201 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4202 " from " TARGET_FMT_lx
"\n",
4203 is_exec
? "exec" : is_write
? "write" : "read", size
,
4204 size
== 1 ? "" : "s", addr
, env
->pc
);
4206 /* Don't overwrite translation and access faults */
4207 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
4208 if ((fault_type
> 4) || (fault_type
== 0)) {
4209 env
->mmuregs
[3] = 0; /* Fault status register */
4211 env
->mmuregs
[3] |= 1 << 16;
4213 env
->mmuregs
[3] |= 1 << 5;
4215 env
->mmuregs
[3] |= 1 << 6;
4217 env
->mmuregs
[3] |= 1 << 7;
4218 env
->mmuregs
[3] |= (5 << 2) | 2;
4219 /* SuperSPARC will never place instruction fault addresses in the FAR */
4221 env
->mmuregs
[4] = addr
; /* Fault address register */
4224 /* overflow (same type fault was not read before another fault) */
4225 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
4226 env
->mmuregs
[3] |= 1;
4229 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
4231 raise_exception(TT_CODE_ACCESS
);
4233 raise_exception(TT_DATA_ACCESS
);
4236 /* flush neverland mappings created during no-fault mode,
4237 so the sequential MMU faults report proper fault types */
4238 if (env
->mmuregs
[0] & MMU_NF
) {
4246 #if defined(CONFIG_USER_ONLY)
4247 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
4248 int is_asi
, int size
)
4250 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
4251 int is_asi
, int size
)
4254 CPUState
*saved_env
;
4256 /* XXX: hack to restore env in all cases, even if not called from
4259 env
= cpu_single_env
;
4261 #ifdef DEBUG_UNASSIGNED
4262 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
4263 "\n", addr
, env
->pc
);
4267 raise_exception(TT_CODE_ACCESS
);
4269 raise_exception(TT_DATA_ACCESS
);
4276 #ifdef TARGET_SPARC64
4277 void helper_tick_set_count(void *opaque
, uint64_t count
)
4279 #if !defined(CONFIG_USER_ONLY)
4280 cpu_tick_set_count(opaque
, count
);
4284 uint64_t helper_tick_get_count(void *opaque
)
4286 #if !defined(CONFIG_USER_ONLY)
4287 return cpu_tick_get_count(opaque
);
4293 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
4295 #if !defined(CONFIG_USER_ONLY)
4296 cpu_tick_set_limit(opaque
, limit
);