xref: /qemu/target/sparc/cpu.c (revision 2136f7f1f95b26129922d05d233b2056b8cbff5c)
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"
268865049bSPhilippe 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;
109*2136f7f1SPhilippe Mathieu-Daudé     info->endian = BFD_ENDIAN_BIG;
110df0900ebSPeter Crosthwaite #ifdef TARGET_SPARC64
111df0900ebSPeter Crosthwaite     info->mach = bfd_mach_sparc_v9b;
112df0900ebSPeter Crosthwaite #endif
113df0900ebSPeter Crosthwaite }
114df0900ebSPeter Crosthwaite 
115d1853231SIgor Mammedov static void
116d1853231SIgor Mammedov cpu_add_feat_as_prop(const char *typename, const char *name, const char *val)
117ab3b491fSBlue Swirl {
118d1853231SIgor Mammedov     GlobalProperty *prop = g_new0(typeof(*prop), 1);
119d1853231SIgor Mammedov     prop->driver = typename;
120d1853231SIgor Mammedov     prop->property = g_strdup(name);
121d1853231SIgor Mammedov     prop->value = g_strdup(val);
122d1853231SIgor Mammedov     qdev_prop_register_global(prop);
123433ac7a9SAndreas Färber }
124433ac7a9SAndreas Färber 
125d1853231SIgor Mammedov /* Parse "+feature,-feature,feature=foo" CPU feature string */
126d1853231SIgor Mammedov static void sparc_cpu_parse_features(const char *typename, char *features,
127d1853231SIgor Mammedov                                      Error **errp)
128d1853231SIgor Mammedov {
129d1853231SIgor Mammedov     GList *l, *plus_features = NULL, *minus_features = NULL;
130d1853231SIgor Mammedov     char *featurestr; /* Single 'key=value" string being parsed */
131d1853231SIgor Mammedov     static bool cpu_globals_initialized;
132d1853231SIgor Mammedov 
133d1853231SIgor Mammedov     if (cpu_globals_initialized) {
134d1853231SIgor Mammedov         return;
135d1853231SIgor Mammedov     }
136d1853231SIgor Mammedov     cpu_globals_initialized = true;
137d1853231SIgor Mammedov 
138d1853231SIgor Mammedov     if (!features) {
139d1853231SIgor Mammedov         return;
140d1853231SIgor Mammedov     }
141d1853231SIgor Mammedov 
142d1853231SIgor Mammedov     for (featurestr = strtok(features, ",");
143d1853231SIgor Mammedov          featurestr;
144d1853231SIgor Mammedov          featurestr = strtok(NULL, ",")) {
145d1853231SIgor Mammedov         const char *name;
146d1853231SIgor Mammedov         const char *val = NULL;
147d1853231SIgor Mammedov         char *eq = NULL;
148d1853231SIgor Mammedov 
149d1853231SIgor Mammedov         /* Compatibility syntax: */
150d1853231SIgor Mammedov         if (featurestr[0] == '+') {
151d1853231SIgor Mammedov             plus_features = g_list_append(plus_features,
152d1853231SIgor Mammedov                                           g_strdup(featurestr + 1));
153d1853231SIgor Mammedov             continue;
154d1853231SIgor Mammedov         } else if (featurestr[0] == '-') {
155d1853231SIgor Mammedov             minus_features = g_list_append(minus_features,
156d1853231SIgor Mammedov                                            g_strdup(featurestr + 1));
157d1853231SIgor Mammedov             continue;
158d1853231SIgor Mammedov         }
159d1853231SIgor Mammedov 
160d1853231SIgor Mammedov         eq = strchr(featurestr, '=');
161d1853231SIgor Mammedov         name = featurestr;
162d1853231SIgor Mammedov         if (eq) {
163d1853231SIgor Mammedov             *eq++ = 0;
164d1853231SIgor Mammedov             val = eq;
165d1853231SIgor Mammedov 
166d1853231SIgor Mammedov             /*
167d1853231SIgor Mammedov              * Temporarily, only +feat/-feat will be supported
168d1853231SIgor Mammedov              * for boolean properties until we remove the
169d1853231SIgor Mammedov              * minus-overrides-plus semantics and just follow
170d1853231SIgor Mammedov              * the order options appear on the command-line.
171d1853231SIgor Mammedov              *
172d1853231SIgor Mammedov              * TODO: warn if user is relying on minus-override-plus semantics
173d1853231SIgor Mammedov              * TODO: remove minus-override-plus semantics after
174d1853231SIgor Mammedov              *       warning for a few releases
175d1853231SIgor Mammedov              */
176d1853231SIgor Mammedov             if (!strcasecmp(val, "on") ||
177d1853231SIgor Mammedov                 !strcasecmp(val, "off") ||
178d1853231SIgor Mammedov                 !strcasecmp(val, "true") ||
179d1853231SIgor Mammedov                 !strcasecmp(val, "false")) {
180d1853231SIgor Mammedov                 error_setg(errp, "Boolean properties in format %s=%s"
181d1853231SIgor Mammedov                                  " are not supported", name, val);
182d1853231SIgor Mammedov                 return;
183d1853231SIgor Mammedov             }
184d1853231SIgor Mammedov         } else {
185d1853231SIgor Mammedov             error_setg(errp, "Unsupported property format: %s", name);
186d1853231SIgor Mammedov             return;
187d1853231SIgor Mammedov         }
188d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, val);
189d1853231SIgor Mammedov     }
190d1853231SIgor Mammedov 
191d1853231SIgor Mammedov     for (l = plus_features; l; l = l->next) {
192d1853231SIgor Mammedov         const char *name = l->data;
193d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, "on");
194d1853231SIgor Mammedov     }
195d1853231SIgor Mammedov     g_list_free_full(plus_features, g_free);
196d1853231SIgor Mammedov 
197d1853231SIgor Mammedov     for (l = minus_features; l; l = l->next) {
198d1853231SIgor Mammedov         const char *name = l->data;
199d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, "off");
200d1853231SIgor Mammedov     }
201d1853231SIgor Mammedov     g_list_free_full(minus_features, g_free);
202ab3b491fSBlue Swirl }
203ab3b491fSBlue Swirl 
204ab3b491fSBlue Swirl void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
205ab3b491fSBlue Swirl {
206ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
207ab3b491fSBlue Swirl     env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
208ab3b491fSBlue Swirl #endif
209ab3b491fSBlue Swirl }
210ab3b491fSBlue Swirl 
211ab3b491fSBlue Swirl static const sparc_def_t sparc_defs[] = {
212ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
213ab3b491fSBlue Swirl     {
2144a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64",
215ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
216ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
217ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
218ab3b491fSBlue Swirl         .nwindows = 4,
219ab3b491fSBlue Swirl         .maxtl = 4,
220ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
221ab3b491fSBlue Swirl     },
222ab3b491fSBlue Swirl     {
2234a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-III",
224ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
225ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
226ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
227ab3b491fSBlue Swirl         .nwindows = 5,
228ab3b491fSBlue Swirl         .maxtl = 4,
229ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
230ab3b491fSBlue Swirl     },
231ab3b491fSBlue Swirl     {
2324a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-IV",
233ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
234ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
235ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
236ab3b491fSBlue Swirl         .nwindows = 8,
237ab3b491fSBlue Swirl         .maxtl = 5,
238ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
239ab3b491fSBlue Swirl     },
240ab3b491fSBlue Swirl     {
2414a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-V",
242ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
243ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
244ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
245ab3b491fSBlue Swirl         .nwindows = 8,
246ab3b491fSBlue Swirl         .maxtl = 5,
247ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
248ab3b491fSBlue Swirl     },
249ab3b491fSBlue Swirl     {
2504a7bdec3SThomas Huth         .name = "TI-UltraSparc-I",
251ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
252ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
253ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
254ab3b491fSBlue Swirl         .nwindows = 8,
255ab3b491fSBlue Swirl         .maxtl = 5,
256ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
257ab3b491fSBlue Swirl     },
258ab3b491fSBlue Swirl     {
2594a7bdec3SThomas Huth         .name = "TI-UltraSparc-II",
260ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
261ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
262ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
263ab3b491fSBlue Swirl         .nwindows = 8,
264ab3b491fSBlue Swirl         .maxtl = 5,
265ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
266ab3b491fSBlue Swirl     },
267ab3b491fSBlue Swirl     {
2684a7bdec3SThomas Huth         .name = "TI-UltraSparc-IIi",
269ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
270ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
271ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
272ab3b491fSBlue Swirl         .nwindows = 8,
273ab3b491fSBlue Swirl         .maxtl = 5,
274ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
275ab3b491fSBlue Swirl     },
276ab3b491fSBlue Swirl     {
2774a7bdec3SThomas Huth         .name = "TI-UltraSparc-IIe",
278ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
279ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
280ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
281ab3b491fSBlue Swirl         .nwindows = 8,
282ab3b491fSBlue Swirl         .maxtl = 5,
283ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
284ab3b491fSBlue Swirl     },
285ab3b491fSBlue Swirl     {
2864a7bdec3SThomas Huth         .name = "Sun-UltraSparc-III",
287ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
288ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
289ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
290ab3b491fSBlue Swirl         .nwindows = 8,
291ab3b491fSBlue Swirl         .maxtl = 5,
292ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
293ab3b491fSBlue Swirl     },
294ab3b491fSBlue Swirl     {
2954a7bdec3SThomas Huth         .name = "Sun-UltraSparc-III-Cu",
296ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
297ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
298ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
299ab3b491fSBlue Swirl         .nwindows = 8,
300ab3b491fSBlue Swirl         .maxtl = 5,
301ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
302ab3b491fSBlue Swirl     },
303ab3b491fSBlue Swirl     {
3044a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IIIi",
305ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
306ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
307ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
308ab3b491fSBlue Swirl         .nwindows = 8,
309ab3b491fSBlue Swirl         .maxtl = 5,
310ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
311ab3b491fSBlue Swirl     },
312ab3b491fSBlue Swirl     {
3134a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IV",
314ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
315ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
316ab3b491fSBlue Swirl         .mmu_version = mmu_us_4,
317ab3b491fSBlue Swirl         .nwindows = 8,
318ab3b491fSBlue Swirl         .maxtl = 5,
319ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
320ab3b491fSBlue Swirl     },
321ab3b491fSBlue Swirl     {
3224a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IV-plus",
323ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
324ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
325ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
326ab3b491fSBlue Swirl         .nwindows = 8,
327ab3b491fSBlue Swirl         .maxtl = 5,
328ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
329ab3b491fSBlue Swirl     },
330ab3b491fSBlue Swirl     {
3314a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IIIi-plus",
332ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
333ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
334ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
335ab3b491fSBlue Swirl         .nwindows = 8,
336ab3b491fSBlue Swirl         .maxtl = 5,
337ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
338ab3b491fSBlue Swirl     },
339ab3b491fSBlue Swirl     {
3404a7bdec3SThomas Huth         .name = "Sun-UltraSparc-T1",
341ab3b491fSBlue Swirl         /* defined in sparc_ifu_fdp.v and ctu.h */
342ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
343ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
344ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
345ab3b491fSBlue Swirl         .nwindows = 8,
346ab3b491fSBlue Swirl         .maxtl = 6,
347ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
348ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
349ab3b491fSBlue Swirl     },
350ab3b491fSBlue Swirl     {
3514a7bdec3SThomas Huth         .name = "Sun-UltraSparc-T2",
352ab3b491fSBlue Swirl         /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
353ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
354ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
355ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
356ab3b491fSBlue Swirl         .nwindows = 8,
357ab3b491fSBlue Swirl         .maxtl = 6,
358ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
359ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
360ab3b491fSBlue Swirl     },
361ab3b491fSBlue Swirl     {
3624a7bdec3SThomas Huth         .name = "NEC-UltraSparc-I",
363ab3b491fSBlue Swirl         .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
364ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
365ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
366ab3b491fSBlue Swirl         .nwindows = 8,
367ab3b491fSBlue Swirl         .maxtl = 5,
368ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
369ab3b491fSBlue Swirl     },
370ab3b491fSBlue Swirl #else
371ab3b491fSBlue Swirl     {
3724a7bdec3SThomas Huth         .name = "Fujitsu-MB86904",
373ab3b491fSBlue Swirl         .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
37449bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
375ab3b491fSBlue Swirl         .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
376ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
377ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
378ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
379ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
380ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
381ab3b491fSBlue Swirl         .nwindows = 8,
382ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
383ab3b491fSBlue Swirl     },
384ab3b491fSBlue Swirl     {
3854a7bdec3SThomas Huth         .name = "Fujitsu-MB86907",
386ab3b491fSBlue Swirl         .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
38749bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
388ab3b491fSBlue Swirl         .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
389ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
390ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
391ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
392ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
393ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
394ab3b491fSBlue Swirl         .nwindows = 8,
395ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
396ab3b491fSBlue Swirl     },
397ab3b491fSBlue Swirl     {
3984a7bdec3SThomas Huth         .name = "TI-MicroSparc-I",
399ab3b491fSBlue Swirl         .iu_version = 0x41000000,
40049bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
401ab3b491fSBlue Swirl         .mmu_version = 0x41000000,
402ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
403ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
404ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
405ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
406ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x0000003f,
407ab3b491fSBlue Swirl         .nwindows = 7,
4085f25b383SRichard Henderson         .features = CPU_FEATURE_MUL | CPU_FEATURE_DIV,
409ab3b491fSBlue Swirl     },
410ab3b491fSBlue Swirl     {
4114a7bdec3SThomas Huth         .name = "TI-MicroSparc-II",
412ab3b491fSBlue Swirl         .iu_version = 0x42000000,
41349bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
414ab3b491fSBlue Swirl         .mmu_version = 0x02000000,
415ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
416ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
417ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
418ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
419ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
420ab3b491fSBlue Swirl         .nwindows = 8,
421ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
422ab3b491fSBlue Swirl     },
423ab3b491fSBlue Swirl     {
4244a7bdec3SThomas Huth         .name = "TI-MicroSparc-IIep",
425ab3b491fSBlue Swirl         .iu_version = 0x42000000,
42649bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
427ab3b491fSBlue Swirl         .mmu_version = 0x04000000,
428ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
429ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
430ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
431ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016bff,
432ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
433ab3b491fSBlue Swirl         .nwindows = 8,
434ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
435ab3b491fSBlue Swirl     },
436ab3b491fSBlue Swirl     {
4374a7bdec3SThomas Huth         .name = "TI-SuperSparc-40", /* STP1020NPGA */
438ab3b491fSBlue Swirl         .iu_version = 0x41000000, /* SuperSPARC 2.x */
43949bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
440ab3b491fSBlue Swirl         .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */
441ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
442ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
443ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
444ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
445ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
446ab3b491fSBlue Swirl         .nwindows = 8,
447ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
448ab3b491fSBlue Swirl     },
449ab3b491fSBlue Swirl     {
4504a7bdec3SThomas Huth         .name = "TI-SuperSparc-50", /* STP1020PGA */
451ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
45249bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
453ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
454ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
455ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
456ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
457ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
458ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
459ab3b491fSBlue Swirl         .nwindows = 8,
460ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
461ab3b491fSBlue Swirl     },
462ab3b491fSBlue Swirl     {
4634a7bdec3SThomas Huth         .name = "TI-SuperSparc-51",
464ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
46549bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
466ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
467ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
468ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
469ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
470ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
471ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
472ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
473ab3b491fSBlue Swirl         .nwindows = 8,
474ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
475ab3b491fSBlue Swirl     },
476ab3b491fSBlue Swirl     {
4774a7bdec3SThomas Huth         .name = "TI-SuperSparc-60", /* STP1020APGA */
478ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
47949bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
480ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
481ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
482ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
483ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
484ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
485ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
486ab3b491fSBlue Swirl         .nwindows = 8,
487ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
488ab3b491fSBlue Swirl     },
489ab3b491fSBlue Swirl     {
4904a7bdec3SThomas Huth         .name = "TI-SuperSparc-61",
491ab3b491fSBlue Swirl         .iu_version = 0x44000000, /* SuperSPARC 3.x */
49249bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
493ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
494ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
495ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
496ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
497ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
498ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
499ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
500ab3b491fSBlue Swirl         .nwindows = 8,
501ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
502ab3b491fSBlue Swirl     },
503ab3b491fSBlue Swirl     {
5044a7bdec3SThomas Huth         .name = "TI-SuperSparc-II",
505ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC II 1.x */
50649bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
507ab3b491fSBlue Swirl         .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */
508ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
509ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
510ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
511ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
512ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
513ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
514ab3b491fSBlue Swirl         .nwindows = 8,
515ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
516ab3b491fSBlue Swirl     },
517ab3b491fSBlue Swirl     {
518ab3b491fSBlue Swirl         .name = "LEON2",
519ab3b491fSBlue Swirl         .iu_version = 0xf2000000,
52049bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
521ab3b491fSBlue Swirl         .mmu_version = 0xf2000000,
522ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
523ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
524ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
525ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
526ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
527ab3b491fSBlue Swirl         .nwindows = 8,
528ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
529ab3b491fSBlue Swirl     },
530ab3b491fSBlue Swirl     {
531ab3b491fSBlue Swirl         .name = "LEON3",
532ab3b491fSBlue Swirl         .iu_version = 0xf3000000,
53349bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
534ab3b491fSBlue Swirl         .mmu_version = 0xf3000000,
535ab3b491fSBlue Swirl         .mmu_bm = 0x00000000,
5367a0a9c2cSRonald Hecht         .mmu_ctpr_mask = 0xfffffffc,
5377a0a9c2cSRonald Hecht         .mmu_cxr_mask = 0x000000ff,
538ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
539ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
540ab3b491fSBlue Swirl         .nwindows = 8,
541ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
54216c358e9SSebastian Huber         CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL | CPU_FEATURE_POWERDOWN |
54316c358e9SSebastian Huber         CPU_FEATURE_CASA,
544ab3b491fSBlue Swirl     },
545ab3b491fSBlue Swirl #endif
546ab3b491fSBlue Swirl };
547ab3b491fSBlue Swirl 
548de1f5203SRichard Henderson /* This must match sparc_cpu_properties[]. */
549ab3b491fSBlue Swirl static const char * const feature_name[] = {
550de1f5203SRichard Henderson     [CPU_FEATURE_BIT_FLOAT128] = "float128",
551554abe47SRichard Henderson #ifdef TARGET_SPARC64
552de1f5203SRichard Henderson     [CPU_FEATURE_BIT_CMT] = "cmt",
553de1f5203SRichard Henderson     [CPU_FEATURE_BIT_GL] = "gl",
554554abe47SRichard Henderson     [CPU_FEATURE_BIT_HYPV] = "hypv",
555554abe47SRichard Henderson     [CPU_FEATURE_BIT_VIS1] = "vis1",
556554abe47SRichard Henderson     [CPU_FEATURE_BIT_VIS2] = "vis2",
5574fd71d19SRichard Henderson     [CPU_FEATURE_BIT_FMAF] = "fmaf",
558deadbb14SRichard Henderson     [CPU_FEATURE_BIT_VIS3] = "vis3",
55968a414e9SRichard Henderson     [CPU_FEATURE_BIT_IMA] = "ima",
560b12b7227SRichard Henderson     [CPU_FEATURE_BIT_VIS4] = "vis4",
561554abe47SRichard Henderson #else
562554abe47SRichard Henderson     [CPU_FEATURE_BIT_MUL] = "mul",
563554abe47SRichard Henderson     [CPU_FEATURE_BIT_DIV] = "div",
564554abe47SRichard Henderson     [CPU_FEATURE_BIT_FSMULD] = "fsmuld",
565554abe47SRichard Henderson #endif
566ab3b491fSBlue Swirl };
567ab3b491fSBlue Swirl 
5680442428aSMarkus Armbruster static void print_features(uint32_t features, const char *prefix)
569ab3b491fSBlue Swirl {
570ab3b491fSBlue Swirl     unsigned int i;
571ab3b491fSBlue Swirl 
572ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
573ab3b491fSBlue Swirl         if (feature_name[i] && (features & (1 << i))) {
574ab3b491fSBlue Swirl             if (prefix) {
5750442428aSMarkus Armbruster                 qemu_printf("%s", prefix);
576ab3b491fSBlue Swirl             }
5770442428aSMarkus Armbruster             qemu_printf("%s ", feature_name[i]);
578ab3b491fSBlue Swirl         }
579ab3b491fSBlue Swirl     }
580ab3b491fSBlue Swirl }
581ab3b491fSBlue Swirl 
5820442428aSMarkus Armbruster void sparc_cpu_list(void)
583ab3b491fSBlue Swirl {
584ab3b491fSBlue Swirl     unsigned int i;
585ab3b491fSBlue Swirl 
58647833f81SThomas Huth     qemu_printf("Available CPU types:\n");
587ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
58847833f81SThomas Huth         qemu_printf(" %-20s (IU " TARGET_FMT_lx
58947833f81SThomas Huth                     " FPU %08x MMU %08x NWINS %d) ",
590ab3b491fSBlue Swirl                     sparc_defs[i].name,
591ab3b491fSBlue Swirl                     sparc_defs[i].iu_version,
592ab3b491fSBlue Swirl                     sparc_defs[i].fpu_version,
593ab3b491fSBlue Swirl                     sparc_defs[i].mmu_version,
594ab3b491fSBlue Swirl                     sparc_defs[i].nwindows);
5950442428aSMarkus Armbruster         print_features(CPU_DEFAULT_FEATURES & ~sparc_defs[i].features, "-");
5960442428aSMarkus Armbruster         print_features(~CPU_DEFAULT_FEATURES & sparc_defs[i].features, "+");
5970442428aSMarkus Armbruster         qemu_printf("\n");
598ab3b491fSBlue Swirl     }
5990442428aSMarkus Armbruster     qemu_printf("Default CPU feature flags (use '-' to remove): ");
6000442428aSMarkus Armbruster     print_features(CPU_DEFAULT_FEATURES, NULL);
6010442428aSMarkus Armbruster     qemu_printf("\n");
6020442428aSMarkus Armbruster     qemu_printf("Available CPU feature flags (use '+' to add): ");
6030442428aSMarkus Armbruster     print_features(~CPU_DEFAULT_FEATURES, NULL);
6040442428aSMarkus Armbruster     qemu_printf("\n");
6050442428aSMarkus Armbruster     qemu_printf("Numerical features (use '=' to set): iu_version "
606ab3b491fSBlue Swirl                 "fpu_version mmu_version nwindows\n");
607ab3b491fSBlue Swirl }
608ab3b491fSBlue Swirl 
60990c84c56SMarkus Armbruster static void cpu_print_cc(FILE *f, uint32_t cc)
610ab3b491fSBlue Swirl {
61190c84c56SMarkus Armbruster     qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
612ab3b491fSBlue Swirl                  cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
613ab3b491fSBlue Swirl                  cc & PSR_CARRY ? 'C' : '-');
614ab3b491fSBlue Swirl }
615ab3b491fSBlue Swirl 
616ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
617ab3b491fSBlue Swirl #define REGS_PER_LINE 4
618ab3b491fSBlue Swirl #else
619ab3b491fSBlue Swirl #define REGS_PER_LINE 8
620ab3b491fSBlue Swirl #endif
621ab3b491fSBlue Swirl 
6229ac200acSPhilippe Mathieu-Daudé static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
623ab3b491fSBlue Swirl {
62477976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
625ab3b491fSBlue Swirl     int i, x;
626ab3b491fSBlue Swirl 
62790c84c56SMarkus Armbruster     qemu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
628ab3b491fSBlue Swirl                  env->npc);
629ab3b491fSBlue Swirl 
630ab3b491fSBlue Swirl     for (i = 0; i < 8; i++) {
631ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == 0) {
63290c84c56SMarkus Armbruster             qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
633ab3b491fSBlue Swirl         }
63490c84c56SMarkus Armbruster         qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
635ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
63690c84c56SMarkus Armbruster             qemu_fprintf(f, "\n");
637ab3b491fSBlue Swirl         }
638ab3b491fSBlue Swirl     }
639ab3b491fSBlue Swirl     for (x = 0; x < 3; x++) {
640ab3b491fSBlue Swirl         for (i = 0; i < 8; i++) {
641ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == 0) {
64290c84c56SMarkus Armbruster                 qemu_fprintf(f, "%%%c%d-%d: ",
643ab3b491fSBlue Swirl                              x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
644ab3b491fSBlue Swirl                              i, i + REGS_PER_LINE - 1);
645ab3b491fSBlue Swirl             }
64690c84c56SMarkus Armbruster             qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
647ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
64890c84c56SMarkus Armbruster                 qemu_fprintf(f, "\n");
649ab3b491fSBlue Swirl             }
650ab3b491fSBlue Swirl         }
651ab3b491fSBlue Swirl     }
65276a23ca0SRichard Henderson 
653d13c394cSRichard Henderson     if (flags & CPU_DUMP_FPU) {
65430038fd8SRichard Henderson         for (i = 0; i < TARGET_DPREGS; i++) {
655ab3b491fSBlue Swirl             if ((i & 3) == 0) {
65690c84c56SMarkus Armbruster                 qemu_fprintf(f, "%%f%02d: ", i * 2);
657ab3b491fSBlue Swirl             }
65890c84c56SMarkus Armbruster             qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
659ab3b491fSBlue Swirl             if ((i & 3) == 3) {
66090c84c56SMarkus Armbruster                 qemu_fprintf(f, "\n");
661ab3b491fSBlue Swirl             }
662ab3b491fSBlue Swirl         }
663d13c394cSRichard Henderson     }
664d13c394cSRichard Henderson 
665ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
66690c84c56SMarkus Armbruster     qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
667ab3b491fSBlue Swirl                  (unsigned)cpu_get_ccr(env));
66890c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
66990c84c56SMarkus Armbruster     qemu_fprintf(f, " xcc: ");
67090c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
67190c84c56SMarkus Armbruster     qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
672cbc3a6a4SArtyom Tarasenko                  env->psrpil, env->gl);
67390c84c56SMarkus Armbruster     qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
674cbc3a6a4SArtyom Tarasenko                  TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
67590c84c56SMarkus Armbruster     qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
676ab3b491fSBlue Swirl                  "cleanwin: %d cwp: %d\n",
677ab3b491fSBlue Swirl                  env->cansave, env->canrestore, env->otherwin, env->wstate,
678ab3b491fSBlue Swirl                  env->cleanwin, env->nwindows - 1 - env->cwp);
679ca4d5d86SPeter Maydell     qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: %016x\n",
6801ccd6e13SRichard Henderson                  cpu_get_fsr(env), env->y, env->fprs);
681cbc3a6a4SArtyom Tarasenko 
682ab3b491fSBlue Swirl #else
68390c84c56SMarkus Armbruster     qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
68490c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_psr(env));
68590c84c56SMarkus Armbruster     qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
686ab3b491fSBlue Swirl                  env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
687ab3b491fSBlue Swirl                  env->wim);
68890c84c56SMarkus Armbruster     qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
6891ccd6e13SRichard Henderson                  cpu_get_fsr(env), env->y);
690ab3b491fSBlue Swirl #endif
69190c84c56SMarkus Armbruster     qemu_fprintf(f, "\n");
692ab3b491fSBlue Swirl }
693ab7ab3d7SAndreas Färber 
694f45748f1SAndreas Färber static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
695f45748f1SAndreas Färber {
696f45748f1SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
697f45748f1SAndreas Färber 
698f45748f1SAndreas Färber     cpu->env.pc = value;
699f45748f1SAndreas Färber     cpu->env.npc = value + 4;
700f45748f1SAndreas Färber }
701f45748f1SAndreas Färber 
702e4fdf9dfSRichard Henderson static vaddr sparc_cpu_get_pc(CPUState *cs)
703e4fdf9dfSRichard Henderson {
704e4fdf9dfSRichard Henderson     SPARCCPU *cpu = SPARC_CPU(cs);
705e4fdf9dfSRichard Henderson 
706e4fdf9dfSRichard Henderson     return cpu->env.pc;
707e4fdf9dfSRichard Henderson }
708e4fdf9dfSRichard Henderson 
70904a37d4cSRichard Henderson static void sparc_cpu_synchronize_from_tb(CPUState *cs,
71004a37d4cSRichard Henderson                                           const TranslationBlock *tb)
711bdf7ae5bSAndreas Färber {
712bdf7ae5bSAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
713bdf7ae5bSAndreas Färber 
714b254c342SPhilippe Mathieu-Daudé     tcg_debug_assert(!tcg_cflags_has(cs, CF_PCREL));
715c4bf3a92SAnton Johansson     cpu->env.pc = tb->pc;
716bdf7ae5bSAndreas Färber     cpu->env.npc = tb->cs_base;
717bdf7ae5bSAndreas Färber }
718bdf7ae5bSAndreas Färber 
71932cf0ac2SAnton Johansson void cpu_get_tb_cpu_state(CPUSPARCState *env, vaddr *pc,
72032cf0ac2SAnton Johansson                           uint64_t *cs_base, uint32_t *pflags)
72132cf0ac2SAnton Johansson {
72232cf0ac2SAnton Johansson     uint32_t flags;
72332cf0ac2SAnton Johansson     *pc = env->pc;
72432cf0ac2SAnton Johansson     *cs_base = env->npc;
72532cf0ac2SAnton Johansson     flags = cpu_mmu_index(env_cpu(env), false);
72632cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
72732cf0ac2SAnton Johansson     if (cpu_supervisor_mode(env)) {
72832cf0ac2SAnton Johansson         flags |= TB_FLAG_SUPER;
72932cf0ac2SAnton Johansson     }
73032cf0ac2SAnton Johansson #endif
73132cf0ac2SAnton Johansson #ifdef TARGET_SPARC64
73232cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
73332cf0ac2SAnton Johansson     if (cpu_hypervisor_mode(env)) {
73432cf0ac2SAnton Johansson         flags |= TB_FLAG_HYPER;
73532cf0ac2SAnton Johansson     }
73632cf0ac2SAnton Johansson #endif
73732cf0ac2SAnton Johansson     if (env->pstate & PS_AM) {
73832cf0ac2SAnton Johansson         flags |= TB_FLAG_AM_ENABLED;
73932cf0ac2SAnton Johansson     }
74032cf0ac2SAnton Johansson     if ((env->pstate & PS_PEF) && (env->fprs & FPRS_FEF)) {
74132cf0ac2SAnton Johansson         flags |= TB_FLAG_FPU_ENABLED;
74232cf0ac2SAnton Johansson     }
74332cf0ac2SAnton Johansson     flags |= env->asi << TB_FLAG_ASI_SHIFT;
74432cf0ac2SAnton Johansson #else
74532cf0ac2SAnton Johansson     if (env->psref) {
74632cf0ac2SAnton Johansson         flags |= TB_FLAG_FPU_ENABLED;
74732cf0ac2SAnton Johansson     }
74832cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
74932cf0ac2SAnton Johansson     if (env->fsr_qne) {
75032cf0ac2SAnton Johansson         flags |= TB_FLAG_FSR_QNE;
75132cf0ac2SAnton Johansson     }
75232cf0ac2SAnton Johansson #endif /* !CONFIG_USER_ONLY */
75332cf0ac2SAnton Johansson #endif /* TARGET_SPARC64 */
75432cf0ac2SAnton Johansson     *pflags = flags;
75532cf0ac2SAnton Johansson }
75632cf0ac2SAnton Johansson 
757fc3630b2SPhilippe Mathieu-Daudé static void sparc_restore_state_to_opc(CPUState *cs,
758fc3630b2SPhilippe Mathieu-Daudé                                        const TranslationBlock *tb,
759fc3630b2SPhilippe Mathieu-Daudé                                        const uint64_t *data)
760fc3630b2SPhilippe Mathieu-Daudé {
761fc3630b2SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
762fc3630b2SPhilippe Mathieu-Daudé     target_ulong pc = data[0];
763fc3630b2SPhilippe Mathieu-Daudé     target_ulong npc = data[1];
764fc3630b2SPhilippe Mathieu-Daudé 
765fc3630b2SPhilippe Mathieu-Daudé     env->pc = pc;
766fc3630b2SPhilippe Mathieu-Daudé     if (npc == DYNAMIC_PC) {
767fc3630b2SPhilippe Mathieu-Daudé         /* dynamic NPC: already stored */
768fc3630b2SPhilippe Mathieu-Daudé     } else if (npc & JUMP_PC) {
769fc3630b2SPhilippe Mathieu-Daudé         /* jump PC: use 'cond' and the jump targets of the translation */
770fc3630b2SPhilippe Mathieu-Daudé         if (env->cond) {
771fc3630b2SPhilippe Mathieu-Daudé             env->npc = npc & ~3;
772fc3630b2SPhilippe Mathieu-Daudé         } else {
773fc3630b2SPhilippe Mathieu-Daudé             env->npc = pc + 4;
774fc3630b2SPhilippe Mathieu-Daudé         }
775fc3630b2SPhilippe Mathieu-Daudé     } else {
776fc3630b2SPhilippe Mathieu-Daudé         env->npc = npc;
777fc3630b2SPhilippe Mathieu-Daudé     }
778fc3630b2SPhilippe Mathieu-Daudé }
779fc3630b2SPhilippe Mathieu-Daudé 
7808c2e1b00SAndreas Färber static bool sparc_cpu_has_work(CPUState *cs)
7818c2e1b00SAndreas Färber {
7828c2e1b00SAndreas Färber     return (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
78377976769SPhilippe Mathieu-Daudé            cpu_interrupts_enabled(cpu_env(cs));
7848c2e1b00SAndreas Färber }
7858c2e1b00SAndreas Färber 
786a120d320SRichard Henderson static int sparc_cpu_mmu_index(CPUState *cs, bool ifetch)
787e3547a7dSRichard Henderson {
788e3547a7dSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
789e3547a7dSRichard Henderson 
790e3547a7dSRichard Henderson #ifndef TARGET_SPARC64
791e3547a7dSRichard Henderson     if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
792e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
793e3547a7dSRichard Henderson     } else {
794e3547a7dSRichard Henderson         return env->psrs;
795e3547a7dSRichard Henderson     }
796e3547a7dSRichard Henderson #else
797e3547a7dSRichard Henderson     /* IMMU or DMMU disabled.  */
798e3547a7dSRichard Henderson     if (ifetch
799e3547a7dSRichard Henderson         ? (env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0
800e3547a7dSRichard Henderson         : (env->lsu & DMMU_E) == 0) {
801e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
802e3547a7dSRichard Henderson     } else if (cpu_hypervisor_mode(env)) {
803e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
804e3547a7dSRichard Henderson     } else if (env->tl > 0) {
805e3547a7dSRichard Henderson         return MMU_NUCLEUS_IDX;
806e3547a7dSRichard Henderson     } else if (cpu_supervisor_mode(env)) {
807e3547a7dSRichard Henderson         return MMU_KERNEL_IDX;
808e3547a7dSRichard Henderson     } else {
809e3547a7dSRichard Henderson         return MMU_USER_IDX;
810e3547a7dSRichard Henderson     }
811e3547a7dSRichard Henderson #endif
812e3547a7dSRichard Henderson }
813e3547a7dSRichard Henderson 
81412a6c15eSIgor Mammedov static char *sparc_cpu_type_name(const char *cpu_model)
81512a6c15eSIgor Mammedov {
8161d4bfc54SIgor Mammedov     char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model);
81712a6c15eSIgor Mammedov     char *s = name;
81812a6c15eSIgor Mammedov 
81912a6c15eSIgor Mammedov     /* SPARC cpu model names happen to have whitespaces,
82012a6c15eSIgor Mammedov      * as type names shouldn't have spaces replace them with '-'
82112a6c15eSIgor Mammedov      */
82212a6c15eSIgor Mammedov     while ((s = strchr(s, ' '))) {
82312a6c15eSIgor Mammedov         *s = '-';
82412a6c15eSIgor Mammedov     }
82512a6c15eSIgor Mammedov 
82612a6c15eSIgor Mammedov     return name;
82712a6c15eSIgor Mammedov }
82812a6c15eSIgor Mammedov 
82912a6c15eSIgor Mammedov static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model)
83012a6c15eSIgor Mammedov {
83112a6c15eSIgor Mammedov     ObjectClass *oc;
83212a6c15eSIgor Mammedov     char *typename;
83312a6c15eSIgor Mammedov 
83412a6c15eSIgor Mammedov     typename = sparc_cpu_type_name(cpu_model);
8356b568e3fSThomas Huth 
8366b568e3fSThomas Huth     /* Fix up legacy names with '+' in it */
8376b568e3fSThomas Huth     if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV+"))) {
8386b568e3fSThomas Huth         g_free(typename);
8396b568e3fSThomas Huth         typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV-plus"));
8406b568e3fSThomas Huth     } else if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi+"))) {
8416b568e3fSThomas Huth         g_free(typename);
8426b568e3fSThomas Huth         typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi-plus"));
8436b568e3fSThomas Huth     }
8446b568e3fSThomas Huth 
84512a6c15eSIgor Mammedov     oc = object_class_by_name(typename);
84612a6c15eSIgor Mammedov     g_free(typename);
84712a6c15eSIgor Mammedov     return oc;
84812a6c15eSIgor Mammedov }
84912a6c15eSIgor Mammedov 
850b6e91ebfSAndreas Färber static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
851b6e91ebfSAndreas Färber {
852ce5b1bbfSLaurent Vivier     CPUState *cs = CPU(dev);
853b6e91ebfSAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
854ce5b1bbfSLaurent Vivier     Error *local_err = NULL;
85577976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
856247bf011SAndreas Färber 
85770054962SIgor Mammedov #if defined(CONFIG_USER_ONLY)
8585f25b383SRichard Henderson     /* We are emulating the kernel, which will trap and emulate float128. */
859576e1c4cSIgor Mammedov     env->def.features |= CPU_FEATURE_FLOAT128;
860247bf011SAndreas Färber #endif
861b6e91ebfSAndreas Färber 
86270054962SIgor Mammedov     env->version = env->def.iu_version;
86370054962SIgor Mammedov     env->nwindows = env->def.nwindows;
86470054962SIgor Mammedov #if !defined(TARGET_SPARC64)
86570054962SIgor Mammedov     env->mmuregs[0] |= env->def.mmu_version;
86670054962SIgor Mammedov     cpu_sparc_set_id(env, 0);
86770054962SIgor Mammedov     env->mxccregs[7] |= env->def.mxcc_version;
86870054962SIgor Mammedov #else
86970054962SIgor Mammedov     env->mmu_version = env->def.mmu_version;
87070054962SIgor Mammedov     env->maxtl = env->def.maxtl;
87170054962SIgor Mammedov     env->version |= env->def.maxtl << 8;
87270054962SIgor Mammedov     env->version |= env->def.nwindows - 1;
87370054962SIgor Mammedov #endif
87470054962SIgor Mammedov 
8754482f32dSPeter Maydell     /*
8764482f32dSPeter Maydell      * Prefer SNaN over QNaN, order B then A. It's OK to do this in realize
8774482f32dSPeter Maydell      * rather than reset, because fp_status is after 'end_reset_fields' in
8784482f32dSPeter Maydell      * the CPU state struct so it won't get zeroed on reset.
8794482f32dSPeter Maydell      */
8804482f32dSPeter Maydell     set_float_2nan_prop_rule(float_2nan_prop_s_ba, &env->fp_status);
88149866dcbSPeter Maydell     /* For fused-multiply add, prefer SNaN over QNaN, then C->B->A */
88249866dcbSPeter Maydell     set_float_3nan_prop_rule(float_3nan_prop_s_cba, &env->fp_status);
8839a31b8d0SPeter Maydell     /* For inf * 0 + NaN, return the input NaN */
8849a31b8d0SPeter Maydell     set_float_infzeronan_rule(float_infzeronan_dnan_never, &env->fp_status);
88545fb2cd6SPeter Maydell     /* Default NaN value: sign bit clear, all frac bits set */
88645fb2cd6SPeter Maydell     set_float_default_nan_pattern(0b01111111, &env->fp_status);
8874482f32dSPeter Maydell 
888ce5b1bbfSLaurent Vivier     cpu_exec_realizefn(cs, &local_err);
889ce5b1bbfSLaurent Vivier     if (local_err != NULL) {
890ce5b1bbfSLaurent Vivier         error_propagate(errp, local_err);
891ce5b1bbfSLaurent Vivier         return;
892ce5b1bbfSLaurent Vivier     }
893ce5b1bbfSLaurent Vivier 
894ce5b1bbfSLaurent Vivier     qemu_init_vcpu(cs);
89514a10fc3SAndreas Färber 
896b6e91ebfSAndreas Färber     scc->parent_realize(dev, errp);
897b6e91ebfSAndreas Färber }
898b6e91ebfSAndreas Färber 
899ab7ab3d7SAndreas Färber static void sparc_cpu_initfn(Object *obj)
900ab7ab3d7SAndreas Färber {
901ab7ab3d7SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(obj);
90212a6c15eSIgor Mammedov     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
903ab7ab3d7SAndreas Färber     CPUSPARCState *env = &cpu->env;
904ab7ab3d7SAndreas Färber 
905576e1c4cSIgor Mammedov     if (scc->cpu_def) {
906576e1c4cSIgor Mammedov         env->def = *scc->cpu_def;
907ab7ab3d7SAndreas Färber     }
908ab7ab3d7SAndreas Färber }
909ab7ab3d7SAndreas Färber 
910de05005bSIgor Mammedov static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
911de05005bSIgor Mammedov                                void *opaque, Error **errp)
912de05005bSIgor Mammedov {
913de05005bSIgor Mammedov     SPARCCPU *cpu = SPARC_CPU(obj);
914de05005bSIgor Mammedov     int64_t value = cpu->env.def.nwindows;
915de05005bSIgor Mammedov 
916de05005bSIgor Mammedov     visit_type_int(v, name, &value, errp);
917de05005bSIgor Mammedov }
918de05005bSIgor Mammedov 
919de05005bSIgor Mammedov static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
920de05005bSIgor Mammedov                                void *opaque, Error **errp)
921de05005bSIgor Mammedov {
922de05005bSIgor Mammedov     const int64_t min = MIN_NWINDOWS;
923de05005bSIgor Mammedov     const int64_t max = MAX_NWINDOWS;
924de05005bSIgor Mammedov     SPARCCPU *cpu = SPARC_CPU(obj);
925de05005bSIgor Mammedov     int64_t value;
926de05005bSIgor Mammedov 
927668f62ecSMarkus Armbruster     if (!visit_type_int(v, name, &value, errp)) {
928de05005bSIgor Mammedov         return;
929de05005bSIgor Mammedov     }
930de05005bSIgor Mammedov 
931de05005bSIgor Mammedov     if (value < min || value > max) {
932de05005bSIgor Mammedov         error_setg(errp, "Property %s.%s doesn't take value %" PRId64
933de05005bSIgor Mammedov                    " (minimum: %" PRId64 ", maximum: %" PRId64 ")",
934de05005bSIgor Mammedov                    object_get_typename(obj), name ? name : "null",
935de05005bSIgor Mammedov                    value, min, max);
936de05005bSIgor Mammedov         return;
937de05005bSIgor Mammedov     }
938de05005bSIgor Mammedov     cpu->env.def.nwindows = value;
939de05005bSIgor Mammedov }
940de05005bSIgor Mammedov 
9413834cc6fSRichard Henderson static const PropertyInfo qdev_prop_nwindows = {
942de05005bSIgor Mammedov     .name  = "int",
943de05005bSIgor Mammedov     .get   = sparc_get_nwindows,
944de05005bSIgor Mammedov     .set   = sparc_set_nwindows,
945de05005bSIgor Mammedov };
946de05005bSIgor Mammedov 
947de1f5203SRichard Henderson /* This must match feature_name[]. */
9483834cc6fSRichard Henderson static const Property sparc_cpu_properties[] = {
949de1f5203SRichard Henderson     DEFINE_PROP_BIT("float128", SPARCCPU, env.def.features,
950de1f5203SRichard Henderson                     CPU_FEATURE_BIT_FLOAT128, false),
951554abe47SRichard Henderson #ifdef TARGET_SPARC64
952de1f5203SRichard Henderson     DEFINE_PROP_BIT("cmt",      SPARCCPU, env.def.features,
953de1f5203SRichard Henderson                     CPU_FEATURE_BIT_CMT, false),
954de1f5203SRichard Henderson     DEFINE_PROP_BIT("gl",       SPARCCPU, env.def.features,
955de1f5203SRichard Henderson                     CPU_FEATURE_BIT_GL, false),
956554abe47SRichard Henderson     DEFINE_PROP_BIT("hypv",     SPARCCPU, env.def.features,
957554abe47SRichard Henderson                     CPU_FEATURE_BIT_HYPV, false),
958554abe47SRichard Henderson     DEFINE_PROP_BIT("vis1",     SPARCCPU, env.def.features,
959554abe47SRichard Henderson                     CPU_FEATURE_BIT_VIS1, false),
960554abe47SRichard Henderson     DEFINE_PROP_BIT("vis2",     SPARCCPU, env.def.features,
961554abe47SRichard Henderson                     CPU_FEATURE_BIT_VIS2, false),
9624fd71d19SRichard Henderson     DEFINE_PROP_BIT("fmaf",     SPARCCPU, env.def.features,
9634fd71d19SRichard Henderson                     CPU_FEATURE_BIT_FMAF, false),
964deadbb14SRichard Henderson     DEFINE_PROP_BIT("vis3",     SPARCCPU, env.def.features,
965deadbb14SRichard Henderson                     CPU_FEATURE_BIT_VIS3, false),
96668a414e9SRichard Henderson     DEFINE_PROP_BIT("ima",      SPARCCPU, env.def.features,
96768a414e9SRichard Henderson                     CPU_FEATURE_BIT_IMA, false),
968b12b7227SRichard Henderson     DEFINE_PROP_BIT("vis4",     SPARCCPU, env.def.features,
969b12b7227SRichard Henderson                     CPU_FEATURE_BIT_VIS4, false),
970554abe47SRichard Henderson #else
971554abe47SRichard Henderson     DEFINE_PROP_BIT("mul",      SPARCCPU, env.def.features,
972554abe47SRichard Henderson                     CPU_FEATURE_BIT_MUL, false),
973554abe47SRichard Henderson     DEFINE_PROP_BIT("div",      SPARCCPU, env.def.features,
974554abe47SRichard Henderson                     CPU_FEATURE_BIT_DIV, false),
975554abe47SRichard Henderson     DEFINE_PROP_BIT("fsmuld",   SPARCCPU, env.def.features,
976554abe47SRichard Henderson                     CPU_FEATURE_BIT_FSMULD, false),
977554abe47SRichard Henderson #endif
978de05005bSIgor Mammedov     DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU, env.def.iu_version, 0,
979de05005bSIgor Mammedov                          qdev_prop_uint64, target_ulong),
980de05005bSIgor Mammedov     DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0),
981de05005bSIgor Mammedov     DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0),
98243b6ab4cSEduardo Habkost     DEFINE_PROP("nwindows", SPARCCPU, env.def.nwindows,
98343b6ab4cSEduardo Habkost                 qdev_prop_nwindows, uint32_t),
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
99615017436SPhilippe Mathieu-Daudé #include "accel/tcg/cpu-ops.h"
99778271684SClaudio Fontana 
9981764ad70SRichard Henderson static const TCGCPUOps sparc_tcg_ops = {
99978271684SClaudio Fontana     .initialize = sparc_tcg_init,
1000e4a8e093SRichard Henderson     .translate_code = sparc_translate_code,
100178271684SClaudio Fontana     .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
1002f36aaa53SRichard Henderson     .restore_state_to_opc = sparc_restore_state_to_opc,
100378271684SClaudio Fontana 
100478271684SClaudio Fontana #ifndef CONFIG_USER_ONLY
1005caac44a5SRichard Henderson     .tlb_fill = sparc_cpu_tlb_fill,
1006798ac8b5SPhilippe Mathieu-Daudé     .cpu_exec_interrupt = sparc_cpu_exec_interrupt,
10074f7b1ecbSPeter Maydell     .cpu_exec_halt = sparc_cpu_has_work,
100878271684SClaudio Fontana     .do_interrupt = sparc_cpu_do_interrupt,
100978271684SClaudio Fontana     .do_transaction_failed = sparc_cpu_do_transaction_failed,
101078271684SClaudio Fontana     .do_unaligned_access = sparc_cpu_do_unaligned_access,
101178271684SClaudio Fontana #endif /* !CONFIG_USER_ONLY */
101278271684SClaudio Fontana };
101378271684SClaudio Fontana #endif /* CONFIG_TCG */
101478271684SClaudio Fontana 
1015ab7ab3d7SAndreas Färber static void sparc_cpu_class_init(ObjectClass *oc, void *data)
1016ab7ab3d7SAndreas Färber {
1017ab7ab3d7SAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
1018ab7ab3d7SAndreas Färber     CPUClass *cc = CPU_CLASS(oc);
1019b6e91ebfSAndreas Färber     DeviceClass *dc = DEVICE_CLASS(oc);
10203b4fff1bSPeter Maydell     ResettableClass *rc = RESETTABLE_CLASS(oc);
1021b6e91ebfSAndreas Färber 
1022bf853881SPhilippe Mathieu-Daudé     device_class_set_parent_realize(dc, sparc_cpu_realizefn,
1023bf853881SPhilippe Mathieu-Daudé                                     &scc->parent_realize);
10244f67d30bSMarc-André Lureau     device_class_set_props(dc, sparc_cpu_properties);
1025ab7ab3d7SAndreas Färber 
10263b4fff1bSPeter Maydell     resettable_class_set_parent_phases(rc, NULL, sparc_cpu_reset_hold, NULL,
10273b4fff1bSPeter Maydell                                        &scc->parent_phases);
102897a8ea5aSAndreas Färber 
102912a6c15eSIgor Mammedov     cc->class_by_name = sparc_cpu_class_by_name;
1030d1853231SIgor Mammedov     cc->parse_features = sparc_cpu_parse_features;
10318c2e1b00SAndreas Färber     cc->has_work = sparc_cpu_has_work;
1032e3547a7dSRichard Henderson     cc->mmu_index = sparc_cpu_mmu_index;
1033878096eeSAndreas Färber     cc->dump_state = sparc_cpu_dump_state;
1034f3659eeeSAndreas Färber #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
1035f3659eeeSAndreas Färber     cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
1036f3659eeeSAndreas Färber #endif
1037f45748f1SAndreas Färber     cc->set_pc = sparc_cpu_set_pc;
1038e4fdf9dfSRichard Henderson     cc->get_pc = sparc_cpu_get_pc;
10395b50e790SAndreas Färber     cc->gdb_read_register = sparc_cpu_gdb_read_register;
10405b50e790SAndreas Färber     cc->gdb_write_register = sparc_cpu_gdb_write_register;
1041e84942f2SRichard Henderson #ifndef CONFIG_USER_ONLY
10428b80bd28SPhilippe Mathieu-Daudé     cc->sysemu_ops = &sparc_sysemu_ops;
104300b941e5SAndreas Färber #endif
1044df0900ebSPeter Crosthwaite     cc->disas_set_info = cpu_sparc_disas_set_info;
1045a0e372f0SAndreas Färber 
1046a0e372f0SAndreas Färber #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1047a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 86;
1048a0e372f0SAndreas Färber #else
1049a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 72;
1050a0e372f0SAndreas Färber #endif
105178271684SClaudio Fontana     cc->tcg_ops = &sparc_tcg_ops;
1052ab7ab3d7SAndreas Färber }
1053ab7ab3d7SAndreas Färber 
1054ab7ab3d7SAndreas Färber static const TypeInfo sparc_cpu_type_info = {
1055ab7ab3d7SAndreas Färber     .name = TYPE_SPARC_CPU,
1056ab7ab3d7SAndreas Färber     .parent = TYPE_CPU,
1057ab7ab3d7SAndreas Färber     .instance_size = sizeof(SPARCCPU),
1058f669c992SRichard Henderson     .instance_align = __alignof(SPARCCPU),
1059ab7ab3d7SAndreas Färber     .instance_init = sparc_cpu_initfn,
106012a6c15eSIgor Mammedov     .abstract = true,
1061ab7ab3d7SAndreas Färber     .class_size = sizeof(SPARCCPUClass),
1062ab7ab3d7SAndreas Färber     .class_init = sparc_cpu_class_init,
1063ab7ab3d7SAndreas Färber };
1064ab7ab3d7SAndreas Färber 
106512a6c15eSIgor Mammedov static void sparc_cpu_cpudef_class_init(ObjectClass *oc, void *data)
106612a6c15eSIgor Mammedov {
106712a6c15eSIgor Mammedov     SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
106812a6c15eSIgor Mammedov     scc->cpu_def = data;
106912a6c15eSIgor Mammedov }
107012a6c15eSIgor Mammedov 
107112a6c15eSIgor Mammedov static void sparc_register_cpudef_type(const struct sparc_def_t *def)
107212a6c15eSIgor Mammedov {
107312a6c15eSIgor Mammedov     char *typename = sparc_cpu_type_name(def->name);
107412a6c15eSIgor Mammedov     TypeInfo ti = {
107512a6c15eSIgor Mammedov         .name = typename,
107612a6c15eSIgor Mammedov         .parent = TYPE_SPARC_CPU,
107712a6c15eSIgor Mammedov         .class_init = sparc_cpu_cpudef_class_init,
107812a6c15eSIgor Mammedov         .class_data = (void *)def,
107912a6c15eSIgor Mammedov     };
108012a6c15eSIgor Mammedov 
10812f02b71bSZhao Liu     type_register_static(&ti);
108212a6c15eSIgor Mammedov     g_free(typename);
108312a6c15eSIgor Mammedov }
108412a6c15eSIgor Mammedov 
1085ab7ab3d7SAndreas Färber static void sparc_cpu_register_types(void)
1086ab7ab3d7SAndreas Färber {
108712a6c15eSIgor Mammedov     int i;
108812a6c15eSIgor Mammedov 
1089ab7ab3d7SAndreas Färber     type_register_static(&sparc_cpu_type_info);
109012a6c15eSIgor Mammedov     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
109112a6c15eSIgor Mammedov         sparc_register_cpudef_type(&sparc_defs[i]);
109212a6c15eSIgor Mammedov     }
1093ab7ab3d7SAndreas Färber }
1094ab7ab3d7SAndreas Färber 
1095ab7ab3d7SAndreas Färber type_init(sparc_cpu_register_types)
1096