]>
Commit | Line | Data |
---|---|---|
6af0bf9c FB |
1 | #if !defined (__MIPS_CPU_H__) |
2 | #define __MIPS_CPU_H__ | |
3 | ||
4ad40f36 FB |
4 | #define TARGET_HAS_ICE 1 |
5 | ||
9042c0e2 TS |
6 | #define ELF_MACHINE EM_MIPS |
7 | ||
c5d6edc3 | 8 | #include "config.h" |
6af0bf9c FB |
9 | #include "mips-defs.h" |
10 | #include "cpu-defs.h" | |
6af0bf9c FB |
11 | #include "softfloat.h" |
12 | ||
fdbb4691 FB |
13 | // uint_fast8_t and uint_fast16_t not in <sys/int_types.h> |
14 | // XXX: move that elsewhere | |
15 | #if defined(HOST_SOLARIS) && SOLARISREV < 10 | |
16 | typedef unsigned char uint_fast8_t; | |
17 | typedef unsigned int uint_fast16_t; | |
18 | #endif | |
19 | ||
c570fd16 | 20 | /* target_ulong size spec */ |
5dc4b744 | 21 | #ifdef MIPS_HAS_MIPS64 |
c570fd16 TS |
22 | #define TLSZ "%016llx" |
23 | #else | |
c570fd16 TS |
24 | #define TLSZ "%08x" |
25 | #endif | |
26 | ||
6af0bf9c FB |
27 | typedef union fpr_t fpr_t; |
28 | union fpr_t { | |
6ea83fed FB |
29 | float64 fd; /* ieee double precision */ |
30 | float32 fs[2];/* ieee single precision */ | |
31 | uint64_t d; /* binary single fixed-point */ | |
32 | uint32_t w[2]; /* binary single fixed-point */ | |
6af0bf9c | 33 | }; |
6ea83fed FB |
34 | /* define FP_ENDIAN_IDX to access the same location |
35 | * in the fpr_t union regardless of the host endianess | |
36 | */ | |
37 | #if defined(WORDS_BIGENDIAN) | |
38 | # define FP_ENDIAN_IDX 1 | |
39 | #else | |
40 | # define FP_ENDIAN_IDX 0 | |
41 | #endif | |
6af0bf9c FB |
42 | |
43 | #if defined(MIPS_USES_R4K_TLB) | |
44 | typedef struct tlb_t tlb_t; | |
45 | struct tlb_t { | |
46 | target_ulong VPN; | |
47 | target_ulong end; | |
4ad40f36 | 48 | target_ulong end2; |
98c1b82b PB |
49 | uint_fast8_t ASID; |
50 | uint_fast16_t G:1; | |
51 | uint_fast16_t C0:3; | |
52 | uint_fast16_t C1:3; | |
53 | uint_fast16_t V0:1; | |
54 | uint_fast16_t V1:1; | |
55 | uint_fast16_t D0:1; | |
56 | uint_fast16_t D1:1; | |
6af0bf9c FB |
57 | target_ulong PFN[2]; |
58 | }; | |
59 | #endif | |
60 | ||
61 | typedef struct CPUMIPSState CPUMIPSState; | |
62 | struct CPUMIPSState { | |
63 | /* General integer registers */ | |
64 | target_ulong gpr[32]; | |
65 | /* Special registers */ | |
66 | target_ulong PC; | |
c570fd16 TS |
67 | #if TARGET_LONG_BITS > HOST_LONG_BITS |
68 | target_ulong t0; | |
69 | target_ulong t1; | |
70 | target_ulong t2; | |
71 | #endif | |
72 | target_ulong HI, LO; | |
6af0bf9c FB |
73 | uint32_t DCR; /* ? */ |
74 | #if defined(MIPS_USES_FPU) | |
75 | /* Floating point registers */ | |
76 | fpr_t fpr[16]; | |
6ea83fed FB |
77 | #define FPR(cpu, n) ((fpr_t*)&(cpu)->fpr[(n) / 2]) |
78 | #define FPR_FD(cpu, n) (FPR(cpu, n)->fd) | |
79 | #define FPR_FS(cpu, n) (FPR(cpu, n)->fs[((n) & 1) ^ FP_ENDIAN_IDX]) | |
80 | #define FPR_D(cpu, n) (FPR(cpu, n)->d) | |
81 | #define FPR_W(cpu, n) (FPR(cpu, n)->w[((n) & 1) ^ FP_ENDIAN_IDX]) | |
82 | ||
83 | #ifndef USE_HOST_FLOAT_REGS | |
84 | fpr_t ft0; | |
85 | fpr_t ft1; | |
86 | fpr_t ft2; | |
87 | #endif | |
88 | float_status fp_status; | |
89 | /* fpu implementation/revision register */ | |
6af0bf9c | 90 | uint32_t fcr0; |
6ea83fed FB |
91 | /* fcsr */ |
92 | uint32_t fcr31; | |
93 | #define SET_FP_COND(reg) do { (reg) |= (1<<23); } while(0) | |
94 | #define CLEAR_FP_COND(reg) do { (reg) &= ~(1<<23); } while(0) | |
95 | #define IS_FP_COND_SET(reg) (((reg) & (1<<23)) != 0) | |
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) << 12); } while(0) | |
100 | #define SET_FP_ENABLE(reg,v) do { (reg) = ((reg) & ~(0x1f << 7)) | ((v) << 7); } while(0) | |
101 | #define SET_FP_FLAGS(reg,v) do { (reg) = ((reg) & ~(0x1f << 2)) | ((v) << 2); } while(0) | |
102 | #define FP_INEXACT 1 | |
103 | #define FP_UNDERFLOW 2 | |
104 | #define FP_OVERFLOW 4 | |
105 | #define FP_DIV0 8 | |
106 | #define FP_INVALID 16 | |
107 | #define FP_UNIMPLEMENTED 32 | |
108 | ||
6af0bf9c FB |
109 | #endif |
110 | #if defined(MIPS_USES_R4K_TLB) | |
814b9a47 TS |
111 | tlb_t tlb[MIPS_TLB_MAX]; |
112 | uint32_t tlb_in_use; | |
6af0bf9c FB |
113 | #endif |
114 | uint32_t CP0_index; | |
115 | uint32_t CP0_random; | |
7a387fff TS |
116 | uint64_t CP0_EntryLo0; |
117 | uint64_t CP0_EntryLo1; | |
118 | uint64_t CP0_Context; | |
6af0bf9c | 119 | uint32_t CP0_PageMask; |
7a387fff | 120 | uint32_t CP0_PageGrain; |
6af0bf9c | 121 | uint32_t CP0_Wired; |
7a387fff | 122 | uint32_t CP0_HWREna; |
c570fd16 | 123 | target_ulong CP0_BadVAddr; |
6af0bf9c | 124 | uint32_t CP0_Count; |
7a387fff | 125 | uint64_t CP0_EntryHi; |
6af0bf9c FB |
126 | uint32_t CP0_Compare; |
127 | uint32_t CP0_Status; | |
128 | #define CP0St_CU3 31 | |
129 | #define CP0St_CU2 30 | |
130 | #define CP0St_CU1 29 | |
131 | #define CP0St_CU0 28 | |
132 | #define CP0St_RP 27 | |
6ea83fed | 133 | #define CP0St_FR 26 |
6af0bf9c | 134 | #define CP0St_RE 25 |
7a387fff TS |
135 | #define CP0St_MX 24 |
136 | #define CP0St_PX 23 | |
6af0bf9c FB |
137 | #define CP0St_BEV 22 |
138 | #define CP0St_TS 21 | |
139 | #define CP0St_SR 20 | |
140 | #define CP0St_NMI 19 | |
141 | #define CP0St_IM 8 | |
7a387fff TS |
142 | #define CP0St_KX 7 |
143 | #define CP0St_SX 6 | |
144 | #define CP0St_UX 5 | |
6af0bf9c | 145 | #define CP0St_UM 4 |
7a387fff | 146 | #define CP0St_R0 3 |
6af0bf9c FB |
147 | #define CP0St_ERL 2 |
148 | #define CP0St_EXL 1 | |
149 | #define CP0St_IE 0 | |
7a387fff TS |
150 | uint32_t CP0_IntCtl; |
151 | uint32_t CP0_SRSCtl; | |
6af0bf9c | 152 | uint32_t CP0_Cause; |
7a387fff TS |
153 | #define CP0Ca_BD 31 |
154 | #define CP0Ca_TI 30 | |
155 | #define CP0Ca_CE 28 | |
156 | #define CP0Ca_DC 27 | |
157 | #define CP0Ca_PCI 26 | |
6af0bf9c | 158 | #define CP0Ca_IV 23 |
7a387fff TS |
159 | #define CP0Ca_WP 22 |
160 | #define CP0Ca_IP 8 | |
161 | #define CP0Ca_EC 2 | |
c570fd16 | 162 | target_ulong CP0_EPC; |
6af0bf9c | 163 | uint32_t CP0_PRid; |
c570fd16 | 164 | target_ulong CP0_EBase; |
6af0bf9c FB |
165 | uint32_t CP0_Config0; |
166 | #define CP0C0_M 31 | |
167 | #define CP0C0_K23 28 | |
168 | #define CP0C0_KU 25 | |
169 | #define CP0C0_MDU 20 | |
170 | #define CP0C0_MM 17 | |
171 | #define CP0C0_BM 16 | |
172 | #define CP0C0_BE 15 | |
173 | #define CP0C0_AT 13 | |
174 | #define CP0C0_AR 10 | |
175 | #define CP0C0_MT 7 | |
7a387fff | 176 | #define CP0C0_VI 3 |
6af0bf9c FB |
177 | #define CP0C0_K0 0 |
178 | uint32_t CP0_Config1; | |
7a387fff | 179 | #define CP0C1_M 31 |
6af0bf9c FB |
180 | #define CP0C1_MMU 25 |
181 | #define CP0C1_IS 22 | |
182 | #define CP0C1_IL 19 | |
183 | #define CP0C1_IA 16 | |
184 | #define CP0C1_DS 13 | |
185 | #define CP0C1_DL 10 | |
186 | #define CP0C1_DA 7 | |
7a387fff TS |
187 | #define CP0C1_C2 6 |
188 | #define CP0C1_MD 5 | |
6af0bf9c FB |
189 | #define CP0C1_PC 4 |
190 | #define CP0C1_WR 3 | |
191 | #define CP0C1_CA 2 | |
192 | #define CP0C1_EP 1 | |
193 | #define CP0C1_FP 0 | |
7a387fff TS |
194 | uint32_t CP0_Config2; |
195 | #define CP0C2_M 31 | |
196 | #define CP0C2_TU 28 | |
197 | #define CP0C2_TS 24 | |
198 | #define CP0C2_TL 20 | |
199 | #define CP0C2_TA 16 | |
200 | #define CP0C2_SU 12 | |
201 | #define CP0C2_SS 8 | |
202 | #define CP0C2_SL 4 | |
203 | #define CP0C2_SA 0 | |
204 | uint32_t CP0_Config3; | |
205 | #define CP0C3_M 31 | |
206 | #define CP0C3_DSPP 10 | |
207 | #define CP0C3_LPA 7 | |
208 | #define CP0C3_VEIC 6 | |
209 | #define CP0C3_VInt 5 | |
210 | #define CP0C3_SP 4 | |
211 | #define CP0C3_MT 2 | |
212 | #define CP0C3_SM 1 | |
213 | #define CP0C3_TL 0 | |
c570fd16 | 214 | target_ulong CP0_LLAddr; |
6af0bf9c FB |
215 | uint32_t CP0_WatchLo; |
216 | uint32_t CP0_WatchHi; | |
7a387fff TS |
217 | uint32_t CP0_XContext; |
218 | uint32_t CP0_Framemask; | |
6af0bf9c FB |
219 | uint32_t CP0_Debug; |
220 | #define CPDB_DBD 31 | |
221 | #define CP0DB_DM 30 | |
222 | #define CP0DB_LSNM 28 | |
223 | #define CP0DB_Doze 27 | |
224 | #define CP0DB_Halt 26 | |
225 | #define CP0DB_CNT 25 | |
226 | #define CP0DB_IBEP 24 | |
227 | #define CP0DB_DBEP 21 | |
228 | #define CP0DB_IEXI 20 | |
229 | #define CP0DB_VER 15 | |
230 | #define CP0DB_DEC 10 | |
231 | #define CP0DB_SSt 8 | |
232 | #define CP0DB_DINT 5 | |
233 | #define CP0DB_DIB 4 | |
234 | #define CP0DB_DDBS 3 | |
235 | #define CP0DB_DDBL 2 | |
236 | #define CP0DB_DBp 1 | |
237 | #define CP0DB_DSS 0 | |
c570fd16 | 238 | target_ulong CP0_DEPC; |
7a387fff | 239 | uint32_t CP0_Performance0; |
6af0bf9c FB |
240 | uint32_t CP0_TagLo; |
241 | uint32_t CP0_DataLo; | |
7a387fff TS |
242 | uint32_t CP0_TagHi; |
243 | uint32_t CP0_DataHi; | |
c570fd16 | 244 | target_ulong CP0_ErrorEPC; |
6af0bf9c FB |
245 | uint32_t CP0_DESAVE; |
246 | /* Qemu */ | |
6af0bf9c FB |
247 | int interrupt_request; |
248 | jmp_buf jmp_env; | |
249 | int exception_index; | |
250 | int error_code; | |
251 | int user_mode_only; /* user mode only simulation */ | |
252 | uint32_t hflags; /* CPU State */ | |
253 | /* TMASK defines different execution modes */ | |
56b19403 | 254 | #define MIPS_HFLAG_TMASK 0x007F |
6af0bf9c FB |
255 | #define MIPS_HFLAG_MODE 0x001F /* execution modes */ |
256 | #define MIPS_HFLAG_UM 0x0001 /* user mode */ | |
257 | #define MIPS_HFLAG_ERL 0x0002 /* Error mode */ | |
258 | #define MIPS_HFLAG_EXL 0x0004 /* Exception mode */ | |
259 | #define MIPS_HFLAG_DM 0x0008 /* Debug mode */ | |
260 | #define MIPS_HFLAG_SM 0x0010 /* Supervisor mode */ | |
261 | #define MIPS_HFLAG_RE 0x0040 /* Reversed endianness */ | |
4ad40f36 FB |
262 | /* If translation is interrupted between the branch instruction and |
263 | * the delay slot, record what type of branch it is so that we can | |
264 | * resume translation properly. It might be possible to reduce | |
265 | * this from three bits to two. */ | |
266 | #define MIPS_HFLAG_BMASK 0x0380 | |
267 | #define MIPS_HFLAG_B 0x0080 /* Unconditional branch */ | |
268 | #define MIPS_HFLAG_BC 0x0100 /* Conditional branch */ | |
269 | #define MIPS_HFLAG_BL 0x0180 /* Likely branch */ | |
270 | #define MIPS_HFLAG_BR 0x0200 /* branch to register (can't link TB) */ | |
6af0bf9c FB |
271 | target_ulong btarget; /* Jump / branch target */ |
272 | int bcond; /* Branch condition (if needed) */ | |
a316d335 | 273 | |
4ad40f36 FB |
274 | int halted; /* TRUE if the CPU is in suspend state */ |
275 | ||
7a387fff TS |
276 | int SYNCI_Step; /* Address step size for SYNCI */ |
277 | int CCRes; /* Cycle count resolution/divisor */ | |
278 | ||
a316d335 | 279 | CPU_COMMON |
6ae81775 TS |
280 | |
281 | int ram_size; | |
282 | const char *kernel_filename; | |
283 | const char *kernel_cmdline; | |
284 | const char *initrd_filename; | |
285 | ||
286 | struct QEMUTimer *timer; /* Internal timer */ | |
6af0bf9c FB |
287 | }; |
288 | ||
289 | #include "cpu-all.h" | |
290 | ||
291 | /* Memory access type : | |
292 | * may be needed for precise access rights control and precise exceptions. | |
293 | */ | |
294 | enum { | |
295 | /* 1 bit to define user level / supervisor access */ | |
296 | ACCESS_USER = 0x00, | |
297 | ACCESS_SUPER = 0x01, | |
298 | /* 1 bit to indicate direction */ | |
299 | ACCESS_STORE = 0x02, | |
300 | /* Type of instruction that generated the access */ | |
301 | ACCESS_CODE = 0x10, /* Code fetch access */ | |
302 | ACCESS_INT = 0x20, /* Integer load/store access */ | |
303 | ACCESS_FLOAT = 0x30, /* floating point load/store access */ | |
304 | }; | |
305 | ||
306 | /* Exceptions */ | |
307 | enum { | |
308 | EXCP_NONE = -1, | |
309 | EXCP_RESET = 0, | |
310 | EXCP_SRESET, | |
311 | EXCP_DSS, | |
312 | EXCP_DINT, | |
313 | EXCP_NMI, | |
314 | EXCP_MCHECK, | |
315 | EXCP_EXT_INTERRUPT, | |
316 | EXCP_DFWATCH, | |
317 | EXCP_DIB, /* 8 */ | |
318 | EXCP_IWATCH, | |
319 | EXCP_AdEL, | |
320 | EXCP_AdES, | |
321 | EXCP_TLBF, | |
322 | EXCP_IBE, | |
323 | EXCP_DBp, | |
324 | EXCP_SYSCALL, | |
4ad40f36 FB |
325 | EXCP_BREAK, /* 16 */ |
326 | EXCP_CpU, | |
6af0bf9c FB |
327 | EXCP_RI, |
328 | EXCP_OVERFLOW, | |
329 | EXCP_TRAP, | |
330 | EXCP_DDBS, | |
331 | EXCP_DWATCH, | |
4ad40f36 FB |
332 | EXCP_LAE, |
333 | EXCP_SAE, /* 24 */ | |
6af0bf9c FB |
334 | EXCP_LTLBL, |
335 | EXCP_TLBL, | |
336 | EXCP_TLBS, | |
337 | EXCP_DBE, | |
338 | EXCP_DDBL, | |
339 | EXCP_MTCP0 = 0x104, /* mtmsr instruction: */ | |
340 | /* may change privilege level */ | |
341 | EXCP_BRANCH = 0x108, /* branch instruction */ | |
342 | EXCP_ERET = 0x10C, /* return from interrupt */ | |
343 | EXCP_SYSCALL_USER = 0x110, /* System call in user mode only */ | |
344 | EXCP_FLUSH = 0x109, | |
345 | }; | |
346 | ||
6af0bf9c FB |
347 | int cpu_mips_exec(CPUMIPSState *s); |
348 | CPUMIPSState *cpu_mips_init(void); | |
349 | uint32_t cpu_mips_get_clock (void); | |
350 | ||
351 | #endif /* !defined (__MIPS_CPU_H__) */ |