Statistics
| Branch: | Revision:

root / target-mips / cpu.h @ c5d6edc3

History | View | Annotate | Download (7.7 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 c5d6edc3 bellard
#include "config.h"
7 6af0bf9c bellard
#include "mips-defs.h"
8 6af0bf9c bellard
#include "cpu-defs.h"
9 6af0bf9c bellard
#include "softfloat.h"
10 6af0bf9c bellard
11 6af0bf9c bellard
typedef union fpr_t fpr_t;
12 6af0bf9c bellard
union fpr_t {
13 6ea83fed bellard
    float64  fd;   /* ieee double precision */
14 6ea83fed bellard
    float32  fs[2];/* ieee single precision */
15 6ea83fed bellard
    uint64_t d;    /* binary single fixed-point */
16 6ea83fed bellard
    uint32_t w[2]; /* binary single fixed-point */
17 6af0bf9c bellard
};
18 6ea83fed bellard
/* define FP_ENDIAN_IDX to access the same location
19 6ea83fed bellard
 * in the fpr_t union regardless of the host endianess
20 6ea83fed bellard
 */
21 6ea83fed bellard
#if defined(WORDS_BIGENDIAN)
22 6ea83fed bellard
#  define FP_ENDIAN_IDX 1
23 6ea83fed bellard
#else
24 6ea83fed bellard
#  define FP_ENDIAN_IDX 0
25 6ea83fed bellard
#endif
26 6af0bf9c bellard
27 6af0bf9c bellard
#if defined(MIPS_USES_R4K_TLB)
28 6af0bf9c bellard
typedef struct tlb_t tlb_t;
29 6af0bf9c bellard
struct tlb_t {
30 6af0bf9c bellard
    target_ulong VPN;
31 6af0bf9c bellard
    target_ulong end;
32 4ad40f36 bellard
    target_ulong end2;
33 98c1b82b pbrook
    uint_fast8_t ASID;
34 98c1b82b pbrook
    uint_fast16_t G:1;
35 98c1b82b pbrook
    uint_fast16_t C0:3;
36 98c1b82b pbrook
    uint_fast16_t C1:3;
37 98c1b82b pbrook
    uint_fast16_t V0:1;
38 98c1b82b pbrook
    uint_fast16_t V1:1;
39 98c1b82b pbrook
    uint_fast16_t D0:1;
40 98c1b82b pbrook
    uint_fast16_t D1:1;
41 6af0bf9c bellard
    target_ulong PFN[2];
42 6af0bf9c bellard
};
43 6af0bf9c bellard
#endif
44 6af0bf9c bellard
45 6af0bf9c bellard
typedef struct CPUMIPSState CPUMIPSState;
46 6af0bf9c bellard
struct CPUMIPSState {
47 6af0bf9c bellard
    /* General integer registers */
48 6af0bf9c bellard
    target_ulong gpr[32];
49 6af0bf9c bellard
    /* Special registers */
50 6af0bf9c bellard
    target_ulong PC;
51 6af0bf9c bellard
    uint32_t HI, LO;
52 6af0bf9c bellard
    uint32_t DCR; /* ? */
53 6af0bf9c bellard
#if defined(MIPS_USES_FPU)
54 6af0bf9c bellard
    /* Floating point registers */
55 6af0bf9c bellard
    fpr_t fpr[16];
56 6ea83fed bellard
#define FPR(cpu, n) ((fpr_t*)&(cpu)->fpr[(n) / 2])
57 6ea83fed bellard
#define FPR_FD(cpu, n) (FPR(cpu, n)->fd)
58 6ea83fed bellard
#define FPR_FS(cpu, n) (FPR(cpu, n)->fs[((n) & 1) ^ FP_ENDIAN_IDX])
59 6ea83fed bellard
#define FPR_D(cpu, n)  (FPR(cpu, n)->d)
60 6ea83fed bellard
#define FPR_W(cpu, n)  (FPR(cpu, n)->w[((n) & 1) ^ FP_ENDIAN_IDX])
61 6ea83fed bellard
62 6ea83fed bellard
#ifndef USE_HOST_FLOAT_REGS
63 6ea83fed bellard
    fpr_t ft0;
64 6ea83fed bellard
    fpr_t ft1;
65 6ea83fed bellard
    fpr_t ft2;
66 6ea83fed bellard
#endif
67 6ea83fed bellard
    float_status fp_status;
68 6ea83fed bellard
    /* fpu implementation/revision register */
69 6af0bf9c bellard
    uint32_t fcr0;
70 6ea83fed bellard
    /* fcsr */
71 6ea83fed bellard
    uint32_t fcr31;
72 6ea83fed bellard
#define SET_FP_COND(reg)     do { (reg) |= (1<<23); } while(0)
73 6ea83fed bellard
#define CLEAR_FP_COND(reg)   do { (reg) &= ~(1<<23); } while(0)
74 6ea83fed bellard
#define IS_FP_COND_SET(reg)  (((reg) & (1<<23)) != 0)
75 6ea83fed bellard
#define GET_FP_CAUSE(reg)    (((reg) >> 12) & 0x3f)
76 6ea83fed bellard
#define GET_FP_ENABLE(reg)   (((reg) >>  7) & 0x1f)
77 6ea83fed bellard
#define GET_FP_FLAGS(reg)    (((reg) >>  2) & 0x1f)
78 6ea83fed bellard
#define SET_FP_CAUSE(reg,v)  do { (reg) = ((reg) & ~(0x3f << 12)) | ((v) << 12); } while(0)
79 6ea83fed bellard
#define SET_FP_ENABLE(reg,v) do { (reg) = ((reg) & ~(0x1f <<  7)) | ((v) << 7); } while(0)
80 6ea83fed bellard
#define SET_FP_FLAGS(reg,v)  do { (reg) = ((reg) & ~(0x1f <<  2)) | ((v) << 2); } while(0)
81 6ea83fed bellard
#define FP_INEXACT        1
82 6ea83fed bellard
#define FP_UNDERFLOW      2
83 6ea83fed bellard
#define FP_OVERFLOW       4
84 6ea83fed bellard
#define FP_DIV0           8
85 6ea83fed bellard
#define FP_INVALID        16
86 6ea83fed bellard
#define FP_UNIMPLEMENTED  32
87 6ea83fed bellard
                
88 6af0bf9c bellard
#endif
89 6af0bf9c bellard
#if defined(MIPS_USES_R4K_TLB)
90 6af0bf9c bellard
    tlb_t tlb[16];
91 6af0bf9c bellard
#endif
92 6af0bf9c bellard
    uint32_t CP0_index;
93 6af0bf9c bellard
    uint32_t CP0_random;
94 6af0bf9c bellard
    uint32_t CP0_EntryLo0;
95 6af0bf9c bellard
    uint32_t CP0_EntryLo1;
96 6af0bf9c bellard
    uint32_t CP0_Context;
97 6af0bf9c bellard
    uint32_t CP0_PageMask;
98 6af0bf9c bellard
    uint32_t CP0_Wired;
99 6af0bf9c bellard
    uint32_t CP0_BadVAddr;
100 6af0bf9c bellard
    uint32_t CP0_Count;
101 6af0bf9c bellard
    uint32_t CP0_EntryHi;
102 6af0bf9c bellard
    uint32_t CP0_Compare;
103 6af0bf9c bellard
    uint32_t CP0_Status;
104 6af0bf9c bellard
#define CP0St_CU3   31
105 6af0bf9c bellard
#define CP0St_CU2   30
106 6af0bf9c bellard
#define CP0St_CU1   29
107 6af0bf9c bellard
#define CP0St_CU0   28
108 6af0bf9c bellard
#define CP0St_RP    27
109 6ea83fed bellard
#define CP0St_FR    26
110 6af0bf9c bellard
#define CP0St_RE    25
111 6af0bf9c bellard
#define CP0St_BEV   22
112 6af0bf9c bellard
#define CP0St_TS    21
113 6af0bf9c bellard
#define CP0St_SR    20
114 6af0bf9c bellard
#define CP0St_NMI   19
115 6af0bf9c bellard
#define CP0St_IM    8
116 6af0bf9c bellard
#define CP0St_UM    4
117 6af0bf9c bellard
#define CP0St_ERL   2
118 6af0bf9c bellard
#define CP0St_EXL   1
119 6af0bf9c bellard
#define CP0St_IE    0
120 6af0bf9c bellard
    uint32_t CP0_Cause;
121 6af0bf9c bellard
#define CP0Ca_IV   23
122 6af0bf9c bellard
    uint32_t CP0_EPC;
123 6af0bf9c bellard
    uint32_t CP0_PRid;
124 6af0bf9c bellard
    uint32_t CP0_Config0;
125 6af0bf9c bellard
#define CP0C0_M    31
126 6af0bf9c bellard
#define CP0C0_K23  28
127 6af0bf9c bellard
#define CP0C0_KU   25
128 6af0bf9c bellard
#define CP0C0_MDU  20
129 6af0bf9c bellard
#define CP0C0_MM   17
130 6af0bf9c bellard
#define CP0C0_BM   16
131 6af0bf9c bellard
#define CP0C0_BE   15
132 6af0bf9c bellard
#define CP0C0_AT   13
133 6af0bf9c bellard
#define CP0C0_AR   10
134 6af0bf9c bellard
#define CP0C0_MT   7
135 6af0bf9c bellard
#define CP0C0_K0   0
136 6af0bf9c bellard
    uint32_t CP0_Config1;
137 6af0bf9c bellard
#define CP0C1_MMU  25
138 6af0bf9c bellard
#define CP0C1_IS   22
139 6af0bf9c bellard
#define CP0C1_IL   19
140 6af0bf9c bellard
#define CP0C1_IA   16
141 6af0bf9c bellard
#define CP0C1_DS   13
142 6af0bf9c bellard
#define CP0C1_DL   10
143 6af0bf9c bellard
#define CP0C1_DA   7
144 6af0bf9c bellard
#define CP0C1_PC   4
145 6af0bf9c bellard
#define CP0C1_WR   3
146 6af0bf9c bellard
#define CP0C1_CA   2
147 6af0bf9c bellard
#define CP0C1_EP   1
148 6af0bf9c bellard
#define CP0C1_FP   0
149 6af0bf9c bellard
    uint32_t CP0_LLAddr;
150 6af0bf9c bellard
    uint32_t CP0_WatchLo;
151 6af0bf9c bellard
    uint32_t CP0_WatchHi;
152 6af0bf9c bellard
    uint32_t CP0_Debug;
153 6af0bf9c bellard
#define CPDB_DBD   31
154 6af0bf9c bellard
#define CP0DB_DM   30
155 6af0bf9c bellard
#define CP0DB_LSNM 28
156 6af0bf9c bellard
#define CP0DB_Doze 27
157 6af0bf9c bellard
#define CP0DB_Halt 26
158 6af0bf9c bellard
#define CP0DB_CNT  25
159 6af0bf9c bellard
#define CP0DB_IBEP 24
160 6af0bf9c bellard
#define CP0DB_DBEP 21
161 6af0bf9c bellard
#define CP0DB_IEXI 20
162 6af0bf9c bellard
#define CP0DB_VER  15
163 6af0bf9c bellard
#define CP0DB_DEC  10
164 6af0bf9c bellard
#define CP0DB_SSt  8
165 6af0bf9c bellard
#define CP0DB_DINT 5
166 6af0bf9c bellard
#define CP0DB_DIB  4
167 6af0bf9c bellard
#define CP0DB_DDBS 3
168 6af0bf9c bellard
#define CP0DB_DDBL 2
169 6af0bf9c bellard
#define CP0DB_DBp  1
170 6af0bf9c bellard
#define CP0DB_DSS  0
171 6af0bf9c bellard
    uint32_t CP0_DEPC;
172 6af0bf9c bellard
    uint32_t CP0_TagLo;
173 6af0bf9c bellard
    uint32_t CP0_DataLo;
174 6af0bf9c bellard
    uint32_t CP0_ErrorEPC;
175 6af0bf9c bellard
    uint32_t CP0_DESAVE;
176 6af0bf9c bellard
    /* Qemu */
177 6af0bf9c bellard
    struct QEMUTimer *timer; /* Internal timer */
178 6af0bf9c bellard
    int interrupt_request;
179 6af0bf9c bellard
    jmp_buf jmp_env;
180 6af0bf9c bellard
    int exception_index;
181 6af0bf9c bellard
    int error_code;
182 6af0bf9c bellard
    int user_mode_only; /* user mode only simulation */
183 6af0bf9c bellard
    uint32_t hflags;    /* CPU State */
184 6af0bf9c bellard
    /* TMASK defines different execution modes */
185 56b19403 pbrook
#define MIPS_HFLAG_TMASK  0x007F
186 6af0bf9c bellard
#define MIPS_HFLAG_MODE   0x001F /* execution modes                    */
187 6af0bf9c bellard
#define MIPS_HFLAG_UM     0x0001 /* user mode                          */
188 6af0bf9c bellard
#define MIPS_HFLAG_ERL    0x0002 /* Error mode                         */
189 6af0bf9c bellard
#define MIPS_HFLAG_EXL    0x0004 /* Exception mode                     */
190 6af0bf9c bellard
#define MIPS_HFLAG_DM     0x0008 /* Debug mode                         */
191 6af0bf9c bellard
#define MIPS_HFLAG_SM     0x0010 /* Supervisor mode                    */
192 6af0bf9c bellard
#define MIPS_HFLAG_RE     0x0040 /* Reversed endianness                */
193 4ad40f36 bellard
    /* If translation is interrupted between the branch instruction and
194 4ad40f36 bellard
     * the delay slot, record what type of branch it is so that we can
195 4ad40f36 bellard
     * resume translation properly.  It might be possible to reduce
196 4ad40f36 bellard
     * this from three bits to two.  */
197 4ad40f36 bellard
#define MIPS_HFLAG_BMASK  0x0380
198 4ad40f36 bellard
#define MIPS_HFLAG_B      0x0080 /* Unconditional branch               */
199 4ad40f36 bellard
#define MIPS_HFLAG_BC     0x0100 /* Conditional branch                 */
200 4ad40f36 bellard
#define MIPS_HFLAG_BL     0x0180 /* Likely branch                      */
201 4ad40f36 bellard
#define MIPS_HFLAG_BR     0x0200 /* branch to register (can't link TB) */
202 6af0bf9c bellard
    target_ulong btarget;        /* Jump / branch target               */
203 6af0bf9c bellard
    int bcond;                   /* Branch condition (if needed)       */
204 a316d335 bellard
205 4ad40f36 bellard
    int halted; /* TRUE if the CPU is in suspend state */
206 4ad40f36 bellard
207 a316d335 bellard
    CPU_COMMON
208 6af0bf9c bellard
};
209 6af0bf9c bellard
210 6af0bf9c bellard
#include "cpu-all.h"
211 6af0bf9c bellard
212 6af0bf9c bellard
/* Memory access type :
213 6af0bf9c bellard
 * may be needed for precise access rights control and precise exceptions.
214 6af0bf9c bellard
 */
215 6af0bf9c bellard
enum {
216 6af0bf9c bellard
    /* 1 bit to define user level / supervisor access */
217 6af0bf9c bellard
    ACCESS_USER  = 0x00,
218 6af0bf9c bellard
    ACCESS_SUPER = 0x01,
219 6af0bf9c bellard
    /* 1 bit to indicate direction */
220 6af0bf9c bellard
    ACCESS_STORE = 0x02,
221 6af0bf9c bellard
    /* Type of instruction that generated the access */
222 6af0bf9c bellard
    ACCESS_CODE  = 0x10, /* Code fetch access                */
223 6af0bf9c bellard
    ACCESS_INT   = 0x20, /* Integer load/store access        */
224 6af0bf9c bellard
    ACCESS_FLOAT = 0x30, /* floating point load/store access */
225 6af0bf9c bellard
};
226 6af0bf9c bellard
227 6af0bf9c bellard
/* Exceptions */
228 6af0bf9c bellard
enum {
229 6af0bf9c bellard
    EXCP_NONE          = -1,
230 6af0bf9c bellard
    EXCP_RESET         = 0,
231 6af0bf9c bellard
    EXCP_SRESET,
232 6af0bf9c bellard
    EXCP_DSS,
233 6af0bf9c bellard
    EXCP_DINT,
234 6af0bf9c bellard
    EXCP_NMI,
235 6af0bf9c bellard
    EXCP_MCHECK,
236 6af0bf9c bellard
    EXCP_EXT_INTERRUPT,
237 6af0bf9c bellard
    EXCP_DFWATCH,
238 6af0bf9c bellard
    EXCP_DIB, /* 8 */
239 6af0bf9c bellard
    EXCP_IWATCH,
240 6af0bf9c bellard
    EXCP_AdEL,
241 6af0bf9c bellard
    EXCP_AdES,
242 6af0bf9c bellard
    EXCP_TLBF,
243 6af0bf9c bellard
    EXCP_IBE,
244 6af0bf9c bellard
    EXCP_DBp,
245 6af0bf9c bellard
    EXCP_SYSCALL,
246 4ad40f36 bellard
    EXCP_BREAK, /* 16 */
247 4ad40f36 bellard
    EXCP_CpU,
248 6af0bf9c bellard
    EXCP_RI,
249 6af0bf9c bellard
    EXCP_OVERFLOW,
250 6af0bf9c bellard
    EXCP_TRAP,
251 6af0bf9c bellard
    EXCP_DDBS,
252 6af0bf9c bellard
    EXCP_DWATCH,
253 4ad40f36 bellard
    EXCP_LAE,
254 4ad40f36 bellard
    EXCP_SAE, /* 24 */
255 6af0bf9c bellard
    EXCP_LTLBL,
256 6af0bf9c bellard
    EXCP_TLBL,
257 6af0bf9c bellard
    EXCP_TLBS,
258 6af0bf9c bellard
    EXCP_DBE,
259 6af0bf9c bellard
    EXCP_DDBL,
260 6af0bf9c bellard
    EXCP_MTCP0         = 0x104, /* mtmsr instruction:               */
261 6af0bf9c bellard
                                /* may change privilege level       */
262 6af0bf9c bellard
    EXCP_BRANCH        = 0x108, /* branch instruction               */
263 6af0bf9c bellard
    EXCP_ERET          = 0x10C, /* return from interrupt            */
264 6af0bf9c bellard
    EXCP_SYSCALL_USER  = 0x110, /* System call in user mode only    */
265 6af0bf9c bellard
    EXCP_FLUSH         = 0x109,
266 6af0bf9c bellard
};
267 6af0bf9c bellard
268 6af0bf9c bellard
int cpu_mips_exec(CPUMIPSState *s);
269 6af0bf9c bellard
CPUMIPSState *cpu_mips_init(void);
270 6af0bf9c bellard
uint32_t cpu_mips_get_clock (void);
271 6af0bf9c bellard
272 6af0bf9c bellard
#endif /* !defined (__MIPS_CPU_H__) */