Statistics
| Branch: | Revision:

root / target-mips / cpu.h @ ea785922

History | View | Annotate | Download (9.5 kB)

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