2 * Helpers for loads and stores
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #include "exec/helper-proto.h"
23 #include "exec/exec-all.h"
24 #include "exec/cpu_ldst.h"
29 //#define DEBUG_UNALIGNED
30 //#define DEBUG_UNASSIGNED
32 //#define DEBUG_CACHE_CONTROL
35 #define DPRINTF_MMU(fmt, ...) \
36 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
38 #define DPRINTF_MMU(fmt, ...) do {} while (0)
42 #define DPRINTF_MXCC(fmt, ...) \
43 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
45 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
49 #define DPRINTF_ASI(fmt, ...) \
50 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
53 #ifdef DEBUG_CACHE_CONTROL
54 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
55 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
57 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
62 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
64 #define AM_CHECK(env1) (1)
68 #define QT0 (env->qt0)
69 #define QT1 (env->qt1)
71 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
72 /* Calculates TSB pointer value for fault page size 8k or 64k */
73 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
74 uint64_t tag_access_register
,
77 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
78 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
79 int tsb_size
= tsb_register
& 0xf;
81 /* discard lower 13 bits which hold tag access context */
82 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
84 /* now reorder bits */
85 uint64_t tsb_base_mask
= ~0x1fffULL
;
86 uint64_t va
= tag_access_va
;
88 /* move va bits to correct position */
89 if (page_size
== 8*1024) {
91 } else if (page_size
== 64*1024) {
96 tsb_base_mask
<<= tsb_size
;
99 /* calculate tsb_base mask and adjust va if split is in use */
101 if (page_size
== 8*1024) {
102 va
&= ~(1ULL << (13 + tsb_size
));
103 } else if (page_size
== 64*1024) {
104 va
|= (1ULL << (13 + tsb_size
));
109 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
112 /* Calculates tag target register value by reordering bits
113 in tag access register */
114 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
116 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
119 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
120 uint64_t tlb_tag
, uint64_t tlb_tte
,
123 target_ulong mask
, size
, va
, offset
;
125 /* flush page range if translation is valid */
126 if (TTE_IS_VALID(tlb
->tte
)) {
127 CPUState
*cs
= CPU(sparc_env_get_cpu(env1
));
129 mask
= 0xffffffffffffe000ULL
;
130 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
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
);
198 dump_mmu(stdout
, fprintf
, env1
);
204 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
205 uint64_t tlb_tag
, uint64_t tlb_tte
,
206 const char *strmmu
, CPUSPARCState
*env1
)
208 unsigned int i
, replace_used
;
210 /* Try replacing invalid entry */
211 for (i
= 0; i
< 64; i
++) {
212 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
213 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
215 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
216 dump_mmu(stdout
, fprintf
, env1
);
222 /* All entries are valid, try replacing unlocked entry */
224 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
226 /* Used entries are not replaced on first pass */
228 for (i
= 0; i
< 64; i
++) {
229 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
231 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
233 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
234 strmmu
, (replace_used
? "used" : "unused"), i
);
235 dump_mmu(stdout
, fprintf
, env1
);
241 /* Now reset used bit and search for unused entries again */
243 for (i
= 0; i
< 64; i
++) {
244 TTE_SET_UNUSED(tlb
[i
].tte
);
249 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
256 #if defined(TARGET_SPARC64) || defined(CONFIG_USER_ONLY)
257 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
259 #ifdef TARGET_SPARC64
260 if (AM_CHECK(env1
)) {
261 addr
&= 0xffffffffULL
;
268 #ifdef TARGET_SPARC64
269 /* returns true if access using this ASI is to have address translated by MMU
270 otherwise access is to raw physical address */
271 /* TODO: check sparc32 bits */
272 static inline int is_translating_asi(int asi
)
274 /* Ultrasparc IIi translating asi
275 - note this list is defined by cpu implementation
292 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
293 int asi
, target_ulong addr
)
295 if (is_translating_asi(asi
)) {
296 return address_mask(env
, addr
);
303 void helper_check_align(CPUSPARCState
*env
, target_ulong addr
, uint32_t align
)
306 #ifdef DEBUG_UNALIGNED
307 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
308 "\n", addr
, env
->pc
);
310 helper_raise_exception(env
, TT_UNALIGNED
);
314 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
316 static void dump_mxcc(CPUSPARCState
*env
)
318 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
320 env
->mxccdata
[0], env
->mxccdata
[1],
321 env
->mxccdata
[2], env
->mxccdata
[3]);
322 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
324 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
326 env
->mxccregs
[0], env
->mxccregs
[1],
327 env
->mxccregs
[2], env
->mxccregs
[3],
328 env
->mxccregs
[4], env
->mxccregs
[5],
329 env
->mxccregs
[6], env
->mxccregs
[7]);
333 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
334 && defined(DEBUG_ASI)
335 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
340 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
341 addr
, asi
, r1
& 0xff);
344 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
345 addr
, asi
, r1
& 0xffff);
348 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
349 addr
, asi
, r1
& 0xffffffff);
352 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
359 #ifndef TARGET_SPARC64
360 #ifndef CONFIG_USER_ONLY
363 /* Leon3 cache control */
365 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
366 uint64_t val
, int size
)
368 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
372 DPRINTF_CACHE_CONTROL("32bits only\n");
377 case 0x00: /* Cache control */
379 /* These values must always be read as zeros */
380 val
&= ~CACHE_CTRL_FD
;
381 val
&= ~CACHE_CTRL_FI
;
382 val
&= ~CACHE_CTRL_IB
;
383 val
&= ~CACHE_CTRL_IP
;
384 val
&= ~CACHE_CTRL_DP
;
386 env
->cache_control
= val
;
388 case 0x04: /* Instruction cache configuration */
389 case 0x08: /* Data cache configuration */
393 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
398 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
404 DPRINTF_CACHE_CONTROL("32bits only\n");
409 case 0x00: /* Cache control */
410 ret
= env
->cache_control
;
413 /* Configuration registers are read and only always keep those
416 case 0x04: /* Instruction cache configuration */
419 case 0x08: /* Data cache configuration */
423 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
426 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
431 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
434 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
436 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
437 uint32_t last_addr
= addr
;
440 helper_check_align(env
, addr
, size
- 1);
442 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
443 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
445 case 0x00: /* Leon3 Cache Control */
446 case 0x08: /* Leon3 Instruction Cache config */
447 case 0x0C: /* Leon3 Date Cache config */
448 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
449 ret
= leon3_cache_control_ld(env
, addr
, size
);
452 case 0x01c00a00: /* MXCC control register */
454 ret
= env
->mxccregs
[3];
456 qemu_log_mask(LOG_UNIMP
,
457 "%08x: unimplemented access size: %d\n", addr
,
461 case 0x01c00a04: /* MXCC control register */
463 ret
= env
->mxccregs
[3];
465 qemu_log_mask(LOG_UNIMP
,
466 "%08x: unimplemented access size: %d\n", addr
,
470 case 0x01c00c00: /* Module reset register */
472 ret
= env
->mxccregs
[5];
473 /* should we do something here? */
475 qemu_log_mask(LOG_UNIMP
,
476 "%08x: unimplemented access size: %d\n", addr
,
480 case 0x01c00f00: /* MBus port address register */
482 ret
= env
->mxccregs
[7];
484 qemu_log_mask(LOG_UNIMP
,
485 "%08x: unimplemented access size: %d\n", addr
,
490 qemu_log_mask(LOG_UNIMP
,
491 "%08x: unimplemented address, size: %d\n", addr
,
495 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
496 "addr = %08x -> ret = %" PRIx64
","
497 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
502 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU probe */
503 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU probe */
507 mmulev
= (addr
>> 8) & 15;
511 ret
= mmu_probe(env
, addr
, mmulev
);
513 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
517 case ASI_M_MMUREGS
: /* SuperSparc MMU regs */
518 case ASI_LEON_MMUREGS
: /* LEON3 MMU regs */
520 int reg
= (addr
>> 8) & 0x1f;
522 ret
= env
->mmuregs
[reg
];
523 if (reg
== 3) { /* Fault status cleared on read */
525 } else if (reg
== 0x13) { /* Fault status read */
526 ret
= env
->mmuregs
[3];
527 } else if (reg
== 0x14) { /* Fault address read */
528 ret
= env
->mmuregs
[4];
530 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
533 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
534 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
535 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
537 case ASI_KERNELTXT
: /* Supervisor code access */
540 ret
= cpu_ldub_code(env
, addr
);
543 ret
= cpu_lduw_code(env
, addr
);
547 ret
= cpu_ldl_code(env
, addr
);
550 ret
= cpu_ldq_code(env
, addr
);
554 case ASI_USERDATA
: /* User data access */
557 ret
= cpu_ldub_user(env
, addr
);
560 ret
= cpu_lduw_user(env
, addr
);
564 ret
= cpu_ldl_user(env
, addr
);
567 ret
= cpu_ldq_user(env
, addr
);
571 case ASI_KERNELDATA
: /* Supervisor data access */
572 case ASI_P
: /* Implicit primary context data access (v9 only?) */
575 ret
= cpu_ldub_kernel(env
, addr
);
578 ret
= cpu_lduw_kernel(env
, addr
);
582 ret
= cpu_ldl_kernel(env
, addr
);
585 ret
= cpu_ldq_kernel(env
, addr
);
589 case ASI_M_TXTC_TAG
: /* SparcStation 5 I-cache tag */
590 case ASI_M_TXTC_DATA
: /* SparcStation 5 I-cache data */
591 case ASI_M_DATAC_TAG
: /* SparcStation 5 D-cache tag */
592 case ASI_M_DATAC_DATA
: /* SparcStation 5 D-cache data */
594 case ASI_M_BYPASS
: /* MMU passthrough */
595 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
598 ret
= ldub_phys(cs
->as
, addr
);
601 ret
= lduw_phys(cs
->as
, addr
);
605 ret
= ldl_phys(cs
->as
, addr
);
608 ret
= ldq_phys(cs
->as
, addr
);
612 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
615 ret
= ldub_phys(cs
->as
, (hwaddr
)addr
616 | ((hwaddr
)(asi
& 0xf) << 32));
619 ret
= lduw_phys(cs
->as
, (hwaddr
)addr
620 | ((hwaddr
)(asi
& 0xf) << 32));
624 ret
= ldl_phys(cs
->as
, (hwaddr
)addr
625 | ((hwaddr
)(asi
& 0xf) << 32));
628 ret
= ldq_phys(cs
->as
, (hwaddr
)addr
629 | ((hwaddr
)(asi
& 0xf) << 32));
633 case 0x30: /* Turbosparc secondary cache diagnostic */
634 case 0x31: /* Turbosparc RAM snoop */
635 case 0x32: /* Turbosparc page table descriptor diagnostic */
636 case 0x39: /* data cache diagnostic register */
639 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
641 int reg
= (addr
>> 8) & 3;
644 case 0: /* Breakpoint Value (Addr) */
645 ret
= env
->mmubpregs
[reg
];
647 case 1: /* Breakpoint Mask */
648 ret
= env
->mmubpregs
[reg
];
650 case 2: /* Breakpoint Control */
651 ret
= env
->mmubpregs
[reg
];
653 case 3: /* Breakpoint Status */
654 ret
= env
->mmubpregs
[reg
];
655 env
->mmubpregs
[reg
] = 0ULL;
658 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
662 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
663 ret
= env
->mmubpctrv
;
665 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
666 ret
= env
->mmubpctrc
;
668 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
669 ret
= env
->mmubpctrs
;
671 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
672 ret
= env
->mmubpaction
;
674 case ASI_USERTXT
: /* User code access, XXX */
676 cpu_unassigned_access(cs
, addr
, false, false, asi
, size
);
696 dump_asi("read ", last_addr
, asi
, size
, ret
);
701 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
, int asi
,
704 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
705 CPUState
*cs
= CPU(cpu
);
707 helper_check_align(env
, addr
, size
- 1);
709 case ASI_M_MXCC
: /* SuperSparc MXCC registers, or... */
710 /* case ASI_LEON_CACHEREGS: Leon3 cache control */
712 case 0x00: /* Leon3 Cache Control */
713 case 0x08: /* Leon3 Instruction Cache config */
714 case 0x0C: /* Leon3 Date Cache config */
715 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
716 leon3_cache_control_st(env
, addr
, val
, size
);
720 case 0x01c00000: /* MXCC stream data register 0 */
722 env
->mxccdata
[0] = val
;
724 qemu_log_mask(LOG_UNIMP
,
725 "%08x: unimplemented access size: %d\n", addr
,
729 case 0x01c00008: /* MXCC stream data register 1 */
731 env
->mxccdata
[1] = val
;
733 qemu_log_mask(LOG_UNIMP
,
734 "%08x: unimplemented access size: %d\n", addr
,
738 case 0x01c00010: /* MXCC stream data register 2 */
740 env
->mxccdata
[2] = val
;
742 qemu_log_mask(LOG_UNIMP
,
743 "%08x: unimplemented access size: %d\n", addr
,
747 case 0x01c00018: /* MXCC stream data register 3 */
749 env
->mxccdata
[3] = val
;
751 qemu_log_mask(LOG_UNIMP
,
752 "%08x: unimplemented access size: %d\n", addr
,
756 case 0x01c00100: /* MXCC stream source */
758 env
->mxccregs
[0] = val
;
760 qemu_log_mask(LOG_UNIMP
,
761 "%08x: unimplemented access size: %d\n", addr
,
764 env
->mxccdata
[0] = ldq_phys(cs
->as
,
765 (env
->mxccregs
[0] & 0xffffffffULL
) +
767 env
->mxccdata
[1] = ldq_phys(cs
->as
,
768 (env
->mxccregs
[0] & 0xffffffffULL
) +
770 env
->mxccdata
[2] = ldq_phys(cs
->as
,
771 (env
->mxccregs
[0] & 0xffffffffULL
) +
773 env
->mxccdata
[3] = ldq_phys(cs
->as
,
774 (env
->mxccregs
[0] & 0xffffffffULL
) +
777 case 0x01c00200: /* MXCC stream destination */
779 env
->mxccregs
[1] = val
;
781 qemu_log_mask(LOG_UNIMP
,
782 "%08x: unimplemented access size: %d\n", addr
,
785 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 0,
787 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 8,
789 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 16,
791 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 24,
794 case 0x01c00a00: /* MXCC control register */
796 env
->mxccregs
[3] = val
;
798 qemu_log_mask(LOG_UNIMP
,
799 "%08x: unimplemented access size: %d\n", addr
,
803 case 0x01c00a04: /* MXCC control register */
805 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
808 qemu_log_mask(LOG_UNIMP
,
809 "%08x: unimplemented access size: %d\n", addr
,
813 case 0x01c00e00: /* MXCC error register */
814 /* writing a 1 bit clears the error */
816 env
->mxccregs
[6] &= ~val
;
818 qemu_log_mask(LOG_UNIMP
,
819 "%08x: unimplemented access size: %d\n", addr
,
823 case 0x01c00f00: /* MBus port address register */
825 env
->mxccregs
[7] = val
;
827 qemu_log_mask(LOG_UNIMP
,
828 "%08x: unimplemented access size: %d\n", addr
,
833 qemu_log_mask(LOG_UNIMP
,
834 "%08x: unimplemented address, size: %d\n", addr
,
838 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
839 asi
, size
, addr
, val
);
844 case ASI_M_FLUSH_PROBE
: /* SuperSparc MMU flush */
845 case ASI_LEON_MMUFLUSH
: /* LEON3 MMU flush */
849 mmulev
= (addr
>> 8) & 15;
850 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
852 case 0: /* flush page */
853 tlb_flush_page(CPU(cpu
), addr
& 0xfffff000);
855 case 1: /* flush segment (256k) */
856 case 2: /* flush region (16M) */
857 case 3: /* flush context (4G) */
858 case 4: /* flush entire */
859 tlb_flush(CPU(cpu
), 1);
865 dump_mmu(stdout
, fprintf
, env
);
869 case ASI_M_MMUREGS
: /* write MMU regs */
870 case ASI_LEON_MMUREGS
: /* LEON3 write MMU regs */
872 int reg
= (addr
>> 8) & 0x1f;
875 oldreg
= env
->mmuregs
[reg
];
877 case 0: /* Control Register */
878 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
880 /* Mappings generated during no-fault mode or MMU
881 disabled mode are invalid in normal mode */
882 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
883 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
))) {
884 tlb_flush(CPU(cpu
), 1);
887 case 1: /* Context Table Pointer Register */
888 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
890 case 2: /* Context Register */
891 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
892 if (oldreg
!= env
->mmuregs
[reg
]) {
893 /* we flush when the MMU context changes because
894 QEMU has no MMU context support */
895 tlb_flush(CPU(cpu
), 1);
898 case 3: /* Synchronous Fault Status Register with Clear */
899 case 4: /* Synchronous Fault Address Register */
901 case 0x10: /* TLB Replacement Control Register */
902 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
904 case 0x13: /* Synchronous Fault Status Register with Read
906 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
908 case 0x14: /* Synchronous Fault Address Register */
909 env
->mmuregs
[4] = val
;
912 env
->mmuregs
[reg
] = val
;
915 if (oldreg
!= env
->mmuregs
[reg
]) {
916 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
917 reg
, oldreg
, env
->mmuregs
[reg
]);
920 dump_mmu(stdout
, fprintf
, env
);
924 case ASI_M_TLBDIAG
: /* Turbosparc ITLB Diagnostic */
925 case ASI_M_DIAGS
: /* Turbosparc DTLB Diagnostic */
926 case ASI_M_IODIAG
: /* Turbosparc IOTLB Diagnostic */
928 case ASI_USERDATA
: /* User data access */
931 cpu_stb_user(env
, addr
, val
);
934 cpu_stw_user(env
, addr
, val
);
938 cpu_stl_user(env
, addr
, val
);
941 cpu_stq_user(env
, addr
, val
);
945 case ASI_KERNELDATA
: /* Supervisor data access */
949 cpu_stb_kernel(env
, addr
, val
);
952 cpu_stw_kernel(env
, addr
, val
);
956 cpu_stl_kernel(env
, addr
, val
);
959 cpu_stq_kernel(env
, addr
, val
);
963 case ASI_M_TXTC_TAG
: /* I-cache tag */
964 case ASI_M_TXTC_DATA
: /* I-cache data */
965 case ASI_M_DATAC_TAG
: /* D-cache tag */
966 case ASI_M_DATAC_DATA
: /* D-cache data */
967 case ASI_M_FLUSH_PAGE
: /* I/D-cache flush page */
968 case ASI_M_FLUSH_SEG
: /* I/D-cache flush segment */
969 case ASI_M_FLUSH_REGION
: /* I/D-cache flush region */
970 case ASI_M_FLUSH_CTX
: /* I/D-cache flush context */
971 case ASI_M_FLUSH_USER
: /* I/D-cache flush user */
973 case ASI_M_BCOPY
: /* Block copy, sta access */
979 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
981 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
982 temp
= cpu_ldl_kernel(env
, src
);
983 cpu_stl_kernel(env
, dst
, temp
);
987 case ASI_M_BFILL
: /* Block fill, stda access */
990 fill 32 bytes with val */
992 uint32_t dst
= addr
& 7;
994 for (i
= 0; i
< 32; i
+= 8, dst
+= 8) {
995 cpu_stq_kernel(env
, dst
, val
);
999 case ASI_M_BYPASS
: /* MMU passthrough */
1000 case ASI_LEON_BYPASS
: /* LEON MMU passthrough */
1004 stb_phys(cs
->as
, addr
, val
);
1007 stw_phys(cs
->as
, addr
, val
);
1011 stl_phys(cs
->as
, addr
, val
);
1014 stq_phys(cs
->as
, addr
, val
);
1019 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1023 stb_phys(cs
->as
, (hwaddr
)addr
1024 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1027 stw_phys(cs
->as
, (hwaddr
)addr
1028 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1032 stl_phys(cs
->as
, (hwaddr
)addr
1033 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1036 stq_phys(cs
->as
, (hwaddr
)addr
1037 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1042 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1043 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1044 Turbosparc snoop RAM */
1045 case 0x32: /* store buffer control or Turbosparc page table
1046 descriptor diagnostic */
1047 case 0x36: /* I-cache flash clear */
1048 case 0x37: /* D-cache flash clear */
1050 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1052 int reg
= (addr
>> 8) & 3;
1055 case 0: /* Breakpoint Value (Addr) */
1056 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1058 case 1: /* Breakpoint Mask */
1059 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1061 case 2: /* Breakpoint Control */
1062 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1064 case 3: /* Breakpoint Status */
1065 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1068 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1072 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1073 env
->mmubpctrv
= val
& 0xffffffff;
1075 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1076 env
->mmubpctrc
= val
& 0x3;
1078 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1079 env
->mmubpctrs
= val
& 0x3;
1081 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1082 env
->mmubpaction
= val
& 0x1fff;
1084 case ASI_USERTXT
: /* User code access, XXX */
1085 case ASI_KERNELTXT
: /* Supervisor code access, XXX */
1087 cpu_unassigned_access(CPU(sparc_env_get_cpu(env
)),
1088 addr
, true, false, asi
, size
);
1092 dump_asi("write", addr
, asi
, size
, val
);
1096 #endif /* CONFIG_USER_ONLY */
1097 #else /* TARGET_SPARC64 */
1099 #ifdef CONFIG_USER_ONLY
1100 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1104 #if defined(DEBUG_ASI)
1105 target_ulong last_addr
= addr
;
1109 helper_raise_exception(env
, TT_PRIV_ACT
);
1112 helper_check_align(env
, addr
, size
- 1);
1113 addr
= asi_address_mask(env
, asi
, addr
);
1116 case ASI_PNF
: /* Primary no-fault */
1117 case ASI_PNFL
: /* Primary no-fault LE */
1118 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1120 dump_asi("read ", last_addr
, asi
, size
, ret
);
1125 case ASI_P
: /* Primary */
1126 case ASI_PL
: /* Primary LE */
1130 ret
= cpu_ldub_data(env
, addr
);
1133 ret
= cpu_lduw_data(env
, addr
);
1136 ret
= cpu_ldl_data(env
, addr
);
1140 ret
= cpu_ldq_data(env
, addr
);
1145 case ASI_SNF
: /* Secondary no-fault */
1146 case ASI_SNFL
: /* Secondary no-fault LE */
1147 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1149 dump_asi("read ", last_addr
, asi
, size
, ret
);
1154 case ASI_S
: /* Secondary */
1155 case ASI_SL
: /* Secondary LE */
1162 /* Convert from little endian */
1164 case ASI_PL
: /* Primary LE */
1165 case ASI_SL
: /* Secondary LE */
1166 case ASI_PNFL
: /* Primary no-fault LE */
1167 case ASI_SNFL
: /* Secondary no-fault LE */
1185 /* Convert to signed number */
1192 ret
= (int16_t) ret
;
1195 ret
= (int32_t) ret
;
1202 dump_asi("read ", last_addr
, asi
, size
, ret
);
1207 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1211 dump_asi("write", addr
, asi
, size
, val
);
1214 helper_raise_exception(env
, TT_PRIV_ACT
);
1217 helper_check_align(env
, addr
, size
- 1);
1218 addr
= asi_address_mask(env
, asi
, addr
);
1220 /* Convert to little endian */
1222 case ASI_PL
: /* Primary LE */
1223 case ASI_SL
: /* Secondary LE */
1242 case ASI_P
: /* Primary */
1243 case ASI_PL
: /* Primary LE */
1247 cpu_stb_data(env
, addr
, val
);
1250 cpu_stw_data(env
, addr
, val
);
1253 cpu_stl_data(env
, addr
, val
);
1257 cpu_stq_data(env
, addr
, val
);
1262 case ASI_S
: /* Secondary */
1263 case ASI_SL
: /* Secondary LE */
1267 case ASI_PNF
: /* Primary no-fault, RO */
1268 case ASI_SNF
: /* Secondary no-fault, RO */
1269 case ASI_PNFL
: /* Primary no-fault LE, RO */
1270 case ASI_SNFL
: /* Secondary no-fault LE, RO */
1272 helper_raise_exception(env
, TT_DATA_ACCESS
);
1277 #else /* CONFIG_USER_ONLY */
1279 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1282 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
1284 #if defined(DEBUG_ASI)
1285 target_ulong last_addr
= addr
;
1290 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1291 || (cpu_has_hypervisor(env
)
1292 && asi
>= 0x30 && asi
< 0x80
1293 && !(env
->hpstate
& HS_PRIV
))) {
1294 helper_raise_exception(env
, TT_PRIV_ACT
);
1297 helper_check_align(env
, addr
, size
- 1);
1298 addr
= asi_address_mask(env
, asi
, addr
);
1300 /* process nonfaulting loads first */
1301 if ((asi
& 0xf6) == 0x82) {
1304 /* secondary space access has lowest asi bit equal to 1 */
1305 if (env
->pstate
& PS_PRIV
) {
1306 mmu_idx
= (asi
& 1) ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
;
1308 mmu_idx
= (asi
& 1) ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
;
1311 if (cpu_get_phys_page_nofault(env
, addr
, mmu_idx
) == -1ULL) {
1313 dump_asi("read ", last_addr
, asi
, size
, ret
);
1315 /* env->exception_index is set in get_physical_address_data(). */
1316 helper_raise_exception(env
, cs
->exception_index
);
1319 /* convert nonfaulting load ASIs to normal load ASIs */
1324 case ASI_AIUP
: /* As if user primary */
1325 case ASI_AIUS
: /* As if user secondary */
1326 case ASI_AIUPL
: /* As if user primary LE */
1327 case ASI_AIUSL
: /* As if user secondary LE */
1328 case ASI_P
: /* Primary */
1329 case ASI_S
: /* Secondary */
1330 case ASI_PL
: /* Primary LE */
1331 case ASI_SL
: /* Secondary LE */
1332 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1333 if (cpu_hypervisor_mode(env
)) {
1336 ret
= cpu_ldub_hypv(env
, addr
);
1339 ret
= cpu_lduw_hypv(env
, addr
);
1342 ret
= cpu_ldl_hypv(env
, addr
);
1346 ret
= cpu_ldq_hypv(env
, addr
);
1350 /* secondary space access has lowest asi bit equal to 1 */
1354 ret
= cpu_ldub_kernel_secondary(env
, addr
);
1357 ret
= cpu_lduw_kernel_secondary(env
, addr
);
1360 ret
= cpu_ldl_kernel_secondary(env
, addr
);
1364 ret
= cpu_ldq_kernel_secondary(env
, addr
);
1370 ret
= cpu_ldub_kernel(env
, addr
);
1373 ret
= cpu_lduw_kernel(env
, addr
);
1376 ret
= cpu_ldl_kernel(env
, addr
);
1380 ret
= cpu_ldq_kernel(env
, addr
);
1386 /* secondary space access has lowest asi bit equal to 1 */
1390 ret
= cpu_ldub_user_secondary(env
, addr
);
1393 ret
= cpu_lduw_user_secondary(env
, addr
);
1396 ret
= cpu_ldl_user_secondary(env
, addr
);
1400 ret
= cpu_ldq_user_secondary(env
, addr
);
1406 ret
= cpu_ldub_user(env
, addr
);
1409 ret
= cpu_lduw_user(env
, addr
);
1412 ret
= cpu_ldl_user(env
, addr
);
1416 ret
= cpu_ldq_user(env
, addr
);
1422 case ASI_REAL
: /* Bypass */
1423 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1424 case ASI_REAL_L
: /* Bypass LE */
1425 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1429 ret
= ldub_phys(cs
->as
, addr
);
1432 ret
= lduw_phys(cs
->as
, addr
);
1435 ret
= ldl_phys(cs
->as
, addr
);
1439 ret
= ldq_phys(cs
->as
, addr
);
1444 case ASI_N
: /* Nucleus */
1445 case ASI_NL
: /* Nucleus Little Endian (LE) */
1449 ret
= cpu_ldub_nucleus(env
, addr
);
1452 ret
= cpu_lduw_nucleus(env
, addr
);
1455 ret
= cpu_ldl_nucleus(env
, addr
);
1459 ret
= cpu_ldq_nucleus(env
, addr
);
1464 case ASI_UPA_CONFIG
: /* UPA config */
1467 case ASI_LSU_CONTROL
: /* LSU */
1470 case ASI_IMMU
: /* I-MMU regs */
1472 int reg
= (addr
>> 3) & 0xf;
1475 /* I-TSB Tag Target register */
1476 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1478 ret
= env
->immuregs
[reg
];
1483 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer */
1485 /* env->immuregs[5] holds I-MMU TSB register value
1486 env->immuregs[6] holds I-MMU Tag Access register value */
1487 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1491 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer */
1493 /* env->immuregs[5] holds I-MMU TSB register value
1494 env->immuregs[6] holds I-MMU Tag Access register value */
1495 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1499 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1501 int reg
= (addr
>> 3) & 0x3f;
1503 ret
= env
->itlb
[reg
].tte
;
1506 case ASI_ITLB_TAG_READ
: /* I-MMU tag read */
1508 int reg
= (addr
>> 3) & 0x3f;
1510 ret
= env
->itlb
[reg
].tag
;
1513 case ASI_DMMU
: /* D-MMU regs */
1515 int reg
= (addr
>> 3) & 0xf;
1518 /* D-TSB Tag Target register */
1519 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1521 ret
= env
->dmmuregs
[reg
];
1525 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer */
1527 /* env->dmmuregs[5] holds D-MMU TSB register value
1528 env->dmmuregs[6] holds D-MMU Tag Access register value */
1529 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1533 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer */
1535 /* env->dmmuregs[5] holds D-MMU TSB register value
1536 env->dmmuregs[6] holds D-MMU Tag Access register value */
1537 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1541 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1543 int reg
= (addr
>> 3) & 0x3f;
1545 ret
= env
->dtlb
[reg
].tte
;
1548 case ASI_DTLB_TAG_READ
: /* D-MMU tag read */
1550 int reg
= (addr
>> 3) & 0x3f;
1552 ret
= env
->dtlb
[reg
].tag
;
1555 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
1557 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
1558 ret
= env
->ivec_status
;
1560 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
1562 int reg
= (addr
>> 4) & 0x3;
1564 ret
= env
->ivec_data
[reg
];
1568 case ASI_DCACHE_DATA
: /* D-cache data */
1569 case ASI_DCACHE_TAG
: /* D-cache tag access */
1570 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
1571 case ASI_AFSR
: /* E-cache asynchronous fault status */
1572 case ASI_AFAR
: /* E-cache asynchronous fault address */
1573 case ASI_EC_TAG_DATA
: /* E-cache tag data */
1574 case ASI_IC_INSTR
: /* I-cache instruction access */
1575 case ASI_IC_TAG
: /* I-cache tag access */
1576 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
1577 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
1578 case ASI_EC_W
: /* E-cache tag */
1579 case ASI_EC_R
: /* E-cache tag */
1581 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer */
1582 case ASI_ITLB_DATA_IN
: /* I-MMU data in, WO */
1583 case ASI_IMMU_DEMAP
: /* I-MMU demap, WO */
1584 case ASI_DTLB_DATA_IN
: /* D-MMU data in, WO */
1585 case ASI_DMMU_DEMAP
: /* D-MMU demap, WO */
1586 case ASI_INTR_W
: /* Interrupt vector, WO */
1588 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1592 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
1593 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
1594 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
1595 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
1596 case ASI_TWINX_REAL
: /* Real address, twinx */
1597 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
1598 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
1599 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
1600 case ASI_TWINX_N
: /* Nucleus, twinx */
1601 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
1602 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1603 case ASI_TWINX_P
: /* Primary, twinx */
1604 case ASI_TWINX_PL
: /* Primary, twinx, LE */
1605 case ASI_TWINX_S
: /* Secondary, twinx */
1606 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
1607 /* These are all 128-bit atomic; only ldda (now ldtxa) allowed */
1608 helper_raise_exception(env
, TT_ILL_INSN
);
1612 /* Convert from little endian */
1614 case ASI_NL
: /* Nucleus Little Endian (LE) */
1615 case ASI_AIUPL
: /* As if user primary LE */
1616 case ASI_AIUSL
: /* As if user secondary LE */
1617 case ASI_REAL_L
: /* Bypass LE */
1618 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1619 case ASI_PL
: /* Primary LE */
1620 case ASI_SL
: /* Secondary LE */
1638 /* Convert to signed number */
1645 ret
= (int16_t) ret
;
1648 ret
= (int32_t) ret
;
1655 dump_asi("read ", last_addr
, asi
, size
, ret
);
1660 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1663 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
1664 CPUState
*cs
= CPU(cpu
);
1667 dump_asi("write", addr
, asi
, size
, val
);
1672 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1673 || (cpu_has_hypervisor(env
)
1674 && asi
>= 0x30 && asi
< 0x80
1675 && !(env
->hpstate
& HS_PRIV
))) {
1676 helper_raise_exception(env
, TT_PRIV_ACT
);
1679 helper_check_align(env
, addr
, size
- 1);
1680 addr
= asi_address_mask(env
, asi
, addr
);
1682 /* Convert to little endian */
1684 case ASI_NL
: /* Nucleus Little Endian (LE) */
1685 case ASI_AIUPL
: /* As if user primary LE */
1686 case ASI_AIUSL
: /* As if user secondary LE */
1687 case ASI_REAL_L
: /* Bypass LE */
1688 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1689 case ASI_PL
: /* Primary LE */
1690 case ASI_SL
: /* Secondary LE */
1709 case ASI_AIUP
: /* As if user primary */
1710 case ASI_AIUS
: /* As if user secondary */
1711 case ASI_AIUPL
: /* As if user primary LE */
1712 case ASI_AIUSL
: /* As if user secondary LE */
1713 case ASI_P
: /* Primary */
1714 case ASI_S
: /* Secondary */
1715 case ASI_PL
: /* Primary LE */
1716 case ASI_SL
: /* Secondary LE */
1717 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1718 if (cpu_hypervisor_mode(env
)) {
1721 cpu_stb_hypv(env
, addr
, val
);
1724 cpu_stw_hypv(env
, addr
, val
);
1727 cpu_stl_hypv(env
, addr
, val
);
1731 cpu_stq_hypv(env
, addr
, val
);
1735 /* secondary space access has lowest asi bit equal to 1 */
1739 cpu_stb_kernel_secondary(env
, addr
, val
);
1742 cpu_stw_kernel_secondary(env
, addr
, val
);
1745 cpu_stl_kernel_secondary(env
, addr
, val
);
1749 cpu_stq_kernel_secondary(env
, addr
, val
);
1755 cpu_stb_kernel(env
, addr
, val
);
1758 cpu_stw_kernel(env
, addr
, val
);
1761 cpu_stl_kernel(env
, addr
, val
);
1765 cpu_stq_kernel(env
, addr
, val
);
1771 /* secondary space access has lowest asi bit equal to 1 */
1775 cpu_stb_user_secondary(env
, addr
, val
);
1778 cpu_stw_user_secondary(env
, addr
, val
);
1781 cpu_stl_user_secondary(env
, addr
, val
);
1785 cpu_stq_user_secondary(env
, addr
, val
);
1791 cpu_stb_user(env
, addr
, val
);
1794 cpu_stw_user(env
, addr
, val
);
1797 cpu_stl_user(env
, addr
, val
);
1801 cpu_stq_user(env
, addr
, val
);
1807 case ASI_REAL
: /* Bypass */
1808 case ASI_REAL_IO
: /* Bypass, non-cacheable */
1809 case ASI_REAL_L
: /* Bypass LE */
1810 case ASI_REAL_IO_L
: /* Bypass, non-cacheable LE */
1814 stb_phys(cs
->as
, addr
, val
);
1817 stw_phys(cs
->as
, addr
, val
);
1820 stl_phys(cs
->as
, addr
, val
);
1824 stq_phys(cs
->as
, addr
, val
);
1829 case ASI_N
: /* Nucleus */
1830 case ASI_NL
: /* Nucleus Little Endian (LE) */
1834 cpu_stb_nucleus(env
, addr
, val
);
1837 cpu_stw_nucleus(env
, addr
, val
);
1840 cpu_stl_nucleus(env
, addr
, val
);
1844 cpu_stq_nucleus(env
, addr
, val
);
1850 case ASI_UPA_CONFIG
: /* UPA config */
1853 case ASI_LSU_CONTROL
: /* LSU */
1858 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1859 /* Mappings generated during D/I MMU disabled mode are
1860 invalid in normal mode */
1861 if (oldreg
!= env
->lsu
) {
1862 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1865 dump_mmu(stdout
, fprintf
, env
);
1867 tlb_flush(CPU(cpu
), 1);
1871 case ASI_IMMU
: /* I-MMU regs */
1873 int reg
= (addr
>> 3) & 0xf;
1876 oldreg
= env
->immuregs
[reg
];
1880 case 1: /* Not in I-MMU */
1884 if ((val
& 1) == 0) {
1885 val
= 0; /* Clear SFSR */
1887 env
->immu
.sfsr
= val
;
1891 case 5: /* TSB access */
1892 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1893 PRIx64
"\n", env
->immu
.tsb
, val
);
1894 env
->immu
.tsb
= val
;
1896 case 6: /* Tag access */
1897 env
->immu
.tag_access
= val
;
1906 if (oldreg
!= env
->immuregs
[reg
]) {
1907 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1908 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1911 dump_mmu(stdout
, fprintf
, env
);
1915 case ASI_ITLB_DATA_IN
: /* I-MMU data in */
1916 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
1918 case ASI_ITLB_DATA_ACCESS
: /* I-MMU data access */
1920 /* TODO: auto demap */
1922 unsigned int i
= (addr
>> 3) & 0x3f;
1924 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
1927 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1928 dump_mmu(stdout
, fprintf
, env
);
1932 case ASI_IMMU_DEMAP
: /* I-MMU demap */
1933 demap_tlb(env
->itlb
, addr
, "immu", env
);
1935 case ASI_DMMU
: /* D-MMU regs */
1937 int reg
= (addr
>> 3) & 0xf;
1940 oldreg
= env
->dmmuregs
[reg
];
1946 if ((val
& 1) == 0) {
1947 val
= 0; /* Clear SFSR, Fault address */
1950 env
->dmmu
.sfsr
= val
;
1952 case 1: /* Primary context */
1953 env
->dmmu
.mmu_primary_context
= val
;
1954 /* can be optimized to only flush MMU_USER_IDX
1955 and MMU_KERNEL_IDX entries */
1956 tlb_flush(CPU(cpu
), 1);
1958 case 2: /* Secondary context */
1959 env
->dmmu
.mmu_secondary_context
= val
;
1960 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1961 and MMU_KERNEL_SECONDARY_IDX entries */
1962 tlb_flush(CPU(cpu
), 1);
1964 case 5: /* TSB access */
1965 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1966 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1967 env
->dmmu
.tsb
= val
;
1969 case 6: /* Tag access */
1970 env
->dmmu
.tag_access
= val
;
1972 case 7: /* Virtual Watchpoint */
1973 case 8: /* Physical Watchpoint */
1975 env
->dmmuregs
[reg
] = val
;
1979 if (oldreg
!= env
->dmmuregs
[reg
]) {
1980 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1981 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1984 dump_mmu(stdout
, fprintf
, env
);
1988 case ASI_DTLB_DATA_IN
: /* D-MMU data in */
1989 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
1991 case ASI_DTLB_DATA_ACCESS
: /* D-MMU data access */
1993 unsigned int i
= (addr
>> 3) & 0x3f;
1995 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
1998 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1999 dump_mmu(stdout
, fprintf
, env
);
2003 case ASI_DMMU_DEMAP
: /* D-MMU demap */
2004 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
2006 case ASI_INTR_RECEIVE
: /* Interrupt data receive */
2007 env
->ivec_status
= val
& 0x20;
2009 case ASI_NUCLEUS_QUAD_LDD
: /* Nucleus quad LDD 128 bit atomic */
2010 case ASI_NUCLEUS_QUAD_LDD_L
: /* Nucleus quad LDD 128 bit atomic LE */
2011 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
2012 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
2013 case ASI_TWINX_REAL
: /* Real address, twinx */
2014 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
2015 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
2016 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
2017 case ASI_TWINX_N
: /* Nucleus, twinx */
2018 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
2019 /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
2020 case ASI_TWINX_P
: /* Primary, twinx */
2021 case ASI_TWINX_PL
: /* Primary, twinx, LE */
2022 case ASI_TWINX_S
: /* Secondary, twinx */
2023 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
2024 /* Only stda allowed */
2025 helper_raise_exception(env
, TT_ILL_INSN
);
2027 case ASI_DCACHE_DATA
: /* D-cache data */
2028 case ASI_DCACHE_TAG
: /* D-cache tag access */
2029 case ASI_ESTATE_ERROR_EN
: /* E-cache error enable */
2030 case ASI_AFSR
: /* E-cache asynchronous fault status */
2031 case ASI_AFAR
: /* E-cache asynchronous fault address */
2032 case ASI_EC_TAG_DATA
: /* E-cache tag data */
2033 case ASI_IC_INSTR
: /* I-cache instruction access */
2034 case ASI_IC_TAG
: /* I-cache tag access */
2035 case ASI_IC_PRE_DECODE
: /* I-cache predecode */
2036 case ASI_IC_NEXT_FIELD
: /* I-cache LRU etc. */
2037 case ASI_EC_W
: /* E-cache tag */
2038 case ASI_EC_R
: /* E-cache tag */
2040 case ASI_IMMU_TSB_8KB_PTR
: /* I-MMU 8k TSB pointer, RO */
2041 case ASI_IMMU_TSB_64KB_PTR
: /* I-MMU 64k TSB pointer, RO */
2042 case ASI_ITLB_TAG_READ
: /* I-MMU tag read, RO */
2043 case ASI_DMMU_TSB_8KB_PTR
: /* D-MMU 8k TSB pointer, RO */
2044 case ASI_DMMU_TSB_64KB_PTR
: /* D-MMU 64k TSB pointer, RO */
2045 case ASI_DMMU_TSB_DIRECT_PTR
: /* D-MMU data pointer, RO */
2046 case ASI_DTLB_TAG_READ
: /* D-MMU tag read, RO */
2047 case ASI_INTR_DISPATCH_STAT
: /* Interrupt dispatch, RO */
2048 case ASI_INTR_R
: /* Incoming interrupt vector, RO */
2049 case ASI_PNF
: /* Primary no-fault, RO */
2050 case ASI_SNF
: /* Secondary no-fault, RO */
2051 case ASI_PNFL
: /* Primary no-fault LE, RO */
2052 case ASI_SNFL
: /* Secondary no-fault LE, RO */
2054 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
2058 #endif /* CONFIG_USER_ONLY */
2060 /* 128-bit LDDA; result returned in QT0. */
2061 void helper_ldda_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
)
2065 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2066 || (cpu_has_hypervisor(env
)
2067 && asi
>= 0x30 && asi
< 0x80
2068 && !(env
->hpstate
& HS_PRIV
))) {
2069 helper_raise_exception(env
, TT_PRIV_ACT
);
2072 addr
= asi_address_mask(env
, asi
, addr
);
2075 #if !defined(CONFIG_USER_ONLY)
2076 case ASI_TWINX_AIUP
: /* As if user primary, twinx */
2077 case ASI_TWINX_AIUP_L
: /* As if user primary, twinx, LE */
2078 helper_check_align(env
, addr
, 0xf);
2079 h
= cpu_ldq_user(env
, addr
);
2080 l
= cpu_ldq_user(env
, addr
+ 8);
2082 case ASI_TWINX_AIUS
: /* As if user secondary, twinx */
2083 case ASI_TWINX_AIUS_L
: /* As if user secondary, twinx, LE */
2084 helper_check_align(env
, addr
, 0xf);
2085 h
= cpu_ldq_user_secondary(env
, addr
);
2086 l
= cpu_ldq_user_secondary(env
, addr
+ 8);
2088 case ASI_TWINX_REAL
: /* Real address, twinx */
2089 case ASI_TWINX_REAL_L
: /* Real address, twinx, LE */
2090 helper_check_align(env
, addr
, 0xf);
2092 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
2093 h
= ldq_phys(cs
->as
, addr
);
2094 l
= ldq_phys(cs
->as
, addr
+ 8);
2097 case ASI_NUCLEUS_QUAD_LDD
:
2098 case ASI_NUCLEUS_QUAD_LDD_L
:
2099 case ASI_TWINX_N
: /* Nucleus, twinx */
2100 case ASI_TWINX_NL
: /* Nucleus, twinx, LE */
2101 helper_check_align(env
, addr
, 0xf);
2102 h
= cpu_ldq_nucleus(env
, addr
);
2103 l
= cpu_ldq_nucleus(env
, addr
+ 8);
2105 case ASI_TWINX_S
: /* Secondary, twinx */
2106 case ASI_TWINX_SL
: /* Secondary, twinx, LE */
2107 if (!cpu_hypervisor_mode(env
)) {
2108 helper_check_align(env
, addr
, 0xf);
2109 if (env
->pstate
& PS_PRIV
) {
2110 h
= cpu_ldq_kernel_secondary(env
, addr
);
2111 l
= cpu_ldq_kernel_secondary(env
, addr
+ 8);
2113 h
= cpu_ldq_user_secondary(env
, addr
);
2114 l
= cpu_ldq_user_secondary(env
, addr
+ 8);
2119 case ASI_TWINX_P
: /* Primary, twinx */
2120 case ASI_TWINX_PL
: /* Primary, twinx, LE */
2121 helper_check_align(env
, addr
, 0xf);
2122 h
= cpu_ldq_data(env
, addr
);
2123 l
= cpu_ldq_data(env
, addr
+ 8);
2126 case ASI_TWINX_P
: /* Primary, twinx */
2127 case ASI_TWINX_PL
: /* Primary, twinx, LE */
2128 case ASI_TWINX_S
: /* Primary, twinx */
2129 case ASI_TWINX_SL
: /* Primary, twinx, LE */
2130 /* ??? Should be available, but we need to implement
2131 an atomic 128-bit load. */
2132 helper_raise_exception(env
, TT_PRIV_ACT
);
2135 /* Non-twinx asi, so this is the legacy ldda insn, which
2136 performs two word sized operations. */
2137 /* ??? The UA2011 manual recommends emulating this with
2138 a single 64-bit load. However, LE asis *are* treated
2139 as two 32-bit loads individually byte swapped. */
2140 helper_check_align(env
, addr
, 0x7);
2141 QT0
.high
= (uint32_t)helper_ld_asi(env
, addr
, asi
, 4, 0);
2142 QT0
.low
= (uint32_t)helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2154 void helper_ldf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2160 helper_check_align(env
, addr
, 3);
2161 addr
= asi_address_mask(env
, asi
, addr
);
2164 case ASI_BLK_P
: /* UA2007/JPS1 Block load primary */
2165 case ASI_BLK_S
: /* UA2007/JPS1 Block load secondary */
2166 case ASI_BLK_PL
: /* UA2007/JPS1 Block load primary LE */
2167 case ASI_BLK_SL
: /* UA2007/JPS1 Block load secondary LE */
2169 helper_raise_exception(env
, TT_ILL_INSN
);
2172 helper_check_align(env
, addr
, 0x3f);
2173 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2174 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x8f, 8, 0);
2178 case ASI_BLK_AIUP_4V
: /* UA2007 Block load primary, user privilege */
2179 case ASI_BLK_AIUS_4V
: /* UA2007 Block load secondary, user privilege */
2180 case ASI_BLK_AIUP_L_4V
: /* UA2007 Block load primary LE, user privilege */
2181 case ASI_BLK_AIUS_L_4V
: /* UA2007 Block load secondary LE, user privilege */
2182 case ASI_BLK_AIUP
: /* JPS1 Block load primary, user privilege */
2183 case ASI_BLK_AIUS
: /* JPS1 Block load secondary, user privilege */
2184 case ASI_BLK_AIUPL
: /* JPS1 Block load primary LE, user privilege */
2185 case ASI_BLK_AIUSL
: /* JPS1 Block load secondary LE, user privilege */
2187 helper_raise_exception(env
, TT_ILL_INSN
);
2190 helper_check_align(env
, addr
, 0x3f);
2191 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2192 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x19, 8, 0);
2203 val
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2205 env
->fpr
[rd
/ 2].l
.lower
= val
;
2207 env
->fpr
[rd
/ 2].l
.upper
= val
;
2211 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2214 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2215 env
->fpr
[rd
/ 2 + 1].ll
= helper_ld_asi(env
, addr
+ 8, asi
, 8, 0);
2220 void helper_stf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2226 addr
= asi_address_mask(env
, asi
, addr
);
2229 case ASI_BLK_COMMIT_P
: /* UA2007/JPS1 Block store primary (cache flush) */
2230 case ASI_BLK_COMMIT_S
: /* UA2007/JPS1 Block store secondary (cache flush) */
2231 case ASI_BLK_P
: /* UA2007/JPS1 Block store primary */
2232 case ASI_BLK_S
: /* UA2007/JPS1 Block store secondary */
2233 case ASI_BLK_PL
: /* UA2007/JPS1 Block store primary LE */
2234 case ASI_BLK_SL
: /* UA2007/JPS1 Block store secondary LE */
2236 helper_raise_exception(env
, TT_ILL_INSN
);
2239 helper_check_align(env
, addr
, 0x3f);
2240 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2241 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x8f, 8);
2245 case ASI_BLK_AIUP_4V
: /* UA2007 Block load primary, user privilege */
2246 case ASI_BLK_AIUS_4V
: /* UA2007 Block load secondary, user privilege */
2247 case ASI_BLK_AIUP_L_4V
: /* UA2007 Block load primary LE, user privilege */
2248 case ASI_BLK_AIUS_L_4V
: /* UA2007 Block load secondary LE, user privilege */
2249 case ASI_BLK_AIUP
: /* JPS1 Block store primary, user privilege */
2250 case ASI_BLK_AIUS
: /* JPS1 Block store secondary, user privilege */
2251 case ASI_BLK_AIUPL
: /* JPS1 Block load primary LE, user privilege */
2252 case ASI_BLK_AIUSL
: /* JPS1 Block load secondary LE, user privilege */
2254 helper_raise_exception(env
, TT_ILL_INSN
);
2257 helper_check_align(env
, addr
, 0x3f);
2258 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2259 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x19, 8);
2263 case ASI_FL16_P
: /* 16-bit floating point load primary */
2264 case ASI_FL16_S
: /* 16-bit floating point load secondary */
2265 case ASI_FL16_PL
: /* 16-bit floating point load primary, LE */
2266 case ASI_FL16_SL
: /* 16-bit floating point load secondary, LE */
2267 helper_check_align(env
, addr
, 1);
2269 case ASI_FL8_P
: /* 8-bit floating point load primary */
2270 case ASI_FL8_S
: /* 8-bit floating point load secondary */
2271 case ASI_FL8_PL
: /* 8-bit floating point load primary, LE */
2272 case ASI_FL8_SL
: /* 8-bit floating point load secondary, LE */
2273 val
= env
->fpr
[rd
/ 2].l
.lower
;
2274 helper_st_asi(env
, addr
, val
, asi
& 0x8d, ((asi
& 2) >> 1) + 1);
2277 helper_check_align(env
, addr
, 3);
2285 val
= env
->fpr
[rd
/ 2].l
.lower
;
2287 val
= env
->fpr
[rd
/ 2].l
.upper
;
2289 helper_st_asi(env
, addr
, val
, asi
, size
);
2292 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, size
);
2295 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, 8);
2296 helper_st_asi(env
, addr
+ 8, env
->fpr
[rd
/ 2 + 1].ll
, asi
, 8);
2301 target_ulong
helper_casx_asi(CPUSPARCState
*env
, target_ulong addr
,
2302 target_ulong val1
, target_ulong val2
,
2307 ret
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2309 helper_st_asi(env
, addr
, val1
, asi
, 8);
2313 #endif /* TARGET_SPARC64 */
2315 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2316 target_ulong
helper_cas_asi(CPUSPARCState
*env
, target_ulong addr
,
2317 target_ulong val1
, target_ulong val2
, uint32_t asi
)
2321 val2
&= 0xffffffffUL
;
2322 ret
= helper_ld_asi(env
, addr
, asi
, 4, 0);
2323 ret
&= 0xffffffffUL
;
2325 helper_st_asi(env
, addr
, val1
& 0xffffffffUL
, asi
, 4);
2329 #endif /* !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) */
2331 void helper_ldqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2333 /* XXX add 128 bit load */
2336 helper_check_align(env
, addr
, 7);
2337 #if !defined(CONFIG_USER_ONLY)
2340 u
.ll
.upper
= cpu_ldq_user(env
, addr
);
2341 u
.ll
.lower
= cpu_ldq_user(env
, addr
+ 8);
2344 case MMU_KERNEL_IDX
:
2345 u
.ll
.upper
= cpu_ldq_kernel(env
, addr
);
2346 u
.ll
.lower
= cpu_ldq_kernel(env
, addr
+ 8);
2349 #ifdef TARGET_SPARC64
2351 u
.ll
.upper
= cpu_ldq_hypv(env
, addr
);
2352 u
.ll
.lower
= cpu_ldq_hypv(env
, addr
+ 8);
2357 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
2361 u
.ll
.upper
= cpu_ldq_data(env
, address_mask(env
, addr
));
2362 u
.ll
.lower
= cpu_ldq_data(env
, address_mask(env
, addr
+ 8));
2367 void helper_stqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2369 /* XXX add 128 bit store */
2372 helper_check_align(env
, addr
, 7);
2373 #if !defined(CONFIG_USER_ONLY)
2377 cpu_stq_user(env
, addr
, u
.ll
.upper
);
2378 cpu_stq_user(env
, addr
+ 8, u
.ll
.lower
);
2380 case MMU_KERNEL_IDX
:
2382 cpu_stq_kernel(env
, addr
, u
.ll
.upper
);
2383 cpu_stq_kernel(env
, addr
+ 8, u
.ll
.lower
);
2385 #ifdef TARGET_SPARC64
2388 cpu_stq_hypv(env
, addr
, u
.ll
.upper
);
2389 cpu_stq_hypv(env
, addr
+ 8, u
.ll
.lower
);
2393 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
2398 cpu_stq_data(env
, address_mask(env
, addr
), u
.ll
.upper
);
2399 cpu_stq_data(env
, address_mask(env
, addr
+ 8), u
.ll
.lower
);
2403 #if !defined(CONFIG_USER_ONLY)
2404 #ifndef TARGET_SPARC64
2405 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2406 bool is_write
, bool is_exec
, int is_asi
,
2409 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2410 CPUSPARCState
*env
= &cpu
->env
;
2413 #ifdef DEBUG_UNASSIGNED
2415 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2416 " asi 0x%02x from " TARGET_FMT_lx
"\n",
2417 is_exec
? "exec" : is_write
? "write" : "read", size
,
2418 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
2420 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2421 " from " TARGET_FMT_lx
"\n",
2422 is_exec
? "exec" : is_write
? "write" : "read", size
,
2423 size
== 1 ? "" : "s", addr
, env
->pc
);
2426 /* Don't overwrite translation and access faults */
2427 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
2428 if ((fault_type
> 4) || (fault_type
== 0)) {
2429 env
->mmuregs
[3] = 0; /* Fault status register */
2431 env
->mmuregs
[3] |= 1 << 16;
2434 env
->mmuregs
[3] |= 1 << 5;
2437 env
->mmuregs
[3] |= 1 << 6;
2440 env
->mmuregs
[3] |= 1 << 7;
2442 env
->mmuregs
[3] |= (5 << 2) | 2;
2443 /* SuperSPARC will never place instruction fault addresses in the FAR */
2445 env
->mmuregs
[4] = addr
; /* Fault address register */
2448 /* overflow (same type fault was not read before another fault) */
2449 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
2450 env
->mmuregs
[3] |= 1;
2453 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2455 helper_raise_exception(env
, TT_CODE_ACCESS
);
2457 helper_raise_exception(env
, TT_DATA_ACCESS
);
2461 /* flush neverland mappings created during no-fault mode,
2462 so the sequential MMU faults report proper fault types */
2463 if (env
->mmuregs
[0] & MMU_NF
) {
2468 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2469 bool is_write
, bool is_exec
, int is_asi
,
2472 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2473 CPUSPARCState
*env
= &cpu
->env
;
2475 #ifdef DEBUG_UNASSIGNED
2476 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
2477 "\n", addr
, env
->pc
);
2481 helper_raise_exception(env
, TT_CODE_ACCESS
);
2483 helper_raise_exception(env
, TT_DATA_ACCESS
);
2489 #if !defined(CONFIG_USER_ONLY)
2490 void QEMU_NORETURN
sparc_cpu_do_unaligned_access(CPUState
*cs
, vaddr addr
,
2491 MMUAccessType access_type
,
2495 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2496 CPUSPARCState
*env
= &cpu
->env
;
2498 #ifdef DEBUG_UNALIGNED
2499 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
2500 "\n", addr
, env
->pc
);
2503 cpu_restore_state(CPU(cpu
), retaddr
);
2505 helper_raise_exception(env
, TT_UNALIGNED
);
2508 /* try to fill the TLB and return an exception if error. If retaddr is
2509 NULL, it means that the function was called in C code (i.e. not
2510 from generated code or from helper.c) */
2511 /* XXX: fix it to restore all registers */
2512 void tlb_fill(CPUState
*cs
, target_ulong addr
, MMUAccessType access_type
,
2513 int mmu_idx
, uintptr_t retaddr
)
2517 ret
= sparc_cpu_handle_mmu_fault(cs
, addr
, access_type
, mmu_idx
);
2520 cpu_restore_state(cs
, retaddr
);