Statistics
| Branch: | Revision:

root / target-mips / cpu.h @ 3b1c8be4

History | View | Annotate | Download (9.5 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) && SOLARISREV < 10
16
typedef unsigned char           uint_fast8_t;
17
typedef unsigned int            uint_fast16_t;
18
#endif
19

    
20
/* target_ulong size spec */
21
#ifdef MIPS_HAS_MIPS64
22
#define TLSZ "%016llx"
23
#else
24
#define TLSZ "%08x"
25
#endif
26

    
27
typedef union fpr_t fpr_t;
28
union fpr_t {
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 */
33
};
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
42

    
43
#if defined(MIPS_USES_R4K_TLB)
44
typedef struct tlb_t tlb_t;
45
struct tlb_t {
46
    target_ulong VPN;
47
    uint_fast32_t PageMask;
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;
56
    target_ulong PFN[2];
57
};
58
#endif
59

    
60
typedef struct CPUMIPSState CPUMIPSState;
61
struct CPUMIPSState {
62
    /* General integer registers */
63
    target_ulong gpr[32];
64
    /* Special registers */
65
    target_ulong PC;
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;
72
    uint32_t DCR; /* ? */
73
#if defined(MIPS_USES_FPU)
74
    /* Floating point registers */
75
    fpr_t fpr[16];
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 */
89
    uint32_t fcr0;
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
                
108
#endif
109
#if defined(MIPS_USES_R4K_TLB)
110
    tlb_t tlb[MIPS_TLB_MAX];
111
    uint32_t tlb_in_use;
112
#endif
113
    uint32_t CP0_index;
114
    uint32_t CP0_random;
115
    uint64_t CP0_EntryLo0;
116
    uint64_t CP0_EntryLo1;
117
    uint64_t CP0_Context;
118
    uint32_t CP0_PageMask;
119
    uint32_t CP0_PageGrain;
120
    uint32_t CP0_Wired;
121
    uint32_t CP0_HWREna;
122
    target_ulong CP0_BadVAddr;
123
    uint32_t CP0_Count;
124
    uint64_t CP0_EntryHi;
125
    uint32_t CP0_Compare;
126
    uint32_t CP0_Status;
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
132
#define CP0St_FR    26
133
#define CP0St_RE    25
134
#define CP0St_MX    24
135
#define CP0St_PX    23
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
141
#define CP0St_KX    7
142
#define CP0St_SX    6
143
#define CP0St_UX    5
144
#define CP0St_UM    4
145
#define CP0St_R0    3
146
#define CP0St_ERL   2
147
#define CP0St_EXL   1
148
#define CP0St_IE    0
149
    uint32_t CP0_IntCtl;
150
    uint32_t CP0_SRSCtl;
151
    uint32_t CP0_Cause;
152
#define CP0Ca_BD   31
153
#define CP0Ca_TI   30
154
#define CP0Ca_CE   28
155
#define CP0Ca_DC   27
156
#define CP0Ca_PCI  26
157
#define CP0Ca_IV   23
158
#define CP0Ca_WP   22
159
#define CP0Ca_IP    8
160
#define CP0Ca_EC    2
161
    target_ulong CP0_EPC;
162
    uint32_t CP0_PRid;
163
    target_ulong CP0_EBase;
164
    uint32_t CP0_Config0;
165
#define CP0C0_M    31
166
#define CP0C0_K23  28
167
#define CP0C0_KU   25
168
#define CP0C0_MDU  20
169
#define CP0C0_MM   17
170
#define CP0C0_BM   16
171
#define CP0C0_BE   15
172
#define CP0C0_AT   13
173
#define CP0C0_AR   10
174
#define CP0C0_MT   7
175
#define CP0C0_VI   3
176
#define CP0C0_K0   0
177
    uint32_t CP0_Config1;
178
#define CP0C1_M    31
179
#define CP0C1_MMU  25
180
#define CP0C1_IS   22
181
#define CP0C1_IL   19
182
#define CP0C1_IA   16
183
#define CP0C1_DS   13
184
#define CP0C1_DL   10
185
#define CP0C1_DA   7
186
#define CP0C1_C2   6
187
#define CP0C1_MD   5
188
#define CP0C1_PC   4
189
#define CP0C1_WR   3
190
#define CP0C1_CA   2
191
#define CP0C1_EP   1
192
#define CP0C1_FP   0
193
    uint32_t CP0_Config2;
194
#define CP0C2_M    31
195
#define CP0C2_TU   28
196
#define CP0C2_TS   24
197
#define CP0C2_TL   20
198
#define CP0C2_TA   16
199
#define CP0C2_SU   12
200
#define CP0C2_SS   8
201
#define CP0C2_SL   4
202
#define CP0C2_SA   0
203
    uint32_t CP0_Config3;
204
#define CP0C3_M    31
205
#define CP0C3_DSPP 10
206
#define CP0C3_LPA  7
207
#define CP0C3_VEIC 6
208
#define CP0C3_VInt 5
209
#define CP0C3_SP   4
210
#define CP0C3_MT   2
211
#define CP0C3_SM   1
212
#define CP0C3_TL   0
213
    target_ulong CP0_LLAddr;
214
    uint32_t CP0_WatchLo;
215
    uint32_t CP0_WatchHi;
216
    uint32_t CP0_XContext;
217
    uint32_t CP0_Framemask;
218
    uint32_t CP0_Debug;
219
#define CPDB_DBD   31
220
#define CP0DB_DM   30
221
#define CP0DB_LSNM 28
222
#define CP0DB_Doze 27
223
#define CP0DB_Halt 26
224
#define CP0DB_CNT  25
225
#define CP0DB_IBEP 24
226
#define CP0DB_DBEP 21
227
#define CP0DB_IEXI 20
228
#define CP0DB_VER  15
229
#define CP0DB_DEC  10
230
#define CP0DB_SSt  8
231
#define CP0DB_DINT 5
232
#define CP0DB_DIB  4
233
#define CP0DB_DDBS 3
234
#define CP0DB_DDBL 2
235
#define CP0DB_DBp  1
236
#define CP0DB_DSS  0
237
    target_ulong CP0_DEPC;
238
    uint32_t CP0_Performance0;
239
    uint32_t CP0_TagLo;
240
    uint32_t CP0_DataLo;
241
    uint32_t CP0_TagHi;
242
    uint32_t CP0_DataHi;
243
    target_ulong CP0_ErrorEPC;
244
    uint32_t CP0_DESAVE;
245
    /* Qemu */
246
    int interrupt_request;
247
    jmp_buf jmp_env;
248
    int exception_index;
249
    int error_code;
250
    int user_mode_only; /* user mode only simulation */
251
    uint32_t hflags;    /* CPU State */
252
    /* TMASK defines different execution modes */
253
#define MIPS_HFLAG_TMASK  0x007F
254
#define MIPS_HFLAG_MODE   0x001F /* execution modes                    */
255
#define MIPS_HFLAG_UM     0x0001 /* user mode                          */
256
#define MIPS_HFLAG_ERL    0x0002 /* Error mode                         */
257
#define MIPS_HFLAG_EXL    0x0004 /* Exception mode                     */
258
#define MIPS_HFLAG_DM     0x0008 /* Debug mode                         */
259
#define MIPS_HFLAG_SM     0x0010 /* Supervisor mode                    */
260
#define MIPS_HFLAG_RE     0x0040 /* Reversed endianness                */
261
    /* If translation is interrupted between the branch instruction and
262
     * the delay slot, record what type of branch it is so that we can
263
     * resume translation properly.  It might be possible to reduce
264
     * this from three bits to two.  */
265
#define MIPS_HFLAG_BMASK  0x0380
266
#define MIPS_HFLAG_B      0x0080 /* Unconditional branch               */
267
#define MIPS_HFLAG_BC     0x0100 /* Conditional branch                 */
268
#define MIPS_HFLAG_BL     0x0180 /* Likely branch                      */
269
#define MIPS_HFLAG_BR     0x0200 /* branch to register (can't link TB) */
270
    target_ulong btarget;        /* Jump / branch target               */
271
    int bcond;                   /* Branch condition (if needed)       */
272

    
273
    int halted; /* TRUE if the CPU is in suspend state */
274

    
275
    int SYNCI_Step; /* Address step size for SYNCI */
276
    int CCRes; /* Cycle count resolution/divisor */
277

    
278
    CPU_COMMON
279

    
280
    int ram_size;
281
    const char *kernel_filename;
282
    const char *kernel_cmdline;
283
    const char *initrd_filename;
284

    
285
    struct QEMUTimer *timer; /* Internal timer */
286
};
287

    
288
#include "cpu-all.h"
289

    
290
/* Memory access type :
291
 * may be needed for precise access rights control and precise exceptions.
292
 */
293
enum {
294
    /* 1 bit to define user level / supervisor access */
295
    ACCESS_USER  = 0x00,
296
    ACCESS_SUPER = 0x01,
297
    /* 1 bit to indicate direction */
298
    ACCESS_STORE = 0x02,
299
    /* Type of instruction that generated the access */
300
    ACCESS_CODE  = 0x10, /* Code fetch access                */
301
    ACCESS_INT   = 0x20, /* Integer load/store access        */
302
    ACCESS_FLOAT = 0x30, /* floating point load/store access */
303
};
304

    
305
/* Exceptions */
306
enum {
307
    EXCP_NONE          = -1,
308
    EXCP_RESET         = 0,
309
    EXCP_SRESET,
310
    EXCP_DSS,
311
    EXCP_DINT,
312
    EXCP_NMI,
313
    EXCP_MCHECK,
314
    EXCP_EXT_INTERRUPT,
315
    EXCP_DFWATCH,
316
    EXCP_DIB, /* 8 */
317
    EXCP_IWATCH,
318
    EXCP_AdEL,
319
    EXCP_AdES,
320
    EXCP_TLBF,
321
    EXCP_IBE,
322
    EXCP_DBp,
323
    EXCP_SYSCALL,
324
    EXCP_BREAK, /* 16 */
325
    EXCP_CpU,
326
    EXCP_RI,
327
    EXCP_OVERFLOW,
328
    EXCP_TRAP,
329
    EXCP_DDBS,
330
    EXCP_DWATCH,
331
    EXCP_LAE,
332
    EXCP_SAE, /* 24 */
333
    EXCP_LTLBL,
334
    EXCP_TLBL,
335
    EXCP_TLBS,
336
    EXCP_DBE,
337
    EXCP_DDBL,
338
    EXCP_MTCP0         = 0x104, /* mtmsr instruction:               */
339
                                /* may change privilege level       */
340
    EXCP_BRANCH        = 0x108, /* branch instruction               */
341
    EXCP_ERET          = 0x10C, /* return from interrupt            */
342
    EXCP_SYSCALL_USER  = 0x110, /* System call in user mode only    */
343
    EXCP_FLUSH         = 0x109,
344
};
345

    
346
int cpu_mips_exec(CPUMIPSState *s);
347
CPUMIPSState *cpu_mips_init(void);
348
uint32_t cpu_mips_get_clock (void);
349

    
350
#endif /* !defined (__MIPS_CPU_H__) */