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/>.
20 #include "qemu/osdep.h"
23 #include "exec/helper-proto.h"
24 #include "exec/exec-all.h"
25 #include "exec/cpu_ldst.h"
30 //#define DEBUG_UNALIGNED
31 //#define DEBUG_UNASSIGNED
33 //#define DEBUG_CACHE_CONTROL
36 #define DPRINTF_MMU(fmt, ...) \
37 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
39 #define DPRINTF_MMU(fmt, ...) do {} while (0)
43 #define DPRINTF_MXCC(fmt, ...) \
44 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
46 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
50 #define DPRINTF_ASI(fmt, ...) \
51 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
54 #ifdef DEBUG_CACHE_CONTROL
55 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
56 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
58 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
63 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
65 #define AM_CHECK(env1) (1)
69 #define QT0 (env->qt0)
70 #define QT1 (env->qt1)
72 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
73 /* Calculates TSB pointer value for fault page size
74 * UltraSPARC IIi has fixed sizes (8k or 64k) for the page pointers
75 * UA2005 holds the page size configuration in mmu_ctx registers */
76 static uint64_t ultrasparc_tsb_pointer(CPUSPARCState
*env
,
77 const SparcV9MMU
*mmu
, const int idx
)
79 uint64_t tsb_register
;
81 if (cpu_has_hypervisor(env
)) {
83 int ctx
= mmu
->tag_access
& 0x1fffULL
;
84 uint64_t ctx_register
= mmu
->sun4v_ctx_config
[ctx
? 1 : 0];
86 tsb_index
|= ctx
? 2 : 0;
87 page_size
= idx
? ctx_register
>> 8 : ctx_register
;
89 tsb_register
= mmu
->sun4v_tsb_pointers
[tsb_index
];
92 tsb_register
= mmu
->tsb
;
94 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
95 int tsb_size
= tsb_register
& 0xf;
97 uint64_t tsb_base_mask
= (~0x1fffULL
) << tsb_size
;
99 /* move va bits to correct position,
100 * the context bits will be masked out later */
101 uint64_t va
= mmu
->tag_access
>> (3 * page_size
+ 9);
103 /* calculate tsb_base mask and adjust va if split is in use */
106 va
&= ~(1ULL << (13 + tsb_size
));
108 va
|= (1ULL << (13 + tsb_size
));
113 return ((tsb_register
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
116 /* Calculates tag target register value by reordering bits
117 in tag access register */
118 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
120 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
123 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
124 uint64_t tlb_tag
, uint64_t tlb_tte
,
127 target_ulong mask
, size
, va
, offset
;
129 /* flush page range if translation is valid */
130 if (TTE_IS_VALID(tlb
->tte
)) {
131 CPUState
*cs
= CPU(sparc_env_get_cpu(env1
));
133 size
= 8192ULL << 3 * TTE_PGSIZE(tlb
->tte
);
136 va
= tlb
->tag
& mask
;
138 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
139 tlb_flush_page(cs
, va
+ offset
);
147 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
148 const char *strmmu
, CPUSPARCState
*env1
)
154 int is_demap_context
= (demap_addr
>> 6) & 1;
157 switch ((demap_addr
>> 4) & 3) {
158 case 0: /* primary */
159 context
= env1
->dmmu
.mmu_primary_context
;
161 case 1: /* secondary */
162 context
= env1
->dmmu
.mmu_secondary_context
;
164 case 2: /* nucleus */
167 case 3: /* reserved */
172 for (i
= 0; i
< 64; i
++) {
173 if (TTE_IS_VALID(tlb
[i
].tte
)) {
175 if (is_demap_context
) {
176 /* will remove non-global entries matching context value */
177 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
178 !tlb_compare_context(&tlb
[i
], context
)) {
183 will remove any entry matching VA */
184 mask
= 0xffffffffffffe000ULL
;
185 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
187 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
191 /* entry should be global or matching context value */
192 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
193 !tlb_compare_context(&tlb
[i
], context
)) {
198 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
200 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
201 dump_mmu(stdout
, fprintf
, env1
);
207 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
208 uint64_t tlb_tag
, uint64_t tlb_tte
,
209 const char *strmmu
, CPUSPARCState
*env1
)
211 unsigned int i
, replace_used
;
213 if (cpu_has_hypervisor(env1
)) {
214 uint64_t new_vaddr
= tlb_tag
& ~0x1fffULL
;
215 uint64_t new_size
= 8192ULL << 3 * TTE_PGSIZE(tlb_tte
);
216 uint32_t new_ctx
= tlb_tag
& 0x1fffU
;
217 for (i
= 0; i
< 64; i
++) {
218 uint32_t ctx
= tlb
[i
].tag
& 0x1fffU
;
219 /* check if new mapping overlaps an existing one */
220 if (new_ctx
== ctx
) {
221 uint64_t vaddr
= tlb
[i
].tag
& ~0x1fffULL
;
222 uint64_t size
= 8192ULL << 3 * TTE_PGSIZE(tlb
[i
].tte
);
223 if (new_vaddr
== vaddr
224 || (new_vaddr
< vaddr
+ size
225 && vaddr
< new_vaddr
+ new_size
)) {
226 DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i
, vaddr
,
228 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
235 /* Try replacing invalid entry */
236 for (i
= 0; i
< 64; i
++) {
237 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
238 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
240 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
241 dump_mmu(stdout
, fprintf
, env1
);
247 /* All entries are valid, try replacing unlocked entry */
249 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
251 /* Used entries are not replaced on first pass */
253 for (i
= 0; i
< 64; i
++) {
254 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
256 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
258 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
259 strmmu
, (replace_used
? "used" : "unused"), i
);
260 dump_mmu(stdout
, fprintf
, env1
);
266 /* Now reset used bit and search for unused entries again */
268 for (i
= 0; i
< 64; i
++) {
269 TTE_SET_UNUSED(tlb
[i
].tte
);
274 DPRINTF_MMU("%s lru replacement: no free entries available, "
275 "replacing the last one\n", strmmu
);
277 /* corner case: the last entry is replaced anyway */
278 replace_tlb_entry(&tlb
[63], tlb_tag
, tlb_tte
, env1
);
283 #ifdef TARGET_SPARC64
284 /* returns true if access using this ASI is to have address translated by MMU
285 otherwise access is to raw physical address */
286 /* TODO: check sparc32 bits */
287 static inline int is_translating_asi(int asi
)
289 /* Ultrasparc IIi translating asi
290 - note this list is defined by cpu implementation
307 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
309 if (AM_CHECK(env1
)) {
310 addr
&= 0xffffffffULL
;
315 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
316 int asi
, target_ulong addr
)
318 if (is_translating_asi(asi
)) {
319 addr
= address_mask(env
, addr
);
324 #ifndef CONFIG_USER_ONLY
325 static inline void do_check_asi(CPUSPARCState
*env
, int asi
, uintptr_t ra
)
327 /* ASIs >= 0x80 are user mode.
328 * ASIs >= 0x30 are hyper mode (or super if hyper is not available).
329 * ASIs <= 0x2f are super mode.
332 && !cpu_hypervisor_mode(env
)
333 && (!cpu_supervisor_mode(env
)
334 || (asi
>= 0x30 && cpu_has_hypervisor(env
)))) {
335 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, ra
);
338 #endif /* !CONFIG_USER_ONLY */
341 static void do_check_align(CPUSPARCState
*env
, target_ulong addr
,
342 uint32_t align
, uintptr_t ra
)
345 #ifdef DEBUG_UNALIGNED
346 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
347 "\n", addr
, env
->pc
);
349 cpu_raise_exception_ra(env
, TT_UNALIGNED
, ra
);
353 void helper_check_align(CPUSPARCState
*env
, target_ulong addr
, uint32_t align
)
355 do_check_align(env
, addr
, align
, GETPC());
358 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
360 static void dump_mxcc(CPUSPARCState
*env
)
362 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
364 env
->mxccdata
[0], env
->mxccdata
[1],
365 env
->mxccdata
[2], env
->mxccdata
[3]);
366 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
368 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
370 env
->mxccregs
[0], env
->mxccregs
[1],
371 env
->mxccregs
[2], env
->mxccregs
[3],
372 env
->mxccregs
[4], env
->mxccregs
[5],
373 env
->mxccregs
[6], env
->mxccregs
[7]);
377 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
378 && defined(DEBUG_ASI)
379 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
384 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
385 addr
, asi
, r1
& 0xff);
388 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
389 addr
, asi
, r1
& 0xffff);
392 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
393 addr
, asi
, r1
& 0xffffffff);
396 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
403 #ifndef TARGET_SPARC64
404 #ifndef CONFIG_USER_ONLY
407 /* Leon3 cache control */
409 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
410 uint64_t val
, int size
)
412 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
416 DPRINTF_CACHE_CONTROL("32bits only\n");
421 case 0x00: /* Cache control */
423 /* These values must always be read as zeros */
424 val
&= ~CACHE_CTRL_FD
;
425 val
&= ~CACHE_CTRL_FI
;
426 val
&= ~CACHE_CTRL_IB
;
427 val
&= ~CACHE_CTRL_IP
;
428 val
&= ~CACHE_CTRL_DP
;
430 env
->cache_control
= val
;
432 case 0x04: /* Instruction cache configuration */
433 case 0x08: /* Data cache configuration */
437 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
442 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
448 DPRINTF_CACHE_CONTROL("32bits only\n");
453 case 0x00: /* Cache control */
454 ret
= env
->cache_control
;
457 /* Configuration registers are read and only always keep those
460 case 0x04: /* Instruction cache configuration */
463 case 0x08: /* Data cache configuration */
467 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
470 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
475 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
476 int asi
, uint32_t memop
)
478 int size
= 1 << (memop
& MO_SIZE
);
479 int sign
= memop
& MO_SIGN
;
480 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
482 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
483 uint32_t last_addr
= addr
;
486 do_check_align(env
, addr
, size
- 1, GETPC());
488 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
489 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
491 case 0x00: /* Leon3 Cache Control */
492 case 0x08: /* Leon3 Instruction Cache config */
493 case 0x0C: /* Leon3 Date Cache config */
494 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
495 ret
= leon3_cache_control_ld(env
, addr
, size
);
498 case 0x01c00a00: /* MXCC control register */
500 ret
= env
->mxccregs
[3];
502 qemu_log_mask(LOG_UNIMP
,
503 "%08x: unimplemented access size: %d\n", addr
,
507 case 0x01c00a04: /* MXCC control register */
509 ret
= env
->mxccregs
[3];
511 qemu_log_mask(LOG_UNIMP
,
512 "%08x: unimplemented access size: %d\n", addr
,
516 case 0x01c00c00: /* Module reset register */
518 ret
= env
->mxccregs
[5];
519 /* should we do something here? */
521 qemu_log_mask(LOG_UNIMP
,
522 "%08x: unimplemented access size: %d\n", addr
,
526 case 0x01c00f00: /* MBus port address register */
528 ret
= env
->mxccregs
[7];
530 qemu_log_mask(LOG_UNIMP
,
531 "%08x: unimplemented access size: %d\n", addr
,
536 qemu_log_mask(LOG_UNIMP
,
537 "%08x: unimplemented address, size: %d\n", addr
,
541 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
542 "addr = %08x -> ret = %" PRIx64
","
543 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
548 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU probe */
549 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU probe */
553 mmulev
= (addr
>> 8) & 15;
557 ret
= mmu_probe(env
, addr
, mmulev
);
559 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
563 case ASI_M_MMUREGS
: /* SuperSparc MMU regs */
564 case ASI_LEON_MMUREGS
: /* LEON3 MMU regs */
566 int reg
= (addr
>> 8) & 0x1f;
568 ret
= env
->mmuregs
[reg
];
569 if (reg
== 3) { /* Fault status cleared on read */
571 } else if (reg
== 0x13) { /* Fault status read */
572 ret
= env
->mmuregs
[3];
573 } else if (reg
== 0x14) { /* Fault address read */
574 ret
= env
->mmuregs
[4];
576 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
579 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
580 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
581 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
583 case ASI_KERNELTXT
: /* Supervisor code access */
586 ret
= cpu_ldub_code(env
, addr
);
589 ret
= cpu_lduw_code(env
, addr
);
593 ret
= cpu_ldl_code(env
, addr
);
596 ret
= cpu_ldq_code(env
, addr
);
600 case ASI_M_TXTC_TAG
: /* SparcStation 5 I-cache tag */
601 case ASI_M_TXTC_DATA
: /* SparcStation 5 I-cache data */
602 case ASI_M_DATAC_TAG
: /* SparcStation 5 D-cache tag */
603 case ASI_M_DATAC_DATA
: /* SparcStation 5 D-cache data */
605 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
608 ret
= ldub_phys(cs
->as
, (hwaddr
)addr
609 | ((hwaddr
)(asi
& 0xf) << 32));
612 ret
= lduw_phys(cs
->as
, (hwaddr
)addr
613 | ((hwaddr
)(asi
& 0xf) << 32));
617 ret
= ldl_phys(cs
->as
, (hwaddr
)addr
618 | ((hwaddr
)(asi
& 0xf) << 32));
621 ret
= ldq_phys(cs
->as
, (hwaddr
)addr
622 | ((hwaddr
)(asi
& 0xf) << 32));
626 case 0x30: /* Turbosparc secondary cache diagnostic */
627 case 0x31: /* Turbosparc RAM snoop */
628 case 0x32: /* Turbosparc page table descriptor diagnostic */
629 case 0x39: /* data cache diagnostic register */
632 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
634 int reg
= (addr
>> 8) & 3;
637 case 0: /* Breakpoint Value (Addr) */
638 ret
= env
->mmubpregs
[reg
];
640 case 1: /* Breakpoint Mask */
641 ret
= env
->mmubpregs
[reg
];
643 case 2: /* Breakpoint Control */
644 ret
= env
->mmubpregs
[reg
];
646 case 3: /* Breakpoint Status */
647 ret
= env
->mmubpregs
[reg
];
648 env
->mmubpregs
[reg
] = 0ULL;
651 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
655 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
656 ret
= env
->mmubpctrv
;
658 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
659 ret
= env
->mmubpctrc
;
661 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
662 ret
= env
->mmubpctrs
;
664 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
665 ret
= env
->mmubpaction
;
667 case ASI_USERTXT
: /* User code access, XXX */
669 cpu_unassigned_access(cs
, addr
, false, false, asi
, size
);
673 case ASI_USERDATA
: /* User data access */
674 case ASI_KERNELDATA
: /* Supervisor data access */
675 case ASI_P
: /* Implicit primary context data access (v9 only?) */
676 case ASI_M_BYPASS
: /* MMU passthrough */
677 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
678 /* These are always handled inline. */
679 g_assert_not_reached();
697 dump_asi("read ", last_addr
, asi
, size
, ret
);
702 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
,
703 int asi
, uint32_t memop
)
705 int size
= 1 << (memop
& MO_SIZE
);
706 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
707 CPUState
*cs
= CPU(cpu
);
709 do_check_align(env
, addr
, size
- 1, GETPC());
711 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
712 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
714 case 0x00: /* Leon3 Cache Control */
715 case 0x08: /* Leon3 Instruction Cache config */
716 case 0x0C: /* Leon3 Date Cache config */
717 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
718 leon3_cache_control_st(env
, addr
, val
, size
);
722 case 0x01c00000: /* MXCC stream data register 0 */
724 env
->mxccdata
[0] = val
;
726 qemu_log_mask(LOG_UNIMP
,
727 "%08x: unimplemented access size: %d\n", addr
,
731 case 0x01c00008: /* MXCC stream data register 1 */
733 env
->mxccdata
[1] = val
;
735 qemu_log_mask(LOG_UNIMP
,
736 "%08x: unimplemented access size: %d\n", addr
,
740 case 0x01c00010: /* MXCC stream data register 2 */
742 env
->mxccdata
[2] = val
;
744 qemu_log_mask(LOG_UNIMP
,
745 "%08x: unimplemented access size: %d\n", addr
,
749 case 0x01c00018: /* MXCC stream data register 3 */
751 env
->mxccdata
[3] = val
;
753 qemu_log_mask(LOG_UNIMP
,
754 "%08x: unimplemented access size: %d\n", addr
,
758 case 0x01c00100: /* MXCC stream source */
760 env
->mxccregs
[0] = val
;
762 qemu_log_mask(LOG_UNIMP
,
763 "%08x: unimplemented access size: %d\n", addr
,
766 env
->mxccdata
[0] = ldq_phys(cs
->as
,
767 (env
->mxccregs
[0] & 0xffffffffULL
) +
769 env
->mxccdata
[1] = ldq_phys(cs
->as
,
770 (env
->mxccregs
[0] & 0xffffffffULL
) +
772 env
->mxccdata
[2] = ldq_phys(cs
->as
,
773 (env
->mxccregs
[0] & 0xffffffffULL
) +
775 env
->mxccdata
[3] = ldq_phys(cs
->as
,
776 (env
->mxccregs
[0] & 0xffffffffULL
) +
779 case 0x01c00200: /* MXCC stream destination */
781 env
->mxccregs
[1] = val
;
783 qemu_log_mask(LOG_UNIMP
,
784 "%08x: unimplemented access size: %d\n", addr
,
787 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 0,
789 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 8,
791 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 16,
793 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 24,
796 case 0x01c00a00: /* MXCC control register */
798 env
->mxccregs
[3] = val
;
800 qemu_log_mask(LOG_UNIMP
,
801 "%08x: unimplemented access size: %d\n", addr
,
805 case 0x01c00a04: /* MXCC control register */
807 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
810 qemu_log_mask(LOG_UNIMP
,
811 "%08x: unimplemented access size: %d\n", addr
,
815 case 0x01c00e00: /* MXCC error register */
816 /* writing a 1 bit clears the error */
818 env
->mxccregs
[6] &= ~val
;
820 qemu_log_mask(LOG_UNIMP
,
821 "%08x: unimplemented access size: %d\n", addr
,
825 case 0x01c00f00: /* MBus port address register */
827 env
->mxccregs
[7] = val
;
829 qemu_log_mask(LOG_UNIMP
,
830 "%08x: unimplemented access size: %d\n", addr
,
835 qemu_log_mask(LOG_UNIMP
,
836 "%08x: unimplemented address, size: %d\n", addr
,
840 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
841 asi
, size
, addr
, val
);
846 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU flush */
847 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU flush */
851 mmulev
= (addr
>> 8) & 15;
852 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
854 case 0: /* flush page */
855 tlb_flush_page(CPU(cpu
), addr
& 0xfffff000);
857 case 1: /* flush segment (256k) */
858 case 2: /* flush region (16M) */
859 case 3: /* flush context (4G) */
860 case 4: /* flush entire */
867 dump_mmu(stdout
, fprintf
, env
);
871 case ASI_M_MMUREGS
: /* write MMU regs */
872 case ASI_LEON_MMUREGS
: /* LEON3 write MMU regs */
874 int reg
= (addr
>> 8) & 0x1f;
877 oldreg
= env
->mmuregs
[reg
];
879 case 0: /* Control Register */
880 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
882 /* Mappings generated during no-fault mode
883 are invalid in normal mode. */
884 if ((oldreg
^ env
->mmuregs
[reg
])
885 & (MMU_NF
| env
->def
->mmu_bm
)) {
889 case 1: /* Context Table Pointer Register */
890 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
892 case 2: /* Context Register */
893 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
894 if (oldreg
!= env
->mmuregs
[reg
]) {
895 /* we flush when the MMU context changes because
896 QEMU has no MMU context support */
900 case 3: /* Synchronous Fault Status Register with Clear */
901 case 4: /* Synchronous Fault Address Register */
903 case 0x10: /* TLB Replacement Control Register */
904 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
906 case 0x13: /* Synchronous Fault Status Register with Read
908 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
910 case 0x14: /* Synchronous Fault Address Register */
911 env
->mmuregs
[4] = val
;
914 env
->mmuregs
[reg
] = val
;
917 if (oldreg
!= env
->mmuregs
[reg
]) {
918 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
919 reg
, oldreg
, env
->mmuregs
[reg
]);
922 dump_mmu(stdout
, fprintf
, env
);
926 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
927 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
928 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
930 case ASI_M_TXTC_TAG
: /* I-cache tag */
931 case ASI_M_TXTC_DATA
: /* I-cache data */
932 case ASI_M_DATAC_TAG
: /* D-cache tag */
933 case ASI_M_DATAC_DATA
: /* D-cache data */
934 case ASI_M_FLUSH_PAGE
: /* I/D-cache flush page */
935 case ASI_M_FLUSH_SEG
: /* I/D-cache flush segment */
936 case ASI_M_FLUSH_REGION
: /* I/D-cache flush region */
937 case ASI_M_FLUSH_CTX
: /* I/D-cache flush context */
938 case ASI_M_FLUSH_USER
: /* I/D-cache flush user */
940 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
944 stb_phys(cs
->as
, (hwaddr
)addr
945 | ((hwaddr
)(asi
& 0xf) << 32), val
);
948 stw_phys(cs
->as
, (hwaddr
)addr
949 | ((hwaddr
)(asi
& 0xf) << 32), val
);
953 stl_phys(cs
->as
, (hwaddr
)addr
954 | ((hwaddr
)(asi
& 0xf) << 32), val
);
957 stq_phys(cs
->as
, (hwaddr
)addr
958 | ((hwaddr
)(asi
& 0xf) << 32), val
);
963 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
964 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
965 Turbosparc snoop RAM */
966 case 0x32: /* store buffer control or Turbosparc page table
967 descriptor diagnostic */
968 case 0x36: /* I-cache flash clear */
969 case 0x37: /* D-cache flash clear */
971 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
973 int reg
= (addr
>> 8) & 3;
976 case 0: /* Breakpoint Value (Addr) */
977 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
979 case 1: /* Breakpoint Mask */
980 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
982 case 2: /* Breakpoint Control */
983 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
985 case 3: /* Breakpoint Status */
986 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
989 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
993 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
994 env
->mmubpctrv
= val
& 0xffffffff;
996 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
997 env
->mmubpctrc
= val
& 0x3;
999 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1000 env
->mmubpctrs
= val
& 0x3;
1002 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1003 env
->mmubpaction
= val
& 0x1fff;
1005 case ASI_USERTXT
: /* User code access, XXX */
1006 case ASI_KERNELTXT
: /* Supervisor code access, XXX */
1008 cpu_unassigned_access(CPU(sparc_env_get_cpu(env
)),
1009 addr
, true, false, asi
, size
);
1012 case ASI_USERDATA
: /* User data access */
1013 case ASI_KERNELDATA
: /* Supervisor data access */
1015 case ASI_M_BYPASS
: /* MMU passthrough */
1016 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
1017 case ASI_M_BCOPY
: /* Block copy, sta access */
1018 case ASI_M_BFILL
: /* Block fill, stda access */
1019 /* These are always handled inline. */
1020 g_assert_not_reached();
1023 dump_asi("write", addr
, asi
, size
, val
);
1027 #endif /* CONFIG_USER_ONLY */
1028 #else /* TARGET_SPARC64 */
1030 #ifdef CONFIG_USER_ONLY
1031 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1032 int asi
, uint32_t memop
)
1034 int size
= 1 << (memop
& MO_SIZE
);
1035 int sign
= memop
& MO_SIGN
;
1039 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1041 do_check_align(env
, addr
, size
- 1, GETPC());
1042 addr
= asi_address_mask(env
, asi
, addr
);
1045 case ASI_PNF
: /* Primary no-fault */
1046 case ASI_PNFL
: /* Primary no-fault LE */
1047 case ASI_SNF
: /* Secondary no-fault */
1048 case ASI_SNFL
: /* Secondary no-fault LE */
1049 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1055 ret
= cpu_ldub_data(env
, addr
);
1058 ret
= cpu_lduw_data(env
, addr
);
1061 ret
= cpu_ldl_data(env
, addr
);
1064 ret
= cpu_ldq_data(env
, addr
);
1067 g_assert_not_reached();
1072 case ASI_P
: /* Primary */
1073 case ASI_PL
: /* Primary LE */
1074 case ASI_S
: /* Secondary */
1075 case ASI_SL
: /* Secondary LE */
1076 /* These are always handled inline. */
1077 g_assert_not_reached();
1080 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1083 /* Convert from little endian */
1085 case ASI_PNFL
: /* Primary no-fault LE */
1086 case ASI_SNFL
: /* Secondary no-fault LE */
1100 /* Convert to signed number */
1107 ret
= (int16_t) ret
;
1110 ret
= (int32_t) ret
;
1115 dump_asi("read", addr
, asi
, size
, ret
);
1120 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1121 int asi
, uint32_t memop
)
1123 int size
= 1 << (memop
& MO_SIZE
);
1125 dump_asi("write", addr
, asi
, size
, val
);
1128 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1130 do_check_align(env
, addr
, size
- 1, GETPC());
1133 case ASI_P
: /* Primary */
1134 case ASI_PL
: /* Primary LE */
1135 case ASI_S
: /* Secondary */
1136 case ASI_SL
: /* Secondary LE */
1137 /* These are always handled inline. */
1138 g_assert_not_reached();
1140 case ASI_PNF
: /* Primary no-fault, RO */
1141 case ASI_SNF
: /* Secondary no-fault, RO */
1142 case ASI_PNFL
: /* Primary no-fault LE, RO */
1143 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1145 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1149 #else /* CONFIG_USER_ONLY */
1151 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1152 int asi
, uint32_t memop
)
1154 int size
= 1 << (memop
& MO_SIZE
);
1155 int sign
= memop
& MO_SIGN
;
1156 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
1158 #if defined(DEBUG_ASI)
1159 target_ulong last_addr
= addr
;
1164 do_check_asi(env
, asi
, GETPC());
1165 do_check_align(env
, addr
, size
- 1, GETPC());
1166 addr
= asi_address_mask(env
, asi
, addr
);
1175 int idx
= (env
->pstate
& PS_PRIV
1176 ? (asi
& 1 ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
)
1177 : (asi
& 1 ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
));
1179 if (cpu_get_phys_page_nofault(env
, addr
, idx
) == -1ULL) {
1181 dump_asi("read ", last_addr
, asi
, size
, ret
);
1183 /* exception_index is set in get_physical_address_data. */
1184 cpu_raise_exception_ra(env
, cs
->exception_index
, GETPC());
1186 oi
= make_memop_idx(memop
, idx
);
1189 ret
= helper_ret_ldub_mmu(env
, addr
, oi
, GETPC());
1193 ret
= helper_le_lduw_mmu(env
, addr
, oi
, GETPC());
1195 ret
= helper_be_lduw_mmu(env
, addr
, oi
, GETPC());
1200 ret
= helper_le_ldul_mmu(env
, addr
, oi
, GETPC());
1202 ret
= helper_be_ldul_mmu(env
, addr
, oi
, GETPC());
1207 ret
= helper_le_ldq_mmu(env
, addr
, oi
, GETPC());
1209 ret
= helper_be_ldq_mmu(env
, addr
, oi
, GETPC());
1213 g_assert_not_reached();
1218 case ASI_AIUP
: /* As if user primary */
1219 case ASI_AIUS
: /* As if user secondary */
1220 case ASI_AIUPL
: /* As if user primary LE */
1221 case ASI_AIUSL
: /* As if user secondary LE */
1222 case ASI_P
: /* Primary */
1223 case ASI_S
: /* Secondary */
1224 case ASI_PL
: /* Primary LE */
1225 case ASI_SL
: /* Secondary LE */
1226 case ASI_REAL
: /* Bypass */
1227 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1228 case ASI_REAL_L
: /* Bypass LE */
1229 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1230 case ASI_N
: /* Nucleus */
1231 case ASI_NL
: /* Nucleus Little Endian (LE) */
1232 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1233 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1234 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1235 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1236 case ASI_TWINX_REAL
: /* Real address, twinx */
1237 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1238 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1239 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1240 case ASI_TWINX_N
: /* Nucleus, twinx */
1241 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1242 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1243 case ASI_TWINX_P
: /* Primary, twinx */
1244 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1245 case ASI_TWINX_S
: /* Secondary, twinx */
1246 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1247 /* These are always handled inline. */
1248 g_assert_not_reached();
1250 case ASI_UPA_CONFIG
: /* UPA config */
1253 case ASI_LSU_CONTROL
: /* LSU */
1256 case ASI_IMMU
: /* I-MMU regs */
1258 int reg
= (addr
>> 3) & 0xf;
1261 /* 0x00 I-TSB Tag Target register */
1262 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1265 ret
= env
->immu
.sfsr
;
1267 case 5: /* TSB access */
1268 ret
= env
->immu
.tsb
;
1271 /* 0x30 I-TSB Tag Access register */
1272 ret
= env
->immu
.tag_access
;
1275 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1280 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer */
1282 /* env->immuregs[5] holds I-MMU TSB register value
1283 env->immuregs[6] holds I-MMU Tag Access register value */
1284 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 0);
1287 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer */
1289 /* env->immuregs[5] holds I-MMU TSB register value
1290 env->immuregs[6] holds I-MMU Tag Access register value */
1291 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 1);
1294 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1296 int reg
= (addr
>> 3) & 0x3f;
1298 ret
= env
->itlb
[reg
].tte
;
1301 case ASI_ITLB_TAG_READ
: /* I-MMU tag read */
1303 int reg
= (addr
>> 3) & 0x3f;
1305 ret
= env
->itlb
[reg
].tag
;
1308 case ASI_DMMU
: /* D-MMU regs */
1310 int reg
= (addr
>> 3) & 0xf;
1313 /* 0x00 D-TSB Tag Target register */
1314 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1316 case 1: /* 0x08 Primary Context */
1317 ret
= env
->dmmu
.mmu_primary_context
;
1319 case 2: /* 0x10 Secondary Context */
1320 ret
= env
->dmmu
.mmu_secondary_context
;
1323 ret
= env
->dmmu
.sfsr
;
1325 case 4: /* 0x20 SFAR */
1326 ret
= env
->dmmu
.sfar
;
1328 case 5: /* 0x28 TSB access */
1329 ret
= env
->dmmu
.tsb
;
1331 case 6: /* 0x30 D-TSB Tag Access register */
1332 ret
= env
->dmmu
.tag_access
;
1335 ret
= env
->dmmu
.virtual_watchpoint
;
1338 ret
= env
->dmmu
.physical_watchpoint
;
1341 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1346 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer */
1348 /* env->dmmuregs[5] holds D-MMU TSB register value
1349 env->dmmuregs[6] holds D-MMU Tag Access register value */
1350 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 0);
1353 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer */
1355 /* env->dmmuregs[5] holds D-MMU TSB register value
1356 env->dmmuregs[6] holds D-MMU Tag Access register value */
1357 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 1);
1360 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1362 int reg
= (addr
>> 3) & 0x3f;
1364 ret
= env
->dtlb
[reg
].tte
;
1367 case ASI_DTLB_TAG_READ
: /* D-MMU tag read */
1369 int reg
= (addr
>> 3) & 0x3f;
1371 ret
= env
->dtlb
[reg
].tag
;
1374 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1376 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1377 ret
= env
->ivec_status
;
1379 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1381 int reg
= (addr
>> 4) & 0x3;
1383 ret
= env
->ivec_data
[reg
];
1387 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1388 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1389 /* Hyperprivileged access only */
1390 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1393 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1395 unsigned int i
= (addr
>> 3) & 0x7;
1396 ret
= env
->scratch
[i
];
1399 case ASI_DCACHE_DATA
: /* D-cache data */
1400 case ASI_DCACHE_TAG
: /* D-cache tag access */
1401 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1402 case ASI_AFSR
: /* E-cache asynchronous fault status */
1403 case ASI_AFAR
: /* E-cache asynchronous fault address */
1404 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1405 case ASI_IC_INSTR
: /* I-cache instruction access */
1406 case ASI_IC_TAG
: /* I-cache tag access */
1407 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1408 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1409 case ASI_EC_W
: /* E-cache tag */
1410 case ASI_EC_R
: /* E-cache tag */
1412 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer */
1413 case ASI_ITLB_DATA_IN
: /* I-MMU data in, WO */
1414 case ASI_IMMU_DEMAP
: /* I-MMU demap, WO */
1415 case ASI_DTLB_DATA_IN
: /* D-MMU data in, WO */
1416 case ASI_DMMU_DEMAP
: /* D-MMU demap, WO */
1417 case ASI_INTR_W
: /* Interrupt vector, WO */
1419 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1424 /* Convert to signed number */
1431 ret
= (int16_t) ret
;
1434 ret
= (int32_t) ret
;
1441 dump_asi("read ", last_addr
, asi
, size
, ret
);
1446 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1447 int asi
, uint32_t memop
)
1449 int size
= 1 << (memop
& MO_SIZE
);
1450 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
1451 CPUState
*cs
= CPU(cpu
);
1454 dump_asi("write", addr
, asi
, size
, val
);
1459 do_check_asi(env
, asi
, GETPC());
1460 do_check_align(env
, addr
, size
- 1, GETPC());
1461 addr
= asi_address_mask(env
, asi
, addr
);
1464 case ASI_AIUP
: /* As if user primary */
1465 case ASI_AIUS
: /* As if user secondary */
1466 case ASI_AIUPL
: /* As if user primary LE */
1467 case ASI_AIUSL
: /* As if user secondary LE */
1468 case ASI_P
: /* Primary */
1469 case ASI_S
: /* Secondary */
1470 case ASI_PL
: /* Primary LE */
1471 case ASI_SL
: /* Secondary LE */
1472 case ASI_REAL
: /* Bypass */
1473 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1474 case ASI_REAL_L
: /* Bypass LE */
1475 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1476 case ASI_N
: /* Nucleus */
1477 case ASI_NL
: /* Nucleus Little Endian (LE) */
1478 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1479 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1480 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1481 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1482 case ASI_TWINX_REAL
: /* Real address, twinx */
1483 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1484 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1485 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1486 case ASI_TWINX_N
: /* Nucleus, twinx */
1487 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1488 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1489 case ASI_TWINX_P
: /* Primary, twinx */
1490 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1491 case ASI_TWINX_S
: /* Secondary, twinx */
1492 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1493 /* These are always handled inline. */
1494 g_assert_not_reached();
1495 /* these ASIs have different functions on UltraSPARC-IIIi
1496 * and UA2005 CPUs. Use the explicit numbers to avoid confusion
1502 if (cpu_has_hypervisor(env
)) {
1504 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS0
1505 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS1
1506 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS0
1507 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS1
1509 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1510 env
->dmmu
.sun4v_tsb_pointers
[idx
] = val
;
1512 helper_raise_exception(env
, TT_ILL_INSN
);
1517 if (cpu_has_hypervisor(env
)) {
1519 * ASI_DMMU_CTX_ZERO_CONFIG
1520 * ASI_DMMU_CTX_NONZERO_CONFIG
1522 env
->dmmu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1524 helper_raise_exception(env
, TT_ILL_INSN
);
1531 if (cpu_has_hypervisor(env
)) {
1533 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS0
1534 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS1
1535 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS0
1536 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS1
1538 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1539 env
->immu
.sun4v_tsb_pointers
[idx
] = val
;
1541 helper_raise_exception(env
, TT_ILL_INSN
);
1546 if (cpu_has_hypervisor(env
)) {
1548 * ASI_IMMU_CTX_ZERO_CONFIG
1549 * ASI_IMMU_CTX_NONZERO_CONFIG
1551 env
->immu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1553 helper_raise_exception(env
, TT_ILL_INSN
);
1556 case ASI_UPA_CONFIG
: /* UPA config */
1559 case ASI_LSU_CONTROL
: /* LSU */
1560 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1562 case ASI_IMMU
: /* I-MMU regs */
1564 int reg
= (addr
>> 3) & 0xf;
1567 oldreg
= env
->immu
.mmuregs
[reg
];
1571 case 1: /* Not in I-MMU */
1575 if ((val
& 1) == 0) {
1576 val
= 0; /* Clear SFSR */
1578 env
->immu
.sfsr
= val
;
1582 case 5: /* TSB access */
1583 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1584 PRIx64
"\n", env
->immu
.tsb
, val
);
1585 env
->immu
.tsb
= val
;
1587 case 6: /* Tag access */
1588 env
->immu
.tag_access
= val
;
1594 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1598 if (oldreg
!= env
->immu
.mmuregs
[reg
]) {
1599 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1600 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1603 dump_mmu(stdout
, fprintf
, env
);
1607 case ASI_ITLB_DATA_IN
: /* I-MMU data in */
1608 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
1610 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1612 /* TODO: auto demap */
1614 unsigned int i
= (addr
>> 3) & 0x3f;
1616 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
1619 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1620 dump_mmu(stdout
, fprintf
, env
);
1624 case ASI_IMMU_DEMAP
: /* I-MMU demap */
1625 demap_tlb(env
->itlb
, addr
, "immu", env
);
1627 case ASI_DMMU
: /* D-MMU regs */
1629 int reg
= (addr
>> 3) & 0xf;
1632 oldreg
= env
->dmmu
.mmuregs
[reg
];
1638 if ((val
& 1) == 0) {
1639 val
= 0; /* Clear SFSR, Fault address */
1642 env
->dmmu
.sfsr
= val
;
1644 case 1: /* Primary context */
1645 env
->dmmu
.mmu_primary_context
= val
;
1646 /* can be optimized to only flush MMU_USER_IDX
1647 and MMU_KERNEL_IDX entries */
1648 tlb_flush(CPU(cpu
));
1650 case 2: /* Secondary context */
1651 env
->dmmu
.mmu_secondary_context
= val
;
1652 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1653 and MMU_KERNEL_SECONDARY_IDX entries */
1654 tlb_flush(CPU(cpu
));
1656 case 5: /* TSB access */
1657 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1658 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1659 env
->dmmu
.tsb
= val
;
1661 case 6: /* Tag access */
1662 env
->dmmu
.tag_access
= val
;
1664 case 7: /* Virtual Watchpoint */
1665 env
->dmmu
.virtual_watchpoint
= val
;
1667 case 8: /* Physical Watchpoint */
1668 env
->dmmu
.physical_watchpoint
= val
;
1671 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1675 if (oldreg
!= env
->dmmu
.mmuregs
[reg
]) {
1676 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1677 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1680 dump_mmu(stdout
, fprintf
, env
);
1684 case ASI_DTLB_DATA_IN
: /* D-MMU data in */
1685 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
1687 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1689 unsigned int i
= (addr
>> 3) & 0x3f;
1691 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
1694 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1695 dump_mmu(stdout
, fprintf
, env
);
1699 case ASI_DMMU_DEMAP
: /* D-MMU demap */
1700 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1702 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1703 env
->ivec_status
= val
& 0x20;
1705 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1706 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1707 /* Hyperprivileged access only */
1708 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1711 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1713 unsigned int i
= (addr
>> 3) & 0x7;
1714 env
->scratch
[i
] = val
;
1717 case ASI_QUEUE
: /* UA2005 CPU mondo queue */
1718 case ASI_DCACHE_DATA
: /* D-cache data */
1719 case ASI_DCACHE_TAG
: /* D-cache tag access */
1720 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1721 case ASI_AFSR
: /* E-cache asynchronous fault status */
1722 case ASI_AFAR
: /* E-cache asynchronous fault address */
1723 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1724 case ASI_IC_INSTR
: /* I-cache instruction access */
1725 case ASI_IC_TAG
: /* I-cache tag access */
1726 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1727 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1728 case ASI_EC_W
: /* E-cache tag */
1729 case ASI_EC_R
: /* E-cache tag */
1731 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer, RO */
1732 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer, RO */
1733 case ASI_ITLB_TAG_READ
: /* I-MMU tag read, RO */
1734 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer, RO */
1735 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer, RO */
1736 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer, RO */
1737 case ASI_DTLB_TAG_READ
: /* D-MMU tag read, RO */
1738 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1739 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1740 case ASI_PNF
: /* Primary no-fault, RO */
1741 case ASI_SNF
: /* Secondary no-fault, RO */
1742 case ASI_PNFL
: /* Primary no-fault LE, RO */
1743 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1745 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1749 #endif /* CONFIG_USER_ONLY */
1750 #endif /* TARGET_SPARC64 */
1752 #if !defined(CONFIG_USER_ONLY)
1753 #ifndef TARGET_SPARC64
1754 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
1755 bool is_write
, bool is_exec
, int is_asi
,
1758 SPARCCPU
*cpu
= SPARC_CPU(cs
);
1759 CPUSPARCState
*env
= &cpu
->env
;
1762 #ifdef DEBUG_UNASSIGNED
1764 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
1765 " asi 0x%02x from " TARGET_FMT_lx
"\n",
1766 is_exec
? "exec" : is_write
? "write" : "read", size
,
1767 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
1769 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
1770 " from " TARGET_FMT_lx
"\n",
1771 is_exec
? "exec" : is_write
? "write" : "read", size
,
1772 size
== 1 ? "" : "s", addr
, env
->pc
);
1775 /* Don't overwrite translation and access faults */
1776 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
1777 if ((fault_type
> 4) || (fault_type
== 0)) {
1778 env
->mmuregs
[3] = 0; /* Fault status register */
1780 env
->mmuregs
[3] |= 1 << 16;
1783 env
->mmuregs
[3] |= 1 << 5;
1786 env
->mmuregs
[3] |= 1 << 6;
1789 env
->mmuregs
[3] |= 1 << 7;
1791 env
->mmuregs
[3] |= (5 << 2) | 2;
1792 /* SuperSPARC will never place instruction fault addresses in the FAR */
1794 env
->mmuregs
[4] = addr
; /* Fault address register */
1797 /* overflow (same type fault was not read before another fault) */
1798 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
1799 env
->mmuregs
[3] |= 1;
1802 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
1803 int tt
= is_exec
? TT_CODE_ACCESS
: TT_DATA_ACCESS
;
1804 cpu_raise_exception_ra(env
, tt
, GETPC());
1807 /* flush neverland mappings created during no-fault mode,
1808 so the sequential MMU faults report proper fault types */
1809 if (env
->mmuregs
[0] & MMU_NF
) {
1814 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
1815 bool is_write
, bool is_exec
, int is_asi
,
1818 SPARCCPU
*cpu
= SPARC_CPU(cs
);
1819 CPUSPARCState
*env
= &cpu
->env
;
1821 #ifdef DEBUG_UNASSIGNED
1822 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
1823 "\n", addr
, env
->pc
);
1826 if (is_exec
) { /* XXX has_hypervisor */
1827 if (env
->lsu
& (IMMU_E
)) {
1828 cpu_raise_exception_ra(env
, TT_CODE_ACCESS
, GETPC());
1829 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
1830 cpu_raise_exception_ra(env
, TT_INSN_REAL_TRANSLATION_MISS
, GETPC());
1833 if (env
->lsu
& (DMMU_E
)) {
1834 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1835 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
1836 cpu_raise_exception_ra(env
, TT_DATA_REAL_TRANSLATION_MISS
, GETPC());
1843 #if !defined(CONFIG_USER_ONLY)
1844 void QEMU_NORETURN
sparc_cpu_do_unaligned_access(CPUState
*cs
, vaddr addr
,
1845 MMUAccessType access_type
,
1849 SPARCCPU
*cpu
= SPARC_CPU(cs
);
1850 CPUSPARCState
*env
= &cpu
->env
;
1852 #ifdef DEBUG_UNALIGNED
1853 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
1854 "\n", addr
, env
->pc
);
1856 cpu_raise_exception_ra(env
, TT_UNALIGNED
, retaddr
);
1859 /* try to fill the TLB and return an exception if error. If retaddr is
1860 NULL, it means that the function was called in C code (i.e. not
1861 from generated code or from helper.c) */
1862 /* XXX: fix it to restore all registers */
1863 void tlb_fill(CPUState
*cs
, target_ulong addr
, MMUAccessType access_type
,
1864 int mmu_idx
, uintptr_t retaddr
)
1868 ret
= sparc_cpu_handle_mmu_fault(cs
, addr
, access_type
, mmu_idx
);
1870 cpu_loop_exit_restore(cs
, retaddr
);