2 #include "host-utils.h"
7 //#define DEBUG_UNALIGNED
8 //#define DEBUG_UNASSIGNED
11 #define DPRINTF_MMU(fmt, args...) \
12 do { printf("MMU: " fmt , ##args); } while (0)
14 #define DPRINTF_MMU(fmt, args...)
18 #define DPRINTF_MXCC(fmt, args...) \
19 do { printf("MXCC: " fmt , ##args); } while (0)
21 #define DPRINTF_MXCC(fmt, args...)
24 void raise_exception(int tt)
26 env->exception_index = tt;
30 void check_ieee_exceptions()
32 T0 = get_float_exception_flags(&env->fp_status);
35 /* Copy IEEE 754 flags into FSR */
36 if (T0 & float_flag_invalid)
38 if (T0 & float_flag_overflow)
40 if (T0 & float_flag_underflow)
42 if (T0 & float_flag_divbyzero)
44 if (T0 & float_flag_inexact)
47 if ((env->fsr & FSR_CEXC_MASK) & ((env->fsr & FSR_TEM_MASK) >> 23))
49 /* Unmasked exception, generate a trap */
50 env->fsr |= FSR_FTT_IEEE_EXCP;
51 raise_exception(TT_FP_EXCP);
55 /* Accumulate exceptions */
56 env->fsr |= (env->fsr & FSR_CEXC_MASK) << 5;
61 #ifdef USE_INT_TO_FLOAT_HELPERS
64 set_float_exception_flags(0, &env->fp_status);
65 FT0 = int32_to_float32(*((int32_t *)&FT1), &env->fp_status);
66 check_ieee_exceptions();
71 DT0 = int32_to_float64(*((int32_t *)&FT1), &env->fp_status);
76 set_float_exception_flags(0, &env->fp_status);
77 FT0 = int64_to_float32(*((int64_t *)&DT1), &env->fp_status);
78 check_ieee_exceptions();
83 set_float_exception_flags(0, &env->fp_status);
84 DT0 = int64_to_float64(*((int64_t *)&DT1), &env->fp_status);
85 check_ieee_exceptions();
92 FT0 = float32_abs(FT1);
98 DT0 = float64_abs(DT1);
104 set_float_exception_flags(0, &env->fp_status);
105 FT0 = float32_sqrt(FT1, &env->fp_status);
106 check_ieee_exceptions();
111 set_float_exception_flags(0, &env->fp_status);
112 DT0 = float64_sqrt(DT1, &env->fp_status);
113 check_ieee_exceptions();
116 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
117 void glue(do_, name) (void) \
119 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
120 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
121 case float_relation_unordered: \
122 T0 = (FSR_FCC1 | FSR_FCC0) << FS; \
123 if ((env->fsr & FSR_NVM) || TRAP) { \
125 env->fsr |= FSR_NVC; \
126 env->fsr |= FSR_FTT_IEEE_EXCP; \
127 raise_exception(TT_FP_EXCP); \
129 env->fsr |= FSR_NVA; \
132 case float_relation_less: \
133 T0 = FSR_FCC0 << FS; \
135 case float_relation_greater: \
136 T0 = FSR_FCC1 << FS; \
145 GEN_FCMP(fcmps, float32, FT0, FT1, 0, 0);
146 GEN_FCMP(fcmpd, float64, DT0, DT1, 0, 0);
148 GEN_FCMP(fcmpes, float32, FT0, FT1, 0, 1);
149 GEN_FCMP(fcmped, float64, DT0, DT1, 0, 1);
151 #ifdef TARGET_SPARC64
152 GEN_FCMP(fcmps_fcc1, float32, FT0, FT1, 22, 0);
153 GEN_FCMP(fcmpd_fcc1, float64, DT0, DT1, 22, 0);
155 GEN_FCMP(fcmps_fcc2, float32, FT0, FT1, 24, 0);
156 GEN_FCMP(fcmpd_fcc2, float64, DT0, DT1, 24, 0);
158 GEN_FCMP(fcmps_fcc3, float32, FT0, FT1, 26, 0);
159 GEN_FCMP(fcmpd_fcc3, float64, DT0, DT1, 26, 0);
161 GEN_FCMP(fcmpes_fcc1, float32, FT0, FT1, 22, 1);
162 GEN_FCMP(fcmped_fcc1, float64, DT0, DT1, 22, 1);
164 GEN_FCMP(fcmpes_fcc2, float32, FT0, FT1, 24, 1);
165 GEN_FCMP(fcmped_fcc2, float64, DT0, DT1, 24, 1);
167 GEN_FCMP(fcmpes_fcc3, float32, FT0, FT1, 26, 1);
168 GEN_FCMP(fcmped_fcc3, float64, DT0, DT1, 26, 1);
171 #ifndef TARGET_SPARC64
172 #ifndef CONFIG_USER_ONLY
175 static void dump_mxcc(CPUState *env)
177 printf("mxccdata: %016llx %016llx %016llx %016llx\n",
178 env->mxccdata[0], env->mxccdata[1], env->mxccdata[2], env->mxccdata[3]);
179 printf("mxccregs: %016llx %016llx %016llx %016llx\n"
180 " %016llx %016llx %016llx %016llx\n",
181 env->mxccregs[0], env->mxccregs[1], env->mxccregs[2], env->mxccregs[3],
182 env->mxccregs[4], env->mxccregs[5], env->mxccregs[6], env->mxccregs[7]);
186 void helper_ld_asi(int asi, int size, int sign)
191 uint32_t last_T0 = T0;
195 case 2: /* SuperSparc MXCC registers */
197 case 0x01c00a00: /* MXCC control register */
199 ret = env->mxccregs[3];
200 T0 = env->mxccregs[3] >> 32;
202 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
204 case 0x01c00a04: /* MXCC control register */
206 ret = env->mxccregs[3];
208 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
210 case 0x01c00f00: /* MBus port address register */
212 ret = env->mxccregs[7];
213 T0 = env->mxccregs[7] >> 32;
215 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
218 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", T0, size);
221 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, T0 = %08x -> ret = %08x,"
222 "T0 = %08x\n", asi, size, sign, last_T0, ret, T0);
227 case 3: /* MMU probe */
231 mmulev = (T0 >> 8) & 15;
235 ret = mmu_probe(env, T0, mmulev);
238 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08x\n", T0, mmulev, ret);
241 case 4: /* read MMU regs */
243 int reg = (T0 >> 8) & 0xf;
245 ret = env->mmuregs[reg];
246 if (reg == 3) /* Fault status cleared on read */
247 env->mmuregs[reg] = 0;
248 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08x\n", reg, ret);
251 case 9: /* Supervisor code access */
257 ret = lduw_code(T0 & ~1);
261 ret = ldl_code(T0 & ~3);
264 tmp = ldq_code(T0 & ~7);
266 T0 = tmp & 0xffffffff;
270 case 0xa: /* User data access */
276 ret = lduw_user(T0 & ~1);
280 ret = ldl_user(T0 & ~3);
283 tmp = ldq_user(T0 & ~7);
285 T0 = tmp & 0xffffffff;
289 case 0xb: /* Supervisor data access */
292 ret = ldub_kernel(T0);
295 ret = lduw_kernel(T0 & ~1);
299 ret = ldl_kernel(T0 & ~3);
302 tmp = ldq_kernel(T0 & ~7);
304 T0 = tmp & 0xffffffff;
308 case 0xc: /* I-cache tag */
309 case 0xd: /* I-cache data */
310 case 0xe: /* D-cache tag */
311 case 0xf: /* D-cache data */
313 case 0x20: /* MMU passthrough */
319 ret = lduw_phys(T0 & ~1);
323 ret = ldl_phys(T0 & ~3);
326 tmp = ldq_phys(T0 & ~7);
328 T0 = tmp & 0xffffffff;
332 case 0x2e: /* MMU passthrough, 0xexxxxxxxx */
333 case 0x2f: /* MMU passthrough, 0xfxxxxxxxx */
336 ret = ldub_phys((target_phys_addr_t)T0
337 | ((target_phys_addr_t)(asi & 0xf) << 32));
340 ret = lduw_phys((target_phys_addr_t)(T0 & ~1)
341 | ((target_phys_addr_t)(asi & 0xf) << 32));
345 ret = ldl_phys((target_phys_addr_t)(T0 & ~3)
346 | ((target_phys_addr_t)(asi & 0xf) << 32));
349 tmp = ldq_phys((target_phys_addr_t)(T0 & ~7)
350 | ((target_phys_addr_t)(asi & 0xf) << 32));
352 T0 = tmp & 0xffffffff;
356 case 0x21 ... 0x2d: /* MMU passthrough, unassigned */
358 do_unassigned_access(T0, 0, 0, 1);
379 void helper_st_asi(int asi, int size)
382 case 2: /* SuperSparc MXCC registers */
384 case 0x01c00000: /* MXCC stream data register 0 */
386 env->mxccdata[0] = ((uint64_t)T1 << 32) | T2;
388 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
390 case 0x01c00008: /* MXCC stream data register 1 */
392 env->mxccdata[1] = ((uint64_t)T1 << 32) | T2;
394 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
396 case 0x01c00010: /* MXCC stream data register 2 */
398 env->mxccdata[2] = ((uint64_t)T1 << 32) | T2;
400 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
402 case 0x01c00018: /* MXCC stream data register 3 */
404 env->mxccdata[3] = ((uint64_t)T1 << 32) | T2;
406 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
408 case 0x01c00100: /* MXCC stream source */
410 env->mxccregs[0] = ((uint64_t)T1 << 32) | T2;
412 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
413 env->mxccdata[0] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 0);
414 env->mxccdata[1] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 8);
415 env->mxccdata[2] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 16);
416 env->mxccdata[3] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 24);
418 case 0x01c00200: /* MXCC stream destination */
420 env->mxccregs[1] = ((uint64_t)T1 << 32) | T2;
422 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
423 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 0, env->mxccdata[0]);
424 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 8, env->mxccdata[1]);
425 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 16, env->mxccdata[2]);
426 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 24, env->mxccdata[3]);
428 case 0x01c00a00: /* MXCC control register */
430 env->mxccregs[3] = ((uint64_t)T1 << 32) | T2;
432 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
434 case 0x01c00a04: /* MXCC control register */
436 env->mxccregs[3] = (env->mxccregs[0xa] & 0xffffffff00000000) | T1;
438 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
440 case 0x01c00e00: /* MXCC error register */
442 env->mxccregs[6] = ((uint64_t)T1 << 32) | T2;
444 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
445 if (env->mxccregs[6] == 0xffffffffffffffffULL) {
446 // this is probably a reset
449 case 0x01c00f00: /* MBus port address register */
451 env->mxccregs[7] = ((uint64_t)T1 << 32) | T2;
453 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
456 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", T0, size);
459 DPRINTF_MXCC("asi = %d, size = %d, T0 = %08x, T1 = %08x\n", asi, size, T0, T1);
464 case 3: /* MMU flush */
468 mmulev = (T0 >> 8) & 15;
469 DPRINTF_MMU("mmu flush level %d\n", mmulev);
471 case 0: // flush page
472 tlb_flush_page(env, T0 & 0xfffff000);
474 case 1: // flush segment (256k)
475 case 2: // flush region (16M)
476 case 3: // flush context (4G)
477 case 4: // flush entire
488 case 4: /* write MMU regs */
490 int reg = (T0 >> 8) & 0xf;
493 oldreg = env->mmuregs[reg];
496 env->mmuregs[reg] &= ~(MMU_E | MMU_NF | MMU_BM);
497 env->mmuregs[reg] |= T1 & (MMU_E | MMU_NF | MMU_BM);
498 // Mappings generated during no-fault mode or MMU
499 // disabled mode are invalid in normal mode
500 if (oldreg != env->mmuregs[reg])
504 env->mmuregs[reg] = T1;
505 if (oldreg != env->mmuregs[reg]) {
506 /* we flush when the MMU context changes because
507 QEMU has no MMU context support */
515 env->mmuregs[reg] = T1;
518 if (oldreg != env->mmuregs[reg]) {
519 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n", reg, oldreg, env->mmuregs[reg]);
526 case 0xa: /* User data access */
532 stw_user(T0 & ~1, T1);
536 stl_user(T0 & ~3, T1);
539 stq_user(T0 & ~7, ((uint64_t)T1 << 32) | T2);
543 case 0xb: /* Supervisor data access */
549 stw_kernel(T0 & ~1, T1);
553 stl_kernel(T0 & ~3, T1);
556 stq_kernel(T0 & ~7, ((uint64_t)T1 << 32) | T2);
560 case 0xc: /* I-cache tag */
561 case 0xd: /* I-cache data */
562 case 0xe: /* D-cache tag */
563 case 0xf: /* D-cache data */
564 case 0x10: /* I/D-cache flush page */
565 case 0x11: /* I/D-cache flush segment */
566 case 0x12: /* I/D-cache flush region */
567 case 0x13: /* I/D-cache flush context */
568 case 0x14: /* I/D-cache flush user */
570 case 0x17: /* Block copy, sta access */
573 // address (T0) = dst
576 uint32_t src = T1 & ~3, dst = T0 & ~3, temp;
578 for (i = 0; i < 32; i += 4, src += 4, dst += 4) {
579 temp = ldl_kernel(src);
580 stl_kernel(dst, temp);
584 case 0x1f: /* Block fill, stda access */
587 // address (T0) = dst
590 uint32_t dst = T0 & 7;
593 val = (((uint64_t)T1) << 32) | T2;
595 for (i = 0; i < 32; i += 8, dst += 8)
596 stq_kernel(dst, val);
599 case 0x20: /* MMU passthrough */
606 stw_phys(T0 & ~1, T1);
610 stl_phys(T0 & ~3, T1);
613 stq_phys(T0 & ~7, ((uint64_t)T1 << 32) | T2);
618 case 0x2e: /* MMU passthrough, 0xexxxxxxxx */
619 case 0x2f: /* MMU passthrough, 0xfxxxxxxxx */
623 stb_phys((target_phys_addr_t)T0
624 | ((target_phys_addr_t)(asi & 0xf) << 32), T1);
627 stw_phys((target_phys_addr_t)(T0 & ~1)
628 | ((target_phys_addr_t)(asi & 0xf) << 32), T1);
632 stl_phys((target_phys_addr_t)(T0 & ~3)
633 | ((target_phys_addr_t)(asi & 0xf) << 32), T1);
636 stq_phys((target_phys_addr_t)(T0 & ~7)
637 | ((target_phys_addr_t)(asi & 0xf) << 32),
638 ((uint64_t)T1 << 32) | T2);
643 case 0x31: /* Ross RT620 I-cache flush */
644 case 0x36: /* I-cache flash clear */
645 case 0x37: /* D-cache flash clear */
647 case 9: /* Supervisor code access, XXX */
648 case 0x21 ... 0x2d: /* MMU passthrough, unassigned */
650 do_unassigned_access(T0, 1, 0, 1);
655 #endif /* CONFIG_USER_ONLY */
656 #else /* TARGET_SPARC64 */
658 #ifdef CONFIG_USER_ONLY
659 void helper_ld_asi(int asi, int size, int sign)
664 raise_exception(TT_PRIV_ACT);
667 case 0x80: // Primary
668 case 0x82: // Primary no-fault
669 case 0x88: // Primary LE
670 case 0x8a: // Primary no-fault LE
677 ret = lduw_raw(T0 & ~1);
680 ret = ldl_raw(T0 & ~3);
684 ret = ldq_raw(T0 & ~7);
689 case 0x81: // Secondary
690 case 0x83: // Secondary no-fault
691 case 0x89: // Secondary LE
692 case 0x8b: // Secondary no-fault LE
699 /* Convert from little endian */
701 case 0x88: // Primary LE
702 case 0x89: // Secondary LE
703 case 0x8a: // Primary no-fault LE
704 case 0x8b: // Secondary no-fault LE
722 /* Convert to signed number */
741 void helper_st_asi(int asi, int size)
744 raise_exception(TT_PRIV_ACT);
746 /* Convert to little endian */
748 case 0x88: // Primary LE
749 case 0x89: // Secondary LE
768 case 0x80: // Primary
769 case 0x88: // Primary LE
776 stw_raw(T0 & ~1, T1);
779 stl_raw(T0 & ~3, T1);
783 stq_raw(T0 & ~7, T1);
788 case 0x81: // Secondary
789 case 0x89: // Secondary LE
793 case 0x82: // Primary no-fault, RO
794 case 0x83: // Secondary no-fault, RO
795 case 0x8a: // Primary no-fault LE, RO
796 case 0x8b: // Secondary no-fault LE, RO
798 do_unassigned_access(T0, 1, 0, 1);
803 #else /* CONFIG_USER_ONLY */
805 void helper_ld_asi(int asi, int size, int sign)
809 if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
810 || (asi >= 0x30 && asi < 0x80 && !(env->hpstate & HS_PRIV)))
811 raise_exception(TT_PRIV_ACT);
814 case 0x10: // As if user primary
815 case 0x18: // As if user primary LE
816 case 0x80: // Primary
817 case 0x82: // Primary no-fault
818 case 0x88: // Primary LE
819 case 0x8a: // Primary no-fault LE
820 if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
821 if (env->hpstate & HS_PRIV) {
827 ret = lduw_hypv(T0 & ~1);
830 ret = ldl_hypv(T0 & ~3);
834 ret = ldq_hypv(T0 & ~7);
840 ret = ldub_kernel(T0);
843 ret = lduw_kernel(T0 & ~1);
846 ret = ldl_kernel(T0 & ~3);
850 ret = ldq_kernel(T0 & ~7);
860 ret = lduw_user(T0 & ~1);
863 ret = ldl_user(T0 & ~3);
867 ret = ldq_user(T0 & ~7);
873 case 0x15: // Bypass, non-cacheable
874 case 0x1c: // Bypass LE
875 case 0x1d: // Bypass, non-cacheable LE
882 ret = lduw_phys(T0 & ~1);
885 ret = ldl_phys(T0 & ~3);
889 ret = ldq_phys(T0 & ~7);
894 case 0x04: // Nucleus
895 case 0x0c: // Nucleus Little Endian (LE)
896 case 0x11: // As if user secondary
897 case 0x19: // As if user secondary LE
898 case 0x24: // Nucleus quad LDD 128 bit atomic
899 case 0x2c: // Nucleus quad LDD 128 bit atomic
900 case 0x4a: // UPA config
901 case 0x81: // Secondary
902 case 0x83: // Secondary no-fault
903 case 0x89: // Secondary LE
904 case 0x8b: // Secondary no-fault LE
910 case 0x50: // I-MMU regs
912 int reg = (T0 >> 3) & 0xf;
914 ret = env->immuregs[reg];
917 case 0x51: // I-MMU 8k TSB pointer
918 case 0x52: // I-MMU 64k TSB pointer
919 case 0x55: // I-MMU data access
922 case 0x56: // I-MMU tag read
926 for (i = 0; i < 64; i++) {
927 // Valid, ctx match, vaddr match
928 if ((env->itlb_tte[i] & 0x8000000000000000ULL) != 0 &&
929 env->itlb_tag[i] == T0) {
930 ret = env->itlb_tag[i];
936 case 0x58: // D-MMU regs
938 int reg = (T0 >> 3) & 0xf;
940 ret = env->dmmuregs[reg];
943 case 0x5e: // D-MMU tag read
947 for (i = 0; i < 64; i++) {
948 // Valid, ctx match, vaddr match
949 if ((env->dtlb_tte[i] & 0x8000000000000000ULL) != 0 &&
950 env->dtlb_tag[i] == T0) {
951 ret = env->dtlb_tag[i];
957 case 0x59: // D-MMU 8k TSB pointer
958 case 0x5a: // D-MMU 64k TSB pointer
959 case 0x5b: // D-MMU data pointer
960 case 0x5d: // D-MMU data access
961 case 0x48: // Interrupt dispatch, RO
962 case 0x49: // Interrupt data receive
963 case 0x7f: // Incoming interrupt vector, RO
966 case 0x54: // I-MMU data in, WO
967 case 0x57: // I-MMU demap, WO
968 case 0x5c: // D-MMU data in, WO
969 case 0x5f: // D-MMU demap, WO
970 case 0x77: // Interrupt vector, WO
972 do_unassigned_access(T0, 0, 0, 1);
977 /* Convert from little endian */
979 case 0x0c: // Nucleus Little Endian (LE)
980 case 0x18: // As if user primary LE
981 case 0x19: // As if user secondary LE
982 case 0x1c: // Bypass LE
983 case 0x1d: // Bypass, non-cacheable LE
984 case 0x88: // Primary LE
985 case 0x89: // Secondary LE
986 case 0x8a: // Primary no-fault LE
987 case 0x8b: // Secondary no-fault LE
1005 /* Convert to signed number */
1012 ret = (int16_t) ret;
1015 ret = (int32_t) ret;
1024 void helper_st_asi(int asi, int size)
1026 if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
1027 || (asi >= 0x30 && asi < 0x80 && !(env->hpstate & HS_PRIV)))
1028 raise_exception(TT_PRIV_ACT);
1030 /* Convert to little endian */
1032 case 0x0c: // Nucleus Little Endian (LE)
1033 case 0x18: // As if user primary LE
1034 case 0x19: // As if user secondary LE
1035 case 0x1c: // Bypass LE
1036 case 0x1d: // Bypass, non-cacheable LE
1037 case 0x88: // Primary LE
1038 case 0x89: // Secondary LE
1057 case 0x10: // As if user primary
1058 case 0x18: // As if user primary LE
1059 case 0x80: // Primary
1060 case 0x88: // Primary LE
1061 if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
1062 if (env->hpstate & HS_PRIV) {
1068 stw_hypv(T0 & ~1, T1);
1071 stl_hypv(T0 & ~3, T1);
1075 stq_hypv(T0 & ~7, T1);
1084 stw_kernel(T0 & ~1, T1);
1087 stl_kernel(T0 & ~3, T1);
1091 stq_kernel(T0 & ~7, T1);
1101 stw_user(T0 & ~1, T1);
1104 stl_user(T0 & ~3, T1);
1108 stq_user(T0 & ~7, T1);
1113 case 0x14: // Bypass
1114 case 0x15: // Bypass, non-cacheable
1115 case 0x1c: // Bypass LE
1116 case 0x1d: // Bypass, non-cacheable LE
1123 stw_phys(T0 & ~1, T1);
1126 stl_phys(T0 & ~3, T1);
1130 stq_phys(T0 & ~7, T1);
1135 case 0x04: // Nucleus
1136 case 0x0c: // Nucleus Little Endian (LE)
1137 case 0x11: // As if user secondary
1138 case 0x19: // As if user secondary LE
1139 case 0x24: // Nucleus quad LDD 128 bit atomic
1140 case 0x2c: // Nucleus quad LDD 128 bit atomic
1141 case 0x4a: // UPA config
1142 case 0x81: // Secondary
1143 case 0x89: // Secondary LE
1151 env->lsu = T1 & (DMMU_E | IMMU_E);
1152 // Mappings generated during D/I MMU disabled mode are
1153 // invalid in normal mode
1154 if (oldreg != env->lsu) {
1155 DPRINTF_MMU("LSU change: 0x%" PRIx64 " -> 0x%" PRIx64 "\n", oldreg, env->lsu);
1163 case 0x50: // I-MMU regs
1165 int reg = (T0 >> 3) & 0xf;
1168 oldreg = env->immuregs[reg];
1173 case 1: // Not in I-MMU
1180 T1 = 0; // Clear SFSR
1182 case 5: // TSB access
1183 case 6: // Tag access
1187 env->immuregs[reg] = T1;
1188 if (oldreg != env->immuregs[reg]) {
1189 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64 " -> 0x%08" PRIx64 "\n", reg, oldreg, env->immuregs[reg]);
1196 case 0x54: // I-MMU data in
1200 // Try finding an invalid entry
1201 for (i = 0; i < 64; i++) {
1202 if ((env->itlb_tte[i] & 0x8000000000000000ULL) == 0) {
1203 env->itlb_tag[i] = env->immuregs[6];
1204 env->itlb_tte[i] = T1;
1208 // Try finding an unlocked entry
1209 for (i = 0; i < 64; i++) {
1210 if ((env->itlb_tte[i] & 0x40) == 0) {
1211 env->itlb_tag[i] = env->immuregs[6];
1212 env->itlb_tte[i] = T1;
1219 case 0x55: // I-MMU data access
1221 unsigned int i = (T0 >> 3) & 0x3f;
1223 env->itlb_tag[i] = env->immuregs[6];
1224 env->itlb_tte[i] = T1;
1227 case 0x57: // I-MMU demap
1230 case 0x58: // D-MMU regs
1232 int reg = (T0 >> 3) & 0xf;
1235 oldreg = env->dmmuregs[reg];
1241 if ((T1 & 1) == 0) {
1242 T1 = 0; // Clear SFSR, Fault address
1243 env->dmmuregs[4] = 0;
1245 env->dmmuregs[reg] = T1;
1247 case 1: // Primary context
1248 case 2: // Secondary context
1249 case 5: // TSB access
1250 case 6: // Tag access
1251 case 7: // Virtual Watchpoint
1252 case 8: // Physical Watchpoint
1256 env->dmmuregs[reg] = T1;
1257 if (oldreg != env->dmmuregs[reg]) {
1258 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64 " -> 0x%08" PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]);
1265 case 0x5c: // D-MMU data in
1269 // Try finding an invalid entry
1270 for (i = 0; i < 64; i++) {
1271 if ((env->dtlb_tte[i] & 0x8000000000000000ULL) == 0) {
1272 env->dtlb_tag[i] = env->dmmuregs[6];
1273 env->dtlb_tte[i] = T1;
1277 // Try finding an unlocked entry
1278 for (i = 0; i < 64; i++) {
1279 if ((env->dtlb_tte[i] & 0x40) == 0) {
1280 env->dtlb_tag[i] = env->dmmuregs[6];
1281 env->dtlb_tte[i] = T1;
1288 case 0x5d: // D-MMU data access
1290 unsigned int i = (T0 >> 3) & 0x3f;
1292 env->dtlb_tag[i] = env->dmmuregs[6];
1293 env->dtlb_tte[i] = T1;
1296 case 0x5f: // D-MMU demap
1297 case 0x49: // Interrupt data receive
1300 case 0x51: // I-MMU 8k TSB pointer, RO
1301 case 0x52: // I-MMU 64k TSB pointer, RO
1302 case 0x56: // I-MMU tag read, RO
1303 case 0x59: // D-MMU 8k TSB pointer, RO
1304 case 0x5a: // D-MMU 64k TSB pointer, RO
1305 case 0x5b: // D-MMU data pointer, RO
1306 case 0x5e: // D-MMU tag read, RO
1307 case 0x48: // Interrupt dispatch, RO
1308 case 0x7f: // Incoming interrupt vector, RO
1309 case 0x82: // Primary no-fault, RO
1310 case 0x83: // Secondary no-fault, RO
1311 case 0x8a: // Primary no-fault LE, RO
1312 case 0x8b: // Secondary no-fault LE, RO
1314 do_unassigned_access(T0, 1, 0, 1);
1318 #endif /* CONFIG_USER_ONLY */
1320 void helper_ldf_asi(int asi, int size, int rd)
1322 target_ulong tmp_T0 = T0, tmp_T1 = T1;
1326 case 0xf0: // Block load primary
1327 case 0xf1: // Block load secondary
1328 case 0xf8: // Block load primary LE
1329 case 0xf9: // Block load secondary LE
1331 raise_exception(TT_ILL_INSN);
1335 raise_exception(TT_UNALIGNED);
1338 for (i = 0; i < 16; i++) {
1339 helper_ld_asi(asi & 0x8f, 4, 0);
1340 *(uint32_t *)&env->fpr[rd++] = T1;
1351 helper_ld_asi(asi, size, 0);
1355 *((uint32_t *)&FT0) = T1;
1358 *((int64_t *)&DT0) = T1;
1364 void helper_stf_asi(int asi, int size, int rd)
1366 target_ulong tmp_T0 = T0, tmp_T1 = T1;
1370 case 0xf0: // Block store primary
1371 case 0xf1: // Block store secondary
1372 case 0xf8: // Block store primary LE
1373 case 0xf9: // Block store secondary LE
1375 raise_exception(TT_ILL_INSN);
1379 raise_exception(TT_UNALIGNED);
1382 for (i = 0; i < 16; i++) {
1383 T1 = *(uint32_t *)&env->fpr[rd++];
1384 helper_st_asi(asi & 0x8f, 4);
1398 T1 = *((uint32_t *)&FT0);
1401 T1 = *((int64_t *)&DT0);
1404 helper_st_asi(asi, size);
1408 #endif /* TARGET_SPARC64 */
1410 #ifndef TARGET_SPARC64
1415 if (env->psret == 1)
1416 raise_exception(TT_ILL_INSN);
1419 cwp = (env->cwp + 1) & (NWINDOWS - 1);
1420 if (env->wim & (1 << cwp)) {
1421 raise_exception(TT_WIN_UNF);
1424 env->psrs = env->psrps;
1428 void helper_ldfsr(void)
1431 switch (env->fsr & FSR_RD_MASK) {
1432 case FSR_RD_NEAREST:
1433 rnd_mode = float_round_nearest_even;
1437 rnd_mode = float_round_to_zero;
1440 rnd_mode = float_round_up;
1443 rnd_mode = float_round_down;
1446 set_float_rounding_mode(rnd_mode, &env->fp_status);
1451 env->exception_index = EXCP_DEBUG;
1455 #ifndef TARGET_SPARC64
1458 if ((T0 & PSR_CWP) >= NWINDOWS)
1459 raise_exception(TT_ILL_INSN);
1476 static inline uint64_t *get_gregset(uint64_t pstate)
1491 static inline void change_pstate(uint64_t new_pstate)
1493 uint64_t pstate_regs, new_pstate_regs;
1494 uint64_t *src, *dst;
1496 pstate_regs = env->pstate & 0xc01;
1497 new_pstate_regs = new_pstate & 0xc01;
1498 if (new_pstate_regs != pstate_regs) {
1499 // Switch global register bank
1500 src = get_gregset(new_pstate_regs);
1501 dst = get_gregset(pstate_regs);
1502 memcpy32(dst, env->gregs);
1503 memcpy32(env->gregs, src);
1505 env->pstate = new_pstate;
1508 void do_wrpstate(void)
1510 change_pstate(T0 & 0xf3f);
1516 env->pc = env->tnpc[env->tl];
1517 env->npc = env->tnpc[env->tl] + 4;
1518 PUT_CCR(env, env->tstate[env->tl] >> 32);
1519 env->asi = (env->tstate[env->tl] >> 24) & 0xff;
1520 change_pstate((env->tstate[env->tl] >> 8) & 0xf3f);
1521 PUT_CWP64(env, env->tstate[env->tl] & 0xff);
1527 env->pc = env->tpc[env->tl];
1528 env->npc = env->tnpc[env->tl];
1529 PUT_CCR(env, env->tstate[env->tl] >> 32);
1530 env->asi = (env->tstate[env->tl] >> 24) & 0xff;
1531 change_pstate((env->tstate[env->tl] >> 8) & 0xf3f);
1532 PUT_CWP64(env, env->tstate[env->tl] & 0xff);
1536 void set_cwp(int new_cwp)
1538 /* put the modified wrap registers at their proper location */
1539 if (env->cwp == (NWINDOWS - 1))
1540 memcpy32(env->regbase, env->regbase + NWINDOWS * 16);
1542 /* put the wrap registers at their temporary location */
1543 if (new_cwp == (NWINDOWS - 1))
1544 memcpy32(env->regbase + NWINDOWS * 16, env->regbase);
1545 env->regwptr = env->regbase + (new_cwp * 16);
1546 REGWPTR = env->regwptr;
1549 void cpu_set_cwp(CPUState *env1, int new_cwp)
1551 CPUState *saved_env;
1553 target_ulong *saved_regwptr;
1558 saved_regwptr = REGWPTR;
1564 REGWPTR = saved_regwptr;
1568 #ifdef TARGET_SPARC64
1569 void do_interrupt(int intno)
1572 if (loglevel & CPU_LOG_INT) {
1574 fprintf(logfile, "%6d: v=%04x pc=%016" PRIx64 " npc=%016" PRIx64 " SP=%016" PRIx64 "\n",
1577 env->npc, env->regwptr[6]);
1578 cpu_dump_state(env, logfile, fprintf, 0);
1584 fprintf(logfile, " code=");
1585 ptr = (uint8_t *)env->pc;
1586 for(i = 0; i < 16; i++) {
1587 fprintf(logfile, " %02x", ldub(ptr + i));
1589 fprintf(logfile, "\n");
1595 #if !defined(CONFIG_USER_ONLY)
1596 if (env->tl == MAXTL) {
1597 cpu_abort(env, "Trap 0x%04x while trap level is MAXTL, Error state", env->exception_index);
1601 env->tstate[env->tl] = ((uint64_t)GET_CCR(env) << 32) | ((env->asi & 0xff) << 24) |
1602 ((env->pstate & 0xf3f) << 8) | GET_CWP64(env);
1603 env->tpc[env->tl] = env->pc;
1604 env->tnpc[env->tl] = env->npc;
1605 env->tt[env->tl] = intno;
1606 change_pstate(PS_PEF | PS_PRIV | PS_AG);
1608 if (intno == TT_CLRWIN)
1609 set_cwp((env->cwp - 1) & (NWINDOWS - 1));
1610 else if ((intno & 0x1c0) == TT_SPILL)
1611 set_cwp((env->cwp - env->cansave - 2) & (NWINDOWS - 1));
1612 else if ((intno & 0x1c0) == TT_FILL)
1613 set_cwp((env->cwp + 1) & (NWINDOWS - 1));
1614 env->tbr &= ~0x7fffULL;
1615 env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
1616 if (env->tl < MAXTL - 1) {
1619 env->pstate |= PS_RED;
1620 if (env->tl != MAXTL)
1624 env->npc = env->pc + 4;
1625 env->exception_index = 0;
1628 void do_interrupt(int intno)
1633 if (loglevel & CPU_LOG_INT) {
1635 fprintf(logfile, "%6d: v=%02x pc=%08x npc=%08x SP=%08x\n",
1638 env->npc, env->regwptr[6]);
1639 cpu_dump_state(env, logfile, fprintf, 0);
1645 fprintf(logfile, " code=");
1646 ptr = (uint8_t *)env->pc;
1647 for(i = 0; i < 16; i++) {
1648 fprintf(logfile, " %02x", ldub(ptr + i));
1650 fprintf(logfile, "\n");
1656 #if !defined(CONFIG_USER_ONLY)
1657 if (env->psret == 0) {
1658 cpu_abort(env, "Trap 0x%02x while interrupts disabled, Error state", env->exception_index);
1663 cwp = (env->cwp - 1) & (NWINDOWS - 1);
1665 env->regwptr[9] = env->pc;
1666 env->regwptr[10] = env->npc;
1667 env->psrps = env->psrs;
1669 env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4);
1671 env->npc = env->pc + 4;
1672 env->exception_index = 0;
1676 #if !defined(CONFIG_USER_ONLY)
1678 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
1681 #define MMUSUFFIX _mmu
1682 #define ALIGNED_ONLY
1683 #define GETPC() (__builtin_return_address(0))
1686 #include "softmmu_template.h"
1689 #include "softmmu_template.h"
1692 #include "softmmu_template.h"
1695 #include "softmmu_template.h"
1697 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
1700 #ifdef DEBUG_UNALIGNED
1701 printf("Unaligned access to 0x%x from 0x%x\n", addr, env->pc);
1703 raise_exception(TT_UNALIGNED);
1706 /* try to fill the TLB and return an exception if error. If retaddr is
1707 NULL, it means that the function was called in C code (i.e. not
1708 from generated code or from helper.c) */
1709 /* XXX: fix it to restore all registers */
1710 void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
1712 TranslationBlock *tb;
1715 CPUState *saved_env;
1717 /* XXX: hack to restore env in all cases, even if not called from
1720 env = cpu_single_env;
1722 ret = cpu_sparc_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
1725 /* now we have a real cpu fault */
1726 pc = (unsigned long)retaddr;
1727 tb = tb_find_pc(pc);
1729 /* the PC is inside the translated code. It means that we have
1730 a virtual CPU fault */
1731 cpu_restore_state(tb, env, pc, (void *)T2);
1741 #ifndef TARGET_SPARC64
1742 void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
1745 CPUState *saved_env;
1747 /* XXX: hack to restore env in all cases, even if not called from
1750 env = cpu_single_env;
1751 if (env->mmuregs[3]) /* Fault status register */
1752 env->mmuregs[3] = 1; /* overflow (not read before another fault) */
1754 env->mmuregs[3] |= 1 << 16;
1756 env->mmuregs[3] |= 1 << 5;
1758 env->mmuregs[3] |= 1 << 6;
1760 env->mmuregs[3] |= 1 << 7;
1761 env->mmuregs[3] |= (5 << 2) | 2;
1762 env->mmuregs[4] = addr; /* Fault address register */
1763 if ((env->mmuregs[0] & MMU_E) && !(env->mmuregs[0] & MMU_NF)) {
1764 #ifdef DEBUG_UNASSIGNED
1765 printf("Unassigned mem access to " TARGET_FMT_plx " from " TARGET_FMT_lx
1766 "\n", addr, env->pc);
1769 raise_exception(TT_CODE_ACCESS);
1771 raise_exception(TT_DATA_ACCESS);
1776 void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
1779 #ifdef DEBUG_UNASSIGNED
1780 CPUState *saved_env;
1782 /* XXX: hack to restore env in all cases, even if not called from
1785 env = cpu_single_env;
1786 printf("Unassigned mem access to " TARGET_FMT_plx " from " TARGET_FMT_lx "\n",
1791 raise_exception(TT_CODE_ACCESS);
1793 raise_exception(TT_DATA_ACCESS);
1797 #ifdef TARGET_SPARC64
1798 void do_tick_set_count(void *opaque, uint64_t count)
1800 #if !defined(CONFIG_USER_ONLY)
1801 ptimer_set_count(opaque, -count);
1805 uint64_t do_tick_get_count(void *opaque)
1807 #if !defined(CONFIG_USER_ONLY)
1808 return -ptimer_get_count(opaque);
1814 void do_tick_set_limit(void *opaque, uint64_t limit)
1816 #if !defined(CONFIG_USER_ONLY)
1817 ptimer_set_limit(opaque, -limit, 0);