xref: /qemu/target/sparc/helper.c (revision ca10f86763f58b7b3667e2ca7d26db3dc810eb20)
1e8af50a3Sbellard /*
2e8af50a3Sbellard  *  sparc helpers
3e8af50a3Sbellard  *
483469015Sbellard  *  Copyright (c) 2003-2005 Fabrice Bellard
5e8af50a3Sbellard  *
6e8af50a3Sbellard  * This library is free software; you can redistribute it and/or
7e8af50a3Sbellard  * modify it under the terms of the GNU Lesser General Public
8e8af50a3Sbellard  * License as published by the Free Software Foundation; either
9e8af50a3Sbellard  * version 2 of the License, or (at your option) any later version.
10e8af50a3Sbellard  *
11e8af50a3Sbellard  * This library is distributed in the hope that it will be useful,
12e8af50a3Sbellard  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13e8af50a3Sbellard  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14e8af50a3Sbellard  * Lesser General Public License for more details.
15e8af50a3Sbellard  *
16e8af50a3Sbellard  * You should have received a copy of the GNU Lesser General Public
17e8af50a3Sbellard  * License along with this library; if not, write to the Free Software
18e8af50a3Sbellard  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19e8af50a3Sbellard  */
20ee5bbe38Sbellard #include <stdarg.h>
21ee5bbe38Sbellard #include <stdlib.h>
22ee5bbe38Sbellard #include <stdio.h>
23ee5bbe38Sbellard #include <string.h>
24ee5bbe38Sbellard #include <inttypes.h>
25ee5bbe38Sbellard #include <signal.h>
26ee5bbe38Sbellard #include <assert.h>
27ee5bbe38Sbellard 
28ee5bbe38Sbellard #include "cpu.h"
29ee5bbe38Sbellard #include "exec-all.h"
30ca10f867Saurel32 #include "qemu-common.h"
31e8af50a3Sbellard 
32e80cfcfcSbellard //#define DEBUG_MMU
33e8af50a3Sbellard 
34c48fcb47Sblueswir1 typedef struct sparc_def_t sparc_def_t;
35c48fcb47Sblueswir1 
36c48fcb47Sblueswir1 struct sparc_def_t {
37c48fcb47Sblueswir1     const unsigned char *name;
38c48fcb47Sblueswir1     target_ulong iu_version;
39c48fcb47Sblueswir1     uint32_t fpu_version;
40c48fcb47Sblueswir1     uint32_t mmu_version;
41c48fcb47Sblueswir1     uint32_t mmu_bm;
42c48fcb47Sblueswir1     uint32_t mmu_ctpr_mask;
43c48fcb47Sblueswir1     uint32_t mmu_cxr_mask;
44c48fcb47Sblueswir1     uint32_t mmu_sfsr_mask;
45c48fcb47Sblueswir1     uint32_t mmu_trcr_mask;
46c48fcb47Sblueswir1 };
47c48fcb47Sblueswir1 
48c48fcb47Sblueswir1 static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name);
49c48fcb47Sblueswir1 
50e8af50a3Sbellard /* Sparc MMU emulation */
51e8af50a3Sbellard 
52e8af50a3Sbellard /* thread support */
53e8af50a3Sbellard 
54e8af50a3Sbellard spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
55e8af50a3Sbellard 
56e8af50a3Sbellard void cpu_lock(void)
57e8af50a3Sbellard {
58e8af50a3Sbellard     spin_lock(&global_cpu_lock);
59e8af50a3Sbellard }
60e8af50a3Sbellard 
61e8af50a3Sbellard void cpu_unlock(void)
62e8af50a3Sbellard {
63e8af50a3Sbellard     spin_unlock(&global_cpu_lock);
64e8af50a3Sbellard }
65e8af50a3Sbellard 
669d893301Sbellard #if defined(CONFIG_USER_ONLY)
679d893301Sbellard 
689d893301Sbellard int cpu_sparc_handle_mmu_fault(CPUState *env, target_ulong address, int rw,
696ebbf390Sj_mayer                                int mmu_idx, int is_softmmu)
709d893301Sbellard {
71878d3096Sbellard     if (rw & 2)
72878d3096Sbellard         env->exception_index = TT_TFAULT;
73878d3096Sbellard     else
74878d3096Sbellard         env->exception_index = TT_DFAULT;
759d893301Sbellard     return 1;
769d893301Sbellard }
779d893301Sbellard 
789d893301Sbellard #else
79e8af50a3Sbellard 
803475187dSbellard #ifndef TARGET_SPARC64
8183469015Sbellard /*
8283469015Sbellard  * Sparc V8 Reference MMU (SRMMU)
8383469015Sbellard  */
84e8af50a3Sbellard static const int access_table[8][8] = {
85e8af50a3Sbellard     { 0, 0, 0, 0, 2, 0, 3, 3 },
86e8af50a3Sbellard     { 0, 0, 0, 0, 2, 0, 0, 0 },
87e8af50a3Sbellard     { 2, 2, 0, 0, 0, 2, 3, 3 },
88e8af50a3Sbellard     { 2, 2, 0, 0, 0, 2, 0, 0 },
89e8af50a3Sbellard     { 2, 0, 2, 0, 2, 2, 3, 3 },
90e8af50a3Sbellard     { 2, 0, 2, 0, 2, 0, 2, 0 },
91e8af50a3Sbellard     { 2, 2, 2, 0, 2, 2, 3, 3 },
92e8af50a3Sbellard     { 2, 2, 2, 0, 2, 2, 2, 0 }
93e8af50a3Sbellard };
94e8af50a3Sbellard 
95227671c9Sbellard static const int perm_table[2][8] = {
96227671c9Sbellard     {
97227671c9Sbellard         PAGE_READ,
98227671c9Sbellard         PAGE_READ | PAGE_WRITE,
99227671c9Sbellard         PAGE_READ | PAGE_EXEC,
100227671c9Sbellard         PAGE_READ | PAGE_WRITE | PAGE_EXEC,
101227671c9Sbellard         PAGE_EXEC,
102227671c9Sbellard         PAGE_READ | PAGE_WRITE,
103227671c9Sbellard         PAGE_READ | PAGE_EXEC,
104227671c9Sbellard         PAGE_READ | PAGE_WRITE | PAGE_EXEC
105227671c9Sbellard     },
106227671c9Sbellard     {
107227671c9Sbellard         PAGE_READ,
108227671c9Sbellard         PAGE_READ | PAGE_WRITE,
109227671c9Sbellard         PAGE_READ | PAGE_EXEC,
110227671c9Sbellard         PAGE_READ | PAGE_WRITE | PAGE_EXEC,
111227671c9Sbellard         PAGE_EXEC,
112227671c9Sbellard         PAGE_READ,
113227671c9Sbellard         0,
114227671c9Sbellard         0,
115227671c9Sbellard     }
116e8af50a3Sbellard };
117e8af50a3Sbellard 
118c48fcb47Sblueswir1 static int get_physical_address(CPUState *env, target_phys_addr_t *physical,
119c48fcb47Sblueswir1                                 int *prot, int *access_index,
120c48fcb47Sblueswir1                                 target_ulong address, int rw, int mmu_idx)
121e8af50a3Sbellard {
122e80cfcfcSbellard     int access_perms = 0;
123e80cfcfcSbellard     target_phys_addr_t pde_ptr;
124af7bf89bSbellard     uint32_t pde;
125af7bf89bSbellard     target_ulong virt_addr;
1266ebbf390Sj_mayer     int error_code = 0, is_dirty, is_user;
127e80cfcfcSbellard     unsigned long page_offset;
128e8af50a3Sbellard 
1296ebbf390Sj_mayer     is_user = mmu_idx == MMU_USER_IDX;
130e8af50a3Sbellard     virt_addr = address & TARGET_PAGE_MASK;
13140ce0a9aSblueswir1 
132e8af50a3Sbellard     if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
13340ce0a9aSblueswir1         // Boot mode: instruction fetches are taken from PROM
1346d5f237aSblueswir1         if (rw == 2 && (env->mmuregs[0] & env->mmu_bm)) {
13558a770f3Sblueswir1             *physical = env->prom_addr | (address & 0x7ffffULL);
13640ce0a9aSblueswir1             *prot = PAGE_READ | PAGE_EXEC;
13740ce0a9aSblueswir1             return 0;
13840ce0a9aSblueswir1         }
139e80cfcfcSbellard         *physical = address;
140227671c9Sbellard         *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
141e80cfcfcSbellard         return 0;
142e8af50a3Sbellard     }
143e8af50a3Sbellard 
1447483750dSbellard     *access_index = ((rw & 1) << 2) | (rw & 2) | (is_user? 0 : 1);
1455dcb6b91Sblueswir1     *physical = 0xffffffffffff0000ULL;
1467483750dSbellard 
147e8af50a3Sbellard     /* SPARC reference MMU table walk: Context table->L1->L2->PTE */
148e8af50a3Sbellard     /* Context base + context number */
1493deaeab7Sblueswir1     pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2);
15049be8030Sbellard     pde = ldl_phys(pde_ptr);
151e8af50a3Sbellard 
152e8af50a3Sbellard     /* Ctx pde */
153e8af50a3Sbellard     switch (pde & PTE_ENTRYTYPE_MASK) {
154e80cfcfcSbellard     default:
155e8af50a3Sbellard     case 0: /* Invalid */
1567483750dSbellard         return 1 << 2;
157e80cfcfcSbellard     case 2: /* L0 PTE, maybe should not happen? */
158e8af50a3Sbellard     case 3: /* Reserved */
1597483750dSbellard         return 4 << 2;
160e80cfcfcSbellard     case 1: /* L0 PDE */
161e80cfcfcSbellard         pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4);
16249be8030Sbellard         pde = ldl_phys(pde_ptr);
163e80cfcfcSbellard 
164e80cfcfcSbellard         switch (pde & PTE_ENTRYTYPE_MASK) {
165e80cfcfcSbellard         default:
166e80cfcfcSbellard         case 0: /* Invalid */
1677483750dSbellard             return (1 << 8) | (1 << 2);
168e80cfcfcSbellard         case 3: /* Reserved */
1697483750dSbellard             return (1 << 8) | (4 << 2);
170e8af50a3Sbellard         case 1: /* L1 PDE */
171e80cfcfcSbellard             pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4);
17249be8030Sbellard             pde = ldl_phys(pde_ptr);
173e8af50a3Sbellard 
174e8af50a3Sbellard             switch (pde & PTE_ENTRYTYPE_MASK) {
175e80cfcfcSbellard             default:
176e8af50a3Sbellard             case 0: /* Invalid */
1777483750dSbellard                 return (2 << 8) | (1 << 2);
178e8af50a3Sbellard             case 3: /* Reserved */
1797483750dSbellard                 return (2 << 8) | (4 << 2);
180e8af50a3Sbellard             case 1: /* L2 PDE */
181e80cfcfcSbellard                 pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4);
18249be8030Sbellard                 pde = ldl_phys(pde_ptr);
183e8af50a3Sbellard 
184e8af50a3Sbellard                 switch (pde & PTE_ENTRYTYPE_MASK) {
185e80cfcfcSbellard                 default:
186e8af50a3Sbellard                 case 0: /* Invalid */
1877483750dSbellard                     return (3 << 8) | (1 << 2);
188e8af50a3Sbellard                 case 1: /* PDE, should not happen */
189e8af50a3Sbellard                 case 3: /* Reserved */
1907483750dSbellard                     return (3 << 8) | (4 << 2);
191e8af50a3Sbellard                 case 2: /* L3 PTE */
192e8af50a3Sbellard                     virt_addr = address & TARGET_PAGE_MASK;
193e8af50a3Sbellard                     page_offset = (address & TARGET_PAGE_MASK) & (TARGET_PAGE_SIZE - 1);
194e8af50a3Sbellard                 }
195e8af50a3Sbellard                 break;
196e8af50a3Sbellard             case 2: /* L2 PTE */
197e8af50a3Sbellard                 virt_addr = address & ~0x3ffff;
198e8af50a3Sbellard                 page_offset = address & 0x3ffff;
199e8af50a3Sbellard             }
200e8af50a3Sbellard             break;
201e8af50a3Sbellard         case 2: /* L1 PTE */
202e8af50a3Sbellard             virt_addr = address & ~0xffffff;
203e8af50a3Sbellard             page_offset = address & 0xffffff;
204e8af50a3Sbellard         }
205e8af50a3Sbellard     }
206e8af50a3Sbellard 
207e8af50a3Sbellard     /* update page modified and dirty bits */
208b769d8feSbellard     is_dirty = (rw & 1) && !(pde & PG_MODIFIED_MASK);
209e8af50a3Sbellard     if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
210e8af50a3Sbellard         pde |= PG_ACCESSED_MASK;
211e8af50a3Sbellard         if (is_dirty)
212e8af50a3Sbellard             pde |= PG_MODIFIED_MASK;
21349be8030Sbellard         stl_phys_notdirty(pde_ptr, pde);
214e8af50a3Sbellard     }
215e8af50a3Sbellard     /* check access */
216e8af50a3Sbellard     access_perms = (pde & PTE_ACCESS_MASK) >> PTE_ACCESS_SHIFT;
217e80cfcfcSbellard     error_code = access_table[*access_index][access_perms];
218d8e3326cSbellard     if (error_code && !((env->mmuregs[0] & MMU_NF) && is_user))
219e80cfcfcSbellard         return error_code;
220e8af50a3Sbellard 
221e8af50a3Sbellard     /* the page can be put in the TLB */
222227671c9Sbellard     *prot = perm_table[is_user][access_perms];
223227671c9Sbellard     if (!(pde & PG_MODIFIED_MASK)) {
224e8af50a3Sbellard         /* only set write access if already dirty... otherwise wait
225e8af50a3Sbellard            for dirty access */
226227671c9Sbellard         *prot &= ~PAGE_WRITE;
227e8af50a3Sbellard     }
228e8af50a3Sbellard 
229e8af50a3Sbellard     /* Even if large ptes, we map only one 4KB page in the cache to
230e8af50a3Sbellard        avoid filling it too fast */
2315dcb6b91Sblueswir1     *physical = ((target_phys_addr_t)(pde & PTE_ADDR_MASK) << 4) + page_offset;
2326f7e9aecSbellard     return error_code;
233e80cfcfcSbellard }
234e80cfcfcSbellard 
235e80cfcfcSbellard /* Perform address translation */
236af7bf89bSbellard int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
2376ebbf390Sj_mayer                               int mmu_idx, int is_softmmu)
238e80cfcfcSbellard {
239af7bf89bSbellard     target_phys_addr_t paddr;
2405dcb6b91Sblueswir1     target_ulong vaddr;
241e80cfcfcSbellard     int error_code = 0, prot, ret = 0, access_index;
242e80cfcfcSbellard 
2436ebbf390Sj_mayer     error_code = get_physical_address(env, &paddr, &prot, &access_index, address, rw, mmu_idx);
244e80cfcfcSbellard     if (error_code == 0) {
2459e61bde5Sbellard         vaddr = address & TARGET_PAGE_MASK;
2469e61bde5Sbellard         paddr &= TARGET_PAGE_MASK;
2479e61bde5Sbellard #ifdef DEBUG_MMU
2485dcb6b91Sblueswir1         printf("Translate at " TARGET_FMT_lx " -> " TARGET_FMT_plx ", vaddr "
2495dcb6b91Sblueswir1                TARGET_FMT_lx "\n", address, paddr, vaddr);
2509e61bde5Sbellard #endif
2516ebbf390Sj_mayer         ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
252e8af50a3Sbellard         return ret;
253e80cfcfcSbellard     }
254e8af50a3Sbellard 
255e8af50a3Sbellard     if (env->mmuregs[3]) /* Fault status register */
256e8af50a3Sbellard         env->mmuregs[3] = 1; /* overflow (not read before another fault) */
2577483750dSbellard     env->mmuregs[3] |= (access_index << 5) | error_code | 2;
258e8af50a3Sbellard     env->mmuregs[4] = address; /* Fault address register */
259e8af50a3Sbellard 
260878d3096Sbellard     if ((env->mmuregs[0] & MMU_NF) || env->psret == 0)  {
2616f7e9aecSbellard         // No fault mode: if a mapping is available, just override
2626f7e9aecSbellard         // permissions. If no mapping is available, redirect accesses to
2636f7e9aecSbellard         // neverland. Fake/overridden mappings will be flushed when
2646f7e9aecSbellard         // switching to normal mode.
2657483750dSbellard         vaddr = address & TARGET_PAGE_MASK;
266227671c9Sbellard         prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
2676ebbf390Sj_mayer         ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
2687483750dSbellard         return ret;
2697483750dSbellard     } else {
270878d3096Sbellard         if (rw & 2)
271878d3096Sbellard             env->exception_index = TT_TFAULT;
272878d3096Sbellard         else
273878d3096Sbellard             env->exception_index = TT_DFAULT;
274878d3096Sbellard         return 1;
275e8af50a3Sbellard     }
2767483750dSbellard }
27724741ef3Sbellard 
27824741ef3Sbellard target_ulong mmu_probe(CPUState *env, target_ulong address, int mmulev)
27924741ef3Sbellard {
28024741ef3Sbellard     target_phys_addr_t pde_ptr;
28124741ef3Sbellard     uint32_t pde;
28224741ef3Sbellard 
28324741ef3Sbellard     /* Context base + context number */
2845dcb6b91Sblueswir1     pde_ptr = (target_phys_addr_t)(env->mmuregs[1] << 4) +
2855dcb6b91Sblueswir1         (env->mmuregs[2] << 2);
28624741ef3Sbellard     pde = ldl_phys(pde_ptr);
28724741ef3Sbellard 
28824741ef3Sbellard     switch (pde & PTE_ENTRYTYPE_MASK) {
28924741ef3Sbellard     default:
29024741ef3Sbellard     case 0: /* Invalid */
29124741ef3Sbellard     case 2: /* PTE, maybe should not happen? */
29224741ef3Sbellard     case 3: /* Reserved */
29324741ef3Sbellard         return 0;
29424741ef3Sbellard     case 1: /* L1 PDE */
29524741ef3Sbellard         if (mmulev == 3)
29624741ef3Sbellard             return pde;
29724741ef3Sbellard         pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4);
29824741ef3Sbellard         pde = ldl_phys(pde_ptr);
29924741ef3Sbellard 
30024741ef3Sbellard         switch (pde & PTE_ENTRYTYPE_MASK) {
30124741ef3Sbellard         default:
30224741ef3Sbellard         case 0: /* Invalid */
30324741ef3Sbellard         case 3: /* Reserved */
30424741ef3Sbellard             return 0;
30524741ef3Sbellard         case 2: /* L1 PTE */
30624741ef3Sbellard             return pde;
30724741ef3Sbellard         case 1: /* L2 PDE */
30824741ef3Sbellard             if (mmulev == 2)
30924741ef3Sbellard                 return pde;
31024741ef3Sbellard             pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4);
31124741ef3Sbellard             pde = ldl_phys(pde_ptr);
31224741ef3Sbellard 
31324741ef3Sbellard             switch (pde & PTE_ENTRYTYPE_MASK) {
31424741ef3Sbellard             default:
31524741ef3Sbellard             case 0: /* Invalid */
31624741ef3Sbellard             case 3: /* Reserved */
31724741ef3Sbellard                 return 0;
31824741ef3Sbellard             case 2: /* L2 PTE */
31924741ef3Sbellard                 return pde;
32024741ef3Sbellard             case 1: /* L3 PDE */
32124741ef3Sbellard                 if (mmulev == 1)
32224741ef3Sbellard                     return pde;
32324741ef3Sbellard                 pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4);
32424741ef3Sbellard                 pde = ldl_phys(pde_ptr);
32524741ef3Sbellard 
32624741ef3Sbellard                 switch (pde & PTE_ENTRYTYPE_MASK) {
32724741ef3Sbellard                 default:
32824741ef3Sbellard                 case 0: /* Invalid */
32924741ef3Sbellard                 case 1: /* PDE, should not happen */
33024741ef3Sbellard                 case 3: /* Reserved */
33124741ef3Sbellard                     return 0;
33224741ef3Sbellard                 case 2: /* L3 PTE */
33324741ef3Sbellard                     return pde;
33424741ef3Sbellard                 }
33524741ef3Sbellard             }
33624741ef3Sbellard         }
33724741ef3Sbellard     }
33824741ef3Sbellard     return 0;
33924741ef3Sbellard }
34024741ef3Sbellard 
34124741ef3Sbellard #ifdef DEBUG_MMU
34224741ef3Sbellard void dump_mmu(CPUState *env)
34324741ef3Sbellard {
34424741ef3Sbellard     target_ulong va, va1, va2;
34524741ef3Sbellard     unsigned int n, m, o;
34624741ef3Sbellard     target_phys_addr_t pde_ptr, pa;
34724741ef3Sbellard     uint32_t pde;
34824741ef3Sbellard 
34924741ef3Sbellard     printf("MMU dump:\n");
35024741ef3Sbellard     pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2);
35124741ef3Sbellard     pde = ldl_phys(pde_ptr);
3525dcb6b91Sblueswir1     printf("Root ptr: " TARGET_FMT_plx ", ctx: %d\n",
3535dcb6b91Sblueswir1            (target_phys_addr_t)env->mmuregs[1] << 4, env->mmuregs[2]);
35424741ef3Sbellard     for (n = 0, va = 0; n < 256; n++, va += 16 * 1024 * 1024) {
3555dcb6b91Sblueswir1         pde = mmu_probe(env, va, 2);
3565dcb6b91Sblueswir1         if (pde) {
35724741ef3Sbellard             pa = cpu_get_phys_page_debug(env, va);
3585dcb6b91Sblueswir1             printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx
3595dcb6b91Sblueswir1                    " PDE: " TARGET_FMT_lx "\n", va, pa, pde);
36024741ef3Sbellard             for (m = 0, va1 = va; m < 64; m++, va1 += 256 * 1024) {
3615dcb6b91Sblueswir1                 pde = mmu_probe(env, va1, 1);
3625dcb6b91Sblueswir1                 if (pde) {
36324741ef3Sbellard                     pa = cpu_get_phys_page_debug(env, va1);
3645dcb6b91Sblueswir1                     printf(" VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx
3655dcb6b91Sblueswir1                            " PDE: " TARGET_FMT_lx "\n", va1, pa, pde);
36624741ef3Sbellard                     for (o = 0, va2 = va1; o < 64; o++, va2 += 4 * 1024) {
3675dcb6b91Sblueswir1                         pde = mmu_probe(env, va2, 0);
3685dcb6b91Sblueswir1                         if (pde) {
36924741ef3Sbellard                             pa = cpu_get_phys_page_debug(env, va2);
3705dcb6b91Sblueswir1                             printf("  VA: " TARGET_FMT_lx ", PA: "
3715dcb6b91Sblueswir1                                    TARGET_FMT_plx " PTE: " TARGET_FMT_lx "\n",
3725dcb6b91Sblueswir1                                    va2, pa, pde);
37324741ef3Sbellard                         }
37424741ef3Sbellard                     }
37524741ef3Sbellard                 }
37624741ef3Sbellard             }
37724741ef3Sbellard         }
37824741ef3Sbellard     }
37924741ef3Sbellard     printf("MMU dump ends\n");
38024741ef3Sbellard }
38124741ef3Sbellard #endif /* DEBUG_MMU */
38224741ef3Sbellard 
38324741ef3Sbellard #else /* !TARGET_SPARC64 */
38483469015Sbellard /*
38583469015Sbellard  * UltraSparc IIi I/DMMUs
38683469015Sbellard  */
3873475187dSbellard static int get_physical_address_data(CPUState *env, target_phys_addr_t *physical, int *prot,
3883475187dSbellard                           int *access_index, target_ulong address, int rw,
3893475187dSbellard                           int is_user)
3903475187dSbellard {
3913475187dSbellard     target_ulong mask;
3923475187dSbellard     unsigned int i;
3933475187dSbellard 
3943475187dSbellard     if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */
39583469015Sbellard         *physical = address;
3963475187dSbellard         *prot = PAGE_READ | PAGE_WRITE;
3973475187dSbellard         return 0;
3983475187dSbellard     }
3993475187dSbellard 
4003475187dSbellard     for (i = 0; i < 64; i++) {
40183469015Sbellard         switch ((env->dtlb_tte[i] >> 61) & 3) {
4023475187dSbellard         default:
40383469015Sbellard         case 0x0: // 8k
4043475187dSbellard             mask = 0xffffffffffffe000ULL;
4053475187dSbellard             break;
40683469015Sbellard         case 0x1: // 64k
4073475187dSbellard             mask = 0xffffffffffff0000ULL;
4083475187dSbellard             break;
40983469015Sbellard         case 0x2: // 512k
4103475187dSbellard             mask = 0xfffffffffff80000ULL;
4113475187dSbellard             break;
41283469015Sbellard         case 0x3: // 4M
4133475187dSbellard             mask = 0xffffffffffc00000ULL;
4143475187dSbellard             break;
4153475187dSbellard         }
4163475187dSbellard         // ctx match, vaddr match?
4173475187dSbellard         if (env->dmmuregs[1] == (env->dtlb_tag[i] & 0x1fff) &&
4183475187dSbellard             (address & mask) == (env->dtlb_tag[i] & ~0x1fffULL)) {
41983469015Sbellard             // valid, access ok?
42083469015Sbellard             if ((env->dtlb_tte[i] & 0x8000000000000000ULL) == 0 ||
42183469015Sbellard                 ((env->dtlb_tte[i] & 0x4) && is_user) ||
4223475187dSbellard                 (!(env->dtlb_tte[i] & 0x2) && (rw == 1))) {
42383469015Sbellard                 if (env->dmmuregs[3]) /* Fault status register */
42483469015Sbellard                     env->dmmuregs[3] = 2; /* overflow (not read before another fault) */
42583469015Sbellard                 env->dmmuregs[3] |= (is_user << 3) | ((rw == 1) << 2) | 1;
42683469015Sbellard                 env->dmmuregs[4] = address; /* Fault address register */
4273475187dSbellard                 env->exception_index = TT_DFAULT;
42883469015Sbellard #ifdef DEBUG_MMU
42926a76461Sbellard                 printf("DFAULT at 0x%" PRIx64 "\n", address);
43083469015Sbellard #endif
4313475187dSbellard                 return 1;
4323475187dSbellard             }
43383469015Sbellard             *physical = (env->dtlb_tte[i] & mask & 0x1fffffff000ULL) + (address & ~mask & 0x1fffffff000ULL);
4343475187dSbellard             *prot = PAGE_READ;
4353475187dSbellard             if (env->dtlb_tte[i] & 0x2)
4363475187dSbellard                 *prot |= PAGE_WRITE;
4373475187dSbellard             return 0;
4383475187dSbellard         }
4393475187dSbellard     }
44083469015Sbellard #ifdef DEBUG_MMU
44126a76461Sbellard     printf("DMISS at 0x%" PRIx64 "\n", address);
44283469015Sbellard #endif
44383469015Sbellard     env->exception_index = TT_DMISS;
4443475187dSbellard     return 1;
4453475187dSbellard }
4463475187dSbellard 
4473475187dSbellard static int get_physical_address_code(CPUState *env, target_phys_addr_t *physical, int *prot,
4483475187dSbellard                           int *access_index, target_ulong address, int rw,
4493475187dSbellard                           int is_user)
4503475187dSbellard {
4513475187dSbellard     target_ulong mask;
4523475187dSbellard     unsigned int i;
4533475187dSbellard 
4543475187dSbellard     if ((env->lsu & IMMU_E) == 0) { /* IMMU disabled */
45583469015Sbellard         *physical = address;
456227671c9Sbellard         *prot = PAGE_EXEC;
4573475187dSbellard         return 0;
4583475187dSbellard     }
45983469015Sbellard 
4603475187dSbellard     for (i = 0; i < 64; i++) {
46183469015Sbellard         switch ((env->itlb_tte[i] >> 61) & 3) {
4623475187dSbellard         default:
46383469015Sbellard         case 0x0: // 8k
4643475187dSbellard             mask = 0xffffffffffffe000ULL;
4653475187dSbellard             break;
46683469015Sbellard         case 0x1: // 64k
4673475187dSbellard             mask = 0xffffffffffff0000ULL;
4683475187dSbellard             break;
46983469015Sbellard         case 0x2: // 512k
4703475187dSbellard             mask = 0xfffffffffff80000ULL;
4713475187dSbellard             break;
47283469015Sbellard         case 0x3: // 4M
4733475187dSbellard             mask = 0xffffffffffc00000ULL;
4743475187dSbellard                 break;
4753475187dSbellard         }
4763475187dSbellard         // ctx match, vaddr match?
47783469015Sbellard         if (env->dmmuregs[1] == (env->itlb_tag[i] & 0x1fff) &&
4783475187dSbellard             (address & mask) == (env->itlb_tag[i] & ~0x1fffULL)) {
47983469015Sbellard             // valid, access ok?
48083469015Sbellard             if ((env->itlb_tte[i] & 0x8000000000000000ULL) == 0 ||
48183469015Sbellard                 ((env->itlb_tte[i] & 0x4) && is_user)) {
48283469015Sbellard                 if (env->immuregs[3]) /* Fault status register */
48383469015Sbellard                     env->immuregs[3] = 2; /* overflow (not read before another fault) */
48483469015Sbellard                 env->immuregs[3] |= (is_user << 3) | 1;
4853475187dSbellard                 env->exception_index = TT_TFAULT;
48683469015Sbellard #ifdef DEBUG_MMU
48726a76461Sbellard                 printf("TFAULT at 0x%" PRIx64 "\n", address);
48883469015Sbellard #endif
4893475187dSbellard                 return 1;
4903475187dSbellard             }
49183469015Sbellard             *physical = (env->itlb_tte[i] & mask & 0x1fffffff000ULL) + (address & ~mask & 0x1fffffff000ULL);
492227671c9Sbellard             *prot = PAGE_EXEC;
4933475187dSbellard             return 0;
4943475187dSbellard         }
4953475187dSbellard     }
49683469015Sbellard #ifdef DEBUG_MMU
49726a76461Sbellard     printf("TMISS at 0x%" PRIx64 "\n", address);
49883469015Sbellard #endif
49983469015Sbellard     env->exception_index = TT_TMISS;
5003475187dSbellard     return 1;
5013475187dSbellard }
5023475187dSbellard 
503c48fcb47Sblueswir1 static int get_physical_address(CPUState *env, target_phys_addr_t *physical,
504c48fcb47Sblueswir1                                 int *prot, int *access_index,
505c48fcb47Sblueswir1                                 target_ulong address, int rw, int mmu_idx)
5063475187dSbellard {
5076ebbf390Sj_mayer     int is_user = mmu_idx == MMU_USER_IDX;
5086ebbf390Sj_mayer 
5093475187dSbellard     if (rw == 2)
5103475187dSbellard         return get_physical_address_code(env, physical, prot, access_index, address, rw, is_user);
5113475187dSbellard     else
5123475187dSbellard         return get_physical_address_data(env, physical, prot, access_index, address, rw, is_user);
5133475187dSbellard }
5143475187dSbellard 
5153475187dSbellard /* Perform address translation */
5163475187dSbellard int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
5176ebbf390Sj_mayer                               int mmu_idx, int is_softmmu)
5183475187dSbellard {
51983469015Sbellard     target_ulong virt_addr, vaddr;
5203475187dSbellard     target_phys_addr_t paddr;
5213475187dSbellard     int error_code = 0, prot, ret = 0, access_index;
5223475187dSbellard 
5236ebbf390Sj_mayer     error_code = get_physical_address(env, &paddr, &prot, &access_index, address, rw, mmu_idx);
5243475187dSbellard     if (error_code == 0) {
5253475187dSbellard         virt_addr = address & TARGET_PAGE_MASK;
5263475187dSbellard         vaddr = virt_addr + ((address & TARGET_PAGE_MASK) & (TARGET_PAGE_SIZE - 1));
52783469015Sbellard #ifdef DEBUG_MMU
52826a76461Sbellard         printf("Translate at 0x%" PRIx64 " -> 0x%" PRIx64 ", vaddr 0x%" PRIx64 "\n", address, paddr, vaddr);
52983469015Sbellard #endif
5306ebbf390Sj_mayer         ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
5313475187dSbellard         return ret;
5323475187dSbellard     }
5333475187dSbellard     // XXX
5343475187dSbellard     return 1;
5353475187dSbellard }
5363475187dSbellard 
53783469015Sbellard #ifdef DEBUG_MMU
53883469015Sbellard void dump_mmu(CPUState *env)
53983469015Sbellard {
54083469015Sbellard     unsigned int i;
54183469015Sbellard     const char *mask;
54283469015Sbellard 
54326a76461Sbellard     printf("MMU contexts: Primary: %" PRId64 ", Secondary: %" PRId64 "\n", env->dmmuregs[1], env->dmmuregs[2]);
54483469015Sbellard     if ((env->lsu & DMMU_E) == 0) {
54583469015Sbellard         printf("DMMU disabled\n");
54683469015Sbellard     } else {
54783469015Sbellard         printf("DMMU dump:\n");
54883469015Sbellard         for (i = 0; i < 64; i++) {
54983469015Sbellard             switch ((env->dtlb_tte[i] >> 61) & 3) {
55083469015Sbellard             default:
55183469015Sbellard             case 0x0:
55283469015Sbellard                 mask = "  8k";
55383469015Sbellard                 break;
55483469015Sbellard             case 0x1:
55583469015Sbellard                 mask = " 64k";
55683469015Sbellard                 break;
55783469015Sbellard             case 0x2:
55883469015Sbellard                 mask = "512k";
55983469015Sbellard                 break;
56083469015Sbellard             case 0x3:
56183469015Sbellard                 mask = "  4M";
56283469015Sbellard                 break;
56383469015Sbellard             }
56483469015Sbellard             if ((env->dtlb_tte[i] & 0x8000000000000000ULL) != 0) {
56526a76461Sbellard                 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx ", %s, %s, %s, %s, ctx %" PRId64 "\n",
56683469015Sbellard                        env->dtlb_tag[i] & ~0x1fffULL,
56783469015Sbellard                        env->dtlb_tte[i] & 0x1ffffffe000ULL,
56883469015Sbellard                        mask,
56983469015Sbellard                        env->dtlb_tte[i] & 0x4? "priv": "user",
57083469015Sbellard                        env->dtlb_tte[i] & 0x2? "RW": "RO",
57183469015Sbellard                        env->dtlb_tte[i] & 0x40? "locked": "unlocked",
57283469015Sbellard                        env->dtlb_tag[i] & 0x1fffULL);
57383469015Sbellard             }
57483469015Sbellard         }
57583469015Sbellard     }
57683469015Sbellard     if ((env->lsu & IMMU_E) == 0) {
57783469015Sbellard         printf("IMMU disabled\n");
57883469015Sbellard     } else {
57983469015Sbellard         printf("IMMU dump:\n");
58083469015Sbellard         for (i = 0; i < 64; i++) {
58183469015Sbellard             switch ((env->itlb_tte[i] >> 61) & 3) {
58283469015Sbellard             default:
58383469015Sbellard             case 0x0:
58483469015Sbellard                 mask = "  8k";
58583469015Sbellard                 break;
58683469015Sbellard             case 0x1:
58783469015Sbellard                 mask = " 64k";
58883469015Sbellard                 break;
58983469015Sbellard             case 0x2:
59083469015Sbellard                 mask = "512k";
59183469015Sbellard                 break;
59283469015Sbellard             case 0x3:
59383469015Sbellard                 mask = "  4M";
59483469015Sbellard                 break;
59583469015Sbellard             }
59683469015Sbellard             if ((env->itlb_tte[i] & 0x8000000000000000ULL) != 0) {
59726a76461Sbellard                 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx ", %s, %s, %s, ctx %" PRId64 "\n",
59883469015Sbellard                        env->itlb_tag[i] & ~0x1fffULL,
59983469015Sbellard                        env->itlb_tte[i] & 0x1ffffffe000ULL,
60083469015Sbellard                        mask,
60183469015Sbellard                        env->itlb_tte[i] & 0x4? "priv": "user",
60283469015Sbellard                        env->itlb_tte[i] & 0x40? "locked": "unlocked",
60383469015Sbellard                        env->itlb_tag[i] & 0x1fffULL);
60483469015Sbellard             }
60583469015Sbellard         }
60683469015Sbellard     }
60783469015Sbellard }
60824741ef3Sbellard #endif /* DEBUG_MMU */
60924741ef3Sbellard 
61024741ef3Sbellard #endif /* TARGET_SPARC64 */
61124741ef3Sbellard #endif /* !CONFIG_USER_ONLY */
61224741ef3Sbellard 
613c48fcb47Sblueswir1 
614c48fcb47Sblueswir1 #if defined(CONFIG_USER_ONLY)
615c48fcb47Sblueswir1 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
616c48fcb47Sblueswir1 {
617c48fcb47Sblueswir1     return addr;
618c48fcb47Sblueswir1 }
619c48fcb47Sblueswir1 
620c48fcb47Sblueswir1 #else
621c48fcb47Sblueswir1 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
622c48fcb47Sblueswir1 {
623c48fcb47Sblueswir1     target_phys_addr_t phys_addr;
624c48fcb47Sblueswir1     int prot, access_index;
625c48fcb47Sblueswir1 
626c48fcb47Sblueswir1     if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2,
627c48fcb47Sblueswir1                              MMU_KERNEL_IDX) != 0)
628c48fcb47Sblueswir1         if (get_physical_address(env, &phys_addr, &prot, &access_index, addr,
629c48fcb47Sblueswir1                                  0, MMU_KERNEL_IDX) != 0)
630c48fcb47Sblueswir1             return -1;
631c48fcb47Sblueswir1     if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED)
632c48fcb47Sblueswir1         return -1;
633c48fcb47Sblueswir1     return phys_addr;
634c48fcb47Sblueswir1 }
635c48fcb47Sblueswir1 #endif
636c48fcb47Sblueswir1 
63724741ef3Sbellard void memcpy32(target_ulong *dst, const target_ulong *src)
63824741ef3Sbellard {
63924741ef3Sbellard     dst[0] = src[0];
64024741ef3Sbellard     dst[1] = src[1];
64124741ef3Sbellard     dst[2] = src[2];
64224741ef3Sbellard     dst[3] = src[3];
64324741ef3Sbellard     dst[4] = src[4];
64424741ef3Sbellard     dst[5] = src[5];
64524741ef3Sbellard     dst[6] = src[6];
64624741ef3Sbellard     dst[7] = src[7];
64724741ef3Sbellard }
64887ecb68bSpbrook 
649c48fcb47Sblueswir1 void helper_flush(target_ulong addr)
650c48fcb47Sblueswir1 {
651c48fcb47Sblueswir1     addr &= ~7;
652c48fcb47Sblueswir1     tb_invalidate_page_range(addr, addr + 8);
653c48fcb47Sblueswir1 }
654c48fcb47Sblueswir1 
655c48fcb47Sblueswir1 void cpu_reset(CPUSPARCState *env)
656c48fcb47Sblueswir1 {
657c48fcb47Sblueswir1     tlb_flush(env, 1);
658c48fcb47Sblueswir1     env->cwp = 0;
659c48fcb47Sblueswir1     env->wim = 1;
660c48fcb47Sblueswir1     env->regwptr = env->regbase + (env->cwp * 16);
661c48fcb47Sblueswir1 #if defined(CONFIG_USER_ONLY)
662c48fcb47Sblueswir1     env->user_mode_only = 1;
663c48fcb47Sblueswir1 #ifdef TARGET_SPARC64
664c48fcb47Sblueswir1     env->cleanwin = NWINDOWS - 2;
665c48fcb47Sblueswir1     env->cansave = NWINDOWS - 2;
666c48fcb47Sblueswir1     env->pstate = PS_RMO | PS_PEF | PS_IE;
667c48fcb47Sblueswir1     env->asi = 0x82; // Primary no-fault
668c48fcb47Sblueswir1 #endif
669c48fcb47Sblueswir1 #else
670c48fcb47Sblueswir1     env->psret = 0;
671c48fcb47Sblueswir1     env->psrs = 1;
672c48fcb47Sblueswir1     env->psrps = 1;
673c48fcb47Sblueswir1 #ifdef TARGET_SPARC64
674c48fcb47Sblueswir1     env->pstate = PS_PRIV;
675c48fcb47Sblueswir1     env->hpstate = HS_PRIV;
676c48fcb47Sblueswir1     env->pc = 0x1fff0000000ULL;
677c48fcb47Sblueswir1     env->tsptr = &env->ts[env->tl];
678c48fcb47Sblueswir1 #else
679c48fcb47Sblueswir1     env->pc = 0;
680c48fcb47Sblueswir1     env->mmuregs[0] &= ~(MMU_E | MMU_NF);
681c48fcb47Sblueswir1     env->mmuregs[0] |= env->mmu_bm;
682c48fcb47Sblueswir1 #endif
683c48fcb47Sblueswir1     env->npc = env->pc + 4;
684c48fcb47Sblueswir1 #endif
685c48fcb47Sblueswir1 }
686c48fcb47Sblueswir1 
687c48fcb47Sblueswir1 CPUSPARCState *cpu_sparc_init(const char *cpu_model)
688c48fcb47Sblueswir1 {
689c48fcb47Sblueswir1     CPUSPARCState *env;
690c48fcb47Sblueswir1     const sparc_def_t *def;
691c48fcb47Sblueswir1 
692c48fcb47Sblueswir1     def = cpu_sparc_find_by_name(cpu_model);
693c48fcb47Sblueswir1     if (!def)
694c48fcb47Sblueswir1         return NULL;
695c48fcb47Sblueswir1 
696c48fcb47Sblueswir1     env = qemu_mallocz(sizeof(CPUSPARCState));
697c48fcb47Sblueswir1     if (!env)
698c48fcb47Sblueswir1         return NULL;
699c48fcb47Sblueswir1     cpu_exec_init(env);
700c48fcb47Sblueswir1     env->cpu_model_str = cpu_model;
701c48fcb47Sblueswir1     env->version = def->iu_version;
702c48fcb47Sblueswir1     env->fsr = def->fpu_version;
703c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64)
704c48fcb47Sblueswir1     env->mmu_bm = def->mmu_bm;
705c48fcb47Sblueswir1     env->mmu_ctpr_mask = def->mmu_ctpr_mask;
706c48fcb47Sblueswir1     env->mmu_cxr_mask = def->mmu_cxr_mask;
707c48fcb47Sblueswir1     env->mmu_sfsr_mask = def->mmu_sfsr_mask;
708c48fcb47Sblueswir1     env->mmu_trcr_mask = def->mmu_trcr_mask;
709c48fcb47Sblueswir1     env->mmuregs[0] |= def->mmu_version;
710c48fcb47Sblueswir1     cpu_sparc_set_id(env, 0);
711c48fcb47Sblueswir1 #endif
712c48fcb47Sblueswir1 
713c48fcb47Sblueswir1     gen_intermediate_code_init(env);
714c48fcb47Sblueswir1 
715c48fcb47Sblueswir1     cpu_reset(env);
716c48fcb47Sblueswir1 
717c48fcb47Sblueswir1     return env;
718c48fcb47Sblueswir1 }
719c48fcb47Sblueswir1 
720c48fcb47Sblueswir1 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
721c48fcb47Sblueswir1 {
722c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64)
723c48fcb47Sblueswir1     env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
724c48fcb47Sblueswir1 #endif
725c48fcb47Sblueswir1 }
726c48fcb47Sblueswir1 
727c48fcb47Sblueswir1 static const sparc_def_t sparc_defs[] = {
728c48fcb47Sblueswir1 #ifdef TARGET_SPARC64
729c48fcb47Sblueswir1     {
730c48fcb47Sblueswir1         .name = "Fujitsu Sparc64",
731c48fcb47Sblueswir1         .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)
732c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
733c48fcb47Sblueswir1         .fpu_version = 0x00000000,
734c48fcb47Sblueswir1         .mmu_version = 0,
735c48fcb47Sblueswir1     },
736c48fcb47Sblueswir1     {
737c48fcb47Sblueswir1         .name = "Fujitsu Sparc64 III",
738c48fcb47Sblueswir1         .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)
739c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
740c48fcb47Sblueswir1         .fpu_version = 0x00000000,
741c48fcb47Sblueswir1         .mmu_version = 0,
742c48fcb47Sblueswir1     },
743c48fcb47Sblueswir1     {
744c48fcb47Sblueswir1         .name = "Fujitsu Sparc64 IV",
745c48fcb47Sblueswir1         .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)
746c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
747c48fcb47Sblueswir1         .fpu_version = 0x00000000,
748c48fcb47Sblueswir1         .mmu_version = 0,
749c48fcb47Sblueswir1     },
750c48fcb47Sblueswir1     {
751c48fcb47Sblueswir1         .name = "Fujitsu Sparc64 V",
752c48fcb47Sblueswir1         .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)
753c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
754c48fcb47Sblueswir1         .fpu_version = 0x00000000,
755c48fcb47Sblueswir1         .mmu_version = 0,
756c48fcb47Sblueswir1     },
757c48fcb47Sblueswir1     {
758c48fcb47Sblueswir1         .name = "TI UltraSparc I",
759c48fcb47Sblueswir1         .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
760c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
761c48fcb47Sblueswir1         .fpu_version = 0x00000000,
762c48fcb47Sblueswir1         .mmu_version = 0,
763c48fcb47Sblueswir1     },
764c48fcb47Sblueswir1     {
765c48fcb47Sblueswir1         .name = "TI UltraSparc II",
766c48fcb47Sblueswir1         .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)
767c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
768c48fcb47Sblueswir1         .fpu_version = 0x00000000,
769c48fcb47Sblueswir1         .mmu_version = 0,
770c48fcb47Sblueswir1     },
771c48fcb47Sblueswir1     {
772c48fcb47Sblueswir1         .name = "TI UltraSparc IIi",
773c48fcb47Sblueswir1         .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)
774c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
775c48fcb47Sblueswir1         .fpu_version = 0x00000000,
776c48fcb47Sblueswir1         .mmu_version = 0,
777c48fcb47Sblueswir1     },
778c48fcb47Sblueswir1     {
779c48fcb47Sblueswir1         .name = "TI UltraSparc IIe",
780c48fcb47Sblueswir1         .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)
781c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
782c48fcb47Sblueswir1         .fpu_version = 0x00000000,
783c48fcb47Sblueswir1         .mmu_version = 0,
784c48fcb47Sblueswir1     },
785c48fcb47Sblueswir1     {
786c48fcb47Sblueswir1         .name = "Sun UltraSparc III",
787c48fcb47Sblueswir1         .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)
788c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
789c48fcb47Sblueswir1         .fpu_version = 0x00000000,
790c48fcb47Sblueswir1         .mmu_version = 0,
791c48fcb47Sblueswir1     },
792c48fcb47Sblueswir1     {
793c48fcb47Sblueswir1         .name = "Sun UltraSparc III Cu",
794c48fcb47Sblueswir1         .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)
795c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
796c48fcb47Sblueswir1         .fpu_version = 0x00000000,
797c48fcb47Sblueswir1         .mmu_version = 0,
798c48fcb47Sblueswir1     },
799c48fcb47Sblueswir1     {
800c48fcb47Sblueswir1         .name = "Sun UltraSparc IIIi",
801c48fcb47Sblueswir1         .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)
802c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
803c48fcb47Sblueswir1         .fpu_version = 0x00000000,
804c48fcb47Sblueswir1         .mmu_version = 0,
805c48fcb47Sblueswir1     },
806c48fcb47Sblueswir1     {
807c48fcb47Sblueswir1         .name = "Sun UltraSparc IV",
808c48fcb47Sblueswir1         .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)
809c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
810c48fcb47Sblueswir1         .fpu_version = 0x00000000,
811c48fcb47Sblueswir1         .mmu_version = 0,
812c48fcb47Sblueswir1     },
813c48fcb47Sblueswir1     {
814c48fcb47Sblueswir1         .name = "Sun UltraSparc IV+",
815c48fcb47Sblueswir1         .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)
816c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
817c48fcb47Sblueswir1         .fpu_version = 0x00000000,
818c48fcb47Sblueswir1         .mmu_version = 0,
819c48fcb47Sblueswir1     },
820c48fcb47Sblueswir1     {
821c48fcb47Sblueswir1         .name = "Sun UltraSparc IIIi+",
822c48fcb47Sblueswir1         .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)
823c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
824c48fcb47Sblueswir1         .fpu_version = 0x00000000,
825c48fcb47Sblueswir1         .mmu_version = 0,
826c48fcb47Sblueswir1     },
827c48fcb47Sblueswir1     {
828c48fcb47Sblueswir1         .name = "NEC UltraSparc I",
829c48fcb47Sblueswir1         .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)
830c48fcb47Sblueswir1                        | (MAXTL << 8) | (NWINDOWS - 1)),
831c48fcb47Sblueswir1         .fpu_version = 0x00000000,
832c48fcb47Sblueswir1         .mmu_version = 0,
833c48fcb47Sblueswir1     },
834c48fcb47Sblueswir1 #else
835c48fcb47Sblueswir1     {
836c48fcb47Sblueswir1         .name = "Fujitsu MB86900",
837c48fcb47Sblueswir1         .iu_version = 0x00 << 24, /* Impl 0, ver 0 */
838c48fcb47Sblueswir1         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
839c48fcb47Sblueswir1         .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */
840c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
841c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
842c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
843c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
844c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
845c48fcb47Sblueswir1     },
846c48fcb47Sblueswir1     {
847c48fcb47Sblueswir1         .name = "Fujitsu MB86904",
848c48fcb47Sblueswir1         .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
849c48fcb47Sblueswir1         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
850c48fcb47Sblueswir1         .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
851c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
852c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x00ffffc0,
853c48fcb47Sblueswir1         .mmu_cxr_mask = 0x000000ff,
854c48fcb47Sblueswir1         .mmu_sfsr_mask = 0x00016fff,
855c48fcb47Sblueswir1         .mmu_trcr_mask = 0x00ffffff,
856c48fcb47Sblueswir1     },
857c48fcb47Sblueswir1     {
858c48fcb47Sblueswir1         .name = "Fujitsu MB86907",
859c48fcb47Sblueswir1         .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
860c48fcb47Sblueswir1         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
861c48fcb47Sblueswir1         .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
862c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
863c48fcb47Sblueswir1         .mmu_ctpr_mask = 0xffffffc0,
864c48fcb47Sblueswir1         .mmu_cxr_mask = 0x000000ff,
865c48fcb47Sblueswir1         .mmu_sfsr_mask = 0x00016fff,
866c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
867c48fcb47Sblueswir1     },
868c48fcb47Sblueswir1     {
869c48fcb47Sblueswir1         .name = "LSI L64811",
870c48fcb47Sblueswir1         .iu_version = 0x10 << 24, /* Impl 1, ver 0 */
871c48fcb47Sblueswir1         .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */
872c48fcb47Sblueswir1         .mmu_version = 0x10 << 24,
873c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
874c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
875c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
876c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
877c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
878c48fcb47Sblueswir1     },
879c48fcb47Sblueswir1     {
880c48fcb47Sblueswir1         .name = "Cypress CY7C601",
881c48fcb47Sblueswir1         .iu_version = 0x11 << 24, /* Impl 1, ver 1 */
882c48fcb47Sblueswir1         .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
883c48fcb47Sblueswir1         .mmu_version = 0x10 << 24,
884c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
885c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
886c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
887c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
888c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
889c48fcb47Sblueswir1     },
890c48fcb47Sblueswir1     {
891c48fcb47Sblueswir1         .name = "Cypress CY7C611",
892c48fcb47Sblueswir1         .iu_version = 0x13 << 24, /* Impl 1, ver 3 */
893c48fcb47Sblueswir1         .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
894c48fcb47Sblueswir1         .mmu_version = 0x10 << 24,
895c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
896c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
897c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
898c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
899c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
900c48fcb47Sblueswir1     },
901c48fcb47Sblueswir1     {
902c48fcb47Sblueswir1         .name = "TI SuperSparc II",
903c48fcb47Sblueswir1         .iu_version = 0x40000000,
904c48fcb47Sblueswir1         .fpu_version = 0 << 17,
905c48fcb47Sblueswir1         .mmu_version = 0x04000000,
906c48fcb47Sblueswir1         .mmu_bm = 0x00002000,
907c48fcb47Sblueswir1         .mmu_ctpr_mask = 0xffffffc0,
908c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000ffff,
909c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
910c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
911c48fcb47Sblueswir1     },
912c48fcb47Sblueswir1     {
913c48fcb47Sblueswir1         .name = "TI MicroSparc I",
914c48fcb47Sblueswir1         .iu_version = 0x41000000,
915c48fcb47Sblueswir1         .fpu_version = 4 << 17,
916c48fcb47Sblueswir1         .mmu_version = 0x41000000,
917c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
918c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
919c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
920c48fcb47Sblueswir1         .mmu_sfsr_mask = 0x00016fff,
921c48fcb47Sblueswir1         .mmu_trcr_mask = 0x0000003f,
922c48fcb47Sblueswir1     },
923c48fcb47Sblueswir1     {
924c48fcb47Sblueswir1         .name = "TI MicroSparc II",
925c48fcb47Sblueswir1         .iu_version = 0x42000000,
926c48fcb47Sblueswir1         .fpu_version = 4 << 17,
927c48fcb47Sblueswir1         .mmu_version = 0x02000000,
928c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
929c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x00ffffc0,
930c48fcb47Sblueswir1         .mmu_cxr_mask = 0x000000ff,
931c48fcb47Sblueswir1         .mmu_sfsr_mask = 0x00016fff,
932c48fcb47Sblueswir1         .mmu_trcr_mask = 0x00ffffff,
933c48fcb47Sblueswir1     },
934c48fcb47Sblueswir1     {
935c48fcb47Sblueswir1         .name = "TI MicroSparc IIep",
936c48fcb47Sblueswir1         .iu_version = 0x42000000,
937c48fcb47Sblueswir1         .fpu_version = 4 << 17,
938c48fcb47Sblueswir1         .mmu_version = 0x04000000,
939c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
940c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x00ffffc0,
941c48fcb47Sblueswir1         .mmu_cxr_mask = 0x000000ff,
942c48fcb47Sblueswir1         .mmu_sfsr_mask = 0x00016bff,
943c48fcb47Sblueswir1         .mmu_trcr_mask = 0x00ffffff,
944c48fcb47Sblueswir1     },
945c48fcb47Sblueswir1     {
946c48fcb47Sblueswir1         .name = "TI SuperSparc 51",
947c48fcb47Sblueswir1         .iu_version = 0x43000000,
948c48fcb47Sblueswir1         .fpu_version = 0 << 17,
949c48fcb47Sblueswir1         .mmu_version = 0x04000000,
950c48fcb47Sblueswir1         .mmu_bm = 0x00002000,
951c48fcb47Sblueswir1         .mmu_ctpr_mask = 0xffffffc0,
952c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000ffff,
953c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
954c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
955c48fcb47Sblueswir1     },
956c48fcb47Sblueswir1     {
957c48fcb47Sblueswir1         .name = "TI SuperSparc 61",
958c48fcb47Sblueswir1         .iu_version = 0x44000000,
959c48fcb47Sblueswir1         .fpu_version = 0 << 17,
960c48fcb47Sblueswir1         .mmu_version = 0x04000000,
961c48fcb47Sblueswir1         .mmu_bm = 0x00002000,
962c48fcb47Sblueswir1         .mmu_ctpr_mask = 0xffffffc0,
963c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000ffff,
964c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
965c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
966c48fcb47Sblueswir1     },
967c48fcb47Sblueswir1     {
968c48fcb47Sblueswir1         .name = "Ross RT625",
969c48fcb47Sblueswir1         .iu_version = 0x1e000000,
970c48fcb47Sblueswir1         .fpu_version = 1 << 17,
971c48fcb47Sblueswir1         .mmu_version = 0x1e000000,
972c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
973c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
974c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
975c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
976c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
977c48fcb47Sblueswir1     },
978c48fcb47Sblueswir1     {
979c48fcb47Sblueswir1         .name = "Ross RT620",
980c48fcb47Sblueswir1         .iu_version = 0x1f000000,
981c48fcb47Sblueswir1         .fpu_version = 1 << 17,
982c48fcb47Sblueswir1         .mmu_version = 0x1f000000,
983c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
984c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
985c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
986c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
987c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
988c48fcb47Sblueswir1     },
989c48fcb47Sblueswir1     {
990c48fcb47Sblueswir1         .name = "BIT B5010",
991c48fcb47Sblueswir1         .iu_version = 0x20000000,
992c48fcb47Sblueswir1         .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */
993c48fcb47Sblueswir1         .mmu_version = 0x20000000,
994c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
995c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
996c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
997c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
998c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
999c48fcb47Sblueswir1     },
1000c48fcb47Sblueswir1     {
1001c48fcb47Sblueswir1         .name = "Matsushita MN10501",
1002c48fcb47Sblueswir1         .iu_version = 0x50000000,
1003c48fcb47Sblueswir1         .fpu_version = 0 << 17,
1004c48fcb47Sblueswir1         .mmu_version = 0x50000000,
1005c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
1006c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
1007c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
1008c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
1009c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
1010c48fcb47Sblueswir1     },
1011c48fcb47Sblueswir1     {
1012c48fcb47Sblueswir1         .name = "Weitek W8601",
1013c48fcb47Sblueswir1         .iu_version = 0x90 << 24, /* Impl 9, ver 0 */
1014c48fcb47Sblueswir1         .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
1015c48fcb47Sblueswir1         .mmu_version = 0x10 << 24,
1016c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
1017c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
1018c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
1019c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
1020c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
1021c48fcb47Sblueswir1     },
1022c48fcb47Sblueswir1     {
1023c48fcb47Sblueswir1         .name = "LEON2",
1024c48fcb47Sblueswir1         .iu_version = 0xf2000000,
1025c48fcb47Sblueswir1         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
1026c48fcb47Sblueswir1         .mmu_version = 0xf2000000,
1027c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
1028c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
1029c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
1030c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
1031c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
1032c48fcb47Sblueswir1     },
1033c48fcb47Sblueswir1     {
1034c48fcb47Sblueswir1         .name = "LEON3",
1035c48fcb47Sblueswir1         .iu_version = 0xf3000000,
1036c48fcb47Sblueswir1         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
1037c48fcb47Sblueswir1         .mmu_version = 0xf3000000,
1038c48fcb47Sblueswir1         .mmu_bm = 0x00004000,
1039c48fcb47Sblueswir1         .mmu_ctpr_mask = 0x007ffff0,
1040c48fcb47Sblueswir1         .mmu_cxr_mask = 0x0000003f,
1041c48fcb47Sblueswir1         .mmu_sfsr_mask = 0xffffffff,
1042c48fcb47Sblueswir1         .mmu_trcr_mask = 0xffffffff,
1043c48fcb47Sblueswir1     },
1044c48fcb47Sblueswir1 #endif
1045c48fcb47Sblueswir1 };
1046c48fcb47Sblueswir1 
1047c48fcb47Sblueswir1 static const sparc_def_t *cpu_sparc_find_by_name(const unsigned char *name)
1048c48fcb47Sblueswir1 {
1049c48fcb47Sblueswir1     unsigned int i;
1050c48fcb47Sblueswir1 
1051c48fcb47Sblueswir1     for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
1052c48fcb47Sblueswir1         if (strcasecmp(name, sparc_defs[i].name) == 0) {
1053c48fcb47Sblueswir1             return &sparc_defs[i];
1054c48fcb47Sblueswir1         }
1055c48fcb47Sblueswir1     }
1056c48fcb47Sblueswir1     return NULL;
1057c48fcb47Sblueswir1 }
1058c48fcb47Sblueswir1 
1059c48fcb47Sblueswir1 void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
1060c48fcb47Sblueswir1 {
1061c48fcb47Sblueswir1     unsigned int i;
1062c48fcb47Sblueswir1 
1063c48fcb47Sblueswir1     for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
1064c48fcb47Sblueswir1         (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x\n",
1065c48fcb47Sblueswir1                        sparc_defs[i].name,
1066c48fcb47Sblueswir1                        sparc_defs[i].iu_version,
1067c48fcb47Sblueswir1                        sparc_defs[i].fpu_version,
1068c48fcb47Sblueswir1                        sparc_defs[i].mmu_version);
1069c48fcb47Sblueswir1     }
1070c48fcb47Sblueswir1 }
1071c48fcb47Sblueswir1 
1072c48fcb47Sblueswir1 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
1073c48fcb47Sblueswir1 
1074c48fcb47Sblueswir1 void cpu_dump_state(CPUState *env, FILE *f,
1075c48fcb47Sblueswir1                     int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
1076c48fcb47Sblueswir1                     int flags)
1077c48fcb47Sblueswir1 {
1078c48fcb47Sblueswir1     int i, x;
1079c48fcb47Sblueswir1 
1080c48fcb47Sblueswir1     cpu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc, env->npc);
1081c48fcb47Sblueswir1     cpu_fprintf(f, "General Registers:\n");
1082c48fcb47Sblueswir1     for (i = 0; i < 4; i++)
1083c48fcb47Sblueswir1         cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
1084c48fcb47Sblueswir1     cpu_fprintf(f, "\n");
1085c48fcb47Sblueswir1     for (; i < 8; i++)
1086c48fcb47Sblueswir1         cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]);
1087c48fcb47Sblueswir1     cpu_fprintf(f, "\nCurrent Register Window:\n");
1088c48fcb47Sblueswir1     for (x = 0; x < 3; x++) {
1089c48fcb47Sblueswir1         for (i = 0; i < 4; i++)
1090c48fcb47Sblueswir1             cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
1091c48fcb47Sblueswir1                     (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i,
1092c48fcb47Sblueswir1                     env->regwptr[i + x * 8]);
1093c48fcb47Sblueswir1         cpu_fprintf(f, "\n");
1094c48fcb47Sblueswir1         for (; i < 8; i++)
1095c48fcb47Sblueswir1             cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t",
1096c48fcb47Sblueswir1                     (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i,
1097c48fcb47Sblueswir1                     env->regwptr[i + x * 8]);
1098c48fcb47Sblueswir1         cpu_fprintf(f, "\n");
1099c48fcb47Sblueswir1     }
1100c48fcb47Sblueswir1     cpu_fprintf(f, "\nFloating Point Registers:\n");
1101c48fcb47Sblueswir1     for (i = 0; i < 32; i++) {
1102c48fcb47Sblueswir1         if ((i & 3) == 0)
1103c48fcb47Sblueswir1             cpu_fprintf(f, "%%f%02d:", i);
1104c48fcb47Sblueswir1         cpu_fprintf(f, " %016lf", env->fpr[i]);
1105c48fcb47Sblueswir1         if ((i & 3) == 3)
1106c48fcb47Sblueswir1             cpu_fprintf(f, "\n");
1107c48fcb47Sblueswir1     }
1108c48fcb47Sblueswir1 #ifdef TARGET_SPARC64
1109c48fcb47Sblueswir1     cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
1110c48fcb47Sblueswir1                 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs);
1111c48fcb47Sblueswir1     cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
1112c48fcb47Sblueswir1                 env->cansave, env->canrestore, env->otherwin, env->wstate,
1113c48fcb47Sblueswir1                 env->cleanwin, NWINDOWS - 1 - env->cwp);
1114c48fcb47Sblueswir1 #else
1115c48fcb47Sblueswir1     cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env),
1116c48fcb47Sblueswir1             GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'),
1117c48fcb47Sblueswir1             GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'),
1118c48fcb47Sblueswir1             env->psrs?'S':'-', env->psrps?'P':'-',
1119c48fcb47Sblueswir1             env->psret?'E':'-', env->wim);
1120c48fcb47Sblueswir1 #endif
1121c48fcb47Sblueswir1     cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env));
1122c48fcb47Sblueswir1 }
1123c48fcb47Sblueswir1 
112487ecb68bSpbrook #ifdef TARGET_SPARC64
112587ecb68bSpbrook #if !defined(CONFIG_USER_ONLY)
112687ecb68bSpbrook #include "qemu-common.h"
112787ecb68bSpbrook #include "hw/irq.h"
112887ecb68bSpbrook #include "qemu-timer.h"
112987ecb68bSpbrook #endif
113087ecb68bSpbrook 
1131ccd4a219Sblueswir1 void helper_tick_set_count(void *opaque, uint64_t count)
113287ecb68bSpbrook {
113387ecb68bSpbrook #if !defined(CONFIG_USER_ONLY)
113487ecb68bSpbrook     ptimer_set_count(opaque, -count);
113587ecb68bSpbrook #endif
113687ecb68bSpbrook }
113787ecb68bSpbrook 
1138ccd4a219Sblueswir1 uint64_t helper_tick_get_count(void *opaque)
113987ecb68bSpbrook {
114087ecb68bSpbrook #if !defined(CONFIG_USER_ONLY)
114187ecb68bSpbrook     return -ptimer_get_count(opaque);
114287ecb68bSpbrook #else
114387ecb68bSpbrook     return 0;
114487ecb68bSpbrook #endif
114587ecb68bSpbrook }
114687ecb68bSpbrook 
1147ccd4a219Sblueswir1 void helper_tick_set_limit(void *opaque, uint64_t limit)
114887ecb68bSpbrook {
114987ecb68bSpbrook #if !defined(CONFIG_USER_ONLY)
115087ecb68bSpbrook     ptimer_set_limit(opaque, -limit, 0);
115187ecb68bSpbrook #endif
115287ecb68bSpbrook }
115387ecb68bSpbrook #endif
1154