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"
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
sparc_cpu_reset_hold(Object * obj,ResetType type)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
sparc_cpu_exec_interrupt(CPUState * cs,int interrupt_request)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
cpu_sparc_disas_set_info(CPUState * cpu,disassemble_info * info)106df0900ebSPeter Crosthwaite static void cpu_sparc_disas_set_info(CPUState *cpu, disassemble_info *info)
107df0900ebSPeter Crosthwaite {
108df0900ebSPeter Crosthwaite info->print_insn = print_insn_sparc;
1092136f7f1SPhilippe 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
cpu_add_feat_as_prop(const char * typename,const char * name,const char * val)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 */
sparc_cpu_parse_features(const char * typename,char * features,Error ** errp)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
cpu_sparc_set_id(CPUSPARCState * env,unsigned int cpu)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
print_features(uint32_t features,const char * prefix)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
sparc_cpu_list(void)5828b54467fSPhilippe Mathieu-Daudé static 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
cpu_print_cc(FILE * f,uint32_t cc)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
sparc_cpu_dump_state(CPUState * cs,FILE * f,int flags)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
sparc_cpu_set_pc(CPUState * cs,vaddr value)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
sparc_cpu_get_pc(CPUState * cs)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
sparc_cpu_synchronize_from_tb(CPUState * cs,const TranslationBlock * tb)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
sparc_get_tb_cpu_state(CPUState * cs)719c37f8978SRichard Henderson static TCGTBCPUState sparc_get_tb_cpu_state(CPUState *cs)
72032cf0ac2SAnton Johansson {
7214759aae4SRichard Henderson CPUSPARCState *env = cpu_env(cs);
7224759aae4SRichard Henderson uint32_t flags = cpu_mmu_index(cs, false);
7234759aae4SRichard Henderson
72432cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
72532cf0ac2SAnton Johansson if (cpu_supervisor_mode(env)) {
72632cf0ac2SAnton Johansson flags |= TB_FLAG_SUPER;
72732cf0ac2SAnton Johansson }
72832cf0ac2SAnton Johansson #endif
72932cf0ac2SAnton Johansson #ifdef TARGET_SPARC64
73032cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
73132cf0ac2SAnton Johansson if (cpu_hypervisor_mode(env)) {
73232cf0ac2SAnton Johansson flags |= TB_FLAG_HYPER;
73332cf0ac2SAnton Johansson }
73432cf0ac2SAnton Johansson #endif
73532cf0ac2SAnton Johansson if (env->pstate & PS_AM) {
73632cf0ac2SAnton Johansson flags |= TB_FLAG_AM_ENABLED;
73732cf0ac2SAnton Johansson }
73832cf0ac2SAnton Johansson if ((env->pstate & PS_PEF) && (env->fprs & FPRS_FEF)) {
73932cf0ac2SAnton Johansson flags |= TB_FLAG_FPU_ENABLED;
74032cf0ac2SAnton Johansson }
74132cf0ac2SAnton Johansson flags |= env->asi << TB_FLAG_ASI_SHIFT;
74232cf0ac2SAnton Johansson #else
74332cf0ac2SAnton Johansson if (env->psref) {
74432cf0ac2SAnton Johansson flags |= TB_FLAG_FPU_ENABLED;
74532cf0ac2SAnton Johansson }
74632cf0ac2SAnton Johansson #ifndef CONFIG_USER_ONLY
74732cf0ac2SAnton Johansson if (env->fsr_qne) {
74832cf0ac2SAnton Johansson flags |= TB_FLAG_FSR_QNE;
74932cf0ac2SAnton Johansson }
75032cf0ac2SAnton Johansson #endif /* !CONFIG_USER_ONLY */
75132cf0ac2SAnton Johansson #endif /* TARGET_SPARC64 */
7524759aae4SRichard Henderson
7534759aae4SRichard Henderson return (TCGTBCPUState){
7544759aae4SRichard Henderson .pc = env->pc,
7554759aae4SRichard Henderson .flags = flags,
7564759aae4SRichard Henderson .cs_base = env->npc,
7574759aae4SRichard Henderson };
75832cf0ac2SAnton Johansson }
75932cf0ac2SAnton Johansson
sparc_restore_state_to_opc(CPUState * cs,const TranslationBlock * tb,const uint64_t * data)760fc3630b2SPhilippe Mathieu-Daudé static void sparc_restore_state_to_opc(CPUState *cs,
761fc3630b2SPhilippe Mathieu-Daudé const TranslationBlock *tb,
762fc3630b2SPhilippe Mathieu-Daudé const uint64_t *data)
763fc3630b2SPhilippe Mathieu-Daudé {
764fc3630b2SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs);
765fc3630b2SPhilippe Mathieu-Daudé target_ulong pc = data[0];
766fc3630b2SPhilippe Mathieu-Daudé target_ulong npc = data[1];
767fc3630b2SPhilippe Mathieu-Daudé
768fc3630b2SPhilippe Mathieu-Daudé env->pc = pc;
769fc3630b2SPhilippe Mathieu-Daudé if (npc == DYNAMIC_PC) {
770fc3630b2SPhilippe Mathieu-Daudé /* dynamic NPC: already stored */
771fc3630b2SPhilippe Mathieu-Daudé } else if (npc & JUMP_PC) {
772fc3630b2SPhilippe Mathieu-Daudé /* jump PC: use 'cond' and the jump targets of the translation */
773fc3630b2SPhilippe Mathieu-Daudé if (env->cond) {
774fc3630b2SPhilippe Mathieu-Daudé env->npc = npc & ~3;
775fc3630b2SPhilippe Mathieu-Daudé } else {
776fc3630b2SPhilippe Mathieu-Daudé env->npc = pc + 4;
777fc3630b2SPhilippe Mathieu-Daudé }
778fc3630b2SPhilippe Mathieu-Daudé } else {
779fc3630b2SPhilippe Mathieu-Daudé env->npc = npc;
780fc3630b2SPhilippe Mathieu-Daudé }
781fc3630b2SPhilippe Mathieu-Daudé }
782fc3630b2SPhilippe Mathieu-Daudé
78382f0f44dSPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
sparc_cpu_has_work(CPUState * cs)7848c2e1b00SAndreas Färber static bool sparc_cpu_has_work(CPUState *cs)
7858c2e1b00SAndreas Färber {
7868c2e1b00SAndreas Färber return (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
78777976769SPhilippe Mathieu-Daudé cpu_interrupts_enabled(cpu_env(cs));
7888c2e1b00SAndreas Färber }
78982f0f44dSPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
7908c2e1b00SAndreas Färber
sparc_cpu_mmu_index(CPUState * cs,bool ifetch)791a120d320SRichard Henderson static int sparc_cpu_mmu_index(CPUState *cs, bool ifetch)
792e3547a7dSRichard Henderson {
793e3547a7dSRichard Henderson CPUSPARCState *env = cpu_env(cs);
794e3547a7dSRichard Henderson
795e3547a7dSRichard Henderson #ifndef TARGET_SPARC64
796e3547a7dSRichard Henderson if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
797e3547a7dSRichard Henderson return MMU_PHYS_IDX;
798e3547a7dSRichard Henderson } else {
799e3547a7dSRichard Henderson return env->psrs;
800e3547a7dSRichard Henderson }
801e3547a7dSRichard Henderson #else
802e3547a7dSRichard Henderson /* IMMU or DMMU disabled. */
803e3547a7dSRichard Henderson if (ifetch
804e3547a7dSRichard Henderson ? (env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0
805e3547a7dSRichard Henderson : (env->lsu & DMMU_E) == 0) {
806e3547a7dSRichard Henderson return MMU_PHYS_IDX;
807e3547a7dSRichard Henderson } else if (cpu_hypervisor_mode(env)) {
808e3547a7dSRichard Henderson return MMU_PHYS_IDX;
809e3547a7dSRichard Henderson } else if (env->tl > 0) {
810e3547a7dSRichard Henderson return MMU_NUCLEUS_IDX;
811e3547a7dSRichard Henderson } else if (cpu_supervisor_mode(env)) {
812e3547a7dSRichard Henderson return MMU_KERNEL_IDX;
813e3547a7dSRichard Henderson } else {
814e3547a7dSRichard Henderson return MMU_USER_IDX;
815e3547a7dSRichard Henderson }
816e3547a7dSRichard Henderson #endif
817e3547a7dSRichard Henderson }
818e3547a7dSRichard Henderson
sparc_cpu_type_name(const char * cpu_model)81912a6c15eSIgor Mammedov static char *sparc_cpu_type_name(const char *cpu_model)
82012a6c15eSIgor Mammedov {
8211d4bfc54SIgor Mammedov char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model);
82212a6c15eSIgor Mammedov char *s = name;
82312a6c15eSIgor Mammedov
82412a6c15eSIgor Mammedov /* SPARC cpu model names happen to have whitespaces,
82512a6c15eSIgor Mammedov * as type names shouldn't have spaces replace them with '-'
82612a6c15eSIgor Mammedov */
82712a6c15eSIgor Mammedov while ((s = strchr(s, ' '))) {
82812a6c15eSIgor Mammedov *s = '-';
82912a6c15eSIgor Mammedov }
83012a6c15eSIgor Mammedov
83112a6c15eSIgor Mammedov return name;
83212a6c15eSIgor Mammedov }
83312a6c15eSIgor Mammedov
sparc_cpu_class_by_name(const char * cpu_model)83412a6c15eSIgor Mammedov static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model)
83512a6c15eSIgor Mammedov {
83612a6c15eSIgor Mammedov ObjectClass *oc;
83712a6c15eSIgor Mammedov char *typename;
83812a6c15eSIgor Mammedov
83912a6c15eSIgor Mammedov typename = sparc_cpu_type_name(cpu_model);
8406b568e3fSThomas Huth
8416b568e3fSThomas Huth /* Fix up legacy names with '+' in it */
8426b568e3fSThomas Huth if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV+"))) {
8436b568e3fSThomas Huth g_free(typename);
8446b568e3fSThomas Huth typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV-plus"));
8456b568e3fSThomas Huth } else if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi+"))) {
8466b568e3fSThomas Huth g_free(typename);
8476b568e3fSThomas Huth typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi-plus"));
8486b568e3fSThomas Huth }
8496b568e3fSThomas Huth
85012a6c15eSIgor Mammedov oc = object_class_by_name(typename);
85112a6c15eSIgor Mammedov g_free(typename);
85212a6c15eSIgor Mammedov return oc;
85312a6c15eSIgor Mammedov }
85412a6c15eSIgor Mammedov
sparc_cpu_realizefn(DeviceState * dev,Error ** errp)855b6e91ebfSAndreas Färber static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
856b6e91ebfSAndreas Färber {
857ce5b1bbfSLaurent Vivier CPUState *cs = CPU(dev);
858b6e91ebfSAndreas Färber SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
859ce5b1bbfSLaurent Vivier Error *local_err = NULL;
86077976769SPhilippe Mathieu-Daudé CPUSPARCState *env = cpu_env(cs);
861247bf011SAndreas Färber
86270054962SIgor Mammedov #if defined(CONFIG_USER_ONLY)
8635f25b383SRichard Henderson /* We are emulating the kernel, which will trap and emulate float128. */
864576e1c4cSIgor Mammedov env->def.features |= CPU_FEATURE_FLOAT128;
865247bf011SAndreas Färber #endif
866b6e91ebfSAndreas Färber
86770054962SIgor Mammedov env->version = env->def.iu_version;
86870054962SIgor Mammedov env->nwindows = env->def.nwindows;
86970054962SIgor Mammedov #if !defined(TARGET_SPARC64)
87070054962SIgor Mammedov env->mmuregs[0] |= env->def.mmu_version;
87170054962SIgor Mammedov cpu_sparc_set_id(env, 0);
87270054962SIgor Mammedov env->mxccregs[7] |= env->def.mxcc_version;
87370054962SIgor Mammedov #else
87470054962SIgor Mammedov env->mmu_version = env->def.mmu_version;
87570054962SIgor Mammedov env->maxtl = env->def.maxtl;
87670054962SIgor Mammedov env->version |= env->def.maxtl << 8;
87770054962SIgor Mammedov env->version |= env->def.nwindows - 1;
87870054962SIgor Mammedov #endif
87970054962SIgor Mammedov
8804482f32dSPeter Maydell /*
8814482f32dSPeter Maydell * Prefer SNaN over QNaN, order B then A. It's OK to do this in realize
8824482f32dSPeter Maydell * rather than reset, because fp_status is after 'end_reset_fields' in
8834482f32dSPeter Maydell * the CPU state struct so it won't get zeroed on reset.
8844482f32dSPeter Maydell */
8854482f32dSPeter Maydell set_float_2nan_prop_rule(float_2nan_prop_s_ba, &env->fp_status);
88649866dcbSPeter Maydell /* For fused-multiply add, prefer SNaN over QNaN, then C->B->A */
88749866dcbSPeter Maydell set_float_3nan_prop_rule(float_3nan_prop_s_cba, &env->fp_status);
8889a31b8d0SPeter Maydell /* For inf * 0 + NaN, return the input NaN */
8899a31b8d0SPeter Maydell set_float_infzeronan_rule(float_infzeronan_dnan_never, &env->fp_status);
89045fb2cd6SPeter Maydell /* Default NaN value: sign bit clear, all frac bits set */
89145fb2cd6SPeter Maydell set_float_default_nan_pattern(0b01111111, &env->fp_status);
8924482f32dSPeter Maydell
893ce5b1bbfSLaurent Vivier cpu_exec_realizefn(cs, &local_err);
894ce5b1bbfSLaurent Vivier if (local_err != NULL) {
895ce5b1bbfSLaurent Vivier error_propagate(errp, local_err);
896ce5b1bbfSLaurent Vivier return;
897ce5b1bbfSLaurent Vivier }
898ce5b1bbfSLaurent Vivier
899ce5b1bbfSLaurent Vivier qemu_init_vcpu(cs);
90014a10fc3SAndreas Färber
901b6e91ebfSAndreas Färber scc->parent_realize(dev, errp);
902b6e91ebfSAndreas Färber }
903b6e91ebfSAndreas Färber
sparc_cpu_initfn(Object * obj)904ab7ab3d7SAndreas Färber static void sparc_cpu_initfn(Object *obj)
905ab7ab3d7SAndreas Färber {
906ab7ab3d7SAndreas Färber SPARCCPU *cpu = SPARC_CPU(obj);
90712a6c15eSIgor Mammedov SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
908ab7ab3d7SAndreas Färber CPUSPARCState *env = &cpu->env;
909ab7ab3d7SAndreas Färber
910576e1c4cSIgor Mammedov if (scc->cpu_def) {
911576e1c4cSIgor Mammedov env->def = *scc->cpu_def;
912ab7ab3d7SAndreas Färber }
913ab7ab3d7SAndreas Färber }
914ab7ab3d7SAndreas Färber
sparc_get_nwindows(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)915de05005bSIgor Mammedov static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
916de05005bSIgor Mammedov void *opaque, Error **errp)
917de05005bSIgor Mammedov {
918de05005bSIgor Mammedov SPARCCPU *cpu = SPARC_CPU(obj);
919de05005bSIgor Mammedov int64_t value = cpu->env.def.nwindows;
920de05005bSIgor Mammedov
921de05005bSIgor Mammedov visit_type_int(v, name, &value, errp);
922de05005bSIgor Mammedov }
923de05005bSIgor Mammedov
sparc_set_nwindows(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)924de05005bSIgor Mammedov static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
925de05005bSIgor Mammedov void *opaque, Error **errp)
926de05005bSIgor Mammedov {
927de05005bSIgor Mammedov const int64_t min = MIN_NWINDOWS;
928de05005bSIgor Mammedov const int64_t max = MAX_NWINDOWS;
929de05005bSIgor Mammedov SPARCCPU *cpu = SPARC_CPU(obj);
930de05005bSIgor Mammedov int64_t value;
931de05005bSIgor Mammedov
932668f62ecSMarkus Armbruster if (!visit_type_int(v, name, &value, errp)) {
933de05005bSIgor Mammedov return;
934de05005bSIgor Mammedov }
935de05005bSIgor Mammedov
936de05005bSIgor Mammedov if (value < min || value > max) {
937de05005bSIgor Mammedov error_setg(errp, "Property %s.%s doesn't take value %" PRId64
938de05005bSIgor Mammedov " (minimum: %" PRId64 ", maximum: %" PRId64 ")",
939de05005bSIgor Mammedov object_get_typename(obj), name ? name : "null",
940de05005bSIgor Mammedov value, min, max);
941de05005bSIgor Mammedov return;
942de05005bSIgor Mammedov }
943de05005bSIgor Mammedov cpu->env.def.nwindows = value;
944de05005bSIgor Mammedov }
945de05005bSIgor Mammedov
9463834cc6fSRichard Henderson static const PropertyInfo qdev_prop_nwindows = {
947c98dac16SMarkus Armbruster .type = "int",
94845e5b493SMarkus Armbruster .description = "Number of register windows",
949de05005bSIgor Mammedov .get = sparc_get_nwindows,
950de05005bSIgor Mammedov .set = sparc_set_nwindows,
951de05005bSIgor Mammedov };
952de05005bSIgor Mammedov
953de1f5203SRichard Henderson /* This must match feature_name[]. */
9543834cc6fSRichard Henderson static const Property sparc_cpu_properties[] = {
955de1f5203SRichard Henderson DEFINE_PROP_BIT("float128", SPARCCPU, env.def.features,
956de1f5203SRichard Henderson CPU_FEATURE_BIT_FLOAT128, false),
957554abe47SRichard Henderson #ifdef TARGET_SPARC64
958de1f5203SRichard Henderson DEFINE_PROP_BIT("cmt", SPARCCPU, env.def.features,
959de1f5203SRichard Henderson CPU_FEATURE_BIT_CMT, false),
960de1f5203SRichard Henderson DEFINE_PROP_BIT("gl", SPARCCPU, env.def.features,
961de1f5203SRichard Henderson CPU_FEATURE_BIT_GL, false),
962554abe47SRichard Henderson DEFINE_PROP_BIT("hypv", SPARCCPU, env.def.features,
963554abe47SRichard Henderson CPU_FEATURE_BIT_HYPV, false),
964554abe47SRichard Henderson DEFINE_PROP_BIT("vis1", SPARCCPU, env.def.features,
965554abe47SRichard Henderson CPU_FEATURE_BIT_VIS1, false),
966554abe47SRichard Henderson DEFINE_PROP_BIT("vis2", SPARCCPU, env.def.features,
967554abe47SRichard Henderson CPU_FEATURE_BIT_VIS2, false),
9684fd71d19SRichard Henderson DEFINE_PROP_BIT("fmaf", SPARCCPU, env.def.features,
9694fd71d19SRichard Henderson CPU_FEATURE_BIT_FMAF, false),
970deadbb14SRichard Henderson DEFINE_PROP_BIT("vis3", SPARCCPU, env.def.features,
971deadbb14SRichard Henderson CPU_FEATURE_BIT_VIS3, false),
97268a414e9SRichard Henderson DEFINE_PROP_BIT("ima", SPARCCPU, env.def.features,
97368a414e9SRichard Henderson CPU_FEATURE_BIT_IMA, false),
974b12b7227SRichard Henderson DEFINE_PROP_BIT("vis4", SPARCCPU, env.def.features,
975b12b7227SRichard Henderson CPU_FEATURE_BIT_VIS4, false),
976554abe47SRichard Henderson #else
977554abe47SRichard Henderson DEFINE_PROP_BIT("mul", SPARCCPU, env.def.features,
978554abe47SRichard Henderson CPU_FEATURE_BIT_MUL, false),
979554abe47SRichard Henderson DEFINE_PROP_BIT("div", SPARCCPU, env.def.features,
980554abe47SRichard Henderson CPU_FEATURE_BIT_DIV, false),
981554abe47SRichard Henderson DEFINE_PROP_BIT("fsmuld", SPARCCPU, env.def.features,
982554abe47SRichard Henderson CPU_FEATURE_BIT_FSMULD, false),
983554abe47SRichard Henderson #endif
984de05005bSIgor Mammedov DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU, env.def.iu_version, 0,
985de05005bSIgor Mammedov qdev_prop_uint64, target_ulong),
986de05005bSIgor Mammedov DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0),
987de05005bSIgor Mammedov DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0),
98843b6ab4cSEduardo Habkost DEFINE_PROP("nwindows", SPARCCPU, env.def.nwindows,
98943b6ab4cSEduardo Habkost qdev_prop_nwindows, uint32_t),
990de05005bSIgor Mammedov };
991de05005bSIgor Mammedov
9928b80bd28SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
9938b80bd28SPhilippe Mathieu-Daudé #include "hw/core/sysemu-cpu-ops.h"
9948b80bd28SPhilippe Mathieu-Daudé
9958b80bd28SPhilippe Mathieu-Daudé static const struct SysemuCPUOps sparc_sysemu_ops = {
99682f0f44dSPhilippe Mathieu-Daudé .has_work = sparc_cpu_has_work,
99708928c6dSPhilippe Mathieu-Daudé .get_phys_page_debug = sparc_cpu_get_phys_page_debug,
998feece4d0SPhilippe Mathieu-Daudé .legacy_vmsd = &vmstate_sparc_cpu,
9998b80bd28SPhilippe Mathieu-Daudé };
10008b80bd28SPhilippe Mathieu-Daudé #endif
10018b80bd28SPhilippe Mathieu-Daudé
100278271684SClaudio Fontana #ifdef CONFIG_TCG
100315017436SPhilippe Mathieu-Daudé #include "accel/tcg/cpu-ops.h"
100478271684SClaudio Fontana
1005*90f80e4bSRichard Henderson #ifndef CONFIG_USER_ONLY
sparc_pointer_wrap(CPUState * cs,int mmu_idx,vaddr result,vaddr base)1006*90f80e4bSRichard Henderson static vaddr sparc_pointer_wrap(CPUState *cs, int mmu_idx,
1007*90f80e4bSRichard Henderson vaddr result, vaddr base)
1008*90f80e4bSRichard Henderson {
1009*90f80e4bSRichard Henderson #ifdef TARGET_SPARC64
1010*90f80e4bSRichard Henderson return cpu_env(cs)->pstate & PS_AM ? (uint32_t)result : result;
1011*90f80e4bSRichard Henderson #else
1012*90f80e4bSRichard Henderson return (uint32_t)result;
1013*90f80e4bSRichard Henderson #endif
1014*90f80e4bSRichard Henderson }
1015*90f80e4bSRichard Henderson #endif
1016*90f80e4bSRichard Henderson
10171764ad70SRichard Henderson static const TCGCPUOps sparc_tcg_ops = {
10188201f1a2SPhilippe Mathieu-Daudé /*
10198201f1a2SPhilippe Mathieu-Daudé * From Oracle SPARC Architecture 2015:
10208201f1a2SPhilippe Mathieu-Daudé *
10218201f1a2SPhilippe Mathieu-Daudé * Compatibility notes: The PSO memory model described in SPARC V8 and
10228201f1a2SPhilippe Mathieu-Daudé * SPARC V9 compatibility architecture specifications was never
10238201f1a2SPhilippe Mathieu-Daudé * implemented in a SPARC V9 implementation and is not included in the
10248201f1a2SPhilippe Mathieu-Daudé * Oracle SPARC Architecture specification.
10258201f1a2SPhilippe Mathieu-Daudé *
10268201f1a2SPhilippe Mathieu-Daudé * The RMO memory model described in the SPARC V9 specification was
10278201f1a2SPhilippe Mathieu-Daudé * implemented in some non-Sun SPARC V9 implementations, but is not
10288201f1a2SPhilippe Mathieu-Daudé * directly supported in Oracle SPARC Architecture 2015 implementations.
10298201f1a2SPhilippe Mathieu-Daudé *
10308201f1a2SPhilippe Mathieu-Daudé * Therefore always use TSO in QEMU.
10318201f1a2SPhilippe Mathieu-Daudé *
10328201f1a2SPhilippe Mathieu-Daudé * D.5 Specification of Partial Store Order (PSO)
10338201f1a2SPhilippe Mathieu-Daudé * ... [loads] are followed by an implied MEMBAR #LoadLoad | #LoadStore.
10348201f1a2SPhilippe Mathieu-Daudé *
10358201f1a2SPhilippe Mathieu-Daudé * D.6 Specification of Total Store Order (TSO)
10368201f1a2SPhilippe Mathieu-Daudé * ... PSO with the additional requirement that all [stores] are followed
10378201f1a2SPhilippe Mathieu-Daudé * by an implied MEMBAR #StoreStore.
10388201f1a2SPhilippe Mathieu-Daudé */
10398201f1a2SPhilippe Mathieu-Daudé .guest_default_memory_order = TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_MO_ST_ST,
1040a3d40b5eSPhilippe Mathieu-Daudé .mttcg_supported = true,
104104583ce7SPhilippe Mathieu-Daudé
104278271684SClaudio Fontana .initialize = sparc_tcg_init,
1043e4a8e093SRichard Henderson .translate_code = sparc_translate_code,
1044c37f8978SRichard Henderson .get_tb_cpu_state = sparc_get_tb_cpu_state,
104578271684SClaudio Fontana .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
1046f36aaa53SRichard Henderson .restore_state_to_opc = sparc_restore_state_to_opc,
1047f34769a5SPhilippe Mathieu-Daudé .mmu_index = sparc_cpu_mmu_index,
104878271684SClaudio Fontana
104978271684SClaudio Fontana #ifndef CONFIG_USER_ONLY
1050caac44a5SRichard Henderson .tlb_fill = sparc_cpu_tlb_fill,
1051*90f80e4bSRichard Henderson .pointer_wrap = sparc_pointer_wrap,
1052798ac8b5SPhilippe Mathieu-Daudé .cpu_exec_interrupt = sparc_cpu_exec_interrupt,
10534f7b1ecbSPeter Maydell .cpu_exec_halt = sparc_cpu_has_work,
10549181ab45SRichard Henderson .cpu_exec_reset = cpu_reset,
105578271684SClaudio Fontana .do_interrupt = sparc_cpu_do_interrupt,
105678271684SClaudio Fontana .do_transaction_failed = sparc_cpu_do_transaction_failed,
105778271684SClaudio Fontana .do_unaligned_access = sparc_cpu_do_unaligned_access,
105878271684SClaudio Fontana #endif /* !CONFIG_USER_ONLY */
105978271684SClaudio Fontana };
106078271684SClaudio Fontana #endif /* CONFIG_TCG */
106178271684SClaudio Fontana
sparc_cpu_class_init(ObjectClass * oc,const void * data)106212d1a768SPhilippe Mathieu-Daudé static void sparc_cpu_class_init(ObjectClass *oc, const void *data)
1063ab7ab3d7SAndreas Färber {
1064ab7ab3d7SAndreas Färber SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
1065ab7ab3d7SAndreas Färber CPUClass *cc = CPU_CLASS(oc);
1066b6e91ebfSAndreas Färber DeviceClass *dc = DEVICE_CLASS(oc);
10673b4fff1bSPeter Maydell ResettableClass *rc = RESETTABLE_CLASS(oc);
1068b6e91ebfSAndreas Färber
1069bf853881SPhilippe Mathieu-Daudé device_class_set_parent_realize(dc, sparc_cpu_realizefn,
1070bf853881SPhilippe Mathieu-Daudé &scc->parent_realize);
10714f67d30bSMarc-André Lureau device_class_set_props(dc, sparc_cpu_properties);
1072ab7ab3d7SAndreas Färber
10733b4fff1bSPeter Maydell resettable_class_set_parent_phases(rc, NULL, sparc_cpu_reset_hold, NULL,
10743b4fff1bSPeter Maydell &scc->parent_phases);
107597a8ea5aSAndreas Färber
107612a6c15eSIgor Mammedov cc->class_by_name = sparc_cpu_class_by_name;
10778b54467fSPhilippe Mathieu-Daudé cc->list_cpus = sparc_cpu_list,
1078d1853231SIgor Mammedov cc->parse_features = sparc_cpu_parse_features;
1079878096eeSAndreas Färber cc->dump_state = sparc_cpu_dump_state;
1080f3659eeeSAndreas Färber #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
1081f3659eeeSAndreas Färber cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
1082f3659eeeSAndreas Färber #endif
1083f45748f1SAndreas Färber cc->set_pc = sparc_cpu_set_pc;
1084e4fdf9dfSRichard Henderson cc->get_pc = sparc_cpu_get_pc;
10855b50e790SAndreas Färber cc->gdb_read_register = sparc_cpu_gdb_read_register;
10865b50e790SAndreas Färber cc->gdb_write_register = sparc_cpu_gdb_write_register;
1087e84942f2SRichard Henderson #ifndef CONFIG_USER_ONLY
10888b80bd28SPhilippe Mathieu-Daudé cc->sysemu_ops = &sparc_sysemu_ops;
108900b941e5SAndreas Färber #endif
1090df0900ebSPeter Crosthwaite cc->disas_set_info = cpu_sparc_disas_set_info;
1091a0e372f0SAndreas Färber
1092a0e372f0SAndreas Färber #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
1093a0e372f0SAndreas Färber cc->gdb_num_core_regs = 86;
1094a0e372f0SAndreas Färber #else
1095a0e372f0SAndreas Färber cc->gdb_num_core_regs = 72;
1096a0e372f0SAndreas Färber #endif
109778271684SClaudio Fontana cc->tcg_ops = &sparc_tcg_ops;
1098ab7ab3d7SAndreas Färber }
1099ab7ab3d7SAndreas Färber
1100ab7ab3d7SAndreas Färber static const TypeInfo sparc_cpu_type_info = {
1101ab7ab3d7SAndreas Färber .name = TYPE_SPARC_CPU,
1102ab7ab3d7SAndreas Färber .parent = TYPE_CPU,
1103ab7ab3d7SAndreas Färber .instance_size = sizeof(SPARCCPU),
1104f669c992SRichard Henderson .instance_align = __alignof(SPARCCPU),
1105ab7ab3d7SAndreas Färber .instance_init = sparc_cpu_initfn,
110612a6c15eSIgor Mammedov .abstract = true,
1107ab7ab3d7SAndreas Färber .class_size = sizeof(SPARCCPUClass),
1108ab7ab3d7SAndreas Färber .class_init = sparc_cpu_class_init,
1109ab7ab3d7SAndreas Färber };
1110ab7ab3d7SAndreas Färber
sparc_cpu_cpudef_class_init(ObjectClass * oc,const void * data)111112d1a768SPhilippe Mathieu-Daudé static void sparc_cpu_cpudef_class_init(ObjectClass *oc, const void *data)
111212a6c15eSIgor Mammedov {
111312a6c15eSIgor Mammedov SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
111412a6c15eSIgor Mammedov scc->cpu_def = data;
111512a6c15eSIgor Mammedov }
111612a6c15eSIgor Mammedov
sparc_register_cpudef_type(const struct sparc_def_t * def)111712a6c15eSIgor Mammedov static void sparc_register_cpudef_type(const struct sparc_def_t *def)
111812a6c15eSIgor Mammedov {
111912a6c15eSIgor Mammedov char *typename = sparc_cpu_type_name(def->name);
112012a6c15eSIgor Mammedov TypeInfo ti = {
112112a6c15eSIgor Mammedov .name = typename,
112212a6c15eSIgor Mammedov .parent = TYPE_SPARC_CPU,
112312a6c15eSIgor Mammedov .class_init = sparc_cpu_cpudef_class_init,
1124b282b859SPhilippe Mathieu-Daudé .class_data = def,
112512a6c15eSIgor Mammedov };
112612a6c15eSIgor Mammedov
11272f02b71bSZhao Liu type_register_static(&ti);
112812a6c15eSIgor Mammedov g_free(typename);
112912a6c15eSIgor Mammedov }
113012a6c15eSIgor Mammedov
sparc_cpu_register_types(void)1131ab7ab3d7SAndreas Färber static void sparc_cpu_register_types(void)
1132ab7ab3d7SAndreas Färber {
113312a6c15eSIgor Mammedov int i;
113412a6c15eSIgor Mammedov
1135ab7ab3d7SAndreas Färber type_register_static(&sparc_cpu_type_info);
113612a6c15eSIgor Mammedov for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
113712a6c15eSIgor Mammedov sparc_register_cpudef_type(&sparc_defs[i]);
113812a6c15eSIgor Mammedov }
1139ab7ab3d7SAndreas Färber }
1140ab7ab3d7SAndreas Färber
1141ab7ab3d7SAndreas Färber type_init(sparc_cpu_register_types)
1142