Statistics
| Branch: | Revision:

root / target-mips / cpu.h @ 6ae81775

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