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 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
471 case 0x01c00a04: /* MXCC control register */
473 ret
= env
->mxccregs
[3];
475 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
479 case 0x01c00c00: /* Module reset register */
481 ret
= env
->mxccregs
[5];
482 /* should we do something here? */
484 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
488 case 0x01c00f00: /* MBus port address register */
490 ret
= env
->mxccregs
[7];
492 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
497 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
501 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
502 "addr = %08x -> ret = %" PRIx64
","
503 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
508 case 3: /* MMU probe */
512 mmulev
= (addr
>> 8) & 15;
516 ret
= mmu_probe(env
, addr
, mmulev
);
518 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
522 case 4: /* read MMU regs */
524 int reg
= (addr
>> 8) & 0x1f;
526 ret
= env
->mmuregs
[reg
];
527 if (reg
== 3) { /* Fault status cleared on read */
529 } else if (reg
== 0x13) { /* Fault status read */
530 ret
= env
->mmuregs
[3];
531 } else if (reg
== 0x14) { /* Fault address read */
532 ret
= env
->mmuregs
[4];
534 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
537 case 5: /* Turbosparc ITLB Diagnostic */
538 case 6: /* Turbosparc DTLB Diagnostic */
539 case 7: /* Turbosparc IOTLB Diagnostic */
541 case 9: /* Supervisor code access */
544 ret
= cpu_ldub_code(env
, addr
);
547 ret
= cpu_lduw_code(env
, addr
);
551 ret
= cpu_ldl_code(env
, addr
);
554 ret
= cpu_ldq_code(env
, addr
);
558 case 0xa: /* User data access */
561 ret
= cpu_ldub_user(env
, addr
);
564 ret
= cpu_lduw_user(env
, addr
);
568 ret
= cpu_ldl_user(env
, addr
);
571 ret
= cpu_ldq_user(env
, addr
);
575 case 0xb: /* Supervisor data access */
578 ret
= cpu_ldub_kernel(env
, addr
);
581 ret
= cpu_lduw_kernel(env
, addr
);
585 ret
= cpu_ldl_kernel(env
, addr
);
588 ret
= cpu_ldq_kernel(env
, addr
);
592 case 0xc: /* I-cache tag */
593 case 0xd: /* I-cache data */
594 case 0xe: /* D-cache tag */
595 case 0xf: /* D-cache data */
597 case 0x20: /* MMU passthrough */
600 ret
= ldub_phys(addr
);
603 ret
= lduw_phys(addr
);
607 ret
= ldl_phys(addr
);
610 ret
= ldq_phys(addr
);
614 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
617 ret
= ldub_phys((target_phys_addr_t
)addr
618 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
621 ret
= lduw_phys((target_phys_addr_t
)addr
622 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
626 ret
= ldl_phys((target_phys_addr_t
)addr
627 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
630 ret
= ldq_phys((target_phys_addr_t
)addr
631 | ((target_phys_addr_t
)(asi
& 0xf) << 32));
635 case 0x30: /* Turbosparc secondary cache diagnostic */
636 case 0x31: /* Turbosparc RAM snoop */
637 case 0x32: /* Turbosparc page table descriptor diagnostic */
638 case 0x39: /* data cache diagnostic register */
641 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
643 int reg
= (addr
>> 8) & 3;
646 case 0: /* Breakpoint Value (Addr) */
647 ret
= env
->mmubpregs
[reg
];
649 case 1: /* Breakpoint Mask */
650 ret
= env
->mmubpregs
[reg
];
652 case 2: /* Breakpoint Control */
653 ret
= env
->mmubpregs
[reg
];
655 case 3: /* Breakpoint Status */
656 ret
= env
->mmubpregs
[reg
];
657 env
->mmubpregs
[reg
] = 0ULL;
660 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
664 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
665 ret
= env
->mmubpctrv
;
667 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
668 ret
= env
->mmubpctrc
;
670 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
671 ret
= env
->mmubpctrs
;
673 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
674 ret
= env
->mmubpaction
;
676 case 8: /* User code access, XXX */
678 cpu_unassigned_access(env
, addr
, 0, 0, asi
, size
);
698 dump_asi("read ", last_addr
, asi
, size
, ret
);
703 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
, int asi
,
706 helper_check_align(env
, addr
, size
- 1);
708 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
710 case 0x00: /* Leon3 Cache Control */
711 case 0x08: /* Leon3 Instruction Cache config */
712 case 0x0C: /* Leon3 Date Cache config */
713 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
714 leon3_cache_control_st(env
, addr
, val
, size
);
718 case 0x01c00000: /* MXCC stream data register 0 */
720 env
->mxccdata
[0] = val
;
722 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
726 case 0x01c00008: /* MXCC stream data register 1 */
728 env
->mxccdata
[1] = val
;
730 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
734 case 0x01c00010: /* MXCC stream data register 2 */
736 env
->mxccdata
[2] = val
;
738 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
742 case 0x01c00018: /* MXCC stream data register 3 */
744 env
->mxccdata
[3] = val
;
746 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
750 case 0x01c00100: /* MXCC stream source */
752 env
->mxccregs
[0] = val
;
754 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
757 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
759 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
761 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
763 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
766 case 0x01c00200: /* MXCC stream destination */
768 env
->mxccregs
[1] = val
;
770 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
773 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
775 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
777 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
779 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
782 case 0x01c00a00: /* MXCC control register */
784 env
->mxccregs
[3] = val
;
786 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
790 case 0x01c00a04: /* MXCC control register */
792 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
795 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
799 case 0x01c00e00: /* MXCC error register */
800 /* writing a 1 bit clears the error */
802 env
->mxccregs
[6] &= ~val
;
804 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
808 case 0x01c00f00: /* MBus port address register */
810 env
->mxccregs
[7] = val
;
812 DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr
,
817 DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr
,
821 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
822 asi
, size
, addr
, val
);
827 case 3: /* MMU flush */
831 mmulev
= (addr
>> 8) & 15;
832 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
834 case 0: /* flush page */
835 tlb_flush_page(env
, addr
& 0xfffff000);
837 case 1: /* flush segment (256k) */
838 case 2: /* flush region (16M) */
839 case 3: /* flush context (4G) */
840 case 4: /* flush entire */
847 dump_mmu(stdout
, fprintf
, env
);
851 case 4: /* write MMU regs */
853 int reg
= (addr
>> 8) & 0x1f;
856 oldreg
= env
->mmuregs
[reg
];
858 case 0: /* Control Register */
859 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
861 /* Mappings generated during no-fault mode or MMU
862 disabled mode are invalid in normal mode */
863 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
864 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
))) {
868 case 1: /* Context Table Pointer Register */
869 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
871 case 2: /* Context Register */
872 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
873 if (oldreg
!= env
->mmuregs
[reg
]) {
874 /* we flush when the MMU context changes because
875 QEMU has no MMU context support */
879 case 3: /* Synchronous Fault Status Register with Clear */
880 case 4: /* Synchronous Fault Address Register */
882 case 0x10: /* TLB Replacement Control Register */
883 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
885 case 0x13: /* Synchronous Fault Status Register with Read
887 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
889 case 0x14: /* Synchronous Fault Address Register */
890 env
->mmuregs
[4] = val
;
893 env
->mmuregs
[reg
] = val
;
896 if (oldreg
!= env
->mmuregs
[reg
]) {
897 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
898 reg
, oldreg
, env
->mmuregs
[reg
]);
901 dump_mmu(stdout
, fprintf
, env
);
905 case 5: /* Turbosparc ITLB Diagnostic */
906 case 6: /* Turbosparc DTLB Diagnostic */
907 case 7: /* Turbosparc IOTLB Diagnostic */
909 case 0xa: /* User data access */
912 cpu_stb_user(env
, addr
, val
);
915 cpu_stw_user(env
, addr
, val
);
919 cpu_stl_user(env
, addr
, val
);
922 cpu_stq_user(env
, addr
, val
);
926 case 0xb: /* Supervisor data access */
929 cpu_stb_kernel(env
, addr
, val
);
932 cpu_stw_kernel(env
, addr
, val
);
936 cpu_stl_kernel(env
, addr
, val
);
939 cpu_stq_kernel(env
, addr
, val
);
943 case 0xc: /* I-cache tag */
944 case 0xd: /* I-cache data */
945 case 0xe: /* D-cache tag */
946 case 0xf: /* D-cache data */
947 case 0x10: /* I/D-cache flush page */
948 case 0x11: /* I/D-cache flush segment */
949 case 0x12: /* I/D-cache flush region */
950 case 0x13: /* I/D-cache flush context */
951 case 0x14: /* I/D-cache flush user */
953 case 0x17: /* Block copy, sta access */
959 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
961 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
962 temp
= cpu_ldl_kernel(env
, src
);
963 cpu_stl_kernel(env
, dst
, temp
);
967 case 0x1f: /* Block fill, stda access */
970 fill 32 bytes with val */
972 uint32_t dst
= addr
& 7;
974 for (i
= 0; i
< 32; i
+= 8, dst
+= 8) {
975 cpu_stq_kernel(env
, dst
, val
);
979 case 0x20: /* MMU passthrough */
998 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1002 stb_phys((target_phys_addr_t
)addr
1003 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1006 stw_phys((target_phys_addr_t
)addr
1007 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1011 stl_phys((target_phys_addr_t
)addr
1012 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1015 stq_phys((target_phys_addr_t
)addr
1016 | ((target_phys_addr_t
)(asi
& 0xf) << 32), val
);
1021 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1022 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1023 Turbosparc snoop RAM */
1024 case 0x32: /* store buffer control or Turbosparc page table
1025 descriptor diagnostic */
1026 case 0x36: /* I-cache flash clear */
1027 case 0x37: /* D-cache flash clear */
1029 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1031 int reg
= (addr
>> 8) & 3;
1034 case 0: /* Breakpoint Value (Addr) */
1035 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1037 case 1: /* Breakpoint Mask */
1038 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1040 case 2: /* Breakpoint Control */
1041 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1043 case 3: /* Breakpoint Status */
1044 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1047 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1051 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1052 env
->mmubpctrv
= val
& 0xffffffff;
1054 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1055 env
->mmubpctrc
= val
& 0x3;
1057 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1058 env
->mmubpctrs
= val
& 0x3;
1060 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1061 env
->mmubpaction
= val
& 0x1fff;
1063 case 8: /* User code access, XXX */
1064 case 9: /* Supervisor code access, XXX */
1066 cpu_unassigned_access(env
, addr
, 1, 0, asi
, size
);
1070 dump_asi("write", addr
, asi
, size
, val
);
1074 #endif /* CONFIG_USER_ONLY */
1075 #else /* TARGET_SPARC64 */
1077 #ifdef CONFIG_USER_ONLY
1078 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1082 #if defined(DEBUG_ASI)
1083 target_ulong last_addr
= addr
;
1087 helper_raise_exception(env
, TT_PRIV_ACT
);
1090 helper_check_align(env
, addr
, size
- 1);
1091 addr
= asi_address_mask(env
, asi
, addr
);
1094 case 0x82: /* Primary no-fault */
1095 case 0x8a: /* Primary no-fault LE */
1096 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1098 dump_asi("read ", last_addr
, asi
, size
, ret
);
1103 case 0x80: /* Primary */
1104 case 0x88: /* Primary LE */
1108 ret
= ldub_raw(addr
);
1111 ret
= lduw_raw(addr
);
1114 ret
= ldl_raw(addr
);
1118 ret
= ldq_raw(addr
);
1123 case 0x83: /* Secondary no-fault */
1124 case 0x8b: /* Secondary no-fault LE */
1125 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1127 dump_asi("read ", last_addr
, asi
, size
, ret
);
1132 case 0x81: /* Secondary */
1133 case 0x89: /* Secondary LE */
1140 /* Convert from little endian */
1142 case 0x88: /* Primary LE */
1143 case 0x89: /* Secondary LE */
1144 case 0x8a: /* Primary no-fault LE */
1145 case 0x8b: /* Secondary no-fault LE */
1163 /* Convert to signed number */
1170 ret
= (int16_t) ret
;
1173 ret
= (int32_t) ret
;
1180 dump_asi("read ", last_addr
, asi
, size
, ret
);
1185 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1189 dump_asi("write", addr
, asi
, size
, val
);
1192 helper_raise_exception(env
, TT_PRIV_ACT
);
1195 helper_check_align(env
, addr
, size
- 1);
1196 addr
= asi_address_mask(env
, asi
, addr
);
1198 /* Convert to little endian */
1200 case 0x88: /* Primary LE */
1201 case 0x89: /* Secondary LE */
1220 case 0x80: /* Primary */
1221 case 0x88: /* Primary LE */
1240 case 0x81: /* Secondary */
1241 case 0x89: /* Secondary LE */
1245 case 0x82: /* Primary no-fault, RO */
1246 case 0x83: /* Secondary no-fault, RO */
1247 case 0x8a: /* Primary no-fault LE, RO */
1248 case 0x8b: /* Secondary no-fault LE, RO */
1250 helper_raise_exception(env
, TT_DATA_ACCESS
);
1255 #else /* CONFIG_USER_ONLY */
1257 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1261 #if defined(DEBUG_ASI)
1262 target_ulong last_addr
= addr
;
1267 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1268 || (cpu_has_hypervisor(env
)
1269 && asi
>= 0x30 && asi
< 0x80
1270 && !(env
->hpstate
& HS_PRIV
))) {
1271 helper_raise_exception(env
, TT_PRIV_ACT
);
1274 helper_check_align(env
, addr
, size
- 1);
1275 addr
= asi_address_mask(env
, asi
, addr
);
1277 /* process nonfaulting loads first */
1278 if ((asi
& 0xf6) == 0x82) {
1281 /* secondary space access has lowest asi bit equal to 1 */
1282 if (env
->pstate
& PS_PRIV
) {
1283 mmu_idx
= (asi
& 1) ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
;
1285 mmu_idx
= (asi
& 1) ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
;
1288 if (cpu_get_phys_page_nofault(env
, addr
, mmu_idx
) == -1ULL) {
1290 dump_asi("read ", last_addr
, asi
, size
, ret
);
1292 /* env->exception_index is set in get_physical_address_data(). */
1293 helper_raise_exception(env
, env
->exception_index
);
1296 /* convert nonfaulting load ASIs to normal load ASIs */
1301 case 0x10: /* As if user primary */
1302 case 0x11: /* As if user secondary */
1303 case 0x18: /* As if user primary LE */
1304 case 0x19: /* As if user secondary LE */
1305 case 0x80: /* Primary */
1306 case 0x81: /* Secondary */
1307 case 0x88: /* Primary LE */
1308 case 0x89: /* Secondary LE */
1309 case 0xe2: /* UA2007 Primary block init */
1310 case 0xe3: /* UA2007 Secondary block init */
1311 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1312 if (cpu_hypervisor_mode(env
)) {
1315 ret
= cpu_ldub_hypv(env
, addr
);
1318 ret
= cpu_lduw_hypv(env
, addr
);
1321 ret
= cpu_ldl_hypv(env
, addr
);
1325 ret
= cpu_ldq_hypv(env
, addr
);
1329 /* secondary space access has lowest asi bit equal to 1 */
1333 ret
= cpu_ldub_kernel_secondary(env
, addr
);
1336 ret
= cpu_lduw_kernel_secondary(env
, addr
);
1339 ret
= cpu_ldl_kernel_secondary(env
, addr
);
1343 ret
= cpu_ldq_kernel_secondary(env
, addr
);
1349 ret
= cpu_ldub_kernel(env
, addr
);
1352 ret
= cpu_lduw_kernel(env
, addr
);
1355 ret
= cpu_ldl_kernel(env
, addr
);
1359 ret
= cpu_ldq_kernel(env
, addr
);
1365 /* secondary space access has lowest asi bit equal to 1 */
1369 ret
= cpu_ldub_user_secondary(env
, addr
);
1372 ret
= cpu_lduw_user_secondary(env
, addr
);
1375 ret
= cpu_ldl_user_secondary(env
, addr
);
1379 ret
= cpu_ldq_user_secondary(env
, addr
);
1385 ret
= cpu_ldub_user(env
, addr
);
1388 ret
= cpu_lduw_user(env
, addr
);
1391 ret
= cpu_ldl_user(env
, addr
);
1395 ret
= cpu_ldq_user(env
, addr
);
1401 case 0x14: /* Bypass */
1402 case 0x15: /* Bypass, non-cacheable */
1403 case 0x1c: /* Bypass LE */
1404 case 0x1d: /* Bypass, non-cacheable LE */
1408 ret
= ldub_phys(addr
);
1411 ret
= lduw_phys(addr
);
1414 ret
= ldl_phys(addr
);
1418 ret
= ldq_phys(addr
);
1423 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1424 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1425 Only ldda allowed */
1426 helper_raise_exception(env
, TT_ILL_INSN
);
1428 case 0x04: /* Nucleus */
1429 case 0x0c: /* Nucleus Little Endian (LE) */
1433 ret
= cpu_ldub_nucleus(env
, addr
);
1436 ret
= cpu_lduw_nucleus(env
, addr
);
1439 ret
= cpu_ldl_nucleus(env
, addr
);
1443 ret
= cpu_ldq_nucleus(env
, addr
);
1448 case 0x4a: /* UPA config */
1451 case 0x45: /* LSU */
1454 case 0x50: /* I-MMU regs */
1456 int reg
= (addr
>> 3) & 0xf;
1459 /* I-TSB Tag Target register */
1460 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1462 ret
= env
->immuregs
[reg
];
1467 case 0x51: /* I-MMU 8k TSB pointer */
1469 /* env->immuregs[5] holds I-MMU TSB register value
1470 env->immuregs[6] holds I-MMU Tag Access register value */
1471 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1475 case 0x52: /* I-MMU 64k TSB pointer */
1477 /* env->immuregs[5] holds I-MMU TSB register value
1478 env->immuregs[6] holds I-MMU Tag Access register value */
1479 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1483 case 0x55: /* I-MMU data access */
1485 int reg
= (addr
>> 3) & 0x3f;
1487 ret
= env
->itlb
[reg
].tte
;
1490 case 0x56: /* I-MMU tag read */
1492 int reg
= (addr
>> 3) & 0x3f;
1494 ret
= env
->itlb
[reg
].tag
;
1497 case 0x58: /* D-MMU regs */
1499 int reg
= (addr
>> 3) & 0xf;
1502 /* D-TSB Tag Target register */
1503 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1505 ret
= env
->dmmuregs
[reg
];
1509 case 0x59: /* D-MMU 8k TSB pointer */
1511 /* env->dmmuregs[5] holds D-MMU TSB register value
1512 env->dmmuregs[6] holds D-MMU Tag Access register value */
1513 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1517 case 0x5a: /* D-MMU 64k TSB pointer */
1519 /* env->dmmuregs[5] holds D-MMU TSB register value
1520 env->dmmuregs[6] holds D-MMU Tag Access register value */
1521 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1525 case 0x5d: /* D-MMU data access */
1527 int reg
= (addr
>> 3) & 0x3f;
1529 ret
= env
->dtlb
[reg
].tte
;
1532 case 0x5e: /* D-MMU tag read */
1534 int reg
= (addr
>> 3) & 0x3f;
1536 ret
= env
->dtlb
[reg
].tag
;
1539 case 0x48: /* Interrupt dispatch, RO */
1541 case 0x49: /* Interrupt data receive */
1542 ret
= env
->ivec_status
;
1544 case 0x7f: /* Incoming interrupt vector, RO */
1546 int reg
= (addr
>> 4) & 0x3;
1548 ret
= env
->ivec_data
[reg
];
1552 case 0x46: /* D-cache data */
1553 case 0x47: /* D-cache tag access */
1554 case 0x4b: /* E-cache error enable */
1555 case 0x4c: /* E-cache asynchronous fault status */
1556 case 0x4d: /* E-cache asynchronous fault address */
1557 case 0x4e: /* E-cache tag data */
1558 case 0x66: /* I-cache instruction access */
1559 case 0x67: /* I-cache tag access */
1560 case 0x6e: /* I-cache predecode */
1561 case 0x6f: /* I-cache LRU etc. */
1562 case 0x76: /* E-cache tag */
1563 case 0x7e: /* E-cache tag */
1565 case 0x5b: /* D-MMU data pointer */
1566 case 0x54: /* I-MMU data in, WO */
1567 case 0x57: /* I-MMU demap, WO */
1568 case 0x5c: /* D-MMU data in, WO */
1569 case 0x5f: /* D-MMU demap, WO */
1570 case 0x77: /* Interrupt vector, WO */
1572 cpu_unassigned_access(env
, addr
, 0, 0, 1, size
);
1577 /* Convert from little endian */
1579 case 0x0c: /* Nucleus Little Endian (LE) */
1580 case 0x18: /* As if user primary LE */
1581 case 0x19: /* As if user secondary LE */
1582 case 0x1c: /* Bypass LE */
1583 case 0x1d: /* Bypass, non-cacheable LE */
1584 case 0x88: /* Primary LE */
1585 case 0x89: /* Secondary LE */
1603 /* Convert to signed number */
1610 ret
= (int16_t) ret
;
1613 ret
= (int32_t) ret
;
1620 dump_asi("read ", last_addr
, asi
, size
, ret
);
1625 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1629 dump_asi("write", addr
, asi
, size
, val
);
1634 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1635 || (cpu_has_hypervisor(env
)
1636 && asi
>= 0x30 && asi
< 0x80
1637 && !(env
->hpstate
& HS_PRIV
))) {
1638 helper_raise_exception(env
, TT_PRIV_ACT
);
1641 helper_check_align(env
, addr
, size
- 1);
1642 addr
= asi_address_mask(env
, asi
, addr
);
1644 /* Convert to little endian */
1646 case 0x0c: /* Nucleus Little Endian (LE) */
1647 case 0x18: /* As if user primary LE */
1648 case 0x19: /* As if user secondary LE */
1649 case 0x1c: /* Bypass LE */
1650 case 0x1d: /* Bypass, non-cacheable LE */
1651 case 0x88: /* Primary LE */
1652 case 0x89: /* Secondary LE */
1671 case 0x10: /* As if user primary */
1672 case 0x11: /* As if user secondary */
1673 case 0x18: /* As if user primary LE */
1674 case 0x19: /* As if user secondary LE */
1675 case 0x80: /* Primary */
1676 case 0x81: /* Secondary */
1677 case 0x88: /* Primary LE */
1678 case 0x89: /* Secondary LE */
1679 case 0xe2: /* UA2007 Primary block init */
1680 case 0xe3: /* UA2007 Secondary block init */
1681 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1682 if (cpu_hypervisor_mode(env
)) {
1685 cpu_stb_hypv(env
, addr
, val
);
1688 cpu_stw_hypv(env
, addr
, val
);
1691 cpu_stl_hypv(env
, addr
, val
);
1695 cpu_stq_hypv(env
, addr
, val
);
1699 /* secondary space access has lowest asi bit equal to 1 */
1703 cpu_stb_kernel_secondary(env
, addr
, val
);
1706 cpu_stw_kernel_secondary(env
, addr
, val
);
1709 cpu_stl_kernel_secondary(env
, addr
, val
);
1713 cpu_stq_kernel_secondary(env
, addr
, val
);
1719 cpu_stb_kernel(env
, addr
, val
);
1722 cpu_stw_kernel(env
, addr
, val
);
1725 cpu_stl_kernel(env
, addr
, val
);
1729 cpu_stq_kernel(env
, addr
, val
);
1735 /* secondary space access has lowest asi bit equal to 1 */
1739 cpu_stb_user_secondary(env
, addr
, val
);
1742 cpu_stw_user_secondary(env
, addr
, val
);
1745 cpu_stl_user_secondary(env
, addr
, val
);
1749 cpu_stq_user_secondary(env
, addr
, val
);
1755 cpu_stb_user(env
, addr
, val
);
1758 cpu_stw_user(env
, addr
, val
);
1761 cpu_stl_user(env
, addr
, val
);
1765 cpu_stq_user(env
, addr
, val
);
1771 case 0x14: /* Bypass */
1772 case 0x15: /* Bypass, non-cacheable */
1773 case 0x1c: /* Bypass LE */
1774 case 0x1d: /* Bypass, non-cacheable LE */
1778 stb_phys(addr
, val
);
1781 stw_phys(addr
, val
);
1784 stl_phys(addr
, val
);
1788 stq_phys(addr
, val
);
1793 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1794 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1795 Only ldda allowed */
1796 helper_raise_exception(env
, TT_ILL_INSN
);
1798 case 0x04: /* Nucleus */
1799 case 0x0c: /* Nucleus Little Endian (LE) */
1803 cpu_stb_nucleus(env
, addr
, val
);
1806 cpu_stw_nucleus(env
, addr
, val
);
1809 cpu_stl_nucleus(env
, addr
, val
);
1813 cpu_stq_nucleus(env
, addr
, val
);
1819 case 0x4a: /* UPA config */
1822 case 0x45: /* LSU */
1827 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1828 /* Mappings generated during D/I MMU disabled mode are
1829 invalid in normal mode */
1830 if (oldreg
!= env
->lsu
) {
1831 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1834 dump_mmu(stdout
, fprintf
, env1
);
1840 case 0x50: /* I-MMU regs */
1842 int reg
= (addr
>> 3) & 0xf;
1845 oldreg
= env
->immuregs
[reg
];
1849 case 1: /* Not in I-MMU */
1853 if ((val
& 1) == 0) {
1854 val
= 0; /* Clear SFSR */
1856 env
->immu
.sfsr
= val
;
1860 case 5: /* TSB access */
1861 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1862 PRIx64
"\n", env
->immu
.tsb
, val
);
1863 env
->immu
.tsb
= val
;
1865 case 6: /* Tag access */
1866 env
->immu
.tag_access
= val
;
1875 if (oldreg
!= env
->immuregs
[reg
]) {
1876 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1877 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1880 dump_mmu(stdout
, fprintf
, env
);
1884 case 0x54: /* I-MMU data in */
1885 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
1887 case 0x55: /* I-MMU data access */
1889 /* TODO: auto demap */
1891 unsigned int i
= (addr
>> 3) & 0x3f;
1893 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
1896 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1897 dump_mmu(stdout
, fprintf
, env
);
1901 case 0x57: /* I-MMU demap */
1902 demap_tlb(env
->itlb
, addr
, "immu", env
);
1904 case 0x58: /* D-MMU regs */
1906 int reg
= (addr
>> 3) & 0xf;
1909 oldreg
= env
->dmmuregs
[reg
];
1915 if ((val
& 1) == 0) {
1916 val
= 0; /* Clear SFSR, Fault address */
1919 env
->dmmu
.sfsr
= val
;
1921 case 1: /* Primary context */
1922 env
->dmmu
.mmu_primary_context
= val
;
1923 /* can be optimized to only flush MMU_USER_IDX
1924 and MMU_KERNEL_IDX entries */
1927 case 2: /* Secondary context */
1928 env
->dmmu
.mmu_secondary_context
= val
;
1929 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1930 and MMU_KERNEL_SECONDARY_IDX entries */
1933 case 5: /* TSB access */
1934 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1935 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1936 env
->dmmu
.tsb
= val
;
1938 case 6: /* Tag access */
1939 env
->dmmu
.tag_access
= val
;
1941 case 7: /* Virtual Watchpoint */
1942 case 8: /* Physical Watchpoint */
1944 env
->dmmuregs
[reg
] = val
;
1948 if (oldreg
!= env
->dmmuregs
[reg
]) {
1949 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1950 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1953 dump_mmu(stdout
, fprintf
, env
);
1957 case 0x5c: /* D-MMU data in */
1958 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
1960 case 0x5d: /* D-MMU data access */
1962 unsigned int i
= (addr
>> 3) & 0x3f;
1964 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
1967 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1968 dump_mmu(stdout
, fprintf
, env
);
1972 case 0x5f: /* D-MMU demap */
1973 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1975 case 0x49: /* Interrupt data receive */
1976 env
->ivec_status
= val
& 0x20;
1978 case 0x46: /* D-cache data */
1979 case 0x47: /* D-cache tag access */
1980 case 0x4b: /* E-cache error enable */
1981 case 0x4c: /* E-cache asynchronous fault status */
1982 case 0x4d: /* E-cache asynchronous fault address */
1983 case 0x4e: /* E-cache tag data */
1984 case 0x66: /* I-cache instruction access */
1985 case 0x67: /* I-cache tag access */
1986 case 0x6e: /* I-cache predecode */
1987 case 0x6f: /* I-cache LRU etc. */
1988 case 0x76: /* E-cache tag */
1989 case 0x7e: /* E-cache tag */
1991 case 0x51: /* I-MMU 8k TSB pointer, RO */
1992 case 0x52: /* I-MMU 64k TSB pointer, RO */
1993 case 0x56: /* I-MMU tag read, RO */
1994 case 0x59: /* D-MMU 8k TSB pointer, RO */
1995 case 0x5a: /* D-MMU 64k TSB pointer, RO */
1996 case 0x5b: /* D-MMU data pointer, RO */
1997 case 0x5e: /* D-MMU tag read, RO */
1998 case 0x48: /* Interrupt dispatch, RO */
1999 case 0x7f: /* Incoming interrupt vector, RO */
2000 case 0x82: /* Primary no-fault, RO */
2001 case 0x83: /* Secondary no-fault, RO */
2002 case 0x8a: /* Primary no-fault LE, RO */
2003 case 0x8b: /* Secondary no-fault LE, RO */
2005 cpu_unassigned_access(env
, addr
, 1, 0, 1, size
);
2009 #endif /* CONFIG_USER_ONLY */
2011 void helper_ldda_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int rd
)
2013 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2014 || (cpu_has_hypervisor(env
)
2015 && asi
>= 0x30 && asi
< 0x80
2016 && !(env
->hpstate
& HS_PRIV
))) {
2017 helper_raise_exception(env
, TT_PRIV_ACT
);
2020 addr
= asi_address_mask(env
, asi
, addr
);
2023 #if !defined(CONFIG_USER_ONLY)
2024 case 0x24: /* Nucleus quad LDD 128 bit atomic */
2025 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE */
2026 helper_check_align(env
, addr
, 0xf);
2028 env
->gregs
[1] = cpu_ldq_nucleus(env
, addr
+ 8);
2030 bswap64s(&env
->gregs
[1]);
2032 } else if (rd
< 8) {
2033 env
->gregs
[rd
] = cpu_ldq_nucleus(env
, addr
);
2034 env
->gregs
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2036 bswap64s(&env
->gregs
[rd
]);
2037 bswap64s(&env
->gregs
[rd
+ 1]);
2040 env
->regwptr
[rd
] = cpu_ldq_nucleus(env
, addr
);
2041 env
->regwptr
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2043 bswap64s(&env
->regwptr
[rd
]);
2044 bswap64s(&env
->regwptr
[rd
+ 1]);
2050 helper_check_align(env
, addr
, 0x3);
2052 env
->gregs
[1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2053 } else if (rd
< 8) {
2054 env
->gregs
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2055 env
->gregs
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2057 env
->regwptr
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2058 env
->regwptr
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2064 void helper_ldf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2070 helper_check_align(env
, addr
, 3);
2071 addr
= asi_address_mask(env
, asi
, addr
);
2074 case 0xf0: /* UA2007/JPS1 Block load primary */
2075 case 0xf1: /* UA2007/JPS1 Block load secondary */
2076 case 0xf8: /* UA2007/JPS1 Block load primary LE */
2077 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
2079 helper_raise_exception(env
, TT_ILL_INSN
);
2082 helper_check_align(env
, addr
, 0x3f);
2083 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2084 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x8f, 8, 0);
2088 case 0x16: /* UA2007 Block load primary, user privilege */
2089 case 0x17: /* UA2007 Block load secondary, user privilege */
2090 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2091 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2092 case 0x70: /* JPS1 Block load primary, user privilege */
2093 case 0x71: /* JPS1 Block load secondary, user privilege */
2094 case 0x78: /* JPS1 Block load primary LE, user privilege */
2095 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2097 helper_raise_exception(env
, TT_ILL_INSN
);
2100 helper_check_align(env
, addr
, 0x3f);
2101 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 4) {
2102 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x19, 8, 0);
2113 val
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2115 env
->fpr
[rd
/ 2].l
.lower
= val
;
2117 env
->fpr
[rd
/ 2].l
.upper
= val
;
2121 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2124 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2125 env
->fpr
[rd
/ 2 + 1].ll
= helper_ld_asi(env
, addr
+ 8, asi
, 8, 0);
2130 void helper_stf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2136 helper_check_align(env
, addr
, 3);
2137 addr
= asi_address_mask(env
, asi
, addr
);
2140 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
2141 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
2142 case 0xf0: /* UA2007/JPS1 Block store primary */
2143 case 0xf1: /* UA2007/JPS1 Block store secondary */
2144 case 0xf8: /* UA2007/JPS1 Block store primary LE */
2145 case 0xf9: /* UA2007/JPS1 Block store secondary LE */
2147 helper_raise_exception(env
, TT_ILL_INSN
);
2150 helper_check_align(env
, addr
, 0x3f);
2151 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2152 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x8f, 8);
2156 case 0x16: /* UA2007 Block load primary, user privilege */
2157 case 0x17: /* UA2007 Block load secondary, user privilege */
2158 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2159 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2160 case 0x70: /* JPS1 Block store primary, user privilege */
2161 case 0x71: /* JPS1 Block store secondary, user privilege */
2162 case 0x78: /* JPS1 Block load primary LE, user privilege */
2163 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2165 helper_raise_exception(env
, TT_ILL_INSN
);
2168 helper_check_align(env
, addr
, 0x3f);
2169 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2170 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x19, 8);
2182 val
= env
->fpr
[rd
/ 2].l
.lower
;
2184 val
= env
->fpr
[rd
/ 2].l
.upper
;
2186 helper_st_asi(env
, addr
, val
, asi
, size
);
2189 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, size
);
2192 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, 8);
2193 helper_st_asi(env
, addr
+ 8, env
->fpr
[rd
/ 2 + 1].ll
, asi
, 8);
2198 target_ulong
helper_cas_asi(CPUSPARCState
*env
, target_ulong addr
,
2199 target_ulong val1
, target_ulong val2
, uint32_t asi
)
2203 val2
&= 0xffffffffUL
;
2204 ret
= helper_ld_asi(env
, addr
, asi
, 4, 0);
2205 ret
&= 0xffffffffUL
;
2207 helper_st_asi(env
, addr
, val1
& 0xffffffffUL
, asi
, 4);
2212 target_ulong
helper_casx_asi(CPUSPARCState
*env
, target_ulong addr
,
2213 target_ulong val1
, target_ulong val2
,
2218 ret
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2220 helper_st_asi(env
, addr
, val1
, asi
, 8);
2224 #endif /* TARGET_SPARC64 */
2226 void helper_ldqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2228 /* XXX add 128 bit load */
2231 helper_check_align(env
, addr
, 7);
2232 #if !defined(CONFIG_USER_ONLY)
2235 u
.ll
.upper
= cpu_ldq_user(env
, addr
);
2236 u
.ll
.lower
= cpu_ldq_user(env
, addr
+ 8);
2239 case MMU_KERNEL_IDX
:
2240 u
.ll
.upper
= cpu_ldq_kernel(env
, addr
);
2241 u
.ll
.lower
= cpu_ldq_kernel(env
, addr
+ 8);
2244 #ifdef TARGET_SPARC64
2246 u
.ll
.upper
= cpu_ldq_hypv(env
, addr
);
2247 u
.ll
.lower
= cpu_ldq_hypv(env
, addr
+ 8);
2252 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
2256 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
2257 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
2262 void helper_stqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2264 /* XXX add 128 bit store */
2267 helper_check_align(env
, addr
, 7);
2268 #if !defined(CONFIG_USER_ONLY)
2272 cpu_stq_user(env
, addr
, u
.ll
.upper
);
2273 cpu_stq_user(env
, addr
+ 8, u
.ll
.lower
);
2275 case MMU_KERNEL_IDX
:
2277 cpu_stq_kernel(env
, addr
, u
.ll
.upper
);
2278 cpu_stq_kernel(env
, addr
+ 8, u
.ll
.lower
);
2280 #ifdef TARGET_SPARC64
2283 cpu_stq_hypv(env
, addr
, u
.ll
.upper
);
2284 cpu_stq_hypv(env
, addr
+ 8, u
.ll
.lower
);
2288 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
2293 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
2294 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
2298 #if !defined(CONFIG_USER_ONLY)
2299 #ifndef TARGET_SPARC64
2300 void cpu_unassigned_access(CPUSPARCState
*env
, target_phys_addr_t addr
,
2301 int is_write
, int is_exec
, int is_asi
, int size
)
2305 #ifdef DEBUG_UNASSIGNED
2307 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2308 " asi 0x%02x from " TARGET_FMT_lx
"\n",
2309 is_exec
? "exec" : is_write
? "write" : "read", size
,
2310 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
2312 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2313 " from " TARGET_FMT_lx
"\n",
2314 is_exec
? "exec" : is_write
? "write" : "read", size
,
2315 size
== 1 ? "" : "s", addr
, env
->pc
);
2318 /* Don't overwrite translation and access faults */
2319 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
2320 if ((fault_type
> 4) || (fault_type
== 0)) {
2321 env
->mmuregs
[3] = 0; /* Fault status register */
2323 env
->mmuregs
[3] |= 1 << 16;
2326 env
->mmuregs
[3] |= 1 << 5;
2329 env
->mmuregs
[3] |= 1 << 6;
2332 env
->mmuregs
[3] |= 1 << 7;
2334 env
->mmuregs
[3] |= (5 << 2) | 2;
2335 /* SuperSPARC will never place instruction fault addresses in the FAR */
2337 env
->mmuregs
[4] = addr
; /* Fault address register */
2340 /* overflow (same type fault was not read before another fault) */
2341 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
2342 env
->mmuregs
[3] |= 1;
2345 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2347 helper_raise_exception(env
, TT_CODE_ACCESS
);
2349 helper_raise_exception(env
, TT_DATA_ACCESS
);
2353 /* flush neverland mappings created during no-fault mode,
2354 so the sequential MMU faults report proper fault types */
2355 if (env
->mmuregs
[0] & MMU_NF
) {
2360 void cpu_unassigned_access(CPUSPARCState
*env
, target_phys_addr_t addr
,
2361 int is_write
, int is_exec
, int is_asi
, int size
)
2363 #ifdef DEBUG_UNASSIGNED
2364 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
2365 "\n", addr
, env
->pc
);
2369 helper_raise_exception(env
, TT_CODE_ACCESS
);
2371 helper_raise_exception(env
, TT_DATA_ACCESS
);
2377 #if !defined(CONFIG_USER_ONLY)
2378 /* XXX: make it generic ? */
2379 static void cpu_restore_state2(CPUSPARCState
*env
, uintptr_t retaddr
)
2381 TranslationBlock
*tb
;
2384 /* now we have a real cpu fault */
2385 tb
= tb_find_pc(retaddr
);
2387 /* the PC is inside the translated code. It means that we have
2388 a virtual CPU fault */
2389 cpu_restore_state(tb
, env
, retaddr
);
2394 void do_unaligned_access(CPUSPARCState
*env
, target_ulong addr
, int is_write
,
2395 int is_user
, uintptr_t retaddr
)
2397 #ifdef DEBUG_UNALIGNED
2398 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
2399 "\n", addr
, env
->pc
);
2401 cpu_restore_state2(env
, retaddr
);
2402 helper_raise_exception(env
, TT_UNALIGNED
);
2405 /* try to fill the TLB and return an exception if error. If retaddr is
2406 NULL, it means that the function was called in C code (i.e. not
2407 from generated code or from helper.c) */
2408 /* XXX: fix it to restore all registers */
2409 void tlb_fill(CPUSPARCState
*env
, target_ulong addr
, int is_write
, int mmu_idx
,
2414 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
2416 cpu_restore_state2(env
, retaddr
);