xref: /qemu/target/mips/cpu.h (revision 1f5c00cfdb8114c1e3a13426588ceb64f82c9ddb)
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 
137623a930eSths #define NB_MMU_MODES 3
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
3099c2149c8Sths     int32_t CP0_Wired;
310ead9360eSths     int32_t CP0_SRSConf0_rw_bitmask;
311ead9360eSths     int32_t CP0_SRSConf0;
312ead9360eSths #define CP0SRSC0_M	31
313ead9360eSths #define CP0SRSC0_SRS3	20
314ead9360eSths #define CP0SRSC0_SRS2	10
315ead9360eSths #define CP0SRSC0_SRS1	0
316ead9360eSths     int32_t CP0_SRSConf1_rw_bitmask;
317ead9360eSths     int32_t CP0_SRSConf1;
318ead9360eSths #define CP0SRSC1_M	31
319ead9360eSths #define CP0SRSC1_SRS6	20
320ead9360eSths #define CP0SRSC1_SRS5	10
321ead9360eSths #define CP0SRSC1_SRS4	0
322ead9360eSths     int32_t CP0_SRSConf2_rw_bitmask;
323ead9360eSths     int32_t CP0_SRSConf2;
324ead9360eSths #define CP0SRSC2_M	31
325ead9360eSths #define CP0SRSC2_SRS9	20
326ead9360eSths #define CP0SRSC2_SRS8	10
327ead9360eSths #define CP0SRSC2_SRS7	0
328ead9360eSths     int32_t CP0_SRSConf3_rw_bitmask;
329ead9360eSths     int32_t CP0_SRSConf3;
330ead9360eSths #define CP0SRSC3_M	31
331ead9360eSths #define CP0SRSC3_SRS12	20
332ead9360eSths #define CP0SRSC3_SRS11	10
333ead9360eSths #define CP0SRSC3_SRS10	0
334ead9360eSths     int32_t CP0_SRSConf4_rw_bitmask;
335ead9360eSths     int32_t CP0_SRSConf4;
336ead9360eSths #define CP0SRSC4_SRS15	20
337ead9360eSths #define CP0SRSC4_SRS14	10
338ead9360eSths #define CP0SRSC4_SRS13	0
3399c2149c8Sths     int32_t CP0_HWREna;
340c570fd16Sths     target_ulong CP0_BadVAddr;
341aea14095SLeon Alrae     uint32_t CP0_BadInstr;
342aea14095SLeon Alrae     uint32_t CP0_BadInstrP;
3439c2149c8Sths     int32_t CP0_Count;
3449c2149c8Sths     target_ulong CP0_EntryHi;
3459456c2fbSLeon Alrae #define CP0EnHi_EHINV 10
3466ec98bd7SPaul Burton     target_ulong CP0_EntryHi_ASID_mask;
3479c2149c8Sths     int32_t CP0_Compare;
3489c2149c8Sths     int32_t CP0_Status;
3496af0bf9cSbellard #define CP0St_CU3   31
3506af0bf9cSbellard #define CP0St_CU2   30
3516af0bf9cSbellard #define CP0St_CU1   29
3526af0bf9cSbellard #define CP0St_CU0   28
3536af0bf9cSbellard #define CP0St_RP    27
3546ea83fedSbellard #define CP0St_FR    26
3556af0bf9cSbellard #define CP0St_RE    25
3567a387fffSths #define CP0St_MX    24
3577a387fffSths #define CP0St_PX    23
3586af0bf9cSbellard #define CP0St_BEV   22
3596af0bf9cSbellard #define CP0St_TS    21
3606af0bf9cSbellard #define CP0St_SR    20
3616af0bf9cSbellard #define CP0St_NMI   19
3626af0bf9cSbellard #define CP0St_IM    8
3637a387fffSths #define CP0St_KX    7
3647a387fffSths #define CP0St_SX    6
3657a387fffSths #define CP0St_UX    5
366623a930eSths #define CP0St_KSU   3
3676af0bf9cSbellard #define CP0St_ERL   2
3686af0bf9cSbellard #define CP0St_EXL   1
3696af0bf9cSbellard #define CP0St_IE    0
3709c2149c8Sths     int32_t CP0_IntCtl;
371ead9360eSths #define CP0IntCtl_IPTI 29
37288991299SDongxue Zhang #define CP0IntCtl_IPPCI 26
373ead9360eSths #define CP0IntCtl_VS 5
3749c2149c8Sths     int32_t CP0_SRSCtl;
375ead9360eSths #define CP0SRSCtl_HSS 26
376ead9360eSths #define CP0SRSCtl_EICSS 18
377ead9360eSths #define CP0SRSCtl_ESS 12
378ead9360eSths #define CP0SRSCtl_PSS 6
379ead9360eSths #define CP0SRSCtl_CSS 0
3809c2149c8Sths     int32_t CP0_SRSMap;
381ead9360eSths #define CP0SRSMap_SSV7 28
382ead9360eSths #define CP0SRSMap_SSV6 24
383ead9360eSths #define CP0SRSMap_SSV5 20
384ead9360eSths #define CP0SRSMap_SSV4 16
385ead9360eSths #define CP0SRSMap_SSV3 12
386ead9360eSths #define CP0SRSMap_SSV2 8
387ead9360eSths #define CP0SRSMap_SSV1 4
388ead9360eSths #define CP0SRSMap_SSV0 0
3899c2149c8Sths     int32_t CP0_Cause;
3907a387fffSths #define CP0Ca_BD   31
3917a387fffSths #define CP0Ca_TI   30
3927a387fffSths #define CP0Ca_CE   28
3937a387fffSths #define CP0Ca_DC   27
3947a387fffSths #define CP0Ca_PCI  26
3956af0bf9cSbellard #define CP0Ca_IV   23
3967a387fffSths #define CP0Ca_WP   22
3977a387fffSths #define CP0Ca_IP    8
3984de9b249Sths #define CP0Ca_IP_mask 0x0000FF00
3997a387fffSths #define CP0Ca_EC    2
400c570fd16Sths     target_ulong CP0_EPC;
4019c2149c8Sths     int32_t CP0_PRid;
402b29a0341Sths     int32_t CP0_EBase;
403c870e3f5SYongbok Kim     target_ulong CP0_CMGCRBase;
4049c2149c8Sths     int32_t CP0_Config0;
4056af0bf9cSbellard #define CP0C0_M    31
4066af0bf9cSbellard #define CP0C0_K23  28
4076af0bf9cSbellard #define CP0C0_KU   25
4086af0bf9cSbellard #define CP0C0_MDU  20
409aff2bc6dSYongbok Kim #define CP0C0_MM   18
4106af0bf9cSbellard #define CP0C0_BM   16
4116af0bf9cSbellard #define CP0C0_BE   15
4126af0bf9cSbellard #define CP0C0_AT   13
4136af0bf9cSbellard #define CP0C0_AR   10
4146af0bf9cSbellard #define CP0C0_MT   7
4157a387fffSths #define CP0C0_VI   3
4166af0bf9cSbellard #define CP0C0_K0   0
4179c2149c8Sths     int32_t CP0_Config1;
4187a387fffSths #define CP0C1_M    31
4196af0bf9cSbellard #define CP0C1_MMU  25
4206af0bf9cSbellard #define CP0C1_IS   22
4216af0bf9cSbellard #define CP0C1_IL   19
4226af0bf9cSbellard #define CP0C1_IA   16
4236af0bf9cSbellard #define CP0C1_DS   13
4246af0bf9cSbellard #define CP0C1_DL   10
4256af0bf9cSbellard #define CP0C1_DA   7
4267a387fffSths #define CP0C1_C2   6
4277a387fffSths #define CP0C1_MD   5
4286af0bf9cSbellard #define CP0C1_PC   4
4296af0bf9cSbellard #define CP0C1_WR   3
4306af0bf9cSbellard #define CP0C1_CA   2
4316af0bf9cSbellard #define CP0C1_EP   1
4326af0bf9cSbellard #define CP0C1_FP   0
4339c2149c8Sths     int32_t CP0_Config2;
4347a387fffSths #define CP0C2_M    31
4357a387fffSths #define CP0C2_TU   28
4367a387fffSths #define CP0C2_TS   24
4377a387fffSths #define CP0C2_TL   20
4387a387fffSths #define CP0C2_TA   16
4397a387fffSths #define CP0C2_SU   12
4407a387fffSths #define CP0C2_SS   8
4417a387fffSths #define CP0C2_SL   4
4427a387fffSths #define CP0C2_SA   0
4439c2149c8Sths     int32_t CP0_Config3;
4447a387fffSths #define CP0C3_M    31
44570409e67SMaciej W. Rozycki #define CP0C3_BPG  30
446c870e3f5SYongbok Kim #define CP0C3_CMGCR 29
447e97a391dSYongbok Kim #define CP0C3_MSAP  28
448aea14095SLeon Alrae #define CP0C3_BP 27
449aea14095SLeon Alrae #define CP0C3_BI 26
45070409e67SMaciej W. Rozycki #define CP0C3_IPLW 21
45170409e67SMaciej W. Rozycki #define CP0C3_MMAR 18
45270409e67SMaciej W. Rozycki #define CP0C3_MCU  17
453bbfa8f72SNathan Froyd #define CP0C3_ISA_ON_EXC 16
45470409e67SMaciej W. Rozycki #define CP0C3_ISA  14
455d279279eSPetar Jovanovic #define CP0C3_ULRI 13
4567207c7f9SLeon Alrae #define CP0C3_RXI  12
45770409e67SMaciej W. Rozycki #define CP0C3_DSP2P 11
4587a387fffSths #define CP0C3_DSPP 10
4597a387fffSths #define CP0C3_LPA  7
4607a387fffSths #define CP0C3_VEIC 6
4617a387fffSths #define CP0C3_VInt 5
4627a387fffSths #define CP0C3_SP   4
46370409e67SMaciej W. Rozycki #define CP0C3_CDMM 3
4647a387fffSths #define CP0C3_MT   2
4657a387fffSths #define CP0C3_SM   1
4667a387fffSths #define CP0C3_TL   0
4678280b12cSMaciej W. Rozycki     int32_t CP0_Config4;
4688280b12cSMaciej W. Rozycki     int32_t CP0_Config4_rw_bitmask;
469b4160af1SPetar Jovanovic #define CP0C4_M    31
4709456c2fbSLeon Alrae #define CP0C4_IE   29
471a0c80608SPaul Burton #define CP0C4_AE   28
472e98c0d17SLeon Alrae #define CP0C4_KScrExist 16
47370409e67SMaciej W. Rozycki #define CP0C4_MMUExtDef 14
47470409e67SMaciej W. Rozycki #define CP0C4_FTLBPageSize 8
47570409e67SMaciej W. Rozycki #define CP0C4_FTLBWays 4
47670409e67SMaciej W. Rozycki #define CP0C4_FTLBSets 0
47770409e67SMaciej W. Rozycki #define CP0C4_MMUSizeExt 0
4788280b12cSMaciej W. Rozycki     int32_t CP0_Config5;
4798280b12cSMaciej W. Rozycki     int32_t CP0_Config5_rw_bitmask;
480b4dd99a3SPetar Jovanovic #define CP0C5_M          31
481b4dd99a3SPetar Jovanovic #define CP0C5_K          30
482b4dd99a3SPetar Jovanovic #define CP0C5_CV         29
483b4dd99a3SPetar Jovanovic #define CP0C5_EVA        28
484b4dd99a3SPetar Jovanovic #define CP0C5_MSAEn      27
485b00c7218SYongbok Kim #define CP0C5_XNP        13
4867c979afdSLeon Alrae #define CP0C5_UFE        9
4877c979afdSLeon Alrae #define CP0C5_FRE        8
48801bc435bSYongbok Kim #define CP0C5_VP         7
489faf1f68bSLeon Alrae #define CP0C5_SBRI       6
4905204ea79SLeon Alrae #define CP0C5_MVH        5
491ce9782f4SLeon Alrae #define CP0C5_LLB        4
492f6d4dd81SYongbok Kim #define CP0C5_MRP        3
493b4dd99a3SPetar Jovanovic #define CP0C5_UFR        2
494b4dd99a3SPetar Jovanovic #define CP0C5_NFExists   0
495e397ee33Sths     int32_t CP0_Config6;
496e397ee33Sths     int32_t CP0_Config7;
497f6d4dd81SYongbok Kim     uint64_t CP0_MAAR[MIPS_MAAR_MAX];
498f6d4dd81SYongbok Kim     int32_t CP0_MAARI;
499ead9360eSths     /* XXX: Maybe make LLAddr per-TC? */
500284b731aSLeon Alrae     uint64_t lladdr;
501590bc601SPaul Brook     target_ulong llval;
502590bc601SPaul Brook     target_ulong llnewval;
503590bc601SPaul Brook     target_ulong llreg;
504284b731aSLeon Alrae     uint64_t CP0_LLAddr_rw_bitmask;
5052a6e32ddSAurelien Jarno     int CP0_LLAddr_shift;
506fd88b6abSths     target_ulong CP0_WatchLo[8];
507fd88b6abSths     int32_t CP0_WatchHi[8];
5086ec98bd7SPaul Burton #define CP0WH_ASID 16
5099c2149c8Sths     target_ulong CP0_XContext;
5109c2149c8Sths     int32_t CP0_Framemask;
5119c2149c8Sths     int32_t CP0_Debug;
512ead9360eSths #define CP0DB_DBD  31
5136af0bf9cSbellard #define CP0DB_DM   30
5146af0bf9cSbellard #define CP0DB_LSNM 28
5156af0bf9cSbellard #define CP0DB_Doze 27
5166af0bf9cSbellard #define CP0DB_Halt 26
5176af0bf9cSbellard #define CP0DB_CNT  25
5186af0bf9cSbellard #define CP0DB_IBEP 24
5196af0bf9cSbellard #define CP0DB_DBEP 21
5206af0bf9cSbellard #define CP0DB_IEXI 20
5216af0bf9cSbellard #define CP0DB_VER  15
5226af0bf9cSbellard #define CP0DB_DEC  10
5236af0bf9cSbellard #define CP0DB_SSt  8
5246af0bf9cSbellard #define CP0DB_DINT 5
5256af0bf9cSbellard #define CP0DB_DIB  4
5266af0bf9cSbellard #define CP0DB_DDBS 3
5276af0bf9cSbellard #define CP0DB_DDBL 2
5286af0bf9cSbellard #define CP0DB_DBp  1
5296af0bf9cSbellard #define CP0DB_DSS  0
530c570fd16Sths     target_ulong CP0_DEPC;
5319c2149c8Sths     int32_t CP0_Performance0;
5320d74a222SLeon Alrae     int32_t CP0_ErrCtl;
5330d74a222SLeon Alrae #define CP0EC_WST 29
5340d74a222SLeon Alrae #define CP0EC_SPR 28
5350d74a222SLeon Alrae #define CP0EC_ITC 26
536284b731aSLeon Alrae     uint64_t CP0_TagLo;
5379c2149c8Sths     int32_t CP0_DataLo;
5389c2149c8Sths     int32_t CP0_TagHi;
5399c2149c8Sths     int32_t CP0_DataHi;
540c570fd16Sths     target_ulong CP0_ErrorEPC;
5419c2149c8Sths     int32_t CP0_DESAVE;
542b5dc7732Sths     /* We waste some space so we can handle shadow registers like TCs. */
543b5dc7732Sths     TCState tcs[MIPS_SHADOW_SET_MAX];
544f01be154Sths     CPUMIPSFPUContext fpus[MIPS_FPU_MAX];
5455cbdb3a3SStefan Weil     /* QEMU */
5466af0bf9cSbellard     int error_code;
547aea14095SLeon Alrae #define EXCP_TLB_NOMATCH   0x1
548aea14095SLeon Alrae #define EXCP_INST_NOTAVAIL 0x2 /* No valid instruction word for BadInstr */
5496af0bf9cSbellard     uint32_t hflags;    /* CPU State */
5506af0bf9cSbellard     /* TMASK defines different execution modes */
5510d74a222SLeon Alrae #define MIPS_HFLAG_TMASK  0xF5807FF
55279ef2c4cSNathan Froyd #define MIPS_HFLAG_MODE   0x00007 /* execution modes                    */
553623a930eSths     /* The KSU flags must be the lowest bits in hflags. The flag order
554623a930eSths        must be the same as defined for CP0 Status. This allows to use
555623a930eSths        the bits as the value of mmu_idx. */
55679ef2c4cSNathan Froyd #define MIPS_HFLAG_KSU    0x00003 /* kernel/supervisor/user mode mask   */
55779ef2c4cSNathan Froyd #define MIPS_HFLAG_UM     0x00002 /* user mode flag                     */
55879ef2c4cSNathan Froyd #define MIPS_HFLAG_SM     0x00001 /* supervisor mode flag               */
55979ef2c4cSNathan Froyd #define MIPS_HFLAG_KM     0x00000 /* kernel mode flag                   */
56079ef2c4cSNathan Froyd #define MIPS_HFLAG_DM     0x00004 /* Debug mode                         */
56179ef2c4cSNathan Froyd #define MIPS_HFLAG_64     0x00008 /* 64-bit instructions enabled        */
56279ef2c4cSNathan Froyd #define MIPS_HFLAG_CP0    0x00010 /* CP0 enabled                        */
56379ef2c4cSNathan Froyd #define MIPS_HFLAG_FPU    0x00020 /* FPU enabled                        */
56479ef2c4cSNathan Froyd #define MIPS_HFLAG_F64    0x00040 /* 64-bit FPU enabled                 */
565b8aa4598Sths     /* True if the MIPS IV COP1X instructions can be used.  This also
566b8aa4598Sths        controls the non-COP1X instructions RECIP.S, RECIP.D, RSQRT.S
567b8aa4598Sths        and RSQRT.D.  */
56879ef2c4cSNathan Froyd #define MIPS_HFLAG_COP1X  0x00080 /* COP1X instructions enabled         */
56979ef2c4cSNathan Froyd #define MIPS_HFLAG_RE     0x00100 /* Reversed endianness                */
57001f72885SLeon Alrae #define MIPS_HFLAG_AWRAP  0x00200 /* 32-bit compatibility address wrapping */
57179ef2c4cSNathan Froyd #define MIPS_HFLAG_M16    0x00400 /* MIPS16 mode flag                   */
57279ef2c4cSNathan Froyd #define MIPS_HFLAG_M16_SHIFT 10
5734ad40f36Sbellard     /* If translation is interrupted between the branch instruction and
5744ad40f36Sbellard      * the delay slot, record what type of branch it is so that we can
5754ad40f36Sbellard      * resume translation properly.  It might be possible to reduce
5764ad40f36Sbellard      * this from three bits to two.  */
577339cd2a8SLeon Alrae #define MIPS_HFLAG_BMASK_BASE  0x803800
57879ef2c4cSNathan Froyd #define MIPS_HFLAG_B      0x00800 /* Unconditional branch               */
57979ef2c4cSNathan Froyd #define MIPS_HFLAG_BC     0x01000 /* Conditional branch                 */
58079ef2c4cSNathan Froyd #define MIPS_HFLAG_BL     0x01800 /* Likely branch                      */
58179ef2c4cSNathan Froyd #define MIPS_HFLAG_BR     0x02000 /* branch to register (can't link TB) */
58279ef2c4cSNathan Froyd     /* Extra flags about the current pending branch.  */
583b231c103SYongbok Kim #define MIPS_HFLAG_BMASK_EXT 0x7C000
58479ef2c4cSNathan Froyd #define MIPS_HFLAG_B16    0x04000 /* branch instruction was 16 bits     */
58579ef2c4cSNathan Froyd #define MIPS_HFLAG_BDS16  0x08000 /* branch requires 16-bit delay slot  */
58679ef2c4cSNathan Froyd #define MIPS_HFLAG_BDS32  0x10000 /* branch requires 32-bit delay slot  */
587b231c103SYongbok Kim #define MIPS_HFLAG_BDS_STRICT  0x20000 /* Strict delay slot size */
588b231c103SYongbok Kim #define MIPS_HFLAG_BX     0x40000 /* branch exchanges execution mode    */
58979ef2c4cSNathan Froyd #define MIPS_HFLAG_BMASK  (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT)
590853c3240SJia Liu     /* MIPS DSP resources access. */
591b231c103SYongbok Kim #define MIPS_HFLAG_DSP   0x080000  /* Enable access to MIPS DSP resources. */
592b231c103SYongbok Kim #define MIPS_HFLAG_DSPR2 0x100000  /* Enable access to MIPS DSPR2 resources. */
593d279279eSPetar Jovanovic     /* Extra flag about HWREna register. */
594b231c103SYongbok Kim #define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */
595faf1f68bSLeon Alrae #define MIPS_HFLAG_SBRI  0x400000 /* R6 SDBBP causes RI excpt. in user mode */
596339cd2a8SLeon Alrae #define MIPS_HFLAG_FBNSLOT 0x800000 /* Forbidden slot                   */
597e97a391dSYongbok Kim #define MIPS_HFLAG_MSA   0x1000000
5987c979afdSLeon Alrae #define MIPS_HFLAG_FRE   0x2000000 /* FRE enabled */
599e117f526SLeon Alrae #define MIPS_HFLAG_ELPA  0x4000000
6000d74a222SLeon Alrae #define MIPS_HFLAG_ITC_CACHE  0x8000000 /* CACHE instr. operates on ITC tag */
6016af0bf9cSbellard     target_ulong btarget;        /* Jump / branch target               */
6021ba74fb8Saurel32     target_ulong bcond;          /* Branch condition (if needed)       */
603a316d335Sbellard 
6047a387fffSths     int SYNCI_Step; /* Address step size for SYNCI */
6057a387fffSths     int CCRes; /* Cycle count resolution/divisor */
606ead9360eSths     uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */
607ead9360eSths     uint32_t CP0_TCStatus_rw_bitmask; /* Read/write bits in CP0_TCStatus */
608e189e748Sths     int insn_flags; /* Supported instruction set */
6097a387fffSths 
610*1f5c00cfSAlex Bennée     /* Fields up to this point are cleared by a CPU reset */
611*1f5c00cfSAlex Bennée     struct {} end_reset_fields;
612*1f5c00cfSAlex Bennée 
613a316d335Sbellard     CPU_COMMON
6146ae81775Sths 
615f0c3c505SAndreas Färber     /* Fields from here on are preserved across CPU reset. */
61651cc2e78SBlue Swirl     CPUMIPSMVPContext *mvp;
6173c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
61851cc2e78SBlue Swirl     CPUMIPSTLBContext *tlb;
6193c7b48b7SPaul Brook #endif
62051cc2e78SBlue Swirl 
621c227f099SAnthony Liguori     const mips_def_t *cpu_model;
62233ac7f16Sths     void *irq[8];
6231246b259SStefan Weil     QEMUTimer *timer; /* Internal timer */
62434fa7e83SLeon Alrae     MemoryRegion *itc_tag; /* ITC Configuration Tags */
62589777fd1SLeon Alrae     target_ulong exception_base; /* ExceptionBase input to the core */
6266af0bf9cSbellard };
6276af0bf9cSbellard 
628416bf936SPaolo Bonzini /**
629416bf936SPaolo Bonzini  * MIPSCPU:
630416bf936SPaolo Bonzini  * @env: #CPUMIPSState
631416bf936SPaolo Bonzini  *
632416bf936SPaolo Bonzini  * A MIPS CPU.
633416bf936SPaolo Bonzini  */
634416bf936SPaolo Bonzini struct MIPSCPU {
635416bf936SPaolo Bonzini     /*< private >*/
636416bf936SPaolo Bonzini     CPUState parent_obj;
637416bf936SPaolo Bonzini     /*< public >*/
638416bf936SPaolo Bonzini 
639416bf936SPaolo Bonzini     CPUMIPSState env;
640416bf936SPaolo Bonzini };
641416bf936SPaolo Bonzini 
642416bf936SPaolo Bonzini static inline MIPSCPU *mips_env_get_cpu(CPUMIPSState *env)
643416bf936SPaolo Bonzini {
644416bf936SPaolo Bonzini     return container_of(env, MIPSCPU, env);
645416bf936SPaolo Bonzini }
646416bf936SPaolo Bonzini 
647416bf936SPaolo Bonzini #define ENV_GET_CPU(e) CPU(mips_env_get_cpu(e))
648416bf936SPaolo Bonzini 
649416bf936SPaolo Bonzini #define ENV_OFFSET offsetof(MIPSCPU, env)
650416bf936SPaolo Bonzini 
651416bf936SPaolo Bonzini #ifndef CONFIG_USER_ONLY
652416bf936SPaolo Bonzini extern const struct VMStateDescription vmstate_mips_cpu;
653416bf936SPaolo Bonzini #endif
654416bf936SPaolo Bonzini 
655416bf936SPaolo Bonzini void mips_cpu_do_interrupt(CPUState *cpu);
656416bf936SPaolo Bonzini bool mips_cpu_exec_interrupt(CPUState *cpu, int int_req);
657416bf936SPaolo Bonzini void mips_cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
658416bf936SPaolo Bonzini                          int flags);
659416bf936SPaolo Bonzini hwaddr mips_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
660416bf936SPaolo Bonzini int mips_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
661416bf936SPaolo Bonzini int mips_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
662416bf936SPaolo Bonzini void mips_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
663b35399bbSSergey Sorokin                                   MMUAccessType access_type,
664b35399bbSSergey Sorokin                                   int mmu_idx, uintptr_t retaddr);
6650f71a709SAndreas Färber 
6663c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
667a8170e5eSAvi Kivity int no_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
66829929e34Sths                         target_ulong address, int rw, int access_type);
669a8170e5eSAvi Kivity int fixed_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
67029929e34Sths                            target_ulong address, int rw, int access_type);
671a8170e5eSAvi Kivity int r4k_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
67229929e34Sths                      target_ulong address, int rw, int access_type);
673895c2d04SBlue Swirl void r4k_helper_tlbwi(CPUMIPSState *env);
674895c2d04SBlue Swirl void r4k_helper_tlbwr(CPUMIPSState *env);
675895c2d04SBlue Swirl void r4k_helper_tlbp(CPUMIPSState *env);
676895c2d04SBlue Swirl void r4k_helper_tlbr(CPUMIPSState *env);
6779456c2fbSLeon Alrae void r4k_helper_tlbinv(CPUMIPSState *env);
6789456c2fbSLeon Alrae void r4k_helper_tlbinvf(CPUMIPSState *env);
67933d68b5fSths 
680c658b94fSAndreas Färber void mips_cpu_unassigned_access(CPUState *cpu, hwaddr addr,
681c658b94fSAndreas Färber                                 bool is_write, bool is_exec, int unused,
682c658b94fSAndreas Färber                                 unsigned size);
6833c7b48b7SPaul Brook #endif
6843c7b48b7SPaul Brook 
6859a78eeadSStefan Weil void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf);
686647de6caSths 
6879467d44cSths #define cpu_signal_handler cpu_mips_signal_handler
688c732abe2Sj_mayer #define cpu_list mips_cpu_list
6899467d44cSths 
690084d0497SRichard Henderson extern void cpu_wrdsp(uint32_t rs, uint32_t mask_num, CPUMIPSState *env);
691084d0497SRichard Henderson extern uint32_t cpu_rddsp(uint32_t mask_num, CPUMIPSState *env);
692084d0497SRichard Henderson 
693623a930eSths /* MMU modes definitions. We carefully match the indices with our
694623a930eSths    hflags layout. */
6956ebbf390Sj_mayer #define MMU_MODE0_SUFFIX _kernel
696623a930eSths #define MMU_MODE1_SUFFIX _super
697623a930eSths #define MMU_MODE2_SUFFIX _user
698623a930eSths #define MMU_USER_IDX 2
69997ed5ccdSBenjamin Herrenschmidt static inline int cpu_mmu_index (CPUMIPSState *env, bool ifetch)
7006ebbf390Sj_mayer {
701623a930eSths     return env->hflags & MIPS_HFLAG_KSU;
7026ebbf390Sj_mayer }
7036ebbf390Sj_mayer 
70471ca034aSLeon Alrae static inline bool cpu_mips_hw_interrupts_enabled(CPUMIPSState *env)
705138afb02SEdgar E. Iglesias {
70671ca034aSLeon Alrae     return (env->CP0_Status & (1 << CP0St_IE)) &&
70771ca034aSLeon Alrae         !(env->CP0_Status & (1 << CP0St_EXL)) &&
70871ca034aSLeon Alrae         !(env->CP0_Status & (1 << CP0St_ERL)) &&
70971ca034aSLeon Alrae         !(env->hflags & MIPS_HFLAG_DM) &&
710344eecf6SEdgar E. Iglesias         /* Note that the TCStatus IXMT field is initialized to zero,
711344eecf6SEdgar E. Iglesias            and only MT capable cores can set it to one. So we don't
712344eecf6SEdgar E. Iglesias            need to check for MT capabilities here.  */
71371ca034aSLeon Alrae         !(env->active_tc.CP0_TCStatus & (1 << CP0TCSt_IXMT));
7144cdc1cd1SAurelien Jarno }
7154cdc1cd1SAurelien Jarno 
71671ca034aSLeon Alrae /* Check if there is pending and not masked out interrupt */
71771ca034aSLeon Alrae static inline bool cpu_mips_hw_interrupts_pending(CPUMIPSState *env)
71871ca034aSLeon Alrae {
71971ca034aSLeon Alrae     int32_t pending;
72071ca034aSLeon Alrae     int32_t status;
72171ca034aSLeon Alrae     bool r;
72271ca034aSLeon Alrae 
723138afb02SEdgar E. Iglesias     pending = env->CP0_Cause & CP0Ca_IP_mask;
724138afb02SEdgar E. Iglesias     status = env->CP0_Status & CP0Ca_IP_mask;
725138afb02SEdgar E. Iglesias 
726138afb02SEdgar E. Iglesias     if (env->CP0_Config3 & (1 << CP0C3_VEIC)) {
727138afb02SEdgar E. Iglesias         /* A MIPS configured with a vectorizing external interrupt controller
728138afb02SEdgar E. Iglesias            will feed a vector into the Cause pending lines. The core treats
729138afb02SEdgar E. Iglesias            the status lines as a vector level, not as indiviual masks.  */
730138afb02SEdgar E. Iglesias         r = pending > status;
731138afb02SEdgar E. Iglesias     } else {
732138afb02SEdgar E. Iglesias         /* A MIPS configured with compatibility or VInt (Vectored Interrupts)
733138afb02SEdgar E. Iglesias            treats the pending lines as individual interrupt lines, the status
734138afb02SEdgar E. Iglesias            lines are individual masks.  */
73571ca034aSLeon Alrae         r = (pending & status) != 0;
736138afb02SEdgar E. Iglesias     }
737138afb02SEdgar E. Iglesias     return r;
738138afb02SEdgar E. Iglesias }
739138afb02SEdgar E. Iglesias 
740022c62cbSPaolo Bonzini #include "exec/cpu-all.h"
7416af0bf9cSbellard 
7426af0bf9cSbellard /* Memory access type :
7436af0bf9cSbellard  * may be needed for precise access rights control and precise exceptions.
7446af0bf9cSbellard  */
7456af0bf9cSbellard enum {
7466af0bf9cSbellard     /* 1 bit to define user level / supervisor access */
7476af0bf9cSbellard     ACCESS_USER  = 0x00,
7486af0bf9cSbellard     ACCESS_SUPER = 0x01,
7496af0bf9cSbellard     /* 1 bit to indicate direction */
7506af0bf9cSbellard     ACCESS_STORE = 0x02,
7516af0bf9cSbellard     /* Type of instruction that generated the access */
7526af0bf9cSbellard     ACCESS_CODE  = 0x10, /* Code fetch access                */
7536af0bf9cSbellard     ACCESS_INT   = 0x20, /* Integer load/store access        */
7546af0bf9cSbellard     ACCESS_FLOAT = 0x30, /* floating point load/store access */
7556af0bf9cSbellard };
7566af0bf9cSbellard 
7576af0bf9cSbellard /* Exceptions */
7586af0bf9cSbellard enum {
7596af0bf9cSbellard     EXCP_NONE          = -1,
7606af0bf9cSbellard     EXCP_RESET         = 0,
7616af0bf9cSbellard     EXCP_SRESET,
7626af0bf9cSbellard     EXCP_DSS,
7636af0bf9cSbellard     EXCP_DINT,
76414e51cc7Sths     EXCP_DDBL,
76514e51cc7Sths     EXCP_DDBS,
7666af0bf9cSbellard     EXCP_NMI,
7676af0bf9cSbellard     EXCP_MCHECK,
76814e51cc7Sths     EXCP_EXT_INTERRUPT, /* 8 */
7696af0bf9cSbellard     EXCP_DFWATCH,
77014e51cc7Sths     EXCP_DIB,
7716af0bf9cSbellard     EXCP_IWATCH,
7726af0bf9cSbellard     EXCP_AdEL,
7736af0bf9cSbellard     EXCP_AdES,
7746af0bf9cSbellard     EXCP_TLBF,
7756af0bf9cSbellard     EXCP_IBE,
77614e51cc7Sths     EXCP_DBp, /* 16 */
7776af0bf9cSbellard     EXCP_SYSCALL,
77814e51cc7Sths     EXCP_BREAK,
7794ad40f36Sbellard     EXCP_CpU,
7806af0bf9cSbellard     EXCP_RI,
7816af0bf9cSbellard     EXCP_OVERFLOW,
7826af0bf9cSbellard     EXCP_TRAP,
7835a5012ecSths     EXCP_FPE,
78414e51cc7Sths     EXCP_DWATCH, /* 24 */
7856af0bf9cSbellard     EXCP_LTLBL,
7866af0bf9cSbellard     EXCP_TLBL,
7876af0bf9cSbellard     EXCP_TLBS,
7886af0bf9cSbellard     EXCP_DBE,
789ead9360eSths     EXCP_THREAD,
79014e51cc7Sths     EXCP_MDMX,
79114e51cc7Sths     EXCP_C2E,
79214e51cc7Sths     EXCP_CACHE, /* 32 */
793853c3240SJia Liu     EXCP_DSPDIS,
794e97a391dSYongbok Kim     EXCP_MSADIS,
795e97a391dSYongbok Kim     EXCP_MSAFPE,
79692ceb440SLeon Alrae     EXCP_TLBXI,
79792ceb440SLeon Alrae     EXCP_TLBRI,
79814e51cc7Sths 
79992ceb440SLeon Alrae     EXCP_LAST = EXCP_TLBRI,
8006af0bf9cSbellard };
801590bc601SPaul Brook /* Dummy exception for conditional stores.  */
802590bc601SPaul Brook #define EXCP_SC 0x100
8036af0bf9cSbellard 
804f249412cSEdgar E. Iglesias /*
805f249412cSEdgar E. Iglesias  * This is an interrnally generated WAKE request line.
806f249412cSEdgar E. Iglesias  * It is driven by the CPU itself. Raised when the MT
807f249412cSEdgar E. Iglesias  * block wants to wake a VPE from an inactive state and
808f249412cSEdgar E. Iglesias  * cleared when VPE goes from active to inactive.
809f249412cSEdgar E. Iglesias  */
810f249412cSEdgar E. Iglesias #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0
811f249412cSEdgar E. Iglesias 
81278ce64f4SAndreas Färber void mips_tcg_init(void);
81330bf942dSAndreas Färber MIPSCPU *cpu_mips_init(const char *cpu_model);
814388bb21aSths int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
8156af0bf9cSbellard 
8162994fd96SEduardo Habkost #define cpu_init(cpu_model) CPU(cpu_mips_init(cpu_model))
817bff384a4SLeon Alrae bool cpu_supports_cps_smp(const char *cpu_model);
81889777fd1SLeon Alrae void cpu_set_exception_base(int vp_index, target_ulong address);
81930bf942dSAndreas Färber 
820b7e516ceSAndreas Färber /* TODO QOM'ify CPU reset and remove */
821b7e516ceSAndreas Färber void cpu_state_reset(CPUMIPSState *s);
822b7e516ceSAndreas Färber 
823f9480ffcSths /* mips_timer.c */
8247db13faeSAndreas Färber uint32_t cpu_mips_get_random (CPUMIPSState *env);
8257db13faeSAndreas Färber uint32_t cpu_mips_get_count (CPUMIPSState *env);
8267db13faeSAndreas Färber void cpu_mips_store_count (CPUMIPSState *env, uint32_t value);
8277db13faeSAndreas Färber void cpu_mips_store_compare (CPUMIPSState *env, uint32_t value);
8287db13faeSAndreas Färber void cpu_mips_start_count(CPUMIPSState *env);
8297db13faeSAndreas Färber void cpu_mips_stop_count(CPUMIPSState *env);
830f9480ffcSths 
8315dc5d9f0SAurelien Jarno /* mips_int.c */
8327db13faeSAndreas Färber void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level);
8335dc5d9f0SAurelien Jarno 
834f9480ffcSths /* helper.c */
8357510454eSAndreas Färber int mips_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
83697b348e7SBlue Swirl                               int mmu_idx);
837af39bc8cSAleksandar Markovic 
838af39bc8cSAleksandar Markovic /* op_helper.c */
839af39bc8cSAleksandar Markovic uint32_t float_class_s(uint32_t arg, float_status *fst);
840af39bc8cSAleksandar Markovic uint64_t float_class_d(uint64_t arg, float_status *fst);
841af39bc8cSAleksandar Markovic 
8423c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
8437db13faeSAndreas Färber void r4k_invalidate_tlb (CPUMIPSState *env, int idx, int use_extra);
844a8170e5eSAvi Kivity hwaddr cpu_mips_translate_address (CPUMIPSState *env, target_ulong address,
84525b91e32SAurelien Jarno 		                               int rw);
8463c7b48b7SPaul Brook #endif
8471239b472SKwok Cheung Yeung target_ulong exception_resume_pc (CPUMIPSState *env);
848f9480ffcSths 
849b7651e95SYongbok Kim /* op_helper.c */
850b7651e95SYongbok Kim extern unsigned int ieee_rm[];
851b7651e95SYongbok Kim int ieee_ex_to_mips(int xcpt);
852b7651e95SYongbok Kim 
853bb962386SMaciej W. Rozycki static inline void restore_rounding_mode(CPUMIPSState *env)
854bb962386SMaciej W. Rozycki {
855bb962386SMaciej W. Rozycki     set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3],
856bb962386SMaciej W. Rozycki                             &env->active_fpu.fp_status);
857bb962386SMaciej W. Rozycki }
858bb962386SMaciej W. Rozycki 
859bb962386SMaciej W. Rozycki static inline void restore_flush_mode(CPUMIPSState *env)
860bb962386SMaciej W. Rozycki {
86177be4199SAleksandar Markovic     set_flush_to_zero((env->active_fpu.fcr31 & (1 << FCR31_FS)) != 0,
862bb962386SMaciej W. Rozycki                       &env->active_fpu.fp_status);
863bb962386SMaciej W. Rozycki }
864bb962386SMaciej W. Rozycki 
865599bc5e8SAleksandar Markovic static inline void restore_snan_bit_mode(CPUMIPSState *env)
866599bc5e8SAleksandar Markovic {
867599bc5e8SAleksandar Markovic     set_snan_bit_is_one((env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) == 0,
868599bc5e8SAleksandar Markovic                         &env->active_fpu.fp_status);
869599bc5e8SAleksandar Markovic }
870599bc5e8SAleksandar Markovic 
87164451111SLeon Alrae static inline void restore_fp_status(CPUMIPSState *env)
87264451111SLeon Alrae {
87364451111SLeon Alrae     restore_rounding_mode(env);
87464451111SLeon Alrae     restore_flush_mode(env);
875599bc5e8SAleksandar Markovic     restore_snan_bit_mode(env);
87664451111SLeon Alrae }
87764451111SLeon Alrae 
87864451111SLeon Alrae static inline void restore_msa_fp_status(CPUMIPSState *env)
87964451111SLeon Alrae {
88064451111SLeon Alrae     float_status *status = &env->active_tc.msa_fp_status;
88164451111SLeon Alrae     int rounding_mode = (env->active_tc.msacsr & MSACSR_RM_MASK) >> MSACSR_RM;
88264451111SLeon Alrae     bool flush_to_zero = (env->active_tc.msacsr & MSACSR_FS_MASK) != 0;
88364451111SLeon Alrae 
88464451111SLeon Alrae     set_float_rounding_mode(ieee_rm[rounding_mode], status);
88564451111SLeon Alrae     set_flush_to_zero(flush_to_zero, status);
88664451111SLeon Alrae     set_flush_inputs_to_zero(flush_to_zero, status);
88764451111SLeon Alrae }
88864451111SLeon Alrae 
889e117f526SLeon Alrae static inline void restore_pamask(CPUMIPSState *env)
890e117f526SLeon Alrae {
891e117f526SLeon Alrae     if (env->hflags & MIPS_HFLAG_ELPA) {
892e117f526SLeon Alrae         env->PAMask = (1ULL << env->PABITS) - 1;
893e117f526SLeon Alrae     } else {
894e117f526SLeon Alrae         env->PAMask = PAMASK_BASE;
895e117f526SLeon Alrae     }
896e117f526SLeon Alrae }
897e117f526SLeon Alrae 
8987db13faeSAndreas Färber static inline void cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc,
89989fee74aSEmilio G. Cota                                         target_ulong *cs_base, uint32_t *flags)
9006b917547Saliguori {
9016b917547Saliguori     *pc = env->active_tc.PC;
9026b917547Saliguori     *cs_base = 0;
903d279279eSPetar Jovanovic     *flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK |
904d279279eSPetar Jovanovic                             MIPS_HFLAG_HWRENA_ULR);
9056b917547Saliguori }
9066b917547Saliguori 
9077db13faeSAndreas Färber static inline int mips_vpe_active(CPUMIPSState *env)
908f249412cSEdgar E. Iglesias {
909f249412cSEdgar E. Iglesias     int active = 1;
910f249412cSEdgar E. Iglesias 
911f249412cSEdgar E. Iglesias     /* Check that the VPE is enabled.  */
912f249412cSEdgar E. Iglesias     if (!(env->mvp->CP0_MVPControl & (1 << CP0MVPCo_EVP))) {
913f249412cSEdgar E. Iglesias         active = 0;
914f249412cSEdgar E. Iglesias     }
9154abf79a4SDong Xu Wang     /* Check that the VPE is activated.  */
916f249412cSEdgar E. Iglesias     if (!(env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))) {
917f249412cSEdgar E. Iglesias         active = 0;
918f249412cSEdgar E. Iglesias     }
919f249412cSEdgar E. Iglesias 
920f249412cSEdgar E. Iglesias     /* Now verify that there are active thread contexts in the VPE.
921f249412cSEdgar E. Iglesias 
922f249412cSEdgar E. Iglesias        This assumes the CPU model will internally reschedule threads
923f249412cSEdgar E. Iglesias        if the active one goes to sleep. If there are no threads available
924f249412cSEdgar E. Iglesias        the active one will be in a sleeping state, and we can turn off
925f249412cSEdgar E. Iglesias        the entire VPE.  */
926f249412cSEdgar E. Iglesias     if (!(env->active_tc.CP0_TCStatus & (1 << CP0TCSt_A))) {
927f249412cSEdgar E. Iglesias         /* TC is not activated.  */
928f249412cSEdgar E. Iglesias         active = 0;
929f249412cSEdgar E. Iglesias     }
930f249412cSEdgar E. Iglesias     if (env->active_tc.CP0_TCHalt & 1) {
931f249412cSEdgar E. Iglesias         /* TC is in halt state.  */
932f249412cSEdgar E. Iglesias         active = 0;
933f249412cSEdgar E. Iglesias     }
934f249412cSEdgar E. Iglesias 
935f249412cSEdgar E. Iglesias     return active;
936f249412cSEdgar E. Iglesias }
937f249412cSEdgar E. Iglesias 
93801bc435bSYongbok Kim static inline int mips_vp_active(CPUMIPSState *env)
93901bc435bSYongbok Kim {
94001bc435bSYongbok Kim     CPUState *other_cs = first_cpu;
94101bc435bSYongbok Kim 
94201bc435bSYongbok Kim     /* Check if the VP disabled other VPs (which means the VP is enabled) */
94301bc435bSYongbok Kim     if ((env->CP0_VPControl >> CP0VPCtl_DIS) & 1) {
94401bc435bSYongbok Kim         return 1;
94501bc435bSYongbok Kim     }
94601bc435bSYongbok Kim 
94701bc435bSYongbok Kim     /* Check if the virtual processor is disabled due to a DVP */
94801bc435bSYongbok Kim     CPU_FOREACH(other_cs) {
94901bc435bSYongbok Kim         MIPSCPU *other_cpu = MIPS_CPU(other_cs);
95001bc435bSYongbok Kim         if ((&other_cpu->env != env) &&
95101bc435bSYongbok Kim             ((other_cpu->env.CP0_VPControl >> CP0VPCtl_DIS) & 1)) {
95201bc435bSYongbok Kim             return 0;
95301bc435bSYongbok Kim         }
95401bc435bSYongbok Kim     }
95501bc435bSYongbok Kim     return 1;
95601bc435bSYongbok Kim }
95701bc435bSYongbok Kim 
95803e6e501SMaciej W. Rozycki static inline void compute_hflags(CPUMIPSState *env)
95903e6e501SMaciej W. Rozycki {
96003e6e501SMaciej W. Rozycki     env->hflags &= ~(MIPS_HFLAG_COP1X | MIPS_HFLAG_64 | MIPS_HFLAG_CP0 |
96103e6e501SMaciej W. Rozycki                      MIPS_HFLAG_F64 | MIPS_HFLAG_FPU | MIPS_HFLAG_KSU |
962faf1f68bSLeon Alrae                      MIPS_HFLAG_AWRAP | MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2 |
963e117f526SLeon Alrae                      MIPS_HFLAG_SBRI | MIPS_HFLAG_MSA | MIPS_HFLAG_FRE |
964e117f526SLeon Alrae                      MIPS_HFLAG_ELPA);
96503e6e501SMaciej W. Rozycki     if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
96603e6e501SMaciej W. Rozycki         !(env->CP0_Status & (1 << CP0St_ERL)) &&
96703e6e501SMaciej W. Rozycki         !(env->hflags & MIPS_HFLAG_DM)) {
96803e6e501SMaciej W. Rozycki         env->hflags |= (env->CP0_Status >> CP0St_KSU) & MIPS_HFLAG_KSU;
96903e6e501SMaciej W. Rozycki     }
97003e6e501SMaciej W. Rozycki #if defined(TARGET_MIPS64)
971d9224450SMaciej W. Rozycki     if ((env->insn_flags & ISA_MIPS3) &&
972d9224450SMaciej W. Rozycki         (((env->hflags & MIPS_HFLAG_KSU) != MIPS_HFLAG_UM) ||
97303e6e501SMaciej W. Rozycki          (env->CP0_Status & (1 << CP0St_PX)) ||
974d9224450SMaciej W. Rozycki          (env->CP0_Status & (1 << CP0St_UX)))) {
97503e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_64;
97603e6e501SMaciej W. Rozycki     }
97701f72885SLeon Alrae 
978c48245f0SMaciej W. Rozycki     if (!(env->insn_flags & ISA_MIPS3)) {
979c48245f0SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_AWRAP;
980c48245f0SMaciej W. Rozycki     } else if (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
98101f72885SLeon Alrae                !(env->CP0_Status & (1 << CP0St_UX))) {
98201f72885SLeon Alrae         env->hflags |= MIPS_HFLAG_AWRAP;
983c48245f0SMaciej W. Rozycki     } else if (env->insn_flags & ISA_MIPS64R6) {
98401f72885SLeon Alrae         /* Address wrapping for Supervisor and Kernel is specified in R6 */
98501f72885SLeon Alrae         if ((((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_SM) &&
98601f72885SLeon Alrae              !(env->CP0_Status & (1 << CP0St_SX))) ||
98701f72885SLeon Alrae             (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_KM) &&
98801f72885SLeon Alrae              !(env->CP0_Status & (1 << CP0St_KX)))) {
98901f72885SLeon Alrae             env->hflags |= MIPS_HFLAG_AWRAP;
99001f72885SLeon Alrae         }
99103e6e501SMaciej W. Rozycki     }
99203e6e501SMaciej W. Rozycki #endif
993a63eb0ceSLeon Alrae     if (((env->CP0_Status & (1 << CP0St_CU0)) &&
994a63eb0ceSLeon Alrae          !(env->insn_flags & ISA_MIPS32R6)) ||
99503e6e501SMaciej W. Rozycki         !(env->hflags & MIPS_HFLAG_KSU)) {
99603e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_CP0;
99703e6e501SMaciej W. Rozycki     }
99803e6e501SMaciej W. Rozycki     if (env->CP0_Status & (1 << CP0St_CU1)) {
99903e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_FPU;
100003e6e501SMaciej W. Rozycki     }
100103e6e501SMaciej W. Rozycki     if (env->CP0_Status & (1 << CP0St_FR)) {
100203e6e501SMaciej W. Rozycki         env->hflags |= MIPS_HFLAG_F64;
100303e6e501SMaciej W. Rozycki     }
1004faf1f68bSLeon Alrae     if (((env->hflags & MIPS_HFLAG_KSU) != MIPS_HFLAG_KM) &&
1005faf1f68bSLeon Alrae         (env->CP0_Config5 & (1 << CP0C5_SBRI))) {
1006faf1f68bSLeon Alrae         env->hflags |= MIPS_HFLAG_SBRI;
1007faf1f68bSLeon Alrae     }
1008853c3240SJia Liu     if (env->insn_flags & ASE_DSPR2) {
1009853c3240SJia Liu         /* Enables access MIPS DSP resources, now our cpu is DSP ASER2,
1010853c3240SJia Liu            so enable to access DSPR2 resources. */
1011853c3240SJia Liu         if (env->CP0_Status & (1 << CP0St_MX)) {
1012853c3240SJia Liu             env->hflags |= MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2;
1013853c3240SJia Liu         }
1014853c3240SJia Liu 
1015853c3240SJia Liu     } else if (env->insn_flags & ASE_DSP) {
1016853c3240SJia Liu         /* Enables access MIPS DSP resources, now our cpu is DSP ASE,
1017853c3240SJia Liu            so enable to access DSP resources. */
1018853c3240SJia Liu         if (env->CP0_Status & (1 << CP0St_MX)) {
1019853c3240SJia Liu             env->hflags |= MIPS_HFLAG_DSP;
1020853c3240SJia Liu         }
1021853c3240SJia Liu 
1022853c3240SJia Liu     }
102303e6e501SMaciej W. Rozycki     if (env->insn_flags & ISA_MIPS32R2) {
102403e6e501SMaciej W. Rozycki         if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
102503e6e501SMaciej W. Rozycki             env->hflags |= MIPS_HFLAG_COP1X;
102603e6e501SMaciej W. Rozycki         }
102703e6e501SMaciej W. Rozycki     } else if (env->insn_flags & ISA_MIPS32) {
102803e6e501SMaciej W. Rozycki         if (env->hflags & MIPS_HFLAG_64) {
102903e6e501SMaciej W. Rozycki             env->hflags |= MIPS_HFLAG_COP1X;
103003e6e501SMaciej W. Rozycki         }
103103e6e501SMaciej W. Rozycki     } else if (env->insn_flags & ISA_MIPS4) {
103203e6e501SMaciej W. Rozycki         /* All supported MIPS IV CPUs use the XX (CU3) to enable
103303e6e501SMaciej W. Rozycki            and disable the MIPS IV extensions to the MIPS III ISA.
103403e6e501SMaciej W. Rozycki            Some other MIPS IV CPUs ignore the bit, so the check here
103503e6e501SMaciej W. Rozycki            would be too restrictive for them.  */
1036f45cb2f4SPeter Maydell         if (env->CP0_Status & (1U << CP0St_CU3)) {
103703e6e501SMaciej W. Rozycki             env->hflags |= MIPS_HFLAG_COP1X;
103803e6e501SMaciej W. Rozycki         }
103903e6e501SMaciej W. Rozycki     }
1040e97a391dSYongbok Kim     if (env->insn_flags & ASE_MSA) {
1041e97a391dSYongbok Kim         if (env->CP0_Config5 & (1 << CP0C5_MSAEn)) {
1042e97a391dSYongbok Kim             env->hflags |= MIPS_HFLAG_MSA;
1043e97a391dSYongbok Kim         }
1044e97a391dSYongbok Kim     }
10457c979afdSLeon Alrae     if (env->active_fpu.fcr0 & (1 << FCR0_FREP)) {
10467c979afdSLeon Alrae         if (env->CP0_Config5 & (1 << CP0C5_FRE)) {
10477c979afdSLeon Alrae             env->hflags |= MIPS_HFLAG_FRE;
10487c979afdSLeon Alrae         }
10497c979afdSLeon Alrae     }
1050e117f526SLeon Alrae     if (env->CP0_Config3 & (1 << CP0C3_LPA)) {
1051e117f526SLeon Alrae         if (env->CP0_PageGrain & (1 << CP0PG_ELPA)) {
1052e117f526SLeon Alrae             env->hflags |= MIPS_HFLAG_ELPA;
1053e117f526SLeon Alrae         }
1054e117f526SLeon Alrae     }
105503e6e501SMaciej W. Rozycki }
105603e6e501SMaciej W. Rozycki 
1057e6623d88SPaolo Bonzini void cpu_mips_tlb_flush(CPUMIPSState *env, int flush_global);
1058e6623d88SPaolo Bonzini void sync_c0_status(CPUMIPSState *env, CPUMIPSState *cpu, int tc);
1059e6623d88SPaolo Bonzini void cpu_mips_store_status(CPUMIPSState *env, target_ulong val);
1060e6623d88SPaolo Bonzini void cpu_mips_store_cause(CPUMIPSState *env, target_ulong val);
106181a423e6SMaciej W. Rozycki 
106233c11879SPaolo Bonzini void QEMU_NORETURN do_raise_exception_err(CPUMIPSState *env, uint32_t exception,
106333c11879SPaolo Bonzini                                           int error_code, uintptr_t pc);
10649c708c7fSPavel Dovgaluk 
10659c708c7fSPavel Dovgaluk static inline void QEMU_NORETURN do_raise_exception(CPUMIPSState *env,
10669c708c7fSPavel Dovgaluk                                                     uint32_t exception,
10679c708c7fSPavel Dovgaluk                                                     uintptr_t pc)
10689c708c7fSPavel Dovgaluk {
10699c708c7fSPavel Dovgaluk     do_raise_exception_err(env, exception, 0, pc);
10709c708c7fSPavel Dovgaluk }
10719c708c7fSPavel Dovgaluk 
107207f5a258SMarkus Armbruster #endif /* MIPS_CPU_H */
1073