]>
Commit | Line | Data |
---|---|---|
6af0bf9c FB |
1 | #if !defined (__MIPS_CPU_H__) |
2 | #define __MIPS_CPU_H__ | |
3 | ||
3e457172 BS |
4 | //#define DEBUG_OP |
5 | ||
d94f0a8e | 6 | #define ALIGNED_ONLY |
4ad40f36 FB |
7 | #define TARGET_HAS_ICE 1 |
8 | ||
9042c0e2 TS |
9 | #define ELF_MACHINE EM_MIPS |
10 | ||
9349b4f9 | 11 | #define CPUArchState struct CPUMIPSState |
c2764719 | 12 | |
c5d6edc3 | 13 | #include "config.h" |
9a78eead | 14 | #include "qemu-common.h" |
6af0bf9c | 15 | #include "mips-defs.h" |
022c62cb | 16 | #include "exec/cpu-defs.h" |
6b4c305c | 17 | #include "fpu/softfloat.h" |
6af0bf9c | 18 | |
ead9360e | 19 | struct CPUMIPSState; |
6af0bf9c | 20 | |
c227f099 AL |
21 | typedef struct r4k_tlb_t r4k_tlb_t; |
22 | struct r4k_tlb_t { | |
6af0bf9c | 23 | target_ulong VPN; |
9c2149c8 | 24 | uint32_t PageMask; |
98c1b82b PB |
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; | |
2fb58b73 LA |
33 | uint_fast16_t XI0:1; |
34 | uint_fast16_t XI1:1; | |
35 | uint_fast16_t RI0:1; | |
36 | uint_fast16_t RI1:1; | |
6af0bf9c FB |
37 | target_ulong PFN[2]; |
38 | }; | |
6af0bf9c | 39 | |
3c7b48b7 | 40 | #if !defined(CONFIG_USER_ONLY) |
ead9360e TS |
41 | typedef struct CPUMIPSTLBContext CPUMIPSTLBContext; |
42 | struct CPUMIPSTLBContext { | |
43 | uint32_t nb_tlb; | |
44 | uint32_t tlb_in_use; | |
a8170e5e | 45 | int (*map_address) (struct CPUMIPSState *env, hwaddr *physical, int *prot, target_ulong address, int rw, int access_type); |
895c2d04 BS |
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); | |
ead9360e TS |
50 | union { |
51 | struct { | |
c227f099 | 52 | r4k_tlb_t tlb[MIPS_TLB_MAX]; |
ead9360e TS |
53 | } r4k; |
54 | } mmu; | |
55 | }; | |
3c7b48b7 | 56 | #endif |
51b2772f | 57 | |
c227f099 AL |
58 | typedef union fpr_t fpr_t; |
59 | union fpr_t { | |
ead9360e TS |
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 | |
4ff9786c | 66 | * in the fpr_t union regardless of the host endianness |
ead9360e | 67 | */ |
e2542fe2 | 68 | #if defined(HOST_WORDS_BIGENDIAN) |
ead9360e TS |
69 | # define FP_ENDIAN_IDX 1 |
70 | #else | |
71 | # define FP_ENDIAN_IDX 0 | |
c570fd16 | 72 | #endif |
ead9360e TS |
73 | |
74 | typedef struct CPUMIPSFPUContext CPUMIPSFPUContext; | |
75 | struct CPUMIPSFPUContext { | |
6af0bf9c | 76 | /* Floating point registers */ |
c227f099 | 77 | fpr_t fpr[32]; |
6ea83fed | 78 | float_status fp_status; |
5a5012ec | 79 | /* fpu implementation/revision register (fir) */ |
6af0bf9c | 80 | uint32_t fcr0; |
b4dd99a3 | 81 | #define FCR0_UFRP 28 |
5a5012ec TS |
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 | |
6ea83fed FB |
91 | /* fcsr */ |
92 | uint32_t fcr31; | |
f01be154 TS |
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)) | |
5a5012ec TS |
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) | |
6ea83fed FB |
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 | |
ead9360e TS |
109 | }; |
110 | ||
623a930e | 111 | #define NB_MMU_MODES 3 |
6ebbf390 | 112 | |
ead9360e TS |
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 | ||
c227f099 | 137 | typedef struct mips_def_t mips_def_t; |
ead9360e TS |
138 | |
139 | #define MIPS_SHADOW_SET_MAX 16 | |
140 | #define MIPS_TC_MAX 5 | |
f01be154 | 141 | #define MIPS_FPU_MAX 1 |
ead9360e | 142 | #define MIPS_DSP_ACC 4 |
e98c0d17 | 143 | #define MIPS_KSCRATCH_NUM 6 |
ead9360e | 144 | |
b5dc7732 TS |
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; | |
d279279e | 176 | target_ulong CP0_UserLocal; |
b5dc7732 TS |
177 | }; |
178 | ||
ead9360e TS |
179 | typedef struct CPUMIPSState CPUMIPSState; |
180 | struct CPUMIPSState { | |
b5dc7732 | 181 | TCState active_tc; |
f01be154 | 182 | CPUMIPSFPUContext active_fpu; |
b5dc7732 | 183 | |
ead9360e | 184 | uint32_t current_tc; |
f01be154 | 185 | uint32_t current_fpu; |
36d23958 | 186 | |
e034e2c3 | 187 | uint32_t SEGBITS; |
6d35524c | 188 | uint32_t PABITS; |
b6d96bed | 189 | target_ulong SEGMask; |
6d35524c | 190 | target_ulong PAMask; |
29929e34 | 191 | |
9c2149c8 | 192 | int32_t CP0_Index; |
ead9360e | 193 | /* CP0_MVP* are per MVP registers. */ |
9c2149c8 | 194 | int32_t CP0_Random; |
ead9360e TS |
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 | |
9c2149c8 TS |
234 | target_ulong CP0_EntryLo0; |
235 | target_ulong CP0_EntryLo1; | |
2fb58b73 LA |
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 | |
9c2149c8 | 243 | target_ulong CP0_Context; |
e98c0d17 | 244 | target_ulong CP0_KScratch[MIPS_KSCRATCH_NUM]; |
9c2149c8 TS |
245 | int32_t CP0_PageMask; |
246 | int32_t CP0_PageGrain; | |
247 | int32_t CP0_Wired; | |
ead9360e TS |
248 | int32_t CP0_SRSConf0_rw_bitmask; |
249 | int32_t CP0_SRSConf0; | |
250 | #define CP0SRSC0_M 31 | |
251 | #define CP0SRSC0_SRS3 20 | |
252 | #define CP0SRSC0_SRS2 10 | |
253 | #define CP0SRSC0_SRS1 0 | |
254 | int32_t CP0_SRSConf1_rw_bitmask; | |
255 | int32_t CP0_SRSConf1; | |
256 | #define CP0SRSC1_M 31 | |
257 | #define CP0SRSC1_SRS6 20 | |
258 | #define CP0SRSC1_SRS5 10 | |
259 | #define CP0SRSC1_SRS4 0 | |
260 | int32_t CP0_SRSConf2_rw_bitmask; | |
261 | int32_t CP0_SRSConf2; | |
262 | #define CP0SRSC2_M 31 | |
263 | #define CP0SRSC2_SRS9 20 | |
264 | #define CP0SRSC2_SRS8 10 | |
265 | #define CP0SRSC2_SRS7 0 | |
266 | int32_t CP0_SRSConf3_rw_bitmask; | |
267 | int32_t CP0_SRSConf3; | |
268 | #define CP0SRSC3_M 31 | |
269 | #define CP0SRSC3_SRS12 20 | |
270 | #define CP0SRSC3_SRS11 10 | |
271 | #define CP0SRSC3_SRS10 0 | |
272 | int32_t CP0_SRSConf4_rw_bitmask; | |
273 | int32_t CP0_SRSConf4; | |
274 | #define CP0SRSC4_SRS15 20 | |
275 | #define CP0SRSC4_SRS14 10 | |
276 | #define CP0SRSC4_SRS13 0 | |
9c2149c8 | 277 | int32_t CP0_HWREna; |
c570fd16 | 278 | target_ulong CP0_BadVAddr; |
9c2149c8 TS |
279 | int32_t CP0_Count; |
280 | target_ulong CP0_EntryHi; | |
281 | int32_t CP0_Compare; | |
282 | int32_t CP0_Status; | |
6af0bf9c FB |
283 | #define CP0St_CU3 31 |
284 | #define CP0St_CU2 30 | |
285 | #define CP0St_CU1 29 | |
286 | #define CP0St_CU0 28 | |
287 | #define CP0St_RP 27 | |
6ea83fed | 288 | #define CP0St_FR 26 |
6af0bf9c | 289 | #define CP0St_RE 25 |
7a387fff TS |
290 | #define CP0St_MX 24 |
291 | #define CP0St_PX 23 | |
6af0bf9c FB |
292 | #define CP0St_BEV 22 |
293 | #define CP0St_TS 21 | |
294 | #define CP0St_SR 20 | |
295 | #define CP0St_NMI 19 | |
296 | #define CP0St_IM 8 | |
7a387fff TS |
297 | #define CP0St_KX 7 |
298 | #define CP0St_SX 6 | |
299 | #define CP0St_UX 5 | |
623a930e | 300 | #define CP0St_KSU 3 |
6af0bf9c FB |
301 | #define CP0St_ERL 2 |
302 | #define CP0St_EXL 1 | |
303 | #define CP0St_IE 0 | |
9c2149c8 | 304 | int32_t CP0_IntCtl; |
ead9360e TS |
305 | #define CP0IntCtl_IPTI 29 |
306 | #define CP0IntCtl_IPPC1 26 | |
307 | #define CP0IntCtl_VS 5 | |
9c2149c8 | 308 | int32_t CP0_SRSCtl; |
ead9360e TS |
309 | #define CP0SRSCtl_HSS 26 |
310 | #define CP0SRSCtl_EICSS 18 | |
311 | #define CP0SRSCtl_ESS 12 | |
312 | #define CP0SRSCtl_PSS 6 | |
313 | #define CP0SRSCtl_CSS 0 | |
9c2149c8 | 314 | int32_t CP0_SRSMap; |
ead9360e TS |
315 | #define CP0SRSMap_SSV7 28 |
316 | #define CP0SRSMap_SSV6 24 | |
317 | #define CP0SRSMap_SSV5 20 | |
318 | #define CP0SRSMap_SSV4 16 | |
319 | #define CP0SRSMap_SSV3 12 | |
320 | #define CP0SRSMap_SSV2 8 | |
321 | #define CP0SRSMap_SSV1 4 | |
322 | #define CP0SRSMap_SSV0 0 | |
9c2149c8 | 323 | int32_t CP0_Cause; |
7a387fff TS |
324 | #define CP0Ca_BD 31 |
325 | #define CP0Ca_TI 30 | |
326 | #define CP0Ca_CE 28 | |
327 | #define CP0Ca_DC 27 | |
328 | #define CP0Ca_PCI 26 | |
6af0bf9c | 329 | #define CP0Ca_IV 23 |
7a387fff TS |
330 | #define CP0Ca_WP 22 |
331 | #define CP0Ca_IP 8 | |
4de9b249 | 332 | #define CP0Ca_IP_mask 0x0000FF00 |
7a387fff | 333 | #define CP0Ca_EC 2 |
c570fd16 | 334 | target_ulong CP0_EPC; |
9c2149c8 | 335 | int32_t CP0_PRid; |
b29a0341 | 336 | int32_t CP0_EBase; |
9c2149c8 | 337 | int32_t CP0_Config0; |
6af0bf9c FB |
338 | #define CP0C0_M 31 |
339 | #define CP0C0_K23 28 | |
340 | #define CP0C0_KU 25 | |
341 | #define CP0C0_MDU 20 | |
342 | #define CP0C0_MM 17 | |
343 | #define CP0C0_BM 16 | |
344 | #define CP0C0_BE 15 | |
345 | #define CP0C0_AT 13 | |
346 | #define CP0C0_AR 10 | |
347 | #define CP0C0_MT 7 | |
7a387fff | 348 | #define CP0C0_VI 3 |
6af0bf9c | 349 | #define CP0C0_K0 0 |
9c2149c8 | 350 | int32_t CP0_Config1; |
7a387fff | 351 | #define CP0C1_M 31 |
6af0bf9c FB |
352 | #define CP0C1_MMU 25 |
353 | #define CP0C1_IS 22 | |
354 | #define CP0C1_IL 19 | |
355 | #define CP0C1_IA 16 | |
356 | #define CP0C1_DS 13 | |
357 | #define CP0C1_DL 10 | |
358 | #define CP0C1_DA 7 | |
7a387fff TS |
359 | #define CP0C1_C2 6 |
360 | #define CP0C1_MD 5 | |
6af0bf9c FB |
361 | #define CP0C1_PC 4 |
362 | #define CP0C1_WR 3 | |
363 | #define CP0C1_CA 2 | |
364 | #define CP0C1_EP 1 | |
365 | #define CP0C1_FP 0 | |
9c2149c8 | 366 | int32_t CP0_Config2; |
7a387fff TS |
367 | #define CP0C2_M 31 |
368 | #define CP0C2_TU 28 | |
369 | #define CP0C2_TS 24 | |
370 | #define CP0C2_TL 20 | |
371 | #define CP0C2_TA 16 | |
372 | #define CP0C2_SU 12 | |
373 | #define CP0C2_SS 8 | |
374 | #define CP0C2_SL 4 | |
375 | #define CP0C2_SA 0 | |
9c2149c8 | 376 | int32_t CP0_Config3; |
7a387fff | 377 | #define CP0C3_M 31 |
bbfa8f72 | 378 | #define CP0C3_ISA_ON_EXC 16 |
d279279e | 379 | #define CP0C3_ULRI 13 |
7a387fff TS |
380 | #define CP0C3_DSPP 10 |
381 | #define CP0C3_LPA 7 | |
382 | #define CP0C3_VEIC 6 | |
383 | #define CP0C3_VInt 5 | |
384 | #define CP0C3_SP 4 | |
385 | #define CP0C3_MT 2 | |
386 | #define CP0C3_SM 1 | |
387 | #define CP0C3_TL 0 | |
b4160af1 PJ |
388 | uint32_t CP0_Config4; |
389 | uint32_t CP0_Config4_rw_bitmask; | |
390 | #define CP0C4_M 31 | |
e98c0d17 | 391 | #define CP0C4_KScrExist 16 |
b4dd99a3 PJ |
392 | uint32_t CP0_Config5; |
393 | uint32_t CP0_Config5_rw_bitmask; | |
394 | #define CP0C5_M 31 | |
395 | #define CP0C5_K 30 | |
396 | #define CP0C5_CV 29 | |
397 | #define CP0C5_EVA 28 | |
398 | #define CP0C5_MSAEn 27 | |
399 | #define CP0C5_UFR 2 | |
400 | #define CP0C5_NFExists 0 | |
e397ee33 TS |
401 | int32_t CP0_Config6; |
402 | int32_t CP0_Config7; | |
ead9360e | 403 | /* XXX: Maybe make LLAddr per-TC? */ |
5499b6ff | 404 | target_ulong lladdr; |
590bc601 PB |
405 | target_ulong llval; |
406 | target_ulong llnewval; | |
407 | target_ulong llreg; | |
2a6e32dd AJ |
408 | target_ulong CP0_LLAddr_rw_bitmask; |
409 | int CP0_LLAddr_shift; | |
fd88b6ab TS |
410 | target_ulong CP0_WatchLo[8]; |
411 | int32_t CP0_WatchHi[8]; | |
9c2149c8 TS |
412 | target_ulong CP0_XContext; |
413 | int32_t CP0_Framemask; | |
414 | int32_t CP0_Debug; | |
ead9360e | 415 | #define CP0DB_DBD 31 |
6af0bf9c FB |
416 | #define CP0DB_DM 30 |
417 | #define CP0DB_LSNM 28 | |
418 | #define CP0DB_Doze 27 | |
419 | #define CP0DB_Halt 26 | |
420 | #define CP0DB_CNT 25 | |
421 | #define CP0DB_IBEP 24 | |
422 | #define CP0DB_DBEP 21 | |
423 | #define CP0DB_IEXI 20 | |
424 | #define CP0DB_VER 15 | |
425 | #define CP0DB_DEC 10 | |
426 | #define CP0DB_SSt 8 | |
427 | #define CP0DB_DINT 5 | |
428 | #define CP0DB_DIB 4 | |
429 | #define CP0DB_DDBS 3 | |
430 | #define CP0DB_DDBL 2 | |
431 | #define CP0DB_DBp 1 | |
432 | #define CP0DB_DSS 0 | |
c570fd16 | 433 | target_ulong CP0_DEPC; |
9c2149c8 TS |
434 | int32_t CP0_Performance0; |
435 | int32_t CP0_TagLo; | |
436 | int32_t CP0_DataLo; | |
437 | int32_t CP0_TagHi; | |
438 | int32_t CP0_DataHi; | |
c570fd16 | 439 | target_ulong CP0_ErrorEPC; |
9c2149c8 | 440 | int32_t CP0_DESAVE; |
b5dc7732 TS |
441 | /* We waste some space so we can handle shadow registers like TCs. */ |
442 | TCState tcs[MIPS_SHADOW_SET_MAX]; | |
f01be154 | 443 | CPUMIPSFPUContext fpus[MIPS_FPU_MAX]; |
5cbdb3a3 | 444 | /* QEMU */ |
6af0bf9c | 445 | int error_code; |
6af0bf9c FB |
446 | uint32_t hflags; /* CPU State */ |
447 | /* TMASK defines different execution modes */ | |
b231c103 | 448 | #define MIPS_HFLAG_TMASK 0x1807FF |
79ef2c4c | 449 | #define MIPS_HFLAG_MODE 0x00007 /* execution modes */ |
623a930e TS |
450 | /* The KSU flags must be the lowest bits in hflags. The flag order |
451 | must be the same as defined for CP0 Status. This allows to use | |
452 | the bits as the value of mmu_idx. */ | |
79ef2c4c NF |
453 | #define MIPS_HFLAG_KSU 0x00003 /* kernel/supervisor/user mode mask */ |
454 | #define MIPS_HFLAG_UM 0x00002 /* user mode flag */ | |
455 | #define MIPS_HFLAG_SM 0x00001 /* supervisor mode flag */ | |
456 | #define MIPS_HFLAG_KM 0x00000 /* kernel mode flag */ | |
457 | #define MIPS_HFLAG_DM 0x00004 /* Debug mode */ | |
458 | #define MIPS_HFLAG_64 0x00008 /* 64-bit instructions enabled */ | |
459 | #define MIPS_HFLAG_CP0 0x00010 /* CP0 enabled */ | |
460 | #define MIPS_HFLAG_FPU 0x00020 /* FPU enabled */ | |
461 | #define MIPS_HFLAG_F64 0x00040 /* 64-bit FPU enabled */ | |
b8aa4598 TS |
462 | /* True if the MIPS IV COP1X instructions can be used. This also |
463 | controls the non-COP1X instructions RECIP.S, RECIP.D, RSQRT.S | |
464 | and RSQRT.D. */ | |
79ef2c4c NF |
465 | #define MIPS_HFLAG_COP1X 0x00080 /* COP1X instructions enabled */ |
466 | #define MIPS_HFLAG_RE 0x00100 /* Reversed endianness */ | |
01f72885 | 467 | #define MIPS_HFLAG_AWRAP 0x00200 /* 32-bit compatibility address wrapping */ |
79ef2c4c NF |
468 | #define MIPS_HFLAG_M16 0x00400 /* MIPS16 mode flag */ |
469 | #define MIPS_HFLAG_M16_SHIFT 10 | |
4ad40f36 FB |
470 | /* If translation is interrupted between the branch instruction and |
471 | * the delay slot, record what type of branch it is so that we can | |
472 | * resume translation properly. It might be possible to reduce | |
473 | * this from three bits to two. */ | |
79ef2c4c NF |
474 | #define MIPS_HFLAG_BMASK_BASE 0x03800 |
475 | #define MIPS_HFLAG_B 0x00800 /* Unconditional branch */ | |
476 | #define MIPS_HFLAG_BC 0x01000 /* Conditional branch */ | |
477 | #define MIPS_HFLAG_BL 0x01800 /* Likely branch */ | |
478 | #define MIPS_HFLAG_BR 0x02000 /* branch to register (can't link TB) */ | |
479 | /* Extra flags about the current pending branch. */ | |
b231c103 | 480 | #define MIPS_HFLAG_BMASK_EXT 0x7C000 |
79ef2c4c NF |
481 | #define MIPS_HFLAG_B16 0x04000 /* branch instruction was 16 bits */ |
482 | #define MIPS_HFLAG_BDS16 0x08000 /* branch requires 16-bit delay slot */ | |
483 | #define MIPS_HFLAG_BDS32 0x10000 /* branch requires 32-bit delay slot */ | |
b231c103 YK |
484 | #define MIPS_HFLAG_BDS_STRICT 0x20000 /* Strict delay slot size */ |
485 | #define MIPS_HFLAG_BX 0x40000 /* branch exchanges execution mode */ | |
79ef2c4c | 486 | #define MIPS_HFLAG_BMASK (MIPS_HFLAG_BMASK_BASE | MIPS_HFLAG_BMASK_EXT) |
853c3240 | 487 | /* MIPS DSP resources access. */ |
b231c103 YK |
488 | #define MIPS_HFLAG_DSP 0x080000 /* Enable access to MIPS DSP resources. */ |
489 | #define MIPS_HFLAG_DSPR2 0x100000 /* Enable access to MIPS DSPR2 resources. */ | |
d279279e | 490 | /* Extra flag about HWREna register. */ |
b231c103 | 491 | #define MIPS_HFLAG_HWRENA_ULR 0x200000 /* ULR bit from HWREna is set. */ |
6af0bf9c | 492 | target_ulong btarget; /* Jump / branch target */ |
1ba74fb8 | 493 | target_ulong bcond; /* Branch condition (if needed) */ |
a316d335 | 494 | |
7a387fff TS |
495 | int SYNCI_Step; /* Address step size for SYNCI */ |
496 | int CCRes; /* Cycle count resolution/divisor */ | |
ead9360e TS |
497 | uint32_t CP0_Status_rw_bitmask; /* Read/write bits in CP0_Status */ |
498 | uint32_t CP0_TCStatus_rw_bitmask; /* Read/write bits in CP0_TCStatus */ | |
e189e748 | 499 | int insn_flags; /* Supported instruction set */ |
7a387fff | 500 | |
a316d335 | 501 | CPU_COMMON |
6ae81775 | 502 | |
f0c3c505 | 503 | /* Fields from here on are preserved across CPU reset. */ |
51cc2e78 | 504 | CPUMIPSMVPContext *mvp; |
3c7b48b7 | 505 | #if !defined(CONFIG_USER_ONLY) |
51cc2e78 | 506 | CPUMIPSTLBContext *tlb; |
3c7b48b7 | 507 | #endif |
51cc2e78 | 508 | |
c227f099 | 509 | const mips_def_t *cpu_model; |
33ac7f16 | 510 | void *irq[8]; |
1246b259 | 511 | QEMUTimer *timer; /* Internal timer */ |
6af0bf9c FB |
512 | }; |
513 | ||
0f71a709 AF |
514 | #include "cpu-qom.h" |
515 | ||
3c7b48b7 | 516 | #if !defined(CONFIG_USER_ONLY) |
a8170e5e | 517 | int no_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot, |
29929e34 | 518 | target_ulong address, int rw, int access_type); |
a8170e5e | 519 | int fixed_mmu_map_address (CPUMIPSState *env, hwaddr *physical, int *prot, |
29929e34 | 520 | target_ulong address, int rw, int access_type); |
a8170e5e | 521 | int r4k_map_address (CPUMIPSState *env, hwaddr *physical, int *prot, |
29929e34 | 522 | target_ulong address, int rw, int access_type); |
895c2d04 BS |
523 | void r4k_helper_tlbwi(CPUMIPSState *env); |
524 | void r4k_helper_tlbwr(CPUMIPSState *env); | |
525 | void r4k_helper_tlbp(CPUMIPSState *env); | |
526 | void r4k_helper_tlbr(CPUMIPSState *env); | |
33d68b5f | 527 | |
c658b94f AF |
528 | void mips_cpu_unassigned_access(CPUState *cpu, hwaddr addr, |
529 | bool is_write, bool is_exec, int unused, | |
530 | unsigned size); | |
3c7b48b7 PB |
531 | #endif |
532 | ||
9a78eead | 533 | void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf); |
647de6ca | 534 | |
9467d44c TS |
535 | #define cpu_exec cpu_mips_exec |
536 | #define cpu_gen_code cpu_mips_gen_code | |
537 | #define cpu_signal_handler cpu_mips_signal_handler | |
c732abe2 | 538 | #define cpu_list mips_cpu_list |
9467d44c | 539 | |
084d0497 RH |
540 | extern void cpu_wrdsp(uint32_t rs, uint32_t mask_num, CPUMIPSState *env); |
541 | extern uint32_t cpu_rddsp(uint32_t mask_num, CPUMIPSState *env); | |
542 | ||
d279279e | 543 | #define CPU_SAVE_VERSION 4 |
b3c7724c | 544 | |
623a930e TS |
545 | /* MMU modes definitions. We carefully match the indices with our |
546 | hflags layout. */ | |
6ebbf390 | 547 | #define MMU_MODE0_SUFFIX _kernel |
623a930e TS |
548 | #define MMU_MODE1_SUFFIX _super |
549 | #define MMU_MODE2_SUFFIX _user | |
550 | #define MMU_USER_IDX 2 | |
7db13fae | 551 | static inline int cpu_mmu_index (CPUMIPSState *env) |
6ebbf390 | 552 | { |
623a930e | 553 | return env->hflags & MIPS_HFLAG_KSU; |
6ebbf390 JM |
554 | } |
555 | ||
7db13fae | 556 | static inline int cpu_mips_hw_interrupts_pending(CPUMIPSState *env) |
138afb02 EI |
557 | { |
558 | int32_t pending; | |
559 | int32_t status; | |
560 | int r; | |
561 | ||
4cdc1cd1 AJ |
562 | if (!(env->CP0_Status & (1 << CP0St_IE)) || |
563 | (env->CP0_Status & (1 << CP0St_EXL)) || | |
564 | (env->CP0_Status & (1 << CP0St_ERL)) || | |
344eecf6 EI |
565 | /* Note that the TCStatus IXMT field is initialized to zero, |
566 | and only MT capable cores can set it to one. So we don't | |
567 | need to check for MT capabilities here. */ | |
568 | (env->active_tc.CP0_TCStatus & (1 << CP0TCSt_IXMT)) || | |
4cdc1cd1 AJ |
569 | (env->hflags & MIPS_HFLAG_DM)) { |
570 | /* Interrupts are disabled */ | |
571 | return 0; | |
572 | } | |
573 | ||
138afb02 EI |
574 | pending = env->CP0_Cause & CP0Ca_IP_mask; |
575 | status = env->CP0_Status & CP0Ca_IP_mask; | |
576 | ||
577 | if (env->CP0_Config3 & (1 << CP0C3_VEIC)) { | |
578 | /* A MIPS configured with a vectorizing external interrupt controller | |
579 | will feed a vector into the Cause pending lines. The core treats | |
580 | the status lines as a vector level, not as indiviual masks. */ | |
581 | r = pending > status; | |
582 | } else { | |
583 | /* A MIPS configured with compatibility or VInt (Vectored Interrupts) | |
584 | treats the pending lines as individual interrupt lines, the status | |
585 | lines are individual masks. */ | |
586 | r = pending & status; | |
587 | } | |
588 | return r; | |
589 | } | |
590 | ||
022c62cb | 591 | #include "exec/cpu-all.h" |
6af0bf9c FB |
592 | |
593 | /* Memory access type : | |
594 | * may be needed for precise access rights control and precise exceptions. | |
595 | */ | |
596 | enum { | |
597 | /* 1 bit to define user level / supervisor access */ | |
598 | ACCESS_USER = 0x00, | |
599 | ACCESS_SUPER = 0x01, | |
600 | /* 1 bit to indicate direction */ | |
601 | ACCESS_STORE = 0x02, | |
602 | /* Type of instruction that generated the access */ | |
603 | ACCESS_CODE = 0x10, /* Code fetch access */ | |
604 | ACCESS_INT = 0x20, /* Integer load/store access */ | |
605 | ACCESS_FLOAT = 0x30, /* floating point load/store access */ | |
606 | }; | |
607 | ||
608 | /* Exceptions */ | |
609 | enum { | |
610 | EXCP_NONE = -1, | |
611 | EXCP_RESET = 0, | |
612 | EXCP_SRESET, | |
613 | EXCP_DSS, | |
614 | EXCP_DINT, | |
14e51cc7 TS |
615 | EXCP_DDBL, |
616 | EXCP_DDBS, | |
6af0bf9c FB |
617 | EXCP_NMI, |
618 | EXCP_MCHECK, | |
14e51cc7 | 619 | EXCP_EXT_INTERRUPT, /* 8 */ |
6af0bf9c | 620 | EXCP_DFWATCH, |
14e51cc7 | 621 | EXCP_DIB, |
6af0bf9c FB |
622 | EXCP_IWATCH, |
623 | EXCP_AdEL, | |
624 | EXCP_AdES, | |
625 | EXCP_TLBF, | |
626 | EXCP_IBE, | |
14e51cc7 | 627 | EXCP_DBp, /* 16 */ |
6af0bf9c | 628 | EXCP_SYSCALL, |
14e51cc7 | 629 | EXCP_BREAK, |
4ad40f36 | 630 | EXCP_CpU, |
6af0bf9c FB |
631 | EXCP_RI, |
632 | EXCP_OVERFLOW, | |
633 | EXCP_TRAP, | |
5a5012ec | 634 | EXCP_FPE, |
14e51cc7 | 635 | EXCP_DWATCH, /* 24 */ |
6af0bf9c FB |
636 | EXCP_LTLBL, |
637 | EXCP_TLBL, | |
638 | EXCP_TLBS, | |
639 | EXCP_DBE, | |
ead9360e | 640 | EXCP_THREAD, |
14e51cc7 TS |
641 | EXCP_MDMX, |
642 | EXCP_C2E, | |
643 | EXCP_CACHE, /* 32 */ | |
853c3240 | 644 | EXCP_DSPDIS, |
14e51cc7 | 645 | |
853c3240 | 646 | EXCP_LAST = EXCP_DSPDIS, |
6af0bf9c | 647 | }; |
590bc601 PB |
648 | /* Dummy exception for conditional stores. */ |
649 | #define EXCP_SC 0x100 | |
6af0bf9c | 650 | |
f249412c EI |
651 | /* |
652 | * This is an interrnally generated WAKE request line. | |
653 | * It is driven by the CPU itself. Raised when the MT | |
654 | * block wants to wake a VPE from an inactive state and | |
655 | * cleared when VPE goes from active to inactive. | |
656 | */ | |
657 | #define CPU_INTERRUPT_WAKE CPU_INTERRUPT_TGT_INT_0 | |
658 | ||
6af0bf9c | 659 | int cpu_mips_exec(CPUMIPSState *s); |
78ce64f4 | 660 | void mips_tcg_init(void); |
30bf942d | 661 | MIPSCPU *cpu_mips_init(const char *cpu_model); |
388bb21a | 662 | int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc); |
6af0bf9c | 663 | |
30bf942d AF |
664 | static inline CPUMIPSState *cpu_init(const char *cpu_model) |
665 | { | |
666 | MIPSCPU *cpu = cpu_mips_init(cpu_model); | |
667 | if (cpu == NULL) { | |
668 | return NULL; | |
669 | } | |
670 | return &cpu->env; | |
671 | } | |
672 | ||
b7e516ce AF |
673 | /* TODO QOM'ify CPU reset and remove */ |
674 | void cpu_state_reset(CPUMIPSState *s); | |
675 | ||
f9480ffc | 676 | /* mips_timer.c */ |
7db13fae AF |
677 | uint32_t cpu_mips_get_random (CPUMIPSState *env); |
678 | uint32_t cpu_mips_get_count (CPUMIPSState *env); | |
679 | void cpu_mips_store_count (CPUMIPSState *env, uint32_t value); | |
680 | void cpu_mips_store_compare (CPUMIPSState *env, uint32_t value); | |
681 | void cpu_mips_start_count(CPUMIPSState *env); | |
682 | void cpu_mips_stop_count(CPUMIPSState *env); | |
f9480ffc | 683 | |
5dc5d9f0 | 684 | /* mips_int.c */ |
7db13fae | 685 | void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level); |
5dc5d9f0 | 686 | |
f9480ffc | 687 | /* helper.c */ |
7510454e AF |
688 | int mips_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw, |
689 | int mmu_idx); | |
3c7b48b7 | 690 | #if !defined(CONFIG_USER_ONLY) |
7db13fae | 691 | void r4k_invalidate_tlb (CPUMIPSState *env, int idx, int use_extra); |
a8170e5e | 692 | hwaddr cpu_mips_translate_address (CPUMIPSState *env, target_ulong address, |
c36bbb28 | 693 | int rw); |
3c7b48b7 | 694 | #endif |
1239b472 | 695 | target_ulong exception_resume_pc (CPUMIPSState *env); |
f9480ffc | 696 | |
7db13fae | 697 | static inline void cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc, |
6b917547 AL |
698 | target_ulong *cs_base, int *flags) |
699 | { | |
700 | *pc = env->active_tc.PC; | |
701 | *cs_base = 0; | |
d279279e PJ |
702 | *flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK | |
703 | MIPS_HFLAG_HWRENA_ULR); | |
6b917547 AL |
704 | } |
705 | ||
7db13fae | 706 | static inline int mips_vpe_active(CPUMIPSState *env) |
f249412c EI |
707 | { |
708 | int active = 1; | |
709 | ||
710 | /* Check that the VPE is enabled. */ | |
711 | if (!(env->mvp->CP0_MVPControl & (1 << CP0MVPCo_EVP))) { | |
712 | active = 0; | |
713 | } | |
4abf79a4 | 714 | /* Check that the VPE is activated. */ |
f249412c EI |
715 | if (!(env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))) { |
716 | active = 0; | |
717 | } | |
718 | ||
719 | /* Now verify that there are active thread contexts in the VPE. | |
720 | ||
721 | This assumes the CPU model will internally reschedule threads | |
722 | if the active one goes to sleep. If there are no threads available | |
723 | the active one will be in a sleeping state, and we can turn off | |
724 | the entire VPE. */ | |
725 | if (!(env->active_tc.CP0_TCStatus & (1 << CP0TCSt_A))) { | |
726 | /* TC is not activated. */ | |
727 | active = 0; | |
728 | } | |
729 | if (env->active_tc.CP0_TCHalt & 1) { | |
730 | /* TC is in halt state. */ | |
731 | active = 0; | |
732 | } | |
733 | ||
734 | return active; | |
735 | } | |
736 | ||
022c62cb | 737 | #include "exec/exec-all.h" |
f081c76c | 738 | |
03e6e501 MR |
739 | static inline void compute_hflags(CPUMIPSState *env) |
740 | { | |
741 | env->hflags &= ~(MIPS_HFLAG_COP1X | MIPS_HFLAG_64 | MIPS_HFLAG_CP0 | | |
742 | MIPS_HFLAG_F64 | MIPS_HFLAG_FPU | MIPS_HFLAG_KSU | | |
01f72885 | 743 | MIPS_HFLAG_AWRAP | MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2); |
03e6e501 MR |
744 | if (!(env->CP0_Status & (1 << CP0St_EXL)) && |
745 | !(env->CP0_Status & (1 << CP0St_ERL)) && | |
746 | !(env->hflags & MIPS_HFLAG_DM)) { | |
747 | env->hflags |= (env->CP0_Status >> CP0St_KSU) & MIPS_HFLAG_KSU; | |
748 | } | |
749 | #if defined(TARGET_MIPS64) | |
750 | if (((env->hflags & MIPS_HFLAG_KSU) != MIPS_HFLAG_UM) || | |
751 | (env->CP0_Status & (1 << CP0St_PX)) || | |
752 | (env->CP0_Status & (1 << CP0St_UX))) { | |
753 | env->hflags |= MIPS_HFLAG_64; | |
754 | } | |
01f72885 LA |
755 | |
756 | if (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) && | |
757 | !(env->CP0_Status & (1 << CP0St_UX))) { | |
758 | env->hflags |= MIPS_HFLAG_AWRAP; | |
759 | } else if (env->insn_flags & ISA_MIPS32R6) { | |
760 | /* Address wrapping for Supervisor and Kernel is specified in R6 */ | |
761 | if ((((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_SM) && | |
762 | !(env->CP0_Status & (1 << CP0St_SX))) || | |
763 | (((env->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_KM) && | |
764 | !(env->CP0_Status & (1 << CP0St_KX)))) { | |
765 | env->hflags |= MIPS_HFLAG_AWRAP; | |
766 | } | |
03e6e501 MR |
767 | } |
768 | #endif | |
769 | if ((env->CP0_Status & (1 << CP0St_CU0)) || | |
770 | !(env->hflags & MIPS_HFLAG_KSU)) { | |
771 | env->hflags |= MIPS_HFLAG_CP0; | |
772 | } | |
773 | if (env->CP0_Status & (1 << CP0St_CU1)) { | |
774 | env->hflags |= MIPS_HFLAG_FPU; | |
775 | } | |
776 | if (env->CP0_Status & (1 << CP0St_FR)) { | |
777 | env->hflags |= MIPS_HFLAG_F64; | |
778 | } | |
853c3240 JL |
779 | if (env->insn_flags & ASE_DSPR2) { |
780 | /* Enables access MIPS DSP resources, now our cpu is DSP ASER2, | |
781 | so enable to access DSPR2 resources. */ | |
782 | if (env->CP0_Status & (1 << CP0St_MX)) { | |
783 | env->hflags |= MIPS_HFLAG_DSP | MIPS_HFLAG_DSPR2; | |
784 | } | |
785 | ||
786 | } else if (env->insn_flags & ASE_DSP) { | |
787 | /* Enables access MIPS DSP resources, now our cpu is DSP ASE, | |
788 | so enable to access DSP resources. */ | |
789 | if (env->CP0_Status & (1 << CP0St_MX)) { | |
790 | env->hflags |= MIPS_HFLAG_DSP; | |
791 | } | |
792 | ||
793 | } | |
03e6e501 MR |
794 | if (env->insn_flags & ISA_MIPS32R2) { |
795 | if (env->active_fpu.fcr0 & (1 << FCR0_F64)) { | |
796 | env->hflags |= MIPS_HFLAG_COP1X; | |
797 | } | |
798 | } else if (env->insn_flags & ISA_MIPS32) { | |
799 | if (env->hflags & MIPS_HFLAG_64) { | |
800 | env->hflags |= MIPS_HFLAG_COP1X; | |
801 | } | |
802 | } else if (env->insn_flags & ISA_MIPS4) { | |
803 | /* All supported MIPS IV CPUs use the XX (CU3) to enable | |
804 | and disable the MIPS IV extensions to the MIPS III ISA. | |
805 | Some other MIPS IV CPUs ignore the bit, so the check here | |
806 | would be too restrictive for them. */ | |
f45cb2f4 | 807 | if (env->CP0_Status & (1U << CP0St_CU3)) { |
03e6e501 MR |
808 | env->hflags |= MIPS_HFLAG_COP1X; |
809 | } | |
810 | } | |
811 | } | |
812 | ||
6af0bf9c | 813 | #endif /* !defined (__MIPS_CPU_H__) */ |