4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "qemu-common.h"
33 //#define DEBUG_FEATURES
35 typedef struct sparc_def_t sparc_def_t;
38 const unsigned char *name;
39 target_ulong iu_version;
43 uint32_t mmu_ctpr_mask;
44 uint32_t mmu_cxr_mask;
45 uint32_t mmu_sfsr_mask;
46 uint32_t mmu_trcr_mask;
50 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const unsigned char *cpu_model);
52 /* Sparc MMU emulation */
56 spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
60 spin_lock(&global_cpu_lock);
65 spin_unlock(&global_cpu_lock);
68 #if defined(CONFIG_USER_ONLY)
70 int cpu_sparc_handle_mmu_fault(CPUState *env, target_ulong address, int rw,
71 int mmu_idx, int is_softmmu)
74 env->exception_index = TT_TFAULT;
76 env->exception_index = TT_DFAULT;
82 #ifndef TARGET_SPARC64
84 * Sparc V8 Reference MMU (SRMMU)
86 static const int access_table[8][8] = {
87 { 0, 0, 0, 0, 2, 0, 3, 3 },
88 { 0, 0, 0, 0, 2, 0, 0, 0 },
89 { 2, 2, 0, 0, 0, 2, 3, 3 },
90 { 2, 2, 0, 0, 0, 2, 0, 0 },
91 { 2, 0, 2, 0, 2, 2, 3, 3 },
92 { 2, 0, 2, 0, 2, 0, 2, 0 },
93 { 2, 2, 2, 0, 2, 2, 3, 3 },
94 { 2, 2, 2, 0, 2, 2, 2, 0 }
97 static const int perm_table[2][8] = {
100 PAGE_READ | PAGE_WRITE,
101 PAGE_READ | PAGE_EXEC,
102 PAGE_READ | PAGE_WRITE | PAGE_EXEC,
104 PAGE_READ | PAGE_WRITE,
105 PAGE_READ | PAGE_EXEC,
106 PAGE_READ | PAGE_WRITE | PAGE_EXEC
110 PAGE_READ | PAGE_WRITE,
111 PAGE_READ | PAGE_EXEC,
112 PAGE_READ | PAGE_WRITE | PAGE_EXEC,
120 static int get_physical_address(CPUState *env, target_phys_addr_t *physical,
121 int *prot, int *access_index,
122 target_ulong address, int rw, int mmu_idx)
124 int access_perms = 0;
125 target_phys_addr_t pde_ptr;
127 target_ulong virt_addr;
128 int error_code = 0, is_dirty, is_user;
129 unsigned long page_offset;
131 is_user = mmu_idx == MMU_USER_IDX;
132 virt_addr = address & TARGET_PAGE_MASK;
134 if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
135 // Boot mode: instruction fetches are taken from PROM
136 if (rw == 2 && (env->mmuregs[0] & env->mmu_bm)) {
137 *physical = env->prom_addr | (address & 0x7ffffULL);
138 *prot = PAGE_READ | PAGE_EXEC;
142 *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
146 *access_index = ((rw & 1) << 2) | (rw & 2) | (is_user? 0 : 1);
147 *physical = 0xffffffffffff0000ULL;
149 /* SPARC reference MMU table walk: Context table->L1->L2->PTE */
150 /* Context base + context number */
151 pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2);
152 pde = ldl_phys(pde_ptr);
155 switch (pde & PTE_ENTRYTYPE_MASK) {
157 case 0: /* Invalid */
159 case 2: /* L0 PTE, maybe should not happen? */
160 case 3: /* Reserved */
163 pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4);
164 pde = ldl_phys(pde_ptr);
166 switch (pde & PTE_ENTRYTYPE_MASK) {
168 case 0: /* Invalid */
169 return (1 << 8) | (1 << 2);
170 case 3: /* Reserved */
171 return (1 << 8) | (4 << 2);
173 pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4);
174 pde = ldl_phys(pde_ptr);
176 switch (pde & PTE_ENTRYTYPE_MASK) {
178 case 0: /* Invalid */
179 return (2 << 8) | (1 << 2);
180 case 3: /* Reserved */
181 return (2 << 8) | (4 << 2);
183 pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4);
184 pde = ldl_phys(pde_ptr);
186 switch (pde & PTE_ENTRYTYPE_MASK) {
188 case 0: /* Invalid */
189 return (3 << 8) | (1 << 2);
190 case 1: /* PDE, should not happen */
191 case 3: /* Reserved */
192 return (3 << 8) | (4 << 2);
194 virt_addr = address & TARGET_PAGE_MASK;
195 page_offset = (address & TARGET_PAGE_MASK) & (TARGET_PAGE_SIZE - 1);
199 virt_addr = address & ~0x3ffff;
200 page_offset = address & 0x3ffff;
204 virt_addr = address & ~0xffffff;
205 page_offset = address & 0xffffff;
209 /* update page modified and dirty bits */
210 is_dirty = (rw & 1) && !(pde & PG_MODIFIED_MASK);
211 if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
212 pde |= PG_ACCESSED_MASK;
214 pde |= PG_MODIFIED_MASK;
215 stl_phys_notdirty(pde_ptr, pde);
218 access_perms = (pde & PTE_ACCESS_MASK) >> PTE_ACCESS_SHIFT;
219 error_code = access_table[*access_index][access_perms];
220 if (error_code && !((env->mmuregs[0] & MMU_NF) && is_user))
223 /* the page can be put in the TLB */
224 *prot = perm_table[is_user][access_perms];
225 if (!(pde & PG_MODIFIED_MASK)) {
226 /* only set write access if already dirty... otherwise wait
228 *prot &= ~PAGE_WRITE;
231 /* Even if large ptes, we map only one 4KB page in the cache to
232 avoid filling it too fast */
233 *physical = ((target_phys_addr_t)(pde & PTE_ADDR_MASK) << 4) + page_offset;
237 /* Perform address translation */
238 int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
239 int mmu_idx, int is_softmmu)
241 target_phys_addr_t paddr;
243 int error_code = 0, prot, ret = 0, access_index;
245 error_code = get_physical_address(env, &paddr, &prot, &access_index, address, rw, mmu_idx);
246 if (error_code == 0) {
247 vaddr = address & TARGET_PAGE_MASK;
248 paddr &= TARGET_PAGE_MASK;
250 printf("Translate at " TARGET_FMT_lx " -> " TARGET_FMT_plx ", vaddr "
251 TARGET_FMT_lx "\n", address, paddr, vaddr);
253 ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
257 if (env->mmuregs[3]) /* Fault status register */
258 env->mmuregs[3] = 1; /* overflow (not read before another fault) */
259 env->mmuregs[3] |= (access_index << 5) | error_code | 2;
260 env->mmuregs[4] = address; /* Fault address register */
262 if ((env->mmuregs[0] & MMU_NF) || env->psret == 0) {
263 // No fault mode: if a mapping is available, just override
264 // permissions. If no mapping is available, redirect accesses to
265 // neverland. Fake/overridden mappings will be flushed when
266 // switching to normal mode.
267 vaddr = address & TARGET_PAGE_MASK;
268 prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
269 ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
273 env->exception_index = TT_TFAULT;
275 env->exception_index = TT_DFAULT;
280 target_ulong mmu_probe(CPUState *env, target_ulong address, int mmulev)
282 target_phys_addr_t pde_ptr;
285 /* Context base + context number */
286 pde_ptr = (target_phys_addr_t)(env->mmuregs[1] << 4) +
287 (env->mmuregs[2] << 2);
288 pde = ldl_phys(pde_ptr);
290 switch (pde & PTE_ENTRYTYPE_MASK) {
292 case 0: /* Invalid */
293 case 2: /* PTE, maybe should not happen? */
294 case 3: /* Reserved */
299 pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4);
300 pde = ldl_phys(pde_ptr);
302 switch (pde & PTE_ENTRYTYPE_MASK) {
304 case 0: /* Invalid */
305 case 3: /* Reserved */
312 pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4);
313 pde = ldl_phys(pde_ptr);
315 switch (pde & PTE_ENTRYTYPE_MASK) {
317 case 0: /* Invalid */
318 case 3: /* Reserved */
325 pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4);
326 pde = ldl_phys(pde_ptr);
328 switch (pde & PTE_ENTRYTYPE_MASK) {
330 case 0: /* Invalid */
331 case 1: /* PDE, should not happen */
332 case 3: /* Reserved */
344 void dump_mmu(CPUState *env)
346 target_ulong va, va1, va2;
347 unsigned int n, m, o;
348 target_phys_addr_t pde_ptr, pa;
351 printf("MMU dump:\n");
352 pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2);
353 pde = ldl_phys(pde_ptr);
354 printf("Root ptr: " TARGET_FMT_plx ", ctx: %d\n",
355 (target_phys_addr_t)env->mmuregs[1] << 4, env->mmuregs[2]);
356 for (n = 0, va = 0; n < 256; n++, va += 16 * 1024 * 1024) {
357 pde = mmu_probe(env, va, 2);
359 pa = cpu_get_phys_page_debug(env, va);
360 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx
361 " PDE: " TARGET_FMT_lx "\n", va, pa, pde);
362 for (m = 0, va1 = va; m < 64; m++, va1 += 256 * 1024) {
363 pde = mmu_probe(env, va1, 1);
365 pa = cpu_get_phys_page_debug(env, va1);
366 printf(" VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx
367 " PDE: " TARGET_FMT_lx "\n", va1, pa, pde);
368 for (o = 0, va2 = va1; o < 64; o++, va2 += 4 * 1024) {
369 pde = mmu_probe(env, va2, 0);
371 pa = cpu_get_phys_page_debug(env, va2);
372 printf(" VA: " TARGET_FMT_lx ", PA: "
373 TARGET_FMT_plx " PTE: " TARGET_FMT_lx "\n",
381 printf("MMU dump ends\n");
383 #endif /* DEBUG_MMU */
385 #else /* !TARGET_SPARC64 */
387 * UltraSparc IIi I/DMMUs
389 static int get_physical_address_data(CPUState *env, target_phys_addr_t *physical, int *prot,
390 int *access_index, target_ulong address, int rw,
396 if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */
398 *prot = PAGE_READ | PAGE_WRITE;
402 for (i = 0; i < 64; i++) {
403 switch ((env->dtlb_tte[i] >> 61) & 3) {
406 mask = 0xffffffffffffe000ULL;
409 mask = 0xffffffffffff0000ULL;
412 mask = 0xfffffffffff80000ULL;
415 mask = 0xffffffffffc00000ULL;
418 // ctx match, vaddr match?
419 if (env->dmmuregs[1] == (env->dtlb_tag[i] & 0x1fff) &&
420 (address & mask) == (env->dtlb_tag[i] & ~0x1fffULL)) {
422 if ((env->dtlb_tte[i] & 0x8000000000000000ULL) == 0 ||
423 ((env->dtlb_tte[i] & 0x4) && is_user) ||
424 (!(env->dtlb_tte[i] & 0x2) && (rw == 1))) {
425 if (env->dmmuregs[3]) /* Fault status register */
426 env->dmmuregs[3] = 2; /* overflow (not read before another fault) */
427 env->dmmuregs[3] |= (is_user << 3) | ((rw == 1) << 2) | 1;
428 env->dmmuregs[4] = address; /* Fault address register */
429 env->exception_index = TT_DFAULT;
431 printf("DFAULT at 0x%" PRIx64 "\n", address);
435 *physical = (env->dtlb_tte[i] & mask & 0x1fffffff000ULL) + (address & ~mask & 0x1fffffff000ULL);
437 if (env->dtlb_tte[i] & 0x2)
443 printf("DMISS at 0x%" PRIx64 "\n", address);
445 env->exception_index = TT_DMISS;
449 static int get_physical_address_code(CPUState *env, target_phys_addr_t *physical, int *prot,
450 int *access_index, target_ulong address, int rw,
456 if ((env->lsu & IMMU_E) == 0) { /* IMMU disabled */
462 for (i = 0; i < 64; i++) {
463 switch ((env->itlb_tte[i] >> 61) & 3) {
466 mask = 0xffffffffffffe000ULL;
469 mask = 0xffffffffffff0000ULL;
472 mask = 0xfffffffffff80000ULL;
475 mask = 0xffffffffffc00000ULL;
478 // ctx match, vaddr match?
479 if (env->dmmuregs[1] == (env->itlb_tag[i] & 0x1fff) &&
480 (address & mask) == (env->itlb_tag[i] & ~0x1fffULL)) {
482 if ((env->itlb_tte[i] & 0x8000000000000000ULL) == 0 ||
483 ((env->itlb_tte[i] & 0x4) && is_user)) {
484 if (env->immuregs[3]) /* Fault status register */
485 env->immuregs[3] = 2; /* overflow (not read before another fault) */
486 env->immuregs[3] |= (is_user << 3) | 1;
487 env->exception_index = TT_TFAULT;
489 printf("TFAULT at 0x%" PRIx64 "\n", address);
493 *physical = (env->itlb_tte[i] & mask & 0x1fffffff000ULL) + (address & ~mask & 0x1fffffff000ULL);
499 printf("TMISS at 0x%" PRIx64 "\n", address);
501 env->exception_index = TT_TMISS;
505 static int get_physical_address(CPUState *env, target_phys_addr_t *physical,
506 int *prot, int *access_index,
507 target_ulong address, int rw, int mmu_idx)
509 int is_user = mmu_idx == MMU_USER_IDX;
512 return get_physical_address_code(env, physical, prot, access_index, address, rw, is_user);
514 return get_physical_address_data(env, physical, prot, access_index, address, rw, is_user);
517 /* Perform address translation */
518 int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
519 int mmu_idx, int is_softmmu)
521 target_ulong virt_addr, vaddr;
522 target_phys_addr_t paddr;
523 int error_code = 0, prot, ret = 0, access_index;
525 error_code = get_physical_address(env, &paddr, &prot, &access_index, address, rw, mmu_idx);
526 if (error_code == 0) {
527 virt_addr = address & TARGET_PAGE_MASK;
528 vaddr = virt_addr + ((address & TARGET_PAGE_MASK) & (TARGET_PAGE_SIZE - 1));
530 printf("Translate at 0x%" PRIx64 " -> 0x%" PRIx64 ", vaddr 0x%" PRIx64 "\n", address, paddr, vaddr);
532 ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
540 void dump_mmu(CPUState *env)
545 printf("MMU contexts: Primary: %" PRId64 ", Secondary: %" PRId64 "\n", env->dmmuregs[1], env->dmmuregs[2]);
546 if ((env->lsu & DMMU_E) == 0) {
547 printf("DMMU disabled\n");
549 printf("DMMU dump:\n");
550 for (i = 0; i < 64; i++) {
551 switch ((env->dtlb_tte[i] >> 61) & 3) {
566 if ((env->dtlb_tte[i] & 0x8000000000000000ULL) != 0) {
567 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx ", %s, %s, %s, %s, ctx %" PRId64 "\n",
568 env->dtlb_tag[i] & ~0x1fffULL,
569 env->dtlb_tte[i] & 0x1ffffffe000ULL,
571 env->dtlb_tte[i] & 0x4? "priv": "user",
572 env->dtlb_tte[i] & 0x2? "RW": "RO",
573 env->dtlb_tte[i] & 0x40? "locked": "unlocked",
574 env->dtlb_tag[i] & 0x1fffULL);
578 if ((env->lsu & IMMU_E) == 0) {
579 printf("IMMU disabled\n");
581 printf("IMMU dump:\n");
582 for (i = 0; i < 64; i++) {
583 switch ((env->itlb_tte[i] >> 61) & 3) {
598 if ((env->itlb_tte[i] & 0x8000000000000000ULL) != 0) {
599 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx ", %s, %s, %s, ctx %" PRId64 "\n",
600 env->itlb_tag[i] & ~0x1fffULL,
601 env->itlb_tte[i] & 0x1ffffffe000ULL,
603 env->itlb_tte[i] & 0x4? "priv": "user",
604 env->itlb_tte[i] & 0x40? "locked": "unlocked",
605 env->itlb_tag[i] & 0x1fffULL);
610 #endif /* DEBUG_MMU */
612 #endif /* TARGET_SPARC64 */
613 #endif /* !CONFIG_USER_ONLY */
616 #if defined(CONFIG_USER_ONLY)
617 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
623 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
625 target_phys_addr_t phys_addr;
626 int prot, access_index;
628 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2,
629 MMU_KERNEL_IDX) != 0)
630 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr,
631 0, MMU_KERNEL_IDX) != 0)
633 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED)
639 void memcpy32(target_ulong *dst, const target_ulong *src)
651 void helper_flush(target_ulong addr)
654 tb_invalidate_page_range(addr, addr + 8);
657 void cpu_reset(CPUSPARCState *env)
662 env->regwptr = env->regbase + (env->cwp * 16);
663 #if defined(CONFIG_USER_ONLY)
664 env->user_mode_only = 1;
665 #ifdef TARGET_SPARC64
666 env->cleanwin = NWINDOWS - 2;
667 env->cansave = NWINDOWS - 2;
668 env->pstate = PS_RMO | PS_PEF | PS_IE;
669 env->asi = 0x82; // Primary no-fault
675 #ifdef TARGET_SPARC64
676 env->pstate = PS_PRIV;
677 env->hpstate = HS_PRIV;
678 env->pc = 0x1fff0000000ULL;
679 env->tsptr = &env->ts[env->tl];
682 env->mmuregs[0] &= ~(MMU_E | MMU_NF);
683 env->mmuregs[0] |= env->mmu_bm;
685 env->npc = env->pc + 4;
689 static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model)
691 sparc_def_t def1, *def = &def1;
693 if (cpu_sparc_find_by_name(def, cpu_model) < 0)
696 env->features = def->features;
697 env->cpu_model_str = cpu_model;
698 env->version = def->iu_version;
699 env->fsr = def->fpu_version;
700 #if !defined(TARGET_SPARC64)
701 env->mmu_bm = def->mmu_bm;
702 env->mmu_ctpr_mask = def->mmu_ctpr_mask;
703 env->mmu_cxr_mask = def->mmu_cxr_mask;
704 env->mmu_sfsr_mask = def->mmu_sfsr_mask;
705 env->mmu_trcr_mask = def->mmu_trcr_mask;
706 env->mmuregs[0] |= def->mmu_version;
707 cpu_sparc_set_id(env, 0);
712 static void cpu_sparc_close(CPUSPARCState *env)
717 CPUSPARCState *cpu_sparc_init(const char *cpu_model)
721 env = qemu_mallocz(sizeof(CPUSPARCState));
726 gen_intermediate_code_init(env);
728 if (cpu_sparc_register(env, cpu_model) < 0) {
729 cpu_sparc_close(env);
737 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
739 #if !defined(TARGET_SPARC64)
740 env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
744 static const sparc_def_t sparc_defs[] = {
745 #ifdef TARGET_SPARC64
747 .name = "Fujitsu Sparc64",
748 .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)
749 | (MAXTL << 8) | (NWINDOWS - 1)),
750 .fpu_version = 0x00000000,
752 .features = CPU_DEFAULT_FEATURES,
755 .name = "Fujitsu Sparc64 III",
756 .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)
757 | (MAXTL << 8) | (NWINDOWS - 1)),
758 .fpu_version = 0x00000000,
760 .features = CPU_DEFAULT_FEATURES,
763 .name = "Fujitsu Sparc64 IV",
764 .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)
765 | (MAXTL << 8) | (NWINDOWS - 1)),
766 .fpu_version = 0x00000000,
768 .features = CPU_DEFAULT_FEATURES,
771 .name = "Fujitsu Sparc64 V",
772 .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)
773 | (MAXTL << 8) | (NWINDOWS - 1)),
774 .fpu_version = 0x00000000,
776 .features = CPU_DEFAULT_FEATURES,
779 .name = "TI UltraSparc I",
780 .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
781 | (MAXTL << 8) | (NWINDOWS - 1)),
782 .fpu_version = 0x00000000,
784 .features = CPU_DEFAULT_FEATURES,
787 .name = "TI UltraSparc II",
788 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)
789 | (MAXTL << 8) | (NWINDOWS - 1)),
790 .fpu_version = 0x00000000,
792 .features = CPU_DEFAULT_FEATURES,
795 .name = "TI UltraSparc IIi",
796 .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)
797 | (MAXTL << 8) | (NWINDOWS - 1)),
798 .fpu_version = 0x00000000,
800 .features = CPU_DEFAULT_FEATURES,
803 .name = "TI UltraSparc IIe",
804 .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)
805 | (MAXTL << 8) | (NWINDOWS - 1)),
806 .fpu_version = 0x00000000,
808 .features = CPU_DEFAULT_FEATURES,
811 .name = "Sun UltraSparc III",
812 .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)
813 | (MAXTL << 8) | (NWINDOWS - 1)),
814 .fpu_version = 0x00000000,
816 .features = CPU_DEFAULT_FEATURES,
819 .name = "Sun UltraSparc III Cu",
820 .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)
821 | (MAXTL << 8) | (NWINDOWS - 1)),
822 .fpu_version = 0x00000000,
824 .features = CPU_DEFAULT_FEATURES,
827 .name = "Sun UltraSparc IIIi",
828 .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)
829 | (MAXTL << 8) | (NWINDOWS - 1)),
830 .fpu_version = 0x00000000,
832 .features = CPU_DEFAULT_FEATURES,
835 .name = "Sun UltraSparc IV",
836 .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)
837 | (MAXTL << 8) | (NWINDOWS - 1)),
838 .fpu_version = 0x00000000,
840 .features = CPU_DEFAULT_FEATURES,
843 .name = "Sun UltraSparc IV+",
844 .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)
845 | (MAXTL << 8) | (NWINDOWS - 1)),
846 .fpu_version = 0x00000000,
848 .features = CPU_DEFAULT_FEATURES,
851 .name = "Sun UltraSparc IIIi+",
852 .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)
853 | (MAXTL << 8) | (NWINDOWS - 1)),
854 .fpu_version = 0x00000000,
856 .features = CPU_DEFAULT_FEATURES,
859 .name = "NEC UltraSparc I",
860 .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
861 | (MAXTL << 8) | (NWINDOWS - 1)),
862 .fpu_version = 0x00000000,
864 .features = CPU_DEFAULT_FEATURES,
868 .name = "Fujitsu MB86900",
869 .iu_version = 0x00 << 24, /* Impl 0, ver 0 */
870 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
871 .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */
872 .mmu_bm = 0x00004000,
873 .mmu_ctpr_mask = 0x007ffff0,
874 .mmu_cxr_mask = 0x0000003f,
875 .mmu_sfsr_mask = 0xffffffff,
876 .mmu_trcr_mask = 0xffffffff,
877 .features = CPU_FEATURE_FLOAT,
880 .name = "Fujitsu MB86904",
881 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
882 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
883 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
884 .mmu_bm = 0x00004000,
885 .mmu_ctpr_mask = 0x00ffffc0,
886 .mmu_cxr_mask = 0x000000ff,
887 .mmu_sfsr_mask = 0x00016fff,
888 .mmu_trcr_mask = 0x00ffffff,
889 .features = CPU_DEFAULT_FEATURES,
892 .name = "Fujitsu MB86907",
893 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
894 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
895 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
896 .mmu_bm = 0x00004000,
897 .mmu_ctpr_mask = 0xffffffc0,
898 .mmu_cxr_mask = 0x000000ff,
899 .mmu_sfsr_mask = 0x00016fff,
900 .mmu_trcr_mask = 0xffffffff,
901 .features = CPU_DEFAULT_FEATURES,
904 .name = "LSI L64811",
905 .iu_version = 0x10 << 24, /* Impl 1, ver 0 */
906 .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */
907 .mmu_version = 0x10 << 24,
908 .mmu_bm = 0x00004000,
909 .mmu_ctpr_mask = 0x007ffff0,
910 .mmu_cxr_mask = 0x0000003f,
911 .mmu_sfsr_mask = 0xffffffff,
912 .mmu_trcr_mask = 0xffffffff,
913 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT,
916 .name = "Cypress CY7C601",
917 .iu_version = 0x11 << 24, /* Impl 1, ver 1 */
918 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
919 .mmu_version = 0x10 << 24,
920 .mmu_bm = 0x00004000,
921 .mmu_ctpr_mask = 0x007ffff0,
922 .mmu_cxr_mask = 0x0000003f,
923 .mmu_sfsr_mask = 0xffffffff,
924 .mmu_trcr_mask = 0xffffffff,
925 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT,
928 .name = "Cypress CY7C611",
929 .iu_version = 0x13 << 24, /* Impl 1, ver 3 */
930 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
931 .mmu_version = 0x10 << 24,
932 .mmu_bm = 0x00004000,
933 .mmu_ctpr_mask = 0x007ffff0,
934 .mmu_cxr_mask = 0x0000003f,
935 .mmu_sfsr_mask = 0xffffffff,
936 .mmu_trcr_mask = 0xffffffff,
937 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT,
940 .name = "TI SuperSparc II",
941 .iu_version = 0x40000000,
942 .fpu_version = 0 << 17,
943 .mmu_version = 0x04000000,
944 .mmu_bm = 0x00002000,
945 .mmu_ctpr_mask = 0xffffffc0,
946 .mmu_cxr_mask = 0x0000ffff,
947 .mmu_sfsr_mask = 0xffffffff,
948 .mmu_trcr_mask = 0xffffffff,
949 .features = CPU_DEFAULT_FEATURES,
952 .name = "TI MicroSparc I",
953 .iu_version = 0x41000000,
954 .fpu_version = 4 << 17,
955 .mmu_version = 0x41000000,
956 .mmu_bm = 0x00004000,
957 .mmu_ctpr_mask = 0x007ffff0,
958 .mmu_cxr_mask = 0x0000003f,
959 .mmu_sfsr_mask = 0x00016fff,
960 .mmu_trcr_mask = 0x0000003f,
961 .features = CPU_DEFAULT_FEATURES,
964 .name = "TI MicroSparc II",
965 .iu_version = 0x42000000,
966 .fpu_version = 4 << 17,
967 .mmu_version = 0x02000000,
968 .mmu_bm = 0x00004000,
969 .mmu_ctpr_mask = 0x00ffffc0,
970 .mmu_cxr_mask = 0x000000ff,
971 .mmu_sfsr_mask = 0x00016fff,
972 .mmu_trcr_mask = 0x00ffffff,
973 .features = CPU_DEFAULT_FEATURES,
976 .name = "TI MicroSparc IIep",
977 .iu_version = 0x42000000,
978 .fpu_version = 4 << 17,
979 .mmu_version = 0x04000000,
980 .mmu_bm = 0x00004000,
981 .mmu_ctpr_mask = 0x00ffffc0,
982 .mmu_cxr_mask = 0x000000ff,
983 .mmu_sfsr_mask = 0x00016bff,
984 .mmu_trcr_mask = 0x00ffffff,
985 .features = CPU_DEFAULT_FEATURES,
988 .name = "TI SuperSparc 51",
989 .iu_version = 0x43000000,
990 .fpu_version = 0 << 17,
991 .mmu_version = 0x04000000,
992 .mmu_bm = 0x00002000,
993 .mmu_ctpr_mask = 0xffffffc0,
994 .mmu_cxr_mask = 0x0000ffff,
995 .mmu_sfsr_mask = 0xffffffff,
996 .mmu_trcr_mask = 0xffffffff,
997 .features = CPU_DEFAULT_FEATURES,
1000 .name = "TI SuperSparc 61",
1001 .iu_version = 0x44000000,
1002 .fpu_version = 0 << 17,
1003 .mmu_version = 0x04000000,
1004 .mmu_bm = 0x00002000,
1005 .mmu_ctpr_mask = 0xffffffc0,
1006 .mmu_cxr_mask = 0x0000ffff,
1007 .mmu_sfsr_mask = 0xffffffff,
1008 .mmu_trcr_mask = 0xffffffff,
1009 .features = CPU_DEFAULT_FEATURES,
1012 .name = "Ross RT625",
1013 .iu_version = 0x1e000000,
1014 .fpu_version = 1 << 17,
1015 .mmu_version = 0x1e000000,
1016 .mmu_bm = 0x00004000,
1017 .mmu_ctpr_mask = 0x007ffff0,
1018 .mmu_cxr_mask = 0x0000003f,
1019 .mmu_sfsr_mask = 0xffffffff,
1020 .mmu_trcr_mask = 0xffffffff,
1021 .features = CPU_DEFAULT_FEATURES,
1024 .name = "Ross RT620",
1025 .iu_version = 0x1f000000,
1026 .fpu_version = 1 << 17,
1027 .mmu_version = 0x1f000000,
1028 .mmu_bm = 0x00004000,
1029 .mmu_ctpr_mask = 0x007ffff0,
1030 .mmu_cxr_mask = 0x0000003f,
1031 .mmu_sfsr_mask = 0xffffffff,
1032 .mmu_trcr_mask = 0xffffffff,
1033 .features = CPU_DEFAULT_FEATURES,
1036 .name = "BIT B5010",
1037 .iu_version = 0x20000000,
1038 .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */
1039 .mmu_version = 0x20000000,
1040 .mmu_bm = 0x00004000,
1041 .mmu_ctpr_mask = 0x007ffff0,
1042 .mmu_cxr_mask = 0x0000003f,
1043 .mmu_sfsr_mask = 0xffffffff,
1044 .mmu_trcr_mask = 0xffffffff,
1045 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT,
1048 .name = "Matsushita MN10501",
1049 .iu_version = 0x50000000,
1050 .fpu_version = 0 << 17,
1051 .mmu_version = 0x50000000,
1052 .mmu_bm = 0x00004000,
1053 .mmu_ctpr_mask = 0x007ffff0,
1054 .mmu_cxr_mask = 0x0000003f,
1055 .mmu_sfsr_mask = 0xffffffff,
1056 .mmu_trcr_mask = 0xffffffff,
1057 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_MUL | CPU_FEATURE_FSQRT,
1060 .name = "Weitek W8601",
1061 .iu_version = 0x90 << 24, /* Impl 9, ver 0 */
1062 .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
1063 .mmu_version = 0x10 << 24,
1064 .mmu_bm = 0x00004000,
1065 .mmu_ctpr_mask = 0x007ffff0,
1066 .mmu_cxr_mask = 0x0000003f,
1067 .mmu_sfsr_mask = 0xffffffff,
1068 .mmu_trcr_mask = 0xffffffff,
1069 .features = CPU_DEFAULT_FEATURES,
1073 .iu_version = 0xf2000000,
1074 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
1075 .mmu_version = 0xf2000000,
1076 .mmu_bm = 0x00004000,
1077 .mmu_ctpr_mask = 0x007ffff0,
1078 .mmu_cxr_mask = 0x0000003f,
1079 .mmu_sfsr_mask = 0xffffffff,
1080 .mmu_trcr_mask = 0xffffffff,
1081 .features = CPU_DEFAULT_FEATURES,
1085 .iu_version = 0xf3000000,
1086 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
1087 .mmu_version = 0xf3000000,
1088 .mmu_bm = 0x00004000,
1089 .mmu_ctpr_mask = 0x007ffff0,
1090 .mmu_cxr_mask = 0x0000003f,
1091 .mmu_sfsr_mask = 0xffffffff,
1092 .mmu_trcr_mask = 0xffffffff,
1093 .features = CPU_DEFAULT_FEATURES,
1098 static const char * const feature_name[] = {
1111 static void print_features(FILE *f,
1112 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
1113 uint32_t features, const char *prefix)
1117 for (i = 0; i < ARRAY_SIZE(feature_name); i++)
1118 if (feature_name[i] && (features & (1 << i))) {
1120 (*cpu_fprintf)(f, "%s", prefix);
1121 (*cpu_fprintf)(f, "%s ", feature_name[i]);
1125 static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features)
1129 for (i = 0; i < ARRAY_SIZE(feature_name); i++)
1130 if (feature_name[i] && !strcmp(flagname, feature_name[i])) {
1131 *features |= 1 << i;
1134 fprintf(stderr, "CPU feature %s not found\n", flagname);
1137 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const unsigned char *cpu_model)
1140 const sparc_def_t *def = NULL;
1141 char *s = strdup(cpu_model);
1142 char *featurestr, *name = strtok(s, ",");
1143 uint32_t plus_features = 0;
1144 uint32_t minus_features = 0;
1145 long long iu_version;
1146 uint32_t fpu_version, mmu_version;
1148 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
1149 if (strcasecmp(name, sparc_defs[i].name) == 0) {
1150 def = &sparc_defs[i];
1155 memcpy(cpu_def, def, sizeof(*def));
1157 featurestr = strtok(NULL, ",");
1158 while (featurestr) {
1161 if (featurestr[0] == '+') {
1162 add_flagname_to_bitmaps(featurestr + 1, &plus_features);
1163 } else if (featurestr[0] == '-') {
1164 add_flagname_to_bitmaps(featurestr + 1, &minus_features);
1165 } else if ((val = strchr(featurestr, '='))) {
1167 if (!strcmp(featurestr, "iu_version")) {
1170 iu_version = strtoll(val, &err, 0);
1171 if (!*val || *err) {
1172 fprintf(stderr, "bad numerical value %s\n", val);
1175 cpu_def->iu_version = iu_version;
1176 #ifdef DEBUG_FEATURES
1177 fprintf(stderr, "iu_version %llx\n", iu_version);
1179 } else if (!strcmp(featurestr, "fpu_version")) {
1182 fpu_version = strtol(val, &err, 0);
1183 if (!*val || *err) {
1184 fprintf(stderr, "bad numerical value %s\n", val);
1187 cpu_def->fpu_version = fpu_version;
1188 #ifdef DEBUG_FEATURES
1189 fprintf(stderr, "fpu_version %llx\n", fpu_version);
1191 } else if (!strcmp(featurestr, "mmu_version")) {
1194 mmu_version = strtol(val, &err, 0);
1195 if (!*val || *err) {
1196 fprintf(stderr, "bad numerical value %s\n", val);
1199 cpu_def->mmu_version = mmu_version;
1200 #ifdef DEBUG_FEATURES
1201 fprintf(stderr, "mmu_version %llx\n", mmu_version);
1204 fprintf(stderr, "unrecognized feature %s\n", featurestr);
1208 fprintf(stderr, "feature string `%s' not in format (+feature|-feature|feature=xyz)\n", featurestr);
1211 featurestr = strtok(NULL, ",");
1213 cpu_def->features |= plus_features;
1214 cpu_def->features &= ~minus_features;
1215 #ifdef DEBUG_FEATURES
1216 print_features(stderr, fprintf, cpu_def->features, NULL);
1226 void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
1230 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
1231 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x ",
1233 sparc_defs[i].iu_version,
1234 sparc_defs[i].fpu_version,
1235 sparc_defs[i].mmu_version);
1236 print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES & ~sparc_defs[i].features, "-");
1237 print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES & sparc_defs[i].features, "+");
1238 (*cpu_fprintf)(f, "\n");
1240 (*cpu_fprintf)(f, "CPU feature flags (+/-): ");
1241 print_features(f, cpu_fprintf, -1, NULL);
1242 (*cpu_fprintf)(f, "\n");
1243 (*cpu_fprintf)(f, "Numerical features (=): iu_version fpu_version mmu_version\n");
1246 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
1248 void cpu_dump_state(CPUState *env, FILE *f,
1249 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
1254 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, env->npc);
1255 cpu_fprintf(f, "General Registers:\n");
1256 for (i = 0; i < 4; i++)
1257 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
1258 cpu_fprintf(f, "\n");
1260 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
1261 cpu_fprintf(f, "\nCurrent Register Window:\n");
1262 for (x = 0; x < 3; x++) {
1263 for (i = 0; i < 4; i++)
1264 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
1265 (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i,
1266 env->regwptr[i + x * 8]);
1267 cpu_fprintf(f, "\n");
1269 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
1270 (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i,
1271 env->regwptr[i + x * 8]);
1272 cpu_fprintf(f, "\n");
1274 cpu_fprintf(f, "\nFloating Point Registers:\n");
1275 for (i = 0; i < 32; i++) {
1277 cpu_fprintf(f, "%%f%02d:", i);
1278 cpu_fprintf(f, " %016lf", env->fpr[i]);
1280 cpu_fprintf(f, "\n");
1282 #ifdef TARGET_SPARC64
1283 cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
1284 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs);
1285 cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
1286 env->cansave, env->canrestore, env->otherwin, env->wstate,
1287 env->cleanwin, NWINDOWS - 1 - env->cwp);
1289 cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env),
1290 GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'),
1291 GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'),
1292 env->psrs?'S':'-', env->psrps?'P':'-',
1293 env->psret?'E':'-', env->wim);
1295 cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env));
1298 #ifdef TARGET_SPARC64
1299 #if !defined(CONFIG_USER_ONLY)
1300 #include "qemu-common.h"
1302 #include "qemu-timer.h"
1305 void helper_tick_set_count(void *opaque, uint64_t count)
1307 #if !defined(CONFIG_USER_ONLY)
1308 ptimer_set_count(opaque, -count);
1312 uint64_t helper_tick_get_count(void *opaque)
1314 #if !defined(CONFIG_USER_ONLY)
1315 return -ptimer_get_count(opaque);
1321 void helper_tick_set_limit(void *opaque, uint64_t limit)
1323 #if !defined(CONFIG_USER_ONLY)
1324 ptimer_set_limit(opaque, -limit, 0);