1ab3b491fSBlue Swirl /* 2ab3b491fSBlue Swirl * Sparc CPU init helpers 3ab3b491fSBlue Swirl * 4ab3b491fSBlue Swirl * Copyright (c) 2003-2005 Fabrice Bellard 5ab3b491fSBlue Swirl * 6ab3b491fSBlue Swirl * This library is free software; you can redistribute it and/or 7ab3b491fSBlue Swirl * modify it under the terms of the GNU Lesser General Public 8ab3b491fSBlue Swirl * License as published by the Free Software Foundation; either 95650b549SChetan Pant * version 2.1 of the License, or (at your option) any later version. 10ab3b491fSBlue Swirl * 11ab3b491fSBlue Swirl * This library is distributed in the hope that it will be useful, 12ab3b491fSBlue Swirl * but WITHOUT ANY WARRANTY; without even the implied warranty of 13ab3b491fSBlue Swirl * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14ab3b491fSBlue Swirl * Lesser General Public License for more details. 15ab3b491fSBlue Swirl * 16ab3b491fSBlue Swirl * You should have received a copy of the GNU Lesser General Public 17ab3b491fSBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18ab3b491fSBlue Swirl */ 19ab3b491fSBlue Swirl 20db5ebe5fSPeter Maydell #include "qemu/osdep.h" 21da34e65cSMarkus Armbruster #include "qapi/error.h" 22ab3b491fSBlue Swirl #include "cpu.h" 230b8fa32fSMarkus Armbruster #include "qemu/module.h" 240442428aSMarkus Armbruster #include "qemu/qemu-print.h" 2563c91552SPaolo Bonzini #include "exec/exec-all.h" 26de05005bSIgor Mammedov #include "hw/qdev-properties.h" 27de05005bSIgor Mammedov #include "qapi/visitor.h" 28ab3b491fSBlue Swirl 29ab3b491fSBlue Swirl //#define DEBUG_FEATURES 30ab3b491fSBlue Swirl 31781c67caSPeter Maydell static void sparc_cpu_reset(DeviceState *dev) 32ab7ab3d7SAndreas Färber { 33781c67caSPeter Maydell CPUState *s = CPU(dev); 34ab7ab3d7SAndreas Färber SPARCCPU *cpu = SPARC_CPU(s); 35ab7ab3d7SAndreas Färber SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(cpu); 36ab7ab3d7SAndreas Färber CPUSPARCState *env = &cpu->env; 37ab7ab3d7SAndreas Färber 38781c67caSPeter Maydell scc->parent_reset(dev); 39ab7ab3d7SAndreas Färber 401f5c00cfSAlex Bennée memset(env, 0, offsetof(CPUSPARCState, end_reset_fields)); 41ab3b491fSBlue Swirl env->cwp = 0; 42ab3b491fSBlue Swirl #ifndef TARGET_SPARC64 43ab3b491fSBlue Swirl env->wim = 1; 44ab3b491fSBlue Swirl #endif 45ab3b491fSBlue Swirl env->regwptr = env->regbase + (env->cwp * 16); 46ab3b491fSBlue Swirl CC_OP = CC_OP_FLAGS; 47ab3b491fSBlue Swirl #if defined(CONFIG_USER_ONLY) 48ab3b491fSBlue Swirl #ifdef TARGET_SPARC64 49ab3b491fSBlue Swirl env->cleanwin = env->nwindows - 2; 50ab3b491fSBlue Swirl env->cansave = env->nwindows - 2; 51ab3b491fSBlue Swirl env->pstate = PS_RMO | PS_PEF | PS_IE; 52ab3b491fSBlue Swirl env->asi = 0x82; /* Primary no-fault */ 53ab3b491fSBlue Swirl #endif 54ab3b491fSBlue Swirl #else 55ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64) 56ab3b491fSBlue Swirl env->psret = 0; 57ab3b491fSBlue Swirl env->psrs = 1; 58ab3b491fSBlue Swirl env->psrps = 1; 59ab3b491fSBlue Swirl #endif 60ab3b491fSBlue Swirl #ifdef TARGET_SPARC64 61cbc3a6a4SArtyom Tarasenko env->pstate = PS_PRIV | PS_RED | PS_PEF; 62cbc3a6a4SArtyom Tarasenko if (!cpu_has_hypervisor(env)) { 63cbc3a6a4SArtyom Tarasenko env->pstate |= PS_AG; 64cbc3a6a4SArtyom Tarasenko } 65ab3b491fSBlue Swirl env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0; 66ab3b491fSBlue Swirl env->tl = env->maxtl; 67cbc3a6a4SArtyom Tarasenko env->gl = 2; 68ab3b491fSBlue Swirl cpu_tsptr(env)->tt = TT_POWER_ON_RESET; 69ab3b491fSBlue Swirl env->lsu = 0; 70ab3b491fSBlue Swirl #else 71ab3b491fSBlue Swirl env->mmuregs[0] &= ~(MMU_E | MMU_NF); 72576e1c4cSIgor Mammedov env->mmuregs[0] |= env->def.mmu_bm; 73ab3b491fSBlue Swirl #endif 74ab3b491fSBlue Swirl env->pc = 0; 75ab3b491fSBlue Swirl env->npc = env->pc + 4; 76ab3b491fSBlue Swirl #endif 77ab3b491fSBlue Swirl env->cache_control = 0; 78ab3b491fSBlue Swirl } 79ab3b491fSBlue Swirl 80798ac8b5SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY 8187afe467SRichard Henderson static bool sparc_cpu_exec_interrupt(CPUState *cs, int interrupt_request) 8287afe467SRichard Henderson { 8387afe467SRichard Henderson if (interrupt_request & CPU_INTERRUPT_HARD) { 8487afe467SRichard Henderson SPARCCPU *cpu = SPARC_CPU(cs); 8587afe467SRichard Henderson CPUSPARCState *env = &cpu->env; 8687afe467SRichard Henderson 8787afe467SRichard Henderson if (cpu_interrupts_enabled(env) && env->interrupt_index > 0) { 8887afe467SRichard Henderson int pil = env->interrupt_index & 0xf; 8987afe467SRichard Henderson int type = env->interrupt_index & 0xf0; 9087afe467SRichard Henderson 9187afe467SRichard Henderson if (type != TT_EXTINT || cpu_pil_allowed(env, pil)) { 9287afe467SRichard Henderson cs->exception_index = env->interrupt_index; 9387afe467SRichard Henderson sparc_cpu_do_interrupt(cs); 9487afe467SRichard Henderson return true; 9587afe467SRichard Henderson } 9687afe467SRichard Henderson } 9787afe467SRichard Henderson } 9887afe467SRichard Henderson return false; 9987afe467SRichard Henderson } 100798ac8b5SPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */ 10187afe467SRichard Henderson 102df0900ebSPeter Crosthwaite static void cpu_sparc_disas_set_info(CPUState *cpu, disassemble_info *info) 103df0900ebSPeter Crosthwaite { 104df0900ebSPeter Crosthwaite info->print_insn = print_insn_sparc; 105df0900ebSPeter Crosthwaite #ifdef TARGET_SPARC64 106df0900ebSPeter Crosthwaite info->mach = bfd_mach_sparc_v9b; 107df0900ebSPeter Crosthwaite #endif 108df0900ebSPeter Crosthwaite } 109df0900ebSPeter Crosthwaite 110d1853231SIgor Mammedov static void 111d1853231SIgor Mammedov cpu_add_feat_as_prop(const char *typename, const char *name, const char *val) 112ab3b491fSBlue Swirl { 113d1853231SIgor Mammedov GlobalProperty *prop = g_new0(typeof(*prop), 1); 114d1853231SIgor Mammedov prop->driver = typename; 115d1853231SIgor Mammedov prop->property = g_strdup(name); 116d1853231SIgor Mammedov prop->value = g_strdup(val); 117d1853231SIgor Mammedov qdev_prop_register_global(prop); 118433ac7a9SAndreas Färber } 119433ac7a9SAndreas Färber 120d1853231SIgor Mammedov /* Parse "+feature,-feature,feature=foo" CPU feature string */ 121d1853231SIgor Mammedov static void sparc_cpu_parse_features(const char *typename, char *features, 122d1853231SIgor Mammedov Error **errp) 123d1853231SIgor Mammedov { 124d1853231SIgor Mammedov GList *l, *plus_features = NULL, *minus_features = NULL; 125d1853231SIgor Mammedov char *featurestr; /* Single 'key=value" string being parsed */ 126d1853231SIgor Mammedov static bool cpu_globals_initialized; 127d1853231SIgor Mammedov 128d1853231SIgor Mammedov if (cpu_globals_initialized) { 129d1853231SIgor Mammedov return; 130d1853231SIgor Mammedov } 131d1853231SIgor Mammedov cpu_globals_initialized = true; 132d1853231SIgor Mammedov 133d1853231SIgor Mammedov if (!features) { 134d1853231SIgor Mammedov return; 135d1853231SIgor Mammedov } 136d1853231SIgor Mammedov 137d1853231SIgor Mammedov for (featurestr = strtok(features, ","); 138d1853231SIgor Mammedov featurestr; 139d1853231SIgor Mammedov featurestr = strtok(NULL, ",")) { 140d1853231SIgor Mammedov const char *name; 141d1853231SIgor Mammedov const char *val = NULL; 142d1853231SIgor Mammedov char *eq = NULL; 143d1853231SIgor Mammedov 144d1853231SIgor Mammedov /* Compatibility syntax: */ 145d1853231SIgor Mammedov if (featurestr[0] == '+') { 146d1853231SIgor Mammedov plus_features = g_list_append(plus_features, 147d1853231SIgor Mammedov g_strdup(featurestr + 1)); 148d1853231SIgor Mammedov continue; 149d1853231SIgor Mammedov } else if (featurestr[0] == '-') { 150d1853231SIgor Mammedov minus_features = g_list_append(minus_features, 151d1853231SIgor Mammedov g_strdup(featurestr + 1)); 152d1853231SIgor Mammedov continue; 153d1853231SIgor Mammedov } 154d1853231SIgor Mammedov 155d1853231SIgor Mammedov eq = strchr(featurestr, '='); 156d1853231SIgor Mammedov name = featurestr; 157d1853231SIgor Mammedov if (eq) { 158d1853231SIgor Mammedov *eq++ = 0; 159d1853231SIgor Mammedov val = eq; 160d1853231SIgor Mammedov 161d1853231SIgor Mammedov /* 162d1853231SIgor Mammedov * Temporarily, only +feat/-feat will be supported 163d1853231SIgor Mammedov * for boolean properties until we remove the 164d1853231SIgor Mammedov * minus-overrides-plus semantics and just follow 165d1853231SIgor Mammedov * the order options appear on the command-line. 166d1853231SIgor Mammedov * 167d1853231SIgor Mammedov * TODO: warn if user is relying on minus-override-plus semantics 168d1853231SIgor Mammedov * TODO: remove minus-override-plus semantics after 169d1853231SIgor Mammedov * warning for a few releases 170d1853231SIgor Mammedov */ 171d1853231SIgor Mammedov if (!strcasecmp(val, "on") || 172d1853231SIgor Mammedov !strcasecmp(val, "off") || 173d1853231SIgor Mammedov !strcasecmp(val, "true") || 174d1853231SIgor Mammedov !strcasecmp(val, "false")) { 175d1853231SIgor Mammedov error_setg(errp, "Boolean properties in format %s=%s" 176d1853231SIgor Mammedov " are not supported", name, val); 177d1853231SIgor Mammedov return; 178d1853231SIgor Mammedov } 179d1853231SIgor Mammedov } else { 180d1853231SIgor Mammedov error_setg(errp, "Unsupported property format: %s", name); 181d1853231SIgor Mammedov return; 182d1853231SIgor Mammedov } 183d1853231SIgor Mammedov cpu_add_feat_as_prop(typename, name, val); 184d1853231SIgor Mammedov } 185d1853231SIgor Mammedov 186d1853231SIgor Mammedov for (l = plus_features; l; l = l->next) { 187d1853231SIgor Mammedov const char *name = l->data; 188d1853231SIgor Mammedov cpu_add_feat_as_prop(typename, name, "on"); 189d1853231SIgor Mammedov } 190d1853231SIgor Mammedov g_list_free_full(plus_features, g_free); 191d1853231SIgor Mammedov 192d1853231SIgor Mammedov for (l = minus_features; l; l = l->next) { 193d1853231SIgor Mammedov const char *name = l->data; 194d1853231SIgor Mammedov cpu_add_feat_as_prop(typename, name, "off"); 195d1853231SIgor Mammedov } 196d1853231SIgor Mammedov g_list_free_full(minus_features, g_free); 197ab3b491fSBlue Swirl } 198ab3b491fSBlue Swirl 199ab3b491fSBlue Swirl void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu) 200ab3b491fSBlue Swirl { 201ab3b491fSBlue Swirl #if !defined(TARGET_SPARC64) 202ab3b491fSBlue Swirl env->mxccregs[7] = ((cpu + 8) & 0xf) << 24; 203ab3b491fSBlue Swirl #endif 204ab3b491fSBlue Swirl } 205ab3b491fSBlue Swirl 206ab3b491fSBlue Swirl static const sparc_def_t sparc_defs[] = { 207ab3b491fSBlue Swirl #ifdef TARGET_SPARC64 208ab3b491fSBlue Swirl { 209ab3b491fSBlue Swirl .name = "Fujitsu Sparc64", 210ab3b491fSBlue Swirl .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)), 211ab3b491fSBlue Swirl .fpu_version = 0x00000000, 212ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 213ab3b491fSBlue Swirl .nwindows = 4, 214ab3b491fSBlue Swirl .maxtl = 4, 215ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 216ab3b491fSBlue Swirl }, 217ab3b491fSBlue Swirl { 218ab3b491fSBlue Swirl .name = "Fujitsu Sparc64 III", 219ab3b491fSBlue Swirl .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)), 220ab3b491fSBlue Swirl .fpu_version = 0x00000000, 221ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 222ab3b491fSBlue Swirl .nwindows = 5, 223ab3b491fSBlue Swirl .maxtl = 4, 224ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 225ab3b491fSBlue Swirl }, 226ab3b491fSBlue Swirl { 227ab3b491fSBlue Swirl .name = "Fujitsu Sparc64 IV", 228ab3b491fSBlue Swirl .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)), 229ab3b491fSBlue Swirl .fpu_version = 0x00000000, 230ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 231ab3b491fSBlue Swirl .nwindows = 8, 232ab3b491fSBlue Swirl .maxtl = 5, 233ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 234ab3b491fSBlue Swirl }, 235ab3b491fSBlue Swirl { 236ab3b491fSBlue Swirl .name = "Fujitsu Sparc64 V", 237ab3b491fSBlue Swirl .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)), 238ab3b491fSBlue Swirl .fpu_version = 0x00000000, 239ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 240ab3b491fSBlue Swirl .nwindows = 8, 241ab3b491fSBlue Swirl .maxtl = 5, 242ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 243ab3b491fSBlue Swirl }, 244ab3b491fSBlue Swirl { 245ab3b491fSBlue Swirl .name = "TI UltraSparc I", 246ab3b491fSBlue Swirl .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)), 247ab3b491fSBlue Swirl .fpu_version = 0x00000000, 248ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 249ab3b491fSBlue Swirl .nwindows = 8, 250ab3b491fSBlue Swirl .maxtl = 5, 251ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 252ab3b491fSBlue Swirl }, 253ab3b491fSBlue Swirl { 254ab3b491fSBlue Swirl .name = "TI UltraSparc II", 255ab3b491fSBlue Swirl .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)), 256ab3b491fSBlue Swirl .fpu_version = 0x00000000, 257ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 258ab3b491fSBlue Swirl .nwindows = 8, 259ab3b491fSBlue Swirl .maxtl = 5, 260ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 261ab3b491fSBlue Swirl }, 262ab3b491fSBlue Swirl { 263ab3b491fSBlue Swirl .name = "TI UltraSparc IIi", 264ab3b491fSBlue Swirl .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)), 265ab3b491fSBlue Swirl .fpu_version = 0x00000000, 266ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 267ab3b491fSBlue Swirl .nwindows = 8, 268ab3b491fSBlue Swirl .maxtl = 5, 269ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 270ab3b491fSBlue Swirl }, 271ab3b491fSBlue Swirl { 272ab3b491fSBlue Swirl .name = "TI UltraSparc IIe", 273ab3b491fSBlue Swirl .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)), 274ab3b491fSBlue Swirl .fpu_version = 0x00000000, 275ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 276ab3b491fSBlue Swirl .nwindows = 8, 277ab3b491fSBlue Swirl .maxtl = 5, 278ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 279ab3b491fSBlue Swirl }, 280ab3b491fSBlue Swirl { 281ab3b491fSBlue Swirl .name = "Sun UltraSparc III", 282ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)), 283ab3b491fSBlue Swirl .fpu_version = 0x00000000, 284ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 285ab3b491fSBlue Swirl .nwindows = 8, 286ab3b491fSBlue Swirl .maxtl = 5, 287ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 288ab3b491fSBlue Swirl }, 289ab3b491fSBlue Swirl { 290ab3b491fSBlue Swirl .name = "Sun UltraSparc III Cu", 291ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)), 292ab3b491fSBlue Swirl .fpu_version = 0x00000000, 293ab3b491fSBlue Swirl .mmu_version = mmu_us_3, 294ab3b491fSBlue Swirl .nwindows = 8, 295ab3b491fSBlue Swirl .maxtl = 5, 296ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 297ab3b491fSBlue Swirl }, 298ab3b491fSBlue Swirl { 299ab3b491fSBlue Swirl .name = "Sun UltraSparc IIIi", 300ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)), 301ab3b491fSBlue Swirl .fpu_version = 0x00000000, 302ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 303ab3b491fSBlue Swirl .nwindows = 8, 304ab3b491fSBlue Swirl .maxtl = 5, 305ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 306ab3b491fSBlue Swirl }, 307ab3b491fSBlue Swirl { 308ab3b491fSBlue Swirl .name = "Sun UltraSparc IV", 309ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)), 310ab3b491fSBlue Swirl .fpu_version = 0x00000000, 311ab3b491fSBlue Swirl .mmu_version = mmu_us_4, 312ab3b491fSBlue Swirl .nwindows = 8, 313ab3b491fSBlue Swirl .maxtl = 5, 314ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 315ab3b491fSBlue Swirl }, 316ab3b491fSBlue Swirl { 317ab3b491fSBlue Swirl .name = "Sun UltraSparc IV+", 318ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)), 319ab3b491fSBlue Swirl .fpu_version = 0x00000000, 320ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 321ab3b491fSBlue Swirl .nwindows = 8, 322ab3b491fSBlue Swirl .maxtl = 5, 323ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT, 324ab3b491fSBlue Swirl }, 325ab3b491fSBlue Swirl { 326ab3b491fSBlue Swirl .name = "Sun UltraSparc IIIi+", 327ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)), 328ab3b491fSBlue Swirl .fpu_version = 0x00000000, 329ab3b491fSBlue Swirl .mmu_version = mmu_us_3, 330ab3b491fSBlue Swirl .nwindows = 8, 331ab3b491fSBlue Swirl .maxtl = 5, 332ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 333ab3b491fSBlue Swirl }, 334ab3b491fSBlue Swirl { 335ab3b491fSBlue Swirl .name = "Sun UltraSparc T1", 336ab3b491fSBlue Swirl /* defined in sparc_ifu_fdp.v and ctu.h */ 337ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)), 338ab3b491fSBlue Swirl .fpu_version = 0x00000000, 339ab3b491fSBlue Swirl .mmu_version = mmu_sun4v, 340ab3b491fSBlue Swirl .nwindows = 8, 341ab3b491fSBlue Swirl .maxtl = 6, 342ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT 343ab3b491fSBlue Swirl | CPU_FEATURE_GL, 344ab3b491fSBlue Swirl }, 345ab3b491fSBlue Swirl { 346ab3b491fSBlue Swirl .name = "Sun UltraSparc T2", 347ab3b491fSBlue Swirl /* defined in tlu_asi_ctl.v and n2_revid_cust.v */ 348ab3b491fSBlue Swirl .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)), 349ab3b491fSBlue Swirl .fpu_version = 0x00000000, 350ab3b491fSBlue Swirl .mmu_version = mmu_sun4v, 351ab3b491fSBlue Swirl .nwindows = 8, 352ab3b491fSBlue Swirl .maxtl = 6, 353ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT 354ab3b491fSBlue Swirl | CPU_FEATURE_GL, 355ab3b491fSBlue Swirl }, 356ab3b491fSBlue Swirl { 357ab3b491fSBlue Swirl .name = "NEC UltraSparc I", 358ab3b491fSBlue Swirl .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)), 359ab3b491fSBlue Swirl .fpu_version = 0x00000000, 360ab3b491fSBlue Swirl .mmu_version = mmu_us_12, 361ab3b491fSBlue Swirl .nwindows = 8, 362ab3b491fSBlue Swirl .maxtl = 5, 363ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 364ab3b491fSBlue Swirl }, 365ab3b491fSBlue Swirl #else 366ab3b491fSBlue Swirl { 367ab3b491fSBlue Swirl .name = "Fujitsu MB86904", 368ab3b491fSBlue Swirl .iu_version = 0x04 << 24, /* Impl 0, ver 4 */ 369ab3b491fSBlue Swirl .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 370ab3b491fSBlue Swirl .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */ 371ab3b491fSBlue Swirl .mmu_bm = 0x00004000, 372ab3b491fSBlue Swirl .mmu_ctpr_mask = 0x00ffffc0, 373ab3b491fSBlue Swirl .mmu_cxr_mask = 0x000000ff, 374ab3b491fSBlue Swirl .mmu_sfsr_mask = 0x00016fff, 375ab3b491fSBlue Swirl .mmu_trcr_mask = 0x00ffffff, 376ab3b491fSBlue Swirl .nwindows = 8, 377ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 378ab3b491fSBlue Swirl }, 379ab3b491fSBlue Swirl { 380ab3b491fSBlue Swirl .name = "Fujitsu MB86907", 381ab3b491fSBlue Swirl .iu_version = 0x05 << 24, /* Impl 0, ver 5 */ 382ab3b491fSBlue Swirl .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 383ab3b491fSBlue Swirl .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */ 384ab3b491fSBlue Swirl .mmu_bm = 0x00004000, 385ab3b491fSBlue Swirl .mmu_ctpr_mask = 0xffffffc0, 386ab3b491fSBlue Swirl .mmu_cxr_mask = 0x000000ff, 387ab3b491fSBlue Swirl .mmu_sfsr_mask = 0x00016fff, 388ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 389ab3b491fSBlue Swirl .nwindows = 8, 390ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 391ab3b491fSBlue Swirl }, 392ab3b491fSBlue Swirl { 393ab3b491fSBlue Swirl .name = "TI MicroSparc I", 394ab3b491fSBlue Swirl .iu_version = 0x41000000, 395ab3b491fSBlue Swirl .fpu_version = 4 << 17, 396ab3b491fSBlue Swirl .mmu_version = 0x41000000, 397ab3b491fSBlue Swirl .mmu_bm = 0x00004000, 398ab3b491fSBlue Swirl .mmu_ctpr_mask = 0x007ffff0, 399ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000003f, 400ab3b491fSBlue Swirl .mmu_sfsr_mask = 0x00016fff, 401ab3b491fSBlue Swirl .mmu_trcr_mask = 0x0000003f, 402ab3b491fSBlue Swirl .nwindows = 7, 403ab3b491fSBlue Swirl .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL | 404ab3b491fSBlue Swirl CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | 405ab3b491fSBlue Swirl CPU_FEATURE_FMUL, 406ab3b491fSBlue Swirl }, 407ab3b491fSBlue Swirl { 408ab3b491fSBlue Swirl .name = "TI MicroSparc II", 409ab3b491fSBlue Swirl .iu_version = 0x42000000, 410ab3b491fSBlue Swirl .fpu_version = 4 << 17, 411ab3b491fSBlue Swirl .mmu_version = 0x02000000, 412ab3b491fSBlue Swirl .mmu_bm = 0x00004000, 413ab3b491fSBlue Swirl .mmu_ctpr_mask = 0x00ffffc0, 414ab3b491fSBlue Swirl .mmu_cxr_mask = 0x000000ff, 415ab3b491fSBlue Swirl .mmu_sfsr_mask = 0x00016fff, 416ab3b491fSBlue Swirl .mmu_trcr_mask = 0x00ffffff, 417ab3b491fSBlue Swirl .nwindows = 8, 418ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 419ab3b491fSBlue Swirl }, 420ab3b491fSBlue Swirl { 421ab3b491fSBlue Swirl .name = "TI MicroSparc IIep", 422ab3b491fSBlue Swirl .iu_version = 0x42000000, 423ab3b491fSBlue Swirl .fpu_version = 4 << 17, 424ab3b491fSBlue Swirl .mmu_version = 0x04000000, 425ab3b491fSBlue Swirl .mmu_bm = 0x00004000, 426ab3b491fSBlue Swirl .mmu_ctpr_mask = 0x00ffffc0, 427ab3b491fSBlue Swirl .mmu_cxr_mask = 0x000000ff, 428ab3b491fSBlue Swirl .mmu_sfsr_mask = 0x00016bff, 429ab3b491fSBlue Swirl .mmu_trcr_mask = 0x00ffffff, 430ab3b491fSBlue Swirl .nwindows = 8, 431ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 432ab3b491fSBlue Swirl }, 433ab3b491fSBlue Swirl { 434ab3b491fSBlue Swirl .name = "TI SuperSparc 40", /* STP1020NPGA */ 435ab3b491fSBlue Swirl .iu_version = 0x41000000, /* SuperSPARC 2.x */ 436ab3b491fSBlue Swirl .fpu_version = 0 << 17, 437ab3b491fSBlue Swirl .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */ 438ab3b491fSBlue Swirl .mmu_bm = 0x00002000, 439ab3b491fSBlue Swirl .mmu_ctpr_mask = 0xffffffc0, 440ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000ffff, 441ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 442ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 443ab3b491fSBlue Swirl .nwindows = 8, 444ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 445ab3b491fSBlue Swirl }, 446ab3b491fSBlue Swirl { 447ab3b491fSBlue Swirl .name = "TI SuperSparc 50", /* STP1020PGA */ 448ab3b491fSBlue Swirl .iu_version = 0x40000000, /* SuperSPARC 3.x */ 449ab3b491fSBlue Swirl .fpu_version = 0 << 17, 450ab3b491fSBlue Swirl .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */ 451ab3b491fSBlue Swirl .mmu_bm = 0x00002000, 452ab3b491fSBlue Swirl .mmu_ctpr_mask = 0xffffffc0, 453ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000ffff, 454ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 455ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 456ab3b491fSBlue Swirl .nwindows = 8, 457ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 458ab3b491fSBlue Swirl }, 459ab3b491fSBlue Swirl { 460ab3b491fSBlue Swirl .name = "TI SuperSparc 51", 461ab3b491fSBlue Swirl .iu_version = 0x40000000, /* SuperSPARC 3.x */ 462ab3b491fSBlue Swirl .fpu_version = 0 << 17, 463ab3b491fSBlue Swirl .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */ 464ab3b491fSBlue Swirl .mmu_bm = 0x00002000, 465ab3b491fSBlue Swirl .mmu_ctpr_mask = 0xffffffc0, 466ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000ffff, 467ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 468ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 469ab3b491fSBlue Swirl .mxcc_version = 0x00000104, 470ab3b491fSBlue Swirl .nwindows = 8, 471ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 472ab3b491fSBlue Swirl }, 473ab3b491fSBlue Swirl { 474ab3b491fSBlue Swirl .name = "TI SuperSparc 60", /* STP1020APGA */ 475ab3b491fSBlue Swirl .iu_version = 0x40000000, /* SuperSPARC 3.x */ 476ab3b491fSBlue Swirl .fpu_version = 0 << 17, 477ab3b491fSBlue Swirl .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */ 478ab3b491fSBlue Swirl .mmu_bm = 0x00002000, 479ab3b491fSBlue Swirl .mmu_ctpr_mask = 0xffffffc0, 480ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000ffff, 481ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 482ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 483ab3b491fSBlue Swirl .nwindows = 8, 484ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 485ab3b491fSBlue Swirl }, 486ab3b491fSBlue Swirl { 487ab3b491fSBlue Swirl .name = "TI SuperSparc 61", 488ab3b491fSBlue Swirl .iu_version = 0x44000000, /* SuperSPARC 3.x */ 489ab3b491fSBlue Swirl .fpu_version = 0 << 17, 490ab3b491fSBlue Swirl .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */ 491ab3b491fSBlue Swirl .mmu_bm = 0x00002000, 492ab3b491fSBlue Swirl .mmu_ctpr_mask = 0xffffffc0, 493ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000ffff, 494ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 495ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 496ab3b491fSBlue Swirl .mxcc_version = 0x00000104, 497ab3b491fSBlue Swirl .nwindows = 8, 498ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 499ab3b491fSBlue Swirl }, 500ab3b491fSBlue Swirl { 501ab3b491fSBlue Swirl .name = "TI SuperSparc II", 502ab3b491fSBlue Swirl .iu_version = 0x40000000, /* SuperSPARC II 1.x */ 503ab3b491fSBlue Swirl .fpu_version = 0 << 17, 504ab3b491fSBlue Swirl .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */ 505ab3b491fSBlue Swirl .mmu_bm = 0x00002000, 506ab3b491fSBlue Swirl .mmu_ctpr_mask = 0xffffffc0, 507ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000ffff, 508ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 509ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 510ab3b491fSBlue Swirl .mxcc_version = 0x00000104, 511ab3b491fSBlue Swirl .nwindows = 8, 512ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES, 513ab3b491fSBlue Swirl }, 514ab3b491fSBlue Swirl { 515ab3b491fSBlue Swirl .name = "LEON2", 516ab3b491fSBlue Swirl .iu_version = 0xf2000000, 517ab3b491fSBlue Swirl .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 518ab3b491fSBlue Swirl .mmu_version = 0xf2000000, 519ab3b491fSBlue Swirl .mmu_bm = 0x00004000, 520ab3b491fSBlue Swirl .mmu_ctpr_mask = 0x007ffff0, 521ab3b491fSBlue Swirl .mmu_cxr_mask = 0x0000003f, 522ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 523ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 524ab3b491fSBlue Swirl .nwindows = 8, 525ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN, 526ab3b491fSBlue Swirl }, 527ab3b491fSBlue Swirl { 528ab3b491fSBlue Swirl .name = "LEON3", 529ab3b491fSBlue Swirl .iu_version = 0xf3000000, 530ab3b491fSBlue Swirl .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */ 531ab3b491fSBlue Swirl .mmu_version = 0xf3000000, 532ab3b491fSBlue Swirl .mmu_bm = 0x00000000, 5337a0a9c2cSRonald Hecht .mmu_ctpr_mask = 0xfffffffc, 5347a0a9c2cSRonald Hecht .mmu_cxr_mask = 0x000000ff, 535ab3b491fSBlue Swirl .mmu_sfsr_mask = 0xffffffff, 536ab3b491fSBlue Swirl .mmu_trcr_mask = 0xffffffff, 537ab3b491fSBlue Swirl .nwindows = 8, 538ab3b491fSBlue Swirl .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN | 53916c358e9SSebastian Huber CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL | CPU_FEATURE_POWERDOWN | 54016c358e9SSebastian Huber CPU_FEATURE_CASA, 541ab3b491fSBlue Swirl }, 542ab3b491fSBlue Swirl #endif 543ab3b491fSBlue Swirl }; 544ab3b491fSBlue Swirl 545ab3b491fSBlue Swirl static const char * const feature_name[] = { 546ab3b491fSBlue Swirl "float", 547ab3b491fSBlue Swirl "float128", 548ab3b491fSBlue Swirl "swap", 549ab3b491fSBlue Swirl "mul", 550ab3b491fSBlue Swirl "div", 551ab3b491fSBlue Swirl "flush", 552ab3b491fSBlue Swirl "fsqrt", 553ab3b491fSBlue Swirl "fmul", 554ab3b491fSBlue Swirl "vis1", 555ab3b491fSBlue Swirl "vis2", 556ab3b491fSBlue Swirl "fsmuld", 557ab3b491fSBlue Swirl "hypv", 558ab3b491fSBlue Swirl "cmt", 559ab3b491fSBlue Swirl "gl", 560ab3b491fSBlue Swirl }; 561ab3b491fSBlue Swirl 5620442428aSMarkus Armbruster static void print_features(uint32_t features, const char *prefix) 563ab3b491fSBlue Swirl { 564ab3b491fSBlue Swirl unsigned int i; 565ab3b491fSBlue Swirl 566ab3b491fSBlue Swirl for (i = 0; i < ARRAY_SIZE(feature_name); i++) { 567ab3b491fSBlue Swirl if (feature_name[i] && (features & (1 << i))) { 568ab3b491fSBlue Swirl if (prefix) { 5690442428aSMarkus Armbruster qemu_printf("%s", prefix); 570ab3b491fSBlue Swirl } 5710442428aSMarkus Armbruster qemu_printf("%s ", feature_name[i]); 572ab3b491fSBlue Swirl } 573ab3b491fSBlue Swirl } 574ab3b491fSBlue Swirl } 575ab3b491fSBlue Swirl 5760442428aSMarkus Armbruster void sparc_cpu_list(void) 577ab3b491fSBlue Swirl { 578ab3b491fSBlue Swirl unsigned int i; 579ab3b491fSBlue Swirl 580ab3b491fSBlue Swirl for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) { 5810442428aSMarkus Armbruster qemu_printf("Sparc %16s IU " TARGET_FMT_lx 582ab3b491fSBlue Swirl " FPU %08x MMU %08x NWINS %d ", 583ab3b491fSBlue Swirl sparc_defs[i].name, 584ab3b491fSBlue Swirl sparc_defs[i].iu_version, 585ab3b491fSBlue Swirl sparc_defs[i].fpu_version, 586ab3b491fSBlue Swirl sparc_defs[i].mmu_version, 587ab3b491fSBlue Swirl sparc_defs[i].nwindows); 5880442428aSMarkus Armbruster print_features(CPU_DEFAULT_FEATURES & ~sparc_defs[i].features, "-"); 5890442428aSMarkus Armbruster print_features(~CPU_DEFAULT_FEATURES & sparc_defs[i].features, "+"); 5900442428aSMarkus Armbruster qemu_printf("\n"); 591ab3b491fSBlue Swirl } 5920442428aSMarkus Armbruster qemu_printf("Default CPU feature flags (use '-' to remove): "); 5930442428aSMarkus Armbruster print_features(CPU_DEFAULT_FEATURES, NULL); 5940442428aSMarkus Armbruster qemu_printf("\n"); 5950442428aSMarkus Armbruster qemu_printf("Available CPU feature flags (use '+' to add): "); 5960442428aSMarkus Armbruster print_features(~CPU_DEFAULT_FEATURES, NULL); 5970442428aSMarkus Armbruster qemu_printf("\n"); 5980442428aSMarkus Armbruster qemu_printf("Numerical features (use '=' to set): iu_version " 599ab3b491fSBlue Swirl "fpu_version mmu_version nwindows\n"); 600ab3b491fSBlue Swirl } 601ab3b491fSBlue Swirl 60290c84c56SMarkus Armbruster static void cpu_print_cc(FILE *f, uint32_t cc) 603ab3b491fSBlue Swirl { 60490c84c56SMarkus Armbruster qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-', 605ab3b491fSBlue Swirl cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-', 606ab3b491fSBlue Swirl cc & PSR_CARRY ? 'C' : '-'); 607ab3b491fSBlue Swirl } 608ab3b491fSBlue Swirl 609ab3b491fSBlue Swirl #ifdef TARGET_SPARC64 610ab3b491fSBlue Swirl #define REGS_PER_LINE 4 611ab3b491fSBlue Swirl #else 612ab3b491fSBlue Swirl #define REGS_PER_LINE 8 613ab3b491fSBlue Swirl #endif 614ab3b491fSBlue Swirl 6159ac200acSPhilippe Mathieu-Daudé static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags) 616ab3b491fSBlue Swirl { 617878096eeSAndreas Färber SPARCCPU *cpu = SPARC_CPU(cs); 618878096eeSAndreas Färber CPUSPARCState *env = &cpu->env; 619ab3b491fSBlue Swirl int i, x; 620ab3b491fSBlue Swirl 62190c84c56SMarkus Armbruster qemu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc, 622ab3b491fSBlue Swirl env->npc); 623ab3b491fSBlue Swirl 624ab3b491fSBlue Swirl for (i = 0; i < 8; i++) { 625ab3b491fSBlue Swirl if (i % REGS_PER_LINE == 0) { 62690c84c56SMarkus Armbruster qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1); 627ab3b491fSBlue Swirl } 62890c84c56SMarkus Armbruster qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]); 629ab3b491fSBlue Swirl if (i % REGS_PER_LINE == REGS_PER_LINE - 1) { 63090c84c56SMarkus Armbruster qemu_fprintf(f, "\n"); 631ab3b491fSBlue Swirl } 632ab3b491fSBlue Swirl } 633ab3b491fSBlue Swirl for (x = 0; x < 3; x++) { 634ab3b491fSBlue Swirl for (i = 0; i < 8; i++) { 635ab3b491fSBlue Swirl if (i % REGS_PER_LINE == 0) { 63690c84c56SMarkus Armbruster qemu_fprintf(f, "%%%c%d-%d: ", 637ab3b491fSBlue Swirl x == 0 ? 'o' : (x == 1 ? 'l' : 'i'), 638ab3b491fSBlue Swirl i, i + REGS_PER_LINE - 1); 639ab3b491fSBlue Swirl } 64090c84c56SMarkus Armbruster qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]); 641ab3b491fSBlue Swirl if (i % REGS_PER_LINE == REGS_PER_LINE - 1) { 64290c84c56SMarkus Armbruster qemu_fprintf(f, "\n"); 643ab3b491fSBlue Swirl } 644ab3b491fSBlue Swirl } 645ab3b491fSBlue Swirl } 64676a23ca0SRichard Henderson 647d13c394cSRichard Henderson if (flags & CPU_DUMP_FPU) { 64830038fd8SRichard Henderson for (i = 0; i < TARGET_DPREGS; i++) { 649ab3b491fSBlue Swirl if ((i & 3) == 0) { 65090c84c56SMarkus Armbruster qemu_fprintf(f, "%%f%02d: ", i * 2); 651ab3b491fSBlue Swirl } 65290c84c56SMarkus Armbruster qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll); 653ab3b491fSBlue Swirl if ((i & 3) == 3) { 65490c84c56SMarkus Armbruster qemu_fprintf(f, "\n"); 655ab3b491fSBlue Swirl } 656ab3b491fSBlue Swirl } 657d13c394cSRichard Henderson } 658d13c394cSRichard Henderson 659ab3b491fSBlue Swirl #ifdef TARGET_SPARC64 66090c84c56SMarkus Armbruster qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate, 661ab3b491fSBlue Swirl (unsigned)cpu_get_ccr(env)); 66290c84c56SMarkus Armbruster cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT); 66390c84c56SMarkus Armbruster qemu_fprintf(f, " xcc: "); 66490c84c56SMarkus Armbruster cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4)); 66590c84c56SMarkus Armbruster qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl, 666cbc3a6a4SArtyom Tarasenko env->psrpil, env->gl); 66790c84c56SMarkus Armbruster qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: " 668cbc3a6a4SArtyom Tarasenko TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba); 66990c84c56SMarkus Armbruster qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d " 670ab3b491fSBlue Swirl "cleanwin: %d cwp: %d\n", 671ab3b491fSBlue Swirl env->cansave, env->canrestore, env->otherwin, env->wstate, 672ab3b491fSBlue Swirl env->cleanwin, env->nwindows - 1 - env->cwp); 67390c84c56SMarkus Armbruster qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: " 674ab3b491fSBlue Swirl TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs); 675cbc3a6a4SArtyom Tarasenko 676ab3b491fSBlue Swirl #else 67790c84c56SMarkus Armbruster qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env)); 67890c84c56SMarkus Armbruster cpu_print_cc(f, cpu_get_psr(env)); 67990c84c56SMarkus Armbruster qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-', 680ab3b491fSBlue Swirl env->psrps ? 'P' : '-', env->psret ? 'E' : '-', 681ab3b491fSBlue Swirl env->wim); 68290c84c56SMarkus Armbruster qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n", 683ab3b491fSBlue Swirl env->fsr, env->y); 684ab3b491fSBlue Swirl #endif 68590c84c56SMarkus Armbruster qemu_fprintf(f, "\n"); 686ab3b491fSBlue Swirl } 687ab7ab3d7SAndreas Färber 688f45748f1SAndreas Färber static void sparc_cpu_set_pc(CPUState *cs, vaddr value) 689f45748f1SAndreas Färber { 690f45748f1SAndreas Färber SPARCCPU *cpu = SPARC_CPU(cs); 691f45748f1SAndreas Färber 692f45748f1SAndreas Färber cpu->env.pc = value; 693f45748f1SAndreas Färber cpu->env.npc = value + 4; 694f45748f1SAndreas Färber } 695f45748f1SAndreas Färber 696e4fdf9dfSRichard Henderson static vaddr sparc_cpu_get_pc(CPUState *cs) 697e4fdf9dfSRichard Henderson { 698e4fdf9dfSRichard Henderson SPARCCPU *cpu = SPARC_CPU(cs); 699e4fdf9dfSRichard Henderson 700e4fdf9dfSRichard Henderson return cpu->env.pc; 701e4fdf9dfSRichard Henderson } 702e4fdf9dfSRichard Henderson 70304a37d4cSRichard Henderson static void sparc_cpu_synchronize_from_tb(CPUState *cs, 70404a37d4cSRichard Henderson const TranslationBlock *tb) 705bdf7ae5bSAndreas Färber { 706bdf7ae5bSAndreas Färber SPARCCPU *cpu = SPARC_CPU(cs); 707bdf7ae5bSAndreas Färber 708fbf59aadSRichard Henderson cpu->env.pc = tb_pc(tb); 709bdf7ae5bSAndreas Färber cpu->env.npc = tb->cs_base; 710bdf7ae5bSAndreas Färber } 711bdf7ae5bSAndreas Färber 7128c2e1b00SAndreas Färber static bool sparc_cpu_has_work(CPUState *cs) 7138c2e1b00SAndreas Färber { 7148c2e1b00SAndreas Färber SPARCCPU *cpu = SPARC_CPU(cs); 7158c2e1b00SAndreas Färber CPUSPARCState *env = &cpu->env; 7168c2e1b00SAndreas Färber 7178c2e1b00SAndreas Färber return (cs->interrupt_request & CPU_INTERRUPT_HARD) && 7188c2e1b00SAndreas Färber cpu_interrupts_enabled(env); 7198c2e1b00SAndreas Färber } 7208c2e1b00SAndreas Färber 72112a6c15eSIgor Mammedov static char *sparc_cpu_type_name(const char *cpu_model) 72212a6c15eSIgor Mammedov { 7231d4bfc54SIgor Mammedov char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model); 72412a6c15eSIgor Mammedov char *s = name; 72512a6c15eSIgor Mammedov 72612a6c15eSIgor Mammedov /* SPARC cpu model names happen to have whitespaces, 72712a6c15eSIgor Mammedov * as type names shouldn't have spaces replace them with '-' 72812a6c15eSIgor Mammedov */ 72912a6c15eSIgor Mammedov while ((s = strchr(s, ' '))) { 73012a6c15eSIgor Mammedov *s = '-'; 73112a6c15eSIgor Mammedov } 73212a6c15eSIgor Mammedov 73312a6c15eSIgor Mammedov return name; 73412a6c15eSIgor Mammedov } 73512a6c15eSIgor Mammedov 73612a6c15eSIgor Mammedov static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model) 73712a6c15eSIgor Mammedov { 73812a6c15eSIgor Mammedov ObjectClass *oc; 73912a6c15eSIgor Mammedov char *typename; 74012a6c15eSIgor Mammedov 74112a6c15eSIgor Mammedov typename = sparc_cpu_type_name(cpu_model); 74212a6c15eSIgor Mammedov oc = object_class_by_name(typename); 74312a6c15eSIgor Mammedov g_free(typename); 74412a6c15eSIgor Mammedov return oc; 74512a6c15eSIgor Mammedov } 74612a6c15eSIgor Mammedov 747b6e91ebfSAndreas Färber static void sparc_cpu_realizefn(DeviceState *dev, Error **errp) 748b6e91ebfSAndreas Färber { 749ce5b1bbfSLaurent Vivier CPUState *cs = CPU(dev); 750b6e91ebfSAndreas Färber SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev); 751ce5b1bbfSLaurent Vivier Error *local_err = NULL; 752247bf011SAndreas Färber SPARCCPU *cpu = SPARC_CPU(dev); 753247bf011SAndreas Färber CPUSPARCState *env = &cpu->env; 754247bf011SAndreas Färber 75570054962SIgor Mammedov #if defined(CONFIG_USER_ONLY) 756576e1c4cSIgor Mammedov if ((env->def.features & CPU_FEATURE_FLOAT)) { 757576e1c4cSIgor Mammedov env->def.features |= CPU_FEATURE_FLOAT128; 758247bf011SAndreas Färber } 759247bf011SAndreas Färber #endif 760b6e91ebfSAndreas Färber 76170054962SIgor Mammedov env->version = env->def.iu_version; 76270054962SIgor Mammedov env->fsr = env->def.fpu_version; 76370054962SIgor Mammedov env->nwindows = env->def.nwindows; 76470054962SIgor Mammedov #if !defined(TARGET_SPARC64) 76570054962SIgor Mammedov env->mmuregs[0] |= env->def.mmu_version; 76670054962SIgor Mammedov cpu_sparc_set_id(env, 0); 76770054962SIgor Mammedov env->mxccregs[7] |= env->def.mxcc_version; 76870054962SIgor Mammedov #else 76970054962SIgor Mammedov env->mmu_version = env->def.mmu_version; 77070054962SIgor Mammedov env->maxtl = env->def.maxtl; 77170054962SIgor Mammedov env->version |= env->def.maxtl << 8; 77270054962SIgor Mammedov env->version |= env->def.nwindows - 1; 77370054962SIgor Mammedov #endif 77470054962SIgor Mammedov 775ce5b1bbfSLaurent Vivier cpu_exec_realizefn(cs, &local_err); 776ce5b1bbfSLaurent Vivier if (local_err != NULL) { 777ce5b1bbfSLaurent Vivier error_propagate(errp, local_err); 778ce5b1bbfSLaurent Vivier return; 779ce5b1bbfSLaurent Vivier } 780ce5b1bbfSLaurent Vivier 781ce5b1bbfSLaurent Vivier qemu_init_vcpu(cs); 78214a10fc3SAndreas Färber 783b6e91ebfSAndreas Färber scc->parent_realize(dev, errp); 784b6e91ebfSAndreas Färber } 785b6e91ebfSAndreas Färber 786ab7ab3d7SAndreas Färber static void sparc_cpu_initfn(Object *obj) 787ab7ab3d7SAndreas Färber { 788ab7ab3d7SAndreas Färber SPARCCPU *cpu = SPARC_CPU(obj); 78912a6c15eSIgor Mammedov SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj); 790ab7ab3d7SAndreas Färber CPUSPARCState *env = &cpu->env; 791ab7ab3d7SAndreas Färber 7927506ed90SRichard Henderson cpu_set_cpustate_pointers(cpu); 7935266d20aSAndreas Färber 794576e1c4cSIgor Mammedov if (scc->cpu_def) { 795576e1c4cSIgor Mammedov env->def = *scc->cpu_def; 796ab7ab3d7SAndreas Färber } 797ab7ab3d7SAndreas Färber } 798ab7ab3d7SAndreas Färber 799de05005bSIgor Mammedov static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name, 800de05005bSIgor Mammedov void *opaque, Error **errp) 801de05005bSIgor Mammedov { 802de05005bSIgor Mammedov SPARCCPU *cpu = SPARC_CPU(obj); 803de05005bSIgor Mammedov int64_t value = cpu->env.def.nwindows; 804de05005bSIgor Mammedov 805de05005bSIgor Mammedov visit_type_int(v, name, &value, errp); 806de05005bSIgor Mammedov } 807de05005bSIgor Mammedov 808de05005bSIgor Mammedov static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name, 809de05005bSIgor Mammedov void *opaque, Error **errp) 810de05005bSIgor Mammedov { 811de05005bSIgor Mammedov const int64_t min = MIN_NWINDOWS; 812de05005bSIgor Mammedov const int64_t max = MAX_NWINDOWS; 813de05005bSIgor Mammedov SPARCCPU *cpu = SPARC_CPU(obj); 814de05005bSIgor Mammedov int64_t value; 815de05005bSIgor Mammedov 816668f62ecSMarkus Armbruster if (!visit_type_int(v, name, &value, errp)) { 817de05005bSIgor Mammedov return; 818de05005bSIgor Mammedov } 819de05005bSIgor Mammedov 820de05005bSIgor Mammedov if (value < min || value > max) { 821de05005bSIgor Mammedov error_setg(errp, "Property %s.%s doesn't take value %" PRId64 822de05005bSIgor Mammedov " (minimum: %" PRId64 ", maximum: %" PRId64 ")", 823de05005bSIgor Mammedov object_get_typename(obj), name ? name : "null", 824de05005bSIgor Mammedov value, min, max); 825de05005bSIgor Mammedov return; 826de05005bSIgor Mammedov } 827de05005bSIgor Mammedov cpu->env.def.nwindows = value; 828de05005bSIgor Mammedov } 829de05005bSIgor Mammedov 830de05005bSIgor Mammedov static PropertyInfo qdev_prop_nwindows = { 831de05005bSIgor Mammedov .name = "int", 832de05005bSIgor Mammedov .get = sparc_get_nwindows, 833de05005bSIgor Mammedov .set = sparc_set_nwindows, 834de05005bSIgor Mammedov }; 835de05005bSIgor Mammedov 836de05005bSIgor Mammedov static Property sparc_cpu_properties[] = { 837de05005bSIgor Mammedov DEFINE_PROP_BIT("float", SPARCCPU, env.def.features, 0, false), 838de05005bSIgor Mammedov DEFINE_PROP_BIT("float128", SPARCCPU, env.def.features, 1, false), 839de05005bSIgor Mammedov DEFINE_PROP_BIT("swap", SPARCCPU, env.def.features, 2, false), 840de05005bSIgor Mammedov DEFINE_PROP_BIT("mul", SPARCCPU, env.def.features, 3, false), 841de05005bSIgor Mammedov DEFINE_PROP_BIT("div", SPARCCPU, env.def.features, 4, false), 842de05005bSIgor Mammedov DEFINE_PROP_BIT("flush", SPARCCPU, env.def.features, 5, false), 843de05005bSIgor Mammedov DEFINE_PROP_BIT("fsqrt", SPARCCPU, env.def.features, 6, false), 844de05005bSIgor Mammedov DEFINE_PROP_BIT("fmul", SPARCCPU, env.def.features, 7, false), 845de05005bSIgor Mammedov DEFINE_PROP_BIT("vis1", SPARCCPU, env.def.features, 8, false), 846de05005bSIgor Mammedov DEFINE_PROP_BIT("vis2", SPARCCPU, env.def.features, 9, false), 847de05005bSIgor Mammedov DEFINE_PROP_BIT("fsmuld", SPARCCPU, env.def.features, 10, false), 848de05005bSIgor Mammedov DEFINE_PROP_BIT("hypv", SPARCCPU, env.def.features, 11, false), 849de05005bSIgor Mammedov DEFINE_PROP_BIT("cmt", SPARCCPU, env.def.features, 12, false), 850de05005bSIgor Mammedov DEFINE_PROP_BIT("gl", SPARCCPU, env.def.features, 13, false), 851de05005bSIgor Mammedov DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU, env.def.iu_version, 0, 852de05005bSIgor Mammedov qdev_prop_uint64, target_ulong), 853de05005bSIgor Mammedov DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0), 854de05005bSIgor Mammedov DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0), 85543b6ab4cSEduardo Habkost DEFINE_PROP("nwindows", SPARCCPU, env.def.nwindows, 85643b6ab4cSEduardo Habkost qdev_prop_nwindows, uint32_t), 857de05005bSIgor Mammedov DEFINE_PROP_END_OF_LIST() 858de05005bSIgor Mammedov }; 859de05005bSIgor Mammedov 8608b80bd28SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY 8618b80bd28SPhilippe Mathieu-Daudé #include "hw/core/sysemu-cpu-ops.h" 8628b80bd28SPhilippe Mathieu-Daudé 8638b80bd28SPhilippe Mathieu-Daudé static const struct SysemuCPUOps sparc_sysemu_ops = { 86408928c6dSPhilippe Mathieu-Daudé .get_phys_page_debug = sparc_cpu_get_phys_page_debug, 865feece4d0SPhilippe Mathieu-Daudé .legacy_vmsd = &vmstate_sparc_cpu, 8668b80bd28SPhilippe Mathieu-Daudé }; 8678b80bd28SPhilippe Mathieu-Daudé #endif 8688b80bd28SPhilippe Mathieu-Daudé 86978271684SClaudio Fontana #ifdef CONFIG_TCG 87078271684SClaudio Fontana #include "hw/core/tcg-cpu-ops.h" 87178271684SClaudio Fontana 87211906557SRichard Henderson static const struct TCGCPUOps sparc_tcg_ops = { 87378271684SClaudio Fontana .initialize = sparc_tcg_init, 87478271684SClaudio Fontana .synchronize_from_tb = sparc_cpu_synchronize_from_tb, 875*f36aaa53SRichard Henderson .restore_state_to_opc = sparc_restore_state_to_opc, 87678271684SClaudio Fontana 87778271684SClaudio Fontana #ifndef CONFIG_USER_ONLY 878caac44a5SRichard Henderson .tlb_fill = sparc_cpu_tlb_fill, 879798ac8b5SPhilippe Mathieu-Daudé .cpu_exec_interrupt = sparc_cpu_exec_interrupt, 88078271684SClaudio Fontana .do_interrupt = sparc_cpu_do_interrupt, 88178271684SClaudio Fontana .do_transaction_failed = sparc_cpu_do_transaction_failed, 88278271684SClaudio Fontana .do_unaligned_access = sparc_cpu_do_unaligned_access, 88378271684SClaudio Fontana #endif /* !CONFIG_USER_ONLY */ 88478271684SClaudio Fontana }; 88578271684SClaudio Fontana #endif /* CONFIG_TCG */ 88678271684SClaudio Fontana 887ab7ab3d7SAndreas Färber static void sparc_cpu_class_init(ObjectClass *oc, void *data) 888ab7ab3d7SAndreas Färber { 889ab7ab3d7SAndreas Färber SPARCCPUClass *scc = SPARC_CPU_CLASS(oc); 890ab7ab3d7SAndreas Färber CPUClass *cc = CPU_CLASS(oc); 891b6e91ebfSAndreas Färber DeviceClass *dc = DEVICE_CLASS(oc); 892b6e91ebfSAndreas Färber 893bf853881SPhilippe Mathieu-Daudé device_class_set_parent_realize(dc, sparc_cpu_realizefn, 894bf853881SPhilippe Mathieu-Daudé &scc->parent_realize); 8954f67d30bSMarc-André Lureau device_class_set_props(dc, sparc_cpu_properties); 896ab7ab3d7SAndreas Färber 897781c67caSPeter Maydell device_class_set_parent_reset(dc, sparc_cpu_reset, &scc->parent_reset); 89897a8ea5aSAndreas Färber 89912a6c15eSIgor Mammedov cc->class_by_name = sparc_cpu_class_by_name; 900d1853231SIgor Mammedov cc->parse_features = sparc_cpu_parse_features; 9018c2e1b00SAndreas Färber cc->has_work = sparc_cpu_has_work; 902878096eeSAndreas Färber cc->dump_state = sparc_cpu_dump_state; 903f3659eeeSAndreas Färber #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) 904f3659eeeSAndreas Färber cc->memory_rw_debug = sparc_cpu_memory_rw_debug; 905f3659eeeSAndreas Färber #endif 906f45748f1SAndreas Färber cc->set_pc = sparc_cpu_set_pc; 907e4fdf9dfSRichard Henderson cc->get_pc = sparc_cpu_get_pc; 9085b50e790SAndreas Färber cc->gdb_read_register = sparc_cpu_gdb_read_register; 9095b50e790SAndreas Färber cc->gdb_write_register = sparc_cpu_gdb_write_register; 910e84942f2SRichard Henderson #ifndef CONFIG_USER_ONLY 9118b80bd28SPhilippe Mathieu-Daudé cc->sysemu_ops = &sparc_sysemu_ops; 91200b941e5SAndreas Färber #endif 913df0900ebSPeter Crosthwaite cc->disas_set_info = cpu_sparc_disas_set_info; 914a0e372f0SAndreas Färber 915a0e372f0SAndreas Färber #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) 916a0e372f0SAndreas Färber cc->gdb_num_core_regs = 86; 917a0e372f0SAndreas Färber #else 918a0e372f0SAndreas Färber cc->gdb_num_core_regs = 72; 919a0e372f0SAndreas Färber #endif 92078271684SClaudio Fontana cc->tcg_ops = &sparc_tcg_ops; 921ab7ab3d7SAndreas Färber } 922ab7ab3d7SAndreas Färber 923ab7ab3d7SAndreas Färber static const TypeInfo sparc_cpu_type_info = { 924ab7ab3d7SAndreas Färber .name = TYPE_SPARC_CPU, 925ab7ab3d7SAndreas Färber .parent = TYPE_CPU, 926ab7ab3d7SAndreas Färber .instance_size = sizeof(SPARCCPU), 927ab7ab3d7SAndreas Färber .instance_init = sparc_cpu_initfn, 92812a6c15eSIgor Mammedov .abstract = true, 929ab7ab3d7SAndreas Färber .class_size = sizeof(SPARCCPUClass), 930ab7ab3d7SAndreas Färber .class_init = sparc_cpu_class_init, 931ab7ab3d7SAndreas Färber }; 932ab7ab3d7SAndreas Färber 93312a6c15eSIgor Mammedov static void sparc_cpu_cpudef_class_init(ObjectClass *oc, void *data) 93412a6c15eSIgor Mammedov { 93512a6c15eSIgor Mammedov SPARCCPUClass *scc = SPARC_CPU_CLASS(oc); 93612a6c15eSIgor Mammedov scc->cpu_def = data; 93712a6c15eSIgor Mammedov } 93812a6c15eSIgor Mammedov 93912a6c15eSIgor Mammedov static void sparc_register_cpudef_type(const struct sparc_def_t *def) 94012a6c15eSIgor Mammedov { 94112a6c15eSIgor Mammedov char *typename = sparc_cpu_type_name(def->name); 94212a6c15eSIgor Mammedov TypeInfo ti = { 94312a6c15eSIgor Mammedov .name = typename, 94412a6c15eSIgor Mammedov .parent = TYPE_SPARC_CPU, 94512a6c15eSIgor Mammedov .class_init = sparc_cpu_cpudef_class_init, 94612a6c15eSIgor Mammedov .class_data = (void *)def, 94712a6c15eSIgor Mammedov }; 94812a6c15eSIgor Mammedov 94912a6c15eSIgor Mammedov type_register(&ti); 95012a6c15eSIgor Mammedov g_free(typename); 95112a6c15eSIgor Mammedov } 95212a6c15eSIgor Mammedov 953ab7ab3d7SAndreas Färber static void sparc_cpu_register_types(void) 954ab7ab3d7SAndreas Färber { 95512a6c15eSIgor Mammedov int i; 95612a6c15eSIgor Mammedov 957ab7ab3d7SAndreas Färber type_register_static(&sparc_cpu_type_info); 95812a6c15eSIgor Mammedov for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) { 95912a6c15eSIgor Mammedov sparc_register_cpudef_type(&sparc_defs[i]); 96012a6c15eSIgor Mammedov } 961ab7ab3d7SAndreas Färber } 962ab7ab3d7SAndreas Färber 963ab7ab3d7SAndreas Färber type_init(sparc_cpu_register_types) 964