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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "qemu-common.h"
34 typedef struct sparc_def_t sparc_def_t
;
37 const unsigned char *name
;
38 target_ulong iu_version
;
42 uint32_t mmu_ctpr_mask
;
43 uint32_t mmu_cxr_mask
;
44 uint32_t mmu_sfsr_mask
;
45 uint32_t mmu_trcr_mask
;
48 static const sparc_def_t
*cpu_sparc_find_by_name(const unsigned char *name
);
50 /* Sparc MMU emulation */
54 spinlock_t global_cpu_lock
= SPIN_LOCK_UNLOCKED
;
58 spin_lock(&global_cpu_lock
);
63 spin_unlock(&global_cpu_lock
);
66 #if defined(CONFIG_USER_ONLY)
68 int cpu_sparc_handle_mmu_fault(CPUState
*env
, target_ulong address
, int rw
,
69 int mmu_idx
, int is_softmmu
)
72 env
->exception_index
= TT_TFAULT
;
74 env
->exception_index
= TT_DFAULT
;
80 #ifndef TARGET_SPARC64
82 * Sparc V8 Reference MMU (SRMMU)
84 static const int access_table
[8][8] = {
85 { 0, 0, 0, 0, 2, 0, 3, 3 },
86 { 0, 0, 0, 0, 2, 0, 0, 0 },
87 { 2, 2, 0, 0, 0, 2, 3, 3 },
88 { 2, 2, 0, 0, 0, 2, 0, 0 },
89 { 2, 0, 2, 0, 2, 2, 3, 3 },
90 { 2, 0, 2, 0, 2, 0, 2, 0 },
91 { 2, 2, 2, 0, 2, 2, 3, 3 },
92 { 2, 2, 2, 0, 2, 2, 2, 0 }
95 static const int perm_table
[2][8] = {
98 PAGE_READ
| PAGE_WRITE
,
99 PAGE_READ
| PAGE_EXEC
,
100 PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
,
102 PAGE_READ
| PAGE_WRITE
,
103 PAGE_READ
| PAGE_EXEC
,
104 PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
108 PAGE_READ
| PAGE_WRITE
,
109 PAGE_READ
| PAGE_EXEC
,
110 PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
,
118 static int get_physical_address(CPUState
*env
, target_phys_addr_t
*physical
,
119 int *prot
, int *access_index
,
120 target_ulong address
, int rw
, int mmu_idx
)
122 int access_perms
= 0;
123 target_phys_addr_t pde_ptr
;
125 target_ulong virt_addr
;
126 int error_code
= 0, is_dirty
, is_user
;
127 unsigned long page_offset
;
129 is_user
= mmu_idx
== MMU_USER_IDX
;
130 virt_addr
= address
& TARGET_PAGE_MASK
;
132 if ((env
->mmuregs
[0] & MMU_E
) == 0) { /* MMU disabled */
133 // Boot mode: instruction fetches are taken from PROM
134 if (rw
== 2 && (env
->mmuregs
[0] & env
->mmu_bm
)) {
135 *physical
= env
->prom_addr
| (address
& 0x7ffffULL
);
136 *prot
= PAGE_READ
| PAGE_EXEC
;
140 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
144 *access_index
= ((rw
& 1) << 2) | (rw
& 2) | (is_user
? 0 : 1);
145 *physical
= 0xffffffffffff0000ULL
;
147 /* SPARC reference MMU table walk: Context table->L1->L2->PTE */
148 /* Context base + context number */
149 pde_ptr
= (env
->mmuregs
[1] << 4) + (env
->mmuregs
[2] << 2);
150 pde
= ldl_phys(pde_ptr
);
153 switch (pde
& PTE_ENTRYTYPE_MASK
) {
155 case 0: /* Invalid */
157 case 2: /* L0 PTE, maybe should not happen? */
158 case 3: /* Reserved */
161 pde_ptr
= ((address
>> 22) & ~3) + ((pde
& ~3) << 4);
162 pde
= ldl_phys(pde_ptr
);
164 switch (pde
& PTE_ENTRYTYPE_MASK
) {
166 case 0: /* Invalid */
167 return (1 << 8) | (1 << 2);
168 case 3: /* Reserved */
169 return (1 << 8) | (4 << 2);
171 pde_ptr
= ((address
& 0xfc0000) >> 16) + ((pde
& ~3) << 4);
172 pde
= ldl_phys(pde_ptr
);
174 switch (pde
& PTE_ENTRYTYPE_MASK
) {
176 case 0: /* Invalid */
177 return (2 << 8) | (1 << 2);
178 case 3: /* Reserved */
179 return (2 << 8) | (4 << 2);
181 pde_ptr
= ((address
& 0x3f000) >> 10) + ((pde
& ~3) << 4);
182 pde
= ldl_phys(pde_ptr
);
184 switch (pde
& PTE_ENTRYTYPE_MASK
) {
186 case 0: /* Invalid */
187 return (3 << 8) | (1 << 2);
188 case 1: /* PDE, should not happen */
189 case 3: /* Reserved */
190 return (3 << 8) | (4 << 2);
192 virt_addr
= address
& TARGET_PAGE_MASK
;
193 page_offset
= (address
& TARGET_PAGE_MASK
) & (TARGET_PAGE_SIZE
- 1);
197 virt_addr
= address
& ~0x3ffff;
198 page_offset
= address
& 0x3ffff;
202 virt_addr
= address
& ~0xffffff;
203 page_offset
= address
& 0xffffff;
207 /* update page modified and dirty bits */
208 is_dirty
= (rw
& 1) && !(pde
& PG_MODIFIED_MASK
);
209 if (!(pde
& PG_ACCESSED_MASK
) || is_dirty
) {
210 pde
|= PG_ACCESSED_MASK
;
212 pde
|= PG_MODIFIED_MASK
;
213 stl_phys_notdirty(pde_ptr
, pde
);
216 access_perms
= (pde
& PTE_ACCESS_MASK
) >> PTE_ACCESS_SHIFT
;
217 error_code
= access_table
[*access_index
][access_perms
];
218 if (error_code
&& !((env
->mmuregs
[0] & MMU_NF
) && is_user
))
221 /* the page can be put in the TLB */
222 *prot
= perm_table
[is_user
][access_perms
];
223 if (!(pde
& PG_MODIFIED_MASK
)) {
224 /* only set write access if already dirty... otherwise wait
226 *prot
&= ~PAGE_WRITE
;
229 /* Even if large ptes, we map only one 4KB page in the cache to
230 avoid filling it too fast */
231 *physical
= ((target_phys_addr_t
)(pde
& PTE_ADDR_MASK
) << 4) + page_offset
;
235 /* Perform address translation */
236 int cpu_sparc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
237 int mmu_idx
, int is_softmmu
)
239 target_phys_addr_t paddr
;
241 int error_code
= 0, prot
, ret
= 0, access_index
;
243 error_code
= get_physical_address(env
, &paddr
, &prot
, &access_index
, address
, rw
, mmu_idx
);
244 if (error_code
== 0) {
245 vaddr
= address
& TARGET_PAGE_MASK
;
246 paddr
&= TARGET_PAGE_MASK
;
248 printf("Translate at " TARGET_FMT_lx
" -> " TARGET_FMT_plx
", vaddr "
249 TARGET_FMT_lx
"\n", address
, paddr
, vaddr
);
251 ret
= tlb_set_page_exec(env
, vaddr
, paddr
, prot
, mmu_idx
, is_softmmu
);
255 if (env
->mmuregs
[3]) /* Fault status register */
256 env
->mmuregs
[3] = 1; /* overflow (not read before another fault) */
257 env
->mmuregs
[3] |= (access_index
<< 5) | error_code
| 2;
258 env
->mmuregs
[4] = address
; /* Fault address register */
260 if ((env
->mmuregs
[0] & MMU_NF
) || env
->psret
== 0) {
261 // No fault mode: if a mapping is available, just override
262 // permissions. If no mapping is available, redirect accesses to
263 // neverland. Fake/overridden mappings will be flushed when
264 // switching to normal mode.
265 vaddr
= address
& TARGET_PAGE_MASK
;
266 prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
267 ret
= tlb_set_page_exec(env
, vaddr
, paddr
, prot
, mmu_idx
, is_softmmu
);
271 env
->exception_index
= TT_TFAULT
;
273 env
->exception_index
= TT_DFAULT
;
278 target_ulong
mmu_probe(CPUState
*env
, target_ulong address
, int mmulev
)
280 target_phys_addr_t pde_ptr
;
283 /* Context base + context number */
284 pde_ptr
= (target_phys_addr_t
)(env
->mmuregs
[1] << 4) +
285 (env
->mmuregs
[2] << 2);
286 pde
= ldl_phys(pde_ptr
);
288 switch (pde
& PTE_ENTRYTYPE_MASK
) {
290 case 0: /* Invalid */
291 case 2: /* PTE, maybe should not happen? */
292 case 3: /* Reserved */
297 pde_ptr
= ((address
>> 22) & ~3) + ((pde
& ~3) << 4);
298 pde
= ldl_phys(pde_ptr
);
300 switch (pde
& PTE_ENTRYTYPE_MASK
) {
302 case 0: /* Invalid */
303 case 3: /* Reserved */
310 pde_ptr
= ((address
& 0xfc0000) >> 16) + ((pde
& ~3) << 4);
311 pde
= ldl_phys(pde_ptr
);
313 switch (pde
& PTE_ENTRYTYPE_MASK
) {
315 case 0: /* Invalid */
316 case 3: /* Reserved */
323 pde_ptr
= ((address
& 0x3f000) >> 10) + ((pde
& ~3) << 4);
324 pde
= ldl_phys(pde_ptr
);
326 switch (pde
& PTE_ENTRYTYPE_MASK
) {
328 case 0: /* Invalid */
329 case 1: /* PDE, should not happen */
330 case 3: /* Reserved */
342 void dump_mmu(CPUState
*env
)
344 target_ulong va
, va1
, va2
;
345 unsigned int n
, m
, o
;
346 target_phys_addr_t pde_ptr
, pa
;
349 printf("MMU dump:\n");
350 pde_ptr
= (env
->mmuregs
[1] << 4) + (env
->mmuregs
[2] << 2);
351 pde
= ldl_phys(pde_ptr
);
352 printf("Root ptr: " TARGET_FMT_plx
", ctx: %d\n",
353 (target_phys_addr_t
)env
->mmuregs
[1] << 4, env
->mmuregs
[2]);
354 for (n
= 0, va
= 0; n
< 256; n
++, va
+= 16 * 1024 * 1024) {
355 pde
= mmu_probe(env
, va
, 2);
357 pa
= cpu_get_phys_page_debug(env
, va
);
358 printf("VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_plx
359 " PDE: " TARGET_FMT_lx
"\n", va
, pa
, pde
);
360 for (m
= 0, va1
= va
; m
< 64; m
++, va1
+= 256 * 1024) {
361 pde
= mmu_probe(env
, va1
, 1);
363 pa
= cpu_get_phys_page_debug(env
, va1
);
364 printf(" VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_plx
365 " PDE: " TARGET_FMT_lx
"\n", va1
, pa
, pde
);
366 for (o
= 0, va2
= va1
; o
< 64; o
++, va2
+= 4 * 1024) {
367 pde
= mmu_probe(env
, va2
, 0);
369 pa
= cpu_get_phys_page_debug(env
, va2
);
370 printf(" VA: " TARGET_FMT_lx
", PA: "
371 TARGET_FMT_plx
" PTE: " TARGET_FMT_lx
"\n",
379 printf("MMU dump ends\n");
381 #endif /* DEBUG_MMU */
383 #else /* !TARGET_SPARC64 */
385 * UltraSparc IIi I/DMMUs
387 static int get_physical_address_data(CPUState
*env
, target_phys_addr_t
*physical
, int *prot
,
388 int *access_index
, target_ulong address
, int rw
,
394 if ((env
->lsu
& DMMU_E
) == 0) { /* DMMU disabled */
396 *prot
= PAGE_READ
| PAGE_WRITE
;
400 for (i
= 0; i
< 64; i
++) {
401 switch ((env
->dtlb_tte
[i
] >> 61) & 3) {
404 mask
= 0xffffffffffffe000ULL
;
407 mask
= 0xffffffffffff0000ULL
;
410 mask
= 0xfffffffffff80000ULL
;
413 mask
= 0xffffffffffc00000ULL
;
416 // ctx match, vaddr match?
417 if (env
->dmmuregs
[1] == (env
->dtlb_tag
[i
] & 0x1fff) &&
418 (address
& mask
) == (env
->dtlb_tag
[i
] & ~0x1fffULL
)) {
420 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) == 0 ||
421 ((env
->dtlb_tte
[i
] & 0x4) && is_user
) ||
422 (!(env
->dtlb_tte
[i
] & 0x2) && (rw
== 1))) {
423 if (env
->dmmuregs
[3]) /* Fault status register */
424 env
->dmmuregs
[3] = 2; /* overflow (not read before another fault) */
425 env
->dmmuregs
[3] |= (is_user
<< 3) | ((rw
== 1) << 2) | 1;
426 env
->dmmuregs
[4] = address
; /* Fault address register */
427 env
->exception_index
= TT_DFAULT
;
429 printf("DFAULT at 0x%" PRIx64
"\n", address
);
433 *physical
= (env
->dtlb_tte
[i
] & mask
& 0x1fffffff000ULL
) + (address
& ~mask
& 0x1fffffff000ULL
);
435 if (env
->dtlb_tte
[i
] & 0x2)
441 printf("DMISS at 0x%" PRIx64
"\n", address
);
443 env
->exception_index
= TT_DMISS
;
447 static int get_physical_address_code(CPUState
*env
, target_phys_addr_t
*physical
, int *prot
,
448 int *access_index
, target_ulong address
, int rw
,
454 if ((env
->lsu
& IMMU_E
) == 0) { /* IMMU disabled */
460 for (i
= 0; i
< 64; i
++) {
461 switch ((env
->itlb_tte
[i
] >> 61) & 3) {
464 mask
= 0xffffffffffffe000ULL
;
467 mask
= 0xffffffffffff0000ULL
;
470 mask
= 0xfffffffffff80000ULL
;
473 mask
= 0xffffffffffc00000ULL
;
476 // ctx match, vaddr match?
477 if (env
->dmmuregs
[1] == (env
->itlb_tag
[i
] & 0x1fff) &&
478 (address
& mask
) == (env
->itlb_tag
[i
] & ~0x1fffULL
)) {
480 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) == 0 ||
481 ((env
->itlb_tte
[i
] & 0x4) && is_user
)) {
482 if (env
->immuregs
[3]) /* Fault status register */
483 env
->immuregs
[3] = 2; /* overflow (not read before another fault) */
484 env
->immuregs
[3] |= (is_user
<< 3) | 1;
485 env
->exception_index
= TT_TFAULT
;
487 printf("TFAULT at 0x%" PRIx64
"\n", address
);
491 *physical
= (env
->itlb_tte
[i
] & mask
& 0x1fffffff000ULL
) + (address
& ~mask
& 0x1fffffff000ULL
);
497 printf("TMISS at 0x%" PRIx64
"\n", address
);
499 env
->exception_index
= TT_TMISS
;
503 static int get_physical_address(CPUState
*env
, target_phys_addr_t
*physical
,
504 int *prot
, int *access_index
,
505 target_ulong address
, int rw
, int mmu_idx
)
507 int is_user
= mmu_idx
== MMU_USER_IDX
;
510 return get_physical_address_code(env
, physical
, prot
, access_index
, address
, rw
, is_user
);
512 return get_physical_address_data(env
, physical
, prot
, access_index
, address
, rw
, is_user
);
515 /* Perform address translation */
516 int cpu_sparc_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
517 int mmu_idx
, int is_softmmu
)
519 target_ulong virt_addr
, vaddr
;
520 target_phys_addr_t paddr
;
521 int error_code
= 0, prot
, ret
= 0, access_index
;
523 error_code
= get_physical_address(env
, &paddr
, &prot
, &access_index
, address
, rw
, mmu_idx
);
524 if (error_code
== 0) {
525 virt_addr
= address
& TARGET_PAGE_MASK
;
526 vaddr
= virt_addr
+ ((address
& TARGET_PAGE_MASK
) & (TARGET_PAGE_SIZE
- 1));
528 printf("Translate at 0x%" PRIx64
" -> 0x%" PRIx64
", vaddr 0x%" PRIx64
"\n", address
, paddr
, vaddr
);
530 ret
= tlb_set_page_exec(env
, vaddr
, paddr
, prot
, mmu_idx
, is_softmmu
);
538 void dump_mmu(CPUState
*env
)
543 printf("MMU contexts: Primary: %" PRId64
", Secondary: %" PRId64
"\n", env
->dmmuregs
[1], env
->dmmuregs
[2]);
544 if ((env
->lsu
& DMMU_E
) == 0) {
545 printf("DMMU disabled\n");
547 printf("DMMU dump:\n");
548 for (i
= 0; i
< 64; i
++) {
549 switch ((env
->dtlb_tte
[i
] >> 61) & 3) {
564 if ((env
->dtlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
565 printf("VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_lx
", %s, %s, %s, %s, ctx %" PRId64
"\n",
566 env
->dtlb_tag
[i
] & ~0x1fffULL
,
567 env
->dtlb_tte
[i
] & 0x1ffffffe000ULL
,
569 env
->dtlb_tte
[i
] & 0x4? "priv": "user",
570 env
->dtlb_tte
[i
] & 0x2? "RW": "RO",
571 env
->dtlb_tte
[i
] & 0x40? "locked": "unlocked",
572 env
->dtlb_tag
[i
] & 0x1fffULL
);
576 if ((env
->lsu
& IMMU_E
) == 0) {
577 printf("IMMU disabled\n");
579 printf("IMMU dump:\n");
580 for (i
= 0; i
< 64; i
++) {
581 switch ((env
->itlb_tte
[i
] >> 61) & 3) {
596 if ((env
->itlb_tte
[i
] & 0x8000000000000000ULL
) != 0) {
597 printf("VA: " TARGET_FMT_lx
", PA: " TARGET_FMT_lx
", %s, %s, %s, ctx %" PRId64
"\n",
598 env
->itlb_tag
[i
] & ~0x1fffULL
,
599 env
->itlb_tte
[i
] & 0x1ffffffe000ULL
,
601 env
->itlb_tte
[i
] & 0x4? "priv": "user",
602 env
->itlb_tte
[i
] & 0x40? "locked": "unlocked",
603 env
->itlb_tag
[i
] & 0x1fffULL
);
608 #endif /* DEBUG_MMU */
610 #endif /* TARGET_SPARC64 */
611 #endif /* !CONFIG_USER_ONLY */
614 #if defined(CONFIG_USER_ONLY)
615 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
621 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
623 target_phys_addr_t phys_addr
;
624 int prot
, access_index
;
626 if (get_physical_address(env
, &phys_addr
, &prot
, &access_index
, addr
, 2,
627 MMU_KERNEL_IDX
) != 0)
628 if (get_physical_address(env
, &phys_addr
, &prot
, &access_index
, addr
,
629 0, MMU_KERNEL_IDX
) != 0)
631 if (cpu_get_physical_page_desc(phys_addr
) == IO_MEM_UNASSIGNED
)
637 void memcpy32(target_ulong
*dst
, const target_ulong
*src
)
649 void helper_flush(target_ulong addr
)
652 tb_invalidate_page_range(addr
, addr
+ 8);
655 void cpu_reset(CPUSPARCState
*env
)
660 env
->regwptr
= env
->regbase
+ (env
->cwp
* 16);
661 #if defined(CONFIG_USER_ONLY)
662 env
->user_mode_only
= 1;
663 #ifdef TARGET_SPARC64
664 env
->cleanwin
= NWINDOWS
- 2;
665 env
->cansave
= NWINDOWS
- 2;
666 env
->pstate
= PS_RMO
| PS_PEF
| PS_IE
;
667 env
->asi
= 0x82; // Primary no-fault
673 #ifdef TARGET_SPARC64
674 env
->pstate
= PS_PRIV
;
675 env
->hpstate
= HS_PRIV
;
676 env
->pc
= 0x1fff0000000ULL
;
677 env
->tsptr
= &env
->ts
[env
->tl
];
680 env
->mmuregs
[0] &= ~(MMU_E
| MMU_NF
);
681 env
->mmuregs
[0] |= env
->mmu_bm
;
683 env
->npc
= env
->pc
+ 4;
687 CPUSPARCState
*cpu_sparc_init(const char *cpu_model
)
690 const sparc_def_t
*def
;
692 def
= cpu_sparc_find_by_name(cpu_model
);
696 env
= qemu_mallocz(sizeof(CPUSPARCState
));
700 env
->cpu_model_str
= cpu_model
;
701 env
->version
= def
->iu_version
;
702 env
->fsr
= def
->fpu_version
;
703 #if !defined(TARGET_SPARC64)
704 env
->mmu_bm
= def
->mmu_bm
;
705 env
->mmu_ctpr_mask
= def
->mmu_ctpr_mask
;
706 env
->mmu_cxr_mask
= def
->mmu_cxr_mask
;
707 env
->mmu_sfsr_mask
= def
->mmu_sfsr_mask
;
708 env
->mmu_trcr_mask
= def
->mmu_trcr_mask
;
709 env
->mmuregs
[0] |= def
->mmu_version
;
710 cpu_sparc_set_id(env
, 0);
713 gen_intermediate_code_init(env
);
720 void cpu_sparc_set_id(CPUSPARCState
*env
, unsigned int cpu
)
722 #if !defined(TARGET_SPARC64)
723 env
->mxccregs
[7] = ((cpu
+ 8) & 0xf) << 24;
727 static const sparc_def_t sparc_defs
[] = {
728 #ifdef TARGET_SPARC64
730 .name
= "Fujitsu Sparc64",
731 .iu_version
= ((0x04ULL
<< 48) | (0x02ULL
<< 32) | (0ULL << 24)
732 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
733 .fpu_version
= 0x00000000,
737 .name
= "Fujitsu Sparc64 III",
738 .iu_version
= ((0x04ULL
<< 48) | (0x03ULL
<< 32) | (0ULL << 24)
739 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
740 .fpu_version
= 0x00000000,
744 .name
= "Fujitsu Sparc64 IV",
745 .iu_version
= ((0x04ULL
<< 48) | (0x04ULL
<< 32) | (0ULL << 24)
746 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
747 .fpu_version
= 0x00000000,
751 .name
= "Fujitsu Sparc64 V",
752 .iu_version
= ((0x04ULL
<< 48) | (0x05ULL
<< 32) | (0x51ULL
<< 24)
753 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
754 .fpu_version
= 0x00000000,
758 .name
= "TI UltraSparc I",
759 .iu_version
= ((0x17ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)
760 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
761 .fpu_version
= 0x00000000,
765 .name
= "TI UltraSparc II",
766 .iu_version
= ((0x17ULL
<< 48) | (0x11ULL
<< 32) | (0x20ULL
<< 24)
767 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
768 .fpu_version
= 0x00000000,
772 .name
= "TI UltraSparc IIi",
773 .iu_version
= ((0x17ULL
<< 48) | (0x12ULL
<< 32) | (0x91ULL
<< 24)
774 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
775 .fpu_version
= 0x00000000,
779 .name
= "TI UltraSparc IIe",
780 .iu_version
= ((0x17ULL
<< 48) | (0x13ULL
<< 32) | (0x14ULL
<< 24)
781 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
782 .fpu_version
= 0x00000000,
786 .name
= "Sun UltraSparc III",
787 .iu_version
= ((0x3eULL
<< 48) | (0x14ULL
<< 32) | (0x34ULL
<< 24)
788 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
789 .fpu_version
= 0x00000000,
793 .name
= "Sun UltraSparc III Cu",
794 .iu_version
= ((0x3eULL
<< 48) | (0x15ULL
<< 32) | (0x41ULL
<< 24)
795 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
796 .fpu_version
= 0x00000000,
800 .name
= "Sun UltraSparc IIIi",
801 .iu_version
= ((0x3eULL
<< 48) | (0x16ULL
<< 32) | (0x34ULL
<< 24)
802 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
803 .fpu_version
= 0x00000000,
807 .name
= "Sun UltraSparc IV",
808 .iu_version
= ((0x3eULL
<< 48) | (0x18ULL
<< 32) | (0x31ULL
<< 24)
809 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
810 .fpu_version
= 0x00000000,
814 .name
= "Sun UltraSparc IV+",
815 .iu_version
= ((0x3eULL
<< 48) | (0x19ULL
<< 32) | (0x22ULL
<< 24)
816 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
817 .fpu_version
= 0x00000000,
821 .name
= "Sun UltraSparc IIIi+",
822 .iu_version
= ((0x3eULL
<< 48) | (0x22ULL
<< 32) | (0ULL << 24)
823 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
824 .fpu_version
= 0x00000000,
828 .name
= "NEC UltraSparc I",
829 .iu_version
= ((0x22ULL
<< 48) | (0x10ULL
<< 32) | (0x40ULL
<< 24)
830 | (MAXTL
<< 8) | (NWINDOWS
- 1)),
831 .fpu_version
= 0x00000000,
836 .name
= "Fujitsu MB86900",
837 .iu_version
= 0x00 << 24, /* Impl 0, ver 0 */
838 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
839 .mmu_version
= 0x00 << 24, /* Impl 0, ver 0 */
840 .mmu_bm
= 0x00004000,
841 .mmu_ctpr_mask
= 0x007ffff0,
842 .mmu_cxr_mask
= 0x0000003f,
843 .mmu_sfsr_mask
= 0xffffffff,
844 .mmu_trcr_mask
= 0xffffffff,
847 .name
= "Fujitsu MB86904",
848 .iu_version
= 0x04 << 24, /* Impl 0, ver 4 */
849 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
850 .mmu_version
= 0x04 << 24, /* Impl 0, ver 4 */
851 .mmu_bm
= 0x00004000,
852 .mmu_ctpr_mask
= 0x00ffffc0,
853 .mmu_cxr_mask
= 0x000000ff,
854 .mmu_sfsr_mask
= 0x00016fff,
855 .mmu_trcr_mask
= 0x00ffffff,
858 .name
= "Fujitsu MB86907",
859 .iu_version
= 0x05 << 24, /* Impl 0, ver 5 */
860 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
861 .mmu_version
= 0x05 << 24, /* Impl 0, ver 5 */
862 .mmu_bm
= 0x00004000,
863 .mmu_ctpr_mask
= 0xffffffc0,
864 .mmu_cxr_mask
= 0x000000ff,
865 .mmu_sfsr_mask
= 0x00016fff,
866 .mmu_trcr_mask
= 0xffffffff,
869 .name
= "LSI L64811",
870 .iu_version
= 0x10 << 24, /* Impl 1, ver 0 */
871 .fpu_version
= 1 << 17, /* FPU version 1 (LSI L64814) */
872 .mmu_version
= 0x10 << 24,
873 .mmu_bm
= 0x00004000,
874 .mmu_ctpr_mask
= 0x007ffff0,
875 .mmu_cxr_mask
= 0x0000003f,
876 .mmu_sfsr_mask
= 0xffffffff,
877 .mmu_trcr_mask
= 0xffffffff,
880 .name
= "Cypress CY7C601",
881 .iu_version
= 0x11 << 24, /* Impl 1, ver 1 */
882 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
883 .mmu_version
= 0x10 << 24,
884 .mmu_bm
= 0x00004000,
885 .mmu_ctpr_mask
= 0x007ffff0,
886 .mmu_cxr_mask
= 0x0000003f,
887 .mmu_sfsr_mask
= 0xffffffff,
888 .mmu_trcr_mask
= 0xffffffff,
891 .name
= "Cypress CY7C611",
892 .iu_version
= 0x13 << 24, /* Impl 1, ver 3 */
893 .fpu_version
= 3 << 17, /* FPU version 3 (Cypress CY7C602) */
894 .mmu_version
= 0x10 << 24,
895 .mmu_bm
= 0x00004000,
896 .mmu_ctpr_mask
= 0x007ffff0,
897 .mmu_cxr_mask
= 0x0000003f,
898 .mmu_sfsr_mask
= 0xffffffff,
899 .mmu_trcr_mask
= 0xffffffff,
902 .name
= "TI SuperSparc II",
903 .iu_version
= 0x40000000,
904 .fpu_version
= 0 << 17,
905 .mmu_version
= 0x04000000,
906 .mmu_bm
= 0x00002000,
907 .mmu_ctpr_mask
= 0xffffffc0,
908 .mmu_cxr_mask
= 0x0000ffff,
909 .mmu_sfsr_mask
= 0xffffffff,
910 .mmu_trcr_mask
= 0xffffffff,
913 .name
= "TI MicroSparc I",
914 .iu_version
= 0x41000000,
915 .fpu_version
= 4 << 17,
916 .mmu_version
= 0x41000000,
917 .mmu_bm
= 0x00004000,
918 .mmu_ctpr_mask
= 0x007ffff0,
919 .mmu_cxr_mask
= 0x0000003f,
920 .mmu_sfsr_mask
= 0x00016fff,
921 .mmu_trcr_mask
= 0x0000003f,
924 .name
= "TI MicroSparc II",
925 .iu_version
= 0x42000000,
926 .fpu_version
= 4 << 17,
927 .mmu_version
= 0x02000000,
928 .mmu_bm
= 0x00004000,
929 .mmu_ctpr_mask
= 0x00ffffc0,
930 .mmu_cxr_mask
= 0x000000ff,
931 .mmu_sfsr_mask
= 0x00016fff,
932 .mmu_trcr_mask
= 0x00ffffff,
935 .name
= "TI MicroSparc IIep",
936 .iu_version
= 0x42000000,
937 .fpu_version
= 4 << 17,
938 .mmu_version
= 0x04000000,
939 .mmu_bm
= 0x00004000,
940 .mmu_ctpr_mask
= 0x00ffffc0,
941 .mmu_cxr_mask
= 0x000000ff,
942 .mmu_sfsr_mask
= 0x00016bff,
943 .mmu_trcr_mask
= 0x00ffffff,
946 .name
= "TI SuperSparc 51",
947 .iu_version
= 0x43000000,
948 .fpu_version
= 0 << 17,
949 .mmu_version
= 0x04000000,
950 .mmu_bm
= 0x00002000,
951 .mmu_ctpr_mask
= 0xffffffc0,
952 .mmu_cxr_mask
= 0x0000ffff,
953 .mmu_sfsr_mask
= 0xffffffff,
954 .mmu_trcr_mask
= 0xffffffff,
957 .name
= "TI SuperSparc 61",
958 .iu_version
= 0x44000000,
959 .fpu_version
= 0 << 17,
960 .mmu_version
= 0x04000000,
961 .mmu_bm
= 0x00002000,
962 .mmu_ctpr_mask
= 0xffffffc0,
963 .mmu_cxr_mask
= 0x0000ffff,
964 .mmu_sfsr_mask
= 0xffffffff,
965 .mmu_trcr_mask
= 0xffffffff,
968 .name
= "Ross RT625",
969 .iu_version
= 0x1e000000,
970 .fpu_version
= 1 << 17,
971 .mmu_version
= 0x1e000000,
972 .mmu_bm
= 0x00004000,
973 .mmu_ctpr_mask
= 0x007ffff0,
974 .mmu_cxr_mask
= 0x0000003f,
975 .mmu_sfsr_mask
= 0xffffffff,
976 .mmu_trcr_mask
= 0xffffffff,
979 .name
= "Ross RT620",
980 .iu_version
= 0x1f000000,
981 .fpu_version
= 1 << 17,
982 .mmu_version
= 0x1f000000,
983 .mmu_bm
= 0x00004000,
984 .mmu_ctpr_mask
= 0x007ffff0,
985 .mmu_cxr_mask
= 0x0000003f,
986 .mmu_sfsr_mask
= 0xffffffff,
987 .mmu_trcr_mask
= 0xffffffff,
991 .iu_version
= 0x20000000,
992 .fpu_version
= 0 << 17, /* B5010/B5110/B5120/B5210 */
993 .mmu_version
= 0x20000000,
994 .mmu_bm
= 0x00004000,
995 .mmu_ctpr_mask
= 0x007ffff0,
996 .mmu_cxr_mask
= 0x0000003f,
997 .mmu_sfsr_mask
= 0xffffffff,
998 .mmu_trcr_mask
= 0xffffffff,
1001 .name
= "Matsushita MN10501",
1002 .iu_version
= 0x50000000,
1003 .fpu_version
= 0 << 17,
1004 .mmu_version
= 0x50000000,
1005 .mmu_bm
= 0x00004000,
1006 .mmu_ctpr_mask
= 0x007ffff0,
1007 .mmu_cxr_mask
= 0x0000003f,
1008 .mmu_sfsr_mask
= 0xffffffff,
1009 .mmu_trcr_mask
= 0xffffffff,
1012 .name
= "Weitek W8601",
1013 .iu_version
= 0x90 << 24, /* Impl 9, ver 0 */
1014 .fpu_version
= 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
1015 .mmu_version
= 0x10 << 24,
1016 .mmu_bm
= 0x00004000,
1017 .mmu_ctpr_mask
= 0x007ffff0,
1018 .mmu_cxr_mask
= 0x0000003f,
1019 .mmu_sfsr_mask
= 0xffffffff,
1020 .mmu_trcr_mask
= 0xffffffff,
1024 .iu_version
= 0xf2000000,
1025 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
1026 .mmu_version
= 0xf2000000,
1027 .mmu_bm
= 0x00004000,
1028 .mmu_ctpr_mask
= 0x007ffff0,
1029 .mmu_cxr_mask
= 0x0000003f,
1030 .mmu_sfsr_mask
= 0xffffffff,
1031 .mmu_trcr_mask
= 0xffffffff,
1035 .iu_version
= 0xf3000000,
1036 .fpu_version
= 4 << 17, /* FPU version 4 (Meiko) */
1037 .mmu_version
= 0xf3000000,
1038 .mmu_bm
= 0x00004000,
1039 .mmu_ctpr_mask
= 0x007ffff0,
1040 .mmu_cxr_mask
= 0x0000003f,
1041 .mmu_sfsr_mask
= 0xffffffff,
1042 .mmu_trcr_mask
= 0xffffffff,
1047 static const sparc_def_t
*cpu_sparc_find_by_name(const unsigned char *name
)
1051 for (i
= 0; i
< sizeof(sparc_defs
) / sizeof(sparc_def_t
); i
++) {
1052 if (strcasecmp(name
, sparc_defs
[i
].name
) == 0) {
1053 return &sparc_defs
[i
];
1059 void sparc_cpu_list (FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
1063 for (i
= 0; i
< sizeof(sparc_defs
) / sizeof(sparc_def_t
); i
++) {
1064 (*cpu_fprintf
)(f
, "Sparc %16s IU " TARGET_FMT_lx
" FPU %08x MMU %08x\n",
1066 sparc_defs
[i
].iu_version
,
1067 sparc_defs
[i
].fpu_version
,
1068 sparc_defs
[i
].mmu_version
);
1072 #define GET_FLAG(a,b) ((env->psr & a)?b:'-')
1074 void cpu_dump_state(CPUState
*env
, FILE *f
,
1075 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
1080 cpu_fprintf(f
, "pc: " TARGET_FMT_lx
" npc: " TARGET_FMT_lx
"\n", env
->pc
, env
->npc
);
1081 cpu_fprintf(f
, "General Registers:\n");
1082 for (i
= 0; i
< 4; i
++)
1083 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
1084 cpu_fprintf(f
, "\n");
1086 cpu_fprintf(f
, "%%g%c: " TARGET_FMT_lx
"\t", i
+ '0', env
->gregs
[i
]);
1087 cpu_fprintf(f
, "\nCurrent Register Window:\n");
1088 for (x
= 0; x
< 3; x
++) {
1089 for (i
= 0; i
< 4; i
++)
1090 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
1091 (x
== 0 ? 'o' : (x
== 1 ? 'l' : 'i')), i
,
1092 env
->regwptr
[i
+ x
* 8]);
1093 cpu_fprintf(f
, "\n");
1095 cpu_fprintf(f
, "%%%c%d: " TARGET_FMT_lx
"\t",
1096 (x
== 0 ? 'o' : x
== 1 ? 'l' : 'i'), i
,
1097 env
->regwptr
[i
+ x
* 8]);
1098 cpu_fprintf(f
, "\n");
1100 cpu_fprintf(f
, "\nFloating Point Registers:\n");
1101 for (i
= 0; i
< 32; i
++) {
1103 cpu_fprintf(f
, "%%f%02d:", i
);
1104 cpu_fprintf(f
, " %016lf", env
->fpr
[i
]);
1106 cpu_fprintf(f
, "\n");
1108 #ifdef TARGET_SPARC64
1109 cpu_fprintf(f
, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n",
1110 env
->pstate
, GET_CCR(env
), env
->asi
, env
->tl
, env
->fprs
);
1111 cpu_fprintf(f
, "cansave: %d canrestore: %d otherwin: %d wstate %d cleanwin %d cwp %d\n",
1112 env
->cansave
, env
->canrestore
, env
->otherwin
, env
->wstate
,
1113 env
->cleanwin
, NWINDOWS
- 1 - env
->cwp
);
1115 cpu_fprintf(f
, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", GET_PSR(env
),
1116 GET_FLAG(PSR_ZERO
, 'Z'), GET_FLAG(PSR_OVF
, 'V'),
1117 GET_FLAG(PSR_NEG
, 'N'), GET_FLAG(PSR_CARRY
, 'C'),
1118 env
->psrs
?'S':'-', env
->psrps
?'P':'-',
1119 env
->psret
?'E':'-', env
->wim
);
1121 cpu_fprintf(f
, "fsr: 0x%08x\n", GET_FSR32(env
));
1124 #ifdef TARGET_SPARC64
1125 #if !defined(CONFIG_USER_ONLY)
1126 #include "qemu-common.h"
1128 #include "qemu-timer.h"
1131 void helper_tick_set_count(void *opaque
, uint64_t count
)
1133 #if !defined(CONFIG_USER_ONLY)
1134 ptimer_set_count(opaque
, -count
);
1138 uint64_t helper_tick_get_count(void *opaque
)
1140 #if !defined(CONFIG_USER_ONLY)
1141 return -ptimer_get_count(opaque
);
1147 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
1149 #if !defined(CONFIG_USER_ONLY)
1150 ptimer_set_limit(opaque
, -limit
, 0);