]> git.proxmox.com Git - mirror_qemu.git/blame - target-mips/cpu.h
Fix DMA timeouts on FreeBSD, by Carlo Marcelo Arenas Belon.
[mirror_qemu.git] / target-mips / cpu.h
CommitLineData
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
16typedef unsigned char uint_fast8_t;
17typedef 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
27typedef union fpr_t fpr_t;
28union 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)
44typedef struct tlb_t tlb_t;
45struct tlb_t {
46 target_ulong VPN;
9c2149c8 47 uint32_t PageMask;
98c1b82b
PB
48 uint_fast8_t ASID;
49 uint_fast16_t G:1;
50 uint_fast16_t C0:3;
51 uint_fast16_t C1:3;
52 uint_fast16_t V0:1;
53 uint_fast16_t V1:1;
54 uint_fast16_t D0:1;
55 uint_fast16_t D1:1;
6af0bf9c
FB
56 target_ulong PFN[2];
57};
58#endif
59
60typedef struct CPUMIPSState CPUMIPSState;
61struct CPUMIPSState {
62 /* General integer registers */
63 target_ulong gpr[32];
64 /* Special registers */
65 target_ulong PC;
c570fd16
TS
66#if TARGET_LONG_BITS > HOST_LONG_BITS
67 target_ulong t0;
68 target_ulong t1;
69 target_ulong t2;
70#endif
71 target_ulong HI, LO;
6af0bf9c
FB
72 uint32_t DCR; /* ? */
73#if defined(MIPS_USES_FPU)
74 /* Floating point registers */
75 fpr_t fpr[16];
6ea83fed
FB
76#define FPR(cpu, n) ((fpr_t*)&(cpu)->fpr[(n) / 2])
77#define FPR_FD(cpu, n) (FPR(cpu, n)->fd)
78#define FPR_FS(cpu, n) (FPR(cpu, n)->fs[((n) & 1) ^ FP_ENDIAN_IDX])
79#define FPR_D(cpu, n) (FPR(cpu, n)->d)
80#define FPR_W(cpu, n) (FPR(cpu, n)->w[((n) & 1) ^ FP_ENDIAN_IDX])
81
82#ifndef USE_HOST_FLOAT_REGS
83 fpr_t ft0;
84 fpr_t ft1;
85 fpr_t ft2;
86#endif
87 float_status fp_status;
88 /* fpu implementation/revision register */
6af0bf9c 89 uint32_t fcr0;
6ea83fed
FB
90 /* fcsr */
91 uint32_t fcr31;
92#define SET_FP_COND(reg) do { (reg) |= (1<<23); } while(0)
93#define CLEAR_FP_COND(reg) do { (reg) &= ~(1<<23); } while(0)
94#define IS_FP_COND_SET(reg) (((reg) & (1<<23)) != 0)
95#define GET_FP_CAUSE(reg) (((reg) >> 12) & 0x3f)
96#define GET_FP_ENABLE(reg) (((reg) >> 7) & 0x1f)
97#define GET_FP_FLAGS(reg) (((reg) >> 2) & 0x1f)
98#define SET_FP_CAUSE(reg,v) do { (reg) = ((reg) & ~(0x3f << 12)) | ((v) << 12); } while(0)
99#define SET_FP_ENABLE(reg,v) do { (reg) = ((reg) & ~(0x1f << 7)) | ((v) << 7); } while(0)
100#define SET_FP_FLAGS(reg,v) do { (reg) = ((reg) & ~(0x1f << 2)) | ((v) << 2); } while(0)
101#define FP_INEXACT 1
102#define FP_UNDERFLOW 2
103#define FP_OVERFLOW 4
104#define FP_DIV0 8
105#define FP_INVALID 16
106#define FP_UNIMPLEMENTED 32
107
6af0bf9c
FB
108#endif
109#if defined(MIPS_USES_R4K_TLB)
814b9a47
TS
110 tlb_t tlb[MIPS_TLB_MAX];
111 uint32_t tlb_in_use;
6af0bf9c 112#endif
9c2149c8
TS
113 int32_t CP0_Index;
114 int32_t CP0_Random;
115 target_ulong CP0_EntryLo0;
116 target_ulong CP0_EntryLo1;
117 target_ulong CP0_Context;
118 int32_t CP0_PageMask;
119 int32_t CP0_PageGrain;
120 int32_t CP0_Wired;
121 int32_t CP0_HWREna;
c570fd16 122 target_ulong CP0_BadVAddr;
9c2149c8
TS
123 int32_t CP0_Count;
124 target_ulong CP0_EntryHi;
125 int32_t CP0_Compare;
126 int32_t CP0_Status;
6af0bf9c
FB
127#define CP0St_CU3 31
128#define CP0St_CU2 30
129#define CP0St_CU1 29
130#define CP0St_CU0 28
131#define CP0St_RP 27
6ea83fed 132#define CP0St_FR 26
6af0bf9c 133#define CP0St_RE 25
7a387fff
TS
134#define CP0St_MX 24
135#define CP0St_PX 23
6af0bf9c
FB
136#define CP0St_BEV 22
137#define CP0St_TS 21
138#define CP0St_SR 20
139#define CP0St_NMI 19
140#define CP0St_IM 8
7a387fff
TS
141#define CP0St_KX 7
142#define CP0St_SX 6
143#define CP0St_UX 5
6af0bf9c 144#define CP0St_UM 4
7a387fff 145#define CP0St_R0 3
6af0bf9c
FB
146#define CP0St_ERL 2
147#define CP0St_EXL 1
148#define CP0St_IE 0
9c2149c8
TS
149 int32_t CP0_IntCtl;
150 int32_t CP0_SRSCtl;
151 int32_t CP0_SRSMap;
152 int32_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;
9c2149c8 163 int32_t CP0_PRid;
c570fd16 164 target_ulong CP0_EBase;
9c2149c8 165 int32_t CP0_Config0;
6af0bf9c
FB
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 177#define CP0C0_K0 0
9c2149c8 178 int32_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
9c2149c8 194 int32_t CP0_Config2;
7a387fff
TS
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
9c2149c8 204 int32_t CP0_Config3;
7a387fff
TS
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;
9c2149c8
TS
215 target_ulong CP0_WatchLo;
216 int32_t CP0_WatchHi;
217 target_ulong CP0_XContext;
218 int32_t CP0_Framemask;
219 int32_t CP0_Debug;
6af0bf9c
FB
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;
9c2149c8
TS
239 int32_t CP0_Performance0;
240 int32_t CP0_TagLo;
241 int32_t CP0_DataLo;
242 int32_t CP0_TagHi;
243 int32_t CP0_DataHi;
c570fd16 244 target_ulong CP0_ErrorEPC;
9c2149c8 245 int32_t CP0_DESAVE;
6af0bf9c 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 */
294enum {
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 */
307enum {
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
347int cpu_mips_exec(CPUMIPSState *s);
348CPUMIPSState *cpu_mips_init(void);
349uint32_t cpu_mips_get_clock (void);
350
351#endif /* !defined (__MIPS_CPU_H__) */