1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth * Helpers for loads and stores
3fcf5ef2aSThomas Huth *
4fcf5ef2aSThomas Huth * Copyright (c) 2003-2005 Fabrice Bellard
5fcf5ef2aSThomas Huth *
6fcf5ef2aSThomas Huth * This library is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth * modify it under the terms of the GNU Lesser General Public
8fcf5ef2aSThomas Huth * License as published by the Free Software Foundation; either
95650b549SChetan Pant * version 2.1 of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth *
11fcf5ef2aSThomas Huth * This library is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14fcf5ef2aSThomas Huth * Lesser General Public License for more details.
15fcf5ef2aSThomas Huth *
16fcf5ef2aSThomas Huth * You should have received a copy of the GNU Lesser General Public
17fcf5ef2aSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18fcf5ef2aSThomas Huth */
19fcf5ef2aSThomas Huth
20fcf5ef2aSThomas Huth #include "qemu/osdep.h"
21cd617484SPhilippe Mathieu-Daudé #include "qemu/log.h"
22*2a48b590SYao Xingtao #include "qemu/range.h"
23fcf5ef2aSThomas Huth #include "cpu.h"
24dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg.h"
25fcf5ef2aSThomas Huth #include "exec/helper-proto.h"
26fcf5ef2aSThomas Huth #include "exec/exec-all.h"
2774781c08SPhilippe Mathieu-Daudé #include "exec/page-protection.h"
28fcf5ef2aSThomas Huth #include "exec/cpu_ldst.h"
29fcf5ef2aSThomas Huth #include "asi.h"
30fcf5ef2aSThomas Huth
31fcf5ef2aSThomas Huth //#define DEBUG_MMU
32fcf5ef2aSThomas Huth //#define DEBUG_MXCC
33fcf5ef2aSThomas Huth //#define DEBUG_UNASSIGNED
34fcf5ef2aSThomas Huth //#define DEBUG_ASI
35fcf5ef2aSThomas Huth //#define DEBUG_CACHE_CONTROL
36fcf5ef2aSThomas Huth
37fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
38fcf5ef2aSThomas Huth #define DPRINTF_MMU(fmt, ...) \
39fcf5ef2aSThomas Huth do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
40fcf5ef2aSThomas Huth #else
41fcf5ef2aSThomas Huth #define DPRINTF_MMU(fmt, ...) do {} while (0)
42fcf5ef2aSThomas Huth #endif
43fcf5ef2aSThomas Huth
44fcf5ef2aSThomas Huth #ifdef DEBUG_MXCC
45fcf5ef2aSThomas Huth #define DPRINTF_MXCC(fmt, ...) \
46fcf5ef2aSThomas Huth do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
47fcf5ef2aSThomas Huth #else
48fcf5ef2aSThomas Huth #define DPRINTF_MXCC(fmt, ...) do {} while (0)
49fcf5ef2aSThomas Huth #endif
50fcf5ef2aSThomas Huth
51fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
52fcf5ef2aSThomas Huth #define DPRINTF_ASI(fmt, ...) \
53fcf5ef2aSThomas Huth do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
54fcf5ef2aSThomas Huth #endif
55fcf5ef2aSThomas Huth
56fcf5ef2aSThomas Huth #ifdef DEBUG_CACHE_CONTROL
57fcf5ef2aSThomas Huth #define DPRINTF_CACHE_CONTROL(fmt, ...) \
58fcf5ef2aSThomas Huth do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
59fcf5ef2aSThomas Huth #else
60fcf5ef2aSThomas Huth #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
61fcf5ef2aSThomas Huth #endif
62fcf5ef2aSThomas Huth
63fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
64fcf5ef2aSThomas Huth #ifndef TARGET_ABI32
65fcf5ef2aSThomas Huth #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
66fcf5ef2aSThomas Huth #else
67fcf5ef2aSThomas Huth #define AM_CHECK(env1) (1)
68fcf5ef2aSThomas Huth #endif
69fcf5ef2aSThomas Huth #endif
70fcf5ef2aSThomas Huth
71fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
7215f746ceSArtyom Tarasenko /* Calculates TSB pointer value for fault page size
7315f746ceSArtyom Tarasenko * UltraSPARC IIi has fixed sizes (8k or 64k) for the page pointers
7415f746ceSArtyom Tarasenko * UA2005 holds the page size configuration in mmu_ctx registers */
ultrasparc_tsb_pointer(CPUSPARCState * env,const SparcV9MMU * mmu,const int idx)75e5673ee4SArtyom Tarasenko static uint64_t ultrasparc_tsb_pointer(CPUSPARCState *env,
76e5673ee4SArtyom Tarasenko const SparcV9MMU *mmu, const int idx)
77fcf5ef2aSThomas Huth {
7815f746ceSArtyom Tarasenko uint64_t tsb_register;
7915f746ceSArtyom Tarasenko int page_size;
8015f746ceSArtyom Tarasenko if (cpu_has_hypervisor(env)) {
8115f746ceSArtyom Tarasenko int tsb_index = 0;
82e5673ee4SArtyom Tarasenko int ctx = mmu->tag_access & 0x1fffULL;
83e5673ee4SArtyom Tarasenko uint64_t ctx_register = mmu->sun4v_ctx_config[ctx ? 1 : 0];
8415f746ceSArtyom Tarasenko tsb_index = idx;
8515f746ceSArtyom Tarasenko tsb_index |= ctx ? 2 : 0;
8615f746ceSArtyom Tarasenko page_size = idx ? ctx_register >> 8 : ctx_register;
8715f746ceSArtyom Tarasenko page_size &= 7;
88e5673ee4SArtyom Tarasenko tsb_register = mmu->sun4v_tsb_pointers[tsb_index];
8915f746ceSArtyom Tarasenko } else {
9015f746ceSArtyom Tarasenko page_size = idx;
91e5673ee4SArtyom Tarasenko tsb_register = mmu->tsb;
9215f746ceSArtyom Tarasenko }
93fcf5ef2aSThomas Huth int tsb_split = (tsb_register & 0x1000ULL) ? 1 : 0;
94fcf5ef2aSThomas Huth int tsb_size = tsb_register & 0xf;
95fcf5ef2aSThomas Huth
96e5673ee4SArtyom Tarasenko uint64_t tsb_base_mask = (~0x1fffULL) << tsb_size;
97fcf5ef2aSThomas Huth
98e5673ee4SArtyom Tarasenko /* move va bits to correct position,
99e5673ee4SArtyom Tarasenko * the context bits will be masked out later */
100e5673ee4SArtyom Tarasenko uint64_t va = mmu->tag_access >> (3 * page_size + 9);
101fcf5ef2aSThomas Huth
102fcf5ef2aSThomas Huth /* calculate tsb_base mask and adjust va if split is in use */
103fcf5ef2aSThomas Huth if (tsb_split) {
10415f746ceSArtyom Tarasenko if (idx == 0) {
105fcf5ef2aSThomas Huth va &= ~(1ULL << (13 + tsb_size));
10615f746ceSArtyom Tarasenko } else {
107fcf5ef2aSThomas Huth va |= (1ULL << (13 + tsb_size));
108fcf5ef2aSThomas Huth }
109fcf5ef2aSThomas Huth tsb_base_mask <<= 1;
110fcf5ef2aSThomas Huth }
111fcf5ef2aSThomas Huth
112e5673ee4SArtyom Tarasenko return ((tsb_register & tsb_base_mask) | (va & ~tsb_base_mask)) & ~0xfULL;
113fcf5ef2aSThomas Huth }
114fcf5ef2aSThomas Huth
115fcf5ef2aSThomas Huth /* Calculates tag target register value by reordering bits
116fcf5ef2aSThomas Huth in tag access register */
ultrasparc_tag_target(uint64_t tag_access_register)117fcf5ef2aSThomas Huth static uint64_t ultrasparc_tag_target(uint64_t tag_access_register)
118fcf5ef2aSThomas Huth {
119fcf5ef2aSThomas Huth return ((tag_access_register & 0x1fff) << 48) | (tag_access_register >> 22);
120fcf5ef2aSThomas Huth }
121fcf5ef2aSThomas Huth
replace_tlb_entry(SparcTLBEntry * tlb,uint64_t tlb_tag,uint64_t tlb_tte,CPUSPARCState * env)122fcf5ef2aSThomas Huth static void replace_tlb_entry(SparcTLBEntry *tlb,
123fcf5ef2aSThomas Huth uint64_t tlb_tag, uint64_t tlb_tte,
1245a59fbceSRichard Henderson CPUSPARCState *env)
125fcf5ef2aSThomas Huth {
126fcf5ef2aSThomas Huth target_ulong mask, size, va, offset;
127fcf5ef2aSThomas Huth
128fcf5ef2aSThomas Huth /* flush page range if translation is valid */
129fcf5ef2aSThomas Huth if (TTE_IS_VALID(tlb->tte)) {
1305a59fbceSRichard Henderson CPUState *cs = env_cpu(env);
131fcf5ef2aSThomas Huth
132e4d06ca7SArtyom Tarasenko size = 8192ULL << 3 * TTE_PGSIZE(tlb->tte);
133e4d06ca7SArtyom Tarasenko mask = 1ULL + ~size;
134fcf5ef2aSThomas Huth
135fcf5ef2aSThomas Huth va = tlb->tag & mask;
136fcf5ef2aSThomas Huth
137fcf5ef2aSThomas Huth for (offset = 0; offset < size; offset += TARGET_PAGE_SIZE) {
138fcf5ef2aSThomas Huth tlb_flush_page(cs, va + offset);
139fcf5ef2aSThomas Huth }
140fcf5ef2aSThomas Huth }
141fcf5ef2aSThomas Huth
142fcf5ef2aSThomas Huth tlb->tag = tlb_tag;
143fcf5ef2aSThomas Huth tlb->tte = tlb_tte;
144fcf5ef2aSThomas Huth }
145fcf5ef2aSThomas Huth
demap_tlb(SparcTLBEntry * tlb,target_ulong demap_addr,const char * strmmu,CPUSPARCState * env1)146fcf5ef2aSThomas Huth static void demap_tlb(SparcTLBEntry *tlb, target_ulong demap_addr,
147fcf5ef2aSThomas Huth const char *strmmu, CPUSPARCState *env1)
148fcf5ef2aSThomas Huth {
149fcf5ef2aSThomas Huth unsigned int i;
150fcf5ef2aSThomas Huth target_ulong mask;
151fcf5ef2aSThomas Huth uint64_t context;
152fcf5ef2aSThomas Huth
153fcf5ef2aSThomas Huth int is_demap_context = (demap_addr >> 6) & 1;
154fcf5ef2aSThomas Huth
155fcf5ef2aSThomas Huth /* demap context */
156fcf5ef2aSThomas Huth switch ((demap_addr >> 4) & 3) {
157fcf5ef2aSThomas Huth case 0: /* primary */
158fcf5ef2aSThomas Huth context = env1->dmmu.mmu_primary_context;
159fcf5ef2aSThomas Huth break;
160fcf5ef2aSThomas Huth case 1: /* secondary */
161fcf5ef2aSThomas Huth context = env1->dmmu.mmu_secondary_context;
162fcf5ef2aSThomas Huth break;
163fcf5ef2aSThomas Huth case 2: /* nucleus */
164fcf5ef2aSThomas Huth context = 0;
165fcf5ef2aSThomas Huth break;
166fcf5ef2aSThomas Huth case 3: /* reserved */
167fcf5ef2aSThomas Huth default:
168fcf5ef2aSThomas Huth return;
169fcf5ef2aSThomas Huth }
170fcf5ef2aSThomas Huth
171fcf5ef2aSThomas Huth for (i = 0; i < 64; i++) {
172fcf5ef2aSThomas Huth if (TTE_IS_VALID(tlb[i].tte)) {
173fcf5ef2aSThomas Huth
174fcf5ef2aSThomas Huth if (is_demap_context) {
175fcf5ef2aSThomas Huth /* will remove non-global entries matching context value */
176fcf5ef2aSThomas Huth if (TTE_IS_GLOBAL(tlb[i].tte) ||
177fcf5ef2aSThomas Huth !tlb_compare_context(&tlb[i], context)) {
178fcf5ef2aSThomas Huth continue;
179fcf5ef2aSThomas Huth }
180fcf5ef2aSThomas Huth } else {
181fcf5ef2aSThomas Huth /* demap page
182fcf5ef2aSThomas Huth will remove any entry matching VA */
183fcf5ef2aSThomas Huth mask = 0xffffffffffffe000ULL;
184fcf5ef2aSThomas Huth mask <<= 3 * ((tlb[i].tte >> 61) & 3);
185fcf5ef2aSThomas Huth
186fcf5ef2aSThomas Huth if (!compare_masked(demap_addr, tlb[i].tag, mask)) {
187fcf5ef2aSThomas Huth continue;
188fcf5ef2aSThomas Huth }
189fcf5ef2aSThomas Huth
190fcf5ef2aSThomas Huth /* entry should be global or matching context value */
191fcf5ef2aSThomas Huth if (!TTE_IS_GLOBAL(tlb[i].tte) &&
192fcf5ef2aSThomas Huth !tlb_compare_context(&tlb[i], context)) {
193fcf5ef2aSThomas Huth continue;
194fcf5ef2aSThomas Huth }
195fcf5ef2aSThomas Huth }
196fcf5ef2aSThomas Huth
197fcf5ef2aSThomas Huth replace_tlb_entry(&tlb[i], 0, 0, env1);
198fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
199fcf5ef2aSThomas Huth DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i);
200fad866daSMarkus Armbruster dump_mmu(env1);
201fcf5ef2aSThomas Huth #endif
202fcf5ef2aSThomas Huth }
203fcf5ef2aSThomas Huth }
204fcf5ef2aSThomas Huth }
205fcf5ef2aSThomas Huth
sun4v_tte_to_sun4u(CPUSPARCState * env,uint64_t tag,uint64_t sun4v_tte)2067285fba0SArtyom Tarasenko static uint64_t sun4v_tte_to_sun4u(CPUSPARCState *env, uint64_t tag,
2077285fba0SArtyom Tarasenko uint64_t sun4v_tte)
2087285fba0SArtyom Tarasenko {
2097285fba0SArtyom Tarasenko uint64_t sun4u_tte;
2107285fba0SArtyom Tarasenko if (!(cpu_has_hypervisor(env) && (tag & TLB_UST1_IS_SUN4V_BIT))) {
2117285fba0SArtyom Tarasenko /* is already in the sun4u format */
2127285fba0SArtyom Tarasenko return sun4v_tte;
2137285fba0SArtyom Tarasenko }
2147285fba0SArtyom Tarasenko sun4u_tte = TTE_PA(sun4v_tte) | (sun4v_tte & TTE_VALID_BIT);
2157285fba0SArtyom Tarasenko sun4u_tte |= (sun4v_tte & 3ULL) << 61; /* TTE_PGSIZE */
2167285fba0SArtyom Tarasenko sun4u_tte |= CONVERT_BIT(sun4v_tte, TTE_NFO_BIT_UA2005, TTE_NFO_BIT);
2177285fba0SArtyom Tarasenko sun4u_tte |= CONVERT_BIT(sun4v_tte, TTE_USED_BIT_UA2005, TTE_USED_BIT);
2187285fba0SArtyom Tarasenko sun4u_tte |= CONVERT_BIT(sun4v_tte, TTE_W_OK_BIT_UA2005, TTE_W_OK_BIT);
2197285fba0SArtyom Tarasenko sun4u_tte |= CONVERT_BIT(sun4v_tte, TTE_SIDEEFFECT_BIT_UA2005,
2207285fba0SArtyom Tarasenko TTE_SIDEEFFECT_BIT);
2217285fba0SArtyom Tarasenko sun4u_tte |= CONVERT_BIT(sun4v_tte, TTE_PRIV_BIT_UA2005, TTE_PRIV_BIT);
2227285fba0SArtyom Tarasenko sun4u_tte |= CONVERT_BIT(sun4v_tte, TTE_LOCKED_BIT_UA2005, TTE_LOCKED_BIT);
2237285fba0SArtyom Tarasenko return sun4u_tte;
2247285fba0SArtyom Tarasenko }
2257285fba0SArtyom Tarasenko
replace_tlb_1bit_lru(SparcTLBEntry * tlb,uint64_t tlb_tag,uint64_t tlb_tte,const char * strmmu,CPUSPARCState * env1,uint64_t addr)226fcf5ef2aSThomas Huth static void replace_tlb_1bit_lru(SparcTLBEntry *tlb,
227fcf5ef2aSThomas Huth uint64_t tlb_tag, uint64_t tlb_tte,
2287285fba0SArtyom Tarasenko const char *strmmu, CPUSPARCState *env1,
2297285fba0SArtyom Tarasenko uint64_t addr)
230fcf5ef2aSThomas Huth {
231fcf5ef2aSThomas Huth unsigned int i, replace_used;
232fcf5ef2aSThomas Huth
2337285fba0SArtyom Tarasenko tlb_tte = sun4v_tte_to_sun4u(env1, addr, tlb_tte);
23470f44d2fSArtyom Tarasenko if (cpu_has_hypervisor(env1)) {
23570f44d2fSArtyom Tarasenko uint64_t new_vaddr = tlb_tag & ~0x1fffULL;
23670f44d2fSArtyom Tarasenko uint64_t new_size = 8192ULL << 3 * TTE_PGSIZE(tlb_tte);
23770f44d2fSArtyom Tarasenko uint32_t new_ctx = tlb_tag & 0x1fffU;
23870f44d2fSArtyom Tarasenko for (i = 0; i < 64; i++) {
23970f44d2fSArtyom Tarasenko uint32_t ctx = tlb[i].tag & 0x1fffU;
24070f44d2fSArtyom Tarasenko /* check if new mapping overlaps an existing one */
24170f44d2fSArtyom Tarasenko if (new_ctx == ctx) {
24270f44d2fSArtyom Tarasenko uint64_t vaddr = tlb[i].tag & ~0x1fffULL;
24370f44d2fSArtyom Tarasenko uint64_t size = 8192ULL << 3 * TTE_PGSIZE(tlb[i].tte);
244*2a48b590SYao Xingtao if (ranges_overlap(new_vaddr, new_size, vaddr, size)) {
24570f44d2fSArtyom Tarasenko DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i, vaddr,
24670f44d2fSArtyom Tarasenko new_vaddr);
24770f44d2fSArtyom Tarasenko replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1);
24870f44d2fSArtyom Tarasenko return;
24970f44d2fSArtyom Tarasenko }
25070f44d2fSArtyom Tarasenko }
25170f44d2fSArtyom Tarasenko
25270f44d2fSArtyom Tarasenko }
25370f44d2fSArtyom Tarasenko }
254fcf5ef2aSThomas Huth /* Try replacing invalid entry */
255fcf5ef2aSThomas Huth for (i = 0; i < 64; i++) {
256fcf5ef2aSThomas Huth if (!TTE_IS_VALID(tlb[i].tte)) {
257fcf5ef2aSThomas Huth replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1);
258fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
259fcf5ef2aSThomas Huth DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu, i);
260fad866daSMarkus Armbruster dump_mmu(env1);
261fcf5ef2aSThomas Huth #endif
262fcf5ef2aSThomas Huth return;
263fcf5ef2aSThomas Huth }
264fcf5ef2aSThomas Huth }
265fcf5ef2aSThomas Huth
266fcf5ef2aSThomas Huth /* All entries are valid, try replacing unlocked entry */
267fcf5ef2aSThomas Huth
268fcf5ef2aSThomas Huth for (replace_used = 0; replace_used < 2; ++replace_used) {
269fcf5ef2aSThomas Huth
270fcf5ef2aSThomas Huth /* Used entries are not replaced on first pass */
271fcf5ef2aSThomas Huth
272fcf5ef2aSThomas Huth for (i = 0; i < 64; i++) {
273fcf5ef2aSThomas Huth if (!TTE_IS_LOCKED(tlb[i].tte) && !TTE_IS_USED(tlb[i].tte)) {
274fcf5ef2aSThomas Huth
275fcf5ef2aSThomas Huth replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1);
276fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
277fcf5ef2aSThomas Huth DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
278fcf5ef2aSThomas Huth strmmu, (replace_used ? "used" : "unused"), i);
279fad866daSMarkus Armbruster dump_mmu(env1);
280fcf5ef2aSThomas Huth #endif
281fcf5ef2aSThomas Huth return;
282fcf5ef2aSThomas Huth }
283fcf5ef2aSThomas Huth }
284fcf5ef2aSThomas Huth
285fcf5ef2aSThomas Huth /* Now reset used bit and search for unused entries again */
286fcf5ef2aSThomas Huth
287fcf5ef2aSThomas Huth for (i = 0; i < 64; i++) {
288fcf5ef2aSThomas Huth TTE_SET_UNUSED(tlb[i].tte);
289fcf5ef2aSThomas Huth }
290fcf5ef2aSThomas Huth }
291fcf5ef2aSThomas Huth
292fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
2934797a685SArtyom Tarasenko DPRINTF_MMU("%s lru replacement: no free entries available, "
2944797a685SArtyom Tarasenko "replacing the last one\n", strmmu);
295fcf5ef2aSThomas Huth #endif
2964797a685SArtyom Tarasenko /* corner case: the last entry is replaced anyway */
2974797a685SArtyom Tarasenko replace_tlb_entry(&tlb[63], tlb_tag, tlb_tte, env1);
298fcf5ef2aSThomas Huth }
299fcf5ef2aSThomas Huth
300fcf5ef2aSThomas Huth #endif
301fcf5ef2aSThomas Huth
302fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
303fcf5ef2aSThomas Huth /* returns true if access using this ASI is to have address translated by MMU
304fcf5ef2aSThomas Huth otherwise access is to raw physical address */
305fcf5ef2aSThomas Huth /* TODO: check sparc32 bits */
is_translating_asi(int asi)306fcf5ef2aSThomas Huth static inline int is_translating_asi(int asi)
307fcf5ef2aSThomas Huth {
308fcf5ef2aSThomas Huth /* Ultrasparc IIi translating asi
309fcf5ef2aSThomas Huth - note this list is defined by cpu implementation
310fcf5ef2aSThomas Huth */
311fcf5ef2aSThomas Huth switch (asi) {
312fcf5ef2aSThomas Huth case 0x04 ... 0x11:
313fcf5ef2aSThomas Huth case 0x16 ... 0x19:
314fcf5ef2aSThomas Huth case 0x1E ... 0x1F:
315fcf5ef2aSThomas Huth case 0x24 ... 0x2C:
316fcf5ef2aSThomas Huth case 0x70 ... 0x73:
317fcf5ef2aSThomas Huth case 0x78 ... 0x79:
318fcf5ef2aSThomas Huth case 0x80 ... 0xFF:
319fcf5ef2aSThomas Huth return 1;
320fcf5ef2aSThomas Huth
321fcf5ef2aSThomas Huth default:
322fcf5ef2aSThomas Huth return 0;
323fcf5ef2aSThomas Huth }
324fcf5ef2aSThomas Huth }
325fcf5ef2aSThomas Huth
address_mask(CPUSPARCState * env1,target_ulong addr)326fcf5ef2aSThomas Huth static inline target_ulong address_mask(CPUSPARCState *env1, target_ulong addr)
327fcf5ef2aSThomas Huth {
328fcf5ef2aSThomas Huth if (AM_CHECK(env1)) {
329fcf5ef2aSThomas Huth addr &= 0xffffffffULL;
330fcf5ef2aSThomas Huth }
331fcf5ef2aSThomas Huth return addr;
332fcf5ef2aSThomas Huth }
333fcf5ef2aSThomas Huth
asi_address_mask(CPUSPARCState * env,int asi,target_ulong addr)334fcf5ef2aSThomas Huth static inline target_ulong asi_address_mask(CPUSPARCState *env,
335fcf5ef2aSThomas Huth int asi, target_ulong addr)
336fcf5ef2aSThomas Huth {
337fcf5ef2aSThomas Huth if (is_translating_asi(asi)) {
338fcf5ef2aSThomas Huth addr = address_mask(env, addr);
339fcf5ef2aSThomas Huth }
340fcf5ef2aSThomas Huth return addr;
341fcf5ef2aSThomas Huth }
3427cd39ef2SArtyom Tarasenko
3437cd39ef2SArtyom Tarasenko #ifndef CONFIG_USER_ONLY
do_check_asi(CPUSPARCState * env,int asi,uintptr_t ra)3447cd39ef2SArtyom Tarasenko static inline void do_check_asi(CPUSPARCState *env, int asi, uintptr_t ra)
3457cd39ef2SArtyom Tarasenko {
3467cd39ef2SArtyom Tarasenko /* ASIs >= 0x80 are user mode.
3477cd39ef2SArtyom Tarasenko * ASIs >= 0x30 are hyper mode (or super if hyper is not available).
3487cd39ef2SArtyom Tarasenko * ASIs <= 0x2f are super mode.
3497cd39ef2SArtyom Tarasenko */
3507cd39ef2SArtyom Tarasenko if (asi < 0x80
3517cd39ef2SArtyom Tarasenko && !cpu_hypervisor_mode(env)
3527cd39ef2SArtyom Tarasenko && (!cpu_supervisor_mode(env)
3537cd39ef2SArtyom Tarasenko || (asi >= 0x30 && cpu_has_hypervisor(env)))) {
3547cd39ef2SArtyom Tarasenko cpu_raise_exception_ra(env, TT_PRIV_ACT, ra);
3557cd39ef2SArtyom Tarasenko }
3567cd39ef2SArtyom Tarasenko }
3577cd39ef2SArtyom Tarasenko #endif /* !CONFIG_USER_ONLY */
358fcf5ef2aSThomas Huth #endif
359fcf5ef2aSThomas Huth
360186e7890SRichard Henderson #if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)
do_check_align(CPUSPARCState * env,target_ulong addr,uint32_t align,uintptr_t ra)361fcf5ef2aSThomas Huth static void do_check_align(CPUSPARCState *env, target_ulong addr,
362fcf5ef2aSThomas Huth uint32_t align, uintptr_t ra)
363fcf5ef2aSThomas Huth {
364fcf5ef2aSThomas Huth if (addr & align) {
365fcf5ef2aSThomas Huth cpu_raise_exception_ra(env, TT_UNALIGNED, ra);
366fcf5ef2aSThomas Huth }
367fcf5ef2aSThomas Huth }
368186e7890SRichard Henderson #endif
369fcf5ef2aSThomas Huth
370fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
371fcf5ef2aSThomas Huth defined(DEBUG_MXCC)
dump_mxcc(CPUSPARCState * env)372fcf5ef2aSThomas Huth static void dump_mxcc(CPUSPARCState *env)
373fcf5ef2aSThomas Huth {
374fcf5ef2aSThomas Huth printf("mxccdata: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64
375fcf5ef2aSThomas Huth "\n",
376fcf5ef2aSThomas Huth env->mxccdata[0], env->mxccdata[1],
377fcf5ef2aSThomas Huth env->mxccdata[2], env->mxccdata[3]);
378fcf5ef2aSThomas Huth printf("mxccregs: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64
379fcf5ef2aSThomas Huth "\n"
380fcf5ef2aSThomas Huth " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64
381fcf5ef2aSThomas Huth "\n",
382fcf5ef2aSThomas Huth env->mxccregs[0], env->mxccregs[1],
383fcf5ef2aSThomas Huth env->mxccregs[2], env->mxccregs[3],
384fcf5ef2aSThomas Huth env->mxccregs[4], env->mxccregs[5],
385fcf5ef2aSThomas Huth env->mxccregs[6], env->mxccregs[7]);
386fcf5ef2aSThomas Huth }
387fcf5ef2aSThomas Huth #endif
388fcf5ef2aSThomas Huth
389fcf5ef2aSThomas Huth #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
390fcf5ef2aSThomas Huth && defined(DEBUG_ASI)
dump_asi(const char * txt,target_ulong addr,int asi,int size,uint64_t r1)391fcf5ef2aSThomas Huth static void dump_asi(const char *txt, target_ulong addr, int asi, int size,
392fcf5ef2aSThomas Huth uint64_t r1)
393fcf5ef2aSThomas Huth {
394fcf5ef2aSThomas Huth switch (size) {
395fcf5ef2aSThomas Huth case 1:
396fcf5ef2aSThomas Huth DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %02" PRIx64 "\n", txt,
397fcf5ef2aSThomas Huth addr, asi, r1 & 0xff);
398fcf5ef2aSThomas Huth break;
399fcf5ef2aSThomas Huth case 2:
400fcf5ef2aSThomas Huth DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %04" PRIx64 "\n", txt,
401fcf5ef2aSThomas Huth addr, asi, r1 & 0xffff);
402fcf5ef2aSThomas Huth break;
403fcf5ef2aSThomas Huth case 4:
404fcf5ef2aSThomas Huth DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %08" PRIx64 "\n", txt,
405fcf5ef2aSThomas Huth addr, asi, r1 & 0xffffffff);
406fcf5ef2aSThomas Huth break;
407fcf5ef2aSThomas Huth case 8:
408fcf5ef2aSThomas Huth DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %016" PRIx64 "\n", txt,
409fcf5ef2aSThomas Huth addr, asi, r1);
410fcf5ef2aSThomas Huth break;
411fcf5ef2aSThomas Huth }
412fcf5ef2aSThomas Huth }
413fcf5ef2aSThomas Huth #endif
414fcf5ef2aSThomas Huth
415c9d793f4SPeter Maydell #ifndef CONFIG_USER_ONLY
416c9d793f4SPeter Maydell #ifndef TARGET_SPARC64
sparc_raise_mmu_fault(CPUState * cs,hwaddr addr,bool is_write,bool is_exec,int is_asi,unsigned size,uintptr_t retaddr)417c9d793f4SPeter Maydell static void sparc_raise_mmu_fault(CPUState *cs, hwaddr addr,
418c9d793f4SPeter Maydell bool is_write, bool is_exec, int is_asi,
419c9d793f4SPeter Maydell unsigned size, uintptr_t retaddr)
420c9d793f4SPeter Maydell {
42177976769SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs);
422c9d793f4SPeter Maydell int fault_type;
423c9d793f4SPeter Maydell
424c9d793f4SPeter Maydell #ifdef DEBUG_UNASSIGNED
425c9d793f4SPeter Maydell if (is_asi) {
426883f2c59SPhilippe Mathieu-Daudé printf("Unassigned mem %s access of %d byte%s to " HWADDR_FMT_plx
427c9d793f4SPeter Maydell " asi 0x%02x from " TARGET_FMT_lx "\n",
428c9d793f4SPeter Maydell is_exec ? "exec" : is_write ? "write" : "read", size,
429c9d793f4SPeter Maydell size == 1 ? "" : "s", addr, is_asi, env->pc);
430c9d793f4SPeter Maydell } else {
431883f2c59SPhilippe Mathieu-Daudé printf("Unassigned mem %s access of %d byte%s to " HWADDR_FMT_plx
432c9d793f4SPeter Maydell " from " TARGET_FMT_lx "\n",
433c9d793f4SPeter Maydell is_exec ? "exec" : is_write ? "write" : "read", size,
434c9d793f4SPeter Maydell size == 1 ? "" : "s", addr, env->pc);
435c9d793f4SPeter Maydell }
436c9d793f4SPeter Maydell #endif
437c9d793f4SPeter Maydell /* Don't overwrite translation and access faults */
438c9d793f4SPeter Maydell fault_type = (env->mmuregs[3] & 0x1c) >> 2;
439c9d793f4SPeter Maydell if ((fault_type > 4) || (fault_type == 0)) {
440c9d793f4SPeter Maydell env->mmuregs[3] = 0; /* Fault status register */
441c9d793f4SPeter Maydell if (is_asi) {
442c9d793f4SPeter Maydell env->mmuregs[3] |= 1 << 16;
443c9d793f4SPeter Maydell }
444c9d793f4SPeter Maydell if (env->psrs) {
445c9d793f4SPeter Maydell env->mmuregs[3] |= 1 << 5;
446c9d793f4SPeter Maydell }
447c9d793f4SPeter Maydell if (is_exec) {
448c9d793f4SPeter Maydell env->mmuregs[3] |= 1 << 6;
449c9d793f4SPeter Maydell }
450c9d793f4SPeter Maydell if (is_write) {
451c9d793f4SPeter Maydell env->mmuregs[3] |= 1 << 7;
452c9d793f4SPeter Maydell }
453c9d793f4SPeter Maydell env->mmuregs[3] |= (5 << 2) | 2;
454c9d793f4SPeter Maydell /* SuperSPARC will never place instruction fault addresses in the FAR */
455c9d793f4SPeter Maydell if (!is_exec) {
456c9d793f4SPeter Maydell env->mmuregs[4] = addr; /* Fault address register */
457c9d793f4SPeter Maydell }
458c9d793f4SPeter Maydell }
459c9d793f4SPeter Maydell /* overflow (same type fault was not read before another fault) */
460c9d793f4SPeter Maydell if (fault_type == ((env->mmuregs[3] & 0x1c)) >> 2) {
461c9d793f4SPeter Maydell env->mmuregs[3] |= 1;
462c9d793f4SPeter Maydell }
463c9d793f4SPeter Maydell
464c9d793f4SPeter Maydell if ((env->mmuregs[0] & MMU_E) && !(env->mmuregs[0] & MMU_NF)) {
465c9d793f4SPeter Maydell int tt = is_exec ? TT_CODE_ACCESS : TT_DATA_ACCESS;
466c9d793f4SPeter Maydell cpu_raise_exception_ra(env, tt, retaddr);
467c9d793f4SPeter Maydell }
468c9d793f4SPeter Maydell
469c9d793f4SPeter Maydell /*
470c9d793f4SPeter Maydell * flush neverland mappings created during no-fault mode,
471c9d793f4SPeter Maydell * so the sequential MMU faults report proper fault types
472c9d793f4SPeter Maydell */
473c9d793f4SPeter Maydell if (env->mmuregs[0] & MMU_NF) {
474c9d793f4SPeter Maydell tlb_flush(cs);
475c9d793f4SPeter Maydell }
476c9d793f4SPeter Maydell }
477c9d793f4SPeter Maydell #else
sparc_raise_mmu_fault(CPUState * cs,hwaddr addr,bool is_write,bool is_exec,int is_asi,unsigned size,uintptr_t retaddr)478c9d793f4SPeter Maydell static void sparc_raise_mmu_fault(CPUState *cs, hwaddr addr,
479c9d793f4SPeter Maydell bool is_write, bool is_exec, int is_asi,
480c9d793f4SPeter Maydell unsigned size, uintptr_t retaddr)
481c9d793f4SPeter Maydell {
48277976769SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs);
483c9d793f4SPeter Maydell
484c9d793f4SPeter Maydell #ifdef DEBUG_UNASSIGNED
485883f2c59SPhilippe Mathieu-Daudé printf("Unassigned mem access to " HWADDR_FMT_plx " from " TARGET_FMT_lx
486c9d793f4SPeter Maydell "\n", addr, env->pc);
487c9d793f4SPeter Maydell #endif
488c9d793f4SPeter Maydell
489c9d793f4SPeter Maydell if (is_exec) { /* XXX has_hypervisor */
490c9d793f4SPeter Maydell if (env->lsu & (IMMU_E)) {
491c9d793f4SPeter Maydell cpu_raise_exception_ra(env, TT_CODE_ACCESS, retaddr);
492c9d793f4SPeter Maydell } else if (cpu_has_hypervisor(env) && !(env->hpstate & HS_PRIV)) {
493c9d793f4SPeter Maydell cpu_raise_exception_ra(env, TT_INSN_REAL_TRANSLATION_MISS, retaddr);
494c9d793f4SPeter Maydell }
495c9d793f4SPeter Maydell } else {
496c9d793f4SPeter Maydell if (env->lsu & (DMMU_E)) {
497c9d793f4SPeter Maydell cpu_raise_exception_ra(env, TT_DATA_ACCESS, retaddr);
498c9d793f4SPeter Maydell } else if (cpu_has_hypervisor(env) && !(env->hpstate & HS_PRIV)) {
499c9d793f4SPeter Maydell cpu_raise_exception_ra(env, TT_DATA_REAL_TRANSLATION_MISS, retaddr);
500c9d793f4SPeter Maydell }
501c9d793f4SPeter Maydell }
502c9d793f4SPeter Maydell }
503c9d793f4SPeter Maydell #endif
504c9d793f4SPeter Maydell #endif
505c9d793f4SPeter Maydell
506fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
507fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
508fcf5ef2aSThomas Huth
509fcf5ef2aSThomas Huth
510fcf5ef2aSThomas Huth /* Leon3 cache control */
511fcf5ef2aSThomas Huth
leon3_cache_control_st(CPUSPARCState * env,target_ulong addr,uint64_t val,int size)512fcf5ef2aSThomas Huth static void leon3_cache_control_st(CPUSPARCState *env, target_ulong addr,
513fcf5ef2aSThomas Huth uint64_t val, int size)
514fcf5ef2aSThomas Huth {
515fcf5ef2aSThomas Huth DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64 ", size:%d\n",
516fcf5ef2aSThomas Huth addr, val, size);
517fcf5ef2aSThomas Huth
518fcf5ef2aSThomas Huth if (size != 4) {
519fcf5ef2aSThomas Huth DPRINTF_CACHE_CONTROL("32bits only\n");
520fcf5ef2aSThomas Huth return;
521fcf5ef2aSThomas Huth }
522fcf5ef2aSThomas Huth
523fcf5ef2aSThomas Huth switch (addr) {
524fcf5ef2aSThomas Huth case 0x00: /* Cache control */
525fcf5ef2aSThomas Huth
526fcf5ef2aSThomas Huth /* These values must always be read as zeros */
527fcf5ef2aSThomas Huth val &= ~CACHE_CTRL_FD;
528fcf5ef2aSThomas Huth val &= ~CACHE_CTRL_FI;
529fcf5ef2aSThomas Huth val &= ~CACHE_CTRL_IB;
530fcf5ef2aSThomas Huth val &= ~CACHE_CTRL_IP;
531fcf5ef2aSThomas Huth val &= ~CACHE_CTRL_DP;
532fcf5ef2aSThomas Huth
533fcf5ef2aSThomas Huth env->cache_control = val;
534fcf5ef2aSThomas Huth break;
535fcf5ef2aSThomas Huth case 0x04: /* Instruction cache configuration */
536fcf5ef2aSThomas Huth case 0x08: /* Data cache configuration */
537fcf5ef2aSThomas Huth /* Read Only */
538fcf5ef2aSThomas Huth break;
539fcf5ef2aSThomas Huth default:
540fcf5ef2aSThomas Huth DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr);
541fcf5ef2aSThomas Huth break;
542fcf5ef2aSThomas Huth };
543fcf5ef2aSThomas Huth }
544fcf5ef2aSThomas Huth
leon3_cache_control_ld(CPUSPARCState * env,target_ulong addr,int size)545fcf5ef2aSThomas Huth static uint64_t leon3_cache_control_ld(CPUSPARCState *env, target_ulong addr,
546fcf5ef2aSThomas Huth int size)
547fcf5ef2aSThomas Huth {
548fcf5ef2aSThomas Huth uint64_t ret = 0;
549fcf5ef2aSThomas Huth
550fcf5ef2aSThomas Huth if (size != 4) {
551fcf5ef2aSThomas Huth DPRINTF_CACHE_CONTROL("32bits only\n");
552fcf5ef2aSThomas Huth return 0;
553fcf5ef2aSThomas Huth }
554fcf5ef2aSThomas Huth
555fcf5ef2aSThomas Huth switch (addr) {
556fcf5ef2aSThomas Huth case 0x00: /* Cache control */
557fcf5ef2aSThomas Huth ret = env->cache_control;
558fcf5ef2aSThomas Huth break;
559fcf5ef2aSThomas Huth
560fcf5ef2aSThomas Huth /* Configuration registers are read and only always keep those
561fcf5ef2aSThomas Huth predefined values */
562fcf5ef2aSThomas Huth
563fcf5ef2aSThomas Huth case 0x04: /* Instruction cache configuration */
564fcf5ef2aSThomas Huth ret = 0x10220000;
565fcf5ef2aSThomas Huth break;
566fcf5ef2aSThomas Huth case 0x08: /* Data cache configuration */
567fcf5ef2aSThomas Huth ret = 0x18220000;
568fcf5ef2aSThomas Huth break;
569fcf5ef2aSThomas Huth default:
570fcf5ef2aSThomas Huth DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr);
571fcf5ef2aSThomas Huth break;
572fcf5ef2aSThomas Huth };
573fcf5ef2aSThomas Huth DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64 ", size:%d\n",
574fcf5ef2aSThomas Huth addr, ret, size);
575fcf5ef2aSThomas Huth return ret;
576fcf5ef2aSThomas Huth }
577fcf5ef2aSThomas Huth
helper_ld_asi(CPUSPARCState * env,target_ulong addr,int asi,uint32_t memop)578fcf5ef2aSThomas Huth uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
579fcf5ef2aSThomas Huth int asi, uint32_t memop)
580fcf5ef2aSThomas Huth {
581fcf5ef2aSThomas Huth int size = 1 << (memop & MO_SIZE);
582fcf5ef2aSThomas Huth int sign = memop & MO_SIGN;
5835a59fbceSRichard Henderson CPUState *cs = env_cpu(env);
584fcf5ef2aSThomas Huth uint64_t ret = 0;
585fcf5ef2aSThomas Huth #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
586fcf5ef2aSThomas Huth uint32_t last_addr = addr;
587fcf5ef2aSThomas Huth #endif
588fcf5ef2aSThomas Huth
589fcf5ef2aSThomas Huth do_check_align(env, addr, size - 1, GETPC());
590fcf5ef2aSThomas Huth switch (asi) {
591fcf5ef2aSThomas Huth case ASI_M_MXCC: /* SuperSparc MXCC registers, or... */
592fcf5ef2aSThomas Huth /* case ASI_LEON_CACHEREGS: Leon3 cache control */
593fcf5ef2aSThomas Huth switch (addr) {
594fcf5ef2aSThomas Huth case 0x00: /* Leon3 Cache Control */
595fcf5ef2aSThomas Huth case 0x08: /* Leon3 Instruction Cache config */
596fcf5ef2aSThomas Huth case 0x0C: /* Leon3 Date Cache config */
597576e1c4cSIgor Mammedov if (env->def.features & CPU_FEATURE_CACHE_CTRL) {
598fcf5ef2aSThomas Huth ret = leon3_cache_control_ld(env, addr, size);
599fcf5ef2aSThomas Huth }
600fcf5ef2aSThomas Huth break;
601fcf5ef2aSThomas Huth case 0x01c00a00: /* MXCC control register */
602fcf5ef2aSThomas Huth if (size == 8) {
603fcf5ef2aSThomas Huth ret = env->mxccregs[3];
604fcf5ef2aSThomas Huth } else {
605fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
606fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
607fcf5ef2aSThomas Huth size);
608fcf5ef2aSThomas Huth }
609fcf5ef2aSThomas Huth break;
610fcf5ef2aSThomas Huth case 0x01c00a04: /* MXCC control register */
611fcf5ef2aSThomas Huth if (size == 4) {
612fcf5ef2aSThomas Huth ret = env->mxccregs[3];
613fcf5ef2aSThomas Huth } else {
614fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
615fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
616fcf5ef2aSThomas Huth size);
617fcf5ef2aSThomas Huth }
618fcf5ef2aSThomas Huth break;
619fcf5ef2aSThomas Huth case 0x01c00c00: /* Module reset register */
620fcf5ef2aSThomas Huth if (size == 8) {
621fcf5ef2aSThomas Huth ret = env->mxccregs[5];
622fcf5ef2aSThomas Huth /* should we do something here? */
623fcf5ef2aSThomas Huth } else {
624fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
625fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
626fcf5ef2aSThomas Huth size);
627fcf5ef2aSThomas Huth }
628fcf5ef2aSThomas Huth break;
629fcf5ef2aSThomas Huth case 0x01c00f00: /* MBus port address register */
630fcf5ef2aSThomas Huth if (size == 8) {
631fcf5ef2aSThomas Huth ret = env->mxccregs[7];
632fcf5ef2aSThomas Huth } else {
633fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
634fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
635fcf5ef2aSThomas Huth size);
636fcf5ef2aSThomas Huth }
637fcf5ef2aSThomas Huth break;
638fcf5ef2aSThomas Huth default:
639fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
640fcf5ef2aSThomas Huth "%08x: unimplemented address, size: %d\n", addr,
641fcf5ef2aSThomas Huth size);
642fcf5ef2aSThomas Huth break;
643fcf5ef2aSThomas Huth }
644fcf5ef2aSThomas Huth DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
645fcf5ef2aSThomas Huth "addr = %08x -> ret = %" PRIx64 ","
646fcf5ef2aSThomas Huth "addr = %08x\n", asi, size, sign, last_addr, ret, addr);
647fcf5ef2aSThomas Huth #ifdef DEBUG_MXCC
648fcf5ef2aSThomas Huth dump_mxcc(env);
649fcf5ef2aSThomas Huth #endif
650fcf5ef2aSThomas Huth break;
651fcf5ef2aSThomas Huth case ASI_M_FLUSH_PROBE: /* SuperSparc MMU probe */
652fcf5ef2aSThomas Huth case ASI_LEON_MMUFLUSH: /* LEON3 MMU probe */
653fcf5ef2aSThomas Huth {
654fcf5ef2aSThomas Huth int mmulev;
655fcf5ef2aSThomas Huth
656fcf5ef2aSThomas Huth mmulev = (addr >> 8) & 15;
657fcf5ef2aSThomas Huth if (mmulev > 4) {
658fcf5ef2aSThomas Huth ret = 0;
659fcf5ef2aSThomas Huth } else {
660fcf5ef2aSThomas Huth ret = mmu_probe(env, addr, mmulev);
661fcf5ef2aSThomas Huth }
662fcf5ef2aSThomas Huth DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64 "\n",
663fcf5ef2aSThomas Huth addr, mmulev, ret);
664fcf5ef2aSThomas Huth }
665fcf5ef2aSThomas Huth break;
666fcf5ef2aSThomas Huth case ASI_M_MMUREGS: /* SuperSparc MMU regs */
667fcf5ef2aSThomas Huth case ASI_LEON_MMUREGS: /* LEON3 MMU regs */
668fcf5ef2aSThomas Huth {
669fcf5ef2aSThomas Huth int reg = (addr >> 8) & 0x1f;
670fcf5ef2aSThomas Huth
671fcf5ef2aSThomas Huth ret = env->mmuregs[reg];
672fcf5ef2aSThomas Huth if (reg == 3) { /* Fault status cleared on read */
673fcf5ef2aSThomas Huth env->mmuregs[3] = 0;
674fcf5ef2aSThomas Huth } else if (reg == 0x13) { /* Fault status read */
675fcf5ef2aSThomas Huth ret = env->mmuregs[3];
676fcf5ef2aSThomas Huth } else if (reg == 0x14) { /* Fault address read */
677fcf5ef2aSThomas Huth ret = env->mmuregs[4];
678fcf5ef2aSThomas Huth }
679fcf5ef2aSThomas Huth DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64 "\n", reg, ret);
680fcf5ef2aSThomas Huth }
681fcf5ef2aSThomas Huth break;
682fcf5ef2aSThomas Huth case ASI_M_TLBDIAG: /* Turbosparc ITLB Diagnostic */
683fcf5ef2aSThomas Huth case ASI_M_DIAGS: /* Turbosparc DTLB Diagnostic */
684fcf5ef2aSThomas Huth case ASI_M_IODIAG: /* Turbosparc IOTLB Diagnostic */
685fcf5ef2aSThomas Huth break;
686fcf5ef2aSThomas Huth case ASI_M_TXTC_TAG: /* SparcStation 5 I-cache tag */
687fcf5ef2aSThomas Huth case ASI_M_TXTC_DATA: /* SparcStation 5 I-cache data */
688fcf5ef2aSThomas Huth case ASI_M_DATAC_TAG: /* SparcStation 5 D-cache tag */
689fcf5ef2aSThomas Huth case ASI_M_DATAC_DATA: /* SparcStation 5 D-cache data */
690fcf5ef2aSThomas Huth break;
691fcf5ef2aSThomas Huth case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
692b9f5fdadSPeter Maydell {
693b9f5fdadSPeter Maydell MemTxResult result;
694b9f5fdadSPeter Maydell hwaddr access_addr = (hwaddr)addr | ((hwaddr)(asi & 0xf) << 32);
695b9f5fdadSPeter Maydell
696fcf5ef2aSThomas Huth switch (size) {
697fcf5ef2aSThomas Huth case 1:
698b9f5fdadSPeter Maydell ret = address_space_ldub(cs->as, access_addr,
699b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
700fcf5ef2aSThomas Huth break;
701fcf5ef2aSThomas Huth case 2:
702b9f5fdadSPeter Maydell ret = address_space_lduw(cs->as, access_addr,
703b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
704fcf5ef2aSThomas Huth break;
705fcf5ef2aSThomas Huth default:
706fcf5ef2aSThomas Huth case 4:
707b9f5fdadSPeter Maydell ret = address_space_ldl(cs->as, access_addr,
708b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
709fcf5ef2aSThomas Huth break;
710fcf5ef2aSThomas Huth case 8:
711b9f5fdadSPeter Maydell ret = address_space_ldq(cs->as, access_addr,
712b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
713fcf5ef2aSThomas Huth break;
714fcf5ef2aSThomas Huth }
715b9f5fdadSPeter Maydell
716b9f5fdadSPeter Maydell if (result != MEMTX_OK) {
717b9f5fdadSPeter Maydell sparc_raise_mmu_fault(cs, access_addr, false, false, false,
718b9f5fdadSPeter Maydell size, GETPC());
719b9f5fdadSPeter Maydell }
720fcf5ef2aSThomas Huth break;
721b9f5fdadSPeter Maydell }
722fcf5ef2aSThomas Huth case 0x30: /* Turbosparc secondary cache diagnostic */
723fcf5ef2aSThomas Huth case 0x31: /* Turbosparc RAM snoop */
724fcf5ef2aSThomas Huth case 0x32: /* Turbosparc page table descriptor diagnostic */
725fcf5ef2aSThomas Huth case 0x39: /* data cache diagnostic register */
726fcf5ef2aSThomas Huth ret = 0;
727fcf5ef2aSThomas Huth break;
728fcf5ef2aSThomas Huth case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
729fcf5ef2aSThomas Huth {
730fcf5ef2aSThomas Huth int reg = (addr >> 8) & 3;
731fcf5ef2aSThomas Huth
732fcf5ef2aSThomas Huth switch (reg) {
733fcf5ef2aSThomas Huth case 0: /* Breakpoint Value (Addr) */
734fcf5ef2aSThomas Huth ret = env->mmubpregs[reg];
735fcf5ef2aSThomas Huth break;
736fcf5ef2aSThomas Huth case 1: /* Breakpoint Mask */
737fcf5ef2aSThomas Huth ret = env->mmubpregs[reg];
738fcf5ef2aSThomas Huth break;
739fcf5ef2aSThomas Huth case 2: /* Breakpoint Control */
740fcf5ef2aSThomas Huth ret = env->mmubpregs[reg];
741fcf5ef2aSThomas Huth break;
742fcf5ef2aSThomas Huth case 3: /* Breakpoint Status */
743fcf5ef2aSThomas Huth ret = env->mmubpregs[reg];
744fcf5ef2aSThomas Huth env->mmubpregs[reg] = 0ULL;
745fcf5ef2aSThomas Huth break;
746fcf5ef2aSThomas Huth }
747fcf5ef2aSThomas Huth DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64 "\n", reg,
748fcf5ef2aSThomas Huth ret);
749fcf5ef2aSThomas Huth }
750fcf5ef2aSThomas Huth break;
751fcf5ef2aSThomas Huth case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
752fcf5ef2aSThomas Huth ret = env->mmubpctrv;
753fcf5ef2aSThomas Huth break;
754fcf5ef2aSThomas Huth case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
755fcf5ef2aSThomas Huth ret = env->mmubpctrc;
756fcf5ef2aSThomas Huth break;
757fcf5ef2aSThomas Huth case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
758fcf5ef2aSThomas Huth ret = env->mmubpctrs;
759fcf5ef2aSThomas Huth break;
760fcf5ef2aSThomas Huth case 0x4c: /* SuperSPARC MMU Breakpoint Action */
761fcf5ef2aSThomas Huth ret = env->mmubpaction;
762fcf5ef2aSThomas Huth break;
763fcf5ef2aSThomas Huth default:
764c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, false, false, asi, size, GETPC());
765fcf5ef2aSThomas Huth ret = 0;
766fcf5ef2aSThomas Huth break;
767fcf5ef2aSThomas Huth
768fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */
769fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */
7702786a3f8SRichard Henderson case ASI_USERTXT: /* User code access */
7712786a3f8SRichard Henderson case ASI_KERNELTXT: /* Supervisor code access */
772fcf5ef2aSThomas Huth case ASI_P: /* Implicit primary context data access (v9 only?) */
773fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */
774fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */
775fcf5ef2aSThomas Huth /* These are always handled inline. */
776fcf5ef2aSThomas Huth g_assert_not_reached();
777fcf5ef2aSThomas Huth }
778fcf5ef2aSThomas Huth if (sign) {
779fcf5ef2aSThomas Huth switch (size) {
780fcf5ef2aSThomas Huth case 1:
781fcf5ef2aSThomas Huth ret = (int8_t) ret;
782fcf5ef2aSThomas Huth break;
783fcf5ef2aSThomas Huth case 2:
784fcf5ef2aSThomas Huth ret = (int16_t) ret;
785fcf5ef2aSThomas Huth break;
786fcf5ef2aSThomas Huth case 4:
787fcf5ef2aSThomas Huth ret = (int32_t) ret;
788fcf5ef2aSThomas Huth break;
789fcf5ef2aSThomas Huth default:
790fcf5ef2aSThomas Huth break;
791fcf5ef2aSThomas Huth }
792fcf5ef2aSThomas Huth }
793fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
794fcf5ef2aSThomas Huth dump_asi("read ", last_addr, asi, size, ret);
795fcf5ef2aSThomas Huth #endif
796fcf5ef2aSThomas Huth return ret;
797fcf5ef2aSThomas Huth }
798fcf5ef2aSThomas Huth
helper_st_asi(CPUSPARCState * env,target_ulong addr,uint64_t val,int asi,uint32_t memop)799fcf5ef2aSThomas Huth void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val,
800fcf5ef2aSThomas Huth int asi, uint32_t memop)
801fcf5ef2aSThomas Huth {
802fcf5ef2aSThomas Huth int size = 1 << (memop & MO_SIZE);
8035a59fbceSRichard Henderson CPUState *cs = env_cpu(env);
804fcf5ef2aSThomas Huth
805fcf5ef2aSThomas Huth do_check_align(env, addr, size - 1, GETPC());
806fcf5ef2aSThomas Huth switch (asi) {
807fcf5ef2aSThomas Huth case ASI_M_MXCC: /* SuperSparc MXCC registers, or... */
808fcf5ef2aSThomas Huth /* case ASI_LEON_CACHEREGS: Leon3 cache control */
809fcf5ef2aSThomas Huth switch (addr) {
810fcf5ef2aSThomas Huth case 0x00: /* Leon3 Cache Control */
811fcf5ef2aSThomas Huth case 0x08: /* Leon3 Instruction Cache config */
812fcf5ef2aSThomas Huth case 0x0C: /* Leon3 Date Cache config */
813576e1c4cSIgor Mammedov if (env->def.features & CPU_FEATURE_CACHE_CTRL) {
814fcf5ef2aSThomas Huth leon3_cache_control_st(env, addr, val, size);
815fcf5ef2aSThomas Huth }
816fcf5ef2aSThomas Huth break;
817fcf5ef2aSThomas Huth
818fcf5ef2aSThomas Huth case 0x01c00000: /* MXCC stream data register 0 */
819fcf5ef2aSThomas Huth if (size == 8) {
820fcf5ef2aSThomas Huth env->mxccdata[0] = val;
821fcf5ef2aSThomas Huth } else {
822fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
823fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
824fcf5ef2aSThomas Huth size);
825fcf5ef2aSThomas Huth }
826fcf5ef2aSThomas Huth break;
827fcf5ef2aSThomas Huth case 0x01c00008: /* MXCC stream data register 1 */
828fcf5ef2aSThomas Huth if (size == 8) {
829fcf5ef2aSThomas Huth env->mxccdata[1] = val;
830fcf5ef2aSThomas Huth } else {
831fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
832fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
833fcf5ef2aSThomas Huth size);
834fcf5ef2aSThomas Huth }
835fcf5ef2aSThomas Huth break;
836fcf5ef2aSThomas Huth case 0x01c00010: /* MXCC stream data register 2 */
837fcf5ef2aSThomas Huth if (size == 8) {
838fcf5ef2aSThomas Huth env->mxccdata[2] = val;
839fcf5ef2aSThomas Huth } else {
840fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
841fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
842fcf5ef2aSThomas Huth size);
843fcf5ef2aSThomas Huth }
844fcf5ef2aSThomas Huth break;
845fcf5ef2aSThomas Huth case 0x01c00018: /* MXCC stream data register 3 */
846fcf5ef2aSThomas Huth if (size == 8) {
847fcf5ef2aSThomas Huth env->mxccdata[3] = val;
848fcf5ef2aSThomas Huth } else {
849fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
850fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
851fcf5ef2aSThomas Huth size);
852fcf5ef2aSThomas Huth }
853fcf5ef2aSThomas Huth break;
854fcf5ef2aSThomas Huth case 0x01c00100: /* MXCC stream source */
855776095d3SPeter Maydell {
856776095d3SPeter Maydell int i;
857776095d3SPeter Maydell
858fcf5ef2aSThomas Huth if (size == 8) {
859fcf5ef2aSThomas Huth env->mxccregs[0] = val;
860fcf5ef2aSThomas Huth } else {
861fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
862fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
863fcf5ef2aSThomas Huth size);
864fcf5ef2aSThomas Huth }
865776095d3SPeter Maydell
866776095d3SPeter Maydell for (i = 0; i < 4; i++) {
867776095d3SPeter Maydell MemTxResult result;
868776095d3SPeter Maydell hwaddr access_addr = (env->mxccregs[0] & 0xffffffffULL) + 8 * i;
869776095d3SPeter Maydell
870776095d3SPeter Maydell env->mxccdata[i] = address_space_ldq(cs->as,
871776095d3SPeter Maydell access_addr,
872776095d3SPeter Maydell MEMTXATTRS_UNSPECIFIED,
873776095d3SPeter Maydell &result);
874776095d3SPeter Maydell if (result != MEMTX_OK) {
875776095d3SPeter Maydell /* TODO: investigate whether this is the right behaviour */
876776095d3SPeter Maydell sparc_raise_mmu_fault(cs, access_addr, false, false,
877776095d3SPeter Maydell false, size, GETPC());
878776095d3SPeter Maydell }
879776095d3SPeter Maydell }
880fcf5ef2aSThomas Huth break;
881776095d3SPeter Maydell }
882fcf5ef2aSThomas Huth case 0x01c00200: /* MXCC stream destination */
883776095d3SPeter Maydell {
884776095d3SPeter Maydell int i;
885776095d3SPeter Maydell
886fcf5ef2aSThomas Huth if (size == 8) {
887fcf5ef2aSThomas Huth env->mxccregs[1] = val;
888fcf5ef2aSThomas Huth } else {
889fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
890fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
891fcf5ef2aSThomas Huth size);
892fcf5ef2aSThomas Huth }
893776095d3SPeter Maydell
894776095d3SPeter Maydell for (i = 0; i < 4; i++) {
895776095d3SPeter Maydell MemTxResult result;
896776095d3SPeter Maydell hwaddr access_addr = (env->mxccregs[1] & 0xffffffffULL) + 8 * i;
897776095d3SPeter Maydell
898776095d3SPeter Maydell address_space_stq(cs->as, access_addr, env->mxccdata[i],
899776095d3SPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
900776095d3SPeter Maydell
901776095d3SPeter Maydell if (result != MEMTX_OK) {
902776095d3SPeter Maydell /* TODO: investigate whether this is the right behaviour */
903776095d3SPeter Maydell sparc_raise_mmu_fault(cs, access_addr, true, false,
904776095d3SPeter Maydell false, size, GETPC());
905776095d3SPeter Maydell }
906776095d3SPeter Maydell }
907fcf5ef2aSThomas Huth break;
908776095d3SPeter Maydell }
909fcf5ef2aSThomas Huth case 0x01c00a00: /* MXCC control register */
910fcf5ef2aSThomas Huth if (size == 8) {
911fcf5ef2aSThomas Huth env->mxccregs[3] = val;
912fcf5ef2aSThomas Huth } else {
913fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
914fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
915fcf5ef2aSThomas Huth size);
916fcf5ef2aSThomas Huth }
917fcf5ef2aSThomas Huth break;
918fcf5ef2aSThomas Huth case 0x01c00a04: /* MXCC control register */
919fcf5ef2aSThomas Huth if (size == 4) {
920fcf5ef2aSThomas Huth env->mxccregs[3] = (env->mxccregs[3] & 0xffffffff00000000ULL)
921fcf5ef2aSThomas Huth | val;
922fcf5ef2aSThomas Huth } else {
923fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
924fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
925fcf5ef2aSThomas Huth size);
926fcf5ef2aSThomas Huth }
927fcf5ef2aSThomas Huth break;
928fcf5ef2aSThomas Huth case 0x01c00e00: /* MXCC error register */
929fcf5ef2aSThomas Huth /* writing a 1 bit clears the error */
930fcf5ef2aSThomas Huth if (size == 8) {
931fcf5ef2aSThomas Huth env->mxccregs[6] &= ~val;
932fcf5ef2aSThomas Huth } else {
933fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
934fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
935fcf5ef2aSThomas Huth size);
936fcf5ef2aSThomas Huth }
937fcf5ef2aSThomas Huth break;
938fcf5ef2aSThomas Huth case 0x01c00f00: /* MBus port address register */
939fcf5ef2aSThomas Huth if (size == 8) {
940fcf5ef2aSThomas Huth env->mxccregs[7] = val;
941fcf5ef2aSThomas Huth } else {
942fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
943fcf5ef2aSThomas Huth "%08x: unimplemented access size: %d\n", addr,
944fcf5ef2aSThomas Huth size);
945fcf5ef2aSThomas Huth }
946fcf5ef2aSThomas Huth break;
947fcf5ef2aSThomas Huth default:
948fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP,
949fcf5ef2aSThomas Huth "%08x: unimplemented address, size: %d\n", addr,
950fcf5ef2aSThomas Huth size);
951fcf5ef2aSThomas Huth break;
952fcf5ef2aSThomas Huth }
953fcf5ef2aSThomas Huth DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64 "\n",
954fcf5ef2aSThomas Huth asi, size, addr, val);
955fcf5ef2aSThomas Huth #ifdef DEBUG_MXCC
956fcf5ef2aSThomas Huth dump_mxcc(env);
957fcf5ef2aSThomas Huth #endif
958fcf5ef2aSThomas Huth break;
959fcf5ef2aSThomas Huth case ASI_M_FLUSH_PROBE: /* SuperSparc MMU flush */
960fcf5ef2aSThomas Huth case ASI_LEON_MMUFLUSH: /* LEON3 MMU flush */
961fcf5ef2aSThomas Huth {
962fcf5ef2aSThomas Huth int mmulev;
963fcf5ef2aSThomas Huth
964fcf5ef2aSThomas Huth mmulev = (addr >> 8) & 15;
965fcf5ef2aSThomas Huth DPRINTF_MMU("mmu flush level %d\n", mmulev);
966fcf5ef2aSThomas Huth switch (mmulev) {
967fcf5ef2aSThomas Huth case 0: /* flush page */
9685a59fbceSRichard Henderson tlb_flush_page(cs, addr & 0xfffff000);
969fcf5ef2aSThomas Huth break;
970fcf5ef2aSThomas Huth case 1: /* flush segment (256k) */
971fcf5ef2aSThomas Huth case 2: /* flush region (16M) */
972fcf5ef2aSThomas Huth case 3: /* flush context (4G) */
973fcf5ef2aSThomas Huth case 4: /* flush entire */
9745a59fbceSRichard Henderson tlb_flush(cs);
975fcf5ef2aSThomas Huth break;
976fcf5ef2aSThomas Huth default:
977fcf5ef2aSThomas Huth break;
978fcf5ef2aSThomas Huth }
979fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
980fad866daSMarkus Armbruster dump_mmu(env);
981fcf5ef2aSThomas Huth #endif
982fcf5ef2aSThomas Huth }
983fcf5ef2aSThomas Huth break;
984fcf5ef2aSThomas Huth case ASI_M_MMUREGS: /* write MMU regs */
985fcf5ef2aSThomas Huth case ASI_LEON_MMUREGS: /* LEON3 write MMU regs */
986fcf5ef2aSThomas Huth {
987fcf5ef2aSThomas Huth int reg = (addr >> 8) & 0x1f;
988fcf5ef2aSThomas Huth uint32_t oldreg;
989fcf5ef2aSThomas Huth
990fcf5ef2aSThomas Huth oldreg = env->mmuregs[reg];
991fcf5ef2aSThomas Huth switch (reg) {
992fcf5ef2aSThomas Huth case 0: /* Control Register */
993fcf5ef2aSThomas Huth env->mmuregs[reg] = (env->mmuregs[reg] & 0xff000000) |
994fcf5ef2aSThomas Huth (val & 0x00ffffff);
995fcf5ef2aSThomas Huth /* Mappings generated during no-fault mode
996fcf5ef2aSThomas Huth are invalid in normal mode. */
997fcf5ef2aSThomas Huth if ((oldreg ^ env->mmuregs[reg])
998576e1c4cSIgor Mammedov & (MMU_NF | env->def.mmu_bm)) {
9995a59fbceSRichard Henderson tlb_flush(cs);
1000fcf5ef2aSThomas Huth }
1001fcf5ef2aSThomas Huth break;
1002fcf5ef2aSThomas Huth case 1: /* Context Table Pointer Register */
1003576e1c4cSIgor Mammedov env->mmuregs[reg] = val & env->def.mmu_ctpr_mask;
1004fcf5ef2aSThomas Huth break;
1005fcf5ef2aSThomas Huth case 2: /* Context Register */
1006576e1c4cSIgor Mammedov env->mmuregs[reg] = val & env->def.mmu_cxr_mask;
1007fcf5ef2aSThomas Huth if (oldreg != env->mmuregs[reg]) {
1008fcf5ef2aSThomas Huth /* we flush when the MMU context changes because
1009fcf5ef2aSThomas Huth QEMU has no MMU context support */
10105a59fbceSRichard Henderson tlb_flush(cs);
1011fcf5ef2aSThomas Huth }
1012fcf5ef2aSThomas Huth break;
1013fcf5ef2aSThomas Huth case 3: /* Synchronous Fault Status Register with Clear */
1014fcf5ef2aSThomas Huth case 4: /* Synchronous Fault Address Register */
1015fcf5ef2aSThomas Huth break;
1016fcf5ef2aSThomas Huth case 0x10: /* TLB Replacement Control Register */
1017576e1c4cSIgor Mammedov env->mmuregs[reg] = val & env->def.mmu_trcr_mask;
1018fcf5ef2aSThomas Huth break;
1019fcf5ef2aSThomas Huth case 0x13: /* Synchronous Fault Status Register with Read
1020fcf5ef2aSThomas Huth and Clear */
1021576e1c4cSIgor Mammedov env->mmuregs[3] = val & env->def.mmu_sfsr_mask;
1022fcf5ef2aSThomas Huth break;
1023fcf5ef2aSThomas Huth case 0x14: /* Synchronous Fault Address Register */
1024fcf5ef2aSThomas Huth env->mmuregs[4] = val;
1025fcf5ef2aSThomas Huth break;
1026fcf5ef2aSThomas Huth default:
1027fcf5ef2aSThomas Huth env->mmuregs[reg] = val;
1028fcf5ef2aSThomas Huth break;
1029fcf5ef2aSThomas Huth }
1030fcf5ef2aSThomas Huth if (oldreg != env->mmuregs[reg]) {
1031fcf5ef2aSThomas Huth DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
1032fcf5ef2aSThomas Huth reg, oldreg, env->mmuregs[reg]);
1033fcf5ef2aSThomas Huth }
1034fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
1035fad866daSMarkus Armbruster dump_mmu(env);
1036fcf5ef2aSThomas Huth #endif
1037fcf5ef2aSThomas Huth }
1038fcf5ef2aSThomas Huth break;
1039fcf5ef2aSThomas Huth case ASI_M_TLBDIAG: /* Turbosparc ITLB Diagnostic */
1040fcf5ef2aSThomas Huth case ASI_M_DIAGS: /* Turbosparc DTLB Diagnostic */
1041fcf5ef2aSThomas Huth case ASI_M_IODIAG: /* Turbosparc IOTLB Diagnostic */
1042fcf5ef2aSThomas Huth break;
1043fcf5ef2aSThomas Huth case ASI_M_TXTC_TAG: /* I-cache tag */
1044fcf5ef2aSThomas Huth case ASI_M_TXTC_DATA: /* I-cache data */
1045fcf5ef2aSThomas Huth case ASI_M_DATAC_TAG: /* D-cache tag */
1046fcf5ef2aSThomas Huth case ASI_M_DATAC_DATA: /* D-cache data */
1047fcf5ef2aSThomas Huth case ASI_M_FLUSH_PAGE: /* I/D-cache flush page */
1048fcf5ef2aSThomas Huth case ASI_M_FLUSH_SEG: /* I/D-cache flush segment */
1049fcf5ef2aSThomas Huth case ASI_M_FLUSH_REGION: /* I/D-cache flush region */
1050fcf5ef2aSThomas Huth case ASI_M_FLUSH_CTX: /* I/D-cache flush context */
1051fcf5ef2aSThomas Huth case ASI_M_FLUSH_USER: /* I/D-cache flush user */
1052fcf5ef2aSThomas Huth break;
1053fcf5ef2aSThomas Huth case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1054fcf5ef2aSThomas Huth {
1055b9f5fdadSPeter Maydell MemTxResult result;
1056b9f5fdadSPeter Maydell hwaddr access_addr = (hwaddr)addr | ((hwaddr)(asi & 0xf) << 32);
1057b9f5fdadSPeter Maydell
1058fcf5ef2aSThomas Huth switch (size) {
1059fcf5ef2aSThomas Huth case 1:
1060b9f5fdadSPeter Maydell address_space_stb(cs->as, access_addr, val,
1061b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
1062fcf5ef2aSThomas Huth break;
1063fcf5ef2aSThomas Huth case 2:
1064b9f5fdadSPeter Maydell address_space_stw(cs->as, access_addr, val,
1065b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
1066fcf5ef2aSThomas Huth break;
1067fcf5ef2aSThomas Huth case 4:
1068fcf5ef2aSThomas Huth default:
1069b9f5fdadSPeter Maydell address_space_stl(cs->as, access_addr, val,
1070b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
1071fcf5ef2aSThomas Huth break;
1072fcf5ef2aSThomas Huth case 8:
1073b9f5fdadSPeter Maydell address_space_stq(cs->as, access_addr, val,
1074b9f5fdadSPeter Maydell MEMTXATTRS_UNSPECIFIED, &result);
1075fcf5ef2aSThomas Huth break;
1076fcf5ef2aSThomas Huth }
1077b9f5fdadSPeter Maydell if (result != MEMTX_OK) {
1078b9f5fdadSPeter Maydell sparc_raise_mmu_fault(cs, access_addr, true, false, false,
1079b9f5fdadSPeter Maydell size, GETPC());
1080b9f5fdadSPeter Maydell }
1081fcf5ef2aSThomas Huth }
1082fcf5ef2aSThomas Huth break;
1083fcf5ef2aSThomas Huth case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1084fcf5ef2aSThomas Huth case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1085fcf5ef2aSThomas Huth Turbosparc snoop RAM */
1086fcf5ef2aSThomas Huth case 0x32: /* store buffer control or Turbosparc page table
1087fcf5ef2aSThomas Huth descriptor diagnostic */
1088fcf5ef2aSThomas Huth case 0x36: /* I-cache flash clear */
1089fcf5ef2aSThomas Huth case 0x37: /* D-cache flash clear */
1090fcf5ef2aSThomas Huth break;
1091fcf5ef2aSThomas Huth case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1092fcf5ef2aSThomas Huth {
1093fcf5ef2aSThomas Huth int reg = (addr >> 8) & 3;
1094fcf5ef2aSThomas Huth
1095fcf5ef2aSThomas Huth switch (reg) {
1096fcf5ef2aSThomas Huth case 0: /* Breakpoint Value (Addr) */
1097fcf5ef2aSThomas Huth env->mmubpregs[reg] = (val & 0xfffffffffULL);
1098fcf5ef2aSThomas Huth break;
1099fcf5ef2aSThomas Huth case 1: /* Breakpoint Mask */
1100fcf5ef2aSThomas Huth env->mmubpregs[reg] = (val & 0xfffffffffULL);
1101fcf5ef2aSThomas Huth break;
1102fcf5ef2aSThomas Huth case 2: /* Breakpoint Control */
1103fcf5ef2aSThomas Huth env->mmubpregs[reg] = (val & 0x7fULL);
1104fcf5ef2aSThomas Huth break;
1105fcf5ef2aSThomas Huth case 3: /* Breakpoint Status */
1106fcf5ef2aSThomas Huth env->mmubpregs[reg] = (val & 0xfULL);
1107fcf5ef2aSThomas Huth break;
1108fcf5ef2aSThomas Huth }
1109fcf5ef2aSThomas Huth DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg,
1110fcf5ef2aSThomas Huth env->mmuregs[reg]);
1111fcf5ef2aSThomas Huth }
1112fcf5ef2aSThomas Huth break;
1113fcf5ef2aSThomas Huth case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1114fcf5ef2aSThomas Huth env->mmubpctrv = val & 0xffffffff;
1115fcf5ef2aSThomas Huth break;
1116fcf5ef2aSThomas Huth case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1117fcf5ef2aSThomas Huth env->mmubpctrc = val & 0x3;
1118fcf5ef2aSThomas Huth break;
1119fcf5ef2aSThomas Huth case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1120fcf5ef2aSThomas Huth env->mmubpctrs = val & 0x3;
1121fcf5ef2aSThomas Huth break;
1122fcf5ef2aSThomas Huth case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1123fcf5ef2aSThomas Huth env->mmubpaction = val & 0x1fff;
1124fcf5ef2aSThomas Huth break;
1125fcf5ef2aSThomas Huth case ASI_USERTXT: /* User code access, XXX */
1126fcf5ef2aSThomas Huth case ASI_KERNELTXT: /* Supervisor code access, XXX */
1127fcf5ef2aSThomas Huth default:
1128c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, true, false, asi, size, GETPC());
1129fcf5ef2aSThomas Huth break;
1130fcf5ef2aSThomas Huth
1131fcf5ef2aSThomas Huth case ASI_USERDATA: /* User data access */
1132fcf5ef2aSThomas Huth case ASI_KERNELDATA: /* Supervisor data access */
1133fcf5ef2aSThomas Huth case ASI_P:
1134fcf5ef2aSThomas Huth case ASI_M_BYPASS: /* MMU passthrough */
1135fcf5ef2aSThomas Huth case ASI_LEON_BYPASS: /* LEON MMU passthrough */
1136fcf5ef2aSThomas Huth case ASI_M_BCOPY: /* Block copy, sta access */
1137fcf5ef2aSThomas Huth case ASI_M_BFILL: /* Block fill, stda access */
1138fcf5ef2aSThomas Huth /* These are always handled inline. */
1139fcf5ef2aSThomas Huth g_assert_not_reached();
1140fcf5ef2aSThomas Huth }
1141fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
1142fcf5ef2aSThomas Huth dump_asi("write", addr, asi, size, val);
1143fcf5ef2aSThomas Huth #endif
1144fcf5ef2aSThomas Huth }
1145fcf5ef2aSThomas Huth
helper_ld_code(CPUSPARCState * env,target_ulong addr,uint32_t oi)11462786a3f8SRichard Henderson uint64_t helper_ld_code(CPUSPARCState *env, target_ulong addr, uint32_t oi)
11472786a3f8SRichard Henderson {
11482786a3f8SRichard Henderson MemOp mop = get_memop(oi);
11492786a3f8SRichard Henderson uintptr_t ra = GETPC();
11502786a3f8SRichard Henderson uint64_t ret;
11512786a3f8SRichard Henderson
11522786a3f8SRichard Henderson switch (mop & MO_SIZE) {
11532786a3f8SRichard Henderson case MO_8:
11542786a3f8SRichard Henderson ret = cpu_ldb_code_mmu(env, addr, oi, ra);
11552786a3f8SRichard Henderson if (mop & MO_SIGN) {
11562786a3f8SRichard Henderson ret = (int8_t)ret;
11572786a3f8SRichard Henderson }
11582786a3f8SRichard Henderson break;
11592786a3f8SRichard Henderson case MO_16:
11602786a3f8SRichard Henderson ret = cpu_ldw_code_mmu(env, addr, oi, ra);
11612786a3f8SRichard Henderson if ((mop & MO_BSWAP) != MO_TE) {
11622786a3f8SRichard Henderson ret = bswap16(ret);
11632786a3f8SRichard Henderson }
11642786a3f8SRichard Henderson if (mop & MO_SIGN) {
11652786a3f8SRichard Henderson ret = (int16_t)ret;
11662786a3f8SRichard Henderson }
11672786a3f8SRichard Henderson break;
11682786a3f8SRichard Henderson case MO_32:
11692786a3f8SRichard Henderson ret = cpu_ldl_code_mmu(env, addr, oi, ra);
11702786a3f8SRichard Henderson if ((mop & MO_BSWAP) != MO_TE) {
11712786a3f8SRichard Henderson ret = bswap32(ret);
11722786a3f8SRichard Henderson }
11732786a3f8SRichard Henderson if (mop & MO_SIGN) {
11742786a3f8SRichard Henderson ret = (int32_t)ret;
11752786a3f8SRichard Henderson }
11762786a3f8SRichard Henderson break;
11772786a3f8SRichard Henderson case MO_64:
11782786a3f8SRichard Henderson ret = cpu_ldq_code_mmu(env, addr, oi, ra);
11792786a3f8SRichard Henderson if ((mop & MO_BSWAP) != MO_TE) {
11802786a3f8SRichard Henderson ret = bswap64(ret);
11812786a3f8SRichard Henderson }
11822786a3f8SRichard Henderson break;
11832786a3f8SRichard Henderson default:
11842786a3f8SRichard Henderson g_assert_not_reached();
11852786a3f8SRichard Henderson }
11862786a3f8SRichard Henderson return ret;
11872786a3f8SRichard Henderson }
11882786a3f8SRichard Henderson
1189fcf5ef2aSThomas Huth #endif /* CONFIG_USER_ONLY */
1190fcf5ef2aSThomas Huth #else /* TARGET_SPARC64 */
1191fcf5ef2aSThomas Huth
1192fcf5ef2aSThomas Huth #ifdef CONFIG_USER_ONLY
helper_ld_asi(CPUSPARCState * env,target_ulong addr,int asi,uint32_t memop)1193fcf5ef2aSThomas Huth uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
1194fcf5ef2aSThomas Huth int asi, uint32_t memop)
1195fcf5ef2aSThomas Huth {
1196fcf5ef2aSThomas Huth int size = 1 << (memop & MO_SIZE);
1197fcf5ef2aSThomas Huth int sign = memop & MO_SIGN;
1198fcf5ef2aSThomas Huth uint64_t ret = 0;
1199fcf5ef2aSThomas Huth
1200fcf5ef2aSThomas Huth if (asi < 0x80) {
1201fcf5ef2aSThomas Huth cpu_raise_exception_ra(env, TT_PRIV_ACT, GETPC());
1202fcf5ef2aSThomas Huth }
1203fcf5ef2aSThomas Huth do_check_align(env, addr, size - 1, GETPC());
1204fcf5ef2aSThomas Huth addr = asi_address_mask(env, asi, addr);
1205fcf5ef2aSThomas Huth
1206fcf5ef2aSThomas Huth switch (asi) {
1207fcf5ef2aSThomas Huth case ASI_PNF: /* Primary no-fault */
1208fcf5ef2aSThomas Huth case ASI_PNFL: /* Primary no-fault LE */
1209fcf5ef2aSThomas Huth case ASI_SNF: /* Secondary no-fault */
1210fcf5ef2aSThomas Huth case ASI_SNFL: /* Secondary no-fault LE */
1211bef6f008SRichard Henderson if (!page_check_range(addr, size, PAGE_READ)) {
1212fcf5ef2aSThomas Huth ret = 0;
1213fcf5ef2aSThomas Huth break;
1214fcf5ef2aSThomas Huth }
1215fcf5ef2aSThomas Huth switch (size) {
1216fcf5ef2aSThomas Huth case 1:
1217fcf5ef2aSThomas Huth ret = cpu_ldub_data(env, addr);
1218fcf5ef2aSThomas Huth break;
1219fcf5ef2aSThomas Huth case 2:
1220fcf5ef2aSThomas Huth ret = cpu_lduw_data(env, addr);
1221fcf5ef2aSThomas Huth break;
1222fcf5ef2aSThomas Huth case 4:
1223fcf5ef2aSThomas Huth ret = cpu_ldl_data(env, addr);
1224fcf5ef2aSThomas Huth break;
1225fcf5ef2aSThomas Huth case 8:
1226fcf5ef2aSThomas Huth ret = cpu_ldq_data(env, addr);
1227fcf5ef2aSThomas Huth break;
1228fcf5ef2aSThomas Huth default:
1229fcf5ef2aSThomas Huth g_assert_not_reached();
1230fcf5ef2aSThomas Huth }
1231fcf5ef2aSThomas Huth break;
1232fcf5ef2aSThomas Huth break;
1233fcf5ef2aSThomas Huth
1234fcf5ef2aSThomas Huth case ASI_P: /* Primary */
1235fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */
1236fcf5ef2aSThomas Huth case ASI_S: /* Secondary */
1237fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */
1238fcf5ef2aSThomas Huth /* These are always handled inline. */
1239fcf5ef2aSThomas Huth g_assert_not_reached();
1240fcf5ef2aSThomas Huth
1241fcf5ef2aSThomas Huth default:
1242fcf5ef2aSThomas Huth cpu_raise_exception_ra(env, TT_DATA_ACCESS, GETPC());
1243fcf5ef2aSThomas Huth }
1244fcf5ef2aSThomas Huth
1245fcf5ef2aSThomas Huth /* Convert from little endian */
1246fcf5ef2aSThomas Huth switch (asi) {
1247fcf5ef2aSThomas Huth case ASI_PNFL: /* Primary no-fault LE */
1248fcf5ef2aSThomas Huth case ASI_SNFL: /* Secondary no-fault LE */
1249fcf5ef2aSThomas Huth switch (size) {
1250fcf5ef2aSThomas Huth case 2:
1251fcf5ef2aSThomas Huth ret = bswap16(ret);
1252fcf5ef2aSThomas Huth break;
1253fcf5ef2aSThomas Huth case 4:
1254fcf5ef2aSThomas Huth ret = bswap32(ret);
1255fcf5ef2aSThomas Huth break;
1256fcf5ef2aSThomas Huth case 8:
1257fcf5ef2aSThomas Huth ret = bswap64(ret);
1258fcf5ef2aSThomas Huth break;
1259fcf5ef2aSThomas Huth }
1260fcf5ef2aSThomas Huth }
1261fcf5ef2aSThomas Huth
1262fcf5ef2aSThomas Huth /* Convert to signed number */
1263fcf5ef2aSThomas Huth if (sign) {
1264fcf5ef2aSThomas Huth switch (size) {
1265fcf5ef2aSThomas Huth case 1:
1266fcf5ef2aSThomas Huth ret = (int8_t) ret;
1267fcf5ef2aSThomas Huth break;
1268fcf5ef2aSThomas Huth case 2:
1269fcf5ef2aSThomas Huth ret = (int16_t) ret;
1270fcf5ef2aSThomas Huth break;
1271fcf5ef2aSThomas Huth case 4:
1272fcf5ef2aSThomas Huth ret = (int32_t) ret;
1273fcf5ef2aSThomas Huth break;
1274fcf5ef2aSThomas Huth }
1275fcf5ef2aSThomas Huth }
1276fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
1277fcf5ef2aSThomas Huth dump_asi("read", addr, asi, size, ret);
1278fcf5ef2aSThomas Huth #endif
1279fcf5ef2aSThomas Huth return ret;
1280fcf5ef2aSThomas Huth }
1281fcf5ef2aSThomas Huth
helper_st_asi(CPUSPARCState * env,target_ulong addr,target_ulong val,int asi,uint32_t memop)1282fcf5ef2aSThomas Huth void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val,
1283fcf5ef2aSThomas Huth int asi, uint32_t memop)
1284fcf5ef2aSThomas Huth {
1285fcf5ef2aSThomas Huth int size = 1 << (memop & MO_SIZE);
1286fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
1287fcf5ef2aSThomas Huth dump_asi("write", addr, asi, size, val);
1288fcf5ef2aSThomas Huth #endif
1289fcf5ef2aSThomas Huth if (asi < 0x80) {
1290fcf5ef2aSThomas Huth cpu_raise_exception_ra(env, TT_PRIV_ACT, GETPC());
1291fcf5ef2aSThomas Huth }
1292fcf5ef2aSThomas Huth do_check_align(env, addr, size - 1, GETPC());
1293fcf5ef2aSThomas Huth
1294fcf5ef2aSThomas Huth switch (asi) {
1295fcf5ef2aSThomas Huth case ASI_P: /* Primary */
1296fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */
1297fcf5ef2aSThomas Huth case ASI_S: /* Secondary */
1298fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */
1299fcf5ef2aSThomas Huth /* These are always handled inline. */
1300fcf5ef2aSThomas Huth g_assert_not_reached();
1301fcf5ef2aSThomas Huth
1302fcf5ef2aSThomas Huth case ASI_PNF: /* Primary no-fault, RO */
1303fcf5ef2aSThomas Huth case ASI_SNF: /* Secondary no-fault, RO */
1304fcf5ef2aSThomas Huth case ASI_PNFL: /* Primary no-fault LE, RO */
1305fcf5ef2aSThomas Huth case ASI_SNFL: /* Secondary no-fault LE, RO */
1306fcf5ef2aSThomas Huth default:
1307fcf5ef2aSThomas Huth cpu_raise_exception_ra(env, TT_DATA_ACCESS, GETPC());
1308fcf5ef2aSThomas Huth }
1309fcf5ef2aSThomas Huth }
1310fcf5ef2aSThomas Huth
1311fcf5ef2aSThomas Huth #else /* CONFIG_USER_ONLY */
1312fcf5ef2aSThomas Huth
helper_ld_asi(CPUSPARCState * env,target_ulong addr,int asi,uint32_t memop)1313fcf5ef2aSThomas Huth uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr,
1314fcf5ef2aSThomas Huth int asi, uint32_t memop)
1315fcf5ef2aSThomas Huth {
1316fcf5ef2aSThomas Huth int size = 1 << (memop & MO_SIZE);
1317fcf5ef2aSThomas Huth int sign = memop & MO_SIGN;
13185a59fbceSRichard Henderson CPUState *cs = env_cpu(env);
1319fcf5ef2aSThomas Huth uint64_t ret = 0;
1320fcf5ef2aSThomas Huth #if defined(DEBUG_ASI)
1321fcf5ef2aSThomas Huth target_ulong last_addr = addr;
1322fcf5ef2aSThomas Huth #endif
1323fcf5ef2aSThomas Huth
1324fcf5ef2aSThomas Huth asi &= 0xff;
1325fcf5ef2aSThomas Huth
13267cd39ef2SArtyom Tarasenko do_check_asi(env, asi, GETPC());
1327fcf5ef2aSThomas Huth do_check_align(env, addr, size - 1, GETPC());
1328fcf5ef2aSThomas Huth addr = asi_address_mask(env, asi, addr);
1329fcf5ef2aSThomas Huth
1330fcf5ef2aSThomas Huth switch (asi) {
1331fcf5ef2aSThomas Huth case ASI_PNF:
1332fcf5ef2aSThomas Huth case ASI_PNFL:
1333fcf5ef2aSThomas Huth case ASI_SNF:
1334fcf5ef2aSThomas Huth case ASI_SNFL:
1335fcf5ef2aSThomas Huth {
13369002ffcbSRichard Henderson MemOpIdx oi;
1337fcf5ef2aSThomas Huth int idx = (env->pstate & PS_PRIV
1338fcf5ef2aSThomas Huth ? (asi & 1 ? MMU_KERNEL_SECONDARY_IDX : MMU_KERNEL_IDX)
1339fcf5ef2aSThomas Huth : (asi & 1 ? MMU_USER_SECONDARY_IDX : MMU_USER_IDX));
1340fcf5ef2aSThomas Huth
1341fcf5ef2aSThomas Huth if (cpu_get_phys_page_nofault(env, addr, idx) == -1ULL) {
1342fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
1343fcf5ef2aSThomas Huth dump_asi("read ", last_addr, asi, size, ret);
1344fcf5ef2aSThomas Huth #endif
1345fcf5ef2aSThomas Huth /* exception_index is set in get_physical_address_data. */
1346fcf5ef2aSThomas Huth cpu_raise_exception_ra(env, cs->exception_index, GETPC());
1347fcf5ef2aSThomas Huth }
1348fcf5ef2aSThomas Huth oi = make_memop_idx(memop, idx);
1349fcf5ef2aSThomas Huth switch (size) {
1350fcf5ef2aSThomas Huth case 1:
1351a8f84958SRichard Henderson ret = cpu_ldb_mmu(env, addr, oi, GETPC());
1352fcf5ef2aSThomas Huth break;
1353fcf5ef2aSThomas Huth case 2:
1354fbea7a40SRichard Henderson ret = cpu_ldw_mmu(env, addr, oi, GETPC());
1355fcf5ef2aSThomas Huth break;
1356fcf5ef2aSThomas Huth case 4:
1357fbea7a40SRichard Henderson ret = cpu_ldl_mmu(env, addr, oi, GETPC());
1358fcf5ef2aSThomas Huth break;
1359fcf5ef2aSThomas Huth case 8:
1360fbea7a40SRichard Henderson ret = cpu_ldq_mmu(env, addr, oi, GETPC());
1361fcf5ef2aSThomas Huth break;
1362fcf5ef2aSThomas Huth default:
1363fcf5ef2aSThomas Huth g_assert_not_reached();
1364fcf5ef2aSThomas Huth }
1365fcf5ef2aSThomas Huth }
1366fcf5ef2aSThomas Huth break;
1367fcf5ef2aSThomas Huth
1368fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */
1369fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */
1370fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */
1371fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */
1372fcf5ef2aSThomas Huth case ASI_P: /* Primary */
1373fcf5ef2aSThomas Huth case ASI_S: /* Secondary */
1374fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */
1375fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */
1376fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */
1377fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */
1378fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */
1379fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1380fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */
1381fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus Little Endian (LE) */
1382fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: /* Nucleus quad LDD 128 bit atomic */
1383fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: /* Nucleus quad LDD 128 bit atomic LE */
1384fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: /* As if user primary, twinx */
1385fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: /* As if user secondary, twinx */
1386fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */
1387fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: /* As if user primary, twinx, LE */
1388fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: /* As if user secondary, twinx, LE */
1389fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1390fcf5ef2aSThomas Huth case ASI_TWINX_N: /* Nucleus, twinx */
1391fcf5ef2aSThomas Huth case ASI_TWINX_NL: /* Nucleus, twinx, LE */
1392fcf5ef2aSThomas Huth /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1393fcf5ef2aSThomas Huth case ASI_TWINX_P: /* Primary, twinx */
1394fcf5ef2aSThomas Huth case ASI_TWINX_PL: /* Primary, twinx, LE */
1395fcf5ef2aSThomas Huth case ASI_TWINX_S: /* Secondary, twinx */
1396fcf5ef2aSThomas Huth case ASI_TWINX_SL: /* Secondary, twinx, LE */
1397eeb3f592SRichard Henderson case ASI_MON_P:
1398eeb3f592SRichard Henderson case ASI_MON_S:
1399eeb3f592SRichard Henderson case ASI_MON_AIUP:
1400eeb3f592SRichard Henderson case ASI_MON_AIUS:
1401fcf5ef2aSThomas Huth /* These are always handled inline. */
1402fcf5ef2aSThomas Huth g_assert_not_reached();
1403fcf5ef2aSThomas Huth
1404fcf5ef2aSThomas Huth case ASI_UPA_CONFIG: /* UPA config */
1405fcf5ef2aSThomas Huth /* XXX */
1406fcf5ef2aSThomas Huth break;
1407fcf5ef2aSThomas Huth case ASI_LSU_CONTROL: /* LSU */
1408fcf5ef2aSThomas Huth ret = env->lsu;
1409fcf5ef2aSThomas Huth break;
1410fcf5ef2aSThomas Huth case ASI_IMMU: /* I-MMU regs */
1411fcf5ef2aSThomas Huth {
1412fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0xf;
141320395e63SArtyom Tarasenko switch (reg) {
141420395e63SArtyom Tarasenko case 0:
141520395e63SArtyom Tarasenko /* 0x00 I-TSB Tag Target register */
1416fcf5ef2aSThomas Huth ret = ultrasparc_tag_target(env->immu.tag_access);
141720395e63SArtyom Tarasenko break;
141820395e63SArtyom Tarasenko case 3: /* SFSR */
141920395e63SArtyom Tarasenko ret = env->immu.sfsr;
142020395e63SArtyom Tarasenko break;
142120395e63SArtyom Tarasenko case 5: /* TSB access */
142220395e63SArtyom Tarasenko ret = env->immu.tsb;
142320395e63SArtyom Tarasenko break;
142420395e63SArtyom Tarasenko case 6:
142520395e63SArtyom Tarasenko /* 0x30 I-TSB Tag Access register */
142620395e63SArtyom Tarasenko ret = env->immu.tag_access;
142720395e63SArtyom Tarasenko break;
142820395e63SArtyom Tarasenko default:
1429c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, false, false, 1, size, GETPC());
143020395e63SArtyom Tarasenko ret = 0;
1431fcf5ef2aSThomas Huth }
1432fcf5ef2aSThomas Huth break;
1433fcf5ef2aSThomas Huth }
1434fcf5ef2aSThomas Huth case ASI_IMMU_TSB_8KB_PTR: /* I-MMU 8k TSB pointer */
1435fcf5ef2aSThomas Huth {
1436fcf5ef2aSThomas Huth /* env->immuregs[5] holds I-MMU TSB register value
1437fcf5ef2aSThomas Huth env->immuregs[6] holds I-MMU Tag Access register value */
1438e5673ee4SArtyom Tarasenko ret = ultrasparc_tsb_pointer(env, &env->immu, 0);
1439fcf5ef2aSThomas Huth break;
1440fcf5ef2aSThomas Huth }
1441fcf5ef2aSThomas Huth case ASI_IMMU_TSB_64KB_PTR: /* I-MMU 64k TSB pointer */
1442fcf5ef2aSThomas Huth {
1443fcf5ef2aSThomas Huth /* env->immuregs[5] holds I-MMU TSB register value
1444fcf5ef2aSThomas Huth env->immuregs[6] holds I-MMU Tag Access register value */
1445e5673ee4SArtyom Tarasenko ret = ultrasparc_tsb_pointer(env, &env->immu, 1);
1446fcf5ef2aSThomas Huth break;
1447fcf5ef2aSThomas Huth }
1448fcf5ef2aSThomas Huth case ASI_ITLB_DATA_ACCESS: /* I-MMU data access */
1449fcf5ef2aSThomas Huth {
1450fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0x3f;
1451fcf5ef2aSThomas Huth
1452fcf5ef2aSThomas Huth ret = env->itlb[reg].tte;
1453fcf5ef2aSThomas Huth break;
1454fcf5ef2aSThomas Huth }
1455fcf5ef2aSThomas Huth case ASI_ITLB_TAG_READ: /* I-MMU tag read */
1456fcf5ef2aSThomas Huth {
1457fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0x3f;
1458fcf5ef2aSThomas Huth
1459fcf5ef2aSThomas Huth ret = env->itlb[reg].tag;
1460fcf5ef2aSThomas Huth break;
1461fcf5ef2aSThomas Huth }
1462fcf5ef2aSThomas Huth case ASI_DMMU: /* D-MMU regs */
1463fcf5ef2aSThomas Huth {
1464fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0xf;
146520395e63SArtyom Tarasenko switch (reg) {
146620395e63SArtyom Tarasenko case 0:
146720395e63SArtyom Tarasenko /* 0x00 D-TSB Tag Target register */
1468fcf5ef2aSThomas Huth ret = ultrasparc_tag_target(env->dmmu.tag_access);
146920395e63SArtyom Tarasenko break;
147020395e63SArtyom Tarasenko case 1: /* 0x08 Primary Context */
147120395e63SArtyom Tarasenko ret = env->dmmu.mmu_primary_context;
147220395e63SArtyom Tarasenko break;
147320395e63SArtyom Tarasenko case 2: /* 0x10 Secondary Context */
147420395e63SArtyom Tarasenko ret = env->dmmu.mmu_secondary_context;
147520395e63SArtyom Tarasenko break;
147620395e63SArtyom Tarasenko case 3: /* SFSR */
147720395e63SArtyom Tarasenko ret = env->dmmu.sfsr;
147820395e63SArtyom Tarasenko break;
147920395e63SArtyom Tarasenko case 4: /* 0x20 SFAR */
148020395e63SArtyom Tarasenko ret = env->dmmu.sfar;
148120395e63SArtyom Tarasenko break;
148220395e63SArtyom Tarasenko case 5: /* 0x28 TSB access */
148320395e63SArtyom Tarasenko ret = env->dmmu.tsb;
148420395e63SArtyom Tarasenko break;
148520395e63SArtyom Tarasenko case 6: /* 0x30 D-TSB Tag Access register */
148620395e63SArtyom Tarasenko ret = env->dmmu.tag_access;
148720395e63SArtyom Tarasenko break;
148820395e63SArtyom Tarasenko case 7:
148920395e63SArtyom Tarasenko ret = env->dmmu.virtual_watchpoint;
149020395e63SArtyom Tarasenko break;
149120395e63SArtyom Tarasenko case 8:
149220395e63SArtyom Tarasenko ret = env->dmmu.physical_watchpoint;
149320395e63SArtyom Tarasenko break;
149420395e63SArtyom Tarasenko default:
1495c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, false, false, 1, size, GETPC());
149620395e63SArtyom Tarasenko ret = 0;
1497fcf5ef2aSThomas Huth }
1498fcf5ef2aSThomas Huth break;
1499fcf5ef2aSThomas Huth }
1500fcf5ef2aSThomas Huth case ASI_DMMU_TSB_8KB_PTR: /* D-MMU 8k TSB pointer */
1501fcf5ef2aSThomas Huth {
1502fcf5ef2aSThomas Huth /* env->dmmuregs[5] holds D-MMU TSB register value
1503fcf5ef2aSThomas Huth env->dmmuregs[6] holds D-MMU Tag Access register value */
1504e5673ee4SArtyom Tarasenko ret = ultrasparc_tsb_pointer(env, &env->dmmu, 0);
1505fcf5ef2aSThomas Huth break;
1506fcf5ef2aSThomas Huth }
1507fcf5ef2aSThomas Huth case ASI_DMMU_TSB_64KB_PTR: /* D-MMU 64k TSB pointer */
1508fcf5ef2aSThomas Huth {
1509fcf5ef2aSThomas Huth /* env->dmmuregs[5] holds D-MMU TSB register value
1510fcf5ef2aSThomas Huth env->dmmuregs[6] holds D-MMU Tag Access register value */
1511e5673ee4SArtyom Tarasenko ret = ultrasparc_tsb_pointer(env, &env->dmmu, 1);
1512fcf5ef2aSThomas Huth break;
1513fcf5ef2aSThomas Huth }
1514fcf5ef2aSThomas Huth case ASI_DTLB_DATA_ACCESS: /* D-MMU data access */
1515fcf5ef2aSThomas Huth {
1516fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0x3f;
1517fcf5ef2aSThomas Huth
1518fcf5ef2aSThomas Huth ret = env->dtlb[reg].tte;
1519fcf5ef2aSThomas Huth break;
1520fcf5ef2aSThomas Huth }
1521fcf5ef2aSThomas Huth case ASI_DTLB_TAG_READ: /* D-MMU tag read */
1522fcf5ef2aSThomas Huth {
1523fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0x3f;
1524fcf5ef2aSThomas Huth
1525fcf5ef2aSThomas Huth ret = env->dtlb[reg].tag;
1526fcf5ef2aSThomas Huth break;
1527fcf5ef2aSThomas Huth }
1528fcf5ef2aSThomas Huth case ASI_INTR_DISPATCH_STAT: /* Interrupt dispatch, RO */
1529fcf5ef2aSThomas Huth break;
1530fcf5ef2aSThomas Huth case ASI_INTR_RECEIVE: /* Interrupt data receive */
1531fcf5ef2aSThomas Huth ret = env->ivec_status;
1532fcf5ef2aSThomas Huth break;
1533fcf5ef2aSThomas Huth case ASI_INTR_R: /* Incoming interrupt vector, RO */
1534fcf5ef2aSThomas Huth {
1535fcf5ef2aSThomas Huth int reg = (addr >> 4) & 0x3;
1536fcf5ef2aSThomas Huth if (reg < 3) {
1537fcf5ef2aSThomas Huth ret = env->ivec_data[reg];
1538fcf5ef2aSThomas Huth }
1539fcf5ef2aSThomas Huth break;
1540fcf5ef2aSThomas Huth }
15414ec3e346SArtyom Tarasenko case ASI_SCRATCHPAD: /* UA2005 privileged scratchpad */
15424ec3e346SArtyom Tarasenko if (unlikely((addr >= 0x20) && (addr < 0x30))) {
15434ec3e346SArtyom Tarasenko /* Hyperprivileged access only */
1544c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, false, false, 1, size, GETPC());
15454ec3e346SArtyom Tarasenko }
15464ec3e346SArtyom Tarasenko /* fall through */
15474ec3e346SArtyom Tarasenko case ASI_HYP_SCRATCHPAD: /* UA2005 hyperprivileged scratchpad */
15484ec3e346SArtyom Tarasenko {
15494ec3e346SArtyom Tarasenko unsigned int i = (addr >> 3) & 0x7;
15504ec3e346SArtyom Tarasenko ret = env->scratch[i];
15514ec3e346SArtyom Tarasenko break;
15524ec3e346SArtyom Tarasenko }
15537dd8c076SArtyom Tarasenko case ASI_MMU: /* UA2005 Context ID registers */
15547dd8c076SArtyom Tarasenko switch ((addr >> 3) & 0x3) {
15557dd8c076SArtyom Tarasenko case 1:
15567dd8c076SArtyom Tarasenko ret = env->dmmu.mmu_primary_context;
15577dd8c076SArtyom Tarasenko break;
15587dd8c076SArtyom Tarasenko case 2:
15597dd8c076SArtyom Tarasenko ret = env->dmmu.mmu_secondary_context;
15607dd8c076SArtyom Tarasenko break;
15617dd8c076SArtyom Tarasenko default:
1562c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, true, false, 1, size, GETPC());
15637dd8c076SArtyom Tarasenko }
15647dd8c076SArtyom Tarasenko break;
1565fcf5ef2aSThomas Huth case ASI_DCACHE_DATA: /* D-cache data */
1566fcf5ef2aSThomas Huth case ASI_DCACHE_TAG: /* D-cache tag access */
1567fcf5ef2aSThomas Huth case ASI_ESTATE_ERROR_EN: /* E-cache error enable */
1568fcf5ef2aSThomas Huth case ASI_AFSR: /* E-cache asynchronous fault status */
1569fcf5ef2aSThomas Huth case ASI_AFAR: /* E-cache asynchronous fault address */
1570fcf5ef2aSThomas Huth case ASI_EC_TAG_DATA: /* E-cache tag data */
1571fcf5ef2aSThomas Huth case ASI_IC_INSTR: /* I-cache instruction access */
1572fcf5ef2aSThomas Huth case ASI_IC_TAG: /* I-cache tag access */
1573fcf5ef2aSThomas Huth case ASI_IC_PRE_DECODE: /* I-cache predecode */
1574fcf5ef2aSThomas Huth case ASI_IC_NEXT_FIELD: /* I-cache LRU etc. */
1575fcf5ef2aSThomas Huth case ASI_EC_W: /* E-cache tag */
1576fcf5ef2aSThomas Huth case ASI_EC_R: /* E-cache tag */
1577fcf5ef2aSThomas Huth break;
1578fcf5ef2aSThomas Huth case ASI_DMMU_TSB_DIRECT_PTR: /* D-MMU data pointer */
1579fcf5ef2aSThomas Huth case ASI_ITLB_DATA_IN: /* I-MMU data in, WO */
1580fcf5ef2aSThomas Huth case ASI_IMMU_DEMAP: /* I-MMU demap, WO */
1581fcf5ef2aSThomas Huth case ASI_DTLB_DATA_IN: /* D-MMU data in, WO */
1582fcf5ef2aSThomas Huth case ASI_DMMU_DEMAP: /* D-MMU demap, WO */
1583fcf5ef2aSThomas Huth case ASI_INTR_W: /* Interrupt vector, WO */
1584fcf5ef2aSThomas Huth default:
1585c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, false, false, 1, size, GETPC());
1586fcf5ef2aSThomas Huth ret = 0;
1587fcf5ef2aSThomas Huth break;
1588fcf5ef2aSThomas Huth }
1589fcf5ef2aSThomas Huth
1590fcf5ef2aSThomas Huth /* Convert to signed number */
1591fcf5ef2aSThomas Huth if (sign) {
1592fcf5ef2aSThomas Huth switch (size) {
1593fcf5ef2aSThomas Huth case 1:
1594fcf5ef2aSThomas Huth ret = (int8_t) ret;
1595fcf5ef2aSThomas Huth break;
1596fcf5ef2aSThomas Huth case 2:
1597fcf5ef2aSThomas Huth ret = (int16_t) ret;
1598fcf5ef2aSThomas Huth break;
1599fcf5ef2aSThomas Huth case 4:
1600fcf5ef2aSThomas Huth ret = (int32_t) ret;
1601fcf5ef2aSThomas Huth break;
1602fcf5ef2aSThomas Huth default:
1603fcf5ef2aSThomas Huth break;
1604fcf5ef2aSThomas Huth }
1605fcf5ef2aSThomas Huth }
1606fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
1607fcf5ef2aSThomas Huth dump_asi("read ", last_addr, asi, size, ret);
1608fcf5ef2aSThomas Huth #endif
1609fcf5ef2aSThomas Huth return ret;
1610fcf5ef2aSThomas Huth }
1611fcf5ef2aSThomas Huth
helper_st_asi(CPUSPARCState * env,target_ulong addr,target_ulong val,int asi,uint32_t memop)1612fcf5ef2aSThomas Huth void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val,
1613fcf5ef2aSThomas Huth int asi, uint32_t memop)
1614fcf5ef2aSThomas Huth {
1615fcf5ef2aSThomas Huth int size = 1 << (memop & MO_SIZE);
16165a59fbceSRichard Henderson CPUState *cs = env_cpu(env);
1617fcf5ef2aSThomas Huth
1618fcf5ef2aSThomas Huth #ifdef DEBUG_ASI
1619fcf5ef2aSThomas Huth dump_asi("write", addr, asi, size, val);
1620fcf5ef2aSThomas Huth #endif
1621fcf5ef2aSThomas Huth
1622fcf5ef2aSThomas Huth asi &= 0xff;
1623fcf5ef2aSThomas Huth
16247cd39ef2SArtyom Tarasenko do_check_asi(env, asi, GETPC());
1625fcf5ef2aSThomas Huth do_check_align(env, addr, size - 1, GETPC());
1626fcf5ef2aSThomas Huth addr = asi_address_mask(env, asi, addr);
1627fcf5ef2aSThomas Huth
1628fcf5ef2aSThomas Huth switch (asi) {
1629fcf5ef2aSThomas Huth case ASI_AIUP: /* As if user primary */
1630fcf5ef2aSThomas Huth case ASI_AIUS: /* As if user secondary */
1631fcf5ef2aSThomas Huth case ASI_AIUPL: /* As if user primary LE */
1632fcf5ef2aSThomas Huth case ASI_AIUSL: /* As if user secondary LE */
1633fcf5ef2aSThomas Huth case ASI_P: /* Primary */
1634fcf5ef2aSThomas Huth case ASI_S: /* Secondary */
1635fcf5ef2aSThomas Huth case ASI_PL: /* Primary LE */
1636fcf5ef2aSThomas Huth case ASI_SL: /* Secondary LE */
1637fcf5ef2aSThomas Huth case ASI_REAL: /* Bypass */
1638fcf5ef2aSThomas Huth case ASI_REAL_IO: /* Bypass, non-cacheable */
1639fcf5ef2aSThomas Huth case ASI_REAL_L: /* Bypass LE */
1640fcf5ef2aSThomas Huth case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */
1641fcf5ef2aSThomas Huth case ASI_N: /* Nucleus */
1642fcf5ef2aSThomas Huth case ASI_NL: /* Nucleus Little Endian (LE) */
1643fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD: /* Nucleus quad LDD 128 bit atomic */
1644fcf5ef2aSThomas Huth case ASI_NUCLEUS_QUAD_LDD_L: /* Nucleus quad LDD 128 bit atomic LE */
1645fcf5ef2aSThomas Huth case ASI_TWINX_AIUP: /* As if user primary, twinx */
1646fcf5ef2aSThomas Huth case ASI_TWINX_AIUS: /* As if user secondary, twinx */
1647fcf5ef2aSThomas Huth case ASI_TWINX_REAL: /* Real address, twinx */
1648fcf5ef2aSThomas Huth case ASI_TWINX_AIUP_L: /* As if user primary, twinx, LE */
1649fcf5ef2aSThomas Huth case ASI_TWINX_AIUS_L: /* As if user secondary, twinx, LE */
1650fcf5ef2aSThomas Huth case ASI_TWINX_REAL_L: /* Real address, twinx, LE */
1651fcf5ef2aSThomas Huth case ASI_TWINX_N: /* Nucleus, twinx */
1652fcf5ef2aSThomas Huth case ASI_TWINX_NL: /* Nucleus, twinx, LE */
1653fcf5ef2aSThomas Huth /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */
1654fcf5ef2aSThomas Huth case ASI_TWINX_P: /* Primary, twinx */
1655fcf5ef2aSThomas Huth case ASI_TWINX_PL: /* Primary, twinx, LE */
1656fcf5ef2aSThomas Huth case ASI_TWINX_S: /* Secondary, twinx */
1657fcf5ef2aSThomas Huth case ASI_TWINX_SL: /* Secondary, twinx, LE */
1658fcf5ef2aSThomas Huth /* These are always handled inline. */
1659fcf5ef2aSThomas Huth g_assert_not_reached();
166015f746ceSArtyom Tarasenko /* these ASIs have different functions on UltraSPARC-IIIi
166115f746ceSArtyom Tarasenko * and UA2005 CPUs. Use the explicit numbers to avoid confusion
166215f746ceSArtyom Tarasenko */
166315f746ceSArtyom Tarasenko case 0x31:
166415f746ceSArtyom Tarasenko case 0x32:
166515f746ceSArtyom Tarasenko case 0x39:
166615f746ceSArtyom Tarasenko case 0x3a:
166715f746ceSArtyom Tarasenko if (cpu_has_hypervisor(env)) {
166815f746ceSArtyom Tarasenko /* UA2005
166915f746ceSArtyom Tarasenko * ASI_DMMU_CTX_ZERO_TSB_BASE_PS0
167015f746ceSArtyom Tarasenko * ASI_DMMU_CTX_ZERO_TSB_BASE_PS1
167115f746ceSArtyom Tarasenko * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS0
167215f746ceSArtyom Tarasenko * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS1
167315f746ceSArtyom Tarasenko */
167415f746ceSArtyom Tarasenko int idx = ((asi & 2) >> 1) | ((asi & 8) >> 2);
167515f746ceSArtyom Tarasenko env->dmmu.sun4v_tsb_pointers[idx] = val;
167615f746ceSArtyom Tarasenko } else {
1677d9125cf2SRichard Henderson goto illegal_insn;
167815f746ceSArtyom Tarasenko }
167915f746ceSArtyom Tarasenko break;
168015f746ceSArtyom Tarasenko case 0x33:
168115f746ceSArtyom Tarasenko case 0x3b:
168215f746ceSArtyom Tarasenko if (cpu_has_hypervisor(env)) {
168315f746ceSArtyom Tarasenko /* UA2005
168415f746ceSArtyom Tarasenko * ASI_DMMU_CTX_ZERO_CONFIG
168515f746ceSArtyom Tarasenko * ASI_DMMU_CTX_NONZERO_CONFIG
168615f746ceSArtyom Tarasenko */
168715f746ceSArtyom Tarasenko env->dmmu.sun4v_ctx_config[(asi & 8) >> 3] = val;
168815f746ceSArtyom Tarasenko } else {
1689d9125cf2SRichard Henderson goto illegal_insn;
169015f746ceSArtyom Tarasenko }
169115f746ceSArtyom Tarasenko break;
169215f746ceSArtyom Tarasenko case 0x35:
169315f746ceSArtyom Tarasenko case 0x36:
169415f746ceSArtyom Tarasenko case 0x3d:
169515f746ceSArtyom Tarasenko case 0x3e:
169615f746ceSArtyom Tarasenko if (cpu_has_hypervisor(env)) {
169715f746ceSArtyom Tarasenko /* UA2005
169815f746ceSArtyom Tarasenko * ASI_IMMU_CTX_ZERO_TSB_BASE_PS0
169915f746ceSArtyom Tarasenko * ASI_IMMU_CTX_ZERO_TSB_BASE_PS1
170015f746ceSArtyom Tarasenko * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS0
170115f746ceSArtyom Tarasenko * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS1
170215f746ceSArtyom Tarasenko */
170315f746ceSArtyom Tarasenko int idx = ((asi & 2) >> 1) | ((asi & 8) >> 2);
170415f746ceSArtyom Tarasenko env->immu.sun4v_tsb_pointers[idx] = val;
170515f746ceSArtyom Tarasenko } else {
1706d9125cf2SRichard Henderson goto illegal_insn;
170715f746ceSArtyom Tarasenko }
170815f746ceSArtyom Tarasenko break;
170915f746ceSArtyom Tarasenko case 0x37:
171015f746ceSArtyom Tarasenko case 0x3f:
171115f746ceSArtyom Tarasenko if (cpu_has_hypervisor(env)) {
171215f746ceSArtyom Tarasenko /* UA2005
171315f746ceSArtyom Tarasenko * ASI_IMMU_CTX_ZERO_CONFIG
171415f746ceSArtyom Tarasenko * ASI_IMMU_CTX_NONZERO_CONFIG
171515f746ceSArtyom Tarasenko */
171615f746ceSArtyom Tarasenko env->immu.sun4v_ctx_config[(asi & 8) >> 3] = val;
171715f746ceSArtyom Tarasenko } else {
1718d9125cf2SRichard Henderson goto illegal_insn;
171915f746ceSArtyom Tarasenko }
172015f746ceSArtyom Tarasenko break;
1721fcf5ef2aSThomas Huth case ASI_UPA_CONFIG: /* UPA config */
1722fcf5ef2aSThomas Huth /* XXX */
1723fcf5ef2aSThomas Huth return;
1724fcf5ef2aSThomas Huth case ASI_LSU_CONTROL: /* LSU */
1725fcf5ef2aSThomas Huth env->lsu = val & (DMMU_E | IMMU_E);
1726fcf5ef2aSThomas Huth return;
1727fcf5ef2aSThomas Huth case ASI_IMMU: /* I-MMU regs */
1728fcf5ef2aSThomas Huth {
1729fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0xf;
1730fcf5ef2aSThomas Huth uint64_t oldreg;
1731fcf5ef2aSThomas Huth
173296df2bc9SArtyom Tarasenko oldreg = env->immu.mmuregs[reg];
1733fcf5ef2aSThomas Huth switch (reg) {
1734fcf5ef2aSThomas Huth case 0: /* RO */
1735fcf5ef2aSThomas Huth return;
1736fcf5ef2aSThomas Huth case 1: /* Not in I-MMU */
1737fcf5ef2aSThomas Huth case 2:
1738fcf5ef2aSThomas Huth return;
1739fcf5ef2aSThomas Huth case 3: /* SFSR */
1740fcf5ef2aSThomas Huth if ((val & 1) == 0) {
1741fcf5ef2aSThomas Huth val = 0; /* Clear SFSR */
1742fcf5ef2aSThomas Huth }
1743fcf5ef2aSThomas Huth env->immu.sfsr = val;
1744fcf5ef2aSThomas Huth break;
1745fcf5ef2aSThomas Huth case 4: /* RO */
1746fcf5ef2aSThomas Huth return;
1747fcf5ef2aSThomas Huth case 5: /* TSB access */
1748fcf5ef2aSThomas Huth DPRINTF_MMU("immu TSB write: 0x%016" PRIx64 " -> 0x%016"
1749fcf5ef2aSThomas Huth PRIx64 "\n", env->immu.tsb, val);
1750fcf5ef2aSThomas Huth env->immu.tsb = val;
1751fcf5ef2aSThomas Huth break;
1752fcf5ef2aSThomas Huth case 6: /* Tag access */
1753fcf5ef2aSThomas Huth env->immu.tag_access = val;
1754fcf5ef2aSThomas Huth break;
1755fcf5ef2aSThomas Huth case 7:
1756fcf5ef2aSThomas Huth case 8:
1757fcf5ef2aSThomas Huth return;
1758fcf5ef2aSThomas Huth default:
1759c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, true, false, 1, size, GETPC());
1760fcf5ef2aSThomas Huth break;
1761fcf5ef2aSThomas Huth }
1762fcf5ef2aSThomas Huth
176396df2bc9SArtyom Tarasenko if (oldreg != env->immu.mmuregs[reg]) {
1764fcf5ef2aSThomas Huth DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64 " -> 0x%016"
1765fcf5ef2aSThomas Huth PRIx64 "\n", reg, oldreg, env->immuregs[reg]);
1766fcf5ef2aSThomas Huth }
1767fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
1768fad866daSMarkus Armbruster dump_mmu(env);
1769fcf5ef2aSThomas Huth #endif
1770fcf5ef2aSThomas Huth return;
1771fcf5ef2aSThomas Huth }
1772fcf5ef2aSThomas Huth case ASI_ITLB_DATA_IN: /* I-MMU data in */
17737285fba0SArtyom Tarasenko /* ignore real translation entries */
17747285fba0SArtyom Tarasenko if (!(addr & TLB_UST1_IS_REAL_BIT)) {
17757285fba0SArtyom Tarasenko replace_tlb_1bit_lru(env->itlb, env->immu.tag_access,
17767285fba0SArtyom Tarasenko val, "immu", env, addr);
17777285fba0SArtyom Tarasenko }
1778fcf5ef2aSThomas Huth return;
1779fcf5ef2aSThomas Huth case ASI_ITLB_DATA_ACCESS: /* I-MMU data access */
1780fcf5ef2aSThomas Huth {
1781fcf5ef2aSThomas Huth /* TODO: auto demap */
1782fcf5ef2aSThomas Huth
1783fcf5ef2aSThomas Huth unsigned int i = (addr >> 3) & 0x3f;
1784fcf5ef2aSThomas Huth
17857285fba0SArtyom Tarasenko /* ignore real translation entries */
17867285fba0SArtyom Tarasenko if (!(addr & TLB_UST1_IS_REAL_BIT)) {
17877285fba0SArtyom Tarasenko replace_tlb_entry(&env->itlb[i], env->immu.tag_access,
17887285fba0SArtyom Tarasenko sun4v_tte_to_sun4u(env, addr, val), env);
17897285fba0SArtyom Tarasenko }
1790fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
1791fcf5ef2aSThomas Huth DPRINTF_MMU("immu data access replaced entry [%i]\n", i);
1792fad866daSMarkus Armbruster dump_mmu(env);
1793fcf5ef2aSThomas Huth #endif
1794fcf5ef2aSThomas Huth return;
1795fcf5ef2aSThomas Huth }
1796fcf5ef2aSThomas Huth case ASI_IMMU_DEMAP: /* I-MMU demap */
1797fcf5ef2aSThomas Huth demap_tlb(env->itlb, addr, "immu", env);
1798fcf5ef2aSThomas Huth return;
1799fcf5ef2aSThomas Huth case ASI_DMMU: /* D-MMU regs */
1800fcf5ef2aSThomas Huth {
1801fcf5ef2aSThomas Huth int reg = (addr >> 3) & 0xf;
1802fcf5ef2aSThomas Huth uint64_t oldreg;
1803fcf5ef2aSThomas Huth
180496df2bc9SArtyom Tarasenko oldreg = env->dmmu.mmuregs[reg];
1805fcf5ef2aSThomas Huth switch (reg) {
1806fcf5ef2aSThomas Huth case 0: /* RO */
1807fcf5ef2aSThomas Huth case 4:
1808fcf5ef2aSThomas Huth return;
1809fcf5ef2aSThomas Huth case 3: /* SFSR */
1810fcf5ef2aSThomas Huth if ((val & 1) == 0) {
1811fcf5ef2aSThomas Huth val = 0; /* Clear SFSR, Fault address */
1812fcf5ef2aSThomas Huth env->dmmu.sfar = 0;
1813fcf5ef2aSThomas Huth }
1814fcf5ef2aSThomas Huth env->dmmu.sfsr = val;
1815fcf5ef2aSThomas Huth break;
1816fcf5ef2aSThomas Huth case 1: /* Primary context */
1817fcf5ef2aSThomas Huth env->dmmu.mmu_primary_context = val;
1818fcf5ef2aSThomas Huth /* can be optimized to only flush MMU_USER_IDX
1819fcf5ef2aSThomas Huth and MMU_KERNEL_IDX entries */
18205a59fbceSRichard Henderson tlb_flush(cs);
1821fcf5ef2aSThomas Huth break;
1822fcf5ef2aSThomas Huth case 2: /* Secondary context */
1823fcf5ef2aSThomas Huth env->dmmu.mmu_secondary_context = val;
1824fcf5ef2aSThomas Huth /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1825fcf5ef2aSThomas Huth and MMU_KERNEL_SECONDARY_IDX entries */
18265a59fbceSRichard Henderson tlb_flush(cs);
1827fcf5ef2aSThomas Huth break;
1828fcf5ef2aSThomas Huth case 5: /* TSB access */
1829fcf5ef2aSThomas Huth DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64 " -> 0x%016"
1830fcf5ef2aSThomas Huth PRIx64 "\n", env->dmmu.tsb, val);
1831fcf5ef2aSThomas Huth env->dmmu.tsb = val;
1832fcf5ef2aSThomas Huth break;
1833fcf5ef2aSThomas Huth case 6: /* Tag access */
1834fcf5ef2aSThomas Huth env->dmmu.tag_access = val;
1835fcf5ef2aSThomas Huth break;
1836fcf5ef2aSThomas Huth case 7: /* Virtual Watchpoint */
183720395e63SArtyom Tarasenko env->dmmu.virtual_watchpoint = val;
183820395e63SArtyom Tarasenko break;
1839fcf5ef2aSThomas Huth case 8: /* Physical Watchpoint */
184020395e63SArtyom Tarasenko env->dmmu.physical_watchpoint = val;
184120395e63SArtyom Tarasenko break;
1842fcf5ef2aSThomas Huth default:
1843c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, true, false, 1, size, GETPC());
1844fcf5ef2aSThomas Huth break;
1845fcf5ef2aSThomas Huth }
1846fcf5ef2aSThomas Huth
184796df2bc9SArtyom Tarasenko if (oldreg != env->dmmu.mmuregs[reg]) {
1848fcf5ef2aSThomas Huth DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64 " -> 0x%016"
1849fcf5ef2aSThomas Huth PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]);
1850fcf5ef2aSThomas Huth }
1851fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
1852fad866daSMarkus Armbruster dump_mmu(env);
1853fcf5ef2aSThomas Huth #endif
1854fcf5ef2aSThomas Huth return;
1855fcf5ef2aSThomas Huth }
1856fcf5ef2aSThomas Huth case ASI_DTLB_DATA_IN: /* D-MMU data in */
18577285fba0SArtyom Tarasenko /* ignore real translation entries */
18587285fba0SArtyom Tarasenko if (!(addr & TLB_UST1_IS_REAL_BIT)) {
18597285fba0SArtyom Tarasenko replace_tlb_1bit_lru(env->dtlb, env->dmmu.tag_access,
18607285fba0SArtyom Tarasenko val, "dmmu", env, addr);
18617285fba0SArtyom Tarasenko }
1862fcf5ef2aSThomas Huth return;
1863fcf5ef2aSThomas Huth case ASI_DTLB_DATA_ACCESS: /* D-MMU data access */
1864fcf5ef2aSThomas Huth {
1865fcf5ef2aSThomas Huth unsigned int i = (addr >> 3) & 0x3f;
1866fcf5ef2aSThomas Huth
18677285fba0SArtyom Tarasenko /* ignore real translation entries */
18687285fba0SArtyom Tarasenko if (!(addr & TLB_UST1_IS_REAL_BIT)) {
18697285fba0SArtyom Tarasenko replace_tlb_entry(&env->dtlb[i], env->dmmu.tag_access,
18707285fba0SArtyom Tarasenko sun4v_tte_to_sun4u(env, addr, val), env);
18717285fba0SArtyom Tarasenko }
1872fcf5ef2aSThomas Huth #ifdef DEBUG_MMU
1873fcf5ef2aSThomas Huth DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i);
1874fad866daSMarkus Armbruster dump_mmu(env);
1875fcf5ef2aSThomas Huth #endif
1876fcf5ef2aSThomas Huth return;
1877fcf5ef2aSThomas Huth }
1878fcf5ef2aSThomas Huth case ASI_DMMU_DEMAP: /* D-MMU demap */
1879fcf5ef2aSThomas Huth demap_tlb(env->dtlb, addr, "dmmu", env);
1880fcf5ef2aSThomas Huth return;
1881fcf5ef2aSThomas Huth case ASI_INTR_RECEIVE: /* Interrupt data receive */
1882fcf5ef2aSThomas Huth env->ivec_status = val & 0x20;
1883fcf5ef2aSThomas Huth return;
18844ec3e346SArtyom Tarasenko case ASI_SCRATCHPAD: /* UA2005 privileged scratchpad */
18854ec3e346SArtyom Tarasenko if (unlikely((addr >= 0x20) && (addr < 0x30))) {
18864ec3e346SArtyom Tarasenko /* Hyperprivileged access only */
1887c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, true, false, 1, size, GETPC());
18884ec3e346SArtyom Tarasenko }
18894ec3e346SArtyom Tarasenko /* fall through */
18904ec3e346SArtyom Tarasenko case ASI_HYP_SCRATCHPAD: /* UA2005 hyperprivileged scratchpad */
18914ec3e346SArtyom Tarasenko {
18924ec3e346SArtyom Tarasenko unsigned int i = (addr >> 3) & 0x7;
18934ec3e346SArtyom Tarasenko env->scratch[i] = val;
18944ec3e346SArtyom Tarasenko return;
18954ec3e346SArtyom Tarasenko }
18967dd8c076SArtyom Tarasenko case ASI_MMU: /* UA2005 Context ID registers */
18977dd8c076SArtyom Tarasenko {
18987dd8c076SArtyom Tarasenko switch ((addr >> 3) & 0x3) {
18997dd8c076SArtyom Tarasenko case 1:
19007dd8c076SArtyom Tarasenko env->dmmu.mmu_primary_context = val;
19017dd8c076SArtyom Tarasenko env->immu.mmu_primary_context = val;
19025a59fbceSRichard Henderson tlb_flush_by_mmuidx(cs,
19030336cbf8SAlex Bennée (1 << MMU_USER_IDX) | (1 << MMU_KERNEL_IDX));
19047dd8c076SArtyom Tarasenko break;
19057dd8c076SArtyom Tarasenko case 2:
19067dd8c076SArtyom Tarasenko env->dmmu.mmu_secondary_context = val;
19077dd8c076SArtyom Tarasenko env->immu.mmu_secondary_context = val;
19085a59fbceSRichard Henderson tlb_flush_by_mmuidx(cs,
19090336cbf8SAlex Bennée (1 << MMU_USER_SECONDARY_IDX) |
19100336cbf8SAlex Bennée (1 << MMU_KERNEL_SECONDARY_IDX));
19117dd8c076SArtyom Tarasenko break;
19127dd8c076SArtyom Tarasenko default:
1913c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, true, false, 1, size, GETPC());
19147dd8c076SArtyom Tarasenko }
19157dd8c076SArtyom Tarasenko }
19167dd8c076SArtyom Tarasenko return;
19172f1b5292SArtyom Tarasenko case ASI_QUEUE: /* UA2005 CPU mondo queue */
1918fcf5ef2aSThomas Huth case ASI_DCACHE_DATA: /* D-cache data */
1919fcf5ef2aSThomas Huth case ASI_DCACHE_TAG: /* D-cache tag access */
1920fcf5ef2aSThomas Huth case ASI_ESTATE_ERROR_EN: /* E-cache error enable */
1921fcf5ef2aSThomas Huth case ASI_AFSR: /* E-cache asynchronous fault status */
1922fcf5ef2aSThomas Huth case ASI_AFAR: /* E-cache asynchronous fault address */
1923fcf5ef2aSThomas Huth case ASI_EC_TAG_DATA: /* E-cache tag data */
1924fcf5ef2aSThomas Huth case ASI_IC_INSTR: /* I-cache instruction access */
1925fcf5ef2aSThomas Huth case ASI_IC_TAG: /* I-cache tag access */
1926fcf5ef2aSThomas Huth case ASI_IC_PRE_DECODE: /* I-cache predecode */
1927fcf5ef2aSThomas Huth case ASI_IC_NEXT_FIELD: /* I-cache LRU etc. */
1928fcf5ef2aSThomas Huth case ASI_EC_W: /* E-cache tag */
1929fcf5ef2aSThomas Huth case ASI_EC_R: /* E-cache tag */
1930fcf5ef2aSThomas Huth return;
1931fcf5ef2aSThomas Huth case ASI_IMMU_TSB_8KB_PTR: /* I-MMU 8k TSB pointer, RO */
1932fcf5ef2aSThomas Huth case ASI_IMMU_TSB_64KB_PTR: /* I-MMU 64k TSB pointer, RO */
1933fcf5ef2aSThomas Huth case ASI_ITLB_TAG_READ: /* I-MMU tag read, RO */
1934fcf5ef2aSThomas Huth case ASI_DMMU_TSB_8KB_PTR: /* D-MMU 8k TSB pointer, RO */
1935fcf5ef2aSThomas Huth case ASI_DMMU_TSB_64KB_PTR: /* D-MMU 64k TSB pointer, RO */
1936fcf5ef2aSThomas Huth case ASI_DMMU_TSB_DIRECT_PTR: /* D-MMU data pointer, RO */
1937fcf5ef2aSThomas Huth case ASI_DTLB_TAG_READ: /* D-MMU tag read, RO */
1938fcf5ef2aSThomas Huth case ASI_INTR_DISPATCH_STAT: /* Interrupt dispatch, RO */
1939fcf5ef2aSThomas Huth case ASI_INTR_R: /* Incoming interrupt vector, RO */
1940fcf5ef2aSThomas Huth case ASI_PNF: /* Primary no-fault, RO */
1941fcf5ef2aSThomas Huth case ASI_SNF: /* Secondary no-fault, RO */
1942fcf5ef2aSThomas Huth case ASI_PNFL: /* Primary no-fault LE, RO */
1943fcf5ef2aSThomas Huth case ASI_SNFL: /* Secondary no-fault LE, RO */
1944fcf5ef2aSThomas Huth default:
1945c9d793f4SPeter Maydell sparc_raise_mmu_fault(cs, addr, true, false, 1, size, GETPC());
1946fcf5ef2aSThomas Huth return;
1947d9125cf2SRichard Henderson illegal_insn:
1948d9125cf2SRichard Henderson cpu_raise_exception_ra(env, TT_ILL_INSN, GETPC());
1949fcf5ef2aSThomas Huth }
1950fcf5ef2aSThomas Huth }
1951fcf5ef2aSThomas Huth #endif /* CONFIG_USER_ONLY */
1952fcf5ef2aSThomas Huth #endif /* TARGET_SPARC64 */
1953fcf5ef2aSThomas Huth
1954fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
1955f8c3db33SPeter Maydell
sparc_cpu_do_transaction_failed(CPUState * cs,hwaddr physaddr,vaddr addr,unsigned size,MMUAccessType access_type,int mmu_idx,MemTxAttrs attrs,MemTxResult response,uintptr_t retaddr)1956f8c3db33SPeter Maydell void sparc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
1957f8c3db33SPeter Maydell vaddr addr, unsigned size,
1958f8c3db33SPeter Maydell MMUAccessType access_type,
1959f8c3db33SPeter Maydell int mmu_idx, MemTxAttrs attrs,
1960f8c3db33SPeter Maydell MemTxResult response, uintptr_t retaddr)
1961fcf5ef2aSThomas Huth {
1962f8c3db33SPeter Maydell bool is_write = access_type == MMU_DATA_STORE;
1963f8c3db33SPeter Maydell bool is_exec = access_type == MMU_INST_FETCH;
1964f8c3db33SPeter Maydell bool is_asi = false;
1965f8c3db33SPeter Maydell
1966f8c3db33SPeter Maydell sparc_raise_mmu_fault(cs, physaddr, is_write, is_exec,
1967f8c3db33SPeter Maydell is_asi, size, retaddr);
1968fcf5ef2aSThomas Huth }
1969fcf5ef2aSThomas Huth #endif
1970