blob: b9369398f24b624bb7c9724ab4a0cf972a80fb92 [file] [log] [blame]
Markus Armbruster07f5a252016-06-29 11:05:55 +02001#ifndef SPARC_CPU_H
2#define SPARC_CPU_H
bellard7a3f1942003-09-30 20:36:07 +00003
Paolo Bonzini1de7afc2012-12-17 18:20:00 +01004#include "qemu/bswap.h"
Paolo Bonzinid61d1b22016-03-15 13:49:25 +01005#include "cpu-qom.h"
Richard Henderson74433bf2019-03-22 11:51:19 -07006#include "exec/cpu-defs.h"
bellardaf7bf892005-01-30 22:39:04 +00007
8#if !defined(TARGET_SPARC64)
Richard Henderson30038fd2011-10-17 10:42:49 -07009#define TARGET_DPREGS 16
Richard Henderson058ed882010-04-17 16:25:06 +000010#else
Richard Henderson30038fd2011-10-17 10:42:49 -070011#define TARGET_DPREGS 32
bellardaf7bf892005-01-30 22:39:04 +000012#endif
bellard3cf1e032004-01-24 15:19:09 +000013
bellard7a3f1942003-09-30 20:36:07 +000014/*#define EXCP_INTERRUPT 0x100*/
15
Richard Hendersonf8a74592019-11-06 12:33:09 +010016/* Windowed register indexes. */
17enum {
18 WREG_O0,
19 WREG_O1,
20 WREG_O2,
21 WREG_O3,
22 WREG_O4,
23 WREG_O5,
24 WREG_O6,
25 WREG_O7,
26
27 WREG_L0,
28 WREG_L1,
29 WREG_L2,
30 WREG_L3,
31 WREG_L4,
32 WREG_L5,
33 WREG_L6,
34 WREG_L7,
35
36 WREG_I0,
37 WREG_I1,
38 WREG_I2,
39 WREG_I3,
40 WREG_I4,
41 WREG_I5,
42 WREG_I6,
43 WREG_I7,
44
45 WREG_SP = WREG_O6,
46 WREG_FP = WREG_I6,
47};
48
bellardcf495bc2004-01-04 15:01:44 +000049/* trap definitions */
bellard34751872005-07-02 14:31:34 +000050#ifndef TARGET_SPARC64
bellard878d3092005-02-13 19:02:42 +000051#define TT_TFAULT 0x01
bellardcf495bc2004-01-04 15:01:44 +000052#define TT_ILL_INSN 0x02
bellarde8af50a2004-09-30 21:55:55 +000053#define TT_PRIV_INSN 0x03
bellarde80cfcf2004-12-19 23:18:01 +000054#define TT_NFPU_INSN 0x04
bellardcf495bc2004-01-04 15:01:44 +000055#define TT_WIN_OVF 0x05
ths5fafdf22007-09-16 21:08:06 +000056#define TT_WIN_UNF 0x06
blueswir1d2889a32007-04-13 15:46:16 +000057#define TT_UNALIGNED 0x07
bellarde8af50a2004-09-30 21:55:55 +000058#define TT_FP_EXCP 0x08
bellard878d3092005-02-13 19:02:42 +000059#define TT_DFAULT 0x09
blueswir1e32f8792007-03-23 20:01:20 +000060#define TT_TOVF 0x0a
bellard878d3092005-02-13 19:02:42 +000061#define TT_EXTINT 0x10
blueswir11b2e93c2007-05-27 19:36:00 +000062#define TT_CODE_ACCESS 0x21
blueswir164a88d52008-05-09 20:13:43 +000063#define TT_UNIMP_FLUSH 0x25
blueswir1b4f0a312007-05-06 17:59:24 +000064#define TT_DATA_ACCESS 0x29
bellardcf495bc2004-01-04 15:01:44 +000065#define TT_DIV_ZERO 0x2a
blueswir1fcc72042007-04-01 15:08:21 +000066#define TT_NCP_INSN 0x24
bellardcf495bc2004-01-04 15:01:44 +000067#define TT_TRAP 0x80
bellard34751872005-07-02 14:31:34 +000068#else
Igor Kovalenko8194f352009-08-03 23:15:02 +040069#define TT_POWER_ON_RESET 0x01
bellard34751872005-07-02 14:31:34 +000070#define TT_TFAULT 0x08
blueswir11b2e93c2007-05-27 19:36:00 +000071#define TT_CODE_ACCESS 0x0a
bellard34751872005-07-02 14:31:34 +000072#define TT_ILL_INSN 0x10
blueswir164a88d52008-05-09 20:13:43 +000073#define TT_UNIMP_FLUSH TT_ILL_INSN
bellard34751872005-07-02 14:31:34 +000074#define TT_PRIV_INSN 0x11
75#define TT_NFPU_INSN 0x20
76#define TT_FP_EXCP 0x21
blueswir1e32f8792007-03-23 20:01:20 +000077#define TT_TOVF 0x23
bellard34751872005-07-02 14:31:34 +000078#define TT_CLRWIN 0x24
79#define TT_DIV_ZERO 0x28
80#define TT_DFAULT 0x30
blueswir1b4f0a312007-05-06 17:59:24 +000081#define TT_DATA_ACCESS 0x32
blueswir1d2889a32007-04-13 15:46:16 +000082#define TT_UNALIGNED 0x34
bellard83469012005-07-23 14:27:54 +000083#define TT_PRIV_ACT 0x37
Artyom Tarasenko1ceca922012-01-23 14:31:21 +010084#define TT_INSN_REAL_TRANSLATION_MISS 0x3e
85#define TT_DATA_REAL_TRANSLATION_MISS 0x3f
bellard34751872005-07-02 14:31:34 +000086#define TT_EXTINT 0x40
blueswir174b9dec2008-07-21 18:43:32 +000087#define TT_IVEC 0x60
blueswir1e19e4ef2008-07-16 16:55:52 +000088#define TT_TMISS 0x64
89#define TT_DMISS 0x68
blueswir174b9dec2008-07-21 18:43:32 +000090#define TT_DPROT 0x6c
bellard34751872005-07-02 14:31:34 +000091#define TT_SPILL 0x80
92#define TT_FILL 0xc0
Igor V. Kovalenko88c8e032010-05-16 04:11:29 +040093#define TT_WOTHER (1 << 5)
bellard34751872005-07-02 14:31:34 +000094#define TT_TRAP 0x100
Artyom Tarasenko6e040752016-06-07 18:33:53 +020095#define TT_HTRAP 0x180
bellard34751872005-07-02 14:31:34 +000096#endif
bellard7a3f1942003-09-30 20:36:07 +000097
blueswir14b8b8b72008-04-23 17:12:35 +000098#define PSR_NEG_SHIFT 23
99#define PSR_NEG (1 << PSR_NEG_SHIFT)
100#define PSR_ZERO_SHIFT 22
101#define PSR_ZERO (1 << PSR_ZERO_SHIFT)
102#define PSR_OVF_SHIFT 21
103#define PSR_OVF (1 << PSR_OVF_SHIFT)
104#define PSR_CARRY_SHIFT 20
105#define PSR_CARRY (1 << PSR_CARRY_SHIFT)
bellarde8af50a2004-09-30 21:55:55 +0000106#define PSR_ICC (PSR_NEG|PSR_ZERO|PSR_OVF|PSR_CARRY)
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400107#if !defined(TARGET_SPARC64)
bellarde80cfcf2004-12-19 23:18:01 +0000108#define PSR_EF (1<<12)
109#define PSR_PIL 0xf00
bellarde8af50a2004-09-30 21:55:55 +0000110#define PSR_S (1<<7)
111#define PSR_PS (1<<6)
112#define PSR_ET (1<<5)
113#define PSR_CWP 0x1f
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400114#endif
bellarde8af50a2004-09-30 21:55:55 +0000115
Blue Swirl83936172009-05-10 07:19:11 +0000116#define CC_SRC (env->cc_src)
117#define CC_SRC2 (env->cc_src2)
118#define CC_DST (env->cc_dst)
119#define CC_OP (env->cc_op)
120
Paolo Bonzinic3ce5a22016-10-06 15:10:57 +0200121/* Even though lazy evaluation of CPU condition codes tends to be less
122 * important on RISC systems where condition codes are only updated
123 * when explicitly requested, SPARC uses it to update 32-bit and 64-bit
124 * condition codes.
125 */
Blue Swirl83936172009-05-10 07:19:11 +0000126enum {
127 CC_OP_DYNAMIC, /* must use dynamic code to get cc_op */
128 CC_OP_FLAGS, /* all cc are back in status register */
129 CC_OP_DIV, /* modify N, Z and V, C = 0*/
130 CC_OP_ADD, /* modify all flags, CC_DST = res, CC_SRC = src1 */
131 CC_OP_ADDX, /* modify all flags, CC_DST = res, CC_SRC = src1 */
132 CC_OP_TADD, /* modify all flags, CC_DST = res, CC_SRC = src1 */
133 CC_OP_TADDTV, /* modify all flags except V, CC_DST = res, CC_SRC = src1 */
134 CC_OP_SUB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
135 CC_OP_SUBX, /* modify all flags, CC_DST = res, CC_SRC = src1 */
136 CC_OP_TSUB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
137 CC_OP_TSUBTV, /* modify all flags except V, CC_DST = res, CC_SRC = src1 */
138 CC_OP_LOGIC, /* modify N and Z, C = V = 0, CC_DST = res */
139 CC_OP_NB,
140};
141
bellarde8af50a2004-09-30 21:55:55 +0000142/* Trap base register */
143#define TBR_BASE_MASK 0xfffff000
144
bellard34751872005-07-02 14:31:34 +0000145#if defined(TARGET_SPARC64)
Igor Kovalenko52109772009-07-12 12:35:31 +0400146#define PS_TCT (1<<12) /* UA2007, impl.dep. trap on control transfer */
147#define PS_IG (1<<11) /* v9, zero on UA2007 */
148#define PS_MG (1<<10) /* v9, zero on UA2007 */
149#define PS_CLE (1<<9) /* UA2007 */
150#define PS_TLE (1<<8) /* UA2007 */
blueswir16ef905f2007-07-07 20:48:42 +0000151#define PS_RMO (1<<7)
Igor Kovalenko52109772009-07-12 12:35:31 +0400152#define PS_RED (1<<5) /* v9, zero on UA2007 */
153#define PS_PEF (1<<4) /* enable fpu */
154#define PS_AM (1<<3) /* address mask */
bellard34751872005-07-02 14:31:34 +0000155#define PS_PRIV (1<<2)
156#define PS_IE (1<<1)
Igor Kovalenko52109772009-07-12 12:35:31 +0400157#define PS_AG (1<<0) /* v9, zero on UA2007 */
bellarda80dde02006-06-26 19:53:29 +0000158
159#define FPRS_FEF (1<<2)
blueswir16f27aba2007-10-14 17:07:21 +0000160
161#define HS_PRIV (1<<2)
bellard34751872005-07-02 14:31:34 +0000162#endif
163
bellarde8af50a2004-09-30 21:55:55 +0000164/* Fcc */
blueswir1ba6a9d82008-08-29 21:03:31 +0000165#define FSR_RD1 (1ULL << 31)
166#define FSR_RD0 (1ULL << 30)
bellarde8af50a2004-09-30 21:55:55 +0000167#define FSR_RD_MASK (FSR_RD1 | FSR_RD0)
168#define FSR_RD_NEAREST 0
169#define FSR_RD_ZERO FSR_RD0
170#define FSR_RD_POS FSR_RD1
171#define FSR_RD_NEG (FSR_RD1 | FSR_RD0)
172
blueswir1ba6a9d82008-08-29 21:03:31 +0000173#define FSR_NVM (1ULL << 27)
174#define FSR_OFM (1ULL << 26)
175#define FSR_UFM (1ULL << 25)
176#define FSR_DZM (1ULL << 24)
177#define FSR_NXM (1ULL << 23)
bellarde8af50a2004-09-30 21:55:55 +0000178#define FSR_TEM_MASK (FSR_NVM | FSR_OFM | FSR_UFM | FSR_DZM | FSR_NXM)
179
blueswir1ba6a9d82008-08-29 21:03:31 +0000180#define FSR_NVA (1ULL << 9)
181#define FSR_OFA (1ULL << 8)
182#define FSR_UFA (1ULL << 7)
183#define FSR_DZA (1ULL << 6)
184#define FSR_NXA (1ULL << 5)
bellarde8af50a2004-09-30 21:55:55 +0000185#define FSR_AEXC_MASK (FSR_NVA | FSR_OFA | FSR_UFA | FSR_DZA | FSR_NXA)
186
blueswir1ba6a9d82008-08-29 21:03:31 +0000187#define FSR_NVC (1ULL << 4)
188#define FSR_OFC (1ULL << 3)
189#define FSR_UFC (1ULL << 2)
190#define FSR_DZC (1ULL << 1)
191#define FSR_NXC (1ULL << 0)
bellarde8af50a2004-09-30 21:55:55 +0000192#define FSR_CEXC_MASK (FSR_NVC | FSR_OFC | FSR_UFC | FSR_DZC | FSR_NXC)
193
blueswir1ba6a9d82008-08-29 21:03:31 +0000194#define FSR_FTT2 (1ULL << 16)
195#define FSR_FTT1 (1ULL << 15)
196#define FSR_FTT0 (1ULL << 14)
blueswir147ad35f2008-09-06 17:50:16 +0000197//gcc warns about constant overflow for ~FSR_FTT_MASK
198//#define FSR_FTT_MASK (FSR_FTT2 | FSR_FTT1 | FSR_FTT0)
199#ifdef TARGET_SPARC64
200#define FSR_FTT_NMASK 0xfffffffffffe3fffULL
201#define FSR_FTT_CEXC_NMASK 0xfffffffffffe3fe0ULL
blueswir13a3b9252008-09-09 19:02:49 +0000202#define FSR_LDFSR_OLDMASK 0x0000003f000fc000ULL
203#define FSR_LDXFSR_MASK 0x0000003fcfc00fffULL
204#define FSR_LDXFSR_OLDMASK 0x00000000000fc000ULL
blueswir147ad35f2008-09-06 17:50:16 +0000205#else
206#define FSR_FTT_NMASK 0xfffe3fffULL
207#define FSR_FTT_CEXC_NMASK 0xfffe3fe0ULL
blueswir13a3b9252008-09-09 19:02:49 +0000208#define FSR_LDFSR_OLDMASK 0x000fc000ULL
blueswir147ad35f2008-09-06 17:50:16 +0000209#endif
blueswir13a3b9252008-09-09 19:02:49 +0000210#define FSR_LDFSR_MASK 0xcfc00fffULL
blueswir1ba6a9d82008-08-29 21:03:31 +0000211#define FSR_FTT_IEEE_EXCP (1ULL << 14)
212#define FSR_FTT_UNIMPFPOP (3ULL << 14)
213#define FSR_FTT_SEQ_ERROR (4ULL << 14)
214#define FSR_FTT_INVAL_FPR (6ULL << 14)
bellarde8af50a2004-09-30 21:55:55 +0000215
blueswir14b8b8b72008-04-23 17:12:35 +0000216#define FSR_FCC1_SHIFT 11
blueswir1ba6a9d82008-08-29 21:03:31 +0000217#define FSR_FCC1 (1ULL << FSR_FCC1_SHIFT)
blueswir14b8b8b72008-04-23 17:12:35 +0000218#define FSR_FCC0_SHIFT 10
blueswir1ba6a9d82008-08-29 21:03:31 +0000219#define FSR_FCC0 (1ULL << FSR_FCC0_SHIFT)
bellarde8af50a2004-09-30 21:55:55 +0000220
221/* MMU */
blueswir10f8a2492007-09-20 14:54:22 +0000222#define MMU_E (1<<0)
223#define MMU_NF (1<<1)
bellarde8af50a2004-09-30 21:55:55 +0000224
225#define PTE_ENTRYTYPE_MASK 3
226#define PTE_ACCESS_MASK 0x1c
227#define PTE_ACCESS_SHIFT 2
bellard8d5f07f2004-10-04 21:23:09 +0000228#define PTE_PPN_SHIFT 7
bellarde8af50a2004-09-30 21:55:55 +0000229#define PTE_ADDR_MASK 0xffffff00
230
blueswir10f8a2492007-09-20 14:54:22 +0000231#define PG_ACCESSED_BIT 5
232#define PG_MODIFIED_BIT 6
bellarde8af50a2004-09-30 21:55:55 +0000233#define PG_CACHE_BIT 7
234
235#define PG_ACCESSED_MASK (1 << PG_ACCESSED_BIT)
236#define PG_MODIFIED_MASK (1 << PG_MODIFIED_BIT)
237#define PG_CACHE_MASK (1 << PG_CACHE_BIT)
238
blueswir11a140262008-06-07 08:07:37 +0000239/* 3 <= NWINDOWS <= 32. */
240#define MIN_NWINDOWS 3
241#define MAX_NWINDOWS 32
bellardcf495bc2004-01-04 15:01:44 +0000242
Richard Henderson74433bf2019-03-22 11:51:19 -0700243#ifdef TARGET_SPARC64
blueswir1375ee382008-03-05 17:59:48 +0000244typedef struct trap_state {
245 uint64_t tpc;
246 uint64_t tnpc;
247 uint64_t tstate;
248 uint32_t tt;
249} trap_state;
blueswir16f27aba2007-10-14 17:07:21 +0000250#endif
Richard Hendersona3d5ad72015-08-31 13:30:52 -0700251#define TARGET_INSN_START_EXTRA_WORDS 1
j_mayer6ebbf392007-10-14 07:07:08 +0000252
Dr. David Alan Gilbert9d81b2d2017-09-14 13:36:09 +0100253struct sparc_def_t {
blueswir15578cea2008-08-21 17:33:42 +0000254 const char *name;
255 target_ulong iu_version;
256 uint32_t fpu_version;
257 uint32_t mmu_version;
258 uint32_t mmu_bm;
259 uint32_t mmu_ctpr_mask;
260 uint32_t mmu_cxr_mask;
261 uint32_t mmu_sfsr_mask;
262 uint32_t mmu_trcr_mask;
blueswir1963262d2008-12-23 15:06:35 +0000263 uint32_t mxcc_version;
blueswir15578cea2008-08-21 17:33:42 +0000264 uint32_t features;
265 uint32_t nwindows;
266 uint32_t maxtl;
Dr. David Alan Gilbert9d81b2d2017-09-14 13:36:09 +0100267};
blueswir15578cea2008-08-21 17:33:42 +0000268
Fabien Chouteaub04d9892011-01-24 12:56:55 +0100269#define CPU_FEATURE_FLOAT (1 << 0)
270#define CPU_FEATURE_FLOAT128 (1 << 1)
271#define CPU_FEATURE_SWAP (1 << 2)
272#define CPU_FEATURE_MUL (1 << 3)
273#define CPU_FEATURE_DIV (1 << 4)
274#define CPU_FEATURE_FLUSH (1 << 5)
275#define CPU_FEATURE_FSQRT (1 << 6)
276#define CPU_FEATURE_FMUL (1 << 7)
277#define CPU_FEATURE_VIS1 (1 << 8)
278#define CPU_FEATURE_VIS2 (1 << 9)
279#define CPU_FEATURE_FSMULD (1 << 10)
280#define CPU_FEATURE_HYPV (1 << 11)
281#define CPU_FEATURE_CMT (1 << 12)
282#define CPU_FEATURE_GL (1 << 13)
283#define CPU_FEATURE_TA0_SHUTDOWN (1 << 14) /* Shutdown on "ta 0x0" */
Fabien Chouteau4a2ba232011-01-24 12:56:56 +0100284#define CPU_FEATURE_ASR17 (1 << 15)
Fabien Chouteau60f356e2011-01-31 11:36:54 +0100285#define CPU_FEATURE_CACHE_CTRL (1 << 16)
Ronald Hechtd1c36ba2013-02-19 12:45:07 +0100286#define CPU_FEATURE_POWERDOWN (1 << 17)
Sebastian Huber16c358e2014-03-11 10:36:00 +0100287#define CPU_FEATURE_CASA (1 << 18)
Fabien Chouteau60f356e2011-01-31 11:36:54 +0100288
blueswir15578cea2008-08-21 17:33:42 +0000289#ifndef TARGET_SPARC64
290#define CPU_DEFAULT_FEATURES (CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | \
291 CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
292 CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | \
293 CPU_FEATURE_FMUL | CPU_FEATURE_FSMULD)
294#else
295#define CPU_DEFAULT_FEATURES (CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | \
296 CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
297 CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | \
298 CPU_FEATURE_FMUL | CPU_FEATURE_VIS1 | \
Sebastian Huber16c358e2014-03-11 10:36:00 +0100299 CPU_FEATURE_VIS2 | CPU_FEATURE_FSMULD | \
300 CPU_FEATURE_CASA)
blueswir15578cea2008-08-21 17:33:42 +0000301enum {
302 mmu_us_12, // Ultrasparc < III (64 entry TLB)
303 mmu_us_3, // Ultrasparc III (512 entry TLB)
304 mmu_us_4, // Ultrasparc IV (several TLBs, 32 and 256MB pages)
305 mmu_sun4v, // T1, T2
306};
307#endif
308
Igor Kovalenkof7077262009-07-27 01:57:39 +0400309#define TTE_VALID_BIT (1ULL << 63)
Tsuneo Saitod1afc482011-07-22 00:16:33 +0900310#define TTE_NFO_BIT (1ULL << 60)
Tony Nguyenccdb4c52019-08-24 04:36:58 +1000311#define TTE_IE_BIT (1ULL << 59)
Igor Kovalenkof7077262009-07-27 01:57:39 +0400312#define TTE_USED_BIT (1ULL << 41)
313#define TTE_LOCKED_BIT (1ULL << 6)
Tsuneo Saitod1afc482011-07-22 00:16:33 +0900314#define TTE_SIDEEFFECT_BIT (1ULL << 3)
Tsuneo Saito06e12b62011-07-22 00:16:27 +0900315#define TTE_PRIV_BIT (1ULL << 2)
316#define TTE_W_OK_BIT (1ULL << 1)
Blue Swirl2a903582009-12-05 11:14:55 +0000317#define TTE_GLOBAL_BIT (1ULL << 0)
Igor Kovalenkof7077262009-07-27 01:57:39 +0400318
Artyom Tarasenkoc2c7f862016-03-02 13:22:27 +0100319#define TTE_NFO_BIT_UA2005 (1ULL << 62)
320#define TTE_USED_BIT_UA2005 (1ULL << 47)
321#define TTE_LOCKED_BIT_UA2005 (1ULL << 61)
322#define TTE_SIDEEFFECT_BIT_UA2005 (1ULL << 11)
323#define TTE_PRIV_BIT_UA2005 (1ULL << 8)
324#define TTE_W_OK_BIT_UA2005 (1ULL << 6)
325
Igor Kovalenkof7077262009-07-27 01:57:39 +0400326#define TTE_IS_VALID(tte) ((tte) & TTE_VALID_BIT)
Tsuneo Saitod1afc482011-07-22 00:16:33 +0900327#define TTE_IS_NFO(tte) ((tte) & TTE_NFO_BIT)
Tony Nguyenccdb4c52019-08-24 04:36:58 +1000328#define TTE_IS_IE(tte) ((tte) & TTE_IE_BIT)
Igor Kovalenkof7077262009-07-27 01:57:39 +0400329#define TTE_IS_USED(tte) ((tte) & TTE_USED_BIT)
330#define TTE_IS_LOCKED(tte) ((tte) & TTE_LOCKED_BIT)
Tsuneo Saitod1afc482011-07-22 00:16:33 +0900331#define TTE_IS_SIDEEFFECT(tte) ((tte) & TTE_SIDEEFFECT_BIT)
Artyom Tarasenkoc2c7f862016-03-02 13:22:27 +0100332#define TTE_IS_SIDEEFFECT_UA2005(tte) ((tte) & TTE_SIDEEFFECT_BIT_UA2005)
Tsuneo Saito06e12b62011-07-22 00:16:27 +0900333#define TTE_IS_PRIV(tte) ((tte) & TTE_PRIV_BIT)
334#define TTE_IS_W_OK(tte) ((tte) & TTE_W_OK_BIT)
Artyom Tarasenkoc2c7f862016-03-02 13:22:27 +0100335
336#define TTE_IS_NFO_UA2005(tte) ((tte) & TTE_NFO_BIT_UA2005)
337#define TTE_IS_USED_UA2005(tte) ((tte) & TTE_USED_BIT_UA2005)
338#define TTE_IS_LOCKED_UA2005(tte) ((tte) & TTE_LOCKED_BIT_UA2005)
339#define TTE_IS_SIDEEFFECT_UA2005(tte) ((tte) & TTE_SIDEEFFECT_BIT_UA2005)
340#define TTE_IS_PRIV_UA2005(tte) ((tte) & TTE_PRIV_BIT_UA2005)
341#define TTE_IS_W_OK_UA2005(tte) ((tte) & TTE_W_OK_BIT_UA2005)
342
Blue Swirl2a903582009-12-05 11:14:55 +0000343#define TTE_IS_GLOBAL(tte) ((tte) & TTE_GLOBAL_BIT)
Igor Kovalenkof7077262009-07-27 01:57:39 +0400344
345#define TTE_SET_USED(tte) ((tte) |= TTE_USED_BIT)
346#define TTE_SET_UNUSED(tte) ((tte) &= ~TTE_USED_BIT)
347
Tsuneo Saito06e12b62011-07-22 00:16:27 +0900348#define TTE_PGSIZE(tte) (((tte) >> 61) & 3ULL)
Artyom Tarasenkoc2c7f862016-03-02 13:22:27 +0100349#define TTE_PGSIZE_UA2005(tte) ((tte) & 7ULL)
Tsuneo Saito06e12b62011-07-22 00:16:27 +0900350#define TTE_PA(tte) ((tte) & 0x1ffffffe000ULL)
351
Artyom Tarasenko5b5352b2016-06-10 10:44:15 +0200352/* UltraSPARC T1 specific */
353#define TLB_UST1_IS_REAL_BIT (1ULL << 9) /* Real translation entry */
354#define TLB_UST1_IS_SUN4V_BIT (1ULL << 10) /* sun4u/sun4v TTE format switch */
355
Tsuneo Saitoccc76c22011-07-22 00:16:28 +0900356#define SFSR_NF_BIT (1ULL << 24) /* JPS1 NoFault */
357#define SFSR_TM_BIT (1ULL << 15) /* JPS1 TLB Miss */
358#define SFSR_FT_VA_IMMU_BIT (1ULL << 13) /* USIIi VA out of range (IMMU) */
359#define SFSR_FT_VA_DMMU_BIT (1ULL << 12) /* USIIi VA out of range (DMMU) */
360#define SFSR_FT_NFO_BIT (1ULL << 11) /* NFO page access */
361#define SFSR_FT_ILL_BIT (1ULL << 10) /* illegal LDA/STA ASI */
362#define SFSR_FT_ATOMIC_BIT (1ULL << 9) /* atomic op on noncacheable area */
363#define SFSR_FT_NF_E_BIT (1ULL << 8) /* NF access on side effect area */
364#define SFSR_FT_PRIV_BIT (1ULL << 7) /* privilege violation */
365#define SFSR_PR_BIT (1ULL << 3) /* privilege mode */
366#define SFSR_WRITE_BIT (1ULL << 2) /* write access mode */
367#define SFSR_OW_BIT (1ULL << 1) /* status overwritten */
368#define SFSR_VALID_BIT (1ULL << 0) /* status valid */
369
370#define SFSR_ASI_SHIFT 16 /* 23:16 ASI value */
371#define SFSR_ASI_MASK (0xffULL << SFSR_ASI_SHIFT)
372#define SFSR_CT_PRIMARY (0ULL << 4) /* 5:4 context type */
373#define SFSR_CT_SECONDARY (1ULL << 4)
374#define SFSR_CT_NUCLEUS (2ULL << 4)
375#define SFSR_CT_NOTRANS (3ULL << 4)
376#define SFSR_CT_MASK (3ULL << 4)
377
Blue Swirl79227032011-08-01 09:20:58 +0000378/* Leon3 cache control */
379
380/* Cache control: emulate the behavior of cache control registers but without
381 any effect on the emulated */
382
383#define CACHE_STATE_MASK 0x3
384#define CACHE_DISABLED 0x0
385#define CACHE_FROZEN 0x1
386#define CACHE_ENABLED 0x3
387
388/* Cache Control register fields */
389
390#define CACHE_CTRL_IF (1 << 4) /* Instruction Cache Freeze on Interrupt */
391#define CACHE_CTRL_DF (1 << 5) /* Data Cache Freeze on Interrupt */
392#define CACHE_CTRL_DP (1 << 14) /* Data cache flush pending */
393#define CACHE_CTRL_IP (1 << 15) /* Instruction cache flush pending */
394#define CACHE_CTRL_IB (1 << 16) /* Instruction burst fetch */
395#define CACHE_CTRL_FI (1 << 21) /* Flush Instruction cache (Write only) */
396#define CACHE_CTRL_FD (1 << 22) /* Flush Data cache (Write only) */
397#define CACHE_CTRL_DS (1 << 23) /* Data cache snoop enable */
398
Artyom Tarasenko7285fba2016-06-03 21:45:05 +0200399#define CONVERT_BIT(X, SRC, DST) \
400 (SRC > DST ? (X) / (SRC / DST) & (DST) : ((X) & SRC) * (DST / SRC))
401
Igor Kovalenko6e8e7d42009-07-27 01:49:04 +0400402typedef struct SparcTLBEntry {
403 uint64_t tag;
404 uint64_t tte;
405} SparcTLBEntry;
406
Igor V. Kovalenko8f4efc52010-01-28 00:00:53 +0300407struct CPUTimer
408{
409 const char *name;
410 uint32_t frequency;
411 uint32_t disabled;
412 uint64_t disabled_mask;
Mark Cave-Aylande913cac2015-11-08 12:27:38 +0000413 uint32_t npt;
414 uint64_t npt_mask;
Igor V. Kovalenko8f4efc52010-01-28 00:00:53 +0300415 int64_t clock_offset;
Stefan Weil1246b252013-12-01 08:49:47 +0100416 QEMUTimer *qtimer;
Igor V. Kovalenko8f4efc52010-01-28 00:00:53 +0300417};
418
419typedef struct CPUTimer CPUTimer;
420
Andreas Färbercb159822012-02-24 17:15:27 +0100421typedef struct CPUSPARCState CPUSPARCState;
Artyom Tarasenko96df2bc2016-02-09 12:07:48 +0100422#if defined(TARGET_SPARC64)
423typedef union {
424 uint64_t mmuregs[16];
425 struct {
426 uint64_t tsb_tag_target;
427 uint64_t mmu_primary_context;
428 uint64_t mmu_secondary_context;
429 uint64_t sfsr;
430 uint64_t sfar;
431 uint64_t tsb;
432 uint64_t tag_access;
433 uint64_t virtual_watchpoint;
434 uint64_t physical_watchpoint;
Artyom Tarasenko15f746c2016-02-09 10:58:49 +0100435 uint64_t sun4v_ctx_config[2];
436 uint64_t sun4v_tsb_pointers[4];
Artyom Tarasenko96df2bc2016-02-09 12:07:48 +0100437 };
438} SparcV9MMU;
439#endif
Andreas Färbercb159822012-02-24 17:15:27 +0100440struct CPUSPARCState {
bellardaf7bf892005-01-30 22:39:04 +0000441 target_ulong gregs[8]; /* general registers */
442 target_ulong *regwptr; /* pointer to current register window */
bellardaf7bf892005-01-30 22:39:04 +0000443 target_ulong pc; /* program counter */
444 target_ulong npc; /* next program counter */
445 target_ulong y; /* multiply/divide register */
blueswir1dc99a3f2008-03-13 20:45:31 +0000446
447 /* emulator internal flags handling */
blueswir1d9bdab82008-03-16 19:22:18 +0000448 target_ulong cc_src, cc_src2;
blueswir1dc99a3f2008-03-13 20:45:31 +0000449 target_ulong cc_dst;
Blue Swirl83936172009-05-10 07:19:11 +0000450 uint32_t cc_op;
blueswir1dc99a3f2008-03-13 20:45:31 +0000451
bellard7c60cc42008-05-10 10:58:20 +0000452 target_ulong cond; /* conditional branch result (XXX: save it in a
453 temporary register when possible) */
454
bellardcf495bc2004-01-04 15:01:44 +0000455 uint32_t psr; /* processor state register */
bellard34751872005-07-02 14:31:34 +0000456 target_ulong fsr; /* FPU state register */
Richard Henderson30038fd2011-10-17 10:42:49 -0700457 CPU_DoubleU fpr[TARGET_DPREGS]; /* floating point registers */
bellardcf495bc2004-01-04 15:01:44 +0000458 uint32_t cwp; /* index of current register window (extracted
459 from PSR) */
Igor Kovalenko52109772009-07-12 12:35:31 +0400460#if !defined(TARGET_SPARC64) || defined(TARGET_ABI32)
bellardcf495bc2004-01-04 15:01:44 +0000461 uint32_t wim; /* window invalid mask */
Igor Kovalenko52109772009-07-12 12:35:31 +0400462#endif
bellard34751872005-07-02 14:31:34 +0000463 target_ulong tbr; /* trap base register */
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400464#if !defined(TARGET_SPARC64)
bellarde8af50a2004-09-30 21:55:55 +0000465 int psrs; /* supervisor mode (extracted from PSR) */
466 int psrps; /* previous supervisor mode */
467 int psret; /* enable traps */
Igor Kovalenko52109772009-07-12 12:35:31 +0400468#endif
blueswir1327ac2e2007-08-04 10:50:30 +0000469 uint32_t psrpil; /* interrupt blocking level */
470 uint32_t pil_in; /* incoming interrupt level bitmap */
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400471#if !defined(TARGET_SPARC64)
bellarde80cfcf2004-12-19 23:18:01 +0000472 int psref; /* enable fpu */
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400473#endif
bellardcf495bc2004-01-04 15:01:44 +0000474 int interrupt_index;
bellardcf495bc2004-01-04 15:01:44 +0000475 /* NOTE: we allow 8 more registers to handle wrapping */
blueswir11a140262008-06-07 08:07:37 +0000476 target_ulong regbase[MAX_NWINDOWS * 16 + 8];
bellardd720b932004-04-25 17:57:43 +0000477
Alex Bennée1f5c00c2016-11-14 14:19:17 +0000478 /* Fields up to this point are cleared by a CPU reset */
479 struct {} end_reset_fields;
480
Andreas Färberf0c3c502013-08-26 21:22:53 +0200481 /* Fields from here on are preserved across CPU reset. */
Blue Swirl89aaf602012-03-10 17:55:05 +0000482 target_ulong version;
483 uint32_t nwindows;
484
bellarde8af50a2004-09-30 21:55:55 +0000485 /* MMU regs */
bellard34751872005-07-02 14:31:34 +0000486#if defined(TARGET_SPARC64)
487 uint64_t lsu;
488#define DMMU_E 0x8
489#define IMMU_E 0x4
Artyom Tarasenko96df2bc2016-02-09 12:07:48 +0100490 SparcV9MMU immu;
491 SparcV9MMU dmmu;
Igor Kovalenko6e8e7d42009-07-27 01:49:04 +0400492 SparcTLBEntry itlb[64];
493 SparcTLBEntry dtlb[64];
blueswir1fb79ceb2008-07-20 18:22:16 +0000494 uint32_t mmu_version;
bellard34751872005-07-02 14:31:34 +0000495#else
blueswir13dd9a152007-11-25 12:43:10 +0000496 uint32_t mmuregs[32];
blueswir1952a3282007-10-14 16:29:21 +0000497 uint64_t mxccdata[4];
498 uint64_t mxccregs[8];
Blue Swirl4d2c2b72011-06-18 20:27:05 +0000499 uint32_t mmubpctrv, mmubpctrc, mmubpctrs;
500 uint64_t mmubpaction;
blueswir140171902008-12-23 15:30:50 +0000501 uint64_t mmubpregs[4];
blueswir13ebf5aa2007-11-28 20:54:33 +0000502 uint64_t prom_addr;
bellard34751872005-07-02 14:31:34 +0000503#endif
bellarde8af50a2004-09-30 21:55:55 +0000504 /* temporary float registers */
blueswir11f587322007-11-25 18:40:20 +0000505 float128 qt0, qt1;
bellard7a0e1f42005-03-13 17:01:47 +0000506 float_status fp_status;
bellardaf7bf892005-01-30 22:39:04 +0000507#if defined(TARGET_SPARC64)
blueswir1c19148b2008-07-25 07:42:14 +0000508#define MAXTL_MAX 8
509#define MAXTL_MASK (MAXTL_MAX - 1)
blueswir1c19148b2008-07-25 07:42:14 +0000510 trap_state ts[MAXTL_MAX];
blueswir10f8a2492007-09-20 14:54:22 +0000511 uint32_t xcc; /* Extended integer condition codes */
bellard34751872005-07-02 14:31:34 +0000512 uint32_t asi;
513 uint32_t pstate;
514 uint32_t tl;
blueswir1c19148b2008-07-25 07:42:14 +0000515 uint32_t maxtl;
bellard34751872005-07-02 14:31:34 +0000516 uint32_t cansave, canrestore, otherwin, wstate, cleanwin;
bellard83469012005-07-23 14:27:54 +0000517 uint64_t agregs[8]; /* alternate general registers */
518 uint64_t bgregs[8]; /* backup for normal global registers */
519 uint64_t igregs[8]; /* interrupt general registers */
520 uint64_t mgregs[8]; /* mmu general registers */
Artyom Tarasenkocbc3a6a2016-06-07 18:34:49 +0200521 uint64_t glregs[8 * MAXTL_MAX];
bellard34751872005-07-02 14:31:34 +0000522 uint64_t fprs;
bellard83469012005-07-23 14:27:54 +0000523 uint64_t tick_cmpr, stick_cmpr;
Igor V. Kovalenko8f4efc52010-01-28 00:00:53 +0300524 CPUTimer *tick, *stick;
Igor V. Kovalenko709f2c12010-01-07 23:28:21 +0300525#define TICK_NPT_MASK 0x8000000000000000ULL
526#define TICK_INT_DIS 0x8000000000000000ULL
bellard725cb902006-07-18 21:12:17 +0000527 uint64_t gsr;
blueswir1e9ebed42007-04-22 19:14:52 +0000528 uint32_t gl; // UA2005
529 /* UA 2005 hyperprivileged registers */
blueswir1c19148b2008-07-25 07:42:14 +0000530 uint64_t hpstate, htstate[MAXTL_MAX], hintp, htba, hver, hstick_cmpr, ssr;
Artyom Tarasenko4ec3e342016-03-02 14:36:20 +0100531 uint64_t scratch[8];
Igor V. Kovalenko8f4efc52010-01-28 00:00:53 +0300532 CPUTimer *hstick; // UA 2005
Blue Swirl361dea42012-03-10 20:37:00 +0000533 /* Interrupt vector registers */
534 uint64_t ivec_status;
535 uint64_t ivec_data[3];
blueswir19d926592008-09-22 19:50:28 +0000536 uint32_t softint;
blueswir18fa211e2008-12-23 08:47:26 +0000537#define SOFTINT_TIMER 1
538#define SOFTINT_STIMER (1 << 16)
Igor V. Kovalenko709f2c12010-01-07 23:28:21 +0300539#define SOFTINT_INTRMASK (0xFFFE)
540#define SOFTINT_REG_MASK (SOFTINT_STIMER|SOFTINT_INTRMASK|SOFTINT_TIMER)
bellard34751872005-07-02 14:31:34 +0000541#endif
Igor Mammedov576e1c42017-08-24 18:31:26 +0200542 sparc_def_t def;
Fabien Chouteaub04d9892011-01-24 12:56:55 +0100543
544 void *irq_manager;
Andreas Färberc5f98642012-03-14 01:38:22 +0100545 void (*qemu_irq_ack)(CPUSPARCState *env, void *irq_manager, int intno);
Fabien Chouteaub04d9892011-01-24 12:56:55 +0100546
547 /* Leon3 cache control */
548 uint32_t cache_control;
Andreas Färbercb159822012-02-24 17:15:27 +0100549};
blueswir164a88d52008-05-09 20:13:43 +0000550
Paolo Bonzinid61d1b22016-03-15 13:49:25 +0100551/**
552 * SPARCCPU:
553 * @env: #CPUSPARCState
554 *
555 * A SPARC CPU.
556 */
557struct SPARCCPU {
558 /*< private >*/
559 CPUState parent_obj;
560 /*< public >*/
561
Richard Henderson5b146dc2019-03-22 17:16:06 -0700562 CPUNegativeOffsetState neg;
Paolo Bonzinid61d1b22016-03-15 13:49:25 +0100563 CPUSPARCState env;
564};
565
Paolo Bonzinid61d1b22016-03-15 13:49:25 +0100566
567#ifndef CONFIG_USER_ONLY
Markus Armbruster8a9358c2019-08-12 07:23:44 +0200568extern const VMStateDescription vmstate_sparc_cpu;
Paolo Bonzinid61d1b22016-03-15 13:49:25 +0100569#endif
570
571void sparc_cpu_do_interrupt(CPUState *cpu);
Markus Armbruster90c84c52019-04-17 21:18:02 +0200572void sparc_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
Paolo Bonzinid61d1b22016-03-15 13:49:25 +0100573hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
Alex Bennéea010bdb2020-03-16 17:21:41 +0000574int sparc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
Paolo Bonzinid61d1b22016-03-15 13:49:25 +0100575int sparc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
Sergey Sorokinb35399b2016-06-14 15:26:17 +0300576void QEMU_NORETURN sparc_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
577 MMUAccessType access_type,
578 int mmu_idx,
579 uintptr_t retaddr);
Richard Henderson2f9d35f2016-07-12 13:12:50 -0700580void cpu_raise_exception_ra(CPUSPARCState *, int, uintptr_t) QEMU_NORETURN;
Andreas Färbere59be772012-05-03 03:12:35 +0200581
Blue Swirl5a834bb2010-05-09 20:19:04 +0000582#ifndef NO_CPU_IO_DEFS
Blue Swirlab3b4912011-09-11 09:33:40 +0000583/* cpu_init.c */
blueswir191736d32008-08-29 20:50:21 +0000584void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu);
Markus Armbruster04424282019-04-17 21:17:57 +0200585void sparc_cpu_list(void);
Blue Swirl163fa5c2011-09-11 11:30:01 +0000586/* mmu_helper.c */
Richard Hendersone84942f2019-04-03 07:16:41 +0700587bool sparc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
588 MMUAccessType access_type, int mmu_idx,
589 bool probe, uintptr_t retaddr);
blueswir148585ec2008-10-03 19:02:42 +0000590target_ulong mmu_probe(CPUSPARCState *env, target_ulong address, int mmulev);
Markus Armbrusterfad866d2019-04-17 21:17:58 +0200591void dump_mmu(CPUSPARCState *env);
blueswir191736d32008-08-29 20:50:21 +0000592
Fabien Chouteau44520db2011-09-08 12:48:16 +0200593#if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
Andreas Färberf3659ee2013-06-27 19:09:09 +0200594int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
595 uint8_t *buf, int len, bool is_write);
Fabien Chouteau44520db2011-09-08 12:48:16 +0200596#endif
597
598
blueswir191736d32008-08-29 20:50:21 +0000599/* translate.c */
Richard Henderson55c3cee2017-10-15 19:02:42 -0700600void sparc_tcg_init(void);
blueswir191736d32008-08-29 20:50:21 +0000601
602/* cpu-exec.c */
bellard7a3f1942003-09-30 20:36:07 +0000603
Blue Swirl070af382011-08-01 09:03:20 +0000604/* win_helper.c */
Andreas Färberc5f98642012-03-14 01:38:22 +0100605target_ulong cpu_get_psr(CPUSPARCState *env1);
606void cpu_put_psr(CPUSPARCState *env1, target_ulong val);
Peter Maydell4552a092016-01-11 12:40:24 +0000607void cpu_put_psr_raw(CPUSPARCState *env1, target_ulong val);
Blue Swirl5a834bb2010-05-09 20:19:04 +0000608#ifdef TARGET_SPARC64
Andreas Färberc5f98642012-03-14 01:38:22 +0100609target_ulong cpu_get_ccr(CPUSPARCState *env1);
610void cpu_put_ccr(CPUSPARCState *env1, target_ulong val);
611target_ulong cpu_get_cwp64(CPUSPARCState *env1);
612void cpu_put_cwp64(CPUSPARCState *env1, int cwp);
613void cpu_change_pstate(CPUSPARCState *env1, uint32_t new_pstate);
Artyom Tarasenkocbc3a6a2016-06-07 18:34:49 +0200614void cpu_gl_switch_gregs(CPUSPARCState *env, uint32_t new_gl);
Igor Kovalenko52109772009-07-12 12:35:31 +0400615#endif
Andreas Färberc5f98642012-03-14 01:38:22 +0100616int cpu_cwp_inc(CPUSPARCState *env1, int cwp);
617int cpu_cwp_dec(CPUSPARCState *env1, int cwp);
618void cpu_set_cwp(CPUSPARCState *env1, int new_cwp);
Blue Swirl070af382011-08-01 09:03:20 +0000619
Blue Swirl79227032011-08-01 09:20:58 +0000620/* int_helper.c */
Andreas Färberc5f98642012-03-14 01:38:22 +0100621void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno);
Fabien Chouteaub04d9892011-01-24 12:56:55 +0100622
Blue Swirl4c6aa082009-08-22 11:54:03 +0000623/* sun4m.c, sun4u.c */
624void cpu_check_irqs(CPUSPARCState *env);
blueswir11a140262008-06-07 08:07:37 +0000625
Fabien Chouteau60f356e2011-01-31 11:36:54 +0100626/* leon3.c */
627void leon3_irq_ack(void *irq_manager, int intno);
628
Igor V. Kovalenko299b5202010-05-04 23:15:41 +0400629#if defined (TARGET_SPARC64)
630
631static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask)
632{
633 return (x & mask) == (y & mask);
634}
635
636#define MMU_CONTEXT_BITS 13
637#define MMU_CONTEXT_MASK ((1 << MMU_CONTEXT_BITS) - 1)
638
639static inline int tlb_compare_context(const SparcTLBEntry *tlb,
640 uint64_t context)
641{
642 return compare_masked(context, tlb->tag, MMU_CONTEXT_MASK);
643}
644
645#endif
bellard34751872005-07-02 14:31:34 +0000646#endif
647
blueswir191736d32008-08-29 20:50:21 +0000648/* cpu-exec.c */
Paul Brook3c7b48b2010-03-01 04:11:28 +0000649#if !defined(CONFIG_USER_ONLY)
Peter Maydellf8c3db32019-08-01 19:30:12 +0100650void sparc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
651 vaddr addr, unsigned size,
652 MMUAccessType access_type,
653 int mmu_idx, MemTxAttrs attrs,
654 MemTxResult response, uintptr_t retaddr);
Tsuneo Saitob64b6432011-07-22 00:16:30 +0900655#if defined(TARGET_SPARC64)
Avi Kivitya8170e52012-10-23 12:30:10 +0200656hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
Igor V. Kovalenko20650612010-05-03 11:29:44 +0400657 int mmu_idx);
Paul Brook3c7b48b2010-03-01 04:11:28 +0000658#endif
Tsuneo Saitob64b6432011-07-22 00:16:30 +0900659#endif
blueswir1f0d5e472008-09-20 09:05:49 +0000660int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
bellard7a3f1942003-09-30 20:36:07 +0000661
Igor Mammedov1d4bfc52017-10-05 15:51:05 +0200662#define SPARC_CPU_TYPE_SUFFIX "-" TYPE_SPARC_CPU
663#define SPARC_CPU_TYPE_NAME(model) model SPARC_CPU_TYPE_SUFFIX
Igor Mammedov0dacec82018-02-07 11:40:25 +0100664#define CPU_RESOLVING_TYPE TYPE_SPARC_CPU
Igor Mammedov1d4bfc52017-10-05 15:51:05 +0200665
ths9467d442007-06-03 21:02:38 +0000666#define cpu_signal_handler cpu_sparc_signal_handler
j_mayerc732abe2007-10-12 06:47:46 +0000667#define cpu_list sparc_cpu_list
ths9467d442007-06-03 21:02:38 +0000668
j_mayer6ebbf392007-10-14 07:07:08 +0000669/* MMU modes definitions */
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400670#if defined (TARGET_SPARC64)
blueswir19e31b9e2008-02-14 17:46:44 +0000671#define MMU_USER_IDX 0
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400672#define MMU_USER_SECONDARY_IDX 1
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400673#define MMU_KERNEL_IDX 2
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400674#define MMU_KERNEL_SECONDARY_IDX 3
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400675#define MMU_NUCLEUS_IDX 4
Artyom Tarasenko84f8f582016-06-09 10:16:03 +0200676#define MMU_PHYS_IDX 5
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400677#else
678#define MMU_USER_IDX 0
blueswir19e31b9e2008-02-14 17:46:44 +0000679#define MMU_KERNEL_IDX 1
Richard Hendersonaf7a06b2016-07-12 21:01:29 -0700680#define MMU_PHYS_IDX 2
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400681#endif
682
683#if defined (TARGET_SPARC64)
Andreas Färberc5f98642012-03-14 01:38:22 +0100684static inline int cpu_has_hypervisor(CPUSPARCState *env1)
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400685{
Igor Mammedov576e1c42017-08-24 18:31:26 +0200686 return env1->def.features & CPU_FEATURE_HYPV;
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400687}
688
Andreas Färberc5f98642012-03-14 01:38:22 +0100689static inline int cpu_hypervisor_mode(CPUSPARCState *env1)
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400690{
691 return cpu_has_hypervisor(env1) && (env1->hpstate & HS_PRIV);
692}
693
Andreas Färberc5f98642012-03-14 01:38:22 +0100694static inline int cpu_supervisor_mode(CPUSPARCState *env1)
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400695{
696 return env1->pstate & PS_PRIV;
697}
Artyom Tarasenkoc9b459a2016-11-01 21:57:01 +0100698#else
699static inline int cpu_supervisor_mode(CPUSPARCState *env1)
700{
701 return env1->psrs;
702}
Igor V. Kovalenko20650612010-05-03 11:29:44 +0400703#endif
blueswir19e31b9e2008-02-14 17:46:44 +0000704
Richard Hendersonaf7a06b2016-07-12 21:01:29 -0700705static inline int cpu_mmu_index(CPUSPARCState *env, bool ifetch)
j_mayer6ebbf392007-10-14 07:07:08 +0000706{
blueswir16f27aba2007-10-14 17:07:21 +0000707#if defined(CONFIG_USER_ONLY)
blueswir19e31b9e2008-02-14 17:46:44 +0000708 return MMU_USER_IDX;
blueswir16f27aba2007-10-14 17:07:21 +0000709#elif !defined(TARGET_SPARC64)
Richard Hendersonaf7a06b2016-07-12 21:01:29 -0700710 if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */
711 return MMU_PHYS_IDX;
712 } else {
713 return env->psrs;
714 }
blueswir16f27aba2007-10-14 17:07:21 +0000715#else
Richard Hendersonaf7a06b2016-07-12 21:01:29 -0700716 /* IMMU or DMMU disabled. */
717 if (ifetch
718 ? (env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0
719 : (env->lsu & DMMU_E) == 0) {
720 return MMU_PHYS_IDX;
Richard Hendersonaf7a06b2016-07-12 21:01:29 -0700721 } else if (cpu_hypervisor_mode(env)) {
Artyom Tarasenko84f8f582016-06-09 10:16:03 +0200722 return MMU_PHYS_IDX;
Artyom Tarasenko9a107562016-03-02 14:53:38 +0100723 } else if (env->tl > 0) {
724 return MMU_NUCLEUS_IDX;
Richard Hendersonaf7a06b2016-07-12 21:01:29 -0700725 } else if (cpu_supervisor_mode(env)) {
Igor V. Kovalenko2aae2b82010-05-22 14:52:24 +0400726 return MMU_KERNEL_IDX;
727 } else {
728 return MMU_USER_IDX;
729 }
blueswir16f27aba2007-10-14 17:07:21 +0000730#endif
731}
732
Andreas Färberc5f98642012-03-14 01:38:22 +0100733static inline int cpu_interrupts_enabled(CPUSPARCState *env1)
Igor V. Kovalenko2df6c2d2010-01-07 23:28:26 +0300734{
735#if !defined (TARGET_SPARC64)
736 if (env1->psret != 0)
737 return 1;
738#else
Artyom Tarasenko1a2aefa2016-06-12 22:19:43 +0200739 if ((env1->pstate & PS_IE) && !cpu_hypervisor_mode(env1)) {
Igor V. Kovalenko2df6c2d2010-01-07 23:28:26 +0300740 return 1;
Artyom Tarasenko1a2aefa2016-06-12 22:19:43 +0200741 }
Igor V. Kovalenko2df6c2d2010-01-07 23:28:26 +0300742#endif
743
744 return 0;
745}
746
Andreas Färberc5f98642012-03-14 01:38:22 +0100747static inline int cpu_pil_allowed(CPUSPARCState *env1, int pil)
Igor V. Kovalenkod532b262010-01-07 23:28:31 +0300748{
749#if !defined(TARGET_SPARC64)
750 /* level 15 is non-maskable on sparc v8 */
751 return pil == 15 || pil > env1->psrpil;
752#else
753 return pil > env1->psrpil;
754#endif
755}
756
Richard Henderson4f7c64b2019-03-22 15:32:23 -0700757typedef CPUSPARCState CPUArchState;
Richard Henderson2161a612019-03-22 15:56:19 -0700758typedef SPARCCPU ArchCPU;
Richard Henderson4f7c64b2019-03-22 15:32:23 -0700759
Paolo Bonzini022c62c2012-12-17 18:19:49 +0100760#include "exec/cpu-all.h"
bellard7a3f1942003-09-30 20:36:07 +0000761
blueswir1f4b1a842008-10-03 19:04:42 +0000762#ifdef TARGET_SPARC64
763/* sun4u.c */
Igor V. Kovalenko8f4efc52010-01-28 00:00:53 +0300764void cpu_tick_set_count(CPUTimer *timer, uint64_t count);
765uint64_t cpu_tick_get_count(CPUTimer *timer);
766void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit);
Andreas Färberc5f98642012-03-14 01:38:22 +0100767trap_state* cpu_tsptr(CPUSPARCState* env);
blueswir1f4b1a842008-10-03 19:04:42 +0000768#endif
769
Richard Henderson99a23062015-08-24 20:51:21 -0700770#define TB_FLAG_MMU_MASK 7
771#define TB_FLAG_FPU_ENABLED (1 << 4)
772#define TB_FLAG_AM_ENABLED (1 << 5)
Artyom Tarasenkoc9b459a2016-11-01 21:57:01 +0100773#define TB_FLAG_SUPER (1 << 6)
774#define TB_FLAG_HYPER (1 << 7)
Richard Hendersona6d567e2015-09-03 14:14:33 -0700775#define TB_FLAG_ASI_SHIFT 24
Blue Swirlf838e2c2011-07-14 17:30:43 +0000776
Andreas Färberc5f98642012-03-14 01:38:22 +0100777static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, target_ulong *pc,
Richard Henderson99a23062015-08-24 20:51:21 -0700778 target_ulong *cs_base, uint32_t *pflags)
aliguori6b917542008-11-18 19:46:41 +0000779{
Richard Henderson99a23062015-08-24 20:51:21 -0700780 uint32_t flags;
aliguori6b917542008-11-18 19:46:41 +0000781 *pc = env->pc;
782 *cs_base = env->npc;
Richard Henderson99a23062015-08-24 20:51:21 -0700783 flags = cpu_mmu_index(env, false);
Artyom Tarasenkoc9b459a2016-11-01 21:57:01 +0100784#ifndef CONFIG_USER_ONLY
785 if (cpu_supervisor_mode(env)) {
786 flags |= TB_FLAG_SUPER;
787 }
788#endif
aliguori6b917542008-11-18 19:46:41 +0000789#ifdef TARGET_SPARC64
Artyom Tarasenkoc9b459a2016-11-01 21:57:01 +0100790#ifndef CONFIG_USER_ONLY
791 if (cpu_hypervisor_mode(env)) {
792 flags |= TB_FLAG_HYPER;
793 }
794#endif
Blue Swirlf838e2c2011-07-14 17:30:43 +0000795 if (env->pstate & PS_AM) {
Richard Henderson99a23062015-08-24 20:51:21 -0700796 flags |= TB_FLAG_AM_ENABLED;
Blue Swirlf838e2c2011-07-14 17:30:43 +0000797 }
Igor Mammedov576e1c42017-08-24 18:31:26 +0200798 if ((env->def.features & CPU_FEATURE_FLOAT)
Richard Henderson99a23062015-08-24 20:51:21 -0700799 && (env->pstate & PS_PEF)
Blue Swirlf838e2c2011-07-14 17:30:43 +0000800 && (env->fprs & FPRS_FEF)) {
Richard Henderson99a23062015-08-24 20:51:21 -0700801 flags |= TB_FLAG_FPU_ENABLED;
Blue Swirlf838e2c2011-07-14 17:30:43 +0000802 }
Richard Hendersona6d567e2015-09-03 14:14:33 -0700803 flags |= env->asi << TB_FLAG_ASI_SHIFT;
aliguori6b917542008-11-18 19:46:41 +0000804#else
Igor Mammedov576e1c42017-08-24 18:31:26 +0200805 if ((env->def.features & CPU_FEATURE_FLOAT) && env->psref) {
Richard Henderson99a23062015-08-24 20:51:21 -0700806 flags |= TB_FLAG_FPU_ENABLED;
Blue Swirlf838e2c2011-07-14 17:30:43 +0000807 }
808#endif
Richard Henderson99a23062015-08-24 20:51:21 -0700809 *pflags = flags;
Blue Swirlf838e2c2011-07-14 17:30:43 +0000810}
811
812static inline bool tb_fpu_enabled(int tb_flags)
813{
814#if defined(CONFIG_USER_ONLY)
815 return true;
816#else
817 return tb_flags & TB_FLAG_FPU_ENABLED;
818#endif
819}
820
821static inline bool tb_am_enabled(int tb_flags)
822{
823#ifndef TARGET_SPARC64
824 return false;
825#else
826 return tb_flags & TB_FLAG_AM_ENABLED;
aliguori6b917542008-11-18 19:46:41 +0000827#endif
828}
829
bellard7a3f1942003-09-30 20:36:07 +0000830#endif