]>
git.proxmox.com Git - qemu.git/blob - target-sparc/op_helper.c
2 #include "host-utils.h"
8 //#define DEBUG_UNALIGNED
9 //#define DEBUG_UNASSIGNED
13 #define DPRINTF_MMU(fmt, args...) \
14 do { printf("MMU: " fmt , ##args); } while (0)
16 #define DPRINTF_MMU(fmt, args...)
20 #define DPRINTF_MXCC(fmt, args...) \
21 do { printf("MXCC: " fmt , ##args); } while (0)
23 #define DPRINTF_MXCC(fmt, args...)
27 #define DPRINTF_ASI(fmt, args...) \
28 do { printf("ASI: " fmt , ##args); } while (0)
30 #define DPRINTF_ASI(fmt, args...)
33 void raise_exception(int tt
)
35 env
->exception_index
= tt
;
39 void helper_trap(target_ulong nb_trap
)
41 env
->exception_index
= TT_TRAP
+ (nb_trap
& 0x7f);
45 void helper_trapcc(target_ulong nb_trap
, target_ulong do_trap
)
48 env
->exception_index
= TT_TRAP
+ (nb_trap
& 0x7f);
53 #define F_HELPER(name, p) void helper_f##name##p(void)
55 #if defined(CONFIG_USER_ONLY)
56 #define F_BINOP(name) \
59 FT0 = float32_ ## name (FT0, FT1, &env->fp_status); \
63 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
67 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
70 #define F_BINOP(name) \
73 FT0 = float32_ ## name (FT0, FT1, &env->fp_status); \
77 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
87 void helper_fsmuld(void)
89 DT0
= float64_mul(float32_to_float64(FT0
, &env
->fp_status
),
90 float32_to_float64(FT1
, &env
->fp_status
),
94 #if defined(CONFIG_USER_ONLY)
95 void helper_fdmulq(void)
97 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
98 float64_to_float128(DT1
, &env
->fp_status
),
105 FT0
= float32_chs(FT1
);
108 #ifdef TARGET_SPARC64
111 DT0
= float64_chs(DT1
);
114 #if defined(CONFIG_USER_ONLY)
117 QT0
= float128_chs(QT1
);
122 /* Integer to float conversion. */
125 FT0
= int32_to_float32(*((int32_t *)&FT1
), &env
->fp_status
);
130 DT0
= int32_to_float64(*((int32_t *)&FT1
), &env
->fp_status
);
133 #if defined(CONFIG_USER_ONLY)
136 QT0
= int32_to_float128(*((int32_t *)&FT1
), &env
->fp_status
);
140 #ifdef TARGET_SPARC64
143 FT0
= int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
148 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
150 #if defined(CONFIG_USER_ONLY)
153 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
159 /* floating point conversion */
160 void helper_fdtos(void)
162 FT0
= float64_to_float32(DT1
, &env
->fp_status
);
165 void helper_fstod(void)
167 DT0
= float32_to_float64(FT1
, &env
->fp_status
);
170 #if defined(CONFIG_USER_ONLY)
171 void helper_fqtos(void)
173 FT0
= float128_to_float32(QT1
, &env
->fp_status
);
176 void helper_fstoq(void)
178 QT0
= float32_to_float128(FT1
, &env
->fp_status
);
181 void helper_fqtod(void)
183 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
186 void helper_fdtoq(void)
188 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
192 /* Float to integer conversion. */
193 void helper_fstoi(void)
195 *((int32_t *)&FT0
) = float32_to_int32_round_to_zero(FT1
, &env
->fp_status
);
198 void helper_fdtoi(void)
200 *((int32_t *)&FT0
) = float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
203 #if defined(CONFIG_USER_ONLY)
204 void helper_fqtoi(void)
206 *((int32_t *)&FT0
) = float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
210 #ifdef TARGET_SPARC64
211 void helper_fstox(void)
213 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(FT1
, &env
->fp_status
);
216 void helper_fdtox(void)
218 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
221 #if defined(CONFIG_USER_ONLY)
222 void helper_fqtox(void)
224 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
228 void helper_faligndata(void)
232 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
233 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
234 *((uint64_t *)&DT0
) = tmp
;
237 void helper_movl_FT0_0(void)
239 *((uint32_t *)&FT0
) = 0;
242 void helper_movl_DT0_0(void)
244 *((uint64_t *)&DT0
) = 0;
247 void helper_movl_FT0_1(void)
249 *((uint32_t *)&FT0
) = 0xffffffff;
252 void helper_movl_DT0_1(void)
254 *((uint64_t *)&DT0
) = 0xffffffffffffffffULL
;
257 void helper_fnot(void)
259 *(uint64_t *)&DT0
= ~*(uint64_t *)&DT1
;
262 void helper_fnots(void)
264 *(uint32_t *)&FT0
= ~*(uint32_t *)&FT1
;
267 void helper_fnor(void)
269 *(uint64_t *)&DT0
= ~(*(uint64_t *)&DT0
| *(uint64_t *)&DT1
);
272 void helper_fnors(void)
274 *(uint32_t *)&FT0
= ~(*(uint32_t *)&FT0
| *(uint32_t *)&FT1
);
277 void helper_for(void)
279 *(uint64_t *)&DT0
|= *(uint64_t *)&DT1
;
282 void helper_fors(void)
284 *(uint32_t *)&FT0
|= *(uint32_t *)&FT1
;
287 void helper_fxor(void)
289 *(uint64_t *)&DT0
^= *(uint64_t *)&DT1
;
292 void helper_fxors(void)
294 *(uint32_t *)&FT0
^= *(uint32_t *)&FT1
;
297 void helper_fand(void)
299 *(uint64_t *)&DT0
&= *(uint64_t *)&DT1
;
302 void helper_fands(void)
304 *(uint32_t *)&FT0
&= *(uint32_t *)&FT1
;
307 void helper_fornot(void)
309 *(uint64_t *)&DT0
= *(uint64_t *)&DT0
| ~*(uint64_t *)&DT1
;
312 void helper_fornots(void)
314 *(uint32_t *)&FT0
= *(uint32_t *)&FT0
| ~*(uint32_t *)&FT1
;
317 void helper_fandnot(void)
319 *(uint64_t *)&DT0
= *(uint64_t *)&DT0
& ~*(uint64_t *)&DT1
;
322 void helper_fandnots(void)
324 *(uint32_t *)&FT0
= *(uint32_t *)&FT0
& ~*(uint32_t *)&FT1
;
327 void helper_fnand(void)
329 *(uint64_t *)&DT0
= ~(*(uint64_t *)&DT0
& *(uint64_t *)&DT1
);
332 void helper_fnands(void)
334 *(uint32_t *)&FT0
= ~(*(uint32_t *)&FT0
& *(uint32_t *)&FT1
);
337 void helper_fxnor(void)
339 *(uint64_t *)&DT0
^= ~*(uint64_t *)&DT1
;
342 void helper_fxnors(void)
344 *(uint32_t *)&FT0
^= ~*(uint32_t *)&FT1
;
347 #ifdef WORDS_BIGENDIAN
348 #define VIS_B64(n) b[7 - (n)]
349 #define VIS_W64(n) w[3 - (n)]
350 #define VIS_SW64(n) sw[3 - (n)]
351 #define VIS_L64(n) l[1 - (n)]
352 #define VIS_B32(n) b[3 - (n)]
353 #define VIS_W32(n) w[1 - (n)]
355 #define VIS_B64(n) b[n]
356 #define VIS_W64(n) w[n]
357 #define VIS_SW64(n) sw[n]
358 #define VIS_L64(n) l[n]
359 #define VIS_B32(n) b[n]
360 #define VIS_W32(n) w[n]
378 void helper_fpmerge(void)
385 // Reverse calculation order to handle overlap
386 d
.VIS_B64(7) = s
.VIS_B64(3);
387 d
.VIS_B64(6) = d
.VIS_B64(3);
388 d
.VIS_B64(5) = s
.VIS_B64(2);
389 d
.VIS_B64(4) = d
.VIS_B64(2);
390 d
.VIS_B64(3) = s
.VIS_B64(1);
391 d
.VIS_B64(2) = d
.VIS_B64(1);
392 d
.VIS_B64(1) = s
.VIS_B64(0);
393 //d.VIS_B64(0) = d.VIS_B64(0);
398 void helper_fmul8x16(void)
407 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
408 if ((tmp & 0xff) > 0x7f) \
410 d.VIS_W64(r) = tmp >> 8;
421 void helper_fmul8x16al(void)
430 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
431 if ((tmp & 0xff) > 0x7f) \
433 d.VIS_W64(r) = tmp >> 8;
444 void helper_fmul8x16au(void)
453 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
454 if ((tmp & 0xff) > 0x7f) \
456 d.VIS_W64(r) = tmp >> 8;
467 void helper_fmul8sux16(void)
476 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
477 if ((tmp & 0xff) > 0x7f) \
479 d.VIS_W64(r) = tmp >> 8;
490 void helper_fmul8ulx16(void)
499 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
500 if ((tmp & 0xff) > 0x7f) \
502 d.VIS_W64(r) = tmp >> 8;
513 void helper_fmuld8sux16(void)
522 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
523 if ((tmp & 0xff) > 0x7f) \
527 // Reverse calculation order to handle overlap
535 void helper_fmuld8ulx16(void)
544 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
545 if ((tmp & 0xff) > 0x7f) \
549 // Reverse calculation order to handle overlap
557 void helper_fexpand(void)
562 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
564 d
.VIS_L64(0) = s
.VIS_W32(0) << 4;
565 d
.VIS_L64(1) = s
.VIS_W32(1) << 4;
566 d
.VIS_L64(2) = s
.VIS_W32(2) << 4;
567 d
.VIS_L64(3) = s
.VIS_W32(3) << 4;
572 #define VIS_HELPER(name, F) \
573 void name##16(void) \
580 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
581 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
582 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
583 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
588 void name##16s(void) \
595 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
596 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
601 void name##32(void) \
608 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
609 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
614 void name##32s(void) \
626 #define FADD(a, b) ((a) + (b))
627 #define FSUB(a, b) ((a) - (b))
628 VIS_HELPER(helper_fpadd
, FADD
)
629 VIS_HELPER(helper_fpsub
, FSUB
)
631 #define VIS_CMPHELPER(name, F) \
632 void name##16(void) \
639 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
640 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
641 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
642 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
647 void name##32(void) \
654 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
655 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
660 #define FCMPGT(a, b) ((a) > (b))
661 #define FCMPEQ(a, b) ((a) == (b))
662 #define FCMPLE(a, b) ((a) <= (b))
663 #define FCMPNE(a, b) ((a) != (b))
665 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
666 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
667 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
668 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
671 void helper_check_ieee_exceptions(void)
675 status
= get_float_exception_flags(&env
->fp_status
);
677 /* Copy IEEE 754 flags into FSR */
678 if (status
& float_flag_invalid
)
680 if (status
& float_flag_overflow
)
682 if (status
& float_flag_underflow
)
684 if (status
& float_flag_divbyzero
)
686 if (status
& float_flag_inexact
)
689 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
690 /* Unmasked exception, generate a trap */
691 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
692 raise_exception(TT_FP_EXCP
);
694 /* Accumulate exceptions */
695 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
700 void helper_clear_float_exceptions(void)
702 set_float_exception_flags(0, &env
->fp_status
);
705 void helper_fabss(void)
707 FT0
= float32_abs(FT1
);
710 #ifdef TARGET_SPARC64
711 void helper_fabsd(void)
713 DT0
= float64_abs(DT1
);
716 #if defined(CONFIG_USER_ONLY)
717 void helper_fabsq(void)
719 QT0
= float128_abs(QT1
);
724 void helper_fsqrts(void)
726 FT0
= float32_sqrt(FT1
, &env
->fp_status
);
729 void helper_fsqrtd(void)
731 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
734 #if defined(CONFIG_USER_ONLY)
735 void helper_fsqrtq(void)
737 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
741 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
742 void glue(helper_, name) (void) \
744 target_ulong new_fsr; \
746 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
747 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
748 case float_relation_unordered: \
749 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
750 if ((env->fsr & FSR_NVM) || TRAP) { \
751 env->fsr |= new_fsr; \
752 env->fsr |= FSR_NVC; \
753 env->fsr |= FSR_FTT_IEEE_EXCP; \
754 raise_exception(TT_FP_EXCP); \
756 env->fsr |= FSR_NVA; \
759 case float_relation_less: \
760 new_fsr = FSR_FCC0 << FS; \
762 case float_relation_greater: \
763 new_fsr = FSR_FCC1 << FS; \
769 env->fsr |= new_fsr; \
772 GEN_FCMP(fcmps
, float32
, FT0
, FT1
, 0, 0);
773 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
775 GEN_FCMP(fcmpes
, float32
, FT0
, FT1
, 0, 1);
776 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
778 #ifdef CONFIG_USER_ONLY
779 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
780 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
783 #ifdef TARGET_SPARC64
784 GEN_FCMP(fcmps_fcc1
, float32
, FT0
, FT1
, 22, 0);
785 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
787 GEN_FCMP(fcmps_fcc2
, float32
, FT0
, FT1
, 24, 0);
788 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
790 GEN_FCMP(fcmps_fcc3
, float32
, FT0
, FT1
, 26, 0);
791 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
793 GEN_FCMP(fcmpes_fcc1
, float32
, FT0
, FT1
, 22, 1);
794 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
796 GEN_FCMP(fcmpes_fcc2
, float32
, FT0
, FT1
, 24, 1);
797 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
799 GEN_FCMP(fcmpes_fcc3
, float32
, FT0
, FT1
, 26, 1);
800 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
801 #ifdef CONFIG_USER_ONLY
802 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
803 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
804 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
805 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
806 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
807 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
811 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && defined(DEBUG_MXCC)
812 static void dump_mxcc(CPUState
*env
)
814 printf("mxccdata: %016llx %016llx %016llx %016llx\n",
815 env
->mxccdata
[0], env
->mxccdata
[1], env
->mxccdata
[2], env
->mxccdata
[3]);
816 printf("mxccregs: %016llx %016llx %016llx %016llx\n"
817 " %016llx %016llx %016llx %016llx\n",
818 env
->mxccregs
[0], env
->mxccregs
[1], env
->mxccregs
[2], env
->mxccregs
[3],
819 env
->mxccregs
[4], env
->mxccregs
[5], env
->mxccregs
[6], env
->mxccregs
[7]);
823 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
824 && defined(DEBUG_ASI)
825 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
831 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
832 addr
, asi
, r1
& 0xff);
835 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
836 addr
, asi
, r1
& 0xffff);
839 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
840 addr
, asi
, r1
& 0xffffffff);
843 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
850 #ifndef TARGET_SPARC64
851 #ifndef CONFIG_USER_ONLY
852 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
855 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
856 uint32_t last_addr
= addr
;
860 case 2: /* SuperSparc MXCC registers */
862 case 0x01c00a00: /* MXCC control register */
864 ret
= env
->mxccregs
[3];
866 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
868 case 0x01c00a04: /* MXCC control register */
870 ret
= env
->mxccregs
[3];
872 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
874 case 0x01c00c00: /* Module reset register */
876 ret
= env
->mxccregs
[5];
877 // should we do something here?
879 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
881 case 0x01c00f00: /* MBus port address register */
883 ret
= env
->mxccregs
[7];
885 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
888 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
, size
);
891 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, addr = %08x -> ret = %08x,"
892 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
897 case 3: /* MMU probe */
901 mmulev
= (addr
>> 8) & 15;
905 ret
= mmu_probe(env
, addr
, mmulev
);
906 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
910 case 4: /* read MMU regs */
912 int reg
= (addr
>> 8) & 0x1f;
914 ret
= env
->mmuregs
[reg
];
915 if (reg
== 3) /* Fault status cleared on read */
917 else if (reg
== 0x13) /* Fault status read */
918 ret
= env
->mmuregs
[3];
919 else if (reg
== 0x14) /* Fault address read */
920 ret
= env
->mmuregs
[4];
921 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
924 case 5: // Turbosparc ITLB Diagnostic
925 case 6: // Turbosparc DTLB Diagnostic
926 case 7: // Turbosparc IOTLB Diagnostic
928 case 9: /* Supervisor code access */
931 ret
= ldub_code(addr
);
934 ret
= lduw_code(addr
& ~1);
938 ret
= ldl_code(addr
& ~3);
941 ret
= ldq_code(addr
& ~7);
945 case 0xa: /* User data access */
948 ret
= ldub_user(addr
);
951 ret
= lduw_user(addr
& ~1);
955 ret
= ldl_user(addr
& ~3);
958 ret
= ldq_user(addr
& ~7);
962 case 0xb: /* Supervisor data access */
965 ret
= ldub_kernel(addr
);
968 ret
= lduw_kernel(addr
& ~1);
972 ret
= ldl_kernel(addr
& ~3);
975 ret
= ldq_kernel(addr
& ~7);
979 case 0xc: /* I-cache tag */
980 case 0xd: /* I-cache data */
981 case 0xe: /* D-cache tag */
982 case 0xf: /* D-cache data */
984 case 0x20: /* MMU passthrough */
987 ret
= ldub_phys(addr
);
990 ret
= lduw_phys(addr
& ~1);
994 ret
= ldl_phys(addr
& ~3);
997 ret
= ldq_phys(addr
& ~7);
1001 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1004 ret
= ldub_phys((target_phys_addr_t
)addr
1005 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1008 ret
= lduw_phys((target_phys_addr_t
)(addr
& ~1)
1009 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1013 ret
= ldl_phys((target_phys_addr_t
)(addr
& ~3)
1014 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1017 ret
= ldq_phys((target_phys_addr_t
)(addr
& ~7)
1018 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1022 case 0x30: // Turbosparc secondary cache diagnostic
1023 case 0x31: // Turbosparc RAM snoop
1024 case 0x32: // Turbosparc page table descriptor diagnostic
1025 case 0x39: /* data cache diagnostic register */
1028 case 8: /* User code access, XXX */
1030 do_unassigned_access(addr
, 0, 0, asi
);
1040 ret
= (int16_t) ret
;
1043 ret
= (int32_t) ret
;
1050 dump_asi("read ", last_addr
, asi
, size
, ret
);
1055 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1058 case 2: /* SuperSparc MXCC registers */
1060 case 0x01c00000: /* MXCC stream data register 0 */
1062 env
->mxccdata
[0] = val
;
1064 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1066 case 0x01c00008: /* MXCC stream data register 1 */
1068 env
->mxccdata
[1] = val
;
1070 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1072 case 0x01c00010: /* MXCC stream data register 2 */
1074 env
->mxccdata
[2] = val
;
1076 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1078 case 0x01c00018: /* MXCC stream data register 3 */
1080 env
->mxccdata
[3] = val
;
1082 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1084 case 0x01c00100: /* MXCC stream source */
1086 env
->mxccregs
[0] = val
;
1088 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1089 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 0);
1090 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 8);
1091 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 16);
1092 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 24);
1094 case 0x01c00200: /* MXCC stream destination */
1096 env
->mxccregs
[1] = val
;
1098 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1099 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0, env
->mxccdata
[0]);
1100 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8, env
->mxccdata
[1]);
1101 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16, env
->mxccdata
[2]);
1102 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24, env
->mxccdata
[3]);
1104 case 0x01c00a00: /* MXCC control register */
1106 env
->mxccregs
[3] = val
;
1108 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1110 case 0x01c00a04: /* MXCC control register */
1112 env
->mxccregs
[3] = (env
->mxccregs
[0xa] & 0xffffffff00000000ULL
) | val
;
1114 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1116 case 0x01c00e00: /* MXCC error register */
1117 // writing a 1 bit clears the error
1119 env
->mxccregs
[6] &= ~val
;
1121 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1123 case 0x01c00f00: /* MBus port address register */
1125 env
->mxccregs
[7] = val
;
1127 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
, size
);
1130 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
, size
);
1133 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %08x\n", asi
, size
, addr
, val
);
1138 case 3: /* MMU flush */
1142 mmulev
= (addr
>> 8) & 15;
1143 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1145 case 0: // flush page
1146 tlb_flush_page(env
, addr
& 0xfffff000);
1148 case 1: // flush segment (256k)
1149 case 2: // flush region (16M)
1150 case 3: // flush context (4G)
1151 case 4: // flush entire
1162 case 4: /* write MMU regs */
1164 int reg
= (addr
>> 8) & 0x1f;
1167 oldreg
= env
->mmuregs
[reg
];
1169 case 0: // Control Register
1170 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1172 // Mappings generated during no-fault mode or MMU
1173 // disabled mode are invalid in normal mode
1174 if ((oldreg
& (MMU_E
| MMU_NF
| env
->mmu_bm
)) !=
1175 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->mmu_bm
)))
1178 case 1: // Context Table Pointer Register
1179 env
->mmuregs
[reg
] = val
& env
->mmu_ctpr_mask
;
1181 case 2: // Context Register
1182 env
->mmuregs
[reg
] = val
& env
->mmu_cxr_mask
;
1183 if (oldreg
!= env
->mmuregs
[reg
]) {
1184 /* we flush when the MMU context changes because
1185 QEMU has no MMU context support */
1189 case 3: // Synchronous Fault Status Register with Clear
1190 case 4: // Synchronous Fault Address Register
1192 case 0x10: // TLB Replacement Control Register
1193 env
->mmuregs
[reg
] = val
& env
->mmu_trcr_mask
;
1195 case 0x13: // Synchronous Fault Status Register with Read and Clear
1196 env
->mmuregs
[3] = val
& env
->mmu_sfsr_mask
;
1198 case 0x14: // Synchronous Fault Address Register
1199 env
->mmuregs
[4] = val
;
1202 env
->mmuregs
[reg
] = val
;
1205 if (oldreg
!= env
->mmuregs
[reg
]) {
1206 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n", reg
, oldreg
, env
->mmuregs
[reg
]);
1213 case 5: // Turbosparc ITLB Diagnostic
1214 case 6: // Turbosparc DTLB Diagnostic
1215 case 7: // Turbosparc IOTLB Diagnostic
1217 case 0xa: /* User data access */
1220 stb_user(addr
, val
);
1223 stw_user(addr
& ~1, val
);
1227 stl_user(addr
& ~3, val
);
1230 stq_user(addr
& ~7, val
);
1234 case 0xb: /* Supervisor data access */
1237 stb_kernel(addr
, val
);
1240 stw_kernel(addr
& ~1, val
);
1244 stl_kernel(addr
& ~3, val
);
1247 stq_kernel(addr
& ~7, val
);
1251 case 0xc: /* I-cache tag */
1252 case 0xd: /* I-cache data */
1253 case 0xe: /* D-cache tag */
1254 case 0xf: /* D-cache data */
1255 case 0x10: /* I/D-cache flush page */
1256 case 0x11: /* I/D-cache flush segment */
1257 case 0x12: /* I/D-cache flush region */
1258 case 0x13: /* I/D-cache flush context */
1259 case 0x14: /* I/D-cache flush user */
1261 case 0x17: /* Block copy, sta access */
1267 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1269 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1270 temp
= ldl_kernel(src
);
1271 stl_kernel(dst
, temp
);
1275 case 0x1f: /* Block fill, stda access */
1278 // fill 32 bytes with val
1280 uint32_t dst
= addr
& 7;
1282 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1283 stq_kernel(dst
, val
);
1286 case 0x20: /* MMU passthrough */
1290 stb_phys(addr
, val
);
1293 stw_phys(addr
& ~1, val
);
1297 stl_phys(addr
& ~3, val
);
1300 stq_phys(addr
& ~7, val
);
1305 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1309 stb_phys((target_phys_addr_t
)addr
1310 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1313 stw_phys((target_phys_addr_t
)(addr
& ~1)
1314 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1318 stl_phys((target_phys_addr_t
)(addr
& ~3)
1319 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1322 stq_phys((target_phys_addr_t
)(addr
& ~7)
1323 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1328 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1329 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1330 // Turbosparc snoop RAM
1331 case 0x32: // store buffer control or Turbosparc page table descriptor diagnostic
1332 case 0x36: /* I-cache flash clear */
1333 case 0x37: /* D-cache flash clear */
1334 case 0x38: /* breakpoint diagnostics */
1335 case 0x4c: /* breakpoint action */
1337 case 8: /* User code access, XXX */
1338 case 9: /* Supervisor code access, XXX */
1340 do_unassigned_access(addr
, 1, 0, asi
);
1344 dump_asi("write", addr
, asi
, size
, val
);
1348 #endif /* CONFIG_USER_ONLY */
1349 #else /* TARGET_SPARC64 */
1351 #ifdef CONFIG_USER_ONLY
1352 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1355 #if defined(DEBUG_ASI)
1356 target_ulong last_addr
= addr
;
1360 raise_exception(TT_PRIV_ACT
);
1363 case 0x80: // Primary
1364 case 0x82: // Primary no-fault
1365 case 0x88: // Primary LE
1366 case 0x8a: // Primary no-fault LE
1370 ret
= ldub_raw(addr
);
1373 ret
= lduw_raw(addr
& ~1);
1376 ret
= ldl_raw(addr
& ~3);
1380 ret
= ldq_raw(addr
& ~7);
1385 case 0x81: // Secondary
1386 case 0x83: // Secondary no-fault
1387 case 0x89: // Secondary LE
1388 case 0x8b: // Secondary no-fault LE
1395 /* Convert from little endian */
1397 case 0x88: // Primary LE
1398 case 0x89: // Secondary LE
1399 case 0x8a: // Primary no-fault LE
1400 case 0x8b: // Secondary no-fault LE
1418 /* Convert to signed number */
1425 ret
= (int16_t) ret
;
1428 ret
= (int32_t) ret
;
1435 dump_asi("read ", last_addr
, asi
, size
, ret
);
1440 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1443 dump_asi("write", addr
, asi
, size
, val
);
1446 raise_exception(TT_PRIV_ACT
);
1448 /* Convert to little endian */
1450 case 0x88: // Primary LE
1451 case 0x89: // Secondary LE
1454 addr
= bswap16(addr
);
1457 addr
= bswap32(addr
);
1460 addr
= bswap64(addr
);
1470 case 0x80: // Primary
1471 case 0x88: // Primary LE
1478 stw_raw(addr
& ~1, val
);
1481 stl_raw(addr
& ~3, val
);
1485 stq_raw(addr
& ~7, val
);
1490 case 0x81: // Secondary
1491 case 0x89: // Secondary LE
1495 case 0x82: // Primary no-fault, RO
1496 case 0x83: // Secondary no-fault, RO
1497 case 0x8a: // Primary no-fault LE, RO
1498 case 0x8b: // Secondary no-fault LE, RO
1500 do_unassigned_access(addr
, 1, 0, 1);
1505 #else /* CONFIG_USER_ONLY */
1507 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1510 #if defined(DEBUG_ASI)
1511 target_ulong last_addr
= addr
;
1514 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1515 || (asi
>= 0x30 && asi
< 0x80 && !(env
->hpstate
& HS_PRIV
)))
1516 raise_exception(TT_PRIV_ACT
);
1519 case 0x10: // As if user primary
1520 case 0x18: // As if user primary LE
1521 case 0x80: // Primary
1522 case 0x82: // Primary no-fault
1523 case 0x88: // Primary LE
1524 case 0x8a: // Primary no-fault LE
1525 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1526 if (env
->hpstate
& HS_PRIV
) {
1529 ret
= ldub_hypv(addr
);
1532 ret
= lduw_hypv(addr
& ~1);
1535 ret
= ldl_hypv(addr
& ~3);
1539 ret
= ldq_hypv(addr
& ~7);
1545 ret
= ldub_kernel(addr
);
1548 ret
= lduw_kernel(addr
& ~1);
1551 ret
= ldl_kernel(addr
& ~3);
1555 ret
= ldq_kernel(addr
& ~7);
1562 ret
= ldub_user(addr
);
1565 ret
= lduw_user(addr
& ~1);
1568 ret
= ldl_user(addr
& ~3);
1572 ret
= ldq_user(addr
& ~7);
1577 case 0x14: // Bypass
1578 case 0x15: // Bypass, non-cacheable
1579 case 0x1c: // Bypass LE
1580 case 0x1d: // Bypass, non-cacheable LE
1584 ret
= ldub_phys(addr
);
1587 ret
= lduw_phys(addr
& ~1);
1590 ret
= ldl_phys(addr
& ~3);
1594 ret
= ldq_phys(addr
& ~7);
1599 case 0x04: // Nucleus
1600 case 0x0c: // Nucleus Little Endian (LE)
1601 case 0x11: // As if user secondary
1602 case 0x19: // As if user secondary LE
1603 case 0x24: // Nucleus quad LDD 128 bit atomic
1604 case 0x2c: // Nucleus quad LDD 128 bit atomic
1605 case 0x4a: // UPA config
1606 case 0x81: // Secondary
1607 case 0x83: // Secondary no-fault
1608 case 0x89: // Secondary LE
1609 case 0x8b: // Secondary no-fault LE
1615 case 0x50: // I-MMU regs
1617 int reg
= (addr
>> 3) & 0xf;
1619 ret
= env
->immuregs
[reg
];
1622 case 0x51: // I-MMU 8k TSB pointer
1623 case 0x52: // I-MMU 64k TSB pointer
1624 case 0x55: // I-MMU data access
1627 case 0x56: // I-MMU tag read
1631 for (i
= 0; i
< 64; i
++) {
1632 // Valid, ctx match, vaddr match
1633 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) != 0 &&
1634 env
->itlb_tag
[i
] == addr
) {
1635 ret
= env
->itlb_tag
[i
];
1641 case 0x58: // D-MMU regs
1643 int reg
= (addr
>> 3) & 0xf;
1645 ret
= env
->dmmuregs
[reg
];
1648 case 0x5e: // D-MMU tag read
1652 for (i
= 0; i
< 64; i
++) {
1653 // Valid, ctx match, vaddr match
1654 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) != 0 &&
1655 env
->dtlb_tag
[i
] == addr
) {
1656 ret
= env
->dtlb_tag
[i
];
1662 case 0x59: // D-MMU 8k TSB pointer
1663 case 0x5a: // D-MMU 64k TSB pointer
1664 case 0x5b: // D-MMU data pointer
1665 case 0x5d: // D-MMU data access
1666 case 0x48: // Interrupt dispatch, RO
1667 case 0x49: // Interrupt data receive
1668 case 0x7f: // Incoming interrupt vector, RO
1671 case 0x54: // I-MMU data in, WO
1672 case 0x57: // I-MMU demap, WO
1673 case 0x5c: // D-MMU data in, WO
1674 case 0x5f: // D-MMU demap, WO
1675 case 0x77: // Interrupt vector, WO
1677 do_unassigned_access(addr
, 0, 0, 1);
1682 /* Convert from little endian */
1684 case 0x0c: // Nucleus Little Endian (LE)
1685 case 0x18: // As if user primary LE
1686 case 0x19: // As if user secondary LE
1687 case 0x1c: // Bypass LE
1688 case 0x1d: // Bypass, non-cacheable LE
1689 case 0x88: // Primary LE
1690 case 0x89: // Secondary LE
1691 case 0x8a: // Primary no-fault LE
1692 case 0x8b: // Secondary no-fault LE
1710 /* Convert to signed number */
1717 ret
= (int16_t) ret
;
1720 ret
= (int32_t) ret
;
1727 dump_asi("read ", last_addr
, asi
, size
, ret
);
1732 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1735 dump_asi("write", addr
, asi
, size
, val
);
1737 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1738 || (asi
>= 0x30 && asi
< 0x80 && !(env
->hpstate
& HS_PRIV
)))
1739 raise_exception(TT_PRIV_ACT
);
1741 /* Convert to little endian */
1743 case 0x0c: // Nucleus Little Endian (LE)
1744 case 0x18: // As if user primary LE
1745 case 0x19: // As if user secondary LE
1746 case 0x1c: // Bypass LE
1747 case 0x1d: // Bypass, non-cacheable LE
1748 case 0x88: // Primary LE
1749 case 0x89: // Secondary LE
1752 addr
= bswap16(addr
);
1755 addr
= bswap32(addr
);
1758 addr
= bswap64(addr
);
1768 case 0x10: // As if user primary
1769 case 0x18: // As if user primary LE
1770 case 0x80: // Primary
1771 case 0x88: // Primary LE
1772 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1773 if (env
->hpstate
& HS_PRIV
) {
1776 stb_hypv(addr
, val
);
1779 stw_hypv(addr
& ~1, val
);
1782 stl_hypv(addr
& ~3, val
);
1786 stq_hypv(addr
& ~7, val
);
1792 stb_kernel(addr
, val
);
1795 stw_kernel(addr
& ~1, val
);
1798 stl_kernel(addr
& ~3, val
);
1802 stq_kernel(addr
& ~7, val
);
1809 stb_user(addr
, val
);
1812 stw_user(addr
& ~1, val
);
1815 stl_user(addr
& ~3, val
);
1819 stq_user(addr
& ~7, val
);
1824 case 0x14: // Bypass
1825 case 0x15: // Bypass, non-cacheable
1826 case 0x1c: // Bypass LE
1827 case 0x1d: // Bypass, non-cacheable LE
1831 stb_phys(addr
, val
);
1834 stw_phys(addr
& ~1, val
);
1837 stl_phys(addr
& ~3, val
);
1841 stq_phys(addr
& ~7, val
);
1846 case 0x04: // Nucleus
1847 case 0x0c: // Nucleus Little Endian (LE)
1848 case 0x11: // As if user secondary
1849 case 0x19: // As if user secondary LE
1850 case 0x24: // Nucleus quad LDD 128 bit atomic
1851 case 0x2c: // Nucleus quad LDD 128 bit atomic
1852 case 0x4a: // UPA config
1853 case 0x81: // Secondary
1854 case 0x89: // Secondary LE
1862 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1863 // Mappings generated during D/I MMU disabled mode are
1864 // invalid in normal mode
1865 if (oldreg
!= env
->lsu
) {
1866 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n", oldreg
, env
->lsu
);
1874 case 0x50: // I-MMU regs
1876 int reg
= (addr
>> 3) & 0xf;
1879 oldreg
= env
->immuregs
[reg
];
1884 case 1: // Not in I-MMU
1891 val
= 0; // Clear SFSR
1893 case 5: // TSB access
1894 case 6: // Tag access
1898 env
->immuregs
[reg
] = val
;
1899 if (oldreg
!= env
->immuregs
[reg
]) {
1900 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08" PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1907 case 0x54: // I-MMU data in
1911 // Try finding an invalid entry
1912 for (i
= 0; i
< 64; i
++) {
1913 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
1914 env
->itlb_tag
[i
] = env
->immuregs
[6];
1915 env
->itlb_tte
[i
] = val
;
1919 // Try finding an unlocked entry
1920 for (i
= 0; i
< 64; i
++) {
1921 if ((env
->itlb_tte
[i
] & 0x40) == 0) {
1922 env
->itlb_tag
[i
] = env
->immuregs
[6];
1923 env
->itlb_tte
[i
] = val
;
1930 case 0x55: // I-MMU data access
1932 unsigned int i
= (addr
>> 3) & 0x3f;
1934 env
->itlb_tag
[i
] = env
->immuregs
[6];
1935 env
->itlb_tte
[i
] = val
;
1938 case 0x57: // I-MMU demap
1941 case 0x58: // D-MMU regs
1943 int reg
= (addr
>> 3) & 0xf;
1946 oldreg
= env
->dmmuregs
[reg
];
1952 if ((val
& 1) == 0) {
1953 val
= 0; // Clear SFSR, Fault address
1954 env
->dmmuregs
[4] = 0;
1956 env
->dmmuregs
[reg
] = val
;
1958 case 1: // Primary context
1959 case 2: // Secondary context
1960 case 5: // TSB access
1961 case 6: // Tag access
1962 case 7: // Virtual Watchpoint
1963 case 8: // Physical Watchpoint
1967 env
->dmmuregs
[reg
] = val
;
1968 if (oldreg
!= env
->dmmuregs
[reg
]) {
1969 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08" PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1976 case 0x5c: // D-MMU data in
1980 // Try finding an invalid entry
1981 for (i
= 0; i
< 64; i
++) {
1982 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
1983 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
1984 env
->dtlb_tte
[i
] = val
;
1988 // Try finding an unlocked entry
1989 for (i
= 0; i
< 64; i
++) {
1990 if ((env
->dtlb_tte
[i
] & 0x40) == 0) {
1991 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
1992 env
->dtlb_tte
[i
] = val
;
1999 case 0x5d: // D-MMU data access
2001 unsigned int i
= (addr
>> 3) & 0x3f;
2003 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2004 env
->dtlb_tte
[i
] = val
;
2007 case 0x5f: // D-MMU demap
2008 case 0x49: // Interrupt data receive
2011 case 0x51: // I-MMU 8k TSB pointer, RO
2012 case 0x52: // I-MMU 64k TSB pointer, RO
2013 case 0x56: // I-MMU tag read, RO
2014 case 0x59: // D-MMU 8k TSB pointer, RO
2015 case 0x5a: // D-MMU 64k TSB pointer, RO
2016 case 0x5b: // D-MMU data pointer, RO
2017 case 0x5e: // D-MMU tag read, RO
2018 case 0x48: // Interrupt dispatch, RO
2019 case 0x7f: // Incoming interrupt vector, RO
2020 case 0x82: // Primary no-fault, RO
2021 case 0x83: // Secondary no-fault, RO
2022 case 0x8a: // Primary no-fault LE, RO
2023 case 0x8b: // Secondary no-fault LE, RO
2025 do_unassigned_access(addr
, 1, 0, 1);
2029 #endif /* CONFIG_USER_ONLY */
2031 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2037 case 0xf0: // Block load primary
2038 case 0xf1: // Block load secondary
2039 case 0xf8: // Block load primary LE
2040 case 0xf9: // Block load secondary LE
2042 raise_exception(TT_ILL_INSN
);
2046 raise_exception(TT_UNALIGNED
);
2049 for (i
= 0; i
< 16; i
++) {
2050 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4, 0);
2059 val
= helper_ld_asi(addr
, asi
, size
, 0);
2063 *((uint32_t *)&FT0
) = val
;
2066 *((int64_t *)&DT0
) = val
;
2068 #if defined(CONFIG_USER_ONLY)
2076 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2079 target_ulong val
= 0;
2082 case 0xf0: // Block store primary
2083 case 0xf1: // Block store secondary
2084 case 0xf8: // Block store primary LE
2085 case 0xf9: // Block store secondary LE
2087 raise_exception(TT_ILL_INSN
);
2091 raise_exception(TT_UNALIGNED
);
2094 for (i
= 0; i
< 16; i
++) {
2095 val
= *(uint32_t *)&env
->fpr
[rd
++];
2096 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2108 val
= *((uint32_t *)&FT0
);
2111 val
= *((int64_t *)&DT0
);
2113 #if defined(CONFIG_USER_ONLY)
2119 helper_st_asi(addr
, val
, asi
, size
);
2122 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2123 target_ulong val2
, uint32_t asi
)
2127 val1
&= 0xffffffffUL
;
2128 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2129 ret
&= 0xffffffffUL
;
2131 helper_st_asi(addr
, val2
& 0xffffffffUL
, asi
, 4);
2135 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2136 target_ulong val2
, uint32_t asi
)
2140 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2142 helper_st_asi(addr
, val2
, asi
, 8);
2145 #endif /* TARGET_SPARC64 */
2147 #ifndef TARGET_SPARC64
2148 void helper_rett(void)
2152 if (env
->psret
== 1)
2153 raise_exception(TT_ILL_INSN
);
2156 cwp
= (env
->cwp
+ 1) & (NWINDOWS
- 1);
2157 if (env
->wim
& (1 << cwp
)) {
2158 raise_exception(TT_WIN_UNF
);
2161 env
->psrs
= env
->psrps
;
2165 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2170 x0
= a
| ((uint64_t) (env
->y
) << 32);
2174 raise_exception(TT_DIV_ZERO
);
2178 if (x0
> 0xffffffff) {
2187 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2192 x0
= a
| ((int64_t) (env
->y
) << 32);
2196 raise_exception(TT_DIV_ZERO
);
2200 if ((int32_t) x0
!= x0
) {
2202 return x0
< 0? 0x80000000: 0x7fffffff;
2209 uint64_t helper_pack64(target_ulong high
, target_ulong low
)
2211 return ((uint64_t)high
<< 32) | (uint64_t)(low
& 0xffffffff);
2214 void helper_ldfsr(void)
2218 PUT_FSR32(env
, *((uint32_t *) &FT0
));
2219 switch (env
->fsr
& FSR_RD_MASK
) {
2220 case FSR_RD_NEAREST
:
2221 rnd_mode
= float_round_nearest_even
;
2225 rnd_mode
= float_round_to_zero
;
2228 rnd_mode
= float_round_up
;
2231 rnd_mode
= float_round_down
;
2234 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
2237 void helper_stfsr(void)
2239 *((uint32_t *) &FT0
) = GET_FSR32(env
);
2242 void helper_debug(void)
2244 env
->exception_index
= EXCP_DEBUG
;
2248 #ifndef TARGET_SPARC64
2249 void helper_wrpsr(target_ulong new_psr
)
2251 if ((new_psr
& PSR_CWP
) >= NWINDOWS
)
2252 raise_exception(TT_ILL_INSN
);
2254 PUT_PSR(env
, new_psr
);
2257 target_ulong
helper_rdpsr(void)
2259 return GET_PSR(env
);
2263 target_ulong
helper_rdccr(void)
2265 return GET_CCR(env
);
2268 void helper_wrccr(target_ulong new_ccr
)
2270 PUT_CCR(env
, new_ccr
);
2273 // CWP handling is reversed in V9, but we still use the V8 register
2275 target_ulong
helper_rdcwp(void)
2277 return GET_CWP64(env
);
2280 void helper_wrcwp(target_ulong new_cwp
)
2282 PUT_CWP64(env
, new_cwp
);
2285 // This function uses non-native bit order
2286 #define GET_FIELD(X, FROM, TO) \
2287 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
2289 // This function uses the order in the manuals, i.e. bit 0 is 2^0
2290 #define GET_FIELD_SP(X, FROM, TO) \
2291 GET_FIELD(X, 63 - (TO), 63 - (FROM))
2293 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
2295 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
2296 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
2297 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
2298 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
2299 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
2300 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
2301 (((pixel_addr
>> 55) & 1) << 4) |
2302 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
2303 GET_FIELD_SP(pixel_addr
, 11, 12);
2306 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
2310 tmp
= addr
+ offset
;
2312 env
->gsr
|= tmp
& 7ULL;
2316 target_ulong
helper_popc(target_ulong val
)
2318 return ctpop64(val
);
2321 static inline uint64_t *get_gregset(uint64_t pstate
)
2336 static inline void change_pstate(uint64_t new_pstate
)
2338 uint64_t pstate_regs
, new_pstate_regs
;
2339 uint64_t *src
, *dst
;
2341 pstate_regs
= env
->pstate
& 0xc01;
2342 new_pstate_regs
= new_pstate
& 0xc01;
2343 if (new_pstate_regs
!= pstate_regs
) {
2344 // Switch global register bank
2345 src
= get_gregset(new_pstate_regs
);
2346 dst
= get_gregset(pstate_regs
);
2347 memcpy32(dst
, env
->gregs
);
2348 memcpy32(env
->gregs
, src
);
2350 env
->pstate
= new_pstate
;
2353 void helper_wrpstate(target_ulong new_state
)
2355 change_pstate(new_state
& 0xf3f);
2358 void helper_done(void)
2361 env
->tsptr
= &env
->ts
[env
->tl
];
2362 env
->pc
= env
->tsptr
->tpc
;
2363 env
->npc
= env
->tsptr
->tnpc
+ 4;
2364 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2365 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2366 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2367 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2370 void helper_retry(void)
2373 env
->tsptr
= &env
->ts
[env
->tl
];
2374 env
->pc
= env
->tsptr
->tpc
;
2375 env
->npc
= env
->tsptr
->tnpc
;
2376 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2377 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2378 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2379 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2383 void set_cwp(int new_cwp
)
2385 /* put the modified wrap registers at their proper location */
2386 if (env
->cwp
== (NWINDOWS
- 1))
2387 memcpy32(env
->regbase
, env
->regbase
+ NWINDOWS
* 16);
2389 /* put the wrap registers at their temporary location */
2390 if (new_cwp
== (NWINDOWS
- 1))
2391 memcpy32(env
->regbase
+ NWINDOWS
* 16, env
->regbase
);
2392 env
->regwptr
= env
->regbase
+ (new_cwp
* 16);
2393 REGWPTR
= env
->regwptr
;
2396 void cpu_set_cwp(CPUState
*env1
, int new_cwp
)
2398 CPUState
*saved_env
;
2400 target_ulong
*saved_regwptr
;
2405 saved_regwptr
= REGWPTR
;
2411 REGWPTR
= saved_regwptr
;
2415 #ifdef TARGET_SPARC64
2417 static const char * const excp_names
[0x50] = {
2418 [TT_TFAULT
] = "Instruction Access Fault",
2419 [TT_TMISS
] = "Instruction Access MMU Miss",
2420 [TT_CODE_ACCESS
] = "Instruction Access Error",
2421 [TT_ILL_INSN
] = "Illegal Instruction",
2422 [TT_PRIV_INSN
] = "Privileged Instruction",
2423 [TT_NFPU_INSN
] = "FPU Disabled",
2424 [TT_FP_EXCP
] = "FPU Exception",
2425 [TT_TOVF
] = "Tag Overflow",
2426 [TT_CLRWIN
] = "Clean Windows",
2427 [TT_DIV_ZERO
] = "Division By Zero",
2428 [TT_DFAULT
] = "Data Access Fault",
2429 [TT_DMISS
] = "Data Access MMU Miss",
2430 [TT_DATA_ACCESS
] = "Data Access Error",
2431 [TT_DPROT
] = "Data Protection Error",
2432 [TT_UNALIGNED
] = "Unaligned Memory Access",
2433 [TT_PRIV_ACT
] = "Privileged Action",
2434 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2435 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2436 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2437 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2438 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2439 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2440 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2441 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2442 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2443 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2444 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2445 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2446 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2447 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2448 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2452 void do_interrupt(int intno
)
2455 if (loglevel
& CPU_LOG_INT
) {
2459 if (intno
< 0 || intno
>= 0x180 || (intno
> 0x4f && intno
< 0x80))
2461 else if (intno
>= 0x100)
2462 name
= "Trap Instruction";
2463 else if (intno
>= 0xc0)
2464 name
= "Window Fill";
2465 else if (intno
>= 0x80)
2466 name
= "Window Spill";
2468 name
= excp_names
[intno
];
2473 fprintf(logfile
, "%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
2474 " SP=%016" PRIx64
"\n",
2477 env
->npc
, env
->regwptr
[6]);
2478 cpu_dump_state(env
, logfile
, fprintf
, 0);
2484 fprintf(logfile
, " code=");
2485 ptr
= (uint8_t *)env
->pc
;
2486 for(i
= 0; i
< 16; i
++) {
2487 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
2489 fprintf(logfile
, "\n");
2495 #if !defined(CONFIG_USER_ONLY)
2496 if (env
->tl
== MAXTL
) {
2497 cpu_abort(env
, "Trap 0x%04x while trap level is MAXTL, Error state", env
->exception_index
);
2501 env
->tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
2502 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
2504 env
->tsptr
->tpc
= env
->pc
;
2505 env
->tsptr
->tnpc
= env
->npc
;
2506 env
->tsptr
->tt
= intno
;
2507 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
2509 if (intno
== TT_CLRWIN
)
2510 set_cwp((env
->cwp
- 1) & (NWINDOWS
- 1));
2511 else if ((intno
& 0x1c0) == TT_SPILL
)
2512 set_cwp((env
->cwp
- env
->cansave
- 2) & (NWINDOWS
- 1));
2513 else if ((intno
& 0x1c0) == TT_FILL
)
2514 set_cwp((env
->cwp
+ 1) & (NWINDOWS
- 1));
2515 env
->tbr
&= ~0x7fffULL
;
2516 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
2517 if (env
->tl
< MAXTL
- 1) {
2520 env
->pstate
|= PS_RED
;
2521 if (env
->tl
!= MAXTL
)
2524 env
->tsptr
= &env
->ts
[env
->tl
];
2526 env
->npc
= env
->pc
+ 4;
2527 env
->exception_index
= 0;
2531 static const char * const excp_names
[0x80] = {
2532 [TT_TFAULT
] = "Instruction Access Fault",
2533 [TT_ILL_INSN
] = "Illegal Instruction",
2534 [TT_PRIV_INSN
] = "Privileged Instruction",
2535 [TT_NFPU_INSN
] = "FPU Disabled",
2536 [TT_WIN_OVF
] = "Window Overflow",
2537 [TT_WIN_UNF
] = "Window Underflow",
2538 [TT_UNALIGNED
] = "Unaligned Memory Access",
2539 [TT_FP_EXCP
] = "FPU Exception",
2540 [TT_DFAULT
] = "Data Access Fault",
2541 [TT_TOVF
] = "Tag Overflow",
2542 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2543 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2544 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2545 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2546 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2547 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2548 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2549 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2550 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2551 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2552 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2553 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2554 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2555 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2556 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2557 [TT_TOVF
] = "Tag Overflow",
2558 [TT_CODE_ACCESS
] = "Instruction Access Error",
2559 [TT_DATA_ACCESS
] = "Data Access Error",
2560 [TT_DIV_ZERO
] = "Division By Zero",
2561 [TT_NCP_INSN
] = "Coprocessor Disabled",
2565 void do_interrupt(int intno
)
2570 if (loglevel
& CPU_LOG_INT
) {
2574 if (intno
< 0 || intno
>= 0x100)
2576 else if (intno
>= 0x80)
2577 name
= "Trap Instruction";
2579 name
= excp_names
[intno
];
2584 fprintf(logfile
, "%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
2587 env
->npc
, env
->regwptr
[6]);
2588 cpu_dump_state(env
, logfile
, fprintf
, 0);
2594 fprintf(logfile
, " code=");
2595 ptr
= (uint8_t *)env
->pc
;
2596 for(i
= 0; i
< 16; i
++) {
2597 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
2599 fprintf(logfile
, "\n");
2605 #if !defined(CONFIG_USER_ONLY)
2606 if (env
->psret
== 0) {
2607 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state", env
->exception_index
);
2612 cwp
= (env
->cwp
- 1) & (NWINDOWS
- 1);
2614 env
->regwptr
[9] = env
->pc
;
2615 env
->regwptr
[10] = env
->npc
;
2616 env
->psrps
= env
->psrs
;
2618 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
2620 env
->npc
= env
->pc
+ 4;
2621 env
->exception_index
= 0;
2625 #if !defined(CONFIG_USER_ONLY)
2627 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
2630 #define MMUSUFFIX _mmu
2631 #define ALIGNED_ONLY
2633 # define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL))
2635 # define GETPC() (__builtin_return_address(0))
2639 #include "softmmu_template.h"
2642 #include "softmmu_template.h"
2645 #include "softmmu_template.h"
2648 #include "softmmu_template.h"
2650 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
2653 #ifdef DEBUG_UNALIGNED
2654 printf("Unaligned access to 0x%x from 0x%x\n", addr
, env
->pc
);
2656 raise_exception(TT_UNALIGNED
);
2659 /* try to fill the TLB and return an exception if error. If retaddr is
2660 NULL, it means that the function was called in C code (i.e. not
2661 from generated code or from helper.c) */
2662 /* XXX: fix it to restore all registers */
2663 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
2665 TranslationBlock
*tb
;
2668 CPUState
*saved_env
;
2670 /* XXX: hack to restore env in all cases, even if not called from
2673 env
= cpu_single_env
;
2675 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
2678 /* now we have a real cpu fault */
2679 pc
= (unsigned long)retaddr
;
2680 tb
= tb_find_pc(pc
);
2682 /* the PC is inside the translated code. It means that we have
2683 a virtual CPU fault */
2684 cpu_restore_state(tb
, env
, pc
, (void *)T2
);
2694 #ifndef TARGET_SPARC64
2695 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
2698 CPUState
*saved_env
;
2700 /* XXX: hack to restore env in all cases, even if not called from
2703 env
= cpu_single_env
;
2704 #ifdef DEBUG_UNASSIGNED
2706 printf("Unassigned mem %s access to " TARGET_FMT_plx
" asi 0x%02x from "
2708 is_exec
? "exec" : is_write
? "write" : "read", addr
, is_asi
,
2711 printf("Unassigned mem %s access to " TARGET_FMT_plx
" from "
2713 is_exec
? "exec" : is_write
? "write" : "read", addr
, env
->pc
);
2715 if (env
->mmuregs
[3]) /* Fault status register */
2716 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
2718 env
->mmuregs
[3] |= 1 << 16;
2720 env
->mmuregs
[3] |= 1 << 5;
2722 env
->mmuregs
[3] |= 1 << 6;
2724 env
->mmuregs
[3] |= 1 << 7;
2725 env
->mmuregs
[3] |= (5 << 2) | 2;
2726 env
->mmuregs
[4] = addr
; /* Fault address register */
2727 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2729 raise_exception(TT_CODE_ACCESS
);
2731 raise_exception(TT_DATA_ACCESS
);
2736 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
2739 #ifdef DEBUG_UNASSIGNED
2740 CPUState
*saved_env
;
2742 /* XXX: hack to restore env in all cases, even if not called from
2745 env
= cpu_single_env
;
2746 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
"\n",
2751 raise_exception(TT_CODE_ACCESS
);
2753 raise_exception(TT_DATA_ACCESS
);