2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 //#define MIPS_DEBUG_DISAS
34 //#define MIPS_DEBUG_SIGN_EXTENSIONS
35 //#define MIPS_SINGLE_STEP
37 #ifdef USE_DIRECT_JUMP
40 #define TBPARAM(x) (long)(x)
44 #define DEF(s, n, copy_size) INDEX_op_ ## s,
50 static uint16_t *gen_opc_ptr;
51 static uint32_t *gen_opparam_ptr;
55 /* MIPS major opcodes */
56 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
59 /* indirect opcode tables */
60 OPC_SPECIAL = (0x00 << 26),
61 OPC_REGIMM = (0x01 << 26),
62 OPC_CP0 = (0x10 << 26),
63 OPC_CP1 = (0x11 << 26),
64 OPC_CP2 = (0x12 << 26),
65 OPC_CP3 = (0x13 << 26),
66 OPC_SPECIAL2 = (0x1C << 26),
67 OPC_SPECIAL3 = (0x1F << 26),
68 /* arithmetic with immediate */
69 OPC_ADDI = (0x08 << 26),
70 OPC_ADDIU = (0x09 << 26),
71 OPC_SLTI = (0x0A << 26),
72 OPC_SLTIU = (0x0B << 26),
73 OPC_ANDI = (0x0C << 26),
74 OPC_ORI = (0x0D << 26),
75 OPC_XORI = (0x0E << 26),
76 OPC_LUI = (0x0F << 26),
77 OPC_DADDI = (0x18 << 26),
78 OPC_DADDIU = (0x19 << 26),
79 /* Jump and branches */
81 OPC_JAL = (0x03 << 26),
82 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
83 OPC_BEQL = (0x14 << 26),
84 OPC_BNE = (0x05 << 26),
85 OPC_BNEL = (0x15 << 26),
86 OPC_BLEZ = (0x06 << 26),
87 OPC_BLEZL = (0x16 << 26),
88 OPC_BGTZ = (0x07 << 26),
89 OPC_BGTZL = (0x17 << 26),
90 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
92 OPC_LDL = (0x1A << 26),
93 OPC_LDR = (0x1B << 26),
94 OPC_LB = (0x20 << 26),
95 OPC_LH = (0x21 << 26),
96 OPC_LWL = (0x22 << 26),
97 OPC_LW = (0x23 << 26),
98 OPC_LBU = (0x24 << 26),
99 OPC_LHU = (0x25 << 26),
100 OPC_LWR = (0x26 << 26),
101 OPC_LWU = (0x27 << 26),
102 OPC_SB = (0x28 << 26),
103 OPC_SH = (0x29 << 26),
104 OPC_SWL = (0x2A << 26),
105 OPC_SW = (0x2B << 26),
106 OPC_SDL = (0x2C << 26),
107 OPC_SDR = (0x2D << 26),
108 OPC_SWR = (0x2E << 26),
109 OPC_LL = (0x30 << 26),
110 OPC_LLD = (0x34 << 26),
111 OPC_LD = (0x37 << 26),
112 OPC_SC = (0x38 << 26),
113 OPC_SCD = (0x3C << 26),
114 OPC_SD = (0x3F << 26),
115 /* Floating point load/store */
116 OPC_LWC1 = (0x31 << 26),
117 OPC_LWC2 = (0x32 << 26),
118 OPC_LDC1 = (0x35 << 26),
119 OPC_LDC2 = (0x36 << 26),
120 OPC_SWC1 = (0x39 << 26),
121 OPC_SWC2 = (0x3A << 26),
122 OPC_SDC1 = (0x3D << 26),
123 OPC_SDC2 = (0x3E << 26),
124 /* MDMX ASE specific */
125 OPC_MDMX = (0x1E << 26),
126 /* Cache and prefetch */
127 OPC_CACHE = (0x2F << 26),
128 OPC_PREF = (0x33 << 26),
129 /* Reserved major opcode */
130 OPC_MAJOR3B_RESERVED = (0x3B << 26),
133 /* MIPS special opcodes */
134 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
138 OPC_SLL = 0x00 | OPC_SPECIAL,
139 /* NOP is SLL r0, r0, 0 */
140 /* SSNOP is SLL r0, r0, 1 */
141 /* EHB is SLL r0, r0, 3 */
142 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
143 OPC_SRA = 0x03 | OPC_SPECIAL,
144 OPC_SLLV = 0x04 | OPC_SPECIAL,
145 OPC_SRLV = 0x06 | OPC_SPECIAL,
146 OPC_SRAV = 0x07 | OPC_SPECIAL,
147 OPC_DSLLV = 0x14 | OPC_SPECIAL,
148 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
149 OPC_DSRAV = 0x17 | OPC_SPECIAL,
150 OPC_DSLL = 0x38 | OPC_SPECIAL,
151 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
152 OPC_DSRA = 0x3B | OPC_SPECIAL,
153 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
154 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
155 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
156 /* Multiplication / division */
157 OPC_MULT = 0x18 | OPC_SPECIAL,
158 OPC_MULTU = 0x19 | OPC_SPECIAL,
159 OPC_DIV = 0x1A | OPC_SPECIAL,
160 OPC_DIVU = 0x1B | OPC_SPECIAL,
161 OPC_DMULT = 0x1C | OPC_SPECIAL,
162 OPC_DMULTU = 0x1D | OPC_SPECIAL,
163 OPC_DDIV = 0x1E | OPC_SPECIAL,
164 OPC_DDIVU = 0x1F | OPC_SPECIAL,
165 /* 2 registers arithmetic / logic */
166 OPC_ADD = 0x20 | OPC_SPECIAL,
167 OPC_ADDU = 0x21 | OPC_SPECIAL,
168 OPC_SUB = 0x22 | OPC_SPECIAL,
169 OPC_SUBU = 0x23 | OPC_SPECIAL,
170 OPC_AND = 0x24 | OPC_SPECIAL,
171 OPC_OR = 0x25 | OPC_SPECIAL,
172 OPC_XOR = 0x26 | OPC_SPECIAL,
173 OPC_NOR = 0x27 | OPC_SPECIAL,
174 OPC_SLT = 0x2A | OPC_SPECIAL,
175 OPC_SLTU = 0x2B | OPC_SPECIAL,
176 OPC_DADD = 0x2C | OPC_SPECIAL,
177 OPC_DADDU = 0x2D | OPC_SPECIAL,
178 OPC_DSUB = 0x2E | OPC_SPECIAL,
179 OPC_DSUBU = 0x2F | OPC_SPECIAL,
181 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
182 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
184 OPC_TGE = 0x30 | OPC_SPECIAL,
185 OPC_TGEU = 0x31 | OPC_SPECIAL,
186 OPC_TLT = 0x32 | OPC_SPECIAL,
187 OPC_TLTU = 0x33 | OPC_SPECIAL,
188 OPC_TEQ = 0x34 | OPC_SPECIAL,
189 OPC_TNE = 0x36 | OPC_SPECIAL,
190 /* HI / LO registers load & stores */
191 OPC_MFHI = 0x10 | OPC_SPECIAL,
192 OPC_MTHI = 0x11 | OPC_SPECIAL,
193 OPC_MFLO = 0x12 | OPC_SPECIAL,
194 OPC_MTLO = 0x13 | OPC_SPECIAL,
195 /* Conditional moves */
196 OPC_MOVZ = 0x0A | OPC_SPECIAL,
197 OPC_MOVN = 0x0B | OPC_SPECIAL,
199 OPC_MOVCI = 0x01 | OPC_SPECIAL,
202 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
203 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
204 OPC_BREAK = 0x0D | OPC_SPECIAL,
205 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
206 OPC_SYNC = 0x0F | OPC_SPECIAL,
208 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
209 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
210 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
211 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
212 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
213 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
214 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
217 /* REGIMM (rt field) opcodes */
218 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
221 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
222 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
223 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
224 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
225 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
226 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
227 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
228 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
229 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
230 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
231 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
232 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
233 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
234 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
235 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
238 /* Special2 opcodes */
239 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
242 /* Multiply & xxx operations */
243 OPC_MADD = 0x00 | OPC_SPECIAL2,
244 OPC_MADDU = 0x01 | OPC_SPECIAL2,
245 OPC_MUL = 0x02 | OPC_SPECIAL2,
246 OPC_MSUB = 0x04 | OPC_SPECIAL2,
247 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
249 OPC_CLZ = 0x20 | OPC_SPECIAL2,
250 OPC_CLO = 0x21 | OPC_SPECIAL2,
251 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
252 OPC_DCLO = 0x25 | OPC_SPECIAL2,
254 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
257 /* Special3 opcodes */
258 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
261 OPC_EXT = 0x00 | OPC_SPECIAL3,
262 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
263 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
264 OPC_DEXT = 0x03 | OPC_SPECIAL3,
265 OPC_INS = 0x04 | OPC_SPECIAL3,
266 OPC_DINSM = 0x05 | OPC_SPECIAL3,
267 OPC_DINSU = 0x06 | OPC_SPECIAL3,
268 OPC_DINS = 0x07 | OPC_SPECIAL3,
269 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
270 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
271 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
275 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
278 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
279 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
280 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
284 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
287 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
288 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
291 /* Coprocessor 0 (rs field) */
292 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
295 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
296 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
297 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
298 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
299 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
300 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
301 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
302 OPC_C0 = (0x10 << 21) | OPC_CP0,
303 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
304 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
308 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
311 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
312 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
315 /* Coprocessor 0 (with rs == C0) */
316 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
319 OPC_TLBR = 0x01 | OPC_C0,
320 OPC_TLBWI = 0x02 | OPC_C0,
321 OPC_TLBWR = 0x06 | OPC_C0,
322 OPC_TLBP = 0x08 | OPC_C0,
323 OPC_RFE = 0x10 | OPC_C0,
324 OPC_ERET = 0x18 | OPC_C0,
325 OPC_DERET = 0x1F | OPC_C0,
326 OPC_WAIT = 0x20 | OPC_C0,
329 /* Coprocessor 1 (rs field) */
330 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
333 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
334 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
335 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
336 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
337 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
338 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
339 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
340 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
341 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
342 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
343 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
344 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
345 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
346 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
347 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
348 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
349 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
350 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
353 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
354 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
357 OPC_BC1F = (0x00 << 16) | OPC_BC1,
358 OPC_BC1T = (0x01 << 16) | OPC_BC1,
359 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
360 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
364 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
365 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
369 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
370 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
373 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
376 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
377 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
378 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
379 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
380 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
381 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
382 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
383 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
384 OPC_BC2 = (0x08 << 21) | OPC_CP2,
387 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
390 OPC_LWXC1 = 0x00 | OPC_CP3,
391 OPC_LDXC1 = 0x01 | OPC_CP3,
392 OPC_LUXC1 = 0x05 | OPC_CP3,
393 OPC_SWXC1 = 0x08 | OPC_CP3,
394 OPC_SDXC1 = 0x09 | OPC_CP3,
395 OPC_SUXC1 = 0x0D | OPC_CP3,
396 OPC_PREFX = 0x0F | OPC_CP3,
397 OPC_ALNV_PS = 0x1E | OPC_CP3,
398 OPC_MADD_S = 0x20 | OPC_CP3,
399 OPC_MADD_D = 0x21 | OPC_CP3,
400 OPC_MADD_PS = 0x26 | OPC_CP3,
401 OPC_MSUB_S = 0x28 | OPC_CP3,
402 OPC_MSUB_D = 0x29 | OPC_CP3,
403 OPC_MSUB_PS = 0x2E | OPC_CP3,
404 OPC_NMADD_S = 0x30 | OPC_CP3,
405 OPC_NMADD_D = 0x31 | OPC_CP3,
406 OPC_NMADD_PS= 0x36 | OPC_CP3,
407 OPC_NMSUB_S = 0x38 | OPC_CP3,
408 OPC_NMSUB_D = 0x39 | OPC_CP3,
409 OPC_NMSUB_PS= 0x3E | OPC_CP3,
413 const unsigned char *regnames[] =
414 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
415 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
416 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
417 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
419 /* Warning: no function for r0 register (hard wired to zero) */
420 #define GEN32(func, NAME) \
421 static GenOpFunc *NAME ## _table [32] = { \
422 NULL, NAME ## 1, NAME ## 2, NAME ## 3, \
423 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
424 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
425 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
426 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
427 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
428 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
429 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
431 static inline void func(int n) \
433 NAME ## _table[n](); \
436 /* General purpose registers moves */
437 GEN32(gen_op_load_gpr_T0, gen_op_load_gpr_T0_gpr);
438 GEN32(gen_op_load_gpr_T1, gen_op_load_gpr_T1_gpr);
439 GEN32(gen_op_load_gpr_T2, gen_op_load_gpr_T2_gpr);
441 GEN32(gen_op_store_T0_gpr, gen_op_store_T0_gpr_gpr);
442 GEN32(gen_op_store_T1_gpr, gen_op_store_T1_gpr_gpr);
444 static const char *fregnames[] =
445 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
446 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
447 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
448 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
450 #define FGEN32(func, NAME) \
451 static GenOpFunc *NAME ## _table [32] = { \
452 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
453 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
454 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
455 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
456 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
457 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
458 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
459 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
461 static inline void func(int n) \
463 NAME ## _table[n](); \
466 FGEN32(gen_op_load_fpr_WT0, gen_op_load_fpr_WT0_fpr);
467 FGEN32(gen_op_store_fpr_WT0, gen_op_store_fpr_WT0_fpr);
469 FGEN32(gen_op_load_fpr_WT1, gen_op_load_fpr_WT1_fpr);
470 FGEN32(gen_op_store_fpr_WT1, gen_op_store_fpr_WT1_fpr);
472 FGEN32(gen_op_load_fpr_WT2, gen_op_load_fpr_WT2_fpr);
473 FGEN32(gen_op_store_fpr_WT2, gen_op_store_fpr_WT2_fpr);
475 FGEN32(gen_op_load_fpr_DT0, gen_op_load_fpr_DT0_fpr);
476 FGEN32(gen_op_store_fpr_DT0, gen_op_store_fpr_DT0_fpr);
478 FGEN32(gen_op_load_fpr_DT1, gen_op_load_fpr_DT1_fpr);
479 FGEN32(gen_op_store_fpr_DT1, gen_op_store_fpr_DT1_fpr);
481 FGEN32(gen_op_load_fpr_DT2, gen_op_load_fpr_DT2_fpr);
482 FGEN32(gen_op_store_fpr_DT2, gen_op_store_fpr_DT2_fpr);
484 FGEN32(gen_op_load_fpr_WTH0, gen_op_load_fpr_WTH0_fpr);
485 FGEN32(gen_op_store_fpr_WTH0, gen_op_store_fpr_WTH0_fpr);
487 FGEN32(gen_op_load_fpr_WTH1, gen_op_load_fpr_WTH1_fpr);
488 FGEN32(gen_op_store_fpr_WTH1, gen_op_store_fpr_WTH1_fpr);
490 FGEN32(gen_op_load_fpr_WTH2, gen_op_load_fpr_WTH2_fpr);
491 FGEN32(gen_op_store_fpr_WTH2, gen_op_store_fpr_WTH2_fpr);
493 #define FOP_CONDS(type, fmt) \
494 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
495 gen_op_cmp ## type ## _ ## fmt ## _f, \
496 gen_op_cmp ## type ## _ ## fmt ## _un, \
497 gen_op_cmp ## type ## _ ## fmt ## _eq, \
498 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
499 gen_op_cmp ## type ## _ ## fmt ## _olt, \
500 gen_op_cmp ## type ## _ ## fmt ## _ult, \
501 gen_op_cmp ## type ## _ ## fmt ## _ole, \
502 gen_op_cmp ## type ## _ ## fmt ## _ule, \
503 gen_op_cmp ## type ## _ ## fmt ## _sf, \
504 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
505 gen_op_cmp ## type ## _ ## fmt ## _seq, \
506 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
507 gen_op_cmp ## type ## _ ## fmt ## _lt, \
508 gen_op_cmp ## type ## _ ## fmt ## _nge, \
509 gen_op_cmp ## type ## _ ## fmt ## _le, \
510 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
512 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
514 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
524 typedef struct DisasContext {
525 struct TranslationBlock *tb;
526 target_ulong pc, saved_pc;
529 /* Routine used to access memory */
531 uint32_t hflags, saved_hflags;
533 target_ulong btarget;
537 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
538 * exception condition
540 BS_STOP = 1, /* We want to stop translation for any reason */
541 BS_BRANCH = 2, /* We reached a branch condition */
542 BS_EXCP = 3, /* We reached an exception condition */
545 #ifdef MIPS_DEBUG_DISAS
546 #define MIPS_DEBUG(fmt, args...) \
548 if (loglevel & CPU_LOG_TB_IN_ASM) { \
549 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
550 ctx->pc, ctx->opcode , ##args); \
554 #define MIPS_DEBUG(fmt, args...) do { } while(0)
557 #define MIPS_INVAL(op) \
559 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
560 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
563 #define GEN_LOAD_REG_TN(Tn, Rn) \
566 glue(gen_op_reset_, Tn)(); \
568 glue(gen_op_load_gpr_, Tn)(Rn); \
573 #define GEN_LOAD_IMM_TN(Tn, Imm) \
576 glue(gen_op_reset_, Tn)(); \
577 } else if ((int32_t)Imm == Imm) { \
578 glue(gen_op_set_, Tn)(Imm); \
580 glue(gen_op_set64_, Tn)(((uint64_t)Imm) >> 32, (uint32_t)Imm); \
584 #define GEN_LOAD_IMM_TN(Tn, Imm) \
587 glue(gen_op_reset_, Tn)(); \
589 glue(gen_op_set_, Tn)(Imm); \
594 #define GEN_STORE_TN_REG(Rn, Tn) \
597 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
601 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
603 glue(gen_op_load_fpr_, FTn)(Fn); \
606 #define GEN_STORE_FTN_FREG(Fn, FTn) \
608 glue(gen_op_store_fpr_, FTn)(Fn); \
611 static inline void gen_save_pc(target_ulong pc)
614 if (pc == (int32_t)pc) {
617 gen_op_save_pc64(pc >> 32, (uint32_t)pc);
624 static inline void gen_save_btarget(target_ulong btarget)
627 if (btarget == (int32_t)btarget) {
628 gen_op_save_btarget(btarget);
630 gen_op_save_btarget64(btarget >> 32, (uint32_t)btarget);
633 gen_op_save_btarget(btarget);
637 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
639 #if defined MIPS_DEBUG_DISAS
640 if (loglevel & CPU_LOG_TB_IN_ASM) {
641 fprintf(logfile, "hflags %08x saved %08x\n",
642 ctx->hflags, ctx->saved_hflags);
645 if (do_save_pc && ctx->pc != ctx->saved_pc) {
646 gen_save_pc(ctx->pc);
647 ctx->saved_pc = ctx->pc;
649 if (ctx->hflags != ctx->saved_hflags) {
650 gen_op_save_state(ctx->hflags);
651 ctx->saved_hflags = ctx->hflags;
652 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
654 gen_op_save_breg_target();
660 /* bcond was already saved by the BL insn */
663 gen_save_btarget(ctx->btarget);
669 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
671 ctx->saved_hflags = ctx->hflags;
672 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
674 gen_op_restore_breg_target();
677 ctx->btarget = env->btarget;
681 ctx->btarget = env->btarget;
682 gen_op_restore_bcond();
687 static inline void generate_exception_err (DisasContext *ctx, int excp, int err)
689 #if defined MIPS_DEBUG_DISAS
690 if (loglevel & CPU_LOG_TB_IN_ASM)
691 fprintf(logfile, "%s: raise exception %d\n", __func__, excp);
693 save_cpu_state(ctx, 1);
695 gen_op_raise_exception(excp);
697 gen_op_raise_exception_err(excp, err);
698 ctx->bstate = BS_EXCP;
701 static inline void generate_exception (DisasContext *ctx, int excp)
703 generate_exception_err (ctx, excp, 0);
706 static inline void check_cp1_enabled(DisasContext *ctx)
708 if (!(ctx->hflags & MIPS_HFLAG_FPU))
709 generate_exception_err(ctx, EXCP_CpU, 1);
712 static inline void check_cp1_64bitmode(DisasContext *ctx)
714 if (!(ctx->hflags & MIPS_HFLAG_F64))
715 generate_exception(ctx, EXCP_RI);
719 * Verify if floating point register is valid; an operation is not defined
720 * if bit 0 of any register specification is set and the FR bit in the
721 * Status register equals zero, since the register numbers specify an
722 * even-odd pair of adjacent coprocessor general registers. When the FR bit
723 * in the Status register equals one, both even and odd register numbers
724 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
726 * Multiple 64 bit wide registers can be checked by calling
727 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
729 void check_cp1_registers(DisasContext *ctx, int regs)
731 if (!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1))
732 generate_exception(ctx, EXCP_RI);
735 #if defined(CONFIG_USER_ONLY)
736 #define op_ldst(name) gen_op_##name##_raw()
737 #define OP_LD_TABLE(width)
738 #define OP_ST_TABLE(width)
740 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
741 #define OP_LD_TABLE(width) \
742 static GenOpFunc *gen_op_l##width[] = { \
743 &gen_op_l##width##_user, \
744 &gen_op_l##width##_kernel, \
746 #define OP_ST_TABLE(width) \
747 static GenOpFunc *gen_op_s##width[] = { \
748 &gen_op_s##width##_user, \
749 &gen_op_s##width##_kernel, \
786 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
787 int base, int16_t offset)
789 const char *opn = "ldst";
792 GEN_LOAD_IMM_TN(T0, offset);
793 } else if (offset == 0) {
794 gen_op_load_gpr_T0(base);
796 gen_op_load_gpr_T0(base);
797 gen_op_set_T1(offset);
800 /* Don't do NOP if destination is zero: we must perform the actual
807 GEN_STORE_TN_REG(rt, T0);
812 GEN_STORE_TN_REG(rt, T0);
817 GEN_STORE_TN_REG(rt, T0);
821 GEN_LOAD_REG_TN(T1, rt);
826 save_cpu_state(ctx, 1);
827 GEN_LOAD_REG_TN(T1, rt);
829 GEN_STORE_TN_REG(rt, T0);
833 GEN_LOAD_REG_TN(T1, rt);
835 GEN_STORE_TN_REG(rt, T0);
839 GEN_LOAD_REG_TN(T1, rt);
844 GEN_LOAD_REG_TN(T1, rt);
846 GEN_STORE_TN_REG(rt, T0);
850 GEN_LOAD_REG_TN(T1, rt);
857 GEN_STORE_TN_REG(rt, T0);
861 GEN_LOAD_REG_TN(T1, rt);
867 GEN_STORE_TN_REG(rt, T0);
871 GEN_LOAD_REG_TN(T1, rt);
877 GEN_STORE_TN_REG(rt, T0);
882 GEN_STORE_TN_REG(rt, T0);
886 GEN_LOAD_REG_TN(T1, rt);
892 GEN_STORE_TN_REG(rt, T0);
896 GEN_LOAD_REG_TN(T1, rt);
898 GEN_STORE_TN_REG(rt, T0);
902 GEN_LOAD_REG_TN(T1, rt);
907 GEN_LOAD_REG_TN(T1, rt);
909 GEN_STORE_TN_REG(rt, T0);
913 GEN_LOAD_REG_TN(T1, rt);
919 GEN_STORE_TN_REG(rt, T0);
923 save_cpu_state(ctx, 1);
924 GEN_LOAD_REG_TN(T1, rt);
926 GEN_STORE_TN_REG(rt, T0);
931 generate_exception(ctx, EXCP_RI);
934 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
938 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
939 int base, int16_t offset)
941 const char *opn = "flt_ldst";
944 GEN_LOAD_IMM_TN(T0, offset);
945 } else if (offset == 0) {
946 gen_op_load_gpr_T0(base);
948 gen_op_load_gpr_T0(base);
949 gen_op_set_T1(offset);
952 /* Don't do NOP if destination is zero: we must perform the actual
958 GEN_STORE_FTN_FREG(ft, WT0);
962 GEN_LOAD_FREG_FTN(WT0, ft);
968 GEN_STORE_FTN_FREG(ft, DT0);
972 GEN_LOAD_FREG_FTN(DT0, ft);
978 generate_exception(ctx, EXCP_RI);
981 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
984 /* Arithmetic with immediate operand */
985 static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
989 const char *opn = "imm arith";
991 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
992 /* if no destination, treat it as a NOP
993 * For addi, we must generate the overflow exception when needed.
998 uimm = (uint16_t)imm;
1002 #ifdef TARGET_MIPS64
1008 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1013 GEN_LOAD_REG_TN(T0, rs);
1014 GEN_LOAD_IMM_TN(T1, uimm);
1017 GEN_LOAD_IMM_TN(T0, imm << 16);
1022 #ifdef TARGET_MIPS64
1031 GEN_LOAD_REG_TN(T0, rs);
1032 GEN_LOAD_IMM_TN(T1, uimm);
1037 save_cpu_state(ctx, 1);
1045 #ifdef TARGET_MIPS64
1047 save_cpu_state(ctx, 1);
1088 switch ((ctx->opcode >> 21) & 0x1f) {
1098 MIPS_INVAL("invalid srl flag");
1099 generate_exception(ctx, EXCP_RI);
1103 #ifdef TARGET_MIPS64
1113 switch ((ctx->opcode >> 21) & 0x1f) {
1123 MIPS_INVAL("invalid dsrl flag");
1124 generate_exception(ctx, EXCP_RI);
1137 switch ((ctx->opcode >> 21) & 0x1f) {
1147 MIPS_INVAL("invalid dsrl32 flag");
1148 generate_exception(ctx, EXCP_RI);
1155 generate_exception(ctx, EXCP_RI);
1158 GEN_STORE_TN_REG(rt, T0);
1159 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1163 static void gen_arith (DisasContext *ctx, uint32_t opc,
1164 int rd, int rs, int rt)
1166 const char *opn = "arith";
1168 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1169 && opc != OPC_DADD && opc != OPC_DSUB) {
1170 /* if no destination, treat it as a NOP
1171 * For add & sub, we must generate the overflow exception when needed.
1176 GEN_LOAD_REG_TN(T0, rs);
1177 GEN_LOAD_REG_TN(T1, rt);
1180 save_cpu_state(ctx, 1);
1189 save_cpu_state(ctx, 1);
1197 #ifdef TARGET_MIPS64
1199 save_cpu_state(ctx, 1);
1208 save_cpu_state(ctx, 1);
1262 switch ((ctx->opcode >> 6) & 0x1f) {
1272 MIPS_INVAL("invalid srlv flag");
1273 generate_exception(ctx, EXCP_RI);
1277 #ifdef TARGET_MIPS64
1287 switch ((ctx->opcode >> 6) & 0x1f) {
1297 MIPS_INVAL("invalid dsrlv flag");
1298 generate_exception(ctx, EXCP_RI);
1305 generate_exception(ctx, EXCP_RI);
1308 GEN_STORE_TN_REG(rd, T0);
1310 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1313 /* Arithmetic on HI/LO registers */
1314 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1316 const char *opn = "hilo";
1318 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1319 /* Treat as a NOP */
1326 GEN_STORE_TN_REG(reg, T0);
1331 GEN_STORE_TN_REG(reg, T0);
1335 GEN_LOAD_REG_TN(T0, reg);
1340 GEN_LOAD_REG_TN(T0, reg);
1346 generate_exception(ctx, EXCP_RI);
1349 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1352 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1355 const char *opn = "mul/div";
1357 GEN_LOAD_REG_TN(T0, rs);
1358 GEN_LOAD_REG_TN(T1, rt);
1376 #ifdef TARGET_MIPS64
1412 generate_exception(ctx, EXCP_RI);
1415 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
1418 static void gen_cl (DisasContext *ctx, uint32_t opc,
1421 const char *opn = "CLx";
1423 /* Treat as a NOP */
1427 GEN_LOAD_REG_TN(T0, rs);
1437 #ifdef TARGET_MIPS64
1449 generate_exception(ctx, EXCP_RI);
1452 gen_op_store_T0_gpr(rd);
1453 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
1457 static void gen_trap (DisasContext *ctx, uint32_t opc,
1458 int rs, int rt, int16_t imm)
1463 /* Load needed operands */
1471 /* Compare two registers */
1473 GEN_LOAD_REG_TN(T0, rs);
1474 GEN_LOAD_REG_TN(T1, rt);
1484 /* Compare register to immediate */
1485 if (rs != 0 || imm != 0) {
1486 GEN_LOAD_REG_TN(T0, rs);
1487 GEN_LOAD_IMM_TN(T1, (int32_t)imm);
1494 case OPC_TEQ: /* rs == rs */
1495 case OPC_TEQI: /* r0 == 0 */
1496 case OPC_TGE: /* rs >= rs */
1497 case OPC_TGEI: /* r0 >= 0 */
1498 case OPC_TGEU: /* rs >= rs unsigned */
1499 case OPC_TGEIU: /* r0 >= 0 unsigned */
1503 case OPC_TLT: /* rs < rs */
1504 case OPC_TLTI: /* r0 < 0 */
1505 case OPC_TLTU: /* rs < rs unsigned */
1506 case OPC_TLTIU: /* r0 < 0 unsigned */
1507 case OPC_TNE: /* rs != rs */
1508 case OPC_TNEI: /* r0 != 0 */
1509 /* Never trap: treat as NOP */
1513 generate_exception(ctx, EXCP_RI);
1544 generate_exception(ctx, EXCP_RI);
1548 save_cpu_state(ctx, 1);
1550 ctx->bstate = BS_STOP;
1553 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
1555 TranslationBlock *tb;
1557 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
1559 gen_op_goto_tb0(TBPARAM(tb));
1561 gen_op_goto_tb1(TBPARAM(tb));
1563 gen_op_set_T0((long)tb + n);
1571 /* Branches (before delay slot) */
1572 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
1573 int rs, int rt, int32_t offset)
1575 target_ulong btarget = -1;
1579 if (ctx->hflags & MIPS_HFLAG_BMASK) {
1580 #ifdef MIPS_DEBUG_DISAS
1581 if (loglevel & CPU_LOG_TB_IN_ASM) {
1583 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
1587 generate_exception(ctx, EXCP_RI);
1591 /* Load needed operands */
1597 /* Compare two registers */
1599 GEN_LOAD_REG_TN(T0, rs);
1600 GEN_LOAD_REG_TN(T1, rt);
1603 btarget = ctx->pc + 4 + offset;
1617 /* Compare to zero */
1619 gen_op_load_gpr_T0(rs);
1622 btarget = ctx->pc + 4 + offset;
1626 /* Jump to immediate */
1627 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
1631 /* Jump to register */
1632 if (offset != 0 && offset != 16) {
1633 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1634 others are reserved. */
1635 MIPS_INVAL("jump hint");
1636 generate_exception(ctx, EXCP_RI);
1639 GEN_LOAD_REG_TN(T2, rs);
1642 MIPS_INVAL("branch/jump");
1643 generate_exception(ctx, EXCP_RI);
1647 /* No condition to be computed */
1649 case OPC_BEQ: /* rx == rx */
1650 case OPC_BEQL: /* rx == rx likely */
1651 case OPC_BGEZ: /* 0 >= 0 */
1652 case OPC_BGEZL: /* 0 >= 0 likely */
1653 case OPC_BLEZ: /* 0 <= 0 */
1654 case OPC_BLEZL: /* 0 <= 0 likely */
1656 ctx->hflags |= MIPS_HFLAG_B;
1657 MIPS_DEBUG("balways");
1659 case OPC_BGEZAL: /* 0 >= 0 */
1660 case OPC_BGEZALL: /* 0 >= 0 likely */
1661 /* Always take and link */
1663 ctx->hflags |= MIPS_HFLAG_B;
1664 MIPS_DEBUG("balways and link");
1666 case OPC_BNE: /* rx != rx */
1667 case OPC_BGTZ: /* 0 > 0 */
1668 case OPC_BLTZ: /* 0 < 0 */
1669 /* Treated as NOP */
1670 MIPS_DEBUG("bnever (NOP)");
1672 case OPC_BLTZAL: /* 0 < 0 */
1673 GEN_LOAD_IMM_TN(T0, ctx->pc + 8);
1674 gen_op_store_T0_gpr(31);
1675 MIPS_DEBUG("bnever and link");
1677 case OPC_BLTZALL: /* 0 < 0 likely */
1678 GEN_LOAD_IMM_TN(T0, ctx->pc + 8);
1679 gen_op_store_T0_gpr(31);
1680 /* Skip the instruction in the delay slot */
1681 MIPS_DEBUG("bnever, link and skip");
1684 case OPC_BNEL: /* rx != rx likely */
1685 case OPC_BGTZL: /* 0 > 0 likely */
1686 case OPC_BLTZL: /* 0 < 0 likely */
1687 /* Skip the instruction in the delay slot */
1688 MIPS_DEBUG("bnever and skip");
1692 ctx->hflags |= MIPS_HFLAG_B;
1693 MIPS_DEBUG("j " TARGET_FMT_lx, btarget);
1697 ctx->hflags |= MIPS_HFLAG_B;
1698 MIPS_DEBUG("jal " TARGET_FMT_lx, btarget);
1701 ctx->hflags |= MIPS_HFLAG_BR;
1702 MIPS_DEBUG("jr %s", regnames[rs]);
1706 ctx->hflags |= MIPS_HFLAG_BR;
1707 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
1710 MIPS_INVAL("branch/jump");
1711 generate_exception(ctx, EXCP_RI);
1718 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
1719 regnames[rs], regnames[rt], btarget);
1723 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
1724 regnames[rs], regnames[rt], btarget);
1728 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
1729 regnames[rs], regnames[rt], btarget);
1733 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
1734 regnames[rs], regnames[rt], btarget);
1738 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btarget);
1742 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1746 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btarget);
1752 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btarget);
1756 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btarget);
1760 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1764 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btarget);
1768 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1772 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btarget);
1776 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1781 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btarget);
1783 ctx->hflags |= MIPS_HFLAG_BC;
1789 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btarget);
1791 ctx->hflags |= MIPS_HFLAG_BL;
1793 gen_op_save_bcond();
1796 MIPS_INVAL("conditional branch/jump");
1797 generate_exception(ctx, EXCP_RI);
1801 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
1802 blink, ctx->hflags, btarget);
1804 ctx->btarget = btarget;
1806 GEN_LOAD_IMM_TN(T0, ctx->pc + 8);
1807 gen_op_store_T0_gpr(blink);
1811 /* special3 bitfield operations */
1812 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
1813 int rs, int lsb, int msb)
1815 GEN_LOAD_REG_TN(T1, rs);
1820 gen_op_ext(lsb, msb + 1);
1825 gen_op_ext(lsb, msb + 1 + 32);
1830 gen_op_ext(lsb + 32, msb + 1);
1833 gen_op_ext(lsb, msb + 1);
1838 GEN_LOAD_REG_TN(T0, rt);
1839 gen_op_ins(lsb, msb - lsb + 1);
1844 GEN_LOAD_REG_TN(T0, rt);
1845 gen_op_ins(lsb, msb - lsb + 1 + 32);
1850 GEN_LOAD_REG_TN(T0, rt);
1851 gen_op_ins(lsb + 32, msb - lsb + 1);
1856 GEN_LOAD_REG_TN(T0, rt);
1857 gen_op_ins(lsb, msb - lsb + 1);
1861 MIPS_INVAL("bitops");
1862 generate_exception(ctx, EXCP_RI);
1865 GEN_STORE_TN_REG(rt, T0);
1868 /* CP0 (MMU and control) */
1869 static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
1871 const char *rn = "invalid";
1877 gen_op_mfc0_index();
1881 // gen_op_mfc0_mvpcontrol(); /* MT ASE */
1885 // gen_op_mfc0_mvpconf0(); /* MT ASE */
1889 // gen_op_mfc0_mvpconf1(); /* MT ASE */
1899 gen_op_mfc0_random();
1903 // gen_op_mfc0_vpecontrol(); /* MT ASE */
1907 // gen_op_mfc0_vpeconf0(); /* MT ASE */
1911 // gen_op_mfc0_vpeconf1(); /* MT ASE */
1915 // gen_op_mfc0_YQMask(); /* MT ASE */
1919 // gen_op_mfc0_vpeschedule(); /* MT ASE */
1923 // gen_op_mfc0_vpeschefback(); /* MT ASE */
1924 rn = "VPEScheFBack";
1927 // gen_op_mfc0_vpeopt(); /* MT ASE */
1937 gen_op_mfc0_entrylo0();
1941 // gen_op_mfc0_tcstatus(); /* MT ASE */
1945 // gen_op_mfc0_tcbind(); /* MT ASE */
1949 // gen_op_mfc0_tcrestart(); /* MT ASE */
1953 // gen_op_mfc0_tchalt(); /* MT ASE */
1957 // gen_op_mfc0_tccontext(); /* MT ASE */
1961 // gen_op_mfc0_tcschedule(); /* MT ASE */
1965 // gen_op_mfc0_tcschefback(); /* MT ASE */
1975 gen_op_mfc0_entrylo1();
1985 gen_op_mfc0_context();
1989 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
1990 rn = "ContextConfig";
1999 gen_op_mfc0_pagemask();
2003 gen_op_mfc0_pagegrain();
2013 gen_op_mfc0_wired();
2017 // gen_op_mfc0_srsconf0(); /* shadow registers */
2021 // gen_op_mfc0_srsconf1(); /* shadow registers */
2025 // gen_op_mfc0_srsconf2(); /* shadow registers */
2029 // gen_op_mfc0_srsconf3(); /* shadow registers */
2033 // gen_op_mfc0_srsconf4(); /* shadow registers */
2043 gen_op_mfc0_hwrena();
2053 gen_op_mfc0_badvaddr();
2063 gen_op_mfc0_count();
2066 /* 6,7 are implementation dependent */
2074 gen_op_mfc0_entryhi();
2084 gen_op_mfc0_compare();
2087 /* 6,7 are implementation dependent */
2095 gen_op_mfc0_status();
2099 gen_op_mfc0_intctl();
2103 gen_op_mfc0_srsctl();
2107 gen_op_mfc0_srsmap();
2117 gen_op_mfc0_cause();
2141 gen_op_mfc0_ebase();
2151 gen_op_mfc0_config0();
2155 gen_op_mfc0_config1();
2159 gen_op_mfc0_config2();
2163 gen_op_mfc0_config3();
2166 /* 4,5 are reserved */
2167 /* 6,7 are implementation dependent */
2169 gen_op_mfc0_config6();
2173 gen_op_mfc0_config7();
2183 gen_op_mfc0_lladdr();
2193 gen_op_mfc0_watchlo(sel);
2203 gen_op_mfc0_watchhi(sel);
2213 #ifdef TARGET_MIPS64
2214 gen_op_mfc0_xcontext();
2223 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2226 gen_op_mfc0_framemask();
2235 rn = "'Diagnostic"; /* implementation dependent */
2240 gen_op_mfc0_debug(); /* EJTAG support */
2244 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2245 rn = "TraceControl";
2248 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2249 rn = "TraceControl2";
2252 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2253 rn = "UserTraceData";
2256 // gen_op_mfc0_debug(); /* PDtrace support */
2266 gen_op_mfc0_depc(); /* EJTAG support */
2276 gen_op_mfc0_performance0();
2277 rn = "Performance0";
2280 // gen_op_mfc0_performance1();
2281 rn = "Performance1";
2284 // gen_op_mfc0_performance2();
2285 rn = "Performance2";
2288 // gen_op_mfc0_performance3();
2289 rn = "Performance3";
2292 // gen_op_mfc0_performance4();
2293 rn = "Performance4";
2296 // gen_op_mfc0_performance5();
2297 rn = "Performance5";
2300 // gen_op_mfc0_performance6();
2301 rn = "Performance6";
2304 // gen_op_mfc0_performance7();
2305 rn = "Performance7";
2330 gen_op_mfc0_taglo();
2337 gen_op_mfc0_datalo();
2350 gen_op_mfc0_taghi();
2357 gen_op_mfc0_datahi();
2367 gen_op_mfc0_errorepc();
2377 gen_op_mfc0_desave(); /* EJTAG support */
2387 #if defined MIPS_DEBUG_DISAS
2388 if (loglevel & CPU_LOG_TB_IN_ASM) {
2389 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2396 #if defined MIPS_DEBUG_DISAS
2397 if (loglevel & CPU_LOG_TB_IN_ASM) {
2398 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2402 generate_exception(ctx, EXCP_RI);
2405 static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
2407 const char *rn = "invalid";
2413 gen_op_mtc0_index();
2417 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
2421 // gen_op_mtc0_mvpconf0(); /* MT ASE */
2425 // gen_op_mtc0_mvpconf1(); /* MT ASE */
2439 // gen_op_mtc0_vpecontrol(); /* MT ASE */
2443 // gen_op_mtc0_vpeconf0(); /* MT ASE */
2447 // gen_op_mtc0_vpeconf1(); /* MT ASE */
2451 // gen_op_mtc0_YQMask(); /* MT ASE */
2455 // gen_op_mtc0_vpeschedule(); /* MT ASE */
2459 // gen_op_mtc0_vpeschefback(); /* MT ASE */
2460 rn = "VPEScheFBack";
2463 // gen_op_mtc0_vpeopt(); /* MT ASE */
2473 gen_op_mtc0_entrylo0();
2477 // gen_op_mtc0_tcstatus(); /* MT ASE */
2481 // gen_op_mtc0_tcbind(); /* MT ASE */
2485 // gen_op_mtc0_tcrestart(); /* MT ASE */
2489 // gen_op_mtc0_tchalt(); /* MT ASE */
2493 // gen_op_mtc0_tccontext(); /* MT ASE */
2497 // gen_op_mtc0_tcschedule(); /* MT ASE */
2501 // gen_op_mtc0_tcschefback(); /* MT ASE */
2511 gen_op_mtc0_entrylo1();
2521 gen_op_mtc0_context();
2525 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2526 rn = "ContextConfig";
2535 gen_op_mtc0_pagemask();
2539 gen_op_mtc0_pagegrain();
2549 gen_op_mtc0_wired();
2553 // gen_op_mtc0_srsconf0(); /* shadow registers */
2557 // gen_op_mtc0_srsconf1(); /* shadow registers */
2561 // gen_op_mtc0_srsconf2(); /* shadow registers */
2565 // gen_op_mtc0_srsconf3(); /* shadow registers */
2569 // gen_op_mtc0_srsconf4(); /* shadow registers */
2579 gen_op_mtc0_hwrena();
2593 gen_op_mtc0_count();
2596 /* 6,7 are implementation dependent */
2600 /* Stop translation as we may have switched the execution mode */
2601 ctx->bstate = BS_STOP;
2606 gen_op_mtc0_entryhi();
2616 gen_op_mtc0_compare();
2619 /* 6,7 are implementation dependent */
2623 /* Stop translation as we may have switched the execution mode */
2624 ctx->bstate = BS_STOP;
2629 gen_op_mtc0_status();
2633 gen_op_mtc0_intctl();
2637 gen_op_mtc0_srsctl();
2641 gen_op_mtc0_srsmap();
2647 /* Stop translation as we may have switched the execution mode */
2648 ctx->bstate = BS_STOP;
2653 gen_op_mtc0_cause();
2659 /* Stop translation as we may have switched the execution mode */
2660 ctx->bstate = BS_STOP;
2679 gen_op_mtc0_ebase();
2689 gen_op_mtc0_config0();
2691 /* Stop translation as we may have switched the execution mode */
2692 ctx->bstate = BS_STOP;
2695 /* ignored, read only */
2699 gen_op_mtc0_config2();
2701 /* Stop translation as we may have switched the execution mode */
2702 ctx->bstate = BS_STOP;
2705 /* ignored, read only */
2708 /* 4,5 are reserved */
2709 /* 6,7 are implementation dependent */
2719 rn = "Invalid config selector";
2736 gen_op_mtc0_watchlo(sel);
2746 gen_op_mtc0_watchhi(sel);
2756 #ifdef TARGET_MIPS64
2757 gen_op_mtc0_xcontext();
2766 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2769 gen_op_mtc0_framemask();
2778 rn = "Diagnostic"; /* implementation dependent */
2783 gen_op_mtc0_debug(); /* EJTAG support */
2787 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2788 rn = "TraceControl";
2791 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2792 rn = "TraceControl2";
2795 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2796 rn = "UserTraceData";
2799 // gen_op_mtc0_debug(); /* PDtrace support */
2805 /* Stop translation as we may have switched the execution mode */
2806 ctx->bstate = BS_STOP;
2811 gen_op_mtc0_depc(); /* EJTAG support */
2821 gen_op_mtc0_performance0();
2822 rn = "Performance0";
2825 // gen_op_mtc0_performance1();
2826 rn = "Performance1";
2829 // gen_op_mtc0_performance2();
2830 rn = "Performance2";
2833 // gen_op_mtc0_performance3();
2834 rn = "Performance3";
2837 // gen_op_mtc0_performance4();
2838 rn = "Performance4";
2841 // gen_op_mtc0_performance5();
2842 rn = "Performance5";
2845 // gen_op_mtc0_performance6();
2846 rn = "Performance6";
2849 // gen_op_mtc0_performance7();
2850 rn = "Performance7";
2876 gen_op_mtc0_taglo();
2883 gen_op_mtc0_datalo();
2896 gen_op_mtc0_taghi();
2903 gen_op_mtc0_datahi();
2914 gen_op_mtc0_errorepc();
2924 gen_op_mtc0_desave(); /* EJTAG support */
2930 /* Stop translation as we may have switched the execution mode */
2931 ctx->bstate = BS_STOP;
2936 #if defined MIPS_DEBUG_DISAS
2937 if (loglevel & CPU_LOG_TB_IN_ASM) {
2938 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2945 #if defined MIPS_DEBUG_DISAS
2946 if (loglevel & CPU_LOG_TB_IN_ASM) {
2947 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2951 generate_exception(ctx, EXCP_RI);
2954 #ifdef TARGET_MIPS64
2955 static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
2957 const char *rn = "invalid";
2963 gen_op_mfc0_index();
2967 // gen_op_dmfc0_mvpcontrol(); /* MT ASE */
2971 // gen_op_dmfc0_mvpconf0(); /* MT ASE */
2975 // gen_op_dmfc0_mvpconf1(); /* MT ASE */
2985 gen_op_mfc0_random();
2989 // gen_op_dmfc0_vpecontrol(); /* MT ASE */
2993 // gen_op_dmfc0_vpeconf0(); /* MT ASE */
2997 // gen_op_dmfc0_vpeconf1(); /* MT ASE */
3001 // gen_op_dmfc0_YQMask(); /* MT ASE */
3005 // gen_op_dmfc0_vpeschedule(); /* MT ASE */
3009 // gen_op_dmfc0_vpeschefback(); /* MT ASE */
3010 rn = "VPEScheFBack";
3013 // gen_op_dmfc0_vpeopt(); /* MT ASE */
3023 gen_op_dmfc0_entrylo0();
3027 // gen_op_dmfc0_tcstatus(); /* MT ASE */
3031 // gen_op_dmfc0_tcbind(); /* MT ASE */
3035 // gen_op_dmfc0_tcrestart(); /* MT ASE */
3039 // gen_op_dmfc0_tchalt(); /* MT ASE */
3043 // gen_op_dmfc0_tccontext(); /* MT ASE */
3047 // gen_op_dmfc0_tcschedule(); /* MT ASE */
3051 // gen_op_dmfc0_tcschefback(); /* MT ASE */
3061 gen_op_dmfc0_entrylo1();
3071 gen_op_dmfc0_context();
3075 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3076 rn = "ContextConfig";
3085 gen_op_mfc0_pagemask();
3089 gen_op_mfc0_pagegrain();
3099 gen_op_mfc0_wired();
3103 // gen_op_dmfc0_srsconf0(); /* shadow registers */
3107 // gen_op_dmfc0_srsconf1(); /* shadow registers */
3111 // gen_op_dmfc0_srsconf2(); /* shadow registers */
3115 // gen_op_dmfc0_srsconf3(); /* shadow registers */
3119 // gen_op_dmfc0_srsconf4(); /* shadow registers */
3129 gen_op_mfc0_hwrena();
3139 gen_op_dmfc0_badvaddr();
3149 gen_op_mfc0_count();
3152 /* 6,7 are implementation dependent */
3160 gen_op_dmfc0_entryhi();
3170 gen_op_mfc0_compare();
3173 /* 6,7 are implementation dependent */
3181 gen_op_mfc0_status();
3185 gen_op_mfc0_intctl();
3189 gen_op_mfc0_srsctl();
3193 gen_op_mfc0_srsmap(); /* shadow registers */
3203 gen_op_mfc0_cause();
3227 gen_op_mfc0_ebase();
3237 gen_op_mfc0_config0();
3241 gen_op_mfc0_config1();
3245 gen_op_mfc0_config2();
3249 gen_op_mfc0_config3();
3252 /* 6,7 are implementation dependent */
3260 gen_op_dmfc0_lladdr();
3270 gen_op_dmfc0_watchlo(sel);
3280 gen_op_mfc0_watchhi(sel);
3290 #ifdef TARGET_MIPS64
3291 gen_op_dmfc0_xcontext();
3300 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3303 gen_op_mfc0_framemask();
3312 rn = "'Diagnostic"; /* implementation dependent */
3317 gen_op_mfc0_debug(); /* EJTAG support */
3321 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3322 rn = "TraceControl";
3325 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3326 rn = "TraceControl2";
3329 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3330 rn = "UserTraceData";
3333 // gen_op_dmfc0_debug(); /* PDtrace support */
3343 gen_op_dmfc0_depc(); /* EJTAG support */
3353 gen_op_mfc0_performance0();
3354 rn = "Performance0";
3357 // gen_op_dmfc0_performance1();
3358 rn = "Performance1";
3361 // gen_op_dmfc0_performance2();
3362 rn = "Performance2";
3365 // gen_op_dmfc0_performance3();
3366 rn = "Performance3";
3369 // gen_op_dmfc0_performance4();
3370 rn = "Performance4";
3373 // gen_op_dmfc0_performance5();
3374 rn = "Performance5";
3377 // gen_op_dmfc0_performance6();
3378 rn = "Performance6";
3381 // gen_op_dmfc0_performance7();
3382 rn = "Performance7";
3407 gen_op_mfc0_taglo();
3414 gen_op_mfc0_datalo();
3427 gen_op_mfc0_taghi();
3434 gen_op_mfc0_datahi();
3444 gen_op_dmfc0_errorepc();
3454 gen_op_mfc0_desave(); /* EJTAG support */
3464 #if defined MIPS_DEBUG_DISAS
3465 if (loglevel & CPU_LOG_TB_IN_ASM) {
3466 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3473 #if defined MIPS_DEBUG_DISAS
3474 if (loglevel & CPU_LOG_TB_IN_ASM) {
3475 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3479 generate_exception(ctx, EXCP_RI);
3482 static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
3484 const char *rn = "invalid";
3490 gen_op_mtc0_index();
3494 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
3498 // gen_op_mtc0_mvpconf0(); /* MT ASE */
3502 // gen_op_mtc0_mvpconf1(); /* MT ASE */
3516 // gen_op_mtc0_vpecontrol(); /* MT ASE */
3520 // gen_op_mtc0_vpeconf0(); /* MT ASE */
3524 // gen_op_mtc0_vpeconf1(); /* MT ASE */
3528 // gen_op_mtc0_YQMask(); /* MT ASE */
3532 // gen_op_mtc0_vpeschedule(); /* MT ASE */
3536 // gen_op_mtc0_vpeschefback(); /* MT ASE */
3537 rn = "VPEScheFBack";
3540 // gen_op_mtc0_vpeopt(); /* MT ASE */
3550 gen_op_mtc0_entrylo0();
3554 // gen_op_mtc0_tcstatus(); /* MT ASE */
3558 // gen_op_mtc0_tcbind(); /* MT ASE */
3562 // gen_op_mtc0_tcrestart(); /* MT ASE */
3566 // gen_op_mtc0_tchalt(); /* MT ASE */
3570 // gen_op_mtc0_tccontext(); /* MT ASE */
3574 // gen_op_mtc0_tcschedule(); /* MT ASE */
3578 // gen_op_mtc0_tcschefback(); /* MT ASE */
3588 gen_op_mtc0_entrylo1();
3598 gen_op_mtc0_context();
3602 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3603 rn = "ContextConfig";
3612 gen_op_mtc0_pagemask();
3616 gen_op_mtc0_pagegrain();
3626 gen_op_mtc0_wired();
3630 // gen_op_mtc0_srsconf0(); /* shadow registers */
3634 // gen_op_mtc0_srsconf1(); /* shadow registers */
3638 // gen_op_mtc0_srsconf2(); /* shadow registers */
3642 // gen_op_mtc0_srsconf3(); /* shadow registers */
3646 // gen_op_mtc0_srsconf4(); /* shadow registers */
3656 gen_op_mtc0_hwrena();
3670 gen_op_mtc0_count();
3673 /* 6,7 are implementation dependent */
3677 /* Stop translation as we may have switched the execution mode */
3678 ctx->bstate = BS_STOP;
3683 gen_op_mtc0_entryhi();
3693 gen_op_mtc0_compare();
3696 /* 6,7 are implementation dependent */
3700 /* Stop translation as we may have switched the execution mode */
3701 ctx->bstate = BS_STOP;
3706 gen_op_mtc0_status();
3710 gen_op_mtc0_intctl();
3714 gen_op_mtc0_srsctl();
3718 gen_op_mtc0_srsmap();
3724 /* Stop translation as we may have switched the execution mode */
3725 ctx->bstate = BS_STOP;
3730 gen_op_mtc0_cause();
3736 /* Stop translation as we may have switched the execution mode */
3737 ctx->bstate = BS_STOP;
3756 gen_op_mtc0_ebase();
3766 gen_op_mtc0_config0();
3768 /* Stop translation as we may have switched the execution mode */
3769 ctx->bstate = BS_STOP;
3776 gen_op_mtc0_config2();
3778 /* Stop translation as we may have switched the execution mode */
3779 ctx->bstate = BS_STOP;
3785 /* 6,7 are implementation dependent */
3787 rn = "Invalid config selector";
3804 gen_op_mtc0_watchlo(sel);
3814 gen_op_mtc0_watchhi(sel);
3824 #ifdef TARGET_MIPS64
3825 gen_op_mtc0_xcontext();
3834 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3837 gen_op_mtc0_framemask();
3846 rn = "Diagnostic"; /* implementation dependent */
3851 gen_op_mtc0_debug(); /* EJTAG support */
3855 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3856 rn = "TraceControl";
3859 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3860 rn = "TraceControl2";
3863 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3864 rn = "UserTraceData";
3867 // gen_op_mtc0_debug(); /* PDtrace support */
3873 /* Stop translation as we may have switched the execution mode */
3874 ctx->bstate = BS_STOP;
3879 gen_op_mtc0_depc(); /* EJTAG support */
3889 gen_op_mtc0_performance0();
3890 rn = "Performance0";
3893 // gen_op_mtc0_performance1();
3894 rn = "Performance1";
3897 // gen_op_mtc0_performance2();
3898 rn = "Performance2";
3901 // gen_op_mtc0_performance3();
3902 rn = "Performance3";
3905 // gen_op_mtc0_performance4();
3906 rn = "Performance4";
3909 // gen_op_mtc0_performance5();
3910 rn = "Performance5";
3913 // gen_op_mtc0_performance6();
3914 rn = "Performance6";
3917 // gen_op_mtc0_performance7();
3918 rn = "Performance7";
3944 gen_op_mtc0_taglo();
3951 gen_op_mtc0_datalo();
3964 gen_op_mtc0_taghi();
3971 gen_op_mtc0_datahi();
3982 gen_op_mtc0_errorepc();
3992 gen_op_mtc0_desave(); /* EJTAG support */
3998 /* Stop translation as we may have switched the execution mode */
3999 ctx->bstate = BS_STOP;
4004 #if defined MIPS_DEBUG_DISAS
4005 if (loglevel & CPU_LOG_TB_IN_ASM) {
4006 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4013 #if defined MIPS_DEBUG_DISAS
4014 if (loglevel & CPU_LOG_TB_IN_ASM) {
4015 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4019 generate_exception(ctx, EXCP_RI);
4021 #endif /* TARGET_MIPS64 */
4023 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
4025 const char *opn = "ldst";
4033 gen_mfc0(ctx, rd, ctx->opcode & 0x7);
4034 gen_op_store_T0_gpr(rt);
4038 GEN_LOAD_REG_TN(T0, rt);
4039 gen_mtc0(ctx, rd, ctx->opcode & 0x7);
4042 #ifdef TARGET_MIPS64
4048 gen_dmfc0(ctx, rd, ctx->opcode & 0x7);
4049 gen_op_store_T0_gpr(rt);
4053 GEN_LOAD_REG_TN(T0, rt);
4054 gen_dmtc0(ctx, rd, ctx->opcode & 0x7);
4085 ctx->bstate = BS_EXCP;
4089 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
4091 generate_exception(ctx, EXCP_RI);
4094 ctx->bstate = BS_EXCP;
4099 /* If we get an exception, we want to restart at next instruction */
4101 save_cpu_state(ctx, 1);
4104 ctx->bstate = BS_EXCP;
4109 generate_exception(ctx, EXCP_RI);
4112 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
4115 /* CP1 Branches (before delay slot) */
4116 static void gen_compute_branch1 (DisasContext *ctx, uint32_t op,
4117 int32_t cc, int32_t offset)
4119 target_ulong btarget;
4120 const char *opn = "cp1 cond branch";
4122 btarget = ctx->pc + 4 + offset;
4141 ctx->hflags |= MIPS_HFLAG_BL;
4143 gen_op_save_bcond();
4146 gen_op_bc1any2f(cc);
4150 gen_op_bc1any2t(cc);
4154 gen_op_bc1any4f(cc);
4158 gen_op_bc1any4t(cc);
4161 ctx->hflags |= MIPS_HFLAG_BC;
4166 generate_exception (ctx, EXCP_RI);
4169 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
4170 ctx->hflags, btarget);
4171 ctx->btarget = btarget;
4174 /* Coprocessor 1 (FPU) */
4176 #define FOP(func, fmt) (((fmt) << 21) | (func))
4178 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
4180 const char *opn = "cp1 move";
4184 GEN_LOAD_FREG_FTN(WT0, fs);
4186 GEN_STORE_TN_REG(rt, T0);
4190 GEN_LOAD_REG_TN(T0, rt);
4192 GEN_STORE_FTN_FREG(fs, WT0);
4196 GEN_LOAD_IMM_TN(T1, fs);
4198 GEN_STORE_TN_REG(rt, T0);
4202 GEN_LOAD_IMM_TN(T1, fs);
4203 GEN_LOAD_REG_TN(T0, rt);
4208 GEN_LOAD_FREG_FTN(DT0, fs);
4210 GEN_STORE_TN_REG(rt, T0);
4214 GEN_LOAD_REG_TN(T0, rt);
4216 GEN_STORE_FTN_FREG(fs, DT0);
4220 GEN_LOAD_FREG_FTN(WTH0, fs);
4222 GEN_STORE_TN_REG(rt, T0);
4226 GEN_LOAD_REG_TN(T0, rt);
4228 GEN_STORE_FTN_FREG(fs, WTH0);
4233 generate_exception (ctx, EXCP_RI);
4236 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
4239 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
4243 GEN_LOAD_REG_TN(T0, rd);
4244 GEN_LOAD_REG_TN(T1, rs);
4246 ccbit = 1 << (24 + cc);
4253 GEN_STORE_TN_REG(rd, T0);
4256 #define GEN_MOVCF(fmt) \
4257 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4262 ccbit = 1 << (24 + cc); \
4266 glue(gen_op_float_movf_, fmt)(ccbit); \
4268 glue(gen_op_float_movt_, fmt)(ccbit); \
4275 static void gen_farith (DisasContext *ctx, uint32_t op1,
4276 int ft, int fs, int fd, int cc)
4278 const char *opn = "farith";
4279 const char *condnames[] = {
4297 const char *condnames_abs[] = {
4315 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
4316 uint32_t func = ctx->opcode & 0x3f;
4318 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
4320 GEN_LOAD_FREG_FTN(WT0, fs);
4321 GEN_LOAD_FREG_FTN(WT1, ft);
4322 gen_op_float_add_s();
4323 GEN_STORE_FTN_FREG(fd, WT2);
4328 GEN_LOAD_FREG_FTN(WT0, fs);
4329 GEN_LOAD_FREG_FTN(WT1, ft);
4330 gen_op_float_sub_s();
4331 GEN_STORE_FTN_FREG(fd, WT2);
4336 GEN_LOAD_FREG_FTN(WT0, fs);
4337 GEN_LOAD_FREG_FTN(WT1, ft);
4338 gen_op_float_mul_s();
4339 GEN_STORE_FTN_FREG(fd, WT2);
4344 GEN_LOAD_FREG_FTN(WT0, fs);
4345 GEN_LOAD_FREG_FTN(WT1, ft);
4346 gen_op_float_div_s();
4347 GEN_STORE_FTN_FREG(fd, WT2);
4352 GEN_LOAD_FREG_FTN(WT0, fs);
4353 gen_op_float_sqrt_s();
4354 GEN_STORE_FTN_FREG(fd, WT2);
4358 GEN_LOAD_FREG_FTN(WT0, fs);
4359 gen_op_float_abs_s();
4360 GEN_STORE_FTN_FREG(fd, WT2);
4364 GEN_LOAD_FREG_FTN(WT0, fs);
4365 gen_op_float_mov_s();
4366 GEN_STORE_FTN_FREG(fd, WT2);
4370 GEN_LOAD_FREG_FTN(WT0, fs);
4371 gen_op_float_chs_s();
4372 GEN_STORE_FTN_FREG(fd, WT2);
4376 check_cp1_64bitmode(ctx);
4377 GEN_LOAD_FREG_FTN(WT0, fs);
4378 gen_op_float_roundl_s();
4379 GEN_STORE_FTN_FREG(fd, DT2);
4383 check_cp1_64bitmode(ctx);
4384 GEN_LOAD_FREG_FTN(WT0, fs);
4385 gen_op_float_truncl_s();
4386 GEN_STORE_FTN_FREG(fd, DT2);
4390 check_cp1_64bitmode(ctx);
4391 GEN_LOAD_FREG_FTN(WT0, fs);
4392 gen_op_float_ceill_s();
4393 GEN_STORE_FTN_FREG(fd, DT2);
4397 check_cp1_64bitmode(ctx);
4398 GEN_LOAD_FREG_FTN(WT0, fs);
4399 gen_op_float_floorl_s();
4400 GEN_STORE_FTN_FREG(fd, DT2);
4404 GEN_LOAD_FREG_FTN(WT0, fs);
4405 gen_op_float_roundw_s();
4406 GEN_STORE_FTN_FREG(fd, WT2);
4410 GEN_LOAD_FREG_FTN(WT0, fs);
4411 gen_op_float_truncw_s();
4412 GEN_STORE_FTN_FREG(fd, WT2);
4416 GEN_LOAD_FREG_FTN(WT0, fs);
4417 gen_op_float_ceilw_s();
4418 GEN_STORE_FTN_FREG(fd, WT2);
4422 GEN_LOAD_FREG_FTN(WT0, fs);
4423 gen_op_float_floorw_s();
4424 GEN_STORE_FTN_FREG(fd, WT2);
4428 GEN_LOAD_REG_TN(T0, ft);
4429 GEN_LOAD_FREG_FTN(WT0, fs);
4430 GEN_LOAD_FREG_FTN(WT2, fd);
4431 gen_movcf_s(ctx, (ft >> 2) & 0x7, ft & 0x1);
4432 GEN_STORE_FTN_FREG(fd, WT2);
4436 GEN_LOAD_REG_TN(T0, ft);
4437 GEN_LOAD_FREG_FTN(WT0, fs);
4438 GEN_LOAD_FREG_FTN(WT2, fd);
4439 gen_op_float_movz_s();
4440 GEN_STORE_FTN_FREG(fd, WT2);
4444 GEN_LOAD_REG_TN(T0, ft);
4445 GEN_LOAD_FREG_FTN(WT0, fs);
4446 GEN_LOAD_FREG_FTN(WT2, fd);
4447 gen_op_float_movn_s();
4448 GEN_STORE_FTN_FREG(fd, WT2);
4452 GEN_LOAD_FREG_FTN(WT0, fs);
4453 gen_op_float_recip_s();
4454 GEN_STORE_FTN_FREG(fd, WT2);
4458 GEN_LOAD_FREG_FTN(WT0, fs);
4459 gen_op_float_rsqrt_s();
4460 GEN_STORE_FTN_FREG(fd, WT2);
4464 check_cp1_64bitmode(ctx);
4465 GEN_LOAD_FREG_FTN(WT0, fs);
4466 GEN_LOAD_FREG_FTN(WT2, fd);
4467 gen_op_float_recip2_s();
4468 GEN_STORE_FTN_FREG(fd, WT2);
4472 check_cp1_64bitmode(ctx);
4473 GEN_LOAD_FREG_FTN(WT0, fs);
4474 gen_op_float_recip1_s();
4475 GEN_STORE_FTN_FREG(fd, WT2);
4479 check_cp1_64bitmode(ctx);
4480 GEN_LOAD_FREG_FTN(WT0, fs);
4481 gen_op_float_rsqrt1_s();
4482 GEN_STORE_FTN_FREG(fd, WT2);
4486 check_cp1_64bitmode(ctx);
4487 GEN_LOAD_FREG_FTN(WT0, fs);
4488 GEN_LOAD_FREG_FTN(WT2, fd);
4489 gen_op_float_rsqrt2_s();
4490 GEN_STORE_FTN_FREG(fd, WT2);
4494 check_cp1_registers(ctx, fd);
4495 GEN_LOAD_FREG_FTN(WT0, fs);
4496 gen_op_float_cvtd_s();
4497 GEN_STORE_FTN_FREG(fd, DT2);
4501 GEN_LOAD_FREG_FTN(WT0, fs);
4502 gen_op_float_cvtw_s();
4503 GEN_STORE_FTN_FREG(fd, WT2);
4507 check_cp1_64bitmode(ctx);
4508 GEN_LOAD_FREG_FTN(WT0, fs);
4509 gen_op_float_cvtl_s();
4510 GEN_STORE_FTN_FREG(fd, DT2);
4514 check_cp1_64bitmode(ctx);
4515 GEN_LOAD_FREG_FTN(WT1, fs);
4516 GEN_LOAD_FREG_FTN(WT0, ft);
4517 gen_op_float_cvtps_s();
4518 GEN_STORE_FTN_FREG(fd, DT2);
4537 GEN_LOAD_FREG_FTN(WT0, fs);
4538 GEN_LOAD_FREG_FTN(WT1, ft);
4539 if (ctx->opcode & (1 << 6)) {
4540 check_cp1_64bitmode(ctx);
4541 gen_cmpabs_s(func-48, cc);
4542 opn = condnames_abs[func-48];
4544 gen_cmp_s(func-48, cc);
4545 opn = condnames[func-48];
4549 check_cp1_registers(ctx, fs | ft | fd);
4550 GEN_LOAD_FREG_FTN(DT0, fs);
4551 GEN_LOAD_FREG_FTN(DT1, ft);
4552 gen_op_float_add_d();
4553 GEN_STORE_FTN_FREG(fd, DT2);
4558 check_cp1_registers(ctx, fs | ft | fd);
4559 GEN_LOAD_FREG_FTN(DT0, fs);
4560 GEN_LOAD_FREG_FTN(DT1, ft);
4561 gen_op_float_sub_d();
4562 GEN_STORE_FTN_FREG(fd, DT2);
4567 check_cp1_registers(ctx, fs | ft | fd);
4568 GEN_LOAD_FREG_FTN(DT0, fs);
4569 GEN_LOAD_FREG_FTN(DT1, ft);
4570 gen_op_float_mul_d();
4571 GEN_STORE_FTN_FREG(fd, DT2);
4576 check_cp1_registers(ctx, fs | ft | fd);
4577 GEN_LOAD_FREG_FTN(DT0, fs);
4578 GEN_LOAD_FREG_FTN(DT1, ft);
4579 gen_op_float_div_d();
4580 GEN_STORE_FTN_FREG(fd, DT2);
4585 check_cp1_registers(ctx, fs | fd);
4586 GEN_LOAD_FREG_FTN(DT0, fs);
4587 gen_op_float_sqrt_d();
4588 GEN_STORE_FTN_FREG(fd, DT2);
4592 check_cp1_registers(ctx, fs | fd);
4593 GEN_LOAD_FREG_FTN(DT0, fs);
4594 gen_op_float_abs_d();
4595 GEN_STORE_FTN_FREG(fd, DT2);
4599 check_cp1_registers(ctx, fs | fd);
4600 GEN_LOAD_FREG_FTN(DT0, fs);
4601 gen_op_float_mov_d();
4602 GEN_STORE_FTN_FREG(fd, DT2);
4606 check_cp1_registers(ctx, fs | fd);
4607 GEN_LOAD_FREG_FTN(DT0, fs);
4608 gen_op_float_chs_d();
4609 GEN_STORE_FTN_FREG(fd, DT2);
4613 check_cp1_64bitmode(ctx);
4614 GEN_LOAD_FREG_FTN(DT0, fs);
4615 gen_op_float_roundl_d();
4616 GEN_STORE_FTN_FREG(fd, DT2);
4620 check_cp1_64bitmode(ctx);
4621 GEN_LOAD_FREG_FTN(DT0, fs);
4622 gen_op_float_truncl_d();
4623 GEN_STORE_FTN_FREG(fd, DT2);
4627 check_cp1_64bitmode(ctx);
4628 GEN_LOAD_FREG_FTN(DT0, fs);
4629 gen_op_float_ceill_d();
4630 GEN_STORE_FTN_FREG(fd, DT2);
4634 check_cp1_64bitmode(ctx);
4635 GEN_LOAD_FREG_FTN(DT0, fs);
4636 gen_op_float_floorl_d();
4637 GEN_STORE_FTN_FREG(fd, DT2);
4641 check_cp1_registers(ctx, fs);
4642 GEN_LOAD_FREG_FTN(DT0, fs);
4643 gen_op_float_roundw_d();
4644 GEN_STORE_FTN_FREG(fd, WT2);
4648 check_cp1_registers(ctx, fs);
4649 GEN_LOAD_FREG_FTN(DT0, fs);
4650 gen_op_float_truncw_d();
4651 GEN_STORE_FTN_FREG(fd, WT2);
4655 check_cp1_registers(ctx, fs);
4656 GEN_LOAD_FREG_FTN(DT0, fs);
4657 gen_op_float_ceilw_d();
4658 GEN_STORE_FTN_FREG(fd, WT2);
4662 check_cp1_registers(ctx, fs);
4663 GEN_LOAD_FREG_FTN(DT0, fs);
4664 gen_op_float_floorw_d();
4665 GEN_STORE_FTN_FREG(fd, WT2);
4669 GEN_LOAD_REG_TN(T0, ft);
4670 GEN_LOAD_FREG_FTN(DT0, fs);
4671 GEN_LOAD_FREG_FTN(DT2, fd);
4672 gen_movcf_d(ctx, (ft >> 2) & 0x7, ft & 0x1);
4673 GEN_STORE_FTN_FREG(fd, DT2);
4677 GEN_LOAD_REG_TN(T0, ft);
4678 GEN_LOAD_FREG_FTN(DT0, fs);
4679 GEN_LOAD_FREG_FTN(DT2, fd);
4680 gen_op_float_movz_d();
4681 GEN_STORE_FTN_FREG(fd, DT2);
4685 GEN_LOAD_REG_TN(T0, ft);
4686 GEN_LOAD_FREG_FTN(DT0, fs);
4687 GEN_LOAD_FREG_FTN(DT2, fd);
4688 gen_op_float_movn_d();
4689 GEN_STORE_FTN_FREG(fd, DT2);
4693 check_cp1_registers(ctx, fs | fd);
4694 GEN_LOAD_FREG_FTN(DT0, fs);
4695 gen_op_float_recip_d();
4696 GEN_STORE_FTN_FREG(fd, DT2);
4700 check_cp1_registers(ctx, fs | fd);
4701 GEN_LOAD_FREG_FTN(DT0, fs);
4702 gen_op_float_rsqrt_d();
4703 GEN_STORE_FTN_FREG(fd, DT2);
4707 check_cp1_64bitmode(ctx);
4708 GEN_LOAD_FREG_FTN(DT0, fs);
4709 GEN_LOAD_FREG_FTN(DT2, ft);
4710 gen_op_float_recip2_d();
4711 GEN_STORE_FTN_FREG(fd, DT2);
4715 check_cp1_64bitmode(ctx);
4716 GEN_LOAD_FREG_FTN(DT0, fs);
4717 gen_op_float_recip1_d();
4718 GEN_STORE_FTN_FREG(fd, DT2);
4722 check_cp1_64bitmode(ctx);
4723 GEN_LOAD_FREG_FTN(DT0, fs);
4724 gen_op_float_rsqrt1_d();
4725 GEN_STORE_FTN_FREG(fd, DT2);
4729 check_cp1_64bitmode(ctx);
4730 GEN_LOAD_FREG_FTN(DT0, fs);
4731 GEN_LOAD_FREG_FTN(DT2, ft);
4732 gen_op_float_rsqrt2_d();
4733 GEN_STORE_FTN_FREG(fd, DT2);
4752 GEN_LOAD_FREG_FTN(DT0, fs);
4753 GEN_LOAD_FREG_FTN(DT1, ft);
4754 if (ctx->opcode & (1 << 6)) {
4755 check_cp1_64bitmode(ctx);
4756 gen_cmpabs_d(func-48, cc);
4757 opn = condnames_abs[func-48];
4759 check_cp1_registers(ctx, fs | ft);
4760 gen_cmp_d(func-48, cc);
4761 opn = condnames[func-48];
4765 check_cp1_registers(ctx, fs);
4766 GEN_LOAD_FREG_FTN(DT0, fs);
4767 gen_op_float_cvts_d();
4768 GEN_STORE_FTN_FREG(fd, WT2);
4772 check_cp1_registers(ctx, fs);
4773 GEN_LOAD_FREG_FTN(DT0, fs);
4774 gen_op_float_cvtw_d();
4775 GEN_STORE_FTN_FREG(fd, WT2);
4779 check_cp1_64bitmode(ctx);
4780 GEN_LOAD_FREG_FTN(DT0, fs);
4781 gen_op_float_cvtl_d();
4782 GEN_STORE_FTN_FREG(fd, DT2);
4786 GEN_LOAD_FREG_FTN(WT0, fs);
4787 gen_op_float_cvts_w();
4788 GEN_STORE_FTN_FREG(fd, WT2);
4792 check_cp1_registers(ctx, fd);
4793 GEN_LOAD_FREG_FTN(WT0, fs);
4794 gen_op_float_cvtd_w();
4795 GEN_STORE_FTN_FREG(fd, DT2);
4799 check_cp1_64bitmode(ctx);
4800 GEN_LOAD_FREG_FTN(DT0, fs);
4801 gen_op_float_cvts_l();
4802 GEN_STORE_FTN_FREG(fd, WT2);
4806 check_cp1_64bitmode(ctx);
4807 GEN_LOAD_FREG_FTN(DT0, fs);
4808 gen_op_float_cvtd_l();
4809 GEN_STORE_FTN_FREG(fd, DT2);
4814 check_cp1_64bitmode(ctx);
4815 GEN_LOAD_FREG_FTN(WT0, fs);
4816 GEN_LOAD_FREG_FTN(WTH0, fs);
4817 gen_op_float_cvtps_pw();
4818 GEN_STORE_FTN_FREG(fd, WT2);
4819 GEN_STORE_FTN_FREG(fd, WTH2);
4823 check_cp1_64bitmode(ctx);
4824 GEN_LOAD_FREG_FTN(WT0, fs);
4825 GEN_LOAD_FREG_FTN(WTH0, fs);
4826 GEN_LOAD_FREG_FTN(WT1, ft);
4827 GEN_LOAD_FREG_FTN(WTH1, ft);
4828 gen_op_float_add_ps();
4829 GEN_STORE_FTN_FREG(fd, WT2);
4830 GEN_STORE_FTN_FREG(fd, WTH2);
4834 check_cp1_64bitmode(ctx);
4835 GEN_LOAD_FREG_FTN(WT0, fs);
4836 GEN_LOAD_FREG_FTN(WTH0, fs);
4837 GEN_LOAD_FREG_FTN(WT1, ft);
4838 GEN_LOAD_FREG_FTN(WTH1, ft);
4839 gen_op_float_sub_ps();
4840 GEN_STORE_FTN_FREG(fd, WT2);
4841 GEN_STORE_FTN_FREG(fd, WTH2);
4845 check_cp1_64bitmode(ctx);
4846 GEN_LOAD_FREG_FTN(WT0, fs);
4847 GEN_LOAD_FREG_FTN(WTH0, fs);
4848 GEN_LOAD_FREG_FTN(WT1, ft);
4849 GEN_LOAD_FREG_FTN(WTH1, ft);
4850 gen_op_float_mul_ps();
4851 GEN_STORE_FTN_FREG(fd, WT2);
4852 GEN_STORE_FTN_FREG(fd, WTH2);
4856 check_cp1_64bitmode(ctx);
4857 GEN_LOAD_FREG_FTN(WT0, fs);
4858 GEN_LOAD_FREG_FTN(WTH0, fs);
4859 gen_op_float_abs_ps();
4860 GEN_STORE_FTN_FREG(fd, WT2);
4861 GEN_STORE_FTN_FREG(fd, WTH2);
4865 check_cp1_64bitmode(ctx);
4866 GEN_LOAD_FREG_FTN(WT0, fs);
4867 GEN_LOAD_FREG_FTN(WTH0, fs);
4868 gen_op_float_mov_ps();
4869 GEN_STORE_FTN_FREG(fd, WT2);
4870 GEN_STORE_FTN_FREG(fd, WTH2);
4874 check_cp1_64bitmode(ctx);
4875 GEN_LOAD_FREG_FTN(WT0, fs);
4876 GEN_LOAD_FREG_FTN(WTH0, fs);
4877 gen_op_float_chs_ps();
4878 GEN_STORE_FTN_FREG(fd, WT2);
4879 GEN_STORE_FTN_FREG(fd, WTH2);
4883 check_cp1_64bitmode(ctx);
4884 GEN_LOAD_REG_TN(T0, ft);
4885 GEN_LOAD_FREG_FTN(WT0, fs);
4886 GEN_LOAD_FREG_FTN(WTH0, fs);
4887 GEN_LOAD_FREG_FTN(WT2, fd);
4888 GEN_LOAD_FREG_FTN(WTH2, fd);
4889 gen_movcf_ps(ctx, (ft >> 2) & 0x7, ft & 0x1);
4890 GEN_STORE_FTN_FREG(fd, WT2);
4891 GEN_STORE_FTN_FREG(fd, WTH2);
4895 check_cp1_64bitmode(ctx);
4896 GEN_LOAD_REG_TN(T0, ft);
4897 GEN_LOAD_FREG_FTN(WT0, fs);
4898 GEN_LOAD_FREG_FTN(WTH0, fs);
4899 GEN_LOAD_FREG_FTN(WT2, fd);
4900 GEN_LOAD_FREG_FTN(WTH2, fd);
4901 gen_op_float_movz_ps();
4902 GEN_STORE_FTN_FREG(fd, WT2);
4903 GEN_STORE_FTN_FREG(fd, WTH2);
4907 check_cp1_64bitmode(ctx);
4908 GEN_LOAD_REG_TN(T0, ft);
4909 GEN_LOAD_FREG_FTN(WT0, fs);
4910 GEN_LOAD_FREG_FTN(WTH0, fs);
4911 GEN_LOAD_FREG_FTN(WT2, fd);
4912 GEN_LOAD_FREG_FTN(WTH2, fd);
4913 gen_op_float_movn_ps();
4914 GEN_STORE_FTN_FREG(fd, WT2);
4915 GEN_STORE_FTN_FREG(fd, WTH2);
4919 check_cp1_64bitmode(ctx);
4920 GEN_LOAD_FREG_FTN(WT0, ft);
4921 GEN_LOAD_FREG_FTN(WTH0, ft);
4922 GEN_LOAD_FREG_FTN(WT1, fs);
4923 GEN_LOAD_FREG_FTN(WTH1, fs);
4924 gen_op_float_addr_ps();
4925 GEN_STORE_FTN_FREG(fd, WT2);
4926 GEN_STORE_FTN_FREG(fd, WTH2);
4930 check_cp1_64bitmode(ctx);
4931 GEN_LOAD_FREG_FTN(WT0, ft);
4932 GEN_LOAD_FREG_FTN(WTH0, ft);
4933 GEN_LOAD_FREG_FTN(WT1, fs);
4934 GEN_LOAD_FREG_FTN(WTH1, fs);
4935 gen_op_float_mulr_ps();
4936 GEN_STORE_FTN_FREG(fd, WT2);
4937 GEN_STORE_FTN_FREG(fd, WTH2);
4941 check_cp1_64bitmode(ctx);
4942 GEN_LOAD_FREG_FTN(WT0, fs);
4943 GEN_LOAD_FREG_FTN(WTH0, fs);
4944 GEN_LOAD_FREG_FTN(WT2, fd);
4945 GEN_LOAD_FREG_FTN(WTH2, fd);
4946 gen_op_float_recip2_ps();
4947 GEN_STORE_FTN_FREG(fd, WT2);
4948 GEN_STORE_FTN_FREG(fd, WTH2);
4952 check_cp1_64bitmode(ctx);
4953 GEN_LOAD_FREG_FTN(WT0, fs);
4954 GEN_LOAD_FREG_FTN(WTH0, fs);
4955 gen_op_float_recip1_ps();
4956 GEN_STORE_FTN_FREG(fd, WT2);
4957 GEN_STORE_FTN_FREG(fd, WTH2);
4961 check_cp1_64bitmode(ctx);
4962 GEN_LOAD_FREG_FTN(WT0, fs);
4963 GEN_LOAD_FREG_FTN(WTH0, fs);
4964 gen_op_float_rsqrt1_ps();
4965 GEN_STORE_FTN_FREG(fd, WT2);
4966 GEN_STORE_FTN_FREG(fd, WTH2);
4970 check_cp1_64bitmode(ctx);
4971 GEN_LOAD_FREG_FTN(WT0, fs);
4972 GEN_LOAD_FREG_FTN(WTH0, fs);
4973 GEN_LOAD_FREG_FTN(WT2, fd);
4974 GEN_LOAD_FREG_FTN(WTH2, fd);
4975 gen_op_float_rsqrt2_ps();
4976 GEN_STORE_FTN_FREG(fd, WT2);
4977 GEN_STORE_FTN_FREG(fd, WTH2);
4981 check_cp1_64bitmode(ctx);
4982 GEN_LOAD_FREG_FTN(WTH0, fs);
4983 gen_op_float_cvts_pu();
4984 GEN_STORE_FTN_FREG(fd, WT2);
4988 check_cp1_64bitmode(ctx);
4989 GEN_LOAD_FREG_FTN(WT0, fs);
4990 GEN_LOAD_FREG_FTN(WTH0, fs);
4991 gen_op_float_cvtpw_ps();
4992 GEN_STORE_FTN_FREG(fd, WT2);
4993 GEN_STORE_FTN_FREG(fd, WTH2);
4997 check_cp1_64bitmode(ctx);
4998 GEN_LOAD_FREG_FTN(WT0, fs);
4999 gen_op_float_cvts_pl();
5000 GEN_STORE_FTN_FREG(fd, WT2);
5004 check_cp1_64bitmode(ctx);
5005 GEN_LOAD_FREG_FTN(WT0, fs);
5006 GEN_LOAD_FREG_FTN(WT1, ft);
5007 gen_op_float_pll_ps();
5008 GEN_STORE_FTN_FREG(fd, DT2);
5012 check_cp1_64bitmode(ctx);
5013 GEN_LOAD_FREG_FTN(WT0, fs);
5014 GEN_LOAD_FREG_FTN(WTH1, ft);
5015 gen_op_float_plu_ps();
5016 GEN_STORE_FTN_FREG(fd, DT2);
5020 check_cp1_64bitmode(ctx);
5021 GEN_LOAD_FREG_FTN(WTH0, fs);
5022 GEN_LOAD_FREG_FTN(WT1, ft);
5023 gen_op_float_pul_ps();
5024 GEN_STORE_FTN_FREG(fd, DT2);
5028 check_cp1_64bitmode(ctx);
5029 GEN_LOAD_FREG_FTN(WTH0, fs);
5030 GEN_LOAD_FREG_FTN(WTH1, ft);
5031 gen_op_float_puu_ps();
5032 GEN_STORE_FTN_FREG(fd, DT2);
5051 check_cp1_64bitmode(ctx);
5052 GEN_LOAD_FREG_FTN(WT0, fs);
5053 GEN_LOAD_FREG_FTN(WTH0, fs);
5054 GEN_LOAD_FREG_FTN(WT1, ft);
5055 GEN_LOAD_FREG_FTN(WTH1, ft);
5056 if (ctx->opcode & (1 << 6)) {
5057 gen_cmpabs_ps(func-48, cc);
5058 opn = condnames_abs[func-48];
5060 gen_cmp_ps(func-48, cc);
5061 opn = condnames[func-48];
5066 generate_exception (ctx, EXCP_RI);
5071 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
5074 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
5077 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
5082 /* Coprocessor 3 (FPU) */
5083 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
5084 int fd, int fs, int base, int index)
5086 const char *opn = "extended float load/store";
5089 /* All of those work only on 64bit FPUs. */
5090 check_cp1_64bitmode(ctx);
5095 GEN_LOAD_REG_TN(T0, index);
5096 } else if (index == 0) {
5097 GEN_LOAD_REG_TN(T0, base);
5099 GEN_LOAD_REG_TN(T0, base);
5100 GEN_LOAD_REG_TN(T1, index);
5103 /* Don't do NOP if destination is zero: we must perform the actual
5109 GEN_STORE_FTN_FREG(fd, WT0);
5114 GEN_STORE_FTN_FREG(fd, DT0);
5119 GEN_STORE_FTN_FREG(fd, DT0);
5123 GEN_LOAD_FREG_FTN(WT0, fs);
5129 GEN_LOAD_FREG_FTN(DT0, fs);
5135 GEN_LOAD_FREG_FTN(DT0, fs);
5142 generate_exception(ctx, EXCP_RI);
5145 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
5146 regnames[index], regnames[base]);
5149 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
5150 int fd, int fr, int fs, int ft)
5152 const char *opn = "flt3_arith";
5154 /* All of those work only on 64bit FPUs. */
5155 check_cp1_64bitmode(ctx);
5158 GEN_LOAD_REG_TN(T0, fr);
5159 GEN_LOAD_FREG_FTN(DT0, fs);
5160 GEN_LOAD_FREG_FTN(DT1, ft);
5161 gen_op_float_alnv_ps();
5162 GEN_STORE_FTN_FREG(fd, DT2);
5166 GEN_LOAD_FREG_FTN(WT0, fs);
5167 GEN_LOAD_FREG_FTN(WT1, ft);
5168 GEN_LOAD_FREG_FTN(WT2, fr);
5169 gen_op_float_muladd_s();
5170 GEN_STORE_FTN_FREG(fd, WT2);
5174 GEN_LOAD_FREG_FTN(DT0, fs);
5175 GEN_LOAD_FREG_FTN(DT1, ft);
5176 GEN_LOAD_FREG_FTN(DT2, fr);
5177 gen_op_float_muladd_d();
5178 GEN_STORE_FTN_FREG(fd, DT2);
5182 GEN_LOAD_FREG_FTN(WT0, fs);
5183 GEN_LOAD_FREG_FTN(WTH0, fs);
5184 GEN_LOAD_FREG_FTN(WT1, ft);
5185 GEN_LOAD_FREG_FTN(WTH1, ft);
5186 GEN_LOAD_FREG_FTN(WT2, fr);
5187 GEN_LOAD_FREG_FTN(WTH2, fr);
5188 gen_op_float_muladd_ps();
5189 GEN_STORE_FTN_FREG(fd, WT2);
5190 GEN_STORE_FTN_FREG(fd, WTH2);
5194 GEN_LOAD_FREG_FTN(WT0, fs);
5195 GEN_LOAD_FREG_FTN(WT1, ft);
5196 GEN_LOAD_FREG_FTN(WT2, fr);
5197 gen_op_float_mulsub_s();
5198 GEN_STORE_FTN_FREG(fd, WT2);
5202 GEN_LOAD_FREG_FTN(DT0, fs);
5203 GEN_LOAD_FREG_FTN(DT1, ft);
5204 GEN_LOAD_FREG_FTN(DT2, fr);
5205 gen_op_float_mulsub_d();
5206 GEN_STORE_FTN_FREG(fd, DT2);
5210 GEN_LOAD_FREG_FTN(WT0, fs);
5211 GEN_LOAD_FREG_FTN(WTH0, fs);
5212 GEN_LOAD_FREG_FTN(WT1, ft);
5213 GEN_LOAD_FREG_FTN(WTH1, ft);
5214 GEN_LOAD_FREG_FTN(WT2, fr);
5215 GEN_LOAD_FREG_FTN(WTH2, fr);
5216 gen_op_float_mulsub_ps();
5217 GEN_STORE_FTN_FREG(fd, WT2);
5218 GEN_STORE_FTN_FREG(fd, WTH2);
5222 GEN_LOAD_FREG_FTN(WT0, fs);
5223 GEN_LOAD_FREG_FTN(WT1, ft);
5224 GEN_LOAD_FREG_FTN(WT2, fr);
5225 gen_op_float_nmuladd_s();
5226 GEN_STORE_FTN_FREG(fd, WT2);
5230 GEN_LOAD_FREG_FTN(DT0, fs);
5231 GEN_LOAD_FREG_FTN(DT1, ft);
5232 GEN_LOAD_FREG_FTN(DT2, fr);
5233 gen_op_float_nmuladd_d();
5234 GEN_STORE_FTN_FREG(fd, DT2);
5238 GEN_LOAD_FREG_FTN(WT0, fs);
5239 GEN_LOAD_FREG_FTN(WTH0, fs);
5240 GEN_LOAD_FREG_FTN(WT1, ft);
5241 GEN_LOAD_FREG_FTN(WTH1, ft);
5242 GEN_LOAD_FREG_FTN(WT2, fr);
5243 GEN_LOAD_FREG_FTN(WTH2, fr);
5244 gen_op_float_nmuladd_ps();
5245 GEN_STORE_FTN_FREG(fd, WT2);
5246 GEN_STORE_FTN_FREG(fd, WTH2);
5250 GEN_LOAD_FREG_FTN(WT0, fs);
5251 GEN_LOAD_FREG_FTN(WT1, ft);
5252 GEN_LOAD_FREG_FTN(WT2, fr);
5253 gen_op_float_nmulsub_s();
5254 GEN_STORE_FTN_FREG(fd, WT2);
5258 GEN_LOAD_FREG_FTN(DT0, fs);
5259 GEN_LOAD_FREG_FTN(DT1, ft);
5260 GEN_LOAD_FREG_FTN(DT2, fr);
5261 gen_op_float_nmulsub_d();
5262 GEN_STORE_FTN_FREG(fd, DT2);
5266 GEN_LOAD_FREG_FTN(WT0, fs);
5267 GEN_LOAD_FREG_FTN(WTH0, fs);
5268 GEN_LOAD_FREG_FTN(WT1, ft);
5269 GEN_LOAD_FREG_FTN(WTH1, ft);
5270 GEN_LOAD_FREG_FTN(WT2, fr);
5271 GEN_LOAD_FREG_FTN(WTH2, fr);
5272 gen_op_float_nmulsub_ps();
5273 GEN_STORE_FTN_FREG(fd, WT2);
5274 GEN_STORE_FTN_FREG(fd, WTH2);
5279 generate_exception (ctx, EXCP_RI);
5282 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
5283 fregnames[fs], fregnames[ft]);
5286 /* ISA extensions (ASEs) */
5287 /* MIPS16 extension to MIPS32 */
5288 /* SmartMIPS extension to MIPS32 */
5290 #ifdef TARGET_MIPS64
5292 /* MDMX extension to MIPS64 */
5293 /* MIPS-3D extension to MIPS64 */
5297 static void decode_opc (CPUState *env, DisasContext *ctx)
5301 uint32_t op, op1, op2;
5304 /* make sure instructions are on a word boundary */
5305 if (ctx->pc & 0x3) {
5306 env->CP0_BadVAddr = ctx->pc;
5307 generate_exception(ctx, EXCP_AdEL);
5311 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
5313 /* Handle blikely not taken case */
5314 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
5315 l1 = gen_new_label();
5317 gen_op_save_state(ctx->hflags & ~MIPS_HFLAG_BMASK);
5318 gen_goto_tb(ctx, 1, ctx->pc + 4);
5321 op = MASK_OP_MAJOR(ctx->opcode);
5322 rs = (ctx->opcode >> 21) & 0x1f;
5323 rt = (ctx->opcode >> 16) & 0x1f;
5324 rd = (ctx->opcode >> 11) & 0x1f;
5325 sa = (ctx->opcode >> 6) & 0x1f;
5326 imm = (int16_t)ctx->opcode;
5329 op1 = MASK_SPECIAL(ctx->opcode);
5331 case OPC_SLL: /* Arithmetic with immediate */
5332 case OPC_SRL ... OPC_SRA:
5333 gen_arith_imm(ctx, op1, rd, rt, sa);
5335 case OPC_SLLV: /* Arithmetic */
5336 case OPC_SRLV ... OPC_SRAV:
5337 case OPC_MOVZ ... OPC_MOVN:
5338 case OPC_ADD ... OPC_NOR:
5339 case OPC_SLT ... OPC_SLTU:
5340 gen_arith(ctx, op1, rd, rs, rt);
5342 case OPC_MULT ... OPC_DIVU:
5343 gen_muldiv(ctx, op1, rs, rt);
5345 case OPC_JR ... OPC_JALR:
5346 gen_compute_branch(ctx, op1, rs, rd, sa);
5348 case OPC_TGE ... OPC_TEQ: /* Traps */
5350 gen_trap(ctx, op1, rs, rt, -1);
5352 case OPC_MFHI: /* Move from HI/LO */
5354 gen_HILO(ctx, op1, rd);
5357 case OPC_MTLO: /* Move to HI/LO */
5358 gen_HILO(ctx, op1, rs);
5360 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
5361 #ifdef MIPS_STRICT_STANDARD
5362 MIPS_INVAL("PMON / selsl");
5363 generate_exception(ctx, EXCP_RI);
5369 generate_exception(ctx, EXCP_SYSCALL);
5372 /* XXX: Hack to work around wrong handling of self-modifying code. */
5374 save_cpu_state(ctx, 1);
5376 generate_exception(ctx, EXCP_BREAK);
5379 #ifdef MIPS_STRICT_STANDARD
5381 generate_exception(ctx, EXCP_RI);
5383 /* Implemented as RI exception for now. */
5384 MIPS_INVAL("spim (unofficial)");
5385 generate_exception(ctx, EXCP_RI);
5389 /* Treat as a noop. */
5393 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5394 save_cpu_state(ctx, 1);
5395 check_cp1_enabled(ctx);
5396 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
5397 (ctx->opcode >> 16) & 1);
5399 generate_exception_err(ctx, EXCP_CpU, 1);
5403 #ifdef TARGET_MIPS64
5404 /* MIPS64 specific opcodes */
5406 case OPC_DSRL ... OPC_DSRA:
5408 case OPC_DSRL32 ... OPC_DSRA32:
5409 if (!(ctx->hflags & MIPS_HFLAG_64))
5410 generate_exception(ctx, EXCP_RI);
5411 gen_arith_imm(ctx, op1, rd, rt, sa);
5414 case OPC_DSRLV ... OPC_DSRAV:
5415 case OPC_DADD ... OPC_DSUBU:
5416 if (!(ctx->hflags & MIPS_HFLAG_64))
5417 generate_exception(ctx, EXCP_RI);
5418 gen_arith(ctx, op1, rd, rs, rt);
5420 case OPC_DMULT ... OPC_DDIVU:
5421 if (!(ctx->hflags & MIPS_HFLAG_64))
5422 generate_exception(ctx, EXCP_RI);
5423 gen_muldiv(ctx, op1, rs, rt);
5426 default: /* Invalid */
5427 MIPS_INVAL("special");
5428 generate_exception(ctx, EXCP_RI);
5433 op1 = MASK_SPECIAL2(ctx->opcode);
5435 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
5436 case OPC_MSUB ... OPC_MSUBU:
5437 gen_muldiv(ctx, op1, rs, rt);
5440 gen_arith(ctx, op1, rd, rs, rt);
5442 case OPC_CLZ ... OPC_CLO:
5443 gen_cl(ctx, op1, rd, rs);
5446 /* XXX: not clear which exception should be raised
5447 * when in debug mode...
5449 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5450 generate_exception(ctx, EXCP_DBp);
5452 generate_exception(ctx, EXCP_DBp);
5454 /* Treat as a noop */
5456 #ifdef TARGET_MIPS64
5457 case OPC_DCLZ ... OPC_DCLO:
5458 if (!(ctx->hflags & MIPS_HFLAG_64))
5459 generate_exception(ctx, EXCP_RI);
5460 gen_cl(ctx, op1, rd, rs);
5463 default: /* Invalid */
5464 MIPS_INVAL("special2");
5465 generate_exception(ctx, EXCP_RI);
5470 op1 = MASK_SPECIAL3(ctx->opcode);
5474 gen_bitops(ctx, op1, rt, rs, sa, rd);
5477 op2 = MASK_BSHFL(ctx->opcode);
5480 GEN_LOAD_REG_TN(T1, rt);
5484 GEN_LOAD_REG_TN(T1, rt);
5488 GEN_LOAD_REG_TN(T1, rt);
5491 default: /* Invalid */
5492 MIPS_INVAL("bshfl");
5493 generate_exception(ctx, EXCP_RI);
5496 GEN_STORE_TN_REG(rd, T0);
5501 save_cpu_state(ctx, 1);
5502 gen_op_rdhwr_cpunum();
5505 save_cpu_state(ctx, 1);
5506 gen_op_rdhwr_synci_step();
5509 save_cpu_state(ctx, 1);
5513 save_cpu_state(ctx, 1);
5514 gen_op_rdhwr_ccres();
5517 #if defined (CONFIG_USER_ONLY)
5518 gen_op_tls_value ();
5521 default: /* Invalid */
5522 MIPS_INVAL("rdhwr");
5523 generate_exception(ctx, EXCP_RI);
5526 GEN_STORE_TN_REG(rt, T0);
5528 #ifdef TARGET_MIPS64
5529 case OPC_DEXTM ... OPC_DEXT:
5530 case OPC_DINSM ... OPC_DINS:
5531 if (!(ctx->hflags & MIPS_HFLAG_64))
5532 generate_exception(ctx, EXCP_RI);
5533 gen_bitops(ctx, op1, rt, rs, sa, rd);
5536 if (!(ctx->hflags & MIPS_HFLAG_64))
5537 generate_exception(ctx, EXCP_RI);
5538 op2 = MASK_DBSHFL(ctx->opcode);
5541 GEN_LOAD_REG_TN(T1, rt);
5545 GEN_LOAD_REG_TN(T1, rt);
5548 default: /* Invalid */
5549 MIPS_INVAL("dbshfl");
5550 generate_exception(ctx, EXCP_RI);
5553 GEN_STORE_TN_REG(rd, T0);
5555 default: /* Invalid */
5556 MIPS_INVAL("special3");
5557 generate_exception(ctx, EXCP_RI);
5562 op1 = MASK_REGIMM(ctx->opcode);
5564 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
5565 case OPC_BLTZAL ... OPC_BGEZALL:
5566 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
5568 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
5570 gen_trap(ctx, op1, rs, -1, imm);
5575 default: /* Invalid */
5576 MIPS_INVAL("regimm");
5577 generate_exception(ctx, EXCP_RI);
5582 save_cpu_state(ctx, 1);
5583 gen_op_cp0_enabled();
5584 op1 = MASK_CP0(ctx->opcode);
5588 #ifdef TARGET_MIPS64
5592 gen_cp0(env, ctx, op1, rt, rd);
5594 case OPC_C0_FIRST ... OPC_C0_LAST:
5595 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
5598 op2 = MASK_MFMC0(ctx->opcode);
5602 /* Stop translation as we may have switched the execution mode */
5603 ctx->bstate = BS_STOP;
5607 /* Stop translation as we may have switched the execution mode */
5608 ctx->bstate = BS_STOP;
5610 default: /* Invalid */
5611 MIPS_INVAL("mfmc0");
5612 generate_exception(ctx, EXCP_RI);
5615 GEN_STORE_TN_REG(rt, T0);
5619 if ((env->CP0_Config0 & (0x7 << CP0C0_AR)) == (1 << CP0C0_AR)) {
5620 /* Shadow registers not implemented. */
5621 GEN_LOAD_REG_TN(T0, rt);
5622 GEN_STORE_TN_REG(rd, T0);
5624 MIPS_INVAL("shadow register move");
5625 generate_exception(ctx, EXCP_RI);
5630 generate_exception(ctx, EXCP_RI);
5634 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
5635 gen_arith_imm(ctx, op, rt, rs, imm);
5637 case OPC_J ... OPC_JAL: /* Jump */
5638 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
5639 gen_compute_branch(ctx, op, rs, rt, offset);
5641 case OPC_BEQ ... OPC_BGTZ: /* Branch */
5642 case OPC_BEQL ... OPC_BGTZL:
5643 gen_compute_branch(ctx, op, rs, rt, imm << 2);
5645 case OPC_LB ... OPC_LWR: /* Load and stores */
5646 case OPC_SB ... OPC_SW:
5650 gen_ldst(ctx, op, rt, rs, imm);
5653 /* Treat as a noop */
5656 /* Treat as a noop */
5659 /* Floating point (COP1). */
5664 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5665 save_cpu_state(ctx, 1);
5666 check_cp1_enabled(ctx);
5667 gen_flt_ldst(ctx, op, rt, rs, imm);
5669 generate_exception_err(ctx, EXCP_CpU, 1);
5674 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5675 save_cpu_state(ctx, 1);
5676 check_cp1_enabled(ctx);
5677 op1 = MASK_CP1(ctx->opcode);
5683 #ifdef TARGET_MIPS64
5689 gen_cp1(ctx, op1, rt, rd);
5694 gen_compute_branch1(ctx, MASK_BC1(ctx->opcode),
5695 (rt >> 2) & 0x7, imm << 2);
5702 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
5707 generate_exception (ctx, EXCP_RI);
5711 generate_exception_err(ctx, EXCP_CpU, 1);
5721 /* COP2: Not implemented. */
5722 generate_exception_err(ctx, EXCP_CpU, 2);
5726 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5727 save_cpu_state(ctx, 1);
5728 check_cp1_enabled(ctx);
5729 op1 = MASK_CP3(ctx->opcode);
5737 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
5755 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
5759 generate_exception (ctx, EXCP_RI);
5763 generate_exception_err(ctx, EXCP_CpU, 1);
5767 #ifdef TARGET_MIPS64
5768 /* MIPS64 opcodes */
5770 case OPC_LDL ... OPC_LDR:
5771 case OPC_SDL ... OPC_SDR:
5776 if (!(ctx->hflags & MIPS_HFLAG_64))
5777 generate_exception(ctx, EXCP_RI);
5778 gen_ldst(ctx, op, rt, rs, imm);
5780 case OPC_DADDI ... OPC_DADDIU:
5781 if (!(ctx->hflags & MIPS_HFLAG_64))
5782 generate_exception(ctx, EXCP_RI);
5783 gen_arith_imm(ctx, op, rt, rs, imm);
5786 #ifdef MIPS_HAS_MIPS16
5788 /* MIPS16: Not implemented. */
5790 #ifdef MIPS_HAS_MDMX
5792 /* MDMX: Not implemented. */
5794 default: /* Invalid */
5795 MIPS_INVAL("major opcode");
5796 generate_exception(ctx, EXCP_RI);
5799 if (ctx->hflags & MIPS_HFLAG_BMASK) {
5800 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
5801 /* Branches completion */
5802 ctx->hflags &= ~MIPS_HFLAG_BMASK;
5803 ctx->bstate = BS_BRANCH;
5804 save_cpu_state(ctx, 0);
5807 /* unconditional branch */
5808 MIPS_DEBUG("unconditional branch");
5809 gen_goto_tb(ctx, 0, ctx->btarget);
5812 /* blikely taken case */
5813 MIPS_DEBUG("blikely branch taken");
5814 gen_goto_tb(ctx, 0, ctx->btarget);
5817 /* Conditional branch */
5818 MIPS_DEBUG("conditional branch");
5821 l1 = gen_new_label();
5823 gen_goto_tb(ctx, 1, ctx->pc + 4);
5825 gen_goto_tb(ctx, 0, ctx->btarget);
5829 /* unconditional branch to register */
5830 MIPS_DEBUG("branch to register");
5836 MIPS_DEBUG("unknown branch");
5843 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
5847 target_ulong pc_start;
5848 uint16_t *gen_opc_end;
5851 if (search_pc && loglevel)
5852 fprintf (logfile, "search pc %d\n", search_pc);
5855 gen_opc_ptr = gen_opc_buf;
5856 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
5857 gen_opparam_ptr = gen_opparam_buf;
5862 ctx.bstate = BS_NONE;
5863 /* Restore delay slot state from the tb context. */
5864 ctx.hflags = tb->flags;
5865 restore_cpu_state(env, &ctx);
5866 #if defined(CONFIG_USER_ONLY)
5869 ctx.mem_idx = !((ctx.hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM);
5872 if (loglevel & CPU_LOG_TB_CPU) {
5873 fprintf(logfile, "------------------------------------------------\n");
5874 /* FIXME: This may print out stale hflags from env... */
5875 cpu_dump_state(env, logfile, fprintf, 0);
5878 #ifdef MIPS_DEBUG_DISAS
5879 if (loglevel & CPU_LOG_TB_IN_ASM)
5880 fprintf(logfile, "\ntb %p super %d cond %04x\n",
5881 tb, ctx.mem_idx, ctx.hflags);
5883 while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) {
5884 if (env->nb_breakpoints > 0) {
5885 for(j = 0; j < env->nb_breakpoints; j++) {
5886 if (env->breakpoints[j] == ctx.pc) {
5887 save_cpu_state(&ctx, 1);
5888 ctx.bstate = BS_BRANCH;
5890 goto done_generating;
5896 j = gen_opc_ptr - gen_opc_buf;
5900 gen_opc_instr_start[lj++] = 0;
5902 gen_opc_pc[lj] = ctx.pc;
5903 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
5904 gen_opc_instr_start[lj] = 1;
5906 ctx.opcode = ldl_code(ctx.pc);
5907 decode_opc(env, &ctx);
5910 if (env->singlestep_enabled)
5913 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
5916 #if defined (MIPS_SINGLE_STEP)
5920 if (env->singlestep_enabled) {
5921 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
5924 switch (ctx.bstate) {
5926 gen_op_interrupt_restart();
5927 gen_goto_tb(&ctx, 0, ctx.pc);
5930 save_cpu_state(&ctx, 0);
5931 gen_goto_tb(&ctx, 0, ctx.pc);
5934 gen_op_interrupt_restart();
5944 *gen_opc_ptr = INDEX_op_end;
5946 j = gen_opc_ptr - gen_opc_buf;
5949 gen_opc_instr_start[lj++] = 0;
5952 tb->size = ctx.pc - pc_start;
5955 #if defined MIPS_DEBUG_DISAS
5956 if (loglevel & CPU_LOG_TB_IN_ASM)
5957 fprintf(logfile, "\n");
5959 if (loglevel & CPU_LOG_TB_IN_ASM) {
5960 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
5961 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
5962 fprintf(logfile, "\n");
5964 if (loglevel & CPU_LOG_TB_OP) {
5965 fprintf(logfile, "OP:\n");
5966 dump_ops(gen_opc_buf, gen_opparam_buf);
5967 fprintf(logfile, "\n");
5969 if (loglevel & CPU_LOG_TB_CPU) {
5970 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
5977 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
5979 return gen_intermediate_code_internal(env, tb, 0);
5982 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
5984 return gen_intermediate_code_internal(env, tb, 1);
5987 void fpu_dump_state(CPUState *env, FILE *f,
5988 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
5992 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
5994 #define printfpr(fp) \
5997 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
5998 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
5999 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
6002 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
6003 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
6004 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
6005 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
6006 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
6011 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
6012 env->fcr0, env->fcr31, is_fpu64, env->fp_status, get_float_exception_flags(&env->fp_status));
6013 fpu_fprintf(f, "FT0: "); printfpr(&env->ft0);
6014 fpu_fprintf(f, "FT1: "); printfpr(&env->ft1);
6015 fpu_fprintf(f, "FT2: "); printfpr(&env->ft2);
6016 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
6017 fpu_fprintf(f, "%3s: ", fregnames[i]);
6018 printfpr(&env->fpr[i]);
6024 void dump_fpu (CPUState *env)
6027 fprintf(logfile, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " %d\n",
6028 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
6029 fpu_dump_state(env, logfile, fprintf, 0);
6033 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6034 /* Debug help: The architecture requires 32bit code to maintain proper
6035 sign-extened values on 64bit machines. */
6037 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
6039 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
6040 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6045 if (!SIGN_EXT_P(env->PC))
6046 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->PC);
6047 if (!SIGN_EXT_P(env->HI))
6048 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->HI);
6049 if (!SIGN_EXT_P(env->LO))
6050 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->LO);
6051 if (!SIGN_EXT_P(env->btarget))
6052 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
6054 for (i = 0; i < 32; i++) {
6055 if (!SIGN_EXT_P(env->gpr[i]))
6056 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->gpr[i]);
6059 if (!SIGN_EXT_P(env->CP0_EPC))
6060 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
6061 if (!SIGN_EXT_P(env->CP0_LLAddr))
6062 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
6066 void cpu_dump_state (CPUState *env, FILE *f,
6067 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6072 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",
6073 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
6074 for (i = 0; i < 32; i++) {
6076 cpu_fprintf(f, "GPR%02d:", i);
6077 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->gpr[i]);
6079 cpu_fprintf(f, "\n");
6082 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
6083 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
6084 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
6085 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
6086 if (env->hflags & MIPS_HFLAG_FPU)
6087 fpu_dump_state(env, f, cpu_fprintf, flags);
6088 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6089 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
6093 CPUMIPSState *cpu_mips_init (void)
6097 env = qemu_mallocz(sizeof(CPUMIPSState));
6105 void cpu_reset (CPUMIPSState *env)
6107 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
6112 #if !defined(CONFIG_USER_ONLY)
6113 if (env->hflags & MIPS_HFLAG_BMASK) {
6114 /* If the exception was raised from a delay slot,
6115 * come back to the jump. */
6116 env->CP0_ErrorEPC = env->PC - 4;
6118 env->CP0_ErrorEPC = env->PC;
6120 #ifdef TARGET_MIPS64
6121 env->hflags = MIPS_HFLAG_64;
6125 env->PC = (int32_t)0xBFC00000;
6127 /* SMP not implemented */
6128 env->CP0_EBase = 0x80000000;
6129 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
6130 /* vectored interrupts not implemented, timer on int 7,
6131 no performance counters. */
6132 env->CP0_IntCtl = 0xe0000000;
6136 for (i = 0; i < 7; i++) {
6137 env->CP0_WatchLo[i] = 0;
6138 env->CP0_WatchHi[i] = 0x80000000;
6140 env->CP0_WatchLo[7] = 0;
6141 env->CP0_WatchHi[7] = 0;
6143 /* Count register increments in debug mode, EJTAG version 1 */
6144 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
6146 env->exception_index = EXCP_NONE;
6147 #if defined(CONFIG_USER_ONLY)
6148 env->hflags |= MIPS_HFLAG_UM;
6149 env->user_mode_only = 1;
6153 #include "translate_init.c"