cpu.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. #ifndef CPU_SPARC_H
  2. #define CPU_SPARC_H
  3. #include "config.h"
  4. #include "qemu-common.h"
  5. #include "qemu/bswap.h"
  6. #define ALIGNED_ONLY
  7. #if !defined(TARGET_SPARC64)
  8. #define TARGET_LONG_BITS 32
  9. #define TARGET_DPREGS 16
  10. #define TARGET_PAGE_BITS 12 /* 4k */
  11. #define TARGET_PHYS_ADDR_SPACE_BITS 36
  12. #define TARGET_VIRT_ADDR_SPACE_BITS 32
  13. #else
  14. #define TARGET_LONG_BITS 64
  15. #define TARGET_DPREGS 32
  16. #define TARGET_PAGE_BITS 13 /* 8k */
  17. #define TARGET_PHYS_ADDR_SPACE_BITS 41
  18. # ifdef TARGET_ABI32
  19. # define TARGET_VIRT_ADDR_SPACE_BITS 32
  20. # else
  21. # define TARGET_VIRT_ADDR_SPACE_BITS 44
  22. # endif
  23. #endif
  24. #define CPUArchState struct CPUSPARCState
  25. #include "exec/cpu-defs.h"
  26. #include "fpu/softfloat.h"
  27. #define TARGET_HAS_ICE 1
  28. #if !defined(TARGET_SPARC64)
  29. #define ELF_MACHINE EM_SPARC
  30. #else
  31. #define ELF_MACHINE EM_SPARCV9
  32. #endif
  33. /*#define EXCP_INTERRUPT 0x100*/
  34. /* trap definitions */
  35. #ifndef TARGET_SPARC64
  36. #define TT_TFAULT 0x01
  37. #define TT_ILL_INSN 0x02
  38. #define TT_PRIV_INSN 0x03
  39. #define TT_NFPU_INSN 0x04
  40. #define TT_WIN_OVF 0x05
  41. #define TT_WIN_UNF 0x06
  42. #define TT_UNALIGNED 0x07
  43. #define TT_FP_EXCP 0x08
  44. #define TT_DFAULT 0x09
  45. #define TT_TOVF 0x0a
  46. #define TT_EXTINT 0x10
  47. #define TT_CODE_ACCESS 0x21
  48. #define TT_UNIMP_FLUSH 0x25
  49. #define TT_DATA_ACCESS 0x29
  50. #define TT_DIV_ZERO 0x2a
  51. #define TT_NCP_INSN 0x24
  52. #define TT_TRAP 0x80
  53. #else
  54. #define TT_POWER_ON_RESET 0x01
  55. #define TT_TFAULT 0x08
  56. #define TT_CODE_ACCESS 0x0a
  57. #define TT_ILL_INSN 0x10
  58. #define TT_UNIMP_FLUSH TT_ILL_INSN
  59. #define TT_PRIV_INSN 0x11
  60. #define TT_NFPU_INSN 0x20
  61. #define TT_FP_EXCP 0x21
  62. #define TT_TOVF 0x23
  63. #define TT_CLRWIN 0x24
  64. #define TT_DIV_ZERO 0x28
  65. #define TT_DFAULT 0x30
  66. #define TT_DATA_ACCESS 0x32
  67. #define TT_UNALIGNED 0x34
  68. #define TT_PRIV_ACT 0x37
  69. #define TT_EXTINT 0x40
  70. #define TT_IVEC 0x60
  71. #define TT_TMISS 0x64
  72. #define TT_DMISS 0x68
  73. #define TT_DPROT 0x6c
  74. #define TT_SPILL 0x80
  75. #define TT_FILL 0xc0
  76. #define TT_WOTHER (1 << 5)
  77. #define TT_TRAP 0x100
  78. #endif
  79. #define PSR_NEG_SHIFT 23
  80. #define PSR_NEG (1 << PSR_NEG_SHIFT)
  81. #define PSR_ZERO_SHIFT 22
  82. #define PSR_ZERO (1 << PSR_ZERO_SHIFT)
  83. #define PSR_OVF_SHIFT 21
  84. #define PSR_OVF (1 << PSR_OVF_SHIFT)
  85. #define PSR_CARRY_SHIFT 20
  86. #define PSR_CARRY (1 << PSR_CARRY_SHIFT)
  87. #define PSR_ICC (PSR_NEG|PSR_ZERO|PSR_OVF|PSR_CARRY)
  88. #if !defined(TARGET_SPARC64)
  89. #define PSR_EF (1<<12)
  90. #define PSR_PIL 0xf00
  91. #define PSR_S (1<<7)
  92. #define PSR_PS (1<<6)
  93. #define PSR_ET (1<<5)
  94. #define PSR_CWP 0x1f
  95. #endif
  96. #define CC_SRC (env->cc_src)
  97. #define CC_SRC2 (env->cc_src2)
  98. #define CC_DST (env->cc_dst)
  99. #define CC_OP (env->cc_op)
  100. enum {
  101. CC_OP_DYNAMIC, /* must use dynamic code to get cc_op */
  102. CC_OP_FLAGS, /* all cc are back in status register */
  103. CC_OP_DIV, /* modify N, Z and V, C = 0*/
  104. CC_OP_ADD, /* modify all flags, CC_DST = res, CC_SRC = src1 */
  105. CC_OP_ADDX, /* modify all flags, CC_DST = res, CC_SRC = src1 */
  106. CC_OP_TADD, /* modify all flags, CC_DST = res, CC_SRC = src1 */
  107. CC_OP_TADDTV, /* modify all flags except V, CC_DST = res, CC_SRC = src1 */
  108. CC_OP_SUB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
  109. CC_OP_SUBX, /* modify all flags, CC_DST = res, CC_SRC = src1 */
  110. CC_OP_TSUB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
  111. CC_OP_TSUBTV, /* modify all flags except V, CC_DST = res, CC_SRC = src1 */
  112. CC_OP_LOGIC, /* modify N and Z, C = V = 0, CC_DST = res */
  113. CC_OP_NB,
  114. };
  115. /* Trap base register */
  116. #define TBR_BASE_MASK 0xfffff000
  117. #if defined(TARGET_SPARC64)
  118. #define PS_TCT (1<<12) /* UA2007, impl.dep. trap on control transfer */
  119. #define PS_IG (1<<11) /* v9, zero on UA2007 */
  120. #define PS_MG (1<<10) /* v9, zero on UA2007 */
  121. #define PS_CLE (1<<9) /* UA2007 */
  122. #define PS_TLE (1<<8) /* UA2007 */
  123. #define PS_RMO (1<<7)
  124. #define PS_RED (1<<5) /* v9, zero on UA2007 */
  125. #define PS_PEF (1<<4) /* enable fpu */
  126. #define PS_AM (1<<3) /* address mask */
  127. #define PS_PRIV (1<<2)
  128. #define PS_IE (1<<1)
  129. #define PS_AG (1<<0) /* v9, zero on UA2007 */
  130. #define FPRS_FEF (1<<2)
  131. #define HS_PRIV (1<<2)
  132. #endif
  133. /* Fcc */
  134. #define FSR_RD1 (1ULL << 31)
  135. #define FSR_RD0 (1ULL << 30)
  136. #define FSR_RD_MASK (FSR_RD1 | FSR_RD0)
  137. #define FSR_RD_NEAREST 0
  138. #define FSR_RD_ZERO FSR_RD0
  139. #define FSR_RD_POS FSR_RD1
  140. #define FSR_RD_NEG (FSR_RD1 | FSR_RD0)
  141. #define FSR_NVM (1ULL << 27)
  142. #define FSR_OFM (1ULL << 26)
  143. #define FSR_UFM (1ULL << 25)
  144. #define FSR_DZM (1ULL << 24)
  145. #define FSR_NXM (1ULL << 23)
  146. #define FSR_TEM_MASK (FSR_NVM | FSR_OFM | FSR_UFM | FSR_DZM | FSR_NXM)
  147. #define FSR_NVA (1ULL << 9)
  148. #define FSR_OFA (1ULL << 8)
  149. #define FSR_UFA (1ULL << 7)
  150. #define FSR_DZA (1ULL << 6)
  151. #define FSR_NXA (1ULL << 5)
  152. #define FSR_AEXC_MASK (FSR_NVA | FSR_OFA | FSR_UFA | FSR_DZA | FSR_NXA)
  153. #define FSR_NVC (1ULL << 4)
  154. #define FSR_OFC (1ULL << 3)
  155. #define FSR_UFC (1ULL << 2)
  156. #define FSR_DZC (1ULL << 1)
  157. #define FSR_NXC (1ULL << 0)
  158. #define FSR_CEXC_MASK (FSR_NVC | FSR_OFC | FSR_UFC | FSR_DZC | FSR_NXC)
  159. #define FSR_FTT2 (1ULL << 16)
  160. #define FSR_FTT1 (1ULL << 15)
  161. #define FSR_FTT0 (1ULL << 14)
  162. //gcc warns about constant overflow for ~FSR_FTT_MASK
  163. //#define FSR_FTT_MASK (FSR_FTT2 | FSR_FTT1 | FSR_FTT0)
  164. #ifdef TARGET_SPARC64
  165. #define FSR_FTT_NMASK 0xfffffffffffe3fffULL
  166. #define FSR_FTT_CEXC_NMASK 0xfffffffffffe3fe0ULL
  167. #define FSR_LDFSR_OLDMASK 0x0000003f000fc000ULL
  168. #define FSR_LDXFSR_MASK 0x0000003fcfc00fffULL
  169. #define FSR_LDXFSR_OLDMASK 0x00000000000fc000ULL
  170. #else
  171. #define FSR_FTT_NMASK 0xfffe3fffULL
  172. #define FSR_FTT_CEXC_NMASK 0xfffe3fe0ULL
  173. #define FSR_LDFSR_OLDMASK 0x000fc000ULL
  174. #endif
  175. #define FSR_LDFSR_MASK 0xcfc00fffULL
  176. #define FSR_FTT_IEEE_EXCP (1ULL << 14)
  177. #define FSR_FTT_UNIMPFPOP (3ULL << 14)
  178. #define FSR_FTT_SEQ_ERROR (4ULL << 14)
  179. #define FSR_FTT_INVAL_FPR (6ULL << 14)
  180. #define FSR_FCC1_SHIFT 11
  181. #define FSR_FCC1 (1ULL << FSR_FCC1_SHIFT)
  182. #define FSR_FCC0_SHIFT 10
  183. #define FSR_FCC0 (1ULL << FSR_FCC0_SHIFT)
  184. /* MMU */
  185. #define MMU_E (1<<0)
  186. #define MMU_NF (1<<1)
  187. #define PTE_ENTRYTYPE_MASK 3
  188. #define PTE_ACCESS_MASK 0x1c
  189. #define PTE_ACCESS_SHIFT 2
  190. #define PTE_PPN_SHIFT 7
  191. #define PTE_ADDR_MASK 0xffffff00
  192. #define PG_ACCESSED_BIT 5
  193. #define PG_MODIFIED_BIT 6
  194. #define PG_CACHE_BIT 7
  195. #define PG_ACCESSED_MASK (1 << PG_ACCESSED_BIT)
  196. #define PG_MODIFIED_MASK (1 << PG_MODIFIED_BIT)
  197. #define PG_CACHE_MASK (1 << PG_CACHE_BIT)
  198. /* 3 <= NWINDOWS <= 32. */
  199. #define MIN_NWINDOWS 3
  200. #define MAX_NWINDOWS 32
  201. #if !defined(TARGET_SPARC64)
  202. #define NB_MMU_MODES 2
  203. #else
  204. #define NB_MMU_MODES 6
  205. typedef struct trap_state {
  206. uint64_t tpc;
  207. uint64_t tnpc;
  208. uint64_t tstate;
  209. uint32_t tt;
  210. } trap_state;
  211. #endif
  212. typedef struct sparc_def_t {
  213. const char *name;
  214. target_ulong iu_version;
  215. uint32_t fpu_version;
  216. uint32_t mmu_version;
  217. uint32_t mmu_bm;
  218. uint32_t mmu_ctpr_mask;
  219. uint32_t mmu_cxr_mask;
  220. uint32_t mmu_sfsr_mask;
  221. uint32_t mmu_trcr_mask;
  222. uint32_t mxcc_version;
  223. uint32_t features;
  224. uint32_t nwindows;
  225. uint32_t maxtl;
  226. } sparc_def_t;
  227. #define CPU_FEATURE_FLOAT (1 << 0)
  228. #define CPU_FEATURE_FLOAT128 (1 << 1)
  229. #define CPU_FEATURE_SWAP (1 << 2)
  230. #define CPU_FEATURE_MUL (1 << 3)
  231. #define CPU_FEATURE_DIV (1 << 4)
  232. #define CPU_FEATURE_FLUSH (1 << 5)
  233. #define CPU_FEATURE_FSQRT (1 << 6)
  234. #define CPU_FEATURE_FMUL (1 << 7)
  235. #define CPU_FEATURE_VIS1 (1 << 8)
  236. #define CPU_FEATURE_VIS2 (1 << 9)
  237. #define CPU_FEATURE_FSMULD (1 << 10)
  238. #define CPU_FEATURE_HYPV (1 << 11)
  239. #define CPU_FEATURE_CMT (1 << 12)
  240. #define CPU_FEATURE_GL (1 << 13)
  241. #define CPU_FEATURE_TA0_SHUTDOWN (1 << 14) /* Shutdown on "ta 0x0" */
  242. #define CPU_FEATURE_ASR17 (1 << 15)
  243. #define CPU_FEATURE_CACHE_CTRL (1 << 16)
  244. #define CPU_FEATURE_POWERDOWN (1 << 17)
  245. #define CPU_FEATURE_CASA (1 << 18)
  246. #ifndef TARGET_SPARC64
  247. #define CPU_DEFAULT_FEATURES (CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | \
  248. CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
  249. CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | \
  250. CPU_FEATURE_FMUL | CPU_FEATURE_FSMULD)
  251. #else
  252. #define CPU_DEFAULT_FEATURES (CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | \
  253. CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
  254. CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | \
  255. CPU_FEATURE_FMUL | CPU_FEATURE_VIS1 | \
  256. CPU_FEATURE_VIS2 | CPU_FEATURE_FSMULD | \
  257. CPU_FEATURE_CASA)
  258. enum {
  259. mmu_us_12, // Ultrasparc < III (64 entry TLB)
  260. mmu_us_3, // Ultrasparc III (512 entry TLB)
  261. mmu_us_4, // Ultrasparc IV (several TLBs, 32 and 256MB pages)
  262. mmu_sun4v, // T1, T2
  263. };
  264. #endif
  265. #define TTE_VALID_BIT (1ULL << 63)
  266. #define TTE_NFO_BIT (1ULL << 60)
  267. #define TTE_USED_BIT (1ULL << 41)
  268. #define TTE_LOCKED_BIT (1ULL << 6)
  269. #define TTE_SIDEEFFECT_BIT (1ULL << 3)
  270. #define TTE_PRIV_BIT (1ULL << 2)
  271. #define TTE_W_OK_BIT (1ULL << 1)
  272. #define TTE_GLOBAL_BIT (1ULL << 0)
  273. #define TTE_IS_VALID(tte) ((tte) & TTE_VALID_BIT)
  274. #define TTE_IS_NFO(tte) ((tte) & TTE_NFO_BIT)
  275. #define TTE_IS_USED(tte) ((tte) & TTE_USED_BIT)
  276. #define TTE_IS_LOCKED(tte) ((tte) & TTE_LOCKED_BIT)
  277. #define TTE_IS_SIDEEFFECT(tte) ((tte) & TTE_SIDEEFFECT_BIT)
  278. #define TTE_IS_PRIV(tte) ((tte) & TTE_PRIV_BIT)
  279. #define TTE_IS_W_OK(tte) ((tte) & TTE_W_OK_BIT)
  280. #define TTE_IS_GLOBAL(tte) ((tte) & TTE_GLOBAL_BIT)
  281. #define TTE_SET_USED(tte) ((tte) |= TTE_USED_BIT)
  282. #define TTE_SET_UNUSED(tte) ((tte) &= ~TTE_USED_BIT)
  283. #define TTE_PGSIZE(tte) (((tte) >> 61) & 3ULL)
  284. #define TTE_PA(tte) ((tte) & 0x1ffffffe000ULL)
  285. #define SFSR_NF_BIT (1ULL << 24) /* JPS1 NoFault */
  286. #define SFSR_TM_BIT (1ULL << 15) /* JPS1 TLB Miss */
  287. #define SFSR_FT_VA_IMMU_BIT (1ULL << 13) /* USIIi VA out of range (IMMU) */
  288. #define SFSR_FT_VA_DMMU_BIT (1ULL << 12) /* USIIi VA out of range (DMMU) */
  289. #define SFSR_FT_NFO_BIT (1ULL << 11) /* NFO page access */
  290. #define SFSR_FT_ILL_BIT (1ULL << 10) /* illegal LDA/STA ASI */
  291. #define SFSR_FT_ATOMIC_BIT (1ULL << 9) /* atomic op on noncacheable area */
  292. #define SFSR_FT_NF_E_BIT (1ULL << 8) /* NF access on side effect area */
  293. #define SFSR_FT_PRIV_BIT (1ULL << 7) /* privilege violation */
  294. #define SFSR_PR_BIT (1ULL << 3) /* privilege mode */
  295. #define SFSR_WRITE_BIT (1ULL << 2) /* write access mode */
  296. #define SFSR_OW_BIT (1ULL << 1) /* status overwritten */
  297. #define SFSR_VALID_BIT (1ULL << 0) /* status valid */
  298. #define SFSR_ASI_SHIFT 16 /* 23:16 ASI value */
  299. #define SFSR_ASI_MASK (0xffULL << SFSR_ASI_SHIFT)
  300. #define SFSR_CT_PRIMARY (0ULL << 4) /* 5:4 context type */
  301. #define SFSR_CT_SECONDARY (1ULL << 4)
  302. #define SFSR_CT_NUCLEUS (2ULL << 4)
  303. #define SFSR_CT_NOTRANS (3ULL << 4)
  304. #define SFSR_CT_MASK (3ULL << 4)
  305. /* Leon3 cache control */
  306. /* Cache control: emulate the behavior of cache control registers but without
  307. any effect on the emulated */
  308. #define CACHE_STATE_MASK 0x3
  309. #define CACHE_DISABLED 0x0
  310. #define CACHE_FROZEN 0x1
  311. #define CACHE_ENABLED 0x3
  312. /* Cache Control register fields */
  313. #define CACHE_CTRL_IF (1 << 4) /* Instruction Cache Freeze on Interrupt */
  314. #define CACHE_CTRL_DF (1 << 5) /* Data Cache Freeze on Interrupt */
  315. #define CACHE_CTRL_DP (1 << 14) /* Data cache flush pending */
  316. #define CACHE_CTRL_IP (1 << 15) /* Instruction cache flush pending */
  317. #define CACHE_CTRL_IB (1 << 16) /* Instruction burst fetch */
  318. #define CACHE_CTRL_FI (1 << 21) /* Flush Instruction cache (Write only) */
  319. #define CACHE_CTRL_FD (1 << 22) /* Flush Data cache (Write only) */
  320. #define CACHE_CTRL_DS (1 << 23) /* Data cache snoop enable */
  321. typedef struct SparcTLBEntry {
  322. uint64_t tag;
  323. uint64_t tte;
  324. } SparcTLBEntry;
  325. struct CPUTimer
  326. {
  327. const char *name;
  328. uint32_t frequency;
  329. uint32_t disabled;
  330. uint64_t disabled_mask;
  331. int64_t clock_offset;
  332. QEMUTimer *qtimer;
  333. };
  334. typedef struct CPUTimer CPUTimer;
  335. struct QEMUFile;
  336. void cpu_put_timer(struct QEMUFile *f, CPUTimer *s);
  337. void cpu_get_timer(struct QEMUFile *f, CPUTimer *s);
  338. typedef struct CPUSPARCState CPUSPARCState;
  339. struct CPUSPARCState {
  340. target_ulong gregs[8]; /* general registers */
  341. target_ulong *regwptr; /* pointer to current register window */
  342. target_ulong pc; /* program counter */
  343. target_ulong npc; /* next program counter */
  344. target_ulong y; /* multiply/divide register */
  345. /* emulator internal flags handling */
  346. target_ulong cc_src, cc_src2;
  347. target_ulong cc_dst;
  348. uint32_t cc_op;
  349. target_ulong cond; /* conditional branch result (XXX: save it in a
  350. temporary register when possible) */
  351. uint32_t psr; /* processor state register */
  352. target_ulong fsr; /* FPU state register */
  353. CPU_DoubleU fpr[TARGET_DPREGS]; /* floating point registers */
  354. uint32_t cwp; /* index of current register window (extracted
  355. from PSR) */
  356. #if !defined(TARGET_SPARC64) || defined(TARGET_ABI32)
  357. uint32_t wim; /* window invalid mask */
  358. #endif
  359. target_ulong tbr; /* trap base register */
  360. #if !defined(TARGET_SPARC64)
  361. int psrs; /* supervisor mode (extracted from PSR) */
  362. int psrps; /* previous supervisor mode */
  363. int psret; /* enable traps */
  364. #endif
  365. uint32_t psrpil; /* interrupt blocking level */
  366. uint32_t pil_in; /* incoming interrupt level bitmap */
  367. #if !defined(TARGET_SPARC64)
  368. int psref; /* enable fpu */
  369. #endif
  370. int interrupt_index;
  371. /* NOTE: we allow 8 more registers to handle wrapping */
  372. target_ulong regbase[MAX_NWINDOWS * 16 + 8];
  373. CPU_COMMON
  374. /* Fields from here on are preserved across CPU reset. */
  375. target_ulong version;
  376. uint32_t nwindows;
  377. /* MMU regs */
  378. #if defined(TARGET_SPARC64)
  379. uint64_t lsu;
  380. #define DMMU_E 0x8
  381. #define IMMU_E 0x4
  382. //typedef struct SparcMMU
  383. union {
  384. uint64_t immuregs[16];
  385. struct {
  386. uint64_t tsb_tag_target;
  387. uint64_t unused_mmu_primary_context; // use DMMU
  388. uint64_t unused_mmu_secondary_context; // use DMMU
  389. uint64_t sfsr;
  390. uint64_t sfar;
  391. uint64_t tsb;
  392. uint64_t tag_access;
  393. } immu;
  394. };
  395. union {
  396. uint64_t dmmuregs[16];
  397. struct {
  398. uint64_t tsb_tag_target;
  399. uint64_t mmu_primary_context;
  400. uint64_t mmu_secondary_context;
  401. uint64_t sfsr;
  402. uint64_t sfar;
  403. uint64_t tsb;
  404. uint64_t tag_access;
  405. } dmmu;
  406. };
  407. SparcTLBEntry itlb[64];
  408. SparcTLBEntry dtlb[64];
  409. uint32_t mmu_version;
  410. #else
  411. uint32_t mmuregs[32];
  412. uint64_t mxccdata[4];
  413. uint64_t mxccregs[8];
  414. uint32_t mmubpctrv, mmubpctrc, mmubpctrs;
  415. uint64_t mmubpaction;
  416. uint64_t mmubpregs[4];
  417. uint64_t prom_addr;
  418. #endif
  419. /* temporary float registers */
  420. float128 qt0, qt1;
  421. float_status fp_status;
  422. #if defined(TARGET_SPARC64)
  423. #define MAXTL_MAX 8
  424. #define MAXTL_MASK (MAXTL_MAX - 1)
  425. trap_state ts[MAXTL_MAX];
  426. uint32_t xcc; /* Extended integer condition codes */
  427. uint32_t asi;
  428. uint32_t pstate;
  429. uint32_t tl;
  430. uint32_t maxtl;
  431. uint32_t cansave, canrestore, otherwin, wstate, cleanwin;
  432. uint64_t agregs[8]; /* alternate general registers */
  433. uint64_t bgregs[8]; /* backup for normal global registers */
  434. uint64_t igregs[8]; /* interrupt general registers */
  435. uint64_t mgregs[8]; /* mmu general registers */
  436. uint64_t fprs;
  437. uint64_t tick_cmpr, stick_cmpr;
  438. CPUTimer *tick, *stick;
  439. #define TICK_NPT_MASK 0x8000000000000000ULL
  440. #define TICK_INT_DIS 0x8000000000000000ULL
  441. uint64_t gsr;
  442. uint32_t gl; // UA2005
  443. /* UA 2005 hyperprivileged registers */
  444. uint64_t hpstate, htstate[MAXTL_MAX], hintp, htba, hver, hstick_cmpr, ssr;
  445. CPUTimer *hstick; // UA 2005
  446. /* Interrupt vector registers */
  447. uint64_t ivec_status;
  448. uint64_t ivec_data[3];
  449. uint32_t softint;
  450. #define SOFTINT_TIMER 1
  451. #define SOFTINT_STIMER (1 << 16)
  452. #define SOFTINT_INTRMASK (0xFFFE)
  453. #define SOFTINT_REG_MASK (SOFTINT_STIMER|SOFTINT_INTRMASK|SOFTINT_TIMER)
  454. #endif
  455. sparc_def_t *def;
  456. void *irq_manager;
  457. void (*qemu_irq_ack)(CPUSPARCState *env, void *irq_manager, int intno);
  458. /* Leon3 cache control */
  459. uint32_t cache_control;
  460. };
  461. #include "cpu-qom.h"
  462. #ifndef NO_CPU_IO_DEFS
  463. /* cpu_init.c */
  464. SPARCCPU *cpu_sparc_init(const char *cpu_model);
  465. void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu);
  466. void sparc_cpu_list(FILE *f, fprintf_function cpu_fprintf);
  467. /* mmu_helper.c */
  468. int sparc_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
  469. int mmu_idx);
  470. target_ulong mmu_probe(CPUSPARCState *env, target_ulong address, int mmulev);
  471. void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUSPARCState *env);
  472. #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
  473. int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
  474. uint8_t *buf, int len, bool is_write);
  475. #endif
  476. /* translate.c */
  477. void gen_intermediate_code_init(CPUSPARCState *env);
  478. /* cpu-exec.c */
  479. int cpu_sparc_exec(CPUSPARCState *s);
  480. /* win_helper.c */
  481. target_ulong cpu_get_psr(CPUSPARCState *env1);
  482. void cpu_put_psr(CPUSPARCState *env1, target_ulong val);
  483. #ifdef TARGET_SPARC64
  484. target_ulong cpu_get_ccr(CPUSPARCState *env1);
  485. void cpu_put_ccr(CPUSPARCState *env1, target_ulong val);
  486. target_ulong cpu_get_cwp64(CPUSPARCState *env1);
  487. void cpu_put_cwp64(CPUSPARCState *env1, int cwp);
  488. void cpu_change_pstate(CPUSPARCState *env1, uint32_t new_pstate);
  489. #endif
  490. int cpu_cwp_inc(CPUSPARCState *env1, int cwp);
  491. int cpu_cwp_dec(CPUSPARCState *env1, int cwp);
  492. void cpu_set_cwp(CPUSPARCState *env1, int new_cwp);
  493. /* int_helper.c */
  494. void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno);
  495. /* sun4m.c, sun4u.c */
  496. void cpu_check_irqs(CPUSPARCState *env);
  497. /* leon3.c */
  498. void leon3_irq_ack(void *irq_manager, int intno);
  499. #if defined (TARGET_SPARC64)
  500. static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask)
  501. {
  502. return (x & mask) == (y & mask);
  503. }
  504. #define MMU_CONTEXT_BITS 13
  505. #define MMU_CONTEXT_MASK ((1 << MMU_CONTEXT_BITS) - 1)
  506. static inline int tlb_compare_context(const SparcTLBEntry *tlb,
  507. uint64_t context)
  508. {
  509. return compare_masked(context, tlb->tag, MMU_CONTEXT_MASK);
  510. }
  511. #endif
  512. #endif
  513. /* cpu-exec.c */
  514. #if !defined(CONFIG_USER_ONLY)
  515. void sparc_cpu_unassigned_access(CPUState *cpu, hwaddr addr,
  516. bool is_write, bool is_exec, int is_asi,
  517. unsigned size);
  518. #if defined(TARGET_SPARC64)
  519. hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
  520. int mmu_idx);
  521. #endif
  522. #endif
  523. int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
  524. #ifndef NO_CPU_IO_DEFS
  525. static inline CPUSPARCState *cpu_init(const char *cpu_model)
  526. {
  527. SPARCCPU *cpu = cpu_sparc_init(cpu_model);
  528. if (cpu == NULL) {
  529. return NULL;
  530. }
  531. return &cpu->env;
  532. }
  533. #endif
  534. #define cpu_exec cpu_sparc_exec
  535. #define cpu_gen_code cpu_sparc_gen_code
  536. #define cpu_signal_handler cpu_sparc_signal_handler
  537. #define cpu_list sparc_cpu_list
  538. #define CPU_SAVE_VERSION 7
  539. /* MMU modes definitions */
  540. #if defined (TARGET_SPARC64)
  541. #define MMU_USER_IDX 0
  542. #define MMU_MODE0_SUFFIX _user
  543. #define MMU_USER_SECONDARY_IDX 1
  544. #define MMU_MODE1_SUFFIX _user_secondary
  545. #define MMU_KERNEL_IDX 2
  546. #define MMU_MODE2_SUFFIX _kernel
  547. #define MMU_KERNEL_SECONDARY_IDX 3
  548. #define MMU_MODE3_SUFFIX _kernel_secondary
  549. #define MMU_NUCLEUS_IDX 4
  550. #define MMU_MODE4_SUFFIX _nucleus
  551. #define MMU_HYPV_IDX 5
  552. #define MMU_MODE5_SUFFIX _hypv
  553. #else
  554. #define MMU_USER_IDX 0
  555. #define MMU_MODE0_SUFFIX _user
  556. #define MMU_KERNEL_IDX 1
  557. #define MMU_MODE1_SUFFIX _kernel
  558. #endif
  559. #if defined (TARGET_SPARC64)
  560. static inline int cpu_has_hypervisor(CPUSPARCState *env1)
  561. {
  562. return env1->def->features & CPU_FEATURE_HYPV;
  563. }
  564. static inline int cpu_hypervisor_mode(CPUSPARCState *env1)
  565. {
  566. return cpu_has_hypervisor(env1) && (env1->hpstate & HS_PRIV);
  567. }
  568. static inline int cpu_supervisor_mode(CPUSPARCState *env1)
  569. {
  570. return env1->pstate & PS_PRIV;
  571. }
  572. #endif
  573. static inline int cpu_mmu_index(CPUSPARCState *env1)
  574. {
  575. #if defined(CONFIG_USER_ONLY)
  576. return MMU_USER_IDX;
  577. #elif !defined(TARGET_SPARC64)
  578. return env1->psrs;
  579. #else
  580. if (env1->tl > 0) {
  581. return MMU_NUCLEUS_IDX;
  582. } else if (cpu_hypervisor_mode(env1)) {
  583. return MMU_HYPV_IDX;
  584. } else if (cpu_supervisor_mode(env1)) {
  585. return MMU_KERNEL_IDX;
  586. } else {
  587. return MMU_USER_IDX;
  588. }
  589. #endif
  590. }
  591. static inline int cpu_interrupts_enabled(CPUSPARCState *env1)
  592. {
  593. #if !defined (TARGET_SPARC64)
  594. if (env1->psret != 0)
  595. return 1;
  596. #else
  597. if (env1->pstate & PS_IE)
  598. return 1;
  599. #endif
  600. return 0;
  601. }
  602. static inline int cpu_pil_allowed(CPUSPARCState *env1, int pil)
  603. {
  604. #if !defined(TARGET_SPARC64)
  605. /* level 15 is non-maskable on sparc v8 */
  606. return pil == 15 || pil > env1->psrpil;
  607. #else
  608. return pil > env1->psrpil;
  609. #endif
  610. }
  611. #include "exec/cpu-all.h"
  612. #ifdef TARGET_SPARC64
  613. /* sun4u.c */
  614. void cpu_tick_set_count(CPUTimer *timer, uint64_t count);
  615. uint64_t cpu_tick_get_count(CPUTimer *timer);
  616. void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit);
  617. trap_state* cpu_tsptr(CPUSPARCState* env);
  618. #endif
  619. #define TB_FLAG_FPU_ENABLED (1 << 4)
  620. #define TB_FLAG_AM_ENABLED (1 << 5)
  621. static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, target_ulong *pc,
  622. target_ulong *cs_base, int *flags)
  623. {
  624. *pc = env->pc;
  625. *cs_base = env->npc;
  626. #ifdef TARGET_SPARC64
  627. // AM . Combined FPU enable bits . PRIV . DMMU enabled . IMMU enabled
  628. *flags = (env->pstate & PS_PRIV) /* 2 */
  629. | ((env->lsu & (DMMU_E | IMMU_E)) >> 2) /* 1, 0 */
  630. | ((env->tl & 0xff) << 8)
  631. | (env->dmmu.mmu_primary_context << 16); /* 16... */
  632. if (env->pstate & PS_AM) {
  633. *flags |= TB_FLAG_AM_ENABLED;
  634. }
  635. if ((env->def->features & CPU_FEATURE_FLOAT) && (env->pstate & PS_PEF)
  636. && (env->fprs & FPRS_FEF)) {
  637. *flags |= TB_FLAG_FPU_ENABLED;
  638. }
  639. #else
  640. // FPU enable . Supervisor
  641. *flags = env->psrs;
  642. if ((env->def->features & CPU_FEATURE_FLOAT) && env->psref) {
  643. *flags |= TB_FLAG_FPU_ENABLED;
  644. }
  645. #endif
  646. }
  647. static inline bool tb_fpu_enabled(int tb_flags)
  648. {
  649. #if defined(CONFIG_USER_ONLY)
  650. return true;
  651. #else
  652. return tb_flags & TB_FLAG_FPU_ENABLED;
  653. #endif
  654. }
  655. static inline bool tb_am_enabled(int tb_flags)
  656. {
  657. #ifndef TARGET_SPARC64
  658. return false;
  659. #else
  660. return tb_flags & TB_FLAG_AM_ENABLED;
  661. #endif
  662. }
  663. #include "exec/exec-all.h"
  664. #endif