2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 //#define MIPS_DEBUG_DISAS
34 //#define MIPS_DEBUG_SIGN_EXTENSIONS
35 //#define MIPS_SINGLE_STEP
37 #ifdef USE_DIRECT_JUMP
40 #define TBPARAM(x) (long)(x)
44 #define DEF(s, n, copy_size) INDEX_op_ ## s,
50 static uint16_t *gen_opc_ptr;
51 static uint32_t *gen_opparam_ptr;
55 /* MIPS major opcodes */
56 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
59 /* indirect opcode tables */
60 OPC_SPECIAL = (0x00 << 26),
61 OPC_REGIMM = (0x01 << 26),
62 OPC_CP0 = (0x10 << 26),
63 OPC_CP1 = (0x11 << 26),
64 OPC_CP2 = (0x12 << 26),
65 OPC_CP3 = (0x13 << 26),
66 OPC_SPECIAL2 = (0x1C << 26),
67 OPC_SPECIAL3 = (0x1F << 26),
68 /* arithmetic with immediate */
69 OPC_ADDI = (0x08 << 26),
70 OPC_ADDIU = (0x09 << 26),
71 OPC_SLTI = (0x0A << 26),
72 OPC_SLTIU = (0x0B << 26),
73 OPC_ANDI = (0x0C << 26),
74 OPC_ORI = (0x0D << 26),
75 OPC_XORI = (0x0E << 26),
76 OPC_LUI = (0x0F << 26),
77 OPC_DADDI = (0x18 << 26),
78 OPC_DADDIU = (0x19 << 26),
79 /* Jump and branches */
81 OPC_JAL = (0x03 << 26),
82 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
83 OPC_BEQL = (0x14 << 26),
84 OPC_BNE = (0x05 << 26),
85 OPC_BNEL = (0x15 << 26),
86 OPC_BLEZ = (0x06 << 26),
87 OPC_BLEZL = (0x16 << 26),
88 OPC_BGTZ = (0x07 << 26),
89 OPC_BGTZL = (0x17 << 26),
90 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
92 OPC_LDL = (0x1A << 26),
93 OPC_LDR = (0x1B << 26),
94 OPC_LB = (0x20 << 26),
95 OPC_LH = (0x21 << 26),
96 OPC_LWL = (0x22 << 26),
97 OPC_LW = (0x23 << 26),
98 OPC_LBU = (0x24 << 26),
99 OPC_LHU = (0x25 << 26),
100 OPC_LWR = (0x26 << 26),
101 OPC_LWU = (0x27 << 26),
102 OPC_SB = (0x28 << 26),
103 OPC_SH = (0x29 << 26),
104 OPC_SWL = (0x2A << 26),
105 OPC_SW = (0x2B << 26),
106 OPC_SDL = (0x2C << 26),
107 OPC_SDR = (0x2D << 26),
108 OPC_SWR = (0x2E << 26),
109 OPC_LL = (0x30 << 26),
110 OPC_LLD = (0x34 << 26),
111 OPC_LD = (0x37 << 26),
112 OPC_SC = (0x38 << 26),
113 OPC_SCD = (0x3C << 26),
114 OPC_SD = (0x3F << 26),
115 /* Floating point load/store */
116 OPC_LWC1 = (0x31 << 26),
117 OPC_LWC2 = (0x32 << 26),
118 OPC_LDC1 = (0x35 << 26),
119 OPC_LDC2 = (0x36 << 26),
120 OPC_SWC1 = (0x39 << 26),
121 OPC_SWC2 = (0x3A << 26),
122 OPC_SDC1 = (0x3D << 26),
123 OPC_SDC2 = (0x3E << 26),
124 /* MDMX ASE specific */
125 OPC_MDMX = (0x1E << 26),
126 /* Cache and prefetch */
127 OPC_CACHE = (0x2F << 26),
128 OPC_PREF = (0x33 << 26),
129 /* Reserved major opcode */
130 OPC_MAJOR3B_RESERVED = (0x3B << 26),
133 /* MIPS special opcodes */
134 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
138 OPC_SLL = 0x00 | OPC_SPECIAL,
139 /* NOP is SLL r0, r0, 0 */
140 /* SSNOP is SLL r0, r0, 1 */
141 /* EHB is SLL r0, r0, 3 */
142 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
143 OPC_SRA = 0x03 | OPC_SPECIAL,
144 OPC_SLLV = 0x04 | OPC_SPECIAL,
145 OPC_SRLV = 0x06 | OPC_SPECIAL,
146 OPC_SRAV = 0x07 | OPC_SPECIAL,
147 OPC_DSLLV = 0x14 | OPC_SPECIAL,
148 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
149 OPC_DSRAV = 0x17 | OPC_SPECIAL,
150 OPC_DSLL = 0x38 | OPC_SPECIAL,
151 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
152 OPC_DSRA = 0x3B | OPC_SPECIAL,
153 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
154 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
155 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
156 /* Multiplication / division */
157 OPC_MULT = 0x18 | OPC_SPECIAL,
158 OPC_MULTU = 0x19 | OPC_SPECIAL,
159 OPC_DIV = 0x1A | OPC_SPECIAL,
160 OPC_DIVU = 0x1B | OPC_SPECIAL,
161 OPC_DMULT = 0x1C | OPC_SPECIAL,
162 OPC_DMULTU = 0x1D | OPC_SPECIAL,
163 OPC_DDIV = 0x1E | OPC_SPECIAL,
164 OPC_DDIVU = 0x1F | OPC_SPECIAL,
165 /* 2 registers arithmetic / logic */
166 OPC_ADD = 0x20 | OPC_SPECIAL,
167 OPC_ADDU = 0x21 | OPC_SPECIAL,
168 OPC_SUB = 0x22 | OPC_SPECIAL,
169 OPC_SUBU = 0x23 | OPC_SPECIAL,
170 OPC_AND = 0x24 | OPC_SPECIAL,
171 OPC_OR = 0x25 | OPC_SPECIAL,
172 OPC_XOR = 0x26 | OPC_SPECIAL,
173 OPC_NOR = 0x27 | OPC_SPECIAL,
174 OPC_SLT = 0x2A | OPC_SPECIAL,
175 OPC_SLTU = 0x2B | OPC_SPECIAL,
176 OPC_DADD = 0x2C | OPC_SPECIAL,
177 OPC_DADDU = 0x2D | OPC_SPECIAL,
178 OPC_DSUB = 0x2E | OPC_SPECIAL,
179 OPC_DSUBU = 0x2F | OPC_SPECIAL,
181 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
182 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
184 OPC_TGE = 0x30 | OPC_SPECIAL,
185 OPC_TGEU = 0x31 | OPC_SPECIAL,
186 OPC_TLT = 0x32 | OPC_SPECIAL,
187 OPC_TLTU = 0x33 | OPC_SPECIAL,
188 OPC_TEQ = 0x34 | OPC_SPECIAL,
189 OPC_TNE = 0x36 | OPC_SPECIAL,
190 /* HI / LO registers load & stores */
191 OPC_MFHI = 0x10 | OPC_SPECIAL,
192 OPC_MTHI = 0x11 | OPC_SPECIAL,
193 OPC_MFLO = 0x12 | OPC_SPECIAL,
194 OPC_MTLO = 0x13 | OPC_SPECIAL,
195 /* Conditional moves */
196 OPC_MOVZ = 0x0A | OPC_SPECIAL,
197 OPC_MOVN = 0x0B | OPC_SPECIAL,
199 OPC_MOVCI = 0x01 | OPC_SPECIAL,
202 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
203 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
204 OPC_BREAK = 0x0D | OPC_SPECIAL,
205 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
206 OPC_SYNC = 0x0F | OPC_SPECIAL,
208 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
209 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
210 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
211 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
212 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
213 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
214 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
217 /* REGIMM (rt field) opcodes */
218 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
221 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
222 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
223 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
224 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
225 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
226 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
227 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
228 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
229 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
230 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
231 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
232 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
233 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
234 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
235 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
238 /* Special2 opcodes */
239 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
242 /* Multiply & xxx operations */
243 OPC_MADD = 0x00 | OPC_SPECIAL2,
244 OPC_MADDU = 0x01 | OPC_SPECIAL2,
245 OPC_MUL = 0x02 | OPC_SPECIAL2,
246 OPC_MSUB = 0x04 | OPC_SPECIAL2,
247 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
249 OPC_CLZ = 0x20 | OPC_SPECIAL2,
250 OPC_CLO = 0x21 | OPC_SPECIAL2,
251 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
252 OPC_DCLO = 0x25 | OPC_SPECIAL2,
254 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
257 /* Special3 opcodes */
258 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
261 OPC_EXT = 0x00 | OPC_SPECIAL3,
262 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
263 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
264 OPC_DEXT = 0x03 | OPC_SPECIAL3,
265 OPC_INS = 0x04 | OPC_SPECIAL3,
266 OPC_DINSM = 0x05 | OPC_SPECIAL3,
267 OPC_DINSU = 0x06 | OPC_SPECIAL3,
268 OPC_DINS = 0x07 | OPC_SPECIAL3,
269 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
270 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
271 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
275 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
278 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
279 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
280 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
284 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
287 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
288 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
291 /* Coprocessor 0 (rs field) */
292 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
295 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
296 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
297 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
298 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
299 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
300 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
301 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
302 OPC_C0 = (0x10 << 21) | OPC_CP0,
303 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
304 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
308 #define MASK_MFMC0(op) MASK_CP0(op) | (op & ((0x0C << 11) | (1 << 5)))
311 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
312 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
315 /* Coprocessor 0 (with rs == C0) */
316 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
319 OPC_TLBR = 0x01 | OPC_C0,
320 OPC_TLBWI = 0x02 | OPC_C0,
321 OPC_TLBWR = 0x06 | OPC_C0,
322 OPC_TLBP = 0x08 | OPC_C0,
323 OPC_RFE = 0x10 | OPC_C0,
324 OPC_ERET = 0x18 | OPC_C0,
325 OPC_DERET = 0x1F | OPC_C0,
326 OPC_WAIT = 0x20 | OPC_C0,
329 /* Coprocessor 1 (rs field) */
330 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
333 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
334 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
335 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
336 OPC_MFHCI = (0x03 << 21) | OPC_CP1,
337 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
338 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
339 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
340 OPC_MTHCI = (0x07 << 21) | OPC_CP1,
341 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
342 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
343 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
344 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
345 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
346 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
347 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
351 OPC_BC1F = (0x00 << 16) | OPC_BC1,
352 OPC_BC1T = (0x01 << 16) | OPC_BC1,
353 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
354 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
357 #define MASK_CP1_BCOND(op) MASK_CP1(op) | (op & (0x3 << 16))
358 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
360 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
363 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
364 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
365 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
366 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
367 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
368 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
369 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
370 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
371 OPC_BC2 = (0x08 << 21) | OPC_CP2,
374 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
377 OPC_LWXC1 = 0x00 | OPC_CP3,
378 OPC_LDXC1 = 0x01 | OPC_CP3,
379 OPC_LUXC1 = 0x05 | OPC_CP3,
380 OPC_SWXC1 = 0x08 | OPC_CP3,
381 OPC_SDXC1 = 0x09 | OPC_CP3,
382 OPC_SUXC1 = 0x0D | OPC_CP3,
383 OPC_PREFX = 0x0F | OPC_CP3,
384 OPC_ALNV_PS = 0x1E | OPC_CP3,
385 OPC_MADD_S = 0x20 | OPC_CP3,
386 OPC_MADD_D = 0x21 | OPC_CP3,
387 OPC_MADD_PS = 0x26 | OPC_CP3,
388 OPC_MSUB_S = 0x28 | OPC_CP3,
389 OPC_MSUB_D = 0x29 | OPC_CP3,
390 OPC_MSUB_PS = 0x2E | OPC_CP3,
391 OPC_NMADD_S = 0x30 | OPC_CP3,
392 OPC_NMADD_D = 0x32 | OPC_CP3,
393 OPC_NMADD_PS= 0x36 | OPC_CP3,
394 OPC_NMSUB_S = 0x38 | OPC_CP3,
395 OPC_NMSUB_D = 0x39 | OPC_CP3,
396 OPC_NMSUB_PS= 0x3E | OPC_CP3,
400 const unsigned char *regnames[] =
401 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
402 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
403 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
404 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
406 /* Warning: no function for r0 register (hard wired to zero) */
407 #define GEN32(func, NAME) \
408 static GenOpFunc *NAME ## _table [32] = { \
409 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
410 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
411 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
412 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
413 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
414 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
415 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
416 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
418 static inline void func(int n) \
420 NAME ## _table[n](); \
423 /* General purpose registers moves */
424 GEN32(gen_op_load_gpr_T0, gen_op_load_gpr_T0_gpr);
425 GEN32(gen_op_load_gpr_T1, gen_op_load_gpr_T1_gpr);
426 GEN32(gen_op_load_gpr_T2, gen_op_load_gpr_T2_gpr);
428 GEN32(gen_op_store_T0_gpr, gen_op_store_T0_gpr_gpr);
429 GEN32(gen_op_store_T1_gpr, gen_op_store_T1_gpr_gpr);
431 static const char *fregnames[] =
432 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
433 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
434 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
435 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
437 # define SFGEN32(func, NAME) \
438 static GenOpFunc *NAME ## _table [32] = { \
439 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
440 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
441 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
442 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
443 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
444 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
445 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
446 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
448 static inline void func(int n) \
450 NAME ## _table[n](); \
453 # define DFGEN32(func, NAME) \
454 static GenOpFunc *NAME ## _table [32] = { \
455 NAME ## 0, 0, NAME ## 2, 0, \
456 NAME ## 4, 0, NAME ## 6, 0, \
457 NAME ## 8, 0, NAME ## 10, 0, \
458 NAME ## 12, 0, NAME ## 14, 0, \
459 NAME ## 16, 0, NAME ## 18, 0, \
460 NAME ## 20, 0, NAME ## 22, 0, \
461 NAME ## 24, 0, NAME ## 26, 0, \
462 NAME ## 28, 0, NAME ## 30, 0, \
464 static inline void func(int n) \
466 NAME ## _table[n](); \
469 SFGEN32(gen_op_load_fpr_WT0, gen_op_load_fpr_WT0_fpr);
470 SFGEN32(gen_op_store_fpr_WT0, gen_op_store_fpr_WT0_fpr);
472 SFGEN32(gen_op_load_fpr_WT1, gen_op_load_fpr_WT1_fpr);
473 SFGEN32(gen_op_store_fpr_WT1, gen_op_store_fpr_WT1_fpr);
475 SFGEN32(gen_op_load_fpr_WT2, gen_op_load_fpr_WT2_fpr);
476 SFGEN32(gen_op_store_fpr_WT2, gen_op_store_fpr_WT2_fpr);
478 DFGEN32(gen_op_load_fpr_DT0, gen_op_load_fpr_DT0_fpr);
479 DFGEN32(gen_op_store_fpr_DT0, gen_op_store_fpr_DT0_fpr);
481 DFGEN32(gen_op_load_fpr_DT1, gen_op_load_fpr_DT1_fpr);
482 DFGEN32(gen_op_store_fpr_DT1, gen_op_store_fpr_DT1_fpr);
484 DFGEN32(gen_op_load_fpr_DT2, gen_op_load_fpr_DT2_fpr);
485 DFGEN32(gen_op_store_fpr_DT2, gen_op_store_fpr_DT2_fpr);
487 #define FOP_CONDS(fmt) \
488 static GenOpFunc * cond_ ## fmt ## _table[16] = { \
489 gen_op_cmp_ ## fmt ## _f, \
490 gen_op_cmp_ ## fmt ## _un, \
491 gen_op_cmp_ ## fmt ## _eq, \
492 gen_op_cmp_ ## fmt ## _ueq, \
493 gen_op_cmp_ ## fmt ## _olt, \
494 gen_op_cmp_ ## fmt ## _ult, \
495 gen_op_cmp_ ## fmt ## _ole, \
496 gen_op_cmp_ ## fmt ## _ule, \
497 gen_op_cmp_ ## fmt ## _sf, \
498 gen_op_cmp_ ## fmt ## _ngle, \
499 gen_op_cmp_ ## fmt ## _seq, \
500 gen_op_cmp_ ## fmt ## _ngl, \
501 gen_op_cmp_ ## fmt ## _lt, \
502 gen_op_cmp_ ## fmt ## _nge, \
503 gen_op_cmp_ ## fmt ## _le, \
504 gen_op_cmp_ ## fmt ## _ngt, \
506 static inline void gen_cmp_ ## fmt(int n) \
508 cond_ ## fmt ## _table[n](); \
514 typedef struct DisasContext {
515 struct TranslationBlock *tb;
516 target_ulong pc, saved_pc;
518 /* Routine used to access memory */
520 uint32_t hflags, saved_hflags;
523 target_ulong btarget;
527 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
528 * exception condition
530 BS_STOP = 1, /* We want to stop translation for any reason */
531 BS_BRANCH = 2, /* We reached a branch condition */
532 BS_EXCP = 3, /* We reached an exception condition */
535 #if defined MIPS_DEBUG_DISAS
536 #define MIPS_DEBUG(fmt, args...) \
538 if (loglevel & CPU_LOG_TB_IN_ASM) { \
539 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
540 ctx->pc, ctx->opcode , ##args); \
544 #define MIPS_DEBUG(fmt, args...) do { } while(0)
547 #define MIPS_INVAL(op) \
549 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
550 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
553 #define GEN_LOAD_REG_TN(Tn, Rn) \
556 glue(gen_op_reset_, Tn)(); \
558 glue(gen_op_load_gpr_, Tn)(Rn); \
562 #define GEN_LOAD_IMM_TN(Tn, Imm) \
565 glue(gen_op_reset_, Tn)(); \
567 glue(gen_op_set_, Tn)(Imm); \
571 #define GEN_STORE_TN_REG(Rn, Tn) \
574 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
578 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
580 glue(gen_op_load_fpr_, FTn)(Fn); \
583 #define GEN_STORE_FTN_FREG(Fn, FTn) \
585 glue(gen_op_store_fpr_, FTn)(Fn); \
588 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
590 #if defined MIPS_DEBUG_DISAS
591 if (loglevel & CPU_LOG_TB_IN_ASM) {
592 fprintf(logfile, "hflags %08x saved %08x\n",
593 ctx->hflags, ctx->saved_hflags);
596 if (do_save_pc && ctx->pc != ctx->saved_pc) {
597 gen_op_save_pc(ctx->pc);
598 ctx->saved_pc = ctx->pc;
600 if (ctx->hflags != ctx->saved_hflags) {
601 gen_op_save_state(ctx->hflags);
602 ctx->saved_hflags = ctx->hflags;
603 if (ctx->hflags & MIPS_HFLAG_BR) {
604 gen_op_save_breg_target();
605 } else if (ctx->hflags & MIPS_HFLAG_B) {
606 gen_op_save_btarget(ctx->btarget);
607 } else if (ctx->hflags & MIPS_HFLAG_BMASK) {
609 gen_op_save_btarget(ctx->btarget);
614 static inline void generate_exception_err (DisasContext *ctx, int excp, int err)
616 #if defined MIPS_DEBUG_DISAS
617 if (loglevel & CPU_LOG_TB_IN_ASM)
618 fprintf(logfile, "%s: raise exception %d\n", __func__, excp);
620 save_cpu_state(ctx, 1);
622 gen_op_raise_exception(excp);
624 gen_op_raise_exception_err(excp, err);
625 ctx->bstate = BS_EXCP;
628 static inline void generate_exception (DisasContext *ctx, int excp)
630 generate_exception_err (ctx, excp, 0);
633 #if defined(CONFIG_USER_ONLY)
634 #define op_ldst(name) gen_op_##name##_raw()
635 #define OP_LD_TABLE(width)
636 #define OP_ST_TABLE(width)
638 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
639 #define OP_LD_TABLE(width) \
640 static GenOpFunc *gen_op_l##width[] = { \
641 &gen_op_l##width##_user, \
642 &gen_op_l##width##_kernel, \
644 #define OP_ST_TABLE(width) \
645 static GenOpFunc *gen_op_s##width[] = { \
646 &gen_op_s##width##_user, \
647 &gen_op_s##width##_kernel, \
682 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
683 int base, int16_t offset)
685 const char *opn = "unk";
688 GEN_LOAD_IMM_TN(T0, offset);
689 } else if (offset == 0) {
690 gen_op_load_gpr_T0(base);
692 gen_op_load_gpr_T0(base);
693 gen_op_set_T1(offset);
696 /* Don't do NOP if destination is zero: we must perform the actual
703 GEN_STORE_TN_REG(rt, T0);
708 GEN_STORE_TN_REG(rt, T0);
712 GEN_LOAD_REG_TN(T1, rt);
717 GEN_LOAD_REG_TN(T1, rt);
723 GEN_STORE_TN_REG(rt, T0);
727 GEN_LOAD_REG_TN(T1, rt);
733 GEN_STORE_TN_REG(rt, T0);
737 GEN_LOAD_REG_TN(T1, rt);
744 GEN_STORE_TN_REG(rt, T0);
749 GEN_STORE_TN_REG(rt, T0);
753 GEN_LOAD_REG_TN(T1, rt);
759 GEN_STORE_TN_REG(rt, T0);
763 GEN_LOAD_REG_TN(T1, rt);
769 GEN_STORE_TN_REG(rt, T0);
774 GEN_STORE_TN_REG(rt, T0);
778 GEN_LOAD_REG_TN(T1, rt);
784 GEN_STORE_TN_REG(rt, T0);
788 GEN_LOAD_REG_TN(T1, rt);
790 GEN_STORE_TN_REG(rt, T0);
794 GEN_LOAD_REG_TN(T1, rt);
799 GEN_LOAD_REG_TN(T1, rt);
801 GEN_STORE_TN_REG(rt, T0);
805 GEN_LOAD_REG_TN(T1, rt);
811 GEN_STORE_TN_REG(rt, T0);
815 GEN_LOAD_REG_TN(T1, rt);
817 GEN_STORE_TN_REG(rt, T0);
821 MIPS_INVAL("load/store");
822 generate_exception(ctx, EXCP_RI);
825 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
829 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
830 int base, int16_t offset)
832 const char *opn = "unk";
835 GEN_LOAD_IMM_TN(T0, offset);
836 } else if (offset == 0) {
837 gen_op_load_gpr_T0(base);
839 gen_op_load_gpr_T0(base);
840 gen_op_set_T1(offset);
843 /* Don't do NOP if destination is zero: we must perform the actual
849 GEN_STORE_FTN_FREG(ft, WT0);
853 GEN_LOAD_FREG_FTN(WT0, ft);
859 GEN_STORE_FTN_FREG(ft, DT0);
863 GEN_LOAD_FREG_FTN(DT0, ft);
868 MIPS_INVAL("float load/store");
869 generate_exception(ctx, EXCP_RI);
872 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
875 /* Arithmetic with immediate operand */
876 static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
880 const char *opn = "unk";
882 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
883 /* if no destination, treat it as a NOP
884 * For addi, we must generate the overflow exception when needed.
889 uimm = (uint16_t)imm;
899 uimm = (int32_t)imm; /* Sign extend to 32 bits */
904 GEN_LOAD_REG_TN(T0, rs);
905 GEN_LOAD_IMM_TN(T1, uimm);
909 GEN_LOAD_IMM_TN(T0, uimm);
923 GEN_LOAD_REG_TN(T0, rs);
924 GEN_LOAD_IMM_TN(T1, uimm);
929 save_cpu_state(ctx, 1);
939 save_cpu_state(ctx, 1);
980 switch ((ctx->opcode >> 21) & 0x1f) {
990 MIPS_INVAL("invalid srl flag");
991 generate_exception(ctx, EXCP_RI);
1005 switch ((ctx->opcode >> 21) & 0x1f) {
1015 MIPS_INVAL("invalid dsrl flag");
1016 generate_exception(ctx, EXCP_RI);
1029 switch ((ctx->opcode >> 21) & 0x1f) {
1039 MIPS_INVAL("invalid dsrl32 flag");
1040 generate_exception(ctx, EXCP_RI);
1046 MIPS_INVAL("imm arith");
1047 generate_exception(ctx, EXCP_RI);
1050 GEN_STORE_TN_REG(rt, T0);
1051 MIPS_DEBUG("%s %s, %s, %x", opn, regnames[rt], regnames[rs], uimm);
1055 static void gen_arith (DisasContext *ctx, uint32_t opc,
1056 int rd, int rs, int rt)
1058 const char *opn = "unk";
1060 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1061 && opc != OPC_DADD && opc != OPC_DSUB) {
1062 /* if no destination, treat it as a NOP
1063 * For add & sub, we must generate the overflow exception when needed.
1068 GEN_LOAD_REG_TN(T0, rs);
1069 GEN_LOAD_REG_TN(T1, rt);
1072 save_cpu_state(ctx, 1);
1081 save_cpu_state(ctx, 1);
1089 #ifdef TARGET_MIPS64
1091 save_cpu_state(ctx, 1);
1100 save_cpu_state(ctx, 1);
1154 switch ((ctx->opcode >> 6) & 0x1f) {
1164 MIPS_INVAL("invalid srlv flag");
1165 generate_exception(ctx, EXCP_RI);
1169 #ifdef TARGET_MIPS64
1179 switch ((ctx->opcode >> 6) & 0x1f) {
1189 MIPS_INVAL("invalid dsrlv flag");
1190 generate_exception(ctx, EXCP_RI);
1196 MIPS_INVAL("arith");
1197 generate_exception(ctx, EXCP_RI);
1200 GEN_STORE_TN_REG(rd, T0);
1202 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1205 /* Arithmetic on HI/LO registers */
1206 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1208 const char *opn = "unk";
1210 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1211 /* Treat as a NOP */
1218 GEN_STORE_TN_REG(reg, T0);
1223 GEN_STORE_TN_REG(reg, T0);
1227 GEN_LOAD_REG_TN(T0, reg);
1232 GEN_LOAD_REG_TN(T0, reg);
1238 generate_exception(ctx, EXCP_RI);
1241 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1244 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1247 const char *opn = "unk";
1249 GEN_LOAD_REG_TN(T0, rs);
1250 GEN_LOAD_REG_TN(T1, rt);
1268 #ifdef TARGET_MIPS64
1303 MIPS_INVAL("mul/div");
1304 generate_exception(ctx, EXCP_RI);
1307 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
1310 static void gen_cl (DisasContext *ctx, uint32_t opc,
1313 const char *opn = "unk";
1315 /* Treat as a NOP */
1319 GEN_LOAD_REG_TN(T0, rs);
1329 #ifdef TARGET_MIPS64
1341 generate_exception(ctx, EXCP_RI);
1344 gen_op_store_T0_gpr(rd);
1345 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
1349 static void gen_trap (DisasContext *ctx, uint32_t opc,
1350 int rs, int rt, int16_t imm)
1355 /* Load needed operands */
1363 /* Compare two registers */
1365 GEN_LOAD_REG_TN(T0, rs);
1366 GEN_LOAD_REG_TN(T1, rt);
1376 /* Compare register to immediate */
1377 if (rs != 0 || imm != 0) {
1378 GEN_LOAD_REG_TN(T0, rs);
1379 GEN_LOAD_IMM_TN(T1, (int32_t)imm);
1386 case OPC_TEQ: /* rs == rs */
1387 case OPC_TEQI: /* r0 == 0 */
1388 case OPC_TGE: /* rs >= rs */
1389 case OPC_TGEI: /* r0 >= 0 */
1390 case OPC_TGEU: /* rs >= rs unsigned */
1391 case OPC_TGEIU: /* r0 >= 0 unsigned */
1395 case OPC_TLT: /* rs < rs */
1396 case OPC_TLTI: /* r0 < 0 */
1397 case OPC_TLTU: /* rs < rs unsigned */
1398 case OPC_TLTIU: /* r0 < 0 unsigned */
1399 case OPC_TNE: /* rs != rs */
1400 case OPC_TNEI: /* r0 != 0 */
1401 /* Never trap: treat as NOP */
1405 generate_exception(ctx, EXCP_RI);
1436 generate_exception(ctx, EXCP_RI);
1440 save_cpu_state(ctx, 1);
1442 ctx->bstate = BS_STOP;
1445 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
1447 TranslationBlock *tb;
1449 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
1451 gen_op_goto_tb0(TBPARAM(tb));
1453 gen_op_goto_tb1(TBPARAM(tb));
1454 gen_op_save_pc(dest);
1455 gen_op_set_T0((long)tb + n);
1458 gen_op_save_pc(dest);
1464 /* Branches (before delay slot) */
1465 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
1466 int rs, int rt, int32_t offset)
1468 target_ulong btarget = -1;
1472 if (ctx->hflags & MIPS_HFLAG_BMASK) {
1473 if (loglevel & CPU_LOG_TB_IN_ASM) {
1475 "undefined branch in delay slot at PC " TARGET_FMT_lx "\n",
1478 MIPS_INVAL("branch/jump in bdelay slot");
1479 generate_exception(ctx, EXCP_RI);
1483 /* Load needed operands */
1489 /* Compare two registers */
1491 GEN_LOAD_REG_TN(T0, rs);
1492 GEN_LOAD_REG_TN(T1, rt);
1495 btarget = ctx->pc + 4 + offset;
1509 /* Compare to zero */
1511 gen_op_load_gpr_T0(rs);
1514 btarget = ctx->pc + 4 + offset;
1518 /* Jump to immediate */
1519 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | offset;
1523 /* Jump to register */
1524 if (offset != 0 && offset != 16) {
1525 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1526 others are reserved. */
1527 generate_exception(ctx, EXCP_RI);
1530 GEN_LOAD_REG_TN(T2, rs);
1533 MIPS_INVAL("branch/jump");
1534 generate_exception(ctx, EXCP_RI);
1538 /* No condition to be computed */
1540 case OPC_BEQ: /* rx == rx */
1541 case OPC_BEQL: /* rx == rx likely */
1542 case OPC_BGEZ: /* 0 >= 0 */
1543 case OPC_BGEZL: /* 0 >= 0 likely */
1544 case OPC_BLEZ: /* 0 <= 0 */
1545 case OPC_BLEZL: /* 0 <= 0 likely */
1547 ctx->hflags |= MIPS_HFLAG_B;
1548 MIPS_DEBUG("balways");
1550 case OPC_BGEZAL: /* 0 >= 0 */
1551 case OPC_BGEZALL: /* 0 >= 0 likely */
1552 /* Always take and link */
1554 ctx->hflags |= MIPS_HFLAG_B;
1555 MIPS_DEBUG("balways and link");
1557 case OPC_BNE: /* rx != rx */
1558 case OPC_BGTZ: /* 0 > 0 */
1559 case OPC_BLTZ: /* 0 < 0 */
1560 /* Treated as NOP */
1561 MIPS_DEBUG("bnever (NOP)");
1563 case OPC_BLTZAL: /* 0 < 0 */
1564 gen_op_set_T0(ctx->pc + 8);
1565 gen_op_store_T0_gpr(31);
1567 case OPC_BLTZALL: /* 0 < 0 likely */
1568 gen_op_set_T0(ctx->pc + 8);
1569 gen_op_store_T0_gpr(31);
1570 gen_goto_tb(ctx, 0, ctx->pc + 8);
1572 case OPC_BNEL: /* rx != rx likely */
1573 case OPC_BGTZL: /* 0 > 0 likely */
1574 case OPC_BLTZL: /* 0 < 0 likely */
1575 /* Skip the instruction in the delay slot */
1576 MIPS_DEBUG("bnever and skip");
1577 gen_goto_tb(ctx, 0, ctx->pc + 8);
1580 ctx->hflags |= MIPS_HFLAG_B;
1581 MIPS_DEBUG("j %08x", btarget);
1585 ctx->hflags |= MIPS_HFLAG_B;
1586 MIPS_DEBUG("jal %08x", btarget);
1589 ctx->hflags |= MIPS_HFLAG_BR;
1590 MIPS_DEBUG("jr %s", regnames[rs]);
1594 ctx->hflags |= MIPS_HFLAG_BR;
1595 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
1598 MIPS_INVAL("branch/jump");
1599 generate_exception(ctx, EXCP_RI);
1606 MIPS_DEBUG("beq %s, %s, %08x",
1607 regnames[rs], regnames[rt], btarget);
1611 MIPS_DEBUG("beql %s, %s, %08x",
1612 regnames[rs], regnames[rt], btarget);
1616 MIPS_DEBUG("bne %s, %s, %08x",
1617 regnames[rs], regnames[rt], btarget);
1621 MIPS_DEBUG("bnel %s, %s, %08x",
1622 regnames[rs], regnames[rt], btarget);
1626 MIPS_DEBUG("bgez %s, %08x", regnames[rs], btarget);
1630 MIPS_DEBUG("bgezl %s, %08x", regnames[rs], btarget);
1634 MIPS_DEBUG("bgezal %s, %08x", regnames[rs], btarget);
1640 MIPS_DEBUG("bgezall %s, %08x", regnames[rs], btarget);
1644 MIPS_DEBUG("bgtz %s, %08x", regnames[rs], btarget);
1648 MIPS_DEBUG("bgtzl %s, %08x", regnames[rs], btarget);
1652 MIPS_DEBUG("blez %s, %08x", regnames[rs], btarget);
1656 MIPS_DEBUG("blezl %s, %08x", regnames[rs], btarget);
1660 MIPS_DEBUG("bltz %s, %08x", regnames[rs], btarget);
1664 MIPS_DEBUG("bltzl %s, %08x", regnames[rs], btarget);
1669 MIPS_DEBUG("bltzal %s, %08x", regnames[rs], btarget);
1671 ctx->hflags |= MIPS_HFLAG_BC;
1676 MIPS_DEBUG("bltzall %s, %08x", regnames[rs], btarget);
1678 ctx->hflags |= MIPS_HFLAG_BL;
1681 MIPS_INVAL("conditional branch/jump");
1682 generate_exception(ctx, EXCP_RI);
1687 MIPS_DEBUG("enter ds: link %d cond %02x target %08x",
1688 blink, ctx->hflags, btarget);
1689 ctx->btarget = btarget;
1691 gen_op_set_T0(ctx->pc + 8);
1692 gen_op_store_T0_gpr(blink);
1696 /* special3 bitfield operations */
1697 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
1698 int rs, int lsb, int msb)
1700 GEN_LOAD_REG_TN(T1, rs);
1705 gen_op_ext(lsb, msb + 1);
1710 gen_op_ext(lsb, msb + 1 + 32);
1715 gen_op_ext(lsb + 32, msb + 1);
1718 gen_op_ext(lsb, msb + 1);
1723 GEN_LOAD_REG_TN(T2, rt);
1724 gen_op_ins(lsb, msb - lsb + 1);
1729 GEN_LOAD_REG_TN(T2, rt);
1730 gen_op_ins(lsb, msb - lsb + 1 + 32);
1735 GEN_LOAD_REG_TN(T2, rt);
1736 gen_op_ins(lsb + 32, msb - lsb + 1);
1741 GEN_LOAD_REG_TN(T2, rt);
1742 gen_op_ins(lsb, msb - lsb + 1);
1746 MIPS_INVAL("bitops");
1747 generate_exception(ctx, EXCP_RI);
1750 GEN_STORE_TN_REG(rt, T0);
1753 /* CP0 (MMU and control) */
1754 static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
1756 const char *rn = "invalid";
1762 gen_op_mfc0_index();
1766 // gen_op_mfc0_mvpcontrol(); /* MT ASE */
1770 // gen_op_mfc0_mvpconf0(); /* MT ASE */
1774 // gen_op_mfc0_mvpconf1(); /* MT ASE */
1784 gen_op_mfc0_random();
1788 // gen_op_mfc0_vpecontrol(); /* MT ASE */
1792 // gen_op_mfc0_vpeconf0(); /* MT ASE */
1796 // gen_op_mfc0_vpeconf1(); /* MT ASE */
1800 // gen_op_mfc0_YQMask(); /* MT ASE */
1804 // gen_op_mfc0_vpeschedule(); /* MT ASE */
1808 // gen_op_mfc0_vpeschefback(); /* MT ASE */
1809 rn = "VPEScheFBack";
1812 // gen_op_mfc0_vpeopt(); /* MT ASE */
1822 gen_op_mfc0_entrylo0();
1826 // gen_op_mfc0_tcstatus(); /* MT ASE */
1830 // gen_op_mfc0_tcbind(); /* MT ASE */
1834 // gen_op_mfc0_tcrestart(); /* MT ASE */
1838 // gen_op_mfc0_tchalt(); /* MT ASE */
1842 // gen_op_mfc0_tccontext(); /* MT ASE */
1846 // gen_op_mfc0_tcschedule(); /* MT ASE */
1850 // gen_op_mfc0_tcschefback(); /* MT ASE */
1860 gen_op_mfc0_entrylo1();
1870 gen_op_mfc0_context();
1874 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
1875 rn = "ContextConfig";
1884 gen_op_mfc0_pagemask();
1888 gen_op_mfc0_pagegrain();
1898 gen_op_mfc0_wired();
1902 // gen_op_mfc0_srsconf0(); /* shadow registers */
1906 // gen_op_mfc0_srsconf1(); /* shadow registers */
1910 // gen_op_mfc0_srsconf2(); /* shadow registers */
1914 // gen_op_mfc0_srsconf3(); /* shadow registers */
1918 // gen_op_mfc0_srsconf4(); /* shadow registers */
1928 gen_op_mfc0_hwrena();
1938 gen_op_mfc0_badvaddr();
1948 gen_op_mfc0_count();
1951 /* 6,7 are implementation dependent */
1959 gen_op_mfc0_entryhi();
1969 gen_op_mfc0_compare();
1972 /* 6,7 are implementation dependent */
1980 gen_op_mfc0_status();
1984 gen_op_mfc0_intctl();
1988 gen_op_mfc0_srsctl();
1992 // gen_op_mfc0_srsmap(); /* shadow registers */
2002 gen_op_mfc0_cause();
2026 gen_op_mfc0_ebase();
2036 gen_op_mfc0_config0();
2040 gen_op_mfc0_config1();
2044 gen_op_mfc0_config2();
2048 gen_op_mfc0_config3();
2051 /* 4,5 are reserved */
2052 /* 6,7 are implementation dependent */
2054 gen_op_mfc0_config6();
2058 gen_op_mfc0_config7();
2068 gen_op_mfc0_lladdr();
2078 gen_op_mfc0_watchlo0();
2082 // gen_op_mfc0_watchlo1();
2086 // gen_op_mfc0_watchlo2();
2090 // gen_op_mfc0_watchlo3();
2094 // gen_op_mfc0_watchlo4();
2098 // gen_op_mfc0_watchlo5();
2102 // gen_op_mfc0_watchlo6();
2106 // gen_op_mfc0_watchlo7();
2116 gen_op_mfc0_watchhi0();
2120 // gen_op_mfc0_watchhi1();
2124 // gen_op_mfc0_watchhi2();
2128 // gen_op_mfc0_watchhi3();
2132 // gen_op_mfc0_watchhi4();
2136 // gen_op_mfc0_watchhi5();
2140 // gen_op_mfc0_watchhi6();
2144 // gen_op_mfc0_watchhi7();
2154 /* 64 bit MMU only */
2155 gen_op_mfc0_xcontext();
2163 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2166 gen_op_mfc0_framemask();
2175 rn = "'Diagnostic"; /* implementation dependent */
2180 gen_op_mfc0_debug(); /* EJTAG support */
2184 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2185 rn = "TraceControl";
2188 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2189 rn = "TraceControl2";
2192 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2193 rn = "UserTraceData";
2196 // gen_op_mfc0_debug(); /* PDtrace support */
2206 gen_op_mfc0_depc(); /* EJTAG support */
2216 gen_op_mfc0_performance0();
2217 rn = "Performance0";
2220 // gen_op_mfc0_performance1();
2221 rn = "Performance1";
2224 // gen_op_mfc0_performance2();
2225 rn = "Performance2";
2228 // gen_op_mfc0_performance3();
2229 rn = "Performance3";
2232 // gen_op_mfc0_performance4();
2233 rn = "Performance4";
2236 // gen_op_mfc0_performance5();
2237 rn = "Performance5";
2240 // gen_op_mfc0_performance6();
2241 rn = "Performance6";
2244 // gen_op_mfc0_performance7();
2245 rn = "Performance7";
2270 gen_op_mfc0_taglo();
2277 gen_op_mfc0_datalo();
2290 gen_op_mfc0_taghi();
2297 gen_op_mfc0_datahi();
2307 gen_op_mfc0_errorepc();
2317 gen_op_mfc0_desave(); /* EJTAG support */
2327 #if defined MIPS_DEBUG_DISAS
2328 if (loglevel & CPU_LOG_TB_IN_ASM) {
2329 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2336 #if defined MIPS_DEBUG_DISAS
2337 if (loglevel & CPU_LOG_TB_IN_ASM) {
2338 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2342 generate_exception(ctx, EXCP_RI);
2345 static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
2347 const char *rn = "invalid";
2353 gen_op_mtc0_index();
2357 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
2361 // gen_op_mtc0_mvpconf0(); /* MT ASE */
2365 // gen_op_mtc0_mvpconf1(); /* MT ASE */
2379 // gen_op_mtc0_vpecontrol(); /* MT ASE */
2383 // gen_op_mtc0_vpeconf0(); /* MT ASE */
2387 // gen_op_mtc0_vpeconf1(); /* MT ASE */
2391 // gen_op_mtc0_YQMask(); /* MT ASE */
2395 // gen_op_mtc0_vpeschedule(); /* MT ASE */
2399 // gen_op_mtc0_vpeschefback(); /* MT ASE */
2400 rn = "VPEScheFBack";
2403 // gen_op_mtc0_vpeopt(); /* MT ASE */
2413 gen_op_mtc0_entrylo0();
2417 // gen_op_mtc0_tcstatus(); /* MT ASE */
2421 // gen_op_mtc0_tcbind(); /* MT ASE */
2425 // gen_op_mtc0_tcrestart(); /* MT ASE */
2429 // gen_op_mtc0_tchalt(); /* MT ASE */
2433 // gen_op_mtc0_tccontext(); /* MT ASE */
2437 // gen_op_mtc0_tcschedule(); /* MT ASE */
2441 // gen_op_mtc0_tcschefback(); /* MT ASE */
2451 gen_op_mtc0_entrylo1();
2461 gen_op_mtc0_context();
2465 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2466 rn = "ContextConfig";
2475 gen_op_mtc0_pagemask();
2479 gen_op_mtc0_pagegrain();
2489 gen_op_mtc0_wired();
2493 // gen_op_mtc0_srsconf0(); /* shadow registers */
2497 // gen_op_mtc0_srsconf1(); /* shadow registers */
2501 // gen_op_mtc0_srsconf2(); /* shadow registers */
2505 // gen_op_mtc0_srsconf3(); /* shadow registers */
2509 // gen_op_mtc0_srsconf4(); /* shadow registers */
2519 gen_op_mtc0_hwrena();
2533 gen_op_mtc0_count();
2536 /* 6,7 are implementation dependent */
2540 /* Stop translation as we may have switched the execution mode */
2541 ctx->bstate = BS_STOP;
2546 gen_op_mtc0_entryhi();
2556 gen_op_mtc0_compare();
2559 /* 6,7 are implementation dependent */
2563 /* Stop translation as we may have switched the execution mode */
2564 ctx->bstate = BS_STOP;
2569 gen_op_mtc0_status();
2573 gen_op_mtc0_intctl();
2577 gen_op_mtc0_srsctl();
2581 // gen_op_mtc0_srsmap(); /* shadow registers */
2587 /* Stop translation as we may have switched the execution mode */
2588 ctx->bstate = BS_STOP;
2593 gen_op_mtc0_cause();
2599 /* Stop translation as we may have switched the execution mode */
2600 ctx->bstate = BS_STOP;
2619 gen_op_mtc0_ebase();
2629 gen_op_mtc0_config0();
2633 /* ignored, read only */
2637 gen_op_mtc0_config2();
2641 /* ignored, read only */
2644 /* 4,5 are reserved */
2645 /* 6,7 are implementation dependent */
2655 rn = "Invalid config selector";
2658 /* Stop translation as we may have switched the execution mode */
2659 ctx->bstate = BS_STOP;
2674 gen_op_mtc0_watchlo0();
2678 // gen_op_mtc0_watchlo1();
2682 // gen_op_mtc0_watchlo2();
2686 // gen_op_mtc0_watchlo3();
2690 // gen_op_mtc0_watchlo4();
2694 // gen_op_mtc0_watchlo5();
2698 // gen_op_mtc0_watchlo6();
2702 // gen_op_mtc0_watchlo7();
2712 gen_op_mtc0_watchhi0();
2716 // gen_op_mtc0_watchhi1();
2720 // gen_op_mtc0_watchhi2();
2724 // gen_op_mtc0_watchhi3();
2728 // gen_op_mtc0_watchhi4();
2732 // gen_op_mtc0_watchhi5();
2736 // gen_op_mtc0_watchhi6();
2740 // gen_op_mtc0_watchhi7();
2750 /* 64 bit MMU only */
2751 gen_op_mtc0_xcontext();
2759 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2762 gen_op_mtc0_framemask();
2771 rn = "Diagnostic"; /* implementation dependent */
2776 gen_op_mtc0_debug(); /* EJTAG support */
2780 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2781 rn = "TraceControl";
2784 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2785 rn = "TraceControl2";
2788 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2789 rn = "UserTraceData";
2792 // gen_op_mtc0_debug(); /* PDtrace support */
2798 /* Stop translation as we may have switched the execution mode */
2799 ctx->bstate = BS_STOP;
2804 gen_op_mtc0_depc(); /* EJTAG support */
2814 gen_op_mtc0_performance0();
2815 rn = "Performance0";
2818 // gen_op_mtc0_performance1();
2819 rn = "Performance1";
2822 // gen_op_mtc0_performance2();
2823 rn = "Performance2";
2826 // gen_op_mtc0_performance3();
2827 rn = "Performance3";
2830 // gen_op_mtc0_performance4();
2831 rn = "Performance4";
2834 // gen_op_mtc0_performance5();
2835 rn = "Performance5";
2838 // gen_op_mtc0_performance6();
2839 rn = "Performance6";
2842 // gen_op_mtc0_performance7();
2843 rn = "Performance7";
2869 gen_op_mtc0_taglo();
2876 gen_op_mtc0_datalo();
2889 gen_op_mtc0_taghi();
2896 gen_op_mtc0_datahi();
2907 gen_op_mtc0_errorepc();
2917 gen_op_mtc0_desave(); /* EJTAG support */
2923 /* Stop translation as we may have switched the execution mode */
2924 ctx->bstate = BS_STOP;
2929 #if defined MIPS_DEBUG_DISAS
2930 if (loglevel & CPU_LOG_TB_IN_ASM) {
2931 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2938 #if defined MIPS_DEBUG_DISAS
2939 if (loglevel & CPU_LOG_TB_IN_ASM) {
2940 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2944 generate_exception(ctx, EXCP_RI);
2947 static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
2949 const char *rn = "invalid";
2955 gen_op_mfc0_index();
2959 // gen_op_dmfc0_mvpcontrol(); /* MT ASE */
2963 // gen_op_dmfc0_mvpconf0(); /* MT ASE */
2967 // gen_op_dmfc0_mvpconf1(); /* MT ASE */
2977 gen_op_mfc0_random();
2981 // gen_op_dmfc0_vpecontrol(); /* MT ASE */
2985 // gen_op_dmfc0_vpeconf0(); /* MT ASE */
2989 // gen_op_dmfc0_vpeconf1(); /* MT ASE */
2993 // gen_op_dmfc0_YQMask(); /* MT ASE */
2997 // gen_op_dmfc0_vpeschedule(); /* MT ASE */
3001 // gen_op_dmfc0_vpeschefback(); /* MT ASE */
3002 rn = "VPEScheFBack";
3005 // gen_op_dmfc0_vpeopt(); /* MT ASE */
3015 gen_op_dmfc0_entrylo0();
3019 // gen_op_dmfc0_tcstatus(); /* MT ASE */
3023 // gen_op_dmfc0_tcbind(); /* MT ASE */
3027 // gen_op_dmfc0_tcrestart(); /* MT ASE */
3031 // gen_op_dmfc0_tchalt(); /* MT ASE */
3035 // gen_op_dmfc0_tccontext(); /* MT ASE */
3039 // gen_op_dmfc0_tcschedule(); /* MT ASE */
3043 // gen_op_dmfc0_tcschefback(); /* MT ASE */
3053 gen_op_dmfc0_entrylo1();
3063 gen_op_dmfc0_context();
3067 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3068 rn = "ContextConfig";
3077 gen_op_mfc0_pagemask();
3081 gen_op_mfc0_pagegrain();
3091 gen_op_mfc0_wired();
3095 // gen_op_dmfc0_srsconf0(); /* shadow registers */
3099 // gen_op_dmfc0_srsconf1(); /* shadow registers */
3103 // gen_op_dmfc0_srsconf2(); /* shadow registers */
3107 // gen_op_dmfc0_srsconf3(); /* shadow registers */
3111 // gen_op_dmfc0_srsconf4(); /* shadow registers */
3121 gen_op_mfc0_hwrena();
3131 gen_op_dmfc0_badvaddr();
3141 gen_op_mfc0_count();
3144 /* 6,7 are implementation dependent */
3152 gen_op_dmfc0_entryhi();
3162 gen_op_mfc0_compare();
3165 /* 6,7 are implementation dependent */
3173 gen_op_mfc0_status();
3177 gen_op_mfc0_intctl();
3181 gen_op_mfc0_srsctl();
3185 gen_op_mfc0_srsmap(); /* shadow registers */
3195 gen_op_mfc0_cause();
3219 gen_op_mfc0_ebase();
3229 gen_op_mfc0_config0();
3233 gen_op_mfc0_config1();
3237 gen_op_mfc0_config2();
3241 gen_op_mfc0_config3();
3244 /* 6,7 are implementation dependent */
3252 gen_op_dmfc0_lladdr();
3262 gen_op_dmfc0_watchlo0();
3266 // gen_op_dmfc0_watchlo1();
3270 // gen_op_dmfc0_watchlo2();
3274 // gen_op_dmfc0_watchlo3();
3278 // gen_op_dmfc0_watchlo4();
3282 // gen_op_dmfc0_watchlo5();
3286 // gen_op_dmfc0_watchlo6();
3290 // gen_op_dmfc0_watchlo7();
3300 gen_op_mfc0_watchhi0();
3304 // gen_op_mfc0_watchhi1();
3308 // gen_op_mfc0_watchhi2();
3312 // gen_op_mfc0_watchhi3();
3316 // gen_op_mfc0_watchhi4();
3320 // gen_op_mfc0_watchhi5();
3324 // gen_op_mfc0_watchhi6();
3328 // gen_op_mfc0_watchhi7();
3338 /* 64 bit MMU only */
3339 gen_op_dmfc0_xcontext();
3347 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3350 gen_op_mfc0_framemask();
3359 rn = "'Diagnostic"; /* implementation dependent */
3364 gen_op_mfc0_debug(); /* EJTAG support */
3368 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3369 rn = "TraceControl";
3372 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3373 rn = "TraceControl2";
3376 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3377 rn = "UserTraceData";
3380 // gen_op_dmfc0_debug(); /* PDtrace support */
3390 gen_op_dmfc0_depc(); /* EJTAG support */
3400 gen_op_mfc0_performance0();
3401 rn = "Performance0";
3404 // gen_op_dmfc0_performance1();
3405 rn = "Performance1";
3408 // gen_op_dmfc0_performance2();
3409 rn = "Performance2";
3412 // gen_op_dmfc0_performance3();
3413 rn = "Performance3";
3416 // gen_op_dmfc0_performance4();
3417 rn = "Performance4";
3420 // gen_op_dmfc0_performance5();
3421 rn = "Performance5";
3424 // gen_op_dmfc0_performance6();
3425 rn = "Performance6";
3428 // gen_op_dmfc0_performance7();
3429 rn = "Performance7";
3454 gen_op_mfc0_taglo();
3461 gen_op_mfc0_datalo();
3474 gen_op_mfc0_taghi();
3481 gen_op_mfc0_datahi();
3491 gen_op_dmfc0_errorepc();
3501 gen_op_mfc0_desave(); /* EJTAG support */
3511 #if defined MIPS_DEBUG_DISAS
3512 if (loglevel & CPU_LOG_TB_IN_ASM) {
3513 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3520 #if defined MIPS_DEBUG_DISAS
3521 if (loglevel & CPU_LOG_TB_IN_ASM) {
3522 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3526 generate_exception(ctx, EXCP_RI);
3529 static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
3531 const char *rn = "invalid";
3537 gen_op_mtc0_index();
3541 // gen_op_dmtc0_mvpcontrol(); /* MT ASE */
3545 // gen_op_dmtc0_mvpconf0(); /* MT ASE */
3549 // gen_op_dmtc0_mvpconf1(); /* MT ASE */
3563 // gen_op_dmtc0_vpecontrol(); /* MT ASE */
3567 // gen_op_dmtc0_vpeconf0(); /* MT ASE */
3571 // gen_op_dmtc0_vpeconf1(); /* MT ASE */
3575 // gen_op_dmtc0_YQMask(); /* MT ASE */
3579 // gen_op_dmtc0_vpeschedule(); /* MT ASE */
3583 // gen_op_dmtc0_vpeschefback(); /* MT ASE */
3584 rn = "VPEScheFBack";
3587 // gen_op_dmtc0_vpeopt(); /* MT ASE */
3597 gen_op_dmtc0_entrylo0();
3601 // gen_op_dmtc0_tcstatus(); /* MT ASE */
3605 // gen_op_dmtc0_tcbind(); /* MT ASE */
3609 // gen_op_dmtc0_tcrestart(); /* MT ASE */
3613 // gen_op_dmtc0_tchalt(); /* MT ASE */
3617 // gen_op_dmtc0_tccontext(); /* MT ASE */
3621 // gen_op_dmtc0_tcschedule(); /* MT ASE */
3625 // gen_op_dmtc0_tcschefback(); /* MT ASE */
3635 gen_op_dmtc0_entrylo1();
3645 gen_op_dmtc0_context();
3649 // gen_op_dmtc0_contextconfig(); /* SmartMIPS ASE */
3650 rn = "ContextConfig";
3659 gen_op_mtc0_pagemask();
3663 gen_op_mtc0_pagegrain();
3673 gen_op_mtc0_wired();
3677 // gen_op_dmtc0_srsconf0(); /* shadow registers */
3681 // gen_op_dmtc0_srsconf1(); /* shadow registers */
3685 // gen_op_dmtc0_srsconf2(); /* shadow registers */
3689 // gen_op_dmtc0_srsconf3(); /* shadow registers */
3693 // gen_op_dmtc0_srsconf4(); /* shadow registers */
3703 gen_op_mtc0_hwrena();
3717 gen_op_mtc0_count();
3720 /* 6,7 are implementation dependent */
3724 /* Stop translation as we may have switched the execution mode */
3725 ctx->bstate = BS_STOP;
3730 gen_op_mtc0_entryhi();
3740 gen_op_mtc0_compare();
3743 /* 6,7 are implementation dependent */
3747 /* Stop translation as we may have switched the execution mode */
3748 ctx->bstate = BS_STOP;
3753 gen_op_mtc0_status();
3757 gen_op_mtc0_intctl();
3761 gen_op_mtc0_srsctl();
3765 gen_op_mtc0_srsmap(); /* shadow registers */
3771 /* Stop translation as we may have switched the execution mode */
3772 ctx->bstate = BS_STOP;
3777 gen_op_mtc0_cause();
3783 /* Stop translation as we may have switched the execution mode */
3784 ctx->bstate = BS_STOP;
3803 gen_op_mtc0_ebase();
3813 gen_op_mtc0_config0();
3821 gen_op_mtc0_config2();
3828 /* 6,7 are implementation dependent */
3830 rn = "Invalid config selector";
3833 /* Stop translation as we may have switched the execution mode */
3834 ctx->bstate = BS_STOP;
3849 gen_op_dmtc0_watchlo0();
3853 // gen_op_dmtc0_watchlo1();
3857 // gen_op_dmtc0_watchlo2();
3861 // gen_op_dmtc0_watchlo3();
3865 // gen_op_dmtc0_watchlo4();
3869 // gen_op_dmtc0_watchlo5();
3873 // gen_op_dmtc0_watchlo6();
3877 // gen_op_dmtc0_watchlo7();
3887 gen_op_mtc0_watchhi0();
3891 // gen_op_dmtc0_watchhi1();
3895 // gen_op_dmtc0_watchhi2();
3899 // gen_op_dmtc0_watchhi3();
3903 // gen_op_dmtc0_watchhi4();
3907 // gen_op_dmtc0_watchhi5();
3911 // gen_op_dmtc0_watchhi6();
3915 // gen_op_dmtc0_watchhi7();
3925 /* 64 bit MMU only */
3926 gen_op_dmtc0_xcontext();
3934 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3937 gen_op_mtc0_framemask();
3946 rn = "Diagnostic"; /* implementation dependent */
3951 gen_op_mtc0_debug(); /* EJTAG support */
3955 // gen_op_dmtc0_tracecontrol(); /* PDtrace support */
3956 rn = "TraceControl";
3959 // gen_op_dmtc0_tracecontrol2(); /* PDtrace support */
3960 rn = "TraceControl2";
3963 // gen_op_dmtc0_usertracedata(); /* PDtrace support */
3964 rn = "UserTraceData";
3967 // gen_op_dmtc0_debug(); /* PDtrace support */
3973 /* Stop translation as we may have switched the execution mode */
3974 ctx->bstate = BS_STOP;
3979 gen_op_dmtc0_depc(); /* EJTAG support */
3989 gen_op_mtc0_performance0();
3990 rn = "Performance0";
3993 // gen_op_dmtc0_performance1();
3994 rn = "Performance1";
3997 // gen_op_dmtc0_performance2();
3998 rn = "Performance2";
4001 // gen_op_dmtc0_performance3();
4002 rn = "Performance3";
4005 // gen_op_dmtc0_performance4();
4006 rn = "Performance4";
4009 // gen_op_dmtc0_performance5();
4010 rn = "Performance5";
4013 // gen_op_dmtc0_performance6();
4014 rn = "Performance6";
4017 // gen_op_dmtc0_performance7();
4018 rn = "Performance7";
4044 gen_op_mtc0_taglo();
4051 gen_op_mtc0_datalo();
4064 gen_op_mtc0_taghi();
4071 gen_op_mtc0_datahi();
4082 gen_op_dmtc0_errorepc();
4092 gen_op_mtc0_desave(); /* EJTAG support */
4098 /* Stop translation as we may have switched the execution mode */
4099 ctx->bstate = BS_STOP;
4104 #if defined MIPS_DEBUG_DISAS
4105 if (loglevel & CPU_LOG_TB_IN_ASM) {
4106 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4113 #if defined MIPS_DEBUG_DISAS
4114 if (loglevel & CPU_LOG_TB_IN_ASM) {
4115 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4119 generate_exception(ctx, EXCP_RI);
4122 static void gen_cp0 (DisasContext *ctx, uint32_t opc, int rt, int rd)
4124 const char *opn = "unk";
4132 gen_mfc0(ctx, rd, ctx->opcode & 0x7);
4133 gen_op_store_T0_gpr(rt);
4137 GEN_LOAD_REG_TN(T0, rt);
4138 gen_mtc0(ctx, rd, ctx->opcode & 0x7);
4146 gen_dmfc0(ctx, rd, ctx->opcode & 0x7);
4147 gen_op_store_T0_gpr(rt);
4151 GEN_LOAD_REG_TN(T0, rt);
4152 gen_dmtc0(ctx, rd, ctx->opcode & 0x7);
4155 #if defined(MIPS_USES_R4K_TLB)
4175 save_cpu_state(ctx, 0);
4177 ctx->bstate = BS_EXCP;
4181 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
4182 generate_exception(ctx, EXCP_RI);
4184 save_cpu_state(ctx, 0);
4186 ctx->bstate = BS_EXCP;
4191 /* If we get an exception, we want to restart at next instruction */
4193 save_cpu_state(ctx, 1);
4196 ctx->bstate = BS_EXCP;
4199 if (loglevel & CPU_LOG_TB_IN_ASM) {
4200 fprintf(logfile, "Invalid CP0 opcode: %08x %03x %03x %03x\n",
4201 ctx->opcode, ctx->opcode >> 26, ctx->opcode & 0x3F,
4202 ((ctx->opcode >> 16) & 0x1F));
4204 generate_exception(ctx, EXCP_RI);
4207 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
4210 /* CP1 Branches (before delay slot) */
4211 static void gen_compute_branch1 (DisasContext *ctx, uint32_t op,
4214 target_ulong btarget;
4216 btarget = ctx->pc + 4 + offset;
4221 MIPS_DEBUG("bc1f " TARGET_FMT_lx, btarget);
4225 MIPS_DEBUG("bc1fl " TARGET_FMT_lx, btarget);
4229 MIPS_DEBUG("bc1t " TARGET_FMT_lx, btarget);
4231 ctx->hflags |= MIPS_HFLAG_BC;
4235 MIPS_DEBUG("bc1tl " TARGET_FMT_lx, btarget);
4237 ctx->hflags |= MIPS_HFLAG_BL;
4240 MIPS_INVAL("cp1 branch/jump");
4241 generate_exception (ctx, EXCP_RI);
4246 MIPS_DEBUG("enter ds: cond %02x target " TARGET_FMT_lx,
4247 ctx->hflags, btarget);
4248 ctx->btarget = btarget;
4253 /* Coprocessor 1 (FPU) */
4254 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
4256 const char *opn = "unk";
4260 GEN_LOAD_FREG_FTN(WT0, fs);
4262 GEN_STORE_TN_REG(rt, T0);
4266 GEN_LOAD_REG_TN(T0, rt);
4268 GEN_STORE_FTN_FREG(fs, WT0);
4272 if (fs != 0 && fs != 31) {
4273 MIPS_INVAL("cfc1 freg");
4274 generate_exception (ctx, EXCP_RI);
4277 GEN_LOAD_IMM_TN(T1, fs);
4279 GEN_STORE_TN_REG(rt, T0);
4283 if (fs != 0 && fs != 31) {
4284 MIPS_INVAL("ctc1 freg");
4285 generate_exception (ctx, EXCP_RI);
4288 GEN_LOAD_IMM_TN(T1, fs);
4289 GEN_LOAD_REG_TN(T0, rt);
4295 /* Not implemented, fallthrough. */
4297 if (loglevel & CPU_LOG_TB_IN_ASM) {
4298 fprintf(logfile, "Invalid CP1 opcode: %08x %03x %03x %03x\n",
4299 ctx->opcode, ctx->opcode >> 26, ctx->opcode & 0x3F,
4300 ((ctx->opcode >> 16) & 0x1F));
4302 generate_exception (ctx, EXCP_RI);
4305 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
4308 /* verify if floating point register is valid; an operation is not defined
4309 * if bit 0 of any register specification is set and the FR bit in the
4310 * Status register equals zero, since the register numbers specify an
4311 * even-odd pair of adjacent coprocessor general registers. When the FR bit
4312 * in the Status register equals one, both even and odd register numbers
4313 * are valid. This limitation exists only for 64 bit wide (d,l) registers.
4315 * Multiple 64 bit wide registers can be checked by calling
4316 * CHECK_FR(ctx, freg1 | freg2 | ... | fregN);
4318 #define CHECK_FR(ctx, freg) do { \
4319 if (!((ctx)->CP0_Status & (1<<CP0St_FR)) && ((freg) & 1)) { \
4320 generate_exception (ctx, EXCP_RI); \
4325 #define FOP(func, fmt) (((fmt) << 21) | (func))
4327 static void gen_farith (DisasContext *ctx, uint32_t op1, int ft, int fs, int fd)
4329 const char *opn = "unk";
4330 const char *condnames[] = {
4349 uint32_t func = ctx->opcode & 0x3f;
4351 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
4353 CHECK_FR(ctx, fs | ft | fd);
4354 GEN_LOAD_FREG_FTN(DT0, fs);
4355 GEN_LOAD_FREG_FTN(DT1, ft);
4356 gen_op_float_add_d();
4357 GEN_STORE_FTN_FREG(fd, DT2);
4362 CHECK_FR(ctx, fs | ft | fd);
4363 GEN_LOAD_FREG_FTN(DT0, fs);
4364 GEN_LOAD_FREG_FTN(DT1, ft);
4365 gen_op_float_sub_d();
4366 GEN_STORE_FTN_FREG(fd, DT2);
4371 CHECK_FR(ctx, fs | ft | fd);
4372 GEN_LOAD_FREG_FTN(DT0, fs);
4373 GEN_LOAD_FREG_FTN(DT1, ft);
4374 gen_op_float_mul_d();
4375 GEN_STORE_FTN_FREG(fd, DT2);
4380 CHECK_FR(ctx, fs | ft | fd);
4381 GEN_LOAD_FREG_FTN(DT0, fs);
4382 GEN_LOAD_FREG_FTN(DT1, ft);
4383 gen_op_float_div_d();
4384 GEN_STORE_FTN_FREG(fd, DT2);
4389 CHECK_FR(ctx, fs | fd);
4390 GEN_LOAD_FREG_FTN(DT0, fs);
4391 gen_op_float_sqrt_d();
4392 GEN_STORE_FTN_FREG(fd, DT2);
4396 CHECK_FR(ctx, fs | fd);
4397 GEN_LOAD_FREG_FTN(DT0, fs);
4398 gen_op_float_abs_d();
4399 GEN_STORE_FTN_FREG(fd, DT2);
4403 CHECK_FR(ctx, fs | fd);
4404 GEN_LOAD_FREG_FTN(DT0, fs);
4405 gen_op_float_mov_d();
4406 GEN_STORE_FTN_FREG(fd, DT2);
4410 CHECK_FR(ctx, fs | fd);
4411 GEN_LOAD_FREG_FTN(DT0, fs);
4412 gen_op_float_chs_d();
4413 GEN_STORE_FTN_FREG(fd, DT2);
4422 GEN_LOAD_FREG_FTN(DT0, fs);
4423 gen_op_float_roundw_d();
4424 GEN_STORE_FTN_FREG(fd, WT2);
4429 GEN_LOAD_FREG_FTN(DT0, fs);
4430 gen_op_float_truncw_d();
4431 GEN_STORE_FTN_FREG(fd, WT2);
4436 GEN_LOAD_FREG_FTN(DT0, fs);
4437 gen_op_float_ceilw_d();
4438 GEN_STORE_FTN_FREG(fd, WT2);
4443 GEN_LOAD_FREG_FTN(DT0, fs);
4444 gen_op_float_floorw_d();
4445 GEN_STORE_FTN_FREG(fd, WT2);
4450 GEN_LOAD_FREG_FTN(WT0, fs);
4451 gen_op_float_cvtd_s();
4452 GEN_STORE_FTN_FREG(fd, DT2);
4457 GEN_LOAD_FREG_FTN(WT0, fs);
4458 gen_op_float_cvtd_w();
4459 GEN_STORE_FTN_FREG(fd, DT2);
4478 CHECK_FR(ctx, fs | ft);
4479 GEN_LOAD_FREG_FTN(DT0, fs);
4480 GEN_LOAD_FREG_FTN(DT1, ft);
4482 opn = condnames[func-48];
4485 GEN_LOAD_FREG_FTN(WT0, fs);
4486 GEN_LOAD_FREG_FTN(WT1, ft);
4487 gen_op_float_add_s();
4488 GEN_STORE_FTN_FREG(fd, WT2);
4493 GEN_LOAD_FREG_FTN(WT0, fs);
4494 GEN_LOAD_FREG_FTN(WT1, ft);
4495 gen_op_float_sub_s();
4496 GEN_STORE_FTN_FREG(fd, WT2);
4501 GEN_LOAD_FREG_FTN(WT0, fs);
4502 GEN_LOAD_FREG_FTN(WT1, ft);
4503 gen_op_float_mul_s();
4504 GEN_STORE_FTN_FREG(fd, WT2);
4509 GEN_LOAD_FREG_FTN(WT0, fs);
4510 GEN_LOAD_FREG_FTN(WT1, ft);
4511 gen_op_float_div_s();
4512 GEN_STORE_FTN_FREG(fd, WT2);
4517 GEN_LOAD_FREG_FTN(WT0, fs);
4518 gen_op_float_sqrt_s();
4519 GEN_STORE_FTN_FREG(fd, WT2);
4523 GEN_LOAD_FREG_FTN(WT0, fs);
4524 gen_op_float_abs_s();
4525 GEN_STORE_FTN_FREG(fd, WT2);
4529 GEN_LOAD_FREG_FTN(WT0, fs);
4530 gen_op_float_mov_s();
4531 GEN_STORE_FTN_FREG(fd, WT2);
4535 GEN_LOAD_FREG_FTN(WT0, fs);
4536 gen_op_float_chs_s();
4537 GEN_STORE_FTN_FREG(fd, WT2);
4541 GEN_LOAD_FREG_FTN(WT0, fs);
4542 gen_op_float_roundw_s();
4543 GEN_STORE_FTN_FREG(fd, WT2);
4547 GEN_LOAD_FREG_FTN(WT0, fs);
4548 gen_op_float_truncw_s();
4549 GEN_STORE_FTN_FREG(fd, WT2);
4554 GEN_LOAD_FREG_FTN(DT0, fs);
4555 gen_op_float_cvts_d();
4556 GEN_STORE_FTN_FREG(fd, WT2);
4560 GEN_LOAD_FREG_FTN(WT0, fs);
4561 gen_op_float_cvts_w();
4562 GEN_STORE_FTN_FREG(fd, WT2);
4566 GEN_LOAD_FREG_FTN(WT0, fs);
4567 gen_op_float_cvtw_s();
4568 GEN_STORE_FTN_FREG(fd, WT2);
4573 GEN_LOAD_FREG_FTN(DT0, fs);
4574 gen_op_float_cvtw_d();
4575 GEN_STORE_FTN_FREG(fd, WT2);
4594 GEN_LOAD_FREG_FTN(WT0, fs);
4595 GEN_LOAD_FREG_FTN(WT1, ft);
4597 opn = condnames[func-48];
4600 if (loglevel & CPU_LOG_TB_IN_ASM) {
4601 fprintf(logfile, "Invalid FP arith function: %08x %03x %03x %03x\n",
4602 ctx->opcode, ctx->opcode >> 26, ctx->opcode & 0x3F,
4603 ((ctx->opcode >> 16) & 0x1F));
4605 generate_exception (ctx, EXCP_RI);
4609 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
4611 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
4614 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
4619 ccbit = 1 << (24 + cc);
4623 gen_op_movf(ccbit, rd, rs);
4625 gen_op_movt(ccbit, rd, rs);
4628 /* ISA extensions (ASEs) */
4629 /* MIPS16 extension to MIPS32 */
4630 /* SmartMIPS extension to MIPS32 */
4632 #ifdef TARGET_MIPS64
4633 /* Coprocessor 3 (FPU) */
4635 /* MDMX extension to MIPS64 */
4636 /* MIPS-3D extension to MIPS64 */
4640 static void gen_blikely(DisasContext *ctx)
4643 l1 = gen_new_label();
4645 gen_op_save_state(ctx->hflags & ~MIPS_HFLAG_BMASK);
4646 gen_goto_tb(ctx, 1, ctx->pc + 4);
4650 static void decode_opc (CPUState *env, DisasContext *ctx)
4654 uint32_t op, op1, op2;
4657 /* make sure instructions are on a word boundary */
4658 if (ctx->pc & 0x3) {
4659 env->CP0_BadVAddr = ctx->pc;
4660 generate_exception(ctx, EXCP_AdEL);
4664 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
4665 /* Handle blikely not taken case */
4666 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
4669 op = MASK_OP_MAJOR(ctx->opcode);
4670 rs = (ctx->opcode >> 21) & 0x1f;
4671 rt = (ctx->opcode >> 16) & 0x1f;
4672 rd = (ctx->opcode >> 11) & 0x1f;
4673 sa = (ctx->opcode >> 6) & 0x1f;
4674 imm = (int16_t)ctx->opcode;
4677 op1 = MASK_SPECIAL(ctx->opcode);
4679 case OPC_SLL: /* Arithmetic with immediate */
4680 case OPC_SRL ... OPC_SRA:
4681 gen_arith_imm(ctx, op1, rd, rt, sa);
4683 case OPC_SLLV: /* Arithmetic */
4684 case OPC_SRLV ... OPC_SRAV:
4685 case OPC_MOVZ ... OPC_MOVN:
4686 case OPC_ADD ... OPC_NOR:
4687 case OPC_SLT ... OPC_SLTU:
4688 gen_arith(ctx, op1, rd, rs, rt);
4690 case OPC_MULT ... OPC_DIVU:
4691 gen_muldiv(ctx, op1, rs, rt);
4693 case OPC_JR ... OPC_JALR:
4694 gen_compute_branch(ctx, op1, rs, rd, sa);
4696 case OPC_TGE ... OPC_TEQ: /* Traps */
4698 gen_trap(ctx, op1, rs, rt, -1);
4700 case OPC_MFHI: /* Move from HI/LO */
4702 gen_HILO(ctx, op1, rd);
4705 case OPC_MTLO: /* Move to HI/LO */
4706 gen_HILO(ctx, op1, rs);
4708 case OPC_PMON: /* Pmon entry point */
4712 generate_exception(ctx, EXCP_SYSCALL);
4713 ctx->bstate = BS_EXCP;
4716 generate_exception(ctx, EXCP_BREAK);
4718 case OPC_SPIM: /* SPIM ? */
4719 /* Implemented as RI exception for now. */
4720 MIPS_INVAL("spim (unofficial)");
4721 generate_exception(ctx, EXCP_RI);
4724 /* Treat as a noop. */
4728 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
4729 save_cpu_state(ctx, 1);
4730 gen_op_cp1_enabled();
4731 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
4732 (ctx->opcode >> 16) & 1);
4734 generate_exception_err(ctx, EXCP_CpU, 1);
4738 #ifdef TARGET_MIPS64
4739 /* MIPS64 specific opcodes */
4741 case OPC_DSRL ... OPC_DSRA:
4743 case OPC_DSRL32 ... OPC_DSRA32:
4744 gen_arith_imm(ctx, op1, rd, rt, sa);
4747 case OPC_DSRLV ... OPC_DSRAV:
4748 case OPC_DADD ... OPC_DSUBU:
4749 gen_arith(ctx, op1, rd, rs, rt);
4751 case OPC_DMULT ... OPC_DDIVU:
4752 gen_muldiv(ctx, op1, rs, rt);
4755 default: /* Invalid */
4756 MIPS_INVAL("special");
4757 generate_exception(ctx, EXCP_RI);
4762 op1 = MASK_SPECIAL2(ctx->opcode);
4764 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
4765 case OPC_MSUB ... OPC_MSUBU:
4766 gen_muldiv(ctx, op1, rs, rt);
4769 gen_arith(ctx, op1, rd, rs, rt);
4771 case OPC_CLZ ... OPC_CLO:
4772 gen_cl(ctx, op1, rd, rs);
4775 /* XXX: not clear which exception should be raised
4776 * when in debug mode...
4778 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
4779 generate_exception(ctx, EXCP_DBp);
4781 generate_exception(ctx, EXCP_DBp);
4783 /* Treat as a noop */
4785 #ifdef TARGET_MIPS64
4786 case OPC_DCLZ ... OPC_DCLO:
4787 gen_cl(ctx, op1, rd, rs);
4790 default: /* Invalid */
4791 MIPS_INVAL("special2");
4792 generate_exception(ctx, EXCP_RI);
4797 op1 = MASK_SPECIAL3(ctx->opcode);
4801 gen_bitops(ctx, op1, rt, rs, sa, rd);
4804 op2 = MASK_BSHFL(ctx->opcode);
4807 GEN_LOAD_REG_TN(T1, rt);
4811 GEN_LOAD_REG_TN(T1, rt);
4815 GEN_LOAD_REG_TN(T1, rt);
4818 default: /* Invalid */
4819 MIPS_INVAL("bshfl");
4820 generate_exception(ctx, EXCP_RI);
4823 GEN_STORE_TN_REG(rd, T0);
4828 save_cpu_state(ctx, 1);
4829 gen_op_rdhwr_cpunum();
4832 save_cpu_state(ctx, 1);
4833 gen_op_rdhwr_synci_step();
4836 save_cpu_state(ctx, 1);
4840 save_cpu_state(ctx, 1);
4841 gen_op_rdhwr_ccres();
4844 #if defined (CONFIG_USER_ONLY)
4845 gen_op_tls_value ();
4848 default: /* Invalid */
4849 MIPS_INVAL("rdhwr");
4850 generate_exception(ctx, EXCP_RI);
4853 GEN_STORE_TN_REG(rt, T0);
4855 #ifdef TARGET_MIPS64
4856 case OPC_DEXTM ... OPC_DEXT:
4857 case OPC_DINSM ... OPC_DINS:
4858 gen_bitops(ctx, op1, rt, rs, sa, rd);
4861 op2 = MASK_DBSHFL(ctx->opcode);
4864 GEN_LOAD_REG_TN(T1, rt);
4868 GEN_LOAD_REG_TN(T1, rt);
4871 default: /* Invalid */
4872 MIPS_INVAL("dbshfl");
4873 generate_exception(ctx, EXCP_RI);
4876 GEN_STORE_TN_REG(rd, T0);
4878 default: /* Invalid */
4879 MIPS_INVAL("special3");
4880 generate_exception(ctx, EXCP_RI);
4885 op1 = MASK_REGIMM(ctx->opcode);
4887 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
4888 case OPC_BLTZAL ... OPC_BGEZALL:
4889 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
4891 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
4893 gen_trap(ctx, op1, rs, -1, imm);
4898 default: /* Invalid */
4899 MIPS_INVAL("REGIMM");
4900 generate_exception(ctx, EXCP_RI);
4905 save_cpu_state(ctx, 1);
4906 gen_op_cp0_enabled();
4907 op1 = MASK_CP0(ctx->opcode);
4911 #ifdef TARGET_MIPS64
4915 gen_cp0(ctx, op1, rt, rd);
4917 case OPC_C0_FIRST ... OPC_C0_LAST:
4918 gen_cp0(ctx, MASK_C0(ctx->opcode), rt, rd);
4921 op2 = MASK_MFMC0(ctx->opcode);
4925 /* Stop translation as we may have switched the execution mode */
4926 ctx->bstate = BS_STOP;
4930 /* Stop translation as we may have switched the execution mode */
4931 ctx->bstate = BS_STOP;
4933 default: /* Invalid */
4934 MIPS_INVAL("MFMC0");
4935 generate_exception(ctx, EXCP_RI);
4938 GEN_STORE_TN_REG(rt, T0);
4942 if ((env->CP0_Config0 & (0x7 << CP0C0_AR)) == (1 << CP0C0_AR)) {
4943 /* Shadow registers not implemented. */
4944 GEN_LOAD_REG_TN(T0, rt);
4945 GEN_STORE_TN_REG(rd, T0);
4947 generate_exception(ctx, EXCP_RI);
4950 generate_exception(ctx, EXCP_RI);
4954 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
4955 gen_arith_imm(ctx, op, rt, rs, imm);
4957 case OPC_J ... OPC_JAL: /* Jump */
4958 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
4959 gen_compute_branch(ctx, op, rs, rt, offset);
4961 case OPC_BEQ ... OPC_BGTZ: /* Branch */
4962 case OPC_BEQL ... OPC_BGTZL:
4963 gen_compute_branch(ctx, op, rs, rt, imm << 2);
4965 case OPC_LB ... OPC_LWR: /* Load and stores */
4966 case OPC_SB ... OPC_SW:
4970 gen_ldst(ctx, op, rt, rs, imm);
4973 /* Treat as a noop */
4976 /* Treat as a noop */
4979 /* Floating point. */
4984 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
4985 save_cpu_state(ctx, 1);
4986 gen_op_cp1_enabled();
4987 gen_flt_ldst(ctx, op, rt, rs, imm);
4989 generate_exception_err(ctx, EXCP_CpU, 1);
4994 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
4995 save_cpu_state(ctx, 1);
4996 gen_op_cp1_enabled();
4997 op1 = MASK_CP1(ctx->opcode);
5003 #ifdef TARGET_MIPS64
5007 gen_cp1(ctx, op1, rt, rd);
5010 gen_compute_branch1(ctx, MASK_CP1_BCOND(ctx->opcode), imm << 2);
5016 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa);
5019 generate_exception (ctx, EXCP_RI);
5023 generate_exception_err(ctx, EXCP_CpU, 1);
5033 /* COP2: Not implemented. */
5034 generate_exception_err(ctx, EXCP_CpU, 2);
5038 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5039 save_cpu_state(ctx, 1);
5040 gen_op_cp1_enabled();
5041 op1 = MASK_CP3(ctx->opcode);
5046 /* Not implemented */
5048 generate_exception (ctx, EXCP_RI);
5052 generate_exception_err(ctx, EXCP_CpU, 1);
5056 #ifdef TARGET_MIPS64
5057 /* MIPS64 opcodes */
5059 case OPC_LDL ... OPC_LDR:
5060 case OPC_SDL ... OPC_SDR:
5065 gen_ldst(ctx, op, rt, rs, imm);
5067 case OPC_DADDI ... OPC_DADDIU:
5068 gen_arith_imm(ctx, op, rt, rs, imm);
5071 #ifdef MIPS_HAS_MIPS16
5073 /* MIPS16: Not implemented. */
5075 #ifdef MIPS_HAS_MDMX
5077 /* MDMX: Not implemented. */
5079 default: /* Invalid */
5081 generate_exception(ctx, EXCP_RI);
5084 if (ctx->hflags & MIPS_HFLAG_BMASK) {
5085 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
5086 /* Branches completion */
5087 ctx->hflags &= ~MIPS_HFLAG_BMASK;
5088 ctx->bstate = BS_BRANCH;
5089 save_cpu_state(ctx, 0);
5090 switch (hflags & MIPS_HFLAG_BMASK) {
5092 /* unconditional branch */
5093 MIPS_DEBUG("unconditional branch");
5094 gen_goto_tb(ctx, 0, ctx->btarget);
5097 /* blikely taken case */
5098 MIPS_DEBUG("blikely branch taken");
5099 gen_goto_tb(ctx, 0, ctx->btarget);
5102 /* Conditional branch */
5103 MIPS_DEBUG("conditional branch");
5106 l1 = gen_new_label();
5108 gen_goto_tb(ctx, 1, ctx->pc + 4);
5110 gen_goto_tb(ctx, 0, ctx->btarget);
5114 /* unconditional branch to register */
5115 MIPS_DEBUG("branch to register");
5119 MIPS_DEBUG("unknown branch");
5126 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
5129 DisasContext ctx, *ctxp = &ctx;
5130 target_ulong pc_start;
5131 uint16_t *gen_opc_end;
5134 if (search_pc && loglevel)
5135 fprintf (logfile, "search pc %d\n", search_pc);
5138 gen_opc_ptr = gen_opc_buf;
5139 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
5140 gen_opparam_ptr = gen_opparam_buf;
5145 ctx.bstate = BS_NONE;
5146 /* Restore delay slot state from the tb context. */
5147 ctx.hflags = tb->flags;
5148 ctx.saved_hflags = ctx.hflags;
5149 if (ctx.hflags & MIPS_HFLAG_BR) {
5150 gen_op_restore_breg_target();
5151 } else if (ctx.hflags & MIPS_HFLAG_B) {
5152 ctx.btarget = env->btarget;
5153 } else if (ctx.hflags & MIPS_HFLAG_BMASK) {
5154 /* If we are in the delay slot of a conditional branch,
5155 * restore the branch condition from env->bcond to T2
5157 ctx.btarget = env->btarget;
5158 gen_op_restore_bcond();
5160 #if defined(CONFIG_USER_ONLY)
5163 ctx.mem_idx = !((ctx.hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM);
5165 ctx.CP0_Status = env->CP0_Status;
5167 if (loglevel & CPU_LOG_TB_CPU) {
5168 fprintf(logfile, "------------------------------------------------\n");
5169 /* FIXME: This may print out stale hflags from env... */
5170 cpu_dump_state(env, logfile, fprintf, 0);
5173 #if defined MIPS_DEBUG_DISAS
5174 if (loglevel & CPU_LOG_TB_IN_ASM)
5175 fprintf(logfile, "\ntb %p super %d cond %04x\n",
5176 tb, ctx.mem_idx, ctx.hflags);
5178 while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) {
5179 if (env->nb_breakpoints > 0) {
5180 for(j = 0; j < env->nb_breakpoints; j++) {
5181 if (env->breakpoints[j] == ctx.pc) {
5182 save_cpu_state(ctxp, 1);
5183 ctx.bstate = BS_BRANCH;
5185 goto done_generating;
5191 j = gen_opc_ptr - gen_opc_buf;
5195 gen_opc_instr_start[lj++] = 0;
5197 gen_opc_pc[lj] = ctx.pc;
5198 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
5199 gen_opc_instr_start[lj] = 1;
5201 ctx.opcode = ldl_code(ctx.pc);
5202 decode_opc(env, &ctx);
5205 if (env->singlestep_enabled)
5208 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
5211 #if defined (MIPS_SINGLE_STEP)
5215 if (env->singlestep_enabled) {
5216 save_cpu_state(ctxp, ctx.bstate == BS_NONE);
5218 goto done_generating;
5220 else if (ctx.bstate != BS_BRANCH && ctx.bstate != BS_EXCP) {
5221 save_cpu_state(ctxp, 0);
5222 gen_goto_tb(&ctx, 0, ctx.pc);
5225 /* Generate the return instruction */
5228 *gen_opc_ptr = INDEX_op_end;
5230 j = gen_opc_ptr - gen_opc_buf;
5233 gen_opc_instr_start[lj++] = 0;
5236 tb->size = ctx.pc - pc_start;
5239 #if defined MIPS_DEBUG_DISAS
5240 if (loglevel & CPU_LOG_TB_IN_ASM)
5241 fprintf(logfile, "\n");
5243 if (loglevel & CPU_LOG_TB_IN_ASM) {
5244 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
5245 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
5246 fprintf(logfile, "\n");
5248 if (loglevel & CPU_LOG_TB_OP) {
5249 fprintf(logfile, "OP:\n");
5250 dump_ops(gen_opc_buf, gen_opparam_buf);
5251 fprintf(logfile, "\n");
5253 if (loglevel & CPU_LOG_TB_CPU) {
5254 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
5261 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
5263 return gen_intermediate_code_internal(env, tb, 0);
5266 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
5268 return gen_intermediate_code_internal(env, tb, 1);
5271 void fpu_dump_state(CPUState *env, FILE *f,
5272 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
5277 # define printfpr(fp) do { \
5278 fpu_fprintf(f, "w:%08x d:%08lx%08lx fd:%g fs:%g\n", \
5279 (fp)->w[FP_ENDIAN_IDX], (fp)->w[0], (fp)->w[1], (fp)->fd, (fp)->fs[FP_ENDIAN_IDX]); \
5282 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d\n",
5283 env->fcr0, env->fcr31,
5284 (env->CP0_Status & (1 << CP0St_FR)) != 0);
5285 fpu_fprintf(f, "FT0: "); printfpr(&env->ft0);
5286 fpu_fprintf(f, "FT1: "); printfpr(&env->ft1);
5287 fpu_fprintf(f, "FT2: "); printfpr(&env->ft2);
5288 for(i = 0; i < 32; i += 2) {
5289 fpu_fprintf(f, "%s: ", fregnames[i]);
5290 printfpr(FPR(env, i));
5296 void dump_fpu (CPUState *env)
5299 fprintf(logfile, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " %d\n",
5300 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
5301 fpu_dump_state(env, logfile, fprintf, 0);
5305 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
5306 /* Debug help: The architecture requires 32bit code to maintain proper
5307 sign-extened values on 64bit machines. */
5309 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
5311 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
5312 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5317 if (!SIGN_EXT_P(env->PC))
5318 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->PC);
5319 if (!SIGN_EXT_P(env->HI))
5320 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->HI);
5321 if (!SIGN_EXT_P(env->LO))
5322 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->LO);
5323 if (!SIGN_EXT_P(env->btarget))
5324 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
5326 for (i = 0; i < 32; i++) {
5327 if (!SIGN_EXT_P(env->gpr[i]))
5328 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->gpr[i]);
5331 if (!SIGN_EXT_P(env->CP0_EPC))
5332 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
5333 if (!SIGN_EXT_P(env->CP0_LLAddr))
5334 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
5338 void cpu_dump_state (CPUState *env, FILE *f,
5339 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5345 cpu_fprintf(f, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " %d\n",
5346 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
5347 for (i = 0; i < 32; i++) {
5349 cpu_fprintf(f, "GPR%02d:", i);
5350 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->gpr[i]);
5352 cpu_fprintf(f, "\n");
5355 c0_status = env->CP0_Status;
5357 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
5358 c0_status, env->CP0_Cause, env->CP0_EPC);
5359 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
5360 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
5361 if (c0_status & (1 << CP0St_CU1))
5362 fpu_dump_state(env, f, cpu_fprintf, flags);
5363 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
5364 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
5368 CPUMIPSState *cpu_mips_init (void)
5372 env = qemu_mallocz(sizeof(CPUMIPSState));
5380 void cpu_reset (CPUMIPSState *env)
5382 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
5387 #if !defined(CONFIG_USER_ONLY)
5388 if (env->hflags & MIPS_HFLAG_BMASK) {
5389 /* If the exception was raised from a delay slot,
5390 * come back to the jump. */
5391 env->CP0_ErrorEPC = env->PC - 4;
5392 env->hflags &= ~MIPS_HFLAG_BMASK;
5394 env->CP0_ErrorEPC = env->PC;
5397 env->PC = (int32_t)0xBFC00000;
5398 #if defined (MIPS_USES_R4K_TLB)
5399 env->CP0_Random = MIPS_TLB_NB - 1;
5400 env->tlb_in_use = MIPS_TLB_NB;
5403 /* SMP not implemented */
5404 env->CP0_EBase = 0x80000000;
5405 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
5406 env->CP0_WatchLo = 0;
5407 /* Count register increments in debug mode, EJTAG version 1 */
5408 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
5410 env->exception_index = EXCP_NONE;
5411 #if defined(CONFIG_USER_ONLY)
5412 env->hflags |= MIPS_HFLAG_UM;
5413 env->user_mode_only = 1;
5415 /* XXX some guesswork here, values are CPU specific */
5416 env->SYNCI_Step = 16;
5420 #include "translate_init.c"