Statistics
| Branch: | Revision:

root / target-sparc / cpu.c @ 5b50e790

History | View | Annotate | Download (24.9 kB)

1 ab3b491f Blue Swirl
/*
2 ab3b491f Blue Swirl
 * Sparc CPU init helpers
3 ab3b491f Blue Swirl
 *
4 ab3b491f Blue Swirl
 *  Copyright (c) 2003-2005 Fabrice Bellard
5 ab3b491f Blue Swirl
 *
6 ab3b491f Blue Swirl
 * This library is free software; you can redistribute it and/or
7 ab3b491f Blue Swirl
 * modify it under the terms of the GNU Lesser General Public
8 ab3b491f Blue Swirl
 * License as published by the Free Software Foundation; either
9 ab3b491f Blue Swirl
 * version 2 of the License, or (at your option) any later version.
10 ab3b491f Blue Swirl
 *
11 ab3b491f Blue Swirl
 * This library is distributed in the hope that it will be useful,
12 ab3b491f Blue Swirl
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ab3b491f Blue Swirl
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ab3b491f Blue Swirl
 * Lesser General Public License for more details.
15 ab3b491f Blue Swirl
 *
16 ab3b491f Blue Swirl
 * You should have received a copy of the GNU Lesser General Public
17 ab3b491f Blue Swirl
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 ab3b491f Blue Swirl
 */
19 ab3b491f Blue Swirl
20 ab3b491f Blue Swirl
#include "cpu.h"
21 ab3b491f Blue Swirl
22 ab3b491f Blue Swirl
//#define DEBUG_FEATURES
23 ab3b491f Blue Swirl
24 ab3b491f Blue Swirl
static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model);
25 ab3b491f Blue Swirl
26 ab7ab3d7 Andreas Färber
/* CPUClass::reset() */
27 ab7ab3d7 Andreas Färber
static void sparc_cpu_reset(CPUState *s)
28 ab7ab3d7 Andreas Färber
{
29 ab7ab3d7 Andreas Färber
    SPARCCPU *cpu = SPARC_CPU(s);
30 ab7ab3d7 Andreas Färber
    SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(cpu);
31 ab7ab3d7 Andreas Färber
    CPUSPARCState *env = &cpu->env;
32 ab7ab3d7 Andreas Färber
33 ab7ab3d7 Andreas Färber
    scc->parent_reset(s);
34 ab7ab3d7 Andreas Färber
35 89aaf60d Blue Swirl
    memset(env, 0, offsetof(CPUSPARCState, breakpoints));
36 ab3b491f Blue Swirl
    tlb_flush(env, 1);
37 ab3b491f Blue Swirl
    env->cwp = 0;
38 ab3b491f Blue Swirl
#ifndef TARGET_SPARC64
39 ab3b491f Blue Swirl
    env->wim = 1;
40 ab3b491f Blue Swirl
#endif
41 ab3b491f Blue Swirl
    env->regwptr = env->regbase + (env->cwp * 16);
42 ab3b491f Blue Swirl
    CC_OP = CC_OP_FLAGS;
43 ab3b491f Blue Swirl
#if defined(CONFIG_USER_ONLY)
44 ab3b491f Blue Swirl
#ifdef TARGET_SPARC64
45 ab3b491f Blue Swirl
    env->cleanwin = env->nwindows - 2;
46 ab3b491f Blue Swirl
    env->cansave = env->nwindows - 2;
47 ab3b491f Blue Swirl
    env->pstate = PS_RMO | PS_PEF | PS_IE;
48 ab3b491f Blue Swirl
    env->asi = 0x82; /* Primary no-fault */
49 ab3b491f Blue Swirl
#endif
50 ab3b491f Blue Swirl
#else
51 ab3b491f Blue Swirl
#if !defined(TARGET_SPARC64)
52 ab3b491f Blue Swirl
    env->psret = 0;
53 ab3b491f Blue Swirl
    env->psrs = 1;
54 ab3b491f Blue Swirl
    env->psrps = 1;
55 ab3b491f Blue Swirl
#endif
56 ab3b491f Blue Swirl
#ifdef TARGET_SPARC64
57 ab3b491f Blue Swirl
    env->pstate = PS_PRIV|PS_RED|PS_PEF|PS_AG;
58 ab3b491f Blue Swirl
    env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0;
59 ab3b491f Blue Swirl
    env->tl = env->maxtl;
60 ab3b491f Blue Swirl
    cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
61 ab3b491f Blue Swirl
    env->lsu = 0;
62 ab3b491f Blue Swirl
#else
63 ab3b491f Blue Swirl
    env->mmuregs[0] &= ~(MMU_E | MMU_NF);
64 ab3b491f Blue Swirl
    env->mmuregs[0] |= env->def->mmu_bm;
65 ab3b491f Blue Swirl
#endif
66 ab3b491f Blue Swirl
    env->pc = 0;
67 ab3b491f Blue Swirl
    env->npc = env->pc + 4;
68 ab3b491f Blue Swirl
#endif
69 ab3b491f Blue Swirl
    env->cache_control = 0;
70 ab3b491f Blue Swirl
}
71 ab3b491f Blue Swirl
72 ab3b491f Blue Swirl
static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model)
73 ab3b491f Blue Swirl
{
74 ab3b491f Blue Swirl
    sparc_def_t def1, *def = &def1;
75 ab3b491f Blue Swirl
76 ab3b491f Blue Swirl
    if (cpu_sparc_find_by_name(def, cpu_model) < 0) {
77 ab3b491f Blue Swirl
        return -1;
78 ab3b491f Blue Swirl
    }
79 ab3b491f Blue Swirl
80 d300854b Stefan Weil
    env->def = g_new0(sparc_def_t, 1);
81 ab3b491f Blue Swirl
    memcpy(env->def, def, sizeof(*def));
82 ab3b491f Blue Swirl
#if defined(CONFIG_USER_ONLY)
83 ab3b491f Blue Swirl
    if ((env->def->features & CPU_FEATURE_FLOAT)) {
84 ab3b491f Blue Swirl
        env->def->features |= CPU_FEATURE_FLOAT128;
85 ab3b491f Blue Swirl
    }
86 ab3b491f Blue Swirl
#endif
87 ab3b491f Blue Swirl
    env->cpu_model_str = cpu_model;
88 ab3b491f Blue Swirl
    env->version = def->iu_version;
89 ab3b491f Blue Swirl
    env->fsr = def->fpu_version;
90 ab3b491f Blue Swirl
    env->nwindows = def->nwindows;
91 ab3b491f Blue Swirl
#if !defined(TARGET_SPARC64)
92 ab3b491f Blue Swirl
    env->mmuregs[0] |= def->mmu_version;
93 ab3b491f Blue Swirl
    cpu_sparc_set_id(env, 0);
94 ab3b491f Blue Swirl
    env->mxccregs[7] |= def->mxcc_version;
95 ab3b491f Blue Swirl
#else
96 ab3b491f Blue Swirl
    env->mmu_version = def->mmu_version;
97 ab3b491f Blue Swirl
    env->maxtl = def->maxtl;
98 ab3b491f Blue Swirl
    env->version |= def->maxtl << 8;
99 ab3b491f Blue Swirl
    env->version |= def->nwindows - 1;
100 ab3b491f Blue Swirl
#endif
101 ab3b491f Blue Swirl
    return 0;
102 ab3b491f Blue Swirl
}
103 ab3b491f Blue Swirl
104 e59be77a Andreas Färber
SPARCCPU *cpu_sparc_init(const char *cpu_model)
105 ab3b491f Blue Swirl
{
106 ab7ab3d7 Andreas Färber
    SPARCCPU *cpu;
107 ab3b491f Blue Swirl
    CPUSPARCState *env;
108 ab3b491f Blue Swirl
109 ab7ab3d7 Andreas Färber
    cpu = SPARC_CPU(object_new(TYPE_SPARC_CPU));
110 ab7ab3d7 Andreas Färber
    env = &cpu->env;
111 ab3b491f Blue Swirl
112 ab3b491f Blue Swirl
    if (cpu_sparc_register(env, cpu_model) < 0) {
113 5c099537 Paolo Bonzini
        object_unref(OBJECT(cpu));
114 ab3b491f Blue Swirl
        return NULL;
115 ab3b491f Blue Swirl
    }
116 b6e91ebf Andreas Färber
117 b6e91ebf Andreas Färber
    object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
118 ab3b491f Blue Swirl
119 e59be77a Andreas Färber
    return cpu;
120 ab3b491f Blue Swirl
}
121 ab3b491f Blue Swirl
122 ab3b491f Blue Swirl
void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
123 ab3b491f Blue Swirl
{
124 ab3b491f Blue Swirl
#if !defined(TARGET_SPARC64)
125 ab3b491f Blue Swirl
    env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
126 ab3b491f Blue Swirl
#endif
127 ab3b491f Blue Swirl
}
128 ab3b491f Blue Swirl
129 ab3b491f Blue Swirl
static const sparc_def_t sparc_defs[] = {
130 ab3b491f Blue Swirl
#ifdef TARGET_SPARC64
131 ab3b491f Blue Swirl
    {
132 ab3b491f Blue Swirl
        .name = "Fujitsu Sparc64",
133 ab3b491f Blue Swirl
        .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
134 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
135 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
136 ab3b491f Blue Swirl
        .nwindows = 4,
137 ab3b491f Blue Swirl
        .maxtl = 4,
138 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
139 ab3b491f Blue Swirl
    },
140 ab3b491f Blue Swirl
    {
141 ab3b491f Blue Swirl
        .name = "Fujitsu Sparc64 III",
142 ab3b491f Blue Swirl
        .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
143 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
144 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
145 ab3b491f Blue Swirl
        .nwindows = 5,
146 ab3b491f Blue Swirl
        .maxtl = 4,
147 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
148 ab3b491f Blue Swirl
    },
149 ab3b491f Blue Swirl
    {
150 ab3b491f Blue Swirl
        .name = "Fujitsu Sparc64 IV",
151 ab3b491f Blue Swirl
        .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
152 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
153 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
154 ab3b491f Blue Swirl
        .nwindows = 8,
155 ab3b491f Blue Swirl
        .maxtl = 5,
156 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
157 ab3b491f Blue Swirl
    },
158 ab3b491f Blue Swirl
    {
159 ab3b491f Blue Swirl
        .name = "Fujitsu Sparc64 V",
160 ab3b491f Blue Swirl
        .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
161 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
162 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
163 ab3b491f Blue Swirl
        .nwindows = 8,
164 ab3b491f Blue Swirl
        .maxtl = 5,
165 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
166 ab3b491f Blue Swirl
    },
167 ab3b491f Blue Swirl
    {
168 ab3b491f Blue Swirl
        .name = "TI UltraSparc I",
169 ab3b491f Blue Swirl
        .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
170 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
171 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
172 ab3b491f Blue Swirl
        .nwindows = 8,
173 ab3b491f Blue Swirl
        .maxtl = 5,
174 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
175 ab3b491f Blue Swirl
    },
176 ab3b491f Blue Swirl
    {
177 ab3b491f Blue Swirl
        .name = "TI UltraSparc II",
178 ab3b491f Blue Swirl
        .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
179 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
180 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
181 ab3b491f Blue Swirl
        .nwindows = 8,
182 ab3b491f Blue Swirl
        .maxtl = 5,
183 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
184 ab3b491f Blue Swirl
    },
185 ab3b491f Blue Swirl
    {
186 ab3b491f Blue Swirl
        .name = "TI UltraSparc IIi",
187 ab3b491f Blue Swirl
        .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
188 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
189 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
190 ab3b491f Blue Swirl
        .nwindows = 8,
191 ab3b491f Blue Swirl
        .maxtl = 5,
192 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
193 ab3b491f Blue Swirl
    },
194 ab3b491f Blue Swirl
    {
195 ab3b491f Blue Swirl
        .name = "TI UltraSparc IIe",
196 ab3b491f Blue Swirl
        .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
197 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
198 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
199 ab3b491f Blue Swirl
        .nwindows = 8,
200 ab3b491f Blue Swirl
        .maxtl = 5,
201 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
202 ab3b491f Blue Swirl
    },
203 ab3b491f Blue Swirl
    {
204 ab3b491f Blue Swirl
        .name = "Sun UltraSparc III",
205 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
206 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
207 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
208 ab3b491f Blue Swirl
        .nwindows = 8,
209 ab3b491f Blue Swirl
        .maxtl = 5,
210 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
211 ab3b491f Blue Swirl
    },
212 ab3b491f Blue Swirl
    {
213 ab3b491f Blue Swirl
        .name = "Sun UltraSparc III Cu",
214 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
215 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
216 ab3b491f Blue Swirl
        .mmu_version = mmu_us_3,
217 ab3b491f Blue Swirl
        .nwindows = 8,
218 ab3b491f Blue Swirl
        .maxtl = 5,
219 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
220 ab3b491f Blue Swirl
    },
221 ab3b491f Blue Swirl
    {
222 ab3b491f Blue Swirl
        .name = "Sun UltraSparc IIIi",
223 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
224 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
225 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
226 ab3b491f Blue Swirl
        .nwindows = 8,
227 ab3b491f Blue Swirl
        .maxtl = 5,
228 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
229 ab3b491f Blue Swirl
    },
230 ab3b491f Blue Swirl
    {
231 ab3b491f Blue Swirl
        .name = "Sun UltraSparc IV",
232 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
233 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
234 ab3b491f Blue Swirl
        .mmu_version = mmu_us_4,
235 ab3b491f Blue Swirl
        .nwindows = 8,
236 ab3b491f Blue Swirl
        .maxtl = 5,
237 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
238 ab3b491f Blue Swirl
    },
239 ab3b491f Blue Swirl
    {
240 ab3b491f Blue Swirl
        .name = "Sun UltraSparc IV+",
241 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
242 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
243 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
244 ab3b491f Blue Swirl
        .nwindows = 8,
245 ab3b491f Blue Swirl
        .maxtl = 5,
246 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
247 ab3b491f Blue Swirl
    },
248 ab3b491f Blue Swirl
    {
249 ab3b491f Blue Swirl
        .name = "Sun UltraSparc IIIi+",
250 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
251 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
252 ab3b491f Blue Swirl
        .mmu_version = mmu_us_3,
253 ab3b491f Blue Swirl
        .nwindows = 8,
254 ab3b491f Blue Swirl
        .maxtl = 5,
255 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
256 ab3b491f Blue Swirl
    },
257 ab3b491f Blue Swirl
    {
258 ab3b491f Blue Swirl
        .name = "Sun UltraSparc T1",
259 ab3b491f Blue Swirl
        /* defined in sparc_ifu_fdp.v and ctu.h */
260 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
261 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
262 ab3b491f Blue Swirl
        .mmu_version = mmu_sun4v,
263 ab3b491f Blue Swirl
        .nwindows = 8,
264 ab3b491f Blue Swirl
        .maxtl = 6,
265 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
266 ab3b491f Blue Swirl
        | CPU_FEATURE_GL,
267 ab3b491f Blue Swirl
    },
268 ab3b491f Blue Swirl
    {
269 ab3b491f Blue Swirl
        .name = "Sun UltraSparc T2",
270 ab3b491f Blue Swirl
        /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
271 ab3b491f Blue Swirl
        .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
272 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
273 ab3b491f Blue Swirl
        .mmu_version = mmu_sun4v,
274 ab3b491f Blue Swirl
        .nwindows = 8,
275 ab3b491f Blue Swirl
        .maxtl = 6,
276 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
277 ab3b491f Blue Swirl
        | CPU_FEATURE_GL,
278 ab3b491f Blue Swirl
    },
279 ab3b491f Blue Swirl
    {
280 ab3b491f Blue Swirl
        .name = "NEC UltraSparc I",
281 ab3b491f Blue Swirl
        .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
282 ab3b491f Blue Swirl
        .fpu_version = 0x00000000,
283 ab3b491f Blue Swirl
        .mmu_version = mmu_us_12,
284 ab3b491f Blue Swirl
        .nwindows = 8,
285 ab3b491f Blue Swirl
        .maxtl = 5,
286 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
287 ab3b491f Blue Swirl
    },
288 ab3b491f Blue Swirl
#else
289 ab3b491f Blue Swirl
    {
290 ab3b491f Blue Swirl
        .name = "Fujitsu MB86904",
291 ab3b491f Blue Swirl
        .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
292 ab3b491f Blue Swirl
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
293 ab3b491f Blue Swirl
        .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
294 ab3b491f Blue Swirl
        .mmu_bm = 0x00004000,
295 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0x00ffffc0,
296 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x000000ff,
297 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0x00016fff,
298 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0x00ffffff,
299 ab3b491f Blue Swirl
        .nwindows = 8,
300 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
301 ab3b491f Blue Swirl
    },
302 ab3b491f Blue Swirl
    {
303 ab3b491f Blue Swirl
        .name = "Fujitsu MB86907",
304 ab3b491f Blue Swirl
        .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
305 ab3b491f Blue Swirl
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
306 ab3b491f Blue Swirl
        .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
307 ab3b491f Blue Swirl
        .mmu_bm = 0x00004000,
308 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0xffffffc0,
309 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x000000ff,
310 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0x00016fff,
311 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
312 ab3b491f Blue Swirl
        .nwindows = 8,
313 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
314 ab3b491f Blue Swirl
    },
315 ab3b491f Blue Swirl
    {
316 ab3b491f Blue Swirl
        .name = "TI MicroSparc I",
317 ab3b491f Blue Swirl
        .iu_version = 0x41000000,
318 ab3b491f Blue Swirl
        .fpu_version = 4 << 17,
319 ab3b491f Blue Swirl
        .mmu_version = 0x41000000,
320 ab3b491f Blue Swirl
        .mmu_bm = 0x00004000,
321 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0x007ffff0,
322 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000003f,
323 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0x00016fff,
324 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0x0000003f,
325 ab3b491f Blue Swirl
        .nwindows = 7,
326 ab3b491f Blue Swirl
        .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL |
327 ab3b491f Blue Swirl
        CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT |
328 ab3b491f Blue Swirl
        CPU_FEATURE_FMUL,
329 ab3b491f Blue Swirl
    },
330 ab3b491f Blue Swirl
    {
331 ab3b491f Blue Swirl
        .name = "TI MicroSparc II",
332 ab3b491f Blue Swirl
        .iu_version = 0x42000000,
333 ab3b491f Blue Swirl
        .fpu_version = 4 << 17,
334 ab3b491f Blue Swirl
        .mmu_version = 0x02000000,
335 ab3b491f Blue Swirl
        .mmu_bm = 0x00004000,
336 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0x00ffffc0,
337 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x000000ff,
338 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0x00016fff,
339 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0x00ffffff,
340 ab3b491f Blue Swirl
        .nwindows = 8,
341 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
342 ab3b491f Blue Swirl
    },
343 ab3b491f Blue Swirl
    {
344 ab3b491f Blue Swirl
        .name = "TI MicroSparc IIep",
345 ab3b491f Blue Swirl
        .iu_version = 0x42000000,
346 ab3b491f Blue Swirl
        .fpu_version = 4 << 17,
347 ab3b491f Blue Swirl
        .mmu_version = 0x04000000,
348 ab3b491f Blue Swirl
        .mmu_bm = 0x00004000,
349 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0x00ffffc0,
350 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x000000ff,
351 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0x00016bff,
352 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0x00ffffff,
353 ab3b491f Blue Swirl
        .nwindows = 8,
354 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
355 ab3b491f Blue Swirl
    },
356 ab3b491f Blue Swirl
    {
357 ab3b491f Blue Swirl
        .name = "TI SuperSparc 40", /* STP1020NPGA */
358 ab3b491f Blue Swirl
        .iu_version = 0x41000000, /* SuperSPARC 2.x */
359 ab3b491f Blue Swirl
        .fpu_version = 0 << 17,
360 ab3b491f Blue Swirl
        .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */
361 ab3b491f Blue Swirl
        .mmu_bm = 0x00002000,
362 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0xffffffc0,
363 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000ffff,
364 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
365 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
366 ab3b491f Blue Swirl
        .nwindows = 8,
367 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
368 ab3b491f Blue Swirl
    },
369 ab3b491f Blue Swirl
    {
370 ab3b491f Blue Swirl
        .name = "TI SuperSparc 50", /* STP1020PGA */
371 ab3b491f Blue Swirl
        .iu_version = 0x40000000, /* SuperSPARC 3.x */
372 ab3b491f Blue Swirl
        .fpu_version = 0 << 17,
373 ab3b491f Blue Swirl
        .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
374 ab3b491f Blue Swirl
        .mmu_bm = 0x00002000,
375 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0xffffffc0,
376 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000ffff,
377 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
378 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
379 ab3b491f Blue Swirl
        .nwindows = 8,
380 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
381 ab3b491f Blue Swirl
    },
382 ab3b491f Blue Swirl
    {
383 ab3b491f Blue Swirl
        .name = "TI SuperSparc 51",
384 ab3b491f Blue Swirl
        .iu_version = 0x40000000, /* SuperSPARC 3.x */
385 ab3b491f Blue Swirl
        .fpu_version = 0 << 17,
386 ab3b491f Blue Swirl
        .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
387 ab3b491f Blue Swirl
        .mmu_bm = 0x00002000,
388 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0xffffffc0,
389 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000ffff,
390 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
391 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
392 ab3b491f Blue Swirl
        .mxcc_version = 0x00000104,
393 ab3b491f Blue Swirl
        .nwindows = 8,
394 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
395 ab3b491f Blue Swirl
    },
396 ab3b491f Blue Swirl
    {
397 ab3b491f Blue Swirl
        .name = "TI SuperSparc 60", /* STP1020APGA */
398 ab3b491f Blue Swirl
        .iu_version = 0x40000000, /* SuperSPARC 3.x */
399 ab3b491f Blue Swirl
        .fpu_version = 0 << 17,
400 ab3b491f Blue Swirl
        .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
401 ab3b491f Blue Swirl
        .mmu_bm = 0x00002000,
402 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0xffffffc0,
403 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000ffff,
404 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
405 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
406 ab3b491f Blue Swirl
        .nwindows = 8,
407 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
408 ab3b491f Blue Swirl
    },
409 ab3b491f Blue Swirl
    {
410 ab3b491f Blue Swirl
        .name = "TI SuperSparc 61",
411 ab3b491f Blue Swirl
        .iu_version = 0x44000000, /* SuperSPARC 3.x */
412 ab3b491f Blue Swirl
        .fpu_version = 0 << 17,
413 ab3b491f Blue Swirl
        .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
414 ab3b491f Blue Swirl
        .mmu_bm = 0x00002000,
415 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0xffffffc0,
416 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000ffff,
417 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
418 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
419 ab3b491f Blue Swirl
        .mxcc_version = 0x00000104,
420 ab3b491f Blue Swirl
        .nwindows = 8,
421 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
422 ab3b491f Blue Swirl
    },
423 ab3b491f Blue Swirl
    {
424 ab3b491f Blue Swirl
        .name = "TI SuperSparc II",
425 ab3b491f Blue Swirl
        .iu_version = 0x40000000, /* SuperSPARC II 1.x */
426 ab3b491f Blue Swirl
        .fpu_version = 0 << 17,
427 ab3b491f Blue Swirl
        .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */
428 ab3b491f Blue Swirl
        .mmu_bm = 0x00002000,
429 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0xffffffc0,
430 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000ffff,
431 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
432 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
433 ab3b491f Blue Swirl
        .mxcc_version = 0x00000104,
434 ab3b491f Blue Swirl
        .nwindows = 8,
435 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES,
436 ab3b491f Blue Swirl
    },
437 ab3b491f Blue Swirl
    {
438 ab3b491f Blue Swirl
        .name = "LEON2",
439 ab3b491f Blue Swirl
        .iu_version = 0xf2000000,
440 ab3b491f Blue Swirl
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
441 ab3b491f Blue Swirl
        .mmu_version = 0xf2000000,
442 ab3b491f Blue Swirl
        .mmu_bm = 0x00004000,
443 ab3b491f Blue Swirl
        .mmu_ctpr_mask = 0x007ffff0,
444 ab3b491f Blue Swirl
        .mmu_cxr_mask = 0x0000003f,
445 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
446 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
447 ab3b491f Blue Swirl
        .nwindows = 8,
448 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
449 ab3b491f Blue Swirl
    },
450 ab3b491f Blue Swirl
    {
451 ab3b491f Blue Swirl
        .name = "LEON3",
452 ab3b491f Blue Swirl
        .iu_version = 0xf3000000,
453 ab3b491f Blue Swirl
        .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
454 ab3b491f Blue Swirl
        .mmu_version = 0xf3000000,
455 ab3b491f Blue Swirl
        .mmu_bm = 0x00000000,
456 7a0a9c2c Ronald Hecht
        .mmu_ctpr_mask = 0xfffffffc,
457 7a0a9c2c Ronald Hecht
        .mmu_cxr_mask = 0x000000ff,
458 ab3b491f Blue Swirl
        .mmu_sfsr_mask = 0xffffffff,
459 ab3b491f Blue Swirl
        .mmu_trcr_mask = 0xffffffff,
460 ab3b491f Blue Swirl
        .nwindows = 8,
461 ab3b491f Blue Swirl
        .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
462 d1c36ba7 Ronald Hecht
        CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL | CPU_FEATURE_POWERDOWN,
463 ab3b491f Blue Swirl
    },
464 ab3b491f Blue Swirl
#endif
465 ab3b491f Blue Swirl
};
466 ab3b491f Blue Swirl
467 ab3b491f Blue Swirl
static const char * const feature_name[] = {
468 ab3b491f Blue Swirl
    "float",
469 ab3b491f Blue Swirl
    "float128",
470 ab3b491f Blue Swirl
    "swap",
471 ab3b491f Blue Swirl
    "mul",
472 ab3b491f Blue Swirl
    "div",
473 ab3b491f Blue Swirl
    "flush",
474 ab3b491f Blue Swirl
    "fsqrt",
475 ab3b491f Blue Swirl
    "fmul",
476 ab3b491f Blue Swirl
    "vis1",
477 ab3b491f Blue Swirl
    "vis2",
478 ab3b491f Blue Swirl
    "fsmuld",
479 ab3b491f Blue Swirl
    "hypv",
480 ab3b491f Blue Swirl
    "cmt",
481 ab3b491f Blue Swirl
    "gl",
482 ab3b491f Blue Swirl
};
483 ab3b491f Blue Swirl
484 ab3b491f Blue Swirl
static void print_features(FILE *f, fprintf_function cpu_fprintf,
485 ab3b491f Blue Swirl
                           uint32_t features, const char *prefix)
486 ab3b491f Blue Swirl
{
487 ab3b491f Blue Swirl
    unsigned int i;
488 ab3b491f Blue Swirl
489 ab3b491f Blue Swirl
    for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
490 ab3b491f Blue Swirl
        if (feature_name[i] && (features & (1 << i))) {
491 ab3b491f Blue Swirl
            if (prefix) {
492 ab3b491f Blue Swirl
                (*cpu_fprintf)(f, "%s", prefix);
493 ab3b491f Blue Swirl
            }
494 ab3b491f Blue Swirl
            (*cpu_fprintf)(f, "%s ", feature_name[i]);
495 ab3b491f Blue Swirl
        }
496 ab3b491f Blue Swirl
    }
497 ab3b491f Blue Swirl
}
498 ab3b491f Blue Swirl
499 ab3b491f Blue Swirl
static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features)
500 ab3b491f Blue Swirl
{
501 ab3b491f Blue Swirl
    unsigned int i;
502 ab3b491f Blue Swirl
503 ab3b491f Blue Swirl
    for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
504 ab3b491f Blue Swirl
        if (feature_name[i] && !strcmp(flagname, feature_name[i])) {
505 ab3b491f Blue Swirl
            *features |= 1 << i;
506 ab3b491f Blue Swirl
            return;
507 ab3b491f Blue Swirl
        }
508 ab3b491f Blue Swirl
    }
509 ab3b491f Blue Swirl
    fprintf(stderr, "CPU feature %s not found\n", flagname);
510 ab3b491f Blue Swirl
}
511 ab3b491f Blue Swirl
512 ab3b491f Blue Swirl
static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model)
513 ab3b491f Blue Swirl
{
514 ab3b491f Blue Swirl
    unsigned int i;
515 ab3b491f Blue Swirl
    const sparc_def_t *def = NULL;
516 bfad6739 Jim Meyering
    char *s = g_strdup(cpu_model);
517 ab3b491f Blue Swirl
    char *featurestr, *name = strtok(s, ",");
518 ab3b491f Blue Swirl
    uint32_t plus_features = 0;
519 ab3b491f Blue Swirl
    uint32_t minus_features = 0;
520 ab3b491f Blue Swirl
    uint64_t iu_version;
521 ab3b491f Blue Swirl
    uint32_t fpu_version, mmu_version, nwindows;
522 ab3b491f Blue Swirl
523 ab3b491f Blue Swirl
    for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
524 ab3b491f Blue Swirl
        if (strcasecmp(name, sparc_defs[i].name) == 0) {
525 ab3b491f Blue Swirl
            def = &sparc_defs[i];
526 ab3b491f Blue Swirl
        }
527 ab3b491f Blue Swirl
    }
528 ab3b491f Blue Swirl
    if (!def) {
529 ab3b491f Blue Swirl
        goto error;
530 ab3b491f Blue Swirl
    }
531 ab3b491f Blue Swirl
    memcpy(cpu_def, def, sizeof(*def));
532 ab3b491f Blue Swirl
533 ab3b491f Blue Swirl
    featurestr = strtok(NULL, ",");
534 ab3b491f Blue Swirl
    while (featurestr) {
535 ab3b491f Blue Swirl
        char *val;
536 ab3b491f Blue Swirl
537 ab3b491f Blue Swirl
        if (featurestr[0] == '+') {
538 ab3b491f Blue Swirl
            add_flagname_to_bitmaps(featurestr + 1, &plus_features);
539 ab3b491f Blue Swirl
        } else if (featurestr[0] == '-') {
540 ab3b491f Blue Swirl
            add_flagname_to_bitmaps(featurestr + 1, &minus_features);
541 ab3b491f Blue Swirl
        } else if ((val = strchr(featurestr, '='))) {
542 ab3b491f Blue Swirl
            *val = 0; val++;
543 ab3b491f Blue Swirl
            if (!strcmp(featurestr, "iu_version")) {
544 ab3b491f Blue Swirl
                char *err;
545 ab3b491f Blue Swirl
546 ab3b491f Blue Swirl
                iu_version = strtoll(val, &err, 0);
547 ab3b491f Blue Swirl
                if (!*val || *err) {
548 ab3b491f Blue Swirl
                    fprintf(stderr, "bad numerical value %s\n", val);
549 ab3b491f Blue Swirl
                    goto error;
550 ab3b491f Blue Swirl
                }
551 ab3b491f Blue Swirl
                cpu_def->iu_version = iu_version;
552 ab3b491f Blue Swirl
#ifdef DEBUG_FEATURES
553 ab3b491f Blue Swirl
                fprintf(stderr, "iu_version %" PRIx64 "\n", iu_version);
554 ab3b491f Blue Swirl
#endif
555 ab3b491f Blue Swirl
            } else if (!strcmp(featurestr, "fpu_version")) {
556 ab3b491f Blue Swirl
                char *err;
557 ab3b491f Blue Swirl
558 ab3b491f Blue Swirl
                fpu_version = strtol(val, &err, 0);
559 ab3b491f Blue Swirl
                if (!*val || *err) {
560 ab3b491f Blue Swirl
                    fprintf(stderr, "bad numerical value %s\n", val);
561 ab3b491f Blue Swirl
                    goto error;
562 ab3b491f Blue Swirl
                }
563 ab3b491f Blue Swirl
                cpu_def->fpu_version = fpu_version;
564 ab3b491f Blue Swirl
#ifdef DEBUG_FEATURES
565 ab3b491f Blue Swirl
                fprintf(stderr, "fpu_version %x\n", fpu_version);
566 ab3b491f Blue Swirl
#endif
567 ab3b491f Blue Swirl
            } else if (!strcmp(featurestr, "mmu_version")) {
568 ab3b491f Blue Swirl
                char *err;
569 ab3b491f Blue Swirl
570 ab3b491f Blue Swirl
                mmu_version = strtol(val, &err, 0);
571 ab3b491f Blue Swirl
                if (!*val || *err) {
572 ab3b491f Blue Swirl
                    fprintf(stderr, "bad numerical value %s\n", val);
573 ab3b491f Blue Swirl
                    goto error;
574 ab3b491f Blue Swirl
                }
575 ab3b491f Blue Swirl
                cpu_def->mmu_version = mmu_version;
576 ab3b491f Blue Swirl
#ifdef DEBUG_FEATURES
577 ab3b491f Blue Swirl
                fprintf(stderr, "mmu_version %x\n", mmu_version);
578 ab3b491f Blue Swirl
#endif
579 ab3b491f Blue Swirl
            } else if (!strcmp(featurestr, "nwindows")) {
580 ab3b491f Blue Swirl
                char *err;
581 ab3b491f Blue Swirl
582 ab3b491f Blue Swirl
                nwindows = strtol(val, &err, 0);
583 ab3b491f Blue Swirl
                if (!*val || *err || nwindows > MAX_NWINDOWS ||
584 ab3b491f Blue Swirl
                    nwindows < MIN_NWINDOWS) {
585 ab3b491f Blue Swirl
                    fprintf(stderr, "bad numerical value %s\n", val);
586 ab3b491f Blue Swirl
                    goto error;
587 ab3b491f Blue Swirl
                }
588 ab3b491f Blue Swirl
                cpu_def->nwindows = nwindows;
589 ab3b491f Blue Swirl
#ifdef DEBUG_FEATURES
590 ab3b491f Blue Swirl
                fprintf(stderr, "nwindows %d\n", nwindows);
591 ab3b491f Blue Swirl
#endif
592 ab3b491f Blue Swirl
            } else {
593 ab3b491f Blue Swirl
                fprintf(stderr, "unrecognized feature %s\n", featurestr);
594 ab3b491f Blue Swirl
                goto error;
595 ab3b491f Blue Swirl
            }
596 ab3b491f Blue Swirl
        } else {
597 ab3b491f Blue Swirl
            fprintf(stderr, "feature string `%s' not in format "
598 ab3b491f Blue Swirl
                    "(+feature|-feature|feature=xyz)\n", featurestr);
599 ab3b491f Blue Swirl
            goto error;
600 ab3b491f Blue Swirl
        }
601 ab3b491f Blue Swirl
        featurestr = strtok(NULL, ",");
602 ab3b491f Blue Swirl
    }
603 ab3b491f Blue Swirl
    cpu_def->features |= plus_features;
604 ab3b491f Blue Swirl
    cpu_def->features &= ~minus_features;
605 ab3b491f Blue Swirl
#ifdef DEBUG_FEATURES
606 ab3b491f Blue Swirl
    print_features(stderr, fprintf, cpu_def->features, NULL);
607 ab3b491f Blue Swirl
#endif
608 bfad6739 Jim Meyering
    g_free(s);
609 ab3b491f Blue Swirl
    return 0;
610 ab3b491f Blue Swirl
611 ab3b491f Blue Swirl
 error:
612 1e2a1d41 Stefan Weil
    g_free(s);
613 ab3b491f Blue Swirl
    return -1;
614 ab3b491f Blue Swirl
}
615 ab3b491f Blue Swirl
616 ab3b491f Blue Swirl
void sparc_cpu_list(FILE *f, fprintf_function cpu_fprintf)
617 ab3b491f Blue Swirl
{
618 ab3b491f Blue Swirl
    unsigned int i;
619 ab3b491f Blue Swirl
620 ab3b491f Blue Swirl
    for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
621 ab3b491f Blue Swirl
        (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx
622 ab3b491f Blue Swirl
                       " FPU %08x MMU %08x NWINS %d ",
623 ab3b491f Blue Swirl
                       sparc_defs[i].name,
624 ab3b491f Blue Swirl
                       sparc_defs[i].iu_version,
625 ab3b491f Blue Swirl
                       sparc_defs[i].fpu_version,
626 ab3b491f Blue Swirl
                       sparc_defs[i].mmu_version,
627 ab3b491f Blue Swirl
                       sparc_defs[i].nwindows);
628 ab3b491f Blue Swirl
        print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES &
629 ab3b491f Blue Swirl
                       ~sparc_defs[i].features, "-");
630 ab3b491f Blue Swirl
        print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES &
631 ab3b491f Blue Swirl
                       sparc_defs[i].features, "+");
632 ab3b491f Blue Swirl
        (*cpu_fprintf)(f, "\n");
633 ab3b491f Blue Swirl
    }
634 ab3b491f Blue Swirl
    (*cpu_fprintf)(f, "Default CPU feature flags (use '-' to remove): ");
635 ab3b491f Blue Swirl
    print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES, NULL);
636 ab3b491f Blue Swirl
    (*cpu_fprintf)(f, "\n");
637 ab3b491f Blue Swirl
    (*cpu_fprintf)(f, "Available CPU feature flags (use '+' to add): ");
638 ab3b491f Blue Swirl
    print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES, NULL);
639 ab3b491f Blue Swirl
    (*cpu_fprintf)(f, "\n");
640 ab3b491f Blue Swirl
    (*cpu_fprintf)(f, "Numerical features (use '=' to set): iu_version "
641 ab3b491f Blue Swirl
                   "fpu_version mmu_version nwindows\n");
642 ab3b491f Blue Swirl
}
643 ab3b491f Blue Swirl
644 ab3b491f Blue Swirl
static void cpu_print_cc(FILE *f, fprintf_function cpu_fprintf,
645 ab3b491f Blue Swirl
                         uint32_t cc)
646 ab3b491f Blue Swirl
{
647 ab3b491f Blue Swirl
    cpu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
648 ab3b491f Blue Swirl
                cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
649 ab3b491f Blue Swirl
                cc & PSR_CARRY ? 'C' : '-');
650 ab3b491f Blue Swirl
}
651 ab3b491f Blue Swirl
652 ab3b491f Blue Swirl
#ifdef TARGET_SPARC64
653 ab3b491f Blue Swirl
#define REGS_PER_LINE 4
654 ab3b491f Blue Swirl
#else
655 ab3b491f Blue Swirl
#define REGS_PER_LINE 8
656 ab3b491f Blue Swirl
#endif
657 ab3b491f Blue Swirl
658 878096ee Andreas Färber
void sparc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
659 878096ee Andreas Färber
                          int flags)
660 ab3b491f Blue Swirl
{
661 878096ee Andreas Färber
    SPARCCPU *cpu = SPARC_CPU(cs);
662 878096ee Andreas Färber
    CPUSPARCState *env = &cpu->env;
663 ab3b491f Blue Swirl
    int i, x;
664 ab3b491f Blue Swirl
665 ab3b491f Blue Swirl
    cpu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
666 ab3b491f Blue Swirl
                env->npc);
667 ab3b491f Blue Swirl
668 ab3b491f Blue Swirl
    for (i = 0; i < 8; i++) {
669 ab3b491f Blue Swirl
        if (i % REGS_PER_LINE == 0) {
670 ab3b491f Blue Swirl
            cpu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
671 ab3b491f Blue Swirl
        }
672 ab3b491f Blue Swirl
        cpu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
673 ab3b491f Blue Swirl
        if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
674 ab3b491f Blue Swirl
            cpu_fprintf(f, "\n");
675 ab3b491f Blue Swirl
        }
676 ab3b491f Blue Swirl
    }
677 ab3b491f Blue Swirl
    for (x = 0; x < 3; x++) {
678 ab3b491f Blue Swirl
        for (i = 0; i < 8; i++) {
679 ab3b491f Blue Swirl
            if (i % REGS_PER_LINE == 0) {
680 ab3b491f Blue Swirl
                cpu_fprintf(f, "%%%c%d-%d: ",
681 ab3b491f Blue Swirl
                            x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
682 ab3b491f Blue Swirl
                            i, i + REGS_PER_LINE - 1);
683 ab3b491f Blue Swirl
            }
684 ab3b491f Blue Swirl
            cpu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
685 ab3b491f Blue Swirl
            if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
686 ab3b491f Blue Swirl
                cpu_fprintf(f, "\n");
687 ab3b491f Blue Swirl
            }
688 ab3b491f Blue Swirl
        }
689 ab3b491f Blue Swirl
    }
690 76a23ca0 Richard Henderson
691 30038fd8 Richard Henderson
    for (i = 0; i < TARGET_DPREGS; i++) {
692 ab3b491f Blue Swirl
        if ((i & 3) == 0) {
693 76a23ca0 Richard Henderson
            cpu_fprintf(f, "%%f%02d: ", i * 2);
694 ab3b491f Blue Swirl
        }
695 30038fd8 Richard Henderson
        cpu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
696 ab3b491f Blue Swirl
        if ((i & 3) == 3) {
697 ab3b491f Blue Swirl
            cpu_fprintf(f, "\n");
698 ab3b491f Blue Swirl
        }
699 ab3b491f Blue Swirl
    }
700 ab3b491f Blue Swirl
#ifdef TARGET_SPARC64
701 ab3b491f Blue Swirl
    cpu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
702 ab3b491f Blue Swirl
                (unsigned)cpu_get_ccr(env));
703 ab3b491f Blue Swirl
    cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
704 ab3b491f Blue Swirl
    cpu_fprintf(f, " xcc: ");
705 ab3b491f Blue Swirl
    cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
706 ab3b491f Blue Swirl
    cpu_fprintf(f, ") asi: %02x tl: %d pil: %x\n", env->asi, env->tl,
707 ab3b491f Blue Swirl
                env->psrpil);
708 ab3b491f Blue Swirl
    cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
709 ab3b491f Blue Swirl
                "cleanwin: %d cwp: %d\n",
710 ab3b491f Blue Swirl
                env->cansave, env->canrestore, env->otherwin, env->wstate,
711 ab3b491f Blue Swirl
                env->cleanwin, env->nwindows - 1 - env->cwp);
712 ab3b491f Blue Swirl
    cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: "
713 ab3b491f Blue Swirl
                TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs);
714 ab3b491f Blue Swirl
#else
715 ab3b491f Blue Swirl
    cpu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
716 ab3b491f Blue Swirl
    cpu_print_cc(f, cpu_fprintf, cpu_get_psr(env));
717 ab3b491f Blue Swirl
    cpu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
718 ab3b491f Blue Swirl
                env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
719 ab3b491f Blue Swirl
                env->wim);
720 ab3b491f Blue Swirl
    cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
721 ab3b491f Blue Swirl
                env->fsr, env->y);
722 ab3b491f Blue Swirl
#endif
723 76a23ca0 Richard Henderson
    cpu_fprintf(f, "\n");
724 ab3b491f Blue Swirl
}
725 ab7ab3d7 Andreas Färber
726 f45748f1 Andreas Färber
static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
727 f45748f1 Andreas Färber
{
728 f45748f1 Andreas Färber
    SPARCCPU *cpu = SPARC_CPU(cs);
729 f45748f1 Andreas Färber
730 f45748f1 Andreas Färber
    cpu->env.pc = value;
731 f45748f1 Andreas Färber
    cpu->env.npc = value + 4;
732 f45748f1 Andreas Färber
}
733 f45748f1 Andreas Färber
734 bdf7ae5b Andreas Färber
static void sparc_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
735 bdf7ae5b Andreas Färber
{
736 bdf7ae5b Andreas Färber
    SPARCCPU *cpu = SPARC_CPU(cs);
737 bdf7ae5b Andreas Färber
738 bdf7ae5b Andreas Färber
    cpu->env.pc = tb->pc;
739 bdf7ae5b Andreas Färber
    cpu->env.npc = tb->cs_base;
740 bdf7ae5b Andreas Färber
}
741 bdf7ae5b Andreas Färber
742 b6e91ebf Andreas Färber
static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
743 b6e91ebf Andreas Färber
{
744 b6e91ebf Andreas Färber
    SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
745 b6e91ebf Andreas Färber
746 b6e91ebf Andreas Färber
    scc->parent_realize(dev, errp);
747 b6e91ebf Andreas Färber
}
748 b6e91ebf Andreas Färber
749 ab7ab3d7 Andreas Färber
static void sparc_cpu_initfn(Object *obj)
750 ab7ab3d7 Andreas Färber
{
751 c05efcb1 Andreas Färber
    CPUState *cs = CPU(obj);
752 ab7ab3d7 Andreas Färber
    SPARCCPU *cpu = SPARC_CPU(obj);
753 ab7ab3d7 Andreas Färber
    CPUSPARCState *env = &cpu->env;
754 ab7ab3d7 Andreas Färber
755 c05efcb1 Andreas Färber
    cs->env_ptr = env;
756 ab7ab3d7 Andreas Färber
    cpu_exec_init(env);
757 5266d20a Andreas Färber
758 5266d20a Andreas Färber
    if (tcg_enabled()) {
759 5266d20a Andreas Färber
        gen_intermediate_code_init(env);
760 5266d20a Andreas Färber
    }
761 ab7ab3d7 Andreas Färber
}
762 ab7ab3d7 Andreas Färber
763 ab7ab3d7 Andreas Färber
static void sparc_cpu_uninitfn(Object *obj)
764 ab7ab3d7 Andreas Färber
{
765 ab7ab3d7 Andreas Färber
    SPARCCPU *cpu = SPARC_CPU(obj);
766 ab7ab3d7 Andreas Färber
    CPUSPARCState *env = &cpu->env;
767 ab7ab3d7 Andreas Färber
768 ab7ab3d7 Andreas Färber
    g_free(env->def);
769 ab7ab3d7 Andreas Färber
}
770 ab7ab3d7 Andreas Färber
771 ab7ab3d7 Andreas Färber
static void sparc_cpu_class_init(ObjectClass *oc, void *data)
772 ab7ab3d7 Andreas Färber
{
773 ab7ab3d7 Andreas Färber
    SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
774 ab7ab3d7 Andreas Färber
    CPUClass *cc = CPU_CLASS(oc);
775 b6e91ebf Andreas Färber
    DeviceClass *dc = DEVICE_CLASS(oc);
776 b6e91ebf Andreas Färber
777 b6e91ebf Andreas Färber
    scc->parent_realize = dc->realize;
778 b6e91ebf Andreas Färber
    dc->realize = sparc_cpu_realizefn;
779 ab7ab3d7 Andreas Färber
780 ab7ab3d7 Andreas Färber
    scc->parent_reset = cc->reset;
781 ab7ab3d7 Andreas Färber
    cc->reset = sparc_cpu_reset;
782 97a8ea5a Andreas Färber
783 97a8ea5a Andreas Färber
    cc->do_interrupt = sparc_cpu_do_interrupt;
784 878096ee Andreas Färber
    cc->dump_state = sparc_cpu_dump_state;
785 f3659eee Andreas Färber
#if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
786 f3659eee Andreas Färber
    cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
787 f3659eee Andreas Färber
#endif
788 f45748f1 Andreas Färber
    cc->set_pc = sparc_cpu_set_pc;
789 bdf7ae5b Andreas Färber
    cc->synchronize_from_tb = sparc_cpu_synchronize_from_tb;
790 5b50e790 Andreas Färber
    cc->gdb_read_register = sparc_cpu_gdb_read_register;
791 5b50e790 Andreas Färber
    cc->gdb_write_register = sparc_cpu_gdb_write_register;
792 00b941e5 Andreas Färber
#ifndef CONFIG_USER_ONLY
793 00b941e5 Andreas Färber
    cc->do_unassigned_access = sparc_cpu_unassigned_access;
794 00b941e5 Andreas Färber
    cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug;
795 00b941e5 Andreas Färber
#endif
796 a0e372f0 Andreas Färber
797 a0e372f0 Andreas Färber
#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
798 a0e372f0 Andreas Färber
    cc->gdb_num_core_regs = 86;
799 a0e372f0 Andreas Färber
#else
800 a0e372f0 Andreas Färber
    cc->gdb_num_core_regs = 72;
801 a0e372f0 Andreas Färber
#endif
802 ab7ab3d7 Andreas Färber
}
803 ab7ab3d7 Andreas Färber
804 ab7ab3d7 Andreas Färber
static const TypeInfo sparc_cpu_type_info = {
805 ab7ab3d7 Andreas Färber
    .name = TYPE_SPARC_CPU,
806 ab7ab3d7 Andreas Färber
    .parent = TYPE_CPU,
807 ab7ab3d7 Andreas Färber
    .instance_size = sizeof(SPARCCPU),
808 ab7ab3d7 Andreas Färber
    .instance_init = sparc_cpu_initfn,
809 ab7ab3d7 Andreas Färber
    .instance_finalize = sparc_cpu_uninitfn,
810 ab7ab3d7 Andreas Färber
    .abstract = false,
811 ab7ab3d7 Andreas Färber
    .class_size = sizeof(SPARCCPUClass),
812 ab7ab3d7 Andreas Färber
    .class_init = sparc_cpu_class_init,
813 ab7ab3d7 Andreas Färber
};
814 ab7ab3d7 Andreas Färber
815 ab7ab3d7 Andreas Färber
static void sparc_cpu_register_types(void)
816 ab7ab3d7 Andreas Färber
{
817 ab7ab3d7 Andreas Färber
    type_register_static(&sparc_cpu_type_info);
818 ab7ab3d7 Andreas Färber
}
819 ab7ab3d7 Andreas Färber
820 ab7ab3d7 Andreas Färber
type_init(sparc_cpu_register_types)