2 * Sparc CPU init helpers
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qapi/error.h"
23 #include "qemu/module.h"
24 #include "qemu/qemu-print.h"
25 #include "exec/exec-all.h"
26 #include "hw/qdev-properties.h"
27 #include "qapi/visitor.h"
30 //#define DEBUG_FEATURES
32 static void sparc_cpu_reset_hold(Object
*obj
)
34 CPUState
*s
= CPU(obj
);
35 SPARCCPU
*cpu
= SPARC_CPU(s
);
36 SPARCCPUClass
*scc
= SPARC_CPU_GET_CLASS(cpu
);
37 CPUSPARCState
*env
= &cpu
->env
;
39 if (scc
->parent_phases
.hold
) {
40 scc
->parent_phases
.hold(obj
);
43 memset(env
, 0, offsetof(CPUSPARCState
, end_reset_fields
));
45 #ifndef TARGET_SPARC64
48 env
->regwptr
= env
->regbase
+ (env
->cwp
* 16);
50 #if defined(CONFIG_USER_ONLY)
52 env
->cleanwin
= env
->nwindows
- 2;
53 env
->cansave
= env
->nwindows
- 2;
54 env
->pstate
= PS_RMO
| PS_PEF
| PS_IE
;
55 env
->asi
= 0x82; /* Primary no-fault */
58 #if !defined(TARGET_SPARC64)
64 env
->pstate
= PS_PRIV
| PS_RED
| PS_PEF
;
65 if (!cpu_has_hypervisor(env
)) {
68 env
->hpstate
= cpu_has_hypervisor(env
) ? HS_PRIV
: 0;
71 cpu_tsptr(env
)->tt
= TT_POWER_ON_RESET
;
74 env
->mmuregs
[0] &= ~(MMU_E
| MMU_NF
);
75 env
->mmuregs
[0] |= env
->def
.mmu_bm
;
78 env
->npc
= env
->pc
+ 4;
80 env
->cache_control
= 0;
83 #ifndef CONFIG_USER_ONLY
84 static bool sparc_cpu_exec_interrupt(CPUState
*cs
, int interrupt_request
)
86 if (interrupt_request
& CPU_INTERRUPT_HARD
) {
87 SPARCCPU
*cpu
= SPARC_CPU(cs
);
88 CPUSPARCState
*env
= &cpu
->env
;
90 if (cpu_interrupts_enabled(env
) && env
->interrupt_index
> 0) {
91 int pil
= env
->interrupt_index
& 0xf;
92 int type
= env
->interrupt_index
& 0xf0;
94 if (type
!= TT_EXTINT
|| cpu_pil_allowed(env
, pil
)) {
95 cs
->exception_index
= env
->interrupt_index
;
96 sparc_cpu_do_interrupt(cs
);
103 #endif /* !CONFIG_USER_ONLY */
105 static void cpu_sparc_disas_set_info(CPUState
*cpu
, disassemble_info
*info
)
107 info
->print_insn
= print_insn_sparc
;
108 #ifdef TARGET_SPARC64
109 info
->mach
= bfd_mach_sparc_v9b
;
114 cpu_add_feat_as_prop(const char *typename
, const char *name
, const char *val
)
116 GlobalProperty
*prop
= g_new0(typeof(*prop
), 1);
117 prop
->driver
= typename
;
118 prop
->property
= g_strdup(name
);
119 prop
->value
= g_strdup(val
);
120 qdev_prop_register_global(prop
);
123 /* Parse "+feature,-feature,feature=foo" CPU feature string */
124 static void sparc_cpu_parse_features(const char *typename
, char *features
,
127 GList
*l
, *plus_features
= NULL
, *minus_features
= NULL
;
128 char *featurestr
; /* Single 'key=value" string being parsed */
129 static bool cpu_globals_initialized
;
131 if (cpu_globals_initialized
) {
134 cpu_globals_initialized
= true;
140 for (featurestr
= strtok(features
, ",");
142 featurestr
= strtok(NULL
, ",")) {
144 const char *val
= NULL
;
147 /* Compatibility syntax: */
148 if (featurestr
[0] == '+') {
149 plus_features
= g_list_append(plus_features
,
150 g_strdup(featurestr
+ 1));
152 } else if (featurestr
[0] == '-') {
153 minus_features
= g_list_append(minus_features
,
154 g_strdup(featurestr
+ 1));
158 eq
= strchr(featurestr
, '=');
165 * Temporarily, only +feat/-feat will be supported
166 * for boolean properties until we remove the
167 * minus-overrides-plus semantics and just follow
168 * the order options appear on the command-line.
170 * TODO: warn if user is relying on minus-override-plus semantics
171 * TODO: remove minus-override-plus semantics after
172 * warning for a few releases
174 if (!strcasecmp(val
, "on") ||
175 !strcasecmp(val
, "off") ||
176 !strcasecmp(val
, "true") ||
177 !strcasecmp(val
, "false")) {
178 error_setg(errp
, "Boolean properties in format %s=%s"
179 " are not supported", name
, val
);
183 error_setg(errp
, "Unsupported property format: %s", name
);
186 cpu_add_feat_as_prop(typename
, name
, val
);
189 for (l
= plus_features
; l
; l
= l
->next
) {
190 const char *name
= l
->data
;
191 cpu_add_feat_as_prop(typename
, name
, "on");
193 g_list_free_full(plus_features
, g_free
);
195 for (l
= minus_features
; l
; l
= l
->next
) {
196 const char *name
= l
->data
;
197 cpu_add_feat_as_prop(typename
, name
, "off");
199 g_list_free_full(minus_features
, g_free
);
202 void cpu_sparc_set_id(CPUSPARCState
*env
, unsigned int cpu
)
204 #if !defined(TARGET_SPARC64)
205 env
->mxccregs
[7] = ((cpu
+ 8) & 0xf) << 24;
209 static const sparc_def_t sparc_defs
[] = {
210 #ifdef TARGET_SPARC64
212 .name
= "Fujitsu Sparc64",
213 .iu_version
= ((0x04ULL
<< 48) | (0x02ULL
<< 32) | (0ULL << 24)),
214 .fpu_version
= 0x00000000,
215 .mmu_version
= mmu_us_12
,
218 .features
= CPU_DEFAULT_FEATURES
,
221 .name
= "Fujitsu Sparc64 III",
222 .iu_version
= ((0x04ULL
<< 48) | (0x03ULL
<< 32) | (0ULL << 24)),
223 .fpu_version
= 0x00000000,
224 .mmu_version
= mmu_us_12
,
227 .features
= CPU_DEFAULT_FEATURES
,
230 .name
= "Fujitsu Sparc64 IV",
231 .iu_version
= ((0x04ULL
<< 48) | (0x04ULL
<< 32) | (0ULL << 24)),
232 .fpu_version
= 0x00000000,
233 .mmu_version
= mmu_us_12
,
236 .features
= CPU_DEFAULT_FEATURES
,
239 .name
= "Fujitsu Sparc64 V",
240 .iu_version
= ((0x04ULL
<< 48) | (0x05ULL
<< 32) | (0x51ULL
<< 24)),
241 .fpu_version
= 0x00000000,
242 .mmu_version
= mmu_us_12
,
245 .features
= CPU_DEFAULT_FEATURES
,
248 .name
= "TI UltraSparc I",
249 .iu_version
= ((0x17ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)),
250 .fpu_version
= 0x00000000,
251 .mmu_version
= mmu_us_12
,
254 .features
= CPU_DEFAULT_FEATURES
,
257 .name
= "TI UltraSparc II",
258 .iu_version
= ((0x17ULL
<< 48) | (0x11ULL
<< 32) | (0x20ULL
<< 24)),
259 .fpu_version
= 0x00000000,
260 .mmu_version
= mmu_us_12
,
263 .features
= CPU_DEFAULT_FEATURES
,
266 .name
= "TI UltraSparc IIi",
267 .iu_version
= ((0x17ULL
<< 48) | (0x12ULL
<< 32) | (0x91ULL
<< 24)),
268 .fpu_version
= 0x00000000,
269 .mmu_version
= mmu_us_12
,
272 .features
= CPU_DEFAULT_FEATURES
,
275 .name
= "TI UltraSparc IIe",
276 .iu_version
= ((0x17ULL
<< 48) | (0x13ULL
<< 32) | (0x14ULL
<< 24)),
277 .fpu_version
= 0x00000000,
278 .mmu_version
= mmu_us_12
,
281 .features
= CPU_DEFAULT_FEATURES
,
284 .name
= "Sun UltraSparc III",
285 .iu_version
= ((0x3eULL
<< 48) | (0x14ULL
<< 32) | (0x34ULL
<< 24)),
286 .fpu_version
= 0x00000000,
287 .mmu_version
= mmu_us_12
,
290 .features
= CPU_DEFAULT_FEATURES
,
293 .name
= "Sun UltraSparc III Cu",
294 .iu_version
= ((0x3eULL
<< 48) | (0x15ULL
<< 32) | (0x41ULL
<< 24)),
295 .fpu_version
= 0x00000000,
296 .mmu_version
= mmu_us_3
,
299 .features
= CPU_DEFAULT_FEATURES
,
302 .name
= "Sun UltraSparc IIIi",
303 .iu_version
= ((0x3eULL
<< 48) | (0x16ULL
<< 32) | (0x34ULL
<< 24)),
304 .fpu_version
= 0x00000000,
305 .mmu_version
= mmu_us_12
,
308 .features
= CPU_DEFAULT_FEATURES
,
311 .name
= "Sun UltraSparc IV",
312 .iu_version
= ((0x3eULL
<< 48) | (0x18ULL
<< 32) | (0x31ULL
<< 24)),
313 .fpu_version
= 0x00000000,
314 .mmu_version
= mmu_us_4
,
317 .features
= CPU_DEFAULT_FEATURES
,
320 .name
= "Sun UltraSparc IV+",
321 .iu_version
= ((0x3eULL
<< 48) | (0x19ULL
<< 32) | (0x22ULL
<< 24)),
322 .fpu_version
= 0x00000000,
323 .mmu_version
= mmu_us_12
,
326 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_CMT
,
329 .name
= "Sun UltraSparc IIIi+",
330 .iu_version
= ((0x3eULL
<< 48) | (0x22ULL
<< 32) | (0ULL << 24)),
331 .fpu_version
= 0x00000000,
332 .mmu_version
= mmu_us_3
,
335 .features
= CPU_DEFAULT_FEATURES
,
338 .name
= "Sun UltraSparc T1",
339 /* defined in sparc_ifu_fdp.v and ctu.h */
340 .iu_version
= ((0x3eULL
<< 48) | (0x23ULL
<< 32) | (0x02ULL
<< 24)),
341 .fpu_version
= 0x00000000,
342 .mmu_version
= mmu_sun4v
,
345 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_HYPV
| CPU_FEATURE_CMT
349 .name
= "Sun UltraSparc T2",
350 /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
351 .iu_version
= ((0x3eULL
<< 48) | (0x24ULL
<< 32) | (0x02ULL
<< 24)),
352 .fpu_version
= 0x00000000,
353 .mmu_version
= mmu_sun4v
,
356 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_HYPV
| CPU_FEATURE_CMT
360 .name
= "NEC UltraSparc I",
361 .iu_version
= ((0x22ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)),
362 .fpu_version
= 0x00000000,
363 .mmu_version
= mmu_us_12
,
366 .features
= CPU_DEFAULT_FEATURES
,
370 .name
= "Fujitsu MB86904",
371 .iu_version
= 0x04 << 24, /* Impl 0, ver 4 */
372 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
373 .mmu_version
= 0x04 << 24, /* Impl 0, ver 4 */
374 .mmu_bm
= 0x00004000,
375 .mmu_ctpr_mask
= 0x00ffffc0,
376 .mmu_cxr_mask
= 0x000000ff,
377 .mmu_sfsr_mask
= 0x00016fff,
378 .mmu_trcr_mask
= 0x00ffffff,
380 .features
= CPU_DEFAULT_FEATURES
,
383 .name
= "Fujitsu MB86907",
384 .iu_version
= 0x05 << 24, /* Impl 0, ver 5 */
385 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
386 .mmu_version
= 0x05 << 24, /* Impl 0, ver 5 */
387 .mmu_bm
= 0x00004000,
388 .mmu_ctpr_mask
= 0xffffffc0,
389 .mmu_cxr_mask
= 0x000000ff,
390 .mmu_sfsr_mask
= 0x00016fff,
391 .mmu_trcr_mask
= 0xffffffff,
393 .features
= CPU_DEFAULT_FEATURES
,
396 .name
= "TI MicroSparc I",
397 .iu_version
= 0x41000000,
398 .fpu_version
= 4 << 17,
399 .mmu_version
= 0x41000000,
400 .mmu_bm
= 0x00004000,
401 .mmu_ctpr_mask
= 0x007ffff0,
402 .mmu_cxr_mask
= 0x0000003f,
403 .mmu_sfsr_mask
= 0x00016fff,
404 .mmu_trcr_mask
= 0x0000003f,
406 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_MUL
|
407 CPU_FEATURE_DIV
| CPU_FEATURE_FLUSH
| CPU_FEATURE_FSQRT
|
411 .name
= "TI MicroSparc II",
412 .iu_version
= 0x42000000,
413 .fpu_version
= 4 << 17,
414 .mmu_version
= 0x02000000,
415 .mmu_bm
= 0x00004000,
416 .mmu_ctpr_mask
= 0x00ffffc0,
417 .mmu_cxr_mask
= 0x000000ff,
418 .mmu_sfsr_mask
= 0x00016fff,
419 .mmu_trcr_mask
= 0x00ffffff,
421 .features
= CPU_DEFAULT_FEATURES
,
424 .name
= "TI MicroSparc IIep",
425 .iu_version
= 0x42000000,
426 .fpu_version
= 4 << 17,
427 .mmu_version
= 0x04000000,
428 .mmu_bm
= 0x00004000,
429 .mmu_ctpr_mask
= 0x00ffffc0,
430 .mmu_cxr_mask
= 0x000000ff,
431 .mmu_sfsr_mask
= 0x00016bff,
432 .mmu_trcr_mask
= 0x00ffffff,
434 .features
= CPU_DEFAULT_FEATURES
,
437 .name
= "TI SuperSparc 40", /* STP1020NPGA */
438 .iu_version
= 0x41000000, /* SuperSPARC 2.x */
439 .fpu_version
= 0 << 17,
440 .mmu_version
= 0x00000800, /* SuperSPARC 2.x, no MXCC */
441 .mmu_bm
= 0x00002000,
442 .mmu_ctpr_mask
= 0xffffffc0,
443 .mmu_cxr_mask
= 0x0000ffff,
444 .mmu_sfsr_mask
= 0xffffffff,
445 .mmu_trcr_mask
= 0xffffffff,
447 .features
= CPU_DEFAULT_FEATURES
,
450 .name
= "TI SuperSparc 50", /* STP1020PGA */
451 .iu_version
= 0x40000000, /* SuperSPARC 3.x */
452 .fpu_version
= 0 << 17,
453 .mmu_version
= 0x01000800, /* SuperSPARC 3.x, no MXCC */
454 .mmu_bm
= 0x00002000,
455 .mmu_ctpr_mask
= 0xffffffc0,
456 .mmu_cxr_mask
= 0x0000ffff,
457 .mmu_sfsr_mask
= 0xffffffff,
458 .mmu_trcr_mask
= 0xffffffff,
460 .features
= CPU_DEFAULT_FEATURES
,
463 .name
= "TI SuperSparc 51",
464 .iu_version
= 0x40000000, /* SuperSPARC 3.x */
465 .fpu_version
= 0 << 17,
466 .mmu_version
= 0x01000000, /* SuperSPARC 3.x, MXCC */
467 .mmu_bm
= 0x00002000,
468 .mmu_ctpr_mask
= 0xffffffc0,
469 .mmu_cxr_mask
= 0x0000ffff,
470 .mmu_sfsr_mask
= 0xffffffff,
471 .mmu_trcr_mask
= 0xffffffff,
472 .mxcc_version
= 0x00000104,
474 .features
= CPU_DEFAULT_FEATURES
,
477 .name
= "TI SuperSparc 60", /* STP1020APGA */
478 .iu_version
= 0x40000000, /* SuperSPARC 3.x */
479 .fpu_version
= 0 << 17,
480 .mmu_version
= 0x01000800, /* SuperSPARC 3.x, no MXCC */
481 .mmu_bm
= 0x00002000,
482 .mmu_ctpr_mask
= 0xffffffc0,
483 .mmu_cxr_mask
= 0x0000ffff,
484 .mmu_sfsr_mask
= 0xffffffff,
485 .mmu_trcr_mask
= 0xffffffff,
487 .features
= CPU_DEFAULT_FEATURES
,
490 .name
= "TI SuperSparc 61",
491 .iu_version
= 0x44000000, /* SuperSPARC 3.x */
492 .fpu_version
= 0 << 17,
493 .mmu_version
= 0x01000000, /* SuperSPARC 3.x, MXCC */
494 .mmu_bm
= 0x00002000,
495 .mmu_ctpr_mask
= 0xffffffc0,
496 .mmu_cxr_mask
= 0x0000ffff,
497 .mmu_sfsr_mask
= 0xffffffff,
498 .mmu_trcr_mask
= 0xffffffff,
499 .mxcc_version
= 0x00000104,
501 .features
= CPU_DEFAULT_FEATURES
,
504 .name
= "TI SuperSparc II",
505 .iu_version
= 0x40000000, /* SuperSPARC II 1.x */
506 .fpu_version
= 0 << 17,
507 .mmu_version
= 0x08000000, /* SuperSPARC II 1.x, MXCC */
508 .mmu_bm
= 0x00002000,
509 .mmu_ctpr_mask
= 0xffffffc0,
510 .mmu_cxr_mask
= 0x0000ffff,
511 .mmu_sfsr_mask
= 0xffffffff,
512 .mmu_trcr_mask
= 0xffffffff,
513 .mxcc_version
= 0x00000104,
515 .features
= CPU_DEFAULT_FEATURES
,
519 .iu_version
= 0xf2000000,
520 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
521 .mmu_version
= 0xf2000000,
522 .mmu_bm
= 0x00004000,
523 .mmu_ctpr_mask
= 0x007ffff0,
524 .mmu_cxr_mask
= 0x0000003f,
525 .mmu_sfsr_mask
= 0xffffffff,
526 .mmu_trcr_mask
= 0xffffffff,
528 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_TA0_SHUTDOWN
,
532 .iu_version
= 0xf3000000,
533 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
534 .mmu_version
= 0xf3000000,
535 .mmu_bm
= 0x00000000,
536 .mmu_ctpr_mask
= 0xfffffffc,
537 .mmu_cxr_mask
= 0x000000ff,
538 .mmu_sfsr_mask
= 0xffffffff,
539 .mmu_trcr_mask
= 0xffffffff,
541 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_TA0_SHUTDOWN
|
542 CPU_FEATURE_ASR17
| CPU_FEATURE_CACHE_CTRL
| CPU_FEATURE_POWERDOWN
|
548 static const char * const feature_name
[] = {
565 static void print_features(uint32_t features
, const char *prefix
)
569 for (i
= 0; i
< ARRAY_SIZE(feature_name
); i
++) {
570 if (feature_name
[i
] && (features
& (1 << i
))) {
572 qemu_printf("%s", prefix
);
574 qemu_printf("%s ", feature_name
[i
]);
579 void sparc_cpu_list(void)
583 for (i
= 0; i
< ARRAY_SIZE(sparc_defs
); i
++) {
584 qemu_printf("Sparc %16s IU " TARGET_FMT_lx
585 " FPU %08x MMU %08x NWINS %d ",
587 sparc_defs
[i
].iu_version
,
588 sparc_defs
[i
].fpu_version
,
589 sparc_defs
[i
].mmu_version
,
590 sparc_defs
[i
].nwindows
);
591 print_features(CPU_DEFAULT_FEATURES
& ~sparc_defs
[i
].features
, "-");
592 print_features(~CPU_DEFAULT_FEATURES
& sparc_defs
[i
].features
, "+");
595 qemu_printf("Default CPU feature flags (use '-' to remove): ");
596 print_features(CPU_DEFAULT_FEATURES
, NULL
);
598 qemu_printf("Available CPU feature flags (use '+' to add): ");
599 print_features(~CPU_DEFAULT_FEATURES
, NULL
);
601 qemu_printf("Numerical features (use '=' to set): iu_version "
602 "fpu_version mmu_version nwindows\n");
605 static void cpu_print_cc(FILE *f
, uint32_t cc
)
607 qemu_fprintf(f
, "%c%c%c%c", cc
& PSR_NEG
? 'N' : '-',
608 cc
& PSR_ZERO
? 'Z' : '-', cc
& PSR_OVF
? 'V' : '-',
609 cc
& PSR_CARRY
? 'C' : '-');
612 #ifdef TARGET_SPARC64
613 #define REGS_PER_LINE 4
615 #define REGS_PER_LINE 8
618 static void sparc_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
620 SPARCCPU
*cpu
= SPARC_CPU(cs
);
621 CPUSPARCState
*env
= &cpu
->env
;
624 qemu_fprintf(f
, "pc: " TARGET_FMT_lx
" npc: " TARGET_FMT_lx
"\n", env
->pc
,
627 for (i
= 0; i
< 8; i
++) {
628 if (i
% REGS_PER_LINE
== 0) {
629 qemu_fprintf(f
, "%%g%d-%d:", i
, i
+ REGS_PER_LINE
- 1);
631 qemu_fprintf(f
, " " TARGET_FMT_lx
, env
->gregs
[i
]);
632 if (i
% REGS_PER_LINE
== REGS_PER_LINE
- 1) {
633 qemu_fprintf(f
, "\n");
636 for (x
= 0; x
< 3; x
++) {
637 for (i
= 0; i
< 8; i
++) {
638 if (i
% REGS_PER_LINE
== 0) {
639 qemu_fprintf(f
, "%%%c%d-%d: ",
640 x
== 0 ? 'o' : (x
== 1 ? 'l' : 'i'),
641 i
, i
+ REGS_PER_LINE
- 1);
643 qemu_fprintf(f
, TARGET_FMT_lx
" ", env
->regwptr
[i
+ x
* 8]);
644 if (i
% REGS_PER_LINE
== REGS_PER_LINE
- 1) {
645 qemu_fprintf(f
, "\n");
650 if (flags
& CPU_DUMP_FPU
) {
651 for (i
= 0; i
< TARGET_DPREGS
; i
++) {
653 qemu_fprintf(f
, "%%f%02d: ", i
* 2);
655 qemu_fprintf(f
, " %016" PRIx64
, env
->fpr
[i
].ll
);
657 qemu_fprintf(f
, "\n");
662 #ifdef TARGET_SPARC64
663 qemu_fprintf(f
, "pstate: %08x ccr: %02x (icc: ", env
->pstate
,
664 (unsigned)cpu_get_ccr(env
));
665 cpu_print_cc(f
, cpu_get_ccr(env
) << PSR_CARRY_SHIFT
);
666 qemu_fprintf(f
, " xcc: ");
667 cpu_print_cc(f
, cpu_get_ccr(env
) << (PSR_CARRY_SHIFT
- 4));
668 qemu_fprintf(f
, ") asi: %02x tl: %d pil: %x gl: %d\n", env
->asi
, env
->tl
,
669 env
->psrpil
, env
->gl
);
670 qemu_fprintf(f
, "tbr: " TARGET_FMT_lx
" hpstate: " TARGET_FMT_lx
" htba: "
671 TARGET_FMT_lx
"\n", env
->tbr
, env
->hpstate
, env
->htba
);
672 qemu_fprintf(f
, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
673 "cleanwin: %d cwp: %d\n",
674 env
->cansave
, env
->canrestore
, env
->otherwin
, env
->wstate
,
675 env
->cleanwin
, env
->nwindows
- 1 - env
->cwp
);
676 qemu_fprintf(f
, "fsr: " TARGET_FMT_lx
" y: " TARGET_FMT_lx
" fprs: %016x\n",
677 env
->fsr
, env
->y
, env
->fprs
);
680 qemu_fprintf(f
, "psr: %08x (icc: ", cpu_get_psr(env
));
681 cpu_print_cc(f
, cpu_get_psr(env
));
682 qemu_fprintf(f
, " SPE: %c%c%c) wim: %08x\n", env
->psrs
? 'S' : '-',
683 env
->psrps
? 'P' : '-', env
->psret
? 'E' : '-',
685 qemu_fprintf(f
, "fsr: " TARGET_FMT_lx
" y: " TARGET_FMT_lx
"\n",
688 qemu_fprintf(f
, "\n");
691 static void sparc_cpu_set_pc(CPUState
*cs
, vaddr value
)
693 SPARCCPU
*cpu
= SPARC_CPU(cs
);
696 cpu
->env
.npc
= value
+ 4;
699 static vaddr
sparc_cpu_get_pc(CPUState
*cs
)
701 SPARCCPU
*cpu
= SPARC_CPU(cs
);
706 static void sparc_cpu_synchronize_from_tb(CPUState
*cs
,
707 const TranslationBlock
*tb
)
709 SPARCCPU
*cpu
= SPARC_CPU(cs
);
711 tcg_debug_assert(!(cs
->tcg_cflags
& CF_PCREL
));
712 cpu
->env
.pc
= tb
->pc
;
713 cpu
->env
.npc
= tb
->cs_base
;
716 static bool sparc_cpu_has_work(CPUState
*cs
)
718 SPARCCPU
*cpu
= SPARC_CPU(cs
);
719 CPUSPARCState
*env
= &cpu
->env
;
721 return (cs
->interrupt_request
& CPU_INTERRUPT_HARD
) &&
722 cpu_interrupts_enabled(env
);
725 static char *sparc_cpu_type_name(const char *cpu_model
)
727 char *name
= g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model
);
730 /* SPARC cpu model names happen to have whitespaces,
731 * as type names shouldn't have spaces replace them with '-'
733 while ((s
= strchr(s
, ' '))) {
740 static ObjectClass
*sparc_cpu_class_by_name(const char *cpu_model
)
745 typename
= sparc_cpu_type_name(cpu_model
);
746 oc
= object_class_by_name(typename
);
751 static void sparc_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
753 CPUState
*cs
= CPU(dev
);
754 SPARCCPUClass
*scc
= SPARC_CPU_GET_CLASS(dev
);
755 Error
*local_err
= NULL
;
756 SPARCCPU
*cpu
= SPARC_CPU(dev
);
757 CPUSPARCState
*env
= &cpu
->env
;
759 #if defined(CONFIG_USER_ONLY)
760 if ((env
->def
.features
& CPU_FEATURE_FLOAT
)) {
761 env
->def
.features
|= CPU_FEATURE_FLOAT128
;
765 env
->version
= env
->def
.iu_version
;
766 env
->fsr
= env
->def
.fpu_version
;
767 env
->nwindows
= env
->def
.nwindows
;
768 #if !defined(TARGET_SPARC64)
769 env
->mmuregs
[0] |= env
->def
.mmu_version
;
770 cpu_sparc_set_id(env
, 0);
771 env
->mxccregs
[7] |= env
->def
.mxcc_version
;
773 env
->mmu_version
= env
->def
.mmu_version
;
774 env
->maxtl
= env
->def
.maxtl
;
775 env
->version
|= env
->def
.maxtl
<< 8;
776 env
->version
|= env
->def
.nwindows
- 1;
779 cpu_exec_realizefn(cs
, &local_err
);
780 if (local_err
!= NULL
) {
781 error_propagate(errp
, local_err
);
787 scc
->parent_realize(dev
, errp
);
790 static void sparc_cpu_initfn(Object
*obj
)
792 SPARCCPU
*cpu
= SPARC_CPU(obj
);
793 SPARCCPUClass
*scc
= SPARC_CPU_GET_CLASS(obj
);
794 CPUSPARCState
*env
= &cpu
->env
;
796 cpu_set_cpustate_pointers(cpu
);
799 env
->def
= *scc
->cpu_def
;
803 static void sparc_get_nwindows(Object
*obj
, Visitor
*v
, const char *name
,
804 void *opaque
, Error
**errp
)
806 SPARCCPU
*cpu
= SPARC_CPU(obj
);
807 int64_t value
= cpu
->env
.def
.nwindows
;
809 visit_type_int(v
, name
, &value
, errp
);
812 static void sparc_set_nwindows(Object
*obj
, Visitor
*v
, const char *name
,
813 void *opaque
, Error
**errp
)
815 const int64_t min
= MIN_NWINDOWS
;
816 const int64_t max
= MAX_NWINDOWS
;
817 SPARCCPU
*cpu
= SPARC_CPU(obj
);
820 if (!visit_type_int(v
, name
, &value
, errp
)) {
824 if (value
< min
|| value
> max
) {
825 error_setg(errp
, "Property %s.%s doesn't take value %" PRId64
826 " (minimum: %" PRId64
", maximum: %" PRId64
")",
827 object_get_typename(obj
), name
? name
: "null",
831 cpu
->env
.def
.nwindows
= value
;
834 static PropertyInfo qdev_prop_nwindows
= {
836 .get
= sparc_get_nwindows
,
837 .set
= sparc_set_nwindows
,
840 static Property sparc_cpu_properties
[] = {
841 DEFINE_PROP_BIT("float", SPARCCPU
, env
.def
.features
, 0, false),
842 DEFINE_PROP_BIT("float128", SPARCCPU
, env
.def
.features
, 1, false),
843 DEFINE_PROP_BIT("swap", SPARCCPU
, env
.def
.features
, 2, false),
844 DEFINE_PROP_BIT("mul", SPARCCPU
, env
.def
.features
, 3, false),
845 DEFINE_PROP_BIT("div", SPARCCPU
, env
.def
.features
, 4, false),
846 DEFINE_PROP_BIT("flush", SPARCCPU
, env
.def
.features
, 5, false),
847 DEFINE_PROP_BIT("fsqrt", SPARCCPU
, env
.def
.features
, 6, false),
848 DEFINE_PROP_BIT("fmul", SPARCCPU
, env
.def
.features
, 7, false),
849 DEFINE_PROP_BIT("vis1", SPARCCPU
, env
.def
.features
, 8, false),
850 DEFINE_PROP_BIT("vis2", SPARCCPU
, env
.def
.features
, 9, false),
851 DEFINE_PROP_BIT("fsmuld", SPARCCPU
, env
.def
.features
, 10, false),
852 DEFINE_PROP_BIT("hypv", SPARCCPU
, env
.def
.features
, 11, false),
853 DEFINE_PROP_BIT("cmt", SPARCCPU
, env
.def
.features
, 12, false),
854 DEFINE_PROP_BIT("gl", SPARCCPU
, env
.def
.features
, 13, false),
855 DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU
, env
.def
.iu_version
, 0,
856 qdev_prop_uint64
, target_ulong
),
857 DEFINE_PROP_UINT32("fpu-version", SPARCCPU
, env
.def
.fpu_version
, 0),
858 DEFINE_PROP_UINT32("mmu-version", SPARCCPU
, env
.def
.mmu_version
, 0),
859 DEFINE_PROP("nwindows", SPARCCPU
, env
.def
.nwindows
,
860 qdev_prop_nwindows
, uint32_t),
861 DEFINE_PROP_END_OF_LIST()
864 #ifndef CONFIG_USER_ONLY
865 #include "hw/core/sysemu-cpu-ops.h"
867 static const struct SysemuCPUOps sparc_sysemu_ops
= {
868 .get_phys_page_debug
= sparc_cpu_get_phys_page_debug
,
869 .legacy_vmsd
= &vmstate_sparc_cpu
,
874 #include "hw/core/tcg-cpu-ops.h"
876 static const struct TCGCPUOps sparc_tcg_ops
= {
877 .initialize
= sparc_tcg_init
,
878 .synchronize_from_tb
= sparc_cpu_synchronize_from_tb
,
879 .restore_state_to_opc
= sparc_restore_state_to_opc
,
881 #ifndef CONFIG_USER_ONLY
882 .tlb_fill
= sparc_cpu_tlb_fill
,
883 .cpu_exec_interrupt
= sparc_cpu_exec_interrupt
,
884 .do_interrupt
= sparc_cpu_do_interrupt
,
885 .do_transaction_failed
= sparc_cpu_do_transaction_failed
,
886 .do_unaligned_access
= sparc_cpu_do_unaligned_access
,
887 #endif /* !CONFIG_USER_ONLY */
889 #endif /* CONFIG_TCG */
891 static void sparc_cpu_class_init(ObjectClass
*oc
, void *data
)
893 SPARCCPUClass
*scc
= SPARC_CPU_CLASS(oc
);
894 CPUClass
*cc
= CPU_CLASS(oc
);
895 DeviceClass
*dc
= DEVICE_CLASS(oc
);
896 ResettableClass
*rc
= RESETTABLE_CLASS(oc
);
898 device_class_set_parent_realize(dc
, sparc_cpu_realizefn
,
899 &scc
->parent_realize
);
900 device_class_set_props(dc
, sparc_cpu_properties
);
902 resettable_class_set_parent_phases(rc
, NULL
, sparc_cpu_reset_hold
, NULL
,
903 &scc
->parent_phases
);
905 cc
->class_by_name
= sparc_cpu_class_by_name
;
906 cc
->parse_features
= sparc_cpu_parse_features
;
907 cc
->has_work
= sparc_cpu_has_work
;
908 cc
->dump_state
= sparc_cpu_dump_state
;
909 #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
910 cc
->memory_rw_debug
= sparc_cpu_memory_rw_debug
;
912 cc
->set_pc
= sparc_cpu_set_pc
;
913 cc
->get_pc
= sparc_cpu_get_pc
;
914 cc
->gdb_read_register
= sparc_cpu_gdb_read_register
;
915 cc
->gdb_write_register
= sparc_cpu_gdb_write_register
;
916 #ifndef CONFIG_USER_ONLY
917 cc
->sysemu_ops
= &sparc_sysemu_ops
;
919 cc
->disas_set_info
= cpu_sparc_disas_set_info
;
921 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
922 cc
->gdb_num_core_regs
= 86;
924 cc
->gdb_num_core_regs
= 72;
926 cc
->tcg_ops
= &sparc_tcg_ops
;
929 static const TypeInfo sparc_cpu_type_info
= {
930 .name
= TYPE_SPARC_CPU
,
932 .instance_size
= sizeof(SPARCCPU
),
933 .instance_init
= sparc_cpu_initfn
,
935 .class_size
= sizeof(SPARCCPUClass
),
936 .class_init
= sparc_cpu_class_init
,
939 static void sparc_cpu_cpudef_class_init(ObjectClass
*oc
, void *data
)
941 SPARCCPUClass
*scc
= SPARC_CPU_CLASS(oc
);
945 static void sparc_register_cpudef_type(const struct sparc_def_t
*def
)
947 char *typename
= sparc_cpu_type_name(def
->name
);
950 .parent
= TYPE_SPARC_CPU
,
951 .class_init
= sparc_cpu_cpudef_class_init
,
952 .class_data
= (void *)def
,
959 static void sparc_cpu_register_types(void)
963 type_register_static(&sparc_cpu_type_info
);
964 for (i
= 0; i
< ARRAY_SIZE(sparc_defs
); i
++) {
965 sparc_register_cpudef_type(&sparc_defs
[i
]);
969 type_init(sparc_cpu_register_types
)