xref: /qemu/target/mips/cpu.h (revision 0b16dcd180bdbe3add9edea42c2374d427882661)
107f5a258SMarkus Armbruster #ifndef MIPS_CPU_H
207f5a258SMarkus Armbruster #define MIPS_CPU_H
36af0bf9cSbellard 
4d94f0a8eSPaolo Bonzini #define ALIGNED_ONLY
54ad40f36Sbellard 
69349b4f9SAndreas Färber #define CPUArchState struct CPUMIPSState
7c2764719Spbrook 
89a78eeadSStefan Weil #include "qemu-common.h"
9416bf936SPaolo Bonzini #include "cpu-qom.h"
106af0bf9cSbellard #include "mips-defs.h"
11022c62cbSPaolo Bonzini #include "exec/cpu-defs.h"
126b4c305cSPaolo Bonzini #include "fpu/softfloat.h"
136af0bf9cSbellard 
14ead9360eSths struct CPUMIPSState;
156af0bf9cSbellard 
16ead9360eSths typedef struct CPUMIPSTLBContext CPUMIPSTLBContext;
1751b2772fSths 
18e97a391dSYongbok Kim /* MSA Context */
19e97a391dSYongbok Kim #define MSA_WRLEN (128)
20e97a391dSYongbok Kim 
21e97a391dSYongbok Kim typedef union wr_t wr_t;
22e97a391dSYongbok Kim union wr_t {
23e97a391dSYongbok Kim     int8_t  b[MSA_WRLEN/8];
24e97a391dSYongbok Kim     int16_t h[MSA_WRLEN/16];
25e97a391dSYongbok Kim     int32_t w[MSA_WRLEN/32];
26e97a391dSYongbok Kim     int64_t d[MSA_WRLEN/64];
27e97a391dSYongbok Kim };
28e97a391dSYongbok Kim 
29c227f099SAnthony Liguori typedef union fpr_t fpr_t;
30c227f099SAnthony Liguori union fpr_t {
31ead9360eSths     float64  fd;   /* ieee double precision */
32ead9360eSths     float32  fs[2];/* ieee single precision */
33ead9360eSths     uint64_t d;    /* binary double fixed-point */
34ead9360eSths     uint32_t w[2]; /* binary single fixed-point */
35e97a391dSYongbok Kim /* FPU/MSA register mapping is not tested on big-endian hosts. */
36e97a391dSYongbok Kim     wr_t     wr;   /* vector data */
37ead9360eSths };
38ead9360eSths /* define FP_ENDIAN_IDX to access the same location
394ff9786cSStefan Weil  * in the fpr_t union regardless of the host endianness
40ead9360eSths  */
41e2542fe2SJuan Quintela #if defined(HOST_WORDS_BIGENDIAN)
42ead9360eSths #  define FP_ENDIAN_IDX 1
43ead9360eSths #else
44ead9360eSths #  define FP_ENDIAN_IDX 0
45c570fd16Sths #endif
46ead9360eSths 
47ead9360eSths typedef struct CPUMIPSFPUContext CPUMIPSFPUContext;
48ead9360eSths struct CPUMIPSFPUContext {
496af0bf9cSbellard     /* Floating point registers */
50c227f099SAnthony Liguori     fpr_t fpr[32];
516ea83fedSbellard     float_status fp_status;
525a5012ecSths     /* fpu implementation/revision register (fir) */
536af0bf9cSbellard     uint32_t fcr0;
547c979afdSLeon Alrae #define FCR0_FREP 29
55b4dd99a3SPetar Jovanovic #define FCR0_UFRP 28
56ba5c79f2SLeon Alrae #define FCR0_HAS2008 23
575a5012ecSths #define FCR0_F64 22
585a5012ecSths #define FCR0_L 21
595a5012ecSths #define FCR0_W 20
605a5012ecSths #define FCR0_3D 19
615a5012ecSths #define FCR0_PS 18
625a5012ecSths #define FCR0_D 17
635a5012ecSths #define FCR0_S 16
645a5012ecSths #define FCR0_PRID 8
655a5012ecSths #define FCR0_REV 0
666ea83fedSbellard     /* fcsr */
67599bc5e8SAleksandar Markovic     uint32_t fcr31_rw_bitmask;
686ea83fedSbellard     uint32_t fcr31;
6977be4199SAleksandar Markovic #define FCR31_FS 24
70ba5c79f2SLeon Alrae #define FCR31_ABS2008 19
71ba5c79f2SLeon Alrae #define FCR31_NAN2008 18
72f01be154Sths #define SET_FP_COND(num,env)     do { ((env).fcr31) |= ((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
73f01be154Sths #define CLEAR_FP_COND(num,env)   do { ((env).fcr31) &= ~((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
74f01be154Sths #define GET_FP_COND(env)         ((((env).fcr31 >> 24) & 0xfe) | (((env).fcr31 >> 23) & 0x1))
756ea83fedSbellard #define GET_FP_CAUSE(reg)        (((reg) >> 12) & 0x3f)
766ea83fedSbellard #define GET_FP_ENABLE(reg)       (((reg) >>  7) & 0x1f)
776ea83fedSbellard #define GET_FP_FLAGS(reg)        (((reg) >>  2) & 0x1f)
785a5012ecSths #define SET_FP_CAUSE(reg,v)      do { (reg) = ((reg) & ~(0x3f << 12)) | ((v & 0x3f) << 12); } while(0)
795a5012ecSths #define SET_FP_ENABLE(reg,v)     do { (reg) = ((reg) & ~(0x1f <<  7)) | ((v & 0x1f) << 7); } while(0)
805a5012ecSths #define SET_FP_FLAGS(reg,v)      do { (reg) = ((reg) & ~(0x1f <<  2)) | ((v & 0x1f) << 2); } while(0)
815a5012ecSths #define UPDATE_FP_FLAGS(reg,v)   do { (reg) |= ((v & 0x1f) << 2); } while(0)
826ea83fedSbellard #define FP_INEXACT        1
836ea83fedSbellard #define FP_UNDERFLOW      2
846ea83fedSbellard #define FP_OVERFLOW       4
856ea83fedSbellard #define FP_DIV0           8
866ea83fedSbellard #define FP_INVALID        16
876ea83fedSbellard #define FP_UNIMPLEMENTED  32
88ead9360eSths };
896ea83fedSbellard 
9042c86612SJames Hogan #define NB_MMU_MODES 4
91c20d594eSRichard Henderson #define TARGET_INSN_START_EXTRA_WORDS 2
926ebbf390Sj_mayer 
93ead9360eSths typedef struct CPUMIPSMVPContext CPUMIPSMVPContext;
94ead9360eSths struct CPUMIPSMVPContext {
95ead9360eSths     int32_t CP0_MVPControl;
96ead9360eSths #define CP0MVPCo_CPA	3
97ead9360eSths #define CP0MVPCo_STLB	2
98ead9360eSths #define CP0MVPCo_VPC	1
99ead9360eSths #define CP0MVPCo_EVP	0
100ead9360eSths     int32_t CP0_MVPConf0;
101ead9360eSths #define CP0MVPC0_M	31
102ead9360eSths #define CP0MVPC0_TLBS	29
103ead9360eSths #define CP0MVPC0_GS	28
104ead9360eSths #define CP0MVPC0_PCP	27
105ead9360eSths #define CP0MVPC0_PTLBE	16
106ead9360eSths #define CP0MVPC0_TCA	15
107ead9360eSths #define CP0MVPC0_PVPE	10
108ead9360eSths #define CP0MVPC0_PTC	0
109ead9360eSths     int32_t CP0_MVPConf1;
110ead9360eSths #define CP0MVPC1_CIM	31
111ead9360eSths #define CP0MVPC1_CIF	30
112ead9360eSths #define CP0MVPC1_PCX	20
113ead9360eSths #define CP0MVPC1_PCP2	10
114ead9360eSths #define CP0MVPC1_PCP1	0
115ead9360eSths };
116ead9360eSths 
117c227f099SAnthony Liguori typedef struct mips_def_t mips_def_t;
118ead9360eSths 
119ead9360eSths #define MIPS_SHADOW_SET_MAX 16
120ead9360eSths #define MIPS_TC_MAX 5
121f01be154Sths #define MIPS_FPU_MAX 1
122ead9360eSths #define MIPS_DSP_ACC 4
123e98c0d17SLeon Alrae #define MIPS_KSCRATCH_NUM 6
124f6d4dd81SYongbok Kim #define MIPS_MAAR_MAX 16 /* Must be an even number. */
125ead9360eSths 
126b5dc7732Sths typedef struct TCState TCState;
127b5dc7732Sths struct TCState {
128b5dc7732Sths     target_ulong gpr[32];
129b5dc7732Sths     target_ulong PC;
130b5dc7732Sths     target_ulong HI[MIPS_DSP_ACC];
131b5dc7732Sths     target_ulong LO[MIPS_DSP_ACC];
132b5dc7732Sths     target_ulong ACX[MIPS_DSP_ACC];
133b5dc7732Sths     target_ulong DSPControl;
134b5dc7732Sths     int32_t CP0_TCStatus;
135b5dc7732Sths #define CP0TCSt_TCU3	31
136b5dc7732Sths #define CP0TCSt_TCU2	30
137b5dc7732Sths #define CP0TCSt_TCU1	29
138b5dc7732Sths #define CP0TCSt_TCU0	28
139b5dc7732Sths #define CP0TCSt_TMX	27
140b5dc7732Sths #define CP0TCSt_RNST	23
141b5dc7732Sths #define CP0TCSt_TDS	21
142b5dc7732Sths #define CP0TCSt_DT	20
143b5dc7732Sths #define CP0TCSt_DA	15
144b5dc7732Sths #define CP0TCSt_A	13
145b5dc7732Sths #define CP0TCSt_TKSU	11
146b5dc7732Sths #define CP0TCSt_IXMT	10
147b5dc7732Sths #define CP0TCSt_TASID	0
148b5dc7732Sths     int32_t CP0_TCBind;
149b5dc7732Sths #define CP0TCBd_CurTC	21
150b5dc7732Sths #define CP0TCBd_TBE	17
151b5dc7732Sths #define CP0TCBd_CurVPE	0
152b5dc7732Sths     target_ulong CP0_TCHalt;
153b5dc7732Sths     target_ulong CP0_TCContext;
154b5dc7732Sths     target_ulong CP0_TCSchedule;
155b5dc7732Sths     target_ulong CP0_TCScheFBack;
156b5dc7732Sths     int32_t CP0_Debug_tcstatus;
157d279279eSPetar Jovanovic     target_ulong CP0_UserLocal;
158e97a391dSYongbok Kim 
159e97a391dSYongbok Kim     int32_t msacsr;
160e97a391dSYongbok Kim 
161e97a391dSYongbok Kim #define MSACSR_FS       24
162e97a391dSYongbok Kim #define MSACSR_FS_MASK  (1 << MSACSR_FS)
163e97a391dSYongbok Kim #define MSACSR_NX       18
164e97a391dSYongbok Kim #define MSACSR_NX_MASK  (1 << MSACSR_NX)
165e97a391dSYongbok Kim #define MSACSR_CEF      2
166e97a391dSYongbok Kim #define MSACSR_CEF_MASK (0xffff << MSACSR_CEF)
167e97a391dSYongbok Kim #define MSACSR_RM       0
168e97a391dSYongbok Kim #define MSACSR_RM_MASK  (0x3 << MSACSR_RM)
169e97a391dSYongbok Kim #define MSACSR_MASK     (MSACSR_RM_MASK | MSACSR_CEF_MASK | MSACSR_NX_MASK | \
170e97a391dSYongbok Kim         MSACSR_FS_MASK)
171e97a391dSYongbok Kim 
172e97a391dSYongbok Kim     float_status msa_fp_status;
173b5dc7732Sths };
174b5dc7732Sths 
175ead9360eSths typedef struct CPUMIPSState CPUMIPSState;
176ead9360eSths struct CPUMIPSState {
177b5dc7732Sths     TCState active_tc;
178f01be154Sths     CPUMIPSFPUContext active_fpu;
179b5dc7732Sths 
180ead9360eSths     uint32_t current_tc;
181f01be154Sths     uint32_t current_fpu;
182ead9360eSths 
183e034e2c3Sths     uint32_t SEGBITS;
1846d35524cSths     uint32_t PABITS;
185e117f526SLeon Alrae #if defined(TARGET_MIPS64)
186e117f526SLeon Alrae # define PABITS_BASE 36
187e117f526SLeon Alrae #else
188e117f526SLeon Alrae # define PABITS_BASE 32
189e117f526SLeon Alrae #endif
190b6d96bedSths     target_ulong SEGMask;
191284b731aSLeon Alrae     uint64_t PAMask;
192e117f526SLeon Alrae #define PAMASK_BASE ((1ULL << PABITS_BASE) - 1)
19329929e34Sths 
194e97a391dSYongbok Kim     int32_t msair;
195e97a391dSYongbok Kim #define MSAIR_ProcID    8
196e97a391dSYongbok Kim #define MSAIR_Rev       0
197e97a391dSYongbok Kim 
1989c2149c8Sths     int32_t CP0_Index;
199ead9360eSths     /* CP0_MVP* are per MVP registers. */
20001bc435bSYongbok Kim     int32_t CP0_VPControl;
20101bc435bSYongbok Kim #define CP0VPCtl_DIS    0
2029c2149c8Sths     int32_t CP0_Random;
203ead9360eSths     int32_t CP0_VPEControl;
204ead9360eSths #define CP0VPECo_YSI	21
205ead9360eSths #define CP0VPECo_GSI	20
206ead9360eSths #define CP0VPECo_EXCPT	16
207ead9360eSths #define CP0VPECo_TE	15
208ead9360eSths #define CP0VPECo_TargTC	0
209ead9360eSths     int32_t CP0_VPEConf0;
210ead9360eSths #define CP0VPEC0_M	31
211ead9360eSths #define CP0VPEC0_XTC	21
212ead9360eSths #define CP0VPEC0_TCS	19
213ead9360eSths #define CP0VPEC0_SCS	18
214ead9360eSths #define CP0VPEC0_DSC	17
215ead9360eSths #define CP0VPEC0_ICS	16
216ead9360eSths #define CP0VPEC0_MVP	1
217ead9360eSths #define CP0VPEC0_VPA	0
218ead9360eSths     int32_t CP0_VPEConf1;
219ead9360eSths #define CP0VPEC1_NCX	20
220ead9360eSths #define CP0VPEC1_NCP2	10
221ead9360eSths #define CP0VPEC1_NCP1	0
222ead9360eSths     target_ulong CP0_YQMask;
223ead9360eSths     target_ulong CP0_VPESchedule;
224ead9360eSths     target_ulong CP0_VPEScheFBack;
225ead9360eSths     int32_t CP0_VPEOpt;
226ead9360eSths #define CP0VPEOpt_IWX7	15
227ead9360eSths #define CP0VPEOpt_IWX6	14
228ead9360eSths #define CP0VPEOpt_IWX5	13
229ead9360eSths #define CP0VPEOpt_IWX4	12
230ead9360eSths #define CP0VPEOpt_IWX3	11
231ead9360eSths #define CP0VPEOpt_IWX2	10
232ead9360eSths #define CP0VPEOpt_IWX1	9
233ead9360eSths #define CP0VPEOpt_IWX0	8
234ead9360eSths #define CP0VPEOpt_DWX7	7
235ead9360eSths #define CP0VPEOpt_DWX6	6
236ead9360eSths #define CP0VPEOpt_DWX5	5
237ead9360eSths #define CP0VPEOpt_DWX4	4
238ead9360eSths #define CP0VPEOpt_DWX3	3
239ead9360eSths #define CP0VPEOpt_DWX2	2
240ead9360eSths #define CP0VPEOpt_DWX1	1
241ead9360eSths #define CP0VPEOpt_DWX0	0
242284b731aSLeon Alrae     uint64_t CP0_EntryLo0;
243284b731aSLeon Alrae     uint64_t CP0_EntryLo1;
2442fb58b73SLeon Alrae #if defined(TARGET_MIPS64)
2452fb58b73SLeon Alrae # define CP0EnLo_RI 63
2462fb58b73SLeon Alrae # define CP0EnLo_XI 62
2472fb58b73SLeon Alrae #else
2482fb58b73SLeon Alrae # define CP0EnLo_RI 31
2492fb58b73SLeon Alrae # define CP0EnLo_XI 30
2502fb58b73SLeon Alrae #endif
25101bc435bSYongbok Kim     int32_t CP0_GlobalNumber;
25201bc435bSYongbok Kim #define CP0GN_VPId 0
2539c2149c8Sths     target_ulong CP0_Context;
254e98c0d17SLeon Alrae     target_ulong CP0_KScratch[MIPS_KSCRATCH_NUM];
2559c2149c8Sths     int32_t CP0_PageMask;
2567207c7f9SLeon Alrae     int32_t CP0_PageGrain_rw_bitmask;
2579c2149c8Sths     int32_t CP0_PageGrain;
2587207c7f9SLeon Alrae #define CP0PG_RIE 31
2597207c7f9SLeon Alrae #define CP0PG_XIE 30
260e117f526SLeon Alrae #define CP0PG_ELPA 29
26192ceb440SLeon Alrae #define CP0PG_IEC 27
262cec56a73SJames Hogan     target_ulong CP0_SegCtl0;
263cec56a73SJames Hogan     target_ulong CP0_SegCtl1;
264cec56a73SJames Hogan     target_ulong CP0_SegCtl2;
265cec56a73SJames Hogan #define CP0SC_PA        9
266cec56a73SJames Hogan #define CP0SC_PA_MASK   (0x7FULL << CP0SC_PA)
267cec56a73SJames Hogan #define CP0SC_PA_1GMASK (0x7EULL << CP0SC_PA)
268cec56a73SJames Hogan #define CP0SC_AM        4
269cec56a73SJames Hogan #define CP0SC_AM_MASK   (0x7ULL << CP0SC_AM)
270cec56a73SJames Hogan #define CP0SC_AM_UK     0ULL
271cec56a73SJames Hogan #define CP0SC_AM_MK     1ULL
272cec56a73SJames Hogan #define CP0SC_AM_MSK    2ULL
273cec56a73SJames Hogan #define CP0SC_AM_MUSK   3ULL
274cec56a73SJames Hogan #define CP0SC_AM_MUSUK  4ULL
275cec56a73SJames Hogan #define CP0SC_AM_USK    5ULL
276cec56a73SJames Hogan #define CP0SC_AM_UUSK   7ULL
277cec56a73SJames Hogan #define CP0SC_EU        3
278cec56a73SJames Hogan #define CP0SC_EU_MASK   (1ULL << CP0SC_EU)
279cec56a73SJames Hogan #define CP0SC_C         0
280cec56a73SJames Hogan #define CP0SC_C_MASK    (0x7ULL << CP0SC_C)
281cec56a73SJames Hogan #define CP0SC_MASK      (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
282cec56a73SJames Hogan                          CP0SC_PA_MASK)
283cec56a73SJames Hogan #define CP0SC_1GMASK    (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
284cec56a73SJames Hogan                          CP0SC_PA_1GMASK)
285cec56a73SJames Hogan #define CP0SC0_MASK     (CP0SC_MASK | (CP0SC_MASK << 16))
286cec56a73SJames Hogan #define CP0SC1_XAM      59
287cec56a73SJames Hogan #define CP0SC1_XAM_MASK (0x7ULL << CP0SC1_XAM)
288cec56a73SJames Hogan #define CP0SC1_MASK     (CP0SC_MASK | (CP0SC_MASK << 16) | CP0SC1_XAM_MASK)
289cec56a73SJames Hogan #define CP0SC2_XR       56
290cec56a73SJames Hogan #define CP0SC2_XR_MASK  (0xFFULL << CP0SC2_XR)
291cec56a73SJames Hogan #define CP0SC2_MASK     (CP0SC_1GMASK | (CP0SC_1GMASK << 16) | CP0SC2_XR_MASK)
2929c2149c8Sths     int32_t CP0_Wired;
293ead9360eSths     int32_t CP0_SRSConf0_rw_bitmask;
294ead9360eSths     int32_t CP0_SRSConf0;
295ead9360eSths #define CP0SRSC0_M	31
296ead9360eSths #define CP0SRSC0_SRS3	20
297ead9360eSths #define CP0SRSC0_SRS2	10
298ead9360eSths #define CP0SRSC0_SRS1	0
299ead9360eSths     int32_t CP0_SRSConf1_rw_bitmask;
300ead9360eSths     int32_t CP0_SRSConf1;
301ead9360eSths #define CP0SRSC1_M	31
302ead9360eSths #define CP0SRSC1_SRS6	20
303ead9360eSths #define CP0SRSC1_SRS5	10
304ead9360eSths #define CP0SRSC1_SRS4	0
305ead9360eSths     int32_t CP0_SRSConf2_rw_bitmask;
306ead9360eSths     int32_t CP0_SRSConf2;
307ead9360eSths #define CP0SRSC2_M	31
308ead9360eSths #define CP0SRSC2_SRS9	20
309ead9360eSths #define CP0SRSC2_SRS8	10
310ead9360eSths #define CP0SRSC2_SRS7	0
311ead9360eSths     int32_t CP0_SRSConf3_rw_bitmask;
312ead9360eSths     int32_t CP0_SRSConf3;
313ead9360eSths #define CP0SRSC3_M	31
314ead9360eSths #define CP0SRSC3_SRS12	20
315ead9360eSths #define CP0SRSC3_SRS11	10
316ead9360eSths #define CP0SRSC3_SRS10	0
317ead9360eSths     int32_t CP0_SRSConf4_rw_bitmask;
318ead9360eSths     int32_t CP0_SRSConf4;
319ead9360eSths #define CP0SRSC4_SRS15	20
320ead9360eSths #define CP0SRSC4_SRS14	10
321ead9360eSths #define CP0SRSC4_SRS13	0
3229c2149c8Sths     int32_t CP0_HWREna;
323c570fd16Sths     target_ulong CP0_BadVAddr;
324aea14095SLeon Alrae     uint32_t CP0_BadInstr;
325aea14095SLeon Alrae     uint32_t CP0_BadInstrP;
32625beba9bSStefan Markovic     uint32_t CP0_BadInstrX;
3279c2149c8Sths     int32_t CP0_Count;
3289c2149c8Sths     target_ulong CP0_EntryHi;
3299456c2fbSLeon Alrae #define CP0EnHi_EHINV 10
3306ec98bd7SPaul Burton     target_ulong CP0_EntryHi_ASID_mask;
3319c2149c8Sths     int32_t CP0_Compare;
3329c2149c8Sths     int32_t CP0_Status;
3336af0bf9cSbellard #define CP0St_CU3   31
3346af0bf9cSbellard #define CP0St_CU2   30
3356af0bf9cSbellard #define CP0St_CU1   29
3366af0bf9cSbellard #define CP0St_CU0   28
3376af0bf9cSbellard #define CP0St_RP    27
3386ea83fedSbellard #define CP0St_FR    26
3396af0bf9cSbellard #define CP0St_RE    25
3407a387fffSths #define CP0St_MX    24
3417a387fffSths #define CP0St_PX    23
3426af0bf9cSbellard #define CP0St_BEV   22
3436af0bf9cSbellard #define CP0St_TS    21
3446af0bf9cSbellard #define CP0St_SR    20
3456af0bf9cSbellard #define CP0St_NMI   19
3466af0bf9cSbellard #define CP0St_IM    8
3477a387fffSths #define CP0St_KX    7
3487a387fffSths #define CP0St_SX    6
3497a387fffSths #define CP0St_UX    5
350623a930eSths #define CP0St_KSU   3
3516af0bf9cSbellard #define CP0St_ERL   2
3526af0bf9cSbellard #define CP0St_EXL   1
3536af0bf9cSbellard #define CP0St_IE    0
3549c2149c8Sths     int32_t CP0_IntCtl;
355ead9360eSths #define CP0IntCtl_IPTI 29
35688991299SDongxue Zhang #define CP0IntCtl_IPPCI 26
357ead9360eSths #define CP0IntCtl_VS 5
3589c2149c8Sths     int32_t CP0_SRSCtl;
359ead9360eSths #define CP0SRSCtl_HSS 26
360ead9360eSths #define CP0SRSCtl_EICSS 18
361ead9360eSths #define CP0SRSCtl_ESS 12
362ead9360eSths #define CP0SRSCtl_PSS 6
363ead9360eSths #define CP0SRSCtl_CSS 0
3649c2149c8Sths     int32_t CP0_SRSMap;
365ead9360eSths #define CP0SRSMap_SSV7 28
366ead9360eSths #define CP0SRSMap_SSV6 24
367ead9360eSths #define CP0SRSMap_SSV5 20
368ead9360eSths #define CP0SRSMap_SSV4 16
369ead9360eSths #define CP0SRSMap_SSV3 12
370ead9360eSths #define CP0SRSMap_SSV2 8
371ead9360eSths #define CP0SRSMap_SSV1 4
372ead9360eSths #define CP0SRSMap_SSV0 0
3739c2149c8Sths     int32_t CP0_Cause;
3747a387fffSths #define CP0Ca_BD   31
3757a387fffSths #define CP0Ca_TI   30
3767a387fffSths #define CP0Ca_CE   28
3777a387fffSths #define CP0Ca_DC   27
3787a387fffSths #define CP0Ca_PCI  26
3796af0bf9cSbellard #define CP0Ca_IV   23
3807a387fffSths #define CP0Ca_WP   22
3817a387fffSths #define CP0Ca_IP    8
3824de9b249Sths #define CP0Ca_IP_mask 0x0000FF00
3837a387fffSths #define CP0Ca_EC    2
384c570fd16Sths     target_ulong CP0_EPC;
3859c2149c8Sths     int32_t CP0_PRid;
38674dbf824SJames Hogan     target_ulong CP0_EBase;
38774dbf824SJames Hogan     target_ulong CP0_EBaseWG_rw_bitmask;
38874dbf824SJames Hogan #define CP0EBase_WG 11
389c870e3f5SYongbok Kim     target_ulong CP0_CMGCRBase;
3909c2149c8Sths     int32_t CP0_Config0;
3916af0bf9cSbellard #define CP0C0_M    31
3920413d7a5SAleksandar Markovic #define CP0C0_K23  28    /* 30..28 */
3930413d7a5SAleksandar Markovic #define CP0C0_KU   25    /* 27..25 */
3946af0bf9cSbellard #define CP0C0_MDU  20
395aff2bc6dSYongbok Kim #define CP0C0_MM   18
3966af0bf9cSbellard #define CP0C0_BM   16
3970413d7a5SAleksandar Markovic #define CP0C0_Impl 16    /* 24..16 */
3986af0bf9cSbellard #define CP0C0_BE   15
3990413d7a5SAleksandar Markovic #define CP0C0_AT   13    /* 14..13 */
4000413d7a5SAleksandar Markovic #define CP0C0_AR   10    /* 12..10 */
4010413d7a5SAleksandar Markovic #define CP0C0_MT   7     /*  9..7  */
4027a387fffSths #define CP0C0_VI   3
4030413d7a5SAleksandar Markovic #define CP0C0_K0   0     /*  2..0  */
4049c2149c8Sths     int32_t CP0_Config1;
4057a387fffSths #define CP0C1_M    31
4060413d7a5SAleksandar Markovic #define CP0C1_MMU  25    /* 30..25 */
4070413d7a5SAleksandar Markovic #define CP0C1_IS   22    /* 24..22 */
4080413d7a5SAleksandar Markovic #define CP0C1_IL   19    /* 21..19 */
4090413d7a5SAleksandar Markovic #define CP0C1_IA   16    /* 18..16 */
4100413d7a5SAleksandar Markovic #define CP0C1_DS   13    /* 15..13 */
4110413d7a5SAleksandar Markovic #define CP0C1_DL   10    /* 12..10 */
4120413d7a5SAleksandar Markovic #define CP0C1_DA   7     /*  9..7  */
4137a387fffSths #define CP0C1_C2   6
4147a387fffSths #define CP0C1_MD   5
4156af0bf9cSbellard #define CP0C1_PC   4
4166af0bf9cSbellard #define CP0C1_WR   3
4176af0bf9cSbellard #define CP0C1_CA   2
4186af0bf9cSbellard #define CP0C1_EP   1
4196af0bf9cSbellard #define CP0C1_FP   0
4209c2149c8Sths     int32_t CP0_Config2;
4217a387fffSths #define CP0C2_M    31
4220413d7a5SAleksandar Markovic #define CP0C2_TU   28    /* 30..28 */
4230413d7a5SAleksandar Markovic #define CP0C2_TS   24    /* 27..24 */
4240413d7a5SAleksandar Markovic #define CP0C2_TL   20    /* 23..20 */
4250413d7a5SAleksandar Markovic #define CP0C2_TA   16    /* 19..16 */
4260413d7a5SAleksandar Markovic #define CP0C2_SU   12    /* 15..12 */
4270413d7a5SAleksandar Markovic #define CP0C2_SS   8     /* 11..8  */
4280413d7a5SAleksandar Markovic #define CP0C2_SL   4     /*  7..4  */
4290413d7a5SAleksandar Markovic #define CP0C2_SA   0     /*  3..0  */
4309c2149c8Sths     int32_t CP0_Config3;
4317a387fffSths #define CP0C3_M            31
43270409e67SMaciej W. Rozycki #define CP0C3_BPG          30
433c870e3f5SYongbok Kim #define CP0C3_CMGCR        29
434e97a391dSYongbok Kim #define CP0C3_MSAP         28
435aea14095SLeon Alrae #define CP0C3_BP           27
436aea14095SLeon Alrae #define CP0C3_BI           26
43774dbf824SJames Hogan #define CP0C3_SC           25
4380413d7a5SAleksandar Markovic #define CP0C3_PW           24
4390413d7a5SAleksandar Markovic #define CP0C3_VZ           23
4400413d7a5SAleksandar Markovic #define CP0C3_IPLV         21    /* 22..21 */
4410413d7a5SAleksandar Markovic #define CP0C3_MMAR         18    /* 20..18 */
44270409e67SMaciej W. Rozycki #define CP0C3_MCU          17
443bbfa8f72SNathan Froyd #define CP0C3_ISA_ON_EXC   16
4440413d7a5SAleksandar Markovic #define CP0C3_ISA          14    /* 15..14 */
445d279279eSPetar Jovanovic #define CP0C3_ULRI         13
4467207c7f9SLeon Alrae #define CP0C3_RXI          12
44770409e67SMaciej W. Rozycki #define CP0C3_DSP2P        11
4487a387fffSths #define CP0C3_DSPP         10
4490413d7a5SAleksandar Markovic #define CP0C3_CTXTC        9
4500413d7a5SAleksandar Markovic #define CP0C3_ITL          8
4517a387fffSths #define CP0C3_LPA          7
4527a387fffSths #define CP0C3_VEIC         6
4537a387fffSths #define CP0C3_VInt         5
4547a387fffSths #define CP0C3_SP           4
45570409e67SMaciej W. Rozycki #define CP0C3_CDMM         3
4567a387fffSths #define CP0C3_MT           2
4577a387fffSths #define CP0C3_SM           1
4587a387fffSths #define CP0C3_TL           0
4598280b12cSMaciej W. Rozycki     int32_t CP0_Config4;
4608280b12cSMaciej W. Rozycki     int32_t CP0_Config4_rw_bitmask;
461b4160af1SPetar Jovanovic #define CP0C4_M            31
4620413d7a5SAleksandar Markovic #define CP0C4_IE           29    /* 30..29 */
463a0c80608SPaul Burton #define CP0C4_AE           28
4640413d7a5SAleksandar Markovic #define CP0C4_VTLBSizeExt  24    /* 27..24 */
465e98c0d17SLeon Alrae #define CP0C4_KScrExist    16
46670409e67SMaciej W. Rozycki #define CP0C4_MMUExtDef    14
4670413d7a5SAleksandar Markovic #define CP0C4_FTLBPageSize 8     /* 12..8  */
4680413d7a5SAleksandar Markovic /* bit layout if MMUExtDef=1 */
4690413d7a5SAleksandar Markovic #define CP0C4_MMUSizeExt   0     /*  7..0  */
4700413d7a5SAleksandar Markovic /* bit layout if MMUExtDef=2 */
4710413d7a5SAleksandar Markovic #define CP0C4_FTLBWays     4     /*  7..4  */
4720413d7a5SAleksandar Markovic #define CP0C4_FTLBSets     0     /*  3..0  */
4738280b12cSMaciej W. Rozycki     int32_t CP0_Config5;
4748280b12cSMaciej W. Rozycki     int32_t CP0_Config5_rw_bitmask;
475b4dd99a3SPetar Jovanovic #define CP0C5_M            31
476b4dd99a3SPetar Jovanovic #define CP0C5_K            30
477b4dd99a3SPetar Jovanovic #define CP0C5_CV           29
478b4dd99a3SPetar Jovanovic #define CP0C5_EVA          28
479b4dd99a3SPetar Jovanovic #define CP0C5_MSAEn        27
4800413d7a5SAleksandar Markovic #define CP0C5_PMJ          23    /* 25..23 */
4810413d7a5SAleksandar Markovic #define CP0C5_WR2          22
4820413d7a5SAleksandar Markovic #define CP0C5_NMS          21
4830413d7a5SAleksandar Markovic #define CP0C5_ULS          20
4840413d7a5SAleksandar Markovic #define CP0C5_XPA          19
4850413d7a5SAleksandar Markovic #define CP0C5_CRCP         18
4860413d7a5SAleksandar Markovic #define CP0C5_MI           17
4870413d7a5SAleksandar Markovic #define CP0C5_GI           15    /* 16..15 */
4880413d7a5SAleksandar Markovic #define CP0C5_CA2          14
489b00c7218SYongbok Kim #define CP0C5_XNP          13
4900413d7a5SAleksandar Markovic #define CP0C5_DEC          11
4910413d7a5SAleksandar Markovic #define CP0C5_L2C          10
4927c979afdSLeon Alrae #define CP0C5_UFE          9
4937c979afdSLeon Alrae #define CP0C5_FRE          8
49401bc435bSYongbok Kim #define CP0C5_VP           7
495faf1f68bSLeon Alrae #define CP0C5_SBRI         6
4965204ea79SLeon Alrae #define CP0C5_MVH          5
497ce9782f4SLeon Alrae #define CP0C5_LLB          4
498f6d4dd81SYongbok Kim #define CP0C5_MRP          3
499b4dd99a3SPetar Jovanovic #define CP0C5_UFR          2
500b4dd99a3SPetar Jovanovic #define CP0C5_NFExists     0
501e397ee33Sths     int32_t CP0_Config6;
502e397ee33Sths     int32_t CP0_Config7;
503f6d4dd81SYongbok Kim     uint64_t CP0_MAAR[MIPS_MAAR_MAX];
504f6d4dd81SYongbok Kim     int32_t CP0_MAARI;
505ead9360eSths     /* XXX: Maybe make LLAddr per-TC? */
506284b731aSLeon Alrae     uint64_t lladdr;
507590bc601SPaul Brook     target_ulong llval;
508590bc601SPaul Brook     target_ulong llnewval;
509*0b16dcd1SAleksandar Rikalo     uint64_t llval_wp;
510*0b16dcd1SAleksandar Rikalo     uint32_t llnewval_wp;
511590bc601SPaul Brook     target_ulong llreg;
512284b731aSLeon Alrae     uint64_t CP0_LLAddr_rw_bitmask;
5132a6e32ddSAurelien Jarno     int CP0_LLAddr_shift;
514fd88b6abSths     target_ulong CP0_WatchLo[8];
515fd88b6abSths     int32_t CP0_WatchHi[8];
5166ec98bd7SPaul Burton #define CP0WH_ASID 16
5179c2149c8Sths     target_ulong CP0_XContext;
5189c2149c8Sths     int32_t CP0_Framemask;
5199c2149c8Sths     int32_t CP0_Debug;
520ead9360eSths #define CP0DB_DBD  31
5216af0bf9cSbellard #define CP0DB_DM   30
5226af0bf9cSbellard #define CP0DB_LSNM 28
5236af0bf9cSbellard #define CP0DB_Doze 27
5246af0bf9cSbellard #define CP0DB_Halt 26
5256af0bf9cSbellard #define CP0DB_CNT  25
5266af0bf9cSbellard #define CP0DB_IBEP 24
5276af0bf9cSbellard #define CP0DB_DBEP 21
5286af0bf9cSbellard #define CP0DB_IEXI 20
5296af0bf9cSbellard #define CP0DB_VER  15
5306af0bf9cSbellard #define CP0DB_DEC  10
5316af0bf9cSbellard #define CP0DB_SSt  8
5326af0bf9cSbellard #define CP0DB_DINT 5
5336af0bf9cSbellard #define CP0DB_DIB  4
5346af0bf9cSbellard #define CP0DB_DDBS 3
5356af0bf9cSbellard #define CP0DB_DDBL 2
5366af0bf9cSbellard #define CP0DB_DBp  1
5376af0bf9cSbellard #define CP0DB_DSS  0
538c570fd16Sths     target_ulong CP0_DEPC;
5399c2149c8Sths     int32_t CP0_Performance0;
5400d74a222SLeon Alrae     int32_t CP0_ErrCtl;
5410d74a222SLeon Alrae #define CP0EC_WST 29
5420d74a222SLeon Alrae #define CP0EC_SPR 28
5430d74a222SLeon Alrae #define CP0EC_ITC 26
544284b731aSLeon Alrae     uint64_t CP0_TagLo;
5459c2149c8Sths     int32_t CP0_DataLo;
5469c2149c8Sths     int32_t CP0_TagHi;
5479c2149c8Sths     int32_t CP0_DataHi;
548c570fd16Sths     target_ulong CP0_ErrorEPC;
5499c2149c8Sths     int32_t CP0_DESAVE;
550b5dc7732Sths     /* We waste some space so we can handle shadow registers like TCs. */
551b5dc7732Sths     TCState tcs[MIPS_SHADOW_SET_MAX];
552f01be154Sths     CPUMIPSFPUContext fpus[MIPS_FPU_MAX];
5535cbdb3a3SStefan Weil     /* QEMU */
5546af0bf9cSbellard     int error_code;
555aea14095SLeon Alrae #define EXCP_TLB_NOMATCH   0x1
556aea14095SLeon Alrae #define EXCP_INST_NOTAVAIL 0x2 /* No valid instruction word for BadInstr */
5576af0bf9cSbellard     uint32_t hflags;    /* CPU State */
5586af0bf9cSbellard     /* TMASK defines different execution modes */
55942c86612SJames Hogan #define MIPS_HFLAG_TMASK  0x1F5807FF
56079ef2c4cSNathan Froyd #define MIPS_HFLAG_MODE   0x00007 /* execution modes                    */
561623a930eSths     /* The KSU flags must be the lowest bits in hflags. The flag order
562623a930eSths        must be the same as defined for CP0 Status. This allows to use
563623a930eSths        the bits as the value of mmu_idx. */
56479ef2c4cSNathan Froyd #define MIPS_HFLAG_KSU    0x00003 /* kernel/supervisor/user mode mask   */
56579ef2c4cSNathan Froyd #define MIPS_HFLAG_UM     0x00002 /* user mode flag                     */
56679ef2c4cSNathan Froyd #define MIPS_HFLAG_SM     0x00001 /* supervisor mode flag               */
56779ef2c4cSNathan Froyd #define MIPS_HFLAG_KM     0x00000 /* kernel mode flag                   */
56879ef2c4cSNathan Froyd #define MIPS_HFLAG_DM     0x00004 /* Debug mode                         */
56979ef2c4cSNathan Froyd #define MIPS_HFLAG_64     0x00008 /* 64-bit instructions enabled        */
57079ef2c4cSNathan Froyd #define MIPS_HFLAG_CP0    0x00010 /* CP0 enabled                        */
57179ef2c4cSNathan Froyd #define MIPS_HFLAG_FPU    0x00020 /* FPU enabled                        */
57279ef2c4cSNathan Froyd #define MIPS_HFLAG_F64    0x00040 /* 64-bit FPU enabled                 */
573b8aa4598Sths     /* True if the MIPS IV COP1X instructions can be used.  This also
574b8aa4598Sths        controls the non-COP1X instructions RECIP.S, RECIP.D, RSQRT.S
575b8aa4598Sths        and RSQRT.D.  */
57679ef2c4cSNathan Froyd #define MIPS_HFLAG_COP1X  0x00080 /* COP1X instructions enabled         */
57779ef2c4cSNathan Froyd #define MIPS_HFLAG_RE     0x00100 /* Reversed endianness                */
57801f72885SLeon Alrae #define MIPS_HFLAG_AWRAP  0x00200 /* 32-bit compatibility address wrapping */
57979ef2c4cSNathan Froyd #define MIPS_HFLAG_M16    0x00400 /* MIPS16 mode flag                   */
58079ef2c4cSNathan Froyd #define MIPS_HFLAG_M16_SHIFT 10
5814ad40f36Sbellard     /* If translation is interrupted between the branch instruction and
5824ad40f36Sbellard      * the delay slot, record what type of branch it is so that we can
5834ad40f36Sbellard      * resume translation properly.  It might be possible to reduce
5844ad40f36Sbellard      * this from three bits to two.  */
585339cd2a8SLeon Alrae #define MIPS_HFLAG_BMASK_BASE  0x803800
58679ef2c4cSNathan Froyd #define MIPS_HFLAG_B      0x00800 /* Unconditional branch               */
58779ef2c4cSNathan Froyd #define MIPS_HFLAG_BC     0x01000 /* Conditional branch                 */
58879ef2c4cSNathan Froyd #define MIPS_HFLAG_BL     0x01800 /* Likely branch                      */
58979ef2c4cSNathan Froyd #define MIPS_HFLAG_BR     0x02000 /* branch to register (can't link TB) */
59079ef2c4cSNathan Froyd     /* Extra flags about the current pending branch.  */
591b231c103SYongbok Kim #define MIPS_HFLAG_BMASK_EXT 0x7C000
59279ef2c4cSNathan Froyd #define MIPS_HFLAG_B16    0x04000 /* branch instruction was 16 bits     */
59379ef2c4cSNathan Froyd #define MIPS_HFLAG_BDS16  0x08000 /* branch requires 16-bit delay slot  */
59479ef2c4cSNathan Froyd #define MIPS_HFLAG_BDS32  0x10000 /* branch requires 32-bit delay slot  */
595b231c103SYongbok Kim #define MIPS_HFLAG_BDS_STRICT  0x20000 /* Strict delay slot size */
596b231c103SYongbok Kim #define MIPS_HFLAG_BX     0x40000 /* branch exchanges execution mode    */
59779ef2c4cSNathan Froyd #define MIPS_HFLAG_BMASK  (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT)
598853c3240SJia Liu     /* MIPS DSP resources access. */
599b231c103SYongbok Kim #define MIPS_HFLAG_DSP   0x080000  /* Enable access to MIPS DSP resources. */
600b231c103SYongbok Kim #define MIPS_HFLAG_DSPR2 0x100000  /* Enable access to MIPS DSPR2 resources. */
601d279279eSPetar Jovanovic     /* Extra flag about HWREna register. */
602b231c103SYongbok Kim #define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */
603faf1f68bSLeon Alrae #define MIPS_HFLAG_SBRI  0x400000 /* R6 SDBBP causes RI excpt. in user mode */
604339cd2a8SLeon Alrae #define MIPS_HFLAG_FBNSLOT 0x800000 /* Forbidden slot                   */
605e97a391dSYongbok Kim #define MIPS_HFLAG_MSA   0x1000000
6067c979afdSLeon Alrae #define MIPS_HFLAG_FRE   0x2000000 /* FRE enabled */
607e117f526SLeon Alrae #define MIPS_HFLAG_ELPA  0x4000000
6080d74a222SLeon Alrae #define MIPS_HFLAG_ITC_CACHE  0x8000000 /* CACHE instr. operates on ITC tag */
60942c86612SJames Hogan #define MIPS_HFLAG_ERL   0x10000000 /* error level flag */
6106af0bf9cSbellard     target_ulong btarget;        /* Jump / branch target               */
6111ba74fb8Saurel32     target_ulong bcond;          /* Branch condition (if needed)       */
612a316d335Sbellard 
6137a387fffSths     int SYNCI_Step; /* Address step size for SYNCI */
6147a387fffSths     int CCRes; /* Cycle count resolution/divisor */
615ead9360eSths     uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */
616ead9360eSths     uint32_t CP0_TCStatus_rw_bitmask; /* Read/write bits in CP0_TCStatus */
617e189e748Sths     int insn_flags; /* Supported instruction set */
6187a387fffSths 
6191f5c00cfSAlex Bennée     /* Fields up to this point are cleared by a CPU reset */
6201f5c00cfSAlex Bennée     struct {} end_reset_fields;
6211f5c00cfSAlex Bennée 
622a316d335Sbellard     CPU_COMMON
6236ae81775Sths 
624f0c3c505SAndreas Färber     /* Fields from here on are preserved across CPU reset. */
62551cc2e78SBlue Swirl     CPUMIPSMVPContext *mvp;
6263c7b48b7SPaul Brook #if !defined(CONFIG_USER_ONLY)
62751cc2e78SBlue Swirl     CPUMIPSTLBContext *tlb;
6283c7b48b7SPaul Brook #endif
62951cc2e78SBlue Swirl 
630c227f099SAnthony Liguori     const mips_def_t *cpu_model;
63133ac7f16Sths     void *irq[8];
6321246b259SStefan Weil     QEMUTimer *timer; /* Internal timer */
63334fa7e83SLeon Alrae     MemoryRegion *itc_tag; /* ITC Configuration Tags */
63489777fd1SLeon Alrae     target_ulong exception_base; /* ExceptionBase input to the core */
6356af0bf9cSbellard };
6366af0bf9cSbellard 
637416bf936SPaolo Bonzini /**
638416bf936SPaolo Bonzini  * MIPSCPU:
639416bf936SPaolo Bonzini  * @env: #CPUMIPSState
640416bf936SPaolo Bonzini  *
641416bf936SPaolo Bonzini  * A MIPS CPU.
642416bf936SPaolo Bonzini  */
643416bf936SPaolo Bonzini struct MIPSCPU {
644416bf936SPaolo Bonzini     /*< private >*/
645416bf936SPaolo Bonzini     CPUState parent_obj;
646416bf936SPaolo Bonzini     /*< public >*/
647416bf936SPaolo Bonzini 
648416bf936SPaolo Bonzini     CPUMIPSState env;
649416bf936SPaolo Bonzini };
650416bf936SPaolo Bonzini 
651416bf936SPaolo Bonzini static inline MIPSCPU *mips_env_get_cpu(CPUMIPSState *env)
652416bf936SPaolo Bonzini {
653416bf936SPaolo Bonzini     return container_of(env, MIPSCPU, env);
654416bf936SPaolo Bonzini }
655416bf936SPaolo Bonzini 
656416bf936SPaolo Bonzini #define ENV_GET_CPU(e) CPU(mips_env_get_cpu(e))
657416bf936SPaolo Bonzini 
658416bf936SPaolo Bonzini #define ENV_OFFSET offsetof(MIPSCPU, env)
659416bf936SPaolo Bonzini 
6609a78eeadSStefan Weil void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf);
661647de6caSths 
6629467d44cSths #define cpu_signal_handler cpu_mips_signal_handler
663c732abe2Sj_mayer #define cpu_list mips_cpu_list
6649467d44cSths 
665084d0497SRichard Henderson extern void cpu_wrdsp(uint32_t rs, uint32_t mask_num, CPUMIPSState *env);
666084d0497SRichard Henderson extern uint32_t cpu_rddsp(uint32_t mask_num, CPUMIPSState *env);
667084d0497SRichard Henderson 
668623a930eSths /* MMU modes definitions. We carefully match the indices with our
669623a930eSths    hflags layout. */
6706ebbf390Sj_mayer #define MMU_MODE0_SUFFIX _kernel
671623a930eSths #define MMU_MODE1_SUFFIX _super
672623a930eSths #define MMU_MODE2_SUFFIX _user
67342c86612SJames Hogan #define MMU_MODE3_SUFFIX _error
674623a930eSths #define MMU_USER_IDX 2
675b0fc6003SJames Hogan 
676b0fc6003SJames Hogan static inline int hflags_mmu_index(uint32_t hflags)
677b0fc6003SJames Hogan {
67842c86612SJames Hogan     if (hflags & MIPS_HFLAG_ERL) {
67942c86612SJames Hogan         return 3; /* ERL */
68042c86612SJames Hogan     } else {
681b0fc6003SJames Hogan         return hflags & MIPS_HFLAG_KSU;
682b0fc6003SJames Hogan     }
68342c86612SJames Hogan }
684b0fc6003SJames Hogan 
68597ed5ccdSBenjamin Herrenschmidt static inline int cpu_mmu_index (CPUMIPSState *env, bool ifetch)
6866ebbf390Sj_mayer {
687b0fc6003SJames Hogan     return hflags_mmu_index(env->hflags);
6886ebbf390Sj_mayer }
6896ebbf390Sj_mayer 
690022c62cbSPaolo Bonzini #include "exec/cpu-all.h"
6916af0bf9cSbellard 
6926af0bf9cSbellard /* Memory access type :
6936af0bf9cSbellard  * may be needed for precise access rights control and precise exceptions.
6946af0bf9cSbellard  */
6956af0bf9cSbellard enum {
6966af0bf9cSbellard     /* 1 bit to define user level / supervisor access */
6976af0bf9cSbellard     ACCESS_USER  = 0x00,
6986af0bf9cSbellard     ACCESS_SUPER = 0x01,
6996af0bf9cSbellard     /* 1 bit to indicate direction */
7006af0bf9cSbellard     ACCESS_STORE = 0x02,
7016af0bf9cSbellard     /* Type of instruction that generated the access */
7026af0bf9cSbellard     ACCESS_CODE  = 0x10, /* Code fetch access                */
7036af0bf9cSbellard     ACCESS_INT   = 0x20, /* Integer load/store access        */
7046af0bf9cSbellard     ACCESS_FLOAT = 0x30, /* floating point load/store access */
7056af0bf9cSbellard };
7066af0bf9cSbellard 
7076af0bf9cSbellard /* Exceptions */
7086af0bf9cSbellard enum {
7096af0bf9cSbellard     EXCP_NONE          = -1,
7106af0bf9cSbellard     EXCP_RESET         = 0,
7116af0bf9cSbellard     EXCP_SRESET,
7126af0bf9cSbellard     EXCP_DSS,
7136af0bf9cSbellard     EXCP_DINT,
71414e51cc7Sths     EXCP_DDBL,
71514e51cc7Sths     EXCP_DDBS,
7166af0bf9cSbellard     EXCP_NMI,
7176af0bf9cSbellard     EXCP_MCHECK,
71814e51cc7Sths     EXCP_EXT_INTERRUPT, /* 8 */
7196af0bf9cSbellard     EXCP_DFWATCH,
72014e51cc7Sths     EXCP_DIB,
7216af0bf9cSbellard     EXCP_IWATCH,
7226af0bf9cSbellard     EXCP_AdEL,
7236af0bf9cSbellard     EXCP_AdES,
7246af0bf9cSbellard     EXCP_TLBF,
7256af0bf9cSbellard     EXCP_IBE,
72614e51cc7Sths     EXCP_DBp, /* 16 */
7276af0bf9cSbellard     EXCP_SYSCALL,
72814e51cc7Sths     EXCP_BREAK,
7294ad40f36Sbellard     EXCP_CpU,
7306af0bf9cSbellard     EXCP_RI,
7316af0bf9cSbellard     EXCP_OVERFLOW,
7326af0bf9cSbellard     EXCP_TRAP,
7335a5012ecSths     EXCP_FPE,
73414e51cc7Sths     EXCP_DWATCH, /* 24 */
7356af0bf9cSbellard     EXCP_LTLBL,
7366af0bf9cSbellard     EXCP_TLBL,
7376af0bf9cSbellard     EXCP_TLBS,
7386af0bf9cSbellard     EXCP_DBE,
739ead9360eSths     EXCP_THREAD,
74014e51cc7Sths     EXCP_MDMX,
74114e51cc7Sths     EXCP_C2E,
74214e51cc7Sths     EXCP_CACHE, /* 32 */
743853c3240SJia Liu     EXCP_DSPDIS,
744e97a391dSYongbok Kim     EXCP_MSADIS,
745e97a391dSYongbok Kim     EXCP_MSAFPE,
74692ceb440SLeon Alrae     EXCP_TLBXI,
74792ceb440SLeon Alrae     EXCP_TLBRI,
74814e51cc7Sths 
74992ceb440SLeon Alrae     EXCP_LAST = EXCP_TLBRI,
7506af0bf9cSbellard };
751590bc601SPaul Brook /* Dummy exception for conditional stores.  */
752590bc601SPaul Brook #define EXCP_SC 0x100
7536af0bf9cSbellard 
754f249412cSEdgar E. Iglesias /*
75526aa3d9aSPhilippe Mathieu-Daudé  * This is an internally generated WAKE request line.
756f249412cSEdgar E. Iglesias  * It is driven by the CPU itself. Raised when the MT
757f249412cSEdgar E. Iglesias  * block wants to wake a VPE from an inactive state and
758f249412cSEdgar E. Iglesias  * cleared when VPE goes from active to inactive.
759f249412cSEdgar E. Iglesias  */
760f249412cSEdgar E. Iglesias #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0
761f249412cSEdgar E. Iglesias 
762388bb21aSths int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
7636af0bf9cSbellard 
764a7519f2bSIgor Mammedov #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
765a7519f2bSIgor Mammedov #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
7660dacec87SIgor Mammedov #define CPU_RESOLVING_TYPE TYPE_MIPS_CPU
767a7519f2bSIgor Mammedov 
768a7519f2bSIgor Mammedov bool cpu_supports_cps_smp(const char *cpu_type);
769a7519f2bSIgor Mammedov bool cpu_supports_isa(const char *cpu_type, unsigned int isa);
77089777fd1SLeon Alrae void cpu_set_exception_base(int vp_index, target_ulong address);
77130bf942dSAndreas Färber 
7725dc5d9f0SAurelien Jarno /* mips_int.c */
7737db13faeSAndreas Färber void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level);
7745dc5d9f0SAurelien Jarno 
775f9480ffcSths /* helper.c */
7761239b472SKwok Cheung Yeung target_ulong exception_resume_pc (CPUMIPSState *env);
777f9480ffcSths 
778599bc5e8SAleksandar Markovic static inline void restore_snan_bit_mode(CPUMIPSState *env)
779599bc5e8SAleksandar Markovic {
780599bc5e8SAleksandar Markovic     set_snan_bit_is_one((env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) == 0,
781599bc5e8SAleksandar Markovic                         &env->active_fpu.fp_status);
782599bc5e8SAleksandar Markovic }
783599bc5e8SAleksandar Markovic 
7847db13faeSAndreas Färber static inline void cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc,
78589fee74aSEmilio G. Cota                                         target_ulong *cs_base, uint32_t *flags)
7866b917547Saliguori {
7876b917547Saliguori     *pc = env->active_tc.PC;
7886b917547Saliguori     *cs_base = 0;
789d279279eSPetar Jovanovic     *flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK |
790d279279eSPetar Jovanovic                             MIPS_HFLAG_HWRENA_ULR);
7916b917547Saliguori }
7926b917547Saliguori 
79307f5a258SMarkus Armbruster #endif /* MIPS_CPU_H */
794