]>
git.proxmox.com Git - qemu.git/blob - target-sparc/op_helper.c
2 #include "host-utils.h"
4 #if !defined(CONFIG_USER_ONLY)
5 #include "softmmu_exec.h"
6 #endif /* !defined(CONFIG_USER_ONLY) */
10 //#define DEBUG_UNALIGNED
11 //#define DEBUG_UNASSIGNED
15 #define DPRINTF_MMU(fmt, args...) \
16 do { printf("MMU: " fmt , ##args); } while (0)
18 #define DPRINTF_MMU(fmt, args...) do {} while (0)
22 #define DPRINTF_MXCC(fmt, args...) \
23 do { printf("MXCC: " fmt , ##args); } while (0)
25 #define DPRINTF_MXCC(fmt, args...) do {} while (0)
29 #define DPRINTF_ASI(fmt, args...) \
30 do { printf("ASI: " fmt , ##args); } while (0)
32 #define DPRINTF_ASI(fmt, args...) do {} while (0)
37 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
39 #define AM_CHECK(env1) (1)
43 static inline void address_mask(CPUState
*env1
, target_ulong
*addr
)
47 *addr
&= 0xffffffffULL
;
51 void raise_exception(int tt
)
53 env
->exception_index
= tt
;
57 void helper_trap(target_ulong nb_trap
)
59 env
->exception_index
= TT_TRAP
+ (nb_trap
& 0x7f);
63 void helper_trapcc(target_ulong nb_trap
, target_ulong do_trap
)
66 env
->exception_index
= TT_TRAP
+ (nb_trap
& 0x7f);
71 void helper_check_align(target_ulong addr
, uint32_t align
)
74 #ifdef DEBUG_UNALIGNED
75 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
78 raise_exception(TT_UNALIGNED
);
82 #define F_HELPER(name, p) void helper_f##name##p(void)
84 #define F_BINOP(name) \
87 FT0 = float32_ ## name (FT0, FT1, &env->fp_status); \
91 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
95 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
104 void helper_fsmuld(void)
106 DT0
= float64_mul(float32_to_float64(FT0
, &env
->fp_status
),
107 float32_to_float64(FT1
, &env
->fp_status
),
111 void helper_fdmulq(void)
113 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
114 float64_to_float128(DT1
, &env
->fp_status
),
120 FT0
= float32_chs(FT1
);
123 #ifdef TARGET_SPARC64
126 DT0
= float64_chs(DT1
);
131 QT0
= float128_chs(QT1
);
135 /* Integer to float conversion. */
138 FT0
= int32_to_float32(*((int32_t *)&FT1
), &env
->fp_status
);
143 DT0
= int32_to_float64(*((int32_t *)&FT1
), &env
->fp_status
);
148 QT0
= int32_to_float128(*((int32_t *)&FT1
), &env
->fp_status
);
151 #ifdef TARGET_SPARC64
154 FT0
= int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
159 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
164 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
169 /* floating point conversion */
170 void helper_fdtos(void)
172 FT0
= float64_to_float32(DT1
, &env
->fp_status
);
175 void helper_fstod(void)
177 DT0
= float32_to_float64(FT1
, &env
->fp_status
);
180 void helper_fqtos(void)
182 FT0
= float128_to_float32(QT1
, &env
->fp_status
);
185 void helper_fstoq(void)
187 QT0
= float32_to_float128(FT1
, &env
->fp_status
);
190 void helper_fqtod(void)
192 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
195 void helper_fdtoq(void)
197 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
200 /* Float to integer conversion. */
201 void helper_fstoi(void)
203 *((int32_t *)&FT0
) = float32_to_int32_round_to_zero(FT1
, &env
->fp_status
);
206 void helper_fdtoi(void)
208 *((int32_t *)&FT0
) = float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
211 void helper_fqtoi(void)
213 *((int32_t *)&FT0
) = float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
216 #ifdef TARGET_SPARC64
217 void helper_fstox(void)
219 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(FT1
, &env
->fp_status
);
222 void helper_fdtox(void)
224 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
227 void helper_fqtox(void)
229 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
232 void helper_faligndata(void)
236 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
237 /* on many architectures a shift of 64 does nothing */
238 if ((env
->gsr
& 7) != 0) {
239 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
241 *((uint64_t *)&DT0
) = tmp
;
244 void helper_movl_FT0_0(void)
246 *((uint32_t *)&FT0
) = 0;
249 void helper_movl_DT0_0(void)
251 *((uint64_t *)&DT0
) = 0;
254 void helper_movl_FT0_1(void)
256 *((uint32_t *)&FT0
) = 0xffffffff;
259 void helper_movl_DT0_1(void)
261 *((uint64_t *)&DT0
) = 0xffffffffffffffffULL
;
264 void helper_fnot(void)
266 *(uint64_t *)&DT0
= ~*(uint64_t *)&DT1
;
269 void helper_fnots(void)
271 *(uint32_t *)&FT0
= ~*(uint32_t *)&FT1
;
274 void helper_fnor(void)
276 *(uint64_t *)&DT0
= ~(*(uint64_t *)&DT0
| *(uint64_t *)&DT1
);
279 void helper_fnors(void)
281 *(uint32_t *)&FT0
= ~(*(uint32_t *)&FT0
| *(uint32_t *)&FT1
);
284 void helper_for(void)
286 *(uint64_t *)&DT0
|= *(uint64_t *)&DT1
;
289 void helper_fors(void)
291 *(uint32_t *)&FT0
|= *(uint32_t *)&FT1
;
294 void helper_fxor(void)
296 *(uint64_t *)&DT0
^= *(uint64_t *)&DT1
;
299 void helper_fxors(void)
301 *(uint32_t *)&FT0
^= *(uint32_t *)&FT1
;
304 void helper_fand(void)
306 *(uint64_t *)&DT0
&= *(uint64_t *)&DT1
;
309 void helper_fands(void)
311 *(uint32_t *)&FT0
&= *(uint32_t *)&FT1
;
314 void helper_fornot(void)
316 *(uint64_t *)&DT0
= *(uint64_t *)&DT0
| ~*(uint64_t *)&DT1
;
319 void helper_fornots(void)
321 *(uint32_t *)&FT0
= *(uint32_t *)&FT0
| ~*(uint32_t *)&FT1
;
324 void helper_fandnot(void)
326 *(uint64_t *)&DT0
= *(uint64_t *)&DT0
& ~*(uint64_t *)&DT1
;
329 void helper_fandnots(void)
331 *(uint32_t *)&FT0
= *(uint32_t *)&FT0
& ~*(uint32_t *)&FT1
;
334 void helper_fnand(void)
336 *(uint64_t *)&DT0
= ~(*(uint64_t *)&DT0
& *(uint64_t *)&DT1
);
339 void helper_fnands(void)
341 *(uint32_t *)&FT0
= ~(*(uint32_t *)&FT0
& *(uint32_t *)&FT1
);
344 void helper_fxnor(void)
346 *(uint64_t *)&DT0
^= ~*(uint64_t *)&DT1
;
349 void helper_fxnors(void)
351 *(uint32_t *)&FT0
^= ~*(uint32_t *)&FT1
;
354 #ifdef WORDS_BIGENDIAN
355 #define VIS_B64(n) b[7 - (n)]
356 #define VIS_W64(n) w[3 - (n)]
357 #define VIS_SW64(n) sw[3 - (n)]
358 #define VIS_L64(n) l[1 - (n)]
359 #define VIS_B32(n) b[3 - (n)]
360 #define VIS_W32(n) w[1 - (n)]
362 #define VIS_B64(n) b[n]
363 #define VIS_W64(n) w[n]
364 #define VIS_SW64(n) sw[n]
365 #define VIS_L64(n) l[n]
366 #define VIS_B32(n) b[n]
367 #define VIS_W32(n) w[n]
385 void helper_fpmerge(void)
392 // Reverse calculation order to handle overlap
393 d
.VIS_B64(7) = s
.VIS_B64(3);
394 d
.VIS_B64(6) = d
.VIS_B64(3);
395 d
.VIS_B64(5) = s
.VIS_B64(2);
396 d
.VIS_B64(4) = d
.VIS_B64(2);
397 d
.VIS_B64(3) = s
.VIS_B64(1);
398 d
.VIS_B64(2) = d
.VIS_B64(1);
399 d
.VIS_B64(1) = s
.VIS_B64(0);
400 //d.VIS_B64(0) = d.VIS_B64(0);
405 void helper_fmul8x16(void)
414 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
415 if ((tmp & 0xff) > 0x7f) \
417 d.VIS_W64(r) = tmp >> 8;
428 void helper_fmul8x16al(void)
437 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
438 if ((tmp & 0xff) > 0x7f) \
440 d.VIS_W64(r) = tmp >> 8;
451 void helper_fmul8x16au(void)
460 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
461 if ((tmp & 0xff) > 0x7f) \
463 d.VIS_W64(r) = tmp >> 8;
474 void helper_fmul8sux16(void)
483 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
484 if ((tmp & 0xff) > 0x7f) \
486 d.VIS_W64(r) = tmp >> 8;
497 void helper_fmul8ulx16(void)
506 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
507 if ((tmp & 0xff) > 0x7f) \
509 d.VIS_W64(r) = tmp >> 8;
520 void helper_fmuld8sux16(void)
529 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
530 if ((tmp & 0xff) > 0x7f) \
534 // Reverse calculation order to handle overlap
542 void helper_fmuld8ulx16(void)
551 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
552 if ((tmp & 0xff) > 0x7f) \
556 // Reverse calculation order to handle overlap
564 void helper_fexpand(void)
569 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
571 d
.VIS_L64(0) = s
.VIS_W32(0) << 4;
572 d
.VIS_L64(1) = s
.VIS_W32(1) << 4;
573 d
.VIS_L64(2) = s
.VIS_W32(2) << 4;
574 d
.VIS_L64(3) = s
.VIS_W32(3) << 4;
579 #define VIS_HELPER(name, F) \
580 void name##16(void) \
587 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
588 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
589 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
590 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
595 void name##16s(void) \
602 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
603 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
608 void name##32(void) \
615 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
616 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
621 void name##32s(void) \
633 #define FADD(a, b) ((a) + (b))
634 #define FSUB(a, b) ((a) - (b))
635 VIS_HELPER(helper_fpadd
, FADD
)
636 VIS_HELPER(helper_fpsub
, FSUB
)
638 #define VIS_CMPHELPER(name, F) \
639 void name##16(void) \
646 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
647 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
648 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
649 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
654 void name##32(void) \
661 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
662 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
667 #define FCMPGT(a, b) ((a) > (b))
668 #define FCMPEQ(a, b) ((a) == (b))
669 #define FCMPLE(a, b) ((a) <= (b))
670 #define FCMPNE(a, b) ((a) != (b))
672 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
673 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
674 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
675 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
678 void helper_check_ieee_exceptions(void)
682 status
= get_float_exception_flags(&env
->fp_status
);
684 /* Copy IEEE 754 flags into FSR */
685 if (status
& float_flag_invalid
)
687 if (status
& float_flag_overflow
)
689 if (status
& float_flag_underflow
)
691 if (status
& float_flag_divbyzero
)
693 if (status
& float_flag_inexact
)
696 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
697 /* Unmasked exception, generate a trap */
698 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
699 raise_exception(TT_FP_EXCP
);
701 /* Accumulate exceptions */
702 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
707 void helper_clear_float_exceptions(void)
709 set_float_exception_flags(0, &env
->fp_status
);
712 void helper_fabss(void)
714 FT0
= float32_abs(FT1
);
717 #ifdef TARGET_SPARC64
718 void helper_fabsd(void)
720 DT0
= float64_abs(DT1
);
723 void helper_fabsq(void)
725 QT0
= float128_abs(QT1
);
729 void helper_fsqrts(void)
731 FT0
= float32_sqrt(FT1
, &env
->fp_status
);
734 void helper_fsqrtd(void)
736 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
739 void helper_fsqrtq(void)
741 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
744 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
745 void glue(helper_, name) (void) \
747 target_ulong new_fsr; \
749 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
750 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
751 case float_relation_unordered: \
752 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
753 if ((env->fsr & FSR_NVM) || TRAP) { \
754 env->fsr |= new_fsr; \
755 env->fsr |= FSR_NVC; \
756 env->fsr |= FSR_FTT_IEEE_EXCP; \
757 raise_exception(TT_FP_EXCP); \
759 env->fsr |= FSR_NVA; \
762 case float_relation_less: \
763 new_fsr = FSR_FCC0 << FS; \
765 case float_relation_greater: \
766 new_fsr = FSR_FCC1 << FS; \
772 env->fsr |= new_fsr; \
775 GEN_FCMP(fcmps
, float32
, FT0
, FT1
, 0, 0);
776 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
778 GEN_FCMP(fcmpes
, float32
, FT0
, FT1
, 0, 1);
779 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
781 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
782 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
784 #ifdef TARGET_SPARC64
785 GEN_FCMP(fcmps_fcc1
, float32
, FT0
, FT1
, 22, 0);
786 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
787 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
789 GEN_FCMP(fcmps_fcc2
, float32
, FT0
, FT1
, 24, 0);
790 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
791 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
793 GEN_FCMP(fcmps_fcc3
, float32
, FT0
, FT1
, 26, 0);
794 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
795 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
797 GEN_FCMP(fcmpes_fcc1
, float32
, FT0
, FT1
, 22, 1);
798 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
799 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
801 GEN_FCMP(fcmpes_fcc2
, float32
, FT0
, FT1
, 24, 1);
802 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
803 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
805 GEN_FCMP(fcmpes_fcc3
, float32
, FT0
, FT1
, 26, 1);
806 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
807 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
810 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
812 static void dump_mxcc(CPUState
*env
)
814 printf("mxccdata: %016llx %016llx %016llx %016llx\n",
815 env
->mxccdata
[0], env
->mxccdata
[1],
816 env
->mxccdata
[2], env
->mxccdata
[3]);
817 printf("mxccregs: %016llx %016llx %016llx %016llx\n"
818 " %016llx %016llx %016llx %016llx\n",
819 env
->mxccregs
[0], env
->mxccregs
[1],
820 env
->mxccregs
[2], env
->mxccregs
[3],
821 env
->mxccregs
[4], env
->mxccregs
[5],
822 env
->mxccregs
[6], env
->mxccregs
[7]);
826 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
827 && defined(DEBUG_ASI)
828 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
834 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
835 addr
, asi
, r1
& 0xff);
838 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
839 addr
, asi
, r1
& 0xffff);
842 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
843 addr
, asi
, r1
& 0xffffffff);
846 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
853 #ifndef TARGET_SPARC64
854 #ifndef CONFIG_USER_ONLY
855 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
858 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
859 uint32_t last_addr
= addr
;
862 helper_check_align(addr
, size
- 1);
864 case 2: /* SuperSparc MXCC registers */
866 case 0x01c00a00: /* MXCC control register */
868 ret
= env
->mxccregs
[3];
870 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
873 case 0x01c00a04: /* MXCC control register */
875 ret
= env
->mxccregs
[3];
877 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
880 case 0x01c00c00: /* Module reset register */
882 ret
= env
->mxccregs
[5];
883 // should we do something here?
885 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
888 case 0x01c00f00: /* MBus port address register */
890 ret
= env
->mxccregs
[7];
892 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
896 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
900 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
901 "addr = %08x -> ret = %08x,"
902 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
907 case 3: /* MMU probe */
911 mmulev
= (addr
>> 8) & 15;
915 ret
= mmu_probe(env
, addr
, mmulev
);
916 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
920 case 4: /* read MMU regs */
922 int reg
= (addr
>> 8) & 0x1f;
924 ret
= env
->mmuregs
[reg
];
925 if (reg
== 3) /* Fault status cleared on read */
927 else if (reg
== 0x13) /* Fault status read */
928 ret
= env
->mmuregs
[3];
929 else if (reg
== 0x14) /* Fault address read */
930 ret
= env
->mmuregs
[4];
931 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
934 case 5: // Turbosparc ITLB Diagnostic
935 case 6: // Turbosparc DTLB Diagnostic
936 case 7: // Turbosparc IOTLB Diagnostic
938 case 9: /* Supervisor code access */
941 ret
= ldub_code(addr
);
944 ret
= lduw_code(addr
);
948 ret
= ldl_code(addr
);
951 ret
= ldq_code(addr
);
955 case 0xa: /* User data access */
958 ret
= ldub_user(addr
);
961 ret
= lduw_user(addr
);
965 ret
= ldl_user(addr
);
968 ret
= ldq_user(addr
);
972 case 0xb: /* Supervisor data access */
975 ret
= ldub_kernel(addr
);
978 ret
= lduw_kernel(addr
);
982 ret
= ldl_kernel(addr
);
985 ret
= ldq_kernel(addr
);
989 case 0xc: /* I-cache tag */
990 case 0xd: /* I-cache data */
991 case 0xe: /* D-cache tag */
992 case 0xf: /* D-cache data */
994 case 0x20: /* MMU passthrough */
997 ret
= ldub_phys(addr
);
1000 ret
= lduw_phys(addr
);
1004 ret
= ldl_phys(addr
);
1007 ret
= ldq_phys(addr
);
1011 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1014 ret
= ldub_phys((target_phys_addr_t
)addr
1015 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1018 ret
= lduw_phys((target_phys_addr_t
)addr
1019 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1023 ret
= ldl_phys((target_phys_addr_t
)addr
1024 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1027 ret
= ldq_phys((target_phys_addr_t
)addr
1028 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1032 case 0x30: // Turbosparc secondary cache diagnostic
1033 case 0x31: // Turbosparc RAM snoop
1034 case 0x32: // Turbosparc page table descriptor diagnostic
1035 case 0x39: /* data cache diagnostic register */
1038 case 8: /* User code access, XXX */
1040 do_unassigned_access(addr
, 0, 0, asi
);
1050 ret
= (int16_t) ret
;
1053 ret
= (int32_t) ret
;
1060 dump_asi("read ", last_addr
, asi
, size
, ret
);
1065 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1067 helper_check_align(addr
, size
- 1);
1069 case 2: /* SuperSparc MXCC registers */
1071 case 0x01c00000: /* MXCC stream data register 0 */
1073 env
->mxccdata
[0] = val
;
1075 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1078 case 0x01c00008: /* MXCC stream data register 1 */
1080 env
->mxccdata
[1] = val
;
1082 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1085 case 0x01c00010: /* MXCC stream data register 2 */
1087 env
->mxccdata
[2] = val
;
1089 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1092 case 0x01c00018: /* MXCC stream data register 3 */
1094 env
->mxccdata
[3] = val
;
1096 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1099 case 0x01c00100: /* MXCC stream source */
1101 env
->mxccregs
[0] = val
;
1103 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1105 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1107 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1109 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1111 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1114 case 0x01c00200: /* MXCC stream destination */
1116 env
->mxccregs
[1] = val
;
1118 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1120 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1122 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1124 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1126 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1129 case 0x01c00a00: /* MXCC control register */
1131 env
->mxccregs
[3] = val
;
1133 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1136 case 0x01c00a04: /* MXCC control register */
1138 env
->mxccregs
[3] = (env
->mxccregs
[0xa] & 0xffffffff00000000ULL
)
1141 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1144 case 0x01c00e00: /* MXCC error register */
1145 // writing a 1 bit clears the error
1147 env
->mxccregs
[6] &= ~val
;
1149 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1152 case 0x01c00f00: /* MBus port address register */
1154 env
->mxccregs
[7] = val
;
1156 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1160 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1164 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %08x\n", asi
,
1170 case 3: /* MMU flush */
1174 mmulev
= (addr
>> 8) & 15;
1175 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1177 case 0: // flush page
1178 tlb_flush_page(env
, addr
& 0xfffff000);
1180 case 1: // flush segment (256k)
1181 case 2: // flush region (16M)
1182 case 3: // flush context (4G)
1183 case 4: // flush entire
1194 case 4: /* write MMU regs */
1196 int reg
= (addr
>> 8) & 0x1f;
1199 oldreg
= env
->mmuregs
[reg
];
1201 case 0: // Control Register
1202 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1204 // Mappings generated during no-fault mode or MMU
1205 // disabled mode are invalid in normal mode
1206 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1207 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1210 case 1: // Context Table Pointer Register
1211 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1213 case 2: // Context Register
1214 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1215 if (oldreg
!= env
->mmuregs
[reg
]) {
1216 /* we flush when the MMU context changes because
1217 QEMU has no MMU context support */
1221 case 3: // Synchronous Fault Status Register with Clear
1222 case 4: // Synchronous Fault Address Register
1224 case 0x10: // TLB Replacement Control Register
1225 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1227 case 0x13: // Synchronous Fault Status Register with Read and Clear
1228 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1230 case 0x14: // Synchronous Fault Address Register
1231 env
->mmuregs
[4] = val
;
1234 env
->mmuregs
[reg
] = val
;
1237 if (oldreg
!= env
->mmuregs
[reg
]) {
1238 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1239 reg
, oldreg
, env
->mmuregs
[reg
]);
1246 case 5: // Turbosparc ITLB Diagnostic
1247 case 6: // Turbosparc DTLB Diagnostic
1248 case 7: // Turbosparc IOTLB Diagnostic
1250 case 0xa: /* User data access */
1253 stb_user(addr
, val
);
1256 stw_user(addr
, val
);
1260 stl_user(addr
, val
);
1263 stq_user(addr
, val
);
1267 case 0xb: /* Supervisor data access */
1270 stb_kernel(addr
, val
);
1273 stw_kernel(addr
, val
);
1277 stl_kernel(addr
, val
);
1280 stq_kernel(addr
, val
);
1284 case 0xc: /* I-cache tag */
1285 case 0xd: /* I-cache data */
1286 case 0xe: /* D-cache tag */
1287 case 0xf: /* D-cache data */
1288 case 0x10: /* I/D-cache flush page */
1289 case 0x11: /* I/D-cache flush segment */
1290 case 0x12: /* I/D-cache flush region */
1291 case 0x13: /* I/D-cache flush context */
1292 case 0x14: /* I/D-cache flush user */
1294 case 0x17: /* Block copy, sta access */
1300 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1302 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1303 temp
= ldl_kernel(src
);
1304 stl_kernel(dst
, temp
);
1308 case 0x1f: /* Block fill, stda access */
1311 // fill 32 bytes with val
1313 uint32_t dst
= addr
& 7;
1315 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1316 stq_kernel(dst
, val
);
1319 case 0x20: /* MMU passthrough */
1323 stb_phys(addr
, val
);
1326 stw_phys(addr
, val
);
1330 stl_phys(addr
, val
);
1333 stq_phys(addr
, val
);
1338 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1342 stb_phys((target_phys_addr_t
)addr
1343 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1346 stw_phys((target_phys_addr_t
)addr
1347 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1351 stl_phys((target_phys_addr_t
)addr
1352 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1355 stq_phys((target_phys_addr_t
)addr
1356 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1361 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1362 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1363 // Turbosparc snoop RAM
1364 case 0x32: // store buffer control or Turbosparc page table
1365 // descriptor diagnostic
1366 case 0x36: /* I-cache flash clear */
1367 case 0x37: /* D-cache flash clear */
1368 case 0x38: /* breakpoint diagnostics */
1369 case 0x4c: /* breakpoint action */
1371 case 8: /* User code access, XXX */
1372 case 9: /* Supervisor code access, XXX */
1374 do_unassigned_access(addr
, 1, 0, asi
);
1378 dump_asi("write", addr
, asi
, size
, val
);
1382 #endif /* CONFIG_USER_ONLY */
1383 #else /* TARGET_SPARC64 */
1385 #ifdef CONFIG_USER_ONLY
1386 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1389 #if defined(DEBUG_ASI)
1390 target_ulong last_addr
= addr
;
1394 raise_exception(TT_PRIV_ACT
);
1396 helper_check_align(addr
, size
- 1);
1397 address_mask(env
, &addr
);
1400 case 0x80: // Primary
1401 case 0x82: // Primary no-fault
1402 case 0x88: // Primary LE
1403 case 0x8a: // Primary no-fault LE
1407 ret
= ldub_raw(addr
);
1410 ret
= lduw_raw(addr
);
1413 ret
= ldl_raw(addr
);
1417 ret
= ldq_raw(addr
);
1422 case 0x81: // Secondary
1423 case 0x83: // Secondary no-fault
1424 case 0x89: // Secondary LE
1425 case 0x8b: // Secondary no-fault LE
1432 /* Convert from little endian */
1434 case 0x88: // Primary LE
1435 case 0x89: // Secondary LE
1436 case 0x8a: // Primary no-fault LE
1437 case 0x8b: // Secondary no-fault LE
1455 /* Convert to signed number */
1462 ret
= (int16_t) ret
;
1465 ret
= (int32_t) ret
;
1472 dump_asi("read ", last_addr
, asi
, size
, ret
);
1477 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1480 dump_asi("write", addr
, asi
, size
, val
);
1483 raise_exception(TT_PRIV_ACT
);
1485 helper_check_align(addr
, size
- 1);
1486 address_mask(env
, &addr
);
1488 /* Convert to little endian */
1490 case 0x88: // Primary LE
1491 case 0x89: // Secondary LE
1494 addr
= bswap16(addr
);
1497 addr
= bswap32(addr
);
1500 addr
= bswap64(addr
);
1510 case 0x80: // Primary
1511 case 0x88: // Primary LE
1530 case 0x81: // Secondary
1531 case 0x89: // Secondary LE
1535 case 0x82: // Primary no-fault, RO
1536 case 0x83: // Secondary no-fault, RO
1537 case 0x8a: // Primary no-fault LE, RO
1538 case 0x8b: // Secondary no-fault LE, RO
1540 do_unassigned_access(addr
, 1, 0, 1);
1545 #else /* CONFIG_USER_ONLY */
1547 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1550 #if defined(DEBUG_ASI)
1551 target_ulong last_addr
= addr
;
1554 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1555 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1556 && asi
>= 0x30 && asi
< 0x80
1557 && !(env
->hpstate
& HS_PRIV
)))
1558 raise_exception(TT_PRIV_ACT
);
1560 helper_check_align(addr
, size
- 1);
1562 case 0x10: // As if user primary
1563 case 0x18: // As if user primary LE
1564 case 0x80: // Primary
1565 case 0x82: // Primary no-fault
1566 case 0x88: // Primary LE
1567 case 0x8a: // Primary no-fault LE
1568 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1569 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1570 && env
->hpstate
& HS_PRIV
) {
1573 ret
= ldub_hypv(addr
);
1576 ret
= lduw_hypv(addr
);
1579 ret
= ldl_hypv(addr
);
1583 ret
= ldq_hypv(addr
);
1589 ret
= ldub_kernel(addr
);
1592 ret
= lduw_kernel(addr
);
1595 ret
= ldl_kernel(addr
);
1599 ret
= ldq_kernel(addr
);
1606 ret
= ldub_user(addr
);
1609 ret
= lduw_user(addr
);
1612 ret
= ldl_user(addr
);
1616 ret
= ldq_user(addr
);
1621 case 0x14: // Bypass
1622 case 0x15: // Bypass, non-cacheable
1623 case 0x1c: // Bypass LE
1624 case 0x1d: // Bypass, non-cacheable LE
1628 ret
= ldub_phys(addr
);
1631 ret
= lduw_phys(addr
);
1634 ret
= ldl_phys(addr
);
1638 ret
= ldq_phys(addr
);
1643 case 0x24: // Nucleus quad LDD 128 bit atomic
1644 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1645 // Only ldda allowed
1646 raise_exception(TT_ILL_INSN
);
1648 case 0x04: // Nucleus
1649 case 0x0c: // Nucleus Little Endian (LE)
1650 case 0x11: // As if user secondary
1651 case 0x19: // As if user secondary LE
1652 case 0x4a: // UPA config
1653 case 0x81: // Secondary
1654 case 0x83: // Secondary no-fault
1655 case 0x89: // Secondary LE
1656 case 0x8b: // Secondary no-fault LE
1662 case 0x50: // I-MMU regs
1664 int reg
= (addr
>> 3) & 0xf;
1666 ret
= env
->immuregs
[reg
];
1669 case 0x51: // I-MMU 8k TSB pointer
1670 case 0x52: // I-MMU 64k TSB pointer
1673 case 0x55: // I-MMU data access
1675 int reg
= (addr
>> 3) & 0x3f;
1677 ret
= env
->itlb_tte
[reg
];
1680 case 0x56: // I-MMU tag read
1682 int reg
= (addr
>> 3) & 0x3f;
1684 ret
= env
->itlb_tag
[reg
];
1687 case 0x58: // D-MMU regs
1689 int reg
= (addr
>> 3) & 0xf;
1691 ret
= env
->dmmuregs
[reg
];
1694 case 0x5d: // D-MMU data access
1696 int reg
= (addr
>> 3) & 0x3f;
1698 ret
= env
->dtlb_tte
[reg
];
1701 case 0x5e: // D-MMU tag read
1703 int reg
= (addr
>> 3) & 0x3f;
1705 ret
= env
->dtlb_tag
[reg
];
1708 case 0x46: // D-cache data
1709 case 0x47: // D-cache tag access
1710 case 0x4b: // E-cache error enable
1711 case 0x4c: // E-cache asynchronous fault status
1712 case 0x4d: // E-cache asynchronous fault address
1713 case 0x4e: // E-cache tag data
1714 case 0x66: // I-cache instruction access
1715 case 0x67: // I-cache tag access
1716 case 0x6e: // I-cache predecode
1717 case 0x6f: // I-cache LRU etc.
1718 case 0x76: // E-cache tag
1719 case 0x7e: // E-cache tag
1721 case 0x59: // D-MMU 8k TSB pointer
1722 case 0x5a: // D-MMU 64k TSB pointer
1723 case 0x5b: // D-MMU data pointer
1724 case 0x48: // Interrupt dispatch, RO
1725 case 0x49: // Interrupt data receive
1726 case 0x7f: // Incoming interrupt vector, RO
1729 case 0x54: // I-MMU data in, WO
1730 case 0x57: // I-MMU demap, WO
1731 case 0x5c: // D-MMU data in, WO
1732 case 0x5f: // D-MMU demap, WO
1733 case 0x77: // Interrupt vector, WO
1735 do_unassigned_access(addr
, 0, 0, 1);
1740 /* Convert from little endian */
1742 case 0x0c: // Nucleus Little Endian (LE)
1743 case 0x18: // As if user primary LE
1744 case 0x19: // As if user secondary LE
1745 case 0x1c: // Bypass LE
1746 case 0x1d: // Bypass, non-cacheable LE
1747 case 0x88: // Primary LE
1748 case 0x89: // Secondary LE
1749 case 0x8a: // Primary no-fault LE
1750 case 0x8b: // Secondary no-fault LE
1768 /* Convert to signed number */
1775 ret
= (int16_t) ret
;
1778 ret
= (int32_t) ret
;
1785 dump_asi("read ", last_addr
, asi
, size
, ret
);
1790 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1793 dump_asi("write", addr
, asi
, size
, val
);
1795 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1796 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1797 && asi
>= 0x30 && asi
< 0x80
1798 && !(env
->hpstate
& HS_PRIV
)))
1799 raise_exception(TT_PRIV_ACT
);
1801 helper_check_align(addr
, size
- 1);
1802 /* Convert to little endian */
1804 case 0x0c: // Nucleus Little Endian (LE)
1805 case 0x18: // As if user primary LE
1806 case 0x19: // As if user secondary LE
1807 case 0x1c: // Bypass LE
1808 case 0x1d: // Bypass, non-cacheable LE
1809 case 0x88: // Primary LE
1810 case 0x89: // Secondary LE
1813 addr
= bswap16(addr
);
1816 addr
= bswap32(addr
);
1819 addr
= bswap64(addr
);
1829 case 0x10: // As if user primary
1830 case 0x18: // As if user primary LE
1831 case 0x80: // Primary
1832 case 0x88: // Primary LE
1833 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1834 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1835 && env
->hpstate
& HS_PRIV
) {
1838 stb_hypv(addr
, val
);
1841 stw_hypv(addr
, val
);
1844 stl_hypv(addr
, val
);
1848 stq_hypv(addr
, val
);
1854 stb_kernel(addr
, val
);
1857 stw_kernel(addr
, val
);
1860 stl_kernel(addr
, val
);
1864 stq_kernel(addr
, val
);
1871 stb_user(addr
, val
);
1874 stw_user(addr
, val
);
1877 stl_user(addr
, val
);
1881 stq_user(addr
, val
);
1886 case 0x14: // Bypass
1887 case 0x15: // Bypass, non-cacheable
1888 case 0x1c: // Bypass LE
1889 case 0x1d: // Bypass, non-cacheable LE
1893 stb_phys(addr
, val
);
1896 stw_phys(addr
, val
);
1899 stl_phys(addr
, val
);
1903 stq_phys(addr
, val
);
1908 case 0x24: // Nucleus quad LDD 128 bit atomic
1909 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1910 // Only ldda allowed
1911 raise_exception(TT_ILL_INSN
);
1913 case 0x04: // Nucleus
1914 case 0x0c: // Nucleus Little Endian (LE)
1915 case 0x11: // As if user secondary
1916 case 0x19: // As if user secondary LE
1917 case 0x4a: // UPA config
1918 case 0x81: // Secondary
1919 case 0x89: // Secondary LE
1927 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1928 // Mappings generated during D/I MMU disabled mode are
1929 // invalid in normal mode
1930 if (oldreg
!= env
->lsu
) {
1931 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1940 case 0x50: // I-MMU regs
1942 int reg
= (addr
>> 3) & 0xf;
1945 oldreg
= env
->immuregs
[reg
];
1950 case 1: // Not in I-MMU
1957 val
= 0; // Clear SFSR
1959 case 5: // TSB access
1960 case 6: // Tag access
1964 env
->immuregs
[reg
] = val
;
1965 if (oldreg
!= env
->immuregs
[reg
]) {
1966 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
1967 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1974 case 0x54: // I-MMU data in
1978 // Try finding an invalid entry
1979 for (i
= 0; i
< 64; i
++) {
1980 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
1981 env
->itlb_tag
[i
] = env
->immuregs
[6];
1982 env
->itlb_tte
[i
] = val
;
1986 // Try finding an unlocked entry
1987 for (i
= 0; i
< 64; i
++) {
1988 if ((env
->itlb_tte
[i
] & 0x40) == 0) {
1989 env
->itlb_tag
[i
] = env
->immuregs
[6];
1990 env
->itlb_tte
[i
] = val
;
1997 case 0x55: // I-MMU data access
1999 unsigned int i
= (addr
>> 3) & 0x3f;
2001 env
->itlb_tag
[i
] = env
->immuregs
[6];
2002 env
->itlb_tte
[i
] = val
;
2005 case 0x57: // I-MMU demap
2008 case 0x58: // D-MMU regs
2010 int reg
= (addr
>> 3) & 0xf;
2013 oldreg
= env
->dmmuregs
[reg
];
2019 if ((val
& 1) == 0) {
2020 val
= 0; // Clear SFSR, Fault address
2021 env
->dmmuregs
[4] = 0;
2023 env
->dmmuregs
[reg
] = val
;
2025 case 1: // Primary context
2026 case 2: // Secondary context
2027 case 5: // TSB access
2028 case 6: // Tag access
2029 case 7: // Virtual Watchpoint
2030 case 8: // Physical Watchpoint
2034 env
->dmmuregs
[reg
] = val
;
2035 if (oldreg
!= env
->dmmuregs
[reg
]) {
2036 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
2037 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2044 case 0x5c: // D-MMU data in
2048 // Try finding an invalid entry
2049 for (i
= 0; i
< 64; i
++) {
2050 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
2051 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2052 env
->dtlb_tte
[i
] = val
;
2056 // Try finding an unlocked entry
2057 for (i
= 0; i
< 64; i
++) {
2058 if ((env
->dtlb_tte
[i
] & 0x40) == 0) {
2059 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2060 env
->dtlb_tte
[i
] = val
;
2067 case 0x5d: // D-MMU data access
2069 unsigned int i
= (addr
>> 3) & 0x3f;
2071 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2072 env
->dtlb_tte
[i
] = val
;
2075 case 0x5f: // D-MMU demap
2076 case 0x49: // Interrupt data receive
2079 case 0x46: // D-cache data
2080 case 0x47: // D-cache tag access
2081 case 0x4b: // E-cache error enable
2082 case 0x4c: // E-cache asynchronous fault status
2083 case 0x4d: // E-cache asynchronous fault address
2084 case 0x4e: // E-cache tag data
2085 case 0x66: // I-cache instruction access
2086 case 0x67: // I-cache tag access
2087 case 0x6e: // I-cache predecode
2088 case 0x6f: // I-cache LRU etc.
2089 case 0x76: // E-cache tag
2090 case 0x7e: // E-cache tag
2092 case 0x51: // I-MMU 8k TSB pointer, RO
2093 case 0x52: // I-MMU 64k TSB pointer, RO
2094 case 0x56: // I-MMU tag read, RO
2095 case 0x59: // D-MMU 8k TSB pointer, RO
2096 case 0x5a: // D-MMU 64k TSB pointer, RO
2097 case 0x5b: // D-MMU data pointer, RO
2098 case 0x5e: // D-MMU tag read, RO
2099 case 0x48: // Interrupt dispatch, RO
2100 case 0x7f: // Incoming interrupt vector, RO
2101 case 0x82: // Primary no-fault, RO
2102 case 0x83: // Secondary no-fault, RO
2103 case 0x8a: // Primary no-fault LE, RO
2104 case 0x8b: // Secondary no-fault LE, RO
2106 do_unassigned_access(addr
, 1, 0, 1);
2110 #endif /* CONFIG_USER_ONLY */
2112 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2114 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2115 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2116 && asi
>= 0x30 && asi
< 0x80
2117 && !(env
->hpstate
& HS_PRIV
)))
2118 raise_exception(TT_PRIV_ACT
);
2121 case 0x24: // Nucleus quad LDD 128 bit atomic
2122 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2123 helper_check_align(addr
, 0xf);
2125 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2127 bswap64s(&env
->gregs
[1]);
2128 } else if (rd
< 8) {
2129 env
->gregs
[rd
] = ldq_kernel(addr
);
2130 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2132 bswap64s(&env
->gregs
[rd
]);
2133 bswap64s(&env
->gregs
[rd
+ 1]);
2136 env
->regwptr
[rd
] = ldq_kernel(addr
);
2137 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2139 bswap64s(&env
->regwptr
[rd
]);
2140 bswap64s(&env
->regwptr
[rd
+ 1]);
2145 helper_check_align(addr
, 0x3);
2147 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2149 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2150 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2152 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2153 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2159 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2164 helper_check_align(addr
, 3);
2166 case 0xf0: // Block load primary
2167 case 0xf1: // Block load secondary
2168 case 0xf8: // Block load primary LE
2169 case 0xf9: // Block load secondary LE
2171 raise_exception(TT_ILL_INSN
);
2174 helper_check_align(addr
, 0x3f);
2175 for (i
= 0; i
< 16; i
++) {
2176 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2186 val
= helper_ld_asi(addr
, asi
, size
, 0);
2190 *((uint32_t *)&FT0
) = val
;
2193 *((int64_t *)&DT0
) = val
;
2201 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2204 target_ulong val
= 0;
2206 helper_check_align(addr
, 3);
2208 case 0xf0: // Block store primary
2209 case 0xf1: // Block store secondary
2210 case 0xf8: // Block store primary LE
2211 case 0xf9: // Block store secondary LE
2213 raise_exception(TT_ILL_INSN
);
2216 helper_check_align(addr
, 0x3f);
2217 for (i
= 0; i
< 16; i
++) {
2218 val
= *(uint32_t *)&env
->fpr
[rd
++];
2219 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2231 val
= *((uint32_t *)&FT0
);
2234 val
= *((int64_t *)&DT0
);
2240 helper_st_asi(addr
, val
, asi
, size
);
2243 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2244 target_ulong val2
, uint32_t asi
)
2248 val1
&= 0xffffffffUL
;
2249 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2250 ret
&= 0xffffffffUL
;
2252 helper_st_asi(addr
, val2
& 0xffffffffUL
, asi
, 4);
2256 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2257 target_ulong val2
, uint32_t asi
)
2261 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2263 helper_st_asi(addr
, val2
, asi
, 8);
2266 #endif /* TARGET_SPARC64 */
2268 #ifndef TARGET_SPARC64
2269 void helper_rett(void)
2273 if (env
->psret
== 1)
2274 raise_exception(TT_ILL_INSN
);
2277 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2278 if (env
->wim
& (1 << cwp
)) {
2279 raise_exception(TT_WIN_UNF
);
2282 env
->psrs
= env
->psrps
;
2286 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2291 x0
= a
| ((uint64_t) (env
->y
) << 32);
2295 raise_exception(TT_DIV_ZERO
);
2299 if (x0
> 0xffffffff) {
2308 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2313 x0
= a
| ((int64_t) (env
->y
) << 32);
2317 raise_exception(TT_DIV_ZERO
);
2321 if ((int32_t) x0
!= x0
) {
2323 return x0
< 0? 0x80000000: 0x7fffffff;
2330 uint64_t helper_pack64(target_ulong high
, target_ulong low
)
2332 return ((uint64_t)high
<< 32) | (uint64_t)(low
& 0xffffffff);
2335 void helper_stdf(target_ulong addr
, int mem_idx
)
2337 helper_check_align(addr
, 7);
2338 #if !defined(CONFIG_USER_ONLY)
2341 stfq_user(addr
, DT0
);
2344 stfq_kernel(addr
, DT0
);
2346 #ifdef TARGET_SPARC64
2348 stfq_hypv(addr
, DT0
);
2355 address_mask(env
, &addr
);
2356 stfq_raw(addr
, DT0
);
2360 void helper_lddf(target_ulong addr
, int mem_idx
)
2362 helper_check_align(addr
, 7);
2363 #if !defined(CONFIG_USER_ONLY)
2366 DT0
= ldfq_user(addr
);
2369 DT0
= ldfq_kernel(addr
);
2371 #ifdef TARGET_SPARC64
2373 DT0
= ldfq_hypv(addr
);
2380 address_mask(env
, &addr
);
2381 DT0
= ldfq_raw(addr
);
2385 void helper_ldqf(target_ulong addr
, int mem_idx
)
2387 // XXX add 128 bit load
2390 helper_check_align(addr
, 7);
2391 #if !defined(CONFIG_USER_ONLY)
2394 u
.ll
.upper
= ldq_user(addr
);
2395 u
.ll
.lower
= ldq_user(addr
+ 8);
2399 u
.ll
.upper
= ldq_kernel(addr
);
2400 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2403 #ifdef TARGET_SPARC64
2405 u
.ll
.upper
= ldq_hypv(addr
);
2406 u
.ll
.lower
= ldq_hypv(addr
+ 8);
2414 address_mask(env
, &addr
);
2415 u
.ll
.upper
= ldq_raw(addr
);
2416 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
2421 void helper_stqf(target_ulong addr
, int mem_idx
)
2423 // XXX add 128 bit store
2426 helper_check_align(addr
, 7);
2427 #if !defined(CONFIG_USER_ONLY)
2431 stq_user(addr
, u
.ll
.upper
);
2432 stq_user(addr
+ 8, u
.ll
.lower
);
2436 stq_kernel(addr
, u
.ll
.upper
);
2437 stq_kernel(addr
+ 8, u
.ll
.lower
);
2439 #ifdef TARGET_SPARC64
2442 stq_hypv(addr
, u
.ll
.upper
);
2443 stq_hypv(addr
+ 8, u
.ll
.lower
);
2451 address_mask(env
, &addr
);
2452 stq_raw(addr
, u
.ll
.upper
);
2453 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
2457 void helper_ldfsr(void)
2461 PUT_FSR32(env
, *((uint32_t *) &FT0
));
2462 switch (env
->fsr
& FSR_RD_MASK
) {
2463 case FSR_RD_NEAREST
:
2464 rnd_mode
= float_round_nearest_even
;
2468 rnd_mode
= float_round_to_zero
;
2471 rnd_mode
= float_round_up
;
2474 rnd_mode
= float_round_down
;
2477 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
2480 void helper_stfsr(void)
2482 *((uint32_t *) &FT0
) = GET_FSR32(env
);
2485 void helper_debug(void)
2487 env
->exception_index
= EXCP_DEBUG
;
2491 #ifndef TARGET_SPARC64
2492 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2494 void helper_save(void)
2498 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2499 if (env
->wim
& (1 << cwp
)) {
2500 raise_exception(TT_WIN_OVF
);
2505 void helper_restore(void)
2509 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2510 if (env
->wim
& (1 << cwp
)) {
2511 raise_exception(TT_WIN_UNF
);
2516 void helper_wrpsr(target_ulong new_psr
)
2518 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
2519 raise_exception(TT_ILL_INSN
);
2521 PUT_PSR(env
, new_psr
);
2524 target_ulong
helper_rdpsr(void)
2526 return GET_PSR(env
);
2530 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2532 void helper_save(void)
2536 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2537 if (env
->cansave
== 0) {
2538 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2539 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2540 ((env
->wstate
& 0x7) << 2)));
2542 if (env
->cleanwin
- env
->canrestore
== 0) {
2543 // XXX Clean windows without trap
2544 raise_exception(TT_CLRWIN
);
2553 void helper_restore(void)
2557 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2558 if (env
->canrestore
== 0) {
2559 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
2560 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2561 ((env
->wstate
& 0x7) << 2)));
2569 void helper_flushw(void)
2571 if (env
->cansave
!= env
->nwindows
- 2) {
2572 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2573 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2574 ((env
->wstate
& 0x7) << 2)));
2578 void helper_saved(void)
2581 if (env
->otherwin
== 0)
2587 void helper_restored(void)
2590 if (env
->cleanwin
< env
->nwindows
- 1)
2592 if (env
->otherwin
== 0)
2598 target_ulong
helper_rdccr(void)
2600 return GET_CCR(env
);
2603 void helper_wrccr(target_ulong new_ccr
)
2605 PUT_CCR(env
, new_ccr
);
2608 // CWP handling is reversed in V9, but we still use the V8 register
2610 target_ulong
helper_rdcwp(void)
2612 return GET_CWP64(env
);
2615 void helper_wrcwp(target_ulong new_cwp
)
2617 PUT_CWP64(env
, new_cwp
);
2620 // This function uses non-native bit order
2621 #define GET_FIELD(X, FROM, TO) \
2622 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
2624 // This function uses the order in the manuals, i.e. bit 0 is 2^0
2625 #define GET_FIELD_SP(X, FROM, TO) \
2626 GET_FIELD(X, 63 - (TO), 63 - (FROM))
2628 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
2630 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
2631 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
2632 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
2633 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
2634 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
2635 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
2636 (((pixel_addr
>> 55) & 1) << 4) |
2637 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
2638 GET_FIELD_SP(pixel_addr
, 11, 12);
2641 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
2645 tmp
= addr
+ offset
;
2647 env
->gsr
|= tmp
& 7ULL;
2651 target_ulong
helper_popc(target_ulong val
)
2653 return ctpop64(val
);
2656 static inline uint64_t *get_gregset(uint64_t pstate
)
2671 void change_pstate(uint64_t new_pstate
)
2673 uint64_t pstate_regs
, new_pstate_regs
;
2674 uint64_t *src
, *dst
;
2676 pstate_regs
= env
->pstate
& 0xc01;
2677 new_pstate_regs
= new_pstate
& 0xc01;
2678 if (new_pstate_regs
!= pstate_regs
) {
2679 // Switch global register bank
2680 src
= get_gregset(new_pstate_regs
);
2681 dst
= get_gregset(pstate_regs
);
2682 memcpy32(dst
, env
->gregs
);
2683 memcpy32(env
->gregs
, src
);
2685 env
->pstate
= new_pstate
;
2688 void helper_wrpstate(target_ulong new_state
)
2690 if (!(env
->def
->features
& CPU_FEATURE_GL
))
2691 change_pstate(new_state
& 0xf3f);
2694 void helper_done(void)
2696 env
->pc
= env
->tsptr
->tpc
;
2697 env
->npc
= env
->tsptr
->tnpc
+ 4;
2698 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2699 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2700 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2701 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2703 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2706 void helper_retry(void)
2708 env
->pc
= env
->tsptr
->tpc
;
2709 env
->npc
= env
->tsptr
->tnpc
;
2710 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2711 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2712 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2713 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2715 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2719 void cpu_set_cwp(CPUState
*env1
, int new_cwp
)
2721 /* put the modified wrap registers at their proper location */
2722 if (env1
->cwp
== env1
->nwindows
- 1)
2723 memcpy32(env1
->regbase
, env1
->regbase
+ env1
->nwindows
* 16);
2724 env1
->cwp
= new_cwp
;
2725 /* put the wrap registers at their temporary location */
2726 if (new_cwp
== env1
->nwindows
- 1)
2727 memcpy32(env1
->regbase
+ env1
->nwindows
* 16, env1
->regbase
);
2728 env1
->regwptr
= env1
->regbase
+ (new_cwp
* 16);
2731 void set_cwp(int new_cwp
)
2733 cpu_set_cwp(env
, new_cwp
);
2736 void helper_flush(target_ulong addr
)
2739 tb_invalidate_page_range(addr
, addr
+ 8);
2742 #if !defined(CONFIG_USER_ONLY)
2744 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
2747 #define MMUSUFFIX _mmu
2748 #define ALIGNED_ONLY
2751 #include "softmmu_template.h"
2754 #include "softmmu_template.h"
2757 #include "softmmu_template.h"
2760 #include "softmmu_template.h"
2762 /* XXX: make it generic ? */
2763 static void cpu_restore_state2(void *retaddr
)
2765 TranslationBlock
*tb
;
2769 /* now we have a real cpu fault */
2770 pc
= (unsigned long)retaddr
;
2771 tb
= tb_find_pc(pc
);
2773 /* the PC is inside the translated code. It means that we have
2774 a virtual CPU fault */
2775 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
2780 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
2783 #ifdef DEBUG_UNALIGNED
2784 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
2785 "\n", addr
, env
->pc
);
2787 cpu_restore_state2(retaddr
);
2788 raise_exception(TT_UNALIGNED
);
2791 /* try to fill the TLB and return an exception if error. If retaddr is
2792 NULL, it means that the function was called in C code (i.e. not
2793 from generated code or from helper.c) */
2794 /* XXX: fix it to restore all registers */
2795 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
2798 CPUState
*saved_env
;
2800 /* XXX: hack to restore env in all cases, even if not called from
2803 env
= cpu_single_env
;
2805 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
2807 cpu_restore_state2(retaddr
);
2815 #ifndef TARGET_SPARC64
2816 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
2819 CPUState
*saved_env
;
2821 /* XXX: hack to restore env in all cases, even if not called from
2824 env
= cpu_single_env
;
2825 #ifdef DEBUG_UNASSIGNED
2827 printf("Unassigned mem %s access to " TARGET_FMT_plx
2828 " asi 0x%02x from " TARGET_FMT_lx
"\n",
2829 is_exec
? "exec" : is_write
? "write" : "read", addr
, is_asi
,
2832 printf("Unassigned mem %s access to " TARGET_FMT_plx
" from "
2834 is_exec
? "exec" : is_write
? "write" : "read", addr
, env
->pc
);
2836 if (env
->mmuregs
[3]) /* Fault status register */
2837 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
2839 env
->mmuregs
[3] |= 1 << 16;
2841 env
->mmuregs
[3] |= 1 << 5;
2843 env
->mmuregs
[3] |= 1 << 6;
2845 env
->mmuregs
[3] |= 1 << 7;
2846 env
->mmuregs
[3] |= (5 << 2) | 2;
2847 env
->mmuregs
[4] = addr
; /* Fault address register */
2848 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2850 raise_exception(TT_CODE_ACCESS
);
2852 raise_exception(TT_DATA_ACCESS
);
2857 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
2860 #ifdef DEBUG_UNASSIGNED
2861 CPUState
*saved_env
;
2863 /* XXX: hack to restore env in all cases, even if not called from
2866 env
= cpu_single_env
;
2867 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
2868 "\n", addr
, env
->pc
);
2872 raise_exception(TT_CODE_ACCESS
);
2874 raise_exception(TT_DATA_ACCESS
);