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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
29 #include "qemu-common.h"
32 //#define DEBUG_FEATURES
34 static int cpu_sparc_find_by_name(sparc_def_t
*cpu_def
, const char *cpu_model
);
36 /* Sparc MMU emulation */
40 static spinlock_t global_cpu_lock
= SPIN_LOCK_UNLOCKED
;
44 spin_lock(&global_cpu_lock
);
49 spin_unlock(&global_cpu_lock
);
52 #if defined(CONFIG_USER_ONLY)
54 int cpu_sparc_handle_mmu_fault(CPUState
*env1
, target_ulong address
, int rw
,
55 int mmu_idx
, int is_softmmu
)
58 env1
->exception_index
= TT_TFAULT
;
60 env1
->exception_index
= TT_DFAULT
;
66 #ifndef TARGET_SPARC64
68 * Sparc V8 Reference MMU (SRMMU)
70 static const int access_table
[8][8] = {
71 { 0, 0, 0, 0, 8, 0, 12, 12 },
72 { 0, 0, 0, 0, 8, 0, 0, 0 },
73 { 8, 8, 0, 0, 0, 8, 12, 12 },
74 { 8, 8, 0, 0, 0, 8, 0, 0 },
75 { 8, 0, 8, 0, 8, 8, 12, 12 },
76 { 8, 0, 8, 0, 8, 0, 8, 0 },
77 { 8, 8, 8, 0, 8, 8, 12, 12 },
78 { 8, 8, 8, 0, 8, 8, 8, 0 }
81 static const int perm_table
[2][8] = {
84 PAGE_READ
| PAGE_WRITE
,
85 PAGE_READ
| PAGE_EXEC
,
86 PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
,
88 PAGE_READ
| PAGE_WRITE
,
89 PAGE_READ
| PAGE_EXEC
,
90 PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
94 PAGE_READ
| PAGE_WRITE
,
95 PAGE_READ
| PAGE_EXEC
,
96 PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
,
104 static int get_physical_address(CPUState
*env
, target_phys_addr_t
*physical
,
105 int *prot
, int *access_index
,
106 target_ulong address
, int rw
, int mmu_idx
)
108 int access_perms
= 0;
109 target_phys_addr_t pde_ptr
;
111 target_ulong virt_addr
;
112 int error_code
= 0, is_dirty
, is_user
;
113 unsigned long page_offset
;
115 is_user
= mmu_idx
== MMU_USER_IDX
;
116 virt_addr
= address
& TARGET_PAGE_MASK
;
118 if ((env
->mmuregs
[0] & MMU_E
) == 0) { /* MMU disabled */
119 // Boot mode: instruction fetches are taken from PROM
120 if (rw
== 2 && (env
->mmuregs
[0] & env
->def
->mmu_bm
)) {
121 *physical
= env
->prom_addr
| (address
& 0x7ffffULL
);
122 *prot
= PAGE_READ
| PAGE_EXEC
;
126 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
130 *access_index
= ((rw
& 1) << 2) | (rw
& 2) | (is_user
? 0 : 1);
131 *physical
= 0xffffffffffff0000ULL
;
133 /* SPARC reference MMU table walk: Context table->L1->L2->PTE */
134 /* Context base + context number */
135 pde_ptr
= (env
->mmuregs
[1] << 4) + (env
->mmuregs
[2] << 2);
136 pde
= ldl_phys(pde_ptr
);
139 switch (pde
& PTE_ENTRYTYPE_MASK
) {
141 case 0: /* Invalid */
143 case 2: /* L0 PTE, maybe should not happen? */
144 case 3: /* Reserved */
147 pde_ptr
= ((address
>> 22) & ~3) + ((pde
& ~3) << 4);
148 pde
= ldl_phys(pde_ptr
);
150 switch (pde
& PTE_ENTRYTYPE_MASK
) {
152 case 0: /* Invalid */
153 return (1 << 8) | (1 << 2);
154 case 3: /* Reserved */
155 return (1 << 8) | (4 << 2);
157 pde_ptr
= ((address
& 0xfc0000) >> 16) + ((pde
& ~3) << 4);
158 pde
= ldl_phys(pde_ptr
);
160 switch (pde
& PTE_ENTRYTYPE_MASK
) {
162 case 0: /* Invalid */
163 return (2 << 8) | (1 << 2);
164 case 3: /* Reserved */
165 return (2 << 8) | (4 << 2);
167 pde_ptr
= ((address
& 0x3f000) >> 10) + ((pde
& ~3) << 4);
168 pde
= ldl_phys(pde_ptr
);
170 switch (pde
& PTE_ENTRYTYPE_MASK
) {
172 case 0: /* Invalid */
173 return (3 << 8) | (1 << 2);
174 case 1: /* PDE, should not happen */
175 case 3: /* Reserved */
176 return (3 << 8) | (4 << 2);
178 virt_addr
= address
& TARGET_PAGE_MASK
;
179 page_offset
= (address
& TARGET_PAGE_MASK
) &
180 (TARGET_PAGE_SIZE
- 1);
184 virt_addr
= address
& ~0x3ffff;
185 page_offset
= address
& 0x3ffff;
189 virt_addr
= address
& ~0xffffff;
190 page_offset
= address
& 0xffffff;
194 /* update page modified and dirty bits */
195 is_dirty
= (rw
& 1) && !(pde
& PG_MODIFIED_MASK
);
196 if (!(pde
& PG_ACCESSED_MASK
) || is_dirty
) {
197 pde
|= PG_ACCESSED_MASK
;
199 pde
|= PG_MODIFIED_MASK
;
200 stl_phys_notdirty(pde_ptr
, pde
);
203 access_perms
= (pde
& PTE_ACCESS_MASK
) >> PTE_ACCESS_SHIFT
;
204 error_code
= access_table
[*access_index
][access_perms
];
205 if (error_code
&& !((env
->mmuregs
[0] & MMU_NF
) && is_user
))
208 /* the page can be put in the TLB */
209 *prot
= perm_table
[is_user
][access_perms
];
210 if (!(pde
& PG_MODIFIED_MASK
)) {
211 /* only set write access if already dirty... otherwise wait
213 *prot
&= ~PAGE_WRITE
;
216 /* Even if large ptes, we map only one 4KB page in the cache to
217 avoid filling it too fast */
218 *physical
= ((target_phys_addr_t
)(pde
& PTE_ADDR_MASK
) << 4) + page_offset
;
222 /* Perform address translation */
223 int cpu_sparc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
224 int mmu_idx
, int is_softmmu
)
226 target_phys_addr_t paddr
;
228 int error_code
= 0, prot
, ret
= 0, access_index
;
230 error_code
= get_physical_address(env
, &paddr
, &prot
, &access_index
,
231 address
, rw
, mmu_idx
);
232 if (error_code
== 0) {
233 vaddr
= address
& TARGET_PAGE_MASK
;
234 paddr
&= TARGET_PAGE_MASK
;
236 printf("Translate at " TARGET_FMT_lx
" -> " TARGET_FMT_plx
", vaddr "
237 TARGET_FMT_lx
"\n", address
, paddr
, vaddr
);
239 ret
= tlb_set_page_exec(env
, vaddr
, paddr
, prot
, mmu_idx
, is_softmmu
);
243 if (env
->mmuregs
[3]) /* Fault status register */
244 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
245 env
->mmuregs
[3] |= (access_index
<< 5) | error_code
| 2;
246 env
->mmuregs
[4] = address
; /* Fault address register */
248 if ((env
->mmuregs
[0] & MMU_NF
) || env
->psret
== 0) {
249 // No fault mode: if a mapping is available, just override
250 // permissions. If no mapping is available, redirect accesses to
251 // neverland. Fake/overridden mappings will be flushed when
252 // switching to normal mode.
253 vaddr
= address
& TARGET_PAGE_MASK
;
254 prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
255 ret
= tlb_set_page_exec(env
, vaddr
, paddr
, prot
, mmu_idx
, is_softmmu
);
259 env
->exception_index
= TT_TFAULT
;
261 env
->exception_index
= TT_DFAULT
;
266 target_ulong
mmu_probe(CPUState
*env
, target_ulong address
, int mmulev
)
268 target_phys_addr_t pde_ptr
;
271 /* Context base + context number */
272 pde_ptr
= (target_phys_addr_t
)(env
->mmuregs
[1] << 4) +
273 (env
->mmuregs
[2] << 2);
274 pde
= ldl_phys(pde_ptr
);
276 switch (pde
& PTE_ENTRYTYPE_MASK
) {
278 case 0: /* Invalid */
279 case 2: /* PTE, maybe should not happen? */
280 case 3: /* Reserved */
285 pde_ptr
= ((address
>> 22) & ~3) + ((pde
& ~3) << 4);
286 pde
= ldl_phys(pde_ptr
);
288 switch (pde
& PTE_ENTRYTYPE_MASK
) {
290 case 0: /* Invalid */
291 case 3: /* Reserved */
298 pde_ptr
= ((address
& 0xfc0000) >> 16) + ((pde
& ~3) << 4);
299 pde
= ldl_phys(pde_ptr
);
301 switch (pde
& PTE_ENTRYTYPE_MASK
) {
303 case 0: /* Invalid */
304 case 3: /* Reserved */
311 pde_ptr
= ((address
& 0x3f000) >> 10) + ((pde
& ~3) << 4);
312 pde
= ldl_phys(pde_ptr
);
314 switch (pde
& PTE_ENTRYTYPE_MASK
) {
316 case 0: /* Invalid */
317 case 1: /* PDE, should not happen */
318 case 3: /* Reserved */
330 void dump_mmu(CPUState
*env
)
332 target_ulong va
, va1
, va2
;
333 unsigned int n
, m
, o
;
334 target_phys_addr_t pde_ptr
, pa
;
337 printf("MMU dump:\n");
338 pde_ptr
= (env
->mmuregs
[1] << 4) + (env
->mmuregs
[2] << 2);
339 pde
= ldl_phys(pde_ptr
);
340 printf("Root ptr: " TARGET_FMT_plx
", ctx: %d\n",
341 (target_phys_addr_t
)env
->mmuregs
[1] << 4, env
->mmuregs
[2]);
342 for (n
= 0, va
= 0; n
< 256; n
++, va
+= 16 * 1024 * 1024) {
343 pde
= mmu_probe(env
, va
, 2);
345 pa
= cpu_get_phys_page_debug(env
, va
);
346 printf("VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_plx
347 " PDE: " TARGET_FMT_lx
"\n", va
, pa
, pde
);
348 for (m
= 0, va1
= va
; m
< 64; m
++, va1
+= 256 * 1024) {
349 pde
= mmu_probe(env
, va1
, 1);
351 pa
= cpu_get_phys_page_debug(env
, va1
);
352 printf(" VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_plx
353 " PDE: " TARGET_FMT_lx
"\n", va1
, pa
, pde
);
354 for (o
= 0, va2
= va1
; o
< 64; o
++, va2
+= 4 * 1024) {
355 pde
= mmu_probe(env
, va2
, 0);
357 pa
= cpu_get_phys_page_debug(env
, va2
);
358 printf(" VA: " TARGET_FMT_lx
", PA: "
359 TARGET_FMT_plx
" PTE: " TARGET_FMT_lx
"\n",
367 printf("MMU dump ends\n");
369 #endif /* DEBUG_MMU */
371 #else /* !TARGET_SPARC64 */
373 // 41 bit physical address space
374 static inline target_phys_addr_t
ultrasparc_truncate_physical(uint64_t x
)
376 return x
& 0x1ffffffffffULL
;
380 * UltraSparc IIi I/DMMUs
383 static inline int compare_masked(uint64_t x
, uint64_t y
, uint64_t mask
)
385 return (x
& mask
) == (y
& mask
);
388 // Returns true if TTE tag is valid and matches virtual address value in context
389 // requires virtual address mask value calculated from TTE entry size
390 static inline int ultrasparc_tag_match(uint64_t tlb_tag
, uint64_t tlb_tte
,
391 uint64_t address
, uint64_t context
,
392 target_phys_addr_t
*physical
)
396 switch ((tlb_tte
>> 61) & 3) {
399 mask
= 0xffffffffffffe000ULL
;
402 mask
= 0xffffffffffff0000ULL
;
405 mask
= 0xfffffffffff80000ULL
;
408 mask
= 0xffffffffffc00000ULL
;
412 // valid, context match, virtual address match?
413 if ((tlb_tte
& 0x8000000000000000ULL
) &&
414 compare_masked(context
, tlb_tag
, 0x1fff) &&
415 compare_masked(address
, tlb_tag
, mask
))
417 // decode physical address
418 *physical
= ((tlb_tte
& mask
) | (address
& ~mask
)) & 0x1ffffffe000ULL
;
425 static int get_physical_address_data(CPUState
*env
,
426 target_phys_addr_t
*physical
, int *prot
,
427 target_ulong address
, int rw
, int is_user
)
432 if ((env
->lsu
& DMMU_E
) == 0) { /* DMMU disabled */
433 *physical
= ultrasparc_truncate_physical(address
);
434 *prot
= PAGE_READ
| PAGE_WRITE
;
438 context
= env
->dmmuregs
[1] & 0x1fff;
440 for (i
= 0; i
< 64; i
++) {
441 // ctx match, vaddr match, valid?
442 if (ultrasparc_tag_match(env
->dtlb_tag
[i
], env
->dtlb_tte
[i
],
443 address
, context
, physical
)
446 if (((env
->dtlb_tte
[i
] & 0x4) && is_user
) ||
447 (!(env
->dtlb_tte
[i
] & 0x2) && (rw
== 1))) {
448 if (env
->dmmuregs
[3]) /* Fault status register */
449 env
->dmmuregs
[3] = 2; /* overflow (not read before
451 env
->dmmuregs
[3] |= (is_user
<< 3) | ((rw
== 1) << 2) | 1;
452 env
->dmmuregs
[4] = address
; /* Fault address register */
453 env
->exception_index
= TT_DFAULT
;
455 printf("DFAULT at 0x%" PRIx64
"\n", address
);
460 if (env
->dtlb_tte
[i
] & 0x2)
466 printf("DMISS at 0x%" PRIx64
"\n", address
);
468 env
->dmmuregs
[6] = (address
& ~0x1fffULL
) | context
;
469 env
->exception_index
= TT_DMISS
;
473 static int get_physical_address_code(CPUState
*env
,
474 target_phys_addr_t
*physical
, int *prot
,
475 target_ulong address
, int is_user
)
480 if ((env
->lsu
& IMMU_E
) == 0 || (env
->pstate
& PS_RED
) != 0) {
482 *physical
= ultrasparc_truncate_physical(address
);
487 context
= env
->dmmuregs
[1] & 0x1fff;
489 for (i
= 0; i
< 64; i
++) {
490 // ctx match, vaddr match, valid?
491 if (ultrasparc_tag_match(env
->itlb_tag
[i
], env
->itlb_tte
[i
],
492 address
, context
, physical
)
495 if ((env
->itlb_tte
[i
] & 0x4) && is_user
) {
496 if (env
->immuregs
[3]) /* Fault status register */
497 env
->immuregs
[3] = 2; /* overflow (not read before
499 env
->immuregs
[3] |= (is_user
<< 3) | 1;
500 env
->exception_index
= TT_TFAULT
;
502 printf("TFAULT at 0x%" PRIx64
"\n", address
);
511 printf("TMISS at 0x%" PRIx64
"\n", address
);
513 /* Context is stored in DMMU (dmmuregs[1]) also for IMMU */
514 env
->immuregs
[6] = (address
& ~0x1fffULL
) | context
;
515 env
->exception_index
= TT_TMISS
;
519 static int get_physical_address(CPUState
*env
, target_phys_addr_t
*physical
,
520 int *prot
, int *access_index
,
521 target_ulong address
, int rw
, int mmu_idx
)
523 int is_user
= mmu_idx
== MMU_USER_IDX
;
526 return get_physical_address_code(env
, physical
, prot
, address
,
529 return get_physical_address_data(env
, physical
, prot
, address
, rw
,
533 /* Perform address translation */
534 int cpu_sparc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
535 int mmu_idx
, int is_softmmu
)
537 target_ulong virt_addr
, vaddr
;
538 target_phys_addr_t paddr
;
539 int error_code
= 0, prot
, ret
= 0, access_index
;
541 error_code
= get_physical_address(env
, &paddr
, &prot
, &access_index
,
542 address
, rw
, mmu_idx
);
543 if (error_code
== 0) {
544 virt_addr
= address
& TARGET_PAGE_MASK
;
545 vaddr
= virt_addr
+ ((address
& TARGET_PAGE_MASK
) &
546 (TARGET_PAGE_SIZE
- 1));
548 printf("Translate at 0x%" PRIx64
" -> 0x%" PRIx64
", vaddr 0x%" PRIx64
549 "\n", address
, paddr
, vaddr
);
551 ret
= tlb_set_page_exec(env
, vaddr
, paddr
, prot
, mmu_idx
, is_softmmu
);
559 void dump_mmu(CPUState
*env
)
564 printf("MMU contexts: Primary: %" PRId64
", Secondary: %" PRId64
"\n",
565 env
->dmmuregs
[1], env
->dmmuregs
[2]);
566 if ((env
->lsu
& DMMU_E
) == 0) {
567 printf("DMMU disabled\n");
569 printf("DMMU dump:\n");
570 for (i
= 0; i
< 64; i
++) {
571 switch ((env
->dtlb_tte
[i
] >> 61) & 3) {
586 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
587 printf("VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_lx
588 ", %s, %s, %s, %s, ctx %" PRId64
"\n",
589 env
->dtlb_tag
[i
] & ~0x1fffULL
,
590 env
->dtlb_tte
[i
] & 0x1ffffffe000ULL
,
592 env
->dtlb_tte
[i
] & 0x4? "priv": "user",
593 env
->dtlb_tte
[i
] & 0x2? "RW": "RO",
594 env
->dtlb_tte
[i
] & 0x40? "locked": "unlocked",
595 env
->dtlb_tag
[i
] & 0x1fffULL
);
599 if ((env
->lsu
& IMMU_E
) == 0) {
600 printf("IMMU disabled\n");
602 printf("IMMU dump:\n");
603 for (i
= 0; i
< 64; i
++) {
604 switch ((env
->itlb_tte
[i
] >> 61) & 3) {
619 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
620 printf("VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_lx
621 ", %s, %s, %s, ctx %" PRId64
"\n",
622 env
->itlb_tag
[i
] & ~0x1fffULL
,
623 env
->itlb_tte
[i
] & 0x1ffffffe000ULL
,
625 env
->itlb_tte
[i
] & 0x4? "priv": "user",
626 env
->itlb_tte
[i
] & 0x40? "locked": "unlocked",
627 env
->itlb_tag
[i
] & 0x1fffULL
);
632 #endif /* DEBUG_MMU */
634 #endif /* TARGET_SPARC64 */
635 #endif /* !CONFIG_USER_ONLY */
638 #if defined(CONFIG_USER_ONLY)
639 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
645 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
647 target_phys_addr_t phys_addr
;
648 int prot
, access_index
;
650 if (get_physical_address(env
, &phys_addr
, &prot
, &access_index
, addr
, 2,
651 MMU_KERNEL_IDX
) != 0)
652 if (get_physical_address(env
, &phys_addr
, &prot
, &access_index
, addr
,
653 0, MMU_KERNEL_IDX
) != 0)
655 if (cpu_get_physical_page_desc(phys_addr
) == IO_MEM_UNASSIGNED
)
661 void cpu_reset(CPUSPARCState
*env
)
663 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
664 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
665 log_cpu_state(env
, 0);
671 env
->regwptr
= env
->regbase
+ (env
->cwp
* 16);
672 #if defined(CONFIG_USER_ONLY)
673 #ifdef TARGET_SPARC64
674 env
->cleanwin
= env
->nwindows
- 2;
675 env
->cansave
= env
->nwindows
- 2;
676 env
->pstate
= PS_RMO
| PS_PEF
| PS_IE
;
677 env
->asi
= 0x82; // Primary no-fault
684 #ifdef TARGET_SPARC64
685 env
->pstate
= PS_PRIV
;
686 env
->hpstate
= HS_PRIV
;
687 env
->tsptr
= &env
->ts
[env
->tl
& MAXTL_MASK
];
690 env
->mmuregs
[0] &= ~(MMU_E
| MMU_NF
);
691 env
->mmuregs
[0] |= env
->def
->mmu_bm
;
694 env
->npc
= env
->pc
+ 4;
698 static int cpu_sparc_register(CPUSPARCState
*env
, const char *cpu_model
)
700 sparc_def_t def1
, *def
= &def1
;
702 if (cpu_sparc_find_by_name(def
, cpu_model
) < 0)
705 env
->def
= qemu_mallocz(sizeof(*def
));
706 memcpy(env
->def
, def
, sizeof(*def
));
707 #if defined(CONFIG_USER_ONLY)
708 if ((env
->def
->features
& CPU_FEATURE_FLOAT
))
709 env
->def
->features
|= CPU_FEATURE_FLOAT128
;
711 env
->cpu_model_str
= cpu_model
;
712 env
->version
= def
->iu_version
;
713 env
->fsr
= def
->fpu_version
;
714 env
->nwindows
= def
->nwindows
;
715 #if !defined(TARGET_SPARC64)
716 env
->mmuregs
[0] |= def
->mmu_version
;
717 cpu_sparc_set_id(env
, 0);
718 env
->mxccregs
[7] |= def
->mxcc_version
;
720 env
->mmu_version
= def
->mmu_version
;
721 env
->maxtl
= def
->maxtl
;
722 env
->version
|= def
->maxtl
<< 8;
723 env
->version
|= def
->nwindows
- 1;
728 static void cpu_sparc_close(CPUSPARCState
*env
)
734 CPUSPARCState
*cpu_sparc_init(const char *cpu_model
)
738 env
= qemu_mallocz(sizeof(CPUSPARCState
));
741 gen_intermediate_code_init(env
);
743 if (cpu_sparc_register(env
, cpu_model
) < 0) {
744 cpu_sparc_close(env
);
753 void cpu_sparc_set_id(CPUSPARCState
*env
, unsigned int cpu
)
755 #if !defined(TARGET_SPARC64)
756 env
->mxccregs
[7] = ((cpu
+ 8) & 0xf) << 24;
760 static const sparc_def_t sparc_defs
[] = {
761 #ifdef TARGET_SPARC64
763 .name
= "Fujitsu Sparc64",
764 .iu_version
= ((0x04ULL
<< 48) | (0x02ULL
<< 32) | (0ULL << 24)),
765 .fpu_version
= 0x00000000,
766 .mmu_version
= mmu_us_12
,
769 .features
= CPU_DEFAULT_FEATURES
,
772 .name
= "Fujitsu Sparc64 III",
773 .iu_version
= ((0x04ULL
<< 48) | (0x03ULL
<< 32) | (0ULL << 24)),
774 .fpu_version
= 0x00000000,
775 .mmu_version
= mmu_us_12
,
778 .features
= CPU_DEFAULT_FEATURES
,
781 .name
= "Fujitsu Sparc64 IV",
782 .iu_version
= ((0x04ULL
<< 48) | (0x04ULL
<< 32) | (0ULL << 24)),
783 .fpu_version
= 0x00000000,
784 .mmu_version
= mmu_us_12
,
787 .features
= CPU_DEFAULT_FEATURES
,
790 .name
= "Fujitsu Sparc64 V",
791 .iu_version
= ((0x04ULL
<< 48) | (0x05ULL
<< 32) | (0x51ULL
<< 24)),
792 .fpu_version
= 0x00000000,
793 .mmu_version
= mmu_us_12
,
796 .features
= CPU_DEFAULT_FEATURES
,
799 .name
= "TI UltraSparc I",
800 .iu_version
= ((0x17ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)),
801 .fpu_version
= 0x00000000,
802 .mmu_version
= mmu_us_12
,
805 .features
= CPU_DEFAULT_FEATURES
,
808 .name
= "TI UltraSparc II",
809 .iu_version
= ((0x17ULL
<< 48) | (0x11ULL
<< 32) | (0x20ULL
<< 24)),
810 .fpu_version
= 0x00000000,
811 .mmu_version
= mmu_us_12
,
814 .features
= CPU_DEFAULT_FEATURES
,
817 .name
= "TI UltraSparc IIi",
818 .iu_version
= ((0x17ULL
<< 48) | (0x12ULL
<< 32) | (0x91ULL
<< 24)),
819 .fpu_version
= 0x00000000,
820 .mmu_version
= mmu_us_12
,
823 .features
= CPU_DEFAULT_FEATURES
,
826 .name
= "TI UltraSparc IIe",
827 .iu_version
= ((0x17ULL
<< 48) | (0x13ULL
<< 32) | (0x14ULL
<< 24)),
828 .fpu_version
= 0x00000000,
829 .mmu_version
= mmu_us_12
,
832 .features
= CPU_DEFAULT_FEATURES
,
835 .name
= "Sun UltraSparc III",
836 .iu_version
= ((0x3eULL
<< 48) | (0x14ULL
<< 32) | (0x34ULL
<< 24)),
837 .fpu_version
= 0x00000000,
838 .mmu_version
= mmu_us_12
,
841 .features
= CPU_DEFAULT_FEATURES
,
844 .name
= "Sun UltraSparc III Cu",
845 .iu_version
= ((0x3eULL
<< 48) | (0x15ULL
<< 32) | (0x41ULL
<< 24)),
846 .fpu_version
= 0x00000000,
847 .mmu_version
= mmu_us_3
,
850 .features
= CPU_DEFAULT_FEATURES
,
853 .name
= "Sun UltraSparc IIIi",
854 .iu_version
= ((0x3eULL
<< 48) | (0x16ULL
<< 32) | (0x34ULL
<< 24)),
855 .fpu_version
= 0x00000000,
856 .mmu_version
= mmu_us_12
,
859 .features
= CPU_DEFAULT_FEATURES
,
862 .name
= "Sun UltraSparc IV",
863 .iu_version
= ((0x3eULL
<< 48) | (0x18ULL
<< 32) | (0x31ULL
<< 24)),
864 .fpu_version
= 0x00000000,
865 .mmu_version
= mmu_us_4
,
868 .features
= CPU_DEFAULT_FEATURES
,
871 .name
= "Sun UltraSparc IV+",
872 .iu_version
= ((0x3eULL
<< 48) | (0x19ULL
<< 32) | (0x22ULL
<< 24)),
873 .fpu_version
= 0x00000000,
874 .mmu_version
= mmu_us_12
,
877 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_CMT
,
880 .name
= "Sun UltraSparc IIIi+",
881 .iu_version
= ((0x3eULL
<< 48) | (0x22ULL
<< 32) | (0ULL << 24)),
882 .fpu_version
= 0x00000000,
883 .mmu_version
= mmu_us_3
,
886 .features
= CPU_DEFAULT_FEATURES
,
889 .name
= "Sun UltraSparc T1",
890 // defined in sparc_ifu_fdp.v and ctu.h
891 .iu_version
= ((0x3eULL
<< 48) | (0x23ULL
<< 32) | (0x02ULL
<< 24)),
892 .fpu_version
= 0x00000000,
893 .mmu_version
= mmu_sun4v
,
896 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_HYPV
| CPU_FEATURE_CMT
900 .name
= "Sun UltraSparc T2",
901 // defined in tlu_asi_ctl.v and n2_revid_cust.v
902 .iu_version
= ((0x3eULL
<< 48) | (0x24ULL
<< 32) | (0x02ULL
<< 24)),
903 .fpu_version
= 0x00000000,
904 .mmu_version
= mmu_sun4v
,
907 .features
= CPU_DEFAULT_FEATURES
| CPU_FEATURE_HYPV
| CPU_FEATURE_CMT
911 .name
= "NEC UltraSparc I",
912 .iu_version
= ((0x22ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)),
913 .fpu_version
= 0x00000000,
914 .mmu_version
= mmu_us_12
,
917 .features
= CPU_DEFAULT_FEATURES
,
921 .name
= "Fujitsu MB86900",
922 .iu_version
= 0x00 << 24, /* Impl 0, ver 0 */
923 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
924 .mmu_version
= 0x00 << 24, /* Impl 0, ver 0 */
925 .mmu_bm
= 0x00004000,
926 .mmu_ctpr_mask
= 0x007ffff0,
927 .mmu_cxr_mask
= 0x0000003f,
928 .mmu_sfsr_mask
= 0xffffffff,
929 .mmu_trcr_mask
= 0xffffffff,
931 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_FSMULD
,
934 .name
= "Fujitsu MB86904",
935 .iu_version
= 0x04 << 24, /* Impl 0, ver 4 */
936 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
937 .mmu_version
= 0x04 << 24, /* Impl 0, ver 4 */
938 .mmu_bm
= 0x00004000,
939 .mmu_ctpr_mask
= 0x00ffffc0,
940 .mmu_cxr_mask
= 0x000000ff,
941 .mmu_sfsr_mask
= 0x00016fff,
942 .mmu_trcr_mask
= 0x00ffffff,
944 .features
= CPU_DEFAULT_FEATURES
,
947 .name
= "Fujitsu MB86907",
948 .iu_version
= 0x05 << 24, /* Impl 0, ver 5 */
949 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
950 .mmu_version
= 0x05 << 24, /* Impl 0, ver 5 */
951 .mmu_bm
= 0x00004000,
952 .mmu_ctpr_mask
= 0xffffffc0,
953 .mmu_cxr_mask
= 0x000000ff,
954 .mmu_sfsr_mask
= 0x00016fff,
955 .mmu_trcr_mask
= 0xffffffff,
957 .features
= CPU_DEFAULT_FEATURES
,
960 .name
= "LSI L64811",
961 .iu_version
= 0x10 << 24, /* Impl 1, ver 0 */
962 .fpu_version
= 1 << 17, /* FPU version 1 (LSI L64814) */
963 .mmu_version
= 0x10 << 24,
964 .mmu_bm
= 0x00004000,
965 .mmu_ctpr_mask
= 0x007ffff0,
966 .mmu_cxr_mask
= 0x0000003f,
967 .mmu_sfsr_mask
= 0xffffffff,
968 .mmu_trcr_mask
= 0xffffffff,
970 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
974 .name
= "Cypress CY7C601",
975 .iu_version
= 0x11 << 24, /* Impl 1, ver 1 */
976 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
977 .mmu_version
= 0x10 << 24,
978 .mmu_bm
= 0x00004000,
979 .mmu_ctpr_mask
= 0x007ffff0,
980 .mmu_cxr_mask
= 0x0000003f,
981 .mmu_sfsr_mask
= 0xffffffff,
982 .mmu_trcr_mask
= 0xffffffff,
984 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
988 .name
= "Cypress CY7C611",
989 .iu_version
= 0x13 << 24, /* Impl 1, ver 3 */
990 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
991 .mmu_version
= 0x10 << 24,
992 .mmu_bm
= 0x00004000,
993 .mmu_ctpr_mask
= 0x007ffff0,
994 .mmu_cxr_mask
= 0x0000003f,
995 .mmu_sfsr_mask
= 0xffffffff,
996 .mmu_trcr_mask
= 0xffffffff,
998 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
1002 .name
= "TI MicroSparc I",
1003 .iu_version
= 0x41000000,
1004 .fpu_version
= 4 << 17,
1005 .mmu_version
= 0x41000000,
1006 .mmu_bm
= 0x00004000,
1007 .mmu_ctpr_mask
= 0x007ffff0,
1008 .mmu_cxr_mask
= 0x0000003f,
1009 .mmu_sfsr_mask
= 0x00016fff,
1010 .mmu_trcr_mask
= 0x0000003f,
1012 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_MUL
|
1013 CPU_FEATURE_DIV
| CPU_FEATURE_FLUSH
| CPU_FEATURE_FSQRT
|
1017 .name
= "TI MicroSparc II",
1018 .iu_version
= 0x42000000,
1019 .fpu_version
= 4 << 17,
1020 .mmu_version
= 0x02000000,
1021 .mmu_bm
= 0x00004000,
1022 .mmu_ctpr_mask
= 0x00ffffc0,
1023 .mmu_cxr_mask
= 0x000000ff,
1024 .mmu_sfsr_mask
= 0x00016fff,
1025 .mmu_trcr_mask
= 0x00ffffff,
1027 .features
= CPU_DEFAULT_FEATURES
,
1030 .name
= "TI MicroSparc IIep",
1031 .iu_version
= 0x42000000,
1032 .fpu_version
= 4 << 17,
1033 .mmu_version
= 0x04000000,
1034 .mmu_bm
= 0x00004000,
1035 .mmu_ctpr_mask
= 0x00ffffc0,
1036 .mmu_cxr_mask
= 0x000000ff,
1037 .mmu_sfsr_mask
= 0x00016bff,
1038 .mmu_trcr_mask
= 0x00ffffff,
1040 .features
= CPU_DEFAULT_FEATURES
,
1043 .name
= "TI SuperSparc 40", // STP1020NPGA
1044 .iu_version
= 0x41000000, // SuperSPARC 2.x
1045 .fpu_version
= 0 << 17,
1046 .mmu_version
= 0x00000800, // SuperSPARC 2.x, no MXCC
1047 .mmu_bm
= 0x00002000,
1048 .mmu_ctpr_mask
= 0xffffffc0,
1049 .mmu_cxr_mask
= 0x0000ffff,
1050 .mmu_sfsr_mask
= 0xffffffff,
1051 .mmu_trcr_mask
= 0xffffffff,
1053 .features
= CPU_DEFAULT_FEATURES
,
1056 .name
= "TI SuperSparc 50", // STP1020PGA
1057 .iu_version
= 0x40000000, // SuperSPARC 3.x
1058 .fpu_version
= 0 << 17,
1059 .mmu_version
= 0x01000800, // SuperSPARC 3.x, no MXCC
1060 .mmu_bm
= 0x00002000,
1061 .mmu_ctpr_mask
= 0xffffffc0,
1062 .mmu_cxr_mask
= 0x0000ffff,
1063 .mmu_sfsr_mask
= 0xffffffff,
1064 .mmu_trcr_mask
= 0xffffffff,
1066 .features
= CPU_DEFAULT_FEATURES
,
1069 .name
= "TI SuperSparc 51",
1070 .iu_version
= 0x40000000, // SuperSPARC 3.x
1071 .fpu_version
= 0 << 17,
1072 .mmu_version
= 0x01000000, // SuperSPARC 3.x, MXCC
1073 .mmu_bm
= 0x00002000,
1074 .mmu_ctpr_mask
= 0xffffffc0,
1075 .mmu_cxr_mask
= 0x0000ffff,
1076 .mmu_sfsr_mask
= 0xffffffff,
1077 .mmu_trcr_mask
= 0xffffffff,
1078 .mxcc_version
= 0x00000104,
1080 .features
= CPU_DEFAULT_FEATURES
,
1083 .name
= "TI SuperSparc 60", // STP1020APGA
1084 .iu_version
= 0x40000000, // SuperSPARC 3.x
1085 .fpu_version
= 0 << 17,
1086 .mmu_version
= 0x01000800, // SuperSPARC 3.x, no MXCC
1087 .mmu_bm
= 0x00002000,
1088 .mmu_ctpr_mask
= 0xffffffc0,
1089 .mmu_cxr_mask
= 0x0000ffff,
1090 .mmu_sfsr_mask
= 0xffffffff,
1091 .mmu_trcr_mask
= 0xffffffff,
1093 .features
= CPU_DEFAULT_FEATURES
,
1096 .name
= "TI SuperSparc 61",
1097 .iu_version
= 0x44000000, // SuperSPARC 3.x
1098 .fpu_version
= 0 << 17,
1099 .mmu_version
= 0x01000000, // SuperSPARC 3.x, MXCC
1100 .mmu_bm
= 0x00002000,
1101 .mmu_ctpr_mask
= 0xffffffc0,
1102 .mmu_cxr_mask
= 0x0000ffff,
1103 .mmu_sfsr_mask
= 0xffffffff,
1104 .mmu_trcr_mask
= 0xffffffff,
1105 .mxcc_version
= 0x00000104,
1107 .features
= CPU_DEFAULT_FEATURES
,
1110 .name
= "TI SuperSparc II",
1111 .iu_version
= 0x40000000, // SuperSPARC II 1.x
1112 .fpu_version
= 0 << 17,
1113 .mmu_version
= 0x08000000, // SuperSPARC II 1.x, MXCC
1114 .mmu_bm
= 0x00002000,
1115 .mmu_ctpr_mask
= 0xffffffc0,
1116 .mmu_cxr_mask
= 0x0000ffff,
1117 .mmu_sfsr_mask
= 0xffffffff,
1118 .mmu_trcr_mask
= 0xffffffff,
1119 .mxcc_version
= 0x00000104,
1121 .features
= CPU_DEFAULT_FEATURES
,
1124 .name
= "Ross RT625",
1125 .iu_version
= 0x1e000000,
1126 .fpu_version
= 1 << 17,
1127 .mmu_version
= 0x1e000000,
1128 .mmu_bm
= 0x00004000,
1129 .mmu_ctpr_mask
= 0x007ffff0,
1130 .mmu_cxr_mask
= 0x0000003f,
1131 .mmu_sfsr_mask
= 0xffffffff,
1132 .mmu_trcr_mask
= 0xffffffff,
1134 .features
= CPU_DEFAULT_FEATURES
,
1137 .name
= "Ross RT620",
1138 .iu_version
= 0x1f000000,
1139 .fpu_version
= 1 << 17,
1140 .mmu_version
= 0x1f000000,
1141 .mmu_bm
= 0x00004000,
1142 .mmu_ctpr_mask
= 0x007ffff0,
1143 .mmu_cxr_mask
= 0x0000003f,
1144 .mmu_sfsr_mask
= 0xffffffff,
1145 .mmu_trcr_mask
= 0xffffffff,
1147 .features
= CPU_DEFAULT_FEATURES
,
1150 .name
= "BIT B5010",
1151 .iu_version
= 0x20000000,
1152 .fpu_version
= 0 << 17, /* B5010/B5110/B5120/B5210 */
1153 .mmu_version
= 0x20000000,
1154 .mmu_bm
= 0x00004000,
1155 .mmu_ctpr_mask
= 0x007ffff0,
1156 .mmu_cxr_mask
= 0x0000003f,
1157 .mmu_sfsr_mask
= 0xffffffff,
1158 .mmu_trcr_mask
= 0xffffffff,
1160 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_SWAP
| CPU_FEATURE_FSQRT
|
1164 .name
= "Matsushita MN10501",
1165 .iu_version
= 0x50000000,
1166 .fpu_version
= 0 << 17,
1167 .mmu_version
= 0x50000000,
1168 .mmu_bm
= 0x00004000,
1169 .mmu_ctpr_mask
= 0x007ffff0,
1170 .mmu_cxr_mask
= 0x0000003f,
1171 .mmu_sfsr_mask
= 0xffffffff,
1172 .mmu_trcr_mask
= 0xffffffff,
1174 .features
= CPU_FEATURE_FLOAT
| CPU_FEATURE_MUL
| CPU_FEATURE_FSQRT
|
1178 .name
= "Weitek W8601",
1179 .iu_version
= 0x90 << 24, /* Impl 9, ver 0 */
1180 .fpu_version
= 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
1181 .mmu_version
= 0x10 << 24,
1182 .mmu_bm
= 0x00004000,
1183 .mmu_ctpr_mask
= 0x007ffff0,
1184 .mmu_cxr_mask
= 0x0000003f,
1185 .mmu_sfsr_mask
= 0xffffffff,
1186 .mmu_trcr_mask
= 0xffffffff,
1188 .features
= CPU_DEFAULT_FEATURES
,
1192 .iu_version
= 0xf2000000,
1193 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
1194 .mmu_version
= 0xf2000000,
1195 .mmu_bm
= 0x00004000,
1196 .mmu_ctpr_mask
= 0x007ffff0,
1197 .mmu_cxr_mask
= 0x0000003f,
1198 .mmu_sfsr_mask
= 0xffffffff,
1199 .mmu_trcr_mask
= 0xffffffff,
1201 .features
= CPU_DEFAULT_FEATURES
,
1205 .iu_version
= 0xf3000000,
1206 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
1207 .mmu_version
= 0xf3000000,
1208 .mmu_bm
= 0x00004000,
1209 .mmu_ctpr_mask
= 0x007ffff0,
1210 .mmu_cxr_mask
= 0x0000003f,
1211 .mmu_sfsr_mask
= 0xffffffff,
1212 .mmu_trcr_mask
= 0xffffffff,
1214 .features
= CPU_DEFAULT_FEATURES
,
1219 static const char * const feature_name
[] = {
1236 static void print_features(FILE *f
,
1237 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
1238 uint32_t features
, const char *prefix
)
1242 for (i
= 0; i
< ARRAY_SIZE(feature_name
); i
++)
1243 if (feature_name
[i
] && (features
& (1 << i
))) {
1245 (*cpu_fprintf
)(f
, "%s", prefix
);
1246 (*cpu_fprintf
)(f
, "%s ", feature_name
[i
]);
1250 static void add_flagname_to_bitmaps(const char *flagname
, uint32_t *features
)
1254 for (i
= 0; i
< ARRAY_SIZE(feature_name
); i
++)
1255 if (feature_name
[i
] && !strcmp(flagname
, feature_name
[i
])) {
1256 *features
|= 1 << i
;
1259 fprintf(stderr
, "CPU feature %s not found\n", flagname
);
1262 static int cpu_sparc_find_by_name(sparc_def_t
*cpu_def
, const char *cpu_model
)
1265 const sparc_def_t
*def
= NULL
;
1266 char *s
= strdup(cpu_model
);
1267 char *featurestr
, *name
= strtok(s
, ",");
1268 uint32_t plus_features
= 0;
1269 uint32_t minus_features
= 0;
1270 long long iu_version
;
1271 uint32_t fpu_version
, mmu_version
, nwindows
;
1273 for (i
= 0; i
< ARRAY_SIZE(sparc_defs
); i
++) {
1274 if (strcasecmp(name
, sparc_defs
[i
].name
) == 0) {
1275 def
= &sparc_defs
[i
];
1280 memcpy(cpu_def
, def
, sizeof(*def
));
1282 featurestr
= strtok(NULL
, ",");
1283 while (featurestr
) {
1286 if (featurestr
[0] == '+') {
1287 add_flagname_to_bitmaps(featurestr
+ 1, &plus_features
);
1288 } else if (featurestr
[0] == '-') {
1289 add_flagname_to_bitmaps(featurestr
+ 1, &minus_features
);
1290 } else if ((val
= strchr(featurestr
, '='))) {
1292 if (!strcmp(featurestr
, "iu_version")) {
1295 iu_version
= strtoll(val
, &err
, 0);
1296 if (!*val
|| *err
) {
1297 fprintf(stderr
, "bad numerical value %s\n", val
);
1300 cpu_def
->iu_version
= iu_version
;
1301 #ifdef DEBUG_FEATURES
1302 fprintf(stderr
, "iu_version %llx\n", iu_version
);
1304 } else if (!strcmp(featurestr
, "fpu_version")) {
1307 fpu_version
= strtol(val
, &err
, 0);
1308 if (!*val
|| *err
) {
1309 fprintf(stderr
, "bad numerical value %s\n", val
);
1312 cpu_def
->fpu_version
= fpu_version
;
1313 #ifdef DEBUG_FEATURES
1314 fprintf(stderr
, "fpu_version %llx\n", fpu_version
);
1316 } else if (!strcmp(featurestr
, "mmu_version")) {
1319 mmu_version
= strtol(val
, &err
, 0);
1320 if (!*val
|| *err
) {
1321 fprintf(stderr
, "bad numerical value %s\n", val
);
1324 cpu_def
->mmu_version
= mmu_version
;
1325 #ifdef DEBUG_FEATURES
1326 fprintf(stderr
, "mmu_version %llx\n", mmu_version
);
1328 } else if (!strcmp(featurestr
, "nwindows")) {
1331 nwindows
= strtol(val
, &err
, 0);
1332 if (!*val
|| *err
|| nwindows
> MAX_NWINDOWS
||
1333 nwindows
< MIN_NWINDOWS
) {
1334 fprintf(stderr
, "bad numerical value %s\n", val
);
1337 cpu_def
->nwindows
= nwindows
;
1338 #ifdef DEBUG_FEATURES
1339 fprintf(stderr
, "nwindows %d\n", nwindows
);
1342 fprintf(stderr
, "unrecognized feature %s\n", featurestr
);
1346 fprintf(stderr
, "feature string `%s' not in format "
1347 "(+feature|-feature|feature=xyz)\n", featurestr
);
1350 featurestr
= strtok(NULL
, ",");
1352 cpu_def
->features
|= plus_features
;
1353 cpu_def
->features
&= ~minus_features
;
1354 #ifdef DEBUG_FEATURES
1355 print_features(stderr
, fprintf
, cpu_def
->features
, NULL
);
1365 void sparc_cpu_list(FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
1369 for (i
= 0; i
< ARRAY_SIZE(sparc_defs
); i
++) {
1370 (*cpu_fprintf
)(f
, "Sparc %16s IU " TARGET_FMT_lx
" FPU %08x MMU %08x NWINS %d ",
1372 sparc_defs
[i
].iu_version
,
1373 sparc_defs
[i
].fpu_version
,
1374 sparc_defs
[i
].mmu_version
,
1375 sparc_defs
[i
].nwindows
);
1376 print_features(f
, cpu_fprintf
, CPU_DEFAULT_FEATURES
&
1377 ~sparc_defs
[i
].features
, "-");
1378 print_features(f
, cpu_fprintf
, ~CPU_DEFAULT_FEATURES
&
1379 sparc_defs
[i
].features
, "+");
1380 (*cpu_fprintf
)(f
, "\n");
1382 (*cpu_fprintf
)(f
, "Default CPU feature flags (use '-' to remove): ");
1383 print_features(f
, cpu_fprintf
, CPU_DEFAULT_FEATURES
, NULL
);
1384 (*cpu_fprintf
)(f
, "\n");
1385 (*cpu_fprintf
)(f
, "Available CPU feature flags (use '+' to add): ");
1386 print_features(f
, cpu_fprintf
, ~CPU_DEFAULT_FEATURES
, NULL
);
1387 (*cpu_fprintf
)(f
, "\n");
1388 (*cpu_fprintf
)(f
, "Numerical features (use '=' to set): iu_version "
1389 "fpu_version mmu_version nwindows\n");
1392 void cpu_dump_state(CPUState
*env
, FILE *f
,
1393 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
1398 cpu_fprintf(f
, "pc: " TARGET_FMT_lx
" npc: " TARGET_FMT_lx
"\n", env
->pc
,
1400 cpu_fprintf(f
, "General Registers:\n");
1401 for (i
= 0; i
< 4; i
++)
1402 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
1403 cpu_fprintf(f
, "\n");
1405 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
1406 cpu_fprintf(f
, "\nCurrent Register Window:\n");
1407 for (x
= 0; x
< 3; x
++) {
1408 for (i
= 0; i
< 4; i
++)
1409 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
1410 (x
== 0 ? 'o' : (x
== 1 ? 'l' : 'i')), i
,
1411 env
->regwptr
[i
+ x
* 8]);
1412 cpu_fprintf(f
, "\n");
1414 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
1415 (x
== 0 ? 'o' : x
== 1 ? 'l' : 'i'), i
,
1416 env
->regwptr
[i
+ x
* 8]);
1417 cpu_fprintf(f
, "\n");
1419 cpu_fprintf(f
, "\nFloating Point Registers:\n");
1420 for (i
= 0; i
< 32; i
++) {
1422 cpu_fprintf(f
, "%%f%02d:", i
);
1423 cpu_fprintf(f
, " %016f", *(float *)&env
->fpr
[i
]);
1425 cpu_fprintf(f
, "\n");
1427 #ifdef TARGET_SPARC64
1428 cpu_fprintf(f
, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
1429 env
->pstate
, GET_CCR(env
), env
->asi
, env
->tl
, env
->fprs
);
1430 cpu_fprintf(f
, "cansave: %d canrestore: %d otherwin: %d wstate %d "
1431 "cleanwin %d cwp %d\n",
1432 env
->cansave
, env
->canrestore
, env
->otherwin
, env
->wstate
,
1433 env
->cleanwin
, env
->nwindows
- 1 - env
->cwp
);
1436 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
1438 cpu_fprintf(f
, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n",
1439 GET_PSR(env
), GET_FLAG(PSR_ZERO
, 'Z'), GET_FLAG(PSR_OVF
, 'V'),
1440 GET_FLAG(PSR_NEG
, 'N'), GET_FLAG(PSR_CARRY
, 'C'),
1441 env
->psrs
?'S':'-', env
->psrps
?'P':'-',
1442 env
->psret
?'E':'-', env
->wim
);
1444 cpu_fprintf(f
, "fsr: 0x%08x\n", env
->fsr
);