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(fmt) \
494 static GenOpFunc1 * cond_ ## fmt ## _table[16] = { \
495 gen_op_cmp_ ## fmt ## _f, \
496 gen_op_cmp_ ## fmt ## _un, \
497 gen_op_cmp_ ## fmt ## _eq, \
498 gen_op_cmp_ ## fmt ## _ueq, \
499 gen_op_cmp_ ## fmt ## _olt, \
500 gen_op_cmp_ ## fmt ## _ult, \
501 gen_op_cmp_ ## fmt ## _ole, \
502 gen_op_cmp_ ## fmt ## _ule, \
503 gen_op_cmp_ ## fmt ## _sf, \
504 gen_op_cmp_ ## fmt ## _ngle, \
505 gen_op_cmp_ ## fmt ## _seq, \
506 gen_op_cmp_ ## fmt ## _ngl, \
507 gen_op_cmp_ ## fmt ## _lt, \
508 gen_op_cmp_ ## fmt ## _nge, \
509 gen_op_cmp_ ## fmt ## _le, \
510 gen_op_cmp_ ## fmt ## _ngt, \
512 static inline void gen_cmp_ ## fmt(int n, long cc) \
514 cond_ ## fmt ## _table[n](cc); \
521 typedef struct DisasContext {
522 struct TranslationBlock *tb;
523 target_ulong pc, saved_pc;
525 uint32_t fp_status, saved_fp_status;
526 /* Routine used to access memory */
528 uint32_t hflags, saved_hflags;
531 target_ulong btarget;
535 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
536 * exception condition
538 BS_STOP = 1, /* We want to stop translation for any reason */
539 BS_BRANCH = 2, /* We reached a branch condition */
540 BS_EXCP = 3, /* We reached an exception condition */
543 #ifdef MIPS_DEBUG_DISAS
544 #define MIPS_DEBUG(fmt, args...) \
546 if (loglevel & CPU_LOG_TB_IN_ASM) { \
547 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
548 ctx->pc, ctx->opcode , ##args); \
552 #define MIPS_DEBUG(fmt, args...) do { } while(0)
555 #define MIPS_INVAL(op) \
557 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
558 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
561 #define GEN_LOAD_REG_TN(Tn, Rn) \
564 glue(gen_op_reset_, Tn)(); \
566 glue(gen_op_load_gpr_, Tn)(Rn); \
570 #define GEN_LOAD_IMM_TN(Tn, Imm) \
573 glue(gen_op_reset_, Tn)(); \
575 glue(gen_op_set_, Tn)(Imm); \
579 #define GEN_STORE_TN_REG(Rn, Tn) \
582 glue(glue(gen_op_store_, Tn),_gpr)(Rn); \
586 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
588 glue(gen_op_load_fpr_, FTn)(Fn); \
591 #define GEN_STORE_FTN_FREG(Fn, FTn) \
593 glue(gen_op_store_fpr_, FTn)(Fn); \
596 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
598 #if defined MIPS_DEBUG_DISAS
599 if (loglevel & CPU_LOG_TB_IN_ASM) {
600 fprintf(logfile, "hflags %08x saved %08x\n",
601 ctx->hflags, ctx->saved_hflags);
604 if (do_save_pc && ctx->pc != ctx->saved_pc) {
605 gen_op_save_pc(ctx->pc);
606 ctx->saved_pc = ctx->pc;
608 if (ctx->hflags != ctx->saved_hflags) {
609 gen_op_save_state(ctx->hflags);
610 ctx->saved_hflags = ctx->hflags;
611 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
613 gen_op_save_breg_target();
619 /* bcond was already saved by the BL insn */
622 gen_op_save_btarget(ctx->btarget);
628 static inline void save_fpu_state (DisasContext *ctx)
630 if (ctx->fp_status != ctx->saved_fp_status) {
631 gen_op_save_fp_status(ctx->fp_status);
632 ctx->saved_fp_status = ctx->fp_status;
636 static inline void generate_exception_err (DisasContext *ctx, int excp, int err)
638 #if defined MIPS_DEBUG_DISAS
639 if (loglevel & CPU_LOG_TB_IN_ASM)
640 fprintf(logfile, "%s: raise exception %d\n", __func__, excp);
642 save_cpu_state(ctx, 1);
644 gen_op_raise_exception(excp);
646 gen_op_raise_exception_err(excp, err);
647 ctx->bstate = BS_EXCP;
650 static inline void generate_exception (DisasContext *ctx, int excp)
652 generate_exception_err (ctx, excp, 0);
655 #if defined(CONFIG_USER_ONLY)
656 #define op_ldst(name) gen_op_##name##_raw()
657 #define OP_LD_TABLE(width)
658 #define OP_ST_TABLE(width)
660 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
661 #define OP_LD_TABLE(width) \
662 static GenOpFunc *gen_op_l##width[] = { \
663 &gen_op_l##width##_user, \
664 &gen_op_l##width##_kernel, \
666 #define OP_ST_TABLE(width) \
667 static GenOpFunc *gen_op_s##width[] = { \
668 &gen_op_s##width##_user, \
669 &gen_op_s##width##_kernel, \
710 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
711 int base, int16_t offset)
713 const char *opn = "ldst";
716 GEN_LOAD_IMM_TN(T0, offset);
717 } else if (offset == 0) {
718 gen_op_load_gpr_T0(base);
720 gen_op_load_gpr_T0(base);
721 gen_op_set_T1(offset);
724 /* Don't do NOP if destination is zero: we must perform the actual
731 GEN_STORE_TN_REG(rt, T0);
736 GEN_STORE_TN_REG(rt, T0);
740 GEN_LOAD_REG_TN(T1, rt);
745 save_cpu_state(ctx, 1);
746 GEN_LOAD_REG_TN(T1, rt);
748 GEN_STORE_TN_REG(rt, T0);
753 GEN_STORE_TN_REG(rt, T0);
757 GEN_LOAD_REG_TN(T1, rt);
763 GEN_STORE_TN_REG(rt, T0);
767 GEN_LOAD_REG_TN(T1, rt);
774 GEN_STORE_TN_REG(rt, T0);
779 GEN_STORE_TN_REG(rt, T0);
783 GEN_LOAD_REG_TN(T1, rt);
789 GEN_STORE_TN_REG(rt, T0);
793 GEN_LOAD_REG_TN(T1, rt);
799 GEN_STORE_TN_REG(rt, T0);
804 GEN_STORE_TN_REG(rt, T0);
808 GEN_LOAD_REG_TN(T1, rt);
814 GEN_STORE_TN_REG(rt, T0);
818 GEN_LOAD_REG_TN(T1, rt);
820 GEN_STORE_TN_REG(rt, T0);
824 GEN_LOAD_REG_TN(T1, rt);
829 GEN_LOAD_REG_TN(T1, rt);
831 GEN_STORE_TN_REG(rt, T0);
835 GEN_LOAD_REG_TN(T1, rt);
841 GEN_STORE_TN_REG(rt, T0);
845 save_cpu_state(ctx, 1);
846 GEN_LOAD_REG_TN(T1, rt);
848 GEN_STORE_TN_REG(rt, T0);
853 generate_exception(ctx, EXCP_RI);
856 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
860 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
861 int base, int16_t offset)
863 const char *opn = "flt_ldst";
866 GEN_LOAD_IMM_TN(T0, offset);
867 } else if (offset == 0) {
868 gen_op_load_gpr_T0(base);
870 gen_op_load_gpr_T0(base);
871 gen_op_set_T1(offset);
874 /* Don't do NOP if destination is zero: we must perform the actual
880 GEN_STORE_FTN_FREG(ft, WT0);
884 GEN_LOAD_FREG_FTN(WT0, ft);
890 GEN_STORE_FTN_FREG(ft, DT0);
894 GEN_LOAD_FREG_FTN(DT0, ft);
900 generate_exception(ctx, EXCP_RI);
903 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
906 /* Arithmetic with immediate operand */
907 static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
911 const char *opn = "imm arith";
913 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
914 /* if no destination, treat it as a NOP
915 * For addi, we must generate the overflow exception when needed.
920 uimm = (uint16_t)imm;
930 uimm = (int32_t)imm; /* Sign extend to 32 bits */
935 GEN_LOAD_REG_TN(T0, rs);
936 GEN_LOAD_IMM_TN(T1, uimm);
939 GEN_LOAD_IMM_TN(T0, uimm << 16);
953 GEN_LOAD_REG_TN(T0, rs);
954 GEN_LOAD_IMM_TN(T1, uimm);
959 save_cpu_state(ctx, 1);
969 save_cpu_state(ctx, 1);
1010 switch ((ctx->opcode >> 21) & 0x1f) {
1020 MIPS_INVAL("invalid srl flag");
1021 generate_exception(ctx, EXCP_RI);
1025 #ifdef TARGET_MIPS64
1035 switch ((ctx->opcode >> 21) & 0x1f) {
1045 MIPS_INVAL("invalid dsrl flag");
1046 generate_exception(ctx, EXCP_RI);
1059 switch ((ctx->opcode >> 21) & 0x1f) {
1069 MIPS_INVAL("invalid dsrl32 flag");
1070 generate_exception(ctx, EXCP_RI);
1077 generate_exception(ctx, EXCP_RI);
1080 GEN_STORE_TN_REG(rt, T0);
1081 MIPS_DEBUG("%s %s, %s, %x", opn, regnames[rt], regnames[rs], uimm);
1085 static void gen_arith (DisasContext *ctx, uint32_t opc,
1086 int rd, int rs, int rt)
1088 const char *opn = "arith";
1090 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1091 && opc != OPC_DADD && opc != OPC_DSUB) {
1092 /* if no destination, treat it as a NOP
1093 * For add & sub, we must generate the overflow exception when needed.
1098 GEN_LOAD_REG_TN(T0, rs);
1099 GEN_LOAD_REG_TN(T1, rt);
1102 save_cpu_state(ctx, 1);
1111 save_cpu_state(ctx, 1);
1119 #ifdef TARGET_MIPS64
1121 save_cpu_state(ctx, 1);
1130 save_cpu_state(ctx, 1);
1184 switch ((ctx->opcode >> 6) & 0x1f) {
1194 MIPS_INVAL("invalid srlv flag");
1195 generate_exception(ctx, EXCP_RI);
1199 #ifdef TARGET_MIPS64
1209 switch ((ctx->opcode >> 6) & 0x1f) {
1219 MIPS_INVAL("invalid dsrlv flag");
1220 generate_exception(ctx, EXCP_RI);
1227 generate_exception(ctx, EXCP_RI);
1230 GEN_STORE_TN_REG(rd, T0);
1232 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1235 /* Arithmetic on HI/LO registers */
1236 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1238 const char *opn = "hilo";
1240 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1241 /* Treat as a NOP */
1248 GEN_STORE_TN_REG(reg, T0);
1253 GEN_STORE_TN_REG(reg, T0);
1257 GEN_LOAD_REG_TN(T0, reg);
1262 GEN_LOAD_REG_TN(T0, reg);
1268 generate_exception(ctx, EXCP_RI);
1271 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1274 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1277 const char *opn = "mul/div";
1279 GEN_LOAD_REG_TN(T0, rs);
1280 GEN_LOAD_REG_TN(T1, rt);
1298 #ifdef TARGET_MIPS64
1334 generate_exception(ctx, EXCP_RI);
1337 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
1340 static void gen_cl (DisasContext *ctx, uint32_t opc,
1343 const char *opn = "CLx";
1345 /* Treat as a NOP */
1349 GEN_LOAD_REG_TN(T0, rs);
1359 #ifdef TARGET_MIPS64
1371 generate_exception(ctx, EXCP_RI);
1374 gen_op_store_T0_gpr(rd);
1375 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
1379 static void gen_trap (DisasContext *ctx, uint32_t opc,
1380 int rs, int rt, int16_t imm)
1385 /* Load needed operands */
1393 /* Compare two registers */
1395 GEN_LOAD_REG_TN(T0, rs);
1396 GEN_LOAD_REG_TN(T1, rt);
1406 /* Compare register to immediate */
1407 if (rs != 0 || imm != 0) {
1408 GEN_LOAD_REG_TN(T0, rs);
1409 GEN_LOAD_IMM_TN(T1, (int32_t)imm);
1416 case OPC_TEQ: /* rs == rs */
1417 case OPC_TEQI: /* r0 == 0 */
1418 case OPC_TGE: /* rs >= rs */
1419 case OPC_TGEI: /* r0 >= 0 */
1420 case OPC_TGEU: /* rs >= rs unsigned */
1421 case OPC_TGEIU: /* r0 >= 0 unsigned */
1425 case OPC_TLT: /* rs < rs */
1426 case OPC_TLTI: /* r0 < 0 */
1427 case OPC_TLTU: /* rs < rs unsigned */
1428 case OPC_TLTIU: /* r0 < 0 unsigned */
1429 case OPC_TNE: /* rs != rs */
1430 case OPC_TNEI: /* r0 != 0 */
1431 /* Never trap: treat as NOP */
1435 generate_exception(ctx, EXCP_RI);
1466 generate_exception(ctx, EXCP_RI);
1470 save_cpu_state(ctx, 1);
1472 ctx->bstate = BS_STOP;
1475 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
1477 TranslationBlock *tb;
1479 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
1481 gen_op_goto_tb0(TBPARAM(tb));
1483 gen_op_goto_tb1(TBPARAM(tb));
1484 gen_op_save_pc(dest);
1485 gen_op_set_T0((long)tb + n);
1487 gen_op_save_pc(dest);
1493 /* Branches (before delay slot) */
1494 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
1495 int rs, int rt, int32_t offset)
1497 target_ulong btarget = -1;
1501 if (ctx->hflags & MIPS_HFLAG_BMASK) {
1502 #ifdef MIPS_DEBUG_DISAS
1503 if (loglevel & CPU_LOG_TB_IN_ASM) {
1505 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
1509 generate_exception(ctx, EXCP_RI);
1513 /* Load needed operands */
1519 /* Compare two registers */
1521 GEN_LOAD_REG_TN(T0, rs);
1522 GEN_LOAD_REG_TN(T1, rt);
1525 btarget = ctx->pc + 4 + offset;
1539 /* Compare to zero */
1541 gen_op_load_gpr_T0(rs);
1544 btarget = ctx->pc + 4 + offset;
1548 /* Jump to immediate */
1549 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | offset;
1553 /* Jump to register */
1554 if (offset != 0 && offset != 16) {
1555 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1556 others are reserved. */
1557 MIPS_INVAL("jump hint");
1558 generate_exception(ctx, EXCP_RI);
1561 GEN_LOAD_REG_TN(T2, rs);
1564 MIPS_INVAL("branch/jump");
1565 generate_exception(ctx, EXCP_RI);
1569 /* No condition to be computed */
1571 case OPC_BEQ: /* rx == rx */
1572 case OPC_BEQL: /* rx == rx likely */
1573 case OPC_BGEZ: /* 0 >= 0 */
1574 case OPC_BGEZL: /* 0 >= 0 likely */
1575 case OPC_BLEZ: /* 0 <= 0 */
1576 case OPC_BLEZL: /* 0 <= 0 likely */
1578 ctx->hflags |= MIPS_HFLAG_B;
1579 MIPS_DEBUG("balways");
1581 case OPC_BGEZAL: /* 0 >= 0 */
1582 case OPC_BGEZALL: /* 0 >= 0 likely */
1583 /* Always take and link */
1585 ctx->hflags |= MIPS_HFLAG_B;
1586 MIPS_DEBUG("balways and link");
1588 case OPC_BNE: /* rx != rx */
1589 case OPC_BGTZ: /* 0 > 0 */
1590 case OPC_BLTZ: /* 0 < 0 */
1591 /* Treated as NOP */
1592 MIPS_DEBUG("bnever (NOP)");
1594 case OPC_BLTZAL: /* 0 < 0 */
1595 gen_op_set_T0(ctx->pc + 8);
1596 gen_op_store_T0_gpr(31);
1597 MIPS_DEBUG("bnever and link");
1599 case OPC_BLTZALL: /* 0 < 0 likely */
1600 gen_op_set_T0(ctx->pc + 8);
1601 gen_op_store_T0_gpr(31);
1602 /* Skip the instruction in the delay slot */
1603 MIPS_DEBUG("bnever, link and skip");
1606 case OPC_BNEL: /* rx != rx likely */
1607 case OPC_BGTZL: /* 0 > 0 likely */
1608 case OPC_BLTZL: /* 0 < 0 likely */
1609 /* Skip the instruction in the delay slot */
1610 MIPS_DEBUG("bnever and skip");
1614 ctx->hflags |= MIPS_HFLAG_B;
1615 MIPS_DEBUG("j " TARGET_FMT_lx, btarget);
1619 ctx->hflags |= MIPS_HFLAG_B;
1620 MIPS_DEBUG("jal " TARGET_FMT_lx, btarget);
1623 ctx->hflags |= MIPS_HFLAG_BR;
1624 MIPS_DEBUG("jr %s", regnames[rs]);
1628 ctx->hflags |= MIPS_HFLAG_BR;
1629 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
1632 MIPS_INVAL("branch/jump");
1633 generate_exception(ctx, EXCP_RI);
1640 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
1641 regnames[rs], regnames[rt], btarget);
1645 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
1646 regnames[rs], regnames[rt], btarget);
1650 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
1651 regnames[rs], regnames[rt], btarget);
1655 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
1656 regnames[rs], regnames[rt], btarget);
1660 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btarget);
1664 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1668 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btarget);
1674 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btarget);
1678 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btarget);
1682 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1686 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btarget);
1690 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1694 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btarget);
1698 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
1703 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btarget);
1705 ctx->hflags |= MIPS_HFLAG_BC;
1711 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btarget);
1713 ctx->hflags |= MIPS_HFLAG_BL;
1715 gen_op_save_bcond();
1718 MIPS_INVAL("conditional branch/jump");
1719 generate_exception(ctx, EXCP_RI);
1723 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
1724 blink, ctx->hflags, btarget);
1725 ctx->btarget = btarget;
1727 gen_op_set_T0(ctx->pc + 8);
1728 gen_op_store_T0_gpr(blink);
1732 /* special3 bitfield operations */
1733 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
1734 int rs, int lsb, int msb)
1736 GEN_LOAD_REG_TN(T1, rs);
1741 gen_op_ext(lsb, msb + 1);
1746 gen_op_ext(lsb, msb + 1 + 32);
1751 gen_op_ext(lsb + 32, msb + 1);
1754 gen_op_ext(lsb, msb + 1);
1759 GEN_LOAD_REG_TN(T0, rt);
1760 gen_op_ins(lsb, msb - lsb + 1);
1765 GEN_LOAD_REG_TN(T0, rt);
1766 gen_op_ins(lsb, msb - lsb + 1 + 32);
1771 GEN_LOAD_REG_TN(T0, rt);
1772 gen_op_ins(lsb + 32, msb - lsb + 1);
1777 GEN_LOAD_REG_TN(T0, rt);
1778 gen_op_ins(lsb, msb - lsb + 1);
1782 MIPS_INVAL("bitops");
1783 generate_exception(ctx, EXCP_RI);
1786 GEN_STORE_TN_REG(rt, T0);
1789 /* CP0 (MMU and control) */
1790 static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
1792 const char *rn = "invalid";
1798 gen_op_mfc0_index();
1802 // gen_op_mfc0_mvpcontrol(); /* MT ASE */
1806 // gen_op_mfc0_mvpconf0(); /* MT ASE */
1810 // gen_op_mfc0_mvpconf1(); /* MT ASE */
1820 gen_op_mfc0_random();
1824 // gen_op_mfc0_vpecontrol(); /* MT ASE */
1828 // gen_op_mfc0_vpeconf0(); /* MT ASE */
1832 // gen_op_mfc0_vpeconf1(); /* MT ASE */
1836 // gen_op_mfc0_YQMask(); /* MT ASE */
1840 // gen_op_mfc0_vpeschedule(); /* MT ASE */
1844 // gen_op_mfc0_vpeschefback(); /* MT ASE */
1845 rn = "VPEScheFBack";
1848 // gen_op_mfc0_vpeopt(); /* MT ASE */
1858 gen_op_mfc0_entrylo0();
1862 // gen_op_mfc0_tcstatus(); /* MT ASE */
1866 // gen_op_mfc0_tcbind(); /* MT ASE */
1870 // gen_op_mfc0_tcrestart(); /* MT ASE */
1874 // gen_op_mfc0_tchalt(); /* MT ASE */
1878 // gen_op_mfc0_tccontext(); /* MT ASE */
1882 // gen_op_mfc0_tcschedule(); /* MT ASE */
1886 // gen_op_mfc0_tcschefback(); /* MT ASE */
1896 gen_op_mfc0_entrylo1();
1906 gen_op_mfc0_context();
1910 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
1911 rn = "ContextConfig";
1920 gen_op_mfc0_pagemask();
1924 gen_op_mfc0_pagegrain();
1934 gen_op_mfc0_wired();
1938 // gen_op_mfc0_srsconf0(); /* shadow registers */
1942 // gen_op_mfc0_srsconf1(); /* shadow registers */
1946 // gen_op_mfc0_srsconf2(); /* shadow registers */
1950 // gen_op_mfc0_srsconf3(); /* shadow registers */
1954 // gen_op_mfc0_srsconf4(); /* shadow registers */
1964 gen_op_mfc0_hwrena();
1974 gen_op_mfc0_badvaddr();
1984 gen_op_mfc0_count();
1987 /* 6,7 are implementation dependent */
1995 gen_op_mfc0_entryhi();
2005 gen_op_mfc0_compare();
2008 /* 6,7 are implementation dependent */
2016 gen_op_mfc0_status();
2020 gen_op_mfc0_intctl();
2024 gen_op_mfc0_srsctl();
2028 // gen_op_mfc0_srsmap(); /* shadow registers */
2038 gen_op_mfc0_cause();
2062 gen_op_mfc0_ebase();
2072 gen_op_mfc0_config0();
2076 gen_op_mfc0_config1();
2080 gen_op_mfc0_config2();
2084 gen_op_mfc0_config3();
2087 /* 4,5 are reserved */
2088 /* 6,7 are implementation dependent */
2090 gen_op_mfc0_config6();
2094 gen_op_mfc0_config7();
2104 gen_op_mfc0_lladdr();
2114 gen_op_mfc0_watchlo0();
2118 // gen_op_mfc0_watchlo1();
2122 // gen_op_mfc0_watchlo2();
2126 // gen_op_mfc0_watchlo3();
2130 // gen_op_mfc0_watchlo4();
2134 // gen_op_mfc0_watchlo5();
2138 // gen_op_mfc0_watchlo6();
2142 // gen_op_mfc0_watchlo7();
2152 gen_op_mfc0_watchhi0();
2156 // gen_op_mfc0_watchhi1();
2160 // gen_op_mfc0_watchhi2();
2164 // gen_op_mfc0_watchhi3();
2168 // gen_op_mfc0_watchhi4();
2172 // gen_op_mfc0_watchhi5();
2176 // gen_op_mfc0_watchhi6();
2180 // gen_op_mfc0_watchhi7();
2190 /* 64 bit MMU only */
2191 gen_op_mfc0_xcontext();
2199 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2202 gen_op_mfc0_framemask();
2211 rn = "'Diagnostic"; /* implementation dependent */
2216 gen_op_mfc0_debug(); /* EJTAG support */
2220 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2221 rn = "TraceControl";
2224 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2225 rn = "TraceControl2";
2228 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2229 rn = "UserTraceData";
2232 // gen_op_mfc0_debug(); /* PDtrace support */
2242 gen_op_mfc0_depc(); /* EJTAG support */
2252 gen_op_mfc0_performance0();
2253 rn = "Performance0";
2256 // gen_op_mfc0_performance1();
2257 rn = "Performance1";
2260 // gen_op_mfc0_performance2();
2261 rn = "Performance2";
2264 // gen_op_mfc0_performance3();
2265 rn = "Performance3";
2268 // gen_op_mfc0_performance4();
2269 rn = "Performance4";
2272 // gen_op_mfc0_performance5();
2273 rn = "Performance5";
2276 // gen_op_mfc0_performance6();
2277 rn = "Performance6";
2280 // gen_op_mfc0_performance7();
2281 rn = "Performance7";
2306 gen_op_mfc0_taglo();
2313 gen_op_mfc0_datalo();
2326 gen_op_mfc0_taghi();
2333 gen_op_mfc0_datahi();
2343 gen_op_mfc0_errorepc();
2353 gen_op_mfc0_desave(); /* EJTAG support */
2363 #if defined MIPS_DEBUG_DISAS
2364 if (loglevel & CPU_LOG_TB_IN_ASM) {
2365 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2372 #if defined MIPS_DEBUG_DISAS
2373 if (loglevel & CPU_LOG_TB_IN_ASM) {
2374 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2378 generate_exception(ctx, EXCP_RI);
2381 static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
2383 const char *rn = "invalid";
2389 gen_op_mtc0_index();
2393 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
2397 // gen_op_mtc0_mvpconf0(); /* MT ASE */
2401 // gen_op_mtc0_mvpconf1(); /* MT ASE */
2415 // gen_op_mtc0_vpecontrol(); /* MT ASE */
2419 // gen_op_mtc0_vpeconf0(); /* MT ASE */
2423 // gen_op_mtc0_vpeconf1(); /* MT ASE */
2427 // gen_op_mtc0_YQMask(); /* MT ASE */
2431 // gen_op_mtc0_vpeschedule(); /* MT ASE */
2435 // gen_op_mtc0_vpeschefback(); /* MT ASE */
2436 rn = "VPEScheFBack";
2439 // gen_op_mtc0_vpeopt(); /* MT ASE */
2449 gen_op_mtc0_entrylo0();
2453 // gen_op_mtc0_tcstatus(); /* MT ASE */
2457 // gen_op_mtc0_tcbind(); /* MT ASE */
2461 // gen_op_mtc0_tcrestart(); /* MT ASE */
2465 // gen_op_mtc0_tchalt(); /* MT ASE */
2469 // gen_op_mtc0_tccontext(); /* MT ASE */
2473 // gen_op_mtc0_tcschedule(); /* MT ASE */
2477 // gen_op_mtc0_tcschefback(); /* MT ASE */
2487 gen_op_mtc0_entrylo1();
2497 gen_op_mtc0_context();
2501 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2502 rn = "ContextConfig";
2511 gen_op_mtc0_pagemask();
2515 gen_op_mtc0_pagegrain();
2525 gen_op_mtc0_wired();
2529 // gen_op_mtc0_srsconf0(); /* shadow registers */
2533 // gen_op_mtc0_srsconf1(); /* shadow registers */
2537 // gen_op_mtc0_srsconf2(); /* shadow registers */
2541 // gen_op_mtc0_srsconf3(); /* shadow registers */
2545 // gen_op_mtc0_srsconf4(); /* shadow registers */
2555 gen_op_mtc0_hwrena();
2569 gen_op_mtc0_count();
2572 /* 6,7 are implementation dependent */
2576 /* Stop translation as we may have switched the execution mode */
2577 ctx->bstate = BS_STOP;
2582 gen_op_mtc0_entryhi();
2592 gen_op_mtc0_compare();
2595 /* 6,7 are implementation dependent */
2599 /* Stop translation as we may have switched the execution mode */
2600 ctx->bstate = BS_STOP;
2605 gen_op_mtc0_status();
2609 gen_op_mtc0_intctl();
2613 gen_op_mtc0_srsctl();
2617 // gen_op_mtc0_srsmap(); /* shadow registers */
2623 /* Stop translation as we may have switched the execution mode */
2624 ctx->bstate = BS_STOP;
2629 gen_op_mtc0_cause();
2635 /* Stop translation as we may have switched the execution mode */
2636 ctx->bstate = BS_STOP;
2655 gen_op_mtc0_ebase();
2665 gen_op_mtc0_config0();
2667 /* Stop translation as we may have switched the execution mode */
2668 ctx->bstate = BS_STOP;
2671 /* ignored, read only */
2675 gen_op_mtc0_config2();
2677 /* Stop translation as we may have switched the execution mode */
2678 ctx->bstate = BS_STOP;
2681 /* ignored, read only */
2684 /* 4,5 are reserved */
2685 /* 6,7 are implementation dependent */
2695 rn = "Invalid config selector";
2712 gen_op_mtc0_watchlo0();
2716 // gen_op_mtc0_watchlo1();
2720 // gen_op_mtc0_watchlo2();
2724 // gen_op_mtc0_watchlo3();
2728 // gen_op_mtc0_watchlo4();
2732 // gen_op_mtc0_watchlo5();
2736 // gen_op_mtc0_watchlo6();
2740 // gen_op_mtc0_watchlo7();
2750 gen_op_mtc0_watchhi0();
2754 // gen_op_mtc0_watchhi1();
2758 // gen_op_mtc0_watchhi2();
2762 // gen_op_mtc0_watchhi3();
2766 // gen_op_mtc0_watchhi4();
2770 // gen_op_mtc0_watchhi5();
2774 // gen_op_mtc0_watchhi6();
2778 // gen_op_mtc0_watchhi7();
2788 /* 64 bit MMU only */
2789 /* Nothing writable in lower 32 bits */
2797 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2800 gen_op_mtc0_framemask();
2809 rn = "Diagnostic"; /* implementation dependent */
2814 gen_op_mtc0_debug(); /* EJTAG support */
2818 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2819 rn = "TraceControl";
2822 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2823 rn = "TraceControl2";
2826 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2827 rn = "UserTraceData";
2830 // gen_op_mtc0_debug(); /* PDtrace support */
2836 /* Stop translation as we may have switched the execution mode */
2837 ctx->bstate = BS_STOP;
2842 gen_op_mtc0_depc(); /* EJTAG support */
2852 gen_op_mtc0_performance0();
2853 rn = "Performance0";
2856 // gen_op_mtc0_performance1();
2857 rn = "Performance1";
2860 // gen_op_mtc0_performance2();
2861 rn = "Performance2";
2864 // gen_op_mtc0_performance3();
2865 rn = "Performance3";
2868 // gen_op_mtc0_performance4();
2869 rn = "Performance4";
2872 // gen_op_mtc0_performance5();
2873 rn = "Performance5";
2876 // gen_op_mtc0_performance6();
2877 rn = "Performance6";
2880 // gen_op_mtc0_performance7();
2881 rn = "Performance7";
2907 gen_op_mtc0_taglo();
2914 gen_op_mtc0_datalo();
2927 gen_op_mtc0_taghi();
2934 gen_op_mtc0_datahi();
2945 gen_op_mtc0_errorepc();
2955 gen_op_mtc0_desave(); /* EJTAG support */
2961 /* Stop translation as we may have switched the execution mode */
2962 ctx->bstate = BS_STOP;
2967 #if defined MIPS_DEBUG_DISAS
2968 if (loglevel & CPU_LOG_TB_IN_ASM) {
2969 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2976 #if defined MIPS_DEBUG_DISAS
2977 if (loglevel & CPU_LOG_TB_IN_ASM) {
2978 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2982 generate_exception(ctx, EXCP_RI);
2985 #ifdef TARGET_MIPS64
2986 static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
2988 const char *rn = "invalid";
2994 gen_op_mfc0_index();
2998 // gen_op_dmfc0_mvpcontrol(); /* MT ASE */
3002 // gen_op_dmfc0_mvpconf0(); /* MT ASE */
3006 // gen_op_dmfc0_mvpconf1(); /* MT ASE */
3016 gen_op_mfc0_random();
3020 // gen_op_dmfc0_vpecontrol(); /* MT ASE */
3024 // gen_op_dmfc0_vpeconf0(); /* MT ASE */
3028 // gen_op_dmfc0_vpeconf1(); /* MT ASE */
3032 // gen_op_dmfc0_YQMask(); /* MT ASE */
3036 // gen_op_dmfc0_vpeschedule(); /* MT ASE */
3040 // gen_op_dmfc0_vpeschefback(); /* MT ASE */
3041 rn = "VPEScheFBack";
3044 // gen_op_dmfc0_vpeopt(); /* MT ASE */
3054 gen_op_dmfc0_entrylo0();
3058 // gen_op_dmfc0_tcstatus(); /* MT ASE */
3062 // gen_op_dmfc0_tcbind(); /* MT ASE */
3066 // gen_op_dmfc0_tcrestart(); /* MT ASE */
3070 // gen_op_dmfc0_tchalt(); /* MT ASE */
3074 // gen_op_dmfc0_tccontext(); /* MT ASE */
3078 // gen_op_dmfc0_tcschedule(); /* MT ASE */
3082 // gen_op_dmfc0_tcschefback(); /* MT ASE */
3092 gen_op_dmfc0_entrylo1();
3102 gen_op_dmfc0_context();
3106 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3107 rn = "ContextConfig";
3116 gen_op_mfc0_pagemask();
3120 gen_op_mfc0_pagegrain();
3130 gen_op_mfc0_wired();
3134 // gen_op_dmfc0_srsconf0(); /* shadow registers */
3138 // gen_op_dmfc0_srsconf1(); /* shadow registers */
3142 // gen_op_dmfc0_srsconf2(); /* shadow registers */
3146 // gen_op_dmfc0_srsconf3(); /* shadow registers */
3150 // gen_op_dmfc0_srsconf4(); /* shadow registers */
3160 gen_op_mfc0_hwrena();
3170 gen_op_dmfc0_badvaddr();
3180 gen_op_mfc0_count();
3183 /* 6,7 are implementation dependent */
3191 gen_op_dmfc0_entryhi();
3201 gen_op_mfc0_compare();
3204 /* 6,7 are implementation dependent */
3212 gen_op_mfc0_status();
3216 gen_op_mfc0_intctl();
3220 gen_op_mfc0_srsctl();
3224 gen_op_mfc0_srsmap(); /* shadow registers */
3234 gen_op_mfc0_cause();
3258 gen_op_mfc0_ebase();
3268 gen_op_mfc0_config0();
3272 gen_op_mfc0_config1();
3276 gen_op_mfc0_config2();
3280 gen_op_mfc0_config3();
3283 /* 6,7 are implementation dependent */
3291 gen_op_dmfc0_lladdr();
3301 gen_op_dmfc0_watchlo0();
3305 // gen_op_dmfc0_watchlo1();
3309 // gen_op_dmfc0_watchlo2();
3313 // gen_op_dmfc0_watchlo3();
3317 // gen_op_dmfc0_watchlo4();
3321 // gen_op_dmfc0_watchlo5();
3325 // gen_op_dmfc0_watchlo6();
3329 // gen_op_dmfc0_watchlo7();
3339 gen_op_mfc0_watchhi0();
3343 // gen_op_mfc0_watchhi1();
3347 // gen_op_mfc0_watchhi2();
3351 // gen_op_mfc0_watchhi3();
3355 // gen_op_mfc0_watchhi4();
3359 // gen_op_mfc0_watchhi5();
3363 // gen_op_mfc0_watchhi6();
3367 // gen_op_mfc0_watchhi7();
3377 /* 64 bit MMU only */
3378 gen_op_dmfc0_xcontext();
3386 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3389 gen_op_mfc0_framemask();
3398 rn = "'Diagnostic"; /* implementation dependent */
3403 gen_op_mfc0_debug(); /* EJTAG support */
3407 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3408 rn = "TraceControl";
3411 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3412 rn = "TraceControl2";
3415 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3416 rn = "UserTraceData";
3419 // gen_op_dmfc0_debug(); /* PDtrace support */
3429 gen_op_dmfc0_depc(); /* EJTAG support */
3439 gen_op_mfc0_performance0();
3440 rn = "Performance0";
3443 // gen_op_dmfc0_performance1();
3444 rn = "Performance1";
3447 // gen_op_dmfc0_performance2();
3448 rn = "Performance2";
3451 // gen_op_dmfc0_performance3();
3452 rn = "Performance3";
3455 // gen_op_dmfc0_performance4();
3456 rn = "Performance4";
3459 // gen_op_dmfc0_performance5();
3460 rn = "Performance5";
3463 // gen_op_dmfc0_performance6();
3464 rn = "Performance6";
3467 // gen_op_dmfc0_performance7();
3468 rn = "Performance7";
3493 gen_op_mfc0_taglo();
3500 gen_op_mfc0_datalo();
3513 gen_op_mfc0_taghi();
3520 gen_op_mfc0_datahi();
3530 gen_op_dmfc0_errorepc();
3540 gen_op_mfc0_desave(); /* EJTAG support */
3550 #if defined MIPS_DEBUG_DISAS
3551 if (loglevel & CPU_LOG_TB_IN_ASM) {
3552 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3559 #if defined MIPS_DEBUG_DISAS
3560 if (loglevel & CPU_LOG_TB_IN_ASM) {
3561 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3565 generate_exception(ctx, EXCP_RI);
3568 static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
3570 const char *rn = "invalid";
3576 gen_op_mtc0_index();
3580 // gen_op_dmtc0_mvpcontrol(); /* MT ASE */
3584 // gen_op_dmtc0_mvpconf0(); /* MT ASE */
3588 // gen_op_dmtc0_mvpconf1(); /* MT ASE */
3602 // gen_op_dmtc0_vpecontrol(); /* MT ASE */
3606 // gen_op_dmtc0_vpeconf0(); /* MT ASE */
3610 // gen_op_dmtc0_vpeconf1(); /* MT ASE */
3614 // gen_op_dmtc0_YQMask(); /* MT ASE */
3618 // gen_op_dmtc0_vpeschedule(); /* MT ASE */
3622 // gen_op_dmtc0_vpeschefback(); /* MT ASE */
3623 rn = "VPEScheFBack";
3626 // gen_op_dmtc0_vpeopt(); /* MT ASE */
3636 gen_op_dmtc0_entrylo0();
3640 // gen_op_dmtc0_tcstatus(); /* MT ASE */
3644 // gen_op_dmtc0_tcbind(); /* MT ASE */
3648 // gen_op_dmtc0_tcrestart(); /* MT ASE */
3652 // gen_op_dmtc0_tchalt(); /* MT ASE */
3656 // gen_op_dmtc0_tccontext(); /* MT ASE */
3660 // gen_op_dmtc0_tcschedule(); /* MT ASE */
3664 // gen_op_dmtc0_tcschefback(); /* MT ASE */
3674 gen_op_dmtc0_entrylo1();
3684 gen_op_dmtc0_context();
3688 // gen_op_dmtc0_contextconfig(); /* SmartMIPS ASE */
3689 rn = "ContextConfig";
3698 gen_op_mtc0_pagemask();
3702 gen_op_mtc0_pagegrain();
3712 gen_op_mtc0_wired();
3716 // gen_op_dmtc0_srsconf0(); /* shadow registers */
3720 // gen_op_dmtc0_srsconf1(); /* shadow registers */
3724 // gen_op_dmtc0_srsconf2(); /* shadow registers */
3728 // gen_op_dmtc0_srsconf3(); /* shadow registers */
3732 // gen_op_dmtc0_srsconf4(); /* shadow registers */
3742 gen_op_mtc0_hwrena();
3756 gen_op_mtc0_count();
3759 /* 6,7 are implementation dependent */
3763 /* Stop translation as we may have switched the execution mode */
3764 ctx->bstate = BS_STOP;
3769 gen_op_mtc0_entryhi();
3779 gen_op_mtc0_compare();
3782 /* 6,7 are implementation dependent */
3786 /* Stop translation as we may have switched the execution mode */
3787 ctx->bstate = BS_STOP;
3792 gen_op_mtc0_status();
3796 gen_op_mtc0_intctl();
3800 gen_op_mtc0_srsctl();
3804 gen_op_mtc0_srsmap(); /* shadow registers */
3810 /* Stop translation as we may have switched the execution mode */
3811 ctx->bstate = BS_STOP;
3816 gen_op_mtc0_cause();
3822 /* Stop translation as we may have switched the execution mode */
3823 ctx->bstate = BS_STOP;
3842 gen_op_mtc0_ebase();
3852 gen_op_mtc0_config0();
3854 /* Stop translation as we may have switched the execution mode */
3855 ctx->bstate = BS_STOP;
3862 gen_op_mtc0_config2();
3864 /* Stop translation as we may have switched the execution mode */
3865 ctx->bstate = BS_STOP;
3871 /* 6,7 are implementation dependent */
3873 rn = "Invalid config selector";
3890 gen_op_dmtc0_watchlo0();
3894 // gen_op_dmtc0_watchlo1();
3898 // gen_op_dmtc0_watchlo2();
3902 // gen_op_dmtc0_watchlo3();
3906 // gen_op_dmtc0_watchlo4();
3910 // gen_op_dmtc0_watchlo5();
3914 // gen_op_dmtc0_watchlo6();
3918 // gen_op_dmtc0_watchlo7();
3928 gen_op_mtc0_watchhi0();
3932 // gen_op_dmtc0_watchhi1();
3936 // gen_op_dmtc0_watchhi2();
3940 // gen_op_dmtc0_watchhi3();
3944 // gen_op_dmtc0_watchhi4();
3948 // gen_op_dmtc0_watchhi5();
3952 // gen_op_dmtc0_watchhi6();
3956 // gen_op_dmtc0_watchhi7();
3966 /* 64 bit MMU only */
3967 gen_op_dmtc0_xcontext();
3975 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3978 gen_op_mtc0_framemask();
3987 rn = "Diagnostic"; /* implementation dependent */
3992 gen_op_mtc0_debug(); /* EJTAG support */
3996 // gen_op_dmtc0_tracecontrol(); /* PDtrace support */
3997 rn = "TraceControl";
4000 // gen_op_dmtc0_tracecontrol2(); /* PDtrace support */
4001 rn = "TraceControl2";
4004 // gen_op_dmtc0_usertracedata(); /* PDtrace support */
4005 rn = "UserTraceData";
4008 // gen_op_dmtc0_debug(); /* PDtrace support */
4014 /* Stop translation as we may have switched the execution mode */
4015 ctx->bstate = BS_STOP;
4020 gen_op_dmtc0_depc(); /* EJTAG support */
4030 gen_op_mtc0_performance0();
4031 rn = "Performance0";
4034 // gen_op_dmtc0_performance1();
4035 rn = "Performance1";
4038 // gen_op_dmtc0_performance2();
4039 rn = "Performance2";
4042 // gen_op_dmtc0_performance3();
4043 rn = "Performance3";
4046 // gen_op_dmtc0_performance4();
4047 rn = "Performance4";
4050 // gen_op_dmtc0_performance5();
4051 rn = "Performance5";
4054 // gen_op_dmtc0_performance6();
4055 rn = "Performance6";
4058 // gen_op_dmtc0_performance7();
4059 rn = "Performance7";
4085 gen_op_mtc0_taglo();
4092 gen_op_mtc0_datalo();
4105 gen_op_mtc0_taghi();
4112 gen_op_mtc0_datahi();
4123 gen_op_dmtc0_errorepc();
4133 gen_op_mtc0_desave(); /* EJTAG support */
4139 /* Stop translation as we may have switched the execution mode */
4140 ctx->bstate = BS_STOP;
4145 #if defined MIPS_DEBUG_DISAS
4146 if (loglevel & CPU_LOG_TB_IN_ASM) {
4147 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4154 #if defined MIPS_DEBUG_DISAS
4155 if (loglevel & CPU_LOG_TB_IN_ASM) {
4156 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4160 generate_exception(ctx, EXCP_RI);
4162 #endif /* TARGET_MIPS64 */
4164 static void gen_cp0 (DisasContext *ctx, uint32_t opc, int rt, int rd)
4166 const char *opn = "ldst";
4174 gen_mfc0(ctx, rd, ctx->opcode & 0x7);
4175 gen_op_store_T0_gpr(rt);
4179 GEN_LOAD_REG_TN(T0, rt);
4180 gen_mtc0(ctx, rd, ctx->opcode & 0x7);
4183 #ifdef TARGET_MIPS64
4189 gen_dmfc0(ctx, rd, ctx->opcode & 0x7);
4190 gen_op_store_T0_gpr(rt);
4194 GEN_LOAD_REG_TN(T0, rt);
4195 gen_dmtc0(ctx, rd, ctx->opcode & 0x7);
4199 #if defined(MIPS_USES_R4K_TLB)
4219 save_cpu_state(ctx, 0);
4221 ctx->bstate = BS_EXCP;
4225 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
4227 generate_exception(ctx, EXCP_RI);
4229 save_cpu_state(ctx, 0);
4231 ctx->bstate = BS_EXCP;
4236 /* If we get an exception, we want to restart at next instruction */
4238 save_cpu_state(ctx, 1);
4241 ctx->bstate = BS_EXCP;
4245 generate_exception(ctx, EXCP_RI);
4248 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
4251 /* CP1 Branches (before delay slot) */
4252 static void gen_compute_branch1 (DisasContext *ctx, uint32_t op,
4253 int32_t cc, int32_t offset)
4255 target_ulong btarget;
4256 const char *opn = "cp1 cond branch";
4258 btarget = ctx->pc + 4 + offset;
4277 ctx->hflags |= MIPS_HFLAG_BL;
4279 gen_op_save_bcond();
4282 gen_op_bc1fany2(cc);
4286 gen_op_bc1tany2(cc);
4290 gen_op_bc1fany4(cc);
4294 gen_op_bc1tany4(cc);
4297 ctx->hflags |= MIPS_HFLAG_BC;
4302 generate_exception (ctx, EXCP_RI);
4305 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
4306 ctx->hflags, btarget);
4307 ctx->btarget = btarget;
4310 /* Coprocessor 1 (FPU) */
4312 /* verify if floating point register is valid; an operation is not defined
4313 * if bit 0 of any register specification is set and the FR bit in the
4314 * Status register equals zero, since the register numbers specify an
4315 * even-odd pair of adjacent coprocessor general registers. When the FR bit
4316 * in the Status register equals one, both even and odd register numbers
4317 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
4319 * Multiple 64 bit wide registers can be checked by calling
4320 * CHECK_FR(ctx, freg1 | freg2 | ... | fregN);
4322 * FIXME: This is broken for R2, it needs to be checked at runtime, not
4323 * at translation time.
4325 #define CHECK_FR(ctx, freg) do { \
4326 if (!((ctx)->CP0_Status & (1 << CP0St_FR)) && ((freg) & 1)) { \
4327 MIPS_INVAL("FPU mode"); \
4328 generate_exception (ctx, EXCP_RI); \
4333 #define FOP(func, fmt) (((fmt) << 21) | (func))
4335 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
4337 const char *opn = "cp1 move";
4341 GEN_LOAD_FREG_FTN(WT0, fs);
4343 GEN_STORE_TN_REG(rt, T0);
4347 GEN_LOAD_REG_TN(T0, rt);
4349 GEN_STORE_FTN_FREG(fs, WT0);
4353 GEN_LOAD_IMM_TN(T1, fs);
4355 GEN_STORE_TN_REG(rt, T0);
4359 GEN_LOAD_IMM_TN(T1, fs);
4360 GEN_LOAD_REG_TN(T0, rt);
4365 GEN_LOAD_FREG_FTN(DT0, fs);
4367 GEN_STORE_TN_REG(rt, T0);
4371 GEN_LOAD_REG_TN(T0, rt);
4373 GEN_STORE_FTN_FREG(fs, DT0);
4378 GEN_LOAD_FREG_FTN(WTH0, fs);
4380 GEN_STORE_TN_REG(rt, T0);
4385 GEN_LOAD_REG_TN(T0, rt);
4387 GEN_STORE_FTN_FREG(fs, WTH0);
4392 generate_exception (ctx, EXCP_RI);
4395 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
4398 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
4402 GEN_LOAD_REG_TN(T0, rd);
4403 GEN_LOAD_REG_TN(T1, rs);
4405 ccbit = 1 << (24 + cc);
4412 GEN_STORE_TN_REG(rd, T0);
4415 #define GEN_MOVCF(fmt) \
4416 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4421 ccbit = 1 << (24 + cc); \
4425 glue(gen_op_float_movf_, fmt)(ccbit); \
4427 glue(gen_op_float_movt_, fmt)(ccbit); \
4434 static void gen_farith (DisasContext *ctx, uint32_t op1, int ft,
4435 int fs, int fd, int cc)
4437 const char *opn = "farith";
4438 const char *condnames[] = {
4457 uint32_t func = ctx->opcode & 0x3f;
4459 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
4461 GEN_LOAD_FREG_FTN(WT0, fs);
4462 GEN_LOAD_FREG_FTN(WT1, ft);
4463 gen_op_float_add_s();
4464 GEN_STORE_FTN_FREG(fd, WT2);
4469 GEN_LOAD_FREG_FTN(WT0, fs);
4470 GEN_LOAD_FREG_FTN(WT1, ft);
4471 gen_op_float_sub_s();
4472 GEN_STORE_FTN_FREG(fd, WT2);
4477 GEN_LOAD_FREG_FTN(WT0, fs);
4478 GEN_LOAD_FREG_FTN(WT1, ft);
4479 gen_op_float_mul_s();
4480 GEN_STORE_FTN_FREG(fd, WT2);
4485 GEN_LOAD_FREG_FTN(WT0, fs);
4486 GEN_LOAD_FREG_FTN(WT1, ft);
4487 gen_op_float_div_s();
4488 GEN_STORE_FTN_FREG(fd, WT2);
4493 GEN_LOAD_FREG_FTN(WT0, fs);
4494 gen_op_float_sqrt_s();
4495 GEN_STORE_FTN_FREG(fd, WT2);
4499 GEN_LOAD_FREG_FTN(WT0, fs);
4500 gen_op_float_abs_s();
4501 GEN_STORE_FTN_FREG(fd, WT2);
4505 GEN_LOAD_FREG_FTN(WT0, fs);
4506 gen_op_float_mov_s();
4507 GEN_STORE_FTN_FREG(fd, WT2);
4511 GEN_LOAD_FREG_FTN(WT0, fs);
4512 gen_op_float_chs_s();
4513 GEN_STORE_FTN_FREG(fd, WT2);
4518 GEN_LOAD_FREG_FTN(WT0, fs);
4519 gen_op_float_roundl_s();
4520 GEN_STORE_FTN_FREG(fd, DT2);
4525 GEN_LOAD_FREG_FTN(WT0, fs);
4526 gen_op_float_truncl_s();
4527 GEN_STORE_FTN_FREG(fd, DT2);
4532 GEN_LOAD_FREG_FTN(WT0, fs);
4533 gen_op_float_ceill_s();
4534 GEN_STORE_FTN_FREG(fd, DT2);
4539 GEN_LOAD_FREG_FTN(WT0, fs);
4540 gen_op_float_floorl_s();
4541 GEN_STORE_FTN_FREG(fd, DT2);
4545 GEN_LOAD_FREG_FTN(WT0, fs);
4546 gen_op_float_roundw_s();
4547 GEN_STORE_FTN_FREG(fd, WT2);
4551 GEN_LOAD_FREG_FTN(WT0, fs);
4552 gen_op_float_truncw_s();
4553 GEN_STORE_FTN_FREG(fd, WT2);
4557 GEN_LOAD_FREG_FTN(WT0, fs);
4558 gen_op_float_ceilw_s();
4559 GEN_STORE_FTN_FREG(fd, WT2);
4563 GEN_LOAD_FREG_FTN(WT0, fs);
4564 gen_op_float_floorw_s();
4565 GEN_STORE_FTN_FREG(fd, WT2);
4569 GEN_LOAD_REG_TN(T0, ft);
4570 GEN_LOAD_FREG_FTN(WT0, fs);
4571 GEN_LOAD_FREG_FTN(WT2, fd);
4572 gen_movcf_s(ctx, (ft >> 2) & 0x7, ft & 0x1);
4573 GEN_STORE_FTN_FREG(fd, WT2);
4577 GEN_LOAD_REG_TN(T0, ft);
4578 GEN_LOAD_FREG_FTN(WT0, fs);
4579 GEN_LOAD_FREG_FTN(WT2, fd);
4580 gen_op_float_movz_s();
4581 GEN_STORE_FTN_FREG(fd, WT2);
4585 GEN_LOAD_REG_TN(T0, ft);
4586 GEN_LOAD_FREG_FTN(WT0, fs);
4587 GEN_LOAD_FREG_FTN(WT2, fd);
4588 gen_op_float_movn_s();
4589 GEN_STORE_FTN_FREG(fd, WT2);
4594 GEN_LOAD_FREG_FTN(WT0, fs);
4595 gen_op_float_cvtd_s();
4596 GEN_STORE_FTN_FREG(fd, DT2);
4600 GEN_LOAD_FREG_FTN(WT0, fs);
4601 gen_op_float_cvtw_s();
4602 GEN_STORE_FTN_FREG(fd, WT2);
4606 CHECK_FR(ctx, fs | fd);
4607 GEN_LOAD_FREG_FTN(WT0, fs);
4608 gen_op_float_cvtl_s();
4609 GEN_STORE_FTN_FREG(fd, DT2);
4613 CHECK_FR(ctx, fs | ft | fd);
4614 GEN_LOAD_FREG_FTN(WT1, fs);
4615 GEN_LOAD_FREG_FTN(WT0, ft);
4616 gen_op_float_cvtps_s();
4617 GEN_STORE_FTN_FREG(fd, DT2);
4636 GEN_LOAD_FREG_FTN(WT0, fs);
4637 GEN_LOAD_FREG_FTN(WT1, ft);
4638 gen_cmp_s(func-48, cc);
4639 opn = condnames[func-48];
4642 CHECK_FR(ctx, fs | ft | fd);
4643 GEN_LOAD_FREG_FTN(DT0, fs);
4644 GEN_LOAD_FREG_FTN(DT1, ft);
4645 gen_op_float_add_d();
4646 GEN_STORE_FTN_FREG(fd, DT2);
4651 CHECK_FR(ctx, fs | ft | fd);
4652 GEN_LOAD_FREG_FTN(DT0, fs);
4653 GEN_LOAD_FREG_FTN(DT1, ft);
4654 gen_op_float_sub_d();
4655 GEN_STORE_FTN_FREG(fd, DT2);
4660 CHECK_FR(ctx, fs | ft | fd);
4661 GEN_LOAD_FREG_FTN(DT0, fs);
4662 GEN_LOAD_FREG_FTN(DT1, ft);
4663 gen_op_float_mul_d();
4664 GEN_STORE_FTN_FREG(fd, DT2);
4669 CHECK_FR(ctx, fs | ft | fd);
4670 GEN_LOAD_FREG_FTN(DT0, fs);
4671 GEN_LOAD_FREG_FTN(DT1, ft);
4672 gen_op_float_div_d();
4673 GEN_STORE_FTN_FREG(fd, DT2);
4678 CHECK_FR(ctx, fs | fd);
4679 GEN_LOAD_FREG_FTN(DT0, fs);
4680 gen_op_float_sqrt_d();
4681 GEN_STORE_FTN_FREG(fd, DT2);
4685 CHECK_FR(ctx, fs | fd);
4686 GEN_LOAD_FREG_FTN(DT0, fs);
4687 gen_op_float_abs_d();
4688 GEN_STORE_FTN_FREG(fd, DT2);
4692 CHECK_FR(ctx, fs | fd);
4693 GEN_LOAD_FREG_FTN(DT0, fs);
4694 gen_op_float_mov_d();
4695 GEN_STORE_FTN_FREG(fd, DT2);
4699 CHECK_FR(ctx, fs | fd);
4700 GEN_LOAD_FREG_FTN(DT0, fs);
4701 gen_op_float_chs_d();
4702 GEN_STORE_FTN_FREG(fd, DT2);
4707 GEN_LOAD_FREG_FTN(DT0, fs);
4708 gen_op_float_roundl_d();
4709 GEN_STORE_FTN_FREG(fd, DT2);
4714 GEN_LOAD_FREG_FTN(DT0, fs);
4715 gen_op_float_truncl_d();
4716 GEN_STORE_FTN_FREG(fd, DT2);
4721 GEN_LOAD_FREG_FTN(DT0, fs);
4722 gen_op_float_ceill_d();
4723 GEN_STORE_FTN_FREG(fd, DT2);
4728 GEN_LOAD_FREG_FTN(DT0, fs);
4729 gen_op_float_floorl_d();
4730 GEN_STORE_FTN_FREG(fd, DT2);
4735 GEN_LOAD_FREG_FTN(DT0, fs);
4736 gen_op_float_roundw_d();
4737 GEN_STORE_FTN_FREG(fd, WT2);
4742 GEN_LOAD_FREG_FTN(DT0, fs);
4743 gen_op_float_truncw_d();
4744 GEN_STORE_FTN_FREG(fd, WT2);
4749 GEN_LOAD_FREG_FTN(DT0, fs);
4750 gen_op_float_ceilw_d();
4751 GEN_STORE_FTN_FREG(fd, WT2);
4756 GEN_LOAD_FREG_FTN(DT0, fs);
4757 gen_op_float_floorw_d();
4758 GEN_STORE_FTN_FREG(fd, WT2);
4762 GEN_LOAD_REG_TN(T0, ft);
4763 GEN_LOAD_FREG_FTN(DT0, fs);
4764 GEN_LOAD_FREG_FTN(DT2, fd);
4765 gen_movcf_d(ctx, (ft >> 2) & 0x7, ft & 0x1);
4766 GEN_STORE_FTN_FREG(fd, DT2);
4770 GEN_LOAD_REG_TN(T0, ft);
4771 GEN_LOAD_FREG_FTN(DT0, fs);
4772 GEN_LOAD_FREG_FTN(DT2, fd);
4773 gen_op_float_movz_d();
4774 GEN_STORE_FTN_FREG(fd, DT2);
4778 GEN_LOAD_REG_TN(T0, ft);
4779 GEN_LOAD_FREG_FTN(DT0, fs);
4780 GEN_LOAD_FREG_FTN(DT2, fd);
4781 gen_op_float_movn_d();
4782 GEN_STORE_FTN_FREG(fd, DT2);
4801 CHECK_FR(ctx, fs | ft);
4802 GEN_LOAD_FREG_FTN(DT0, fs);
4803 GEN_LOAD_FREG_FTN(DT1, ft);
4804 gen_cmp_d(func-48, cc);
4805 opn = condnames[func-48];
4809 GEN_LOAD_FREG_FTN(DT0, fs);
4810 gen_op_float_cvts_d();
4811 GEN_STORE_FTN_FREG(fd, WT2);
4816 GEN_LOAD_FREG_FTN(DT0, fs);
4817 gen_op_float_cvtw_d();
4818 GEN_STORE_FTN_FREG(fd, WT2);
4822 CHECK_FR(ctx, fs | fd);
4823 GEN_LOAD_FREG_FTN(DT0, fs);
4824 gen_op_float_cvtl_d();
4825 GEN_STORE_FTN_FREG(fd, DT2);
4829 GEN_LOAD_FREG_FTN(WT0, fs);
4830 gen_op_float_cvts_w();
4831 GEN_STORE_FTN_FREG(fd, WT2);
4836 GEN_LOAD_FREG_FTN(WT0, fs);
4837 gen_op_float_cvtd_w();
4838 GEN_STORE_FTN_FREG(fd, DT2);
4843 GEN_LOAD_FREG_FTN(DT0, fs);
4844 gen_op_float_cvts_l();
4845 GEN_STORE_FTN_FREG(fd, WT2);
4849 CHECK_FR(ctx, fs | fd);
4850 GEN_LOAD_FREG_FTN(DT0, fs);
4851 gen_op_float_cvtd_l();
4852 GEN_STORE_FTN_FREG(fd, DT2);
4857 CHECK_FR(ctx, fs | fd);
4858 GEN_LOAD_FREG_FTN(WT0, fs);
4859 GEN_LOAD_FREG_FTN(WTH0, fs);
4860 gen_op_float_cvtps_pw();
4861 GEN_STORE_FTN_FREG(fd, WT2);
4862 GEN_STORE_FTN_FREG(fd, WTH2);
4866 CHECK_FR(ctx, fs | ft | fd);
4867 GEN_LOAD_FREG_FTN(WT0, fs);
4868 GEN_LOAD_FREG_FTN(WTH0, fs);
4869 GEN_LOAD_FREG_FTN(WT1, ft);
4870 GEN_LOAD_FREG_FTN(WTH1, ft);
4871 gen_op_float_add_ps();
4872 GEN_STORE_FTN_FREG(fd, WT2);
4873 GEN_STORE_FTN_FREG(fd, WTH2);
4877 CHECK_FR(ctx, fs | ft | fd);
4878 GEN_LOAD_FREG_FTN(WT0, fs);
4879 GEN_LOAD_FREG_FTN(WTH0, fs);
4880 GEN_LOAD_FREG_FTN(WT1, ft);
4881 GEN_LOAD_FREG_FTN(WTH1, ft);
4882 gen_op_float_sub_ps();
4883 GEN_STORE_FTN_FREG(fd, WT2);
4884 GEN_STORE_FTN_FREG(fd, WTH2);
4888 CHECK_FR(ctx, fs | ft | fd);
4889 GEN_LOAD_FREG_FTN(WT0, fs);
4890 GEN_LOAD_FREG_FTN(WTH0, fs);
4891 GEN_LOAD_FREG_FTN(WT1, ft);
4892 GEN_LOAD_FREG_FTN(WTH1, ft);
4893 gen_op_float_mul_ps();
4894 GEN_STORE_FTN_FREG(fd, WT2);
4895 GEN_STORE_FTN_FREG(fd, WTH2);
4899 CHECK_FR(ctx, fs | fd);
4900 GEN_LOAD_FREG_FTN(WT0, fs);
4901 GEN_LOAD_FREG_FTN(WTH0, fs);
4902 gen_op_float_abs_ps();
4903 GEN_STORE_FTN_FREG(fd, WT2);
4904 GEN_STORE_FTN_FREG(fd, WTH2);
4908 CHECK_FR(ctx, fs | fd);
4909 GEN_LOAD_FREG_FTN(WT0, fs);
4910 GEN_LOAD_FREG_FTN(WTH0, fs);
4911 gen_op_float_mov_ps();
4912 GEN_STORE_FTN_FREG(fd, WT2);
4913 GEN_STORE_FTN_FREG(fd, WTH2);
4917 CHECK_FR(ctx, fs | fd);
4918 GEN_LOAD_FREG_FTN(WT0, fs);
4919 GEN_LOAD_FREG_FTN(WTH0, fs);
4920 gen_op_float_chs_ps();
4921 GEN_STORE_FTN_FREG(fd, WT2);
4922 GEN_STORE_FTN_FREG(fd, WTH2);
4926 GEN_LOAD_REG_TN(T0, ft);
4927 GEN_LOAD_FREG_FTN(WT0, fs);
4928 GEN_LOAD_FREG_FTN(WTH0, fs);
4929 GEN_LOAD_FREG_FTN(WT2, fd);
4930 GEN_LOAD_FREG_FTN(WTH2, fd);
4931 gen_movcf_ps(ctx, (ft >> 2) & 0x7, ft & 0x1);
4932 GEN_STORE_FTN_FREG(fd, WT2);
4933 GEN_STORE_FTN_FREG(fd, WTH2);
4937 GEN_LOAD_REG_TN(T0, ft);
4938 GEN_LOAD_FREG_FTN(WT0, fs);
4939 GEN_LOAD_FREG_FTN(WTH0, fs);
4940 GEN_LOAD_FREG_FTN(WT2, fd);
4941 GEN_LOAD_FREG_FTN(WTH2, fd);
4942 gen_op_float_movz_ps();
4943 GEN_STORE_FTN_FREG(fd, WT2);
4944 GEN_STORE_FTN_FREG(fd, WTH2);
4948 GEN_LOAD_REG_TN(T0, ft);
4949 GEN_LOAD_FREG_FTN(WT0, fs);
4950 GEN_LOAD_FREG_FTN(WTH0, fs);
4951 GEN_LOAD_FREG_FTN(WT2, fd);
4952 GEN_LOAD_FREG_FTN(WTH2, fd);
4953 gen_op_float_movn_ps();
4954 GEN_STORE_FTN_FREG(fd, WT2);
4955 GEN_STORE_FTN_FREG(fd, WTH2);
4959 CHECK_FR(ctx, fs | fd | ft);
4960 GEN_LOAD_FREG_FTN(WT0, fs);
4961 GEN_LOAD_FREG_FTN(WTH0, fs);
4962 GEN_LOAD_FREG_FTN(WT1, ft);
4963 GEN_LOAD_FREG_FTN(WTH1, ft);
4964 gen_op_float_addr_ps();
4965 GEN_STORE_FTN_FREG(fd, WT2);
4966 GEN_STORE_FTN_FREG(fd, WTH2);
4971 GEN_LOAD_FREG_FTN(WTH0, fs);
4972 gen_op_float_cvts_pu();
4973 GEN_STORE_FTN_FREG(fd, WT2);
4977 CHECK_FR(ctx, fs | fd);
4978 GEN_LOAD_FREG_FTN(WT0, fs);
4979 GEN_LOAD_FREG_FTN(WTH0, fs);
4980 gen_op_float_cvtpw_ps();
4981 GEN_STORE_FTN_FREG(fd, WT2);
4982 GEN_STORE_FTN_FREG(fd, WTH2);
4987 GEN_LOAD_FREG_FTN(WT0, fs);
4988 gen_op_float_cvts_pl();
4989 GEN_STORE_FTN_FREG(fd, WT2);
4993 CHECK_FR(ctx, fs | ft | fd);
4994 GEN_LOAD_FREG_FTN(WT0, fs);
4995 GEN_LOAD_FREG_FTN(WT1, ft);
4996 gen_op_float_pll_ps();
4997 GEN_STORE_FTN_FREG(fd, DT2);
5001 CHECK_FR(ctx, fs | ft | fd);
5002 GEN_LOAD_FREG_FTN(WT0, fs);
5003 GEN_LOAD_FREG_FTN(WTH1, ft);
5004 gen_op_float_plu_ps();
5005 GEN_STORE_FTN_FREG(fd, DT2);
5009 CHECK_FR(ctx, fs | ft | fd);
5010 GEN_LOAD_FREG_FTN(WTH0, fs);
5011 GEN_LOAD_FREG_FTN(WT1, ft);
5012 gen_op_float_pul_ps();
5013 GEN_STORE_FTN_FREG(fd, DT2);
5017 CHECK_FR(ctx, fs | ft | fd);
5018 GEN_LOAD_FREG_FTN(WTH0, fs);
5019 GEN_LOAD_FREG_FTN(WTH1, ft);
5020 gen_op_float_puu_ps();
5021 GEN_STORE_FTN_FREG(fd, DT2);
5040 CHECK_FR(ctx, fs | ft);
5041 GEN_LOAD_FREG_FTN(WT0, fs);
5042 GEN_LOAD_FREG_FTN(WTH0, fs);
5043 GEN_LOAD_FREG_FTN(WT1, ft);
5044 GEN_LOAD_FREG_FTN(WTH1, ft);
5045 gen_cmp_ps(func-48, cc);
5046 opn = condnames[func-48];
5050 generate_exception (ctx, EXCP_RI);
5054 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
5056 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
5059 /* Coprocessor 3 (FPU) */
5060 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc, int fd,
5061 int base, int index)
5063 const char *opn = "extended float load/store";
5065 GEN_LOAD_REG_TN(T0, base);
5066 GEN_LOAD_REG_TN(T1, index);
5067 /* Don't do NOP if destination is zero: we must perform the actual
5073 GEN_STORE_FTN_FREG(fd, WT0);
5078 GEN_STORE_FTN_FREG(fd, DT0);
5083 GEN_STORE_FTN_FREG(fd, DT0);
5087 GEN_LOAD_FREG_FTN(WT0, fd);
5092 GEN_LOAD_FREG_FTN(DT0, fd);
5097 GEN_LOAD_FREG_FTN(DT0, fd);
5103 generate_exception(ctx, EXCP_RI);
5106 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[fd],regnames[index], regnames[base]);
5109 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc, int fd,
5110 int fr, int fs, int ft)
5112 const char *opn = "flt3_arith";
5114 /* All of those work only on 64bit FPUs. */
5115 CHECK_FR(ctx, fd | fr | fs | ft);
5118 GEN_LOAD_REG_TN(T0, fr);
5119 GEN_LOAD_FREG_FTN(DT0, fs);
5120 GEN_LOAD_FREG_FTN(DT1, ft);
5121 gen_op_float_alnv_ps();
5122 GEN_STORE_FTN_FREG(fd, DT2);
5126 GEN_LOAD_FREG_FTN(WT0, fs);
5127 GEN_LOAD_FREG_FTN(WT1, ft);
5128 GEN_LOAD_FREG_FTN(WT2, fr);
5129 gen_op_float_muladd_s();
5130 GEN_STORE_FTN_FREG(fd, WT2);
5134 GEN_LOAD_FREG_FTN(DT0, fs);
5135 GEN_LOAD_FREG_FTN(DT1, ft);
5136 GEN_LOAD_FREG_FTN(DT2, fr);
5137 gen_op_float_muladd_d();
5138 GEN_STORE_FTN_FREG(fd, DT2);
5142 GEN_LOAD_FREG_FTN(WT0, fs);
5143 GEN_LOAD_FREG_FTN(WTH0, fs);
5144 GEN_LOAD_FREG_FTN(WT1, ft);
5145 GEN_LOAD_FREG_FTN(WTH1, ft);
5146 GEN_LOAD_FREG_FTN(WT2, fr);
5147 GEN_LOAD_FREG_FTN(WTH2, fr);
5148 gen_op_float_muladd_ps();
5149 GEN_STORE_FTN_FREG(fd, WT2);
5150 GEN_STORE_FTN_FREG(fd, WTH2);
5154 GEN_LOAD_FREG_FTN(WT0, fs);
5155 GEN_LOAD_FREG_FTN(WT1, ft);
5156 GEN_LOAD_FREG_FTN(WT2, fr);
5157 gen_op_float_mulsub_s();
5158 GEN_STORE_FTN_FREG(fd, WT2);
5162 GEN_LOAD_FREG_FTN(DT0, fs);
5163 GEN_LOAD_FREG_FTN(DT1, ft);
5164 GEN_LOAD_FREG_FTN(DT2, fr);
5165 gen_op_float_mulsub_d();
5166 GEN_STORE_FTN_FREG(fd, DT2);
5170 GEN_LOAD_FREG_FTN(WT0, fs);
5171 GEN_LOAD_FREG_FTN(WTH0, fs);
5172 GEN_LOAD_FREG_FTN(WT1, ft);
5173 GEN_LOAD_FREG_FTN(WTH1, ft);
5174 GEN_LOAD_FREG_FTN(WT2, fr);
5175 GEN_LOAD_FREG_FTN(WTH2, fr);
5176 gen_op_float_mulsub_ps();
5177 GEN_STORE_FTN_FREG(fd, WT2);
5178 GEN_STORE_FTN_FREG(fd, WTH2);
5182 GEN_LOAD_FREG_FTN(WT0, fs);
5183 GEN_LOAD_FREG_FTN(WT1, ft);
5184 GEN_LOAD_FREG_FTN(WT2, fr);
5185 gen_op_float_nmuladd_s();
5186 GEN_STORE_FTN_FREG(fd, WT2);
5190 GEN_LOAD_FREG_FTN(DT0, fs);
5191 GEN_LOAD_FREG_FTN(DT1, ft);
5192 GEN_LOAD_FREG_FTN(DT2, fr);
5193 gen_op_float_nmuladd_d();
5194 GEN_STORE_FTN_FREG(fd, DT2);
5198 GEN_LOAD_FREG_FTN(WT0, fs);
5199 GEN_LOAD_FREG_FTN(WTH0, fs);
5200 GEN_LOAD_FREG_FTN(WT1, ft);
5201 GEN_LOAD_FREG_FTN(WTH1, ft);
5202 GEN_LOAD_FREG_FTN(WT2, fr);
5203 GEN_LOAD_FREG_FTN(WTH2, fr);
5204 gen_op_float_nmuladd_ps();
5205 GEN_STORE_FTN_FREG(fd, WT2);
5206 GEN_STORE_FTN_FREG(fd, WTH2);
5210 GEN_LOAD_FREG_FTN(WT0, fs);
5211 GEN_LOAD_FREG_FTN(WT1, ft);
5212 GEN_LOAD_FREG_FTN(WT2, fr);
5213 gen_op_float_nmulsub_s();
5214 GEN_STORE_FTN_FREG(fd, WT2);
5218 GEN_LOAD_FREG_FTN(DT0, fs);
5219 GEN_LOAD_FREG_FTN(DT1, ft);
5220 GEN_LOAD_FREG_FTN(DT2, fr);
5221 gen_op_float_nmulsub_d();
5222 GEN_STORE_FTN_FREG(fd, DT2);
5226 GEN_LOAD_FREG_FTN(WT0, fs);
5227 GEN_LOAD_FREG_FTN(WTH0, fs);
5228 GEN_LOAD_FREG_FTN(WT1, ft);
5229 GEN_LOAD_FREG_FTN(WTH1, ft);
5230 GEN_LOAD_FREG_FTN(WT2, fr);
5231 GEN_LOAD_FREG_FTN(WTH2, fr);
5232 gen_op_float_nmulsub_ps();
5233 GEN_STORE_FTN_FREG(fd, WT2);
5234 GEN_STORE_FTN_FREG(fd, WTH2);
5239 generate_exception (ctx, EXCP_RI);
5242 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
5243 fregnames[fs], fregnames[ft]);
5246 /* ISA extensions (ASEs) */
5247 /* MIPS16 extension to MIPS32 */
5248 /* SmartMIPS extension to MIPS32 */
5250 #ifdef TARGET_MIPS64
5252 /* MDMX extension to MIPS64 */
5253 /* MIPS-3D extension to MIPS64 */
5257 static void decode_opc (CPUState *env, DisasContext *ctx)
5261 uint32_t op, op1, op2;
5264 /* make sure instructions are on a word boundary */
5265 if (ctx->pc & 0x3) {
5266 env->CP0_BadVAddr = ctx->pc;
5267 generate_exception(ctx, EXCP_AdEL);
5271 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
5273 /* Handle blikely not taken case */
5274 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
5275 l1 = gen_new_label();
5277 gen_op_save_state(ctx->hflags & ~MIPS_HFLAG_BMASK);
5278 gen_goto_tb(ctx, 1, ctx->pc + 4);
5281 op = MASK_OP_MAJOR(ctx->opcode);
5282 rs = (ctx->opcode >> 21) & 0x1f;
5283 rt = (ctx->opcode >> 16) & 0x1f;
5284 rd = (ctx->opcode >> 11) & 0x1f;
5285 sa = (ctx->opcode >> 6) & 0x1f;
5286 imm = (int16_t)ctx->opcode;
5289 op1 = MASK_SPECIAL(ctx->opcode);
5291 case OPC_SLL: /* Arithmetic with immediate */
5292 case OPC_SRL ... OPC_SRA:
5293 gen_arith_imm(ctx, op1, rd, rt, sa);
5295 case OPC_SLLV: /* Arithmetic */
5296 case OPC_SRLV ... OPC_SRAV:
5297 case OPC_MOVZ ... OPC_MOVN:
5298 case OPC_ADD ... OPC_NOR:
5299 case OPC_SLT ... OPC_SLTU:
5300 gen_arith(ctx, op1, rd, rs, rt);
5302 case OPC_MULT ... OPC_DIVU:
5303 gen_muldiv(ctx, op1, rs, rt);
5305 case OPC_JR ... OPC_JALR:
5306 gen_compute_branch(ctx, op1, rs, rd, sa);
5308 case OPC_TGE ... OPC_TEQ: /* Traps */
5310 gen_trap(ctx, op1, rs, rt, -1);
5312 case OPC_MFHI: /* Move from HI/LO */
5314 gen_HILO(ctx, op1, rd);
5317 case OPC_MTLO: /* Move to HI/LO */
5318 gen_HILO(ctx, op1, rs);
5320 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
5321 #ifdef MIPS_STRICT_STANDARD
5322 MIPS_INVAL("PMON / selsl");
5323 generate_exception(ctx, EXCP_RI);
5329 generate_exception(ctx, EXCP_SYSCALL);
5332 generate_exception(ctx, EXCP_BREAK);
5335 #ifdef MIPS_STRICT_STANDARD
5337 generate_exception(ctx, EXCP_RI);
5339 /* Implemented as RI exception for now. */
5340 MIPS_INVAL("spim (unofficial)");
5341 generate_exception(ctx, EXCP_RI);
5345 /* Treat as a noop. */
5349 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5350 save_cpu_state(ctx, 1);
5351 gen_op_cp1_enabled();
5352 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
5353 (ctx->opcode >> 16) & 1);
5355 generate_exception_err(ctx, EXCP_CpU, 1);
5359 #ifdef TARGET_MIPS64
5360 /* MIPS64 specific opcodes */
5362 case OPC_DSRL ... OPC_DSRA:
5364 case OPC_DSRL32 ... OPC_DSRA32:
5365 gen_arith_imm(ctx, op1, rd, rt, sa);
5368 case OPC_DSRLV ... OPC_DSRAV:
5369 case OPC_DADD ... OPC_DSUBU:
5370 gen_arith(ctx, op1, rd, rs, rt);
5372 case OPC_DMULT ... OPC_DDIVU:
5373 gen_muldiv(ctx, op1, rs, rt);
5376 default: /* Invalid */
5377 MIPS_INVAL("special");
5378 generate_exception(ctx, EXCP_RI);
5383 op1 = MASK_SPECIAL2(ctx->opcode);
5385 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
5386 case OPC_MSUB ... OPC_MSUBU:
5387 gen_muldiv(ctx, op1, rs, rt);
5390 gen_arith(ctx, op1, rd, rs, rt);
5392 case OPC_CLZ ... OPC_CLO:
5393 gen_cl(ctx, op1, rd, rs);
5396 /* XXX: not clear which exception should be raised
5397 * when in debug mode...
5399 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5400 generate_exception(ctx, EXCP_DBp);
5402 generate_exception(ctx, EXCP_DBp);
5404 /* Treat as a noop */
5406 #ifdef TARGET_MIPS64
5407 case OPC_DCLZ ... OPC_DCLO:
5408 gen_cl(ctx, op1, rd, rs);
5411 default: /* Invalid */
5412 MIPS_INVAL("special2");
5413 generate_exception(ctx, EXCP_RI);
5418 op1 = MASK_SPECIAL3(ctx->opcode);
5422 gen_bitops(ctx, op1, rt, rs, sa, rd);
5425 op2 = MASK_BSHFL(ctx->opcode);
5428 GEN_LOAD_REG_TN(T1, rt);
5432 GEN_LOAD_REG_TN(T1, rt);
5436 GEN_LOAD_REG_TN(T1, rt);
5439 default: /* Invalid */
5440 MIPS_INVAL("bshfl");
5441 generate_exception(ctx, EXCP_RI);
5444 GEN_STORE_TN_REG(rd, T0);
5449 save_cpu_state(ctx, 1);
5450 gen_op_rdhwr_cpunum();
5453 save_cpu_state(ctx, 1);
5454 gen_op_rdhwr_synci_step();
5457 save_cpu_state(ctx, 1);
5461 save_cpu_state(ctx, 1);
5462 gen_op_rdhwr_ccres();
5465 #if defined (CONFIG_USER_ONLY)
5466 gen_op_tls_value ();
5469 default: /* Invalid */
5470 MIPS_INVAL("rdhwr");
5471 generate_exception(ctx, EXCP_RI);
5474 GEN_STORE_TN_REG(rt, T0);
5476 #ifdef TARGET_MIPS64
5477 case OPC_DEXTM ... OPC_DEXT:
5478 case OPC_DINSM ... OPC_DINS:
5479 gen_bitops(ctx, op1, rt, rs, sa, rd);
5482 op2 = MASK_DBSHFL(ctx->opcode);
5485 GEN_LOAD_REG_TN(T1, rt);
5489 GEN_LOAD_REG_TN(T1, rt);
5492 default: /* Invalid */
5493 MIPS_INVAL("dbshfl");
5494 generate_exception(ctx, EXCP_RI);
5497 GEN_STORE_TN_REG(rd, T0);
5499 default: /* Invalid */
5500 MIPS_INVAL("special3");
5501 generate_exception(ctx, EXCP_RI);
5506 op1 = MASK_REGIMM(ctx->opcode);
5508 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
5509 case OPC_BLTZAL ... OPC_BGEZALL:
5510 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
5512 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
5514 gen_trap(ctx, op1, rs, -1, imm);
5519 default: /* Invalid */
5520 MIPS_INVAL("regimm");
5521 generate_exception(ctx, EXCP_RI);
5526 save_cpu_state(ctx, 1);
5527 gen_op_cp0_enabled();
5528 op1 = MASK_CP0(ctx->opcode);
5532 #ifdef TARGET_MIPS64
5536 gen_cp0(ctx, op1, rt, rd);
5538 case OPC_C0_FIRST ... OPC_C0_LAST:
5539 gen_cp0(ctx, MASK_C0(ctx->opcode), rt, rd);
5542 op2 = MASK_MFMC0(ctx->opcode);
5546 /* Stop translation as we may have switched the execution mode */
5547 ctx->bstate = BS_STOP;
5551 /* Stop translation as we may have switched the execution mode */
5552 ctx->bstate = BS_STOP;
5554 default: /* Invalid */
5555 MIPS_INVAL("mfmc0");
5556 generate_exception(ctx, EXCP_RI);
5559 GEN_STORE_TN_REG(rt, T0);
5563 if ((env->CP0_Config0 & (0x7 << CP0C0_AR)) == (1 << CP0C0_AR)) {
5564 /* Shadow registers not implemented. */
5565 GEN_LOAD_REG_TN(T0, rt);
5566 GEN_STORE_TN_REG(rd, T0);
5568 MIPS_INVAL("shadow register move");
5569 generate_exception(ctx, EXCP_RI);
5574 generate_exception(ctx, EXCP_RI);
5578 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
5579 gen_arith_imm(ctx, op, rt, rs, imm);
5581 case OPC_J ... OPC_JAL: /* Jump */
5582 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
5583 gen_compute_branch(ctx, op, rs, rt, offset);
5585 case OPC_BEQ ... OPC_BGTZ: /* Branch */
5586 case OPC_BEQL ... OPC_BGTZL:
5587 gen_compute_branch(ctx, op, rs, rt, imm << 2);
5589 case OPC_LB ... OPC_LWR: /* Load and stores */
5590 case OPC_SB ... OPC_SW:
5594 gen_ldst(ctx, op, rt, rs, imm);
5597 /* Treat as a noop */
5600 /* Treat as a noop */
5603 /* Floating point (COP1). */
5608 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5609 save_cpu_state(ctx, 1);
5610 gen_op_cp1_enabled();
5611 gen_flt_ldst(ctx, op, rt, rs, imm);
5613 generate_exception_err(ctx, EXCP_CpU, 1);
5618 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5619 save_cpu_state(ctx, 1);
5620 gen_op_cp1_enabled();
5621 op1 = MASK_CP1(ctx->opcode);
5627 #ifdef TARGET_MIPS64
5633 gen_cp1(ctx, op1, rt, rd);
5638 gen_compute_branch1(ctx, MASK_BC1(ctx->opcode),
5639 (rt >> 2) & 0x7, imm << 2);
5646 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
5651 generate_exception (ctx, EXCP_RI);
5655 generate_exception_err(ctx, EXCP_CpU, 1);
5665 /* COP2: Not implemented. */
5666 generate_exception_err(ctx, EXCP_CpU, 2);
5670 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5671 save_cpu_state(ctx, 1);
5672 gen_op_cp1_enabled();
5673 op1 = MASK_CP3(ctx->opcode);
5681 gen_flt3_ldst(ctx, op1, sa, rs, rt);
5699 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
5703 generate_exception (ctx, EXCP_RI);
5707 generate_exception_err(ctx, EXCP_CpU, 1);
5711 #ifdef TARGET_MIPS64
5712 /* MIPS64 opcodes */
5714 case OPC_LDL ... OPC_LDR:
5715 case OPC_SDL ... OPC_SDR:
5720 gen_ldst(ctx, op, rt, rs, imm);
5722 case OPC_DADDI ... OPC_DADDIU:
5723 gen_arith_imm(ctx, op, rt, rs, imm);
5726 #ifdef MIPS_HAS_MIPS16
5728 /* MIPS16: Not implemented. */
5730 #ifdef MIPS_HAS_MDMX
5732 /* MDMX: Not implemented. */
5734 default: /* Invalid */
5735 MIPS_INVAL("major opcode");
5736 generate_exception(ctx, EXCP_RI);
5739 if (ctx->hflags & MIPS_HFLAG_BMASK) {
5740 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
5741 /* Branches completion */
5742 ctx->hflags &= ~MIPS_HFLAG_BMASK;
5743 ctx->bstate = BS_BRANCH;
5744 save_cpu_state(ctx, 0);
5747 /* unconditional branch */
5748 MIPS_DEBUG("unconditional branch");
5749 gen_goto_tb(ctx, 0, ctx->btarget);
5752 /* blikely taken case */
5753 MIPS_DEBUG("blikely branch taken");
5754 gen_goto_tb(ctx, 0, ctx->btarget);
5757 /* Conditional branch */
5758 MIPS_DEBUG("conditional branch");
5761 l1 = gen_new_label();
5763 gen_goto_tb(ctx, 1, ctx->pc + 4);
5765 gen_goto_tb(ctx, 0, ctx->btarget);
5769 /* unconditional branch to register */
5770 MIPS_DEBUG("branch to register");
5776 MIPS_DEBUG("unknown branch");
5783 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
5786 DisasContext ctx, *ctxp = &ctx;
5787 target_ulong pc_start;
5788 uint16_t *gen_opc_end;
5791 if (search_pc && loglevel)
5792 fprintf (logfile, "search pc %d\n", search_pc);
5795 gen_opc_ptr = gen_opc_buf;
5796 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
5797 gen_opparam_ptr = gen_opparam_buf;
5802 ctx.bstate = BS_NONE;
5803 /* Restore delay slot state from the tb context. */
5804 ctx.hflags = tb->flags;
5805 ctx.saved_hflags = ctx.hflags;
5806 switch (ctx.hflags & MIPS_HFLAG_BMASK) {
5808 gen_op_restore_breg_target();
5811 ctx.btarget = env->btarget;
5815 ctx.btarget = env->btarget;
5816 gen_op_restore_bcond();
5819 #if defined(CONFIG_USER_ONLY)
5822 ctx.mem_idx = !((ctx.hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM);
5824 ctx.CP0_Status = env->CP0_Status;
5826 if (loglevel & CPU_LOG_TB_CPU) {
5827 fprintf(logfile, "------------------------------------------------\n");
5828 /* FIXME: This may print out stale hflags from env... */
5829 cpu_dump_state(env, logfile, fprintf, 0);
5832 #ifdef MIPS_DEBUG_DISAS
5833 if (loglevel & CPU_LOG_TB_IN_ASM)
5834 fprintf(logfile, "\ntb %p super %d cond %04x\n",
5835 tb, ctx.mem_idx, ctx.hflags);
5837 while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) {
5838 if (env->nb_breakpoints > 0) {
5839 for(j = 0; j < env->nb_breakpoints; j++) {
5840 if (env->breakpoints[j] == ctx.pc) {
5841 save_cpu_state(ctxp, 1);
5842 ctx.bstate = BS_BRANCH;
5844 goto done_generating;
5850 j = gen_opc_ptr - gen_opc_buf;
5854 gen_opc_instr_start[lj++] = 0;
5856 gen_opc_pc[lj] = ctx.pc;
5857 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
5858 gen_opc_instr_start[lj] = 1;
5860 ctx.opcode = ldl_code(ctx.pc);
5861 decode_opc(env, &ctx);
5864 if (env->singlestep_enabled)
5867 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
5870 #if defined (MIPS_SINGLE_STEP)
5874 if (env->singlestep_enabled) {
5875 save_cpu_state(ctxp, ctx.bstate == BS_NONE);
5878 switch (ctx.bstate) {
5880 gen_op_interrupt_restart();
5883 save_cpu_state(ctxp, 0);
5884 gen_goto_tb(&ctx, 0, ctx.pc);
5887 gen_op_interrupt_restart();
5897 *gen_opc_ptr = INDEX_op_end;
5899 j = gen_opc_ptr - gen_opc_buf;
5902 gen_opc_instr_start[lj++] = 0;
5905 tb->size = ctx.pc - pc_start;
5908 #if defined MIPS_DEBUG_DISAS
5909 if (loglevel & CPU_LOG_TB_IN_ASM)
5910 fprintf(logfile, "\n");
5912 if (loglevel & CPU_LOG_TB_IN_ASM) {
5913 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
5914 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
5915 fprintf(logfile, "\n");
5917 if (loglevel & CPU_LOG_TB_OP) {
5918 fprintf(logfile, "OP:\n");
5919 dump_ops(gen_opc_buf, gen_opparam_buf);
5920 fprintf(logfile, "\n");
5922 if (loglevel & CPU_LOG_TB_CPU) {
5923 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
5930 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
5932 return gen_intermediate_code_internal(env, tb, 0);
5935 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
5937 return gen_intermediate_code_internal(env, tb, 1);
5940 void fpu_dump_state(CPUState *env, FILE *f,
5941 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
5945 int is_fpu64 = !!(env->CP0_Status & (1 << CP0St_FR));
5947 #define printfpr(fp) \
5950 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
5951 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
5952 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
5955 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
5956 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
5957 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
5958 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
5959 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
5964 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
5965 env->fcr0, env->fcr31, is_fpu64, env->fp_status, get_float_exception_flags(&env->fp_status));
5966 fpu_fprintf(f, "FT0: "); printfpr(&env->ft0);
5967 fpu_fprintf(f, "FT1: "); printfpr(&env->ft1);
5968 fpu_fprintf(f, "FT2: "); printfpr(&env->ft2);
5969 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
5970 fpu_fprintf(f, "%3s: ", fregnames[i]);
5971 printfpr(&env->fpr[i]);
5977 void dump_fpu (CPUState *env)
5980 fprintf(logfile, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " %d\n",
5981 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
5982 fpu_dump_state(env, logfile, fprintf, 0);
5986 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
5987 /* Debug help: The architecture requires 32bit code to maintain proper
5988 sign-extened values on 64bit machines. */
5990 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
5992 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
5993 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5998 if (!SIGN_EXT_P(env->PC))
5999 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->PC);
6000 if (!SIGN_EXT_P(env->HI))
6001 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->HI);
6002 if (!SIGN_EXT_P(env->LO))
6003 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->LO);
6004 if (!SIGN_EXT_P(env->btarget))
6005 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
6007 for (i = 0; i < 32; i++) {
6008 if (!SIGN_EXT_P(env->gpr[i]))
6009 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->gpr[i]);
6012 if (!SIGN_EXT_P(env->CP0_EPC))
6013 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
6014 if (!SIGN_EXT_P(env->CP0_LLAddr))
6015 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
6019 void cpu_dump_state (CPUState *env, FILE *f,
6020 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6026 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",
6027 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
6028 for (i = 0; i < 32; i++) {
6030 cpu_fprintf(f, "GPR%02d:", i);
6031 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->gpr[i]);
6033 cpu_fprintf(f, "\n");
6036 c0_status = env->CP0_Status;
6038 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
6039 c0_status, env->CP0_Cause, env->CP0_EPC);
6040 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
6041 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
6042 if (c0_status & (1 << CP0St_CU1))
6043 fpu_dump_state(env, f, cpu_fprintf, flags);
6044 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
6045 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
6049 CPUMIPSState *cpu_mips_init (void)
6053 env = qemu_mallocz(sizeof(CPUMIPSState));
6061 void cpu_reset (CPUMIPSState *env)
6063 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
6068 #if !defined(CONFIG_USER_ONLY)
6069 if (env->hflags & MIPS_HFLAG_BMASK) {
6070 /* If the exception was raised from a delay slot,
6071 * come back to the jump. */
6072 env->CP0_ErrorEPC = env->PC - 4;
6073 env->hflags &= ~MIPS_HFLAG_BMASK;
6075 env->CP0_ErrorEPC = env->PC;
6078 env->PC = (int32_t)0xBFC00000;
6080 /* SMP not implemented */
6081 env->CP0_EBase = 0x80000000;
6082 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
6083 /* vectored interrupts not implemented, timer on int 7,
6084 no performance counters. */
6085 env->CP0_IntCtl = 0xe0000000;
6086 env->CP0_WatchLo = 0;
6087 env->CP0_WatchHi = 0;
6088 /* Count register increments in debug mode, EJTAG version 1 */
6089 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
6091 env->exception_index = EXCP_NONE;
6092 #if defined(CONFIG_USER_ONLY)
6093 env->hflags |= MIPS_HFLAG_UM;
6094 env->user_mode_only = 1;
6098 #include "translate_init.c"