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 17e8af50a3Sbellard * License along with this library; if not, write to the Free Software 18e8af50a3Sbellard * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19e8af50a3Sbellard */ 20ee5bbe38Sbellard #include <stdarg.h> 21ee5bbe38Sbellard #include <stdlib.h> 22ee5bbe38Sbellard #include <stdio.h> 23ee5bbe38Sbellard #include <string.h> 24ee5bbe38Sbellard #include <inttypes.h> 25ee5bbe38Sbellard #include <signal.h> 26ee5bbe38Sbellard #include <assert.h> 27ee5bbe38Sbellard 28ee5bbe38Sbellard #include "cpu.h" 29ee5bbe38Sbellard #include "exec-all.h" 30ca10f867Saurel32 #include "qemu-common.h" 3122548760Sblueswir1 #include "helper.h" 32e8af50a3Sbellard 33e80cfcfcSbellard //#define DEBUG_MMU 3464a88d5dSblueswir1 //#define DEBUG_FEATURES 35f2bc7e7fSblueswir1 //#define DEBUG_PCALL 36e8af50a3Sbellard 37c48fcb47Sblueswir1 typedef struct sparc_def_t sparc_def_t; 38c48fcb47Sblueswir1 39c48fcb47Sblueswir1 struct sparc_def_t { 4022548760Sblueswir1 const char *name; 41c48fcb47Sblueswir1 target_ulong iu_version; 42c48fcb47Sblueswir1 uint32_t fpu_version; 43c48fcb47Sblueswir1 uint32_t mmu_version; 44c48fcb47Sblueswir1 uint32_t mmu_bm; 45c48fcb47Sblueswir1 uint32_t mmu_ctpr_mask; 46c48fcb47Sblueswir1 uint32_t mmu_cxr_mask; 47c48fcb47Sblueswir1 uint32_t mmu_sfsr_mask; 48c48fcb47Sblueswir1 uint32_t mmu_trcr_mask; 4964a88d5dSblueswir1 uint32_t features; 501a14026eSblueswir1 uint32_t nwindows; 51c48fcb47Sblueswir1 }; 52c48fcb47Sblueswir1 5322548760Sblueswir1 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model); 54c48fcb47Sblueswir1 55e8af50a3Sbellard /* Sparc MMU emulation */ 56e8af50a3Sbellard 57e8af50a3Sbellard /* thread support */ 58e8af50a3Sbellard 59e8af50a3Sbellard spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED; 60e8af50a3Sbellard 61e8af50a3Sbellard void cpu_lock(void) 62e8af50a3Sbellard { 63e8af50a3Sbellard spin_lock(&global_cpu_lock); 64e8af50a3Sbellard } 65e8af50a3Sbellard 66e8af50a3Sbellard void cpu_unlock(void) 67e8af50a3Sbellard { 68e8af50a3Sbellard spin_unlock(&global_cpu_lock); 69e8af50a3Sbellard } 70e8af50a3Sbellard 719d893301Sbellard #if defined(CONFIG_USER_ONLY) 729d893301Sbellard 7322548760Sblueswir1 int cpu_sparc_handle_mmu_fault(CPUState *env1, target_ulong address, int rw, 746ebbf390Sj_mayer int mmu_idx, int is_softmmu) 759d893301Sbellard { 76878d3096Sbellard if (rw & 2) 7722548760Sblueswir1 env1->exception_index = TT_TFAULT; 78878d3096Sbellard else 7922548760Sblueswir1 env1->exception_index = TT_DFAULT; 809d893301Sbellard return 1; 819d893301Sbellard } 829d893301Sbellard 839d893301Sbellard #else 84e8af50a3Sbellard 853475187dSbellard #ifndef TARGET_SPARC64 8683469015Sbellard /* 8783469015Sbellard * Sparc V8 Reference MMU (SRMMU) 8883469015Sbellard */ 89e8af50a3Sbellard static const int access_table[8][8] = { 90e8af50a3Sbellard { 0, 0, 0, 0, 2, 0, 3, 3 }, 91e8af50a3Sbellard { 0, 0, 0, 0, 2, 0, 0, 0 }, 92e8af50a3Sbellard { 2, 2, 0, 0, 0, 2, 3, 3 }, 93e8af50a3Sbellard { 2, 2, 0, 0, 0, 2, 0, 0 }, 94e8af50a3Sbellard { 2, 0, 2, 0, 2, 2, 3, 3 }, 95e8af50a3Sbellard { 2, 0, 2, 0, 2, 0, 2, 0 }, 96e8af50a3Sbellard { 2, 2, 2, 0, 2, 2, 3, 3 }, 97e8af50a3Sbellard { 2, 2, 2, 0, 2, 2, 2, 0 } 98e8af50a3Sbellard }; 99e8af50a3Sbellard 100227671c9Sbellard static const int perm_table[2][8] = { 101227671c9Sbellard { 102227671c9Sbellard PAGE_READ, 103227671c9Sbellard PAGE_READ | PAGE_WRITE, 104227671c9Sbellard PAGE_READ | PAGE_EXEC, 105227671c9Sbellard PAGE_READ | PAGE_WRITE | PAGE_EXEC, 106227671c9Sbellard PAGE_EXEC, 107227671c9Sbellard PAGE_READ | PAGE_WRITE, 108227671c9Sbellard PAGE_READ | PAGE_EXEC, 109227671c9Sbellard PAGE_READ | PAGE_WRITE | PAGE_EXEC 110227671c9Sbellard }, 111227671c9Sbellard { 112227671c9Sbellard PAGE_READ, 113227671c9Sbellard PAGE_READ | PAGE_WRITE, 114227671c9Sbellard PAGE_READ | PAGE_EXEC, 115227671c9Sbellard PAGE_READ | PAGE_WRITE | PAGE_EXEC, 116227671c9Sbellard PAGE_EXEC, 117227671c9Sbellard PAGE_READ, 118227671c9Sbellard 0, 119227671c9Sbellard 0, 120227671c9Sbellard } 121e8af50a3Sbellard }; 122e8af50a3Sbellard 123c48fcb47Sblueswir1 static int get_physical_address(CPUState *env, target_phys_addr_t *physical, 124c48fcb47Sblueswir1 int *prot, int *access_index, 125c48fcb47Sblueswir1 target_ulong address, int rw, int mmu_idx) 126e8af50a3Sbellard { 127e80cfcfcSbellard int access_perms = 0; 128e80cfcfcSbellard target_phys_addr_t pde_ptr; 129af7bf89bSbellard uint32_t pde; 130af7bf89bSbellard target_ulong virt_addr; 1316ebbf390Sj_mayer int error_code = 0, is_dirty, is_user; 132e80cfcfcSbellard unsigned long page_offset; 133e8af50a3Sbellard 1346ebbf390Sj_mayer is_user = mmu_idx == MMU_USER_IDX; 135e8af50a3Sbellard virt_addr = address & TARGET_PAGE_MASK; 13640ce0a9aSblueswir1 137e8af50a3Sbellard if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */ 13840ce0a9aSblueswir1 // Boot mode: instruction fetches are taken from PROM 1396d5f237aSblueswir1 if (rw == 2 && (env->mmuregs[0] & env->mmu_bm)) { 14058a770f3Sblueswir1 *physical = env->prom_addr | (address & 0x7ffffULL); 14140ce0a9aSblueswir1 *prot = PAGE_READ | PAGE_EXEC; 14240ce0a9aSblueswir1 return 0; 14340ce0a9aSblueswir1 } 144e80cfcfcSbellard *physical = address; 145227671c9Sbellard *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; 146e80cfcfcSbellard return 0; 147e8af50a3Sbellard } 148e8af50a3Sbellard 1497483750dSbellard *access_index = ((rw & 1) << 2) | (rw & 2) | (is_user? 0 : 1); 1505dcb6b91Sblueswir1 *physical = 0xffffffffffff0000ULL; 1517483750dSbellard 152e8af50a3Sbellard /* SPARC reference MMU table walk: Context table->L1->L2->PTE */ 153e8af50a3Sbellard /* Context base + context number */ 1543deaeab7Sblueswir1 pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2); 15549be8030Sbellard pde = ldl_phys(pde_ptr); 156e8af50a3Sbellard 157e8af50a3Sbellard /* Ctx pde */ 158e8af50a3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 159e80cfcfcSbellard default: 160e8af50a3Sbellard case 0: /* Invalid */ 1617483750dSbellard return 1 << 2; 162e80cfcfcSbellard case 2: /* L0 PTE, maybe should not happen? */ 163e8af50a3Sbellard case 3: /* Reserved */ 1647483750dSbellard return 4 << 2; 165e80cfcfcSbellard case 1: /* L0 PDE */ 166e80cfcfcSbellard pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4); 16749be8030Sbellard pde = ldl_phys(pde_ptr); 168e80cfcfcSbellard 169e80cfcfcSbellard switch (pde & PTE_ENTRYTYPE_MASK) { 170e80cfcfcSbellard default: 171e80cfcfcSbellard case 0: /* Invalid */ 1727483750dSbellard return (1 << 8) | (1 << 2); 173e80cfcfcSbellard case 3: /* Reserved */ 1747483750dSbellard return (1 << 8) | (4 << 2); 175e8af50a3Sbellard case 1: /* L1 PDE */ 176e80cfcfcSbellard pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4); 17749be8030Sbellard pde = ldl_phys(pde_ptr); 178e8af50a3Sbellard 179e8af50a3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 180e80cfcfcSbellard default: 181e8af50a3Sbellard case 0: /* Invalid */ 1827483750dSbellard return (2 << 8) | (1 << 2); 183e8af50a3Sbellard case 3: /* Reserved */ 1847483750dSbellard return (2 << 8) | (4 << 2); 185e8af50a3Sbellard case 1: /* L2 PDE */ 186e80cfcfcSbellard pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4); 18749be8030Sbellard pde = ldl_phys(pde_ptr); 188e8af50a3Sbellard 189e8af50a3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 190e80cfcfcSbellard default: 191e8af50a3Sbellard case 0: /* Invalid */ 1927483750dSbellard return (3 << 8) | (1 << 2); 193e8af50a3Sbellard case 1: /* PDE, should not happen */ 194e8af50a3Sbellard case 3: /* Reserved */ 1957483750dSbellard return (3 << 8) | (4 << 2); 196e8af50a3Sbellard case 2: /* L3 PTE */ 197e8af50a3Sbellard virt_addr = address & TARGET_PAGE_MASK; 19877f193daSblueswir1 page_offset = (address & TARGET_PAGE_MASK) & 19977f193daSblueswir1 (TARGET_PAGE_SIZE - 1); 200e8af50a3Sbellard } 201e8af50a3Sbellard break; 202e8af50a3Sbellard case 2: /* L2 PTE */ 203e8af50a3Sbellard virt_addr = address & ~0x3ffff; 204e8af50a3Sbellard page_offset = address & 0x3ffff; 205e8af50a3Sbellard } 206e8af50a3Sbellard break; 207e8af50a3Sbellard case 2: /* L1 PTE */ 208e8af50a3Sbellard virt_addr = address & ~0xffffff; 209e8af50a3Sbellard page_offset = address & 0xffffff; 210e8af50a3Sbellard } 211e8af50a3Sbellard } 212e8af50a3Sbellard 213e8af50a3Sbellard /* update page modified and dirty bits */ 214b769d8feSbellard is_dirty = (rw & 1) && !(pde & PG_MODIFIED_MASK); 215e8af50a3Sbellard if (!(pde & PG_ACCESSED_MASK) || is_dirty) { 216e8af50a3Sbellard pde |= PG_ACCESSED_MASK; 217e8af50a3Sbellard if (is_dirty) 218e8af50a3Sbellard pde |= PG_MODIFIED_MASK; 21949be8030Sbellard stl_phys_notdirty(pde_ptr, pde); 220e8af50a3Sbellard } 221e8af50a3Sbellard /* check access */ 222e8af50a3Sbellard access_perms = (pde & PTE_ACCESS_MASK) >> PTE_ACCESS_SHIFT; 223e80cfcfcSbellard error_code = access_table[*access_index][access_perms]; 224d8e3326cSbellard if (error_code && !((env->mmuregs[0] & MMU_NF) && is_user)) 225e80cfcfcSbellard return error_code; 226e8af50a3Sbellard 227e8af50a3Sbellard /* the page can be put in the TLB */ 228227671c9Sbellard *prot = perm_table[is_user][access_perms]; 229227671c9Sbellard if (!(pde & PG_MODIFIED_MASK)) { 230e8af50a3Sbellard /* only set write access if already dirty... otherwise wait 231e8af50a3Sbellard for dirty access */ 232227671c9Sbellard *prot &= ~PAGE_WRITE; 233e8af50a3Sbellard } 234e8af50a3Sbellard 235e8af50a3Sbellard /* Even if large ptes, we map only one 4KB page in the cache to 236e8af50a3Sbellard avoid filling it too fast */ 2375dcb6b91Sblueswir1 *physical = ((target_phys_addr_t)(pde & PTE_ADDR_MASK) << 4) + page_offset; 2386f7e9aecSbellard return error_code; 239e80cfcfcSbellard } 240e80cfcfcSbellard 241e80cfcfcSbellard /* Perform address translation */ 242af7bf89bSbellard int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, 2436ebbf390Sj_mayer int mmu_idx, int is_softmmu) 244e80cfcfcSbellard { 245af7bf89bSbellard target_phys_addr_t paddr; 2465dcb6b91Sblueswir1 target_ulong vaddr; 247e80cfcfcSbellard int error_code = 0, prot, ret = 0, access_index; 248e80cfcfcSbellard 24977f193daSblueswir1 error_code = get_physical_address(env, &paddr, &prot, &access_index, 25077f193daSblueswir1 address, rw, mmu_idx); 251e80cfcfcSbellard if (error_code == 0) { 2529e61bde5Sbellard vaddr = address & TARGET_PAGE_MASK; 2539e61bde5Sbellard paddr &= TARGET_PAGE_MASK; 2549e61bde5Sbellard #ifdef DEBUG_MMU 2555dcb6b91Sblueswir1 printf("Translate at " TARGET_FMT_lx " -> " TARGET_FMT_plx ", vaddr " 2565dcb6b91Sblueswir1 TARGET_FMT_lx "\n", address, paddr, vaddr); 2579e61bde5Sbellard #endif 2586ebbf390Sj_mayer ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu); 259e8af50a3Sbellard return ret; 260e80cfcfcSbellard } 261e8af50a3Sbellard 262e8af50a3Sbellard if (env->mmuregs[3]) /* Fault status register */ 263e8af50a3Sbellard env->mmuregs[3] = 1; /* overflow (not read before another fault) */ 2647483750dSbellard env->mmuregs[3] |= (access_index << 5) | error_code | 2; 265e8af50a3Sbellard env->mmuregs[4] = address; /* Fault address register */ 266e8af50a3Sbellard 267878d3096Sbellard if ((env->mmuregs[0] & MMU_NF) || env->psret == 0) { 2686f7e9aecSbellard // No fault mode: if a mapping is available, just override 2696f7e9aecSbellard // permissions. If no mapping is available, redirect accesses to 2706f7e9aecSbellard // neverland. Fake/overridden mappings will be flushed when 2716f7e9aecSbellard // switching to normal mode. 2727483750dSbellard vaddr = address & TARGET_PAGE_MASK; 273227671c9Sbellard prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; 2746ebbf390Sj_mayer ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu); 2757483750dSbellard return ret; 2767483750dSbellard } else { 277878d3096Sbellard if (rw & 2) 278878d3096Sbellard env->exception_index = TT_TFAULT; 279878d3096Sbellard else 280878d3096Sbellard env->exception_index = TT_DFAULT; 281878d3096Sbellard return 1; 282e8af50a3Sbellard } 2837483750dSbellard } 28424741ef3Sbellard 28524741ef3Sbellard target_ulong mmu_probe(CPUState *env, target_ulong address, int mmulev) 28624741ef3Sbellard { 28724741ef3Sbellard target_phys_addr_t pde_ptr; 28824741ef3Sbellard uint32_t pde; 28924741ef3Sbellard 29024741ef3Sbellard /* Context base + context number */ 2915dcb6b91Sblueswir1 pde_ptr = (target_phys_addr_t)(env->mmuregs[1] << 4) + 2925dcb6b91Sblueswir1 (env->mmuregs[2] << 2); 29324741ef3Sbellard pde = ldl_phys(pde_ptr); 29424741ef3Sbellard 29524741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 29624741ef3Sbellard default: 29724741ef3Sbellard case 0: /* Invalid */ 29824741ef3Sbellard case 2: /* PTE, maybe should not happen? */ 29924741ef3Sbellard case 3: /* Reserved */ 30024741ef3Sbellard return 0; 30124741ef3Sbellard case 1: /* L1 PDE */ 30224741ef3Sbellard if (mmulev == 3) 30324741ef3Sbellard return pde; 30424741ef3Sbellard pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4); 30524741ef3Sbellard pde = ldl_phys(pde_ptr); 30624741ef3Sbellard 30724741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 30824741ef3Sbellard default: 30924741ef3Sbellard case 0: /* Invalid */ 31024741ef3Sbellard case 3: /* Reserved */ 31124741ef3Sbellard return 0; 31224741ef3Sbellard case 2: /* L1 PTE */ 31324741ef3Sbellard return pde; 31424741ef3Sbellard case 1: /* L2 PDE */ 31524741ef3Sbellard if (mmulev == 2) 31624741ef3Sbellard return pde; 31724741ef3Sbellard pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4); 31824741ef3Sbellard pde = ldl_phys(pde_ptr); 31924741ef3Sbellard 32024741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 32124741ef3Sbellard default: 32224741ef3Sbellard case 0: /* Invalid */ 32324741ef3Sbellard case 3: /* Reserved */ 32424741ef3Sbellard return 0; 32524741ef3Sbellard case 2: /* L2 PTE */ 32624741ef3Sbellard return pde; 32724741ef3Sbellard case 1: /* L3 PDE */ 32824741ef3Sbellard if (mmulev == 1) 32924741ef3Sbellard return pde; 33024741ef3Sbellard pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4); 33124741ef3Sbellard pde = ldl_phys(pde_ptr); 33224741ef3Sbellard 33324741ef3Sbellard switch (pde & PTE_ENTRYTYPE_MASK) { 33424741ef3Sbellard default: 33524741ef3Sbellard case 0: /* Invalid */ 33624741ef3Sbellard case 1: /* PDE, should not happen */ 33724741ef3Sbellard case 3: /* Reserved */ 33824741ef3Sbellard return 0; 33924741ef3Sbellard case 2: /* L3 PTE */ 34024741ef3Sbellard return pde; 34124741ef3Sbellard } 34224741ef3Sbellard } 34324741ef3Sbellard } 34424741ef3Sbellard } 34524741ef3Sbellard return 0; 34624741ef3Sbellard } 34724741ef3Sbellard 34824741ef3Sbellard #ifdef DEBUG_MMU 34924741ef3Sbellard void dump_mmu(CPUState *env) 35024741ef3Sbellard { 35124741ef3Sbellard target_ulong va, va1, va2; 35224741ef3Sbellard unsigned int n, m, o; 35324741ef3Sbellard target_phys_addr_t pde_ptr, pa; 35424741ef3Sbellard uint32_t pde; 35524741ef3Sbellard 35624741ef3Sbellard printf("MMU dump:\n"); 35724741ef3Sbellard pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2); 35824741ef3Sbellard pde = ldl_phys(pde_ptr); 3595dcb6b91Sblueswir1 printf("Root ptr: " TARGET_FMT_plx ", ctx: %d\n", 3605dcb6b91Sblueswir1 (target_phys_addr_t)env->mmuregs[1] << 4, env->mmuregs[2]); 36124741ef3Sbellard for (n = 0, va = 0; n < 256; n++, va += 16 * 1024 * 1024) { 3625dcb6b91Sblueswir1 pde = mmu_probe(env, va, 2); 3635dcb6b91Sblueswir1 if (pde) { 36424741ef3Sbellard pa = cpu_get_phys_page_debug(env, va); 3655dcb6b91Sblueswir1 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx 3665dcb6b91Sblueswir1 " PDE: " TARGET_FMT_lx "\n", va, pa, pde); 36724741ef3Sbellard for (m = 0, va1 = va; m < 64; m++, va1 += 256 * 1024) { 3685dcb6b91Sblueswir1 pde = mmu_probe(env, va1, 1); 3695dcb6b91Sblueswir1 if (pde) { 37024741ef3Sbellard pa = cpu_get_phys_page_debug(env, va1); 3715dcb6b91Sblueswir1 printf(" VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_plx 3725dcb6b91Sblueswir1 " PDE: " TARGET_FMT_lx "\n", va1, pa, pde); 37324741ef3Sbellard for (o = 0, va2 = va1; o < 64; o++, va2 += 4 * 1024) { 3745dcb6b91Sblueswir1 pde = mmu_probe(env, va2, 0); 3755dcb6b91Sblueswir1 if (pde) { 37624741ef3Sbellard pa = cpu_get_phys_page_debug(env, va2); 3775dcb6b91Sblueswir1 printf(" VA: " TARGET_FMT_lx ", PA: " 3785dcb6b91Sblueswir1 TARGET_FMT_plx " PTE: " TARGET_FMT_lx "\n", 3795dcb6b91Sblueswir1 va2, pa, pde); 38024741ef3Sbellard } 38124741ef3Sbellard } 38224741ef3Sbellard } 38324741ef3Sbellard } 38424741ef3Sbellard } 38524741ef3Sbellard } 38624741ef3Sbellard printf("MMU dump ends\n"); 38724741ef3Sbellard } 38824741ef3Sbellard #endif /* DEBUG_MMU */ 38924741ef3Sbellard 39024741ef3Sbellard #else /* !TARGET_SPARC64 */ 39183469015Sbellard /* 39283469015Sbellard * UltraSparc IIi I/DMMUs 39383469015Sbellard */ 39477f193daSblueswir1 static int get_physical_address_data(CPUState *env, 39577f193daSblueswir1 target_phys_addr_t *physical, int *prot, 39622548760Sblueswir1 target_ulong address, int rw, int is_user) 3973475187dSbellard { 3983475187dSbellard target_ulong mask; 3993475187dSbellard unsigned int i; 4003475187dSbellard 4013475187dSbellard if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */ 40283469015Sbellard *physical = address; 4033475187dSbellard *prot = PAGE_READ | PAGE_WRITE; 4043475187dSbellard return 0; 4053475187dSbellard } 4063475187dSbellard 4073475187dSbellard for (i = 0; i < 64; i++) { 40883469015Sbellard switch ((env->dtlb_tte[i] >> 61) & 3) { 4093475187dSbellard default: 41083469015Sbellard case 0x0: // 8k 4113475187dSbellard mask = 0xffffffffffffe000ULL; 4123475187dSbellard break; 41383469015Sbellard case 0x1: // 64k 4143475187dSbellard mask = 0xffffffffffff0000ULL; 4153475187dSbellard break; 41683469015Sbellard case 0x2: // 512k 4173475187dSbellard mask = 0xfffffffffff80000ULL; 4183475187dSbellard break; 41983469015Sbellard case 0x3: // 4M 4203475187dSbellard mask = 0xffffffffffc00000ULL; 4213475187dSbellard break; 4223475187dSbellard } 4233475187dSbellard // ctx match, vaddr match? 4243475187dSbellard if (env->dmmuregs[1] == (env->dtlb_tag[i] & 0x1fff) && 4253475187dSbellard (address & mask) == (env->dtlb_tag[i] & ~0x1fffULL)) { 42683469015Sbellard // valid, access ok? 42783469015Sbellard if ((env->dtlb_tte[i] & 0x8000000000000000ULL) == 0 || 42883469015Sbellard ((env->dtlb_tte[i] & 0x4) && is_user) || 4293475187dSbellard (!(env->dtlb_tte[i] & 0x2) && (rw == 1))) { 43083469015Sbellard if (env->dmmuregs[3]) /* Fault status register */ 43177f193daSblueswir1 env->dmmuregs[3] = 2; /* overflow (not read before 43277f193daSblueswir1 another fault) */ 43383469015Sbellard env->dmmuregs[3] |= (is_user << 3) | ((rw == 1) << 2) | 1; 43483469015Sbellard env->dmmuregs[4] = address; /* Fault address register */ 4353475187dSbellard env->exception_index = TT_DFAULT; 43683469015Sbellard #ifdef DEBUG_MMU 43726a76461Sbellard printf("DFAULT at 0x%" PRIx64 "\n", address); 43883469015Sbellard #endif 4393475187dSbellard return 1; 4403475187dSbellard } 44177f193daSblueswir1 *physical = (env->dtlb_tte[i] & mask & 0x1fffffff000ULL) + 44277f193daSblueswir1 (address & ~mask & 0x1fffffff000ULL); 4433475187dSbellard *prot = PAGE_READ; 4443475187dSbellard if (env->dtlb_tte[i] & 0x2) 4453475187dSbellard *prot |= PAGE_WRITE; 4463475187dSbellard return 0; 4473475187dSbellard } 4483475187dSbellard } 44983469015Sbellard #ifdef DEBUG_MMU 45026a76461Sbellard printf("DMISS at 0x%" PRIx64 "\n", address); 45183469015Sbellard #endif 45283469015Sbellard env->exception_index = TT_DMISS; 4533475187dSbellard return 1; 4543475187dSbellard } 4553475187dSbellard 45677f193daSblueswir1 static int get_physical_address_code(CPUState *env, 45777f193daSblueswir1 target_phys_addr_t *physical, int *prot, 45822548760Sblueswir1 target_ulong address, int is_user) 4593475187dSbellard { 4603475187dSbellard target_ulong mask; 4613475187dSbellard unsigned int i; 4623475187dSbellard 4633475187dSbellard if ((env->lsu & IMMU_E) == 0) { /* IMMU disabled */ 46483469015Sbellard *physical = address; 465227671c9Sbellard *prot = PAGE_EXEC; 4663475187dSbellard return 0; 4673475187dSbellard } 46883469015Sbellard 4693475187dSbellard for (i = 0; i < 64; i++) { 47083469015Sbellard switch ((env->itlb_tte[i] >> 61) & 3) { 4713475187dSbellard default: 47283469015Sbellard case 0x0: // 8k 4733475187dSbellard mask = 0xffffffffffffe000ULL; 4743475187dSbellard break; 47583469015Sbellard case 0x1: // 64k 4763475187dSbellard mask = 0xffffffffffff0000ULL; 4773475187dSbellard break; 47883469015Sbellard case 0x2: // 512k 4793475187dSbellard mask = 0xfffffffffff80000ULL; 4803475187dSbellard break; 48183469015Sbellard case 0x3: // 4M 4823475187dSbellard mask = 0xffffffffffc00000ULL; 4833475187dSbellard break; 4843475187dSbellard } 4853475187dSbellard // ctx match, vaddr match? 48683469015Sbellard if (env->dmmuregs[1] == (env->itlb_tag[i] & 0x1fff) && 4873475187dSbellard (address & mask) == (env->itlb_tag[i] & ~0x1fffULL)) { 48883469015Sbellard // valid, access ok? 48983469015Sbellard if ((env->itlb_tte[i] & 0x8000000000000000ULL) == 0 || 49083469015Sbellard ((env->itlb_tte[i] & 0x4) && is_user)) { 49183469015Sbellard if (env->immuregs[3]) /* Fault status register */ 49277f193daSblueswir1 env->immuregs[3] = 2; /* overflow (not read before 49377f193daSblueswir1 another fault) */ 49483469015Sbellard env->immuregs[3] |= (is_user << 3) | 1; 4953475187dSbellard env->exception_index = TT_TFAULT; 49683469015Sbellard #ifdef DEBUG_MMU 49726a76461Sbellard printf("TFAULT at 0x%" PRIx64 "\n", address); 49883469015Sbellard #endif 4993475187dSbellard return 1; 5003475187dSbellard } 50177f193daSblueswir1 *physical = (env->itlb_tte[i] & mask & 0x1fffffff000ULL) + 50277f193daSblueswir1 (address & ~mask & 0x1fffffff000ULL); 503227671c9Sbellard *prot = PAGE_EXEC; 5043475187dSbellard return 0; 5053475187dSbellard } 5063475187dSbellard } 50783469015Sbellard #ifdef DEBUG_MMU 50826a76461Sbellard printf("TMISS at 0x%" PRIx64 "\n", address); 50983469015Sbellard #endif 51083469015Sbellard env->exception_index = TT_TMISS; 5113475187dSbellard return 1; 5123475187dSbellard } 5133475187dSbellard 514c48fcb47Sblueswir1 static int get_physical_address(CPUState *env, target_phys_addr_t *physical, 515c48fcb47Sblueswir1 int *prot, int *access_index, 516c48fcb47Sblueswir1 target_ulong address, int rw, int mmu_idx) 5173475187dSbellard { 5186ebbf390Sj_mayer int is_user = mmu_idx == MMU_USER_IDX; 5196ebbf390Sj_mayer 5203475187dSbellard if (rw == 2) 52122548760Sblueswir1 return get_physical_address_code(env, physical, prot, address, 52222548760Sblueswir1 is_user); 5233475187dSbellard else 52422548760Sblueswir1 return get_physical_address_data(env, physical, prot, address, rw, 52522548760Sblueswir1 is_user); 5263475187dSbellard } 5273475187dSbellard 5283475187dSbellard /* Perform address translation */ 5293475187dSbellard int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, 5306ebbf390Sj_mayer int mmu_idx, int is_softmmu) 5313475187dSbellard { 53283469015Sbellard target_ulong virt_addr, vaddr; 5333475187dSbellard target_phys_addr_t paddr; 5343475187dSbellard int error_code = 0, prot, ret = 0, access_index; 5353475187dSbellard 53677f193daSblueswir1 error_code = get_physical_address(env, &paddr, &prot, &access_index, 53777f193daSblueswir1 address, rw, mmu_idx); 5383475187dSbellard if (error_code == 0) { 5393475187dSbellard virt_addr = address & TARGET_PAGE_MASK; 54077f193daSblueswir1 vaddr = virt_addr + ((address & TARGET_PAGE_MASK) & 54177f193daSblueswir1 (TARGET_PAGE_SIZE - 1)); 54283469015Sbellard #ifdef DEBUG_MMU 54377f193daSblueswir1 printf("Translate at 0x%" PRIx64 " -> 0x%" PRIx64 ", vaddr 0x%" PRIx64 54477f193daSblueswir1 "\n", address, paddr, vaddr); 54583469015Sbellard #endif 5466ebbf390Sj_mayer ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu); 5473475187dSbellard return ret; 5483475187dSbellard } 5493475187dSbellard // XXX 5503475187dSbellard return 1; 5513475187dSbellard } 5523475187dSbellard 55383469015Sbellard #ifdef DEBUG_MMU 55483469015Sbellard void dump_mmu(CPUState *env) 55583469015Sbellard { 55683469015Sbellard unsigned int i; 55783469015Sbellard const char *mask; 55883469015Sbellard 55977f193daSblueswir1 printf("MMU contexts: Primary: %" PRId64 ", Secondary: %" PRId64 "\n", 56077f193daSblueswir1 env->dmmuregs[1], env->dmmuregs[2]); 56183469015Sbellard if ((env->lsu & DMMU_E) == 0) { 56283469015Sbellard printf("DMMU disabled\n"); 56383469015Sbellard } else { 56483469015Sbellard printf("DMMU dump:\n"); 56583469015Sbellard for (i = 0; i < 64; i++) { 56683469015Sbellard switch ((env->dtlb_tte[i] >> 61) & 3) { 56783469015Sbellard default: 56883469015Sbellard case 0x0: 56983469015Sbellard mask = " 8k"; 57083469015Sbellard break; 57183469015Sbellard case 0x1: 57283469015Sbellard mask = " 64k"; 57383469015Sbellard break; 57483469015Sbellard case 0x2: 57583469015Sbellard mask = "512k"; 57683469015Sbellard break; 57783469015Sbellard case 0x3: 57883469015Sbellard mask = " 4M"; 57983469015Sbellard break; 58083469015Sbellard } 58183469015Sbellard if ((env->dtlb_tte[i] & 0x8000000000000000ULL) != 0) { 58277f193daSblueswir1 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx 58377f193daSblueswir1 ", %s, %s, %s, %s, ctx %" PRId64 "\n", 58483469015Sbellard env->dtlb_tag[i] & ~0x1fffULL, 58583469015Sbellard env->dtlb_tte[i] & 0x1ffffffe000ULL, 58683469015Sbellard mask, 58783469015Sbellard env->dtlb_tte[i] & 0x4? "priv": "user", 58883469015Sbellard env->dtlb_tte[i] & 0x2? "RW": "RO", 58983469015Sbellard env->dtlb_tte[i] & 0x40? "locked": "unlocked", 59083469015Sbellard env->dtlb_tag[i] & 0x1fffULL); 59183469015Sbellard } 59283469015Sbellard } 59383469015Sbellard } 59483469015Sbellard if ((env->lsu & IMMU_E) == 0) { 59583469015Sbellard printf("IMMU disabled\n"); 59683469015Sbellard } else { 59783469015Sbellard printf("IMMU dump:\n"); 59883469015Sbellard for (i = 0; i < 64; i++) { 59983469015Sbellard switch ((env->itlb_tte[i] >> 61) & 3) { 60083469015Sbellard default: 60183469015Sbellard case 0x0: 60283469015Sbellard mask = " 8k"; 60383469015Sbellard break; 60483469015Sbellard case 0x1: 60583469015Sbellard mask = " 64k"; 60683469015Sbellard break; 60783469015Sbellard case 0x2: 60883469015Sbellard mask = "512k"; 60983469015Sbellard break; 61083469015Sbellard case 0x3: 61183469015Sbellard mask = " 4M"; 61283469015Sbellard break; 61383469015Sbellard } 61483469015Sbellard if ((env->itlb_tte[i] & 0x8000000000000000ULL) != 0) { 61577f193daSblueswir1 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx 61677f193daSblueswir1 ", %s, %s, %s, ctx %" PRId64 "\n", 61783469015Sbellard env->itlb_tag[i] & ~0x1fffULL, 61883469015Sbellard env->itlb_tte[i] & 0x1ffffffe000ULL, 61983469015Sbellard mask, 62083469015Sbellard env->itlb_tte[i] & 0x4? "priv": "user", 62183469015Sbellard env->itlb_tte[i] & 0x40? "locked": "unlocked", 62283469015Sbellard env->itlb_tag[i] & 0x1fffULL); 62383469015Sbellard } 62483469015Sbellard } 62583469015Sbellard } 62683469015Sbellard } 62724741ef3Sbellard #endif /* DEBUG_MMU */ 62824741ef3Sbellard 62924741ef3Sbellard #endif /* TARGET_SPARC64 */ 63024741ef3Sbellard #endif /* !CONFIG_USER_ONLY */ 63124741ef3Sbellard 632c48fcb47Sblueswir1 633c48fcb47Sblueswir1 #if defined(CONFIG_USER_ONLY) 634c48fcb47Sblueswir1 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) 635c48fcb47Sblueswir1 { 636c48fcb47Sblueswir1 return addr; 637c48fcb47Sblueswir1 } 638c48fcb47Sblueswir1 639c48fcb47Sblueswir1 #else 640c48fcb47Sblueswir1 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) 641c48fcb47Sblueswir1 { 642c48fcb47Sblueswir1 target_phys_addr_t phys_addr; 643c48fcb47Sblueswir1 int prot, access_index; 644c48fcb47Sblueswir1 645c48fcb47Sblueswir1 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2, 646c48fcb47Sblueswir1 MMU_KERNEL_IDX) != 0) 647c48fcb47Sblueswir1 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 648c48fcb47Sblueswir1 0, MMU_KERNEL_IDX) != 0) 649c48fcb47Sblueswir1 return -1; 650c48fcb47Sblueswir1 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED) 651c48fcb47Sblueswir1 return -1; 652c48fcb47Sblueswir1 return phys_addr; 653c48fcb47Sblueswir1 } 654c48fcb47Sblueswir1 #endif 655c48fcb47Sblueswir1 656f2bc7e7fSblueswir1 #ifdef TARGET_SPARC64 657f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 658f2bc7e7fSblueswir1 static const char * const excp_names[0x50] = { 659f2bc7e7fSblueswir1 [TT_TFAULT] = "Instruction Access Fault", 660f2bc7e7fSblueswir1 [TT_TMISS] = "Instruction Access MMU Miss", 661f2bc7e7fSblueswir1 [TT_CODE_ACCESS] = "Instruction Access Error", 662f2bc7e7fSblueswir1 [TT_ILL_INSN] = "Illegal Instruction", 663f2bc7e7fSblueswir1 [TT_PRIV_INSN] = "Privileged Instruction", 664f2bc7e7fSblueswir1 [TT_NFPU_INSN] = "FPU Disabled", 665f2bc7e7fSblueswir1 [TT_FP_EXCP] = "FPU Exception", 666f2bc7e7fSblueswir1 [TT_TOVF] = "Tag Overflow", 667f2bc7e7fSblueswir1 [TT_CLRWIN] = "Clean Windows", 668f2bc7e7fSblueswir1 [TT_DIV_ZERO] = "Division By Zero", 669f2bc7e7fSblueswir1 [TT_DFAULT] = "Data Access Fault", 670f2bc7e7fSblueswir1 [TT_DMISS] = "Data Access MMU Miss", 671f2bc7e7fSblueswir1 [TT_DATA_ACCESS] = "Data Access Error", 672f2bc7e7fSblueswir1 [TT_DPROT] = "Data Protection Error", 673f2bc7e7fSblueswir1 [TT_UNALIGNED] = "Unaligned Memory Access", 674f2bc7e7fSblueswir1 [TT_PRIV_ACT] = "Privileged Action", 675f2bc7e7fSblueswir1 [TT_EXTINT | 0x1] = "External Interrupt 1", 676f2bc7e7fSblueswir1 [TT_EXTINT | 0x2] = "External Interrupt 2", 677f2bc7e7fSblueswir1 [TT_EXTINT | 0x3] = "External Interrupt 3", 678f2bc7e7fSblueswir1 [TT_EXTINT | 0x4] = "External Interrupt 4", 679f2bc7e7fSblueswir1 [TT_EXTINT | 0x5] = "External Interrupt 5", 680f2bc7e7fSblueswir1 [TT_EXTINT | 0x6] = "External Interrupt 6", 681f2bc7e7fSblueswir1 [TT_EXTINT | 0x7] = "External Interrupt 7", 682f2bc7e7fSblueswir1 [TT_EXTINT | 0x8] = "External Interrupt 8", 683f2bc7e7fSblueswir1 [TT_EXTINT | 0x9] = "External Interrupt 9", 684f2bc7e7fSblueswir1 [TT_EXTINT | 0xa] = "External Interrupt 10", 685f2bc7e7fSblueswir1 [TT_EXTINT | 0xb] = "External Interrupt 11", 686f2bc7e7fSblueswir1 [TT_EXTINT | 0xc] = "External Interrupt 12", 687f2bc7e7fSblueswir1 [TT_EXTINT | 0xd] = "External Interrupt 13", 688f2bc7e7fSblueswir1 [TT_EXTINT | 0xe] = "External Interrupt 14", 689f2bc7e7fSblueswir1 [TT_EXTINT | 0xf] = "External Interrupt 15", 690f2bc7e7fSblueswir1 }; 691f2bc7e7fSblueswir1 #endif 692f2bc7e7fSblueswir1 693f2bc7e7fSblueswir1 void do_interrupt(CPUState *env) 694f2bc7e7fSblueswir1 { 695f2bc7e7fSblueswir1 int intno = env->exception_index; 696f2bc7e7fSblueswir1 697f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 698f2bc7e7fSblueswir1 if (loglevel & CPU_LOG_INT) { 699f2bc7e7fSblueswir1 static int count; 700f2bc7e7fSblueswir1 const char *name; 701f2bc7e7fSblueswir1 702f2bc7e7fSblueswir1 if (intno < 0 || intno >= 0x180 || (intno > 0x4f && intno < 0x80)) 703f2bc7e7fSblueswir1 name = "Unknown"; 704f2bc7e7fSblueswir1 else if (intno >= 0x100) 705f2bc7e7fSblueswir1 name = "Trap Instruction"; 706f2bc7e7fSblueswir1 else if (intno >= 0xc0) 707f2bc7e7fSblueswir1 name = "Window Fill"; 708f2bc7e7fSblueswir1 else if (intno >= 0x80) 709f2bc7e7fSblueswir1 name = "Window Spill"; 710f2bc7e7fSblueswir1 else { 711f2bc7e7fSblueswir1 name = excp_names[intno]; 712f2bc7e7fSblueswir1 if (!name) 713f2bc7e7fSblueswir1 name = "Unknown"; 714f2bc7e7fSblueswir1 } 715f2bc7e7fSblueswir1 716f2bc7e7fSblueswir1 fprintf(logfile, "%6d: %s (v=%04x) pc=%016" PRIx64 " npc=%016" PRIx64 717f2bc7e7fSblueswir1 " SP=%016" PRIx64 "\n", 718f2bc7e7fSblueswir1 count, name, intno, 719f2bc7e7fSblueswir1 env->pc, 720f2bc7e7fSblueswir1 env->npc, env->regwptr[6]); 721f2bc7e7fSblueswir1 cpu_dump_state(env, logfile, fprintf, 0); 722f2bc7e7fSblueswir1 #if 0 723f2bc7e7fSblueswir1 { 724f2bc7e7fSblueswir1 int i; 725f2bc7e7fSblueswir1 uint8_t *ptr; 726f2bc7e7fSblueswir1 727f2bc7e7fSblueswir1 fprintf(logfile, " code="); 728f2bc7e7fSblueswir1 ptr = (uint8_t *)env->pc; 729f2bc7e7fSblueswir1 for(i = 0; i < 16; i++) { 730f2bc7e7fSblueswir1 fprintf(logfile, " %02x", ldub(ptr + i)); 731f2bc7e7fSblueswir1 } 732f2bc7e7fSblueswir1 fprintf(logfile, "\n"); 733f2bc7e7fSblueswir1 } 734f2bc7e7fSblueswir1 #endif 735f2bc7e7fSblueswir1 count++; 736f2bc7e7fSblueswir1 } 737f2bc7e7fSblueswir1 #endif 738f2bc7e7fSblueswir1 #if !defined(CONFIG_USER_ONLY) 739f2bc7e7fSblueswir1 if (env->tl == MAXTL) { 740f2bc7e7fSblueswir1 cpu_abort(env, "Trap 0x%04x while trap level is MAXTL, Error state", 741f2bc7e7fSblueswir1 env->exception_index); 742f2bc7e7fSblueswir1 return; 743f2bc7e7fSblueswir1 } 744f2bc7e7fSblueswir1 #endif 745f2bc7e7fSblueswir1 env->tsptr->tstate = ((uint64_t)GET_CCR(env) << 32) | 746f2bc7e7fSblueswir1 ((env->asi & 0xff) << 24) | ((env->pstate & 0xf3f) << 8) | 747f2bc7e7fSblueswir1 GET_CWP64(env); 748f2bc7e7fSblueswir1 env->tsptr->tpc = env->pc; 749f2bc7e7fSblueswir1 env->tsptr->tnpc = env->npc; 750f2bc7e7fSblueswir1 env->tsptr->tt = intno; 751f2bc7e7fSblueswir1 change_pstate(PS_PEF | PS_PRIV | PS_AG); 752f2bc7e7fSblueswir1 753f2bc7e7fSblueswir1 if (intno == TT_CLRWIN) 7541a14026eSblueswir1 cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - 1)); 755f2bc7e7fSblueswir1 else if ((intno & 0x1c0) == TT_SPILL) 7561a14026eSblueswir1 cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2)); 757f2bc7e7fSblueswir1 else if ((intno & 0x1c0) == TT_FILL) 7581a14026eSblueswir1 cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1)); 759f2bc7e7fSblueswir1 env->tbr &= ~0x7fffULL; 760f2bc7e7fSblueswir1 env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5); 761f2bc7e7fSblueswir1 if (env->tl < MAXTL - 1) { 762f2bc7e7fSblueswir1 env->tl++; 763f2bc7e7fSblueswir1 } else { 764f2bc7e7fSblueswir1 env->pstate |= PS_RED; 765f2bc7e7fSblueswir1 if (env->tl != MAXTL) 766f2bc7e7fSblueswir1 env->tl++; 767f2bc7e7fSblueswir1 } 768f2bc7e7fSblueswir1 env->tsptr = &env->ts[env->tl]; 769f2bc7e7fSblueswir1 env->pc = env->tbr; 770f2bc7e7fSblueswir1 env->npc = env->pc + 4; 771f2bc7e7fSblueswir1 env->exception_index = 0; 772f2bc7e7fSblueswir1 } 773f2bc7e7fSblueswir1 #else 774f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 775f2bc7e7fSblueswir1 static const char * const excp_names[0x80] = { 776f2bc7e7fSblueswir1 [TT_TFAULT] = "Instruction Access Fault", 777f2bc7e7fSblueswir1 [TT_ILL_INSN] = "Illegal Instruction", 778f2bc7e7fSblueswir1 [TT_PRIV_INSN] = "Privileged Instruction", 779f2bc7e7fSblueswir1 [TT_NFPU_INSN] = "FPU Disabled", 780f2bc7e7fSblueswir1 [TT_WIN_OVF] = "Window Overflow", 781f2bc7e7fSblueswir1 [TT_WIN_UNF] = "Window Underflow", 782f2bc7e7fSblueswir1 [TT_UNALIGNED] = "Unaligned Memory Access", 783f2bc7e7fSblueswir1 [TT_FP_EXCP] = "FPU Exception", 784f2bc7e7fSblueswir1 [TT_DFAULT] = "Data Access Fault", 785f2bc7e7fSblueswir1 [TT_TOVF] = "Tag Overflow", 786f2bc7e7fSblueswir1 [TT_EXTINT | 0x1] = "External Interrupt 1", 787f2bc7e7fSblueswir1 [TT_EXTINT | 0x2] = "External Interrupt 2", 788f2bc7e7fSblueswir1 [TT_EXTINT | 0x3] = "External Interrupt 3", 789f2bc7e7fSblueswir1 [TT_EXTINT | 0x4] = "External Interrupt 4", 790f2bc7e7fSblueswir1 [TT_EXTINT | 0x5] = "External Interrupt 5", 791f2bc7e7fSblueswir1 [TT_EXTINT | 0x6] = "External Interrupt 6", 792f2bc7e7fSblueswir1 [TT_EXTINT | 0x7] = "External Interrupt 7", 793f2bc7e7fSblueswir1 [TT_EXTINT | 0x8] = "External Interrupt 8", 794f2bc7e7fSblueswir1 [TT_EXTINT | 0x9] = "External Interrupt 9", 795f2bc7e7fSblueswir1 [TT_EXTINT | 0xa] = "External Interrupt 10", 796f2bc7e7fSblueswir1 [TT_EXTINT | 0xb] = "External Interrupt 11", 797f2bc7e7fSblueswir1 [TT_EXTINT | 0xc] = "External Interrupt 12", 798f2bc7e7fSblueswir1 [TT_EXTINT | 0xd] = "External Interrupt 13", 799f2bc7e7fSblueswir1 [TT_EXTINT | 0xe] = "External Interrupt 14", 800f2bc7e7fSblueswir1 [TT_EXTINT | 0xf] = "External Interrupt 15", 801f2bc7e7fSblueswir1 [TT_TOVF] = "Tag Overflow", 802f2bc7e7fSblueswir1 [TT_CODE_ACCESS] = "Instruction Access Error", 803f2bc7e7fSblueswir1 [TT_DATA_ACCESS] = "Data Access Error", 804f2bc7e7fSblueswir1 [TT_DIV_ZERO] = "Division By Zero", 805f2bc7e7fSblueswir1 [TT_NCP_INSN] = "Coprocessor Disabled", 806f2bc7e7fSblueswir1 }; 807f2bc7e7fSblueswir1 #endif 808f2bc7e7fSblueswir1 809f2bc7e7fSblueswir1 void do_interrupt(CPUState *env) 810f2bc7e7fSblueswir1 { 811f2bc7e7fSblueswir1 int cwp, intno = env->exception_index; 812f2bc7e7fSblueswir1 813f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 814f2bc7e7fSblueswir1 if (loglevel & CPU_LOG_INT) { 815f2bc7e7fSblueswir1 static int count; 816f2bc7e7fSblueswir1 const char *name; 817f2bc7e7fSblueswir1 818f2bc7e7fSblueswir1 if (intno < 0 || intno >= 0x100) 819f2bc7e7fSblueswir1 name = "Unknown"; 820f2bc7e7fSblueswir1 else if (intno >= 0x80) 821f2bc7e7fSblueswir1 name = "Trap Instruction"; 822f2bc7e7fSblueswir1 else { 823f2bc7e7fSblueswir1 name = excp_names[intno]; 824f2bc7e7fSblueswir1 if (!name) 825f2bc7e7fSblueswir1 name = "Unknown"; 826f2bc7e7fSblueswir1 } 827f2bc7e7fSblueswir1 828f2bc7e7fSblueswir1 fprintf(logfile, "%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n", 829f2bc7e7fSblueswir1 count, name, intno, 830f2bc7e7fSblueswir1 env->pc, 831f2bc7e7fSblueswir1 env->npc, env->regwptr[6]); 832f2bc7e7fSblueswir1 cpu_dump_state(env, logfile, fprintf, 0); 833f2bc7e7fSblueswir1 #if 0 834f2bc7e7fSblueswir1 { 835f2bc7e7fSblueswir1 int i; 836f2bc7e7fSblueswir1 uint8_t *ptr; 837f2bc7e7fSblueswir1 838f2bc7e7fSblueswir1 fprintf(logfile, " code="); 839f2bc7e7fSblueswir1 ptr = (uint8_t *)env->pc; 840f2bc7e7fSblueswir1 for(i = 0; i < 16; i++) { 841f2bc7e7fSblueswir1 fprintf(logfile, " %02x", ldub(ptr + i)); 842f2bc7e7fSblueswir1 } 843f2bc7e7fSblueswir1 fprintf(logfile, "\n"); 844f2bc7e7fSblueswir1 } 845f2bc7e7fSblueswir1 #endif 846f2bc7e7fSblueswir1 count++; 847f2bc7e7fSblueswir1 } 848f2bc7e7fSblueswir1 #endif 849f2bc7e7fSblueswir1 #if !defined(CONFIG_USER_ONLY) 850f2bc7e7fSblueswir1 if (env->psret == 0) { 851f2bc7e7fSblueswir1 cpu_abort(env, "Trap 0x%02x while interrupts disabled, Error state", 852f2bc7e7fSblueswir1 env->exception_index); 853f2bc7e7fSblueswir1 return; 854f2bc7e7fSblueswir1 } 855f2bc7e7fSblueswir1 #endif 856f2bc7e7fSblueswir1 env->psret = 0; 8571a14026eSblueswir1 cwp = cpu_cwp_dec(env, env->cwp - 1); 858f2bc7e7fSblueswir1 cpu_set_cwp(env, cwp); 859f2bc7e7fSblueswir1 env->regwptr[9] = env->pc; 860f2bc7e7fSblueswir1 env->regwptr[10] = env->npc; 861f2bc7e7fSblueswir1 env->psrps = env->psrs; 862f2bc7e7fSblueswir1 env->psrs = 1; 863f2bc7e7fSblueswir1 env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4); 864f2bc7e7fSblueswir1 env->pc = env->tbr; 865f2bc7e7fSblueswir1 env->npc = env->pc + 4; 866f2bc7e7fSblueswir1 env->exception_index = 0; 867f2bc7e7fSblueswir1 } 868f2bc7e7fSblueswir1 #endif 869f2bc7e7fSblueswir1 87024741ef3Sbellard void memcpy32(target_ulong *dst, const target_ulong *src) 87124741ef3Sbellard { 87224741ef3Sbellard dst[0] = src[0]; 87324741ef3Sbellard dst[1] = src[1]; 87424741ef3Sbellard dst[2] = src[2]; 87524741ef3Sbellard dst[3] = src[3]; 87624741ef3Sbellard dst[4] = src[4]; 87724741ef3Sbellard dst[5] = src[5]; 87824741ef3Sbellard dst[6] = src[6]; 87924741ef3Sbellard dst[7] = src[7]; 88024741ef3Sbellard } 88187ecb68bSpbrook 882c48fcb47Sblueswir1 void cpu_reset(CPUSPARCState *env) 883c48fcb47Sblueswir1 { 884c48fcb47Sblueswir1 tlb_flush(env, 1); 885c48fcb47Sblueswir1 env->cwp = 0; 886c48fcb47Sblueswir1 env->wim = 1; 887c48fcb47Sblueswir1 env->regwptr = env->regbase + (env->cwp * 16); 888c48fcb47Sblueswir1 #if defined(CONFIG_USER_ONLY) 889c48fcb47Sblueswir1 env->user_mode_only = 1; 890c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 8911a14026eSblueswir1 env->cleanwin = env->nwindows - 2; 8921a14026eSblueswir1 env->cansave = env->nwindows - 2; 893c48fcb47Sblueswir1 env->pstate = PS_RMO | PS_PEF | PS_IE; 894c48fcb47Sblueswir1 env->asi = 0x82; // Primary no-fault 895c48fcb47Sblueswir1 #endif 896c48fcb47Sblueswir1 #else 897c48fcb47Sblueswir1 env->psret = 0; 898c48fcb47Sblueswir1 env->psrs = 1; 899c48fcb47Sblueswir1 env->psrps = 1; 900c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 901c48fcb47Sblueswir1 env->pstate = PS_PRIV; 902c48fcb47Sblueswir1 env->hpstate = HS_PRIV; 903c48fcb47Sblueswir1 env->pc = 0x1fff0000000ULL; 904c48fcb47Sblueswir1 env->tsptr = &env->ts[env->tl]; 905c48fcb47Sblueswir1 #else 906c48fcb47Sblueswir1 env->pc = 0; 907c48fcb47Sblueswir1 env->mmuregs[0] &= ~(MMU_E | MMU_NF); 908c48fcb47Sblueswir1 env->mmuregs[0] |= env->mmu_bm; 909c48fcb47Sblueswir1 #endif 910c48fcb47Sblueswir1 env->npc = env->pc + 4; 911c48fcb47Sblueswir1 #endif 912c48fcb47Sblueswir1 } 913c48fcb47Sblueswir1 91464a88d5dSblueswir1 static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model) 915c48fcb47Sblueswir1 { 91664a88d5dSblueswir1 sparc_def_t def1, *def = &def1; 917c48fcb47Sblueswir1 91864a88d5dSblueswir1 if (cpu_sparc_find_by_name(def, cpu_model) < 0) 91964a88d5dSblueswir1 return -1; 920c48fcb47Sblueswir1 92164a88d5dSblueswir1 env->features = def->features; 922c48fcb47Sblueswir1 env->cpu_model_str = cpu_model; 923c48fcb47Sblueswir1 env->version = def->iu_version; 924c48fcb47Sblueswir1 env->fsr = def->fpu_version; 9251a14026eSblueswir1 env->nwindows = def->nwindows; 926c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64) 927c48fcb47Sblueswir1 env->mmu_bm = def->mmu_bm; 928c48fcb47Sblueswir1 env->mmu_ctpr_mask = def->mmu_ctpr_mask; 929c48fcb47Sblueswir1 env->mmu_cxr_mask = def->mmu_cxr_mask; 930c48fcb47Sblueswir1 env->mmu_sfsr_mask = def->mmu_sfsr_mask; 931c48fcb47Sblueswir1 env->mmu_trcr_mask = def->mmu_trcr_mask; 932c48fcb47Sblueswir1 env->mmuregs[0] |= def->mmu_version; 933c48fcb47Sblueswir1 cpu_sparc_set_id(env, 0); 9341a14026eSblueswir1 #else 9351a14026eSblueswir1 env->version |= def->nwindows - 1; 936c48fcb47Sblueswir1 #endif 93764a88d5dSblueswir1 return 0; 93864a88d5dSblueswir1 } 93964a88d5dSblueswir1 94064a88d5dSblueswir1 static void cpu_sparc_close(CPUSPARCState *env) 94164a88d5dSblueswir1 { 94264a88d5dSblueswir1 free(env); 94364a88d5dSblueswir1 } 94464a88d5dSblueswir1 94564a88d5dSblueswir1 CPUSPARCState *cpu_sparc_init(const char *cpu_model) 94664a88d5dSblueswir1 { 94764a88d5dSblueswir1 CPUSPARCState *env; 94864a88d5dSblueswir1 94964a88d5dSblueswir1 env = qemu_mallocz(sizeof(CPUSPARCState)); 95064a88d5dSblueswir1 if (!env) 95164a88d5dSblueswir1 return NULL; 95264a88d5dSblueswir1 cpu_exec_init(env); 953c48fcb47Sblueswir1 954c48fcb47Sblueswir1 gen_intermediate_code_init(env); 955c48fcb47Sblueswir1 95664a88d5dSblueswir1 if (cpu_sparc_register(env, cpu_model) < 0) { 95764a88d5dSblueswir1 cpu_sparc_close(env); 95864a88d5dSblueswir1 return NULL; 95964a88d5dSblueswir1 } 960c48fcb47Sblueswir1 cpu_reset(env); 961c48fcb47Sblueswir1 962c48fcb47Sblueswir1 return env; 963c48fcb47Sblueswir1 } 964c48fcb47Sblueswir1 965c48fcb47Sblueswir1 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu) 966c48fcb47Sblueswir1 { 967c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64) 968c48fcb47Sblueswir1 env->mxccregs[7] = ((cpu + 8) & 0xf) << 24; 969c48fcb47Sblueswir1 #endif 970c48fcb47Sblueswir1 } 971c48fcb47Sblueswir1 972c48fcb47Sblueswir1 static const sparc_def_t sparc_defs[] = { 973c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 974c48fcb47Sblueswir1 { 975c48fcb47Sblueswir1 .name = "Fujitsu Sparc64", 976c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24) 9771a14026eSblueswir1 | (MAXTL << 8)), 978c48fcb47Sblueswir1 .fpu_version = 0x00000000, 979c48fcb47Sblueswir1 .mmu_version = 0, 9801a14026eSblueswir1 .nwindows = 4, 98164a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 982c48fcb47Sblueswir1 }, 983c48fcb47Sblueswir1 { 984c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 III", 985c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24) 9861a14026eSblueswir1 | (MAXTL << 8)), 987c48fcb47Sblueswir1 .fpu_version = 0x00000000, 988c48fcb47Sblueswir1 .mmu_version = 0, 9891a14026eSblueswir1 .nwindows = 5, 99064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 991c48fcb47Sblueswir1 }, 992c48fcb47Sblueswir1 { 993c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 IV", 994c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24) 9951a14026eSblueswir1 | (MAXTL << 8)), 996c48fcb47Sblueswir1 .fpu_version = 0x00000000, 997c48fcb47Sblueswir1 .mmu_version = 0, 9981a14026eSblueswir1 .nwindows = 8, 99964a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1000c48fcb47Sblueswir1 }, 1001c48fcb47Sblueswir1 { 1002c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 V", 1003c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24) 10041a14026eSblueswir1 | (MAXTL << 8)), 1005c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1006c48fcb47Sblueswir1 .mmu_version = 0, 10071a14026eSblueswir1 .nwindows = 8, 100864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1009c48fcb47Sblueswir1 }, 1010c48fcb47Sblueswir1 { 1011c48fcb47Sblueswir1 .name = "TI UltraSparc I", 1012c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24) 10131a14026eSblueswir1 | (MAXTL << 8)), 1014c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1015c48fcb47Sblueswir1 .mmu_version = 0, 10161a14026eSblueswir1 .nwindows = 8, 101764a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1018c48fcb47Sblueswir1 }, 1019c48fcb47Sblueswir1 { 1020c48fcb47Sblueswir1 .name = "TI UltraSparc II", 1021c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24) 10221a14026eSblueswir1 | (MAXTL << 8)), 1023c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1024c48fcb47Sblueswir1 .mmu_version = 0, 10251a14026eSblueswir1 .nwindows = 8, 102664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1027c48fcb47Sblueswir1 }, 1028c48fcb47Sblueswir1 { 1029c48fcb47Sblueswir1 .name = "TI UltraSparc IIi", 1030c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24) 10311a14026eSblueswir1 | (MAXTL << 8)), 1032c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1033c48fcb47Sblueswir1 .mmu_version = 0, 10341a14026eSblueswir1 .nwindows = 8, 103564a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1036c48fcb47Sblueswir1 }, 1037c48fcb47Sblueswir1 { 1038c48fcb47Sblueswir1 .name = "TI UltraSparc IIe", 1039c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24) 10401a14026eSblueswir1 | (MAXTL << 8)), 1041c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1042c48fcb47Sblueswir1 .mmu_version = 0, 10431a14026eSblueswir1 .nwindows = 8, 104464a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1045c48fcb47Sblueswir1 }, 1046c48fcb47Sblueswir1 { 1047c48fcb47Sblueswir1 .name = "Sun UltraSparc III", 1048c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24) 10491a14026eSblueswir1 | (MAXTL << 8)), 1050c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1051c48fcb47Sblueswir1 .mmu_version = 0, 10521a14026eSblueswir1 .nwindows = 8, 105364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1054c48fcb47Sblueswir1 }, 1055c48fcb47Sblueswir1 { 1056c48fcb47Sblueswir1 .name = "Sun UltraSparc III Cu", 1057c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24) 10581a14026eSblueswir1 | (MAXTL << 8)), 1059c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1060c48fcb47Sblueswir1 .mmu_version = 0, 10611a14026eSblueswir1 .nwindows = 8, 106264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1063c48fcb47Sblueswir1 }, 1064c48fcb47Sblueswir1 { 1065c48fcb47Sblueswir1 .name = "Sun UltraSparc IIIi", 1066c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24) 10671a14026eSblueswir1 | (MAXTL << 8)), 1068c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1069c48fcb47Sblueswir1 .mmu_version = 0, 10701a14026eSblueswir1 .nwindows = 8, 107164a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1072c48fcb47Sblueswir1 }, 1073c48fcb47Sblueswir1 { 1074c48fcb47Sblueswir1 .name = "Sun UltraSparc IV", 1075c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24) 10761a14026eSblueswir1 | (MAXTL << 8)), 1077c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1078c48fcb47Sblueswir1 .mmu_version = 0, 10791a14026eSblueswir1 .nwindows = 8, 108064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1081c48fcb47Sblueswir1 }, 1082c48fcb47Sblueswir1 { 1083c48fcb47Sblueswir1 .name = "Sun UltraSparc IV+", 1084c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24) 10851a14026eSblueswir1 | (MAXTL << 8)), 1086c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1087c48fcb47Sblueswir1 .mmu_version = 0, 10881a14026eSblueswir1 .nwindows = 8, 108964a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1090c48fcb47Sblueswir1 }, 1091c48fcb47Sblueswir1 { 1092c48fcb47Sblueswir1 .name = "Sun UltraSparc IIIi+", 1093c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24) 10941a14026eSblueswir1 | (MAXTL << 8)), 1095c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1096c48fcb47Sblueswir1 .mmu_version = 0, 10971a14026eSblueswir1 .nwindows = 8, 109864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1099c48fcb47Sblueswir1 }, 1100c48fcb47Sblueswir1 { 1101c48fcb47Sblueswir1 .name = "NEC UltraSparc I", 1102c48fcb47Sblueswir1 .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24) 11031a14026eSblueswir1 | (MAXTL << 8)), 1104c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1105c48fcb47Sblueswir1 .mmu_version = 0, 11061a14026eSblueswir1 .nwindows = 8, 110764a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1108c48fcb47Sblueswir1 }, 1109c48fcb47Sblueswir1 #else 1110c48fcb47Sblueswir1 { 1111c48fcb47Sblueswir1 .name = "Fujitsu MB86900", 1112c48fcb47Sblueswir1 .iu_version = 0x00 << 24, /* Impl 0, ver 0 */ 1113c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1114c48fcb47Sblueswir1 .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */ 1115c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1116c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1117c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1118c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1119c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11201a14026eSblueswir1 .nwindows = 7, 1121e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_FSMULD, 1122c48fcb47Sblueswir1 }, 1123c48fcb47Sblueswir1 { 1124c48fcb47Sblueswir1 .name = "Fujitsu MB86904", 1125c48fcb47Sblueswir1 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */ 1126c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1127c48fcb47Sblueswir1 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */ 1128c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1129c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1130c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1131c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1132c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 11331a14026eSblueswir1 .nwindows = 8, 113464a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1135c48fcb47Sblueswir1 }, 1136c48fcb47Sblueswir1 { 1137c48fcb47Sblueswir1 .name = "Fujitsu MB86907", 1138c48fcb47Sblueswir1 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */ 1139c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1140c48fcb47Sblueswir1 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */ 1141c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1142c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1143c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1144c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1145c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11461a14026eSblueswir1 .nwindows = 8, 114764a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1148c48fcb47Sblueswir1 }, 1149c48fcb47Sblueswir1 { 1150c48fcb47Sblueswir1 .name = "LSI L64811", 1151c48fcb47Sblueswir1 .iu_version = 0x10 << 24, /* Impl 1, ver 0 */ 1152c48fcb47Sblueswir1 .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */ 1153c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1154c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1155c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1156c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1157c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1158c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11591a14026eSblueswir1 .nwindows = 8, 1160e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1161e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1162c48fcb47Sblueswir1 }, 1163c48fcb47Sblueswir1 { 1164c48fcb47Sblueswir1 .name = "Cypress CY7C601", 1165c48fcb47Sblueswir1 .iu_version = 0x11 << 24, /* Impl 1, ver 1 */ 1166c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ 1167c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1168c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1169c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1170c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1171c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1172c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11731a14026eSblueswir1 .nwindows = 8, 1174e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1175e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1176c48fcb47Sblueswir1 }, 1177c48fcb47Sblueswir1 { 1178c48fcb47Sblueswir1 .name = "Cypress CY7C611", 1179c48fcb47Sblueswir1 .iu_version = 0x13 << 24, /* Impl 1, ver 3 */ 1180c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ 1181c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1182c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1183c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1184c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1185c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1186c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11871a14026eSblueswir1 .nwindows = 8, 1188e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1189e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1190c48fcb47Sblueswir1 }, 1191c48fcb47Sblueswir1 { 1192c48fcb47Sblueswir1 .name = "TI SuperSparc II", 1193c48fcb47Sblueswir1 .iu_version = 0x40000000, 1194c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1195c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1196c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1197c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1198c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1199c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1200c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12011a14026eSblueswir1 .nwindows = 8, 120264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1203c48fcb47Sblueswir1 }, 1204c48fcb47Sblueswir1 { 1205c48fcb47Sblueswir1 .name = "TI MicroSparc I", 1206c48fcb47Sblueswir1 .iu_version = 0x41000000, 1207c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1208c48fcb47Sblueswir1 .mmu_version = 0x41000000, 1209c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1210c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1211c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1212c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1213c48fcb47Sblueswir1 .mmu_trcr_mask = 0x0000003f, 12141a14026eSblueswir1 .nwindows = 7, 1215e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL | 1216e30b4678Sblueswir1 CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | 1217e30b4678Sblueswir1 CPU_FEATURE_FMUL, 1218c48fcb47Sblueswir1 }, 1219c48fcb47Sblueswir1 { 1220c48fcb47Sblueswir1 .name = "TI MicroSparc II", 1221c48fcb47Sblueswir1 .iu_version = 0x42000000, 1222c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1223c48fcb47Sblueswir1 .mmu_version = 0x02000000, 1224c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1225c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1226c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1227c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1228c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 12291a14026eSblueswir1 .nwindows = 8, 123064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1231c48fcb47Sblueswir1 }, 1232c48fcb47Sblueswir1 { 1233c48fcb47Sblueswir1 .name = "TI MicroSparc IIep", 1234c48fcb47Sblueswir1 .iu_version = 0x42000000, 1235c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1236c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1237c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1238c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1239c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1240c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016bff, 1241c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 12421a14026eSblueswir1 .nwindows = 8, 124364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1244c48fcb47Sblueswir1 }, 1245c48fcb47Sblueswir1 { 1246b5154bdeSblueswir1 .name = "TI SuperSparc 40", // STP1020NPGA 1247b5154bdeSblueswir1 .iu_version = 0x41000000, 1248b5154bdeSblueswir1 .fpu_version = 0 << 17, 1249b5154bdeSblueswir1 .mmu_version = 0x00000000, 1250b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1251b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1252b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1253b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1254b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 12551a14026eSblueswir1 .nwindows = 8, 1256b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1257b5154bdeSblueswir1 }, 1258b5154bdeSblueswir1 { 1259b5154bdeSblueswir1 .name = "TI SuperSparc 50", // STP1020PGA 1260b5154bdeSblueswir1 .iu_version = 0x40000000, 1261b5154bdeSblueswir1 .fpu_version = 0 << 17, 1262b5154bdeSblueswir1 .mmu_version = 0x04000000, 1263b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1264b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1265b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1266b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1267b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 12681a14026eSblueswir1 .nwindows = 8, 1269b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1270b5154bdeSblueswir1 }, 1271b5154bdeSblueswir1 { 1272c48fcb47Sblueswir1 .name = "TI SuperSparc 51", 1273c48fcb47Sblueswir1 .iu_version = 0x43000000, 1274c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1275c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1276c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1277c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1278c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1279c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1280c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12811a14026eSblueswir1 .nwindows = 8, 128264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1283c48fcb47Sblueswir1 }, 1284c48fcb47Sblueswir1 { 1285b5154bdeSblueswir1 .name = "TI SuperSparc 60", // STP1020APGA 1286b5154bdeSblueswir1 .iu_version = 0x40000000, 1287b5154bdeSblueswir1 .fpu_version = 0 << 17, 1288b5154bdeSblueswir1 .mmu_version = 0x03000000, 1289b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1290b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1291b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1292b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1293b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 12941a14026eSblueswir1 .nwindows = 8, 1295b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1296b5154bdeSblueswir1 }, 1297b5154bdeSblueswir1 { 1298c48fcb47Sblueswir1 .name = "TI SuperSparc 61", 1299c48fcb47Sblueswir1 .iu_version = 0x44000000, 1300c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1301c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1302c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1303c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1304c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1305c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1306c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13071a14026eSblueswir1 .nwindows = 8, 130864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1309c48fcb47Sblueswir1 }, 1310c48fcb47Sblueswir1 { 1311c48fcb47Sblueswir1 .name = "Ross RT625", 1312c48fcb47Sblueswir1 .iu_version = 0x1e000000, 1313c48fcb47Sblueswir1 .fpu_version = 1 << 17, 1314c48fcb47Sblueswir1 .mmu_version = 0x1e000000, 1315c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1316c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1317c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1318c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1319c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13201a14026eSblueswir1 .nwindows = 8, 132164a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1322c48fcb47Sblueswir1 }, 1323c48fcb47Sblueswir1 { 1324c48fcb47Sblueswir1 .name = "Ross RT620", 1325c48fcb47Sblueswir1 .iu_version = 0x1f000000, 1326c48fcb47Sblueswir1 .fpu_version = 1 << 17, 1327c48fcb47Sblueswir1 .mmu_version = 0x1f000000, 1328c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1329c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1330c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1331c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1332c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13331a14026eSblueswir1 .nwindows = 8, 133464a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1335c48fcb47Sblueswir1 }, 1336c48fcb47Sblueswir1 { 1337c48fcb47Sblueswir1 .name = "BIT B5010", 1338c48fcb47Sblueswir1 .iu_version = 0x20000000, 1339c48fcb47Sblueswir1 .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */ 1340c48fcb47Sblueswir1 .mmu_version = 0x20000000, 1341c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1342c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1343c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1344c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1345c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13461a14026eSblueswir1 .nwindows = 8, 1347e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1348e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1349c48fcb47Sblueswir1 }, 1350c48fcb47Sblueswir1 { 1351c48fcb47Sblueswir1 .name = "Matsushita MN10501", 1352c48fcb47Sblueswir1 .iu_version = 0x50000000, 1353c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1354c48fcb47Sblueswir1 .mmu_version = 0x50000000, 1355c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1356c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1357c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1358c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1359c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13601a14026eSblueswir1 .nwindows = 8, 1361e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_MUL | CPU_FEATURE_FSQRT | 1362e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1363c48fcb47Sblueswir1 }, 1364c48fcb47Sblueswir1 { 1365c48fcb47Sblueswir1 .name = "Weitek W8601", 1366c48fcb47Sblueswir1 .iu_version = 0x90 << 24, /* Impl 9, ver 0 */ 1367c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */ 1368c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1369c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1370c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1371c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1372c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1373c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13741a14026eSblueswir1 .nwindows = 8, 137564a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1376c48fcb47Sblueswir1 }, 1377c48fcb47Sblueswir1 { 1378c48fcb47Sblueswir1 .name = "LEON2", 1379c48fcb47Sblueswir1 .iu_version = 0xf2000000, 1380c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1381c48fcb47Sblueswir1 .mmu_version = 0xf2000000, 1382c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1383c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1384c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1385c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1386c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13871a14026eSblueswir1 .nwindows = 8, 138864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1389c48fcb47Sblueswir1 }, 1390c48fcb47Sblueswir1 { 1391c48fcb47Sblueswir1 .name = "LEON3", 1392c48fcb47Sblueswir1 .iu_version = 0xf3000000, 1393c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1394c48fcb47Sblueswir1 .mmu_version = 0xf3000000, 1395c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1396c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1397c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1398c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1399c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 14001a14026eSblueswir1 .nwindows = 8, 140164a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1402c48fcb47Sblueswir1 }, 1403c48fcb47Sblueswir1 #endif 1404c48fcb47Sblueswir1 }; 1405c48fcb47Sblueswir1 140664a88d5dSblueswir1 static const char * const feature_name[] = { 140764a88d5dSblueswir1 "float", 140864a88d5dSblueswir1 "float128", 140964a88d5dSblueswir1 "swap", 141064a88d5dSblueswir1 "mul", 141164a88d5dSblueswir1 "div", 141264a88d5dSblueswir1 "flush", 141364a88d5dSblueswir1 "fsqrt", 141464a88d5dSblueswir1 "fmul", 141564a88d5dSblueswir1 "vis1", 141664a88d5dSblueswir1 "vis2", 1417e30b4678Sblueswir1 "fsmuld", 141864a88d5dSblueswir1 }; 141964a88d5dSblueswir1 142064a88d5dSblueswir1 static void print_features(FILE *f, 142164a88d5dSblueswir1 int (*cpu_fprintf)(FILE *f, const char *fmt, ...), 142264a88d5dSblueswir1 uint32_t features, const char *prefix) 1423c48fcb47Sblueswir1 { 1424c48fcb47Sblueswir1 unsigned int i; 1425c48fcb47Sblueswir1 142664a88d5dSblueswir1 for (i = 0; i < ARRAY_SIZE(feature_name); i++) 142764a88d5dSblueswir1 if (feature_name[i] && (features & (1 << i))) { 142864a88d5dSblueswir1 if (prefix) 142964a88d5dSblueswir1 (*cpu_fprintf)(f, "%s", prefix); 143064a88d5dSblueswir1 (*cpu_fprintf)(f, "%s ", feature_name[i]); 143164a88d5dSblueswir1 } 143264a88d5dSblueswir1 } 143364a88d5dSblueswir1 143464a88d5dSblueswir1 static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features) 143564a88d5dSblueswir1 { 143664a88d5dSblueswir1 unsigned int i; 143764a88d5dSblueswir1 143864a88d5dSblueswir1 for (i = 0; i < ARRAY_SIZE(feature_name); i++) 143964a88d5dSblueswir1 if (feature_name[i] && !strcmp(flagname, feature_name[i])) { 144064a88d5dSblueswir1 *features |= 1 << i; 144164a88d5dSblueswir1 return; 144264a88d5dSblueswir1 } 144364a88d5dSblueswir1 fprintf(stderr, "CPU feature %s not found\n", flagname); 144464a88d5dSblueswir1 } 144564a88d5dSblueswir1 144622548760Sblueswir1 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model) 144764a88d5dSblueswir1 { 144864a88d5dSblueswir1 unsigned int i; 144964a88d5dSblueswir1 const sparc_def_t *def = NULL; 145064a88d5dSblueswir1 char *s = strdup(cpu_model); 145164a88d5dSblueswir1 char *featurestr, *name = strtok(s, ","); 145264a88d5dSblueswir1 uint32_t plus_features = 0; 145364a88d5dSblueswir1 uint32_t minus_features = 0; 145464a88d5dSblueswir1 long long iu_version; 14551a14026eSblueswir1 uint32_t fpu_version, mmu_version, nwindows; 145664a88d5dSblueswir1 1457c48fcb47Sblueswir1 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) { 1458c48fcb47Sblueswir1 if (strcasecmp(name, sparc_defs[i].name) == 0) { 145964a88d5dSblueswir1 def = &sparc_defs[i]; 1460c48fcb47Sblueswir1 } 1461c48fcb47Sblueswir1 } 146264a88d5dSblueswir1 if (!def) 146364a88d5dSblueswir1 goto error; 146464a88d5dSblueswir1 memcpy(cpu_def, def, sizeof(*def)); 146564a88d5dSblueswir1 146664a88d5dSblueswir1 featurestr = strtok(NULL, ","); 146764a88d5dSblueswir1 while (featurestr) { 146864a88d5dSblueswir1 char *val; 146964a88d5dSblueswir1 147064a88d5dSblueswir1 if (featurestr[0] == '+') { 147164a88d5dSblueswir1 add_flagname_to_bitmaps(featurestr + 1, &plus_features); 147264a88d5dSblueswir1 } else if (featurestr[0] == '-') { 147364a88d5dSblueswir1 add_flagname_to_bitmaps(featurestr + 1, &minus_features); 147464a88d5dSblueswir1 } else if ((val = strchr(featurestr, '='))) { 147564a88d5dSblueswir1 *val = 0; val++; 147664a88d5dSblueswir1 if (!strcmp(featurestr, "iu_version")) { 147764a88d5dSblueswir1 char *err; 147864a88d5dSblueswir1 147964a88d5dSblueswir1 iu_version = strtoll(val, &err, 0); 148064a88d5dSblueswir1 if (!*val || *err) { 148164a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 148264a88d5dSblueswir1 goto error; 148364a88d5dSblueswir1 } 148464a88d5dSblueswir1 cpu_def->iu_version = iu_version; 148564a88d5dSblueswir1 #ifdef DEBUG_FEATURES 148664a88d5dSblueswir1 fprintf(stderr, "iu_version %llx\n", iu_version); 148764a88d5dSblueswir1 #endif 148864a88d5dSblueswir1 } else if (!strcmp(featurestr, "fpu_version")) { 148964a88d5dSblueswir1 char *err; 149064a88d5dSblueswir1 149164a88d5dSblueswir1 fpu_version = strtol(val, &err, 0); 149264a88d5dSblueswir1 if (!*val || *err) { 149364a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 149464a88d5dSblueswir1 goto error; 149564a88d5dSblueswir1 } 149664a88d5dSblueswir1 cpu_def->fpu_version = fpu_version; 149764a88d5dSblueswir1 #ifdef DEBUG_FEATURES 149864a88d5dSblueswir1 fprintf(stderr, "fpu_version %llx\n", fpu_version); 149964a88d5dSblueswir1 #endif 150064a88d5dSblueswir1 } else if (!strcmp(featurestr, "mmu_version")) { 150164a88d5dSblueswir1 char *err; 150264a88d5dSblueswir1 150364a88d5dSblueswir1 mmu_version = strtol(val, &err, 0); 150464a88d5dSblueswir1 if (!*val || *err) { 150564a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 150664a88d5dSblueswir1 goto error; 150764a88d5dSblueswir1 } 150864a88d5dSblueswir1 cpu_def->mmu_version = mmu_version; 150964a88d5dSblueswir1 #ifdef DEBUG_FEATURES 151064a88d5dSblueswir1 fprintf(stderr, "mmu_version %llx\n", mmu_version); 151164a88d5dSblueswir1 #endif 15121a14026eSblueswir1 } else if (!strcmp(featurestr, "nwindows")) { 15131a14026eSblueswir1 char *err; 15141a14026eSblueswir1 15151a14026eSblueswir1 nwindows = strtol(val, &err, 0); 15161a14026eSblueswir1 if (!*val || *err || nwindows > MAX_NWINDOWS || 15171a14026eSblueswir1 nwindows < MIN_NWINDOWS) { 15181a14026eSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 15191a14026eSblueswir1 goto error; 15201a14026eSblueswir1 } 15211a14026eSblueswir1 cpu_def->nwindows = nwindows; 15221a14026eSblueswir1 #ifdef DEBUG_FEATURES 15231a14026eSblueswir1 fprintf(stderr, "nwindows %d\n", nwindows); 15241a14026eSblueswir1 #endif 152564a88d5dSblueswir1 } else { 152664a88d5dSblueswir1 fprintf(stderr, "unrecognized feature %s\n", featurestr); 152764a88d5dSblueswir1 goto error; 152864a88d5dSblueswir1 } 152964a88d5dSblueswir1 } else { 153077f193daSblueswir1 fprintf(stderr, "feature string `%s' not in format " 153177f193daSblueswir1 "(+feature|-feature|feature=xyz)\n", featurestr); 153264a88d5dSblueswir1 goto error; 153364a88d5dSblueswir1 } 153464a88d5dSblueswir1 featurestr = strtok(NULL, ","); 153564a88d5dSblueswir1 } 153664a88d5dSblueswir1 cpu_def->features |= plus_features; 153764a88d5dSblueswir1 cpu_def->features &= ~minus_features; 153864a88d5dSblueswir1 #ifdef DEBUG_FEATURES 153964a88d5dSblueswir1 print_features(stderr, fprintf, cpu_def->features, NULL); 154064a88d5dSblueswir1 #endif 154164a88d5dSblueswir1 free(s); 154264a88d5dSblueswir1 return 0; 154364a88d5dSblueswir1 154464a88d5dSblueswir1 error: 154564a88d5dSblueswir1 free(s); 154664a88d5dSblueswir1 return -1; 1547c48fcb47Sblueswir1 } 1548c48fcb47Sblueswir1 1549c48fcb47Sblueswir1 void sparc_cpu_list(FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...)) 1550c48fcb47Sblueswir1 { 1551c48fcb47Sblueswir1 unsigned int i; 1552c48fcb47Sblueswir1 1553c48fcb47Sblueswir1 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) { 15541a14026eSblueswir1 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x NWINS %d ", 1555c48fcb47Sblueswir1 sparc_defs[i].name, 1556c48fcb47Sblueswir1 sparc_defs[i].iu_version, 1557c48fcb47Sblueswir1 sparc_defs[i].fpu_version, 15581a14026eSblueswir1 sparc_defs[i].mmu_version, 15591a14026eSblueswir1 sparc_defs[i].nwindows); 156077f193daSblueswir1 print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES & 156177f193daSblueswir1 ~sparc_defs[i].features, "-"); 156277f193daSblueswir1 print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES & 156377f193daSblueswir1 sparc_defs[i].features, "+"); 156464a88d5dSblueswir1 (*cpu_fprintf)(f, "\n"); 1565c48fcb47Sblueswir1 } 156664a88d5dSblueswir1 (*cpu_fprintf)(f, "CPU feature flags (+/-): "); 156764a88d5dSblueswir1 print_features(f, cpu_fprintf, -1, NULL); 156864a88d5dSblueswir1 (*cpu_fprintf)(f, "\n"); 156977f193daSblueswir1 (*cpu_fprintf)(f, "Numerical features (=): iu_version fpu_version " 15701a14026eSblueswir1 "mmu_version nwindows\n"); 1571c48fcb47Sblueswir1 } 1572c48fcb47Sblueswir1 1573c48fcb47Sblueswir1 #define GET_FLAG(a,b) ((env->psr & a)?b:'-') 1574c48fcb47Sblueswir1 1575c48fcb47Sblueswir1 void cpu_dump_state(CPUState *env, FILE *f, 1576c48fcb47Sblueswir1 int (*cpu_fprintf)(FILE *f, const char *fmt, ...), 1577c48fcb47Sblueswir1 int flags) 1578c48fcb47Sblueswir1 { 1579c48fcb47Sblueswir1 int i, x; 1580c48fcb47Sblueswir1 158177f193daSblueswir1 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, 158277f193daSblueswir1 env->npc); 1583c48fcb47Sblueswir1 cpu_fprintf(f, "General Registers:\n"); 1584c48fcb47Sblueswir1 for (i = 0; i < 4; i++) 1585c48fcb47Sblueswir1 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]); 1586c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1587c48fcb47Sblueswir1 for (; i < 8; i++) 1588c48fcb47Sblueswir1 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]); 1589c48fcb47Sblueswir1 cpu_fprintf(f, "\nCurrent Register Window:\n"); 1590c48fcb47Sblueswir1 for (x = 0; x < 3; x++) { 1591c48fcb47Sblueswir1 for (i = 0; i < 4; i++) 1592c48fcb47Sblueswir1 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t", 1593c48fcb47Sblueswir1 (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i, 1594c48fcb47Sblueswir1 env->regwptr[i + x * 8]); 1595c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1596c48fcb47Sblueswir1 for (; i < 8; i++) 1597c48fcb47Sblueswir1 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t", 1598c48fcb47Sblueswir1 (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i, 1599c48fcb47Sblueswir1 env->regwptr[i + x * 8]); 1600c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1601c48fcb47Sblueswir1 } 1602c48fcb47Sblueswir1 cpu_fprintf(f, "\nFloating Point Registers:\n"); 1603c48fcb47Sblueswir1 for (i = 0; i < 32; i++) { 1604c48fcb47Sblueswir1 if ((i & 3) == 0) 1605c48fcb47Sblueswir1 cpu_fprintf(f, "%%f%02d:", i); 1606c48fcb47Sblueswir1 cpu_fprintf(f, " %016lf", env->fpr[i]); 1607c48fcb47Sblueswir1 if ((i & 3) == 3) 1608c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1609c48fcb47Sblueswir1 } 1610c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 1611c48fcb47Sblueswir1 cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n", 1612c48fcb47Sblueswir1 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs); 161377f193daSblueswir1 cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d " 161477f193daSblueswir1 "cleanwin %d cwp %d\n", 1615c48fcb47Sblueswir1 env->cansave, env->canrestore, env->otherwin, env->wstate, 16161a14026eSblueswir1 env->cleanwin, env->nwindows - 1 - env->cwp); 1617c48fcb47Sblueswir1 #else 161877f193daSblueswir1 cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", 161977f193daSblueswir1 GET_PSR(env), GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'), 1620c48fcb47Sblueswir1 GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'), 1621c48fcb47Sblueswir1 env->psrs?'S':'-', env->psrps?'P':'-', 1622c48fcb47Sblueswir1 env->psret?'E':'-', env->wim); 1623c48fcb47Sblueswir1 #endif 1624c48fcb47Sblueswir1 cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env)); 1625c48fcb47Sblueswir1 } 1626c48fcb47Sblueswir1 162787ecb68bSpbrook #ifdef TARGET_SPARC64 162887ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 162987ecb68bSpbrook #include "qemu-common.h" 163087ecb68bSpbrook #include "hw/irq.h" 163187ecb68bSpbrook #include "qemu-timer.h" 163287ecb68bSpbrook #endif 163387ecb68bSpbrook 1634ccd4a219Sblueswir1 void helper_tick_set_count(void *opaque, uint64_t count) 163587ecb68bSpbrook { 163687ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 163787ecb68bSpbrook ptimer_set_count(opaque, -count); 163887ecb68bSpbrook #endif 163987ecb68bSpbrook } 164087ecb68bSpbrook 1641ccd4a219Sblueswir1 uint64_t helper_tick_get_count(void *opaque) 164287ecb68bSpbrook { 164387ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 164487ecb68bSpbrook return -ptimer_get_count(opaque); 164587ecb68bSpbrook #else 164687ecb68bSpbrook return 0; 164787ecb68bSpbrook #endif 164887ecb68bSpbrook } 164987ecb68bSpbrook 1650ccd4a219Sblueswir1 void helper_tick_set_limit(void *opaque, uint64_t limit) 165187ecb68bSpbrook { 165287ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 165387ecb68bSpbrook ptimer_set_limit(opaque, -limit, 0); 165487ecb68bSpbrook #endif 165587ecb68bSpbrook } 165687ecb68bSpbrook #endif 1657