]>
git.proxmox.com Git - mirror_qemu.git/blob - target-sparc/op_helper.c
2 #include "host-utils.h"
7 //#define DEBUG_UNALIGNED
8 //#define DEBUG_UNASSIGNED
12 #define DPRINTF_MMU(fmt, args...) \
13 do { printf("MMU: " fmt , ##args); } while (0)
15 #define DPRINTF_MMU(fmt, args...)
19 #define DPRINTF_MXCC(fmt, args...) \
20 do { printf("MXCC: " fmt , ##args); } while (0)
22 #define DPRINTF_MXCC(fmt, args...)
26 #define DPRINTF_ASI(fmt, args...) \
27 do { printf("ASI: " fmt , ##args); } while (0)
29 #define DPRINTF_ASI(fmt, args...)
32 void raise_exception(int tt
)
34 env
->exception_index
= tt
;
38 void check_ieee_exceptions()
40 T0
= get_float_exception_flags(&env
->fp_status
);
43 /* Copy IEEE 754 flags into FSR */
44 if (T0
& float_flag_invalid
)
46 if (T0
& float_flag_overflow
)
48 if (T0
& float_flag_underflow
)
50 if (T0
& float_flag_divbyzero
)
52 if (T0
& float_flag_inexact
)
55 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23))
57 /* Unmasked exception, generate a trap */
58 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
59 raise_exception(TT_FP_EXCP
);
63 /* Accumulate exceptions */
64 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
69 #ifdef USE_INT_TO_FLOAT_HELPERS
72 set_float_exception_flags(0, &env
->fp_status
);
73 FT0
= int32_to_float32(*((int32_t *)&FT1
), &env
->fp_status
);
74 check_ieee_exceptions();
79 DT0
= int32_to_float64(*((int32_t *)&FT1
), &env
->fp_status
);
82 #if defined(CONFIG_USER_ONLY)
85 QT0
= int32_to_float128(*((int32_t *)&FT1
), &env
->fp_status
);
92 set_float_exception_flags(0, &env
->fp_status
);
93 FT0
= int64_to_float32(*((int64_t *)&DT1
), &env
->fp_status
);
94 check_ieee_exceptions();
99 set_float_exception_flags(0, &env
->fp_status
);
100 DT0
= int64_to_float64(*((int64_t *)&DT1
), &env
->fp_status
);
101 check_ieee_exceptions();
104 #if defined(CONFIG_USER_ONLY)
107 set_float_exception_flags(0, &env
->fp_status
);
108 QT0
= int64_to_float128(*((int32_t *)&DT1
), &env
->fp_status
);
109 check_ieee_exceptions();
117 FT0
= float32_abs(FT1
);
120 #ifdef TARGET_SPARC64
123 DT0
= float64_abs(DT1
);
126 #if defined(CONFIG_USER_ONLY)
129 QT0
= float128_abs(QT1
);
136 set_float_exception_flags(0, &env
->fp_status
);
137 FT0
= float32_sqrt(FT1
, &env
->fp_status
);
138 check_ieee_exceptions();
143 set_float_exception_flags(0, &env
->fp_status
);
144 DT0
= float64_sqrt(DT1
, &env
->fp_status
);
145 check_ieee_exceptions();
148 #if defined(CONFIG_USER_ONLY)
151 set_float_exception_flags(0, &env
->fp_status
);
152 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
153 check_ieee_exceptions();
157 #define GEN_FCMP(name, size, reg1, reg2, FS, TRAP) \
158 void glue(do_, name) (void) \
160 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
161 switch (glue(size, _compare) (reg1, reg2, &env->fp_status)) { \
162 case float_relation_unordered: \
163 T0 = (FSR_FCC1 | FSR_FCC0) << FS; \
164 if ((env->fsr & FSR_NVM) || TRAP) { \
166 env->fsr |= FSR_NVC; \
167 env->fsr |= FSR_FTT_IEEE_EXCP; \
168 raise_exception(TT_FP_EXCP); \
170 env->fsr |= FSR_NVA; \
173 case float_relation_less: \
174 T0 = FSR_FCC0 << FS; \
176 case float_relation_greater: \
177 T0 = FSR_FCC1 << FS; \
186 GEN_FCMP(fcmps
, float32
, FT0
, FT1
, 0, 0);
187 GEN_FCMP(fcmpd
, float64
, DT0
, DT1
, 0, 0);
189 GEN_FCMP(fcmpes
, float32
, FT0
, FT1
, 0, 1);
190 GEN_FCMP(fcmped
, float64
, DT0
, DT1
, 0, 1);
192 #ifdef CONFIG_USER_ONLY
193 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
194 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
197 #ifdef TARGET_SPARC64
198 GEN_FCMP(fcmps_fcc1
, float32
, FT0
, FT1
, 22, 0);
199 GEN_FCMP(fcmpd_fcc1
, float64
, DT0
, DT1
, 22, 0);
201 GEN_FCMP(fcmps_fcc2
, float32
, FT0
, FT1
, 24, 0);
202 GEN_FCMP(fcmpd_fcc2
, float64
, DT0
, DT1
, 24, 0);
204 GEN_FCMP(fcmps_fcc3
, float32
, FT0
, FT1
, 26, 0);
205 GEN_FCMP(fcmpd_fcc3
, float64
, DT0
, DT1
, 26, 0);
207 GEN_FCMP(fcmpes_fcc1
, float32
, FT0
, FT1
, 22, 1);
208 GEN_FCMP(fcmped_fcc1
, float64
, DT0
, DT1
, 22, 1);
210 GEN_FCMP(fcmpes_fcc2
, float32
, FT0
, FT1
, 24, 1);
211 GEN_FCMP(fcmped_fcc2
, float64
, DT0
, DT1
, 24, 1);
213 GEN_FCMP(fcmpes_fcc3
, float32
, FT0
, FT1
, 26, 1);
214 GEN_FCMP(fcmped_fcc3
, float64
, DT0
, DT1
, 26, 1);
215 #ifdef CONFIG_USER_ONLY
216 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
217 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
218 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
219 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
220 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
221 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
225 #ifndef TARGET_SPARC64
226 #ifndef CONFIG_USER_ONLY
229 static void dump_mxcc(CPUState
*env
)
231 printf("mxccdata: %016llx %016llx %016llx %016llx\n",
232 env
->mxccdata
[0], env
->mxccdata
[1], env
->mxccdata
[2], env
->mxccdata
[3]);
233 printf("mxccregs: %016llx %016llx %016llx %016llx\n"
234 " %016llx %016llx %016llx %016llx\n",
235 env
->mxccregs
[0], env
->mxccregs
[1], env
->mxccregs
[2], env
->mxccregs
[3],
236 env
->mxccregs
[4], env
->mxccregs
[5], env
->mxccregs
[6], env
->mxccregs
[7]);
241 static void dump_asi(const char * txt
, uint32_t addr
, int asi
, int size
,
242 uint32_t r1
, uint32_t r2
)
247 DPRINTF_ASI("%s %08x asi 0x%02x = %02x\n", txt
, addr
, asi
, r1
& 0xff);
250 DPRINTF_ASI("%s %08x asi 0x%02x = %04x\n", txt
, addr
, asi
, r1
& 0xffff);
253 DPRINTF_ASI("%s %08x asi 0x%02x = %08x\n", txt
, addr
, asi
, r1
);
256 DPRINTF_ASI("%s %08x asi 0x%02x = %016llx\n", txt
, addr
, asi
,
257 r2
| ((uint64_t)r1
<< 32));
263 void helper_ld_asi(int asi
, int size
, int sign
)
267 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
268 uint32_t last_T0
= T0
;
272 case 2: /* SuperSparc MXCC registers */
274 case 0x01c00a00: /* MXCC control register */
276 ret
= env
->mxccregs
[3] >> 32;
277 T0
= env
->mxccregs
[3];
279 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
281 case 0x01c00a04: /* MXCC control register */
283 ret
= env
->mxccregs
[3];
285 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
287 case 0x01c00c00: /* Module reset register */
289 ret
= env
->mxccregs
[5] >> 32;
290 T0
= env
->mxccregs
[5];
291 // should we do something here?
293 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
295 case 0x01c00f00: /* MBus port address register */
297 ret
= env
->mxccregs
[7] >> 32;
298 T0
= env
->mxccregs
[7];
300 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
303 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", T0
, size
);
306 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, T0 = %08x -> ret = %08x,"
307 "T0 = %08x\n", asi
, size
, sign
, last_T0
, ret
, T0
);
312 case 3: /* MMU probe */
316 mmulev
= (T0
>> 8) & 15;
320 ret
= mmu_probe(env
, T0
, mmulev
);
323 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08x\n", T0
, mmulev
, ret
);
326 case 4: /* read MMU regs */
328 int reg
= (T0
>> 8) & 0x1f;
330 ret
= env
->mmuregs
[reg
];
331 if (reg
== 3) /* Fault status cleared on read */
333 else if (reg
== 0x13) /* Fault status read */
334 ret
= env
->mmuregs
[3];
335 else if (reg
== 0x14) /* Fault address read */
336 ret
= env
->mmuregs
[4];
337 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08x\n", reg
, ret
);
340 case 9: /* Supervisor code access */
346 ret
= lduw_code(T0
& ~1);
350 ret
= ldl_code(T0
& ~3);
353 tmp
= ldq_code(T0
& ~7);
359 case 0xa: /* User data access */
365 ret
= lduw_user(T0
& ~1);
369 ret
= ldl_user(T0
& ~3);
372 tmp
= ldq_user(T0
& ~7);
378 case 0xb: /* Supervisor data access */
381 ret
= ldub_kernel(T0
);
384 ret
= lduw_kernel(T0
& ~1);
388 ret
= ldl_kernel(T0
& ~3);
391 tmp
= ldq_kernel(T0
& ~7);
397 case 0xc: /* I-cache tag */
398 case 0xd: /* I-cache data */
399 case 0xe: /* D-cache tag */
400 case 0xf: /* D-cache data */
402 case 0x20: /* MMU passthrough */
408 ret
= lduw_phys(T0
& ~1);
412 ret
= ldl_phys(T0
& ~3);
415 tmp
= ldq_phys(T0
& ~7);
421 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
424 ret
= ldub_phys((target_phys_addr_t
)T0
425 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
428 ret
= lduw_phys((target_phys_addr_t
)(T0
& ~1)
429 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
433 ret
= ldl_phys((target_phys_addr_t
)(T0
& ~3)
434 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
437 tmp
= ldq_phys((target_phys_addr_t
)(T0
& ~7)
438 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
444 case 0x39: /* data cache diagnostic register */
448 do_unassigned_access(T0
, 0, 0, asi
);
468 dump_asi("read ", last_T0
, asi
, size
, T1
, T0
);
472 void helper_st_asi(int asi
, int size
)
475 case 2: /* SuperSparc MXCC registers */
477 case 0x01c00000: /* MXCC stream data register 0 */
479 env
->mxccdata
[0] = ((uint64_t)T1
<< 32) | T2
;
481 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
483 case 0x01c00008: /* MXCC stream data register 1 */
485 env
->mxccdata
[1] = ((uint64_t)T1
<< 32) | T2
;
487 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
489 case 0x01c00010: /* MXCC stream data register 2 */
491 env
->mxccdata
[2] = ((uint64_t)T1
<< 32) | T2
;
493 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
495 case 0x01c00018: /* MXCC stream data register 3 */
497 env
->mxccdata
[3] = ((uint64_t)T1
<< 32) | T2
;
499 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
501 case 0x01c00100: /* MXCC stream source */
503 env
->mxccregs
[0] = ((uint64_t)T1
<< 32) | T2
;
505 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
506 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 0);
507 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 8);
508 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 16);
509 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) + 24);
511 case 0x01c00200: /* MXCC stream destination */
513 env
->mxccregs
[1] = ((uint64_t)T1
<< 32) | T2
;
515 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
516 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0, env
->mxccdata
[0]);
517 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8, env
->mxccdata
[1]);
518 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16, env
->mxccdata
[2]);
519 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24, env
->mxccdata
[3]);
521 case 0x01c00a00: /* MXCC control register */
523 env
->mxccregs
[3] = ((uint64_t)T1
<< 32) | T2
;
525 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
527 case 0x01c00a04: /* MXCC control register */
529 env
->mxccregs
[3] = (env
->mxccregs
[0xa] & 0xffffffff00000000ULL
) | T1
;
531 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
533 case 0x01c00e00: /* MXCC error register */
534 // writing a 1 bit clears the error
536 env
->mxccregs
[6] &= ~(((uint64_t)T1
<< 32) | T2
);
538 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
540 case 0x01c00f00: /* MBus port address register */
542 env
->mxccregs
[7] = ((uint64_t)T1
<< 32) | T2
;
544 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", T0
, size
);
547 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", T0
, size
);
550 DPRINTF_MXCC("asi = %d, size = %d, T0 = %08x, T1 = %08x\n", asi
, size
, T0
, T1
);
555 case 3: /* MMU flush */
559 mmulev
= (T0
>> 8) & 15;
560 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
562 case 0: // flush page
563 tlb_flush_page(env
, T0
& 0xfffff000);
565 case 1: // flush segment (256k)
566 case 2: // flush region (16M)
567 case 3: // flush context (4G)
568 case 4: // flush entire
579 case 4: /* write MMU regs */
581 int reg
= (T0
>> 8) & 0x1f;
584 oldreg
= env
->mmuregs
[reg
];
587 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
589 // Mappings generated during no-fault mode or MMU
590 // disabled mode are invalid in normal mode
591 if ((oldreg
& (MMU_E
| MMU_NF
| env
->mmu_bm
)) !=
592 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->mmu_bm
)))
596 env
->mmuregs
[reg
] = T1
;
597 if (oldreg
!= env
->mmuregs
[reg
]) {
598 /* we flush when the MMU context changes because
599 QEMU has no MMU context support */
607 env
->mmuregs
[3] = T1
;
610 env
->mmuregs
[4] = T1
;
613 env
->mmuregs
[reg
] = T1
;
616 if (oldreg
!= env
->mmuregs
[reg
]) {
617 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n", reg
, oldreg
, env
->mmuregs
[reg
]);
624 case 0xa: /* User data access */
630 stw_user(T0
& ~1, T1
);
634 stl_user(T0
& ~3, T1
);
637 stq_user(T0
& ~7, ((uint64_t)T1
<< 32) | T2
);
641 case 0xb: /* Supervisor data access */
647 stw_kernel(T0
& ~1, T1
);
651 stl_kernel(T0
& ~3, T1
);
654 stq_kernel(T0
& ~7, ((uint64_t)T1
<< 32) | T2
);
658 case 0xc: /* I-cache tag */
659 case 0xd: /* I-cache data */
660 case 0xe: /* D-cache tag */
661 case 0xf: /* D-cache data */
662 case 0x10: /* I/D-cache flush page */
663 case 0x11: /* I/D-cache flush segment */
664 case 0x12: /* I/D-cache flush region */
665 case 0x13: /* I/D-cache flush context */
666 case 0x14: /* I/D-cache flush user */
668 case 0x17: /* Block copy, sta access */
671 // address (T0) = dst
674 uint32_t src
= T1
& ~3, dst
= T0
& ~3, temp
;
676 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
677 temp
= ldl_kernel(src
);
678 stl_kernel(dst
, temp
);
682 case 0x1f: /* Block fill, stda access */
685 // address (T0) = dst
688 uint32_t dst
= T0
& 7;
691 val
= (((uint64_t)T1
) << 32) | T2
;
693 for (i
= 0; i
< 32; i
+= 8, dst
+= 8)
694 stq_kernel(dst
, val
);
697 case 0x20: /* MMU passthrough */
704 stw_phys(T0
& ~1, T1
);
708 stl_phys(T0
& ~3, T1
);
711 stq_phys(T0
& ~7, ((uint64_t)T1
<< 32) | T2
);
716 case 0x2e: /* MMU passthrough, 0xexxxxxxxx */
717 case 0x2f: /* MMU passthrough, 0xfxxxxxxxx */
721 stb_phys((target_phys_addr_t
)T0
722 | ((target_phys_addr_t
)(asi
& 0xf) << 32), T1
);
725 stw_phys((target_phys_addr_t
)(T0
& ~1)
726 | ((target_phys_addr_t
)(asi
& 0xf) << 32), T1
);
730 stl_phys((target_phys_addr_t
)(T0
& ~3)
731 | ((target_phys_addr_t
)(asi
& 0xf) << 32), T1
);
734 stq_phys((target_phys_addr_t
)(T0
& ~7)
735 | ((target_phys_addr_t
)(asi
& 0xf) << 32),
736 ((uint64_t)T1
<< 32) | T2
);
741 case 0x30: /* store buffer tags */
742 case 0x31: /* store buffer data or Ross RT620 I-cache flush */
743 case 0x32: /* store buffer control */
744 case 0x36: /* I-cache flash clear */
745 case 0x37: /* D-cache flash clear */
746 case 0x38: /* breakpoint diagnostics */
747 case 0x4c: /* breakpoint action */
749 case 9: /* Supervisor code access, XXX */
750 case 0x21 ... 0x2d: /* MMU passthrough, unassigned */
752 do_unassigned_access(T0
, 1, 0, asi
);
756 dump_asi("write", T0
, asi
, size
, T1
, T2
);
760 #endif /* CONFIG_USER_ONLY */
761 #else /* TARGET_SPARC64 */
763 #ifdef CONFIG_USER_ONLY
764 void helper_ld_asi(int asi
, int size
, int sign
)
769 raise_exception(TT_PRIV_ACT
);
772 case 0x80: // Primary
773 case 0x82: // Primary no-fault
774 case 0x88: // Primary LE
775 case 0x8a: // Primary no-fault LE
782 ret
= lduw_raw(T0
& ~1);
785 ret
= ldl_raw(T0
& ~3);
789 ret
= ldq_raw(T0
& ~7);
794 case 0x81: // Secondary
795 case 0x83: // Secondary no-fault
796 case 0x89: // Secondary LE
797 case 0x8b: // Secondary no-fault LE
804 /* Convert from little endian */
806 case 0x88: // Primary LE
807 case 0x89: // Secondary LE
808 case 0x8a: // Primary no-fault LE
809 case 0x8b: // Secondary no-fault LE
827 /* Convert to signed number */
846 void helper_st_asi(int asi
, int size
)
849 raise_exception(TT_PRIV_ACT
);
851 /* Convert to little endian */
853 case 0x88: // Primary LE
854 case 0x89: // Secondary LE
873 case 0x80: // Primary
874 case 0x88: // Primary LE
881 stw_raw(T0
& ~1, T1
);
884 stl_raw(T0
& ~3, T1
);
888 stq_raw(T0
& ~7, T1
);
893 case 0x81: // Secondary
894 case 0x89: // Secondary LE
898 case 0x82: // Primary no-fault, RO
899 case 0x83: // Secondary no-fault, RO
900 case 0x8a: // Primary no-fault LE, RO
901 case 0x8b: // Secondary no-fault LE, RO
903 do_unassigned_access(T0
, 1, 0, 1);
908 #else /* CONFIG_USER_ONLY */
910 void helper_ld_asi(int asi
, int size
, int sign
)
914 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
915 || (asi
>= 0x30 && asi
< 0x80 && !(env
->hpstate
& HS_PRIV
)))
916 raise_exception(TT_PRIV_ACT
);
919 case 0x10: // As if user primary
920 case 0x18: // As if user primary LE
921 case 0x80: // Primary
922 case 0x82: // Primary no-fault
923 case 0x88: // Primary LE
924 case 0x8a: // Primary no-fault LE
925 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
926 if (env
->hpstate
& HS_PRIV
) {
932 ret
= lduw_hypv(T0
& ~1);
935 ret
= ldl_hypv(T0
& ~3);
939 ret
= ldq_hypv(T0
& ~7);
945 ret
= ldub_kernel(T0
);
948 ret
= lduw_kernel(T0
& ~1);
951 ret
= ldl_kernel(T0
& ~3);
955 ret
= ldq_kernel(T0
& ~7);
965 ret
= lduw_user(T0
& ~1);
968 ret
= ldl_user(T0
& ~3);
972 ret
= ldq_user(T0
& ~7);
978 case 0x15: // Bypass, non-cacheable
979 case 0x1c: // Bypass LE
980 case 0x1d: // Bypass, non-cacheable LE
987 ret
= lduw_phys(T0
& ~1);
990 ret
= ldl_phys(T0
& ~3);
994 ret
= ldq_phys(T0
& ~7);
999 case 0x04: // Nucleus
1000 case 0x0c: // Nucleus Little Endian (LE)
1001 case 0x11: // As if user secondary
1002 case 0x19: // As if user secondary LE
1003 case 0x24: // Nucleus quad LDD 128 bit atomic
1004 case 0x2c: // Nucleus quad LDD 128 bit atomic
1005 case 0x4a: // UPA config
1006 case 0x81: // Secondary
1007 case 0x83: // Secondary no-fault
1008 case 0x89: // Secondary LE
1009 case 0x8b: // Secondary no-fault LE
1015 case 0x50: // I-MMU regs
1017 int reg
= (T0
>> 3) & 0xf;
1019 ret
= env
->immuregs
[reg
];
1022 case 0x51: // I-MMU 8k TSB pointer
1023 case 0x52: // I-MMU 64k TSB pointer
1024 case 0x55: // I-MMU data access
1027 case 0x56: // I-MMU tag read
1031 for (i
= 0; i
< 64; i
++) {
1032 // Valid, ctx match, vaddr match
1033 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) != 0 &&
1034 env
->itlb_tag
[i
] == T0
) {
1035 ret
= env
->itlb_tag
[i
];
1041 case 0x58: // D-MMU regs
1043 int reg
= (T0
>> 3) & 0xf;
1045 ret
= env
->dmmuregs
[reg
];
1048 case 0x5e: // D-MMU tag read
1052 for (i
= 0; i
< 64; i
++) {
1053 // Valid, ctx match, vaddr match
1054 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) != 0 &&
1055 env
->dtlb_tag
[i
] == T0
) {
1056 ret
= env
->dtlb_tag
[i
];
1062 case 0x59: // D-MMU 8k TSB pointer
1063 case 0x5a: // D-MMU 64k TSB pointer
1064 case 0x5b: // D-MMU data pointer
1065 case 0x5d: // D-MMU data access
1066 case 0x48: // Interrupt dispatch, RO
1067 case 0x49: // Interrupt data receive
1068 case 0x7f: // Incoming interrupt vector, RO
1071 case 0x54: // I-MMU data in, WO
1072 case 0x57: // I-MMU demap, WO
1073 case 0x5c: // D-MMU data in, WO
1074 case 0x5f: // D-MMU demap, WO
1075 case 0x77: // Interrupt vector, WO
1077 do_unassigned_access(T0
, 0, 0, 1);
1082 /* Convert from little endian */
1084 case 0x0c: // Nucleus Little Endian (LE)
1085 case 0x18: // As if user primary LE
1086 case 0x19: // As if user secondary LE
1087 case 0x1c: // Bypass LE
1088 case 0x1d: // Bypass, non-cacheable LE
1089 case 0x88: // Primary LE
1090 case 0x89: // Secondary LE
1091 case 0x8a: // Primary no-fault LE
1092 case 0x8b: // Secondary no-fault LE
1110 /* Convert to signed number */
1117 ret
= (int16_t) ret
;
1120 ret
= (int32_t) ret
;
1129 void helper_st_asi(int asi
, int size
)
1131 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1132 || (asi
>= 0x30 && asi
< 0x80 && !(env
->hpstate
& HS_PRIV
)))
1133 raise_exception(TT_PRIV_ACT
);
1135 /* Convert to little endian */
1137 case 0x0c: // Nucleus Little Endian (LE)
1138 case 0x18: // As if user primary LE
1139 case 0x19: // As if user secondary LE
1140 case 0x1c: // Bypass LE
1141 case 0x1d: // Bypass, non-cacheable LE
1142 case 0x88: // Primary LE
1143 case 0x89: // Secondary LE
1162 case 0x10: // As if user primary
1163 case 0x18: // As if user primary LE
1164 case 0x80: // Primary
1165 case 0x88: // Primary LE
1166 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1167 if (env
->hpstate
& HS_PRIV
) {
1173 stw_hypv(T0
& ~1, T1
);
1176 stl_hypv(T0
& ~3, T1
);
1180 stq_hypv(T0
& ~7, T1
);
1189 stw_kernel(T0
& ~1, T1
);
1192 stl_kernel(T0
& ~3, T1
);
1196 stq_kernel(T0
& ~7, T1
);
1206 stw_user(T0
& ~1, T1
);
1209 stl_user(T0
& ~3, T1
);
1213 stq_user(T0
& ~7, T1
);
1218 case 0x14: // Bypass
1219 case 0x15: // Bypass, non-cacheable
1220 case 0x1c: // Bypass LE
1221 case 0x1d: // Bypass, non-cacheable LE
1228 stw_phys(T0
& ~1, T1
);
1231 stl_phys(T0
& ~3, T1
);
1235 stq_phys(T0
& ~7, T1
);
1240 case 0x04: // Nucleus
1241 case 0x0c: // Nucleus Little Endian (LE)
1242 case 0x11: // As if user secondary
1243 case 0x19: // As if user secondary LE
1244 case 0x24: // Nucleus quad LDD 128 bit atomic
1245 case 0x2c: // Nucleus quad LDD 128 bit atomic
1246 case 0x4a: // UPA config
1247 case 0x81: // Secondary
1248 case 0x89: // Secondary LE
1256 env
->lsu
= T1
& (DMMU_E
| IMMU_E
);
1257 // Mappings generated during D/I MMU disabled mode are
1258 // invalid in normal mode
1259 if (oldreg
!= env
->lsu
) {
1260 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n", oldreg
, env
->lsu
);
1268 case 0x50: // I-MMU regs
1270 int reg
= (T0
>> 3) & 0xf;
1273 oldreg
= env
->immuregs
[reg
];
1278 case 1: // Not in I-MMU
1285 T1
= 0; // Clear SFSR
1287 case 5: // TSB access
1288 case 6: // Tag access
1292 env
->immuregs
[reg
] = T1
;
1293 if (oldreg
!= env
->immuregs
[reg
]) {
1294 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08" PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1301 case 0x54: // I-MMU data in
1305 // Try finding an invalid entry
1306 for (i
= 0; i
< 64; i
++) {
1307 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
1308 env
->itlb_tag
[i
] = env
->immuregs
[6];
1309 env
->itlb_tte
[i
] = T1
;
1313 // Try finding an unlocked entry
1314 for (i
= 0; i
< 64; i
++) {
1315 if ((env
->itlb_tte
[i
] & 0x40) == 0) {
1316 env
->itlb_tag
[i
] = env
->immuregs
[6];
1317 env
->itlb_tte
[i
] = T1
;
1324 case 0x55: // I-MMU data access
1326 unsigned int i
= (T0
>> 3) & 0x3f;
1328 env
->itlb_tag
[i
] = env
->immuregs
[6];
1329 env
->itlb_tte
[i
] = T1
;
1332 case 0x57: // I-MMU demap
1335 case 0x58: // D-MMU regs
1337 int reg
= (T0
>> 3) & 0xf;
1340 oldreg
= env
->dmmuregs
[reg
];
1346 if ((T1
& 1) == 0) {
1347 T1
= 0; // Clear SFSR, Fault address
1348 env
->dmmuregs
[4] = 0;
1350 env
->dmmuregs
[reg
] = T1
;
1352 case 1: // Primary context
1353 case 2: // Secondary context
1354 case 5: // TSB access
1355 case 6: // Tag access
1356 case 7: // Virtual Watchpoint
1357 case 8: // Physical Watchpoint
1361 env
->dmmuregs
[reg
] = T1
;
1362 if (oldreg
!= env
->dmmuregs
[reg
]) {
1363 DPRINTF_MMU("mmu change reg[%d]: 0x%08" PRIx64
" -> 0x%08" PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1370 case 0x5c: // D-MMU data in
1374 // Try finding an invalid entry
1375 for (i
= 0; i
< 64; i
++) {
1376 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0) {
1377 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
1378 env
->dtlb_tte
[i
] = T1
;
1382 // Try finding an unlocked entry
1383 for (i
= 0; i
< 64; i
++) {
1384 if ((env
->dtlb_tte
[i
] & 0x40) == 0) {
1385 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
1386 env
->dtlb_tte
[i
] = T1
;
1393 case 0x5d: // D-MMU data access
1395 unsigned int i
= (T0
>> 3) & 0x3f;
1397 env
->dtlb_tag
[i
] = env
->dmmuregs
[6];
1398 env
->dtlb_tte
[i
] = T1
;
1401 case 0x5f: // D-MMU demap
1402 case 0x49: // Interrupt data receive
1405 case 0x51: // I-MMU 8k TSB pointer, RO
1406 case 0x52: // I-MMU 64k TSB pointer, RO
1407 case 0x56: // I-MMU tag read, RO
1408 case 0x59: // D-MMU 8k TSB pointer, RO
1409 case 0x5a: // D-MMU 64k TSB pointer, RO
1410 case 0x5b: // D-MMU data pointer, RO
1411 case 0x5e: // D-MMU tag read, RO
1412 case 0x48: // Interrupt dispatch, RO
1413 case 0x7f: // Incoming interrupt vector, RO
1414 case 0x82: // Primary no-fault, RO
1415 case 0x83: // Secondary no-fault, RO
1416 case 0x8a: // Primary no-fault LE, RO
1417 case 0x8b: // Secondary no-fault LE, RO
1419 do_unassigned_access(T0
, 1, 0, 1);
1423 #endif /* CONFIG_USER_ONLY */
1425 void helper_ldf_asi(int asi
, int size
, int rd
)
1427 target_ulong tmp_T0
= T0
, tmp_T1
= T1
;
1431 case 0xf0: // Block load primary
1432 case 0xf1: // Block load secondary
1433 case 0xf8: // Block load primary LE
1434 case 0xf9: // Block load secondary LE
1436 raise_exception(TT_ILL_INSN
);
1440 raise_exception(TT_UNALIGNED
);
1443 for (i
= 0; i
< 16; i
++) {
1444 helper_ld_asi(asi
& 0x8f, 4, 0);
1445 *(uint32_t *)&env
->fpr
[rd
++] = T1
;
1456 helper_ld_asi(asi
, size
, 0);
1460 *((uint32_t *)&FT0
) = T1
;
1463 *((int64_t *)&DT0
) = T1
;
1465 #if defined(CONFIG_USER_ONLY)
1474 void helper_stf_asi(int asi
, int size
, int rd
)
1476 target_ulong tmp_T0
= T0
, tmp_T1
= T1
;
1480 case 0xf0: // Block store primary
1481 case 0xf1: // Block store secondary
1482 case 0xf8: // Block store primary LE
1483 case 0xf9: // Block store secondary LE
1485 raise_exception(TT_ILL_INSN
);
1489 raise_exception(TT_UNALIGNED
);
1492 for (i
= 0; i
< 16; i
++) {
1493 T1
= *(uint32_t *)&env
->fpr
[rd
++];
1494 helper_st_asi(asi
& 0x8f, 4);
1508 T1
= *((uint32_t *)&FT0
);
1511 T1
= *((int64_t *)&DT0
);
1513 #if defined(CONFIG_USER_ONLY)
1519 helper_st_asi(asi
, size
);
1523 #endif /* TARGET_SPARC64 */
1525 #ifndef TARGET_SPARC64
1530 if (env
->psret
== 1)
1531 raise_exception(TT_ILL_INSN
);
1534 cwp
= (env
->cwp
+ 1) & (NWINDOWS
- 1);
1535 if (env
->wim
& (1 << cwp
)) {
1536 raise_exception(TT_WIN_UNF
);
1539 env
->psrs
= env
->psrps
;
1543 void helper_ldfsr(void)
1546 switch (env
->fsr
& FSR_RD_MASK
) {
1547 case FSR_RD_NEAREST
:
1548 rnd_mode
= float_round_nearest_even
;
1552 rnd_mode
= float_round_to_zero
;
1555 rnd_mode
= float_round_up
;
1558 rnd_mode
= float_round_down
;
1561 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
1566 env
->exception_index
= EXCP_DEBUG
;
1570 #ifndef TARGET_SPARC64
1573 if ((T0
& PSR_CWP
) >= NWINDOWS
)
1574 raise_exception(TT_ILL_INSN
);
1591 static inline uint64_t *get_gregset(uint64_t pstate
)
1606 static inline void change_pstate(uint64_t new_pstate
)
1608 uint64_t pstate_regs
, new_pstate_regs
;
1609 uint64_t *src
, *dst
;
1611 pstate_regs
= env
->pstate
& 0xc01;
1612 new_pstate_regs
= new_pstate
& 0xc01;
1613 if (new_pstate_regs
!= pstate_regs
) {
1614 // Switch global register bank
1615 src
= get_gregset(new_pstate_regs
);
1616 dst
= get_gregset(pstate_regs
);
1617 memcpy32(dst
, env
->gregs
);
1618 memcpy32(env
->gregs
, src
);
1620 env
->pstate
= new_pstate
;
1623 void do_wrpstate(void)
1625 change_pstate(T0
& 0xf3f);
1631 env
->pc
= env
->tnpc
[env
->tl
];
1632 env
->npc
= env
->tnpc
[env
->tl
] + 4;
1633 PUT_CCR(env
, env
->tstate
[env
->tl
] >> 32);
1634 env
->asi
= (env
->tstate
[env
->tl
] >> 24) & 0xff;
1635 change_pstate((env
->tstate
[env
->tl
] >> 8) & 0xf3f);
1636 PUT_CWP64(env
, env
->tstate
[env
->tl
] & 0xff);
1642 env
->pc
= env
->tpc
[env
->tl
];
1643 env
->npc
= env
->tnpc
[env
->tl
];
1644 PUT_CCR(env
, env
->tstate
[env
->tl
] >> 32);
1645 env
->asi
= (env
->tstate
[env
->tl
] >> 24) & 0xff;
1646 change_pstate((env
->tstate
[env
->tl
] >> 8) & 0xf3f);
1647 PUT_CWP64(env
, env
->tstate
[env
->tl
] & 0xff);
1651 void set_cwp(int new_cwp
)
1653 /* put the modified wrap registers at their proper location */
1654 if (env
->cwp
== (NWINDOWS
- 1))
1655 memcpy32(env
->regbase
, env
->regbase
+ NWINDOWS
* 16);
1657 /* put the wrap registers at their temporary location */
1658 if (new_cwp
== (NWINDOWS
- 1))
1659 memcpy32(env
->regbase
+ NWINDOWS
* 16, env
->regbase
);
1660 env
->regwptr
= env
->regbase
+ (new_cwp
* 16);
1661 REGWPTR
= env
->regwptr
;
1664 void cpu_set_cwp(CPUState
*env1
, int new_cwp
)
1666 CPUState
*saved_env
;
1668 target_ulong
*saved_regwptr
;
1673 saved_regwptr
= REGWPTR
;
1679 REGWPTR
= saved_regwptr
;
1683 #ifdef TARGET_SPARC64
1684 void do_interrupt(int intno
)
1687 if (loglevel
& CPU_LOG_INT
) {
1689 fprintf(logfile
, "%6d: v=%04x pc=%016" PRIx64
" npc=%016" PRIx64
" SP=%016" PRIx64
"\n",
1692 env
->npc
, env
->regwptr
[6]);
1693 cpu_dump_state(env
, logfile
, fprintf
, 0);
1699 fprintf(logfile
, " code=");
1700 ptr
= (uint8_t *)env
->pc
;
1701 for(i
= 0; i
< 16; i
++) {
1702 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
1704 fprintf(logfile
, "\n");
1710 #if !defined(CONFIG_USER_ONLY)
1711 if (env
->tl
== MAXTL
) {
1712 cpu_abort(env
, "Trap 0x%04x while trap level is MAXTL, Error state", env
->exception_index
);
1716 env
->tstate
[env
->tl
] = ((uint64_t)GET_CCR(env
) << 32) | ((env
->asi
& 0xff) << 24) |
1717 ((env
->pstate
& 0xf3f) << 8) | GET_CWP64(env
);
1718 env
->tpc
[env
->tl
] = env
->pc
;
1719 env
->tnpc
[env
->tl
] = env
->npc
;
1720 env
->tt
[env
->tl
] = intno
;
1721 change_pstate(PS_PEF
| PS_PRIV
| PS_AG
);
1723 if (intno
== TT_CLRWIN
)
1724 set_cwp((env
->cwp
- 1) & (NWINDOWS
- 1));
1725 else if ((intno
& 0x1c0) == TT_SPILL
)
1726 set_cwp((env
->cwp
- env
->cansave
- 2) & (NWINDOWS
- 1));
1727 else if ((intno
& 0x1c0) == TT_FILL
)
1728 set_cwp((env
->cwp
+ 1) & (NWINDOWS
- 1));
1729 env
->tbr
&= ~0x7fffULL
;
1730 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
1731 if (env
->tl
< MAXTL
- 1) {
1734 env
->pstate
|= PS_RED
;
1735 if (env
->tl
!= MAXTL
)
1739 env
->npc
= env
->pc
+ 4;
1740 env
->exception_index
= 0;
1743 void do_interrupt(int intno
)
1748 if (loglevel
& CPU_LOG_INT
) {
1750 fprintf(logfile
, "%6d: v=%02x pc=%08x npc=%08x SP=%08x\n",
1753 env
->npc
, env
->regwptr
[6]);
1754 cpu_dump_state(env
, logfile
, fprintf
, 0);
1760 fprintf(logfile
, " code=");
1761 ptr
= (uint8_t *)env
->pc
;
1762 for(i
= 0; i
< 16; i
++) {
1763 fprintf(logfile
, " %02x", ldub(ptr
+ i
));
1765 fprintf(logfile
, "\n");
1771 #if !defined(CONFIG_USER_ONLY)
1772 if (env
->psret
== 0) {
1773 cpu_abort(env
, "Trap 0x%02x while interrupts disabled, Error state", env
->exception_index
);
1778 cwp
= (env
->cwp
- 1) & (NWINDOWS
- 1);
1780 env
->regwptr
[9] = env
->pc
;
1781 env
->regwptr
[10] = env
->npc
;
1782 env
->psrps
= env
->psrs
;
1784 env
->tbr
= (env
->tbr
& TBR_BASE_MASK
) | (intno
<< 4);
1786 env
->npc
= env
->pc
+ 4;
1787 env
->exception_index
= 0;
1791 #if !defined(CONFIG_USER_ONLY)
1793 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
1796 #define MMUSUFFIX _mmu
1797 #define ALIGNED_ONLY
1799 # define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL))
1801 # define GETPC() (__builtin_return_address(0))
1805 #include "softmmu_template.h"
1808 #include "softmmu_template.h"
1811 #include "softmmu_template.h"
1814 #include "softmmu_template.h"
1816 static void do_unaligned_access(target_ulong addr
, int is_write
, int is_user
,
1819 #ifdef DEBUG_UNALIGNED
1820 printf("Unaligned access to 0x%x from 0x%x\n", addr
, env
->pc
);
1822 raise_exception(TT_UNALIGNED
);
1825 /* try to fill the TLB and return an exception if error. If retaddr is
1826 NULL, it means that the function was called in C code (i.e. not
1827 from generated code or from helper.c) */
1828 /* XXX: fix it to restore all registers */
1829 void tlb_fill(target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
1831 TranslationBlock
*tb
;
1834 CPUState
*saved_env
;
1836 /* XXX: hack to restore env in all cases, even if not called from
1839 env
= cpu_single_env
;
1841 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
1844 /* now we have a real cpu fault */
1845 pc
= (unsigned long)retaddr
;
1846 tb
= tb_find_pc(pc
);
1848 /* the PC is inside the translated code. It means that we have
1849 a virtual CPU fault */
1850 cpu_restore_state(tb
, env
, pc
, (void *)T2
);
1860 #ifndef TARGET_SPARC64
1861 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
1864 CPUState
*saved_env
;
1866 /* XXX: hack to restore env in all cases, even if not called from
1869 env
= cpu_single_env
;
1870 #ifdef DEBUG_UNASSIGNED
1872 printf("Unassigned mem %s access to " TARGET_FMT_plx
" asi 0x%02x from "
1874 is_exec
? "exec" : is_write
? "write" : "read", addr
, is_asi
,
1877 printf("Unassigned mem %s access to " TARGET_FMT_plx
" from "
1879 is_exec
? "exec" : is_write
? "write" : "read", addr
, env
->pc
);
1881 if (env
->mmuregs
[3]) /* Fault status register */
1882 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
1884 env
->mmuregs
[3] |= 1 << 16;
1886 env
->mmuregs
[3] |= 1 << 5;
1888 env
->mmuregs
[3] |= 1 << 6;
1890 env
->mmuregs
[3] |= 1 << 7;
1891 env
->mmuregs
[3] |= (5 << 2) | 2;
1892 env
->mmuregs
[4] = addr
; /* Fault address register */
1893 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
1895 raise_exception(TT_CODE_ACCESS
);
1897 raise_exception(TT_DATA_ACCESS
);
1902 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
1905 #ifdef DEBUG_UNASSIGNED
1906 CPUState
*saved_env
;
1908 /* XXX: hack to restore env in all cases, even if not called from
1911 env
= cpu_single_env
;
1912 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
"\n",
1917 raise_exception(TT_CODE_ACCESS
);
1919 raise_exception(TT_DATA_ACCESS
);