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/page-protection.h"
27 #include "exec/cpu_ldst.h"
32 //#define DEBUG_UNASSIGNED
34 //#define DEBUG_CACHE_CONTROL
37 #define DPRINTF_MMU(fmt, ...) \
38 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
40 #define DPRINTF_MMU(fmt, ...) do {} while (0)
44 #define DPRINTF_MXCC(fmt, ...) \
45 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
47 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
51 #define DPRINTF_ASI(fmt, ...) \
52 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
55 #ifdef DEBUG_CACHE_CONTROL
56 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
57 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
59 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
64 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
66 #define AM_CHECK(env1) (1)
70 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
71 /* Calculates TSB pointer value for fault page size
72 * UltraSPARC IIi has fixed sizes (8k or 64k) for the page pointers
73 * UA2005 holds the page size configuration in mmu_ctx registers */
74 static uint64_t ultrasparc_tsb_pointer(CPUSPARCState
*env
,
75 const SparcV9MMU
*mmu
, const int idx
)
77 uint64_t tsb_register
;
79 if (cpu_has_hypervisor(env
)) {
81 int ctx
= mmu
->tag_access
& 0x1fffULL
;
82 uint64_t ctx_register
= mmu
->sun4v_ctx_config
[ctx
? 1 : 0];
84 tsb_index
|= ctx
? 2 : 0;
85 page_size
= idx
? ctx_register
>> 8 : ctx_register
;
87 tsb_register
= mmu
->sun4v_tsb_pointers
[tsb_index
];
90 tsb_register
= mmu
->tsb
;
92 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
93 int tsb_size
= tsb_register
& 0xf;
95 uint64_t tsb_base_mask
= (~0x1fffULL
) << tsb_size
;
97 /* move va bits to correct position,
98 * the context bits will be masked out later */
99 uint64_t va
= mmu
->tag_access
>> (3 * page_size
+ 9);
101 /* calculate tsb_base mask and adjust va if split is in use */
104 va
&= ~(1ULL << (13 + tsb_size
));
106 va
|= (1ULL << (13 + tsb_size
));
111 return ((tsb_register
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
114 /* Calculates tag target register value by reordering bits
115 in tag access register */
116 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
118 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
121 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
122 uint64_t tlb_tag
, uint64_t tlb_tte
,
125 target_ulong mask
, size
, va
, offset
;
127 /* flush page range if translation is valid */
128 if (TTE_IS_VALID(tlb
->tte
)) {
129 CPUState
*cs
= env_cpu(env
);
131 size
= 8192ULL << 3 * TTE_PGSIZE(tlb
->tte
);
134 va
= tlb
->tag
& mask
;
136 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
137 tlb_flush_page(cs
, va
+ offset
);
145 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
146 const char *strmmu
, CPUSPARCState
*env1
)
152 int is_demap_context
= (demap_addr
>> 6) & 1;
155 switch ((demap_addr
>> 4) & 3) {
156 case 0: /* primary */
157 context
= env1
->dmmu
.mmu_primary_context
;
159 case 1: /* secondary */
160 context
= env1
->dmmu
.mmu_secondary_context
;
162 case 2: /* nucleus */
165 case 3: /* reserved */
170 for (i
= 0; i
< 64; i
++) {
171 if (TTE_IS_VALID(tlb
[i
].tte
)) {
173 if (is_demap_context
) {
174 /* will remove non-global entries matching context value */
175 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
176 !tlb_compare_context(&tlb
[i
], context
)) {
181 will remove any entry matching VA */
182 mask
= 0xffffffffffffe000ULL
;
183 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
185 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
189 /* entry should be global or matching context value */
190 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
191 !tlb_compare_context(&tlb
[i
], context
)) {
196 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
198 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
205 static uint64_t sun4v_tte_to_sun4u(CPUSPARCState
*env
, uint64_t tag
,
209 if (!(cpu_has_hypervisor(env
) && (tag
& TLB_UST1_IS_SUN4V_BIT
))) {
210 /* is already in the sun4u format */
213 sun4u_tte
= TTE_PA(sun4v_tte
) | (sun4v_tte
& TTE_VALID_BIT
);
214 sun4u_tte
|= (sun4v_tte
& 3ULL) << 61; /* TTE_PGSIZE */
215 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_NFO_BIT_UA2005
, TTE_NFO_BIT
);
216 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_USED_BIT_UA2005
, TTE_USED_BIT
);
217 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_W_OK_BIT_UA2005
, TTE_W_OK_BIT
);
218 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_SIDEEFFECT_BIT_UA2005
,
220 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_PRIV_BIT_UA2005
, TTE_PRIV_BIT
);
221 sun4u_tte
|= CONVERT_BIT(sun4v_tte
, TTE_LOCKED_BIT_UA2005
, TTE_LOCKED_BIT
);
225 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
226 uint64_t tlb_tag
, uint64_t tlb_tte
,
227 const char *strmmu
, CPUSPARCState
*env1
,
230 unsigned int i
, replace_used
;
232 tlb_tte
= sun4v_tte_to_sun4u(env1
, addr
, tlb_tte
);
233 if (cpu_has_hypervisor(env1
)) {
234 uint64_t new_vaddr
= tlb_tag
& ~0x1fffULL
;
235 uint64_t new_size
= 8192ULL << 3 * TTE_PGSIZE(tlb_tte
);
236 uint32_t new_ctx
= tlb_tag
& 0x1fffU
;
237 for (i
= 0; i
< 64; i
++) {
238 uint32_t ctx
= tlb
[i
].tag
& 0x1fffU
;
239 /* check if new mapping overlaps an existing one */
240 if (new_ctx
== ctx
) {
241 uint64_t vaddr
= tlb
[i
].tag
& ~0x1fffULL
;
242 uint64_t size
= 8192ULL << 3 * TTE_PGSIZE(tlb
[i
].tte
);
243 if (new_vaddr
== vaddr
244 || (new_vaddr
< vaddr
+ size
245 && vaddr
< new_vaddr
+ new_size
)) {
246 DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i
, vaddr
,
248 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
255 /* Try replacing invalid entry */
256 for (i
= 0; i
< 64; i
++) {
257 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
258 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
260 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
267 /* All entries are valid, try replacing unlocked entry */
269 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
271 /* Used entries are not replaced on first pass */
273 for (i
= 0; i
< 64; i
++) {
274 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
276 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
278 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
279 strmmu
, (replace_used
? "used" : "unused"), i
);
286 /* Now reset used bit and search for unused entries again */
288 for (i
= 0; i
< 64; i
++) {
289 TTE_SET_UNUSED(tlb
[i
].tte
);
294 DPRINTF_MMU("%s lru replacement: no free entries available, "
295 "replacing the last one\n", strmmu
);
297 /* corner case: the last entry is replaced anyway */
298 replace_tlb_entry(&tlb
[63], tlb_tag
, tlb_tte
, env1
);
303 #ifdef TARGET_SPARC64
304 /* returns true if access using this ASI is to have address translated by MMU
305 otherwise access is to raw physical address */
306 /* TODO: check sparc32 bits */
307 static inline int is_translating_asi(int asi
)
309 /* Ultrasparc IIi translating asi
310 - note this list is defined by cpu implementation
327 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
329 if (AM_CHECK(env1
)) {
330 addr
&= 0xffffffffULL
;
335 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
336 int asi
, target_ulong addr
)
338 if (is_translating_asi(asi
)) {
339 addr
= address_mask(env
, addr
);
344 #ifndef CONFIG_USER_ONLY
345 static inline void do_check_asi(CPUSPARCState
*env
, int asi
, uintptr_t ra
)
347 /* ASIs >= 0x80 are user mode.
348 * ASIs >= 0x30 are hyper mode (or super if hyper is not available).
349 * ASIs <= 0x2f are super mode.
352 && !cpu_hypervisor_mode(env
)
353 && (!cpu_supervisor_mode(env
)
354 || (asi
>= 0x30 && cpu_has_hypervisor(env
)))) {
355 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, ra
);
358 #endif /* !CONFIG_USER_ONLY */
361 #if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
362 static void do_check_align(CPUSPARCState
*env
, target_ulong addr
,
363 uint32_t align
, uintptr_t ra
)
366 cpu_raise_exception_ra(env
, TT_UNALIGNED
, ra
);
371 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
373 static void dump_mxcc(CPUSPARCState
*env
)
375 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
377 env
->mxccdata
[0], env
->mxccdata
[1],
378 env
->mxccdata
[2], env
->mxccdata
[3]);
379 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
381 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
383 env
->mxccregs
[0], env
->mxccregs
[1],
384 env
->mxccregs
[2], env
->mxccregs
[3],
385 env
->mxccregs
[4], env
->mxccregs
[5],
386 env
->mxccregs
[6], env
->mxccregs
[7]);
390 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
391 && defined(DEBUG_ASI)
392 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
397 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
398 addr
, asi
, r1
& 0xff);
401 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
402 addr
, asi
, r1
& 0xffff);
405 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
406 addr
, asi
, r1
& 0xffffffff);
409 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
416 #ifndef CONFIG_USER_ONLY
417 #ifndef TARGET_SPARC64
418 static void sparc_raise_mmu_fault(CPUState
*cs
, hwaddr addr
,
419 bool is_write
, bool is_exec
, int is_asi
,
420 unsigned size
, uintptr_t retaddr
)
422 CPUSPARCState
*env
= cpu_env(cs
);
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 CPUSPARCState
*env
= cpu_env(cs
);
485 #ifdef DEBUG_UNASSIGNED
486 printf("Unassigned mem access to " HWADDR_FMT_plx
" from " TARGET_FMT_lx
487 "\n", addr
, env
->pc
);
490 if (is_exec
) { /* XXX has_hypervisor */
491 if (env
->lsu
& (IMMU_E
)) {
492 cpu_raise_exception_ra(env
, TT_CODE_ACCESS
, retaddr
);
493 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
494 cpu_raise_exception_ra(env
, TT_INSN_REAL_TRANSLATION_MISS
, retaddr
);
497 if (env
->lsu
& (DMMU_E
)) {
498 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, retaddr
);
499 } else if (cpu_has_hypervisor(env
) && !(env
->hpstate
& HS_PRIV
)) {
500 cpu_raise_exception_ra(env
, TT_DATA_REAL_TRANSLATION_MISS
, retaddr
);
507 #ifndef TARGET_SPARC64
508 #ifndef CONFIG_USER_ONLY
511 /* Leon3 cache control */
513 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
514 uint64_t val
, int size
)
516 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
520 DPRINTF_CACHE_CONTROL("32bits only\n");
525 case 0x00: /* Cache control */
527 /* These values must always be read as zeros */
528 val
&= ~CACHE_CTRL_FD
;
529 val
&= ~CACHE_CTRL_FI
;
530 val
&= ~CACHE_CTRL_IB
;
531 val
&= ~CACHE_CTRL_IP
;
532 val
&= ~CACHE_CTRL_DP
;
534 env
->cache_control
= val
;
536 case 0x04: /* Instruction cache configuration */
537 case 0x08: /* Data cache configuration */
541 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
546 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
552 DPRINTF_CACHE_CONTROL("32bits only\n");
557 case 0x00: /* Cache control */
558 ret
= env
->cache_control
;
561 /* Configuration registers are read and only always keep those
564 case 0x04: /* Instruction cache configuration */
567 case 0x08: /* Data cache configuration */
571 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
574 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
579 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
580 int asi
, uint32_t memop
)
582 int size
= 1 << (memop
& MO_SIZE
);
583 int sign
= memop
& MO_SIGN
;
584 CPUState
*cs
= env_cpu(env
);
586 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
587 uint32_t last_addr
= addr
;
590 do_check_align(env
, addr
, size
- 1, GETPC());
592 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
593 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
595 case 0x00: /* Leon3 Cache Control */
596 case 0x08: /* Leon3 Instruction Cache config */
597 case 0x0C: /* Leon3 Date Cache config */
598 if (env
->def
.features
& CPU_FEATURE_CACHE_CTRL
) {
599 ret
= leon3_cache_control_ld(env
, addr
, size
);
602 case 0x01c00a00: /* MXCC control register */
604 ret
= env
->mxccregs
[3];
606 qemu_log_mask(LOG_UNIMP
,
607 "%08x: unimplemented access size: %d\n", addr
,
611 case 0x01c00a04: /* MXCC control register */
613 ret
= env
->mxccregs
[3];
615 qemu_log_mask(LOG_UNIMP
,
616 "%08x: unimplemented access size: %d\n", addr
,
620 case 0x01c00c00: /* Module reset register */
622 ret
= env
->mxccregs
[5];
623 /* should we do something here? */
625 qemu_log_mask(LOG_UNIMP
,
626 "%08x: unimplemented access size: %d\n", addr
,
630 case 0x01c00f00: /* MBus port address register */
632 ret
= env
->mxccregs
[7];
634 qemu_log_mask(LOG_UNIMP
,
635 "%08x: unimplemented access size: %d\n", addr
,
640 qemu_log_mask(LOG_UNIMP
,
641 "%08x: unimplemented address, size: %d\n", addr
,
645 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
646 "addr = %08x -> ret = %" PRIx64
","
647 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
652 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU probe */
653 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU probe */
657 mmulev
= (addr
>> 8) & 15;
661 ret
= mmu_probe(env
, addr
, mmulev
);
663 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
667 case ASI_M_MMUREGS
: /* SuperSparc MMU regs */
668 case ASI_LEON_MMUREGS
: /* LEON3 MMU regs */
670 int reg
= (addr
>> 8) & 0x1f;
672 ret
= env
->mmuregs
[reg
];
673 if (reg
== 3) { /* Fault status cleared on read */
675 } else if (reg
== 0x13) { /* Fault status read */
676 ret
= env
->mmuregs
[3];
677 } else if (reg
== 0x14) { /* Fault address read */
678 ret
= env
->mmuregs
[4];
680 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
683 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
684 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
685 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
687 case ASI_M_TXTC_TAG
: /* SparcStation 5 I-cache tag */
688 case ASI_M_TXTC_DATA
: /* SparcStation 5 I-cache data */
689 case ASI_M_DATAC_TAG
: /* SparcStation 5 D-cache tag */
690 case ASI_M_DATAC_DATA
: /* SparcStation 5 D-cache data */
692 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
695 hwaddr access_addr
= (hwaddr
)addr
| ((hwaddr
)(asi
& 0xf) << 32);
699 ret
= address_space_ldub(cs
->as
, access_addr
,
700 MEMTXATTRS_UNSPECIFIED
, &result
);
703 ret
= address_space_lduw(cs
->as
, access_addr
,
704 MEMTXATTRS_UNSPECIFIED
, &result
);
708 ret
= address_space_ldl(cs
->as
, access_addr
,
709 MEMTXATTRS_UNSPECIFIED
, &result
);
712 ret
= address_space_ldq(cs
->as
, access_addr
,
713 MEMTXATTRS_UNSPECIFIED
, &result
);
717 if (result
!= MEMTX_OK
) {
718 sparc_raise_mmu_fault(cs
, access_addr
, false, false, false,
723 case 0x30: /* Turbosparc secondary cache diagnostic */
724 case 0x31: /* Turbosparc RAM snoop */
725 case 0x32: /* Turbosparc page table descriptor diagnostic */
726 case 0x39: /* data cache diagnostic register */
729 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
731 int reg
= (addr
>> 8) & 3;
734 case 0: /* Breakpoint Value (Addr) */
735 ret
= env
->mmubpregs
[reg
];
737 case 1: /* Breakpoint Mask */
738 ret
= env
->mmubpregs
[reg
];
740 case 2: /* Breakpoint Control */
741 ret
= env
->mmubpregs
[reg
];
743 case 3: /* Breakpoint Status */
744 ret
= env
->mmubpregs
[reg
];
745 env
->mmubpregs
[reg
] = 0ULL;
748 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
752 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
753 ret
= env
->mmubpctrv
;
755 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
756 ret
= env
->mmubpctrc
;
758 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
759 ret
= env
->mmubpctrs
;
761 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
762 ret
= env
->mmubpaction
;
765 sparc_raise_mmu_fault(cs
, addr
, false, false, asi
, size
, GETPC());
769 case ASI_USERDATA
: /* User data access */
770 case ASI_KERNELDATA
: /* Supervisor data access */
771 case ASI_USERTXT
: /* User code access */
772 case ASI_KERNELTXT
: /* Supervisor code access */
773 case ASI_P
: /* Implicit primary context data access (v9 only?) */
774 case ASI_M_BYPASS
: /* MMU passthrough */
775 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
776 /* These are always handled inline. */
777 g_assert_not_reached();
795 dump_asi("read ", last_addr
, asi
, size
, ret
);
800 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
,
801 int asi
, uint32_t memop
)
803 int size
= 1 << (memop
& MO_SIZE
);
804 CPUState
*cs
= env_cpu(env
);
806 do_check_align(env
, addr
, size
- 1, GETPC());
808 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
809 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
811 case 0x00: /* Leon3 Cache Control */
812 case 0x08: /* Leon3 Instruction Cache config */
813 case 0x0C: /* Leon3 Date Cache config */
814 if (env
->def
.features
& CPU_FEATURE_CACHE_CTRL
) {
815 leon3_cache_control_st(env
, addr
, val
, size
);
819 case 0x01c00000: /* MXCC stream data register 0 */
821 env
->mxccdata
[0] = val
;
823 qemu_log_mask(LOG_UNIMP
,
824 "%08x: unimplemented access size: %d\n", addr
,
828 case 0x01c00008: /* MXCC stream data register 1 */
830 env
->mxccdata
[1] = val
;
832 qemu_log_mask(LOG_UNIMP
,
833 "%08x: unimplemented access size: %d\n", addr
,
837 case 0x01c00010: /* MXCC stream data register 2 */
839 env
->mxccdata
[2] = val
;
841 qemu_log_mask(LOG_UNIMP
,
842 "%08x: unimplemented access size: %d\n", addr
,
846 case 0x01c00018: /* MXCC stream data register 3 */
848 env
->mxccdata
[3] = val
;
850 qemu_log_mask(LOG_UNIMP
,
851 "%08x: unimplemented access size: %d\n", addr
,
855 case 0x01c00100: /* MXCC stream source */
860 env
->mxccregs
[0] = val
;
862 qemu_log_mask(LOG_UNIMP
,
863 "%08x: unimplemented access size: %d\n", addr
,
867 for (i
= 0; i
< 4; i
++) {
869 hwaddr access_addr
= (env
->mxccregs
[0] & 0xffffffffULL
) + 8 * i
;
871 env
->mxccdata
[i
] = address_space_ldq(cs
->as
,
873 MEMTXATTRS_UNSPECIFIED
,
875 if (result
!= MEMTX_OK
) {
876 /* TODO: investigate whether this is the right behaviour */
877 sparc_raise_mmu_fault(cs
, access_addr
, false, false,
878 false, size
, GETPC());
883 case 0x01c00200: /* MXCC stream destination */
888 env
->mxccregs
[1] = val
;
890 qemu_log_mask(LOG_UNIMP
,
891 "%08x: unimplemented access size: %d\n", addr
,
895 for (i
= 0; i
< 4; i
++) {
897 hwaddr access_addr
= (env
->mxccregs
[1] & 0xffffffffULL
) + 8 * i
;
899 address_space_stq(cs
->as
, access_addr
, env
->mxccdata
[i
],
900 MEMTXATTRS_UNSPECIFIED
, &result
);
902 if (result
!= MEMTX_OK
) {
903 /* TODO: investigate whether this is the right behaviour */
904 sparc_raise_mmu_fault(cs
, access_addr
, true, false,
905 false, size
, GETPC());
910 case 0x01c00a00: /* MXCC control register */
912 env
->mxccregs
[3] = val
;
914 qemu_log_mask(LOG_UNIMP
,
915 "%08x: unimplemented access size: %d\n", addr
,
919 case 0x01c00a04: /* MXCC control register */
921 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
924 qemu_log_mask(LOG_UNIMP
,
925 "%08x: unimplemented access size: %d\n", addr
,
929 case 0x01c00e00: /* MXCC error register */
930 /* writing a 1 bit clears the error */
932 env
->mxccregs
[6] &= ~val
;
934 qemu_log_mask(LOG_UNIMP
,
935 "%08x: unimplemented access size: %d\n", addr
,
939 case 0x01c00f00: /* MBus port address register */
941 env
->mxccregs
[7] = val
;
943 qemu_log_mask(LOG_UNIMP
,
944 "%08x: unimplemented access size: %d\n", addr
,
949 qemu_log_mask(LOG_UNIMP
,
950 "%08x: unimplemented address, size: %d\n", addr
,
954 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
955 asi
, size
, addr
, val
);
960 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU flush */
961 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU flush */
965 mmulev
= (addr
>> 8) & 15;
966 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
968 case 0: /* flush page */
969 tlb_flush_page(cs
, addr
& 0xfffff000);
971 case 1: /* flush segment (256k) */
972 case 2: /* flush region (16M) */
973 case 3: /* flush context (4G) */
974 case 4: /* flush entire */
985 case ASI_M_MMUREGS
: /* write MMU regs */
986 case ASI_LEON_MMUREGS
: /* LEON3 write MMU regs */
988 int reg
= (addr
>> 8) & 0x1f;
991 oldreg
= env
->mmuregs
[reg
];
993 case 0: /* Control Register */
994 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
996 /* Mappings generated during no-fault mode
997 are invalid in normal mode. */
998 if ((oldreg
^ env
->mmuregs
[reg
])
999 & (MMU_NF
| env
->def
.mmu_bm
)) {
1003 case 1: /* Context Table Pointer Register */
1004 env
->mmuregs
[reg
] = val
& env
->def
.mmu_ctpr_mask
;
1006 case 2: /* Context Register */
1007 env
->mmuregs
[reg
] = val
& env
->def
.mmu_cxr_mask
;
1008 if (oldreg
!= env
->mmuregs
[reg
]) {
1009 /* we flush when the MMU context changes because
1010 QEMU has no MMU context support */
1014 case 3: /* Synchronous Fault Status Register with Clear */
1015 case 4: /* Synchronous Fault Address Register */
1017 case 0x10: /* TLB Replacement Control Register */
1018 env
->mmuregs
[reg
] = val
& env
->def
.mmu_trcr_mask
;
1020 case 0x13: /* Synchronous Fault Status Register with Read
1022 env
->mmuregs
[3] = val
& env
->def
.mmu_sfsr_mask
;
1024 case 0x14: /* Synchronous Fault Address Register */
1025 env
->mmuregs
[4] = val
;
1028 env
->mmuregs
[reg
] = val
;
1031 if (oldreg
!= env
->mmuregs
[reg
]) {
1032 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1033 reg
, oldreg
, env
->mmuregs
[reg
]);
1040 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
1041 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
1042 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
1044 case ASI_M_TXTC_TAG
: /* I-cache tag */
1045 case ASI_M_TXTC_DATA
: /* I-cache data */
1046 case ASI_M_DATAC_TAG
: /* D-cache tag */
1047 case ASI_M_DATAC_DATA
: /* D-cache data */
1048 case ASI_M_FLUSH_PAGE
: /* I/D-cache flush page */
1049 case ASI_M_FLUSH_SEG
: /* I/D-cache flush segment */
1050 case ASI_M_FLUSH_REGION
: /* I/D-cache flush region */
1051 case ASI_M_FLUSH_CTX
: /* I/D-cache flush context */
1052 case ASI_M_FLUSH_USER
: /* I/D-cache flush user */
1054 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1057 hwaddr access_addr
= (hwaddr
)addr
| ((hwaddr
)(asi
& 0xf) << 32);
1061 address_space_stb(cs
->as
, access_addr
, val
,
1062 MEMTXATTRS_UNSPECIFIED
, &result
);
1065 address_space_stw(cs
->as
, access_addr
, val
,
1066 MEMTXATTRS_UNSPECIFIED
, &result
);
1070 address_space_stl(cs
->as
, access_addr
, val
,
1071 MEMTXATTRS_UNSPECIFIED
, &result
);
1074 address_space_stq(cs
->as
, access_addr
, val
,
1075 MEMTXATTRS_UNSPECIFIED
, &result
);
1078 if (result
!= MEMTX_OK
) {
1079 sparc_raise_mmu_fault(cs
, access_addr
, true, false, false,
1084 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1085 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1086 Turbosparc snoop RAM */
1087 case 0x32: /* store buffer control or Turbosparc page table
1088 descriptor diagnostic */
1089 case 0x36: /* I-cache flash clear */
1090 case 0x37: /* D-cache flash clear */
1092 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1094 int reg
= (addr
>> 8) & 3;
1097 case 0: /* Breakpoint Value (Addr) */
1098 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1100 case 1: /* Breakpoint Mask */
1101 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1103 case 2: /* Breakpoint Control */
1104 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1106 case 3: /* Breakpoint Status */
1107 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1110 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1114 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1115 env
->mmubpctrv
= val
& 0xffffffff;
1117 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1118 env
->mmubpctrc
= val
& 0x3;
1120 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1121 env
->mmubpctrs
= val
& 0x3;
1123 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1124 env
->mmubpaction
= val
& 0x1fff;
1126 case ASI_USERTXT
: /* User code access, XXX */
1127 case ASI_KERNELTXT
: /* Supervisor code access, XXX */
1129 sparc_raise_mmu_fault(cs
, addr
, true, false, asi
, size
, GETPC());
1132 case ASI_USERDATA
: /* User data access */
1133 case ASI_KERNELDATA
: /* Supervisor data access */
1135 case ASI_M_BYPASS
: /* MMU passthrough */
1136 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
1137 case ASI_M_BCOPY
: /* Block copy, sta access */
1138 case ASI_M_BFILL
: /* Block fill, stda access */
1139 /* These are always handled inline. */
1140 g_assert_not_reached();
1143 dump_asi("write", addr
, asi
, size
, val
);
1147 uint64_t helper_ld_code(CPUSPARCState
*env
, target_ulong addr
, uint32_t oi
)
1149 MemOp mop
= get_memop(oi
);
1150 uintptr_t ra
= GETPC();
1153 switch (mop
& MO_SIZE
) {
1155 ret
= cpu_ldb_code_mmu(env
, addr
, oi
, ra
);
1156 if (mop
& MO_SIGN
) {
1161 ret
= cpu_ldw_code_mmu(env
, addr
, oi
, ra
);
1162 if ((mop
& MO_BSWAP
) != MO_TE
) {
1165 if (mop
& MO_SIGN
) {
1170 ret
= cpu_ldl_code_mmu(env
, addr
, oi
, ra
);
1171 if ((mop
& MO_BSWAP
) != MO_TE
) {
1174 if (mop
& MO_SIGN
) {
1179 ret
= cpu_ldq_code_mmu(env
, addr
, oi
, ra
);
1180 if ((mop
& MO_BSWAP
) != MO_TE
) {
1185 g_assert_not_reached();
1190 #endif /* CONFIG_USER_ONLY */
1191 #else /* TARGET_SPARC64 */
1193 #ifdef CONFIG_USER_ONLY
1194 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1195 int asi
, uint32_t memop
)
1197 int size
= 1 << (memop
& MO_SIZE
);
1198 int sign
= memop
& MO_SIGN
;
1202 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1204 do_check_align(env
, addr
, size
- 1, GETPC());
1205 addr
= asi_address_mask(env
, asi
, addr
);
1208 case ASI_PNF
: /* Primary no-fault */
1209 case ASI_PNFL
: /* Primary no-fault LE */
1210 case ASI_SNF
: /* Secondary no-fault */
1211 case ASI_SNFL
: /* Secondary no-fault LE */
1212 if (!page_check_range(addr
, size
, PAGE_READ
)) {
1218 ret
= cpu_ldub_data(env
, addr
);
1221 ret
= cpu_lduw_data(env
, addr
);
1224 ret
= cpu_ldl_data(env
, addr
);
1227 ret
= cpu_ldq_data(env
, addr
);
1230 g_assert_not_reached();
1235 case ASI_P
: /* Primary */
1236 case ASI_PL
: /* Primary LE */
1237 case ASI_S
: /* Secondary */
1238 case ASI_SL
: /* Secondary LE */
1239 /* These are always handled inline. */
1240 g_assert_not_reached();
1243 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1246 /* Convert from little endian */
1248 case ASI_PNFL
: /* Primary no-fault LE */
1249 case ASI_SNFL
: /* Secondary no-fault LE */
1263 /* Convert to signed number */
1270 ret
= (int16_t) ret
;
1273 ret
= (int32_t) ret
;
1278 dump_asi("read", addr
, asi
, size
, ret
);
1283 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1284 int asi
, uint32_t memop
)
1286 int size
= 1 << (memop
& MO_SIZE
);
1288 dump_asi("write", addr
, asi
, size
, val
);
1291 cpu_raise_exception_ra(env
, TT_PRIV_ACT
, GETPC());
1293 do_check_align(env
, addr
, size
- 1, GETPC());
1296 case ASI_P
: /* Primary */
1297 case ASI_PL
: /* Primary LE */
1298 case ASI_S
: /* Secondary */
1299 case ASI_SL
: /* Secondary LE */
1300 /* These are always handled inline. */
1301 g_assert_not_reached();
1303 case ASI_PNF
: /* Primary no-fault, RO */
1304 case ASI_SNF
: /* Secondary no-fault, RO */
1305 case ASI_PNFL
: /* Primary no-fault LE, RO */
1306 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1308 cpu_raise_exception_ra(env
, TT_DATA_ACCESS
, GETPC());
1312 #else /* CONFIG_USER_ONLY */
1314 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
,
1315 int asi
, uint32_t memop
)
1317 int size
= 1 << (memop
& MO_SIZE
);
1318 int sign
= memop
& MO_SIGN
;
1319 CPUState
*cs
= env_cpu(env
);
1321 #if defined(DEBUG_ASI)
1322 target_ulong last_addr
= addr
;
1327 do_check_asi(env
, asi
, GETPC());
1328 do_check_align(env
, addr
, size
- 1, GETPC());
1329 addr
= asi_address_mask(env
, asi
, addr
);
1338 int idx
= (env
->pstate
& PS_PRIV
1339 ? (asi
& 1 ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
)
1340 : (asi
& 1 ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
));
1342 if (cpu_get_phys_page_nofault(env
, addr
, idx
) == -1ULL) {
1344 dump_asi("read ", last_addr
, asi
, size
, ret
);
1346 /* exception_index is set in get_physical_address_data. */
1347 cpu_raise_exception_ra(env
, cs
->exception_index
, GETPC());
1349 oi
= make_memop_idx(memop
, idx
);
1352 ret
= cpu_ldb_mmu(env
, addr
, oi
, GETPC());
1355 ret
= cpu_ldw_mmu(env
, addr
, oi
, GETPC());
1358 ret
= cpu_ldl_mmu(env
, addr
, oi
, GETPC());
1361 ret
= cpu_ldq_mmu(env
, addr
, oi
, GETPC());
1364 g_assert_not_reached();
1369 case ASI_AIUP
: /* As if user primary */
1370 case ASI_AIUS
: /* As if user secondary */
1371 case ASI_AIUPL
: /* As if user primary LE */
1372 case ASI_AIUSL
: /* As if user secondary LE */
1373 case ASI_P
: /* Primary */
1374 case ASI_S
: /* Secondary */
1375 case ASI_PL
: /* Primary LE */
1376 case ASI_SL
: /* Secondary LE */
1377 case ASI_REAL
: /* Bypass */
1378 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1379 case ASI_REAL_L
: /* Bypass LE */
1380 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1381 case ASI_N
: /* Nucleus */
1382 case ASI_NL
: /* Nucleus Little Endian (LE) */
1383 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1384 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1385 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1386 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1387 case ASI_TWINX_REAL
: /* Real address, twinx */
1388 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1389 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1390 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1391 case ASI_TWINX_N
: /* Nucleus, twinx */
1392 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1393 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1394 case ASI_TWINX_P
: /* Primary, twinx */
1395 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1396 case ASI_TWINX_S
: /* Secondary, twinx */
1397 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1402 /* These are always handled inline. */
1403 g_assert_not_reached();
1405 case ASI_UPA_CONFIG
: /* UPA config */
1408 case ASI_LSU_CONTROL
: /* LSU */
1411 case ASI_IMMU
: /* I-MMU regs */
1413 int reg
= (addr
>> 3) & 0xf;
1416 /* 0x00 I-TSB Tag Target register */
1417 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1420 ret
= env
->immu
.sfsr
;
1422 case 5: /* TSB access */
1423 ret
= env
->immu
.tsb
;
1426 /* 0x30 I-TSB Tag Access register */
1427 ret
= env
->immu
.tag_access
;
1430 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1435 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer */
1437 /* env->immuregs[5] holds I-MMU TSB register value
1438 env->immuregs[6] holds I-MMU Tag Access register value */
1439 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 0);
1442 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer */
1444 /* env->immuregs[5] holds I-MMU TSB register value
1445 env->immuregs[6] holds I-MMU Tag Access register value */
1446 ret
= ultrasparc_tsb_pointer(env
, &env
->immu
, 1);
1449 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1451 int reg
= (addr
>> 3) & 0x3f;
1453 ret
= env
->itlb
[reg
].tte
;
1456 case ASI_ITLB_TAG_READ
: /* I-MMU tag read */
1458 int reg
= (addr
>> 3) & 0x3f;
1460 ret
= env
->itlb
[reg
].tag
;
1463 case ASI_DMMU
: /* D-MMU regs */
1465 int reg
= (addr
>> 3) & 0xf;
1468 /* 0x00 D-TSB Tag Target register */
1469 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1471 case 1: /* 0x08 Primary Context */
1472 ret
= env
->dmmu
.mmu_primary_context
;
1474 case 2: /* 0x10 Secondary Context */
1475 ret
= env
->dmmu
.mmu_secondary_context
;
1478 ret
= env
->dmmu
.sfsr
;
1480 case 4: /* 0x20 SFAR */
1481 ret
= env
->dmmu
.sfar
;
1483 case 5: /* 0x28 TSB access */
1484 ret
= env
->dmmu
.tsb
;
1486 case 6: /* 0x30 D-TSB Tag Access register */
1487 ret
= env
->dmmu
.tag_access
;
1490 ret
= env
->dmmu
.virtual_watchpoint
;
1493 ret
= env
->dmmu
.physical_watchpoint
;
1496 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1501 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer */
1503 /* env->dmmuregs[5] holds D-MMU TSB register value
1504 env->dmmuregs[6] holds D-MMU Tag Access register value */
1505 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 0);
1508 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer */
1510 /* env->dmmuregs[5] holds D-MMU TSB register value
1511 env->dmmuregs[6] holds D-MMU Tag Access register value */
1512 ret
= ultrasparc_tsb_pointer(env
, &env
->dmmu
, 1);
1515 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1517 int reg
= (addr
>> 3) & 0x3f;
1519 ret
= env
->dtlb
[reg
].tte
;
1522 case ASI_DTLB_TAG_READ
: /* D-MMU tag read */
1524 int reg
= (addr
>> 3) & 0x3f;
1526 ret
= env
->dtlb
[reg
].tag
;
1529 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1531 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1532 ret
= env
->ivec_status
;
1534 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1536 int reg
= (addr
>> 4) & 0x3;
1538 ret
= env
->ivec_data
[reg
];
1542 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1543 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1544 /* Hyperprivileged access only */
1545 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1548 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1550 unsigned int i
= (addr
>> 3) & 0x7;
1551 ret
= env
->scratch
[i
];
1554 case ASI_MMU
: /* UA2005 Context ID registers */
1555 switch ((addr
>> 3) & 0x3) {
1557 ret
= env
->dmmu
.mmu_primary_context
;
1560 ret
= env
->dmmu
.mmu_secondary_context
;
1563 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1566 case ASI_DCACHE_DATA
: /* D-cache data */
1567 case ASI_DCACHE_TAG
: /* D-cache tag access */
1568 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1569 case ASI_AFSR
: /* E-cache asynchronous fault status */
1570 case ASI_AFAR
: /* E-cache asynchronous fault address */
1571 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1572 case ASI_IC_INSTR
: /* I-cache instruction access */
1573 case ASI_IC_TAG
: /* I-cache tag access */
1574 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1575 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1576 case ASI_EC_W
: /* E-cache tag */
1577 case ASI_EC_R
: /* E-cache tag */
1579 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer */
1580 case ASI_ITLB_DATA_IN
: /* I-MMU data in, WO */
1581 case ASI_IMMU_DEMAP
: /* I-MMU demap, WO */
1582 case ASI_DTLB_DATA_IN
: /* D-MMU data in, WO */
1583 case ASI_DMMU_DEMAP
: /* D-MMU demap, WO */
1584 case ASI_INTR_W
: /* Interrupt vector, WO */
1586 sparc_raise_mmu_fault(cs
, addr
, false, false, 1, size
, GETPC());
1591 /* Convert to signed number */
1598 ret
= (int16_t) ret
;
1601 ret
= (int32_t) ret
;
1608 dump_asi("read ", last_addr
, asi
, size
, ret
);
1613 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1614 int asi
, uint32_t memop
)
1616 int size
= 1 << (memop
& MO_SIZE
);
1617 CPUState
*cs
= env_cpu(env
);
1620 dump_asi("write", addr
, asi
, size
, val
);
1625 do_check_asi(env
, asi
, GETPC());
1626 do_check_align(env
, addr
, size
- 1, GETPC());
1627 addr
= asi_address_mask(env
, asi
, addr
);
1630 case ASI_AIUP
: /* As if user primary */
1631 case ASI_AIUS
: /* As if user secondary */
1632 case ASI_AIUPL
: /* As if user primary LE */
1633 case ASI_AIUSL
: /* As if user secondary LE */
1634 case ASI_P
: /* Primary */
1635 case ASI_S
: /* Secondary */
1636 case ASI_PL
: /* Primary LE */
1637 case ASI_SL
: /* Secondary LE */
1638 case ASI_REAL
: /* Bypass */
1639 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1640 case ASI_REAL_L
: /* Bypass LE */
1641 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1642 case ASI_N
: /* Nucleus */
1643 case ASI_NL
: /* Nucleus Little Endian (LE) */
1644 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1645 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1646 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1647 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1648 case ASI_TWINX_REAL
: /* Real address, twinx */
1649 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1650 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1651 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1652 case ASI_TWINX_N
: /* Nucleus, twinx */
1653 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1654 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1655 case ASI_TWINX_P
: /* Primary, twinx */
1656 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1657 case ASI_TWINX_S
: /* Secondary, twinx */
1658 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1659 /* These are always handled inline. */
1660 g_assert_not_reached();
1661 /* these ASIs have different functions on UltraSPARC-IIIi
1662 * and UA2005 CPUs. Use the explicit numbers to avoid confusion
1668 if (cpu_has_hypervisor(env
)) {
1670 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS0
1671 * ASI_DMMU_CTX_ZERO_TSB_BASE_PS1
1672 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS0
1673 * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS1
1675 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1676 env
->dmmu
.sun4v_tsb_pointers
[idx
] = val
;
1683 if (cpu_has_hypervisor(env
)) {
1685 * ASI_DMMU_CTX_ZERO_CONFIG
1686 * ASI_DMMU_CTX_NONZERO_CONFIG
1688 env
->dmmu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1697 if (cpu_has_hypervisor(env
)) {
1699 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS0
1700 * ASI_IMMU_CTX_ZERO_TSB_BASE_PS1
1701 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS0
1702 * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS1
1704 int idx
= ((asi
& 2) >> 1) | ((asi
& 8) >> 2);
1705 env
->immu
.sun4v_tsb_pointers
[idx
] = val
;
1712 if (cpu_has_hypervisor(env
)) {
1714 * ASI_IMMU_CTX_ZERO_CONFIG
1715 * ASI_IMMU_CTX_NONZERO_CONFIG
1717 env
->immu
.sun4v_ctx_config
[(asi
& 8) >> 3] = val
;
1722 case ASI_UPA_CONFIG
: /* UPA config */
1725 case ASI_LSU_CONTROL
: /* LSU */
1726 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1728 case ASI_IMMU
: /* I-MMU regs */
1730 int reg
= (addr
>> 3) & 0xf;
1733 oldreg
= env
->immu
.mmuregs
[reg
];
1737 case 1: /* Not in I-MMU */
1741 if ((val
& 1) == 0) {
1742 val
= 0; /* Clear SFSR */
1744 env
->immu
.sfsr
= val
;
1748 case 5: /* TSB access */
1749 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1750 PRIx64
"\n", env
->immu
.tsb
, val
);
1751 env
->immu
.tsb
= val
;
1753 case 6: /* Tag access */
1754 env
->immu
.tag_access
= val
;
1760 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1764 if (oldreg
!= env
->immu
.mmuregs
[reg
]) {
1765 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1766 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1773 case ASI_ITLB_DATA_IN
: /* I-MMU data in */
1774 /* ignore real translation entries */
1775 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1776 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
,
1777 val
, "immu", env
, addr
);
1780 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1782 /* TODO: auto demap */
1784 unsigned int i
= (addr
>> 3) & 0x3f;
1786 /* ignore real translation entries */
1787 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1788 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
,
1789 sun4v_tte_to_sun4u(env
, addr
, val
), env
);
1792 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1797 case ASI_IMMU_DEMAP
: /* I-MMU demap */
1798 demap_tlb(env
->itlb
, addr
, "immu", env
);
1800 case ASI_DMMU
: /* D-MMU regs */
1802 int reg
= (addr
>> 3) & 0xf;
1805 oldreg
= env
->dmmu
.mmuregs
[reg
];
1811 if ((val
& 1) == 0) {
1812 val
= 0; /* Clear SFSR, Fault address */
1815 env
->dmmu
.sfsr
= val
;
1817 case 1: /* Primary context */
1818 env
->dmmu
.mmu_primary_context
= val
;
1819 /* can be optimized to only flush MMU_USER_IDX
1820 and MMU_KERNEL_IDX entries */
1823 case 2: /* Secondary context */
1824 env
->dmmu
.mmu_secondary_context
= val
;
1825 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1826 and MMU_KERNEL_SECONDARY_IDX entries */
1829 case 5: /* TSB access */
1830 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1831 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1832 env
->dmmu
.tsb
= val
;
1834 case 6: /* Tag access */
1835 env
->dmmu
.tag_access
= val
;
1837 case 7: /* Virtual Watchpoint */
1838 env
->dmmu
.virtual_watchpoint
= val
;
1840 case 8: /* Physical Watchpoint */
1841 env
->dmmu
.physical_watchpoint
= val
;
1844 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1848 if (oldreg
!= env
->dmmu
.mmuregs
[reg
]) {
1849 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1850 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1857 case ASI_DTLB_DATA_IN
: /* D-MMU data in */
1858 /* ignore real translation entries */
1859 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1860 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
,
1861 val
, "dmmu", env
, addr
);
1864 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1866 unsigned int i
= (addr
>> 3) & 0x3f;
1868 /* ignore real translation entries */
1869 if (!(addr
& TLB_UST1_IS_REAL_BIT
)) {
1870 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
,
1871 sun4v_tte_to_sun4u(env
, addr
, val
), env
);
1874 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1879 case ASI_DMMU_DEMAP
: /* D-MMU demap */
1880 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1882 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1883 env
->ivec_status
= val
& 0x20;
1885 case ASI_SCRATCHPAD
: /* UA2005 privileged scratchpad */
1886 if (unlikely((addr
>= 0x20) && (addr
< 0x30))) {
1887 /* Hyperprivileged access only */
1888 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1891 case ASI_HYP_SCRATCHPAD
: /* UA2005 hyperprivileged scratchpad */
1893 unsigned int i
= (addr
>> 3) & 0x7;
1894 env
->scratch
[i
] = val
;
1897 case ASI_MMU
: /* UA2005 Context ID registers */
1899 switch ((addr
>> 3) & 0x3) {
1901 env
->dmmu
.mmu_primary_context
= val
;
1902 env
->immu
.mmu_primary_context
= val
;
1903 tlb_flush_by_mmuidx(cs
,
1904 (1 << MMU_USER_IDX
) | (1 << MMU_KERNEL_IDX
));
1907 env
->dmmu
.mmu_secondary_context
= val
;
1908 env
->immu
.mmu_secondary_context
= val
;
1909 tlb_flush_by_mmuidx(cs
,
1910 (1 << MMU_USER_SECONDARY_IDX
) |
1911 (1 << MMU_KERNEL_SECONDARY_IDX
));
1914 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1918 case ASI_QUEUE
: /* UA2005 CPU mondo queue */
1919 case ASI_DCACHE_DATA
: /* D-cache data */
1920 case ASI_DCACHE_TAG
: /* D-cache tag access */
1921 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1922 case ASI_AFSR
: /* E-cache asynchronous fault status */
1923 case ASI_AFAR
: /* E-cache asynchronous fault address */
1924 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1925 case ASI_IC_INSTR
: /* I-cache instruction access */
1926 case ASI_IC_TAG
: /* I-cache tag access */
1927 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1928 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1929 case ASI_EC_W
: /* E-cache tag */
1930 case ASI_EC_R
: /* E-cache tag */
1932 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer, RO */
1933 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer, RO */
1934 case ASI_ITLB_TAG_READ
: /* I-MMU tag read, RO */
1935 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer, RO */
1936 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer, RO */
1937 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer, RO */
1938 case ASI_DTLB_TAG_READ
: /* D-MMU tag read, RO */
1939 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1940 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1941 case ASI_PNF
: /* Primary no-fault, RO */
1942 case ASI_SNF
: /* Secondary no-fault, RO */
1943 case ASI_PNFL
: /* Primary no-fault LE, RO */
1944 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1946 sparc_raise_mmu_fault(cs
, addr
, true, false, 1, size
, GETPC());
1949 cpu_raise_exception_ra(env
, TT_ILL_INSN
, GETPC());
1952 #endif /* CONFIG_USER_ONLY */
1953 #endif /* TARGET_SPARC64 */
1955 #if !defined(CONFIG_USER_ONLY)
1957 void sparc_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
,
1958 vaddr addr
, unsigned size
,
1959 MMUAccessType access_type
,
1960 int mmu_idx
, MemTxAttrs attrs
,
1961 MemTxResult response
, uintptr_t retaddr
)
1963 bool is_write
= access_type
== MMU_DATA_STORE
;
1964 bool is_exec
= access_type
== MMU_INST_FETCH
;
1965 bool is_asi
= false;
1967 sparc_raise_mmu_fault(cs
, physaddr
, is_write
, is_exec
,
1968 is_asi
, size
, retaddr
);