Statistics
| Branch: | Revision:

root / target-mips / cpu.h @ 51b2772f

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

    
20
typedef union fpr_t fpr_t;
21
union fpr_t {
22
    float64  fd;   /* ieee double precision */
23
    float32  fs[2];/* ieee single precision */
24
    uint64_t d;    /* binary double fixed-point */
25
    uint32_t w[2]; /* binary single fixed-point */
26
};
27
/* define FP_ENDIAN_IDX to access the same location
28
 * in the fpr_t union regardless of the host endianess
29
 */
30
#if defined(WORDS_BIGENDIAN)
31
#  define FP_ENDIAN_IDX 1
32
#else
33
#  define FP_ENDIAN_IDX 0
34
#endif
35

    
36
typedef struct r4k_tlb_t r4k_tlb_t;
37
struct r4k_tlb_t {
38
    target_ulong VPN;
39
    uint32_t PageMask;
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

    
51
typedef struct mips_def_t mips_def_t;
52

    
53
typedef struct CPUMIPSState CPUMIPSState;
54
struct CPUMIPSState {
55
    /* General integer registers */
56
    target_ulong gpr[32];
57
    /* Special registers */
58
    target_ulong PC;
59
#if TARGET_LONG_BITS > HOST_LONG_BITS
60
    target_ulong t0;
61
    target_ulong t1;
62
    target_ulong t2;
63
#endif
64
    target_ulong HI, LO;
65
    /* Floating point registers */
66
    fpr_t fpr[32];
67
#ifndef USE_HOST_FLOAT_REGS
68
    fpr_t ft0;
69
    fpr_t ft1;
70
    fpr_t ft2;
71
#endif
72
    float_status fp_status;
73
    /* fpu implementation/revision register (fir) */
74
    uint32_t fcr0;
75
#define FCR0_F64 22
76
#define FCR0_L 21
77
#define FCR0_W 20
78
#define FCR0_3D 19
79
#define FCR0_PS 18
80
#define FCR0_D 17
81
#define FCR0_S 16
82
#define FCR0_PRID 8
83
#define FCR0_REV 0
84
    /* fcsr */
85
    uint32_t fcr31;
86
#define SET_FP_COND(num,env)     do { ((env)->fcr31) |= ((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
87
#define CLEAR_FP_COND(num,env)   do { ((env)->fcr31) &= ~((num) ? (1 << ((num) + 24)) : (1 << 23)); } while(0)
88
#define GET_FP_COND(env)         ((((env)->fcr31 >> 24) & 0xfe) | (((env)->fcr31 >> 23) & 0x1))
89
#define GET_FP_CAUSE(reg)        (((reg) >> 12) & 0x3f)
90
#define GET_FP_ENABLE(reg)       (((reg) >>  7) & 0x1f)
91
#define GET_FP_FLAGS(reg)        (((reg) >>  2) & 0x1f)
92
#define SET_FP_CAUSE(reg,v)      do { (reg) = ((reg) & ~(0x3f << 12)) | ((v & 0x3f) << 12); } while(0)
93
#define SET_FP_ENABLE(reg,v)     do { (reg) = ((reg) & ~(0x1f <<  7)) | ((v & 0x1f) << 7); } while(0)
94
#define SET_FP_FLAGS(reg,v)      do { (reg) = ((reg) & ~(0x1f <<  2)) | ((v & 0x1f) << 2); } while(0)
95
#define UPDATE_FP_FLAGS(reg,v)   do { (reg) |= ((v & 0x1f) << 2); } while(0)
96
#define FP_INEXACT        1
97
#define FP_UNDERFLOW      2
98
#define FP_OVERFLOW       4
99
#define FP_DIV0           8
100
#define FP_INVALID        16
101
#define FP_UNIMPLEMENTED  32
102

    
103
    uint32_t nb_tlb;
104
    uint32_t tlb_in_use;
105
    int (*map_address) (CPUMIPSState *env, target_ulong *physical, int *prot, target_ulong address, int rw, int access_type);
106
    void (*do_tlbwi) (void);
107
    void (*do_tlbwr) (void);
108
    void (*do_tlbp) (void);
109
    void (*do_tlbr) (void);
110
    union {
111
        struct {
112
            r4k_tlb_t tlb[MIPS_TLB_MAX];
113
        } r4k;
114
    } mmu;
115

    
116
    int32_t CP0_Index;
117
    int32_t CP0_Random;
118
    target_ulong CP0_EntryLo0;
119
    target_ulong CP0_EntryLo1;
120
    target_ulong CP0_Context;
121
    int32_t CP0_PageMask;
122
    int32_t CP0_PageGrain;
123
    int32_t CP0_Wired;
124
    int32_t CP0_HWREna;
125
    target_ulong CP0_BadVAddr;
126
    int32_t CP0_Count;
127
    target_ulong CP0_EntryHi;
128
    int32_t CP0_Compare;
129
    int32_t CP0_Status;
130
#define CP0St_CU3   31
131
#define CP0St_CU2   30
132
#define CP0St_CU1   29
133
#define CP0St_CU0   28
134
#define CP0St_RP    27
135
#define CP0St_FR    26
136
#define CP0St_RE    25
137
#define CP0St_MX    24
138
#define CP0St_PX    23
139
#define CP0St_BEV   22
140
#define CP0St_TS    21
141
#define CP0St_SR    20
142
#define CP0St_NMI   19
143
#define CP0St_IM    8
144
#define CP0St_KX    7
145
#define CP0St_SX    6
146
#define CP0St_UX    5
147
#define CP0St_UM    4
148
#define CP0St_R0    3
149
#define CP0St_ERL   2
150
#define CP0St_EXL   1
151
#define CP0St_IE    0
152
    int32_t CP0_IntCtl;
153
    int32_t CP0_SRSCtl;
154
    int32_t CP0_SRSMap;
155
    int32_t CP0_Cause;
156
#define CP0Ca_BD   31
157
#define CP0Ca_TI   30
158
#define CP0Ca_CE   28
159
#define CP0Ca_DC   27
160
#define CP0Ca_PCI  26
161
#define CP0Ca_IV   23
162
#define CP0Ca_WP   22
163
#define CP0Ca_IP    8
164
#define CP0Ca_IP_mask 0x0000FF00
165
#define CP0Ca_EC    2
166
    target_ulong CP0_EPC;
167
    int32_t CP0_PRid;
168
    int32_t CP0_EBase;
169
    int32_t CP0_Config0;
170
#define CP0C0_M    31
171
#define CP0C0_K23  28
172
#define CP0C0_KU   25
173
#define CP0C0_MDU  20
174
#define CP0C0_MM   17
175
#define CP0C0_BM   16
176
#define CP0C0_BE   15
177
#define CP0C0_AT   13
178
#define CP0C0_AR   10
179
#define CP0C0_MT   7
180
#define CP0C0_VI   3
181
#define CP0C0_K0   0
182
    int32_t CP0_Config1;
183
#define CP0C1_M    31
184
#define CP0C1_MMU  25
185
#define CP0C1_IS   22
186
#define CP0C1_IL   19
187
#define CP0C1_IA   16
188
#define CP0C1_DS   13
189
#define CP0C1_DL   10
190
#define CP0C1_DA   7
191
#define CP0C1_C2   6
192
#define CP0C1_MD   5
193
#define CP0C1_PC   4
194
#define CP0C1_WR   3
195
#define CP0C1_CA   2
196
#define CP0C1_EP   1
197
#define CP0C1_FP   0
198
    int32_t CP0_Config2;
199
#define CP0C2_M    31
200
#define CP0C2_TU   28
201
#define CP0C2_TS   24
202
#define CP0C2_TL   20
203
#define CP0C2_TA   16
204
#define CP0C2_SU   12
205
#define CP0C2_SS   8
206
#define CP0C2_SL   4
207
#define CP0C2_SA   0
208
    int32_t CP0_Config3;
209
#define CP0C3_M    31
210
#define CP0C3_DSPP 10
211
#define CP0C3_LPA  7
212
#define CP0C3_VEIC 6
213
#define CP0C3_VInt 5
214
#define CP0C3_SP   4
215
#define CP0C3_MT   2
216
#define CP0C3_SM   1
217
#define CP0C3_TL   0
218
    int32_t CP0_Config6;
219
    int32_t CP0_Config7;
220
    target_ulong CP0_LLAddr;
221
    target_ulong CP0_WatchLo[8];
222
    int32_t CP0_WatchHi[8];
223
    target_ulong CP0_XContext;
224
    int32_t CP0_Framemask;
225
    int32_t CP0_Debug;
226
#define CPDB_DBD   31
227
#define CP0DB_DM   30
228
#define CP0DB_LSNM 28
229
#define CP0DB_Doze 27
230
#define CP0DB_Halt 26
231
#define CP0DB_CNT  25
232
#define CP0DB_IBEP 24
233
#define CP0DB_DBEP 21
234
#define CP0DB_IEXI 20
235
#define CP0DB_VER  15
236
#define CP0DB_DEC  10
237
#define CP0DB_SSt  8
238
#define CP0DB_DINT 5
239
#define CP0DB_DIB  4
240
#define CP0DB_DDBS 3
241
#define CP0DB_DDBL 2
242
#define CP0DB_DBp  1
243
#define CP0DB_DSS  0
244
    target_ulong CP0_DEPC;
245
    int32_t CP0_Performance0;
246
    int32_t CP0_TagLo;
247
    int32_t CP0_DataLo;
248
    int32_t CP0_TagHi;
249
    int32_t CP0_DataHi;
250
    target_ulong CP0_ErrorEPC;
251
    int32_t CP0_DESAVE;
252
    /* Qemu */
253
    int interrupt_request;
254
    jmp_buf jmp_env;
255
    int exception_index;
256
    int error_code;
257
    int user_mode_only; /* user mode only simulation */
258
    uint32_t hflags;    /* CPU State */
259
    /* TMASK defines different execution modes */
260
#define MIPS_HFLAG_TMASK  0x007F
261
#define MIPS_HFLAG_MODE   0x0007 /* execution modes                    */
262
#define MIPS_HFLAG_UM     0x0001 /* user mode                          */
263
#define MIPS_HFLAG_DM     0x0002 /* Debug mode                         */
264
#define MIPS_HFLAG_SM     0x0004 /* Supervisor mode                    */
265
#define MIPS_HFLAG_64     0x0008 /* 64-bit instructions enabled        */
266
#define MIPS_HFLAG_FPU    0x0010 /* FPU enabled                        */
267
#define MIPS_HFLAG_F64    0x0020 /* 64-bit FPU enabled                 */
268
#define MIPS_HFLAG_RE     0x0040 /* Reversed endianness                */
269
    /* If translation is interrupted between the branch instruction and
270
     * the delay slot, record what type of branch it is so that we can
271
     * resume translation properly.  It might be possible to reduce
272
     * this from three bits to two.  */
273
#define MIPS_HFLAG_BMASK  0x0380
274
#define MIPS_HFLAG_B      0x0080 /* Unconditional branch               */
275
#define MIPS_HFLAG_BC     0x0100 /* Conditional branch                 */
276
#define MIPS_HFLAG_BL     0x0180 /* Likely branch                      */
277
#define MIPS_HFLAG_BR     0x0200 /* branch to register (can't link TB) */
278
    target_ulong btarget;        /* Jump / branch target               */
279
    int bcond;                   /* Branch condition (if needed)       */
280

    
281
    int halted; /* TRUE if the CPU is in suspend state */
282

    
283
    int SYNCI_Step; /* Address step size for SYNCI */
284
    int CCRes; /* Cycle count resolution/divisor */
285
    int Status_rw_bitmask; /* Read/write bits in CP0_Status */
286

    
287
#if defined(CONFIG_USER_ONLY)
288
    target_ulong tls_value;
289
#else
290
    void *irq[8];
291
#endif
292

    
293
    CPU_COMMON
294

    
295
    int ram_size;
296
    const char *kernel_filename;
297
    const char *kernel_cmdline;
298
    const char *initrd_filename;
299

    
300
    mips_def_t *cpu_model;
301

    
302
    struct QEMUTimer *timer; /* Internal timer */
303
};
304

    
305
int no_mmu_map_address (CPUMIPSState *env, target_ulong *physical, int *prot,
306
                        target_ulong address, int rw, int access_type);
307
int fixed_mmu_map_address (CPUMIPSState *env, target_ulong *physical, int *prot,
308
                           target_ulong address, int rw, int access_type);
309
int r4k_map_address (CPUMIPSState *env, target_ulong *physical, int *prot,
310
                     target_ulong address, int rw, int access_type);
311
void r4k_do_tlbwi (void);
312
void r4k_do_tlbwr (void);
313
void r4k_do_tlbp (void);
314
void r4k_do_tlbr (void);
315
int mips_find_by_name (const unsigned char *name, mips_def_t **def);
316
void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...));
317
int cpu_mips_register (CPUMIPSState *env, mips_def_t *def);
318

    
319
#include "cpu-all.h"
320

    
321
/* Memory access type :
322
 * may be needed for precise access rights control and precise exceptions.
323
 */
324
enum {
325
    /* 1 bit to define user level / supervisor access */
326
    ACCESS_USER  = 0x00,
327
    ACCESS_SUPER = 0x01,
328
    /* 1 bit to indicate direction */
329
    ACCESS_STORE = 0x02,
330
    /* Type of instruction that generated the access */
331
    ACCESS_CODE  = 0x10, /* Code fetch access                */
332
    ACCESS_INT   = 0x20, /* Integer load/store access        */
333
    ACCESS_FLOAT = 0x30, /* floating point load/store access */
334
};
335

    
336
/* Exceptions */
337
enum {
338
    EXCP_NONE          = -1,
339
    EXCP_RESET         = 0,
340
    EXCP_SRESET,
341
    EXCP_DSS,
342
    EXCP_DINT,
343
    EXCP_NMI,
344
    EXCP_MCHECK,
345
    EXCP_EXT_INTERRUPT,
346
    EXCP_DFWATCH,
347
    EXCP_DIB, /* 8 */
348
    EXCP_IWATCH,
349
    EXCP_AdEL,
350
    EXCP_AdES,
351
    EXCP_TLBF,
352
    EXCP_IBE,
353
    EXCP_DBp,
354
    EXCP_SYSCALL,
355
    EXCP_BREAK, /* 16 */
356
    EXCP_CpU,
357
    EXCP_RI,
358
    EXCP_OVERFLOW,
359
    EXCP_TRAP,
360
    EXCP_FPE,
361
    EXCP_DDBS,
362
    EXCP_DWATCH,
363
    EXCP_LAE, /* 24 */
364
    EXCP_SAE,
365
    EXCP_LTLBL,
366
    EXCP_TLBL,
367
    EXCP_TLBS,
368
    EXCP_DBE,
369
    EXCP_DDBL,
370
    EXCP_MTCP0         = 0x104, /* mtmsr instruction:               */
371
                                /* may change privilege level       */
372
    EXCP_BRANCH        = 0x108, /* branch instruction               */
373
    EXCP_ERET          = 0x10C, /* return from interrupt            */
374
    EXCP_SYSCALL_USER  = 0x110, /* System call in user mode only    */
375
    EXCP_FLUSH         = 0x109,
376
};
377

    
378
int cpu_mips_exec(CPUMIPSState *s);
379
CPUMIPSState *cpu_mips_init(void);
380
uint32_t cpu_mips_get_clock (void);
381
int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
382

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