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 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
958 int reg
= (addr
>> 8) & 3;
961 case 0: /* Breakpoint Value (Addr) */
962 ret
= env
->mmubpregs
[reg
];
964 case 1: /* Breakpoint Mask */
965 ret
= env
->mmubpregs
[reg
];
967 case 2: /* Breakpoint Control */
968 ret
= env
->mmubpregs
[reg
];
970 case 3: /* Breakpoint Status */
971 ret
= env
->mmubpregs
[reg
];
972 env
->mmubpregs
[reg
] = 0ULL;
975 DPRINTF_MMU("read breakpoint reg[%d] 0x%016llx\n", reg
, ret
);
978 case 8: /* User code access, XXX */
980 do_unassigned_access(addr
, 0, 0, asi
, size
);
1000 dump_asi("read ", last_addr
, asi
, size
, ret
);
1005 void helper_st_asi(target_ulong addr
, uint64_t val
, int asi
, int size
)
1007 helper_check_align(addr
, size
- 1);
1009 case 2: /* SuperSparc MXCC registers */
1011 case 0x01c00000: /* MXCC stream data register 0 */
1013 env
->mxccdata
[0] = val
;
1015 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1018 case 0x01c00008: /* MXCC stream data register 1 */
1020 env
->mxccdata
[1] = val
;
1022 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1025 case 0x01c00010: /* MXCC stream data register 2 */
1027 env
->mxccdata
[2] = val
;
1029 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1032 case 0x01c00018: /* MXCC stream data register 3 */
1034 env
->mxccdata
[3] = val
;
1036 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1039 case 0x01c00100: /* MXCC stream source */
1041 env
->mxccregs
[0] = val
;
1043 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1045 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1047 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1049 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1051 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
1054 case 0x01c00200: /* MXCC stream destination */
1056 env
->mxccregs
[1] = val
;
1058 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1060 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
1062 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
1064 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
1066 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
1069 case 0x01c00a00: /* MXCC control register */
1071 env
->mxccregs
[3] = val
;
1073 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1076 case 0x01c00a04: /* MXCC control register */
1078 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
1081 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1084 case 0x01c00e00: /* MXCC error register */
1085 // writing a 1 bit clears the error
1087 env
->mxccregs
[6] &= ~val
;
1089 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1092 case 0x01c00f00: /* MBus port address register */
1094 env
->mxccregs
[7] = val
;
1096 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
1100 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
1104 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
1105 asi
, size
, addr
, val
);
1110 case 3: /* MMU flush */
1114 mmulev
= (addr
>> 8) & 15;
1115 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
1117 case 0: // flush page
1118 tlb_flush_page(env
, addr
& 0xfffff000);
1120 case 1: // flush segment (256k)
1121 case 2: // flush region (16M)
1122 case 3: // flush context (4G)
1123 case 4: // flush entire
1134 case 4: /* write MMU regs */
1136 int reg
= (addr
>> 8) & 0x1f;
1139 oldreg
= env
->mmuregs
[reg
];
1141 case 0: // Control Register
1142 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1144 // Mappings generated during no-fault mode or MMU
1145 // disabled mode are invalid in normal mode
1146 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
1147 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)))
1150 case 1: // Context Table Pointer Register
1151 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
1153 case 2: // Context Register
1154 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
1155 if (oldreg
!= env
->mmuregs
[reg
]) {
1156 /* we flush when the MMU context changes because
1157 QEMU has no MMU context support */
1161 case 3: // Synchronous Fault Status Register with Clear
1162 case 4: // Synchronous Fault Address Register
1164 case 0x10: // TLB Replacement Control Register
1165 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
1167 case 0x13: // Synchronous Fault Status Register with Read and Clear
1168 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
1170 case 0x14: // Synchronous Fault Address Register
1171 env
->mmuregs
[4] = val
;
1174 env
->mmuregs
[reg
] = val
;
1177 if (oldreg
!= env
->mmuregs
[reg
]) {
1178 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1179 reg
, oldreg
, env
->mmuregs
[reg
]);
1186 case 5: // Turbosparc ITLB Diagnostic
1187 case 6: // Turbosparc DTLB Diagnostic
1188 case 7: // Turbosparc IOTLB Diagnostic
1190 case 0xa: /* User data access */
1193 stb_user(addr
, val
);
1196 stw_user(addr
, val
);
1200 stl_user(addr
, val
);
1203 stq_user(addr
, val
);
1207 case 0xb: /* Supervisor data access */
1210 stb_kernel(addr
, val
);
1213 stw_kernel(addr
, val
);
1217 stl_kernel(addr
, val
);
1220 stq_kernel(addr
, val
);
1224 case 0xc: /* I-cache tag */
1225 case 0xd: /* I-cache data */
1226 case 0xe: /* D-cache tag */
1227 case 0xf: /* D-cache data */
1228 case 0x10: /* I/D-cache flush page */
1229 case 0x11: /* I/D-cache flush segment */
1230 case 0x12: /* I/D-cache flush region */
1231 case 0x13: /* I/D-cache flush context */
1232 case 0x14: /* I/D-cache flush user */
1234 case 0x17: /* Block copy, sta access */
1240 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
1242 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
1243 temp
= ldl_kernel(src
);
1244 stl_kernel(dst
, temp
);
1248 case 0x1f: /* Block fill, stda access */
1251 // fill 32 bytes with val
1253 uint32_t dst
= addr
& 7;
1255 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
1256 stq_kernel(dst
, val
);
1259 case 0x20: /* MMU passthrough */
1263 stb_phys(addr
, val
);
1266 stw_phys(addr
, val
);
1270 stl_phys(addr
, val
);
1273 stq_phys(addr
, val
);
1278 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1282 stb_phys((target_phys_addr_t
)addr
1283 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1286 stw_phys((target_phys_addr_t
)addr
1287 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1291 stl_phys((target_phys_addr_t
)addr
1292 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1295 stq_phys((target_phys_addr_t
)addr
1296 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1301 case 0x30: // store buffer tags or Turbosparc secondary cache diagnostic
1302 case 0x31: // store buffer data, Ross RT620 I-cache flush or
1303 // Turbosparc snoop RAM
1304 case 0x32: // store buffer control or Turbosparc page table
1305 // descriptor diagnostic
1306 case 0x36: /* I-cache flash clear */
1307 case 0x37: /* D-cache flash clear */
1308 case 0x4c: /* breakpoint action */
1310 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1312 int reg
= (addr
>> 8) & 3;
1315 case 0: /* Breakpoint Value (Addr) */
1316 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1318 case 1: /* Breakpoint Mask */
1319 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1321 case 2: /* Breakpoint Control */
1322 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1324 case 3: /* Breakpoint Status */
1325 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1328 DPRINTF_MMU("write breakpoint reg[%d] 0x%016llx\n", reg
,
1332 case 8: /* User code access, XXX */
1333 case 9: /* Supervisor code access, XXX */
1335 do_unassigned_access(addr
, 1, 0, asi
, size
);
1339 dump_asi("write", addr
, asi
, size
, val
);
1343 #endif /* CONFIG_USER_ONLY */
1344 #else /* TARGET_SPARC64 */
1346 #ifdef CONFIG_USER_ONLY
1347 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1350 #if defined(DEBUG_ASI)
1351 target_ulong last_addr
= addr
;
1355 raise_exception(TT_PRIV_ACT
);
1357 helper_check_align(addr
, size
- 1);
1358 address_mask(env
, &addr
);
1361 case 0x82: // Primary no-fault
1362 case 0x8a: // Primary no-fault LE
1363 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1365 dump_asi("read ", last_addr
, asi
, size
, ret
);
1370 case 0x80: // Primary
1371 case 0x88: // Primary LE
1375 ret
= ldub_raw(addr
);
1378 ret
= lduw_raw(addr
);
1381 ret
= ldl_raw(addr
);
1385 ret
= ldq_raw(addr
);
1390 case 0x83: // Secondary no-fault
1391 case 0x8b: // Secondary no-fault LE
1392 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1394 dump_asi("read ", last_addr
, asi
, size
, ret
);
1399 case 0x81: // Secondary
1400 case 0x89: // Secondary LE
1407 /* Convert from little endian */
1409 case 0x88: // Primary LE
1410 case 0x89: // Secondary LE
1411 case 0x8a: // Primary no-fault LE
1412 case 0x8b: // Secondary no-fault LE
1430 /* Convert to signed number */
1437 ret
= (int16_t) ret
;
1440 ret
= (int32_t) ret
;
1447 dump_asi("read ", last_addr
, asi
, size
, ret
);
1452 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1455 dump_asi("write", addr
, asi
, size
, val
);
1458 raise_exception(TT_PRIV_ACT
);
1460 helper_check_align(addr
, size
- 1);
1461 address_mask(env
, &addr
);
1463 /* Convert to little endian */
1465 case 0x88: // Primary LE
1466 case 0x89: // Secondary LE
1469 addr
= bswap16(addr
);
1472 addr
= bswap32(addr
);
1475 addr
= bswap64(addr
);
1485 case 0x80: // Primary
1486 case 0x88: // Primary LE
1505 case 0x81: // Secondary
1506 case 0x89: // Secondary LE
1510 case 0x82: // Primary no-fault, RO
1511 case 0x83: // Secondary no-fault, RO
1512 case 0x8a: // Primary no-fault LE, RO
1513 case 0x8b: // Secondary no-fault LE, RO
1515 do_unassigned_access(addr
, 1, 0, 1, size
);
1520 #else /* CONFIG_USER_ONLY */
1522 uint64_t helper_ld_asi(target_ulong addr
, int asi
, int size
, int sign
)
1525 #if defined(DEBUG_ASI)
1526 target_ulong last_addr
= addr
;
1529 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1530 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1531 && asi
>= 0x30 && asi
< 0x80
1532 && !(env
->hpstate
& HS_PRIV
)))
1533 raise_exception(TT_PRIV_ACT
);
1535 helper_check_align(addr
, size
- 1);
1537 case 0x82: // Primary no-fault
1538 case 0x8a: // Primary no-fault LE
1539 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
1541 dump_asi("read ", last_addr
, asi
, size
, ret
);
1546 case 0x10: // As if user primary
1547 case 0x18: // As if user primary LE
1548 case 0x80: // Primary
1549 case 0x88: // Primary LE
1550 case 0xe2: // UA2007 Primary block init
1551 case 0xe3: // UA2007 Secondary block init
1552 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1553 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1554 && env
->hpstate
& HS_PRIV
) {
1557 ret
= ldub_hypv(addr
);
1560 ret
= lduw_hypv(addr
);
1563 ret
= ldl_hypv(addr
);
1567 ret
= ldq_hypv(addr
);
1573 ret
= ldub_kernel(addr
);
1576 ret
= lduw_kernel(addr
);
1579 ret
= ldl_kernel(addr
);
1583 ret
= ldq_kernel(addr
);
1590 ret
= ldub_user(addr
);
1593 ret
= lduw_user(addr
);
1596 ret
= ldl_user(addr
);
1600 ret
= ldq_user(addr
);
1605 case 0x14: // Bypass
1606 case 0x15: // Bypass, non-cacheable
1607 case 0x1c: // Bypass LE
1608 case 0x1d: // Bypass, non-cacheable LE
1612 ret
= ldub_phys(addr
);
1615 ret
= lduw_phys(addr
);
1618 ret
= ldl_phys(addr
);
1622 ret
= ldq_phys(addr
);
1627 case 0x24: // Nucleus quad LDD 128 bit atomic
1628 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1629 // Only ldda allowed
1630 raise_exception(TT_ILL_INSN
);
1632 case 0x83: // Secondary no-fault
1633 case 0x8b: // Secondary no-fault LE
1634 if (cpu_get_phys_page_debug(env
, addr
) == -1ULL) {
1636 dump_asi("read ", last_addr
, asi
, size
, ret
);
1641 case 0x04: // Nucleus
1642 case 0x0c: // Nucleus Little Endian (LE)
1643 case 0x11: // As if user secondary
1644 case 0x19: // As if user secondary LE
1645 case 0x4a: // UPA config
1646 case 0x81: // Secondary
1647 case 0x89: // Secondary LE
1653 case 0x50: // I-MMU regs
1655 int reg
= (addr
>> 3) & 0xf;
1657 ret
= env
->immuregs
[reg
];
1660 case 0x51: // I-MMU 8k TSB pointer
1661 case 0x52: // I-MMU 64k TSB pointer
1664 case 0x55: // I-MMU data access
1666 int reg
= (addr
>> 3) & 0x3f;
1668 ret
= env
->itlb_tte
[reg
];
1671 case 0x56: // I-MMU tag read
1673 int reg
= (addr
>> 3) & 0x3f;
1675 ret
= env
->itlb_tag
[reg
];
1678 case 0x58: // D-MMU regs
1680 int reg
= (addr
>> 3) & 0xf;
1682 ret
= env
->dmmuregs
[reg
];
1685 case 0x5d: // D-MMU data access
1687 int reg
= (addr
>> 3) & 0x3f;
1689 ret
= env
->dtlb_tte
[reg
];
1692 case 0x5e: // D-MMU tag read
1694 int reg
= (addr
>> 3) & 0x3f;
1696 ret
= env
->dtlb_tag
[reg
];
1699 case 0x46: // D-cache data
1700 case 0x47: // D-cache tag access
1701 case 0x4b: // E-cache error enable
1702 case 0x4c: // E-cache asynchronous fault status
1703 case 0x4d: // E-cache asynchronous fault address
1704 case 0x4e: // E-cache tag data
1705 case 0x66: // I-cache instruction access
1706 case 0x67: // I-cache tag access
1707 case 0x6e: // I-cache predecode
1708 case 0x6f: // I-cache LRU etc.
1709 case 0x76: // E-cache tag
1710 case 0x7e: // E-cache tag
1712 case 0x59: // D-MMU 8k TSB pointer
1713 case 0x5a: // D-MMU 64k TSB pointer
1714 case 0x5b: // D-MMU data pointer
1715 case 0x48: // Interrupt dispatch, RO
1716 case 0x49: // Interrupt data receive
1717 case 0x7f: // Incoming interrupt vector, RO
1720 case 0x54: // I-MMU data in, WO
1721 case 0x57: // I-MMU demap, WO
1722 case 0x5c: // D-MMU data in, WO
1723 case 0x5f: // D-MMU demap, WO
1724 case 0x77: // Interrupt vector, WO
1726 do_unassigned_access(addr
, 0, 0, 1, size
);
1731 /* Convert from little endian */
1733 case 0x0c: // Nucleus Little Endian (LE)
1734 case 0x18: // As if user primary LE
1735 case 0x19: // As if user secondary LE
1736 case 0x1c: // Bypass LE
1737 case 0x1d: // Bypass, non-cacheable LE
1738 case 0x88: // Primary LE
1739 case 0x89: // Secondary LE
1740 case 0x8a: // Primary no-fault LE
1741 case 0x8b: // Secondary no-fault LE
1759 /* Convert to signed number */
1766 ret
= (int16_t) ret
;
1769 ret
= (int32_t) ret
;
1776 dump_asi("read ", last_addr
, asi
, size
, ret
);
1781 void helper_st_asi(target_ulong addr
, target_ulong val
, int asi
, int size
)
1784 dump_asi("write", addr
, asi
, size
, val
);
1786 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1787 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
1788 && asi
>= 0x30 && asi
< 0x80
1789 && !(env
->hpstate
& HS_PRIV
)))
1790 raise_exception(TT_PRIV_ACT
);
1792 helper_check_align(addr
, size
- 1);
1793 /* Convert to little endian */
1795 case 0x0c: // Nucleus Little Endian (LE)
1796 case 0x18: // As if user primary LE
1797 case 0x19: // As if user secondary LE
1798 case 0x1c: // Bypass LE
1799 case 0x1d: // Bypass, non-cacheable LE
1800 case 0x88: // Primary LE
1801 case 0x89: // Secondary LE
1804 addr
= bswap16(addr
);
1807 addr
= bswap32(addr
);
1810 addr
= bswap64(addr
);
1820 case 0x10: // As if user primary
1821 case 0x18: // As if user primary LE
1822 case 0x80: // Primary
1823 case 0x88: // Primary LE
1824 case 0xe2: // UA2007 Primary block init
1825 case 0xe3: // UA2007 Secondary block init
1826 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1827 if ((env
->def
->features
& CPU_FEATURE_HYPV
)
1828 && env
->hpstate
& HS_PRIV
) {
1831 stb_hypv(addr
, val
);
1834 stw_hypv(addr
, val
);
1837 stl_hypv(addr
, val
);
1841 stq_hypv(addr
, val
);
1847 stb_kernel(addr
, val
);
1850 stw_kernel(addr
, val
);
1853 stl_kernel(addr
, val
);
1857 stq_kernel(addr
, val
);
1864 stb_user(addr
, val
);
1867 stw_user(addr
, val
);
1870 stl_user(addr
, val
);
1874 stq_user(addr
, val
);
1879 case 0x14: // Bypass
1880 case 0x15: // Bypass, non-cacheable
1881 case 0x1c: // Bypass LE
1882 case 0x1d: // Bypass, non-cacheable LE
1886 stb_phys(addr
, val
);
1889 stw_phys(addr
, val
);
1892 stl_phys(addr
, val
);
1896 stq_phys(addr
, val
);
1901 case 0x24: // Nucleus quad LDD 128 bit atomic
1902 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
1903 // Only ldda allowed
1904 raise_exception(TT_ILL_INSN
);
1906 case 0x04: // Nucleus
1907 case 0x0c: // Nucleus Little Endian (LE)
1908 case 0x11: // As if user secondary
1909 case 0x19: // As if user secondary LE
1910 case 0x4a: // UPA config
1911 case 0x81: // Secondary
1912 case 0x89: // Secondary LE
1920 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1921 // Mappings generated during D/I MMU disabled mode are
1922 // invalid in normal mode
1923 if (oldreg
!= env
->lsu
) {
1924 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1933 case 0x50: // I-MMU regs
1935 int reg
= (addr
>> 3) & 0xf;
1938 oldreg
= env
->immuregs
[reg
];
1943 case 1: // Not in I-MMU
1950 val
= 0; // Clear SFSR
1952 case 5: // TSB access
1953 case 6: // Tag access
1957 env
->immuregs
[reg
] = val
;
1958 if (oldreg
!= env
->immuregs
[reg
]) {
1959 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
1960 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1967 case 0x54: // I-MMU data in
1971 // Try finding an invalid entry
1972 for (i
= 0; i
< 64; i
++) {
1973 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
1974 env
->itlb_tag
[i
] = env
->immuregs
[6];
1975 env
->itlb_tte
[i
] = val
;
1979 // Try finding an unlocked entry
1980 for (i
= 0; i
< 64; i
++) {
1981 if ((env
->itlb_tte
[i
] & 0x40) == 0) {
1982 env
->itlb_tag
[i
] = env
->immuregs
[6];
1983 env
->itlb_tte
[i
] = val
;
1990 case 0x55: // I-MMU data access
1994 unsigned int i
= (addr
>> 3) & 0x3f;
1996 env
->itlb_tag
[i
] = env
->immuregs
[6];
1997 env
->itlb_tte
[i
] = val
;
2000 case 0x57: // I-MMU demap
2004 for (i
= 0; i
< 64; i
++) {
2005 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
2006 target_ulong mask
= 0xffffffffffffe000ULL
;
2008 mask
<<= 3 * ((env
->itlb_tte
[i
] >> 61) & 3);
2009 if ((val
& mask
) == (env
->itlb_tag
[i
] & mask
)) {
2010 env
->itlb_tag
[i
] = 0;
2011 env
->itlb_tte
[i
] = 0;
2018 case 0x58: // D-MMU regs
2020 int reg
= (addr
>> 3) & 0xf;
2023 oldreg
= env
->dmmuregs
[reg
];
2029 if ((val
& 1) == 0) {
2030 val
= 0; // Clear SFSR, Fault address
2031 env
->dmmuregs
[4] = 0;
2033 env
->dmmuregs
[reg
] = val
;
2035 case 1: // Primary context
2036 case 2: // Secondary context
2037 case 5: // TSB access
2038 case 6: // Tag access
2039 case 7: // Virtual Watchpoint
2040 case 8: // Physical Watchpoint
2044 env
->dmmuregs
[reg
] = val
;
2045 if (oldreg
!= env
->dmmuregs
[reg
]) {
2046 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08"
2047 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
2054 case 0x5c: // D-MMU data in
2058 // Try finding an invalid entry
2059 for (i
= 0; i
< 64; i
++) {
2060 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
2061 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2062 env
->dtlb_tte
[i
] = val
;
2066 // Try finding an unlocked entry
2067 for (i
= 0; i
< 64; i
++) {
2068 if ((env
->dtlb_tte
[i
] & 0x40) == 0) {
2069 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2070 env
->dtlb_tte
[i
] = val
;
2077 case 0x5d: // D-MMU data access
2079 unsigned int i
= (addr
>> 3) & 0x3f;
2081 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
2082 env
->dtlb_tte
[i
] = val
;
2085 case 0x5f: // D-MMU demap
2089 for (i
= 0; i
< 64; i
++) {
2090 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
2091 target_ulong mask
= 0xffffffffffffe000ULL
;
2093 mask
<<= 3 * ((env
->dtlb_tte
[i
] >> 61) & 3);
2094 if ((val
& mask
) == (env
->dtlb_tag
[i
] & mask
)) {
2095 env
->dtlb_tag
[i
] = 0;
2096 env
->dtlb_tte
[i
] = 0;
2103 case 0x49: // Interrupt data receive
2106 case 0x46: // D-cache data
2107 case 0x47: // D-cache tag access
2108 case 0x4b: // E-cache error enable
2109 case 0x4c: // E-cache asynchronous fault status
2110 case 0x4d: // E-cache asynchronous fault address
2111 case 0x4e: // E-cache tag data
2112 case 0x66: // I-cache instruction access
2113 case 0x67: // I-cache tag access
2114 case 0x6e: // I-cache predecode
2115 case 0x6f: // I-cache LRU etc.
2116 case 0x76: // E-cache tag
2117 case 0x7e: // E-cache tag
2119 case 0x51: // I-MMU 8k TSB pointer, RO
2120 case 0x52: // I-MMU 64k TSB pointer, RO
2121 case 0x56: // I-MMU tag read, RO
2122 case 0x59: // D-MMU 8k TSB pointer, RO
2123 case 0x5a: // D-MMU 64k TSB pointer, RO
2124 case 0x5b: // D-MMU data pointer, RO
2125 case 0x5e: // D-MMU tag read, RO
2126 case 0x48: // Interrupt dispatch, RO
2127 case 0x7f: // Incoming interrupt vector, RO
2128 case 0x82: // Primary no-fault, RO
2129 case 0x83: // Secondary no-fault, RO
2130 case 0x8a: // Primary no-fault LE, RO
2131 case 0x8b: // Secondary no-fault LE, RO
2133 do_unassigned_access(addr
, 1, 0, 1, size
);
2137 #endif /* CONFIG_USER_ONLY */
2139 void helper_ldda_asi(target_ulong addr
, int asi
, int rd
)
2141 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2142 || ((env
->def
->features
& CPU_FEATURE_HYPV
)
2143 && asi
>= 0x30 && asi
< 0x80
2144 && !(env
->hpstate
& HS_PRIV
)))
2145 raise_exception(TT_PRIV_ACT
);
2148 case 0x24: // Nucleus quad LDD 128 bit atomic
2149 case 0x2c: // Nucleus quad LDD 128 bit atomic LE
2150 helper_check_align(addr
, 0xf);
2152 env
->gregs
[1] = ldq_kernel(addr
+ 8);
2154 bswap64s(&env
->gregs
[1]);
2155 } else if (rd
< 8) {
2156 env
->gregs
[rd
] = ldq_kernel(addr
);
2157 env
->gregs
[rd
+ 1] = ldq_kernel(addr
+ 8);
2159 bswap64s(&env
->gregs
[rd
]);
2160 bswap64s(&env
->gregs
[rd
+ 1]);
2163 env
->regwptr
[rd
] = ldq_kernel(addr
);
2164 env
->regwptr
[rd
+ 1] = ldq_kernel(addr
+ 8);
2166 bswap64s(&env
->regwptr
[rd
]);
2167 bswap64s(&env
->regwptr
[rd
+ 1]);
2172 helper_check_align(addr
, 0x3);
2174 env
->gregs
[1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2176 env
->gregs
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2177 env
->gregs
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2179 env
->regwptr
[rd
] = helper_ld_asi(addr
, asi
, 4, 0);
2180 env
->regwptr
[rd
+ 1] = helper_ld_asi(addr
+ 4, asi
, 4, 0);
2186 void helper_ldf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2191 helper_check_align(addr
, 3);
2193 case 0xf0: // Block load primary
2194 case 0xf1: // Block load secondary
2195 case 0xf8: // Block load primary LE
2196 case 0xf9: // Block load secondary LE
2198 raise_exception(TT_ILL_INSN
);
2201 helper_check_align(addr
, 0x3f);
2202 for (i
= 0; i
< 16; i
++) {
2203 *(uint32_t *)&env
->fpr
[rd
++] = helper_ld_asi(addr
, asi
& 0x8f, 4,
2213 val
= helper_ld_asi(addr
, asi
, size
, 0);
2217 *((uint32_t *)&env
->fpr
[rd
]) = val
;
2220 *((int64_t *)&DT0
) = val
;
2228 void helper_stf_asi(target_ulong addr
, int asi
, int size
, int rd
)
2231 target_ulong val
= 0;
2233 helper_check_align(addr
, 3);
2235 case 0xe0: // UA2007 Block commit store primary (cache flush)
2236 case 0xe1: // UA2007 Block commit store secondary (cache flush)
2237 case 0xf0: // Block store primary
2238 case 0xf1: // Block store secondary
2239 case 0xf8: // Block store primary LE
2240 case 0xf9: // Block store secondary LE
2242 raise_exception(TT_ILL_INSN
);
2245 helper_check_align(addr
, 0x3f);
2246 for (i
= 0; i
< 16; i
++) {
2247 val
= *(uint32_t *)&env
->fpr
[rd
++];
2248 helper_st_asi(addr
, val
, asi
& 0x8f, 4);
2260 val
= *((uint32_t *)&env
->fpr
[rd
]);
2263 val
= *((int64_t *)&DT0
);
2269 helper_st_asi(addr
, val
, asi
, size
);
2272 target_ulong
helper_cas_asi(target_ulong addr
, target_ulong val1
,
2273 target_ulong val2
, uint32_t asi
)
2277 val2
&= 0xffffffffUL
;
2278 ret
= helper_ld_asi(addr
, asi
, 4, 0);
2279 ret
&= 0xffffffffUL
;
2281 helper_st_asi(addr
, val1
& 0xffffffffUL
, asi
, 4);
2285 target_ulong
helper_casx_asi(target_ulong addr
, target_ulong val1
,
2286 target_ulong val2
, uint32_t asi
)
2290 ret
= helper_ld_asi(addr
, asi
, 8, 0);
2292 helper_st_asi(addr
, val1
, asi
, 8);
2295 #endif /* TARGET_SPARC64 */
2297 #ifndef TARGET_SPARC64
2298 void helper_rett(void)
2302 if (env
->psret
== 1)
2303 raise_exception(TT_ILL_INSN
);
2306 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
2307 if (env
->wim
& (1 << cwp
)) {
2308 raise_exception(TT_WIN_UNF
);
2311 env
->psrs
= env
->psrps
;
2315 target_ulong
helper_udiv(target_ulong a
, target_ulong b
)
2320 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2324 raise_exception(TT_DIV_ZERO
);
2328 if (x0
> 0xffffffff) {
2337 target_ulong
helper_sdiv(target_ulong a
, target_ulong b
)
2342 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
2346 raise_exception(TT_DIV_ZERO
);
2350 if ((int32_t) x0
!= x0
) {
2352 return x0
< 0? 0x80000000: 0x7fffffff;
2359 void helper_stdf(target_ulong addr
, int mem_idx
)
2361 helper_check_align(addr
, 7);
2362 #if !defined(CONFIG_USER_ONLY)
2365 stfq_user(addr
, DT0
);
2368 stfq_kernel(addr
, DT0
);
2370 #ifdef TARGET_SPARC64
2372 stfq_hypv(addr
, DT0
);
2379 address_mask(env
, &addr
);
2380 stfq_raw(addr
, DT0
);
2384 void helper_lddf(target_ulong addr
, int mem_idx
)
2386 helper_check_align(addr
, 7);
2387 #if !defined(CONFIG_USER_ONLY)
2390 DT0
= ldfq_user(addr
);
2393 DT0
= ldfq_kernel(addr
);
2395 #ifdef TARGET_SPARC64
2397 DT0
= ldfq_hypv(addr
);
2404 address_mask(env
, &addr
);
2405 DT0
= ldfq_raw(addr
);
2409 void helper_ldqf(target_ulong addr
, int mem_idx
)
2411 // XXX add 128 bit load
2414 helper_check_align(addr
, 7);
2415 #if !defined(CONFIG_USER_ONLY)
2418 u
.ll
.upper
= ldq_user(addr
);
2419 u
.ll
.lower
= ldq_user(addr
+ 8);
2423 u
.ll
.upper
= ldq_kernel(addr
);
2424 u
.ll
.lower
= ldq_kernel(addr
+ 8);
2427 #ifdef TARGET_SPARC64
2429 u
.ll
.upper
= ldq_hypv(addr
);
2430 u
.ll
.lower
= ldq_hypv(addr
+ 8);
2438 address_mask(env
, &addr
);
2439 u
.ll
.upper
= ldq_raw(addr
);
2440 u
.ll
.lower
= ldq_raw((addr
+ 8) & 0xffffffffULL
);
2445 void helper_stqf(target_ulong addr
, int mem_idx
)
2447 // XXX add 128 bit store
2450 helper_check_align(addr
, 7);
2451 #if !defined(CONFIG_USER_ONLY)
2455 stq_user(addr
, u
.ll
.upper
);
2456 stq_user(addr
+ 8, u
.ll
.lower
);
2460 stq_kernel(addr
, u
.ll
.upper
);
2461 stq_kernel(addr
+ 8, u
.ll
.lower
);
2463 #ifdef TARGET_SPARC64
2466 stq_hypv(addr
, u
.ll
.upper
);
2467 stq_hypv(addr
+ 8, u
.ll
.lower
);
2475 address_mask(env
, &addr
);
2476 stq_raw(addr
, u
.ll
.upper
);
2477 stq_raw((addr
+ 8) & 0xffffffffULL
, u
.ll
.lower
);
2481 static inline void set_fsr(void)
2485 switch (env
->fsr
& FSR_RD_MASK
) {
2486 case FSR_RD_NEAREST
:
2487 rnd_mode
= float_round_nearest_even
;
2491 rnd_mode
= float_round_to_zero
;
2494 rnd_mode
= float_round_up
;
2497 rnd_mode
= float_round_down
;
2500 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
2503 void helper_ldfsr(uint32_t new_fsr
)
2505 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
2509 #ifdef TARGET_SPARC64
2510 void helper_ldxfsr(uint64_t new_fsr
)
2512 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);
2517 void helper_debug(void)
2519 env
->exception_index
= EXCP_DEBUG
;
2523 #ifndef TARGET_SPARC64
2524 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2526 void helper_save(void)
2530 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2531 if (env
->wim
& (1 << cwp
)) {
2532 raise_exception(TT_WIN_OVF
);
2537 void helper_restore(void)
2541 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2542 if (env
->wim
& (1 << cwp
)) {
2543 raise_exception(TT_WIN_UNF
);
2548 void helper_wrpsr(target_ulong new_psr
)
2550 if ((new_psr
& PSR_CWP
) >= env
->nwindows
)
2551 raise_exception(TT_ILL_INSN
);
2553 PUT_PSR(env
, new_psr
);
2556 target_ulong
helper_rdpsr(void)
2558 return GET_PSR(env
);
2562 /* XXX: use another pointer for %iN registers to avoid slow wrapping
2564 void helper_save(void)
2568 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2569 if (env
->cansave
== 0) {
2570 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2571 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2572 ((env
->wstate
& 0x7) << 2)));
2574 if (env
->cleanwin
- env
->canrestore
== 0) {
2575 // XXX Clean windows without trap
2576 raise_exception(TT_CLRWIN
);
2585 void helper_restore(void)
2589 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
2590 if (env
->canrestore
== 0) {
2591 raise_exception(TT_FILL
| (env
->otherwin
!= 0 ?
2592 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2593 ((env
->wstate
& 0x7) << 2)));
2601 void helper_flushw(void)
2603 if (env
->cansave
!= env
->nwindows
- 2) {
2604 raise_exception(TT_SPILL
| (env
->otherwin
!= 0 ?
2605 (TT_WOTHER
| ((env
->wstate
& 0x38) >> 1)):
2606 ((env
->wstate
& 0x7) << 2)));
2610 void helper_saved(void)
2613 if (env
->otherwin
== 0)
2619 void helper_restored(void)
2622 if (env
->cleanwin
< env
->nwindows
- 1)
2624 if (env
->otherwin
== 0)
2630 target_ulong
helper_rdccr(void)
2632 return GET_CCR(env
);
2635 void helper_wrccr(target_ulong new_ccr
)
2637 PUT_CCR(env
, new_ccr
);
2640 // CWP handling is reversed in V9, but we still use the V8 register
2642 target_ulong
helper_rdcwp(void)
2644 return GET_CWP64(env
);
2647 void helper_wrcwp(target_ulong new_cwp
)
2649 PUT_CWP64(env
, new_cwp
);
2652 // This function uses non-native bit order
2653 #define GET_FIELD(X, FROM, TO) \
2654 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
2656 // This function uses the order in the manuals, i.e. bit 0 is 2^0
2657 #define GET_FIELD_SP(X, FROM, TO) \
2658 GET_FIELD(X, 63 - (TO), 63 - (FROM))
2660 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
2662 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
2663 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
2664 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
2665 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
2666 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
2667 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
2668 (((pixel_addr
>> 55) & 1) << 4) |
2669 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
2670 GET_FIELD_SP(pixel_addr
, 11, 12);
2673 target_ulong
helper_alignaddr(target_ulong addr
, target_ulong offset
)
2677 tmp
= addr
+ offset
;
2679 env
->gsr
|= tmp
& 7ULL;
2683 target_ulong
helper_popc(target_ulong val
)
2685 return ctpop64(val
);
2688 static inline uint64_t *get_gregset(uint64_t pstate
)
2703 static inline void change_pstate(uint64_t new_pstate
)
2705 uint64_t pstate_regs
, new_pstate_regs
;
2706 uint64_t *src
, *dst
;
2708 pstate_regs
= env
->pstate
& 0xc01;
2709 new_pstate_regs
= new_pstate
& 0xc01;
2710 if (new_pstate_regs
!= pstate_regs
) {
2711 // Switch global register bank
2712 src
= get_gregset(new_pstate_regs
);
2713 dst
= get_gregset(pstate_regs
);
2714 memcpy32(dst
, env
->gregs
);
2715 memcpy32(env
->gregs
, src
);
2717 env
->pstate
= new_pstate
;
2720 void helper_wrpstate(target_ulong new_state
)
2722 if (!(env
->def
->features
& CPU_FEATURE_GL
))
2723 change_pstate(new_state
& 0xf3f);
2726 void helper_done(void)
2728 env
->pc
= env
->tsptr
->tpc
;
2729 env
->npc
= env
->tsptr
->tnpc
+ 4;
2730 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2731 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2732 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2733 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2735 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2738 void helper_retry(void)
2740 env
->pc
= env
->tsptr
->tpc
;
2741 env
->npc
= env
->tsptr
->tnpc
;
2742 PUT_CCR(env
, env
->tsptr
->tstate
>> 32);
2743 env
->asi
= (env
->tsptr
->tstate
>> 24) & 0xff;
2744 change_pstate((env
->tsptr
->tstate
>> 8) & 0xf3f);
2745 PUT_CWP64(env
, env
->tsptr
->tstate
& 0xff);
2747 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2750 void helper_set_softint(uint64_t value
)
2752 env
->softint
|= (uint32_t)value
;
2755 void helper_clear_softint(uint64_t value
)
2757 env
->softint
&= (uint32_t)~value
;
2760 void helper_write_softint(uint64_t value
)
2762 env
->softint
= (uint32_t)value
;
2766 void helper_flush(target_ulong addr
)
2769 tb_invalidate_page_range(addr
, addr
+ 8);
2772 #ifdef TARGET_SPARC64
2774 static const char * const excp_names
[0x80] = {
2775 [TT_TFAULT
] = "Instruction Access Fault",
2776 [TT_TMISS
] = "Instruction Access MMU Miss",
2777 [TT_CODE_ACCESS
] = "Instruction Access Error",
2778 [TT_ILL_INSN
] = "Illegal Instruction",
2779 [TT_PRIV_INSN
] = "Privileged Instruction",
2780 [TT_NFPU_INSN
] = "FPU Disabled",
2781 [TT_FP_EXCP
] = "FPU Exception",
2782 [TT_TOVF
] = "Tag Overflow",
2783 [TT_CLRWIN
] = "Clean Windows",
2784 [TT_DIV_ZERO
] = "Division By Zero",
2785 [TT_DFAULT
] = "Data Access Fault",
2786 [TT_DMISS
] = "Data Access MMU Miss",
2787 [TT_DATA_ACCESS
] = "Data Access Error",
2788 [TT_DPROT
] = "Data Protection Error",
2789 [TT_UNALIGNED
] = "Unaligned Memory Access",
2790 [TT_PRIV_ACT
] = "Privileged Action",
2791 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2792 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2793 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2794 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2795 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2796 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2797 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2798 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2799 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2800 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2801 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2802 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2803 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2804 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2805 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2809 void do_interrupt(CPUState
*env
)
2811 int intno
= env
->exception_index
;
2814 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
2818 if (intno
< 0 || intno
>= 0x180)
2820 else if (intno
>= 0x100)
2821 name
= "Trap Instruction";
2822 else if (intno
>= 0xc0)
2823 name
= "Window Fill";
2824 else if (intno
>= 0x80)
2825 name
= "Window Spill";
2827 name
= excp_names
[intno
];
2832 qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64
" npc=%016" PRIx64
2833 " SP=%016" PRIx64
"\n",
2836 env
->npc
, env
->regwptr
[6]);
2837 log_cpu_state(env
, 0);
2844 ptr
= (uint8_t *)env
->pc
;
2845 for(i
= 0; i
< 16; i
++) {
2846 qemu_log(" %02x", ldub(ptr
+ i
));
2854 #if !defined(CONFIG_USER_ONLY)
2855 if (env
->tl
>= env
->maxtl
) {
2856 cpu_abort(env
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
2857 " Error state", env
->exception_index
, env
->tl
, env
->maxtl
);
2861 if (env
->tl
< env
->maxtl
- 1) {
2864 env
->pstate
|= PS_RED
;
2865 if (env
->tl
< env
->maxtl
)
2868 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
2869 env
->tsptr
->tstate
= ((uint64_t)GET_CCR(env
) << 32) |
2870 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
2872 env
->tsptr
->tpc
= env
->pc
;
2873 env
->tsptr
->tnpc
= env
->npc
;
2874 env
->tsptr
->tt
= intno
;
2875 if (!(env
->def
->features
& CPU_FEATURE_GL
)) {
2878 change_pstate(PS_PEF
| PS_PRIV
| PS_IG
);
2885 change_pstate(PS_PEF
| PS_PRIV
| PS_MG
);
2888 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
2892 if (intno
== TT_CLRWIN
)
2893 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
2894 else if ((intno
& 0x1c0) == TT_SPILL
)
2895 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
2896 else if ((intno
& 0x1c0) == TT_FILL
)
2897 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
2898 env
->tbr
&= ~0x7fffULL
;
2899 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
2901 env
->npc
= env
->pc
+ 4;
2902 env
->exception_index
= 0;
2906 static const char * const excp_names
[0x80] = {
2907 [TT_TFAULT
] = "Instruction Access Fault",
2908 [TT_ILL_INSN
] = "Illegal Instruction",
2909 [TT_PRIV_INSN
] = "Privileged Instruction",
2910 [TT_NFPU_INSN
] = "FPU Disabled",
2911 [TT_WIN_OVF
] = "Window Overflow",
2912 [TT_WIN_UNF
] = "Window Underflow",
2913 [TT_UNALIGNED
] = "Unaligned Memory Access",
2914 [TT_FP_EXCP
] = "FPU Exception",
2915 [TT_DFAULT
] = "Data Access Fault",
2916 [TT_TOVF
] = "Tag Overflow",
2917 [TT_EXTINT
| 0x1] = "External Interrupt 1",
2918 [TT_EXTINT
| 0x2] = "External Interrupt 2",
2919 [TT_EXTINT
| 0x3] = "External Interrupt 3",
2920 [TT_EXTINT
| 0x4] = "External Interrupt 4",
2921 [TT_EXTINT
| 0x5] = "External Interrupt 5",
2922 [TT_EXTINT
| 0x6] = "External Interrupt 6",
2923 [TT_EXTINT
| 0x7] = "External Interrupt 7",
2924 [TT_EXTINT
| 0x8] = "External Interrupt 8",
2925 [TT_EXTINT
| 0x9] = "External Interrupt 9",
2926 [TT_EXTINT
| 0xa] = "External Interrupt 10",
2927 [TT_EXTINT
| 0xb] = "External Interrupt 11",
2928 [TT_EXTINT
| 0xc] = "External Interrupt 12",
2929 [TT_EXTINT
| 0xd] = "External Interrupt 13",
2930 [TT_EXTINT
| 0xe] = "External Interrupt 14",
2931 [TT_EXTINT
| 0xf] = "External Interrupt 15",
2932 [TT_TOVF
] = "Tag Overflow",
2933 [TT_CODE_ACCESS
] = "Instruction Access Error",
2934 [TT_DATA_ACCESS
] = "Data Access Error",
2935 [TT_DIV_ZERO
] = "Division By Zero",
2936 [TT_NCP_INSN
] = "Coprocessor Disabled",
2940 void do_interrupt(CPUState
*env
)
2942 int cwp
, intno
= env
->exception_index
;
2945 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
2949 if (intno
< 0 || intno
>= 0x100)
2951 else if (intno
>= 0x80)
2952 name
= "Trap Instruction";
2954 name
= excp_names
[intno
];
2959 qemu_log("%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
2962 env
->npc
, env
->regwptr
[6]);
2963 log_cpu_state(env
, 0);
2970 ptr
= (uint8_t *)env
->pc
;
2971 for(i
= 0; i
< 16; i
++) {
2972 qemu_log(" %02x", ldub(ptr
+ i
));
2980 #if !defined(CONFIG_USER_ONLY)
2981 if (env
->psret
== 0) {
2982 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state",
2983 env
->exception_index
);
2988 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
2989 cpu_set_cwp(env
, cwp
);
2990 env
->regwptr
[9] = env
->pc
;
2991 env
->regwptr
[10] = env
->npc
;
2992 env
->psrps
= env
->psrs
;
2994 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
2996 env
->npc
= env
->pc
+ 4;
2997 env
->exception_index
= 0;
3001 #if !defined(CONFIG_USER_ONLY)
3003 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3006 #define MMUSUFFIX _mmu
3007 #define ALIGNED_ONLY
3010 #include "softmmu_template.h"
3013 #include "softmmu_template.h"
3016 #include "softmmu_template.h"
3019 #include "softmmu_template.h"
3021 /* XXX: make it generic ? */
3022 static void cpu_restore_state2(void *retaddr
)
3024 TranslationBlock
*tb
;
3028 /* now we have a real cpu fault */
3029 pc
= (unsigned long)retaddr
;
3030 tb
= tb_find_pc(pc
);
3032 /* the PC is inside the translated code. It means that we have
3033 a virtual CPU fault */
3034 cpu_restore_state(tb
, env
, pc
, (void *)(long)env
->cond
);
3039 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
3042 #ifdef DEBUG_UNALIGNED
3043 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
3044 "\n", addr
, env
->pc
);
3046 cpu_restore_state2(retaddr
);
3047 raise_exception(TT_UNALIGNED
);
3050 /* try to fill the TLB and return an exception if error. If retaddr is
3051 NULL, it means that the function was called in C code (i.e. not
3052 from generated code or from helper.c) */
3053 /* XXX: fix it to restore all registers */
3054 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
3057 CPUState
*saved_env
;
3059 /* XXX: hack to restore env in all cases, even if not called from
3062 env
= cpu_single_env
;
3064 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
3066 cpu_restore_state2(retaddr
);
3074 #ifndef TARGET_SPARC64
3075 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3076 int is_asi
, int size
)
3078 CPUState
*saved_env
;
3080 /* XXX: hack to restore env in all cases, even if not called from
3083 env
= cpu_single_env
;
3084 #ifdef DEBUG_UNASSIGNED
3086 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3087 " asi 0x%02x from " TARGET_FMT_lx
"\n",
3088 is_exec
? "exec" : is_write
? "write" : "read", size
,
3089 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
3091 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
3092 " from " TARGET_FMT_lx
"\n",
3093 is_exec
? "exec" : is_write
? "write" : "read", size
,
3094 size
== 1 ? "" : "s", addr
, env
->pc
);
3096 if (env
->mmuregs
[3]) /* Fault status register */
3097 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
3099 env
->mmuregs
[3] |= 1 << 16;
3101 env
->mmuregs
[3] |= 1 << 5;
3103 env
->mmuregs
[3] |= 1 << 6;
3105 env
->mmuregs
[3] |= 1 << 7;
3106 env
->mmuregs
[3] |= (5 << 2) | 2;
3107 env
->mmuregs
[4] = addr
; /* Fault address register */
3108 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
3110 raise_exception(TT_CODE_ACCESS
);
3112 raise_exception(TT_DATA_ACCESS
);
3117 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
3118 int is_asi
, int size
)
3120 #ifdef DEBUG_UNASSIGNED
3121 CPUState
*saved_env
;
3123 /* XXX: hack to restore env in all cases, even if not called from
3126 env
= cpu_single_env
;
3127 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
3128 "\n", addr
, env
->pc
);
3132 raise_exception(TT_CODE_ACCESS
);
3134 raise_exception(TT_DATA_ACCESS
);
3138 #ifdef TARGET_SPARC64
3139 void helper_tick_set_count(void *opaque
, uint64_t count
)
3141 #if !defined(CONFIG_USER_ONLY)
3142 cpu_tick_set_count(opaque
, count
);
3146 uint64_t helper_tick_get_count(void *opaque
)
3148 #if !defined(CONFIG_USER_ONLY)
3149 return cpu_tick_get_count(opaque
);
3155 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
3157 #if !defined(CONFIG_USER_ONLY)
3158 cpu_tick_set_limit(opaque
, limit
);