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
16 #define DPRINTF_MMU(fmt, args...) \
17 do { printf("MMU: " fmt , ##args); } while (0)
19 #define DPRINTF_MMU(fmt, args...) do {} while (0)
23 #define DPRINTF_MXCC(fmt, args...) \
24 do { printf("MXCC: " fmt , ##args); } while (0)
26 #define DPRINTF_MXCC(fmt, args...) do {} while (0)
30 #define DPRINTF_ASI(fmt, args...) \
31 do { printf("ASI: " fmt , ##args); } while (0)
33 #define DPRINTF_ASI(fmt, args...) do {} while (0)
38 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
40 #define AM_CHECK(env1) (1)
44 static inline void address_mask(CPUState
*env1
, target_ulong
*addr
)
48 *addr
&= 0xffffffffULL
;
52 static void raise_exception(int tt
)
54 env
->exception_index
= tt
;
58 void HELPER(raise_exception
)(int tt
)
63 static inline void set_cwp(int new_cwp
)
65 cpu_set_cwp(env
, new_cwp
);
68 void helper_check_align(target_ulong addr
, uint32_t align
)
71 #ifdef DEBUG_UNALIGNED
72 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
75 raise_exception(TT_UNALIGNED
);
79 #define F_HELPER(name, p) void helper_f##name##p(void)
81 #define F_BINOP(name) \
82 float32 helper_f ## name ## s (float32 src1, float32 src2) \
84 return float32_ ## name (src1, src2, &env->fp_status); \
88 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
92 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
101 void helper_fsmuld(float32 src1
, float32 src2
)
103 DT0
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
104 float32_to_float64(src2
, &env
->fp_status
),
108 void helper_fdmulq(void)
110 QT0
= float128_mul(float64_to_float128(DT0
, &env
->fp_status
),
111 float64_to_float128(DT1
, &env
->fp_status
),
115 float32
helper_fnegs(float32 src
)
117 return float32_chs(src
);
120 #ifdef TARGET_SPARC64
123 DT0
= float64_chs(DT1
);
128 QT0
= float128_chs(QT1
);
132 /* Integer to float conversion. */
133 float32
helper_fitos(int32_t src
)
135 return int32_to_float32(src
, &env
->fp_status
);
138 void helper_fitod(int32_t src
)
140 DT0
= int32_to_float64(src
, &env
->fp_status
);
143 void helper_fitoq(int32_t src
)
145 QT0
= int32_to_float128(src
, &env
->fp_status
);
148 #ifdef TARGET_SPARC64
149 float32
helper_fxtos(void)
151 return int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
156 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
161 QT0
= int64_to_float128(*((int64_t *)&DT1
), &env
->fp_status
);
166 /* floating point conversion */
167 float32
helper_fdtos(void)
169 return float64_to_float32(DT1
, &env
->fp_status
);
172 void helper_fstod(float32 src
)
174 DT0
= float32_to_float64(src
, &env
->fp_status
);
177 float32
helper_fqtos(void)
179 return float128_to_float32(QT1
, &env
->fp_status
);
182 void helper_fstoq(float32 src
)
184 QT0
= float32_to_float128(src
, &env
->fp_status
);
187 void helper_fqtod(void)
189 DT0
= float128_to_float64(QT1
, &env
->fp_status
);
192 void helper_fdtoq(void)
194 QT0
= float64_to_float128(DT1
, &env
->fp_status
);
197 /* Float to integer conversion. */
198 int32_t helper_fstoi(float32 src
)
200 return float32_to_int32_round_to_zero(src
, &env
->fp_status
);
203 int32_t helper_fdtoi(void)
205 return float64_to_int32_round_to_zero(DT1
, &env
->fp_status
);
208 int32_t helper_fqtoi(void)
210 return float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
213 #ifdef TARGET_SPARC64
214 void helper_fstox(float32 src
)
216 *((int64_t *)&DT0
) = float32_to_int64_round_to_zero(src
, &env
->fp_status
);
219 void helper_fdtox(void)
221 *((int64_t *)&DT0
) = float64_to_int64_round_to_zero(DT1
, &env
->fp_status
);
224 void helper_fqtox(void)
226 *((int64_t *)&DT0
) = float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
229 void helper_faligndata(void)
233 tmp
= (*((uint64_t *)&DT0
)) << ((env
->gsr
& 7) * 8);
234 /* on many architectures a shift of 64 does nothing */
235 if ((env
->gsr
& 7) != 0) {
236 tmp
|= (*((uint64_t *)&DT1
)) >> (64 - (env
->gsr
& 7) * 8);
238 *((uint64_t *)&DT0
) = tmp
;
241 #ifdef WORDS_BIGENDIAN
242 #define VIS_B64(n) b[7 - (n)]
243 #define VIS_W64(n) w[3 - (n)]
244 #define VIS_SW64(n) sw[3 - (n)]
245 #define VIS_L64(n) l[1 - (n)]
246 #define VIS_B32(n) b[3 - (n)]
247 #define VIS_W32(n) w[1 - (n)]
249 #define VIS_B64(n) b[n]
250 #define VIS_W64(n) w[n]
251 #define VIS_SW64(n) sw[n]
252 #define VIS_L64(n) l[n]
253 #define VIS_B32(n) b[n]
254 #define VIS_W32(n) w[n]
272 void helper_fpmerge(void)
279 // Reverse calculation order to handle overlap
280 d
.VIS_B64(7) = s
.VIS_B64(3);
281 d
.VIS_B64(6) = d
.VIS_B64(3);
282 d
.VIS_B64(5) = s
.VIS_B64(2);
283 d
.VIS_B64(4) = d
.VIS_B64(2);
284 d
.VIS_B64(3) = s
.VIS_B64(1);
285 d
.VIS_B64(2) = d
.VIS_B64(1);
286 d
.VIS_B64(1) = s
.VIS_B64(0);
287 //d.VIS_B64(0) = d.VIS_B64(0);
292 void helper_fmul8x16(void)
301 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
302 if ((tmp & 0xff) > 0x7f) \
304 d.VIS_W64(r) = tmp >> 8;
315 void helper_fmul8x16al(void)
324 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
325 if ((tmp & 0xff) > 0x7f) \
327 d.VIS_W64(r) = tmp >> 8;
338 void helper_fmul8x16au(void)
347 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
348 if ((tmp & 0xff) > 0x7f) \
350 d.VIS_W64(r) = tmp >> 8;
361 void helper_fmul8sux16(void)
370 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
371 if ((tmp & 0xff) > 0x7f) \
373 d.VIS_W64(r) = tmp >> 8;
384 void helper_fmul8ulx16(void)
393 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
394 if ((tmp & 0xff) > 0x7f) \
396 d.VIS_W64(r) = tmp >> 8;
407 void helper_fmuld8sux16(void)
416 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
417 if ((tmp & 0xff) > 0x7f) \
421 // Reverse calculation order to handle overlap
429 void helper_fmuld8ulx16(void)
438 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
439 if ((tmp & 0xff) > 0x7f) \
443 // Reverse calculation order to handle overlap
451 void helper_fexpand(void)
456 s
.l
= (uint32_t)(*(uint64_t *)&DT0
& 0xffffffff);
458 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
459 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
460 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
461 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
466 #define VIS_HELPER(name, F) \
467 void name##16(void) \
474 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
475 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
476 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
477 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
482 uint32_t name##16s(uint32_t src1, uint32_t src2) \
489 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
490 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
495 void name##32(void) \
502 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
503 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
508 uint32_t name##32s(uint32_t src1, uint32_t src2) \
520 #define FADD(a, b) ((a) + (b))
521 #define FSUB(a, b) ((a) - (b))
522 VIS_HELPER(helper_fpadd
, FADD
)
523 VIS_HELPER(helper_fpsub
, FSUB
)
525 #define VIS_CMPHELPER(name, F) \
526 void name##16(void) \
533 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
534 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
535 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
536 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
541 void name##32(void) \
548 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
549 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
554 #define FCMPGT(a, b) ((a) > (b))
555 #define FCMPEQ(a, b) ((a) == (b))
556 #define FCMPLE(a, b) ((a) <= (b))
557 #define FCMPNE(a, b) ((a) != (b))
559 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
560 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
561 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
562 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
565 void helper_check_ieee_exceptions(void)
569 status
= get_float_exception_flags(&env
->fp_status
);
571 /* Copy IEEE 754 flags into FSR */
572 if (status
& float_flag_invalid
)
574 if (status
& float_flag_overflow
)
576 if (status
& float_flag_underflow
)
578 if (status
& float_flag_divbyzero
)
580 if (status
& float_flag_inexact
)
583 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
584 /* Unmasked exception, generate a trap */
585 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
586 raise_exception(TT_FP_EXCP
);
588 /* Accumulate exceptions */
589 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
594 void helper_clear_float_exceptions(void)
596 set_float_exception_flags(0, &env
->fp_status
);
599 float32
helper_fabss(float32 src
)
601 return float32_abs(src
);
604 #ifdef TARGET_SPARC64
605 void helper_fabsd(void)
607 DT0
= float64_abs(DT1
);
610 void helper_fabsq(void)
612 QT0
= float128_abs(QT1
);
616 float32
helper_fsqrts(float32 src
)
618 return float32_sqrt(src
, &env
->fp_status
);
621 void helper_fsqrtd(void)
623 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
626 void helper_fsqrtq(void)
628 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
631 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
632 void glue(helper_, name) (void) \
634 target_ulong new_fsr; \
636 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
637 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
638 case float_relation_unordered: \
639 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
640 if ((env->fsr & FSR_NVM) || TRAP) { \
641 env->fsr |= new_fsr; \
642 env->fsr |= FSR_NVC; \
643 env->fsr |= FSR_FTT_IEEE_EXCP; \
644 raise_exception(TT_FP_EXCP); \
646 env->fsr |= FSR_NVA; \
649 case float_relation_less: \
650 new_fsr = FSR_FCC0 << FS; \
652 case float_relation_greater: \
653 new_fsr = FSR_FCC1 << FS; \
659 env->fsr |= new_fsr; \
661 #define GEN_FCMPS(name, size, FS, TRAP) \
662 void glue(helper_, name)(float32 src1, float32 src2) \
664 target_ulong new_fsr; \
666 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
667 switch (glue(size, _compare) (src1, src2, &env->fp_status)) { \
668 case float_relation_unordered: \
669 new_fsr = (FSR_FCC1 | FSR_FCC0) << FS; \
670 if ((env->fsr & FSR_NVM) || TRAP) { \
671 env->fsr |= new_fsr; \
672 env->fsr |= FSR_NVC; \
673 env->fsr |= FSR_FTT_IEEE_EXCP; \
674 raise_exception(TT_FP_EXCP); \
676 env->fsr |= FSR_NVA; \
679 case float_relation_less: \
680 new_fsr = FSR_FCC0 << FS; \
682 case float_relation_greater: \
683 new_fsr = FSR_FCC1 << FS; \
689 env->fsr |= new_fsr; \
692 GEN_FCMPS(fcmps
, float32
, 0, 0);
693 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
695 GEN_FCMPS(fcmpes
, float32
, 0, 1);
696 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
698 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
699 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
701 #ifdef TARGET_SPARC64
702 GEN_FCMPS(fcmps_fcc1
, float32
, 22, 0);
703 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
704 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
706 GEN_FCMPS(fcmps_fcc2
, float32
, 24, 0);
707 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
708 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
710 GEN_FCMPS(fcmps_fcc3
, float32
, 26, 0);
711 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
712 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
714 GEN_FCMPS(fcmpes_fcc1
, float32
, 22, 1);
715 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
716 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
718 GEN_FCMPS(fcmpes_fcc2
, float32
, 24, 1);
719 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
720 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
722 GEN_FCMPS(fcmpes_fcc3
, float32
, 26, 1);
723 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
724 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
728 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
730 static void dump_mxcc(CPUState
*env
)
732 printf("mxccdata: %016llx %016llx %016llx %016llx\n",
733 env
->mxccdata
[0], env
->mxccdata
[1],
734 env
->mxccdata
[2], env
->mxccdata
[3]);
735 printf("mxccregs: %016llx %016llx %016llx %016llx\n"
736 " %016llx %016llx %016llx %016llx\n",
737 env
->mxccregs
[0], env
->mxccregs
[1],
738 env
->mxccregs
[2], env
->mxccregs
[3],
739 env
->mxccregs
[4], env
->mxccregs
[5],
740 env
->mxccregs
[6], env
->mxccregs
[7]);
744 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
745 && defined(DEBUG_ASI)
746 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
752 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
753 addr
, asi
, r1
& 0xff);
756 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
757 addr
, asi
, r1
& 0xffff);
760 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
761 addr
, asi
, r1
& 0xffffffff);
764 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
771 #ifndef TARGET_SPARC64
772 #ifndef CONFIG_USER_ONLY
773 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
776 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
777 uint32_t last_addr
= addr
;
780 helper_check_align(addr
, size
- 1);
782 case 2: /* SuperSparc MXCC registers */
784 case 0x01c00a00: /* MXCC control register */
786 ret
= env
->mxccregs
[3];
788 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
791 case 0x01c00a04: /* MXCC control register */
793 ret
= env
->mxccregs
[3];
795 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
798 case 0x01c00c00: /* Module reset register */
800 ret
= env
->mxccregs
[5];
801 // should we do something here?
803 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
806 case 0x01c00f00: /* MBus port address register */
808 ret
= env
->mxccregs
[7];
810 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
814 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
818 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
819 "addr = %08x -> ret = %" PRIx64
","
820 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
825 case 3: /* MMU probe */
829 mmulev
= (addr
>> 8) & 15;
833 ret
= mmu_probe(env
, addr
, mmulev
);
834 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
838 case 4: /* read MMU regs */
840 int reg
= (addr
>> 8) & 0x1f;
842 ret
= env
->mmuregs
[reg
];
843 if (reg
== 3) /* Fault status cleared on read */
845 else if (reg
== 0x13) /* Fault status read */
846 ret
= env
->mmuregs
[3];
847 else if (reg
== 0x14) /* Fault address read */
848 ret
= env
->mmuregs
[4];
849 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
852 case 5: // Turbosparc ITLB Diagnostic
853 case 6: // Turbosparc DTLB Diagnostic
854 case 7: // Turbosparc IOTLB Diagnostic
856 case 9: /* Supervisor code access */
859 ret
= ldub_code(addr
);
862 ret
= lduw_code(addr
);
866 ret
= ldl_code(addr
);
869 ret
= ldq_code(addr
);
873 case 0xa: /* User data access */
876 ret
= ldub_user(addr
);
879 ret
= lduw_user(addr
);
883 ret
= ldl_user(addr
);
886 ret
= ldq_user(addr
);
890 case 0xb: /* Supervisor data access */
893 ret
= ldub_kernel(addr
);
896 ret
= lduw_kernel(addr
);
900 ret
= ldl_kernel(addr
);
903 ret
= ldq_kernel(addr
);
907 case 0xc: /* I-cache tag */
908 case 0xd: /* I-cache data */
909 case 0xe: /* D-cache tag */
910 case 0xf: /* D-cache data */
912 case 0x20: /* MMU passthrough */
915 ret
= ldub_phys(addr
);
918 ret
= lduw_phys(addr
);
922 ret
= ldl_phys(addr
);
925 ret
= ldq_phys(addr
);
929 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
932 ret
= ldub_phys((target_phys_addr_t
)addr
933 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
936 ret
= lduw_phys((target_phys_addr_t
)addr
937 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
941 ret
= ldl_phys((target_phys_addr_t
)addr
942 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
945 ret
= ldq_phys((target_phys_addr_t
)addr
946 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
950 case 0x30: // Turbosparc secondary cache diagnostic
951 case 0x31: // Turbosparc RAM snoop
952 case 0x32: // Turbosparc page table descriptor diagnostic
953 case 0x39: /* data cache diagnostic register */
956 case 8: /* User code access, XXX */
958 do_unassigned_access(addr
, 0, 0, asi
, size
);
978 dump_asi("read ", last_addr
, asi
, size
, ret
);
983 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
985 helper_check_align(addr
, size
- 1);
987 case 2: /* SuperSparc MXCC registers */
989 case 0x01c00000: /* MXCC stream data register 0 */
991 env
->mxccdata
[0] = val
;
993 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
996 case 0x01c00008: /* MXCC stream data register 1 */
998 env
->mxccdata
[1] = val
;
1000 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1003 case 0x01c00010: /* MXCC stream data register 2 */
1005 env
->mxccdata
[2] = val
;
1007 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1010 case 0x01c00018: /* MXCC stream data register 3 */
1012 env
->mxccdata
[3] = val
;
1014 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1017 case 0x01c00100: /* MXCC stream source */
1019 env
->mxccregs
[0] = val
;
1021 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1023 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1025 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1027 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1029 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1032 case 0x01c00200: /* MXCC stream destination */
1034 env
->mxccregs
[1] = val
;
1036 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1038 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1040 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1042 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1044 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1047 case 0x01c00a00: /* MXCC control register */
1049 env
->mxccregs
[3] = val
;
1051 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1054 case 0x01c00a04: /* MXCC control register */
1056 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1059 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1062 case 0x01c00e00: /* MXCC error register */
1063 // writing a 1 bit clears the error
1065 env
->mxccregs
[6] &= ~val
;
1067 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1070 case 0x01c00f00: /* MBus port address register */
1072 env
->mxccregs
[7] = val
;
1074 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1078 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1082 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1083 asi
, size
, addr
, val
);
1088 case 3: /* MMU flush */
1092 mmulev
= (addr
>> 8) & 15;
1093 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1095 case 0: // flush page
1096 tlb_flush_page(env
, addr
& 0xfffff000);
1098 case 1: // flush segment (256k)
1099 case 2: // flush region (16M)
1100 case 3: // flush context (4G)
1101 case 4: // flush entire
1112 case 4: /* write MMU regs */
1114 int reg
= (addr
>> 8) & 0x1f;
1117 oldreg
= env
->mmuregs
[reg
];
1119 case 0: // Control Register
1120 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1122 // Mappings generated during no-fault mode or MMU
1123 // disabled mode are invalid in normal mode
1124 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1125 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1128 case 1: // Context Table Pointer Register
1129 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1131 case 2: // Context Register
1132 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1133 if (oldreg
!= env
->mmuregs
[reg
]) {
1134 /* we flush when the MMU context changes because
1135 QEMU has no MMU context support */
1139 case 3: // Synchronous Fault Status Register with Clear
1140 case 4: // Synchronous Fault Address Register
1142 case 0x10: // TLB Replacement Control Register
1143 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1145 case 0x13: // Synchronous Fault Status Register with Read and Clear
1146 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1148 case 0x14: // Synchronous Fault Address Register
1149 env
->mmuregs
[4] = val
;
1152 env
->mmuregs
[reg
] = val
;
1155 if (oldreg
!= env
->mmuregs
[reg
]) {
1156 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1157 reg
, oldreg
, env
->mmuregs
[reg
]);
1164 case 5: // Turbosparc ITLB Diagnostic
1165 case 6: // Turbosparc DTLB Diagnostic
1166 case 7: // Turbosparc IOTLB Diagnostic
1168 case 0xa: /* User data access */
1171 stb_user(addr
, val
);
1174 stw_user(addr
, val
);
1178 stl_user(addr
, val
);
1181 stq_user(addr
, val
);
1185 case 0xb: /* Supervisor data access */
1188 stb_kernel(addr
, val
);
1191 stw_kernel(addr
, val
);
1195 stl_kernel(addr
, val
);
1198 stq_kernel(addr
, val
);
1202 case 0xc: /* I-cache tag */
1203 case 0xd: /* I-cache data */
1204 case 0xe: /* D-cache tag */
1205 case 0xf: /* D-cache data */
1206 case 0x10: /* I/D-cache flush page */
1207 case 0x11: /* I/D-cache flush segment */
1208 case 0x12: /* I/D-cache flush region */
1209 case 0x13: /* I/D-cache flush context */
1210 case 0x14: /* I/D-cache flush user */
1212 case 0x17: /* Block copy, sta access */
1218 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1220 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1221 temp
= ldl_kernel(src
);
1222 stl_kernel(dst
, temp
);
1226 case 0x1f: /* Block fill, stda access */
1229 // fill 32 bytes with val
1231 uint32_t dst
= addr
& 7;
1233 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1234 stq_kernel(dst
, val
);
1237 case 0x20: /* MMU passthrough */
1241 stb_phys(addr
, val
);
1244 stw_phys(addr
, val
);
1248 stl_phys(addr
, val
);
1251 stq_phys(addr
, val
);
1256 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1260 stb_phys((target_phys_addr_t
)addr
1261 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1264 stw_phys((target_phys_addr_t
)addr
1265 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1269 stl_phys((target_phys_addr_t
)addr
1270 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1273 stq_phys((target_phys_addr_t
)addr
1274 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1279 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1280 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1281 // Turbosparc snoop RAM
1282 case 0x32: // store buffer control or Turbosparc page table
1283 // descriptor diagnostic
1284 case 0x36: /* I-cache flash clear */
1285 case 0x37: /* D-cache flash clear */
1286 case 0x38: /* breakpoint diagnostics */
1287 case 0x4c: /* breakpoint action */
1289 case 8: /* User code access, XXX */
1290 case 9: /* Supervisor code access, XXX */
1292 do_unassigned_access(addr
, 1, 0, asi
, size
);
1296 dump_asi("write", addr
, asi
, size
, val
);
1300 #endif /* CONFIG_USER_ONLY */
1301 #else /* TARGET_SPARC64 */
1303 #ifdef CONFIG_USER_ONLY
1304 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1307 #if defined(DEBUG_ASI)
1308 target_ulong last_addr
= addr
;
1312 raise_exception(TT_PRIV_ACT
);
1314 helper_check_align(addr
, size
- 1);
1315 address_mask(env
, &addr
);
1318 case 0x82: // Primary no-fault
1319 case 0x8a: // Primary no-fault LE
1320 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1322 dump_asi("read ", last_addr
, asi
, size
, ret
);
1327 case 0x80: // Primary
1328 case 0x88: // Primary LE
1332 ret
= ldub_raw(addr
);
1335 ret
= lduw_raw(addr
);
1338 ret
= ldl_raw(addr
);
1342 ret
= ldq_raw(addr
);
1347 case 0x83: // Secondary no-fault
1348 case 0x8b: // Secondary no-fault LE
1349 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1351 dump_asi("read ", last_addr
, asi
, size
, ret
);
1356 case 0x81: // Secondary
1357 case 0x89: // Secondary LE
1364 /* Convert from little endian */
1366 case 0x88: // Primary LE
1367 case 0x89: // Secondary LE
1368 case 0x8a: // Primary no-fault LE
1369 case 0x8b: // Secondary no-fault LE
1387 /* Convert to signed number */
1394 ret
= (int16_t) ret
;
1397 ret
= (int32_t) ret
;
1404 dump_asi("read ", last_addr
, asi
, size
, ret
);
1409 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1412 dump_asi("write", addr
, asi
, size
, val
);
1415 raise_exception(TT_PRIV_ACT
);
1417 helper_check_align(addr
, size
- 1);
1418 address_mask(env
, &addr
);
1420 /* Convert to little endian */
1422 case 0x88: // Primary LE
1423 case 0x89: // Secondary LE
1426 addr
= bswap16(addr
);
1429 addr
= bswap32(addr
);
1432 addr
= bswap64(addr
);
1442 case 0x80: // Primary
1443 case 0x88: // Primary LE
1462 case 0x81: // Secondary
1463 case 0x89: // Secondary LE
1467 case 0x82: // Primary no-fault, RO
1468 case 0x83: // Secondary no-fault, RO
1469 case 0x8a: // Primary no-fault LE, RO
1470 case 0x8b: // Secondary no-fault LE, RO
1472 do_unassigned_access(addr
, 1, 0, 1, size
);
1477 #else /* CONFIG_USER_ONLY */
1479 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1482 #if defined(DEBUG_ASI)
1483 target_ulong last_addr
= addr
;
1486 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1487 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1488 && asi
>= 0x30 && asi
< 0x80
1489 && !(env
->hpstate
& HS_PRIV
)))
1490 raise_exception(TT_PRIV_ACT
);
1492 helper_check_align(addr
, size
- 1);
1494 case 0x82: // Primary no-fault
1495 case 0x8a: // Primary no-fault LE
1496 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
1498 dump_asi("read ", last_addr
, asi
, size
, ret
);
1503 case 0x10: // As if user primary
1504 case 0x18: // As if user primary LE
1505 case 0x80: // Primary
1506 case 0x88: // Primary LE
1507 case 0xe2: // UA2007 Primary block init
1508 case 0xe3: // UA2007 Secondary block init
1509 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1510 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1511 && env
->hpstate
& HS_PRIV
) {
1514 ret
= ldub_hypv(addr
);
1517 ret
= lduw_hypv(addr
);
1520 ret
= ldl_hypv(addr
);
1524 ret
= ldq_hypv(addr
);
1530 ret
= ldub_kernel(addr
);
1533 ret
= lduw_kernel(addr
);
1536 ret
= ldl_kernel(addr
);
1540 ret
= ldq_kernel(addr
);
1547 ret
= ldub_user(addr
);
1550 ret
= lduw_user(addr
);
1553 ret
= ldl_user(addr
);
1557 ret
= ldq_user(addr
);
1562 case 0x14: // Bypass
1563 case 0x15: // Bypass, non-cacheable
1564 case 0x1c: // Bypass LE
1565 case 0x1d: // Bypass, non-cacheable LE
1569 ret
= ldub_phys(addr
);
1572 ret
= lduw_phys(addr
);
1575 ret
= ldl_phys(addr
);
1579 ret
= ldq_phys(addr
);
1584 case 0x24: // Nucleus quad LDD 128 bit atomic
1585 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1586 // Only ldda allowed
1587 raise_exception(TT_ILL_INSN
);
1589 case 0x83: // Secondary no-fault
1590 case 0x8b: // Secondary no-fault LE
1591 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
1593 dump_asi("read ", last_addr
, asi
, size
, ret
);
1598 case 0x04: // Nucleus
1599 case 0x0c: // Nucleus Little Endian (LE)
1600 case 0x11: // As if user secondary
1601 case 0x19: // As if user secondary LE
1602 case 0x4a: // UPA config
1603 case 0x81: // Secondary
1604 case 0x89: // Secondary LE
1610 case 0x50: // I-MMU regs
1612 int reg
= (addr
>> 3) & 0xf;
1614 ret
= env
->immuregs
[reg
];
1617 case 0x51: // I-MMU 8k TSB pointer
1618 case 0x52: // I-MMU 64k TSB pointer
1621 case 0x55: // I-MMU data access
1623 int reg
= (addr
>> 3) & 0x3f;
1625 ret
= env
->itlb_tte
[reg
];
1628 case 0x56: // I-MMU tag read
1630 int reg
= (addr
>> 3) & 0x3f;
1632 ret
= env
->itlb_tag
[reg
];
1635 case 0x58: // D-MMU regs
1637 int reg
= (addr
>> 3) & 0xf;
1639 ret
= env
->dmmuregs
[reg
];
1642 case 0x5d: // D-MMU data access
1644 int reg
= (addr
>> 3) & 0x3f;
1646 ret
= env
->dtlb_tte
[reg
];
1649 case 0x5e: // D-MMU tag read
1651 int reg
= (addr
>> 3) & 0x3f;
1653 ret
= env
->dtlb_tag
[reg
];
1656 case 0x46: // D-cache data
1657 case 0x47: // D-cache tag access
1658 case 0x4b: // E-cache error enable
1659 case 0x4c: // E-cache asynchronous fault status
1660 case 0x4d: // E-cache asynchronous fault address
1661 case 0x4e: // E-cache tag data
1662 case 0x66: // I-cache instruction access
1663 case 0x67: // I-cache tag access
1664 case 0x6e: // I-cache predecode
1665 case 0x6f: // I-cache LRU etc.
1666 case 0x76: // E-cache tag
1667 case 0x7e: // E-cache tag
1669 case 0x59: // D-MMU 8k TSB pointer
1670 case 0x5a: // D-MMU 64k TSB pointer
1671 case 0x5b: // D-MMU data pointer
1672 case 0x48: // Interrupt dispatch, RO
1673 case 0x49: // Interrupt data receive
1674 case 0x7f: // Incoming interrupt vector, RO
1677 case 0x54: // I-MMU data in, WO
1678 case 0x57: // I-MMU demap, WO
1679 case 0x5c: // D-MMU data in, WO
1680 case 0x5f: // D-MMU demap, WO
1681 case 0x77: // Interrupt vector, WO
1683 do_unassigned_access(addr
, 0, 0, 1, size
);
1688 /* Convert from little endian */
1690 case 0x0c: // Nucleus Little Endian (LE)
1691 case 0x18: // As if user primary LE
1692 case 0x19: // As if user secondary LE
1693 case 0x1c: // Bypass LE
1694 case 0x1d: // Bypass, non-cacheable LE
1695 case 0x88: // Primary LE
1696 case 0x89: // Secondary LE
1697 case 0x8a: // Primary no-fault LE
1698 case 0x8b: // Secondary no-fault LE
1716 /* Convert to signed number */
1723 ret
= (int16_t) ret
;
1726 ret
= (int32_t) ret
;
1733 dump_asi("read ", last_addr
, asi
, size
, ret
);
1738 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1741 dump_asi("write", addr
, asi
, size
, val
);
1743 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1744 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1745 && asi
>= 0x30 && asi
< 0x80
1746 && !(env
->hpstate
& HS_PRIV
)))
1747 raise_exception(TT_PRIV_ACT
);
1749 helper_check_align(addr
, size
- 1);
1750 /* Convert to little endian */
1752 case 0x0c: // Nucleus Little Endian (LE)
1753 case 0x18: // As if user primary LE
1754 case 0x19: // As if user secondary LE
1755 case 0x1c: // Bypass LE
1756 case 0x1d: // Bypass, non-cacheable LE
1757 case 0x88: // Primary LE
1758 case 0x89: // Secondary LE
1761 addr
= bswap16(addr
);
1764 addr
= bswap32(addr
);
1767 addr
= bswap64(addr
);
1777 case 0x10: // As if user primary
1778 case 0x18: // As if user primary LE
1779 case 0x80: // Primary
1780 case 0x88: // Primary LE
1781 case 0xe2: // UA2007 Primary block init
1782 case 0xe3: // UA2007 Secondary block init
1783 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1784 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1785 && env
->hpstate
& HS_PRIV
) {
1788 stb_hypv(addr
, val
);
1791 stw_hypv(addr
, val
);
1794 stl_hypv(addr
, val
);
1798 stq_hypv(addr
, val
);
1804 stb_kernel(addr
, val
);
1807 stw_kernel(addr
, val
);
1810 stl_kernel(addr
, val
);
1814 stq_kernel(addr
, val
);
1821 stb_user(addr
, val
);
1824 stw_user(addr
, val
);
1827 stl_user(addr
, val
);
1831 stq_user(addr
, val
);
1836 case 0x14: // Bypass
1837 case 0x15: // Bypass, non-cacheable
1838 case 0x1c: // Bypass LE
1839 case 0x1d: // Bypass, non-cacheable LE
1843 stb_phys(addr
, val
);
1846 stw_phys(addr
, val
);
1849 stl_phys(addr
, val
);
1853 stq_phys(addr
, val
);
1858 case 0x24: // Nucleus quad LDD 128 bit atomic
1859 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1860 // Only ldda allowed
1861 raise_exception(TT_ILL_INSN
);
1863 case 0x04: // Nucleus
1864 case 0x0c: // Nucleus Little Endian (LE)
1865 case 0x11: // As if user secondary
1866 case 0x19: // As if user secondary LE
1867 case 0x4a: // UPA config
1868 case 0x81: // Secondary
1869 case 0x89: // Secondary LE
1877 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1878 // Mappings generated during D/I MMU disabled mode are
1879 // invalid in normal mode
1880 if (oldreg
!= env
->lsu
) {
1881 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1890 case 0x50: // I-MMU regs
1892 int reg
= (addr
>> 3) & 0xf;
1895 oldreg
= env
->immuregs
[reg
];
1900 case 1: // Not in I-MMU
1907 val
= 0; // Clear SFSR
1909 case 5: // TSB access
1910 case 6: // Tag access
1914 env
->immuregs
[reg
] = val
;
1915 if (oldreg
!= env
->immuregs
[reg
]) {
1916 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
1917 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1924 case 0x54: // I-MMU data in
1928 // Try finding an invalid entry
1929 for (i
= 0; i
< 64; i
++) {
1930 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
1931 env
->itlb_tag
[i
] = env
->immuregs
[6];
1932 env
->itlb_tte
[i
] = val
;
1936 // Try finding an unlocked entry
1937 for (i
= 0; i
< 64; i
++) {
1938 if ((env
->itlb_tte
[i
] & 0x40) == 0) {
1939 env
->itlb_tag
[i
] = env
->immuregs
[6];
1940 env
->itlb_tte
[i
] = val
;
1947 case 0x55: // I-MMU data access
1951 unsigned int i
= (addr
>> 3) & 0x3f;
1953 env
->itlb_tag
[i
] = env
->immuregs
[6];
1954 env
->itlb_tte
[i
] = val
;
1957 case 0x57: // I-MMU demap
1961 for (i
= 0; i
< 64; i
++) {
1962 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
1963 target_ulong mask
= 0xffffffffffffe000ULL
;
1965 mask
<<= 3 * ((env
->itlb_tte
[i
] >> 61) & 3);
1966 if ((val
& mask
) == (env
->itlb_tag
[i
] & mask
)) {
1967 env
->itlb_tag
[i
] = 0;
1968 env
->itlb_tte
[i
] = 0;
1975 case 0x58: // D-MMU regs
1977 int reg
= (addr
>> 3) & 0xf;
1980 oldreg
= env
->dmmuregs
[reg
];
1986 if ((val
& 1) == 0) {
1987 val
= 0; // Clear SFSR, Fault address
1988 env
->dmmuregs
[4] = 0;
1990 env
->dmmuregs
[reg
] = val
;
1992 case 1: // Primary context
1993 case 2: // Secondary context
1994 case 5: // TSB access
1995 case 6: // Tag access
1996 case 7: // Virtual Watchpoint
1997 case 8: // Physical Watchpoint
2001 env
->dmmuregs
[reg
] = val
;
2002 if (oldreg
!= env
->dmmuregs
[reg
]) {
2003 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
2004 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2011 case 0x5c: // D-MMU data in
2015 // Try finding an invalid entry
2016 for (i
= 0; i
< 64; i
++) {
2017 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
2018 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2019 env
->dtlb_tte
[i
] = val
;
2023 // Try finding an unlocked entry
2024 for (i
= 0; i
< 64; i
++) {
2025 if ((env
->dtlb_tte
[i
] & 0x40) == 0) {
2026 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2027 env
->dtlb_tte
[i
] = val
;
2034 case 0x5d: // D-MMU data access
2036 unsigned int i
= (addr
>> 3) & 0x3f;
2038 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2039 env
->dtlb_tte
[i
] = val
;
2042 case 0x5f: // D-MMU demap
2046 for (i
= 0; i
< 64; i
++) {
2047 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
2048 target_ulong mask
= 0xffffffffffffe000ULL
;
2050 mask
<<= 3 * ((env
->dtlb_tte
[i
] >> 61) & 3);
2051 if ((val
& mask
) == (env
->dtlb_tag
[i
] & mask
)) {
2052 env
->dtlb_tag
[i
] = 0;
2053 env
->dtlb_tte
[i
] = 0;
2060 case 0x49: // Interrupt data receive
2063 case 0x46: // D-cache data
2064 case 0x47: // D-cache tag access
2065 case 0x4b: // E-cache error enable
2066 case 0x4c: // E-cache asynchronous fault status
2067 case 0x4d: // E-cache asynchronous fault address
2068 case 0x4e: // E-cache tag data
2069 case 0x66: // I-cache instruction access
2070 case 0x67: // I-cache tag access
2071 case 0x6e: // I-cache predecode
2072 case 0x6f: // I-cache LRU etc.
2073 case 0x76: // E-cache tag
2074 case 0x7e: // E-cache tag
2076 case 0x51: // I-MMU 8k TSB pointer, RO
2077 case 0x52: // I-MMU 64k TSB pointer, RO
2078 case 0x56: // I-MMU tag read, RO
2079 case 0x59: // D-MMU 8k TSB pointer, RO
2080 case 0x5a: // D-MMU 64k TSB pointer, RO
2081 case 0x5b: // D-MMU data pointer, RO
2082 case 0x5e: // D-MMU tag read, RO
2083 case 0x48: // Interrupt dispatch, RO
2084 case 0x7f: // Incoming interrupt vector, RO
2085 case 0x82: // Primary no-fault, RO
2086 case 0x83: // Secondary no-fault, RO
2087 case 0x8a: // Primary no-fault LE, RO
2088 case 0x8b: // Secondary no-fault LE, RO
2090 do_unassigned_access(addr
, 1, 0, 1, size
);
2094 #endif /* CONFIG_USER_ONLY */
2096 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2098 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2099 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2100 && asi
>= 0x30 && asi
< 0x80
2101 && !(env
->hpstate
& HS_PRIV
)))
2102 raise_exception(TT_PRIV_ACT
);
2105 case 0x24: // Nucleus quad LDD 128 bit atomic
2106 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2107 helper_check_align(addr
, 0xf);
2109 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2111 bswap64s(&env
->gregs
[1]);
2112 } else if (rd
< 8) {
2113 env
->gregs
[rd
] = ldq_kernel(addr
);
2114 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2116 bswap64s(&env
->gregs
[rd
]);
2117 bswap64s(&env
->gregs
[rd
+ 1]);
2120 env
->regwptr
[rd
] = ldq_kernel(addr
);
2121 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2123 bswap64s(&env
->regwptr
[rd
]);
2124 bswap64s(&env
->regwptr
[rd
+ 1]);
2129 helper_check_align(addr
, 0x3);
2131 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2133 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2134 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2136 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2137 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2143 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2148 helper_check_align(addr
, 3);
2150 case 0xf0: // Block load primary
2151 case 0xf1: // Block load secondary
2152 case 0xf8: // Block load primary LE
2153 case 0xf9: // Block load secondary LE
2155 raise_exception(TT_ILL_INSN
);
2158 helper_check_align(addr
, 0x3f);
2159 for (i
= 0; i
< 16; i
++) {
2160 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2170 val
= helper_ld_asi(addr
, asi
, size
, 0);
2174 *((uint32_t *)&env
->fpr
[rd
]) = val
;
2177 *((int64_t *)&DT0
) = val
;
2185 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2188 target_ulong val
= 0;
2190 helper_check_align(addr
, 3);
2192 case 0xe0: // UA2007 Block commit store primary (cache flush)
2193 case 0xe1: // UA2007 Block commit store secondary (cache flush)
2194 case 0xf0: // Block store primary
2195 case 0xf1: // Block store secondary
2196 case 0xf8: // Block store primary LE
2197 case 0xf9: // Block store secondary LE
2199 raise_exception(TT_ILL_INSN
);
2202 helper_check_align(addr
, 0x3f);
2203 for (i
= 0; i
< 16; i
++) {
2204 val
= *(uint32_t *)&env
->fpr
[rd
++];
2205 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2217 val
= *((uint32_t *)&env
->fpr
[rd
]);
2220 val
= *((int64_t *)&DT0
);
2226 helper_st_asi(addr
, val
, asi
, size
);
2229 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2230 target_ulong val2
, uint32_t asi
)
2234 val2
&= 0xffffffffUL
;
2235 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2236 ret
&= 0xffffffffUL
;
2238 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
2242 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2243 target_ulong val2
, uint32_t asi
)
2247 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2249 helper_st_asi(addr
, val1
, asi
, 8);
2252 #endif /* TARGET_SPARC64 */
2254 #ifndef TARGET_SPARC64
2255 void helper_rett(void)
2259 if (env
->psret
== 1)
2260 raise_exception(TT_ILL_INSN
);
2263 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2264 if (env
->wim
& (1 << cwp
)) {
2265 raise_exception(TT_WIN_UNF
);
2268 env
->psrs
= env
->psrps
;
2272 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2277 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2281 raise_exception(TT_DIV_ZERO
);
2285 if (x0
> 0xffffffff) {
2294 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2299 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2303 raise_exception(TT_DIV_ZERO
);
2307 if ((int32_t) x0
!= x0
) {
2309 return x0
< 0? 0x80000000: 0x7fffffff;
2316 void helper_stdf(target_ulong addr
, int mem_idx
)
2318 helper_check_align(addr
, 7);
2319 #if !defined(CONFIG_USER_ONLY)
2322 stfq_user(addr
, DT0
);
2325 stfq_kernel(addr
, DT0
);
2327 #ifdef TARGET_SPARC64
2329 stfq_hypv(addr
, DT0
);
2336 address_mask(env
, &addr
);
2337 stfq_raw(addr
, DT0
);
2341 void helper_lddf(target_ulong addr
, int mem_idx
)
2343 helper_check_align(addr
, 7);
2344 #if !defined(CONFIG_USER_ONLY)
2347 DT0
= ldfq_user(addr
);
2350 DT0
= ldfq_kernel(addr
);
2352 #ifdef TARGET_SPARC64
2354 DT0
= ldfq_hypv(addr
);
2361 address_mask(env
, &addr
);
2362 DT0
= ldfq_raw(addr
);
2366 void helper_ldqf(target_ulong addr
, int mem_idx
)
2368 // XXX add 128 bit load
2371 helper_check_align(addr
, 7);
2372 #if !defined(CONFIG_USER_ONLY)
2375 u
.ll
.upper
= ldq_user(addr
);
2376 u
.ll
.lower
= ldq_user(addr
+ 8);
2380 u
.ll
.upper
= ldq_kernel(addr
);
2381 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2384 #ifdef TARGET_SPARC64
2386 u
.ll
.upper
= ldq_hypv(addr
);
2387 u
.ll
.lower
= ldq_hypv(addr
+ 8);
2395 address_mask(env
, &addr
);
2396 u
.ll
.upper
= ldq_raw(addr
);
2397 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
2402 void helper_stqf(target_ulong addr
, int mem_idx
)
2404 // XXX add 128 bit store
2407 helper_check_align(addr
, 7);
2408 #if !defined(CONFIG_USER_ONLY)
2412 stq_user(addr
, u
.ll
.upper
);
2413 stq_user(addr
+ 8, u
.ll
.lower
);
2417 stq_kernel(addr
, u
.ll
.upper
);
2418 stq_kernel(addr
+ 8, u
.ll
.lower
);
2420 #ifdef TARGET_SPARC64
2423 stq_hypv(addr
, u
.ll
.upper
);
2424 stq_hypv(addr
+ 8, u
.ll
.lower
);
2432 address_mask(env
, &addr
);
2433 stq_raw(addr
, u
.ll
.upper
);
2434 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
2438 static inline void set_fsr(void)
2442 switch (env
->fsr
& FSR_RD_MASK
) {
2443 case FSR_RD_NEAREST
:
2444 rnd_mode
= float_round_nearest_even
;
2448 rnd_mode
= float_round_to_zero
;
2451 rnd_mode
= float_round_up
;
2454 rnd_mode
= float_round_down
;
2457 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
2460 void helper_ldfsr(uint32_t new_fsr
)
2462 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
2466 #ifdef TARGET_SPARC64
2467 void helper_ldxfsr(uint64_t new_fsr
)
2469 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
2474 void helper_debug(void)
2476 env
->exception_index
= EXCP_DEBUG
;
2480 #ifndef TARGET_SPARC64
2481 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2483 void helper_save(void)
2487 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2488 if (env
->wim
& (1 << cwp
)) {
2489 raise_exception(TT_WIN_OVF
);
2494 void helper_restore(void)
2498 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2499 if (env
->wim
& (1 << cwp
)) {
2500 raise_exception(TT_WIN_UNF
);
2505 void helper_wrpsr(target_ulong new_psr
)
2507 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
2508 raise_exception(TT_ILL_INSN
);
2510 PUT_PSR(env
, new_psr
);
2513 target_ulong
helper_rdpsr(void)
2515 return GET_PSR(env
);
2519 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2521 void helper_save(void)
2525 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2526 if (env
->cansave
== 0) {
2527 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2528 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2529 ((env
->wstate
& 0x7) << 2)));
2531 if (env
->cleanwin
- env
->canrestore
== 0) {
2532 // XXX Clean windows without trap
2533 raise_exception(TT_CLRWIN
);
2542 void helper_restore(void)
2546 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2547 if (env
->canrestore
== 0) {
2548 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
2549 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2550 ((env
->wstate
& 0x7) << 2)));
2558 void helper_flushw(void)
2560 if (env
->cansave
!= env
->nwindows
- 2) {
2561 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2562 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2563 ((env
->wstate
& 0x7) << 2)));
2567 void helper_saved(void)
2570 if (env
->otherwin
== 0)
2576 void helper_restored(void)
2579 if (env
->cleanwin
< env
->nwindows
- 1)
2581 if (env
->otherwin
== 0)
2587 target_ulong
helper_rdccr(void)
2589 return GET_CCR(env
);
2592 void helper_wrccr(target_ulong new_ccr
)
2594 PUT_CCR(env
, new_ccr
);
2597 // CWP handling is reversed in V9, but we still use the V8 register
2599 target_ulong
helper_rdcwp(void)
2601 return GET_CWP64(env
);
2604 void helper_wrcwp(target_ulong new_cwp
)
2606 PUT_CWP64(env
, new_cwp
);
2609 // This function uses non-native bit order
2610 #define GET_FIELD(X, FROM, TO) \
2611 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
2613 // This function uses the order in the manuals, i.e. bit 0 is 2^0
2614 #define GET_FIELD_SP(X, FROM, TO) \
2615 GET_FIELD(X, 63 - (TO), 63 - (FROM))
2617 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
2619 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
2620 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
2621 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
2622 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
2623 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
2624 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
2625 (((pixel_addr
>> 55) & 1) << 4) |
2626 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
2627 GET_FIELD_SP(pixel_addr
, 11, 12);
2630 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
2634 tmp
= addr
+ offset
;
2636 env
->gsr
|= tmp
& 7ULL;
2640 target_ulong
helper_popc(target_ulong val
)
2642 return ctpop64(val
);
2645 static inline uint64_t *get_gregset(uint64_t pstate
)
2660 static inline void change_pstate(uint64_t new_pstate
)
2662 uint64_t pstate_regs
, new_pstate_regs
;
2663 uint64_t *src
, *dst
;
2665 pstate_regs
= env
->pstate
& 0xc01;
2666 new_pstate_regs
= new_pstate
& 0xc01;
2667 if (new_pstate_regs
!= pstate_regs
) {
2668 // Switch global register bank
2669 src
= get_gregset(new_pstate_regs
);
2670 dst
= get_gregset(pstate_regs
);
2671 memcpy32(dst
, env
->gregs
);
2672 memcpy32(env
->gregs
, src
);
2674 env
->pstate
= new_pstate
;
2677 void helper_wrpstate(target_ulong new_state
)
2679 if (!(env
->def
->features
& CPU_FEATURE_GL
))
2680 change_pstate(new_state
& 0xf3f);
2683 void helper_done(void)
2685 env
->pc
= env
->tsptr
->tpc
;
2686 env
->npc
= env
->tsptr
->tnpc
+ 4;
2687 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2688 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2689 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2690 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2692 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2695 void helper_retry(void)
2697 env
->pc
= env
->tsptr
->tpc
;
2698 env
->npc
= env
->tsptr
->tnpc
;
2699 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2700 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2701 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2702 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2704 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2707 void helper_set_softint(uint64_t value
)
2709 env
->softint
|= (uint32_t)value
;
2712 void helper_clear_softint(uint64_t value
)
2714 env
->softint
&= (uint32_t)~value
;
2717 void helper_write_softint(uint64_t value
)
2719 env
->softint
= (uint32_t)value
;
2723 void helper_flush(target_ulong addr
)
2726 tb_invalidate_page_range(addr
, addr
+ 8);
2729 #ifdef TARGET_SPARC64
2731 static const char * const excp_names
[0x80] = {
2732 [TT_TFAULT
] = "Instruction Access Fault",
2733 [TT_TMISS
] = "Instruction Access MMU Miss",
2734 [TT_CODE_ACCESS
] = "Instruction Access Error",
2735 [TT_ILL_INSN
] = "Illegal Instruction",
2736 [TT_PRIV_INSN
] = "Privileged Instruction",
2737 [TT_NFPU_INSN
] = "FPU Disabled",
2738 [TT_FP_EXCP
] = "FPU Exception",
2739 [TT_TOVF
] = "Tag Overflow",
2740 [TT_CLRWIN
] = "Clean Windows",
2741 [TT_DIV_ZERO
] = "Division By Zero",
2742 [TT_DFAULT
] = "Data Access Fault",
2743 [TT_DMISS
] = "Data Access MMU Miss",
2744 [TT_DATA_ACCESS
] = "Data Access Error",
2745 [TT_DPROT
] = "Data Protection Error",
2746 [TT_UNALIGNED
] = "Unaligned Memory Access",
2747 [TT_PRIV_ACT
] = "Privileged Action",
2748 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2749 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2750 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2751 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2752 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2753 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2754 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2755 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2756 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2757 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2758 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2759 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2760 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2761 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2762 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2766 void do_interrupt(CPUState
*env
)
2768 int intno
= env
->exception_index
;
2771 if (loglevel
& CPU_LOG_INT
) {
2775 if (intno
< 0 || intno
>= 0x180)
2777 else if (intno
>= 0x100)
2778 name
= "Trap Instruction";
2779 else if (intno
>= 0xc0)
2780 name
= "Window Fill";
2781 else if (intno
>= 0x80)
2782 name
= "Window Spill";
2784 name
= excp_names
[intno
];
2789 fprintf(logfile
, "%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
2790 " SP=%016" PRIx64
"\n",
2793 env
->npc
, env
->regwptr
[6]);
2794 cpu_dump_state(env
, logfile
, fprintf
, 0);
2800 fprintf(logfile
, " code=");
2801 ptr
= (uint8_t *)env
->pc
;
2802 for(i
= 0; i
< 16; i
++) {
2803 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
2805 fprintf(logfile
, "\n");
2811 #if !defined(CONFIG_USER_ONLY)
2812 if (env
->tl
>= env
->maxtl
) {
2813 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
2814 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
2818 if (env
->tl
< env
->maxtl
- 1) {
2821 env
->pstate
|= PS_RED
;
2822 if (env
->tl
< env
->maxtl
)
2825 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2826 env
->tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
2827 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
2829 env
->tsptr
->tpc
= env
->pc
;
2830 env
->tsptr
->tnpc
= env
->npc
;
2831 env
->tsptr
->tt
= intno
;
2832 if (!(env
->def
->features
& CPU_FEATURE_GL
)) {
2835 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
2842 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
2845 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
2849 if (intno
== TT_CLRWIN
)
2850 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
2851 else if ((intno
& 0x1c0) == TT_SPILL
)
2852 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
2853 else if ((intno
& 0x1c0) == TT_FILL
)
2854 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
2855 env
->tbr
&= ~0x7fffULL
;
2856 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
2858 env
->npc
= env
->pc
+ 4;
2859 env
->exception_index
= 0;
2863 static const char * const excp_names
[0x80] = {
2864 [TT_TFAULT
] = "Instruction Access Fault",
2865 [TT_ILL_INSN
] = "Illegal Instruction",
2866 [TT_PRIV_INSN
] = "Privileged Instruction",
2867 [TT_NFPU_INSN
] = "FPU Disabled",
2868 [TT_WIN_OVF
] = "Window Overflow",
2869 [TT_WIN_UNF
] = "Window Underflow",
2870 [TT_UNALIGNED
] = "Unaligned Memory Access",
2871 [TT_FP_EXCP
] = "FPU Exception",
2872 [TT_DFAULT
] = "Data Access Fault",
2873 [TT_TOVF
] = "Tag Overflow",
2874 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2875 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2876 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2877 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2878 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2879 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2880 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2881 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2882 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2883 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2884 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2885 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2886 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2887 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2888 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2889 [TT_TOVF
] = "Tag Overflow",
2890 [TT_CODE_ACCESS
] = "Instruction Access Error",
2891 [TT_DATA_ACCESS
] = "Data Access Error",
2892 [TT_DIV_ZERO
] = "Division By Zero",
2893 [TT_NCP_INSN
] = "Coprocessor Disabled",
2897 void do_interrupt(CPUState
*env
)
2899 int cwp
, intno
= env
->exception_index
;
2902 if (loglevel
& CPU_LOG_INT
) {
2906 if (intno
< 0 || intno
>= 0x100)
2908 else if (intno
>= 0x80)
2909 name
= "Trap Instruction";
2911 name
= excp_names
[intno
];
2916 fprintf(logfile
, "%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
2919 env
->npc
, env
->regwptr
[6]);
2920 cpu_dump_state(env
, logfile
, fprintf
, 0);
2926 fprintf(logfile
, " code=");
2927 ptr
= (uint8_t *)env
->pc
;
2928 for(i
= 0; i
< 16; i
++) {
2929 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
2931 fprintf(logfile
, "\n");
2937 #if !defined(CONFIG_USER_ONLY)
2938 if (env
->psret
== 0) {
2939 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
2940 env
->exception_index
);
2945 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2946 cpu_set_cwp(env
, cwp
);
2947 env
->regwptr
[9] = env
->pc
;
2948 env
->regwptr
[10] = env
->npc
;
2949 env
->psrps
= env
->psrs
;
2951 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
2953 env
->npc
= env
->pc
+ 4;
2954 env
->exception_index
= 0;
2958 #if !defined(CONFIG_USER_ONLY)
2960 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
2963 #define MMUSUFFIX _mmu
2964 #define ALIGNED_ONLY
2967 #include "softmmu_template.h"
2970 #include "softmmu_template.h"
2973 #include "softmmu_template.h"
2976 #include "softmmu_template.h"
2978 /* XXX: make it generic ? */
2979 static void cpu_restore_state2(void *retaddr
)
2981 TranslationBlock
*tb
;
2985 /* now we have a real cpu fault */
2986 pc
= (unsigned long)retaddr
;
2987 tb
= tb_find_pc(pc
);
2989 /* the PC is inside the translated code. It means that we have
2990 a virtual CPU fault */
2991 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
2996 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
2999 #ifdef DEBUG_UNALIGNED
3000 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3001 "\n", addr
, env
->pc
);
3003 cpu_restore_state2(retaddr
);
3004 raise_exception(TT_UNALIGNED
);
3007 /* try to fill the TLB and return an exception if error. If retaddr is
3008 NULL, it means that the function was called in C code (i.e. not
3009 from generated code or from helper.c) */
3010 /* XXX: fix it to restore all registers */
3011 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3014 CPUState
*saved_env
;
3016 /* XXX: hack to restore env in all cases, even if not called from
3019 env
= cpu_single_env
;
3021 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3023 cpu_restore_state2(retaddr
);
3031 #ifndef TARGET_SPARC64
3032 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3033 int is_asi
, int size
)
3035 CPUState
*saved_env
;
3037 /* XXX: hack to restore env in all cases, even if not called from
3040 env
= cpu_single_env
;
3041 #ifdef DEBUG_UNASSIGNED
3043 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3044 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3045 is_exec
? "exec" : is_write
? "write" : "read", size
,
3046 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
3048 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3049 " from " TARGET_FMT_lx
"\n",
3050 is_exec
? "exec" : is_write
? "write" : "read", size
,
3051 size
== 1 ? "" : "s", addr
, env
->pc
);
3053 if (env
->mmuregs
[3]) /* Fault status register */
3054 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
3056 env
->mmuregs
[3] |= 1 << 16;
3058 env
->mmuregs
[3] |= 1 << 5;
3060 env
->mmuregs
[3] |= 1 << 6;
3062 env
->mmuregs
[3] |= 1 << 7;
3063 env
->mmuregs
[3] |= (5 << 2) | 2;
3064 env
->mmuregs
[4] = addr
; /* Fault address register */
3065 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3067 raise_exception(TT_CODE_ACCESS
);
3069 raise_exception(TT_DATA_ACCESS
);
3074 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3075 int is_asi
, int size
)
3077 #ifdef DEBUG_UNASSIGNED
3078 CPUState
*saved_env
;
3080 /* XXX: hack to restore env in all cases, even if not called from
3083 env
= cpu_single_env
;
3084 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3085 "\n", addr
, env
->pc
);
3089 raise_exception(TT_CODE_ACCESS
);
3091 raise_exception(TT_DATA_ACCESS
);
3095 #ifdef TARGET_SPARC64
3096 void helper_tick_set_count(void *opaque
, uint64_t count
)
3098 #if !defined(CONFIG_USER_ONLY)
3099 cpu_tick_set_count(opaque
, count
);
3103 uint64_t helper_tick_get_count(void *opaque
)
3105 #if !defined(CONFIG_USER_ONLY)
3106 return cpu_tick_get_count(opaque
);
3112 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
3114 #if !defined(CONFIG_USER_ONLY)
3115 cpu_tick_set_limit(opaque
, limit
);