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/>.
21 #include "exec/helper-proto.h"
22 #include "exec/cpu_ldst.h"
26 //#define DEBUG_UNALIGNED
27 //#define DEBUG_UNASSIGNED
29 //#define DEBUG_CACHE_CONTROL
32 #define DPRINTF_MMU(fmt, ...) \
33 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
35 #define DPRINTF_MMU(fmt, ...) do {} while (0)
39 #define DPRINTF_MXCC(fmt, ...) \
40 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
42 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
46 #define DPRINTF_ASI(fmt, ...) \
47 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
50 #ifdef DEBUG_CACHE_CONTROL
51 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
52 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
54 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
59 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
61 #define AM_CHECK(env1) (1)
65 #define QT0 (env->qt0)
66 #define QT1 (env->qt1)
68 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
69 /* Calculates TSB pointer value for fault page size 8k or 64k */
70 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
71 uint64_t tag_access_register
,
74 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
75 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
76 int tsb_size
= tsb_register
& 0xf;
78 /* discard lower 13 bits which hold tag access context */
79 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
81 /* now reorder bits */
82 uint64_t tsb_base_mask
= ~0x1fffULL
;
83 uint64_t va
= tag_access_va
;
85 /* move va bits to correct position */
86 if (page_size
== 8*1024) {
88 } else if (page_size
== 64*1024) {
93 tsb_base_mask
<<= tsb_size
;
96 /* calculate tsb_base mask and adjust va if split is in use */
98 if (page_size
== 8*1024) {
99 va
&= ~(1ULL << (13 + tsb_size
));
100 } else if (page_size
== 64*1024) {
101 va
|= (1ULL << (13 + tsb_size
));
106 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
109 /* Calculates tag target register value by reordering bits
110 in tag access register */
111 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
113 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
116 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
117 uint64_t tlb_tag
, uint64_t tlb_tte
,
120 target_ulong mask
, size
, va
, offset
;
122 /* flush page range if translation is valid */
123 if (TTE_IS_VALID(tlb
->tte
)) {
124 CPUState
*cs
= CPU(sparc_env_get_cpu(env1
));
126 mask
= 0xffffffffffffe000ULL
;
127 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
130 va
= tlb
->tag
& mask
;
132 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
133 tlb_flush_page(cs
, va
+ offset
);
141 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
142 const char *strmmu
, CPUSPARCState
*env1
)
148 int is_demap_context
= (demap_addr
>> 6) & 1;
151 switch ((demap_addr
>> 4) & 3) {
152 case 0: /* primary */
153 context
= env1
->dmmu
.mmu_primary_context
;
155 case 1: /* secondary */
156 context
= env1
->dmmu
.mmu_secondary_context
;
158 case 2: /* nucleus */
161 case 3: /* reserved */
166 for (i
= 0; i
< 64; i
++) {
167 if (TTE_IS_VALID(tlb
[i
].tte
)) {
169 if (is_demap_context
) {
170 /* will remove non-global entries matching context value */
171 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
172 !tlb_compare_context(&tlb
[i
], context
)) {
177 will remove any entry matching VA */
178 mask
= 0xffffffffffffe000ULL
;
179 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
181 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
185 /* entry should be global or matching context value */
186 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
187 !tlb_compare_context(&tlb
[i
], context
)) {
192 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
194 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
195 dump_mmu(stdout
, fprintf
, env1
);
201 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
202 uint64_t tlb_tag
, uint64_t tlb_tte
,
203 const char *strmmu
, CPUSPARCState
*env1
)
205 unsigned int i
, replace_used
;
207 /* Try replacing invalid entry */
208 for (i
= 0; i
< 64; i
++) {
209 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
210 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
212 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
213 dump_mmu(stdout
, fprintf
, env1
);
219 /* All entries are valid, try replacing unlocked entry */
221 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
223 /* Used entries are not replaced on first pass */
225 for (i
= 0; i
< 64; i
++) {
226 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
228 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
230 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
231 strmmu
, (replace_used
? "used" : "unused"), i
);
232 dump_mmu(stdout
, fprintf
, env1
);
238 /* Now reset used bit and search for unused entries again */
240 for (i
= 0; i
< 64; i
++) {
241 TTE_SET_UNUSED(tlb
[i
].tte
);
246 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
253 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
255 #ifdef TARGET_SPARC64
256 if (AM_CHECK(env1
)) {
257 addr
&= 0xffffffffULL
;
263 /* returns true if access using this ASI is to have address translated by MMU
264 otherwise access is to raw physical address */
265 static inline int is_translating_asi(int asi
)
267 #ifdef TARGET_SPARC64
268 /* Ultrasparc IIi translating asi
269 - note this list is defined by cpu implementation
285 /* TODO: check sparc32 bits */
290 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
291 int asi
, target_ulong addr
)
293 if (is_translating_asi(asi
)) {
294 return address_mask(env
, addr
);
300 void helper_check_align(CPUSPARCState
*env
, target_ulong addr
, uint32_t align
)
303 #ifdef DEBUG_UNALIGNED
304 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
305 "\n", addr
, env
->pc
);
307 helper_raise_exception(env
, TT_UNALIGNED
);
311 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
313 static void dump_mxcc(CPUSPARCState
*env
)
315 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
317 env
->mxccdata
[0], env
->mxccdata
[1],
318 env
->mxccdata
[2], env
->mxccdata
[3]);
319 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
321 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
323 env
->mxccregs
[0], env
->mxccregs
[1],
324 env
->mxccregs
[2], env
->mxccregs
[3],
325 env
->mxccregs
[4], env
->mxccregs
[5],
326 env
->mxccregs
[6], env
->mxccregs
[7]);
330 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
331 && defined(DEBUG_ASI)
332 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
337 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
338 addr
, asi
, r1
& 0xff);
341 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
342 addr
, asi
, r1
& 0xffff);
345 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
346 addr
, asi
, r1
& 0xffffffff);
349 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
356 #ifndef TARGET_SPARC64
357 #ifndef CONFIG_USER_ONLY
360 /* Leon3 cache control */
362 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
363 uint64_t val
, int size
)
365 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
369 DPRINTF_CACHE_CONTROL("32bits only\n");
374 case 0x00: /* Cache control */
376 /* These values must always be read as zeros */
377 val
&= ~CACHE_CTRL_FD
;
378 val
&= ~CACHE_CTRL_FI
;
379 val
&= ~CACHE_CTRL_IB
;
380 val
&= ~CACHE_CTRL_IP
;
381 val
&= ~CACHE_CTRL_DP
;
383 env
->cache_control
= val
;
385 case 0x04: /* Instruction cache configuration */
386 case 0x08: /* Data cache configuration */
390 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
395 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
401 DPRINTF_CACHE_CONTROL("32bits only\n");
406 case 0x00: /* Cache control */
407 ret
= env
->cache_control
;
410 /* Configuration registers are read and only always keep those
413 case 0x04: /* Instruction cache configuration */
416 case 0x08: /* Data cache configuration */
420 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
423 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
428 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
431 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
433 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
434 uint32_t last_addr
= addr
;
437 helper_check_align(env
, addr
, size
- 1);
439 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
441 case 0x00: /* Leon3 Cache Control */
442 case 0x08: /* Leon3 Instruction Cache config */
443 case 0x0C: /* Leon3 Date Cache config */
444 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
445 ret
= leon3_cache_control_ld(env
, addr
, size
);
448 case 0x01c00a00: /* MXCC control register */
450 ret
= env
->mxccregs
[3];
452 qemu_log_mask(LOG_UNIMP
,
453 "%08x: unimplemented access size: %d\n", addr
,
457 case 0x01c00a04: /* MXCC control register */
459 ret
= env
->mxccregs
[3];
461 qemu_log_mask(LOG_UNIMP
,
462 "%08x: unimplemented access size: %d\n", addr
,
466 case 0x01c00c00: /* Module reset register */
468 ret
= env
->mxccregs
[5];
469 /* should we do something here? */
471 qemu_log_mask(LOG_UNIMP
,
472 "%08x: unimplemented access size: %d\n", addr
,
476 case 0x01c00f00: /* MBus port address register */
478 ret
= env
->mxccregs
[7];
480 qemu_log_mask(LOG_UNIMP
,
481 "%08x: unimplemented access size: %d\n", addr
,
486 qemu_log_mask(LOG_UNIMP
,
487 "%08x: unimplemented address, size: %d\n", addr
,
491 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
492 "addr = %08x -> ret = %" PRIx64
","
493 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
498 case 3: /* MMU probe */
499 case 0x18: /* LEON3 MMU probe */
503 mmulev
= (addr
>> 8) & 15;
507 ret
= mmu_probe(env
, addr
, mmulev
);
509 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
513 case 4: /* read MMU regs */
514 case 0x19: /* LEON3 read MMU regs */
516 int reg
= (addr
>> 8) & 0x1f;
518 ret
= env
->mmuregs
[reg
];
519 if (reg
== 3) { /* Fault status cleared on read */
521 } else if (reg
== 0x13) { /* Fault status read */
522 ret
= env
->mmuregs
[3];
523 } else if (reg
== 0x14) { /* Fault address read */
524 ret
= env
->mmuregs
[4];
526 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
529 case 5: /* Turbosparc ITLB Diagnostic */
530 case 6: /* Turbosparc DTLB Diagnostic */
531 case 7: /* Turbosparc IOTLB Diagnostic */
533 case 9: /* Supervisor code access */
536 ret
= cpu_ldub_code(env
, addr
);
539 ret
= cpu_lduw_code(env
, addr
);
543 ret
= cpu_ldl_code(env
, addr
);
546 ret
= cpu_ldq_code(env
, addr
);
550 case 0xa: /* User data access */
553 ret
= cpu_ldub_user(env
, addr
);
556 ret
= cpu_lduw_user(env
, addr
);
560 ret
= cpu_ldl_user(env
, addr
);
563 ret
= cpu_ldq_user(env
, addr
);
567 case 0xb: /* Supervisor data access */
571 ret
= cpu_ldub_kernel(env
, addr
);
574 ret
= cpu_lduw_kernel(env
, addr
);
578 ret
= cpu_ldl_kernel(env
, addr
);
581 ret
= cpu_ldq_kernel(env
, addr
);
585 case 0xc: /* I-cache tag */
586 case 0xd: /* I-cache data */
587 case 0xe: /* D-cache tag */
588 case 0xf: /* D-cache data */
590 case 0x20: /* MMU passthrough */
591 case 0x1c: /* LEON MMU passthrough */
594 ret
= ldub_phys(cs
->as
, addr
);
597 ret
= lduw_phys(cs
->as
, addr
);
601 ret
= ldl_phys(cs
->as
, addr
);
604 ret
= ldq_phys(cs
->as
, addr
);
608 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
611 ret
= ldub_phys(cs
->as
, (hwaddr
)addr
612 | ((hwaddr
)(asi
& 0xf) << 32));
615 ret
= lduw_phys(cs
->as
, (hwaddr
)addr
616 | ((hwaddr
)(asi
& 0xf) << 32));
620 ret
= ldl_phys(cs
->as
, (hwaddr
)addr
621 | ((hwaddr
)(asi
& 0xf) << 32));
624 ret
= ldq_phys(cs
->as
, (hwaddr
)addr
625 | ((hwaddr
)(asi
& 0xf) << 32));
629 case 0x30: /* Turbosparc secondary cache diagnostic */
630 case 0x31: /* Turbosparc RAM snoop */
631 case 0x32: /* Turbosparc page table descriptor diagnostic */
632 case 0x39: /* data cache diagnostic register */
635 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
637 int reg
= (addr
>> 8) & 3;
640 case 0: /* Breakpoint Value (Addr) */
641 ret
= env
->mmubpregs
[reg
];
643 case 1: /* Breakpoint Mask */
644 ret
= env
->mmubpregs
[reg
];
646 case 2: /* Breakpoint Control */
647 ret
= env
->mmubpregs
[reg
];
649 case 3: /* Breakpoint Status */
650 ret
= env
->mmubpregs
[reg
];
651 env
->mmubpregs
[reg
] = 0ULL;
654 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
658 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
659 ret
= env
->mmubpctrv
;
661 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
662 ret
= env
->mmubpctrc
;
664 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
665 ret
= env
->mmubpctrs
;
667 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
668 ret
= env
->mmubpaction
;
670 case 8: /* User code access, XXX */
672 cpu_unassigned_access(cs
, addr
, false, false, asi
, size
);
692 dump_asi("read ", last_addr
, asi
, size
, ret
);
697 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
, int asi
,
700 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
701 CPUState
*cs
= CPU(cpu
);
703 helper_check_align(env
, addr
, size
- 1);
705 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
707 case 0x00: /* Leon3 Cache Control */
708 case 0x08: /* Leon3 Instruction Cache config */
709 case 0x0C: /* Leon3 Date Cache config */
710 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
711 leon3_cache_control_st(env
, addr
, val
, size
);
715 case 0x01c00000: /* MXCC stream data register 0 */
717 env
->mxccdata
[0] = val
;
719 qemu_log_mask(LOG_UNIMP
,
720 "%08x: unimplemented access size: %d\n", addr
,
724 case 0x01c00008: /* MXCC stream data register 1 */
726 env
->mxccdata
[1] = val
;
728 qemu_log_mask(LOG_UNIMP
,
729 "%08x: unimplemented access size: %d\n", addr
,
733 case 0x01c00010: /* MXCC stream data register 2 */
735 env
->mxccdata
[2] = val
;
737 qemu_log_mask(LOG_UNIMP
,
738 "%08x: unimplemented access size: %d\n", addr
,
742 case 0x01c00018: /* MXCC stream data register 3 */
744 env
->mxccdata
[3] = val
;
746 qemu_log_mask(LOG_UNIMP
,
747 "%08x: unimplemented access size: %d\n", addr
,
751 case 0x01c00100: /* MXCC stream source */
753 env
->mxccregs
[0] = val
;
755 qemu_log_mask(LOG_UNIMP
,
756 "%08x: unimplemented access size: %d\n", addr
,
759 env
->mxccdata
[0] = ldq_phys(cs
->as
,
760 (env
->mxccregs
[0] & 0xffffffffULL
) +
762 env
->mxccdata
[1] = ldq_phys(cs
->as
,
763 (env
->mxccregs
[0] & 0xffffffffULL
) +
765 env
->mxccdata
[2] = ldq_phys(cs
->as
,
766 (env
->mxccregs
[0] & 0xffffffffULL
) +
768 env
->mxccdata
[3] = ldq_phys(cs
->as
,
769 (env
->mxccregs
[0] & 0xffffffffULL
) +
772 case 0x01c00200: /* MXCC stream destination */
774 env
->mxccregs
[1] = val
;
776 qemu_log_mask(LOG_UNIMP
,
777 "%08x: unimplemented access size: %d\n", addr
,
780 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 0,
782 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 8,
784 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 16,
786 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 24,
789 case 0x01c00a00: /* MXCC control register */
791 env
->mxccregs
[3] = val
;
793 qemu_log_mask(LOG_UNIMP
,
794 "%08x: unimplemented access size: %d\n", addr
,
798 case 0x01c00a04: /* MXCC control register */
800 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
803 qemu_log_mask(LOG_UNIMP
,
804 "%08x: unimplemented access size: %d\n", addr
,
808 case 0x01c00e00: /* MXCC error register */
809 /* writing a 1 bit clears the error */
811 env
->mxccregs
[6] &= ~val
;
813 qemu_log_mask(LOG_UNIMP
,
814 "%08x: unimplemented access size: %d\n", addr
,
818 case 0x01c00f00: /* MBus port address register */
820 env
->mxccregs
[7] = val
;
822 qemu_log_mask(LOG_UNIMP
,
823 "%08x: unimplemented access size: %d\n", addr
,
828 qemu_log_mask(LOG_UNIMP
,
829 "%08x: unimplemented address, size: %d\n", addr
,
833 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
834 asi
, size
, addr
, val
);
839 case 3: /* MMU flush */
840 case 0x18: /* LEON3 MMU flush */
844 mmulev
= (addr
>> 8) & 15;
845 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
847 case 0: /* flush page */
848 tlb_flush_page(CPU(cpu
), addr
& 0xfffff000);
850 case 1: /* flush segment (256k) */
851 case 2: /* flush region (16M) */
852 case 3: /* flush context (4G) */
853 case 4: /* flush entire */
854 tlb_flush(CPU(cpu
), 1);
860 dump_mmu(stdout
, fprintf
, env
);
864 case 4: /* write MMU regs */
865 case 0x19: /* LEON3 write MMU regs */
867 int reg
= (addr
>> 8) & 0x1f;
870 oldreg
= env
->mmuregs
[reg
];
872 case 0: /* Control Register */
873 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
875 /* Mappings generated during no-fault mode or MMU
876 disabled mode are invalid in normal mode */
877 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
878 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
))) {
879 tlb_flush(CPU(cpu
), 1);
882 case 1: /* Context Table Pointer Register */
883 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
885 case 2: /* Context Register */
886 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
887 if (oldreg
!= env
->mmuregs
[reg
]) {
888 /* we flush when the MMU context changes because
889 QEMU has no MMU context support */
890 tlb_flush(CPU(cpu
), 1);
893 case 3: /* Synchronous Fault Status Register with Clear */
894 case 4: /* Synchronous Fault Address Register */
896 case 0x10: /* TLB Replacement Control Register */
897 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
899 case 0x13: /* Synchronous Fault Status Register with Read
901 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
903 case 0x14: /* Synchronous Fault Address Register */
904 env
->mmuregs
[4] = val
;
907 env
->mmuregs
[reg
] = val
;
910 if (oldreg
!= env
->mmuregs
[reg
]) {
911 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
912 reg
, oldreg
, env
->mmuregs
[reg
]);
915 dump_mmu(stdout
, fprintf
, env
);
919 case 5: /* Turbosparc ITLB Diagnostic */
920 case 6: /* Turbosparc DTLB Diagnostic */
921 case 7: /* Turbosparc IOTLB Diagnostic */
923 case 0xa: /* User data access */
926 cpu_stb_user(env
, addr
, val
);
929 cpu_stw_user(env
, addr
, val
);
933 cpu_stl_user(env
, addr
, val
);
936 cpu_stq_user(env
, addr
, val
);
940 case 0xb: /* Supervisor data access */
944 cpu_stb_kernel(env
, addr
, val
);
947 cpu_stw_kernel(env
, addr
, val
);
951 cpu_stl_kernel(env
, addr
, val
);
954 cpu_stq_kernel(env
, addr
, val
);
958 case 0xc: /* I-cache tag */
959 case 0xd: /* I-cache data */
960 case 0xe: /* D-cache tag */
961 case 0xf: /* D-cache data */
962 case 0x10: /* I/D-cache flush page */
963 case 0x11: /* I/D-cache flush segment */
964 case 0x12: /* I/D-cache flush region */
965 case 0x13: /* I/D-cache flush context */
966 case 0x14: /* I/D-cache flush user */
968 case 0x17: /* Block copy, sta access */
974 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
976 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
977 temp
= cpu_ldl_kernel(env
, src
);
978 cpu_stl_kernel(env
, dst
, temp
);
982 case 0x1f: /* Block fill, stda access */
985 fill 32 bytes with val */
987 uint32_t dst
= addr
& 7;
989 for (i
= 0; i
< 32; i
+= 8, dst
+= 8) {
990 cpu_stq_kernel(env
, dst
, val
);
994 case 0x20: /* MMU passthrough */
995 case 0x1c: /* LEON MMU passthrough */
999 stb_phys(cs
->as
, addr
, val
);
1002 stw_phys(cs
->as
, addr
, val
);
1006 stl_phys(cs
->as
, addr
, val
);
1009 stq_phys(cs
->as
, addr
, val
);
1014 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1018 stb_phys(cs
->as
, (hwaddr
)addr
1019 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1022 stw_phys(cs
->as
, (hwaddr
)addr
1023 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1027 stl_phys(cs
->as
, (hwaddr
)addr
1028 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1031 stq_phys(cs
->as
, (hwaddr
)addr
1032 | ((hwaddr
)(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(CPU(sparc_env_get_cpu(env
)),
1083 addr
, true, false, asi
, size
);
1087 dump_asi("write", addr
, asi
, size
, val
);
1091 #endif /* CONFIG_USER_ONLY */
1092 #else /* TARGET_SPARC64 */
1094 #ifdef CONFIG_USER_ONLY
1095 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1099 #if defined(DEBUG_ASI)
1100 target_ulong last_addr
= addr
;
1104 helper_raise_exception(env
, TT_PRIV_ACT
);
1107 helper_check_align(env
, addr
, size
- 1);
1108 addr
= asi_address_mask(env
, asi
, addr
);
1111 case 0x82: /* Primary no-fault */
1112 case 0x8a: /* Primary no-fault LE */
1113 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1115 dump_asi("read ", last_addr
, asi
, size
, ret
);
1120 case 0x80: /* Primary */
1121 case 0x88: /* Primary LE */
1125 ret
= ldub_raw(addr
);
1128 ret
= lduw_raw(addr
);
1131 ret
= ldl_raw(addr
);
1135 ret
= ldq_raw(addr
);
1140 case 0x83: /* Secondary no-fault */
1141 case 0x8b: /* Secondary no-fault LE */
1142 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1144 dump_asi("read ", last_addr
, asi
, size
, ret
);
1149 case 0x81: /* Secondary */
1150 case 0x89: /* Secondary LE */
1157 /* Convert from little endian */
1159 case 0x88: /* Primary LE */
1160 case 0x89: /* Secondary LE */
1161 case 0x8a: /* Primary no-fault LE */
1162 case 0x8b: /* Secondary no-fault LE */
1180 /* Convert to signed number */
1187 ret
= (int16_t) ret
;
1190 ret
= (int32_t) ret
;
1197 dump_asi("read ", last_addr
, asi
, size
, ret
);
1202 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1206 dump_asi("write", addr
, asi
, size
, val
);
1209 helper_raise_exception(env
, TT_PRIV_ACT
);
1212 helper_check_align(env
, addr
, size
- 1);
1213 addr
= asi_address_mask(env
, asi
, addr
);
1215 /* Convert to little endian */
1217 case 0x88: /* Primary LE */
1218 case 0x89: /* Secondary LE */
1237 case 0x80: /* Primary */
1238 case 0x88: /* Primary LE */
1257 case 0x81: /* Secondary */
1258 case 0x89: /* Secondary LE */
1262 case 0x82: /* Primary no-fault, RO */
1263 case 0x83: /* Secondary no-fault, RO */
1264 case 0x8a: /* Primary no-fault LE, RO */
1265 case 0x8b: /* Secondary no-fault LE, RO */
1267 helper_raise_exception(env
, TT_DATA_ACCESS
);
1272 #else /* CONFIG_USER_ONLY */
1274 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1277 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
1279 #if defined(DEBUG_ASI)
1280 target_ulong last_addr
= addr
;
1285 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1286 || (cpu_has_hypervisor(env
)
1287 && asi
>= 0x30 && asi
< 0x80
1288 && !(env
->hpstate
& HS_PRIV
))) {
1289 helper_raise_exception(env
, TT_PRIV_ACT
);
1292 helper_check_align(env
, addr
, size
- 1);
1293 addr
= asi_address_mask(env
, asi
, addr
);
1295 /* process nonfaulting loads first */
1296 if ((asi
& 0xf6) == 0x82) {
1299 /* secondary space access has lowest asi bit equal to 1 */
1300 if (env
->pstate
& PS_PRIV
) {
1301 mmu_idx
= (asi
& 1) ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
;
1303 mmu_idx
= (asi
& 1) ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
;
1306 if (cpu_get_phys_page_nofault(env
, addr
, mmu_idx
) == -1ULL) {
1308 dump_asi("read ", last_addr
, asi
, size
, ret
);
1310 /* env->exception_index is set in get_physical_address_data(). */
1311 helper_raise_exception(env
, cs
->exception_index
);
1314 /* convert nonfaulting load ASIs to normal load ASIs */
1319 case 0x10: /* As if user primary */
1320 case 0x11: /* As if user secondary */
1321 case 0x18: /* As if user primary LE */
1322 case 0x19: /* As if user secondary LE */
1323 case 0x80: /* Primary */
1324 case 0x81: /* Secondary */
1325 case 0x88: /* Primary LE */
1326 case 0x89: /* Secondary LE */
1327 case 0xe2: /* UA2007 Primary block init */
1328 case 0xe3: /* UA2007 Secondary block init */
1329 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1330 if (cpu_hypervisor_mode(env
)) {
1333 ret
= cpu_ldub_hypv(env
, addr
);
1336 ret
= cpu_lduw_hypv(env
, addr
);
1339 ret
= cpu_ldl_hypv(env
, addr
);
1343 ret
= cpu_ldq_hypv(env
, addr
);
1347 /* secondary space access has lowest asi bit equal to 1 */
1351 ret
= cpu_ldub_kernel_secondary(env
, addr
);
1354 ret
= cpu_lduw_kernel_secondary(env
, addr
);
1357 ret
= cpu_ldl_kernel_secondary(env
, addr
);
1361 ret
= cpu_ldq_kernel_secondary(env
, addr
);
1367 ret
= cpu_ldub_kernel(env
, addr
);
1370 ret
= cpu_lduw_kernel(env
, addr
);
1373 ret
= cpu_ldl_kernel(env
, addr
);
1377 ret
= cpu_ldq_kernel(env
, addr
);
1383 /* secondary space access has lowest asi bit equal to 1 */
1387 ret
= cpu_ldub_user_secondary(env
, addr
);
1390 ret
= cpu_lduw_user_secondary(env
, addr
);
1393 ret
= cpu_ldl_user_secondary(env
, addr
);
1397 ret
= cpu_ldq_user_secondary(env
, addr
);
1403 ret
= cpu_ldub_user(env
, addr
);
1406 ret
= cpu_lduw_user(env
, addr
);
1409 ret
= cpu_ldl_user(env
, addr
);
1413 ret
= cpu_ldq_user(env
, addr
);
1419 case 0x14: /* Bypass */
1420 case 0x15: /* Bypass, non-cacheable */
1421 case 0x1c: /* Bypass LE */
1422 case 0x1d: /* Bypass, non-cacheable LE */
1426 ret
= ldub_phys(cs
->as
, addr
);
1429 ret
= lduw_phys(cs
->as
, addr
);
1432 ret
= ldl_phys(cs
->as
, addr
);
1436 ret
= ldq_phys(cs
->as
, addr
);
1441 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1442 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1443 Only ldda allowed */
1444 helper_raise_exception(env
, TT_ILL_INSN
);
1446 case 0x04: /* Nucleus */
1447 case 0x0c: /* Nucleus Little Endian (LE) */
1451 ret
= cpu_ldub_nucleus(env
, addr
);
1454 ret
= cpu_lduw_nucleus(env
, addr
);
1457 ret
= cpu_ldl_nucleus(env
, addr
);
1461 ret
= cpu_ldq_nucleus(env
, addr
);
1466 case 0x4a: /* UPA config */
1469 case 0x45: /* LSU */
1472 case 0x50: /* I-MMU regs */
1474 int reg
= (addr
>> 3) & 0xf;
1477 /* I-TSB Tag Target register */
1478 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1480 ret
= env
->immuregs
[reg
];
1485 case 0x51: /* I-MMU 8k TSB pointer */
1487 /* env->immuregs[5] holds I-MMU TSB register value
1488 env->immuregs[6] holds I-MMU Tag Access register value */
1489 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1493 case 0x52: /* I-MMU 64k TSB pointer */
1495 /* env->immuregs[5] holds I-MMU TSB register value
1496 env->immuregs[6] holds I-MMU Tag Access register value */
1497 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1501 case 0x55: /* I-MMU data access */
1503 int reg
= (addr
>> 3) & 0x3f;
1505 ret
= env
->itlb
[reg
].tte
;
1508 case 0x56: /* I-MMU tag read */
1510 int reg
= (addr
>> 3) & 0x3f;
1512 ret
= env
->itlb
[reg
].tag
;
1515 case 0x58: /* D-MMU regs */
1517 int reg
= (addr
>> 3) & 0xf;
1520 /* D-TSB Tag Target register */
1521 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1523 ret
= env
->dmmuregs
[reg
];
1527 case 0x59: /* D-MMU 8k TSB pointer */
1529 /* env->dmmuregs[5] holds D-MMU TSB register value
1530 env->dmmuregs[6] holds D-MMU Tag Access register value */
1531 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1535 case 0x5a: /* D-MMU 64k TSB pointer */
1537 /* env->dmmuregs[5] holds D-MMU TSB register value
1538 env->dmmuregs[6] holds D-MMU Tag Access register value */
1539 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1543 case 0x5d: /* D-MMU data access */
1545 int reg
= (addr
>> 3) & 0x3f;
1547 ret
= env
->dtlb
[reg
].tte
;
1550 case 0x5e: /* D-MMU tag read */
1552 int reg
= (addr
>> 3) & 0x3f;
1554 ret
= env
->dtlb
[reg
].tag
;
1557 case 0x48: /* Interrupt dispatch, RO */
1559 case 0x49: /* Interrupt data receive */
1560 ret
= env
->ivec_status
;
1562 case 0x7f: /* Incoming interrupt vector, RO */
1564 int reg
= (addr
>> 4) & 0x3;
1566 ret
= env
->ivec_data
[reg
];
1570 case 0x46: /* D-cache data */
1571 case 0x47: /* D-cache tag access */
1572 case 0x4b: /* E-cache error enable */
1573 case 0x4c: /* E-cache asynchronous fault status */
1574 case 0x4d: /* E-cache asynchronous fault address */
1575 case 0x4e: /* E-cache tag data */
1576 case 0x66: /* I-cache instruction access */
1577 case 0x67: /* I-cache tag access */
1578 case 0x6e: /* I-cache predecode */
1579 case 0x6f: /* I-cache LRU etc. */
1580 case 0x76: /* E-cache tag */
1581 case 0x7e: /* E-cache tag */
1583 case 0x5b: /* D-MMU data pointer */
1584 case 0x54: /* I-MMU data in, WO */
1585 case 0x57: /* I-MMU demap, WO */
1586 case 0x5c: /* D-MMU data in, WO */
1587 case 0x5f: /* D-MMU demap, WO */
1588 case 0x77: /* Interrupt vector, WO */
1590 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1595 /* Convert from little endian */
1597 case 0x0c: /* Nucleus Little Endian (LE) */
1598 case 0x18: /* As if user primary LE */
1599 case 0x19: /* As if user secondary LE */
1600 case 0x1c: /* Bypass LE */
1601 case 0x1d: /* Bypass, non-cacheable LE */
1602 case 0x88: /* Primary LE */
1603 case 0x89: /* Secondary LE */
1621 /* Convert to signed number */
1628 ret
= (int16_t) ret
;
1631 ret
= (int32_t) ret
;
1638 dump_asi("read ", last_addr
, asi
, size
, ret
);
1643 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1646 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
1647 CPUState
*cs
= CPU(cpu
);
1650 dump_asi("write", addr
, asi
, size
, val
);
1655 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1656 || (cpu_has_hypervisor(env
)
1657 && asi
>= 0x30 && asi
< 0x80
1658 && !(env
->hpstate
& HS_PRIV
))) {
1659 helper_raise_exception(env
, TT_PRIV_ACT
);
1662 helper_check_align(env
, addr
, size
- 1);
1663 addr
= asi_address_mask(env
, asi
, addr
);
1665 /* Convert to little endian */
1667 case 0x0c: /* Nucleus Little Endian (LE) */
1668 case 0x18: /* As if user primary LE */
1669 case 0x19: /* As if user secondary LE */
1670 case 0x1c: /* Bypass LE */
1671 case 0x1d: /* Bypass, non-cacheable LE */
1672 case 0x88: /* Primary LE */
1673 case 0x89: /* Secondary LE */
1692 case 0x10: /* As if user primary */
1693 case 0x11: /* As if user secondary */
1694 case 0x18: /* As if user primary LE */
1695 case 0x19: /* As if user secondary LE */
1696 case 0x80: /* Primary */
1697 case 0x81: /* Secondary */
1698 case 0x88: /* Primary LE */
1699 case 0x89: /* Secondary LE */
1700 case 0xe2: /* UA2007 Primary block init */
1701 case 0xe3: /* UA2007 Secondary block init */
1702 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1703 if (cpu_hypervisor_mode(env
)) {
1706 cpu_stb_hypv(env
, addr
, val
);
1709 cpu_stw_hypv(env
, addr
, val
);
1712 cpu_stl_hypv(env
, addr
, val
);
1716 cpu_stq_hypv(env
, addr
, val
);
1720 /* secondary space access has lowest asi bit equal to 1 */
1724 cpu_stb_kernel_secondary(env
, addr
, val
);
1727 cpu_stw_kernel_secondary(env
, addr
, val
);
1730 cpu_stl_kernel_secondary(env
, addr
, val
);
1734 cpu_stq_kernel_secondary(env
, addr
, val
);
1740 cpu_stb_kernel(env
, addr
, val
);
1743 cpu_stw_kernel(env
, addr
, val
);
1746 cpu_stl_kernel(env
, addr
, val
);
1750 cpu_stq_kernel(env
, addr
, val
);
1756 /* secondary space access has lowest asi bit equal to 1 */
1760 cpu_stb_user_secondary(env
, addr
, val
);
1763 cpu_stw_user_secondary(env
, addr
, val
);
1766 cpu_stl_user_secondary(env
, addr
, val
);
1770 cpu_stq_user_secondary(env
, addr
, val
);
1776 cpu_stb_user(env
, addr
, val
);
1779 cpu_stw_user(env
, addr
, val
);
1782 cpu_stl_user(env
, addr
, val
);
1786 cpu_stq_user(env
, addr
, val
);
1792 case 0x14: /* Bypass */
1793 case 0x15: /* Bypass, non-cacheable */
1794 case 0x1c: /* Bypass LE */
1795 case 0x1d: /* Bypass, non-cacheable LE */
1799 stb_phys(cs
->as
, addr
, val
);
1802 stw_phys(cs
->as
, addr
, val
);
1805 stl_phys(cs
->as
, addr
, val
);
1809 stq_phys(cs
->as
, addr
, val
);
1814 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1815 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1816 Only ldda allowed */
1817 helper_raise_exception(env
, TT_ILL_INSN
);
1819 case 0x04: /* Nucleus */
1820 case 0x0c: /* Nucleus Little Endian (LE) */
1824 cpu_stb_nucleus(env
, addr
, val
);
1827 cpu_stw_nucleus(env
, addr
, val
);
1830 cpu_stl_nucleus(env
, addr
, val
);
1834 cpu_stq_nucleus(env
, addr
, val
);
1840 case 0x4a: /* UPA config */
1843 case 0x45: /* LSU */
1848 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1849 /* Mappings generated during D/I MMU disabled mode are
1850 invalid in normal mode */
1851 if (oldreg
!= env
->lsu
) {
1852 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1855 dump_mmu(stdout
, fprintf
, env
);
1857 tlb_flush(CPU(cpu
), 1);
1861 case 0x50: /* I-MMU regs */
1863 int reg
= (addr
>> 3) & 0xf;
1866 oldreg
= env
->immuregs
[reg
];
1870 case 1: /* Not in I-MMU */
1874 if ((val
& 1) == 0) {
1875 val
= 0; /* Clear SFSR */
1877 env
->immu
.sfsr
= val
;
1881 case 5: /* TSB access */
1882 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1883 PRIx64
"\n", env
->immu
.tsb
, val
);
1884 env
->immu
.tsb
= val
;
1886 case 6: /* Tag access */
1887 env
->immu
.tag_access
= val
;
1896 if (oldreg
!= env
->immuregs
[reg
]) {
1897 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1898 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1901 dump_mmu(stdout
, fprintf
, env
);
1905 case 0x54: /* I-MMU data in */
1906 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
1908 case 0x55: /* I-MMU data access */
1910 /* TODO: auto demap */
1912 unsigned int i
= (addr
>> 3) & 0x3f;
1914 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
1917 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1918 dump_mmu(stdout
, fprintf
, env
);
1922 case 0x57: /* I-MMU demap */
1923 demap_tlb(env
->itlb
, addr
, "immu", env
);
1925 case 0x58: /* D-MMU regs */
1927 int reg
= (addr
>> 3) & 0xf;
1930 oldreg
= env
->dmmuregs
[reg
];
1936 if ((val
& 1) == 0) {
1937 val
= 0; /* Clear SFSR, Fault address */
1940 env
->dmmu
.sfsr
= val
;
1942 case 1: /* Primary context */
1943 env
->dmmu
.mmu_primary_context
= val
;
1944 /* can be optimized to only flush MMU_USER_IDX
1945 and MMU_KERNEL_IDX entries */
1946 tlb_flush(CPU(cpu
), 1);
1948 case 2: /* Secondary context */
1949 env
->dmmu
.mmu_secondary_context
= val
;
1950 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1951 and MMU_KERNEL_SECONDARY_IDX entries */
1952 tlb_flush(CPU(cpu
), 1);
1954 case 5: /* TSB access */
1955 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1956 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1957 env
->dmmu
.tsb
= val
;
1959 case 6: /* Tag access */
1960 env
->dmmu
.tag_access
= val
;
1962 case 7: /* Virtual Watchpoint */
1963 case 8: /* Physical Watchpoint */
1965 env
->dmmuregs
[reg
] = val
;
1969 if (oldreg
!= env
->dmmuregs
[reg
]) {
1970 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1971 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1974 dump_mmu(stdout
, fprintf
, env
);
1978 case 0x5c: /* D-MMU data in */
1979 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
1981 case 0x5d: /* D-MMU data access */
1983 unsigned int i
= (addr
>> 3) & 0x3f;
1985 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
1988 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1989 dump_mmu(stdout
, fprintf
, env
);
1993 case 0x5f: /* D-MMU demap */
1994 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1996 case 0x49: /* Interrupt data receive */
1997 env
->ivec_status
= val
& 0x20;
1999 case 0x46: /* D-cache data */
2000 case 0x47: /* D-cache tag access */
2001 case 0x4b: /* E-cache error enable */
2002 case 0x4c: /* E-cache asynchronous fault status */
2003 case 0x4d: /* E-cache asynchronous fault address */
2004 case 0x4e: /* E-cache tag data */
2005 case 0x66: /* I-cache instruction access */
2006 case 0x67: /* I-cache tag access */
2007 case 0x6e: /* I-cache predecode */
2008 case 0x6f: /* I-cache LRU etc. */
2009 case 0x76: /* E-cache tag */
2010 case 0x7e: /* E-cache tag */
2012 case 0x51: /* I-MMU 8k TSB pointer, RO */
2013 case 0x52: /* I-MMU 64k TSB pointer, RO */
2014 case 0x56: /* I-MMU tag read, RO */
2015 case 0x59: /* D-MMU 8k TSB pointer, RO */
2016 case 0x5a: /* D-MMU 64k TSB pointer, RO */
2017 case 0x5b: /* D-MMU data pointer, RO */
2018 case 0x5e: /* D-MMU tag read, RO */
2019 case 0x48: /* Interrupt dispatch, RO */
2020 case 0x7f: /* Incoming interrupt vector, RO */
2021 case 0x82: /* Primary no-fault, RO */
2022 case 0x83: /* Secondary no-fault, RO */
2023 case 0x8a: /* Primary no-fault LE, RO */
2024 case 0x8b: /* Secondary no-fault LE, RO */
2026 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
2030 #endif /* CONFIG_USER_ONLY */
2032 void helper_ldda_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int rd
)
2034 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2035 || (cpu_has_hypervisor(env
)
2036 && asi
>= 0x30 && asi
< 0x80
2037 && !(env
->hpstate
& HS_PRIV
))) {
2038 helper_raise_exception(env
, TT_PRIV_ACT
);
2041 addr
= asi_address_mask(env
, asi
, addr
);
2044 #if !defined(CONFIG_USER_ONLY)
2045 case 0x24: /* Nucleus quad LDD 128 bit atomic */
2046 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE */
2047 helper_check_align(env
, addr
, 0xf);
2049 env
->gregs
[1] = cpu_ldq_nucleus(env
, addr
+ 8);
2051 bswap64s(&env
->gregs
[1]);
2053 } else if (rd
< 8) {
2054 env
->gregs
[rd
] = cpu_ldq_nucleus(env
, addr
);
2055 env
->gregs
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2057 bswap64s(&env
->gregs
[rd
]);
2058 bswap64s(&env
->gregs
[rd
+ 1]);
2061 env
->regwptr
[rd
] = cpu_ldq_nucleus(env
, addr
);
2062 env
->regwptr
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2064 bswap64s(&env
->regwptr
[rd
]);
2065 bswap64s(&env
->regwptr
[rd
+ 1]);
2071 helper_check_align(env
, addr
, 0x3);
2073 env
->gregs
[1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2074 } else if (rd
< 8) {
2075 env
->gregs
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2076 env
->gregs
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2078 env
->regwptr
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2079 env
->regwptr
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2085 void helper_ldf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2091 helper_check_align(env
, addr
, 3);
2092 addr
= asi_address_mask(env
, asi
, addr
);
2095 case 0xf0: /* UA2007/JPS1 Block load primary */
2096 case 0xf1: /* UA2007/JPS1 Block load secondary */
2097 case 0xf8: /* UA2007/JPS1 Block load primary LE */
2098 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
2100 helper_raise_exception(env
, TT_ILL_INSN
);
2103 helper_check_align(env
, addr
, 0x3f);
2104 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2105 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x8f, 8, 0);
2109 case 0x16: /* UA2007 Block load primary, user privilege */
2110 case 0x17: /* UA2007 Block load secondary, user privilege */
2111 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2112 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2113 case 0x70: /* JPS1 Block load primary, user privilege */
2114 case 0x71: /* JPS1 Block load secondary, user privilege */
2115 case 0x78: /* JPS1 Block load primary LE, user privilege */
2116 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2118 helper_raise_exception(env
, TT_ILL_INSN
);
2121 helper_check_align(env
, addr
, 0x3f);
2122 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2123 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x19, 8, 0);
2134 val
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2136 env
->fpr
[rd
/ 2].l
.lower
= val
;
2138 env
->fpr
[rd
/ 2].l
.upper
= val
;
2142 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2145 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2146 env
->fpr
[rd
/ 2 + 1].ll
= helper_ld_asi(env
, addr
+ 8, asi
, 8, 0);
2151 void helper_stf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2157 addr
= asi_address_mask(env
, asi
, addr
);
2160 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
2161 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
2162 case 0xf0: /* UA2007/JPS1 Block store primary */
2163 case 0xf1: /* UA2007/JPS1 Block store secondary */
2164 case 0xf8: /* UA2007/JPS1 Block store primary LE */
2165 case 0xf9: /* UA2007/JPS1 Block store secondary LE */
2167 helper_raise_exception(env
, TT_ILL_INSN
);
2170 helper_check_align(env
, addr
, 0x3f);
2171 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2172 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x8f, 8);
2176 case 0x16: /* UA2007 Block load primary, user privilege */
2177 case 0x17: /* UA2007 Block load secondary, user privilege */
2178 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2179 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2180 case 0x70: /* JPS1 Block store primary, user privilege */
2181 case 0x71: /* JPS1 Block store secondary, user privilege */
2182 case 0x78: /* JPS1 Block load primary LE, user privilege */
2183 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2185 helper_raise_exception(env
, TT_ILL_INSN
);
2188 helper_check_align(env
, addr
, 0x3f);
2189 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2190 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x19, 8);
2194 case 0xd2: /* 16-bit floating point load primary */
2195 case 0xd3: /* 16-bit floating point load secondary */
2196 case 0xda: /* 16-bit floating point load primary, LE */
2197 case 0xdb: /* 16-bit floating point load secondary, LE */
2198 helper_check_align(env
, addr
, 1);
2200 case 0xd0: /* 8-bit floating point load primary */
2201 case 0xd1: /* 8-bit floating point load secondary */
2202 case 0xd8: /* 8-bit floating point load primary, LE */
2203 case 0xd9: /* 8-bit floating point load secondary, LE */
2204 val
= env
->fpr
[rd
/ 2].l
.lower
;
2205 helper_st_asi(env
, addr
, val
, asi
& 0x8d, ((asi
& 2) >> 1) + 1);
2208 helper_check_align(env
, addr
, 3);
2216 val
= env
->fpr
[rd
/ 2].l
.lower
;
2218 val
= env
->fpr
[rd
/ 2].l
.upper
;
2220 helper_st_asi(env
, addr
, val
, asi
, size
);
2223 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, size
);
2226 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, 8);
2227 helper_st_asi(env
, addr
+ 8, env
->fpr
[rd
/ 2 + 1].ll
, asi
, 8);
2232 target_ulong
helper_casx_asi(CPUSPARCState
*env
, target_ulong addr
,
2233 target_ulong val1
, target_ulong val2
,
2238 ret
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2240 helper_st_asi(env
, addr
, val1
, asi
, 8);
2244 #endif /* TARGET_SPARC64 */
2246 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2247 target_ulong
helper_cas_asi(CPUSPARCState
*env
, target_ulong addr
,
2248 target_ulong val1
, target_ulong val2
, uint32_t asi
)
2252 val2
&= 0xffffffffUL
;
2253 ret
= helper_ld_asi(env
, addr
, asi
, 4, 0);
2254 ret
&= 0xffffffffUL
;
2256 helper_st_asi(env
, addr
, val1
& 0xffffffffUL
, asi
, 4);
2260 #endif /* !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) */
2262 void helper_ldqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2264 /* XXX add 128 bit load */
2267 helper_check_align(env
, addr
, 7);
2268 #if !defined(CONFIG_USER_ONLY)
2271 u
.ll
.upper
= cpu_ldq_user(env
, addr
);
2272 u
.ll
.lower
= cpu_ldq_user(env
, addr
+ 8);
2275 case MMU_KERNEL_IDX
:
2276 u
.ll
.upper
= cpu_ldq_kernel(env
, addr
);
2277 u
.ll
.lower
= cpu_ldq_kernel(env
, addr
+ 8);
2280 #ifdef TARGET_SPARC64
2282 u
.ll
.upper
= cpu_ldq_hypv(env
, addr
);
2283 u
.ll
.lower
= cpu_ldq_hypv(env
, addr
+ 8);
2288 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
2292 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
2293 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
2298 void helper_stqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2300 /* XXX add 128 bit store */
2303 helper_check_align(env
, addr
, 7);
2304 #if !defined(CONFIG_USER_ONLY)
2308 cpu_stq_user(env
, addr
, u
.ll
.upper
);
2309 cpu_stq_user(env
, addr
+ 8, u
.ll
.lower
);
2311 case MMU_KERNEL_IDX
:
2313 cpu_stq_kernel(env
, addr
, u
.ll
.upper
);
2314 cpu_stq_kernel(env
, addr
+ 8, u
.ll
.lower
);
2316 #ifdef TARGET_SPARC64
2319 cpu_stq_hypv(env
, addr
, u
.ll
.upper
);
2320 cpu_stq_hypv(env
, addr
+ 8, u
.ll
.lower
);
2324 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
2329 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
2330 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
2334 #if !defined(CONFIG_USER_ONLY)
2335 #ifndef TARGET_SPARC64
2336 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2337 bool is_write
, bool is_exec
, int is_asi
,
2340 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2341 CPUSPARCState
*env
= &cpu
->env
;
2344 #ifdef DEBUG_UNASSIGNED
2346 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2347 " asi 0x%02x from " TARGET_FMT_lx
"\n",
2348 is_exec
? "exec" : is_write
? "write" : "read", size
,
2349 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
2351 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2352 " from " TARGET_FMT_lx
"\n",
2353 is_exec
? "exec" : is_write
? "write" : "read", size
,
2354 size
== 1 ? "" : "s", addr
, env
->pc
);
2357 /* Don't overwrite translation and access faults */
2358 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
2359 if ((fault_type
> 4) || (fault_type
== 0)) {
2360 env
->mmuregs
[3] = 0; /* Fault status register */
2362 env
->mmuregs
[3] |= 1 << 16;
2365 env
->mmuregs
[3] |= 1 << 5;
2368 env
->mmuregs
[3] |= 1 << 6;
2371 env
->mmuregs
[3] |= 1 << 7;
2373 env
->mmuregs
[3] |= (5 << 2) | 2;
2374 /* SuperSPARC will never place instruction fault addresses in the FAR */
2376 env
->mmuregs
[4] = addr
; /* Fault address register */
2379 /* overflow (same type fault was not read before another fault) */
2380 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
2381 env
->mmuregs
[3] |= 1;
2384 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2386 helper_raise_exception(env
, TT_CODE_ACCESS
);
2388 helper_raise_exception(env
, TT_DATA_ACCESS
);
2392 /* flush neverland mappings created during no-fault mode,
2393 so the sequential MMU faults report proper fault types */
2394 if (env
->mmuregs
[0] & MMU_NF
) {
2399 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2400 bool is_write
, bool is_exec
, int is_asi
,
2403 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2404 CPUSPARCState
*env
= &cpu
->env
;
2406 #ifdef DEBUG_UNASSIGNED
2407 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
2408 "\n", addr
, env
->pc
);
2412 helper_raise_exception(env
, TT_CODE_ACCESS
);
2414 helper_raise_exception(env
, TT_DATA_ACCESS
);
2420 #if !defined(CONFIG_USER_ONLY)
2421 void QEMU_NORETURN
sparc_cpu_do_unaligned_access(CPUState
*cs
,
2422 vaddr addr
, int is_write
,
2423 int is_user
, uintptr_t retaddr
)
2425 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2426 CPUSPARCState
*env
= &cpu
->env
;
2428 #ifdef DEBUG_UNALIGNED
2429 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
2430 "\n", addr
, env
->pc
);
2433 cpu_restore_state(CPU(cpu
), retaddr
);
2435 helper_raise_exception(env
, TT_UNALIGNED
);
2438 /* try to fill the TLB and return an exception if error. If retaddr is
2439 NULL, it means that the function was called in C code (i.e. not
2440 from generated code or from helper.c) */
2441 /* XXX: fix it to restore all registers */
2442 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
2447 ret
= sparc_cpu_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
2450 cpu_restore_state(cs
, retaddr
);