1e8af50a3Sbellard /* 2e8af50a3Sbellard * sparc helpers 3e8af50a3Sbellard * 483469015Sbellard * Copyright (c) 2003-2005 Fabrice Bellard 5e8af50a3Sbellard * 6e8af50a3Sbellard * This library is free software; you can redistribute it and/or 7e8af50a3Sbellard * modify it under the terms of the GNU Lesser General Public 8e8af50a3Sbellard * License as published by the Free Software Foundation; either 9e8af50a3Sbellard * version 2 of the License, or (at your option) any later version. 10e8af50a3Sbellard * 11e8af50a3Sbellard * This library is distributed in the hope that it will be useful, 12e8af50a3Sbellard * but WITHOUT ANY WARRANTY; without even the implied warranty of 13e8af50a3Sbellard * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14e8af50a3Sbellard * Lesser General Public License for more details. 15e8af50a3Sbellard * 16e8af50a3Sbellard * You should have received a copy of the GNU Lesser General Public 178167ee88SBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18e8af50a3Sbellard */ 19ee5bbe38Sbellard #include <stdarg.h> 20ee5bbe38Sbellard #include <stdlib.h> 21ee5bbe38Sbellard #include <stdio.h> 22ee5bbe38Sbellard #include <string.h> 23ee5bbe38Sbellard #include <inttypes.h> 24ee5bbe38Sbellard #include <signal.h> 25ee5bbe38Sbellard 26ee5bbe38Sbellard #include "cpu.h" 27ee5bbe38Sbellard #include "exec-all.h" 28ca10f867Saurel32 #include "qemu-common.h" 29e8af50a3Sbellard 30e80cfcfcSbellard //#define DEBUG_MMU 3164a88d5dSblueswir1 //#define DEBUG_FEATURES 32e8af50a3Sbellard 33b8e9fc06SIgor V. Kovalenko #ifdef DEBUG_MMU 34b8e9fc06SIgor V. Kovalenko #define DPRINTF_MMU(fmt, ...) \ 35b8e9fc06SIgor V. Kovalenko do { printf("MMU: " fmt , ## __VA_ARGS__); } while (0) 36b8e9fc06SIgor V. Kovalenko #else 37b8e9fc06SIgor V. Kovalenko #define DPRINTF_MMU(fmt, ...) do {} while (0) 38b8e9fc06SIgor V. Kovalenko #endif 39b8e9fc06SIgor V. Kovalenko 4022548760Sblueswir1 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model); 41c48fcb47Sblueswir1 42e8af50a3Sbellard /* Sparc MMU emulation */ 43e8af50a3Sbellard 449d893301Sbellard #if defined(CONFIG_USER_ONLY) 459d893301Sbellard 4622548760Sblueswir1 int cpu_sparc_handle_mmu_fault(CPUState *env1, target_ulong address, int rw, 476ebbf390Sj_mayer int mmu_idx, int is_softmmu) 489d893301Sbellard { 49878d3096Sbellard if (rw & 2) 5022548760Sblueswir1 env1->exception_index = TT_TFAULT; 51878d3096Sbellard else 5222548760Sblueswir1 env1->exception_index = TT_DFAULT; 539d893301Sbellard return 1; 549d893301Sbellard } 559d893301Sbellard 569d893301Sbellard #else 57e8af50a3Sbellard 583475187dSbellard #ifndef TARGET_SPARC64 5983469015Sbellard /* 6083469015Sbellard * Sparc V8 Reference MMU (SRMMU) 6183469015Sbellard */ 62e8af50a3Sbellard static const int access_table[8][8] = { 63a764a566Sblueswir1 { 0, 0, 0, 0, 8, 0, 12, 12 }, 64a764a566Sblueswir1 { 0, 0, 0, 0, 8, 0, 0, 0 }, 65a764a566Sblueswir1 { 8, 8, 0, 0, 0, 8, 12, 12 }, 66a764a566Sblueswir1 { 8, 8, 0, 0, 0, 8, 0, 0 }, 67a764a566Sblueswir1 { 8, 0, 8, 0, 8, 8, 12, 12 }, 68a764a566Sblueswir1 { 8, 0, 8, 0, 8, 0, 8, 0 }, 69a764a566Sblueswir1 { 8, 8, 8, 0, 8, 8, 12, 12 }, 70a764a566Sblueswir1 { 8, 8, 8, 0, 8, 8, 8, 0 } 71e8af50a3Sbellard }; 72e8af50a3Sbellard 73227671c9Sbellard static const int perm_table[2][8] = { 74227671c9Sbellard { 75227671c9Sbellard PAGE_READ, 76227671c9Sbellard PAGE_READ | PAGE_WRITE, 77227671c9Sbellard PAGE_READ | PAGE_EXEC, 78227671c9Sbellard PAGE_READ | PAGE_WRITE | PAGE_EXEC, 79227671c9Sbellard PAGE_EXEC, 80227671c9Sbellard PAGE_READ | PAGE_WRITE, 81227671c9Sbellard PAGE_READ | PAGE_EXEC, 82227671c9Sbellard PAGE_READ | PAGE_WRITE | PAGE_EXEC 83227671c9Sbellard }, 84227671c9Sbellard { 85227671c9Sbellard PAGE_READ, 86227671c9Sbellard PAGE_READ | PAGE_WRITE, 87227671c9Sbellard PAGE_READ | PAGE_EXEC, 88227671c9Sbellard PAGE_READ | PAGE_WRITE | PAGE_EXEC, 89227671c9Sbellard PAGE_EXEC, 90227671c9Sbellard PAGE_READ, 91227671c9Sbellard 0, 92227671c9Sbellard 0, 93227671c9Sbellard } 94e8af50a3Sbellard }; 95e8af50a3Sbellard 96c227f099SAnthony Liguori static int get_physical_address(CPUState *env, target_phys_addr_t *physical, 97c48fcb47Sblueswir1 int *prot, int *access_index, 98d4c430a8SPaul Brook target_ulong address, int rw, int mmu_idx, 99d4c430a8SPaul Brook target_ulong *page_size) 100e8af50a3Sbellard { 101e80cfcfcSbellard int access_perms = 0; 102c227f099SAnthony Liguori target_phys_addr_t pde_ptr; 103af7bf89bSbellard uint32_t pde; 1046ebbf390Sj_mayer int error_code = 0, is_dirty, is_user; 105e80cfcfcSbellard unsigned long page_offset; 106e8af50a3Sbellard 1076ebbf390Sj_mayer is_user = mmu_idx == MMU_USER_IDX; 10840ce0a9aSblueswir1 109e8af50a3Sbellard if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */ 110d4c430a8SPaul Brook *page_size = TARGET_PAGE_SIZE; 11140ce0a9aSblueswir1 // Boot mode: instruction fetches are taken from PROM 1125578ceabSblueswir1 if (rw == 2 && (env->mmuregs[0] & env->def->mmu_bm)) { 11358a770f3Sblueswir1 *physical = env->prom_addr | (address & 0x7ffffULL); 11440ce0a9aSblueswir1 *prot = PAGE_READ | PAGE_EXEC; 11540ce0a9aSblueswir1 return 0; 11640ce0a9aSblueswir1 } 117e80cfcfcSbellard *physical = address; 118227671c9Sbellard *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; 119e80cfcfcSbellard return 0; 120e8af50a3Sbellard } 121e8af50a3Sbellard 1227483750dSbellard *access_index = ((rw & 1) << 2) | (rw & 2) | (is_user? 0 : 1); 1235dcb6b91Sblueswir1 *physical = 0xffffffffffff0000ULL; 1247483750dSbellard 125e8af50a3Sbellard /* SPARC reference MMU table walk: Context table->L1->L2->PTE */ 126e8af50a3Sbellard /* Context base + context number */ 1273deaeab7Sblueswir1 pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2); 12849be8030Sbellard pde = ldl_phys(pde_ptr); 129e8af50a3Sbellard 130e8af50a3Sbellard /* Ctx pde */ 131e8af50a3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 132e80cfcfcSbellard default: 133e8af50a3Sbellard case 0: /* Invalid */ 1347483750dSbellard return 1 << 2; 135e80cfcfcSbellard case 2: /* L0 PTE, maybe should not happen? */ 136e8af50a3Sbellard case 3: /* Reserved */ 1377483750dSbellard return 4 << 2; 138e80cfcfcSbellard case 1: /* L0 PDE */ 139e80cfcfcSbellard pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4); 14049be8030Sbellard pde = ldl_phys(pde_ptr); 141e80cfcfcSbellard 142e80cfcfcSbellard switch (pde & PTE_ENTRYTYPE_MASK) { 143e80cfcfcSbellard default: 144e80cfcfcSbellard case 0: /* Invalid */ 1457483750dSbellard return (1 << 8) | (1 << 2); 146e80cfcfcSbellard case 3: /* Reserved */ 1477483750dSbellard return (1 << 8) | (4 << 2); 148e8af50a3Sbellard case 1: /* L1 PDE */ 149e80cfcfcSbellard pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4); 15049be8030Sbellard pde = ldl_phys(pde_ptr); 151e8af50a3Sbellard 152e8af50a3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 153e80cfcfcSbellard default: 154e8af50a3Sbellard case 0: /* Invalid */ 1557483750dSbellard return (2 << 8) | (1 << 2); 156e8af50a3Sbellard case 3: /* Reserved */ 1577483750dSbellard return (2 << 8) | (4 << 2); 158e8af50a3Sbellard case 1: /* L2 PDE */ 159e80cfcfcSbellard pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4); 16049be8030Sbellard pde = ldl_phys(pde_ptr); 161e8af50a3Sbellard 162e8af50a3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 163e80cfcfcSbellard default: 164e8af50a3Sbellard case 0: /* Invalid */ 1657483750dSbellard return (3 << 8) | (1 << 2); 166e8af50a3Sbellard case 1: /* PDE, should not happen */ 167e8af50a3Sbellard case 3: /* Reserved */ 1687483750dSbellard return (3 << 8) | (4 << 2); 169e8af50a3Sbellard case 2: /* L3 PTE */ 17077f193daSblueswir1 page_offset = (address & TARGET_PAGE_MASK) & 17177f193daSblueswir1 (TARGET_PAGE_SIZE - 1); 172e8af50a3Sbellard } 173d4c430a8SPaul Brook *page_size = TARGET_PAGE_SIZE; 174e8af50a3Sbellard break; 175e8af50a3Sbellard case 2: /* L2 PTE */ 176e8af50a3Sbellard page_offset = address & 0x3ffff; 177d4c430a8SPaul Brook *page_size = 0x40000; 178e8af50a3Sbellard } 179e8af50a3Sbellard break; 180e8af50a3Sbellard case 2: /* L1 PTE */ 181e8af50a3Sbellard page_offset = address & 0xffffff; 182d4c430a8SPaul Brook *page_size = 0x1000000; 183e8af50a3Sbellard } 184e8af50a3Sbellard } 185e8af50a3Sbellard 186698235aaSArtyom Tarasenko /* check access */ 187698235aaSArtyom Tarasenko access_perms = (pde & PTE_ACCESS_MASK) >> PTE_ACCESS_SHIFT; 188698235aaSArtyom Tarasenko error_code = access_table[*access_index][access_perms]; 189698235aaSArtyom Tarasenko if (error_code && !((env->mmuregs[0] & MMU_NF) && is_user)) 190698235aaSArtyom Tarasenko return error_code; 191698235aaSArtyom Tarasenko 192e8af50a3Sbellard /* update page modified and dirty bits */ 193b769d8feSbellard is_dirty = (rw & 1) && !(pde & PG_MODIFIED_MASK); 194e8af50a3Sbellard if (!(pde & PG_ACCESSED_MASK) || is_dirty) { 195e8af50a3Sbellard pde |= PG_ACCESSED_MASK; 196e8af50a3Sbellard if (is_dirty) 197e8af50a3Sbellard pde |= PG_MODIFIED_MASK; 19849be8030Sbellard stl_phys_notdirty(pde_ptr, pde); 199e8af50a3Sbellard } 200e8af50a3Sbellard 201e8af50a3Sbellard /* the page can be put in the TLB */ 202227671c9Sbellard *prot = perm_table[is_user][access_perms]; 203227671c9Sbellard if (!(pde & PG_MODIFIED_MASK)) { 204e8af50a3Sbellard /* only set write access if already dirty... otherwise wait 205e8af50a3Sbellard for dirty access */ 206227671c9Sbellard *prot &= ~PAGE_WRITE; 207e8af50a3Sbellard } 208e8af50a3Sbellard 209e8af50a3Sbellard /* Even if large ptes, we map only one 4KB page in the cache to 210e8af50a3Sbellard avoid filling it too fast */ 211c227f099SAnthony Liguori *physical = ((target_phys_addr_t)(pde & PTE_ADDR_MASK) << 4) + page_offset; 2126f7e9aecSbellard return error_code; 213e80cfcfcSbellard } 214e80cfcfcSbellard 215e80cfcfcSbellard /* Perform address translation */ 216af7bf89bSbellard int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, 2176ebbf390Sj_mayer int mmu_idx, int is_softmmu) 218e80cfcfcSbellard { 219c227f099SAnthony Liguori target_phys_addr_t paddr; 2205dcb6b91Sblueswir1 target_ulong vaddr; 221d4c430a8SPaul Brook target_ulong page_size; 222d4c430a8SPaul Brook int error_code = 0, prot, access_index; 223e80cfcfcSbellard 22477f193daSblueswir1 error_code = get_physical_address(env, &paddr, &prot, &access_index, 225d4c430a8SPaul Brook address, rw, mmu_idx, &page_size); 226e80cfcfcSbellard if (error_code == 0) { 2279e61bde5Sbellard vaddr = address & TARGET_PAGE_MASK; 2289e61bde5Sbellard paddr &= TARGET_PAGE_MASK; 2299e61bde5Sbellard #ifdef DEBUG_MMU 2305dcb6b91Sblueswir1 printf("Translate at " TARGET_FMT_lx " -> " TARGET_FMT_plx ", vaddr " 2315dcb6b91Sblueswir1 TARGET_FMT_lx "\n", address, paddr, vaddr); 2329e61bde5Sbellard #endif 233d4c430a8SPaul Brook tlb_set_page(env, vaddr, paddr, prot, mmu_idx, page_size); 234d4c430a8SPaul Brook return 0; 235e80cfcfcSbellard } 236e8af50a3Sbellard 237e8af50a3Sbellard if (env->mmuregs[3]) /* Fault status register */ 238e8af50a3Sbellard env->mmuregs[3] = 1; /* overflow (not read before another fault) */ 2397483750dSbellard env->mmuregs[3] |= (access_index << 5) | error_code | 2; 240e8af50a3Sbellard env->mmuregs[4] = address; /* Fault address register */ 241e8af50a3Sbellard 242878d3096Sbellard if ((env->mmuregs[0] & MMU_NF) || env->psret == 0) { 2436f7e9aecSbellard // No fault mode: if a mapping is available, just override 2446f7e9aecSbellard // permissions. If no mapping is available, redirect accesses to 2456f7e9aecSbellard // neverland. Fake/overridden mappings will be flushed when 2466f7e9aecSbellard // switching to normal mode. 2477483750dSbellard vaddr = address & TARGET_PAGE_MASK; 248227671c9Sbellard prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; 249d4c430a8SPaul Brook tlb_set_page(env, vaddr, paddr, prot, mmu_idx, TARGET_PAGE_SIZE); 250d4c430a8SPaul Brook return 0; 2517483750dSbellard } else { 252878d3096Sbellard if (rw & 2) 253878d3096Sbellard env->exception_index = TT_TFAULT; 254878d3096Sbellard else 255878d3096Sbellard env->exception_index = TT_DFAULT; 256878d3096Sbellard return 1; 257e8af50a3Sbellard } 2587483750dSbellard } 25924741ef3Sbellard 26024741ef3Sbellard target_ulong mmu_probe(CPUState *env, target_ulong address, int mmulev) 26124741ef3Sbellard { 262c227f099SAnthony Liguori target_phys_addr_t pde_ptr; 26324741ef3Sbellard uint32_t pde; 26424741ef3Sbellard 26524741ef3Sbellard /* Context base + context number */ 266c227f099SAnthony Liguori pde_ptr = (target_phys_addr_t)(env->mmuregs[1] << 4) + 2675dcb6b91Sblueswir1 (env->mmuregs[2] << 2); 26824741ef3Sbellard pde = ldl_phys(pde_ptr); 26924741ef3Sbellard 27024741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 27124741ef3Sbellard default: 27224741ef3Sbellard case 0: /* Invalid */ 27324741ef3Sbellard case 2: /* PTE, maybe should not happen? */ 27424741ef3Sbellard case 3: /* Reserved */ 27524741ef3Sbellard return 0; 27624741ef3Sbellard case 1: /* L1 PDE */ 27724741ef3Sbellard if (mmulev == 3) 27824741ef3Sbellard return pde; 27924741ef3Sbellard pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4); 28024741ef3Sbellard pde = ldl_phys(pde_ptr); 28124741ef3Sbellard 28224741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 28324741ef3Sbellard default: 28424741ef3Sbellard case 0: /* Invalid */ 28524741ef3Sbellard case 3: /* Reserved */ 28624741ef3Sbellard return 0; 28724741ef3Sbellard case 2: /* L1 PTE */ 28824741ef3Sbellard return pde; 28924741ef3Sbellard case 1: /* L2 PDE */ 29024741ef3Sbellard if (mmulev == 2) 29124741ef3Sbellard return pde; 29224741ef3Sbellard pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4); 29324741ef3Sbellard pde = ldl_phys(pde_ptr); 29424741ef3Sbellard 29524741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 29624741ef3Sbellard default: 29724741ef3Sbellard case 0: /* Invalid */ 29824741ef3Sbellard case 3: /* Reserved */ 29924741ef3Sbellard return 0; 30024741ef3Sbellard case 2: /* L2 PTE */ 30124741ef3Sbellard return pde; 30224741ef3Sbellard case 1: /* L3 PDE */ 30324741ef3Sbellard if (mmulev == 1) 30424741ef3Sbellard return pde; 30524741ef3Sbellard pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4); 30624741ef3Sbellard pde = ldl_phys(pde_ptr); 30724741ef3Sbellard 30824741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 30924741ef3Sbellard default: 31024741ef3Sbellard case 0: /* Invalid */ 31124741ef3Sbellard case 1: /* PDE, should not happen */ 31224741ef3Sbellard case 3: /* Reserved */ 31324741ef3Sbellard return 0; 31424741ef3Sbellard case 2: /* L3 PTE */ 31524741ef3Sbellard return pde; 31624741ef3Sbellard } 31724741ef3Sbellard } 31824741ef3Sbellard } 31924741ef3Sbellard } 32024741ef3Sbellard return 0; 32124741ef3Sbellard } 32224741ef3Sbellard 323d41160a3SBlue Swirl void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUState *env) 32424741ef3Sbellard { 32524741ef3Sbellard target_ulong va, va1, va2; 32624741ef3Sbellard unsigned int n, m, o; 327c227f099SAnthony Liguori target_phys_addr_t pde_ptr, pa; 32824741ef3Sbellard uint32_t pde; 32924741ef3Sbellard 33024741ef3Sbellard pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2); 33124741ef3Sbellard pde = ldl_phys(pde_ptr); 332d41160a3SBlue Swirl (*cpu_fprintf)(f, "Root ptr: " TARGET_FMT_plx ", ctx: %d\n", 333c227f099SAnthony Liguori (target_phys_addr_t)env->mmuregs[1] << 4, env->mmuregs[2]); 33424741ef3Sbellard for (n = 0, va = 0; n < 256; n++, va += 16 * 1024 * 1024) { 3355dcb6b91Sblueswir1 pde = mmu_probe(env, va, 2); 3365dcb6b91Sblueswir1 if (pde) { 33724741ef3Sbellard pa = cpu_get_phys_page_debug(env, va); 338d41160a3SBlue Swirl (*cpu_fprintf)(f, "VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx 3395dcb6b91Sblueswir1 " PDE: " TARGET_FMT_lx "\n", va, pa, pde); 34024741ef3Sbellard for (m = 0, va1 = va; m < 64; m++, va1 += 256 * 1024) { 3415dcb6b91Sblueswir1 pde = mmu_probe(env, va1, 1); 3425dcb6b91Sblueswir1 if (pde) { 34324741ef3Sbellard pa = cpu_get_phys_page_debug(env, va1); 344d41160a3SBlue Swirl (*cpu_fprintf)(f, " VA: " TARGET_FMT_lx ", PA: " 345d41160a3SBlue Swirl TARGET_FMT_plx " PDE: " TARGET_FMT_lx "\n", 346d41160a3SBlue Swirl va1, pa, pde); 34724741ef3Sbellard for (o = 0, va2 = va1; o < 64; o++, va2 += 4 * 1024) { 3485dcb6b91Sblueswir1 pde = mmu_probe(env, va2, 0); 3495dcb6b91Sblueswir1 if (pde) { 35024741ef3Sbellard pa = cpu_get_phys_page_debug(env, va2); 351d41160a3SBlue Swirl (*cpu_fprintf)(f, " VA: " TARGET_FMT_lx ", PA: " 352d41160a3SBlue Swirl TARGET_FMT_plx " PTE: " 353d41160a3SBlue Swirl TARGET_FMT_lx "\n", 3545dcb6b91Sblueswir1 va2, pa, pde); 35524741ef3Sbellard } 35624741ef3Sbellard } 35724741ef3Sbellard } 35824741ef3Sbellard } 35924741ef3Sbellard } 36024741ef3Sbellard } 36124741ef3Sbellard } 36224741ef3Sbellard 36324741ef3Sbellard #else /* !TARGET_SPARC64 */ 364e8807b14SIgor Kovalenko 365e8807b14SIgor Kovalenko // 41 bit physical address space 366c227f099SAnthony Liguori static inline target_phys_addr_t ultrasparc_truncate_physical(uint64_t x) 367e8807b14SIgor Kovalenko { 368e8807b14SIgor Kovalenko return x & 0x1ffffffffffULL; 369e8807b14SIgor Kovalenko } 370e8807b14SIgor Kovalenko 37183469015Sbellard /* 37283469015Sbellard * UltraSparc IIi I/DMMUs 37383469015Sbellard */ 3743475187dSbellard 375536ba015SIgor Kovalenko // Returns true if TTE tag is valid and matches virtual address value in context 376536ba015SIgor Kovalenko // requires virtual address mask value calculated from TTE entry size 3776e8e7d4cSIgor Kovalenko static inline int ultrasparc_tag_match(SparcTLBEntry *tlb, 378536ba015SIgor Kovalenko uint64_t address, uint64_t context, 379299b520cSIgor V. Kovalenko target_phys_addr_t *physical) 380536ba015SIgor Kovalenko { 381536ba015SIgor Kovalenko uint64_t mask; 382536ba015SIgor Kovalenko 3836e8e7d4cSIgor Kovalenko switch ((tlb->tte >> 61) & 3) { 3843475187dSbellard default: 38583469015Sbellard case 0x0: // 8k 3863475187dSbellard mask = 0xffffffffffffe000ULL; 3873475187dSbellard break; 38883469015Sbellard case 0x1: // 64k 3893475187dSbellard mask = 0xffffffffffff0000ULL; 3903475187dSbellard break; 39183469015Sbellard case 0x2: // 512k 3923475187dSbellard mask = 0xfffffffffff80000ULL; 3933475187dSbellard break; 39483469015Sbellard case 0x3: // 4M 3953475187dSbellard mask = 0xffffffffffc00000ULL; 3963475187dSbellard break; 3973475187dSbellard } 398536ba015SIgor Kovalenko 399536ba015SIgor Kovalenko // valid, context match, virtual address match? 400f707726eSIgor Kovalenko if (TTE_IS_VALID(tlb->tte) && 401299b520cSIgor V. Kovalenko (TTE_IS_GLOBAL(tlb->tte) || tlb_compare_context(tlb, context)) 4022a90358fSBlue Swirl && compare_masked(address, tlb->tag, mask)) 403536ba015SIgor Kovalenko { 404536ba015SIgor Kovalenko // decode physical address 4056e8e7d4cSIgor Kovalenko *physical = ((tlb->tte & mask) | (address & ~mask)) & 0x1ffffffe000ULL; 406536ba015SIgor Kovalenko return 1; 407536ba015SIgor Kovalenko } 408536ba015SIgor Kovalenko 409536ba015SIgor Kovalenko return 0; 410536ba015SIgor Kovalenko } 411536ba015SIgor Kovalenko 412536ba015SIgor Kovalenko static int get_physical_address_data(CPUState *env, 413c227f099SAnthony Liguori target_phys_addr_t *physical, int *prot, 4142065061eSIgor V. Kovalenko target_ulong address, int rw, int mmu_idx) 415536ba015SIgor Kovalenko { 416536ba015SIgor Kovalenko unsigned int i; 417536ba015SIgor Kovalenko uint64_t context; 418536ba015SIgor Kovalenko 4192065061eSIgor V. Kovalenko int is_user = (mmu_idx == MMU_USER_IDX || 4202065061eSIgor V. Kovalenko mmu_idx == MMU_USER_SECONDARY_IDX); 4212065061eSIgor V. Kovalenko 422536ba015SIgor Kovalenko if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */ 423536ba015SIgor Kovalenko *physical = ultrasparc_truncate_physical(address); 424536ba015SIgor Kovalenko *prot = PAGE_READ | PAGE_WRITE; 425536ba015SIgor Kovalenko return 0; 426536ba015SIgor Kovalenko } 427536ba015SIgor Kovalenko 4282065061eSIgor V. Kovalenko switch(mmu_idx) { 4292065061eSIgor V. Kovalenko case MMU_USER_IDX: 4302065061eSIgor V. Kovalenko case MMU_KERNEL_IDX: 4316e8e7d4cSIgor Kovalenko context = env->dmmu.mmu_primary_context & 0x1fff; 4322065061eSIgor V. Kovalenko break; 4332065061eSIgor V. Kovalenko case MMU_USER_SECONDARY_IDX: 4342065061eSIgor V. Kovalenko case MMU_KERNEL_SECONDARY_IDX: 4352065061eSIgor V. Kovalenko context = env->dmmu.mmu_secondary_context & 0x1fff; 4362065061eSIgor V. Kovalenko break; 4372065061eSIgor V. Kovalenko case MMU_NUCLEUS_IDX: 43844505216SBlue Swirl default: 439299b520cSIgor V. Kovalenko context = 0; 4402065061eSIgor V. Kovalenko break; 441299b520cSIgor V. Kovalenko } 442536ba015SIgor Kovalenko 443536ba015SIgor Kovalenko for (i = 0; i < 64; i++) { 444afdf8109Sblueswir1 // ctx match, vaddr match, valid? 445b8e9fc06SIgor V. Kovalenko if (ultrasparc_tag_match(&env->dtlb[i], address, context, physical)) { 446b8e9fc06SIgor V. Kovalenko 4476e8e7d4cSIgor Kovalenko uint8_t fault_type = 0; 4486e8e7d4cSIgor Kovalenko 449b8e9fc06SIgor V. Kovalenko // access ok? 4506e8e7d4cSIgor Kovalenko if ((env->dtlb[i].tte & 0x4) && is_user) { 4516e8e7d4cSIgor Kovalenko fault_type |= 1; /* privilege violation */ 452b8e9fc06SIgor V. Kovalenko env->exception_index = TT_DFAULT; 453b8e9fc06SIgor V. Kovalenko 454b8e9fc06SIgor V. Kovalenko DPRINTF_MMU("DFAULT at %" PRIx64 " context %" PRIx64 455b8e9fc06SIgor V. Kovalenko " mmu_idx=%d tl=%d\n", 456b8e9fc06SIgor V. Kovalenko address, context, mmu_idx, env->tl); 457b8e9fc06SIgor V. Kovalenko } else if (!(env->dtlb[i].tte & 0x2) && (rw == 1)) { 458b8e9fc06SIgor V. Kovalenko env->exception_index = TT_DPROT; 459b8e9fc06SIgor V. Kovalenko 460b8e9fc06SIgor V. Kovalenko DPRINTF_MMU("DPROT at %" PRIx64 " context %" PRIx64 461b8e9fc06SIgor V. Kovalenko " mmu_idx=%d tl=%d\n", 462b8e9fc06SIgor V. Kovalenko address, context, mmu_idx, env->tl); 463b8e9fc06SIgor V. Kovalenko } else { 464b8e9fc06SIgor V. Kovalenko *prot = PAGE_READ; 465b8e9fc06SIgor V. Kovalenko if (env->dtlb[i].tte & 0x2) 466b8e9fc06SIgor V. Kovalenko *prot |= PAGE_WRITE; 467b8e9fc06SIgor V. Kovalenko 468b8e9fc06SIgor V. Kovalenko TTE_SET_USED(env->dtlb[i].tte); 469b8e9fc06SIgor V. Kovalenko 470b8e9fc06SIgor V. Kovalenko return 0; 4716e8e7d4cSIgor Kovalenko } 4726e8e7d4cSIgor Kovalenko 4736e8e7d4cSIgor Kovalenko if (env->dmmu.sfsr & 1) /* Fault status register */ 4746e8e7d4cSIgor Kovalenko env->dmmu.sfsr = 2; /* overflow (not read before 47577f193daSblueswir1 another fault) */ 4766e8e7d4cSIgor Kovalenko 4776e8e7d4cSIgor Kovalenko env->dmmu.sfsr |= (is_user << 3) | ((rw == 1) << 2) | 1; 4786e8e7d4cSIgor Kovalenko 4796e8e7d4cSIgor Kovalenko env->dmmu.sfsr |= (fault_type << 7); 4806e8e7d4cSIgor Kovalenko 4816e8e7d4cSIgor Kovalenko env->dmmu.sfar = address; /* Fault address register */ 4829168b3a5SIgor V. Kovalenko 4839168b3a5SIgor V. Kovalenko env->dmmu.tag_access = (address & ~0x1fffULL) | context; 4849168b3a5SIgor V. Kovalenko 4853475187dSbellard return 1; 4863475187dSbellard } 4873475187dSbellard } 488b8e9fc06SIgor V. Kovalenko 489b8e9fc06SIgor V. Kovalenko DPRINTF_MMU("DMISS at %" PRIx64 " context %" PRIx64 "\n", 490b8e9fc06SIgor V. Kovalenko address, context); 491b8e9fc06SIgor V. Kovalenko 4926e8e7d4cSIgor Kovalenko env->dmmu.tag_access = (address & ~0x1fffULL) | context; 49383469015Sbellard env->exception_index = TT_DMISS; 4943475187dSbellard return 1; 4953475187dSbellard } 4963475187dSbellard 49777f193daSblueswir1 static int get_physical_address_code(CPUState *env, 498c227f099SAnthony Liguori target_phys_addr_t *physical, int *prot, 4992065061eSIgor V. Kovalenko target_ulong address, int mmu_idx) 5003475187dSbellard { 5013475187dSbellard unsigned int i; 502536ba015SIgor Kovalenko uint64_t context; 5033475187dSbellard 5042065061eSIgor V. Kovalenko int is_user = (mmu_idx == MMU_USER_IDX || 5052065061eSIgor V. Kovalenko mmu_idx == MMU_USER_SECONDARY_IDX); 5062065061eSIgor V. Kovalenko 507e8807b14SIgor Kovalenko if ((env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0) { 508e8807b14SIgor Kovalenko /* IMMU disabled */ 509e8807b14SIgor Kovalenko *physical = ultrasparc_truncate_physical(address); 510227671c9Sbellard *prot = PAGE_EXEC; 5113475187dSbellard return 0; 5123475187dSbellard } 51383469015Sbellard 514299b520cSIgor V. Kovalenko if (env->tl == 0) { 5152065061eSIgor V. Kovalenko /* PRIMARY context */ 5166e8e7d4cSIgor Kovalenko context = env->dmmu.mmu_primary_context & 0x1fff; 517299b520cSIgor V. Kovalenko } else { 5182065061eSIgor V. Kovalenko /* NUCLEUS context */ 519299b520cSIgor V. Kovalenko context = 0; 520299b520cSIgor V. Kovalenko } 521536ba015SIgor Kovalenko 5223475187dSbellard for (i = 0; i < 64; i++) { 523afdf8109Sblueswir1 // ctx match, vaddr match, valid? 5246e8e7d4cSIgor Kovalenko if (ultrasparc_tag_match(&env->itlb[i], 525299b520cSIgor V. Kovalenko address, context, physical)) { 526afdf8109Sblueswir1 // access ok? 5276e8e7d4cSIgor Kovalenko if ((env->itlb[i].tte & 0x4) && is_user) { 5286e8e7d4cSIgor Kovalenko if (env->immu.sfsr) /* Fault status register */ 5296e8e7d4cSIgor Kovalenko env->immu.sfsr = 2; /* overflow (not read before 53077f193daSblueswir1 another fault) */ 5316e8e7d4cSIgor Kovalenko env->immu.sfsr |= (is_user << 3) | 1; 5323475187dSbellard env->exception_index = TT_TFAULT; 533b8e9fc06SIgor V. Kovalenko 5349168b3a5SIgor V. Kovalenko env->immu.tag_access = (address & ~0x1fffULL) | context; 5359168b3a5SIgor V. Kovalenko 536b8e9fc06SIgor V. Kovalenko DPRINTF_MMU("TFAULT at %" PRIx64 " context %" PRIx64 "\n", 537b8e9fc06SIgor V. Kovalenko address, context); 538b8e9fc06SIgor V. Kovalenko 5393475187dSbellard return 1; 5403475187dSbellard } 541227671c9Sbellard *prot = PAGE_EXEC; 542f707726eSIgor Kovalenko TTE_SET_USED(env->itlb[i].tte); 5433475187dSbellard return 0; 5443475187dSbellard } 5453475187dSbellard } 546b8e9fc06SIgor V. Kovalenko 547b8e9fc06SIgor V. Kovalenko DPRINTF_MMU("TMISS at %" PRIx64 " context %" PRIx64 "\n", 548b8e9fc06SIgor V. Kovalenko address, context); 549b8e9fc06SIgor V. Kovalenko 5507ab463cbSBlue Swirl /* Context is stored in DMMU (dmmuregs[1]) also for IMMU */ 5516e8e7d4cSIgor Kovalenko env->immu.tag_access = (address & ~0x1fffULL) | context; 55283469015Sbellard env->exception_index = TT_TMISS; 5533475187dSbellard return 1; 5543475187dSbellard } 5553475187dSbellard 556c227f099SAnthony Liguori static int get_physical_address(CPUState *env, target_phys_addr_t *physical, 557c48fcb47Sblueswir1 int *prot, int *access_index, 558d4c430a8SPaul Brook target_ulong address, int rw, int mmu_idx, 559d4c430a8SPaul Brook target_ulong *page_size) 5603475187dSbellard { 561d4c430a8SPaul Brook /* ??? We treat everything as a small page, then explicitly flush 562d4c430a8SPaul Brook everything when an entry is evicted. */ 563d4c430a8SPaul Brook *page_size = TARGET_PAGE_SIZE; 5649fd1ae3aSIgor V. Kovalenko 5659fd1ae3aSIgor V. Kovalenko #if defined (DEBUG_MMU) 5669fd1ae3aSIgor V. Kovalenko /* safety net to catch wrong softmmu index use from dynamic code */ 5679fd1ae3aSIgor V. Kovalenko if (env->tl > 0 && mmu_idx != MMU_NUCLEUS_IDX) { 5689fd1ae3aSIgor V. Kovalenko DPRINTF_MMU("get_physical_address %s tl=%d mmu_idx=%d" 5699fd1ae3aSIgor V. Kovalenko " primary context=%" PRIx64 5709fd1ae3aSIgor V. Kovalenko " secondary context=%" PRIx64 5719fd1ae3aSIgor V. Kovalenko " address=%" PRIx64 5729fd1ae3aSIgor V. Kovalenko "\n", 5739fd1ae3aSIgor V. Kovalenko (rw == 2 ? "CODE" : "DATA"), 5749fd1ae3aSIgor V. Kovalenko env->tl, mmu_idx, 5759fd1ae3aSIgor V. Kovalenko env->dmmu.mmu_primary_context, 5769fd1ae3aSIgor V. Kovalenko env->dmmu.mmu_secondary_context, 5779fd1ae3aSIgor V. Kovalenko address); 5789fd1ae3aSIgor V. Kovalenko } 5799fd1ae3aSIgor V. Kovalenko #endif 5809fd1ae3aSIgor V. Kovalenko 5813475187dSbellard if (rw == 2) 58222548760Sblueswir1 return get_physical_address_code(env, physical, prot, address, 5832065061eSIgor V. Kovalenko mmu_idx); 5843475187dSbellard else 58522548760Sblueswir1 return get_physical_address_data(env, physical, prot, address, rw, 5862065061eSIgor V. Kovalenko mmu_idx); 5873475187dSbellard } 5883475187dSbellard 5893475187dSbellard /* Perform address translation */ 5903475187dSbellard int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, 5916ebbf390Sj_mayer int mmu_idx, int is_softmmu) 5923475187dSbellard { 59383469015Sbellard target_ulong virt_addr, vaddr; 594c227f099SAnthony Liguori target_phys_addr_t paddr; 595d4c430a8SPaul Brook target_ulong page_size; 596d4c430a8SPaul Brook int error_code = 0, prot, access_index; 5973475187dSbellard 59877f193daSblueswir1 error_code = get_physical_address(env, &paddr, &prot, &access_index, 599d4c430a8SPaul Brook address, rw, mmu_idx, &page_size); 6003475187dSbellard if (error_code == 0) { 6013475187dSbellard virt_addr = address & TARGET_PAGE_MASK; 60277f193daSblueswir1 vaddr = virt_addr + ((address & TARGET_PAGE_MASK) & 60377f193daSblueswir1 (TARGET_PAGE_SIZE - 1)); 604b8e9fc06SIgor V. Kovalenko 605b8e9fc06SIgor V. Kovalenko DPRINTF_MMU("Translate at %" PRIx64 " -> %" PRIx64 "," 606b8e9fc06SIgor V. Kovalenko " vaddr %" PRIx64 607b8e9fc06SIgor V. Kovalenko " mmu_idx=%d" 608b8e9fc06SIgor V. Kovalenko " tl=%d" 609b8e9fc06SIgor V. Kovalenko " primary context=%" PRIx64 610b8e9fc06SIgor V. Kovalenko " secondary context=%" PRIx64 611b8e9fc06SIgor V. Kovalenko "\n", 612b8e9fc06SIgor V. Kovalenko address, paddr, vaddr, mmu_idx, env->tl, 613b8e9fc06SIgor V. Kovalenko env->dmmu.mmu_primary_context, 614b8e9fc06SIgor V. Kovalenko env->dmmu.mmu_secondary_context); 615b8e9fc06SIgor V. Kovalenko 616d4c430a8SPaul Brook tlb_set_page(env, vaddr, paddr, prot, mmu_idx, page_size); 617d4c430a8SPaul Brook return 0; 6183475187dSbellard } 6193475187dSbellard // XXX 6203475187dSbellard return 1; 6213475187dSbellard } 6223475187dSbellard 623d41160a3SBlue Swirl void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUState *env) 62483469015Sbellard { 62583469015Sbellard unsigned int i; 62683469015Sbellard const char *mask; 62783469015Sbellard 628d41160a3SBlue Swirl (*cpu_fprintf)(f, "MMU contexts: Primary: %" PRId64 ", Secondary: %" 629d41160a3SBlue Swirl PRId64 "\n", 630d41160a3SBlue Swirl env->dmmu.mmu_primary_context, 631d41160a3SBlue Swirl env->dmmu.mmu_secondary_context); 63283469015Sbellard if ((env->lsu & DMMU_E) == 0) { 633d41160a3SBlue Swirl (*cpu_fprintf)(f, "DMMU disabled\n"); 63483469015Sbellard } else { 635d41160a3SBlue Swirl (*cpu_fprintf)(f, "DMMU dump\n"); 63683469015Sbellard for (i = 0; i < 64; i++) { 63731a68d57SBlue Swirl switch ((env->dtlb[i].tte >> 61) & 3) { 63883469015Sbellard default: 63983469015Sbellard case 0x0: 64083469015Sbellard mask = " 8k"; 64183469015Sbellard break; 64283469015Sbellard case 0x1: 64383469015Sbellard mask = " 64k"; 64483469015Sbellard break; 64583469015Sbellard case 0x2: 64683469015Sbellard mask = "512k"; 64783469015Sbellard break; 64883469015Sbellard case 0x3: 64983469015Sbellard mask = " 4M"; 65083469015Sbellard break; 65183469015Sbellard } 65231a68d57SBlue Swirl if ((env->dtlb[i].tte & 0x8000000000000000ULL) != 0) { 653d41160a3SBlue Swirl (*cpu_fprintf)(f, "[%02u] VA: %" PRIx64 ", PA: %" PRIx64 6542a90358fSBlue Swirl ", %s, %s, %s, %s, ctx %" PRId64 " %s\n", 6556e8e7d4cSIgor Kovalenko i, 65631a68d57SBlue Swirl env->dtlb[i].tag & (uint64_t)~0x1fffULL, 65731a68d57SBlue Swirl env->dtlb[i].tte & (uint64_t)0x1ffffffe000ULL, 65883469015Sbellard mask, 65931a68d57SBlue Swirl env->dtlb[i].tte & 0x4? "priv": "user", 66031a68d57SBlue Swirl env->dtlb[i].tte & 0x2? "RW": "RO", 66131a68d57SBlue Swirl env->dtlb[i].tte & 0x40? "locked": "unlocked", 6622a90358fSBlue Swirl env->dtlb[i].tag & (uint64_t)0x1fffULL, 663d41160a3SBlue Swirl TTE_IS_GLOBAL(env->dtlb[i].tte)? 664d41160a3SBlue Swirl "global" : "local"); 66583469015Sbellard } 66683469015Sbellard } 66783469015Sbellard } 66883469015Sbellard if ((env->lsu & IMMU_E) == 0) { 669d41160a3SBlue Swirl (*cpu_fprintf)(f, "IMMU disabled\n"); 67083469015Sbellard } else { 671d41160a3SBlue Swirl (*cpu_fprintf)(f, "IMMU dump\n"); 67283469015Sbellard for (i = 0; i < 64; i++) { 67331a68d57SBlue Swirl switch ((env->itlb[i].tte >> 61) & 3) { 67483469015Sbellard default: 67583469015Sbellard case 0x0: 67683469015Sbellard mask = " 8k"; 67783469015Sbellard break; 67883469015Sbellard case 0x1: 67983469015Sbellard mask = " 64k"; 68083469015Sbellard break; 68183469015Sbellard case 0x2: 68283469015Sbellard mask = "512k"; 68383469015Sbellard break; 68483469015Sbellard case 0x3: 68583469015Sbellard mask = " 4M"; 68683469015Sbellard break; 68783469015Sbellard } 68831a68d57SBlue Swirl if ((env->itlb[i].tte & 0x8000000000000000ULL) != 0) { 689d41160a3SBlue Swirl (*cpu_fprintf)(f, "[%02u] VA: %" PRIx64 ", PA: %" PRIx64 6902a90358fSBlue Swirl ", %s, %s, %s, ctx %" PRId64 " %s\n", 6916e8e7d4cSIgor Kovalenko i, 6926e8e7d4cSIgor Kovalenko env->itlb[i].tag & (uint64_t)~0x1fffULL, 69331a68d57SBlue Swirl env->itlb[i].tte & (uint64_t)0x1ffffffe000ULL, 69483469015Sbellard mask, 69531a68d57SBlue Swirl env->itlb[i].tte & 0x4? "priv": "user", 69631a68d57SBlue Swirl env->itlb[i].tte & 0x40? "locked": "unlocked", 6972a90358fSBlue Swirl env->itlb[i].tag & (uint64_t)0x1fffULL, 698d41160a3SBlue Swirl TTE_IS_GLOBAL(env->itlb[i].tte)? 699d41160a3SBlue Swirl "global" : "local"); 70083469015Sbellard } 70183469015Sbellard } 70283469015Sbellard } 70383469015Sbellard } 70424741ef3Sbellard 70524741ef3Sbellard #endif /* TARGET_SPARC64 */ 70624741ef3Sbellard #endif /* !CONFIG_USER_ONLY */ 70724741ef3Sbellard 708c48fcb47Sblueswir1 7094fcc562bSPaul Brook #if !defined(CONFIG_USER_ONLY) 7102065061eSIgor V. Kovalenko target_phys_addr_t cpu_get_phys_page_nofault(CPUState *env, target_ulong addr, 7112065061eSIgor V. Kovalenko int mmu_idx) 712c48fcb47Sblueswir1 { 713c227f099SAnthony Liguori target_phys_addr_t phys_addr; 714d4c430a8SPaul Brook target_ulong page_size; 715c48fcb47Sblueswir1 int prot, access_index; 716c48fcb47Sblueswir1 717c48fcb47Sblueswir1 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2, 7182065061eSIgor V. Kovalenko mmu_idx, &page_size) != 0) 719c48fcb47Sblueswir1 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 7202065061eSIgor V. Kovalenko 0, mmu_idx, &page_size) != 0) 721c48fcb47Sblueswir1 return -1; 722c48fcb47Sblueswir1 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED) 723c48fcb47Sblueswir1 return -1; 724c48fcb47Sblueswir1 return phys_addr; 725c48fcb47Sblueswir1 } 7262065061eSIgor V. Kovalenko 7272065061eSIgor V. Kovalenko target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) 7282065061eSIgor V. Kovalenko { 7299fd1ae3aSIgor V. Kovalenko return cpu_get_phys_page_nofault(env, addr, cpu_mmu_index(env)); 7302065061eSIgor V. Kovalenko } 731c48fcb47Sblueswir1 #endif 732c48fcb47Sblueswir1 733c48fcb47Sblueswir1 void cpu_reset(CPUSPARCState *env) 734c48fcb47Sblueswir1 { 735eca1bdf4Saliguori if (qemu_loglevel_mask(CPU_LOG_RESET)) { 736eca1bdf4Saliguori qemu_log("CPU Reset (CPU %d)\n", env->cpu_index); 737eca1bdf4Saliguori log_cpu_state(env, 0); 738eca1bdf4Saliguori } 739eca1bdf4Saliguori 740c48fcb47Sblueswir1 tlb_flush(env, 1); 741c48fcb47Sblueswir1 env->cwp = 0; 7425210977aSIgor Kovalenko #ifndef TARGET_SPARC64 743c48fcb47Sblueswir1 env->wim = 1; 7445210977aSIgor Kovalenko #endif 745c48fcb47Sblueswir1 env->regwptr = env->regbase + (env->cwp * 16); 7466b743278SBlue Swirl CC_OP = CC_OP_FLAGS; 747c48fcb47Sblueswir1 #if defined(CONFIG_USER_ONLY) 748c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 7491a14026eSblueswir1 env->cleanwin = env->nwindows - 2; 7501a14026eSblueswir1 env->cansave = env->nwindows - 2; 751c48fcb47Sblueswir1 env->pstate = PS_RMO | PS_PEF | PS_IE; 752c48fcb47Sblueswir1 env->asi = 0x82; // Primary no-fault 753c48fcb47Sblueswir1 #endif 754c48fcb47Sblueswir1 #else 7555210977aSIgor Kovalenko #if !defined(TARGET_SPARC64) 756c48fcb47Sblueswir1 env->psret = 0; 757c48fcb47Sblueswir1 env->psrs = 1; 758c48fcb47Sblueswir1 env->psrps = 1; 7592aae2b8eSIgor V. Kovalenko #endif 760c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 7618194f35aSIgor Kovalenko env->pstate = PS_PRIV|PS_RED|PS_PEF|PS_AG; 7622aae2b8eSIgor V. Kovalenko env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0; 7638194f35aSIgor Kovalenko env->tl = env->maxtl; 7648194f35aSIgor Kovalenko cpu_tsptr(env)->tt = TT_POWER_ON_RESET; 765415fc906Sblueswir1 env->lsu = 0; 766c48fcb47Sblueswir1 #else 767c48fcb47Sblueswir1 env->mmuregs[0] &= ~(MMU_E | MMU_NF); 7685578ceabSblueswir1 env->mmuregs[0] |= env->def->mmu_bm; 769c48fcb47Sblueswir1 #endif 770e87231d4Sblueswir1 env->pc = 0; 771c48fcb47Sblueswir1 env->npc = env->pc + 4; 772c48fcb47Sblueswir1 #endif 773c48fcb47Sblueswir1 } 774c48fcb47Sblueswir1 77564a88d5dSblueswir1 static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model) 776c48fcb47Sblueswir1 { 77764a88d5dSblueswir1 sparc_def_t def1, *def = &def1; 778c48fcb47Sblueswir1 77964a88d5dSblueswir1 if (cpu_sparc_find_by_name(def, cpu_model) < 0) 78064a88d5dSblueswir1 return -1; 781c48fcb47Sblueswir1 7825578ceabSblueswir1 env->def = qemu_mallocz(sizeof(*def)); 7835578ceabSblueswir1 memcpy(env->def, def, sizeof(*def)); 7845578ceabSblueswir1 #if defined(CONFIG_USER_ONLY) 7855578ceabSblueswir1 if ((env->def->features & CPU_FEATURE_FLOAT)) 7865578ceabSblueswir1 env->def->features |= CPU_FEATURE_FLOAT128; 7875578ceabSblueswir1 #endif 788c48fcb47Sblueswir1 env->cpu_model_str = cpu_model; 789c48fcb47Sblueswir1 env->version = def->iu_version; 790c48fcb47Sblueswir1 env->fsr = def->fpu_version; 7911a14026eSblueswir1 env->nwindows = def->nwindows; 792c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64) 793c48fcb47Sblueswir1 env->mmuregs[0] |= def->mmu_version; 794c48fcb47Sblueswir1 cpu_sparc_set_id(env, 0); 795963262deSblueswir1 env->mxccregs[7] |= def->mxcc_version; 7961a14026eSblueswir1 #else 797fb79ceb9Sblueswir1 env->mmu_version = def->mmu_version; 798c19148bdSblueswir1 env->maxtl = def->maxtl; 799c19148bdSblueswir1 env->version |= def->maxtl << 8; 8001a14026eSblueswir1 env->version |= def->nwindows - 1; 801c48fcb47Sblueswir1 #endif 80264a88d5dSblueswir1 return 0; 80364a88d5dSblueswir1 } 80464a88d5dSblueswir1 80564a88d5dSblueswir1 static void cpu_sparc_close(CPUSPARCState *env) 80664a88d5dSblueswir1 { 8075578ceabSblueswir1 free(env->def); 80864a88d5dSblueswir1 free(env); 80964a88d5dSblueswir1 } 81064a88d5dSblueswir1 81164a88d5dSblueswir1 CPUSPARCState *cpu_sparc_init(const char *cpu_model) 81264a88d5dSblueswir1 { 81364a88d5dSblueswir1 CPUSPARCState *env; 81464a88d5dSblueswir1 81564a88d5dSblueswir1 env = qemu_mallocz(sizeof(CPUSPARCState)); 81664a88d5dSblueswir1 cpu_exec_init(env); 817c48fcb47Sblueswir1 818c48fcb47Sblueswir1 gen_intermediate_code_init(env); 819c48fcb47Sblueswir1 82064a88d5dSblueswir1 if (cpu_sparc_register(env, cpu_model) < 0) { 82164a88d5dSblueswir1 cpu_sparc_close(env); 82264a88d5dSblueswir1 return NULL; 82364a88d5dSblueswir1 } 8240bf46a40Saliguori qemu_init_vcpu(env); 825c48fcb47Sblueswir1 826c48fcb47Sblueswir1 return env; 827c48fcb47Sblueswir1 } 828c48fcb47Sblueswir1 829c48fcb47Sblueswir1 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu) 830c48fcb47Sblueswir1 { 831c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64) 832c48fcb47Sblueswir1 env->mxccregs[7] = ((cpu + 8) & 0xf) << 24; 833c48fcb47Sblueswir1 #endif 834c48fcb47Sblueswir1 } 835c48fcb47Sblueswir1 836c48fcb47Sblueswir1 static const sparc_def_t sparc_defs[] = { 837c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 838c48fcb47Sblueswir1 { 839c48fcb47Sblueswir1 .name = "Fujitsu Sparc64", 840c19148bdSblueswir1 .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)), 841c48fcb47Sblueswir1 .fpu_version = 0x00000000, 842fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 8431a14026eSblueswir1 .nwindows = 4, 844c19148bdSblueswir1 .maxtl = 4, 84564a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 846c48fcb47Sblueswir1 }, 847c48fcb47Sblueswir1 { 848c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 III", 849c19148bdSblueswir1 .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)), 850c48fcb47Sblueswir1 .fpu_version = 0x00000000, 851fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 8521a14026eSblueswir1 .nwindows = 5, 853c19148bdSblueswir1 .maxtl = 4, 85464a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 855c48fcb47Sblueswir1 }, 856c48fcb47Sblueswir1 { 857c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 IV", 858c19148bdSblueswir1 .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)), 859c48fcb47Sblueswir1 .fpu_version = 0x00000000, 860fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 8611a14026eSblueswir1 .nwindows = 8, 862c19148bdSblueswir1 .maxtl = 5, 86364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 864c48fcb47Sblueswir1 }, 865c48fcb47Sblueswir1 { 866c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 V", 867c19148bdSblueswir1 .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)), 868c48fcb47Sblueswir1 .fpu_version = 0x00000000, 869fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 8701a14026eSblueswir1 .nwindows = 8, 871c19148bdSblueswir1 .maxtl = 5, 87264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 873c48fcb47Sblueswir1 }, 874c48fcb47Sblueswir1 { 875c48fcb47Sblueswir1 .name = "TI UltraSparc I", 876c19148bdSblueswir1 .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)), 877c48fcb47Sblueswir1 .fpu_version = 0x00000000, 878fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 8791a14026eSblueswir1 .nwindows = 8, 880c19148bdSblueswir1 .maxtl = 5, 88164a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 882c48fcb47Sblueswir1 }, 883c48fcb47Sblueswir1 { 884c48fcb47Sblueswir1 .name = "TI UltraSparc II", 885c19148bdSblueswir1 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)), 886c48fcb47Sblueswir1 .fpu_version = 0x00000000, 887fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 8881a14026eSblueswir1 .nwindows = 8, 889c19148bdSblueswir1 .maxtl = 5, 89064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 891c48fcb47Sblueswir1 }, 892c48fcb47Sblueswir1 { 893c48fcb47Sblueswir1 .name = "TI UltraSparc IIi", 894c19148bdSblueswir1 .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)), 895c48fcb47Sblueswir1 .fpu_version = 0x00000000, 896fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 8971a14026eSblueswir1 .nwindows = 8, 898c19148bdSblueswir1 .maxtl = 5, 89964a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 900c48fcb47Sblueswir1 }, 901c48fcb47Sblueswir1 { 902c48fcb47Sblueswir1 .name = "TI UltraSparc IIe", 903c19148bdSblueswir1 .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)), 904c48fcb47Sblueswir1 .fpu_version = 0x00000000, 905fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 9061a14026eSblueswir1 .nwindows = 8, 907c19148bdSblueswir1 .maxtl = 5, 90864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 909c48fcb47Sblueswir1 }, 910c48fcb47Sblueswir1 { 911c48fcb47Sblueswir1 .name = "Sun UltraSparc III", 912c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)), 913c48fcb47Sblueswir1 .fpu_version = 0x00000000, 914fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 9151a14026eSblueswir1 .nwindows = 8, 916c19148bdSblueswir1 .maxtl = 5, 91764a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 918c48fcb47Sblueswir1 }, 919c48fcb47Sblueswir1 { 920c48fcb47Sblueswir1 .name = "Sun UltraSparc III Cu", 921c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)), 922c48fcb47Sblueswir1 .fpu_version = 0x00000000, 923fb79ceb9Sblueswir1 .mmu_version = mmu_us_3, 9241a14026eSblueswir1 .nwindows = 8, 925c19148bdSblueswir1 .maxtl = 5, 92664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 927c48fcb47Sblueswir1 }, 928c48fcb47Sblueswir1 { 929c48fcb47Sblueswir1 .name = "Sun UltraSparc IIIi", 930c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)), 931c48fcb47Sblueswir1 .fpu_version = 0x00000000, 932fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 9331a14026eSblueswir1 .nwindows = 8, 934c19148bdSblueswir1 .maxtl = 5, 93564a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 936c48fcb47Sblueswir1 }, 937c48fcb47Sblueswir1 { 938c48fcb47Sblueswir1 .name = "Sun UltraSparc IV", 939c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)), 940c48fcb47Sblueswir1 .fpu_version = 0x00000000, 941fb79ceb9Sblueswir1 .mmu_version = mmu_us_4, 9421a14026eSblueswir1 .nwindows = 8, 943c19148bdSblueswir1 .maxtl = 5, 94464a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 945c48fcb47Sblueswir1 }, 946c48fcb47Sblueswir1 { 947c48fcb47Sblueswir1 .name = "Sun UltraSparc IV+", 948c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)), 949c48fcb47Sblueswir1 .fpu_version = 0x00000000, 950fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 9511a14026eSblueswir1 .nwindows = 8, 952c19148bdSblueswir1 .maxtl = 5, 953fb79ceb9Sblueswir1 .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT, 954c48fcb47Sblueswir1 }, 955c48fcb47Sblueswir1 { 956c48fcb47Sblueswir1 .name = "Sun UltraSparc IIIi+", 957c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)), 958c48fcb47Sblueswir1 .fpu_version = 0x00000000, 959fb79ceb9Sblueswir1 .mmu_version = mmu_us_3, 9601a14026eSblueswir1 .nwindows = 8, 961c19148bdSblueswir1 .maxtl = 5, 96264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 963c48fcb47Sblueswir1 }, 964c48fcb47Sblueswir1 { 965c7ba218dSblueswir1 .name = "Sun UltraSparc T1", 966c7ba218dSblueswir1 // defined in sparc_ifu_fdp.v and ctu.h 967c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)), 968c7ba218dSblueswir1 .fpu_version = 0x00000000, 969c7ba218dSblueswir1 .mmu_version = mmu_sun4v, 970c7ba218dSblueswir1 .nwindows = 8, 971c19148bdSblueswir1 .maxtl = 6, 972c7ba218dSblueswir1 .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT 973c7ba218dSblueswir1 | CPU_FEATURE_GL, 974c7ba218dSblueswir1 }, 975c7ba218dSblueswir1 { 976c7ba218dSblueswir1 .name = "Sun UltraSparc T2", 977c7ba218dSblueswir1 // defined in tlu_asi_ctl.v and n2_revid_cust.v 978c19148bdSblueswir1 .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)), 979c7ba218dSblueswir1 .fpu_version = 0x00000000, 980c7ba218dSblueswir1 .mmu_version = mmu_sun4v, 981c7ba218dSblueswir1 .nwindows = 8, 982c19148bdSblueswir1 .maxtl = 6, 983c7ba218dSblueswir1 .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT 984c7ba218dSblueswir1 | CPU_FEATURE_GL, 985c7ba218dSblueswir1 }, 986c7ba218dSblueswir1 { 987c48fcb47Sblueswir1 .name = "NEC UltraSparc I", 988c19148bdSblueswir1 .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)), 989c48fcb47Sblueswir1 .fpu_version = 0x00000000, 990fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 9911a14026eSblueswir1 .nwindows = 8, 992c19148bdSblueswir1 .maxtl = 5, 99364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 994c48fcb47Sblueswir1 }, 995c48fcb47Sblueswir1 #else 996c48fcb47Sblueswir1 { 997c48fcb47Sblueswir1 .name = "Fujitsu MB86900", 998c48fcb47Sblueswir1 .iu_version = 0x00 << 24, /* Impl 0, ver 0 */ 999c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1000c48fcb47Sblueswir1 .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */ 1001c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1002c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1003c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1004c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1005c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 10061a14026eSblueswir1 .nwindows = 7, 1007e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_FSMULD, 1008c48fcb47Sblueswir1 }, 1009c48fcb47Sblueswir1 { 1010c48fcb47Sblueswir1 .name = "Fujitsu MB86904", 1011c48fcb47Sblueswir1 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */ 1012c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1013c48fcb47Sblueswir1 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */ 1014c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1015c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1016c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1017c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1018c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 10191a14026eSblueswir1 .nwindows = 8, 102064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1021c48fcb47Sblueswir1 }, 1022c48fcb47Sblueswir1 { 1023c48fcb47Sblueswir1 .name = "Fujitsu MB86907", 1024c48fcb47Sblueswir1 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */ 1025c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1026c48fcb47Sblueswir1 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */ 1027c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1028c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1029c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1030c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1031c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 10321a14026eSblueswir1 .nwindows = 8, 103364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1034c48fcb47Sblueswir1 }, 1035c48fcb47Sblueswir1 { 1036c48fcb47Sblueswir1 .name = "LSI L64811", 1037c48fcb47Sblueswir1 .iu_version = 0x10 << 24, /* Impl 1, ver 0 */ 1038c48fcb47Sblueswir1 .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */ 1039c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1040c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1041c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1042c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1043c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1044c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 10451a14026eSblueswir1 .nwindows = 8, 1046e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1047e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1048c48fcb47Sblueswir1 }, 1049c48fcb47Sblueswir1 { 1050c48fcb47Sblueswir1 .name = "Cypress CY7C601", 1051c48fcb47Sblueswir1 .iu_version = 0x11 << 24, /* Impl 1, ver 1 */ 1052c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ 1053c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1054c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1055c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1056c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1057c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1058c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 10591a14026eSblueswir1 .nwindows = 8, 1060e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1061e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1062c48fcb47Sblueswir1 }, 1063c48fcb47Sblueswir1 { 1064c48fcb47Sblueswir1 .name = "Cypress CY7C611", 1065c48fcb47Sblueswir1 .iu_version = 0x13 << 24, /* Impl 1, ver 3 */ 1066c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ 1067c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1068c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1069c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1070c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1071c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1072c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 10731a14026eSblueswir1 .nwindows = 8, 1074e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1075e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1076c48fcb47Sblueswir1 }, 1077c48fcb47Sblueswir1 { 1078c48fcb47Sblueswir1 .name = "TI MicroSparc I", 1079c48fcb47Sblueswir1 .iu_version = 0x41000000, 1080c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1081c48fcb47Sblueswir1 .mmu_version = 0x41000000, 1082c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1083c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1084c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1085c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1086c48fcb47Sblueswir1 .mmu_trcr_mask = 0x0000003f, 10871a14026eSblueswir1 .nwindows = 7, 1088e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL | 1089e30b4678Sblueswir1 CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | 1090e30b4678Sblueswir1 CPU_FEATURE_FMUL, 1091c48fcb47Sblueswir1 }, 1092c48fcb47Sblueswir1 { 1093c48fcb47Sblueswir1 .name = "TI MicroSparc II", 1094c48fcb47Sblueswir1 .iu_version = 0x42000000, 1095c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1096c48fcb47Sblueswir1 .mmu_version = 0x02000000, 1097c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1098c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1099c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1100c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1101c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 11021a14026eSblueswir1 .nwindows = 8, 110364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1104c48fcb47Sblueswir1 }, 1105c48fcb47Sblueswir1 { 1106c48fcb47Sblueswir1 .name = "TI MicroSparc IIep", 1107c48fcb47Sblueswir1 .iu_version = 0x42000000, 1108c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1109c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1110c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1111c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1112c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1113c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016bff, 1114c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 11151a14026eSblueswir1 .nwindows = 8, 111664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1117c48fcb47Sblueswir1 }, 1118c48fcb47Sblueswir1 { 1119b5154bdeSblueswir1 .name = "TI SuperSparc 40", // STP1020NPGA 1120963262deSblueswir1 .iu_version = 0x41000000, // SuperSPARC 2.x 1121b5154bdeSblueswir1 .fpu_version = 0 << 17, 1122963262deSblueswir1 .mmu_version = 0x00000800, // SuperSPARC 2.x, no MXCC 1123b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1124b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1125b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1126b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1127b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 11281a14026eSblueswir1 .nwindows = 8, 1129b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1130b5154bdeSblueswir1 }, 1131b5154bdeSblueswir1 { 1132b5154bdeSblueswir1 .name = "TI SuperSparc 50", // STP1020PGA 1133963262deSblueswir1 .iu_version = 0x40000000, // SuperSPARC 3.x 1134b5154bdeSblueswir1 .fpu_version = 0 << 17, 1135963262deSblueswir1 .mmu_version = 0x01000800, // SuperSPARC 3.x, no MXCC 1136b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1137b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1138b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1139b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1140b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 11411a14026eSblueswir1 .nwindows = 8, 1142b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1143b5154bdeSblueswir1 }, 1144b5154bdeSblueswir1 { 1145c48fcb47Sblueswir1 .name = "TI SuperSparc 51", 1146963262deSblueswir1 .iu_version = 0x40000000, // SuperSPARC 3.x 1147c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1148963262deSblueswir1 .mmu_version = 0x01000000, // SuperSPARC 3.x, MXCC 1149c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1150c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1151c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1152c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1153c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 1154963262deSblueswir1 .mxcc_version = 0x00000104, 11551a14026eSblueswir1 .nwindows = 8, 115664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1157c48fcb47Sblueswir1 }, 1158c48fcb47Sblueswir1 { 1159b5154bdeSblueswir1 .name = "TI SuperSparc 60", // STP1020APGA 1160963262deSblueswir1 .iu_version = 0x40000000, // SuperSPARC 3.x 1161b5154bdeSblueswir1 .fpu_version = 0 << 17, 1162963262deSblueswir1 .mmu_version = 0x01000800, // SuperSPARC 3.x, no MXCC 1163b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1164b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1165b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1166b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1167b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 11681a14026eSblueswir1 .nwindows = 8, 1169b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1170b5154bdeSblueswir1 }, 1171b5154bdeSblueswir1 { 1172c48fcb47Sblueswir1 .name = "TI SuperSparc 61", 1173963262deSblueswir1 .iu_version = 0x44000000, // SuperSPARC 3.x 1174c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1175963262deSblueswir1 .mmu_version = 0x01000000, // SuperSPARC 3.x, MXCC 1176c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1177c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1178c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1179c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1180c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 1181963262deSblueswir1 .mxcc_version = 0x00000104, 1182963262deSblueswir1 .nwindows = 8, 1183963262deSblueswir1 .features = CPU_DEFAULT_FEATURES, 1184963262deSblueswir1 }, 1185963262deSblueswir1 { 1186963262deSblueswir1 .name = "TI SuperSparc II", 1187963262deSblueswir1 .iu_version = 0x40000000, // SuperSPARC II 1.x 1188963262deSblueswir1 .fpu_version = 0 << 17, 1189963262deSblueswir1 .mmu_version = 0x08000000, // SuperSPARC II 1.x, MXCC 1190963262deSblueswir1 .mmu_bm = 0x00002000, 1191963262deSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1192963262deSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1193963262deSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1194963262deSblueswir1 .mmu_trcr_mask = 0xffffffff, 1195963262deSblueswir1 .mxcc_version = 0x00000104, 11961a14026eSblueswir1 .nwindows = 8, 119764a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1198c48fcb47Sblueswir1 }, 1199c48fcb47Sblueswir1 { 1200c48fcb47Sblueswir1 .name = "Ross RT625", 1201c48fcb47Sblueswir1 .iu_version = 0x1e000000, 1202c48fcb47Sblueswir1 .fpu_version = 1 << 17, 1203c48fcb47Sblueswir1 .mmu_version = 0x1e000000, 1204c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1205c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1206c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1207c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1208c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12091a14026eSblueswir1 .nwindows = 8, 121064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1211c48fcb47Sblueswir1 }, 1212c48fcb47Sblueswir1 { 1213c48fcb47Sblueswir1 .name = "Ross RT620", 1214c48fcb47Sblueswir1 .iu_version = 0x1f000000, 1215c48fcb47Sblueswir1 .fpu_version = 1 << 17, 1216c48fcb47Sblueswir1 .mmu_version = 0x1f000000, 1217c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1218c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1219c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1220c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1221c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12221a14026eSblueswir1 .nwindows = 8, 122364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1224c48fcb47Sblueswir1 }, 1225c48fcb47Sblueswir1 { 1226c48fcb47Sblueswir1 .name = "BIT B5010", 1227c48fcb47Sblueswir1 .iu_version = 0x20000000, 1228c48fcb47Sblueswir1 .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */ 1229c48fcb47Sblueswir1 .mmu_version = 0x20000000, 1230c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1231c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1232c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1233c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1234c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12351a14026eSblueswir1 .nwindows = 8, 1236e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1237e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1238c48fcb47Sblueswir1 }, 1239c48fcb47Sblueswir1 { 1240c48fcb47Sblueswir1 .name = "Matsushita MN10501", 1241c48fcb47Sblueswir1 .iu_version = 0x50000000, 1242c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1243c48fcb47Sblueswir1 .mmu_version = 0x50000000, 1244c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1245c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1246c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1247c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1248c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12491a14026eSblueswir1 .nwindows = 8, 1250e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_MUL | CPU_FEATURE_FSQRT | 1251e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1252c48fcb47Sblueswir1 }, 1253c48fcb47Sblueswir1 { 1254c48fcb47Sblueswir1 .name = "Weitek W8601", 1255c48fcb47Sblueswir1 .iu_version = 0x90 << 24, /* Impl 9, ver 0 */ 1256c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */ 1257c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1258c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1259c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1260c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1261c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1262c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12631a14026eSblueswir1 .nwindows = 8, 126464a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1265c48fcb47Sblueswir1 }, 1266c48fcb47Sblueswir1 { 1267c48fcb47Sblueswir1 .name = "LEON2", 1268c48fcb47Sblueswir1 .iu_version = 0xf2000000, 1269c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1270c48fcb47Sblueswir1 .mmu_version = 0xf2000000, 1271c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1272c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1273c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1274c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1275c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12761a14026eSblueswir1 .nwindows = 8, 127764a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1278c48fcb47Sblueswir1 }, 1279c48fcb47Sblueswir1 { 1280c48fcb47Sblueswir1 .name = "LEON3", 1281c48fcb47Sblueswir1 .iu_version = 0xf3000000, 1282c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1283c48fcb47Sblueswir1 .mmu_version = 0xf3000000, 1284c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1285c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1286c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1287c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1288c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12891a14026eSblueswir1 .nwindows = 8, 129064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1291c48fcb47Sblueswir1 }, 1292c48fcb47Sblueswir1 #endif 1293c48fcb47Sblueswir1 }; 1294c48fcb47Sblueswir1 129564a88d5dSblueswir1 static const char * const feature_name[] = { 129664a88d5dSblueswir1 "float", 129764a88d5dSblueswir1 "float128", 129864a88d5dSblueswir1 "swap", 129964a88d5dSblueswir1 "mul", 130064a88d5dSblueswir1 "div", 130164a88d5dSblueswir1 "flush", 130264a88d5dSblueswir1 "fsqrt", 130364a88d5dSblueswir1 "fmul", 130464a88d5dSblueswir1 "vis1", 130564a88d5dSblueswir1 "vis2", 1306e30b4678Sblueswir1 "fsmuld", 1307fb79ceb9Sblueswir1 "hypv", 1308fb79ceb9Sblueswir1 "cmt", 1309fb79ceb9Sblueswir1 "gl", 131064a88d5dSblueswir1 }; 131164a88d5dSblueswir1 13129a78eeadSStefan Weil static void print_features(FILE *f, fprintf_function cpu_fprintf, 131364a88d5dSblueswir1 uint32_t features, const char *prefix) 1314c48fcb47Sblueswir1 { 1315c48fcb47Sblueswir1 unsigned int i; 1316c48fcb47Sblueswir1 131764a88d5dSblueswir1 for (i = 0; i < ARRAY_SIZE(feature_name); i++) 131864a88d5dSblueswir1 if (feature_name[i] && (features & (1 << i))) { 131964a88d5dSblueswir1 if (prefix) 132064a88d5dSblueswir1 (*cpu_fprintf)(f, "%s", prefix); 132164a88d5dSblueswir1 (*cpu_fprintf)(f, "%s ", feature_name[i]); 132264a88d5dSblueswir1 } 132364a88d5dSblueswir1 } 132464a88d5dSblueswir1 132564a88d5dSblueswir1 static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features) 132664a88d5dSblueswir1 { 132764a88d5dSblueswir1 unsigned int i; 132864a88d5dSblueswir1 132964a88d5dSblueswir1 for (i = 0; i < ARRAY_SIZE(feature_name); i++) 133064a88d5dSblueswir1 if (feature_name[i] && !strcmp(flagname, feature_name[i])) { 133164a88d5dSblueswir1 *features |= 1 << i; 133264a88d5dSblueswir1 return; 133364a88d5dSblueswir1 } 133464a88d5dSblueswir1 fprintf(stderr, "CPU feature %s not found\n", flagname); 133564a88d5dSblueswir1 } 133664a88d5dSblueswir1 133722548760Sblueswir1 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model) 133864a88d5dSblueswir1 { 133964a88d5dSblueswir1 unsigned int i; 134064a88d5dSblueswir1 const sparc_def_t *def = NULL; 134164a88d5dSblueswir1 char *s = strdup(cpu_model); 134264a88d5dSblueswir1 char *featurestr, *name = strtok(s, ","); 134364a88d5dSblueswir1 uint32_t plus_features = 0; 134464a88d5dSblueswir1 uint32_t minus_features = 0; 13450bfcd599SBlue Swirl uint64_t iu_version; 13461a14026eSblueswir1 uint32_t fpu_version, mmu_version, nwindows; 134764a88d5dSblueswir1 1348b1503cdaSmalc for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) { 1349c48fcb47Sblueswir1 if (strcasecmp(name, sparc_defs[i].name) == 0) { 135064a88d5dSblueswir1 def = &sparc_defs[i]; 1351c48fcb47Sblueswir1 } 1352c48fcb47Sblueswir1 } 135364a88d5dSblueswir1 if (!def) 135464a88d5dSblueswir1 goto error; 135564a88d5dSblueswir1 memcpy(cpu_def, def, sizeof(*def)); 135664a88d5dSblueswir1 135764a88d5dSblueswir1 featurestr = strtok(NULL, ","); 135864a88d5dSblueswir1 while (featurestr) { 135964a88d5dSblueswir1 char *val; 136064a88d5dSblueswir1 136164a88d5dSblueswir1 if (featurestr[0] == '+') { 136264a88d5dSblueswir1 add_flagname_to_bitmaps(featurestr + 1, &plus_features); 136364a88d5dSblueswir1 } else if (featurestr[0] == '-') { 136464a88d5dSblueswir1 add_flagname_to_bitmaps(featurestr + 1, &minus_features); 136564a88d5dSblueswir1 } else if ((val = strchr(featurestr, '='))) { 136664a88d5dSblueswir1 *val = 0; val++; 136764a88d5dSblueswir1 if (!strcmp(featurestr, "iu_version")) { 136864a88d5dSblueswir1 char *err; 136964a88d5dSblueswir1 137064a88d5dSblueswir1 iu_version = strtoll(val, &err, 0); 137164a88d5dSblueswir1 if (!*val || *err) { 137264a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 137364a88d5dSblueswir1 goto error; 137464a88d5dSblueswir1 } 137564a88d5dSblueswir1 cpu_def->iu_version = iu_version; 137664a88d5dSblueswir1 #ifdef DEBUG_FEATURES 13770bfcd599SBlue Swirl fprintf(stderr, "iu_version %" PRIx64 "\n", iu_version); 137864a88d5dSblueswir1 #endif 137964a88d5dSblueswir1 } else if (!strcmp(featurestr, "fpu_version")) { 138064a88d5dSblueswir1 char *err; 138164a88d5dSblueswir1 138264a88d5dSblueswir1 fpu_version = strtol(val, &err, 0); 138364a88d5dSblueswir1 if (!*val || *err) { 138464a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 138564a88d5dSblueswir1 goto error; 138664a88d5dSblueswir1 } 138764a88d5dSblueswir1 cpu_def->fpu_version = fpu_version; 138864a88d5dSblueswir1 #ifdef DEBUG_FEATURES 13890bf9e31aSBlue Swirl fprintf(stderr, "fpu_version %x\n", fpu_version); 139064a88d5dSblueswir1 #endif 139164a88d5dSblueswir1 } else if (!strcmp(featurestr, "mmu_version")) { 139264a88d5dSblueswir1 char *err; 139364a88d5dSblueswir1 139464a88d5dSblueswir1 mmu_version = strtol(val, &err, 0); 139564a88d5dSblueswir1 if (!*val || *err) { 139664a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 139764a88d5dSblueswir1 goto error; 139864a88d5dSblueswir1 } 139964a88d5dSblueswir1 cpu_def->mmu_version = mmu_version; 140064a88d5dSblueswir1 #ifdef DEBUG_FEATURES 14010bf9e31aSBlue Swirl fprintf(stderr, "mmu_version %x\n", mmu_version); 140264a88d5dSblueswir1 #endif 14031a14026eSblueswir1 } else if (!strcmp(featurestr, "nwindows")) { 14041a14026eSblueswir1 char *err; 14051a14026eSblueswir1 14061a14026eSblueswir1 nwindows = strtol(val, &err, 0); 14071a14026eSblueswir1 if (!*val || *err || nwindows > MAX_NWINDOWS || 14081a14026eSblueswir1 nwindows < MIN_NWINDOWS) { 14091a14026eSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 14101a14026eSblueswir1 goto error; 14111a14026eSblueswir1 } 14121a14026eSblueswir1 cpu_def->nwindows = nwindows; 14131a14026eSblueswir1 #ifdef DEBUG_FEATURES 14141a14026eSblueswir1 fprintf(stderr, "nwindows %d\n", nwindows); 14151a14026eSblueswir1 #endif 141664a88d5dSblueswir1 } else { 141764a88d5dSblueswir1 fprintf(stderr, "unrecognized feature %s\n", featurestr); 141864a88d5dSblueswir1 goto error; 141964a88d5dSblueswir1 } 142064a88d5dSblueswir1 } else { 142177f193daSblueswir1 fprintf(stderr, "feature string `%s' not in format " 142277f193daSblueswir1 "(+feature|-feature|feature=xyz)\n", featurestr); 142364a88d5dSblueswir1 goto error; 142464a88d5dSblueswir1 } 142564a88d5dSblueswir1 featurestr = strtok(NULL, ","); 142664a88d5dSblueswir1 } 142764a88d5dSblueswir1 cpu_def->features |= plus_features; 142864a88d5dSblueswir1 cpu_def->features &= ~minus_features; 142964a88d5dSblueswir1 #ifdef DEBUG_FEATURES 143064a88d5dSblueswir1 print_features(stderr, fprintf, cpu_def->features, NULL); 143164a88d5dSblueswir1 #endif 143264a88d5dSblueswir1 free(s); 143364a88d5dSblueswir1 return 0; 143464a88d5dSblueswir1 143564a88d5dSblueswir1 error: 143664a88d5dSblueswir1 free(s); 143764a88d5dSblueswir1 return -1; 1438c48fcb47Sblueswir1 } 1439c48fcb47Sblueswir1 14409a78eeadSStefan Weil void sparc_cpu_list(FILE *f, fprintf_function cpu_fprintf) 1441c48fcb47Sblueswir1 { 1442c48fcb47Sblueswir1 unsigned int i; 1443c48fcb47Sblueswir1 1444b1503cdaSmalc for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) { 14451a14026eSblueswir1 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x NWINS %d ", 1446c48fcb47Sblueswir1 sparc_defs[i].name, 1447c48fcb47Sblueswir1 sparc_defs[i].iu_version, 1448c48fcb47Sblueswir1 sparc_defs[i].fpu_version, 14491a14026eSblueswir1 sparc_defs[i].mmu_version, 14501a14026eSblueswir1 sparc_defs[i].nwindows); 145177f193daSblueswir1 print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES & 145277f193daSblueswir1 ~sparc_defs[i].features, "-"); 145377f193daSblueswir1 print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES & 145477f193daSblueswir1 sparc_defs[i].features, "+"); 145564a88d5dSblueswir1 (*cpu_fprintf)(f, "\n"); 1456c48fcb47Sblueswir1 } 1457f76981b1Sblueswir1 (*cpu_fprintf)(f, "Default CPU feature flags (use '-' to remove): "); 1458f76981b1Sblueswir1 print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES, NULL); 145964a88d5dSblueswir1 (*cpu_fprintf)(f, "\n"); 1460f76981b1Sblueswir1 (*cpu_fprintf)(f, "Available CPU feature flags (use '+' to add): "); 1461f76981b1Sblueswir1 print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES, NULL); 1462f76981b1Sblueswir1 (*cpu_fprintf)(f, "\n"); 1463f76981b1Sblueswir1 (*cpu_fprintf)(f, "Numerical features (use '=' to set): iu_version " 1464f76981b1Sblueswir1 "fpu_version mmu_version nwindows\n"); 1465c48fcb47Sblueswir1 } 1466c48fcb47Sblueswir1 14679a78eeadSStefan Weil static void cpu_print_cc(FILE *f, fprintf_function cpu_fprintf, 146843bb98bfSBlue Swirl uint32_t cc) 146943bb98bfSBlue Swirl { 147043bb98bfSBlue Swirl cpu_fprintf(f, "%c%c%c%c", cc & PSR_NEG? 'N' : '-', 147143bb98bfSBlue Swirl cc & PSR_ZERO? 'Z' : '-', cc & PSR_OVF? 'V' : '-', 147243bb98bfSBlue Swirl cc & PSR_CARRY? 'C' : '-'); 147343bb98bfSBlue Swirl } 147443bb98bfSBlue Swirl 147543bb98bfSBlue Swirl #ifdef TARGET_SPARC64 147643bb98bfSBlue Swirl #define REGS_PER_LINE 4 147743bb98bfSBlue Swirl #else 147843bb98bfSBlue Swirl #define REGS_PER_LINE 8 147943bb98bfSBlue Swirl #endif 148043bb98bfSBlue Swirl 14819a78eeadSStefan Weil void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf, 1482c48fcb47Sblueswir1 int flags) 1483c48fcb47Sblueswir1 { 1484c48fcb47Sblueswir1 int i, x; 1485c48fcb47Sblueswir1 148677f193daSblueswir1 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, 148777f193daSblueswir1 env->npc); 1488c48fcb47Sblueswir1 cpu_fprintf(f, "General Registers:\n"); 148943bb98bfSBlue Swirl 149043bb98bfSBlue Swirl for (i = 0; i < 8; i++) { 149143bb98bfSBlue Swirl if (i % REGS_PER_LINE == 0) { 149243bb98bfSBlue Swirl cpu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1); 149343bb98bfSBlue Swirl } 149443bb98bfSBlue Swirl cpu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]); 149543bb98bfSBlue Swirl if (i % REGS_PER_LINE == REGS_PER_LINE - 1) { 1496c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1497c48fcb47Sblueswir1 } 149843bb98bfSBlue Swirl } 149943bb98bfSBlue Swirl cpu_fprintf(f, "\nCurrent Register Window:\n"); 150043bb98bfSBlue Swirl for (x = 0; x < 3; x++) { 150143bb98bfSBlue Swirl for (i = 0; i < 8; i++) { 150243bb98bfSBlue Swirl if (i % REGS_PER_LINE == 0) { 150343bb98bfSBlue Swirl cpu_fprintf(f, "%%%c%d-%d: ", 150443bb98bfSBlue Swirl x == 0 ? 'o' : (x == 1 ? 'l' : 'i'), 150543bb98bfSBlue Swirl i, i + REGS_PER_LINE - 1); 150643bb98bfSBlue Swirl } 150743bb98bfSBlue Swirl cpu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]); 150843bb98bfSBlue Swirl if (i % REGS_PER_LINE == REGS_PER_LINE - 1) { 150943bb98bfSBlue Swirl cpu_fprintf(f, "\n"); 151043bb98bfSBlue Swirl } 151143bb98bfSBlue Swirl } 151243bb98bfSBlue Swirl } 1513c48fcb47Sblueswir1 cpu_fprintf(f, "\nFloating Point Registers:\n"); 151443bb98bfSBlue Swirl for (i = 0; i < TARGET_FPREGS; i++) { 1515c48fcb47Sblueswir1 if ((i & 3) == 0) 1516c48fcb47Sblueswir1 cpu_fprintf(f, "%%f%02d:", i); 1517a37ee56cSblueswir1 cpu_fprintf(f, " %016f", *(float *)&env->fpr[i]); 1518c48fcb47Sblueswir1 if ((i & 3) == 3) 1519c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1520c48fcb47Sblueswir1 } 1521c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 152243bb98bfSBlue Swirl cpu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate, 1523113c6106SStefan Weil (unsigned)cpu_get_ccr(env)); 15245a834bb4SBlue Swirl cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << PSR_CARRY_SHIFT); 152543bb98bfSBlue Swirl cpu_fprintf(f, " xcc: "); 15265a834bb4SBlue Swirl cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4)); 152743bb98bfSBlue Swirl cpu_fprintf(f, ") asi: %02x tl: %d pil: %x\n", env->asi, env->tl, 152843bb98bfSBlue Swirl env->psrpil); 152943bb98bfSBlue Swirl cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d " 153043bb98bfSBlue Swirl "cleanwin: %d cwp: %d\n", 1531c48fcb47Sblueswir1 env->cansave, env->canrestore, env->otherwin, env->wstate, 15321a14026eSblueswir1 env->cleanwin, env->nwindows - 1 - env->cwp); 153343bb98bfSBlue Swirl cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: " 153443bb98bfSBlue Swirl TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs); 1535c48fcb47Sblueswir1 #else 15365a834bb4SBlue Swirl cpu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env)); 15375a834bb4SBlue Swirl cpu_print_cc(f, cpu_fprintf, cpu_get_psr(env)); 153843bb98bfSBlue Swirl cpu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs? 'S' : '-', 153943bb98bfSBlue Swirl env->psrps? 'P' : '-', env->psret? 'E' : '-', 154043bb98bfSBlue Swirl env->wim); 154143bb98bfSBlue Swirl cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n", 154243bb98bfSBlue Swirl env->fsr, env->y); 1543c48fcb47Sblueswir1 #endif 1544c48fcb47Sblueswir1 } 1545