6 #define CPUArchState struct CPUMIPSState
8 #include "qemu-common.h"
10 #include "mips-defs.h"
11 #include "exec/cpu-defs.h"
12 #include "fpu/softfloat.h"
14 #define TCG_GUEST_DEFAULT_MO (0)
18 typedef struct CPUMIPSTLBContext CPUMIPSTLBContext
;
21 #define MSA_WRLEN (128)
23 typedef union wr_t wr_t
;
25 int8_t b
[MSA_WRLEN
/ 8];
26 int16_t h
[MSA_WRLEN
/ 16];
27 int32_t w
[MSA_WRLEN
/ 32];
28 int64_t d
[MSA_WRLEN
/ 64];
31 typedef union fpr_t fpr_t
;
33 float64 fd
; /* ieee double precision */
34 float32 fs
[2];/* ieee single precision */
35 uint64_t d
; /* binary double fixed-point */
36 uint32_t w
[2]; /* binary single fixed-point */
37 /* FPU/MSA register mapping is not tested on big-endian hosts. */
38 wr_t wr
; /* vector data */
41 *define FP_ENDIAN_IDX to access the same location
42 * in the fpr_t union regardless of the host endianness
44 #if defined(HOST_WORDS_BIGENDIAN)
45 # define FP_ENDIAN_IDX 1
47 # define FP_ENDIAN_IDX 0
50 typedef struct CPUMIPSFPUContext CPUMIPSFPUContext
;
51 struct CPUMIPSFPUContext
{
52 /* Floating point registers */
54 float_status fp_status
;
55 /* fpu implementation/revision register (fir) */
59 #define FCR0_HAS2008 23
70 uint32_t fcr31_rw_bitmask
;
73 #define FCR31_ABS2008 19
74 #define FCR31_NAN2008 18
75 #define SET_FP_COND(num, env) do { ((env).fcr31) |= \
76 ((num) ? (1 << ((num) + 24)) : \
79 #define CLEAR_FP_COND(num, env) do { ((env).fcr31) &= \
80 ~((num) ? (1 << ((num) + 24)) : \
83 #define GET_FP_COND(env) ((((env).fcr31 >> 24) & 0xfe) | \
84 (((env).fcr31 >> 23) & 0x1))
85 #define GET_FP_CAUSE(reg) (((reg) >> 12) & 0x3f)
86 #define GET_FP_ENABLE(reg) (((reg) >> 7) & 0x1f)
87 #define GET_FP_FLAGS(reg) (((reg) >> 2) & 0x1f)
88 #define SET_FP_CAUSE(reg, v) do { (reg) = ((reg) & ~(0x3f << 12)) | \
91 #define SET_FP_ENABLE(reg, v) do { (reg) = ((reg) & ~(0x1f << 7)) | \
94 #define SET_FP_FLAGS(reg, v) do { (reg) = ((reg) & ~(0x1f << 2)) | \
97 #define UPDATE_FP_FLAGS(reg, v) do { (reg) |= ((v & 0x1f) << 2); } while (0)
99 #define FP_UNDERFLOW 2
100 #define FP_OVERFLOW 4
102 #define FP_INVALID 16
103 #define FP_UNIMPLEMENTED 32
106 #define NB_MMU_MODES 4
107 #define TARGET_INSN_START_EXTRA_WORDS 2
109 typedef struct CPUMIPSMVPContext CPUMIPSMVPContext
;
110 struct CPUMIPSMVPContext
{
111 int32_t CP0_MVPControl
;
112 #define CP0MVPCo_CPA 3
113 #define CP0MVPCo_STLB 2
114 #define CP0MVPCo_VPC 1
115 #define CP0MVPCo_EVP 0
116 int32_t CP0_MVPConf0
;
117 #define CP0MVPC0_M 31
118 #define CP0MVPC0_TLBS 29
119 #define CP0MVPC0_GS 28
120 #define CP0MVPC0_PCP 27
121 #define CP0MVPC0_PTLBE 16
122 #define CP0MVPC0_TCA 15
123 #define CP0MVPC0_PVPE 10
124 #define CP0MVPC0_PTC 0
125 int32_t CP0_MVPConf1
;
126 #define CP0MVPC1_CIM 31
127 #define CP0MVPC1_CIF 30
128 #define CP0MVPC1_PCX 20
129 #define CP0MVPC1_PCP2 10
130 #define CP0MVPC1_PCP1 0
133 typedef struct mips_def_t mips_def_t
;
135 #define MIPS_SHADOW_SET_MAX 16
136 #define MIPS_TC_MAX 5
137 #define MIPS_FPU_MAX 1
138 #define MIPS_DSP_ACC 4
139 #define MIPS_KSCRATCH_NUM 6
140 #define MIPS_MAAR_MAX 16 /* Must be an even number. */
144 * Summary of CP0 registers
145 * ========================
148 * Register 0 Register 1 Register 2 Register 3
149 * ---------- ---------- ---------- ----------
151 * 0 Index Random EntryLo0 EntryLo1
152 * 1 MVPControl VPEControl TCStatus GlobalNumber
153 * 2 MVPConf0 VPEConf0 TCBind
154 * 3 MVPConf1 VPEConf1 TCRestart
155 * 4 VPControl YQMask TCHalt
156 * 5 VPESchedule TCContext
157 * 6 VPEScheFBack TCSchedule
158 * 7 VPEOpt TCScheFBack TCOpt
161 * Register 4 Register 5 Register 6 Register 7
162 * ---------- ---------- ---------- ----------
164 * 0 Context PageMask Wired HWREna
165 * 1 ContextConfig PageGrain SRSConf0
166 * 2 UserLocal SegCtl0 SRSConf1
167 * 3 XContextConfig SegCtl1 SRSConf2
168 * 4 DebugContextID SegCtl2 SRSConf3
169 * 5 MemoryMapID PWBase SRSConf4
174 * Register 8 Register 9 Register 10 Register 11
175 * ---------- ---------- ----------- -----------
177 * 0 BadVAddr Count EntryHi Compare
181 * 4 GuestCtl1 GuestCtl0Ext
187 * Register 12 Register 13 Register 14 Register 15
188 * ----------- ----------- ----------- -----------
190 * 0 Status Cause EPC PRId
192 * 2 SRSCtl NestedEPC CDMMBase
194 * 4 View_IPL View_RIPL BEVVA
195 * 5 SRSMap2 NestedExc
200 * Register 16 Register 17 Register 18 Register 19
201 * ----------- ----------- ----------- -----------
203 * 0 Config LLAddr WatchLo WatchHi
204 * 1 Config1 MAAR WatchLo WatchHi
205 * 2 Config2 MAARI WatchLo WatchHi
206 * 3 Config3 WatchLo WatchHi
207 * 4 Config4 WatchLo WatchHi
208 * 5 Config5 WatchLo WatchHi
213 * Register 20 Register 21 Register 22 Register 23
214 * ----------- ----------- ----------- -----------
226 * Register 24 Register 25 Register 26 Register 27
227 * ----------- ----------- ----------- -----------
229 * 0 DEPC PerfCnt ErrCtl CacheErr
231 * 2 TraceControl3 PerfCnt
232 * 3 UserTraceData2 PerfCnt
239 * Register 28 Register 29 Register 30 Register 31
240 * ----------- ----------- ----------- -----------
242 * 0 DataLo DataHi ErrorEPC DESAVE
244 * 2 DataLo DataHi KScratch<n>
245 * 3 TagLo TagHi KScratch<n>
246 * 4 DataLo DataHi KScratch<n>
247 * 5 TagLo TagHi KScratch<n>
248 * 6 DataLo DataHi KScratch<n>
249 * 7 TagLo TagHi KScratch<n>
252 #define CP0_REGISTER_00 0
253 #define CP0_REGISTER_01 1
254 #define CP0_REGISTER_02 2
255 #define CP0_REGISTER_03 3
256 #define CP0_REGISTER_04 4
257 #define CP0_REGISTER_05 5
258 #define CP0_REGISTER_06 6
259 #define CP0_REGISTER_07 7
260 #define CP0_REGISTER_08 8
261 #define CP0_REGISTER_09 9
262 #define CP0_REGISTER_10 10
263 #define CP0_REGISTER_11 11
264 #define CP0_REGISTER_12 12
265 #define CP0_REGISTER_13 13
266 #define CP0_REGISTER_14 14
267 #define CP0_REGISTER_15 15
268 #define CP0_REGISTER_16 16
269 #define CP0_REGISTER_17 17
270 #define CP0_REGISTER_18 18
271 #define CP0_REGISTER_19 19
272 #define CP0_REGISTER_20 20
273 #define CP0_REGISTER_21 21
274 #define CP0_REGISTER_22 22
275 #define CP0_REGISTER_23 23
276 #define CP0_REGISTER_24 24
277 #define CP0_REGISTER_25 25
278 #define CP0_REGISTER_26 26
279 #define CP0_REGISTER_27 27
280 #define CP0_REGISTER_28 28
281 #define CP0_REGISTER_29 29
282 #define CP0_REGISTER_30 30
283 #define CP0_REGISTER_31 31
286 /* CP0 Register 00 */
287 #define CP0_REG00__INDEX 0
288 #define CP0_REG00__VPCONTROL 4
289 /* CP0 Register 01 */
290 /* CP0 Register 02 */
291 #define CP0_REG02__ENTRYLO0 0
292 /* CP0 Register 03 */
293 #define CP0_REG03__ENTRYLO1 0
294 #define CP0_REG03__GLOBALNUM 1
295 /* CP0 Register 04 */
296 #define CP0_REG04__CONTEXT 0
297 #define CP0_REG04__USERLOCAL 2
298 #define CP0_REG04__DBGCONTEXTID 4
299 #define CP0_REG00__MMID 5
300 /* CP0 Register 05 */
301 #define CP0_REG05__PAGEMASK 0
302 #define CP0_REG05__PAGEGRAIN 1
303 /* CP0 Register 06 */
304 #define CP0_REG06__WIRED 0
305 /* CP0 Register 07 */
306 #define CP0_REG07__HWRENA 0
307 /* CP0 Register 08 */
308 #define CP0_REG08__BADVADDR 0
309 #define CP0_REG08__BADINSTR 1
310 #define CP0_REG08__BADINSTRP 2
311 /* CP0 Register 09 */
312 #define CP0_REG09__COUNT 0
313 #define CP0_REG09__SAARI 6
314 #define CP0_REG09__SAAR 7
315 /* CP0 Register 10 */
316 #define CP0_REG10__ENTRYHI 0
317 #define CP0_REG10__GUESTCTL1 4
318 #define CP0_REG10__GUESTCTL2 5
319 /* CP0 Register 11 */
320 #define CP0_REG11__COMPARE 0
321 #define CP0_REG11__GUESTCTL0EXT 4
322 /* CP0 Register 12 */
323 #define CP0_REG12__STATUS 0
324 #define CP0_REG12__INTCTL 1
325 #define CP0_REG12__SRSCTL 2
326 #define CP0_REG12__GUESTCTL0 6
327 #define CP0_REG12__GTOFFSET 7
328 /* CP0 Register 13 */
329 #define CP0_REG13__CAUSE 0
330 /* CP0 Register 14 */
331 #define CP0_REG14__EPC 0
332 /* CP0 Register 15 */
333 #define CP0_REG15__PRID 0
334 #define CP0_REG15__EBASE 1
335 #define CP0_REG15__CDMMBASE 2
336 #define CP0_REG15__CMGCRBASE 3
337 /* CP0 Register 16 */
338 #define CP0_REG16__CONFIG 0
339 #define CP0_REG16__CONFIG1 1
340 #define CP0_REG16__CONFIG2 2
341 #define CP0_REG16__CONFIG3 3
342 #define CP0_REG16__CONFIG4 4
343 #define CP0_REG16__CONFIG5 5
344 #define CP0_REG00__CONFIG7 7
345 /* CP0 Register 17 */
346 #define CP0_REG17__LLADDR 0
347 #define CP0_REG17__MAAR 1
348 #define CP0_REG17__MAARI 2
349 /* CP0 Register 18 */
350 #define CP0_REG18__WATCHLO0 0
351 #define CP0_REG18__WATCHLO1 1
352 #define CP0_REG18__WATCHLO2 2
353 #define CP0_REG18__WATCHLO3 3
354 /* CP0 Register 19 */
355 #define CP0_REG19__WATCHHI0 0
356 #define CP0_REG19__WATCHHI1 1
357 #define CP0_REG19__WATCHHI2 2
358 #define CP0_REG19__WATCHHI3 3
359 /* CP0 Register 20 */
360 #define CP0_REG20__XCONTEXT 0
361 /* CP0 Register 21 */
362 /* CP0 Register 22 */
363 /* CP0 Register 23 */
364 #define CP0_REG23__DEBUG 0
365 /* CP0 Register 24 */
366 #define CP0_REG24__DEPC 0
367 /* CP0 Register 25 */
368 #define CP0_REG25__PERFCTL0 0
369 #define CP0_REG25__PERFCNT0 1
370 #define CP0_REG25__PERFCTL1 2
371 #define CP0_REG25__PERFCNT1 3
372 #define CP0_REG25__PERFCTL2 4
373 #define CP0_REG25__PERFCNT2 5
374 #define CP0_REG25__PERFCTL3 6
375 #define CP0_REG25__PERFCNT3 7
376 /* CP0 Register 26 */
377 #define CP0_REG00__ERRCTL 0
378 /* CP0 Register 27 */
379 #define CP0_REG27__CACHERR 0
380 /* CP0 Register 28 */
381 #define CP0_REG28__ITAGLO 0
382 #define CP0_REG28__IDATALO 1
383 #define CP0_REG28__DTAGLO 2
384 #define CP0_REG28__DDATALO 3
385 /* CP0 Register 29 */
386 #define CP0_REG29__IDATAHI 1
387 #define CP0_REG29__DDATAHI 3
388 /* CP0 Register 30 */
389 #define CP0_REG30__ERROREPC 0
390 /* CP0 Register 31 */
391 #define CP0_REG31__DESAVE 0
392 #define CP0_REG31__KSCRATCH1 2
393 #define CP0_REG31__KSCRATCH2 3
394 #define CP0_REG31__KSCRATCH3 4
395 #define CP0_REG31__KSCRATCH4 5
396 #define CP0_REG31__KSCRATCH5 6
397 #define CP0_REG31__KSCRATCH6 7
400 typedef struct TCState TCState
;
402 target_ulong gpr
[32];
404 target_ulong HI
[MIPS_DSP_ACC
];
405 target_ulong LO
[MIPS_DSP_ACC
];
406 target_ulong ACX
[MIPS_DSP_ACC
];
407 target_ulong DSPControl
;
408 int32_t CP0_TCStatus
;
409 #define CP0TCSt_TCU3 31
410 #define CP0TCSt_TCU2 30
411 #define CP0TCSt_TCU1 29
412 #define CP0TCSt_TCU0 28
413 #define CP0TCSt_TMX 27
414 #define CP0TCSt_RNST 23
415 #define CP0TCSt_TDS 21
416 #define CP0TCSt_DT 20
417 #define CP0TCSt_DA 15
419 #define CP0TCSt_TKSU 11
420 #define CP0TCSt_IXMT 10
421 #define CP0TCSt_TASID 0
423 #define CP0TCBd_CurTC 21
424 #define CP0TCBd_TBE 17
425 #define CP0TCBd_CurVPE 0
426 target_ulong CP0_TCHalt
;
427 target_ulong CP0_TCContext
;
428 target_ulong CP0_TCSchedule
;
429 target_ulong CP0_TCScheFBack
;
430 int32_t CP0_Debug_tcstatus
;
431 target_ulong CP0_UserLocal
;
436 #define MSACSR_FS_MASK (1 << MSACSR_FS)
438 #define MSACSR_NX_MASK (1 << MSACSR_NX)
440 #define MSACSR_CEF_MASK (0xffff << MSACSR_CEF)
442 #define MSACSR_RM_MASK (0x3 << MSACSR_RM)
443 #define MSACSR_MASK (MSACSR_RM_MASK | MSACSR_CEF_MASK | MSACSR_NX_MASK | \
446 float_status msa_fp_status
;
448 /* Upper 64-bit MMRs (multimedia registers); the lower 64-bit are GPRs */
451 #define NUMBER_OF_MXU_REGISTERS 16
452 target_ulong mxu_gpr
[NUMBER_OF_MXU_REGISTERS
- 1];
456 #define MXU_CR_BIAS 2
457 #define MXU_CR_RD_EN 1
458 #define MXU_CR_MXU_EN 0
463 typedef struct CPUMIPSState CPUMIPSState
;
464 struct CPUMIPSState
{
466 CPUMIPSFPUContext active_fpu
;
469 uint32_t current_fpu
;
473 #if defined(TARGET_MIPS64)
474 # define PABITS_BASE 36
476 # define PABITS_BASE 32
478 target_ulong SEGMask
;
480 #define PAMASK_BASE ((1ULL << PABITS_BASE) - 1)
483 #define MSAIR_ProcID 8
490 /* CP0_MVP* are per MVP registers. */
491 int32_t CP0_VPControl
;
492 #define CP0VPCtl_DIS 0
497 int32_t CP0_VPEControl
;
498 #define CP0VPECo_YSI 21
499 #define CP0VPECo_GSI 20
500 #define CP0VPECo_EXCPT 16
501 #define CP0VPECo_TE 15
502 #define CP0VPECo_TargTC 0
503 int32_t CP0_VPEConf0
;
504 #define CP0VPEC0_M 31
505 #define CP0VPEC0_XTC 21
506 #define CP0VPEC0_TCS 19
507 #define CP0VPEC0_SCS 18
508 #define CP0VPEC0_DSC 17
509 #define CP0VPEC0_ICS 16
510 #define CP0VPEC0_MVP 1
511 #define CP0VPEC0_VPA 0
512 int32_t CP0_VPEConf1
;
513 #define CP0VPEC1_NCX 20
514 #define CP0VPEC1_NCP2 10
515 #define CP0VPEC1_NCP1 0
516 target_ulong CP0_YQMask
;
517 target_ulong CP0_VPESchedule
;
518 target_ulong CP0_VPEScheFBack
;
520 #define CP0VPEOpt_IWX7 15
521 #define CP0VPEOpt_IWX6 14
522 #define CP0VPEOpt_IWX5 13
523 #define CP0VPEOpt_IWX4 12
524 #define CP0VPEOpt_IWX3 11
525 #define CP0VPEOpt_IWX2 10
526 #define CP0VPEOpt_IWX1 9
527 #define CP0VPEOpt_IWX0 8
528 #define CP0VPEOpt_DWX7 7
529 #define CP0VPEOpt_DWX6 6
530 #define CP0VPEOpt_DWX5 5
531 #define CP0VPEOpt_DWX4 4
532 #define CP0VPEOpt_DWX3 3
533 #define CP0VPEOpt_DWX2 2
534 #define CP0VPEOpt_DWX1 1
535 #define CP0VPEOpt_DWX0 0
539 uint64_t CP0_EntryLo0
;
543 uint64_t CP0_EntryLo1
;
544 #if defined(TARGET_MIPS64)
545 # define CP0EnLo_RI 63
546 # define CP0EnLo_XI 62
548 # define CP0EnLo_RI 31
549 # define CP0EnLo_XI 30
551 int32_t CP0_GlobalNumber
;
556 target_ulong CP0_Context
;
557 target_ulong CP0_KScratch
[MIPS_KSCRATCH_NUM
];
558 int32_t CP0_MemoryMapID
;
562 int32_t CP0_PageMask
;
563 int32_t CP0_PageGrain_rw_bitmask
;
564 int32_t CP0_PageGrain
;
567 #define CP0PG_ELPA 29
569 target_ulong CP0_SegCtl0
;
570 target_ulong CP0_SegCtl1
;
571 target_ulong CP0_SegCtl2
;
573 #define CP0SC_PA_MASK (0x7FULL << CP0SC_PA)
574 #define CP0SC_PA_1GMASK (0x7EULL << CP0SC_PA)
576 #define CP0SC_AM_MASK (0x7ULL << CP0SC_AM)
577 #define CP0SC_AM_UK 0ULL
578 #define CP0SC_AM_MK 1ULL
579 #define CP0SC_AM_MSK 2ULL
580 #define CP0SC_AM_MUSK 3ULL
581 #define CP0SC_AM_MUSUK 4ULL
582 #define CP0SC_AM_USK 5ULL
583 #define CP0SC_AM_UUSK 7ULL
585 #define CP0SC_EU_MASK (1ULL << CP0SC_EU)
587 #define CP0SC_C_MASK (0x7ULL << CP0SC_C)
588 #define CP0SC_MASK (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
590 #define CP0SC_1GMASK (CP0SC_C_MASK | CP0SC_EU_MASK | CP0SC_AM_MASK | \
592 #define CP0SC0_MASK (CP0SC_MASK | (CP0SC_MASK << 16))
593 #define CP0SC1_XAM 59
594 #define CP0SC1_XAM_MASK (0x7ULL << CP0SC1_XAM)
595 #define CP0SC1_MASK (CP0SC_MASK | (CP0SC_MASK << 16) | CP0SC1_XAM_MASK)
597 #define CP0SC2_XR_MASK (0xFFULL << CP0SC2_XR)
598 #define CP0SC2_MASK (CP0SC_1GMASK | (CP0SC_1GMASK << 16) | CP0SC2_XR_MASK)
599 target_ulong CP0_PWBase
;
600 target_ulong CP0_PWField
;
601 #if defined(TARGET_MIPS64)
602 #define CP0PF_BDI 32 /* 37..32 */
603 #define CP0PF_GDI 24 /* 29..24 */
604 #define CP0PF_UDI 18 /* 23..18 */
605 #define CP0PF_MDI 12 /* 17..12 */
606 #define CP0PF_PTI 6 /* 11..6 */
607 #define CP0PF_PTEI 0 /* 5..0 */
609 #define CP0PF_GDW 24 /* 29..24 */
610 #define CP0PF_UDW 18 /* 23..18 */
611 #define CP0PF_MDW 12 /* 17..12 */
612 #define CP0PF_PTW 6 /* 11..6 */
613 #define CP0PF_PTEW 0 /* 5..0 */
615 target_ulong CP0_PWSize
;
616 #if defined(TARGET_MIPS64)
617 #define CP0PS_BDW 32 /* 37..32 */
620 #define CP0PS_GDW 24 /* 29..24 */
621 #define CP0PS_UDW 18 /* 23..18 */
622 #define CP0PS_MDW 12 /* 17..12 */
623 #define CP0PS_PTW 6 /* 11..6 */
624 #define CP0PS_PTEW 0 /* 5..0 */
630 #define CP0PC_PWEN 31
631 #if defined(TARGET_MIPS64)
632 #define CP0PC_PWDIREXT 30
638 #define CP0PC_HUGEPG 6
639 #define CP0PC_PSN 0 /* 5..0 */
640 int32_t CP0_SRSConf0_rw_bitmask
;
641 int32_t CP0_SRSConf0
;
642 #define CP0SRSC0_M 31
643 #define CP0SRSC0_SRS3 20
644 #define CP0SRSC0_SRS2 10
645 #define CP0SRSC0_SRS1 0
646 int32_t CP0_SRSConf1_rw_bitmask
;
647 int32_t CP0_SRSConf1
;
648 #define CP0SRSC1_M 31
649 #define CP0SRSC1_SRS6 20
650 #define CP0SRSC1_SRS5 10
651 #define CP0SRSC1_SRS4 0
652 int32_t CP0_SRSConf2_rw_bitmask
;
653 int32_t CP0_SRSConf2
;
654 #define CP0SRSC2_M 31
655 #define CP0SRSC2_SRS9 20
656 #define CP0SRSC2_SRS8 10
657 #define CP0SRSC2_SRS7 0
658 int32_t CP0_SRSConf3_rw_bitmask
;
659 int32_t CP0_SRSConf3
;
660 #define CP0SRSC3_M 31
661 #define CP0SRSC3_SRS12 20
662 #define CP0SRSC3_SRS11 10
663 #define CP0SRSC3_SRS10 0
664 int32_t CP0_SRSConf4_rw_bitmask
;
665 int32_t CP0_SRSConf4
;
666 #define CP0SRSC4_SRS15 20
667 #define CP0SRSC4_SRS14 10
668 #define CP0SRSC4_SRS13 0
676 target_ulong CP0_BadVAddr
;
677 uint32_t CP0_BadInstr
;
678 uint32_t CP0_BadInstrP
;
679 uint32_t CP0_BadInstrX
;
685 #define CP0SAARI_TARGET 0 /* 5..0 */
686 uint64_t CP0_SAAR
[2];
687 #define CP0SAAR_BASE 12 /* 43..12 */
688 #define CP0SAAR_SIZE 1 /* 5..1 */
693 target_ulong CP0_EntryHi
;
694 #define CP0EnHi_EHINV 10
695 target_ulong CP0_EntryHi_ASID_mask
;
726 #define CP0IntCtl_IPTI 29
727 #define CP0IntCtl_IPPCI 26
728 #define CP0IntCtl_VS 5
730 #define CP0SRSCtl_HSS 26
731 #define CP0SRSCtl_EICSS 18
732 #define CP0SRSCtl_ESS 12
733 #define CP0SRSCtl_PSS 6
734 #define CP0SRSCtl_CSS 0
736 #define CP0SRSMap_SSV7 28
737 #define CP0SRSMap_SSV6 24
738 #define CP0SRSMap_SSV5 20
739 #define CP0SRSMap_SSV4 16
740 #define CP0SRSMap_SSV3 12
741 #define CP0SRSMap_SSV2 8
742 #define CP0SRSMap_SSV1 4
743 #define CP0SRSMap_SSV0 0
756 #define CP0Ca_IP_mask 0x0000FF00
761 target_ulong CP0_EPC
;
766 target_ulong CP0_EBase
;
767 target_ulong CP0_EBaseWG_rw_bitmask
;
768 #define CP0EBase_WG 11
769 target_ulong CP0_CMGCRBase
;
775 #define CP0C0_K23 28 /* 30..28 */
776 #define CP0C0_KU 25 /* 27..25 */
780 #define CP0C0_Impl 16 /* 24..16 */
782 #define CP0C0_AT 13 /* 14..13 */
783 #define CP0C0_AR 10 /* 12..10 */
784 #define CP0C0_MT 7 /* 9..7 */
786 #define CP0C0_K0 0 /* 2..0 */
789 #define CP0C1_MMU 25 /* 30..25 */
790 #define CP0C1_IS 22 /* 24..22 */
791 #define CP0C1_IL 19 /* 21..19 */
792 #define CP0C1_IA 16 /* 18..16 */
793 #define CP0C1_DS 13 /* 15..13 */
794 #define CP0C1_DL 10 /* 12..10 */
795 #define CP0C1_DA 7 /* 9..7 */
805 #define CP0C2_TU 28 /* 30..28 */
806 #define CP0C2_TS 24 /* 27..24 */
807 #define CP0C2_TL 20 /* 23..20 */
808 #define CP0C2_TA 16 /* 19..16 */
809 #define CP0C2_SU 12 /* 15..12 */
810 #define CP0C2_SS 8 /* 11..8 */
811 #define CP0C2_SL 4 /* 7..4 */
812 #define CP0C2_SA 0 /* 3..0 */
816 #define CP0C3_CMGCR 29
817 #define CP0C3_MSAP 28
823 #define CP0C3_IPLV 21 /* 22..21 */
824 #define CP0C3_MMAR 18 /* 20..18 */
826 #define CP0C3_ISA_ON_EXC 16
827 #define CP0C3_ISA 14 /* 15..14 */
828 #define CP0C3_ULRI 13
830 #define CP0C3_DSP2P 11
831 #define CP0C3_DSPP 10
832 #define CP0C3_CTXTC 9
843 int32_t CP0_Config4_rw_bitmask
;
845 #define CP0C4_IE 29 /* 30..29 */
847 #define CP0C4_VTLBSizeExt 24 /* 27..24 */
848 #define CP0C4_KScrExist 16
849 #define CP0C4_MMUExtDef 14
850 #define CP0C4_FTLBPageSize 8 /* 12..8 */
851 /* bit layout if MMUExtDef=1 */
852 #define CP0C4_MMUSizeExt 0 /* 7..0 */
853 /* bit layout if MMUExtDef=2 */
854 #define CP0C4_FTLBWays 4 /* 7..4 */
855 #define CP0C4_FTLBSets 0 /* 3..0 */
857 int32_t CP0_Config5_rw_bitmask
;
862 #define CP0C5_MSAEn 27
863 #define CP0C5_PMJ 23 /* 25..23 */
868 #define CP0C5_CRCP 18
870 #define CP0C5_GI 15 /* 16..15 */
883 #define CP0C5_NFExists 0
887 uint64_t CP0_MAAR
[MIPS_MAAR_MAX
];
889 /* XXX: Maybe make LLAddr per-TC? */
893 target_ulong lladdr
; /* LL virtual address compared against SC */
896 uint32_t llnewval_wp
;
897 uint64_t CP0_LLAddr_rw_bitmask
;
898 int CP0_LLAddr_shift
;
902 target_ulong CP0_WatchLo
[8];
906 int32_t CP0_WatchHi
[8];
907 #define CP0WH_ASID 16
911 target_ulong CP0_XContext
;
912 int32_t CP0_Framemask
;
919 #define CP0DB_LSNM 28
920 #define CP0DB_Doze 27
921 #define CP0DB_Halt 26
923 #define CP0DB_IBEP 24
924 #define CP0DB_DBEP 21
925 #define CP0DB_IEXI 20
938 target_ulong CP0_DEPC
;
942 int32_t CP0_Performance0
;
963 target_ulong CP0_ErrorEPC
;
969 /* We waste some space so we can handle shadow registers like TCs. */
970 TCState tcs
[MIPS_SHADOW_SET_MAX
];
971 CPUMIPSFPUContext fpus
[MIPS_FPU_MAX
];
974 #define EXCP_TLB_NOMATCH 0x1
975 #define EXCP_INST_NOTAVAIL 0x2 /* No valid instruction word for BadInstr */
976 uint32_t hflags
; /* CPU State */
977 /* TMASK defines different execution modes */
978 #define MIPS_HFLAG_TMASK 0x1F5807FF
979 #define MIPS_HFLAG_MODE 0x00007 /* execution modes */
981 * The KSU flags must be the lowest bits in hflags. The flag order
982 * must be the same as defined for CP0 Status. This allows to use
983 * the bits as the value of mmu_idx.
985 #define MIPS_HFLAG_KSU 0x00003 /* kernel/supervisor/user mode mask */
986 #define MIPS_HFLAG_UM 0x00002 /* user mode flag */
987 #define MIPS_HFLAG_SM 0x00001 /* supervisor mode flag */
988 #define MIPS_HFLAG_KM 0x00000 /* kernel mode flag */
989 #define MIPS_HFLAG_DM 0x00004 /* Debug mode */
990 #define MIPS_HFLAG_64 0x00008 /* 64-bit instructions enabled */
991 #define MIPS_HFLAG_CP0 0x00010 /* CP0 enabled */
992 #define MIPS_HFLAG_FPU 0x00020 /* FPU enabled */
993 #define MIPS_HFLAG_F64 0x00040 /* 64-bit FPU enabled */
995 * True if the MIPS IV COP1X instructions can be used. This also
996 * controls the non-COP1X instructions RECIP.S, RECIP.D, RSQRT.S
999 #define MIPS_HFLAG_COP1X 0x00080 /* COP1X instructions enabled */
1000 #define MIPS_HFLAG_RE 0x00100 /* Reversed endianness */
1001 #define MIPS_HFLAG_AWRAP 0x00200 /* 32-bit compatibility address wrapping */
1002 #define MIPS_HFLAG_M16 0x00400 /* MIPS16 mode flag */
1003 #define MIPS_HFLAG_M16_SHIFT 10
1005 * If translation is interrupted between the branch instruction and
1006 * the delay slot, record what type of branch it is so that we can
1007 * resume translation properly. It might be possible to reduce
1008 * this from three bits to two.
1010 #define MIPS_HFLAG_BMASK_BASE 0x803800
1011 #define MIPS_HFLAG_B 0x00800 /* Unconditional branch */
1012 #define MIPS_HFLAG_BC 0x01000 /* Conditional branch */
1013 #define MIPS_HFLAG_BL 0x01800 /* Likely branch */
1014 #define MIPS_HFLAG_BR 0x02000 /* branch to register (can't link TB) */
1015 /* Extra flags about the current pending branch. */
1016 #define MIPS_HFLAG_BMASK_EXT 0x7C000
1017 #define MIPS_HFLAG_B16 0x04000 /* branch instruction was 16 bits */
1018 #define MIPS_HFLAG_BDS16 0x08000 /* branch requires 16-bit delay slot */
1019 #define MIPS_HFLAG_BDS32 0x10000 /* branch requires 32-bit delay slot */
1020 #define MIPS_HFLAG_BDS_STRICT 0x20000 /* Strict delay slot size */
1021 #define MIPS_HFLAG_BX 0x40000 /* branch exchanges execution mode */
1022 #define MIPS_HFLAG_BMASK (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT)
1023 /* MIPS DSP resources access. */
1024 #define MIPS_HFLAG_DSP 0x080000 /* Enable access to DSP resources. */
1025 #define MIPS_HFLAG_DSP_R2 0x100000 /* Enable access to DSP R2 resources. */
1026 #define MIPS_HFLAG_DSP_R3 0x20000000 /* Enable access to DSP R3 resources. */
1027 /* Extra flag about HWREna register. */
1028 #define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */
1029 #define MIPS_HFLAG_SBRI 0x400000 /* R6 SDBBP causes RI excpt. in user mode */
1030 #define MIPS_HFLAG_FBNSLOT 0x800000 /* Forbidden slot */
1031 #define MIPS_HFLAG_MSA 0x1000000
1032 #define MIPS_HFLAG_FRE 0x2000000 /* FRE enabled */
1033 #define MIPS_HFLAG_ELPA 0x4000000
1034 #define MIPS_HFLAG_ITC_CACHE 0x8000000 /* CACHE instr. operates on ITC tag */
1035 #define MIPS_HFLAG_ERL 0x10000000 /* error level flag */
1036 target_ulong btarget
; /* Jump / branch target */
1037 target_ulong bcond
; /* Branch condition (if needed) */
1039 int SYNCI_Step
; /* Address step size for SYNCI */
1040 int CCRes
; /* Cycle count resolution/divisor */
1041 uint32_t CP0_Status_rw_bitmask
; /* Read/write bits in CP0_Status */
1042 uint32_t CP0_TCStatus_rw_bitmask
; /* Read/write bits in CP0_TCStatus */
1043 uint64_t insn_flags
; /* Supported instruction set */
1046 /* Fields up to this point are cleared by a CPU reset */
1047 struct {} end_reset_fields
;
1051 /* Fields from here on are preserved across CPU reset. */
1052 CPUMIPSMVPContext
*mvp
;
1053 #if !defined(CONFIG_USER_ONLY)
1054 CPUMIPSTLBContext
*tlb
;
1057 const mips_def_t
*cpu_model
;
1059 QEMUTimer
*timer
; /* Internal timer */
1060 struct MIPSITUState
*itu
;
1061 MemoryRegion
*itc_tag
; /* ITC Configuration Tags */
1062 target_ulong exception_base
; /* ExceptionBase input to the core */
1067 * @env: #CPUMIPSState
1073 CPUState parent_obj
;
1079 static inline MIPSCPU
*mips_env_get_cpu(CPUMIPSState
*env
)
1081 return container_of(env
, MIPSCPU
, env
);
1084 #define ENV_GET_CPU(e) CPU(mips_env_get_cpu(e))
1086 #define ENV_OFFSET offsetof(MIPSCPU, env)
1088 void mips_cpu_list(void);
1090 #define cpu_signal_handler cpu_mips_signal_handler
1091 #define cpu_list mips_cpu_list
1093 extern void cpu_wrdsp(uint32_t rs
, uint32_t mask_num
, CPUMIPSState
*env
);
1094 extern uint32_t cpu_rddsp(uint32_t mask_num
, CPUMIPSState
*env
);
1097 * MMU modes definitions. We carefully match the indices with our
1100 #define MMU_MODE0_SUFFIX _kernel
1101 #define MMU_MODE1_SUFFIX _super
1102 #define MMU_MODE2_SUFFIX _user
1103 #define MMU_MODE3_SUFFIX _error
1104 #define MMU_USER_IDX 2
1106 static inline int hflags_mmu_index(uint32_t hflags
)
1108 if (hflags
& MIPS_HFLAG_ERL
) {
1111 return hflags
& MIPS_HFLAG_KSU
;
1115 static inline int cpu_mmu_index(CPUMIPSState
*env
, bool ifetch
)
1117 return hflags_mmu_index(env
->hflags
);
1120 #include "exec/cpu-all.h"
1123 * Memory access type :
1124 * may be needed for precise access rights control and precise exceptions.
1127 /* 1 bit to define user level / supervisor access */
1129 ACCESS_SUPER
= 0x01,
1130 /* 1 bit to indicate direction */
1131 ACCESS_STORE
= 0x02,
1132 /* Type of instruction that generated the access */
1133 ACCESS_CODE
= 0x10, /* Code fetch access */
1134 ACCESS_INT
= 0x20, /* Integer load/store access */
1135 ACCESS_FLOAT
= 0x30, /* floating point load/store access */
1149 EXCP_EXT_INTERRUPT
, /* 8 */
1165 EXCP_DWATCH
, /* 24 */
1173 EXCP_CACHE
, /* 32 */
1180 EXCP_LAST
= EXCP_TLBRI
,
1184 * This is an internally generated WAKE request line.
1185 * It is driven by the CPU itself. Raised when the MT
1186 * block wants to wake a VPE from an inactive state and
1187 * cleared when VPE goes from active to inactive.
1189 #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0
1191 int cpu_mips_signal_handler(int host_signum
, void *pinfo
, void *puc
);
1193 #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
1194 #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
1195 #define CPU_RESOLVING_TYPE TYPE_MIPS_CPU
1197 bool cpu_supports_cps_smp(const char *cpu_type
);
1198 bool cpu_supports_isa(const char *cpu_type
, uint64_t isa
);
1199 void cpu_set_exception_base(int vp_index
, target_ulong address
);
1202 void cpu_mips_soft_irq(CPUMIPSState
*env
, int irq
, int level
);
1205 void itc_reconfigure(struct MIPSITUState
*tag
);
1208 target_ulong
exception_resume_pc(CPUMIPSState
*env
);
1210 static inline void restore_snan_bit_mode(CPUMIPSState
*env
)
1212 set_snan_bit_is_one((env
->active_fpu
.fcr31
& (1 << FCR31_NAN2008
)) == 0,
1213 &env
->active_fpu
.fp_status
);
1216 static inline void cpu_get_tb_cpu_state(CPUMIPSState
*env
, target_ulong
*pc
,
1217 target_ulong
*cs_base
, uint32_t *flags
)
1219 *pc
= env
->active_tc
.PC
;
1221 *flags
= env
->hflags
& (MIPS_HFLAG_TMASK
| MIPS_HFLAG_BMASK
|
1222 MIPS_HFLAG_HWRENA_ULR
);
1225 #endif /* MIPS_CPU_H */