xref: /qemu/target/mips/cpu.h (revision cec56a733dd2c3fa81dbedbecf03922258747f7d)
107f5a258SMarkus Armbruster #ifndef MIPS_CPU_H
207f5a258SMarkus Armbruster #define MIPS_CPU_H
36af0bf9cSbellard 
43e457172SBlue Swirl //#define DEBUG_OP
53e457172SBlue Swirl 
6d94f0a8eSPaolo Bonzini #define ALIGNED_ONLY
74ad40f36Sbellard 
89349b4f9SAndreas Färber #define CPUArchState struct CPUMIPSState
9c2764719Spbrook 
109a78eeadSStefan Weil #include "qemu-common.h"
11416bf936SPaolo Bonzini #include "cpu-qom.h"
126af0bf9cSbellard #include "mips-defs.h"
13022c62cbSPaolo Bonzini #include "exec/cpu-defs.h"
146b4c305cSPaolo Bonzini #include "fpu/softfloat.h"
156af0bf9cSbellard 
16ead9360eSths struct CPUMIPSState;
176af0bf9cSbellard 
18c227f099SAnthony Liguori typedef struct r4k_tlb_t r4k_tlb_t;
19c227f099SAnthony Liguori struct r4k_tlb_t {
206af0bf9cSbellard     target_ulong VPN;
219c2149c8Sths     uint32_t PageMask;
222d72e7b0SPaul Burton     uint16_t ASID;
23d783f789SPeter Maydell     unsigned int G:1;
24d783f789SPeter Maydell     unsigned int C0:3;
25d783f789SPeter Maydell     unsigned int C1:3;
26d783f789SPeter Maydell     unsigned int V0:1;
27d783f789SPeter Maydell     unsigned int V1:1;
28d783f789SPeter Maydell     unsigned int D0:1;
29d783f789SPeter Maydell     unsigned int D1:1;
30d783f789SPeter Maydell     unsigned int XI0:1;
31d783f789SPeter Maydell     unsigned int XI1:1;
32d783f789SPeter Maydell     unsigned int RI0:1;
33d783f789SPeter Maydell     unsigned int RI1:1;
34d783f789SPeter Maydell     unsigned int EHINV:1;
35284b731aSLeon Alrae     uint64_t PFN[2];
366af0bf9cSbellard };
376af0bf9cSbellard 
383c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
39ead9360eSths typedef struct CPUMIPSTLBContext CPUMIPSTLBContext;
40ead9360eSths struct CPUMIPSTLBContext {
41ead9360eSths     uint32_t nb_tlb;
42ead9360eSths     uint32_t tlb_in_use;
43a8170e5eSAvi Kivity     int (*map_address) (struct CPUMIPSState *env, hwaddr *physical, int *prot, target_ulong address, int rw, int access_type);
44895c2d04SBlue Swirl     void (*helper_tlbwi)(struct CPUMIPSState *env);
45895c2d04SBlue Swirl     void (*helper_tlbwr)(struct CPUMIPSState *env);
46895c2d04SBlue Swirl     void (*helper_tlbp)(struct CPUMIPSState *env);
47895c2d04SBlue Swirl     void (*helper_tlbr)(struct CPUMIPSState *env);
489456c2fbSLeon Alrae     void (*helper_tlbinv)(struct CPUMIPSState *env);
499456c2fbSLeon Alrae     void (*helper_tlbinvf)(struct CPUMIPSState *env);
50ead9360eSths     union {
51ead9360eSths         struct {
52c227f099SAnthony Liguori             r4k_tlb_t tlb[MIPS_TLB_MAX];
53ead9360eSths         } r4k;
54ead9360eSths     } mmu;
55ead9360eSths };
563c7b48b7SPaul Brook #endif
5751b2772fSths 
58e97a391dSYongbok Kim /* MSA Context */
59e97a391dSYongbok Kim #define MSA_WRLEN (128)
60e97a391dSYongbok Kim 
61e97a391dSYongbok Kim enum CPUMIPSMSADataFormat {
62e97a391dSYongbok Kim     DF_BYTE = 0,
63e97a391dSYongbok Kim     DF_HALF,
64e97a391dSYongbok Kim     DF_WORD,
65e97a391dSYongbok Kim     DF_DOUBLE
66e97a391dSYongbok Kim };
67e97a391dSYongbok Kim 
68e97a391dSYongbok Kim typedef union wr_t wr_t;
69e97a391dSYongbok Kim union wr_t {
70e97a391dSYongbok Kim     int8_t  b[MSA_WRLEN/8];
71e97a391dSYongbok Kim     int16_t h[MSA_WRLEN/16];
72e97a391dSYongbok Kim     int32_t w[MSA_WRLEN/32];
73e97a391dSYongbok Kim     int64_t d[MSA_WRLEN/64];
74e97a391dSYongbok Kim };
75e97a391dSYongbok Kim 
76c227f099SAnthony Liguori typedef union fpr_t fpr_t;
77c227f099SAnthony Liguori union fpr_t {
78ead9360eSths     float64  fd;   /* ieee double precision */
79ead9360eSths     float32  fs[2];/* ieee single precision */
80ead9360eSths     uint64_t d;    /* binary double fixed-point */
81ead9360eSths     uint32_t w[2]; /* binary single fixed-point */
82e97a391dSYongbok Kim /* FPU/MSA register mapping is not tested on big-endian hosts. */
83e97a391dSYongbok Kim     wr_t     wr;   /* vector data */
84ead9360eSths };
85ead9360eSths /* define FP_ENDIAN_IDX to access the same location
864ff9786cSStefan Weil  * in the fpr_t union regardless of the host endianness
87ead9360eSths  */
88e2542fe2SJuan Quintela #if defined(HOST_WORDS_BIGENDIAN)
89ead9360eSths #  define FP_ENDIAN_IDX 1
90ead9360eSths #else
91ead9360eSths #  define FP_ENDIAN_IDX 0
92c570fd16Sths #endif
93ead9360eSths 
94ead9360eSths typedef struct CPUMIPSFPUContext CPUMIPSFPUContext;
95ead9360eSths struct CPUMIPSFPUContext {
966af0bf9cSbellard     /* Floating point registers */
97c227f099SAnthony Liguori     fpr_t fpr[32];
986ea83fedSbellard     float_status fp_status;
995a5012ecSths     /* fpu implementation/revision register (fir) */
1006af0bf9cSbellard     uint32_t fcr0;
1017c979afdSLeon Alrae #define FCR0_FREP 29
102b4dd99a3SPetar Jovanovic #define FCR0_UFRP 28
103ba5c79f2SLeon Alrae #define FCR0_HAS2008 23
1045a5012ecSths #define FCR0_F64 22
1055a5012ecSths #define FCR0_L 21
1065a5012ecSths #define FCR0_W 20
1075a5012ecSths #define FCR0_3D 19
1085a5012ecSths #define FCR0_PS 18
1095a5012ecSths #define FCR0_D 17
1105a5012ecSths #define FCR0_S 16
1115a5012ecSths #define FCR0_PRID 8
1125a5012ecSths #define FCR0_REV 0
1136ea83fedSbellard     /* fcsr */
114599bc5e8SAleksandar Markovic     uint32_t fcr31_rw_bitmask;
1156ea83fedSbellard     uint32_t fcr31;
11677be4199SAleksandar Markovic #define FCR31_FS 24
117ba5c79f2SLeon Alrae #define FCR31_ABS2008 19
118ba5c79f2SLeon Alrae #define FCR31_NAN2008 18
119f01be154Sths #define SET_FP_COND(num,env)     do { ((env).fcr31) |= ((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
120f01be154Sths #define CLEAR_FP_COND(num,env)   do { ((env).fcr31) &= ~((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
121f01be154Sths #define GET_FP_COND(env)         ((((env).fcr31 >> 24) & 0xfe) | (((env).fcr31 >> 23) & 0x1))
1226ea83fedSbellard #define GET_FP_CAUSE(reg)        (((reg) >> 12) & 0x3f)
1236ea83fedSbellard #define GET_FP_ENABLE(reg)       (((reg) >>  7) & 0x1f)
1246ea83fedSbellard #define GET_FP_FLAGS(reg)        (((reg) >>  2) & 0x1f)
1255a5012ecSths #define SET_FP_CAUSE(reg,v)      do { (reg) = ((reg) & ~(0x3f << 12)) | ((v & 0x3f) << 12); } while(0)
1265a5012ecSths #define SET_FP_ENABLE(reg,v)     do { (reg) = ((reg) & ~(0x1f <<  7)) | ((v & 0x1f) << 7); } while(0)
1275a5012ecSths #define SET_FP_FLAGS(reg,v)      do { (reg) = ((reg) & ~(0x1f <<  2)) | ((v & 0x1f) << 2); } while(0)
1285a5012ecSths #define UPDATE_FP_FLAGS(reg,v)   do { (reg) |= ((v & 0x1f) << 2); } while(0)
1296ea83fedSbellard #define FP_INEXACT        1
1306ea83fedSbellard #define FP_UNDERFLOW      2
1316ea83fedSbellard #define FP_OVERFLOW       4
1326ea83fedSbellard #define FP_DIV0           8
1336ea83fedSbellard #define FP_INVALID        16
1346ea83fedSbellard #define FP_UNIMPLEMENTED  32
135ead9360eSths };
1366ea83fedSbellard 
13742c86612SJames Hogan #define NB_MMU_MODES 4
138c20d594eSRichard Henderson #define TARGET_INSN_START_EXTRA_WORDS 2
1396ebbf390Sj_mayer 
140ead9360eSths typedef struct CPUMIPSMVPContext CPUMIPSMVPContext;
141ead9360eSths struct CPUMIPSMVPContext {
142ead9360eSths     int32_t CP0_MVPControl;
143ead9360eSths #define CP0MVPCo_CPA	3
144ead9360eSths #define CP0MVPCo_STLB	2
145ead9360eSths #define CP0MVPCo_VPC	1
146ead9360eSths #define CP0MVPCo_EVP	0
147ead9360eSths     int32_t CP0_MVPConf0;
148ead9360eSths #define CP0MVPC0_M	31
149ead9360eSths #define CP0MVPC0_TLBS	29
150ead9360eSths #define CP0MVPC0_GS	28
151ead9360eSths #define CP0MVPC0_PCP	27
152ead9360eSths #define CP0MVPC0_PTLBE	16
153ead9360eSths #define CP0MVPC0_TCA	15
154ead9360eSths #define CP0MVPC0_PVPE	10
155ead9360eSths #define CP0MVPC0_PTC	0
156ead9360eSths     int32_t CP0_MVPConf1;
157ead9360eSths #define CP0MVPC1_CIM	31
158ead9360eSths #define CP0MVPC1_CIF	30
159ead9360eSths #define CP0MVPC1_PCX	20
160ead9360eSths #define CP0MVPC1_PCP2	10
161ead9360eSths #define CP0MVPC1_PCP1	0
162ead9360eSths };
163ead9360eSths 
164c227f099SAnthony Liguori typedef struct mips_def_t mips_def_t;
165ead9360eSths 
166ead9360eSths #define MIPS_SHADOW_SET_MAX 16
167ead9360eSths #define MIPS_TC_MAX 5
168f01be154Sths #define MIPS_FPU_MAX 1
169ead9360eSths #define MIPS_DSP_ACC 4
170e98c0d17SLeon Alrae #define MIPS_KSCRATCH_NUM 6
171f6d4dd81SYongbok Kim #define MIPS_MAAR_MAX 16 /* Must be an even number. */
172ead9360eSths 
173b5dc7732Sths typedef struct TCState TCState;
174b5dc7732Sths struct TCState {
175b5dc7732Sths     target_ulong gpr[32];
176b5dc7732Sths     target_ulong PC;
177b5dc7732Sths     target_ulong HI[MIPS_DSP_ACC];
178b5dc7732Sths     target_ulong LO[MIPS_DSP_ACC];
179b5dc7732Sths     target_ulong ACX[MIPS_DSP_ACC];
180b5dc7732Sths     target_ulong DSPControl;
181b5dc7732Sths     int32_t CP0_TCStatus;
182b5dc7732Sths #define CP0TCSt_TCU3	31
183b5dc7732Sths #define CP0TCSt_TCU2	30
184b5dc7732Sths #define CP0TCSt_TCU1	29
185b5dc7732Sths #define CP0TCSt_TCU0	28
186b5dc7732Sths #define CP0TCSt_TMX	27
187b5dc7732Sths #define CP0TCSt_RNST	23
188b5dc7732Sths #define CP0TCSt_TDS	21
189b5dc7732Sths #define CP0TCSt_DT	20
190b5dc7732Sths #define CP0TCSt_DA	15
191b5dc7732Sths #define CP0TCSt_A	13
192b5dc7732Sths #define CP0TCSt_TKSU	11
193b5dc7732Sths #define CP0TCSt_IXMT	10
194b5dc7732Sths #define CP0TCSt_TASID	0
195b5dc7732Sths     int32_t CP0_TCBind;
196b5dc7732Sths #define CP0TCBd_CurTC	21
197b5dc7732Sths #define CP0TCBd_TBE	17
198b5dc7732Sths #define CP0TCBd_CurVPE	0
199b5dc7732Sths     target_ulong CP0_TCHalt;
200b5dc7732Sths     target_ulong CP0_TCContext;
201b5dc7732Sths     target_ulong CP0_TCSchedule;
202b5dc7732Sths     target_ulong CP0_TCScheFBack;
203b5dc7732Sths     int32_t CP0_Debug_tcstatus;
204d279279eSPetar Jovanovic     target_ulong CP0_UserLocal;
205e97a391dSYongbok Kim 
206e97a391dSYongbok Kim     int32_t msacsr;
207e97a391dSYongbok Kim 
208e97a391dSYongbok Kim #define MSACSR_FS       24
209e97a391dSYongbok Kim #define MSACSR_FS_MASK  (1 << MSACSR_FS)
210e97a391dSYongbok Kim #define MSACSR_NX       18
211e97a391dSYongbok Kim #define MSACSR_NX_MASK  (1 << MSACSR_NX)
212e97a391dSYongbok Kim #define MSACSR_CEF      2
213e97a391dSYongbok Kim #define MSACSR_CEF_MASK (0xffff << MSACSR_CEF)
214e97a391dSYongbok Kim #define MSACSR_RM       0
215e97a391dSYongbok Kim #define MSACSR_RM_MASK  (0x3 << MSACSR_RM)
216e97a391dSYongbok Kim #define MSACSR_MASK     (MSACSR_RM_MASK | MSACSR_CEF_MASK | MSACSR_NX_MASK | \
217e97a391dSYongbok Kim         MSACSR_FS_MASK)
218e97a391dSYongbok Kim 
219e97a391dSYongbok Kim     float_status msa_fp_status;
220b5dc7732Sths };
221b5dc7732Sths 
222ead9360eSths typedef struct CPUMIPSState CPUMIPSState;
223ead9360eSths struct CPUMIPSState {
224b5dc7732Sths     TCState active_tc;
225f01be154Sths     CPUMIPSFPUContext active_fpu;
226b5dc7732Sths 
227ead9360eSths     uint32_t current_tc;
228f01be154Sths     uint32_t current_fpu;
229ead9360eSths 
230e034e2c3Sths     uint32_t SEGBITS;
2316d35524cSths     uint32_t PABITS;
232e117f526SLeon Alrae #if defined(TARGET_MIPS64)
233e117f526SLeon Alrae # define PABITS_BASE 36
234e117f526SLeon Alrae #else
235e117f526SLeon Alrae # define PABITS_BASE 32
236e117f526SLeon Alrae #endif
237b6d96bedSths     target_ulong SEGMask;
238284b731aSLeon Alrae     uint64_t PAMask;
239e117f526SLeon Alrae #define PAMASK_BASE ((1ULL << PABITS_BASE) - 1)
24029929e34Sths 
241e97a391dSYongbok Kim     int32_t msair;
242e97a391dSYongbok Kim #define MSAIR_ProcID    8
243e97a391dSYongbok Kim #define MSAIR_Rev       0
244e97a391dSYongbok Kim 
2459c2149c8Sths     int32_t CP0_Index;
246ead9360eSths     /* CP0_MVP* are per MVP registers. */
24701bc435bSYongbok Kim     int32_t CP0_VPControl;
24801bc435bSYongbok Kim #define CP0VPCtl_DIS    0
2499c2149c8Sths     int32_t CP0_Random;
250ead9360eSths     int32_t CP0_VPEControl;
251ead9360eSths #define CP0VPECo_YSI	21
252ead9360eSths #define CP0VPECo_GSI	20
253ead9360eSths #define CP0VPECo_EXCPT	16
254ead9360eSths #define CP0VPECo_TE	15
255ead9360eSths #define CP0VPECo_TargTC	0
256ead9360eSths     int32_t CP0_VPEConf0;
257ead9360eSths #define CP0VPEC0_M	31
258ead9360eSths #define CP0VPEC0_XTC	21
259ead9360eSths #define CP0VPEC0_TCS	19
260ead9360eSths #define CP0VPEC0_SCS	18
261ead9360eSths #define CP0VPEC0_DSC	17
262ead9360eSths #define CP0VPEC0_ICS	16
263ead9360eSths #define CP0VPEC0_MVP	1
264ead9360eSths #define CP0VPEC0_VPA	0
265ead9360eSths     int32_t CP0_VPEConf1;
266ead9360eSths #define CP0VPEC1_NCX	20
267ead9360eSths #define CP0VPEC1_NCP2	10
268ead9360eSths #define CP0VPEC1_NCP1	0
269ead9360eSths     target_ulong CP0_YQMask;
270ead9360eSths     target_ulong CP0_VPESchedule;
271ead9360eSths     target_ulong CP0_VPEScheFBack;
272ead9360eSths     int32_t CP0_VPEOpt;
273ead9360eSths #define CP0VPEOpt_IWX7	15
274ead9360eSths #define CP0VPEOpt_IWX6	14
275ead9360eSths #define CP0VPEOpt_IWX5	13
276ead9360eSths #define CP0VPEOpt_IWX4	12
277ead9360eSths #define CP0VPEOpt_IWX3	11
278ead9360eSths #define CP0VPEOpt_IWX2	10
279ead9360eSths #define CP0VPEOpt_IWX1	9
280ead9360eSths #define CP0VPEOpt_IWX0	8
281ead9360eSths #define CP0VPEOpt_DWX7	7
282ead9360eSths #define CP0VPEOpt_DWX6	6
283ead9360eSths #define CP0VPEOpt_DWX5	5
284ead9360eSths #define CP0VPEOpt_DWX4	4
285ead9360eSths #define CP0VPEOpt_DWX3	3
286ead9360eSths #define CP0VPEOpt_DWX2	2
287ead9360eSths #define CP0VPEOpt_DWX1	1
288ead9360eSths #define CP0VPEOpt_DWX0	0
289284b731aSLeon Alrae     uint64_t CP0_EntryLo0;
290284b731aSLeon Alrae     uint64_t CP0_EntryLo1;
2912fb58b73SLeon Alrae #if defined(TARGET_MIPS64)
2922fb58b73SLeon Alrae # define CP0EnLo_RI 63
2932fb58b73SLeon Alrae # define CP0EnLo_XI 62
2942fb58b73SLeon Alrae #else
2952fb58b73SLeon Alrae # define CP0EnLo_RI 31
2962fb58b73SLeon Alrae # define CP0EnLo_XI 30
2972fb58b73SLeon Alrae #endif
29801bc435bSYongbok Kim     int32_t CP0_GlobalNumber;
29901bc435bSYongbok Kim #define CP0GN_VPId 0
3009c2149c8Sths     target_ulong CP0_Context;
301e98c0d17SLeon Alrae     target_ulong CP0_KScratch[MIPS_KSCRATCH_NUM];
3029c2149c8Sths     int32_t CP0_PageMask;
3037207c7f9SLeon Alrae     int32_t CP0_PageGrain_rw_bitmask;
3049c2149c8Sths     int32_t CP0_PageGrain;
3057207c7f9SLeon Alrae #define CP0PG_RIE 31
3067207c7f9SLeon Alrae #define CP0PG_XIE 30
307e117f526SLeon Alrae #define CP0PG_ELPA 29
30892ceb440SLeon Alrae #define CP0PG_IEC 27
309*cec56a73SJames Hogan     target_ulong CP0_SegCtl0;
310*cec56a73SJames Hogan     target_ulong CP0_SegCtl1;
311*cec56a73SJames Hogan     target_ulong CP0_SegCtl2;
312*cec56a73SJames Hogan #define CP0SC_PA        9
313*cec56a73SJames Hogan #define CP0SC_PA_MASK   (0x7FULL << CP0SC_PA)
314*cec56a73SJames Hogan #define CP0SC_PA_1GMASK (0x7EULL << CP0SC_PA)
315*cec56a73SJames Hogan #define CP0SC_AM        4
316*cec56a73SJames Hogan #define CP0SC_AM_MASK   (0x7ULL << CP0SC_AM)
317*cec56a73SJames Hogan #define CP0SC_AM_UK     0ULL
318*cec56a73SJames Hogan #define CP0SC_AM_MK     1ULL
319*cec56a73SJames Hogan #define CP0SC_AM_MSK    2ULL
320*cec56a73SJames Hogan #define CP0SC_AM_MUSK   3ULL
321*cec56a73SJames Hogan #define CP0SC_AM_MUSUK  4ULL
322*cec56a73SJames Hogan #define CP0SC_AM_USK    5ULL
323*cec56a73SJames Hogan #define CP0SC_AM_UUSK   7ULL
324*cec56a73SJames Hogan #define CP0SC_EU        3
325*cec56a73SJames Hogan #define CP0SC_EU_MASK   (1ULL << CP0SC_EU)
326*cec56a73SJames Hogan #define CP0SC_C         0
327*cec56a73SJames Hogan #define CP0SC_C_MASK    (0x7ULL << CP0SC_C)
328*cec56a73SJames Hogan #define CP0SC_MASK      (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
329*cec56a73SJames Hogan                          CP0SC_PA_MASK)
330*cec56a73SJames Hogan #define CP0SC_1GMASK    (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
331*cec56a73SJames Hogan                          CP0SC_PA_1GMASK)
332*cec56a73SJames Hogan #define CP0SC0_MASK     (CP0SC_MASK | (CP0SC_MASK << 16))
333*cec56a73SJames Hogan #define CP0SC1_XAM      59
334*cec56a73SJames Hogan #define CP0SC1_XAM_MASK (0x7ULL << CP0SC1_XAM)
335*cec56a73SJames Hogan #define CP0SC1_MASK     (CP0SC_MASK | (CP0SC_MASK << 16) | CP0SC1_XAM_MASK)
336*cec56a73SJames Hogan #define CP0SC2_XR       56
337*cec56a73SJames Hogan #define CP0SC2_XR_MASK  (0xFFULL << CP0SC2_XR)
338*cec56a73SJames Hogan #define CP0SC2_MASK     (CP0SC_1GMASK | (CP0SC_1GMASK << 16) | CP0SC2_XR_MASK)
3399c2149c8Sths     int32_t CP0_Wired;
340ead9360eSths     int32_t CP0_SRSConf0_rw_bitmask;
341ead9360eSths     int32_t CP0_SRSConf0;
342ead9360eSths #define CP0SRSC0_M	31
343ead9360eSths #define CP0SRSC0_SRS3	20
344ead9360eSths #define CP0SRSC0_SRS2	10
345ead9360eSths #define CP0SRSC0_SRS1	0
346ead9360eSths     int32_t CP0_SRSConf1_rw_bitmask;
347ead9360eSths     int32_t CP0_SRSConf1;
348ead9360eSths #define CP0SRSC1_M	31
349ead9360eSths #define CP0SRSC1_SRS6	20
350ead9360eSths #define CP0SRSC1_SRS5	10
351ead9360eSths #define CP0SRSC1_SRS4	0
352ead9360eSths     int32_t CP0_SRSConf2_rw_bitmask;
353ead9360eSths     int32_t CP0_SRSConf2;
354ead9360eSths #define CP0SRSC2_M	31
355ead9360eSths #define CP0SRSC2_SRS9	20
356ead9360eSths #define CP0SRSC2_SRS8	10
357ead9360eSths #define CP0SRSC2_SRS7	0
358ead9360eSths     int32_t CP0_SRSConf3_rw_bitmask;
359ead9360eSths     int32_t CP0_SRSConf3;
360ead9360eSths #define CP0SRSC3_M	31
361ead9360eSths #define CP0SRSC3_SRS12	20
362ead9360eSths #define CP0SRSC3_SRS11	10
363ead9360eSths #define CP0SRSC3_SRS10	0
364ead9360eSths     int32_t CP0_SRSConf4_rw_bitmask;
365ead9360eSths     int32_t CP0_SRSConf4;
366ead9360eSths #define CP0SRSC4_SRS15	20
367ead9360eSths #define CP0SRSC4_SRS14	10
368ead9360eSths #define CP0SRSC4_SRS13	0
3699c2149c8Sths     int32_t CP0_HWREna;
370c570fd16Sths     target_ulong CP0_BadVAddr;
371aea14095SLeon Alrae     uint32_t CP0_BadInstr;
372aea14095SLeon Alrae     uint32_t CP0_BadInstrP;
3739c2149c8Sths     int32_t CP0_Count;
3749c2149c8Sths     target_ulong CP0_EntryHi;
3759456c2fbSLeon Alrae #define CP0EnHi_EHINV 10
3766ec98bd7SPaul Burton     target_ulong CP0_EntryHi_ASID_mask;
3779c2149c8Sths     int32_t CP0_Compare;
3789c2149c8Sths     int32_t CP0_Status;
3796af0bf9cSbellard #define CP0St_CU3   31
3806af0bf9cSbellard #define CP0St_CU2   30
3816af0bf9cSbellard #define CP0St_CU1   29
3826af0bf9cSbellard #define CP0St_CU0   28
3836af0bf9cSbellard #define CP0St_RP    27
3846ea83fedSbellard #define CP0St_FR    26
3856af0bf9cSbellard #define CP0St_RE    25
3867a387fffSths #define CP0St_MX    24
3877a387fffSths #define CP0St_PX    23
3886af0bf9cSbellard #define CP0St_BEV   22
3896af0bf9cSbellard #define CP0St_TS    21
3906af0bf9cSbellard #define CP0St_SR    20
3916af0bf9cSbellard #define CP0St_NMI   19
3926af0bf9cSbellard #define CP0St_IM    8
3937a387fffSths #define CP0St_KX    7
3947a387fffSths #define CP0St_SX    6
3957a387fffSths #define CP0St_UX    5
396623a930eSths #define CP0St_KSU   3
3976af0bf9cSbellard #define CP0St_ERL   2
3986af0bf9cSbellard #define CP0St_EXL   1
3996af0bf9cSbellard #define CP0St_IE    0
4009c2149c8Sths     int32_t CP0_IntCtl;
401ead9360eSths #define CP0IntCtl_IPTI 29
40288991299SDongxue Zhang #define CP0IntCtl_IPPCI 26
403ead9360eSths #define CP0IntCtl_VS 5
4049c2149c8Sths     int32_t CP0_SRSCtl;
405ead9360eSths #define CP0SRSCtl_HSS 26
406ead9360eSths #define CP0SRSCtl_EICSS 18
407ead9360eSths #define CP0SRSCtl_ESS 12
408ead9360eSths #define CP0SRSCtl_PSS 6
409ead9360eSths #define CP0SRSCtl_CSS 0
4109c2149c8Sths     int32_t CP0_SRSMap;
411ead9360eSths #define CP0SRSMap_SSV7 28
412ead9360eSths #define CP0SRSMap_SSV6 24
413ead9360eSths #define CP0SRSMap_SSV5 20
414ead9360eSths #define CP0SRSMap_SSV4 16
415ead9360eSths #define CP0SRSMap_SSV3 12
416ead9360eSths #define CP0SRSMap_SSV2 8
417ead9360eSths #define CP0SRSMap_SSV1 4
418ead9360eSths #define CP0SRSMap_SSV0 0
4199c2149c8Sths     int32_t CP0_Cause;
4207a387fffSths #define CP0Ca_BD   31
4217a387fffSths #define CP0Ca_TI   30
4227a387fffSths #define CP0Ca_CE   28
4237a387fffSths #define CP0Ca_DC   27
4247a387fffSths #define CP0Ca_PCI  26
4256af0bf9cSbellard #define CP0Ca_IV   23
4267a387fffSths #define CP0Ca_WP   22
4277a387fffSths #define CP0Ca_IP    8
4284de9b249Sths #define CP0Ca_IP_mask 0x0000FF00
4297a387fffSths #define CP0Ca_EC    2
430c570fd16Sths     target_ulong CP0_EPC;
4319c2149c8Sths     int32_t CP0_PRid;
43274dbf824SJames Hogan     target_ulong CP0_EBase;
43374dbf824SJames Hogan     target_ulong CP0_EBaseWG_rw_bitmask;
43474dbf824SJames Hogan #define CP0EBase_WG 11
435c870e3f5SYongbok Kim     target_ulong CP0_CMGCRBase;
4369c2149c8Sths     int32_t CP0_Config0;
4376af0bf9cSbellard #define CP0C0_M    31
4386af0bf9cSbellard #define CP0C0_K23  28
4396af0bf9cSbellard #define CP0C0_KU   25
4406af0bf9cSbellard #define CP0C0_MDU  20
441aff2bc6dSYongbok Kim #define CP0C0_MM   18
4426af0bf9cSbellard #define CP0C0_BM   16
4436af0bf9cSbellard #define CP0C0_BE   15
4446af0bf9cSbellard #define CP0C0_AT   13
4456af0bf9cSbellard #define CP0C0_AR   10
4466af0bf9cSbellard #define CP0C0_MT   7
4477a387fffSths #define CP0C0_VI   3
4486af0bf9cSbellard #define CP0C0_K0   0
4499c2149c8Sths     int32_t CP0_Config1;
4507a387fffSths #define CP0C1_M    31
4516af0bf9cSbellard #define CP0C1_MMU  25
4526af0bf9cSbellard #define CP0C1_IS   22
4536af0bf9cSbellard #define CP0C1_IL   19
4546af0bf9cSbellard #define CP0C1_IA   16
4556af0bf9cSbellard #define CP0C1_DS   13
4566af0bf9cSbellard #define CP0C1_DL   10
4576af0bf9cSbellard #define CP0C1_DA   7
4587a387fffSths #define CP0C1_C2   6
4597a387fffSths #define CP0C1_MD   5
4606af0bf9cSbellard #define CP0C1_PC   4
4616af0bf9cSbellard #define CP0C1_WR   3
4626af0bf9cSbellard #define CP0C1_CA   2
4636af0bf9cSbellard #define CP0C1_EP   1
4646af0bf9cSbellard #define CP0C1_FP   0
4659c2149c8Sths     int32_t CP0_Config2;
4667a387fffSths #define CP0C2_M    31
4677a387fffSths #define CP0C2_TU   28
4687a387fffSths #define CP0C2_TS   24
4697a387fffSths #define CP0C2_TL   20
4707a387fffSths #define CP0C2_TA   16
4717a387fffSths #define CP0C2_SU   12
4727a387fffSths #define CP0C2_SS   8
4737a387fffSths #define CP0C2_SL   4
4747a387fffSths #define CP0C2_SA   0
4759c2149c8Sths     int32_t CP0_Config3;
4767a387fffSths #define CP0C3_M    31
47770409e67SMaciej W. Rozycki #define CP0C3_BPG  30
478c870e3f5SYongbok Kim #define CP0C3_CMGCR 29
479e97a391dSYongbok Kim #define CP0C3_MSAP  28
480aea14095SLeon Alrae #define CP0C3_BP 27
481aea14095SLeon Alrae #define CP0C3_BI 26
48274dbf824SJames Hogan #define CP0C3_SC 25
48370409e67SMaciej W. Rozycki #define CP0C3_IPLW 21
48470409e67SMaciej W. Rozycki #define CP0C3_MMAR 18
48570409e67SMaciej W. Rozycki #define CP0C3_MCU  17
486bbfa8f72SNathan Froyd #define CP0C3_ISA_ON_EXC 16
48770409e67SMaciej W. Rozycki #define CP0C3_ISA  14
488d279279eSPetar Jovanovic #define CP0C3_ULRI 13
4897207c7f9SLeon Alrae #define CP0C3_RXI  12
49070409e67SMaciej W. Rozycki #define CP0C3_DSP2P 11
4917a387fffSths #define CP0C3_DSPP 10
4927a387fffSths #define CP0C3_LPA  7
4937a387fffSths #define CP0C3_VEIC 6
4947a387fffSths #define CP0C3_VInt 5
4957a387fffSths #define CP0C3_SP   4
49670409e67SMaciej W. Rozycki #define CP0C3_CDMM 3
4977a387fffSths #define CP0C3_MT   2
4987a387fffSths #define CP0C3_SM   1
4997a387fffSths #define CP0C3_TL   0
5008280b12cSMaciej W. Rozycki     int32_t CP0_Config4;
5018280b12cSMaciej W. Rozycki     int32_t CP0_Config4_rw_bitmask;
502b4160af1SPetar Jovanovic #define CP0C4_M    31
5039456c2fbSLeon Alrae #define CP0C4_IE   29
504a0c80608SPaul Burton #define CP0C4_AE   28
505e98c0d17SLeon Alrae #define CP0C4_KScrExist 16
50670409e67SMaciej W. Rozycki #define CP0C4_MMUExtDef 14
50770409e67SMaciej W. Rozycki #define CP0C4_FTLBPageSize 8
50870409e67SMaciej W. Rozycki #define CP0C4_FTLBWays 4
50970409e67SMaciej W. Rozycki #define CP0C4_FTLBSets 0
51070409e67SMaciej W. Rozycki #define CP0C4_MMUSizeExt 0
5118280b12cSMaciej W. Rozycki     int32_t CP0_Config5;
5128280b12cSMaciej W. Rozycki     int32_t CP0_Config5_rw_bitmask;
513b4dd99a3SPetar Jovanovic #define CP0C5_M          31
514b4dd99a3SPetar Jovanovic #define CP0C5_K          30
515b4dd99a3SPetar Jovanovic #define CP0C5_CV         29
516b4dd99a3SPetar Jovanovic #define CP0C5_EVA        28
517b4dd99a3SPetar Jovanovic #define CP0C5_MSAEn      27
518b00c7218SYongbok Kim #define CP0C5_XNP        13
5197c979afdSLeon Alrae #define CP0C5_UFE        9
5207c979afdSLeon Alrae #define CP0C5_FRE        8
52101bc435bSYongbok Kim #define CP0C5_VP         7
522faf1f68bSLeon Alrae #define CP0C5_SBRI       6
5235204ea79SLeon Alrae #define CP0C5_MVH        5
524ce9782f4SLeon Alrae #define CP0C5_LLB        4
525f6d4dd81SYongbok Kim #define CP0C5_MRP        3
526b4dd99a3SPetar Jovanovic #define CP0C5_UFR        2
527b4dd99a3SPetar Jovanovic #define CP0C5_NFExists   0
528e397ee33Sths     int32_t CP0_Config6;
529e397ee33Sths     int32_t CP0_Config7;
530f6d4dd81SYongbok Kim     uint64_t CP0_MAAR[MIPS_MAAR_MAX];
531f6d4dd81SYongbok Kim     int32_t CP0_MAARI;
532ead9360eSths     /* XXX: Maybe make LLAddr per-TC? */
533284b731aSLeon Alrae     uint64_t lladdr;
534590bc601SPaul Brook     target_ulong llval;
535590bc601SPaul Brook     target_ulong llnewval;
536590bc601SPaul Brook     target_ulong llreg;
537284b731aSLeon Alrae     uint64_t CP0_LLAddr_rw_bitmask;
5382a6e32ddSAurelien Jarno     int CP0_LLAddr_shift;
539fd88b6abSths     target_ulong CP0_WatchLo[8];
540fd88b6abSths     int32_t CP0_WatchHi[8];
5416ec98bd7SPaul Burton #define CP0WH_ASID 16
5429c2149c8Sths     target_ulong CP0_XContext;
5439c2149c8Sths     int32_t CP0_Framemask;
5449c2149c8Sths     int32_t CP0_Debug;
545ead9360eSths #define CP0DB_DBD  31
5466af0bf9cSbellard #define CP0DB_DM   30
5476af0bf9cSbellard #define CP0DB_LSNM 28
5486af0bf9cSbellard #define CP0DB_Doze 27
5496af0bf9cSbellard #define CP0DB_Halt 26
5506af0bf9cSbellard #define CP0DB_CNT  25
5516af0bf9cSbellard #define CP0DB_IBEP 24
5526af0bf9cSbellard #define CP0DB_DBEP 21
5536af0bf9cSbellard #define CP0DB_IEXI 20
5546af0bf9cSbellard #define CP0DB_VER  15
5556af0bf9cSbellard #define CP0DB_DEC  10
5566af0bf9cSbellard #define CP0DB_SSt  8
5576af0bf9cSbellard #define CP0DB_DINT 5
5586af0bf9cSbellard #define CP0DB_DIB  4
5596af0bf9cSbellard #define CP0DB_DDBS 3
5606af0bf9cSbellard #define CP0DB_DDBL 2
5616af0bf9cSbellard #define CP0DB_DBp  1
5626af0bf9cSbellard #define CP0DB_DSS  0
563c570fd16Sths     target_ulong CP0_DEPC;
5649c2149c8Sths     int32_t CP0_Performance0;
5650d74a222SLeon Alrae     int32_t CP0_ErrCtl;
5660d74a222SLeon Alrae #define CP0EC_WST 29
5670d74a222SLeon Alrae #define CP0EC_SPR 28
5680d74a222SLeon Alrae #define CP0EC_ITC 26
569284b731aSLeon Alrae     uint64_t CP0_TagLo;
5709c2149c8Sths     int32_t CP0_DataLo;
5719c2149c8Sths     int32_t CP0_TagHi;
5729c2149c8Sths     int32_t CP0_DataHi;
573c570fd16Sths     target_ulong CP0_ErrorEPC;
5749c2149c8Sths     int32_t CP0_DESAVE;
575b5dc7732Sths     /* We waste some space so we can handle shadow registers like TCs. */
576b5dc7732Sths     TCState tcs[MIPS_SHADOW_SET_MAX];
577f01be154Sths     CPUMIPSFPUContext fpus[MIPS_FPU_MAX];
5785cbdb3a3SStefan Weil     /* QEMU */
5796af0bf9cSbellard     int error_code;
580aea14095SLeon Alrae #define EXCP_TLB_NOMATCH   0x1
581aea14095SLeon Alrae #define EXCP_INST_NOTAVAIL 0x2 /* No valid instruction word for BadInstr */
5826af0bf9cSbellard     uint32_t hflags;    /* CPU State */
5836af0bf9cSbellard     /* TMASK defines different execution modes */
58442c86612SJames Hogan #define MIPS_HFLAG_TMASK  0x1F5807FF
58579ef2c4cSNathan Froyd #define MIPS_HFLAG_MODE   0x00007 /* execution modes                    */
586623a930eSths     /* The KSU flags must be the lowest bits in hflags. The flag order
587623a930eSths        must be the same as defined for CP0 Status. This allows to use
588623a930eSths        the bits as the value of mmu_idx. */
58979ef2c4cSNathan Froyd #define MIPS_HFLAG_KSU    0x00003 /* kernel/supervisor/user mode mask   */
59079ef2c4cSNathan Froyd #define MIPS_HFLAG_UM     0x00002 /* user mode flag                     */
59179ef2c4cSNathan Froyd #define MIPS_HFLAG_SM     0x00001 /* supervisor mode flag               */
59279ef2c4cSNathan Froyd #define MIPS_HFLAG_KM     0x00000 /* kernel mode flag                   */
59379ef2c4cSNathan Froyd #define MIPS_HFLAG_DM     0x00004 /* Debug mode                         */
59479ef2c4cSNathan Froyd #define MIPS_HFLAG_64     0x00008 /* 64-bit instructions enabled        */
59579ef2c4cSNathan Froyd #define MIPS_HFLAG_CP0    0x00010 /* CP0 enabled                        */
59679ef2c4cSNathan Froyd #define MIPS_HFLAG_FPU    0x00020 /* FPU enabled                        */
59779ef2c4cSNathan Froyd #define MIPS_HFLAG_F64    0x00040 /* 64-bit FPU enabled                 */
598b8aa4598Sths     /* True if the MIPS IV COP1X instructions can be used.  This also
599b8aa4598Sths        controls the non-COP1X instructions RECIP.S, RECIP.D, RSQRT.S
600b8aa4598Sths        and RSQRT.D.  */
60179ef2c4cSNathan Froyd #define MIPS_HFLAG_COP1X  0x00080 /* COP1X instructions enabled         */
60279ef2c4cSNathan Froyd #define MIPS_HFLAG_RE     0x00100 /* Reversed endianness                */
60301f72885SLeon Alrae #define MIPS_HFLAG_AWRAP  0x00200 /* 32-bit compatibility address wrapping */
60479ef2c4cSNathan Froyd #define MIPS_HFLAG_M16    0x00400 /* MIPS16 mode flag                   */
60579ef2c4cSNathan Froyd #define MIPS_HFLAG_M16_SHIFT 10
6064ad40f36Sbellard     /* If translation is interrupted between the branch instruction and
6074ad40f36Sbellard      * the delay slot, record what type of branch it is so that we can
6084ad40f36Sbellard      * resume translation properly.  It might be possible to reduce
6094ad40f36Sbellard      * this from three bits to two.  */
610339cd2a8SLeon Alrae #define MIPS_HFLAG_BMASK_BASE  0x803800
61179ef2c4cSNathan Froyd #define MIPS_HFLAG_B      0x00800 /* Unconditional branch               */
61279ef2c4cSNathan Froyd #define MIPS_HFLAG_BC     0x01000 /* Conditional branch                 */
61379ef2c4cSNathan Froyd #define MIPS_HFLAG_BL     0x01800 /* Likely branch                      */
61479ef2c4cSNathan Froyd #define MIPS_HFLAG_BR     0x02000 /* branch to register (can't link TB) */
61579ef2c4cSNathan Froyd     /* Extra flags about the current pending branch.  */
616b231c103SYongbok Kim #define MIPS_HFLAG_BMASK_EXT 0x7C000
61779ef2c4cSNathan Froyd #define MIPS_HFLAG_B16    0x04000 /* branch instruction was 16 bits     */
61879ef2c4cSNathan Froyd #define MIPS_HFLAG_BDS16  0x08000 /* branch requires 16-bit delay slot  */
61979ef2c4cSNathan Froyd #define MIPS_HFLAG_BDS32  0x10000 /* branch requires 32-bit delay slot  */
620b231c103SYongbok Kim #define MIPS_HFLAG_BDS_STRICT  0x20000 /* Strict delay slot size */
621b231c103SYongbok Kim #define MIPS_HFLAG_BX     0x40000 /* branch exchanges execution mode    */
62279ef2c4cSNathan Froyd #define MIPS_HFLAG_BMASK  (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT)
623853c3240SJia Liu     /* MIPS DSP resources access. */
624b231c103SYongbok Kim #define MIPS_HFLAG_DSP   0x080000  /* Enable access to MIPS DSP resources. */
625b231c103SYongbok Kim #define MIPS_HFLAG_DSPR2 0x100000  /* Enable access to MIPS DSPR2 resources. */
626d279279eSPetar Jovanovic     /* Extra flag about HWREna register. */
627b231c103SYongbok Kim #define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */
628faf1f68bSLeon Alrae #define MIPS_HFLAG_SBRI  0x400000 /* R6 SDBBP causes RI excpt. in user mode */
629339cd2a8SLeon Alrae #define MIPS_HFLAG_FBNSLOT 0x800000 /* Forbidden slot                   */
630e97a391dSYongbok Kim #define MIPS_HFLAG_MSA   0x1000000
6317c979afdSLeon Alrae #define MIPS_HFLAG_FRE   0x2000000 /* FRE enabled */
632e117f526SLeon Alrae #define MIPS_HFLAG_ELPA  0x4000000
6330d74a222SLeon Alrae #define MIPS_HFLAG_ITC_CACHE  0x8000000 /* CACHE instr. operates on ITC tag */
63442c86612SJames Hogan #define MIPS_HFLAG_ERL   0x10000000 /* error level flag */
6356af0bf9cSbellard     target_ulong btarget;        /* Jump / branch target               */
6361ba74fb8Saurel32     target_ulong bcond;          /* Branch condition (if needed)       */
637a316d335Sbellard 
6387a387fffSths     int SYNCI_Step; /* Address step size for SYNCI */
6397a387fffSths     int CCRes; /* Cycle count resolution/divisor */
640ead9360eSths     uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */
641ead9360eSths     uint32_t CP0_TCStatus_rw_bitmask; /* Read/write bits in CP0_TCStatus */
642e189e748Sths     int insn_flags; /* Supported instruction set */
6437a387fffSths 
6441f5c00cfSAlex Bennée     /* Fields up to this point are cleared by a CPU reset */
6451f5c00cfSAlex Bennée     struct {} end_reset_fields;
6461f5c00cfSAlex Bennée 
647a316d335Sbellard     CPU_COMMON
6486ae81775Sths 
649f0c3c505SAndreas Färber     /* Fields from here on are preserved across CPU reset. */
65051cc2e78SBlue Swirl     CPUMIPSMVPContext *mvp;
6513c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
65251cc2e78SBlue Swirl     CPUMIPSTLBContext *tlb;
6533c7b48b7SPaul Brook #endif
65451cc2e78SBlue Swirl 
655c227f099SAnthony Liguori     const mips_def_t *cpu_model;
65633ac7f16Sths     void *irq[8];
6571246b259SStefan Weil     QEMUTimer *timer; /* Internal timer */
65834fa7e83SLeon Alrae     MemoryRegion *itc_tag; /* ITC Configuration Tags */
65989777fd1SLeon Alrae     target_ulong exception_base; /* ExceptionBase input to the core */
6606af0bf9cSbellard };
6616af0bf9cSbellard 
662416bf936SPaolo Bonzini /**
663416bf936SPaolo Bonzini  * MIPSCPU:
664416bf936SPaolo Bonzini  * @env: #CPUMIPSState
665416bf936SPaolo Bonzini  *
666416bf936SPaolo Bonzini  * A MIPS CPU.
667416bf936SPaolo Bonzini  */
668416bf936SPaolo Bonzini struct MIPSCPU {
669416bf936SPaolo Bonzini     /*< private >*/
670416bf936SPaolo Bonzini     CPUState parent_obj;
671416bf936SPaolo Bonzini     /*< public >*/
672416bf936SPaolo Bonzini 
673416bf936SPaolo Bonzini     CPUMIPSState env;
674416bf936SPaolo Bonzini };
675416bf936SPaolo Bonzini 
676416bf936SPaolo Bonzini static inline MIPSCPU *mips_env_get_cpu(CPUMIPSState *env)
677416bf936SPaolo Bonzini {
678416bf936SPaolo Bonzini     return container_of(env, MIPSCPU, env);
679416bf936SPaolo Bonzini }
680416bf936SPaolo Bonzini 
681416bf936SPaolo Bonzini #define ENV_GET_CPU(e) CPU(mips_env_get_cpu(e))
682416bf936SPaolo Bonzini 
683416bf936SPaolo Bonzini #define ENV_OFFSET offsetof(MIPSCPU, env)
684416bf936SPaolo Bonzini 
685416bf936SPaolo Bonzini #ifndef CONFIG_USER_ONLY
686416bf936SPaolo Bonzini extern const struct VMStateDescription vmstate_mips_cpu;
687416bf936SPaolo Bonzini #endif
688416bf936SPaolo Bonzini 
689416bf936SPaolo Bonzini void mips_cpu_do_interrupt(CPUState *cpu);
690416bf936SPaolo Bonzini bool mips_cpu_exec_interrupt(CPUState *cpu, int int_req);
691416bf936SPaolo Bonzini void mips_cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
692416bf936SPaolo Bonzini                          int flags);
693416bf936SPaolo Bonzini hwaddr mips_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
694416bf936SPaolo Bonzini int mips_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
695416bf936SPaolo Bonzini int mips_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
696416bf936SPaolo Bonzini void mips_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
697b35399bbSSergey Sorokin                                   MMUAccessType access_type,
698b35399bbSSergey Sorokin                                   int mmu_idx, uintptr_t retaddr);
6990f71a709SAndreas Färber 
7003c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
701a8170e5eSAvi Kivity int no_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
70229929e34Sths                         target_ulong address, int rw, int access_type);
703a8170e5eSAvi Kivity int fixed_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
70429929e34Sths                            target_ulong address, int rw, int access_type);
705a8170e5eSAvi Kivity int r4k_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
70629929e34Sths                      target_ulong address, int rw, int access_type);
707895c2d04SBlue Swirl void r4k_helper_tlbwi(CPUMIPSState *env);
708895c2d04SBlue Swirl void r4k_helper_tlbwr(CPUMIPSState *env);
709895c2d04SBlue Swirl void r4k_helper_tlbp(CPUMIPSState *env);
710895c2d04SBlue Swirl void r4k_helper_tlbr(CPUMIPSState *env);
7119456c2fbSLeon Alrae void r4k_helper_tlbinv(CPUMIPSState *env);
7129456c2fbSLeon Alrae void r4k_helper_tlbinvf(CPUMIPSState *env);
71333d68b5fSths 
714c658b94fSAndreas Färber void mips_cpu_unassigned_access(CPUState *cpu, hwaddr addr,
715c658b94fSAndreas Färber                                 bool is_write, bool is_exec, int unused,
716c658b94fSAndreas Färber                                 unsigned size);
7173c7b48b7SPaul Brook #endif
7183c7b48b7SPaul Brook 
7199a78eeadSStefan Weil void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf);
720647de6caSths 
7219467d44cSths #define cpu_signal_handler cpu_mips_signal_handler
722c732abe2Sj_mayer #define cpu_list mips_cpu_list
7239467d44cSths 
724084d0497SRichard Henderson extern void cpu_wrdsp(uint32_t rs, uint32_t mask_num, CPUMIPSState *env);
725084d0497SRichard Henderson extern uint32_t cpu_rddsp(uint32_t mask_num, CPUMIPSState *env);
726084d0497SRichard Henderson 
727623a930eSths /* MMU modes definitions. We carefully match the indices with our
728623a930eSths    hflags layout. */
7296ebbf390Sj_mayer #define MMU_MODE0_SUFFIX _kernel
730623a930eSths #define MMU_MODE1_SUFFIX _super
731623a930eSths #define MMU_MODE2_SUFFIX _user
73242c86612SJames Hogan #define MMU_MODE3_SUFFIX _error
733623a930eSths #define MMU_USER_IDX 2
734b0fc6003SJames Hogan 
735b0fc6003SJames Hogan static inline int hflags_mmu_index(uint32_t hflags)
736b0fc6003SJames Hogan {
73742c86612SJames Hogan     if (hflags & MIPS_HFLAG_ERL) {
73842c86612SJames Hogan         return 3; /* ERL */
73942c86612SJames Hogan     } else {
740b0fc6003SJames Hogan         return hflags & MIPS_HFLAG_KSU;
741b0fc6003SJames Hogan     }
74242c86612SJames Hogan }
743b0fc6003SJames Hogan 
74497ed5ccdSBenjamin Herrenschmidt static inline int cpu_mmu_index (CPUMIPSState *env, bool ifetch)
7456ebbf390Sj_mayer {
746b0fc6003SJames Hogan     return hflags_mmu_index(env->hflags);
7476ebbf390Sj_mayer }
7486ebbf390Sj_mayer 
74971ca034aSLeon Alrae static inline bool cpu_mips_hw_interrupts_enabled(CPUMIPSState *env)
750138afb02SEdgar E. Iglesias {
75171ca034aSLeon Alrae     return (env->CP0_Status & (1 << CP0St_IE)) &&
75271ca034aSLeon Alrae         !(env->CP0_Status & (1 << CP0St_EXL)) &&
75371ca034aSLeon Alrae         !(env->CP0_Status & (1 << CP0St_ERL)) &&
75471ca034aSLeon Alrae         !(env->hflags & MIPS_HFLAG_DM) &&
755344eecf6SEdgar E. Iglesias         /* Note that the TCStatus IXMT field is initialized to zero,
756344eecf6SEdgar E. Iglesias            and only MT capable cores can set it to one. So we don't
757344eecf6SEdgar E. Iglesias            need to check for MT capabilities here.  */
75871ca034aSLeon Alrae         !(env->active_tc.CP0_TCStatus & (1 << CP0TCSt_IXMT));
7594cdc1cd1SAurelien Jarno }
7604cdc1cd1SAurelien Jarno 
76171ca034aSLeon Alrae /* Check if there is pending and not masked out interrupt */
76271ca034aSLeon Alrae static inline bool cpu_mips_hw_interrupts_pending(CPUMIPSState *env)
76371ca034aSLeon Alrae {
76471ca034aSLeon Alrae     int32_t pending;
76571ca034aSLeon Alrae     int32_t status;
76671ca034aSLeon Alrae     bool r;
76771ca034aSLeon Alrae 
768138afb02SEdgar E. Iglesias     pending = env->CP0_Cause & CP0Ca_IP_mask;
769138afb02SEdgar E. Iglesias     status = env->CP0_Status & CP0Ca_IP_mask;
770138afb02SEdgar E. Iglesias 
771138afb02SEdgar E. Iglesias     if (env->CP0_Config3 & (1 << CP0C3_VEIC)) {
772138afb02SEdgar E. Iglesias         /* A MIPS configured with a vectorizing external interrupt controller
773138afb02SEdgar E. Iglesias            will feed a vector into the Cause pending lines. The core treats
774138afb02SEdgar E. Iglesias            the status lines as a vector level, not as indiviual masks.  */
775138afb02SEdgar E. Iglesias         r = pending > status;
776138afb02SEdgar E. Iglesias     } else {
777138afb02SEdgar E. Iglesias         /* A MIPS configured with compatibility or VInt (Vectored Interrupts)
778138afb02SEdgar E. Iglesias            treats the pending lines as individual interrupt lines, the status
779138afb02SEdgar E. Iglesias            lines are individual masks.  */
78071ca034aSLeon Alrae         r = (pending & status) != 0;
781138afb02SEdgar E. Iglesias     }
782138afb02SEdgar E. Iglesias     return r;
783138afb02SEdgar E. Iglesias }
784138afb02SEdgar E. Iglesias 
785022c62cbSPaolo Bonzini #include "exec/cpu-all.h"
7866af0bf9cSbellard 
7876af0bf9cSbellard /* Memory access type :
7886af0bf9cSbellard  * may be needed for precise access rights control and precise exceptions.
7896af0bf9cSbellard  */
7906af0bf9cSbellard enum {
7916af0bf9cSbellard     /* 1 bit to define user level / supervisor access */
7926af0bf9cSbellard     ACCESS_USER  = 0x00,
7936af0bf9cSbellard     ACCESS_SUPER = 0x01,
7946af0bf9cSbellard     /* 1 bit to indicate direction */
7956af0bf9cSbellard     ACCESS_STORE = 0x02,
7966af0bf9cSbellard     /* Type of instruction that generated the access */
7976af0bf9cSbellard     ACCESS_CODE  = 0x10, /* Code fetch access                */
7986af0bf9cSbellard     ACCESS_INT   = 0x20, /* Integer load/store access        */
7996af0bf9cSbellard     ACCESS_FLOAT = 0x30, /* floating point load/store access */
8006af0bf9cSbellard };
8016af0bf9cSbellard 
8026af0bf9cSbellard /* Exceptions */
8036af0bf9cSbellard enum {
8046af0bf9cSbellard     EXCP_NONE          = -1,
8056af0bf9cSbellard     EXCP_RESET         = 0,
8066af0bf9cSbellard     EXCP_SRESET,
8076af0bf9cSbellard     EXCP_DSS,
8086af0bf9cSbellard     EXCP_DINT,
80914e51cc7Sths     EXCP_DDBL,
81014e51cc7Sths     EXCP_DDBS,
8116af0bf9cSbellard     EXCP_NMI,
8126af0bf9cSbellard     EXCP_MCHECK,
81314e51cc7Sths     EXCP_EXT_INTERRUPT, /* 8 */
8146af0bf9cSbellard     EXCP_DFWATCH,
81514e51cc7Sths     EXCP_DIB,
8166af0bf9cSbellard     EXCP_IWATCH,
8176af0bf9cSbellard     EXCP_AdEL,
8186af0bf9cSbellard     EXCP_AdES,
8196af0bf9cSbellard     EXCP_TLBF,
8206af0bf9cSbellard     EXCP_IBE,
82114e51cc7Sths     EXCP_DBp, /* 16 */
8226af0bf9cSbellard     EXCP_SYSCALL,
82314e51cc7Sths     EXCP_BREAK,
8244ad40f36Sbellard     EXCP_CpU,
8256af0bf9cSbellard     EXCP_RI,
8266af0bf9cSbellard     EXCP_OVERFLOW,
8276af0bf9cSbellard     EXCP_TRAP,
8285a5012ecSths     EXCP_FPE,
82914e51cc7Sths     EXCP_DWATCH, /* 24 */
8306af0bf9cSbellard     EXCP_LTLBL,
8316af0bf9cSbellard     EXCP_TLBL,
8326af0bf9cSbellard     EXCP_TLBS,
8336af0bf9cSbellard     EXCP_DBE,
834ead9360eSths     EXCP_THREAD,
83514e51cc7Sths     EXCP_MDMX,
83614e51cc7Sths     EXCP_C2E,
83714e51cc7Sths     EXCP_CACHE, /* 32 */
838853c3240SJia Liu     EXCP_DSPDIS,
839e97a391dSYongbok Kim     EXCP_MSADIS,
840e97a391dSYongbok Kim     EXCP_MSAFPE,
84192ceb440SLeon Alrae     EXCP_TLBXI,
84292ceb440SLeon Alrae     EXCP_TLBRI,
84314e51cc7Sths 
84492ceb440SLeon Alrae     EXCP_LAST = EXCP_TLBRI,
8456af0bf9cSbellard };
846590bc601SPaul Brook /* Dummy exception for conditional stores.  */
847590bc601SPaul Brook #define EXCP_SC 0x100
8486af0bf9cSbellard 
849f249412cSEdgar E. Iglesias /*
850f249412cSEdgar E. Iglesias  * This is an interrnally generated WAKE request line.
851f249412cSEdgar E. Iglesias  * It is driven by the CPU itself. Raised when the MT
852f249412cSEdgar E. Iglesias  * block wants to wake a VPE from an inactive state and
853f249412cSEdgar E. Iglesias  * cleared when VPE goes from active to inactive.
854f249412cSEdgar E. Iglesias  */
855f249412cSEdgar E. Iglesias #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0
856f249412cSEdgar E. Iglesias 
85778ce64f4SAndreas Färber void mips_tcg_init(void);
85830bf942dSAndreas Färber MIPSCPU *cpu_mips_init(const char *cpu_model);
859388bb21aSths int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
8606af0bf9cSbellard 
8612994fd96SEduardo Habkost #define cpu_init(cpu_model) CPU(cpu_mips_init(cpu_model))
862bff384a4SLeon Alrae bool cpu_supports_cps_smp(const char *cpu_model);
863bed9e5ceSPaul Burton bool cpu_supports_isa(const char *cpu_model, unsigned int isa);
86489777fd1SLeon Alrae void cpu_set_exception_base(int vp_index, target_ulong address);
86530bf942dSAndreas Färber 
866b7e516ceSAndreas Färber /* TODO QOM'ify CPU reset and remove */
867b7e516ceSAndreas Färber void cpu_state_reset(CPUMIPSState *s);
868b7e516ceSAndreas Färber 
869f9480ffcSths /* mips_timer.c */
8707db13faeSAndreas Färber uint32_t cpu_mips_get_random (CPUMIPSState *env);
8717db13faeSAndreas Färber uint32_t cpu_mips_get_count (CPUMIPSState *env);
8727db13faeSAndreas Färber void cpu_mips_store_count (CPUMIPSState *env, uint32_t value);
8737db13faeSAndreas Färber void cpu_mips_store_compare (CPUMIPSState *env, uint32_t value);
8747db13faeSAndreas Färber void cpu_mips_start_count(CPUMIPSState *env);
8757db13faeSAndreas Färber void cpu_mips_stop_count(CPUMIPSState *env);
876f9480ffcSths 
8775dc5d9f0SAurelien Jarno /* mips_int.c */
8787db13faeSAndreas Färber void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level);
8795dc5d9f0SAurelien Jarno 
880f9480ffcSths /* helper.c */
8817510454eSAndreas Färber int mips_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
88297b348e7SBlue Swirl                               int mmu_idx);
883af39bc8cSAleksandar Markovic 
884af39bc8cSAleksandar Markovic /* op_helper.c */
885af39bc8cSAleksandar Markovic uint32_t float_class_s(uint32_t arg, float_status *fst);
886af39bc8cSAleksandar Markovic uint64_t float_class_d(uint64_t arg, float_status *fst);
887af39bc8cSAleksandar Markovic 
8883c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
8897db13faeSAndreas Färber void r4k_invalidate_tlb (CPUMIPSState *env, int idx, int use_extra);
890a8170e5eSAvi Kivity hwaddr cpu_mips_translate_address (CPUMIPSState *env, target_ulong address,
89125b91e32SAurelien Jarno 		                               int rw);
8923c7b48b7SPaul Brook #endif
8931239b472SKwok Cheung Yeung target_ulong exception_resume_pc (CPUMIPSState *env);
894f9480ffcSths 
895b7651e95SYongbok Kim /* op_helper.c */
896b7651e95SYongbok Kim extern unsigned int ieee_rm[];
897b7651e95SYongbok Kim int ieee_ex_to_mips(int xcpt);
898b7651e95SYongbok Kim 
899bb962386SMaciej W. Rozycki static inline void restore_rounding_mode(CPUMIPSState *env)
900bb962386SMaciej W. Rozycki {
901bb962386SMaciej W. Rozycki     set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3],
902bb962386SMaciej W. Rozycki                             &env->active_fpu.fp_status);
903bb962386SMaciej W. Rozycki }
904bb962386SMaciej W. Rozycki 
905bb962386SMaciej W. Rozycki static inline void restore_flush_mode(CPUMIPSState *env)
906bb962386SMaciej W. Rozycki {
90777be4199SAleksandar Markovic     set_flush_to_zero((env->active_fpu.fcr31 & (1 << FCR31_FS)) != 0,
908bb962386SMaciej W. Rozycki                       &env->active_fpu.fp_status);
909bb962386SMaciej W. Rozycki }
910bb962386SMaciej W. Rozycki 
911599bc5e8SAleksandar Markovic static inline void restore_snan_bit_mode(CPUMIPSState *env)
912599bc5e8SAleksandar Markovic {
913599bc5e8SAleksandar Markovic     set_snan_bit_is_one((env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) == 0,
914599bc5e8SAleksandar Markovic                         &env->active_fpu.fp_status);
915599bc5e8SAleksandar Markovic }
916599bc5e8SAleksandar Markovic 
91764451111SLeon Alrae static inline void restore_fp_status(CPUMIPSState *env)
91864451111SLeon Alrae {
91964451111SLeon Alrae     restore_rounding_mode(env);
92064451111SLeon Alrae     restore_flush_mode(env);
921599bc5e8SAleksandar Markovic     restore_snan_bit_mode(env);
92264451111SLeon Alrae }
92364451111SLeon Alrae 
92464451111SLeon Alrae static inline void restore_msa_fp_status(CPUMIPSState *env)
92564451111SLeon Alrae {
92664451111SLeon Alrae     float_status *status = &env->active_tc.msa_fp_status;
92764451111SLeon Alrae     int rounding_mode = (env->active_tc.msacsr & MSACSR_RM_MASK) >> MSACSR_RM;
92864451111SLeon Alrae     bool flush_to_zero = (env->active_tc.msacsr & MSACSR_FS_MASK) != 0;
92964451111SLeon Alrae 
93064451111SLeon Alrae     set_float_rounding_mode(ieee_rm[rounding_mode], status);
93164451111SLeon Alrae     set_flush_to_zero(flush_to_zero, status);
93264451111SLeon Alrae     set_flush_inputs_to_zero(flush_to_zero, status);
93364451111SLeon Alrae }
93464451111SLeon Alrae 
935e117f526SLeon Alrae static inline void restore_pamask(CPUMIPSState *env)
936e117f526SLeon Alrae {
937e117f526SLeon Alrae     if (env->hflags & MIPS_HFLAG_ELPA) {
938e117f526SLeon Alrae         env->PAMask = (1ULL << env->PABITS) - 1;
939e117f526SLeon Alrae     } else {
940e117f526SLeon Alrae         env->PAMask = PAMASK_BASE;
941e117f526SLeon Alrae     }
942e117f526SLeon Alrae }
943e117f526SLeon Alrae 
9447db13faeSAndreas Färber static inline void cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc,
94589fee74aSEmilio G. Cota                                         target_ulong *cs_base, uint32_t *flags)
9466b917547Saliguori {
9476b917547Saliguori     *pc = env->active_tc.PC;
9486b917547Saliguori     *cs_base = 0;
949d279279eSPetar Jovanovic     *flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK |
950d279279eSPetar Jovanovic                             MIPS_HFLAG_HWRENA_ULR);
9516b917547Saliguori }
9526b917547Saliguori 
9537db13faeSAndreas Färber static inline int mips_vpe_active(CPUMIPSState *env)
954f249412cSEdgar E. Iglesias {
955f249412cSEdgar E. Iglesias     int active = 1;
956f249412cSEdgar E. Iglesias 
957f249412cSEdgar E. Iglesias     /* Check that the VPE is enabled.  */
958f249412cSEdgar E. Iglesias     if (!(env->mvp->CP0_MVPControl & (1 << CP0MVPCo_EVP))) {
959f249412cSEdgar E. Iglesias         active = 0;
960f249412cSEdgar E. Iglesias     }
9614abf79a4SDong Xu Wang     /* Check that the VPE is activated.  */
962f249412cSEdgar E. Iglesias     if (!(env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))) {
963f249412cSEdgar E. Iglesias         active = 0;
964f249412cSEdgar E. Iglesias     }
965f249412cSEdgar E. Iglesias 
966f249412cSEdgar E. Iglesias     /* Now verify that there are active thread contexts in the VPE.
967f249412cSEdgar E. Iglesias 
968f249412cSEdgar E. Iglesias        This assumes the CPU model will internally reschedule threads
969f249412cSEdgar E. Iglesias        if the active one goes to sleep. If there are no threads available
970f249412cSEdgar E. Iglesias        the active one will be in a sleeping state, and we can turn off
971f249412cSEdgar E. Iglesias        the entire VPE.  */
972f249412cSEdgar E. Iglesias     if (!(env->active_tc.CP0_TCStatus & (1 << CP0TCSt_A))) {
973f249412cSEdgar E. Iglesias         /* TC is not activated.  */
974f249412cSEdgar E. Iglesias         active = 0;
975f249412cSEdgar E. Iglesias     }
976f249412cSEdgar E. Iglesias     if (env->active_tc.CP0_TCHalt & 1) {
977f249412cSEdgar E. Iglesias         /* TC is in halt state.  */
978f249412cSEdgar E. Iglesias         active = 0;
979f249412cSEdgar E. Iglesias     }
980f249412cSEdgar E. Iglesias 
981f249412cSEdgar E. Iglesias     return active;
982f249412cSEdgar E. Iglesias }
983f249412cSEdgar E. Iglesias 
98401bc435bSYongbok Kim static inline int mips_vp_active(CPUMIPSState *env)
98501bc435bSYongbok Kim {
98601bc435bSYongbok Kim     CPUState *other_cs = first_cpu;
98701bc435bSYongbok Kim 
98801bc435bSYongbok Kim     /* Check if the VP disabled other VPs (which means the VP is enabled) */
98901bc435bSYongbok Kim     if ((env->CP0_VPControl >> CP0VPCtl_DIS) & 1) {
99001bc435bSYongbok Kim         return 1;
99101bc435bSYongbok Kim     }
99201bc435bSYongbok Kim 
99301bc435bSYongbok Kim     /* Check if the virtual processor is disabled due to a DVP */
99401bc435bSYongbok Kim     CPU_FOREACH(other_cs) {
99501bc435bSYongbok Kim         MIPSCPU *other_cpu = MIPS_CPU(other_cs);
99601bc435bSYongbok Kim         if ((&other_cpu->env != env) &&
99701bc435bSYongbok Kim             ((other_cpu->env.CP0_VPControl >> CP0VPCtl_DIS) & 1)) {
99801bc435bSYongbok Kim             return 0;
99901bc435bSYongbok Kim         }
100001bc435bSYongbok Kim     }
100101bc435bSYongbok Kim     return 1;
100201bc435bSYongbok Kim }
100301bc435bSYongbok Kim 
100403e6e501SMaciej W. Rozycki static inline void compute_hflags(CPUMIPSState *env)
100503e6e501SMaciej W. Rozycki {
100603e6e501SMaciej W. Rozycki     env->hflags &= ~(MIPS_HFLAG_COP1X | MIPS_HFLAG_64 | MIPS_HFLAG_CP0 |
100703e6e501SMaciej W. Rozycki                      MIPS_HFLAG_F64 | MIPS_HFLAG_FPU | MIPS_HFLAG_KSU |
1008faf1f68bSLeon Alrae                      MIPS_HFLAG_AWRAP | MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2 |
1009e117f526SLeon Alrae                      MIPS_HFLAG_SBRI | MIPS_HFLAG_MSA | MIPS_HFLAG_FRE |
101042c86612SJames Hogan                      MIPS_HFLAG_ELPA | MIPS_HFLAG_ERL);
101142c86612SJames Hogan     if (env->CP0_Status & (1 << CP0St_ERL)) {
101242c86612SJames Hogan         env->hflags |= MIPS_HFLAG_ERL;
101342c86612SJames Hogan     }
101403e6e501SMaciej W. Rozycki     if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
101503e6e501SMaciej W. Rozycki         !(env->CP0_Status & (1 << CP0St_ERL)) &&
101603e6e501SMaciej W. Rozycki         !(env->hflags & MIPS_HFLAG_DM)) {
101703e6e501SMaciej W. Rozycki         env->hflags |= (env->CP0_Status >> CP0St_KSU) & MIPS_HFLAG_KSU;
101803e6e501SMaciej W. Rozycki     }
101903e6e501SMaciej W. Rozycki #if defined(TARGET_MIPS64)
1020d9224450SMaciej W. Rozycki     if ((env->insn_flags & ISA_MIPS3) &&
1021d9224450SMaciej W. Rozycki         (((env->hflags & MIPS_HFLAG_KSU) != MIPS_HFLAG_UM) ||
102203e6e501SMaciej W. Rozycki          (env->CP0_Status & (1 << CP0St_PX)) ||
1023d9224450SMaciej W. Rozycki          (env->CP0_Status & (1 << CP0St_UX)))) {
102403e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_64;
102503e6e501SMaciej W. Rozycki     }
102601f72885SLeon Alrae 
1027c48245f0SMaciej W. Rozycki     if (!(env->insn_flags & ISA_MIPS3)) {
1028c48245f0SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_AWRAP;
1029c48245f0SMaciej W. Rozycki     } else if (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
103001f72885SLeon Alrae                !(env->CP0_Status & (1 << CP0St_UX))) {
103101f72885SLeon Alrae         env->hflags |= MIPS_HFLAG_AWRAP;
1032c48245f0SMaciej W. Rozycki     } else if (env->insn_flags & ISA_MIPS64R6) {
103301f72885SLeon Alrae         /* Address wrapping for Supervisor and Kernel is specified in R6 */
103401f72885SLeon Alrae         if ((((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_SM) &&
103501f72885SLeon Alrae              !(env->CP0_Status & (1 << CP0St_SX))) ||
103601f72885SLeon Alrae             (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_KM) &&
103701f72885SLeon Alrae              !(env->CP0_Status & (1 << CP0St_KX)))) {
103801f72885SLeon Alrae             env->hflags |= MIPS_HFLAG_AWRAP;
103901f72885SLeon Alrae         }
104003e6e501SMaciej W. Rozycki     }
104103e6e501SMaciej W. Rozycki #endif
1042a63eb0ceSLeon Alrae     if (((env->CP0_Status & (1 << CP0St_CU0)) &&
1043a63eb0ceSLeon Alrae          !(env->insn_flags & ISA_MIPS32R6)) ||
104403e6e501SMaciej W. Rozycki         !(env->hflags & MIPS_HFLAG_KSU)) {
104503e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_CP0;
104603e6e501SMaciej W. Rozycki     }
104703e6e501SMaciej W. Rozycki     if (env->CP0_Status & (1 << CP0St_CU1)) {
104803e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_FPU;
104903e6e501SMaciej W. Rozycki     }
105003e6e501SMaciej W. Rozycki     if (env->CP0_Status & (1 << CP0St_FR)) {
105103e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_F64;
105203e6e501SMaciej W. Rozycki     }
1053faf1f68bSLeon Alrae     if (((env->hflags & MIPS_HFLAG_KSU) != MIPS_HFLAG_KM) &&
1054faf1f68bSLeon Alrae         (env->CP0_Config5 & (1 << CP0C5_SBRI))) {
1055faf1f68bSLeon Alrae         env->hflags |= MIPS_HFLAG_SBRI;
1056faf1f68bSLeon Alrae     }
1057853c3240SJia Liu     if (env->insn_flags & ASE_DSPR2) {
1058853c3240SJia Liu         /* Enables access MIPS DSP resources, now our cpu is DSP ASER2,
1059853c3240SJia Liu            so enable to access DSPR2 resources. */
1060853c3240SJia Liu         if (env->CP0_Status & (1 << CP0St_MX)) {
1061853c3240SJia Liu             env->hflags |= MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2;
1062853c3240SJia Liu         }
1063853c3240SJia Liu 
1064853c3240SJia Liu     } else if (env->insn_flags & ASE_DSP) {
1065853c3240SJia Liu         /* Enables access MIPS DSP resources, now our cpu is DSP ASE,
1066853c3240SJia Liu            so enable to access DSP resources. */
1067853c3240SJia Liu         if (env->CP0_Status & (1 << CP0St_MX)) {
1068853c3240SJia Liu             env->hflags |= MIPS_HFLAG_DSP;
1069853c3240SJia Liu         }
1070853c3240SJia Liu 
1071853c3240SJia Liu     }
107203e6e501SMaciej W. Rozycki     if (env->insn_flags & ISA_MIPS32R2) {
107303e6e501SMaciej W. Rozycki         if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
107403e6e501SMaciej W. Rozycki             env->hflags |= MIPS_HFLAG_COP1X;
107503e6e501SMaciej W. Rozycki         }
107603e6e501SMaciej W. Rozycki     } else if (env->insn_flags & ISA_MIPS32) {
107703e6e501SMaciej W. Rozycki         if (env->hflags & MIPS_HFLAG_64) {
107803e6e501SMaciej W. Rozycki             env->hflags |= MIPS_HFLAG_COP1X;
107903e6e501SMaciej W. Rozycki         }
108003e6e501SMaciej W. Rozycki     } else if (env->insn_flags & ISA_MIPS4) {
108103e6e501SMaciej W. Rozycki         /* All supported MIPS IV CPUs use the XX (CU3) to enable
108203e6e501SMaciej W. Rozycki            and disable the MIPS IV extensions to the MIPS III ISA.
108303e6e501SMaciej W. Rozycki            Some other MIPS IV CPUs ignore the bit, so the check here
108403e6e501SMaciej W. Rozycki            would be too restrictive for them.  */
1085f45cb2f4SPeter Maydell         if (env->CP0_Status & (1U << CP0St_CU3)) {
108603e6e501SMaciej W. Rozycki             env->hflags |= MIPS_HFLAG_COP1X;
108703e6e501SMaciej W. Rozycki         }
108803e6e501SMaciej W. Rozycki     }
1089e97a391dSYongbok Kim     if (env->insn_flags & ASE_MSA) {
1090e97a391dSYongbok Kim         if (env->CP0_Config5 & (1 << CP0C5_MSAEn)) {
1091e97a391dSYongbok Kim             env->hflags |= MIPS_HFLAG_MSA;
1092e97a391dSYongbok Kim         }
1093e97a391dSYongbok Kim     }
10947c979afdSLeon Alrae     if (env->active_fpu.fcr0 & (1 << FCR0_FREP)) {
10957c979afdSLeon Alrae         if (env->CP0_Config5 & (1 << CP0C5_FRE)) {
10967c979afdSLeon Alrae             env->hflags |= MIPS_HFLAG_FRE;
10977c979afdSLeon Alrae         }
10987c979afdSLeon Alrae     }
1099e117f526SLeon Alrae     if (env->CP0_Config3 & (1 << CP0C3_LPA)) {
1100e117f526SLeon Alrae         if (env->CP0_PageGrain & (1 << CP0PG_ELPA)) {
1101e117f526SLeon Alrae             env->hflags |= MIPS_HFLAG_ELPA;
1102e117f526SLeon Alrae         }
1103e117f526SLeon Alrae     }
110403e6e501SMaciej W. Rozycki }
110503e6e501SMaciej W. Rozycki 
1106d10eb08fSAlex Bennée void cpu_mips_tlb_flush(CPUMIPSState *env);
1107e6623d88SPaolo Bonzini void sync_c0_status(CPUMIPSState *env, CPUMIPSState *cpu, int tc);
1108e6623d88SPaolo Bonzini void cpu_mips_store_status(CPUMIPSState *env, target_ulong val);
1109e6623d88SPaolo Bonzini void cpu_mips_store_cause(CPUMIPSState *env, target_ulong val);
111081a423e6SMaciej W. Rozycki 
111133c11879SPaolo Bonzini void QEMU_NORETURN do_raise_exception_err(CPUMIPSState *env, uint32_t exception,
111233c11879SPaolo Bonzini                                           int error_code, uintptr_t pc);
11139c708c7fSPavel Dovgaluk 
11149c708c7fSPavel Dovgaluk static inline void QEMU_NORETURN do_raise_exception(CPUMIPSState *env,
11159c708c7fSPavel Dovgaluk                                                     uint32_t exception,
11169c708c7fSPavel Dovgaluk                                                     uintptr_t pc)
11179c708c7fSPavel Dovgaluk {
11189c708c7fSPavel Dovgaluk     do_raise_exception_err(env, exception, 0, pc);
11199c708c7fSPavel Dovgaluk }
11209c708c7fSPavel Dovgaluk 
112107f5a258SMarkus Armbruster #endif /* MIPS_CPU_H */
1122