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"
28 //#define DEBUG_UNALIGNED
29 //#define DEBUG_UNASSIGNED
31 //#define DEBUG_CACHE_CONTROL
34 #define DPRINTF_MMU(fmt, ...) \
35 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
37 #define DPRINTF_MMU(fmt, ...) do {} while (0)
41 #define DPRINTF_MXCC(fmt, ...) \
42 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
44 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
48 #define DPRINTF_ASI(fmt, ...) \
49 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
52 #ifdef DEBUG_CACHE_CONTROL
53 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
54 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
56 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
61 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
63 #define AM_CHECK(env1) (1)
67 #define QT0 (env->qt0)
68 #define QT1 (env->qt1)
70 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
71 /* Calculates TSB pointer value for fault page size 8k or 64k */
72 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register
,
73 uint64_t tag_access_register
,
76 uint64_t tsb_base
= tsb_register
& ~0x1fffULL
;
77 int tsb_split
= (tsb_register
& 0x1000ULL
) ? 1 : 0;
78 int tsb_size
= tsb_register
& 0xf;
80 /* discard lower 13 bits which hold tag access context */
81 uint64_t tag_access_va
= tag_access_register
& ~0x1fffULL
;
83 /* now reorder bits */
84 uint64_t tsb_base_mask
= ~0x1fffULL
;
85 uint64_t va
= tag_access_va
;
87 /* move va bits to correct position */
88 if (page_size
== 8*1024) {
90 } else if (page_size
== 64*1024) {
95 tsb_base_mask
<<= tsb_size
;
98 /* calculate tsb_base mask and adjust va if split is in use */
100 if (page_size
== 8*1024) {
101 va
&= ~(1ULL << (13 + tsb_size
));
102 } else if (page_size
== 64*1024) {
103 va
|= (1ULL << (13 + tsb_size
));
108 return ((tsb_base
& tsb_base_mask
) | (va
& ~tsb_base_mask
)) & ~0xfULL
;
111 /* Calculates tag target register value by reordering bits
112 in tag access register */
113 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register
)
115 return ((tag_access_register
& 0x1fff) << 48) | (tag_access_register
>> 22);
118 static void replace_tlb_entry(SparcTLBEntry
*tlb
,
119 uint64_t tlb_tag
, uint64_t tlb_tte
,
122 target_ulong mask
, size
, va
, offset
;
124 /* flush page range if translation is valid */
125 if (TTE_IS_VALID(tlb
->tte
)) {
126 CPUState
*cs
= CPU(sparc_env_get_cpu(env1
));
128 mask
= 0xffffffffffffe000ULL
;
129 mask
<<= 3 * ((tlb
->tte
>> 61) & 3);
132 va
= tlb
->tag
& mask
;
134 for (offset
= 0; offset
< size
; offset
+= TARGET_PAGE_SIZE
) {
135 tlb_flush_page(cs
, va
+ offset
);
143 static void demap_tlb(SparcTLBEntry
*tlb
, target_ulong demap_addr
,
144 const char *strmmu
, CPUSPARCState
*env1
)
150 int is_demap_context
= (demap_addr
>> 6) & 1;
153 switch ((demap_addr
>> 4) & 3) {
154 case 0: /* primary */
155 context
= env1
->dmmu
.mmu_primary_context
;
157 case 1: /* secondary */
158 context
= env1
->dmmu
.mmu_secondary_context
;
160 case 2: /* nucleus */
163 case 3: /* reserved */
168 for (i
= 0; i
< 64; i
++) {
169 if (TTE_IS_VALID(tlb
[i
].tte
)) {
171 if (is_demap_context
) {
172 /* will remove non-global entries matching context value */
173 if (TTE_IS_GLOBAL(tlb
[i
].tte
) ||
174 !tlb_compare_context(&tlb
[i
], context
)) {
179 will remove any entry matching VA */
180 mask
= 0xffffffffffffe000ULL
;
181 mask
<<= 3 * ((tlb
[i
].tte
>> 61) & 3);
183 if (!compare_masked(demap_addr
, tlb
[i
].tag
, mask
)) {
187 /* entry should be global or matching context value */
188 if (!TTE_IS_GLOBAL(tlb
[i
].tte
) &&
189 !tlb_compare_context(&tlb
[i
], context
)) {
194 replace_tlb_entry(&tlb
[i
], 0, 0, env1
);
196 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu
, i
);
197 dump_mmu(stdout
, fprintf
, env1
);
203 static void replace_tlb_1bit_lru(SparcTLBEntry
*tlb
,
204 uint64_t tlb_tag
, uint64_t tlb_tte
,
205 const char *strmmu
, CPUSPARCState
*env1
)
207 unsigned int i
, replace_used
;
209 /* Try replacing invalid entry */
210 for (i
= 0; i
< 64; i
++) {
211 if (!TTE_IS_VALID(tlb
[i
].tte
)) {
212 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
214 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu
, i
);
215 dump_mmu(stdout
, fprintf
, env1
);
221 /* All entries are valid, try replacing unlocked entry */
223 for (replace_used
= 0; replace_used
< 2; ++replace_used
) {
225 /* Used entries are not replaced on first pass */
227 for (i
= 0; i
< 64; i
++) {
228 if (!TTE_IS_LOCKED(tlb
[i
].tte
) && !TTE_IS_USED(tlb
[i
].tte
)) {
230 replace_tlb_entry(&tlb
[i
], tlb_tag
, tlb_tte
, env1
);
232 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
233 strmmu
, (replace_used
? "used" : "unused"), i
);
234 dump_mmu(stdout
, fprintf
, env1
);
240 /* Now reset used bit and search for unused entries again */
242 for (i
= 0; i
< 64; i
++) {
243 TTE_SET_UNUSED(tlb
[i
].tte
);
248 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu
);
255 #if defined(TARGET_SPARC64) || defined(CONFIG_USER_ONLY)
256 static inline target_ulong
address_mask(CPUSPARCState
*env1
, target_ulong addr
)
258 #ifdef TARGET_SPARC64
259 if (AM_CHECK(env1
)) {
260 addr
&= 0xffffffffULL
;
267 #ifdef TARGET_SPARC64
268 /* returns true if access using this ASI is to have address translated by MMU
269 otherwise access is to raw physical address */
270 /* TODO: check sparc32 bits */
271 static inline int is_translating_asi(int asi
)
273 /* Ultrasparc IIi translating asi
274 - note this list is defined by cpu implementation
291 static inline target_ulong
asi_address_mask(CPUSPARCState
*env
,
292 int asi
, target_ulong addr
)
294 if (is_translating_asi(asi
)) {
295 return address_mask(env
, addr
);
302 void helper_check_align(CPUSPARCState
*env
, target_ulong addr
, uint32_t align
)
305 #ifdef DEBUG_UNALIGNED
306 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
307 "\n", addr
, env
->pc
);
309 helper_raise_exception(env
, TT_UNALIGNED
);
313 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
315 static void dump_mxcc(CPUSPARCState
*env
)
317 printf("mxccdata: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
319 env
->mxccdata
[0], env
->mxccdata
[1],
320 env
->mxccdata
[2], env
->mxccdata
[3]);
321 printf("mxccregs: %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
323 " %016" PRIx64
" %016" PRIx64
" %016" PRIx64
" %016" PRIx64
325 env
->mxccregs
[0], env
->mxccregs
[1],
326 env
->mxccregs
[2], env
->mxccregs
[3],
327 env
->mxccregs
[4], env
->mxccregs
[5],
328 env
->mxccregs
[6], env
->mxccregs
[7]);
332 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
333 && defined(DEBUG_ASI)
334 static void dump_asi(const char *txt
, target_ulong addr
, int asi
, int size
,
339 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %02" PRIx64
"\n", txt
,
340 addr
, asi
, r1
& 0xff);
343 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %04" PRIx64
"\n", txt
,
344 addr
, asi
, r1
& 0xffff);
347 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %08" PRIx64
"\n", txt
,
348 addr
, asi
, r1
& 0xffffffff);
351 DPRINTF_ASI("%s "TARGET_FMT_lx
" asi 0x%02x = %016" PRIx64
"\n", txt
,
358 #ifndef TARGET_SPARC64
359 #ifndef CONFIG_USER_ONLY
362 /* Leon3 cache control */
364 static void leon3_cache_control_st(CPUSPARCState
*env
, target_ulong addr
,
365 uint64_t val
, int size
)
367 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64
", size:%d\n",
371 DPRINTF_CACHE_CONTROL("32bits only\n");
376 case 0x00: /* Cache control */
378 /* These values must always be read as zeros */
379 val
&= ~CACHE_CTRL_FD
;
380 val
&= ~CACHE_CTRL_FI
;
381 val
&= ~CACHE_CTRL_IB
;
382 val
&= ~CACHE_CTRL_IP
;
383 val
&= ~CACHE_CTRL_DP
;
385 env
->cache_control
= val
;
387 case 0x04: /* Instruction cache configuration */
388 case 0x08: /* Data cache configuration */
392 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr
);
397 static uint64_t leon3_cache_control_ld(CPUSPARCState
*env
, target_ulong addr
,
403 DPRINTF_CACHE_CONTROL("32bits only\n");
408 case 0x00: /* Cache control */
409 ret
= env
->cache_control
;
412 /* Configuration registers are read and only always keep those
415 case 0x04: /* Instruction cache configuration */
418 case 0x08: /* Data cache configuration */
422 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr
);
425 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64
", size:%d\n",
430 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
433 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
435 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
436 uint32_t last_addr
= addr
;
439 helper_check_align(env
, addr
, size
- 1);
441 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
443 case 0x00: /* Leon3 Cache Control */
444 case 0x08: /* Leon3 Instruction Cache config */
445 case 0x0C: /* Leon3 Date Cache config */
446 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
447 ret
= leon3_cache_control_ld(env
, addr
, size
);
450 case 0x01c00a00: /* MXCC control register */
452 ret
= env
->mxccregs
[3];
454 qemu_log_mask(LOG_UNIMP
,
455 "%08x: unimplemented access size: %d\n", addr
,
459 case 0x01c00a04: /* MXCC control register */
461 ret
= env
->mxccregs
[3];
463 qemu_log_mask(LOG_UNIMP
,
464 "%08x: unimplemented access size: %d\n", addr
,
468 case 0x01c00c00: /* Module reset register */
470 ret
= env
->mxccregs
[5];
471 /* should we do something here? */
473 qemu_log_mask(LOG_UNIMP
,
474 "%08x: unimplemented access size: %d\n", addr
,
478 case 0x01c00f00: /* MBus port address register */
480 ret
= env
->mxccregs
[7];
482 qemu_log_mask(LOG_UNIMP
,
483 "%08x: unimplemented access size: %d\n", addr
,
488 qemu_log_mask(LOG_UNIMP
,
489 "%08x: unimplemented address, size: %d\n", addr
,
493 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
494 "addr = %08x -> ret = %" PRIx64
","
495 "addr = %08x\n", asi
, size
, sign
, last_addr
, ret
, addr
);
500 case 3: /* MMU probe */
501 case 0x18: /* LEON3 MMU probe */
505 mmulev
= (addr
>> 8) & 15;
509 ret
= mmu_probe(env
, addr
, mmulev
);
511 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64
"\n",
515 case 4: /* read MMU regs */
516 case 0x19: /* LEON3 read MMU regs */
518 int reg
= (addr
>> 8) & 0x1f;
520 ret
= env
->mmuregs
[reg
];
521 if (reg
== 3) { /* Fault status cleared on read */
523 } else if (reg
== 0x13) { /* Fault status read */
524 ret
= env
->mmuregs
[3];
525 } else if (reg
== 0x14) { /* Fault address read */
526 ret
= env
->mmuregs
[4];
528 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64
"\n", reg
, ret
);
531 case 5: /* Turbosparc ITLB Diagnostic */
532 case 6: /* Turbosparc DTLB Diagnostic */
533 case 7: /* Turbosparc IOTLB Diagnostic */
535 case 9: /* Supervisor code access */
538 ret
= cpu_ldub_code(env
, addr
);
541 ret
= cpu_lduw_code(env
, addr
);
545 ret
= cpu_ldl_code(env
, addr
);
548 ret
= cpu_ldq_code(env
, addr
);
552 case 0xa: /* User data access */
555 ret
= cpu_ldub_user(env
, addr
);
558 ret
= cpu_lduw_user(env
, addr
);
562 ret
= cpu_ldl_user(env
, addr
);
565 ret
= cpu_ldq_user(env
, addr
);
569 case 0xb: /* Supervisor data access */
573 ret
= cpu_ldub_kernel(env
, addr
);
576 ret
= cpu_lduw_kernel(env
, addr
);
580 ret
= cpu_ldl_kernel(env
, addr
);
583 ret
= cpu_ldq_kernel(env
, addr
);
587 case 0xc: /* I-cache tag */
588 case 0xd: /* I-cache data */
589 case 0xe: /* D-cache tag */
590 case 0xf: /* D-cache data */
592 case 0x20: /* MMU passthrough */
593 case 0x1c: /* LEON MMU passthrough */
596 ret
= ldub_phys(cs
->as
, addr
);
599 ret
= lduw_phys(cs
->as
, addr
);
603 ret
= ldl_phys(cs
->as
, addr
);
606 ret
= ldq_phys(cs
->as
, addr
);
610 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
613 ret
= ldub_phys(cs
->as
, (hwaddr
)addr
614 | ((hwaddr
)(asi
& 0xf) << 32));
617 ret
= lduw_phys(cs
->as
, (hwaddr
)addr
618 | ((hwaddr
)(asi
& 0xf) << 32));
622 ret
= ldl_phys(cs
->as
, (hwaddr
)addr
623 | ((hwaddr
)(asi
& 0xf) << 32));
626 ret
= ldq_phys(cs
->as
, (hwaddr
)addr
627 | ((hwaddr
)(asi
& 0xf) << 32));
631 case 0x30: /* Turbosparc secondary cache diagnostic */
632 case 0x31: /* Turbosparc RAM snoop */
633 case 0x32: /* Turbosparc page table descriptor diagnostic */
634 case 0x39: /* data cache diagnostic register */
637 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
639 int reg
= (addr
>> 8) & 3;
642 case 0: /* Breakpoint Value (Addr) */
643 ret
= env
->mmubpregs
[reg
];
645 case 1: /* Breakpoint Mask */
646 ret
= env
->mmubpregs
[reg
];
648 case 2: /* Breakpoint Control */
649 ret
= env
->mmubpregs
[reg
];
651 case 3: /* Breakpoint Status */
652 ret
= env
->mmubpregs
[reg
];
653 env
->mmubpregs
[reg
] = 0ULL;
656 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64
"\n", reg
,
660 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
661 ret
= env
->mmubpctrv
;
663 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
664 ret
= env
->mmubpctrc
;
666 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
667 ret
= env
->mmubpctrs
;
669 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
670 ret
= env
->mmubpaction
;
672 case 8: /* User code access, XXX */
674 cpu_unassigned_access(cs
, addr
, false, false, asi
, size
);
694 dump_asi("read ", last_addr
, asi
, size
, ret
);
699 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, uint64_t val
, int asi
,
702 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
703 CPUState
*cs
= CPU(cpu
);
705 helper_check_align(env
, addr
, size
- 1);
707 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
709 case 0x00: /* Leon3 Cache Control */
710 case 0x08: /* Leon3 Instruction Cache config */
711 case 0x0C: /* Leon3 Date Cache config */
712 if (env
->def
->features
& CPU_FEATURE_CACHE_CTRL
) {
713 leon3_cache_control_st(env
, addr
, val
, size
);
717 case 0x01c00000: /* MXCC stream data register 0 */
719 env
->mxccdata
[0] = val
;
721 qemu_log_mask(LOG_UNIMP
,
722 "%08x: unimplemented access size: %d\n", addr
,
726 case 0x01c00008: /* MXCC stream data register 1 */
728 env
->mxccdata
[1] = val
;
730 qemu_log_mask(LOG_UNIMP
,
731 "%08x: unimplemented access size: %d\n", addr
,
735 case 0x01c00010: /* MXCC stream data register 2 */
737 env
->mxccdata
[2] = val
;
739 qemu_log_mask(LOG_UNIMP
,
740 "%08x: unimplemented access size: %d\n", addr
,
744 case 0x01c00018: /* MXCC stream data register 3 */
746 env
->mxccdata
[3] = val
;
748 qemu_log_mask(LOG_UNIMP
,
749 "%08x: unimplemented access size: %d\n", addr
,
753 case 0x01c00100: /* MXCC stream source */
755 env
->mxccregs
[0] = val
;
757 qemu_log_mask(LOG_UNIMP
,
758 "%08x: unimplemented access size: %d\n", addr
,
761 env
->mxccdata
[0] = ldq_phys(cs
->as
,
762 (env
->mxccregs
[0] & 0xffffffffULL
) +
764 env
->mxccdata
[1] = ldq_phys(cs
->as
,
765 (env
->mxccregs
[0] & 0xffffffffULL
) +
767 env
->mxccdata
[2] = ldq_phys(cs
->as
,
768 (env
->mxccregs
[0] & 0xffffffffULL
) +
770 env
->mxccdata
[3] = ldq_phys(cs
->as
,
771 (env
->mxccregs
[0] & 0xffffffffULL
) +
774 case 0x01c00200: /* MXCC stream destination */
776 env
->mxccregs
[1] = val
;
778 qemu_log_mask(LOG_UNIMP
,
779 "%08x: unimplemented access size: %d\n", addr
,
782 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 0,
784 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 8,
786 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 16,
788 stq_phys(cs
->as
, (env
->mxccregs
[1] & 0xffffffffULL
) + 24,
791 case 0x01c00a00: /* MXCC control register */
793 env
->mxccregs
[3] = val
;
795 qemu_log_mask(LOG_UNIMP
,
796 "%08x: unimplemented access size: %d\n", addr
,
800 case 0x01c00a04: /* MXCC control register */
802 env
->mxccregs
[3] = (env
->mxccregs
[3] & 0xffffffff00000000ULL
)
805 qemu_log_mask(LOG_UNIMP
,
806 "%08x: unimplemented access size: %d\n", addr
,
810 case 0x01c00e00: /* MXCC error register */
811 /* writing a 1 bit clears the error */
813 env
->mxccregs
[6] &= ~val
;
815 qemu_log_mask(LOG_UNIMP
,
816 "%08x: unimplemented access size: %d\n", addr
,
820 case 0x01c00f00: /* MBus port address register */
822 env
->mxccregs
[7] = val
;
824 qemu_log_mask(LOG_UNIMP
,
825 "%08x: unimplemented access size: %d\n", addr
,
830 qemu_log_mask(LOG_UNIMP
,
831 "%08x: unimplemented address, size: %d\n", addr
,
835 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64
"\n",
836 asi
, size
, addr
, val
);
841 case 3: /* MMU flush */
842 case 0x18: /* LEON3 MMU flush */
846 mmulev
= (addr
>> 8) & 15;
847 DPRINTF_MMU("mmu flush level %d\n", mmulev
);
849 case 0: /* flush page */
850 tlb_flush_page(CPU(cpu
), addr
& 0xfffff000);
852 case 1: /* flush segment (256k) */
853 case 2: /* flush region (16M) */
854 case 3: /* flush context (4G) */
855 case 4: /* flush entire */
856 tlb_flush(CPU(cpu
), 1);
862 dump_mmu(stdout
, fprintf
, env
);
866 case 4: /* write MMU regs */
867 case 0x19: /* LEON3 write MMU regs */
869 int reg
= (addr
>> 8) & 0x1f;
872 oldreg
= env
->mmuregs
[reg
];
874 case 0: /* Control Register */
875 env
->mmuregs
[reg
] = (env
->mmuregs
[reg
] & 0xff000000) |
877 /* Mappings generated during no-fault mode or MMU
878 disabled mode are invalid in normal mode */
879 if ((oldreg
& (MMU_E
| MMU_NF
| env
->def
->mmu_bm
)) !=
880 (env
->mmuregs
[reg
] & (MMU_E
| MMU_NF
| env
->def
->mmu_bm
))) {
881 tlb_flush(CPU(cpu
), 1);
884 case 1: /* Context Table Pointer Register */
885 env
->mmuregs
[reg
] = val
& env
->def
->mmu_ctpr_mask
;
887 case 2: /* Context Register */
888 env
->mmuregs
[reg
] = val
& env
->def
->mmu_cxr_mask
;
889 if (oldreg
!= env
->mmuregs
[reg
]) {
890 /* we flush when the MMU context changes because
891 QEMU has no MMU context support */
892 tlb_flush(CPU(cpu
), 1);
895 case 3: /* Synchronous Fault Status Register with Clear */
896 case 4: /* Synchronous Fault Address Register */
898 case 0x10: /* TLB Replacement Control Register */
899 env
->mmuregs
[reg
] = val
& env
->def
->mmu_trcr_mask
;
901 case 0x13: /* Synchronous Fault Status Register with Read
903 env
->mmuregs
[3] = val
& env
->def
->mmu_sfsr_mask
;
905 case 0x14: /* Synchronous Fault Address Register */
906 env
->mmuregs
[4] = val
;
909 env
->mmuregs
[reg
] = val
;
912 if (oldreg
!= env
->mmuregs
[reg
]) {
913 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
914 reg
, oldreg
, env
->mmuregs
[reg
]);
917 dump_mmu(stdout
, fprintf
, env
);
921 case 5: /* Turbosparc ITLB Diagnostic */
922 case 6: /* Turbosparc DTLB Diagnostic */
923 case 7: /* Turbosparc IOTLB Diagnostic */
925 case 0xa: /* User data access */
928 cpu_stb_user(env
, addr
, val
);
931 cpu_stw_user(env
, addr
, val
);
935 cpu_stl_user(env
, addr
, val
);
938 cpu_stq_user(env
, addr
, val
);
942 case 0xb: /* Supervisor data access */
946 cpu_stb_kernel(env
, addr
, val
);
949 cpu_stw_kernel(env
, addr
, val
);
953 cpu_stl_kernel(env
, addr
, val
);
956 cpu_stq_kernel(env
, addr
, val
);
960 case 0xc: /* I-cache tag */
961 case 0xd: /* I-cache data */
962 case 0xe: /* D-cache tag */
963 case 0xf: /* D-cache data */
964 case 0x10: /* I/D-cache flush page */
965 case 0x11: /* I/D-cache flush segment */
966 case 0x12: /* I/D-cache flush region */
967 case 0x13: /* I/D-cache flush context */
968 case 0x14: /* I/D-cache flush user */
970 case 0x17: /* Block copy, sta access */
976 uint32_t src
= val
& ~3, dst
= addr
& ~3, temp
;
978 for (i
= 0; i
< 32; i
+= 4, src
+= 4, dst
+= 4) {
979 temp
= cpu_ldl_kernel(env
, src
);
980 cpu_stl_kernel(env
, dst
, temp
);
984 case 0x1f: /* Block fill, stda access */
987 fill 32 bytes with val */
989 uint32_t dst
= addr
& 7;
991 for (i
= 0; i
< 32; i
+= 8, dst
+= 8) {
992 cpu_stq_kernel(env
, dst
, val
);
996 case 0x20: /* MMU passthrough */
997 case 0x1c: /* LEON MMU passthrough */
1001 stb_phys(cs
->as
, addr
, val
);
1004 stw_phys(cs
->as
, addr
, val
);
1008 stl_phys(cs
->as
, addr
, val
);
1011 stq_phys(cs
->as
, addr
, val
);
1016 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1020 stb_phys(cs
->as
, (hwaddr
)addr
1021 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1024 stw_phys(cs
->as
, (hwaddr
)addr
1025 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1029 stl_phys(cs
->as
, (hwaddr
)addr
1030 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1033 stq_phys(cs
->as
, (hwaddr
)addr
1034 | ((hwaddr
)(asi
& 0xf) << 32), val
);
1039 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1040 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1041 Turbosparc snoop RAM */
1042 case 0x32: /* store buffer control or Turbosparc page table
1043 descriptor diagnostic */
1044 case 0x36: /* I-cache flash clear */
1045 case 0x37: /* D-cache flash clear */
1047 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1049 int reg
= (addr
>> 8) & 3;
1052 case 0: /* Breakpoint Value (Addr) */
1053 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1055 case 1: /* Breakpoint Mask */
1056 env
->mmubpregs
[reg
] = (val
& 0xfffffffffULL
);
1058 case 2: /* Breakpoint Control */
1059 env
->mmubpregs
[reg
] = (val
& 0x7fULL
);
1061 case 3: /* Breakpoint Status */
1062 env
->mmubpregs
[reg
] = (val
& 0xfULL
);
1065 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg
,
1069 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1070 env
->mmubpctrv
= val
& 0xffffffff;
1072 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1073 env
->mmubpctrc
= val
& 0x3;
1075 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1076 env
->mmubpctrs
= val
& 0x3;
1078 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1079 env
->mmubpaction
= val
& 0x1fff;
1081 case 8: /* User code access, XXX */
1082 case 9: /* Supervisor code access, XXX */
1084 cpu_unassigned_access(CPU(sparc_env_get_cpu(env
)),
1085 addr
, true, false, asi
, size
);
1089 dump_asi("write", addr
, asi
, size
, val
);
1093 #endif /* CONFIG_USER_ONLY */
1094 #else /* TARGET_SPARC64 */
1096 #ifdef CONFIG_USER_ONLY
1097 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1101 #if defined(DEBUG_ASI)
1102 target_ulong last_addr
= addr
;
1106 helper_raise_exception(env
, TT_PRIV_ACT
);
1109 helper_check_align(env
, addr
, size
- 1);
1110 addr
= asi_address_mask(env
, asi
, addr
);
1113 case 0x82: /* Primary no-fault */
1114 case 0x8a: /* Primary no-fault LE */
1115 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1117 dump_asi("read ", last_addr
, asi
, size
, ret
);
1122 case 0x80: /* Primary */
1123 case 0x88: /* Primary LE */
1127 ret
= cpu_ldub_data(env
, addr
);
1130 ret
= cpu_lduw_data(env
, addr
);
1133 ret
= cpu_ldl_data(env
, addr
);
1137 ret
= cpu_ldq_data(env
, addr
);
1142 case 0x83: /* Secondary no-fault */
1143 case 0x8b: /* Secondary no-fault LE */
1144 if (page_check_range(addr
, size
, PAGE_READ
) == -1) {
1146 dump_asi("read ", last_addr
, asi
, size
, ret
);
1151 case 0x81: /* Secondary */
1152 case 0x89: /* Secondary LE */
1159 /* Convert from little endian */
1161 case 0x88: /* Primary LE */
1162 case 0x89: /* Secondary LE */
1163 case 0x8a: /* Primary no-fault LE */
1164 case 0x8b: /* Secondary no-fault LE */
1182 /* Convert to signed number */
1189 ret
= (int16_t) ret
;
1192 ret
= (int32_t) ret
;
1199 dump_asi("read ", last_addr
, asi
, size
, ret
);
1204 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1208 dump_asi("write", addr
, asi
, size
, val
);
1211 helper_raise_exception(env
, TT_PRIV_ACT
);
1214 helper_check_align(env
, addr
, size
- 1);
1215 addr
= asi_address_mask(env
, asi
, addr
);
1217 /* Convert to little endian */
1219 case 0x88: /* Primary LE */
1220 case 0x89: /* Secondary LE */
1239 case 0x80: /* Primary */
1240 case 0x88: /* Primary LE */
1244 cpu_stb_data(env
, addr
, val
);
1247 cpu_stw_data(env
, addr
, val
);
1250 cpu_stl_data(env
, addr
, val
);
1254 cpu_stq_data(env
, addr
, val
);
1259 case 0x81: /* Secondary */
1260 case 0x89: /* Secondary LE */
1264 case 0x82: /* Primary no-fault, RO */
1265 case 0x83: /* Secondary no-fault, RO */
1266 case 0x8a: /* Primary no-fault LE, RO */
1267 case 0x8b: /* Secondary no-fault LE, RO */
1269 helper_raise_exception(env
, TT_DATA_ACCESS
);
1274 #else /* CONFIG_USER_ONLY */
1276 uint64_t helper_ld_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
1279 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
1281 #if defined(DEBUG_ASI)
1282 target_ulong last_addr
= addr
;
1287 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1288 || (cpu_has_hypervisor(env
)
1289 && asi
>= 0x30 && asi
< 0x80
1290 && !(env
->hpstate
& HS_PRIV
))) {
1291 helper_raise_exception(env
, TT_PRIV_ACT
);
1294 helper_check_align(env
, addr
, size
- 1);
1295 addr
= asi_address_mask(env
, asi
, addr
);
1297 /* process nonfaulting loads first */
1298 if ((asi
& 0xf6) == 0x82) {
1301 /* secondary space access has lowest asi bit equal to 1 */
1302 if (env
->pstate
& PS_PRIV
) {
1303 mmu_idx
= (asi
& 1) ? MMU_KERNEL_SECONDARY_IDX
: MMU_KERNEL_IDX
;
1305 mmu_idx
= (asi
& 1) ? MMU_USER_SECONDARY_IDX
: MMU_USER_IDX
;
1308 if (cpu_get_phys_page_nofault(env
, addr
, mmu_idx
) == -1ULL) {
1310 dump_asi("read ", last_addr
, asi
, size
, ret
);
1312 /* env->exception_index is set in get_physical_address_data(). */
1313 helper_raise_exception(env
, cs
->exception_index
);
1316 /* convert nonfaulting load ASIs to normal load ASIs */
1321 case 0x10: /* As if user primary */
1322 case 0x11: /* As if user secondary */
1323 case 0x18: /* As if user primary LE */
1324 case 0x19: /* As if user secondary LE */
1325 case 0x80: /* Primary */
1326 case 0x81: /* Secondary */
1327 case 0x88: /* Primary LE */
1328 case 0x89: /* Secondary LE */
1329 case 0xe2: /* UA2007 Primary block init */
1330 case 0xe3: /* UA2007 Secondary block init */
1331 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1332 if (cpu_hypervisor_mode(env
)) {
1335 ret
= cpu_ldub_hypv(env
, addr
);
1338 ret
= cpu_lduw_hypv(env
, addr
);
1341 ret
= cpu_ldl_hypv(env
, addr
);
1345 ret
= cpu_ldq_hypv(env
, addr
);
1349 /* secondary space access has lowest asi bit equal to 1 */
1353 ret
= cpu_ldub_kernel_secondary(env
, addr
);
1356 ret
= cpu_lduw_kernel_secondary(env
, addr
);
1359 ret
= cpu_ldl_kernel_secondary(env
, addr
);
1363 ret
= cpu_ldq_kernel_secondary(env
, addr
);
1369 ret
= cpu_ldub_kernel(env
, addr
);
1372 ret
= cpu_lduw_kernel(env
, addr
);
1375 ret
= cpu_ldl_kernel(env
, addr
);
1379 ret
= cpu_ldq_kernel(env
, addr
);
1385 /* secondary space access has lowest asi bit equal to 1 */
1389 ret
= cpu_ldub_user_secondary(env
, addr
);
1392 ret
= cpu_lduw_user_secondary(env
, addr
);
1395 ret
= cpu_ldl_user_secondary(env
, addr
);
1399 ret
= cpu_ldq_user_secondary(env
, addr
);
1405 ret
= cpu_ldub_user(env
, addr
);
1408 ret
= cpu_lduw_user(env
, addr
);
1411 ret
= cpu_ldl_user(env
, addr
);
1415 ret
= cpu_ldq_user(env
, addr
);
1421 case 0x14: /* Bypass */
1422 case 0x15: /* Bypass, non-cacheable */
1423 case 0x1c: /* Bypass LE */
1424 case 0x1d: /* Bypass, non-cacheable LE */
1428 ret
= ldub_phys(cs
->as
, addr
);
1431 ret
= lduw_phys(cs
->as
, addr
);
1434 ret
= ldl_phys(cs
->as
, addr
);
1438 ret
= ldq_phys(cs
->as
, addr
);
1443 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1444 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1445 Only ldda allowed */
1446 helper_raise_exception(env
, TT_ILL_INSN
);
1448 case 0x04: /* Nucleus */
1449 case 0x0c: /* Nucleus Little Endian (LE) */
1453 ret
= cpu_ldub_nucleus(env
, addr
);
1456 ret
= cpu_lduw_nucleus(env
, addr
);
1459 ret
= cpu_ldl_nucleus(env
, addr
);
1463 ret
= cpu_ldq_nucleus(env
, addr
);
1468 case 0x4a: /* UPA config */
1471 case 0x45: /* LSU */
1474 case 0x50: /* I-MMU regs */
1476 int reg
= (addr
>> 3) & 0xf;
1479 /* I-TSB Tag Target register */
1480 ret
= ultrasparc_tag_target(env
->immu
.tag_access
);
1482 ret
= env
->immuregs
[reg
];
1487 case 0x51: /* I-MMU 8k TSB pointer */
1489 /* env->immuregs[5] holds I-MMU TSB register value
1490 env->immuregs[6] holds I-MMU Tag Access register value */
1491 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1495 case 0x52: /* I-MMU 64k TSB pointer */
1497 /* env->immuregs[5] holds I-MMU TSB register value
1498 env->immuregs[6] holds I-MMU Tag Access register value */
1499 ret
= ultrasparc_tsb_pointer(env
->immu
.tsb
, env
->immu
.tag_access
,
1503 case 0x55: /* I-MMU data access */
1505 int reg
= (addr
>> 3) & 0x3f;
1507 ret
= env
->itlb
[reg
].tte
;
1510 case 0x56: /* I-MMU tag read */
1512 int reg
= (addr
>> 3) & 0x3f;
1514 ret
= env
->itlb
[reg
].tag
;
1517 case 0x58: /* D-MMU regs */
1519 int reg
= (addr
>> 3) & 0xf;
1522 /* D-TSB Tag Target register */
1523 ret
= ultrasparc_tag_target(env
->dmmu
.tag_access
);
1525 ret
= env
->dmmuregs
[reg
];
1529 case 0x59: /* D-MMU 8k TSB pointer */
1531 /* env->dmmuregs[5] holds D-MMU TSB register value
1532 env->dmmuregs[6] holds D-MMU Tag Access register value */
1533 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1537 case 0x5a: /* D-MMU 64k TSB pointer */
1539 /* env->dmmuregs[5] holds D-MMU TSB register value
1540 env->dmmuregs[6] holds D-MMU Tag Access register value */
1541 ret
= ultrasparc_tsb_pointer(env
->dmmu
.tsb
, env
->dmmu
.tag_access
,
1545 case 0x5d: /* D-MMU data access */
1547 int reg
= (addr
>> 3) & 0x3f;
1549 ret
= env
->dtlb
[reg
].tte
;
1552 case 0x5e: /* D-MMU tag read */
1554 int reg
= (addr
>> 3) & 0x3f;
1556 ret
= env
->dtlb
[reg
].tag
;
1559 case 0x48: /* Interrupt dispatch, RO */
1561 case 0x49: /* Interrupt data receive */
1562 ret
= env
->ivec_status
;
1564 case 0x7f: /* Incoming interrupt vector, RO */
1566 int reg
= (addr
>> 4) & 0x3;
1568 ret
= env
->ivec_data
[reg
];
1572 case 0x46: /* D-cache data */
1573 case 0x47: /* D-cache tag access */
1574 case 0x4b: /* E-cache error enable */
1575 case 0x4c: /* E-cache asynchronous fault status */
1576 case 0x4d: /* E-cache asynchronous fault address */
1577 case 0x4e: /* E-cache tag data */
1578 case 0x66: /* I-cache instruction access */
1579 case 0x67: /* I-cache tag access */
1580 case 0x6e: /* I-cache predecode */
1581 case 0x6f: /* I-cache LRU etc. */
1582 case 0x76: /* E-cache tag */
1583 case 0x7e: /* E-cache tag */
1585 case 0x5b: /* D-MMU data pointer */
1586 case 0x54: /* I-MMU data in, WO */
1587 case 0x57: /* I-MMU demap, WO */
1588 case 0x5c: /* D-MMU data in, WO */
1589 case 0x5f: /* D-MMU demap, WO */
1590 case 0x77: /* Interrupt vector, WO */
1592 cpu_unassigned_access(cs
, addr
, false, false, 1, size
);
1597 /* Convert from little endian */
1599 case 0x0c: /* Nucleus Little Endian (LE) */
1600 case 0x18: /* As if user primary LE */
1601 case 0x19: /* As if user secondary LE */
1602 case 0x1c: /* Bypass LE */
1603 case 0x1d: /* Bypass, non-cacheable LE */
1604 case 0x88: /* Primary LE */
1605 case 0x89: /* Secondary LE */
1623 /* Convert to signed number */
1630 ret
= (int16_t) ret
;
1633 ret
= (int32_t) ret
;
1640 dump_asi("read ", last_addr
, asi
, size
, ret
);
1645 void helper_st_asi(CPUSPARCState
*env
, target_ulong addr
, target_ulong val
,
1648 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
1649 CPUState
*cs
= CPU(cpu
);
1652 dump_asi("write", addr
, asi
, size
, val
);
1657 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
1658 || (cpu_has_hypervisor(env
)
1659 && asi
>= 0x30 && asi
< 0x80
1660 && !(env
->hpstate
& HS_PRIV
))) {
1661 helper_raise_exception(env
, TT_PRIV_ACT
);
1664 helper_check_align(env
, addr
, size
- 1);
1665 addr
= asi_address_mask(env
, asi
, addr
);
1667 /* Convert to little endian */
1669 case 0x0c: /* Nucleus Little Endian (LE) */
1670 case 0x18: /* As if user primary LE */
1671 case 0x19: /* As if user secondary LE */
1672 case 0x1c: /* Bypass LE */
1673 case 0x1d: /* Bypass, non-cacheable LE */
1674 case 0x88: /* Primary LE */
1675 case 0x89: /* Secondary LE */
1694 case 0x10: /* As if user primary */
1695 case 0x11: /* As if user secondary */
1696 case 0x18: /* As if user primary LE */
1697 case 0x19: /* As if user secondary LE */
1698 case 0x80: /* Primary */
1699 case 0x81: /* Secondary */
1700 case 0x88: /* Primary LE */
1701 case 0x89: /* Secondary LE */
1702 case 0xe2: /* UA2007 Primary block init */
1703 case 0xe3: /* UA2007 Secondary block init */
1704 if ((asi
& 0x80) && (env
->pstate
& PS_PRIV
)) {
1705 if (cpu_hypervisor_mode(env
)) {
1708 cpu_stb_hypv(env
, addr
, val
);
1711 cpu_stw_hypv(env
, addr
, val
);
1714 cpu_stl_hypv(env
, addr
, val
);
1718 cpu_stq_hypv(env
, addr
, val
);
1722 /* secondary space access has lowest asi bit equal to 1 */
1726 cpu_stb_kernel_secondary(env
, addr
, val
);
1729 cpu_stw_kernel_secondary(env
, addr
, val
);
1732 cpu_stl_kernel_secondary(env
, addr
, val
);
1736 cpu_stq_kernel_secondary(env
, addr
, val
);
1742 cpu_stb_kernel(env
, addr
, val
);
1745 cpu_stw_kernel(env
, addr
, val
);
1748 cpu_stl_kernel(env
, addr
, val
);
1752 cpu_stq_kernel(env
, addr
, val
);
1758 /* secondary space access has lowest asi bit equal to 1 */
1762 cpu_stb_user_secondary(env
, addr
, val
);
1765 cpu_stw_user_secondary(env
, addr
, val
);
1768 cpu_stl_user_secondary(env
, addr
, val
);
1772 cpu_stq_user_secondary(env
, addr
, val
);
1778 cpu_stb_user(env
, addr
, val
);
1781 cpu_stw_user(env
, addr
, val
);
1784 cpu_stl_user(env
, addr
, val
);
1788 cpu_stq_user(env
, addr
, val
);
1794 case 0x14: /* Bypass */
1795 case 0x15: /* Bypass, non-cacheable */
1796 case 0x1c: /* Bypass LE */
1797 case 0x1d: /* Bypass, non-cacheable LE */
1801 stb_phys(cs
->as
, addr
, val
);
1804 stw_phys(cs
->as
, addr
, val
);
1807 stl_phys(cs
->as
, addr
, val
);
1811 stq_phys(cs
->as
, addr
, val
);
1816 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1817 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1818 Only ldda allowed */
1819 helper_raise_exception(env
, TT_ILL_INSN
);
1821 case 0x04: /* Nucleus */
1822 case 0x0c: /* Nucleus Little Endian (LE) */
1826 cpu_stb_nucleus(env
, addr
, val
);
1829 cpu_stw_nucleus(env
, addr
, val
);
1832 cpu_stl_nucleus(env
, addr
, val
);
1836 cpu_stq_nucleus(env
, addr
, val
);
1842 case 0x4a: /* UPA config */
1845 case 0x45: /* LSU */
1850 env
->lsu
= val
& (DMMU_E
| IMMU_E
);
1851 /* Mappings generated during D/I MMU disabled mode are
1852 invalid in normal mode */
1853 if (oldreg
!= env
->lsu
) {
1854 DPRINTF_MMU("LSU change: 0x%" PRIx64
" -> 0x%" PRIx64
"\n",
1857 dump_mmu(stdout
, fprintf
, env
);
1859 tlb_flush(CPU(cpu
), 1);
1863 case 0x50: /* I-MMU regs */
1865 int reg
= (addr
>> 3) & 0xf;
1868 oldreg
= env
->immuregs
[reg
];
1872 case 1: /* Not in I-MMU */
1876 if ((val
& 1) == 0) {
1877 val
= 0; /* Clear SFSR */
1879 env
->immu
.sfsr
= val
;
1883 case 5: /* TSB access */
1884 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64
" -> 0x%016"
1885 PRIx64
"\n", env
->immu
.tsb
, val
);
1886 env
->immu
.tsb
= val
;
1888 case 6: /* Tag access */
1889 env
->immu
.tag_access
= val
;
1898 if (oldreg
!= env
->immuregs
[reg
]) {
1899 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1900 PRIx64
"\n", reg
, oldreg
, env
->immuregs
[reg
]);
1903 dump_mmu(stdout
, fprintf
, env
);
1907 case 0x54: /* I-MMU data in */
1908 replace_tlb_1bit_lru(env
->itlb
, env
->immu
.tag_access
, val
, "immu", env
);
1910 case 0x55: /* I-MMU data access */
1912 /* TODO: auto demap */
1914 unsigned int i
= (addr
>> 3) & 0x3f;
1916 replace_tlb_entry(&env
->itlb
[i
], env
->immu
.tag_access
, val
, env
);
1919 DPRINTF_MMU("immu data access replaced entry [%i]\n", i
);
1920 dump_mmu(stdout
, fprintf
, env
);
1924 case 0x57: /* I-MMU demap */
1925 demap_tlb(env
->itlb
, addr
, "immu", env
);
1927 case 0x58: /* D-MMU regs */
1929 int reg
= (addr
>> 3) & 0xf;
1932 oldreg
= env
->dmmuregs
[reg
];
1938 if ((val
& 1) == 0) {
1939 val
= 0; /* Clear SFSR, Fault address */
1942 env
->dmmu
.sfsr
= val
;
1944 case 1: /* Primary context */
1945 env
->dmmu
.mmu_primary_context
= val
;
1946 /* can be optimized to only flush MMU_USER_IDX
1947 and MMU_KERNEL_IDX entries */
1948 tlb_flush(CPU(cpu
), 1);
1950 case 2: /* Secondary context */
1951 env
->dmmu
.mmu_secondary_context
= val
;
1952 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1953 and MMU_KERNEL_SECONDARY_IDX entries */
1954 tlb_flush(CPU(cpu
), 1);
1956 case 5: /* TSB access */
1957 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64
" -> 0x%016"
1958 PRIx64
"\n", env
->dmmu
.tsb
, val
);
1959 env
->dmmu
.tsb
= val
;
1961 case 6: /* Tag access */
1962 env
->dmmu
.tag_access
= val
;
1964 case 7: /* Virtual Watchpoint */
1965 case 8: /* Physical Watchpoint */
1967 env
->dmmuregs
[reg
] = val
;
1971 if (oldreg
!= env
->dmmuregs
[reg
]) {
1972 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64
" -> 0x%016"
1973 PRIx64
"\n", reg
, oldreg
, env
->dmmuregs
[reg
]);
1976 dump_mmu(stdout
, fprintf
, env
);
1980 case 0x5c: /* D-MMU data in */
1981 replace_tlb_1bit_lru(env
->dtlb
, env
->dmmu
.tag_access
, val
, "dmmu", env
);
1983 case 0x5d: /* D-MMU data access */
1985 unsigned int i
= (addr
>> 3) & 0x3f;
1987 replace_tlb_entry(&env
->dtlb
[i
], env
->dmmu
.tag_access
, val
, env
);
1990 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i
);
1991 dump_mmu(stdout
, fprintf
, env
);
1995 case 0x5f: /* D-MMU demap */
1996 demap_tlb(env
->dtlb
, addr
, "dmmu", env
);
1998 case 0x49: /* Interrupt data receive */
1999 env
->ivec_status
= val
& 0x20;
2001 case 0x46: /* D-cache data */
2002 case 0x47: /* D-cache tag access */
2003 case 0x4b: /* E-cache error enable */
2004 case 0x4c: /* E-cache asynchronous fault status */
2005 case 0x4d: /* E-cache asynchronous fault address */
2006 case 0x4e: /* E-cache tag data */
2007 case 0x66: /* I-cache instruction access */
2008 case 0x67: /* I-cache tag access */
2009 case 0x6e: /* I-cache predecode */
2010 case 0x6f: /* I-cache LRU etc. */
2011 case 0x76: /* E-cache tag */
2012 case 0x7e: /* E-cache tag */
2014 case 0x51: /* I-MMU 8k TSB pointer, RO */
2015 case 0x52: /* I-MMU 64k TSB pointer, RO */
2016 case 0x56: /* I-MMU tag read, RO */
2017 case 0x59: /* D-MMU 8k TSB pointer, RO */
2018 case 0x5a: /* D-MMU 64k TSB pointer, RO */
2019 case 0x5b: /* D-MMU data pointer, RO */
2020 case 0x5e: /* D-MMU tag read, RO */
2021 case 0x48: /* Interrupt dispatch, RO */
2022 case 0x7f: /* Incoming interrupt vector, RO */
2023 case 0x82: /* Primary no-fault, RO */
2024 case 0x83: /* Secondary no-fault, RO */
2025 case 0x8a: /* Primary no-fault LE, RO */
2026 case 0x8b: /* Secondary no-fault LE, RO */
2028 cpu_unassigned_access(cs
, addr
, true, false, 1, size
);
2032 #endif /* CONFIG_USER_ONLY */
2034 void helper_ldda_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int rd
)
2036 if ((asi
< 0x80 && (env
->pstate
& PS_PRIV
) == 0)
2037 || (cpu_has_hypervisor(env
)
2038 && asi
>= 0x30 && asi
< 0x80
2039 && !(env
->hpstate
& HS_PRIV
))) {
2040 helper_raise_exception(env
, TT_PRIV_ACT
);
2043 addr
= asi_address_mask(env
, asi
, addr
);
2046 #if !defined(CONFIG_USER_ONLY)
2047 case 0x24: /* Nucleus quad LDD 128 bit atomic */
2048 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE */
2049 helper_check_align(env
, addr
, 0xf);
2051 env
->gregs
[1] = cpu_ldq_nucleus(env
, addr
+ 8);
2053 bswap64s(&env
->gregs
[1]);
2055 } else if (rd
< 8) {
2056 env
->gregs
[rd
] = cpu_ldq_nucleus(env
, addr
);
2057 env
->gregs
[rd
+ 1] = cpu_ldq_nucleus(env
, addr
+ 8);
2059 bswap64s(&env
->gregs
[rd
]);
2060 bswap64s(&env
->gregs
[rd
+ 1]);
2063 env
->regwptr
[rd
- 8] = cpu_ldq_nucleus(env
, addr
);
2064 env
->regwptr
[rd
+ 1 - 8] = cpu_ldq_nucleus(env
, addr
+ 8);
2066 bswap64s(&env
->regwptr
[rd
- 8]);
2067 bswap64s(&env
->regwptr
[rd
+ 1 - 8]);
2073 helper_check_align(env
, addr
, 0x3);
2075 env
->gregs
[1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2076 } else if (rd
< 8) {
2077 env
->gregs
[rd
] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2078 env
->gregs
[rd
+ 1] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2080 env
->regwptr
[rd
- 8] = helper_ld_asi(env
, addr
, asi
, 4, 0);
2081 env
->regwptr
[rd
+ 1 - 8] = helper_ld_asi(env
, addr
+ 4, asi
, 4, 0);
2087 void helper_ldf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2093 helper_check_align(env
, addr
, 3);
2094 addr
= asi_address_mask(env
, asi
, addr
);
2097 case 0xf0: /* UA2007/JPS1 Block load primary */
2098 case 0xf1: /* UA2007/JPS1 Block load secondary */
2099 case 0xf8: /* UA2007/JPS1 Block load primary LE */
2100 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
2102 helper_raise_exception(env
, TT_ILL_INSN
);
2105 helper_check_align(env
, addr
, 0x3f);
2106 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2107 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x8f, 8, 0);
2111 case 0x16: /* UA2007 Block load primary, user privilege */
2112 case 0x17: /* UA2007 Block load secondary, user privilege */
2113 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2114 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2115 case 0x70: /* JPS1 Block load primary, user privilege */
2116 case 0x71: /* JPS1 Block load secondary, user privilege */
2117 case 0x78: /* JPS1 Block load primary LE, user privilege */
2118 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2120 helper_raise_exception(env
, TT_ILL_INSN
);
2123 helper_check_align(env
, addr
, 0x3f);
2124 for (i
= 0; i
< 8; i
++, rd
+= 2, addr
+= 8) {
2125 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
& 0x19, 8, 0);
2136 val
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2138 env
->fpr
[rd
/ 2].l
.lower
= val
;
2140 env
->fpr
[rd
/ 2].l
.upper
= val
;
2144 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, size
, 0);
2147 env
->fpr
[rd
/ 2].ll
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2148 env
->fpr
[rd
/ 2 + 1].ll
= helper_ld_asi(env
, addr
+ 8, asi
, 8, 0);
2153 void helper_stf_asi(CPUSPARCState
*env
, target_ulong addr
, int asi
, int size
,
2159 addr
= asi_address_mask(env
, asi
, addr
);
2162 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
2163 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
2164 case 0xf0: /* UA2007/JPS1 Block store primary */
2165 case 0xf1: /* UA2007/JPS1 Block store secondary */
2166 case 0xf8: /* UA2007/JPS1 Block store primary LE */
2167 case 0xf9: /* UA2007/JPS1 Block store 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 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x8f, 8);
2178 case 0x16: /* UA2007 Block load primary, user privilege */
2179 case 0x17: /* UA2007 Block load secondary, user privilege */
2180 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2181 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2182 case 0x70: /* JPS1 Block store primary, user privilege */
2183 case 0x71: /* JPS1 Block store secondary, user privilege */
2184 case 0x78: /* JPS1 Block load primary LE, user privilege */
2185 case 0x79: /* 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 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
& 0x19, 8);
2196 case 0xd2: /* 16-bit floating point load primary */
2197 case 0xd3: /* 16-bit floating point load secondary */
2198 case 0xda: /* 16-bit floating point load primary, LE */
2199 case 0xdb: /* 16-bit floating point load secondary, LE */
2200 helper_check_align(env
, addr
, 1);
2202 case 0xd0: /* 8-bit floating point load primary */
2203 case 0xd1: /* 8-bit floating point load secondary */
2204 case 0xd8: /* 8-bit floating point load primary, LE */
2205 case 0xd9: /* 8-bit floating point load secondary, LE */
2206 val
= env
->fpr
[rd
/ 2].l
.lower
;
2207 helper_st_asi(env
, addr
, val
, asi
& 0x8d, ((asi
& 2) >> 1) + 1);
2210 helper_check_align(env
, addr
, 3);
2218 val
= env
->fpr
[rd
/ 2].l
.lower
;
2220 val
= env
->fpr
[rd
/ 2].l
.upper
;
2222 helper_st_asi(env
, addr
, val
, asi
, size
);
2225 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, size
);
2228 helper_st_asi(env
, addr
, env
->fpr
[rd
/ 2].ll
, asi
, 8);
2229 helper_st_asi(env
, addr
+ 8, env
->fpr
[rd
/ 2 + 1].ll
, asi
, 8);
2234 target_ulong
helper_casx_asi(CPUSPARCState
*env
, target_ulong addr
,
2235 target_ulong val1
, target_ulong val2
,
2240 ret
= helper_ld_asi(env
, addr
, asi
, 8, 0);
2242 helper_st_asi(env
, addr
, val1
, asi
, 8);
2246 #endif /* TARGET_SPARC64 */
2248 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2249 target_ulong
helper_cas_asi(CPUSPARCState
*env
, target_ulong addr
,
2250 target_ulong val1
, target_ulong val2
, uint32_t asi
)
2254 val2
&= 0xffffffffUL
;
2255 ret
= helper_ld_asi(env
, addr
, asi
, 4, 0);
2256 ret
&= 0xffffffffUL
;
2258 helper_st_asi(env
, addr
, val1
& 0xffffffffUL
, asi
, 4);
2262 #endif /* !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) */
2264 void helper_ldqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2266 /* XXX add 128 bit load */
2269 helper_check_align(env
, addr
, 7);
2270 #if !defined(CONFIG_USER_ONLY)
2273 u
.ll
.upper
= cpu_ldq_user(env
, addr
);
2274 u
.ll
.lower
= cpu_ldq_user(env
, addr
+ 8);
2277 case MMU_KERNEL_IDX
:
2278 u
.ll
.upper
= cpu_ldq_kernel(env
, addr
);
2279 u
.ll
.lower
= cpu_ldq_kernel(env
, addr
+ 8);
2282 #ifdef TARGET_SPARC64
2284 u
.ll
.upper
= cpu_ldq_hypv(env
, addr
);
2285 u
.ll
.lower
= cpu_ldq_hypv(env
, addr
+ 8);
2290 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx
);
2294 u
.ll
.upper
= cpu_ldq_data(env
, address_mask(env
, addr
));
2295 u
.ll
.lower
= cpu_ldq_data(env
, address_mask(env
, addr
+ 8));
2300 void helper_stqf(CPUSPARCState
*env
, target_ulong addr
, int mem_idx
)
2302 /* XXX add 128 bit store */
2305 helper_check_align(env
, addr
, 7);
2306 #if !defined(CONFIG_USER_ONLY)
2310 cpu_stq_user(env
, addr
, u
.ll
.upper
);
2311 cpu_stq_user(env
, addr
+ 8, u
.ll
.lower
);
2313 case MMU_KERNEL_IDX
:
2315 cpu_stq_kernel(env
, addr
, u
.ll
.upper
);
2316 cpu_stq_kernel(env
, addr
+ 8, u
.ll
.lower
);
2318 #ifdef TARGET_SPARC64
2321 cpu_stq_hypv(env
, addr
, u
.ll
.upper
);
2322 cpu_stq_hypv(env
, addr
+ 8, u
.ll
.lower
);
2326 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx
);
2331 cpu_stq_data(env
, address_mask(env
, addr
), u
.ll
.upper
);
2332 cpu_stq_data(env
, address_mask(env
, addr
+ 8), u
.ll
.lower
);
2336 #if !defined(CONFIG_USER_ONLY)
2337 #ifndef TARGET_SPARC64
2338 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2339 bool is_write
, bool is_exec
, int is_asi
,
2342 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2343 CPUSPARCState
*env
= &cpu
->env
;
2346 #ifdef DEBUG_UNASSIGNED
2348 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2349 " asi 0x%02x from " TARGET_FMT_lx
"\n",
2350 is_exec
? "exec" : is_write
? "write" : "read", size
,
2351 size
== 1 ? "" : "s", addr
, is_asi
, env
->pc
);
2353 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2354 " from " TARGET_FMT_lx
"\n",
2355 is_exec
? "exec" : is_write
? "write" : "read", size
,
2356 size
== 1 ? "" : "s", addr
, env
->pc
);
2359 /* Don't overwrite translation and access faults */
2360 fault_type
= (env
->mmuregs
[3] & 0x1c) >> 2;
2361 if ((fault_type
> 4) || (fault_type
== 0)) {
2362 env
->mmuregs
[3] = 0; /* Fault status register */
2364 env
->mmuregs
[3] |= 1 << 16;
2367 env
->mmuregs
[3] |= 1 << 5;
2370 env
->mmuregs
[3] |= 1 << 6;
2373 env
->mmuregs
[3] |= 1 << 7;
2375 env
->mmuregs
[3] |= (5 << 2) | 2;
2376 /* SuperSPARC will never place instruction fault addresses in the FAR */
2378 env
->mmuregs
[4] = addr
; /* Fault address register */
2381 /* overflow (same type fault was not read before another fault) */
2382 if (fault_type
== ((env
->mmuregs
[3] & 0x1c)) >> 2) {
2383 env
->mmuregs
[3] |= 1;
2386 if ((env
->mmuregs
[0] & MMU_E
) && !(env
->mmuregs
[0] & MMU_NF
)) {
2388 helper_raise_exception(env
, TT_CODE_ACCESS
);
2390 helper_raise_exception(env
, TT_DATA_ACCESS
);
2394 /* flush neverland mappings created during no-fault mode,
2395 so the sequential MMU faults report proper fault types */
2396 if (env
->mmuregs
[0] & MMU_NF
) {
2401 void sparc_cpu_unassigned_access(CPUState
*cs
, hwaddr addr
,
2402 bool is_write
, bool is_exec
, int is_asi
,
2405 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2406 CPUSPARCState
*env
= &cpu
->env
;
2408 #ifdef DEBUG_UNASSIGNED
2409 printf("Unassigned mem access to " TARGET_FMT_plx
" from " TARGET_FMT_lx
2410 "\n", addr
, env
->pc
);
2414 helper_raise_exception(env
, TT_CODE_ACCESS
);
2416 helper_raise_exception(env
, TT_DATA_ACCESS
);
2422 #if !defined(CONFIG_USER_ONLY)
2423 void QEMU_NORETURN
sparc_cpu_do_unaligned_access(CPUState
*cs
, vaddr addr
,
2424 MMUAccessType access_type
,
2428 SPARCCPU
*cpu
= SPARC_CPU(cs
);
2429 CPUSPARCState
*env
= &cpu
->env
;
2431 #ifdef DEBUG_UNALIGNED
2432 printf("Unaligned access to 0x" TARGET_FMT_lx
" from 0x" TARGET_FMT_lx
2433 "\n", addr
, env
->pc
);
2436 cpu_restore_state(CPU(cpu
), retaddr
);
2438 helper_raise_exception(env
, TT_UNALIGNED
);
2441 /* try to fill the TLB and return an exception if error. If retaddr is
2442 NULL, it means that the function was called in C code (i.e. not
2443 from generated code or from helper.c) */
2444 /* XXX: fix it to restore all registers */
2445 void tlb_fill(CPUState
*cs
, target_ulong addr
, MMUAccessType access_type
,
2446 int mmu_idx
, uintptr_t retaddr
)
2450 ret
= sparc_cpu_handle_mmu_fault(cs
, addr
, access_type
, mmu_idx
);
2453 cpu_restore_state(cs
, retaddr
);