]> git.proxmox.com Git - mirror_qemu.git/blob - target-sparc/ldst_helper.c
Merge remote-tracking branch 'remotes/kraxel/tags/pull-chardev-1' into staging
[mirror_qemu.git] / target-sparc / ldst_helper.c
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
20 #include "cpu.h"
21 #include "helper.h"
22
23 //#define DEBUG_MMU
24 //#define DEBUG_MXCC
25 //#define DEBUG_UNALIGNED
26 //#define DEBUG_UNASSIGNED
27 //#define DEBUG_ASI
28 //#define DEBUG_CACHE_CONTROL
29
30 #ifdef DEBUG_MMU
31 #define DPRINTF_MMU(fmt, ...) \
32 do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0)
33 #else
34 #define DPRINTF_MMU(fmt, ...) do {} while (0)
35 #endif
36
37 #ifdef DEBUG_MXCC
38 #define DPRINTF_MXCC(fmt, ...) \
39 do { printf("MXCC: " fmt , ## __VA_ARGS__); } while (0)
40 #else
41 #define DPRINTF_MXCC(fmt, ...) do {} while (0)
42 #endif
43
44 #ifdef DEBUG_ASI
45 #define DPRINTF_ASI(fmt, ...) \
46 do { printf("ASI: " fmt , ## __VA_ARGS__); } while (0)
47 #endif
48
49 #ifdef DEBUG_CACHE_CONTROL
50 #define DPRINTF_CACHE_CONTROL(fmt, ...) \
51 do { printf("CACHE_CONTROL: " fmt , ## __VA_ARGS__); } while (0)
52 #else
53 #define DPRINTF_CACHE_CONTROL(fmt, ...) do {} while (0)
54 #endif
55
56 #ifdef TARGET_SPARC64
57 #ifndef TARGET_ABI32
58 #define AM_CHECK(env1) ((env1)->pstate & PS_AM)
59 #else
60 #define AM_CHECK(env1) (1)
61 #endif
62 #endif
63
64 #define QT0 (env->qt0)
65 #define QT1 (env->qt1)
66
67 #if !defined(CONFIG_USER_ONLY)
68 static void QEMU_NORETURN do_unaligned_access(CPUSPARCState *env,
69 target_ulong addr, int is_write,
70 int is_user, uintptr_t retaddr);
71 #include "exec/softmmu_exec.h"
72 #define MMUSUFFIX _mmu
73 #define ALIGNED_ONLY
74
75 #define SHIFT 0
76 #include "exec/softmmu_template.h"
77
78 #define SHIFT 1
79 #include "exec/softmmu_template.h"
80
81 #define SHIFT 2
82 #include "exec/softmmu_template.h"
83
84 #define SHIFT 3
85 #include "exec/softmmu_template.h"
86 #endif
87
88 #if defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
89 /* Calculates TSB pointer value for fault page size 8k or 64k */
90 static uint64_t ultrasparc_tsb_pointer(uint64_t tsb_register,
91 uint64_t tag_access_register,
92 int page_size)
93 {
94 uint64_t tsb_base = tsb_register & ~0x1fffULL;
95 int tsb_split = (tsb_register & 0x1000ULL) ? 1 : 0;
96 int tsb_size = tsb_register & 0xf;
97
98 /* discard lower 13 bits which hold tag access context */
99 uint64_t tag_access_va = tag_access_register & ~0x1fffULL;
100
101 /* now reorder bits */
102 uint64_t tsb_base_mask = ~0x1fffULL;
103 uint64_t va = tag_access_va;
104
105 /* move va bits to correct position */
106 if (page_size == 8*1024) {
107 va >>= 9;
108 } else if (page_size == 64*1024) {
109 va >>= 12;
110 }
111
112 if (tsb_size) {
113 tsb_base_mask <<= tsb_size;
114 }
115
116 /* calculate tsb_base mask and adjust va if split is in use */
117 if (tsb_split) {
118 if (page_size == 8*1024) {
119 va &= ~(1ULL << (13 + tsb_size));
120 } else if (page_size == 64*1024) {
121 va |= (1ULL << (13 + tsb_size));
122 }
123 tsb_base_mask <<= 1;
124 }
125
126 return ((tsb_base & tsb_base_mask) | (va & ~tsb_base_mask)) & ~0xfULL;
127 }
128
129 /* Calculates tag target register value by reordering bits
130 in tag access register */
131 static uint64_t ultrasparc_tag_target(uint64_t tag_access_register)
132 {
133 return ((tag_access_register & 0x1fff) << 48) | (tag_access_register >> 22);
134 }
135
136 static void replace_tlb_entry(SparcTLBEntry *tlb,
137 uint64_t tlb_tag, uint64_t tlb_tte,
138 CPUSPARCState *env1)
139 {
140 target_ulong mask, size, va, offset;
141
142 /* flush page range if translation is valid */
143 if (TTE_IS_VALID(tlb->tte)) {
144
145 mask = 0xffffffffffffe000ULL;
146 mask <<= 3 * ((tlb->tte >> 61) & 3);
147 size = ~mask + 1;
148
149 va = tlb->tag & mask;
150
151 for (offset = 0; offset < size; offset += TARGET_PAGE_SIZE) {
152 tlb_flush_page(env1, va + offset);
153 }
154 }
155
156 tlb->tag = tlb_tag;
157 tlb->tte = tlb_tte;
158 }
159
160 static void demap_tlb(SparcTLBEntry *tlb, target_ulong demap_addr,
161 const char *strmmu, CPUSPARCState *env1)
162 {
163 unsigned int i;
164 target_ulong mask;
165 uint64_t context;
166
167 int is_demap_context = (demap_addr >> 6) & 1;
168
169 /* demap context */
170 switch ((demap_addr >> 4) & 3) {
171 case 0: /* primary */
172 context = env1->dmmu.mmu_primary_context;
173 break;
174 case 1: /* secondary */
175 context = env1->dmmu.mmu_secondary_context;
176 break;
177 case 2: /* nucleus */
178 context = 0;
179 break;
180 case 3: /* reserved */
181 default:
182 return;
183 }
184
185 for (i = 0; i < 64; i++) {
186 if (TTE_IS_VALID(tlb[i].tte)) {
187
188 if (is_demap_context) {
189 /* will remove non-global entries matching context value */
190 if (TTE_IS_GLOBAL(tlb[i].tte) ||
191 !tlb_compare_context(&tlb[i], context)) {
192 continue;
193 }
194 } else {
195 /* demap page
196 will remove any entry matching VA */
197 mask = 0xffffffffffffe000ULL;
198 mask <<= 3 * ((tlb[i].tte >> 61) & 3);
199
200 if (!compare_masked(demap_addr, tlb[i].tag, mask)) {
201 continue;
202 }
203
204 /* entry should be global or matching context value */
205 if (!TTE_IS_GLOBAL(tlb[i].tte) &&
206 !tlb_compare_context(&tlb[i], context)) {
207 continue;
208 }
209 }
210
211 replace_tlb_entry(&tlb[i], 0, 0, env1);
212 #ifdef DEBUG_MMU
213 DPRINTF_MMU("%s demap invalidated entry [%02u]\n", strmmu, i);
214 dump_mmu(stdout, fprintf, env1);
215 #endif
216 }
217 }
218 }
219
220 static void replace_tlb_1bit_lru(SparcTLBEntry *tlb,
221 uint64_t tlb_tag, uint64_t tlb_tte,
222 const char *strmmu, CPUSPARCState *env1)
223 {
224 unsigned int i, replace_used;
225
226 /* Try replacing invalid entry */
227 for (i = 0; i < 64; i++) {
228 if (!TTE_IS_VALID(tlb[i].tte)) {
229 replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1);
230 #ifdef DEBUG_MMU
231 DPRINTF_MMU("%s lru replaced invalid entry [%i]\n", strmmu, i);
232 dump_mmu(stdout, fprintf, env1);
233 #endif
234 return;
235 }
236 }
237
238 /* All entries are valid, try replacing unlocked entry */
239
240 for (replace_used = 0; replace_used < 2; ++replace_used) {
241
242 /* Used entries are not replaced on first pass */
243
244 for (i = 0; i < 64; i++) {
245 if (!TTE_IS_LOCKED(tlb[i].tte) && !TTE_IS_USED(tlb[i].tte)) {
246
247 replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1);
248 #ifdef DEBUG_MMU
249 DPRINTF_MMU("%s lru replaced unlocked %s entry [%i]\n",
250 strmmu, (replace_used ? "used" : "unused"), i);
251 dump_mmu(stdout, fprintf, env1);
252 #endif
253 return;
254 }
255 }
256
257 /* Now reset used bit and search for unused entries again */
258
259 for (i = 0; i < 64; i++) {
260 TTE_SET_UNUSED(tlb[i].tte);
261 }
262 }
263
264 #ifdef DEBUG_MMU
265 DPRINTF_MMU("%s lru replacement failed: no entries available\n", strmmu);
266 #endif
267 /* error state? */
268 }
269
270 #endif
271
272 static inline target_ulong address_mask(CPUSPARCState *env1, target_ulong addr)
273 {
274 #ifdef TARGET_SPARC64
275 if (AM_CHECK(env1)) {
276 addr &= 0xffffffffULL;
277 }
278 #endif
279 return addr;
280 }
281
282 /* returns true if access using this ASI is to have address translated by MMU
283 otherwise access is to raw physical address */
284 static inline int is_translating_asi(int asi)
285 {
286 #ifdef TARGET_SPARC64
287 /* Ultrasparc IIi translating asi
288 - note this list is defined by cpu implementation
289 */
290 switch (asi) {
291 case 0x04 ... 0x11:
292 case 0x16 ... 0x19:
293 case 0x1E ... 0x1F:
294 case 0x24 ... 0x2C:
295 case 0x70 ... 0x73:
296 case 0x78 ... 0x79:
297 case 0x80 ... 0xFF:
298 return 1;
299
300 default:
301 return 0;
302 }
303 #else
304 /* TODO: check sparc32 bits */
305 return 0;
306 #endif
307 }
308
309 static inline target_ulong asi_address_mask(CPUSPARCState *env,
310 int asi, target_ulong addr)
311 {
312 if (is_translating_asi(asi)) {
313 return address_mask(env, addr);
314 } else {
315 return addr;
316 }
317 }
318
319 void helper_check_align(CPUSPARCState *env, target_ulong addr, uint32_t align)
320 {
321 if (addr & align) {
322 #ifdef DEBUG_UNALIGNED
323 printf("Unaligned access to 0x" TARGET_FMT_lx " from 0x" TARGET_FMT_lx
324 "\n", addr, env->pc);
325 #endif
326 helper_raise_exception(env, TT_UNALIGNED);
327 }
328 }
329
330 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \
331 defined(DEBUG_MXCC)
332 static void dump_mxcc(CPUSPARCState *env)
333 {
334 printf("mxccdata: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64
335 "\n",
336 env->mxccdata[0], env->mxccdata[1],
337 env->mxccdata[2], env->mxccdata[3]);
338 printf("mxccregs: %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64
339 "\n"
340 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64
341 "\n",
342 env->mxccregs[0], env->mxccregs[1],
343 env->mxccregs[2], env->mxccregs[3],
344 env->mxccregs[4], env->mxccregs[5],
345 env->mxccregs[6], env->mxccregs[7]);
346 }
347 #endif
348
349 #if (defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY)) \
350 && defined(DEBUG_ASI)
351 static void dump_asi(const char *txt, target_ulong addr, int asi, int size,
352 uint64_t r1)
353 {
354 switch (size) {
355 case 1:
356 DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %02" PRIx64 "\n", txt,
357 addr, asi, r1 & 0xff);
358 break;
359 case 2:
360 DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %04" PRIx64 "\n", txt,
361 addr, asi, r1 & 0xffff);
362 break;
363 case 4:
364 DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %08" PRIx64 "\n", txt,
365 addr, asi, r1 & 0xffffffff);
366 break;
367 case 8:
368 DPRINTF_ASI("%s "TARGET_FMT_lx " asi 0x%02x = %016" PRIx64 "\n", txt,
369 addr, asi, r1);
370 break;
371 }
372 }
373 #endif
374
375 #ifndef TARGET_SPARC64
376 #ifndef CONFIG_USER_ONLY
377
378
379 /* Leon3 cache control */
380
381 static void leon3_cache_control_st(CPUSPARCState *env, target_ulong addr,
382 uint64_t val, int size)
383 {
384 DPRINTF_CACHE_CONTROL("st addr:%08x, val:%" PRIx64 ", size:%d\n",
385 addr, val, size);
386
387 if (size != 4) {
388 DPRINTF_CACHE_CONTROL("32bits only\n");
389 return;
390 }
391
392 switch (addr) {
393 case 0x00: /* Cache control */
394
395 /* These values must always be read as zeros */
396 val &= ~CACHE_CTRL_FD;
397 val &= ~CACHE_CTRL_FI;
398 val &= ~CACHE_CTRL_IB;
399 val &= ~CACHE_CTRL_IP;
400 val &= ~CACHE_CTRL_DP;
401
402 env->cache_control = val;
403 break;
404 case 0x04: /* Instruction cache configuration */
405 case 0x08: /* Data cache configuration */
406 /* Read Only */
407 break;
408 default:
409 DPRINTF_CACHE_CONTROL("write unknown register %08x\n", addr);
410 break;
411 };
412 }
413
414 static uint64_t leon3_cache_control_ld(CPUSPARCState *env, target_ulong addr,
415 int size)
416 {
417 uint64_t ret = 0;
418
419 if (size != 4) {
420 DPRINTF_CACHE_CONTROL("32bits only\n");
421 return 0;
422 }
423
424 switch (addr) {
425 case 0x00: /* Cache control */
426 ret = env->cache_control;
427 break;
428
429 /* Configuration registers are read and only always keep those
430 predefined values */
431
432 case 0x04: /* Instruction cache configuration */
433 ret = 0x10220000;
434 break;
435 case 0x08: /* Data cache configuration */
436 ret = 0x18220000;
437 break;
438 default:
439 DPRINTF_CACHE_CONTROL("read unknown register %08x\n", addr);
440 break;
441 };
442 DPRINTF_CACHE_CONTROL("ld addr:%08x, ret:0x%" PRIx64 ", size:%d\n",
443 addr, ret, size);
444 return ret;
445 }
446
447 uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, int asi, int size,
448 int sign)
449 {
450 CPUState *cs = ENV_GET_CPU(env);
451 uint64_t ret = 0;
452 #if defined(DEBUG_MXCC) || defined(DEBUG_ASI)
453 uint32_t last_addr = addr;
454 #endif
455
456 helper_check_align(env, addr, size - 1);
457 switch (asi) {
458 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
459 switch (addr) {
460 case 0x00: /* Leon3 Cache Control */
461 case 0x08: /* Leon3 Instruction Cache config */
462 case 0x0C: /* Leon3 Date Cache config */
463 if (env->def->features & CPU_FEATURE_CACHE_CTRL) {
464 ret = leon3_cache_control_ld(env, addr, size);
465 }
466 break;
467 case 0x01c00a00: /* MXCC control register */
468 if (size == 8) {
469 ret = env->mxccregs[3];
470 } else {
471 qemu_log_mask(LOG_UNIMP,
472 "%08x: unimplemented access size: %d\n", addr,
473 size);
474 }
475 break;
476 case 0x01c00a04: /* MXCC control register */
477 if (size == 4) {
478 ret = env->mxccregs[3];
479 } else {
480 qemu_log_mask(LOG_UNIMP,
481 "%08x: unimplemented access size: %d\n", addr,
482 size);
483 }
484 break;
485 case 0x01c00c00: /* Module reset register */
486 if (size == 8) {
487 ret = env->mxccregs[5];
488 /* should we do something here? */
489 } else {
490 qemu_log_mask(LOG_UNIMP,
491 "%08x: unimplemented access size: %d\n", addr,
492 size);
493 }
494 break;
495 case 0x01c00f00: /* MBus port address register */
496 if (size == 8) {
497 ret = env->mxccregs[7];
498 } else {
499 qemu_log_mask(LOG_UNIMP,
500 "%08x: unimplemented access size: %d\n", addr,
501 size);
502 }
503 break;
504 default:
505 qemu_log_mask(LOG_UNIMP,
506 "%08x: unimplemented address, size: %d\n", addr,
507 size);
508 break;
509 }
510 DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
511 "addr = %08x -> ret = %" PRIx64 ","
512 "addr = %08x\n", asi, size, sign, last_addr, ret, addr);
513 #ifdef DEBUG_MXCC
514 dump_mxcc(env);
515 #endif
516 break;
517 case 3: /* MMU probe */
518 case 0x18: /* LEON3 MMU probe */
519 {
520 int mmulev;
521
522 mmulev = (addr >> 8) & 15;
523 if (mmulev > 4) {
524 ret = 0;
525 } else {
526 ret = mmu_probe(env, addr, mmulev);
527 }
528 DPRINTF_MMU("mmu_probe: 0x%08x (lev %d) -> 0x%08" PRIx64 "\n",
529 addr, mmulev, ret);
530 }
531 break;
532 case 4: /* read MMU regs */
533 case 0x19: /* LEON3 read MMU regs */
534 {
535 int reg = (addr >> 8) & 0x1f;
536
537 ret = env->mmuregs[reg];
538 if (reg == 3) { /* Fault status cleared on read */
539 env->mmuregs[3] = 0;
540 } else if (reg == 0x13) { /* Fault status read */
541 ret = env->mmuregs[3];
542 } else if (reg == 0x14) { /* Fault address read */
543 ret = env->mmuregs[4];
544 }
545 DPRINTF_MMU("mmu_read: reg[%d] = 0x%08" PRIx64 "\n", reg, ret);
546 }
547 break;
548 case 5: /* Turbosparc ITLB Diagnostic */
549 case 6: /* Turbosparc DTLB Diagnostic */
550 case 7: /* Turbosparc IOTLB Diagnostic */
551 break;
552 case 9: /* Supervisor code access */
553 switch (size) {
554 case 1:
555 ret = cpu_ldub_code(env, addr);
556 break;
557 case 2:
558 ret = cpu_lduw_code(env, addr);
559 break;
560 default:
561 case 4:
562 ret = cpu_ldl_code(env, addr);
563 break;
564 case 8:
565 ret = cpu_ldq_code(env, addr);
566 break;
567 }
568 break;
569 case 0xa: /* User data access */
570 switch (size) {
571 case 1:
572 ret = cpu_ldub_user(env, addr);
573 break;
574 case 2:
575 ret = cpu_lduw_user(env, addr);
576 break;
577 default:
578 case 4:
579 ret = cpu_ldl_user(env, addr);
580 break;
581 case 8:
582 ret = cpu_ldq_user(env, addr);
583 break;
584 }
585 break;
586 case 0xb: /* Supervisor data access */
587 case 0x80:
588 switch (size) {
589 case 1:
590 ret = cpu_ldub_kernel(env, addr);
591 break;
592 case 2:
593 ret = cpu_lduw_kernel(env, addr);
594 break;
595 default:
596 case 4:
597 ret = cpu_ldl_kernel(env, addr);
598 break;
599 case 8:
600 ret = cpu_ldq_kernel(env, addr);
601 break;
602 }
603 break;
604 case 0xc: /* I-cache tag */
605 case 0xd: /* I-cache data */
606 case 0xe: /* D-cache tag */
607 case 0xf: /* D-cache data */
608 break;
609 case 0x20: /* MMU passthrough */
610 case 0x1c: /* LEON MMU passthrough */
611 switch (size) {
612 case 1:
613 ret = ldub_phys(cs->as, addr);
614 break;
615 case 2:
616 ret = lduw_phys(cs->as, addr);
617 break;
618 default:
619 case 4:
620 ret = ldl_phys(cs->as, addr);
621 break;
622 case 8:
623 ret = ldq_phys(cs->as, addr);
624 break;
625 }
626 break;
627 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
628 switch (size) {
629 case 1:
630 ret = ldub_phys(cs->as, (hwaddr)addr
631 | ((hwaddr)(asi & 0xf) << 32));
632 break;
633 case 2:
634 ret = lduw_phys(cs->as, (hwaddr)addr
635 | ((hwaddr)(asi & 0xf) << 32));
636 break;
637 default:
638 case 4:
639 ret = ldl_phys(cs->as, (hwaddr)addr
640 | ((hwaddr)(asi & 0xf) << 32));
641 break;
642 case 8:
643 ret = ldq_phys(cs->as, (hwaddr)addr
644 | ((hwaddr)(asi & 0xf) << 32));
645 break;
646 }
647 break;
648 case 0x30: /* Turbosparc secondary cache diagnostic */
649 case 0x31: /* Turbosparc RAM snoop */
650 case 0x32: /* Turbosparc page table descriptor diagnostic */
651 case 0x39: /* data cache diagnostic register */
652 ret = 0;
653 break;
654 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers */
655 {
656 int reg = (addr >> 8) & 3;
657
658 switch (reg) {
659 case 0: /* Breakpoint Value (Addr) */
660 ret = env->mmubpregs[reg];
661 break;
662 case 1: /* Breakpoint Mask */
663 ret = env->mmubpregs[reg];
664 break;
665 case 2: /* Breakpoint Control */
666 ret = env->mmubpregs[reg];
667 break;
668 case 3: /* Breakpoint Status */
669 ret = env->mmubpregs[reg];
670 env->mmubpregs[reg] = 0ULL;
671 break;
672 }
673 DPRINTF_MMU("read breakpoint reg[%d] 0x%016" PRIx64 "\n", reg,
674 ret);
675 }
676 break;
677 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
678 ret = env->mmubpctrv;
679 break;
680 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
681 ret = env->mmubpctrc;
682 break;
683 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
684 ret = env->mmubpctrs;
685 break;
686 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
687 ret = env->mmubpaction;
688 break;
689 case 8: /* User code access, XXX */
690 default:
691 cpu_unassigned_access(CPU(sparc_env_get_cpu(env)),
692 addr, false, false, asi, size);
693 ret = 0;
694 break;
695 }
696 if (sign) {
697 switch (size) {
698 case 1:
699 ret = (int8_t) ret;
700 break;
701 case 2:
702 ret = (int16_t) ret;
703 break;
704 case 4:
705 ret = (int32_t) ret;
706 break;
707 default:
708 break;
709 }
710 }
711 #ifdef DEBUG_ASI
712 dump_asi("read ", last_addr, asi, size, ret);
713 #endif
714 return ret;
715 }
716
717 void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val, int asi,
718 int size)
719 {
720 CPUState *cs = ENV_GET_CPU(env);
721 helper_check_align(env, addr, size - 1);
722 switch (asi) {
723 case 2: /* SuperSparc MXCC registers and Leon3 cache control */
724 switch (addr) {
725 case 0x00: /* Leon3 Cache Control */
726 case 0x08: /* Leon3 Instruction Cache config */
727 case 0x0C: /* Leon3 Date Cache config */
728 if (env->def->features & CPU_FEATURE_CACHE_CTRL) {
729 leon3_cache_control_st(env, addr, val, size);
730 }
731 break;
732
733 case 0x01c00000: /* MXCC stream data register 0 */
734 if (size == 8) {
735 env->mxccdata[0] = val;
736 } else {
737 qemu_log_mask(LOG_UNIMP,
738 "%08x: unimplemented access size: %d\n", addr,
739 size);
740 }
741 break;
742 case 0x01c00008: /* MXCC stream data register 1 */
743 if (size == 8) {
744 env->mxccdata[1] = val;
745 } else {
746 qemu_log_mask(LOG_UNIMP,
747 "%08x: unimplemented access size: %d\n", addr,
748 size);
749 }
750 break;
751 case 0x01c00010: /* MXCC stream data register 2 */
752 if (size == 8) {
753 env->mxccdata[2] = val;
754 } else {
755 qemu_log_mask(LOG_UNIMP,
756 "%08x: unimplemented access size: %d\n", addr,
757 size);
758 }
759 break;
760 case 0x01c00018: /* MXCC stream data register 3 */
761 if (size == 8) {
762 env->mxccdata[3] = val;
763 } else {
764 qemu_log_mask(LOG_UNIMP,
765 "%08x: unimplemented access size: %d\n", addr,
766 size);
767 }
768 break;
769 case 0x01c00100: /* MXCC stream source */
770 if (size == 8) {
771 env->mxccregs[0] = val;
772 } else {
773 qemu_log_mask(LOG_UNIMP,
774 "%08x: unimplemented access size: %d\n", addr,
775 size);
776 }
777 env->mxccdata[0] = ldq_phys(cs->as,
778 (env->mxccregs[0] & 0xffffffffULL) +
779 0);
780 env->mxccdata[1] = ldq_phys(cs->as,
781 (env->mxccregs[0] & 0xffffffffULL) +
782 8);
783 env->mxccdata[2] = ldq_phys(cs->as,
784 (env->mxccregs[0] & 0xffffffffULL) +
785 16);
786 env->mxccdata[3] = ldq_phys(cs->as,
787 (env->mxccregs[0] & 0xffffffffULL) +
788 24);
789 break;
790 case 0x01c00200: /* MXCC stream destination */
791 if (size == 8) {
792 env->mxccregs[1] = val;
793 } else {
794 qemu_log_mask(LOG_UNIMP,
795 "%08x: unimplemented access size: %d\n", addr,
796 size);
797 }
798 stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 0,
799 env->mxccdata[0]);
800 stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 8,
801 env->mxccdata[1]);
802 stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 16,
803 env->mxccdata[2]);
804 stq_phys(cs->as, (env->mxccregs[1] & 0xffffffffULL) + 24,
805 env->mxccdata[3]);
806 break;
807 case 0x01c00a00: /* MXCC control register */
808 if (size == 8) {
809 env->mxccregs[3] = val;
810 } else {
811 qemu_log_mask(LOG_UNIMP,
812 "%08x: unimplemented access size: %d\n", addr,
813 size);
814 }
815 break;
816 case 0x01c00a04: /* MXCC control register */
817 if (size == 4) {
818 env->mxccregs[3] = (env->mxccregs[3] & 0xffffffff00000000ULL)
819 | val;
820 } else {
821 qemu_log_mask(LOG_UNIMP,
822 "%08x: unimplemented access size: %d\n", addr,
823 size);
824 }
825 break;
826 case 0x01c00e00: /* MXCC error register */
827 /* writing a 1 bit clears the error */
828 if (size == 8) {
829 env->mxccregs[6] &= ~val;
830 } else {
831 qemu_log_mask(LOG_UNIMP,
832 "%08x: unimplemented access size: %d\n", addr,
833 size);
834 }
835 break;
836 case 0x01c00f00: /* MBus port address register */
837 if (size == 8) {
838 env->mxccregs[7] = val;
839 } else {
840 qemu_log_mask(LOG_UNIMP,
841 "%08x: unimplemented access size: %d\n", addr,
842 size);
843 }
844 break;
845 default:
846 qemu_log_mask(LOG_UNIMP,
847 "%08x: unimplemented address, size: %d\n", addr,
848 size);
849 break;
850 }
851 DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64 "\n",
852 asi, size, addr, val);
853 #ifdef DEBUG_MXCC
854 dump_mxcc(env);
855 #endif
856 break;
857 case 3: /* MMU flush */
858 case 0x18: /* LEON3 MMU flush */
859 {
860 int mmulev;
861
862 mmulev = (addr >> 8) & 15;
863 DPRINTF_MMU("mmu flush level %d\n", mmulev);
864 switch (mmulev) {
865 case 0: /* flush page */
866 tlb_flush_page(env, addr & 0xfffff000);
867 break;
868 case 1: /* flush segment (256k) */
869 case 2: /* flush region (16M) */
870 case 3: /* flush context (4G) */
871 case 4: /* flush entire */
872 tlb_flush(env, 1);
873 break;
874 default:
875 break;
876 }
877 #ifdef DEBUG_MMU
878 dump_mmu(stdout, fprintf, env);
879 #endif
880 }
881 break;
882 case 4: /* write MMU regs */
883 case 0x19: /* LEON3 write MMU regs */
884 {
885 int reg = (addr >> 8) & 0x1f;
886 uint32_t oldreg;
887
888 oldreg = env->mmuregs[reg];
889 switch (reg) {
890 case 0: /* Control Register */
891 env->mmuregs[reg] = (env->mmuregs[reg] & 0xff000000) |
892 (val & 0x00ffffff);
893 /* Mappings generated during no-fault mode or MMU
894 disabled mode are invalid in normal mode */
895 if ((oldreg & (MMU_E | MMU_NF | env->def->mmu_bm)) !=
896 (env->mmuregs[reg] & (MMU_E | MMU_NF | env->def->mmu_bm))) {
897 tlb_flush(env, 1);
898 }
899 break;
900 case 1: /* Context Table Pointer Register */
901 env->mmuregs[reg] = val & env->def->mmu_ctpr_mask;
902 break;
903 case 2: /* Context Register */
904 env->mmuregs[reg] = val & env->def->mmu_cxr_mask;
905 if (oldreg != env->mmuregs[reg]) {
906 /* we flush when the MMU context changes because
907 QEMU has no MMU context support */
908 tlb_flush(env, 1);
909 }
910 break;
911 case 3: /* Synchronous Fault Status Register with Clear */
912 case 4: /* Synchronous Fault Address Register */
913 break;
914 case 0x10: /* TLB Replacement Control Register */
915 env->mmuregs[reg] = val & env->def->mmu_trcr_mask;
916 break;
917 case 0x13: /* Synchronous Fault Status Register with Read
918 and Clear */
919 env->mmuregs[3] = val & env->def->mmu_sfsr_mask;
920 break;
921 case 0x14: /* Synchronous Fault Address Register */
922 env->mmuregs[4] = val;
923 break;
924 default:
925 env->mmuregs[reg] = val;
926 break;
927 }
928 if (oldreg != env->mmuregs[reg]) {
929 DPRINTF_MMU("mmu change reg[%d]: 0x%08x -> 0x%08x\n",
930 reg, oldreg, env->mmuregs[reg]);
931 }
932 #ifdef DEBUG_MMU
933 dump_mmu(stdout, fprintf, env);
934 #endif
935 }
936 break;
937 case 5: /* Turbosparc ITLB Diagnostic */
938 case 6: /* Turbosparc DTLB Diagnostic */
939 case 7: /* Turbosparc IOTLB Diagnostic */
940 break;
941 case 0xa: /* User data access */
942 switch (size) {
943 case 1:
944 cpu_stb_user(env, addr, val);
945 break;
946 case 2:
947 cpu_stw_user(env, addr, val);
948 break;
949 default:
950 case 4:
951 cpu_stl_user(env, addr, val);
952 break;
953 case 8:
954 cpu_stq_user(env, addr, val);
955 break;
956 }
957 break;
958 case 0xb: /* Supervisor data access */
959 case 0x80:
960 switch (size) {
961 case 1:
962 cpu_stb_kernel(env, addr, val);
963 break;
964 case 2:
965 cpu_stw_kernel(env, addr, val);
966 break;
967 default:
968 case 4:
969 cpu_stl_kernel(env, addr, val);
970 break;
971 case 8:
972 cpu_stq_kernel(env, addr, val);
973 break;
974 }
975 break;
976 case 0xc: /* I-cache tag */
977 case 0xd: /* I-cache data */
978 case 0xe: /* D-cache tag */
979 case 0xf: /* D-cache data */
980 case 0x10: /* I/D-cache flush page */
981 case 0x11: /* I/D-cache flush segment */
982 case 0x12: /* I/D-cache flush region */
983 case 0x13: /* I/D-cache flush context */
984 case 0x14: /* I/D-cache flush user */
985 break;
986 case 0x17: /* Block copy, sta access */
987 {
988 /* val = src
989 addr = dst
990 copy 32 bytes */
991 unsigned int i;
992 uint32_t src = val & ~3, dst = addr & ~3, temp;
993
994 for (i = 0; i < 32; i += 4, src += 4, dst += 4) {
995 temp = cpu_ldl_kernel(env, src);
996 cpu_stl_kernel(env, dst, temp);
997 }
998 }
999 break;
1000 case 0x1f: /* Block fill, stda access */
1001 {
1002 /* addr = dst
1003 fill 32 bytes with val */
1004 unsigned int i;
1005 uint32_t dst = addr & 7;
1006
1007 for (i = 0; i < 32; i += 8, dst += 8) {
1008 cpu_stq_kernel(env, dst, val);
1009 }
1010 }
1011 break;
1012 case 0x20: /* MMU passthrough */
1013 case 0x1c: /* LEON MMU passthrough */
1014 {
1015 switch (size) {
1016 case 1:
1017 stb_phys(cs->as, addr, val);
1018 break;
1019 case 2:
1020 stw_phys(cs->as, addr, val);
1021 break;
1022 case 4:
1023 default:
1024 stl_phys(cs->as, addr, val);
1025 break;
1026 case 8:
1027 stq_phys(cs->as, addr, val);
1028 break;
1029 }
1030 }
1031 break;
1032 case 0x21 ... 0x2f: /* MMU passthrough, 0x100000000 to 0xfffffffff */
1033 {
1034 switch (size) {
1035 case 1:
1036 stb_phys(cs->as, (hwaddr)addr
1037 | ((hwaddr)(asi & 0xf) << 32), val);
1038 break;
1039 case 2:
1040 stw_phys(cs->as, (hwaddr)addr
1041 | ((hwaddr)(asi & 0xf) << 32), val);
1042 break;
1043 case 4:
1044 default:
1045 stl_phys(cs->as, (hwaddr)addr
1046 | ((hwaddr)(asi & 0xf) << 32), val);
1047 break;
1048 case 8:
1049 stq_phys(cs->as, (hwaddr)addr
1050 | ((hwaddr)(asi & 0xf) << 32), val);
1051 break;
1052 }
1053 }
1054 break;
1055 case 0x30: /* store buffer tags or Turbosparc secondary cache diagnostic */
1056 case 0x31: /* store buffer data, Ross RT620 I-cache flush or
1057 Turbosparc snoop RAM */
1058 case 0x32: /* store buffer control or Turbosparc page table
1059 descriptor diagnostic */
1060 case 0x36: /* I-cache flash clear */
1061 case 0x37: /* D-cache flash clear */
1062 break;
1063 case 0x38: /* SuperSPARC MMU Breakpoint Control Registers*/
1064 {
1065 int reg = (addr >> 8) & 3;
1066
1067 switch (reg) {
1068 case 0: /* Breakpoint Value (Addr) */
1069 env->mmubpregs[reg] = (val & 0xfffffffffULL);
1070 break;
1071 case 1: /* Breakpoint Mask */
1072 env->mmubpregs[reg] = (val & 0xfffffffffULL);
1073 break;
1074 case 2: /* Breakpoint Control */
1075 env->mmubpregs[reg] = (val & 0x7fULL);
1076 break;
1077 case 3: /* Breakpoint Status */
1078 env->mmubpregs[reg] = (val & 0xfULL);
1079 break;
1080 }
1081 DPRINTF_MMU("write breakpoint reg[%d] 0x%016x\n", reg,
1082 env->mmuregs[reg]);
1083 }
1084 break;
1085 case 0x49: /* SuperSPARC MMU Counter Breakpoint Value */
1086 env->mmubpctrv = val & 0xffffffff;
1087 break;
1088 case 0x4a: /* SuperSPARC MMU Counter Breakpoint Control */
1089 env->mmubpctrc = val & 0x3;
1090 break;
1091 case 0x4b: /* SuperSPARC MMU Counter Breakpoint Status */
1092 env->mmubpctrs = val & 0x3;
1093 break;
1094 case 0x4c: /* SuperSPARC MMU Breakpoint Action */
1095 env->mmubpaction = val & 0x1fff;
1096 break;
1097 case 8: /* User code access, XXX */
1098 case 9: /* Supervisor code access, XXX */
1099 default:
1100 cpu_unassigned_access(CPU(sparc_env_get_cpu(env)),
1101 addr, true, false, asi, size);
1102 break;
1103 }
1104 #ifdef DEBUG_ASI
1105 dump_asi("write", addr, asi, size, val);
1106 #endif
1107 }
1108
1109 #endif /* CONFIG_USER_ONLY */
1110 #else /* TARGET_SPARC64 */
1111
1112 #ifdef CONFIG_USER_ONLY
1113 uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, int asi, int size,
1114 int sign)
1115 {
1116 uint64_t ret = 0;
1117 #if defined(DEBUG_ASI)
1118 target_ulong last_addr = addr;
1119 #endif
1120
1121 if (asi < 0x80) {
1122 helper_raise_exception(env, TT_PRIV_ACT);
1123 }
1124
1125 helper_check_align(env, addr, size - 1);
1126 addr = asi_address_mask(env, asi, addr);
1127
1128 switch (asi) {
1129 case 0x82: /* Primary no-fault */
1130 case 0x8a: /* Primary no-fault LE */
1131 if (page_check_range(addr, size, PAGE_READ) == -1) {
1132 #ifdef DEBUG_ASI
1133 dump_asi("read ", last_addr, asi, size, ret);
1134 #endif
1135 return 0;
1136 }
1137 /* Fall through */
1138 case 0x80: /* Primary */
1139 case 0x88: /* Primary LE */
1140 {
1141 switch (size) {
1142 case 1:
1143 ret = ldub_raw(addr);
1144 break;
1145 case 2:
1146 ret = lduw_raw(addr);
1147 break;
1148 case 4:
1149 ret = ldl_raw(addr);
1150 break;
1151 default:
1152 case 8:
1153 ret = ldq_raw(addr);
1154 break;
1155 }
1156 }
1157 break;
1158 case 0x83: /* Secondary no-fault */
1159 case 0x8b: /* Secondary no-fault LE */
1160 if (page_check_range(addr, size, PAGE_READ) == -1) {
1161 #ifdef DEBUG_ASI
1162 dump_asi("read ", last_addr, asi, size, ret);
1163 #endif
1164 return 0;
1165 }
1166 /* Fall through */
1167 case 0x81: /* Secondary */
1168 case 0x89: /* Secondary LE */
1169 /* XXX */
1170 break;
1171 default:
1172 break;
1173 }
1174
1175 /* Convert from little endian */
1176 switch (asi) {
1177 case 0x88: /* Primary LE */
1178 case 0x89: /* Secondary LE */
1179 case 0x8a: /* Primary no-fault LE */
1180 case 0x8b: /* Secondary no-fault LE */
1181 switch (size) {
1182 case 2:
1183 ret = bswap16(ret);
1184 break;
1185 case 4:
1186 ret = bswap32(ret);
1187 break;
1188 case 8:
1189 ret = bswap64(ret);
1190 break;
1191 default:
1192 break;
1193 }
1194 default:
1195 break;
1196 }
1197
1198 /* Convert to signed number */
1199 if (sign) {
1200 switch (size) {
1201 case 1:
1202 ret = (int8_t) ret;
1203 break;
1204 case 2:
1205 ret = (int16_t) ret;
1206 break;
1207 case 4:
1208 ret = (int32_t) ret;
1209 break;
1210 default:
1211 break;
1212 }
1213 }
1214 #ifdef DEBUG_ASI
1215 dump_asi("read ", last_addr, asi, size, ret);
1216 #endif
1217 return ret;
1218 }
1219
1220 void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val,
1221 int asi, int size)
1222 {
1223 #ifdef DEBUG_ASI
1224 dump_asi("write", addr, asi, size, val);
1225 #endif
1226 if (asi < 0x80) {
1227 helper_raise_exception(env, TT_PRIV_ACT);
1228 }
1229
1230 helper_check_align(env, addr, size - 1);
1231 addr = asi_address_mask(env, asi, addr);
1232
1233 /* Convert to little endian */
1234 switch (asi) {
1235 case 0x88: /* Primary LE */
1236 case 0x89: /* Secondary LE */
1237 switch (size) {
1238 case 2:
1239 val = bswap16(val);
1240 break;
1241 case 4:
1242 val = bswap32(val);
1243 break;
1244 case 8:
1245 val = bswap64(val);
1246 break;
1247 default:
1248 break;
1249 }
1250 default:
1251 break;
1252 }
1253
1254 switch (asi) {
1255 case 0x80: /* Primary */
1256 case 0x88: /* Primary LE */
1257 {
1258 switch (size) {
1259 case 1:
1260 stb_raw(addr, val);
1261 break;
1262 case 2:
1263 stw_raw(addr, val);
1264 break;
1265 case 4:
1266 stl_raw(addr, val);
1267 break;
1268 case 8:
1269 default:
1270 stq_raw(addr, val);
1271 break;
1272 }
1273 }
1274 break;
1275 case 0x81: /* Secondary */
1276 case 0x89: /* Secondary LE */
1277 /* XXX */
1278 return;
1279
1280 case 0x82: /* Primary no-fault, RO */
1281 case 0x83: /* Secondary no-fault, RO */
1282 case 0x8a: /* Primary no-fault LE, RO */
1283 case 0x8b: /* Secondary no-fault LE, RO */
1284 default:
1285 helper_raise_exception(env, TT_DATA_ACCESS);
1286 return;
1287 }
1288 }
1289
1290 #else /* CONFIG_USER_ONLY */
1291
1292 uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, int asi, int size,
1293 int sign)
1294 {
1295 CPUState *cs = ENV_GET_CPU(env);
1296 uint64_t ret = 0;
1297 #if defined(DEBUG_ASI)
1298 target_ulong last_addr = addr;
1299 #endif
1300
1301 asi &= 0xff;
1302
1303 if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
1304 || (cpu_has_hypervisor(env)
1305 && asi >= 0x30 && asi < 0x80
1306 && !(env->hpstate & HS_PRIV))) {
1307 helper_raise_exception(env, TT_PRIV_ACT);
1308 }
1309
1310 helper_check_align(env, addr, size - 1);
1311 addr = asi_address_mask(env, asi, addr);
1312
1313 /* process nonfaulting loads first */
1314 if ((asi & 0xf6) == 0x82) {
1315 int mmu_idx;
1316
1317 /* secondary space access has lowest asi bit equal to 1 */
1318 if (env->pstate & PS_PRIV) {
1319 mmu_idx = (asi & 1) ? MMU_KERNEL_SECONDARY_IDX : MMU_KERNEL_IDX;
1320 } else {
1321 mmu_idx = (asi & 1) ? MMU_USER_SECONDARY_IDX : MMU_USER_IDX;
1322 }
1323
1324 if (cpu_get_phys_page_nofault(env, addr, mmu_idx) == -1ULL) {
1325 #ifdef DEBUG_ASI
1326 dump_asi("read ", last_addr, asi, size, ret);
1327 #endif
1328 /* env->exception_index is set in get_physical_address_data(). */
1329 helper_raise_exception(env, env->exception_index);
1330 }
1331
1332 /* convert nonfaulting load ASIs to normal load ASIs */
1333 asi &= ~0x02;
1334 }
1335
1336 switch (asi) {
1337 case 0x10: /* As if user primary */
1338 case 0x11: /* As if user secondary */
1339 case 0x18: /* As if user primary LE */
1340 case 0x19: /* As if user secondary LE */
1341 case 0x80: /* Primary */
1342 case 0x81: /* Secondary */
1343 case 0x88: /* Primary LE */
1344 case 0x89: /* Secondary LE */
1345 case 0xe2: /* UA2007 Primary block init */
1346 case 0xe3: /* UA2007 Secondary block init */
1347 if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
1348 if (cpu_hypervisor_mode(env)) {
1349 switch (size) {
1350 case 1:
1351 ret = cpu_ldub_hypv(env, addr);
1352 break;
1353 case 2:
1354 ret = cpu_lduw_hypv(env, addr);
1355 break;
1356 case 4:
1357 ret = cpu_ldl_hypv(env, addr);
1358 break;
1359 default:
1360 case 8:
1361 ret = cpu_ldq_hypv(env, addr);
1362 break;
1363 }
1364 } else {
1365 /* secondary space access has lowest asi bit equal to 1 */
1366 if (asi & 1) {
1367 switch (size) {
1368 case 1:
1369 ret = cpu_ldub_kernel_secondary(env, addr);
1370 break;
1371 case 2:
1372 ret = cpu_lduw_kernel_secondary(env, addr);
1373 break;
1374 case 4:
1375 ret = cpu_ldl_kernel_secondary(env, addr);
1376 break;
1377 default:
1378 case 8:
1379 ret = cpu_ldq_kernel_secondary(env, addr);
1380 break;
1381 }
1382 } else {
1383 switch (size) {
1384 case 1:
1385 ret = cpu_ldub_kernel(env, addr);
1386 break;
1387 case 2:
1388 ret = cpu_lduw_kernel(env, addr);
1389 break;
1390 case 4:
1391 ret = cpu_ldl_kernel(env, addr);
1392 break;
1393 default:
1394 case 8:
1395 ret = cpu_ldq_kernel(env, addr);
1396 break;
1397 }
1398 }
1399 }
1400 } else {
1401 /* secondary space access has lowest asi bit equal to 1 */
1402 if (asi & 1) {
1403 switch (size) {
1404 case 1:
1405 ret = cpu_ldub_user_secondary(env, addr);
1406 break;
1407 case 2:
1408 ret = cpu_lduw_user_secondary(env, addr);
1409 break;
1410 case 4:
1411 ret = cpu_ldl_user_secondary(env, addr);
1412 break;
1413 default:
1414 case 8:
1415 ret = cpu_ldq_user_secondary(env, addr);
1416 break;
1417 }
1418 } else {
1419 switch (size) {
1420 case 1:
1421 ret = cpu_ldub_user(env, addr);
1422 break;
1423 case 2:
1424 ret = cpu_lduw_user(env, addr);
1425 break;
1426 case 4:
1427 ret = cpu_ldl_user(env, addr);
1428 break;
1429 default:
1430 case 8:
1431 ret = cpu_ldq_user(env, addr);
1432 break;
1433 }
1434 }
1435 }
1436 break;
1437 case 0x14: /* Bypass */
1438 case 0x15: /* Bypass, non-cacheable */
1439 case 0x1c: /* Bypass LE */
1440 case 0x1d: /* Bypass, non-cacheable LE */
1441 {
1442 switch (size) {
1443 case 1:
1444 ret = ldub_phys(cs->as, addr);
1445 break;
1446 case 2:
1447 ret = lduw_phys(cs->as, addr);
1448 break;
1449 case 4:
1450 ret = ldl_phys(cs->as, addr);
1451 break;
1452 default:
1453 case 8:
1454 ret = ldq_phys(cs->as, addr);
1455 break;
1456 }
1457 break;
1458 }
1459 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1460 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1461 Only ldda allowed */
1462 helper_raise_exception(env, TT_ILL_INSN);
1463 return 0;
1464 case 0x04: /* Nucleus */
1465 case 0x0c: /* Nucleus Little Endian (LE) */
1466 {
1467 switch (size) {
1468 case 1:
1469 ret = cpu_ldub_nucleus(env, addr);
1470 break;
1471 case 2:
1472 ret = cpu_lduw_nucleus(env, addr);
1473 break;
1474 case 4:
1475 ret = cpu_ldl_nucleus(env, addr);
1476 break;
1477 default:
1478 case 8:
1479 ret = cpu_ldq_nucleus(env, addr);
1480 break;
1481 }
1482 break;
1483 }
1484 case 0x4a: /* UPA config */
1485 /* XXX */
1486 break;
1487 case 0x45: /* LSU */
1488 ret = env->lsu;
1489 break;
1490 case 0x50: /* I-MMU regs */
1491 {
1492 int reg = (addr >> 3) & 0xf;
1493
1494 if (reg == 0) {
1495 /* I-TSB Tag Target register */
1496 ret = ultrasparc_tag_target(env->immu.tag_access);
1497 } else {
1498 ret = env->immuregs[reg];
1499 }
1500
1501 break;
1502 }
1503 case 0x51: /* I-MMU 8k TSB pointer */
1504 {
1505 /* env->immuregs[5] holds I-MMU TSB register value
1506 env->immuregs[6] holds I-MMU Tag Access register value */
1507 ret = ultrasparc_tsb_pointer(env->immu.tsb, env->immu.tag_access,
1508 8*1024);
1509 break;
1510 }
1511 case 0x52: /* I-MMU 64k TSB pointer */
1512 {
1513 /* env->immuregs[5] holds I-MMU TSB register value
1514 env->immuregs[6] holds I-MMU Tag Access register value */
1515 ret = ultrasparc_tsb_pointer(env->immu.tsb, env->immu.tag_access,
1516 64*1024);
1517 break;
1518 }
1519 case 0x55: /* I-MMU data access */
1520 {
1521 int reg = (addr >> 3) & 0x3f;
1522
1523 ret = env->itlb[reg].tte;
1524 break;
1525 }
1526 case 0x56: /* I-MMU tag read */
1527 {
1528 int reg = (addr >> 3) & 0x3f;
1529
1530 ret = env->itlb[reg].tag;
1531 break;
1532 }
1533 case 0x58: /* D-MMU regs */
1534 {
1535 int reg = (addr >> 3) & 0xf;
1536
1537 if (reg == 0) {
1538 /* D-TSB Tag Target register */
1539 ret = ultrasparc_tag_target(env->dmmu.tag_access);
1540 } else {
1541 ret = env->dmmuregs[reg];
1542 }
1543 break;
1544 }
1545 case 0x59: /* D-MMU 8k TSB pointer */
1546 {
1547 /* env->dmmuregs[5] holds D-MMU TSB register value
1548 env->dmmuregs[6] holds D-MMU Tag Access register value */
1549 ret = ultrasparc_tsb_pointer(env->dmmu.tsb, env->dmmu.tag_access,
1550 8*1024);
1551 break;
1552 }
1553 case 0x5a: /* D-MMU 64k TSB pointer */
1554 {
1555 /* env->dmmuregs[5] holds D-MMU TSB register value
1556 env->dmmuregs[6] holds D-MMU Tag Access register value */
1557 ret = ultrasparc_tsb_pointer(env->dmmu.tsb, env->dmmu.tag_access,
1558 64*1024);
1559 break;
1560 }
1561 case 0x5d: /* D-MMU data access */
1562 {
1563 int reg = (addr >> 3) & 0x3f;
1564
1565 ret = env->dtlb[reg].tte;
1566 break;
1567 }
1568 case 0x5e: /* D-MMU tag read */
1569 {
1570 int reg = (addr >> 3) & 0x3f;
1571
1572 ret = env->dtlb[reg].tag;
1573 break;
1574 }
1575 case 0x48: /* Interrupt dispatch, RO */
1576 break;
1577 case 0x49: /* Interrupt data receive */
1578 ret = env->ivec_status;
1579 break;
1580 case 0x7f: /* Incoming interrupt vector, RO */
1581 {
1582 int reg = (addr >> 4) & 0x3;
1583 if (reg < 3) {
1584 ret = env->ivec_data[reg];
1585 }
1586 break;
1587 }
1588 case 0x46: /* D-cache data */
1589 case 0x47: /* D-cache tag access */
1590 case 0x4b: /* E-cache error enable */
1591 case 0x4c: /* E-cache asynchronous fault status */
1592 case 0x4d: /* E-cache asynchronous fault address */
1593 case 0x4e: /* E-cache tag data */
1594 case 0x66: /* I-cache instruction access */
1595 case 0x67: /* I-cache tag access */
1596 case 0x6e: /* I-cache predecode */
1597 case 0x6f: /* I-cache LRU etc. */
1598 case 0x76: /* E-cache tag */
1599 case 0x7e: /* E-cache tag */
1600 break;
1601 case 0x5b: /* D-MMU data pointer */
1602 case 0x54: /* I-MMU data in, WO */
1603 case 0x57: /* I-MMU demap, WO */
1604 case 0x5c: /* D-MMU data in, WO */
1605 case 0x5f: /* D-MMU demap, WO */
1606 case 0x77: /* Interrupt vector, WO */
1607 default:
1608 cpu_unassigned_access(CPU(sparc_env_get_cpu(env)),
1609 addr, false, false, 1, size);
1610 ret = 0;
1611 break;
1612 }
1613
1614 /* Convert from little endian */
1615 switch (asi) {
1616 case 0x0c: /* Nucleus Little Endian (LE) */
1617 case 0x18: /* As if user primary LE */
1618 case 0x19: /* As if user secondary LE */
1619 case 0x1c: /* Bypass LE */
1620 case 0x1d: /* Bypass, non-cacheable LE */
1621 case 0x88: /* Primary LE */
1622 case 0x89: /* Secondary LE */
1623 switch(size) {
1624 case 2:
1625 ret = bswap16(ret);
1626 break;
1627 case 4:
1628 ret = bswap32(ret);
1629 break;
1630 case 8:
1631 ret = bswap64(ret);
1632 break;
1633 default:
1634 break;
1635 }
1636 default:
1637 break;
1638 }
1639
1640 /* Convert to signed number */
1641 if (sign) {
1642 switch (size) {
1643 case 1:
1644 ret = (int8_t) ret;
1645 break;
1646 case 2:
1647 ret = (int16_t) ret;
1648 break;
1649 case 4:
1650 ret = (int32_t) ret;
1651 break;
1652 default:
1653 break;
1654 }
1655 }
1656 #ifdef DEBUG_ASI
1657 dump_asi("read ", last_addr, asi, size, ret);
1658 #endif
1659 return ret;
1660 }
1661
1662 void helper_st_asi(CPUSPARCState *env, target_ulong addr, target_ulong val,
1663 int asi, int size)
1664 {
1665 CPUState *cs = ENV_GET_CPU(env);
1666 #ifdef DEBUG_ASI
1667 dump_asi("write", addr, asi, size, val);
1668 #endif
1669
1670 asi &= 0xff;
1671
1672 if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
1673 || (cpu_has_hypervisor(env)
1674 && asi >= 0x30 && asi < 0x80
1675 && !(env->hpstate & HS_PRIV))) {
1676 helper_raise_exception(env, TT_PRIV_ACT);
1677 }
1678
1679 helper_check_align(env, addr, size - 1);
1680 addr = asi_address_mask(env, asi, addr);
1681
1682 /* Convert to little endian */
1683 switch (asi) {
1684 case 0x0c: /* Nucleus Little Endian (LE) */
1685 case 0x18: /* As if user primary LE */
1686 case 0x19: /* As if user secondary LE */
1687 case 0x1c: /* Bypass LE */
1688 case 0x1d: /* Bypass, non-cacheable LE */
1689 case 0x88: /* Primary LE */
1690 case 0x89: /* Secondary LE */
1691 switch (size) {
1692 case 2:
1693 val = bswap16(val);
1694 break;
1695 case 4:
1696 val = bswap32(val);
1697 break;
1698 case 8:
1699 val = bswap64(val);
1700 break;
1701 default:
1702 break;
1703 }
1704 default:
1705 break;
1706 }
1707
1708 switch (asi) {
1709 case 0x10: /* As if user primary */
1710 case 0x11: /* As if user secondary */
1711 case 0x18: /* As if user primary LE */
1712 case 0x19: /* As if user secondary LE */
1713 case 0x80: /* Primary */
1714 case 0x81: /* Secondary */
1715 case 0x88: /* Primary LE */
1716 case 0x89: /* Secondary LE */
1717 case 0xe2: /* UA2007 Primary block init */
1718 case 0xe3: /* UA2007 Secondary block init */
1719 if ((asi & 0x80) && (env->pstate & PS_PRIV)) {
1720 if (cpu_hypervisor_mode(env)) {
1721 switch (size) {
1722 case 1:
1723 cpu_stb_hypv(env, addr, val);
1724 break;
1725 case 2:
1726 cpu_stw_hypv(env, addr, val);
1727 break;
1728 case 4:
1729 cpu_stl_hypv(env, addr, val);
1730 break;
1731 case 8:
1732 default:
1733 cpu_stq_hypv(env, addr, val);
1734 break;
1735 }
1736 } else {
1737 /* secondary space access has lowest asi bit equal to 1 */
1738 if (asi & 1) {
1739 switch (size) {
1740 case 1:
1741 cpu_stb_kernel_secondary(env, addr, val);
1742 break;
1743 case 2:
1744 cpu_stw_kernel_secondary(env, addr, val);
1745 break;
1746 case 4:
1747 cpu_stl_kernel_secondary(env, addr, val);
1748 break;
1749 case 8:
1750 default:
1751 cpu_stq_kernel_secondary(env, addr, val);
1752 break;
1753 }
1754 } else {
1755 switch (size) {
1756 case 1:
1757 cpu_stb_kernel(env, addr, val);
1758 break;
1759 case 2:
1760 cpu_stw_kernel(env, addr, val);
1761 break;
1762 case 4:
1763 cpu_stl_kernel(env, addr, val);
1764 break;
1765 case 8:
1766 default:
1767 cpu_stq_kernel(env, addr, val);
1768 break;
1769 }
1770 }
1771 }
1772 } else {
1773 /* secondary space access has lowest asi bit equal to 1 */
1774 if (asi & 1) {
1775 switch (size) {
1776 case 1:
1777 cpu_stb_user_secondary(env, addr, val);
1778 break;
1779 case 2:
1780 cpu_stw_user_secondary(env, addr, val);
1781 break;
1782 case 4:
1783 cpu_stl_user_secondary(env, addr, val);
1784 break;
1785 case 8:
1786 default:
1787 cpu_stq_user_secondary(env, addr, val);
1788 break;
1789 }
1790 } else {
1791 switch (size) {
1792 case 1:
1793 cpu_stb_user(env, addr, val);
1794 break;
1795 case 2:
1796 cpu_stw_user(env, addr, val);
1797 break;
1798 case 4:
1799 cpu_stl_user(env, addr, val);
1800 break;
1801 case 8:
1802 default:
1803 cpu_stq_user(env, addr, val);
1804 break;
1805 }
1806 }
1807 }
1808 break;
1809 case 0x14: /* Bypass */
1810 case 0x15: /* Bypass, non-cacheable */
1811 case 0x1c: /* Bypass LE */
1812 case 0x1d: /* Bypass, non-cacheable LE */
1813 {
1814 switch (size) {
1815 case 1:
1816 stb_phys(cs->as, addr, val);
1817 break;
1818 case 2:
1819 stw_phys(cs->as, addr, val);
1820 break;
1821 case 4:
1822 stl_phys(cs->as, addr, val);
1823 break;
1824 case 8:
1825 default:
1826 stq_phys(cs->as, addr, val);
1827 break;
1828 }
1829 }
1830 return;
1831 case 0x24: /* Nucleus quad LDD 128 bit atomic */
1832 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE
1833 Only ldda allowed */
1834 helper_raise_exception(env, TT_ILL_INSN);
1835 return;
1836 case 0x04: /* Nucleus */
1837 case 0x0c: /* Nucleus Little Endian (LE) */
1838 {
1839 switch (size) {
1840 case 1:
1841 cpu_stb_nucleus(env, addr, val);
1842 break;
1843 case 2:
1844 cpu_stw_nucleus(env, addr, val);
1845 break;
1846 case 4:
1847 cpu_stl_nucleus(env, addr, val);
1848 break;
1849 default:
1850 case 8:
1851 cpu_stq_nucleus(env, addr, val);
1852 break;
1853 }
1854 break;
1855 }
1856
1857 case 0x4a: /* UPA config */
1858 /* XXX */
1859 return;
1860 case 0x45: /* LSU */
1861 {
1862 uint64_t oldreg;
1863
1864 oldreg = env->lsu;
1865 env->lsu = val & (DMMU_E | IMMU_E);
1866 /* Mappings generated during D/I MMU disabled mode are
1867 invalid in normal mode */
1868 if (oldreg != env->lsu) {
1869 DPRINTF_MMU("LSU change: 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
1870 oldreg, env->lsu);
1871 #ifdef DEBUG_MMU
1872 dump_mmu(stdout, fprintf, env);
1873 #endif
1874 tlb_flush(env, 1);
1875 }
1876 return;
1877 }
1878 case 0x50: /* I-MMU regs */
1879 {
1880 int reg = (addr >> 3) & 0xf;
1881 uint64_t oldreg;
1882
1883 oldreg = env->immuregs[reg];
1884 switch (reg) {
1885 case 0: /* RO */
1886 return;
1887 case 1: /* Not in I-MMU */
1888 case 2:
1889 return;
1890 case 3: /* SFSR */
1891 if ((val & 1) == 0) {
1892 val = 0; /* Clear SFSR */
1893 }
1894 env->immu.sfsr = val;
1895 break;
1896 case 4: /* RO */
1897 return;
1898 case 5: /* TSB access */
1899 DPRINTF_MMU("immu TSB write: 0x%016" PRIx64 " -> 0x%016"
1900 PRIx64 "\n", env->immu.tsb, val);
1901 env->immu.tsb = val;
1902 break;
1903 case 6: /* Tag access */
1904 env->immu.tag_access = val;
1905 break;
1906 case 7:
1907 case 8:
1908 return;
1909 default:
1910 break;
1911 }
1912
1913 if (oldreg != env->immuregs[reg]) {
1914 DPRINTF_MMU("immu change reg[%d]: 0x%016" PRIx64 " -> 0x%016"
1915 PRIx64 "\n", reg, oldreg, env->immuregs[reg]);
1916 }
1917 #ifdef DEBUG_MMU
1918 dump_mmu(stdout, fprintf, env);
1919 #endif
1920 return;
1921 }
1922 case 0x54: /* I-MMU data in */
1923 replace_tlb_1bit_lru(env->itlb, env->immu.tag_access, val, "immu", env);
1924 return;
1925 case 0x55: /* I-MMU data access */
1926 {
1927 /* TODO: auto demap */
1928
1929 unsigned int i = (addr >> 3) & 0x3f;
1930
1931 replace_tlb_entry(&env->itlb[i], env->immu.tag_access, val, env);
1932
1933 #ifdef DEBUG_MMU
1934 DPRINTF_MMU("immu data access replaced entry [%i]\n", i);
1935 dump_mmu(stdout, fprintf, env);
1936 #endif
1937 return;
1938 }
1939 case 0x57: /* I-MMU demap */
1940 demap_tlb(env->itlb, addr, "immu", env);
1941 return;
1942 case 0x58: /* D-MMU regs */
1943 {
1944 int reg = (addr >> 3) & 0xf;
1945 uint64_t oldreg;
1946
1947 oldreg = env->dmmuregs[reg];
1948 switch (reg) {
1949 case 0: /* RO */
1950 case 4:
1951 return;
1952 case 3: /* SFSR */
1953 if ((val & 1) == 0) {
1954 val = 0; /* Clear SFSR, Fault address */
1955 env->dmmu.sfar = 0;
1956 }
1957 env->dmmu.sfsr = val;
1958 break;
1959 case 1: /* Primary context */
1960 env->dmmu.mmu_primary_context = val;
1961 /* can be optimized to only flush MMU_USER_IDX
1962 and MMU_KERNEL_IDX entries */
1963 tlb_flush(env, 1);
1964 break;
1965 case 2: /* Secondary context */
1966 env->dmmu.mmu_secondary_context = val;
1967 /* can be optimized to only flush MMU_USER_SECONDARY_IDX
1968 and MMU_KERNEL_SECONDARY_IDX entries */
1969 tlb_flush(env, 1);
1970 break;
1971 case 5: /* TSB access */
1972 DPRINTF_MMU("dmmu TSB write: 0x%016" PRIx64 " -> 0x%016"
1973 PRIx64 "\n", env->dmmu.tsb, val);
1974 env->dmmu.tsb = val;
1975 break;
1976 case 6: /* Tag access */
1977 env->dmmu.tag_access = val;
1978 break;
1979 case 7: /* Virtual Watchpoint */
1980 case 8: /* Physical Watchpoint */
1981 default:
1982 env->dmmuregs[reg] = val;
1983 break;
1984 }
1985
1986 if (oldreg != env->dmmuregs[reg]) {
1987 DPRINTF_MMU("dmmu change reg[%d]: 0x%016" PRIx64 " -> 0x%016"
1988 PRIx64 "\n", reg, oldreg, env->dmmuregs[reg]);
1989 }
1990 #ifdef DEBUG_MMU
1991 dump_mmu(stdout, fprintf, env);
1992 #endif
1993 return;
1994 }
1995 case 0x5c: /* D-MMU data in */
1996 replace_tlb_1bit_lru(env->dtlb, env->dmmu.tag_access, val, "dmmu", env);
1997 return;
1998 case 0x5d: /* D-MMU data access */
1999 {
2000 unsigned int i = (addr >> 3) & 0x3f;
2001
2002 replace_tlb_entry(&env->dtlb[i], env->dmmu.tag_access, val, env);
2003
2004 #ifdef DEBUG_MMU
2005 DPRINTF_MMU("dmmu data access replaced entry [%i]\n", i);
2006 dump_mmu(stdout, fprintf, env);
2007 #endif
2008 return;
2009 }
2010 case 0x5f: /* D-MMU demap */
2011 demap_tlb(env->dtlb, addr, "dmmu", env);
2012 return;
2013 case 0x49: /* Interrupt data receive */
2014 env->ivec_status = val & 0x20;
2015 return;
2016 case 0x46: /* D-cache data */
2017 case 0x47: /* D-cache tag access */
2018 case 0x4b: /* E-cache error enable */
2019 case 0x4c: /* E-cache asynchronous fault status */
2020 case 0x4d: /* E-cache asynchronous fault address */
2021 case 0x4e: /* E-cache tag data */
2022 case 0x66: /* I-cache instruction access */
2023 case 0x67: /* I-cache tag access */
2024 case 0x6e: /* I-cache predecode */
2025 case 0x6f: /* I-cache LRU etc. */
2026 case 0x76: /* E-cache tag */
2027 case 0x7e: /* E-cache tag */
2028 return;
2029 case 0x51: /* I-MMU 8k TSB pointer, RO */
2030 case 0x52: /* I-MMU 64k TSB pointer, RO */
2031 case 0x56: /* I-MMU tag read, RO */
2032 case 0x59: /* D-MMU 8k TSB pointer, RO */
2033 case 0x5a: /* D-MMU 64k TSB pointer, RO */
2034 case 0x5b: /* D-MMU data pointer, RO */
2035 case 0x5e: /* D-MMU tag read, RO */
2036 case 0x48: /* Interrupt dispatch, RO */
2037 case 0x7f: /* Incoming interrupt vector, RO */
2038 case 0x82: /* Primary no-fault, RO */
2039 case 0x83: /* Secondary no-fault, RO */
2040 case 0x8a: /* Primary no-fault LE, RO */
2041 case 0x8b: /* Secondary no-fault LE, RO */
2042 default:
2043 cpu_unassigned_access(CPU(sparc_env_get_cpu(env)),
2044 addr, true, false, 1, size);
2045 return;
2046 }
2047 }
2048 #endif /* CONFIG_USER_ONLY */
2049
2050 void helper_ldda_asi(CPUSPARCState *env, target_ulong addr, int asi, int rd)
2051 {
2052 if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0)
2053 || (cpu_has_hypervisor(env)
2054 && asi >= 0x30 && asi < 0x80
2055 && !(env->hpstate & HS_PRIV))) {
2056 helper_raise_exception(env, TT_PRIV_ACT);
2057 }
2058
2059 addr = asi_address_mask(env, asi, addr);
2060
2061 switch (asi) {
2062 #if !defined(CONFIG_USER_ONLY)
2063 case 0x24: /* Nucleus quad LDD 128 bit atomic */
2064 case 0x2c: /* Nucleus quad LDD 128 bit atomic LE */
2065 helper_check_align(env, addr, 0xf);
2066 if (rd == 0) {
2067 env->gregs[1] = cpu_ldq_nucleus(env, addr + 8);
2068 if (asi == 0x2c) {
2069 bswap64s(&env->gregs[1]);
2070 }
2071 } else if (rd < 8) {
2072 env->gregs[rd] = cpu_ldq_nucleus(env, addr);
2073 env->gregs[rd + 1] = cpu_ldq_nucleus(env, addr + 8);
2074 if (asi == 0x2c) {
2075 bswap64s(&env->gregs[rd]);
2076 bswap64s(&env->gregs[rd + 1]);
2077 }
2078 } else {
2079 env->regwptr[rd] = cpu_ldq_nucleus(env, addr);
2080 env->regwptr[rd + 1] = cpu_ldq_nucleus(env, addr + 8);
2081 if (asi == 0x2c) {
2082 bswap64s(&env->regwptr[rd]);
2083 bswap64s(&env->regwptr[rd + 1]);
2084 }
2085 }
2086 break;
2087 #endif
2088 default:
2089 helper_check_align(env, addr, 0x3);
2090 if (rd == 0) {
2091 env->gregs[1] = helper_ld_asi(env, addr + 4, asi, 4, 0);
2092 } else if (rd < 8) {
2093 env->gregs[rd] = helper_ld_asi(env, addr, asi, 4, 0);
2094 env->gregs[rd + 1] = helper_ld_asi(env, addr + 4, asi, 4, 0);
2095 } else {
2096 env->regwptr[rd] = helper_ld_asi(env, addr, asi, 4, 0);
2097 env->regwptr[rd + 1] = helper_ld_asi(env, addr + 4, asi, 4, 0);
2098 }
2099 break;
2100 }
2101 }
2102
2103 void helper_ldf_asi(CPUSPARCState *env, target_ulong addr, int asi, int size,
2104 int rd)
2105 {
2106 unsigned int i;
2107 target_ulong val;
2108
2109 helper_check_align(env, addr, 3);
2110 addr = asi_address_mask(env, asi, addr);
2111
2112 switch (asi) {
2113 case 0xf0: /* UA2007/JPS1 Block load primary */
2114 case 0xf1: /* UA2007/JPS1 Block load secondary */
2115 case 0xf8: /* UA2007/JPS1 Block load primary LE */
2116 case 0xf9: /* UA2007/JPS1 Block load secondary LE */
2117 if (rd & 7) {
2118 helper_raise_exception(env, TT_ILL_INSN);
2119 return;
2120 }
2121 helper_check_align(env, addr, 0x3f);
2122 for (i = 0; i < 8; i++, rd += 2, addr += 8) {
2123 env->fpr[rd / 2].ll = helper_ld_asi(env, addr, asi & 0x8f, 8, 0);
2124 }
2125 return;
2126
2127 case 0x16: /* UA2007 Block load primary, user privilege */
2128 case 0x17: /* UA2007 Block load secondary, user privilege */
2129 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2130 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2131 case 0x70: /* JPS1 Block load primary, user privilege */
2132 case 0x71: /* JPS1 Block load secondary, user privilege */
2133 case 0x78: /* JPS1 Block load primary LE, user privilege */
2134 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2135 if (rd & 7) {
2136 helper_raise_exception(env, TT_ILL_INSN);
2137 return;
2138 }
2139 helper_check_align(env, addr, 0x3f);
2140 for (i = 0; i < 8; i++, rd += 2, addr += 8) {
2141 env->fpr[rd / 2].ll = helper_ld_asi(env, addr, asi & 0x19, 8, 0);
2142 }
2143 return;
2144
2145 default:
2146 break;
2147 }
2148
2149 switch (size) {
2150 default:
2151 case 4:
2152 val = helper_ld_asi(env, addr, asi, size, 0);
2153 if (rd & 1) {
2154 env->fpr[rd / 2].l.lower = val;
2155 } else {
2156 env->fpr[rd / 2].l.upper = val;
2157 }
2158 break;
2159 case 8:
2160 env->fpr[rd / 2].ll = helper_ld_asi(env, addr, asi, size, 0);
2161 break;
2162 case 16:
2163 env->fpr[rd / 2].ll = helper_ld_asi(env, addr, asi, 8, 0);
2164 env->fpr[rd / 2 + 1].ll = helper_ld_asi(env, addr + 8, asi, 8, 0);
2165 break;
2166 }
2167 }
2168
2169 void helper_stf_asi(CPUSPARCState *env, target_ulong addr, int asi, int size,
2170 int rd)
2171 {
2172 unsigned int i;
2173 target_ulong val;
2174
2175 helper_check_align(env, addr, 3);
2176 addr = asi_address_mask(env, asi, addr);
2177
2178 switch (asi) {
2179 case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
2180 case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
2181 case 0xf0: /* UA2007/JPS1 Block store primary */
2182 case 0xf1: /* UA2007/JPS1 Block store secondary */
2183 case 0xf8: /* UA2007/JPS1 Block store primary LE */
2184 case 0xf9: /* UA2007/JPS1 Block store secondary LE */
2185 if (rd & 7) {
2186 helper_raise_exception(env, TT_ILL_INSN);
2187 return;
2188 }
2189 helper_check_align(env, addr, 0x3f);
2190 for (i = 0; i < 8; i++, rd += 2, addr += 8) {
2191 helper_st_asi(env, addr, env->fpr[rd / 2].ll, asi & 0x8f, 8);
2192 }
2193
2194 return;
2195 case 0x16: /* UA2007 Block load primary, user privilege */
2196 case 0x17: /* UA2007 Block load secondary, user privilege */
2197 case 0x1e: /* UA2007 Block load primary LE, user privilege */
2198 case 0x1f: /* UA2007 Block load secondary LE, user privilege */
2199 case 0x70: /* JPS1 Block store primary, user privilege */
2200 case 0x71: /* JPS1 Block store secondary, user privilege */
2201 case 0x78: /* JPS1 Block load primary LE, user privilege */
2202 case 0x79: /* JPS1 Block load secondary LE, user privilege */
2203 if (rd & 7) {
2204 helper_raise_exception(env, TT_ILL_INSN);
2205 return;
2206 }
2207 helper_check_align(env, addr, 0x3f);
2208 for (i = 0; i < 8; i++, rd += 2, addr += 8) {
2209 helper_st_asi(env, addr, env->fpr[rd / 2].ll, asi & 0x19, 8);
2210 }
2211
2212 return;
2213 default:
2214 break;
2215 }
2216
2217 switch (size) {
2218 default:
2219 case 4:
2220 if (rd & 1) {
2221 val = env->fpr[rd / 2].l.lower;
2222 } else {
2223 val = env->fpr[rd / 2].l.upper;
2224 }
2225 helper_st_asi(env, addr, val, asi, size);
2226 break;
2227 case 8:
2228 helper_st_asi(env, addr, env->fpr[rd / 2].ll, asi, size);
2229 break;
2230 case 16:
2231 helper_st_asi(env, addr, env->fpr[rd / 2].ll, asi, 8);
2232 helper_st_asi(env, addr + 8, env->fpr[rd / 2 + 1].ll, asi, 8);
2233 break;
2234 }
2235 }
2236
2237 target_ulong helper_casx_asi(CPUSPARCState *env, target_ulong addr,
2238 target_ulong val1, target_ulong val2,
2239 uint32_t asi)
2240 {
2241 target_ulong ret;
2242
2243 ret = helper_ld_asi(env, addr, asi, 8, 0);
2244 if (val2 == ret) {
2245 helper_st_asi(env, addr, val1, asi, 8);
2246 }
2247 return ret;
2248 }
2249 #endif /* TARGET_SPARC64 */
2250
2251 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2252 target_ulong helper_cas_asi(CPUSPARCState *env, target_ulong addr,
2253 target_ulong val1, target_ulong val2, uint32_t asi)
2254 {
2255 target_ulong ret;
2256
2257 val2 &= 0xffffffffUL;
2258 ret = helper_ld_asi(env, addr, asi, 4, 0);
2259 ret &= 0xffffffffUL;
2260 if (val2 == ret) {
2261 helper_st_asi(env, addr, val1 & 0xffffffffUL, asi, 4);
2262 }
2263 return ret;
2264 }
2265 #endif /* !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64) */
2266
2267 void helper_ldqf(CPUSPARCState *env, target_ulong addr, int mem_idx)
2268 {
2269 /* XXX add 128 bit load */
2270 CPU_QuadU u;
2271
2272 helper_check_align(env, addr, 7);
2273 #if !defined(CONFIG_USER_ONLY)
2274 switch (mem_idx) {
2275 case MMU_USER_IDX:
2276 u.ll.upper = cpu_ldq_user(env, addr);
2277 u.ll.lower = cpu_ldq_user(env, addr + 8);
2278 QT0 = u.q;
2279 break;
2280 case MMU_KERNEL_IDX:
2281 u.ll.upper = cpu_ldq_kernel(env, addr);
2282 u.ll.lower = cpu_ldq_kernel(env, addr + 8);
2283 QT0 = u.q;
2284 break;
2285 #ifdef TARGET_SPARC64
2286 case MMU_HYPV_IDX:
2287 u.ll.upper = cpu_ldq_hypv(env, addr);
2288 u.ll.lower = cpu_ldq_hypv(env, addr + 8);
2289 QT0 = u.q;
2290 break;
2291 #endif
2292 default:
2293 DPRINTF_MMU("helper_ldqf: need to check MMU idx %d\n", mem_idx);
2294 break;
2295 }
2296 #else
2297 u.ll.upper = ldq_raw(address_mask(env, addr));
2298 u.ll.lower = ldq_raw(address_mask(env, addr + 8));
2299 QT0 = u.q;
2300 #endif
2301 }
2302
2303 void helper_stqf(CPUSPARCState *env, target_ulong addr, int mem_idx)
2304 {
2305 /* XXX add 128 bit store */
2306 CPU_QuadU u;
2307
2308 helper_check_align(env, addr, 7);
2309 #if !defined(CONFIG_USER_ONLY)
2310 switch (mem_idx) {
2311 case MMU_USER_IDX:
2312 u.q = QT0;
2313 cpu_stq_user(env, addr, u.ll.upper);
2314 cpu_stq_user(env, addr + 8, u.ll.lower);
2315 break;
2316 case MMU_KERNEL_IDX:
2317 u.q = QT0;
2318 cpu_stq_kernel(env, addr, u.ll.upper);
2319 cpu_stq_kernel(env, addr + 8, u.ll.lower);
2320 break;
2321 #ifdef TARGET_SPARC64
2322 case MMU_HYPV_IDX:
2323 u.q = QT0;
2324 cpu_stq_hypv(env, addr, u.ll.upper);
2325 cpu_stq_hypv(env, addr + 8, u.ll.lower);
2326 break;
2327 #endif
2328 default:
2329 DPRINTF_MMU("helper_stqf: need to check MMU idx %d\n", mem_idx);
2330 break;
2331 }
2332 #else
2333 u.q = QT0;
2334 stq_raw(address_mask(env, addr), u.ll.upper);
2335 stq_raw(address_mask(env, addr + 8), u.ll.lower);
2336 #endif
2337 }
2338
2339 #if !defined(CONFIG_USER_ONLY)
2340 #ifndef TARGET_SPARC64
2341 void sparc_cpu_unassigned_access(CPUState *cs, hwaddr addr,
2342 bool is_write, bool is_exec, int is_asi,
2343 unsigned size)
2344 {
2345 SPARCCPU *cpu = SPARC_CPU(cs);
2346 CPUSPARCState *env = &cpu->env;
2347 int fault_type;
2348
2349 #ifdef DEBUG_UNASSIGNED
2350 if (is_asi) {
2351 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2352 " asi 0x%02x from " TARGET_FMT_lx "\n",
2353 is_exec ? "exec" : is_write ? "write" : "read", size,
2354 size == 1 ? "" : "s", addr, is_asi, env->pc);
2355 } else {
2356 printf("Unassigned mem %s access of %d byte%s to " TARGET_FMT_plx
2357 " from " TARGET_FMT_lx "\n",
2358 is_exec ? "exec" : is_write ? "write" : "read", size,
2359 size == 1 ? "" : "s", addr, env->pc);
2360 }
2361 #endif
2362 /* Don't overwrite translation and access faults */
2363 fault_type = (env->mmuregs[3] & 0x1c) >> 2;
2364 if ((fault_type > 4) || (fault_type == 0)) {
2365 env->mmuregs[3] = 0; /* Fault status register */
2366 if (is_asi) {
2367 env->mmuregs[3] |= 1 << 16;
2368 }
2369 if (env->psrs) {
2370 env->mmuregs[3] |= 1 << 5;
2371 }
2372 if (is_exec) {
2373 env->mmuregs[3] |= 1 << 6;
2374 }
2375 if (is_write) {
2376 env->mmuregs[3] |= 1 << 7;
2377 }
2378 env->mmuregs[3] |= (5 << 2) | 2;
2379 /* SuperSPARC will never place instruction fault addresses in the FAR */
2380 if (!is_exec) {
2381 env->mmuregs[4] = addr; /* Fault address register */
2382 }
2383 }
2384 /* overflow (same type fault was not read before another fault) */
2385 if (fault_type == ((env->mmuregs[3] & 0x1c)) >> 2) {
2386 env->mmuregs[3] |= 1;
2387 }
2388
2389 if ((env->mmuregs[0] & MMU_E) && !(env->mmuregs[0] & MMU_NF)) {
2390 if (is_exec) {
2391 helper_raise_exception(env, TT_CODE_ACCESS);
2392 } else {
2393 helper_raise_exception(env, TT_DATA_ACCESS);
2394 }
2395 }
2396
2397 /* flush neverland mappings created during no-fault mode,
2398 so the sequential MMU faults report proper fault types */
2399 if (env->mmuregs[0] & MMU_NF) {
2400 tlb_flush(env, 1);
2401 }
2402 }
2403 #else
2404 void sparc_cpu_unassigned_access(CPUState *cs, hwaddr addr,
2405 bool is_write, bool is_exec, int is_asi,
2406 unsigned size)
2407 {
2408 SPARCCPU *cpu = SPARC_CPU(cs);
2409 CPUSPARCState *env = &cpu->env;
2410
2411 #ifdef DEBUG_UNASSIGNED
2412 printf("Unassigned mem access to " TARGET_FMT_plx " from " TARGET_FMT_lx
2413 "\n", addr, env->pc);
2414 #endif
2415
2416 if (is_exec) {
2417 helper_raise_exception(env, TT_CODE_ACCESS);
2418 } else {
2419 helper_raise_exception(env, TT_DATA_ACCESS);
2420 }
2421 }
2422 #endif
2423 #endif
2424
2425 #if !defined(CONFIG_USER_ONLY)
2426 static void QEMU_NORETURN do_unaligned_access(CPUSPARCState *env,
2427 target_ulong addr, int is_write,
2428 int is_user, uintptr_t retaddr)
2429 {
2430 #ifdef DEBUG_UNALIGNED
2431 printf("Unaligned access to 0x" TARGET_FMT_lx " from 0x" TARGET_FMT_lx
2432 "\n", addr, env->pc);
2433 #endif
2434 if (retaddr) {
2435 cpu_restore_state(env, retaddr);
2436 }
2437 helper_raise_exception(env, TT_UNALIGNED);
2438 }
2439
2440 /* try to fill the TLB and return an exception if error. If retaddr is
2441 NULL, it means that the function was called in C code (i.e. not
2442 from generated code or from helper.c) */
2443 /* XXX: fix it to restore all registers */
2444 void tlb_fill(CPUSPARCState *env, target_ulong addr, int is_write, int mmu_idx,
2445 uintptr_t retaddr)
2446 {
2447 int ret;
2448
2449 ret = cpu_sparc_handle_mmu_fault(env, addr, is_write, mmu_idx);
2450 if (ret) {
2451 if (retaddr) {
2452 cpu_restore_state(env, retaddr);
2453 }
2454 cpu_loop_exit(env);
2455 }
2456 }
2457 #endif