]> git.proxmox.com Git - mirror_qemu.git/blame - target/mips/cpu.h
target/mips: Clean up handling of CP0 register 5
[mirror_qemu.git] / target / mips / cpu.h
CommitLineData
07f5a258
MA
1#ifndef MIPS_CPU_H
2#define MIPS_CPU_H
6af0bf9c 3
416bf936 4#include "cpu-qom.h"
022c62cb 5#include "exec/cpu-defs.h"
502700d0 6#include "fpu/softfloat-types.h"
74433bf0 7#include "mips-defs.h"
6af0bf9c 8
0454728c
AM
9#define TCG_GUEST_DEFAULT_MO (0)
10
ead9360e 11typedef struct CPUMIPSTLBContext CPUMIPSTLBContext;
51b2772f 12
e97a391d
YK
13/* MSA Context */
14#define MSA_WRLEN (128)
15
e97a391d
YK
16typedef union wr_t wr_t;
17union wr_t {
8ebf2e1a
JI
18 int8_t b[MSA_WRLEN / 8];
19 int16_t h[MSA_WRLEN / 16];
20 int32_t w[MSA_WRLEN / 32];
21 int64_t d[MSA_WRLEN / 64];
e97a391d
YK
22};
23
c227f099
AL
24typedef union fpr_t fpr_t;
25union fpr_t {
ead9360e
TS
26 float64 fd; /* ieee double precision */
27 float32 fs[2];/* ieee single precision */
28 uint64_t d; /* binary double fixed-point */
29 uint32_t w[2]; /* binary single fixed-point */
e97a391d
YK
30/* FPU/MSA register mapping is not tested on big-endian hosts. */
31 wr_t wr; /* vector data */
ead9360e 32};
9e72f33d
JI
33/*
34 *define FP_ENDIAN_IDX to access the same location
4ff9786c 35 * in the fpr_t union regardless of the host endianness
ead9360e 36 */
e2542fe2 37#if defined(HOST_WORDS_BIGENDIAN)
ead9360e
TS
38# define FP_ENDIAN_IDX 1
39#else
40# define FP_ENDIAN_IDX 0
c570fd16 41#endif
ead9360e
TS
42
43typedef struct CPUMIPSFPUContext CPUMIPSFPUContext;
44struct CPUMIPSFPUContext {
6af0bf9c 45 /* Floating point registers */
c227f099 46 fpr_t fpr[32];
6ea83fed 47 float_status fp_status;
5a5012ec 48 /* fpu implementation/revision register (fir) */
6af0bf9c 49 uint32_t fcr0;
7c979afd 50#define FCR0_FREP 29
b4dd99a3 51#define FCR0_UFRP 28
ba5c79f2 52#define FCR0_HAS2008 23
5a5012ec
TS
53#define FCR0_F64 22
54#define FCR0_L 21
55#define FCR0_W 20
56#define FCR0_3D 19
57#define FCR0_PS 18
58#define FCR0_D 17
59#define FCR0_S 16
60#define FCR0_PRID 8
61#define FCR0_REV 0
6ea83fed 62 /* fcsr */
599bc5e8 63 uint32_t fcr31_rw_bitmask;
6ea83fed 64 uint32_t fcr31;
77be4199 65#define FCR31_FS 24
ba5c79f2
LA
66#define FCR31_ABS2008 19
67#define FCR31_NAN2008 18
8ebf2e1a
JI
68#define SET_FP_COND(num, env) do { ((env).fcr31) |= \
69 ((num) ? (1 << ((num) + 24)) : \
70 (1 << 23)); \
71 } while (0)
72#define CLEAR_FP_COND(num, env) do { ((env).fcr31) &= \
73 ~((num) ? (1 << ((num) + 24)) : \
74 (1 << 23)); \
75 } while (0)
76#define GET_FP_COND(env) ((((env).fcr31 >> 24) & 0xfe) | \
77 (((env).fcr31 >> 23) & 0x1))
5a5012ec
TS
78#define GET_FP_CAUSE(reg) (((reg) >> 12) & 0x3f)
79#define GET_FP_ENABLE(reg) (((reg) >> 7) & 0x1f)
80#define GET_FP_FLAGS(reg) (((reg) >> 2) & 0x1f)
8ebf2e1a
JI
81#define SET_FP_CAUSE(reg, v) do { (reg) = ((reg) & ~(0x3f << 12)) | \
82 ((v & 0x3f) << 12); \
83 } while (0)
84#define SET_FP_ENABLE(reg, v) do { (reg) = ((reg) & ~(0x1f << 7)) | \
85 ((v & 0x1f) << 7); \
86 } while (0)
87#define SET_FP_FLAGS(reg, v) do { (reg) = ((reg) & ~(0x1f << 2)) | \
88 ((v & 0x1f) << 2); \
89 } while (0)
90#define UPDATE_FP_FLAGS(reg, v) do { (reg) |= ((v & 0x1f) << 2); } while (0)
6ea83fed
FB
91#define FP_INEXACT 1
92#define FP_UNDERFLOW 2
93#define FP_OVERFLOW 4
94#define FP_DIV0 8
95#define FP_INVALID 16
96#define FP_UNIMPLEMENTED 32
ead9360e
TS
97};
98
c20d594e 99#define TARGET_INSN_START_EXTRA_WORDS 2
6ebbf390 100
ead9360e
TS
101typedef struct CPUMIPSMVPContext CPUMIPSMVPContext;
102struct CPUMIPSMVPContext {
103 int32_t CP0_MVPControl;
8ebf2e1a
JI
104#define CP0MVPCo_CPA 3
105#define CP0MVPCo_STLB 2
106#define CP0MVPCo_VPC 1
107#define CP0MVPCo_EVP 0
ead9360e 108 int32_t CP0_MVPConf0;
8ebf2e1a
JI
109#define CP0MVPC0_M 31
110#define CP0MVPC0_TLBS 29
111#define CP0MVPC0_GS 28
112#define CP0MVPC0_PCP 27
113#define CP0MVPC0_PTLBE 16
114#define CP0MVPC0_TCA 15
115#define CP0MVPC0_PVPE 10
116#define CP0MVPC0_PTC 0
ead9360e 117 int32_t CP0_MVPConf1;
8ebf2e1a
JI
118#define CP0MVPC1_CIM 31
119#define CP0MVPC1_CIF 30
120#define CP0MVPC1_PCX 20
121#define CP0MVPC1_PCP2 10
122#define CP0MVPC1_PCP1 0
ead9360e
TS
123};
124
c227f099 125typedef struct mips_def_t mips_def_t;
ead9360e
TS
126
127#define MIPS_SHADOW_SET_MAX 16
128#define MIPS_TC_MAX 5
f01be154 129#define MIPS_FPU_MAX 1
ead9360e 130#define MIPS_DSP_ACC 4
e98c0d17 131#define MIPS_KSCRATCH_NUM 6
f6d4dd81 132#define MIPS_MAAR_MAX 16 /* Must be an even number. */
ead9360e 133
e97a391d 134
a86d421e
AM
135/*
136 * Summary of CP0 registers
137 * ========================
138 *
139 *
140 * Register 0 Register 1 Register 2 Register 3
141 * ---------- ---------- ---------- ----------
142 *
143 * 0 Index Random EntryLo0 EntryLo1
144 * 1 MVPControl VPEControl TCStatus GlobalNumber
145 * 2 MVPConf0 VPEConf0 TCBind
146 * 3 MVPConf1 VPEConf1 TCRestart
147 * 4 VPControl YQMask TCHalt
148 * 5 VPESchedule TCContext
149 * 6 VPEScheFBack TCSchedule
150 * 7 VPEOpt TCScheFBack TCOpt
151 *
152 *
153 * Register 4 Register 5 Register 6 Register 7
154 * ---------- ---------- ---------- ----------
155 *
156 * 0 Context PageMask Wired HWREna
157 * 1 ContextConfig PageGrain SRSConf0
158 * 2 UserLocal SegCtl0 SRSConf1
159 * 3 XContextConfig SegCtl1 SRSConf2
160 * 4 DebugContextID SegCtl2 SRSConf3
161 * 5 MemoryMapID PWBase SRSConf4
162 * 6 PWField PWCtl
163 * 7 PWSize
164 *
165 *
166 * Register 8 Register 9 Register 10 Register 11
167 * ---------- ---------- ----------- -----------
168 *
169 * 0 BadVAddr Count EntryHi Compare
170 * 1 BadInstr
171 * 2 BadInstrP
172 * 3 BadInstrX
173 * 4 GuestCtl1 GuestCtl0Ext
174 * 5 GuestCtl2
167db30e
YK
175 * 6 SAARI GuestCtl3
176 * 7 SAAR
a86d421e
AM
177 *
178 *
179 * Register 12 Register 13 Register 14 Register 15
180 * ----------- ----------- ----------- -----------
181 *
182 * 0 Status Cause EPC PRId
183 * 1 IntCtl EBase
184 * 2 SRSCtl NestedEPC CDMMBase
185 * 3 SRSMap CMGCRBase
186 * 4 View_IPL View_RIPL BEVVA
187 * 5 SRSMap2 NestedExc
188 * 6 GuestCtl0
189 * 7 GTOffset
190 *
191 *
192 * Register 16 Register 17 Register 18 Register 19
193 * ----------- ----------- ----------- -----------
194 *
195 * 0 Config LLAddr WatchLo WatchHi
196 * 1 Config1 MAAR WatchLo WatchHi
197 * 2 Config2 MAARI WatchLo WatchHi
198 * 3 Config3 WatchLo WatchHi
199 * 4 Config4 WatchLo WatchHi
200 * 5 Config5 WatchLo WatchHi
201 * 6 WatchLo WatchHi
202 * 7 WatchLo WatchHi
203 *
204 *
205 * Register 20 Register 21 Register 22 Register 23
206 * ----------- ----------- ----------- -----------
207 *
208 * 0 XContext Debug
209 * 1 TraceControl
210 * 2 TraceControl2
211 * 3 UserTraceData1
212 * 4 TraceIBPC
213 * 5 TraceDBPC
214 * 6 Debug2
215 * 7
216 *
217 *
218 * Register 24 Register 25 Register 26 Register 27
219 * ----------- ----------- ----------- -----------
220 *
221 * 0 DEPC PerfCnt ErrCtl CacheErr
222 * 1 PerfCnt
223 * 2 TraceControl3 PerfCnt
224 * 3 UserTraceData2 PerfCnt
225 * 4 PerfCnt
226 * 5 PerfCnt
227 * 6 PerfCnt
228 * 7 PerfCnt
229 *
230 *
231 * Register 28 Register 29 Register 30 Register 31
232 * ----------- ----------- ----------- -----------
233 *
234 * 0 DataLo DataHi ErrorEPC DESAVE
235 * 1 TagLo TagHi
236 * 2 DataLo DataHi KScratch<n>
237 * 3 TagLo TagHi KScratch<n>
238 * 4 DataLo DataHi KScratch<n>
239 * 5 TagLo TagHi KScratch<n>
240 * 6 DataLo DataHi KScratch<n>
241 * 7 TagLo TagHi KScratch<n>
242 *
50e7edc5 243 */
04992c8c
AM
244#define CP0_REGISTER_00 0
245#define CP0_REGISTER_01 1
246#define CP0_REGISTER_02 2
247#define CP0_REGISTER_03 3
248#define CP0_REGISTER_04 4
249#define CP0_REGISTER_05 5
250#define CP0_REGISTER_06 6
251#define CP0_REGISTER_07 7
252#define CP0_REGISTER_08 8
253#define CP0_REGISTER_09 9
254#define CP0_REGISTER_10 10
255#define CP0_REGISTER_11 11
256#define CP0_REGISTER_12 12
257#define CP0_REGISTER_13 13
258#define CP0_REGISTER_14 14
259#define CP0_REGISTER_15 15
260#define CP0_REGISTER_16 16
261#define CP0_REGISTER_17 17
262#define CP0_REGISTER_18 18
263#define CP0_REGISTER_19 19
264#define CP0_REGISTER_20 20
265#define CP0_REGISTER_21 21
266#define CP0_REGISTER_22 22
267#define CP0_REGISTER_23 23
268#define CP0_REGISTER_24 24
269#define CP0_REGISTER_25 25
270#define CP0_REGISTER_26 26
271#define CP0_REGISTER_27 27
272#define CP0_REGISTER_28 28
273#define CP0_REGISTER_29 29
274#define CP0_REGISTER_30 30
275#define CP0_REGISTER_31 31
276
277
278/* CP0 Register 00 */
279#define CP0_REG00__INDEX 0
1b142da5
AM
280#define CP0_REG00__MVPCONTROL 1
281#define CP0_REG00__MVPCONF0 2
282#define CP0_REG00__MVPCONF1 3
04992c8c
AM
283#define CP0_REG00__VPCONTROL 4
284/* CP0 Register 01 */
30deb460
AM
285#define CP0_REG01__RANDOM 0
286#define CP0_REG01__VPECONTROL 1
287#define CP0_REG01__VPECONF0 2
288#define CP0_REG01__VPECONF1 3
289#define CP0_REG01__YQMASK 4
290#define CP0_REG01__VPESCHEDULE 5
291#define CP0_REG01__VPESCHEFBACK 6
292#define CP0_REG01__VPEOPT 7
04992c8c
AM
293/* CP0 Register 02 */
294#define CP0_REG02__ENTRYLO0 0
6d27d5bd
AM
295#define CP0_REG02__TCSTATUS 1
296#define CP0_REG02__TCBIND 2
297#define CP0_REG02__TCRESTART 3
298#define CP0_REG02__TCHALT 4
299#define CP0_REG02__TCCONTEXT 5
300#define CP0_REG02__TCSCHEDULE 6
301#define CP0_REG02__TCSCHEFBACK 7
04992c8c
AM
302/* CP0 Register 03 */
303#define CP0_REG03__ENTRYLO1 0
304#define CP0_REG03__GLOBALNUM 1
acd37316 305#define CP0_REG03__TCOPT 7
04992c8c
AM
306/* CP0 Register 04 */
307#define CP0_REG04__CONTEXT 0
020fe379 308#define CP0_REG04__CONTEXTCONFIG 1
04992c8c 309#define CP0_REG04__USERLOCAL 2
020fe379 310#define CP0_REG04__XCONTEXTCONFIG 3
04992c8c
AM
311#define CP0_REG04__DBGCONTEXTID 4
312#define CP0_REG00__MMID 5
313/* CP0 Register 05 */
314#define CP0_REG05__PAGEMASK 0
315#define CP0_REG05__PAGEGRAIN 1
a1e76353
AM
316#define CP0_REG05__SEGCTL0 2
317#define CP0_REG05__SEGCTL1 3
318#define CP0_REG05__SEGCTL2 4
319#define CP0_REG05__PWBASE 5
320#define CP0_REG05__PWFIELD 6
321#define CP0_REG05__PWSIZE 7
04992c8c
AM
322/* CP0 Register 06 */
323#define CP0_REG06__WIRED 0
324/* CP0 Register 07 */
325#define CP0_REG07__HWRENA 0
326/* CP0 Register 08 */
327#define CP0_REG08__BADVADDR 0
328#define CP0_REG08__BADINSTR 1
329#define CP0_REG08__BADINSTRP 2
330/* CP0 Register 09 */
331#define CP0_REG09__COUNT 0
332#define CP0_REG09__SAARI 6
333#define CP0_REG09__SAAR 7
334/* CP0 Register 10 */
335#define CP0_REG10__ENTRYHI 0
336#define CP0_REG10__GUESTCTL1 4
337#define CP0_REG10__GUESTCTL2 5
338/* CP0 Register 11 */
339#define CP0_REG11__COMPARE 0
340#define CP0_REG11__GUESTCTL0EXT 4
341/* CP0 Register 12 */
342#define CP0_REG12__STATUS 0
343#define CP0_REG12__INTCTL 1
344#define CP0_REG12__SRSCTL 2
345#define CP0_REG12__GUESTCTL0 6
346#define CP0_REG12__GTOFFSET 7
347/* CP0 Register 13 */
348#define CP0_REG13__CAUSE 0
349/* CP0 Register 14 */
350#define CP0_REG14__EPC 0
351/* CP0 Register 15 */
352#define CP0_REG15__PRID 0
353#define CP0_REG15__EBASE 1
354#define CP0_REG15__CDMMBASE 2
355#define CP0_REG15__CMGCRBASE 3
356/* CP0 Register 16 */
357#define CP0_REG16__CONFIG 0
358#define CP0_REG16__CONFIG1 1
359#define CP0_REG16__CONFIG2 2
360#define CP0_REG16__CONFIG3 3
361#define CP0_REG16__CONFIG4 4
362#define CP0_REG16__CONFIG5 5
363#define CP0_REG00__CONFIG7 7
364/* CP0 Register 17 */
365#define CP0_REG17__LLADDR 0
366#define CP0_REG17__MAAR 1
367#define CP0_REG17__MAARI 2
368/* CP0 Register 18 */
369#define CP0_REG18__WATCHLO0 0
370#define CP0_REG18__WATCHLO1 1
371#define CP0_REG18__WATCHLO2 2
372#define CP0_REG18__WATCHLO3 3
373/* CP0 Register 19 */
374#define CP0_REG19__WATCHHI0 0
375#define CP0_REG19__WATCHHI1 1
376#define CP0_REG19__WATCHHI2 2
377#define CP0_REG19__WATCHHI3 3
378/* CP0 Register 20 */
379#define CP0_REG20__XCONTEXT 0
380/* CP0 Register 21 */
381/* CP0 Register 22 */
382/* CP0 Register 23 */
383#define CP0_REG23__DEBUG 0
384/* CP0 Register 24 */
385#define CP0_REG24__DEPC 0
386/* CP0 Register 25 */
387#define CP0_REG25__PERFCTL0 0
388#define CP0_REG25__PERFCNT0 1
389#define CP0_REG25__PERFCTL1 2
390#define CP0_REG25__PERFCNT1 3
391#define CP0_REG25__PERFCTL2 4
392#define CP0_REG25__PERFCNT2 5
393#define CP0_REG25__PERFCTL3 6
394#define CP0_REG25__PERFCNT3 7
395/* CP0 Register 26 */
396#define CP0_REG00__ERRCTL 0
397/* CP0 Register 27 */
398#define CP0_REG27__CACHERR 0
399/* CP0 Register 28 */
400#define CP0_REG28__ITAGLO 0
401#define CP0_REG28__IDATALO 1
402#define CP0_REG28__DTAGLO 2
403#define CP0_REG28__DDATALO 3
404/* CP0 Register 29 */
405#define CP0_REG29__IDATAHI 1
406#define CP0_REG29__DDATAHI 3
407/* CP0 Register 30 */
408#define CP0_REG30__ERROREPC 0
409/* CP0 Register 31 */
410#define CP0_REG31__DESAVE 0
411#define CP0_REG31__KSCRATCH1 2
412#define CP0_REG31__KSCRATCH2 3
413#define CP0_REG31__KSCRATCH3 4
414#define CP0_REG31__KSCRATCH4 5
415#define CP0_REG31__KSCRATCH5 6
416#define CP0_REG31__KSCRATCH6 7
ea9c5e83
AM
417
418
419typedef struct TCState TCState;
420struct TCState {
421 target_ulong gpr[32];
422 target_ulong PC;
423 target_ulong HI[MIPS_DSP_ACC];
424 target_ulong LO[MIPS_DSP_ACC];
425 target_ulong ACX[MIPS_DSP_ACC];
426 target_ulong DSPControl;
427 int32_t CP0_TCStatus;
428#define CP0TCSt_TCU3 31
429#define CP0TCSt_TCU2 30
430#define CP0TCSt_TCU1 29
431#define CP0TCSt_TCU0 28
432#define CP0TCSt_TMX 27
433#define CP0TCSt_RNST 23
434#define CP0TCSt_TDS 21
435#define CP0TCSt_DT 20
436#define CP0TCSt_DA 15
437#define CP0TCSt_A 13
438#define CP0TCSt_TKSU 11
439#define CP0TCSt_IXMT 10
440#define CP0TCSt_TASID 0
441 int32_t CP0_TCBind;
442#define CP0TCBd_CurTC 21
443#define CP0TCBd_TBE 17
444#define CP0TCBd_CurVPE 0
445 target_ulong CP0_TCHalt;
446 target_ulong CP0_TCContext;
447 target_ulong CP0_TCSchedule;
448 target_ulong CP0_TCScheFBack;
449 int32_t CP0_Debug_tcstatus;
450 target_ulong CP0_UserLocal;
451
452 int32_t msacsr;
453
454#define MSACSR_FS 24
455#define MSACSR_FS_MASK (1 << MSACSR_FS)
456#define MSACSR_NX 18
457#define MSACSR_NX_MASK (1 << MSACSR_NX)
458#define MSACSR_CEF 2
459#define MSACSR_CEF_MASK (0xffff << MSACSR_CEF)
460#define MSACSR_RM 0
461#define MSACSR_RM_MASK (0x3 << MSACSR_RM)
462#define MSACSR_MASK (MSACSR_RM_MASK | MSACSR_CEF_MASK | MSACSR_NX_MASK | \
463 MSACSR_FS_MASK)
464
465 float_status msa_fp_status;
466
a168a796
FN
467 /* Upper 64-bit MMRs (multimedia registers); the lower 64-bit are GPRs */
468 uint64_t mmr[32];
469
ea9c5e83
AM
470#define NUMBER_OF_MXU_REGISTERS 16
471 target_ulong mxu_gpr[NUMBER_OF_MXU_REGISTERS - 1];
472 target_ulong mxu_cr;
473#define MXU_CR_LC 31
474#define MXU_CR_RC 30
475#define MXU_CR_BIAS 2
476#define MXU_CR_RD_EN 1
477#define MXU_CR_MXU_EN 0
478
479};
480
043715d1 481struct MIPSITUState;
ea9c5e83
AM
482typedef struct CPUMIPSState CPUMIPSState;
483struct CPUMIPSState {
484 TCState active_tc;
485 CPUMIPSFPUContext active_fpu;
486
487 uint32_t current_tc;
488 uint32_t current_fpu;
489
490 uint32_t SEGBITS;
491 uint32_t PABITS;
492#if defined(TARGET_MIPS64)
493# define PABITS_BASE 36
494#else
495# define PABITS_BASE 32
496#endif
497 target_ulong SEGMask;
498 uint64_t PAMask;
499#define PAMASK_BASE ((1ULL << PABITS_BASE) - 1)
500
501 int32_t msair;
502#define MSAIR_ProcID 8
503#define MSAIR_Rev 0
504
50e7edc5
AM
505/*
506 * CP0 Register 0
a86d421e 507 */
9c2149c8 508 int32_t CP0_Index;
ead9360e 509 /* CP0_MVP* are per MVP registers. */
01bc435b
YK
510 int32_t CP0_VPControl;
511#define CP0VPCtl_DIS 0
50e7edc5
AM
512/*
513 * CP0 Register 1
514 */
9c2149c8 515 int32_t CP0_Random;
ead9360e 516 int32_t CP0_VPEControl;
8ebf2e1a
JI
517#define CP0VPECo_YSI 21
518#define CP0VPECo_GSI 20
519#define CP0VPECo_EXCPT 16
520#define CP0VPECo_TE 15
521#define CP0VPECo_TargTC 0
ead9360e 522 int32_t CP0_VPEConf0;
8ebf2e1a
JI
523#define CP0VPEC0_M 31
524#define CP0VPEC0_XTC 21
525#define CP0VPEC0_TCS 19
526#define CP0VPEC0_SCS 18
527#define CP0VPEC0_DSC 17
528#define CP0VPEC0_ICS 16
529#define CP0VPEC0_MVP 1
530#define CP0VPEC0_VPA 0
ead9360e 531 int32_t CP0_VPEConf1;
8ebf2e1a
JI
532#define CP0VPEC1_NCX 20
533#define CP0VPEC1_NCP2 10
534#define CP0VPEC1_NCP1 0
ead9360e
TS
535 target_ulong CP0_YQMask;
536 target_ulong CP0_VPESchedule;
537 target_ulong CP0_VPEScheFBack;
538 int32_t CP0_VPEOpt;
8ebf2e1a
JI
539#define CP0VPEOpt_IWX7 15
540#define CP0VPEOpt_IWX6 14
541#define CP0VPEOpt_IWX5 13
542#define CP0VPEOpt_IWX4 12
543#define CP0VPEOpt_IWX3 11
544#define CP0VPEOpt_IWX2 10
545#define CP0VPEOpt_IWX1 9
546#define CP0VPEOpt_IWX0 8
547#define CP0VPEOpt_DWX7 7
548#define CP0VPEOpt_DWX6 6
549#define CP0VPEOpt_DWX5 5
550#define CP0VPEOpt_DWX4 4
551#define CP0VPEOpt_DWX3 3
552#define CP0VPEOpt_DWX2 2
553#define CP0VPEOpt_DWX1 1
554#define CP0VPEOpt_DWX0 0
50e7edc5
AM
555/*
556 * CP0 Register 2
557 */
284b731a 558 uint64_t CP0_EntryLo0;
50e7edc5
AM
559/*
560 * CP0 Register 3
561 */
284b731a 562 uint64_t CP0_EntryLo1;
2fb58b73
LA
563#if defined(TARGET_MIPS64)
564# define CP0EnLo_RI 63
565# define CP0EnLo_XI 62
566#else
567# define CP0EnLo_RI 31
568# define CP0EnLo_XI 30
569#endif
01bc435b
YK
570 int32_t CP0_GlobalNumber;
571#define CP0GN_VPId 0
50e7edc5
AM
572/*
573 * CP0 Register 4
574 */
9c2149c8 575 target_ulong CP0_Context;
e98c0d17 576 target_ulong CP0_KScratch[MIPS_KSCRATCH_NUM];
3ef521ee 577 int32_t CP0_MemoryMapID;
50e7edc5
AM
578/*
579 * CP0 Register 5
580 */
9c2149c8 581 int32_t CP0_PageMask;
7207c7f9 582 int32_t CP0_PageGrain_rw_bitmask;
9c2149c8 583 int32_t CP0_PageGrain;
7207c7f9
LA
584#define CP0PG_RIE 31
585#define CP0PG_XIE 30
e117f526 586#define CP0PG_ELPA 29
92ceb440 587#define CP0PG_IEC 27
cec56a73
JH
588 target_ulong CP0_SegCtl0;
589 target_ulong CP0_SegCtl1;
590 target_ulong CP0_SegCtl2;
591#define CP0SC_PA 9
592#define CP0SC_PA_MASK (0x7FULL << CP0SC_PA)
593#define CP0SC_PA_1GMASK (0x7EULL << CP0SC_PA)
594#define CP0SC_AM 4
595#define CP0SC_AM_MASK (0x7ULL << CP0SC_AM)
596#define CP0SC_AM_UK 0ULL
597#define CP0SC_AM_MK 1ULL
598#define CP0SC_AM_MSK 2ULL
599#define CP0SC_AM_MUSK 3ULL
600#define CP0SC_AM_MUSUK 4ULL
601#define CP0SC_AM_USK 5ULL
602#define CP0SC_AM_UUSK 7ULL
603#define CP0SC_EU 3
604#define CP0SC_EU_MASK (1ULL << CP0SC_EU)
605#define CP0SC_C 0
606#define CP0SC_C_MASK (0x7ULL << CP0SC_C)
607#define CP0SC_MASK (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
608 CP0SC_PA_MASK)
609#define CP0SC_1GMASK (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
610 CP0SC_PA_1GMASK)
611#define CP0SC0_MASK (CP0SC_MASK | (CP0SC_MASK << 16))
612#define CP0SC1_XAM 59
613#define CP0SC1_XAM_MASK (0x7ULL << CP0SC1_XAM)
614#define CP0SC1_MASK (CP0SC_MASK | (CP0SC_MASK << 16) | CP0SC1_XAM_MASK)
615#define CP0SC2_XR 56
616#define CP0SC2_XR_MASK (0xFFULL << CP0SC2_XR)
617#define CP0SC2_MASK (CP0SC_1GMASK | (CP0SC_1GMASK << 16) | CP0SC2_XR_MASK)
5e31fdd5 618 target_ulong CP0_PWBase;
fa75ad14
YK
619 target_ulong CP0_PWField;
620#if defined(TARGET_MIPS64)
621#define CP0PF_BDI 32 /* 37..32 */
622#define CP0PF_GDI 24 /* 29..24 */
623#define CP0PF_UDI 18 /* 23..18 */
624#define CP0PF_MDI 12 /* 17..12 */
625#define CP0PF_PTI 6 /* 11..6 */
626#define CP0PF_PTEI 0 /* 5..0 */
627#else
628#define CP0PF_GDW 24 /* 29..24 */
629#define CP0PF_UDW 18 /* 23..18 */
630#define CP0PF_MDW 12 /* 17..12 */
631#define CP0PF_PTW 6 /* 11..6 */
632#define CP0PF_PTEW 0 /* 5..0 */
633#endif
20b28ebc
YK
634 target_ulong CP0_PWSize;
635#if defined(TARGET_MIPS64)
636#define CP0PS_BDW 32 /* 37..32 */
637#endif
638#define CP0PS_PS 30
639#define CP0PS_GDW 24 /* 29..24 */
640#define CP0PS_UDW 18 /* 23..18 */
641#define CP0PS_MDW 12 /* 17..12 */
642#define CP0PS_PTW 6 /* 11..6 */
643#define CP0PS_PTEW 0 /* 5..0 */
50e7edc5
AM
644/*
645 * CP0 Register 6
646 */
9c2149c8 647 int32_t CP0_Wired;
103be64c
YK
648 int32_t CP0_PWCtl;
649#define CP0PC_PWEN 31
650#if defined(TARGET_MIPS64)
651#define CP0PC_PWDIREXT 30
652#define CP0PC_XK 28
653#define CP0PC_XS 27
654#define CP0PC_XU 26
655#endif
656#define CP0PC_DPH 7
657#define CP0PC_HUGEPG 6
658#define CP0PC_PSN 0 /* 5..0 */
ead9360e
TS
659 int32_t CP0_SRSConf0_rw_bitmask;
660 int32_t CP0_SRSConf0;
8ebf2e1a
JI
661#define CP0SRSC0_M 31
662#define CP0SRSC0_SRS3 20
663#define CP0SRSC0_SRS2 10
664#define CP0SRSC0_SRS1 0
ead9360e
TS
665 int32_t CP0_SRSConf1_rw_bitmask;
666 int32_t CP0_SRSConf1;
8ebf2e1a
JI
667#define CP0SRSC1_M 31
668#define CP0SRSC1_SRS6 20
669#define CP0SRSC1_SRS5 10
670#define CP0SRSC1_SRS4 0
ead9360e
TS
671 int32_t CP0_SRSConf2_rw_bitmask;
672 int32_t CP0_SRSConf2;
8ebf2e1a
JI
673#define CP0SRSC2_M 31
674#define CP0SRSC2_SRS9 20
675#define CP0SRSC2_SRS8 10
676#define CP0SRSC2_SRS7 0
ead9360e
TS
677 int32_t CP0_SRSConf3_rw_bitmask;
678 int32_t CP0_SRSConf3;
8ebf2e1a
JI
679#define CP0SRSC3_M 31
680#define CP0SRSC3_SRS12 20
681#define CP0SRSC3_SRS11 10
682#define CP0SRSC3_SRS10 0
ead9360e
TS
683 int32_t CP0_SRSConf4_rw_bitmask;
684 int32_t CP0_SRSConf4;
8ebf2e1a
JI
685#define CP0SRSC4_SRS15 20
686#define CP0SRSC4_SRS14 10
687#define CP0SRSC4_SRS13 0
50e7edc5
AM
688/*
689 * CP0 Register 7
690 */
9c2149c8 691 int32_t CP0_HWREna;
50e7edc5
AM
692/*
693 * CP0 Register 8
694 */
c570fd16 695 target_ulong CP0_BadVAddr;
aea14095
LA
696 uint32_t CP0_BadInstr;
697 uint32_t CP0_BadInstrP;
25beba9b 698 uint32_t CP0_BadInstrX;
50e7edc5
AM
699/*
700 * CP0 Register 9
701 */
9c2149c8 702 int32_t CP0_Count;
167db30e
YK
703 uint32_t CP0_SAARI;
704#define CP0SAARI_TARGET 0 /* 5..0 */
705 uint64_t CP0_SAAR[2];
706#define CP0SAAR_BASE 12 /* 43..12 */
707#define CP0SAAR_SIZE 1 /* 5..1 */
708#define CP0SAAR_EN 0
50e7edc5
AM
709/*
710 * CP0 Register 10
711 */
9c2149c8 712 target_ulong CP0_EntryHi;
9456c2fb 713#define CP0EnHi_EHINV 10
6ec98bd7 714 target_ulong CP0_EntryHi_ASID_mask;
50e7edc5
AM
715/*
716 * CP0 Register 11
717 */
9c2149c8 718 int32_t CP0_Compare;
50e7edc5
AM
719/*
720 * CP0 Register 12
721 */
9c2149c8 722 int32_t CP0_Status;
6af0bf9c
FB
723#define CP0St_CU3 31
724#define CP0St_CU2 30
725#define CP0St_CU1 29
726#define CP0St_CU0 28
727#define CP0St_RP 27
6ea83fed 728#define CP0St_FR 26
6af0bf9c 729#define CP0St_RE 25
7a387fff
TS
730#define CP0St_MX 24
731#define CP0St_PX 23
6af0bf9c
FB
732#define CP0St_BEV 22
733#define CP0St_TS 21
734#define CP0St_SR 20
735#define CP0St_NMI 19
736#define CP0St_IM 8
7a387fff
TS
737#define CP0St_KX 7
738#define CP0St_SX 6
739#define CP0St_UX 5
623a930e 740#define CP0St_KSU 3
6af0bf9c
FB
741#define CP0St_ERL 2
742#define CP0St_EXL 1
743#define CP0St_IE 0
9c2149c8 744 int32_t CP0_IntCtl;
ead9360e 745#define CP0IntCtl_IPTI 29
88991299 746#define CP0IntCtl_IPPCI 26
ead9360e 747#define CP0IntCtl_VS 5
9c2149c8 748 int32_t CP0_SRSCtl;
ead9360e
TS
749#define CP0SRSCtl_HSS 26
750#define CP0SRSCtl_EICSS 18
751#define CP0SRSCtl_ESS 12
752#define CP0SRSCtl_PSS 6
753#define CP0SRSCtl_CSS 0
9c2149c8 754 int32_t CP0_SRSMap;
ead9360e
TS
755#define CP0SRSMap_SSV7 28
756#define CP0SRSMap_SSV6 24
757#define CP0SRSMap_SSV5 20
758#define CP0SRSMap_SSV4 16
759#define CP0SRSMap_SSV3 12
760#define CP0SRSMap_SSV2 8
761#define CP0SRSMap_SSV1 4
762#define CP0SRSMap_SSV0 0
50e7edc5
AM
763/*
764 * CP0 Register 13
765 */
9c2149c8 766 int32_t CP0_Cause;
7a387fff
TS
767#define CP0Ca_BD 31
768#define CP0Ca_TI 30
769#define CP0Ca_CE 28
770#define CP0Ca_DC 27
771#define CP0Ca_PCI 26
6af0bf9c 772#define CP0Ca_IV 23
7a387fff
TS
773#define CP0Ca_WP 22
774#define CP0Ca_IP 8
4de9b249 775#define CP0Ca_IP_mask 0x0000FF00
7a387fff 776#define CP0Ca_EC 2
50e7edc5
AM
777/*
778 * CP0 Register 14
779 */
c570fd16 780 target_ulong CP0_EPC;
50e7edc5
AM
781/*
782 * CP0 Register 15
783 */
9c2149c8 784 int32_t CP0_PRid;
74dbf824
JH
785 target_ulong CP0_EBase;
786 target_ulong CP0_EBaseWG_rw_bitmask;
787#define CP0EBase_WG 11
c870e3f5 788 target_ulong CP0_CMGCRBase;
50e7edc5
AM
789/*
790 * CP0 Register 16
791 */
9c2149c8 792 int32_t CP0_Config0;
6af0bf9c 793#define CP0C0_M 31
0413d7a5
AM
794#define CP0C0_K23 28 /* 30..28 */
795#define CP0C0_KU 25 /* 27..25 */
6af0bf9c 796#define CP0C0_MDU 20
aff2bc6d 797#define CP0C0_MM 18
6af0bf9c 798#define CP0C0_BM 16
0413d7a5 799#define CP0C0_Impl 16 /* 24..16 */
6af0bf9c 800#define CP0C0_BE 15
0413d7a5
AM
801#define CP0C0_AT 13 /* 14..13 */
802#define CP0C0_AR 10 /* 12..10 */
803#define CP0C0_MT 7 /* 9..7 */
7a387fff 804#define CP0C0_VI 3
0413d7a5 805#define CP0C0_K0 0 /* 2..0 */
9c2149c8 806 int32_t CP0_Config1;
7a387fff 807#define CP0C1_M 31
0413d7a5
AM
808#define CP0C1_MMU 25 /* 30..25 */
809#define CP0C1_IS 22 /* 24..22 */
810#define CP0C1_IL 19 /* 21..19 */
811#define CP0C1_IA 16 /* 18..16 */
812#define CP0C1_DS 13 /* 15..13 */
813#define CP0C1_DL 10 /* 12..10 */
814#define CP0C1_DA 7 /* 9..7 */
7a387fff
TS
815#define CP0C1_C2 6
816#define CP0C1_MD 5
6af0bf9c
FB
817#define CP0C1_PC 4
818#define CP0C1_WR 3
819#define CP0C1_CA 2
820#define CP0C1_EP 1
821#define CP0C1_FP 0
9c2149c8 822 int32_t CP0_Config2;
7a387fff 823#define CP0C2_M 31
0413d7a5
AM
824#define CP0C2_TU 28 /* 30..28 */
825#define CP0C2_TS 24 /* 27..24 */
826#define CP0C2_TL 20 /* 23..20 */
827#define CP0C2_TA 16 /* 19..16 */
828#define CP0C2_SU 12 /* 15..12 */
829#define CP0C2_SS 8 /* 11..8 */
830#define CP0C2_SL 4 /* 7..4 */
831#define CP0C2_SA 0 /* 3..0 */
9c2149c8 832 int32_t CP0_Config3;
0413d7a5
AM
833#define CP0C3_M 31
834#define CP0C3_BPG 30
835#define CP0C3_CMGCR 29
836#define CP0C3_MSAP 28
837#define CP0C3_BP 27
838#define CP0C3_BI 26
839#define CP0C3_SC 25
840#define CP0C3_PW 24
841#define CP0C3_VZ 23
842#define CP0C3_IPLV 21 /* 22..21 */
843#define CP0C3_MMAR 18 /* 20..18 */
844#define CP0C3_MCU 17
845#define CP0C3_ISA_ON_EXC 16
846#define CP0C3_ISA 14 /* 15..14 */
847#define CP0C3_ULRI 13
848#define CP0C3_RXI 12
849#define CP0C3_DSP2P 11
850#define CP0C3_DSPP 10
851#define CP0C3_CTXTC 9
852#define CP0C3_ITL 8
853#define CP0C3_LPA 7
854#define CP0C3_VEIC 6
855#define CP0C3_VInt 5
856#define CP0C3_SP 4
857#define CP0C3_CDMM 3
858#define CP0C3_MT 2
859#define CP0C3_SM 1
860#define CP0C3_TL 0
8280b12c
MR
861 int32_t CP0_Config4;
862 int32_t CP0_Config4_rw_bitmask;
0413d7a5
AM
863#define CP0C4_M 31
864#define CP0C4_IE 29 /* 30..29 */
865#define CP0C4_AE 28
866#define CP0C4_VTLBSizeExt 24 /* 27..24 */
867#define CP0C4_KScrExist 16
868#define CP0C4_MMUExtDef 14
869#define CP0C4_FTLBPageSize 8 /* 12..8 */
870/* bit layout if MMUExtDef=1 */
871#define CP0C4_MMUSizeExt 0 /* 7..0 */
872/* bit layout if MMUExtDef=2 */
873#define CP0C4_FTLBWays 4 /* 7..4 */
874#define CP0C4_FTLBSets 0 /* 3..0 */
8280b12c
MR
875 int32_t CP0_Config5;
876 int32_t CP0_Config5_rw_bitmask;
0413d7a5
AM
877#define CP0C5_M 31
878#define CP0C5_K 30
879#define CP0C5_CV 29
880#define CP0C5_EVA 28
881#define CP0C5_MSAEn 27
882#define CP0C5_PMJ 23 /* 25..23 */
883#define CP0C5_WR2 22
884#define CP0C5_NMS 21
885#define CP0C5_ULS 20
886#define CP0C5_XPA 19
887#define CP0C5_CRCP 18
888#define CP0C5_MI 17
889#define CP0C5_GI 15 /* 16..15 */
890#define CP0C5_CA2 14
891#define CP0C5_XNP 13
892#define CP0C5_DEC 11
893#define CP0C5_L2C 10
894#define CP0C5_UFE 9
895#define CP0C5_FRE 8
896#define CP0C5_VP 7
897#define CP0C5_SBRI 6
898#define CP0C5_MVH 5
899#define CP0C5_LLB 4
900#define CP0C5_MRP 3
901#define CP0C5_UFR 2
902#define CP0C5_NFExists 0
e397ee33
TS
903 int32_t CP0_Config6;
904 int32_t CP0_Config7;
c7c7e1e9 905 uint64_t CP0_LLAddr;
f6d4dd81
YK
906 uint64_t CP0_MAAR[MIPS_MAAR_MAX];
907 int32_t CP0_MAARI;
ead9360e 908 /* XXX: Maybe make LLAddr per-TC? */
50e7edc5
AM
909/*
910 * CP0 Register 17
911 */
c7c7e1e9 912 target_ulong lladdr; /* LL virtual address compared against SC */
590bc601 913 target_ulong llval;
0b16dcd1
AR
914 uint64_t llval_wp;
915 uint32_t llnewval_wp;
284b731a 916 uint64_t CP0_LLAddr_rw_bitmask;
2a6e32dd 917 int CP0_LLAddr_shift;
50e7edc5
AM
918/*
919 * CP0 Register 18
920 */
fd88b6ab 921 target_ulong CP0_WatchLo[8];
50e7edc5
AM
922/*
923 * CP0 Register 19
924 */
fd88b6ab 925 int32_t CP0_WatchHi[8];
6ec98bd7 926#define CP0WH_ASID 16
50e7edc5
AM
927/*
928 * CP0 Register 20
929 */
9c2149c8
TS
930 target_ulong CP0_XContext;
931 int32_t CP0_Framemask;
50e7edc5
AM
932/*
933 * CP0 Register 23
934 */
9c2149c8 935 int32_t CP0_Debug;
ead9360e 936#define CP0DB_DBD 31
6af0bf9c
FB
937#define CP0DB_DM 30
938#define CP0DB_LSNM 28
939#define CP0DB_Doze 27
940#define CP0DB_Halt 26
941#define CP0DB_CNT 25
942#define CP0DB_IBEP 24
943#define CP0DB_DBEP 21
944#define CP0DB_IEXI 20
945#define CP0DB_VER 15
946#define CP0DB_DEC 10
947#define CP0DB_SSt 8
948#define CP0DB_DINT 5
949#define CP0DB_DIB 4
950#define CP0DB_DDBS 3
951#define CP0DB_DDBL 2
952#define CP0DB_DBp 1
953#define CP0DB_DSS 0
50e7edc5
AM
954/*
955 * CP0 Register 24
956 */
c570fd16 957 target_ulong CP0_DEPC;
50e7edc5
AM
958/*
959 * CP0 Register 25
960 */
9c2149c8 961 int32_t CP0_Performance0;
50e7edc5
AM
962/*
963 * CP0 Register 26
964 */
0d74a222
LA
965 int32_t CP0_ErrCtl;
966#define CP0EC_WST 29
967#define CP0EC_SPR 28
968#define CP0EC_ITC 26
50e7edc5
AM
969/*
970 * CP0 Register 28
971 */
284b731a 972 uint64_t CP0_TagLo;
9c2149c8 973 int32_t CP0_DataLo;
50e7edc5
AM
974/*
975 * CP0 Register 29
976 */
9c2149c8
TS
977 int32_t CP0_TagHi;
978 int32_t CP0_DataHi;
50e7edc5
AM
979/*
980 * CP0 Register 30
981 */
c570fd16 982 target_ulong CP0_ErrorEPC;
50e7edc5
AM
983/*
984 * CP0 Register 31
985 */
9c2149c8 986 int32_t CP0_DESAVE;
50e7edc5 987
b5dc7732
TS
988 /* We waste some space so we can handle shadow registers like TCs. */
989 TCState tcs[MIPS_SHADOW_SET_MAX];
f01be154 990 CPUMIPSFPUContext fpus[MIPS_FPU_MAX];
5cbdb3a3 991 /* QEMU */
6af0bf9c 992 int error_code;
aea14095
LA
993#define EXCP_TLB_NOMATCH 0x1
994#define EXCP_INST_NOTAVAIL 0x2 /* No valid instruction word for BadInstr */
6af0bf9c
FB
995 uint32_t hflags; /* CPU State */
996 /* TMASK defines different execution modes */
42c86612 997#define MIPS_HFLAG_TMASK 0x1F5807FF
79ef2c4c 998#define MIPS_HFLAG_MODE 0x00007 /* execution modes */
9e72f33d
JI
999 /*
1000 * The KSU flags must be the lowest bits in hflags. The flag order
1001 * must be the same as defined for CP0 Status. This allows to use
1002 * the bits as the value of mmu_idx.
1003 */
79ef2c4c
NF
1004#define MIPS_HFLAG_KSU 0x00003 /* kernel/supervisor/user mode mask */
1005#define MIPS_HFLAG_UM 0x00002 /* user mode flag */
1006#define MIPS_HFLAG_SM 0x00001 /* supervisor mode flag */
1007#define MIPS_HFLAG_KM 0x00000 /* kernel mode flag */
1008#define MIPS_HFLAG_DM 0x00004 /* Debug mode */
1009#define MIPS_HFLAG_64 0x00008 /* 64-bit instructions enabled */
1010#define MIPS_HFLAG_CP0 0x00010 /* CP0 enabled */
1011#define MIPS_HFLAG_FPU 0x00020 /* FPU enabled */
1012#define MIPS_HFLAG_F64 0x00040 /* 64-bit FPU enabled */
9e72f33d
JI
1013 /*
1014 * True if the MIPS IV COP1X instructions can be used. This also
1015 * controls the non-COP1X instructions RECIP.S, RECIP.D, RSQRT.S
1016 * and RSQRT.D.
1017 */
79ef2c4c
NF
1018#define MIPS_HFLAG_COP1X 0x00080 /* COP1X instructions enabled */
1019#define MIPS_HFLAG_RE 0x00100 /* Reversed endianness */
01f72885 1020#define MIPS_HFLAG_AWRAP 0x00200 /* 32-bit compatibility address wrapping */
79ef2c4c
NF
1021#define MIPS_HFLAG_M16 0x00400 /* MIPS16 mode flag */
1022#define MIPS_HFLAG_M16_SHIFT 10
9e72f33d
JI
1023 /*
1024 * If translation is interrupted between the branch instruction and
4ad40f36
FB
1025 * the delay slot, record what type of branch it is so that we can
1026 * resume translation properly. It might be possible to reduce
9e72f33d
JI
1027 * this from three bits to two.
1028 */
339cd2a8 1029#define MIPS_HFLAG_BMASK_BASE 0x803800
79ef2c4c
NF
1030#define MIPS_HFLAG_B 0x00800 /* Unconditional branch */
1031#define MIPS_HFLAG_BC 0x01000 /* Conditional branch */
1032#define MIPS_HFLAG_BL 0x01800 /* Likely branch */
1033#define MIPS_HFLAG_BR 0x02000 /* branch to register (can't link TB) */
1034 /* Extra flags about the current pending branch. */
b231c103 1035#define MIPS_HFLAG_BMASK_EXT 0x7C000
79ef2c4c
NF
1036#define MIPS_HFLAG_B16 0x04000 /* branch instruction was 16 bits */
1037#define MIPS_HFLAG_BDS16 0x08000 /* branch requires 16-bit delay slot */
1038#define MIPS_HFLAG_BDS32 0x10000 /* branch requires 32-bit delay slot */
b231c103
YK
1039#define MIPS_HFLAG_BDS_STRICT 0x20000 /* Strict delay slot size */
1040#define MIPS_HFLAG_BX 0x40000 /* branch exchanges execution mode */
79ef2c4c 1041#define MIPS_HFLAG_BMASK (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT)
853c3240 1042 /* MIPS DSP resources access. */
908f6be1
SM
1043#define MIPS_HFLAG_DSP 0x080000 /* Enable access to DSP resources. */
1044#define MIPS_HFLAG_DSP_R2 0x100000 /* Enable access to DSP R2 resources. */
1045#define MIPS_HFLAG_DSP_R3 0x20000000 /* Enable access to DSP R3 resources. */
d279279e 1046 /* Extra flag about HWREna register. */
b231c103 1047#define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */
faf1f68b 1048#define MIPS_HFLAG_SBRI 0x400000 /* R6 SDBBP causes RI excpt. in user mode */
339cd2a8 1049#define MIPS_HFLAG_FBNSLOT 0x800000 /* Forbidden slot */
e97a391d 1050#define MIPS_HFLAG_MSA 0x1000000
7c979afd 1051#define MIPS_HFLAG_FRE 0x2000000 /* FRE enabled */
e117f526 1052#define MIPS_HFLAG_ELPA 0x4000000
0d74a222 1053#define MIPS_HFLAG_ITC_CACHE 0x8000000 /* CACHE instr. operates on ITC tag */
42c86612 1054#define MIPS_HFLAG_ERL 0x10000000 /* error level flag */
6af0bf9c 1055 target_ulong btarget; /* Jump / branch target */
1ba74fb8 1056 target_ulong bcond; /* Branch condition (if needed) */
a316d335 1057
7a387fff
TS
1058 int SYNCI_Step; /* Address step size for SYNCI */
1059 int CCRes; /* Cycle count resolution/divisor */
ead9360e
TS
1060 uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */
1061 uint32_t CP0_TCStatus_rw_bitmask; /* Read/write bits in CP0_TCStatus */
f9c9cd63 1062 uint64_t insn_flags; /* Supported instruction set */
5fb2dcd1 1063 int saarp;
7a387fff 1064
1f5c00cf
AB
1065 /* Fields up to this point are cleared by a CPU reset */
1066 struct {} end_reset_fields;
1067
f0c3c505 1068 /* Fields from here on are preserved across CPU reset. */
51cc2e78 1069 CPUMIPSMVPContext *mvp;
3c7b48b7 1070#if !defined(CONFIG_USER_ONLY)
51cc2e78 1071 CPUMIPSTLBContext *tlb;
3c7b48b7 1072#endif
51cc2e78 1073
c227f099 1074 const mips_def_t *cpu_model;
33ac7f16 1075 void *irq[8];
1246b259 1076 QEMUTimer *timer; /* Internal timer */
043715d1 1077 struct MIPSITUState *itu;
34fa7e83 1078 MemoryRegion *itc_tag; /* ITC Configuration Tags */
89777fd1 1079 target_ulong exception_base; /* ExceptionBase input to the core */
6af0bf9c
FB
1080};
1081
416bf936
PB
1082/**
1083 * MIPSCPU:
1084 * @env: #CPUMIPSState
1085 *
1086 * A MIPS CPU.
1087 */
1088struct MIPSCPU {
1089 /*< private >*/
1090 CPUState parent_obj;
1091 /*< public >*/
1092
5b146dc7 1093 CPUNegativeOffsetState neg;
416bf936
PB
1094 CPUMIPSState env;
1095};
1096
416bf936 1097
0442428a 1098void mips_cpu_list(void);
647de6ca 1099
9467d44c 1100#define cpu_signal_handler cpu_mips_signal_handler
c732abe2 1101#define cpu_list mips_cpu_list
9467d44c 1102
084d0497
RH
1103extern void cpu_wrdsp(uint32_t rs, uint32_t mask_num, CPUMIPSState *env);
1104extern uint32_t cpu_rddsp(uint32_t mask_num, CPUMIPSState *env);
1105
9e72f33d
JI
1106/*
1107 * MMU modes definitions. We carefully match the indices with our
1108 * hflags layout.
1109 */
6ebbf390 1110#define MMU_MODE0_SUFFIX _kernel
623a930e
TS
1111#define MMU_MODE1_SUFFIX _super
1112#define MMU_MODE2_SUFFIX _user
42c86612 1113#define MMU_MODE3_SUFFIX _error
623a930e 1114#define MMU_USER_IDX 2
b0fc6003
JH
1115
1116static inline int hflags_mmu_index(uint32_t hflags)
1117{
42c86612
JH
1118 if (hflags & MIPS_HFLAG_ERL) {
1119 return 3; /* ERL */
1120 } else {
1121 return hflags & MIPS_HFLAG_KSU;
1122 }
b0fc6003
JH
1123}
1124
8ebf2e1a 1125static inline int cpu_mmu_index(CPUMIPSState *env, bool ifetch)
6ebbf390 1126{
b0fc6003 1127 return hflags_mmu_index(env->hflags);
6ebbf390
JM
1128}
1129
4f7c64b3 1130typedef CPUMIPSState CPUArchState;
2161a612 1131typedef MIPSCPU ArchCPU;
4f7c64b3 1132
022c62cb 1133#include "exec/cpu-all.h"
6af0bf9c 1134
9e72f33d
JI
1135/*
1136 * Memory access type :
6af0bf9c
FB
1137 * may be needed for precise access rights control and precise exceptions.
1138 */
1139enum {
1140 /* 1 bit to define user level / supervisor access */
1141 ACCESS_USER = 0x00,
1142 ACCESS_SUPER = 0x01,
1143 /* 1 bit to indicate direction */
1144 ACCESS_STORE = 0x02,
1145 /* Type of instruction that generated the access */
1146 ACCESS_CODE = 0x10, /* Code fetch access */
1147 ACCESS_INT = 0x20, /* Integer load/store access */
1148 ACCESS_FLOAT = 0x30, /* floating point load/store access */
1149};
1150
1151/* Exceptions */
1152enum {
1153 EXCP_NONE = -1,
1154 EXCP_RESET = 0,
1155 EXCP_SRESET,
1156 EXCP_DSS,
1157 EXCP_DINT,
14e51cc7
TS
1158 EXCP_DDBL,
1159 EXCP_DDBS,
6af0bf9c
FB
1160 EXCP_NMI,
1161 EXCP_MCHECK,
14e51cc7 1162 EXCP_EXT_INTERRUPT, /* 8 */
6af0bf9c 1163 EXCP_DFWATCH,
14e51cc7 1164 EXCP_DIB,
6af0bf9c
FB
1165 EXCP_IWATCH,
1166 EXCP_AdEL,
1167 EXCP_AdES,
1168 EXCP_TLBF,
1169 EXCP_IBE,
14e51cc7 1170 EXCP_DBp, /* 16 */
6af0bf9c 1171 EXCP_SYSCALL,
14e51cc7 1172 EXCP_BREAK,
4ad40f36 1173 EXCP_CpU,
6af0bf9c
FB
1174 EXCP_RI,
1175 EXCP_OVERFLOW,
1176 EXCP_TRAP,
5a5012ec 1177 EXCP_FPE,
14e51cc7 1178 EXCP_DWATCH, /* 24 */
6af0bf9c
FB
1179 EXCP_LTLBL,
1180 EXCP_TLBL,
1181 EXCP_TLBS,
1182 EXCP_DBE,
ead9360e 1183 EXCP_THREAD,
14e51cc7
TS
1184 EXCP_MDMX,
1185 EXCP_C2E,
1186 EXCP_CACHE, /* 32 */
853c3240 1187 EXCP_DSPDIS,
e97a391d
YK
1188 EXCP_MSADIS,
1189 EXCP_MSAFPE,
92ceb440
LA
1190 EXCP_TLBXI,
1191 EXCP_TLBRI,
14e51cc7 1192
92ceb440 1193 EXCP_LAST = EXCP_TLBRI,
6af0bf9c
FB
1194};
1195
f249412c 1196/*
26aa3d9a 1197 * This is an internally generated WAKE request line.
f249412c
EI
1198 * It is driven by the CPU itself. Raised when the MT
1199 * block wants to wake a VPE from an inactive state and
1200 * cleared when VPE goes from active to inactive.
1201 */
1202#define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0
1203
388bb21a 1204int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
6af0bf9c 1205
a7519f2b
IM
1206#define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
1207#define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
0dacec87 1208#define CPU_RESOLVING_TYPE TYPE_MIPS_CPU
a7519f2b
IM
1209
1210bool cpu_supports_cps_smp(const char *cpu_type);
5b1e0981 1211bool cpu_supports_isa(const char *cpu_type, uint64_t isa);
89777fd1 1212void cpu_set_exception_base(int vp_index, target_ulong address);
30bf942d 1213
5dc5d9f0 1214/* mips_int.c */
7db13fae 1215void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level);
5dc5d9f0 1216
043715d1
YK
1217/* mips_itu.c */
1218void itc_reconfigure(struct MIPSITUState *tag);
1219
f9480ffc 1220/* helper.c */
8ebf2e1a 1221target_ulong exception_resume_pc(CPUMIPSState *env);
f9480ffc 1222
7db13fae 1223static inline void cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc,
89fee74a 1224 target_ulong *cs_base, uint32_t *flags)
6b917547
AL
1225{
1226 *pc = env->active_tc.PC;
1227 *cs_base = 0;
d279279e
PJ
1228 *flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK |
1229 MIPS_HFLAG_HWRENA_ULR);
6b917547
AL
1230}
1231
07f5a258 1232#endif /* MIPS_CPU_H */