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, /* also ROTRV */
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_FORK = 0x08 | OPC_SPECIAL3,
270 OPC_YIELD = 0x09 | OPC_SPECIAL3,
271 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
272 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
273 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
277 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
280 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
281 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
282 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
286 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
289 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
290 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
293 /* Coprocessor 0 (rs field) */
294 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
297 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
298 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
299 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
300 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
301 OPC_MFTR = (0x08 << 21) | OPC_CP0,
302 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
303 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
304 OPC_MTTR = (0x0C << 21) | OPC_CP0,
305 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
306 OPC_C0 = (0x10 << 21) | OPC_CP0,
307 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
308 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
312 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
315 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
316 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
317 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
318 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
319 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
320 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
323 /* Coprocessor 0 (with rs == C0) */
324 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
327 OPC_TLBR = 0x01 | OPC_C0,
328 OPC_TLBWI = 0x02 | OPC_C0,
329 OPC_TLBWR = 0x06 | OPC_C0,
330 OPC_TLBP = 0x08 | OPC_C0,
331 OPC_RFE = 0x10 | OPC_C0,
332 OPC_ERET = 0x18 | OPC_C0,
333 OPC_DERET = 0x1F | OPC_C0,
334 OPC_WAIT = 0x20 | OPC_C0,
337 /* Coprocessor 1 (rs field) */
338 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
341 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
342 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
343 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
344 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
345 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
346 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
347 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
348 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
349 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
350 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
351 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
352 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
353 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
354 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
355 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
356 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
357 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
358 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
361 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
362 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
365 OPC_BC1F = (0x00 << 16) | OPC_BC1,
366 OPC_BC1T = (0x01 << 16) | OPC_BC1,
367 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
368 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
372 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
373 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
377 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
378 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
381 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
384 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
385 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
386 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
387 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
388 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
389 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
390 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
391 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
392 OPC_BC2 = (0x08 << 21) | OPC_CP2,
395 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
398 OPC_LWXC1 = 0x00 | OPC_CP3,
399 OPC_LDXC1 = 0x01 | OPC_CP3,
400 OPC_LUXC1 = 0x05 | OPC_CP3,
401 OPC_SWXC1 = 0x08 | OPC_CP3,
402 OPC_SDXC1 = 0x09 | OPC_CP3,
403 OPC_SUXC1 = 0x0D | OPC_CP3,
404 OPC_PREFX = 0x0F | OPC_CP3,
405 OPC_ALNV_PS = 0x1E | OPC_CP3,
406 OPC_MADD_S = 0x20 | OPC_CP3,
407 OPC_MADD_D = 0x21 | OPC_CP3,
408 OPC_MADD_PS = 0x26 | OPC_CP3,
409 OPC_MSUB_S = 0x28 | OPC_CP3,
410 OPC_MSUB_D = 0x29 | OPC_CP3,
411 OPC_MSUB_PS = 0x2E | OPC_CP3,
412 OPC_NMADD_S = 0x30 | OPC_CP3,
413 OPC_NMADD_D = 0x31 | OPC_CP3,
414 OPC_NMADD_PS= 0x36 | OPC_CP3,
415 OPC_NMSUB_S = 0x38 | OPC_CP3,
416 OPC_NMSUB_D = 0x39 | OPC_CP3,
417 OPC_NMSUB_PS= 0x3E | OPC_CP3,
421 const unsigned char *regnames[] =
422 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
423 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
424 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
425 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
427 /* Warning: no function for r0 register (hard wired to zero) */
428 #define GEN32(func, NAME) \
429 static GenOpFunc *NAME ## _table [32] = { \
430 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
431 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
432 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
433 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
434 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
435 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
436 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
437 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
439 static inline void func(int n) \
441 NAME ## _table[n](); \
444 /* General purpose registers moves */
445 GEN32(gen_op_load_gpr_T0, gen_op_load_gpr_T0_gpr);
446 GEN32(gen_op_load_gpr_T1, gen_op_load_gpr_T1_gpr);
447 GEN32(gen_op_load_gpr_T2, gen_op_load_gpr_T2_gpr);
449 GEN32(gen_op_store_T0_gpr, gen_op_store_T0_gpr_gpr);
450 GEN32(gen_op_store_T1_gpr, gen_op_store_T1_gpr_gpr);
452 /* Moves to/from shadow registers */
453 GEN32(gen_op_load_srsgpr_T0, gen_op_load_srsgpr_T0_gpr);
454 GEN32(gen_op_store_T0_srsgpr, gen_op_store_T0_srsgpr_gpr);
456 static const char *fregnames[] =
457 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
458 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
459 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
460 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
462 #define FGEN32(func, NAME) \
463 static GenOpFunc *NAME ## _table [32] = { \
464 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
465 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
466 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
467 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
468 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
469 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
470 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
471 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
473 static inline void func(int n) \
475 NAME ## _table[n](); \
478 FGEN32(gen_op_load_fpr_WT0, gen_op_load_fpr_WT0_fpr);
479 FGEN32(gen_op_store_fpr_WT0, gen_op_store_fpr_WT0_fpr);
481 FGEN32(gen_op_load_fpr_WT1, gen_op_load_fpr_WT1_fpr);
482 FGEN32(gen_op_store_fpr_WT1, gen_op_store_fpr_WT1_fpr);
484 FGEN32(gen_op_load_fpr_WT2, gen_op_load_fpr_WT2_fpr);
485 FGEN32(gen_op_store_fpr_WT2, gen_op_store_fpr_WT2_fpr);
487 FGEN32(gen_op_load_fpr_DT0, gen_op_load_fpr_DT0_fpr);
488 FGEN32(gen_op_store_fpr_DT0, gen_op_store_fpr_DT0_fpr);
490 FGEN32(gen_op_load_fpr_DT1, gen_op_load_fpr_DT1_fpr);
491 FGEN32(gen_op_store_fpr_DT1, gen_op_store_fpr_DT1_fpr);
493 FGEN32(gen_op_load_fpr_DT2, gen_op_load_fpr_DT2_fpr);
494 FGEN32(gen_op_store_fpr_DT2, gen_op_store_fpr_DT2_fpr);
496 FGEN32(gen_op_load_fpr_WTH0, gen_op_load_fpr_WTH0_fpr);
497 FGEN32(gen_op_store_fpr_WTH0, gen_op_store_fpr_WTH0_fpr);
499 FGEN32(gen_op_load_fpr_WTH1, gen_op_load_fpr_WTH1_fpr);
500 FGEN32(gen_op_store_fpr_WTH1, gen_op_store_fpr_WTH1_fpr);
502 FGEN32(gen_op_load_fpr_WTH2, gen_op_load_fpr_WTH2_fpr);
503 FGEN32(gen_op_store_fpr_WTH2, gen_op_store_fpr_WTH2_fpr);
505 #define FOP_CONDS(type, fmt) \
506 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
507 gen_op_cmp ## type ## _ ## fmt ## _f, \
508 gen_op_cmp ## type ## _ ## fmt ## _un, \
509 gen_op_cmp ## type ## _ ## fmt ## _eq, \
510 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
511 gen_op_cmp ## type ## _ ## fmt ## _olt, \
512 gen_op_cmp ## type ## _ ## fmt ## _ult, \
513 gen_op_cmp ## type ## _ ## fmt ## _ole, \
514 gen_op_cmp ## type ## _ ## fmt ## _ule, \
515 gen_op_cmp ## type ## _ ## fmt ## _sf, \
516 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
517 gen_op_cmp ## type ## _ ## fmt ## _seq, \
518 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
519 gen_op_cmp ## type ## _ ## fmt ## _lt, \
520 gen_op_cmp ## type ## _ ## fmt ## _nge, \
521 gen_op_cmp ## type ## _ ## fmt ## _le, \
522 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
524 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
526 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
536 typedef struct DisasContext {
537 struct TranslationBlock *tb;
538 target_ulong pc, saved_pc;
541 /* Routine used to access memory */
543 uint32_t hflags, saved_hflags;
545 target_ulong btarget;
549 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
550 * exception condition
552 BS_STOP = 1, /* We want to stop translation for any reason */
553 BS_BRANCH = 2, /* We reached a branch condition */
554 BS_EXCP = 3, /* We reached an exception condition */
557 #ifdef MIPS_DEBUG_DISAS
558 #define MIPS_DEBUG(fmt, args...) \
560 if (loglevel & CPU_LOG_TB_IN_ASM) { \
561 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
562 ctx->pc, ctx->opcode , ##args); \
566 #define MIPS_DEBUG(fmt, args...) do { } while(0)
569 #define MIPS_INVAL(op) \
571 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
572 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
575 #define GEN_LOAD_REG_TN(Tn, Rn) \
578 glue(gen_op_reset_, Tn)(); \
580 glue(gen_op_load_gpr_, Tn)(Rn); \
584 #define GEN_LOAD_SRSREG_TN(Tn, Rn) \
587 glue(gen_op_reset_, Tn)(); \
589 glue(gen_op_load_srsgpr_, Tn)(Rn); \
593 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
594 #define GEN_LOAD_IMM_TN(Tn, Imm) \
597 glue(gen_op_reset_, Tn)(); \
598 } else if ((int32_t)Imm == Imm) { \
599 glue(gen_op_set_, Tn)(Imm); \
601 glue(gen_op_set64_, Tn)(((uint64_t)Imm) >> 32, (uint32_t)Imm); \
605 #define GEN_LOAD_IMM_TN(Tn, Imm) \
608 glue(gen_op_reset_, Tn)(); \
610 glue(gen_op_set_, Tn)(Imm); \
615 #define GEN_STORE_TN_REG(Rn, Tn) \
618 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
622 #define GEN_STORE_TN_SRSREG(Rn, Tn) \
625 glue(glue(gen_op_store_, Tn),_srsgpr)(Rn); \
629 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
631 glue(gen_op_load_fpr_, FTn)(Fn); \
634 #define GEN_STORE_FTN_FREG(Fn, FTn) \
636 glue(gen_op_store_fpr_, FTn)(Fn); \
639 static inline void gen_save_pc(target_ulong pc)
641 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
642 if (pc == (int32_t)pc) {
645 gen_op_save_pc64(pc >> 32, (uint32_t)pc);
652 static inline void gen_save_btarget(target_ulong btarget)
654 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
655 if (btarget == (int32_t)btarget) {
656 gen_op_save_btarget(btarget);
658 gen_op_save_btarget64(btarget >> 32, (uint32_t)btarget);
661 gen_op_save_btarget(btarget);
665 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
667 #if defined MIPS_DEBUG_DISAS
668 if (loglevel & CPU_LOG_TB_IN_ASM) {
669 fprintf(logfile, "hflags %08x saved %08x\n",
670 ctx->hflags, ctx->saved_hflags);
673 if (do_save_pc && ctx->pc != ctx->saved_pc) {
674 gen_save_pc(ctx->pc);
675 ctx->saved_pc = ctx->pc;
677 if (ctx->hflags != ctx->saved_hflags) {
678 gen_op_save_state(ctx->hflags);
679 ctx->saved_hflags = ctx->hflags;
680 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
682 gen_op_save_breg_target();
688 /* bcond was already saved by the BL insn */
691 gen_save_btarget(ctx->btarget);
697 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
699 ctx->saved_hflags = ctx->hflags;
700 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
702 gen_op_restore_breg_target();
705 ctx->btarget = env->btarget;
709 ctx->btarget = env->btarget;
710 gen_op_restore_bcond();
715 static inline void generate_exception_err (DisasContext *ctx, int excp, int err)
717 #if defined MIPS_DEBUG_DISAS
718 if (loglevel & CPU_LOG_TB_IN_ASM)
719 fprintf(logfile, "%s: raise exception %d\n", __func__, excp);
721 save_cpu_state(ctx, 1);
723 gen_op_raise_exception(excp);
725 gen_op_raise_exception_err(excp, err);
726 ctx->bstate = BS_EXCP;
729 static inline void generate_exception (DisasContext *ctx, int excp)
731 generate_exception_err (ctx, excp, 0);
734 static inline void check_cp0_enabled(DisasContext *ctx)
736 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
737 generate_exception_err(ctx, EXCP_CpU, 1);
740 static inline void check_cp1_enabled(DisasContext *ctx)
742 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
743 generate_exception_err(ctx, EXCP_CpU, 1);
746 static inline void check_cp1_64bitmode(DisasContext *ctx)
748 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64)))
749 generate_exception(ctx, EXCP_RI);
753 * Verify if floating point register is valid; an operation is not defined
754 * if bit 0 of any register specification is set and the FR bit in the
755 * Status register equals zero, since the register numbers specify an
756 * even-odd pair of adjacent coprocessor general registers. When the FR bit
757 * in the Status register equals one, both even and odd register numbers
758 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
760 * Multiple 64 bit wide registers can be checked by calling
761 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
763 void check_cp1_registers(DisasContext *ctx, int regs)
765 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
766 generate_exception(ctx, EXCP_RI);
769 /* This code generates a "reserved instruction" exception if the
770 CPU does not support the instruction set corresponding to flags. */
771 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
773 if (unlikely(!(env->insn_flags & flags)))
774 generate_exception(ctx, EXCP_RI);
777 /* This code generates a "reserved instruction" exception if the
778 CPU is not MIPS MT capable. */
779 static inline void check_mips_mt(CPUState *env, DisasContext *ctx)
781 if (unlikely(!(env->CP0_Config3 & (1 << CP0C3_MT))))
782 generate_exception(ctx, EXCP_RI);
785 /* This code generates a "reserved instruction" exception if 64-bit
786 instructions are not enabled. */
787 static inline void check_mips_64(DisasContext *ctx)
789 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
790 generate_exception(ctx, EXCP_RI);
793 #if defined(CONFIG_USER_ONLY)
794 #define op_ldst(name) gen_op_##name##_raw()
795 #define OP_LD_TABLE(width)
796 #define OP_ST_TABLE(width)
798 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
799 #define OP_LD_TABLE(width) \
800 static GenOpFunc *gen_op_l##width[] = { \
801 &gen_op_l##width##_user, \
802 &gen_op_l##width##_kernel, \
804 #define OP_ST_TABLE(width) \
805 static GenOpFunc *gen_op_s##width[] = { \
806 &gen_op_s##width##_user, \
807 &gen_op_s##width##_kernel, \
811 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
844 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
845 int base, int16_t offset)
847 const char *opn = "ldst";
850 GEN_LOAD_IMM_TN(T0, offset);
851 } else if (offset == 0) {
852 gen_op_load_gpr_T0(base);
854 gen_op_load_gpr_T0(base);
855 gen_op_set_T1(offset);
858 /* Don't do NOP if destination is zero: we must perform the actual
861 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
864 GEN_STORE_TN_REG(rt, T0);
869 GEN_STORE_TN_REG(rt, T0);
874 GEN_STORE_TN_REG(rt, T0);
878 GEN_LOAD_REG_TN(T1, rt);
883 save_cpu_state(ctx, 1);
884 GEN_LOAD_REG_TN(T1, rt);
886 GEN_STORE_TN_REG(rt, T0);
890 GEN_LOAD_REG_TN(T1, rt);
892 GEN_STORE_TN_REG(rt, T1);
896 GEN_LOAD_REG_TN(T1, rt);
901 GEN_LOAD_REG_TN(T1, rt);
903 GEN_STORE_TN_REG(rt, T1);
907 GEN_LOAD_REG_TN(T1, rt);
914 GEN_STORE_TN_REG(rt, T0);
918 GEN_LOAD_REG_TN(T1, rt);
924 GEN_STORE_TN_REG(rt, T0);
928 GEN_LOAD_REG_TN(T1, rt);
934 GEN_STORE_TN_REG(rt, T0);
939 GEN_STORE_TN_REG(rt, T0);
943 GEN_LOAD_REG_TN(T1, rt);
949 GEN_STORE_TN_REG(rt, T0);
953 GEN_LOAD_REG_TN(T1, rt);
955 GEN_STORE_TN_REG(rt, T1);
959 GEN_LOAD_REG_TN(T1, rt);
964 GEN_LOAD_REG_TN(T1, rt);
966 GEN_STORE_TN_REG(rt, T1);
970 GEN_LOAD_REG_TN(T1, rt);
976 GEN_STORE_TN_REG(rt, T0);
980 save_cpu_state(ctx, 1);
981 GEN_LOAD_REG_TN(T1, rt);
983 GEN_STORE_TN_REG(rt, T0);
988 generate_exception(ctx, EXCP_RI);
991 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
995 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
996 int base, int16_t offset)
998 const char *opn = "flt_ldst";
1001 GEN_LOAD_IMM_TN(T0, offset);
1002 } else if (offset == 0) {
1003 gen_op_load_gpr_T0(base);
1005 gen_op_load_gpr_T0(base);
1006 gen_op_set_T1(offset);
1009 /* Don't do NOP if destination is zero: we must perform the actual
1014 GEN_STORE_FTN_FREG(ft, WT0);
1018 GEN_LOAD_FREG_FTN(WT0, ft);
1024 GEN_STORE_FTN_FREG(ft, DT0);
1028 GEN_LOAD_FREG_FTN(DT0, ft);
1034 generate_exception(ctx, EXCP_RI);
1037 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1040 /* Arithmetic with immediate operand */
1041 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1042 int rt, int rs, int16_t imm)
1045 const char *opn = "imm arith";
1047 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1048 /* If no destination, treat it as a NOP.
1049 For addi, we must generate the overflow exception when needed. */
1053 uimm = (uint16_t)imm;
1057 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1063 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1068 GEN_LOAD_REG_TN(T0, rs);
1069 GEN_LOAD_IMM_TN(T1, uimm);
1072 GEN_LOAD_IMM_TN(T0, imm << 16);
1077 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1086 GEN_LOAD_REG_TN(T0, rs);
1087 GEN_LOAD_IMM_TN(T1, uimm);
1092 save_cpu_state(ctx, 1);
1100 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1102 save_cpu_state(ctx, 1);
1143 switch ((ctx->opcode >> 21) & 0x1f) {
1149 /* rotr is decoded as srl on non-R2 CPUs */
1150 if (env->insn_flags & ISA_MIPS32R2) {
1159 MIPS_INVAL("invalid srl flag");
1160 generate_exception(ctx, EXCP_RI);
1164 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1174 switch ((ctx->opcode >> 21) & 0x1f) {
1180 /* drotr is decoded as dsrl on non-R2 CPUs */
1181 if (env->insn_flags & ISA_MIPS32R2) {
1190 MIPS_INVAL("invalid dsrl flag");
1191 generate_exception(ctx, EXCP_RI);
1204 switch ((ctx->opcode >> 21) & 0x1f) {
1210 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1211 if (env->insn_flags & ISA_MIPS32R2) {
1220 MIPS_INVAL("invalid dsrl32 flag");
1221 generate_exception(ctx, EXCP_RI);
1228 generate_exception(ctx, EXCP_RI);
1231 GEN_STORE_TN_REG(rt, T0);
1232 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1236 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1237 int rd, int rs, int rt)
1239 const char *opn = "arith";
1241 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1242 && opc != OPC_DADD && opc != OPC_DSUB) {
1243 /* If no destination, treat it as a NOP.
1244 For add & sub, we must generate the overflow exception when needed. */
1248 GEN_LOAD_REG_TN(T0, rs);
1249 GEN_LOAD_REG_TN(T1, rt);
1252 save_cpu_state(ctx, 1);
1261 save_cpu_state(ctx, 1);
1269 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1271 save_cpu_state(ctx, 1);
1280 save_cpu_state(ctx, 1);
1334 switch ((ctx->opcode >> 6) & 0x1f) {
1340 /* rotrv is decoded as srlv on non-R2 CPUs */
1341 if (env->insn_flags & ISA_MIPS32R2) {
1350 MIPS_INVAL("invalid srlv flag");
1351 generate_exception(ctx, EXCP_RI);
1355 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1365 switch ((ctx->opcode >> 6) & 0x1f) {
1371 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1372 if (env->insn_flags & ISA_MIPS32R2) {
1381 MIPS_INVAL("invalid dsrlv flag");
1382 generate_exception(ctx, EXCP_RI);
1389 generate_exception(ctx, EXCP_RI);
1392 GEN_STORE_TN_REG(rd, T0);
1394 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1397 /* Arithmetic on HI/LO registers */
1398 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1400 const char *opn = "hilo";
1402 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1410 GEN_STORE_TN_REG(reg, T0);
1415 GEN_STORE_TN_REG(reg, T0);
1419 GEN_LOAD_REG_TN(T0, reg);
1424 GEN_LOAD_REG_TN(T0, reg);
1430 generate_exception(ctx, EXCP_RI);
1433 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1436 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1439 const char *opn = "mul/div";
1441 GEN_LOAD_REG_TN(T0, rs);
1442 GEN_LOAD_REG_TN(T1, rt);
1460 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1496 generate_exception(ctx, EXCP_RI);
1499 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
1502 static void gen_cl (DisasContext *ctx, uint32_t opc,
1505 const char *opn = "CLx";
1511 GEN_LOAD_REG_TN(T0, rs);
1521 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1533 generate_exception(ctx, EXCP_RI);
1536 gen_op_store_T0_gpr(rd);
1537 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
1541 static void gen_trap (DisasContext *ctx, uint32_t opc,
1542 int rs, int rt, int16_t imm)
1547 /* Load needed operands */
1555 /* Compare two registers */
1557 GEN_LOAD_REG_TN(T0, rs);
1558 GEN_LOAD_REG_TN(T1, rt);
1568 /* Compare register to immediate */
1569 if (rs != 0 || imm != 0) {
1570 GEN_LOAD_REG_TN(T0, rs);
1571 GEN_LOAD_IMM_TN(T1, (int32_t)imm);
1578 case OPC_TEQ: /* rs == rs */
1579 case OPC_TEQI: /* r0 == 0 */
1580 case OPC_TGE: /* rs >= rs */
1581 case OPC_TGEI: /* r0 >= 0 */
1582 case OPC_TGEU: /* rs >= rs unsigned */
1583 case OPC_TGEIU: /* r0 >= 0 unsigned */
1587 case OPC_TLT: /* rs < rs */
1588 case OPC_TLTI: /* r0 < 0 */
1589 case OPC_TLTU: /* rs < rs unsigned */
1590 case OPC_TLTIU: /* r0 < 0 unsigned */
1591 case OPC_TNE: /* rs != rs */
1592 case OPC_TNEI: /* r0 != 0 */
1593 /* Never trap: treat as NOP. */
1597 generate_exception(ctx, EXCP_RI);
1628 generate_exception(ctx, EXCP_RI);
1632 save_cpu_state(ctx, 1);
1634 ctx->bstate = BS_STOP;
1637 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
1639 TranslationBlock *tb;
1641 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
1643 gen_op_goto_tb0(TBPARAM(tb));
1645 gen_op_goto_tb1(TBPARAM(tb));
1647 gen_op_set_T0((long)tb + n);
1655 /* Branches (before delay slot) */
1656 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
1657 int rs, int rt, int32_t offset)
1659 target_ulong btarget = -1;
1663 if (ctx->hflags & MIPS_HFLAG_BMASK) {
1664 #ifdef MIPS_DEBUG_DISAS
1665 if (loglevel & CPU_LOG_TB_IN_ASM) {
1667 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
1671 generate_exception(ctx, EXCP_RI);
1675 /* Load needed operands */
1681 /* Compare two registers */
1683 GEN_LOAD_REG_TN(T0, rs);
1684 GEN_LOAD_REG_TN(T1, rt);
1687 btarget = ctx->pc + 4 + offset;
1701 /* Compare to zero */
1703 gen_op_load_gpr_T0(rs);
1706 btarget = ctx->pc + 4 + offset;
1710 /* Jump to immediate */
1711 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
1715 /* Jump to register */
1716 if (offset != 0 && offset != 16) {
1717 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1718 others are reserved. */
1719 MIPS_INVAL("jump hint");
1720 generate_exception(ctx, EXCP_RI);
1723 GEN_LOAD_REG_TN(T2, rs);
1726 MIPS_INVAL("branch/jump");
1727 generate_exception(ctx, EXCP_RI);
1731 /* No condition to be computed */
1733 case OPC_BEQ: /* rx == rx */
1734 case OPC_BEQL: /* rx == rx likely */
1735 case OPC_BGEZ: /* 0 >= 0 */
1736 case OPC_BGEZL: /* 0 >= 0 likely */
1737 case OPC_BLEZ: /* 0 <= 0 */
1738 case OPC_BLEZL: /* 0 <= 0 likely */
1740 ctx->hflags |= MIPS_HFLAG_B;
1741 MIPS_DEBUG("balways");
1743 case OPC_BGEZAL: /* 0 >= 0 */
1744 case OPC_BGEZALL: /* 0 >= 0 likely */
1745 /* Always take and link */
1747 ctx->hflags |= MIPS_HFLAG_B;
1748 MIPS_DEBUG("balways and link");
1750 case OPC_BNE: /* rx != rx */
1751 case OPC_BGTZ: /* 0 > 0 */
1752 case OPC_BLTZ: /* 0 < 0 */
1754 MIPS_DEBUG("bnever (NOP)");
1756 case OPC_BLTZAL: /* 0 < 0 */
1757 GEN_LOAD_IMM_TN(T0, ctx->pc + 8);
1758 gen_op_store_T0_gpr(31);
1759 MIPS_DEBUG("bnever and link");
1761 case OPC_BLTZALL: /* 0 < 0 likely */
1762 GEN_LOAD_IMM_TN(T0, ctx->pc + 8);
1763 gen_op_store_T0_gpr(31);
1764 /* Skip the instruction in the delay slot */
1765 MIPS_DEBUG("bnever, link and skip");
1768 case OPC_BNEL: /* rx != rx likely */
1769 case OPC_BGTZL: /* 0 > 0 likely */
1770 case OPC_BLTZL: /* 0 < 0 likely */
1771 /* Skip the instruction in the delay slot */
1772 MIPS_DEBUG("bnever and skip");
1776 ctx->hflags |= MIPS_HFLAG_B;
1777 MIPS_DEBUG("j " TARGET_FMT_lx, btarget);
1781 ctx->hflags |= MIPS_HFLAG_B;
1782 MIPS_DEBUG("jal " TARGET_FMT_lx, btarget);
1785 ctx->hflags |= MIPS_HFLAG_BR;
1786 MIPS_DEBUG("jr %s", regnames[rs]);
1790 ctx->hflags |= MIPS_HFLAG_BR;
1791 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
1794 MIPS_INVAL("branch/jump");
1795 generate_exception(ctx, EXCP_RI);
1802 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
1803 regnames[rs], regnames[rt], btarget);
1807 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
1808 regnames[rs], regnames[rt], btarget);
1812 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
1813 regnames[rs], regnames[rt], btarget);
1817 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
1818 regnames[rs], regnames[rt], btarget);
1822 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btarget);
1826 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1830 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btarget);
1836 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btarget);
1840 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btarget);
1844 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1848 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btarget);
1852 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1856 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btarget);
1860 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1865 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btarget);
1867 ctx->hflags |= MIPS_HFLAG_BC;
1873 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btarget);
1875 ctx->hflags |= MIPS_HFLAG_BL;
1877 gen_op_save_bcond();
1880 MIPS_INVAL("conditional branch/jump");
1881 generate_exception(ctx, EXCP_RI);
1885 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
1886 blink, ctx->hflags, btarget);
1888 ctx->btarget = btarget;
1890 GEN_LOAD_IMM_TN(T0, ctx->pc + 8);
1891 gen_op_store_T0_gpr(blink);
1895 /* special3 bitfield operations */
1896 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
1897 int rs, int lsb, int msb)
1899 GEN_LOAD_REG_TN(T1, rs);
1904 gen_op_ext(lsb, msb + 1);
1909 gen_op_ext(lsb, msb + 1 + 32);
1914 gen_op_ext(lsb + 32, msb + 1);
1917 gen_op_ext(lsb, msb + 1);
1922 GEN_LOAD_REG_TN(T0, rt);
1923 gen_op_ins(lsb, msb - lsb + 1);
1928 GEN_LOAD_REG_TN(T0, rt);
1929 gen_op_ins(lsb, msb - lsb + 1 + 32);
1934 GEN_LOAD_REG_TN(T0, rt);
1935 gen_op_ins(lsb + 32, msb - lsb + 1);
1940 GEN_LOAD_REG_TN(T0, rt);
1941 gen_op_ins(lsb, msb - lsb + 1);
1945 MIPS_INVAL("bitops");
1946 generate_exception(ctx, EXCP_RI);
1949 GEN_STORE_TN_REG(rt, T0);
1952 /* CP0 (MMU and control) */
1953 static void gen_mfc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
1955 const char *rn = "invalid";
1958 check_insn(env, ctx, ISA_MIPS32);
1964 gen_op_mfc0_index();
1968 check_mips_mt(env, ctx);
1969 gen_op_mfc0_mvpcontrol();
1973 check_mips_mt(env, ctx);
1974 gen_op_mfc0_mvpconf0();
1978 check_mips_mt(env, ctx);
1979 gen_op_mfc0_mvpconf1();
1989 gen_op_mfc0_random();
1993 check_mips_mt(env, ctx);
1994 gen_op_mfc0_vpecontrol();
1998 check_mips_mt(env, ctx);
1999 gen_op_mfc0_vpeconf0();
2003 check_mips_mt(env, ctx);
2004 gen_op_mfc0_vpeconf1();
2008 check_mips_mt(env, ctx);
2009 gen_op_mfc0_yqmask();
2013 check_mips_mt(env, ctx);
2014 gen_op_mfc0_vpeschedule();
2018 check_mips_mt(env, ctx);
2019 gen_op_mfc0_vpeschefback();
2020 rn = "VPEScheFBack";
2023 check_mips_mt(env, ctx);
2024 gen_op_mfc0_vpeopt();
2034 gen_op_mfc0_entrylo0();
2038 check_mips_mt(env, ctx);
2039 gen_op_mfc0_tcstatus();
2043 check_mips_mt(env, ctx);
2044 gen_op_mfc0_tcbind();
2048 check_mips_mt(env, ctx);
2049 gen_op_mfc0_tcrestart();
2053 check_mips_mt(env, ctx);
2054 gen_op_mfc0_tchalt();
2058 check_mips_mt(env, ctx);
2059 gen_op_mfc0_tccontext();
2063 check_mips_mt(env, ctx);
2064 gen_op_mfc0_tcschedule();
2068 check_mips_mt(env, ctx);
2069 gen_op_mfc0_tcschefback();
2079 gen_op_mfc0_entrylo1();
2089 gen_op_mfc0_context();
2093 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2094 rn = "ContextConfig";
2103 gen_op_mfc0_pagemask();
2107 check_insn(env, ctx, ISA_MIPS32R2);
2108 gen_op_mfc0_pagegrain();
2118 gen_op_mfc0_wired();
2122 check_insn(env, ctx, ISA_MIPS32R2);
2123 gen_op_mfc0_srsconf0();
2127 check_insn(env, ctx, ISA_MIPS32R2);
2128 gen_op_mfc0_srsconf1();
2132 check_insn(env, ctx, ISA_MIPS32R2);
2133 gen_op_mfc0_srsconf2();
2137 check_insn(env, ctx, ISA_MIPS32R2);
2138 gen_op_mfc0_srsconf3();
2142 check_insn(env, ctx, ISA_MIPS32R2);
2143 gen_op_mfc0_srsconf4();
2153 check_insn(env, ctx, ISA_MIPS32R2);
2154 gen_op_mfc0_hwrena();
2164 gen_op_mfc0_badvaddr();
2174 gen_op_mfc0_count();
2177 /* 6,7 are implementation dependent */
2185 gen_op_mfc0_entryhi();
2195 gen_op_mfc0_compare();
2198 /* 6,7 are implementation dependent */
2206 gen_op_mfc0_status();
2210 check_insn(env, ctx, ISA_MIPS32R2);
2211 gen_op_mfc0_intctl();
2215 check_insn(env, ctx, ISA_MIPS32R2);
2216 gen_op_mfc0_srsctl();
2220 check_insn(env, ctx, ISA_MIPS32R2);
2221 gen_op_mfc0_srsmap();
2231 gen_op_mfc0_cause();
2255 check_insn(env, ctx, ISA_MIPS32R2);
2256 gen_op_mfc0_ebase();
2266 gen_op_mfc0_config0();
2270 gen_op_mfc0_config1();
2274 gen_op_mfc0_config2();
2278 gen_op_mfc0_config3();
2281 /* 4,5 are reserved */
2282 /* 6,7 are implementation dependent */
2284 gen_op_mfc0_config6();
2288 gen_op_mfc0_config7();
2298 gen_op_mfc0_lladdr();
2308 gen_op_mfc0_watchlo(sel);
2318 gen_op_mfc0_watchhi(sel);
2328 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
2329 check_insn(env, ctx, ISA_MIPS3);
2330 gen_op_mfc0_xcontext();
2339 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2342 gen_op_mfc0_framemask();
2351 rn = "'Diagnostic"; /* implementation dependent */
2356 gen_op_mfc0_debug(); /* EJTAG support */
2360 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2361 rn = "TraceControl";
2364 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2365 rn = "TraceControl2";
2368 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2369 rn = "UserTraceData";
2372 // gen_op_mfc0_debug(); /* PDtrace support */
2382 gen_op_mfc0_depc(); /* EJTAG support */
2392 gen_op_mfc0_performance0();
2393 rn = "Performance0";
2396 // gen_op_mfc0_performance1();
2397 rn = "Performance1";
2400 // gen_op_mfc0_performance2();
2401 rn = "Performance2";
2404 // gen_op_mfc0_performance3();
2405 rn = "Performance3";
2408 // gen_op_mfc0_performance4();
2409 rn = "Performance4";
2412 // gen_op_mfc0_performance5();
2413 rn = "Performance5";
2416 // gen_op_mfc0_performance6();
2417 rn = "Performance6";
2420 // gen_op_mfc0_performance7();
2421 rn = "Performance7";
2446 gen_op_mfc0_taglo();
2453 gen_op_mfc0_datalo();
2466 gen_op_mfc0_taghi();
2473 gen_op_mfc0_datahi();
2483 gen_op_mfc0_errorepc();
2493 gen_op_mfc0_desave(); /* EJTAG support */
2503 #if defined MIPS_DEBUG_DISAS
2504 if (loglevel & CPU_LOG_TB_IN_ASM) {
2505 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2512 #if defined MIPS_DEBUG_DISAS
2513 if (loglevel & CPU_LOG_TB_IN_ASM) {
2514 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2518 generate_exception(ctx, EXCP_RI);
2521 static void gen_mtc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
2523 const char *rn = "invalid";
2526 check_insn(env, ctx, ISA_MIPS32);
2532 gen_op_mtc0_index();
2536 check_mips_mt(env, ctx);
2537 gen_op_mtc0_mvpcontrol();
2541 check_mips_mt(env, ctx);
2546 check_mips_mt(env, ctx);
2561 check_mips_mt(env, ctx);
2562 gen_op_mtc0_vpecontrol();
2566 check_mips_mt(env, ctx);
2567 gen_op_mtc0_vpeconf0();
2571 check_mips_mt(env, ctx);
2572 gen_op_mtc0_vpeconf1();
2576 check_mips_mt(env, ctx);
2577 gen_op_mtc0_yqmask();
2581 check_mips_mt(env, ctx);
2582 gen_op_mtc0_vpeschedule();
2586 check_mips_mt(env, ctx);
2587 gen_op_mtc0_vpeschefback();
2588 rn = "VPEScheFBack";
2591 check_mips_mt(env, ctx);
2592 gen_op_mtc0_vpeopt();
2602 gen_op_mtc0_entrylo0();
2606 check_mips_mt(env, ctx);
2607 gen_op_mtc0_tcstatus();
2611 check_mips_mt(env, ctx);
2612 gen_op_mtc0_tcbind();
2616 check_mips_mt(env, ctx);
2617 gen_op_mtc0_tcrestart();
2621 check_mips_mt(env, ctx);
2622 gen_op_mtc0_tchalt();
2626 check_mips_mt(env, ctx);
2627 gen_op_mtc0_tccontext();
2631 check_mips_mt(env, ctx);
2632 gen_op_mtc0_tcschedule();
2636 check_mips_mt(env, ctx);
2637 gen_op_mtc0_tcschefback();
2647 gen_op_mtc0_entrylo1();
2657 gen_op_mtc0_context();
2661 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2662 rn = "ContextConfig";
2671 gen_op_mtc0_pagemask();
2675 check_insn(env, ctx, ISA_MIPS32R2);
2676 gen_op_mtc0_pagegrain();
2686 gen_op_mtc0_wired();
2690 check_insn(env, ctx, ISA_MIPS32R2);
2691 gen_op_mtc0_srsconf0();
2695 check_insn(env, ctx, ISA_MIPS32R2);
2696 gen_op_mtc0_srsconf1();
2700 check_insn(env, ctx, ISA_MIPS32R2);
2701 gen_op_mtc0_srsconf2();
2705 check_insn(env, ctx, ISA_MIPS32R2);
2706 gen_op_mtc0_srsconf3();
2710 check_insn(env, ctx, ISA_MIPS32R2);
2711 gen_op_mtc0_srsconf4();
2721 check_insn(env, ctx, ISA_MIPS32R2);
2722 gen_op_mtc0_hwrena();
2736 gen_op_mtc0_count();
2739 /* 6,7 are implementation dependent */
2743 /* Stop translation as we may have switched the execution mode */
2744 ctx->bstate = BS_STOP;
2749 gen_op_mtc0_entryhi();
2759 gen_op_mtc0_compare();
2762 /* 6,7 are implementation dependent */
2766 /* Stop translation as we may have switched the execution mode */
2767 ctx->bstate = BS_STOP;
2772 gen_op_mtc0_status();
2773 /* BS_STOP isn't good enough here, hflags may have changed. */
2774 gen_save_pc(ctx->pc + 4);
2775 ctx->bstate = BS_EXCP;
2779 check_insn(env, ctx, ISA_MIPS32R2);
2780 gen_op_mtc0_intctl();
2781 /* Stop translation as we may have switched the execution mode */
2782 ctx->bstate = BS_STOP;
2786 check_insn(env, ctx, ISA_MIPS32R2);
2787 gen_op_mtc0_srsctl();
2788 /* Stop translation as we may have switched the execution mode */
2789 ctx->bstate = BS_STOP;
2793 check_insn(env, ctx, ISA_MIPS32R2);
2794 gen_op_mtc0_srsmap();
2795 /* Stop translation as we may have switched the execution mode */
2796 ctx->bstate = BS_STOP;
2806 gen_op_mtc0_cause();
2812 /* Stop translation as we may have switched the execution mode */
2813 ctx->bstate = BS_STOP;
2832 check_insn(env, ctx, ISA_MIPS32R2);
2833 gen_op_mtc0_ebase();
2843 gen_op_mtc0_config0();
2845 /* Stop translation as we may have switched the execution mode */
2846 ctx->bstate = BS_STOP;
2849 /* ignored, read only */
2853 gen_op_mtc0_config2();
2855 /* Stop translation as we may have switched the execution mode */
2856 ctx->bstate = BS_STOP;
2859 /* ignored, read only */
2862 /* 4,5 are reserved */
2863 /* 6,7 are implementation dependent */
2873 rn = "Invalid config selector";
2890 gen_op_mtc0_watchlo(sel);
2900 gen_op_mtc0_watchhi(sel);
2910 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
2911 check_insn(env, ctx, ISA_MIPS3);
2912 gen_op_mtc0_xcontext();
2921 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2924 gen_op_mtc0_framemask();
2933 rn = "Diagnostic"; /* implementation dependent */
2938 gen_op_mtc0_debug(); /* EJTAG support */
2939 /* BS_STOP isn't good enough here, hflags may have changed. */
2940 gen_save_pc(ctx->pc + 4);
2941 ctx->bstate = BS_EXCP;
2945 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2946 rn = "TraceControl";
2947 /* Stop translation as we may have switched the execution mode */
2948 ctx->bstate = BS_STOP;
2951 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2952 rn = "TraceControl2";
2953 /* Stop translation as we may have switched the execution mode */
2954 ctx->bstate = BS_STOP;
2957 /* Stop translation as we may have switched the execution mode */
2958 ctx->bstate = BS_STOP;
2959 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2960 rn = "UserTraceData";
2961 /* Stop translation as we may have switched the execution mode */
2962 ctx->bstate = BS_STOP;
2965 // gen_op_mtc0_debug(); /* PDtrace support */
2966 /* Stop translation as we may have switched the execution mode */
2967 ctx->bstate = BS_STOP;
2977 gen_op_mtc0_depc(); /* EJTAG support */
2987 gen_op_mtc0_performance0();
2988 rn = "Performance0";
2991 // gen_op_mtc0_performance1();
2992 rn = "Performance1";
2995 // gen_op_mtc0_performance2();
2996 rn = "Performance2";
2999 // gen_op_mtc0_performance3();
3000 rn = "Performance3";
3003 // gen_op_mtc0_performance4();
3004 rn = "Performance4";
3007 // gen_op_mtc0_performance5();
3008 rn = "Performance5";
3011 // gen_op_mtc0_performance6();
3012 rn = "Performance6";
3015 // gen_op_mtc0_performance7();
3016 rn = "Performance7";
3042 gen_op_mtc0_taglo();
3049 gen_op_mtc0_datalo();
3062 gen_op_mtc0_taghi();
3069 gen_op_mtc0_datahi();
3080 gen_op_mtc0_errorepc();
3090 gen_op_mtc0_desave(); /* EJTAG support */
3096 /* Stop translation as we may have switched the execution mode */
3097 ctx->bstate = BS_STOP;
3102 #if defined MIPS_DEBUG_DISAS
3103 if (loglevel & CPU_LOG_TB_IN_ASM) {
3104 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3111 #if defined MIPS_DEBUG_DISAS
3112 if (loglevel & CPU_LOG_TB_IN_ASM) {
3113 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3117 generate_exception(ctx, EXCP_RI);
3120 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
3121 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
3123 const char *rn = "invalid";
3126 check_insn(env, ctx, ISA_MIPS64);
3132 gen_op_mfc0_index();
3136 check_mips_mt(env, ctx);
3137 gen_op_mfc0_mvpcontrol();
3141 check_mips_mt(env, ctx);
3142 gen_op_mfc0_mvpconf0();
3146 check_mips_mt(env, ctx);
3147 gen_op_mfc0_mvpconf1();
3157 gen_op_mfc0_random();
3161 check_mips_mt(env, ctx);
3162 gen_op_mfc0_vpecontrol();
3166 check_mips_mt(env, ctx);
3167 gen_op_mfc0_vpeconf0();
3171 check_mips_mt(env, ctx);
3172 gen_op_mfc0_vpeconf1();
3176 check_mips_mt(env, ctx);
3177 gen_op_dmfc0_yqmask();
3181 check_mips_mt(env, ctx);
3182 gen_op_dmfc0_vpeschedule();
3186 check_mips_mt(env, ctx);
3187 gen_op_dmfc0_vpeschefback();
3188 rn = "VPEScheFBack";
3191 check_mips_mt(env, ctx);
3192 gen_op_mfc0_vpeopt();
3202 gen_op_dmfc0_entrylo0();
3206 check_mips_mt(env, ctx);
3207 gen_op_mfc0_tcstatus();
3211 check_mips_mt(env, ctx);
3212 gen_op_mfc0_tcbind();
3216 check_mips_mt(env, ctx);
3217 gen_op_dmfc0_tcrestart();
3221 check_mips_mt(env, ctx);
3222 gen_op_dmfc0_tchalt();
3226 check_mips_mt(env, ctx);
3227 gen_op_dmfc0_tccontext();
3231 check_mips_mt(env, ctx);
3232 gen_op_dmfc0_tcschedule();
3236 check_mips_mt(env, ctx);
3237 gen_op_dmfc0_tcschefback();
3247 gen_op_dmfc0_entrylo1();
3257 gen_op_dmfc0_context();
3261 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3262 rn = "ContextConfig";
3271 gen_op_mfc0_pagemask();
3275 check_insn(env, ctx, ISA_MIPS32R2);
3276 gen_op_mfc0_pagegrain();
3286 gen_op_mfc0_wired();
3290 check_insn(env, ctx, ISA_MIPS32R2);
3291 gen_op_mfc0_srsconf0();
3295 check_insn(env, ctx, ISA_MIPS32R2);
3296 gen_op_mfc0_srsconf1();
3300 check_insn(env, ctx, ISA_MIPS32R2);
3301 gen_op_mfc0_srsconf2();
3305 check_insn(env, ctx, ISA_MIPS32R2);
3306 gen_op_mfc0_srsconf3();
3310 check_insn(env, ctx, ISA_MIPS32R2);
3311 gen_op_mfc0_srsconf4();
3321 check_insn(env, ctx, ISA_MIPS32R2);
3322 gen_op_mfc0_hwrena();
3332 gen_op_dmfc0_badvaddr();
3342 gen_op_mfc0_count();
3345 /* 6,7 are implementation dependent */
3353 gen_op_dmfc0_entryhi();
3363 gen_op_mfc0_compare();
3366 /* 6,7 are implementation dependent */
3374 gen_op_mfc0_status();
3378 check_insn(env, ctx, ISA_MIPS32R2);
3379 gen_op_mfc0_intctl();
3383 check_insn(env, ctx, ISA_MIPS32R2);
3384 gen_op_mfc0_srsctl();
3388 check_insn(env, ctx, ISA_MIPS32R2);
3389 gen_op_mfc0_srsmap();
3399 gen_op_mfc0_cause();
3423 check_insn(env, ctx, ISA_MIPS32R2);
3424 gen_op_mfc0_ebase();
3434 gen_op_mfc0_config0();
3438 gen_op_mfc0_config1();
3442 gen_op_mfc0_config2();
3446 gen_op_mfc0_config3();
3449 /* 6,7 are implementation dependent */
3457 gen_op_dmfc0_lladdr();
3467 gen_op_dmfc0_watchlo(sel);
3477 gen_op_mfc0_watchhi(sel);
3487 check_insn(env, ctx, ISA_MIPS3);
3488 gen_op_dmfc0_xcontext();
3496 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3499 gen_op_mfc0_framemask();
3508 rn = "'Diagnostic"; /* implementation dependent */
3513 gen_op_mfc0_debug(); /* EJTAG support */
3517 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3518 rn = "TraceControl";
3521 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3522 rn = "TraceControl2";
3525 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3526 rn = "UserTraceData";
3529 // gen_op_dmfc0_debug(); /* PDtrace support */
3539 gen_op_dmfc0_depc(); /* EJTAG support */
3549 gen_op_mfc0_performance0();
3550 rn = "Performance0";
3553 // gen_op_dmfc0_performance1();
3554 rn = "Performance1";
3557 // gen_op_dmfc0_performance2();
3558 rn = "Performance2";
3561 // gen_op_dmfc0_performance3();
3562 rn = "Performance3";
3565 // gen_op_dmfc0_performance4();
3566 rn = "Performance4";
3569 // gen_op_dmfc0_performance5();
3570 rn = "Performance5";
3573 // gen_op_dmfc0_performance6();
3574 rn = "Performance6";
3577 // gen_op_dmfc0_performance7();
3578 rn = "Performance7";
3603 gen_op_mfc0_taglo();
3610 gen_op_mfc0_datalo();
3623 gen_op_mfc0_taghi();
3630 gen_op_mfc0_datahi();
3640 gen_op_dmfc0_errorepc();
3650 gen_op_mfc0_desave(); /* EJTAG support */
3660 #if defined MIPS_DEBUG_DISAS
3661 if (loglevel & CPU_LOG_TB_IN_ASM) {
3662 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3669 #if defined MIPS_DEBUG_DISAS
3670 if (loglevel & CPU_LOG_TB_IN_ASM) {
3671 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3675 generate_exception(ctx, EXCP_RI);
3678 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
3680 const char *rn = "invalid";
3683 check_insn(env, ctx, ISA_MIPS64);
3689 gen_op_mtc0_index();
3693 check_mips_mt(env, ctx);
3694 gen_op_mtc0_mvpcontrol();
3698 check_mips_mt(env, ctx);
3703 check_mips_mt(env, ctx);
3718 check_mips_mt(env, ctx);
3719 gen_op_mtc0_vpecontrol();
3723 check_mips_mt(env, ctx);
3724 gen_op_mtc0_vpeconf0();
3728 check_mips_mt(env, ctx);
3729 gen_op_mtc0_vpeconf1();
3733 check_mips_mt(env, ctx);
3734 gen_op_mtc0_yqmask();
3738 check_mips_mt(env, ctx);
3739 gen_op_mtc0_vpeschedule();
3743 check_mips_mt(env, ctx);
3744 gen_op_mtc0_vpeschefback();
3745 rn = "VPEScheFBack";
3748 check_mips_mt(env, ctx);
3749 gen_op_mtc0_vpeopt();
3759 gen_op_mtc0_entrylo0();
3763 check_mips_mt(env, ctx);
3764 gen_op_mtc0_tcstatus();
3768 check_mips_mt(env, ctx);
3769 gen_op_mtc0_tcbind();
3773 check_mips_mt(env, ctx);
3774 gen_op_mtc0_tcrestart();
3778 check_mips_mt(env, ctx);
3779 gen_op_mtc0_tchalt();
3783 check_mips_mt(env, ctx);
3784 gen_op_mtc0_tccontext();
3788 check_mips_mt(env, ctx);
3789 gen_op_mtc0_tcschedule();
3793 check_mips_mt(env, ctx);
3794 gen_op_mtc0_tcschefback();
3804 gen_op_mtc0_entrylo1();
3814 gen_op_mtc0_context();
3818 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3819 rn = "ContextConfig";
3828 gen_op_mtc0_pagemask();
3832 check_insn(env, ctx, ISA_MIPS32R2);
3833 gen_op_mtc0_pagegrain();
3843 gen_op_mtc0_wired();
3847 check_insn(env, ctx, ISA_MIPS32R2);
3848 gen_op_mtc0_srsconf0();
3852 check_insn(env, ctx, ISA_MIPS32R2);
3853 gen_op_mtc0_srsconf1();
3857 check_insn(env, ctx, ISA_MIPS32R2);
3858 gen_op_mtc0_srsconf2();
3862 check_insn(env, ctx, ISA_MIPS32R2);
3863 gen_op_mtc0_srsconf3();
3867 check_insn(env, ctx, ISA_MIPS32R2);
3868 gen_op_mtc0_srsconf4();
3878 check_insn(env, ctx, ISA_MIPS32R2);
3879 gen_op_mtc0_hwrena();
3893 gen_op_mtc0_count();
3896 /* 6,7 are implementation dependent */
3900 /* Stop translation as we may have switched the execution mode */
3901 ctx->bstate = BS_STOP;
3906 gen_op_mtc0_entryhi();
3916 gen_op_mtc0_compare();
3919 /* 6,7 are implementation dependent */
3923 /* Stop translation as we may have switched the execution mode */
3924 ctx->bstate = BS_STOP;
3929 gen_op_mtc0_status();
3930 /* BS_STOP isn't good enough here, hflags may have changed. */
3931 gen_save_pc(ctx->pc + 4);
3932 ctx->bstate = BS_EXCP;
3936 check_insn(env, ctx, ISA_MIPS32R2);
3937 gen_op_mtc0_intctl();
3938 /* Stop translation as we may have switched the execution mode */
3939 ctx->bstate = BS_STOP;
3943 check_insn(env, ctx, ISA_MIPS32R2);
3944 gen_op_mtc0_srsctl();
3945 /* Stop translation as we may have switched the execution mode */
3946 ctx->bstate = BS_STOP;
3950 check_insn(env, ctx, ISA_MIPS32R2);
3951 gen_op_mtc0_srsmap();
3952 /* Stop translation as we may have switched the execution mode */
3953 ctx->bstate = BS_STOP;
3963 gen_op_mtc0_cause();
3969 /* Stop translation as we may have switched the execution mode */
3970 ctx->bstate = BS_STOP;
3989 check_insn(env, ctx, ISA_MIPS32R2);
3990 gen_op_mtc0_ebase();
4000 gen_op_mtc0_config0();
4002 /* Stop translation as we may have switched the execution mode */
4003 ctx->bstate = BS_STOP;
4010 gen_op_mtc0_config2();
4012 /* Stop translation as we may have switched the execution mode */
4013 ctx->bstate = BS_STOP;
4019 /* 6,7 are implementation dependent */
4021 rn = "Invalid config selector";
4038 gen_op_mtc0_watchlo(sel);
4048 gen_op_mtc0_watchhi(sel);
4058 check_insn(env, ctx, ISA_MIPS3);
4059 gen_op_mtc0_xcontext();
4067 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4070 gen_op_mtc0_framemask();
4079 rn = "Diagnostic"; /* implementation dependent */
4084 gen_op_mtc0_debug(); /* EJTAG support */
4085 /* BS_STOP isn't good enough here, hflags may have changed. */
4086 gen_save_pc(ctx->pc + 4);
4087 ctx->bstate = BS_EXCP;
4091 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4092 /* Stop translation as we may have switched the execution mode */
4093 ctx->bstate = BS_STOP;
4094 rn = "TraceControl";
4097 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4098 /* Stop translation as we may have switched the execution mode */
4099 ctx->bstate = BS_STOP;
4100 rn = "TraceControl2";
4103 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4104 /* Stop translation as we may have switched the execution mode */
4105 ctx->bstate = BS_STOP;
4106 rn = "UserTraceData";
4109 // gen_op_mtc0_debug(); /* PDtrace support */
4110 /* Stop translation as we may have switched the execution mode */
4111 ctx->bstate = BS_STOP;
4121 gen_op_mtc0_depc(); /* EJTAG support */
4131 gen_op_mtc0_performance0();
4132 rn = "Performance0";
4135 // gen_op_mtc0_performance1();
4136 rn = "Performance1";
4139 // gen_op_mtc0_performance2();
4140 rn = "Performance2";
4143 // gen_op_mtc0_performance3();
4144 rn = "Performance3";
4147 // gen_op_mtc0_performance4();
4148 rn = "Performance4";
4151 // gen_op_mtc0_performance5();
4152 rn = "Performance5";
4155 // gen_op_mtc0_performance6();
4156 rn = "Performance6";
4159 // gen_op_mtc0_performance7();
4160 rn = "Performance7";
4186 gen_op_mtc0_taglo();
4193 gen_op_mtc0_datalo();
4206 gen_op_mtc0_taghi();
4213 gen_op_mtc0_datahi();
4224 gen_op_mtc0_errorepc();
4234 gen_op_mtc0_desave(); /* EJTAG support */
4240 /* Stop translation as we may have switched the execution mode */
4241 ctx->bstate = BS_STOP;
4246 #if defined MIPS_DEBUG_DISAS
4247 if (loglevel & CPU_LOG_TB_IN_ASM) {
4248 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4255 #if defined MIPS_DEBUG_DISAS
4256 if (loglevel & CPU_LOG_TB_IN_ASM) {
4257 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4261 generate_exception(ctx, EXCP_RI);
4263 #endif /* TARGET_MIPSN32 || TARGET_MIPS64 */
4265 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt,
4266 int u, int sel, int h)
4268 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
4270 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
4271 ((env->CP0_TCBind[other_tc] & (0xf << CP0TCBd_CurVPE)) !=
4272 (env->CP0_TCBind[env->current_tc] & (0xf << CP0TCBd_CurVPE))))
4274 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
4275 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
4282 gen_op_mftc0_tcstatus();
4285 gen_op_mftc0_tcbind();
4288 gen_op_mftc0_tcrestart();
4291 gen_op_mftc0_tchalt();
4294 gen_op_mftc0_tccontext();
4297 gen_op_mftc0_tcschedule();
4300 gen_op_mftc0_tcschefback();
4303 gen_mfc0(env, ctx, rt, sel);
4310 gen_op_mftc0_entryhi();
4313 gen_mfc0(env, ctx, rt, sel);
4319 gen_op_mftc0_status();
4322 gen_mfc0(env, ctx, rt, sel);
4328 gen_op_mftc0_debug();
4331 gen_mfc0(env, ctx, rt, sel);
4336 gen_mfc0(env, ctx, rt, sel);
4338 } else switch (sel) {
4339 /* GPR registers. */
4343 /* Auxiliary CPU registers */
4389 /* Floating point (COP1). */
4391 /* XXX: For now we support only a single FPU context. */
4393 GEN_LOAD_FREG_FTN(WT0, rt);
4396 GEN_LOAD_FREG_FTN(WTH0, rt);
4401 /* XXX: For now we support only a single FPU context. */
4404 /* COP2: Not implemented. */
4411 #if defined MIPS_DEBUG_DISAS
4412 if (loglevel & CPU_LOG_TB_IN_ASM) {
4413 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
4420 #if defined MIPS_DEBUG_DISAS
4421 if (loglevel & CPU_LOG_TB_IN_ASM) {
4422 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
4426 generate_exception(ctx, EXCP_RI);
4429 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd,
4430 int u, int sel, int h)
4432 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
4434 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
4435 ((env->CP0_TCBind[other_tc] & (0xf << CP0TCBd_CurVPE)) !=
4436 (env->CP0_TCBind[env->current_tc] & (0xf << CP0TCBd_CurVPE))))
4438 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
4439 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
4446 gen_op_mttc0_tcstatus();
4449 gen_op_mttc0_tcbind();
4452 gen_op_mttc0_tcrestart();
4455 gen_op_mttc0_tchalt();
4458 gen_op_mttc0_tccontext();
4461 gen_op_mttc0_tcschedule();
4464 gen_op_mttc0_tcschefback();
4467 gen_mtc0(env, ctx, rd, sel);
4474 gen_op_mttc0_entryhi();
4477 gen_mtc0(env, ctx, rd, sel);
4483 gen_op_mttc0_status();
4486 gen_mtc0(env, ctx, rd, sel);
4492 gen_op_mttc0_debug();
4495 gen_mtc0(env, ctx, rd, sel);
4500 gen_mtc0(env, ctx, rd, sel);
4502 } else switch (sel) {
4503 /* GPR registers. */
4507 /* Auxiliary CPU registers */
4553 /* Floating point (COP1). */
4555 /* XXX: For now we support only a single FPU context. */
4558 GEN_STORE_FTN_FREG(rd, WT0);
4561 GEN_STORE_FTN_FREG(rd, WTH0);
4565 /* XXX: For now we support only a single FPU context. */
4568 /* COP2: Not implemented. */
4575 #if defined MIPS_DEBUG_DISAS
4576 if (loglevel & CPU_LOG_TB_IN_ASM) {
4577 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
4584 #if defined MIPS_DEBUG_DISAS
4585 if (loglevel & CPU_LOG_TB_IN_ASM) {
4586 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
4590 generate_exception(ctx, EXCP_RI);
4593 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
4595 const char *opn = "ldst";
4603 gen_mfc0(env, ctx, rd, ctx->opcode & 0x7);
4604 gen_op_store_T0_gpr(rt);
4608 GEN_LOAD_REG_TN(T0, rt);
4609 save_cpu_state(ctx, 1);
4610 gen_mtc0(env, ctx, rd, ctx->opcode & 0x7);
4613 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
4615 check_insn(env, ctx, ISA_MIPS3);
4620 gen_dmfc0(env, ctx, rd, ctx->opcode & 0x7);
4621 gen_op_store_T0_gpr(rt);
4625 check_insn(env, ctx, ISA_MIPS3);
4626 GEN_LOAD_REG_TN(T0, rt);
4627 save_cpu_state(ctx, 1);
4628 gen_dmtc0(env, ctx, rd, ctx->opcode & 0x7);
4633 check_mips_mt(env, ctx);
4638 gen_mftr(env, ctx, rt, (ctx->opcode >> 5) & 1,
4639 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
4640 gen_op_store_T0_gpr(rd);
4644 check_mips_mt(env, ctx);
4645 GEN_LOAD_REG_TN(T0, rt);
4646 gen_mttr(env, ctx, rd, (ctx->opcode >> 5) & 1,
4647 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
4652 if (!env->tlb->do_tlbwi)
4658 if (!env->tlb->do_tlbwr)
4664 if (!env->tlb->do_tlbp)
4670 if (!env->tlb->do_tlbr)
4676 check_insn(env, ctx, ISA_MIPS2);
4677 save_cpu_state(ctx, 1);
4679 ctx->bstate = BS_EXCP;
4683 check_insn(env, ctx, ISA_MIPS32);
4684 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
4686 generate_exception(ctx, EXCP_RI);
4688 save_cpu_state(ctx, 1);
4690 ctx->bstate = BS_EXCP;
4695 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
4696 /* If we get an exception, we want to restart at next instruction */
4698 save_cpu_state(ctx, 1);
4701 ctx->bstate = BS_EXCP;
4706 generate_exception(ctx, EXCP_RI);
4709 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
4712 /* CP1 Branches (before delay slot) */
4713 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
4714 int32_t cc, int32_t offset)
4716 target_ulong btarget;
4717 const char *opn = "cp1 cond branch";
4720 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
4722 btarget = ctx->pc + 4 + offset;
4741 ctx->hflags |= MIPS_HFLAG_BL;
4743 gen_op_save_bcond();
4746 gen_op_bc1any2f(cc);
4750 gen_op_bc1any2t(cc);
4754 gen_op_bc1any4f(cc);
4758 gen_op_bc1any4t(cc);
4761 ctx->hflags |= MIPS_HFLAG_BC;
4766 generate_exception (ctx, EXCP_RI);
4769 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
4770 ctx->hflags, btarget);
4771 ctx->btarget = btarget;
4774 /* Coprocessor 1 (FPU) */
4776 #define FOP(func, fmt) (((fmt) << 21) | (func))
4778 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
4780 const char *opn = "cp1 move";
4784 GEN_LOAD_FREG_FTN(WT0, fs);
4786 GEN_STORE_TN_REG(rt, T0);
4790 GEN_LOAD_REG_TN(T0, rt);
4792 GEN_STORE_FTN_FREG(fs, WT0);
4797 GEN_STORE_TN_REG(rt, T0);
4801 GEN_LOAD_REG_TN(T0, rt);
4806 GEN_LOAD_FREG_FTN(DT0, fs);
4808 GEN_STORE_TN_REG(rt, T0);
4812 GEN_LOAD_REG_TN(T0, rt);
4814 GEN_STORE_FTN_FREG(fs, DT0);
4818 GEN_LOAD_FREG_FTN(WTH0, fs);
4820 GEN_STORE_TN_REG(rt, T0);
4824 GEN_LOAD_REG_TN(T0, rt);
4826 GEN_STORE_FTN_FREG(fs, WTH0);
4831 generate_exception (ctx, EXCP_RI);
4834 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
4837 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
4841 GEN_LOAD_REG_TN(T0, rd);
4842 GEN_LOAD_REG_TN(T1, rs);
4844 ccbit = 1 << (24 + cc);
4851 GEN_STORE_TN_REG(rd, T0);
4854 #define GEN_MOVCF(fmt) \
4855 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4860 ccbit = 1 << (24 + cc); \
4864 glue(gen_op_float_movf_, fmt)(ccbit); \
4866 glue(gen_op_float_movt_, fmt)(ccbit); \
4873 static void gen_farith (DisasContext *ctx, uint32_t op1,
4874 int ft, int fs, int fd, int cc)
4876 const char *opn = "farith";
4877 const char *condnames[] = {
4895 const char *condnames_abs[] = {
4913 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
4914 uint32_t func = ctx->opcode & 0x3f;
4916 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
4918 GEN_LOAD_FREG_FTN(WT0, fs);
4919 GEN_LOAD_FREG_FTN(WT1, ft);
4920 gen_op_float_add_s();
4921 GEN_STORE_FTN_FREG(fd, WT2);
4926 GEN_LOAD_FREG_FTN(WT0, fs);
4927 GEN_LOAD_FREG_FTN(WT1, ft);
4928 gen_op_float_sub_s();
4929 GEN_STORE_FTN_FREG(fd, WT2);
4934 GEN_LOAD_FREG_FTN(WT0, fs);
4935 GEN_LOAD_FREG_FTN(WT1, ft);
4936 gen_op_float_mul_s();
4937 GEN_STORE_FTN_FREG(fd, WT2);
4942 GEN_LOAD_FREG_FTN(WT0, fs);
4943 GEN_LOAD_FREG_FTN(WT1, ft);
4944 gen_op_float_div_s();
4945 GEN_STORE_FTN_FREG(fd, WT2);
4950 GEN_LOAD_FREG_FTN(WT0, fs);
4951 gen_op_float_sqrt_s();
4952 GEN_STORE_FTN_FREG(fd, WT2);
4956 GEN_LOAD_FREG_FTN(WT0, fs);
4957 gen_op_float_abs_s();
4958 GEN_STORE_FTN_FREG(fd, WT2);
4962 GEN_LOAD_FREG_FTN(WT0, fs);
4963 gen_op_float_mov_s();
4964 GEN_STORE_FTN_FREG(fd, WT2);
4968 GEN_LOAD_FREG_FTN(WT0, fs);
4969 gen_op_float_chs_s();
4970 GEN_STORE_FTN_FREG(fd, WT2);
4974 check_cp1_64bitmode(ctx);
4975 GEN_LOAD_FREG_FTN(WT0, fs);
4976 gen_op_float_roundl_s();
4977 GEN_STORE_FTN_FREG(fd, DT2);
4981 check_cp1_64bitmode(ctx);
4982 GEN_LOAD_FREG_FTN(WT0, fs);
4983 gen_op_float_truncl_s();
4984 GEN_STORE_FTN_FREG(fd, DT2);
4988 check_cp1_64bitmode(ctx);
4989 GEN_LOAD_FREG_FTN(WT0, fs);
4990 gen_op_float_ceill_s();
4991 GEN_STORE_FTN_FREG(fd, DT2);
4995 check_cp1_64bitmode(ctx);
4996 GEN_LOAD_FREG_FTN(WT0, fs);
4997 gen_op_float_floorl_s();
4998 GEN_STORE_FTN_FREG(fd, DT2);
5002 GEN_LOAD_FREG_FTN(WT0, fs);
5003 gen_op_float_roundw_s();
5004 GEN_STORE_FTN_FREG(fd, WT2);
5008 GEN_LOAD_FREG_FTN(WT0, fs);
5009 gen_op_float_truncw_s();
5010 GEN_STORE_FTN_FREG(fd, WT2);
5014 GEN_LOAD_FREG_FTN(WT0, fs);
5015 gen_op_float_ceilw_s();
5016 GEN_STORE_FTN_FREG(fd, WT2);
5020 GEN_LOAD_FREG_FTN(WT0, fs);
5021 gen_op_float_floorw_s();
5022 GEN_STORE_FTN_FREG(fd, WT2);
5026 GEN_LOAD_REG_TN(T0, ft);
5027 GEN_LOAD_FREG_FTN(WT0, fs);
5028 GEN_LOAD_FREG_FTN(WT2, fd);
5029 gen_movcf_s(ctx, (ft >> 2) & 0x7, ft & 0x1);
5030 GEN_STORE_FTN_FREG(fd, WT2);
5034 GEN_LOAD_REG_TN(T0, ft);
5035 GEN_LOAD_FREG_FTN(WT0, fs);
5036 GEN_LOAD_FREG_FTN(WT2, fd);
5037 gen_op_float_movz_s();
5038 GEN_STORE_FTN_FREG(fd, WT2);
5042 GEN_LOAD_REG_TN(T0, ft);
5043 GEN_LOAD_FREG_FTN(WT0, fs);
5044 GEN_LOAD_FREG_FTN(WT2, fd);
5045 gen_op_float_movn_s();
5046 GEN_STORE_FTN_FREG(fd, WT2);
5050 GEN_LOAD_FREG_FTN(WT0, fs);
5051 gen_op_float_recip_s();
5052 GEN_STORE_FTN_FREG(fd, WT2);
5056 GEN_LOAD_FREG_FTN(WT0, fs);
5057 gen_op_float_rsqrt_s();
5058 GEN_STORE_FTN_FREG(fd, WT2);
5062 check_cp1_64bitmode(ctx);
5063 GEN_LOAD_FREG_FTN(WT0, fs);
5064 GEN_LOAD_FREG_FTN(WT2, fd);
5065 gen_op_float_recip2_s();
5066 GEN_STORE_FTN_FREG(fd, WT2);
5070 check_cp1_64bitmode(ctx);
5071 GEN_LOAD_FREG_FTN(WT0, fs);
5072 gen_op_float_recip1_s();
5073 GEN_STORE_FTN_FREG(fd, WT2);
5077 check_cp1_64bitmode(ctx);
5078 GEN_LOAD_FREG_FTN(WT0, fs);
5079 gen_op_float_rsqrt1_s();
5080 GEN_STORE_FTN_FREG(fd, WT2);
5084 check_cp1_64bitmode(ctx);
5085 GEN_LOAD_FREG_FTN(WT0, fs);
5086 GEN_LOAD_FREG_FTN(WT2, ft);
5087 gen_op_float_rsqrt2_s();
5088 GEN_STORE_FTN_FREG(fd, WT2);
5092 check_cp1_registers(ctx, fd);
5093 GEN_LOAD_FREG_FTN(WT0, fs);
5094 gen_op_float_cvtd_s();
5095 GEN_STORE_FTN_FREG(fd, DT2);
5099 GEN_LOAD_FREG_FTN(WT0, fs);
5100 gen_op_float_cvtw_s();
5101 GEN_STORE_FTN_FREG(fd, WT2);
5105 check_cp1_64bitmode(ctx);
5106 GEN_LOAD_FREG_FTN(WT0, fs);
5107 gen_op_float_cvtl_s();
5108 GEN_STORE_FTN_FREG(fd, DT2);
5112 check_cp1_64bitmode(ctx);
5113 GEN_LOAD_FREG_FTN(WT1, fs);
5114 GEN_LOAD_FREG_FTN(WT0, ft);
5115 gen_op_float_cvtps_s();
5116 GEN_STORE_FTN_FREG(fd, DT2);
5135 GEN_LOAD_FREG_FTN(WT0, fs);
5136 GEN_LOAD_FREG_FTN(WT1, ft);
5137 if (ctx->opcode & (1 << 6)) {
5138 check_cp1_64bitmode(ctx);
5139 gen_cmpabs_s(func-48, cc);
5140 opn = condnames_abs[func-48];
5142 gen_cmp_s(func-48, cc);
5143 opn = condnames[func-48];
5147 check_cp1_registers(ctx, fs | ft | fd);
5148 GEN_LOAD_FREG_FTN(DT0, fs);
5149 GEN_LOAD_FREG_FTN(DT1, ft);
5150 gen_op_float_add_d();
5151 GEN_STORE_FTN_FREG(fd, DT2);
5156 check_cp1_registers(ctx, fs | ft | fd);
5157 GEN_LOAD_FREG_FTN(DT0, fs);
5158 GEN_LOAD_FREG_FTN(DT1, ft);
5159 gen_op_float_sub_d();
5160 GEN_STORE_FTN_FREG(fd, DT2);
5165 check_cp1_registers(ctx, fs | ft | fd);
5166 GEN_LOAD_FREG_FTN(DT0, fs);
5167 GEN_LOAD_FREG_FTN(DT1, ft);
5168 gen_op_float_mul_d();
5169 GEN_STORE_FTN_FREG(fd, DT2);
5174 check_cp1_registers(ctx, fs | ft | fd);
5175 GEN_LOAD_FREG_FTN(DT0, fs);
5176 GEN_LOAD_FREG_FTN(DT1, ft);
5177 gen_op_float_div_d();
5178 GEN_STORE_FTN_FREG(fd, DT2);
5183 check_cp1_registers(ctx, fs | fd);
5184 GEN_LOAD_FREG_FTN(DT0, fs);
5185 gen_op_float_sqrt_d();
5186 GEN_STORE_FTN_FREG(fd, DT2);
5190 check_cp1_registers(ctx, fs | fd);
5191 GEN_LOAD_FREG_FTN(DT0, fs);
5192 gen_op_float_abs_d();
5193 GEN_STORE_FTN_FREG(fd, DT2);
5197 check_cp1_registers(ctx, fs | fd);
5198 GEN_LOAD_FREG_FTN(DT0, fs);
5199 gen_op_float_mov_d();
5200 GEN_STORE_FTN_FREG(fd, DT2);
5204 check_cp1_registers(ctx, fs | fd);
5205 GEN_LOAD_FREG_FTN(DT0, fs);
5206 gen_op_float_chs_d();
5207 GEN_STORE_FTN_FREG(fd, DT2);
5211 check_cp1_64bitmode(ctx);
5212 GEN_LOAD_FREG_FTN(DT0, fs);
5213 gen_op_float_roundl_d();
5214 GEN_STORE_FTN_FREG(fd, DT2);
5218 check_cp1_64bitmode(ctx);
5219 GEN_LOAD_FREG_FTN(DT0, fs);
5220 gen_op_float_truncl_d();
5221 GEN_STORE_FTN_FREG(fd, DT2);
5225 check_cp1_64bitmode(ctx);
5226 GEN_LOAD_FREG_FTN(DT0, fs);
5227 gen_op_float_ceill_d();
5228 GEN_STORE_FTN_FREG(fd, DT2);
5232 check_cp1_64bitmode(ctx);
5233 GEN_LOAD_FREG_FTN(DT0, fs);
5234 gen_op_float_floorl_d();
5235 GEN_STORE_FTN_FREG(fd, DT2);
5239 check_cp1_registers(ctx, fs);
5240 GEN_LOAD_FREG_FTN(DT0, fs);
5241 gen_op_float_roundw_d();
5242 GEN_STORE_FTN_FREG(fd, WT2);
5246 check_cp1_registers(ctx, fs);
5247 GEN_LOAD_FREG_FTN(DT0, fs);
5248 gen_op_float_truncw_d();
5249 GEN_STORE_FTN_FREG(fd, WT2);
5253 check_cp1_registers(ctx, fs);
5254 GEN_LOAD_FREG_FTN(DT0, fs);
5255 gen_op_float_ceilw_d();
5256 GEN_STORE_FTN_FREG(fd, WT2);
5260 check_cp1_registers(ctx, fs);
5261 GEN_LOAD_FREG_FTN(DT0, fs);
5262 gen_op_float_floorw_d();
5263 GEN_STORE_FTN_FREG(fd, WT2);
5267 GEN_LOAD_REG_TN(T0, ft);
5268 GEN_LOAD_FREG_FTN(DT0, fs);
5269 GEN_LOAD_FREG_FTN(DT2, fd);
5270 gen_movcf_d(ctx, (ft >> 2) & 0x7, ft & 0x1);
5271 GEN_STORE_FTN_FREG(fd, DT2);
5275 GEN_LOAD_REG_TN(T0, ft);
5276 GEN_LOAD_FREG_FTN(DT0, fs);
5277 GEN_LOAD_FREG_FTN(DT2, fd);
5278 gen_op_float_movz_d();
5279 GEN_STORE_FTN_FREG(fd, DT2);
5283 GEN_LOAD_REG_TN(T0, ft);
5284 GEN_LOAD_FREG_FTN(DT0, fs);
5285 GEN_LOAD_FREG_FTN(DT2, fd);
5286 gen_op_float_movn_d();
5287 GEN_STORE_FTN_FREG(fd, DT2);
5291 check_cp1_registers(ctx, fs | fd);
5292 GEN_LOAD_FREG_FTN(DT0, fs);
5293 gen_op_float_recip_d();
5294 GEN_STORE_FTN_FREG(fd, DT2);
5298 check_cp1_registers(ctx, fs | fd);
5299 GEN_LOAD_FREG_FTN(DT0, fs);
5300 gen_op_float_rsqrt_d();
5301 GEN_STORE_FTN_FREG(fd, DT2);
5305 check_cp1_64bitmode(ctx);
5306 GEN_LOAD_FREG_FTN(DT0, fs);
5307 GEN_LOAD_FREG_FTN(DT2, ft);
5308 gen_op_float_recip2_d();
5309 GEN_STORE_FTN_FREG(fd, DT2);
5313 check_cp1_64bitmode(ctx);
5314 GEN_LOAD_FREG_FTN(DT0, fs);
5315 gen_op_float_recip1_d();
5316 GEN_STORE_FTN_FREG(fd, DT2);
5320 check_cp1_64bitmode(ctx);
5321 GEN_LOAD_FREG_FTN(DT0, fs);
5322 gen_op_float_rsqrt1_d();
5323 GEN_STORE_FTN_FREG(fd, DT2);
5327 check_cp1_64bitmode(ctx);
5328 GEN_LOAD_FREG_FTN(DT0, fs);
5329 GEN_LOAD_FREG_FTN(DT2, ft);
5330 gen_op_float_rsqrt2_d();
5331 GEN_STORE_FTN_FREG(fd, DT2);
5350 GEN_LOAD_FREG_FTN(DT0, fs);
5351 GEN_LOAD_FREG_FTN(DT1, ft);
5352 if (ctx->opcode & (1 << 6)) {
5353 check_cp1_64bitmode(ctx);
5354 gen_cmpabs_d(func-48, cc);
5355 opn = condnames_abs[func-48];
5357 check_cp1_registers(ctx, fs | ft);
5358 gen_cmp_d(func-48, cc);
5359 opn = condnames[func-48];
5363 check_cp1_registers(ctx, fs);
5364 GEN_LOAD_FREG_FTN(DT0, fs);
5365 gen_op_float_cvts_d();
5366 GEN_STORE_FTN_FREG(fd, WT2);
5370 check_cp1_registers(ctx, fs);
5371 GEN_LOAD_FREG_FTN(DT0, fs);
5372 gen_op_float_cvtw_d();
5373 GEN_STORE_FTN_FREG(fd, WT2);
5377 check_cp1_64bitmode(ctx);
5378 GEN_LOAD_FREG_FTN(DT0, fs);
5379 gen_op_float_cvtl_d();
5380 GEN_STORE_FTN_FREG(fd, DT2);
5384 GEN_LOAD_FREG_FTN(WT0, fs);
5385 gen_op_float_cvts_w();
5386 GEN_STORE_FTN_FREG(fd, WT2);
5390 check_cp1_registers(ctx, fd);
5391 GEN_LOAD_FREG_FTN(WT0, fs);
5392 gen_op_float_cvtd_w();
5393 GEN_STORE_FTN_FREG(fd, DT2);
5397 check_cp1_64bitmode(ctx);
5398 GEN_LOAD_FREG_FTN(DT0, fs);
5399 gen_op_float_cvts_l();
5400 GEN_STORE_FTN_FREG(fd, WT2);
5404 check_cp1_64bitmode(ctx);
5405 GEN_LOAD_FREG_FTN(DT0, fs);
5406 gen_op_float_cvtd_l();
5407 GEN_STORE_FTN_FREG(fd, DT2);
5412 check_cp1_64bitmode(ctx);
5413 GEN_LOAD_FREG_FTN(WT0, fs);
5414 GEN_LOAD_FREG_FTN(WTH0, fs);
5415 gen_op_float_cvtps_pw();
5416 GEN_STORE_FTN_FREG(fd, WT2);
5417 GEN_STORE_FTN_FREG(fd, WTH2);
5421 check_cp1_64bitmode(ctx);
5422 GEN_LOAD_FREG_FTN(WT0, fs);
5423 GEN_LOAD_FREG_FTN(WTH0, fs);
5424 GEN_LOAD_FREG_FTN(WT1, ft);
5425 GEN_LOAD_FREG_FTN(WTH1, ft);
5426 gen_op_float_add_ps();
5427 GEN_STORE_FTN_FREG(fd, WT2);
5428 GEN_STORE_FTN_FREG(fd, WTH2);
5432 check_cp1_64bitmode(ctx);
5433 GEN_LOAD_FREG_FTN(WT0, fs);
5434 GEN_LOAD_FREG_FTN(WTH0, fs);
5435 GEN_LOAD_FREG_FTN(WT1, ft);
5436 GEN_LOAD_FREG_FTN(WTH1, ft);
5437 gen_op_float_sub_ps();
5438 GEN_STORE_FTN_FREG(fd, WT2);
5439 GEN_STORE_FTN_FREG(fd, WTH2);
5443 check_cp1_64bitmode(ctx);
5444 GEN_LOAD_FREG_FTN(WT0, fs);
5445 GEN_LOAD_FREG_FTN(WTH0, fs);
5446 GEN_LOAD_FREG_FTN(WT1, ft);
5447 GEN_LOAD_FREG_FTN(WTH1, ft);
5448 gen_op_float_mul_ps();
5449 GEN_STORE_FTN_FREG(fd, WT2);
5450 GEN_STORE_FTN_FREG(fd, WTH2);
5454 check_cp1_64bitmode(ctx);
5455 GEN_LOAD_FREG_FTN(WT0, fs);
5456 GEN_LOAD_FREG_FTN(WTH0, fs);
5457 gen_op_float_abs_ps();
5458 GEN_STORE_FTN_FREG(fd, WT2);
5459 GEN_STORE_FTN_FREG(fd, WTH2);
5463 check_cp1_64bitmode(ctx);
5464 GEN_LOAD_FREG_FTN(WT0, fs);
5465 GEN_LOAD_FREG_FTN(WTH0, fs);
5466 gen_op_float_mov_ps();
5467 GEN_STORE_FTN_FREG(fd, WT2);
5468 GEN_STORE_FTN_FREG(fd, WTH2);
5472 check_cp1_64bitmode(ctx);
5473 GEN_LOAD_FREG_FTN(WT0, fs);
5474 GEN_LOAD_FREG_FTN(WTH0, fs);
5475 gen_op_float_chs_ps();
5476 GEN_STORE_FTN_FREG(fd, WT2);
5477 GEN_STORE_FTN_FREG(fd, WTH2);
5481 check_cp1_64bitmode(ctx);
5482 GEN_LOAD_REG_TN(T0, ft);
5483 GEN_LOAD_FREG_FTN(WT0, fs);
5484 GEN_LOAD_FREG_FTN(WTH0, fs);
5485 GEN_LOAD_FREG_FTN(WT2, fd);
5486 GEN_LOAD_FREG_FTN(WTH2, fd);
5487 gen_movcf_ps(ctx, (ft >> 2) & 0x7, ft & 0x1);
5488 GEN_STORE_FTN_FREG(fd, WT2);
5489 GEN_STORE_FTN_FREG(fd, WTH2);
5493 check_cp1_64bitmode(ctx);
5494 GEN_LOAD_REG_TN(T0, ft);
5495 GEN_LOAD_FREG_FTN(WT0, fs);
5496 GEN_LOAD_FREG_FTN(WTH0, fs);
5497 GEN_LOAD_FREG_FTN(WT2, fd);
5498 GEN_LOAD_FREG_FTN(WTH2, fd);
5499 gen_op_float_movz_ps();
5500 GEN_STORE_FTN_FREG(fd, WT2);
5501 GEN_STORE_FTN_FREG(fd, WTH2);
5505 check_cp1_64bitmode(ctx);
5506 GEN_LOAD_REG_TN(T0, ft);
5507 GEN_LOAD_FREG_FTN(WT0, fs);
5508 GEN_LOAD_FREG_FTN(WTH0, fs);
5509 GEN_LOAD_FREG_FTN(WT2, fd);
5510 GEN_LOAD_FREG_FTN(WTH2, fd);
5511 gen_op_float_movn_ps();
5512 GEN_STORE_FTN_FREG(fd, WT2);
5513 GEN_STORE_FTN_FREG(fd, WTH2);
5517 check_cp1_64bitmode(ctx);
5518 GEN_LOAD_FREG_FTN(WT0, ft);
5519 GEN_LOAD_FREG_FTN(WTH0, ft);
5520 GEN_LOAD_FREG_FTN(WT1, fs);
5521 GEN_LOAD_FREG_FTN(WTH1, fs);
5522 gen_op_float_addr_ps();
5523 GEN_STORE_FTN_FREG(fd, WT2);
5524 GEN_STORE_FTN_FREG(fd, WTH2);
5528 check_cp1_64bitmode(ctx);
5529 GEN_LOAD_FREG_FTN(WT0, ft);
5530 GEN_LOAD_FREG_FTN(WTH0, ft);
5531 GEN_LOAD_FREG_FTN(WT1, fs);
5532 GEN_LOAD_FREG_FTN(WTH1, fs);
5533 gen_op_float_mulr_ps();
5534 GEN_STORE_FTN_FREG(fd, WT2);
5535 GEN_STORE_FTN_FREG(fd, WTH2);
5539 check_cp1_64bitmode(ctx);
5540 GEN_LOAD_FREG_FTN(WT0, fs);
5541 GEN_LOAD_FREG_FTN(WTH0, fs);
5542 GEN_LOAD_FREG_FTN(WT2, fd);
5543 GEN_LOAD_FREG_FTN(WTH2, fd);
5544 gen_op_float_recip2_ps();
5545 GEN_STORE_FTN_FREG(fd, WT2);
5546 GEN_STORE_FTN_FREG(fd, WTH2);
5550 check_cp1_64bitmode(ctx);
5551 GEN_LOAD_FREG_FTN(WT0, fs);
5552 GEN_LOAD_FREG_FTN(WTH0, fs);
5553 gen_op_float_recip1_ps();
5554 GEN_STORE_FTN_FREG(fd, WT2);
5555 GEN_STORE_FTN_FREG(fd, WTH2);
5559 check_cp1_64bitmode(ctx);
5560 GEN_LOAD_FREG_FTN(WT0, fs);
5561 GEN_LOAD_FREG_FTN(WTH0, fs);
5562 gen_op_float_rsqrt1_ps();
5563 GEN_STORE_FTN_FREG(fd, WT2);
5564 GEN_STORE_FTN_FREG(fd, WTH2);
5568 check_cp1_64bitmode(ctx);
5569 GEN_LOAD_FREG_FTN(WT0, fs);
5570 GEN_LOAD_FREG_FTN(WTH0, fs);
5571 GEN_LOAD_FREG_FTN(WT2, ft);
5572 GEN_LOAD_FREG_FTN(WTH2, ft);
5573 gen_op_float_rsqrt2_ps();
5574 GEN_STORE_FTN_FREG(fd, WT2);
5575 GEN_STORE_FTN_FREG(fd, WTH2);
5579 check_cp1_64bitmode(ctx);
5580 GEN_LOAD_FREG_FTN(WTH0, fs);
5581 gen_op_float_cvts_pu();
5582 GEN_STORE_FTN_FREG(fd, WT2);
5586 check_cp1_64bitmode(ctx);
5587 GEN_LOAD_FREG_FTN(WT0, fs);
5588 GEN_LOAD_FREG_FTN(WTH0, fs);
5589 gen_op_float_cvtpw_ps();
5590 GEN_STORE_FTN_FREG(fd, WT2);
5591 GEN_STORE_FTN_FREG(fd, WTH2);
5595 check_cp1_64bitmode(ctx);
5596 GEN_LOAD_FREG_FTN(WT0, fs);
5597 gen_op_float_cvts_pl();
5598 GEN_STORE_FTN_FREG(fd, WT2);
5602 check_cp1_64bitmode(ctx);
5603 GEN_LOAD_FREG_FTN(WT0, fs);
5604 GEN_LOAD_FREG_FTN(WT1, ft);
5605 gen_op_float_pll_ps();
5606 GEN_STORE_FTN_FREG(fd, DT2);
5610 check_cp1_64bitmode(ctx);
5611 GEN_LOAD_FREG_FTN(WT0, fs);
5612 GEN_LOAD_FREG_FTN(WTH1, ft);
5613 gen_op_float_plu_ps();
5614 GEN_STORE_FTN_FREG(fd, DT2);
5618 check_cp1_64bitmode(ctx);
5619 GEN_LOAD_FREG_FTN(WTH0, fs);
5620 GEN_LOAD_FREG_FTN(WT1, ft);
5621 gen_op_float_pul_ps();
5622 GEN_STORE_FTN_FREG(fd, DT2);
5626 check_cp1_64bitmode(ctx);
5627 GEN_LOAD_FREG_FTN(WTH0, fs);
5628 GEN_LOAD_FREG_FTN(WTH1, ft);
5629 gen_op_float_puu_ps();
5630 GEN_STORE_FTN_FREG(fd, DT2);
5649 check_cp1_64bitmode(ctx);
5650 GEN_LOAD_FREG_FTN(WT0, fs);
5651 GEN_LOAD_FREG_FTN(WTH0, fs);
5652 GEN_LOAD_FREG_FTN(WT1, ft);
5653 GEN_LOAD_FREG_FTN(WTH1, ft);
5654 if (ctx->opcode & (1 << 6)) {
5655 gen_cmpabs_ps(func-48, cc);
5656 opn = condnames_abs[func-48];
5658 gen_cmp_ps(func-48, cc);
5659 opn = condnames[func-48];
5664 generate_exception (ctx, EXCP_RI);
5669 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
5672 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
5675 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
5680 /* Coprocessor 3 (FPU) */
5681 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
5682 int fd, int fs, int base, int index)
5684 const char *opn = "extended float load/store";
5687 /* All of those work only on 64bit FPUs. */
5688 check_cp1_64bitmode(ctx);
5693 GEN_LOAD_REG_TN(T0, index);
5694 } else if (index == 0) {
5695 GEN_LOAD_REG_TN(T0, base);
5697 GEN_LOAD_REG_TN(T0, base);
5698 GEN_LOAD_REG_TN(T1, index);
5701 /* Don't do NOP if destination is zero: we must perform the actual
5706 GEN_STORE_FTN_FREG(fd, WT0);
5711 GEN_STORE_FTN_FREG(fd, DT0);
5716 GEN_STORE_FTN_FREG(fd, DT0);
5720 GEN_LOAD_FREG_FTN(WT0, fs);
5726 GEN_LOAD_FREG_FTN(DT0, fs);
5732 GEN_LOAD_FREG_FTN(DT0, fs);
5739 generate_exception(ctx, EXCP_RI);
5742 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
5743 regnames[index], regnames[base]);
5746 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
5747 int fd, int fr, int fs, int ft)
5749 const char *opn = "flt3_arith";
5751 /* All of those work only on 64bit FPUs. */
5752 check_cp1_64bitmode(ctx);
5755 GEN_LOAD_REG_TN(T0, fr);
5756 GEN_LOAD_FREG_FTN(DT0, fs);
5757 GEN_LOAD_FREG_FTN(DT1, ft);
5758 gen_op_float_alnv_ps();
5759 GEN_STORE_FTN_FREG(fd, DT2);
5763 GEN_LOAD_FREG_FTN(WT0, fs);
5764 GEN_LOAD_FREG_FTN(WT1, ft);
5765 GEN_LOAD_FREG_FTN(WT2, fr);
5766 gen_op_float_muladd_s();
5767 GEN_STORE_FTN_FREG(fd, WT2);
5771 GEN_LOAD_FREG_FTN(DT0, fs);
5772 GEN_LOAD_FREG_FTN(DT1, ft);
5773 GEN_LOAD_FREG_FTN(DT2, fr);
5774 gen_op_float_muladd_d();
5775 GEN_STORE_FTN_FREG(fd, DT2);
5779 GEN_LOAD_FREG_FTN(WT0, fs);
5780 GEN_LOAD_FREG_FTN(WTH0, fs);
5781 GEN_LOAD_FREG_FTN(WT1, ft);
5782 GEN_LOAD_FREG_FTN(WTH1, ft);
5783 GEN_LOAD_FREG_FTN(WT2, fr);
5784 GEN_LOAD_FREG_FTN(WTH2, fr);
5785 gen_op_float_muladd_ps();
5786 GEN_STORE_FTN_FREG(fd, WT2);
5787 GEN_STORE_FTN_FREG(fd, WTH2);
5791 GEN_LOAD_FREG_FTN(WT0, fs);
5792 GEN_LOAD_FREG_FTN(WT1, ft);
5793 GEN_LOAD_FREG_FTN(WT2, fr);
5794 gen_op_float_mulsub_s();
5795 GEN_STORE_FTN_FREG(fd, WT2);
5799 GEN_LOAD_FREG_FTN(DT0, fs);
5800 GEN_LOAD_FREG_FTN(DT1, ft);
5801 GEN_LOAD_FREG_FTN(DT2, fr);
5802 gen_op_float_mulsub_d();
5803 GEN_STORE_FTN_FREG(fd, DT2);
5807 GEN_LOAD_FREG_FTN(WT0, fs);
5808 GEN_LOAD_FREG_FTN(WTH0, fs);
5809 GEN_LOAD_FREG_FTN(WT1, ft);
5810 GEN_LOAD_FREG_FTN(WTH1, ft);
5811 GEN_LOAD_FREG_FTN(WT2, fr);
5812 GEN_LOAD_FREG_FTN(WTH2, fr);
5813 gen_op_float_mulsub_ps();
5814 GEN_STORE_FTN_FREG(fd, WT2);
5815 GEN_STORE_FTN_FREG(fd, WTH2);
5819 GEN_LOAD_FREG_FTN(WT0, fs);
5820 GEN_LOAD_FREG_FTN(WT1, ft);
5821 GEN_LOAD_FREG_FTN(WT2, fr);
5822 gen_op_float_nmuladd_s();
5823 GEN_STORE_FTN_FREG(fd, WT2);
5827 GEN_LOAD_FREG_FTN(DT0, fs);
5828 GEN_LOAD_FREG_FTN(DT1, ft);
5829 GEN_LOAD_FREG_FTN(DT2, fr);
5830 gen_op_float_nmuladd_d();
5831 GEN_STORE_FTN_FREG(fd, DT2);
5835 GEN_LOAD_FREG_FTN(WT0, fs);
5836 GEN_LOAD_FREG_FTN(WTH0, fs);
5837 GEN_LOAD_FREG_FTN(WT1, ft);
5838 GEN_LOAD_FREG_FTN(WTH1, ft);
5839 GEN_LOAD_FREG_FTN(WT2, fr);
5840 GEN_LOAD_FREG_FTN(WTH2, fr);
5841 gen_op_float_nmuladd_ps();
5842 GEN_STORE_FTN_FREG(fd, WT2);
5843 GEN_STORE_FTN_FREG(fd, WTH2);
5847 GEN_LOAD_FREG_FTN(WT0, fs);
5848 GEN_LOAD_FREG_FTN(WT1, ft);
5849 GEN_LOAD_FREG_FTN(WT2, fr);
5850 gen_op_float_nmulsub_s();
5851 GEN_STORE_FTN_FREG(fd, WT2);
5855 GEN_LOAD_FREG_FTN(DT0, fs);
5856 GEN_LOAD_FREG_FTN(DT1, ft);
5857 GEN_LOAD_FREG_FTN(DT2, fr);
5858 gen_op_float_nmulsub_d();
5859 GEN_STORE_FTN_FREG(fd, DT2);
5863 GEN_LOAD_FREG_FTN(WT0, fs);
5864 GEN_LOAD_FREG_FTN(WTH0, fs);
5865 GEN_LOAD_FREG_FTN(WT1, ft);
5866 GEN_LOAD_FREG_FTN(WTH1, ft);
5867 GEN_LOAD_FREG_FTN(WT2, fr);
5868 GEN_LOAD_FREG_FTN(WTH2, fr);
5869 gen_op_float_nmulsub_ps();
5870 GEN_STORE_FTN_FREG(fd, WT2);
5871 GEN_STORE_FTN_FREG(fd, WTH2);
5876 generate_exception (ctx, EXCP_RI);
5879 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
5880 fregnames[fs], fregnames[ft]);
5883 /* ISA extensions (ASEs) */
5884 /* MIPS16 extension to MIPS32 */
5885 /* SmartMIPS extension to MIPS32 */
5887 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
5889 /* MDMX extension to MIPS64 */
5890 /* MIPS-3D extension to MIPS64 */
5894 static void decode_opc (CPUState *env, DisasContext *ctx)
5898 uint32_t op, op1, op2;
5901 /* make sure instructions are on a word boundary */
5902 if (ctx->pc & 0x3) {
5903 env->CP0_BadVAddr = ctx->pc;
5904 generate_exception(ctx, EXCP_AdEL);
5908 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
5910 /* Handle blikely not taken case */
5911 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
5912 l1 = gen_new_label();
5914 gen_op_save_state(ctx->hflags & ~MIPS_HFLAG_BMASK);
5915 gen_goto_tb(ctx, 1, ctx->pc + 4);
5918 op = MASK_OP_MAJOR(ctx->opcode);
5919 rs = (ctx->opcode >> 21) & 0x1f;
5920 rt = (ctx->opcode >> 16) & 0x1f;
5921 rd = (ctx->opcode >> 11) & 0x1f;
5922 sa = (ctx->opcode >> 6) & 0x1f;
5923 imm = (int16_t)ctx->opcode;
5926 op1 = MASK_SPECIAL(ctx->opcode);
5928 case OPC_SLL: /* Arithmetic with immediate */
5929 case OPC_SRL ... OPC_SRA:
5930 gen_arith_imm(env, ctx, op1, rd, rt, sa);
5932 case OPC_MOVZ ... OPC_MOVN:
5933 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5934 case OPC_SLLV: /* Arithmetic */
5935 case OPC_SRLV ... OPC_SRAV:
5936 case OPC_ADD ... OPC_NOR:
5937 case OPC_SLT ... OPC_SLTU:
5938 gen_arith(env, ctx, op1, rd, rs, rt);
5940 case OPC_MULT ... OPC_DIVU:
5941 gen_muldiv(ctx, op1, rs, rt);
5943 case OPC_JR ... OPC_JALR:
5944 gen_compute_branch(ctx, op1, rs, rd, sa);
5946 case OPC_TGE ... OPC_TEQ: /* Traps */
5948 gen_trap(ctx, op1, rs, rt, -1);
5950 case OPC_MFHI: /* Move from HI/LO */
5952 gen_HILO(ctx, op1, rd);
5955 case OPC_MTLO: /* Move to HI/LO */
5956 gen_HILO(ctx, op1, rs);
5958 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
5959 #ifdef MIPS_STRICT_STANDARD
5960 MIPS_INVAL("PMON / selsl");
5961 generate_exception(ctx, EXCP_RI);
5967 generate_exception(ctx, EXCP_SYSCALL);
5970 generate_exception(ctx, EXCP_BREAK);
5973 #ifdef MIPS_STRICT_STANDARD
5975 generate_exception(ctx, EXCP_RI);
5977 /* Implemented as RI exception for now. */
5978 MIPS_INVAL("spim (unofficial)");
5979 generate_exception(ctx, EXCP_RI);
5987 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5988 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5989 save_cpu_state(ctx, 1);
5990 check_cp1_enabled(ctx);
5991 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
5992 (ctx->opcode >> 16) & 1);
5994 generate_exception_err(ctx, EXCP_CpU, 1);
5998 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
5999 /* MIPS64 specific opcodes */
6001 case OPC_DSRL ... OPC_DSRA:
6003 case OPC_DSRL32 ... OPC_DSRA32:
6004 check_insn(env, ctx, ISA_MIPS3);
6006 gen_arith_imm(env, ctx, op1, rd, rt, sa);
6009 case OPC_DSRLV ... OPC_DSRAV:
6010 case OPC_DADD ... OPC_DSUBU:
6011 check_insn(env, ctx, ISA_MIPS3);
6013 gen_arith(env, ctx, op1, rd, rs, rt);
6015 case OPC_DMULT ... OPC_DDIVU:
6016 check_insn(env, ctx, ISA_MIPS3);
6018 gen_muldiv(ctx, op1, rs, rt);
6021 default: /* Invalid */
6022 MIPS_INVAL("special");
6023 generate_exception(ctx, EXCP_RI);
6028 op1 = MASK_SPECIAL2(ctx->opcode);
6030 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
6031 case OPC_MSUB ... OPC_MSUBU:
6032 check_insn(env, ctx, ISA_MIPS32);
6033 gen_muldiv(ctx, op1, rs, rt);
6036 gen_arith(env, ctx, op1, rd, rs, rt);
6038 case OPC_CLZ ... OPC_CLO:
6039 check_insn(env, ctx, ISA_MIPS32);
6040 gen_cl(ctx, op1, rd, rs);
6043 /* XXX: not clear which exception should be raised
6044 * when in debug mode...
6046 check_insn(env, ctx, ISA_MIPS32);
6047 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
6048 generate_exception(ctx, EXCP_DBp);
6050 generate_exception(ctx, EXCP_DBp);
6054 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
6055 case OPC_DCLZ ... OPC_DCLO:
6056 check_insn(env, ctx, ISA_MIPS64);
6058 gen_cl(ctx, op1, rd, rs);
6061 default: /* Invalid */
6062 MIPS_INVAL("special2");
6063 generate_exception(ctx, EXCP_RI);
6068 op1 = MASK_SPECIAL3(ctx->opcode);
6072 check_insn(env, ctx, ISA_MIPS32R2);
6073 gen_bitops(ctx, op1, rt, rs, sa, rd);
6076 check_insn(env, ctx, ISA_MIPS32R2);
6077 op2 = MASK_BSHFL(ctx->opcode);
6080 GEN_LOAD_REG_TN(T1, rt);
6084 GEN_LOAD_REG_TN(T1, rt);
6088 GEN_LOAD_REG_TN(T1, rt);
6091 default: /* Invalid */
6092 MIPS_INVAL("bshfl");
6093 generate_exception(ctx, EXCP_RI);
6096 GEN_STORE_TN_REG(rd, T0);
6099 check_insn(env, ctx, ISA_MIPS32R2);
6102 save_cpu_state(ctx, 1);
6103 gen_op_rdhwr_cpunum();
6106 save_cpu_state(ctx, 1);
6107 gen_op_rdhwr_synci_step();
6110 save_cpu_state(ctx, 1);
6114 save_cpu_state(ctx, 1);
6115 gen_op_rdhwr_ccres();
6118 #if defined (CONFIG_USER_ONLY)
6122 default: /* Invalid */
6123 MIPS_INVAL("rdhwr");
6124 generate_exception(ctx, EXCP_RI);
6127 GEN_STORE_TN_REG(rt, T0);
6130 check_mips_mt(env, ctx);
6131 GEN_LOAD_REG_TN(T0, rt);
6132 GEN_LOAD_REG_TN(T1, rs);
6136 check_mips_mt(env, ctx);
6137 GEN_LOAD_REG_TN(T0, rs);
6139 GEN_STORE_TN_REG(rd, T0);
6141 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
6142 case OPC_DEXTM ... OPC_DEXT:
6143 case OPC_DINSM ... OPC_DINS:
6144 check_insn(env, ctx, ISA_MIPS64R2);
6146 gen_bitops(ctx, op1, rt, rs, sa, rd);
6149 check_insn(env, ctx, ISA_MIPS64R2);
6151 op2 = MASK_DBSHFL(ctx->opcode);
6154 GEN_LOAD_REG_TN(T1, rt);
6158 GEN_LOAD_REG_TN(T1, rt);
6161 default: /* Invalid */
6162 MIPS_INVAL("dbshfl");
6163 generate_exception(ctx, EXCP_RI);
6166 GEN_STORE_TN_REG(rd, T0);
6168 default: /* Invalid */
6169 MIPS_INVAL("special3");
6170 generate_exception(ctx, EXCP_RI);
6175 op1 = MASK_REGIMM(ctx->opcode);
6177 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
6178 case OPC_BLTZAL ... OPC_BGEZALL:
6179 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
6181 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
6183 gen_trap(ctx, op1, rs, -1, imm);
6186 check_insn(env, ctx, ISA_MIPS32R2);
6189 default: /* Invalid */
6190 MIPS_INVAL("regimm");
6191 generate_exception(ctx, EXCP_RI);
6196 check_cp0_enabled(ctx);
6197 op1 = MASK_CP0(ctx->opcode);
6203 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
6207 gen_cp0(env, ctx, op1, rt, rd);
6209 case OPC_C0_FIRST ... OPC_C0_LAST:
6210 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
6213 op2 = MASK_MFMC0(ctx->opcode);
6216 check_mips_mt(env, ctx);
6220 check_mips_mt(env, ctx);
6224 check_mips_mt(env, ctx);
6228 check_mips_mt(env, ctx);
6232 check_insn(env, ctx, ISA_MIPS32R2);
6233 save_cpu_state(ctx, 1);
6235 /* Stop translation as we may have switched the execution mode */
6236 ctx->bstate = BS_STOP;
6239 check_insn(env, ctx, ISA_MIPS32R2);
6240 save_cpu_state(ctx, 1);
6242 /* Stop translation as we may have switched the execution mode */
6243 ctx->bstate = BS_STOP;
6245 default: /* Invalid */
6246 MIPS_INVAL("mfmc0");
6247 generate_exception(ctx, EXCP_RI);
6250 GEN_STORE_TN_REG(rt, T0);
6253 check_insn(env, ctx, ISA_MIPS32R2);
6254 GEN_LOAD_SRSREG_TN(T0, rt);
6255 GEN_STORE_TN_REG(rd, T0);
6258 check_insn(env, ctx, ISA_MIPS32R2);
6259 GEN_LOAD_REG_TN(T0, rt);
6260 GEN_STORE_TN_SRSREG(rd, T0);
6264 generate_exception(ctx, EXCP_RI);
6268 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
6269 gen_arith_imm(env, ctx, op, rt, rs, imm);
6271 case OPC_J ... OPC_JAL: /* Jump */
6272 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
6273 gen_compute_branch(ctx, op, rs, rt, offset);
6275 case OPC_BEQ ... OPC_BGTZ: /* Branch */
6276 case OPC_BEQL ... OPC_BGTZL:
6277 gen_compute_branch(ctx, op, rs, rt, imm << 2);
6279 case OPC_LB ... OPC_LWR: /* Load and stores */
6280 case OPC_SB ... OPC_SW:
6284 gen_ldst(ctx, op, rt, rs, imm);
6287 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
6291 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
6295 /* Floating point (COP1). */
6300 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
6301 save_cpu_state(ctx, 1);
6302 check_cp1_enabled(ctx);
6303 gen_flt_ldst(ctx, op, rt, rs, imm);
6305 generate_exception_err(ctx, EXCP_CpU, 1);
6310 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
6311 save_cpu_state(ctx, 1);
6312 check_cp1_enabled(ctx);
6313 op1 = MASK_CP1(ctx->opcode);
6317 check_insn(env, ctx, ISA_MIPS32R2);
6322 gen_cp1(ctx, op1, rt, rd);
6324 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
6327 check_insn(env, ctx, ISA_MIPS3);
6328 gen_cp1(ctx, op1, rt, rd);
6334 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
6335 (rt >> 2) & 0x7, imm << 2);
6342 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
6347 generate_exception (ctx, EXCP_RI);
6351 generate_exception_err(ctx, EXCP_CpU, 1);
6361 /* COP2: Not implemented. */
6362 generate_exception_err(ctx, EXCP_CpU, 2);
6366 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
6367 save_cpu_state(ctx, 1);
6368 check_cp1_enabled(ctx);
6369 op1 = MASK_CP3(ctx->opcode);
6377 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
6395 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
6399 generate_exception (ctx, EXCP_RI);
6403 generate_exception_err(ctx, EXCP_CpU, 1);
6407 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
6408 /* MIPS64 opcodes */
6410 case OPC_LDL ... OPC_LDR:
6411 case OPC_SDL ... OPC_SDR:
6416 check_insn(env, ctx, ISA_MIPS3);
6418 gen_ldst(ctx, op, rt, rs, imm);
6420 case OPC_DADDI ... OPC_DADDIU:
6421 check_insn(env, ctx, ISA_MIPS3);
6423 gen_arith_imm(env, ctx, op, rt, rs, imm);
6427 check_insn(env, ctx, ASE_MIPS16);
6428 /* MIPS16: Not implemented. */
6430 check_insn(env, ctx, ASE_MDMX);
6431 /* MDMX: Not implemented. */
6432 default: /* Invalid */
6433 MIPS_INVAL("major opcode");
6434 generate_exception(ctx, EXCP_RI);
6437 if (ctx->hflags & MIPS_HFLAG_BMASK) {
6438 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
6439 /* Branches completion */
6440 ctx->hflags &= ~MIPS_HFLAG_BMASK;
6441 ctx->bstate = BS_BRANCH;
6442 save_cpu_state(ctx, 0);
6445 /* unconditional branch */
6446 MIPS_DEBUG("unconditional branch");
6447 gen_goto_tb(ctx, 0, ctx->btarget);
6450 /* blikely taken case */
6451 MIPS_DEBUG("blikely branch taken");
6452 gen_goto_tb(ctx, 0, ctx->btarget);
6455 /* Conditional branch */
6456 MIPS_DEBUG("conditional branch");
6459 l1 = gen_new_label();
6461 gen_goto_tb(ctx, 1, ctx->pc + 4);
6463 gen_goto_tb(ctx, 0, ctx->btarget);
6467 /* unconditional branch to register */
6468 MIPS_DEBUG("branch to register");
6474 MIPS_DEBUG("unknown branch");
6481 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
6485 target_ulong pc_start;
6486 uint16_t *gen_opc_end;
6489 if (search_pc && loglevel)
6490 fprintf (logfile, "search pc %d\n", search_pc);
6493 gen_opc_ptr = gen_opc_buf;
6494 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
6495 gen_opparam_ptr = gen_opparam_buf;
6500 ctx.bstate = BS_NONE;
6501 /* Restore delay slot state from the tb context. */
6502 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
6503 restore_cpu_state(env, &ctx);
6504 #if defined(CONFIG_USER_ONLY)
6507 ctx.mem_idx = !((ctx.hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM);
6510 if (loglevel & CPU_LOG_TB_CPU) {
6511 fprintf(logfile, "------------------------------------------------\n");
6512 /* FIXME: This may print out stale hflags from env... */
6513 cpu_dump_state(env, logfile, fprintf, 0);
6516 #ifdef MIPS_DEBUG_DISAS
6517 if (loglevel & CPU_LOG_TB_IN_ASM)
6518 fprintf(logfile, "\ntb %p super %d cond %04x\n",
6519 tb, ctx.mem_idx, ctx.hflags);
6521 while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) {
6522 if (env->nb_breakpoints > 0) {
6523 for(j = 0; j < env->nb_breakpoints; j++) {
6524 if (env->breakpoints[j] == ctx.pc) {
6525 save_cpu_state(&ctx, 1);
6526 ctx.bstate = BS_BRANCH;
6528 /* Include the breakpoint location or the tb won't
6529 * be flushed when it must be. */
6531 goto done_generating;
6537 j = gen_opc_ptr - gen_opc_buf;
6541 gen_opc_instr_start[lj++] = 0;
6543 gen_opc_pc[lj] = ctx.pc;
6544 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
6545 gen_opc_instr_start[lj] = 1;
6547 ctx.opcode = ldl_code(ctx.pc);
6548 decode_opc(env, &ctx);
6551 if (env->singlestep_enabled)
6554 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
6557 #if defined (MIPS_SINGLE_STEP)
6561 if (env->singlestep_enabled) {
6562 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
6565 switch (ctx.bstate) {
6567 gen_op_interrupt_restart();
6568 gen_goto_tb(&ctx, 0, ctx.pc);
6571 save_cpu_state(&ctx, 0);
6572 gen_goto_tb(&ctx, 0, ctx.pc);
6575 gen_op_interrupt_restart();
6585 *gen_opc_ptr = INDEX_op_end;
6587 j = gen_opc_ptr - gen_opc_buf;
6590 gen_opc_instr_start[lj++] = 0;
6592 tb->size = ctx.pc - pc_start;
6595 #if defined MIPS_DEBUG_DISAS
6596 if (loglevel & CPU_LOG_TB_IN_ASM)
6597 fprintf(logfile, "\n");
6599 if (loglevel & CPU_LOG_TB_IN_ASM) {
6600 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
6601 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
6602 fprintf(logfile, "\n");
6604 if (loglevel & CPU_LOG_TB_OP) {
6605 fprintf(logfile, "OP:\n");
6606 dump_ops(gen_opc_buf, gen_opparam_buf);
6607 fprintf(logfile, "\n");
6609 if (loglevel & CPU_LOG_TB_CPU) {
6610 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
6617 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
6619 return gen_intermediate_code_internal(env, tb, 0);
6622 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
6624 return gen_intermediate_code_internal(env, tb, 1);
6627 void fpu_dump_state(CPUState *env, FILE *f,
6628 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
6632 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
6634 #define printfpr(fp) \
6637 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
6638 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
6639 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6642 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6643 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6644 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6645 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6646 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6651 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6652 env->fpu->fcr0, env->fpu->fcr31, is_fpu64, env->fpu->fp_status,
6653 get_float_exception_flags(&env->fpu->fp_status));
6654 fpu_fprintf(f, "FT0: "); printfpr(&env->fpu->ft0);
6655 fpu_fprintf(f, "FT1: "); printfpr(&env->fpu->ft1);
6656 fpu_fprintf(f, "FT2: "); printfpr(&env->fpu->ft2);
6657 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
6658 fpu_fprintf(f, "%3s: ", fregnames[i]);
6659 printfpr(&env->fpu->fpr[i]);
6665 void dump_fpu (CPUState *env)
6668 fprintf(logfile, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " %d\n",
6669 env->PC[env->current_tc], env->HI[0][env->current_tc], env->LO[0][env->current_tc], env->hflags, env->btarget, env->bcond);
6670 fpu_dump_state(env, logfile, fprintf, 0);
6674 #if (defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6675 /* Debug help: The architecture requires 32bit code to maintain proper
6676 sign-extened values on 64bit machines. */
6678 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6680 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
6681 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6686 if (!SIGN_EXT_P(env->PC[env->current_tc]))
6687 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->PC[env->current_tc]);
6688 if (!SIGN_EXT_P(env->HI[env->current_tc]))
6689 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->HI[env->current_tc]);
6690 if (!SIGN_EXT_P(env->LO[env->current_tc]))
6691 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->LO[env->current_tc]);
6692 if (!SIGN_EXT_P(env->btarget))
6693 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
6695 for (i = 0; i < 32; i++) {
6696 if (!SIGN_EXT_P(env->gpr[i][env->current_tc]))
6697 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->gpr[i][env->current_tc]);
6700 if (!SIGN_EXT_P(env->CP0_EPC))
6701 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
6702 if (!SIGN_EXT_P(env->CP0_LLAddr))
6703 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
6707 void cpu_dump_state (CPUState *env, FILE *f,
6708 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6713 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",
6714 env->PC[env->current_tc], env->HI[env->current_tc], env->LO[env->current_tc], env->hflags, env->btarget, env->bcond);
6715 for (i = 0; i < 32; i++) {
6717 cpu_fprintf(f, "GPR%02d:", i);
6718 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->gpr[i][env->current_tc]);
6720 cpu_fprintf(f, "\n");
6723 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
6724 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
6725 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
6726 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
6727 if (env->hflags & MIPS_HFLAG_FPU)
6728 fpu_dump_state(env, f, cpu_fprintf, flags);
6729 #if (defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6730 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
6734 CPUMIPSState *cpu_mips_init (void)
6738 env = qemu_mallocz(sizeof(CPUMIPSState));
6746 void cpu_reset (CPUMIPSState *env)
6748 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
6753 #if !defined(CONFIG_USER_ONLY)
6754 if (env->hflags & MIPS_HFLAG_BMASK) {
6755 /* If the exception was raised from a delay slot,
6756 * come back to the jump. */
6757 env->CP0_ErrorEPC = env->PC[env->current_tc] - 4;
6759 env->CP0_ErrorEPC = env->PC[env->current_tc];
6761 env->PC[env->current_tc] = (int32_t)0xBFC00000;
6763 /* SMP not implemented */
6764 env->CP0_EBase = 0x80000000;
6765 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
6766 /* vectored interrupts not implemented, timer on int 7,
6767 no performance counters. */
6768 env->CP0_IntCtl = 0xe0000000;
6772 for (i = 0; i < 7; i++) {
6773 env->CP0_WatchLo[i] = 0;
6774 env->CP0_WatchHi[i] = 0x80000000;
6776 env->CP0_WatchLo[7] = 0;
6777 env->CP0_WatchHi[7] = 0;
6779 /* Count register increments in debug mode, EJTAG version 1 */
6780 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
6782 env->exception_index = EXCP_NONE;
6783 #if defined(CONFIG_USER_ONLY)
6784 env->hflags = MIPS_HFLAG_UM;
6785 env->user_mode_only = 1;
6787 env->hflags = MIPS_HFLAG_CP0;
6791 #include "translate_init.c"