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