2 #include "host-utils.h"
8 //#define DEBUG_UNALIGNED
9 //#define DEBUG_UNASSIGNED
12 //#define DEBUG_PSTATE
13 //#define DEBUG_CACHE_CONTROL
16 #define DPRINTF_MMU(fmt, ...) \
17 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
19 #define DPRINTF_MMU(fmt, ...) do {} while (0)
23 #define DPRINTF_MXCC(fmt, ...) \
24 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
26 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
30 #define DPRINTF_ASI(fmt, ...) \
31 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
35 #define DPRINTF_PSTATE(fmt, ...) \
36 do { printf("PSTATE: " fmt , ## __VA_ARGS__); } while (0)
38 #define DPRINTF_PSTATE(fmt, ...) do {} while (0)
41 #ifdef DEBUG_CACHE_CONTROL
42 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
43 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
45 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
50 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
52 #define AM_CHECK(env1) (1)
56 #define DT0 (env->dt0)
57 #define DT1 (env->dt1)
58 #define QT0 (env->qt0)
59 #define QT1 (env->qt1)
61 /* Leon3 cache control */
63 /* Cache control: emulate the behavior of cache control registers but without
64 any effect on the emulated */
66 #define CACHE_STATE_MASK 0x3
67 #define CACHE_DISABLED 0x0
68 #define CACHE_FROZEN 0x1
69 #define CACHE_ENABLED 0x3
71 /* Cache Control register fields */
73 #define CACHE_CTRL_IF (1 << 4) /* Instruction Cache Freeze on Interrupt */
74 #define CACHE_CTRL_DF (1 << 5) /* Data Cache Freeze on Interrupt */
75 #define CACHE_CTRL_DP (1 << 14) /* Data cache flush pending */
76 #define CACHE_CTRL_IP (1 << 15) /* Instruction cache flush pending */
77 #define CACHE_CTRL_IB (1 << 16) /* Instruction burst fetch */
78 #define CACHE_CTRL_FI (1 << 21) /* Flush Instruction cache (Write only) */
79 #define CACHE_CTRL_FD (1 << 22) /* Flush Data cache (Write only) */
80 #define CACHE_CTRL_DS (1 << 23) /* Data cache snoop enable */
82 #if defined(CONFIG_USER_ONLY) && defined(TARGET_SPARC64)
83 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
84 int is_asi
, int size
);
87 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
88 // Calculates TSB pointer value for fault page size 8k or 64k
89 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
90 uint64_t tag_access_register
,
93 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
94 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
95 int tsb_size
= tsb_register
& 0xf;
97 // discard lower 13 bits which hold tag access context
98 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
101 uint64_t tsb_base_mask
= ~0x1fffULL
;
102 uint64_t va
= tag_access_va
;
104 // move va bits to correct position
105 if (page_size
== 8*1024) {
107 } else if (page_size
== 64*1024) {
112 tsb_base_mask
<<= tsb_size
;
115 // calculate tsb_base mask and adjust va if split is in use
117 if (page_size
== 8*1024) {
118 va
&= ~(1ULL << (13 + tsb_size
));
119 } else if (page_size
== 64*1024) {
120 va
|= (1ULL << (13 + tsb_size
));
125 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
128 // Calculates tag target register value by reordering bits
129 // in tag access register
130 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
132 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
135 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
136 uint64_t tlb_tag
, uint64_t tlb_tte
,
139 target_ulong mask
, size
, va
, offset
;
141 // flush page range if translation is valid
142 if (TTE_IS_VALID(tlb
->tte
)) {
144 mask
= 0xffffffffffffe000ULL
;
145 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
148 va
= tlb
->tag
& mask
;
150 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
151 tlb_flush_page(env1
, va
+ offset
);
159 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
160 const char* strmmu
, CPUState
*env1
)
166 int is_demap_context
= (demap_addr
>> 6) & 1;
169 switch ((demap_addr
>> 4) & 3) {
171 context
= env1
->dmmu
.mmu_primary_context
;
174 context
= env1
->dmmu
.mmu_secondary_context
;
184 for (i
= 0; i
< 64; i
++) {
185 if (TTE_IS_VALID(tlb
[i
].tte
)) {
187 if (is_demap_context
) {
188 // will remove non-global entries matching context value
189 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
190 !tlb_compare_context(&tlb
[i
], context
)) {
195 // will remove any entry matching VA
196 mask
= 0xffffffffffffe000ULL
;
197 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
199 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
203 // entry should be global or matching context value
204 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
205 !tlb_compare_context(&tlb
[i
], context
)) {
210 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
212 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
213 dump_mmu(stdout
, fprintf
, env1
);
219 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
220 uint64_t tlb_tag
, uint64_t tlb_tte
,
221 const char* strmmu
, CPUState
*env1
)
223 unsigned int i
, replace_used
;
225 // Try replacing invalid entry
226 for (i
= 0; i
< 64; i
++) {
227 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
228 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
230 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
231 dump_mmu(stdout
, fprintf
, env1
);
237 // All entries are valid, try replacing unlocked entry
239 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
241 // Used entries are not replaced on first pass
243 for (i
= 0; i
< 64; i
++) {
244 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
246 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
248 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
249 strmmu
, (replace_used
?"used":"unused"), i
);
250 dump_mmu(stdout
, fprintf
, env1
);
256 // Now reset used bit and search for unused entries again
258 for (i
= 0; i
< 64; i
++) {
259 TTE_SET_UNUSED(tlb
[i
].tte
);
264 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
271 static inline target_ulong
address_mask(CPUState
*env1
, target_ulong addr
)
273 #ifdef TARGET_SPARC64
275 addr
&= 0xffffffffULL
;
280 /* returns true if access using this ASI is to have address translated by MMU
281 otherwise access is to raw physical address */
282 static inline int is_translating_asi(int asi
)
284 #ifdef TARGET_SPARC64
285 /* Ultrasparc IIi translating asi
286 - note this list is defined by cpu implementation
301 /* TODO: check sparc32 bits */
306 static inline target_ulong
asi_address_mask(CPUState
*env1
,
307 int asi
, target_ulong addr
)
309 if (is_translating_asi(asi
)) {
310 return address_mask(env
, addr
);
316 static void raise_exception(int tt
)
318 env
->exception_index
= tt
;
322 void HELPER(raise_exception
)(int tt
)
327 void helper_shutdown(void)
329 #if !defined(CONFIG_USER_ONLY)
330 qemu_system_shutdown_request();
334 void helper_check_align(target_ulong addr
, uint32_t align
)
337 #ifdef DEBUG_UNALIGNED
338 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
339 "\n", addr
, env
->pc
);
341 raise_exception(TT_UNALIGNED
);
345 #define F_HELPER(name, p) void helper_f##name##p(void)
347 #define F_BINOP(name) \
348 float32 helper_f ## name ## s (float32 src1, float32 src2) \
350 return float32_ ## name (src1, src2, &env->fp_status); \
354 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
358 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
367 void helper_fsmuld(float32 src1
, float32 src2
)
369 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
370 float32_to_float64(src2
, &env
->fp_status
),
374 void helper_fdmulq(void)
376 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
377 float64_to_float128(DT1
, &env
->fp_status
),
381 float32
helper_fnegs(float32 src
)
383 return float32_chs(src
);
386 #ifdef TARGET_SPARC64
389 DT0
= float64_chs(DT1
);
394 QT0
= float128_chs(QT1
);
398 /* Integer to float conversion. */
399 float32
helper_fitos(int32_t src
)
401 return int32_to_float32(src
, &env
->fp_status
);
404 void helper_fitod(int32_t src
)
406 DT0
= int32_to_float64(src
, &env
->fp_status
);
409 void helper_fitoq(int32_t src
)
411 QT0
= int32_to_float128(src
, &env
->fp_status
);
414 #ifdef TARGET_SPARC64
415 float32
helper_fxtos(void)
417 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
422 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
427 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
432 /* floating point conversion */
433 float32
helper_fdtos(void)
435 return float64_to_float32(DT1
, &env
->fp_status
);
438 void helper_fstod(float32 src
)
440 DT0
= float32_to_float64(src
, &env
->fp_status
);
443 float32
helper_fqtos(void)
445 return float128_to_float32(QT1
, &env
->fp_status
);
448 void helper_fstoq(float32 src
)
450 QT0
= float32_to_float128(src
, &env
->fp_status
);
453 void helper_fqtod(void)
455 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
458 void helper_fdtoq(void)
460 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
463 /* Float to integer conversion. */
464 int32_t helper_fstoi(float32 src
)
466 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
469 int32_t helper_fdtoi(void)
471 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
474 int32_t helper_fqtoi(void)
476 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
479 #ifdef TARGET_SPARC64
480 void helper_fstox(float32 src
)
482 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
485 void helper_fdtox(void)
487 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
490 void helper_fqtox(void)
492 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
495 void helper_faligndata(void)
499 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
500 /* on many architectures a shift of 64 does nothing */
501 if ((env
->gsr
& 7) != 0) {
502 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
504 *((uint64_t *)&DT0
) = tmp
;
507 #ifdef HOST_WORDS_BIGENDIAN
508 #define VIS_B64(n) b[7 - (n)]
509 #define VIS_W64(n) w[3 - (n)]
510 #define VIS_SW64(n) sw[3 - (n)]
511 #define VIS_L64(n) l[1 - (n)]
512 #define VIS_B32(n) b[3 - (n)]
513 #define VIS_W32(n) w[1 - (n)]
515 #define VIS_B64(n) b[n]
516 #define VIS_W64(n) w[n]
517 #define VIS_SW64(n) sw[n]
518 #define VIS_L64(n) l[n]
519 #define VIS_B32(n) b[n]
520 #define VIS_W32(n) w[n]
538 void helper_fpmerge(void)
545 // Reverse calculation order to handle overlap
546 d
.VIS_B64(7) = s
.VIS_B64(3);
547 d
.VIS_B64(6) = d
.VIS_B64(3);
548 d
.VIS_B64(5) = s
.VIS_B64(2);
549 d
.VIS_B64(4) = d
.VIS_B64(2);
550 d
.VIS_B64(3) = s
.VIS_B64(1);
551 d
.VIS_B64(2) = d
.VIS_B64(1);
552 d
.VIS_B64(1) = s
.VIS_B64(0);
553 //d.VIS_B64(0) = d.VIS_B64(0);
558 void helper_fmul8x16(void)
567 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
568 if ((tmp & 0xff) > 0x7f) \
570 d.VIS_W64(r) = tmp >> 8;
581 void helper_fmul8x16al(void)
590 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
591 if ((tmp & 0xff) > 0x7f) \
593 d.VIS_W64(r) = tmp >> 8;
604 void helper_fmul8x16au(void)
613 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
614 if ((tmp & 0xff) > 0x7f) \
616 d.VIS_W64(r) = tmp >> 8;
627 void helper_fmul8sux16(void)
636 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
637 if ((tmp & 0xff) > 0x7f) \
639 d.VIS_W64(r) = tmp >> 8;
650 void helper_fmul8ulx16(void)
659 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
660 if ((tmp & 0xff) > 0x7f) \
662 d.VIS_W64(r) = tmp >> 8;
673 void helper_fmuld8sux16(void)
682 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
683 if ((tmp & 0xff) > 0x7f) \
687 // Reverse calculation order to handle overlap
695 void helper_fmuld8ulx16(void)
704 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
705 if ((tmp & 0xff) > 0x7f) \
709 // Reverse calculation order to handle overlap
717 void helper_fexpand(void)
722 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
724 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
725 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
726 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
727 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
732 #define VIS_HELPER(name, F) \
733 void name##16(void) \
740 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
741 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
742 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
743 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
748 uint32_t name##16s(uint32_t src1, uint32_t src2) \
755 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
756 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
761 void name##32(void) \
768 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
769 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
774 uint32_t name##32s(uint32_t src1, uint32_t src2) \
786 #define FADD(a, b) ((a) + (b))
787 #define FSUB(a, b) ((a) - (b))
788 VIS_HELPER(helper_fpadd
, FADD
)
789 VIS_HELPER(helper_fpsub
, FSUB
)
791 #define VIS_CMPHELPER(name, F) \
792 void name##16(void) \
799 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
800 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
801 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
802 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
807 void name##32(void) \
814 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
815 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
820 #define FCMPGT(a, b) ((a) > (b))
821 #define FCMPEQ(a, b) ((a) == (b))
822 #define FCMPLE(a, b) ((a) <= (b))
823 #define FCMPNE(a, b) ((a) != (b))
825 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
826 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
827 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
828 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
831 void helper_check_ieee_exceptions(void)
835 status
= get_float_exception_flags(&env
->fp_status
);
837 /* Copy IEEE 754 flags into FSR */
838 if (status
& float_flag_invalid
)
840 if (status
& float_flag_overflow
)
842 if (status
& float_flag_underflow
)
844 if (status
& float_flag_divbyzero
)
846 if (status
& float_flag_inexact
)
849 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
850 /* Unmasked exception, generate a trap */
851 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
852 raise_exception(TT_FP_EXCP
);
854 /* Accumulate exceptions */
855 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
860 void helper_clear_float_exceptions(void)
862 set_float_exception_flags(0, &env
->fp_status
);
865 float32
helper_fabss(float32 src
)
867 return float32_abs(src
);
870 #ifdef TARGET_SPARC64
871 void helper_fabsd(void)
873 DT0
= float64_abs(DT1
);
876 void helper_fabsq(void)
878 QT0
= float128_abs(QT1
);
882 float32
helper_fsqrts(float32 src
)
884 return float32_sqrt(src
, &env
->fp_status
);
887 void helper_fsqrtd(void)
889 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
892 void helper_fsqrtq(void)
894 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
897 #define GEN_FCMP(name, size, reg1, reg2, FS, E) \
898 void glue(helper_, name) (void) \
900 env->fsr &= FSR_FTT_NMASK; \
901 if (E && (glue(size, _is_any_nan)(reg1) || \
902 glue(size, _is_any_nan)(reg2)) && \
903 (env->fsr & FSR_NVM)) { \
904 env->fsr |= FSR_NVC; \
905 env->fsr |= FSR_FTT_IEEE_EXCP; \
906 raise_exception(TT_FP_EXCP); \
908 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
909 case float_relation_unordered: \
910 if ((env->fsr & FSR_NVM)) { \
911 env->fsr |= FSR_NVC; \
912 env->fsr |= FSR_FTT_IEEE_EXCP; \
913 raise_exception(TT_FP_EXCP); \
915 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
916 env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
917 env->fsr |= FSR_NVA; \
920 case float_relation_less: \
921 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
922 env->fsr |= FSR_FCC0 << FS; \
924 case float_relation_greater: \
925 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
926 env->fsr |= FSR_FCC1 << FS; \
929 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
933 #define GEN_FCMPS(name, size, FS, E) \
934 void glue(helper_, name)(float32 src1, float32 src2) \
936 env->fsr &= FSR_FTT_NMASK; \
937 if (E && (glue(size, _is_any_nan)(src1) || \
938 glue(size, _is_any_nan)(src2)) && \
939 (env->fsr & FSR_NVM)) { \
940 env->fsr |= FSR_NVC; \
941 env->fsr |= FSR_FTT_IEEE_EXCP; \
942 raise_exception(TT_FP_EXCP); \
944 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
945 case float_relation_unordered: \
946 if ((env->fsr & FSR_NVM)) { \
947 env->fsr |= FSR_NVC; \
948 env->fsr |= FSR_FTT_IEEE_EXCP; \
949 raise_exception(TT_FP_EXCP); \
951 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
952 env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
953 env->fsr |= FSR_NVA; \
956 case float_relation_less: \
957 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
958 env->fsr |= FSR_FCC0 << FS; \
960 case float_relation_greater: \
961 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
962 env->fsr |= FSR_FCC1 << FS; \
965 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
970 GEN_FCMPS(fcmps
, float32
, 0, 0);
971 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
973 GEN_FCMPS(fcmpes
, float32
, 0, 1);
974 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
976 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
977 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
979 static uint32_t compute_all_flags(void)
981 return env
->psr
& PSR_ICC
;
984 static uint32_t compute_C_flags(void)
986 return env
->psr
& PSR_CARRY
;
989 static inline uint32_t get_NZ_icc(int32_t dst
)
995 } else if (dst
< 0) {
1001 #ifdef TARGET_SPARC64
1002 static uint32_t compute_all_flags_xcc(void)
1004 return env
->xcc
& PSR_ICC
;
1007 static uint32_t compute_C_flags_xcc(void)
1009 return env
->xcc
& PSR_CARRY
;
1012 static inline uint32_t get_NZ_xcc(target_long dst
)
1018 } else if (dst
< 0) {
1025 static inline uint32_t get_V_div_icc(target_ulong src2
)
1035 static uint32_t compute_all_div(void)
1039 ret
= get_NZ_icc(CC_DST
);
1040 ret
|= get_V_div_icc(CC_SRC2
);
1044 static uint32_t compute_C_div(void)
1049 static inline uint32_t get_C_add_icc(uint32_t dst
, uint32_t src1
)
1059 static inline uint32_t get_C_addx_icc(uint32_t dst
, uint32_t src1
,
1064 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1U << 31)) {
1070 static inline uint32_t get_V_add_icc(uint32_t dst
, uint32_t src1
,
1075 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1U << 31)) {
1081 #ifdef TARGET_SPARC64
1082 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
1092 static inline uint32_t get_C_addx_xcc(target_ulong dst
, target_ulong src1
,
1097 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1ULL << 63)) {
1103 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
1108 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63)) {
1114 static uint32_t compute_all_add_xcc(void)
1118 ret
= get_NZ_xcc(CC_DST
);
1119 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1120 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1124 static uint32_t compute_C_add_xcc(void)
1126 return get_C_add_xcc(CC_DST
, CC_SRC
);
1130 static uint32_t compute_all_add(void)
1134 ret
= get_NZ_icc(CC_DST
);
1135 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1136 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1140 static uint32_t compute_C_add(void)
1142 return get_C_add_icc(CC_DST
, CC_SRC
);
1145 #ifdef TARGET_SPARC64
1146 static uint32_t compute_all_addx_xcc(void)
1150 ret
= get_NZ_xcc(CC_DST
);
1151 ret
|= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1152 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1156 static uint32_t compute_C_addx_xcc(void)
1160 ret
= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1165 static uint32_t compute_all_addx(void)
1169 ret
= get_NZ_icc(CC_DST
);
1170 ret
|= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1171 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1175 static uint32_t compute_C_addx(void)
1179 ret
= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1183 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1187 if ((src1
| src2
) & 0x3) {
1193 static uint32_t compute_all_tadd(void)
1197 ret
= get_NZ_icc(CC_DST
);
1198 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1199 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1200 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1204 static uint32_t compute_all_taddtv(void)
1208 ret
= get_NZ_icc(CC_DST
);
1209 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1213 static inline uint32_t get_C_sub_icc(uint32_t src1
, uint32_t src2
)
1223 static inline uint32_t get_C_subx_icc(uint32_t dst
, uint32_t src1
,
1228 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1U << 31)) {
1234 static inline uint32_t get_V_sub_icc(uint32_t dst
, uint32_t src1
,
1239 if (((src1
^ src2
) & (src1
^ dst
)) & (1U << 31)) {
1246 #ifdef TARGET_SPARC64
1247 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1257 static inline uint32_t get_C_subx_xcc(target_ulong dst
, target_ulong src1
,
1262 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1ULL << 63)) {
1268 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1273 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63)) {
1279 static uint32_t compute_all_sub_xcc(void)
1283 ret
= get_NZ_xcc(CC_DST
);
1284 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1285 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1289 static uint32_t compute_C_sub_xcc(void)
1291 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1295 static uint32_t compute_all_sub(void)
1299 ret
= get_NZ_icc(CC_DST
);
1300 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1301 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1305 static uint32_t compute_C_sub(void)
1307 return get_C_sub_icc(CC_SRC
, CC_SRC2
);
1310 #ifdef TARGET_SPARC64
1311 static uint32_t compute_all_subx_xcc(void)
1315 ret
= get_NZ_xcc(CC_DST
);
1316 ret
|= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1317 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1321 static uint32_t compute_C_subx_xcc(void)
1325 ret
= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1330 static uint32_t compute_all_subx(void)
1334 ret
= get_NZ_icc(CC_DST
);
1335 ret
|= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1336 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1340 static uint32_t compute_C_subx(void)
1344 ret
= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1348 static uint32_t compute_all_tsub(void)
1352 ret
= get_NZ_icc(CC_DST
);
1353 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1354 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1355 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1359 static uint32_t compute_all_tsubtv(void)
1363 ret
= get_NZ_icc(CC_DST
);
1364 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1368 static uint32_t compute_all_logic(void)
1370 return get_NZ_icc(CC_DST
);
1373 static uint32_t compute_C_logic(void)
1378 #ifdef TARGET_SPARC64
1379 static uint32_t compute_all_logic_xcc(void)
1381 return get_NZ_xcc(CC_DST
);
1385 typedef struct CCTable
{
1386 uint32_t (*compute_all
)(void); /* return all the flags */
1387 uint32_t (*compute_c
)(void); /* return the C flag */
1390 static const CCTable icc_table
[CC_OP_NB
] = {
1391 /* CC_OP_DYNAMIC should never happen */
1392 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1393 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1394 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1395 [CC_OP_ADDX
] = { compute_all_addx
, compute_C_addx
},
1396 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_add
},
1397 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_add
},
1398 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1399 [CC_OP_SUBX
] = { compute_all_subx
, compute_C_subx
},
1400 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_sub
},
1401 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_sub
},
1402 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1405 #ifdef TARGET_SPARC64
1406 static const CCTable xcc_table
[CC_OP_NB
] = {
1407 /* CC_OP_DYNAMIC should never happen */
1408 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1409 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1410 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1411 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1412 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1413 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1414 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1415 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1416 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1417 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1418 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1422 void helper_compute_psr(void)
1426 new_psr
= icc_table
[CC_OP
].compute_all();
1428 #ifdef TARGET_SPARC64
1429 new_psr
= xcc_table
[CC_OP
].compute_all();
1432 CC_OP
= CC_OP_FLAGS
;
1435 uint32_t helper_compute_C_icc(void)
1439 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1443 static inline void memcpy32(target_ulong
*dst
, const target_ulong
*src
)
1455 static void set_cwp(int new_cwp
)
1457 /* put the modified wrap registers at their proper location */
1458 if (env
->cwp
== env
->nwindows
- 1) {
1459 memcpy32(env
->regbase
, env
->regbase
+ env
->nwindows
* 16);
1463 /* put the wrap registers at their temporary location */
1464 if (new_cwp
== env
->nwindows
- 1) {
1465 memcpy32(env
->regbase
+ env
->nwindows
* 16, env
->regbase
);
1467 env
->regwptr
= env
->regbase
+ (new_cwp
* 16);
1470 void cpu_set_cwp(CPUState
*env1
, int new_cwp
)
1472 CPUState
*saved_env
;
1480 static target_ulong
get_psr(void)
1482 helper_compute_psr();
1484 #if !defined (TARGET_SPARC64)
1485 return env
->version
| (env
->psr
& PSR_ICC
) |
1486 (env
->psref
? PSR_EF
: 0) |
1487 (env
->psrpil
<< 8) |
1488 (env
->psrs
? PSR_S
: 0) |
1489 (env
->psrps
? PSR_PS
: 0) |
1490 (env
->psret
? PSR_ET
: 0) | env
->cwp
;
1492 return env
->psr
& PSR_ICC
;
1496 target_ulong
cpu_get_psr(CPUState
*env1
)
1498 CPUState
*saved_env
;
1508 static void put_psr(target_ulong val
)
1510 env
->psr
= val
& PSR_ICC
;
1511 #if !defined (TARGET_SPARC64)
1512 env
->psref
= (val
& PSR_EF
)? 1 : 0;
1513 env
->psrpil
= (val
& PSR_PIL
) >> 8;
1515 #if ((!defined (TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
1516 cpu_check_irqs(env
);
1518 #if !defined (TARGET_SPARC64)
1519 env
->psrs
= (val
& PSR_S
)? 1 : 0;
1520 env
->psrps
= (val
& PSR_PS
)? 1 : 0;
1521 env
->psret
= (val
& PSR_ET
)? 1 : 0;
1522 set_cwp(val
& PSR_CWP
);
1524 env
->cc_op
= CC_OP_FLAGS
;
1527 void cpu_put_psr(CPUState
*env1
, target_ulong val
)
1529 CPUState
*saved_env
;
1537 static int cwp_inc(int cwp
)
1539 if (unlikely(cwp
>= env
->nwindows
)) {
1540 cwp
-= env
->nwindows
;
1545 int cpu_cwp_inc(CPUState
*env1
, int cwp
)
1547 CPUState
*saved_env
;
1557 static int cwp_dec(int cwp
)
1559 if (unlikely(cwp
< 0)) {
1560 cwp
+= env
->nwindows
;
1565 int cpu_cwp_dec(CPUState
*env1
, int cwp
)
1567 CPUState
*saved_env
;
1577 #ifdef TARGET_SPARC64
1578 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1579 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1580 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1582 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1583 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1584 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1586 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1587 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1588 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1590 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1591 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1592 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1594 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1595 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1596 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1598 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1599 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1600 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1604 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1606 static void dump_mxcc(CPUState
*env
)
1608 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1610 env
->mxccdata
[0], env
->mxccdata
[1],
1611 env
->mxccdata
[2], env
->mxccdata
[3]);
1612 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1614 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1616 env
->mxccregs
[0], env
->mxccregs
[1],
1617 env
->mxccregs
[2], env
->mxccregs
[3],
1618 env
->mxccregs
[4], env
->mxccregs
[5],
1619 env
->mxccregs
[6], env
->mxccregs
[7]);
1623 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1624 && defined(DEBUG_ASI)
1625 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1631 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1632 addr
, asi
, r1
& 0xff);
1635 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1636 addr
, asi
, r1
& 0xffff);
1639 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1640 addr
, asi
, r1
& 0xffffffff);
1643 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1650 #ifndef TARGET_SPARC64
1651 #ifndef CONFIG_USER_ONLY
1654 /* Leon3 cache control */
1656 static void leon3_cache_control_int(void)
1660 if (env
->cache_control
& CACHE_CTRL_IF
) {
1661 /* Instruction cache state */
1662 state
= env
->cache_control
& CACHE_STATE_MASK
;
1663 if (state
== CACHE_ENABLED
) {
1664 state
= CACHE_FROZEN
;
1665 DPRINTF_CACHE_CONTROL("Instruction cache: freeze\n");
1668 env
->cache_control
&= ~CACHE_STATE_MASK
;
1669 env
->cache_control
|= state
;
1672 if (env
->cache_control
& CACHE_CTRL_DF
) {
1673 /* Data cache state */
1674 state
= (env
->cache_control
>> 2) & CACHE_STATE_MASK
;
1675 if (state
== CACHE_ENABLED
) {
1676 state
= CACHE_FROZEN
;
1677 DPRINTF_CACHE_CONTROL("Data cache: freeze\n");
1680 env
->cache_control
&= ~(CACHE_STATE_MASK
<< 2);
1681 env
->cache_control
|= (state
<< 2);
1685 static void leon3_cache_control_st(target_ulong addr
, uint64_t val
, int size
)
1687 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
1691 DPRINTF_CACHE_CONTROL("32bits only\n");
1696 case 0x00: /* Cache control */
1698 /* These values must always be read as zeros */
1699 val
&= ~CACHE_CTRL_FD
;
1700 val
&= ~CACHE_CTRL_FI
;
1701 val
&= ~CACHE_CTRL_IB
;
1702 val
&= ~CACHE_CTRL_IP
;
1703 val
&= ~CACHE_CTRL_DP
;
1705 env
->cache_control
= val
;
1707 case 0x04: /* Instruction cache configuration */
1708 case 0x08: /* Data cache configuration */
1712 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
1717 static uint64_t leon3_cache_control_ld(target_ulong addr
, int size
)
1722 DPRINTF_CACHE_CONTROL("32bits only\n");
1727 case 0x00: /* Cache control */
1728 ret
= env
->cache_control
;
1731 /* Configuration registers are read and only always keep those
1732 predefined values */
1734 case 0x04: /* Instruction cache configuration */
1737 case 0x08: /* Data cache configuration */
1741 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
1744 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
1749 void leon3_irq_manager(void *irq_manager
, int intno
)
1751 leon3_irq_ack(irq_manager
, intno
);
1752 leon3_cache_control_int();
1755 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1758 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1759 uint32_t last_addr
= addr
;
1762 helper_check_align(addr
, size
- 1);
1764 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
1766 case 0x00: /* Leon3 Cache Control */
1767 case 0x08: /* Leon3 Instruction Cache config */
1768 case 0x0C: /* Leon3 Date Cache config */
1769 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
1770 ret
= leon3_cache_control_ld(addr
, size
);
1773 case 0x01c00a00: /* MXCC control register */
1775 ret
= env
->mxccregs
[3];
1777 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1780 case 0x01c00a04: /* MXCC control register */
1782 ret
= env
->mxccregs
[3];
1784 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1787 case 0x01c00c00: /* Module reset register */
1789 ret
= env
->mxccregs
[5];
1790 // should we do something here?
1792 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1795 case 0x01c00f00: /* MBus port address register */
1797 ret
= env
->mxccregs
[7];
1799 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1803 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1807 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1808 "addr = %08x -> ret = %" PRIx64
","
1809 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1814 case 3: /* MMU probe */
1818 mmulev
= (addr
>> 8) & 15;
1822 ret
= mmu_probe(env
, addr
, mmulev
);
1823 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1827 case 4: /* read MMU regs */
1829 int reg
= (addr
>> 8) & 0x1f;
1831 ret
= env
->mmuregs
[reg
];
1832 if (reg
== 3) /* Fault status cleared on read */
1833 env
->mmuregs
[3] = 0;
1834 else if (reg
== 0x13) /* Fault status read */
1835 ret
= env
->mmuregs
[3];
1836 else if (reg
== 0x14) /* Fault address read */
1837 ret
= env
->mmuregs
[4];
1838 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1841 case 5: // Turbosparc ITLB Diagnostic
1842 case 6: // Turbosparc DTLB Diagnostic
1843 case 7: // Turbosparc IOTLB Diagnostic
1845 case 9: /* Supervisor code access */
1848 ret
= ldub_code(addr
);
1851 ret
= lduw_code(addr
);
1855 ret
= ldl_code(addr
);
1858 ret
= ldq_code(addr
);
1862 case 0xa: /* User data access */
1865 ret
= ldub_user(addr
);
1868 ret
= lduw_user(addr
);
1872 ret
= ldl_user(addr
);
1875 ret
= ldq_user(addr
);
1879 case 0xb: /* Supervisor data access */
1882 ret
= ldub_kernel(addr
);
1885 ret
= lduw_kernel(addr
);
1889 ret
= ldl_kernel(addr
);
1892 ret
= ldq_kernel(addr
);
1896 case 0xc: /* I-cache tag */
1897 case 0xd: /* I-cache data */
1898 case 0xe: /* D-cache tag */
1899 case 0xf: /* D-cache data */
1901 case 0x20: /* MMU passthrough */
1904 ret
= ldub_phys(addr
);
1907 ret
= lduw_phys(addr
);
1911 ret
= ldl_phys(addr
);
1914 ret
= ldq_phys(addr
);
1918 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1921 ret
= ldub_phys((target_phys_addr_t
)addr
1922 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1925 ret
= lduw_phys((target_phys_addr_t
)addr
1926 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1930 ret
= ldl_phys((target_phys_addr_t
)addr
1931 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1934 ret
= ldq_phys((target_phys_addr_t
)addr
1935 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1939 case 0x30: // Turbosparc secondary cache diagnostic
1940 case 0x31: // Turbosparc RAM snoop
1941 case 0x32: // Turbosparc page table descriptor diagnostic
1942 case 0x39: /* data cache diagnostic register */
1945 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1947 int reg
= (addr
>> 8) & 3;
1950 case 0: /* Breakpoint Value (Addr) */
1951 ret
= env
->mmubpregs
[reg
];
1953 case 1: /* Breakpoint Mask */
1954 ret
= env
->mmubpregs
[reg
];
1956 case 2: /* Breakpoint Control */
1957 ret
= env
->mmubpregs
[reg
];
1959 case 3: /* Breakpoint Status */
1960 ret
= env
->mmubpregs
[reg
];
1961 env
->mmubpregs
[reg
] = 0ULL;
1964 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1968 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1969 ret
= env
->mmubpctrv
;
1971 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1972 ret
= env
->mmubpctrc
;
1974 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1975 ret
= env
->mmubpctrs
;
1977 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1978 ret
= env
->mmubpaction
;
1980 case 8: /* User code access, XXX */
1982 do_unassigned_access(addr
, 0, 0, asi
, size
);
1992 ret
= (int16_t) ret
;
1995 ret
= (int32_t) ret
;
2002 dump_asi("read ", last_addr
, asi
, size
, ret
);
2007 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
2009 helper_check_align(addr
, size
- 1);
2011 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
2013 case 0x00: /* Leon3 Cache Control */
2014 case 0x08: /* Leon3 Instruction Cache config */
2015 case 0x0C: /* Leon3 Date Cache config */
2016 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
2017 leon3_cache_control_st(addr
, val
, size
);
2021 case 0x01c00000: /* MXCC stream data register 0 */
2023 env
->mxccdata
[0] = val
;
2025 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2028 case 0x01c00008: /* MXCC stream data register 1 */
2030 env
->mxccdata
[1] = val
;
2032 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2035 case 0x01c00010: /* MXCC stream data register 2 */
2037 env
->mxccdata
[2] = val
;
2039 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2042 case 0x01c00018: /* MXCC stream data register 3 */
2044 env
->mxccdata
[3] = val
;
2046 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2049 case 0x01c00100: /* MXCC stream source */
2051 env
->mxccregs
[0] = val
;
2053 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2055 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2057 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2059 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2061 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2064 case 0x01c00200: /* MXCC stream destination */
2066 env
->mxccregs
[1] = val
;
2068 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2070 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
2072 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
2074 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
2076 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
2079 case 0x01c00a00: /* MXCC control register */
2081 env
->mxccregs
[3] = val
;
2083 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2086 case 0x01c00a04: /* MXCC control register */
2088 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
2091 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2094 case 0x01c00e00: /* MXCC error register */
2095 // writing a 1 bit clears the error
2097 env
->mxccregs
[6] &= ~val
;
2099 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2102 case 0x01c00f00: /* MBus port address register */
2104 env
->mxccregs
[7] = val
;
2106 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2110 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
2114 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
2115 asi
, size
, addr
, val
);
2120 case 3: /* MMU flush */
2124 mmulev
= (addr
>> 8) & 15;
2125 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
2127 case 0: // flush page
2128 tlb_flush_page(env
, addr
& 0xfffff000);
2130 case 1: // flush segment (256k)
2131 case 2: // flush region (16M)
2132 case 3: // flush context (4G)
2133 case 4: // flush entire
2140 dump_mmu(stdout
, fprintf
, env
);
2144 case 4: /* write MMU regs */
2146 int reg
= (addr
>> 8) & 0x1f;
2149 oldreg
= env
->mmuregs
[reg
];
2151 case 0: // Control Register
2152 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
2154 // Mappings generated during no-fault mode or MMU
2155 // disabled mode are invalid in normal mode
2156 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
2157 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
2160 case 1: // Context Table Pointer Register
2161 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
2163 case 2: // Context Register
2164 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
2165 if (oldreg
!= env
->mmuregs
[reg
]) {
2166 /* we flush when the MMU context changes because
2167 QEMU has no MMU context support */
2171 case 3: // Synchronous Fault Status Register with Clear
2172 case 4: // Synchronous Fault Address Register
2174 case 0x10: // TLB Replacement Control Register
2175 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
2177 case 0x13: // Synchronous Fault Status Register with Read and Clear
2178 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
2180 case 0x14: // Synchronous Fault Address Register
2181 env
->mmuregs
[4] = val
;
2184 env
->mmuregs
[reg
] = val
;
2187 if (oldreg
!= env
->mmuregs
[reg
]) {
2188 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
2189 reg
, oldreg
, env
->mmuregs
[reg
]);
2192 dump_mmu(stdout
, fprintf
, env
);
2196 case 5: // Turbosparc ITLB Diagnostic
2197 case 6: // Turbosparc DTLB Diagnostic
2198 case 7: // Turbosparc IOTLB Diagnostic
2200 case 0xa: /* User data access */
2203 stb_user(addr
, val
);
2206 stw_user(addr
, val
);
2210 stl_user(addr
, val
);
2213 stq_user(addr
, val
);
2217 case 0xb: /* Supervisor data access */
2220 stb_kernel(addr
, val
);
2223 stw_kernel(addr
, val
);
2227 stl_kernel(addr
, val
);
2230 stq_kernel(addr
, val
);
2234 case 0xc: /* I-cache tag */
2235 case 0xd: /* I-cache data */
2236 case 0xe: /* D-cache tag */
2237 case 0xf: /* D-cache data */
2238 case 0x10: /* I/D-cache flush page */
2239 case 0x11: /* I/D-cache flush segment */
2240 case 0x12: /* I/D-cache flush region */
2241 case 0x13: /* I/D-cache flush context */
2242 case 0x14: /* I/D-cache flush user */
2244 case 0x17: /* Block copy, sta access */
2250 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
2252 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
2253 temp
= ldl_kernel(src
);
2254 stl_kernel(dst
, temp
);
2258 case 0x1f: /* Block fill, stda access */
2261 // fill 32 bytes with val
2263 uint32_t dst
= addr
& 7;
2265 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
2266 stq_kernel(dst
, val
);
2269 case 0x20: /* MMU passthrough */
2273 stb_phys(addr
, val
);
2276 stw_phys(addr
, val
);
2280 stl_phys(addr
, val
);
2283 stq_phys(addr
, val
);
2288 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
2292 stb_phys((target_phys_addr_t
)addr
2293 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2296 stw_phys((target_phys_addr_t
)addr
2297 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2301 stl_phys((target_phys_addr_t
)addr
2302 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2305 stq_phys((target_phys_addr_t
)addr
2306 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2311 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
2312 case 0x31: // store buffer data, Ross RT620 I-cache flush or
2313 // Turbosparc snoop RAM
2314 case 0x32: // store buffer control or Turbosparc page table
2315 // descriptor diagnostic
2316 case 0x36: /* I-cache flash clear */
2317 case 0x37: /* D-cache flash clear */
2319 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
2321 int reg
= (addr
>> 8) & 3;
2324 case 0: /* Breakpoint Value (Addr) */
2325 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2327 case 1: /* Breakpoint Mask */
2328 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2330 case 2: /* Breakpoint Control */
2331 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
2333 case 3: /* Breakpoint Status */
2334 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
2337 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
2341 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
2342 env
->mmubpctrv
= val
& 0xffffffff;
2344 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
2345 env
->mmubpctrc
= val
& 0x3;
2347 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
2348 env
->mmubpctrs
= val
& 0x3;
2350 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
2351 env
->mmubpaction
= val
& 0x1fff;
2353 case 8: /* User code access, XXX */
2354 case 9: /* Supervisor code access, XXX */
2356 do_unassigned_access(addr
, 1, 0, asi
, size
);
2360 dump_asi("write", addr
, asi
, size
, val
);
2364 #endif /* CONFIG_USER_ONLY */
2365 #else /* TARGET_SPARC64 */
2367 #ifdef CONFIG_USER_ONLY
2368 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2371 #if defined(DEBUG_ASI)
2372 target_ulong last_addr
= addr
;
2376 raise_exception(TT_PRIV_ACT
);
2378 helper_check_align(addr
, size
- 1);
2379 addr
= asi_address_mask(env
, asi
, addr
);
2382 case 0x82: // Primary no-fault
2383 case 0x8a: // Primary no-fault LE
2384 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2386 dump_asi("read ", last_addr
, asi
, size
, ret
);
2391 case 0x80: // Primary
2392 case 0x88: // Primary LE
2396 ret
= ldub_raw(addr
);
2399 ret
= lduw_raw(addr
);
2402 ret
= ldl_raw(addr
);
2406 ret
= ldq_raw(addr
);
2411 case 0x83: // Secondary no-fault
2412 case 0x8b: // Secondary no-fault LE
2413 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2415 dump_asi("read ", last_addr
, asi
, size
, ret
);
2420 case 0x81: // Secondary
2421 case 0x89: // Secondary LE
2428 /* Convert from little endian */
2430 case 0x88: // Primary LE
2431 case 0x89: // Secondary LE
2432 case 0x8a: // Primary no-fault LE
2433 case 0x8b: // Secondary no-fault LE
2451 /* Convert to signed number */
2458 ret
= (int16_t) ret
;
2461 ret
= (int32_t) ret
;
2468 dump_asi("read ", last_addr
, asi
, size
, ret
);
2473 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2476 dump_asi("write", addr
, asi
, size
, val
);
2479 raise_exception(TT_PRIV_ACT
);
2481 helper_check_align(addr
, size
- 1);
2482 addr
= asi_address_mask(env
, asi
, addr
);
2484 /* Convert to little endian */
2486 case 0x88: // Primary LE
2487 case 0x89: // Secondary LE
2506 case 0x80: // Primary
2507 case 0x88: // Primary LE
2526 case 0x81: // Secondary
2527 case 0x89: // Secondary LE
2531 case 0x82: // Primary no-fault, RO
2532 case 0x83: // Secondary no-fault, RO
2533 case 0x8a: // Primary no-fault LE, RO
2534 case 0x8b: // Secondary no-fault LE, RO
2536 do_unassigned_access(addr
, 1, 0, 1, size
);
2541 #else /* CONFIG_USER_ONLY */
2543 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2546 #if defined(DEBUG_ASI)
2547 target_ulong last_addr
= addr
;
2552 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2553 || (cpu_has_hypervisor(env
)
2554 && asi
>= 0x30 && asi
< 0x80
2555 && !(env
->hpstate
& HS_PRIV
)))
2556 raise_exception(TT_PRIV_ACT
);
2558 helper_check_align(addr
, size
- 1);
2559 addr
= asi_address_mask(env
, asi
, addr
);
2562 case 0x82: // Primary no-fault
2563 case 0x8a: // Primary no-fault LE
2564 case 0x83: // Secondary no-fault
2565 case 0x8b: // Secondary no-fault LE
2567 /* secondary space access has lowest asi bit equal to 1 */
2568 int access_mmu_idx
= ( asi
& 1 ) ? MMU_KERNEL_IDX
2569 : MMU_KERNEL_SECONDARY_IDX
;
2571 if (cpu_get_phys_page_nofault(env
, addr
, access_mmu_idx
) == -1ULL) {
2573 dump_asi("read ", last_addr
, asi
, size
, ret
);
2579 case 0x10: // As if user primary
2580 case 0x11: // As if user secondary
2581 case 0x18: // As if user primary LE
2582 case 0x19: // As if user secondary LE
2583 case 0x80: // Primary
2584 case 0x81: // Secondary
2585 case 0x88: // Primary LE
2586 case 0x89: // Secondary LE
2587 case 0xe2: // UA2007 Primary block init
2588 case 0xe3: // UA2007 Secondary block init
2589 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2590 if (cpu_hypervisor_mode(env
)) {
2593 ret
= ldub_hypv(addr
);
2596 ret
= lduw_hypv(addr
);
2599 ret
= ldl_hypv(addr
);
2603 ret
= ldq_hypv(addr
);
2607 /* secondary space access has lowest asi bit equal to 1 */
2611 ret
= ldub_kernel_secondary(addr
);
2614 ret
= lduw_kernel_secondary(addr
);
2617 ret
= ldl_kernel_secondary(addr
);
2621 ret
= ldq_kernel_secondary(addr
);
2627 ret
= ldub_kernel(addr
);
2630 ret
= lduw_kernel(addr
);
2633 ret
= ldl_kernel(addr
);
2637 ret
= ldq_kernel(addr
);
2643 /* secondary space access has lowest asi bit equal to 1 */
2647 ret
= ldub_user_secondary(addr
);
2650 ret
= lduw_user_secondary(addr
);
2653 ret
= ldl_user_secondary(addr
);
2657 ret
= ldq_user_secondary(addr
);
2663 ret
= ldub_user(addr
);
2666 ret
= lduw_user(addr
);
2669 ret
= ldl_user(addr
);
2673 ret
= ldq_user(addr
);
2679 case 0x14: // Bypass
2680 case 0x15: // Bypass, non-cacheable
2681 case 0x1c: // Bypass LE
2682 case 0x1d: // Bypass, non-cacheable LE
2686 ret
= ldub_phys(addr
);
2689 ret
= lduw_phys(addr
);
2692 ret
= ldl_phys(addr
);
2696 ret
= ldq_phys(addr
);
2701 case 0x24: // Nucleus quad LDD 128 bit atomic
2702 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2703 // Only ldda allowed
2704 raise_exception(TT_ILL_INSN
);
2706 case 0x04: // Nucleus
2707 case 0x0c: // Nucleus Little Endian (LE)
2711 ret
= ldub_nucleus(addr
);
2714 ret
= lduw_nucleus(addr
);
2717 ret
= ldl_nucleus(addr
);
2721 ret
= ldq_nucleus(addr
);
2726 case 0x4a: // UPA config
2732 case 0x50: // I-MMU regs
2734 int reg
= (addr
>> 3) & 0xf;
2737 // I-TSB Tag Target register
2738 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2740 ret
= env
->immuregs
[reg
];
2745 case 0x51: // I-MMU 8k TSB pointer
2747 // env->immuregs[5] holds I-MMU TSB register value
2748 // env->immuregs[6] holds I-MMU Tag Access register value
2749 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2753 case 0x52: // I-MMU 64k TSB pointer
2755 // env->immuregs[5] holds I-MMU TSB register value
2756 // env->immuregs[6] holds I-MMU Tag Access register value
2757 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2761 case 0x55: // I-MMU data access
2763 int reg
= (addr
>> 3) & 0x3f;
2765 ret
= env
->itlb
[reg
].tte
;
2768 case 0x56: // I-MMU tag read
2770 int reg
= (addr
>> 3) & 0x3f;
2772 ret
= env
->itlb
[reg
].tag
;
2775 case 0x58: // D-MMU regs
2777 int reg
= (addr
>> 3) & 0xf;
2780 // D-TSB Tag Target register
2781 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2783 ret
= env
->dmmuregs
[reg
];
2787 case 0x59: // D-MMU 8k TSB pointer
2789 // env->dmmuregs[5] holds D-MMU TSB register value
2790 // env->dmmuregs[6] holds D-MMU Tag Access register value
2791 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2795 case 0x5a: // D-MMU 64k TSB pointer
2797 // env->dmmuregs[5] holds D-MMU TSB register value
2798 // env->dmmuregs[6] holds D-MMU Tag Access register value
2799 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2803 case 0x5d: // D-MMU data access
2805 int reg
= (addr
>> 3) & 0x3f;
2807 ret
= env
->dtlb
[reg
].tte
;
2810 case 0x5e: // D-MMU tag read
2812 int reg
= (addr
>> 3) & 0x3f;
2814 ret
= env
->dtlb
[reg
].tag
;
2817 case 0x46: // D-cache data
2818 case 0x47: // D-cache tag access
2819 case 0x4b: // E-cache error enable
2820 case 0x4c: // E-cache asynchronous fault status
2821 case 0x4d: // E-cache asynchronous fault address
2822 case 0x4e: // E-cache tag data
2823 case 0x66: // I-cache instruction access
2824 case 0x67: // I-cache tag access
2825 case 0x6e: // I-cache predecode
2826 case 0x6f: // I-cache LRU etc.
2827 case 0x76: // E-cache tag
2828 case 0x7e: // E-cache tag
2830 case 0x5b: // D-MMU data pointer
2831 case 0x48: // Interrupt dispatch, RO
2832 case 0x49: // Interrupt data receive
2833 case 0x7f: // Incoming interrupt vector, RO
2836 case 0x54: // I-MMU data in, WO
2837 case 0x57: // I-MMU demap, WO
2838 case 0x5c: // D-MMU data in, WO
2839 case 0x5f: // D-MMU demap, WO
2840 case 0x77: // Interrupt vector, WO
2842 do_unassigned_access(addr
, 0, 0, 1, size
);
2847 /* Convert from little endian */
2849 case 0x0c: // Nucleus Little Endian (LE)
2850 case 0x18: // As if user primary LE
2851 case 0x19: // As if user secondary LE
2852 case 0x1c: // Bypass LE
2853 case 0x1d: // Bypass, non-cacheable LE
2854 case 0x88: // Primary LE
2855 case 0x89: // Secondary LE
2856 case 0x8a: // Primary no-fault LE
2857 case 0x8b: // Secondary no-fault LE
2875 /* Convert to signed number */
2882 ret
= (int16_t) ret
;
2885 ret
= (int32_t) ret
;
2892 dump_asi("read ", last_addr
, asi
, size
, ret
);
2897 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2900 dump_asi("write", addr
, asi
, size
, val
);
2905 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2906 || (cpu_has_hypervisor(env
)
2907 && asi
>= 0x30 && asi
< 0x80
2908 && !(env
->hpstate
& HS_PRIV
)))
2909 raise_exception(TT_PRIV_ACT
);
2911 helper_check_align(addr
, size
- 1);
2912 addr
= asi_address_mask(env
, asi
, addr
);
2914 /* Convert to little endian */
2916 case 0x0c: // Nucleus Little Endian (LE)
2917 case 0x18: // As if user primary LE
2918 case 0x19: // As if user secondary LE
2919 case 0x1c: // Bypass LE
2920 case 0x1d: // Bypass, non-cacheable LE
2921 case 0x88: // Primary LE
2922 case 0x89: // Secondary LE
2941 case 0x10: // As if user primary
2942 case 0x11: // As if user secondary
2943 case 0x18: // As if user primary LE
2944 case 0x19: // As if user secondary LE
2945 case 0x80: // Primary
2946 case 0x81: // Secondary
2947 case 0x88: // Primary LE
2948 case 0x89: // Secondary LE
2949 case 0xe2: // UA2007 Primary block init
2950 case 0xe3: // UA2007 Secondary block init
2951 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2952 if (cpu_hypervisor_mode(env
)) {
2955 stb_hypv(addr
, val
);
2958 stw_hypv(addr
, val
);
2961 stl_hypv(addr
, val
);
2965 stq_hypv(addr
, val
);
2969 /* secondary space access has lowest asi bit equal to 1 */
2973 stb_kernel_secondary(addr
, val
);
2976 stw_kernel_secondary(addr
, val
);
2979 stl_kernel_secondary(addr
, val
);
2983 stq_kernel_secondary(addr
, val
);
2989 stb_kernel(addr
, val
);
2992 stw_kernel(addr
, val
);
2995 stl_kernel(addr
, val
);
2999 stq_kernel(addr
, val
);
3005 /* secondary space access has lowest asi bit equal to 1 */
3009 stb_user_secondary(addr
, val
);
3012 stw_user_secondary(addr
, val
);
3015 stl_user_secondary(addr
, val
);
3019 stq_user_secondary(addr
, val
);
3025 stb_user(addr
, val
);
3028 stw_user(addr
, val
);
3031 stl_user(addr
, val
);
3035 stq_user(addr
, val
);
3041 case 0x14: // Bypass
3042 case 0x15: // Bypass, non-cacheable
3043 case 0x1c: // Bypass LE
3044 case 0x1d: // Bypass, non-cacheable LE
3048 stb_phys(addr
, val
);
3051 stw_phys(addr
, val
);
3054 stl_phys(addr
, val
);
3058 stq_phys(addr
, val
);
3063 case 0x24: // Nucleus quad LDD 128 bit atomic
3064 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
3065 // Only ldda allowed
3066 raise_exception(TT_ILL_INSN
);
3068 case 0x04: // Nucleus
3069 case 0x0c: // Nucleus Little Endian (LE)
3073 stb_nucleus(addr
, val
);
3076 stw_nucleus(addr
, val
);
3079 stl_nucleus(addr
, val
);
3083 stq_nucleus(addr
, val
);
3089 case 0x4a: // UPA config
3097 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
3098 // Mappings generated during D/I MMU disabled mode are
3099 // invalid in normal mode
3100 if (oldreg
!= env
->lsu
) {
3101 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
3104 dump_mmu(stdout
, fprintf
, env1
);
3110 case 0x50: // I-MMU regs
3112 int reg
= (addr
>> 3) & 0xf;
3115 oldreg
= env
->immuregs
[reg
];
3119 case 1: // Not in I-MMU
3124 val
= 0; // Clear SFSR
3125 env
->immu
.sfsr
= val
;
3129 case 5: // TSB access
3130 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
3131 PRIx64
"\n", env
->immu
.tsb
, val
);
3132 env
->immu
.tsb
= val
;
3134 case 6: // Tag access
3135 env
->immu
.tag_access
= val
;
3144 if (oldreg
!= env
->immuregs
[reg
]) {
3145 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
3146 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
3149 dump_mmu(stdout
, fprintf
, env
);
3153 case 0x54: // I-MMU data in
3154 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
3156 case 0x55: // I-MMU data access
3160 unsigned int i
= (addr
>> 3) & 0x3f;
3162 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
3165 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
3166 dump_mmu(stdout
, fprintf
, env
);
3170 case 0x57: // I-MMU demap
3171 demap_tlb(env
->itlb
, addr
, "immu", env
);
3173 case 0x58: // D-MMU regs
3175 int reg
= (addr
>> 3) & 0xf;
3178 oldreg
= env
->dmmuregs
[reg
];
3184 if ((val
& 1) == 0) {
3185 val
= 0; // Clear SFSR, Fault address
3188 env
->dmmu
.sfsr
= val
;
3190 case 1: // Primary context
3191 env
->dmmu
.mmu_primary_context
= val
;
3192 /* can be optimized to only flush MMU_USER_IDX
3193 and MMU_KERNEL_IDX entries */
3196 case 2: // Secondary context
3197 env
->dmmu
.mmu_secondary_context
= val
;
3198 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
3199 and MMU_KERNEL_SECONDARY_IDX entries */
3202 case 5: // TSB access
3203 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
3204 PRIx64
"\n", env
->dmmu
.tsb
, val
);
3205 env
->dmmu
.tsb
= val
;
3207 case 6: // Tag access
3208 env
->dmmu
.tag_access
= val
;
3210 case 7: // Virtual Watchpoint
3211 case 8: // Physical Watchpoint
3213 env
->dmmuregs
[reg
] = val
;
3217 if (oldreg
!= env
->dmmuregs
[reg
]) {
3218 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
3219 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
3222 dump_mmu(stdout
, fprintf
, env
);
3226 case 0x5c: // D-MMU data in
3227 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
3229 case 0x5d: // D-MMU data access
3231 unsigned int i
= (addr
>> 3) & 0x3f;
3233 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
3236 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
3237 dump_mmu(stdout
, fprintf
, env
);
3241 case 0x5f: // D-MMU demap
3242 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
3244 case 0x49: // Interrupt data receive
3247 case 0x46: // D-cache data
3248 case 0x47: // D-cache tag access
3249 case 0x4b: // E-cache error enable
3250 case 0x4c: // E-cache asynchronous fault status
3251 case 0x4d: // E-cache asynchronous fault address
3252 case 0x4e: // E-cache tag data
3253 case 0x66: // I-cache instruction access
3254 case 0x67: // I-cache tag access
3255 case 0x6e: // I-cache predecode
3256 case 0x6f: // I-cache LRU etc.
3257 case 0x76: // E-cache tag
3258 case 0x7e: // E-cache tag
3260 case 0x51: // I-MMU 8k TSB pointer, RO
3261 case 0x52: // I-MMU 64k TSB pointer, RO
3262 case 0x56: // I-MMU tag read, RO
3263 case 0x59: // D-MMU 8k TSB pointer, RO
3264 case 0x5a: // D-MMU 64k TSB pointer, RO
3265 case 0x5b: // D-MMU data pointer, RO
3266 case 0x5e: // D-MMU tag read, RO
3267 case 0x48: // Interrupt dispatch, RO
3268 case 0x7f: // Incoming interrupt vector, RO
3269 case 0x82: // Primary no-fault, RO
3270 case 0x83: // Secondary no-fault, RO
3271 case 0x8a: // Primary no-fault LE, RO
3272 case 0x8b: // Secondary no-fault LE, RO
3274 do_unassigned_access(addr
, 1, 0, 1, size
);
3278 #endif /* CONFIG_USER_ONLY */
3280 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
3282 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
3283 || (cpu_has_hypervisor(env
)
3284 && asi
>= 0x30 && asi
< 0x80
3285 && !(env
->hpstate
& HS_PRIV
)))
3286 raise_exception(TT_PRIV_ACT
);
3288 addr
= asi_address_mask(env
, asi
, addr
);
3291 #if !defined(CONFIG_USER_ONLY)
3292 case 0x24: // Nucleus quad LDD 128 bit atomic
3293 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
3294 helper_check_align(addr
, 0xf);
3296 env
->gregs
[1] = ldq_nucleus(addr
+ 8);
3298 bswap64s(&env
->gregs
[1]);
3299 } else if (rd
< 8) {
3300 env
->gregs
[rd
] = ldq_nucleus(addr
);
3301 env
->gregs
[rd
+ 1] = ldq_nucleus(addr
+ 8);
3303 bswap64s(&env
->gregs
[rd
]);
3304 bswap64s(&env
->gregs
[rd
+ 1]);
3307 env
->regwptr
[rd
] = ldq_nucleus(addr
);
3308 env
->regwptr
[rd
+ 1] = ldq_nucleus(addr
+ 8);
3310 bswap64s(&env
->regwptr
[rd
]);
3311 bswap64s(&env
->regwptr
[rd
+ 1]);
3317 helper_check_align(addr
, 0x3);
3319 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3321 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3322 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3324 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3325 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3331 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3336 helper_check_align(addr
, 3);
3337 addr
= asi_address_mask(env
, asi
, addr
);
3340 case 0xf0: /* UA2007/JPS1 Block load primary */
3341 case 0xf1: /* UA2007/JPS1 Block load secondary */
3342 case 0xf8: /* UA2007/JPS1 Block load primary LE */
3343 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
3345 raise_exception(TT_ILL_INSN
);
3348 helper_check_align(addr
, 0x3f);
3349 for (i
= 0; i
< 16; i
++) {
3350 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
3356 case 0x16: /* UA2007 Block load primary, user privilege */
3357 case 0x17: /* UA2007 Block load secondary, user privilege */
3358 case 0x1e: /* UA2007 Block load primary LE, user privilege */
3359 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
3360 case 0x70: /* JPS1 Block load primary, user privilege */
3361 case 0x71: /* JPS1 Block load secondary, user privilege */
3362 case 0x78: /* JPS1 Block load primary LE, user privilege */
3363 case 0x79: /* JPS1 Block load secondary LE, user privilege */
3365 raise_exception(TT_ILL_INSN
);
3368 helper_check_align(addr
, 0x3f);
3369 for (i
= 0; i
< 16; i
++) {
3370 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x19, 4,
3383 *((uint32_t *)&env
->fpr
[rd
]) = helper_ld_asi(addr
, asi
, size
, 0);
3386 u
.ll
= helper_ld_asi(addr
, asi
, size
, 0);
3387 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.upper
;
3388 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.lower
;
3391 u
.ll
= helper_ld_asi(addr
, asi
, 8, 0);
3392 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.upper
;
3393 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.lower
;
3394 u
.ll
= helper_ld_asi(addr
+ 8, asi
, 8, 0);
3395 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.upper
;
3396 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.lower
;
3401 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3404 target_ulong val
= 0;
3407 helper_check_align(addr
, 3);
3408 addr
= asi_address_mask(env
, asi
, addr
);
3411 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
3412 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
3413 case 0xf0: /* UA2007/JPS1 Block store primary */
3414 case 0xf1: /* UA2007/JPS1 Block store secondary */
3415 case 0xf8: /* UA2007/JPS1 Block store primary LE */
3416 case 0xf9: /* UA2007/JPS1 Block store secondary LE */
3418 raise_exception(TT_ILL_INSN
);
3421 helper_check_align(addr
, 0x3f);
3422 for (i
= 0; i
< 16; i
++) {
3423 val
= *(uint32_t *)&env
->fpr
[rd
++];
3424 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
3429 case 0x16: /* UA2007 Block load primary, user privilege */
3430 case 0x17: /* UA2007 Block load secondary, user privilege */
3431 case 0x1e: /* UA2007 Block load primary LE, user privilege */
3432 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
3433 case 0x70: /* JPS1 Block store primary, user privilege */
3434 case 0x71: /* JPS1 Block store secondary, user privilege */
3435 case 0x78: /* JPS1 Block load primary LE, user privilege */
3436 case 0x79: /* JPS1 Block load secondary LE, user privilege */
3438 raise_exception(TT_ILL_INSN
);
3441 helper_check_align(addr
, 0x3f);
3442 for (i
= 0; i
< 16; i
++) {
3443 val
= *(uint32_t *)&env
->fpr
[rd
++];
3444 helper_st_asi(addr
, val
, asi
& 0x19, 4);
3456 helper_st_asi(addr
, *(uint32_t *)&env
->fpr
[rd
], asi
, size
);
3459 u
.l
.upper
= *(uint32_t *)&env
->fpr
[rd
++];
3460 u
.l
.lower
= *(uint32_t *)&env
->fpr
[rd
++];
3461 helper_st_asi(addr
, u
.ll
, asi
, size
);
3464 u
.l
.upper
= *(uint32_t *)&env
->fpr
[rd
++];
3465 u
.l
.lower
= *(uint32_t *)&env
->fpr
[rd
++];
3466 helper_st_asi(addr
, u
.ll
, asi
, 8);
3467 u
.l
.upper
= *(uint32_t *)&env
->fpr
[rd
++];
3468 u
.l
.lower
= *(uint32_t *)&env
->fpr
[rd
++];
3469 helper_st_asi(addr
+ 8, u
.ll
, asi
, 8);
3474 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
3475 target_ulong val2
, uint32_t asi
)
3479 val2
&= 0xffffffffUL
;
3480 ret
= helper_ld_asi(addr
, asi
, 4, 0);
3481 ret
&= 0xffffffffUL
;
3483 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
3487 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
3488 target_ulong val2
, uint32_t asi
)
3492 ret
= helper_ld_asi(addr
, asi
, 8, 0);
3494 helper_st_asi(addr
, val1
, asi
, 8);
3497 #endif /* TARGET_SPARC64 */
3499 #ifndef TARGET_SPARC64
3500 void helper_rett(void)
3504 if (env
->psret
== 1)
3505 raise_exception(TT_ILL_INSN
);
3508 cwp
= cwp_inc(env
->cwp
+ 1) ;
3509 if (env
->wim
& (1 << cwp
)) {
3510 raise_exception(TT_WIN_UNF
);
3513 env
->psrs
= env
->psrps
;
3517 static target_ulong
helper_udiv_common(target_ulong a
, target_ulong b
, int cc
)
3523 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3524 x1
= (b
& 0xffffffff);
3527 raise_exception(TT_DIV_ZERO
);
3531 if (x0
> 0xffffffff) {
3538 env
->cc_src2
= overflow
;
3539 env
->cc_op
= CC_OP_DIV
;
3544 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
3546 return helper_udiv_common(a
, b
, 0);
3549 target_ulong
helper_udiv_cc(target_ulong a
, target_ulong b
)
3551 return helper_udiv_common(a
, b
, 1);
3554 static target_ulong
helper_sdiv_common(target_ulong a
, target_ulong b
, int cc
)
3560 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3561 x1
= (b
& 0xffffffff);
3564 raise_exception(TT_DIV_ZERO
);
3568 if ((int32_t) x0
!= x0
) {
3569 x0
= x0
< 0 ? 0x80000000: 0x7fffffff;
3575 env
->cc_src2
= overflow
;
3576 env
->cc_op
= CC_OP_DIV
;
3581 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
3583 return helper_sdiv_common(a
, b
, 0);
3586 target_ulong
helper_sdiv_cc(target_ulong a
, target_ulong b
)
3588 return helper_sdiv_common(a
, b
, 1);
3591 void helper_stdf(target_ulong addr
, int mem_idx
)
3593 helper_check_align(addr
, 7);
3594 #if !defined(CONFIG_USER_ONLY)
3597 stfq_user(addr
, DT0
);
3599 case MMU_KERNEL_IDX
:
3600 stfq_kernel(addr
, DT0
);
3602 #ifdef TARGET_SPARC64
3604 stfq_hypv(addr
, DT0
);
3608 DPRINTF_MMU("helper_stdf: need to check MMU idx %d\n", mem_idx
);
3612 stfq_raw(address_mask(env
, addr
), DT0
);
3616 void helper_lddf(target_ulong addr
, int mem_idx
)
3618 helper_check_align(addr
, 7);
3619 #if !defined(CONFIG_USER_ONLY)
3622 DT0
= ldfq_user(addr
);
3624 case MMU_KERNEL_IDX
:
3625 DT0
= ldfq_kernel(addr
);
3627 #ifdef TARGET_SPARC64
3629 DT0
= ldfq_hypv(addr
);
3633 DPRINTF_MMU("helper_lddf: need to check MMU idx %d\n", mem_idx
);
3637 DT0
= ldfq_raw(address_mask(env
, addr
));
3641 void helper_ldqf(target_ulong addr
, int mem_idx
)
3643 // XXX add 128 bit load
3646 helper_check_align(addr
, 7);
3647 #if !defined(CONFIG_USER_ONLY)
3650 u
.ll
.upper
= ldq_user(addr
);
3651 u
.ll
.lower
= ldq_user(addr
+ 8);
3654 case MMU_KERNEL_IDX
:
3655 u
.ll
.upper
= ldq_kernel(addr
);
3656 u
.ll
.lower
= ldq_kernel(addr
+ 8);
3659 #ifdef TARGET_SPARC64
3661 u
.ll
.upper
= ldq_hypv(addr
);
3662 u
.ll
.lower
= ldq_hypv(addr
+ 8);
3667 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
3671 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
3672 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
3677 void helper_stqf(target_ulong addr
, int mem_idx
)
3679 // XXX add 128 bit store
3682 helper_check_align(addr
, 7);
3683 #if !defined(CONFIG_USER_ONLY)
3687 stq_user(addr
, u
.ll
.upper
);
3688 stq_user(addr
+ 8, u
.ll
.lower
);
3690 case MMU_KERNEL_IDX
:
3692 stq_kernel(addr
, u
.ll
.upper
);
3693 stq_kernel(addr
+ 8, u
.ll
.lower
);
3695 #ifdef TARGET_SPARC64
3698 stq_hypv(addr
, u
.ll
.upper
);
3699 stq_hypv(addr
+ 8, u
.ll
.lower
);
3703 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
3708 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
3709 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
3713 static inline void set_fsr(void)
3717 switch (env
->fsr
& FSR_RD_MASK
) {
3718 case FSR_RD_NEAREST
:
3719 rnd_mode
= float_round_nearest_even
;
3723 rnd_mode
= float_round_to_zero
;
3726 rnd_mode
= float_round_up
;
3729 rnd_mode
= float_round_down
;
3732 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3735 void helper_ldfsr(uint32_t new_fsr
)
3737 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3741 #ifdef TARGET_SPARC64
3742 void helper_ldxfsr(uint64_t new_fsr
)
3744 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3749 void helper_debug(void)
3751 env
->exception_index
= EXCP_DEBUG
;
3755 #ifndef TARGET_SPARC64
3756 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3758 void helper_save(void)
3762 cwp
= cwp_dec(env
->cwp
- 1);
3763 if (env
->wim
& (1 << cwp
)) {
3764 raise_exception(TT_WIN_OVF
);
3769 void helper_restore(void)
3773 cwp
= cwp_inc(env
->cwp
+ 1);
3774 if (env
->wim
& (1 << cwp
)) {
3775 raise_exception(TT_WIN_UNF
);
3780 void helper_wrpsr(target_ulong new_psr
)
3782 if ((new_psr
& PSR_CWP
) >= env
->nwindows
) {
3783 raise_exception(TT_ILL_INSN
);
3785 cpu_put_psr(env
, new_psr
);
3789 target_ulong
helper_rdpsr(void)
3795 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3797 void helper_save(void)
3801 cwp
= cwp_dec(env
->cwp
- 1);
3802 if (env
->cansave
== 0) {
3803 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3804 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3805 ((env
->wstate
& 0x7) << 2)));
3807 if (env
->cleanwin
- env
->canrestore
== 0) {
3808 // XXX Clean windows without trap
3809 raise_exception(TT_CLRWIN
);
3818 void helper_restore(void)
3822 cwp
= cwp_inc(env
->cwp
+ 1);
3823 if (env
->canrestore
== 0) {
3824 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3825 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3826 ((env
->wstate
& 0x7) << 2)));
3834 void helper_flushw(void)
3836 if (env
->cansave
!= env
->nwindows
- 2) {
3837 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3838 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3839 ((env
->wstate
& 0x7) << 2)));
3843 void helper_saved(void)
3846 if (env
->otherwin
== 0)
3852 void helper_restored(void)
3855 if (env
->cleanwin
< env
->nwindows
- 1)
3857 if (env
->otherwin
== 0)
3863 static target_ulong
get_ccr(void)
3869 return ((env
->xcc
>> 20) << 4) | ((psr
& PSR_ICC
) >> 20);
3872 target_ulong
cpu_get_ccr(CPUState
*env1
)
3874 CPUState
*saved_env
;
3884 static void put_ccr(target_ulong val
)
3886 target_ulong tmp
= val
;
3888 env
->xcc
= (tmp
>> 4) << 20;
3889 env
->psr
= (tmp
& 0xf) << 20;
3890 CC_OP
= CC_OP_FLAGS
;
3893 void cpu_put_ccr(CPUState
*env1
, target_ulong val
)
3895 CPUState
*saved_env
;
3903 static target_ulong
get_cwp64(void)
3905 return env
->nwindows
- 1 - env
->cwp
;
3908 target_ulong
cpu_get_cwp64(CPUState
*env1
)
3910 CPUState
*saved_env
;
3920 static void put_cwp64(int cwp
)
3922 if (unlikely(cwp
>= env
->nwindows
|| cwp
< 0)) {
3923 cwp
%= env
->nwindows
;
3925 set_cwp(env
->nwindows
- 1 - cwp
);
3928 void cpu_put_cwp64(CPUState
*env1
, int cwp
)
3930 CPUState
*saved_env
;
3938 target_ulong
helper_rdccr(void)
3943 void helper_wrccr(target_ulong new_ccr
)
3948 // CWP handling is reversed in V9, but we still use the V8 register
3950 target_ulong
helper_rdcwp(void)
3955 void helper_wrcwp(target_ulong new_cwp
)
3960 // This function uses non-native bit order
3961 #define GET_FIELD(X, FROM, TO) \
3962 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3964 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3965 #define GET_FIELD_SP(X, FROM, TO) \
3966 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3968 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3970 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3971 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3972 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3973 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3974 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3975 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3976 (((pixel_addr
>> 55) & 1) << 4) |
3977 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3978 GET_FIELD_SP(pixel_addr
, 11, 12);
3981 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
3985 tmp
= addr
+ offset
;
3987 env
->gsr
|= tmp
& 7ULL;
3991 target_ulong
helper_popc(target_ulong val
)
3993 return ctpop64(val
);
3996 static inline uint64_t *get_gregset(uint32_t pstate
)
4000 DPRINTF_PSTATE("ERROR in get_gregset: active pstate bits=%x%s%s%s\n",
4002 (pstate
& PS_IG
) ? " IG" : "",
4003 (pstate
& PS_MG
) ? " MG" : "",
4004 (pstate
& PS_AG
) ? " AG" : "");
4005 /* pass through to normal set of global registers */
4017 static inline void change_pstate(uint32_t new_pstate
)
4019 uint32_t pstate_regs
, new_pstate_regs
;
4020 uint64_t *src
, *dst
;
4022 if (env
->def
->features
& CPU_FEATURE_GL
) {
4023 // PS_AG is not implemented in this case
4024 new_pstate
&= ~PS_AG
;
4027 pstate_regs
= env
->pstate
& 0xc01;
4028 new_pstate_regs
= new_pstate
& 0xc01;
4030 if (new_pstate_regs
!= pstate_regs
) {
4031 DPRINTF_PSTATE("change_pstate: switching regs old=%x new=%x\n",
4032 pstate_regs
, new_pstate_regs
);
4033 // Switch global register bank
4034 src
= get_gregset(new_pstate_regs
);
4035 dst
= get_gregset(pstate_regs
);
4036 memcpy32(dst
, env
->gregs
);
4037 memcpy32(env
->gregs
, src
);
4040 DPRINTF_PSTATE("change_pstate: regs new=%x (unchanged)\n",
4043 env
->pstate
= new_pstate
;
4046 void helper_wrpstate(target_ulong new_state
)
4048 change_pstate(new_state
& 0xf3f);
4050 #if !defined(CONFIG_USER_ONLY)
4051 if (cpu_interrupts_enabled(env
)) {
4052 cpu_check_irqs(env
);
4057 void cpu_change_pstate(CPUState
*env1
, uint32_t new_pstate
)
4059 CPUState
*saved_env
;
4063 change_pstate(new_pstate
);
4067 void helper_wrpil(target_ulong new_pil
)
4069 #if !defined(CONFIG_USER_ONLY)
4070 DPRINTF_PSTATE("helper_wrpil old=%x new=%x\n",
4071 env
->psrpil
, (uint32_t)new_pil
);
4073 env
->psrpil
= new_pil
;
4075 if (cpu_interrupts_enabled(env
)) {
4076 cpu_check_irqs(env
);
4081 void helper_done(void)
4083 trap_state
* tsptr
= cpu_tsptr(env
);
4085 env
->pc
= tsptr
->tnpc
;
4086 env
->npc
= tsptr
->tnpc
+ 4;
4087 put_ccr(tsptr
->tstate
>> 32);
4088 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
4089 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
4090 put_cwp64(tsptr
->tstate
& 0xff);
4093 DPRINTF_PSTATE("... helper_done tl=%d\n", env
->tl
);
4095 #if !defined(CONFIG_USER_ONLY)
4096 if (cpu_interrupts_enabled(env
)) {
4097 cpu_check_irqs(env
);
4102 void helper_retry(void)
4104 trap_state
* tsptr
= cpu_tsptr(env
);
4106 env
->pc
= tsptr
->tpc
;
4107 env
->npc
= tsptr
->tnpc
;
4108 put_ccr(tsptr
->tstate
>> 32);
4109 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
4110 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
4111 put_cwp64(tsptr
->tstate
& 0xff);
4114 DPRINTF_PSTATE("... helper_retry tl=%d\n", env
->tl
);
4116 #if !defined(CONFIG_USER_ONLY)
4117 if (cpu_interrupts_enabled(env
)) {
4118 cpu_check_irqs(env
);
4123 static void do_modify_softint(const char* operation
, uint32_t value
)
4125 if (env
->softint
!= value
) {
4126 env
->softint
= value
;
4127 DPRINTF_PSTATE(": %s new %08x\n", operation
, env
->softint
);
4128 #if !defined(CONFIG_USER_ONLY)
4129 if (cpu_interrupts_enabled(env
)) {
4130 cpu_check_irqs(env
);
4136 void helper_set_softint(uint64_t value
)
4138 do_modify_softint("helper_set_softint", env
->softint
| (uint32_t)value
);
4141 void helper_clear_softint(uint64_t value
)
4143 do_modify_softint("helper_clear_softint", env
->softint
& (uint32_t)~value
);
4146 void helper_write_softint(uint64_t value
)
4148 do_modify_softint("helper_write_softint", (uint32_t)value
);
4152 #ifdef TARGET_SPARC64
4153 trap_state
* cpu_tsptr(CPUState
* env
)
4155 return &env
->ts
[env
->tl
& MAXTL_MASK
];
4159 #if !defined(CONFIG_USER_ONLY)
4161 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4164 #define MMUSUFFIX _mmu
4165 #define ALIGNED_ONLY
4168 #include "softmmu_template.h"
4171 #include "softmmu_template.h"
4174 #include "softmmu_template.h"
4177 #include "softmmu_template.h"
4179 /* XXX: make it generic ? */
4180 static void cpu_restore_state2(void *retaddr
)
4182 TranslationBlock
*tb
;
4186 /* now we have a real cpu fault */
4187 pc
= (unsigned long)retaddr
;
4188 tb
= tb_find_pc(pc
);
4190 /* the PC is inside the translated code. It means that we have
4191 a virtual CPU fault */
4192 cpu_restore_state(tb
, env
, pc
);
4197 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4200 #ifdef DEBUG_UNALIGNED
4201 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
4202 "\n", addr
, env
->pc
);
4204 cpu_restore_state2(retaddr
);
4205 raise_exception(TT_UNALIGNED
);
4208 /* try to fill the TLB and return an exception if error. If retaddr is
4209 NULL, it means that the function was called in C code (i.e. not
4210 from generated code or from helper.c) */
4211 /* XXX: fix it to restore all registers */
4212 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
4215 CPUState
*saved_env
;
4217 /* XXX: hack to restore env in all cases, even if not called from
4220 env
= cpu_single_env
;
4222 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
4224 cpu_restore_state2(retaddr
);
4230 #endif /* !CONFIG_USER_ONLY */
4232 #ifndef TARGET_SPARC64
4233 #if !defined(CONFIG_USER_ONLY)
4234 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
4235 int is_asi
, int size
)
4237 CPUState
*saved_env
;
4240 /* XXX: hack to restore env in all cases, even if not called from
4243 env
= cpu_single_env
;
4244 #ifdef DEBUG_UNASSIGNED
4246 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4247 " asi 0x%02x from " TARGET_FMT_lx
"\n",
4248 is_exec
? "exec" : is_write
? "write" : "read", size
,
4249 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
4251 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4252 " from " TARGET_FMT_lx
"\n",
4253 is_exec
? "exec" : is_write
? "write" : "read", size
,
4254 size
== 1 ? "" : "s", addr
, env
->pc
);
4256 /* Don't overwrite translation and access faults */
4257 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
4258 if ((fault_type
> 4) || (fault_type
== 0)) {
4259 env
->mmuregs
[3] = 0; /* Fault status register */
4261 env
->mmuregs
[3] |= 1 << 16;
4263 env
->mmuregs
[3] |= 1 << 5;
4265 env
->mmuregs
[3] |= 1 << 6;
4267 env
->mmuregs
[3] |= 1 << 7;
4268 env
->mmuregs
[3] |= (5 << 2) | 2;
4269 /* SuperSPARC will never place instruction fault addresses in the FAR */
4271 env
->mmuregs
[4] = addr
; /* Fault address register */
4274 /* overflow (same type fault was not read before another fault) */
4275 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
4276 env
->mmuregs
[3] |= 1;
4279 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
4281 raise_exception(TT_CODE_ACCESS
);
4283 raise_exception(TT_DATA_ACCESS
);
4286 /* flush neverland mappings created during no-fault mode,
4287 so the sequential MMU faults report proper fault types */
4288 if (env
->mmuregs
[0] & MMU_NF
) {
4296 #if defined(CONFIG_USER_ONLY)
4297 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
4298 int is_asi
, int size
)
4300 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
4301 int is_asi
, int size
)
4304 CPUState
*saved_env
;
4306 /* XXX: hack to restore env in all cases, even if not called from
4309 env
= cpu_single_env
;
4311 #ifdef DEBUG_UNASSIGNED
4312 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
4313 "\n", addr
, env
->pc
);
4317 raise_exception(TT_CODE_ACCESS
);
4319 raise_exception(TT_DATA_ACCESS
);
4326 #ifdef TARGET_SPARC64
4327 void helper_tick_set_count(void *opaque
, uint64_t count
)
4329 #if !defined(CONFIG_USER_ONLY)
4330 cpu_tick_set_count(opaque
, count
);
4334 uint64_t helper_tick_get_count(void *opaque
)
4336 #if !defined(CONFIG_USER_ONLY)
4337 return cpu_tick_get_count(opaque
);
4343 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
4345 #if !defined(CONFIG_USER_ONLY)
4346 cpu_tick_set_limit(opaque
, limit
);