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 static inline void set_cwp(int new_cwp
)
73 cpu_set_cwp(env
, new_cwp
);
76 void helper_check_align(target_ulong addr
, uint32_t align
)
79 #ifdef DEBUG_UNALIGNED
80 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
83 raise_exception(TT_UNALIGNED
);
87 #define F_HELPER(name, p) void helper_f##name##p(void)
89 #define F_BINOP(name) \
92 FT0 = float32_ ## name (FT0, FT1, &env->fp_status); \
96 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
100 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
109 void helper_fsmuld(void)
111 DT0
= float64_mul(float32_to_float64(FT0
, &env
->fp_status
),
112 float32_to_float64(FT1
, &env
->fp_status
),
116 void helper_fdmulq(void)
118 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
119 float64_to_float128(DT1
, &env
->fp_status
),
125 FT0
= float32_chs(FT1
);
128 #ifdef TARGET_SPARC64
131 DT0
= float64_chs(DT1
);
136 QT0
= float128_chs(QT1
);
140 /* Integer to float conversion. */
143 FT0
= int32_to_float32(*((int32_t *)&FT1
), &env
->fp_status
);
148 DT0
= int32_to_float64(*((int32_t *)&FT1
), &env
->fp_status
);
153 QT0
= int32_to_float128(*((int32_t *)&FT1
), &env
->fp_status
);
156 #ifdef TARGET_SPARC64
159 FT0
= int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
164 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
169 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
174 /* floating point conversion */
175 void helper_fdtos(void)
177 FT0
= float64_to_float32(DT1
, &env
->fp_status
);
180 void helper_fstod(void)
182 DT0
= float32_to_float64(FT1
, &env
->fp_status
);
185 void helper_fqtos(void)
187 FT0
= float128_to_float32(QT1
, &env
->fp_status
);
190 void helper_fstoq(void)
192 QT0
= float32_to_float128(FT1
, &env
->fp_status
);
195 void helper_fqtod(void)
197 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
200 void helper_fdtoq(void)
202 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
205 /* Float to integer conversion. */
206 void helper_fstoi(void)
208 *((int32_t *)&FT0
) = float32_to_int32_round_to_zero(FT1
, &env
->fp_status
);
211 void helper_fdtoi(void)
213 *((int32_t *)&FT0
) = float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
216 void helper_fqtoi(void)
218 *((int32_t *)&FT0
) = float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
221 #ifdef TARGET_SPARC64
222 void helper_fstox(void)
224 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(FT1
, &env
->fp_status
);
227 void helper_fdtox(void)
229 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
232 void helper_fqtox(void)
234 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
237 void helper_faligndata(void)
241 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
242 /* on many architectures a shift of 64 does nothing */
243 if ((env
->gsr
& 7) != 0) {
244 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
246 *((uint64_t *)&DT0
) = tmp
;
249 void helper_movl_FT0_0(void)
251 *((uint32_t *)&FT0
) = 0;
254 void helper_movl_DT0_0(void)
256 *((uint64_t *)&DT0
) = 0;
259 void helper_movl_FT0_1(void)
261 *((uint32_t *)&FT0
) = 0xffffffff;
264 void helper_movl_DT0_1(void)
266 *((uint64_t *)&DT0
) = 0xffffffffffffffffULL
;
269 void helper_fnot(void)
271 *(uint64_t *)&DT0
= ~*(uint64_t *)&DT1
;
274 void helper_fnots(void)
276 *(uint32_t *)&FT0
= ~*(uint32_t *)&FT1
;
279 void helper_fnor(void)
281 *(uint64_t *)&DT0
= ~(*(uint64_t *)&DT0
| *(uint64_t *)&DT1
);
284 void helper_fnors(void)
286 *(uint32_t *)&FT0
= ~(*(uint32_t *)&FT0
| *(uint32_t *)&FT1
);
289 void helper_for(void)
291 *(uint64_t *)&DT0
|= *(uint64_t *)&DT1
;
294 void helper_fors(void)
296 *(uint32_t *)&FT0
|= *(uint32_t *)&FT1
;
299 void helper_fxor(void)
301 *(uint64_t *)&DT0
^= *(uint64_t *)&DT1
;
304 void helper_fxors(void)
306 *(uint32_t *)&FT0
^= *(uint32_t *)&FT1
;
309 void helper_fand(void)
311 *(uint64_t *)&DT0
&= *(uint64_t *)&DT1
;
314 void helper_fands(void)
316 *(uint32_t *)&FT0
&= *(uint32_t *)&FT1
;
319 void helper_fornot(void)
321 *(uint64_t *)&DT0
= *(uint64_t *)&DT0
| ~*(uint64_t *)&DT1
;
324 void helper_fornots(void)
326 *(uint32_t *)&FT0
= *(uint32_t *)&FT0
| ~*(uint32_t *)&FT1
;
329 void helper_fandnot(void)
331 *(uint64_t *)&DT0
= *(uint64_t *)&DT0
& ~*(uint64_t *)&DT1
;
334 void helper_fandnots(void)
336 *(uint32_t *)&FT0
= *(uint32_t *)&FT0
& ~*(uint32_t *)&FT1
;
339 void helper_fnand(void)
341 *(uint64_t *)&DT0
= ~(*(uint64_t *)&DT0
& *(uint64_t *)&DT1
);
344 void helper_fnands(void)
346 *(uint32_t *)&FT0
= ~(*(uint32_t *)&FT0
& *(uint32_t *)&FT1
);
349 void helper_fxnor(void)
351 *(uint64_t *)&DT0
^= ~*(uint64_t *)&DT1
;
354 void helper_fxnors(void)
356 *(uint32_t *)&FT0
^= ~*(uint32_t *)&FT1
;
359 #ifdef WORDS_BIGENDIAN
360 #define VIS_B64(n) b[7 - (n)]
361 #define VIS_W64(n) w[3 - (n)]
362 #define VIS_SW64(n) sw[3 - (n)]
363 #define VIS_L64(n) l[1 - (n)]
364 #define VIS_B32(n) b[3 - (n)]
365 #define VIS_W32(n) w[1 - (n)]
367 #define VIS_B64(n) b[n]
368 #define VIS_W64(n) w[n]
369 #define VIS_SW64(n) sw[n]
370 #define VIS_L64(n) l[n]
371 #define VIS_B32(n) b[n]
372 #define VIS_W32(n) w[n]
390 void helper_fpmerge(void)
397 // Reverse calculation order to handle overlap
398 d
.VIS_B64(7) = s
.VIS_B64(3);
399 d
.VIS_B64(6) = d
.VIS_B64(3);
400 d
.VIS_B64(5) = s
.VIS_B64(2);
401 d
.VIS_B64(4) = d
.VIS_B64(2);
402 d
.VIS_B64(3) = s
.VIS_B64(1);
403 d
.VIS_B64(2) = d
.VIS_B64(1);
404 d
.VIS_B64(1) = s
.VIS_B64(0);
405 //d.VIS_B64(0) = d.VIS_B64(0);
410 void helper_fmul8x16(void)
419 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
420 if ((tmp & 0xff) > 0x7f) \
422 d.VIS_W64(r) = tmp >> 8;
433 void helper_fmul8x16al(void)
442 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
443 if ((tmp & 0xff) > 0x7f) \
445 d.VIS_W64(r) = tmp >> 8;
456 void helper_fmul8x16au(void)
465 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
466 if ((tmp & 0xff) > 0x7f) \
468 d.VIS_W64(r) = tmp >> 8;
479 void helper_fmul8sux16(void)
488 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
489 if ((tmp & 0xff) > 0x7f) \
491 d.VIS_W64(r) = tmp >> 8;
502 void helper_fmul8ulx16(void)
511 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
512 if ((tmp & 0xff) > 0x7f) \
514 d.VIS_W64(r) = tmp >> 8;
525 void helper_fmuld8sux16(void)
534 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
535 if ((tmp & 0xff) > 0x7f) \
539 // Reverse calculation order to handle overlap
547 void helper_fmuld8ulx16(void)
556 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
557 if ((tmp & 0xff) > 0x7f) \
561 // Reverse calculation order to handle overlap
569 void helper_fexpand(void)
574 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
576 d
.VIS_L64(0) = s
.VIS_W32(0) << 4;
577 d
.VIS_L64(1) = s
.VIS_W32(1) << 4;
578 d
.VIS_L64(2) = s
.VIS_W32(2) << 4;
579 d
.VIS_L64(3) = s
.VIS_W32(3) << 4;
584 #define VIS_HELPER(name, F) \
585 void name##16(void) \
592 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
593 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
594 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
595 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
600 void name##16s(void) \
607 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
608 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
613 void name##32(void) \
620 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
621 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
626 void name##32s(void) \
638 #define FADD(a, b) ((a) + (b))
639 #define FSUB(a, b) ((a) - (b))
640 VIS_HELPER(helper_fpadd
, FADD
)
641 VIS_HELPER(helper_fpsub
, FSUB
)
643 #define VIS_CMPHELPER(name, F) \
644 void name##16(void) \
651 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
652 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
653 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
654 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
659 void name##32(void) \
666 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
667 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
672 #define FCMPGT(a, b) ((a) > (b))
673 #define FCMPEQ(a, b) ((a) == (b))
674 #define FCMPLE(a, b) ((a) <= (b))
675 #define FCMPNE(a, b) ((a) != (b))
677 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
678 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
679 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
680 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
683 void helper_check_ieee_exceptions(void)
687 status
= get_float_exception_flags(&env
->fp_status
);
689 /* Copy IEEE 754 flags into FSR */
690 if (status
& float_flag_invalid
)
692 if (status
& float_flag_overflow
)
694 if (status
& float_flag_underflow
)
696 if (status
& float_flag_divbyzero
)
698 if (status
& float_flag_inexact
)
701 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
702 /* Unmasked exception, generate a trap */
703 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
704 raise_exception(TT_FP_EXCP
);
706 /* Accumulate exceptions */
707 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
712 void helper_clear_float_exceptions(void)
714 set_float_exception_flags(0, &env
->fp_status
);
717 void helper_fabss(void)
719 FT0
= float32_abs(FT1
);
722 #ifdef TARGET_SPARC64
723 void helper_fabsd(void)
725 DT0
= float64_abs(DT1
);
728 void helper_fabsq(void)
730 QT0
= float128_abs(QT1
);
734 void helper_fsqrts(void)
736 FT0
= float32_sqrt(FT1
, &env
->fp_status
);
739 void helper_fsqrtd(void)
741 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
744 void helper_fsqrtq(void)
746 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
749 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
750 void glue(helper_, name) (void) \
752 target_ulong new_fsr; \
754 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
755 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
756 case float_relation_unordered: \
757 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
758 if ((env->fsr & FSR_NVM) || TRAP) { \
759 env->fsr |= new_fsr; \
760 env->fsr |= FSR_NVC; \
761 env->fsr |= FSR_FTT_IEEE_EXCP; \
762 raise_exception(TT_FP_EXCP); \
764 env->fsr |= FSR_NVA; \
767 case float_relation_less: \
768 new_fsr = FSR_FCC0 << FS; \
770 case float_relation_greater: \
771 new_fsr = FSR_FCC1 << FS; \
777 env->fsr |= new_fsr; \
780 GEN_FCMP(fcmps
, float32
, FT0
, FT1
, 0, 0);
781 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
783 GEN_FCMP(fcmpes
, float32
, FT0
, FT1
, 0, 1);
784 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
786 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
787 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
789 #ifdef TARGET_SPARC64
790 GEN_FCMP(fcmps_fcc1
, float32
, FT0
, FT1
, 22, 0);
791 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
792 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
794 GEN_FCMP(fcmps_fcc2
, float32
, FT0
, FT1
, 24, 0);
795 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
796 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
798 GEN_FCMP(fcmps_fcc3
, float32
, FT0
, FT1
, 26, 0);
799 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
800 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
802 GEN_FCMP(fcmpes_fcc1
, float32
, FT0
, FT1
, 22, 1);
803 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
804 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
806 GEN_FCMP(fcmpes_fcc2
, float32
, FT0
, FT1
, 24, 1);
807 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
808 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
810 GEN_FCMP(fcmpes_fcc3
, float32
, FT0
, FT1
, 26, 1);
811 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
812 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
815 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
817 static void dump_mxcc(CPUState
*env
)
819 printf("mxccdata: %016llx %016llx %016llx %016llx\n",
820 env
->mxccdata
[0], env
->mxccdata
[1],
821 env
->mxccdata
[2], env
->mxccdata
[3]);
822 printf("mxccregs: %016llx %016llx %016llx %016llx\n"
823 " %016llx %016llx %016llx %016llx\n",
824 env
->mxccregs
[0], env
->mxccregs
[1],
825 env
->mxccregs
[2], env
->mxccregs
[3],
826 env
->mxccregs
[4], env
->mxccregs
[5],
827 env
->mxccregs
[6], env
->mxccregs
[7]);
831 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
832 && defined(DEBUG_ASI)
833 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
839 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
840 addr
, asi
, r1
& 0xff);
843 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
844 addr
, asi
, r1
& 0xffff);
847 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
848 addr
, asi
, r1
& 0xffffffff);
851 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
858 #ifndef TARGET_SPARC64
859 #ifndef CONFIG_USER_ONLY
860 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
863 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
864 uint32_t last_addr
= addr
;
867 helper_check_align(addr
, size
- 1);
869 case 2: /* SuperSparc MXCC registers */
871 case 0x01c00a00: /* MXCC control register */
873 ret
= env
->mxccregs
[3];
875 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
878 case 0x01c00a04: /* MXCC control register */
880 ret
= env
->mxccregs
[3];
882 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
885 case 0x01c00c00: /* Module reset register */
887 ret
= env
->mxccregs
[5];
888 // should we do something here?
890 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
893 case 0x01c00f00: /* MBus port address register */
895 ret
= env
->mxccregs
[7];
897 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
901 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
905 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
906 "addr = %08x -> ret = %08x,"
907 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
912 case 3: /* MMU probe */
916 mmulev
= (addr
>> 8) & 15;
920 ret
= mmu_probe(env
, addr
, mmulev
);
921 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
925 case 4: /* read MMU regs */
927 int reg
= (addr
>> 8) & 0x1f;
929 ret
= env
->mmuregs
[reg
];
930 if (reg
== 3) /* Fault status cleared on read */
932 else if (reg
== 0x13) /* Fault status read */
933 ret
= env
->mmuregs
[3];
934 else if (reg
== 0x14) /* Fault address read */
935 ret
= env
->mmuregs
[4];
936 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
939 case 5: // Turbosparc ITLB Diagnostic
940 case 6: // Turbosparc DTLB Diagnostic
941 case 7: // Turbosparc IOTLB Diagnostic
943 case 9: /* Supervisor code access */
946 ret
= ldub_code(addr
);
949 ret
= lduw_code(addr
);
953 ret
= ldl_code(addr
);
956 ret
= ldq_code(addr
);
960 case 0xa: /* User data access */
963 ret
= ldub_user(addr
);
966 ret
= lduw_user(addr
);
970 ret
= ldl_user(addr
);
973 ret
= ldq_user(addr
);
977 case 0xb: /* Supervisor data access */
980 ret
= ldub_kernel(addr
);
983 ret
= lduw_kernel(addr
);
987 ret
= ldl_kernel(addr
);
990 ret
= ldq_kernel(addr
);
994 case 0xc: /* I-cache tag */
995 case 0xd: /* I-cache data */
996 case 0xe: /* D-cache tag */
997 case 0xf: /* D-cache data */
999 case 0x20: /* MMU passthrough */
1002 ret
= ldub_phys(addr
);
1005 ret
= lduw_phys(addr
);
1009 ret
= ldl_phys(addr
);
1012 ret
= ldq_phys(addr
);
1016 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1019 ret
= ldub_phys((target_phys_addr_t
)addr
1020 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1023 ret
= lduw_phys((target_phys_addr_t
)addr
1024 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1028 ret
= ldl_phys((target_phys_addr_t
)addr
1029 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1032 ret
= ldq_phys((target_phys_addr_t
)addr
1033 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
1037 case 0x30: // Turbosparc secondary cache diagnostic
1038 case 0x31: // Turbosparc RAM snoop
1039 case 0x32: // Turbosparc page table descriptor diagnostic
1040 case 0x39: /* data cache diagnostic register */
1043 case 8: /* User code access, XXX */
1045 do_unassigned_access(addr
, 0, 0, asi
);
1055 ret
= (int16_t) ret
;
1058 ret
= (int32_t) ret
;
1065 dump_asi("read ", last_addr
, asi
, size
, ret
);
1070 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1072 helper_check_align(addr
, size
- 1);
1074 case 2: /* SuperSparc MXCC registers */
1076 case 0x01c00000: /* MXCC stream data register 0 */
1078 env
->mxccdata
[0] = val
;
1080 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1083 case 0x01c00008: /* MXCC stream data register 1 */
1085 env
->mxccdata
[1] = val
;
1087 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1090 case 0x01c00010: /* MXCC stream data register 2 */
1092 env
->mxccdata
[2] = val
;
1094 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1097 case 0x01c00018: /* MXCC stream data register 3 */
1099 env
->mxccdata
[3] = val
;
1101 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1104 case 0x01c00100: /* MXCC stream source */
1106 env
->mxccregs
[0] = val
;
1108 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1110 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1112 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1114 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1116 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1119 case 0x01c00200: /* MXCC stream destination */
1121 env
->mxccregs
[1] = val
;
1123 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1125 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1127 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1129 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1131 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1134 case 0x01c00a00: /* MXCC control register */
1136 env
->mxccregs
[3] = val
;
1138 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1141 case 0x01c00a04: /* MXCC control register */
1143 env
->mxccregs
[3] = (env
->mxccregs
[0xa] & 0xffffffff00000000ULL
)
1146 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1149 case 0x01c00e00: /* MXCC error register */
1150 // writing a 1 bit clears the error
1152 env
->mxccregs
[6] &= ~val
;
1154 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1157 case 0x01c00f00: /* MBus port address register */
1159 env
->mxccregs
[7] = val
;
1161 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1165 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1169 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %08x\n", asi
,
1175 case 3: /* MMU flush */
1179 mmulev
= (addr
>> 8) & 15;
1180 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1182 case 0: // flush page
1183 tlb_flush_page(env
, addr
& 0xfffff000);
1185 case 1: // flush segment (256k)
1186 case 2: // flush region (16M)
1187 case 3: // flush context (4G)
1188 case 4: // flush entire
1199 case 4: /* write MMU regs */
1201 int reg
= (addr
>> 8) & 0x1f;
1204 oldreg
= env
->mmuregs
[reg
];
1206 case 0: // Control Register
1207 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1209 // Mappings generated during no-fault mode or MMU
1210 // disabled mode are invalid in normal mode
1211 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1212 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1215 case 1: // Context Table Pointer Register
1216 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1218 case 2: // Context Register
1219 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1220 if (oldreg
!= env
->mmuregs
[reg
]) {
1221 /* we flush when the MMU context changes because
1222 QEMU has no MMU context support */
1226 case 3: // Synchronous Fault Status Register with Clear
1227 case 4: // Synchronous Fault Address Register
1229 case 0x10: // TLB Replacement Control Register
1230 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1232 case 0x13: // Synchronous Fault Status Register with Read and Clear
1233 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1235 case 0x14: // Synchronous Fault Address Register
1236 env
->mmuregs
[4] = val
;
1239 env
->mmuregs
[reg
] = val
;
1242 if (oldreg
!= env
->mmuregs
[reg
]) {
1243 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1244 reg
, oldreg
, env
->mmuregs
[reg
]);
1251 case 5: // Turbosparc ITLB Diagnostic
1252 case 6: // Turbosparc DTLB Diagnostic
1253 case 7: // Turbosparc IOTLB Diagnostic
1255 case 0xa: /* User data access */
1258 stb_user(addr
, val
);
1261 stw_user(addr
, val
);
1265 stl_user(addr
, val
);
1268 stq_user(addr
, val
);
1272 case 0xb: /* Supervisor data access */
1275 stb_kernel(addr
, val
);
1278 stw_kernel(addr
, val
);
1282 stl_kernel(addr
, val
);
1285 stq_kernel(addr
, val
);
1289 case 0xc: /* I-cache tag */
1290 case 0xd: /* I-cache data */
1291 case 0xe: /* D-cache tag */
1292 case 0xf: /* D-cache data */
1293 case 0x10: /* I/D-cache flush page */
1294 case 0x11: /* I/D-cache flush segment */
1295 case 0x12: /* I/D-cache flush region */
1296 case 0x13: /* I/D-cache flush context */
1297 case 0x14: /* I/D-cache flush user */
1299 case 0x17: /* Block copy, sta access */
1305 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1307 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1308 temp
= ldl_kernel(src
);
1309 stl_kernel(dst
, temp
);
1313 case 0x1f: /* Block fill, stda access */
1316 // fill 32 bytes with val
1318 uint32_t dst
= addr
& 7;
1320 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1321 stq_kernel(dst
, val
);
1324 case 0x20: /* MMU passthrough */
1328 stb_phys(addr
, val
);
1331 stw_phys(addr
, val
);
1335 stl_phys(addr
, val
);
1338 stq_phys(addr
, val
);
1343 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1347 stb_phys((target_phys_addr_t
)addr
1348 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1351 stw_phys((target_phys_addr_t
)addr
1352 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1356 stl_phys((target_phys_addr_t
)addr
1357 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1360 stq_phys((target_phys_addr_t
)addr
1361 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1366 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1367 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1368 // Turbosparc snoop RAM
1369 case 0x32: // store buffer control or Turbosparc page table
1370 // descriptor diagnostic
1371 case 0x36: /* I-cache flash clear */
1372 case 0x37: /* D-cache flash clear */
1373 case 0x38: /* breakpoint diagnostics */
1374 case 0x4c: /* breakpoint action */
1376 case 8: /* User code access, XXX */
1377 case 9: /* Supervisor code access, XXX */
1379 do_unassigned_access(addr
, 1, 0, asi
);
1383 dump_asi("write", addr
, asi
, size
, val
);
1387 #endif /* CONFIG_USER_ONLY */
1388 #else /* TARGET_SPARC64 */
1390 #ifdef CONFIG_USER_ONLY
1391 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1394 #if defined(DEBUG_ASI)
1395 target_ulong last_addr
= addr
;
1399 raise_exception(TT_PRIV_ACT
);
1401 helper_check_align(addr
, size
- 1);
1402 address_mask(env
, &addr
);
1405 case 0x82: // Primary no-fault
1406 case 0x8a: // Primary no-fault LE
1407 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1409 dump_asi("read ", last_addr
, asi
, size
, ret
);
1414 case 0x80: // Primary
1415 case 0x88: // Primary LE
1419 ret
= ldub_raw(addr
);
1422 ret
= lduw_raw(addr
);
1425 ret
= ldl_raw(addr
);
1429 ret
= ldq_raw(addr
);
1434 case 0x83: // Secondary no-fault
1435 case 0x8b: // Secondary no-fault LE
1436 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1438 dump_asi("read ", last_addr
, asi
, size
, ret
);
1443 case 0x81: // Secondary
1444 case 0x89: // Secondary LE
1451 /* Convert from little endian */
1453 case 0x88: // Primary LE
1454 case 0x89: // Secondary LE
1455 case 0x8a: // Primary no-fault LE
1456 case 0x8b: // Secondary no-fault LE
1474 /* Convert to signed number */
1481 ret
= (int16_t) ret
;
1484 ret
= (int32_t) ret
;
1491 dump_asi("read ", last_addr
, asi
, size
, ret
);
1496 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1499 dump_asi("write", addr
, asi
, size
, val
);
1502 raise_exception(TT_PRIV_ACT
);
1504 helper_check_align(addr
, size
- 1);
1505 address_mask(env
, &addr
);
1507 /* Convert to little endian */
1509 case 0x88: // Primary LE
1510 case 0x89: // Secondary LE
1513 addr
= bswap16(addr
);
1516 addr
= bswap32(addr
);
1519 addr
= bswap64(addr
);
1529 case 0x80: // Primary
1530 case 0x88: // Primary LE
1549 case 0x81: // Secondary
1550 case 0x89: // Secondary LE
1554 case 0x82: // Primary no-fault, RO
1555 case 0x83: // Secondary no-fault, RO
1556 case 0x8a: // Primary no-fault LE, RO
1557 case 0x8b: // Secondary no-fault LE, RO
1559 do_unassigned_access(addr
, 1, 0, 1);
1564 #else /* CONFIG_USER_ONLY */
1566 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1569 #if defined(DEBUG_ASI)
1570 target_ulong last_addr
= addr
;
1573 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1574 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1575 && asi
>= 0x30 && asi
< 0x80
1576 && !(env
->hpstate
& HS_PRIV
)))
1577 raise_exception(TT_PRIV_ACT
);
1579 helper_check_align(addr
, size
- 1);
1581 case 0x82: // Primary no-fault
1582 case 0x8a: // Primary no-fault LE
1583 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
1585 dump_asi("read ", last_addr
, asi
, size
, ret
);
1590 case 0x10: // As if user primary
1591 case 0x18: // As if user primary LE
1592 case 0x80: // Primary
1593 case 0x88: // Primary LE
1594 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1595 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1596 && env
->hpstate
& HS_PRIV
) {
1599 ret
= ldub_hypv(addr
);
1602 ret
= lduw_hypv(addr
);
1605 ret
= ldl_hypv(addr
);
1609 ret
= ldq_hypv(addr
);
1615 ret
= ldub_kernel(addr
);
1618 ret
= lduw_kernel(addr
);
1621 ret
= ldl_kernel(addr
);
1625 ret
= ldq_kernel(addr
);
1632 ret
= ldub_user(addr
);
1635 ret
= lduw_user(addr
);
1638 ret
= ldl_user(addr
);
1642 ret
= ldq_user(addr
);
1647 case 0x14: // Bypass
1648 case 0x15: // Bypass, non-cacheable
1649 case 0x1c: // Bypass LE
1650 case 0x1d: // Bypass, non-cacheable LE
1654 ret
= ldub_phys(addr
);
1657 ret
= lduw_phys(addr
);
1660 ret
= ldl_phys(addr
);
1664 ret
= ldq_phys(addr
);
1669 case 0x24: // Nucleus quad LDD 128 bit atomic
1670 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1671 // Only ldda allowed
1672 raise_exception(TT_ILL_INSN
);
1674 case 0x83: // Secondary no-fault
1675 case 0x8b: // Secondary no-fault LE
1676 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
1678 dump_asi("read ", last_addr
, asi
, size
, ret
);
1683 case 0x04: // Nucleus
1684 case 0x0c: // Nucleus Little Endian (LE)
1685 case 0x11: // As if user secondary
1686 case 0x19: // As if user secondary LE
1687 case 0x4a: // UPA config
1688 case 0x81: // Secondary
1689 case 0x89: // Secondary LE
1695 case 0x50: // I-MMU regs
1697 int reg
= (addr
>> 3) & 0xf;
1699 ret
= env
->immuregs
[reg
];
1702 case 0x51: // I-MMU 8k TSB pointer
1703 case 0x52: // I-MMU 64k TSB pointer
1706 case 0x55: // I-MMU data access
1708 int reg
= (addr
>> 3) & 0x3f;
1710 ret
= env
->itlb_tte
[reg
];
1713 case 0x56: // I-MMU tag read
1715 int reg
= (addr
>> 3) & 0x3f;
1717 ret
= env
->itlb_tag
[reg
];
1720 case 0x58: // D-MMU regs
1722 int reg
= (addr
>> 3) & 0xf;
1724 ret
= env
->dmmuregs
[reg
];
1727 case 0x5d: // D-MMU data access
1729 int reg
= (addr
>> 3) & 0x3f;
1731 ret
= env
->dtlb_tte
[reg
];
1734 case 0x5e: // D-MMU tag read
1736 int reg
= (addr
>> 3) & 0x3f;
1738 ret
= env
->dtlb_tag
[reg
];
1741 case 0x46: // D-cache data
1742 case 0x47: // D-cache tag access
1743 case 0x4b: // E-cache error enable
1744 case 0x4c: // E-cache asynchronous fault status
1745 case 0x4d: // E-cache asynchronous fault address
1746 case 0x4e: // E-cache tag data
1747 case 0x66: // I-cache instruction access
1748 case 0x67: // I-cache tag access
1749 case 0x6e: // I-cache predecode
1750 case 0x6f: // I-cache LRU etc.
1751 case 0x76: // E-cache tag
1752 case 0x7e: // E-cache tag
1754 case 0x59: // D-MMU 8k TSB pointer
1755 case 0x5a: // D-MMU 64k TSB pointer
1756 case 0x5b: // D-MMU data pointer
1757 case 0x48: // Interrupt dispatch, RO
1758 case 0x49: // Interrupt data receive
1759 case 0x7f: // Incoming interrupt vector, RO
1762 case 0x54: // I-MMU data in, WO
1763 case 0x57: // I-MMU demap, WO
1764 case 0x5c: // D-MMU data in, WO
1765 case 0x5f: // D-MMU demap, WO
1766 case 0x77: // Interrupt vector, WO
1768 do_unassigned_access(addr
, 0, 0, 1);
1773 /* Convert from little endian */
1775 case 0x0c: // Nucleus Little Endian (LE)
1776 case 0x18: // As if user primary LE
1777 case 0x19: // As if user secondary LE
1778 case 0x1c: // Bypass LE
1779 case 0x1d: // Bypass, non-cacheable LE
1780 case 0x88: // Primary LE
1781 case 0x89: // Secondary LE
1782 case 0x8a: // Primary no-fault LE
1783 case 0x8b: // Secondary no-fault LE
1801 /* Convert to signed number */
1808 ret
= (int16_t) ret
;
1811 ret
= (int32_t) ret
;
1818 dump_asi("read ", last_addr
, asi
, size
, ret
);
1823 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1826 dump_asi("write", addr
, asi
, size
, val
);
1828 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1829 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1830 && asi
>= 0x30 && asi
< 0x80
1831 && !(env
->hpstate
& HS_PRIV
)))
1832 raise_exception(TT_PRIV_ACT
);
1834 helper_check_align(addr
, size
- 1);
1835 /* Convert to little endian */
1837 case 0x0c: // Nucleus Little Endian (LE)
1838 case 0x18: // As if user primary LE
1839 case 0x19: // As if user secondary LE
1840 case 0x1c: // Bypass LE
1841 case 0x1d: // Bypass, non-cacheable LE
1842 case 0x88: // Primary LE
1843 case 0x89: // Secondary LE
1846 addr
= bswap16(addr
);
1849 addr
= bswap32(addr
);
1852 addr
= bswap64(addr
);
1862 case 0x10: // As if user primary
1863 case 0x18: // As if user primary LE
1864 case 0x80: // Primary
1865 case 0x88: // Primary LE
1866 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1867 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1868 && env
->hpstate
& HS_PRIV
) {
1871 stb_hypv(addr
, val
);
1874 stw_hypv(addr
, val
);
1877 stl_hypv(addr
, val
);
1881 stq_hypv(addr
, val
);
1887 stb_kernel(addr
, val
);
1890 stw_kernel(addr
, val
);
1893 stl_kernel(addr
, val
);
1897 stq_kernel(addr
, val
);
1904 stb_user(addr
, val
);
1907 stw_user(addr
, val
);
1910 stl_user(addr
, val
);
1914 stq_user(addr
, val
);
1919 case 0x14: // Bypass
1920 case 0x15: // Bypass, non-cacheable
1921 case 0x1c: // Bypass LE
1922 case 0x1d: // Bypass, non-cacheable LE
1926 stb_phys(addr
, val
);
1929 stw_phys(addr
, val
);
1932 stl_phys(addr
, val
);
1936 stq_phys(addr
, val
);
1941 case 0x24: // Nucleus quad LDD 128 bit atomic
1942 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1943 // Only ldda allowed
1944 raise_exception(TT_ILL_INSN
);
1946 case 0x04: // Nucleus
1947 case 0x0c: // Nucleus Little Endian (LE)
1948 case 0x11: // As if user secondary
1949 case 0x19: // As if user secondary LE
1950 case 0x4a: // UPA config
1951 case 0x81: // Secondary
1952 case 0x89: // Secondary LE
1960 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1961 // Mappings generated during D/I MMU disabled mode are
1962 // invalid in normal mode
1963 if (oldreg
!= env
->lsu
) {
1964 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1973 case 0x50: // I-MMU regs
1975 int reg
= (addr
>> 3) & 0xf;
1978 oldreg
= env
->immuregs
[reg
];
1983 case 1: // Not in I-MMU
1990 val
= 0; // Clear SFSR
1992 case 5: // TSB access
1993 case 6: // Tag access
1997 env
->immuregs
[reg
] = val
;
1998 if (oldreg
!= env
->immuregs
[reg
]) {
1999 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
2000 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
2007 case 0x54: // I-MMU data in
2011 // Try finding an invalid entry
2012 for (i
= 0; i
< 64; i
++) {
2013 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
2014 env
->itlb_tag
[i
] = env
->immuregs
[6];
2015 env
->itlb_tte
[i
] = val
;
2019 // Try finding an unlocked entry
2020 for (i
= 0; i
< 64; i
++) {
2021 if ((env
->itlb_tte
[i
] & 0x40) == 0) {
2022 env
->itlb_tag
[i
] = env
->immuregs
[6];
2023 env
->itlb_tte
[i
] = val
;
2030 case 0x55: // I-MMU data access
2032 unsigned int i
= (addr
>> 3) & 0x3f;
2034 env
->itlb_tag
[i
] = env
->immuregs
[6];
2035 env
->itlb_tte
[i
] = val
;
2038 case 0x57: // I-MMU demap
2041 case 0x58: // D-MMU regs
2043 int reg
= (addr
>> 3) & 0xf;
2046 oldreg
= env
->dmmuregs
[reg
];
2052 if ((val
& 1) == 0) {
2053 val
= 0; // Clear SFSR, Fault address
2054 env
->dmmuregs
[4] = 0;
2056 env
->dmmuregs
[reg
] = val
;
2058 case 1: // Primary context
2059 case 2: // Secondary context
2060 case 5: // TSB access
2061 case 6: // Tag access
2062 case 7: // Virtual Watchpoint
2063 case 8: // Physical Watchpoint
2067 env
->dmmuregs
[reg
] = val
;
2068 if (oldreg
!= env
->dmmuregs
[reg
]) {
2069 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
2070 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2077 case 0x5c: // D-MMU data in
2081 // Try finding an invalid entry
2082 for (i
= 0; i
< 64; i
++) {
2083 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
2084 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2085 env
->dtlb_tte
[i
] = val
;
2089 // Try finding an unlocked entry
2090 for (i
= 0; i
< 64; i
++) {
2091 if ((env
->dtlb_tte
[i
] & 0x40) == 0) {
2092 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2093 env
->dtlb_tte
[i
] = val
;
2100 case 0x5d: // D-MMU data access
2102 unsigned int i
= (addr
>> 3) & 0x3f;
2104 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2105 env
->dtlb_tte
[i
] = val
;
2108 case 0x5f: // D-MMU demap
2109 case 0x49: // Interrupt data receive
2112 case 0x46: // D-cache data
2113 case 0x47: // D-cache tag access
2114 case 0x4b: // E-cache error enable
2115 case 0x4c: // E-cache asynchronous fault status
2116 case 0x4d: // E-cache asynchronous fault address
2117 case 0x4e: // E-cache tag data
2118 case 0x66: // I-cache instruction access
2119 case 0x67: // I-cache tag access
2120 case 0x6e: // I-cache predecode
2121 case 0x6f: // I-cache LRU etc.
2122 case 0x76: // E-cache tag
2123 case 0x7e: // E-cache tag
2125 case 0x51: // I-MMU 8k TSB pointer, RO
2126 case 0x52: // I-MMU 64k TSB pointer, RO
2127 case 0x56: // I-MMU tag read, RO
2128 case 0x59: // D-MMU 8k TSB pointer, RO
2129 case 0x5a: // D-MMU 64k TSB pointer, RO
2130 case 0x5b: // D-MMU data pointer, RO
2131 case 0x5e: // D-MMU tag read, RO
2132 case 0x48: // Interrupt dispatch, RO
2133 case 0x7f: // Incoming interrupt vector, RO
2134 case 0x82: // Primary no-fault, RO
2135 case 0x83: // Secondary no-fault, RO
2136 case 0x8a: // Primary no-fault LE, RO
2137 case 0x8b: // Secondary no-fault LE, RO
2139 do_unassigned_access(addr
, 1, 0, 1);
2143 #endif /* CONFIG_USER_ONLY */
2145 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2147 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2148 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2149 && asi
>= 0x30 && asi
< 0x80
2150 && !(env
->hpstate
& HS_PRIV
)))
2151 raise_exception(TT_PRIV_ACT
);
2154 case 0x24: // Nucleus quad LDD 128 bit atomic
2155 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2156 helper_check_align(addr
, 0xf);
2158 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2160 bswap64s(&env
->gregs
[1]);
2161 } else if (rd
< 8) {
2162 env
->gregs
[rd
] = ldq_kernel(addr
);
2163 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2165 bswap64s(&env
->gregs
[rd
]);
2166 bswap64s(&env
->gregs
[rd
+ 1]);
2169 env
->regwptr
[rd
] = ldq_kernel(addr
);
2170 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2172 bswap64s(&env
->regwptr
[rd
]);
2173 bswap64s(&env
->regwptr
[rd
+ 1]);
2178 helper_check_align(addr
, 0x3);
2180 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2182 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2183 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2185 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2186 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2192 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2197 helper_check_align(addr
, 3);
2199 case 0xf0: // Block load primary
2200 case 0xf1: // Block load secondary
2201 case 0xf8: // Block load primary LE
2202 case 0xf9: // Block load secondary LE
2204 raise_exception(TT_ILL_INSN
);
2207 helper_check_align(addr
, 0x3f);
2208 for (i
= 0; i
< 16; i
++) {
2209 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2219 val
= helper_ld_asi(addr
, asi
, size
, 0);
2223 *((uint32_t *)&FT0
) = val
;
2226 *((int64_t *)&DT0
) = val
;
2234 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2237 target_ulong val
= 0;
2239 helper_check_align(addr
, 3);
2241 case 0xf0: // Block store primary
2242 case 0xf1: // Block store secondary
2243 case 0xf8: // Block store primary LE
2244 case 0xf9: // Block store secondary LE
2246 raise_exception(TT_ILL_INSN
);
2249 helper_check_align(addr
, 0x3f);
2250 for (i
= 0; i
< 16; i
++) {
2251 val
= *(uint32_t *)&env
->fpr
[rd
++];
2252 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2264 val
= *((uint32_t *)&FT0
);
2267 val
= *((int64_t *)&DT0
);
2273 helper_st_asi(addr
, val
, asi
, size
);
2276 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2277 target_ulong val2
, uint32_t asi
)
2281 val1
&= 0xffffffffUL
;
2282 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2283 ret
&= 0xffffffffUL
;
2285 helper_st_asi(addr
, val2
& 0xffffffffUL
, asi
, 4);
2289 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2290 target_ulong val2
, uint32_t asi
)
2294 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2296 helper_st_asi(addr
, val2
, asi
, 8);
2299 #endif /* TARGET_SPARC64 */
2301 #ifndef TARGET_SPARC64
2302 void helper_rett(void)
2306 if (env
->psret
== 1)
2307 raise_exception(TT_ILL_INSN
);
2310 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2311 if (env
->wim
& (1 << cwp
)) {
2312 raise_exception(TT_WIN_UNF
);
2315 env
->psrs
= env
->psrps
;
2319 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2324 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2328 raise_exception(TT_DIV_ZERO
);
2332 if (x0
> 0xffffffff) {
2341 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2346 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2350 raise_exception(TT_DIV_ZERO
);
2354 if ((int32_t) x0
!= x0
) {
2356 return x0
< 0? 0x80000000: 0x7fffffff;
2363 uint64_t helper_pack64(target_ulong high
, target_ulong low
)
2365 return ((uint64_t)high
<< 32) | (uint64_t)(low
& 0xffffffff);
2368 void helper_stdf(target_ulong addr
, int mem_idx
)
2370 helper_check_align(addr
, 7);
2371 #if !defined(CONFIG_USER_ONLY)
2374 stfq_user(addr
, DT0
);
2377 stfq_kernel(addr
, DT0
);
2379 #ifdef TARGET_SPARC64
2381 stfq_hypv(addr
, DT0
);
2388 address_mask(env
, &addr
);
2389 stfq_raw(addr
, DT0
);
2393 void helper_lddf(target_ulong addr
, int mem_idx
)
2395 helper_check_align(addr
, 7);
2396 #if !defined(CONFIG_USER_ONLY)
2399 DT0
= ldfq_user(addr
);
2402 DT0
= ldfq_kernel(addr
);
2404 #ifdef TARGET_SPARC64
2406 DT0
= ldfq_hypv(addr
);
2413 address_mask(env
, &addr
);
2414 DT0
= ldfq_raw(addr
);
2418 void helper_ldqf(target_ulong addr
, int mem_idx
)
2420 // XXX add 128 bit load
2423 helper_check_align(addr
, 7);
2424 #if !defined(CONFIG_USER_ONLY)
2427 u
.ll
.upper
= ldq_user(addr
);
2428 u
.ll
.lower
= ldq_user(addr
+ 8);
2432 u
.ll
.upper
= ldq_kernel(addr
);
2433 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2436 #ifdef TARGET_SPARC64
2438 u
.ll
.upper
= ldq_hypv(addr
);
2439 u
.ll
.lower
= ldq_hypv(addr
+ 8);
2447 address_mask(env
, &addr
);
2448 u
.ll
.upper
= ldq_raw(addr
);
2449 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
2454 void helper_stqf(target_ulong addr
, int mem_idx
)
2456 // XXX add 128 bit store
2459 helper_check_align(addr
, 7);
2460 #if !defined(CONFIG_USER_ONLY)
2464 stq_user(addr
, u
.ll
.upper
);
2465 stq_user(addr
+ 8, u
.ll
.lower
);
2469 stq_kernel(addr
, u
.ll
.upper
);
2470 stq_kernel(addr
+ 8, u
.ll
.lower
);
2472 #ifdef TARGET_SPARC64
2475 stq_hypv(addr
, u
.ll
.upper
);
2476 stq_hypv(addr
+ 8, u
.ll
.lower
);
2484 address_mask(env
, &addr
);
2485 stq_raw(addr
, u
.ll
.upper
);
2486 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
2490 void helper_ldfsr(void)
2494 PUT_FSR32(env
, *((uint32_t *) &FT0
));
2495 switch (env
->fsr
& FSR_RD_MASK
) {
2496 case FSR_RD_NEAREST
:
2497 rnd_mode
= float_round_nearest_even
;
2501 rnd_mode
= float_round_to_zero
;
2504 rnd_mode
= float_round_up
;
2507 rnd_mode
= float_round_down
;
2510 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
2513 void helper_stfsr(void)
2515 *((uint32_t *) &FT0
) = GET_FSR32(env
);
2518 void helper_debug(void)
2520 env
->exception_index
= EXCP_DEBUG
;
2524 #ifndef TARGET_SPARC64
2525 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2527 void helper_save(void)
2531 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2532 if (env
->wim
& (1 << cwp
)) {
2533 raise_exception(TT_WIN_OVF
);
2538 void helper_restore(void)
2542 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2543 if (env
->wim
& (1 << cwp
)) {
2544 raise_exception(TT_WIN_UNF
);
2549 void helper_wrpsr(target_ulong new_psr
)
2551 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
2552 raise_exception(TT_ILL_INSN
);
2554 PUT_PSR(env
, new_psr
);
2557 target_ulong
helper_rdpsr(void)
2559 return GET_PSR(env
);
2563 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2565 void helper_save(void)
2569 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2570 if (env
->cansave
== 0) {
2571 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2572 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2573 ((env
->wstate
& 0x7) << 2)));
2575 if (env
->cleanwin
- env
->canrestore
== 0) {
2576 // XXX Clean windows without trap
2577 raise_exception(TT_CLRWIN
);
2586 void helper_restore(void)
2590 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2591 if (env
->canrestore
== 0) {
2592 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
2593 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2594 ((env
->wstate
& 0x7) << 2)));
2602 void helper_flushw(void)
2604 if (env
->cansave
!= env
->nwindows
- 2) {
2605 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2606 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2607 ((env
->wstate
& 0x7) << 2)));
2611 void helper_saved(void)
2614 if (env
->otherwin
== 0)
2620 void helper_restored(void)
2623 if (env
->cleanwin
< env
->nwindows
- 1)
2625 if (env
->otherwin
== 0)
2631 target_ulong
helper_rdccr(void)
2633 return GET_CCR(env
);
2636 void helper_wrccr(target_ulong new_ccr
)
2638 PUT_CCR(env
, new_ccr
);
2641 // CWP handling is reversed in V9, but we still use the V8 register
2643 target_ulong
helper_rdcwp(void)
2645 return GET_CWP64(env
);
2648 void helper_wrcwp(target_ulong new_cwp
)
2650 PUT_CWP64(env
, new_cwp
);
2653 // This function uses non-native bit order
2654 #define GET_FIELD(X, FROM, TO) \
2655 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
2657 // This function uses the order in the manuals, i.e. bit 0 is 2^0
2658 #define GET_FIELD_SP(X, FROM, TO) \
2659 GET_FIELD(X, 63 - (TO), 63 - (FROM))
2661 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
2663 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
2664 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
2665 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
2666 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
2667 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
2668 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
2669 (((pixel_addr
>> 55) & 1) << 4) |
2670 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
2671 GET_FIELD_SP(pixel_addr
, 11, 12);
2674 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
2678 tmp
= addr
+ offset
;
2680 env
->gsr
|= tmp
& 7ULL;
2684 target_ulong
helper_popc(target_ulong val
)
2686 return ctpop64(val
);
2689 static inline uint64_t *get_gregset(uint64_t pstate
)
2704 static inline void change_pstate(uint64_t new_pstate
)
2706 uint64_t pstate_regs
, new_pstate_regs
;
2707 uint64_t *src
, *dst
;
2709 pstate_regs
= env
->pstate
& 0xc01;
2710 new_pstate_regs
= new_pstate
& 0xc01;
2711 if (new_pstate_regs
!= pstate_regs
) {
2712 // Switch global register bank
2713 src
= get_gregset(new_pstate_regs
);
2714 dst
= get_gregset(pstate_regs
);
2715 memcpy32(dst
, env
->gregs
);
2716 memcpy32(env
->gregs
, src
);
2718 env
->pstate
= new_pstate
;
2721 void helper_wrpstate(target_ulong new_state
)
2723 if (!(env
->def
->features
& CPU_FEATURE_GL
))
2724 change_pstate(new_state
& 0xf3f);
2727 void helper_done(void)
2729 env
->pc
= env
->tsptr
->tpc
;
2730 env
->npc
= env
->tsptr
->tnpc
+ 4;
2731 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2732 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2733 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2734 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2736 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2739 void helper_retry(void)
2741 env
->pc
= env
->tsptr
->tpc
;
2742 env
->npc
= env
->tsptr
->tnpc
;
2743 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2744 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2745 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2746 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2748 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2752 void helper_flush(target_ulong addr
)
2755 tb_invalidate_page_range(addr
, addr
+ 8);
2758 #ifdef TARGET_SPARC64
2760 static const char * const excp_names
[0x80] = {
2761 [TT_TFAULT
] = "Instruction Access Fault",
2762 [TT_TMISS
] = "Instruction Access MMU Miss",
2763 [TT_CODE_ACCESS
] = "Instruction Access Error",
2764 [TT_ILL_INSN
] = "Illegal Instruction",
2765 [TT_PRIV_INSN
] = "Privileged Instruction",
2766 [TT_NFPU_INSN
] = "FPU Disabled",
2767 [TT_FP_EXCP
] = "FPU Exception",
2768 [TT_TOVF
] = "Tag Overflow",
2769 [TT_CLRWIN
] = "Clean Windows",
2770 [TT_DIV_ZERO
] = "Division By Zero",
2771 [TT_DFAULT
] = "Data Access Fault",
2772 [TT_DMISS
] = "Data Access MMU Miss",
2773 [TT_DATA_ACCESS
] = "Data Access Error",
2774 [TT_DPROT
] = "Data Protection Error",
2775 [TT_UNALIGNED
] = "Unaligned Memory Access",
2776 [TT_PRIV_ACT
] = "Privileged Action",
2777 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2778 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2779 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2780 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2781 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2782 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2783 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2784 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2785 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2786 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2787 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2788 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2789 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2790 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2791 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2795 void do_interrupt(CPUState
*env
)
2797 int intno
= env
->exception_index
;
2800 if (loglevel
& CPU_LOG_INT
) {
2804 if (intno
< 0 || intno
>= 0x180)
2806 else if (intno
>= 0x100)
2807 name
= "Trap Instruction";
2808 else if (intno
>= 0xc0)
2809 name
= "Window Fill";
2810 else if (intno
>= 0x80)
2811 name
= "Window Spill";
2813 name
= excp_names
[intno
];
2818 fprintf(logfile
, "%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
2819 " SP=%016" PRIx64
"\n",
2822 env
->npc
, env
->regwptr
[6]);
2823 cpu_dump_state(env
, logfile
, fprintf
, 0);
2829 fprintf(logfile
, " code=");
2830 ptr
= (uint8_t *)env
->pc
;
2831 for(i
= 0; i
< 16; i
++) {
2832 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
2834 fprintf(logfile
, "\n");
2840 #if !defined(CONFIG_USER_ONLY)
2841 if (env
->tl
>= env
->maxtl
) {
2842 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
2843 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
2847 if (env
->tl
< env
->maxtl
- 1) {
2850 env
->pstate
|= PS_RED
;
2851 if (env
->tl
< env
->maxtl
)
2854 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2855 env
->tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
2856 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
2858 env
->tsptr
->tpc
= env
->pc
;
2859 env
->tsptr
->tnpc
= env
->npc
;
2860 env
->tsptr
->tt
= intno
;
2861 if (!(env
->def
->features
& CPU_FEATURE_GL
)) {
2864 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
2871 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
2874 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
2878 if (intno
== TT_CLRWIN
)
2879 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
2880 else if ((intno
& 0x1c0) == TT_SPILL
)
2881 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
2882 else if ((intno
& 0x1c0) == TT_FILL
)
2883 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
2884 env
->tbr
&= ~0x7fffULL
;
2885 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
2887 env
->npc
= env
->pc
+ 4;
2888 env
->exception_index
= 0;
2892 static const char * const excp_names
[0x80] = {
2893 [TT_TFAULT
] = "Instruction Access Fault",
2894 [TT_ILL_INSN
] = "Illegal Instruction",
2895 [TT_PRIV_INSN
] = "Privileged Instruction",
2896 [TT_NFPU_INSN
] = "FPU Disabled",
2897 [TT_WIN_OVF
] = "Window Overflow",
2898 [TT_WIN_UNF
] = "Window Underflow",
2899 [TT_UNALIGNED
] = "Unaligned Memory Access",
2900 [TT_FP_EXCP
] = "FPU Exception",
2901 [TT_DFAULT
] = "Data Access Fault",
2902 [TT_TOVF
] = "Tag Overflow",
2903 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2904 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2905 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2906 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2907 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2908 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2909 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2910 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2911 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2912 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2913 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2914 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2915 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2916 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2917 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2918 [TT_TOVF
] = "Tag Overflow",
2919 [TT_CODE_ACCESS
] = "Instruction Access Error",
2920 [TT_DATA_ACCESS
] = "Data Access Error",
2921 [TT_DIV_ZERO
] = "Division By Zero",
2922 [TT_NCP_INSN
] = "Coprocessor Disabled",
2926 void do_interrupt(CPUState
*env
)
2928 int cwp
, intno
= env
->exception_index
;
2931 if (loglevel
& CPU_LOG_INT
) {
2935 if (intno
< 0 || intno
>= 0x100)
2937 else if (intno
>= 0x80)
2938 name
= "Trap Instruction";
2940 name
= excp_names
[intno
];
2945 fprintf(logfile
, "%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
2948 env
->npc
, env
->regwptr
[6]);
2949 cpu_dump_state(env
, logfile
, fprintf
, 0);
2955 fprintf(logfile
, " code=");
2956 ptr
= (uint8_t *)env
->pc
;
2957 for(i
= 0; i
< 16; i
++) {
2958 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
2960 fprintf(logfile
, "\n");
2966 #if !defined(CONFIG_USER_ONLY)
2967 if (env
->psret
== 0) {
2968 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
2969 env
->exception_index
);
2974 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2975 cpu_set_cwp(env
, cwp
);
2976 env
->regwptr
[9] = env
->pc
;
2977 env
->regwptr
[10] = env
->npc
;
2978 env
->psrps
= env
->psrs
;
2980 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
2982 env
->npc
= env
->pc
+ 4;
2983 env
->exception_index
= 0;
2987 #if !defined(CONFIG_USER_ONLY)
2989 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
2992 #define MMUSUFFIX _mmu
2993 #define ALIGNED_ONLY
2996 #include "softmmu_template.h"
2999 #include "softmmu_template.h"
3002 #include "softmmu_template.h"
3005 #include "softmmu_template.h"
3007 /* XXX: make it generic ? */
3008 static void cpu_restore_state2(void *retaddr
)
3010 TranslationBlock
*tb
;
3014 /* now we have a real cpu fault */
3015 pc
= (unsigned long)retaddr
;
3016 tb
= tb_find_pc(pc
);
3018 /* the PC is inside the translated code. It means that we have
3019 a virtual CPU fault */
3020 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
3025 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3028 #ifdef DEBUG_UNALIGNED
3029 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3030 "\n", addr
, env
->pc
);
3032 cpu_restore_state2(retaddr
);
3033 raise_exception(TT_UNALIGNED
);
3036 /* try to fill the TLB and return an exception if error. If retaddr is
3037 NULL, it means that the function was called in C code (i.e. not
3038 from generated code or from helper.c) */
3039 /* XXX: fix it to restore all registers */
3040 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3043 CPUState
*saved_env
;
3045 /* XXX: hack to restore env in all cases, even if not called from
3048 env
= cpu_single_env
;
3050 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3052 cpu_restore_state2(retaddr
);
3060 #ifndef TARGET_SPARC64
3061 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3064 CPUState
*saved_env
;
3066 /* XXX: hack to restore env in all cases, even if not called from
3069 env
= cpu_single_env
;
3070 #ifdef DEBUG_UNASSIGNED
3072 printf("Unassigned mem %s access to " TARGET_FMT_plx
3073 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3074 is_exec
? "exec" : is_write
? "write" : "read", addr
, is_asi
,
3077 printf("Unassigned mem %s access to " TARGET_FMT_plx
" from "
3079 is_exec
? "exec" : is_write
? "write" : "read", addr
, env
->pc
);
3081 if (env
->mmuregs
[3]) /* Fault status register */
3082 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
3084 env
->mmuregs
[3] |= 1 << 16;
3086 env
->mmuregs
[3] |= 1 << 5;
3088 env
->mmuregs
[3] |= 1 << 6;
3090 env
->mmuregs
[3] |= 1 << 7;
3091 env
->mmuregs
[3] |= (5 << 2) | 2;
3092 env
->mmuregs
[4] = addr
; /* Fault address register */
3093 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3095 raise_exception(TT_CODE_ACCESS
);
3097 raise_exception(TT_DATA_ACCESS
);
3102 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3105 #ifdef DEBUG_UNASSIGNED
3106 CPUState
*saved_env
;
3108 /* XXX: hack to restore env in all cases, even if not called from
3111 env
= cpu_single_env
;
3112 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3113 "\n", addr
, env
->pc
);
3117 raise_exception(TT_CODE_ACCESS
);
3119 raise_exception(TT_DATA_ACCESS
);