2 * Helpers for loads and stores
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 //#define DEBUG_UNALIGNED
26 //#define DEBUG_UNASSIGNED
28 //#define DEBUG_CACHE_CONTROL
31 #define DPRINTF_MMU(fmt, ...) \
32 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
34 #define DPRINTF_MMU(fmt, ...) do {} while (0)
38 #define DPRINTF_MXCC(fmt, ...) \
39 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
41 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
45 #define DPRINTF_ASI(fmt, ...) \
46 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
49 #ifdef DEBUG_CACHE_CONTROL
50 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
51 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
53 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
58 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
60 #define AM_CHECK(env1) (1)
64 #define QT0 (env->qt0)
65 #define QT1 (env->qt1)
67 #if !defined(CONFIG_USER_ONLY)
68 #include "softmmu_exec.h"
69 #define MMUSUFFIX _mmu
73 #include "softmmu_template.h"
76 #include "softmmu_template.h"
79 #include "softmmu_template.h"
82 #include "softmmu_template.h"
85 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
86 /* Calculates TSB pointer value for fault page size 8k or 64k */
87 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
88 uint64_t tag_access_register
,
91 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
92 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
93 int tsb_size
= tsb_register
& 0xf;
95 /* discard lower 13 bits which hold tag access context */
96 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
98 /* now reorder bits */
99 uint64_t tsb_base_mask
= ~0x1fffULL
;
100 uint64_t va
= tag_access_va
;
102 /* move va bits to correct position */
103 if (page_size
== 8*1024) {
105 } else if (page_size
== 64*1024) {
110 tsb_base_mask
<<= tsb_size
;
113 /* calculate tsb_base mask and adjust va if split is in use */
115 if (page_size
== 8*1024) {
116 va
&= ~(1ULL << (13 + tsb_size
));
117 } else if (page_size
== 64*1024) {
118 va
|= (1ULL << (13 + tsb_size
));
123 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
126 /* Calculates tag target register value by reordering bits
127 in tag access register */
128 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
130 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
133 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
134 uint64_t tlb_tag
, uint64_t tlb_tte
,
137 target_ulong mask
, size
, va
, offset
;
139 /* flush page range if translation is valid */
140 if (TTE_IS_VALID(tlb
->tte
)) {
142 mask
= 0xffffffffffffe000ULL
;
143 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
146 va
= tlb
->tag
& mask
;
148 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
149 tlb_flush_page(env1
, va
+ offset
);
157 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
158 const char *strmmu
, CPUSPARCState
*env1
)
164 int is_demap_context
= (demap_addr
>> 6) & 1;
167 switch ((demap_addr
>> 4) & 3) {
168 case 0: /* primary */
169 context
= env1
->dmmu
.mmu_primary_context
;
171 case 1: /* secondary */
172 context
= env1
->dmmu
.mmu_secondary_context
;
174 case 2: /* nucleus */
177 case 3: /* reserved */
182 for (i
= 0; i
< 64; i
++) {
183 if (TTE_IS_VALID(tlb
[i
].tte
)) {
185 if (is_demap_context
) {
186 /* will remove non-global entries matching context value */
187 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
188 !tlb_compare_context(&tlb
[i
], context
)) {
193 will remove any entry matching VA */
194 mask
= 0xffffffffffffe000ULL
;
195 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
197 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
201 /* entry should be global or matching context value */
202 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
203 !tlb_compare_context(&tlb
[i
], context
)) {
208 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
210 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
211 dump_mmu(stdout
, fprintf
, env1
);
217 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
218 uint64_t tlb_tag
, uint64_t tlb_tte
,
219 const char *strmmu
, CPUSPARCState
*env1
)
221 unsigned int i
, replace_used
;
223 /* Try replacing invalid entry */
224 for (i
= 0; i
< 64; i
++) {
225 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
226 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
228 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
229 dump_mmu(stdout
, fprintf
, env1
);
235 /* All entries are valid, try replacing unlocked entry */
237 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
239 /* Used entries are not replaced on first pass */
241 for (i
= 0; i
< 64; i
++) {
242 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
244 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
246 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
247 strmmu
, (replace_used
? "used" : "unused"), i
);
248 dump_mmu(stdout
, fprintf
, env1
);
254 /* Now reset used bit and search for unused entries again */
256 for (i
= 0; i
< 64; i
++) {
257 TTE_SET_UNUSED(tlb
[i
].tte
);
262 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
269 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
271 #ifdef TARGET_SPARC64
272 if (AM_CHECK(env1
)) {
273 addr
&= 0xffffffffULL
;
279 /* returns true if access using this ASI is to have address translated by MMU
280 otherwise access is to raw physical address */
281 static inline int is_translating_asi(int asi
)
283 #ifdef TARGET_SPARC64
284 /* Ultrasparc IIi translating asi
285 - note this list is defined by cpu implementation
301 /* TODO: check sparc32 bits */
306 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
307 int asi
, target_ulong addr
)
309 if (is_translating_asi(asi
)) {
310 return address_mask(env
, addr
);
316 void helper_check_align(CPUSPARCState
*env
, target_ulong addr
, uint32_t align
)
319 #ifdef DEBUG_UNALIGNED
320 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
321 "\n", addr
, env
->pc
);
323 helper_raise_exception(env
, TT_UNALIGNED
);
327 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
329 static void dump_mxcc(CPUSPARCState
*env
)
331 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
333 env
->mxccdata
[0], env
->mxccdata
[1],
334 env
->mxccdata
[2], env
->mxccdata
[3]);
335 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
337 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
339 env
->mxccregs
[0], env
->mxccregs
[1],
340 env
->mxccregs
[2], env
->mxccregs
[3],
341 env
->mxccregs
[4], env
->mxccregs
[5],
342 env
->mxccregs
[6], env
->mxccregs
[7]);
346 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
347 && defined(DEBUG_ASI)
348 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
353 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
354 addr
, asi
, r1
& 0xff);
357 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
358 addr
, asi
, r1
& 0xffff);
361 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
362 addr
, asi
, r1
& 0xffffffff);
365 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
372 #ifndef TARGET_SPARC64
373 #ifndef CONFIG_USER_ONLY
376 /* Leon3 cache control */
378 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
379 uint64_t val
, int size
)
381 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
385 DPRINTF_CACHE_CONTROL("32bits only\n");
390 case 0x00: /* Cache control */
392 /* These values must always be read as zeros */
393 val
&= ~CACHE_CTRL_FD
;
394 val
&= ~CACHE_CTRL_FI
;
395 val
&= ~CACHE_CTRL_IB
;
396 val
&= ~CACHE_CTRL_IP
;
397 val
&= ~CACHE_CTRL_DP
;
399 env
->cache_control
= val
;
401 case 0x04: /* Instruction cache configuration */
402 case 0x08: /* Data cache configuration */
406 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
411 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
417 DPRINTF_CACHE_CONTROL("32bits only\n");
422 case 0x00: /* Cache control */
423 ret
= env
->cache_control
;
426 /* Configuration registers are read and only always keep those
429 case 0x04: /* Instruction cache configuration */
432 case 0x08: /* Data cache configuration */
436 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
439 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
444 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
448 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
449 uint32_t last_addr
= addr
;
452 helper_check_align(env
, addr
, size
- 1);
454 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
456 case 0x00: /* Leon3 Cache Control */
457 case 0x08: /* Leon3 Instruction Cache config */
458 case 0x0C: /* Leon3 Date Cache config */
459 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
460 ret
= leon3_cache_control_ld(env
, addr
, size
);
463 case 0x01c00a00: /* MXCC control register */
465 ret
= env
->mxccregs
[3];
467 qemu_log_mask(LOG_UNIMP
,
468 "%08x: unimplemented access size: %d\n", addr
,
472 case 0x01c00a04: /* MXCC control register */
474 ret
= env
->mxccregs
[3];
476 qemu_log_mask(LOG_UNIMP
,
477 "%08x: unimplemented access size: %d\n", addr
,
481 case 0x01c00c00: /* Module reset register */
483 ret
= env
->mxccregs
[5];
484 /* should we do something here? */
486 qemu_log_mask(LOG_UNIMP
,
487 "%08x: unimplemented access size: %d\n", addr
,
491 case 0x01c00f00: /* MBus port address register */
493 ret
= env
->mxccregs
[7];
495 qemu_log_mask(LOG_UNIMP
,
496 "%08x: unimplemented access size: %d\n", addr
,
501 qemu_log_mask(LOG_UNIMP
,
502 "%08x: unimplemented address, size: %d\n", addr
,
506 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
507 "addr = %08x -> ret = %" PRIx64
","
508 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
513 case 3: /* MMU probe */
517 mmulev
= (addr
>> 8) & 15;
521 ret
= mmu_probe(env
, addr
, mmulev
);
523 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
527 case 4: /* read MMU regs */
529 int reg
= (addr
>> 8) & 0x1f;
531 ret
= env
->mmuregs
[reg
];
532 if (reg
== 3) { /* Fault status cleared on read */
534 } else if (reg
== 0x13) { /* Fault status read */
535 ret
= env
->mmuregs
[3];
536 } else if (reg
== 0x14) { /* Fault address read */
537 ret
= env
->mmuregs
[4];
539 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
542 case 5: /* Turbosparc ITLB Diagnostic */
543 case 6: /* Turbosparc DTLB Diagnostic */
544 case 7: /* Turbosparc IOTLB Diagnostic */
546 case 9: /* Supervisor code access */
549 ret
= cpu_ldub_code(env
, addr
);
552 ret
= cpu_lduw_code(env
, addr
);
556 ret
= cpu_ldl_code(env
, addr
);
559 ret
= cpu_ldq_code(env
, addr
);
563 case 0xa: /* User data access */
566 ret
= cpu_ldub_user(env
, addr
);
569 ret
= cpu_lduw_user(env
, addr
);
573 ret
= cpu_ldl_user(env
, addr
);
576 ret
= cpu_ldq_user(env
, addr
);
580 case 0xb: /* Supervisor data access */
583 ret
= cpu_ldub_kernel(env
, addr
);
586 ret
= cpu_lduw_kernel(env
, addr
);
590 ret
= cpu_ldl_kernel(env
, addr
);
593 ret
= cpu_ldq_kernel(env
, addr
);
597 case 0xc: /* I-cache tag */
598 case 0xd: /* I-cache data */
599 case 0xe: /* D-cache tag */
600 case 0xf: /* D-cache data */
602 case 0x20: /* MMU passthrough */
605 ret
= ldub_phys(addr
);
608 ret
= lduw_phys(addr
);
612 ret
= ldl_phys(addr
);
615 ret
= ldq_phys(addr
);
619 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
622 ret
= ldub_phys((target_phys_addr_t
)addr
623 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
626 ret
= lduw_phys((target_phys_addr_t
)addr
627 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
631 ret
= ldl_phys((target_phys_addr_t
)addr
632 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
635 ret
= ldq_phys((target_phys_addr_t
)addr
636 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
640 case 0x30: /* Turbosparc secondary cache diagnostic */
641 case 0x31: /* Turbosparc RAM snoop */
642 case 0x32: /* Turbosparc page table descriptor diagnostic */
643 case 0x39: /* data cache diagnostic register */
646 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
648 int reg
= (addr
>> 8) & 3;
651 case 0: /* Breakpoint Value (Addr) */
652 ret
= env
->mmubpregs
[reg
];
654 case 1: /* Breakpoint Mask */
655 ret
= env
->mmubpregs
[reg
];
657 case 2: /* Breakpoint Control */
658 ret
= env
->mmubpregs
[reg
];
660 case 3: /* Breakpoint Status */
661 ret
= env
->mmubpregs
[reg
];
662 env
->mmubpregs
[reg
] = 0ULL;
665 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
669 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
670 ret
= env
->mmubpctrv
;
672 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
673 ret
= env
->mmubpctrc
;
675 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
676 ret
= env
->mmubpctrs
;
678 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
679 ret
= env
->mmubpaction
;
681 case 8: /* User code access, XXX */
683 cpu_unassigned_access(env
, addr
, 0, 0, asi
, size
);
703 dump_asi("read ", last_addr
, asi
, size
, ret
);
708 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
, int asi
,
711 helper_check_align(env
, addr
, size
- 1);
713 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
715 case 0x00: /* Leon3 Cache Control */
716 case 0x08: /* Leon3 Instruction Cache config */
717 case 0x0C: /* Leon3 Date Cache config */
718 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
719 leon3_cache_control_st(env
, addr
, val
, size
);
723 case 0x01c00000: /* MXCC stream data register 0 */
725 env
->mxccdata
[0] = val
;
727 qemu_log_mask(LOG_UNIMP
,
728 "%08x: unimplemented access size: %d\n", addr
,
732 case 0x01c00008: /* MXCC stream data register 1 */
734 env
->mxccdata
[1] = val
;
736 qemu_log_mask(LOG_UNIMP
,
737 "%08x: unimplemented access size: %d\n", addr
,
741 case 0x01c00010: /* MXCC stream data register 2 */
743 env
->mxccdata
[2] = val
;
745 qemu_log_mask(LOG_UNIMP
,
746 "%08x: unimplemented access size: %d\n", addr
,
750 case 0x01c00018: /* MXCC stream data register 3 */
752 env
->mxccdata
[3] = val
;
754 qemu_log_mask(LOG_UNIMP
,
755 "%08x: unimplemented access size: %d\n", addr
,
759 case 0x01c00100: /* MXCC stream source */
761 env
->mxccregs
[0] = val
;
763 qemu_log_mask(LOG_UNIMP
,
764 "%08x: unimplemented access size: %d\n", addr
,
767 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
769 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
771 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
773 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
776 case 0x01c00200: /* MXCC stream destination */
778 env
->mxccregs
[1] = val
;
780 qemu_log_mask(LOG_UNIMP
,
781 "%08x: unimplemented access size: %d\n", addr
,
784 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
786 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
788 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
790 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
793 case 0x01c00a00: /* MXCC control register */
795 env
->mxccregs
[3] = val
;
797 qemu_log_mask(LOG_UNIMP
,
798 "%08x: unimplemented access size: %d\n", addr
,
802 case 0x01c00a04: /* MXCC control register */
804 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
807 qemu_log_mask(LOG_UNIMP
,
808 "%08x: unimplemented access size: %d\n", addr
,
812 case 0x01c00e00: /* MXCC error register */
813 /* writing a 1 bit clears the error */
815 env
->mxccregs
[6] &= ~val
;
817 qemu_log_mask(LOG_UNIMP
,
818 "%08x: unimplemented access size: %d\n", addr
,
822 case 0x01c00f00: /* MBus port address register */
824 env
->mxccregs
[7] = val
;
826 qemu_log_mask(LOG_UNIMP
,
827 "%08x: unimplemented access size: %d\n", addr
,
832 qemu_log_mask(LOG_UNIMP
,
833 "%08x: unimplemented address, size: %d\n", addr
,
837 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
838 asi
, size
, addr
, val
);
843 case 3: /* MMU flush */
847 mmulev
= (addr
>> 8) & 15;
848 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
850 case 0: /* flush page */
851 tlb_flush_page(env
, addr
& 0xfffff000);
853 case 1: /* flush segment (256k) */
854 case 2: /* flush region (16M) */
855 case 3: /* flush context (4G) */
856 case 4: /* flush entire */
863 dump_mmu(stdout
, fprintf
, env
);
867 case 4: /* write MMU regs */
869 int reg
= (addr
>> 8) & 0x1f;
872 oldreg
= env
->mmuregs
[reg
];
874 case 0: /* Control Register */
875 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
877 /* Mappings generated during no-fault mode or MMU
878 disabled mode are invalid in normal mode */
879 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
880 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
))) {
884 case 1: /* Context Table Pointer Register */
885 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
887 case 2: /* Context Register */
888 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
889 if (oldreg
!= env
->mmuregs
[reg
]) {
890 /* we flush when the MMU context changes because
891 QEMU has no MMU context support */
895 case 3: /* Synchronous Fault Status Register with Clear */
896 case 4: /* Synchronous Fault Address Register */
898 case 0x10: /* TLB Replacement Control Register */
899 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
901 case 0x13: /* Synchronous Fault Status Register with Read
903 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
905 case 0x14: /* Synchronous Fault Address Register */
906 env
->mmuregs
[4] = val
;
909 env
->mmuregs
[reg
] = val
;
912 if (oldreg
!= env
->mmuregs
[reg
]) {
913 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
914 reg
, oldreg
, env
->mmuregs
[reg
]);
917 dump_mmu(stdout
, fprintf
, env
);
921 case 5: /* Turbosparc ITLB Diagnostic */
922 case 6: /* Turbosparc DTLB Diagnostic */
923 case 7: /* Turbosparc IOTLB Diagnostic */
925 case 0xa: /* User data access */
928 cpu_stb_user(env
, addr
, val
);
931 cpu_stw_user(env
, addr
, val
);
935 cpu_stl_user(env
, addr
, val
);
938 cpu_stq_user(env
, addr
, val
);
942 case 0xb: /* Supervisor data access */
945 cpu_stb_kernel(env
, addr
, val
);
948 cpu_stw_kernel(env
, addr
, val
);
952 cpu_stl_kernel(env
, addr
, val
);
955 cpu_stq_kernel(env
, addr
, val
);
959 case 0xc: /* I-cache tag */
960 case 0xd: /* I-cache data */
961 case 0xe: /* D-cache tag */
962 case 0xf: /* D-cache data */
963 case 0x10: /* I/D-cache flush page */
964 case 0x11: /* I/D-cache flush segment */
965 case 0x12: /* I/D-cache flush region */
966 case 0x13: /* I/D-cache flush context */
967 case 0x14: /* I/D-cache flush user */
969 case 0x17: /* Block copy, sta access */
975 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
977 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
978 temp
= cpu_ldl_kernel(env
, src
);
979 cpu_stl_kernel(env
, dst
, temp
);
983 case 0x1f: /* Block fill, stda access */
986 fill 32 bytes with val */
988 uint32_t dst
= addr
& 7;
990 for (i
= 0; i
< 32; i
+= 8, dst
+= 8) {
991 cpu_stq_kernel(env
, dst
, val
);
995 case 0x20: /* MMU passthrough */
1002 stw_phys(addr
, val
);
1006 stl_phys(addr
, val
);
1009 stq_phys(addr
, val
);
1014 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1018 stb_phys((target_phys_addr_t
)addr
1019 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1022 stw_phys((target_phys_addr_t
)addr
1023 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1027 stl_phys((target_phys_addr_t
)addr
1028 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1031 stq_phys((target_phys_addr_t
)addr
1032 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1037 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1038 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1039 Turbosparc snoop RAM */
1040 case 0x32: /* store buffer control or Turbosparc page table
1041 descriptor diagnostic */
1042 case 0x36: /* I-cache flash clear */
1043 case 0x37: /* D-cache flash clear */
1045 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1047 int reg
= (addr
>> 8) & 3;
1050 case 0: /* Breakpoint Value (Addr) */
1051 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1053 case 1: /* Breakpoint Mask */
1054 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1056 case 2: /* Breakpoint Control */
1057 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1059 case 3: /* Breakpoint Status */
1060 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1063 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1067 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1068 env
->mmubpctrv
= val
& 0xffffffff;
1070 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1071 env
->mmubpctrc
= val
& 0x3;
1073 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1074 env
->mmubpctrs
= val
& 0x3;
1076 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1077 env
->mmubpaction
= val
& 0x1fff;
1079 case 8: /* User code access, XXX */
1080 case 9: /* Supervisor code access, XXX */
1082 cpu_unassigned_access(env
, addr
, 1, 0, asi
, size
);
1086 dump_asi("write", addr
, asi
, size
, val
);
1090 #endif /* CONFIG_USER_ONLY */
1091 #else /* TARGET_SPARC64 */
1093 #ifdef CONFIG_USER_ONLY
1094 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1098 #if defined(DEBUG_ASI)
1099 target_ulong last_addr
= addr
;
1103 helper_raise_exception(env
, TT_PRIV_ACT
);
1106 helper_check_align(env
, addr
, size
- 1);
1107 addr
= asi_address_mask(env
, asi
, addr
);
1110 case 0x82: /* Primary no-fault */
1111 case 0x8a: /* Primary no-fault LE */
1112 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1114 dump_asi("read ", last_addr
, asi
, size
, ret
);
1119 case 0x80: /* Primary */
1120 case 0x88: /* Primary LE */
1124 ret
= ldub_raw(addr
);
1127 ret
= lduw_raw(addr
);
1130 ret
= ldl_raw(addr
);
1134 ret
= ldq_raw(addr
);
1139 case 0x83: /* Secondary no-fault */
1140 case 0x8b: /* Secondary no-fault LE */
1141 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1143 dump_asi("read ", last_addr
, asi
, size
, ret
);
1148 case 0x81: /* Secondary */
1149 case 0x89: /* Secondary LE */
1156 /* Convert from little endian */
1158 case 0x88: /* Primary LE */
1159 case 0x89: /* Secondary LE */
1160 case 0x8a: /* Primary no-fault LE */
1161 case 0x8b: /* Secondary no-fault LE */
1179 /* Convert to signed number */
1186 ret
= (int16_t) ret
;
1189 ret
= (int32_t) ret
;
1196 dump_asi("read ", last_addr
, asi
, size
, ret
);
1201 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1205 dump_asi("write", addr
, asi
, size
, val
);
1208 helper_raise_exception(env
, TT_PRIV_ACT
);
1211 helper_check_align(env
, addr
, size
- 1);
1212 addr
= asi_address_mask(env
, asi
, addr
);
1214 /* Convert to little endian */
1216 case 0x88: /* Primary LE */
1217 case 0x89: /* Secondary LE */
1236 case 0x80: /* Primary */
1237 case 0x88: /* Primary LE */
1256 case 0x81: /* Secondary */
1257 case 0x89: /* Secondary LE */
1261 case 0x82: /* Primary no-fault, RO */
1262 case 0x83: /* Secondary no-fault, RO */
1263 case 0x8a: /* Primary no-fault LE, RO */
1264 case 0x8b: /* Secondary no-fault LE, RO */
1266 helper_raise_exception(env
, TT_DATA_ACCESS
);
1271 #else /* CONFIG_USER_ONLY */
1273 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1277 #if defined(DEBUG_ASI)
1278 target_ulong last_addr
= addr
;
1283 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1284 || (cpu_has_hypervisor(env
)
1285 && asi
>= 0x30 && asi
< 0x80
1286 && !(env
->hpstate
& HS_PRIV
))) {
1287 helper_raise_exception(env
, TT_PRIV_ACT
);
1290 helper_check_align(env
, addr
, size
- 1);
1291 addr
= asi_address_mask(env
, asi
, addr
);
1293 /* process nonfaulting loads first */
1294 if ((asi
& 0xf6) == 0x82) {
1297 /* secondary space access has lowest asi bit equal to 1 */
1298 if (env
->pstate
& PS_PRIV
) {
1299 mmu_idx
= (asi
& 1) ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
;
1301 mmu_idx
= (asi
& 1) ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
;
1304 if (cpu_get_phys_page_nofault(env
, addr
, mmu_idx
) == -1ULL) {
1306 dump_asi("read ", last_addr
, asi
, size
, ret
);
1308 /* env->exception_index is set in get_physical_address_data(). */
1309 helper_raise_exception(env
, env
->exception_index
);
1312 /* convert nonfaulting load ASIs to normal load ASIs */
1317 case 0x10: /* As if user primary */
1318 case 0x11: /* As if user secondary */
1319 case 0x18: /* As if user primary LE */
1320 case 0x19: /* As if user secondary LE */
1321 case 0x80: /* Primary */
1322 case 0x81: /* Secondary */
1323 case 0x88: /* Primary LE */
1324 case 0x89: /* Secondary LE */
1325 case 0xe2: /* UA2007 Primary block init */
1326 case 0xe3: /* UA2007 Secondary block init */
1327 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1328 if (cpu_hypervisor_mode(env
)) {
1331 ret
= cpu_ldub_hypv(env
, addr
);
1334 ret
= cpu_lduw_hypv(env
, addr
);
1337 ret
= cpu_ldl_hypv(env
, addr
);
1341 ret
= cpu_ldq_hypv(env
, addr
);
1345 /* secondary space access has lowest asi bit equal to 1 */
1349 ret
= cpu_ldub_kernel_secondary(env
, addr
);
1352 ret
= cpu_lduw_kernel_secondary(env
, addr
);
1355 ret
= cpu_ldl_kernel_secondary(env
, addr
);
1359 ret
= cpu_ldq_kernel_secondary(env
, addr
);
1365 ret
= cpu_ldub_kernel(env
, addr
);
1368 ret
= cpu_lduw_kernel(env
, addr
);
1371 ret
= cpu_ldl_kernel(env
, addr
);
1375 ret
= cpu_ldq_kernel(env
, addr
);
1381 /* secondary space access has lowest asi bit equal to 1 */
1385 ret
= cpu_ldub_user_secondary(env
, addr
);
1388 ret
= cpu_lduw_user_secondary(env
, addr
);
1391 ret
= cpu_ldl_user_secondary(env
, addr
);
1395 ret
= cpu_ldq_user_secondary(env
, addr
);
1401 ret
= cpu_ldub_user(env
, addr
);
1404 ret
= cpu_lduw_user(env
, addr
);
1407 ret
= cpu_ldl_user(env
, addr
);
1411 ret
= cpu_ldq_user(env
, addr
);
1417 case 0x14: /* Bypass */
1418 case 0x15: /* Bypass, non-cacheable */
1419 case 0x1c: /* Bypass LE */
1420 case 0x1d: /* Bypass, non-cacheable LE */
1424 ret
= ldub_phys(addr
);
1427 ret
= lduw_phys(addr
);
1430 ret
= ldl_phys(addr
);
1434 ret
= ldq_phys(addr
);
1439 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1440 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1441 Only ldda allowed */
1442 helper_raise_exception(env
, TT_ILL_INSN
);
1444 case 0x04: /* Nucleus */
1445 case 0x0c: /* Nucleus Little Endian (LE) */
1449 ret
= cpu_ldub_nucleus(env
, addr
);
1452 ret
= cpu_lduw_nucleus(env
, addr
);
1455 ret
= cpu_ldl_nucleus(env
, addr
);
1459 ret
= cpu_ldq_nucleus(env
, addr
);
1464 case 0x4a: /* UPA config */
1467 case 0x45: /* LSU */
1470 case 0x50: /* I-MMU regs */
1472 int reg
= (addr
>> 3) & 0xf;
1475 /* I-TSB Tag Target register */
1476 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1478 ret
= env
->immuregs
[reg
];
1483 case 0x51: /* I-MMU 8k TSB pointer */
1485 /* env->immuregs[5] holds I-MMU TSB register value
1486 env->immuregs[6] holds I-MMU Tag Access register value */
1487 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1491 case 0x52: /* I-MMU 64k TSB pointer */
1493 /* env->immuregs[5] holds I-MMU TSB register value
1494 env->immuregs[6] holds I-MMU Tag Access register value */
1495 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1499 case 0x55: /* I-MMU data access */
1501 int reg
= (addr
>> 3) & 0x3f;
1503 ret
= env
->itlb
[reg
].tte
;
1506 case 0x56: /* I-MMU tag read */
1508 int reg
= (addr
>> 3) & 0x3f;
1510 ret
= env
->itlb
[reg
].tag
;
1513 case 0x58: /* D-MMU regs */
1515 int reg
= (addr
>> 3) & 0xf;
1518 /* D-TSB Tag Target register */
1519 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1521 ret
= env
->dmmuregs
[reg
];
1525 case 0x59: /* D-MMU 8k TSB pointer */
1527 /* env->dmmuregs[5] holds D-MMU TSB register value
1528 env->dmmuregs[6] holds D-MMU Tag Access register value */
1529 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1533 case 0x5a: /* D-MMU 64k TSB pointer */
1535 /* env->dmmuregs[5] holds D-MMU TSB register value
1536 env->dmmuregs[6] holds D-MMU Tag Access register value */
1537 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1541 case 0x5d: /* D-MMU data access */
1543 int reg
= (addr
>> 3) & 0x3f;
1545 ret
= env
->dtlb
[reg
].tte
;
1548 case 0x5e: /* D-MMU tag read */
1550 int reg
= (addr
>> 3) & 0x3f;
1552 ret
= env
->dtlb
[reg
].tag
;
1555 case 0x48: /* Interrupt dispatch, RO */
1557 case 0x49: /* Interrupt data receive */
1558 ret
= env
->ivec_status
;
1560 case 0x7f: /* Incoming interrupt vector, RO */
1562 int reg
= (addr
>> 4) & 0x3;
1564 ret
= env
->ivec_data
[reg
];
1568 case 0x46: /* D-cache data */
1569 case 0x47: /* D-cache tag access */
1570 case 0x4b: /* E-cache error enable */
1571 case 0x4c: /* E-cache asynchronous fault status */
1572 case 0x4d: /* E-cache asynchronous fault address */
1573 case 0x4e: /* E-cache tag data */
1574 case 0x66: /* I-cache instruction access */
1575 case 0x67: /* I-cache tag access */
1576 case 0x6e: /* I-cache predecode */
1577 case 0x6f: /* I-cache LRU etc. */
1578 case 0x76: /* E-cache tag */
1579 case 0x7e: /* E-cache tag */
1581 case 0x5b: /* D-MMU data pointer */
1582 case 0x54: /* I-MMU data in, WO */
1583 case 0x57: /* I-MMU demap, WO */
1584 case 0x5c: /* D-MMU data in, WO */
1585 case 0x5f: /* D-MMU demap, WO */
1586 case 0x77: /* Interrupt vector, WO */
1588 cpu_unassigned_access(env
, addr
, 0, 0, 1, size
);
1593 /* Convert from little endian */
1595 case 0x0c: /* Nucleus Little Endian (LE) */
1596 case 0x18: /* As if user primary LE */
1597 case 0x19: /* As if user secondary LE */
1598 case 0x1c: /* Bypass LE */
1599 case 0x1d: /* Bypass, non-cacheable LE */
1600 case 0x88: /* Primary LE */
1601 case 0x89: /* Secondary LE */
1619 /* Convert to signed number */
1626 ret
= (int16_t) ret
;
1629 ret
= (int32_t) ret
;
1636 dump_asi("read ", last_addr
, asi
, size
, ret
);
1641 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1645 dump_asi("write", addr
, asi
, size
, val
);
1650 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1651 || (cpu_has_hypervisor(env
)
1652 && asi
>= 0x30 && asi
< 0x80
1653 && !(env
->hpstate
& HS_PRIV
))) {
1654 helper_raise_exception(env
, TT_PRIV_ACT
);
1657 helper_check_align(env
, addr
, size
- 1);
1658 addr
= asi_address_mask(env
, asi
, addr
);
1660 /* Convert to little endian */
1662 case 0x0c: /* Nucleus Little Endian (LE) */
1663 case 0x18: /* As if user primary LE */
1664 case 0x19: /* As if user secondary LE */
1665 case 0x1c: /* Bypass LE */
1666 case 0x1d: /* Bypass, non-cacheable LE */
1667 case 0x88: /* Primary LE */
1668 case 0x89: /* Secondary LE */
1687 case 0x10: /* As if user primary */
1688 case 0x11: /* As if user secondary */
1689 case 0x18: /* As if user primary LE */
1690 case 0x19: /* As if user secondary LE */
1691 case 0x80: /* Primary */
1692 case 0x81: /* Secondary */
1693 case 0x88: /* Primary LE */
1694 case 0x89: /* Secondary LE */
1695 case 0xe2: /* UA2007 Primary block init */
1696 case 0xe3: /* UA2007 Secondary block init */
1697 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1698 if (cpu_hypervisor_mode(env
)) {
1701 cpu_stb_hypv(env
, addr
, val
);
1704 cpu_stw_hypv(env
, addr
, val
);
1707 cpu_stl_hypv(env
, addr
, val
);
1711 cpu_stq_hypv(env
, addr
, val
);
1715 /* secondary space access has lowest asi bit equal to 1 */
1719 cpu_stb_kernel_secondary(env
, addr
, val
);
1722 cpu_stw_kernel_secondary(env
, addr
, val
);
1725 cpu_stl_kernel_secondary(env
, addr
, val
);
1729 cpu_stq_kernel_secondary(env
, addr
, val
);
1735 cpu_stb_kernel(env
, addr
, val
);
1738 cpu_stw_kernel(env
, addr
, val
);
1741 cpu_stl_kernel(env
, addr
, val
);
1745 cpu_stq_kernel(env
, addr
, val
);
1751 /* secondary space access has lowest asi bit equal to 1 */
1755 cpu_stb_user_secondary(env
, addr
, val
);
1758 cpu_stw_user_secondary(env
, addr
, val
);
1761 cpu_stl_user_secondary(env
, addr
, val
);
1765 cpu_stq_user_secondary(env
, addr
, val
);
1771 cpu_stb_user(env
, addr
, val
);
1774 cpu_stw_user(env
, addr
, val
);
1777 cpu_stl_user(env
, addr
, val
);
1781 cpu_stq_user(env
, addr
, val
);
1787 case 0x14: /* Bypass */
1788 case 0x15: /* Bypass, non-cacheable */
1789 case 0x1c: /* Bypass LE */
1790 case 0x1d: /* Bypass, non-cacheable LE */
1794 stb_phys(addr
, val
);
1797 stw_phys(addr
, val
);
1800 stl_phys(addr
, val
);
1804 stq_phys(addr
, val
);
1809 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1810 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1811 Only ldda allowed */
1812 helper_raise_exception(env
, TT_ILL_INSN
);
1814 case 0x04: /* Nucleus */
1815 case 0x0c: /* Nucleus Little Endian (LE) */
1819 cpu_stb_nucleus(env
, addr
, val
);
1822 cpu_stw_nucleus(env
, addr
, val
);
1825 cpu_stl_nucleus(env
, addr
, val
);
1829 cpu_stq_nucleus(env
, addr
, val
);
1835 case 0x4a: /* UPA config */
1838 case 0x45: /* LSU */
1843 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1844 /* Mappings generated during D/I MMU disabled mode are
1845 invalid in normal mode */
1846 if (oldreg
!= env
->lsu
) {
1847 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1850 dump_mmu(stdout
, fprintf
, env1
);
1856 case 0x50: /* I-MMU regs */
1858 int reg
= (addr
>> 3) & 0xf;
1861 oldreg
= env
->immuregs
[reg
];
1865 case 1: /* Not in I-MMU */
1869 if ((val
& 1) == 0) {
1870 val
= 0; /* Clear SFSR */
1872 env
->immu
.sfsr
= val
;
1876 case 5: /* TSB access */
1877 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1878 PRIx64
"\n", env
->immu
.tsb
, val
);
1879 env
->immu
.tsb
= val
;
1881 case 6: /* Tag access */
1882 env
->immu
.tag_access
= val
;
1891 if (oldreg
!= env
->immuregs
[reg
]) {
1892 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1893 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1896 dump_mmu(stdout
, fprintf
, env
);
1900 case 0x54: /* I-MMU data in */
1901 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
1903 case 0x55: /* I-MMU data access */
1905 /* TODO: auto demap */
1907 unsigned int i
= (addr
>> 3) & 0x3f;
1909 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
1912 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1913 dump_mmu(stdout
, fprintf
, env
);
1917 case 0x57: /* I-MMU demap */
1918 demap_tlb(env
->itlb
, addr
, "immu", env
);
1920 case 0x58: /* D-MMU regs */
1922 int reg
= (addr
>> 3) & 0xf;
1925 oldreg
= env
->dmmuregs
[reg
];
1931 if ((val
& 1) == 0) {
1932 val
= 0; /* Clear SFSR, Fault address */
1935 env
->dmmu
.sfsr
= val
;
1937 case 1: /* Primary context */
1938 env
->dmmu
.mmu_primary_context
= val
;
1939 /* can be optimized to only flush MMU_USER_IDX
1940 and MMU_KERNEL_IDX entries */
1943 case 2: /* Secondary context */
1944 env
->dmmu
.mmu_secondary_context
= val
;
1945 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1946 and MMU_KERNEL_SECONDARY_IDX entries */
1949 case 5: /* TSB access */
1950 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1951 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1952 env
->dmmu
.tsb
= val
;
1954 case 6: /* Tag access */
1955 env
->dmmu
.tag_access
= val
;
1957 case 7: /* Virtual Watchpoint */
1958 case 8: /* Physical Watchpoint */
1960 env
->dmmuregs
[reg
] = val
;
1964 if (oldreg
!= env
->dmmuregs
[reg
]) {
1965 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1966 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1969 dump_mmu(stdout
, fprintf
, env
);
1973 case 0x5c: /* D-MMU data in */
1974 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
1976 case 0x5d: /* D-MMU data access */
1978 unsigned int i
= (addr
>> 3) & 0x3f;
1980 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
1983 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1984 dump_mmu(stdout
, fprintf
, env
);
1988 case 0x5f: /* D-MMU demap */
1989 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1991 case 0x49: /* Interrupt data receive */
1992 env
->ivec_status
= val
& 0x20;
1994 case 0x46: /* D-cache data */
1995 case 0x47: /* D-cache tag access */
1996 case 0x4b: /* E-cache error enable */
1997 case 0x4c: /* E-cache asynchronous fault status */
1998 case 0x4d: /* E-cache asynchronous fault address */
1999 case 0x4e: /* E-cache tag data */
2000 case 0x66: /* I-cache instruction access */
2001 case 0x67: /* I-cache tag access */
2002 case 0x6e: /* I-cache predecode */
2003 case 0x6f: /* I-cache LRU etc. */
2004 case 0x76: /* E-cache tag */
2005 case 0x7e: /* E-cache tag */
2007 case 0x51: /* I-MMU 8k TSB pointer, RO */
2008 case 0x52: /* I-MMU 64k TSB pointer, RO */
2009 case 0x56: /* I-MMU tag read, RO */
2010 case 0x59: /* D-MMU 8k TSB pointer, RO */
2011 case 0x5a: /* D-MMU 64k TSB pointer, RO */
2012 case 0x5b: /* D-MMU data pointer, RO */
2013 case 0x5e: /* D-MMU tag read, RO */
2014 case 0x48: /* Interrupt dispatch, RO */
2015 case 0x7f: /* Incoming interrupt vector, RO */
2016 case 0x82: /* Primary no-fault, RO */
2017 case 0x83: /* Secondary no-fault, RO */
2018 case 0x8a: /* Primary no-fault LE, RO */
2019 case 0x8b: /* Secondary no-fault LE, RO */
2021 cpu_unassigned_access(env
, addr
, 1, 0, 1, size
);
2025 #endif /* CONFIG_USER_ONLY */
2027 void helper_ldda_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int rd
)
2029 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2030 || (cpu_has_hypervisor(env
)
2031 && asi
>= 0x30 && asi
< 0x80
2032 && !(env
->hpstate
& HS_PRIV
))) {
2033 helper_raise_exception(env
, TT_PRIV_ACT
);
2036 addr
= asi_address_mask(env
, asi
, addr
);
2039 #if !defined(CONFIG_USER_ONLY)
2040 case 0x24: /* Nucleus quad LDD 128 bit atomic */
2041 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE */
2042 helper_check_align(env
, addr
, 0xf);
2044 env
->gregs
[1] = cpu_ldq_nucleus(env
, addr
+ 8);
2046 bswap64s(&env
->gregs
[1]);
2048 } else if (rd
< 8) {
2049 env
->gregs
[rd
] = cpu_ldq_nucleus(env
, addr
);
2050 env
->gregs
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2052 bswap64s(&env
->gregs
[rd
]);
2053 bswap64s(&env
->gregs
[rd
+ 1]);
2056 env
->regwptr
[rd
] = cpu_ldq_nucleus(env
, addr
);
2057 env
->regwptr
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2059 bswap64s(&env
->regwptr
[rd
]);
2060 bswap64s(&env
->regwptr
[rd
+ 1]);
2066 helper_check_align(env
, addr
, 0x3);
2068 env
->gregs
[1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2069 } else if (rd
< 8) {
2070 env
->gregs
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2071 env
->gregs
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2073 env
->regwptr
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2074 env
->regwptr
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2080 void helper_ldf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2086 helper_check_align(env
, addr
, 3);
2087 addr
= asi_address_mask(env
, asi
, addr
);
2090 case 0xf0: /* UA2007/JPS1 Block load primary */
2091 case 0xf1: /* UA2007/JPS1 Block load secondary */
2092 case 0xf8: /* UA2007/JPS1 Block load primary LE */
2093 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
2095 helper_raise_exception(env
, TT_ILL_INSN
);
2098 helper_check_align(env
, addr
, 0x3f);
2099 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2100 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x8f, 8, 0);
2104 case 0x16: /* UA2007 Block load primary, user privilege */
2105 case 0x17: /* UA2007 Block load secondary, user privilege */
2106 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2107 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2108 case 0x70: /* JPS1 Block load primary, user privilege */
2109 case 0x71: /* JPS1 Block load secondary, user privilege */
2110 case 0x78: /* JPS1 Block load primary LE, user privilege */
2111 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2113 helper_raise_exception(env
, TT_ILL_INSN
);
2116 helper_check_align(env
, addr
, 0x3f);
2117 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2118 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x19, 8, 0);
2129 val
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2131 env
->fpr
[rd
/ 2].l
.lower
= val
;
2133 env
->fpr
[rd
/ 2].l
.upper
= val
;
2137 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2140 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2141 env
->fpr
[rd
/ 2 + 1].ll
= helper_ld_asi(env
, addr
+ 8, asi
, 8, 0);
2146 void helper_stf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2152 helper_check_align(env
, addr
, 3);
2153 addr
= asi_address_mask(env
, asi
, addr
);
2156 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
2157 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
2158 case 0xf0: /* UA2007/JPS1 Block store primary */
2159 case 0xf1: /* UA2007/JPS1 Block store secondary */
2160 case 0xf8: /* UA2007/JPS1 Block store primary LE */
2161 case 0xf9: /* UA2007/JPS1 Block store secondary LE */
2163 helper_raise_exception(env
, TT_ILL_INSN
);
2166 helper_check_align(env
, addr
, 0x3f);
2167 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2168 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x8f, 8);
2172 case 0x16: /* UA2007 Block load primary, user privilege */
2173 case 0x17: /* UA2007 Block load secondary, user privilege */
2174 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2175 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2176 case 0x70: /* JPS1 Block store primary, user privilege */
2177 case 0x71: /* JPS1 Block store secondary, user privilege */
2178 case 0x78: /* JPS1 Block load primary LE, user privilege */
2179 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2181 helper_raise_exception(env
, TT_ILL_INSN
);
2184 helper_check_align(env
, addr
, 0x3f);
2185 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2186 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x19, 8);
2198 val
= env
->fpr
[rd
/ 2].l
.lower
;
2200 val
= env
->fpr
[rd
/ 2].l
.upper
;
2202 helper_st_asi(env
, addr
, val
, asi
, size
);
2205 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, size
);
2208 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, 8);
2209 helper_st_asi(env
, addr
+ 8, env
->fpr
[rd
/ 2 + 1].ll
, asi
, 8);
2214 target_ulong
helper_cas_asi(CPUSPARCState
*env
, target_ulong addr
,
2215 target_ulong val1
, target_ulong val2
, uint32_t asi
)
2219 val2
&= 0xffffffffUL
;
2220 ret
= helper_ld_asi(env
, addr
, asi
, 4, 0);
2221 ret
&= 0xffffffffUL
;
2223 helper_st_asi(env
, addr
, val1
& 0xffffffffUL
, asi
, 4);
2228 target_ulong
helper_casx_asi(CPUSPARCState
*env
, target_ulong addr
,
2229 target_ulong val1
, target_ulong val2
,
2234 ret
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2236 helper_st_asi(env
, addr
, val1
, asi
, 8);
2240 #endif /* TARGET_SPARC64 */
2242 void helper_ldqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2244 /* XXX add 128 bit load */
2247 helper_check_align(env
, addr
, 7);
2248 #if !defined(CONFIG_USER_ONLY)
2251 u
.ll
.upper
= cpu_ldq_user(env
, addr
);
2252 u
.ll
.lower
= cpu_ldq_user(env
, addr
+ 8);
2255 case MMU_KERNEL_IDX
:
2256 u
.ll
.upper
= cpu_ldq_kernel(env
, addr
);
2257 u
.ll
.lower
= cpu_ldq_kernel(env
, addr
+ 8);
2260 #ifdef TARGET_SPARC64
2262 u
.ll
.upper
= cpu_ldq_hypv(env
, addr
);
2263 u
.ll
.lower
= cpu_ldq_hypv(env
, addr
+ 8);
2268 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
2272 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
2273 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
2278 void helper_stqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2280 /* XXX add 128 bit store */
2283 helper_check_align(env
, addr
, 7);
2284 #if !defined(CONFIG_USER_ONLY)
2288 cpu_stq_user(env
, addr
, u
.ll
.upper
);
2289 cpu_stq_user(env
, addr
+ 8, u
.ll
.lower
);
2291 case MMU_KERNEL_IDX
:
2293 cpu_stq_kernel(env
, addr
, u
.ll
.upper
);
2294 cpu_stq_kernel(env
, addr
+ 8, u
.ll
.lower
);
2296 #ifdef TARGET_SPARC64
2299 cpu_stq_hypv(env
, addr
, u
.ll
.upper
);
2300 cpu_stq_hypv(env
, addr
+ 8, u
.ll
.lower
);
2304 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
2309 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
2310 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
2314 #if !defined(CONFIG_USER_ONLY)
2315 #ifndef TARGET_SPARC64
2316 void cpu_unassigned_access(CPUSPARCState
*env
, target_phys_addr_t addr
,
2317 int is_write
, int is_exec
, int is_asi
, int size
)
2321 #ifdef DEBUG_UNASSIGNED
2323 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2324 " asi 0x%02x from " TARGET_FMT_lx
"\n",
2325 is_exec
? "exec" : is_write
? "write" : "read", size
,
2326 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
2328 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2329 " from " TARGET_FMT_lx
"\n",
2330 is_exec
? "exec" : is_write
? "write" : "read", size
,
2331 size
== 1 ? "" : "s", addr
, env
->pc
);
2334 /* Don't overwrite translation and access faults */
2335 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
2336 if ((fault_type
> 4) || (fault_type
== 0)) {
2337 env
->mmuregs
[3] = 0; /* Fault status register */
2339 env
->mmuregs
[3] |= 1 << 16;
2342 env
->mmuregs
[3] |= 1 << 5;
2345 env
->mmuregs
[3] |= 1 << 6;
2348 env
->mmuregs
[3] |= 1 << 7;
2350 env
->mmuregs
[3] |= (5 << 2) | 2;
2351 /* SuperSPARC will never place instruction fault addresses in the FAR */
2353 env
->mmuregs
[4] = addr
; /* Fault address register */
2356 /* overflow (same type fault was not read before another fault) */
2357 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
2358 env
->mmuregs
[3] |= 1;
2361 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2363 helper_raise_exception(env
, TT_CODE_ACCESS
);
2365 helper_raise_exception(env
, TT_DATA_ACCESS
);
2369 /* flush neverland mappings created during no-fault mode,
2370 so the sequential MMU faults report proper fault types */
2371 if (env
->mmuregs
[0] & MMU_NF
) {
2376 void cpu_unassigned_access(CPUSPARCState
*env
, target_phys_addr_t addr
,
2377 int is_write
, int is_exec
, int is_asi
, int size
)
2379 #ifdef DEBUG_UNASSIGNED
2380 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
2381 "\n", addr
, env
->pc
);
2385 helper_raise_exception(env
, TT_CODE_ACCESS
);
2387 helper_raise_exception(env
, TT_DATA_ACCESS
);
2393 #if !defined(CONFIG_USER_ONLY)
2394 /* XXX: make it generic ? */
2395 static void cpu_restore_state2(CPUSPARCState
*env
, uintptr_t retaddr
)
2397 TranslationBlock
*tb
;
2400 /* now we have a real cpu fault */
2401 tb
= tb_find_pc(retaddr
);
2403 /* the PC is inside the translated code. It means that we have
2404 a virtual CPU fault */
2405 cpu_restore_state(tb
, env
, retaddr
);
2410 void do_unaligned_access(CPUSPARCState
*env
, target_ulong addr
, int is_write
,
2411 int is_user
, uintptr_t retaddr
)
2413 #ifdef DEBUG_UNALIGNED
2414 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
2415 "\n", addr
, env
->pc
);
2417 cpu_restore_state2(env
, retaddr
);
2418 helper_raise_exception(env
, TT_UNALIGNED
);
2421 /* try to fill the TLB and return an exception if error. If retaddr is
2422 NULL, it means that the function was called in C code (i.e. not
2423 from generated code or from helper.c) */
2424 /* XXX: fix it to restore all registers */
2425 void tlb_fill(CPUSPARCState
*env
, target_ulong addr
, int is_write
, int mmu_idx
,
2430 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
2432 cpu_restore_state2(env
, retaddr
);