cpu.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. /*
  2. * Sparc CPU init helpers
  3. *
  4. * Copyright (c) 2003-2005 Fabrice Bellard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "qemu/osdep.h"
  20. #include "qapi/error.h"
  21. #include "cpu.h"
  22. #include "qemu/module.h"
  23. #include "qemu/qemu-print.h"
  24. #include "exec/exec-all.h"
  25. #include "exec/translation-block.h"
  26. #include "hw/qdev-properties.h"
  27. #include "qapi/visitor.h"
  28. #include "tcg/tcg.h"
  29. #include "fpu/softfloat.h"
  30. #include "target/sparc/translate.h"
  31. //#define DEBUG_FEATURES
  32. static void sparc_cpu_reset_hold(Object *obj, ResetType type)
  33. {
  34. CPUState *cs = CPU(obj);
  35. SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
  36. CPUSPARCState *env = cpu_env(cs);
  37. if (scc->parent_phases.hold) {
  38. scc->parent_phases.hold(obj, type);
  39. }
  40. memset(env, 0, offsetof(CPUSPARCState, end_reset_fields));
  41. env->cwp = 0;
  42. #ifndef TARGET_SPARC64
  43. env->wim = 1;
  44. #endif
  45. env->regwptr = env->regbase + (env->cwp * 16);
  46. #if defined(CONFIG_USER_ONLY)
  47. #ifdef TARGET_SPARC64
  48. env->cleanwin = env->nwindows - 2;
  49. env->cansave = env->nwindows - 2;
  50. env->pstate = PS_RMO | PS_PEF | PS_IE;
  51. env->asi = 0x82; /* Primary no-fault */
  52. #endif
  53. #else
  54. #if !defined(TARGET_SPARC64)
  55. env->psret = 0;
  56. env->psrs = 1;
  57. env->psrps = 1;
  58. #endif
  59. #ifdef TARGET_SPARC64
  60. env->pstate = PS_PRIV | PS_RED | PS_PEF;
  61. if (!cpu_has_hypervisor(env)) {
  62. env->pstate |= PS_AG;
  63. }
  64. env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0;
  65. env->tl = env->maxtl;
  66. env->gl = 2;
  67. cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
  68. env->lsu = 0;
  69. #else
  70. env->mmuregs[0] &= ~(MMU_E | MMU_NF);
  71. env->mmuregs[0] |= env->def.mmu_bm;
  72. #endif
  73. env->pc = 0;
  74. env->npc = env->pc + 4;
  75. #endif
  76. env->cache_control = 0;
  77. cpu_put_fsr(env, 0);
  78. }
  79. #ifndef CONFIG_USER_ONLY
  80. static bool sparc_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
  81. {
  82. if (interrupt_request & CPU_INTERRUPT_HARD) {
  83. CPUSPARCState *env = cpu_env(cs);
  84. if (cpu_interrupts_enabled(env) && env->interrupt_index > 0) {
  85. int pil = env->interrupt_index & 0xf;
  86. int type = env->interrupt_index & 0xf0;
  87. if (type != TT_EXTINT || cpu_pil_allowed(env, pil)) {
  88. cs->exception_index = env->interrupt_index;
  89. sparc_cpu_do_interrupt(cs);
  90. return true;
  91. }
  92. }
  93. }
  94. return false;
  95. }
  96. #endif /* !CONFIG_USER_ONLY */
  97. static void cpu_sparc_disas_set_info(CPUState *cpu, disassemble_info *info)
  98. {
  99. info->print_insn = print_insn_sparc;
  100. info->endian = BFD_ENDIAN_BIG;
  101. #ifdef TARGET_SPARC64
  102. info->mach = bfd_mach_sparc_v9b;
  103. #endif
  104. }
  105. static void
  106. cpu_add_feat_as_prop(const char *typename, const char *name, const char *val)
  107. {
  108. GlobalProperty *prop = g_new0(typeof(*prop), 1);
  109. prop->driver = typename;
  110. prop->property = g_strdup(name);
  111. prop->value = g_strdup(val);
  112. qdev_prop_register_global(prop);
  113. }
  114. /* Parse "+feature,-feature,feature=foo" CPU feature string */
  115. static void sparc_cpu_parse_features(const char *typename, char *features,
  116. Error **errp)
  117. {
  118. GList *l, *plus_features = NULL, *minus_features = NULL;
  119. char *featurestr; /* Single 'key=value" string being parsed */
  120. static bool cpu_globals_initialized;
  121. if (cpu_globals_initialized) {
  122. return;
  123. }
  124. cpu_globals_initialized = true;
  125. if (!features) {
  126. return;
  127. }
  128. for (featurestr = strtok(features, ",");
  129. featurestr;
  130. featurestr = strtok(NULL, ",")) {
  131. const char *name;
  132. const char *val = NULL;
  133. char *eq = NULL;
  134. /* Compatibility syntax: */
  135. if (featurestr[0] == '+') {
  136. plus_features = g_list_append(plus_features,
  137. g_strdup(featurestr + 1));
  138. continue;
  139. } else if (featurestr[0] == '-') {
  140. minus_features = g_list_append(minus_features,
  141. g_strdup(featurestr + 1));
  142. continue;
  143. }
  144. eq = strchr(featurestr, '=');
  145. name = featurestr;
  146. if (eq) {
  147. *eq++ = 0;
  148. val = eq;
  149. /*
  150. * Temporarily, only +feat/-feat will be supported
  151. * for boolean properties until we remove the
  152. * minus-overrides-plus semantics and just follow
  153. * the order options appear on the command-line.
  154. *
  155. * TODO: warn if user is relying on minus-override-plus semantics
  156. * TODO: remove minus-override-plus semantics after
  157. * warning for a few releases
  158. */
  159. if (!strcasecmp(val, "on") ||
  160. !strcasecmp(val, "off") ||
  161. !strcasecmp(val, "true") ||
  162. !strcasecmp(val, "false")) {
  163. error_setg(errp, "Boolean properties in format %s=%s"
  164. " are not supported", name, val);
  165. return;
  166. }
  167. } else {
  168. error_setg(errp, "Unsupported property format: %s", name);
  169. return;
  170. }
  171. cpu_add_feat_as_prop(typename, name, val);
  172. }
  173. for (l = plus_features; l; l = l->next) {
  174. const char *name = l->data;
  175. cpu_add_feat_as_prop(typename, name, "on");
  176. }
  177. g_list_free_full(plus_features, g_free);
  178. for (l = minus_features; l; l = l->next) {
  179. const char *name = l->data;
  180. cpu_add_feat_as_prop(typename, name, "off");
  181. }
  182. g_list_free_full(minus_features, g_free);
  183. }
  184. void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
  185. {
  186. #if !defined(TARGET_SPARC64)
  187. env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
  188. #endif
  189. }
  190. static const sparc_def_t sparc_defs[] = {
  191. #ifdef TARGET_SPARC64
  192. {
  193. .name = "Fujitsu-Sparc64",
  194. .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
  195. .fpu_version = 0x00000000,
  196. .mmu_version = mmu_us_12,
  197. .nwindows = 4,
  198. .maxtl = 4,
  199. .features = CPU_DEFAULT_FEATURES,
  200. },
  201. {
  202. .name = "Fujitsu-Sparc64-III",
  203. .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
  204. .fpu_version = 0x00000000,
  205. .mmu_version = mmu_us_12,
  206. .nwindows = 5,
  207. .maxtl = 4,
  208. .features = CPU_DEFAULT_FEATURES,
  209. },
  210. {
  211. .name = "Fujitsu-Sparc64-IV",
  212. .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
  213. .fpu_version = 0x00000000,
  214. .mmu_version = mmu_us_12,
  215. .nwindows = 8,
  216. .maxtl = 5,
  217. .features = CPU_DEFAULT_FEATURES,
  218. },
  219. {
  220. .name = "Fujitsu-Sparc64-V",
  221. .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
  222. .fpu_version = 0x00000000,
  223. .mmu_version = mmu_us_12,
  224. .nwindows = 8,
  225. .maxtl = 5,
  226. .features = CPU_DEFAULT_FEATURES,
  227. },
  228. {
  229. .name = "TI-UltraSparc-I",
  230. .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
  231. .fpu_version = 0x00000000,
  232. .mmu_version = mmu_us_12,
  233. .nwindows = 8,
  234. .maxtl = 5,
  235. .features = CPU_DEFAULT_FEATURES,
  236. },
  237. {
  238. .name = "TI-UltraSparc-II",
  239. .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
  240. .fpu_version = 0x00000000,
  241. .mmu_version = mmu_us_12,
  242. .nwindows = 8,
  243. .maxtl = 5,
  244. .features = CPU_DEFAULT_FEATURES,
  245. },
  246. {
  247. .name = "TI-UltraSparc-IIi",
  248. .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
  249. .fpu_version = 0x00000000,
  250. .mmu_version = mmu_us_12,
  251. .nwindows = 8,
  252. .maxtl = 5,
  253. .features = CPU_DEFAULT_FEATURES,
  254. },
  255. {
  256. .name = "TI-UltraSparc-IIe",
  257. .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
  258. .fpu_version = 0x00000000,
  259. .mmu_version = mmu_us_12,
  260. .nwindows = 8,
  261. .maxtl = 5,
  262. .features = CPU_DEFAULT_FEATURES,
  263. },
  264. {
  265. .name = "Sun-UltraSparc-III",
  266. .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
  267. .fpu_version = 0x00000000,
  268. .mmu_version = mmu_us_12,
  269. .nwindows = 8,
  270. .maxtl = 5,
  271. .features = CPU_DEFAULT_FEATURES,
  272. },
  273. {
  274. .name = "Sun-UltraSparc-III-Cu",
  275. .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
  276. .fpu_version = 0x00000000,
  277. .mmu_version = mmu_us_3,
  278. .nwindows = 8,
  279. .maxtl = 5,
  280. .features = CPU_DEFAULT_FEATURES,
  281. },
  282. {
  283. .name = "Sun-UltraSparc-IIIi",
  284. .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
  285. .fpu_version = 0x00000000,
  286. .mmu_version = mmu_us_12,
  287. .nwindows = 8,
  288. .maxtl = 5,
  289. .features = CPU_DEFAULT_FEATURES,
  290. },
  291. {
  292. .name = "Sun-UltraSparc-IV",
  293. .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
  294. .fpu_version = 0x00000000,
  295. .mmu_version = mmu_us_4,
  296. .nwindows = 8,
  297. .maxtl = 5,
  298. .features = CPU_DEFAULT_FEATURES,
  299. },
  300. {
  301. .name = "Sun-UltraSparc-IV-plus",
  302. .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
  303. .fpu_version = 0x00000000,
  304. .mmu_version = mmu_us_12,
  305. .nwindows = 8,
  306. .maxtl = 5,
  307. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
  308. },
  309. {
  310. .name = "Sun-UltraSparc-IIIi-plus",
  311. .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
  312. .fpu_version = 0x00000000,
  313. .mmu_version = mmu_us_3,
  314. .nwindows = 8,
  315. .maxtl = 5,
  316. .features = CPU_DEFAULT_FEATURES,
  317. },
  318. {
  319. .name = "Sun-UltraSparc-T1",
  320. /* defined in sparc_ifu_fdp.v and ctu.h */
  321. .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
  322. .fpu_version = 0x00000000,
  323. .mmu_version = mmu_sun4v,
  324. .nwindows = 8,
  325. .maxtl = 6,
  326. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
  327. | CPU_FEATURE_GL,
  328. },
  329. {
  330. .name = "Sun-UltraSparc-T2",
  331. /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
  332. .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
  333. .fpu_version = 0x00000000,
  334. .mmu_version = mmu_sun4v,
  335. .nwindows = 8,
  336. .maxtl = 6,
  337. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
  338. | CPU_FEATURE_GL,
  339. },
  340. {
  341. .name = "NEC-UltraSparc-I",
  342. .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
  343. .fpu_version = 0x00000000,
  344. .mmu_version = mmu_us_12,
  345. .nwindows = 8,
  346. .maxtl = 5,
  347. .features = CPU_DEFAULT_FEATURES,
  348. },
  349. #else
  350. {
  351. .name = "Fujitsu-MB86904",
  352. .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
  353. .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
  354. .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
  355. .mmu_bm = 0x00004000,
  356. .mmu_ctpr_mask = 0x00ffffc0,
  357. .mmu_cxr_mask = 0x000000ff,
  358. .mmu_sfsr_mask = 0x00016fff,
  359. .mmu_trcr_mask = 0x00ffffff,
  360. .nwindows = 8,
  361. .features = CPU_DEFAULT_FEATURES,
  362. },
  363. {
  364. .name = "Fujitsu-MB86907",
  365. .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
  366. .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
  367. .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
  368. .mmu_bm = 0x00004000,
  369. .mmu_ctpr_mask = 0xffffffc0,
  370. .mmu_cxr_mask = 0x000000ff,
  371. .mmu_sfsr_mask = 0x00016fff,
  372. .mmu_trcr_mask = 0xffffffff,
  373. .nwindows = 8,
  374. .features = CPU_DEFAULT_FEATURES,
  375. },
  376. {
  377. .name = "TI-MicroSparc-I",
  378. .iu_version = 0x41000000,
  379. .fpu_version = 4 << FSR_VER_SHIFT,
  380. .mmu_version = 0x41000000,
  381. .mmu_bm = 0x00004000,
  382. .mmu_ctpr_mask = 0x007ffff0,
  383. .mmu_cxr_mask = 0x0000003f,
  384. .mmu_sfsr_mask = 0x00016fff,
  385. .mmu_trcr_mask = 0x0000003f,
  386. .nwindows = 7,
  387. .features = CPU_FEATURE_MUL | CPU_FEATURE_DIV,
  388. },
  389. {
  390. .name = "TI-MicroSparc-II",
  391. .iu_version = 0x42000000,
  392. .fpu_version = 4 << FSR_VER_SHIFT,
  393. .mmu_version = 0x02000000,
  394. .mmu_bm = 0x00004000,
  395. .mmu_ctpr_mask = 0x00ffffc0,
  396. .mmu_cxr_mask = 0x000000ff,
  397. .mmu_sfsr_mask = 0x00016fff,
  398. .mmu_trcr_mask = 0x00ffffff,
  399. .nwindows = 8,
  400. .features = CPU_DEFAULT_FEATURES,
  401. },
  402. {
  403. .name = "TI-MicroSparc-IIep",
  404. .iu_version = 0x42000000,
  405. .fpu_version = 4 << FSR_VER_SHIFT,
  406. .mmu_version = 0x04000000,
  407. .mmu_bm = 0x00004000,
  408. .mmu_ctpr_mask = 0x00ffffc0,
  409. .mmu_cxr_mask = 0x000000ff,
  410. .mmu_sfsr_mask = 0x00016bff,
  411. .mmu_trcr_mask = 0x00ffffff,
  412. .nwindows = 8,
  413. .features = CPU_DEFAULT_FEATURES,
  414. },
  415. {
  416. .name = "TI-SuperSparc-40", /* STP1020NPGA */
  417. .iu_version = 0x41000000, /* SuperSPARC 2.x */
  418. .fpu_version = 0 << FSR_VER_SHIFT,
  419. .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */
  420. .mmu_bm = 0x00002000,
  421. .mmu_ctpr_mask = 0xffffffc0,
  422. .mmu_cxr_mask = 0x0000ffff,
  423. .mmu_sfsr_mask = 0xffffffff,
  424. .mmu_trcr_mask = 0xffffffff,
  425. .nwindows = 8,
  426. .features = CPU_DEFAULT_FEATURES,
  427. },
  428. {
  429. .name = "TI-SuperSparc-50", /* STP1020PGA */
  430. .iu_version = 0x40000000, /* SuperSPARC 3.x */
  431. .fpu_version = 0 << FSR_VER_SHIFT,
  432. .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
  433. .mmu_bm = 0x00002000,
  434. .mmu_ctpr_mask = 0xffffffc0,
  435. .mmu_cxr_mask = 0x0000ffff,
  436. .mmu_sfsr_mask = 0xffffffff,
  437. .mmu_trcr_mask = 0xffffffff,
  438. .nwindows = 8,
  439. .features = CPU_DEFAULT_FEATURES,
  440. },
  441. {
  442. .name = "TI-SuperSparc-51",
  443. .iu_version = 0x40000000, /* SuperSPARC 3.x */
  444. .fpu_version = 0 << FSR_VER_SHIFT,
  445. .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
  446. .mmu_bm = 0x00002000,
  447. .mmu_ctpr_mask = 0xffffffc0,
  448. .mmu_cxr_mask = 0x0000ffff,
  449. .mmu_sfsr_mask = 0xffffffff,
  450. .mmu_trcr_mask = 0xffffffff,
  451. .mxcc_version = 0x00000104,
  452. .nwindows = 8,
  453. .features = CPU_DEFAULT_FEATURES,
  454. },
  455. {
  456. .name = "TI-SuperSparc-60", /* STP1020APGA */
  457. .iu_version = 0x40000000, /* SuperSPARC 3.x */
  458. .fpu_version = 0 << FSR_VER_SHIFT,
  459. .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
  460. .mmu_bm = 0x00002000,
  461. .mmu_ctpr_mask = 0xffffffc0,
  462. .mmu_cxr_mask = 0x0000ffff,
  463. .mmu_sfsr_mask = 0xffffffff,
  464. .mmu_trcr_mask = 0xffffffff,
  465. .nwindows = 8,
  466. .features = CPU_DEFAULT_FEATURES,
  467. },
  468. {
  469. .name = "TI-SuperSparc-61",
  470. .iu_version = 0x44000000, /* SuperSPARC 3.x */
  471. .fpu_version = 0 << FSR_VER_SHIFT,
  472. .mmu_version = 0x01000000, /* SuperSPARC 3.x, MXCC */
  473. .mmu_bm = 0x00002000,
  474. .mmu_ctpr_mask = 0xffffffc0,
  475. .mmu_cxr_mask = 0x0000ffff,
  476. .mmu_sfsr_mask = 0xffffffff,
  477. .mmu_trcr_mask = 0xffffffff,
  478. .mxcc_version = 0x00000104,
  479. .nwindows = 8,
  480. .features = CPU_DEFAULT_FEATURES,
  481. },
  482. {
  483. .name = "TI-SuperSparc-II",
  484. .iu_version = 0x40000000, /* SuperSPARC II 1.x */
  485. .fpu_version = 0 << FSR_VER_SHIFT,
  486. .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */
  487. .mmu_bm = 0x00002000,
  488. .mmu_ctpr_mask = 0xffffffc0,
  489. .mmu_cxr_mask = 0x0000ffff,
  490. .mmu_sfsr_mask = 0xffffffff,
  491. .mmu_trcr_mask = 0xffffffff,
  492. .mxcc_version = 0x00000104,
  493. .nwindows = 8,
  494. .features = CPU_DEFAULT_FEATURES,
  495. },
  496. {
  497. .name = "LEON2",
  498. .iu_version = 0xf2000000,
  499. .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
  500. .mmu_version = 0xf2000000,
  501. .mmu_bm = 0x00004000,
  502. .mmu_ctpr_mask = 0x007ffff0,
  503. .mmu_cxr_mask = 0x0000003f,
  504. .mmu_sfsr_mask = 0xffffffff,
  505. .mmu_trcr_mask = 0xffffffff,
  506. .nwindows = 8,
  507. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
  508. },
  509. {
  510. .name = "LEON3",
  511. .iu_version = 0xf3000000,
  512. .fpu_version = 4 << FSR_VER_SHIFT, /* FPU version 4 (Meiko) */
  513. .mmu_version = 0xf3000000,
  514. .mmu_bm = 0x00000000,
  515. .mmu_ctpr_mask = 0xfffffffc,
  516. .mmu_cxr_mask = 0x000000ff,
  517. .mmu_sfsr_mask = 0xffffffff,
  518. .mmu_trcr_mask = 0xffffffff,
  519. .nwindows = 8,
  520. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
  521. CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL | CPU_FEATURE_POWERDOWN |
  522. CPU_FEATURE_CASA,
  523. },
  524. #endif
  525. };
  526. /* This must match sparc_cpu_properties[]. */
  527. static const char * const feature_name[] = {
  528. [CPU_FEATURE_BIT_FLOAT128] = "float128",
  529. #ifdef TARGET_SPARC64
  530. [CPU_FEATURE_BIT_CMT] = "cmt",
  531. [CPU_FEATURE_BIT_GL] = "gl",
  532. [CPU_FEATURE_BIT_HYPV] = "hypv",
  533. [CPU_FEATURE_BIT_VIS1] = "vis1",
  534. [CPU_FEATURE_BIT_VIS2] = "vis2",
  535. [CPU_FEATURE_BIT_FMAF] = "fmaf",
  536. [CPU_FEATURE_BIT_VIS3] = "vis3",
  537. [CPU_FEATURE_BIT_IMA] = "ima",
  538. [CPU_FEATURE_BIT_VIS4] = "vis4",
  539. #else
  540. [CPU_FEATURE_BIT_MUL] = "mul",
  541. [CPU_FEATURE_BIT_DIV] = "div",
  542. [CPU_FEATURE_BIT_FSMULD] = "fsmuld",
  543. #endif
  544. };
  545. static void print_features(uint32_t features, const char *prefix)
  546. {
  547. unsigned int i;
  548. for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
  549. if (feature_name[i] && (features & (1 << i))) {
  550. if (prefix) {
  551. qemu_printf("%s", prefix);
  552. }
  553. qemu_printf("%s ", feature_name[i]);
  554. }
  555. }
  556. }
  557. void sparc_cpu_list(void)
  558. {
  559. unsigned int i;
  560. qemu_printf("Available CPU types:\n");
  561. for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
  562. qemu_printf(" %-20s (IU " TARGET_FMT_lx
  563. " FPU %08x MMU %08x NWINS %d) ",
  564. sparc_defs[i].name,
  565. sparc_defs[i].iu_version,
  566. sparc_defs[i].fpu_version,
  567. sparc_defs[i].mmu_version,
  568. sparc_defs[i].nwindows);
  569. print_features(CPU_DEFAULT_FEATURES & ~sparc_defs[i].features, "-");
  570. print_features(~CPU_DEFAULT_FEATURES & sparc_defs[i].features, "+");
  571. qemu_printf("\n");
  572. }
  573. qemu_printf("Default CPU feature flags (use '-' to remove): ");
  574. print_features(CPU_DEFAULT_FEATURES, NULL);
  575. qemu_printf("\n");
  576. qemu_printf("Available CPU feature flags (use '+' to add): ");
  577. print_features(~CPU_DEFAULT_FEATURES, NULL);
  578. qemu_printf("\n");
  579. qemu_printf("Numerical features (use '=' to set): iu_version "
  580. "fpu_version mmu_version nwindows\n");
  581. }
  582. static void cpu_print_cc(FILE *f, uint32_t cc)
  583. {
  584. qemu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
  585. cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
  586. cc & PSR_CARRY ? 'C' : '-');
  587. }
  588. #ifdef TARGET_SPARC64
  589. #define REGS_PER_LINE 4
  590. #else
  591. #define REGS_PER_LINE 8
  592. #endif
  593. static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
  594. {
  595. CPUSPARCState *env = cpu_env(cs);
  596. int i, x;
  597. qemu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc,
  598. env->npc);
  599. for (i = 0; i < 8; i++) {
  600. if (i % REGS_PER_LINE == 0) {
  601. qemu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
  602. }
  603. qemu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
  604. if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
  605. qemu_fprintf(f, "\n");
  606. }
  607. }
  608. for (x = 0; x < 3; x++) {
  609. for (i = 0; i < 8; i++) {
  610. if (i % REGS_PER_LINE == 0) {
  611. qemu_fprintf(f, "%%%c%d-%d: ",
  612. x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
  613. i, i + REGS_PER_LINE - 1);
  614. }
  615. qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
  616. if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
  617. qemu_fprintf(f, "\n");
  618. }
  619. }
  620. }
  621. if (flags & CPU_DUMP_FPU) {
  622. for (i = 0; i < TARGET_DPREGS; i++) {
  623. if ((i & 3) == 0) {
  624. qemu_fprintf(f, "%%f%02d: ", i * 2);
  625. }
  626. qemu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
  627. if ((i & 3) == 3) {
  628. qemu_fprintf(f, "\n");
  629. }
  630. }
  631. }
  632. #ifdef TARGET_SPARC64
  633. qemu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
  634. (unsigned)cpu_get_ccr(env));
  635. cpu_print_cc(f, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
  636. qemu_fprintf(f, " xcc: ");
  637. cpu_print_cc(f, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
  638. qemu_fprintf(f, ") asi: %02x tl: %d pil: %x gl: %d\n", env->asi, env->tl,
  639. env->psrpil, env->gl);
  640. qemu_fprintf(f, "tbr: " TARGET_FMT_lx " hpstate: " TARGET_FMT_lx " htba: "
  641. TARGET_FMT_lx "\n", env->tbr, env->hpstate, env->htba);
  642. qemu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
  643. "cleanwin: %d cwp: %d\n",
  644. env->cansave, env->canrestore, env->otherwin, env->wstate,
  645. env->cleanwin, env->nwindows - 1 - env->cwp);
  646. qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: %016x\n",
  647. cpu_get_fsr(env), env->y, env->fprs);
  648. #else
  649. qemu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
  650. cpu_print_cc(f, cpu_get_psr(env));
  651. qemu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
  652. env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
  653. env->wim);
  654. qemu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
  655. cpu_get_fsr(env), env->y);
  656. #endif
  657. qemu_fprintf(f, "\n");
  658. }
  659. static void sparc_cpu_set_pc(CPUState *cs, vaddr value)
  660. {
  661. SPARCCPU *cpu = SPARC_CPU(cs);
  662. cpu->env.pc = value;
  663. cpu->env.npc = value + 4;
  664. }
  665. static vaddr sparc_cpu_get_pc(CPUState *cs)
  666. {
  667. SPARCCPU *cpu = SPARC_CPU(cs);
  668. return cpu->env.pc;
  669. }
  670. static void sparc_cpu_synchronize_from_tb(CPUState *cs,
  671. const TranslationBlock *tb)
  672. {
  673. SPARCCPU *cpu = SPARC_CPU(cs);
  674. tcg_debug_assert(!tcg_cflags_has(cs, CF_PCREL));
  675. cpu->env.pc = tb->pc;
  676. cpu->env.npc = tb->cs_base;
  677. }
  678. void cpu_get_tb_cpu_state(CPUSPARCState *env, vaddr *pc,
  679. uint64_t *cs_base, uint32_t *pflags)
  680. {
  681. uint32_t flags;
  682. *pc = env->pc;
  683. *cs_base = env->npc;
  684. flags = cpu_mmu_index(env_cpu(env), false);
  685. #ifndef CONFIG_USER_ONLY
  686. if (cpu_supervisor_mode(env)) {
  687. flags |= TB_FLAG_SUPER;
  688. }
  689. #endif
  690. #ifdef TARGET_SPARC64
  691. #ifndef CONFIG_USER_ONLY
  692. if (cpu_hypervisor_mode(env)) {
  693. flags |= TB_FLAG_HYPER;
  694. }
  695. #endif
  696. if (env->pstate & PS_AM) {
  697. flags |= TB_FLAG_AM_ENABLED;
  698. }
  699. if ((env->pstate & PS_PEF) && (env->fprs & FPRS_FEF)) {
  700. flags |= TB_FLAG_FPU_ENABLED;
  701. }
  702. flags |= env->asi << TB_FLAG_ASI_SHIFT;
  703. #else
  704. if (env->psref) {
  705. flags |= TB_FLAG_FPU_ENABLED;
  706. }
  707. #ifndef CONFIG_USER_ONLY
  708. if (env->fsr_qne) {
  709. flags |= TB_FLAG_FSR_QNE;
  710. }
  711. #endif /* !CONFIG_USER_ONLY */
  712. #endif /* TARGET_SPARC64 */
  713. *pflags = flags;
  714. }
  715. static void sparc_restore_state_to_opc(CPUState *cs,
  716. const TranslationBlock *tb,
  717. const uint64_t *data)
  718. {
  719. CPUSPARCState *env = cpu_env(cs);
  720. target_ulong pc = data[0];
  721. target_ulong npc = data[1];
  722. env->pc = pc;
  723. if (npc == DYNAMIC_PC) {
  724. /* dynamic NPC: already stored */
  725. } else if (npc & JUMP_PC) {
  726. /* jump PC: use 'cond' and the jump targets of the translation */
  727. if (env->cond) {
  728. env->npc = npc & ~3;
  729. } else {
  730. env->npc = pc + 4;
  731. }
  732. } else {
  733. env->npc = npc;
  734. }
  735. }
  736. #ifndef CONFIG_USER_ONLY
  737. static bool sparc_cpu_has_work(CPUState *cs)
  738. {
  739. return (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
  740. cpu_interrupts_enabled(cpu_env(cs));
  741. }
  742. #endif /* !CONFIG_USER_ONLY */
  743. static int sparc_cpu_mmu_index(CPUState *cs, bool ifetch)
  744. {
  745. CPUSPARCState *env = cpu_env(cs);
  746. #ifndef TARGET_SPARC64
  747. if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
  748. return MMU_PHYS_IDX;
  749. } else {
  750. return env->psrs;
  751. }
  752. #else
  753. /* IMMU or DMMU disabled. */
  754. if (ifetch
  755. ? (env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0
  756. : (env->lsu & DMMU_E) == 0) {
  757. return MMU_PHYS_IDX;
  758. } else if (cpu_hypervisor_mode(env)) {
  759. return MMU_PHYS_IDX;
  760. } else if (env->tl > 0) {
  761. return MMU_NUCLEUS_IDX;
  762. } else if (cpu_supervisor_mode(env)) {
  763. return MMU_KERNEL_IDX;
  764. } else {
  765. return MMU_USER_IDX;
  766. }
  767. #endif
  768. }
  769. static char *sparc_cpu_type_name(const char *cpu_model)
  770. {
  771. char *name = g_strdup_printf(SPARC_CPU_TYPE_NAME("%s"), cpu_model);
  772. char *s = name;
  773. /* SPARC cpu model names happen to have whitespaces,
  774. * as type names shouldn't have spaces replace them with '-'
  775. */
  776. while ((s = strchr(s, ' '))) {
  777. *s = '-';
  778. }
  779. return name;
  780. }
  781. static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model)
  782. {
  783. ObjectClass *oc;
  784. char *typename;
  785. typename = sparc_cpu_type_name(cpu_model);
  786. /* Fix up legacy names with '+' in it */
  787. if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV+"))) {
  788. g_free(typename);
  789. typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IV-plus"));
  790. } else if (g_str_equal(typename, SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi+"))) {
  791. g_free(typename);
  792. typename = g_strdup(SPARC_CPU_TYPE_NAME("Sun-UltraSparc-IIIi-plus"));
  793. }
  794. oc = object_class_by_name(typename);
  795. g_free(typename);
  796. return oc;
  797. }
  798. static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
  799. {
  800. CPUState *cs = CPU(dev);
  801. SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
  802. Error *local_err = NULL;
  803. CPUSPARCState *env = cpu_env(cs);
  804. #if defined(CONFIG_USER_ONLY)
  805. /* We are emulating the kernel, which will trap and emulate float128. */
  806. env->def.features |= CPU_FEATURE_FLOAT128;
  807. #endif
  808. env->version = env->def.iu_version;
  809. env->nwindows = env->def.nwindows;
  810. #if !defined(TARGET_SPARC64)
  811. env->mmuregs[0] |= env->def.mmu_version;
  812. cpu_sparc_set_id(env, 0);
  813. env->mxccregs[7] |= env->def.mxcc_version;
  814. #else
  815. env->mmu_version = env->def.mmu_version;
  816. env->maxtl = env->def.maxtl;
  817. env->version |= env->def.maxtl << 8;
  818. env->version |= env->def.nwindows - 1;
  819. #endif
  820. /*
  821. * Prefer SNaN over QNaN, order B then A. It's OK to do this in realize
  822. * rather than reset, because fp_status is after 'end_reset_fields' in
  823. * the CPU state struct so it won't get zeroed on reset.
  824. */
  825. set_float_2nan_prop_rule(float_2nan_prop_s_ba, &env->fp_status);
  826. /* For fused-multiply add, prefer SNaN over QNaN, then C->B->A */
  827. set_float_3nan_prop_rule(float_3nan_prop_s_cba, &env->fp_status);
  828. /* For inf * 0 + NaN, return the input NaN */
  829. set_float_infzeronan_rule(float_infzeronan_dnan_never, &env->fp_status);
  830. /* Default NaN value: sign bit clear, all frac bits set */
  831. set_float_default_nan_pattern(0b01111111, &env->fp_status);
  832. cpu_exec_realizefn(cs, &local_err);
  833. if (local_err != NULL) {
  834. error_propagate(errp, local_err);
  835. return;
  836. }
  837. qemu_init_vcpu(cs);
  838. scc->parent_realize(dev, errp);
  839. }
  840. static void sparc_cpu_initfn(Object *obj)
  841. {
  842. SPARCCPU *cpu = SPARC_CPU(obj);
  843. SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj);
  844. CPUSPARCState *env = &cpu->env;
  845. if (scc->cpu_def) {
  846. env->def = *scc->cpu_def;
  847. }
  848. }
  849. static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
  850. void *opaque, Error **errp)
  851. {
  852. SPARCCPU *cpu = SPARC_CPU(obj);
  853. int64_t value = cpu->env.def.nwindows;
  854. visit_type_int(v, name, &value, errp);
  855. }
  856. static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
  857. void *opaque, Error **errp)
  858. {
  859. const int64_t min = MIN_NWINDOWS;
  860. const int64_t max = MAX_NWINDOWS;
  861. SPARCCPU *cpu = SPARC_CPU(obj);
  862. int64_t value;
  863. if (!visit_type_int(v, name, &value, errp)) {
  864. return;
  865. }
  866. if (value < min || value > max) {
  867. error_setg(errp, "Property %s.%s doesn't take value %" PRId64
  868. " (minimum: %" PRId64 ", maximum: %" PRId64 ")",
  869. object_get_typename(obj), name ? name : "null",
  870. value, min, max);
  871. return;
  872. }
  873. cpu->env.def.nwindows = value;
  874. }
  875. static const PropertyInfo qdev_prop_nwindows = {
  876. .type = "int",
  877. .description = "Number of register windows",
  878. .get = sparc_get_nwindows,
  879. .set = sparc_set_nwindows,
  880. };
  881. /* This must match feature_name[]. */
  882. static const Property sparc_cpu_properties[] = {
  883. DEFINE_PROP_BIT("float128", SPARCCPU, env.def.features,
  884. CPU_FEATURE_BIT_FLOAT128, false),
  885. #ifdef TARGET_SPARC64
  886. DEFINE_PROP_BIT("cmt", SPARCCPU, env.def.features,
  887. CPU_FEATURE_BIT_CMT, false),
  888. DEFINE_PROP_BIT("gl", SPARCCPU, env.def.features,
  889. CPU_FEATURE_BIT_GL, false),
  890. DEFINE_PROP_BIT("hypv", SPARCCPU, env.def.features,
  891. CPU_FEATURE_BIT_HYPV, false),
  892. DEFINE_PROP_BIT("vis1", SPARCCPU, env.def.features,
  893. CPU_FEATURE_BIT_VIS1, false),
  894. DEFINE_PROP_BIT("vis2", SPARCCPU, env.def.features,
  895. CPU_FEATURE_BIT_VIS2, false),
  896. DEFINE_PROP_BIT("fmaf", SPARCCPU, env.def.features,
  897. CPU_FEATURE_BIT_FMAF, false),
  898. DEFINE_PROP_BIT("vis3", SPARCCPU, env.def.features,
  899. CPU_FEATURE_BIT_VIS3, false),
  900. DEFINE_PROP_BIT("ima", SPARCCPU, env.def.features,
  901. CPU_FEATURE_BIT_IMA, false),
  902. DEFINE_PROP_BIT("vis4", SPARCCPU, env.def.features,
  903. CPU_FEATURE_BIT_VIS4, false),
  904. #else
  905. DEFINE_PROP_BIT("mul", SPARCCPU, env.def.features,
  906. CPU_FEATURE_BIT_MUL, false),
  907. DEFINE_PROP_BIT("div", SPARCCPU, env.def.features,
  908. CPU_FEATURE_BIT_DIV, false),
  909. DEFINE_PROP_BIT("fsmuld", SPARCCPU, env.def.features,
  910. CPU_FEATURE_BIT_FSMULD, false),
  911. #endif
  912. DEFINE_PROP_UNSIGNED("iu-version", SPARCCPU, env.def.iu_version, 0,
  913. qdev_prop_uint64, target_ulong),
  914. DEFINE_PROP_UINT32("fpu-version", SPARCCPU, env.def.fpu_version, 0),
  915. DEFINE_PROP_UINT32("mmu-version", SPARCCPU, env.def.mmu_version, 0),
  916. DEFINE_PROP("nwindows", SPARCCPU, env.def.nwindows,
  917. qdev_prop_nwindows, uint32_t),
  918. };
  919. #ifndef CONFIG_USER_ONLY
  920. #include "hw/core/sysemu-cpu-ops.h"
  921. static const struct SysemuCPUOps sparc_sysemu_ops = {
  922. .has_work = sparc_cpu_has_work,
  923. .get_phys_page_debug = sparc_cpu_get_phys_page_debug,
  924. .legacy_vmsd = &vmstate_sparc_cpu,
  925. };
  926. #endif
  927. #ifdef CONFIG_TCG
  928. #include "accel/tcg/cpu-ops.h"
  929. static const TCGCPUOps sparc_tcg_ops = {
  930. .initialize = sparc_tcg_init,
  931. .translate_code = sparc_translate_code,
  932. .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
  933. .restore_state_to_opc = sparc_restore_state_to_opc,
  934. #ifndef CONFIG_USER_ONLY
  935. .tlb_fill = sparc_cpu_tlb_fill,
  936. .cpu_exec_interrupt = sparc_cpu_exec_interrupt,
  937. .cpu_exec_halt = sparc_cpu_has_work,
  938. .do_interrupt = sparc_cpu_do_interrupt,
  939. .do_transaction_failed = sparc_cpu_do_transaction_failed,
  940. .do_unaligned_access = sparc_cpu_do_unaligned_access,
  941. #endif /* !CONFIG_USER_ONLY */
  942. };
  943. #endif /* CONFIG_TCG */
  944. static void sparc_cpu_class_init(ObjectClass *oc, void *data)
  945. {
  946. SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
  947. CPUClass *cc = CPU_CLASS(oc);
  948. DeviceClass *dc = DEVICE_CLASS(oc);
  949. ResettableClass *rc = RESETTABLE_CLASS(oc);
  950. device_class_set_parent_realize(dc, sparc_cpu_realizefn,
  951. &scc->parent_realize);
  952. device_class_set_props(dc, sparc_cpu_properties);
  953. resettable_class_set_parent_phases(rc, NULL, sparc_cpu_reset_hold, NULL,
  954. &scc->parent_phases);
  955. cc->class_by_name = sparc_cpu_class_by_name;
  956. cc->parse_features = sparc_cpu_parse_features;
  957. cc->mmu_index = sparc_cpu_mmu_index;
  958. cc->dump_state = sparc_cpu_dump_state;
  959. #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
  960. cc->memory_rw_debug = sparc_cpu_memory_rw_debug;
  961. #endif
  962. cc->set_pc = sparc_cpu_set_pc;
  963. cc->get_pc = sparc_cpu_get_pc;
  964. cc->gdb_read_register = sparc_cpu_gdb_read_register;
  965. cc->gdb_write_register = sparc_cpu_gdb_write_register;
  966. #ifndef CONFIG_USER_ONLY
  967. cc->sysemu_ops = &sparc_sysemu_ops;
  968. #endif
  969. cc->disas_set_info = cpu_sparc_disas_set_info;
  970. #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
  971. cc->gdb_num_core_regs = 86;
  972. #else
  973. cc->gdb_num_core_regs = 72;
  974. #endif
  975. cc->tcg_ops = &sparc_tcg_ops;
  976. }
  977. static const TypeInfo sparc_cpu_type_info = {
  978. .name = TYPE_SPARC_CPU,
  979. .parent = TYPE_CPU,
  980. .instance_size = sizeof(SPARCCPU),
  981. .instance_align = __alignof(SPARCCPU),
  982. .instance_init = sparc_cpu_initfn,
  983. .abstract = true,
  984. .class_size = sizeof(SPARCCPUClass),
  985. .class_init = sparc_cpu_class_init,
  986. };
  987. static void sparc_cpu_cpudef_class_init(ObjectClass *oc, void *data)
  988. {
  989. SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
  990. scc->cpu_def = data;
  991. }
  992. static void sparc_register_cpudef_type(const struct sparc_def_t *def)
  993. {
  994. char *typename = sparc_cpu_type_name(def->name);
  995. TypeInfo ti = {
  996. .name = typename,
  997. .parent = TYPE_SPARC_CPU,
  998. .class_init = sparc_cpu_cpudef_class_init,
  999. .class_data = (void *)def,
  1000. };
  1001. type_register_static(&ti);
  1002. g_free(typename);
  1003. }
  1004. static void sparc_cpu_register_types(void)
  1005. {
  1006. int i;
  1007. type_register_static(&sparc_cpu_type_info);
  1008. for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
  1009. sparc_register_cpudef_type(&sparc_defs[i]);
  1010. }
  1011. }
  1012. type_init(sparc_cpu_register_types)