xref: /qemu/target/sparc/cpu.c (revision 8865049bab9957eb5b027d3e53bd05316817ea07)
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
95650b549SChetan Pant  * version 2.1 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"
230b8fa32fSMarkus Armbruster #include "qemu/module.h"
240442428aSMarkus Armbruster #include "qemu/qemu-print.h"
2563c91552SPaolo Bonzini #include "exec/exec-all.h"
26*8865049bSPhilippe Mathieu-Daudé #include "exec/translation-block.h"
27de05005bSIgor Mammedov #include "hw/qdev-properties.h"
28de05005bSIgor Mammedov #include "qapi/visitor.h"
29c4bf3a92SAnton Johansson #include "tcg/tcg.h"
304482f32dSPeter Maydell #include "fpu/softfloat.h"
31fc3630b2SPhilippe Mathieu-Daudé #include "target/sparc/translate.h"
32ab3b491fSBlue Swirl 
33ab3b491fSBlue Swirl //#define DEBUG_FEATURES
34ab3b491fSBlue Swirl 
35ad80e367SPeter Maydell static void sparc_cpu_reset_hold(Object *obj, ResetType type)
36ab7ab3d7SAndreas Färber {
37348802b5SPhilippe Mathieu-Daudé     CPUState *cs = CPU(obj);
38348802b5SPhilippe Mathieu-Daudé     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
3977976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
40ab7ab3d7SAndreas Färber 
413b4fff1bSPeter Maydell     if (scc->parent_phases.hold) {
42ad80e367SPeter Maydell         scc->parent_phases.hold(obj, type);
433b4fff1bSPeter Maydell     }
44ab7ab3d7SAndreas Färber 
451f5c00cfSAlex Bennée     memset(env, 0, offsetof(CPUSPARCState, end_reset_fields));
46ab3b491fSBlue Swirl     env->cwp = 0;
47ab3b491fSBlue Swirl #ifndef TARGET_SPARC64
48ab3b491fSBlue Swirl     env->wim = 1;
49ab3b491fSBlue Swirl #endif
50ab3b491fSBlue Swirl     env->regwptr = env->regbase + (env->cwp * 16);
51ab3b491fSBlue Swirl #if defined(CONFIG_USER_ONLY)
52ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
53ab3b491fSBlue Swirl     env->cleanwin = env->nwindows - 2;
54ab3b491fSBlue Swirl     env->cansave = env->nwindows - 2;
55ab3b491fSBlue Swirl     env->pstate = PS_RMO | PS_PEF | PS_IE;
56ab3b491fSBlue Swirl     env->asi = 0x82; /* Primary no-fault */
57ab3b491fSBlue Swirl #endif
58ab3b491fSBlue Swirl #else
59ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
60ab3b491fSBlue Swirl     env->psret = 0;
61ab3b491fSBlue Swirl     env->psrs = 1;
62ab3b491fSBlue Swirl     env->psrps = 1;
63ab3b491fSBlue Swirl #endif
64ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
65cbc3a6a4SArtyom Tarasenko     env->pstate = PS_PRIV | PS_RED | PS_PEF;
66cbc3a6a4SArtyom Tarasenko     if (!cpu_has_hypervisor(env)) {
67cbc3a6a4SArtyom Tarasenko         env->pstate |= PS_AG;
68cbc3a6a4SArtyom Tarasenko     }
69ab3b491fSBlue Swirl     env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0;
70ab3b491fSBlue Swirl     env->tl = env->maxtl;
71cbc3a6a4SArtyom Tarasenko     env->gl = 2;
72ab3b491fSBlue Swirl     cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
73ab3b491fSBlue Swirl     env->lsu = 0;
74ab3b491fSBlue Swirl #else
75ab3b491fSBlue Swirl     env->mmuregs[0] &= ~(MMU_E | MMU_NF);
76576e1c4cSIgor Mammedov     env->mmuregs[0] |= env->def.mmu_bm;
77ab3b491fSBlue Swirl #endif
78ab3b491fSBlue Swirl     env->pc = 0;
79ab3b491fSBlue Swirl     env->npc = env->pc + 4;
80ab3b491fSBlue Swirl #endif
81ab3b491fSBlue Swirl     env->cache_control = 0;
8265c1c039SPeter Maydell     cpu_put_fsr(env, 0);
83ab3b491fSBlue Swirl }
84ab3b491fSBlue Swirl 
85798ac8b5SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
8687afe467SRichard Henderson static bool sparc_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
8787afe467SRichard Henderson {
8887afe467SRichard Henderson     if (interrupt_request & CPU_INTERRUPT_HARD) {
8977976769SPhilippe Mathieu-Daudé         CPUSPARCState *env = cpu_env(cs);
9087afe467SRichard Henderson 
9187afe467SRichard Henderson         if (cpu_interrupts_enabled(env) && env->interrupt_index > 0) {
9287afe467SRichard Henderson             int pil = env->interrupt_index & 0xf;
9387afe467SRichard Henderson             int type = env->interrupt_index & 0xf0;
9487afe467SRichard Henderson 
9587afe467SRichard Henderson             if (type != TT_EXTINT || cpu_pil_allowed(env, pil)) {
9687afe467SRichard Henderson                 cs->exception_index = env->interrupt_index;
9787afe467SRichard Henderson                 sparc_cpu_do_interrupt(cs);
9887afe467SRichard Henderson                 return true;
9987afe467SRichard Henderson             }
10087afe467SRichard Henderson         }
10187afe467SRichard Henderson     }
10287afe467SRichard Henderson     return false;
10387afe467SRichard Henderson }
104798ac8b5SPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
10587afe467SRichard Henderson 
106df0900ebSPeter Crosthwaite static void cpu_sparc_disas_set_info(CPUState *cpu, disassemble_info *info)
107df0900ebSPeter Crosthwaite {
108df0900ebSPeter Crosthwaite     info->print_insn = print_insn_sparc;
109df0900ebSPeter Crosthwaite #ifdef TARGET_SPARC64
110df0900ebSPeter Crosthwaite     info->mach = bfd_mach_sparc_v9b;
111df0900ebSPeter Crosthwaite #endif
112df0900ebSPeter Crosthwaite }
113df0900ebSPeter Crosthwaite 
114d1853231SIgor Mammedov static void
115d1853231SIgor Mammedov cpu_add_feat_as_prop(const char *typename, const char *name, const char *val)
116ab3b491fSBlue Swirl {
117d1853231SIgor Mammedov     GlobalProperty *prop = g_new0(typeof(*prop), 1);
118d1853231SIgor Mammedov     prop->driver = typename;
119d1853231SIgor Mammedov     prop->property = g_strdup(name);
120d1853231SIgor Mammedov     prop->value = g_strdup(val);
121d1853231SIgor Mammedov     qdev_prop_register_global(prop);
122433ac7a9SAndreas Färber }
123433ac7a9SAndreas Färber 
124d1853231SIgor Mammedov /* Parse "+feature,-feature,feature=foo" CPU feature string */
125d1853231SIgor Mammedov static void sparc_cpu_parse_features(const char *typename, char *features,
126d1853231SIgor Mammedov                                      Error **errp)
127d1853231SIgor Mammedov {
128d1853231SIgor Mammedov     GList *l, *plus_features = NULL, *minus_features = NULL;
129d1853231SIgor Mammedov     char *featurestr; /* Single 'key=value" string being parsed */
130d1853231SIgor Mammedov     static bool cpu_globals_initialized;
131d1853231SIgor Mammedov 
132d1853231SIgor Mammedov     if (cpu_globals_initialized) {
133d1853231SIgor Mammedov         return;
134d1853231SIgor Mammedov     }
135d1853231SIgor Mammedov     cpu_globals_initialized = true;
136d1853231SIgor Mammedov 
137d1853231SIgor Mammedov     if (!features) {
138d1853231SIgor Mammedov         return;
139d1853231SIgor Mammedov     }
140d1853231SIgor Mammedov 
141d1853231SIgor Mammedov     for (featurestr = strtok(features, ",");
142d1853231SIgor Mammedov          featurestr;
143d1853231SIgor Mammedov          featurestr = strtok(NULL, ",")) {
144d1853231SIgor Mammedov         const char *name;
145d1853231SIgor Mammedov         const char *val = NULL;
146d1853231SIgor Mammedov         char *eq = NULL;
147d1853231SIgor Mammedov 
148d1853231SIgor Mammedov         /* Compatibility syntax: */
149d1853231SIgor Mammedov         if (featurestr[0] == '+') {
150d1853231SIgor Mammedov             plus_features = g_list_append(plus_features,
151d1853231SIgor Mammedov                                           g_strdup(featurestr + 1));
152d1853231SIgor Mammedov             continue;
153d1853231SIgor Mammedov         } else if (featurestr[0] == '-') {
154d1853231SIgor Mammedov             minus_features = g_list_append(minus_features,
155d1853231SIgor Mammedov                                            g_strdup(featurestr + 1));
156d1853231SIgor Mammedov             continue;
157d1853231SIgor Mammedov         }
158d1853231SIgor Mammedov 
159d1853231SIgor Mammedov         eq = strchr(featurestr, '=');
160d1853231SIgor Mammedov         name = featurestr;
161d1853231SIgor Mammedov         if (eq) {
162d1853231SIgor Mammedov             *eq++ = 0;
163d1853231SIgor Mammedov             val = eq;
164d1853231SIgor Mammedov 
165d1853231SIgor Mammedov             /*
166d1853231SIgor Mammedov              * Temporarily, only +feat/-feat will be supported
167d1853231SIgor Mammedov              * for boolean properties until we remove the
168d1853231SIgor Mammedov              * minus-overrides-plus semantics and just follow
169d1853231SIgor Mammedov              * the order options appear on the command-line.
170d1853231SIgor Mammedov              *
171d1853231SIgor Mammedov              * TODO: warn if user is relying on minus-override-plus semantics
172d1853231SIgor Mammedov              * TODO: remove minus-override-plus semantics after
173d1853231SIgor Mammedov              *       warning for a few releases
174d1853231SIgor Mammedov              */
175d1853231SIgor Mammedov             if (!strcasecmp(val, "on") ||
176d1853231SIgor Mammedov                 !strcasecmp(val, "off") ||
177d1853231SIgor Mammedov                 !strcasecmp(val, "true") ||
178d1853231SIgor Mammedov                 !strcasecmp(val, "false")) {
179d1853231SIgor Mammedov                 error_setg(errp, "Boolean properties in format %s=%s"
180d1853231SIgor Mammedov                                  " are not supported", name, val);
181d1853231SIgor Mammedov                 return;
182d1853231SIgor Mammedov             }
183d1853231SIgor Mammedov         } else {
184d1853231SIgor Mammedov             error_setg(errp, "Unsupported property format: %s", name);
185d1853231SIgor Mammedov             return;
186d1853231SIgor Mammedov         }
187d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, val);
188d1853231SIgor Mammedov     }
189d1853231SIgor Mammedov 
190d1853231SIgor Mammedov     for (l = plus_features; l; l = l->next) {
191d1853231SIgor Mammedov         const char *name = l->data;
192d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, "on");
193d1853231SIgor Mammedov     }
194d1853231SIgor Mammedov     g_list_free_full(plus_features, g_free);
195d1853231SIgor Mammedov 
196d1853231SIgor Mammedov     for (l = minus_features; l; l = l->next) {
197d1853231SIgor Mammedov         const char *name = l->data;
198d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, "off");
199d1853231SIgor Mammedov     }
200d1853231SIgor Mammedov     g_list_free_full(minus_features, g_free);
201ab3b491fSBlue Swirl }
202ab3b491fSBlue Swirl 
203ab3b491fSBlue Swirl void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
204ab3b491fSBlue Swirl {
205ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
206ab3b491fSBlue Swirl     env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
207ab3b491fSBlue Swirl #endif
208ab3b491fSBlue Swirl }
209ab3b491fSBlue Swirl 
210ab3b491fSBlue Swirl static const sparc_def_t sparc_defs[] = {
211ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
212ab3b491fSBlue Swirl     {
2134a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64",
214ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
215ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
216ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
217ab3b491fSBlue Swirl         .nwindows = 4,
218ab3b491fSBlue Swirl         .maxtl = 4,
219ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
220ab3b491fSBlue Swirl     },
221ab3b491fSBlue Swirl     {
2224a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-III",
223ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
224ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
225ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
226ab3b491fSBlue Swirl         .nwindows = 5,
227ab3b491fSBlue Swirl         .maxtl = 4,
228ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
229ab3b491fSBlue Swirl     },
230ab3b491fSBlue Swirl     {
2314a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-IV",
232ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
233ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
234ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
235ab3b491fSBlue Swirl         .nwindows = 8,
236ab3b491fSBlue Swirl         .maxtl = 5,
237ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
238ab3b491fSBlue Swirl     },
239ab3b491fSBlue Swirl     {
2404a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-V",
241ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
242ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
243ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
244ab3b491fSBlue Swirl         .nwindows = 8,
245ab3b491fSBlue Swirl         .maxtl = 5,
246ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
247ab3b491fSBlue Swirl     },
248ab3b491fSBlue Swirl     {
2494a7bdec3SThomas Huth         .name = "TI-UltraSparc-I",
250ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
251ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
252ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
253ab3b491fSBlue Swirl         .nwindows = 8,
254ab3b491fSBlue Swirl         .maxtl = 5,
255ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
256ab3b491fSBlue Swirl     },
257ab3b491fSBlue Swirl     {
2584a7bdec3SThomas Huth         .name = "TI-UltraSparc-II",
259ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
260ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
261ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
262ab3b491fSBlue Swirl         .nwindows = 8,
263ab3b491fSBlue Swirl         .maxtl = 5,
264ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
265ab3b491fSBlue Swirl     },
266ab3b491fSBlue Swirl     {
2674a7bdec3SThomas Huth         .name = "TI-UltraSparc-IIi",
268ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
269ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
270ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
271ab3b491fSBlue Swirl         .nwindows = 8,
272ab3b491fSBlue Swirl         .maxtl = 5,
273ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
274ab3b491fSBlue Swirl     },
275ab3b491fSBlue Swirl     {
2764a7bdec3SThomas Huth         .name = "TI-UltraSparc-IIe",
277ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
278ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
279ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
280ab3b491fSBlue Swirl         .nwindows = 8,
281ab3b491fSBlue Swirl         .maxtl = 5,
282ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
283ab3b491fSBlue Swirl     },
284ab3b491fSBlue Swirl     {
2854a7bdec3SThomas Huth         .name = "Sun-UltraSparc-III",
286ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
287ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
288ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
289ab3b491fSBlue Swirl         .nwindows = 8,
290ab3b491fSBlue Swirl         .maxtl = 5,
291ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
292ab3b491fSBlue Swirl     },
293ab3b491fSBlue Swirl     {
2944a7bdec3SThomas Huth         .name = "Sun-UltraSparc-III-Cu",
295ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
296ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
297ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
298ab3b491fSBlue Swirl         .nwindows = 8,
299ab3b491fSBlue Swirl         .maxtl = 5,
300ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
301ab3b491fSBlue Swirl     },
302ab3b491fSBlue Swirl     {
3034a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IIIi",
304ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
305ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
306ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
307ab3b491fSBlue Swirl         .nwindows = 8,
308ab3b491fSBlue Swirl         .maxtl = 5,
309ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
310ab3b491fSBlue Swirl     },
311ab3b491fSBlue Swirl     {
3124a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IV",
313ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
314ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
315ab3b491fSBlue Swirl         .mmu_version = mmu_us_4,
316ab3b491fSBlue Swirl         .nwindows = 8,
317ab3b491fSBlue Swirl         .maxtl = 5,
318ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
319ab3b491fSBlue Swirl     },
320ab3b491fSBlue Swirl     {
3214a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IV-plus",
322ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
323ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
324ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
325ab3b491fSBlue Swirl         .nwindows = 8,
326ab3b491fSBlue Swirl         .maxtl = 5,
327ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
328ab3b491fSBlue Swirl     },
329ab3b491fSBlue Swirl     {
3304a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IIIi-plus",
331ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
332ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
333ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
334ab3b491fSBlue Swirl         .nwindows = 8,
335ab3b491fSBlue Swirl         .maxtl = 5,
336ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
337ab3b491fSBlue Swirl     },
338ab3b491fSBlue Swirl     {
3394a7bdec3SThomas Huth         .name = "Sun-UltraSparc-T1",
340ab3b491fSBlue Swirl         /* defined in sparc_ifu_fdp.v and ctu.h */
341ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
342ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
343ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
344ab3b491fSBlue Swirl         .nwindows = 8,
345ab3b491fSBlue Swirl         .maxtl = 6,
346ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
347ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
348ab3b491fSBlue Swirl     },
349ab3b491fSBlue Swirl     {
3504a7bdec3SThomas Huth         .name = "Sun-UltraSparc-T2",
351ab3b491fSBlue Swirl         /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
352ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
353ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
354ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
355ab3b491fSBlue Swirl         .nwindows = 8,
356ab3b491fSBlue Swirl         .maxtl = 6,
357ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
358ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
359ab3b491fSBlue Swirl     },
360ab3b491fSBlue Swirl     {
3614a7bdec3SThomas Huth         .name = "NEC-UltraSparc-I",
362ab3b491fSBlue Swirl         .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
363ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
364ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
365ab3b491fSBlue Swirl         .nwindows = 8,
366ab3b491fSBlue Swirl         .maxtl = 5,
367ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
368ab3b491fSBlue Swirl     },
369ab3b491fSBlue Swirl #else
370ab3b491fSBlue Swirl     {
3714a7bdec3SThomas Huth         .name = "Fujitsu-MB86904",
372ab3b491fSBlue Swirl         .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
37349bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
374ab3b491fSBlue Swirl         .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
375ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
376ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
377ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
378ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
379ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
380ab3b491fSBlue Swirl         .nwindows = 8,
381ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
382ab3b491fSBlue Swirl     },
383ab3b491fSBlue Swirl     {
3844a7bdec3SThomas Huth         .name = "Fujitsu-MB86907",
385ab3b491fSBlue Swirl         .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
38649bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
387ab3b491fSBlue Swirl         .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
388ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
389ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
390ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
391ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
392ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
393ab3b491fSBlue Swirl         .nwindows = 8,
394ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
395ab3b491fSBlue Swirl     },
396ab3b491fSBlue Swirl     {
3974a7bdec3SThomas Huth         .name = "TI-MicroSparc-I",
398ab3b491fSBlue Swirl         .iu_version = 0x41000000,
39949bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
400ab3b491fSBlue Swirl         .mmu_version = 0x41000000,
401ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
402ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
403ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
404ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
405ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x0000003f,
406ab3b491fSBlue Swirl         .nwindows = 7,
4075f25b383SRichard Henderson         .features = CPU_FEATURE_MUL | CPU_FEATURE_DIV,
408ab3b491fSBlue Swirl     },
409ab3b491fSBlue Swirl     {
4104a7bdec3SThomas Huth         .name = "TI-MicroSparc-II",
411ab3b491fSBlue Swirl         .iu_version = 0x42000000,
41249bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
413ab3b491fSBlue Swirl         .mmu_version = 0x02000000,
414ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
415ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
416ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
417ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
418ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
419ab3b491fSBlue Swirl         .nwindows = 8,
420ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
421ab3b491fSBlue Swirl     },
422ab3b491fSBlue Swirl     {
4234a7bdec3SThomas Huth         .name = "TI-MicroSparc-IIep",
424ab3b491fSBlue Swirl         .iu_version = 0x42000000,
42549bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
426ab3b491fSBlue Swirl         .mmu_version = 0x04000000,
427ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
428ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
429ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
430ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016bff,
431ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
432ab3b491fSBlue Swirl         .nwindows = 8,
433ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
434ab3b491fSBlue Swirl     },
435ab3b491fSBlue Swirl     {
4364a7bdec3SThomas Huth         .name = "TI-SuperSparc-40", /* STP1020NPGA */
437ab3b491fSBlue Swirl         .iu_version = 0x41000000, /* SuperSPARC 2.x */
43849bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
439ab3b491fSBlue Swirl         .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */
440ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
441ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
442ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
443ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
444ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
445ab3b491fSBlue Swirl         .nwindows = 8,
446ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
447ab3b491fSBlue Swirl     },
448ab3b491fSBlue Swirl     {
4494a7bdec3SThomas Huth         .name = "TI-SuperSparc-50", /* STP1020PGA */
450ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
45149bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
452ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
453ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
454ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
455ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
456ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
457ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
458ab3b491fSBlue Swirl         .nwindows = 8,
459ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
460ab3b491fSBlue Swirl     },
461ab3b491fSBlue Swirl     {
4624a7bdec3SThomas Huth         .name = "TI-SuperSparc-51",
463ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
46449bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
465ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
466ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
467ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
468ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
469ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
470ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
471ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
472ab3b491fSBlue Swirl         .nwindows = 8,
473ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
474ab3b491fSBlue Swirl     },
475ab3b491fSBlue Swirl     {
4764a7bdec3SThomas Huth         .name = "TI-SuperSparc-60", /* STP1020APGA */
477ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
47849bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
479ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
480ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
481ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
482ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
483ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
484ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
485ab3b491fSBlue Swirl         .nwindows = 8,
486ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
487ab3b491fSBlue Swirl     },
488ab3b491fSBlue Swirl     {
4894a7bdec3SThomas Huth         .name = "TI-SuperSparc-61",
490ab3b491fSBlue Swirl         .iu_version = 0x44000000, /* SuperSPARC 3.x */
49149bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
492ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
493ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
494ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
495ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
496ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
497ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
498ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
499ab3b491fSBlue Swirl         .nwindows = 8,
500ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
501ab3b491fSBlue Swirl     },
502ab3b491fSBlue Swirl     {
5034a7bdec3SThomas Huth         .name = "TI-SuperSparc-II",
504ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC II 1.x */
50549bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
506ab3b491fSBlue Swirl         .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */
507ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
508ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
509ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
510ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
511ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
512ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
513ab3b491fSBlue Swirl         .nwindows = 8,
514ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
515ab3b491fSBlue Swirl     },
516ab3b491fSBlue Swirl     {
517ab3b491fSBlue Swirl         .name = "LEON2",
518ab3b491fSBlue Swirl         .iu_version = 0xf2000000,
51949bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
520ab3b491fSBlue Swirl         .mmu_version = 0xf2000000,
521ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
522ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
523ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
524ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
525ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
526ab3b491fSBlue Swirl         .nwindows = 8,
527ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
528ab3b491fSBlue Swirl     },
529ab3b491fSBlue Swirl     {
530ab3b491fSBlue Swirl         .name = "LEON3",
531ab3b491fSBlue Swirl         .iu_version = 0xf3000000,
53249bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
533ab3b491fSBlue Swirl         .mmu_version = 0xf3000000,
534ab3b491fSBlue Swirl         .mmu_bm = 0x00000000,
5357a0a9c2cSRonald Hecht         .mmu_ctpr_mask = 0xfffffffc,
5367a0a9c2cSRonald Hecht         .mmu_cxr_mask = 0x000000ff,
537ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
538ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
539ab3b491fSBlue Swirl         .nwindows = 8,
540ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
54116c358e9SSebastian Huber         CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL | CPU_FEATURE_POWERDOWN |
54216c358e9SSebastian Huber         CPU_FEATURE_CASA,
543ab3b491fSBlue Swirl     },
544ab3b491fSBlue Swirl #endif
545ab3b491fSBlue Swirl };
546ab3b491fSBlue Swirl 
547de1f5203SRichard Henderson /* This must match sparc_cpu_properties[]. */
548ab3b491fSBlue Swirl static const char * const feature_name[] = {
549de1f5203SRichard Henderson     [CPU_FEATURE_BIT_FLOAT128] = "float128",
550554abe47SRichard Henderson #ifdef TARGET_SPARC64
551de1f5203SRichard Henderson     [CPU_FEATURE_BIT_CMT] = "cmt",
552de1f5203SRichard Henderson     [CPU_FEATURE_BIT_GL] = "gl",
553554abe47SRichard Henderson     [CPU_FEATURE_BIT_HYPV] = "hypv",
554554abe47SRichard Henderson     [CPU_FEATURE_BIT_VIS1] = "vis1",
555554abe47SRichard Henderson     [CPU_FEATURE_BIT_VIS2] = "vis2",
5564fd71d19SRichard Henderson     [CPU_FEATURE_BIT_FMAF] = "fmaf",
557deadbb14SRichard Henderson     [CPU_FEATURE_BIT_VIS3] = "vis3",
55868a414e9SRichard Henderson     [CPU_FEATURE_BIT_IMA] = "ima",
559b12b7227SRichard Henderson     [CPU_FEATURE_BIT_VIS4] = "vis4",
560554abe47SRichard Henderson #else
561554abe47SRichard Henderson     [CPU_FEATURE_BIT_MUL] = "mul",
562554abe47SRichard Henderson     [CPU_FEATURE_BIT_DIV] = "div",
563554abe47SRichard Henderson     [CPU_FEATURE_BIT_FSMULD] = "fsmuld",
564554abe47SRichard Henderson #endif
565ab3b491fSBlue Swirl };
566ab3b491fSBlue Swirl 
5670442428aSMarkus Armbruster static void print_features(uint32_t features, const char *prefix)
568ab3b491fSBlue Swirl {
569ab3b491fSBlue Swirl     unsigned int i;
570ab3b491fSBlue Swirl 
571ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
572ab3b491fSBlue Swirl         if (feature_name[i] && (features & (1 << i))) {
573ab3b491fSBlue Swirl             if (prefix) {
5740442428aSMarkus Armbruster                 qemu_printf("%s", prefix);
575ab3b491fSBlue Swirl             }
5760442428aSMarkus Armbruster             qemu_printf("%s ", feature_name[i]);
577ab3b491fSBlue Swirl         }
578ab3b491fSBlue Swirl     }
579ab3b491fSBlue Swirl }
580ab3b491fSBlue Swirl 
5810442428aSMarkus Armbruster void sparc_cpu_list(void)
582ab3b491fSBlue Swirl {
583ab3b491fSBlue Swirl     unsigned int i;
584ab3b491fSBlue Swirl 
58547833f81SThomas Huth     qemu_printf("Available CPU types:\n");
586ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
58747833f81SThomas Huth         qemu_printf(" %-20s (IU " TARGET_FMT_lx
58847833f81SThomas Huth                     " FPU %08x MMU %08x NWINS %d) ",
589ab3b491fSBlue Swirl                     sparc_defs[i].name,
590ab3b491fSBlue Swirl                     sparc_defs[i].iu_version,
591ab3b491fSBlue Swirl                     sparc_defs[i].fpu_version,
592ab3b491fSBlue Swirl                     sparc_defs[i].mmu_version,
593ab3b491fSBlue Swirl                     sparc_defs[i].nwindows);
5940442428aSMarkus Armbruster         print_features(CPU_DEFAULT_FEATURES & ~sparc_defs[i].features, "-");
5950442428aSMarkus Armbruster         print_features(~CPU_DEFAULT_FEATURES & sparc_defs[i].features, "+");
5960442428aSMarkus Armbruster         qemu_printf("\n");
597ab3b491fSBlue Swirl     }
5980442428aSMarkus Armbruster     qemu_printf("Default CPU feature flags (use '-' to remove): ");
5990442428aSMarkus Armbruster     print_features(CPU_DEFAULT_FEATURES, NULL);
6000442428aSMarkus Armbruster     qemu_printf("\n");
6010442428aSMarkus Armbruster     qemu_printf("Available CPU feature flags (use '+' to add): ");
6020442428aSMarkus Armbruster     print_features(~CPU_DEFAULT_FEATURES, NULL);
6030442428aSMarkus Armbruster     qemu_printf("\n");
6040442428aSMarkus Armbruster     qemu_printf("Numerical features (use '=' to set): iu_version "
605ab3b491fSBlue Swirl                 "fpu_version mmu_version nwindows\n");
606ab3b491fSBlue Swirl }
607ab3b491fSBlue Swirl 
60890c84c56SMarkus Armbruster static void cpu_print_cc(FILE *f, uint32_t cc)
609ab3b491fSBlue Swirl {
61090c84c56SMarkus Armbruster     qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
611ab3b491fSBlue Swirl                  cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
612ab3b491fSBlue Swirl                  cc & PSR_CARRY ? 'C' : '-');
613ab3b491fSBlue Swirl }
614ab3b491fSBlue Swirl 
615ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
616ab3b491fSBlue Swirl #define REGS_PER_LINE 4
617ab3b491fSBlue Swirl #else
618ab3b491fSBlue Swirl #define REGS_PER_LINE 8
619ab3b491fSBlue Swirl #endif
620ab3b491fSBlue Swirl 
6219ac200acSPhilippe Mathieu-Daudé static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
622ab3b491fSBlue Swirl {
62377976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
624ab3b491fSBlue Swirl     int i, x;
625ab3b491fSBlue Swirl 
62690c84c56SMarkus Armbruster     qemu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
627ab3b491fSBlue Swirl                  env->npc);
628ab3b491fSBlue Swirl 
629ab3b491fSBlue Swirl     for (i = 0; i < 8; i++) {
630ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == 0) {
63190c84c56SMarkus Armbruster             qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
632ab3b491fSBlue Swirl         }
63390c84c56SMarkus Armbruster         qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
634ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
63590c84c56SMarkus Armbruster             qemu_fprintf(f, "\n");
636ab3b491fSBlue Swirl         }
637ab3b491fSBlue Swirl     }
638ab3b491fSBlue Swirl     for (x = 0; x < 3; x++) {
639ab3b491fSBlue Swirl         for (i = 0; i < 8; i++) {
640ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == 0) {
64190c84c56SMarkus Armbruster                 qemu_fprintf(f, "%%%c%d-%d: ",
642ab3b491fSBlue Swirl                              x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
643ab3b491fSBlue Swirl                              i, i + REGS_PER_LINE - 1);
644ab3b491fSBlue Swirl             }
64590c84c56SMarkus Armbruster             qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
646ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
64790c84c56SMarkus Armbruster                 qemu_fprintf(f, "\n");
648ab3b491fSBlue Swirl             }
649ab3b491fSBlue Swirl         }
650ab3b491fSBlue Swirl     }
65176a23ca0SRichard Henderson 
652d13c394cSRichard Henderson     if (flags & CPU_DUMP_FPU) {
65330038fd8SRichard Henderson         for (i = 0; i < TARGET_DPREGS; i++) {
654ab3b491fSBlue Swirl             if ((i & 3) == 0) {
65590c84c56SMarkus Armbruster                 qemu_fprintf(f, "%%f%02d: ", i * 2);
656ab3b491fSBlue Swirl             }
65790c84c56SMarkus Armbruster             qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
658ab3b491fSBlue Swirl             if ((i & 3) == 3) {
65990c84c56SMarkus Armbruster                 qemu_fprintf(f, "\n");
660ab3b491fSBlue Swirl             }
661ab3b491fSBlue Swirl         }
662d13c394cSRichard Henderson     }
663d13c394cSRichard Henderson 
664ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
66590c84c56SMarkus Armbruster     qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
666ab3b491fSBlue Swirl                  (unsigned)cpu_get_ccr(env));
66790c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
66890c84c56SMarkus Armbruster     qemu_fprintf(f, " xcc: ");
66990c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
67090c84c56SMarkus Armbruster     qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
671cbc3a6a4SArtyom Tarasenko                  env->psrpil, env->gl);
67290c84c56SMarkus Armbruster     qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
673cbc3a6a4SArtyom Tarasenko                  TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
67490c84c56SMarkus Armbruster     qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
675ab3b491fSBlue Swirl                  "cleanwin: %d cwp: %d\n",
676ab3b491fSBlue Swirl                  env->cansave, env->canrestore, env->otherwin, env->wstate,
677ab3b491fSBlue Swirl                  env->cleanwin, env->nwindows - 1 - env->cwp);
678ca4d5d86SPeter Maydell     qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: %016x\n",
6791ccd6e13SRichard Henderson                  cpu_get_fsr(env), env->y, env->fprs);
680cbc3a6a4SArtyom Tarasenko 
681ab3b491fSBlue Swirl #else
68290c84c56SMarkus Armbruster     qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
68390c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_psr(env));
68490c84c56SMarkus Armbruster     qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
685ab3b491fSBlue Swirl                  env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
686ab3b491fSBlue Swirl                  env->wim);
68790c84c56SMarkus Armbruster     qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
6881ccd6e13SRichard Henderson                  cpu_get_fsr(env), env->y);
689ab3b491fSBlue Swirl #endif
69090c84c56SMarkus Armbruster     qemu_fprintf(f, "\n");
691ab3b491fSBlue Swirl }
692ab7ab3d7SAndreas Färber 
693f45748f1SAndreas Färber static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
694f45748f1SAndreas Färber {
695f45748f1SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
696f45748f1SAndreas Färber 
697f45748f1SAndreas Färber     cpu->env.pc = value;
698f45748f1SAndreas Färber     cpu->env.npc = value + 4;
699f45748f1SAndreas Färber }
700f45748f1SAndreas Färber 
701e4fdf9dfSRichard Henderson static vaddr sparc_cpu_get_pc(CPUState *cs)
702e4fdf9dfSRichard Henderson {
703e4fdf9dfSRichard Henderson     SPARCCPU *cpu = SPARC_CPU(cs);
704e4fdf9dfSRichard Henderson 
705e4fdf9dfSRichard Henderson     return cpu->env.pc;
706e4fdf9dfSRichard Henderson }
707e4fdf9dfSRichard Henderson 
70804a37d4cSRichard Henderson static void sparc_cpu_synchronize_from_tb(CPUState *cs,
70904a37d4cSRichard Henderson                                           const TranslationBlock *tb)
710bdf7ae5bSAndreas Färber {
711bdf7ae5bSAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
712bdf7ae5bSAndreas Färber 
713b254c342SPhilippe Mathieu-Daudé     tcg_debug_assert(!tcg_cflags_has(cs, CF_PCREL));
714c4bf3a92SAnton Johansson     cpu->env.pc = tb->pc;
715bdf7ae5bSAndreas Färber     cpu->env.npc = tb->cs_base;
716bdf7ae5bSAndreas Färber }
717bdf7ae5bSAndreas Färber 
71832cf0ac2SAnton Johansson void cpu_get_tb_cpu_state(CPUSPARCState *env, vaddr *pc,
71932cf0ac2SAnton Johansson                           uint64_t *cs_base, uint32_t *pflags)
72032cf0ac2SAnton Johansson {
72132cf0ac2SAnton Johansson     uint32_t flags;
72232cf0ac2SAnton Johansson     *pc = env->pc;
72332cf0ac2SAnton Johansson     *cs_base = env->npc;
72432cf0ac2SAnton Johansson     flags = cpu_mmu_index(env_cpu(env), false);
72532cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
72632cf0ac2SAnton Johansson     if (cpu_supervisor_mode(env)) {
72732cf0ac2SAnton Johansson         flags |= TB_FLAG_SUPER;
72832cf0ac2SAnton Johansson     }
72932cf0ac2SAnton Johansson #endif
73032cf0ac2SAnton Johansson #ifdef TARGET_SPARC64
73132cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
73232cf0ac2SAnton Johansson     if (cpu_hypervisor_mode(env)) {
73332cf0ac2SAnton Johansson         flags |= TB_FLAG_HYPER;
73432cf0ac2SAnton Johansson     }
73532cf0ac2SAnton Johansson #endif
73632cf0ac2SAnton Johansson     if (env->pstate & PS_AM) {
73732cf0ac2SAnton Johansson         flags |= TB_FLAG_AM_ENABLED;
73832cf0ac2SAnton Johansson     }
73932cf0ac2SAnton Johansson     if ((env->pstate & PS_PEF) && (env->fprs & FPRS_FEF)) {
74032cf0ac2SAnton Johansson         flags |= TB_FLAG_FPU_ENABLED;
74132cf0ac2SAnton Johansson     }
74232cf0ac2SAnton Johansson     flags |= env->asi << TB_FLAG_ASI_SHIFT;
74332cf0ac2SAnton Johansson #else
74432cf0ac2SAnton Johansson     if (env->psref) {
74532cf0ac2SAnton Johansson         flags |= TB_FLAG_FPU_ENABLED;
74632cf0ac2SAnton Johansson     }
74732cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
74832cf0ac2SAnton Johansson     if (env->fsr_qne) {
74932cf0ac2SAnton Johansson         flags |= TB_FLAG_FSR_QNE;
75032cf0ac2SAnton Johansson     }
75132cf0ac2SAnton Johansson #endif /* !CONFIG_USER_ONLY */
75232cf0ac2SAnton Johansson #endif /* TARGET_SPARC64 */
75332cf0ac2SAnton Johansson     *pflags = flags;
75432cf0ac2SAnton Johansson }
75532cf0ac2SAnton Johansson 
756fc3630b2SPhilippe Mathieu-Daudé static void sparc_restore_state_to_opc(CPUState *cs,
757fc3630b2SPhilippe Mathieu-Daudé                                        const TranslationBlock *tb,
758fc3630b2SPhilippe Mathieu-Daudé                                        const uint64_t *data)
759fc3630b2SPhilippe Mathieu-Daudé {
760fc3630b2SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
761fc3630b2SPhilippe Mathieu-Daudé     target_ulong pc = data[0];
762fc3630b2SPhilippe Mathieu-Daudé     target_ulong npc = data[1];
763fc3630b2SPhilippe Mathieu-Daudé 
764fc3630b2SPhilippe Mathieu-Daudé     env->pc = pc;
765fc3630b2SPhilippe Mathieu-Daudé     if (npc == DYNAMIC_PC) {
766fc3630b2SPhilippe Mathieu-Daudé         /* dynamic NPC: already stored */
767fc3630b2SPhilippe Mathieu-Daudé     } else if (npc & JUMP_PC) {
768fc3630b2SPhilippe Mathieu-Daudé         /* jump PC: use 'cond' and the jump targets of the translation */
769fc3630b2SPhilippe Mathieu-Daudé         if (env->cond) {
770fc3630b2SPhilippe Mathieu-Daudé             env->npc = npc & ~3;
771fc3630b2SPhilippe Mathieu-Daudé         } else {
772fc3630b2SPhilippe Mathieu-Daudé             env->npc = pc + 4;
773fc3630b2SPhilippe Mathieu-Daudé         }
774fc3630b2SPhilippe Mathieu-Daudé     } else {
775fc3630b2SPhilippe Mathieu-Daudé         env->npc = npc;
776fc3630b2SPhilippe Mathieu-Daudé     }
777fc3630b2SPhilippe Mathieu-Daudé }
778fc3630b2SPhilippe Mathieu-Daudé 
7798c2e1b00SAndreas Färber static bool sparc_cpu_has_work(CPUState *cs)
7808c2e1b00SAndreas Färber {
7818c2e1b00SAndreas Färber     return (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
78277976769SPhilippe Mathieu-Daudé            cpu_interrupts_enabled(cpu_env(cs));
7838c2e1b00SAndreas Färber }
7848c2e1b00SAndreas Färber 
785a120d320SRichard Henderson static int sparc_cpu_mmu_index(CPUState *cs, bool ifetch)
786e3547a7dSRichard Henderson {
787e3547a7dSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
788e3547a7dSRichard Henderson 
789e3547a7dSRichard Henderson #ifndef TARGET_SPARC64
790e3547a7dSRichard Henderson     if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
791e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
792e3547a7dSRichard Henderson     } else {
793e3547a7dSRichard Henderson         return env->psrs;
794e3547a7dSRichard Henderson     }
795e3547a7dSRichard Henderson #else
796e3547a7dSRichard Henderson     /* IMMU or DMMU disabled.  */
797e3547a7dSRichard Henderson     if (ifetch
798e3547a7dSRichard Henderson         ? (env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0
799e3547a7dSRichard Henderson         : (env->lsu & DMMU_E) == 0) {
800e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
801e3547a7dSRichard Henderson     } else if (cpu_hypervisor_mode(env)) {
802e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
803e3547a7dSRichard Henderson     } else if (env->tl > 0) {
804e3547a7dSRichard Henderson         return MMU_NUCLEUS_IDX;
805e3547a7dSRichard Henderson     } else if (cpu_supervisor_mode(env)) {
806e3547a7dSRichard Henderson         return MMU_KERNEL_IDX;
807e3547a7dSRichard Henderson     } else {
808e3547a7dSRichard Henderson         return MMU_USER_IDX;
809e3547a7dSRichard Henderson     }
810e3547a7dSRichard Henderson #endif
811e3547a7dSRichard Henderson }
812e3547a7dSRichard Henderson 
81312a6c15eSIgor Mammedov static char *sparc_cpu_type_name(const char *cpu_model)
81412a6c15eSIgor Mammedov {
8151d4bfc54SIgor Mammedov     char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model);
81612a6c15eSIgor Mammedov     char *s = name;
81712a6c15eSIgor Mammedov 
81812a6c15eSIgor Mammedov     /* SPARC cpu model names happen to have whitespaces,
81912a6c15eSIgor Mammedov      * as type names shouldn't have spaces replace them with '-'
82012a6c15eSIgor Mammedov      */
82112a6c15eSIgor Mammedov     while ((s = strchr(s, ' '))) {
82212a6c15eSIgor Mammedov         *s = '-';
82312a6c15eSIgor Mammedov     }
82412a6c15eSIgor Mammedov 
82512a6c15eSIgor Mammedov     return name;
82612a6c15eSIgor Mammedov }
82712a6c15eSIgor Mammedov 
82812a6c15eSIgor Mammedov static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model)
82912a6c15eSIgor Mammedov {
83012a6c15eSIgor Mammedov     ObjectClass *oc;
83112a6c15eSIgor Mammedov     char *typename;
83212a6c15eSIgor Mammedov 
83312a6c15eSIgor Mammedov     typename = sparc_cpu_type_name(cpu_model);
8346b568e3fSThomas Huth 
8356b568e3fSThomas Huth     /* Fix up legacy names with '+' in it */
8366b568e3fSThomas Huth     if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV+"))) {
8376b568e3fSThomas Huth         g_free(typename);
8386b568e3fSThomas Huth         typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV-plus"));
8396b568e3fSThomas Huth     } else if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi+"))) {
8406b568e3fSThomas Huth         g_free(typename);
8416b568e3fSThomas Huth         typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi-plus"));
8426b568e3fSThomas Huth     }
8436b568e3fSThomas Huth 
84412a6c15eSIgor Mammedov     oc = object_class_by_name(typename);
84512a6c15eSIgor Mammedov     g_free(typename);
84612a6c15eSIgor Mammedov     return oc;
84712a6c15eSIgor Mammedov }
84812a6c15eSIgor Mammedov 
849b6e91ebfSAndreas Färber static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
850b6e91ebfSAndreas Färber {
851ce5b1bbfSLaurent Vivier     CPUState *cs = CPU(dev);
852b6e91ebfSAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
853ce5b1bbfSLaurent Vivier     Error *local_err = NULL;
85477976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
855247bf011SAndreas Färber 
85670054962SIgor Mammedov #if defined(CONFIG_USER_ONLY)
8575f25b383SRichard Henderson     /* We are emulating the kernel, which will trap and emulate float128. */
858576e1c4cSIgor Mammedov     env->def.features |= CPU_FEATURE_FLOAT128;
859247bf011SAndreas Färber #endif
860b6e91ebfSAndreas Färber 
86170054962SIgor Mammedov     env->version = env->def.iu_version;
86270054962SIgor Mammedov     env->nwindows = env->def.nwindows;
86370054962SIgor Mammedov #if !defined(TARGET_SPARC64)
86470054962SIgor Mammedov     env->mmuregs[0] |= env->def.mmu_version;
86570054962SIgor Mammedov     cpu_sparc_set_id(env, 0);
86670054962SIgor Mammedov     env->mxccregs[7] |= env->def.mxcc_version;
86770054962SIgor Mammedov #else
86870054962SIgor Mammedov     env->mmu_version = env->def.mmu_version;
86970054962SIgor Mammedov     env->maxtl = env->def.maxtl;
87070054962SIgor Mammedov     env->version |= env->def.maxtl << 8;
87170054962SIgor Mammedov     env->version |= env->def.nwindows - 1;
87270054962SIgor Mammedov #endif
87370054962SIgor Mammedov 
8744482f32dSPeter Maydell     /*
8754482f32dSPeter Maydell      * Prefer SNaN over QNaN, order B then A. It's OK to do this in realize
8764482f32dSPeter Maydell      * rather than reset, because fp_status is after 'end_reset_fields' in
8774482f32dSPeter Maydell      * the CPU state struct so it won't get zeroed on reset.
8784482f32dSPeter Maydell      */
8794482f32dSPeter Maydell     set_float_2nan_prop_rule(float_2nan_prop_s_ba, &env->fp_status);
88049866dcbSPeter Maydell     /* For fused-multiply add, prefer SNaN over QNaN, then C->B->A */
88149866dcbSPeter Maydell     set_float_3nan_prop_rule(float_3nan_prop_s_cba, &env->fp_status);
8829a31b8d0SPeter Maydell     /* For inf * 0 + NaN, return the input NaN */
8839a31b8d0SPeter Maydell     set_float_infzeronan_rule(float_infzeronan_dnan_never, &env->fp_status);
88445fb2cd6SPeter Maydell     /* Default NaN value: sign bit clear, all frac bits set */
88545fb2cd6SPeter Maydell     set_float_default_nan_pattern(0b01111111, &env->fp_status);
8864482f32dSPeter Maydell 
887ce5b1bbfSLaurent Vivier     cpu_exec_realizefn(cs, &local_err);
888ce5b1bbfSLaurent Vivier     if (local_err != NULL) {
889ce5b1bbfSLaurent Vivier         error_propagate(errp, local_err);
890ce5b1bbfSLaurent Vivier         return;
891ce5b1bbfSLaurent Vivier     }
892ce5b1bbfSLaurent Vivier 
893ce5b1bbfSLaurent Vivier     qemu_init_vcpu(cs);
89414a10fc3SAndreas Färber 
895b6e91ebfSAndreas Färber     scc->parent_realize(dev, errp);
896b6e91ebfSAndreas Färber }
897b6e91ebfSAndreas Färber 
898ab7ab3d7SAndreas Färber static void sparc_cpu_initfn(Object *obj)
899ab7ab3d7SAndreas Färber {
900ab7ab3d7SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(obj);
90112a6c15eSIgor Mammedov     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
902ab7ab3d7SAndreas Färber     CPUSPARCState *env = &cpu->env;
903ab7ab3d7SAndreas Färber 
904576e1c4cSIgor Mammedov     if (scc->cpu_def) {
905576e1c4cSIgor Mammedov         env->def = *scc->cpu_def;
906ab7ab3d7SAndreas Färber     }
907ab7ab3d7SAndreas Färber }
908ab7ab3d7SAndreas Färber 
909de05005bSIgor Mammedov static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
910de05005bSIgor Mammedov                                void *opaque, Error **errp)
911de05005bSIgor Mammedov {
912de05005bSIgor Mammedov     SPARCCPU *cpu = SPARC_CPU(obj);
913de05005bSIgor Mammedov     int64_t value = cpu->env.def.nwindows;
914de05005bSIgor Mammedov 
915de05005bSIgor Mammedov     visit_type_int(v, name, &value, errp);
916de05005bSIgor Mammedov }
917de05005bSIgor Mammedov 
918de05005bSIgor Mammedov static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
919de05005bSIgor Mammedov                                void *opaque, Error **errp)
920de05005bSIgor Mammedov {
921de05005bSIgor Mammedov     const int64_t min = MIN_NWINDOWS;
922de05005bSIgor Mammedov     const int64_t max = MAX_NWINDOWS;
923de05005bSIgor Mammedov     SPARCCPU *cpu = SPARC_CPU(obj);
924de05005bSIgor Mammedov     int64_t value;
925de05005bSIgor Mammedov 
926668f62ecSMarkus Armbruster     if (!visit_type_int(v, name, &value, errp)) {
927de05005bSIgor Mammedov         return;
928de05005bSIgor Mammedov     }
929de05005bSIgor Mammedov 
930de05005bSIgor Mammedov     if (value < min || value > max) {
931de05005bSIgor Mammedov         error_setg(errp, "Property %s.%s doesn't take value %" PRId64
932de05005bSIgor Mammedov                    " (minimum: %" PRId64 ", maximum: %" PRId64 ")",
933de05005bSIgor Mammedov                    object_get_typename(obj), name ? name : "null",
934de05005bSIgor Mammedov                    value, min, max);
935de05005bSIgor Mammedov         return;
936de05005bSIgor Mammedov     }
937de05005bSIgor Mammedov     cpu->env.def.nwindows = value;
938de05005bSIgor Mammedov }
939de05005bSIgor Mammedov 
9403834cc6fSRichard Henderson static const PropertyInfo qdev_prop_nwindows = {
941de05005bSIgor Mammedov     .name  = "int",
942de05005bSIgor Mammedov     .get   = sparc_get_nwindows,
943de05005bSIgor Mammedov     .set   = sparc_set_nwindows,
944de05005bSIgor Mammedov };
945de05005bSIgor Mammedov 
946de1f5203SRichard Henderson /* This must match feature_name[]. */
9473834cc6fSRichard Henderson static const Property sparc_cpu_properties[] = {
948de1f5203SRichard Henderson     DEFINE_PROP_BIT("float128", SPARCCPU, env.def.features,
949de1f5203SRichard Henderson                     CPU_FEATURE_BIT_FLOAT128, false),
950554abe47SRichard Henderson #ifdef TARGET_SPARC64
951de1f5203SRichard Henderson     DEFINE_PROP_BIT("cmt",      SPARCCPU, env.def.features,
952de1f5203SRichard Henderson                     CPU_FEATURE_BIT_CMT, false),
953de1f5203SRichard Henderson     DEFINE_PROP_BIT("gl",       SPARCCPU, env.def.features,
954de1f5203SRichard Henderson                     CPU_FEATURE_BIT_GL, false),
955554abe47SRichard Henderson     DEFINE_PROP_BIT("hypv",     SPARCCPU, env.def.features,
956554abe47SRichard Henderson                     CPU_FEATURE_BIT_HYPV, false),
957554abe47SRichard Henderson     DEFINE_PROP_BIT("vis1",     SPARCCPU, env.def.features,
958554abe47SRichard Henderson                     CPU_FEATURE_BIT_VIS1, false),
959554abe47SRichard Henderson     DEFINE_PROP_BIT("vis2",     SPARCCPU, env.def.features,
960554abe47SRichard Henderson                     CPU_FEATURE_BIT_VIS2, false),
9614fd71d19SRichard Henderson     DEFINE_PROP_BIT("fmaf",     SPARCCPU, env.def.features,
9624fd71d19SRichard Henderson                     CPU_FEATURE_BIT_FMAF, false),
963deadbb14SRichard Henderson     DEFINE_PROP_BIT("vis3",     SPARCCPU, env.def.features,
964deadbb14SRichard Henderson                     CPU_FEATURE_BIT_VIS3, false),
96568a414e9SRichard Henderson     DEFINE_PROP_BIT("ima",      SPARCCPU, env.def.features,
96668a414e9SRichard Henderson                     CPU_FEATURE_BIT_IMA, false),
967b12b7227SRichard Henderson     DEFINE_PROP_BIT("vis4",     SPARCCPU, env.def.features,
968b12b7227SRichard Henderson                     CPU_FEATURE_BIT_VIS4, false),
969554abe47SRichard Henderson #else
970554abe47SRichard Henderson     DEFINE_PROP_BIT("mul",      SPARCCPU, env.def.features,
971554abe47SRichard Henderson                     CPU_FEATURE_BIT_MUL, false),
972554abe47SRichard Henderson     DEFINE_PROP_BIT("div",      SPARCCPU, env.def.features,
973554abe47SRichard Henderson                     CPU_FEATURE_BIT_DIV, false),
974554abe47SRichard Henderson     DEFINE_PROP_BIT("fsmuld",   SPARCCPU, env.def.features,
975554abe47SRichard Henderson                     CPU_FEATURE_BIT_FSMULD, false),
976554abe47SRichard Henderson #endif
977de05005bSIgor Mammedov     DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU, env.def.iu_version, 0,
978de05005bSIgor Mammedov                          qdev_prop_uint64, target_ulong),
979de05005bSIgor Mammedov     DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0),
980de05005bSIgor Mammedov     DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0),
98143b6ab4cSEduardo Habkost     DEFINE_PROP("nwindows", SPARCCPU, env.def.nwindows,
98243b6ab4cSEduardo Habkost                 qdev_prop_nwindows, uint32_t),
983de05005bSIgor Mammedov     DEFINE_PROP_END_OF_LIST()
984de05005bSIgor Mammedov };
985de05005bSIgor Mammedov 
9868b80bd28SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
9878b80bd28SPhilippe Mathieu-Daudé #include "hw/core/sysemu-cpu-ops.h"
9888b80bd28SPhilippe Mathieu-Daudé 
9898b80bd28SPhilippe Mathieu-Daudé static const struct SysemuCPUOps sparc_sysemu_ops = {
99008928c6dSPhilippe Mathieu-Daudé     .get_phys_page_debug = sparc_cpu_get_phys_page_debug,
991feece4d0SPhilippe Mathieu-Daudé     .legacy_vmsd = &vmstate_sparc_cpu,
9928b80bd28SPhilippe Mathieu-Daudé };
9938b80bd28SPhilippe Mathieu-Daudé #endif
9948b80bd28SPhilippe Mathieu-Daudé 
99578271684SClaudio Fontana #ifdef CONFIG_TCG
99678271684SClaudio Fontana #include "hw/core/tcg-cpu-ops.h"
99778271684SClaudio Fontana 
9981764ad70SRichard Henderson static const TCGCPUOps sparc_tcg_ops = {
99978271684SClaudio Fontana     .initialize = sparc_tcg_init,
100078271684SClaudio Fontana     .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
1001f36aaa53SRichard Henderson     .restore_state_to_opc = sparc_restore_state_to_opc,
100278271684SClaudio Fontana 
100378271684SClaudio Fontana #ifndef CONFIG_USER_ONLY
1004caac44a5SRichard Henderson     .tlb_fill = sparc_cpu_tlb_fill,
1005798ac8b5SPhilippe Mathieu-Daudé     .cpu_exec_interrupt = sparc_cpu_exec_interrupt,
10064f7b1ecbSPeter Maydell     .cpu_exec_halt = sparc_cpu_has_work,
100778271684SClaudio Fontana     .do_interrupt = sparc_cpu_do_interrupt,
100878271684SClaudio Fontana     .do_transaction_failed = sparc_cpu_do_transaction_failed,
100978271684SClaudio Fontana     .do_unaligned_access = sparc_cpu_do_unaligned_access,
101078271684SClaudio Fontana #endif /* !CONFIG_USER_ONLY */
101178271684SClaudio Fontana };
101278271684SClaudio Fontana #endif /* CONFIG_TCG */
101378271684SClaudio Fontana 
1014ab7ab3d7SAndreas Färber static void sparc_cpu_class_init(ObjectClass *oc, void *data)
1015ab7ab3d7SAndreas Färber {
1016ab7ab3d7SAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
1017ab7ab3d7SAndreas Färber     CPUClass *cc = CPU_CLASS(oc);
1018b6e91ebfSAndreas Färber     DeviceClass *dc = DEVICE_CLASS(oc);
10193b4fff1bSPeter Maydell     ResettableClass *rc = RESETTABLE_CLASS(oc);
1020b6e91ebfSAndreas Färber 
1021bf853881SPhilippe Mathieu-Daudé     device_class_set_parent_realize(dc, sparc_cpu_realizefn,
1022bf853881SPhilippe Mathieu-Daudé                                     &scc->parent_realize);
10234f67d30bSMarc-André Lureau     device_class_set_props(dc, sparc_cpu_properties);
1024ab7ab3d7SAndreas Färber 
10253b4fff1bSPeter Maydell     resettable_class_set_parent_phases(rc, NULL, sparc_cpu_reset_hold, NULL,
10263b4fff1bSPeter Maydell                                        &scc->parent_phases);
102797a8ea5aSAndreas Färber 
102812a6c15eSIgor Mammedov     cc->class_by_name = sparc_cpu_class_by_name;
1029d1853231SIgor Mammedov     cc->parse_features = sparc_cpu_parse_features;
10308c2e1b00SAndreas Färber     cc->has_work = sparc_cpu_has_work;
1031e3547a7dSRichard Henderson     cc->mmu_index = sparc_cpu_mmu_index;
1032878096eeSAndreas Färber     cc->dump_state = sparc_cpu_dump_state;
1033f3659eeeSAndreas Färber #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
1034f3659eeeSAndreas Färber     cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
1035f3659eeeSAndreas Färber #endif
1036f45748f1SAndreas Färber     cc->set_pc = sparc_cpu_set_pc;
1037e4fdf9dfSRichard Henderson     cc->get_pc = sparc_cpu_get_pc;
10385b50e790SAndreas Färber     cc->gdb_read_register = sparc_cpu_gdb_read_register;
10395b50e790SAndreas Färber     cc->gdb_write_register = sparc_cpu_gdb_write_register;
1040e84942f2SRichard Henderson #ifndef CONFIG_USER_ONLY
10418b80bd28SPhilippe Mathieu-Daudé     cc->sysemu_ops = &sparc_sysemu_ops;
104200b941e5SAndreas Färber #endif
1043df0900ebSPeter Crosthwaite     cc->disas_set_info = cpu_sparc_disas_set_info;
1044a0e372f0SAndreas Färber 
1045a0e372f0SAndreas Färber #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1046a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 86;
1047a0e372f0SAndreas Färber #else
1048a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 72;
1049a0e372f0SAndreas Färber #endif
105078271684SClaudio Fontana     cc->tcg_ops = &sparc_tcg_ops;
1051ab7ab3d7SAndreas Färber }
1052ab7ab3d7SAndreas Färber 
1053ab7ab3d7SAndreas Färber static const TypeInfo sparc_cpu_type_info = {
1054ab7ab3d7SAndreas Färber     .name = TYPE_SPARC_CPU,
1055ab7ab3d7SAndreas Färber     .parent = TYPE_CPU,
1056ab7ab3d7SAndreas Färber     .instance_size = sizeof(SPARCCPU),
1057f669c992SRichard Henderson     .instance_align = __alignof(SPARCCPU),
1058ab7ab3d7SAndreas Färber     .instance_init = sparc_cpu_initfn,
105912a6c15eSIgor Mammedov     .abstract = true,
1060ab7ab3d7SAndreas Färber     .class_size = sizeof(SPARCCPUClass),
1061ab7ab3d7SAndreas Färber     .class_init = sparc_cpu_class_init,
1062ab7ab3d7SAndreas Färber };
1063ab7ab3d7SAndreas Färber 
106412a6c15eSIgor Mammedov static void sparc_cpu_cpudef_class_init(ObjectClass *oc, void *data)
106512a6c15eSIgor Mammedov {
106612a6c15eSIgor Mammedov     SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
106712a6c15eSIgor Mammedov     scc->cpu_def = data;
106812a6c15eSIgor Mammedov }
106912a6c15eSIgor Mammedov 
107012a6c15eSIgor Mammedov static void sparc_register_cpudef_type(const struct sparc_def_t *def)
107112a6c15eSIgor Mammedov {
107212a6c15eSIgor Mammedov     char *typename = sparc_cpu_type_name(def->name);
107312a6c15eSIgor Mammedov     TypeInfo ti = {
107412a6c15eSIgor Mammedov         .name = typename,
107512a6c15eSIgor Mammedov         .parent = TYPE_SPARC_CPU,
107612a6c15eSIgor Mammedov         .class_init = sparc_cpu_cpudef_class_init,
107712a6c15eSIgor Mammedov         .class_data = (void *)def,
107812a6c15eSIgor Mammedov     };
107912a6c15eSIgor Mammedov 
10802f02b71bSZhao Liu     type_register_static(&ti);
108112a6c15eSIgor Mammedov     g_free(typename);
108212a6c15eSIgor Mammedov }
108312a6c15eSIgor Mammedov 
1084ab7ab3d7SAndreas Färber static void sparc_cpu_register_types(void)
1085ab7ab3d7SAndreas Färber {
108612a6c15eSIgor Mammedov     int i;
108712a6c15eSIgor Mammedov 
1088ab7ab3d7SAndreas Färber     type_register_static(&sparc_cpu_type_info);
108912a6c15eSIgor Mammedov     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
109012a6c15eSIgor Mammedov         sparc_register_cpudef_type(&sparc_defs[i]);
109112a6c15eSIgor Mammedov     }
1092ab7ab3d7SAndreas Färber }
1093ab7ab3d7SAndreas Färber 
1094ab7ab3d7SAndreas Färber type_init(sparc_cpu_register_types)
1095