root / target-mips / cpu.h @ e04bcc69
History | View | Annotate | Download (9.6 kB)
1 |
#if !defined (__MIPS_CPU_H__)
|
---|---|
2 |
#define __MIPS_CPU_H__
|
3 |
|
4 |
#define TARGET_HAS_ICE 1 |
5 |
|
6 |
#define ELF_MACHINE EM_MIPS
|
7 |
|
8 |
#include "config.h" |
9 |
#include "mips-defs.h" |
10 |
#include "cpu-defs.h" |
11 |
#include "softfloat.h" |
12 |
|
13 |
// uint_fast8_t and uint_fast16_t not in <sys/int_types.h>
|
14 |
// XXX: move that elsewhere
|
15 |
#if defined(HOST_SOLARIS) && HOST_SOLARIS < 10 |
16 |
typedef unsigned char uint_fast8_t; |
17 |
typedef unsigned int uint_fast16_t; |
18 |
#endif
|
19 |
|
20 |
typedef union fpr_t fpr_t; |
21 |
union fpr_t {
|
22 |
float64 fd; /* ieee double precision */
|
23 |
float32 fs[2];/* ieee single precision */ |
24 |
uint64_t d; /* binary single fixed-point */
|
25 |
uint32_t w[2]; /* binary single fixed-point */ |
26 |
}; |
27 |
/* define FP_ENDIAN_IDX to access the same location
|
28 |
* in the fpr_t union regardless of the host endianess
|
29 |
*/
|
30 |
#if defined(WORDS_BIGENDIAN)
|
31 |
# define FP_ENDIAN_IDX 1 |
32 |
#else
|
33 |
# define FP_ENDIAN_IDX 0 |
34 |
#endif
|
35 |
|
36 |
#if defined(MIPS_USES_R4K_TLB)
|
37 |
typedef struct tlb_t tlb_t; |
38 |
struct tlb_t {
|
39 |
target_ulong VPN; |
40 |
uint32_t PageMask; |
41 |
uint_fast8_t ASID; |
42 |
uint_fast16_t G:1;
|
43 |
uint_fast16_t C0:3;
|
44 |
uint_fast16_t C1:3;
|
45 |
uint_fast16_t V0:1;
|
46 |
uint_fast16_t V1:1;
|
47 |
uint_fast16_t D0:1;
|
48 |
uint_fast16_t D1:1;
|
49 |
target_ulong PFN[2];
|
50 |
}; |
51 |
#endif
|
52 |
|
53 |
typedef struct CPUMIPSState CPUMIPSState; |
54 |
struct CPUMIPSState {
|
55 |
/* General integer registers */
|
56 |
target_ulong gpr[32];
|
57 |
/* Special registers */
|
58 |
target_ulong PC; |
59 |
#if TARGET_LONG_BITS > HOST_LONG_BITS
|
60 |
target_ulong t0; |
61 |
target_ulong t1; |
62 |
target_ulong t2; |
63 |
#endif
|
64 |
target_ulong HI, LO; |
65 |
/* Floating point registers */
|
66 |
fpr_t fpr[32];
|
67 |
#define FPR(cpu, n) ((fpr_t*)&(cpu)->fpr[(n) / 2]) |
68 |
#define FPR_FD(cpu, n) (FPR(cpu, n)->fd)
|
69 |
#define FPR_FS(cpu, n) (FPR(cpu, n)->fs[((n) & 1) ^ FP_ENDIAN_IDX]) |
70 |
#define FPR_D(cpu, n) (FPR(cpu, n)->d)
|
71 |
#define FPR_W(cpu, n) (FPR(cpu, n)->w[((n) & 1) ^ FP_ENDIAN_IDX]) |
72 |
|
73 |
#ifndef USE_HOST_FLOAT_REGS
|
74 |
fpr_t ft0; |
75 |
fpr_t ft1; |
76 |
fpr_t ft2; |
77 |
#endif
|
78 |
float_status fp_status; |
79 |
/* fpu implementation/revision register */
|
80 |
uint32_t fcr0; |
81 |
/* fcsr */
|
82 |
uint32_t fcr31; |
83 |
#define SET_FP_COND(reg) do { (reg) |= (1<<23); } while(0) |
84 |
#define CLEAR_FP_COND(reg) do { (reg) &= ~(1<<23); } while(0) |
85 |
#define IS_FP_COND_SET(reg) (((reg) & (1<<23)) != 0) |
86 |
#define GET_FP_CAUSE(reg) (((reg) >> 12) & 0x3f) |
87 |
#define GET_FP_ENABLE(reg) (((reg) >> 7) & 0x1f) |
88 |
#define GET_FP_FLAGS(reg) (((reg) >> 2) & 0x1f) |
89 |
#define SET_FP_CAUSE(reg,v) do { (reg) = ((reg) & ~(0x3f << 12)) | ((v) << 12); } while(0) |
90 |
#define SET_FP_ENABLE(reg,v) do { (reg) = ((reg) & ~(0x1f << 7)) | ((v) << 7); } while(0) |
91 |
#define SET_FP_FLAGS(reg,v) do { (reg) = ((reg) & ~(0x1f << 2)) | ((v) << 2); } while(0) |
92 |
#define FP_INEXACT 1 |
93 |
#define FP_UNDERFLOW 2 |
94 |
#define FP_OVERFLOW 4 |
95 |
#define FP_DIV0 8 |
96 |
#define FP_INVALID 16 |
97 |
#define FP_UNIMPLEMENTED 32 |
98 |
|
99 |
#if defined(MIPS_USES_R4K_TLB)
|
100 |
tlb_t tlb[MIPS_TLB_MAX]; |
101 |
uint32_t tlb_in_use; |
102 |
#endif
|
103 |
int32_t CP0_Index; |
104 |
int32_t CP0_Random; |
105 |
target_ulong CP0_EntryLo0; |
106 |
target_ulong CP0_EntryLo1; |
107 |
target_ulong CP0_Context; |
108 |
int32_t CP0_PageMask; |
109 |
int32_t CP0_PageGrain; |
110 |
int32_t CP0_Wired; |
111 |
int32_t CP0_HWREna; |
112 |
target_ulong CP0_BadVAddr; |
113 |
int32_t CP0_Count; |
114 |
target_ulong CP0_EntryHi; |
115 |
int32_t CP0_Compare; |
116 |
int32_t CP0_Status; |
117 |
#define CP0St_CU3 31 |
118 |
#define CP0St_CU2 30 |
119 |
#define CP0St_CU1 29 |
120 |
#define CP0St_CU0 28 |
121 |
#define CP0St_RP 27 |
122 |
#define CP0St_FR 26 |
123 |
#define CP0St_RE 25 |
124 |
#define CP0St_MX 24 |
125 |
#define CP0St_PX 23 |
126 |
#define CP0St_BEV 22 |
127 |
#define CP0St_TS 21 |
128 |
#define CP0St_SR 20 |
129 |
#define CP0St_NMI 19 |
130 |
#define CP0St_IM 8 |
131 |
#define CP0St_KX 7 |
132 |
#define CP0St_SX 6 |
133 |
#define CP0St_UX 5 |
134 |
#define CP0St_UM 4 |
135 |
#define CP0St_R0 3 |
136 |
#define CP0St_ERL 2 |
137 |
#define CP0St_EXL 1 |
138 |
#define CP0St_IE 0 |
139 |
int32_t CP0_IntCtl; |
140 |
int32_t CP0_SRSCtl; |
141 |
int32_t CP0_SRSMap; |
142 |
int32_t CP0_Cause; |
143 |
#define CP0Ca_BD 31 |
144 |
#define CP0Ca_TI 30 |
145 |
#define CP0Ca_CE 28 |
146 |
#define CP0Ca_DC 27 |
147 |
#define CP0Ca_PCI 26 |
148 |
#define CP0Ca_IV 23 |
149 |
#define CP0Ca_WP 22 |
150 |
#define CP0Ca_IP 8 |
151 |
#define CP0Ca_IP_mask 0x0000FF00 |
152 |
#define CP0Ca_EC 2 |
153 |
target_ulong CP0_EPC; |
154 |
int32_t CP0_PRid; |
155 |
int32_t CP0_EBase; |
156 |
int32_t CP0_Config0; |
157 |
#define CP0C0_M 31 |
158 |
#define CP0C0_K23 28 |
159 |
#define CP0C0_KU 25 |
160 |
#define CP0C0_MDU 20 |
161 |
#define CP0C0_MM 17 |
162 |
#define CP0C0_BM 16 |
163 |
#define CP0C0_BE 15 |
164 |
#define CP0C0_AT 13 |
165 |
#define CP0C0_AR 10 |
166 |
#define CP0C0_MT 7 |
167 |
#define CP0C0_VI 3 |
168 |
#define CP0C0_K0 0 |
169 |
int32_t CP0_Config1; |
170 |
#define CP0C1_M 31 |
171 |
#define CP0C1_MMU 25 |
172 |
#define CP0C1_IS 22 |
173 |
#define CP0C1_IL 19 |
174 |
#define CP0C1_IA 16 |
175 |
#define CP0C1_DS 13 |
176 |
#define CP0C1_DL 10 |
177 |
#define CP0C1_DA 7 |
178 |
#define CP0C1_C2 6 |
179 |
#define CP0C1_MD 5 |
180 |
#define CP0C1_PC 4 |
181 |
#define CP0C1_WR 3 |
182 |
#define CP0C1_CA 2 |
183 |
#define CP0C1_EP 1 |
184 |
#define CP0C1_FP 0 |
185 |
int32_t CP0_Config2; |
186 |
#define CP0C2_M 31 |
187 |
#define CP0C2_TU 28 |
188 |
#define CP0C2_TS 24 |
189 |
#define CP0C2_TL 20 |
190 |
#define CP0C2_TA 16 |
191 |
#define CP0C2_SU 12 |
192 |
#define CP0C2_SS 8 |
193 |
#define CP0C2_SL 4 |
194 |
#define CP0C2_SA 0 |
195 |
int32_t CP0_Config3; |
196 |
#define CP0C3_M 31 |
197 |
#define CP0C3_DSPP 10 |
198 |
#define CP0C3_LPA 7 |
199 |
#define CP0C3_VEIC 6 |
200 |
#define CP0C3_VInt 5 |
201 |
#define CP0C3_SP 4 |
202 |
#define CP0C3_MT 2 |
203 |
#define CP0C3_SM 1 |
204 |
#define CP0C3_TL 0 |
205 |
int32_t CP0_Config6; |
206 |
int32_t CP0_Config7; |
207 |
target_ulong CP0_LLAddr; |
208 |
target_ulong CP0_WatchLo; |
209 |
int32_t CP0_WatchHi; |
210 |
target_ulong CP0_XContext; |
211 |
int32_t CP0_Framemask; |
212 |
int32_t CP0_Debug; |
213 |
#define CPDB_DBD 31 |
214 |
#define CP0DB_DM 30 |
215 |
#define CP0DB_LSNM 28 |
216 |
#define CP0DB_Doze 27 |
217 |
#define CP0DB_Halt 26 |
218 |
#define CP0DB_CNT 25 |
219 |
#define CP0DB_IBEP 24 |
220 |
#define CP0DB_DBEP 21 |
221 |
#define CP0DB_IEXI 20 |
222 |
#define CP0DB_VER 15 |
223 |
#define CP0DB_DEC 10 |
224 |
#define CP0DB_SSt 8 |
225 |
#define CP0DB_DINT 5 |
226 |
#define CP0DB_DIB 4 |
227 |
#define CP0DB_DDBS 3 |
228 |
#define CP0DB_DDBL 2 |
229 |
#define CP0DB_DBp 1 |
230 |
#define CP0DB_DSS 0 |
231 |
target_ulong CP0_DEPC; |
232 |
int32_t CP0_Performance0; |
233 |
int32_t CP0_TagLo; |
234 |
int32_t CP0_DataLo; |
235 |
int32_t CP0_TagHi; |
236 |
int32_t CP0_DataHi; |
237 |
target_ulong CP0_ErrorEPC; |
238 |
int32_t CP0_DESAVE; |
239 |
/* Qemu */
|
240 |
int interrupt_request;
|
241 |
jmp_buf jmp_env; |
242 |
int exception_index;
|
243 |
int error_code;
|
244 |
int user_mode_only; /* user mode only simulation */ |
245 |
uint32_t hflags; /* CPU State */
|
246 |
/* TMASK defines different execution modes */
|
247 |
#define MIPS_HFLAG_TMASK 0x007F |
248 |
#define MIPS_HFLAG_MODE 0x001F /* execution modes */ |
249 |
#define MIPS_HFLAG_UM 0x0001 /* user mode */ |
250 |
#define MIPS_HFLAG_DM 0x0008 /* Debug mode */ |
251 |
#define MIPS_HFLAG_SM 0x0010 /* Supervisor mode */ |
252 |
#define MIPS_HFLAG_RE 0x0040 /* Reversed endianness */ |
253 |
/* If translation is interrupted between the branch instruction and
|
254 |
* the delay slot, record what type of branch it is so that we can
|
255 |
* resume translation properly. It might be possible to reduce
|
256 |
* this from three bits to two. */
|
257 |
#define MIPS_HFLAG_BMASK 0x0380 |
258 |
#define MIPS_HFLAG_B 0x0080 /* Unconditional branch */ |
259 |
#define MIPS_HFLAG_BC 0x0100 /* Conditional branch */ |
260 |
#define MIPS_HFLAG_BL 0x0180 /* Likely branch */ |
261 |
#define MIPS_HFLAG_BR 0x0200 /* branch to register (can't link TB) */ |
262 |
target_ulong btarget; /* Jump / branch target */
|
263 |
int bcond; /* Branch condition (if needed) */ |
264 |
|
265 |
int halted; /* TRUE if the CPU is in suspend state */ |
266 |
|
267 |
int SYNCI_Step; /* Address step size for SYNCI */ |
268 |
int CCRes; /* Cycle count resolution/divisor */ |
269 |
|
270 |
#if defined(CONFIG_USER_ONLY)
|
271 |
target_ulong tls_value; |
272 |
#endif
|
273 |
|
274 |
CPU_COMMON |
275 |
|
276 |
int ram_size;
|
277 |
const char *kernel_filename; |
278 |
const char *kernel_cmdline; |
279 |
const char *initrd_filename; |
280 |
|
281 |
struct QEMUTimer *timer; /* Internal timer */ |
282 |
}; |
283 |
|
284 |
typedef struct mips_def_t mips_def_t; |
285 |
int mips_find_by_name (const unsigned char *name, mips_def_t **def); |
286 |
void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...)); |
287 |
int cpu_mips_register (CPUMIPSState *env, mips_def_t *def);
|
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, |
325 |
EXCP_BREAK, /* 16 */
|
326 |
EXCP_CpU, |
327 |
EXCP_RI, |
328 |
EXCP_OVERFLOW, |
329 |
EXCP_TRAP, |
330 |
EXCP_DDBS, |
331 |
EXCP_DWATCH, |
332 |
EXCP_LAE, |
333 |
EXCP_SAE, /* 24 */
|
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 |
|
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__) */ |