Statistics
| Branch: | Revision:

root / target-mips / cpu.h @ fcb4a419

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