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
= env_cpu(env
);
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
);
207 static uint64_t sun4v_tte_to_sun4u(CPUSPARCState
*env
, uint64_t tag
,
211 if (!(cpu_has_hypervisor(env
) && (tag
& TLB_UST1_IS_SUN4V_BIT
))) {
212 /* is already in the sun4u format */
215 sun4u_tte
= TTE_PA(sun4v_tte
) | (sun4v_tte
& TTE_VALID_BIT
);
216 sun4u_tte
|= (sun4v_tte
& 3ULL) << 61; /* TTE_PGSIZE */
217 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_NFO_BIT_UA2005
, TTE_NFO_BIT
);
218 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_USED_BIT_UA2005
, TTE_USED_BIT
);
219 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_W_OK_BIT_UA2005
, TTE_W_OK_BIT
);
220 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_SIDEEFFECT_BIT_UA2005
,
222 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_PRIV_BIT_UA2005
, TTE_PRIV_BIT
);
223 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_LOCKED_BIT_UA2005
, TTE_LOCKED_BIT
);
227 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
228 uint64_t tlb_tag
, uint64_t tlb_tte
,
229 const char *strmmu
, CPUSPARCState
*env1
,
232 unsigned int i
, replace_used
;
234 tlb_tte
= sun4v_tte_to_sun4u(env1
, addr
, tlb_tte
);
235 if (cpu_has_hypervisor(env1
)) {
236 uint64_t new_vaddr
= tlb_tag
& ~0x1fffULL
;
237 uint64_t new_size
= 8192ULL << 3 * TTE_PGSIZE(tlb_tte
);
238 uint32_t new_ctx
= tlb_tag
& 0x1fffU
;
239 for (i
= 0; i
< 64; i
++) {
240 uint32_t ctx
= tlb
[i
].tag
& 0x1fffU
;
241 /* check if new mapping overlaps an existing one */
242 if (new_ctx
== ctx
) {
243 uint64_t vaddr
= tlb
[i
].tag
& ~0x1fffULL
;
244 uint64_t size
= 8192ULL << 3 * TTE_PGSIZE(tlb
[i
].tte
);
245 if (new_vaddr
== vaddr
246 || (new_vaddr
< vaddr
+ size
247 && vaddr
< new_vaddr
+ new_size
)) {
248 DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i
, vaddr
,
250 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
257 /* Try replacing invalid entry */
258 for (i
= 0; i
< 64; i
++) {
259 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
260 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
262 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
269 /* All entries are valid, try replacing unlocked entry */
271 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
273 /* Used entries are not replaced on first pass */
275 for (i
= 0; i
< 64; i
++) {
276 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
278 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
280 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
281 strmmu
, (replace_used
? "used" : "unused"), i
);
288 /* Now reset used bit and search for unused entries again */
290 for (i
= 0; i
< 64; i
++) {
291 TTE_SET_UNUSED(tlb
[i
].tte
);
296 DPRINTF_MMU("%s lru replacement: no free entries available, "
297 "replacing the last one\n", strmmu
);
299 /* corner case: the last entry is replaced anyway */
300 replace_tlb_entry(&tlb
[63], tlb_tag
, tlb_tte
, env1
);
305 #ifdef TARGET_SPARC64
306 /* returns true if access using this ASI is to have address translated by MMU
307 otherwise access is to raw physical address */
308 /* TODO: check sparc32 bits */
309 static inline int is_translating_asi(int asi
)
311 /* Ultrasparc IIi translating asi
312 - note this list is defined by cpu implementation
329 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
331 if (AM_CHECK(env1
)) {
332 addr
&= 0xffffffffULL
;
337 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
338 int asi
, target_ulong addr
)
340 if (is_translating_asi(asi
)) {
341 addr
= address_mask(env
, addr
);
346 #ifndef CONFIG_USER_ONLY
347 static inline void do_check_asi(CPUSPARCState
*env
, int asi
, uintptr_t ra
)
349 /* ASIs >= 0x80 are user mode.
350 * ASIs >= 0x30 are hyper mode (or super if hyper is not available).
351 * ASIs <= 0x2f are super mode.
354 && !cpu_hypervisor_mode(env
)
355 && (!cpu_supervisor_mode(env
)
356 || (asi
>= 0x30 && cpu_has_hypervisor(env
)))) {
357 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, ra
);
360 #endif /* !CONFIG_USER_ONLY */
363 static void do_check_align(CPUSPARCState
*env
, target_ulong addr
,
364 uint32_t align
, uintptr_t ra
)
367 #ifdef DEBUG_UNALIGNED
368 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
369 "\n", addr
, env
->pc
);
371 cpu_raise_exception_ra(env
, TT_UNALIGNED
, ra
);
375 void helper_check_align(CPUSPARCState
*env
, target_ulong addr
, uint32_t align
)
377 do_check_align(env
, addr
, align
, GETPC());
380 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
382 static void dump_mxcc(CPUSPARCState
*env
)
384 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
386 env
->mxccdata
[0], env
->mxccdata
[1],
387 env
->mxccdata
[2], env
->mxccdata
[3]);
388 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
390 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
392 env
->mxccregs
[0], env
->mxccregs
[1],
393 env
->mxccregs
[2], env
->mxccregs
[3],
394 env
->mxccregs
[4], env
->mxccregs
[5],
395 env
->mxccregs
[6], env
->mxccregs
[7]);
399 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
400 && defined(DEBUG_ASI)
401 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
406 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
407 addr
, asi
, r1
& 0xff);
410 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
411 addr
, asi
, r1
& 0xffff);
414 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
415 addr
, asi
, r1
& 0xffffffff);
418 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
425 #ifndef TARGET_SPARC64
426 #ifndef CONFIG_USER_ONLY
429 /* Leon3 cache control */
431 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
432 uint64_t val
, int size
)
434 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
438 DPRINTF_CACHE_CONTROL("32bits only\n");
443 case 0x00: /* Cache control */
445 /* These values must always be read as zeros */
446 val
&= ~CACHE_CTRL_FD
;
447 val
&= ~CACHE_CTRL_FI
;
448 val
&= ~CACHE_CTRL_IB
;
449 val
&= ~CACHE_CTRL_IP
;
450 val
&= ~CACHE_CTRL_DP
;
452 env
->cache_control
= val
;
454 case 0x04: /* Instruction cache configuration */
455 case 0x08: /* Data cache configuration */
459 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
464 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
470 DPRINTF_CACHE_CONTROL("32bits only\n");
475 case 0x00: /* Cache control */
476 ret
= env
->cache_control
;
479 /* Configuration registers are read and only always keep those
482 case 0x04: /* Instruction cache configuration */
485 case 0x08: /* Data cache configuration */
489 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
492 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
497 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
498 int asi
, uint32_t memop
)
500 int size
= 1 << (memop
& MO_SIZE
);
501 int sign
= memop
& MO_SIGN
;
502 CPUState
*cs
= env_cpu(env
);
504 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
505 uint32_t last_addr
= addr
;
508 do_check_align(env
, addr
, size
- 1, GETPC());
510 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
511 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
513 case 0x00: /* Leon3 Cache Control */
514 case 0x08: /* Leon3 Instruction Cache config */
515 case 0x0C: /* Leon3 Date Cache config */
516 if (env
->def
.features
& CPU_FEATURE_CACHE_CTRL
) {
517 ret
= leon3_cache_control_ld(env
, addr
, size
);
520 case 0x01c00a00: /* MXCC control register */
522 ret
= env
->mxccregs
[3];
524 qemu_log_mask(LOG_UNIMP
,
525 "%08x: unimplemented access size: %d\n", addr
,
529 case 0x01c00a04: /* MXCC control register */
531 ret
= env
->mxccregs
[3];
533 qemu_log_mask(LOG_UNIMP
,
534 "%08x: unimplemented access size: %d\n", addr
,
538 case 0x01c00c00: /* Module reset register */
540 ret
= env
->mxccregs
[5];
541 /* should we do something here? */
543 qemu_log_mask(LOG_UNIMP
,
544 "%08x: unimplemented access size: %d\n", addr
,
548 case 0x01c00f00: /* MBus port address register */
550 ret
= env
->mxccregs
[7];
552 qemu_log_mask(LOG_UNIMP
,
553 "%08x: unimplemented access size: %d\n", addr
,
558 qemu_log_mask(LOG_UNIMP
,
559 "%08x: unimplemented address, size: %d\n", addr
,
563 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
564 "addr = %08x -> ret = %" PRIx64
","
565 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
570 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU probe */
571 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU probe */
575 mmulev
= (addr
>> 8) & 15;
579 ret
= mmu_probe(env
, addr
, mmulev
);
581 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
585 case ASI_M_MMUREGS
: /* SuperSparc MMU regs */
586 case ASI_LEON_MMUREGS
: /* LEON3 MMU regs */
588 int reg
= (addr
>> 8) & 0x1f;
590 ret
= env
->mmuregs
[reg
];
591 if (reg
== 3) { /* Fault status cleared on read */
593 } else if (reg
== 0x13) { /* Fault status read */
594 ret
= env
->mmuregs
[3];
595 } else if (reg
== 0x14) { /* Fault address read */
596 ret
= env
->mmuregs
[4];
598 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
601 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
602 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
603 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
605 case ASI_KERNELTXT
: /* Supervisor code access */
608 ret
= cpu_ldub_code(env
, addr
);
611 ret
= cpu_lduw_code(env
, addr
);
615 ret
= cpu_ldl_code(env
, addr
);
618 ret
= cpu_ldq_code(env
, addr
);
622 case ASI_M_TXTC_TAG
: /* SparcStation 5 I-cache tag */
623 case ASI_M_TXTC_DATA
: /* SparcStation 5 I-cache data */
624 case ASI_M_DATAC_TAG
: /* SparcStation 5 D-cache tag */
625 case ASI_M_DATAC_DATA
: /* SparcStation 5 D-cache data */
627 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
630 ret
= ldub_phys(cs
->as
, (hwaddr
)addr
631 | ((hwaddr
)(asi
& 0xf) << 32));
634 ret
= lduw_phys(cs
->as
, (hwaddr
)addr
635 | ((hwaddr
)(asi
& 0xf) << 32));
639 ret
= ldl_phys(cs
->as
, (hwaddr
)addr
640 | ((hwaddr
)(asi
& 0xf) << 32));
643 ret
= ldq_phys(cs
->as
, (hwaddr
)addr
644 | ((hwaddr
)(asi
& 0xf) << 32));
648 case 0x30: /* Turbosparc secondary cache diagnostic */
649 case 0x31: /* Turbosparc RAM snoop */
650 case 0x32: /* Turbosparc page table descriptor diagnostic */
651 case 0x39: /* data cache diagnostic register */
654 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
656 int reg
= (addr
>> 8) & 3;
659 case 0: /* Breakpoint Value (Addr) */
660 ret
= env
->mmubpregs
[reg
];
662 case 1: /* Breakpoint Mask */
663 ret
= env
->mmubpregs
[reg
];
665 case 2: /* Breakpoint Control */
666 ret
= env
->mmubpregs
[reg
];
668 case 3: /* Breakpoint Status */
669 ret
= env
->mmubpregs
[reg
];
670 env
->mmubpregs
[reg
] = 0ULL;
673 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
677 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
678 ret
= env
->mmubpctrv
;
680 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
681 ret
= env
->mmubpctrc
;
683 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
684 ret
= env
->mmubpctrs
;
686 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
687 ret
= env
->mmubpaction
;
689 case ASI_USERTXT
: /* User code access, XXX */
691 cpu_unassigned_access(cs
, addr
, false, false, asi
, size
);
695 case ASI_USERDATA
: /* User data access */
696 case ASI_KERNELDATA
: /* Supervisor data access */
697 case ASI_P
: /* Implicit primary context data access (v9 only?) */
698 case ASI_M_BYPASS
: /* MMU passthrough */
699 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
700 /* These are always handled inline. */
701 g_assert_not_reached();
719 dump_asi("read ", last_addr
, asi
, size
, ret
);
724 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
,
725 int asi
, uint32_t memop
)
727 int size
= 1 << (memop
& MO_SIZE
);
728 CPUState
*cs
= env_cpu(env
);
730 do_check_align(env
, addr
, size
- 1, GETPC());
732 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
733 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
735 case 0x00: /* Leon3 Cache Control */
736 case 0x08: /* Leon3 Instruction Cache config */
737 case 0x0C: /* Leon3 Date Cache config */
738 if (env
->def
.features
& CPU_FEATURE_CACHE_CTRL
) {
739 leon3_cache_control_st(env
, addr
, val
, size
);
743 case 0x01c00000: /* MXCC stream data register 0 */
745 env
->mxccdata
[0] = val
;
747 qemu_log_mask(LOG_UNIMP
,
748 "%08x: unimplemented access size: %d\n", addr
,
752 case 0x01c00008: /* MXCC stream data register 1 */
754 env
->mxccdata
[1] = val
;
756 qemu_log_mask(LOG_UNIMP
,
757 "%08x: unimplemented access size: %d\n", addr
,
761 case 0x01c00010: /* MXCC stream data register 2 */
763 env
->mxccdata
[2] = val
;
765 qemu_log_mask(LOG_UNIMP
,
766 "%08x: unimplemented access size: %d\n", addr
,
770 case 0x01c00018: /* MXCC stream data register 3 */
772 env
->mxccdata
[3] = val
;
774 qemu_log_mask(LOG_UNIMP
,
775 "%08x: unimplemented access size: %d\n", addr
,
779 case 0x01c00100: /* MXCC stream source */
781 env
->mxccregs
[0] = val
;
783 qemu_log_mask(LOG_UNIMP
,
784 "%08x: unimplemented access size: %d\n", addr
,
787 env
->mxccdata
[0] = ldq_phys(cs
->as
,
788 (env
->mxccregs
[0] & 0xffffffffULL
) +
790 env
->mxccdata
[1] = ldq_phys(cs
->as
,
791 (env
->mxccregs
[0] & 0xffffffffULL
) +
793 env
->mxccdata
[2] = ldq_phys(cs
->as
,
794 (env
->mxccregs
[0] & 0xffffffffULL
) +
796 env
->mxccdata
[3] = ldq_phys(cs
->as
,
797 (env
->mxccregs
[0] & 0xffffffffULL
) +
800 case 0x01c00200: /* MXCC stream destination */
802 env
->mxccregs
[1] = val
;
804 qemu_log_mask(LOG_UNIMP
,
805 "%08x: unimplemented access size: %d\n", addr
,
808 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 0,
810 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 8,
812 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 16,
814 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 24,
817 case 0x01c00a00: /* MXCC control register */
819 env
->mxccregs
[3] = val
;
821 qemu_log_mask(LOG_UNIMP
,
822 "%08x: unimplemented access size: %d\n", addr
,
826 case 0x01c00a04: /* MXCC control register */
828 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
831 qemu_log_mask(LOG_UNIMP
,
832 "%08x: unimplemented access size: %d\n", addr
,
836 case 0x01c00e00: /* MXCC error register */
837 /* writing a 1 bit clears the error */
839 env
->mxccregs
[6] &= ~val
;
841 qemu_log_mask(LOG_UNIMP
,
842 "%08x: unimplemented access size: %d\n", addr
,
846 case 0x01c00f00: /* MBus port address register */
848 env
->mxccregs
[7] = val
;
850 qemu_log_mask(LOG_UNIMP
,
851 "%08x: unimplemented access size: %d\n", addr
,
856 qemu_log_mask(LOG_UNIMP
,
857 "%08x: unimplemented address, size: %d\n", addr
,
861 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
862 asi
, size
, addr
, val
);
867 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU flush */
868 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU flush */
872 mmulev
= (addr
>> 8) & 15;
873 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
875 case 0: /* flush page */
876 tlb_flush_page(cs
, addr
& 0xfffff000);
878 case 1: /* flush segment (256k) */
879 case 2: /* flush region (16M) */
880 case 3: /* flush context (4G) */
881 case 4: /* flush entire */
892 case ASI_M_MMUREGS
: /* write MMU regs */
893 case ASI_LEON_MMUREGS
: /* LEON3 write MMU regs */
895 int reg
= (addr
>> 8) & 0x1f;
898 oldreg
= env
->mmuregs
[reg
];
900 case 0: /* Control Register */
901 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
903 /* Mappings generated during no-fault mode
904 are invalid in normal mode. */
905 if ((oldreg
^ env
->mmuregs
[reg
])
906 & (MMU_NF
| env
->def
.mmu_bm
)) {
910 case 1: /* Context Table Pointer Register */
911 env
->mmuregs
[reg
] = val
& env
->def
.mmu_ctpr_mask
;
913 case 2: /* Context Register */
914 env
->mmuregs
[reg
] = val
& env
->def
.mmu_cxr_mask
;
915 if (oldreg
!= env
->mmuregs
[reg
]) {
916 /* we flush when the MMU context changes because
917 QEMU has no MMU context support */
921 case 3: /* Synchronous Fault Status Register with Clear */
922 case 4: /* Synchronous Fault Address Register */
924 case 0x10: /* TLB Replacement Control Register */
925 env
->mmuregs
[reg
] = val
& env
->def
.mmu_trcr_mask
;
927 case 0x13: /* Synchronous Fault Status Register with Read
929 env
->mmuregs
[3] = val
& env
->def
.mmu_sfsr_mask
;
931 case 0x14: /* Synchronous Fault Address Register */
932 env
->mmuregs
[4] = val
;
935 env
->mmuregs
[reg
] = val
;
938 if (oldreg
!= env
->mmuregs
[reg
]) {
939 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
940 reg
, oldreg
, env
->mmuregs
[reg
]);
947 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
948 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
949 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
951 case ASI_M_TXTC_TAG
: /* I-cache tag */
952 case ASI_M_TXTC_DATA
: /* I-cache data */
953 case ASI_M_DATAC_TAG
: /* D-cache tag */
954 case ASI_M_DATAC_DATA
: /* D-cache data */
955 case ASI_M_FLUSH_PAGE
: /* I/D-cache flush page */
956 case ASI_M_FLUSH_SEG
: /* I/D-cache flush segment */
957 case ASI_M_FLUSH_REGION
: /* I/D-cache flush region */
958 case ASI_M_FLUSH_CTX
: /* I/D-cache flush context */
959 case ASI_M_FLUSH_USER
: /* I/D-cache flush user */
961 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
965 stb_phys(cs
->as
, (hwaddr
)addr
966 | ((hwaddr
)(asi
& 0xf) << 32), val
);
969 stw_phys(cs
->as
, (hwaddr
)addr
970 | ((hwaddr
)(asi
& 0xf) << 32), val
);
974 stl_phys(cs
->as
, (hwaddr
)addr
975 | ((hwaddr
)(asi
& 0xf) << 32), val
);
978 stq_phys(cs
->as
, (hwaddr
)addr
979 | ((hwaddr
)(asi
& 0xf) << 32), val
);
984 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
985 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
986 Turbosparc snoop RAM */
987 case 0x32: /* store buffer control or Turbosparc page table
988 descriptor diagnostic */
989 case 0x36: /* I-cache flash clear */
990 case 0x37: /* D-cache flash clear */
992 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
994 int reg
= (addr
>> 8) & 3;
997 case 0: /* Breakpoint Value (Addr) */
998 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1000 case 1: /* Breakpoint Mask */
1001 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1003 case 2: /* Breakpoint Control */
1004 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1006 case 3: /* Breakpoint Status */
1007 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1010 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1014 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1015 env
->mmubpctrv
= val
& 0xffffffff;
1017 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1018 env
->mmubpctrc
= val
& 0x3;
1020 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1021 env
->mmubpctrs
= val
& 0x3;
1023 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1024 env
->mmubpaction
= val
& 0x1fff;
1026 case ASI_USERTXT
: /* User code access, XXX */
1027 case ASI_KERNELTXT
: /* Supervisor code access, XXX */
1029 cpu_unassigned_access(cs
, addr
, true, false, asi
, size
);
1032 case ASI_USERDATA
: /* User data access */
1033 case ASI_KERNELDATA
: /* Supervisor data access */
1035 case ASI_M_BYPASS
: /* MMU passthrough */
1036 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
1037 case ASI_M_BCOPY
: /* Block copy, sta access */
1038 case ASI_M_BFILL
: /* Block fill, stda access */
1039 /* These are always handled inline. */
1040 g_assert_not_reached();
1043 dump_asi("write", addr
, asi
, size
, val
);
1047 #endif /* CONFIG_USER_ONLY */
1048 #else /* TARGET_SPARC64 */
1050 #ifdef CONFIG_USER_ONLY
1051 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1052 int asi
, uint32_t memop
)
1054 int size
= 1 << (memop
& MO_SIZE
);
1055 int sign
= memop
& MO_SIGN
;
1059 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1061 do_check_align(env
, addr
, size
- 1, GETPC());
1062 addr
= asi_address_mask(env
, asi
, addr
);
1065 case ASI_PNF
: /* Primary no-fault */
1066 case ASI_PNFL
: /* Primary no-fault LE */
1067 case ASI_SNF
: /* Secondary no-fault */
1068 case ASI_SNFL
: /* Secondary no-fault LE */
1069 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1075 ret
= cpu_ldub_data(env
, addr
);
1078 ret
= cpu_lduw_data(env
, addr
);
1081 ret
= cpu_ldl_data(env
, addr
);
1084 ret
= cpu_ldq_data(env
, addr
);
1087 g_assert_not_reached();
1092 case ASI_P
: /* Primary */
1093 case ASI_PL
: /* Primary LE */
1094 case ASI_S
: /* Secondary */
1095 case ASI_SL
: /* Secondary LE */
1096 /* These are always handled inline. */
1097 g_assert_not_reached();
1100 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1103 /* Convert from little endian */
1105 case ASI_PNFL
: /* Primary no-fault LE */
1106 case ASI_SNFL
: /* Secondary no-fault LE */
1120 /* Convert to signed number */
1127 ret
= (int16_t) ret
;
1130 ret
= (int32_t) ret
;
1135 dump_asi("read", addr
, asi
, size
, ret
);
1140 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1141 int asi
, uint32_t memop
)
1143 int size
= 1 << (memop
& MO_SIZE
);
1145 dump_asi("write", addr
, asi
, size
, val
);
1148 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1150 do_check_align(env
, addr
, size
- 1, GETPC());
1153 case ASI_P
: /* Primary */
1154 case ASI_PL
: /* Primary LE */
1155 case ASI_S
: /* Secondary */
1156 case ASI_SL
: /* Secondary LE */
1157 /* These are always handled inline. */
1158 g_assert_not_reached();
1160 case ASI_PNF
: /* Primary no-fault, RO */
1161 case ASI_SNF
: /* Secondary no-fault, RO */
1162 case ASI_PNFL
: /* Primary no-fault LE, RO */
1163 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1165 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1169 #else /* CONFIG_USER_ONLY */
1171 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1172 int asi
, uint32_t memop
)
1174 int size
= 1 << (memop
& MO_SIZE
);
1175 int sign
= memop
& MO_SIGN
;
1176 CPUState
*cs
= env_cpu(env
);
1178 #if defined(DEBUG_ASI)
1179 target_ulong last_addr
= addr
;
1184 do_check_asi(env
, asi
, GETPC());
1185 do_check_align(env
, addr
, size
- 1, GETPC());
1186 addr
= asi_address_mask(env
, asi
, addr
);
1195 int idx
= (env
->pstate
& PS_PRIV
1196 ? (asi
& 1 ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
)
1197 : (asi
& 1 ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
));
1199 if (cpu_get_phys_page_nofault(env
, addr
, idx
) == -1ULL) {
1201 dump_asi("read ", last_addr
, asi
, size
, ret
);
1203 /* exception_index is set in get_physical_address_data. */
1204 cpu_raise_exception_ra(env
, cs
->exception_index
, GETPC());
1206 oi
= make_memop_idx(memop
, idx
);
1209 ret
= helper_ret_ldub_mmu(env
, addr
, oi
, GETPC());
1213 ret
= helper_le_lduw_mmu(env
, addr
, oi
, GETPC());
1215 ret
= helper_be_lduw_mmu(env
, addr
, oi
, GETPC());
1220 ret
= helper_le_ldul_mmu(env
, addr
, oi
, GETPC());
1222 ret
= helper_be_ldul_mmu(env
, addr
, oi
, GETPC());
1227 ret
= helper_le_ldq_mmu(env
, addr
, oi
, GETPC());
1229 ret
= helper_be_ldq_mmu(env
, addr
, oi
, GETPC());
1233 g_assert_not_reached();
1238 case ASI_AIUP
: /* As if user primary */
1239 case ASI_AIUS
: /* As if user secondary */
1240 case ASI_AIUPL
: /* As if user primary LE */
1241 case ASI_AIUSL
: /* As if user secondary LE */
1242 case ASI_P
: /* Primary */
1243 case ASI_S
: /* Secondary */
1244 case ASI_PL
: /* Primary LE */
1245 case ASI_SL
: /* Secondary LE */
1246 case ASI_REAL
: /* Bypass */
1247 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1248 case ASI_REAL_L
: /* Bypass LE */
1249 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1250 case ASI_N
: /* Nucleus */
1251 case ASI_NL
: /* Nucleus Little Endian (LE) */
1252 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1253 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1254 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1255 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1256 case ASI_TWINX_REAL
: /* Real address, twinx */
1257 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1258 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1259 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1260 case ASI_TWINX_N
: /* Nucleus, twinx */
1261 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1262 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1263 case ASI_TWINX_P
: /* Primary, twinx */
1264 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1265 case ASI_TWINX_S
: /* Secondary, twinx */
1266 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1267 /* These are always handled inline. */
1268 g_assert_not_reached();
1270 case ASI_UPA_CONFIG
: /* UPA config */
1273 case ASI_LSU_CONTROL
: /* LSU */
1276 case ASI_IMMU
: /* I-MMU regs */
1278 int reg
= (addr
>> 3) & 0xf;
1281 /* 0x00 I-TSB Tag Target register */
1282 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1285 ret
= env
->immu
.sfsr
;
1287 case 5: /* TSB access */
1288 ret
= env
->immu
.tsb
;
1291 /* 0x30 I-TSB Tag Access register */
1292 ret
= env
->immu
.tag_access
;
1295 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1300 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer */
1302 /* env->immuregs[5] holds I-MMU TSB register value
1303 env->immuregs[6] holds I-MMU Tag Access register value */
1304 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 0);
1307 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer */
1309 /* env->immuregs[5] holds I-MMU TSB register value
1310 env->immuregs[6] holds I-MMU Tag Access register value */
1311 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 1);
1314 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1316 int reg
= (addr
>> 3) & 0x3f;
1318 ret
= env
->itlb
[reg
].tte
;
1321 case ASI_ITLB_TAG_READ
: /* I-MMU tag read */
1323 int reg
= (addr
>> 3) & 0x3f;
1325 ret
= env
->itlb
[reg
].tag
;
1328 case ASI_DMMU
: /* D-MMU regs */
1330 int reg
= (addr
>> 3) & 0xf;
1333 /* 0x00 D-TSB Tag Target register */
1334 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1336 case 1: /* 0x08 Primary Context */
1337 ret
= env
->dmmu
.mmu_primary_context
;
1339 case 2: /* 0x10 Secondary Context */
1340 ret
= env
->dmmu
.mmu_secondary_context
;
1343 ret
= env
->dmmu
.sfsr
;
1345 case 4: /* 0x20 SFAR */
1346 ret
= env
->dmmu
.sfar
;
1348 case 5: /* 0x28 TSB access */
1349 ret
= env
->dmmu
.tsb
;
1351 case 6: /* 0x30 D-TSB Tag Access register */
1352 ret
= env
->dmmu
.tag_access
;
1355 ret
= env
->dmmu
.virtual_watchpoint
;
1358 ret
= env
->dmmu
.physical_watchpoint
;
1361 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1366 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer */
1368 /* env->dmmuregs[5] holds D-MMU TSB register value
1369 env->dmmuregs[6] holds D-MMU Tag Access register value */
1370 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 0);
1373 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer */
1375 /* env->dmmuregs[5] holds D-MMU TSB register value
1376 env->dmmuregs[6] holds D-MMU Tag Access register value */
1377 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 1);
1380 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1382 int reg
= (addr
>> 3) & 0x3f;
1384 ret
= env
->dtlb
[reg
].tte
;
1387 case ASI_DTLB_TAG_READ
: /* D-MMU tag read */
1389 int reg
= (addr
>> 3) & 0x3f;
1391 ret
= env
->dtlb
[reg
].tag
;
1394 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1396 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1397 ret
= env
->ivec_status
;
1399 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1401 int reg
= (addr
>> 4) & 0x3;
1403 ret
= env
->ivec_data
[reg
];
1407 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1408 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1409 /* Hyperprivileged access only */
1410 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1413 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1415 unsigned int i
= (addr
>> 3) & 0x7;
1416 ret
= env
->scratch
[i
];
1419 case ASI_MMU
: /* UA2005 Context ID registers */
1420 switch ((addr
>> 3) & 0x3) {
1422 ret
= env
->dmmu
.mmu_primary_context
;
1425 ret
= env
->dmmu
.mmu_secondary_context
;
1428 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1431 case ASI_DCACHE_DATA
: /* D-cache data */
1432 case ASI_DCACHE_TAG
: /* D-cache tag access */
1433 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1434 case ASI_AFSR
: /* E-cache asynchronous fault status */
1435 case ASI_AFAR
: /* E-cache asynchronous fault address */
1436 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1437 case ASI_IC_INSTR
: /* I-cache instruction access */
1438 case ASI_IC_TAG
: /* I-cache tag access */
1439 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1440 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1441 case ASI_EC_W
: /* E-cache tag */
1442 case ASI_EC_R
: /* E-cache tag */
1444 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer */
1445 case ASI_ITLB_DATA_IN
: /* I-MMU data in, WO */
1446 case ASI_IMMU_DEMAP
: /* I-MMU demap, WO */
1447 case ASI_DTLB_DATA_IN
: /* D-MMU data in, WO */
1448 case ASI_DMMU_DEMAP
: /* D-MMU demap, WO */
1449 case ASI_INTR_W
: /* Interrupt vector, WO */
1451 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1456 /* Convert to signed number */
1463 ret
= (int16_t) ret
;
1466 ret
= (int32_t) ret
;
1473 dump_asi("read ", last_addr
, asi
, size
, ret
);
1478 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1479 int asi
, uint32_t memop
)
1481 int size
= 1 << (memop
& MO_SIZE
);
1482 CPUState
*cs
= env_cpu(env
);
1485 dump_asi("write", addr
, asi
, size
, val
);
1490 do_check_asi(env
, asi
, GETPC());
1491 do_check_align(env
, addr
, size
- 1, GETPC());
1492 addr
= asi_address_mask(env
, asi
, addr
);
1495 case ASI_AIUP
: /* As if user primary */
1496 case ASI_AIUS
: /* As if user secondary */
1497 case ASI_AIUPL
: /* As if user primary LE */
1498 case ASI_AIUSL
: /* As if user secondary LE */
1499 case ASI_P
: /* Primary */
1500 case ASI_S
: /* Secondary */
1501 case ASI_PL
: /* Primary LE */
1502 case ASI_SL
: /* Secondary LE */
1503 case ASI_REAL
: /* Bypass */
1504 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1505 case ASI_REAL_L
: /* Bypass LE */
1506 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1507 case ASI_N
: /* Nucleus */
1508 case ASI_NL
: /* Nucleus Little Endian (LE) */
1509 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1510 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1511 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1512 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1513 case ASI_TWINX_REAL
: /* Real address, twinx */
1514 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1515 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1516 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1517 case ASI_TWINX_N
: /* Nucleus, twinx */
1518 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1519 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1520 case ASI_TWINX_P
: /* Primary, twinx */
1521 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1522 case ASI_TWINX_S
: /* Secondary, twinx */
1523 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1524 /* These are always handled inline. */
1525 g_assert_not_reached();
1526 /* these ASIs have different functions on UltraSPARC-IIIi
1527 * and UA2005 CPUs. Use the explicit numbers to avoid confusion
1533 if (cpu_has_hypervisor(env
)) {
1535 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS0
1536 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS1
1537 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS0
1538 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS1
1540 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1541 env
->dmmu
.sun4v_tsb_pointers
[idx
] = val
;
1543 helper_raise_exception(env
, TT_ILL_INSN
);
1548 if (cpu_has_hypervisor(env
)) {
1550 * ASI_DMMU_CTX_ZERO_CONFIG
1551 * ASI_DMMU_CTX_NONZERO_CONFIG
1553 env
->dmmu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1555 helper_raise_exception(env
, TT_ILL_INSN
);
1562 if (cpu_has_hypervisor(env
)) {
1564 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS0
1565 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS1
1566 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS0
1567 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS1
1569 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1570 env
->immu
.sun4v_tsb_pointers
[idx
] = val
;
1572 helper_raise_exception(env
, TT_ILL_INSN
);
1577 if (cpu_has_hypervisor(env
)) {
1579 * ASI_IMMU_CTX_ZERO_CONFIG
1580 * ASI_IMMU_CTX_NONZERO_CONFIG
1582 env
->immu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1584 helper_raise_exception(env
, TT_ILL_INSN
);
1587 case ASI_UPA_CONFIG
: /* UPA config */
1590 case ASI_LSU_CONTROL
: /* LSU */
1591 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1593 case ASI_IMMU
: /* I-MMU regs */
1595 int reg
= (addr
>> 3) & 0xf;
1598 oldreg
= env
->immu
.mmuregs
[reg
];
1602 case 1: /* Not in I-MMU */
1606 if ((val
& 1) == 0) {
1607 val
= 0; /* Clear SFSR */
1609 env
->immu
.sfsr
= val
;
1613 case 5: /* TSB access */
1614 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1615 PRIx64
"\n", env
->immu
.tsb
, val
);
1616 env
->immu
.tsb
= val
;
1618 case 6: /* Tag access */
1619 env
->immu
.tag_access
= val
;
1625 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1629 if (oldreg
!= env
->immu
.mmuregs
[reg
]) {
1630 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1631 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1638 case ASI_ITLB_DATA_IN
: /* I-MMU data in */
1639 /* ignore real translation entries */
1640 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1641 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
,
1642 val
, "immu", env
, addr
);
1645 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1647 /* TODO: auto demap */
1649 unsigned int i
= (addr
>> 3) & 0x3f;
1651 /* ignore real translation entries */
1652 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1653 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
,
1654 sun4v_tte_to_sun4u(env
, addr
, val
), env
);
1657 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1662 case ASI_IMMU_DEMAP
: /* I-MMU demap */
1663 demap_tlb(env
->itlb
, addr
, "immu", env
);
1665 case ASI_DMMU
: /* D-MMU regs */
1667 int reg
= (addr
>> 3) & 0xf;
1670 oldreg
= env
->dmmu
.mmuregs
[reg
];
1676 if ((val
& 1) == 0) {
1677 val
= 0; /* Clear SFSR, Fault address */
1680 env
->dmmu
.sfsr
= val
;
1682 case 1: /* Primary context */
1683 env
->dmmu
.mmu_primary_context
= val
;
1684 /* can be optimized to only flush MMU_USER_IDX
1685 and MMU_KERNEL_IDX entries */
1688 case 2: /* Secondary context */
1689 env
->dmmu
.mmu_secondary_context
= val
;
1690 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1691 and MMU_KERNEL_SECONDARY_IDX entries */
1694 case 5: /* TSB access */
1695 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1696 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1697 env
->dmmu
.tsb
= val
;
1699 case 6: /* Tag access */
1700 env
->dmmu
.tag_access
= val
;
1702 case 7: /* Virtual Watchpoint */
1703 env
->dmmu
.virtual_watchpoint
= val
;
1705 case 8: /* Physical Watchpoint */
1706 env
->dmmu
.physical_watchpoint
= val
;
1709 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1713 if (oldreg
!= env
->dmmu
.mmuregs
[reg
]) {
1714 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1715 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1722 case ASI_DTLB_DATA_IN
: /* D-MMU data in */
1723 /* ignore real translation entries */
1724 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1725 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
,
1726 val
, "dmmu", env
, addr
);
1729 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1731 unsigned int i
= (addr
>> 3) & 0x3f;
1733 /* ignore real translation entries */
1734 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1735 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
,
1736 sun4v_tte_to_sun4u(env
, addr
, val
), env
);
1739 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1744 case ASI_DMMU_DEMAP
: /* D-MMU demap */
1745 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1747 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1748 env
->ivec_status
= val
& 0x20;
1750 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1751 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1752 /* Hyperprivileged access only */
1753 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1756 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1758 unsigned int i
= (addr
>> 3) & 0x7;
1759 env
->scratch
[i
] = val
;
1762 case ASI_MMU
: /* UA2005 Context ID registers */
1764 switch ((addr
>> 3) & 0x3) {
1766 env
->dmmu
.mmu_primary_context
= val
;
1767 env
->immu
.mmu_primary_context
= val
;
1768 tlb_flush_by_mmuidx(cs
,
1769 (1 << MMU_USER_IDX
) | (1 << MMU_KERNEL_IDX
));
1772 env
->dmmu
.mmu_secondary_context
= val
;
1773 env
->immu
.mmu_secondary_context
= val
;
1774 tlb_flush_by_mmuidx(cs
,
1775 (1 << MMU_USER_SECONDARY_IDX
) |
1776 (1 << MMU_KERNEL_SECONDARY_IDX
));
1779 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1783 case ASI_QUEUE
: /* UA2005 CPU mondo queue */
1784 case ASI_DCACHE_DATA
: /* D-cache data */
1785 case ASI_DCACHE_TAG
: /* D-cache tag access */
1786 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1787 case ASI_AFSR
: /* E-cache asynchronous fault status */
1788 case ASI_AFAR
: /* E-cache asynchronous fault address */
1789 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1790 case ASI_IC_INSTR
: /* I-cache instruction access */
1791 case ASI_IC_TAG
: /* I-cache tag access */
1792 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1793 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1794 case ASI_EC_W
: /* E-cache tag */
1795 case ASI_EC_R
: /* E-cache tag */
1797 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer, RO */
1798 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer, RO */
1799 case ASI_ITLB_TAG_READ
: /* I-MMU tag read, RO */
1800 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer, RO */
1801 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer, RO */
1802 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer, RO */
1803 case ASI_DTLB_TAG_READ
: /* D-MMU tag read, RO */
1804 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1805 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1806 case ASI_PNF
: /* Primary no-fault, RO */
1807 case ASI_SNF
: /* Secondary no-fault, RO */
1808 case ASI_PNFL
: /* Primary no-fault LE, RO */
1809 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1811 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
1815 #endif /* CONFIG_USER_ONLY */
1816 #endif /* TARGET_SPARC64 */
1818 #if !defined(CONFIG_USER_ONLY)
1819 #ifndef TARGET_SPARC64
1820 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
1821 bool is_write
, bool is_exec
, int is_asi
,
1824 SPARCCPU
*cpu
= SPARC_CPU(cs
);
1825 CPUSPARCState
*env
= &cpu
->env
;
1828 #ifdef DEBUG_UNASSIGNED
1830 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
1831 " asi 0x%02x from " TARGET_FMT_lx
"\n",
1832 is_exec
? "exec" : is_write
? "write" : "read", size
,
1833 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
1835 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
1836 " from " TARGET_FMT_lx
"\n",
1837 is_exec
? "exec" : is_write
? "write" : "read", size
,
1838 size
== 1 ? "" : "s", addr
, env
->pc
);
1841 /* Don't overwrite translation and access faults */
1842 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
1843 if ((fault_type
> 4) || (fault_type
== 0)) {
1844 env
->mmuregs
[3] = 0; /* Fault status register */
1846 env
->mmuregs
[3] |= 1 << 16;
1849 env
->mmuregs
[3] |= 1 << 5;
1852 env
->mmuregs
[3] |= 1 << 6;
1855 env
->mmuregs
[3] |= 1 << 7;
1857 env
->mmuregs
[3] |= (5 << 2) | 2;
1858 /* SuperSPARC will never place instruction fault addresses in the FAR */
1860 env
->mmuregs
[4] = addr
; /* Fault address register */
1863 /* overflow (same type fault was not read before another fault) */
1864 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
1865 env
->mmuregs
[3] |= 1;
1868 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
1869 int tt
= is_exec
? TT_CODE_ACCESS
: TT_DATA_ACCESS
;
1870 cpu_raise_exception_ra(env
, tt
, GETPC());
1873 /* flush neverland mappings created during no-fault mode,
1874 so the sequential MMU faults report proper fault types */
1875 if (env
->mmuregs
[0] & MMU_NF
) {
1880 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
1881 bool is_write
, bool is_exec
, int is_asi
,
1884 SPARCCPU
*cpu
= SPARC_CPU(cs
);
1885 CPUSPARCState
*env
= &cpu
->env
;
1887 #ifdef DEBUG_UNASSIGNED
1888 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
1889 "\n", addr
, env
->pc
);
1892 if (is_exec
) { /* XXX has_hypervisor */
1893 if (env
->lsu
& (IMMU_E
)) {
1894 cpu_raise_exception_ra(env
, TT_CODE_ACCESS
, GETPC());
1895 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
1896 cpu_raise_exception_ra(env
, TT_INSN_REAL_TRANSLATION_MISS
, GETPC());
1899 if (env
->lsu
& (DMMU_E
)) {
1900 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1901 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
1902 cpu_raise_exception_ra(env
, TT_DATA_REAL_TRANSLATION_MISS
, GETPC());
1909 #if !defined(CONFIG_USER_ONLY)
1910 void QEMU_NORETURN
sparc_cpu_do_unaligned_access(CPUState
*cs
, vaddr addr
,
1911 MMUAccessType access_type
,
1915 SPARCCPU
*cpu
= SPARC_CPU(cs
);
1916 CPUSPARCState
*env
= &cpu
->env
;
1918 #ifdef DEBUG_UNALIGNED
1919 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
1920 "\n", addr
, env
->pc
);
1922 cpu_raise_exception_ra(env
, TT_UNALIGNED
, retaddr
);