Statistics
| Branch: | Revision:

root / target-sparc / helper.c @ 49a945a3

History | View | Annotate | Download (46.8 kB)

1 e8af50a3 bellard
/*
2 e8af50a3 bellard
 *  sparc helpers
3 5fafdf24 ths
 *
4 83469015 bellard
 *  Copyright (c) 2003-2005 Fabrice Bellard
5 e8af50a3 bellard
 *
6 e8af50a3 bellard
 * This library is free software; you can redistribute it and/or
7 e8af50a3 bellard
 * modify it under the terms of the GNU Lesser General Public
8 e8af50a3 bellard
 * License as published by the Free Software Foundation; either
9 e8af50a3 bellard
 * version 2 of the License, or (at your option) any later version.
10 e8af50a3 bellard
 *
11 e8af50a3 bellard
 * This library is distributed in the hope that it will be useful,
12 e8af50a3 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 e8af50a3 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 e8af50a3 bellard
 * Lesser General Public License for more details.
15 e8af50a3 bellard
 *
16 e8af50a3 bellard
 * You should have received a copy of the GNU Lesser General Public
17 8167ee88 Blue Swirl
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 e8af50a3 bellard
 */
19 ee5bbe38 bellard
#include <stdarg.h>
20 ee5bbe38 bellard
#include <stdlib.h>
21 ee5bbe38 bellard
#include <stdio.h>
22 ee5bbe38 bellard
#include <string.h>
23 ee5bbe38 bellard
#include <inttypes.h>
24 ee5bbe38 bellard
#include <signal.h>
25 ee5bbe38 bellard
26 ee5bbe38 bellard
#include "cpu.h"
27 ee5bbe38 bellard
#include "exec-all.h"
28 ca10f867 aurel32
#include "qemu-common.h"
29 e8af50a3 bellard
30 e80cfcfc bellard
//#define DEBUG_MMU
31 64a88d5d blueswir1
//#define DEBUG_FEATURES
32 e8af50a3 bellard
33 22548760 blueswir1
static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model);
34 c48fcb47 blueswir1
35 e8af50a3 bellard
/* Sparc MMU emulation */
36 e8af50a3 bellard
37 e8af50a3 bellard
/* thread support */
38 e8af50a3 bellard
39 c227f099 Anthony Liguori
static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
40 e8af50a3 bellard
41 e8af50a3 bellard
void cpu_lock(void)
42 e8af50a3 bellard
{
43 e8af50a3 bellard
    spin_lock(&global_cpu_lock);
44 e8af50a3 bellard
}
45 e8af50a3 bellard
46 e8af50a3 bellard
void cpu_unlock(void)
47 e8af50a3 bellard
{
48 e8af50a3 bellard
    spin_unlock(&global_cpu_lock);
49 e8af50a3 bellard
}
50 e8af50a3 bellard
51 5fafdf24 ths
#if defined(CONFIG_USER_ONLY)
52 9d893301 bellard
53 22548760 blueswir1
int cpu_sparc_handle_mmu_fault(CPUState *env1, target_ulong address, int rw,
54 6ebbf390 j_mayer
                               int mmu_idx, int is_softmmu)
55 9d893301 bellard
{
56 878d3096 bellard
    if (rw & 2)
57 22548760 blueswir1
        env1->exception_index = TT_TFAULT;
58 878d3096 bellard
    else
59 22548760 blueswir1
        env1->exception_index = TT_DFAULT;
60 9d893301 bellard
    return 1;
61 9d893301 bellard
}
62 9d893301 bellard
63 9d893301 bellard
#else
64 e8af50a3 bellard
65 3475187d bellard
#ifndef TARGET_SPARC64
66 83469015 bellard
/*
67 83469015 bellard
 * Sparc V8 Reference MMU (SRMMU)
68 83469015 bellard
 */
69 e8af50a3 bellard
static const int access_table[8][8] = {
70 a764a566 blueswir1
    { 0, 0, 0, 0, 8, 0, 12, 12 },
71 a764a566 blueswir1
    { 0, 0, 0, 0, 8, 0, 0, 0 },
72 a764a566 blueswir1
    { 8, 8, 0, 0, 0, 8, 12, 12 },
73 a764a566 blueswir1
    { 8, 8, 0, 0, 0, 8, 0, 0 },
74 a764a566 blueswir1
    { 8, 0, 8, 0, 8, 8, 12, 12 },
75 a764a566 blueswir1
    { 8, 0, 8, 0, 8, 0, 8, 0 },
76 a764a566 blueswir1
    { 8, 8, 8, 0, 8, 8, 12, 12 },
77 a764a566 blueswir1
    { 8, 8, 8, 0, 8, 8, 8, 0 }
78 e8af50a3 bellard
};
79 e8af50a3 bellard
80 227671c9 bellard
static const int perm_table[2][8] = {
81 227671c9 bellard
    {
82 227671c9 bellard
        PAGE_READ,
83 227671c9 bellard
        PAGE_READ | PAGE_WRITE,
84 227671c9 bellard
        PAGE_READ | PAGE_EXEC,
85 227671c9 bellard
        PAGE_READ | PAGE_WRITE | PAGE_EXEC,
86 227671c9 bellard
        PAGE_EXEC,
87 227671c9 bellard
        PAGE_READ | PAGE_WRITE,
88 227671c9 bellard
        PAGE_READ | PAGE_EXEC,
89 227671c9 bellard
        PAGE_READ | PAGE_WRITE | PAGE_EXEC
90 227671c9 bellard
    },
91 227671c9 bellard
    {
92 227671c9 bellard
        PAGE_READ,
93 227671c9 bellard
        PAGE_READ | PAGE_WRITE,
94 227671c9 bellard
        PAGE_READ | PAGE_EXEC,
95 227671c9 bellard
        PAGE_READ | PAGE_WRITE | PAGE_EXEC,
96 227671c9 bellard
        PAGE_EXEC,
97 227671c9 bellard
        PAGE_READ,
98 227671c9 bellard
        0,
99 227671c9 bellard
        0,
100 227671c9 bellard
    }
101 e8af50a3 bellard
};
102 e8af50a3 bellard
103 c227f099 Anthony Liguori
static int get_physical_address(CPUState *env, target_phys_addr_t *physical,
104 c48fcb47 blueswir1
                                int *prot, int *access_index,
105 c48fcb47 blueswir1
                                target_ulong address, int rw, int mmu_idx)
106 e8af50a3 bellard
{
107 e80cfcfc bellard
    int access_perms = 0;
108 c227f099 Anthony Liguori
    target_phys_addr_t pde_ptr;
109 af7bf89b bellard
    uint32_t pde;
110 6ebbf390 j_mayer
    int error_code = 0, is_dirty, is_user;
111 e80cfcfc bellard
    unsigned long page_offset;
112 e8af50a3 bellard
113 6ebbf390 j_mayer
    is_user = mmu_idx == MMU_USER_IDX;
114 40ce0a9a blueswir1
115 e8af50a3 bellard
    if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
116 40ce0a9a blueswir1
        // Boot mode: instruction fetches are taken from PROM
117 5578ceab blueswir1
        if (rw == 2 && (env->mmuregs[0] & env->def->mmu_bm)) {
118 58a770f3 blueswir1
            *physical = env->prom_addr | (address & 0x7ffffULL);
119 40ce0a9a blueswir1
            *prot = PAGE_READ | PAGE_EXEC;
120 40ce0a9a blueswir1
            return 0;
121 40ce0a9a blueswir1
        }
122 0f8a249a blueswir1
        *physical = address;
123 227671c9 bellard
        *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
124 e80cfcfc bellard
        return 0;
125 e8af50a3 bellard
    }
126 e8af50a3 bellard
127 7483750d bellard
    *access_index = ((rw & 1) << 2) | (rw & 2) | (is_user? 0 : 1);
128 5dcb6b91 blueswir1
    *physical = 0xffffffffffff0000ULL;
129 7483750d bellard
130 e8af50a3 bellard
    /* SPARC reference MMU table walk: Context table->L1->L2->PTE */
131 e8af50a3 bellard
    /* Context base + context number */
132 3deaeab7 blueswir1
    pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2);
133 49be8030 bellard
    pde = ldl_phys(pde_ptr);
134 e8af50a3 bellard
135 e8af50a3 bellard
    /* Ctx pde */
136 e8af50a3 bellard
    switch (pde & PTE_ENTRYTYPE_MASK) {
137 e80cfcfc bellard
    default:
138 e8af50a3 bellard
    case 0: /* Invalid */
139 0f8a249a blueswir1
        return 1 << 2;
140 e80cfcfc bellard
    case 2: /* L0 PTE, maybe should not happen? */
141 e8af50a3 bellard
    case 3: /* Reserved */
142 7483750d bellard
        return 4 << 2;
143 e80cfcfc bellard
    case 1: /* L0 PDE */
144 0f8a249a blueswir1
        pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4);
145 49be8030 bellard
        pde = ldl_phys(pde_ptr);
146 e8af50a3 bellard
147 0f8a249a blueswir1
        switch (pde & PTE_ENTRYTYPE_MASK) {
148 0f8a249a blueswir1
        default:
149 0f8a249a blueswir1
        case 0: /* Invalid */
150 0f8a249a blueswir1
            return (1 << 8) | (1 << 2);
151 0f8a249a blueswir1
        case 3: /* Reserved */
152 0f8a249a blueswir1
            return (1 << 8) | (4 << 2);
153 0f8a249a blueswir1
        case 1: /* L1 PDE */
154 0f8a249a blueswir1
            pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4);
155 49be8030 bellard
            pde = ldl_phys(pde_ptr);
156 e8af50a3 bellard
157 0f8a249a blueswir1
            switch (pde & PTE_ENTRYTYPE_MASK) {
158 0f8a249a blueswir1
            default:
159 0f8a249a blueswir1
            case 0: /* Invalid */
160 0f8a249a blueswir1
                return (2 << 8) | (1 << 2);
161 0f8a249a blueswir1
            case 3: /* Reserved */
162 0f8a249a blueswir1
                return (2 << 8) | (4 << 2);
163 0f8a249a blueswir1
            case 1: /* L2 PDE */
164 0f8a249a blueswir1
                pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4);
165 49be8030 bellard
                pde = ldl_phys(pde_ptr);
166 e8af50a3 bellard
167 0f8a249a blueswir1
                switch (pde & PTE_ENTRYTYPE_MASK) {
168 0f8a249a blueswir1
                default:
169 0f8a249a blueswir1
                case 0: /* Invalid */
170 0f8a249a blueswir1
                    return (3 << 8) | (1 << 2);
171 0f8a249a blueswir1
                case 1: /* PDE, should not happen */
172 0f8a249a blueswir1
                case 3: /* Reserved */
173 0f8a249a blueswir1
                    return (3 << 8) | (4 << 2);
174 0f8a249a blueswir1
                case 2: /* L3 PTE */
175 77f193da blueswir1
                    page_offset = (address & TARGET_PAGE_MASK) &
176 77f193da blueswir1
                        (TARGET_PAGE_SIZE - 1);
177 0f8a249a blueswir1
                }
178 0f8a249a blueswir1
                break;
179 0f8a249a blueswir1
            case 2: /* L2 PTE */
180 0f8a249a blueswir1
                page_offset = address & 0x3ffff;
181 0f8a249a blueswir1
            }
182 0f8a249a blueswir1
            break;
183 0f8a249a blueswir1
        case 2: /* L1 PTE */
184 0f8a249a blueswir1
            page_offset = address & 0xffffff;
185 0f8a249a blueswir1
        }
186 e8af50a3 bellard
    }
187 e8af50a3 bellard
188 e8af50a3 bellard
    /* update page modified and dirty bits */
189 b769d8fe bellard
    is_dirty = (rw & 1) && !(pde & PG_MODIFIED_MASK);
190 e8af50a3 bellard
    if (!(pde & PG_ACCESSED_MASK) || is_dirty) {
191 0f8a249a blueswir1
        pde |= PG_ACCESSED_MASK;
192 0f8a249a blueswir1
        if (is_dirty)
193 0f8a249a blueswir1
            pde |= PG_MODIFIED_MASK;
194 49be8030 bellard
        stl_phys_notdirty(pde_ptr, pde);
195 e8af50a3 bellard
    }
196 e8af50a3 bellard
    /* check access */
197 e8af50a3 bellard
    access_perms = (pde & PTE_ACCESS_MASK) >> PTE_ACCESS_SHIFT;
198 e80cfcfc bellard
    error_code = access_table[*access_index][access_perms];
199 d8e3326c bellard
    if (error_code && !((env->mmuregs[0] & MMU_NF) && is_user))
200 0f8a249a blueswir1
        return error_code;
201 e8af50a3 bellard
202 e8af50a3 bellard
    /* the page can be put in the TLB */
203 227671c9 bellard
    *prot = perm_table[is_user][access_perms];
204 227671c9 bellard
    if (!(pde & PG_MODIFIED_MASK)) {
205 e8af50a3 bellard
        /* only set write access if already dirty... otherwise wait
206 e8af50a3 bellard
           for dirty access */
207 227671c9 bellard
        *prot &= ~PAGE_WRITE;
208 e8af50a3 bellard
    }
209 e8af50a3 bellard
210 e8af50a3 bellard
    /* Even if large ptes, we map only one 4KB page in the cache to
211 e8af50a3 bellard
       avoid filling it too fast */
212 c227f099 Anthony Liguori
    *physical = ((target_phys_addr_t)(pde & PTE_ADDR_MASK) << 4) + page_offset;
213 6f7e9aec bellard
    return error_code;
214 e80cfcfc bellard
}
215 e80cfcfc bellard
216 e80cfcfc bellard
/* Perform address translation */
217 af7bf89b bellard
int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
218 6ebbf390 j_mayer
                              int mmu_idx, int is_softmmu)
219 e80cfcfc bellard
{
220 c227f099 Anthony Liguori
    target_phys_addr_t paddr;
221 5dcb6b91 blueswir1
    target_ulong vaddr;
222 e80cfcfc bellard
    int error_code = 0, prot, ret = 0, access_index;
223 e8af50a3 bellard
224 77f193da blueswir1
    error_code = get_physical_address(env, &paddr, &prot, &access_index,
225 77f193da blueswir1
                                      address, rw, mmu_idx);
226 e80cfcfc bellard
    if (error_code == 0) {
227 0f8a249a blueswir1
        vaddr = address & TARGET_PAGE_MASK;
228 0f8a249a blueswir1
        paddr &= TARGET_PAGE_MASK;
229 9e61bde5 bellard
#ifdef DEBUG_MMU
230 0f8a249a blueswir1
        printf("Translate at " TARGET_FMT_lx " -> " TARGET_FMT_plx ", vaddr "
231 5dcb6b91 blueswir1
               TARGET_FMT_lx "\n", address, paddr, vaddr);
232 9e61bde5 bellard
#endif
233 6ebbf390 j_mayer
        ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
234 0f8a249a blueswir1
        return ret;
235 e80cfcfc bellard
    }
236 e8af50a3 bellard
237 e8af50a3 bellard
    if (env->mmuregs[3]) /* Fault status register */
238 0f8a249a blueswir1
        env->mmuregs[3] = 1; /* overflow (not read before another fault) */
239 7483750d bellard
    env->mmuregs[3] |= (access_index << 5) | error_code | 2;
240 e8af50a3 bellard
    env->mmuregs[4] = address; /* Fault address register */
241 e8af50a3 bellard
242 878d3096 bellard
    if ((env->mmuregs[0] & MMU_NF) || env->psret == 0)  {
243 6f7e9aec bellard
        // No fault mode: if a mapping is available, just override
244 6f7e9aec bellard
        // permissions. If no mapping is available, redirect accesses to
245 6f7e9aec bellard
        // neverland. Fake/overridden mappings will be flushed when
246 6f7e9aec bellard
        // switching to normal mode.
247 0f8a249a blueswir1
        vaddr = address & TARGET_PAGE_MASK;
248 227671c9 bellard
        prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
249 6ebbf390 j_mayer
        ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
250 0f8a249a blueswir1
        return ret;
251 7483750d bellard
    } else {
252 7483750d bellard
        if (rw & 2)
253 7483750d bellard
            env->exception_index = TT_TFAULT;
254 7483750d bellard
        else
255 7483750d bellard
            env->exception_index = TT_DFAULT;
256 7483750d bellard
        return 1;
257 878d3096 bellard
    }
258 e8af50a3 bellard
}
259 24741ef3 bellard
260 24741ef3 bellard
target_ulong mmu_probe(CPUState *env, target_ulong address, int mmulev)
261 24741ef3 bellard
{
262 c227f099 Anthony Liguori
    target_phys_addr_t pde_ptr;
263 24741ef3 bellard
    uint32_t pde;
264 24741ef3 bellard
265 24741ef3 bellard
    /* Context base + context number */
266 c227f099 Anthony Liguori
    pde_ptr = (target_phys_addr_t)(env->mmuregs[1] << 4) +
267 5dcb6b91 blueswir1
        (env->mmuregs[2] << 2);
268 24741ef3 bellard
    pde = ldl_phys(pde_ptr);
269 24741ef3 bellard
270 24741ef3 bellard
    switch (pde & PTE_ENTRYTYPE_MASK) {
271 24741ef3 bellard
    default:
272 24741ef3 bellard
    case 0: /* Invalid */
273 24741ef3 bellard
    case 2: /* PTE, maybe should not happen? */
274 24741ef3 bellard
    case 3: /* Reserved */
275 0f8a249a blueswir1
        return 0;
276 24741ef3 bellard
    case 1: /* L1 PDE */
277 0f8a249a blueswir1
        if (mmulev == 3)
278 0f8a249a blueswir1
            return pde;
279 0f8a249a blueswir1
        pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4);
280 24741ef3 bellard
        pde = ldl_phys(pde_ptr);
281 24741ef3 bellard
282 0f8a249a blueswir1
        switch (pde & PTE_ENTRYTYPE_MASK) {
283 0f8a249a blueswir1
        default:
284 0f8a249a blueswir1
        case 0: /* Invalid */
285 0f8a249a blueswir1
        case 3: /* Reserved */
286 0f8a249a blueswir1
            return 0;
287 0f8a249a blueswir1
        case 2: /* L1 PTE */
288 0f8a249a blueswir1
            return pde;
289 0f8a249a blueswir1
        case 1: /* L2 PDE */
290 0f8a249a blueswir1
            if (mmulev == 2)
291 0f8a249a blueswir1
                return pde;
292 0f8a249a blueswir1
            pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4);
293 24741ef3 bellard
            pde = ldl_phys(pde_ptr);
294 24741ef3 bellard
295 0f8a249a blueswir1
            switch (pde & PTE_ENTRYTYPE_MASK) {
296 0f8a249a blueswir1
            default:
297 0f8a249a blueswir1
            case 0: /* Invalid */
298 0f8a249a blueswir1
            case 3: /* Reserved */
299 0f8a249a blueswir1
                return 0;
300 0f8a249a blueswir1
            case 2: /* L2 PTE */
301 0f8a249a blueswir1
                return pde;
302 0f8a249a blueswir1
            case 1: /* L3 PDE */
303 0f8a249a blueswir1
                if (mmulev == 1)
304 0f8a249a blueswir1
                    return pde;
305 0f8a249a blueswir1
                pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4);
306 24741ef3 bellard
                pde = ldl_phys(pde_ptr);
307 24741ef3 bellard
308 0f8a249a blueswir1
                switch (pde & PTE_ENTRYTYPE_MASK) {
309 0f8a249a blueswir1
                default:
310 0f8a249a blueswir1
                case 0: /* Invalid */
311 0f8a249a blueswir1
                case 1: /* PDE, should not happen */
312 0f8a249a blueswir1
                case 3: /* Reserved */
313 0f8a249a blueswir1
                    return 0;
314 0f8a249a blueswir1
                case 2: /* L3 PTE */
315 0f8a249a blueswir1
                    return pde;
316 0f8a249a blueswir1
                }
317 0f8a249a blueswir1
            }
318 0f8a249a blueswir1
        }
319 24741ef3 bellard
    }
320 24741ef3 bellard
    return 0;
321 24741ef3 bellard
}
322 24741ef3 bellard
323 24741ef3 bellard
#ifdef DEBUG_MMU
324 24741ef3 bellard
void dump_mmu(CPUState *env)
325 24741ef3 bellard
{
326 5dcb6b91 blueswir1
    target_ulong va, va1, va2;
327 5dcb6b91 blueswir1
    unsigned int n, m, o;
328 c227f099 Anthony Liguori
    target_phys_addr_t pde_ptr, pa;
329 24741ef3 bellard
    uint32_t pde;
330 24741ef3 bellard
331 24741ef3 bellard
    printf("MMU dump:\n");
332 24741ef3 bellard
    pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2);
333 24741ef3 bellard
    pde = ldl_phys(pde_ptr);
334 5dcb6b91 blueswir1
    printf("Root ptr: " TARGET_FMT_plx ", ctx: %d\n",
335 c227f099 Anthony Liguori
           (target_phys_addr_t)env->mmuregs[1] << 4, env->mmuregs[2]);
336 24741ef3 bellard
    for (n = 0, va = 0; n < 256; n++, va += 16 * 1024 * 1024) {
337 0f8a249a blueswir1
        pde = mmu_probe(env, va, 2);
338 0f8a249a blueswir1
        if (pde) {
339 0f8a249a blueswir1
            pa = cpu_get_phys_page_debug(env, va);
340 0f8a249a blueswir1
            printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx
341 5dcb6b91 blueswir1
                   " PDE: " TARGET_FMT_lx "\n", va, pa, pde);
342 0f8a249a blueswir1
            for (m = 0, va1 = va; m < 64; m++, va1 += 256 * 1024) {
343 0f8a249a blueswir1
                pde = mmu_probe(env, va1, 1);
344 0f8a249a blueswir1
                if (pde) {
345 0f8a249a blueswir1
                    pa = cpu_get_phys_page_debug(env, va1);
346 0f8a249a blueswir1
                    printf(" VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx
347 5dcb6b91 blueswir1
                           " PDE: " TARGET_FMT_lx "\n", va1, pa, pde);
348 0f8a249a blueswir1
                    for (o = 0, va2 = va1; o < 64; o++, va2 += 4 * 1024) {
349 0f8a249a blueswir1
                        pde = mmu_probe(env, va2, 0);
350 0f8a249a blueswir1
                        if (pde) {
351 0f8a249a blueswir1
                            pa = cpu_get_phys_page_debug(env, va2);
352 0f8a249a blueswir1
                            printf("  VA: " TARGET_FMT_lx ", PA: "
353 5dcb6b91 blueswir1
                                   TARGET_FMT_plx " PTE: " TARGET_FMT_lx "\n",
354 5dcb6b91 blueswir1
                                   va2, pa, pde);
355 0f8a249a blueswir1
                        }
356 0f8a249a blueswir1
                    }
357 0f8a249a blueswir1
                }
358 0f8a249a blueswir1
            }
359 0f8a249a blueswir1
        }
360 24741ef3 bellard
    }
361 24741ef3 bellard
    printf("MMU dump ends\n");
362 24741ef3 bellard
}
363 24741ef3 bellard
#endif /* DEBUG_MMU */
364 24741ef3 bellard
365 24741ef3 bellard
#else /* !TARGET_SPARC64 */
366 e8807b14 Igor Kovalenko
367 e8807b14 Igor Kovalenko
// 41 bit physical address space
368 c227f099 Anthony Liguori
static inline target_phys_addr_t ultrasparc_truncate_physical(uint64_t x)
369 e8807b14 Igor Kovalenko
{
370 e8807b14 Igor Kovalenko
    return x & 0x1ffffffffffULL;
371 e8807b14 Igor Kovalenko
}
372 e8807b14 Igor Kovalenko
373 83469015 bellard
/*
374 83469015 bellard
 * UltraSparc IIi I/DMMUs
375 83469015 bellard
 */
376 536ba015 Igor Kovalenko
377 536ba015 Igor Kovalenko
static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask)
378 536ba015 Igor Kovalenko
{
379 536ba015 Igor Kovalenko
    return (x & mask) == (y & mask);
380 536ba015 Igor Kovalenko
}
381 536ba015 Igor Kovalenko
382 536ba015 Igor Kovalenko
// Returns true if TTE tag is valid and matches virtual address value in context
383 536ba015 Igor Kovalenko
// requires virtual address mask value calculated from TTE entry size
384 6e8e7d4c Igor Kovalenko
static inline int ultrasparc_tag_match(SparcTLBEntry *tlb,
385 536ba015 Igor Kovalenko
                                       uint64_t address, uint64_t context,
386 2a90358f Blue Swirl
                                       target_phys_addr_t *physical,
387 2a90358f Blue Swirl
                                       int is_nucleus)
388 536ba015 Igor Kovalenko
{
389 536ba015 Igor Kovalenko
    uint64_t mask;
390 536ba015 Igor Kovalenko
391 6e8e7d4c Igor Kovalenko
    switch ((tlb->tte >> 61) & 3) {
392 536ba015 Igor Kovalenko
    default:
393 536ba015 Igor Kovalenko
    case 0x0: // 8k
394 536ba015 Igor Kovalenko
        mask = 0xffffffffffffe000ULL;
395 536ba015 Igor Kovalenko
        break;
396 536ba015 Igor Kovalenko
    case 0x1: // 64k
397 536ba015 Igor Kovalenko
        mask = 0xffffffffffff0000ULL;
398 536ba015 Igor Kovalenko
        break;
399 536ba015 Igor Kovalenko
    case 0x2: // 512k
400 536ba015 Igor Kovalenko
        mask = 0xfffffffffff80000ULL;
401 536ba015 Igor Kovalenko
        break;
402 536ba015 Igor Kovalenko
    case 0x3: // 4M
403 536ba015 Igor Kovalenko
        mask = 0xffffffffffc00000ULL;
404 536ba015 Igor Kovalenko
        break;
405 536ba015 Igor Kovalenko
    }
406 536ba015 Igor Kovalenko
407 536ba015 Igor Kovalenko
    // valid, context match, virtual address match?
408 f707726e Igor Kovalenko
    if (TTE_IS_VALID(tlb->tte) &&
409 2a90358f Blue Swirl
        ((is_nucleus && compare_masked(0, tlb->tag, 0x1fff))
410 2a90358f Blue Swirl
         || TTE_IS_GLOBAL(tlb->tte) || compare_masked(context, tlb->tag, 0x1fff))
411 2a90358f Blue Swirl
        && compare_masked(address, tlb->tag, mask))
412 536ba015 Igor Kovalenko
    {
413 536ba015 Igor Kovalenko
        // decode physical address
414 6e8e7d4c Igor Kovalenko
        *physical = ((tlb->tte & mask) | (address & ~mask)) & 0x1ffffffe000ULL;
415 536ba015 Igor Kovalenko
        return 1;
416 536ba015 Igor Kovalenko
    }
417 536ba015 Igor Kovalenko
418 536ba015 Igor Kovalenko
    return 0;
419 536ba015 Igor Kovalenko
}
420 536ba015 Igor Kovalenko
421 77f193da blueswir1
static int get_physical_address_data(CPUState *env,
422 c227f099 Anthony Liguori
                                     target_phys_addr_t *physical, int *prot,
423 22548760 blueswir1
                                     target_ulong address, int rw, int is_user)
424 3475187d bellard
{
425 3475187d bellard
    unsigned int i;
426 536ba015 Igor Kovalenko
    uint64_t context;
427 2a90358f Blue Swirl
    int is_nucleus;
428 3475187d bellard
429 3475187d bellard
    if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */
430 e8807b14 Igor Kovalenko
        *physical = ultrasparc_truncate_physical(address);
431 0f8a249a blueswir1
        *prot = PAGE_READ | PAGE_WRITE;
432 3475187d bellard
        return 0;
433 3475187d bellard
    }
434 3475187d bellard
435 6e8e7d4c Igor Kovalenko
    context = env->dmmu.mmu_primary_context & 0x1fff;
436 2a90358f Blue Swirl
    is_nucleus = env->tl > 0;
437 536ba015 Igor Kovalenko
438 3475187d bellard
    for (i = 0; i < 64; i++) {
439 afdf8109 blueswir1
        // ctx match, vaddr match, valid?
440 6e8e7d4c Igor Kovalenko
        if (ultrasparc_tag_match(&env->dtlb[i],
441 2a90358f Blue Swirl
                                 address, context, physical,
442 2a90358f Blue Swirl
                                 is_nucleus)) {
443 afdf8109 blueswir1
            // access ok?
444 6e8e7d4c Igor Kovalenko
            if (((env->dtlb[i].tte & 0x4) && is_user) ||
445 6e8e7d4c Igor Kovalenko
                (!(env->dtlb[i].tte & 0x2) && (rw == 1))) {
446 6e8e7d4c Igor Kovalenko
                uint8_t fault_type = 0;
447 6e8e7d4c Igor Kovalenko
448 6e8e7d4c Igor Kovalenko
                if ((env->dtlb[i].tte & 0x4) && is_user) {
449 6e8e7d4c Igor Kovalenko
                    fault_type |= 1; /* privilege violation */
450 6e8e7d4c Igor Kovalenko
                }
451 6e8e7d4c Igor Kovalenko
452 6e8e7d4c Igor Kovalenko
                if (env->dmmu.sfsr & 1) /* Fault status register */
453 6e8e7d4c Igor Kovalenko
                    env->dmmu.sfsr = 2; /* overflow (not read before
454 77f193da blueswir1
                                             another fault) */
455 6e8e7d4c Igor Kovalenko
456 6e8e7d4c Igor Kovalenko
                env->dmmu.sfsr |= (is_user << 3) | ((rw == 1) << 2) | 1;
457 6e8e7d4c Igor Kovalenko
458 6e8e7d4c Igor Kovalenko
                env->dmmu.sfsr |= (fault_type << 7);
459 6e8e7d4c Igor Kovalenko
460 6e8e7d4c Igor Kovalenko
                env->dmmu.sfar = address; /* Fault address register */
461 0f8a249a blueswir1
                env->exception_index = TT_DFAULT;
462 83469015 bellard
#ifdef DEBUG_MMU
463 0f8a249a blueswir1
                printf("DFAULT at 0x%" PRIx64 "\n", address);
464 83469015 bellard
#endif
465 0f8a249a blueswir1
                return 1;
466 0f8a249a blueswir1
            }
467 0f8a249a blueswir1
            *prot = PAGE_READ;
468 6e8e7d4c Igor Kovalenko
            if (env->dtlb[i].tte & 0x2)
469 0f8a249a blueswir1
                *prot |= PAGE_WRITE;
470 f707726e Igor Kovalenko
            TTE_SET_USED(env->dtlb[i].tte);
471 0f8a249a blueswir1
            return 0;
472 0f8a249a blueswir1
        }
473 3475187d bellard
    }
474 83469015 bellard
#ifdef DEBUG_MMU
475 26a76461 bellard
    printf("DMISS at 0x%" PRIx64 "\n", address);
476 83469015 bellard
#endif
477 6e8e7d4c Igor Kovalenko
    env->dmmu.tag_access = (address & ~0x1fffULL) | context;
478 83469015 bellard
    env->exception_index = TT_DMISS;
479 3475187d bellard
    return 1;
480 3475187d bellard
}
481 3475187d bellard
482 77f193da blueswir1
static int get_physical_address_code(CPUState *env,
483 c227f099 Anthony Liguori
                                     target_phys_addr_t *physical, int *prot,
484 22548760 blueswir1
                                     target_ulong address, int is_user)
485 3475187d bellard
{
486 3475187d bellard
    unsigned int i;
487 536ba015 Igor Kovalenko
    uint64_t context;
488 2a90358f Blue Swirl
    int is_nucleus;
489 3475187d bellard
490 e8807b14 Igor Kovalenko
    if ((env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0) {
491 e8807b14 Igor Kovalenko
        /* IMMU disabled */
492 e8807b14 Igor Kovalenko
        *physical = ultrasparc_truncate_physical(address);
493 0f8a249a blueswir1
        *prot = PAGE_EXEC;
494 3475187d bellard
        return 0;
495 3475187d bellard
    }
496 83469015 bellard
497 6e8e7d4c Igor Kovalenko
    context = env->dmmu.mmu_primary_context & 0x1fff;
498 2a90358f Blue Swirl
    is_nucleus = env->tl > 0;
499 536ba015 Igor Kovalenko
500 3475187d bellard
    for (i = 0; i < 64; i++) {
501 afdf8109 blueswir1
        // ctx match, vaddr match, valid?
502 6e8e7d4c Igor Kovalenko
        if (ultrasparc_tag_match(&env->itlb[i],
503 2a90358f Blue Swirl
                                 address, context, physical,
504 2a90358f Blue Swirl
                                 is_nucleus)) {
505 afdf8109 blueswir1
            // access ok?
506 6e8e7d4c Igor Kovalenko
            if ((env->itlb[i].tte & 0x4) && is_user) {
507 6e8e7d4c Igor Kovalenko
                if (env->immu.sfsr) /* Fault status register */
508 6e8e7d4c Igor Kovalenko
                    env->immu.sfsr = 2; /* overflow (not read before
509 77f193da blueswir1
                                             another fault) */
510 6e8e7d4c Igor Kovalenko
                env->immu.sfsr |= (is_user << 3) | 1;
511 0f8a249a blueswir1
                env->exception_index = TT_TFAULT;
512 83469015 bellard
#ifdef DEBUG_MMU
513 0f8a249a blueswir1
                printf("TFAULT at 0x%" PRIx64 "\n", address);
514 83469015 bellard
#endif
515 0f8a249a blueswir1
                return 1;
516 0f8a249a blueswir1
            }
517 0f8a249a blueswir1
            *prot = PAGE_EXEC;
518 f707726e Igor Kovalenko
            TTE_SET_USED(env->itlb[i].tte);
519 0f8a249a blueswir1
            return 0;
520 0f8a249a blueswir1
        }
521 3475187d bellard
    }
522 83469015 bellard
#ifdef DEBUG_MMU
523 26a76461 bellard
    printf("TMISS at 0x%" PRIx64 "\n", address);
524 83469015 bellard
#endif
525 7ab463cb Blue Swirl
    /* Context is stored in DMMU (dmmuregs[1]) also for IMMU */
526 6e8e7d4c Igor Kovalenko
    env->immu.tag_access = (address & ~0x1fffULL) | context;
527 83469015 bellard
    env->exception_index = TT_TMISS;
528 3475187d bellard
    return 1;
529 3475187d bellard
}
530 3475187d bellard
531 c227f099 Anthony Liguori
static int get_physical_address(CPUState *env, target_phys_addr_t *physical,
532 c48fcb47 blueswir1
                                int *prot, int *access_index,
533 c48fcb47 blueswir1
                                target_ulong address, int rw, int mmu_idx)
534 3475187d bellard
{
535 6ebbf390 j_mayer
    int is_user = mmu_idx == MMU_USER_IDX;
536 6ebbf390 j_mayer
537 3475187d bellard
    if (rw == 2)
538 22548760 blueswir1
        return get_physical_address_code(env, physical, prot, address,
539 22548760 blueswir1
                                         is_user);
540 3475187d bellard
    else
541 22548760 blueswir1
        return get_physical_address_data(env, physical, prot, address, rw,
542 22548760 blueswir1
                                         is_user);
543 3475187d bellard
}
544 3475187d bellard
545 3475187d bellard
/* Perform address translation */
546 3475187d bellard
int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
547 6ebbf390 j_mayer
                              int mmu_idx, int is_softmmu)
548 3475187d bellard
{
549 83469015 bellard
    target_ulong virt_addr, vaddr;
550 c227f099 Anthony Liguori
    target_phys_addr_t paddr;
551 3475187d bellard
    int error_code = 0, prot, ret = 0, access_index;
552 3475187d bellard
553 77f193da blueswir1
    error_code = get_physical_address(env, &paddr, &prot, &access_index,
554 77f193da blueswir1
                                      address, rw, mmu_idx);
555 3475187d bellard
    if (error_code == 0) {
556 0f8a249a blueswir1
        virt_addr = address & TARGET_PAGE_MASK;
557 77f193da blueswir1
        vaddr = virt_addr + ((address & TARGET_PAGE_MASK) &
558 77f193da blueswir1
                             (TARGET_PAGE_SIZE - 1));
559 83469015 bellard
#ifdef DEBUG_MMU
560 77f193da blueswir1
        printf("Translate at 0x%" PRIx64 " -> 0x%" PRIx64 ", vaddr 0x%" PRIx64
561 77f193da blueswir1
               "\n", address, paddr, vaddr);
562 83469015 bellard
#endif
563 6ebbf390 j_mayer
        ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu);
564 0f8a249a blueswir1
        return ret;
565 3475187d bellard
    }
566 3475187d bellard
    // XXX
567 3475187d bellard
    return 1;
568 3475187d bellard
}
569 3475187d bellard
570 83469015 bellard
#ifdef DEBUG_MMU
571 83469015 bellard
void dump_mmu(CPUState *env)
572 83469015 bellard
{
573 83469015 bellard
    unsigned int i;
574 83469015 bellard
    const char *mask;
575 83469015 bellard
576 77f193da blueswir1
    printf("MMU contexts: Primary: %" PRId64 ", Secondary: %" PRId64 "\n",
577 6e8e7d4c Igor Kovalenko
           env->dmmu.mmu_primary_context, env->dmmu.mmu_secondary_context);
578 83469015 bellard
    if ((env->lsu & DMMU_E) == 0) {
579 0f8a249a blueswir1
        printf("DMMU disabled\n");
580 83469015 bellard
    } else {
581 0f8a249a blueswir1
        printf("DMMU dump:\n");
582 0f8a249a blueswir1
        for (i = 0; i < 64; i++) {
583 31a68d57 Blue Swirl
            switch ((env->dtlb[i].tte >> 61) & 3) {
584 0f8a249a blueswir1
            default:
585 0f8a249a blueswir1
            case 0x0:
586 0f8a249a blueswir1
                mask = "  8k";
587 0f8a249a blueswir1
                break;
588 0f8a249a blueswir1
            case 0x1:
589 0f8a249a blueswir1
                mask = " 64k";
590 0f8a249a blueswir1
                break;
591 0f8a249a blueswir1
            case 0x2:
592 0f8a249a blueswir1
                mask = "512k";
593 0f8a249a blueswir1
                break;
594 0f8a249a blueswir1
            case 0x3:
595 0f8a249a blueswir1
                mask = "  4M";
596 0f8a249a blueswir1
                break;
597 0f8a249a blueswir1
            }
598 31a68d57 Blue Swirl
            if ((env->dtlb[i].tte & 0x8000000000000000ULL) != 0) {
599 31a68d57 Blue Swirl
                printf("[%02u] VA: %" PRIx64 ", PA: %" PRIx64
600 2a90358f Blue Swirl
                       ", %s, %s, %s, %s, ctx %" PRId64 " %s\n",
601 6e8e7d4c Igor Kovalenko
                       i,
602 31a68d57 Blue Swirl
                       env->dtlb[i].tag & (uint64_t)~0x1fffULL,
603 31a68d57 Blue Swirl
                       env->dtlb[i].tte & (uint64_t)0x1ffffffe000ULL,
604 0f8a249a blueswir1
                       mask,
605 31a68d57 Blue Swirl
                       env->dtlb[i].tte & 0x4? "priv": "user",
606 31a68d57 Blue Swirl
                       env->dtlb[i].tte & 0x2? "RW": "RO",
607 31a68d57 Blue Swirl
                       env->dtlb[i].tte & 0x40? "locked": "unlocked",
608 2a90358f Blue Swirl
                       env->dtlb[i].tag & (uint64_t)0x1fffULL,
609 2a90358f Blue Swirl
                       TTE_IS_GLOBAL(env->dtlb[i].tag)? "global" : "local");
610 0f8a249a blueswir1
            }
611 0f8a249a blueswir1
        }
612 83469015 bellard
    }
613 83469015 bellard
    if ((env->lsu & IMMU_E) == 0) {
614 0f8a249a blueswir1
        printf("IMMU disabled\n");
615 83469015 bellard
    } else {
616 0f8a249a blueswir1
        printf("IMMU dump:\n");
617 0f8a249a blueswir1
        for (i = 0; i < 64; i++) {
618 31a68d57 Blue Swirl
            switch ((env->itlb[i].tte >> 61) & 3) {
619 0f8a249a blueswir1
            default:
620 0f8a249a blueswir1
            case 0x0:
621 0f8a249a blueswir1
                mask = "  8k";
622 0f8a249a blueswir1
                break;
623 0f8a249a blueswir1
            case 0x1:
624 0f8a249a blueswir1
                mask = " 64k";
625 0f8a249a blueswir1
                break;
626 0f8a249a blueswir1
            case 0x2:
627 0f8a249a blueswir1
                mask = "512k";
628 0f8a249a blueswir1
                break;
629 0f8a249a blueswir1
            case 0x3:
630 0f8a249a blueswir1
                mask = "  4M";
631 0f8a249a blueswir1
                break;
632 0f8a249a blueswir1
            }
633 31a68d57 Blue Swirl
            if ((env->itlb[i].tte & 0x8000000000000000ULL) != 0) {
634 31a68d57 Blue Swirl
                printf("[%02u] VA: %" PRIx64 ", PA: %" PRIx64
635 2a90358f Blue Swirl
                       ", %s, %s, %s, ctx %" PRId64 " %s\n",
636 6e8e7d4c Igor Kovalenko
                       i,
637 6e8e7d4c Igor Kovalenko
                       env->itlb[i].tag & (uint64_t)~0x1fffULL,
638 31a68d57 Blue Swirl
                       env->itlb[i].tte & (uint64_t)0x1ffffffe000ULL,
639 0f8a249a blueswir1
                       mask,
640 31a68d57 Blue Swirl
                       env->itlb[i].tte & 0x4? "priv": "user",
641 31a68d57 Blue Swirl
                       env->itlb[i].tte & 0x40? "locked": "unlocked",
642 2a90358f Blue Swirl
                       env->itlb[i].tag & (uint64_t)0x1fffULL,
643 2a90358f Blue Swirl
                       TTE_IS_GLOBAL(env->itlb[i].tag)? "global" : "local");
644 0f8a249a blueswir1
            }
645 0f8a249a blueswir1
        }
646 83469015 bellard
    }
647 83469015 bellard
}
648 24741ef3 bellard
#endif /* DEBUG_MMU */
649 24741ef3 bellard
650 24741ef3 bellard
#endif /* TARGET_SPARC64 */
651 24741ef3 bellard
#endif /* !CONFIG_USER_ONLY */
652 24741ef3 bellard
653 c48fcb47 blueswir1
654 c48fcb47 blueswir1
#if defined(CONFIG_USER_ONLY)
655 c227f099 Anthony Liguori
target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
656 c48fcb47 blueswir1
{
657 c48fcb47 blueswir1
    return addr;
658 c48fcb47 blueswir1
}
659 c48fcb47 blueswir1
660 c48fcb47 blueswir1
#else
661 c227f099 Anthony Liguori
target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
662 c48fcb47 blueswir1
{
663 c227f099 Anthony Liguori
    target_phys_addr_t phys_addr;
664 c48fcb47 blueswir1
    int prot, access_index;
665 c48fcb47 blueswir1
666 c48fcb47 blueswir1
    if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2,
667 c48fcb47 blueswir1
                             MMU_KERNEL_IDX) != 0)
668 c48fcb47 blueswir1
        if (get_physical_address(env, &phys_addr, &prot, &access_index, addr,
669 c48fcb47 blueswir1
                                 0, MMU_KERNEL_IDX) != 0)
670 c48fcb47 blueswir1
            return -1;
671 c48fcb47 blueswir1
    if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED)
672 c48fcb47 blueswir1
        return -1;
673 c48fcb47 blueswir1
    return phys_addr;
674 c48fcb47 blueswir1
}
675 c48fcb47 blueswir1
#endif
676 c48fcb47 blueswir1
677 c48fcb47 blueswir1
void cpu_reset(CPUSPARCState *env)
678 c48fcb47 blueswir1
{
679 eca1bdf4 aliguori
    if (qemu_loglevel_mask(CPU_LOG_RESET)) {
680 eca1bdf4 aliguori
        qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
681 eca1bdf4 aliguori
        log_cpu_state(env, 0);
682 eca1bdf4 aliguori
    }
683 eca1bdf4 aliguori
684 c48fcb47 blueswir1
    tlb_flush(env, 1);
685 c48fcb47 blueswir1
    env->cwp = 0;
686 5210977a Igor Kovalenko
#ifndef TARGET_SPARC64
687 c48fcb47 blueswir1
    env->wim = 1;
688 5210977a Igor Kovalenko
#endif
689 c48fcb47 blueswir1
    env->regwptr = env->regbase + (env->cwp * 16);
690 6b743278 Blue Swirl
    CC_OP = CC_OP_FLAGS;
691 c48fcb47 blueswir1
#if defined(CONFIG_USER_ONLY)
692 c48fcb47 blueswir1
#ifdef TARGET_SPARC64
693 1a14026e blueswir1
    env->cleanwin = env->nwindows - 2;
694 1a14026e blueswir1
    env->cansave = env->nwindows - 2;
695 c48fcb47 blueswir1
    env->pstate = PS_RMO | PS_PEF | PS_IE;
696 c48fcb47 blueswir1
    env->asi = 0x82; // Primary no-fault
697 c48fcb47 blueswir1
#endif
698 c48fcb47 blueswir1
#else
699 5210977a Igor Kovalenko
#if !defined(TARGET_SPARC64)
700 c48fcb47 blueswir1
    env->psret = 0;
701 5210977a Igor Kovalenko
#endif
702 c48fcb47 blueswir1
    env->psrs = 1;
703 c48fcb47 blueswir1
    env->psrps = 1;
704 c48fcb47 blueswir1
#ifdef TARGET_SPARC64
705 8194f35a Igor Kovalenko
    env->pstate = PS_PRIV|PS_RED|PS_PEF|PS_AG;
706 c48fcb47 blueswir1
    env->hpstate = HS_PRIV;
707 8194f35a Igor Kovalenko
    env->tl = env->maxtl;
708 8194f35a Igor Kovalenko
    cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
709 415fc906 blueswir1
    env->lsu = 0;
710 c48fcb47 blueswir1
#else
711 c48fcb47 blueswir1
    env->mmuregs[0] &= ~(MMU_E | MMU_NF);
712 5578ceab blueswir1
    env->mmuregs[0] |= env->def->mmu_bm;
713 c48fcb47 blueswir1
#endif
714 e87231d4 blueswir1
    env->pc = 0;
715 c48fcb47 blueswir1
    env->npc = env->pc + 4;
716 c48fcb47 blueswir1
#endif
717 c48fcb47 blueswir1
}
718 c48fcb47 blueswir1
719 64a88d5d blueswir1
static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model)
720 c48fcb47 blueswir1
{
721 64a88d5d blueswir1
    sparc_def_t def1, *def = &def1;
722 c48fcb47 blueswir1
723 64a88d5d blueswir1
    if (cpu_sparc_find_by_name(def, cpu_model) < 0)
724 64a88d5d blueswir1
        return -1;
725 c48fcb47 blueswir1
726 5578ceab blueswir1
    env->def = qemu_mallocz(sizeof(*def));
727 5578ceab blueswir1
    memcpy(env->def, def, sizeof(*def));
728 5578ceab blueswir1
#if defined(CONFIG_USER_ONLY)
729 5578ceab blueswir1
    if ((env->def->features & CPU_FEATURE_FLOAT))
730 5578ceab blueswir1
        env->def->features |= CPU_FEATURE_FLOAT128;
731 5578ceab blueswir1
#endif
732 c48fcb47 blueswir1
    env->cpu_model_str = cpu_model;
733 c48fcb47 blueswir1
    env->version = def->iu_version;
734 c48fcb47 blueswir1
    env->fsr = def->fpu_version;
735 1a14026e blueswir1
    env->nwindows = def->nwindows;
736 c48fcb47 blueswir1
#if !defined(TARGET_SPARC64)
737 c48fcb47 blueswir1
    env->mmuregs[0] |= def->mmu_version;
738 c48fcb47 blueswir1
    cpu_sparc_set_id(env, 0);
739 963262de blueswir1
    env->mxccregs[7] |= def->mxcc_version;
740 1a14026e blueswir1
#else
741 fb79ceb9 blueswir1
    env->mmu_version = def->mmu_version;
742 c19148bd blueswir1
    env->maxtl = def->maxtl;
743 c19148bd blueswir1
    env->version |= def->maxtl << 8;
744 1a14026e blueswir1
    env->version |= def->nwindows - 1;
745 c48fcb47 blueswir1
#endif
746 64a88d5d blueswir1
    return 0;
747 64a88d5d blueswir1
}
748 64a88d5d blueswir1
749 64a88d5d blueswir1
static void cpu_sparc_close(CPUSPARCState *env)
750 64a88d5d blueswir1
{
751 5578ceab blueswir1
    free(env->def);
752 64a88d5d blueswir1
    free(env);
753 64a88d5d blueswir1
}
754 64a88d5d blueswir1
755 64a88d5d blueswir1
CPUSPARCState *cpu_sparc_init(const char *cpu_model)
756 64a88d5d blueswir1
{
757 64a88d5d blueswir1
    CPUSPARCState *env;
758 64a88d5d blueswir1
759 64a88d5d blueswir1
    env = qemu_mallocz(sizeof(CPUSPARCState));
760 64a88d5d blueswir1
    cpu_exec_init(env);
761 c48fcb47 blueswir1
762 c48fcb47 blueswir1
    gen_intermediate_code_init(env);
763 c48fcb47 blueswir1
764 64a88d5d blueswir1
    if (cpu_sparc_register(env, cpu_model) < 0) {
765 64a88d5d blueswir1
        cpu_sparc_close(env);
766 64a88d5d blueswir1
        return NULL;
767 64a88d5d blueswir1
    }
768 0bf46a40 aliguori
    qemu_init_vcpu(env);
769 c48fcb47 blueswir1
770 c48fcb47 blueswir1
    return env;
771 c48fcb47 blueswir1
}
772 c48fcb47 blueswir1
773 c48fcb47 blueswir1
void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
774 c48fcb47 blueswir1
{
775 c48fcb47 blueswir1
#if !defined(TARGET_SPARC64)
776 c48fcb47 blueswir1
    env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
777 c48fcb47 blueswir1
#endif
778 c48fcb47 blueswir1
}
779 c48fcb47 blueswir1
780 c48fcb47 blueswir1
static const sparc_def_t sparc_defs[] = {
781 c48fcb47 blueswir1
#ifdef TARGET_SPARC64
782 c48fcb47 blueswir1
    {
783 c48fcb47 blueswir1
        .name = "Fujitsu Sparc64",
784 c19148bd blueswir1
        .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
785 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
786 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
787 1a14026e blueswir1
        .nwindows = 4,
788 c19148bd blueswir1
        .maxtl = 4,
789 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
790 c48fcb47 blueswir1
    },
791 c48fcb47 blueswir1
    {
792 c48fcb47 blueswir1
        .name = "Fujitsu Sparc64 III",
793 c19148bd blueswir1
        .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
794 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
795 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
796 1a14026e blueswir1
        .nwindows = 5,
797 c19148bd blueswir1
        .maxtl = 4,
798 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
799 c48fcb47 blueswir1
    },
800 c48fcb47 blueswir1
    {
801 c48fcb47 blueswir1
        .name = "Fujitsu Sparc64 IV",
802 c19148bd blueswir1
        .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
803 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
804 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
805 1a14026e blueswir1
        .nwindows = 8,
806 c19148bd blueswir1
        .maxtl = 5,
807 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
808 c48fcb47 blueswir1
    },
809 c48fcb47 blueswir1
    {
810 c48fcb47 blueswir1
        .name = "Fujitsu Sparc64 V",
811 c19148bd blueswir1
        .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
812 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
813 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
814 1a14026e blueswir1
        .nwindows = 8,
815 c19148bd blueswir1
        .maxtl = 5,
816 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
817 c48fcb47 blueswir1
    },
818 c48fcb47 blueswir1
    {
819 c48fcb47 blueswir1
        .name = "TI UltraSparc I",
820 c19148bd blueswir1
        .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
821 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
822 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
823 1a14026e blueswir1
        .nwindows = 8,
824 c19148bd blueswir1
        .maxtl = 5,
825 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
826 c48fcb47 blueswir1
    },
827 c48fcb47 blueswir1
    {
828 c48fcb47 blueswir1
        .name = "TI UltraSparc II",
829 c19148bd blueswir1
        .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
830 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
831 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
832 1a14026e blueswir1
        .nwindows = 8,
833 c19148bd blueswir1
        .maxtl = 5,
834 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
835 c48fcb47 blueswir1
    },
836 c48fcb47 blueswir1
    {
837 c48fcb47 blueswir1
        .name = "TI UltraSparc IIi",
838 c19148bd blueswir1
        .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
839 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
840 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
841 1a14026e blueswir1
        .nwindows = 8,
842 c19148bd blueswir1
        .maxtl = 5,
843 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
844 c48fcb47 blueswir1
    },
845 c48fcb47 blueswir1
    {
846 c48fcb47 blueswir1
        .name = "TI UltraSparc IIe",
847 c19148bd blueswir1
        .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
848 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
849 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
850 1a14026e blueswir1
        .nwindows = 8,
851 c19148bd blueswir1
        .maxtl = 5,
852 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
853 c48fcb47 blueswir1
    },
854 c48fcb47 blueswir1
    {
855 c48fcb47 blueswir1
        .name = "Sun UltraSparc III",
856 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
857 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
858 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
859 1a14026e blueswir1
        .nwindows = 8,
860 c19148bd blueswir1
        .maxtl = 5,
861 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
862 c48fcb47 blueswir1
    },
863 c48fcb47 blueswir1
    {
864 c48fcb47 blueswir1
        .name = "Sun UltraSparc III Cu",
865 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
866 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
867 fb79ceb9 blueswir1
        .mmu_version = mmu_us_3,
868 1a14026e blueswir1
        .nwindows = 8,
869 c19148bd blueswir1
        .maxtl = 5,
870 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
871 c48fcb47 blueswir1
    },
872 c48fcb47 blueswir1
    {
873 c48fcb47 blueswir1
        .name = "Sun UltraSparc IIIi",
874 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
875 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
876 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
877 1a14026e blueswir1
        .nwindows = 8,
878 c19148bd blueswir1
        .maxtl = 5,
879 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
880 c48fcb47 blueswir1
    },
881 c48fcb47 blueswir1
    {
882 c48fcb47 blueswir1
        .name = "Sun UltraSparc IV",
883 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
884 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
885 fb79ceb9 blueswir1
        .mmu_version = mmu_us_4,
886 1a14026e blueswir1
        .nwindows = 8,
887 c19148bd blueswir1
        .maxtl = 5,
888 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
889 c48fcb47 blueswir1
    },
890 c48fcb47 blueswir1
    {
891 c48fcb47 blueswir1
        .name = "Sun UltraSparc IV+",
892 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
893 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
894 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
895 1a14026e blueswir1
        .nwindows = 8,
896 c19148bd blueswir1
        .maxtl = 5,
897 fb79ceb9 blueswir1
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
898 c48fcb47 blueswir1
    },
899 c48fcb47 blueswir1
    {
900 c48fcb47 blueswir1
        .name = "Sun UltraSparc IIIi+",
901 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
902 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
903 fb79ceb9 blueswir1
        .mmu_version = mmu_us_3,
904 1a14026e blueswir1
        .nwindows = 8,
905 c19148bd blueswir1
        .maxtl = 5,
906 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
907 c48fcb47 blueswir1
    },
908 c48fcb47 blueswir1
    {
909 c7ba218d blueswir1
        .name = "Sun UltraSparc T1",
910 c7ba218d blueswir1
        // defined in sparc_ifu_fdp.v and ctu.h
911 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
912 c7ba218d blueswir1
        .fpu_version = 0x00000000,
913 c7ba218d blueswir1
        .mmu_version = mmu_sun4v,
914 c7ba218d blueswir1
        .nwindows = 8,
915 c19148bd blueswir1
        .maxtl = 6,
916 c7ba218d blueswir1
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
917 c7ba218d blueswir1
        | CPU_FEATURE_GL,
918 c7ba218d blueswir1
    },
919 c7ba218d blueswir1
    {
920 c7ba218d blueswir1
        .name = "Sun UltraSparc T2",
921 c7ba218d blueswir1
        // defined in tlu_asi_ctl.v and n2_revid_cust.v
922 c19148bd blueswir1
        .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
923 c7ba218d blueswir1
        .fpu_version = 0x00000000,
924 c7ba218d blueswir1
        .mmu_version = mmu_sun4v,
925 c7ba218d blueswir1
        .nwindows = 8,
926 c19148bd blueswir1
        .maxtl = 6,
927 c7ba218d blueswir1
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
928 c7ba218d blueswir1
        | CPU_FEATURE_GL,
929 c7ba218d blueswir1
    },
930 c7ba218d blueswir1
    {
931 c48fcb47 blueswir1
        .name = "NEC UltraSparc I",
932 c19148bd blueswir1
        .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
933 c48fcb47 blueswir1
        .fpu_version = 0x00000000,
934 fb79ceb9 blueswir1
        .mmu_version = mmu_us_12,
935 1a14026e blueswir1
        .nwindows = 8,
936 c19148bd blueswir1
        .maxtl = 5,
937 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
938 c48fcb47 blueswir1
    },
939 c48fcb47 blueswir1
#else
940 c48fcb47 blueswir1
    {
941 c48fcb47 blueswir1
        .name = "Fujitsu MB86900",
942 c48fcb47 blueswir1
        .iu_version = 0x00 << 24, /* Impl 0, ver 0 */
943 c48fcb47 blueswir1
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
944 c48fcb47 blueswir1
        .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */
945 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
946 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
947 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
948 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
949 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
950 1a14026e blueswir1
        .nwindows = 7,
951 e30b4678 blueswir1
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_FSMULD,
952 c48fcb47 blueswir1
    },
953 c48fcb47 blueswir1
    {
954 c48fcb47 blueswir1
        .name = "Fujitsu MB86904",
955 c48fcb47 blueswir1
        .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
956 c48fcb47 blueswir1
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
957 c48fcb47 blueswir1
        .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
958 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
959 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x00ffffc0,
960 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x000000ff,
961 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0x00016fff,
962 c48fcb47 blueswir1
        .mmu_trcr_mask = 0x00ffffff,
963 1a14026e blueswir1
        .nwindows = 8,
964 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
965 c48fcb47 blueswir1
    },
966 c48fcb47 blueswir1
    {
967 c48fcb47 blueswir1
        .name = "Fujitsu MB86907",
968 c48fcb47 blueswir1
        .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
969 c48fcb47 blueswir1
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
970 c48fcb47 blueswir1
        .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
971 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
972 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0xffffffc0,
973 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x000000ff,
974 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0x00016fff,
975 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
976 1a14026e blueswir1
        .nwindows = 8,
977 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
978 c48fcb47 blueswir1
    },
979 c48fcb47 blueswir1
    {
980 c48fcb47 blueswir1
        .name = "LSI L64811",
981 c48fcb47 blueswir1
        .iu_version = 0x10 << 24, /* Impl 1, ver 0 */
982 c48fcb47 blueswir1
        .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */
983 c48fcb47 blueswir1
        .mmu_version = 0x10 << 24,
984 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
985 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
986 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
987 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
988 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
989 1a14026e blueswir1
        .nwindows = 8,
990 e30b4678 blueswir1
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
991 e30b4678 blueswir1
        CPU_FEATURE_FSMULD,
992 c48fcb47 blueswir1
    },
993 c48fcb47 blueswir1
    {
994 c48fcb47 blueswir1
        .name = "Cypress CY7C601",
995 c48fcb47 blueswir1
        .iu_version = 0x11 << 24, /* Impl 1, ver 1 */
996 c48fcb47 blueswir1
        .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
997 c48fcb47 blueswir1
        .mmu_version = 0x10 << 24,
998 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
999 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1000 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1001 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1002 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1003 1a14026e blueswir1
        .nwindows = 8,
1004 e30b4678 blueswir1
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
1005 e30b4678 blueswir1
        CPU_FEATURE_FSMULD,
1006 c48fcb47 blueswir1
    },
1007 c48fcb47 blueswir1
    {
1008 c48fcb47 blueswir1
        .name = "Cypress CY7C611",
1009 c48fcb47 blueswir1
        .iu_version = 0x13 << 24, /* Impl 1, ver 3 */
1010 c48fcb47 blueswir1
        .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
1011 c48fcb47 blueswir1
        .mmu_version = 0x10 << 24,
1012 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1013 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1014 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1015 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1016 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1017 1a14026e blueswir1
        .nwindows = 8,
1018 e30b4678 blueswir1
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
1019 e30b4678 blueswir1
        CPU_FEATURE_FSMULD,
1020 c48fcb47 blueswir1
    },
1021 c48fcb47 blueswir1
    {
1022 c48fcb47 blueswir1
        .name = "TI MicroSparc I",
1023 c48fcb47 blueswir1
        .iu_version = 0x41000000,
1024 c48fcb47 blueswir1
        .fpu_version = 4 << 17,
1025 c48fcb47 blueswir1
        .mmu_version = 0x41000000,
1026 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1027 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1028 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1029 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0x00016fff,
1030 c48fcb47 blueswir1
        .mmu_trcr_mask = 0x0000003f,
1031 1a14026e blueswir1
        .nwindows = 7,
1032 e30b4678 blueswir1
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL |
1033 e30b4678 blueswir1
        CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT |
1034 e30b4678 blueswir1
        CPU_FEATURE_FMUL,
1035 c48fcb47 blueswir1
    },
1036 c48fcb47 blueswir1
    {
1037 c48fcb47 blueswir1
        .name = "TI MicroSparc II",
1038 c48fcb47 blueswir1
        .iu_version = 0x42000000,
1039 c48fcb47 blueswir1
        .fpu_version = 4 << 17,
1040 c48fcb47 blueswir1
        .mmu_version = 0x02000000,
1041 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1042 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x00ffffc0,
1043 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x000000ff,
1044 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0x00016fff,
1045 c48fcb47 blueswir1
        .mmu_trcr_mask = 0x00ffffff,
1046 1a14026e blueswir1
        .nwindows = 8,
1047 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1048 c48fcb47 blueswir1
    },
1049 c48fcb47 blueswir1
    {
1050 c48fcb47 blueswir1
        .name = "TI MicroSparc IIep",
1051 c48fcb47 blueswir1
        .iu_version = 0x42000000,
1052 c48fcb47 blueswir1
        .fpu_version = 4 << 17,
1053 c48fcb47 blueswir1
        .mmu_version = 0x04000000,
1054 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1055 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x00ffffc0,
1056 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x000000ff,
1057 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0x00016bff,
1058 c48fcb47 blueswir1
        .mmu_trcr_mask = 0x00ffffff,
1059 1a14026e blueswir1
        .nwindows = 8,
1060 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1061 c48fcb47 blueswir1
    },
1062 c48fcb47 blueswir1
    {
1063 b5154bde blueswir1
        .name = "TI SuperSparc 40", // STP1020NPGA
1064 963262de blueswir1
        .iu_version = 0x41000000, // SuperSPARC 2.x
1065 b5154bde blueswir1
        .fpu_version = 0 << 17,
1066 963262de blueswir1
        .mmu_version = 0x00000800, // SuperSPARC 2.x, no MXCC
1067 b5154bde blueswir1
        .mmu_bm = 0x00002000,
1068 b5154bde blueswir1
        .mmu_ctpr_mask = 0xffffffc0,
1069 b5154bde blueswir1
        .mmu_cxr_mask = 0x0000ffff,
1070 b5154bde blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1071 b5154bde blueswir1
        .mmu_trcr_mask = 0xffffffff,
1072 1a14026e blueswir1
        .nwindows = 8,
1073 b5154bde blueswir1
        .features = CPU_DEFAULT_FEATURES,
1074 b5154bde blueswir1
    },
1075 b5154bde blueswir1
    {
1076 b5154bde blueswir1
        .name = "TI SuperSparc 50", // STP1020PGA
1077 963262de blueswir1
        .iu_version = 0x40000000, // SuperSPARC 3.x
1078 b5154bde blueswir1
        .fpu_version = 0 << 17,
1079 963262de blueswir1
        .mmu_version = 0x01000800, // SuperSPARC 3.x, no MXCC
1080 b5154bde blueswir1
        .mmu_bm = 0x00002000,
1081 b5154bde blueswir1
        .mmu_ctpr_mask = 0xffffffc0,
1082 b5154bde blueswir1
        .mmu_cxr_mask = 0x0000ffff,
1083 b5154bde blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1084 b5154bde blueswir1
        .mmu_trcr_mask = 0xffffffff,
1085 1a14026e blueswir1
        .nwindows = 8,
1086 b5154bde blueswir1
        .features = CPU_DEFAULT_FEATURES,
1087 b5154bde blueswir1
    },
1088 b5154bde blueswir1
    {
1089 c48fcb47 blueswir1
        .name = "TI SuperSparc 51",
1090 963262de blueswir1
        .iu_version = 0x40000000, // SuperSPARC 3.x
1091 c48fcb47 blueswir1
        .fpu_version = 0 << 17,
1092 963262de blueswir1
        .mmu_version = 0x01000000, // SuperSPARC 3.x, MXCC
1093 c48fcb47 blueswir1
        .mmu_bm = 0x00002000,
1094 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0xffffffc0,
1095 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000ffff,
1096 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1097 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1098 963262de blueswir1
        .mxcc_version = 0x00000104,
1099 1a14026e blueswir1
        .nwindows = 8,
1100 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1101 c48fcb47 blueswir1
    },
1102 c48fcb47 blueswir1
    {
1103 b5154bde blueswir1
        .name = "TI SuperSparc 60", // STP1020APGA
1104 963262de blueswir1
        .iu_version = 0x40000000, // SuperSPARC 3.x
1105 b5154bde blueswir1
        .fpu_version = 0 << 17,
1106 963262de blueswir1
        .mmu_version = 0x01000800, // SuperSPARC 3.x, no MXCC
1107 b5154bde blueswir1
        .mmu_bm = 0x00002000,
1108 b5154bde blueswir1
        .mmu_ctpr_mask = 0xffffffc0,
1109 b5154bde blueswir1
        .mmu_cxr_mask = 0x0000ffff,
1110 b5154bde blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1111 b5154bde blueswir1
        .mmu_trcr_mask = 0xffffffff,
1112 1a14026e blueswir1
        .nwindows = 8,
1113 b5154bde blueswir1
        .features = CPU_DEFAULT_FEATURES,
1114 b5154bde blueswir1
    },
1115 b5154bde blueswir1
    {
1116 c48fcb47 blueswir1
        .name = "TI SuperSparc 61",
1117 963262de blueswir1
        .iu_version = 0x44000000, // SuperSPARC 3.x
1118 c48fcb47 blueswir1
        .fpu_version = 0 << 17,
1119 963262de blueswir1
        .mmu_version = 0x01000000, // SuperSPARC 3.x, MXCC
1120 963262de blueswir1
        .mmu_bm = 0x00002000,
1121 963262de blueswir1
        .mmu_ctpr_mask = 0xffffffc0,
1122 963262de blueswir1
        .mmu_cxr_mask = 0x0000ffff,
1123 963262de blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1124 963262de blueswir1
        .mmu_trcr_mask = 0xffffffff,
1125 963262de blueswir1
        .mxcc_version = 0x00000104,
1126 963262de blueswir1
        .nwindows = 8,
1127 963262de blueswir1
        .features = CPU_DEFAULT_FEATURES,
1128 963262de blueswir1
    },
1129 963262de blueswir1
    {
1130 963262de blueswir1
        .name = "TI SuperSparc II",
1131 963262de blueswir1
        .iu_version = 0x40000000, // SuperSPARC II 1.x
1132 963262de blueswir1
        .fpu_version = 0 << 17,
1133 963262de blueswir1
        .mmu_version = 0x08000000, // SuperSPARC II 1.x, MXCC
1134 c48fcb47 blueswir1
        .mmu_bm = 0x00002000,
1135 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0xffffffc0,
1136 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000ffff,
1137 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1138 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1139 963262de blueswir1
        .mxcc_version = 0x00000104,
1140 1a14026e blueswir1
        .nwindows = 8,
1141 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1142 c48fcb47 blueswir1
    },
1143 c48fcb47 blueswir1
    {
1144 c48fcb47 blueswir1
        .name = "Ross RT625",
1145 c48fcb47 blueswir1
        .iu_version = 0x1e000000,
1146 c48fcb47 blueswir1
        .fpu_version = 1 << 17,
1147 c48fcb47 blueswir1
        .mmu_version = 0x1e000000,
1148 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1149 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1150 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1151 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1152 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1153 1a14026e blueswir1
        .nwindows = 8,
1154 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1155 c48fcb47 blueswir1
    },
1156 c48fcb47 blueswir1
    {
1157 c48fcb47 blueswir1
        .name = "Ross RT620",
1158 c48fcb47 blueswir1
        .iu_version = 0x1f000000,
1159 c48fcb47 blueswir1
        .fpu_version = 1 << 17,
1160 c48fcb47 blueswir1
        .mmu_version = 0x1f000000,
1161 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1162 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1163 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1164 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1165 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1166 1a14026e blueswir1
        .nwindows = 8,
1167 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1168 c48fcb47 blueswir1
    },
1169 c48fcb47 blueswir1
    {
1170 c48fcb47 blueswir1
        .name = "BIT B5010",
1171 c48fcb47 blueswir1
        .iu_version = 0x20000000,
1172 c48fcb47 blueswir1
        .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */
1173 c48fcb47 blueswir1
        .mmu_version = 0x20000000,
1174 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1175 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1176 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1177 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1178 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1179 1a14026e blueswir1
        .nwindows = 8,
1180 e30b4678 blueswir1
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
1181 e30b4678 blueswir1
        CPU_FEATURE_FSMULD,
1182 c48fcb47 blueswir1
    },
1183 c48fcb47 blueswir1
    {
1184 c48fcb47 blueswir1
        .name = "Matsushita MN10501",
1185 c48fcb47 blueswir1
        .iu_version = 0x50000000,
1186 c48fcb47 blueswir1
        .fpu_version = 0 << 17,
1187 c48fcb47 blueswir1
        .mmu_version = 0x50000000,
1188 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1189 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1190 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1191 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1192 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1193 1a14026e blueswir1
        .nwindows = 8,
1194 e30b4678 blueswir1
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_MUL | CPU_FEATURE_FSQRT |
1195 e30b4678 blueswir1
        CPU_FEATURE_FSMULD,
1196 c48fcb47 blueswir1
    },
1197 c48fcb47 blueswir1
    {
1198 c48fcb47 blueswir1
        .name = "Weitek W8601",
1199 c48fcb47 blueswir1
        .iu_version = 0x90 << 24, /* Impl 9, ver 0 */
1200 c48fcb47 blueswir1
        .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
1201 c48fcb47 blueswir1
        .mmu_version = 0x10 << 24,
1202 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1203 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1204 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1205 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1206 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1207 1a14026e blueswir1
        .nwindows = 8,
1208 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1209 c48fcb47 blueswir1
    },
1210 c48fcb47 blueswir1
    {
1211 c48fcb47 blueswir1
        .name = "LEON2",
1212 c48fcb47 blueswir1
        .iu_version = 0xf2000000,
1213 c48fcb47 blueswir1
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
1214 c48fcb47 blueswir1
        .mmu_version = 0xf2000000,
1215 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1216 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1217 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1218 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1219 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1220 1a14026e blueswir1
        .nwindows = 8,
1221 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1222 c48fcb47 blueswir1
    },
1223 c48fcb47 blueswir1
    {
1224 c48fcb47 blueswir1
        .name = "LEON3",
1225 c48fcb47 blueswir1
        .iu_version = 0xf3000000,
1226 c48fcb47 blueswir1
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
1227 c48fcb47 blueswir1
        .mmu_version = 0xf3000000,
1228 c48fcb47 blueswir1
        .mmu_bm = 0x00004000,
1229 c48fcb47 blueswir1
        .mmu_ctpr_mask = 0x007ffff0,
1230 c48fcb47 blueswir1
        .mmu_cxr_mask = 0x0000003f,
1231 c48fcb47 blueswir1
        .mmu_sfsr_mask = 0xffffffff,
1232 c48fcb47 blueswir1
        .mmu_trcr_mask = 0xffffffff,
1233 1a14026e blueswir1
        .nwindows = 8,
1234 64a88d5d blueswir1
        .features = CPU_DEFAULT_FEATURES,
1235 c48fcb47 blueswir1
    },
1236 c48fcb47 blueswir1
#endif
1237 c48fcb47 blueswir1
};
1238 c48fcb47 blueswir1
1239 64a88d5d blueswir1
static const char * const feature_name[] = {
1240 64a88d5d blueswir1
    "float",
1241 64a88d5d blueswir1
    "float128",
1242 64a88d5d blueswir1
    "swap",
1243 64a88d5d blueswir1
    "mul",
1244 64a88d5d blueswir1
    "div",
1245 64a88d5d blueswir1
    "flush",
1246 64a88d5d blueswir1
    "fsqrt",
1247 64a88d5d blueswir1
    "fmul",
1248 64a88d5d blueswir1
    "vis1",
1249 64a88d5d blueswir1
    "vis2",
1250 e30b4678 blueswir1
    "fsmuld",
1251 fb79ceb9 blueswir1
    "hypv",
1252 fb79ceb9 blueswir1
    "cmt",
1253 fb79ceb9 blueswir1
    "gl",
1254 64a88d5d blueswir1
};
1255 64a88d5d blueswir1
1256 64a88d5d blueswir1
static void print_features(FILE *f,
1257 64a88d5d blueswir1
                           int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
1258 64a88d5d blueswir1
                           uint32_t features, const char *prefix)
1259 c48fcb47 blueswir1
{
1260 c48fcb47 blueswir1
    unsigned int i;
1261 c48fcb47 blueswir1
1262 64a88d5d blueswir1
    for (i = 0; i < ARRAY_SIZE(feature_name); i++)
1263 64a88d5d blueswir1
        if (feature_name[i] && (features & (1 << i))) {
1264 64a88d5d blueswir1
            if (prefix)
1265 64a88d5d blueswir1
                (*cpu_fprintf)(f, "%s", prefix);
1266 64a88d5d blueswir1
            (*cpu_fprintf)(f, "%s ", feature_name[i]);
1267 64a88d5d blueswir1
        }
1268 64a88d5d blueswir1
}
1269 64a88d5d blueswir1
1270 64a88d5d blueswir1
static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features)
1271 64a88d5d blueswir1
{
1272 64a88d5d blueswir1
    unsigned int i;
1273 64a88d5d blueswir1
1274 64a88d5d blueswir1
    for (i = 0; i < ARRAY_SIZE(feature_name); i++)
1275 64a88d5d blueswir1
        if (feature_name[i] && !strcmp(flagname, feature_name[i])) {
1276 64a88d5d blueswir1
            *features |= 1 << i;
1277 64a88d5d blueswir1
            return;
1278 64a88d5d blueswir1
        }
1279 64a88d5d blueswir1
    fprintf(stderr, "CPU feature %s not found\n", flagname);
1280 64a88d5d blueswir1
}
1281 64a88d5d blueswir1
1282 22548760 blueswir1
static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model)
1283 64a88d5d blueswir1
{
1284 64a88d5d blueswir1
    unsigned int i;
1285 64a88d5d blueswir1
    const sparc_def_t *def = NULL;
1286 64a88d5d blueswir1
    char *s = strdup(cpu_model);
1287 64a88d5d blueswir1
    char *featurestr, *name = strtok(s, ",");
1288 64a88d5d blueswir1
    uint32_t plus_features = 0;
1289 64a88d5d blueswir1
    uint32_t minus_features = 0;
1290 64a88d5d blueswir1
    long long iu_version;
1291 1a14026e blueswir1
    uint32_t fpu_version, mmu_version, nwindows;
1292 64a88d5d blueswir1
1293 b1503cda malc
    for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
1294 c48fcb47 blueswir1
        if (strcasecmp(name, sparc_defs[i].name) == 0) {
1295 64a88d5d blueswir1
            def = &sparc_defs[i];
1296 c48fcb47 blueswir1
        }
1297 c48fcb47 blueswir1
    }
1298 64a88d5d blueswir1
    if (!def)
1299 64a88d5d blueswir1
        goto error;
1300 64a88d5d blueswir1
    memcpy(cpu_def, def, sizeof(*def));
1301 64a88d5d blueswir1
1302 64a88d5d blueswir1
    featurestr = strtok(NULL, ",");
1303 64a88d5d blueswir1
    while (featurestr) {
1304 64a88d5d blueswir1
        char *val;
1305 64a88d5d blueswir1
1306 64a88d5d blueswir1
        if (featurestr[0] == '+') {
1307 64a88d5d blueswir1
            add_flagname_to_bitmaps(featurestr + 1, &plus_features);
1308 64a88d5d blueswir1
        } else if (featurestr[0] == '-') {
1309 64a88d5d blueswir1
            add_flagname_to_bitmaps(featurestr + 1, &minus_features);
1310 64a88d5d blueswir1
        } else if ((val = strchr(featurestr, '='))) {
1311 64a88d5d blueswir1
            *val = 0; val++;
1312 64a88d5d blueswir1
            if (!strcmp(featurestr, "iu_version")) {
1313 64a88d5d blueswir1
                char *err;
1314 64a88d5d blueswir1
1315 64a88d5d blueswir1
                iu_version = strtoll(val, &err, 0);
1316 64a88d5d blueswir1
                if (!*val || *err) {
1317 64a88d5d blueswir1
                    fprintf(stderr, "bad numerical value %s\n", val);
1318 64a88d5d blueswir1
                    goto error;
1319 64a88d5d blueswir1
                }
1320 64a88d5d blueswir1
                cpu_def->iu_version = iu_version;
1321 64a88d5d blueswir1
#ifdef DEBUG_FEATURES
1322 64a88d5d blueswir1
                fprintf(stderr, "iu_version %llx\n", iu_version);
1323 64a88d5d blueswir1
#endif
1324 64a88d5d blueswir1
            } else if (!strcmp(featurestr, "fpu_version")) {
1325 64a88d5d blueswir1
                char *err;
1326 64a88d5d blueswir1
1327 64a88d5d blueswir1
                fpu_version = strtol(val, &err, 0);
1328 64a88d5d blueswir1
                if (!*val || *err) {
1329 64a88d5d blueswir1
                    fprintf(stderr, "bad numerical value %s\n", val);
1330 64a88d5d blueswir1
                    goto error;
1331 64a88d5d blueswir1
                }
1332 64a88d5d blueswir1
                cpu_def->fpu_version = fpu_version;
1333 64a88d5d blueswir1
#ifdef DEBUG_FEATURES
1334 0bf9e31a Blue Swirl
                fprintf(stderr, "fpu_version %x\n", fpu_version);
1335 64a88d5d blueswir1
#endif
1336 64a88d5d blueswir1
            } else if (!strcmp(featurestr, "mmu_version")) {
1337 64a88d5d blueswir1
                char *err;
1338 64a88d5d blueswir1
1339 64a88d5d blueswir1
                mmu_version = strtol(val, &err, 0);
1340 64a88d5d blueswir1
                if (!*val || *err) {
1341 64a88d5d blueswir1
                    fprintf(stderr, "bad numerical value %s\n", val);
1342 64a88d5d blueswir1
                    goto error;
1343 64a88d5d blueswir1
                }
1344 64a88d5d blueswir1
                cpu_def->mmu_version = mmu_version;
1345 64a88d5d blueswir1
#ifdef DEBUG_FEATURES
1346 0bf9e31a Blue Swirl
                fprintf(stderr, "mmu_version %x\n", mmu_version);
1347 64a88d5d blueswir1
#endif
1348 1a14026e blueswir1
            } else if (!strcmp(featurestr, "nwindows")) {
1349 1a14026e blueswir1
                char *err;
1350 1a14026e blueswir1
1351 1a14026e blueswir1
                nwindows = strtol(val, &err, 0);
1352 1a14026e blueswir1
                if (!*val || *err || nwindows > MAX_NWINDOWS ||
1353 1a14026e blueswir1
                    nwindows < MIN_NWINDOWS) {
1354 1a14026e blueswir1
                    fprintf(stderr, "bad numerical value %s\n", val);
1355 1a14026e blueswir1
                    goto error;
1356 1a14026e blueswir1
                }
1357 1a14026e blueswir1
                cpu_def->nwindows = nwindows;
1358 1a14026e blueswir1
#ifdef DEBUG_FEATURES
1359 1a14026e blueswir1
                fprintf(stderr, "nwindows %d\n", nwindows);
1360 1a14026e blueswir1
#endif
1361 64a88d5d blueswir1
            } else {
1362 64a88d5d blueswir1
                fprintf(stderr, "unrecognized feature %s\n", featurestr);
1363 64a88d5d blueswir1
                goto error;
1364 64a88d5d blueswir1
            }
1365 64a88d5d blueswir1
        } else {
1366 77f193da blueswir1
            fprintf(stderr, "feature string `%s' not in format "
1367 77f193da blueswir1
                    "(+feature|-feature|feature=xyz)\n", featurestr);
1368 64a88d5d blueswir1
            goto error;
1369 64a88d5d blueswir1
        }
1370 64a88d5d blueswir1
        featurestr = strtok(NULL, ",");
1371 64a88d5d blueswir1
    }
1372 64a88d5d blueswir1
    cpu_def->features |= plus_features;
1373 64a88d5d blueswir1
    cpu_def->features &= ~minus_features;
1374 64a88d5d blueswir1
#ifdef DEBUG_FEATURES
1375 64a88d5d blueswir1
    print_features(stderr, fprintf, cpu_def->features, NULL);
1376 64a88d5d blueswir1
#endif
1377 64a88d5d blueswir1
    free(s);
1378 64a88d5d blueswir1
    return 0;
1379 64a88d5d blueswir1
1380 64a88d5d blueswir1
 error:
1381 64a88d5d blueswir1
    free(s);
1382 64a88d5d blueswir1
    return -1;
1383 c48fcb47 blueswir1
}
1384 c48fcb47 blueswir1
1385 77f193da blueswir1
void sparc_cpu_list(FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
1386 c48fcb47 blueswir1
{
1387 c48fcb47 blueswir1
    unsigned int i;
1388 c48fcb47 blueswir1
1389 b1503cda malc
    for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
1390 1a14026e blueswir1
        (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x NWINS %d ",
1391 c48fcb47 blueswir1
                       sparc_defs[i].name,
1392 c48fcb47 blueswir1
                       sparc_defs[i].iu_version,
1393 c48fcb47 blueswir1
                       sparc_defs[i].fpu_version,
1394 1a14026e blueswir1
                       sparc_defs[i].mmu_version,
1395 1a14026e blueswir1
                       sparc_defs[i].nwindows);
1396 77f193da blueswir1
        print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES &
1397 77f193da blueswir1
                       ~sparc_defs[i].features, "-");
1398 77f193da blueswir1
        print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES &
1399 77f193da blueswir1
                       sparc_defs[i].features, "+");
1400 64a88d5d blueswir1
        (*cpu_fprintf)(f, "\n");
1401 c48fcb47 blueswir1
    }
1402 f76981b1 blueswir1
    (*cpu_fprintf)(f, "Default CPU feature flags (use '-' to remove): ");
1403 f76981b1 blueswir1
    print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES, NULL);
1404 64a88d5d blueswir1
    (*cpu_fprintf)(f, "\n");
1405 f76981b1 blueswir1
    (*cpu_fprintf)(f, "Available CPU feature flags (use '+' to add): ");
1406 f76981b1 blueswir1
    print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES, NULL);
1407 f76981b1 blueswir1
    (*cpu_fprintf)(f, "\n");
1408 f76981b1 blueswir1
    (*cpu_fprintf)(f, "Numerical features (use '=' to set): iu_version "
1409 f76981b1 blueswir1
                   "fpu_version mmu_version nwindows\n");
1410 c48fcb47 blueswir1
}
1411 c48fcb47 blueswir1
1412 43bb98bf Blue Swirl
static void cpu_print_cc(FILE *f,
1413 43bb98bf Blue Swirl
                         int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
1414 43bb98bf Blue Swirl
                         uint32_t cc)
1415 43bb98bf Blue Swirl
{
1416 43bb98bf Blue Swirl
    cpu_fprintf(f, "%c%c%c%c", cc & PSR_NEG? 'N' : '-',
1417 43bb98bf Blue Swirl
                cc & PSR_ZERO? 'Z' : '-', cc & PSR_OVF? 'V' : '-',
1418 43bb98bf Blue Swirl
                cc & PSR_CARRY? 'C' : '-');
1419 43bb98bf Blue Swirl
}
1420 43bb98bf Blue Swirl
1421 43bb98bf Blue Swirl
#ifdef TARGET_SPARC64
1422 43bb98bf Blue Swirl
#define REGS_PER_LINE 4
1423 43bb98bf Blue Swirl
#else
1424 43bb98bf Blue Swirl
#define REGS_PER_LINE 8
1425 43bb98bf Blue Swirl
#endif
1426 43bb98bf Blue Swirl
1427 c48fcb47 blueswir1
void cpu_dump_state(CPUState *env, FILE *f,
1428 c48fcb47 blueswir1
                    int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
1429 c48fcb47 blueswir1
                    int flags)
1430 c48fcb47 blueswir1
{
1431 c48fcb47 blueswir1
    int i, x;
1432 c48fcb47 blueswir1
1433 77f193da blueswir1
    cpu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
1434 77f193da blueswir1
                env->npc);
1435 c48fcb47 blueswir1
    cpu_fprintf(f, "General Registers:\n");
1436 43bb98bf Blue Swirl
1437 43bb98bf Blue Swirl
    for (i = 0; i < 8; i++) {
1438 43bb98bf Blue Swirl
        if (i % REGS_PER_LINE == 0) {
1439 43bb98bf Blue Swirl
            cpu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
1440 43bb98bf Blue Swirl
        }
1441 43bb98bf Blue Swirl
        cpu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
1442 43bb98bf Blue Swirl
        if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
1443 43bb98bf Blue Swirl
            cpu_fprintf(f, "\n");
1444 43bb98bf Blue Swirl
        }
1445 43bb98bf Blue Swirl
    }
1446 c48fcb47 blueswir1
    cpu_fprintf(f, "\nCurrent Register Window:\n");
1447 c48fcb47 blueswir1
    for (x = 0; x < 3; x++) {
1448 43bb98bf Blue Swirl
        for (i = 0; i < 8; i++) {
1449 43bb98bf Blue Swirl
            if (i % REGS_PER_LINE == 0) {
1450 43bb98bf Blue Swirl
                cpu_fprintf(f, "%%%c%d-%d: ",
1451 43bb98bf Blue Swirl
                            x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
1452 43bb98bf Blue Swirl
                            i, i + REGS_PER_LINE - 1);
1453 43bb98bf Blue Swirl
            }
1454 43bb98bf Blue Swirl
            cpu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
1455 43bb98bf Blue Swirl
            if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
1456 43bb98bf Blue Swirl
                cpu_fprintf(f, "\n");
1457 43bb98bf Blue Swirl
            }
1458 43bb98bf Blue Swirl
        }
1459 c48fcb47 blueswir1
    }
1460 c48fcb47 blueswir1
    cpu_fprintf(f, "\nFloating Point Registers:\n");
1461 43bb98bf Blue Swirl
    for (i = 0; i < TARGET_FPREGS; i++) {
1462 c48fcb47 blueswir1
        if ((i & 3) == 0)
1463 c48fcb47 blueswir1
            cpu_fprintf(f, "%%f%02d:", i);
1464 a37ee56c blueswir1
        cpu_fprintf(f, " %016f", *(float *)&env->fpr[i]);
1465 c48fcb47 blueswir1
        if ((i & 3) == 3)
1466 c48fcb47 blueswir1
            cpu_fprintf(f, "\n");
1467 c48fcb47 blueswir1
    }
1468 c48fcb47 blueswir1
#ifdef TARGET_SPARC64
1469 43bb98bf Blue Swirl
    cpu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
1470 43bb98bf Blue Swirl
                GET_CCR(env));
1471 43bb98bf Blue Swirl
    cpu_print_cc(f, cpu_fprintf, GET_CCR(env) << PSR_CARRY_SHIFT);
1472 43bb98bf Blue Swirl
    cpu_fprintf(f, " xcc: ");
1473 43bb98bf Blue Swirl
    cpu_print_cc(f, cpu_fprintf, GET_CCR(env) << (PSR_CARRY_SHIFT - 4));
1474 43bb98bf Blue Swirl
    cpu_fprintf(f, ") asi: %02x tl: %d pil: %x\n", env->asi, env->tl,
1475 43bb98bf Blue Swirl
                env->psrpil);
1476 43bb98bf Blue Swirl
    cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
1477 43bb98bf Blue Swirl
                "cleanwin: %d cwp: %d\n",
1478 c48fcb47 blueswir1
                env->cansave, env->canrestore, env->otherwin, env->wstate,
1479 1a14026e blueswir1
                env->cleanwin, env->nwindows - 1 - env->cwp);
1480 43bb98bf Blue Swirl
    cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: "
1481 43bb98bf Blue Swirl
                TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs);
1482 c48fcb47 blueswir1
#else
1483 43bb98bf Blue Swirl
    cpu_fprintf(f, "psr: %08x (icc: ", GET_PSR(env));
1484 43bb98bf Blue Swirl
    cpu_print_cc(f, cpu_fprintf, GET_PSR(env));
1485 43bb98bf Blue Swirl
    cpu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs? 'S' : '-',
1486 43bb98bf Blue Swirl
                env->psrps? 'P' : '-', env->psret? 'E' : '-',
1487 43bb98bf Blue Swirl
                env->wim);
1488 43bb98bf Blue Swirl
    cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
1489 43bb98bf Blue Swirl
                env->fsr, env->y);
1490 c48fcb47 blueswir1
#endif
1491 c48fcb47 blueswir1
}