xref: /qemu/target/sparc/cpu.c (revision 04583ce7e032ee8e0a12756b69dc67ad7b399997)
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"
25efe25c26SRichard Henderson #include "accel/tcg/cpu-mmu-index.h"
2663c91552SPaolo Bonzini #include "exec/exec-all.h"
278865049bSPhilippe Mathieu-Daudé #include "exec/translation-block.h"
28de05005bSIgor Mammedov #include "hw/qdev-properties.h"
29de05005bSIgor Mammedov #include "qapi/visitor.h"
30c4bf3a92SAnton Johansson #include "tcg/tcg.h"
314482f32dSPeter Maydell #include "fpu/softfloat.h"
32fc3630b2SPhilippe Mathieu-Daudé #include "target/sparc/translate.h"
33ab3b491fSBlue Swirl 
34ab3b491fSBlue Swirl //#define DEBUG_FEATURES
35ab3b491fSBlue Swirl 
36ad80e367SPeter Maydell static void sparc_cpu_reset_hold(Object *obj, ResetType type)
37ab7ab3d7SAndreas Färber {
38348802b5SPhilippe Mathieu-Daudé     CPUState *cs = CPU(obj);
39348802b5SPhilippe Mathieu-Daudé     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
4077976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
41ab7ab3d7SAndreas Färber 
423b4fff1bSPeter Maydell     if (scc->parent_phases.hold) {
43ad80e367SPeter Maydell         scc->parent_phases.hold(obj, type);
443b4fff1bSPeter Maydell     }
45ab7ab3d7SAndreas Färber 
461f5c00cfSAlex Bennée     memset(env, 0, offsetof(CPUSPARCState, end_reset_fields));
47ab3b491fSBlue Swirl     env->cwp = 0;
48ab3b491fSBlue Swirl #ifndef TARGET_SPARC64
49ab3b491fSBlue Swirl     env->wim = 1;
50ab3b491fSBlue Swirl #endif
51ab3b491fSBlue Swirl     env->regwptr = env->regbase + (env->cwp * 16);
52ab3b491fSBlue Swirl #if defined(CONFIG_USER_ONLY)
53ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
54ab3b491fSBlue Swirl     env->cleanwin = env->nwindows - 2;
55ab3b491fSBlue Swirl     env->cansave = env->nwindows - 2;
56ab3b491fSBlue Swirl     env->pstate = PS_RMO | PS_PEF | PS_IE;
57ab3b491fSBlue Swirl     env->asi = 0x82; /* Primary no-fault */
58ab3b491fSBlue Swirl #endif
59ab3b491fSBlue Swirl #else
60ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
61ab3b491fSBlue Swirl     env->psret = 0;
62ab3b491fSBlue Swirl     env->psrs = 1;
63ab3b491fSBlue Swirl     env->psrps = 1;
64ab3b491fSBlue Swirl #endif
65ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
66cbc3a6a4SArtyom Tarasenko     env->pstate = PS_PRIV | PS_RED | PS_PEF;
67cbc3a6a4SArtyom Tarasenko     if (!cpu_has_hypervisor(env)) {
68cbc3a6a4SArtyom Tarasenko         env->pstate |= PS_AG;
69cbc3a6a4SArtyom Tarasenko     }
70ab3b491fSBlue Swirl     env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0;
71ab3b491fSBlue Swirl     env->tl = env->maxtl;
72cbc3a6a4SArtyom Tarasenko     env->gl = 2;
73ab3b491fSBlue Swirl     cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
74ab3b491fSBlue Swirl     env->lsu = 0;
75ab3b491fSBlue Swirl #else
76ab3b491fSBlue Swirl     env->mmuregs[0] &= ~(MMU_E | MMU_NF);
77576e1c4cSIgor Mammedov     env->mmuregs[0] |= env->def.mmu_bm;
78ab3b491fSBlue Swirl #endif
79ab3b491fSBlue Swirl     env->pc = 0;
80ab3b491fSBlue Swirl     env->npc = env->pc + 4;
81ab3b491fSBlue Swirl #endif
82ab3b491fSBlue Swirl     env->cache_control = 0;
8365c1c039SPeter Maydell     cpu_put_fsr(env, 0);
84ab3b491fSBlue Swirl }
85ab3b491fSBlue Swirl 
86798ac8b5SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
8787afe467SRichard Henderson static bool sparc_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
8887afe467SRichard Henderson {
8987afe467SRichard Henderson     if (interrupt_request & CPU_INTERRUPT_HARD) {
9077976769SPhilippe Mathieu-Daudé         CPUSPARCState *env = cpu_env(cs);
9187afe467SRichard Henderson 
9287afe467SRichard Henderson         if (cpu_interrupts_enabled(env) && env->interrupt_index > 0) {
9387afe467SRichard Henderson             int pil = env->interrupt_index & 0xf;
9487afe467SRichard Henderson             int type = env->interrupt_index & 0xf0;
9587afe467SRichard Henderson 
9687afe467SRichard Henderson             if (type != TT_EXTINT || cpu_pil_allowed(env, pil)) {
9787afe467SRichard Henderson                 cs->exception_index = env->interrupt_index;
9887afe467SRichard Henderson                 sparc_cpu_do_interrupt(cs);
9987afe467SRichard Henderson                 return true;
10087afe467SRichard Henderson             }
10187afe467SRichard Henderson         }
10287afe467SRichard Henderson     }
10387afe467SRichard Henderson     return false;
10487afe467SRichard Henderson }
105798ac8b5SPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
10687afe467SRichard Henderson 
107df0900ebSPeter Crosthwaite static void cpu_sparc_disas_set_info(CPUState *cpu, disassemble_info *info)
108df0900ebSPeter Crosthwaite {
109df0900ebSPeter Crosthwaite     info->print_insn = print_insn_sparc;
1102136f7f1SPhilippe Mathieu-Daudé     info->endian = BFD_ENDIAN_BIG;
111df0900ebSPeter Crosthwaite #ifdef TARGET_SPARC64
112df0900ebSPeter Crosthwaite     info->mach = bfd_mach_sparc_v9b;
113df0900ebSPeter Crosthwaite #endif
114df0900ebSPeter Crosthwaite }
115df0900ebSPeter Crosthwaite 
116d1853231SIgor Mammedov static void
117d1853231SIgor Mammedov cpu_add_feat_as_prop(const char *typename, const char *name, const char *val)
118ab3b491fSBlue Swirl {
119d1853231SIgor Mammedov     GlobalProperty *prop = g_new0(typeof(*prop), 1);
120d1853231SIgor Mammedov     prop->driver = typename;
121d1853231SIgor Mammedov     prop->property = g_strdup(name);
122d1853231SIgor Mammedov     prop->value = g_strdup(val);
123d1853231SIgor Mammedov     qdev_prop_register_global(prop);
124433ac7a9SAndreas Färber }
125433ac7a9SAndreas Färber 
126d1853231SIgor Mammedov /* Parse "+feature,-feature,feature=foo" CPU feature string */
127d1853231SIgor Mammedov static void sparc_cpu_parse_features(const char *typename, char *features,
128d1853231SIgor Mammedov                                      Error **errp)
129d1853231SIgor Mammedov {
130d1853231SIgor Mammedov     GList *l, *plus_features = NULL, *minus_features = NULL;
131d1853231SIgor Mammedov     char *featurestr; /* Single 'key=value" string being parsed */
132d1853231SIgor Mammedov     static bool cpu_globals_initialized;
133d1853231SIgor Mammedov 
134d1853231SIgor Mammedov     if (cpu_globals_initialized) {
135d1853231SIgor Mammedov         return;
136d1853231SIgor Mammedov     }
137d1853231SIgor Mammedov     cpu_globals_initialized = true;
138d1853231SIgor Mammedov 
139d1853231SIgor Mammedov     if (!features) {
140d1853231SIgor Mammedov         return;
141d1853231SIgor Mammedov     }
142d1853231SIgor Mammedov 
143d1853231SIgor Mammedov     for (featurestr = strtok(features, ",");
144d1853231SIgor Mammedov          featurestr;
145d1853231SIgor Mammedov          featurestr = strtok(NULL, ",")) {
146d1853231SIgor Mammedov         const char *name;
147d1853231SIgor Mammedov         const char *val = NULL;
148d1853231SIgor Mammedov         char *eq = NULL;
149d1853231SIgor Mammedov 
150d1853231SIgor Mammedov         /* Compatibility syntax: */
151d1853231SIgor Mammedov         if (featurestr[0] == '+') {
152d1853231SIgor Mammedov             plus_features = g_list_append(plus_features,
153d1853231SIgor Mammedov                                           g_strdup(featurestr + 1));
154d1853231SIgor Mammedov             continue;
155d1853231SIgor Mammedov         } else if (featurestr[0] == '-') {
156d1853231SIgor Mammedov             minus_features = g_list_append(minus_features,
157d1853231SIgor Mammedov                                            g_strdup(featurestr + 1));
158d1853231SIgor Mammedov             continue;
159d1853231SIgor Mammedov         }
160d1853231SIgor Mammedov 
161d1853231SIgor Mammedov         eq = strchr(featurestr, '=');
162d1853231SIgor Mammedov         name = featurestr;
163d1853231SIgor Mammedov         if (eq) {
164d1853231SIgor Mammedov             *eq++ = 0;
165d1853231SIgor Mammedov             val = eq;
166d1853231SIgor Mammedov 
167d1853231SIgor Mammedov             /*
168d1853231SIgor Mammedov              * Temporarily, only +feat/-feat will be supported
169d1853231SIgor Mammedov              * for boolean properties until we remove the
170d1853231SIgor Mammedov              * minus-overrides-plus semantics and just follow
171d1853231SIgor Mammedov              * the order options appear on the command-line.
172d1853231SIgor Mammedov              *
173d1853231SIgor Mammedov              * TODO: warn if user is relying on minus-override-plus semantics
174d1853231SIgor Mammedov              * TODO: remove minus-override-plus semantics after
175d1853231SIgor Mammedov              *       warning for a few releases
176d1853231SIgor Mammedov              */
177d1853231SIgor Mammedov             if (!strcasecmp(val, "on") ||
178d1853231SIgor Mammedov                 !strcasecmp(val, "off") ||
179d1853231SIgor Mammedov                 !strcasecmp(val, "true") ||
180d1853231SIgor Mammedov                 !strcasecmp(val, "false")) {
181d1853231SIgor Mammedov                 error_setg(errp, "Boolean properties in format %s=%s"
182d1853231SIgor Mammedov                                  " are not supported", name, val);
183d1853231SIgor Mammedov                 return;
184d1853231SIgor Mammedov             }
185d1853231SIgor Mammedov         } else {
186d1853231SIgor Mammedov             error_setg(errp, "Unsupported property format: %s", name);
187d1853231SIgor Mammedov             return;
188d1853231SIgor Mammedov         }
189d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, val);
190d1853231SIgor Mammedov     }
191d1853231SIgor Mammedov 
192d1853231SIgor Mammedov     for (l = plus_features; l; l = l->next) {
193d1853231SIgor Mammedov         const char *name = l->data;
194d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, "on");
195d1853231SIgor Mammedov     }
196d1853231SIgor Mammedov     g_list_free_full(plus_features, g_free);
197d1853231SIgor Mammedov 
198d1853231SIgor Mammedov     for (l = minus_features; l; l = l->next) {
199d1853231SIgor Mammedov         const char *name = l->data;
200d1853231SIgor Mammedov         cpu_add_feat_as_prop(typename, name, "off");
201d1853231SIgor Mammedov     }
202d1853231SIgor Mammedov     g_list_free_full(minus_features, g_free);
203ab3b491fSBlue Swirl }
204ab3b491fSBlue Swirl 
205ab3b491fSBlue Swirl void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
206ab3b491fSBlue Swirl {
207ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64)
208ab3b491fSBlue Swirl     env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
209ab3b491fSBlue Swirl #endif
210ab3b491fSBlue Swirl }
211ab3b491fSBlue Swirl 
212ab3b491fSBlue Swirl static const sparc_def_t sparc_defs[] = {
213ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
214ab3b491fSBlue Swirl     {
2154a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64",
216ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
217ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
218ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
219ab3b491fSBlue Swirl         .nwindows = 4,
220ab3b491fSBlue Swirl         .maxtl = 4,
221ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
222ab3b491fSBlue Swirl     },
223ab3b491fSBlue Swirl     {
2244a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-III",
225ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
226ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
227ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
228ab3b491fSBlue Swirl         .nwindows = 5,
229ab3b491fSBlue Swirl         .maxtl = 4,
230ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
231ab3b491fSBlue Swirl     },
232ab3b491fSBlue Swirl     {
2334a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-IV",
234ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
235ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
236ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
237ab3b491fSBlue Swirl         .nwindows = 8,
238ab3b491fSBlue Swirl         .maxtl = 5,
239ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
240ab3b491fSBlue Swirl     },
241ab3b491fSBlue Swirl     {
2424a7bdec3SThomas Huth         .name = "Fujitsu-Sparc64-V",
243ab3b491fSBlue Swirl         .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
244ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
245ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
246ab3b491fSBlue Swirl         .nwindows = 8,
247ab3b491fSBlue Swirl         .maxtl = 5,
248ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
249ab3b491fSBlue Swirl     },
250ab3b491fSBlue Swirl     {
2514a7bdec3SThomas Huth         .name = "TI-UltraSparc-I",
252ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
253ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
254ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
255ab3b491fSBlue Swirl         .nwindows = 8,
256ab3b491fSBlue Swirl         .maxtl = 5,
257ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
258ab3b491fSBlue Swirl     },
259ab3b491fSBlue Swirl     {
2604a7bdec3SThomas Huth         .name = "TI-UltraSparc-II",
261ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
262ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
263ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
264ab3b491fSBlue Swirl         .nwindows = 8,
265ab3b491fSBlue Swirl         .maxtl = 5,
266ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
267ab3b491fSBlue Swirl     },
268ab3b491fSBlue Swirl     {
2694a7bdec3SThomas Huth         .name = "TI-UltraSparc-IIi",
270ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
271ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
272ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
273ab3b491fSBlue Swirl         .nwindows = 8,
274ab3b491fSBlue Swirl         .maxtl = 5,
275ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
276ab3b491fSBlue Swirl     },
277ab3b491fSBlue Swirl     {
2784a7bdec3SThomas Huth         .name = "TI-UltraSparc-IIe",
279ab3b491fSBlue Swirl         .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
280ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
281ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
282ab3b491fSBlue Swirl         .nwindows = 8,
283ab3b491fSBlue Swirl         .maxtl = 5,
284ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
285ab3b491fSBlue Swirl     },
286ab3b491fSBlue Swirl     {
2874a7bdec3SThomas Huth         .name = "Sun-UltraSparc-III",
288ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
289ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
290ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
291ab3b491fSBlue Swirl         .nwindows = 8,
292ab3b491fSBlue Swirl         .maxtl = 5,
293ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
294ab3b491fSBlue Swirl     },
295ab3b491fSBlue Swirl     {
2964a7bdec3SThomas Huth         .name = "Sun-UltraSparc-III-Cu",
297ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
298ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
299ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
300ab3b491fSBlue Swirl         .nwindows = 8,
301ab3b491fSBlue Swirl         .maxtl = 5,
302ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
303ab3b491fSBlue Swirl     },
304ab3b491fSBlue Swirl     {
3054a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IIIi",
306ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
307ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
308ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
309ab3b491fSBlue Swirl         .nwindows = 8,
310ab3b491fSBlue Swirl         .maxtl = 5,
311ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
312ab3b491fSBlue Swirl     },
313ab3b491fSBlue Swirl     {
3144a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IV",
315ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
316ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
317ab3b491fSBlue Swirl         .mmu_version = mmu_us_4,
318ab3b491fSBlue Swirl         .nwindows = 8,
319ab3b491fSBlue Swirl         .maxtl = 5,
320ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
321ab3b491fSBlue Swirl     },
322ab3b491fSBlue Swirl     {
3234a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IV-plus",
324ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
325ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
326ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
327ab3b491fSBlue Swirl         .nwindows = 8,
328ab3b491fSBlue Swirl         .maxtl = 5,
329ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
330ab3b491fSBlue Swirl     },
331ab3b491fSBlue Swirl     {
3324a7bdec3SThomas Huth         .name = "Sun-UltraSparc-IIIi-plus",
333ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
334ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
335ab3b491fSBlue Swirl         .mmu_version = mmu_us_3,
336ab3b491fSBlue Swirl         .nwindows = 8,
337ab3b491fSBlue Swirl         .maxtl = 5,
338ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
339ab3b491fSBlue Swirl     },
340ab3b491fSBlue Swirl     {
3414a7bdec3SThomas Huth         .name = "Sun-UltraSparc-T1",
342ab3b491fSBlue Swirl         /* defined in sparc_ifu_fdp.v and ctu.h */
343ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
344ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
345ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
346ab3b491fSBlue Swirl         .nwindows = 8,
347ab3b491fSBlue Swirl         .maxtl = 6,
348ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
349ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
350ab3b491fSBlue Swirl     },
351ab3b491fSBlue Swirl     {
3524a7bdec3SThomas Huth         .name = "Sun-UltraSparc-T2",
353ab3b491fSBlue Swirl         /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
354ab3b491fSBlue Swirl         .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
355ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
356ab3b491fSBlue Swirl         .mmu_version = mmu_sun4v,
357ab3b491fSBlue Swirl         .nwindows = 8,
358ab3b491fSBlue Swirl         .maxtl = 6,
359ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
360ab3b491fSBlue Swirl         | CPU_FEATURE_GL,
361ab3b491fSBlue Swirl     },
362ab3b491fSBlue Swirl     {
3634a7bdec3SThomas Huth         .name = "NEC-UltraSparc-I",
364ab3b491fSBlue Swirl         .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
365ab3b491fSBlue Swirl         .fpu_version = 0x00000000,
366ab3b491fSBlue Swirl         .mmu_version = mmu_us_12,
367ab3b491fSBlue Swirl         .nwindows = 8,
368ab3b491fSBlue Swirl         .maxtl = 5,
369ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
370ab3b491fSBlue Swirl     },
371ab3b491fSBlue Swirl #else
372ab3b491fSBlue Swirl     {
3734a7bdec3SThomas Huth         .name = "Fujitsu-MB86904",
374ab3b491fSBlue Swirl         .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
37549bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
376ab3b491fSBlue Swirl         .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
377ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
378ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
379ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
380ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
381ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
382ab3b491fSBlue Swirl         .nwindows = 8,
383ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
384ab3b491fSBlue Swirl     },
385ab3b491fSBlue Swirl     {
3864a7bdec3SThomas Huth         .name = "Fujitsu-MB86907",
387ab3b491fSBlue Swirl         .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
38849bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
389ab3b491fSBlue Swirl         .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
390ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
391ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
392ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
393ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
394ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
395ab3b491fSBlue Swirl         .nwindows = 8,
396ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
397ab3b491fSBlue Swirl     },
398ab3b491fSBlue Swirl     {
3994a7bdec3SThomas Huth         .name = "TI-MicroSparc-I",
400ab3b491fSBlue Swirl         .iu_version = 0x41000000,
40149bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
402ab3b491fSBlue Swirl         .mmu_version = 0x41000000,
403ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
404ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
405ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
406ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
407ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x0000003f,
408ab3b491fSBlue Swirl         .nwindows = 7,
4095f25b383SRichard Henderson         .features = CPU_FEATURE_MUL | CPU_FEATURE_DIV,
410ab3b491fSBlue Swirl     },
411ab3b491fSBlue Swirl     {
4124a7bdec3SThomas Huth         .name = "TI-MicroSparc-II",
413ab3b491fSBlue Swirl         .iu_version = 0x42000000,
41449bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
415ab3b491fSBlue Swirl         .mmu_version = 0x02000000,
416ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
417ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
418ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
419ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016fff,
420ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
421ab3b491fSBlue Swirl         .nwindows = 8,
422ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
423ab3b491fSBlue Swirl     },
424ab3b491fSBlue Swirl     {
4254a7bdec3SThomas Huth         .name = "TI-MicroSparc-IIep",
426ab3b491fSBlue Swirl         .iu_version = 0x42000000,
42749bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT,
428ab3b491fSBlue Swirl         .mmu_version = 0x04000000,
429ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
430ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x00ffffc0,
431ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x000000ff,
432ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0x00016bff,
433ab3b491fSBlue Swirl         .mmu_trcr_mask = 0x00ffffff,
434ab3b491fSBlue Swirl         .nwindows = 8,
435ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
436ab3b491fSBlue Swirl     },
437ab3b491fSBlue Swirl     {
4384a7bdec3SThomas Huth         .name = "TI-SuperSparc-40", /* STP1020NPGA */
439ab3b491fSBlue Swirl         .iu_version = 0x41000000, /* SuperSPARC 2.x */
44049bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
441ab3b491fSBlue Swirl         .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */
442ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
443ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
444ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
445ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
446ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
447ab3b491fSBlue Swirl         .nwindows = 8,
448ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
449ab3b491fSBlue Swirl     },
450ab3b491fSBlue Swirl     {
4514a7bdec3SThomas Huth         .name = "TI-SuperSparc-50", /* STP1020PGA */
452ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
45349bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
454ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
455ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
456ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
457ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
458ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
459ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
460ab3b491fSBlue Swirl         .nwindows = 8,
461ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
462ab3b491fSBlue Swirl     },
463ab3b491fSBlue Swirl     {
4644a7bdec3SThomas Huth         .name = "TI-SuperSparc-51",
465ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
46649bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
467ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
468ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
469ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
470ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
471ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
472ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
473ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
474ab3b491fSBlue Swirl         .nwindows = 8,
475ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
476ab3b491fSBlue Swirl     },
477ab3b491fSBlue Swirl     {
4784a7bdec3SThomas Huth         .name = "TI-SuperSparc-60", /* STP1020APGA */
479ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC 3.x */
48049bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
481ab3b491fSBlue Swirl         .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
482ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
483ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
484ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
485ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
486ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
487ab3b491fSBlue Swirl         .nwindows = 8,
488ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
489ab3b491fSBlue Swirl     },
490ab3b491fSBlue Swirl     {
4914a7bdec3SThomas Huth         .name = "TI-SuperSparc-61",
492ab3b491fSBlue Swirl         .iu_version = 0x44000000, /* SuperSPARC 3.x */
49349bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
494ab3b491fSBlue Swirl         .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
495ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
496ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
497ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
498ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
499ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
500ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
501ab3b491fSBlue Swirl         .nwindows = 8,
502ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
503ab3b491fSBlue Swirl     },
504ab3b491fSBlue Swirl     {
5054a7bdec3SThomas Huth         .name = "TI-SuperSparc-II",
506ab3b491fSBlue Swirl         .iu_version = 0x40000000, /* SuperSPARC II 1.x */
50749bb9725SRichard Henderson         .fpu_version = 0 << FSR_VER_SHIFT,
508ab3b491fSBlue Swirl         .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */
509ab3b491fSBlue Swirl         .mmu_bm = 0x00002000,
510ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0xffffffc0,
511ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000ffff,
512ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
513ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
514ab3b491fSBlue Swirl         .mxcc_version = 0x00000104,
515ab3b491fSBlue Swirl         .nwindows = 8,
516ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES,
517ab3b491fSBlue Swirl     },
518ab3b491fSBlue Swirl     {
519ab3b491fSBlue Swirl         .name = "LEON2",
520ab3b491fSBlue Swirl         .iu_version = 0xf2000000,
52149bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
522ab3b491fSBlue Swirl         .mmu_version = 0xf2000000,
523ab3b491fSBlue Swirl         .mmu_bm = 0x00004000,
524ab3b491fSBlue Swirl         .mmu_ctpr_mask = 0x007ffff0,
525ab3b491fSBlue Swirl         .mmu_cxr_mask = 0x0000003f,
526ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
527ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
528ab3b491fSBlue Swirl         .nwindows = 8,
529ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
530ab3b491fSBlue Swirl     },
531ab3b491fSBlue Swirl     {
532ab3b491fSBlue Swirl         .name = "LEON3",
533ab3b491fSBlue Swirl         .iu_version = 0xf3000000,
53449bb9725SRichard Henderson         .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
535ab3b491fSBlue Swirl         .mmu_version = 0xf3000000,
536ab3b491fSBlue Swirl         .mmu_bm = 0x00000000,
5377a0a9c2cSRonald Hecht         .mmu_ctpr_mask = 0xfffffffc,
5387a0a9c2cSRonald Hecht         .mmu_cxr_mask = 0x000000ff,
539ab3b491fSBlue Swirl         .mmu_sfsr_mask = 0xffffffff,
540ab3b491fSBlue Swirl         .mmu_trcr_mask = 0xffffffff,
541ab3b491fSBlue Swirl         .nwindows = 8,
542ab3b491fSBlue Swirl         .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
54316c358e9SSebastian Huber         CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL | CPU_FEATURE_POWERDOWN |
54416c358e9SSebastian Huber         CPU_FEATURE_CASA,
545ab3b491fSBlue Swirl     },
546ab3b491fSBlue Swirl #endif
547ab3b491fSBlue Swirl };
548ab3b491fSBlue Swirl 
549de1f5203SRichard Henderson /* This must match sparc_cpu_properties[]. */
550ab3b491fSBlue Swirl static const char * const feature_name[] = {
551de1f5203SRichard Henderson     [CPU_FEATURE_BIT_FLOAT128] = "float128",
552554abe47SRichard Henderson #ifdef TARGET_SPARC64
553de1f5203SRichard Henderson     [CPU_FEATURE_BIT_CMT] = "cmt",
554de1f5203SRichard Henderson     [CPU_FEATURE_BIT_GL] = "gl",
555554abe47SRichard Henderson     [CPU_FEATURE_BIT_HYPV] = "hypv",
556554abe47SRichard Henderson     [CPU_FEATURE_BIT_VIS1] = "vis1",
557554abe47SRichard Henderson     [CPU_FEATURE_BIT_VIS2] = "vis2",
5584fd71d19SRichard Henderson     [CPU_FEATURE_BIT_FMAF] = "fmaf",
559deadbb14SRichard Henderson     [CPU_FEATURE_BIT_VIS3] = "vis3",
56068a414e9SRichard Henderson     [CPU_FEATURE_BIT_IMA] = "ima",
561b12b7227SRichard Henderson     [CPU_FEATURE_BIT_VIS4] = "vis4",
562554abe47SRichard Henderson #else
563554abe47SRichard Henderson     [CPU_FEATURE_BIT_MUL] = "mul",
564554abe47SRichard Henderson     [CPU_FEATURE_BIT_DIV] = "div",
565554abe47SRichard Henderson     [CPU_FEATURE_BIT_FSMULD] = "fsmuld",
566554abe47SRichard Henderson #endif
567ab3b491fSBlue Swirl };
568ab3b491fSBlue Swirl 
5690442428aSMarkus Armbruster static void print_features(uint32_t features, const char *prefix)
570ab3b491fSBlue Swirl {
571ab3b491fSBlue Swirl     unsigned int i;
572ab3b491fSBlue Swirl 
573ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
574ab3b491fSBlue Swirl         if (feature_name[i] && (features & (1 << i))) {
575ab3b491fSBlue Swirl             if (prefix) {
5760442428aSMarkus Armbruster                 qemu_printf("%s", prefix);
577ab3b491fSBlue Swirl             }
5780442428aSMarkus Armbruster             qemu_printf("%s ", feature_name[i]);
579ab3b491fSBlue Swirl         }
580ab3b491fSBlue Swirl     }
581ab3b491fSBlue Swirl }
582ab3b491fSBlue Swirl 
5830442428aSMarkus Armbruster void sparc_cpu_list(void)
584ab3b491fSBlue Swirl {
585ab3b491fSBlue Swirl     unsigned int i;
586ab3b491fSBlue Swirl 
58747833f81SThomas Huth     qemu_printf("Available CPU types:\n");
588ab3b491fSBlue Swirl     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
58947833f81SThomas Huth         qemu_printf(" %-20s (IU " TARGET_FMT_lx
59047833f81SThomas Huth                     " FPU %08x MMU %08x NWINS %d) ",
591ab3b491fSBlue Swirl                     sparc_defs[i].name,
592ab3b491fSBlue Swirl                     sparc_defs[i].iu_version,
593ab3b491fSBlue Swirl                     sparc_defs[i].fpu_version,
594ab3b491fSBlue Swirl                     sparc_defs[i].mmu_version,
595ab3b491fSBlue Swirl                     sparc_defs[i].nwindows);
5960442428aSMarkus Armbruster         print_features(CPU_DEFAULT_FEATURES & ~sparc_defs[i].features, "-");
5970442428aSMarkus Armbruster         print_features(~CPU_DEFAULT_FEATURES & sparc_defs[i].features, "+");
5980442428aSMarkus Armbruster         qemu_printf("\n");
599ab3b491fSBlue Swirl     }
6000442428aSMarkus Armbruster     qemu_printf("Default CPU feature flags (use '-' to remove): ");
6010442428aSMarkus Armbruster     print_features(CPU_DEFAULT_FEATURES, NULL);
6020442428aSMarkus Armbruster     qemu_printf("\n");
6030442428aSMarkus Armbruster     qemu_printf("Available CPU feature flags (use '+' to add): ");
6040442428aSMarkus Armbruster     print_features(~CPU_DEFAULT_FEATURES, NULL);
6050442428aSMarkus Armbruster     qemu_printf("\n");
6060442428aSMarkus Armbruster     qemu_printf("Numerical features (use '=' to set): iu_version "
607ab3b491fSBlue Swirl                 "fpu_version mmu_version nwindows\n");
608ab3b491fSBlue Swirl }
609ab3b491fSBlue Swirl 
61090c84c56SMarkus Armbruster static void cpu_print_cc(FILE *f, uint32_t cc)
611ab3b491fSBlue Swirl {
61290c84c56SMarkus Armbruster     qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
613ab3b491fSBlue Swirl                  cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
614ab3b491fSBlue Swirl                  cc & PSR_CARRY ? 'C' : '-');
615ab3b491fSBlue Swirl }
616ab3b491fSBlue Swirl 
617ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
618ab3b491fSBlue Swirl #define REGS_PER_LINE 4
619ab3b491fSBlue Swirl #else
620ab3b491fSBlue Swirl #define REGS_PER_LINE 8
621ab3b491fSBlue Swirl #endif
622ab3b491fSBlue Swirl 
6239ac200acSPhilippe Mathieu-Daudé static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
624ab3b491fSBlue Swirl {
62577976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
626ab3b491fSBlue Swirl     int i, x;
627ab3b491fSBlue Swirl 
62890c84c56SMarkus Armbruster     qemu_fprintf(f, "pc: " TARGET_FMT_lx "  npc: " TARGET_FMT_lx "\n", env->pc,
629ab3b491fSBlue Swirl                  env->npc);
630ab3b491fSBlue Swirl 
631ab3b491fSBlue Swirl     for (i = 0; i < 8; i++) {
632ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == 0) {
63390c84c56SMarkus Armbruster             qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
634ab3b491fSBlue Swirl         }
63590c84c56SMarkus Armbruster         qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
636ab3b491fSBlue Swirl         if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
63790c84c56SMarkus Armbruster             qemu_fprintf(f, "\n");
638ab3b491fSBlue Swirl         }
639ab3b491fSBlue Swirl     }
640ab3b491fSBlue Swirl     for (x = 0; x < 3; x++) {
641ab3b491fSBlue Swirl         for (i = 0; i < 8; i++) {
642ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == 0) {
64390c84c56SMarkus Armbruster                 qemu_fprintf(f, "%%%c%d-%d: ",
644ab3b491fSBlue Swirl                              x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
645ab3b491fSBlue Swirl                              i, i + REGS_PER_LINE - 1);
646ab3b491fSBlue Swirl             }
64790c84c56SMarkus Armbruster             qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
648ab3b491fSBlue Swirl             if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
64990c84c56SMarkus Armbruster                 qemu_fprintf(f, "\n");
650ab3b491fSBlue Swirl             }
651ab3b491fSBlue Swirl         }
652ab3b491fSBlue Swirl     }
65376a23ca0SRichard Henderson 
654d13c394cSRichard Henderson     if (flags & CPU_DUMP_FPU) {
65530038fd8SRichard Henderson         for (i = 0; i < TARGET_DPREGS; i++) {
656ab3b491fSBlue Swirl             if ((i & 3) == 0) {
65790c84c56SMarkus Armbruster                 qemu_fprintf(f, "%%f%02d: ", i * 2);
658ab3b491fSBlue Swirl             }
65990c84c56SMarkus Armbruster             qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
660ab3b491fSBlue Swirl             if ((i & 3) == 3) {
66190c84c56SMarkus Armbruster                 qemu_fprintf(f, "\n");
662ab3b491fSBlue Swirl             }
663ab3b491fSBlue Swirl         }
664d13c394cSRichard Henderson     }
665d13c394cSRichard Henderson 
666ab3b491fSBlue Swirl #ifdef TARGET_SPARC64
66790c84c56SMarkus Armbruster     qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
668ab3b491fSBlue Swirl                  (unsigned)cpu_get_ccr(env));
66990c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
67090c84c56SMarkus Armbruster     qemu_fprintf(f, " xcc: ");
67190c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
67290c84c56SMarkus Armbruster     qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
673cbc3a6a4SArtyom Tarasenko                  env->psrpil, env->gl);
67490c84c56SMarkus Armbruster     qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
675cbc3a6a4SArtyom Tarasenko                  TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
67690c84c56SMarkus Armbruster     qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
677ab3b491fSBlue Swirl                  "cleanwin: %d cwp: %d\n",
678ab3b491fSBlue Swirl                  env->cansave, env->canrestore, env->otherwin, env->wstate,
679ab3b491fSBlue Swirl                  env->cleanwin, env->nwindows - 1 - env->cwp);
680ca4d5d86SPeter Maydell     qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: %016x\n",
6811ccd6e13SRichard Henderson                  cpu_get_fsr(env), env->y, env->fprs);
682cbc3a6a4SArtyom Tarasenko 
683ab3b491fSBlue Swirl #else
68490c84c56SMarkus Armbruster     qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
68590c84c56SMarkus Armbruster     cpu_print_cc(f, cpu_get_psr(env));
68690c84c56SMarkus Armbruster     qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
687ab3b491fSBlue Swirl                  env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
688ab3b491fSBlue Swirl                  env->wim);
68990c84c56SMarkus Armbruster     qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
6901ccd6e13SRichard Henderson                  cpu_get_fsr(env), env->y);
691ab3b491fSBlue Swirl #endif
69290c84c56SMarkus Armbruster     qemu_fprintf(f, "\n");
693ab3b491fSBlue Swirl }
694ab7ab3d7SAndreas Färber 
695f45748f1SAndreas Färber static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
696f45748f1SAndreas Färber {
697f45748f1SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
698f45748f1SAndreas Färber 
699f45748f1SAndreas Färber     cpu->env.pc = value;
700f45748f1SAndreas Färber     cpu->env.npc = value + 4;
701f45748f1SAndreas Färber }
702f45748f1SAndreas Färber 
703e4fdf9dfSRichard Henderson static vaddr sparc_cpu_get_pc(CPUState *cs)
704e4fdf9dfSRichard Henderson {
705e4fdf9dfSRichard Henderson     SPARCCPU *cpu = SPARC_CPU(cs);
706e4fdf9dfSRichard Henderson 
707e4fdf9dfSRichard Henderson     return cpu->env.pc;
708e4fdf9dfSRichard Henderson }
709e4fdf9dfSRichard Henderson 
71004a37d4cSRichard Henderson static void sparc_cpu_synchronize_from_tb(CPUState *cs,
71104a37d4cSRichard Henderson                                           const TranslationBlock *tb)
712bdf7ae5bSAndreas Färber {
713bdf7ae5bSAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
714bdf7ae5bSAndreas Färber 
715b254c342SPhilippe Mathieu-Daudé     tcg_debug_assert(!tcg_cflags_has(cs, CF_PCREL));
716c4bf3a92SAnton Johansson     cpu->env.pc = tb->pc;
717bdf7ae5bSAndreas Färber     cpu->env.npc = tb->cs_base;
718bdf7ae5bSAndreas Färber }
719bdf7ae5bSAndreas Färber 
72032cf0ac2SAnton Johansson void cpu_get_tb_cpu_state(CPUSPARCState *env, vaddr *pc,
72132cf0ac2SAnton Johansson                           uint64_t *cs_base, uint32_t *pflags)
72232cf0ac2SAnton Johansson {
72332cf0ac2SAnton Johansson     uint32_t flags;
72432cf0ac2SAnton Johansson     *pc = env->pc;
72532cf0ac2SAnton Johansson     *cs_base = env->npc;
72632cf0ac2SAnton Johansson     flags = cpu_mmu_index(env_cpu(env), false);
72732cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
72832cf0ac2SAnton Johansson     if (cpu_supervisor_mode(env)) {
72932cf0ac2SAnton Johansson         flags |= TB_FLAG_SUPER;
73032cf0ac2SAnton Johansson     }
73132cf0ac2SAnton Johansson #endif
73232cf0ac2SAnton Johansson #ifdef TARGET_SPARC64
73332cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
73432cf0ac2SAnton Johansson     if (cpu_hypervisor_mode(env)) {
73532cf0ac2SAnton Johansson         flags |= TB_FLAG_HYPER;
73632cf0ac2SAnton Johansson     }
73732cf0ac2SAnton Johansson #endif
73832cf0ac2SAnton Johansson     if (env->pstate & PS_AM) {
73932cf0ac2SAnton Johansson         flags |= TB_FLAG_AM_ENABLED;
74032cf0ac2SAnton Johansson     }
74132cf0ac2SAnton Johansson     if ((env->pstate & PS_PEF) && (env->fprs & FPRS_FEF)) {
74232cf0ac2SAnton Johansson         flags |= TB_FLAG_FPU_ENABLED;
74332cf0ac2SAnton Johansson     }
74432cf0ac2SAnton Johansson     flags |= env->asi << TB_FLAG_ASI_SHIFT;
74532cf0ac2SAnton Johansson #else
74632cf0ac2SAnton Johansson     if (env->psref) {
74732cf0ac2SAnton Johansson         flags |= TB_FLAG_FPU_ENABLED;
74832cf0ac2SAnton Johansson     }
74932cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
75032cf0ac2SAnton Johansson     if (env->fsr_qne) {
75132cf0ac2SAnton Johansson         flags |= TB_FLAG_FSR_QNE;
75232cf0ac2SAnton Johansson     }
75332cf0ac2SAnton Johansson #endif /* !CONFIG_USER_ONLY */
75432cf0ac2SAnton Johansson #endif /* TARGET_SPARC64 */
75532cf0ac2SAnton Johansson     *pflags = flags;
75632cf0ac2SAnton Johansson }
75732cf0ac2SAnton Johansson 
758fc3630b2SPhilippe Mathieu-Daudé static void sparc_restore_state_to_opc(CPUState *cs,
759fc3630b2SPhilippe Mathieu-Daudé                                        const TranslationBlock *tb,
760fc3630b2SPhilippe Mathieu-Daudé                                        const uint64_t *data)
761fc3630b2SPhilippe Mathieu-Daudé {
762fc3630b2SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
763fc3630b2SPhilippe Mathieu-Daudé     target_ulong pc = data[0];
764fc3630b2SPhilippe Mathieu-Daudé     target_ulong npc = data[1];
765fc3630b2SPhilippe Mathieu-Daudé 
766fc3630b2SPhilippe Mathieu-Daudé     env->pc = pc;
767fc3630b2SPhilippe Mathieu-Daudé     if (npc == DYNAMIC_PC) {
768fc3630b2SPhilippe Mathieu-Daudé         /* dynamic NPC: already stored */
769fc3630b2SPhilippe Mathieu-Daudé     } else if (npc & JUMP_PC) {
770fc3630b2SPhilippe Mathieu-Daudé         /* jump PC: use 'cond' and the jump targets of the translation */
771fc3630b2SPhilippe Mathieu-Daudé         if (env->cond) {
772fc3630b2SPhilippe Mathieu-Daudé             env->npc = npc & ~3;
773fc3630b2SPhilippe Mathieu-Daudé         } else {
774fc3630b2SPhilippe Mathieu-Daudé             env->npc = pc + 4;
775fc3630b2SPhilippe Mathieu-Daudé         }
776fc3630b2SPhilippe Mathieu-Daudé     } else {
777fc3630b2SPhilippe Mathieu-Daudé         env->npc = npc;
778fc3630b2SPhilippe Mathieu-Daudé     }
779fc3630b2SPhilippe Mathieu-Daudé }
780fc3630b2SPhilippe Mathieu-Daudé 
78182f0f44dSPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
7828c2e1b00SAndreas Färber static bool sparc_cpu_has_work(CPUState *cs)
7838c2e1b00SAndreas Färber {
7848c2e1b00SAndreas Färber     return (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
78577976769SPhilippe Mathieu-Daudé            cpu_interrupts_enabled(cpu_env(cs));
7868c2e1b00SAndreas Färber }
78782f0f44dSPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
7888c2e1b00SAndreas Färber 
789a120d320SRichard Henderson static int sparc_cpu_mmu_index(CPUState *cs, bool ifetch)
790e3547a7dSRichard Henderson {
791e3547a7dSRichard Henderson     CPUSPARCState *env = cpu_env(cs);
792e3547a7dSRichard Henderson 
793e3547a7dSRichard Henderson #ifndef TARGET_SPARC64
794e3547a7dSRichard Henderson     if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
795e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
796e3547a7dSRichard Henderson     } else {
797e3547a7dSRichard Henderson         return env->psrs;
798e3547a7dSRichard Henderson     }
799e3547a7dSRichard Henderson #else
800e3547a7dSRichard Henderson     /* IMMU or DMMU disabled.  */
801e3547a7dSRichard Henderson     if (ifetch
802e3547a7dSRichard Henderson         ? (env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0
803e3547a7dSRichard Henderson         : (env->lsu & DMMU_E) == 0) {
804e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
805e3547a7dSRichard Henderson     } else if (cpu_hypervisor_mode(env)) {
806e3547a7dSRichard Henderson         return MMU_PHYS_IDX;
807e3547a7dSRichard Henderson     } else if (env->tl > 0) {
808e3547a7dSRichard Henderson         return MMU_NUCLEUS_IDX;
809e3547a7dSRichard Henderson     } else if (cpu_supervisor_mode(env)) {
810e3547a7dSRichard Henderson         return MMU_KERNEL_IDX;
811e3547a7dSRichard Henderson     } else {
812e3547a7dSRichard Henderson         return MMU_USER_IDX;
813e3547a7dSRichard Henderson     }
814e3547a7dSRichard Henderson #endif
815e3547a7dSRichard Henderson }
816e3547a7dSRichard Henderson 
81712a6c15eSIgor Mammedov static char *sparc_cpu_type_name(const char *cpu_model)
81812a6c15eSIgor Mammedov {
8191d4bfc54SIgor Mammedov     char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model);
82012a6c15eSIgor Mammedov     char *s = name;
82112a6c15eSIgor Mammedov 
82212a6c15eSIgor Mammedov     /* SPARC cpu model names happen to have whitespaces,
82312a6c15eSIgor Mammedov      * as type names shouldn't have spaces replace them with '-'
82412a6c15eSIgor Mammedov      */
82512a6c15eSIgor Mammedov     while ((s = strchr(s, ' '))) {
82612a6c15eSIgor Mammedov         *s = '-';
82712a6c15eSIgor Mammedov     }
82812a6c15eSIgor Mammedov 
82912a6c15eSIgor Mammedov     return name;
83012a6c15eSIgor Mammedov }
83112a6c15eSIgor Mammedov 
83212a6c15eSIgor Mammedov static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model)
83312a6c15eSIgor Mammedov {
83412a6c15eSIgor Mammedov     ObjectClass *oc;
83512a6c15eSIgor Mammedov     char *typename;
83612a6c15eSIgor Mammedov 
83712a6c15eSIgor Mammedov     typename = sparc_cpu_type_name(cpu_model);
8386b568e3fSThomas Huth 
8396b568e3fSThomas Huth     /* Fix up legacy names with '+' in it */
8406b568e3fSThomas Huth     if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV+"))) {
8416b568e3fSThomas Huth         g_free(typename);
8426b568e3fSThomas Huth         typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV-plus"));
8436b568e3fSThomas Huth     } else if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi+"))) {
8446b568e3fSThomas Huth         g_free(typename);
8456b568e3fSThomas Huth         typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi-plus"));
8466b568e3fSThomas Huth     }
8476b568e3fSThomas Huth 
84812a6c15eSIgor Mammedov     oc = object_class_by_name(typename);
84912a6c15eSIgor Mammedov     g_free(typename);
85012a6c15eSIgor Mammedov     return oc;
85112a6c15eSIgor Mammedov }
85212a6c15eSIgor Mammedov 
853b6e91ebfSAndreas Färber static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
854b6e91ebfSAndreas Färber {
855ce5b1bbfSLaurent Vivier     CPUState *cs = CPU(dev);
856b6e91ebfSAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
857ce5b1bbfSLaurent Vivier     Error *local_err = NULL;
85877976769SPhilippe Mathieu-Daudé     CPUSPARCState *env = cpu_env(cs);
859247bf011SAndreas Färber 
86070054962SIgor Mammedov #if defined(CONFIG_USER_ONLY)
8615f25b383SRichard Henderson     /* We are emulating the kernel, which will trap and emulate float128. */
862576e1c4cSIgor Mammedov     env->def.features |= CPU_FEATURE_FLOAT128;
863247bf011SAndreas Färber #endif
864b6e91ebfSAndreas Färber 
86570054962SIgor Mammedov     env->version = env->def.iu_version;
86670054962SIgor Mammedov     env->nwindows = env->def.nwindows;
86770054962SIgor Mammedov #if !defined(TARGET_SPARC64)
86870054962SIgor Mammedov     env->mmuregs[0] |= env->def.mmu_version;
86970054962SIgor Mammedov     cpu_sparc_set_id(env, 0);
87070054962SIgor Mammedov     env->mxccregs[7] |= env->def.mxcc_version;
87170054962SIgor Mammedov #else
87270054962SIgor Mammedov     env->mmu_version = env->def.mmu_version;
87370054962SIgor Mammedov     env->maxtl = env->def.maxtl;
87470054962SIgor Mammedov     env->version |= env->def.maxtl << 8;
87570054962SIgor Mammedov     env->version |= env->def.nwindows - 1;
87670054962SIgor Mammedov #endif
87770054962SIgor Mammedov 
8784482f32dSPeter Maydell     /*
8794482f32dSPeter Maydell      * Prefer SNaN over QNaN, order B then A. It's OK to do this in realize
8804482f32dSPeter Maydell      * rather than reset, because fp_status is after 'end_reset_fields' in
8814482f32dSPeter Maydell      * the CPU state struct so it won't get zeroed on reset.
8824482f32dSPeter Maydell      */
8834482f32dSPeter Maydell     set_float_2nan_prop_rule(float_2nan_prop_s_ba, &env->fp_status);
88449866dcbSPeter Maydell     /* For fused-multiply add, prefer SNaN over QNaN, then C->B->A */
88549866dcbSPeter Maydell     set_float_3nan_prop_rule(float_3nan_prop_s_cba, &env->fp_status);
8869a31b8d0SPeter Maydell     /* For inf * 0 + NaN, return the input NaN */
8879a31b8d0SPeter Maydell     set_float_infzeronan_rule(float_infzeronan_dnan_never, &env->fp_status);
88845fb2cd6SPeter Maydell     /* Default NaN value: sign bit clear, all frac bits set */
88945fb2cd6SPeter Maydell     set_float_default_nan_pattern(0b01111111, &env->fp_status);
8904482f32dSPeter Maydell 
891ce5b1bbfSLaurent Vivier     cpu_exec_realizefn(cs, &local_err);
892ce5b1bbfSLaurent Vivier     if (local_err != NULL) {
893ce5b1bbfSLaurent Vivier         error_propagate(errp, local_err);
894ce5b1bbfSLaurent Vivier         return;
895ce5b1bbfSLaurent Vivier     }
896ce5b1bbfSLaurent Vivier 
897ce5b1bbfSLaurent Vivier     qemu_init_vcpu(cs);
89814a10fc3SAndreas Färber 
899b6e91ebfSAndreas Färber     scc->parent_realize(dev, errp);
900b6e91ebfSAndreas Färber }
901b6e91ebfSAndreas Färber 
902ab7ab3d7SAndreas Färber static void sparc_cpu_initfn(Object *obj)
903ab7ab3d7SAndreas Färber {
904ab7ab3d7SAndreas Färber     SPARCCPU *cpu = SPARC_CPU(obj);
90512a6c15eSIgor Mammedov     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
906ab7ab3d7SAndreas Färber     CPUSPARCState *env = &cpu->env;
907ab7ab3d7SAndreas Färber 
908576e1c4cSIgor Mammedov     if (scc->cpu_def) {
909576e1c4cSIgor Mammedov         env->def = *scc->cpu_def;
910ab7ab3d7SAndreas Färber     }
911ab7ab3d7SAndreas Färber }
912ab7ab3d7SAndreas Färber 
913de05005bSIgor Mammedov static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
914de05005bSIgor Mammedov                                void *opaque, Error **errp)
915de05005bSIgor Mammedov {
916de05005bSIgor Mammedov     SPARCCPU *cpu = SPARC_CPU(obj);
917de05005bSIgor Mammedov     int64_t value = cpu->env.def.nwindows;
918de05005bSIgor Mammedov 
919de05005bSIgor Mammedov     visit_type_int(v, name, &value, errp);
920de05005bSIgor Mammedov }
921de05005bSIgor Mammedov 
922de05005bSIgor Mammedov static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
923de05005bSIgor Mammedov                                void *opaque, Error **errp)
924de05005bSIgor Mammedov {
925de05005bSIgor Mammedov     const int64_t min = MIN_NWINDOWS;
926de05005bSIgor Mammedov     const int64_t max = MAX_NWINDOWS;
927de05005bSIgor Mammedov     SPARCCPU *cpu = SPARC_CPU(obj);
928de05005bSIgor Mammedov     int64_t value;
929de05005bSIgor Mammedov 
930668f62ecSMarkus Armbruster     if (!visit_type_int(v, name, &value, errp)) {
931de05005bSIgor Mammedov         return;
932de05005bSIgor Mammedov     }
933de05005bSIgor Mammedov 
934de05005bSIgor Mammedov     if (value < min || value > max) {
935de05005bSIgor Mammedov         error_setg(errp, "Property %s.%s doesn't take value %" PRId64
936de05005bSIgor Mammedov                    " (minimum: %" PRId64 ", maximum: %" PRId64 ")",
937de05005bSIgor Mammedov                    object_get_typename(obj), name ? name : "null",
938de05005bSIgor Mammedov                    value, min, max);
939de05005bSIgor Mammedov         return;
940de05005bSIgor Mammedov     }
941de05005bSIgor Mammedov     cpu->env.def.nwindows = value;
942de05005bSIgor Mammedov }
943de05005bSIgor Mammedov 
9443834cc6fSRichard Henderson static const PropertyInfo qdev_prop_nwindows = {
945c98dac16SMarkus Armbruster     .type  = "int",
94645e5b493SMarkus Armbruster     .description = "Number of register windows",
947de05005bSIgor Mammedov     .get   = sparc_get_nwindows,
948de05005bSIgor Mammedov     .set   = sparc_set_nwindows,
949de05005bSIgor Mammedov };
950de05005bSIgor Mammedov 
951de1f5203SRichard Henderson /* This must match feature_name[]. */
9523834cc6fSRichard Henderson static const Property sparc_cpu_properties[] = {
953de1f5203SRichard Henderson     DEFINE_PROP_BIT("float128", SPARCCPU, env.def.features,
954de1f5203SRichard Henderson                     CPU_FEATURE_BIT_FLOAT128, false),
955554abe47SRichard Henderson #ifdef TARGET_SPARC64
956de1f5203SRichard Henderson     DEFINE_PROP_BIT("cmt",      SPARCCPU, env.def.features,
957de1f5203SRichard Henderson                     CPU_FEATURE_BIT_CMT, false),
958de1f5203SRichard Henderson     DEFINE_PROP_BIT("gl",       SPARCCPU, env.def.features,
959de1f5203SRichard Henderson                     CPU_FEATURE_BIT_GL, false),
960554abe47SRichard Henderson     DEFINE_PROP_BIT("hypv",     SPARCCPU, env.def.features,
961554abe47SRichard Henderson                     CPU_FEATURE_BIT_HYPV, false),
962554abe47SRichard Henderson     DEFINE_PROP_BIT("vis1",     SPARCCPU, env.def.features,
963554abe47SRichard Henderson                     CPU_FEATURE_BIT_VIS1, false),
964554abe47SRichard Henderson     DEFINE_PROP_BIT("vis2",     SPARCCPU, env.def.features,
965554abe47SRichard Henderson                     CPU_FEATURE_BIT_VIS2, false),
9664fd71d19SRichard Henderson     DEFINE_PROP_BIT("fmaf",     SPARCCPU, env.def.features,
9674fd71d19SRichard Henderson                     CPU_FEATURE_BIT_FMAF, false),
968deadbb14SRichard Henderson     DEFINE_PROP_BIT("vis3",     SPARCCPU, env.def.features,
969deadbb14SRichard Henderson                     CPU_FEATURE_BIT_VIS3, false),
97068a414e9SRichard Henderson     DEFINE_PROP_BIT("ima",      SPARCCPU, env.def.features,
97168a414e9SRichard Henderson                     CPU_FEATURE_BIT_IMA, false),
972b12b7227SRichard Henderson     DEFINE_PROP_BIT("vis4",     SPARCCPU, env.def.features,
973b12b7227SRichard Henderson                     CPU_FEATURE_BIT_VIS4, false),
974554abe47SRichard Henderson #else
975554abe47SRichard Henderson     DEFINE_PROP_BIT("mul",      SPARCCPU, env.def.features,
976554abe47SRichard Henderson                     CPU_FEATURE_BIT_MUL, false),
977554abe47SRichard Henderson     DEFINE_PROP_BIT("div",      SPARCCPU, env.def.features,
978554abe47SRichard Henderson                     CPU_FEATURE_BIT_DIV, false),
979554abe47SRichard Henderson     DEFINE_PROP_BIT("fsmuld",   SPARCCPU, env.def.features,
980554abe47SRichard Henderson                     CPU_FEATURE_BIT_FSMULD, false),
981554abe47SRichard Henderson #endif
982de05005bSIgor Mammedov     DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU, env.def.iu_version, 0,
983de05005bSIgor Mammedov                          qdev_prop_uint64, target_ulong),
984de05005bSIgor Mammedov     DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0),
985de05005bSIgor Mammedov     DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0),
98643b6ab4cSEduardo Habkost     DEFINE_PROP("nwindows", SPARCCPU, env.def.nwindows,
98743b6ab4cSEduardo Habkost                 qdev_prop_nwindows, uint32_t),
988de05005bSIgor Mammedov };
989de05005bSIgor Mammedov 
9908b80bd28SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
9918b80bd28SPhilippe Mathieu-Daudé #include "hw/core/sysemu-cpu-ops.h"
9928b80bd28SPhilippe Mathieu-Daudé 
9938b80bd28SPhilippe Mathieu-Daudé static const struct SysemuCPUOps sparc_sysemu_ops = {
99482f0f44dSPhilippe Mathieu-Daudé     .has_work = sparc_cpu_has_work,
99508928c6dSPhilippe Mathieu-Daudé     .get_phys_page_debug = sparc_cpu_get_phys_page_debug,
996feece4d0SPhilippe Mathieu-Daudé     .legacy_vmsd = &vmstate_sparc_cpu,
9978b80bd28SPhilippe Mathieu-Daudé };
9988b80bd28SPhilippe Mathieu-Daudé #endif
9998b80bd28SPhilippe Mathieu-Daudé 
100078271684SClaudio Fontana #ifdef CONFIG_TCG
100115017436SPhilippe Mathieu-Daudé #include "accel/tcg/cpu-ops.h"
100278271684SClaudio Fontana 
10031764ad70SRichard Henderson static const TCGCPUOps sparc_tcg_ops = {
1004*04583ce7SPhilippe Mathieu-Daudé     .guest_default_memory_order = TCG_GUEST_DEFAULT_MO,
1005*04583ce7SPhilippe Mathieu-Daudé 
100678271684SClaudio Fontana     .initialize = sparc_tcg_init,
1007e4a8e093SRichard Henderson     .translate_code = sparc_translate_code,
100878271684SClaudio Fontana     .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
1009f36aaa53SRichard Henderson     .restore_state_to_opc = sparc_restore_state_to_opc,
1010f34769a5SPhilippe Mathieu-Daudé     .mmu_index = sparc_cpu_mmu_index,
101178271684SClaudio Fontana 
101278271684SClaudio Fontana #ifndef CONFIG_USER_ONLY
1013caac44a5SRichard Henderson     .tlb_fill = sparc_cpu_tlb_fill,
1014798ac8b5SPhilippe Mathieu-Daudé     .cpu_exec_interrupt = sparc_cpu_exec_interrupt,
10154f7b1ecbSPeter Maydell     .cpu_exec_halt = sparc_cpu_has_work,
101678271684SClaudio Fontana     .do_interrupt = sparc_cpu_do_interrupt,
101778271684SClaudio Fontana     .do_transaction_failed = sparc_cpu_do_transaction_failed,
101878271684SClaudio Fontana     .do_unaligned_access = sparc_cpu_do_unaligned_access,
101978271684SClaudio Fontana #endif /* !CONFIG_USER_ONLY */
102078271684SClaudio Fontana };
102178271684SClaudio Fontana #endif /* CONFIG_TCG */
102278271684SClaudio Fontana 
1023ab7ab3d7SAndreas Färber static void sparc_cpu_class_init(ObjectClass *oc, void *data)
1024ab7ab3d7SAndreas Färber {
1025ab7ab3d7SAndreas Färber     SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
1026ab7ab3d7SAndreas Färber     CPUClass *cc = CPU_CLASS(oc);
1027b6e91ebfSAndreas Färber     DeviceClass *dc = DEVICE_CLASS(oc);
10283b4fff1bSPeter Maydell     ResettableClass *rc = RESETTABLE_CLASS(oc);
1029b6e91ebfSAndreas Färber 
1030bf853881SPhilippe Mathieu-Daudé     device_class_set_parent_realize(dc, sparc_cpu_realizefn,
1031bf853881SPhilippe Mathieu-Daudé                                     &scc->parent_realize);
10324f67d30bSMarc-André Lureau     device_class_set_props(dc, sparc_cpu_properties);
1033ab7ab3d7SAndreas Färber 
10343b4fff1bSPeter Maydell     resettable_class_set_parent_phases(rc, NULL, sparc_cpu_reset_hold, NULL,
10353b4fff1bSPeter Maydell                                        &scc->parent_phases);
103697a8ea5aSAndreas Färber 
103712a6c15eSIgor Mammedov     cc->class_by_name = sparc_cpu_class_by_name;
1038d1853231SIgor Mammedov     cc->parse_features = sparc_cpu_parse_features;
1039878096eeSAndreas Färber     cc->dump_state = sparc_cpu_dump_state;
1040f3659eeeSAndreas Färber #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
1041f3659eeeSAndreas Färber     cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
1042f3659eeeSAndreas Färber #endif
1043f45748f1SAndreas Färber     cc->set_pc = sparc_cpu_set_pc;
1044e4fdf9dfSRichard Henderson     cc->get_pc = sparc_cpu_get_pc;
10455b50e790SAndreas Färber     cc->gdb_read_register = sparc_cpu_gdb_read_register;
10465b50e790SAndreas Färber     cc->gdb_write_register = sparc_cpu_gdb_write_register;
1047e84942f2SRichard Henderson #ifndef CONFIG_USER_ONLY
10488b80bd28SPhilippe Mathieu-Daudé     cc->sysemu_ops = &sparc_sysemu_ops;
104900b941e5SAndreas Färber #endif
1050df0900ebSPeter Crosthwaite     cc->disas_set_info = cpu_sparc_disas_set_info;
1051a0e372f0SAndreas Färber 
1052a0e372f0SAndreas Färber #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1053a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 86;
1054a0e372f0SAndreas Färber #else
1055a0e372f0SAndreas Färber     cc->gdb_num_core_regs = 72;
1056a0e372f0SAndreas Färber #endif
105778271684SClaudio Fontana     cc->tcg_ops = &sparc_tcg_ops;
1058ab7ab3d7SAndreas Färber }
1059ab7ab3d7SAndreas Färber 
1060ab7ab3d7SAndreas Färber static const TypeInfo sparc_cpu_type_info = {
1061ab7ab3d7SAndreas Färber     .name = TYPE_SPARC_CPU,
1062ab7ab3d7SAndreas Färber     .parent = TYPE_CPU,
1063ab7ab3d7SAndreas Färber     .instance_size = sizeof(SPARCCPU),
1064f669c992SRichard Henderson     .instance_align = __alignof(SPARCCPU),
1065ab7ab3d7SAndreas Färber     .instance_init = sparc_cpu_initfn,
106612a6c15eSIgor Mammedov     .abstract = true,
1067ab7ab3d7SAndreas Färber     .class_size = sizeof(SPARCCPUClass),
1068ab7ab3d7SAndreas Färber     .class_init = sparc_cpu_class_init,
1069ab7ab3d7SAndreas Färber };
1070ab7ab3d7SAndreas Färber 
107112a6c15eSIgor Mammedov static void sparc_cpu_cpudef_class_init(ObjectClass *oc, void *data)
107212a6c15eSIgor Mammedov {
107312a6c15eSIgor Mammedov     SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
107412a6c15eSIgor Mammedov     scc->cpu_def = data;
107512a6c15eSIgor Mammedov }
107612a6c15eSIgor Mammedov 
107712a6c15eSIgor Mammedov static void sparc_register_cpudef_type(const struct sparc_def_t *def)
107812a6c15eSIgor Mammedov {
107912a6c15eSIgor Mammedov     char *typename = sparc_cpu_type_name(def->name);
108012a6c15eSIgor Mammedov     TypeInfo ti = {
108112a6c15eSIgor Mammedov         .name = typename,
108212a6c15eSIgor Mammedov         .parent = TYPE_SPARC_CPU,
108312a6c15eSIgor Mammedov         .class_init = sparc_cpu_cpudef_class_init,
108412a6c15eSIgor Mammedov         .class_data = (void *)def,
108512a6c15eSIgor Mammedov     };
108612a6c15eSIgor Mammedov 
10872f02b71bSZhao Liu     type_register_static(&ti);
108812a6c15eSIgor Mammedov     g_free(typename);
108912a6c15eSIgor Mammedov }
109012a6c15eSIgor Mammedov 
1091ab7ab3d7SAndreas Färber static void sparc_cpu_register_types(void)
1092ab7ab3d7SAndreas Färber {
109312a6c15eSIgor Mammedov     int i;
109412a6c15eSIgor Mammedov 
1095ab7ab3d7SAndreas Färber     type_register_static(&sparc_cpu_type_info);
109612a6c15eSIgor Mammedov     for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
109712a6c15eSIgor Mammedov         sparc_register_cpudef_type(&sparc_defs[i]);
109812a6c15eSIgor Mammedov     }
1099ab7ab3d7SAndreas Färber }
1100ab7ab3d7SAndreas Färber 
1101ab7ab3d7SAndreas Färber type_init(sparc_cpu_register_types)
1102