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 0x01c00c00: /* Module reset register */
212 ret = env->mxccregs[5] >> 32;
213 T0 = env->mxccregs[5];
214 // should we do something here?
216 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
218 case 0x01c00f00: /* MBus port address register */
220 ret = env->mxccregs[7];
221 T0 = env->mxccregs[7] >> 32;
223 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
226 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", T0, size);
229 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, T0 = %08x -> ret = %08x,"
230 "T0 = %08x\n", asi, size, sign, last_T0, ret, T0);
235 case 3: /* MMU probe */
239 mmulev = (T0 >> 8) & 15;
243 ret = mmu_probe(env, T0, mmulev);
246 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08x\n", T0, mmulev, ret);
249 case 4: /* read MMU regs */
251 int reg = (T0 >> 8) & 0xf;
253 ret = env->mmuregs[reg];
254 if (reg == 3) /* Fault status cleared on read */
255 env->mmuregs[reg] = 0;
256 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08x\n", reg, ret);
259 case 9: /* Supervisor code access */
265 ret = lduw_code(T0 & ~1);
269 ret = ldl_code(T0 & ~3);
272 tmp = ldq_code(T0 & ~7);
274 T0 = tmp & 0xffffffff;
278 case 0xa: /* User data access */
284 ret = lduw_user(T0 & ~1);
288 ret = ldl_user(T0 & ~3);
291 tmp = ldq_user(T0 & ~7);
293 T0 = tmp & 0xffffffff;
297 case 0xb: /* Supervisor data access */
300 ret = ldub_kernel(T0);
303 ret = lduw_kernel(T0 & ~1);
307 ret = ldl_kernel(T0 & ~3);
310 tmp = ldq_kernel(T0 & ~7);
312 T0 = tmp & 0xffffffff;
316 case 0xc: /* I-cache tag */
317 case 0xd: /* I-cache data */
318 case 0xe: /* D-cache tag */
319 case 0xf: /* D-cache data */
321 case 0x20: /* MMU passthrough */
327 ret = lduw_phys(T0 & ~1);
331 ret = ldl_phys(T0 & ~3);
334 tmp = ldq_phys(T0 & ~7);
336 T0 = tmp & 0xffffffff;
340 case 0x2e: /* MMU passthrough, 0xexxxxxxxx */
341 case 0x2f: /* MMU passthrough, 0xfxxxxxxxx */
344 ret = ldub_phys((target_phys_addr_t)T0
345 | ((target_phys_addr_t)(asi & 0xf) << 32));
348 ret = lduw_phys((target_phys_addr_t)(T0 & ~1)
349 | ((target_phys_addr_t)(asi & 0xf) << 32));
353 ret = ldl_phys((target_phys_addr_t)(T0 & ~3)
354 | ((target_phys_addr_t)(asi & 0xf) << 32));
357 tmp = ldq_phys((target_phys_addr_t)(T0 & ~7)
358 | ((target_phys_addr_t)(asi & 0xf) << 32));
360 T0 = tmp & 0xffffffff;
364 case 0x21 ... 0x2d: /* MMU passthrough, unassigned */
366 do_unassigned_access(T0, 0, 0, 1);
387 void helper_st_asi(int asi, int size)
390 case 2: /* SuperSparc MXCC registers */
392 case 0x01c00000: /* MXCC stream data register 0 */
394 env->mxccdata[0] = ((uint64_t)T1 << 32) | T2;
396 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
398 case 0x01c00008: /* MXCC stream data register 1 */
400 env->mxccdata[1] = ((uint64_t)T1 << 32) | T2;
402 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
404 case 0x01c00010: /* MXCC stream data register 2 */
406 env->mxccdata[2] = ((uint64_t)T1 << 32) | T2;
408 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
410 case 0x01c00018: /* MXCC stream data register 3 */
412 env->mxccdata[3] = ((uint64_t)T1 << 32) | T2;
414 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
416 case 0x01c00100: /* MXCC stream source */
418 env->mxccregs[0] = ((uint64_t)T1 << 32) | T2;
420 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
421 env->mxccdata[0] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 0);
422 env->mxccdata[1] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 8);
423 env->mxccdata[2] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 16);
424 env->mxccdata[3] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) + 24);
426 case 0x01c00200: /* MXCC stream destination */
428 env->mxccregs[1] = ((uint64_t)T1 << 32) | T2;
430 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
431 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 0, env->mxccdata[0]);
432 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 8, env->mxccdata[1]);
433 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 16, env->mxccdata[2]);
434 stq_phys((env->mxccregs[1] & 0xffffffffULL) + 24, env->mxccdata[3]);
436 case 0x01c00a00: /* MXCC control register */
438 env->mxccregs[3] = ((uint64_t)T1 << 32) | T2;
440 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
442 case 0x01c00a04: /* MXCC control register */
444 env->mxccregs[3] = (env->mxccregs[0xa] & 0xffffffff00000000ULL) | T1;
446 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
448 case 0x01c00e00: /* MXCC error register */
450 env->mxccregs[6] = ((uint64_t)T1 << 32) | T2;
452 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
453 if (env->mxccregs[6] == 0xffffffffffffffffULL) {
454 // this is probably a reset
457 case 0x01c00f00: /* MBus port address register */
459 env->mxccregs[7] = ((uint64_t)T1 << 32) | T2;
461 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0, size);
464 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", T0, size);
467 DPRINTF_MXCC("asi = %d, size = %d, T0 = %08x, T1 = %08x\n", asi, size, T0, T1);
472 case 3: /* MMU flush */
476 mmulev = (T0 >> 8) & 15;
477 DPRINTF_MMU("mmu flush level %d\n", mmulev);
479 case 0: // flush page
480 tlb_flush_page(env, T0 & 0xfffff000);
482 case 1: // flush segment (256k)
483 case 2: // flush region (16M)
484 case 3: // flush context (4G)
485 case 4: // flush entire
496 case 4: /* write MMU regs */
498 int reg = (T0 >> 8) & 0xf;
501 oldreg = env->mmuregs[reg];
504 env->mmuregs[reg] &= ~(MMU_E | MMU_NF | env->mmu_bm);
505 env->mmuregs[reg] |= T1 & (MMU_E | MMU_NF | env->mmu_bm);
506 // Mappings generated during no-fault mode or MMU
507 // disabled mode are invalid in normal mode
508 if (oldreg != env->mmuregs[reg])
512 env->mmuregs[reg] = T1;
513 if (oldreg != env->mmuregs[reg]) {
514 /* we flush when the MMU context changes because
515 QEMU has no MMU context support */
523 env->mmuregs[reg] = T1;
526 if (oldreg != env->mmuregs[reg]) {
527 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n", reg, oldreg, env->mmuregs[reg]);
534 case 0xa: /* User data access */
540 stw_user(T0 & ~1, T1);
544 stl_user(T0 & ~3, T1);
547 stq_user(T0 & ~7, ((uint64_t)T1 << 32) | T2);
551 case 0xb: /* Supervisor data access */
557 stw_kernel(T0 & ~1, T1);
561 stl_kernel(T0 & ~3, T1);
564 stq_kernel(T0 & ~7, ((uint64_t)T1 << 32) | T2);
568 case 0xc: /* I-cache tag */
569 case 0xd: /* I-cache data */
570 case 0xe: /* D-cache tag */
571 case 0xf: /* D-cache data */
572 case 0x10: /* I/D-cache flush page */
573 case 0x11: /* I/D-cache flush segment */
574 case 0x12: /* I/D-cache flush region */
575 case 0x13: /* I/D-cache flush context */
576 case 0x14: /* I/D-cache flush user */
578 case 0x17: /* Block copy, sta access */
581 // address (T0) = dst
584 uint32_t src = T1 & ~3, dst = T0 & ~3, temp;
586 for (i = 0; i < 32; i += 4, src += 4, dst += 4) {
587 temp = ldl_kernel(src);
588 stl_kernel(dst, temp);
592 case 0x1f: /* Block fill, stda access */
595 // address (T0) = dst
598 uint32_t dst = T0 & 7;
601 val = (((uint64_t)T1) << 32) | T2;
603 for (i = 0; i < 32; i += 8, dst += 8)
604 stq_kernel(dst, val);
607 case 0x20: /* MMU passthrough */
614 stw_phys(T0 & ~1, T1);
618 stl_phys(T0 & ~3, T1);
621 stq_phys(T0 & ~7, ((uint64_t)T1 << 32) | T2);
626 case 0x2e: /* MMU passthrough, 0xexxxxxxxx */
627 case 0x2f: /* MMU passthrough, 0xfxxxxxxxx */
631 stb_phys((target_phys_addr_t)T0
632 | ((target_phys_addr_t)(asi & 0xf) << 32), T1);
635 stw_phys((target_phys_addr_t)(T0 & ~1)
636 | ((target_phys_addr_t)(asi & 0xf) << 32), T1);
640 stl_phys((target_phys_addr_t)(T0 & ~3)
641 | ((target_phys_addr_t)(asi & 0xf) << 32), T1);
644 stq_phys((target_phys_addr_t)(T0 & ~7)
645 | ((target_phys_addr_t)(asi & 0xf) << 32),
646 ((uint64_t)T1 << 32) | T2);
651 case 0x31: /* Ross RT620 I-cache flush */
652 case 0x36: /* I-cache flash clear */
653 case 0x37: /* D-cache flash clear */
655 case 9: /* Supervisor code access, XXX */
656 case 0x21 ... 0x2d: /* MMU passthrough, unassigned */
658 do_unassigned_access(T0, 1, 0, 1);
663 #endif /* CONFIG_USER_ONLY */
664 #else /* TARGET_SPARC64 */
666 #ifdef CONFIG_USER_ONLY
667 void helper_ld_asi(int asi, int size, int sign)
672 raise_exception(TT_PRIV_ACT);
675 case 0x80: // Primary
676 case 0x82: // Primary no-fault
677 case 0x88: // Primary LE
678 case 0x8a: // Primary no-fault LE
685 ret = lduw_raw(T0 & ~1);
688 ret = ldl_raw(T0 & ~3);
692 ret = ldq_raw(T0 & ~7);
697 case 0x81: // Secondary
698 case 0x83: // Secondary no-fault
699 case 0x89: // Secondary LE
700 case 0x8b: // Secondary no-fault LE
707 /* Convert from little endian */
709 case 0x88: // Primary LE
710 case 0x89: // Secondary LE
711 case 0x8a: // Primary no-fault LE
712 case 0x8b: // Secondary no-fault LE
730 /* Convert to signed number */
749 void helper_st_asi(int asi, int size)
752 raise_exception(TT_PRIV_ACT);
754 /* Convert to little endian */
756 case 0x88: // Primary LE
757 case 0x89: // Secondary LE
776 case 0x80: // Primary
777 case 0x88: // Primary LE
784 stw_raw(T0 & ~1, T1);
787 stl_raw(T0 & ~3, T1);
791 stq_raw(T0 & ~7, T1);
796 case 0x81: // Secondary
797 case 0x89: // Secondary LE
801 case 0x82: // Primary no-fault, RO
802 case 0x83: // Secondary no-fault, RO
803 case 0x8a: // Primary no-fault LE, RO
804 case 0x8b: // Secondary no-fault LE, RO
806 do_unassigned_access(T0, 1, 0, 1);
811 #else /* CONFIG_USER_ONLY */
813 void helper_ld_asi(int asi, int size, int sign)
817 if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
818 || (asi >= 0x30 && asi < 0x80 && !(env->hpstate & HS_PRIV)))
819 raise_exception(TT_PRIV_ACT);
822 case 0x10: // As if user primary
823 case 0x18: // As if user primary LE
824 case 0x80: // Primary
825 case 0x82: // Primary no-fault
826 case 0x88: // Primary LE
827 case 0x8a: // Primary no-fault LE
828 if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
829 if (env->hpstate & HS_PRIV) {
835 ret = lduw_hypv(T0 & ~1);
838 ret = ldl_hypv(T0 & ~3);
842 ret = ldq_hypv(T0 & ~7);
848 ret = ldub_kernel(T0);
851 ret = lduw_kernel(T0 & ~1);
854 ret = ldl_kernel(T0 & ~3);
858 ret = ldq_kernel(T0 & ~7);
868 ret = lduw_user(T0 & ~1);
871 ret = ldl_user(T0 & ~3);
875 ret = ldq_user(T0 & ~7);
881 case 0x15: // Bypass, non-cacheable
882 case 0x1c: // Bypass LE
883 case 0x1d: // Bypass, non-cacheable LE
890 ret = lduw_phys(T0 & ~1);
893 ret = ldl_phys(T0 & ~3);
897 ret = ldq_phys(T0 & ~7);
902 case 0x04: // Nucleus
903 case 0x0c: // Nucleus Little Endian (LE)
904 case 0x11: // As if user secondary
905 case 0x19: // As if user secondary LE
906 case 0x24: // Nucleus quad LDD 128 bit atomic
907 case 0x2c: // Nucleus quad LDD 128 bit atomic
908 case 0x4a: // UPA config
909 case 0x81: // Secondary
910 case 0x83: // Secondary no-fault
911 case 0x89: // Secondary LE
912 case 0x8b: // Secondary no-fault LE
918 case 0x50: // I-MMU regs
920 int reg = (T0 >> 3) & 0xf;
922 ret = env->immuregs[reg];
925 case 0x51: // I-MMU 8k TSB pointer
926 case 0x52: // I-MMU 64k TSB pointer
927 case 0x55: // I-MMU data access
930 case 0x56: // I-MMU tag read
934 for (i = 0; i < 64; i++) {
935 // Valid, ctx match, vaddr match
936 if ((env->itlb_tte[i] & 0x8000000000000000ULL) != 0 &&
937 env->itlb_tag[i] == T0) {
938 ret = env->itlb_tag[i];
944 case 0x58: // D-MMU regs
946 int reg = (T0 >> 3) & 0xf;
948 ret = env->dmmuregs[reg];
951 case 0x5e: // D-MMU tag read
955 for (i = 0; i < 64; i++) {
956 // Valid, ctx match, vaddr match
957 if ((env->dtlb_tte[i] & 0x8000000000000000ULL) != 0 &&
958 env->dtlb_tag[i] == T0) {
959 ret = env->dtlb_tag[i];
965 case 0x59: // D-MMU 8k TSB pointer
966 case 0x5a: // D-MMU 64k TSB pointer
967 case 0x5b: // D-MMU data pointer
968 case 0x5d: // D-MMU data access
969 case 0x48: // Interrupt dispatch, RO
970 case 0x49: // Interrupt data receive
971 case 0x7f: // Incoming interrupt vector, RO
974 case 0x54: // I-MMU data in, WO
975 case 0x57: // I-MMU demap, WO
976 case 0x5c: // D-MMU data in, WO
977 case 0x5f: // D-MMU demap, WO
978 case 0x77: // Interrupt vector, WO
980 do_unassigned_access(T0, 0, 0, 1);
985 /* Convert from little endian */
987 case 0x0c: // Nucleus Little Endian (LE)
988 case 0x18: // As if user primary LE
989 case 0x19: // As if user secondary LE
990 case 0x1c: // Bypass LE
991 case 0x1d: // Bypass, non-cacheable LE
992 case 0x88: // Primary LE
993 case 0x89: // Secondary LE
994 case 0x8a: // Primary no-fault LE
995 case 0x8b: // Secondary no-fault LE
1013 /* Convert to signed number */
1020 ret = (int16_t) ret;
1023 ret = (int32_t) ret;
1032 void helper_st_asi(int asi, int size)
1034 if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
1035 || (asi >= 0x30 && asi < 0x80 && !(env->hpstate & HS_PRIV)))
1036 raise_exception(TT_PRIV_ACT);
1038 /* Convert to little endian */
1040 case 0x0c: // Nucleus Little Endian (LE)
1041 case 0x18: // As if user primary LE
1042 case 0x19: // As if user secondary LE
1043 case 0x1c: // Bypass LE
1044 case 0x1d: // Bypass, non-cacheable LE
1045 case 0x88: // Primary LE
1046 case 0x89: // Secondary LE
1065 case 0x10: // As if user primary
1066 case 0x18: // As if user primary LE
1067 case 0x80: // Primary
1068 case 0x88: // Primary LE
1069 if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
1070 if (env->hpstate & HS_PRIV) {
1076 stw_hypv(T0 & ~1, T1);
1079 stl_hypv(T0 & ~3, T1);
1083 stq_hypv(T0 & ~7, T1);
1092 stw_kernel(T0 & ~1, T1);
1095 stl_kernel(T0 & ~3, T1);
1099 stq_kernel(T0 & ~7, T1);
1109 stw_user(T0 & ~1, T1);
1112 stl_user(T0 & ~3, T1);
1116 stq_user(T0 & ~7, T1);
1121 case 0x14: // Bypass
1122 case 0x15: // Bypass, non-cacheable
1123 case 0x1c: // Bypass LE
1124 case 0x1d: // Bypass, non-cacheable LE
1131 stw_phys(T0 & ~1, T1);
1134 stl_phys(T0 & ~3, T1);
1138 stq_phys(T0 & ~7, T1);
1143 case 0x04: // Nucleus
1144 case 0x0c: // Nucleus Little Endian (LE)
1145 case 0x11: // As if user secondary
1146 case 0x19: // As if user secondary LE
1147 case 0x24: // Nucleus quad LDD 128 bit atomic
1148 case 0x2c: // Nucleus quad LDD 128 bit atomic
1149 case 0x4a: // UPA config
1150 case 0x81: // Secondary
1151 case 0x89: // Secondary LE
1159 env->lsu = T1 & (DMMU_E | IMMU_E);
1160 // Mappings generated during D/I MMU disabled mode are
1161 // invalid in normal mode
1162 if (oldreg != env->lsu) {
1163 DPRINTF_MMU("LSU change: 0x%" PRIx64 " -> 0x%" PRIx64 "\n", oldreg, env->lsu);
1171 case 0x50: // I-MMU regs
1173 int reg = (T0 >> 3) & 0xf;
1176 oldreg = env->immuregs[reg];
1181 case 1: // Not in I-MMU
1188 T1 = 0; // Clear SFSR
1190 case 5: // TSB access
1191 case 6: // Tag access
1195 env->immuregs[reg] = T1;
1196 if (oldreg != env->immuregs[reg]) {
1197 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64 " -> 0x%08" PRIx64 "\n", reg, oldreg, env->immuregs[reg]);
1204 case 0x54: // I-MMU data in
1208 // Try finding an invalid entry
1209 for (i = 0; i < 64; i++) {
1210 if ((env->itlb_tte[i] & 0x8000000000000000ULL) == 0) {
1211 env->itlb_tag[i] = env->immuregs[6];
1212 env->itlb_tte[i] = T1;
1216 // Try finding an unlocked entry
1217 for (i = 0; i < 64; i++) {
1218 if ((env->itlb_tte[i] & 0x40) == 0) {
1219 env->itlb_tag[i] = env->immuregs[6];
1220 env->itlb_tte[i] = T1;
1227 case 0x55: // I-MMU data access
1229 unsigned int i = (T0 >> 3) & 0x3f;
1231 env->itlb_tag[i] = env->immuregs[6];
1232 env->itlb_tte[i] = T1;
1235 case 0x57: // I-MMU demap
1238 case 0x58: // D-MMU regs
1240 int reg = (T0 >> 3) & 0xf;
1243 oldreg = env->dmmuregs[reg];
1249 if ((T1 & 1) == 0) {
1250 T1 = 0; // Clear SFSR, Fault address
1251 env->dmmuregs[4] = 0;
1253 env->dmmuregs[reg] = T1;
1255 case 1: // Primary context
1256 case 2: // Secondary context
1257 case 5: // TSB access
1258 case 6: // Tag access
1259 case 7: // Virtual Watchpoint
1260 case 8: // Physical Watchpoint
1264 env->dmmuregs[reg] = T1;
1265 if (oldreg != env->dmmuregs[reg]) {
1266 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64 " -> 0x%08" PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]);
1273 case 0x5c: // D-MMU data in
1277 // Try finding an invalid entry
1278 for (i = 0; i < 64; i++) {
1279 if ((env->dtlb_tte[i] & 0x8000000000000000ULL) == 0) {
1280 env->dtlb_tag[i] = env->dmmuregs[6];
1281 env->dtlb_tte[i] = T1;
1285 // Try finding an unlocked entry
1286 for (i = 0; i < 64; i++) {
1287 if ((env->dtlb_tte[i] & 0x40) == 0) {
1288 env->dtlb_tag[i] = env->dmmuregs[6];
1289 env->dtlb_tte[i] = T1;
1296 case 0x5d: // D-MMU data access
1298 unsigned int i = (T0 >> 3) & 0x3f;
1300 env->dtlb_tag[i] = env->dmmuregs[6];
1301 env->dtlb_tte[i] = T1;
1304 case 0x5f: // D-MMU demap
1305 case 0x49: // Interrupt data receive
1308 case 0x51: // I-MMU 8k TSB pointer, RO
1309 case 0x52: // I-MMU 64k TSB pointer, RO
1310 case 0x56: // I-MMU tag read, RO
1311 case 0x59: // D-MMU 8k TSB pointer, RO
1312 case 0x5a: // D-MMU 64k TSB pointer, RO
1313 case 0x5b: // D-MMU data pointer, RO
1314 case 0x5e: // D-MMU tag read, RO
1315 case 0x48: // Interrupt dispatch, RO
1316 case 0x7f: // Incoming interrupt vector, RO
1317 case 0x82: // Primary no-fault, RO
1318 case 0x83: // Secondary no-fault, RO
1319 case 0x8a: // Primary no-fault LE, RO
1320 case 0x8b: // Secondary no-fault LE, RO
1322 do_unassigned_access(T0, 1, 0, 1);
1326 #endif /* CONFIG_USER_ONLY */
1328 void helper_ldf_asi(int asi, int size, int rd)
1330 target_ulong tmp_T0 = T0, tmp_T1 = T1;
1334 case 0xf0: // Block load primary
1335 case 0xf1: // Block load secondary
1336 case 0xf8: // Block load primary LE
1337 case 0xf9: // Block load secondary LE
1339 raise_exception(TT_ILL_INSN);
1343 raise_exception(TT_UNALIGNED);
1346 for (i = 0; i < 16; i++) {
1347 helper_ld_asi(asi & 0x8f, 4, 0);
1348 *(uint32_t *)&env->fpr[rd++] = T1;
1359 helper_ld_asi(asi, size, 0);
1363 *((uint32_t *)&FT0) = T1;
1366 *((int64_t *)&DT0) = T1;
1372 void helper_stf_asi(int asi, int size, int rd)
1374 target_ulong tmp_T0 = T0, tmp_T1 = T1;
1378 case 0xf0: // Block store primary
1379 case 0xf1: // Block store secondary
1380 case 0xf8: // Block store primary LE
1381 case 0xf9: // Block store secondary LE
1383 raise_exception(TT_ILL_INSN);
1387 raise_exception(TT_UNALIGNED);
1390 for (i = 0; i < 16; i++) {
1391 T1 = *(uint32_t *)&env->fpr[rd++];
1392 helper_st_asi(asi & 0x8f, 4);
1406 T1 = *((uint32_t *)&FT0);
1409 T1 = *((int64_t *)&DT0);
1412 helper_st_asi(asi, size);
1416 #endif /* TARGET_SPARC64 */
1418 #ifndef TARGET_SPARC64
1423 if (env->psret == 1)
1424 raise_exception(TT_ILL_INSN);
1427 cwp = (env->cwp + 1) & (NWINDOWS - 1);
1428 if (env->wim & (1 << cwp)) {
1429 raise_exception(TT_WIN_UNF);
1432 env->psrs = env->psrps;
1436 void helper_ldfsr(void)
1439 switch (env->fsr & FSR_RD_MASK) {
1440 case FSR_RD_NEAREST:
1441 rnd_mode = float_round_nearest_even;
1445 rnd_mode = float_round_to_zero;
1448 rnd_mode = float_round_up;
1451 rnd_mode = float_round_down;
1454 set_float_rounding_mode(rnd_mode, &env->fp_status);
1459 env->exception_index = EXCP_DEBUG;
1463 #ifndef TARGET_SPARC64
1466 if ((T0 & PSR_CWP) >= NWINDOWS)
1467 raise_exception(TT_ILL_INSN);
1484 static inline uint64_t *get_gregset(uint64_t pstate)
1499 static inline void change_pstate(uint64_t new_pstate)
1501 uint64_t pstate_regs, new_pstate_regs;
1502 uint64_t *src, *dst;
1504 pstate_regs = env->pstate & 0xc01;
1505 new_pstate_regs = new_pstate & 0xc01;
1506 if (new_pstate_regs != pstate_regs) {
1507 // Switch global register bank
1508 src = get_gregset(new_pstate_regs);
1509 dst = get_gregset(pstate_regs);
1510 memcpy32(dst, env->gregs);
1511 memcpy32(env->gregs, src);
1513 env->pstate = new_pstate;
1516 void do_wrpstate(void)
1518 change_pstate(T0 & 0xf3f);
1524 env->pc = env->tnpc[env->tl];
1525 env->npc = env->tnpc[env->tl] + 4;
1526 PUT_CCR(env, env->tstate[env->tl] >> 32);
1527 env->asi = (env->tstate[env->tl] >> 24) & 0xff;
1528 change_pstate((env->tstate[env->tl] >> 8) & 0xf3f);
1529 PUT_CWP64(env, env->tstate[env->tl] & 0xff);
1535 env->pc = env->tpc[env->tl];
1536 env->npc = env->tnpc[env->tl];
1537 PUT_CCR(env, env->tstate[env->tl] >> 32);
1538 env->asi = (env->tstate[env->tl] >> 24) & 0xff;
1539 change_pstate((env->tstate[env->tl] >> 8) & 0xf3f);
1540 PUT_CWP64(env, env->tstate[env->tl] & 0xff);
1544 void set_cwp(int new_cwp)
1546 /* put the modified wrap registers at their proper location */
1547 if (env->cwp == (NWINDOWS - 1))
1548 memcpy32(env->regbase, env->regbase + NWINDOWS * 16);
1550 /* put the wrap registers at their temporary location */
1551 if (new_cwp == (NWINDOWS - 1))
1552 memcpy32(env->regbase + NWINDOWS * 16, env->regbase);
1553 env->regwptr = env->regbase + (new_cwp * 16);
1554 REGWPTR = env->regwptr;
1557 void cpu_set_cwp(CPUState *env1, int new_cwp)
1559 CPUState *saved_env;
1561 target_ulong *saved_regwptr;
1566 saved_regwptr = REGWPTR;
1572 REGWPTR = saved_regwptr;
1576 #ifdef TARGET_SPARC64
1577 void do_interrupt(int intno)
1580 if (loglevel & CPU_LOG_INT) {
1582 fprintf(logfile, "%6d: v=%04x pc=%016" PRIx64 " npc=%016" PRIx64 " SP=%016" PRIx64 "\n",
1585 env->npc, env->regwptr[6]);
1586 cpu_dump_state(env, logfile, fprintf, 0);
1592 fprintf(logfile, " code=");
1593 ptr = (uint8_t *)env->pc;
1594 for(i = 0; i < 16; i++) {
1595 fprintf(logfile, " %02x", ldub(ptr + i));
1597 fprintf(logfile, "\n");
1603 #if !defined(CONFIG_USER_ONLY)
1604 if (env->tl == MAXTL) {
1605 cpu_abort(env, "Trap 0x%04x while trap level is MAXTL, Error state", env->exception_index);
1609 env->tstate[env->tl] = ((uint64_t)GET_CCR(env) << 32) | ((env->asi & 0xff) << 24) |
1610 ((env->pstate & 0xf3f) << 8) | GET_CWP64(env);
1611 env->tpc[env->tl] = env->pc;
1612 env->tnpc[env->tl] = env->npc;
1613 env->tt[env->tl] = intno;
1614 change_pstate(PS_PEF | PS_PRIV | PS_AG);
1616 if (intno == TT_CLRWIN)
1617 set_cwp((env->cwp - 1) & (NWINDOWS - 1));
1618 else if ((intno & 0x1c0) == TT_SPILL)
1619 set_cwp((env->cwp - env->cansave - 2) & (NWINDOWS - 1));
1620 else if ((intno & 0x1c0) == TT_FILL)
1621 set_cwp((env->cwp + 1) & (NWINDOWS - 1));
1622 env->tbr &= ~0x7fffULL;
1623 env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
1624 if (env->tl < MAXTL - 1) {
1627 env->pstate |= PS_RED;
1628 if (env->tl != MAXTL)
1632 env->npc = env->pc + 4;
1633 env->exception_index = 0;
1636 void do_interrupt(int intno)
1641 if (loglevel & CPU_LOG_INT) {
1643 fprintf(logfile, "%6d: v=%02x pc=%08x npc=%08x SP=%08x\n",
1646 env->npc, env->regwptr[6]);
1647 cpu_dump_state(env, logfile, fprintf, 0);
1653 fprintf(logfile, " code=");
1654 ptr = (uint8_t *)env->pc;
1655 for(i = 0; i < 16; i++) {
1656 fprintf(logfile, " %02x", ldub(ptr + i));
1658 fprintf(logfile, "\n");
1664 #if !defined(CONFIG_USER_ONLY)
1665 if (env->psret == 0) {
1666 cpu_abort(env, "Trap 0x%02x while interrupts disabled, Error state", env->exception_index);
1671 cwp = (env->cwp - 1) & (NWINDOWS - 1);
1673 env->regwptr[9] = env->pc;
1674 env->regwptr[10] = env->npc;
1675 env->psrps = env->psrs;
1677 env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4);
1679 env->npc = env->pc + 4;
1680 env->exception_index = 0;
1684 #if !defined(CONFIG_USER_ONLY)
1686 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
1689 #define MMUSUFFIX _mmu
1690 #define ALIGNED_ONLY
1692 # define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL))
1694 # define GETPC() (__builtin_return_address(0))
1698 #include "softmmu_template.h"
1701 #include "softmmu_template.h"
1704 #include "softmmu_template.h"
1707 #include "softmmu_template.h"
1709 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
1712 #ifdef DEBUG_UNALIGNED
1713 printf("Unaligned access to 0x%x from 0x%x\n", addr, env->pc);
1715 raise_exception(TT_UNALIGNED);
1718 /* try to fill the TLB and return an exception if error. If retaddr is
1719 NULL, it means that the function was called in C code (i.e. not
1720 from generated code or from helper.c) */
1721 /* XXX: fix it to restore all registers */
1722 void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)
1724 TranslationBlock *tb;
1727 CPUState *saved_env;
1729 /* XXX: hack to restore env in all cases, even if not called from
1732 env = cpu_single_env;
1734 ret = cpu_sparc_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
1737 /* now we have a real cpu fault */
1738 pc = (unsigned long)retaddr;
1739 tb = tb_find_pc(pc);
1741 /* the PC is inside the translated code. It means that we have
1742 a virtual CPU fault */
1743 cpu_restore_state(tb, env, pc, (void *)T2);
1753 #ifndef TARGET_SPARC64
1754 void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
1757 CPUState *saved_env;
1759 /* XXX: hack to restore env in all cases, even if not called from
1762 env = cpu_single_env;
1763 if (env->mmuregs[3]) /* Fault status register */
1764 env->mmuregs[3] = 1; /* overflow (not read before another fault) */
1766 env->mmuregs[3] |= 1 << 16;
1768 env->mmuregs[3] |= 1 << 5;
1770 env->mmuregs[3] |= 1 << 6;
1772 env->mmuregs[3] |= 1 << 7;
1773 env->mmuregs[3] |= (5 << 2) | 2;
1774 env->mmuregs[4] = addr; /* Fault address register */
1775 if ((env->mmuregs[0] & MMU_E) && !(env->mmuregs[0] & MMU_NF)) {
1776 #ifdef DEBUG_UNASSIGNED
1777 printf("Unassigned mem access to " TARGET_FMT_plx " from " TARGET_FMT_lx
1778 "\n", addr, env->pc);
1781 raise_exception(TT_CODE_ACCESS);
1783 raise_exception(TT_DATA_ACCESS);
1788 void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
1791 #ifdef DEBUG_UNASSIGNED
1792 CPUState *saved_env;
1794 /* XXX: hack to restore env in all cases, even if not called from
1797 env = cpu_single_env;
1798 printf("Unassigned mem access to " TARGET_FMT_plx " from " TARGET_FMT_lx "\n",
1803 raise_exception(TT_CODE_ACCESS);
1805 raise_exception(TT_DATA_ACCESS);
1809 #ifdef TARGET_SPARC64
1810 void do_tick_set_count(void *opaque, uint64_t count)
1812 #if !defined(CONFIG_USER_ONLY)
1813 ptimer_set_count(opaque, -count);
1817 uint64_t do_tick_get_count(void *opaque)
1819 #if !defined(CONFIG_USER_ONLY)
1820 return -ptimer_get_count(opaque);
1826 void do_tick_set_limit(void *opaque, uint64_t limit)
1828 #if !defined(CONFIG_USER_ONLY)
1829 ptimer_set_limit(opaque, -limit, 0);