2 #include "dyngen-exec.h"
3 #include "host-utils.h"
7 #if !defined(CONFIG_USER_ONLY)
8 #include "softmmu_exec.h"
13 //#define DEBUG_UNALIGNED
14 //#define DEBUG_UNASSIGNED
17 //#define DEBUG_PSTATE
18 //#define DEBUG_CACHE_CONTROL
21 #define DPRINTF_MMU(fmt, ...) \
22 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
24 #define DPRINTF_MMU(fmt, ...) do {} while (0)
28 #define DPRINTF_MXCC(fmt, ...) \
29 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
31 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
35 #define DPRINTF_ASI(fmt, ...) \
36 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
40 #define DPRINTF_PSTATE(fmt, ...) \
41 do { printf("PSTATE: " fmt , ## __VA_ARGS__); } while (0)
43 #define DPRINTF_PSTATE(fmt, ...) do {} while (0)
46 #ifdef DEBUG_CACHE_CONTROL
47 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
48 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
50 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
55 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
57 #define AM_CHECK(env1) (1)
61 #define DT0 (env->dt0)
62 #define DT1 (env->dt1)
63 #define QT0 (env->qt0)
64 #define QT1 (env->qt1)
66 /* Leon3 cache control */
68 /* Cache control: emulate the behavior of cache control registers but without
69 any effect on the emulated */
71 #define CACHE_STATE_MASK 0x3
72 #define CACHE_DISABLED 0x0
73 #define CACHE_FROZEN 0x1
74 #define CACHE_ENABLED 0x3
76 /* Cache Control register fields */
78 #define CACHE_CTRL_IF (1 << 4) /* Instruction Cache Freeze on Interrupt */
79 #define CACHE_CTRL_DF (1 << 5) /* Data Cache Freeze on Interrupt */
80 #define CACHE_CTRL_DP (1 << 14) /* Data cache flush pending */
81 #define CACHE_CTRL_IP (1 << 15) /* Instruction cache flush pending */
82 #define CACHE_CTRL_IB (1 << 16) /* Instruction burst fetch */
83 #define CACHE_CTRL_FI (1 << 21) /* Flush Instruction cache (Write only) */
84 #define CACHE_CTRL_FD (1 << 22) /* Flush Data cache (Write only) */
85 #define CACHE_CTRL_DS (1 << 23) /* Data cache snoop enable */
87 #if !defined(CONFIG_USER_ONLY)
88 static void do_unassigned_access(target_phys_addr_t addr
, int is_write
,
89 int is_exec
, int is_asi
, int size
);
92 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
93 int is_asi
, int size
);
97 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
98 // Calculates TSB pointer value for fault page size 8k or 64k
99 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
100 uint64_t tag_access_register
,
103 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
104 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
105 int tsb_size
= tsb_register
& 0xf;
107 // discard lower 13 bits which hold tag access context
108 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
111 uint64_t tsb_base_mask
= ~0x1fffULL
;
112 uint64_t va
= tag_access_va
;
114 // move va bits to correct position
115 if (page_size
== 8*1024) {
117 } else if (page_size
== 64*1024) {
122 tsb_base_mask
<<= tsb_size
;
125 // calculate tsb_base mask and adjust va if split is in use
127 if (page_size
== 8*1024) {
128 va
&= ~(1ULL << (13 + tsb_size
));
129 } else if (page_size
== 64*1024) {
130 va
|= (1ULL << (13 + tsb_size
));
135 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
138 // Calculates tag target register value by reordering bits
139 // in tag access register
140 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
142 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
145 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
146 uint64_t tlb_tag
, uint64_t tlb_tte
,
149 target_ulong mask
, size
, va
, offset
;
151 // flush page range if translation is valid
152 if (TTE_IS_VALID(tlb
->tte
)) {
154 mask
= 0xffffffffffffe000ULL
;
155 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
158 va
= tlb
->tag
& mask
;
160 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
161 tlb_flush_page(env1
, va
+ offset
);
169 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
170 const char* strmmu
, CPUState
*env1
)
176 int is_demap_context
= (demap_addr
>> 6) & 1;
179 switch ((demap_addr
>> 4) & 3) {
181 context
= env1
->dmmu
.mmu_primary_context
;
184 context
= env1
->dmmu
.mmu_secondary_context
;
194 for (i
= 0; i
< 64; i
++) {
195 if (TTE_IS_VALID(tlb
[i
].tte
)) {
197 if (is_demap_context
) {
198 // will remove non-global entries matching context value
199 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
200 !tlb_compare_context(&tlb
[i
], context
)) {
205 // will remove any entry matching VA
206 mask
= 0xffffffffffffe000ULL
;
207 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
209 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
213 // entry should be global or matching context value
214 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
215 !tlb_compare_context(&tlb
[i
], context
)) {
220 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
222 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
223 dump_mmu(stdout
, fprintf
, env1
);
229 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
230 uint64_t tlb_tag
, uint64_t tlb_tte
,
231 const char* strmmu
, CPUState
*env1
)
233 unsigned int i
, replace_used
;
235 // Try replacing invalid entry
236 for (i
= 0; i
< 64; i
++) {
237 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
238 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
240 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
241 dump_mmu(stdout
, fprintf
, env1
);
247 // All entries are valid, try replacing unlocked entry
249 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
251 // Used entries are not replaced on first pass
253 for (i
= 0; i
< 64; i
++) {
254 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
256 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
258 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
259 strmmu
, (replace_used
?"used":"unused"), i
);
260 dump_mmu(stdout
, fprintf
, env1
);
266 // Now reset used bit and search for unused entries again
268 for (i
= 0; i
< 64; i
++) {
269 TTE_SET_UNUSED(tlb
[i
].tte
);
274 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
281 static inline target_ulong
address_mask(CPUState
*env1
, target_ulong addr
)
283 #ifdef TARGET_SPARC64
285 addr
&= 0xffffffffULL
;
290 /* returns true if access using this ASI is to have address translated by MMU
291 otherwise access is to raw physical address */
292 static inline int is_translating_asi(int asi
)
294 #ifdef TARGET_SPARC64
295 /* Ultrasparc IIi translating asi
296 - note this list is defined by cpu implementation
312 /* TODO: check sparc32 bits */
317 static inline target_ulong
asi_address_mask(CPUState
*env1
,
318 int asi
, target_ulong addr
)
320 if (is_translating_asi(asi
)) {
321 return address_mask(env
, addr
);
327 static void raise_exception(int tt
)
329 env
->exception_index
= tt
;
333 void HELPER(raise_exception
)(int tt
)
338 void helper_shutdown(void)
340 #if !defined(CONFIG_USER_ONLY)
341 qemu_system_shutdown_request();
345 void helper_check_align(target_ulong addr
, uint32_t align
)
348 #ifdef DEBUG_UNALIGNED
349 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
350 "\n", addr
, env
->pc
);
352 raise_exception(TT_UNALIGNED
);
356 #define F_HELPER(name, p) void helper_f##name##p(void)
358 #define F_BINOP(name) \
359 float32 helper_f ## name ## s (float32 src1, float32 src2) \
361 return float32_ ## name (src1, src2, &env->fp_status); \
365 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
369 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
378 void helper_fsmuld(float32 src1
, float32 src2
)
380 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
381 float32_to_float64(src2
, &env
->fp_status
),
385 void helper_fdmulq(void)
387 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
388 float64_to_float128(DT1
, &env
->fp_status
),
392 float32
helper_fnegs(float32 src
)
394 return float32_chs(src
);
397 #ifdef TARGET_SPARC64
400 DT0
= float64_chs(DT1
);
405 QT0
= float128_chs(QT1
);
409 /* Integer to float conversion. */
410 float32
helper_fitos(int32_t src
)
412 return int32_to_float32(src
, &env
->fp_status
);
415 void helper_fitod(int32_t src
)
417 DT0
= int32_to_float64(src
, &env
->fp_status
);
420 void helper_fitoq(int32_t src
)
422 QT0
= int32_to_float128(src
, &env
->fp_status
);
425 #ifdef TARGET_SPARC64
426 float32
helper_fxtos(void)
428 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
433 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
438 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
443 /* floating point conversion */
444 float32
helper_fdtos(void)
446 return float64_to_float32(DT1
, &env
->fp_status
);
449 void helper_fstod(float32 src
)
451 DT0
= float32_to_float64(src
, &env
->fp_status
);
454 float32
helper_fqtos(void)
456 return float128_to_float32(QT1
, &env
->fp_status
);
459 void helper_fstoq(float32 src
)
461 QT0
= float32_to_float128(src
, &env
->fp_status
);
464 void helper_fqtod(void)
466 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
469 void helper_fdtoq(void)
471 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
474 /* Float to integer conversion. */
475 int32_t helper_fstoi(float32 src
)
477 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
480 int32_t helper_fdtoi(void)
482 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
485 int32_t helper_fqtoi(void)
487 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
490 #ifdef TARGET_SPARC64
491 void helper_fstox(float32 src
)
493 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
496 void helper_fdtox(void)
498 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
501 void helper_fqtox(void)
503 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
506 void helper_faligndata(void)
510 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
511 /* on many architectures a shift of 64 does nothing */
512 if ((env
->gsr
& 7) != 0) {
513 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
515 *((uint64_t *)&DT0
) = tmp
;
518 #ifdef HOST_WORDS_BIGENDIAN
519 #define VIS_B64(n) b[7 - (n)]
520 #define VIS_W64(n) w[3 - (n)]
521 #define VIS_SW64(n) sw[3 - (n)]
522 #define VIS_L64(n) l[1 - (n)]
523 #define VIS_B32(n) b[3 - (n)]
524 #define VIS_W32(n) w[1 - (n)]
526 #define VIS_B64(n) b[n]
527 #define VIS_W64(n) w[n]
528 #define VIS_SW64(n) sw[n]
529 #define VIS_L64(n) l[n]
530 #define VIS_B32(n) b[n]
531 #define VIS_W32(n) w[n]
550 void helper_fpmerge(void)
557 // Reverse calculation order to handle overlap
558 d
.VIS_B64(7) = s
.VIS_B64(3);
559 d
.VIS_B64(6) = d
.VIS_B64(3);
560 d
.VIS_B64(5) = s
.VIS_B64(2);
561 d
.VIS_B64(4) = d
.VIS_B64(2);
562 d
.VIS_B64(3) = s
.VIS_B64(1);
563 d
.VIS_B64(2) = d
.VIS_B64(1);
564 d
.VIS_B64(1) = s
.VIS_B64(0);
565 //d.VIS_B64(0) = d.VIS_B64(0);
570 void helper_fmul8x16(void)
579 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
580 if ((tmp & 0xff) > 0x7f) \
582 d.VIS_W64(r) = tmp >> 8;
593 void helper_fmul8x16al(void)
602 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
603 if ((tmp & 0xff) > 0x7f) \
605 d.VIS_W64(r) = tmp >> 8;
616 void helper_fmul8x16au(void)
625 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
626 if ((tmp & 0xff) > 0x7f) \
628 d.VIS_W64(r) = tmp >> 8;
639 void helper_fmul8sux16(void)
648 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
649 if ((tmp & 0xff) > 0x7f) \
651 d.VIS_W64(r) = tmp >> 8;
662 void helper_fmul8ulx16(void)
671 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
672 if ((tmp & 0xff) > 0x7f) \
674 d.VIS_W64(r) = tmp >> 8;
685 void helper_fmuld8sux16(void)
694 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
695 if ((tmp & 0xff) > 0x7f) \
699 // Reverse calculation order to handle overlap
707 void helper_fmuld8ulx16(void)
716 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
717 if ((tmp & 0xff) > 0x7f) \
721 // Reverse calculation order to handle overlap
729 void helper_fexpand(void)
734 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
736 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
737 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
738 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
739 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
744 #define VIS_HELPER(name, F) \
745 void name##16(void) \
752 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
753 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
754 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
755 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
760 uint32_t name##16s(uint32_t src1, uint32_t src2) \
767 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
768 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
773 void name##32(void) \
780 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
781 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
786 uint32_t name##32s(uint32_t src1, uint32_t src2) \
798 #define FADD(a, b) ((a) + (b))
799 #define FSUB(a, b) ((a) - (b))
800 VIS_HELPER(helper_fpadd
, FADD
)
801 VIS_HELPER(helper_fpsub
, FSUB
)
803 #define VIS_CMPHELPER(name, F) \
804 uint64_t name##16(void) \
811 d.VIS_W64(0) = F(s.VIS_W64(0), d.VIS_W64(0)) ? 1 : 0; \
812 d.VIS_W64(0) |= F(s.VIS_W64(1), d.VIS_W64(1)) ? 2 : 0; \
813 d.VIS_W64(0) |= F(s.VIS_W64(2), d.VIS_W64(2)) ? 4 : 0; \
814 d.VIS_W64(0) |= F(s.VIS_W64(3), d.VIS_W64(3)) ? 8 : 0; \
815 d.VIS_W64(1) = d.VIS_W64(2) = d.VIS_W64(3) = 0; \
820 uint64_t name##32(void) \
827 d.VIS_L64(0) = F(s.VIS_L64(0), d.VIS_L64(0)) ? 1 : 0; \
828 d.VIS_L64(0) |= F(s.VIS_L64(1), d.VIS_L64(1)) ? 2 : 0; \
834 #define FCMPGT(a, b) ((a) > (b))
835 #define FCMPEQ(a, b) ((a) == (b))
836 #define FCMPLE(a, b) ((a) <= (b))
837 #define FCMPNE(a, b) ((a) != (b))
839 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
840 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
841 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
842 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
845 void helper_check_ieee_exceptions(void)
849 status
= get_float_exception_flags(&env
->fp_status
);
851 /* Copy IEEE 754 flags into FSR */
852 if (status
& float_flag_invalid
)
854 if (status
& float_flag_overflow
)
856 if (status
& float_flag_underflow
)
858 if (status
& float_flag_divbyzero
)
860 if (status
& float_flag_inexact
)
863 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
864 /* Unmasked exception, generate a trap */
865 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
866 raise_exception(TT_FP_EXCP
);
868 /* Accumulate exceptions */
869 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
874 void helper_clear_float_exceptions(void)
876 set_float_exception_flags(0, &env
->fp_status
);
879 float32
helper_fabss(float32 src
)
881 return float32_abs(src
);
884 #ifdef TARGET_SPARC64
885 void helper_fabsd(void)
887 DT0
= float64_abs(DT1
);
890 void helper_fabsq(void)
892 QT0
= float128_abs(QT1
);
896 float32
helper_fsqrts(float32 src
)
898 return float32_sqrt(src
, &env
->fp_status
);
901 void helper_fsqrtd(void)
903 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
906 void helper_fsqrtq(void)
908 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
911 #define GEN_FCMP(name, size, reg1, reg2, FS, E) \
912 void glue(helper_, name) (void) \
914 env->fsr &= FSR_FTT_NMASK; \
915 if (E && (glue(size, _is_any_nan)(reg1) || \
916 glue(size, _is_any_nan)(reg2)) && \
917 (env->fsr & FSR_NVM)) { \
918 env->fsr |= FSR_NVC; \
919 env->fsr |= FSR_FTT_IEEE_EXCP; \
920 raise_exception(TT_FP_EXCP); \
922 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
923 case float_relation_unordered: \
924 if ((env->fsr & FSR_NVM)) { \
925 env->fsr |= FSR_NVC; \
926 env->fsr |= FSR_FTT_IEEE_EXCP; \
927 raise_exception(TT_FP_EXCP); \
929 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
930 env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
931 env->fsr |= FSR_NVA; \
934 case float_relation_less: \
935 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
936 env->fsr |= FSR_FCC0 << FS; \
938 case float_relation_greater: \
939 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
940 env->fsr |= FSR_FCC1 << FS; \
943 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
947 #define GEN_FCMPS(name, size, FS, E) \
948 void glue(helper_, name)(float32 src1, float32 src2) \
950 env->fsr &= FSR_FTT_NMASK; \
951 if (E && (glue(size, _is_any_nan)(src1) || \
952 glue(size, _is_any_nan)(src2)) && \
953 (env->fsr & FSR_NVM)) { \
954 env->fsr |= FSR_NVC; \
955 env->fsr |= FSR_FTT_IEEE_EXCP; \
956 raise_exception(TT_FP_EXCP); \
958 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
959 case float_relation_unordered: \
960 if ((env->fsr & FSR_NVM)) { \
961 env->fsr |= FSR_NVC; \
962 env->fsr |= FSR_FTT_IEEE_EXCP; \
963 raise_exception(TT_FP_EXCP); \
965 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
966 env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
967 env->fsr |= FSR_NVA; \
970 case float_relation_less: \
971 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
972 env->fsr |= FSR_FCC0 << FS; \
974 case float_relation_greater: \
975 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
976 env->fsr |= FSR_FCC1 << FS; \
979 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
984 GEN_FCMPS(fcmps
, float32
, 0, 0);
985 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
987 GEN_FCMPS(fcmpes
, float32
, 0, 1);
988 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
990 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
991 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
993 static uint32_t compute_all_flags(void)
995 return env
->psr
& PSR_ICC
;
998 static uint32_t compute_C_flags(void)
1000 return env
->psr
& PSR_CARRY
;
1003 static inline uint32_t get_NZ_icc(int32_t dst
)
1009 } else if (dst
< 0) {
1015 #ifdef TARGET_SPARC64
1016 static uint32_t compute_all_flags_xcc(void)
1018 return env
->xcc
& PSR_ICC
;
1021 static uint32_t compute_C_flags_xcc(void)
1023 return env
->xcc
& PSR_CARRY
;
1026 static inline uint32_t get_NZ_xcc(target_long dst
)
1032 } else if (dst
< 0) {
1039 static inline uint32_t get_V_div_icc(target_ulong src2
)
1049 static uint32_t compute_all_div(void)
1053 ret
= get_NZ_icc(CC_DST
);
1054 ret
|= get_V_div_icc(CC_SRC2
);
1058 static uint32_t compute_C_div(void)
1063 static inline uint32_t get_C_add_icc(uint32_t dst
, uint32_t src1
)
1073 static inline uint32_t get_C_addx_icc(uint32_t dst
, uint32_t src1
,
1078 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1U << 31)) {
1084 static inline uint32_t get_V_add_icc(uint32_t dst
, uint32_t src1
,
1089 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1U << 31)) {
1095 #ifdef TARGET_SPARC64
1096 static inline uint32_t get_C_add_xcc(target_ulong dst
, target_ulong src1
)
1106 static inline uint32_t get_C_addx_xcc(target_ulong dst
, target_ulong src1
,
1111 if (((src1
& src2
) | (~dst
& (src1
| src2
))) & (1ULL << 63)) {
1117 static inline uint32_t get_V_add_xcc(target_ulong dst
, target_ulong src1
,
1122 if (((src1
^ src2
^ -1) & (src1
^ dst
)) & (1ULL << 63)) {
1128 static uint32_t compute_all_add_xcc(void)
1132 ret
= get_NZ_xcc(CC_DST
);
1133 ret
|= get_C_add_xcc(CC_DST
, CC_SRC
);
1134 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1138 static uint32_t compute_C_add_xcc(void)
1140 return get_C_add_xcc(CC_DST
, CC_SRC
);
1144 static uint32_t compute_all_add(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
);
1154 static uint32_t compute_C_add(void)
1156 return get_C_add_icc(CC_DST
, CC_SRC
);
1159 #ifdef TARGET_SPARC64
1160 static uint32_t compute_all_addx_xcc(void)
1164 ret
= get_NZ_xcc(CC_DST
);
1165 ret
|= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1166 ret
|= get_V_add_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1170 static uint32_t compute_C_addx_xcc(void)
1174 ret
= get_C_addx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1179 static uint32_t compute_all_addx(void)
1183 ret
= get_NZ_icc(CC_DST
);
1184 ret
|= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1185 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1189 static uint32_t compute_C_addx(void)
1193 ret
= get_C_addx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1197 static inline uint32_t get_V_tag_icc(target_ulong src1
, target_ulong src2
)
1201 if ((src1
| src2
) & 0x3) {
1207 static uint32_t compute_all_tadd(void)
1211 ret
= get_NZ_icc(CC_DST
);
1212 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1213 ret
|= get_V_add_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1214 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1218 static uint32_t compute_all_taddtv(void)
1222 ret
= get_NZ_icc(CC_DST
);
1223 ret
|= get_C_add_icc(CC_DST
, CC_SRC
);
1227 static inline uint32_t get_C_sub_icc(uint32_t src1
, uint32_t src2
)
1237 static inline uint32_t get_C_subx_icc(uint32_t dst
, uint32_t src1
,
1242 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1U << 31)) {
1248 static inline uint32_t get_V_sub_icc(uint32_t dst
, uint32_t src1
,
1253 if (((src1
^ src2
) & (src1
^ dst
)) & (1U << 31)) {
1260 #ifdef TARGET_SPARC64
1261 static inline uint32_t get_C_sub_xcc(target_ulong src1
, target_ulong src2
)
1271 static inline uint32_t get_C_subx_xcc(target_ulong dst
, target_ulong src1
,
1276 if (((~src1
& src2
) | (dst
& (~src1
| src2
))) & (1ULL << 63)) {
1282 static inline uint32_t get_V_sub_xcc(target_ulong dst
, target_ulong src1
,
1287 if (((src1
^ src2
) & (src1
^ dst
)) & (1ULL << 63)) {
1293 static uint32_t compute_all_sub_xcc(void)
1297 ret
= get_NZ_xcc(CC_DST
);
1298 ret
|= get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1299 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1303 static uint32_t compute_C_sub_xcc(void)
1305 return get_C_sub_xcc(CC_SRC
, CC_SRC2
);
1309 static uint32_t compute_all_sub(void)
1313 ret
= get_NZ_icc(CC_DST
);
1314 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1315 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1319 static uint32_t compute_C_sub(void)
1321 return get_C_sub_icc(CC_SRC
, CC_SRC2
);
1324 #ifdef TARGET_SPARC64
1325 static uint32_t compute_all_subx_xcc(void)
1329 ret
= get_NZ_xcc(CC_DST
);
1330 ret
|= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1331 ret
|= get_V_sub_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1335 static uint32_t compute_C_subx_xcc(void)
1339 ret
= get_C_subx_xcc(CC_DST
, CC_SRC
, CC_SRC2
);
1344 static uint32_t compute_all_subx(void)
1348 ret
= get_NZ_icc(CC_DST
);
1349 ret
|= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1350 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1354 static uint32_t compute_C_subx(void)
1358 ret
= get_C_subx_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1362 static uint32_t compute_all_tsub(void)
1366 ret
= get_NZ_icc(CC_DST
);
1367 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1368 ret
|= get_V_sub_icc(CC_DST
, CC_SRC
, CC_SRC2
);
1369 ret
|= get_V_tag_icc(CC_SRC
, CC_SRC2
);
1373 static uint32_t compute_all_tsubtv(void)
1377 ret
= get_NZ_icc(CC_DST
);
1378 ret
|= get_C_sub_icc(CC_SRC
, CC_SRC2
);
1382 static uint32_t compute_all_logic(void)
1384 return get_NZ_icc(CC_DST
);
1387 static uint32_t compute_C_logic(void)
1392 #ifdef TARGET_SPARC64
1393 static uint32_t compute_all_logic_xcc(void)
1395 return get_NZ_xcc(CC_DST
);
1399 typedef struct CCTable
{
1400 uint32_t (*compute_all
)(void); /* return all the flags */
1401 uint32_t (*compute_c
)(void); /* return the C flag */
1404 static const CCTable icc_table
[CC_OP_NB
] = {
1405 /* CC_OP_DYNAMIC should never happen */
1406 [CC_OP_FLAGS
] = { compute_all_flags
, compute_C_flags
},
1407 [CC_OP_DIV
] = { compute_all_div
, compute_C_div
},
1408 [CC_OP_ADD
] = { compute_all_add
, compute_C_add
},
1409 [CC_OP_ADDX
] = { compute_all_addx
, compute_C_addx
},
1410 [CC_OP_TADD
] = { compute_all_tadd
, compute_C_add
},
1411 [CC_OP_TADDTV
] = { compute_all_taddtv
, compute_C_add
},
1412 [CC_OP_SUB
] = { compute_all_sub
, compute_C_sub
},
1413 [CC_OP_SUBX
] = { compute_all_subx
, compute_C_subx
},
1414 [CC_OP_TSUB
] = { compute_all_tsub
, compute_C_sub
},
1415 [CC_OP_TSUBTV
] = { compute_all_tsubtv
, compute_C_sub
},
1416 [CC_OP_LOGIC
] = { compute_all_logic
, compute_C_logic
},
1419 #ifdef TARGET_SPARC64
1420 static const CCTable xcc_table
[CC_OP_NB
] = {
1421 /* CC_OP_DYNAMIC should never happen */
1422 [CC_OP_FLAGS
] = { compute_all_flags_xcc
, compute_C_flags_xcc
},
1423 [CC_OP_DIV
] = { compute_all_logic_xcc
, compute_C_logic
},
1424 [CC_OP_ADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1425 [CC_OP_ADDX
] = { compute_all_addx_xcc
, compute_C_addx_xcc
},
1426 [CC_OP_TADD
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1427 [CC_OP_TADDTV
] = { compute_all_add_xcc
, compute_C_add_xcc
},
1428 [CC_OP_SUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1429 [CC_OP_SUBX
] = { compute_all_subx_xcc
, compute_C_subx_xcc
},
1430 [CC_OP_TSUB
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1431 [CC_OP_TSUBTV
] = { compute_all_sub_xcc
, compute_C_sub_xcc
},
1432 [CC_OP_LOGIC
] = { compute_all_logic_xcc
, compute_C_logic
},
1436 void helper_compute_psr(void)
1440 new_psr
= icc_table
[CC_OP
].compute_all();
1442 #ifdef TARGET_SPARC64
1443 new_psr
= xcc_table
[CC_OP
].compute_all();
1446 CC_OP
= CC_OP_FLAGS
;
1449 uint32_t helper_compute_C_icc(void)
1453 ret
= icc_table
[CC_OP
].compute_c() >> PSR_CARRY_SHIFT
;
1457 static inline void memcpy32(target_ulong
*dst
, const target_ulong
*src
)
1469 static void set_cwp(int new_cwp
)
1471 /* put the modified wrap registers at their proper location */
1472 if (env
->cwp
== env
->nwindows
- 1) {
1473 memcpy32(env
->regbase
, env
->regbase
+ env
->nwindows
* 16);
1477 /* put the wrap registers at their temporary location */
1478 if (new_cwp
== env
->nwindows
- 1) {
1479 memcpy32(env
->regbase
+ env
->nwindows
* 16, env
->regbase
);
1481 env
->regwptr
= env
->regbase
+ (new_cwp
* 16);
1484 void cpu_set_cwp(CPUState
*env1
, int new_cwp
)
1486 CPUState
*saved_env
;
1494 static target_ulong
get_psr(void)
1496 helper_compute_psr();
1498 #if !defined (TARGET_SPARC64)
1499 return env
->version
| (env
->psr
& PSR_ICC
) |
1500 (env
->psref
? PSR_EF
: 0) |
1501 (env
->psrpil
<< 8) |
1502 (env
->psrs
? PSR_S
: 0) |
1503 (env
->psrps
? PSR_PS
: 0) |
1504 (env
->psret
? PSR_ET
: 0) | env
->cwp
;
1506 return env
->psr
& PSR_ICC
;
1510 target_ulong
cpu_get_psr(CPUState
*env1
)
1512 CPUState
*saved_env
;
1522 static void put_psr(target_ulong val
)
1524 env
->psr
= val
& PSR_ICC
;
1525 #if !defined (TARGET_SPARC64)
1526 env
->psref
= (val
& PSR_EF
)? 1 : 0;
1527 env
->psrpil
= (val
& PSR_PIL
) >> 8;
1529 #if ((!defined (TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
1530 cpu_check_irqs(env
);
1532 #if !defined (TARGET_SPARC64)
1533 env
->psrs
= (val
& PSR_S
)? 1 : 0;
1534 env
->psrps
= (val
& PSR_PS
)? 1 : 0;
1535 env
->psret
= (val
& PSR_ET
)? 1 : 0;
1536 set_cwp(val
& PSR_CWP
);
1538 env
->cc_op
= CC_OP_FLAGS
;
1541 void cpu_put_psr(CPUState
*env1
, target_ulong val
)
1543 CPUState
*saved_env
;
1551 static int cwp_inc(int cwp
)
1553 if (unlikely(cwp
>= env
->nwindows
)) {
1554 cwp
-= env
->nwindows
;
1559 int cpu_cwp_inc(CPUState
*env1
, int cwp
)
1561 CPUState
*saved_env
;
1571 static int cwp_dec(int cwp
)
1573 if (unlikely(cwp
< 0)) {
1574 cwp
+= env
->nwindows
;
1579 int cpu_cwp_dec(CPUState
*env1
, int cwp
)
1581 CPUState
*saved_env
;
1591 #ifdef TARGET_SPARC64
1592 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
1593 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
1594 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
1596 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
1597 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
1598 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
1600 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
1601 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
1602 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
1604 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
1605 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
1606 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
1608 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
1609 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
1610 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
1612 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
1613 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
1614 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
1618 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
1620 static void dump_mxcc(CPUState
*env
)
1622 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1624 env
->mxccdata
[0], env
->mxccdata
[1],
1625 env
->mxccdata
[2], env
->mxccdata
[3]);
1626 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1628 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
1630 env
->mxccregs
[0], env
->mxccregs
[1],
1631 env
->mxccregs
[2], env
->mxccregs
[3],
1632 env
->mxccregs
[4], env
->mxccregs
[5],
1633 env
->mxccregs
[6], env
->mxccregs
[7]);
1637 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
1638 && defined(DEBUG_ASI)
1639 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
1645 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
1646 addr
, asi
, r1
& 0xff);
1649 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
1650 addr
, asi
, r1
& 0xffff);
1653 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
1654 addr
, asi
, r1
& 0xffffffff);
1657 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
1664 #ifndef TARGET_SPARC64
1665 #ifndef CONFIG_USER_ONLY
1668 /* Leon3 cache control */
1670 static void leon3_cache_control_int(void)
1674 if (env
->cache_control
& CACHE_CTRL_IF
) {
1675 /* Instruction cache state */
1676 state
= env
->cache_control
& CACHE_STATE_MASK
;
1677 if (state
== CACHE_ENABLED
) {
1678 state
= CACHE_FROZEN
;
1679 DPRINTF_CACHE_CONTROL("Instruction cache: freeze\n");
1682 env
->cache_control
&= ~CACHE_STATE_MASK
;
1683 env
->cache_control
|= state
;
1686 if (env
->cache_control
& CACHE_CTRL_DF
) {
1687 /* Data cache state */
1688 state
= (env
->cache_control
>> 2) & CACHE_STATE_MASK
;
1689 if (state
== CACHE_ENABLED
) {
1690 state
= CACHE_FROZEN
;
1691 DPRINTF_CACHE_CONTROL("Data cache: freeze\n");
1694 env
->cache_control
&= ~(CACHE_STATE_MASK
<< 2);
1695 env
->cache_control
|= (state
<< 2);
1699 static void leon3_cache_control_st(target_ulong addr
, uint64_t val
, int size
)
1701 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
1705 DPRINTF_CACHE_CONTROL("32bits only\n");
1710 case 0x00: /* Cache control */
1712 /* These values must always be read as zeros */
1713 val
&= ~CACHE_CTRL_FD
;
1714 val
&= ~CACHE_CTRL_FI
;
1715 val
&= ~CACHE_CTRL_IB
;
1716 val
&= ~CACHE_CTRL_IP
;
1717 val
&= ~CACHE_CTRL_DP
;
1719 env
->cache_control
= val
;
1721 case 0x04: /* Instruction cache configuration */
1722 case 0x08: /* Data cache configuration */
1726 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
1731 static uint64_t leon3_cache_control_ld(target_ulong addr
, int size
)
1736 DPRINTF_CACHE_CONTROL("32bits only\n");
1741 case 0x00: /* Cache control */
1742 ret
= env
->cache_control
;
1745 /* Configuration registers are read and only always keep those
1746 predefined values */
1748 case 0x04: /* Instruction cache configuration */
1751 case 0x08: /* Data cache configuration */
1755 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
1758 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
1763 void leon3_irq_manager(void *irq_manager
, int intno
)
1765 leon3_irq_ack(irq_manager
, intno
);
1766 leon3_cache_control_int();
1769 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1772 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
1773 uint32_t last_addr
= addr
;
1776 helper_check_align(addr
, size
- 1);
1778 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
1780 case 0x00: /* Leon3 Cache Control */
1781 case 0x08: /* Leon3 Instruction Cache config */
1782 case 0x0C: /* Leon3 Date Cache config */
1783 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
1784 ret
= leon3_cache_control_ld(addr
, size
);
1787 case 0x01c00a00: /* MXCC control register */
1789 ret
= env
->mxccregs
[3];
1791 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1794 case 0x01c00a04: /* MXCC control register */
1796 ret
= env
->mxccregs
[3];
1798 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1801 case 0x01c00c00: /* Module reset register */
1803 ret
= env
->mxccregs
[5];
1804 // should we do something here?
1806 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1809 case 0x01c00f00: /* MBus port address register */
1811 ret
= env
->mxccregs
[7];
1813 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1817 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1821 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
1822 "addr = %08x -> ret = %" PRIx64
","
1823 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
1828 case 3: /* MMU probe */
1832 mmulev
= (addr
>> 8) & 15;
1836 ret
= mmu_probe(env
, addr
, mmulev
);
1837 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
1841 case 4: /* read MMU regs */
1843 int reg
= (addr
>> 8) & 0x1f;
1845 ret
= env
->mmuregs
[reg
];
1846 if (reg
== 3) /* Fault status cleared on read */
1847 env
->mmuregs
[3] = 0;
1848 else if (reg
== 0x13) /* Fault status read */
1849 ret
= env
->mmuregs
[3];
1850 else if (reg
== 0x14) /* Fault address read */
1851 ret
= env
->mmuregs
[4];
1852 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
1855 case 5: // Turbosparc ITLB Diagnostic
1856 case 6: // Turbosparc DTLB Diagnostic
1857 case 7: // Turbosparc IOTLB Diagnostic
1859 case 9: /* Supervisor code access */
1862 ret
= ldub_code(addr
);
1865 ret
= lduw_code(addr
);
1869 ret
= ldl_code(addr
);
1872 ret
= ldq_code(addr
);
1876 case 0xa: /* User data access */
1879 ret
= ldub_user(addr
);
1882 ret
= lduw_user(addr
);
1886 ret
= ldl_user(addr
);
1889 ret
= ldq_user(addr
);
1893 case 0xb: /* Supervisor data access */
1896 ret
= ldub_kernel(addr
);
1899 ret
= lduw_kernel(addr
);
1903 ret
= ldl_kernel(addr
);
1906 ret
= ldq_kernel(addr
);
1910 case 0xc: /* I-cache tag */
1911 case 0xd: /* I-cache data */
1912 case 0xe: /* D-cache tag */
1913 case 0xf: /* D-cache data */
1915 case 0x20: /* MMU passthrough */
1918 ret
= ldub_phys(addr
);
1921 ret
= lduw_phys(addr
);
1925 ret
= ldl_phys(addr
);
1928 ret
= ldq_phys(addr
);
1932 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1935 ret
= ldub_phys((target_phys_addr_t
)addr
1936 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1939 ret
= lduw_phys((target_phys_addr_t
)addr
1940 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1944 ret
= ldl_phys((target_phys_addr_t
)addr
1945 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1948 ret
= ldq_phys((target_phys_addr_t
)addr
1949 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1953 case 0x30: // Turbosparc secondary cache diagnostic
1954 case 0x31: // Turbosparc RAM snoop
1955 case 0x32: // Turbosparc page table descriptor diagnostic
1956 case 0x39: /* data cache diagnostic register */
1959 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
1961 int reg
= (addr
>> 8) & 3;
1964 case 0: /* Breakpoint Value (Addr) */
1965 ret
= env
->mmubpregs
[reg
];
1967 case 1: /* Breakpoint Mask */
1968 ret
= env
->mmubpregs
[reg
];
1970 case 2: /* Breakpoint Control */
1971 ret
= env
->mmubpregs
[reg
];
1973 case 3: /* Breakpoint Status */
1974 ret
= env
->mmubpregs
[reg
];
1975 env
->mmubpregs
[reg
] = 0ULL;
1978 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
1982 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1983 ret
= env
->mmubpctrv
;
1985 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1986 ret
= env
->mmubpctrc
;
1988 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1989 ret
= env
->mmubpctrs
;
1991 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1992 ret
= env
->mmubpaction
;
1994 case 8: /* User code access, XXX */
1996 do_unassigned_access(addr
, 0, 0, asi
, size
);
2006 ret
= (int16_t) ret
;
2009 ret
= (int32_t) ret
;
2016 dump_asi("read ", last_addr
, asi
, size
, ret
);
2021 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
2023 helper_check_align(addr
, size
- 1);
2025 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
2027 case 0x00: /* Leon3 Cache Control */
2028 case 0x08: /* Leon3 Instruction Cache config */
2029 case 0x0C: /* Leon3 Date Cache config */
2030 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
2031 leon3_cache_control_st(addr
, val
, size
);
2035 case 0x01c00000: /* MXCC stream data register 0 */
2037 env
->mxccdata
[0] = val
;
2039 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2042 case 0x01c00008: /* MXCC stream data register 1 */
2044 env
->mxccdata
[1] = val
;
2046 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2049 case 0x01c00010: /* MXCC stream data register 2 */
2051 env
->mxccdata
[2] = val
;
2053 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2056 case 0x01c00018: /* MXCC stream data register 3 */
2058 env
->mxccdata
[3] = val
;
2060 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2063 case 0x01c00100: /* MXCC stream source */
2065 env
->mxccregs
[0] = val
;
2067 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2069 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2071 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2073 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2075 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
2078 case 0x01c00200: /* MXCC stream destination */
2080 env
->mxccregs
[1] = val
;
2082 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2084 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
2086 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
2088 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
2090 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
2093 case 0x01c00a00: /* MXCC control register */
2095 env
->mxccregs
[3] = val
;
2097 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2100 case 0x01c00a04: /* MXCC control register */
2102 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
2105 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2108 case 0x01c00e00: /* MXCC error register */
2109 // writing a 1 bit clears the error
2111 env
->mxccregs
[6] &= ~val
;
2113 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2116 case 0x01c00f00: /* MBus port address register */
2118 env
->mxccregs
[7] = val
;
2120 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
2124 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
2128 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
2129 asi
, size
, addr
, val
);
2134 case 3: /* MMU flush */
2138 mmulev
= (addr
>> 8) & 15;
2139 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
2141 case 0: // flush page
2142 tlb_flush_page(env
, addr
& 0xfffff000);
2144 case 1: // flush segment (256k)
2145 case 2: // flush region (16M)
2146 case 3: // flush context (4G)
2147 case 4: // flush entire
2154 dump_mmu(stdout
, fprintf
, env
);
2158 case 4: /* write MMU regs */
2160 int reg
= (addr
>> 8) & 0x1f;
2163 oldreg
= env
->mmuregs
[reg
];
2165 case 0: // Control Register
2166 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
2168 // Mappings generated during no-fault mode or MMU
2169 // disabled mode are invalid in normal mode
2170 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
2171 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
2174 case 1: // Context Table Pointer Register
2175 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
2177 case 2: // Context Register
2178 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
2179 if (oldreg
!= env
->mmuregs
[reg
]) {
2180 /* we flush when the MMU context changes because
2181 QEMU has no MMU context support */
2185 case 3: // Synchronous Fault Status Register with Clear
2186 case 4: // Synchronous Fault Address Register
2188 case 0x10: // TLB Replacement Control Register
2189 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
2191 case 0x13: // Synchronous Fault Status Register with Read and Clear
2192 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
2194 case 0x14: // Synchronous Fault Address Register
2195 env
->mmuregs
[4] = val
;
2198 env
->mmuregs
[reg
] = val
;
2201 if (oldreg
!= env
->mmuregs
[reg
]) {
2202 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
2203 reg
, oldreg
, env
->mmuregs
[reg
]);
2206 dump_mmu(stdout
, fprintf
, env
);
2210 case 5: // Turbosparc ITLB Diagnostic
2211 case 6: // Turbosparc DTLB Diagnostic
2212 case 7: // Turbosparc IOTLB Diagnostic
2214 case 0xa: /* User data access */
2217 stb_user(addr
, val
);
2220 stw_user(addr
, val
);
2224 stl_user(addr
, val
);
2227 stq_user(addr
, val
);
2231 case 0xb: /* Supervisor data access */
2234 stb_kernel(addr
, val
);
2237 stw_kernel(addr
, val
);
2241 stl_kernel(addr
, val
);
2244 stq_kernel(addr
, val
);
2248 case 0xc: /* I-cache tag */
2249 case 0xd: /* I-cache data */
2250 case 0xe: /* D-cache tag */
2251 case 0xf: /* D-cache data */
2252 case 0x10: /* I/D-cache flush page */
2253 case 0x11: /* I/D-cache flush segment */
2254 case 0x12: /* I/D-cache flush region */
2255 case 0x13: /* I/D-cache flush context */
2256 case 0x14: /* I/D-cache flush user */
2258 case 0x17: /* Block copy, sta access */
2264 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
2266 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
2267 temp
= ldl_kernel(src
);
2268 stl_kernel(dst
, temp
);
2272 case 0x1f: /* Block fill, stda access */
2275 // fill 32 bytes with val
2277 uint32_t dst
= addr
& 7;
2279 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
2280 stq_kernel(dst
, val
);
2283 case 0x20: /* MMU passthrough */
2287 stb_phys(addr
, val
);
2290 stw_phys(addr
, val
);
2294 stl_phys(addr
, val
);
2297 stq_phys(addr
, val
);
2302 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
2306 stb_phys((target_phys_addr_t
)addr
2307 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2310 stw_phys((target_phys_addr_t
)addr
2311 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2315 stl_phys((target_phys_addr_t
)addr
2316 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2319 stq_phys((target_phys_addr_t
)addr
2320 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
2325 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
2326 case 0x31: // store buffer data, Ross RT620 I-cache flush or
2327 // Turbosparc snoop RAM
2328 case 0x32: // store buffer control or Turbosparc page table
2329 // descriptor diagnostic
2330 case 0x36: /* I-cache flash clear */
2331 case 0x37: /* D-cache flash clear */
2333 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
2335 int reg
= (addr
>> 8) & 3;
2338 case 0: /* Breakpoint Value (Addr) */
2339 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2341 case 1: /* Breakpoint Mask */
2342 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
2344 case 2: /* Breakpoint Control */
2345 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
2347 case 3: /* Breakpoint Status */
2348 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
2351 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
2355 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
2356 env
->mmubpctrv
= val
& 0xffffffff;
2358 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
2359 env
->mmubpctrc
= val
& 0x3;
2361 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
2362 env
->mmubpctrs
= val
& 0x3;
2364 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
2365 env
->mmubpaction
= val
& 0x1fff;
2367 case 8: /* User code access, XXX */
2368 case 9: /* Supervisor code access, XXX */
2370 do_unassigned_access(addr
, 1, 0, asi
, size
);
2374 dump_asi("write", addr
, asi
, size
, val
);
2378 #endif /* CONFIG_USER_ONLY */
2379 #else /* TARGET_SPARC64 */
2381 #ifdef CONFIG_USER_ONLY
2382 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2385 #if defined(DEBUG_ASI)
2386 target_ulong last_addr
= addr
;
2390 raise_exception(TT_PRIV_ACT
);
2392 helper_check_align(addr
, size
- 1);
2393 addr
= asi_address_mask(env
, asi
, addr
);
2396 case 0x82: // Primary no-fault
2397 case 0x8a: // Primary no-fault LE
2398 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2400 dump_asi("read ", last_addr
, asi
, size
, ret
);
2405 case 0x80: // Primary
2406 case 0x88: // Primary LE
2410 ret
= ldub_raw(addr
);
2413 ret
= lduw_raw(addr
);
2416 ret
= ldl_raw(addr
);
2420 ret
= ldq_raw(addr
);
2425 case 0x83: // Secondary no-fault
2426 case 0x8b: // Secondary no-fault LE
2427 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
2429 dump_asi("read ", last_addr
, asi
, size
, ret
);
2434 case 0x81: // Secondary
2435 case 0x89: // Secondary LE
2442 /* Convert from little endian */
2444 case 0x88: // Primary LE
2445 case 0x89: // Secondary LE
2446 case 0x8a: // Primary no-fault LE
2447 case 0x8b: // Secondary no-fault LE
2465 /* Convert to signed number */
2472 ret
= (int16_t) ret
;
2475 ret
= (int32_t) ret
;
2482 dump_asi("read ", last_addr
, asi
, size
, ret
);
2487 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2490 dump_asi("write", addr
, asi
, size
, val
);
2493 raise_exception(TT_PRIV_ACT
);
2495 helper_check_align(addr
, size
- 1);
2496 addr
= asi_address_mask(env
, asi
, addr
);
2498 /* Convert to little endian */
2500 case 0x88: // Primary LE
2501 case 0x89: // Secondary LE
2520 case 0x80: // Primary
2521 case 0x88: // Primary LE
2540 case 0x81: // Secondary
2541 case 0x89: // Secondary LE
2545 case 0x82: // Primary no-fault, RO
2546 case 0x83: // Secondary no-fault, RO
2547 case 0x8a: // Primary no-fault LE, RO
2548 case 0x8b: // Secondary no-fault LE, RO
2550 do_unassigned_access(addr
, 1, 0, 1, size
);
2555 #else /* CONFIG_USER_ONLY */
2557 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
2560 #if defined(DEBUG_ASI)
2561 target_ulong last_addr
= addr
;
2566 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2567 || (cpu_has_hypervisor(env
)
2568 && asi
>= 0x30 && asi
< 0x80
2569 && !(env
->hpstate
& HS_PRIV
)))
2570 raise_exception(TT_PRIV_ACT
);
2572 helper_check_align(addr
, size
- 1);
2573 addr
= asi_address_mask(env
, asi
, addr
);
2575 /* process nonfaulting loads first */
2576 if ((asi
& 0xf6) == 0x82) {
2579 /* secondary space access has lowest asi bit equal to 1 */
2580 if (env
->pstate
& PS_PRIV
) {
2581 mmu_idx
= (asi
& 1) ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
;
2583 mmu_idx
= (asi
& 1) ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
;
2586 if (cpu_get_phys_page_nofault(env
, addr
, mmu_idx
) == -1ULL) {
2588 dump_asi("read ", last_addr
, asi
, size
, ret
);
2590 /* env->exception_index is set in get_physical_address_data(). */
2591 raise_exception(env
->exception_index
);
2594 /* convert nonfaulting load ASIs to normal load ASIs */
2599 case 0x10: // As if user primary
2600 case 0x11: // As if user secondary
2601 case 0x18: // As if user primary LE
2602 case 0x19: // As if user secondary LE
2603 case 0x80: // Primary
2604 case 0x81: // Secondary
2605 case 0x88: // Primary LE
2606 case 0x89: // Secondary LE
2607 case 0xe2: // UA2007 Primary block init
2608 case 0xe3: // UA2007 Secondary block init
2609 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2610 if (cpu_hypervisor_mode(env
)) {
2613 ret
= ldub_hypv(addr
);
2616 ret
= lduw_hypv(addr
);
2619 ret
= ldl_hypv(addr
);
2623 ret
= ldq_hypv(addr
);
2627 /* secondary space access has lowest asi bit equal to 1 */
2631 ret
= ldub_kernel_secondary(addr
);
2634 ret
= lduw_kernel_secondary(addr
);
2637 ret
= ldl_kernel_secondary(addr
);
2641 ret
= ldq_kernel_secondary(addr
);
2647 ret
= ldub_kernel(addr
);
2650 ret
= lduw_kernel(addr
);
2653 ret
= ldl_kernel(addr
);
2657 ret
= ldq_kernel(addr
);
2663 /* secondary space access has lowest asi bit equal to 1 */
2667 ret
= ldub_user_secondary(addr
);
2670 ret
= lduw_user_secondary(addr
);
2673 ret
= ldl_user_secondary(addr
);
2677 ret
= ldq_user_secondary(addr
);
2683 ret
= ldub_user(addr
);
2686 ret
= lduw_user(addr
);
2689 ret
= ldl_user(addr
);
2693 ret
= ldq_user(addr
);
2699 case 0x14: // Bypass
2700 case 0x15: // Bypass, non-cacheable
2701 case 0x1c: // Bypass LE
2702 case 0x1d: // Bypass, non-cacheable LE
2706 ret
= ldub_phys(addr
);
2709 ret
= lduw_phys(addr
);
2712 ret
= ldl_phys(addr
);
2716 ret
= ldq_phys(addr
);
2721 case 0x24: // Nucleus quad LDD 128 bit atomic
2722 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2723 // Only ldda allowed
2724 raise_exception(TT_ILL_INSN
);
2726 case 0x04: // Nucleus
2727 case 0x0c: // Nucleus Little Endian (LE)
2731 ret
= ldub_nucleus(addr
);
2734 ret
= lduw_nucleus(addr
);
2737 ret
= ldl_nucleus(addr
);
2741 ret
= ldq_nucleus(addr
);
2746 case 0x4a: // UPA config
2752 case 0x50: // I-MMU regs
2754 int reg
= (addr
>> 3) & 0xf;
2757 // I-TSB Tag Target register
2758 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
2760 ret
= env
->immuregs
[reg
];
2765 case 0x51: // I-MMU 8k TSB pointer
2767 // env->immuregs[5] holds I-MMU TSB register value
2768 // env->immuregs[6] holds I-MMU Tag Access register value
2769 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2773 case 0x52: // I-MMU 64k TSB pointer
2775 // env->immuregs[5] holds I-MMU TSB register value
2776 // env->immuregs[6] holds I-MMU Tag Access register value
2777 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
2781 case 0x55: // I-MMU data access
2783 int reg
= (addr
>> 3) & 0x3f;
2785 ret
= env
->itlb
[reg
].tte
;
2788 case 0x56: // I-MMU tag read
2790 int reg
= (addr
>> 3) & 0x3f;
2792 ret
= env
->itlb
[reg
].tag
;
2795 case 0x58: // D-MMU regs
2797 int reg
= (addr
>> 3) & 0xf;
2800 // D-TSB Tag Target register
2801 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
2803 ret
= env
->dmmuregs
[reg
];
2807 case 0x59: // D-MMU 8k TSB pointer
2809 // env->dmmuregs[5] holds D-MMU TSB register value
2810 // env->dmmuregs[6] holds D-MMU Tag Access register value
2811 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2815 case 0x5a: // D-MMU 64k TSB pointer
2817 // env->dmmuregs[5] holds D-MMU TSB register value
2818 // env->dmmuregs[6] holds D-MMU Tag Access register value
2819 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
2823 case 0x5d: // D-MMU data access
2825 int reg
= (addr
>> 3) & 0x3f;
2827 ret
= env
->dtlb
[reg
].tte
;
2830 case 0x5e: // D-MMU tag read
2832 int reg
= (addr
>> 3) & 0x3f;
2834 ret
= env
->dtlb
[reg
].tag
;
2837 case 0x46: // D-cache data
2838 case 0x47: // D-cache tag access
2839 case 0x4b: // E-cache error enable
2840 case 0x4c: // E-cache asynchronous fault status
2841 case 0x4d: // E-cache asynchronous fault address
2842 case 0x4e: // E-cache tag data
2843 case 0x66: // I-cache instruction access
2844 case 0x67: // I-cache tag access
2845 case 0x6e: // I-cache predecode
2846 case 0x6f: // I-cache LRU etc.
2847 case 0x76: // E-cache tag
2848 case 0x7e: // E-cache tag
2850 case 0x5b: // D-MMU data pointer
2851 case 0x48: // Interrupt dispatch, RO
2852 case 0x49: // Interrupt data receive
2853 case 0x7f: // Incoming interrupt vector, RO
2856 case 0x54: // I-MMU data in, WO
2857 case 0x57: // I-MMU demap, WO
2858 case 0x5c: // D-MMU data in, WO
2859 case 0x5f: // D-MMU demap, WO
2860 case 0x77: // Interrupt vector, WO
2862 do_unassigned_access(addr
, 0, 0, 1, size
);
2867 /* Convert from little endian */
2869 case 0x0c: // Nucleus Little Endian (LE)
2870 case 0x18: // As if user primary LE
2871 case 0x19: // As if user secondary LE
2872 case 0x1c: // Bypass LE
2873 case 0x1d: // Bypass, non-cacheable LE
2874 case 0x88: // Primary LE
2875 case 0x89: // Secondary LE
2893 /* Convert to signed number */
2900 ret
= (int16_t) ret
;
2903 ret
= (int32_t) ret
;
2910 dump_asi("read ", last_addr
, asi
, size
, ret
);
2915 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
2918 dump_asi("write", addr
, asi
, size
, val
);
2923 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2924 || (cpu_has_hypervisor(env
)
2925 && asi
>= 0x30 && asi
< 0x80
2926 && !(env
->hpstate
& HS_PRIV
)))
2927 raise_exception(TT_PRIV_ACT
);
2929 helper_check_align(addr
, size
- 1);
2930 addr
= asi_address_mask(env
, asi
, addr
);
2932 /* Convert to little endian */
2934 case 0x0c: // Nucleus Little Endian (LE)
2935 case 0x18: // As if user primary LE
2936 case 0x19: // As if user secondary LE
2937 case 0x1c: // Bypass LE
2938 case 0x1d: // Bypass, non-cacheable LE
2939 case 0x88: // Primary LE
2940 case 0x89: // Secondary LE
2959 case 0x10: // As if user primary
2960 case 0x11: // As if user secondary
2961 case 0x18: // As if user primary LE
2962 case 0x19: // As if user secondary LE
2963 case 0x80: // Primary
2964 case 0x81: // Secondary
2965 case 0x88: // Primary LE
2966 case 0x89: // Secondary LE
2967 case 0xe2: // UA2007 Primary block init
2968 case 0xe3: // UA2007 Secondary block init
2969 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
2970 if (cpu_hypervisor_mode(env
)) {
2973 stb_hypv(addr
, val
);
2976 stw_hypv(addr
, val
);
2979 stl_hypv(addr
, val
);
2983 stq_hypv(addr
, val
);
2987 /* secondary space access has lowest asi bit equal to 1 */
2991 stb_kernel_secondary(addr
, val
);
2994 stw_kernel_secondary(addr
, val
);
2997 stl_kernel_secondary(addr
, val
);
3001 stq_kernel_secondary(addr
, val
);
3007 stb_kernel(addr
, val
);
3010 stw_kernel(addr
, val
);
3013 stl_kernel(addr
, val
);
3017 stq_kernel(addr
, val
);
3023 /* secondary space access has lowest asi bit equal to 1 */
3027 stb_user_secondary(addr
, val
);
3030 stw_user_secondary(addr
, val
);
3033 stl_user_secondary(addr
, val
);
3037 stq_user_secondary(addr
, val
);
3043 stb_user(addr
, val
);
3046 stw_user(addr
, val
);
3049 stl_user(addr
, val
);
3053 stq_user(addr
, val
);
3059 case 0x14: // Bypass
3060 case 0x15: // Bypass, non-cacheable
3061 case 0x1c: // Bypass LE
3062 case 0x1d: // Bypass, non-cacheable LE
3066 stb_phys(addr
, val
);
3069 stw_phys(addr
, val
);
3072 stl_phys(addr
, val
);
3076 stq_phys(addr
, val
);
3081 case 0x24: // Nucleus quad LDD 128 bit atomic
3082 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
3083 // Only ldda allowed
3084 raise_exception(TT_ILL_INSN
);
3086 case 0x04: // Nucleus
3087 case 0x0c: // Nucleus Little Endian (LE)
3091 stb_nucleus(addr
, val
);
3094 stw_nucleus(addr
, val
);
3097 stl_nucleus(addr
, val
);
3101 stq_nucleus(addr
, val
);
3107 case 0x4a: // UPA config
3115 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
3116 // Mappings generated during D/I MMU disabled mode are
3117 // invalid in normal mode
3118 if (oldreg
!= env
->lsu
) {
3119 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
3122 dump_mmu(stdout
, fprintf
, env1
);
3128 case 0x50: // I-MMU regs
3130 int reg
= (addr
>> 3) & 0xf;
3133 oldreg
= env
->immuregs
[reg
];
3137 case 1: // Not in I-MMU
3142 val
= 0; // Clear SFSR
3143 env
->immu
.sfsr
= val
;
3147 case 5: // TSB access
3148 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
3149 PRIx64
"\n", env
->immu
.tsb
, val
);
3150 env
->immu
.tsb
= val
;
3152 case 6: // Tag access
3153 env
->immu
.tag_access
= val
;
3162 if (oldreg
!= env
->immuregs
[reg
]) {
3163 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
3164 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
3167 dump_mmu(stdout
, fprintf
, env
);
3171 case 0x54: // I-MMU data in
3172 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
3174 case 0x55: // I-MMU data access
3178 unsigned int i
= (addr
>> 3) & 0x3f;
3180 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
3183 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
3184 dump_mmu(stdout
, fprintf
, env
);
3188 case 0x57: // I-MMU demap
3189 demap_tlb(env
->itlb
, addr
, "immu", env
);
3191 case 0x58: // D-MMU regs
3193 int reg
= (addr
>> 3) & 0xf;
3196 oldreg
= env
->dmmuregs
[reg
];
3202 if ((val
& 1) == 0) {
3203 val
= 0; // Clear SFSR, Fault address
3206 env
->dmmu
.sfsr
= val
;
3208 case 1: // Primary context
3209 env
->dmmu
.mmu_primary_context
= val
;
3210 /* can be optimized to only flush MMU_USER_IDX
3211 and MMU_KERNEL_IDX entries */
3214 case 2: // Secondary context
3215 env
->dmmu
.mmu_secondary_context
= val
;
3216 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
3217 and MMU_KERNEL_SECONDARY_IDX entries */
3220 case 5: // TSB access
3221 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
3222 PRIx64
"\n", env
->dmmu
.tsb
, val
);
3223 env
->dmmu
.tsb
= val
;
3225 case 6: // Tag access
3226 env
->dmmu
.tag_access
= val
;
3228 case 7: // Virtual Watchpoint
3229 case 8: // Physical Watchpoint
3231 env
->dmmuregs
[reg
] = val
;
3235 if (oldreg
!= env
->dmmuregs
[reg
]) {
3236 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
3237 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
3240 dump_mmu(stdout
, fprintf
, env
);
3244 case 0x5c: // D-MMU data in
3245 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
3247 case 0x5d: // D-MMU data access
3249 unsigned int i
= (addr
>> 3) & 0x3f;
3251 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
3254 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
3255 dump_mmu(stdout
, fprintf
, env
);
3259 case 0x5f: // D-MMU demap
3260 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
3262 case 0x49: // Interrupt data receive
3265 case 0x46: // D-cache data
3266 case 0x47: // D-cache tag access
3267 case 0x4b: // E-cache error enable
3268 case 0x4c: // E-cache asynchronous fault status
3269 case 0x4d: // E-cache asynchronous fault address
3270 case 0x4e: // E-cache tag data
3271 case 0x66: // I-cache instruction access
3272 case 0x67: // I-cache tag access
3273 case 0x6e: // I-cache predecode
3274 case 0x6f: // I-cache LRU etc.
3275 case 0x76: // E-cache tag
3276 case 0x7e: // E-cache tag
3278 case 0x51: // I-MMU 8k TSB pointer, RO
3279 case 0x52: // I-MMU 64k TSB pointer, RO
3280 case 0x56: // I-MMU tag read, RO
3281 case 0x59: // D-MMU 8k TSB pointer, RO
3282 case 0x5a: // D-MMU 64k TSB pointer, RO
3283 case 0x5b: // D-MMU data pointer, RO
3284 case 0x5e: // D-MMU tag read, RO
3285 case 0x48: // Interrupt dispatch, RO
3286 case 0x7f: // Incoming interrupt vector, RO
3287 case 0x82: // Primary no-fault, RO
3288 case 0x83: // Secondary no-fault, RO
3289 case 0x8a: // Primary no-fault LE, RO
3290 case 0x8b: // Secondary no-fault LE, RO
3292 do_unassigned_access(addr
, 1, 0, 1, size
);
3296 #endif /* CONFIG_USER_ONLY */
3298 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
3300 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
3301 || (cpu_has_hypervisor(env
)
3302 && asi
>= 0x30 && asi
< 0x80
3303 && !(env
->hpstate
& HS_PRIV
)))
3304 raise_exception(TT_PRIV_ACT
);
3306 addr
= asi_address_mask(env
, asi
, addr
);
3309 #if !defined(CONFIG_USER_ONLY)
3310 case 0x24: // Nucleus quad LDD 128 bit atomic
3311 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
3312 helper_check_align(addr
, 0xf);
3314 env
->gregs
[1] = ldq_nucleus(addr
+ 8);
3316 bswap64s(&env
->gregs
[1]);
3317 } else if (rd
< 8) {
3318 env
->gregs
[rd
] = ldq_nucleus(addr
);
3319 env
->gregs
[rd
+ 1] = ldq_nucleus(addr
+ 8);
3321 bswap64s(&env
->gregs
[rd
]);
3322 bswap64s(&env
->gregs
[rd
+ 1]);
3325 env
->regwptr
[rd
] = ldq_nucleus(addr
);
3326 env
->regwptr
[rd
+ 1] = ldq_nucleus(addr
+ 8);
3328 bswap64s(&env
->regwptr
[rd
]);
3329 bswap64s(&env
->regwptr
[rd
+ 1]);
3335 helper_check_align(addr
, 0x3);
3337 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3339 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3340 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3342 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
3343 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
3349 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3354 helper_check_align(addr
, 3);
3355 addr
= asi_address_mask(env
, asi
, addr
);
3358 case 0xf0: /* UA2007/JPS1 Block load primary */
3359 case 0xf1: /* UA2007/JPS1 Block load secondary */
3360 case 0xf8: /* UA2007/JPS1 Block load primary LE */
3361 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
3363 raise_exception(TT_ILL_INSN
);
3366 helper_check_align(addr
, 0x3f);
3367 for (i
= 0; i
< 16; i
++) {
3368 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
3374 case 0x16: /* UA2007 Block load primary, user privilege */
3375 case 0x17: /* UA2007 Block load secondary, user privilege */
3376 case 0x1e: /* UA2007 Block load primary LE, user privilege */
3377 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
3378 case 0x70: /* JPS1 Block load primary, user privilege */
3379 case 0x71: /* JPS1 Block load secondary, user privilege */
3380 case 0x78: /* JPS1 Block load primary LE, user privilege */
3381 case 0x79: /* JPS1 Block load secondary LE, user privilege */
3383 raise_exception(TT_ILL_INSN
);
3386 helper_check_align(addr
, 0x3f);
3387 for (i
= 0; i
< 16; i
++) {
3388 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x19, 4,
3401 *((uint32_t *)&env
->fpr
[rd
]) = helper_ld_asi(addr
, asi
, size
, 0);
3404 u
.ll
= helper_ld_asi(addr
, asi
, size
, 0);
3405 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.upper
;
3406 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.lower
;
3409 u
.ll
= helper_ld_asi(addr
, asi
, 8, 0);
3410 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.upper
;
3411 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.lower
;
3412 u
.ll
= helper_ld_asi(addr
+ 8, asi
, 8, 0);
3413 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.upper
;
3414 *((uint32_t *)&env
->fpr
[rd
++]) = u
.l
.lower
;
3419 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
3422 target_ulong val
= 0;
3425 helper_check_align(addr
, 3);
3426 addr
= asi_address_mask(env
, asi
, addr
);
3429 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
3430 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
3431 case 0xf0: /* UA2007/JPS1 Block store primary */
3432 case 0xf1: /* UA2007/JPS1 Block store secondary */
3433 case 0xf8: /* UA2007/JPS1 Block store primary LE */
3434 case 0xf9: /* UA2007/JPS1 Block store secondary LE */
3436 raise_exception(TT_ILL_INSN
);
3439 helper_check_align(addr
, 0x3f);
3440 for (i
= 0; i
< 16; i
++) {
3441 val
= *(uint32_t *)&env
->fpr
[rd
++];
3442 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
3447 case 0x16: /* UA2007 Block load primary, user privilege */
3448 case 0x17: /* UA2007 Block load secondary, user privilege */
3449 case 0x1e: /* UA2007 Block load primary LE, user privilege */
3450 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
3451 case 0x70: /* JPS1 Block store primary, user privilege */
3452 case 0x71: /* JPS1 Block store secondary, user privilege */
3453 case 0x78: /* JPS1 Block load primary LE, user privilege */
3454 case 0x79: /* JPS1 Block load secondary LE, user privilege */
3456 raise_exception(TT_ILL_INSN
);
3459 helper_check_align(addr
, 0x3f);
3460 for (i
= 0; i
< 16; i
++) {
3461 val
= *(uint32_t *)&env
->fpr
[rd
++];
3462 helper_st_asi(addr
, val
, asi
& 0x19, 4);
3474 helper_st_asi(addr
, *(uint32_t *)&env
->fpr
[rd
], asi
, size
);
3477 u
.l
.upper
= *(uint32_t *)&env
->fpr
[rd
++];
3478 u
.l
.lower
= *(uint32_t *)&env
->fpr
[rd
++];
3479 helper_st_asi(addr
, u
.ll
, asi
, size
);
3482 u
.l
.upper
= *(uint32_t *)&env
->fpr
[rd
++];
3483 u
.l
.lower
= *(uint32_t *)&env
->fpr
[rd
++];
3484 helper_st_asi(addr
, u
.ll
, asi
, 8);
3485 u
.l
.upper
= *(uint32_t *)&env
->fpr
[rd
++];
3486 u
.l
.lower
= *(uint32_t *)&env
->fpr
[rd
++];
3487 helper_st_asi(addr
+ 8, u
.ll
, asi
, 8);
3492 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
3493 target_ulong val2
, uint32_t asi
)
3497 val2
&= 0xffffffffUL
;
3498 ret
= helper_ld_asi(addr
, asi
, 4, 0);
3499 ret
&= 0xffffffffUL
;
3501 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
3505 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
3506 target_ulong val2
, uint32_t asi
)
3510 ret
= helper_ld_asi(addr
, asi
, 8, 0);
3512 helper_st_asi(addr
, val1
, asi
, 8);
3515 #endif /* TARGET_SPARC64 */
3517 #ifndef TARGET_SPARC64
3518 void helper_rett(void)
3522 if (env
->psret
== 1)
3523 raise_exception(TT_ILL_INSN
);
3526 cwp
= cwp_inc(env
->cwp
+ 1) ;
3527 if (env
->wim
& (1 << cwp
)) {
3528 raise_exception(TT_WIN_UNF
);
3531 env
->psrs
= env
->psrps
;
3535 static target_ulong
helper_udiv_common(target_ulong a
, target_ulong b
, int cc
)
3541 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3542 x1
= (b
& 0xffffffff);
3545 raise_exception(TT_DIV_ZERO
);
3549 if (x0
> 0xffffffff) {
3556 env
->cc_src2
= overflow
;
3557 env
->cc_op
= CC_OP_DIV
;
3562 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
3564 return helper_udiv_common(a
, b
, 0);
3567 target_ulong
helper_udiv_cc(target_ulong a
, target_ulong b
)
3569 return helper_udiv_common(a
, b
, 1);
3572 static target_ulong
helper_sdiv_common(target_ulong a
, target_ulong b
, int cc
)
3578 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
3579 x1
= (b
& 0xffffffff);
3582 raise_exception(TT_DIV_ZERO
);
3586 if ((int32_t) x0
!= x0
) {
3587 x0
= x0
< 0 ? 0x80000000: 0x7fffffff;
3593 env
->cc_src2
= overflow
;
3594 env
->cc_op
= CC_OP_DIV
;
3599 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
3601 return helper_sdiv_common(a
, b
, 0);
3604 target_ulong
helper_sdiv_cc(target_ulong a
, target_ulong b
)
3606 return helper_sdiv_common(a
, b
, 1);
3609 void helper_stdf(target_ulong addr
, int mem_idx
)
3611 helper_check_align(addr
, 7);
3612 #if !defined(CONFIG_USER_ONLY)
3615 stfq_user(addr
, DT0
);
3617 case MMU_KERNEL_IDX
:
3618 stfq_kernel(addr
, DT0
);
3620 #ifdef TARGET_SPARC64
3622 stfq_hypv(addr
, DT0
);
3626 DPRINTF_MMU("helper_stdf: need to check MMU idx %d\n", mem_idx
);
3630 stfq_raw(address_mask(env
, addr
), DT0
);
3634 void helper_lddf(target_ulong addr
, int mem_idx
)
3636 helper_check_align(addr
, 7);
3637 #if !defined(CONFIG_USER_ONLY)
3640 DT0
= ldfq_user(addr
);
3642 case MMU_KERNEL_IDX
:
3643 DT0
= ldfq_kernel(addr
);
3645 #ifdef TARGET_SPARC64
3647 DT0
= ldfq_hypv(addr
);
3651 DPRINTF_MMU("helper_lddf: need to check MMU idx %d\n", mem_idx
);
3655 DT0
= ldfq_raw(address_mask(env
, addr
));
3659 void helper_ldqf(target_ulong addr
, int mem_idx
)
3661 // XXX add 128 bit load
3664 helper_check_align(addr
, 7);
3665 #if !defined(CONFIG_USER_ONLY)
3668 u
.ll
.upper
= ldq_user(addr
);
3669 u
.ll
.lower
= ldq_user(addr
+ 8);
3672 case MMU_KERNEL_IDX
:
3673 u
.ll
.upper
= ldq_kernel(addr
);
3674 u
.ll
.lower
= ldq_kernel(addr
+ 8);
3677 #ifdef TARGET_SPARC64
3679 u
.ll
.upper
= ldq_hypv(addr
);
3680 u
.ll
.lower
= ldq_hypv(addr
+ 8);
3685 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
3689 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
3690 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
3695 void helper_stqf(target_ulong addr
, int mem_idx
)
3697 // XXX add 128 bit store
3700 helper_check_align(addr
, 7);
3701 #if !defined(CONFIG_USER_ONLY)
3705 stq_user(addr
, u
.ll
.upper
);
3706 stq_user(addr
+ 8, u
.ll
.lower
);
3708 case MMU_KERNEL_IDX
:
3710 stq_kernel(addr
, u
.ll
.upper
);
3711 stq_kernel(addr
+ 8, u
.ll
.lower
);
3713 #ifdef TARGET_SPARC64
3716 stq_hypv(addr
, u
.ll
.upper
);
3717 stq_hypv(addr
+ 8, u
.ll
.lower
);
3721 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
3726 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
3727 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
3731 static inline void set_fsr(void)
3735 switch (env
->fsr
& FSR_RD_MASK
) {
3736 case FSR_RD_NEAREST
:
3737 rnd_mode
= float_round_nearest_even
;
3741 rnd_mode
= float_round_to_zero
;
3744 rnd_mode
= float_round_up
;
3747 rnd_mode
= float_round_down
;
3750 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
3753 void helper_ldfsr(uint32_t new_fsr
)
3755 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
3759 #ifdef TARGET_SPARC64
3760 void helper_ldxfsr(uint64_t new_fsr
)
3762 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
3767 void helper_debug(void)
3769 env
->exception_index
= EXCP_DEBUG
;
3773 #ifndef TARGET_SPARC64
3774 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3776 void helper_save(void)
3780 cwp
= cwp_dec(env
->cwp
- 1);
3781 if (env
->wim
& (1 << cwp
)) {
3782 raise_exception(TT_WIN_OVF
);
3787 void helper_restore(void)
3791 cwp
= cwp_inc(env
->cwp
+ 1);
3792 if (env
->wim
& (1 << cwp
)) {
3793 raise_exception(TT_WIN_UNF
);
3798 void helper_wrpsr(target_ulong new_psr
)
3800 if ((new_psr
& PSR_CWP
) >= env
->nwindows
) {
3801 raise_exception(TT_ILL_INSN
);
3803 cpu_put_psr(env
, new_psr
);
3807 target_ulong
helper_rdpsr(void)
3813 /* XXX: use another pointer for %iN registers to avoid slow wrapping
3815 void helper_save(void)
3819 cwp
= cwp_dec(env
->cwp
- 1);
3820 if (env
->cansave
== 0) {
3821 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3822 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3823 ((env
->wstate
& 0x7) << 2)));
3825 if (env
->cleanwin
- env
->canrestore
== 0) {
3826 // XXX Clean windows without trap
3827 raise_exception(TT_CLRWIN
);
3836 void helper_restore(void)
3840 cwp
= cwp_inc(env
->cwp
+ 1);
3841 if (env
->canrestore
== 0) {
3842 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
3843 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3844 ((env
->wstate
& 0x7) << 2)));
3852 void helper_flushw(void)
3854 if (env
->cansave
!= env
->nwindows
- 2) {
3855 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
3856 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
3857 ((env
->wstate
& 0x7) << 2)));
3861 void helper_saved(void)
3864 if (env
->otherwin
== 0)
3870 void helper_restored(void)
3873 if (env
->cleanwin
< env
->nwindows
- 1)
3875 if (env
->otherwin
== 0)
3881 static target_ulong
get_ccr(void)
3887 return ((env
->xcc
>> 20) << 4) | ((psr
& PSR_ICC
) >> 20);
3890 target_ulong
cpu_get_ccr(CPUState
*env1
)
3892 CPUState
*saved_env
;
3902 static void put_ccr(target_ulong val
)
3904 env
->xcc
= (val
>> 4) << 20;
3905 env
->psr
= (val
& 0xf) << 20;
3906 CC_OP
= CC_OP_FLAGS
;
3909 void cpu_put_ccr(CPUState
*env1
, target_ulong val
)
3911 CPUState
*saved_env
;
3919 static target_ulong
get_cwp64(void)
3921 return env
->nwindows
- 1 - env
->cwp
;
3924 target_ulong
cpu_get_cwp64(CPUState
*env1
)
3926 CPUState
*saved_env
;
3936 static void put_cwp64(int cwp
)
3938 if (unlikely(cwp
>= env
->nwindows
|| cwp
< 0)) {
3939 cwp
%= env
->nwindows
;
3941 set_cwp(env
->nwindows
- 1 - cwp
);
3944 void cpu_put_cwp64(CPUState
*env1
, int cwp
)
3946 CPUState
*saved_env
;
3954 target_ulong
helper_rdccr(void)
3959 void helper_wrccr(target_ulong new_ccr
)
3964 // CWP handling is reversed in V9, but we still use the V8 register
3966 target_ulong
helper_rdcwp(void)
3971 void helper_wrcwp(target_ulong new_cwp
)
3976 // This function uses non-native bit order
3977 #define GET_FIELD(X, FROM, TO) \
3978 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
3980 // This function uses the order in the manuals, i.e. bit 0 is 2^0
3981 #define GET_FIELD_SP(X, FROM, TO) \
3982 GET_FIELD(X, 63 - (TO), 63 - (FROM))
3984 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
3986 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
3987 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
3988 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
3989 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
3990 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
3991 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
3992 (((pixel_addr
>> 55) & 1) << 4) |
3993 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
3994 GET_FIELD_SP(pixel_addr
, 11, 12);
3997 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
4001 tmp
= addr
+ offset
;
4003 env
->gsr
|= tmp
& 7ULL;
4007 target_ulong
helper_popc(target_ulong val
)
4009 return ctpop64(val
);
4012 static inline uint64_t *get_gregset(uint32_t pstate
)
4016 DPRINTF_PSTATE("ERROR in get_gregset: active pstate bits=%x%s%s%s\n",
4018 (pstate
& PS_IG
) ? " IG" : "",
4019 (pstate
& PS_MG
) ? " MG" : "",
4020 (pstate
& PS_AG
) ? " AG" : "");
4021 /* pass through to normal set of global registers */
4033 static inline void change_pstate(uint32_t new_pstate
)
4035 uint32_t pstate_regs
, new_pstate_regs
;
4036 uint64_t *src
, *dst
;
4038 if (env
->def
->features
& CPU_FEATURE_GL
) {
4039 // PS_AG is not implemented in this case
4040 new_pstate
&= ~PS_AG
;
4043 pstate_regs
= env
->pstate
& 0xc01;
4044 new_pstate_regs
= new_pstate
& 0xc01;
4046 if (new_pstate_regs
!= pstate_regs
) {
4047 DPRINTF_PSTATE("change_pstate: switching regs old=%x new=%x\n",
4048 pstate_regs
, new_pstate_regs
);
4049 // Switch global register bank
4050 src
= get_gregset(new_pstate_regs
);
4051 dst
= get_gregset(pstate_regs
);
4052 memcpy32(dst
, env
->gregs
);
4053 memcpy32(env
->gregs
, src
);
4056 DPRINTF_PSTATE("change_pstate: regs new=%x (unchanged)\n",
4059 env
->pstate
= new_pstate
;
4062 void helper_wrpstate(target_ulong new_state
)
4064 change_pstate(new_state
& 0xf3f);
4066 #if !defined(CONFIG_USER_ONLY)
4067 if (cpu_interrupts_enabled(env
)) {
4068 cpu_check_irqs(env
);
4073 void cpu_change_pstate(CPUState
*env1
, uint32_t new_pstate
)
4075 CPUState
*saved_env
;
4079 change_pstate(new_pstate
);
4083 void helper_wrpil(target_ulong new_pil
)
4085 #if !defined(CONFIG_USER_ONLY)
4086 DPRINTF_PSTATE("helper_wrpil old=%x new=%x\n",
4087 env
->psrpil
, (uint32_t)new_pil
);
4089 env
->psrpil
= new_pil
;
4091 if (cpu_interrupts_enabled(env
)) {
4092 cpu_check_irqs(env
);
4097 void helper_done(void)
4099 trap_state
* tsptr
= cpu_tsptr(env
);
4101 env
->pc
= tsptr
->tnpc
;
4102 env
->npc
= tsptr
->tnpc
+ 4;
4103 put_ccr(tsptr
->tstate
>> 32);
4104 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
4105 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
4106 put_cwp64(tsptr
->tstate
& 0xff);
4109 DPRINTF_PSTATE("... helper_done tl=%d\n", env
->tl
);
4111 #if !defined(CONFIG_USER_ONLY)
4112 if (cpu_interrupts_enabled(env
)) {
4113 cpu_check_irqs(env
);
4118 void helper_retry(void)
4120 trap_state
* tsptr
= cpu_tsptr(env
);
4122 env
->pc
= tsptr
->tpc
;
4123 env
->npc
= tsptr
->tnpc
;
4124 put_ccr(tsptr
->tstate
>> 32);
4125 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
4126 change_pstate((tsptr
->tstate
>> 8) & 0xf3f);
4127 put_cwp64(tsptr
->tstate
& 0xff);
4130 DPRINTF_PSTATE("... helper_retry tl=%d\n", env
->tl
);
4132 #if !defined(CONFIG_USER_ONLY)
4133 if (cpu_interrupts_enabled(env
)) {
4134 cpu_check_irqs(env
);
4139 static void do_modify_softint(const char* operation
, uint32_t value
)
4141 if (env
->softint
!= value
) {
4142 env
->softint
= value
;
4143 DPRINTF_PSTATE(": %s new %08x\n", operation
, env
->softint
);
4144 #if !defined(CONFIG_USER_ONLY)
4145 if (cpu_interrupts_enabled(env
)) {
4146 cpu_check_irqs(env
);
4152 void helper_set_softint(uint64_t value
)
4154 do_modify_softint("helper_set_softint", env
->softint
| (uint32_t)value
);
4157 void helper_clear_softint(uint64_t value
)
4159 do_modify_softint("helper_clear_softint", env
->softint
& (uint32_t)~value
);
4162 void helper_write_softint(uint64_t value
)
4164 do_modify_softint("helper_write_softint", (uint32_t)value
);
4168 #ifdef TARGET_SPARC64
4169 trap_state
* cpu_tsptr(CPUState
* env
)
4171 return &env
->ts
[env
->tl
& MAXTL_MASK
];
4175 #if !defined(CONFIG_USER_ONLY)
4177 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4180 #define MMUSUFFIX _mmu
4181 #define ALIGNED_ONLY
4184 #include "softmmu_template.h"
4187 #include "softmmu_template.h"
4190 #include "softmmu_template.h"
4193 #include "softmmu_template.h"
4195 /* XXX: make it generic ? */
4196 static void cpu_restore_state2(void *retaddr
)
4198 TranslationBlock
*tb
;
4202 /* now we have a real cpu fault */
4203 pc
= (unsigned long)retaddr
;
4204 tb
= tb_find_pc(pc
);
4206 /* the PC is inside the translated code. It means that we have
4207 a virtual CPU fault */
4208 cpu_restore_state(tb
, env
, pc
);
4213 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
4216 #ifdef DEBUG_UNALIGNED
4217 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
4218 "\n", addr
, env
->pc
);
4220 cpu_restore_state2(retaddr
);
4221 raise_exception(TT_UNALIGNED
);
4224 /* try to fill the TLB and return an exception if error. If retaddr is
4225 NULL, it means that the function was called in C code (i.e. not
4226 from generated code or from helper.c) */
4227 /* XXX: fix it to restore all registers */
4228 void tlb_fill(CPUState
*env1
, target_ulong addr
, int is_write
, int mmu_idx
,
4232 CPUState
*saved_env
;
4237 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
4239 cpu_restore_state2(retaddr
);
4245 #endif /* !CONFIG_USER_ONLY */
4247 #ifndef TARGET_SPARC64
4248 #if !defined(CONFIG_USER_ONLY)
4249 static void do_unassigned_access(target_phys_addr_t addr
, int is_write
,
4250 int is_exec
, int is_asi
, int size
)
4254 #ifdef DEBUG_UNASSIGNED
4256 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4257 " asi 0x%02x from " TARGET_FMT_lx
"\n",
4258 is_exec
? "exec" : is_write
? "write" : "read", size
,
4259 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
4261 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
4262 " from " TARGET_FMT_lx
"\n",
4263 is_exec
? "exec" : is_write
? "write" : "read", size
,
4264 size
== 1 ? "" : "s", addr
, env
->pc
);
4266 /* Don't overwrite translation and access faults */
4267 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
4268 if ((fault_type
> 4) || (fault_type
== 0)) {
4269 env
->mmuregs
[3] = 0; /* Fault status register */
4271 env
->mmuregs
[3] |= 1 << 16;
4273 env
->mmuregs
[3] |= 1 << 5;
4275 env
->mmuregs
[3] |= 1 << 6;
4277 env
->mmuregs
[3] |= 1 << 7;
4278 env
->mmuregs
[3] |= (5 << 2) | 2;
4279 /* SuperSPARC will never place instruction fault addresses in the FAR */
4281 env
->mmuregs
[4] = addr
; /* Fault address register */
4284 /* overflow (same type fault was not read before another fault) */
4285 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
4286 env
->mmuregs
[3] |= 1;
4289 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
4291 raise_exception(TT_CODE_ACCESS
);
4293 raise_exception(TT_DATA_ACCESS
);
4296 /* flush neverland mappings created during no-fault mode,
4297 so the sequential MMU faults report proper fault types */
4298 if (env
->mmuregs
[0] & MMU_NF
) {
4304 #if defined(CONFIG_USER_ONLY)
4305 static void do_unassigned_access(target_ulong addr
, int is_write
, int is_exec
,
4306 int is_asi
, int size
)
4308 static void do_unassigned_access(target_phys_addr_t addr
, int is_write
,
4309 int is_exec
, int is_asi
, int size
)
4312 #ifdef DEBUG_UNASSIGNED
4313 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
4314 "\n", addr
, env
->pc
);
4318 raise_exception(TT_CODE_ACCESS
);
4320 raise_exception(TT_DATA_ACCESS
);
4325 #ifdef TARGET_SPARC64
4326 void helper_tick_set_count(void *opaque
, uint64_t count
)
4328 #if !defined(CONFIG_USER_ONLY)
4329 cpu_tick_set_count(opaque
, count
);
4333 uint64_t helper_tick_get_count(void *opaque
)
4335 #if !defined(CONFIG_USER_ONLY)
4336 return cpu_tick_get_count(opaque
);
4342 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
4344 #if !defined(CONFIG_USER_ONLY)
4345 cpu_tick_set_limit(opaque
, limit
);
4350 #if !defined(CONFIG_USER_ONLY)
4351 void cpu_unassigned_access(CPUState
*env1
, target_phys_addr_t addr
,
4352 int is_write
, int is_exec
, int is_asi
, int size
)
4354 CPUState
*saved_env
;
4358 /* Ignore unassigned accesses outside of CPU context */
4360 do_unassigned_access(addr
, is_write
, is_exec
, is_asi
, size
);