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] = { 90a764a566Sblueswir1 { 0, 0, 0, 0, 8, 0, 12, 12 }, 91a764a566Sblueswir1 { 0, 0, 0, 0, 8, 0, 0, 0 }, 92a764a566Sblueswir1 { 8, 8, 0, 0, 0, 8, 12, 12 }, 93a764a566Sblueswir1 { 8, 8, 0, 0, 0, 8, 0, 0 }, 94a764a566Sblueswir1 { 8, 0, 8, 0, 8, 8, 12, 12 }, 95a764a566Sblueswir1 { 8, 0, 8, 0, 8, 0, 8, 0 }, 96a764a566Sblueswir1 { 8, 8, 8, 0, 8, 8, 12, 12 }, 97a764a566Sblueswir1 { 8, 8, 8, 0, 8, 8, 8, 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 452f617a9a6Sblueswir1 env->dmmuregs[6] = (address & ~0x1fffULL) | (env->dmmuregs[1] & 0x1fff); 45383469015Sbellard env->exception_index = TT_DMISS; 4543475187dSbellard return 1; 4553475187dSbellard } 4563475187dSbellard 45777f193daSblueswir1 static int get_physical_address_code(CPUState *env, 45877f193daSblueswir1 target_phys_addr_t *physical, int *prot, 45922548760Sblueswir1 target_ulong address, int is_user) 4603475187dSbellard { 4613475187dSbellard target_ulong mask; 4623475187dSbellard unsigned int i; 4633475187dSbellard 4643475187dSbellard if ((env->lsu & IMMU_E) == 0) { /* IMMU disabled */ 46583469015Sbellard *physical = address; 466227671c9Sbellard *prot = PAGE_EXEC; 4673475187dSbellard return 0; 4683475187dSbellard } 46983469015Sbellard 4703475187dSbellard for (i = 0; i < 64; i++) { 47183469015Sbellard switch ((env->itlb_tte[i] >> 61) & 3) { 4723475187dSbellard default: 47383469015Sbellard case 0x0: // 8k 4743475187dSbellard mask = 0xffffffffffffe000ULL; 4753475187dSbellard break; 47683469015Sbellard case 0x1: // 64k 4773475187dSbellard mask = 0xffffffffffff0000ULL; 4783475187dSbellard break; 47983469015Sbellard case 0x2: // 512k 4803475187dSbellard mask = 0xfffffffffff80000ULL; 4813475187dSbellard break; 48283469015Sbellard case 0x3: // 4M 4833475187dSbellard mask = 0xffffffffffc00000ULL; 4843475187dSbellard break; 4853475187dSbellard } 4863475187dSbellard // ctx match, vaddr match? 48783469015Sbellard if (env->dmmuregs[1] == (env->itlb_tag[i] & 0x1fff) && 4883475187dSbellard (address & mask) == (env->itlb_tag[i] & ~0x1fffULL)) { 48983469015Sbellard // valid, access ok? 49083469015Sbellard if ((env->itlb_tte[i] & 0x8000000000000000ULL) == 0 || 49183469015Sbellard ((env->itlb_tte[i] & 0x4) && is_user)) { 49283469015Sbellard if (env->immuregs[3]) /* Fault status register */ 49377f193daSblueswir1 env->immuregs[3] = 2; /* overflow (not read before 49477f193daSblueswir1 another fault) */ 49583469015Sbellard env->immuregs[3] |= (is_user << 3) | 1; 4963475187dSbellard env->exception_index = TT_TFAULT; 49783469015Sbellard #ifdef DEBUG_MMU 49826a76461Sbellard printf("TFAULT at 0x%" PRIx64 "\n", address); 49983469015Sbellard #endif 5003475187dSbellard return 1; 5013475187dSbellard } 50277f193daSblueswir1 *physical = (env->itlb_tte[i] & mask & 0x1fffffff000ULL) + 50377f193daSblueswir1 (address & ~mask & 0x1fffffff000ULL); 504227671c9Sbellard *prot = PAGE_EXEC; 5053475187dSbellard return 0; 5063475187dSbellard } 5073475187dSbellard } 50883469015Sbellard #ifdef DEBUG_MMU 50926a76461Sbellard printf("TMISS at 0x%" PRIx64 "\n", address); 51083469015Sbellard #endif 511f617a9a6Sblueswir1 env->immuregs[6] = (address & ~0x1fffULL) | (env->dmmuregs[1] & 0x1fff); 51283469015Sbellard env->exception_index = TT_TMISS; 5133475187dSbellard return 1; 5143475187dSbellard } 5153475187dSbellard 516c48fcb47Sblueswir1 static int get_physical_address(CPUState *env, target_phys_addr_t *physical, 517c48fcb47Sblueswir1 int *prot, int *access_index, 518c48fcb47Sblueswir1 target_ulong address, int rw, int mmu_idx) 5193475187dSbellard { 5206ebbf390Sj_mayer int is_user = mmu_idx == MMU_USER_IDX; 5216ebbf390Sj_mayer 5223475187dSbellard if (rw == 2) 52322548760Sblueswir1 return get_physical_address_code(env, physical, prot, address, 52422548760Sblueswir1 is_user); 5253475187dSbellard else 52622548760Sblueswir1 return get_physical_address_data(env, physical, prot, address, rw, 52722548760Sblueswir1 is_user); 5283475187dSbellard } 5293475187dSbellard 5303475187dSbellard /* Perform address translation */ 5313475187dSbellard int cpu_sparc_handle_mmu_fault (CPUState *env, target_ulong address, int rw, 5326ebbf390Sj_mayer int mmu_idx, int is_softmmu) 5333475187dSbellard { 53483469015Sbellard target_ulong virt_addr, vaddr; 5353475187dSbellard target_phys_addr_t paddr; 5363475187dSbellard int error_code = 0, prot, ret = 0, access_index; 5373475187dSbellard 53877f193daSblueswir1 error_code = get_physical_address(env, &paddr, &prot, &access_index, 53977f193daSblueswir1 address, rw, mmu_idx); 5403475187dSbellard if (error_code == 0) { 5413475187dSbellard virt_addr = address & TARGET_PAGE_MASK; 54277f193daSblueswir1 vaddr = virt_addr + ((address & TARGET_PAGE_MASK) & 54377f193daSblueswir1 (TARGET_PAGE_SIZE - 1)); 54483469015Sbellard #ifdef DEBUG_MMU 54577f193daSblueswir1 printf("Translate at 0x%" PRIx64 " -> 0x%" PRIx64 ", vaddr 0x%" PRIx64 54677f193daSblueswir1 "\n", address, paddr, vaddr); 54783469015Sbellard #endif 5486ebbf390Sj_mayer ret = tlb_set_page_exec(env, vaddr, paddr, prot, mmu_idx, is_softmmu); 5493475187dSbellard return ret; 5503475187dSbellard } 5513475187dSbellard // XXX 5523475187dSbellard return 1; 5533475187dSbellard } 5543475187dSbellard 55583469015Sbellard #ifdef DEBUG_MMU 55683469015Sbellard void dump_mmu(CPUState *env) 55783469015Sbellard { 55883469015Sbellard unsigned int i; 55983469015Sbellard const char *mask; 56083469015Sbellard 56177f193daSblueswir1 printf("MMU contexts: Primary: %" PRId64 ", Secondary: %" PRId64 "\n", 56277f193daSblueswir1 env->dmmuregs[1], env->dmmuregs[2]); 56383469015Sbellard if ((env->lsu & DMMU_E) == 0) { 56483469015Sbellard printf("DMMU disabled\n"); 56583469015Sbellard } else { 56683469015Sbellard printf("DMMU dump:\n"); 56783469015Sbellard for (i = 0; i < 64; i++) { 56883469015Sbellard switch ((env->dtlb_tte[i] >> 61) & 3) { 56983469015Sbellard default: 57083469015Sbellard case 0x0: 57183469015Sbellard mask = " 8k"; 57283469015Sbellard break; 57383469015Sbellard case 0x1: 57483469015Sbellard mask = " 64k"; 57583469015Sbellard break; 57683469015Sbellard case 0x2: 57783469015Sbellard mask = "512k"; 57883469015Sbellard break; 57983469015Sbellard case 0x3: 58083469015Sbellard mask = " 4M"; 58183469015Sbellard break; 58283469015Sbellard } 58383469015Sbellard if ((env->dtlb_tte[i] & 0x8000000000000000ULL) != 0) { 58477f193daSblueswir1 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx 58577f193daSblueswir1 ", %s, %s, %s, %s, ctx %" PRId64 "\n", 58683469015Sbellard env->dtlb_tag[i] & ~0x1fffULL, 58783469015Sbellard env->dtlb_tte[i] & 0x1ffffffe000ULL, 58883469015Sbellard mask, 58983469015Sbellard env->dtlb_tte[i] & 0x4? "priv": "user", 59083469015Sbellard env->dtlb_tte[i] & 0x2? "RW": "RO", 59183469015Sbellard env->dtlb_tte[i] & 0x40? "locked": "unlocked", 59283469015Sbellard env->dtlb_tag[i] & 0x1fffULL); 59383469015Sbellard } 59483469015Sbellard } 59583469015Sbellard } 59683469015Sbellard if ((env->lsu & IMMU_E) == 0) { 59783469015Sbellard printf("IMMU disabled\n"); 59883469015Sbellard } else { 59983469015Sbellard printf("IMMU dump:\n"); 60083469015Sbellard for (i = 0; i < 64; i++) { 60183469015Sbellard switch ((env->itlb_tte[i] >> 61) & 3) { 60283469015Sbellard default: 60383469015Sbellard case 0x0: 60483469015Sbellard mask = " 8k"; 60583469015Sbellard break; 60683469015Sbellard case 0x1: 60783469015Sbellard mask = " 64k"; 60883469015Sbellard break; 60983469015Sbellard case 0x2: 61083469015Sbellard mask = "512k"; 61183469015Sbellard break; 61283469015Sbellard case 0x3: 61383469015Sbellard mask = " 4M"; 61483469015Sbellard break; 61583469015Sbellard } 61683469015Sbellard if ((env->itlb_tte[i] & 0x8000000000000000ULL) != 0) { 61777f193daSblueswir1 printf("VA: " TARGET_FMT_lx ", PA: " TARGET_FMT_lx 61877f193daSblueswir1 ", %s, %s, %s, ctx %" PRId64 "\n", 61983469015Sbellard env->itlb_tag[i] & ~0x1fffULL, 62083469015Sbellard env->itlb_tte[i] & 0x1ffffffe000ULL, 62183469015Sbellard mask, 62283469015Sbellard env->itlb_tte[i] & 0x4? "priv": "user", 62383469015Sbellard env->itlb_tte[i] & 0x40? "locked": "unlocked", 62483469015Sbellard env->itlb_tag[i] & 0x1fffULL); 62583469015Sbellard } 62683469015Sbellard } 62783469015Sbellard } 62883469015Sbellard } 62924741ef3Sbellard #endif /* DEBUG_MMU */ 63024741ef3Sbellard 63124741ef3Sbellard #endif /* TARGET_SPARC64 */ 63224741ef3Sbellard #endif /* !CONFIG_USER_ONLY */ 63324741ef3Sbellard 634c48fcb47Sblueswir1 635c48fcb47Sblueswir1 #if defined(CONFIG_USER_ONLY) 636c48fcb47Sblueswir1 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) 637c48fcb47Sblueswir1 { 638c48fcb47Sblueswir1 return addr; 639c48fcb47Sblueswir1 } 640c48fcb47Sblueswir1 641c48fcb47Sblueswir1 #else 642c48fcb47Sblueswir1 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) 643c48fcb47Sblueswir1 { 644c48fcb47Sblueswir1 target_phys_addr_t phys_addr; 645c48fcb47Sblueswir1 int prot, access_index; 646c48fcb47Sblueswir1 647c48fcb47Sblueswir1 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 2, 648c48fcb47Sblueswir1 MMU_KERNEL_IDX) != 0) 649c48fcb47Sblueswir1 if (get_physical_address(env, &phys_addr, &prot, &access_index, addr, 650c48fcb47Sblueswir1 0, MMU_KERNEL_IDX) != 0) 651c48fcb47Sblueswir1 return -1; 652c48fcb47Sblueswir1 if (cpu_get_physical_page_desc(phys_addr) == IO_MEM_UNASSIGNED) 653c48fcb47Sblueswir1 return -1; 654c48fcb47Sblueswir1 return phys_addr; 655c48fcb47Sblueswir1 } 656c48fcb47Sblueswir1 #endif 657c48fcb47Sblueswir1 658f2bc7e7fSblueswir1 #ifdef TARGET_SPARC64 659f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 660e19e4efeSblueswir1 static const char * const excp_names[0x80] = { 661f2bc7e7fSblueswir1 [TT_TFAULT] = "Instruction Access Fault", 662f2bc7e7fSblueswir1 [TT_TMISS] = "Instruction Access MMU Miss", 663f2bc7e7fSblueswir1 [TT_CODE_ACCESS] = "Instruction Access Error", 664f2bc7e7fSblueswir1 [TT_ILL_INSN] = "Illegal Instruction", 665f2bc7e7fSblueswir1 [TT_PRIV_INSN] = "Privileged Instruction", 666f2bc7e7fSblueswir1 [TT_NFPU_INSN] = "FPU Disabled", 667f2bc7e7fSblueswir1 [TT_FP_EXCP] = "FPU Exception", 668f2bc7e7fSblueswir1 [TT_TOVF] = "Tag Overflow", 669f2bc7e7fSblueswir1 [TT_CLRWIN] = "Clean Windows", 670f2bc7e7fSblueswir1 [TT_DIV_ZERO] = "Division By Zero", 671f2bc7e7fSblueswir1 [TT_DFAULT] = "Data Access Fault", 672f2bc7e7fSblueswir1 [TT_DMISS] = "Data Access MMU Miss", 673f2bc7e7fSblueswir1 [TT_DATA_ACCESS] = "Data Access Error", 674f2bc7e7fSblueswir1 [TT_DPROT] = "Data Protection Error", 675f2bc7e7fSblueswir1 [TT_UNALIGNED] = "Unaligned Memory Access", 676f2bc7e7fSblueswir1 [TT_PRIV_ACT] = "Privileged Action", 677f2bc7e7fSblueswir1 [TT_EXTINT | 0x1] = "External Interrupt 1", 678f2bc7e7fSblueswir1 [TT_EXTINT | 0x2] = "External Interrupt 2", 679f2bc7e7fSblueswir1 [TT_EXTINT | 0x3] = "External Interrupt 3", 680f2bc7e7fSblueswir1 [TT_EXTINT | 0x4] = "External Interrupt 4", 681f2bc7e7fSblueswir1 [TT_EXTINT | 0x5] = "External Interrupt 5", 682f2bc7e7fSblueswir1 [TT_EXTINT | 0x6] = "External Interrupt 6", 683f2bc7e7fSblueswir1 [TT_EXTINT | 0x7] = "External Interrupt 7", 684f2bc7e7fSblueswir1 [TT_EXTINT | 0x8] = "External Interrupt 8", 685f2bc7e7fSblueswir1 [TT_EXTINT | 0x9] = "External Interrupt 9", 686f2bc7e7fSblueswir1 [TT_EXTINT | 0xa] = "External Interrupt 10", 687f2bc7e7fSblueswir1 [TT_EXTINT | 0xb] = "External Interrupt 11", 688f2bc7e7fSblueswir1 [TT_EXTINT | 0xc] = "External Interrupt 12", 689f2bc7e7fSblueswir1 [TT_EXTINT | 0xd] = "External Interrupt 13", 690f2bc7e7fSblueswir1 [TT_EXTINT | 0xe] = "External Interrupt 14", 691f2bc7e7fSblueswir1 [TT_EXTINT | 0xf] = "External Interrupt 15", 692f2bc7e7fSblueswir1 }; 693f2bc7e7fSblueswir1 #endif 694f2bc7e7fSblueswir1 695f2bc7e7fSblueswir1 void do_interrupt(CPUState *env) 696f2bc7e7fSblueswir1 { 697f2bc7e7fSblueswir1 int intno = env->exception_index; 698f2bc7e7fSblueswir1 699f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 700f2bc7e7fSblueswir1 if (loglevel & CPU_LOG_INT) { 701f2bc7e7fSblueswir1 static int count; 702f2bc7e7fSblueswir1 const char *name; 703f2bc7e7fSblueswir1 704e19e4efeSblueswir1 if (intno < 0 || intno >= 0x180) 705f2bc7e7fSblueswir1 name = "Unknown"; 706f2bc7e7fSblueswir1 else if (intno >= 0x100) 707f2bc7e7fSblueswir1 name = "Trap Instruction"; 708f2bc7e7fSblueswir1 else if (intno >= 0xc0) 709f2bc7e7fSblueswir1 name = "Window Fill"; 710f2bc7e7fSblueswir1 else if (intno >= 0x80) 711f2bc7e7fSblueswir1 name = "Window Spill"; 712f2bc7e7fSblueswir1 else { 713f2bc7e7fSblueswir1 name = excp_names[intno]; 714f2bc7e7fSblueswir1 if (!name) 715f2bc7e7fSblueswir1 name = "Unknown"; 716f2bc7e7fSblueswir1 } 717f2bc7e7fSblueswir1 718f2bc7e7fSblueswir1 fprintf(logfile, "%6d: %s (v=%04x) pc=%016" PRIx64 " npc=%016" PRIx64 719f2bc7e7fSblueswir1 " SP=%016" PRIx64 "\n", 720f2bc7e7fSblueswir1 count, name, intno, 721f2bc7e7fSblueswir1 env->pc, 722f2bc7e7fSblueswir1 env->npc, env->regwptr[6]); 723f2bc7e7fSblueswir1 cpu_dump_state(env, logfile, fprintf, 0); 724f2bc7e7fSblueswir1 #if 0 725f2bc7e7fSblueswir1 { 726f2bc7e7fSblueswir1 int i; 727f2bc7e7fSblueswir1 uint8_t *ptr; 728f2bc7e7fSblueswir1 729f2bc7e7fSblueswir1 fprintf(logfile, " code="); 730f2bc7e7fSblueswir1 ptr = (uint8_t *)env->pc; 731f2bc7e7fSblueswir1 for(i = 0; i < 16; i++) { 732f2bc7e7fSblueswir1 fprintf(logfile, " %02x", ldub(ptr + i)); 733f2bc7e7fSblueswir1 } 734f2bc7e7fSblueswir1 fprintf(logfile, "\n"); 735f2bc7e7fSblueswir1 } 736f2bc7e7fSblueswir1 #endif 737f2bc7e7fSblueswir1 count++; 738f2bc7e7fSblueswir1 } 739f2bc7e7fSblueswir1 #endif 740f2bc7e7fSblueswir1 #if !defined(CONFIG_USER_ONLY) 741f2bc7e7fSblueswir1 if (env->tl == MAXTL) { 742f2bc7e7fSblueswir1 cpu_abort(env, "Trap 0x%04x while trap level is MAXTL, Error state", 743f2bc7e7fSblueswir1 env->exception_index); 744f2bc7e7fSblueswir1 return; 745f2bc7e7fSblueswir1 } 746f2bc7e7fSblueswir1 #endif 747e6bf7d70Sblueswir1 if (env->tl < MAXTL - 1) { 748e6bf7d70Sblueswir1 env->tl++; 749e6bf7d70Sblueswir1 } else { 750e6bf7d70Sblueswir1 env->pstate |= PS_RED; 751e6bf7d70Sblueswir1 if (env->tl != MAXTL) 752e6bf7d70Sblueswir1 env->tl++; 753e6bf7d70Sblueswir1 } 754e6bf7d70Sblueswir1 env->tsptr = &env->ts[env->tl]; 755f2bc7e7fSblueswir1 env->tsptr->tstate = ((uint64_t)GET_CCR(env) << 32) | 756f2bc7e7fSblueswir1 ((env->asi & 0xff) << 24) | ((env->pstate & 0xf3f) << 8) | 757f2bc7e7fSblueswir1 GET_CWP64(env); 758f2bc7e7fSblueswir1 env->tsptr->tpc = env->pc; 759f2bc7e7fSblueswir1 env->tsptr->tnpc = env->npc; 760f2bc7e7fSblueswir1 env->tsptr->tt = intno; 76174b9deccSblueswir1 if (!(env->features & CPU_FEATURE_GL)) { 76274b9deccSblueswir1 switch (intno) { 76374b9deccSblueswir1 case TT_IVEC: 76474b9deccSblueswir1 change_pstate(PS_PEF | PS_PRIV | PS_IG); 76574b9deccSblueswir1 break; 76674b9deccSblueswir1 case TT_TFAULT: 76774b9deccSblueswir1 case TT_TMISS: 76874b9deccSblueswir1 case TT_DFAULT: 76974b9deccSblueswir1 case TT_DMISS: 77074b9deccSblueswir1 case TT_DPROT: 77174b9deccSblueswir1 change_pstate(PS_PEF | PS_PRIV | PS_MG); 77274b9deccSblueswir1 break; 77374b9deccSblueswir1 default: 774f2bc7e7fSblueswir1 change_pstate(PS_PEF | PS_PRIV | PS_AG); 77574b9deccSblueswir1 break; 77674b9deccSblueswir1 } 77774b9deccSblueswir1 } 778f2bc7e7fSblueswir1 if (intno == TT_CLRWIN) 7791a14026eSblueswir1 cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - 1)); 780f2bc7e7fSblueswir1 else if ((intno & 0x1c0) == TT_SPILL) 7811a14026eSblueswir1 cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2)); 782f2bc7e7fSblueswir1 else if ((intno & 0x1c0) == TT_FILL) 7831a14026eSblueswir1 cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1)); 784f2bc7e7fSblueswir1 env->tbr &= ~0x7fffULL; 785f2bc7e7fSblueswir1 env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5); 786f2bc7e7fSblueswir1 env->pc = env->tbr; 787f2bc7e7fSblueswir1 env->npc = env->pc + 4; 788f2bc7e7fSblueswir1 env->exception_index = 0; 789f2bc7e7fSblueswir1 } 790f2bc7e7fSblueswir1 #else 791f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 792f2bc7e7fSblueswir1 static const char * const excp_names[0x80] = { 793f2bc7e7fSblueswir1 [TT_TFAULT] = "Instruction Access Fault", 794f2bc7e7fSblueswir1 [TT_ILL_INSN] = "Illegal Instruction", 795f2bc7e7fSblueswir1 [TT_PRIV_INSN] = "Privileged Instruction", 796f2bc7e7fSblueswir1 [TT_NFPU_INSN] = "FPU Disabled", 797f2bc7e7fSblueswir1 [TT_WIN_OVF] = "Window Overflow", 798f2bc7e7fSblueswir1 [TT_WIN_UNF] = "Window Underflow", 799f2bc7e7fSblueswir1 [TT_UNALIGNED] = "Unaligned Memory Access", 800f2bc7e7fSblueswir1 [TT_FP_EXCP] = "FPU Exception", 801f2bc7e7fSblueswir1 [TT_DFAULT] = "Data Access Fault", 802f2bc7e7fSblueswir1 [TT_TOVF] = "Tag Overflow", 803f2bc7e7fSblueswir1 [TT_EXTINT | 0x1] = "External Interrupt 1", 804f2bc7e7fSblueswir1 [TT_EXTINT | 0x2] = "External Interrupt 2", 805f2bc7e7fSblueswir1 [TT_EXTINT | 0x3] = "External Interrupt 3", 806f2bc7e7fSblueswir1 [TT_EXTINT | 0x4] = "External Interrupt 4", 807f2bc7e7fSblueswir1 [TT_EXTINT | 0x5] = "External Interrupt 5", 808f2bc7e7fSblueswir1 [TT_EXTINT | 0x6] = "External Interrupt 6", 809f2bc7e7fSblueswir1 [TT_EXTINT | 0x7] = "External Interrupt 7", 810f2bc7e7fSblueswir1 [TT_EXTINT | 0x8] = "External Interrupt 8", 811f2bc7e7fSblueswir1 [TT_EXTINT | 0x9] = "External Interrupt 9", 812f2bc7e7fSblueswir1 [TT_EXTINT | 0xa] = "External Interrupt 10", 813f2bc7e7fSblueswir1 [TT_EXTINT | 0xb] = "External Interrupt 11", 814f2bc7e7fSblueswir1 [TT_EXTINT | 0xc] = "External Interrupt 12", 815f2bc7e7fSblueswir1 [TT_EXTINT | 0xd] = "External Interrupt 13", 816f2bc7e7fSblueswir1 [TT_EXTINT | 0xe] = "External Interrupt 14", 817f2bc7e7fSblueswir1 [TT_EXTINT | 0xf] = "External Interrupt 15", 818f2bc7e7fSblueswir1 [TT_TOVF] = "Tag Overflow", 819f2bc7e7fSblueswir1 [TT_CODE_ACCESS] = "Instruction Access Error", 820f2bc7e7fSblueswir1 [TT_DATA_ACCESS] = "Data Access Error", 821f2bc7e7fSblueswir1 [TT_DIV_ZERO] = "Division By Zero", 822f2bc7e7fSblueswir1 [TT_NCP_INSN] = "Coprocessor Disabled", 823f2bc7e7fSblueswir1 }; 824f2bc7e7fSblueswir1 #endif 825f2bc7e7fSblueswir1 826f2bc7e7fSblueswir1 void do_interrupt(CPUState *env) 827f2bc7e7fSblueswir1 { 828f2bc7e7fSblueswir1 int cwp, intno = env->exception_index; 829f2bc7e7fSblueswir1 830f2bc7e7fSblueswir1 #ifdef DEBUG_PCALL 831f2bc7e7fSblueswir1 if (loglevel & CPU_LOG_INT) { 832f2bc7e7fSblueswir1 static int count; 833f2bc7e7fSblueswir1 const char *name; 834f2bc7e7fSblueswir1 835f2bc7e7fSblueswir1 if (intno < 0 || intno >= 0x100) 836f2bc7e7fSblueswir1 name = "Unknown"; 837f2bc7e7fSblueswir1 else if (intno >= 0x80) 838f2bc7e7fSblueswir1 name = "Trap Instruction"; 839f2bc7e7fSblueswir1 else { 840f2bc7e7fSblueswir1 name = excp_names[intno]; 841f2bc7e7fSblueswir1 if (!name) 842f2bc7e7fSblueswir1 name = "Unknown"; 843f2bc7e7fSblueswir1 } 844f2bc7e7fSblueswir1 845f2bc7e7fSblueswir1 fprintf(logfile, "%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n", 846f2bc7e7fSblueswir1 count, name, intno, 847f2bc7e7fSblueswir1 env->pc, 848f2bc7e7fSblueswir1 env->npc, env->regwptr[6]); 849f2bc7e7fSblueswir1 cpu_dump_state(env, logfile, fprintf, 0); 850f2bc7e7fSblueswir1 #if 0 851f2bc7e7fSblueswir1 { 852f2bc7e7fSblueswir1 int i; 853f2bc7e7fSblueswir1 uint8_t *ptr; 854f2bc7e7fSblueswir1 855f2bc7e7fSblueswir1 fprintf(logfile, " code="); 856f2bc7e7fSblueswir1 ptr = (uint8_t *)env->pc; 857f2bc7e7fSblueswir1 for(i = 0; i < 16; i++) { 858f2bc7e7fSblueswir1 fprintf(logfile, " %02x", ldub(ptr + i)); 859f2bc7e7fSblueswir1 } 860f2bc7e7fSblueswir1 fprintf(logfile, "\n"); 861f2bc7e7fSblueswir1 } 862f2bc7e7fSblueswir1 #endif 863f2bc7e7fSblueswir1 count++; 864f2bc7e7fSblueswir1 } 865f2bc7e7fSblueswir1 #endif 866f2bc7e7fSblueswir1 #if !defined(CONFIG_USER_ONLY) 867f2bc7e7fSblueswir1 if (env->psret == 0) { 868f2bc7e7fSblueswir1 cpu_abort(env, "Trap 0x%02x while interrupts disabled, Error state", 869f2bc7e7fSblueswir1 env->exception_index); 870f2bc7e7fSblueswir1 return; 871f2bc7e7fSblueswir1 } 872f2bc7e7fSblueswir1 #endif 873f2bc7e7fSblueswir1 env->psret = 0; 8741a14026eSblueswir1 cwp = cpu_cwp_dec(env, env->cwp - 1); 875f2bc7e7fSblueswir1 cpu_set_cwp(env, cwp); 876f2bc7e7fSblueswir1 env->regwptr[9] = env->pc; 877f2bc7e7fSblueswir1 env->regwptr[10] = env->npc; 878f2bc7e7fSblueswir1 env->psrps = env->psrs; 879f2bc7e7fSblueswir1 env->psrs = 1; 880f2bc7e7fSblueswir1 env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4); 881f2bc7e7fSblueswir1 env->pc = env->tbr; 882f2bc7e7fSblueswir1 env->npc = env->pc + 4; 883f2bc7e7fSblueswir1 env->exception_index = 0; 884f2bc7e7fSblueswir1 } 885f2bc7e7fSblueswir1 #endif 886f2bc7e7fSblueswir1 88724741ef3Sbellard void memcpy32(target_ulong *dst, const target_ulong *src) 88824741ef3Sbellard { 88924741ef3Sbellard dst[0] = src[0]; 89024741ef3Sbellard dst[1] = src[1]; 89124741ef3Sbellard dst[2] = src[2]; 89224741ef3Sbellard dst[3] = src[3]; 89324741ef3Sbellard dst[4] = src[4]; 89424741ef3Sbellard dst[5] = src[5]; 89524741ef3Sbellard dst[6] = src[6]; 89624741ef3Sbellard dst[7] = src[7]; 89724741ef3Sbellard } 89887ecb68bSpbrook 899c48fcb47Sblueswir1 void cpu_reset(CPUSPARCState *env) 900c48fcb47Sblueswir1 { 901c48fcb47Sblueswir1 tlb_flush(env, 1); 902c48fcb47Sblueswir1 env->cwp = 0; 903c48fcb47Sblueswir1 env->wim = 1; 904c48fcb47Sblueswir1 env->regwptr = env->regbase + (env->cwp * 16); 905c48fcb47Sblueswir1 #if defined(CONFIG_USER_ONLY) 906c48fcb47Sblueswir1 env->user_mode_only = 1; 907c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 9081a14026eSblueswir1 env->cleanwin = env->nwindows - 2; 9091a14026eSblueswir1 env->cansave = env->nwindows - 2; 910c48fcb47Sblueswir1 env->pstate = PS_RMO | PS_PEF | PS_IE; 911c48fcb47Sblueswir1 env->asi = 0x82; // Primary no-fault 912c48fcb47Sblueswir1 #endif 913c48fcb47Sblueswir1 #else 914c48fcb47Sblueswir1 env->psret = 0; 915c48fcb47Sblueswir1 env->psrs = 1; 916c48fcb47Sblueswir1 env->psrps = 1; 917c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 918c48fcb47Sblueswir1 env->pstate = PS_PRIV; 919c48fcb47Sblueswir1 env->hpstate = HS_PRIV; 9208eba209eSblueswir1 env->pc = 0x1fff0000020ULL; // XXX should be different for system_reset 921c48fcb47Sblueswir1 env->tsptr = &env->ts[env->tl]; 922c48fcb47Sblueswir1 #else 923c48fcb47Sblueswir1 env->pc = 0; 924c48fcb47Sblueswir1 env->mmuregs[0] &= ~(MMU_E | MMU_NF); 925c48fcb47Sblueswir1 env->mmuregs[0] |= env->mmu_bm; 926c48fcb47Sblueswir1 #endif 927c48fcb47Sblueswir1 env->npc = env->pc + 4; 928c48fcb47Sblueswir1 #endif 929c48fcb47Sblueswir1 } 930c48fcb47Sblueswir1 93164a88d5dSblueswir1 static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model) 932c48fcb47Sblueswir1 { 93364a88d5dSblueswir1 sparc_def_t def1, *def = &def1; 934c48fcb47Sblueswir1 93564a88d5dSblueswir1 if (cpu_sparc_find_by_name(def, cpu_model) < 0) 93664a88d5dSblueswir1 return -1; 937c48fcb47Sblueswir1 93864a88d5dSblueswir1 env->features = def->features; 939c48fcb47Sblueswir1 env->cpu_model_str = cpu_model; 940c48fcb47Sblueswir1 env->version = def->iu_version; 941c48fcb47Sblueswir1 env->fsr = def->fpu_version; 9421a14026eSblueswir1 env->nwindows = def->nwindows; 943c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64) 944c48fcb47Sblueswir1 env->mmu_bm = def->mmu_bm; 945c48fcb47Sblueswir1 env->mmu_ctpr_mask = def->mmu_ctpr_mask; 946c48fcb47Sblueswir1 env->mmu_cxr_mask = def->mmu_cxr_mask; 947c48fcb47Sblueswir1 env->mmu_sfsr_mask = def->mmu_sfsr_mask; 948c48fcb47Sblueswir1 env->mmu_trcr_mask = def->mmu_trcr_mask; 949c48fcb47Sblueswir1 env->mmuregs[0] |= def->mmu_version; 950c48fcb47Sblueswir1 cpu_sparc_set_id(env, 0); 9511a14026eSblueswir1 #else 952fb79ceb9Sblueswir1 env->mmu_version = def->mmu_version; 9531a14026eSblueswir1 env->version |= def->nwindows - 1; 954c48fcb47Sblueswir1 #endif 95564a88d5dSblueswir1 return 0; 95664a88d5dSblueswir1 } 95764a88d5dSblueswir1 95864a88d5dSblueswir1 static void cpu_sparc_close(CPUSPARCState *env) 95964a88d5dSblueswir1 { 96064a88d5dSblueswir1 free(env); 96164a88d5dSblueswir1 } 96264a88d5dSblueswir1 96364a88d5dSblueswir1 CPUSPARCState *cpu_sparc_init(const char *cpu_model) 96464a88d5dSblueswir1 { 96564a88d5dSblueswir1 CPUSPARCState *env; 96664a88d5dSblueswir1 96764a88d5dSblueswir1 env = qemu_mallocz(sizeof(CPUSPARCState)); 96864a88d5dSblueswir1 if (!env) 96964a88d5dSblueswir1 return NULL; 97064a88d5dSblueswir1 cpu_exec_init(env); 971c48fcb47Sblueswir1 972c48fcb47Sblueswir1 gen_intermediate_code_init(env); 973c48fcb47Sblueswir1 97464a88d5dSblueswir1 if (cpu_sparc_register(env, cpu_model) < 0) { 97564a88d5dSblueswir1 cpu_sparc_close(env); 97664a88d5dSblueswir1 return NULL; 97764a88d5dSblueswir1 } 978c48fcb47Sblueswir1 cpu_reset(env); 979c48fcb47Sblueswir1 980c48fcb47Sblueswir1 return env; 981c48fcb47Sblueswir1 } 982c48fcb47Sblueswir1 983c48fcb47Sblueswir1 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu) 984c48fcb47Sblueswir1 { 985c48fcb47Sblueswir1 #if !defined(TARGET_SPARC64) 986c48fcb47Sblueswir1 env->mxccregs[7] = ((cpu + 8) & 0xf) << 24; 987c48fcb47Sblueswir1 #endif 988c48fcb47Sblueswir1 } 989c48fcb47Sblueswir1 990c48fcb47Sblueswir1 static const sparc_def_t sparc_defs[] = { 991c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 992c48fcb47Sblueswir1 { 993c48fcb47Sblueswir1 .name = "Fujitsu Sparc64", 994c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24) 9951a14026eSblueswir1 | (MAXTL << 8)), 996c48fcb47Sblueswir1 .fpu_version = 0x00000000, 997fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 9981a14026eSblueswir1 .nwindows = 4, 99964a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1000c48fcb47Sblueswir1 }, 1001c48fcb47Sblueswir1 { 1002c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 III", 1003c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24) 10041a14026eSblueswir1 | (MAXTL << 8)), 1005c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1006fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10071a14026eSblueswir1 .nwindows = 5, 100864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1009c48fcb47Sblueswir1 }, 1010c48fcb47Sblueswir1 { 1011c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 IV", 1012c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24) 10131a14026eSblueswir1 | (MAXTL << 8)), 1014c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1015fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10161a14026eSblueswir1 .nwindows = 8, 101764a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1018c48fcb47Sblueswir1 }, 1019c48fcb47Sblueswir1 { 1020c48fcb47Sblueswir1 .name = "Fujitsu Sparc64 V", 1021c48fcb47Sblueswir1 .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24) 10221a14026eSblueswir1 | (MAXTL << 8)), 1023c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1024fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10251a14026eSblueswir1 .nwindows = 8, 102664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1027c48fcb47Sblueswir1 }, 1028c48fcb47Sblueswir1 { 1029c48fcb47Sblueswir1 .name = "TI UltraSparc I", 1030c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24) 10311a14026eSblueswir1 | (MAXTL << 8)), 1032c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1033fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10341a14026eSblueswir1 .nwindows = 8, 103564a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1036c48fcb47Sblueswir1 }, 1037c48fcb47Sblueswir1 { 1038c48fcb47Sblueswir1 .name = "TI UltraSparc II", 1039c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24) 10401a14026eSblueswir1 | (MAXTL << 8)), 1041c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1042fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10431a14026eSblueswir1 .nwindows = 8, 104464a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1045c48fcb47Sblueswir1 }, 1046c48fcb47Sblueswir1 { 1047c48fcb47Sblueswir1 .name = "TI UltraSparc IIi", 1048c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24) 10491a14026eSblueswir1 | (MAXTL << 8)), 1050c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1051fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10521a14026eSblueswir1 .nwindows = 8, 105364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1054c48fcb47Sblueswir1 }, 1055c48fcb47Sblueswir1 { 1056c48fcb47Sblueswir1 .name = "TI UltraSparc IIe", 1057c48fcb47Sblueswir1 .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24) 10581a14026eSblueswir1 | (MAXTL << 8)), 1059c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1060fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10611a14026eSblueswir1 .nwindows = 8, 106264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1063c48fcb47Sblueswir1 }, 1064c48fcb47Sblueswir1 { 1065c48fcb47Sblueswir1 .name = "Sun UltraSparc III", 1066c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24) 10671a14026eSblueswir1 | (MAXTL << 8)), 1068c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1069fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10701a14026eSblueswir1 .nwindows = 8, 107164a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1072c48fcb47Sblueswir1 }, 1073c48fcb47Sblueswir1 { 1074c48fcb47Sblueswir1 .name = "Sun UltraSparc III Cu", 1075c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24) 10761a14026eSblueswir1 | (MAXTL << 8)), 1077c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1078fb79ceb9Sblueswir1 .mmu_version = mmu_us_3, 10791a14026eSblueswir1 .nwindows = 8, 108064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1081c48fcb47Sblueswir1 }, 1082c48fcb47Sblueswir1 { 1083c48fcb47Sblueswir1 .name = "Sun UltraSparc IIIi", 1084c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24) 10851a14026eSblueswir1 | (MAXTL << 8)), 1086c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1087fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 10881a14026eSblueswir1 .nwindows = 8, 108964a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1090c48fcb47Sblueswir1 }, 1091c48fcb47Sblueswir1 { 1092c48fcb47Sblueswir1 .name = "Sun UltraSparc IV", 1093c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24) 10941a14026eSblueswir1 | (MAXTL << 8)), 1095c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1096fb79ceb9Sblueswir1 .mmu_version = mmu_us_4, 10971a14026eSblueswir1 .nwindows = 8, 109864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1099c48fcb47Sblueswir1 }, 1100c48fcb47Sblueswir1 { 1101c48fcb47Sblueswir1 .name = "Sun UltraSparc IV+", 1102c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24) 11031a14026eSblueswir1 | (MAXTL << 8)), 1104c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1105fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 11061a14026eSblueswir1 .nwindows = 8, 1107fb79ceb9Sblueswir1 .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT, 1108c48fcb47Sblueswir1 }, 1109c48fcb47Sblueswir1 { 1110c48fcb47Sblueswir1 .name = "Sun UltraSparc IIIi+", 1111c48fcb47Sblueswir1 .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24) 11121a14026eSblueswir1 | (MAXTL << 8)), 1113c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1114fb79ceb9Sblueswir1 .mmu_version = mmu_us_3, 11151a14026eSblueswir1 .nwindows = 8, 111664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1117c48fcb47Sblueswir1 }, 1118c48fcb47Sblueswir1 { 1119c48fcb47Sblueswir1 .name = "NEC UltraSparc I", 1120c48fcb47Sblueswir1 .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24) 11211a14026eSblueswir1 | (MAXTL << 8)), 1122c48fcb47Sblueswir1 .fpu_version = 0x00000000, 1123fb79ceb9Sblueswir1 .mmu_version = mmu_us_12, 11241a14026eSblueswir1 .nwindows = 8, 112564a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1126c48fcb47Sblueswir1 }, 1127c48fcb47Sblueswir1 #else 1128c48fcb47Sblueswir1 { 1129c48fcb47Sblueswir1 .name = "Fujitsu MB86900", 1130c48fcb47Sblueswir1 .iu_version = 0x00 << 24, /* Impl 0, ver 0 */ 1131c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1132c48fcb47Sblueswir1 .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */ 1133c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1134c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1135c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1136c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1137c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11381a14026eSblueswir1 .nwindows = 7, 1139e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_FSMULD, 1140c48fcb47Sblueswir1 }, 1141c48fcb47Sblueswir1 { 1142c48fcb47Sblueswir1 .name = "Fujitsu MB86904", 1143c48fcb47Sblueswir1 .iu_version = 0x04 << 24, /* Impl 0, ver 4 */ 1144c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1145c48fcb47Sblueswir1 .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */ 1146c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1147c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1148c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1149c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1150c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 11511a14026eSblueswir1 .nwindows = 8, 115264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1153c48fcb47Sblueswir1 }, 1154c48fcb47Sblueswir1 { 1155c48fcb47Sblueswir1 .name = "Fujitsu MB86907", 1156c48fcb47Sblueswir1 .iu_version = 0x05 << 24, /* Impl 0, ver 5 */ 1157c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1158c48fcb47Sblueswir1 .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */ 1159c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1160c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1161c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1162c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1163c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11641a14026eSblueswir1 .nwindows = 8, 116564a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1166c48fcb47Sblueswir1 }, 1167c48fcb47Sblueswir1 { 1168c48fcb47Sblueswir1 .name = "LSI L64811", 1169c48fcb47Sblueswir1 .iu_version = 0x10 << 24, /* Impl 1, ver 0 */ 1170c48fcb47Sblueswir1 .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */ 1171c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1172c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1173c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1174c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1175c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1176c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11771a14026eSblueswir1 .nwindows = 8, 1178e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1179e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1180c48fcb47Sblueswir1 }, 1181c48fcb47Sblueswir1 { 1182c48fcb47Sblueswir1 .name = "Cypress CY7C601", 1183c48fcb47Sblueswir1 .iu_version = 0x11 << 24, /* Impl 1, ver 1 */ 1184c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ 1185c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1186c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1187c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1188c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1189c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1190c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 11911a14026eSblueswir1 .nwindows = 8, 1192e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1193e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1194c48fcb47Sblueswir1 }, 1195c48fcb47Sblueswir1 { 1196c48fcb47Sblueswir1 .name = "Cypress CY7C611", 1197c48fcb47Sblueswir1 .iu_version = 0x13 << 24, /* Impl 1, ver 3 */ 1198c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */ 1199c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1200c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1201c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1202c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1203c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1204c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12051a14026eSblueswir1 .nwindows = 8, 1206e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1207e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1208c48fcb47Sblueswir1 }, 1209c48fcb47Sblueswir1 { 1210c48fcb47Sblueswir1 .name = "TI SuperSparc II", 1211c48fcb47Sblueswir1 .iu_version = 0x40000000, 1212c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1213c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1214c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1215c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1216c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1217c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1218c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12191a14026eSblueswir1 .nwindows = 8, 122064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1221c48fcb47Sblueswir1 }, 1222c48fcb47Sblueswir1 { 1223c48fcb47Sblueswir1 .name = "TI MicroSparc I", 1224c48fcb47Sblueswir1 .iu_version = 0x41000000, 1225c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1226c48fcb47Sblueswir1 .mmu_version = 0x41000000, 1227c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1228c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1229c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1230c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1231c48fcb47Sblueswir1 .mmu_trcr_mask = 0x0000003f, 12321a14026eSblueswir1 .nwindows = 7, 1233e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL | 1234e30b4678Sblueswir1 CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | 1235e30b4678Sblueswir1 CPU_FEATURE_FMUL, 1236c48fcb47Sblueswir1 }, 1237c48fcb47Sblueswir1 { 1238c48fcb47Sblueswir1 .name = "TI MicroSparc II", 1239c48fcb47Sblueswir1 .iu_version = 0x42000000, 1240c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1241c48fcb47Sblueswir1 .mmu_version = 0x02000000, 1242c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1243c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1244c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1245c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016fff, 1246c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 12471a14026eSblueswir1 .nwindows = 8, 124864a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1249c48fcb47Sblueswir1 }, 1250c48fcb47Sblueswir1 { 1251c48fcb47Sblueswir1 .name = "TI MicroSparc IIep", 1252c48fcb47Sblueswir1 .iu_version = 0x42000000, 1253c48fcb47Sblueswir1 .fpu_version = 4 << 17, 1254c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1255c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1256c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x00ffffc0, 1257c48fcb47Sblueswir1 .mmu_cxr_mask = 0x000000ff, 1258c48fcb47Sblueswir1 .mmu_sfsr_mask = 0x00016bff, 1259c48fcb47Sblueswir1 .mmu_trcr_mask = 0x00ffffff, 12601a14026eSblueswir1 .nwindows = 8, 126164a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1262c48fcb47Sblueswir1 }, 1263c48fcb47Sblueswir1 { 1264b5154bdeSblueswir1 .name = "TI SuperSparc 40", // STP1020NPGA 1265b5154bdeSblueswir1 .iu_version = 0x41000000, 1266b5154bdeSblueswir1 .fpu_version = 0 << 17, 1267b5154bdeSblueswir1 .mmu_version = 0x00000000, 1268b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1269b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1270b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1271b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1272b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 12731a14026eSblueswir1 .nwindows = 8, 1274b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1275b5154bdeSblueswir1 }, 1276b5154bdeSblueswir1 { 1277b5154bdeSblueswir1 .name = "TI SuperSparc 50", // STP1020PGA 1278b5154bdeSblueswir1 .iu_version = 0x40000000, 1279b5154bdeSblueswir1 .fpu_version = 0 << 17, 1280b5154bdeSblueswir1 .mmu_version = 0x04000000, 1281b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1282b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1283b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1284b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1285b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 12861a14026eSblueswir1 .nwindows = 8, 1287b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1288b5154bdeSblueswir1 }, 1289b5154bdeSblueswir1 { 1290c48fcb47Sblueswir1 .name = "TI SuperSparc 51", 1291c48fcb47Sblueswir1 .iu_version = 0x43000000, 1292c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1293c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1294c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1295c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1296c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1297c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1298c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 12991a14026eSblueswir1 .nwindows = 8, 130064a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1301c48fcb47Sblueswir1 }, 1302c48fcb47Sblueswir1 { 1303b5154bdeSblueswir1 .name = "TI SuperSparc 60", // STP1020APGA 1304b5154bdeSblueswir1 .iu_version = 0x40000000, 1305b5154bdeSblueswir1 .fpu_version = 0 << 17, 1306b5154bdeSblueswir1 .mmu_version = 0x03000000, 1307b5154bdeSblueswir1 .mmu_bm = 0x00002000, 1308b5154bdeSblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1309b5154bdeSblueswir1 .mmu_cxr_mask = 0x0000ffff, 1310b5154bdeSblueswir1 .mmu_sfsr_mask = 0xffffffff, 1311b5154bdeSblueswir1 .mmu_trcr_mask = 0xffffffff, 13121a14026eSblueswir1 .nwindows = 8, 1313b5154bdeSblueswir1 .features = CPU_DEFAULT_FEATURES, 1314b5154bdeSblueswir1 }, 1315b5154bdeSblueswir1 { 1316c48fcb47Sblueswir1 .name = "TI SuperSparc 61", 1317c48fcb47Sblueswir1 .iu_version = 0x44000000, 1318c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1319c48fcb47Sblueswir1 .mmu_version = 0x04000000, 1320c48fcb47Sblueswir1 .mmu_bm = 0x00002000, 1321c48fcb47Sblueswir1 .mmu_ctpr_mask = 0xffffffc0, 1322c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000ffff, 1323c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1324c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13251a14026eSblueswir1 .nwindows = 8, 132664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1327c48fcb47Sblueswir1 }, 1328c48fcb47Sblueswir1 { 1329c48fcb47Sblueswir1 .name = "Ross RT625", 1330c48fcb47Sblueswir1 .iu_version = 0x1e000000, 1331c48fcb47Sblueswir1 .fpu_version = 1 << 17, 1332c48fcb47Sblueswir1 .mmu_version = 0x1e000000, 1333c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1334c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1335c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1336c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1337c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13381a14026eSblueswir1 .nwindows = 8, 133964a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1340c48fcb47Sblueswir1 }, 1341c48fcb47Sblueswir1 { 1342c48fcb47Sblueswir1 .name = "Ross RT620", 1343c48fcb47Sblueswir1 .iu_version = 0x1f000000, 1344c48fcb47Sblueswir1 .fpu_version = 1 << 17, 1345c48fcb47Sblueswir1 .mmu_version = 0x1f000000, 1346c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1347c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1348c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1349c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1350c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13511a14026eSblueswir1 .nwindows = 8, 135264a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1353c48fcb47Sblueswir1 }, 1354c48fcb47Sblueswir1 { 1355c48fcb47Sblueswir1 .name = "BIT B5010", 1356c48fcb47Sblueswir1 .iu_version = 0x20000000, 1357c48fcb47Sblueswir1 .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */ 1358c48fcb47Sblueswir1 .mmu_version = 0x20000000, 1359c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1360c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1361c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1362c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1363c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13641a14026eSblueswir1 .nwindows = 8, 1365e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT | 1366e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1367c48fcb47Sblueswir1 }, 1368c48fcb47Sblueswir1 { 1369c48fcb47Sblueswir1 .name = "Matsushita MN10501", 1370c48fcb47Sblueswir1 .iu_version = 0x50000000, 1371c48fcb47Sblueswir1 .fpu_version = 0 << 17, 1372c48fcb47Sblueswir1 .mmu_version = 0x50000000, 1373c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1374c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1375c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1376c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1377c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13781a14026eSblueswir1 .nwindows = 8, 1379e30b4678Sblueswir1 .features = CPU_FEATURE_FLOAT | CPU_FEATURE_MUL | CPU_FEATURE_FSQRT | 1380e30b4678Sblueswir1 CPU_FEATURE_FSMULD, 1381c48fcb47Sblueswir1 }, 1382c48fcb47Sblueswir1 { 1383c48fcb47Sblueswir1 .name = "Weitek W8601", 1384c48fcb47Sblueswir1 .iu_version = 0x90 << 24, /* Impl 9, ver 0 */ 1385c48fcb47Sblueswir1 .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */ 1386c48fcb47Sblueswir1 .mmu_version = 0x10 << 24, 1387c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1388c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1389c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1390c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1391c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 13921a14026eSblueswir1 .nwindows = 8, 139364a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1394c48fcb47Sblueswir1 }, 1395c48fcb47Sblueswir1 { 1396c48fcb47Sblueswir1 .name = "LEON2", 1397c48fcb47Sblueswir1 .iu_version = 0xf2000000, 1398c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1399c48fcb47Sblueswir1 .mmu_version = 0xf2000000, 1400c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1401c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1402c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1403c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1404c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 14051a14026eSblueswir1 .nwindows = 8, 140664a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1407c48fcb47Sblueswir1 }, 1408c48fcb47Sblueswir1 { 1409c48fcb47Sblueswir1 .name = "LEON3", 1410c48fcb47Sblueswir1 .iu_version = 0xf3000000, 1411c48fcb47Sblueswir1 .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 1412c48fcb47Sblueswir1 .mmu_version = 0xf3000000, 1413c48fcb47Sblueswir1 .mmu_bm = 0x00004000, 1414c48fcb47Sblueswir1 .mmu_ctpr_mask = 0x007ffff0, 1415c48fcb47Sblueswir1 .mmu_cxr_mask = 0x0000003f, 1416c48fcb47Sblueswir1 .mmu_sfsr_mask = 0xffffffff, 1417c48fcb47Sblueswir1 .mmu_trcr_mask = 0xffffffff, 14181a14026eSblueswir1 .nwindows = 8, 141964a88d5dSblueswir1 .features = CPU_DEFAULT_FEATURES, 1420c48fcb47Sblueswir1 }, 1421c48fcb47Sblueswir1 #endif 1422c48fcb47Sblueswir1 }; 1423c48fcb47Sblueswir1 142464a88d5dSblueswir1 static const char * const feature_name[] = { 142564a88d5dSblueswir1 "float", 142664a88d5dSblueswir1 "float128", 142764a88d5dSblueswir1 "swap", 142864a88d5dSblueswir1 "mul", 142964a88d5dSblueswir1 "div", 143064a88d5dSblueswir1 "flush", 143164a88d5dSblueswir1 "fsqrt", 143264a88d5dSblueswir1 "fmul", 143364a88d5dSblueswir1 "vis1", 143464a88d5dSblueswir1 "vis2", 1435e30b4678Sblueswir1 "fsmuld", 1436fb79ceb9Sblueswir1 "hypv", 1437fb79ceb9Sblueswir1 "cmt", 1438fb79ceb9Sblueswir1 "gl", 143964a88d5dSblueswir1 }; 144064a88d5dSblueswir1 144164a88d5dSblueswir1 static void print_features(FILE *f, 144264a88d5dSblueswir1 int (*cpu_fprintf)(FILE *f, const char *fmt, ...), 144364a88d5dSblueswir1 uint32_t features, const char *prefix) 1444c48fcb47Sblueswir1 { 1445c48fcb47Sblueswir1 unsigned int i; 1446c48fcb47Sblueswir1 144764a88d5dSblueswir1 for (i = 0; i < ARRAY_SIZE(feature_name); i++) 144864a88d5dSblueswir1 if (feature_name[i] && (features & (1 << i))) { 144964a88d5dSblueswir1 if (prefix) 145064a88d5dSblueswir1 (*cpu_fprintf)(f, "%s", prefix); 145164a88d5dSblueswir1 (*cpu_fprintf)(f, "%s ", feature_name[i]); 145264a88d5dSblueswir1 } 145364a88d5dSblueswir1 } 145464a88d5dSblueswir1 145564a88d5dSblueswir1 static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features) 145664a88d5dSblueswir1 { 145764a88d5dSblueswir1 unsigned int i; 145864a88d5dSblueswir1 145964a88d5dSblueswir1 for (i = 0; i < ARRAY_SIZE(feature_name); i++) 146064a88d5dSblueswir1 if (feature_name[i] && !strcmp(flagname, feature_name[i])) { 146164a88d5dSblueswir1 *features |= 1 << i; 146264a88d5dSblueswir1 return; 146364a88d5dSblueswir1 } 146464a88d5dSblueswir1 fprintf(stderr, "CPU feature %s not found\n", flagname); 146564a88d5dSblueswir1 } 146664a88d5dSblueswir1 146722548760Sblueswir1 static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model) 146864a88d5dSblueswir1 { 146964a88d5dSblueswir1 unsigned int i; 147064a88d5dSblueswir1 const sparc_def_t *def = NULL; 147164a88d5dSblueswir1 char *s = strdup(cpu_model); 147264a88d5dSblueswir1 char *featurestr, *name = strtok(s, ","); 147364a88d5dSblueswir1 uint32_t plus_features = 0; 147464a88d5dSblueswir1 uint32_t minus_features = 0; 147564a88d5dSblueswir1 long long iu_version; 14761a14026eSblueswir1 uint32_t fpu_version, mmu_version, nwindows; 147764a88d5dSblueswir1 1478c48fcb47Sblueswir1 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) { 1479c48fcb47Sblueswir1 if (strcasecmp(name, sparc_defs[i].name) == 0) { 148064a88d5dSblueswir1 def = &sparc_defs[i]; 1481c48fcb47Sblueswir1 } 1482c48fcb47Sblueswir1 } 148364a88d5dSblueswir1 if (!def) 148464a88d5dSblueswir1 goto error; 148564a88d5dSblueswir1 memcpy(cpu_def, def, sizeof(*def)); 148664a88d5dSblueswir1 148764a88d5dSblueswir1 featurestr = strtok(NULL, ","); 148864a88d5dSblueswir1 while (featurestr) { 148964a88d5dSblueswir1 char *val; 149064a88d5dSblueswir1 149164a88d5dSblueswir1 if (featurestr[0] == '+') { 149264a88d5dSblueswir1 add_flagname_to_bitmaps(featurestr + 1, &plus_features); 149364a88d5dSblueswir1 } else if (featurestr[0] == '-') { 149464a88d5dSblueswir1 add_flagname_to_bitmaps(featurestr + 1, &minus_features); 149564a88d5dSblueswir1 } else if ((val = strchr(featurestr, '='))) { 149664a88d5dSblueswir1 *val = 0; val++; 149764a88d5dSblueswir1 if (!strcmp(featurestr, "iu_version")) { 149864a88d5dSblueswir1 char *err; 149964a88d5dSblueswir1 150064a88d5dSblueswir1 iu_version = strtoll(val, &err, 0); 150164a88d5dSblueswir1 if (!*val || *err) { 150264a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 150364a88d5dSblueswir1 goto error; 150464a88d5dSblueswir1 } 150564a88d5dSblueswir1 cpu_def->iu_version = iu_version; 150664a88d5dSblueswir1 #ifdef DEBUG_FEATURES 150764a88d5dSblueswir1 fprintf(stderr, "iu_version %llx\n", iu_version); 150864a88d5dSblueswir1 #endif 150964a88d5dSblueswir1 } else if (!strcmp(featurestr, "fpu_version")) { 151064a88d5dSblueswir1 char *err; 151164a88d5dSblueswir1 151264a88d5dSblueswir1 fpu_version = strtol(val, &err, 0); 151364a88d5dSblueswir1 if (!*val || *err) { 151464a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 151564a88d5dSblueswir1 goto error; 151664a88d5dSblueswir1 } 151764a88d5dSblueswir1 cpu_def->fpu_version = fpu_version; 151864a88d5dSblueswir1 #ifdef DEBUG_FEATURES 151964a88d5dSblueswir1 fprintf(stderr, "fpu_version %llx\n", fpu_version); 152064a88d5dSblueswir1 #endif 152164a88d5dSblueswir1 } else if (!strcmp(featurestr, "mmu_version")) { 152264a88d5dSblueswir1 char *err; 152364a88d5dSblueswir1 152464a88d5dSblueswir1 mmu_version = strtol(val, &err, 0); 152564a88d5dSblueswir1 if (!*val || *err) { 152664a88d5dSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 152764a88d5dSblueswir1 goto error; 152864a88d5dSblueswir1 } 152964a88d5dSblueswir1 cpu_def->mmu_version = mmu_version; 153064a88d5dSblueswir1 #ifdef DEBUG_FEATURES 153164a88d5dSblueswir1 fprintf(stderr, "mmu_version %llx\n", mmu_version); 153264a88d5dSblueswir1 #endif 15331a14026eSblueswir1 } else if (!strcmp(featurestr, "nwindows")) { 15341a14026eSblueswir1 char *err; 15351a14026eSblueswir1 15361a14026eSblueswir1 nwindows = strtol(val, &err, 0); 15371a14026eSblueswir1 if (!*val || *err || nwindows > MAX_NWINDOWS || 15381a14026eSblueswir1 nwindows < MIN_NWINDOWS) { 15391a14026eSblueswir1 fprintf(stderr, "bad numerical value %s\n", val); 15401a14026eSblueswir1 goto error; 15411a14026eSblueswir1 } 15421a14026eSblueswir1 cpu_def->nwindows = nwindows; 15431a14026eSblueswir1 #ifdef DEBUG_FEATURES 15441a14026eSblueswir1 fprintf(stderr, "nwindows %d\n", nwindows); 15451a14026eSblueswir1 #endif 154664a88d5dSblueswir1 } else { 154764a88d5dSblueswir1 fprintf(stderr, "unrecognized feature %s\n", featurestr); 154864a88d5dSblueswir1 goto error; 154964a88d5dSblueswir1 } 155064a88d5dSblueswir1 } else { 155177f193daSblueswir1 fprintf(stderr, "feature string `%s' not in format " 155277f193daSblueswir1 "(+feature|-feature|feature=xyz)\n", featurestr); 155364a88d5dSblueswir1 goto error; 155464a88d5dSblueswir1 } 155564a88d5dSblueswir1 featurestr = strtok(NULL, ","); 155664a88d5dSblueswir1 } 155764a88d5dSblueswir1 cpu_def->features |= plus_features; 155864a88d5dSblueswir1 cpu_def->features &= ~minus_features; 155964a88d5dSblueswir1 #ifdef DEBUG_FEATURES 156064a88d5dSblueswir1 print_features(stderr, fprintf, cpu_def->features, NULL); 156164a88d5dSblueswir1 #endif 156264a88d5dSblueswir1 free(s); 156364a88d5dSblueswir1 return 0; 156464a88d5dSblueswir1 156564a88d5dSblueswir1 error: 156664a88d5dSblueswir1 free(s); 156764a88d5dSblueswir1 return -1; 1568c48fcb47Sblueswir1 } 1569c48fcb47Sblueswir1 1570c48fcb47Sblueswir1 void sparc_cpu_list(FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...)) 1571c48fcb47Sblueswir1 { 1572c48fcb47Sblueswir1 unsigned int i; 1573c48fcb47Sblueswir1 1574c48fcb47Sblueswir1 for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) { 15751a14026eSblueswir1 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x NWINS %d ", 1576c48fcb47Sblueswir1 sparc_defs[i].name, 1577c48fcb47Sblueswir1 sparc_defs[i].iu_version, 1578c48fcb47Sblueswir1 sparc_defs[i].fpu_version, 15791a14026eSblueswir1 sparc_defs[i].mmu_version, 15801a14026eSblueswir1 sparc_defs[i].nwindows); 158177f193daSblueswir1 print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES & 158277f193daSblueswir1 ~sparc_defs[i].features, "-"); 158377f193daSblueswir1 print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES & 158477f193daSblueswir1 sparc_defs[i].features, "+"); 158564a88d5dSblueswir1 (*cpu_fprintf)(f, "\n"); 1586c48fcb47Sblueswir1 } 1587f76981b1Sblueswir1 (*cpu_fprintf)(f, "Default CPU feature flags (use '-' to remove): "); 1588f76981b1Sblueswir1 print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES, NULL); 158964a88d5dSblueswir1 (*cpu_fprintf)(f, "\n"); 1590f76981b1Sblueswir1 (*cpu_fprintf)(f, "Available CPU feature flags (use '+' to add): "); 1591f76981b1Sblueswir1 print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES, NULL); 1592f76981b1Sblueswir1 (*cpu_fprintf)(f, "\n"); 1593f76981b1Sblueswir1 (*cpu_fprintf)(f, "Numerical features (use '=' to set): iu_version " 1594f76981b1Sblueswir1 "fpu_version mmu_version nwindows\n"); 1595c48fcb47Sblueswir1 } 1596c48fcb47Sblueswir1 1597c48fcb47Sblueswir1 #define GET_FLAG(a,b) ((env->psr & a)?b:'-') 1598c48fcb47Sblueswir1 1599c48fcb47Sblueswir1 void cpu_dump_state(CPUState *env, FILE *f, 1600c48fcb47Sblueswir1 int (*cpu_fprintf)(FILE *f, const char *fmt, ...), 1601c48fcb47Sblueswir1 int flags) 1602c48fcb47Sblueswir1 { 1603c48fcb47Sblueswir1 int i, x; 1604c48fcb47Sblueswir1 160577f193daSblueswir1 cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, 160677f193daSblueswir1 env->npc); 1607c48fcb47Sblueswir1 cpu_fprintf(f, "General Registers:\n"); 1608c48fcb47Sblueswir1 for (i = 0; i < 4; i++) 1609c48fcb47Sblueswir1 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]); 1610c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1611c48fcb47Sblueswir1 for (; i < 8; i++) 1612c48fcb47Sblueswir1 cpu_fprintf(f, "%%g%c: " TARGET_FMT_lx "\t", i + '0', env->gregs[i]); 1613c48fcb47Sblueswir1 cpu_fprintf(f, "\nCurrent Register Window:\n"); 1614c48fcb47Sblueswir1 for (x = 0; x < 3; x++) { 1615c48fcb47Sblueswir1 for (i = 0; i < 4; i++) 1616c48fcb47Sblueswir1 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t", 1617c48fcb47Sblueswir1 (x == 0 ? 'o' : (x == 1 ? 'l' : 'i')), i, 1618c48fcb47Sblueswir1 env->regwptr[i + x * 8]); 1619c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1620c48fcb47Sblueswir1 for (; i < 8; i++) 1621c48fcb47Sblueswir1 cpu_fprintf(f, "%%%c%d: " TARGET_FMT_lx "\t", 1622c48fcb47Sblueswir1 (x == 0 ? 'o' : x == 1 ? 'l' : 'i'), i, 1623c48fcb47Sblueswir1 env->regwptr[i + x * 8]); 1624c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1625c48fcb47Sblueswir1 } 1626c48fcb47Sblueswir1 cpu_fprintf(f, "\nFloating Point Registers:\n"); 1627c48fcb47Sblueswir1 for (i = 0; i < 32; i++) { 1628c48fcb47Sblueswir1 if ((i & 3) == 0) 1629c48fcb47Sblueswir1 cpu_fprintf(f, "%%f%02d:", i); 1630a37ee56cSblueswir1 cpu_fprintf(f, " %016f", *(float *)&env->fpr[i]); 1631c48fcb47Sblueswir1 if ((i & 3) == 3) 1632c48fcb47Sblueswir1 cpu_fprintf(f, "\n"); 1633c48fcb47Sblueswir1 } 1634c48fcb47Sblueswir1 #ifdef TARGET_SPARC64 1635c48fcb47Sblueswir1 cpu_fprintf(f, "pstate: 0x%08x ccr: 0x%02x asi: 0x%02x tl: %d fprs: %d\n", 1636c48fcb47Sblueswir1 env->pstate, GET_CCR(env), env->asi, env->tl, env->fprs); 163777f193daSblueswir1 cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate %d " 163877f193daSblueswir1 "cleanwin %d cwp %d\n", 1639c48fcb47Sblueswir1 env->cansave, env->canrestore, env->otherwin, env->wstate, 16401a14026eSblueswir1 env->cleanwin, env->nwindows - 1 - env->cwp); 1641c48fcb47Sblueswir1 #else 164277f193daSblueswir1 cpu_fprintf(f, "psr: 0x%08x -> %c%c%c%c %c%c%c wim: 0x%08x\n", 164377f193daSblueswir1 GET_PSR(env), GET_FLAG(PSR_ZERO, 'Z'), GET_FLAG(PSR_OVF, 'V'), 1644c48fcb47Sblueswir1 GET_FLAG(PSR_NEG, 'N'), GET_FLAG(PSR_CARRY, 'C'), 1645c48fcb47Sblueswir1 env->psrs?'S':'-', env->psrps?'P':'-', 1646c48fcb47Sblueswir1 env->psret?'E':'-', env->wim); 1647c48fcb47Sblueswir1 #endif 1648c48fcb47Sblueswir1 cpu_fprintf(f, "fsr: 0x%08x\n", GET_FSR32(env)); 1649c48fcb47Sblueswir1 } 1650c48fcb47Sblueswir1 165187ecb68bSpbrook #ifdef TARGET_SPARC64 165287ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 165387ecb68bSpbrook #include "qemu-common.h" 165487ecb68bSpbrook #include "hw/irq.h" 165587ecb68bSpbrook #include "qemu-timer.h" 165687ecb68bSpbrook #endif 165787ecb68bSpbrook 1658ccd4a219Sblueswir1 void helper_tick_set_count(void *opaque, uint64_t count) 165987ecb68bSpbrook { 166087ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 166187ecb68bSpbrook ptimer_set_count(opaque, -count); 166287ecb68bSpbrook #endif 166387ecb68bSpbrook } 166487ecb68bSpbrook 1665ccd4a219Sblueswir1 uint64_t helper_tick_get_count(void *opaque) 166687ecb68bSpbrook { 166787ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 166887ecb68bSpbrook return -ptimer_get_count(opaque); 166987ecb68bSpbrook #else 167087ecb68bSpbrook return 0; 167187ecb68bSpbrook #endif 167287ecb68bSpbrook } 167387ecb68bSpbrook 1674ccd4a219Sblueswir1 void helper_tick_set_limit(void *opaque, uint64_t limit) 167587ecb68bSpbrook { 167687ecb68bSpbrook #if !defined(CONFIG_USER_ONLY) 167787ecb68bSpbrook ptimer_set_limit(opaque, -limit, 0); 167887ecb68bSpbrook #endif 167987ecb68bSpbrook } 168087ecb68bSpbrook #endif 1681