Statistics
| Branch: | Revision:

root / target-mips / cpu.h @ 43057ab1

History | View | Annotate | Download (7.7 kB)

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
typedef union fpr_t fpr_t;
12
union fpr_t {
13
    float64  fd;   /* ieee double precision */
14
    float32  fs[2];/* ieee single precision */
15
    uint64_t d;    /* binary single fixed-point */
16
    uint32_t w[2]; /* binary single fixed-point */
17
};
18
/* define FP_ENDIAN_IDX to access the same location
19
 * in the fpr_t union regardless of the host endianess
20
 */
21
#if defined(WORDS_BIGENDIAN)
22
#  define FP_ENDIAN_IDX 1
23
#else
24
#  define FP_ENDIAN_IDX 0
25
#endif
26

    
27
#if defined(MIPS_USES_R4K_TLB)
28
typedef struct tlb_t tlb_t;
29
struct tlb_t {
30
    target_ulong VPN;
31
    target_ulong end;
32
    target_ulong end2;
33
    uint_fast8_t ASID;
34
    uint_fast16_t G:1;
35
    uint_fast16_t C0:3;
36
    uint_fast16_t C1:3;
37
    uint_fast16_t V0:1;
38
    uint_fast16_t V1:1;
39
    uint_fast16_t D0:1;
40
    uint_fast16_t D1:1;
41
    target_ulong PFN[2];
42
};
43
#endif
44

    
45
typedef struct CPUMIPSState CPUMIPSState;
46
struct CPUMIPSState {
47
    /* General integer registers */
48
    target_ulong gpr[32];
49
    /* Special registers */
50
    target_ulong PC;
51
    uint32_t HI, LO;
52
    uint32_t DCR; /* ? */
53
#if defined(MIPS_USES_FPU)
54
    /* Floating point registers */
55
    fpr_t fpr[16];
56
#define FPR(cpu, n) ((fpr_t*)&(cpu)->fpr[(n) / 2])
57
#define FPR_FD(cpu, n) (FPR(cpu, n)->fd)
58
#define FPR_FS(cpu, n) (FPR(cpu, n)->fs[((n) & 1) ^ FP_ENDIAN_IDX])
59
#define FPR_D(cpu, n)  (FPR(cpu, n)->d)
60
#define FPR_W(cpu, n)  (FPR(cpu, n)->w[((n) & 1) ^ FP_ENDIAN_IDX])
61

    
62
#ifndef USE_HOST_FLOAT_REGS
63
    fpr_t ft0;
64
    fpr_t ft1;
65
    fpr_t ft2;
66
#endif
67
    float_status fp_status;
68
    /* fpu implementation/revision register */
69
    uint32_t fcr0;
70
    /* fcsr */
71
    uint32_t fcr31;
72
#define SET_FP_COND(reg)     do { (reg) |= (1<<23); } while(0)
73
#define CLEAR_FP_COND(reg)   do { (reg) &= ~(1<<23); } while(0)
74
#define IS_FP_COND_SET(reg)  (((reg) & (1<<23)) != 0)
75
#define GET_FP_CAUSE(reg)    (((reg) >> 12) & 0x3f)
76
#define GET_FP_ENABLE(reg)   (((reg) >>  7) & 0x1f)
77
#define GET_FP_FLAGS(reg)    (((reg) >>  2) & 0x1f)
78
#define SET_FP_CAUSE(reg,v)  do { (reg) = ((reg) & ~(0x3f << 12)) | ((v) << 12); } while(0)
79
#define SET_FP_ENABLE(reg,v) do { (reg) = ((reg) & ~(0x1f <<  7)) | ((v) << 7); } while(0)
80
#define SET_FP_FLAGS(reg,v)  do { (reg) = ((reg) & ~(0x1f <<  2)) | ((v) << 2); } while(0)
81
#define FP_INEXACT        1
82
#define FP_UNDERFLOW      2
83
#define FP_OVERFLOW       4
84
#define FP_DIV0           8
85
#define FP_INVALID        16
86
#define FP_UNIMPLEMENTED  32
87
                
88
#endif
89
#if defined(MIPS_USES_R4K_TLB)
90
    tlb_t tlb[MIPS_TLB_NB];
91
#endif
92
    uint32_t CP0_index;
93
    uint32_t CP0_random;
94
    uint32_t CP0_EntryLo0;
95
    uint32_t CP0_EntryLo1;
96
    uint32_t CP0_Context;
97
    uint32_t CP0_PageMask;
98
    uint32_t CP0_Wired;
99
    uint32_t CP0_BadVAddr;
100
    uint32_t CP0_Count;
101
    uint32_t CP0_EntryHi;
102
    uint32_t CP0_Compare;
103
    uint32_t CP0_Status;
104
#define CP0St_CU3   31
105
#define CP0St_CU2   30
106
#define CP0St_CU1   29
107
#define CP0St_CU0   28
108
#define CP0St_RP    27
109
#define CP0St_FR    26
110
#define CP0St_RE    25
111
#define CP0St_BEV   22
112
#define CP0St_TS    21
113
#define CP0St_SR    20
114
#define CP0St_NMI   19
115
#define CP0St_IM    8
116
#define CP0St_UM    4
117
#define CP0St_ERL   2
118
#define CP0St_EXL   1
119
#define CP0St_IE    0
120
    uint32_t CP0_Cause;
121
#define CP0Ca_IV   23
122
    uint32_t CP0_EPC;
123
    uint32_t CP0_PRid;
124
    uint32_t CP0_Config0;
125
#define CP0C0_M    31
126
#define CP0C0_K23  28
127
#define CP0C0_KU   25
128
#define CP0C0_MDU  20
129
#define CP0C0_MM   17
130
#define CP0C0_BM   16
131
#define CP0C0_BE   15
132
#define CP0C0_AT   13
133
#define CP0C0_AR   10
134
#define CP0C0_MT   7
135
#define CP0C0_K0   0
136
    uint32_t CP0_Config1;
137
#define CP0C1_MMU  25
138
#define CP0C1_IS   22
139
#define CP0C1_IL   19
140
#define CP0C1_IA   16
141
#define CP0C1_DS   13
142
#define CP0C1_DL   10
143
#define CP0C1_DA   7
144
#define CP0C1_PC   4
145
#define CP0C1_WR   3
146
#define CP0C1_CA   2
147
#define CP0C1_EP   1
148
#define CP0C1_FP   0
149
    uint32_t CP0_LLAddr;
150
    uint32_t CP0_WatchLo;
151
    uint32_t CP0_WatchHi;
152
    uint32_t CP0_Debug;
153
#define CPDB_DBD   31
154
#define CP0DB_DM   30
155
#define CP0DB_LSNM 28
156
#define CP0DB_Doze 27
157
#define CP0DB_Halt 26
158
#define CP0DB_CNT  25
159
#define CP0DB_IBEP 24
160
#define CP0DB_DBEP 21
161
#define CP0DB_IEXI 20
162
#define CP0DB_VER  15
163
#define CP0DB_DEC  10
164
#define CP0DB_SSt  8
165
#define CP0DB_DINT 5
166
#define CP0DB_DIB  4
167
#define CP0DB_DDBS 3
168
#define CP0DB_DDBL 2
169
#define CP0DB_DBp  1
170
#define CP0DB_DSS  0
171
    uint32_t CP0_DEPC;
172
    uint32_t CP0_TagLo;
173
    uint32_t CP0_DataLo;
174
    uint32_t CP0_ErrorEPC;
175
    uint32_t CP0_DESAVE;
176
    /* Qemu */
177
    struct QEMUTimer *timer; /* Internal timer */
178
    int interrupt_request;
179
    jmp_buf jmp_env;
180
    int exception_index;
181
    int error_code;
182
    int user_mode_only; /* user mode only simulation */
183
    uint32_t hflags;    /* CPU State */
184
    /* TMASK defines different execution modes */
185
#define MIPS_HFLAG_TMASK  0x007F
186
#define MIPS_HFLAG_MODE   0x001F /* execution modes                    */
187
#define MIPS_HFLAG_UM     0x0001 /* user mode                          */
188
#define MIPS_HFLAG_ERL    0x0002 /* Error mode                         */
189
#define MIPS_HFLAG_EXL    0x0004 /* Exception mode                     */
190
#define MIPS_HFLAG_DM     0x0008 /* Debug mode                         */
191
#define MIPS_HFLAG_SM     0x0010 /* Supervisor mode                    */
192
#define MIPS_HFLAG_RE     0x0040 /* Reversed endianness                */
193
    /* If translation is interrupted between the branch instruction and
194
     * the delay slot, record what type of branch it is so that we can
195
     * resume translation properly.  It might be possible to reduce
196
     * this from three bits to two.  */
197
#define MIPS_HFLAG_BMASK  0x0380
198
#define MIPS_HFLAG_B      0x0080 /* Unconditional branch               */
199
#define MIPS_HFLAG_BC     0x0100 /* Conditional branch                 */
200
#define MIPS_HFLAG_BL     0x0180 /* Likely branch                      */
201
#define MIPS_HFLAG_BR     0x0200 /* branch to register (can't link TB) */
202
    target_ulong btarget;        /* Jump / branch target               */
203
    int bcond;                   /* Branch condition (if needed)       */
204

    
205
    int halted; /* TRUE if the CPU is in suspend state */
206

    
207
    CPU_COMMON
208
};
209

    
210
#include "cpu-all.h"
211

    
212
/* Memory access type :
213
 * may be needed for precise access rights control and precise exceptions.
214
 */
215
enum {
216
    /* 1 bit to define user level / supervisor access */
217
    ACCESS_USER  = 0x00,
218
    ACCESS_SUPER = 0x01,
219
    /* 1 bit to indicate direction */
220
    ACCESS_STORE = 0x02,
221
    /* Type of instruction that generated the access */
222
    ACCESS_CODE  = 0x10, /* Code fetch access                */
223
    ACCESS_INT   = 0x20, /* Integer load/store access        */
224
    ACCESS_FLOAT = 0x30, /* floating point load/store access */
225
};
226

    
227
/* Exceptions */
228
enum {
229
    EXCP_NONE          = -1,
230
    EXCP_RESET         = 0,
231
    EXCP_SRESET,
232
    EXCP_DSS,
233
    EXCP_DINT,
234
    EXCP_NMI,
235
    EXCP_MCHECK,
236
    EXCP_EXT_INTERRUPT,
237
    EXCP_DFWATCH,
238
    EXCP_DIB, /* 8 */
239
    EXCP_IWATCH,
240
    EXCP_AdEL,
241
    EXCP_AdES,
242
    EXCP_TLBF,
243
    EXCP_IBE,
244
    EXCP_DBp,
245
    EXCP_SYSCALL,
246
    EXCP_BREAK, /* 16 */
247
    EXCP_CpU,
248
    EXCP_RI,
249
    EXCP_OVERFLOW,
250
    EXCP_TRAP,
251
    EXCP_DDBS,
252
    EXCP_DWATCH,
253
    EXCP_LAE,
254
    EXCP_SAE, /* 24 */
255
    EXCP_LTLBL,
256
    EXCP_TLBL,
257
    EXCP_TLBS,
258
    EXCP_DBE,
259
    EXCP_DDBL,
260
    EXCP_MTCP0         = 0x104, /* mtmsr instruction:               */
261
                                /* may change privilege level       */
262
    EXCP_BRANCH        = 0x108, /* branch instruction               */
263
    EXCP_ERET          = 0x10C, /* return from interrupt            */
264
    EXCP_SYSCALL_USER  = 0x110, /* System call in user mode only    */
265
    EXCP_FLUSH         = 0x109,
266
};
267

    
268
int cpu_mips_exec(CPUMIPSState *s);
269
CPUMIPSState *cpu_mips_init(void);
270
uint32_t cpu_mips_get_clock (void);
271

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