xref: /openbmc/qemu/target/sparc/cpu.h (revision a837ef2285c296cbff4a60c34a97af3cbf0a879e)
1fcf5ef2aSThomas Huth #ifndef SPARC_CPU_H
2fcf5ef2aSThomas Huth #define SPARC_CPU_H
3fcf5ef2aSThomas Huth 
4fcf5ef2aSThomas Huth #include "qemu/bswap.h"
5fcf5ef2aSThomas Huth #include "cpu-qom.h"
674433bf0SRichard Henderson #include "exec/cpu-defs.h"
769242e7eSMarc-André Lureau #include "qemu/cpu-float.h"
8fcf5ef2aSThomas Huth 
9fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64)
10fcf5ef2aSThomas Huth #define TARGET_DPREGS 16
11d8c5b92fSRichard Henderson #define TARGET_FCCREGS 1
12fcf5ef2aSThomas Huth #else
13fcf5ef2aSThomas Huth #define TARGET_DPREGS 32
14d8c5b92fSRichard Henderson #define TARGET_FCCREGS 4
15fcf5ef2aSThomas Huth #endif
16fcf5ef2aSThomas Huth 
17fcf5ef2aSThomas Huth /*#define EXCP_INTERRUPT 0x100*/
18fcf5ef2aSThomas Huth 
19f8a74597SRichard Henderson /* Windowed register indexes.  */
20f8a74597SRichard Henderson enum {
21f8a74597SRichard Henderson     WREG_O0,
22f8a74597SRichard Henderson     WREG_O1,
23f8a74597SRichard Henderson     WREG_O2,
24f8a74597SRichard Henderson     WREG_O3,
25f8a74597SRichard Henderson     WREG_O4,
26f8a74597SRichard Henderson     WREG_O5,
27f8a74597SRichard Henderson     WREG_O6,
28f8a74597SRichard Henderson     WREG_O7,
29f8a74597SRichard Henderson 
30f8a74597SRichard Henderson     WREG_L0,
31f8a74597SRichard Henderson     WREG_L1,
32f8a74597SRichard Henderson     WREG_L2,
33f8a74597SRichard Henderson     WREG_L3,
34f8a74597SRichard Henderson     WREG_L4,
35f8a74597SRichard Henderson     WREG_L5,
36f8a74597SRichard Henderson     WREG_L6,
37f8a74597SRichard Henderson     WREG_L7,
38f8a74597SRichard Henderson 
39f8a74597SRichard Henderson     WREG_I0,
40f8a74597SRichard Henderson     WREG_I1,
41f8a74597SRichard Henderson     WREG_I2,
42f8a74597SRichard Henderson     WREG_I3,
43f8a74597SRichard Henderson     WREG_I4,
44f8a74597SRichard Henderson     WREG_I5,
45f8a74597SRichard Henderson     WREG_I6,
46f8a74597SRichard Henderson     WREG_I7,
47f8a74597SRichard Henderson 
48f8a74597SRichard Henderson     WREG_SP = WREG_O6,
49f8a74597SRichard Henderson     WREG_FP = WREG_I6,
50f8a74597SRichard Henderson };
51f8a74597SRichard Henderson 
52fcf5ef2aSThomas Huth /* trap definitions */
53fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
54fcf5ef2aSThomas Huth #define TT_TFAULT   0x01
55fcf5ef2aSThomas Huth #define TT_ILL_INSN 0x02
56fcf5ef2aSThomas Huth #define TT_PRIV_INSN 0x03
57fcf5ef2aSThomas Huth #define TT_NFPU_INSN 0x04
58fcf5ef2aSThomas Huth #define TT_WIN_OVF  0x05
59fcf5ef2aSThomas Huth #define TT_WIN_UNF  0x06
60fcf5ef2aSThomas Huth #define TT_UNALIGNED 0x07
61fcf5ef2aSThomas Huth #define TT_FP_EXCP  0x08
62fcf5ef2aSThomas Huth #define TT_DFAULT   0x09
63fcf5ef2aSThomas Huth #define TT_TOVF     0x0a
64fcf5ef2aSThomas Huth #define TT_EXTINT   0x10
65fcf5ef2aSThomas Huth #define TT_CODE_ACCESS 0x21
66fcf5ef2aSThomas Huth #define TT_UNIMP_FLUSH 0x25
67fcf5ef2aSThomas Huth #define TT_DATA_ACCESS 0x29
68fcf5ef2aSThomas Huth #define TT_DIV_ZERO 0x2a
69fcf5ef2aSThomas Huth #define TT_NCP_INSN 0x24
70fcf5ef2aSThomas Huth #define TT_TRAP     0x80
71fcf5ef2aSThomas Huth #else
72fcf5ef2aSThomas Huth #define TT_POWER_ON_RESET 0x01
73fcf5ef2aSThomas Huth #define TT_TFAULT   0x08
74fcf5ef2aSThomas Huth #define TT_CODE_ACCESS 0x0a
75fcf5ef2aSThomas Huth #define TT_ILL_INSN 0x10
76fcf5ef2aSThomas Huth #define TT_UNIMP_FLUSH TT_ILL_INSN
77fcf5ef2aSThomas Huth #define TT_PRIV_INSN 0x11
78fcf5ef2aSThomas Huth #define TT_NFPU_INSN 0x20
79fcf5ef2aSThomas Huth #define TT_FP_EXCP  0x21
80fcf5ef2aSThomas Huth #define TT_TOVF     0x23
81fcf5ef2aSThomas Huth #define TT_CLRWIN   0x24
82fcf5ef2aSThomas Huth #define TT_DIV_ZERO 0x28
83fcf5ef2aSThomas Huth #define TT_DFAULT   0x30
84fcf5ef2aSThomas Huth #define TT_DATA_ACCESS 0x32
85fcf5ef2aSThomas Huth #define TT_UNALIGNED 0x34
86fcf5ef2aSThomas Huth #define TT_PRIV_ACT 0x37
871ceca928SArtyom Tarasenko #define TT_INSN_REAL_TRANSLATION_MISS 0x3e
881ceca928SArtyom Tarasenko #define TT_DATA_REAL_TRANSLATION_MISS 0x3f
89fcf5ef2aSThomas Huth #define TT_EXTINT   0x40
90fcf5ef2aSThomas Huth #define TT_IVEC     0x60
91fcf5ef2aSThomas Huth #define TT_TMISS    0x64
92fcf5ef2aSThomas Huth #define TT_DMISS    0x68
93fcf5ef2aSThomas Huth #define TT_DPROT    0x6c
94fcf5ef2aSThomas Huth #define TT_SPILL    0x80
95fcf5ef2aSThomas Huth #define TT_FILL     0xc0
96fcf5ef2aSThomas Huth #define TT_WOTHER   (1 << 5)
97fcf5ef2aSThomas Huth #define TT_TRAP     0x100
986e040755SArtyom Tarasenko #define TT_HTRAP    0x180
99fcf5ef2aSThomas Huth #endif
100fcf5ef2aSThomas Huth 
101fcf5ef2aSThomas Huth #define PSR_NEG_SHIFT 23
102fcf5ef2aSThomas Huth #define PSR_NEG   (1 << PSR_NEG_SHIFT)
103fcf5ef2aSThomas Huth #define PSR_ZERO_SHIFT 22
104fcf5ef2aSThomas Huth #define PSR_ZERO  (1 << PSR_ZERO_SHIFT)
105fcf5ef2aSThomas Huth #define PSR_OVF_SHIFT 21
106fcf5ef2aSThomas Huth #define PSR_OVF   (1 << PSR_OVF_SHIFT)
107fcf5ef2aSThomas Huth #define PSR_CARRY_SHIFT 20
108fcf5ef2aSThomas Huth #define PSR_CARRY (1 << PSR_CARRY_SHIFT)
109fcf5ef2aSThomas Huth #define PSR_ICC   (PSR_NEG|PSR_ZERO|PSR_OVF|PSR_CARRY)
110fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64)
111fcf5ef2aSThomas Huth #define PSR_EF    (1<<12)
112fcf5ef2aSThomas Huth #define PSR_PIL   0xf00
113fcf5ef2aSThomas Huth #define PSR_S     (1<<7)
114fcf5ef2aSThomas Huth #define PSR_PS    (1<<6)
115fcf5ef2aSThomas Huth #define PSR_ET    (1<<5)
116fcf5ef2aSThomas Huth #define PSR_CWP   0x1f
117fcf5ef2aSThomas Huth #endif
118fcf5ef2aSThomas Huth 
119fcf5ef2aSThomas Huth /* Trap base register */
120fcf5ef2aSThomas Huth #define TBR_BASE_MASK 0xfffff000
121fcf5ef2aSThomas Huth 
122fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
123fcf5ef2aSThomas Huth #define PS_TCT   (1<<12) /* UA2007, impl.dep. trap on control transfer */
124fcf5ef2aSThomas Huth #define PS_IG    (1<<11) /* v9, zero on UA2007 */
125fcf5ef2aSThomas Huth #define PS_MG    (1<<10) /* v9, zero on UA2007 */
126fcf5ef2aSThomas Huth #define PS_CLE   (1<<9) /* UA2007 */
127fcf5ef2aSThomas Huth #define PS_TLE   (1<<8) /* UA2007 */
128fcf5ef2aSThomas Huth #define PS_RMO   (1<<7)
129fcf5ef2aSThomas Huth #define PS_RED   (1<<5) /* v9, zero on UA2007 */
130fcf5ef2aSThomas Huth #define PS_PEF   (1<<4) /* enable fpu */
131fcf5ef2aSThomas Huth #define PS_AM    (1<<3) /* address mask */
132fcf5ef2aSThomas Huth #define PS_PRIV  (1<<2)
133fcf5ef2aSThomas Huth #define PS_IE    (1<<1)
134fcf5ef2aSThomas Huth #define PS_AG    (1<<0) /* v9, zero on UA2007 */
135fcf5ef2aSThomas Huth 
136246ff442SPeter Maydell #define FPRS_DL (1 << 0)
137246ff442SPeter Maydell #define FPRS_DU (1 << 1)
138fcf5ef2aSThomas Huth #define FPRS_FEF (1 << 2)
139fcf5ef2aSThomas Huth 
140fcf5ef2aSThomas Huth #define HS_PRIV  (1<<2)
141fcf5ef2aSThomas Huth #endif
142fcf5ef2aSThomas Huth 
143fcf5ef2aSThomas Huth /* Fcc */
144fcf5ef2aSThomas Huth #define FSR_RD1        (1ULL << 31)
145fcf5ef2aSThomas Huth #define FSR_RD0        (1ULL << 30)
146fcf5ef2aSThomas Huth #define FSR_RD_MASK    (FSR_RD1 | FSR_RD0)
147fcf5ef2aSThomas Huth #define FSR_RD_NEAREST 0
148fcf5ef2aSThomas Huth #define FSR_RD_ZERO    FSR_RD0
149fcf5ef2aSThomas Huth #define FSR_RD_POS     FSR_RD1
150fcf5ef2aSThomas Huth #define FSR_RD_NEG     (FSR_RD1 | FSR_RD0)
151fcf5ef2aSThomas Huth 
152fcf5ef2aSThomas Huth #define FSR_NVM   (1ULL << 27)
153fcf5ef2aSThomas Huth #define FSR_OFM   (1ULL << 26)
154fcf5ef2aSThomas Huth #define FSR_UFM   (1ULL << 25)
155fcf5ef2aSThomas Huth #define FSR_DZM   (1ULL << 24)
156fcf5ef2aSThomas Huth #define FSR_NXM   (1ULL << 23)
157fcf5ef2aSThomas Huth #define FSR_TEM_MASK (FSR_NVM | FSR_OFM | FSR_UFM | FSR_DZM | FSR_NXM)
1583590f01eSRichard Henderson #define FSR_TEM_SHIFT  23
159fcf5ef2aSThomas Huth 
160fcf5ef2aSThomas Huth #define FSR_NVA   (1ULL << 9)
161fcf5ef2aSThomas Huth #define FSR_OFA   (1ULL << 8)
162fcf5ef2aSThomas Huth #define FSR_UFA   (1ULL << 7)
163fcf5ef2aSThomas Huth #define FSR_DZA   (1ULL << 6)
164fcf5ef2aSThomas Huth #define FSR_NXA   (1ULL << 5)
165fcf5ef2aSThomas Huth #define FSR_AEXC_MASK (FSR_NVA | FSR_OFA | FSR_UFA | FSR_DZA | FSR_NXA)
1663590f01eSRichard Henderson #define FSR_AEXC_SHIFT 5
167fcf5ef2aSThomas Huth 
168fcf5ef2aSThomas Huth #define FSR_NVC   (1ULL << 4)
169fcf5ef2aSThomas Huth #define FSR_OFC   (1ULL << 3)
170fcf5ef2aSThomas Huth #define FSR_UFC   (1ULL << 2)
171fcf5ef2aSThomas Huth #define FSR_DZC   (1ULL << 1)
172fcf5ef2aSThomas Huth #define FSR_NXC   (1ULL << 0)
173fcf5ef2aSThomas Huth #define FSR_CEXC_MASK (FSR_NVC | FSR_OFC | FSR_UFC | FSR_DZC | FSR_NXC)
174fcf5ef2aSThomas Huth 
17549bb9725SRichard Henderson #define FSR_VER_SHIFT  17
17649bb9725SRichard Henderson #define FSR_VER_MASK   (7 << FSR_VER_SHIFT)
17749bb9725SRichard Henderson 
178fcf5ef2aSThomas Huth #define FSR_FTT2   (1ULL << 16)
179fcf5ef2aSThomas Huth #define FSR_FTT1   (1ULL << 15)
180fcf5ef2aSThomas Huth #define FSR_FTT0   (1ULL << 14)
1814ea3af39SRichard Henderson #define FSR_FTT_MASK (FSR_FTT2 | FSR_FTT1 | FSR_FTT0)
182fcf5ef2aSThomas Huth #define FSR_FTT_IEEE_EXCP (1ULL << 14)
183fcf5ef2aSThomas Huth #define FSR_FTT_UNIMPFPOP (3ULL << 14)
184fcf5ef2aSThomas Huth #define FSR_FTT_SEQ_ERROR (4ULL << 14)
185fcf5ef2aSThomas Huth #define FSR_FTT_INVAL_FPR (6ULL << 14)
186fcf5ef2aSThomas Huth 
187e412e997SCarl Hauser #define FSR_QNE    (1ULL << 13)
188e412e997SCarl Hauser 
189fcf5ef2aSThomas Huth #define FSR_FCC0_SHIFT    10
190d8c5b92fSRichard Henderson #define FSR_FCC1_SHIFT    32
191d8c5b92fSRichard Henderson #define FSR_FCC2_SHIFT    34
192d8c5b92fSRichard Henderson #define FSR_FCC3_SHIFT    36
193fcf5ef2aSThomas Huth 
194fcf5ef2aSThomas Huth /* MMU */
195fcf5ef2aSThomas Huth #define MMU_E     (1<<0)
196fcf5ef2aSThomas Huth #define MMU_NF    (1<<1)
197fcf5ef2aSThomas Huth 
198fcf5ef2aSThomas Huth #define PTE_ENTRYTYPE_MASK 3
199fcf5ef2aSThomas Huth #define PTE_ACCESS_MASK    0x1c
200fcf5ef2aSThomas Huth #define PTE_ACCESS_SHIFT   2
201fcf5ef2aSThomas Huth #define PTE_PPN_SHIFT      7
202fcf5ef2aSThomas Huth #define PTE_ADDR_MASK      0xffffff00
203fcf5ef2aSThomas Huth 
204fcf5ef2aSThomas Huth #define PG_ACCESSED_BIT 5
205fcf5ef2aSThomas Huth #define PG_MODIFIED_BIT 6
206fcf5ef2aSThomas Huth #define PG_CACHE_BIT    7
207fcf5ef2aSThomas Huth 
208fcf5ef2aSThomas Huth #define PG_ACCESSED_MASK (1 << PG_ACCESSED_BIT)
209fcf5ef2aSThomas Huth #define PG_MODIFIED_MASK (1 << PG_MODIFIED_BIT)
210fcf5ef2aSThomas Huth #define PG_CACHE_MASK    (1 << PG_CACHE_BIT)
211fcf5ef2aSThomas Huth 
212fcf5ef2aSThomas Huth /* 3 <= NWINDOWS <= 32. */
213fcf5ef2aSThomas Huth #define MIN_NWINDOWS 3
214fcf5ef2aSThomas Huth #define MAX_NWINDOWS 32
215fcf5ef2aSThomas Huth 
21674433bf0SRichard Henderson #ifdef TARGET_SPARC64
217fcf5ef2aSThomas Huth typedef struct trap_state {
218fcf5ef2aSThomas Huth     uint64_t tpc;
219fcf5ef2aSThomas Huth     uint64_t tnpc;
220fcf5ef2aSThomas Huth     uint64_t tstate;
221fcf5ef2aSThomas Huth     uint32_t tt;
222fcf5ef2aSThomas Huth } trap_state;
223fcf5ef2aSThomas Huth #endif
224fcf5ef2aSThomas Huth #define TARGET_INSN_START_EXTRA_WORDS 1
225fcf5ef2aSThomas Huth 
2269348028eSPhilippe Mathieu-Daudé typedef struct sparc_def_t {
227fcf5ef2aSThomas Huth     const char *name;
228fcf5ef2aSThomas Huth     target_ulong iu_version;
229fcf5ef2aSThomas Huth     uint32_t fpu_version;
230fcf5ef2aSThomas Huth     uint32_t mmu_version;
231fcf5ef2aSThomas Huth     uint32_t mmu_bm;
232fcf5ef2aSThomas Huth     uint32_t mmu_ctpr_mask;
233fcf5ef2aSThomas Huth     uint32_t mmu_cxr_mask;
234fcf5ef2aSThomas Huth     uint32_t mmu_sfsr_mask;
235fcf5ef2aSThomas Huth     uint32_t mmu_trcr_mask;
236fcf5ef2aSThomas Huth     uint32_t mxcc_version;
237fcf5ef2aSThomas Huth     uint32_t features;
238fcf5ef2aSThomas Huth     uint32_t nwindows;
239fcf5ef2aSThomas Huth     uint32_t maxtl;
2409348028eSPhilippe Mathieu-Daudé } sparc_def_t;
241fcf5ef2aSThomas Huth 
242bd7ff659SRichard Henderson #define FEATURE(X)  CPU_FEATURE_BIT_##X,
243bd7ff659SRichard Henderson enum {
244bd7ff659SRichard Henderson #include "cpu-feature.h.inc"
245bd7ff659SRichard Henderson };
246bd7ff659SRichard Henderson 
247bd7ff659SRichard Henderson #undef FEATURE
248bd7ff659SRichard Henderson #define FEATURE(X)  CPU_FEATURE_##X = 1u << CPU_FEATURE_BIT_##X,
249bd7ff659SRichard Henderson 
250bd7ff659SRichard Henderson enum {
251bd7ff659SRichard Henderson #include "cpu-feature.h.inc"
252bd7ff659SRichard Henderson };
253bd7ff659SRichard Henderson 
254bd7ff659SRichard Henderson #undef FEATURE
255fcf5ef2aSThomas Huth 
256fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
2575f25b383SRichard Henderson #define CPU_DEFAULT_FEATURES (CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
2585f25b383SRichard Henderson                               CPU_FEATURE_FSMULD)
259fcf5ef2aSThomas Huth #else
2605f25b383SRichard Henderson #define CPU_DEFAULT_FEATURES (CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
2615f25b383SRichard Henderson                               CPU_FEATURE_FSMULD | CPU_FEATURE_CASA | \
2625f25b383SRichard Henderson                               CPU_FEATURE_VIS1 | CPU_FEATURE_VIS2)
263fcf5ef2aSThomas Huth enum {
264fcf5ef2aSThomas Huth     mmu_us_12, // Ultrasparc < III (64 entry TLB)
265fcf5ef2aSThomas Huth     mmu_us_3,  // Ultrasparc III (512 entry TLB)
266fcf5ef2aSThomas Huth     mmu_us_4,  // Ultrasparc IV (several TLBs, 32 and 256MB pages)
267fcf5ef2aSThomas Huth     mmu_sun4v, // T1, T2
268fcf5ef2aSThomas Huth };
269fcf5ef2aSThomas Huth #endif
270fcf5ef2aSThomas Huth 
271fcf5ef2aSThomas Huth #define TTE_VALID_BIT       (1ULL << 63)
272fcf5ef2aSThomas Huth #define TTE_NFO_BIT         (1ULL << 60)
273ccdb4c55STony Nguyen #define TTE_IE_BIT          (1ULL << 59)
274fcf5ef2aSThomas Huth #define TTE_USED_BIT        (1ULL << 41)
275fcf5ef2aSThomas Huth #define TTE_LOCKED_BIT      (1ULL <<  6)
276fcf5ef2aSThomas Huth #define TTE_SIDEEFFECT_BIT  (1ULL <<  3)
277fcf5ef2aSThomas Huth #define TTE_PRIV_BIT        (1ULL <<  2)
278fcf5ef2aSThomas Huth #define TTE_W_OK_BIT        (1ULL <<  1)
279fcf5ef2aSThomas Huth #define TTE_GLOBAL_BIT      (1ULL <<  0)
280fcf5ef2aSThomas Huth 
281c2c7f864SArtyom Tarasenko #define TTE_NFO_BIT_UA2005  (1ULL << 62)
282c2c7f864SArtyom Tarasenko #define TTE_USED_BIT_UA2005 (1ULL << 47)
283c2c7f864SArtyom Tarasenko #define TTE_LOCKED_BIT_UA2005 (1ULL <<  61)
284c2c7f864SArtyom Tarasenko #define TTE_SIDEEFFECT_BIT_UA2005 (1ULL <<  11)
285c2c7f864SArtyom Tarasenko #define TTE_PRIV_BIT_UA2005 (1ULL <<  8)
286c2c7f864SArtyom Tarasenko #define TTE_W_OK_BIT_UA2005 (1ULL <<  6)
287c2c7f864SArtyom Tarasenko 
288fcf5ef2aSThomas Huth #define TTE_IS_VALID(tte)   ((tte) & TTE_VALID_BIT)
289fcf5ef2aSThomas Huth #define TTE_IS_NFO(tte)     ((tte) & TTE_NFO_BIT)
290ccdb4c55STony Nguyen #define TTE_IS_IE(tte)      ((tte) & TTE_IE_BIT)
291fcf5ef2aSThomas Huth #define TTE_IS_USED(tte)    ((tte) & TTE_USED_BIT)
292fcf5ef2aSThomas Huth #define TTE_IS_LOCKED(tte)  ((tte) & TTE_LOCKED_BIT)
293fcf5ef2aSThomas Huth #define TTE_IS_SIDEEFFECT(tte) ((tte) & TTE_SIDEEFFECT_BIT)
294c2c7f864SArtyom Tarasenko #define TTE_IS_SIDEEFFECT_UA2005(tte) ((tte) & TTE_SIDEEFFECT_BIT_UA2005)
295fcf5ef2aSThomas Huth #define TTE_IS_PRIV(tte)    ((tte) & TTE_PRIV_BIT)
296fcf5ef2aSThomas Huth #define TTE_IS_W_OK(tte)    ((tte) & TTE_W_OK_BIT)
297c2c7f864SArtyom Tarasenko 
298c2c7f864SArtyom Tarasenko #define TTE_IS_NFO_UA2005(tte)     ((tte) & TTE_NFO_BIT_UA2005)
299c2c7f864SArtyom Tarasenko #define TTE_IS_USED_UA2005(tte)    ((tte) & TTE_USED_BIT_UA2005)
300c2c7f864SArtyom Tarasenko #define TTE_IS_LOCKED_UA2005(tte)  ((tte) & TTE_LOCKED_BIT_UA2005)
301c2c7f864SArtyom Tarasenko #define TTE_IS_SIDEEFFECT_UA2005(tte) ((tte) & TTE_SIDEEFFECT_BIT_UA2005)
302c2c7f864SArtyom Tarasenko #define TTE_IS_PRIV_UA2005(tte)    ((tte) & TTE_PRIV_BIT_UA2005)
303c2c7f864SArtyom Tarasenko #define TTE_IS_W_OK_UA2005(tte)    ((tte) & TTE_W_OK_BIT_UA2005)
304c2c7f864SArtyom Tarasenko 
305fcf5ef2aSThomas Huth #define TTE_IS_GLOBAL(tte)  ((tte) & TTE_GLOBAL_BIT)
306fcf5ef2aSThomas Huth 
307fcf5ef2aSThomas Huth #define TTE_SET_USED(tte)   ((tte) |= TTE_USED_BIT)
308fcf5ef2aSThomas Huth #define TTE_SET_UNUSED(tte) ((tte) &= ~TTE_USED_BIT)
309fcf5ef2aSThomas Huth 
310fcf5ef2aSThomas Huth #define TTE_PGSIZE(tte)     (((tte) >> 61) & 3ULL)
311c2c7f864SArtyom Tarasenko #define TTE_PGSIZE_UA2005(tte)     ((tte) & 7ULL)
312fcf5ef2aSThomas Huth #define TTE_PA(tte)         ((tte) & 0x1ffffffe000ULL)
313fcf5ef2aSThomas Huth 
3145b5352b2SArtyom Tarasenko /* UltraSPARC T1 specific */
3155b5352b2SArtyom Tarasenko #define TLB_UST1_IS_REAL_BIT   (1ULL << 9)  /* Real translation entry */
3165b5352b2SArtyom Tarasenko #define TLB_UST1_IS_SUN4V_BIT  (1ULL << 10) /* sun4u/sun4v TTE format switch */
3175b5352b2SArtyom Tarasenko 
318fcf5ef2aSThomas Huth #define SFSR_NF_BIT         (1ULL << 24)   /* JPS1 NoFault */
319fcf5ef2aSThomas Huth #define SFSR_TM_BIT         (1ULL << 15)   /* JPS1 TLB Miss */
320fcf5ef2aSThomas Huth #define SFSR_FT_VA_IMMU_BIT (1ULL << 13)   /* USIIi VA out of range (IMMU) */
321fcf5ef2aSThomas Huth #define SFSR_FT_VA_DMMU_BIT (1ULL << 12)   /* USIIi VA out of range (DMMU) */
322fcf5ef2aSThomas Huth #define SFSR_FT_NFO_BIT     (1ULL << 11)   /* NFO page access */
323fcf5ef2aSThomas Huth #define SFSR_FT_ILL_BIT     (1ULL << 10)   /* illegal LDA/STA ASI */
324fcf5ef2aSThomas Huth #define SFSR_FT_ATOMIC_BIT  (1ULL <<  9)   /* atomic op on noncacheable area */
325fcf5ef2aSThomas Huth #define SFSR_FT_NF_E_BIT    (1ULL <<  8)   /* NF access on side effect area */
326fcf5ef2aSThomas Huth #define SFSR_FT_PRIV_BIT    (1ULL <<  7)   /* privilege violation */
327fcf5ef2aSThomas Huth #define SFSR_PR_BIT         (1ULL <<  3)   /* privilege mode */
328fcf5ef2aSThomas Huth #define SFSR_WRITE_BIT      (1ULL <<  2)   /* write access mode */
329fcf5ef2aSThomas Huth #define SFSR_OW_BIT         (1ULL <<  1)   /* status overwritten */
330fcf5ef2aSThomas Huth #define SFSR_VALID_BIT      (1ULL <<  0)   /* status valid */
331fcf5ef2aSThomas Huth 
332fcf5ef2aSThomas Huth #define SFSR_ASI_SHIFT      16             /* 23:16 ASI value */
333fcf5ef2aSThomas Huth #define SFSR_ASI_MASK       (0xffULL << SFSR_ASI_SHIFT)
334fcf5ef2aSThomas Huth #define SFSR_CT_PRIMARY     (0ULL <<  4)   /* 5:4 context type */
335fcf5ef2aSThomas Huth #define SFSR_CT_SECONDARY   (1ULL <<  4)
336fcf5ef2aSThomas Huth #define SFSR_CT_NUCLEUS     (2ULL <<  4)
337fcf5ef2aSThomas Huth #define SFSR_CT_NOTRANS     (3ULL <<  4)
338fcf5ef2aSThomas Huth #define SFSR_CT_MASK        (3ULL <<  4)
339fcf5ef2aSThomas Huth 
340fcf5ef2aSThomas Huth /* Leon3 cache control */
341fcf5ef2aSThomas Huth 
342fcf5ef2aSThomas Huth /* Cache control: emulate the behavior of cache control registers but without
343fcf5ef2aSThomas Huth    any effect on the emulated */
344fcf5ef2aSThomas Huth 
345fcf5ef2aSThomas Huth #define CACHE_STATE_MASK 0x3
346fcf5ef2aSThomas Huth #define CACHE_DISABLED   0x0
347fcf5ef2aSThomas Huth #define CACHE_FROZEN     0x1
348fcf5ef2aSThomas Huth #define CACHE_ENABLED    0x3
349fcf5ef2aSThomas Huth 
350fcf5ef2aSThomas Huth /* Cache Control register fields */
351fcf5ef2aSThomas Huth 
352fcf5ef2aSThomas Huth #define CACHE_CTRL_IF (1 <<  4)  /* Instruction Cache Freeze on Interrupt */
353fcf5ef2aSThomas Huth #define CACHE_CTRL_DF (1 <<  5)  /* Data Cache Freeze on Interrupt */
354fcf5ef2aSThomas Huth #define CACHE_CTRL_DP (1 << 14)  /* Data cache flush pending */
355fcf5ef2aSThomas Huth #define CACHE_CTRL_IP (1 << 15)  /* Instruction cache flush pending */
356fcf5ef2aSThomas Huth #define CACHE_CTRL_IB (1 << 16)  /* Instruction burst fetch */
357fcf5ef2aSThomas Huth #define CACHE_CTRL_FI (1 << 21)  /* Flush Instruction cache (Write only) */
358fcf5ef2aSThomas Huth #define CACHE_CTRL_FD (1 << 22)  /* Flush Data cache (Write only) */
359fcf5ef2aSThomas Huth #define CACHE_CTRL_DS (1 << 23)  /* Data cache snoop enable */
360fcf5ef2aSThomas Huth 
3617285fba0SArtyom Tarasenko #define CONVERT_BIT(X, SRC, DST) \
3627285fba0SArtyom Tarasenko          (SRC > DST ? (X) / (SRC / DST) & (DST) : ((X) & SRC) * (DST / SRC))
3637285fba0SArtyom Tarasenko 
364fcf5ef2aSThomas Huth typedef struct SparcTLBEntry {
365fcf5ef2aSThomas Huth     uint64_t tag;
366fcf5ef2aSThomas Huth     uint64_t tte;
367fcf5ef2aSThomas Huth } SparcTLBEntry;
368fcf5ef2aSThomas Huth 
369fcf5ef2aSThomas Huth struct CPUTimer
370fcf5ef2aSThomas Huth {
371fcf5ef2aSThomas Huth     const char *name;
372fcf5ef2aSThomas Huth     uint32_t    frequency;
373fcf5ef2aSThomas Huth     uint32_t    disabled;
374fcf5ef2aSThomas Huth     uint64_t    disabled_mask;
375fcf5ef2aSThomas Huth     uint32_t    npt;
376fcf5ef2aSThomas Huth     uint64_t    npt_mask;
377fcf5ef2aSThomas Huth     int64_t     clock_offset;
378fcf5ef2aSThomas Huth     QEMUTimer  *qtimer;
379fcf5ef2aSThomas Huth };
380fcf5ef2aSThomas Huth 
381fcf5ef2aSThomas Huth typedef struct CPUTimer CPUTimer;
382fcf5ef2aSThomas Huth 
3831ea4a06aSPhilippe Mathieu-Daudé typedef struct CPUArchState CPUSPARCState;
38496df2bc9SArtyom Tarasenko #if defined(TARGET_SPARC64)
38596df2bc9SArtyom Tarasenko typedef union {
38696df2bc9SArtyom Tarasenko    uint64_t mmuregs[16];
38796df2bc9SArtyom Tarasenko    struct {
38896df2bc9SArtyom Tarasenko     uint64_t tsb_tag_target;
38996df2bc9SArtyom Tarasenko     uint64_t mmu_primary_context;
39096df2bc9SArtyom Tarasenko     uint64_t mmu_secondary_context;
39196df2bc9SArtyom Tarasenko     uint64_t sfsr;
39296df2bc9SArtyom Tarasenko     uint64_t sfar;
39396df2bc9SArtyom Tarasenko     uint64_t tsb;
39496df2bc9SArtyom Tarasenko     uint64_t tag_access;
39596df2bc9SArtyom Tarasenko     uint64_t virtual_watchpoint;
39696df2bc9SArtyom Tarasenko     uint64_t physical_watchpoint;
39715f746ceSArtyom Tarasenko     uint64_t sun4v_ctx_config[2];
39815f746ceSArtyom Tarasenko     uint64_t sun4v_tsb_pointers[4];
39996df2bc9SArtyom Tarasenko    };
40096df2bc9SArtyom Tarasenko } SparcV9MMU;
40196df2bc9SArtyom Tarasenko #endif
4021ea4a06aSPhilippe Mathieu-Daudé struct CPUArchState {
403fcf5ef2aSThomas Huth     target_ulong gregs[8]; /* general registers */
404fcf5ef2aSThomas Huth     target_ulong *regwptr; /* pointer to current register window */
405fcf5ef2aSThomas Huth     target_ulong pc;       /* program counter */
406fcf5ef2aSThomas Huth     target_ulong npc;      /* next program counter */
407fcf5ef2aSThomas Huth     target_ulong y;        /* multiply/divide register */
408fcf5ef2aSThomas Huth 
4092a1905c7SRichard Henderson     /*
4102a1905c7SRichard Henderson      * Bit 31 is for icc, bit 63 for xcc.
4112a1905c7SRichard Henderson      * Other bits are garbage.
4122a1905c7SRichard Henderson      */
4132a1905c7SRichard Henderson     target_long cc_N;
4142a1905c7SRichard Henderson     target_long cc_V;
4152a1905c7SRichard Henderson 
4162a1905c7SRichard Henderson     /*
4172a1905c7SRichard Henderson      * Z is represented as == 0; any non-zero value is !Z.
4182a1905c7SRichard Henderson      * For sparc64, the high 32-bits of icc.Z are garbage.
4192a1905c7SRichard Henderson      */
4202a1905c7SRichard Henderson     target_ulong icc_Z;
4212a1905c7SRichard Henderson #ifdef TARGET_SPARC64
4222a1905c7SRichard Henderson     target_ulong xcc_Z;
4232a1905c7SRichard Henderson #endif
4242a1905c7SRichard Henderson 
4252a1905c7SRichard Henderson     /*
4262a1905c7SRichard Henderson      * For sparc32, icc.C is boolean.
4272a1905c7SRichard Henderson      * For sparc64, xcc.C is boolean;
4282a1905c7SRichard Henderson      *              icc.C is bit 32 with other bits garbage.
4292a1905c7SRichard Henderson      */
4302a1905c7SRichard Henderson     target_ulong icc_C;
4312a1905c7SRichard Henderson #ifdef TARGET_SPARC64
4322a1905c7SRichard Henderson     target_ulong xcc_C;
4332a1905c7SRichard Henderson #endif
4342a1905c7SRichard Henderson 
435fcf5ef2aSThomas Huth     target_ulong cond; /* conditional branch result (XXX: save it in a
436fcf5ef2aSThomas Huth                           temporary register when possible) */
437fcf5ef2aSThomas Huth 
4383590f01eSRichard Henderson     /* FPU State Register, in parts */
439d8c5b92fSRichard Henderson     uint32_t fsr;                    /* rm, tem, aexc */
4403590f01eSRichard Henderson     uint32_t fsr_cexc_ftt;           /* cexc, ftt */
441d8c5b92fSRichard Henderson     uint32_t fcc[TARGET_FCCREGS];    /* fcc* */
4423590f01eSRichard Henderson 
443e412e997SCarl Hauser #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
444e412e997SCarl Hauser     /*
445e412e997SCarl Hauser      * Single-element FPU fault queue, with address and insn,
446e412e997SCarl Hauser      * packaged into the double-word with which it is stored.
447e412e997SCarl Hauser      */
448e412e997SCarl Hauser     uint32_t fsr_qne;                /* qne */
449e412e997SCarl Hauser     union {
450e412e997SCarl Hauser         uint64_t d;
451e412e997SCarl Hauser         struct {
452e412e997SCarl Hauser #if HOST_BIG_ENDIAN
453e412e997SCarl Hauser             uint32_t addr;
454e412e997SCarl Hauser             uint32_t insn;
455e412e997SCarl Hauser #else
456e412e997SCarl Hauser             uint32_t insn;
457e412e997SCarl Hauser             uint32_t addr;
458e412e997SCarl Hauser #endif
459e412e997SCarl Hauser         } s;
460e412e997SCarl Hauser     } fq;
461e412e997SCarl Hauser #endif
462e412e997SCarl Hauser 
463fcf5ef2aSThomas Huth     CPU_DoubleU fpr[TARGET_DPREGS];  /* floating point registers */
464fcf5ef2aSThomas Huth     uint32_t cwp;      /* index of current register window (extracted
465fcf5ef2aSThomas Huth                           from PSR) */
466fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64) || defined(TARGET_ABI32)
467fcf5ef2aSThomas Huth     uint32_t wim;      /* window invalid mask */
468fcf5ef2aSThomas Huth #endif
469fcf5ef2aSThomas Huth     target_ulong tbr;  /* trap base register */
470fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64)
471fcf5ef2aSThomas Huth     int      psrs;     /* supervisor mode (extracted from PSR) */
472fcf5ef2aSThomas Huth     int      psrps;    /* previous supervisor mode */
473fcf5ef2aSThomas Huth     int      psret;    /* enable traps */
474fcf5ef2aSThomas Huth #endif
475fcf5ef2aSThomas Huth     uint32_t psrpil;   /* interrupt blocking level */
476fcf5ef2aSThomas Huth     uint32_t pil_in;   /* incoming interrupt level bitmap */
477fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64)
478fcf5ef2aSThomas Huth     int      psref;    /* enable fpu */
479fcf5ef2aSThomas Huth #endif
480fcf5ef2aSThomas Huth     int interrupt_index;
481fcf5ef2aSThomas Huth     /* NOTE: we allow 8 more registers to handle wrapping */
482fcf5ef2aSThomas Huth     target_ulong regbase[MAX_NWINDOWS * 16 + 8];
483fcf5ef2aSThomas Huth 
4841f5c00cfSAlex Bennée     /* Fields up to this point are cleared by a CPU reset */
4851f5c00cfSAlex Bennée     struct {} end_reset_fields;
4861f5c00cfSAlex Bennée 
487fcf5ef2aSThomas Huth     /* Fields from here on are preserved across CPU reset. */
488fcf5ef2aSThomas Huth     target_ulong version;
489fcf5ef2aSThomas Huth     uint32_t nwindows;
490fcf5ef2aSThomas Huth 
491fcf5ef2aSThomas Huth     /* MMU regs */
492fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
493fcf5ef2aSThomas Huth     uint64_t lsu;
494fcf5ef2aSThomas Huth #define DMMU_E 0x8
495fcf5ef2aSThomas Huth #define IMMU_E 0x4
49696df2bc9SArtyom Tarasenko     SparcV9MMU immu;
49796df2bc9SArtyom Tarasenko     SparcV9MMU dmmu;
498fcf5ef2aSThomas Huth     SparcTLBEntry itlb[64];
499fcf5ef2aSThomas Huth     SparcTLBEntry dtlb[64];
500fcf5ef2aSThomas Huth     uint32_t mmu_version;
501fcf5ef2aSThomas Huth #else
502fcf5ef2aSThomas Huth     uint32_t mmuregs[32];
503fcf5ef2aSThomas Huth     uint64_t mxccdata[4];
504fcf5ef2aSThomas Huth     uint64_t mxccregs[8];
505fcf5ef2aSThomas Huth     uint32_t mmubpctrv, mmubpctrc, mmubpctrs;
506fcf5ef2aSThomas Huth     uint64_t mmubpaction;
507fcf5ef2aSThomas Huth     uint64_t mmubpregs[4];
508fcf5ef2aSThomas Huth     uint64_t prom_addr;
509fcf5ef2aSThomas Huth #endif
510fcf5ef2aSThomas Huth     float_status fp_status;
511fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
512fcf5ef2aSThomas Huth #define MAXTL_MAX 8
513fcf5ef2aSThomas Huth #define MAXTL_MASK (MAXTL_MAX - 1)
514fcf5ef2aSThomas Huth     trap_state ts[MAXTL_MAX];
515fcf5ef2aSThomas Huth     uint32_t asi;
516fcf5ef2aSThomas Huth     uint32_t pstate;
517fcf5ef2aSThomas Huth     uint32_t tl;
518fcf5ef2aSThomas Huth     uint32_t maxtl;
519fcf5ef2aSThomas Huth     uint32_t cansave, canrestore, otherwin, wstate, cleanwin;
520fcf5ef2aSThomas Huth     uint64_t agregs[8]; /* alternate general registers */
521fcf5ef2aSThomas Huth     uint64_t bgregs[8]; /* backup for normal global registers */
522fcf5ef2aSThomas Huth     uint64_t igregs[8]; /* interrupt general registers */
523fcf5ef2aSThomas Huth     uint64_t mgregs[8]; /* mmu general registers */
524cbc3a6a4SArtyom Tarasenko     uint64_t glregs[8 * MAXTL_MAX];
525ca4d5d86SPeter Maydell     uint32_t fprs;
526fcf5ef2aSThomas Huth     uint64_t tick_cmpr, stick_cmpr;
527fcf5ef2aSThomas Huth     CPUTimer *tick, *stick;
528fcf5ef2aSThomas Huth #define TICK_NPT_MASK        0x8000000000000000ULL
529fcf5ef2aSThomas Huth #define TICK_INT_DIS         0x8000000000000000ULL
530fcf5ef2aSThomas Huth     uint64_t gsr;
531fcf5ef2aSThomas Huth     uint32_t gl; // UA2005
532fcf5ef2aSThomas Huth     /* UA 2005 hyperprivileged registers */
533fcf5ef2aSThomas Huth     uint64_t hpstate, htstate[MAXTL_MAX], hintp, htba, hver, hstick_cmpr, ssr;
5344ec3e346SArtyom Tarasenko     uint64_t scratch[8];
535fcf5ef2aSThomas Huth     CPUTimer *hstick; // UA 2005
536fcf5ef2aSThomas Huth     /* Interrupt vector registers */
537fcf5ef2aSThomas Huth     uint64_t ivec_status;
538fcf5ef2aSThomas Huth     uint64_t ivec_data[3];
539fcf5ef2aSThomas Huth     uint32_t softint;
540fcf5ef2aSThomas Huth #define SOFTINT_TIMER   1
541fcf5ef2aSThomas Huth #define SOFTINT_STIMER  (1 << 16)
542fcf5ef2aSThomas Huth #define SOFTINT_INTRMASK (0xFFFE)
543fcf5ef2aSThomas Huth #define SOFTINT_REG_MASK (SOFTINT_STIMER|SOFTINT_INTRMASK|SOFTINT_TIMER)
544fcf5ef2aSThomas Huth #endif
545576e1c4cSIgor Mammedov     sparc_def_t def;
546fcf5ef2aSThomas Huth 
547d08b7af3SPhilippe Mathieu-Daudé     /* Leon3 */
548d08b7af3SPhilippe Mathieu-Daudé     DeviceState *irq_manager;
549a318da6bSClément Chigot     void (*qemu_irq_ack)(CPUSPARCState *env, int intno);
550fcf5ef2aSThomas Huth     uint32_t cache_control;
551fcf5ef2aSThomas Huth };
552fcf5ef2aSThomas Huth 
553fcf5ef2aSThomas Huth /**
554fcf5ef2aSThomas Huth  * SPARCCPU:
555fcf5ef2aSThomas Huth  * @env: #CPUSPARCState
556fcf5ef2aSThomas Huth  *
557fcf5ef2aSThomas Huth  * A SPARC CPU.
558fcf5ef2aSThomas Huth  */
559b36e239eSPhilippe Mathieu-Daudé struct ArchCPU {
560fcf5ef2aSThomas Huth     CPUState parent_obj;
561fcf5ef2aSThomas Huth 
562fcf5ef2aSThomas Huth     CPUSPARCState env;
563fcf5ef2aSThomas Huth };
564fcf5ef2aSThomas Huth 
5659348028eSPhilippe Mathieu-Daudé /**
5669348028eSPhilippe Mathieu-Daudé  * SPARCCPUClass:
5679348028eSPhilippe Mathieu-Daudé  * @parent_realize: The parent class' realize handler.
5689348028eSPhilippe Mathieu-Daudé  * @parent_phases: The parent class' reset phase handlers.
5699348028eSPhilippe Mathieu-Daudé  *
5709348028eSPhilippe Mathieu-Daudé  * A SPARC CPU model.
5719348028eSPhilippe Mathieu-Daudé  */
5729348028eSPhilippe Mathieu-Daudé struct SPARCCPUClass {
5739348028eSPhilippe Mathieu-Daudé     CPUClass parent_class;
5749348028eSPhilippe Mathieu-Daudé 
5759348028eSPhilippe Mathieu-Daudé     DeviceRealize parent_realize;
5769348028eSPhilippe Mathieu-Daudé     ResettablePhases parent_phases;
5779348028eSPhilippe Mathieu-Daudé     sparc_def_t *cpu_def;
5789348028eSPhilippe Mathieu-Daudé };
579fcf5ef2aSThomas Huth 
580fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
5818a9358ccSMarkus Armbruster extern const VMStateDescription vmstate_sparc_cpu;
5826d2d454aSPhilippe Mathieu-Daudé 
5836d2d454aSPhilippe Mathieu-Daudé hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
584fcf5ef2aSThomas Huth #endif
585fcf5ef2aSThomas Huth 
586fcf5ef2aSThomas Huth void sparc_cpu_do_interrupt(CPUState *cpu);
587a010bdbeSAlex Bennée int sparc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
588fcf5ef2aSThomas Huth int sparc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
5898905770bSMarc-André Lureau G_NORETURN void sparc_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
590fcf5ef2aSThomas Huth                                               MMUAccessType access_type,
591fcf5ef2aSThomas Huth                                               int mmu_idx,
592fcf5ef2aSThomas Huth                                               uintptr_t retaddr);
5938905770bSMarc-André Lureau G_NORETURN void cpu_raise_exception_ra(CPUSPARCState *, int, uintptr_t);
594fcf5ef2aSThomas Huth 
595fcf5ef2aSThomas Huth /* cpu_init.c */
596fcf5ef2aSThomas Huth void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu);
5970442428aSMarkus Armbruster void sparc_cpu_list(void);
598fcf5ef2aSThomas Huth /* mmu_helper.c */
599e84942f2SRichard Henderson bool sparc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
600e84942f2SRichard Henderson                         MMUAccessType access_type, int mmu_idx,
601e84942f2SRichard Henderson                         bool probe, uintptr_t retaddr);
602fcf5ef2aSThomas Huth target_ulong mmu_probe(CPUSPARCState *env, target_ulong address, int mmulev);
603fad866daSMarkus Armbruster void dump_mmu(CPUSPARCState *env);
604fcf5ef2aSThomas Huth 
605fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
606fcf5ef2aSThomas Huth int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
607fcf5ef2aSThomas Huth                               uint8_t *buf, int len, bool is_write);
608fcf5ef2aSThomas Huth #endif
609fcf5ef2aSThomas Huth 
610fcf5ef2aSThomas Huth 
611fcf5ef2aSThomas Huth /* translate.c */
61255c3ceefSRichard Henderson void sparc_tcg_init(void);
613f36aaa53SRichard Henderson void sparc_restore_state_to_opc(CPUState *cs,
614f36aaa53SRichard Henderson                                 const TranslationBlock *tb,
615f36aaa53SRichard Henderson                                 const uint64_t *data);
616fcf5ef2aSThomas Huth 
6171ccd6e13SRichard Henderson /* fop_helper.c */
6181ccd6e13SRichard Henderson target_ulong cpu_get_fsr(CPUSPARCState *);
6191ccd6e13SRichard Henderson void cpu_put_fsr(CPUSPARCState *, target_ulong);
620fcf5ef2aSThomas Huth 
621fcf5ef2aSThomas Huth /* win_helper.c */
622fcf5ef2aSThomas Huth target_ulong cpu_get_psr(CPUSPARCState *env1);
623fcf5ef2aSThomas Huth void cpu_put_psr(CPUSPARCState *env1, target_ulong val);
624b1fa27fcSRichard Henderson void cpu_put_psr_icc(CPUSPARCState *env1, target_ulong val);
625fcf5ef2aSThomas Huth void cpu_put_psr_raw(CPUSPARCState *env1, target_ulong val);
626fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
627fcf5ef2aSThomas Huth void cpu_change_pstate(CPUSPARCState *env1, uint32_t new_pstate);
628cbc3a6a4SArtyom Tarasenko void cpu_gl_switch_gregs(CPUSPARCState *env, uint32_t new_gl);
629fcf5ef2aSThomas Huth #endif
630fcf5ef2aSThomas Huth int cpu_cwp_inc(CPUSPARCState *env1, int cwp);
631fcf5ef2aSThomas Huth int cpu_cwp_dec(CPUSPARCState *env1, int cwp);
632fcf5ef2aSThomas Huth void cpu_set_cwp(CPUSPARCState *env1, int new_cwp);
633fcf5ef2aSThomas Huth 
634fcf5ef2aSThomas Huth /* sun4m.c, sun4u.c */
635fcf5ef2aSThomas Huth void cpu_check_irqs(CPUSPARCState *env);
636fcf5ef2aSThomas Huth 
637fcf5ef2aSThomas Huth #if defined (TARGET_SPARC64)
638fcf5ef2aSThomas Huth 
compare_masked(uint64_t x,uint64_t y,uint64_t mask)639fcf5ef2aSThomas Huth static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask)
640fcf5ef2aSThomas Huth {
641fcf5ef2aSThomas Huth     return (x & mask) == (y & mask);
642fcf5ef2aSThomas Huth }
643fcf5ef2aSThomas Huth 
644fcf5ef2aSThomas Huth #define MMU_CONTEXT_BITS 13
645fcf5ef2aSThomas Huth #define MMU_CONTEXT_MASK ((1 << MMU_CONTEXT_BITS) - 1)
646fcf5ef2aSThomas Huth 
tlb_compare_context(const SparcTLBEntry * tlb,uint64_t context)647fcf5ef2aSThomas Huth static inline int tlb_compare_context(const SparcTLBEntry *tlb,
648fcf5ef2aSThomas Huth                                       uint64_t context)
649fcf5ef2aSThomas Huth {
650fcf5ef2aSThomas Huth     return compare_masked(context, tlb->tag, MMU_CONTEXT_MASK);
651fcf5ef2aSThomas Huth }
652fcf5ef2aSThomas Huth 
653fcf5ef2aSThomas Huth #endif
654fcf5ef2aSThomas Huth 
655fcf5ef2aSThomas Huth /* cpu-exec.c */
656fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
657f8c3db33SPeter Maydell void sparc_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
658f8c3db33SPeter Maydell                                      vaddr addr, unsigned size,
659f8c3db33SPeter Maydell                                      MMUAccessType access_type,
660f8c3db33SPeter Maydell                                      int mmu_idx, MemTxAttrs attrs,
661f8c3db33SPeter Maydell                                      MemTxResult response, uintptr_t retaddr);
662fcf5ef2aSThomas Huth #if defined(TARGET_SPARC64)
663fcf5ef2aSThomas Huth hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
664fcf5ef2aSThomas Huth                                            int mmu_idx);
665fcf5ef2aSThomas Huth #endif
666fcf5ef2aSThomas Huth #endif
667fcf5ef2aSThomas Huth 
6680dacec87SIgor Mammedov #define CPU_RESOLVING_TYPE TYPE_SPARC_CPU
6691d4bfc54SIgor Mammedov 
670fcf5ef2aSThomas Huth #define cpu_list sparc_cpu_list
671fcf5ef2aSThomas Huth 
672fcf5ef2aSThomas Huth /* MMU modes definitions */
673fcf5ef2aSThomas Huth #if defined (TARGET_SPARC64)
674fcf5ef2aSThomas Huth #define MMU_USER_IDX   0
675fcf5ef2aSThomas Huth #define MMU_USER_SECONDARY_IDX   1
676fcf5ef2aSThomas Huth #define MMU_KERNEL_IDX 2
677fcf5ef2aSThomas Huth #define MMU_KERNEL_SECONDARY_IDX 3
678fcf5ef2aSThomas Huth #define MMU_NUCLEUS_IDX 4
67984f8f587SArtyom Tarasenko #define MMU_PHYS_IDX   5
680fcf5ef2aSThomas Huth #else
681fcf5ef2aSThomas Huth #define MMU_USER_IDX   0
682fcf5ef2aSThomas Huth #define MMU_KERNEL_IDX 1
683fcf5ef2aSThomas Huth #define MMU_PHYS_IDX   2
684fcf5ef2aSThomas Huth #endif
685fcf5ef2aSThomas Huth 
686fcf5ef2aSThomas Huth #if defined (TARGET_SPARC64)
cpu_has_hypervisor(CPUSPARCState * env1)687fcf5ef2aSThomas Huth static inline int cpu_has_hypervisor(CPUSPARCState *env1)
688fcf5ef2aSThomas Huth {
689576e1c4cSIgor Mammedov     return env1->def.features & CPU_FEATURE_HYPV;
690fcf5ef2aSThomas Huth }
691fcf5ef2aSThomas Huth 
cpu_hypervisor_mode(CPUSPARCState * env1)692fcf5ef2aSThomas Huth static inline int cpu_hypervisor_mode(CPUSPARCState *env1)
693fcf5ef2aSThomas Huth {
694fcf5ef2aSThomas Huth     return cpu_has_hypervisor(env1) && (env1->hpstate & HS_PRIV);
695fcf5ef2aSThomas Huth }
696fcf5ef2aSThomas Huth 
cpu_supervisor_mode(CPUSPARCState * env1)697fcf5ef2aSThomas Huth static inline int cpu_supervisor_mode(CPUSPARCState *env1)
698fcf5ef2aSThomas Huth {
699fcf5ef2aSThomas Huth     return env1->pstate & PS_PRIV;
700fcf5ef2aSThomas Huth }
701c9b459aaSArtyom Tarasenko #else
cpu_supervisor_mode(CPUSPARCState * env1)702c9b459aaSArtyom Tarasenko static inline int cpu_supervisor_mode(CPUSPARCState *env1)
703c9b459aaSArtyom Tarasenko {
704c9b459aaSArtyom Tarasenko     return env1->psrs;
705c9b459aaSArtyom Tarasenko }
706fcf5ef2aSThomas Huth #endif
707fcf5ef2aSThomas Huth 
cpu_interrupts_enabled(CPUSPARCState * env1)708fcf5ef2aSThomas Huth static inline int cpu_interrupts_enabled(CPUSPARCState *env1)
709fcf5ef2aSThomas Huth {
710fcf5ef2aSThomas Huth #if !defined (TARGET_SPARC64)
711fcf5ef2aSThomas Huth     if (env1->psret != 0)
712fcf5ef2aSThomas Huth         return 1;
713fcf5ef2aSThomas Huth #else
7141a2aefaeSArtyom Tarasenko     if ((env1->pstate & PS_IE) && !cpu_hypervisor_mode(env1)) {
715fcf5ef2aSThomas Huth         return 1;
7161a2aefaeSArtyom Tarasenko     }
717fcf5ef2aSThomas Huth #endif
718fcf5ef2aSThomas Huth 
719fcf5ef2aSThomas Huth     return 0;
720fcf5ef2aSThomas Huth }
721fcf5ef2aSThomas Huth 
cpu_pil_allowed(CPUSPARCState * env1,int pil)722fcf5ef2aSThomas Huth static inline int cpu_pil_allowed(CPUSPARCState *env1, int pil)
723fcf5ef2aSThomas Huth {
724fcf5ef2aSThomas Huth #if !defined(TARGET_SPARC64)
725fcf5ef2aSThomas Huth     /* level 15 is non-maskable on sparc v8 */
726fcf5ef2aSThomas Huth     return pil == 15 || pil > env1->psrpil;
727fcf5ef2aSThomas Huth #else
728fcf5ef2aSThomas Huth     return pil > env1->psrpil;
729fcf5ef2aSThomas Huth #endif
730fcf5ef2aSThomas Huth }
731fcf5ef2aSThomas Huth 
732fcf5ef2aSThomas Huth #include "exec/cpu-all.h"
733fcf5ef2aSThomas Huth 
734fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
735fcf5ef2aSThomas Huth /* sun4u.c */
736fcf5ef2aSThomas Huth void cpu_tick_set_count(CPUTimer *timer, uint64_t count);
737fcf5ef2aSThomas Huth uint64_t cpu_tick_get_count(CPUTimer *timer);
738fcf5ef2aSThomas Huth void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit);
739fcf5ef2aSThomas Huth trap_state* cpu_tsptr(CPUSPARCState* env);
740fcf5ef2aSThomas Huth #endif
741fcf5ef2aSThomas Huth 
742fcf5ef2aSThomas Huth #define TB_FLAG_MMU_MASK     7
743fcf5ef2aSThomas Huth #define TB_FLAG_FPU_ENABLED  (1 << 4)
744fcf5ef2aSThomas Huth #define TB_FLAG_AM_ENABLED   (1 << 5)
745c9b459aaSArtyom Tarasenko #define TB_FLAG_SUPER        (1 << 6)
746c9b459aaSArtyom Tarasenko #define TB_FLAG_HYPER        (1 << 7)
747*5a165e26SRichard Henderson #define TB_FLAG_FSR_QNE      (1 << 8)
748fcf5ef2aSThomas Huth #define TB_FLAG_ASI_SHIFT    24
749fcf5ef2aSThomas Huth 
cpu_get_tb_cpu_state(CPUSPARCState * env,vaddr * pc,uint64_t * cs_base,uint32_t * pflags)750bb5de525SAnton Johansson static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, vaddr *pc,
751bb5de525SAnton Johansson                                         uint64_t *cs_base, uint32_t *pflags)
752fcf5ef2aSThomas Huth {
753fcf5ef2aSThomas Huth     uint32_t flags;
754fcf5ef2aSThomas Huth     *pc = env->pc;
755fcf5ef2aSThomas Huth     *cs_base = env->npc;
7563b916140SRichard Henderson     flags = cpu_mmu_index(env_cpu(env), false);
757c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
758c9b459aaSArtyom Tarasenko     if (cpu_supervisor_mode(env)) {
759c9b459aaSArtyom Tarasenko         flags |= TB_FLAG_SUPER;
760c9b459aaSArtyom Tarasenko     }
761c9b459aaSArtyom Tarasenko #endif
762fcf5ef2aSThomas Huth #ifdef TARGET_SPARC64
763c9b459aaSArtyom Tarasenko #ifndef CONFIG_USER_ONLY
764c9b459aaSArtyom Tarasenko     if (cpu_hypervisor_mode(env)) {
765c9b459aaSArtyom Tarasenko         flags |= TB_FLAG_HYPER;
766c9b459aaSArtyom Tarasenko     }
767c9b459aaSArtyom Tarasenko #endif
768fcf5ef2aSThomas Huth     if (env->pstate & PS_AM) {
769fcf5ef2aSThomas Huth         flags |= TB_FLAG_AM_ENABLED;
770fcf5ef2aSThomas Huth     }
7715f25b383SRichard Henderson     if ((env->pstate & PS_PEF) && (env->fprs & FPRS_FEF)) {
772fcf5ef2aSThomas Huth         flags |= TB_FLAG_FPU_ENABLED;
773fcf5ef2aSThomas Huth     }
774fcf5ef2aSThomas Huth     flags |= env->asi << TB_FLAG_ASI_SHIFT;
775fcf5ef2aSThomas Huth #else
7765f25b383SRichard Henderson     if (env->psref) {
777fcf5ef2aSThomas Huth         flags |= TB_FLAG_FPU_ENABLED;
778fcf5ef2aSThomas Huth     }
779*5a165e26SRichard Henderson #ifndef CONFIG_USER_ONLY
780*5a165e26SRichard Henderson     if (env->fsr_qne) {
781*5a165e26SRichard Henderson         flags |= TB_FLAG_FSR_QNE;
782*5a165e26SRichard Henderson     }
783*5a165e26SRichard Henderson #endif /* !CONFIG_USER_ONLY */
784*5a165e26SRichard Henderson #endif /* TARGET_SPARC64 */
785fcf5ef2aSThomas Huth     *pflags = flags;
786fcf5ef2aSThomas Huth }
787fcf5ef2aSThomas Huth 
tb_fpu_enabled(int tb_flags)788fcf5ef2aSThomas Huth static inline bool tb_fpu_enabled(int tb_flags)
789fcf5ef2aSThomas Huth {
790fcf5ef2aSThomas Huth #if defined(CONFIG_USER_ONLY)
791fcf5ef2aSThomas Huth     return true;
792fcf5ef2aSThomas Huth #else
793fcf5ef2aSThomas Huth     return tb_flags & TB_FLAG_FPU_ENABLED;
794fcf5ef2aSThomas Huth #endif
795fcf5ef2aSThomas Huth }
796fcf5ef2aSThomas Huth 
tb_am_enabled(int tb_flags)797fcf5ef2aSThomas Huth static inline bool tb_am_enabled(int tb_flags)
798fcf5ef2aSThomas Huth {
799fcf5ef2aSThomas Huth #ifndef TARGET_SPARC64
800fcf5ef2aSThomas Huth     return false;
801fcf5ef2aSThomas Huth #else
802fcf5ef2aSThomas Huth     return tb_flags & TB_FLAG_AM_ENABLED;
803fcf5ef2aSThomas Huth #endif
804fcf5ef2aSThomas Huth }
805fcf5ef2aSThomas Huth 
8067a5805a0SPeter Maydell #ifdef TARGET_SPARC64
8077a5805a0SPeter Maydell /* win_helper.c */
8087a5805a0SPeter Maydell target_ulong cpu_get_ccr(CPUSPARCState *env1);
8097a5805a0SPeter Maydell void cpu_put_ccr(CPUSPARCState *env1, target_ulong val);
8107a5805a0SPeter Maydell target_ulong cpu_get_cwp64(CPUSPARCState *env1);
8117a5805a0SPeter Maydell void cpu_put_cwp64(CPUSPARCState *env1, int cwp);
8127a5805a0SPeter Maydell 
sparc64_tstate(CPUSPARCState * env)8137a5805a0SPeter Maydell static inline uint64_t sparc64_tstate(CPUSPARCState *env)
8147a5805a0SPeter Maydell {
8157a5805a0SPeter Maydell     uint64_t tstate = (cpu_get_ccr(env) << 32) |
8167a5805a0SPeter Maydell         ((env->asi & 0xff) << 24) | ((env->pstate & 0xf3f) << 8) |
8177a5805a0SPeter Maydell         cpu_get_cwp64(env);
8187a5805a0SPeter Maydell 
8197a5805a0SPeter Maydell     if (env->def.features & CPU_FEATURE_GL) {
8207a5805a0SPeter Maydell         tstate |= (env->gl & 7ULL) << 40;
8217a5805a0SPeter Maydell     }
8227a5805a0SPeter Maydell     return tstate;
8237a5805a0SPeter Maydell }
8247a5805a0SPeter Maydell #endif
8257a5805a0SPeter Maydell 
826fcf5ef2aSThomas Huth #endif
827