cpu.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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 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 "cpu.h"
  20. //#define DEBUG_FEATURES
  21. static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model);
  22. /* CPUClass::reset() */
  23. static void sparc_cpu_reset(CPUState *s)
  24. {
  25. SPARCCPU *cpu = SPARC_CPU(s);
  26. SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(cpu);
  27. CPUSPARCState *env = &cpu->env;
  28. if (qemu_loglevel_mask(CPU_LOG_RESET)) {
  29. qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
  30. log_cpu_state(env, 0);
  31. }
  32. scc->parent_reset(s);
  33. memset(env, 0, offsetof(CPUSPARCState, breakpoints));
  34. tlb_flush(env, 1);
  35. env->cwp = 0;
  36. #ifndef TARGET_SPARC64
  37. env->wim = 1;
  38. #endif
  39. env->regwptr = env->regbase + (env->cwp * 16);
  40. CC_OP = CC_OP_FLAGS;
  41. #if defined(CONFIG_USER_ONLY)
  42. #ifdef TARGET_SPARC64
  43. env->cleanwin = env->nwindows - 2;
  44. env->cansave = env->nwindows - 2;
  45. env->pstate = PS_RMO | PS_PEF | PS_IE;
  46. env->asi = 0x82; /* Primary no-fault */
  47. #endif
  48. #else
  49. #if !defined(TARGET_SPARC64)
  50. env->psret = 0;
  51. env->psrs = 1;
  52. env->psrps = 1;
  53. #endif
  54. #ifdef TARGET_SPARC64
  55. env->pstate = PS_PRIV|PS_RED|PS_PEF|PS_AG;
  56. env->hpstate = cpu_has_hypervisor(env) ? HS_PRIV : 0;
  57. env->tl = env->maxtl;
  58. cpu_tsptr(env)->tt = TT_POWER_ON_RESET;
  59. env->lsu = 0;
  60. #else
  61. env->mmuregs[0] &= ~(MMU_E | MMU_NF);
  62. env->mmuregs[0] |= env->def->mmu_bm;
  63. #endif
  64. env->pc = 0;
  65. env->npc = env->pc + 4;
  66. #endif
  67. env->cache_control = 0;
  68. }
  69. static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model)
  70. {
  71. sparc_def_t def1, *def = &def1;
  72. if (cpu_sparc_find_by_name(def, cpu_model) < 0) {
  73. return -1;
  74. }
  75. env->def = g_new0(sparc_def_t, 1);
  76. memcpy(env->def, def, sizeof(*def));
  77. #if defined(CONFIG_USER_ONLY)
  78. if ((env->def->features & CPU_FEATURE_FLOAT)) {
  79. env->def->features |= CPU_FEATURE_FLOAT128;
  80. }
  81. #endif
  82. env->cpu_model_str = cpu_model;
  83. env->version = def->iu_version;
  84. env->fsr = def->fpu_version;
  85. env->nwindows = def->nwindows;
  86. #if !defined(TARGET_SPARC64)
  87. env->mmuregs[0] |= def->mmu_version;
  88. cpu_sparc_set_id(env, 0);
  89. env->mxccregs[7] |= def->mxcc_version;
  90. #else
  91. env->mmu_version = def->mmu_version;
  92. env->maxtl = def->maxtl;
  93. env->version |= def->maxtl << 8;
  94. env->version |= def->nwindows - 1;
  95. #endif
  96. return 0;
  97. }
  98. SPARCCPU *cpu_sparc_init(const char *cpu_model)
  99. {
  100. SPARCCPU *cpu;
  101. CPUSPARCState *env;
  102. cpu = SPARC_CPU(object_new(TYPE_SPARC_CPU));
  103. env = &cpu->env;
  104. if (tcg_enabled()) {
  105. gen_intermediate_code_init(env);
  106. }
  107. if (cpu_sparc_register(env, cpu_model) < 0) {
  108. object_delete(OBJECT(cpu));
  109. return NULL;
  110. }
  111. qemu_init_vcpu(env);
  112. return cpu;
  113. }
  114. void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu)
  115. {
  116. #if !defined(TARGET_SPARC64)
  117. env->mxccregs[7] = ((cpu + 8) & 0xf) << 24;
  118. #endif
  119. }
  120. static const sparc_def_t sparc_defs[] = {
  121. #ifdef TARGET_SPARC64
  122. {
  123. .name = "Fujitsu Sparc64",
  124. .iu_version = ((0x04ULL << 48) | (0x02ULL << 32) | (0ULL << 24)),
  125. .fpu_version = 0x00000000,
  126. .mmu_version = mmu_us_12,
  127. .nwindows = 4,
  128. .maxtl = 4,
  129. .features = CPU_DEFAULT_FEATURES,
  130. },
  131. {
  132. .name = "Fujitsu Sparc64 III",
  133. .iu_version = ((0x04ULL << 48) | (0x03ULL << 32) | (0ULL << 24)),
  134. .fpu_version = 0x00000000,
  135. .mmu_version = mmu_us_12,
  136. .nwindows = 5,
  137. .maxtl = 4,
  138. .features = CPU_DEFAULT_FEATURES,
  139. },
  140. {
  141. .name = "Fujitsu Sparc64 IV",
  142. .iu_version = ((0x04ULL << 48) | (0x04ULL << 32) | (0ULL << 24)),
  143. .fpu_version = 0x00000000,
  144. .mmu_version = mmu_us_12,
  145. .nwindows = 8,
  146. .maxtl = 5,
  147. .features = CPU_DEFAULT_FEATURES,
  148. },
  149. {
  150. .name = "Fujitsu Sparc64 V",
  151. .iu_version = ((0x04ULL << 48) | (0x05ULL << 32) | (0x51ULL << 24)),
  152. .fpu_version = 0x00000000,
  153. .mmu_version = mmu_us_12,
  154. .nwindows = 8,
  155. .maxtl = 5,
  156. .features = CPU_DEFAULT_FEATURES,
  157. },
  158. {
  159. .name = "TI UltraSparc I",
  160. .iu_version = ((0x17ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
  161. .fpu_version = 0x00000000,
  162. .mmu_version = mmu_us_12,
  163. .nwindows = 8,
  164. .maxtl = 5,
  165. .features = CPU_DEFAULT_FEATURES,
  166. },
  167. {
  168. .name = "TI UltraSparc II",
  169. .iu_version = ((0x17ULL << 48) | (0x11ULL << 32) | (0x20ULL << 24)),
  170. .fpu_version = 0x00000000,
  171. .mmu_version = mmu_us_12,
  172. .nwindows = 8,
  173. .maxtl = 5,
  174. .features = CPU_DEFAULT_FEATURES,
  175. },
  176. {
  177. .name = "TI UltraSparc IIi",
  178. .iu_version = ((0x17ULL << 48) | (0x12ULL << 32) | (0x91ULL << 24)),
  179. .fpu_version = 0x00000000,
  180. .mmu_version = mmu_us_12,
  181. .nwindows = 8,
  182. .maxtl = 5,
  183. .features = CPU_DEFAULT_FEATURES,
  184. },
  185. {
  186. .name = "TI UltraSparc IIe",
  187. .iu_version = ((0x17ULL << 48) | (0x13ULL << 32) | (0x14ULL << 24)),
  188. .fpu_version = 0x00000000,
  189. .mmu_version = mmu_us_12,
  190. .nwindows = 8,
  191. .maxtl = 5,
  192. .features = CPU_DEFAULT_FEATURES,
  193. },
  194. {
  195. .name = "Sun UltraSparc III",
  196. .iu_version = ((0x3eULL << 48) | (0x14ULL << 32) | (0x34ULL << 24)),
  197. .fpu_version = 0x00000000,
  198. .mmu_version = mmu_us_12,
  199. .nwindows = 8,
  200. .maxtl = 5,
  201. .features = CPU_DEFAULT_FEATURES,
  202. },
  203. {
  204. .name = "Sun UltraSparc III Cu",
  205. .iu_version = ((0x3eULL << 48) | (0x15ULL << 32) | (0x41ULL << 24)),
  206. .fpu_version = 0x00000000,
  207. .mmu_version = mmu_us_3,
  208. .nwindows = 8,
  209. .maxtl = 5,
  210. .features = CPU_DEFAULT_FEATURES,
  211. },
  212. {
  213. .name = "Sun UltraSparc IIIi",
  214. .iu_version = ((0x3eULL << 48) | (0x16ULL << 32) | (0x34ULL << 24)),
  215. .fpu_version = 0x00000000,
  216. .mmu_version = mmu_us_12,
  217. .nwindows = 8,
  218. .maxtl = 5,
  219. .features = CPU_DEFAULT_FEATURES,
  220. },
  221. {
  222. .name = "Sun UltraSparc IV",
  223. .iu_version = ((0x3eULL << 48) | (0x18ULL << 32) | (0x31ULL << 24)),
  224. .fpu_version = 0x00000000,
  225. .mmu_version = mmu_us_4,
  226. .nwindows = 8,
  227. .maxtl = 5,
  228. .features = CPU_DEFAULT_FEATURES,
  229. },
  230. {
  231. .name = "Sun UltraSparc IV+",
  232. .iu_version = ((0x3eULL << 48) | (0x19ULL << 32) | (0x22ULL << 24)),
  233. .fpu_version = 0x00000000,
  234. .mmu_version = mmu_us_12,
  235. .nwindows = 8,
  236. .maxtl = 5,
  237. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_CMT,
  238. },
  239. {
  240. .name = "Sun UltraSparc IIIi+",
  241. .iu_version = ((0x3eULL << 48) | (0x22ULL << 32) | (0ULL << 24)),
  242. .fpu_version = 0x00000000,
  243. .mmu_version = mmu_us_3,
  244. .nwindows = 8,
  245. .maxtl = 5,
  246. .features = CPU_DEFAULT_FEATURES,
  247. },
  248. {
  249. .name = "Sun UltraSparc T1",
  250. /* defined in sparc_ifu_fdp.v and ctu.h */
  251. .iu_version = ((0x3eULL << 48) | (0x23ULL << 32) | (0x02ULL << 24)),
  252. .fpu_version = 0x00000000,
  253. .mmu_version = mmu_sun4v,
  254. .nwindows = 8,
  255. .maxtl = 6,
  256. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
  257. | CPU_FEATURE_GL,
  258. },
  259. {
  260. .name = "Sun UltraSparc T2",
  261. /* defined in tlu_asi_ctl.v and n2_revid_cust.v */
  262. .iu_version = ((0x3eULL << 48) | (0x24ULL << 32) | (0x02ULL << 24)),
  263. .fpu_version = 0x00000000,
  264. .mmu_version = mmu_sun4v,
  265. .nwindows = 8,
  266. .maxtl = 6,
  267. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_HYPV | CPU_FEATURE_CMT
  268. | CPU_FEATURE_GL,
  269. },
  270. {
  271. .name = "NEC UltraSparc I",
  272. .iu_version = ((0x22ULL << 48) | (0x10ULL << 32) | (0x40ULL << 24)),
  273. .fpu_version = 0x00000000,
  274. .mmu_version = mmu_us_12,
  275. .nwindows = 8,
  276. .maxtl = 5,
  277. .features = CPU_DEFAULT_FEATURES,
  278. },
  279. #else
  280. {
  281. .name = "Fujitsu MB86900",
  282. .iu_version = 0x00 << 24, /* Impl 0, ver 0 */
  283. .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
  284. .mmu_version = 0x00 << 24, /* Impl 0, ver 0 */
  285. .mmu_bm = 0x00004000,
  286. .mmu_ctpr_mask = 0x007ffff0,
  287. .mmu_cxr_mask = 0x0000003f,
  288. .mmu_sfsr_mask = 0xffffffff,
  289. .mmu_trcr_mask = 0xffffffff,
  290. .nwindows = 7,
  291. .features = CPU_FEATURE_FLOAT | CPU_FEATURE_FSMULD,
  292. },
  293. {
  294. .name = "Fujitsu MB86904",
  295. .iu_version = 0x04 << 24, /* Impl 0, ver 4 */
  296. .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
  297. .mmu_version = 0x04 << 24, /* Impl 0, ver 4 */
  298. .mmu_bm = 0x00004000,
  299. .mmu_ctpr_mask = 0x00ffffc0,
  300. .mmu_cxr_mask = 0x000000ff,
  301. .mmu_sfsr_mask = 0x00016fff,
  302. .mmu_trcr_mask = 0x00ffffff,
  303. .nwindows = 8,
  304. .features = CPU_DEFAULT_FEATURES,
  305. },
  306. {
  307. .name = "Fujitsu MB86907",
  308. .iu_version = 0x05 << 24, /* Impl 0, ver 5 */
  309. .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
  310. .mmu_version = 0x05 << 24, /* Impl 0, ver 5 */
  311. .mmu_bm = 0x00004000,
  312. .mmu_ctpr_mask = 0xffffffc0,
  313. .mmu_cxr_mask = 0x000000ff,
  314. .mmu_sfsr_mask = 0x00016fff,
  315. .mmu_trcr_mask = 0xffffffff,
  316. .nwindows = 8,
  317. .features = CPU_DEFAULT_FEATURES,
  318. },
  319. {
  320. .name = "LSI L64811",
  321. .iu_version = 0x10 << 24, /* Impl 1, ver 0 */
  322. .fpu_version = 1 << 17, /* FPU version 1 (LSI L64814) */
  323. .mmu_version = 0x10 << 24,
  324. .mmu_bm = 0x00004000,
  325. .mmu_ctpr_mask = 0x007ffff0,
  326. .mmu_cxr_mask = 0x0000003f,
  327. .mmu_sfsr_mask = 0xffffffff,
  328. .mmu_trcr_mask = 0xffffffff,
  329. .nwindows = 8,
  330. .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
  331. CPU_FEATURE_FSMULD,
  332. },
  333. {
  334. .name = "Cypress CY7C601",
  335. .iu_version = 0x11 << 24, /* Impl 1, ver 1 */
  336. .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
  337. .mmu_version = 0x10 << 24,
  338. .mmu_bm = 0x00004000,
  339. .mmu_ctpr_mask = 0x007ffff0,
  340. .mmu_cxr_mask = 0x0000003f,
  341. .mmu_sfsr_mask = 0xffffffff,
  342. .mmu_trcr_mask = 0xffffffff,
  343. .nwindows = 8,
  344. .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
  345. CPU_FEATURE_FSMULD,
  346. },
  347. {
  348. .name = "Cypress CY7C611",
  349. .iu_version = 0x13 << 24, /* Impl 1, ver 3 */
  350. .fpu_version = 3 << 17, /* FPU version 3 (Cypress CY7C602) */
  351. .mmu_version = 0x10 << 24,
  352. .mmu_bm = 0x00004000,
  353. .mmu_ctpr_mask = 0x007ffff0,
  354. .mmu_cxr_mask = 0x0000003f,
  355. .mmu_sfsr_mask = 0xffffffff,
  356. .mmu_trcr_mask = 0xffffffff,
  357. .nwindows = 8,
  358. .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
  359. CPU_FEATURE_FSMULD,
  360. },
  361. {
  362. .name = "TI MicroSparc I",
  363. .iu_version = 0x41000000,
  364. .fpu_version = 4 << 17,
  365. .mmu_version = 0x41000000,
  366. .mmu_bm = 0x00004000,
  367. .mmu_ctpr_mask = 0x007ffff0,
  368. .mmu_cxr_mask = 0x0000003f,
  369. .mmu_sfsr_mask = 0x00016fff,
  370. .mmu_trcr_mask = 0x0000003f,
  371. .nwindows = 7,
  372. .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_MUL |
  373. CPU_FEATURE_DIV | CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT |
  374. CPU_FEATURE_FMUL,
  375. },
  376. {
  377. .name = "TI MicroSparc II",
  378. .iu_version = 0x42000000,
  379. .fpu_version = 4 << 17,
  380. .mmu_version = 0x02000000,
  381. .mmu_bm = 0x00004000,
  382. .mmu_ctpr_mask = 0x00ffffc0,
  383. .mmu_cxr_mask = 0x000000ff,
  384. .mmu_sfsr_mask = 0x00016fff,
  385. .mmu_trcr_mask = 0x00ffffff,
  386. .nwindows = 8,
  387. .features = CPU_DEFAULT_FEATURES,
  388. },
  389. {
  390. .name = "TI MicroSparc IIep",
  391. .iu_version = 0x42000000,
  392. .fpu_version = 4 << 17,
  393. .mmu_version = 0x04000000,
  394. .mmu_bm = 0x00004000,
  395. .mmu_ctpr_mask = 0x00ffffc0,
  396. .mmu_cxr_mask = 0x000000ff,
  397. .mmu_sfsr_mask = 0x00016bff,
  398. .mmu_trcr_mask = 0x00ffffff,
  399. .nwindows = 8,
  400. .features = CPU_DEFAULT_FEATURES,
  401. },
  402. {
  403. .name = "TI SuperSparc 40", /* STP1020NPGA */
  404. .iu_version = 0x41000000, /* SuperSPARC 2.x */
  405. .fpu_version = 0 << 17,
  406. .mmu_version = 0x00000800, /* SuperSPARC 2.x, no MXCC */
  407. .mmu_bm = 0x00002000,
  408. .mmu_ctpr_mask = 0xffffffc0,
  409. .mmu_cxr_mask = 0x0000ffff,
  410. .mmu_sfsr_mask = 0xffffffff,
  411. .mmu_trcr_mask = 0xffffffff,
  412. .nwindows = 8,
  413. .features = CPU_DEFAULT_FEATURES,
  414. },
  415. {
  416. .name = "TI SuperSparc 50", /* STP1020PGA */
  417. .iu_version = 0x40000000, /* SuperSPARC 3.x */
  418. .fpu_version = 0 << 17,
  419. .mmu_version = 0x01000800, /* SuperSPARC 3.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 51",
  430. .iu_version = 0x40000000, /* SuperSPARC 3.x */
  431. .fpu_version = 0 << 17,
  432. .mmu_version = 0x01000000, /* SuperSPARC 3.x, 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. .mxcc_version = 0x00000104,
  439. .nwindows = 8,
  440. .features = CPU_DEFAULT_FEATURES,
  441. },
  442. {
  443. .name = "TI SuperSparc 60", /* STP1020APGA */
  444. .iu_version = 0x40000000, /* SuperSPARC 3.x */
  445. .fpu_version = 0 << 17,
  446. .mmu_version = 0x01000800, /* SuperSPARC 3.x, no MXCC */
  447. .mmu_bm = 0x00002000,
  448. .mmu_ctpr_mask = 0xffffffc0,
  449. .mmu_cxr_mask = 0x0000ffff,
  450. .mmu_sfsr_mask = 0xffffffff,
  451. .mmu_trcr_mask = 0xffffffff,
  452. .nwindows = 8,
  453. .features = CPU_DEFAULT_FEATURES,
  454. },
  455. {
  456. .name = "TI SuperSparc 61",
  457. .iu_version = 0x44000000, /* SuperSPARC 3.x */
  458. .fpu_version = 0 << 17,
  459. .mmu_version = 0x01000000, /* SuperSPARC 3.x, 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. .mxcc_version = 0x00000104,
  466. .nwindows = 8,
  467. .features = CPU_DEFAULT_FEATURES,
  468. },
  469. {
  470. .name = "TI SuperSparc II",
  471. .iu_version = 0x40000000, /* SuperSPARC II 1.x */
  472. .fpu_version = 0 << 17,
  473. .mmu_version = 0x08000000, /* SuperSPARC II 1.x, MXCC */
  474. .mmu_bm = 0x00002000,
  475. .mmu_ctpr_mask = 0xffffffc0,
  476. .mmu_cxr_mask = 0x0000ffff,
  477. .mmu_sfsr_mask = 0xffffffff,
  478. .mmu_trcr_mask = 0xffffffff,
  479. .mxcc_version = 0x00000104,
  480. .nwindows = 8,
  481. .features = CPU_DEFAULT_FEATURES,
  482. },
  483. {
  484. .name = "Ross RT625",
  485. .iu_version = 0x1e000000,
  486. .fpu_version = 1 << 17,
  487. .mmu_version = 0x1e000000,
  488. .mmu_bm = 0x00004000,
  489. .mmu_ctpr_mask = 0x007ffff0,
  490. .mmu_cxr_mask = 0x0000003f,
  491. .mmu_sfsr_mask = 0xffffffff,
  492. .mmu_trcr_mask = 0xffffffff,
  493. .nwindows = 8,
  494. .features = CPU_DEFAULT_FEATURES,
  495. },
  496. {
  497. .name = "Ross RT620",
  498. .iu_version = 0x1f000000,
  499. .fpu_version = 1 << 17,
  500. .mmu_version = 0x1f000000,
  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,
  508. },
  509. {
  510. .name = "BIT B5010",
  511. .iu_version = 0x20000000,
  512. .fpu_version = 0 << 17, /* B5010/B5110/B5120/B5210 */
  513. .mmu_version = 0x20000000,
  514. .mmu_bm = 0x00004000,
  515. .mmu_ctpr_mask = 0x007ffff0,
  516. .mmu_cxr_mask = 0x0000003f,
  517. .mmu_sfsr_mask = 0xffffffff,
  518. .mmu_trcr_mask = 0xffffffff,
  519. .nwindows = 8,
  520. .features = CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | CPU_FEATURE_FSQRT |
  521. CPU_FEATURE_FSMULD,
  522. },
  523. {
  524. .name = "Matsushita MN10501",
  525. .iu_version = 0x50000000,
  526. .fpu_version = 0 << 17,
  527. .mmu_version = 0x50000000,
  528. .mmu_bm = 0x00004000,
  529. .mmu_ctpr_mask = 0x007ffff0,
  530. .mmu_cxr_mask = 0x0000003f,
  531. .mmu_sfsr_mask = 0xffffffff,
  532. .mmu_trcr_mask = 0xffffffff,
  533. .nwindows = 8,
  534. .features = CPU_FEATURE_FLOAT | CPU_FEATURE_MUL | CPU_FEATURE_FSQRT |
  535. CPU_FEATURE_FSMULD,
  536. },
  537. {
  538. .name = "Weitek W8601",
  539. .iu_version = 0x90 << 24, /* Impl 9, ver 0 */
  540. .fpu_version = 3 << 17, /* FPU version 3 (Weitek WTL3170/2) */
  541. .mmu_version = 0x10 << 24,
  542. .mmu_bm = 0x00004000,
  543. .mmu_ctpr_mask = 0x007ffff0,
  544. .mmu_cxr_mask = 0x0000003f,
  545. .mmu_sfsr_mask = 0xffffffff,
  546. .mmu_trcr_mask = 0xffffffff,
  547. .nwindows = 8,
  548. .features = CPU_DEFAULT_FEATURES,
  549. },
  550. {
  551. .name = "LEON2",
  552. .iu_version = 0xf2000000,
  553. .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
  554. .mmu_version = 0xf2000000,
  555. .mmu_bm = 0x00004000,
  556. .mmu_ctpr_mask = 0x007ffff0,
  557. .mmu_cxr_mask = 0x0000003f,
  558. .mmu_sfsr_mask = 0xffffffff,
  559. .mmu_trcr_mask = 0xffffffff,
  560. .nwindows = 8,
  561. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
  562. },
  563. {
  564. .name = "LEON3",
  565. .iu_version = 0xf3000000,
  566. .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
  567. .mmu_version = 0xf3000000,
  568. .mmu_bm = 0x00000000,
  569. .mmu_ctpr_mask = 0x007ffff0,
  570. .mmu_cxr_mask = 0x0000003f,
  571. .mmu_sfsr_mask = 0xffffffff,
  572. .mmu_trcr_mask = 0xffffffff,
  573. .nwindows = 8,
  574. .features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
  575. CPU_FEATURE_ASR17 | CPU_FEATURE_CACHE_CTRL,
  576. },
  577. #endif
  578. };
  579. static const char * const feature_name[] = {
  580. "float",
  581. "float128",
  582. "swap",
  583. "mul",
  584. "div",
  585. "flush",
  586. "fsqrt",
  587. "fmul",
  588. "vis1",
  589. "vis2",
  590. "fsmuld",
  591. "hypv",
  592. "cmt",
  593. "gl",
  594. };
  595. static void print_features(FILE *f, fprintf_function cpu_fprintf,
  596. uint32_t features, const char *prefix)
  597. {
  598. unsigned int i;
  599. for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
  600. if (feature_name[i] && (features & (1 << i))) {
  601. if (prefix) {
  602. (*cpu_fprintf)(f, "%s", prefix);
  603. }
  604. (*cpu_fprintf)(f, "%s ", feature_name[i]);
  605. }
  606. }
  607. }
  608. static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features)
  609. {
  610. unsigned int i;
  611. for (i = 0; i < ARRAY_SIZE(feature_name); i++) {
  612. if (feature_name[i] && !strcmp(flagname, feature_name[i])) {
  613. *features |= 1 << i;
  614. return;
  615. }
  616. }
  617. fprintf(stderr, "CPU feature %s not found\n", flagname);
  618. }
  619. static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model)
  620. {
  621. unsigned int i;
  622. const sparc_def_t *def = NULL;
  623. char *s = strdup(cpu_model);
  624. char *featurestr, *name = strtok(s, ",");
  625. uint32_t plus_features = 0;
  626. uint32_t minus_features = 0;
  627. uint64_t iu_version;
  628. uint32_t fpu_version, mmu_version, nwindows;
  629. for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
  630. if (strcasecmp(name, sparc_defs[i].name) == 0) {
  631. def = &sparc_defs[i];
  632. }
  633. }
  634. if (!def) {
  635. goto error;
  636. }
  637. memcpy(cpu_def, def, sizeof(*def));
  638. featurestr = strtok(NULL, ",");
  639. while (featurestr) {
  640. char *val;
  641. if (featurestr[0] == '+') {
  642. add_flagname_to_bitmaps(featurestr + 1, &plus_features);
  643. } else if (featurestr[0] == '-') {
  644. add_flagname_to_bitmaps(featurestr + 1, &minus_features);
  645. } else if ((val = strchr(featurestr, '='))) {
  646. *val = 0; val++;
  647. if (!strcmp(featurestr, "iu_version")) {
  648. char *err;
  649. iu_version = strtoll(val, &err, 0);
  650. if (!*val || *err) {
  651. fprintf(stderr, "bad numerical value %s\n", val);
  652. goto error;
  653. }
  654. cpu_def->iu_version = iu_version;
  655. #ifdef DEBUG_FEATURES
  656. fprintf(stderr, "iu_version %" PRIx64 "\n", iu_version);
  657. #endif
  658. } else if (!strcmp(featurestr, "fpu_version")) {
  659. char *err;
  660. fpu_version = strtol(val, &err, 0);
  661. if (!*val || *err) {
  662. fprintf(stderr, "bad numerical value %s\n", val);
  663. goto error;
  664. }
  665. cpu_def->fpu_version = fpu_version;
  666. #ifdef DEBUG_FEATURES
  667. fprintf(stderr, "fpu_version %x\n", fpu_version);
  668. #endif
  669. } else if (!strcmp(featurestr, "mmu_version")) {
  670. char *err;
  671. mmu_version = strtol(val, &err, 0);
  672. if (!*val || *err) {
  673. fprintf(stderr, "bad numerical value %s\n", val);
  674. goto error;
  675. }
  676. cpu_def->mmu_version = mmu_version;
  677. #ifdef DEBUG_FEATURES
  678. fprintf(stderr, "mmu_version %x\n", mmu_version);
  679. #endif
  680. } else if (!strcmp(featurestr, "nwindows")) {
  681. char *err;
  682. nwindows = strtol(val, &err, 0);
  683. if (!*val || *err || nwindows > MAX_NWINDOWS ||
  684. nwindows < MIN_NWINDOWS) {
  685. fprintf(stderr, "bad numerical value %s\n", val);
  686. goto error;
  687. }
  688. cpu_def->nwindows = nwindows;
  689. #ifdef DEBUG_FEATURES
  690. fprintf(stderr, "nwindows %d\n", nwindows);
  691. #endif
  692. } else {
  693. fprintf(stderr, "unrecognized feature %s\n", featurestr);
  694. goto error;
  695. }
  696. } else {
  697. fprintf(stderr, "feature string `%s' not in format "
  698. "(+feature|-feature|feature=xyz)\n", featurestr);
  699. goto error;
  700. }
  701. featurestr = strtok(NULL, ",");
  702. }
  703. cpu_def->features |= plus_features;
  704. cpu_def->features &= ~minus_features;
  705. #ifdef DEBUG_FEATURES
  706. print_features(stderr, fprintf, cpu_def->features, NULL);
  707. #endif
  708. free(s);
  709. return 0;
  710. error:
  711. free(s);
  712. return -1;
  713. }
  714. void sparc_cpu_list(FILE *f, fprintf_function cpu_fprintf)
  715. {
  716. unsigned int i;
  717. for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
  718. (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx
  719. " FPU %08x MMU %08x NWINS %d ",
  720. sparc_defs[i].name,
  721. sparc_defs[i].iu_version,
  722. sparc_defs[i].fpu_version,
  723. sparc_defs[i].mmu_version,
  724. sparc_defs[i].nwindows);
  725. print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES &
  726. ~sparc_defs[i].features, "-");
  727. print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES &
  728. sparc_defs[i].features, "+");
  729. (*cpu_fprintf)(f, "\n");
  730. }
  731. (*cpu_fprintf)(f, "Default CPU feature flags (use '-' to remove): ");
  732. print_features(f, cpu_fprintf, CPU_DEFAULT_FEATURES, NULL);
  733. (*cpu_fprintf)(f, "\n");
  734. (*cpu_fprintf)(f, "Available CPU feature flags (use '+' to add): ");
  735. print_features(f, cpu_fprintf, ~CPU_DEFAULT_FEATURES, NULL);
  736. (*cpu_fprintf)(f, "\n");
  737. (*cpu_fprintf)(f, "Numerical features (use '=' to set): iu_version "
  738. "fpu_version mmu_version nwindows\n");
  739. }
  740. static void cpu_print_cc(FILE *f, fprintf_function cpu_fprintf,
  741. uint32_t cc)
  742. {
  743. cpu_fprintf(f, "%c%c%c%c", cc & PSR_NEG ? 'N' : '-',
  744. cc & PSR_ZERO ? 'Z' : '-', cc & PSR_OVF ? 'V' : '-',
  745. cc & PSR_CARRY ? 'C' : '-');
  746. }
  747. #ifdef TARGET_SPARC64
  748. #define REGS_PER_LINE 4
  749. #else
  750. #define REGS_PER_LINE 8
  751. #endif
  752. void cpu_dump_state(CPUSPARCState *env, FILE *f, fprintf_function cpu_fprintf,
  753. int flags)
  754. {
  755. int i, x;
  756. cpu_fprintf(f, "pc: " TARGET_FMT_lx " npc: " TARGET_FMT_lx "\n", env->pc,
  757. env->npc);
  758. cpu_fprintf(f, "General Registers:\n");
  759. for (i = 0; i < 8; i++) {
  760. if (i % REGS_PER_LINE == 0) {
  761. cpu_fprintf(f, "%%g%d-%d:", i, i + REGS_PER_LINE - 1);
  762. }
  763. cpu_fprintf(f, " " TARGET_FMT_lx, env->gregs[i]);
  764. if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
  765. cpu_fprintf(f, "\n");
  766. }
  767. }
  768. cpu_fprintf(f, "\nCurrent Register Window:\n");
  769. for (x = 0; x < 3; x++) {
  770. for (i = 0; i < 8; i++) {
  771. if (i % REGS_PER_LINE == 0) {
  772. cpu_fprintf(f, "%%%c%d-%d: ",
  773. x == 0 ? 'o' : (x == 1 ? 'l' : 'i'),
  774. i, i + REGS_PER_LINE - 1);
  775. }
  776. cpu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]);
  777. if (i % REGS_PER_LINE == REGS_PER_LINE - 1) {
  778. cpu_fprintf(f, "\n");
  779. }
  780. }
  781. }
  782. cpu_fprintf(f, "\nFloating Point Registers:\n");
  783. for (i = 0; i < TARGET_DPREGS; i++) {
  784. if ((i & 3) == 0) {
  785. cpu_fprintf(f, "%%f%02d:", i * 2);
  786. }
  787. cpu_fprintf(f, " %016" PRIx64, env->fpr[i].ll);
  788. if ((i & 3) == 3) {
  789. cpu_fprintf(f, "\n");
  790. }
  791. }
  792. #ifdef TARGET_SPARC64
  793. cpu_fprintf(f, "pstate: %08x ccr: %02x (icc: ", env->pstate,
  794. (unsigned)cpu_get_ccr(env));
  795. cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << PSR_CARRY_SHIFT);
  796. cpu_fprintf(f, " xcc: ");
  797. cpu_print_cc(f, cpu_fprintf, cpu_get_ccr(env) << (PSR_CARRY_SHIFT - 4));
  798. cpu_fprintf(f, ") asi: %02x tl: %d pil: %x\n", env->asi, env->tl,
  799. env->psrpil);
  800. cpu_fprintf(f, "cansave: %d canrestore: %d otherwin: %d wstate: %d "
  801. "cleanwin: %d cwp: %d\n",
  802. env->cansave, env->canrestore, env->otherwin, env->wstate,
  803. env->cleanwin, env->nwindows - 1 - env->cwp);
  804. cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx " fprs: "
  805. TARGET_FMT_lx "\n", env->fsr, env->y, env->fprs);
  806. #else
  807. cpu_fprintf(f, "psr: %08x (icc: ", cpu_get_psr(env));
  808. cpu_print_cc(f, cpu_fprintf, cpu_get_psr(env));
  809. cpu_fprintf(f, " SPE: %c%c%c) wim: %08x\n", env->psrs ? 'S' : '-',
  810. env->psrps ? 'P' : '-', env->psret ? 'E' : '-',
  811. env->wim);
  812. cpu_fprintf(f, "fsr: " TARGET_FMT_lx " y: " TARGET_FMT_lx "\n",
  813. env->fsr, env->y);
  814. #endif
  815. }
  816. static void sparc_cpu_initfn(Object *obj)
  817. {
  818. SPARCCPU *cpu = SPARC_CPU(obj);
  819. CPUSPARCState *env = &cpu->env;
  820. cpu_exec_init(env);
  821. }
  822. static void sparc_cpu_uninitfn(Object *obj)
  823. {
  824. SPARCCPU *cpu = SPARC_CPU(obj);
  825. CPUSPARCState *env = &cpu->env;
  826. g_free(env->def);
  827. }
  828. static void sparc_cpu_class_init(ObjectClass *oc, void *data)
  829. {
  830. SPARCCPUClass *scc = SPARC_CPU_CLASS(oc);
  831. CPUClass *cc = CPU_CLASS(oc);
  832. scc->parent_reset = cc->reset;
  833. cc->reset = sparc_cpu_reset;
  834. }
  835. static const TypeInfo sparc_cpu_type_info = {
  836. .name = TYPE_SPARC_CPU,
  837. .parent = TYPE_CPU,
  838. .instance_size = sizeof(SPARCCPU),
  839. .instance_init = sparc_cpu_initfn,
  840. .instance_finalize = sparc_cpu_uninitfn,
  841. .abstract = false,
  842. .class_size = sizeof(SPARCCPUClass),
  843. .class_init = sparc_cpu_class_init,
  844. };
  845. static void sparc_cpu_register_types(void)
  846. {
  847. type_register_static(&sparc_cpu_type_info);
  848. }
  849. type_init(sparc_cpu_register_types)