xref: /qemu/target/sparc/cpu.c (revision cbc3a6a4cc675516328a2b0d3602355d68b6302d)
1ab3b491fSBlue Swirl /*
2ab3b491fSBlue Swirl  * Sparc CPU init helpers
3ab3b491fSBlue Swirl  *
4ab3b491fSBlue Swirl  *  Copyright (c) 2003-2005 Fabrice Bellard
5ab3b491fSBlue Swirl  *
6ab3b491fSBlue Swirl  * This library is free software; you can redistribute it and/or
7ab3b491fSBlue Swirl  * modify it under the terms of the GNU Lesser General Public
8ab3b491fSBlue Swirl  * License as published by the Free Software Foundation; either
9ab3b491fSBlue Swirl  * version 2 of the License, or (at your option) any later version.
10ab3b491fSBlue Swirl  *
11ab3b491fSBlue Swirl  * This library is distributed in the hope that it will be useful,
12ab3b491fSBlue Swirl  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13ab3b491fSBlue Swirl  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14ab3b491fSBlue Swirl  * Lesser General Public License for more details.
15ab3b491fSBlue Swirl  *
16ab3b491fSBlue Swirl  * You should have received a copy of the GNU Lesser General Public
17ab3b491fSBlue Swirl  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18ab3b491fSBlue Swirl  */
19ab3b491fSBlue Swirl 
20db5ebe5fSPeter Maydell #include "qemu/osdep.h"
21da34e65cSMarkus Armbruster #include "qapi/error.h"
22ab3b491fSBlue Swirl #include "cpu.h"
23db5d39f7SAndreas Färber #include "qemu/error-report.h"
2463c91552SPaolo Bonzini #include "exec/exec-all.h"
25ab3b491fSBlue Swirl 
26ab3b491fSBlue Swirl //#define DEBUG_FEATURES
27ab3b491fSBlue Swirl 
28ab3b491fSBlue Swirl static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model);
29ab3b491fSBlue Swirl 
30ab7ab3d7SAndreas Färber /* CPUClass::reset() */
31ab7ab3d7SAndreas Färber static void sparc_cpu_reset(CPUState *s)
32ab7ab3d7SAndreas Färber {
33ab7ab3d7SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(s);
34ab7ab3d7SAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(cpu);
35ab7ab3d7SAndreas Färber     CPUSPARCState *env = &cpu->env;
36ab7ab3d7SAndreas Färber 
37ab7ab3d7SAndreas Färber     scc->parent_reset(s);
38ab7ab3d7SAndreas Färber 
391f5c00cfSAlex Bennée     memset(env, 0, offsetof(CPUSPARCState, end_reset_fields));
40ab3b491fSBlue Swirl     env->cwp = 0;
41ab3b491fSBlue Swirl #ifndef TARGET_SPARC64
42ab3b491fSBlue Swirl     env->wim = 1;
43ab3b491fSBlue Swirl #endif
44ab3b491fSBlue Swirl     env->regwptr = env->regbase + (env->cwp * 16);
45ab3b491fSBlue Swirl     CC_OP = CC_OP_FLAGS;
46ab3b491fSBlue Swirl #if defined(CONFIG_USER_ONLY)
47ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
48ab3b491fSBlue Swirl     env->cleanwin = env->nwindows - 2;
49ab3b491fSBlue Swirl     env->cansave = env->nwindows - 2;
50ab3b491fSBlue Swirl     env->pstate = PS_RMO | PS_PEF | PS_IE;
51ab3b491fSBlue Swirl     env->asi = 0x82; /* Primary no-fault */
52ab3b491fSBlue Swirl #endif
53ab3b491fSBlue Swirl #else
54ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
55ab3b491fSBlue Swirl     env->psret = 0;
56ab3b491fSBlue Swirl     env->psrs = 1;
57ab3b491fSBlue Swirl     env->psrps = 1;
58ab3b491fSBlue Swirl #endif
59ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
60*cbc3a6a4SArtyom Tarasenko     env->pstate = PS_PRIV | PS_RED | PS_PEF;
61*cbc3a6a4SArtyom Tarasenko     if (!cpu_has_hypervisor(env)) {
62*cbc3a6a4SArtyom Tarasenko         env->pstate |= PS_AG;
63*cbc3a6a4SArtyom Tarasenko     }
64ab3b491fSBlue Swirl     env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0;
65ab3b491fSBlue Swirl     env->tl = env->maxtl;
66*cbc3a6a4SArtyom Tarasenko     env->gl = 2;
67ab3b491fSBlue Swirl     cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
68ab3b491fSBlue Swirl     env->lsu = 0;
69ab3b491fSBlue Swirl #else
70ab3b491fSBlue Swirl     env->mmuregs[0] &= ~(MMU_E | MMU_NF);
71ab3b491fSBlue Swirl     env->mmuregs[0] |= env->def->mmu_bm;
72ab3b491fSBlue Swirl #endif
73ab3b491fSBlue Swirl     env->pc = 0;
74ab3b491fSBlue Swirl     env->npc = env->pc + 4;
75ab3b491fSBlue Swirl #endif
76ab3b491fSBlue Swirl     env->cache_control = 0;
77ab3b491fSBlue Swirl }
78ab3b491fSBlue Swirl 
7987afe467SRichard Henderson static bool sparc_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
8087afe467SRichard Henderson {
8187afe467SRichard Henderson     if (interrupt_request & CPU_INTERRUPT_HARD) {
8287afe467SRichard Henderson         SPARCCPU *cpu = SPARC_CPU(cs);
8387afe467SRichard Henderson         CPUSPARCState *env = &cpu->env;
8487afe467SRichard Henderson 
8587afe467SRichard Henderson         if (cpu_interrupts_enabled(env) && env->interrupt_index > 0) {
8687afe467SRichard Henderson             int pil = env->interrupt_index & 0xf;
8787afe467SRichard Henderson             int type = env->interrupt_index & 0xf0;
8887afe467SRichard Henderson 
8987afe467SRichard Henderson             if (type != TT_EXTINT || cpu_pil_allowed(env, pil)) {
9087afe467SRichard Henderson                 cs->exception_index = env->interrupt_index;
9187afe467SRichard Henderson                 sparc_cpu_do_interrupt(cs);
9287afe467SRichard Henderson                 return true;
9387afe467SRichard Henderson             }
9487afe467SRichard Henderson         }
9587afe467SRichard Henderson     }
9687afe467SRichard Henderson     return false;
9787afe467SRichard Henderson }
9887afe467SRichard Henderson 
99df0900ebSPeter Crosthwaite static void cpu_sparc_disas_set_info(CPUState *cpu, disassemble_info *info)
100df0900ebSPeter Crosthwaite {
101df0900ebSPeter Crosthwaite     info->print_insn = print_insn_sparc;
102df0900ebSPeter Crosthwaite #ifdef TARGET_SPARC64
103df0900ebSPeter Crosthwaite     info->mach = bfd_mach_sparc_v9b;
104df0900ebSPeter Crosthwaite #endif
105df0900ebSPeter Crosthwaite }
106df0900ebSPeter Crosthwaite 
107fb02d56eSIgor Mammedov static void sparc_cpu_parse_features(CPUState *cs, char *features,
108fb02d56eSIgor Mammedov                                      Error **errp);
109fb02d56eSIgor Mammedov 
110433ac7a9SAndreas Färber static int cpu_sparc_register(SPARCCPU *cpu, const char *cpu_model)
111ab3b491fSBlue Swirl {
112433ac7a9SAndreas Färber     CPUSPARCState *env = &cpu->env;
113433ac7a9SAndreas Färber     char *s = g_strdup(cpu_model);
114433ac7a9SAndreas Färber     char *featurestr, *name = strtok(s, ",");
115ab3b491fSBlue Swirl     sparc_def_t def1, *def = &def1;
116433ac7a9SAndreas Färber     Error *err = NULL;
117ab3b491fSBlue Swirl 
118433ac7a9SAndreas Färber     if (cpu_sparc_find_by_name(def, name) < 0) {
119433ac7a9SAndreas Färber         g_free(s);
120ab3b491fSBlue Swirl         return -1;
121ab3b491fSBlue Swirl     }
122ab3b491fSBlue Swirl 
123a337f295SThomas Huth     env->def = g_memdup(def, sizeof(*def));
124433ac7a9SAndreas Färber 
125433ac7a9SAndreas Färber     featurestr = strtok(NULL, ",");
126fb02d56eSIgor Mammedov     sparc_cpu_parse_features(CPU(cpu), featurestr, &err);
127433ac7a9SAndreas Färber     g_free(s);
128433ac7a9SAndreas Färber     if (err) {
129565f65d2SMarkus Armbruster         error_report_err(err);
130433ac7a9SAndreas Färber         return -1;
131433ac7a9SAndreas Färber     }
132433ac7a9SAndreas Färber 
133ab3b491fSBlue Swirl     env->version = def->iu_version;
134ab3b491fSBlue Swirl     env->fsr = def->fpu_version;
135ab3b491fSBlue Swirl     env->nwindows = def->nwindows;
136ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
137ab3b491fSBlue Swirl     env->mmuregs[0] |= def->mmu_version;
138ab3b491fSBlue Swirl     cpu_sparc_set_id(env, 0);
139ab3b491fSBlue Swirl     env->mxccregs[7] |= def->mxcc_version;
140ab3b491fSBlue Swirl #else
141ab3b491fSBlue Swirl     env->mmu_version = def->mmu_version;
142ab3b491fSBlue Swirl     env->maxtl = def->maxtl;
143ab3b491fSBlue Swirl     env->version |= def->maxtl << 8;
144ab3b491fSBlue Swirl     env->version |= def->nwindows - 1;
145ab3b491fSBlue Swirl #endif
146ab3b491fSBlue Swirl     return 0;
147ab3b491fSBlue Swirl }
148ab3b491fSBlue Swirl 
149e59be77aSAndreas Färber SPARCCPU *cpu_sparc_init(const char *cpu_model)
150ab3b491fSBlue Swirl {
151ab7ab3d7SAndreas Färber     SPARCCPU *cpu;
152ab3b491fSBlue Swirl 
153ab7ab3d7SAndreas Färber     cpu = SPARC_CPU(object_new(TYPE_SPARC_CPU));
154ab3b491fSBlue Swirl 
155433ac7a9SAndreas Färber     if (cpu_sparc_register(cpu, cpu_model) < 0) {
1565c099537SPaolo Bonzini         object_unref(OBJECT(cpu));
157ab3b491fSBlue Swirl         return NULL;
158ab3b491fSBlue Swirl     }
159b6e91ebfSAndreas Färber 
160b6e91ebfSAndreas Färber     object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
161ab3b491fSBlue Swirl 
162e59be77aSAndreas Färber     return cpu;
163ab3b491fSBlue Swirl }
164ab3b491fSBlue Swirl 
165ab3b491fSBlue Swirl void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
166ab3b491fSBlue Swirl {
167ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
168ab3b491fSBlue Swirl     env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
169ab3b491fSBlue Swirl #endif
170ab3b491fSBlue Swirl }
171ab3b491fSBlue Swirl 
172ab3b491fSBlue Swirl static const sparc_def_t sparc_defs[] = {
173ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
174ab3b491fSBlue Swirl     {
175ab3b491fSBlue Swirl         .name = "Fujitsu Sparc64",
176ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
177ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
178ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
179ab3b491fSBlue Swirl         .nwindows = 4,
180ab3b491fSBlue Swirl         .maxtl = 4,
181ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
182ab3b491fSBlue Swirl     },
183ab3b491fSBlue Swirl     {
184ab3b491fSBlue Swirl         .name = "Fujitsu Sparc64 III",
185ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
186ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
187ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
188ab3b491fSBlue Swirl         .nwindows = 5,
189ab3b491fSBlue Swirl         .maxtl = 4,
190ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
191ab3b491fSBlue Swirl     },
192ab3b491fSBlue Swirl     {
193ab3b491fSBlue Swirl         .name = "Fujitsu Sparc64 IV",
194ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
195ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
196ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
197ab3b491fSBlue Swirl         .nwindows = 8,
198ab3b491fSBlue Swirl         .maxtl = 5,
199ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
200ab3b491fSBlue Swirl     },
201ab3b491fSBlue Swirl     {
202ab3b491fSBlue Swirl         .name = "Fujitsu Sparc64 V",
203ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
204ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
205ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
206ab3b491fSBlue Swirl         .nwindows = 8,
207ab3b491fSBlue Swirl         .maxtl = 5,
208ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
209ab3b491fSBlue Swirl     },
210ab3b491fSBlue Swirl     {
211ab3b491fSBlue Swirl         .name = "TI UltraSparc I",
212ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
213ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
214ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
215ab3b491fSBlue Swirl         .nwindows = 8,
216ab3b491fSBlue Swirl         .maxtl = 5,
217ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
218ab3b491fSBlue Swirl     },
219ab3b491fSBlue Swirl     {
220ab3b491fSBlue Swirl         .name = "TI UltraSparc II",
221ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
222ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
223ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
224ab3b491fSBlue Swirl         .nwindows = 8,
225ab3b491fSBlue Swirl         .maxtl = 5,
226ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
227ab3b491fSBlue Swirl     },
228ab3b491fSBlue Swirl     {
229ab3b491fSBlue Swirl         .name = "TI UltraSparc IIi",
230ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
231ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
232ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
233ab3b491fSBlue Swirl         .nwindows = 8,
234ab3b491fSBlue Swirl         .maxtl = 5,
235ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
236ab3b491fSBlue Swirl     },
237ab3b491fSBlue Swirl     {
238ab3b491fSBlue Swirl         .name = "TI UltraSparc IIe",
239ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
240ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
241ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
242ab3b491fSBlue Swirl         .nwindows = 8,
243ab3b491fSBlue Swirl         .maxtl = 5,
244ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
245ab3b491fSBlue Swirl     },
246ab3b491fSBlue Swirl     {
247ab3b491fSBlue Swirl         .name = "Sun UltraSparc III",
248ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
249ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
250ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
251ab3b491fSBlue Swirl         .nwindows = 8,
252ab3b491fSBlue Swirl         .maxtl = 5,
253ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
254ab3b491fSBlue Swirl     },
255ab3b491fSBlue Swirl     {
256ab3b491fSBlue Swirl         .name = "Sun UltraSparc III Cu",
257ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
258ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
259ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
260ab3b491fSBlue Swirl         .nwindows = 8,
261ab3b491fSBlue Swirl         .maxtl = 5,
262ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
263ab3b491fSBlue Swirl     },
264ab3b491fSBlue Swirl     {
265ab3b491fSBlue Swirl         .name = "Sun UltraSparc IIIi",
266ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
267ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
268ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
269ab3b491fSBlue Swirl         .nwindows = 8,
270ab3b491fSBlue Swirl         .maxtl = 5,
271ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
272ab3b491fSBlue Swirl     },
273ab3b491fSBlue Swirl     {
274ab3b491fSBlue Swirl         .name = "Sun UltraSparc IV",
275ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
276ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
277ab3b491fSBlue Swirl         .mmu_version = mmu_us_4,
278ab3b491fSBlue Swirl         .nwindows = 8,
279ab3b491fSBlue Swirl         .maxtl = 5,
280ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
281ab3b491fSBlue Swirl     },
282ab3b491fSBlue Swirl     {
283ab3b491fSBlue Swirl         .name = "Sun UltraSparc IV+",
284ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
285ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
286ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
287ab3b491fSBlue Swirl         .nwindows = 8,
288ab3b491fSBlue Swirl         .maxtl = 5,
289ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
290ab3b491fSBlue Swirl     },
291ab3b491fSBlue Swirl     {
292ab3b491fSBlue Swirl         .name = "Sun UltraSparc IIIi+",
293ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
294ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
295ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
296ab3b491fSBlue Swirl         .nwindows = 8,
297ab3b491fSBlue Swirl         .maxtl = 5,
298ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
299ab3b491fSBlue Swirl     },
300ab3b491fSBlue Swirl     {
301ab3b491fSBlue Swirl         .name = "Sun UltraSparc T1",
302ab3b491fSBlue Swirl         /* defined in sparc_ifu_fdp.v and ctu.h */
303ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
304ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
305ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
306ab3b491fSBlue Swirl         .nwindows = 8,
307ab3b491fSBlue Swirl         .maxtl = 6,
308ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
309ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
310ab3b491fSBlue Swirl     },
311ab3b491fSBlue Swirl     {
312ab3b491fSBlue Swirl         .name = "Sun UltraSparc T2",
313ab3b491fSBlue Swirl         /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
314ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
315ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
316ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
317ab3b491fSBlue Swirl         .nwindows = 8,
318ab3b491fSBlue Swirl         .maxtl = 6,
319ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
320ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
321ab3b491fSBlue Swirl     },
322ab3b491fSBlue Swirl     {
323ab3b491fSBlue Swirl         .name = "NEC UltraSparc I",
324ab3b491fSBlue Swirl         .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
325ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
326ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
327ab3b491fSBlue Swirl         .nwindows = 8,
328ab3b491fSBlue Swirl         .maxtl = 5,
329ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
330ab3b491fSBlue Swirl     },
331ab3b491fSBlue Swirl #else
332ab3b491fSBlue Swirl     {
333ab3b491fSBlue Swirl         .name = "Fujitsu MB86904",
334ab3b491fSBlue Swirl         .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
335ab3b491fSBlue Swirl         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
336ab3b491fSBlue Swirl         .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
337ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
338ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
339ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
340ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
341ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
342ab3b491fSBlue Swirl         .nwindows = 8,
343ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
344ab3b491fSBlue Swirl     },
345ab3b491fSBlue Swirl     {
346ab3b491fSBlue Swirl         .name = "Fujitsu MB86907",
347ab3b491fSBlue Swirl         .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
348ab3b491fSBlue Swirl         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
349ab3b491fSBlue Swirl         .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
350ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
351ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
352ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
353ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
354ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
355ab3b491fSBlue Swirl         .nwindows = 8,
356ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
357ab3b491fSBlue Swirl     },
358ab3b491fSBlue Swirl     {
359ab3b491fSBlue Swirl         .name = "TI MicroSparc I",
360ab3b491fSBlue Swirl         .iu_version = 0x41000000,
361ab3b491fSBlue Swirl         .fpu_version = 4 << 17,
362ab3b491fSBlue Swirl         .mmu_version = 0x41000000,
363ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
364ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
365ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
366ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
367ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x0000003f,
368ab3b491fSBlue Swirl         .nwindows = 7,
369ab3b491fSBlue Swirl         .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL |
370ab3b491fSBlue Swirl         CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT |
371ab3b491fSBlue Swirl         CPU_FEATURE_FMUL,
372ab3b491fSBlue Swirl     },
373ab3b491fSBlue Swirl     {
374ab3b491fSBlue Swirl         .name = "TI MicroSparc II",
375ab3b491fSBlue Swirl         .iu_version = 0x42000000,
376ab3b491fSBlue Swirl         .fpu_version = 4 << 17,
377ab3b491fSBlue Swirl         .mmu_version = 0x02000000,
378ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
379ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
380ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
381ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
382ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
383ab3b491fSBlue Swirl         .nwindows = 8,
384ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
385ab3b491fSBlue Swirl     },
386ab3b491fSBlue Swirl     {
387ab3b491fSBlue Swirl         .name = "TI MicroSparc IIep",
388ab3b491fSBlue Swirl         .iu_version = 0x42000000,
389ab3b491fSBlue Swirl         .fpu_version = 4 << 17,
390ab3b491fSBlue Swirl         .mmu_version = 0x04000000,
391ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
392ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
393ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
394ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016bff,
395ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
396ab3b491fSBlue Swirl         .nwindows = 8,
397ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
398ab3b491fSBlue Swirl     },
399ab3b491fSBlue Swirl     {
400ab3b491fSBlue Swirl         .name = "TI SuperSparc 40", /* STP1020NPGA */
401ab3b491fSBlue Swirl         .iu_version = 0x41000000, /* SuperSPARC 2.x */
402ab3b491fSBlue Swirl         .fpu_version = 0 << 17,
403ab3b491fSBlue Swirl         .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */
404ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
405ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
406ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
407ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
408ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
409ab3b491fSBlue Swirl         .nwindows = 8,
410ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
411ab3b491fSBlue Swirl     },
412ab3b491fSBlue Swirl     {
413ab3b491fSBlue Swirl         .name = "TI SuperSparc 50", /* STP1020PGA */
414ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
415ab3b491fSBlue Swirl         .fpu_version = 0 << 17,
416ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
417ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
418ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
419ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
420ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
421ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
422ab3b491fSBlue Swirl         .nwindows = 8,
423ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
424ab3b491fSBlue Swirl     },
425ab3b491fSBlue Swirl     {
426ab3b491fSBlue Swirl         .name = "TI SuperSparc 51",
427ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
428ab3b491fSBlue Swirl         .fpu_version = 0 << 17,
429ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
430ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
431ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
432ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
433ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
434ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
435ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
436ab3b491fSBlue Swirl         .nwindows = 8,
437ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
438ab3b491fSBlue Swirl     },
439ab3b491fSBlue Swirl     {
440ab3b491fSBlue Swirl         .name = "TI SuperSparc 60", /* STP1020APGA */
441ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
442ab3b491fSBlue Swirl         .fpu_version = 0 << 17,
443ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
444ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
445ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
446ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
447ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
448ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
449ab3b491fSBlue Swirl         .nwindows = 8,
450ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
451ab3b491fSBlue Swirl     },
452ab3b491fSBlue Swirl     {
453ab3b491fSBlue Swirl         .name = "TI SuperSparc 61",
454ab3b491fSBlue Swirl         .iu_version = 0x44000000, /* SuperSPARC 3.x */
455ab3b491fSBlue Swirl         .fpu_version = 0 << 17,
456ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
457ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
458ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
459ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
460ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
461ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
462ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
463ab3b491fSBlue Swirl         .nwindows = 8,
464ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
465ab3b491fSBlue Swirl     },
466ab3b491fSBlue Swirl     {
467ab3b491fSBlue Swirl         .name = "TI SuperSparc II",
468ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC II 1.x */
469ab3b491fSBlue Swirl         .fpu_version = 0 << 17,
470ab3b491fSBlue Swirl         .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */
471ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
472ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
473ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
474ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
475ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
476ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
477ab3b491fSBlue Swirl         .nwindows = 8,
478ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
479ab3b491fSBlue Swirl     },
480ab3b491fSBlue Swirl     {
481ab3b491fSBlue Swirl         .name = "LEON2",
482ab3b491fSBlue Swirl         .iu_version = 0xf2000000,
483ab3b491fSBlue Swirl         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
484ab3b491fSBlue Swirl         .mmu_version = 0xf2000000,
485ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
486ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
487ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
488ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
489ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
490ab3b491fSBlue Swirl         .nwindows = 8,
491ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
492ab3b491fSBlue Swirl     },
493ab3b491fSBlue Swirl     {
494ab3b491fSBlue Swirl         .name = "LEON3",
495ab3b491fSBlue Swirl         .iu_version = 0xf3000000,
496ab3b491fSBlue Swirl         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
497ab3b491fSBlue Swirl         .mmu_version = 0xf3000000,
498ab3b491fSBlue Swirl         .mmu_bm = 0x00000000,
4997a0a9c2cSRonald Hecht         .mmu_ctpr_mask = 0xfffffffc,
5007a0a9c2cSRonald Hecht         .mmu_cxr_mask = 0x000000ff,
501ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
502ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
503ab3b491fSBlue Swirl         .nwindows = 8,
504ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
50516c358e9SSebastian Huber         CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL | CPU_FEATURE_POWERDOWN |
50616c358e9SSebastian Huber         CPU_FEATURE_CASA,
507ab3b491fSBlue Swirl     },
508ab3b491fSBlue Swirl #endif
509ab3b491fSBlue Swirl };
510ab3b491fSBlue Swirl 
511ab3b491fSBlue Swirl static const char * const feature_name[] = {
512ab3b491fSBlue Swirl     "float",
513ab3b491fSBlue Swirl     "float128",
514ab3b491fSBlue Swirl     "swap",
515ab3b491fSBlue Swirl     "mul",
516ab3b491fSBlue Swirl     "div",
517ab3b491fSBlue Swirl     "flush",
518ab3b491fSBlue Swirl     "fsqrt",
519ab3b491fSBlue Swirl     "fmul",
520ab3b491fSBlue Swirl     "vis1",
521ab3b491fSBlue Swirl     "vis2",
522ab3b491fSBlue Swirl     "fsmuld",
523ab3b491fSBlue Swirl     "hypv",
524ab3b491fSBlue Swirl     "cmt",
525ab3b491fSBlue Swirl     "gl",
526ab3b491fSBlue Swirl };
527ab3b491fSBlue Swirl 
528ab3b491fSBlue Swirl static void print_features(FILE *f, fprintf_function cpu_fprintf,
529ab3b491fSBlue Swirl                            uint32_t features, const char *prefix)
530ab3b491fSBlue Swirl {
531ab3b491fSBlue Swirl     unsigned int i;
532ab3b491fSBlue Swirl 
533ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
534ab3b491fSBlue Swirl         if (feature_name[i] && (features & (1 << i))) {
535ab3b491fSBlue Swirl             if (prefix) {
536ab3b491fSBlue Swirl                 (*cpu_fprintf)(f, "%s", prefix);
537ab3b491fSBlue Swirl             }
538ab3b491fSBlue Swirl             (*cpu_fprintf)(f, "%s ", feature_name[i]);
539ab3b491fSBlue Swirl         }
540ab3b491fSBlue Swirl     }
541ab3b491fSBlue Swirl }
542ab3b491fSBlue Swirl 
543ab3b491fSBlue Swirl static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features)
544ab3b491fSBlue Swirl {
545ab3b491fSBlue Swirl     unsigned int i;
546ab3b491fSBlue Swirl 
547ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
548ab3b491fSBlue Swirl         if (feature_name[i] && !strcmp(flagname, feature_name[i])) {
549ab3b491fSBlue Swirl             *features |= 1 << i;
550ab3b491fSBlue Swirl             return;
551ab3b491fSBlue Swirl         }
552ab3b491fSBlue Swirl     }
553db5d39f7SAndreas Färber     error_report("CPU feature %s not found", flagname);
554ab3b491fSBlue Swirl }
555ab3b491fSBlue Swirl 
556433ac7a9SAndreas Färber static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *name)
557ab3b491fSBlue Swirl {
558ab3b491fSBlue Swirl     unsigned int i;
559ab3b491fSBlue Swirl     const sparc_def_t *def = NULL;
560ab3b491fSBlue Swirl 
561ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
562ab3b491fSBlue Swirl         if (strcasecmp(name, sparc_defs[i].name) == 0) {
563ab3b491fSBlue Swirl             def = &sparc_defs[i];
564ab3b491fSBlue Swirl         }
565ab3b491fSBlue Swirl     }
566ab3b491fSBlue Swirl     if (!def) {
567433ac7a9SAndreas Färber         return -1;
568ab3b491fSBlue Swirl     }
569ab3b491fSBlue Swirl     memcpy(cpu_def, def, sizeof(*def));
570433ac7a9SAndreas Färber     return 0;
571433ac7a9SAndreas Färber }
572ab3b491fSBlue Swirl 
573433ac7a9SAndreas Färber static void sparc_cpu_parse_features(CPUState *cs, char *features,
574433ac7a9SAndreas Färber                                      Error **errp)
575433ac7a9SAndreas Färber {
576433ac7a9SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
577433ac7a9SAndreas Färber     sparc_def_t *cpu_def = cpu->env.def;
578433ac7a9SAndreas Färber     char *featurestr;
579433ac7a9SAndreas Färber     uint32_t plus_features = 0;
580433ac7a9SAndreas Färber     uint32_t minus_features = 0;
581433ac7a9SAndreas Färber     uint64_t iu_version;
582433ac7a9SAndreas Färber     uint32_t fpu_version, mmu_version, nwindows;
583433ac7a9SAndreas Färber 
584433ac7a9SAndreas Färber     featurestr = features ? strtok(features, ",") : NULL;
585ab3b491fSBlue Swirl     while (featurestr) {
586ab3b491fSBlue Swirl         char *val;
587ab3b491fSBlue Swirl 
588ab3b491fSBlue Swirl         if (featurestr[0] == '+') {
589ab3b491fSBlue Swirl             add_flagname_to_bitmaps(featurestr + 1, &plus_features);
590ab3b491fSBlue Swirl         } else if (featurestr[0] == '-') {
591ab3b491fSBlue Swirl             add_flagname_to_bitmaps(featurestr + 1, &minus_features);
592ab3b491fSBlue Swirl         } else if ((val = strchr(featurestr, '='))) {
593ab3b491fSBlue Swirl             *val = 0; val++;
594ab3b491fSBlue Swirl             if (!strcmp(featurestr, "iu_version")) {
595ab3b491fSBlue Swirl                 char *err;
596ab3b491fSBlue Swirl 
597ab3b491fSBlue Swirl                 iu_version = strtoll(val, &err, 0);
598ab3b491fSBlue Swirl                 if (!*val || *err) {
599433ac7a9SAndreas Färber                     error_setg(errp, "bad numerical value %s", val);
600433ac7a9SAndreas Färber                     return;
601ab3b491fSBlue Swirl                 }
602ab3b491fSBlue Swirl                 cpu_def->iu_version = iu_version;
603ab3b491fSBlue Swirl #ifdef DEBUG_FEATURES
604ab3b491fSBlue Swirl                 fprintf(stderr, "iu_version %" PRIx64 "\n", iu_version);
605ab3b491fSBlue Swirl #endif
606ab3b491fSBlue Swirl             } else if (!strcmp(featurestr, "fpu_version")) {
607ab3b491fSBlue Swirl                 char *err;
608ab3b491fSBlue Swirl 
609ab3b491fSBlue Swirl                 fpu_version = strtol(val, &err, 0);
610ab3b491fSBlue Swirl                 if (!*val || *err) {
611433ac7a9SAndreas Färber                     error_setg(errp, "bad numerical value %s", val);
612433ac7a9SAndreas Färber                     return;
613ab3b491fSBlue Swirl                 }
614ab3b491fSBlue Swirl                 cpu_def->fpu_version = fpu_version;
615ab3b491fSBlue Swirl #ifdef DEBUG_FEATURES
616ab3b491fSBlue Swirl                 fprintf(stderr, "fpu_version %x\n", fpu_version);
617ab3b491fSBlue Swirl #endif
618ab3b491fSBlue Swirl             } else if (!strcmp(featurestr, "mmu_version")) {
619ab3b491fSBlue Swirl                 char *err;
620ab3b491fSBlue Swirl 
621ab3b491fSBlue Swirl                 mmu_version = strtol(val, &err, 0);
622ab3b491fSBlue Swirl                 if (!*val || *err) {
623433ac7a9SAndreas Färber                     error_setg(errp, "bad numerical value %s", val);
624433ac7a9SAndreas Färber                     return;
625ab3b491fSBlue Swirl                 }
626ab3b491fSBlue Swirl                 cpu_def->mmu_version = mmu_version;
627ab3b491fSBlue Swirl #ifdef DEBUG_FEATURES
628ab3b491fSBlue Swirl                 fprintf(stderr, "mmu_version %x\n", mmu_version);
629ab3b491fSBlue Swirl #endif
630ab3b491fSBlue Swirl             } else if (!strcmp(featurestr, "nwindows")) {
631ab3b491fSBlue Swirl                 char *err;
632ab3b491fSBlue Swirl 
633ab3b491fSBlue Swirl                 nwindows = strtol(val, &err, 0);
634ab3b491fSBlue Swirl                 if (!*val || *err || nwindows > MAX_NWINDOWS ||
635ab3b491fSBlue Swirl                     nwindows < MIN_NWINDOWS) {
636433ac7a9SAndreas Färber                     error_setg(errp, "bad numerical value %s", val);
637433ac7a9SAndreas Färber                     return;
638ab3b491fSBlue Swirl                 }
639ab3b491fSBlue Swirl                 cpu_def->nwindows = nwindows;
640ab3b491fSBlue Swirl #ifdef DEBUG_FEATURES
641ab3b491fSBlue Swirl                 fprintf(stderr, "nwindows %d\n", nwindows);
642ab3b491fSBlue Swirl #endif
643ab3b491fSBlue Swirl             } else {
644433ac7a9SAndreas Färber                 error_setg(errp, "unrecognized feature %s", featurestr);
645433ac7a9SAndreas Färber                 return;
646ab3b491fSBlue Swirl             }
647ab3b491fSBlue Swirl         } else {
648433ac7a9SAndreas Färber             error_setg(errp, "feature string `%s' not in format "
649db5d39f7SAndreas Färber                              "(+feature|-feature|feature=xyz)", featurestr);
650433ac7a9SAndreas Färber             return;
651ab3b491fSBlue Swirl         }
652ab3b491fSBlue Swirl         featurestr = strtok(NULL, ",");
653ab3b491fSBlue Swirl     }
654ab3b491fSBlue Swirl     cpu_def->features |= plus_features;
655ab3b491fSBlue Swirl     cpu_def->features &= ~minus_features;
656ab3b491fSBlue Swirl #ifdef DEBUG_FEATURES
657ab3b491fSBlue Swirl     print_features(stderr, fprintf, cpu_def->features, NULL);
658ab3b491fSBlue Swirl #endif
659ab3b491fSBlue Swirl }
660ab3b491fSBlue Swirl 
661ab3b491fSBlue Swirl void sparc_cpu_list(FILE *f, fprintf_function cpu_fprintf)
662ab3b491fSBlue Swirl {
663ab3b491fSBlue Swirl     unsigned int i;
664ab3b491fSBlue Swirl 
665ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
666ab3b491fSBlue Swirl         (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx
667ab3b491fSBlue Swirl                        " FPU %08x MMU %08x NWINS %d ",
668ab3b491fSBlue Swirl                        sparc_defs[i].name,
669ab3b491fSBlue Swirl                        sparc_defs[i].iu_version,
670ab3b491fSBlue Swirl                        sparc_defs[i].fpu_version,
671ab3b491fSBlue Swirl                        sparc_defs[i].mmu_version,
672ab3b491fSBlue Swirl                        sparc_defs[i].nwindows);
673ab3b491fSBlue Swirl         print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES &
674ab3b491fSBlue Swirl                        ~sparc_defs[i].features, "-");
675ab3b491fSBlue Swirl         print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES &
676ab3b491fSBlue Swirl                        sparc_defs[i].features, "+");
677ab3b491fSBlue Swirl         (*cpu_fprintf)(f, "\n");
678ab3b491fSBlue Swirl     }
679ab3b491fSBlue Swirl     (*cpu_fprintf)(f, "Default CPU feature flags (use '-' to remove): ");
680ab3b491fSBlue Swirl     print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES, NULL);
681ab3b491fSBlue Swirl     (*cpu_fprintf)(f, "\n");
682ab3b491fSBlue Swirl     (*cpu_fprintf)(f, "Available CPU feature flags (use '+' to add): ");
683ab3b491fSBlue Swirl     print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES, NULL);
684ab3b491fSBlue Swirl     (*cpu_fprintf)(f, "\n");
685ab3b491fSBlue Swirl     (*cpu_fprintf)(f, "Numerical features (use '=' to set): iu_version "
686ab3b491fSBlue Swirl                    "fpu_version mmu_version nwindows\n");
687ab3b491fSBlue Swirl }
688ab3b491fSBlue Swirl 
689ab3b491fSBlue Swirl static void cpu_print_cc(FILE *f, fprintf_function cpu_fprintf,
690ab3b491fSBlue Swirl                          uint32_t cc)
691ab3b491fSBlue Swirl {
692ab3b491fSBlue Swirl     cpu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
693ab3b491fSBlue Swirl                 cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
694ab3b491fSBlue Swirl                 cc & PSR_CARRY ? 'C' : '-');
695ab3b491fSBlue Swirl }
696ab3b491fSBlue Swirl 
697ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
698ab3b491fSBlue Swirl #define REGS_PER_LINE 4
699ab3b491fSBlue Swirl #else
700ab3b491fSBlue Swirl #define REGS_PER_LINE 8
701ab3b491fSBlue Swirl #endif
702ab3b491fSBlue Swirl 
703878096eeSAndreas Färber void sparc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
704ab3b491fSBlue Swirl                           int flags)
705ab3b491fSBlue Swirl {
706878096eeSAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
707878096eeSAndreas Färber     CPUSPARCState *env = &cpu->env;
708ab3b491fSBlue Swirl     int i, x;
709ab3b491fSBlue Swirl 
710ab3b491fSBlue Swirl     cpu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
711ab3b491fSBlue Swirl                 env->npc);
712ab3b491fSBlue Swirl 
713ab3b491fSBlue Swirl     for (i = 0; i < 8; i++) {
714ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == 0) {
715ab3b491fSBlue Swirl             cpu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
716ab3b491fSBlue Swirl         }
717ab3b491fSBlue Swirl         cpu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
718ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
719ab3b491fSBlue Swirl             cpu_fprintf(f, "\n");
720ab3b491fSBlue Swirl         }
721ab3b491fSBlue Swirl     }
722ab3b491fSBlue Swirl     for (x = 0; x < 3; x++) {
723ab3b491fSBlue Swirl         for (i = 0; i < 8; i++) {
724ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == 0) {
725ab3b491fSBlue Swirl                 cpu_fprintf(f, "%%%c%d-%d: ",
726ab3b491fSBlue Swirl                             x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
727ab3b491fSBlue Swirl                             i, i + REGS_PER_LINE - 1);
728ab3b491fSBlue Swirl             }
729ab3b491fSBlue Swirl             cpu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
730ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
731ab3b491fSBlue Swirl                 cpu_fprintf(f, "\n");
732ab3b491fSBlue Swirl             }
733ab3b491fSBlue Swirl         }
734ab3b491fSBlue Swirl     }
73576a23ca0SRichard Henderson 
73630038fd8SRichard Henderson     for (i = 0; i < TARGET_DPREGS; i++) {
737ab3b491fSBlue Swirl         if ((i & 3) == 0) {
73830038fd8SRichard Henderson             cpu_fprintf(f, "%%f%02d: ", i * 2);
739ab3b491fSBlue Swirl         }
74030038fd8SRichard Henderson         cpu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
741ab3b491fSBlue Swirl         if ((i & 3) == 3) {
742ab3b491fSBlue Swirl             cpu_fprintf(f, "\n");
743ab3b491fSBlue Swirl         }
744ab3b491fSBlue Swirl     }
745ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
746ab3b491fSBlue Swirl     cpu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
747ab3b491fSBlue Swirl                 (unsigned)cpu_get_ccr(env));
748ab3b491fSBlue Swirl     cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
749ab3b491fSBlue Swirl     cpu_fprintf(f, " xcc: ");
750ab3b491fSBlue Swirl     cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
751*cbc3a6a4SArtyom Tarasenko     cpu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
752*cbc3a6a4SArtyom Tarasenko                 env->psrpil, env->gl);
753*cbc3a6a4SArtyom Tarasenko     cpu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
754*cbc3a6a4SArtyom Tarasenko                 TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
755ab3b491fSBlue Swirl     cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
756ab3b491fSBlue Swirl                 "cleanwin: %d cwp: %d\n",
757ab3b491fSBlue Swirl                 env->cansave, env->canrestore, env->otherwin, env->wstate,
758ab3b491fSBlue Swirl                 env->cleanwin, env->nwindows - 1 - env->cwp);
759ab3b491fSBlue Swirl     cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: "
760ab3b491fSBlue Swirl                 TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs);
761*cbc3a6a4SArtyom Tarasenko 
762ab3b491fSBlue Swirl #else
763ab3b491fSBlue Swirl     cpu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
764ab3b491fSBlue Swirl     cpu_print_cc(f, cpu_fprintf, cpu_get_psr(env));
765ab3b491fSBlue Swirl     cpu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
766ab3b491fSBlue Swirl                 env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
767ab3b491fSBlue Swirl                 env->wim);
768ab3b491fSBlue Swirl     cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
769ab3b491fSBlue Swirl                 env->fsr, env->y);
770ab3b491fSBlue Swirl #endif
77176a23ca0SRichard Henderson     cpu_fprintf(f, "\n");
772ab3b491fSBlue Swirl }
773ab7ab3d7SAndreas Färber 
774f45748f1SAndreas Färber static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
775f45748f1SAndreas Färber {
776f45748f1SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
777f45748f1SAndreas Färber 
778f45748f1SAndreas Färber     cpu->env.pc = value;
779f45748f1SAndreas Färber     cpu->env.npc = value + 4;
780f45748f1SAndreas Färber }
781f45748f1SAndreas Färber 
782bdf7ae5bSAndreas Färber static void sparc_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
783bdf7ae5bSAndreas Färber {
784bdf7ae5bSAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
785bdf7ae5bSAndreas Färber 
786bdf7ae5bSAndreas Färber     cpu->env.pc = tb->pc;
787bdf7ae5bSAndreas Färber     cpu->env.npc = tb->cs_base;
788bdf7ae5bSAndreas Färber }
789bdf7ae5bSAndreas Färber 
7908c2e1b00SAndreas Färber static bool sparc_cpu_has_work(CPUState *cs)
7918c2e1b00SAndreas Färber {
7928c2e1b00SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
7938c2e1b00SAndreas Färber     CPUSPARCState *env = &cpu->env;
7948c2e1b00SAndreas Färber 
7958c2e1b00SAndreas Färber     return (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
7968c2e1b00SAndreas Färber            cpu_interrupts_enabled(env);
7978c2e1b00SAndreas Färber }
7988c2e1b00SAndreas Färber 
799b6e91ebfSAndreas Färber static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
800b6e91ebfSAndreas Färber {
801ce5b1bbfSLaurent Vivier     CPUState *cs = CPU(dev);
802b6e91ebfSAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
803ce5b1bbfSLaurent Vivier     Error *local_err = NULL;
804247bf011SAndreas Färber #if defined(CONFIG_USER_ONLY)
805247bf011SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(dev);
806247bf011SAndreas Färber     CPUSPARCState *env = &cpu->env;
807247bf011SAndreas Färber 
808247bf011SAndreas Färber     if ((env->def->features & CPU_FEATURE_FLOAT)) {
809247bf011SAndreas Färber         env->def->features |= CPU_FEATURE_FLOAT128;
810247bf011SAndreas Färber     }
811247bf011SAndreas Färber #endif
812b6e91ebfSAndreas Färber 
813ce5b1bbfSLaurent Vivier     cpu_exec_realizefn(cs, &local_err);
814ce5b1bbfSLaurent Vivier     if (local_err != NULL) {
815ce5b1bbfSLaurent Vivier         error_propagate(errp, local_err);
816ce5b1bbfSLaurent Vivier         return;
817ce5b1bbfSLaurent Vivier     }
818ce5b1bbfSLaurent Vivier 
819ce5b1bbfSLaurent Vivier     qemu_init_vcpu(cs);
82014a10fc3SAndreas Färber 
821b6e91ebfSAndreas Färber     scc->parent_realize(dev, errp);
822b6e91ebfSAndreas Färber }
823b6e91ebfSAndreas Färber 
824ab7ab3d7SAndreas Färber static void sparc_cpu_initfn(Object *obj)
825ab7ab3d7SAndreas Färber {
826c05efcb1SAndreas Färber     CPUState *cs = CPU(obj);
827ab7ab3d7SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(obj);
828ab7ab3d7SAndreas Färber     CPUSPARCState *env = &cpu->env;
829ab7ab3d7SAndreas Färber 
830c05efcb1SAndreas Färber     cs->env_ptr = env;
8315266d20aSAndreas Färber 
8325266d20aSAndreas Färber     if (tcg_enabled()) {
8335266d20aSAndreas Färber         gen_intermediate_code_init(env);
8345266d20aSAndreas Färber     }
835ab7ab3d7SAndreas Färber }
836ab7ab3d7SAndreas Färber 
837ab7ab3d7SAndreas Färber static void sparc_cpu_uninitfn(Object *obj)
838ab7ab3d7SAndreas Färber {
839ab7ab3d7SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(obj);
840ab7ab3d7SAndreas Färber     CPUSPARCState *env = &cpu->env;
841ab7ab3d7SAndreas Färber 
842ab7ab3d7SAndreas Färber     g_free(env->def);
843ab7ab3d7SAndreas Färber }
844ab7ab3d7SAndreas Färber 
845ab7ab3d7SAndreas Färber static void sparc_cpu_class_init(ObjectClass *oc, void *data)
846ab7ab3d7SAndreas Färber {
847ab7ab3d7SAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
848ab7ab3d7SAndreas Färber     CPUClass *cc = CPU_CLASS(oc);
849b6e91ebfSAndreas Färber     DeviceClass *dc = DEVICE_CLASS(oc);
850b6e91ebfSAndreas Färber 
851b6e91ebfSAndreas Färber     scc->parent_realize = dc->realize;
852b6e91ebfSAndreas Färber     dc->realize = sparc_cpu_realizefn;
853ab7ab3d7SAndreas Färber 
854ab7ab3d7SAndreas Färber     scc->parent_reset = cc->reset;
855ab7ab3d7SAndreas Färber     cc->reset = sparc_cpu_reset;
85697a8ea5aSAndreas Färber 
8578c2e1b00SAndreas Färber     cc->has_work = sparc_cpu_has_work;
85897a8ea5aSAndreas Färber     cc->do_interrupt = sparc_cpu_do_interrupt;
85987afe467SRichard Henderson     cc->cpu_exec_interrupt = sparc_cpu_exec_interrupt;
860878096eeSAndreas Färber     cc->dump_state = sparc_cpu_dump_state;
861f3659eeeSAndreas Färber #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
862f3659eeeSAndreas Färber     cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
863f3659eeeSAndreas Färber #endif
864f45748f1SAndreas Färber     cc->set_pc = sparc_cpu_set_pc;
865bdf7ae5bSAndreas Färber     cc->synchronize_from_tb = sparc_cpu_synchronize_from_tb;
8665b50e790SAndreas Färber     cc->gdb_read_register = sparc_cpu_gdb_read_register;
8675b50e790SAndreas Färber     cc->gdb_write_register = sparc_cpu_gdb_write_register;
8687510454eSAndreas Färber #ifdef CONFIG_USER_ONLY
8697510454eSAndreas Färber     cc->handle_mmu_fault = sparc_cpu_handle_mmu_fault;
8707510454eSAndreas Färber #else
87100b941e5SAndreas Färber     cc->do_unassigned_access = sparc_cpu_unassigned_access;
87293e22326SPaolo Bonzini     cc->do_unaligned_access = sparc_cpu_do_unaligned_access;
87300b941e5SAndreas Färber     cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug;
874df32c8d4SJuan Quintela     cc->vmsd = &vmstate_sparc_cpu;
87500b941e5SAndreas Färber #endif
876df0900ebSPeter Crosthwaite     cc->disas_set_info = cpu_sparc_disas_set_info;
877a0e372f0SAndreas Färber 
878a0e372f0SAndreas Färber #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
879a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 86;
880a0e372f0SAndreas Färber #else
881a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 72;
882a0e372f0SAndreas Färber #endif
883ab7ab3d7SAndreas Färber }
884ab7ab3d7SAndreas Färber 
885ab7ab3d7SAndreas Färber static const TypeInfo sparc_cpu_type_info = {
886ab7ab3d7SAndreas Färber     .name = TYPE_SPARC_CPU,
887ab7ab3d7SAndreas Färber     .parent = TYPE_CPU,
888ab7ab3d7SAndreas Färber     .instance_size = sizeof(SPARCCPU),
889ab7ab3d7SAndreas Färber     .instance_init = sparc_cpu_initfn,
890ab7ab3d7SAndreas Färber     .instance_finalize = sparc_cpu_uninitfn,
891ab7ab3d7SAndreas Färber     .abstract = false,
892ab7ab3d7SAndreas Färber     .class_size = sizeof(SPARCCPUClass),
893ab7ab3d7SAndreas Färber     .class_init = sparc_cpu_class_init,
894ab7ab3d7SAndreas Färber };
895ab7ab3d7SAndreas Färber 
896ab7ab3d7SAndreas Färber static void sparc_cpu_register_types(void)
897ab7ab3d7SAndreas Färber {
898ab7ab3d7SAndreas Färber     type_register_static(&sparc_cpu_type_info);
899ab7ab3d7SAndreas Färber }
900ab7ab3d7SAndreas Färber 
901ab7ab3d7SAndreas Färber type_init(sparc_cpu_register_types)
902