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 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/>.
22 //#define DEBUG_FEATURES
24 static int cpu_sparc_find_by_name(sparc_def_t
*cpu_def
, const char *cpu_model
);
26 /* CPUClass::reset() */
27 static void sparc_cpu_reset(CPUState
*s
)
29 SPARCCPU
*cpu
= SPARC_CPU(s
);
30 SPARCCPUClass
*scc
= SPARC_CPU_GET_CLASS(cpu
);
31 CPUSPARCState
*env
= &cpu
->env
;
33 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
34 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
35 log_cpu_state(env
, 0);
40 memset(env
, 0, offsetof(CPUSPARCState
, breakpoints
));
43 #ifndef TARGET_SPARC64
46 env
->regwptr
= env
->regbase
+ (env
->cwp
* 16);
48 #if defined(CONFIG_USER_ONLY)
50 env
->cleanwin
= env
->nwindows
- 2;
51 env
->cansave
= env
->nwindows
- 2;
52 env
->pstate
= PS_RMO
| PS_PEF
| PS_IE
;
53 env
->asi
= 0x82; /* Primary no-fault */
56 #if !defined(TARGET_SPARC64)
62 env
->pstate
= PS_PRIV
|PS_RED
|PS_PEF
|PS_AG
;
63 env
->hpstate
= cpu_has_hypervisor(env
) ? HS_PRIV
: 0;
65 cpu_tsptr(env
)->tt
= TT_POWER_ON_RESET
;
68 env
->mmuregs
[0] &= ~(MMU_E
| MMU_NF
);
69 env
->mmuregs
[0] |= env
->def
->mmu_bm
;
72 env
->npc
= env
->pc
+ 4;
74 env
->cache_control
= 0;
77 static int cpu_sparc_register(CPUSPARCState
*env
, const char *cpu_model
)
79 sparc_def_t def1
, *def
= &def1
;
81 if (cpu_sparc_find_by_name(def
, cpu_model
) < 0) {
85 env
->def
= g_new0(sparc_def_t
, 1);
86 memcpy(env
->def
, def
, sizeof(*def
));
87 #if defined(CONFIG_USER_ONLY)
88 if ((env
->def
->features
& CPU_FEATURE_FLOAT
)) {
89 env
->def
->features
|= CPU_FEATURE_FLOAT128
;
92 env
->cpu_model_str
= cpu_model
;
93 env
->version
= def
->iu_version
;
94 env
->fsr
= def
->fpu_version
;
95 env
->nwindows
= def
->nwindows
;
96 #if !defined(TARGET_SPARC64)
97 env
->mmuregs
[0] |= def
->mmu_version
;
98 cpu_sparc_set_id(env
, 0);
99 env
->mxccregs
[7] |= def
->mxcc_version
;
101 env
->mmu_version
= def
->mmu_version
;
102 env
->maxtl
= def
->maxtl
;
103 env
->version
|= def
->maxtl
<< 8;
104 env
->version
|= def
->nwindows
- 1;
109 SPARCCPU
*cpu_sparc_init(const char *cpu_model
)
114 cpu
= SPARC_CPU(object_new(TYPE_SPARC_CPU
));
118 gen_intermediate_code_init(env
);
121 if (cpu_sparc_register(env
, cpu_model
) < 0) {
122 object_delete(OBJECT(cpu
));
130 void cpu_sparc_set_id(CPUSPARCState
*env
, unsigned int cpu
)
132 #if !defined(TARGET_SPARC64)
133 env
->mxccregs
[7] = ((cpu
+ 8) & 0xf) << 24;
137 static const sparc_def_t sparc_defs
[] = {
138 #ifdef TARGET_SPARC64
140 .name
= "Fujitsu Sparc64",
141 .iu_version
= ((0x04ULL
<< 48) | (0x02ULL
<< 32) | (0ULL << 24)),
142 .fpu_version
= 0x00000000,
143 .mmu_version
= mmu_us_12
,
146 .features
= CPU_DEFAULT_FEATURES
,
149 .name
= "Fujitsu Sparc64 III",
150 .iu_version
= ((0x04ULL
<< 48) | (0x03ULL
<< 32) | (0ULL << 24)),
151 .fpu_version
= 0x00000000,
152 .mmu_version
= mmu_us_12
,
155 .features
= CPU_DEFAULT_FEATURES
,
158 .name
= "Fujitsu Sparc64 IV",
159 .iu_version
= ((0x04ULL
<< 48) | (0x04ULL
<< 32) | (0ULL << 24)),
160 .fpu_version
= 0x00000000,
161 .mmu_version
= mmu_us_12
,
164 .features
= CPU_DEFAULT_FEATURES
,
167 .name
= "Fujitsu Sparc64 V",
168 .iu_version
= ((0x04ULL
<< 48) | (0x05ULL
<< 32) | (0x51ULL
<< 24)),
169 .fpu_version
= 0x00000000,
170 .mmu_version
= mmu_us_12
,
173 .features
= CPU_DEFAULT_FEATURES
,
176 .name
= "TI UltraSparc I",
177 .iu_version
= ((0x17ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)),
178 .fpu_version
= 0x00000000,
179 .mmu_version
= mmu_us_12
,
182 .features
= CPU_DEFAULT_FEATURES
,
185 .name
= "TI UltraSparc II",
186 .iu_version
= ((0x17ULL
<< 48) | (0x11ULL
<< 32) | (0x20ULL
<< 24)),
187 .fpu_version
= 0x00000000,
188 .mmu_version
= mmu_us_12
,
191 .features
= CPU_DEFAULT_FEATURES
,
194 .name
= "TI UltraSparc IIi",
195 .iu_version
= ((0x17ULL
<< 48) | (0x12ULL
<< 32) | (0x91ULL
<< 24)),
196 .fpu_version
= 0x00000000,
197 .mmu_version
= mmu_us_12
,
200 .features
= CPU_DEFAULT_FEATURES
,
203 .name
= "TI UltraSparc IIe",
204 .iu_version
= ((0x17ULL
<< 48) | (0x13ULL
<< 32) | (0x14ULL
<< 24)),
205 .fpu_version
= 0x00000000,
206 .mmu_version
= mmu_us_12
,
209 .features
= CPU_DEFAULT_FEATURES
,
212 .name
= "Sun UltraSparc III",
213 .iu_version
= ((0x3eULL
<< 48) | (0x14ULL
<< 32) | (0x34ULL
<< 24)),
214 .fpu_version
= 0x00000000,
215 .mmu_version
= mmu_us_12
,
218 .features
= CPU_DEFAULT_FEATURES
,
221 .name
= "Sun UltraSparc III Cu",
222 .iu_version
= ((0x3eULL
<< 48) | (0x15ULL
<< 32) | (0x41ULL
<< 24)),
223 .fpu_version
= 0x00000000,
224 .mmu_version
= mmu_us_3
,
227 .features
= CPU_DEFAULT_FEATURES
,
230 .name
= "Sun UltraSparc IIIi",
231 .iu_version
= ((0x3eULL
<< 48) | (0x16ULL
<< 32) | (0x34ULL
<< 24)),
232 .fpu_version
= 0x00000000,
233 .mmu_version
= mmu_us_12
,
236 .features
= CPU_DEFAULT_FEATURES
,
239 .name
= "Sun UltraSparc IV",
240 .iu_version
= ((0x3eULL
<< 48) | (0x18ULL
<< 32) | (0x31ULL
<< 24)),
241 .fpu_version
= 0x00000000,
242 .mmu_version
= mmu_us_4
,
245 .features
= CPU_DEFAULT_FEATURES
,
248 .name
= "Sun UltraSparc IV+",
249 .iu_version
= ((0x3eULL
<< 48) | (0x19ULL
<< 32) | (0x22ULL
<< 24)),
250 .fpu_version
= 0x00000000,
251 .mmu_version
= mmu_us_12
,
254 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_CMT
,
257 .name
= "Sun UltraSparc IIIi+",
258 .iu_version
= ((0x3eULL
<< 48) | (0x22ULL
<< 32) | (0ULL << 24)),
259 .fpu_version
= 0x00000000,
260 .mmu_version
= mmu_us_3
,
263 .features
= CPU_DEFAULT_FEATURES
,
266 .name
= "Sun UltraSparc T1",
267 /* defined in sparc_ifu_fdp.v and ctu.h */
268 .iu_version
= ((0x3eULL
<< 48) | (0x23ULL
<< 32) | (0x02ULL
<< 24)),
269 .fpu_version
= 0x00000000,
270 .mmu_version
= mmu_sun4v
,
273 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_HYPV
| CPU_FEATURE_CMT
277 .name
= "Sun UltraSparc T2",
278 /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
279 .iu_version
= ((0x3eULL
<< 48) | (0x24ULL
<< 32) | (0x02ULL
<< 24)),
280 .fpu_version
= 0x00000000,
281 .mmu_version
= mmu_sun4v
,
284 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_HYPV
| CPU_FEATURE_CMT
288 .name
= "NEC UltraSparc I",
289 .iu_version
= ((0x22ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)),
290 .fpu_version
= 0x00000000,
291 .mmu_version
= mmu_us_12
,
294 .features
= CPU_DEFAULT_FEATURES
,
298 .name
= "Fujitsu MB86900",
299 .iu_version
= 0x00 << 24, /* Impl 0, ver 0 */
300 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
301 .mmu_version
= 0x00 << 24, /* Impl 0, ver 0 */
302 .mmu_bm
= 0x00004000,
303 .mmu_ctpr_mask
= 0x007ffff0,
304 .mmu_cxr_mask
= 0x0000003f,
305 .mmu_sfsr_mask
= 0xffffffff,
306 .mmu_trcr_mask
= 0xffffffff,
308 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_FSMULD
,
311 .name
= "Fujitsu MB86904",
312 .iu_version
= 0x04 << 24, /* Impl 0, ver 4 */
313 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
314 .mmu_version
= 0x04 << 24, /* Impl 0, ver 4 */
315 .mmu_bm
= 0x00004000,
316 .mmu_ctpr_mask
= 0x00ffffc0,
317 .mmu_cxr_mask
= 0x000000ff,
318 .mmu_sfsr_mask
= 0x00016fff,
319 .mmu_trcr_mask
= 0x00ffffff,
321 .features
= CPU_DEFAULT_FEATURES
,
324 .name
= "Fujitsu MB86907",
325 .iu_version
= 0x05 << 24, /* Impl 0, ver 5 */
326 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
327 .mmu_version
= 0x05 << 24, /* Impl 0, ver 5 */
328 .mmu_bm
= 0x00004000,
329 .mmu_ctpr_mask
= 0xffffffc0,
330 .mmu_cxr_mask
= 0x000000ff,
331 .mmu_sfsr_mask
= 0x00016fff,
332 .mmu_trcr_mask
= 0xffffffff,
334 .features
= CPU_DEFAULT_FEATURES
,
337 .name
= "LSI L64811",
338 .iu_version
= 0x10 << 24, /* Impl 1, ver 0 */
339 .fpu_version
= 1 << 17, /* FPU version 1 (LSI L64814) */
340 .mmu_version
= 0x10 << 24,
341 .mmu_bm
= 0x00004000,
342 .mmu_ctpr_mask
= 0x007ffff0,
343 .mmu_cxr_mask
= 0x0000003f,
344 .mmu_sfsr_mask
= 0xffffffff,
345 .mmu_trcr_mask
= 0xffffffff,
347 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
351 .name
= "Cypress CY7C601",
352 .iu_version
= 0x11 << 24, /* Impl 1, ver 1 */
353 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
354 .mmu_version
= 0x10 << 24,
355 .mmu_bm
= 0x00004000,
356 .mmu_ctpr_mask
= 0x007ffff0,
357 .mmu_cxr_mask
= 0x0000003f,
358 .mmu_sfsr_mask
= 0xffffffff,
359 .mmu_trcr_mask
= 0xffffffff,
361 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
365 .name
= "Cypress CY7C611",
366 .iu_version
= 0x13 << 24, /* Impl 1, ver 3 */
367 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
368 .mmu_version
= 0x10 << 24,
369 .mmu_bm
= 0x00004000,
370 .mmu_ctpr_mask
= 0x007ffff0,
371 .mmu_cxr_mask
= 0x0000003f,
372 .mmu_sfsr_mask
= 0xffffffff,
373 .mmu_trcr_mask
= 0xffffffff,
375 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
379 .name
= "TI MicroSparc I",
380 .iu_version
= 0x41000000,
381 .fpu_version
= 4 << 17,
382 .mmu_version
= 0x41000000,
383 .mmu_bm
= 0x00004000,
384 .mmu_ctpr_mask
= 0x007ffff0,
385 .mmu_cxr_mask
= 0x0000003f,
386 .mmu_sfsr_mask
= 0x00016fff,
387 .mmu_trcr_mask
= 0x0000003f,
389 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_MUL
|
390 CPU_FEATURE_DIV
| CPU_FEATURE_FLUSH
| CPU_FEATURE_FSQRT
|
394 .name
= "TI MicroSparc II",
395 .iu_version
= 0x42000000,
396 .fpu_version
= 4 << 17,
397 .mmu_version
= 0x02000000,
398 .mmu_bm
= 0x00004000,
399 .mmu_ctpr_mask
= 0x00ffffc0,
400 .mmu_cxr_mask
= 0x000000ff,
401 .mmu_sfsr_mask
= 0x00016fff,
402 .mmu_trcr_mask
= 0x00ffffff,
404 .features
= CPU_DEFAULT_FEATURES
,
407 .name
= "TI MicroSparc IIep",
408 .iu_version
= 0x42000000,
409 .fpu_version
= 4 << 17,
410 .mmu_version
= 0x04000000,
411 .mmu_bm
= 0x00004000,
412 .mmu_ctpr_mask
= 0x00ffffc0,
413 .mmu_cxr_mask
= 0x000000ff,
414 .mmu_sfsr_mask
= 0x00016bff,
415 .mmu_trcr_mask
= 0x00ffffff,
417 .features
= CPU_DEFAULT_FEATURES
,
420 .name
= "TI SuperSparc 40", /* STP1020NPGA */
421 .iu_version
= 0x41000000, /* SuperSPARC 2.x */
422 .fpu_version
= 0 << 17,
423 .mmu_version
= 0x00000800, /* SuperSPARC 2.x, no MXCC */
424 .mmu_bm
= 0x00002000,
425 .mmu_ctpr_mask
= 0xffffffc0,
426 .mmu_cxr_mask
= 0x0000ffff,
427 .mmu_sfsr_mask
= 0xffffffff,
428 .mmu_trcr_mask
= 0xffffffff,
430 .features
= CPU_DEFAULT_FEATURES
,
433 .name
= "TI SuperSparc 50", /* STP1020PGA */
434 .iu_version
= 0x40000000, /* SuperSPARC 3.x */
435 .fpu_version
= 0 << 17,
436 .mmu_version
= 0x01000800, /* SuperSPARC 3.x, no MXCC */
437 .mmu_bm
= 0x00002000,
438 .mmu_ctpr_mask
= 0xffffffc0,
439 .mmu_cxr_mask
= 0x0000ffff,
440 .mmu_sfsr_mask
= 0xffffffff,
441 .mmu_trcr_mask
= 0xffffffff,
443 .features
= CPU_DEFAULT_FEATURES
,
446 .name
= "TI SuperSparc 51",
447 .iu_version
= 0x40000000, /* SuperSPARC 3.x */
448 .fpu_version
= 0 << 17,
449 .mmu_version
= 0x01000000, /* SuperSPARC 3.x, MXCC */
450 .mmu_bm
= 0x00002000,
451 .mmu_ctpr_mask
= 0xffffffc0,
452 .mmu_cxr_mask
= 0x0000ffff,
453 .mmu_sfsr_mask
= 0xffffffff,
454 .mmu_trcr_mask
= 0xffffffff,
455 .mxcc_version
= 0x00000104,
457 .features
= CPU_DEFAULT_FEATURES
,
460 .name
= "TI SuperSparc 60", /* STP1020APGA */
461 .iu_version
= 0x40000000, /* SuperSPARC 3.x */
462 .fpu_version
= 0 << 17,
463 .mmu_version
= 0x01000800, /* SuperSPARC 3.x, no MXCC */
464 .mmu_bm
= 0x00002000,
465 .mmu_ctpr_mask
= 0xffffffc0,
466 .mmu_cxr_mask
= 0x0000ffff,
467 .mmu_sfsr_mask
= 0xffffffff,
468 .mmu_trcr_mask
= 0xffffffff,
470 .features
= CPU_DEFAULT_FEATURES
,
473 .name
= "TI SuperSparc 61",
474 .iu_version
= 0x44000000, /* SuperSPARC 3.x */
475 .fpu_version
= 0 << 17,
476 .mmu_version
= 0x01000000, /* SuperSPARC 3.x, MXCC */
477 .mmu_bm
= 0x00002000,
478 .mmu_ctpr_mask
= 0xffffffc0,
479 .mmu_cxr_mask
= 0x0000ffff,
480 .mmu_sfsr_mask
= 0xffffffff,
481 .mmu_trcr_mask
= 0xffffffff,
482 .mxcc_version
= 0x00000104,
484 .features
= CPU_DEFAULT_FEATURES
,
487 .name
= "TI SuperSparc II",
488 .iu_version
= 0x40000000, /* SuperSPARC II 1.x */
489 .fpu_version
= 0 << 17,
490 .mmu_version
= 0x08000000, /* SuperSPARC II 1.x, MXCC */
491 .mmu_bm
= 0x00002000,
492 .mmu_ctpr_mask
= 0xffffffc0,
493 .mmu_cxr_mask
= 0x0000ffff,
494 .mmu_sfsr_mask
= 0xffffffff,
495 .mmu_trcr_mask
= 0xffffffff,
496 .mxcc_version
= 0x00000104,
498 .features
= CPU_DEFAULT_FEATURES
,
501 .name
= "Ross RT625",
502 .iu_version
= 0x1e000000,
503 .fpu_version
= 1 << 17,
504 .mmu_version
= 0x1e000000,
505 .mmu_bm
= 0x00004000,
506 .mmu_ctpr_mask
= 0x007ffff0,
507 .mmu_cxr_mask
= 0x0000003f,
508 .mmu_sfsr_mask
= 0xffffffff,
509 .mmu_trcr_mask
= 0xffffffff,
511 .features
= CPU_DEFAULT_FEATURES
,
514 .name
= "Ross RT620",
515 .iu_version
= 0x1f000000,
516 .fpu_version
= 1 << 17,
517 .mmu_version
= 0x1f000000,
518 .mmu_bm
= 0x00004000,
519 .mmu_ctpr_mask
= 0x007ffff0,
520 .mmu_cxr_mask
= 0x0000003f,
521 .mmu_sfsr_mask
= 0xffffffff,
522 .mmu_trcr_mask
= 0xffffffff,
524 .features
= CPU_DEFAULT_FEATURES
,
528 .iu_version
= 0x20000000,
529 .fpu_version
= 0 << 17, /* B5010/B5110/B5120/B5210 */
530 .mmu_version
= 0x20000000,
531 .mmu_bm
= 0x00004000,
532 .mmu_ctpr_mask
= 0x007ffff0,
533 .mmu_cxr_mask
= 0x0000003f,
534 .mmu_sfsr_mask
= 0xffffffff,
535 .mmu_trcr_mask
= 0xffffffff,
537 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
541 .name
= "Matsushita MN10501",
542 .iu_version
= 0x50000000,
543 .fpu_version
= 0 << 17,
544 .mmu_version
= 0x50000000,
545 .mmu_bm
= 0x00004000,
546 .mmu_ctpr_mask
= 0x007ffff0,
547 .mmu_cxr_mask
= 0x0000003f,
548 .mmu_sfsr_mask
= 0xffffffff,
549 .mmu_trcr_mask
= 0xffffffff,
551 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_MUL
| CPU_FEATURE_FSQRT
|
555 .name
= "Weitek W8601",
556 .iu_version
= 0x90 << 24, /* Impl 9, ver 0 */
557 .fpu_version
= 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
558 .mmu_version
= 0x10 << 24,
559 .mmu_bm
= 0x00004000,
560 .mmu_ctpr_mask
= 0x007ffff0,
561 .mmu_cxr_mask
= 0x0000003f,
562 .mmu_sfsr_mask
= 0xffffffff,
563 .mmu_trcr_mask
= 0xffffffff,
565 .features
= CPU_DEFAULT_FEATURES
,
569 .iu_version
= 0xf2000000,
570 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
571 .mmu_version
= 0xf2000000,
572 .mmu_bm
= 0x00004000,
573 .mmu_ctpr_mask
= 0x007ffff0,
574 .mmu_cxr_mask
= 0x0000003f,
575 .mmu_sfsr_mask
= 0xffffffff,
576 .mmu_trcr_mask
= 0xffffffff,
578 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_TA0_SHUTDOWN
,
582 .iu_version
= 0xf3000000,
583 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
584 .mmu_version
= 0xf3000000,
585 .mmu_bm
= 0x00000000,
586 .mmu_ctpr_mask
= 0x007ffff0,
587 .mmu_cxr_mask
= 0x0000003f,
588 .mmu_sfsr_mask
= 0xffffffff,
589 .mmu_trcr_mask
= 0xffffffff,
591 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_TA0_SHUTDOWN
|
592 CPU_FEATURE_ASR17
| CPU_FEATURE_CACHE_CTRL
,
597 static const char * const feature_name
[] = {
614 static void print_features(FILE *f
, fprintf_function cpu_fprintf
,
615 uint32_t features
, const char *prefix
)
619 for (i
= 0; i
< ARRAY_SIZE(feature_name
); i
++) {
620 if (feature_name
[i
] && (features
& (1 << i
))) {
622 (*cpu_fprintf
)(f
, "%s", prefix
);
624 (*cpu_fprintf
)(f
, "%s ", feature_name
[i
]);
629 static void add_flagname_to_bitmaps(const char *flagname
, uint32_t *features
)
633 for (i
= 0; i
< ARRAY_SIZE(feature_name
); i
++) {
634 if (feature_name
[i
] && !strcmp(flagname
, feature_name
[i
])) {
639 fprintf(stderr
, "CPU feature %s not found\n", flagname
);
642 static int cpu_sparc_find_by_name(sparc_def_t
*cpu_def
, const char *cpu_model
)
645 const sparc_def_t
*def
= NULL
;
646 char *s
= strdup(cpu_model
);
647 char *featurestr
, *name
= strtok(s
, ",");
648 uint32_t plus_features
= 0;
649 uint32_t minus_features
= 0;
651 uint32_t fpu_version
, mmu_version
, nwindows
;
653 for (i
= 0; i
< ARRAY_SIZE(sparc_defs
); i
++) {
654 if (strcasecmp(name
, sparc_defs
[i
].name
) == 0) {
655 def
= &sparc_defs
[i
];
661 memcpy(cpu_def
, def
, sizeof(*def
));
663 featurestr
= strtok(NULL
, ",");
667 if (featurestr
[0] == '+') {
668 add_flagname_to_bitmaps(featurestr
+ 1, &plus_features
);
669 } else if (featurestr
[0] == '-') {
670 add_flagname_to_bitmaps(featurestr
+ 1, &minus_features
);
671 } else if ((val
= strchr(featurestr
, '='))) {
673 if (!strcmp(featurestr
, "iu_version")) {
676 iu_version
= strtoll(val
, &err
, 0);
678 fprintf(stderr
, "bad numerical value %s\n", val
);
681 cpu_def
->iu_version
= iu_version
;
682 #ifdef DEBUG_FEATURES
683 fprintf(stderr
, "iu_version %" PRIx64
"\n", iu_version
);
685 } else if (!strcmp(featurestr
, "fpu_version")) {
688 fpu_version
= strtol(val
, &err
, 0);
690 fprintf(stderr
, "bad numerical value %s\n", val
);
693 cpu_def
->fpu_version
= fpu_version
;
694 #ifdef DEBUG_FEATURES
695 fprintf(stderr
, "fpu_version %x\n", fpu_version
);
697 } else if (!strcmp(featurestr
, "mmu_version")) {
700 mmu_version
= strtol(val
, &err
, 0);
702 fprintf(stderr
, "bad numerical value %s\n", val
);
705 cpu_def
->mmu_version
= mmu_version
;
706 #ifdef DEBUG_FEATURES
707 fprintf(stderr
, "mmu_version %x\n", mmu_version
);
709 } else if (!strcmp(featurestr
, "nwindows")) {
712 nwindows
= strtol(val
, &err
, 0);
713 if (!*val
|| *err
|| nwindows
> MAX_NWINDOWS
||
714 nwindows
< MIN_NWINDOWS
) {
715 fprintf(stderr
, "bad numerical value %s\n", val
);
718 cpu_def
->nwindows
= nwindows
;
719 #ifdef DEBUG_FEATURES
720 fprintf(stderr
, "nwindows %d\n", nwindows
);
723 fprintf(stderr
, "unrecognized feature %s\n", featurestr
);
727 fprintf(stderr
, "feature string `%s' not in format "
728 "(+feature|-feature|feature=xyz)\n", featurestr
);
731 featurestr
= strtok(NULL
, ",");
733 cpu_def
->features
|= plus_features
;
734 cpu_def
->features
&= ~minus_features
;
735 #ifdef DEBUG_FEATURES
736 print_features(stderr
, fprintf
, cpu_def
->features
, NULL
);
746 void sparc_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
750 for (i
= 0; i
< ARRAY_SIZE(sparc_defs
); i
++) {
751 (*cpu_fprintf
)(f
, "Sparc %16s IU " TARGET_FMT_lx
752 " FPU %08x MMU %08x NWINS %d ",
754 sparc_defs
[i
].iu_version
,
755 sparc_defs
[i
].fpu_version
,
756 sparc_defs
[i
].mmu_version
,
757 sparc_defs
[i
].nwindows
);
758 print_features(f
, cpu_fprintf
, CPU_DEFAULT_FEATURES
&
759 ~sparc_defs
[i
].features
, "-");
760 print_features(f
, cpu_fprintf
, ~CPU_DEFAULT_FEATURES
&
761 sparc_defs
[i
].features
, "+");
762 (*cpu_fprintf
)(f
, "\n");
764 (*cpu_fprintf
)(f
, "Default CPU feature flags (use '-' to remove): ");
765 print_features(f
, cpu_fprintf
, CPU_DEFAULT_FEATURES
, NULL
);
766 (*cpu_fprintf
)(f
, "\n");
767 (*cpu_fprintf
)(f
, "Available CPU feature flags (use '+' to add): ");
768 print_features(f
, cpu_fprintf
, ~CPU_DEFAULT_FEATURES
, NULL
);
769 (*cpu_fprintf
)(f
, "\n");
770 (*cpu_fprintf
)(f
, "Numerical features (use '=' to set): iu_version "
771 "fpu_version mmu_version nwindows\n");
774 static void cpu_print_cc(FILE *f
, fprintf_function cpu_fprintf
,
777 cpu_fprintf(f
, "%c%c%c%c", cc
& PSR_NEG
? 'N' : '-',
778 cc
& PSR_ZERO
? 'Z' : '-', cc
& PSR_OVF
? 'V' : '-',
779 cc
& PSR_CARRY
? 'C' : '-');
782 #ifdef TARGET_SPARC64
783 #define REGS_PER_LINE 4
785 #define REGS_PER_LINE 8
788 void cpu_dump_state(CPUSPARCState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
793 cpu_fprintf(f
, "pc: " TARGET_FMT_lx
" npc: " TARGET_FMT_lx
"\n", env
->pc
,
795 cpu_fprintf(f
, "General Registers:\n");
797 for (i
= 0; i
< 8; i
++) {
798 if (i
% REGS_PER_LINE
== 0) {
799 cpu_fprintf(f
, "%%g%d-%d:", i
, i
+ REGS_PER_LINE
- 1);
801 cpu_fprintf(f
, " " TARGET_FMT_lx
, env
->gregs
[i
]);
802 if (i
% REGS_PER_LINE
== REGS_PER_LINE
- 1) {
803 cpu_fprintf(f
, "\n");
806 cpu_fprintf(f
, "\nCurrent Register Window:\n");
807 for (x
= 0; x
< 3; x
++) {
808 for (i
= 0; i
< 8; i
++) {
809 if (i
% REGS_PER_LINE
== 0) {
810 cpu_fprintf(f
, "%%%c%d-%d: ",
811 x
== 0 ? 'o' : (x
== 1 ? 'l' : 'i'),
812 i
, i
+ REGS_PER_LINE
- 1);
814 cpu_fprintf(f
, TARGET_FMT_lx
" ", env
->regwptr
[i
+ x
* 8]);
815 if (i
% REGS_PER_LINE
== REGS_PER_LINE
- 1) {
816 cpu_fprintf(f
, "\n");
820 cpu_fprintf(f
, "\nFloating Point Registers:\n");
821 for (i
= 0; i
< TARGET_DPREGS
; i
++) {
823 cpu_fprintf(f
, "%%f%02d:", i
* 2);
825 cpu_fprintf(f
, " %016" PRIx64
, env
->fpr
[i
].ll
);
827 cpu_fprintf(f
, "\n");
830 #ifdef TARGET_SPARC64
831 cpu_fprintf(f
, "pstate: %08x ccr: %02x (icc: ", env
->pstate
,
832 (unsigned)cpu_get_ccr(env
));
833 cpu_print_cc(f
, cpu_fprintf
, cpu_get_ccr(env
) << PSR_CARRY_SHIFT
);
834 cpu_fprintf(f
, " xcc: ");
835 cpu_print_cc(f
, cpu_fprintf
, cpu_get_ccr(env
) << (PSR_CARRY_SHIFT
- 4));
836 cpu_fprintf(f
, ") asi: %02x tl: %d pil: %x\n", env
->asi
, env
->tl
,
838 cpu_fprintf(f
, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
839 "cleanwin: %d cwp: %d\n",
840 env
->cansave
, env
->canrestore
, env
->otherwin
, env
->wstate
,
841 env
->cleanwin
, env
->nwindows
- 1 - env
->cwp
);
842 cpu_fprintf(f
, "fsr: " TARGET_FMT_lx
" y: " TARGET_FMT_lx
" fprs: "
843 TARGET_FMT_lx
"\n", env
->fsr
, env
->y
, env
->fprs
);
845 cpu_fprintf(f
, "psr: %08x (icc: ", cpu_get_psr(env
));
846 cpu_print_cc(f
, cpu_fprintf
, cpu_get_psr(env
));
847 cpu_fprintf(f
, " SPE: %c%c%c) wim: %08x\n", env
->psrs
? 'S' : '-',
848 env
->psrps
? 'P' : '-', env
->psret
? 'E' : '-',
850 cpu_fprintf(f
, "fsr: " TARGET_FMT_lx
" y: " TARGET_FMT_lx
"\n",
855 static void sparc_cpu_initfn(Object
*obj
)
857 SPARCCPU
*cpu
= SPARC_CPU(obj
);
858 CPUSPARCState
*env
= &cpu
->env
;
863 static void sparc_cpu_uninitfn(Object
*obj
)
865 SPARCCPU
*cpu
= SPARC_CPU(obj
);
866 CPUSPARCState
*env
= &cpu
->env
;
871 static void sparc_cpu_class_init(ObjectClass
*oc
, void *data
)
873 SPARCCPUClass
*scc
= SPARC_CPU_CLASS(oc
);
874 CPUClass
*cc
= CPU_CLASS(oc
);
876 scc
->parent_reset
= cc
->reset
;
877 cc
->reset
= sparc_cpu_reset
;
880 static const TypeInfo sparc_cpu_type_info
= {
881 .name
= TYPE_SPARC_CPU
,
883 .instance_size
= sizeof(SPARCCPU
),
884 .instance_init
= sparc_cpu_initfn
,
885 .instance_finalize
= sparc_cpu_uninitfn
,
887 .class_size
= sizeof(SPARCCPUClass
),
888 .class_init
= sparc_cpu_class_init
,
891 static void sparc_cpu_register_types(void)
893 type_register_static(&sparc_cpu_type_info
);
896 type_init(sparc_cpu_register_types
)