]> Git Repo - qemu.git/blob - target-mips/cpu.h
target-mips: add new Read-Inhibit and Execute-Inhibit exceptions
[qemu.git] / target-mips / cpu.h
1 #if !defined (__MIPS_CPU_H__)
2 #define __MIPS_CPU_H__
3
4 //#define DEBUG_OP
5
6 #define ALIGNED_ONLY
7 #define TARGET_HAS_ICE 1
8
9 #define ELF_MACHINE     EM_MIPS
10
11 #define CPUArchState struct CPUMIPSState
12
13 #include "config.h"
14 #include "qemu-common.h"
15 #include "mips-defs.h"
16 #include "exec/cpu-defs.h"
17 #include "fpu/softfloat.h"
18
19 struct CPUMIPSState;
20
21 typedef struct r4k_tlb_t r4k_tlb_t;
22 struct r4k_tlb_t {
23     target_ulong VPN;
24     uint32_t PageMask;
25     uint_fast8_t ASID;
26     uint_fast16_t G:1;
27     uint_fast16_t C0:3;
28     uint_fast16_t C1:3;
29     uint_fast16_t V0:1;
30     uint_fast16_t V1:1;
31     uint_fast16_t D0:1;
32     uint_fast16_t D1:1;
33     uint_fast16_t XI0:1;
34     uint_fast16_t XI1:1;
35     uint_fast16_t RI0:1;
36     uint_fast16_t RI1:1;
37     target_ulong PFN[2];
38 };
39
40 #if !defined(CONFIG_USER_ONLY)
41 typedef struct CPUMIPSTLBContext CPUMIPSTLBContext;
42 struct CPUMIPSTLBContext {
43     uint32_t nb_tlb;
44     uint32_t tlb_in_use;
45     int (*map_address) (struct CPUMIPSState *env, hwaddr *physical, int *prot, target_ulong address, int rw, int access_type);
46     void (*helper_tlbwi)(struct CPUMIPSState *env);
47     void (*helper_tlbwr)(struct CPUMIPSState *env);
48     void (*helper_tlbp)(struct CPUMIPSState *env);
49     void (*helper_tlbr)(struct CPUMIPSState *env);
50     union {
51         struct {
52             r4k_tlb_t tlb[MIPS_TLB_MAX];
53         } r4k;
54     } mmu;
55 };
56 #endif
57
58 typedef union fpr_t fpr_t;
59 union fpr_t {
60     float64  fd;   /* ieee double precision */
61     float32  fs[2];/* ieee single precision */
62     uint64_t d;    /* binary double fixed-point */
63     uint32_t w[2]; /* binary single fixed-point */
64 };
65 /* define FP_ENDIAN_IDX to access the same location
66  * in the fpr_t union regardless of the host endianness
67  */
68 #if defined(HOST_WORDS_BIGENDIAN)
69 #  define FP_ENDIAN_IDX 1
70 #else
71 #  define FP_ENDIAN_IDX 0
72 #endif
73
74 typedef struct CPUMIPSFPUContext CPUMIPSFPUContext;
75 struct CPUMIPSFPUContext {
76     /* Floating point registers */
77     fpr_t fpr[32];
78     float_status fp_status;
79     /* fpu implementation/revision register (fir) */
80     uint32_t fcr0;
81 #define FCR0_UFRP 28
82 #define FCR0_F64 22
83 #define FCR0_L 21
84 #define FCR0_W 20
85 #define FCR0_3D 19
86 #define FCR0_PS 18
87 #define FCR0_D 17
88 #define FCR0_S 16
89 #define FCR0_PRID 8
90 #define FCR0_REV 0
91     /* fcsr */
92     uint32_t fcr31;
93 #define SET_FP_COND(num,env)     do { ((env).fcr31) |= ((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
94 #define CLEAR_FP_COND(num,env)   do { ((env).fcr31) &= ~((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
95 #define GET_FP_COND(env)         ((((env).fcr31 >> 24) & 0xfe) | (((env).fcr31 >> 23) & 0x1))
96 #define GET_FP_CAUSE(reg)        (((reg) >> 12) & 0x3f)
97 #define GET_FP_ENABLE(reg)       (((reg) >>  7) & 0x1f)
98 #define GET_FP_FLAGS(reg)        (((reg) >>  2) & 0x1f)
99 #define SET_FP_CAUSE(reg,v)      do { (reg) = ((reg) & ~(0x3f << 12)) | ((v & 0x3f) << 12); } while(0)
100 #define SET_FP_ENABLE(reg,v)     do { (reg) = ((reg) & ~(0x1f <<  7)) | ((v & 0x1f) << 7); } while(0)
101 #define SET_FP_FLAGS(reg,v)      do { (reg) = ((reg) & ~(0x1f <<  2)) | ((v & 0x1f) << 2); } while(0)
102 #define UPDATE_FP_FLAGS(reg,v)   do { (reg) |= ((v & 0x1f) << 2); } while(0)
103 #define FP_INEXACT        1
104 #define FP_UNDERFLOW      2
105 #define FP_OVERFLOW       4
106 #define FP_DIV0           8
107 #define FP_INVALID        16
108 #define FP_UNIMPLEMENTED  32
109 };
110
111 #define NB_MMU_MODES 3
112
113 typedef struct CPUMIPSMVPContext CPUMIPSMVPContext;
114 struct CPUMIPSMVPContext {
115     int32_t CP0_MVPControl;
116 #define CP0MVPCo_CPA    3
117 #define CP0MVPCo_STLB   2
118 #define CP0MVPCo_VPC    1
119 #define CP0MVPCo_EVP    0
120     int32_t CP0_MVPConf0;
121 #define CP0MVPC0_M      31
122 #define CP0MVPC0_TLBS   29
123 #define CP0MVPC0_GS     28
124 #define CP0MVPC0_PCP    27
125 #define CP0MVPC0_PTLBE  16
126 #define CP0MVPC0_TCA    15
127 #define CP0MVPC0_PVPE   10
128 #define CP0MVPC0_PTC    0
129     int32_t CP0_MVPConf1;
130 #define CP0MVPC1_CIM    31
131 #define CP0MVPC1_CIF    30
132 #define CP0MVPC1_PCX    20
133 #define CP0MVPC1_PCP2   10
134 #define CP0MVPC1_PCP1   0
135 };
136
137 typedef struct mips_def_t mips_def_t;
138
139 #define MIPS_SHADOW_SET_MAX 16
140 #define MIPS_TC_MAX 5
141 #define MIPS_FPU_MAX 1
142 #define MIPS_DSP_ACC 4
143 #define MIPS_KSCRATCH_NUM 6
144
145 typedef struct TCState TCState;
146 struct TCState {
147     target_ulong gpr[32];
148     target_ulong PC;
149     target_ulong HI[MIPS_DSP_ACC];
150     target_ulong LO[MIPS_DSP_ACC];
151     target_ulong ACX[MIPS_DSP_ACC];
152     target_ulong DSPControl;
153     int32_t CP0_TCStatus;
154 #define CP0TCSt_TCU3    31
155 #define CP0TCSt_TCU2    30
156 #define CP0TCSt_TCU1    29
157 #define CP0TCSt_TCU0    28
158 #define CP0TCSt_TMX     27
159 #define CP0TCSt_RNST    23
160 #define CP0TCSt_TDS     21
161 #define CP0TCSt_DT      20
162 #define CP0TCSt_DA      15
163 #define CP0TCSt_A       13
164 #define CP0TCSt_TKSU    11
165 #define CP0TCSt_IXMT    10
166 #define CP0TCSt_TASID   0
167     int32_t CP0_TCBind;
168 #define CP0TCBd_CurTC   21
169 #define CP0TCBd_TBE     17
170 #define CP0TCBd_CurVPE  0
171     target_ulong CP0_TCHalt;
172     target_ulong CP0_TCContext;
173     target_ulong CP0_TCSchedule;
174     target_ulong CP0_TCScheFBack;
175     int32_t CP0_Debug_tcstatus;
176     target_ulong CP0_UserLocal;
177 };
178
179 typedef struct CPUMIPSState CPUMIPSState;
180 struct CPUMIPSState {
181     TCState active_tc;
182     CPUMIPSFPUContext active_fpu;
183
184     uint32_t current_tc;
185     uint32_t current_fpu;
186
187     uint32_t SEGBITS;
188     uint32_t PABITS;
189     target_ulong SEGMask;
190     target_ulong PAMask;
191
192     int32_t CP0_Index;
193     /* CP0_MVP* are per MVP registers. */
194     int32_t CP0_Random;
195     int32_t CP0_VPEControl;
196 #define CP0VPECo_YSI    21
197 #define CP0VPECo_GSI    20
198 #define CP0VPECo_EXCPT  16
199 #define CP0VPECo_TE     15
200 #define CP0VPECo_TargTC 0
201     int32_t CP0_VPEConf0;
202 #define CP0VPEC0_M      31
203 #define CP0VPEC0_XTC    21
204 #define CP0VPEC0_TCS    19
205 #define CP0VPEC0_SCS    18
206 #define CP0VPEC0_DSC    17
207 #define CP0VPEC0_ICS    16
208 #define CP0VPEC0_MVP    1
209 #define CP0VPEC0_VPA    0
210     int32_t CP0_VPEConf1;
211 #define CP0VPEC1_NCX    20
212 #define CP0VPEC1_NCP2   10
213 #define CP0VPEC1_NCP1   0
214     target_ulong CP0_YQMask;
215     target_ulong CP0_VPESchedule;
216     target_ulong CP0_VPEScheFBack;
217     int32_t CP0_VPEOpt;
218 #define CP0VPEOpt_IWX7  15
219 #define CP0VPEOpt_IWX6  14
220 #define CP0VPEOpt_IWX5  13
221 #define CP0VPEOpt_IWX4  12
222 #define CP0VPEOpt_IWX3  11
223 #define CP0VPEOpt_IWX2  10
224 #define CP0VPEOpt_IWX1  9
225 #define CP0VPEOpt_IWX0  8
226 #define CP0VPEOpt_DWX7  7
227 #define CP0VPEOpt_DWX6  6
228 #define CP0VPEOpt_DWX5  5
229 #define CP0VPEOpt_DWX4  4
230 #define CP0VPEOpt_DWX3  3
231 #define CP0VPEOpt_DWX2  2
232 #define CP0VPEOpt_DWX1  1
233 #define CP0VPEOpt_DWX0  0
234     target_ulong CP0_EntryLo0;
235     target_ulong CP0_EntryLo1;
236 #if defined(TARGET_MIPS64)
237 # define CP0EnLo_RI 63
238 # define CP0EnLo_XI 62
239 #else
240 # define CP0EnLo_RI 31
241 # define CP0EnLo_XI 30
242 #endif
243     target_ulong CP0_Context;
244     target_ulong CP0_KScratch[MIPS_KSCRATCH_NUM];
245     int32_t CP0_PageMask;
246     int32_t CP0_PageGrain_rw_bitmask;
247     int32_t CP0_PageGrain;
248 #define CP0PG_RIE 31
249 #define CP0PG_XIE 30
250 #define CP0PG_IEC 27
251     int32_t CP0_Wired;
252     int32_t CP0_SRSConf0_rw_bitmask;
253     int32_t CP0_SRSConf0;
254 #define CP0SRSC0_M      31
255 #define CP0SRSC0_SRS3   20
256 #define CP0SRSC0_SRS2   10
257 #define CP0SRSC0_SRS1   0
258     int32_t CP0_SRSConf1_rw_bitmask;
259     int32_t CP0_SRSConf1;
260 #define CP0SRSC1_M      31
261 #define CP0SRSC1_SRS6   20
262 #define CP0SRSC1_SRS5   10
263 #define CP0SRSC1_SRS4   0
264     int32_t CP0_SRSConf2_rw_bitmask;
265     int32_t CP0_SRSConf2;
266 #define CP0SRSC2_M      31
267 #define CP0SRSC2_SRS9   20
268 #define CP0SRSC2_SRS8   10
269 #define CP0SRSC2_SRS7   0
270     int32_t CP0_SRSConf3_rw_bitmask;
271     int32_t CP0_SRSConf3;
272 #define CP0SRSC3_M      31
273 #define CP0SRSC3_SRS12  20
274 #define CP0SRSC3_SRS11  10
275 #define CP0SRSC3_SRS10  0
276     int32_t CP0_SRSConf4_rw_bitmask;
277     int32_t CP0_SRSConf4;
278 #define CP0SRSC4_SRS15  20
279 #define CP0SRSC4_SRS14  10
280 #define CP0SRSC4_SRS13  0
281     int32_t CP0_HWREna;
282     target_ulong CP0_BadVAddr;
283     int32_t CP0_Count;
284     target_ulong CP0_EntryHi;
285     int32_t CP0_Compare;
286     int32_t CP0_Status;
287 #define CP0St_CU3   31
288 #define CP0St_CU2   30
289 #define CP0St_CU1   29
290 #define CP0St_CU0   28
291 #define CP0St_RP    27
292 #define CP0St_FR    26
293 #define CP0St_RE    25
294 #define CP0St_MX    24
295 #define CP0St_PX    23
296 #define CP0St_BEV   22
297 #define CP0St_TS    21
298 #define CP0St_SR    20
299 #define CP0St_NMI   19
300 #define CP0St_IM    8
301 #define CP0St_KX    7
302 #define CP0St_SX    6
303 #define CP0St_UX    5
304 #define CP0St_KSU   3
305 #define CP0St_ERL   2
306 #define CP0St_EXL   1
307 #define CP0St_IE    0
308     int32_t CP0_IntCtl;
309 #define CP0IntCtl_IPTI 29
310 #define CP0IntCtl_IPPC1 26
311 #define CP0IntCtl_VS 5
312     int32_t CP0_SRSCtl;
313 #define CP0SRSCtl_HSS 26
314 #define CP0SRSCtl_EICSS 18
315 #define CP0SRSCtl_ESS 12
316 #define CP0SRSCtl_PSS 6
317 #define CP0SRSCtl_CSS 0
318     int32_t CP0_SRSMap;
319 #define CP0SRSMap_SSV7 28
320 #define CP0SRSMap_SSV6 24
321 #define CP0SRSMap_SSV5 20
322 #define CP0SRSMap_SSV4 16
323 #define CP0SRSMap_SSV3 12
324 #define CP0SRSMap_SSV2 8
325 #define CP0SRSMap_SSV1 4
326 #define CP0SRSMap_SSV0 0
327     int32_t CP0_Cause;
328 #define CP0Ca_BD   31
329 #define CP0Ca_TI   30
330 #define CP0Ca_CE   28
331 #define CP0Ca_DC   27
332 #define CP0Ca_PCI  26
333 #define CP0Ca_IV   23
334 #define CP0Ca_WP   22
335 #define CP0Ca_IP    8
336 #define CP0Ca_IP_mask 0x0000FF00
337 #define CP0Ca_EC    2
338     target_ulong CP0_EPC;
339     int32_t CP0_PRid;
340     int32_t CP0_EBase;
341     int32_t CP0_Config0;
342 #define CP0C0_M    31
343 #define CP0C0_K23  28
344 #define CP0C0_KU   25
345 #define CP0C0_MDU  20
346 #define CP0C0_MM   17
347 #define CP0C0_BM   16
348 #define CP0C0_BE   15
349 #define CP0C0_AT   13
350 #define CP0C0_AR   10
351 #define CP0C0_MT   7
352 #define CP0C0_VI   3
353 #define CP0C0_K0   0
354     int32_t CP0_Config1;
355 #define CP0C1_M    31
356 #define CP0C1_MMU  25
357 #define CP0C1_IS   22
358 #define CP0C1_IL   19
359 #define CP0C1_IA   16
360 #define CP0C1_DS   13
361 #define CP0C1_DL   10
362 #define CP0C1_DA   7
363 #define CP0C1_C2   6
364 #define CP0C1_MD   5
365 #define CP0C1_PC   4
366 #define CP0C1_WR   3
367 #define CP0C1_CA   2
368 #define CP0C1_EP   1
369 #define CP0C1_FP   0
370     int32_t CP0_Config2;
371 #define CP0C2_M    31
372 #define CP0C2_TU   28
373 #define CP0C2_TS   24
374 #define CP0C2_TL   20
375 #define CP0C2_TA   16
376 #define CP0C2_SU   12
377 #define CP0C2_SS   8
378 #define CP0C2_SL   4
379 #define CP0C2_SA   0
380     int32_t CP0_Config3;
381 #define CP0C3_M    31
382 #define CP0C3_ISA_ON_EXC 16
383 #define CP0C3_ULRI 13
384 #define CP0C3_RXI  12
385 #define CP0C3_DSPP 10
386 #define CP0C3_LPA  7
387 #define CP0C3_VEIC 6
388 #define CP0C3_VInt 5
389 #define CP0C3_SP   4
390 #define CP0C3_MT   2
391 #define CP0C3_SM   1
392 #define CP0C3_TL   0
393     uint32_t CP0_Config4;
394     uint32_t CP0_Config4_rw_bitmask;
395 #define CP0C4_M    31
396 #define CP0C4_KScrExist 16
397     uint32_t CP0_Config5;
398     uint32_t CP0_Config5_rw_bitmask;
399 #define CP0C5_M          31
400 #define CP0C5_K          30
401 #define CP0C5_CV         29
402 #define CP0C5_EVA        28
403 #define CP0C5_MSAEn      27
404 #define CP0C5_UFR        2
405 #define CP0C5_NFExists   0
406     int32_t CP0_Config6;
407     int32_t CP0_Config7;
408     /* XXX: Maybe make LLAddr per-TC? */
409     target_ulong lladdr;
410     target_ulong llval;
411     target_ulong llnewval;
412     target_ulong llreg;
413     target_ulong CP0_LLAddr_rw_bitmask;
414     int CP0_LLAddr_shift;
415     target_ulong CP0_WatchLo[8];
416     int32_t CP0_WatchHi[8];
417     target_ulong CP0_XContext;
418     int32_t CP0_Framemask;
419     int32_t CP0_Debug;
420 #define CP0DB_DBD  31
421 #define CP0DB_DM   30
422 #define CP0DB_LSNM 28
423 #define CP0DB_Doze 27
424 #define CP0DB_Halt 26
425 #define CP0DB_CNT  25
426 #define CP0DB_IBEP 24
427 #define CP0DB_DBEP 21
428 #define CP0DB_IEXI 20
429 #define CP0DB_VER  15
430 #define CP0DB_DEC  10
431 #define CP0DB_SSt  8
432 #define CP0DB_DINT 5
433 #define CP0DB_DIB  4
434 #define CP0DB_DDBS 3
435 #define CP0DB_DDBL 2
436 #define CP0DB_DBp  1
437 #define CP0DB_DSS  0
438     target_ulong CP0_DEPC;
439     int32_t CP0_Performance0;
440     int32_t CP0_TagLo;
441     int32_t CP0_DataLo;
442     int32_t CP0_TagHi;
443     int32_t CP0_DataHi;
444     target_ulong CP0_ErrorEPC;
445     int32_t CP0_DESAVE;
446     /* We waste some space so we can handle shadow registers like TCs. */
447     TCState tcs[MIPS_SHADOW_SET_MAX];
448     CPUMIPSFPUContext fpus[MIPS_FPU_MAX];
449     /* QEMU */
450     int error_code;
451     uint32_t hflags;    /* CPU State */
452     /* TMASK defines different execution modes */
453 #define MIPS_HFLAG_TMASK  0x1807FF
454 #define MIPS_HFLAG_MODE   0x00007 /* execution modes                    */
455     /* The KSU flags must be the lowest bits in hflags. The flag order
456        must be the same as defined for CP0 Status. This allows to use
457        the bits as the value of mmu_idx. */
458 #define MIPS_HFLAG_KSU    0x00003 /* kernel/supervisor/user mode mask   */
459 #define MIPS_HFLAG_UM     0x00002 /* user mode flag                     */
460 #define MIPS_HFLAG_SM     0x00001 /* supervisor mode flag               */
461 #define MIPS_HFLAG_KM     0x00000 /* kernel mode flag                   */
462 #define MIPS_HFLAG_DM     0x00004 /* Debug mode                         */
463 #define MIPS_HFLAG_64     0x00008 /* 64-bit instructions enabled        */
464 #define MIPS_HFLAG_CP0    0x00010 /* CP0 enabled                        */
465 #define MIPS_HFLAG_FPU    0x00020 /* FPU enabled                        */
466 #define MIPS_HFLAG_F64    0x00040 /* 64-bit FPU enabled                 */
467     /* True if the MIPS IV COP1X instructions can be used.  This also
468        controls the non-COP1X instructions RECIP.S, RECIP.D, RSQRT.S
469        and RSQRT.D.  */
470 #define MIPS_HFLAG_COP1X  0x00080 /* COP1X instructions enabled         */
471 #define MIPS_HFLAG_RE     0x00100 /* Reversed endianness                */
472 #define MIPS_HFLAG_AWRAP  0x00200 /* 32-bit compatibility address wrapping */
473 #define MIPS_HFLAG_M16    0x00400 /* MIPS16 mode flag                   */
474 #define MIPS_HFLAG_M16_SHIFT 10
475     /* If translation is interrupted between the branch instruction and
476      * the delay slot, record what type of branch it is so that we can
477      * resume translation properly.  It might be possible to reduce
478      * this from three bits to two.  */
479 #define MIPS_HFLAG_BMASK_BASE  0x03800
480 #define MIPS_HFLAG_B      0x00800 /* Unconditional branch               */
481 #define MIPS_HFLAG_BC     0x01000 /* Conditional branch                 */
482 #define MIPS_HFLAG_BL     0x01800 /* Likely branch                      */
483 #define MIPS_HFLAG_BR     0x02000 /* branch to register (can't link TB) */
484     /* Extra flags about the current pending branch.  */
485 #define MIPS_HFLAG_BMASK_EXT 0x7C000
486 #define MIPS_HFLAG_B16    0x04000 /* branch instruction was 16 bits     */
487 #define MIPS_HFLAG_BDS16  0x08000 /* branch requires 16-bit delay slot  */
488 #define MIPS_HFLAG_BDS32  0x10000 /* branch requires 32-bit delay slot  */
489 #define MIPS_HFLAG_BDS_STRICT  0x20000 /* Strict delay slot size */
490 #define MIPS_HFLAG_BX     0x40000 /* branch exchanges execution mode    */
491 #define MIPS_HFLAG_BMASK  (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT)
492     /* MIPS DSP resources access. */
493 #define MIPS_HFLAG_DSP   0x080000  /* Enable access to MIPS DSP resources. */
494 #define MIPS_HFLAG_DSPR2 0x100000  /* Enable access to MIPS DSPR2 resources. */
495     /* Extra flag about HWREna register. */
496 #define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */
497     target_ulong btarget;        /* Jump / branch target               */
498     target_ulong bcond;          /* Branch condition (if needed)       */
499
500     int SYNCI_Step; /* Address step size for SYNCI */
501     int CCRes; /* Cycle count resolution/divisor */
502     uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */
503     uint32_t CP0_TCStatus_rw_bitmask; /* Read/write bits in CP0_TCStatus */
504     int insn_flags; /* Supported instruction set */
505
506     CPU_COMMON
507
508     /* Fields from here on are preserved across CPU reset. */
509     CPUMIPSMVPContext *mvp;
510 #if !defined(CONFIG_USER_ONLY)
511     CPUMIPSTLBContext *tlb;
512 #endif
513
514     const mips_def_t *cpu_model;
515     void *irq[8];
516     QEMUTimer *timer; /* Internal timer */
517 };
518
519 #include "cpu-qom.h"
520
521 #if !defined(CONFIG_USER_ONLY)
522 int no_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
523                         target_ulong address, int rw, int access_type);
524 int fixed_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
525                            target_ulong address, int rw, int access_type);
526 int r4k_map_address (CPUMIPSState *env, hwaddr *physical, int *prot,
527                      target_ulong address, int rw, int access_type);
528 void r4k_helper_tlbwi(CPUMIPSState *env);
529 void r4k_helper_tlbwr(CPUMIPSState *env);
530 void r4k_helper_tlbp(CPUMIPSState *env);
531 void r4k_helper_tlbr(CPUMIPSState *env);
532
533 void mips_cpu_unassigned_access(CPUState *cpu, hwaddr addr,
534                                 bool is_write, bool is_exec, int unused,
535                                 unsigned size);
536 #endif
537
538 void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf);
539
540 #define cpu_exec cpu_mips_exec
541 #define cpu_gen_code cpu_mips_gen_code
542 #define cpu_signal_handler cpu_mips_signal_handler
543 #define cpu_list mips_cpu_list
544
545 extern void cpu_wrdsp(uint32_t rs, uint32_t mask_num, CPUMIPSState *env);
546 extern uint32_t cpu_rddsp(uint32_t mask_num, CPUMIPSState *env);
547
548 #define CPU_SAVE_VERSION 4
549
550 /* MMU modes definitions. We carefully match the indices with our
551    hflags layout. */
552 #define MMU_MODE0_SUFFIX _kernel
553 #define MMU_MODE1_SUFFIX _super
554 #define MMU_MODE2_SUFFIX _user
555 #define MMU_USER_IDX 2
556 static inline int cpu_mmu_index (CPUMIPSState *env)
557 {
558     return env->hflags & MIPS_HFLAG_KSU;
559 }
560
561 static inline int cpu_mips_hw_interrupts_pending(CPUMIPSState *env)
562 {
563     int32_t pending;
564     int32_t status;
565     int r;
566
567     if (!(env->CP0_Status & (1 << CP0St_IE)) ||
568         (env->CP0_Status & (1 << CP0St_EXL)) ||
569         (env->CP0_Status & (1 << CP0St_ERL)) ||
570         /* Note that the TCStatus IXMT field is initialized to zero,
571            and only MT capable cores can set it to one. So we don't
572            need to check for MT capabilities here.  */
573         (env->active_tc.CP0_TCStatus & (1 << CP0TCSt_IXMT)) ||
574         (env->hflags & MIPS_HFLAG_DM)) {
575         /* Interrupts are disabled */
576         return 0;
577     }
578
579     pending = env->CP0_Cause & CP0Ca_IP_mask;
580     status = env->CP0_Status & CP0Ca_IP_mask;
581
582     if (env->CP0_Config3 & (1 << CP0C3_VEIC)) {
583         /* A MIPS configured with a vectorizing external interrupt controller
584            will feed a vector into the Cause pending lines. The core treats
585            the status lines as a vector level, not as indiviual masks.  */
586         r = pending > status;
587     } else {
588         /* A MIPS configured with compatibility or VInt (Vectored Interrupts)
589            treats the pending lines as individual interrupt lines, the status
590            lines are individual masks.  */
591         r = pending & status;
592     }
593     return r;
594 }
595
596 #include "exec/cpu-all.h"
597
598 /* Memory access type :
599  * may be needed for precise access rights control and precise exceptions.
600  */
601 enum {
602     /* 1 bit to define user level / supervisor access */
603     ACCESS_USER  = 0x00,
604     ACCESS_SUPER = 0x01,
605     /* 1 bit to indicate direction */
606     ACCESS_STORE = 0x02,
607     /* Type of instruction that generated the access */
608     ACCESS_CODE  = 0x10, /* Code fetch access                */
609     ACCESS_INT   = 0x20, /* Integer load/store access        */
610     ACCESS_FLOAT = 0x30, /* floating point load/store access */
611 };
612
613 /* Exceptions */
614 enum {
615     EXCP_NONE          = -1,
616     EXCP_RESET         = 0,
617     EXCP_SRESET,
618     EXCP_DSS,
619     EXCP_DINT,
620     EXCP_DDBL,
621     EXCP_DDBS,
622     EXCP_NMI,
623     EXCP_MCHECK,
624     EXCP_EXT_INTERRUPT, /* 8 */
625     EXCP_DFWATCH,
626     EXCP_DIB,
627     EXCP_IWATCH,
628     EXCP_AdEL,
629     EXCP_AdES,
630     EXCP_TLBF,
631     EXCP_IBE,
632     EXCP_DBp, /* 16 */
633     EXCP_SYSCALL,
634     EXCP_BREAK,
635     EXCP_CpU,
636     EXCP_RI,
637     EXCP_OVERFLOW,
638     EXCP_TRAP,
639     EXCP_FPE,
640     EXCP_DWATCH, /* 24 */
641     EXCP_LTLBL,
642     EXCP_TLBL,
643     EXCP_TLBS,
644     EXCP_DBE,
645     EXCP_THREAD,
646     EXCP_MDMX,
647     EXCP_C2E,
648     EXCP_CACHE, /* 32 */
649     EXCP_DSPDIS,
650     EXCP_TLBXI,
651     EXCP_TLBRI,
652
653     EXCP_LAST = EXCP_TLBRI,
654 };
655 /* Dummy exception for conditional stores.  */
656 #define EXCP_SC 0x100
657
658 /*
659  * This is an interrnally generated WAKE request line.
660  * It is driven by the CPU itself. Raised when the MT
661  * block wants to wake a VPE from an inactive state and
662  * cleared when VPE goes from active to inactive.
663  */
664 #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0
665
666 int cpu_mips_exec(CPUMIPSState *s);
667 void mips_tcg_init(void);
668 MIPSCPU *cpu_mips_init(const char *cpu_model);
669 int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
670
671 static inline CPUMIPSState *cpu_init(const char *cpu_model)
672 {
673     MIPSCPU *cpu = cpu_mips_init(cpu_model);
674     if (cpu == NULL) {
675         return NULL;
676     }
677     return &cpu->env;
678 }
679
680 /* TODO QOM'ify CPU reset and remove */
681 void cpu_state_reset(CPUMIPSState *s);
682
683 /* mips_timer.c */
684 uint32_t cpu_mips_get_random (CPUMIPSState *env);
685 uint32_t cpu_mips_get_count (CPUMIPSState *env);
686 void cpu_mips_store_count (CPUMIPSState *env, uint32_t value);
687 void cpu_mips_store_compare (CPUMIPSState *env, uint32_t value);
688 void cpu_mips_start_count(CPUMIPSState *env);
689 void cpu_mips_stop_count(CPUMIPSState *env);
690
691 /* mips_int.c */
692 void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level);
693
694 /* helper.c */
695 int mips_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
696                               int mmu_idx);
697 #if !defined(CONFIG_USER_ONLY)
698 void r4k_invalidate_tlb (CPUMIPSState *env, int idx, int use_extra);
699 hwaddr cpu_mips_translate_address (CPUMIPSState *env, target_ulong address,
700                                                int rw);
701 #endif
702 target_ulong exception_resume_pc (CPUMIPSState *env);
703
704 static inline void cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc,
705                                         target_ulong *cs_base, int *flags)
706 {
707     *pc = env->active_tc.PC;
708     *cs_base = 0;
709     *flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK |
710                             MIPS_HFLAG_HWRENA_ULR);
711 }
712
713 static inline int mips_vpe_active(CPUMIPSState *env)
714 {
715     int active = 1;
716
717     /* Check that the VPE is enabled.  */
718     if (!(env->mvp->CP0_MVPControl & (1 << CP0MVPCo_EVP))) {
719         active = 0;
720     }
721     /* Check that the VPE is activated.  */
722     if (!(env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))) {
723         active = 0;
724     }
725
726     /* Now verify that there are active thread contexts in the VPE.
727
728        This assumes the CPU model will internally reschedule threads
729        if the active one goes to sleep. If there are no threads available
730        the active one will be in a sleeping state, and we can turn off
731        the entire VPE.  */
732     if (!(env->active_tc.CP0_TCStatus & (1 << CP0TCSt_A))) {
733         /* TC is not activated.  */
734         active = 0;
735     }
736     if (env->active_tc.CP0_TCHalt & 1) {
737         /* TC is in halt state.  */
738         active = 0;
739     }
740
741     return active;
742 }
743
744 #include "exec/exec-all.h"
745
746 static inline void compute_hflags(CPUMIPSState *env)
747 {
748     env->hflags &= ~(MIPS_HFLAG_COP1X | MIPS_HFLAG_64 | MIPS_HFLAG_CP0 |
749                      MIPS_HFLAG_F64 | MIPS_HFLAG_FPU | MIPS_HFLAG_KSU |
750                      MIPS_HFLAG_AWRAP | MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2);
751     if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
752         !(env->CP0_Status & (1 << CP0St_ERL)) &&
753         !(env->hflags & MIPS_HFLAG_DM)) {
754         env->hflags |= (env->CP0_Status >> CP0St_KSU) & MIPS_HFLAG_KSU;
755     }
756 #if defined(TARGET_MIPS64)
757     if (((env->hflags & MIPS_HFLAG_KSU) != MIPS_HFLAG_UM) ||
758         (env->CP0_Status & (1 << CP0St_PX)) ||
759         (env->CP0_Status & (1 << CP0St_UX))) {
760         env->hflags |= MIPS_HFLAG_64;
761     }
762
763     if (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
764         !(env->CP0_Status & (1 << CP0St_UX))) {
765         env->hflags |= MIPS_HFLAG_AWRAP;
766     } else if (env->insn_flags & ISA_MIPS32R6) {
767         /* Address wrapping for Supervisor and Kernel is specified in R6 */
768         if ((((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_SM) &&
769              !(env->CP0_Status & (1 << CP0St_SX))) ||
770             (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_KM) &&
771              !(env->CP0_Status & (1 << CP0St_KX)))) {
772             env->hflags |= MIPS_HFLAG_AWRAP;
773         }
774     }
775 #endif
776     if ((env->CP0_Status & (1 << CP0St_CU0)) ||
777         !(env->hflags & MIPS_HFLAG_KSU)) {
778         env->hflags |= MIPS_HFLAG_CP0;
779     }
780     if (env->CP0_Status & (1 << CP0St_CU1)) {
781         env->hflags |= MIPS_HFLAG_FPU;
782     }
783     if (env->CP0_Status & (1 << CP0St_FR)) {
784         env->hflags |= MIPS_HFLAG_F64;
785     }
786     if (env->insn_flags & ASE_DSPR2) {
787         /* Enables access MIPS DSP resources, now our cpu is DSP ASER2,
788            so enable to access DSPR2 resources. */
789         if (env->CP0_Status & (1 << CP0St_MX)) {
790             env->hflags |= MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2;
791         }
792
793     } else if (env->insn_flags & ASE_DSP) {
794         /* Enables access MIPS DSP resources, now our cpu is DSP ASE,
795            so enable to access DSP resources. */
796         if (env->CP0_Status & (1 << CP0St_MX)) {
797             env->hflags |= MIPS_HFLAG_DSP;
798         }
799
800     }
801     if (env->insn_flags & ISA_MIPS32R2) {
802         if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
803             env->hflags |= MIPS_HFLAG_COP1X;
804         }
805     } else if (env->insn_flags & ISA_MIPS32) {
806         if (env->hflags & MIPS_HFLAG_64) {
807             env->hflags |= MIPS_HFLAG_COP1X;
808         }
809     } else if (env->insn_flags & ISA_MIPS4) {
810         /* All supported MIPS IV CPUs use the XX (CU3) to enable
811            and disable the MIPS IV extensions to the MIPS III ISA.
812            Some other MIPS IV CPUs ignore the bit, so the check here
813            would be too restrictive for them.  */
814         if (env->CP0_Status & (1U << CP0St_CU3)) {
815             env->hflags |= MIPS_HFLAG_COP1X;
816         }
817     }
818 }
819
820 #endif /* !defined (__MIPS_CPU_H__) */
This page took 0.072418 seconds and 4 git commands to generate.