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 static void QEMU_NORETURN
do_unaligned_access(CPUSPARCState
*env
,
69 target_ulong addr
, int is_write
,
70 int is_user
, uintptr_t retaddr
);
71 #include "exec/softmmu_exec.h"
72 #define MMUSUFFIX _mmu
76 #include "exec/softmmu_template.h"
79 #include "exec/softmmu_template.h"
82 #include "exec/softmmu_template.h"
85 #include "exec/softmmu_template.h"
88 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
89 /* Calculates TSB pointer value for fault page size 8k or 64k */
90 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
91 uint64_t tag_access_register
,
94 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
95 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
96 int tsb_size
= tsb_register
& 0xf;
98 /* discard lower 13 bits which hold tag access context */
99 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
101 /* now reorder bits */
102 uint64_t tsb_base_mask
= ~0x1fffULL
;
103 uint64_t va
= tag_access_va
;
105 /* move va bits to correct position */
106 if (page_size
== 8*1024) {
108 } else if (page_size
== 64*1024) {
113 tsb_base_mask
<<= tsb_size
;
116 /* calculate tsb_base mask and adjust va if split is in use */
118 if (page_size
== 8*1024) {
119 va
&= ~(1ULL << (13 + tsb_size
));
120 } else if (page_size
== 64*1024) {
121 va
|= (1ULL << (13 + tsb_size
));
126 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
129 /* Calculates tag target register value by reordering bits
130 in tag access register */
131 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
133 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
136 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
137 uint64_t tlb_tag
, uint64_t tlb_tte
,
140 target_ulong mask
, size
, va
, offset
;
142 /* flush page range if translation is valid */
143 if (TTE_IS_VALID(tlb
->tte
)) {
145 mask
= 0xffffffffffffe000ULL
;
146 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
149 va
= tlb
->tag
& mask
;
151 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
152 tlb_flush_page(env1
, va
+ offset
);
160 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
161 const char *strmmu
, CPUSPARCState
*env1
)
167 int is_demap_context
= (demap_addr
>> 6) & 1;
170 switch ((demap_addr
>> 4) & 3) {
171 case 0: /* primary */
172 context
= env1
->dmmu
.mmu_primary_context
;
174 case 1: /* secondary */
175 context
= env1
->dmmu
.mmu_secondary_context
;
177 case 2: /* nucleus */
180 case 3: /* reserved */
185 for (i
= 0; i
< 64; i
++) {
186 if (TTE_IS_VALID(tlb
[i
].tte
)) {
188 if (is_demap_context
) {
189 /* will remove non-global entries matching context value */
190 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
191 !tlb_compare_context(&tlb
[i
], context
)) {
196 will remove any entry matching VA */
197 mask
= 0xffffffffffffe000ULL
;
198 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
200 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
204 /* entry should be global or matching context value */
205 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
206 !tlb_compare_context(&tlb
[i
], context
)) {
211 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
213 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
214 dump_mmu(stdout
, fprintf
, env1
);
220 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
221 uint64_t tlb_tag
, uint64_t tlb_tte
,
222 const char *strmmu
, CPUSPARCState
*env1
)
224 unsigned int i
, replace_used
;
226 /* Try replacing invalid entry */
227 for (i
= 0; i
< 64; i
++) {
228 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
229 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
231 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
232 dump_mmu(stdout
, fprintf
, env1
);
238 /* All entries are valid, try replacing unlocked entry */
240 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
242 /* Used entries are not replaced on first pass */
244 for (i
= 0; i
< 64; i
++) {
245 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
247 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
249 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
250 strmmu
, (replace_used
? "used" : "unused"), i
);
251 dump_mmu(stdout
, fprintf
, env1
);
257 /* Now reset used bit and search for unused entries again */
259 for (i
= 0; i
< 64; i
++) {
260 TTE_SET_UNUSED(tlb
[i
].tte
);
265 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
272 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
274 #ifdef TARGET_SPARC64
275 if (AM_CHECK(env1
)) {
276 addr
&= 0xffffffffULL
;
282 /* returns true if access using this ASI is to have address translated by MMU
283 otherwise access is to raw physical address */
284 static inline int is_translating_asi(int asi
)
286 #ifdef TARGET_SPARC64
287 /* Ultrasparc IIi translating asi
288 - note this list is defined by cpu implementation
304 /* TODO: check sparc32 bits */
309 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
310 int asi
, target_ulong addr
)
312 if (is_translating_asi(asi
)) {
313 return address_mask(env
, addr
);
319 void helper_check_align(CPUSPARCState
*env
, target_ulong addr
, uint32_t align
)
322 #ifdef DEBUG_UNALIGNED
323 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
324 "\n", addr
, env
->pc
);
326 helper_raise_exception(env
, TT_UNALIGNED
);
330 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
332 static void dump_mxcc(CPUSPARCState
*env
)
334 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
336 env
->mxccdata
[0], env
->mxccdata
[1],
337 env
->mxccdata
[2], env
->mxccdata
[3]);
338 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
340 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
342 env
->mxccregs
[0], env
->mxccregs
[1],
343 env
->mxccregs
[2], env
->mxccregs
[3],
344 env
->mxccregs
[4], env
->mxccregs
[5],
345 env
->mxccregs
[6], env
->mxccregs
[7]);
349 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
350 && defined(DEBUG_ASI)
351 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
356 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
357 addr
, asi
, r1
& 0xff);
360 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
361 addr
, asi
, r1
& 0xffff);
364 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
365 addr
, asi
, r1
& 0xffffffff);
368 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
375 #ifndef TARGET_SPARC64
376 #ifndef CONFIG_USER_ONLY
379 /* Leon3 cache control */
381 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
382 uint64_t val
, int size
)
384 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
388 DPRINTF_CACHE_CONTROL("32bits only\n");
393 case 0x00: /* Cache control */
395 /* These values must always be read as zeros */
396 val
&= ~CACHE_CTRL_FD
;
397 val
&= ~CACHE_CTRL_FI
;
398 val
&= ~CACHE_CTRL_IB
;
399 val
&= ~CACHE_CTRL_IP
;
400 val
&= ~CACHE_CTRL_DP
;
402 env
->cache_control
= val
;
404 case 0x04: /* Instruction cache configuration */
405 case 0x08: /* Data cache configuration */
409 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
414 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
420 DPRINTF_CACHE_CONTROL("32bits only\n");
425 case 0x00: /* Cache control */
426 ret
= env
->cache_control
;
429 /* Configuration registers are read and only always keep those
432 case 0x04: /* Instruction cache configuration */
435 case 0x08: /* Data cache configuration */
439 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
442 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
447 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
451 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
452 uint32_t last_addr
= addr
;
455 helper_check_align(env
, addr
, size
- 1);
457 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
459 case 0x00: /* Leon3 Cache Control */
460 case 0x08: /* Leon3 Instruction Cache config */
461 case 0x0C: /* Leon3 Date Cache config */
462 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
463 ret
= leon3_cache_control_ld(env
, addr
, size
);
466 case 0x01c00a00: /* MXCC control register */
468 ret
= env
->mxccregs
[3];
470 qemu_log_mask(LOG_UNIMP
,
471 "%08x: unimplemented access size: %d\n", addr
,
475 case 0x01c00a04: /* MXCC control register */
477 ret
= env
->mxccregs
[3];
479 qemu_log_mask(LOG_UNIMP
,
480 "%08x: unimplemented access size: %d\n", addr
,
484 case 0x01c00c00: /* Module reset register */
486 ret
= env
->mxccregs
[5];
487 /* should we do something here? */
489 qemu_log_mask(LOG_UNIMP
,
490 "%08x: unimplemented access size: %d\n", addr
,
494 case 0x01c00f00: /* MBus port address register */
496 ret
= env
->mxccregs
[7];
498 qemu_log_mask(LOG_UNIMP
,
499 "%08x: unimplemented access size: %d\n", addr
,
504 qemu_log_mask(LOG_UNIMP
,
505 "%08x: unimplemented address, size: %d\n", addr
,
509 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
510 "addr = %08x -> ret = %" PRIx64
","
511 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
516 case 3: /* MMU probe */
517 case 0x18: /* LEON3 MMU probe */
521 mmulev
= (addr
>> 8) & 15;
525 ret
= mmu_probe(env
, addr
, mmulev
);
527 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
531 case 4: /* read MMU regs */
532 case 0x19: /* LEON3 read MMU regs */
534 int reg
= (addr
>> 8) & 0x1f;
536 ret
= env
->mmuregs
[reg
];
537 if (reg
== 3) { /* Fault status cleared on read */
539 } else if (reg
== 0x13) { /* Fault status read */
540 ret
= env
->mmuregs
[3];
541 } else if (reg
== 0x14) { /* Fault address read */
542 ret
= env
->mmuregs
[4];
544 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
547 case 5: /* Turbosparc ITLB Diagnostic */
548 case 6: /* Turbosparc DTLB Diagnostic */
549 case 7: /* Turbosparc IOTLB Diagnostic */
551 case 9: /* Supervisor code access */
554 ret
= cpu_ldub_code(env
, addr
);
557 ret
= cpu_lduw_code(env
, addr
);
561 ret
= cpu_ldl_code(env
, addr
);
564 ret
= cpu_ldq_code(env
, addr
);
568 case 0xa: /* User data access */
571 ret
= cpu_ldub_user(env
, addr
);
574 ret
= cpu_lduw_user(env
, addr
);
578 ret
= cpu_ldl_user(env
, addr
);
581 ret
= cpu_ldq_user(env
, addr
);
585 case 0xb: /* Supervisor data access */
588 ret
= cpu_ldub_kernel(env
, addr
);
591 ret
= cpu_lduw_kernel(env
, addr
);
595 ret
= cpu_ldl_kernel(env
, addr
);
598 ret
= cpu_ldq_kernel(env
, addr
);
602 case 0xc: /* I-cache tag */
603 case 0xd: /* I-cache data */
604 case 0xe: /* D-cache tag */
605 case 0xf: /* D-cache data */
607 case 0x20: /* MMU passthrough */
608 case 0x1c: /* LEON MMU passthrough */
611 ret
= ldub_phys(addr
);
614 ret
= lduw_phys(addr
);
618 ret
= ldl_phys(addr
);
621 ret
= ldq_phys(addr
);
625 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
628 ret
= ldub_phys((hwaddr
)addr
629 | ((hwaddr
)(asi
& 0xf) << 32));
632 ret
= lduw_phys((hwaddr
)addr
633 | ((hwaddr
)(asi
& 0xf) << 32));
637 ret
= ldl_phys((hwaddr
)addr
638 | ((hwaddr
)(asi
& 0xf) << 32));
641 ret
= ldq_phys((hwaddr
)addr
642 | ((hwaddr
)(asi
& 0xf) << 32));
646 case 0x30: /* Turbosparc secondary cache diagnostic */
647 case 0x31: /* Turbosparc RAM snoop */
648 case 0x32: /* Turbosparc page table descriptor diagnostic */
649 case 0x39: /* data cache diagnostic register */
652 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
654 int reg
= (addr
>> 8) & 3;
657 case 0: /* Breakpoint Value (Addr) */
658 ret
= env
->mmubpregs
[reg
];
660 case 1: /* Breakpoint Mask */
661 ret
= env
->mmubpregs
[reg
];
663 case 2: /* Breakpoint Control */
664 ret
= env
->mmubpregs
[reg
];
666 case 3: /* Breakpoint Status */
667 ret
= env
->mmubpregs
[reg
];
668 env
->mmubpregs
[reg
] = 0ULL;
671 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
675 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
676 ret
= env
->mmubpctrv
;
678 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
679 ret
= env
->mmubpctrc
;
681 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
682 ret
= env
->mmubpctrs
;
684 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
685 ret
= env
->mmubpaction
;
687 case 8: /* User code access, XXX */
689 cpu_unassigned_access(CPU(sparc_env_get_cpu(env
)),
690 addr
, false, false, asi
, size
);
710 dump_asi("read ", last_addr
, asi
, size
, ret
);
715 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
, int asi
,
718 helper_check_align(env
, addr
, size
- 1);
720 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
722 case 0x00: /* Leon3 Cache Control */
723 case 0x08: /* Leon3 Instruction Cache config */
724 case 0x0C: /* Leon3 Date Cache config */
725 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
726 leon3_cache_control_st(env
, addr
, val
, size
);
730 case 0x01c00000: /* MXCC stream data register 0 */
732 env
->mxccdata
[0] = val
;
734 qemu_log_mask(LOG_UNIMP
,
735 "%08x: unimplemented access size: %d\n", addr
,
739 case 0x01c00008: /* MXCC stream data register 1 */
741 env
->mxccdata
[1] = val
;
743 qemu_log_mask(LOG_UNIMP
,
744 "%08x: unimplemented access size: %d\n", addr
,
748 case 0x01c00010: /* MXCC stream data register 2 */
750 env
->mxccdata
[2] = val
;
752 qemu_log_mask(LOG_UNIMP
,
753 "%08x: unimplemented access size: %d\n", addr
,
757 case 0x01c00018: /* MXCC stream data register 3 */
759 env
->mxccdata
[3] = val
;
761 qemu_log_mask(LOG_UNIMP
,
762 "%08x: unimplemented access size: %d\n", addr
,
766 case 0x01c00100: /* MXCC stream source */
768 env
->mxccregs
[0] = val
;
770 qemu_log_mask(LOG_UNIMP
,
771 "%08x: unimplemented access size: %d\n", addr
,
774 env
->mxccdata
[0] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
776 env
->mxccdata
[1] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
778 env
->mxccdata
[2] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
780 env
->mxccdata
[3] = ldq_phys((env
->mxccregs
[0] & 0xffffffffULL
) +
783 case 0x01c00200: /* MXCC stream destination */
785 env
->mxccregs
[1] = val
;
787 qemu_log_mask(LOG_UNIMP
,
788 "%08x: unimplemented access size: %d\n", addr
,
791 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 0,
793 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 8,
795 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 16,
797 stq_phys((env
->mxccregs
[1] & 0xffffffffULL
) + 24,
800 case 0x01c00a00: /* MXCC control register */
802 env
->mxccregs
[3] = val
;
804 qemu_log_mask(LOG_UNIMP
,
805 "%08x: unimplemented access size: %d\n", addr
,
809 case 0x01c00a04: /* MXCC control register */
811 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
814 qemu_log_mask(LOG_UNIMP
,
815 "%08x: unimplemented access size: %d\n", addr
,
819 case 0x01c00e00: /* MXCC error register */
820 /* writing a 1 bit clears the error */
822 env
->mxccregs
[6] &= ~val
;
824 qemu_log_mask(LOG_UNIMP
,
825 "%08x: unimplemented access size: %d\n", addr
,
829 case 0x01c00f00: /* MBus port address register */
831 env
->mxccregs
[7] = val
;
833 qemu_log_mask(LOG_UNIMP
,
834 "%08x: unimplemented access size: %d\n", addr
,
839 qemu_log_mask(LOG_UNIMP
,
840 "%08x: unimplemented address, size: %d\n", addr
,
844 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
845 asi
, size
, addr
, val
);
850 case 3: /* MMU flush */
851 case 0x18: /* LEON3 MMU flush */
855 mmulev
= (addr
>> 8) & 15;
856 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
858 case 0: /* flush page */
859 tlb_flush_page(env
, addr
& 0xfffff000);
861 case 1: /* flush segment (256k) */
862 case 2: /* flush region (16M) */
863 case 3: /* flush context (4G) */
864 case 4: /* flush entire */
871 dump_mmu(stdout
, fprintf
, env
);
875 case 4: /* write MMU regs */
876 case 0x19: /* LEON3 write MMU regs */
878 int reg
= (addr
>> 8) & 0x1f;
881 oldreg
= env
->mmuregs
[reg
];
883 case 0: /* Control Register */
884 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
886 /* Mappings generated during no-fault mode or MMU
887 disabled mode are invalid in normal mode */
888 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
889 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
))) {
893 case 1: /* Context Table Pointer Register */
894 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
896 case 2: /* Context Register */
897 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
898 if (oldreg
!= env
->mmuregs
[reg
]) {
899 /* we flush when the MMU context changes because
900 QEMU has no MMU context support */
904 case 3: /* Synchronous Fault Status Register with Clear */
905 case 4: /* Synchronous Fault Address Register */
907 case 0x10: /* TLB Replacement Control Register */
908 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
910 case 0x13: /* Synchronous Fault Status Register with Read
912 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
914 case 0x14: /* Synchronous Fault Address Register */
915 env
->mmuregs
[4] = val
;
918 env
->mmuregs
[reg
] = val
;
921 if (oldreg
!= env
->mmuregs
[reg
]) {
922 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
923 reg
, oldreg
, env
->mmuregs
[reg
]);
926 dump_mmu(stdout
, fprintf
, env
);
930 case 5: /* Turbosparc ITLB Diagnostic */
931 case 6: /* Turbosparc DTLB Diagnostic */
932 case 7: /* Turbosparc IOTLB Diagnostic */
934 case 0xa: /* User data access */
937 cpu_stb_user(env
, addr
, val
);
940 cpu_stw_user(env
, addr
, val
);
944 cpu_stl_user(env
, addr
, val
);
947 cpu_stq_user(env
, addr
, val
);
951 case 0xb: /* Supervisor data access */
954 cpu_stb_kernel(env
, addr
, val
);
957 cpu_stw_kernel(env
, addr
, val
);
961 cpu_stl_kernel(env
, addr
, val
);
964 cpu_stq_kernel(env
, addr
, val
);
968 case 0xc: /* I-cache tag */
969 case 0xd: /* I-cache data */
970 case 0xe: /* D-cache tag */
971 case 0xf: /* D-cache data */
972 case 0x10: /* I/D-cache flush page */
973 case 0x11: /* I/D-cache flush segment */
974 case 0x12: /* I/D-cache flush region */
975 case 0x13: /* I/D-cache flush context */
976 case 0x14: /* I/D-cache flush user */
978 case 0x17: /* Block copy, sta access */
984 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
986 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
987 temp
= cpu_ldl_kernel(env
, src
);
988 cpu_stl_kernel(env
, dst
, temp
);
992 case 0x1f: /* Block fill, stda access */
995 fill 32 bytes with val */
997 uint32_t dst
= addr
& 7;
999 for (i
= 0; i
< 32; i
+= 8, dst
+= 8) {
1000 cpu_stq_kernel(env
, dst
, val
);
1004 case 0x20: /* MMU passthrough */
1005 case 0x1c: /* LEON MMU passthrough */
1009 stb_phys(addr
, val
);
1012 stw_phys(addr
, val
);
1016 stl_phys(addr
, val
);
1019 stq_phys(addr
, val
);
1024 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1028 stb_phys((hwaddr
)addr
1029 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1032 stw_phys((hwaddr
)addr
1033 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1037 stl_phys((hwaddr
)addr
1038 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1041 stq_phys((hwaddr
)addr
1042 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1047 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1048 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1049 Turbosparc snoop RAM */
1050 case 0x32: /* store buffer control or Turbosparc page table
1051 descriptor diagnostic */
1052 case 0x36: /* I-cache flash clear */
1053 case 0x37: /* D-cache flash clear */
1055 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1057 int reg
= (addr
>> 8) & 3;
1060 case 0: /* Breakpoint Value (Addr) */
1061 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1063 case 1: /* Breakpoint Mask */
1064 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1066 case 2: /* Breakpoint Control */
1067 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1069 case 3: /* Breakpoint Status */
1070 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1073 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1077 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1078 env
->mmubpctrv
= val
& 0xffffffff;
1080 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1081 env
->mmubpctrc
= val
& 0x3;
1083 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1084 env
->mmubpctrs
= val
& 0x3;
1086 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1087 env
->mmubpaction
= val
& 0x1fff;
1089 case 8: /* User code access, XXX */
1090 case 9: /* Supervisor code access, XXX */
1092 cpu_unassigned_access(CPU(sparc_env_get_cpu(env
)),
1093 addr
, true, false, asi
, size
);
1097 dump_asi("write", addr
, asi
, size
, val
);
1101 #endif /* CONFIG_USER_ONLY */
1102 #else /* TARGET_SPARC64 */
1104 #ifdef CONFIG_USER_ONLY
1105 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1109 #if defined(DEBUG_ASI)
1110 target_ulong last_addr
= addr
;
1114 helper_raise_exception(env
, TT_PRIV_ACT
);
1117 helper_check_align(env
, addr
, size
- 1);
1118 addr
= asi_address_mask(env
, asi
, addr
);
1121 case 0x82: /* Primary no-fault */
1122 case 0x8a: /* Primary no-fault LE */
1123 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1125 dump_asi("read ", last_addr
, asi
, size
, ret
);
1130 case 0x80: /* Primary */
1131 case 0x88: /* Primary LE */
1135 ret
= ldub_raw(addr
);
1138 ret
= lduw_raw(addr
);
1141 ret
= ldl_raw(addr
);
1145 ret
= ldq_raw(addr
);
1150 case 0x83: /* Secondary no-fault */
1151 case 0x8b: /* Secondary no-fault LE */
1152 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1154 dump_asi("read ", last_addr
, asi
, size
, ret
);
1159 case 0x81: /* Secondary */
1160 case 0x89: /* Secondary LE */
1167 /* Convert from little endian */
1169 case 0x88: /* Primary LE */
1170 case 0x89: /* Secondary LE */
1171 case 0x8a: /* Primary no-fault LE */
1172 case 0x8b: /* Secondary no-fault LE */
1190 /* Convert to signed number */
1197 ret
= (int16_t) ret
;
1200 ret
= (int32_t) ret
;
1207 dump_asi("read ", last_addr
, asi
, size
, ret
);
1212 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1216 dump_asi("write", addr
, asi
, size
, val
);
1219 helper_raise_exception(env
, TT_PRIV_ACT
);
1222 helper_check_align(env
, addr
, size
- 1);
1223 addr
= asi_address_mask(env
, asi
, addr
);
1225 /* Convert to little endian */
1227 case 0x88: /* Primary LE */
1228 case 0x89: /* Secondary LE */
1247 case 0x80: /* Primary */
1248 case 0x88: /* Primary LE */
1267 case 0x81: /* Secondary */
1268 case 0x89: /* Secondary LE */
1272 case 0x82: /* Primary no-fault, RO */
1273 case 0x83: /* Secondary no-fault, RO */
1274 case 0x8a: /* Primary no-fault LE, RO */
1275 case 0x8b: /* Secondary no-fault LE, RO */
1277 helper_raise_exception(env
, TT_DATA_ACCESS
);
1282 #else /* CONFIG_USER_ONLY */
1284 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1288 #if defined(DEBUG_ASI)
1289 target_ulong last_addr
= addr
;
1294 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1295 || (cpu_has_hypervisor(env
)
1296 && asi
>= 0x30 && asi
< 0x80
1297 && !(env
->hpstate
& HS_PRIV
))) {
1298 helper_raise_exception(env
, TT_PRIV_ACT
);
1301 helper_check_align(env
, addr
, size
- 1);
1302 addr
= asi_address_mask(env
, asi
, addr
);
1304 /* process nonfaulting loads first */
1305 if ((asi
& 0xf6) == 0x82) {
1308 /* secondary space access has lowest asi bit equal to 1 */
1309 if (env
->pstate
& PS_PRIV
) {
1310 mmu_idx
= (asi
& 1) ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
;
1312 mmu_idx
= (asi
& 1) ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
;
1315 if (cpu_get_phys_page_nofault(env
, addr
, mmu_idx
) == -1ULL) {
1317 dump_asi("read ", last_addr
, asi
, size
, ret
);
1319 /* env->exception_index is set in get_physical_address_data(). */
1320 helper_raise_exception(env
, env
->exception_index
);
1323 /* convert nonfaulting load ASIs to normal load ASIs */
1328 case 0x10: /* As if user primary */
1329 case 0x11: /* As if user secondary */
1330 case 0x18: /* As if user primary LE */
1331 case 0x19: /* As if user secondary LE */
1332 case 0x80: /* Primary */
1333 case 0x81: /* Secondary */
1334 case 0x88: /* Primary LE */
1335 case 0x89: /* Secondary LE */
1336 case 0xe2: /* UA2007 Primary block init */
1337 case 0xe3: /* UA2007 Secondary block init */
1338 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1339 if (cpu_hypervisor_mode(env
)) {
1342 ret
= cpu_ldub_hypv(env
, addr
);
1345 ret
= cpu_lduw_hypv(env
, addr
);
1348 ret
= cpu_ldl_hypv(env
, addr
);
1352 ret
= cpu_ldq_hypv(env
, addr
);
1356 /* secondary space access has lowest asi bit equal to 1 */
1360 ret
= cpu_ldub_kernel_secondary(env
, addr
);
1363 ret
= cpu_lduw_kernel_secondary(env
, addr
);
1366 ret
= cpu_ldl_kernel_secondary(env
, addr
);
1370 ret
= cpu_ldq_kernel_secondary(env
, addr
);
1376 ret
= cpu_ldub_kernel(env
, addr
);
1379 ret
= cpu_lduw_kernel(env
, addr
);
1382 ret
= cpu_ldl_kernel(env
, addr
);
1386 ret
= cpu_ldq_kernel(env
, addr
);
1392 /* secondary space access has lowest asi bit equal to 1 */
1396 ret
= cpu_ldub_user_secondary(env
, addr
);
1399 ret
= cpu_lduw_user_secondary(env
, addr
);
1402 ret
= cpu_ldl_user_secondary(env
, addr
);
1406 ret
= cpu_ldq_user_secondary(env
, addr
);
1412 ret
= cpu_ldub_user(env
, addr
);
1415 ret
= cpu_lduw_user(env
, addr
);
1418 ret
= cpu_ldl_user(env
, addr
);
1422 ret
= cpu_ldq_user(env
, addr
);
1428 case 0x14: /* Bypass */
1429 case 0x15: /* Bypass, non-cacheable */
1430 case 0x1c: /* Bypass LE */
1431 case 0x1d: /* Bypass, non-cacheable LE */
1435 ret
= ldub_phys(addr
);
1438 ret
= lduw_phys(addr
);
1441 ret
= ldl_phys(addr
);
1445 ret
= ldq_phys(addr
);
1450 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1451 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1452 Only ldda allowed */
1453 helper_raise_exception(env
, TT_ILL_INSN
);
1455 case 0x04: /* Nucleus */
1456 case 0x0c: /* Nucleus Little Endian (LE) */
1460 ret
= cpu_ldub_nucleus(env
, addr
);
1463 ret
= cpu_lduw_nucleus(env
, addr
);
1466 ret
= cpu_ldl_nucleus(env
, addr
);
1470 ret
= cpu_ldq_nucleus(env
, addr
);
1475 case 0x4a: /* UPA config */
1478 case 0x45: /* LSU */
1481 case 0x50: /* I-MMU regs */
1483 int reg
= (addr
>> 3) & 0xf;
1486 /* I-TSB Tag Target register */
1487 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1489 ret
= env
->immuregs
[reg
];
1494 case 0x51: /* I-MMU 8k TSB pointer */
1496 /* env->immuregs[5] holds I-MMU TSB register value
1497 env->immuregs[6] holds I-MMU Tag Access register value */
1498 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1502 case 0x52: /* I-MMU 64k TSB pointer */
1504 /* env->immuregs[5] holds I-MMU TSB register value
1505 env->immuregs[6] holds I-MMU Tag Access register value */
1506 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1510 case 0x55: /* I-MMU data access */
1512 int reg
= (addr
>> 3) & 0x3f;
1514 ret
= env
->itlb
[reg
].tte
;
1517 case 0x56: /* I-MMU tag read */
1519 int reg
= (addr
>> 3) & 0x3f;
1521 ret
= env
->itlb
[reg
].tag
;
1524 case 0x58: /* D-MMU regs */
1526 int reg
= (addr
>> 3) & 0xf;
1529 /* D-TSB Tag Target register */
1530 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1532 ret
= env
->dmmuregs
[reg
];
1536 case 0x59: /* D-MMU 8k TSB pointer */
1538 /* env->dmmuregs[5] holds D-MMU TSB register value
1539 env->dmmuregs[6] holds D-MMU Tag Access register value */
1540 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1544 case 0x5a: /* D-MMU 64k TSB pointer */
1546 /* env->dmmuregs[5] holds D-MMU TSB register value
1547 env->dmmuregs[6] holds D-MMU Tag Access register value */
1548 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1552 case 0x5d: /* D-MMU data access */
1554 int reg
= (addr
>> 3) & 0x3f;
1556 ret
= env
->dtlb
[reg
].tte
;
1559 case 0x5e: /* D-MMU tag read */
1561 int reg
= (addr
>> 3) & 0x3f;
1563 ret
= env
->dtlb
[reg
].tag
;
1566 case 0x48: /* Interrupt dispatch, RO */
1568 case 0x49: /* Interrupt data receive */
1569 ret
= env
->ivec_status
;
1571 case 0x7f: /* Incoming interrupt vector, RO */
1573 int reg
= (addr
>> 4) & 0x3;
1575 ret
= env
->ivec_data
[reg
];
1579 case 0x46: /* D-cache data */
1580 case 0x47: /* D-cache tag access */
1581 case 0x4b: /* E-cache error enable */
1582 case 0x4c: /* E-cache asynchronous fault status */
1583 case 0x4d: /* E-cache asynchronous fault address */
1584 case 0x4e: /* E-cache tag data */
1585 case 0x66: /* I-cache instruction access */
1586 case 0x67: /* I-cache tag access */
1587 case 0x6e: /* I-cache predecode */
1588 case 0x6f: /* I-cache LRU etc. */
1589 case 0x76: /* E-cache tag */
1590 case 0x7e: /* E-cache tag */
1592 case 0x5b: /* D-MMU data pointer */
1593 case 0x54: /* I-MMU data in, WO */
1594 case 0x57: /* I-MMU demap, WO */
1595 case 0x5c: /* D-MMU data in, WO */
1596 case 0x5f: /* D-MMU demap, WO */
1597 case 0x77: /* Interrupt vector, WO */
1599 cpu_unassigned_access(CPU(sparc_env_get_cpu(env
)),
1600 addr
, false, false, 1, size
);
1605 /* Convert from little endian */
1607 case 0x0c: /* Nucleus Little Endian (LE) */
1608 case 0x18: /* As if user primary LE */
1609 case 0x19: /* As if user secondary LE */
1610 case 0x1c: /* Bypass LE */
1611 case 0x1d: /* Bypass, non-cacheable LE */
1612 case 0x88: /* Primary LE */
1613 case 0x89: /* Secondary LE */
1631 /* Convert to signed number */
1638 ret
= (int16_t) ret
;
1641 ret
= (int32_t) ret
;
1648 dump_asi("read ", last_addr
, asi
, size
, ret
);
1653 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1657 dump_asi("write", addr
, asi
, size
, val
);
1662 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1663 || (cpu_has_hypervisor(env
)
1664 && asi
>= 0x30 && asi
< 0x80
1665 && !(env
->hpstate
& HS_PRIV
))) {
1666 helper_raise_exception(env
, TT_PRIV_ACT
);
1669 helper_check_align(env
, addr
, size
- 1);
1670 addr
= asi_address_mask(env
, asi
, addr
);
1672 /* Convert to little endian */
1674 case 0x0c: /* Nucleus Little Endian (LE) */
1675 case 0x18: /* As if user primary LE */
1676 case 0x19: /* As if user secondary LE */
1677 case 0x1c: /* Bypass LE */
1678 case 0x1d: /* Bypass, non-cacheable LE */
1679 case 0x88: /* Primary LE */
1680 case 0x89: /* Secondary LE */
1699 case 0x10: /* As if user primary */
1700 case 0x11: /* As if user secondary */
1701 case 0x18: /* As if user primary LE */
1702 case 0x19: /* As if user secondary LE */
1703 case 0x80: /* Primary */
1704 case 0x81: /* Secondary */
1705 case 0x88: /* Primary LE */
1706 case 0x89: /* Secondary LE */
1707 case 0xe2: /* UA2007 Primary block init */
1708 case 0xe3: /* UA2007 Secondary block init */
1709 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1710 if (cpu_hypervisor_mode(env
)) {
1713 cpu_stb_hypv(env
, addr
, val
);
1716 cpu_stw_hypv(env
, addr
, val
);
1719 cpu_stl_hypv(env
, addr
, val
);
1723 cpu_stq_hypv(env
, addr
, val
);
1727 /* secondary space access has lowest asi bit equal to 1 */
1731 cpu_stb_kernel_secondary(env
, addr
, val
);
1734 cpu_stw_kernel_secondary(env
, addr
, val
);
1737 cpu_stl_kernel_secondary(env
, addr
, val
);
1741 cpu_stq_kernel_secondary(env
, addr
, val
);
1747 cpu_stb_kernel(env
, addr
, val
);
1750 cpu_stw_kernel(env
, addr
, val
);
1753 cpu_stl_kernel(env
, addr
, val
);
1757 cpu_stq_kernel(env
, addr
, val
);
1763 /* secondary space access has lowest asi bit equal to 1 */
1767 cpu_stb_user_secondary(env
, addr
, val
);
1770 cpu_stw_user_secondary(env
, addr
, val
);
1773 cpu_stl_user_secondary(env
, addr
, val
);
1777 cpu_stq_user_secondary(env
, addr
, val
);
1783 cpu_stb_user(env
, addr
, val
);
1786 cpu_stw_user(env
, addr
, val
);
1789 cpu_stl_user(env
, addr
, val
);
1793 cpu_stq_user(env
, addr
, val
);
1799 case 0x14: /* Bypass */
1800 case 0x15: /* Bypass, non-cacheable */
1801 case 0x1c: /* Bypass LE */
1802 case 0x1d: /* Bypass, non-cacheable LE */
1806 stb_phys(addr
, val
);
1809 stw_phys(addr
, val
);
1812 stl_phys(addr
, val
);
1816 stq_phys(addr
, val
);
1821 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1822 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1823 Only ldda allowed */
1824 helper_raise_exception(env
, TT_ILL_INSN
);
1826 case 0x04: /* Nucleus */
1827 case 0x0c: /* Nucleus Little Endian (LE) */
1831 cpu_stb_nucleus(env
, addr
, val
);
1834 cpu_stw_nucleus(env
, addr
, val
);
1837 cpu_stl_nucleus(env
, addr
, val
);
1841 cpu_stq_nucleus(env
, addr
, val
);
1847 case 0x4a: /* UPA config */
1850 case 0x45: /* LSU */
1855 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1856 /* Mappings generated during D/I MMU disabled mode are
1857 invalid in normal mode */
1858 if (oldreg
!= env
->lsu
) {
1859 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1862 dump_mmu(stdout
, fprintf
, env
);
1868 case 0x50: /* I-MMU regs */
1870 int reg
= (addr
>> 3) & 0xf;
1873 oldreg
= env
->immuregs
[reg
];
1877 case 1: /* Not in I-MMU */
1881 if ((val
& 1) == 0) {
1882 val
= 0; /* Clear SFSR */
1884 env
->immu
.sfsr
= val
;
1888 case 5: /* TSB access */
1889 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1890 PRIx64
"\n", env
->immu
.tsb
, val
);
1891 env
->immu
.tsb
= val
;
1893 case 6: /* Tag access */
1894 env
->immu
.tag_access
= val
;
1903 if (oldreg
!= env
->immuregs
[reg
]) {
1904 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1905 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1908 dump_mmu(stdout
, fprintf
, env
);
1912 case 0x54: /* I-MMU data in */
1913 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
1915 case 0x55: /* I-MMU data access */
1917 /* TODO: auto demap */
1919 unsigned int i
= (addr
>> 3) & 0x3f;
1921 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
1924 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1925 dump_mmu(stdout
, fprintf
, env
);
1929 case 0x57: /* I-MMU demap */
1930 demap_tlb(env
->itlb
, addr
, "immu", env
);
1932 case 0x58: /* D-MMU regs */
1934 int reg
= (addr
>> 3) & 0xf;
1937 oldreg
= env
->dmmuregs
[reg
];
1943 if ((val
& 1) == 0) {
1944 val
= 0; /* Clear SFSR, Fault address */
1947 env
->dmmu
.sfsr
= val
;
1949 case 1: /* Primary context */
1950 env
->dmmu
.mmu_primary_context
= val
;
1951 /* can be optimized to only flush MMU_USER_IDX
1952 and MMU_KERNEL_IDX entries */
1955 case 2: /* Secondary context */
1956 env
->dmmu
.mmu_secondary_context
= val
;
1957 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1958 and MMU_KERNEL_SECONDARY_IDX entries */
1961 case 5: /* TSB access */
1962 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1963 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1964 env
->dmmu
.tsb
= val
;
1966 case 6: /* Tag access */
1967 env
->dmmu
.tag_access
= val
;
1969 case 7: /* Virtual Watchpoint */
1970 case 8: /* Physical Watchpoint */
1972 env
->dmmuregs
[reg
] = val
;
1976 if (oldreg
!= env
->dmmuregs
[reg
]) {
1977 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1978 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1981 dump_mmu(stdout
, fprintf
, env
);
1985 case 0x5c: /* D-MMU data in */
1986 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
1988 case 0x5d: /* D-MMU data access */
1990 unsigned int i
= (addr
>> 3) & 0x3f;
1992 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
1995 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1996 dump_mmu(stdout
, fprintf
, env
);
2000 case 0x5f: /* D-MMU demap */
2001 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
2003 case 0x49: /* Interrupt data receive */
2004 env
->ivec_status
= val
& 0x20;
2006 case 0x46: /* D-cache data */
2007 case 0x47: /* D-cache tag access */
2008 case 0x4b: /* E-cache error enable */
2009 case 0x4c: /* E-cache asynchronous fault status */
2010 case 0x4d: /* E-cache asynchronous fault address */
2011 case 0x4e: /* E-cache tag data */
2012 case 0x66: /* I-cache instruction access */
2013 case 0x67: /* I-cache tag access */
2014 case 0x6e: /* I-cache predecode */
2015 case 0x6f: /* I-cache LRU etc. */
2016 case 0x76: /* E-cache tag */
2017 case 0x7e: /* E-cache tag */
2019 case 0x51: /* I-MMU 8k TSB pointer, RO */
2020 case 0x52: /* I-MMU 64k TSB pointer, RO */
2021 case 0x56: /* I-MMU tag read, RO */
2022 case 0x59: /* D-MMU 8k TSB pointer, RO */
2023 case 0x5a: /* D-MMU 64k TSB pointer, RO */
2024 case 0x5b: /* D-MMU data pointer, RO */
2025 case 0x5e: /* D-MMU tag read, RO */
2026 case 0x48: /* Interrupt dispatch, RO */
2027 case 0x7f: /* Incoming interrupt vector, RO */
2028 case 0x82: /* Primary no-fault, RO */
2029 case 0x83: /* Secondary no-fault, RO */
2030 case 0x8a: /* Primary no-fault LE, RO */
2031 case 0x8b: /* Secondary no-fault LE, RO */
2033 cpu_unassigned_access(CPU(sparc_env_get_cpu(env
)),
2034 addr
, true, false, 1, size
);
2038 #endif /* CONFIG_USER_ONLY */
2040 void helper_ldda_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int rd
)
2042 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2043 || (cpu_has_hypervisor(env
)
2044 && asi
>= 0x30 && asi
< 0x80
2045 && !(env
->hpstate
& HS_PRIV
))) {
2046 helper_raise_exception(env
, TT_PRIV_ACT
);
2049 addr
= asi_address_mask(env
, asi
, addr
);
2052 #if !defined(CONFIG_USER_ONLY)
2053 case 0x24: /* Nucleus quad LDD 128 bit atomic */
2054 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE */
2055 helper_check_align(env
, addr
, 0xf);
2057 env
->gregs
[1] = cpu_ldq_nucleus(env
, addr
+ 8);
2059 bswap64s(&env
->gregs
[1]);
2061 } else if (rd
< 8) {
2062 env
->gregs
[rd
] = cpu_ldq_nucleus(env
, addr
);
2063 env
->gregs
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2065 bswap64s(&env
->gregs
[rd
]);
2066 bswap64s(&env
->gregs
[rd
+ 1]);
2069 env
->regwptr
[rd
] = cpu_ldq_nucleus(env
, addr
);
2070 env
->regwptr
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2072 bswap64s(&env
->regwptr
[rd
]);
2073 bswap64s(&env
->regwptr
[rd
+ 1]);
2079 helper_check_align(env
, addr
, 0x3);
2081 env
->gregs
[1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2082 } else if (rd
< 8) {
2083 env
->gregs
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2084 env
->gregs
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2086 env
->regwptr
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2087 env
->regwptr
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2093 void helper_ldf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2099 helper_check_align(env
, addr
, 3);
2100 addr
= asi_address_mask(env
, asi
, addr
);
2103 case 0xf0: /* UA2007/JPS1 Block load primary */
2104 case 0xf1: /* UA2007/JPS1 Block load secondary */
2105 case 0xf8: /* UA2007/JPS1 Block load primary LE */
2106 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
2108 helper_raise_exception(env
, TT_ILL_INSN
);
2111 helper_check_align(env
, addr
, 0x3f);
2112 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2113 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x8f, 8, 0);
2117 case 0x16: /* UA2007 Block load primary, user privilege */
2118 case 0x17: /* UA2007 Block load secondary, user privilege */
2119 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2120 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2121 case 0x70: /* JPS1 Block load primary, user privilege */
2122 case 0x71: /* JPS1 Block load secondary, user privilege */
2123 case 0x78: /* JPS1 Block load primary LE, user privilege */
2124 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2126 helper_raise_exception(env
, TT_ILL_INSN
);
2129 helper_check_align(env
, addr
, 0x3f);
2130 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2131 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x19, 8, 0);
2142 val
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2144 env
->fpr
[rd
/ 2].l
.lower
= val
;
2146 env
->fpr
[rd
/ 2].l
.upper
= val
;
2150 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2153 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2154 env
->fpr
[rd
/ 2 + 1].ll
= helper_ld_asi(env
, addr
+ 8, asi
, 8, 0);
2159 void helper_stf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2165 helper_check_align(env
, addr
, 3);
2166 addr
= asi_address_mask(env
, asi
, addr
);
2169 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
2170 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
2171 case 0xf0: /* UA2007/JPS1 Block store primary */
2172 case 0xf1: /* UA2007/JPS1 Block store secondary */
2173 case 0xf8: /* UA2007/JPS1 Block store primary LE */
2174 case 0xf9: /* UA2007/JPS1 Block store secondary LE */
2176 helper_raise_exception(env
, TT_ILL_INSN
);
2179 helper_check_align(env
, addr
, 0x3f);
2180 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2181 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x8f, 8);
2185 case 0x16: /* UA2007 Block load primary, user privilege */
2186 case 0x17: /* UA2007 Block load secondary, user privilege */
2187 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2188 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2189 case 0x70: /* JPS1 Block store primary, user privilege */
2190 case 0x71: /* JPS1 Block store secondary, user privilege */
2191 case 0x78: /* JPS1 Block load primary LE, user privilege */
2192 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2194 helper_raise_exception(env
, TT_ILL_INSN
);
2197 helper_check_align(env
, addr
, 0x3f);
2198 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2199 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x19, 8);
2211 val
= env
->fpr
[rd
/ 2].l
.lower
;
2213 val
= env
->fpr
[rd
/ 2].l
.upper
;
2215 helper_st_asi(env
, addr
, val
, asi
, size
);
2218 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, size
);
2221 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, 8);
2222 helper_st_asi(env
, addr
+ 8, env
->fpr
[rd
/ 2 + 1].ll
, asi
, 8);
2227 target_ulong
helper_cas_asi(CPUSPARCState
*env
, target_ulong addr
,
2228 target_ulong val1
, target_ulong val2
, uint32_t asi
)
2232 val2
&= 0xffffffffUL
;
2233 ret
= helper_ld_asi(env
, addr
, asi
, 4, 0);
2234 ret
&= 0xffffffffUL
;
2236 helper_st_asi(env
, addr
, val1
& 0xffffffffUL
, asi
, 4);
2241 target_ulong
helper_casx_asi(CPUSPARCState
*env
, target_ulong addr
,
2242 target_ulong val1
, target_ulong val2
,
2247 ret
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2249 helper_st_asi(env
, addr
, val1
, asi
, 8);
2253 #endif /* TARGET_SPARC64 */
2255 void helper_ldqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2257 /* XXX add 128 bit load */
2260 helper_check_align(env
, addr
, 7);
2261 #if !defined(CONFIG_USER_ONLY)
2264 u
.ll
.upper
= cpu_ldq_user(env
, addr
);
2265 u
.ll
.lower
= cpu_ldq_user(env
, addr
+ 8);
2268 case MMU_KERNEL_IDX
:
2269 u
.ll
.upper
= cpu_ldq_kernel(env
, addr
);
2270 u
.ll
.lower
= cpu_ldq_kernel(env
, addr
+ 8);
2273 #ifdef TARGET_SPARC64
2275 u
.ll
.upper
= cpu_ldq_hypv(env
, addr
);
2276 u
.ll
.lower
= cpu_ldq_hypv(env
, addr
+ 8);
2281 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
2285 u
.ll
.upper
= ldq_raw(address_mask(env
, addr
));
2286 u
.ll
.lower
= ldq_raw(address_mask(env
, addr
+ 8));
2291 void helper_stqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2293 /* XXX add 128 bit store */
2296 helper_check_align(env
, addr
, 7);
2297 #if !defined(CONFIG_USER_ONLY)
2301 cpu_stq_user(env
, addr
, u
.ll
.upper
);
2302 cpu_stq_user(env
, addr
+ 8, u
.ll
.lower
);
2304 case MMU_KERNEL_IDX
:
2306 cpu_stq_kernel(env
, addr
, u
.ll
.upper
);
2307 cpu_stq_kernel(env
, addr
+ 8, u
.ll
.lower
);
2309 #ifdef TARGET_SPARC64
2312 cpu_stq_hypv(env
, addr
, u
.ll
.upper
);
2313 cpu_stq_hypv(env
, addr
+ 8, u
.ll
.lower
);
2317 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
2322 stq_raw(address_mask(env
, addr
), u
.ll
.upper
);
2323 stq_raw(address_mask(env
, addr
+ 8), u
.ll
.lower
);
2327 #if !defined(CONFIG_USER_ONLY)
2328 #ifndef TARGET_SPARC64
2329 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2330 bool is_write
, bool is_exec
, int is_asi
,
2333 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2334 CPUSPARCState
*env
= &cpu
->env
;
2337 #ifdef DEBUG_UNASSIGNED
2339 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2340 " asi 0x%02x from " TARGET_FMT_lx
"\n",
2341 is_exec
? "exec" : is_write
? "write" : "read", size
,
2342 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
2344 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2345 " from " TARGET_FMT_lx
"\n",
2346 is_exec
? "exec" : is_write
? "write" : "read", size
,
2347 size
== 1 ? "" : "s", addr
, env
->pc
);
2350 /* Don't overwrite translation and access faults */
2351 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
2352 if ((fault_type
> 4) || (fault_type
== 0)) {
2353 env
->mmuregs
[3] = 0; /* Fault status register */
2355 env
->mmuregs
[3] |= 1 << 16;
2358 env
->mmuregs
[3] |= 1 << 5;
2361 env
->mmuregs
[3] |= 1 << 6;
2364 env
->mmuregs
[3] |= 1 << 7;
2366 env
->mmuregs
[3] |= (5 << 2) | 2;
2367 /* SuperSPARC will never place instruction fault addresses in the FAR */
2369 env
->mmuregs
[4] = addr
; /* Fault address register */
2372 /* overflow (same type fault was not read before another fault) */
2373 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
2374 env
->mmuregs
[3] |= 1;
2377 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2379 helper_raise_exception(env
, TT_CODE_ACCESS
);
2381 helper_raise_exception(env
, TT_DATA_ACCESS
);
2385 /* flush neverland mappings created during no-fault mode,
2386 so the sequential MMU faults report proper fault types */
2387 if (env
->mmuregs
[0] & MMU_NF
) {
2392 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2393 bool is_write
, bool is_exec
, int is_asi
,
2396 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2397 CPUSPARCState
*env
= &cpu
->env
;
2399 #ifdef DEBUG_UNASSIGNED
2400 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
2401 "\n", addr
, env
->pc
);
2405 helper_raise_exception(env
, TT_CODE_ACCESS
);
2407 helper_raise_exception(env
, TT_DATA_ACCESS
);
2413 #if !defined(CONFIG_USER_ONLY)
2414 static void QEMU_NORETURN
do_unaligned_access(CPUSPARCState
*env
,
2415 target_ulong addr
, int is_write
,
2416 int is_user
, uintptr_t retaddr
)
2418 #ifdef DEBUG_UNALIGNED
2419 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
2420 "\n", addr
, env
->pc
);
2423 cpu_restore_state(env
, retaddr
);
2425 helper_raise_exception(env
, TT_UNALIGNED
);
2428 /* try to fill the TLB and return an exception if error. If retaddr is
2429 NULL, it means that the function was called in C code (i.e. not
2430 from generated code or from helper.c) */
2431 /* XXX: fix it to restore all registers */
2432 void tlb_fill(CPUSPARCState
*env
, target_ulong addr
, int is_write
, int mmu_idx
,
2437 ret
= cpu_sparc_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
2440 cpu_restore_state(env
, retaddr
);