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.1 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"
24 #include "exec/helper-proto.h"
25 #include "exec/exec-all.h"
26 #include "exec/cpu_ldst.h"
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 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
70 /* Calculates TSB pointer value for fault page size
71 * UltraSPARC IIi has fixed sizes (8k or 64k) for the page pointers
72 * UA2005 holds the page size configuration in mmu_ctx registers */
73 static uint64_t ultrasparc_tsb_pointer(CPUSPARCState
*env
,
74 const SparcV9MMU
*mmu
, const int idx
)
76 uint64_t tsb_register
;
78 if (cpu_has_hypervisor(env
)) {
80 int ctx
= mmu
->tag_access
& 0x1fffULL
;
81 uint64_t ctx_register
= mmu
->sun4v_ctx_config
[ctx
? 1 : 0];
83 tsb_index
|= ctx
? 2 : 0;
84 page_size
= idx
? ctx_register
>> 8 : ctx_register
;
86 tsb_register
= mmu
->sun4v_tsb_pointers
[tsb_index
];
89 tsb_register
= mmu
->tsb
;
91 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
92 int tsb_size
= tsb_register
& 0xf;
94 uint64_t tsb_base_mask
= (~0x1fffULL
) << tsb_size
;
96 /* move va bits to correct position,
97 * the context bits will be masked out later */
98 uint64_t va
= mmu
->tag_access
>> (3 * page_size
+ 9);
100 /* calculate tsb_base mask and adjust va if split is in use */
103 va
&= ~(1ULL << (13 + tsb_size
));
105 va
|= (1ULL << (13 + tsb_size
));
110 return ((tsb_register
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
113 /* Calculates tag target register value by reordering bits
114 in tag access register */
115 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
117 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
120 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
121 uint64_t tlb_tag
, uint64_t tlb_tte
,
124 target_ulong mask
, size
, va
, offset
;
126 /* flush page range if translation is valid */
127 if (TTE_IS_VALID(tlb
->tte
)) {
128 CPUState
*cs
= env_cpu(env
);
130 size
= 8192ULL << 3 * TTE_PGSIZE(tlb
->tte
);
133 va
= tlb
->tag
& mask
;
135 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
136 tlb_flush_page(cs
, va
+ offset
);
144 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
145 const char *strmmu
, CPUSPARCState
*env1
)
151 int is_demap_context
= (demap_addr
>> 6) & 1;
154 switch ((demap_addr
>> 4) & 3) {
155 case 0: /* primary */
156 context
= env1
->dmmu
.mmu_primary_context
;
158 case 1: /* secondary */
159 context
= env1
->dmmu
.mmu_secondary_context
;
161 case 2: /* nucleus */
164 case 3: /* reserved */
169 for (i
= 0; i
< 64; i
++) {
170 if (TTE_IS_VALID(tlb
[i
].tte
)) {
172 if (is_demap_context
) {
173 /* will remove non-global entries matching context value */
174 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
175 !tlb_compare_context(&tlb
[i
], context
)) {
180 will remove any entry matching VA */
181 mask
= 0xffffffffffffe000ULL
;
182 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
184 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
188 /* entry should be global or matching context value */
189 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
190 !tlb_compare_context(&tlb
[i
], context
)) {
195 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
197 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
204 static uint64_t sun4v_tte_to_sun4u(CPUSPARCState
*env
, uint64_t tag
,
208 if (!(cpu_has_hypervisor(env
) && (tag
& TLB_UST1_IS_SUN4V_BIT
))) {
209 /* is already in the sun4u format */
212 sun4u_tte
= TTE_PA(sun4v_tte
) | (sun4v_tte
& TTE_VALID_BIT
);
213 sun4u_tte
|= (sun4v_tte
& 3ULL) << 61; /* TTE_PGSIZE */
214 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_NFO_BIT_UA2005
, TTE_NFO_BIT
);
215 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_USED_BIT_UA2005
, TTE_USED_BIT
);
216 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_W_OK_BIT_UA2005
, TTE_W_OK_BIT
);
217 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_SIDEEFFECT_BIT_UA2005
,
219 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_PRIV_BIT_UA2005
, TTE_PRIV_BIT
);
220 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_LOCKED_BIT_UA2005
, TTE_LOCKED_BIT
);
224 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
225 uint64_t tlb_tag
, uint64_t tlb_tte
,
226 const char *strmmu
, CPUSPARCState
*env1
,
229 unsigned int i
, replace_used
;
231 tlb_tte
= sun4v_tte_to_sun4u(env1
, addr
, tlb_tte
);
232 if (cpu_has_hypervisor(env1
)) {
233 uint64_t new_vaddr
= tlb_tag
& ~0x1fffULL
;
234 uint64_t new_size
= 8192ULL << 3 * TTE_PGSIZE(tlb_tte
);
235 uint32_t new_ctx
= tlb_tag
& 0x1fffU
;
236 for (i
= 0; i
< 64; i
++) {
237 uint32_t ctx
= tlb
[i
].tag
& 0x1fffU
;
238 /* check if new mapping overlaps an existing one */
239 if (new_ctx
== ctx
) {
240 uint64_t vaddr
= tlb
[i
].tag
& ~0x1fffULL
;
241 uint64_t size
= 8192ULL << 3 * TTE_PGSIZE(tlb
[i
].tte
);
242 if (new_vaddr
== vaddr
243 || (new_vaddr
< vaddr
+ size
244 && vaddr
< new_vaddr
+ new_size
)) {
245 DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i
, vaddr
,
247 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
254 /* Try replacing invalid entry */
255 for (i
= 0; i
< 64; i
++) {
256 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
257 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
259 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
266 /* All entries are valid, try replacing unlocked entry */
268 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
270 /* Used entries are not replaced on first pass */
272 for (i
= 0; i
< 64; i
++) {
273 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
275 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
277 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
278 strmmu
, (replace_used
? "used" : "unused"), i
);
285 /* Now reset used bit and search for unused entries again */
287 for (i
= 0; i
< 64; i
++) {
288 TTE_SET_UNUSED(tlb
[i
].tte
);
293 DPRINTF_MMU("%s lru replacement: no free entries available, "
294 "replacing the last one\n", strmmu
);
296 /* corner case: the last entry is replaced anyway */
297 replace_tlb_entry(&tlb
[63], tlb_tag
, tlb_tte
, env1
);
302 #ifdef TARGET_SPARC64
303 /* returns true if access using this ASI is to have address translated by MMU
304 otherwise access is to raw physical address */
305 /* TODO: check sparc32 bits */
306 static inline int is_translating_asi(int asi
)
308 /* Ultrasparc IIi translating asi
309 - note this list is defined by cpu implementation
326 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
328 if (AM_CHECK(env1
)) {
329 addr
&= 0xffffffffULL
;
334 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
335 int asi
, target_ulong addr
)
337 if (is_translating_asi(asi
)) {
338 addr
= address_mask(env
, addr
);
343 #ifndef CONFIG_USER_ONLY
344 static inline void do_check_asi(CPUSPARCState
*env
, int asi
, uintptr_t ra
)
346 /* ASIs >= 0x80 are user mode.
347 * ASIs >= 0x30 are hyper mode (or super if hyper is not available).
348 * ASIs <= 0x2f are super mode.
351 && !cpu_hypervisor_mode(env
)
352 && (!cpu_supervisor_mode(env
)
353 || (asi
>= 0x30 && cpu_has_hypervisor(env
)))) {
354 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, ra
);
357 #endif /* !CONFIG_USER_ONLY */
360 #if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
361 static void do_check_align(CPUSPARCState
*env
, target_ulong addr
,
362 uint32_t align
, uintptr_t ra
)
365 cpu_raise_exception_ra(env
, TT_UNALIGNED
, ra
);
370 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
372 static void dump_mxcc(CPUSPARCState
*env
)
374 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
376 env
->mxccdata
[0], env
->mxccdata
[1],
377 env
->mxccdata
[2], env
->mxccdata
[3]);
378 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
380 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
382 env
->mxccregs
[0], env
->mxccregs
[1],
383 env
->mxccregs
[2], env
->mxccregs
[3],
384 env
->mxccregs
[4], env
->mxccregs
[5],
385 env
->mxccregs
[6], env
->mxccregs
[7]);
389 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
390 && defined(DEBUG_ASI)
391 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
396 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
397 addr
, asi
, r1
& 0xff);
400 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
401 addr
, asi
, r1
& 0xffff);
404 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
405 addr
, asi
, r1
& 0xffffffff);
408 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
415 #ifndef CONFIG_USER_ONLY
416 #ifndef TARGET_SPARC64
417 static void sparc_raise_mmu_fault(CPUState
*cs
, hwaddr addr
,
418 bool is_write
, bool is_exec
, int is_asi
,
419 unsigned size
, uintptr_t retaddr
)
421 SPARCCPU
*cpu
= SPARC_CPU(cs
);
422 CPUSPARCState
*env
= &cpu
->env
;
425 #ifdef DEBUG_UNASSIGNED
427 printf("Unassigned mem %s access of %d byte%s to " HWADDR_FMT_plx
428 " asi 0x%02x from " TARGET_FMT_lx
"\n",
429 is_exec
? "exec" : is_write
? "write" : "read", size
,
430 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
432 printf("Unassigned mem %s access of %d byte%s to " HWADDR_FMT_plx
433 " from " TARGET_FMT_lx
"\n",
434 is_exec
? "exec" : is_write
? "write" : "read", size
,
435 size
== 1 ? "" : "s", addr
, env
->pc
);
438 /* Don't overwrite translation and access faults */
439 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
440 if ((fault_type
> 4) || (fault_type
== 0)) {
441 env
->mmuregs
[3] = 0; /* Fault status register */
443 env
->mmuregs
[3] |= 1 << 16;
446 env
->mmuregs
[3] |= 1 << 5;
449 env
->mmuregs
[3] |= 1 << 6;
452 env
->mmuregs
[3] |= 1 << 7;
454 env
->mmuregs
[3] |= (5 << 2) | 2;
455 /* SuperSPARC will never place instruction fault addresses in the FAR */
457 env
->mmuregs
[4] = addr
; /* Fault address register */
460 /* overflow (same type fault was not read before another fault) */
461 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
462 env
->mmuregs
[3] |= 1;
465 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
466 int tt
= is_exec
? TT_CODE_ACCESS
: TT_DATA_ACCESS
;
467 cpu_raise_exception_ra(env
, tt
, retaddr
);
471 * flush neverland mappings created during no-fault mode,
472 * so the sequential MMU faults report proper fault types
474 if (env
->mmuregs
[0] & MMU_NF
) {
479 static void sparc_raise_mmu_fault(CPUState
*cs
, hwaddr addr
,
480 bool is_write
, bool is_exec
, int is_asi
,
481 unsigned size
, uintptr_t retaddr
)
483 SPARCCPU
*cpu
= SPARC_CPU(cs
);
484 CPUSPARCState
*env
= &cpu
->env
;
486 #ifdef DEBUG_UNASSIGNED
487 printf("Unassigned mem access to " HWADDR_FMT_plx
" from " TARGET_FMT_lx
488 "\n", addr
, env
->pc
);
491 if (is_exec
) { /* XXX has_hypervisor */
492 if (env
->lsu
& (IMMU_E
)) {
493 cpu_raise_exception_ra(env
, TT_CODE_ACCESS
, retaddr
);
494 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
495 cpu_raise_exception_ra(env
, TT_INSN_REAL_TRANSLATION_MISS
, retaddr
);
498 if (env
->lsu
& (DMMU_E
)) {
499 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, retaddr
);
500 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
501 cpu_raise_exception_ra(env
, TT_DATA_REAL_TRANSLATION_MISS
, retaddr
);
508 #ifndef TARGET_SPARC64
509 #ifndef CONFIG_USER_ONLY
512 /* Leon3 cache control */
514 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
515 uint64_t val
, int size
)
517 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
521 DPRINTF_CACHE_CONTROL("32bits only\n");
526 case 0x00: /* Cache control */
528 /* These values must always be read as zeros */
529 val
&= ~CACHE_CTRL_FD
;
530 val
&= ~CACHE_CTRL_FI
;
531 val
&= ~CACHE_CTRL_IB
;
532 val
&= ~CACHE_CTRL_IP
;
533 val
&= ~CACHE_CTRL_DP
;
535 env
->cache_control
= val
;
537 case 0x04: /* Instruction cache configuration */
538 case 0x08: /* Data cache configuration */
542 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
547 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
553 DPRINTF_CACHE_CONTROL("32bits only\n");
558 case 0x00: /* Cache control */
559 ret
= env
->cache_control
;
562 /* Configuration registers are read and only always keep those
565 case 0x04: /* Instruction cache configuration */
568 case 0x08: /* Data cache configuration */
572 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
575 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
580 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
581 int asi
, uint32_t memop
)
583 int size
= 1 << (memop
& MO_SIZE
);
584 int sign
= memop
& MO_SIGN
;
585 CPUState
*cs
= env_cpu(env
);
587 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
588 uint32_t last_addr
= addr
;
592 do_check_align(env
, addr
, size
- 1, GETPC());
594 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
595 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
597 case 0x00: /* Leon3 Cache Control */
598 case 0x08: /* Leon3 Instruction Cache config */
599 case 0x0C: /* Leon3 Date Cache config */
600 if (env
->def
.features
& CPU_FEATURE_CACHE_CTRL
) {
601 ret
= leon3_cache_control_ld(env
, addr
, size
);
604 case 0x01c00a00: /* MXCC control register */
606 ret
= env
->mxccregs
[3];
608 qemu_log_mask(LOG_UNIMP
,
609 "%08x: unimplemented access size: %d\n", addr
,
613 case 0x01c00a04: /* MXCC control register */
615 ret
= env
->mxccregs
[3];
617 qemu_log_mask(LOG_UNIMP
,
618 "%08x: unimplemented access size: %d\n", addr
,
622 case 0x01c00c00: /* Module reset register */
624 ret
= env
->mxccregs
[5];
625 /* should we do something here? */
627 qemu_log_mask(LOG_UNIMP
,
628 "%08x: unimplemented access size: %d\n", addr
,
632 case 0x01c00f00: /* MBus port address register */
634 ret
= env
->mxccregs
[7];
636 qemu_log_mask(LOG_UNIMP
,
637 "%08x: unimplemented access size: %d\n", addr
,
642 qemu_log_mask(LOG_UNIMP
,
643 "%08x: unimplemented address, size: %d\n", addr
,
647 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
648 "addr = %08x -> ret = %" PRIx64
","
649 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
654 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU probe */
655 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU probe */
659 mmulev
= (addr
>> 8) & 15;
663 ret
= mmu_probe(env
, addr
, mmulev
);
665 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
669 case ASI_M_MMUREGS
: /* SuperSparc MMU regs */
670 case ASI_LEON_MMUREGS
: /* LEON3 MMU regs */
672 int reg
= (addr
>> 8) & 0x1f;
674 ret
= env
->mmuregs
[reg
];
675 if (reg
== 3) { /* Fault status cleared on read */
677 } else if (reg
== 0x13) { /* Fault status read */
678 ret
= env
->mmuregs
[3];
679 } else if (reg
== 0x14) { /* Fault address read */
680 ret
= env
->mmuregs
[4];
682 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
685 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
686 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
687 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
689 case ASI_KERNELTXT
: /* Supervisor code access */
690 oi
= make_memop_idx(memop
, cpu_mmu_index(env_cpu(env
), true));
693 ret
= cpu_ldb_code_mmu(env
, addr
, oi
, GETPC());
696 ret
= cpu_ldw_code_mmu(env
, addr
, oi
, GETPC());
700 ret
= cpu_ldl_code_mmu(env
, addr
, oi
, GETPC());
703 ret
= cpu_ldq_code_mmu(env
, addr
, oi
, GETPC());
707 case ASI_M_TXTC_TAG
: /* SparcStation 5 I-cache tag */
708 case ASI_M_TXTC_DATA
: /* SparcStation 5 I-cache data */
709 case ASI_M_DATAC_TAG
: /* SparcStation 5 D-cache tag */
710 case ASI_M_DATAC_DATA
: /* SparcStation 5 D-cache data */
712 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
715 hwaddr access_addr
= (hwaddr
)addr
| ((hwaddr
)(asi
& 0xf) << 32);
719 ret
= address_space_ldub(cs
->as
, access_addr
,
720 MEMTXATTRS_UNSPECIFIED
, &result
);
723 ret
= address_space_lduw(cs
->as
, access_addr
,
724 MEMTXATTRS_UNSPECIFIED
, &result
);
728 ret
= address_space_ldl(cs
->as
, access_addr
,
729 MEMTXATTRS_UNSPECIFIED
, &result
);
732 ret
= address_space_ldq(cs
->as
, access_addr
,
733 MEMTXATTRS_UNSPECIFIED
, &result
);
737 if (result
!= MEMTX_OK
) {
738 sparc_raise_mmu_fault(cs
, access_addr
, false, false, false,
743 case 0x30: /* Turbosparc secondary cache diagnostic */
744 case 0x31: /* Turbosparc RAM snoop */
745 case 0x32: /* Turbosparc page table descriptor diagnostic */
746 case 0x39: /* data cache diagnostic register */
749 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
751 int reg
= (addr
>> 8) & 3;
754 case 0: /* Breakpoint Value (Addr) */
755 ret
= env
->mmubpregs
[reg
];
757 case 1: /* Breakpoint Mask */
758 ret
= env
->mmubpregs
[reg
];
760 case 2: /* Breakpoint Control */
761 ret
= env
->mmubpregs
[reg
];
763 case 3: /* Breakpoint Status */
764 ret
= env
->mmubpregs
[reg
];
765 env
->mmubpregs
[reg
] = 0ULL;
768 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
772 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
773 ret
= env
->mmubpctrv
;
775 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
776 ret
= env
->mmubpctrc
;
778 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
779 ret
= env
->mmubpctrs
;
781 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
782 ret
= env
->mmubpaction
;
784 case ASI_USERTXT
: /* User code access, XXX */
786 sparc_raise_mmu_fault(cs
, addr
, false, false, asi
, size
, GETPC());
790 case ASI_USERDATA
: /* User data access */
791 case ASI_KERNELDATA
: /* Supervisor data access */
792 case ASI_P
: /* Implicit primary context data access (v9 only?) */
793 case ASI_M_BYPASS
: /* MMU passthrough */
794 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
795 /* These are always handled inline. */
796 g_assert_not_reached();
814 dump_asi("read ", last_addr
, asi
, size
, ret
);
819 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
,
820 int asi
, uint32_t memop
)
822 int size
= 1 << (memop
& MO_SIZE
);
823 CPUState
*cs
= env_cpu(env
);
825 do_check_align(env
, addr
, size
- 1, GETPC());
827 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
828 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
830 case 0x00: /* Leon3 Cache Control */
831 case 0x08: /* Leon3 Instruction Cache config */
832 case 0x0C: /* Leon3 Date Cache config */
833 if (env
->def
.features
& CPU_FEATURE_CACHE_CTRL
) {
834 leon3_cache_control_st(env
, addr
, val
, size
);
838 case 0x01c00000: /* MXCC stream data register 0 */
840 env
->mxccdata
[0] = val
;
842 qemu_log_mask(LOG_UNIMP
,
843 "%08x: unimplemented access size: %d\n", addr
,
847 case 0x01c00008: /* MXCC stream data register 1 */
849 env
->mxccdata
[1] = val
;
851 qemu_log_mask(LOG_UNIMP
,
852 "%08x: unimplemented access size: %d\n", addr
,
856 case 0x01c00010: /* MXCC stream data register 2 */
858 env
->mxccdata
[2] = val
;
860 qemu_log_mask(LOG_UNIMP
,
861 "%08x: unimplemented access size: %d\n", addr
,
865 case 0x01c00018: /* MXCC stream data register 3 */
867 env
->mxccdata
[3] = val
;
869 qemu_log_mask(LOG_UNIMP
,
870 "%08x: unimplemented access size: %d\n", addr
,
874 case 0x01c00100: /* MXCC stream source */
879 env
->mxccregs
[0] = val
;
881 qemu_log_mask(LOG_UNIMP
,
882 "%08x: unimplemented access size: %d\n", addr
,
886 for (i
= 0; i
< 4; i
++) {
888 hwaddr access_addr
= (env
->mxccregs
[0] & 0xffffffffULL
) + 8 * i
;
890 env
->mxccdata
[i
] = address_space_ldq(cs
->as
,
892 MEMTXATTRS_UNSPECIFIED
,
894 if (result
!= MEMTX_OK
) {
895 /* TODO: investigate whether this is the right behaviour */
896 sparc_raise_mmu_fault(cs
, access_addr
, false, false,
897 false, size
, GETPC());
902 case 0x01c00200: /* MXCC stream destination */
907 env
->mxccregs
[1] = val
;
909 qemu_log_mask(LOG_UNIMP
,
910 "%08x: unimplemented access size: %d\n", addr
,
914 for (i
= 0; i
< 4; i
++) {
916 hwaddr access_addr
= (env
->mxccregs
[1] & 0xffffffffULL
) + 8 * i
;
918 address_space_stq(cs
->as
, access_addr
, env
->mxccdata
[i
],
919 MEMTXATTRS_UNSPECIFIED
, &result
);
921 if (result
!= MEMTX_OK
) {
922 /* TODO: investigate whether this is the right behaviour */
923 sparc_raise_mmu_fault(cs
, access_addr
, true, false,
924 false, size
, GETPC());
929 case 0x01c00a00: /* MXCC control register */
931 env
->mxccregs
[3] = val
;
933 qemu_log_mask(LOG_UNIMP
,
934 "%08x: unimplemented access size: %d\n", addr
,
938 case 0x01c00a04: /* MXCC control register */
940 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
943 qemu_log_mask(LOG_UNIMP
,
944 "%08x: unimplemented access size: %d\n", addr
,
948 case 0x01c00e00: /* MXCC error register */
949 /* writing a 1 bit clears the error */
951 env
->mxccregs
[6] &= ~val
;
953 qemu_log_mask(LOG_UNIMP
,
954 "%08x: unimplemented access size: %d\n", addr
,
958 case 0x01c00f00: /* MBus port address register */
960 env
->mxccregs
[7] = val
;
962 qemu_log_mask(LOG_UNIMP
,
963 "%08x: unimplemented access size: %d\n", addr
,
968 qemu_log_mask(LOG_UNIMP
,
969 "%08x: unimplemented address, size: %d\n", addr
,
973 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
974 asi
, size
, addr
, val
);
979 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU flush */
980 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU flush */
984 mmulev
= (addr
>> 8) & 15;
985 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
987 case 0: /* flush page */
988 tlb_flush_page(cs
, addr
& 0xfffff000);
990 case 1: /* flush segment (256k) */
991 case 2: /* flush region (16M) */
992 case 3: /* flush context (4G) */
993 case 4: /* flush entire */
1004 case ASI_M_MMUREGS
: /* write MMU regs */
1005 case ASI_LEON_MMUREGS
: /* LEON3 write MMU regs */
1007 int reg
= (addr
>> 8) & 0x1f;
1010 oldreg
= env
->mmuregs
[reg
];
1012 case 0: /* Control Register */
1013 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
1015 /* Mappings generated during no-fault mode
1016 are invalid in normal mode. */
1017 if ((oldreg
^ env
->mmuregs
[reg
])
1018 & (MMU_NF
| env
->def
.mmu_bm
)) {
1022 case 1: /* Context Table Pointer Register */
1023 env
->mmuregs
[reg
] = val
& env
->def
.mmu_ctpr_mask
;
1025 case 2: /* Context Register */
1026 env
->mmuregs
[reg
] = val
& env
->def
.mmu_cxr_mask
;
1027 if (oldreg
!= env
->mmuregs
[reg
]) {
1028 /* we flush when the MMU context changes because
1029 QEMU has no MMU context support */
1033 case 3: /* Synchronous Fault Status Register with Clear */
1034 case 4: /* Synchronous Fault Address Register */
1036 case 0x10: /* TLB Replacement Control Register */
1037 env
->mmuregs
[reg
] = val
& env
->def
.mmu_trcr_mask
;
1039 case 0x13: /* Synchronous Fault Status Register with Read
1041 env
->mmuregs
[3] = val
& env
->def
.mmu_sfsr_mask
;
1043 case 0x14: /* Synchronous Fault Address Register */
1044 env
->mmuregs
[4] = val
;
1047 env
->mmuregs
[reg
] = val
;
1050 if (oldreg
!= env
->mmuregs
[reg
]) {
1051 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1052 reg
, oldreg
, env
->mmuregs
[reg
]);
1059 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
1060 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
1061 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
1063 case ASI_M_TXTC_TAG
: /* I-cache tag */
1064 case ASI_M_TXTC_DATA
: /* I-cache data */
1065 case ASI_M_DATAC_TAG
: /* D-cache tag */
1066 case ASI_M_DATAC_DATA
: /* D-cache data */
1067 case ASI_M_FLUSH_PAGE
: /* I/D-cache flush page */
1068 case ASI_M_FLUSH_SEG
: /* I/D-cache flush segment */
1069 case ASI_M_FLUSH_REGION
: /* I/D-cache flush region */
1070 case ASI_M_FLUSH_CTX
: /* I/D-cache flush context */
1071 case ASI_M_FLUSH_USER
: /* I/D-cache flush user */
1073 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1076 hwaddr access_addr
= (hwaddr
)addr
| ((hwaddr
)(asi
& 0xf) << 32);
1080 address_space_stb(cs
->as
, access_addr
, val
,
1081 MEMTXATTRS_UNSPECIFIED
, &result
);
1084 address_space_stw(cs
->as
, access_addr
, val
,
1085 MEMTXATTRS_UNSPECIFIED
, &result
);
1089 address_space_stl(cs
->as
, access_addr
, val
,
1090 MEMTXATTRS_UNSPECIFIED
, &result
);
1093 address_space_stq(cs
->as
, access_addr
, val
,
1094 MEMTXATTRS_UNSPECIFIED
, &result
);
1097 if (result
!= MEMTX_OK
) {
1098 sparc_raise_mmu_fault(cs
, access_addr
, true, false, false,
1103 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1104 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1105 Turbosparc snoop RAM */
1106 case 0x32: /* store buffer control or Turbosparc page table
1107 descriptor diagnostic */
1108 case 0x36: /* I-cache flash clear */
1109 case 0x37: /* D-cache flash clear */
1111 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1113 int reg
= (addr
>> 8) & 3;
1116 case 0: /* Breakpoint Value (Addr) */
1117 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1119 case 1: /* Breakpoint Mask */
1120 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1122 case 2: /* Breakpoint Control */
1123 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1125 case 3: /* Breakpoint Status */
1126 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1129 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1133 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1134 env
->mmubpctrv
= val
& 0xffffffff;
1136 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1137 env
->mmubpctrc
= val
& 0x3;
1139 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1140 env
->mmubpctrs
= val
& 0x3;
1142 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1143 env
->mmubpaction
= val
& 0x1fff;
1145 case ASI_USERTXT
: /* User code access, XXX */
1146 case ASI_KERNELTXT
: /* Supervisor code access, XXX */
1148 sparc_raise_mmu_fault(cs
, addr
, true, false, asi
, size
, GETPC());
1151 case ASI_USERDATA
: /* User data access */
1152 case ASI_KERNELDATA
: /* Supervisor data access */
1154 case ASI_M_BYPASS
: /* MMU passthrough */
1155 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
1156 case ASI_M_BCOPY
: /* Block copy, sta access */
1157 case ASI_M_BFILL
: /* Block fill, stda access */
1158 /* These are always handled inline. */
1159 g_assert_not_reached();
1162 dump_asi("write", addr
, asi
, size
, val
);
1166 #endif /* CONFIG_USER_ONLY */
1167 #else /* TARGET_SPARC64 */
1169 #ifdef CONFIG_USER_ONLY
1170 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1171 int asi
, uint32_t memop
)
1173 int size
= 1 << (memop
& MO_SIZE
);
1174 int sign
= memop
& MO_SIGN
;
1178 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1180 do_check_align(env
, addr
, size
- 1, GETPC());
1181 addr
= asi_address_mask(env
, asi
, addr
);
1184 case ASI_PNF
: /* Primary no-fault */
1185 case ASI_PNFL
: /* Primary no-fault LE */
1186 case ASI_SNF
: /* Secondary no-fault */
1187 case ASI_SNFL
: /* Secondary no-fault LE */
1188 if (!page_check_range(addr
, size
, PAGE_READ
)) {
1194 ret
= cpu_ldub_data(env
, addr
);
1197 ret
= cpu_lduw_data(env
, addr
);
1200 ret
= cpu_ldl_data(env
, addr
);
1203 ret
= cpu_ldq_data(env
, addr
);
1206 g_assert_not_reached();
1211 case ASI_P
: /* Primary */
1212 case ASI_PL
: /* Primary LE */
1213 case ASI_S
: /* Secondary */
1214 case ASI_SL
: /* Secondary LE */
1215 /* These are always handled inline. */
1216 g_assert_not_reached();
1219 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1222 /* Convert from little endian */
1224 case ASI_PNFL
: /* Primary no-fault LE */
1225 case ASI_SNFL
: /* Secondary no-fault LE */
1239 /* Convert to signed number */
1246 ret
= (int16_t) ret
;
1249 ret
= (int32_t) ret
;
1254 dump_asi("read", addr
, asi
, size
, ret
);
1259 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1260 int asi
, uint32_t memop
)
1262 int size
= 1 << (memop
& MO_SIZE
);
1264 dump_asi("write", addr
, asi
, size
, val
);
1267 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1269 do_check_align(env
, addr
, size
- 1, GETPC());
1272 case ASI_P
: /* Primary */
1273 case ASI_PL
: /* Primary LE */
1274 case ASI_S
: /* Secondary */
1275 case ASI_SL
: /* Secondary LE */
1276 /* These are always handled inline. */
1277 g_assert_not_reached();
1279 case ASI_PNF
: /* Primary no-fault, RO */
1280 case ASI_SNF
: /* Secondary no-fault, RO */
1281 case ASI_PNFL
: /* Primary no-fault LE, RO */
1282 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1284 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1288 #else /* CONFIG_USER_ONLY */
1290 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1291 int asi
, uint32_t memop
)
1293 int size
= 1 << (memop
& MO_SIZE
);
1294 int sign
= memop
& MO_SIGN
;
1295 CPUState
*cs
= env_cpu(env
);
1297 #if defined(DEBUG_ASI)
1298 target_ulong last_addr
= addr
;
1303 do_check_asi(env
, asi
, GETPC());
1304 do_check_align(env
, addr
, size
- 1, GETPC());
1305 addr
= asi_address_mask(env
, asi
, addr
);
1314 int idx
= (env
->pstate
& PS_PRIV
1315 ? (asi
& 1 ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
)
1316 : (asi
& 1 ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
));
1318 if (cpu_get_phys_page_nofault(env
, addr
, idx
) == -1ULL) {
1320 dump_asi("read ", last_addr
, asi
, size
, ret
);
1322 /* exception_index is set in get_physical_address_data. */
1323 cpu_raise_exception_ra(env
, cs
->exception_index
, GETPC());
1325 oi
= make_memop_idx(memop
, idx
);
1328 ret
= cpu_ldb_mmu(env
, addr
, oi
, GETPC());
1331 ret
= cpu_ldw_mmu(env
, addr
, oi
, GETPC());
1334 ret
= cpu_ldl_mmu(env
, addr
, oi
, GETPC());
1337 ret
= cpu_ldq_mmu(env
, addr
, oi
, GETPC());
1340 g_assert_not_reached();
1345 case ASI_AIUP
: /* As if user primary */
1346 case ASI_AIUS
: /* As if user secondary */
1347 case ASI_AIUPL
: /* As if user primary LE */
1348 case ASI_AIUSL
: /* As if user secondary LE */
1349 case ASI_P
: /* Primary */
1350 case ASI_S
: /* Secondary */
1351 case ASI_PL
: /* Primary LE */
1352 case ASI_SL
: /* Secondary LE */
1353 case ASI_REAL
: /* Bypass */
1354 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1355 case ASI_REAL_L
: /* Bypass LE */
1356 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1357 case ASI_N
: /* Nucleus */
1358 case ASI_NL
: /* Nucleus Little Endian (LE) */
1359 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1360 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1361 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1362 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1363 case ASI_TWINX_REAL
: /* Real address, twinx */
1364 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1365 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1366 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1367 case ASI_TWINX_N
: /* Nucleus, twinx */
1368 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1369 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1370 case ASI_TWINX_P
: /* Primary, twinx */
1371 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1372 case ASI_TWINX_S
: /* Secondary, twinx */
1373 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1374 /* These are always handled inline. */
1375 g_assert_not_reached();
1377 case ASI_UPA_CONFIG
: /* UPA config */
1380 case ASI_LSU_CONTROL
: /* LSU */
1383 case ASI_IMMU
: /* I-MMU regs */
1385 int reg
= (addr
>> 3) & 0xf;
1388 /* 0x00 I-TSB Tag Target register */
1389 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1392 ret
= env
->immu
.sfsr
;
1394 case 5: /* TSB access */
1395 ret
= env
->immu
.tsb
;
1398 /* 0x30 I-TSB Tag Access register */
1399 ret
= env
->immu
.tag_access
;
1402 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1407 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer */
1409 /* env->immuregs[5] holds I-MMU TSB register value
1410 env->immuregs[6] holds I-MMU Tag Access register value */
1411 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 0);
1414 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer */
1416 /* env->immuregs[5] holds I-MMU TSB register value
1417 env->immuregs[6] holds I-MMU Tag Access register value */
1418 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 1);
1421 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1423 int reg
= (addr
>> 3) & 0x3f;
1425 ret
= env
->itlb
[reg
].tte
;
1428 case ASI_ITLB_TAG_READ
: /* I-MMU tag read */
1430 int reg
= (addr
>> 3) & 0x3f;
1432 ret
= env
->itlb
[reg
].tag
;
1435 case ASI_DMMU
: /* D-MMU regs */
1437 int reg
= (addr
>> 3) & 0xf;
1440 /* 0x00 D-TSB Tag Target register */
1441 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1443 case 1: /* 0x08 Primary Context */
1444 ret
= env
->dmmu
.mmu_primary_context
;
1446 case 2: /* 0x10 Secondary Context */
1447 ret
= env
->dmmu
.mmu_secondary_context
;
1450 ret
= env
->dmmu
.sfsr
;
1452 case 4: /* 0x20 SFAR */
1453 ret
= env
->dmmu
.sfar
;
1455 case 5: /* 0x28 TSB access */
1456 ret
= env
->dmmu
.tsb
;
1458 case 6: /* 0x30 D-TSB Tag Access register */
1459 ret
= env
->dmmu
.tag_access
;
1462 ret
= env
->dmmu
.virtual_watchpoint
;
1465 ret
= env
->dmmu
.physical_watchpoint
;
1468 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1473 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer */
1475 /* env->dmmuregs[5] holds D-MMU TSB register value
1476 env->dmmuregs[6] holds D-MMU Tag Access register value */
1477 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 0);
1480 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer */
1482 /* env->dmmuregs[5] holds D-MMU TSB register value
1483 env->dmmuregs[6] holds D-MMU Tag Access register value */
1484 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 1);
1487 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1489 int reg
= (addr
>> 3) & 0x3f;
1491 ret
= env
->dtlb
[reg
].tte
;
1494 case ASI_DTLB_TAG_READ
: /* D-MMU tag read */
1496 int reg
= (addr
>> 3) & 0x3f;
1498 ret
= env
->dtlb
[reg
].tag
;
1501 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1503 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1504 ret
= env
->ivec_status
;
1506 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1508 int reg
= (addr
>> 4) & 0x3;
1510 ret
= env
->ivec_data
[reg
];
1514 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1515 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1516 /* Hyperprivileged access only */
1517 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1520 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1522 unsigned int i
= (addr
>> 3) & 0x7;
1523 ret
= env
->scratch
[i
];
1526 case ASI_MMU
: /* UA2005 Context ID registers */
1527 switch ((addr
>> 3) & 0x3) {
1529 ret
= env
->dmmu
.mmu_primary_context
;
1532 ret
= env
->dmmu
.mmu_secondary_context
;
1535 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1538 case ASI_DCACHE_DATA
: /* D-cache data */
1539 case ASI_DCACHE_TAG
: /* D-cache tag access */
1540 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1541 case ASI_AFSR
: /* E-cache asynchronous fault status */
1542 case ASI_AFAR
: /* E-cache asynchronous fault address */
1543 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1544 case ASI_IC_INSTR
: /* I-cache instruction access */
1545 case ASI_IC_TAG
: /* I-cache tag access */
1546 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1547 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1548 case ASI_EC_W
: /* E-cache tag */
1549 case ASI_EC_R
: /* E-cache tag */
1551 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer */
1552 case ASI_ITLB_DATA_IN
: /* I-MMU data in, WO */
1553 case ASI_IMMU_DEMAP
: /* I-MMU demap, WO */
1554 case ASI_DTLB_DATA_IN
: /* D-MMU data in, WO */
1555 case ASI_DMMU_DEMAP
: /* D-MMU demap, WO */
1556 case ASI_INTR_W
: /* Interrupt vector, WO */
1558 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1563 /* Convert to signed number */
1570 ret
= (int16_t) ret
;
1573 ret
= (int32_t) ret
;
1580 dump_asi("read ", last_addr
, asi
, size
, ret
);
1585 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1586 int asi
, uint32_t memop
)
1588 int size
= 1 << (memop
& MO_SIZE
);
1589 CPUState
*cs
= env_cpu(env
);
1592 dump_asi("write", addr
, asi
, size
, val
);
1597 do_check_asi(env
, asi
, GETPC());
1598 do_check_align(env
, addr
, size
- 1, GETPC());
1599 addr
= asi_address_mask(env
, asi
, addr
);
1602 case ASI_AIUP
: /* As if user primary */
1603 case ASI_AIUS
: /* As if user secondary */
1604 case ASI_AIUPL
: /* As if user primary LE */
1605 case ASI_AIUSL
: /* As if user secondary LE */
1606 case ASI_P
: /* Primary */
1607 case ASI_S
: /* Secondary */
1608 case ASI_PL
: /* Primary LE */
1609 case ASI_SL
: /* Secondary LE */
1610 case ASI_REAL
: /* Bypass */
1611 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1612 case ASI_REAL_L
: /* Bypass LE */
1613 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1614 case ASI_N
: /* Nucleus */
1615 case ASI_NL
: /* Nucleus Little Endian (LE) */
1616 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1617 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1618 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1619 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1620 case ASI_TWINX_REAL
: /* Real address, twinx */
1621 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1622 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1623 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1624 case ASI_TWINX_N
: /* Nucleus, twinx */
1625 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1626 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1627 case ASI_TWINX_P
: /* Primary, twinx */
1628 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1629 case ASI_TWINX_S
: /* Secondary, twinx */
1630 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1631 /* These are always handled inline. */
1632 g_assert_not_reached();
1633 /* these ASIs have different functions on UltraSPARC-IIIi
1634 * and UA2005 CPUs. Use the explicit numbers to avoid confusion
1640 if (cpu_has_hypervisor(env
)) {
1642 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS0
1643 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS1
1644 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS0
1645 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS1
1647 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1648 env
->dmmu
.sun4v_tsb_pointers
[idx
] = val
;
1655 if (cpu_has_hypervisor(env
)) {
1657 * ASI_DMMU_CTX_ZERO_CONFIG
1658 * ASI_DMMU_CTX_NONZERO_CONFIG
1660 env
->dmmu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1669 if (cpu_has_hypervisor(env
)) {
1671 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS0
1672 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS1
1673 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS0
1674 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS1
1676 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1677 env
->immu
.sun4v_tsb_pointers
[idx
] = val
;
1684 if (cpu_has_hypervisor(env
)) {
1686 * ASI_IMMU_CTX_ZERO_CONFIG
1687 * ASI_IMMU_CTX_NONZERO_CONFIG
1689 env
->immu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1694 case ASI_UPA_CONFIG
: /* UPA config */
1697 case ASI_LSU_CONTROL
: /* LSU */
1698 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1700 case ASI_IMMU
: /* I-MMU regs */
1702 int reg
= (addr
>> 3) & 0xf;
1705 oldreg
= env
->immu
.mmuregs
[reg
];
1709 case 1: /* Not in I-MMU */
1713 if ((val
& 1) == 0) {
1714 val
= 0; /* Clear SFSR */
1716 env
->immu
.sfsr
= val
;
1720 case 5: /* TSB access */
1721 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1722 PRIx64
"\n", env
->immu
.tsb
, val
);
1723 env
->immu
.tsb
= val
;
1725 case 6: /* Tag access */
1726 env
->immu
.tag_access
= val
;
1732 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1736 if (oldreg
!= env
->immu
.mmuregs
[reg
]) {
1737 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1738 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1745 case ASI_ITLB_DATA_IN
: /* I-MMU data in */
1746 /* ignore real translation entries */
1747 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1748 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
,
1749 val
, "immu", env
, addr
);
1752 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1754 /* TODO: auto demap */
1756 unsigned int i
= (addr
>> 3) & 0x3f;
1758 /* ignore real translation entries */
1759 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1760 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
,
1761 sun4v_tte_to_sun4u(env
, addr
, val
), env
);
1764 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1769 case ASI_IMMU_DEMAP
: /* I-MMU demap */
1770 demap_tlb(env
->itlb
, addr
, "immu", env
);
1772 case ASI_DMMU
: /* D-MMU regs */
1774 int reg
= (addr
>> 3) & 0xf;
1777 oldreg
= env
->dmmu
.mmuregs
[reg
];
1783 if ((val
& 1) == 0) {
1784 val
= 0; /* Clear SFSR, Fault address */
1787 env
->dmmu
.sfsr
= val
;
1789 case 1: /* Primary context */
1790 env
->dmmu
.mmu_primary_context
= val
;
1791 /* can be optimized to only flush MMU_USER_IDX
1792 and MMU_KERNEL_IDX entries */
1795 case 2: /* Secondary context */
1796 env
->dmmu
.mmu_secondary_context
= val
;
1797 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1798 and MMU_KERNEL_SECONDARY_IDX entries */
1801 case 5: /* TSB access */
1802 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1803 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1804 env
->dmmu
.tsb
= val
;
1806 case 6: /* Tag access */
1807 env
->dmmu
.tag_access
= val
;
1809 case 7: /* Virtual Watchpoint */
1810 env
->dmmu
.virtual_watchpoint
= val
;
1812 case 8: /* Physical Watchpoint */
1813 env
->dmmu
.physical_watchpoint
= val
;
1816 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1820 if (oldreg
!= env
->dmmu
.mmuregs
[reg
]) {
1821 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1822 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1829 case ASI_DTLB_DATA_IN
: /* D-MMU data in */
1830 /* ignore real translation entries */
1831 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1832 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
,
1833 val
, "dmmu", env
, addr
);
1836 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1838 unsigned int i
= (addr
>> 3) & 0x3f;
1840 /* ignore real translation entries */
1841 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1842 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
,
1843 sun4v_tte_to_sun4u(env
, addr
, val
), env
);
1846 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1851 case ASI_DMMU_DEMAP
: /* D-MMU demap */
1852 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1854 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1855 env
->ivec_status
= val
& 0x20;
1857 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1858 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1859 /* Hyperprivileged access only */
1860 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1863 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1865 unsigned int i
= (addr
>> 3) & 0x7;
1866 env
->scratch
[i
] = val
;
1869 case ASI_MMU
: /* UA2005 Context ID registers */
1871 switch ((addr
>> 3) & 0x3) {
1873 env
->dmmu
.mmu_primary_context
= val
;
1874 env
->immu
.mmu_primary_context
= val
;
1875 tlb_flush_by_mmuidx(cs
,
1876 (1 << MMU_USER_IDX
) | (1 << MMU_KERNEL_IDX
));
1879 env
->dmmu
.mmu_secondary_context
= val
;
1880 env
->immu
.mmu_secondary_context
= val
;
1881 tlb_flush_by_mmuidx(cs
,
1882 (1 << MMU_USER_SECONDARY_IDX
) |
1883 (1 << MMU_KERNEL_SECONDARY_IDX
));
1886 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1890 case ASI_QUEUE
: /* UA2005 CPU mondo queue */
1891 case ASI_DCACHE_DATA
: /* D-cache data */
1892 case ASI_DCACHE_TAG
: /* D-cache tag access */
1893 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1894 case ASI_AFSR
: /* E-cache asynchronous fault status */
1895 case ASI_AFAR
: /* E-cache asynchronous fault address */
1896 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1897 case ASI_IC_INSTR
: /* I-cache instruction access */
1898 case ASI_IC_TAG
: /* I-cache tag access */
1899 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1900 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1901 case ASI_EC_W
: /* E-cache tag */
1902 case ASI_EC_R
: /* E-cache tag */
1904 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer, RO */
1905 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer, RO */
1906 case ASI_ITLB_TAG_READ
: /* I-MMU tag read, RO */
1907 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer, RO */
1908 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer, RO */
1909 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer, RO */
1910 case ASI_DTLB_TAG_READ
: /* D-MMU tag read, RO */
1911 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1912 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1913 case ASI_PNF
: /* Primary no-fault, RO */
1914 case ASI_SNF
: /* Secondary no-fault, RO */
1915 case ASI_PNFL
: /* Primary no-fault LE, RO */
1916 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1918 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1921 cpu_raise_exception_ra(env
, TT_ILL_INSN
, GETPC());
1924 #endif /* CONFIG_USER_ONLY */
1925 #endif /* TARGET_SPARC64 */
1927 #if !defined(CONFIG_USER_ONLY)
1929 void sparc_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
,
1930 vaddr addr
, unsigned size
,
1931 MMUAccessType access_type
,
1932 int mmu_idx
, MemTxAttrs attrs
,
1933 MemTxResult response
, uintptr_t retaddr
)
1935 bool is_write
= access_type
== MMU_DATA_STORE
;
1936 bool is_exec
= access_type
== MMU_INST_FETCH
;
1937 bool is_asi
= false;
1939 sparc_raise_mmu_fault(cs
, physaddr
, is_write
, is_exec
,
1940 is_asi
, size
, retaddr
);