]>
Commit | Line | Data |
---|---|---|
fafd8bce BS |
1 | /* |
2 | * Helpers for loads and stores | |
3 | * | |
4 | * Copyright (c) 2003-2005 Fabrice Bellard | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
db5ebe5f | 20 | #include "qemu/osdep.h" |
fafd8bce | 21 | #include "cpu.h" |
6850811e | 22 | #include "tcg.h" |
2ef6175a | 23 | #include "exec/helper-proto.h" |
63c91552 | 24 | #include "exec/exec-all.h" |
f08b6170 | 25 | #include "exec/cpu_ldst.h" |
0cc1f4bf | 26 | #include "asi.h" |
fafd8bce | 27 | |
fafd8bce BS |
28 | //#define DEBUG_MMU |
29 | //#define DEBUG_MXCC | |
30 | //#define DEBUG_UNALIGNED | |
31 | //#define DEBUG_UNASSIGNED | |
32 | //#define DEBUG_ASI | |
33 | //#define DEBUG_CACHE_CONTROL | |
34 | ||
35 | #ifdef DEBUG_MMU | |
36 | #define DPRINTF_MMU(fmt, ...) \ | |
37 | do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0) | |
38 | #else | |
39 | #define DPRINTF_MMU(fmt, ...) do {} while (0) | |
40 | #endif | |
41 | ||
42 | #ifdef DEBUG_MXCC | |
43 | #define DPRINTF_MXCC(fmt, ...) \ | |
44 | do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0) | |
45 | #else | |
46 | #define DPRINTF_MXCC(fmt, ...) do {} while (0) | |
47 | #endif | |
48 | ||
49 | #ifdef DEBUG_ASI | |
50 | #define DPRINTF_ASI(fmt, ...) \ | |
51 | do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0) | |
52 | #endif | |
53 | ||
54 | #ifdef DEBUG_CACHE_CONTROL | |
55 | #define DPRINTF_CACHE_CONTROL(fmt, ...) \ | |
56 | do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0) | |
57 | #else | |
58 | #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0) | |
59 | #endif | |
60 | ||
61 | #ifdef TARGET_SPARC64 | |
62 | #ifndef TARGET_ABI32 | |
63 | #define AM_CHECK(env1) ((env1)->pstate & PS_AM) | |
64 | #else | |
65 | #define AM_CHECK(env1) (1) | |
66 | #endif | |
67 | #endif | |
68 | ||
fafd8bce BS |
69 | #define QT0 (env->qt0) |
70 | #define QT1 (env->qt1) | |
71 | ||
fafd8bce | 72 | #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) |
15f746ce AT |
73 | /* Calculates TSB pointer value for fault page size |
74 | * UltraSPARC IIi has fixed sizes (8k or 64k) for the page pointers | |
75 | * UA2005 holds the page size configuration in mmu_ctx registers */ | |
e5673ee4 AT |
76 | static uint64_t ultrasparc_tsb_pointer(CPUSPARCState *env, |
77 | const SparcV9MMU *mmu, const int idx) | |
fafd8bce | 78 | { |
15f746ce AT |
79 | uint64_t tsb_register; |
80 | int page_size; | |
81 | if (cpu_has_hypervisor(env)) { | |
82 | int tsb_index = 0; | |
e5673ee4 AT |
83 | int ctx = mmu->tag_access & 0x1fffULL; |
84 | uint64_t ctx_register = mmu->sun4v_ctx_config[ctx ? 1 : 0]; | |
15f746ce AT |
85 | tsb_index = idx; |
86 | tsb_index |= ctx ? 2 : 0; | |
87 | page_size = idx ? ctx_register >> 8 : ctx_register; | |
88 | page_size &= 7; | |
e5673ee4 | 89 | tsb_register = mmu->sun4v_tsb_pointers[tsb_index]; |
15f746ce AT |
90 | } else { |
91 | page_size = idx; | |
e5673ee4 | 92 | tsb_register = mmu->tsb; |
15f746ce | 93 | } |
fafd8bce BS |
94 | int tsb_split = (tsb_register & 0x1000ULL) ? 1 : 0; |
95 | int tsb_size = tsb_register & 0xf; | |
96 | ||
e5673ee4 | 97 | uint64_t tsb_base_mask = (~0x1fffULL) << tsb_size; |
fafd8bce | 98 | |
e5673ee4 AT |
99 | /* move va bits to correct position, |
100 | * the context bits will be masked out later */ | |
101 | uint64_t va = mmu->tag_access >> (3 * page_size + 9); | |
fafd8bce BS |
102 | |
103 | /* calculate tsb_base mask and adjust va if split is in use */ | |
104 | if (tsb_split) { | |
15f746ce | 105 | if (idx == 0) { |
fafd8bce | 106 | va &= ~(1ULL << (13 + tsb_size)); |
15f746ce | 107 | } else { |
fafd8bce BS |
108 | va |= (1ULL << (13 + tsb_size)); |
109 | } | |
110 | tsb_base_mask <<= 1; | |
111 | } | |
112 | ||
e5673ee4 | 113 | return ((tsb_register & tsb_base_mask) | (va & ~tsb_base_mask)) & ~0xfULL; |
fafd8bce BS |
114 | } |
115 | ||
116 | /* Calculates tag target register value by reordering bits | |
117 | in tag access register */ | |
118 | static uint64_t ultrasparc_tag_target(uint64_t tag_access_register) | |
119 | { | |
120 | return ((tag_access_register & 0x1fff) << 48) | (tag_access_register >> 22); | |
121 | } | |
122 | ||
123 | static void replace_tlb_entry(SparcTLBEntry *tlb, | |
124 | uint64_t tlb_tag, uint64_t tlb_tte, | |
c5f9864e | 125 | CPUSPARCState *env1) |
fafd8bce BS |
126 | { |
127 | target_ulong mask, size, va, offset; | |
128 | ||
129 | /* flush page range if translation is valid */ | |
130 | if (TTE_IS_VALID(tlb->tte)) { | |
31b030d4 | 131 | CPUState *cs = CPU(sparc_env_get_cpu(env1)); |
fafd8bce | 132 | |
e4d06ca7 AT |
133 | size = 8192ULL << 3 * TTE_PGSIZE(tlb->tte); |
134 | mask = 1ULL + ~size; | |
fafd8bce BS |
135 | |
136 | va = tlb->tag & mask; | |
137 | ||
138 | for (offset = 0; offset < size; offset += TARGET_PAGE_SIZE) { | |
31b030d4 | 139 | tlb_flush_page(cs, va + offset); |
fafd8bce BS |
140 | } |
141 | } | |
142 | ||
143 | tlb->tag = tlb_tag; | |
144 | tlb->tte = tlb_tte; | |
145 | } | |
146 | ||
147 | static void demap_tlb(SparcTLBEntry *tlb, target_ulong demap_addr, | |
c5f9864e | 148 | const char *strmmu, CPUSPARCState *env1) |
fafd8bce BS |
149 | { |
150 | unsigned int i; | |
151 | target_ulong mask; | |
152 | uint64_t context; | |
153 | ||
154 | int is_demap_context = (demap_addr >> 6) & 1; | |
155 | ||
156 | /* demap context */ | |
157 | switch ((demap_addr >> 4) & 3) { | |
158 | case 0: /* primary */ | |
159 | context = env1->dmmu.mmu_primary_context; | |
160 | break; | |
161 | case 1: /* secondary */ | |
162 | context = env1->dmmu.mmu_secondary_context; | |
163 | break; | |
164 | case 2: /* nucleus */ | |
165 | context = 0; | |
166 | break; | |
167 | case 3: /* reserved */ | |
168 | default: | |
169 | return; | |
170 | } | |
171 | ||
172 | for (i = 0; i < 64; i++) { | |
173 | if (TTE_IS_VALID(tlb[i].tte)) { | |
174 | ||
175 | if (is_demap_context) { | |
176 | /* will remove non-global entries matching context value */ | |
177 | if (TTE_IS_GLOBAL(tlb[i].tte) || | |
178 | !tlb_compare_context(&tlb[i], context)) { | |
179 | continue; | |
180 | } | |
181 | } else { | |
182 | /* demap page | |
183 | will remove any entry matching VA */ | |
184 | mask = 0xffffffffffffe000ULL; | |
185 | mask <<= 3 * ((tlb[i].tte >> 61) & 3); | |
186 | ||
187 | if (!compare_masked(demap_addr, tlb[i].tag, mask)) { | |
188 | continue; | |
189 | } | |
190 | ||
191 | /* entry should be global or matching context value */ | |
192 | if (!TTE_IS_GLOBAL(tlb[i].tte) && | |
193 | !tlb_compare_context(&tlb[i], context)) { | |
194 | continue; | |
195 | } | |
196 | } | |
197 | ||
198 | replace_tlb_entry(&tlb[i], 0, 0, env1); | |
199 | #ifdef DEBUG_MMU | |
200 | DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i); | |
201 | dump_mmu(stdout, fprintf, env1); | |
202 | #endif | |
203 | } | |
204 | } | |
205 | } | |
206 | ||
207 | static void replace_tlb_1bit_lru(SparcTLBEntry *tlb, | |
208 | uint64_t tlb_tag, uint64_t tlb_tte, | |
c5f9864e | 209 | const char *strmmu, CPUSPARCState *env1) |
fafd8bce BS |
210 | { |
211 | unsigned int i, replace_used; | |
212 | ||
70f44d2f AT |
213 | if (cpu_has_hypervisor(env1)) { |
214 | uint64_t new_vaddr = tlb_tag & ~0x1fffULL; | |
215 | uint64_t new_size = 8192ULL << 3 * TTE_PGSIZE(tlb_tte); | |
216 | uint32_t new_ctx = tlb_tag & 0x1fffU; | |
217 | for (i = 0; i < 64; i++) { | |
218 | uint32_t ctx = tlb[i].tag & 0x1fffU; | |
219 | /* check if new mapping overlaps an existing one */ | |
220 | if (new_ctx == ctx) { | |
221 | uint64_t vaddr = tlb[i].tag & ~0x1fffULL; | |
222 | uint64_t size = 8192ULL << 3 * TTE_PGSIZE(tlb[i].tte); | |
223 | if (new_vaddr == vaddr | |
224 | || (new_vaddr < vaddr + size | |
225 | && vaddr < new_vaddr + new_size)) { | |
226 | DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i, vaddr, | |
227 | new_vaddr); | |
228 | replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1); | |
229 | return; | |
230 | } | |
231 | } | |
232 | ||
233 | } | |
234 | } | |
fafd8bce BS |
235 | /* Try replacing invalid entry */ |
236 | for (i = 0; i < 64; i++) { | |
237 | if (!TTE_IS_VALID(tlb[i].tte)) { | |
238 | replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1); | |
239 | #ifdef DEBUG_MMU | |
240 | DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu, i); | |
241 | dump_mmu(stdout, fprintf, env1); | |
242 | #endif | |
243 | return; | |
244 | } | |
245 | } | |
246 | ||
247 | /* All entries are valid, try replacing unlocked entry */ | |
248 | ||
249 | for (replace_used = 0; replace_used < 2; ++replace_used) { | |
250 | ||
251 | /* Used entries are not replaced on first pass */ | |
252 | ||
253 | for (i = 0; i < 64; i++) { | |
254 | if (!TTE_IS_LOCKED(tlb[i].tte) && !TTE_IS_USED(tlb[i].tte)) { | |
255 | ||
256 | replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1); | |
257 | #ifdef DEBUG_MMU | |
258 | DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n", | |
259 | strmmu, (replace_used ? "used" : "unused"), i); | |
260 | dump_mmu(stdout, fprintf, env1); | |
261 | #endif | |
262 | return; | |
263 | } | |
264 | } | |
265 | ||
266 | /* Now reset used bit and search for unused entries again */ | |
267 | ||
268 | for (i = 0; i < 64; i++) { | |
269 | TTE_SET_UNUSED(tlb[i].tte); | |
270 | } | |
271 | } | |
272 | ||
273 | #ifdef DEBUG_MMU | |
4797a685 AT |
274 | DPRINTF_MMU("%s lru replacement: no free entries available, " |
275 | "replacing the last one\n", strmmu); | |
fafd8bce | 276 | #endif |
4797a685 AT |
277 | /* corner case: the last entry is replaced anyway */ |
278 | replace_tlb_entry(&tlb[63], tlb_tag, tlb_tte, env1); | |
fafd8bce BS |
279 | } |
280 | ||
281 | #endif | |
282 | ||
69694625 | 283 | #ifdef TARGET_SPARC64 |
fafd8bce BS |
284 | /* returns true if access using this ASI is to have address translated by MMU |
285 | otherwise access is to raw physical address */ | |
69694625 | 286 | /* TODO: check sparc32 bits */ |
fafd8bce BS |
287 | static inline int is_translating_asi(int asi) |
288 | { | |
fafd8bce BS |
289 | /* Ultrasparc IIi translating asi |
290 | - note this list is defined by cpu implementation | |
291 | */ | |
292 | switch (asi) { | |
293 | case 0x04 ... 0x11: | |
294 | case 0x16 ... 0x19: | |
295 | case 0x1E ... 0x1F: | |
296 | case 0x24 ... 0x2C: | |
297 | case 0x70 ... 0x73: | |
298 | case 0x78 ... 0x79: | |
299 | case 0x80 ... 0xFF: | |
300 | return 1; | |
301 | ||
302 | default: | |
303 | return 0; | |
304 | } | |
fafd8bce BS |
305 | } |
306 | ||
f939ffe5 RH |
307 | static inline target_ulong address_mask(CPUSPARCState *env1, target_ulong addr) |
308 | { | |
309 | if (AM_CHECK(env1)) { | |
310 | addr &= 0xffffffffULL; | |
311 | } | |
312 | return addr; | |
313 | } | |
314 | ||
fe8d8f0f | 315 | static inline target_ulong asi_address_mask(CPUSPARCState *env, |
fafd8bce BS |
316 | int asi, target_ulong addr) |
317 | { | |
318 | if (is_translating_asi(asi)) { | |
f939ffe5 | 319 | addr = address_mask(env, addr); |
fafd8bce | 320 | } |
f939ffe5 | 321 | return addr; |
fafd8bce | 322 | } |
7cd39ef2 AT |
323 | |
324 | #ifndef CONFIG_USER_ONLY | |
325 | static inline void do_check_asi(CPUSPARCState *env, int asi, uintptr_t ra) | |
326 | { | |
327 | /* ASIs >= 0x80 are user mode. | |
328 | * ASIs >= 0x30 are hyper mode (or super if hyper is not available). | |
329 | * ASIs <= 0x2f are super mode. | |
330 | */ | |
331 | if (asi < 0x80 | |
332 | && !cpu_hypervisor_mode(env) | |
333 | && (!cpu_supervisor_mode(env) | |
334 | || (asi >= 0x30 && cpu_has_hypervisor(env)))) { | |
335 | cpu_raise_exception_ra(env, TT_PRIV_ACT, ra); | |
336 | } | |
337 | } | |
338 | #endif /* !CONFIG_USER_ONLY */ | |
e60538c7 | 339 | #endif |
fafd8bce | 340 | |
2f9d35fc RH |
341 | static void do_check_align(CPUSPARCState *env, target_ulong addr, |
342 | uint32_t align, uintptr_t ra) | |
fafd8bce BS |
343 | { |
344 | if (addr & align) { | |
345 | #ifdef DEBUG_UNALIGNED | |
346 | printf("Unaligned access to 0x" TARGET_FMT_lx " from 0x" TARGET_FMT_lx | |
347 | "\n", addr, env->pc); | |
348 | #endif | |
2f9d35fc | 349 | cpu_raise_exception_ra(env, TT_UNALIGNED, ra); |
fafd8bce BS |
350 | } |
351 | } | |
352 | ||
2f9d35fc RH |
353 | void helper_check_align(CPUSPARCState *env, target_ulong addr, uint32_t align) |
354 | { | |
355 | do_check_align(env, addr, align, GETPC()); | |
356 | } | |
357 | ||
fafd8bce BS |
358 | #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \ |
359 | defined(DEBUG_MXCC) | |
c5f9864e | 360 | static void dump_mxcc(CPUSPARCState *env) |
fafd8bce BS |
361 | { |
362 | printf("mxccdata: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 | |
363 | "\n", | |
364 | env->mxccdata[0], env->mxccdata[1], | |
365 | env->mxccdata[2], env->mxccdata[3]); | |
366 | printf("mxccregs: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 | |
367 | "\n" | |
368 | " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 | |
369 | "\n", | |
370 | env->mxccregs[0], env->mxccregs[1], | |
371 | env->mxccregs[2], env->mxccregs[3], | |
372 | env->mxccregs[4], env->mxccregs[5], | |
373 | env->mxccregs[6], env->mxccregs[7]); | |
374 | } | |
375 | #endif | |
376 | ||
377 | #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \ | |
378 | && defined(DEBUG_ASI) | |
379 | static void dump_asi(const char *txt, target_ulong addr, int asi, int size, | |
380 | uint64_t r1) | |
381 | { | |
382 | switch (size) { | |
383 | case 1: | |
384 | DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %02" PRIx64 "\n", txt, | |
385 | addr, asi, r1 & 0xff); | |
386 | break; | |
387 | case 2: | |
388 | DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %04" PRIx64 "\n", txt, | |
389 | addr, asi, r1 & 0xffff); | |
390 | break; | |
391 | case 4: | |
392 | DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %08" PRIx64 "\n", txt, | |
393 | addr, asi, r1 & 0xffffffff); | |
394 | break; | |
395 | case 8: | |
396 | DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %016" PRIx64 "\n", txt, | |
397 | addr, asi, r1); | |
398 | break; | |
399 | } | |
400 | } | |
401 | #endif | |
402 | ||
403 | #ifndef TARGET_SPARC64 | |
404 | #ifndef CONFIG_USER_ONLY | |
405 | ||
406 | ||
407 | /* Leon3 cache control */ | |
408 | ||
fe8d8f0f BS |
409 | static void leon3_cache_control_st(CPUSPARCState *env, target_ulong addr, |
410 | uint64_t val, int size) | |
fafd8bce BS |
411 | { |
412 | DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64 ", size:%d\n", | |
413 | addr, val, size); | |
414 | ||
415 | if (size != 4) { | |
416 | DPRINTF_CACHE_CONTROL("32bits only\n"); | |
417 | return; | |
418 | } | |
419 | ||
420 | switch (addr) { | |
421 | case 0x00: /* Cache control */ | |
422 | ||
423 | /* These values must always be read as zeros */ | |
424 | val &= ~CACHE_CTRL_FD; | |
425 | val &= ~CACHE_CTRL_FI; | |
426 | val &= ~CACHE_CTRL_IB; | |
427 | val &= ~CACHE_CTRL_IP; | |
428 | val &= ~CACHE_CTRL_DP; | |
429 | ||
430 | env->cache_control = val; | |
431 | break; | |
432 | case 0x04: /* Instruction cache configuration */ | |
433 | case 0x08: /* Data cache configuration */ | |
434 | /* Read Only */ | |
435 | break; | |
436 | default: | |
437 | DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr); | |
438 | break; | |
439 | }; | |
440 | } | |
441 | ||
fe8d8f0f BS |
442 | static uint64_t leon3_cache_control_ld(CPUSPARCState *env, target_ulong addr, |
443 | int size) | |
fafd8bce BS |
444 | { |
445 | uint64_t ret = 0; | |
446 | ||
447 | if (size != 4) { | |
448 | DPRINTF_CACHE_CONTROL("32bits only\n"); | |
449 | return 0; | |
450 | } | |
451 | ||
452 | switch (addr) { | |
453 | case 0x00: /* Cache control */ | |
454 | ret = env->cache_control; | |
455 | break; | |
456 | ||
457 | /* Configuration registers are read and only always keep those | |
458 | predefined values */ | |
459 | ||
460 | case 0x04: /* Instruction cache configuration */ | |
461 | ret = 0x10220000; | |
462 | break; | |
463 | case 0x08: /* Data cache configuration */ | |
464 | ret = 0x18220000; | |
465 | break; | |
466 | default: | |
467 | DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr); | |
468 | break; | |
469 | }; | |
470 | DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64 ", size:%d\n", | |
471 | addr, ret, size); | |
472 | return ret; | |
473 | } | |
474 | ||
6850811e RH |
475 | uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, |
476 | int asi, uint32_t memop) | |
fafd8bce | 477 | { |
6850811e RH |
478 | int size = 1 << (memop & MO_SIZE); |
479 | int sign = memop & MO_SIGN; | |
2fad1112 | 480 | CPUState *cs = CPU(sparc_env_get_cpu(env)); |
fafd8bce BS |
481 | uint64_t ret = 0; |
482 | #if defined(DEBUG_MXCC) || defined(DEBUG_ASI) | |
483 | uint32_t last_addr = addr; | |
484 | #endif | |
485 | ||
2f9d35fc | 486 | do_check_align(env, addr, size - 1, GETPC()); |
fafd8bce | 487 | switch (asi) { |
0cc1f4bf RH |
488 | case ASI_M_MXCC: /* SuperSparc MXCC registers, or... */ |
489 | /* case ASI_LEON_CACHEREGS: Leon3 cache control */ | |
fafd8bce BS |
490 | switch (addr) { |
491 | case 0x00: /* Leon3 Cache Control */ | |
492 | case 0x08: /* Leon3 Instruction Cache config */ | |
493 | case 0x0C: /* Leon3 Date Cache config */ | |
494 | if (env->def->features & CPU_FEATURE_CACHE_CTRL) { | |
fe8d8f0f | 495 | ret = leon3_cache_control_ld(env, addr, size); |
fafd8bce BS |
496 | } |
497 | break; | |
498 | case 0x01c00a00: /* MXCC control register */ | |
499 | if (size == 8) { | |
500 | ret = env->mxccregs[3]; | |
501 | } else { | |
71547a3b BS |
502 | qemu_log_mask(LOG_UNIMP, |
503 | "%08x: unimplemented access size: %d\n", addr, | |
504 | size); | |
fafd8bce BS |
505 | } |
506 | break; | |
507 | case 0x01c00a04: /* MXCC control register */ | |
508 | if (size == 4) { | |
509 | ret = env->mxccregs[3]; | |
510 | } else { | |
71547a3b BS |
511 | qemu_log_mask(LOG_UNIMP, |
512 | "%08x: unimplemented access size: %d\n", addr, | |
513 | size); | |
fafd8bce BS |
514 | } |
515 | break; | |
516 | case 0x01c00c00: /* Module reset register */ | |
517 | if (size == 8) { | |
518 | ret = env->mxccregs[5]; | |
519 | /* should we do something here? */ | |
520 | } else { | |
71547a3b BS |
521 | qemu_log_mask(LOG_UNIMP, |
522 | "%08x: unimplemented access size: %d\n", addr, | |
523 | size); | |
fafd8bce BS |
524 | } |
525 | break; | |
526 | case 0x01c00f00: /* MBus port address register */ | |
527 | if (size == 8) { | |
528 | ret = env->mxccregs[7]; | |
529 | } else { | |
71547a3b BS |
530 | qemu_log_mask(LOG_UNIMP, |
531 | "%08x: unimplemented access size: %d\n", addr, | |
532 | size); | |
fafd8bce BS |
533 | } |
534 | break; | |
535 | default: | |
71547a3b BS |
536 | qemu_log_mask(LOG_UNIMP, |
537 | "%08x: unimplemented address, size: %d\n", addr, | |
538 | size); | |
fafd8bce BS |
539 | break; |
540 | } | |
541 | DPRINTF_MXCC("asi = %d, size = %d, sign = %d, " | |
542 | "addr = %08x -> ret = %" PRIx64 "," | |
543 | "addr = %08x\n", asi, size, sign, last_addr, ret, addr); | |
544 | #ifdef DEBUG_MXCC | |
545 | dump_mxcc(env); | |
546 | #endif | |
547 | break; | |
0cc1f4bf RH |
548 | case ASI_M_FLUSH_PROBE: /* SuperSparc MMU probe */ |
549 | case ASI_LEON_MMUFLUSH: /* LEON3 MMU probe */ | |
fafd8bce BS |
550 | { |
551 | int mmulev; | |
552 | ||
553 | mmulev = (addr >> 8) & 15; | |
554 | if (mmulev > 4) { | |
555 | ret = 0; | |
556 | } else { | |
557 | ret = mmu_probe(env, addr, mmulev); | |
558 | } | |
559 | DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64 "\n", | |
560 | addr, mmulev, ret); | |
561 | } | |
562 | break; | |
0cc1f4bf RH |
563 | case ASI_M_MMUREGS: /* SuperSparc MMU regs */ |
564 | case ASI_LEON_MMUREGS: /* LEON3 MMU regs */ | |
fafd8bce BS |
565 | { |
566 | int reg = (addr >> 8) & 0x1f; | |
567 | ||
568 | ret = env->mmuregs[reg]; | |
569 | if (reg == 3) { /* Fault status cleared on read */ | |
570 | env->mmuregs[3] = 0; | |
571 | } else if (reg == 0x13) { /* Fault status read */ | |
572 | ret = env->mmuregs[3]; | |
573 | } else if (reg == 0x14) { /* Fault address read */ | |
574 | ret = env->mmuregs[4]; | |
575 | } | |
576 | DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64 "\n", reg, ret); | |
577 | } | |
578 | break; | |
0cc1f4bf RH |
579 | case ASI_M_TLBDIAG: /* Turbosparc ITLB Diagnostic */ |
580 | case ASI_M_DIAGS: /* Turbosparc DTLB Diagnostic */ | |
581 | case ASI_M_IODIAG: /* Turbosparc IOTLB Diagnostic */ | |
fafd8bce | 582 | break; |
0cc1f4bf | 583 | case ASI_KERNELTXT: /* Supervisor code access */ |
fafd8bce BS |
584 | switch (size) { |
585 | case 1: | |
0184e266 | 586 | ret = cpu_ldub_code(env, addr); |
fafd8bce BS |
587 | break; |
588 | case 2: | |
0184e266 | 589 | ret = cpu_lduw_code(env, addr); |
fafd8bce BS |
590 | break; |
591 | default: | |
592 | case 4: | |
0184e266 | 593 | ret = cpu_ldl_code(env, addr); |
fafd8bce BS |
594 | break; |
595 | case 8: | |
0184e266 | 596 | ret = cpu_ldq_code(env, addr); |
fafd8bce BS |
597 | break; |
598 | } | |
599 | break; | |
0cc1f4bf RH |
600 | case ASI_M_TXTC_TAG: /* SparcStation 5 I-cache tag */ |
601 | case ASI_M_TXTC_DATA: /* SparcStation 5 I-cache data */ | |
602 | case ASI_M_DATAC_TAG: /* SparcStation 5 D-cache tag */ | |
603 | case ASI_M_DATAC_DATA: /* SparcStation 5 D-cache data */ | |
fafd8bce | 604 | break; |
fafd8bce BS |
605 | case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */ |
606 | switch (size) { | |
607 | case 1: | |
2c17449b | 608 | ret = ldub_phys(cs->as, (hwaddr)addr |
a8170e5e | 609 | | ((hwaddr)(asi & 0xf) << 32)); |
fafd8bce BS |
610 | break; |
611 | case 2: | |
41701aa4 | 612 | ret = lduw_phys(cs->as, (hwaddr)addr |
a8170e5e | 613 | | ((hwaddr)(asi & 0xf) << 32)); |
fafd8bce BS |
614 | break; |
615 | default: | |
616 | case 4: | |
fdfba1a2 | 617 | ret = ldl_phys(cs->as, (hwaddr)addr |
a8170e5e | 618 | | ((hwaddr)(asi & 0xf) << 32)); |
fafd8bce BS |
619 | break; |
620 | case 8: | |
2c17449b | 621 | ret = ldq_phys(cs->as, (hwaddr)addr |
a8170e5e | 622 | | ((hwaddr)(asi & 0xf) << 32)); |
fafd8bce BS |
623 | break; |
624 | } | |
625 | break; | |
626 | case 0x30: /* Turbosparc secondary cache diagnostic */ | |
627 | case 0x31: /* Turbosparc RAM snoop */ | |
628 | case 0x32: /* Turbosparc page table descriptor diagnostic */ | |
629 | case 0x39: /* data cache diagnostic register */ | |
630 | ret = 0; | |
631 | break; | |
632 | case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */ | |
633 | { | |
634 | int reg = (addr >> 8) & 3; | |
635 | ||
636 | switch (reg) { | |
637 | case 0: /* Breakpoint Value (Addr) */ | |
638 | ret = env->mmubpregs[reg]; | |
639 | break; | |
640 | case 1: /* Breakpoint Mask */ | |
641 | ret = env->mmubpregs[reg]; | |
642 | break; | |
643 | case 2: /* Breakpoint Control */ | |
644 | ret = env->mmubpregs[reg]; | |
645 | break; | |
646 | case 3: /* Breakpoint Status */ | |
647 | ret = env->mmubpregs[reg]; | |
648 | env->mmubpregs[reg] = 0ULL; | |
649 | break; | |
650 | } | |
651 | DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64 "\n", reg, | |
652 | ret); | |
653 | } | |
654 | break; | |
655 | case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */ | |
656 | ret = env->mmubpctrv; | |
657 | break; | |
658 | case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */ | |
659 | ret = env->mmubpctrc; | |
660 | break; | |
661 | case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */ | |
662 | ret = env->mmubpctrs; | |
663 | break; | |
664 | case 0x4c: /* SuperSPARC MMU Breakpoint Action */ | |
665 | ret = env->mmubpaction; | |
666 | break; | |
0cc1f4bf | 667 | case ASI_USERTXT: /* User code access, XXX */ |
fafd8bce | 668 | default: |
2fad1112 | 669 | cpu_unassigned_access(cs, addr, false, false, asi, size); |
fafd8bce BS |
670 | ret = 0; |
671 | break; | |
918d9a2c RH |
672 | |
673 | case ASI_USERDATA: /* User data access */ | |
674 | case ASI_KERNELDATA: /* Supervisor data access */ | |
675 | case ASI_P: /* Implicit primary context data access (v9 only?) */ | |
676 | case ASI_M_BYPASS: /* MMU passthrough */ | |
677 | case ASI_LEON_BYPASS: /* LEON MMU passthrough */ | |
678 | /* These are always handled inline. */ | |
679 | g_assert_not_reached(); | |
fafd8bce BS |
680 | } |
681 | if (sign) { | |
682 | switch (size) { | |
683 | case 1: | |
684 | ret = (int8_t) ret; | |
685 | break; | |
686 | case 2: | |
687 | ret = (int16_t) ret; | |
688 | break; | |
689 | case 4: | |
690 | ret = (int32_t) ret; | |
691 | break; | |
692 | default: | |
693 | break; | |
694 | } | |
695 | } | |
696 | #ifdef DEBUG_ASI | |
697 | dump_asi("read ", last_addr, asi, size, ret); | |
698 | #endif | |
699 | return ret; | |
700 | } | |
701 | ||
6850811e RH |
702 | void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val, |
703 | int asi, uint32_t memop) | |
fafd8bce | 704 | { |
6850811e | 705 | int size = 1 << (memop & MO_SIZE); |
31b030d4 AF |
706 | SPARCCPU *cpu = sparc_env_get_cpu(env); |
707 | CPUState *cs = CPU(cpu); | |
708 | ||
2f9d35fc | 709 | do_check_align(env, addr, size - 1, GETPC()); |
fafd8bce | 710 | switch (asi) { |
0cc1f4bf RH |
711 | case ASI_M_MXCC: /* SuperSparc MXCC registers, or... */ |
712 | /* case ASI_LEON_CACHEREGS: Leon3 cache control */ | |
fafd8bce BS |
713 | switch (addr) { |
714 | case 0x00: /* Leon3 Cache Control */ | |
715 | case 0x08: /* Leon3 Instruction Cache config */ | |
716 | case 0x0C: /* Leon3 Date Cache config */ | |
717 | if (env->def->features & CPU_FEATURE_CACHE_CTRL) { | |
fe8d8f0f | 718 | leon3_cache_control_st(env, addr, val, size); |
fafd8bce BS |
719 | } |
720 | break; | |
721 | ||
722 | case 0x01c00000: /* MXCC stream data register 0 */ | |
723 | if (size == 8) { | |
724 | env->mxccdata[0] = val; | |
725 | } else { | |
71547a3b BS |
726 | qemu_log_mask(LOG_UNIMP, |
727 | "%08x: unimplemented access size: %d\n", addr, | |
728 | size); | |
fafd8bce BS |
729 | } |
730 | break; | |
731 | case 0x01c00008: /* MXCC stream data register 1 */ | |
732 | if (size == 8) { | |
733 | env->mxccdata[1] = val; | |
734 | } else { | |
71547a3b BS |
735 | qemu_log_mask(LOG_UNIMP, |
736 | "%08x: unimplemented access size: %d\n", addr, | |
737 | size); | |
fafd8bce BS |
738 | } |
739 | break; | |
740 | case 0x01c00010: /* MXCC stream data register 2 */ | |
741 | if (size == 8) { | |
742 | env->mxccdata[2] = val; | |
743 | } else { | |
71547a3b BS |
744 | qemu_log_mask(LOG_UNIMP, |
745 | "%08x: unimplemented access size: %d\n", addr, | |
746 | size); | |
fafd8bce BS |
747 | } |
748 | break; | |
749 | case 0x01c00018: /* MXCC stream data register 3 */ | |
750 | if (size == 8) { | |
751 | env->mxccdata[3] = val; | |
752 | } else { | |
71547a3b BS |
753 | qemu_log_mask(LOG_UNIMP, |
754 | "%08x: unimplemented access size: %d\n", addr, | |
755 | size); | |
fafd8bce BS |
756 | } |
757 | break; | |
758 | case 0x01c00100: /* MXCC stream source */ | |
759 | if (size == 8) { | |
760 | env->mxccregs[0] = val; | |
761 | } else { | |
71547a3b BS |
762 | qemu_log_mask(LOG_UNIMP, |
763 | "%08x: unimplemented access size: %d\n", addr, | |
764 | size); | |
fafd8bce | 765 | } |
2c17449b EI |
766 | env->mxccdata[0] = ldq_phys(cs->as, |
767 | (env->mxccregs[0] & 0xffffffffULL) + | |
fafd8bce | 768 | 0); |
2c17449b EI |
769 | env->mxccdata[1] = ldq_phys(cs->as, |
770 | (env->mxccregs[0] & 0xffffffffULL) + | |
fafd8bce | 771 | 8); |
2c17449b EI |
772 | env->mxccdata[2] = ldq_phys(cs->as, |
773 | (env->mxccregs[0] & 0xffffffffULL) + | |
fafd8bce | 774 | 16); |
2c17449b EI |
775 | env->mxccdata[3] = ldq_phys(cs->as, |
776 | (env->mxccregs[0] & 0xffffffffULL) + | |
fafd8bce BS |
777 | 24); |
778 | break; | |
779 | case 0x01c00200: /* MXCC stream destination */ | |
780 | if (size == 8) { | |
781 | env->mxccregs[1] = val; | |
782 | } else { | |
71547a3b BS |
783 | qemu_log_mask(LOG_UNIMP, |
784 | "%08x: unimplemented access size: %d\n", addr, | |
785 | size); | |
fafd8bce | 786 | } |
f606604f | 787 | stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 0, |
fafd8bce | 788 | env->mxccdata[0]); |
f606604f | 789 | stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 8, |
fafd8bce | 790 | env->mxccdata[1]); |
f606604f | 791 | stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 16, |
fafd8bce | 792 | env->mxccdata[2]); |
f606604f | 793 | stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 24, |
fafd8bce BS |
794 | env->mxccdata[3]); |
795 | break; | |
796 | case 0x01c00a00: /* MXCC control register */ | |
797 | if (size == 8) { | |
798 | env->mxccregs[3] = val; | |
799 | } else { | |
71547a3b BS |
800 | qemu_log_mask(LOG_UNIMP, |
801 | "%08x: unimplemented access size: %d\n", addr, | |
802 | size); | |
fafd8bce BS |
803 | } |
804 | break; | |
805 | case 0x01c00a04: /* MXCC control register */ | |
806 | if (size == 4) { | |
807 | env->mxccregs[3] = (env->mxccregs[3] & 0xffffffff00000000ULL) | |
808 | | val; | |
809 | } else { | |
71547a3b BS |
810 | qemu_log_mask(LOG_UNIMP, |
811 | "%08x: unimplemented access size: %d\n", addr, | |
812 | size); | |
fafd8bce BS |
813 | } |
814 | break; | |
815 | case 0x01c00e00: /* MXCC error register */ | |
816 | /* writing a 1 bit clears the error */ | |
817 | if (size == 8) { | |
818 | env->mxccregs[6] &= ~val; | |
819 | } else { | |
71547a3b BS |
820 | qemu_log_mask(LOG_UNIMP, |
821 | "%08x: unimplemented access size: %d\n", addr, | |
822 | size); | |
fafd8bce BS |
823 | } |
824 | break; | |
825 | case 0x01c00f00: /* MBus port address register */ | |
826 | if (size == 8) { | |
827 | env->mxccregs[7] = val; | |
828 | } else { | |
71547a3b BS |
829 | qemu_log_mask(LOG_UNIMP, |
830 | "%08x: unimplemented access size: %d\n", addr, | |
831 | size); | |
fafd8bce BS |
832 | } |
833 | break; | |
834 | default: | |
71547a3b BS |
835 | qemu_log_mask(LOG_UNIMP, |
836 | "%08x: unimplemented address, size: %d\n", addr, | |
837 | size); | |
fafd8bce BS |
838 | break; |
839 | } | |
840 | DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64 "\n", | |
841 | asi, size, addr, val); | |
842 | #ifdef DEBUG_MXCC | |
843 | dump_mxcc(env); | |
844 | #endif | |
845 | break; | |
0cc1f4bf RH |
846 | case ASI_M_FLUSH_PROBE: /* SuperSparc MMU flush */ |
847 | case ASI_LEON_MMUFLUSH: /* LEON3 MMU flush */ | |
fafd8bce BS |
848 | { |
849 | int mmulev; | |
850 | ||
851 | mmulev = (addr >> 8) & 15; | |
852 | DPRINTF_MMU("mmu flush level %d\n", mmulev); | |
853 | switch (mmulev) { | |
854 | case 0: /* flush page */ | |
31b030d4 | 855 | tlb_flush_page(CPU(cpu), addr & 0xfffff000); |
fafd8bce BS |
856 | break; |
857 | case 1: /* flush segment (256k) */ | |
858 | case 2: /* flush region (16M) */ | |
859 | case 3: /* flush context (4G) */ | |
860 | case 4: /* flush entire */ | |
d10eb08f | 861 | tlb_flush(CPU(cpu)); |
fafd8bce BS |
862 | break; |
863 | default: | |
864 | break; | |
865 | } | |
866 | #ifdef DEBUG_MMU | |
867 | dump_mmu(stdout, fprintf, env); | |
868 | #endif | |
869 | } | |
870 | break; | |
0cc1f4bf RH |
871 | case ASI_M_MMUREGS: /* write MMU regs */ |
872 | case ASI_LEON_MMUREGS: /* LEON3 write MMU regs */ | |
fafd8bce BS |
873 | { |
874 | int reg = (addr >> 8) & 0x1f; | |
875 | uint32_t oldreg; | |
876 | ||
877 | oldreg = env->mmuregs[reg]; | |
878 | switch (reg) { | |
879 | case 0: /* Control Register */ | |
880 | env->mmuregs[reg] = (env->mmuregs[reg] & 0xff000000) | | |
881 | (val & 0x00ffffff); | |
af7a06ba RH |
882 | /* Mappings generated during no-fault mode |
883 | are invalid in normal mode. */ | |
884 | if ((oldreg ^ env->mmuregs[reg]) | |
885 | & (MMU_NF | env->def->mmu_bm)) { | |
d10eb08f | 886 | tlb_flush(CPU(cpu)); |
fafd8bce BS |
887 | } |
888 | break; | |
889 | case 1: /* Context Table Pointer Register */ | |
890 | env->mmuregs[reg] = val & env->def->mmu_ctpr_mask; | |
891 | break; | |
892 | case 2: /* Context Register */ | |
893 | env->mmuregs[reg] = val & env->def->mmu_cxr_mask; | |
894 | if (oldreg != env->mmuregs[reg]) { | |
895 | /* we flush when the MMU context changes because | |
896 | QEMU has no MMU context support */ | |
d10eb08f | 897 | tlb_flush(CPU(cpu)); |
fafd8bce BS |
898 | } |
899 | break; | |
900 | case 3: /* Synchronous Fault Status Register with Clear */ | |
901 | case 4: /* Synchronous Fault Address Register */ | |
902 | break; | |
903 | case 0x10: /* TLB Replacement Control Register */ | |
904 | env->mmuregs[reg] = val & env->def->mmu_trcr_mask; | |
905 | break; | |
906 | case 0x13: /* Synchronous Fault Status Register with Read | |
907 | and Clear */ | |
908 | env->mmuregs[3] = val & env->def->mmu_sfsr_mask; | |
909 | break; | |
910 | case 0x14: /* Synchronous Fault Address Register */ | |
911 | env->mmuregs[4] = val; | |
912 | break; | |
913 | default: | |
914 | env->mmuregs[reg] = val; | |
915 | break; | |
916 | } | |
917 | if (oldreg != env->mmuregs[reg]) { | |
918 | DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n", | |
919 | reg, oldreg, env->mmuregs[reg]); | |
920 | } | |
921 | #ifdef DEBUG_MMU | |
922 | dump_mmu(stdout, fprintf, env); | |
923 | #endif | |
924 | } | |
925 | break; | |
0cc1f4bf RH |
926 | case ASI_M_TLBDIAG: /* Turbosparc ITLB Diagnostic */ |
927 | case ASI_M_DIAGS: /* Turbosparc DTLB Diagnostic */ | |
928 | case ASI_M_IODIAG: /* Turbosparc IOTLB Diagnostic */ | |
fafd8bce | 929 | break; |
0cc1f4bf RH |
930 | case ASI_M_TXTC_TAG: /* I-cache tag */ |
931 | case ASI_M_TXTC_DATA: /* I-cache data */ | |
932 | case ASI_M_DATAC_TAG: /* D-cache tag */ | |
933 | case ASI_M_DATAC_DATA: /* D-cache data */ | |
934 | case ASI_M_FLUSH_PAGE: /* I/D-cache flush page */ | |
935 | case ASI_M_FLUSH_SEG: /* I/D-cache flush segment */ | |
936 | case ASI_M_FLUSH_REGION: /* I/D-cache flush region */ | |
937 | case ASI_M_FLUSH_CTX: /* I/D-cache flush context */ | |
938 | case ASI_M_FLUSH_USER: /* I/D-cache flush user */ | |
fafd8bce | 939 | break; |
fafd8bce BS |
940 | case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */ |
941 | { | |
942 | switch (size) { | |
943 | case 1: | |
db3be60d | 944 | stb_phys(cs->as, (hwaddr)addr |
a8170e5e | 945 | | ((hwaddr)(asi & 0xf) << 32), val); |
fafd8bce BS |
946 | break; |
947 | case 2: | |
5ce5944d | 948 | stw_phys(cs->as, (hwaddr)addr |
a8170e5e | 949 | | ((hwaddr)(asi & 0xf) << 32), val); |
fafd8bce BS |
950 | break; |
951 | case 4: | |
952 | default: | |
ab1da857 | 953 | stl_phys(cs->as, (hwaddr)addr |
a8170e5e | 954 | | ((hwaddr)(asi & 0xf) << 32), val); |
fafd8bce BS |
955 | break; |
956 | case 8: | |
f606604f | 957 | stq_phys(cs->as, (hwaddr)addr |
a8170e5e | 958 | | ((hwaddr)(asi & 0xf) << 32), val); |
fafd8bce BS |
959 | break; |
960 | } | |
961 | } | |
962 | break; | |
963 | case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */ | |
964 | case 0x31: /* store buffer data, Ross RT620 I-cache flush or | |
965 | Turbosparc snoop RAM */ | |
966 | case 0x32: /* store buffer control or Turbosparc page table | |
967 | descriptor diagnostic */ | |
968 | case 0x36: /* I-cache flash clear */ | |
969 | case 0x37: /* D-cache flash clear */ | |
970 | break; | |
971 | case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/ | |
972 | { | |
973 | int reg = (addr >> 8) & 3; | |
974 | ||
975 | switch (reg) { | |
976 | case 0: /* Breakpoint Value (Addr) */ | |
977 | env->mmubpregs[reg] = (val & 0xfffffffffULL); | |
978 | break; | |
979 | case 1: /* Breakpoint Mask */ | |
980 | env->mmubpregs[reg] = (val & 0xfffffffffULL); | |
981 | break; | |
982 | case 2: /* Breakpoint Control */ | |
983 | env->mmubpregs[reg] = (val & 0x7fULL); | |
984 | break; | |
985 | case 3: /* Breakpoint Status */ | |
986 | env->mmubpregs[reg] = (val & 0xfULL); | |
987 | break; | |
988 | } | |
989 | DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg, | |
990 | env->mmuregs[reg]); | |
991 | } | |
992 | break; | |
993 | case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */ | |
994 | env->mmubpctrv = val & 0xffffffff; | |
995 | break; | |
996 | case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */ | |
997 | env->mmubpctrc = val & 0x3; | |
998 | break; | |
999 | case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */ | |
1000 | env->mmubpctrs = val & 0x3; | |
1001 | break; | |
1002 | case 0x4c: /* SuperSPARC MMU Breakpoint Action */ | |
1003 | env->mmubpaction = val & 0x1fff; | |
1004 | break; | |
0cc1f4bf RH |
1005 | case ASI_USERTXT: /* User code access, XXX */ |
1006 | case ASI_KERNELTXT: /* Supervisor code access, XXX */ | |
fafd8bce | 1007 | default: |
c658b94f AF |
1008 | cpu_unassigned_access(CPU(sparc_env_get_cpu(env)), |
1009 | addr, true, false, asi, size); | |
fafd8bce | 1010 | break; |
918d9a2c RH |
1011 | |
1012 | case ASI_USERDATA: /* User data access */ | |
1013 | case ASI_KERNELDATA: /* Supervisor data access */ | |
1014 | case ASI_P: | |
1015 | case ASI_M_BYPASS: /* MMU passthrough */ | |
1016 | case ASI_LEON_BYPASS: /* LEON MMU passthrough */ | |
1017 | case ASI_M_BCOPY: /* Block copy, sta access */ | |
1018 | case ASI_M_BFILL: /* Block fill, stda access */ | |
1019 | /* These are always handled inline. */ | |
1020 | g_assert_not_reached(); | |
fafd8bce BS |
1021 | } |
1022 | #ifdef DEBUG_ASI | |
1023 | dump_asi("write", addr, asi, size, val); | |
1024 | #endif | |
1025 | } | |
1026 | ||
1027 | #endif /* CONFIG_USER_ONLY */ | |
1028 | #else /* TARGET_SPARC64 */ | |
1029 | ||
1030 | #ifdef CONFIG_USER_ONLY | |
6850811e RH |
1031 | uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, |
1032 | int asi, uint32_t memop) | |
fafd8bce | 1033 | { |
6850811e RH |
1034 | int size = 1 << (memop & MO_SIZE); |
1035 | int sign = memop & MO_SIGN; | |
fafd8bce | 1036 | uint64_t ret = 0; |
fafd8bce BS |
1037 | |
1038 | if (asi < 0x80) { | |
2f9d35fc | 1039 | cpu_raise_exception_ra(env, TT_PRIV_ACT, GETPC()); |
fafd8bce | 1040 | } |
2f9d35fc | 1041 | do_check_align(env, addr, size - 1, GETPC()); |
fafd8bce BS |
1042 | addr = asi_address_mask(env, asi, addr); |
1043 | ||
1044 | switch (asi) { | |
0cc1f4bf RH |
1045 | case ASI_PNF: /* Primary no-fault */ |
1046 | case ASI_PNFL: /* Primary no-fault LE */ | |
0cc1f4bf RH |
1047 | case ASI_SNF: /* Secondary no-fault */ |
1048 | case ASI_SNFL: /* Secondary no-fault LE */ | |
fafd8bce | 1049 | if (page_check_range(addr, size, PAGE_READ) == -1) { |
918d9a2c RH |
1050 | ret = 0; |
1051 | break; | |
1052 | } | |
1053 | switch (size) { | |
1054 | case 1: | |
1055 | ret = cpu_ldub_data(env, addr); | |
1056 | break; | |
1057 | case 2: | |
1058 | ret = cpu_lduw_data(env, addr); | |
1059 | break; | |
1060 | case 4: | |
1061 | ret = cpu_ldl_data(env, addr); | |
1062 | break; | |
1063 | case 8: | |
1064 | ret = cpu_ldq_data(env, addr); | |
1065 | break; | |
1066 | default: | |
1067 | g_assert_not_reached(); | |
fafd8bce | 1068 | } |
918d9a2c RH |
1069 | break; |
1070 | break; | |
1071 | ||
1072 | case ASI_P: /* Primary */ | |
1073 | case ASI_PL: /* Primary LE */ | |
0cc1f4bf RH |
1074 | case ASI_S: /* Secondary */ |
1075 | case ASI_SL: /* Secondary LE */ | |
918d9a2c RH |
1076 | /* These are always handled inline. */ |
1077 | g_assert_not_reached(); | |
1078 | ||
fafd8bce | 1079 | default: |
918d9a2c | 1080 | cpu_raise_exception_ra(env, TT_DATA_ACCESS, GETPC()); |
fafd8bce BS |
1081 | } |
1082 | ||
1083 | /* Convert from little endian */ | |
1084 | switch (asi) { | |
0cc1f4bf RH |
1085 | case ASI_PNFL: /* Primary no-fault LE */ |
1086 | case ASI_SNFL: /* Secondary no-fault LE */ | |
fafd8bce BS |
1087 | switch (size) { |
1088 | case 2: | |
1089 | ret = bswap16(ret); | |
1090 | break; | |
1091 | case 4: | |
1092 | ret = bswap32(ret); | |
1093 | break; | |
1094 | case 8: | |
1095 | ret = bswap64(ret); | |
1096 | break; | |
fafd8bce | 1097 | } |
fafd8bce BS |
1098 | } |
1099 | ||
1100 | /* Convert to signed number */ | |
1101 | if (sign) { | |
1102 | switch (size) { | |
1103 | case 1: | |
1104 | ret = (int8_t) ret; | |
1105 | break; | |
1106 | case 2: | |
1107 | ret = (int16_t) ret; | |
1108 | break; | |
1109 | case 4: | |
1110 | ret = (int32_t) ret; | |
1111 | break; | |
fafd8bce BS |
1112 | } |
1113 | } | |
1114 | #ifdef DEBUG_ASI | |
918d9a2c | 1115 | dump_asi("read", addr, asi, size, ret); |
fafd8bce BS |
1116 | #endif |
1117 | return ret; | |
1118 | } | |
1119 | ||
fe8d8f0f | 1120 | void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val, |
6850811e | 1121 | int asi, uint32_t memop) |
fafd8bce | 1122 | { |
6850811e | 1123 | int size = 1 << (memop & MO_SIZE); |
fafd8bce BS |
1124 | #ifdef DEBUG_ASI |
1125 | dump_asi("write", addr, asi, size, val); | |
1126 | #endif | |
1127 | if (asi < 0x80) { | |
2f9d35fc | 1128 | cpu_raise_exception_ra(env, TT_PRIV_ACT, GETPC()); |
fafd8bce | 1129 | } |
2f9d35fc | 1130 | do_check_align(env, addr, size - 1, GETPC()); |
fafd8bce BS |
1131 | |
1132 | switch (asi) { | |
0cc1f4bf RH |
1133 | case ASI_P: /* Primary */ |
1134 | case ASI_PL: /* Primary LE */ | |
0cc1f4bf RH |
1135 | case ASI_S: /* Secondary */ |
1136 | case ASI_SL: /* Secondary LE */ | |
918d9a2c RH |
1137 | /* These are always handled inline. */ |
1138 | g_assert_not_reached(); | |
fafd8bce | 1139 | |
0cc1f4bf RH |
1140 | case ASI_PNF: /* Primary no-fault, RO */ |
1141 | case ASI_SNF: /* Secondary no-fault, RO */ | |
1142 | case ASI_PNFL: /* Primary no-fault LE, RO */ | |
1143 | case ASI_SNFL: /* Secondary no-fault LE, RO */ | |
fafd8bce | 1144 | default: |
2f9d35fc | 1145 | cpu_raise_exception_ra(env, TT_DATA_ACCESS, GETPC()); |
fafd8bce BS |
1146 | } |
1147 | } | |
1148 | ||
1149 | #else /* CONFIG_USER_ONLY */ | |
1150 | ||
6850811e RH |
1151 | uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, |
1152 | int asi, uint32_t memop) | |
fafd8bce | 1153 | { |
6850811e RH |
1154 | int size = 1 << (memop & MO_SIZE); |
1155 | int sign = memop & MO_SIGN; | |
2fad1112 | 1156 | CPUState *cs = CPU(sparc_env_get_cpu(env)); |
fafd8bce BS |
1157 | uint64_t ret = 0; |
1158 | #if defined(DEBUG_ASI) | |
1159 | target_ulong last_addr = addr; | |
1160 | #endif | |
1161 | ||
1162 | asi &= 0xff; | |
1163 | ||
7cd39ef2 | 1164 | do_check_asi(env, asi, GETPC()); |
2f9d35fc | 1165 | do_check_align(env, addr, size - 1, GETPC()); |
fafd8bce BS |
1166 | addr = asi_address_mask(env, asi, addr); |
1167 | ||
918d9a2c RH |
1168 | switch (asi) { |
1169 | case ASI_PNF: | |
1170 | case ASI_PNFL: | |
1171 | case ASI_SNF: | |
1172 | case ASI_SNFL: | |
1173 | { | |
1174 | TCGMemOpIdx oi; | |
1175 | int idx = (env->pstate & PS_PRIV | |
1176 | ? (asi & 1 ? MMU_KERNEL_SECONDARY_IDX : MMU_KERNEL_IDX) | |
1177 | : (asi & 1 ? MMU_USER_SECONDARY_IDX : MMU_USER_IDX)); | |
fafd8bce | 1178 | |
918d9a2c | 1179 | if (cpu_get_phys_page_nofault(env, addr, idx) == -1ULL) { |
fafd8bce | 1180 | #ifdef DEBUG_ASI |
918d9a2c | 1181 | dump_asi("read ", last_addr, asi, size, ret); |
fafd8bce | 1182 | #endif |
918d9a2c RH |
1183 | /* exception_index is set in get_physical_address_data. */ |
1184 | cpu_raise_exception_ra(env, cs->exception_index, GETPC()); | |
fafd8bce | 1185 | } |
918d9a2c | 1186 | oi = make_memop_idx(memop, idx); |
fafd8bce BS |
1187 | switch (size) { |
1188 | case 1: | |
918d9a2c | 1189 | ret = helper_ret_ldub_mmu(env, addr, oi, GETPC()); |
fafd8bce BS |
1190 | break; |
1191 | case 2: | |
918d9a2c RH |
1192 | if (asi & 8) { |
1193 | ret = helper_le_lduw_mmu(env, addr, oi, GETPC()); | |
1194 | } else { | |
1195 | ret = helper_be_lduw_mmu(env, addr, oi, GETPC()); | |
1196 | } | |
fafd8bce BS |
1197 | break; |
1198 | case 4: | |
918d9a2c RH |
1199 | if (asi & 8) { |
1200 | ret = helper_le_ldul_mmu(env, addr, oi, GETPC()); | |
1201 | } else { | |
1202 | ret = helper_be_ldul_mmu(env, addr, oi, GETPC()); | |
1203 | } | |
fafd8bce | 1204 | break; |
fafd8bce | 1205 | case 8: |
918d9a2c RH |
1206 | if (asi & 8) { |
1207 | ret = helper_le_ldq_mmu(env, addr, oi, GETPC()); | |
1208 | } else { | |
1209 | ret = helper_be_ldq_mmu(env, addr, oi, GETPC()); | |
1210 | } | |
fafd8bce | 1211 | break; |
918d9a2c RH |
1212 | default: |
1213 | g_assert_not_reached(); | |
fafd8bce | 1214 | } |
fafd8bce | 1215 | } |
918d9a2c RH |
1216 | break; |
1217 | ||
1218 | case ASI_AIUP: /* As if user primary */ | |
1219 | case ASI_AIUS: /* As if user secondary */ | |
1220 | case ASI_AIUPL: /* As if user primary LE */ | |
1221 | case ASI_AIUSL: /* As if user secondary LE */ | |
1222 | case ASI_P: /* Primary */ | |
1223 | case ASI_S: /* Secondary */ | |
1224 | case ASI_PL: /* Primary LE */ | |
1225 | case ASI_SL: /* Secondary LE */ | |
1226 | case ASI_REAL: /* Bypass */ | |
1227 | case ASI_REAL_IO: /* Bypass, non-cacheable */ | |
1228 | case ASI_REAL_L: /* Bypass LE */ | |
1229 | case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */ | |
0cc1f4bf RH |
1230 | case ASI_N: /* Nucleus */ |
1231 | case ASI_NL: /* Nucleus Little Endian (LE) */ | |
918d9a2c RH |
1232 | case ASI_NUCLEUS_QUAD_LDD: /* Nucleus quad LDD 128 bit atomic */ |
1233 | case ASI_NUCLEUS_QUAD_LDD_L: /* Nucleus quad LDD 128 bit atomic LE */ | |
1234 | case ASI_TWINX_AIUP: /* As if user primary, twinx */ | |
1235 | case ASI_TWINX_AIUS: /* As if user secondary, twinx */ | |
1236 | case ASI_TWINX_REAL: /* Real address, twinx */ | |
1237 | case ASI_TWINX_AIUP_L: /* As if user primary, twinx, LE */ | |
1238 | case ASI_TWINX_AIUS_L: /* As if user secondary, twinx, LE */ | |
1239 | case ASI_TWINX_REAL_L: /* Real address, twinx, LE */ | |
1240 | case ASI_TWINX_N: /* Nucleus, twinx */ | |
1241 | case ASI_TWINX_NL: /* Nucleus, twinx, LE */ | |
1242 | /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */ | |
1243 | case ASI_TWINX_P: /* Primary, twinx */ | |
1244 | case ASI_TWINX_PL: /* Primary, twinx, LE */ | |
1245 | case ASI_TWINX_S: /* Secondary, twinx */ | |
1246 | case ASI_TWINX_SL: /* Secondary, twinx, LE */ | |
1247 | /* These are always handled inline. */ | |
1248 | g_assert_not_reached(); | |
1249 | ||
0cc1f4bf | 1250 | case ASI_UPA_CONFIG: /* UPA config */ |
fafd8bce BS |
1251 | /* XXX */ |
1252 | break; | |
0cc1f4bf | 1253 | case ASI_LSU_CONTROL: /* LSU */ |
fafd8bce BS |
1254 | ret = env->lsu; |
1255 | break; | |
0cc1f4bf | 1256 | case ASI_IMMU: /* I-MMU regs */ |
fafd8bce BS |
1257 | { |
1258 | int reg = (addr >> 3) & 0xf; | |
20395e63 AT |
1259 | switch (reg) { |
1260 | case 0: | |
1261 | /* 0x00 I-TSB Tag Target register */ | |
fafd8bce | 1262 | ret = ultrasparc_tag_target(env->immu.tag_access); |
20395e63 AT |
1263 | break; |
1264 | case 3: /* SFSR */ | |
1265 | ret = env->immu.sfsr; | |
1266 | break; | |
1267 | case 5: /* TSB access */ | |
1268 | ret = env->immu.tsb; | |
1269 | break; | |
1270 | case 6: | |
1271 | /* 0x30 I-TSB Tag Access register */ | |
1272 | ret = env->immu.tag_access; | |
1273 | break; | |
1274 | default: | |
1275 | cpu_unassigned_access(cs, addr, false, false, 1, size); | |
1276 | ret = 0; | |
fafd8bce | 1277 | } |
fafd8bce BS |
1278 | break; |
1279 | } | |
0cc1f4bf | 1280 | case ASI_IMMU_TSB_8KB_PTR: /* I-MMU 8k TSB pointer */ |
fafd8bce BS |
1281 | { |
1282 | /* env->immuregs[5] holds I-MMU TSB register value | |
1283 | env->immuregs[6] holds I-MMU Tag Access register value */ | |
e5673ee4 | 1284 | ret = ultrasparc_tsb_pointer(env, &env->immu, 0); |
fafd8bce BS |
1285 | break; |
1286 | } | |
0cc1f4bf | 1287 | case ASI_IMMU_TSB_64KB_PTR: /* I-MMU 64k TSB pointer */ |
fafd8bce BS |
1288 | { |
1289 | /* env->immuregs[5] holds I-MMU TSB register value | |
1290 | env->immuregs[6] holds I-MMU Tag Access register value */ | |
e5673ee4 | 1291 | ret = ultrasparc_tsb_pointer(env, &env->immu, 1); |
fafd8bce BS |
1292 | break; |
1293 | } | |
0cc1f4bf | 1294 | case ASI_ITLB_DATA_ACCESS: /* I-MMU data access */ |
fafd8bce BS |
1295 | { |
1296 | int reg = (addr >> 3) & 0x3f; | |
1297 | ||
1298 | ret = env->itlb[reg].tte; | |
1299 | break; | |
1300 | } | |
0cc1f4bf | 1301 | case ASI_ITLB_TAG_READ: /* I-MMU tag read */ |
fafd8bce BS |
1302 | { |
1303 | int reg = (addr >> 3) & 0x3f; | |
1304 | ||
1305 | ret = env->itlb[reg].tag; | |
1306 | break; | |
1307 | } | |
0cc1f4bf | 1308 | case ASI_DMMU: /* D-MMU regs */ |
fafd8bce BS |
1309 | { |
1310 | int reg = (addr >> 3) & 0xf; | |
20395e63 AT |
1311 | switch (reg) { |
1312 | case 0: | |
1313 | /* 0x00 D-TSB Tag Target register */ | |
fafd8bce | 1314 | ret = ultrasparc_tag_target(env->dmmu.tag_access); |
20395e63 AT |
1315 | break; |
1316 | case 1: /* 0x08 Primary Context */ | |
1317 | ret = env->dmmu.mmu_primary_context; | |
1318 | break; | |
1319 | case 2: /* 0x10 Secondary Context */ | |
1320 | ret = env->dmmu.mmu_secondary_context; | |
1321 | break; | |
1322 | case 3: /* SFSR */ | |
1323 | ret = env->dmmu.sfsr; | |
1324 | break; | |
1325 | case 4: /* 0x20 SFAR */ | |
1326 | ret = env->dmmu.sfar; | |
1327 | break; | |
1328 | case 5: /* 0x28 TSB access */ | |
1329 | ret = env->dmmu.tsb; | |
1330 | break; | |
1331 | case 6: /* 0x30 D-TSB Tag Access register */ | |
1332 | ret = env->dmmu.tag_access; | |
1333 | break; | |
1334 | case 7: | |
1335 | ret = env->dmmu.virtual_watchpoint; | |
1336 | break; | |
1337 | case 8: | |
1338 | ret = env->dmmu.physical_watchpoint; | |
1339 | break; | |
1340 | default: | |
1341 | cpu_unassigned_access(cs, addr, false, false, 1, size); | |
1342 | ret = 0; | |
fafd8bce BS |
1343 | } |
1344 | break; | |
1345 | } | |
0cc1f4bf | 1346 | case ASI_DMMU_TSB_8KB_PTR: /* D-MMU 8k TSB pointer */ |
fafd8bce BS |
1347 | { |
1348 | /* env->dmmuregs[5] holds D-MMU TSB register value | |
1349 | env->dmmuregs[6] holds D-MMU Tag Access register value */ | |
e5673ee4 | 1350 | ret = ultrasparc_tsb_pointer(env, &env->dmmu, 0); |
fafd8bce BS |
1351 | break; |
1352 | } | |
0cc1f4bf | 1353 | case ASI_DMMU_TSB_64KB_PTR: /* D-MMU 64k TSB pointer */ |
fafd8bce BS |
1354 | { |
1355 | /* env->dmmuregs[5] holds D-MMU TSB register value | |
1356 | env->dmmuregs[6] holds D-MMU Tag Access register value */ | |
e5673ee4 | 1357 | ret = ultrasparc_tsb_pointer(env, &env->dmmu, 1); |
fafd8bce BS |
1358 | break; |
1359 | } | |
0cc1f4bf | 1360 | case ASI_DTLB_DATA_ACCESS: /* D-MMU data access */ |
fafd8bce BS |
1361 | { |
1362 | int reg = (addr >> 3) & 0x3f; | |
1363 | ||
1364 | ret = env->dtlb[reg].tte; | |
1365 | break; | |
1366 | } | |
0cc1f4bf | 1367 | case ASI_DTLB_TAG_READ: /* D-MMU tag read */ |
fafd8bce BS |
1368 | { |
1369 | int reg = (addr >> 3) & 0x3f; | |
1370 | ||
1371 | ret = env->dtlb[reg].tag; | |
1372 | break; | |
1373 | } | |
0cc1f4bf | 1374 | case ASI_INTR_DISPATCH_STAT: /* Interrupt dispatch, RO */ |
361dea40 | 1375 | break; |
0cc1f4bf | 1376 | case ASI_INTR_RECEIVE: /* Interrupt data receive */ |
361dea40 BS |
1377 | ret = env->ivec_status; |
1378 | break; | |
0cc1f4bf | 1379 | case ASI_INTR_R: /* Incoming interrupt vector, RO */ |
361dea40 BS |
1380 | { |
1381 | int reg = (addr >> 4) & 0x3; | |
1382 | if (reg < 3) { | |
1383 | ret = env->ivec_data[reg]; | |
1384 | } | |
1385 | break; | |
1386 | } | |
4ec3e346 AT |
1387 | case ASI_SCRATCHPAD: /* UA2005 privileged scratchpad */ |
1388 | if (unlikely((addr >= 0x20) && (addr < 0x30))) { | |
1389 | /* Hyperprivileged access only */ | |
1390 | cpu_unassigned_access(cs, addr, false, false, 1, size); | |
1391 | } | |
1392 | /* fall through */ | |
1393 | case ASI_HYP_SCRATCHPAD: /* UA2005 hyperprivileged scratchpad */ | |
1394 | { | |
1395 | unsigned int i = (addr >> 3) & 0x7; | |
1396 | ret = env->scratch[i]; | |
1397 | break; | |
1398 | } | |
7dd8c076 AT |
1399 | case ASI_MMU: /* UA2005 Context ID registers */ |
1400 | switch ((addr >> 3) & 0x3) { | |
1401 | case 1: | |
1402 | ret = env->dmmu.mmu_primary_context; | |
1403 | break; | |
1404 | case 2: | |
1405 | ret = env->dmmu.mmu_secondary_context; | |
1406 | break; | |
1407 | default: | |
1408 | cpu_unassigned_access(cs, addr, true, false, 1, size); | |
1409 | } | |
1410 | break; | |
0cc1f4bf RH |
1411 | case ASI_DCACHE_DATA: /* D-cache data */ |
1412 | case ASI_DCACHE_TAG: /* D-cache tag access */ | |
1413 | case ASI_ESTATE_ERROR_EN: /* E-cache error enable */ | |
1414 | case ASI_AFSR: /* E-cache asynchronous fault status */ | |
1415 | case ASI_AFAR: /* E-cache asynchronous fault address */ | |
1416 | case ASI_EC_TAG_DATA: /* E-cache tag data */ | |
1417 | case ASI_IC_INSTR: /* I-cache instruction access */ | |
1418 | case ASI_IC_TAG: /* I-cache tag access */ | |
1419 | case ASI_IC_PRE_DECODE: /* I-cache predecode */ | |
1420 | case ASI_IC_NEXT_FIELD: /* I-cache LRU etc. */ | |
1421 | case ASI_EC_W: /* E-cache tag */ | |
1422 | case ASI_EC_R: /* E-cache tag */ | |
1423 | break; | |
1424 | case ASI_DMMU_TSB_DIRECT_PTR: /* D-MMU data pointer */ | |
1425 | case ASI_ITLB_DATA_IN: /* I-MMU data in, WO */ | |
1426 | case ASI_IMMU_DEMAP: /* I-MMU demap, WO */ | |
1427 | case ASI_DTLB_DATA_IN: /* D-MMU data in, WO */ | |
1428 | case ASI_DMMU_DEMAP: /* D-MMU demap, WO */ | |
1429 | case ASI_INTR_W: /* Interrupt vector, WO */ | |
fafd8bce | 1430 | default: |
2fad1112 | 1431 | cpu_unassigned_access(cs, addr, false, false, 1, size); |
fafd8bce BS |
1432 | ret = 0; |
1433 | break; | |
fafd8bce BS |
1434 | } |
1435 | ||
1436 | /* Convert to signed number */ | |
1437 | if (sign) { | |
1438 | switch (size) { | |
1439 | case 1: | |
1440 | ret = (int8_t) ret; | |
1441 | break; | |
1442 | case 2: | |
1443 | ret = (int16_t) ret; | |
1444 | break; | |
1445 | case 4: | |
1446 | ret = (int32_t) ret; | |
1447 | break; | |
1448 | default: | |
1449 | break; | |
1450 | } | |
1451 | } | |
1452 | #ifdef DEBUG_ASI | |
1453 | dump_asi("read ", last_addr, asi, size, ret); | |
1454 | #endif | |
1455 | return ret; | |
1456 | } | |
1457 | ||
fe8d8f0f | 1458 | void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val, |
6850811e | 1459 | int asi, uint32_t memop) |
fafd8bce | 1460 | { |
6850811e | 1461 | int size = 1 << (memop & MO_SIZE); |
00c8cb0a AF |
1462 | SPARCCPU *cpu = sparc_env_get_cpu(env); |
1463 | CPUState *cs = CPU(cpu); | |
1464 | ||
fafd8bce BS |
1465 | #ifdef DEBUG_ASI |
1466 | dump_asi("write", addr, asi, size, val); | |
1467 | #endif | |
1468 | ||
1469 | asi &= 0xff; | |
1470 | ||
7cd39ef2 | 1471 | do_check_asi(env, asi, GETPC()); |
2f9d35fc | 1472 | do_check_align(env, addr, size - 1, GETPC()); |
fafd8bce BS |
1473 | addr = asi_address_mask(env, asi, addr); |
1474 | ||
fafd8bce | 1475 | switch (asi) { |
0cc1f4bf RH |
1476 | case ASI_AIUP: /* As if user primary */ |
1477 | case ASI_AIUS: /* As if user secondary */ | |
1478 | case ASI_AIUPL: /* As if user primary LE */ | |
1479 | case ASI_AIUSL: /* As if user secondary LE */ | |
1480 | case ASI_P: /* Primary */ | |
1481 | case ASI_S: /* Secondary */ | |
1482 | case ASI_PL: /* Primary LE */ | |
1483 | case ASI_SL: /* Secondary LE */ | |
0cc1f4bf RH |
1484 | case ASI_REAL: /* Bypass */ |
1485 | case ASI_REAL_IO: /* Bypass, non-cacheable */ | |
1486 | case ASI_REAL_L: /* Bypass LE */ | |
1487 | case ASI_REAL_IO_L: /* Bypass, non-cacheable LE */ | |
0cc1f4bf RH |
1488 | case ASI_N: /* Nucleus */ |
1489 | case ASI_NL: /* Nucleus Little Endian (LE) */ | |
918d9a2c RH |
1490 | case ASI_NUCLEUS_QUAD_LDD: /* Nucleus quad LDD 128 bit atomic */ |
1491 | case ASI_NUCLEUS_QUAD_LDD_L: /* Nucleus quad LDD 128 bit atomic LE */ | |
1492 | case ASI_TWINX_AIUP: /* As if user primary, twinx */ | |
1493 | case ASI_TWINX_AIUS: /* As if user secondary, twinx */ | |
1494 | case ASI_TWINX_REAL: /* Real address, twinx */ | |
1495 | case ASI_TWINX_AIUP_L: /* As if user primary, twinx, LE */ | |
1496 | case ASI_TWINX_AIUS_L: /* As if user secondary, twinx, LE */ | |
1497 | case ASI_TWINX_REAL_L: /* Real address, twinx, LE */ | |
1498 | case ASI_TWINX_N: /* Nucleus, twinx */ | |
1499 | case ASI_TWINX_NL: /* Nucleus, twinx, LE */ | |
1500 | /* ??? From the UA2011 document; overlaps BLK_INIT_QUAD_LDD_* */ | |
1501 | case ASI_TWINX_P: /* Primary, twinx */ | |
1502 | case ASI_TWINX_PL: /* Primary, twinx, LE */ | |
1503 | case ASI_TWINX_S: /* Secondary, twinx */ | |
1504 | case ASI_TWINX_SL: /* Secondary, twinx, LE */ | |
1505 | /* These are always handled inline. */ | |
1506 | g_assert_not_reached(); | |
15f746ce AT |
1507 | /* these ASIs have different functions on UltraSPARC-IIIi |
1508 | * and UA2005 CPUs. Use the explicit numbers to avoid confusion | |
1509 | */ | |
1510 | case 0x31: | |
1511 | case 0x32: | |
1512 | case 0x39: | |
1513 | case 0x3a: | |
1514 | if (cpu_has_hypervisor(env)) { | |
1515 | /* UA2005 | |
1516 | * ASI_DMMU_CTX_ZERO_TSB_BASE_PS0 | |
1517 | * ASI_DMMU_CTX_ZERO_TSB_BASE_PS1 | |
1518 | * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS0 | |
1519 | * ASI_DMMU_CTX_NONZERO_TSB_BASE_PS1 | |
1520 | */ | |
1521 | int idx = ((asi & 2) >> 1) | ((asi & 8) >> 2); | |
1522 | env->dmmu.sun4v_tsb_pointers[idx] = val; | |
1523 | } else { | |
1524 | helper_raise_exception(env, TT_ILL_INSN); | |
1525 | } | |
1526 | break; | |
1527 | case 0x33: | |
1528 | case 0x3b: | |
1529 | if (cpu_has_hypervisor(env)) { | |
1530 | /* UA2005 | |
1531 | * ASI_DMMU_CTX_ZERO_CONFIG | |
1532 | * ASI_DMMU_CTX_NONZERO_CONFIG | |
1533 | */ | |
1534 | env->dmmu.sun4v_ctx_config[(asi & 8) >> 3] = val; | |
1535 | } else { | |
1536 | helper_raise_exception(env, TT_ILL_INSN); | |
1537 | } | |
1538 | break; | |
1539 | case 0x35: | |
1540 | case 0x36: | |
1541 | case 0x3d: | |
1542 | case 0x3e: | |
1543 | if (cpu_has_hypervisor(env)) { | |
1544 | /* UA2005 | |
1545 | * ASI_IMMU_CTX_ZERO_TSB_BASE_PS0 | |
1546 | * ASI_IMMU_CTX_ZERO_TSB_BASE_PS1 | |
1547 | * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS0 | |
1548 | * ASI_IMMU_CTX_NONZERO_TSB_BASE_PS1 | |
1549 | */ | |
1550 | int idx = ((asi & 2) >> 1) | ((asi & 8) >> 2); | |
1551 | env->immu.sun4v_tsb_pointers[idx] = val; | |
1552 | } else { | |
1553 | helper_raise_exception(env, TT_ILL_INSN); | |
1554 | } | |
1555 | break; | |
1556 | case 0x37: | |
1557 | case 0x3f: | |
1558 | if (cpu_has_hypervisor(env)) { | |
1559 | /* UA2005 | |
1560 | * ASI_IMMU_CTX_ZERO_CONFIG | |
1561 | * ASI_IMMU_CTX_NONZERO_CONFIG | |
1562 | */ | |
1563 | env->immu.sun4v_ctx_config[(asi & 8) >> 3] = val; | |
1564 | } else { | |
1565 | helper_raise_exception(env, TT_ILL_INSN); | |
1566 | } | |
1567 | break; | |
0cc1f4bf | 1568 | case ASI_UPA_CONFIG: /* UPA config */ |
fafd8bce BS |
1569 | /* XXX */ |
1570 | return; | |
0cc1f4bf | 1571 | case ASI_LSU_CONTROL: /* LSU */ |
af7a06ba RH |
1572 | env->lsu = val & (DMMU_E | IMMU_E); |
1573 | return; | |
0cc1f4bf | 1574 | case ASI_IMMU: /* I-MMU regs */ |
fafd8bce BS |
1575 | { |
1576 | int reg = (addr >> 3) & 0xf; | |
1577 | uint64_t oldreg; | |
1578 | ||
96df2bc9 | 1579 | oldreg = env->immu.mmuregs[reg]; |
fafd8bce BS |
1580 | switch (reg) { |
1581 | case 0: /* RO */ | |
1582 | return; | |
1583 | case 1: /* Not in I-MMU */ | |
1584 | case 2: | |
1585 | return; | |
1586 | case 3: /* SFSR */ | |
1587 | if ((val & 1) == 0) { | |
1588 | val = 0; /* Clear SFSR */ | |
1589 | } | |
1590 | env->immu.sfsr = val; | |
1591 | break; | |
1592 | case 4: /* RO */ | |
1593 | return; | |
1594 | case 5: /* TSB access */ | |
1595 | DPRINTF_MMU("immu TSB write: 0x%016" PRIx64 " -> 0x%016" | |
1596 | PRIx64 "\n", env->immu.tsb, val); | |
1597 | env->immu.tsb = val; | |
1598 | break; | |
1599 | case 6: /* Tag access */ | |
1600 | env->immu.tag_access = val; | |
1601 | break; | |
1602 | case 7: | |
1603 | case 8: | |
1604 | return; | |
1605 | default: | |
20395e63 | 1606 | cpu_unassigned_access(cs, addr, true, false, 1, size); |
fafd8bce BS |
1607 | break; |
1608 | } | |
1609 | ||
96df2bc9 | 1610 | if (oldreg != env->immu.mmuregs[reg]) { |
fafd8bce BS |
1611 | DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64 " -> 0x%016" |
1612 | PRIx64 "\n", reg, oldreg, env->immuregs[reg]); | |
1613 | } | |
1614 | #ifdef DEBUG_MMU | |
1615 | dump_mmu(stdout, fprintf, env); | |
1616 | #endif | |
1617 | return; | |
1618 | } | |
0cc1f4bf | 1619 | case ASI_ITLB_DATA_IN: /* I-MMU data in */ |
fafd8bce BS |
1620 | replace_tlb_1bit_lru(env->itlb, env->immu.tag_access, val, "immu", env); |
1621 | return; | |
0cc1f4bf | 1622 | case ASI_ITLB_DATA_ACCESS: /* I-MMU data access */ |
fafd8bce BS |
1623 | { |
1624 | /* TODO: auto demap */ | |
1625 | ||
1626 | unsigned int i = (addr >> 3) & 0x3f; | |
1627 | ||
1628 | replace_tlb_entry(&env->itlb[i], env->immu.tag_access, val, env); | |
1629 | ||
1630 | #ifdef DEBUG_MMU | |
1631 | DPRINTF_MMU("immu data access replaced entry [%i]\n", i); | |
1632 | dump_mmu(stdout, fprintf, env); | |
1633 | #endif | |
1634 | return; | |
1635 | } | |
0cc1f4bf | 1636 | case ASI_IMMU_DEMAP: /* I-MMU demap */ |
fafd8bce BS |
1637 | demap_tlb(env->itlb, addr, "immu", env); |
1638 | return; | |
0cc1f4bf | 1639 | case ASI_DMMU: /* D-MMU regs */ |
fafd8bce BS |
1640 | { |
1641 | int reg = (addr >> 3) & 0xf; | |
1642 | uint64_t oldreg; | |
1643 | ||
96df2bc9 | 1644 | oldreg = env->dmmu.mmuregs[reg]; |
fafd8bce BS |
1645 | switch (reg) { |
1646 | case 0: /* RO */ | |
1647 | case 4: | |
1648 | return; | |
1649 | case 3: /* SFSR */ | |
1650 | if ((val & 1) == 0) { | |
1651 | val = 0; /* Clear SFSR, Fault address */ | |
1652 | env->dmmu.sfar = 0; | |
1653 | } | |
1654 | env->dmmu.sfsr = val; | |
1655 | break; | |
1656 | case 1: /* Primary context */ | |
1657 | env->dmmu.mmu_primary_context = val; | |
1658 | /* can be optimized to only flush MMU_USER_IDX | |
1659 | and MMU_KERNEL_IDX entries */ | |
d10eb08f | 1660 | tlb_flush(CPU(cpu)); |
fafd8bce BS |
1661 | break; |
1662 | case 2: /* Secondary context */ | |
1663 | env->dmmu.mmu_secondary_context = val; | |
1664 | /* can be optimized to only flush MMU_USER_SECONDARY_IDX | |
1665 | and MMU_KERNEL_SECONDARY_IDX entries */ | |
d10eb08f | 1666 | tlb_flush(CPU(cpu)); |
fafd8bce BS |
1667 | break; |
1668 | case 5: /* TSB access */ | |
1669 | DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64 " -> 0x%016" | |
1670 | PRIx64 "\n", env->dmmu.tsb, val); | |
1671 | env->dmmu.tsb = val; | |
1672 | break; | |
1673 | case 6: /* Tag access */ | |
1674 | env->dmmu.tag_access = val; | |
1675 | break; | |
1676 | case 7: /* Virtual Watchpoint */ | |
20395e63 AT |
1677 | env->dmmu.virtual_watchpoint = val; |
1678 | break; | |
fafd8bce | 1679 | case 8: /* Physical Watchpoint */ |
20395e63 AT |
1680 | env->dmmu.physical_watchpoint = val; |
1681 | break; | |
fafd8bce | 1682 | default: |
20395e63 | 1683 | cpu_unassigned_access(cs, addr, true, false, 1, size); |
fafd8bce BS |
1684 | break; |
1685 | } | |
1686 | ||
96df2bc9 | 1687 | if (oldreg != env->dmmu.mmuregs[reg]) { |
fafd8bce BS |
1688 | DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64 " -> 0x%016" |
1689 | PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]); | |
1690 | } | |
1691 | #ifdef DEBUG_MMU | |
1692 | dump_mmu(stdout, fprintf, env); | |
1693 | #endif | |
1694 | return; | |
1695 | } | |
0cc1f4bf | 1696 | case ASI_DTLB_DATA_IN: /* D-MMU data in */ |
fafd8bce BS |
1697 | replace_tlb_1bit_lru(env->dtlb, env->dmmu.tag_access, val, "dmmu", env); |
1698 | return; | |
0cc1f4bf | 1699 | case ASI_DTLB_DATA_ACCESS: /* D-MMU data access */ |
fafd8bce BS |
1700 | { |
1701 | unsigned int i = (addr >> 3) & 0x3f; | |
1702 | ||
1703 | replace_tlb_entry(&env->dtlb[i], env->dmmu.tag_access, val, env); | |
1704 | ||
1705 | #ifdef DEBUG_MMU | |
1706 | DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i); | |
1707 | dump_mmu(stdout, fprintf, env); | |
1708 | #endif | |
1709 | return; | |
1710 | } | |
0cc1f4bf | 1711 | case ASI_DMMU_DEMAP: /* D-MMU demap */ |
fafd8bce BS |
1712 | demap_tlb(env->dtlb, addr, "dmmu", env); |
1713 | return; | |
0cc1f4bf | 1714 | case ASI_INTR_RECEIVE: /* Interrupt data receive */ |
361dea40 | 1715 | env->ivec_status = val & 0x20; |
fafd8bce | 1716 | return; |
4ec3e346 AT |
1717 | case ASI_SCRATCHPAD: /* UA2005 privileged scratchpad */ |
1718 | if (unlikely((addr >= 0x20) && (addr < 0x30))) { | |
1719 | /* Hyperprivileged access only */ | |
1720 | cpu_unassigned_access(cs, addr, true, false, 1, size); | |
1721 | } | |
1722 | /* fall through */ | |
1723 | case ASI_HYP_SCRATCHPAD: /* UA2005 hyperprivileged scratchpad */ | |
1724 | { | |
1725 | unsigned int i = (addr >> 3) & 0x7; | |
1726 | env->scratch[i] = val; | |
1727 | return; | |
1728 | } | |
7dd8c076 AT |
1729 | case ASI_MMU: /* UA2005 Context ID registers */ |
1730 | { | |
1731 | switch ((addr >> 3) & 0x3) { | |
1732 | case 1: | |
1733 | env->dmmu.mmu_primary_context = val; | |
1734 | env->immu.mmu_primary_context = val; | |
1735 | tlb_flush_by_mmuidx(CPU(cpu), MMU_USER_IDX, MMU_KERNEL_IDX, -1); | |
1736 | break; | |
1737 | case 2: | |
1738 | env->dmmu.mmu_secondary_context = val; | |
1739 | env->immu.mmu_secondary_context = val; | |
1740 | tlb_flush_by_mmuidx(CPU(cpu), MMU_USER_SECONDARY_IDX, | |
1741 | MMU_KERNEL_SECONDARY_IDX, -1); | |
1742 | break; | |
1743 | default: | |
1744 | cpu_unassigned_access(cs, addr, true, false, 1, size); | |
1745 | } | |
1746 | } | |
1747 | return; | |
2f1b5292 | 1748 | case ASI_QUEUE: /* UA2005 CPU mondo queue */ |
0cc1f4bf RH |
1749 | case ASI_DCACHE_DATA: /* D-cache data */ |
1750 | case ASI_DCACHE_TAG: /* D-cache tag access */ | |
1751 | case ASI_ESTATE_ERROR_EN: /* E-cache error enable */ | |
1752 | case ASI_AFSR: /* E-cache asynchronous fault status */ | |
1753 | case ASI_AFAR: /* E-cache asynchronous fault address */ | |
1754 | case ASI_EC_TAG_DATA: /* E-cache tag data */ | |
1755 | case ASI_IC_INSTR: /* I-cache instruction access */ | |
1756 | case ASI_IC_TAG: /* I-cache tag access */ | |
1757 | case ASI_IC_PRE_DECODE: /* I-cache predecode */ | |
1758 | case ASI_IC_NEXT_FIELD: /* I-cache LRU etc. */ | |
1759 | case ASI_EC_W: /* E-cache tag */ | |
1760 | case ASI_EC_R: /* E-cache tag */ | |
fafd8bce | 1761 | return; |
0cc1f4bf RH |
1762 | case ASI_IMMU_TSB_8KB_PTR: /* I-MMU 8k TSB pointer, RO */ |
1763 | case ASI_IMMU_TSB_64KB_PTR: /* I-MMU 64k TSB pointer, RO */ | |
1764 | case ASI_ITLB_TAG_READ: /* I-MMU tag read, RO */ | |
1765 | case ASI_DMMU_TSB_8KB_PTR: /* D-MMU 8k TSB pointer, RO */ | |
1766 | case ASI_DMMU_TSB_64KB_PTR: /* D-MMU 64k TSB pointer, RO */ | |
1767 | case ASI_DMMU_TSB_DIRECT_PTR: /* D-MMU data pointer, RO */ | |
1768 | case ASI_DTLB_TAG_READ: /* D-MMU tag read, RO */ | |
1769 | case ASI_INTR_DISPATCH_STAT: /* Interrupt dispatch, RO */ | |
1770 | case ASI_INTR_R: /* Incoming interrupt vector, RO */ | |
1771 | case ASI_PNF: /* Primary no-fault, RO */ | |
1772 | case ASI_SNF: /* Secondary no-fault, RO */ | |
1773 | case ASI_PNFL: /* Primary no-fault LE, RO */ | |
1774 | case ASI_SNFL: /* Secondary no-fault LE, RO */ | |
fafd8bce | 1775 | default: |
2fad1112 | 1776 | cpu_unassigned_access(cs, addr, true, false, 1, size); |
fafd8bce BS |
1777 | return; |
1778 | } | |
1779 | } | |
1780 | #endif /* CONFIG_USER_ONLY */ | |
16c358e9 | 1781 | #endif /* TARGET_SPARC64 */ |
fafd8bce | 1782 | |
fafd8bce | 1783 | #if !defined(CONFIG_USER_ONLY) |
fe8d8f0f | 1784 | #ifndef TARGET_SPARC64 |
c658b94f AF |
1785 | void sparc_cpu_unassigned_access(CPUState *cs, hwaddr addr, |
1786 | bool is_write, bool is_exec, int is_asi, | |
1787 | unsigned size) | |
fafd8bce | 1788 | { |
c658b94f AF |
1789 | SPARCCPU *cpu = SPARC_CPU(cs); |
1790 | CPUSPARCState *env = &cpu->env; | |
fafd8bce BS |
1791 | int fault_type; |
1792 | ||
1793 | #ifdef DEBUG_UNASSIGNED | |
1794 | if (is_asi) { | |
1795 | printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx | |
1796 | " asi 0x%02x from " TARGET_FMT_lx "\n", | |
1797 | is_exec ? "exec" : is_write ? "write" : "read", size, | |
1798 | size == 1 ? "" : "s", addr, is_asi, env->pc); | |
1799 | } else { | |
1800 | printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx | |
1801 | " from " TARGET_FMT_lx "\n", | |
1802 | is_exec ? "exec" : is_write ? "write" : "read", size, | |
1803 | size == 1 ? "" : "s", addr, env->pc); | |
1804 | } | |
1805 | #endif | |
1806 | /* Don't overwrite translation and access faults */ | |
1807 | fault_type = (env->mmuregs[3] & 0x1c) >> 2; | |
1808 | if ((fault_type > 4) || (fault_type == 0)) { | |
1809 | env->mmuregs[3] = 0; /* Fault status register */ | |
1810 | if (is_asi) { | |
1811 | env->mmuregs[3] |= 1 << 16; | |
1812 | } | |
1813 | if (env->psrs) { | |
1814 | env->mmuregs[3] |= 1 << 5; | |
1815 | } | |
1816 | if (is_exec) { | |
1817 | env->mmuregs[3] |= 1 << 6; | |
1818 | } | |
1819 | if (is_write) { | |
1820 | env->mmuregs[3] |= 1 << 7; | |
1821 | } | |
1822 | env->mmuregs[3] |= (5 << 2) | 2; | |
1823 | /* SuperSPARC will never place instruction fault addresses in the FAR */ | |
1824 | if (!is_exec) { | |
1825 | env->mmuregs[4] = addr; /* Fault address register */ | |
1826 | } | |
1827 | } | |
1828 | /* overflow (same type fault was not read before another fault) */ | |
1829 | if (fault_type == ((env->mmuregs[3] & 0x1c)) >> 2) { | |
1830 | env->mmuregs[3] |= 1; | |
1831 | } | |
1832 | ||
1833 | if ((env->mmuregs[0] & MMU_E) && !(env->mmuregs[0] & MMU_NF)) { | |
2f9d35fc RH |
1834 | int tt = is_exec ? TT_CODE_ACCESS : TT_DATA_ACCESS; |
1835 | cpu_raise_exception_ra(env, tt, GETPC()); | |
fafd8bce BS |
1836 | } |
1837 | ||
1838 | /* flush neverland mappings created during no-fault mode, | |
1839 | so the sequential MMU faults report proper fault types */ | |
1840 | if (env->mmuregs[0] & MMU_NF) { | |
d10eb08f | 1841 | tlb_flush(cs); |
fafd8bce BS |
1842 | } |
1843 | } | |
fafd8bce | 1844 | #else |
c658b94f AF |
1845 | void sparc_cpu_unassigned_access(CPUState *cs, hwaddr addr, |
1846 | bool is_write, bool is_exec, int is_asi, | |
1847 | unsigned size) | |
fafd8bce | 1848 | { |
c658b94f AF |
1849 | SPARCCPU *cpu = SPARC_CPU(cs); |
1850 | CPUSPARCState *env = &cpu->env; | |
1851 | ||
fafd8bce BS |
1852 | #ifdef DEBUG_UNASSIGNED |
1853 | printf("Unassigned mem access to " TARGET_FMT_plx " from " TARGET_FMT_lx | |
1854 | "\n", addr, env->pc); | |
1855 | #endif | |
1856 | ||
1ceca928 AT |
1857 | if (is_exec) { /* XXX has_hypervisor */ |
1858 | if (env->lsu & (IMMU_E)) { | |
1859 | cpu_raise_exception_ra(env, TT_CODE_ACCESS, GETPC()); | |
1860 | } else if (cpu_has_hypervisor(env) && !(env->hpstate & HS_PRIV)) { | |
1861 | cpu_raise_exception_ra(env, TT_INSN_REAL_TRANSLATION_MISS, GETPC()); | |
1862 | } | |
1863 | } else { | |
1864 | if (env->lsu & (DMMU_E)) { | |
1865 | cpu_raise_exception_ra(env, TT_DATA_ACCESS, GETPC()); | |
1866 | } else if (cpu_has_hypervisor(env) && !(env->hpstate & HS_PRIV)) { | |
1867 | cpu_raise_exception_ra(env, TT_DATA_REAL_TRANSLATION_MISS, GETPC()); | |
1868 | } | |
1869 | } | |
fafd8bce BS |
1870 | } |
1871 | #endif | |
fafd8bce | 1872 | #endif |
0184e266 | 1873 | |
c28ae41e | 1874 | #if !defined(CONFIG_USER_ONLY) |
b35399bb SS |
1875 | void QEMU_NORETURN sparc_cpu_do_unaligned_access(CPUState *cs, vaddr addr, |
1876 | MMUAccessType access_type, | |
1877 | int mmu_idx, | |
1878 | uintptr_t retaddr) | |
0184e266 | 1879 | { |
93e22326 PB |
1880 | SPARCCPU *cpu = SPARC_CPU(cs); |
1881 | CPUSPARCState *env = &cpu->env; | |
1882 | ||
0184e266 BS |
1883 | #ifdef DEBUG_UNALIGNED |
1884 | printf("Unaligned access to 0x" TARGET_FMT_lx " from 0x" TARGET_FMT_lx | |
1885 | "\n", addr, env->pc); | |
1886 | #endif | |
2f9d35fc | 1887 | cpu_raise_exception_ra(env, TT_UNALIGNED, retaddr); |
0184e266 BS |
1888 | } |
1889 | ||
1890 | /* try to fill the TLB and return an exception if error. If retaddr is | |
1891 | NULL, it means that the function was called in C code (i.e. not | |
1892 | from generated code or from helper.c) */ | |
1893 | /* XXX: fix it to restore all registers */ | |
b35399bb SS |
1894 | void tlb_fill(CPUState *cs, target_ulong addr, MMUAccessType access_type, |
1895 | int mmu_idx, uintptr_t retaddr) | |
0184e266 BS |
1896 | { |
1897 | int ret; | |
1898 | ||
b35399bb | 1899 | ret = sparc_cpu_handle_mmu_fault(cs, addr, access_type, mmu_idx); |
0184e266 | 1900 | if (ret) { |
2f9d35fc | 1901 | cpu_loop_exit_restore(cs, retaddr); |
0184e266 BS |
1902 | } |
1903 | } | |
1904 | #endif |