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 = 0x32 | 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 #if defined 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 = "unk";
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);
752 GEN_STORE_TN_REG(rt, T0);
756 GEN_LOAD_REG_TN(T1, rt);
762 GEN_STORE_TN_REG(rt, T0);
766 GEN_LOAD_REG_TN(T1, rt);
773 GEN_STORE_TN_REG(rt, T0);
778 GEN_STORE_TN_REG(rt, T0);
782 GEN_LOAD_REG_TN(T1, rt);
788 GEN_STORE_TN_REG(rt, T0);
792 GEN_LOAD_REG_TN(T1, rt);
798 GEN_STORE_TN_REG(rt, T0);
803 GEN_STORE_TN_REG(rt, T0);
807 GEN_LOAD_REG_TN(T1, rt);
813 GEN_STORE_TN_REG(rt, T0);
817 GEN_LOAD_REG_TN(T1, rt);
819 GEN_STORE_TN_REG(rt, T0);
823 GEN_LOAD_REG_TN(T1, rt);
828 GEN_LOAD_REG_TN(T1, rt);
830 GEN_STORE_TN_REG(rt, T0);
834 GEN_LOAD_REG_TN(T1, rt);
840 GEN_STORE_TN_REG(rt, T0);
844 save_cpu_state(ctx, 1);
845 GEN_LOAD_REG_TN(T1, rt);
847 GEN_STORE_TN_REG(rt, T0);
851 MIPS_INVAL("load/store");
852 generate_exception(ctx, EXCP_RI);
855 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
859 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
860 int base, int16_t offset)
862 const char *opn = "unk";
865 GEN_LOAD_IMM_TN(T0, offset);
866 } else if (offset == 0) {
867 gen_op_load_gpr_T0(base);
869 gen_op_load_gpr_T0(base);
870 gen_op_set_T1(offset);
873 /* Don't do NOP if destination is zero: we must perform the actual
879 GEN_STORE_FTN_FREG(ft, WT0);
883 GEN_LOAD_FREG_FTN(WT0, ft);
889 GEN_STORE_FTN_FREG(ft, DT0);
893 GEN_LOAD_FREG_FTN(DT0, ft);
898 MIPS_INVAL("float load/store");
899 generate_exception(ctx, EXCP_RI);
902 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
905 /* Arithmetic with immediate operand */
906 static void gen_arith_imm (DisasContext *ctx, uint32_t opc, int rt,
910 const char *opn = "unk";
912 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
913 /* if no destination, treat it as a NOP
914 * For addi, we must generate the overflow exception when needed.
919 uimm = (uint16_t)imm;
929 uimm = (int32_t)imm; /* Sign extend to 32 bits */
934 GEN_LOAD_REG_TN(T0, rs);
935 GEN_LOAD_IMM_TN(T1, uimm);
938 GEN_LOAD_IMM_TN(T0, uimm << 16);
952 GEN_LOAD_REG_TN(T0, rs);
953 GEN_LOAD_IMM_TN(T1, uimm);
958 save_cpu_state(ctx, 1);
968 save_cpu_state(ctx, 1);
1009 switch ((ctx->opcode >> 21) & 0x1f) {
1019 MIPS_INVAL("invalid srl flag");
1020 generate_exception(ctx, EXCP_RI);
1024 #ifdef TARGET_MIPS64
1034 switch ((ctx->opcode >> 21) & 0x1f) {
1044 MIPS_INVAL("invalid dsrl flag");
1045 generate_exception(ctx, EXCP_RI);
1058 switch ((ctx->opcode >> 21) & 0x1f) {
1068 MIPS_INVAL("invalid dsrl32 flag");
1069 generate_exception(ctx, EXCP_RI);
1075 MIPS_INVAL("imm arith");
1076 generate_exception(ctx, EXCP_RI);
1079 GEN_STORE_TN_REG(rt, T0);
1080 MIPS_DEBUG("%s %s, %s, %x", opn, regnames[rt], regnames[rs], uimm);
1084 static void gen_arith (DisasContext *ctx, uint32_t opc,
1085 int rd, int rs, int rt)
1087 const char *opn = "unk";
1089 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1090 && opc != OPC_DADD && opc != OPC_DSUB) {
1091 /* if no destination, treat it as a NOP
1092 * For add & sub, we must generate the overflow exception when needed.
1097 GEN_LOAD_REG_TN(T0, rs);
1098 GEN_LOAD_REG_TN(T1, rt);
1101 save_cpu_state(ctx, 1);
1110 save_cpu_state(ctx, 1);
1118 #ifdef TARGET_MIPS64
1120 save_cpu_state(ctx, 1);
1129 save_cpu_state(ctx, 1);
1183 switch ((ctx->opcode >> 6) & 0x1f) {
1193 MIPS_INVAL("invalid srlv flag");
1194 generate_exception(ctx, EXCP_RI);
1198 #ifdef TARGET_MIPS64
1208 switch ((ctx->opcode >> 6) & 0x1f) {
1218 MIPS_INVAL("invalid dsrlv flag");
1219 generate_exception(ctx, EXCP_RI);
1225 MIPS_INVAL("arith");
1226 generate_exception(ctx, EXCP_RI);
1229 GEN_STORE_TN_REG(rd, T0);
1231 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1234 /* Arithmetic on HI/LO registers */
1235 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1237 const char *opn = "unk";
1239 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1240 /* Treat as a NOP */
1247 GEN_STORE_TN_REG(reg, T0);
1252 GEN_STORE_TN_REG(reg, T0);
1256 GEN_LOAD_REG_TN(T0, reg);
1261 GEN_LOAD_REG_TN(T0, reg);
1267 generate_exception(ctx, EXCP_RI);
1270 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1273 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1276 const char *opn = "unk";
1278 GEN_LOAD_REG_TN(T0, rs);
1279 GEN_LOAD_REG_TN(T1, rt);
1297 #ifdef TARGET_MIPS64
1332 MIPS_INVAL("mul/div");
1333 generate_exception(ctx, EXCP_RI);
1336 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
1339 static void gen_cl (DisasContext *ctx, uint32_t opc,
1342 const char *opn = "unk";
1344 /* Treat as a NOP */
1348 GEN_LOAD_REG_TN(T0, rs);
1358 #ifdef TARGET_MIPS64
1370 generate_exception(ctx, EXCP_RI);
1373 gen_op_store_T0_gpr(rd);
1374 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
1378 static void gen_trap (DisasContext *ctx, uint32_t opc,
1379 int rs, int rt, int16_t imm)
1384 /* Load needed operands */
1392 /* Compare two registers */
1394 GEN_LOAD_REG_TN(T0, rs);
1395 GEN_LOAD_REG_TN(T1, rt);
1405 /* Compare register to immediate */
1406 if (rs != 0 || imm != 0) {
1407 GEN_LOAD_REG_TN(T0, rs);
1408 GEN_LOAD_IMM_TN(T1, (int32_t)imm);
1415 case OPC_TEQ: /* rs == rs */
1416 case OPC_TEQI: /* r0 == 0 */
1417 case OPC_TGE: /* rs >= rs */
1418 case OPC_TGEI: /* r0 >= 0 */
1419 case OPC_TGEU: /* rs >= rs unsigned */
1420 case OPC_TGEIU: /* r0 >= 0 unsigned */
1424 case OPC_TLT: /* rs < rs */
1425 case OPC_TLTI: /* r0 < 0 */
1426 case OPC_TLTU: /* rs < rs unsigned */
1427 case OPC_TLTIU: /* r0 < 0 unsigned */
1428 case OPC_TNE: /* rs != rs */
1429 case OPC_TNEI: /* r0 != 0 */
1430 /* Never trap: treat as NOP */
1434 generate_exception(ctx, EXCP_RI);
1465 generate_exception(ctx, EXCP_RI);
1469 save_cpu_state(ctx, 1);
1471 ctx->bstate = BS_STOP;
1474 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
1476 TranslationBlock *tb;
1478 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
1480 gen_op_goto_tb0(TBPARAM(tb));
1482 gen_op_goto_tb1(TBPARAM(tb));
1483 gen_op_save_pc(dest);
1484 gen_op_set_T0((long)tb + n);
1486 gen_op_save_pc(dest);
1492 /* Branches (before delay slot) */
1493 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
1494 int rs, int rt, int32_t offset)
1496 target_ulong btarget = -1;
1500 if (ctx->hflags & MIPS_HFLAG_BMASK) {
1501 if (loglevel & CPU_LOG_TB_IN_ASM) {
1503 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
1506 MIPS_INVAL("branch/jump in bdelay slot");
1507 generate_exception(ctx, EXCP_RI);
1511 /* Load needed operands */
1517 /* Compare two registers */
1519 GEN_LOAD_REG_TN(T0, rs);
1520 GEN_LOAD_REG_TN(T1, rt);
1523 btarget = ctx->pc + 4 + offset;
1537 /* Compare to zero */
1539 gen_op_load_gpr_T0(rs);
1542 btarget = ctx->pc + 4 + offset;
1546 /* Jump to immediate */
1547 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | offset;
1551 /* Jump to register */
1552 if (offset != 0 && offset != 16) {
1553 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
1554 others are reserved. */
1555 generate_exception(ctx, EXCP_RI);
1558 GEN_LOAD_REG_TN(T2, rs);
1561 MIPS_INVAL("branch/jump");
1562 generate_exception(ctx, EXCP_RI);
1566 /* No condition to be computed */
1568 case OPC_BEQ: /* rx == rx */
1569 case OPC_BEQL: /* rx == rx likely */
1570 case OPC_BGEZ: /* 0 >= 0 */
1571 case OPC_BGEZL: /* 0 >= 0 likely */
1572 case OPC_BLEZ: /* 0 <= 0 */
1573 case OPC_BLEZL: /* 0 <= 0 likely */
1575 ctx->hflags |= MIPS_HFLAG_B;
1576 MIPS_DEBUG("balways");
1578 case OPC_BGEZAL: /* 0 >= 0 */
1579 case OPC_BGEZALL: /* 0 >= 0 likely */
1580 /* Always take and link */
1582 ctx->hflags |= MIPS_HFLAG_B;
1583 MIPS_DEBUG("balways and link");
1585 case OPC_BNE: /* rx != rx */
1586 case OPC_BGTZ: /* 0 > 0 */
1587 case OPC_BLTZ: /* 0 < 0 */
1588 /* Treated as NOP */
1589 MIPS_DEBUG("bnever (NOP)");
1591 case OPC_BLTZAL: /* 0 < 0 */
1592 gen_op_set_T0(ctx->pc + 8);
1593 gen_op_store_T0_gpr(31);
1594 MIPS_DEBUG("bnever and link");
1596 case OPC_BLTZALL: /* 0 < 0 likely */
1597 gen_op_set_T0(ctx->pc + 8);
1598 gen_op_store_T0_gpr(31);
1599 /* Skip the instruction in the delay slot */
1600 MIPS_DEBUG("bnever, link and skip");
1603 case OPC_BNEL: /* rx != rx likely */
1604 case OPC_BGTZL: /* 0 > 0 likely */
1605 case OPC_BLTZL: /* 0 < 0 likely */
1606 /* Skip the instruction in the delay slot */
1607 MIPS_DEBUG("bnever and skip");
1611 ctx->hflags |= MIPS_HFLAG_B;
1612 MIPS_DEBUG("j %08x", btarget);
1616 ctx->hflags |= MIPS_HFLAG_B;
1617 MIPS_DEBUG("jal %08x", btarget);
1620 ctx->hflags |= MIPS_HFLAG_BR;
1621 MIPS_DEBUG("jr %s", regnames[rs]);
1625 ctx->hflags |= MIPS_HFLAG_BR;
1626 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
1629 MIPS_INVAL("branch/jump");
1630 generate_exception(ctx, EXCP_RI);
1637 MIPS_DEBUG("beq %s, %s, %08x",
1638 regnames[rs], regnames[rt], btarget);
1642 MIPS_DEBUG("beql %s, %s, %08x",
1643 regnames[rs], regnames[rt], btarget);
1647 MIPS_DEBUG("bne %s, %s, %08x",
1648 regnames[rs], regnames[rt], btarget);
1652 MIPS_DEBUG("bnel %s, %s, %08x",
1653 regnames[rs], regnames[rt], btarget);
1657 MIPS_DEBUG("bgez %s, %08x", regnames[rs], btarget);
1661 MIPS_DEBUG("bgezl %s, %08x", regnames[rs], btarget);
1665 MIPS_DEBUG("bgezal %s, %08x", regnames[rs], btarget);
1671 MIPS_DEBUG("bgezall %s, %08x", regnames[rs], btarget);
1675 MIPS_DEBUG("bgtz %s, %08x", regnames[rs], btarget);
1679 MIPS_DEBUG("bgtzl %s, %08x", regnames[rs], btarget);
1683 MIPS_DEBUG("blez %s, %08x", regnames[rs], btarget);
1687 MIPS_DEBUG("blezl %s, %08x", regnames[rs], btarget);
1691 MIPS_DEBUG("bltz %s, %08x", regnames[rs], btarget);
1695 MIPS_DEBUG("bltzl %s, %08x", regnames[rs], btarget);
1700 MIPS_DEBUG("bltzal %s, %08x", regnames[rs], btarget);
1702 ctx->hflags |= MIPS_HFLAG_BC;
1708 MIPS_DEBUG("bltzall %s, %08x", regnames[rs], btarget);
1710 ctx->hflags |= MIPS_HFLAG_BL;
1712 gen_op_save_bcond();
1715 MIPS_INVAL("conditional branch/jump");
1716 generate_exception(ctx, EXCP_RI);
1720 MIPS_DEBUG("enter ds: link %d cond %02x target %08x",
1721 blink, ctx->hflags, btarget);
1722 ctx->btarget = btarget;
1724 gen_op_set_T0(ctx->pc + 8);
1725 gen_op_store_T0_gpr(blink);
1729 /* special3 bitfield operations */
1730 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
1731 int rs, int lsb, int msb)
1733 GEN_LOAD_REG_TN(T1, rs);
1738 gen_op_ext(lsb, msb + 1);
1743 gen_op_ext(lsb, msb + 1 + 32);
1748 gen_op_ext(lsb + 32, msb + 1);
1751 gen_op_ext(lsb, msb + 1);
1756 GEN_LOAD_REG_TN(T0, rt);
1757 gen_op_ins(lsb, msb - lsb + 1);
1762 GEN_LOAD_REG_TN(T0, rt);
1763 gen_op_ins(lsb, msb - lsb + 1 + 32);
1768 GEN_LOAD_REG_TN(T0, rt);
1769 gen_op_ins(lsb + 32, msb - lsb + 1);
1774 GEN_LOAD_REG_TN(T0, rt);
1775 gen_op_ins(lsb, msb - lsb + 1);
1779 MIPS_INVAL("bitops");
1780 generate_exception(ctx, EXCP_RI);
1783 GEN_STORE_TN_REG(rt, T0);
1786 /* CP0 (MMU and control) */
1787 static void gen_mfc0 (DisasContext *ctx, int reg, int sel)
1789 const char *rn = "invalid";
1795 gen_op_mfc0_index();
1799 // gen_op_mfc0_mvpcontrol(); /* MT ASE */
1803 // gen_op_mfc0_mvpconf0(); /* MT ASE */
1807 // gen_op_mfc0_mvpconf1(); /* MT ASE */
1817 gen_op_mfc0_random();
1821 // gen_op_mfc0_vpecontrol(); /* MT ASE */
1825 // gen_op_mfc0_vpeconf0(); /* MT ASE */
1829 // gen_op_mfc0_vpeconf1(); /* MT ASE */
1833 // gen_op_mfc0_YQMask(); /* MT ASE */
1837 // gen_op_mfc0_vpeschedule(); /* MT ASE */
1841 // gen_op_mfc0_vpeschefback(); /* MT ASE */
1842 rn = "VPEScheFBack";
1845 // gen_op_mfc0_vpeopt(); /* MT ASE */
1855 gen_op_mfc0_entrylo0();
1859 // gen_op_mfc0_tcstatus(); /* MT ASE */
1863 // gen_op_mfc0_tcbind(); /* MT ASE */
1867 // gen_op_mfc0_tcrestart(); /* MT ASE */
1871 // gen_op_mfc0_tchalt(); /* MT ASE */
1875 // gen_op_mfc0_tccontext(); /* MT ASE */
1879 // gen_op_mfc0_tcschedule(); /* MT ASE */
1883 // gen_op_mfc0_tcschefback(); /* MT ASE */
1893 gen_op_mfc0_entrylo1();
1903 gen_op_mfc0_context();
1907 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
1908 rn = "ContextConfig";
1917 gen_op_mfc0_pagemask();
1921 gen_op_mfc0_pagegrain();
1931 gen_op_mfc0_wired();
1935 // gen_op_mfc0_srsconf0(); /* shadow registers */
1939 // gen_op_mfc0_srsconf1(); /* shadow registers */
1943 // gen_op_mfc0_srsconf2(); /* shadow registers */
1947 // gen_op_mfc0_srsconf3(); /* shadow registers */
1951 // gen_op_mfc0_srsconf4(); /* shadow registers */
1961 gen_op_mfc0_hwrena();
1971 gen_op_mfc0_badvaddr();
1981 gen_op_mfc0_count();
1984 /* 6,7 are implementation dependent */
1992 gen_op_mfc0_entryhi();
2002 gen_op_mfc0_compare();
2005 /* 6,7 are implementation dependent */
2013 gen_op_mfc0_status();
2017 gen_op_mfc0_intctl();
2021 gen_op_mfc0_srsctl();
2025 // gen_op_mfc0_srsmap(); /* shadow registers */
2035 gen_op_mfc0_cause();
2059 gen_op_mfc0_ebase();
2069 gen_op_mfc0_config0();
2073 gen_op_mfc0_config1();
2077 gen_op_mfc0_config2();
2081 gen_op_mfc0_config3();
2084 /* 4,5 are reserved */
2085 /* 6,7 are implementation dependent */
2087 gen_op_mfc0_config6();
2091 gen_op_mfc0_config7();
2101 gen_op_mfc0_lladdr();
2111 gen_op_mfc0_watchlo0();
2115 // gen_op_mfc0_watchlo1();
2119 // gen_op_mfc0_watchlo2();
2123 // gen_op_mfc0_watchlo3();
2127 // gen_op_mfc0_watchlo4();
2131 // gen_op_mfc0_watchlo5();
2135 // gen_op_mfc0_watchlo6();
2139 // gen_op_mfc0_watchlo7();
2149 gen_op_mfc0_watchhi0();
2153 // gen_op_mfc0_watchhi1();
2157 // gen_op_mfc0_watchhi2();
2161 // gen_op_mfc0_watchhi3();
2165 // gen_op_mfc0_watchhi4();
2169 // gen_op_mfc0_watchhi5();
2173 // gen_op_mfc0_watchhi6();
2177 // gen_op_mfc0_watchhi7();
2187 /* 64 bit MMU only */
2188 gen_op_mfc0_xcontext();
2196 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2199 gen_op_mfc0_framemask();
2208 rn = "'Diagnostic"; /* implementation dependent */
2213 gen_op_mfc0_debug(); /* EJTAG support */
2217 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
2218 rn = "TraceControl";
2221 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
2222 rn = "TraceControl2";
2225 // gen_op_mfc0_usertracedata(); /* PDtrace support */
2226 rn = "UserTraceData";
2229 // gen_op_mfc0_debug(); /* PDtrace support */
2239 gen_op_mfc0_depc(); /* EJTAG support */
2249 gen_op_mfc0_performance0();
2250 rn = "Performance0";
2253 // gen_op_mfc0_performance1();
2254 rn = "Performance1";
2257 // gen_op_mfc0_performance2();
2258 rn = "Performance2";
2261 // gen_op_mfc0_performance3();
2262 rn = "Performance3";
2265 // gen_op_mfc0_performance4();
2266 rn = "Performance4";
2269 // gen_op_mfc0_performance5();
2270 rn = "Performance5";
2273 // gen_op_mfc0_performance6();
2274 rn = "Performance6";
2277 // gen_op_mfc0_performance7();
2278 rn = "Performance7";
2303 gen_op_mfc0_taglo();
2310 gen_op_mfc0_datalo();
2323 gen_op_mfc0_taghi();
2330 gen_op_mfc0_datahi();
2340 gen_op_mfc0_errorepc();
2350 gen_op_mfc0_desave(); /* EJTAG support */
2360 #if defined MIPS_DEBUG_DISAS
2361 if (loglevel & CPU_LOG_TB_IN_ASM) {
2362 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2369 #if defined MIPS_DEBUG_DISAS
2370 if (loglevel & CPU_LOG_TB_IN_ASM) {
2371 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
2375 generate_exception(ctx, EXCP_RI);
2378 static void gen_mtc0 (DisasContext *ctx, int reg, int sel)
2380 const char *rn = "invalid";
2386 gen_op_mtc0_index();
2390 // gen_op_mtc0_mvpcontrol(); /* MT ASE */
2394 // gen_op_mtc0_mvpconf0(); /* MT ASE */
2398 // gen_op_mtc0_mvpconf1(); /* MT ASE */
2412 // gen_op_mtc0_vpecontrol(); /* MT ASE */
2416 // gen_op_mtc0_vpeconf0(); /* MT ASE */
2420 // gen_op_mtc0_vpeconf1(); /* MT ASE */
2424 // gen_op_mtc0_YQMask(); /* MT ASE */
2428 // gen_op_mtc0_vpeschedule(); /* MT ASE */
2432 // gen_op_mtc0_vpeschefback(); /* MT ASE */
2433 rn = "VPEScheFBack";
2436 // gen_op_mtc0_vpeopt(); /* MT ASE */
2446 gen_op_mtc0_entrylo0();
2450 // gen_op_mtc0_tcstatus(); /* MT ASE */
2454 // gen_op_mtc0_tcbind(); /* MT ASE */
2458 // gen_op_mtc0_tcrestart(); /* MT ASE */
2462 // gen_op_mtc0_tchalt(); /* MT ASE */
2466 // gen_op_mtc0_tccontext(); /* MT ASE */
2470 // gen_op_mtc0_tcschedule(); /* MT ASE */
2474 // gen_op_mtc0_tcschefback(); /* MT ASE */
2484 gen_op_mtc0_entrylo1();
2494 gen_op_mtc0_context();
2498 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
2499 rn = "ContextConfig";
2508 gen_op_mtc0_pagemask();
2512 gen_op_mtc0_pagegrain();
2522 gen_op_mtc0_wired();
2526 // gen_op_mtc0_srsconf0(); /* shadow registers */
2530 // gen_op_mtc0_srsconf1(); /* shadow registers */
2534 // gen_op_mtc0_srsconf2(); /* shadow registers */
2538 // gen_op_mtc0_srsconf3(); /* shadow registers */
2542 // gen_op_mtc0_srsconf4(); /* shadow registers */
2552 gen_op_mtc0_hwrena();
2566 gen_op_mtc0_count();
2569 /* 6,7 are implementation dependent */
2573 /* Stop translation as we may have switched the execution mode */
2574 ctx->bstate = BS_STOP;
2579 gen_op_mtc0_entryhi();
2589 gen_op_mtc0_compare();
2592 /* 6,7 are implementation dependent */
2596 /* Stop translation as we may have switched the execution mode */
2597 ctx->bstate = BS_STOP;
2602 gen_op_mtc0_status();
2606 gen_op_mtc0_intctl();
2610 gen_op_mtc0_srsctl();
2614 // gen_op_mtc0_srsmap(); /* shadow registers */
2620 /* Stop translation as we may have switched the execution mode */
2621 ctx->bstate = BS_STOP;
2626 gen_op_mtc0_cause();
2632 /* Stop translation as we may have switched the execution mode */
2633 ctx->bstate = BS_STOP;
2652 gen_op_mtc0_ebase();
2662 gen_op_mtc0_config0();
2664 /* Stop translation as we may have switched the execution mode */
2665 ctx->bstate = BS_STOP;
2668 /* ignored, read only */
2672 gen_op_mtc0_config2();
2674 /* Stop translation as we may have switched the execution mode */
2675 ctx->bstate = BS_STOP;
2678 /* ignored, read only */
2681 /* 4,5 are reserved */
2682 /* 6,7 are implementation dependent */
2692 rn = "Invalid config selector";
2709 gen_op_mtc0_watchlo0();
2713 // gen_op_mtc0_watchlo1();
2717 // gen_op_mtc0_watchlo2();
2721 // gen_op_mtc0_watchlo3();
2725 // gen_op_mtc0_watchlo4();
2729 // gen_op_mtc0_watchlo5();
2733 // gen_op_mtc0_watchlo6();
2737 // gen_op_mtc0_watchlo7();
2747 gen_op_mtc0_watchhi0();
2751 // gen_op_mtc0_watchhi1();
2755 // gen_op_mtc0_watchhi2();
2759 // gen_op_mtc0_watchhi3();
2763 // gen_op_mtc0_watchhi4();
2767 // gen_op_mtc0_watchhi5();
2771 // gen_op_mtc0_watchhi6();
2775 // gen_op_mtc0_watchhi7();
2785 /* 64 bit MMU only */
2786 /* Nothing writable in lower 32 bits */
2794 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2797 gen_op_mtc0_framemask();
2806 rn = "Diagnostic"; /* implementation dependent */
2811 gen_op_mtc0_debug(); /* EJTAG support */
2815 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
2816 rn = "TraceControl";
2819 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
2820 rn = "TraceControl2";
2823 // gen_op_mtc0_usertracedata(); /* PDtrace support */
2824 rn = "UserTraceData";
2827 // gen_op_mtc0_debug(); /* PDtrace support */
2833 /* Stop translation as we may have switched the execution mode */
2834 ctx->bstate = BS_STOP;
2839 gen_op_mtc0_depc(); /* EJTAG support */
2849 gen_op_mtc0_performance0();
2850 rn = "Performance0";
2853 // gen_op_mtc0_performance1();
2854 rn = "Performance1";
2857 // gen_op_mtc0_performance2();
2858 rn = "Performance2";
2861 // gen_op_mtc0_performance3();
2862 rn = "Performance3";
2865 // gen_op_mtc0_performance4();
2866 rn = "Performance4";
2869 // gen_op_mtc0_performance5();
2870 rn = "Performance5";
2873 // gen_op_mtc0_performance6();
2874 rn = "Performance6";
2877 // gen_op_mtc0_performance7();
2878 rn = "Performance7";
2904 gen_op_mtc0_taglo();
2911 gen_op_mtc0_datalo();
2924 gen_op_mtc0_taghi();
2931 gen_op_mtc0_datahi();
2942 gen_op_mtc0_errorepc();
2952 gen_op_mtc0_desave(); /* EJTAG support */
2958 /* Stop translation as we may have switched the execution mode */
2959 ctx->bstate = BS_STOP;
2964 #if defined MIPS_DEBUG_DISAS
2965 if (loglevel & CPU_LOG_TB_IN_ASM) {
2966 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2973 #if defined MIPS_DEBUG_DISAS
2974 if (loglevel & CPU_LOG_TB_IN_ASM) {
2975 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
2979 generate_exception(ctx, EXCP_RI);
2982 #ifdef TARGET_MIPS64
2983 static void gen_dmfc0 (DisasContext *ctx, int reg, int sel)
2985 const char *rn = "invalid";
2991 gen_op_mfc0_index();
2995 // gen_op_dmfc0_mvpcontrol(); /* MT ASE */
2999 // gen_op_dmfc0_mvpconf0(); /* MT ASE */
3003 // gen_op_dmfc0_mvpconf1(); /* MT ASE */
3013 gen_op_mfc0_random();
3017 // gen_op_dmfc0_vpecontrol(); /* MT ASE */
3021 // gen_op_dmfc0_vpeconf0(); /* MT ASE */
3025 // gen_op_dmfc0_vpeconf1(); /* MT ASE */
3029 // gen_op_dmfc0_YQMask(); /* MT ASE */
3033 // gen_op_dmfc0_vpeschedule(); /* MT ASE */
3037 // gen_op_dmfc0_vpeschefback(); /* MT ASE */
3038 rn = "VPEScheFBack";
3041 // gen_op_dmfc0_vpeopt(); /* MT ASE */
3051 gen_op_dmfc0_entrylo0();
3055 // gen_op_dmfc0_tcstatus(); /* MT ASE */
3059 // gen_op_dmfc0_tcbind(); /* MT ASE */
3063 // gen_op_dmfc0_tcrestart(); /* MT ASE */
3067 // gen_op_dmfc0_tchalt(); /* MT ASE */
3071 // gen_op_dmfc0_tccontext(); /* MT ASE */
3075 // gen_op_dmfc0_tcschedule(); /* MT ASE */
3079 // gen_op_dmfc0_tcschefback(); /* MT ASE */
3089 gen_op_dmfc0_entrylo1();
3099 gen_op_dmfc0_context();
3103 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3104 rn = "ContextConfig";
3113 gen_op_mfc0_pagemask();
3117 gen_op_mfc0_pagegrain();
3127 gen_op_mfc0_wired();
3131 // gen_op_dmfc0_srsconf0(); /* shadow registers */
3135 // gen_op_dmfc0_srsconf1(); /* shadow registers */
3139 // gen_op_dmfc0_srsconf2(); /* shadow registers */
3143 // gen_op_dmfc0_srsconf3(); /* shadow registers */
3147 // gen_op_dmfc0_srsconf4(); /* shadow registers */
3157 gen_op_mfc0_hwrena();
3167 gen_op_dmfc0_badvaddr();
3177 gen_op_mfc0_count();
3180 /* 6,7 are implementation dependent */
3188 gen_op_dmfc0_entryhi();
3198 gen_op_mfc0_compare();
3201 /* 6,7 are implementation dependent */
3209 gen_op_mfc0_status();
3213 gen_op_mfc0_intctl();
3217 gen_op_mfc0_srsctl();
3221 gen_op_mfc0_srsmap(); /* shadow registers */
3231 gen_op_mfc0_cause();
3255 gen_op_mfc0_ebase();
3265 gen_op_mfc0_config0();
3269 gen_op_mfc0_config1();
3273 gen_op_mfc0_config2();
3277 gen_op_mfc0_config3();
3280 /* 6,7 are implementation dependent */
3288 gen_op_dmfc0_lladdr();
3298 gen_op_dmfc0_watchlo0();
3302 // gen_op_dmfc0_watchlo1();
3306 // gen_op_dmfc0_watchlo2();
3310 // gen_op_dmfc0_watchlo3();
3314 // gen_op_dmfc0_watchlo4();
3318 // gen_op_dmfc0_watchlo5();
3322 // gen_op_dmfc0_watchlo6();
3326 // gen_op_dmfc0_watchlo7();
3336 gen_op_mfc0_watchhi0();
3340 // gen_op_mfc0_watchhi1();
3344 // gen_op_mfc0_watchhi2();
3348 // gen_op_mfc0_watchhi3();
3352 // gen_op_mfc0_watchhi4();
3356 // gen_op_mfc0_watchhi5();
3360 // gen_op_mfc0_watchhi6();
3364 // gen_op_mfc0_watchhi7();
3374 /* 64 bit MMU only */
3375 gen_op_dmfc0_xcontext();
3383 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3386 gen_op_mfc0_framemask();
3395 rn = "'Diagnostic"; /* implementation dependent */
3400 gen_op_mfc0_debug(); /* EJTAG support */
3404 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
3405 rn = "TraceControl";
3408 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
3409 rn = "TraceControl2";
3412 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
3413 rn = "UserTraceData";
3416 // gen_op_dmfc0_debug(); /* PDtrace support */
3426 gen_op_dmfc0_depc(); /* EJTAG support */
3436 gen_op_mfc0_performance0();
3437 rn = "Performance0";
3440 // gen_op_dmfc0_performance1();
3441 rn = "Performance1";
3444 // gen_op_dmfc0_performance2();
3445 rn = "Performance2";
3448 // gen_op_dmfc0_performance3();
3449 rn = "Performance3";
3452 // gen_op_dmfc0_performance4();
3453 rn = "Performance4";
3456 // gen_op_dmfc0_performance5();
3457 rn = "Performance5";
3460 // gen_op_dmfc0_performance6();
3461 rn = "Performance6";
3464 // gen_op_dmfc0_performance7();
3465 rn = "Performance7";
3490 gen_op_mfc0_taglo();
3497 gen_op_mfc0_datalo();
3510 gen_op_mfc0_taghi();
3517 gen_op_mfc0_datahi();
3527 gen_op_dmfc0_errorepc();
3537 gen_op_mfc0_desave(); /* EJTAG support */
3547 #if defined MIPS_DEBUG_DISAS
3548 if (loglevel & CPU_LOG_TB_IN_ASM) {
3549 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3556 #if defined MIPS_DEBUG_DISAS
3557 if (loglevel & CPU_LOG_TB_IN_ASM) {
3558 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
3562 generate_exception(ctx, EXCP_RI);
3565 static void gen_dmtc0 (DisasContext *ctx, int reg, int sel)
3567 const char *rn = "invalid";
3573 gen_op_mtc0_index();
3577 // gen_op_dmtc0_mvpcontrol(); /* MT ASE */
3581 // gen_op_dmtc0_mvpconf0(); /* MT ASE */
3585 // gen_op_dmtc0_mvpconf1(); /* MT ASE */
3599 // gen_op_dmtc0_vpecontrol(); /* MT ASE */
3603 // gen_op_dmtc0_vpeconf0(); /* MT ASE */
3607 // gen_op_dmtc0_vpeconf1(); /* MT ASE */
3611 // gen_op_dmtc0_YQMask(); /* MT ASE */
3615 // gen_op_dmtc0_vpeschedule(); /* MT ASE */
3619 // gen_op_dmtc0_vpeschefback(); /* MT ASE */
3620 rn = "VPEScheFBack";
3623 // gen_op_dmtc0_vpeopt(); /* MT ASE */
3633 gen_op_dmtc0_entrylo0();
3637 // gen_op_dmtc0_tcstatus(); /* MT ASE */
3641 // gen_op_dmtc0_tcbind(); /* MT ASE */
3645 // gen_op_dmtc0_tcrestart(); /* MT ASE */
3649 // gen_op_dmtc0_tchalt(); /* MT ASE */
3653 // gen_op_dmtc0_tccontext(); /* MT ASE */
3657 // gen_op_dmtc0_tcschedule(); /* MT ASE */
3661 // gen_op_dmtc0_tcschefback(); /* MT ASE */
3671 gen_op_dmtc0_entrylo1();
3681 gen_op_dmtc0_context();
3685 // gen_op_dmtc0_contextconfig(); /* SmartMIPS ASE */
3686 rn = "ContextConfig";
3695 gen_op_mtc0_pagemask();
3699 gen_op_mtc0_pagegrain();
3709 gen_op_mtc0_wired();
3713 // gen_op_dmtc0_srsconf0(); /* shadow registers */
3717 // gen_op_dmtc0_srsconf1(); /* shadow registers */
3721 // gen_op_dmtc0_srsconf2(); /* shadow registers */
3725 // gen_op_dmtc0_srsconf3(); /* shadow registers */
3729 // gen_op_dmtc0_srsconf4(); /* shadow registers */
3739 gen_op_mtc0_hwrena();
3753 gen_op_mtc0_count();
3756 /* 6,7 are implementation dependent */
3760 /* Stop translation as we may have switched the execution mode */
3761 ctx->bstate = BS_STOP;
3766 gen_op_mtc0_entryhi();
3776 gen_op_mtc0_compare();
3779 /* 6,7 are implementation dependent */
3783 /* Stop translation as we may have switched the execution mode */
3784 ctx->bstate = BS_STOP;
3789 gen_op_mtc0_status();
3793 gen_op_mtc0_intctl();
3797 gen_op_mtc0_srsctl();
3801 gen_op_mtc0_srsmap(); /* shadow registers */
3807 /* Stop translation as we may have switched the execution mode */
3808 ctx->bstate = BS_STOP;
3813 gen_op_mtc0_cause();
3819 /* Stop translation as we may have switched the execution mode */
3820 ctx->bstate = BS_STOP;
3839 gen_op_mtc0_ebase();
3849 gen_op_mtc0_config0();
3851 /* Stop translation as we may have switched the execution mode */
3852 ctx->bstate = BS_STOP;
3859 gen_op_mtc0_config2();
3861 /* Stop translation as we may have switched the execution mode */
3862 ctx->bstate = BS_STOP;
3868 /* 6,7 are implementation dependent */
3870 rn = "Invalid config selector";
3887 gen_op_dmtc0_watchlo0();
3891 // gen_op_dmtc0_watchlo1();
3895 // gen_op_dmtc0_watchlo2();
3899 // gen_op_dmtc0_watchlo3();
3903 // gen_op_dmtc0_watchlo4();
3907 // gen_op_dmtc0_watchlo5();
3911 // gen_op_dmtc0_watchlo6();
3915 // gen_op_dmtc0_watchlo7();
3925 gen_op_mtc0_watchhi0();
3929 // gen_op_dmtc0_watchhi1();
3933 // gen_op_dmtc0_watchhi2();
3937 // gen_op_dmtc0_watchhi3();
3941 // gen_op_dmtc0_watchhi4();
3945 // gen_op_dmtc0_watchhi5();
3949 // gen_op_dmtc0_watchhi6();
3953 // gen_op_dmtc0_watchhi7();
3963 /* 64 bit MMU only */
3964 gen_op_dmtc0_xcontext();
3972 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3975 gen_op_mtc0_framemask();
3984 rn = "Diagnostic"; /* implementation dependent */
3989 gen_op_mtc0_debug(); /* EJTAG support */
3993 // gen_op_dmtc0_tracecontrol(); /* PDtrace support */
3994 rn = "TraceControl";
3997 // gen_op_dmtc0_tracecontrol2(); /* PDtrace support */
3998 rn = "TraceControl2";
4001 // gen_op_dmtc0_usertracedata(); /* PDtrace support */
4002 rn = "UserTraceData";
4005 // gen_op_dmtc0_debug(); /* PDtrace support */
4011 /* Stop translation as we may have switched the execution mode */
4012 ctx->bstate = BS_STOP;
4017 gen_op_dmtc0_depc(); /* EJTAG support */
4027 gen_op_mtc0_performance0();
4028 rn = "Performance0";
4031 // gen_op_dmtc0_performance1();
4032 rn = "Performance1";
4035 // gen_op_dmtc0_performance2();
4036 rn = "Performance2";
4039 // gen_op_dmtc0_performance3();
4040 rn = "Performance3";
4043 // gen_op_dmtc0_performance4();
4044 rn = "Performance4";
4047 // gen_op_dmtc0_performance5();
4048 rn = "Performance5";
4051 // gen_op_dmtc0_performance6();
4052 rn = "Performance6";
4055 // gen_op_dmtc0_performance7();
4056 rn = "Performance7";
4082 gen_op_mtc0_taglo();
4089 gen_op_mtc0_datalo();
4102 gen_op_mtc0_taghi();
4109 gen_op_mtc0_datahi();
4120 gen_op_dmtc0_errorepc();
4130 gen_op_mtc0_desave(); /* EJTAG support */
4136 /* Stop translation as we may have switched the execution mode */
4137 ctx->bstate = BS_STOP;
4142 #if defined MIPS_DEBUG_DISAS
4143 if (loglevel & CPU_LOG_TB_IN_ASM) {
4144 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4151 #if defined MIPS_DEBUG_DISAS
4152 if (loglevel & CPU_LOG_TB_IN_ASM) {
4153 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4157 generate_exception(ctx, EXCP_RI);
4159 #endif /* TARGET_MIPS64 */
4161 static void gen_cp0 (DisasContext *ctx, uint32_t opc, int rt, int rd)
4163 const char *opn = "unk";
4171 gen_mfc0(ctx, rd, ctx->opcode & 0x7);
4172 gen_op_store_T0_gpr(rt);
4176 GEN_LOAD_REG_TN(T0, rt);
4177 gen_mtc0(ctx, rd, ctx->opcode & 0x7);
4180 #ifdef TARGET_MIPS64
4186 gen_dmfc0(ctx, rd, ctx->opcode & 0x7);
4187 gen_op_store_T0_gpr(rt);
4191 GEN_LOAD_REG_TN(T0, rt);
4192 gen_dmtc0(ctx, rd, ctx->opcode & 0x7);
4196 #if defined(MIPS_USES_R4K_TLB)
4216 save_cpu_state(ctx, 0);
4218 ctx->bstate = BS_EXCP;
4222 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
4223 generate_exception(ctx, EXCP_RI);
4225 save_cpu_state(ctx, 0);
4227 ctx->bstate = BS_EXCP;
4232 /* If we get an exception, we want to restart at next instruction */
4234 save_cpu_state(ctx, 1);
4237 ctx->bstate = BS_EXCP;
4240 if (loglevel & CPU_LOG_TB_IN_ASM) {
4241 fprintf(logfile, "Invalid CP0 opcode: %08x %03x %03x %03x\n",
4242 ctx->opcode, ctx->opcode >> 26, ctx->opcode & 0x3F,
4243 ((ctx->opcode >> 16) & 0x1F));
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;
4257 btarget = ctx->pc + 4 + offset;
4262 MIPS_DEBUG("bc1f " TARGET_FMT_lx, btarget);
4266 MIPS_DEBUG("bc1fl " TARGET_FMT_lx, btarget);
4270 MIPS_DEBUG("bc1t " TARGET_FMT_lx, btarget);
4274 MIPS_DEBUG("bc1tl " TARGET_FMT_lx, btarget);
4276 ctx->hflags |= MIPS_HFLAG_BL;
4278 gen_op_save_bcond();
4281 gen_op_bc1fany2(cc);
4282 MIPS_DEBUG("bc1fany2 " TARGET_FMT_lx, btarget);
4285 gen_op_bc1tany2(cc);
4286 MIPS_DEBUG("bc1tany2 " TARGET_FMT_lx, btarget);
4289 gen_op_bc1fany4(cc);
4290 MIPS_DEBUG("bc1fany4 " TARGET_FMT_lx, btarget);
4293 gen_op_bc1tany4(cc);
4294 MIPS_DEBUG("bc1tany4 " TARGET_FMT_lx, btarget);
4296 ctx->hflags |= MIPS_HFLAG_BC;
4300 MIPS_INVAL("cp1 branch");
4301 generate_exception (ctx, EXCP_RI);
4305 MIPS_DEBUG("enter ds: cond %02x target " TARGET_FMT_lx,
4306 ctx->hflags, btarget);
4307 ctx->btarget = btarget;
4312 /* Coprocessor 1 (FPU) */
4314 /* verify if floating point register is valid; an operation is not defined
4315 * if bit 0 of any register specification is set and the FR bit in the
4316 * Status register equals zero, since the register numbers specify an
4317 * even-odd pair of adjacent coprocessor general registers. When the FR bit
4318 * in the Status register equals one, both even and odd register numbers
4319 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
4321 * Multiple 64 bit wide registers can be checked by calling
4322 * CHECK_FR(ctx, freg1 | freg2 | ... | fregN);
4324 * FIXME: This is broken for R2, it needs to be checked at runtime, not
4325 * at translation time.
4327 #define CHECK_FR(ctx, freg) do { \
4328 if (!((ctx)->CP0_Status & (1 << CP0St_FR)) && ((freg) & 1)) { \
4329 generate_exception (ctx, EXCP_RI); \
4334 #define FOP(func, fmt) (((fmt) << 21) | (func))
4336 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
4338 const char *opn = "unk";
4342 GEN_LOAD_FREG_FTN(WT0, fs);
4344 GEN_STORE_TN_REG(rt, T0);
4348 GEN_LOAD_REG_TN(T0, rt);
4350 GEN_STORE_FTN_FREG(fs, WT0);
4354 GEN_LOAD_IMM_TN(T1, fs);
4356 GEN_STORE_TN_REG(rt, T0);
4360 GEN_LOAD_IMM_TN(T1, fs);
4361 GEN_LOAD_REG_TN(T0, rt);
4366 GEN_LOAD_FREG_FTN(DT0, fs);
4368 GEN_STORE_TN_REG(rt, T0);
4372 GEN_LOAD_REG_TN(T0, rt);
4374 GEN_STORE_FTN_FREG(fs, DT0);
4379 GEN_LOAD_FREG_FTN(WTH0, fs);
4381 GEN_STORE_TN_REG(rt, T0);
4386 GEN_LOAD_REG_TN(T0, rt);
4388 GEN_STORE_FTN_FREG(fs, WTH0);
4392 if (loglevel & CPU_LOG_TB_IN_ASM) {
4393 fprintf(logfile, "Invalid CP1 opcode: %08x %03x %03x %03x\n",
4394 ctx->opcode, ctx->opcode >> 26, ctx->opcode & 0x3F,
4395 ((ctx->opcode >> 16) & 0x1F));
4397 generate_exception (ctx, EXCP_RI);
4400 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
4403 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
4407 GEN_LOAD_REG_TN(T0, rd);
4408 GEN_LOAD_REG_TN(T1, rs);
4410 ccbit = 1 << (24 + cc);
4417 GEN_STORE_TN_REG(rd, T0);
4420 #define GEN_MOVCF(fmt) \
4421 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
4426 ccbit = 1 << (24 + cc); \
4430 glue(gen_op_float_movf_, fmt)(ccbit); \
4432 glue(gen_op_float_movt_, fmt)(ccbit); \
4439 static void gen_farith (DisasContext *ctx, uint32_t op1, int ft,
4440 int fs, int fd, int cc)
4442 const char *opn = "unk";
4443 const char *condnames[] = {
4462 uint32_t func = ctx->opcode & 0x3f;
4464 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
4466 GEN_LOAD_FREG_FTN(WT0, fs);
4467 GEN_LOAD_FREG_FTN(WT1, ft);
4468 gen_op_float_add_s();
4469 GEN_STORE_FTN_FREG(fd, WT2);
4474 GEN_LOAD_FREG_FTN(WT0, fs);
4475 GEN_LOAD_FREG_FTN(WT1, ft);
4476 gen_op_float_sub_s();
4477 GEN_STORE_FTN_FREG(fd, WT2);
4482 GEN_LOAD_FREG_FTN(WT0, fs);
4483 GEN_LOAD_FREG_FTN(WT1, ft);
4484 gen_op_float_mul_s();
4485 GEN_STORE_FTN_FREG(fd, WT2);
4490 GEN_LOAD_FREG_FTN(WT0, fs);
4491 GEN_LOAD_FREG_FTN(WT1, ft);
4492 gen_op_float_div_s();
4493 GEN_STORE_FTN_FREG(fd, WT2);
4498 GEN_LOAD_FREG_FTN(WT0, fs);
4499 gen_op_float_sqrt_s();
4500 GEN_STORE_FTN_FREG(fd, WT2);
4504 GEN_LOAD_FREG_FTN(WT0, fs);
4505 gen_op_float_abs_s();
4506 GEN_STORE_FTN_FREG(fd, WT2);
4510 GEN_LOAD_FREG_FTN(WT0, fs);
4511 gen_op_float_mov_s();
4512 GEN_STORE_FTN_FREG(fd, WT2);
4516 GEN_LOAD_FREG_FTN(WT0, fs);
4517 gen_op_float_chs_s();
4518 GEN_STORE_FTN_FREG(fd, WT2);
4523 GEN_LOAD_FREG_FTN(WT0, fs);
4524 gen_op_float_roundl_s();
4525 GEN_STORE_FTN_FREG(fd, DT2);
4530 GEN_LOAD_FREG_FTN(WT0, fs);
4531 gen_op_float_truncl_s();
4532 GEN_STORE_FTN_FREG(fd, DT2);
4537 GEN_LOAD_FREG_FTN(WT0, fs);
4538 gen_op_float_ceill_s();
4539 GEN_STORE_FTN_FREG(fd, DT2);
4544 GEN_LOAD_FREG_FTN(WT0, fs);
4545 gen_op_float_floorl_s();
4546 GEN_STORE_FTN_FREG(fd, DT2);
4550 GEN_LOAD_FREG_FTN(WT0, fs);
4551 gen_op_float_roundw_s();
4552 GEN_STORE_FTN_FREG(fd, WT2);
4556 GEN_LOAD_FREG_FTN(WT0, fs);
4557 gen_op_float_truncw_s();
4558 GEN_STORE_FTN_FREG(fd, WT2);
4562 GEN_LOAD_FREG_FTN(WT0, fs);
4563 gen_op_float_ceilw_s();
4564 GEN_STORE_FTN_FREG(fd, WT2);
4568 GEN_LOAD_FREG_FTN(WT0, fs);
4569 gen_op_float_floorw_s();
4570 GEN_STORE_FTN_FREG(fd, WT2);
4574 GEN_LOAD_REG_TN(T0, ft);
4575 GEN_LOAD_FREG_FTN(WT0, fs);
4576 GEN_LOAD_FREG_FTN(WT2, fd);
4577 gen_movcf_s(ctx, (ft >> 2) & 0x7, ft & 0x1);
4578 GEN_STORE_FTN_FREG(fd, WT2);
4582 GEN_LOAD_REG_TN(T0, ft);
4583 GEN_LOAD_FREG_FTN(WT0, fs);
4584 GEN_LOAD_FREG_FTN(WT2, fd);
4585 gen_op_float_movz_s();
4586 GEN_STORE_FTN_FREG(fd, WT2);
4590 GEN_LOAD_REG_TN(T0, ft);
4591 GEN_LOAD_FREG_FTN(WT0, fs);
4592 GEN_LOAD_FREG_FTN(WT2, fd);
4593 gen_op_float_movn_s();
4594 GEN_STORE_FTN_FREG(fd, WT2);
4599 GEN_LOAD_FREG_FTN(WT0, fs);
4600 gen_op_float_cvtd_s();
4601 GEN_STORE_FTN_FREG(fd, DT2);
4605 GEN_LOAD_FREG_FTN(WT0, fs);
4606 gen_op_float_cvtw_s();
4607 GEN_STORE_FTN_FREG(fd, WT2);
4611 CHECK_FR(ctx, fs | fd);
4612 GEN_LOAD_FREG_FTN(WT0, fs);
4613 gen_op_float_cvtl_s();
4614 GEN_STORE_FTN_FREG(fd, DT2);
4618 CHECK_FR(ctx, fs | ft | fd);
4619 GEN_LOAD_FREG_FTN(WT1, fs);
4620 GEN_LOAD_FREG_FTN(WT0, ft);
4621 gen_op_float_cvtps_s();
4622 GEN_STORE_FTN_FREG(fd, DT2);
4641 GEN_LOAD_FREG_FTN(WT0, fs);
4642 GEN_LOAD_FREG_FTN(WT1, ft);
4643 gen_cmp_s(func-48, cc);
4644 opn = condnames[func-48];
4647 CHECK_FR(ctx, fs | ft | fd);
4648 GEN_LOAD_FREG_FTN(DT0, fs);
4649 GEN_LOAD_FREG_FTN(DT1, ft);
4650 gen_op_float_add_d();
4651 GEN_STORE_FTN_FREG(fd, DT2);
4656 CHECK_FR(ctx, fs | ft | fd);
4657 GEN_LOAD_FREG_FTN(DT0, fs);
4658 GEN_LOAD_FREG_FTN(DT1, ft);
4659 gen_op_float_sub_d();
4660 GEN_STORE_FTN_FREG(fd, DT2);
4665 CHECK_FR(ctx, fs | ft | fd);
4666 GEN_LOAD_FREG_FTN(DT0, fs);
4667 GEN_LOAD_FREG_FTN(DT1, ft);
4668 gen_op_float_mul_d();
4669 GEN_STORE_FTN_FREG(fd, DT2);
4674 CHECK_FR(ctx, fs | ft | fd);
4675 GEN_LOAD_FREG_FTN(DT0, fs);
4676 GEN_LOAD_FREG_FTN(DT1, ft);
4677 gen_op_float_div_d();
4678 GEN_STORE_FTN_FREG(fd, DT2);
4683 CHECK_FR(ctx, fs | fd);
4684 GEN_LOAD_FREG_FTN(DT0, fs);
4685 gen_op_float_sqrt_d();
4686 GEN_STORE_FTN_FREG(fd, DT2);
4690 CHECK_FR(ctx, fs | fd);
4691 GEN_LOAD_FREG_FTN(DT0, fs);
4692 gen_op_float_abs_d();
4693 GEN_STORE_FTN_FREG(fd, DT2);
4697 CHECK_FR(ctx, fs | fd);
4698 GEN_LOAD_FREG_FTN(DT0, fs);
4699 gen_op_float_mov_d();
4700 GEN_STORE_FTN_FREG(fd, DT2);
4704 CHECK_FR(ctx, fs | fd);
4705 GEN_LOAD_FREG_FTN(DT0, fs);
4706 gen_op_float_chs_d();
4707 GEN_STORE_FTN_FREG(fd, DT2);
4712 GEN_LOAD_FREG_FTN(DT0, fs);
4713 gen_op_float_roundl_d();
4714 GEN_STORE_FTN_FREG(fd, DT2);
4719 GEN_LOAD_FREG_FTN(DT0, fs);
4720 gen_op_float_truncl_d();
4721 GEN_STORE_FTN_FREG(fd, DT2);
4726 GEN_LOAD_FREG_FTN(DT0, fs);
4727 gen_op_float_ceill_d();
4728 GEN_STORE_FTN_FREG(fd, DT2);
4733 GEN_LOAD_FREG_FTN(DT0, fs);
4734 gen_op_float_floorl_d();
4735 GEN_STORE_FTN_FREG(fd, DT2);
4740 GEN_LOAD_FREG_FTN(DT0, fs);
4741 gen_op_float_roundw_d();
4742 GEN_STORE_FTN_FREG(fd, WT2);
4747 GEN_LOAD_FREG_FTN(DT0, fs);
4748 gen_op_float_truncw_d();
4749 GEN_STORE_FTN_FREG(fd, WT2);
4754 GEN_LOAD_FREG_FTN(DT0, fs);
4755 gen_op_float_ceilw_d();
4756 GEN_STORE_FTN_FREG(fd, WT2);
4761 GEN_LOAD_FREG_FTN(DT0, fs);
4762 gen_op_float_floorw_d();
4763 GEN_STORE_FTN_FREG(fd, WT2);
4767 GEN_LOAD_REG_TN(T0, ft);
4768 GEN_LOAD_FREG_FTN(DT0, fs);
4769 GEN_LOAD_FREG_FTN(DT2, fd);
4770 gen_movcf_d(ctx, (ft >> 2) & 0x7, ft & 0x1);
4771 GEN_STORE_FTN_FREG(fd, DT2);
4775 GEN_LOAD_REG_TN(T0, ft);
4776 GEN_LOAD_FREG_FTN(DT0, fs);
4777 GEN_LOAD_FREG_FTN(DT2, fd);
4778 gen_op_float_movz_d();
4779 GEN_STORE_FTN_FREG(fd, DT2);
4783 GEN_LOAD_REG_TN(T0, ft);
4784 GEN_LOAD_FREG_FTN(DT0, fs);
4785 GEN_LOAD_FREG_FTN(DT2, fd);
4786 gen_op_float_movn_d();
4787 GEN_STORE_FTN_FREG(fd, DT2);
4806 CHECK_FR(ctx, fs | ft);
4807 GEN_LOAD_FREG_FTN(DT0, fs);
4808 GEN_LOAD_FREG_FTN(DT1, ft);
4809 gen_cmp_d(func-48, cc);
4810 opn = condnames[func-48];
4814 GEN_LOAD_FREG_FTN(DT0, fs);
4815 gen_op_float_cvts_d();
4816 GEN_STORE_FTN_FREG(fd, WT2);
4821 GEN_LOAD_FREG_FTN(DT0, fs);
4822 gen_op_float_cvtw_d();
4823 GEN_STORE_FTN_FREG(fd, WT2);
4827 CHECK_FR(ctx, fs | fd);
4828 GEN_LOAD_FREG_FTN(DT0, fs);
4829 gen_op_float_cvtl_d();
4830 GEN_STORE_FTN_FREG(fd, DT2);
4834 GEN_LOAD_FREG_FTN(WT0, fs);
4835 gen_op_float_cvts_w();
4836 GEN_STORE_FTN_FREG(fd, WT2);
4841 GEN_LOAD_FREG_FTN(WT0, fs);
4842 gen_op_float_cvtd_w();
4843 GEN_STORE_FTN_FREG(fd, DT2);
4848 GEN_LOAD_FREG_FTN(DT0, fs);
4849 gen_op_float_cvts_l();
4850 GEN_STORE_FTN_FREG(fd, WT2);
4854 CHECK_FR(ctx, fs | fd);
4855 GEN_LOAD_FREG_FTN(DT0, fs);
4856 gen_op_float_cvtd_l();
4857 GEN_STORE_FTN_FREG(fd, DT2);
4862 CHECK_FR(ctx, fs | fd);
4863 GEN_LOAD_FREG_FTN(WT0, fs);
4864 GEN_LOAD_FREG_FTN(WTH0, fs);
4865 gen_op_float_cvtps_pw();
4866 GEN_STORE_FTN_FREG(fd, WT2);
4867 GEN_STORE_FTN_FREG(fd, WTH2);
4871 CHECK_FR(ctx, fs | ft | fd);
4872 GEN_LOAD_FREG_FTN(WT0, fs);
4873 GEN_LOAD_FREG_FTN(WTH0, fs);
4874 GEN_LOAD_FREG_FTN(WT1, ft);
4875 GEN_LOAD_FREG_FTN(WTH1, ft);
4876 gen_op_float_add_ps();
4877 GEN_STORE_FTN_FREG(fd, WT2);
4878 GEN_STORE_FTN_FREG(fd, WTH2);
4882 CHECK_FR(ctx, fs | ft | fd);
4883 GEN_LOAD_FREG_FTN(WT0, fs);
4884 GEN_LOAD_FREG_FTN(WTH0, fs);
4885 GEN_LOAD_FREG_FTN(WT1, ft);
4886 GEN_LOAD_FREG_FTN(WTH1, ft);
4887 gen_op_float_sub_ps();
4888 GEN_STORE_FTN_FREG(fd, WT2);
4889 GEN_STORE_FTN_FREG(fd, WTH2);
4893 CHECK_FR(ctx, fs | ft | fd);
4894 GEN_LOAD_FREG_FTN(WT0, fs);
4895 GEN_LOAD_FREG_FTN(WTH0, fs);
4896 GEN_LOAD_FREG_FTN(WT1, ft);
4897 GEN_LOAD_FREG_FTN(WTH1, ft);
4898 gen_op_float_mul_ps();
4899 GEN_STORE_FTN_FREG(fd, WT2);
4900 GEN_STORE_FTN_FREG(fd, WTH2);
4904 CHECK_FR(ctx, fs | fd);
4905 GEN_LOAD_FREG_FTN(WT0, fs);
4906 GEN_LOAD_FREG_FTN(WTH0, fs);
4907 gen_op_float_abs_ps();
4908 GEN_STORE_FTN_FREG(fd, WT2);
4909 GEN_STORE_FTN_FREG(fd, WTH2);
4913 CHECK_FR(ctx, fs | fd);
4914 GEN_LOAD_FREG_FTN(WT0, fs);
4915 GEN_LOAD_FREG_FTN(WTH0, fs);
4916 gen_op_float_mov_ps();
4917 GEN_STORE_FTN_FREG(fd, WT2);
4918 GEN_STORE_FTN_FREG(fd, WTH2);
4922 CHECK_FR(ctx, fs | fd);
4923 GEN_LOAD_FREG_FTN(WT0, fs);
4924 GEN_LOAD_FREG_FTN(WTH0, fs);
4925 gen_op_float_chs_ps();
4926 GEN_STORE_FTN_FREG(fd, WT2);
4927 GEN_STORE_FTN_FREG(fd, WTH2);
4931 GEN_LOAD_REG_TN(T0, ft);
4932 GEN_LOAD_FREG_FTN(WT0, fs);
4933 GEN_LOAD_FREG_FTN(WTH0, fs);
4934 GEN_LOAD_FREG_FTN(WT2, fd);
4935 GEN_LOAD_FREG_FTN(WTH2, fd);
4936 gen_movcf_ps(ctx, (ft >> 2) & 0x7, ft & 0x1);
4937 GEN_STORE_FTN_FREG(fd, WT2);
4938 GEN_STORE_FTN_FREG(fd, WTH2);
4942 GEN_LOAD_REG_TN(T0, ft);
4943 GEN_LOAD_FREG_FTN(WT0, fs);
4944 GEN_LOAD_FREG_FTN(WTH0, fs);
4945 GEN_LOAD_FREG_FTN(WT2, fd);
4946 GEN_LOAD_FREG_FTN(WTH2, fd);
4947 gen_op_float_movz_ps();
4948 GEN_STORE_FTN_FREG(fd, WT2);
4949 GEN_STORE_FTN_FREG(fd, WTH2);
4953 GEN_LOAD_REG_TN(T0, ft);
4954 GEN_LOAD_FREG_FTN(WT0, fs);
4955 GEN_LOAD_FREG_FTN(WTH0, fs);
4956 GEN_LOAD_FREG_FTN(WT2, fd);
4957 GEN_LOAD_FREG_FTN(WTH2, fd);
4958 gen_op_float_movn_ps();
4959 GEN_STORE_FTN_FREG(fd, WT2);
4960 GEN_STORE_FTN_FREG(fd, WTH2);
4965 GEN_LOAD_FREG_FTN(WTH0, fs);
4966 gen_op_float_cvts_pu();
4967 GEN_STORE_FTN_FREG(fd, WT2);
4971 CHECK_FR(ctx, fs | fd);
4972 GEN_LOAD_FREG_FTN(WT0, fs);
4973 GEN_LOAD_FREG_FTN(WTH0, fs);
4974 gen_op_float_cvtpw_ps();
4975 GEN_STORE_FTN_FREG(fd, WT2);
4976 GEN_STORE_FTN_FREG(fd, WTH2);
4981 GEN_LOAD_FREG_FTN(WT0, fs);
4982 gen_op_float_cvts_pl();
4983 GEN_STORE_FTN_FREG(fd, WT2);
4987 CHECK_FR(ctx, fs | ft | fd);
4988 GEN_LOAD_FREG_FTN(WT0, fs);
4989 GEN_LOAD_FREG_FTN(WT1, ft);
4990 gen_op_float_pll_ps();
4991 GEN_STORE_FTN_FREG(fd, DT2);
4995 CHECK_FR(ctx, fs | ft | fd);
4996 GEN_LOAD_FREG_FTN(WT0, fs);
4997 GEN_LOAD_FREG_FTN(WTH1, ft);
4998 gen_op_float_plu_ps();
4999 GEN_STORE_FTN_FREG(fd, DT2);
5003 CHECK_FR(ctx, fs | ft | fd);
5004 GEN_LOAD_FREG_FTN(WTH0, fs);
5005 GEN_LOAD_FREG_FTN(WT1, ft);
5006 gen_op_float_pul_ps();
5007 GEN_STORE_FTN_FREG(fd, DT2);
5011 CHECK_FR(ctx, fs | ft | fd);
5012 GEN_LOAD_FREG_FTN(WTH0, fs);
5013 GEN_LOAD_FREG_FTN(WTH1, ft);
5014 gen_op_float_puu_ps();
5015 GEN_STORE_FTN_FREG(fd, DT2);
5034 CHECK_FR(ctx, fs | ft);
5035 GEN_LOAD_FREG_FTN(WT0, fs);
5036 GEN_LOAD_FREG_FTN(WTH0, fs);
5037 GEN_LOAD_FREG_FTN(WT1, ft);
5038 GEN_LOAD_FREG_FTN(WTH1, ft);
5039 gen_cmp_ps(func-48, cc);
5040 opn = condnames[func-48];
5043 if (loglevel & CPU_LOG_TB_IN_ASM) {
5044 fprintf(logfile, "Invalid FP arith function: %08x %03x %03x %03x\n",
5045 ctx->opcode, ctx->opcode >> 26, ctx->opcode & 0x3F,
5046 ((ctx->opcode >> 16) & 0x1F));
5048 generate_exception (ctx, EXCP_RI);
5052 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
5054 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
5057 /* Coprocessor 3 (FPU) */
5058 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc, int fd,
5059 int base, int index)
5061 const char *opn = "unk";
5063 GEN_LOAD_REG_TN(T0, base);
5064 GEN_LOAD_REG_TN(T1, index);
5065 /* Don't do NOP if destination is zero: we must perform the actual
5071 GEN_STORE_FTN_FREG(fd, WT0);
5076 GEN_STORE_FTN_FREG(fd, DT0);
5081 GEN_STORE_FTN_FREG(fd, DT0);
5085 GEN_LOAD_FREG_FTN(WT0, fd);
5090 GEN_LOAD_FREG_FTN(DT0, fd);
5095 GEN_LOAD_FREG_FTN(DT0, fd);
5100 MIPS_INVAL("extended float load/store");
5101 generate_exception(ctx, EXCP_RI);
5104 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[fd],regnames[index], regnames[base]);
5107 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc, int fd,
5108 int fr, int fs, int ft)
5110 const char *opn = "unk";
5112 /* All of those work only on 64bit FPUs. */
5113 CHECK_FR(ctx, fd | fr | fs | ft);
5116 GEN_LOAD_REG_TN(T0, fr);
5117 GEN_LOAD_FREG_FTN(DT0, fs);
5118 GEN_LOAD_FREG_FTN(DT1, ft);
5119 gen_op_float_alnv_ps();
5120 GEN_STORE_FTN_FREG(fd, DT2);
5124 GEN_LOAD_FREG_FTN(WT0, fs);
5125 GEN_LOAD_FREG_FTN(WT1, ft);
5126 GEN_LOAD_FREG_FTN(WT2, fr);
5127 gen_op_float_muladd_s();
5128 GEN_STORE_FTN_FREG(fd, WT2);
5132 generate_exception (ctx, EXCP_RI);
5136 generate_exception (ctx, EXCP_RI);
5140 generate_exception (ctx, EXCP_RI);
5144 generate_exception (ctx, EXCP_RI);
5148 generate_exception (ctx, EXCP_RI);
5152 generate_exception (ctx, EXCP_RI);
5156 generate_exception (ctx, EXCP_RI);
5160 generate_exception (ctx, EXCP_RI);
5164 generate_exception (ctx, EXCP_RI);
5168 generate_exception (ctx, EXCP_RI);
5172 generate_exception (ctx, EXCP_RI);
5176 if (loglevel & CPU_LOG_TB_IN_ASM) {
5177 fprintf(logfile, "Invalid extended FP arith function: %08x %03x %03x\n",
5178 ctx->opcode, ctx->opcode >> 26, ctx->opcode & 0x3F);
5180 generate_exception (ctx, EXCP_RI);
5183 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
5184 fregnames[fs], fregnames[ft]);
5187 /* ISA extensions (ASEs) */
5188 /* MIPS16 extension to MIPS32 */
5189 /* SmartMIPS extension to MIPS32 */
5191 #ifdef TARGET_MIPS64
5193 /* MDMX extension to MIPS64 */
5194 /* MIPS-3D extension to MIPS64 */
5198 static void decode_opc (CPUState *env, DisasContext *ctx)
5202 uint32_t op, op1, op2;
5205 /* make sure instructions are on a word boundary */
5206 if (ctx->pc & 0x3) {
5207 env->CP0_BadVAddr = ctx->pc;
5208 generate_exception(ctx, EXCP_AdEL);
5212 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
5214 /* Handle blikely not taken case */
5215 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
5216 l1 = gen_new_label();
5218 gen_op_save_state(ctx->hflags & ~MIPS_HFLAG_BMASK);
5219 gen_goto_tb(ctx, 1, ctx->pc + 4);
5222 op = MASK_OP_MAJOR(ctx->opcode);
5223 rs = (ctx->opcode >> 21) & 0x1f;
5224 rt = (ctx->opcode >> 16) & 0x1f;
5225 rd = (ctx->opcode >> 11) & 0x1f;
5226 sa = (ctx->opcode >> 6) & 0x1f;
5227 imm = (int16_t)ctx->opcode;
5230 op1 = MASK_SPECIAL(ctx->opcode);
5232 case OPC_SLL: /* Arithmetic with immediate */
5233 case OPC_SRL ... OPC_SRA:
5234 gen_arith_imm(ctx, op1, rd, rt, sa);
5236 case OPC_SLLV: /* Arithmetic */
5237 case OPC_SRLV ... OPC_SRAV:
5238 case OPC_MOVZ ... OPC_MOVN:
5239 case OPC_ADD ... OPC_NOR:
5240 case OPC_SLT ... OPC_SLTU:
5241 gen_arith(ctx, op1, rd, rs, rt);
5243 case OPC_MULT ... OPC_DIVU:
5244 gen_muldiv(ctx, op1, rs, rt);
5246 case OPC_JR ... OPC_JALR:
5247 gen_compute_branch(ctx, op1, rs, rd, sa);
5249 case OPC_TGE ... OPC_TEQ: /* Traps */
5251 gen_trap(ctx, op1, rs, rt, -1);
5253 case OPC_MFHI: /* Move from HI/LO */
5255 gen_HILO(ctx, op1, rd);
5258 case OPC_MTLO: /* Move to HI/LO */
5259 gen_HILO(ctx, op1, rs);
5261 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
5262 #ifdef MIPS_STRICT_STANDARD
5263 MIPS_INVAL("PMON / selsl");
5264 generate_exception(ctx, EXCP_RI);
5270 generate_exception(ctx, EXCP_SYSCALL);
5273 generate_exception(ctx, EXCP_BREAK);
5276 #ifdef MIPS_STRICT_STANDARD
5278 generate_exception(ctx, EXCP_RI);
5280 /* Implemented as RI exception for now. */
5281 MIPS_INVAL("spim (unofficial)");
5282 generate_exception(ctx, EXCP_RI);
5286 /* Treat as a noop. */
5290 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5291 save_cpu_state(ctx, 1);
5292 gen_op_cp1_enabled();
5293 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
5294 (ctx->opcode >> 16) & 1);
5296 generate_exception_err(ctx, EXCP_CpU, 1);
5300 #ifdef TARGET_MIPS64
5301 /* MIPS64 specific opcodes */
5303 case OPC_DSRL ... OPC_DSRA:
5305 case OPC_DSRL32 ... OPC_DSRA32:
5306 gen_arith_imm(ctx, op1, rd, rt, sa);
5309 case OPC_DSRLV ... OPC_DSRAV:
5310 case OPC_DADD ... OPC_DSUBU:
5311 gen_arith(ctx, op1, rd, rs, rt);
5313 case OPC_DMULT ... OPC_DDIVU:
5314 gen_muldiv(ctx, op1, rs, rt);
5317 default: /* Invalid */
5318 MIPS_INVAL("special");
5319 generate_exception(ctx, EXCP_RI);
5324 op1 = MASK_SPECIAL2(ctx->opcode);
5326 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
5327 case OPC_MSUB ... OPC_MSUBU:
5328 gen_muldiv(ctx, op1, rs, rt);
5331 gen_arith(ctx, op1, rd, rs, rt);
5333 case OPC_CLZ ... OPC_CLO:
5334 gen_cl(ctx, op1, rd, rs);
5337 /* XXX: not clear which exception should be raised
5338 * when in debug mode...
5340 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5341 generate_exception(ctx, EXCP_DBp);
5343 generate_exception(ctx, EXCP_DBp);
5345 /* Treat as a noop */
5347 #ifdef TARGET_MIPS64
5348 case OPC_DCLZ ... OPC_DCLO:
5349 gen_cl(ctx, op1, rd, rs);
5352 default: /* Invalid */
5353 MIPS_INVAL("special2");
5354 generate_exception(ctx, EXCP_RI);
5359 op1 = MASK_SPECIAL3(ctx->opcode);
5363 gen_bitops(ctx, op1, rt, rs, sa, rd);
5366 op2 = MASK_BSHFL(ctx->opcode);
5369 GEN_LOAD_REG_TN(T1, rt);
5373 GEN_LOAD_REG_TN(T1, rt);
5377 GEN_LOAD_REG_TN(T1, rt);
5380 default: /* Invalid */
5381 MIPS_INVAL("bshfl");
5382 generate_exception(ctx, EXCP_RI);
5385 GEN_STORE_TN_REG(rd, T0);
5390 save_cpu_state(ctx, 1);
5391 gen_op_rdhwr_cpunum();
5394 save_cpu_state(ctx, 1);
5395 gen_op_rdhwr_synci_step();
5398 save_cpu_state(ctx, 1);
5402 save_cpu_state(ctx, 1);
5403 gen_op_rdhwr_ccres();
5406 #if defined (CONFIG_USER_ONLY)
5407 gen_op_tls_value ();
5410 default: /* Invalid */
5411 MIPS_INVAL("rdhwr");
5412 generate_exception(ctx, EXCP_RI);
5415 GEN_STORE_TN_REG(rt, T0);
5417 #ifdef TARGET_MIPS64
5418 case OPC_DEXTM ... OPC_DEXT:
5419 case OPC_DINSM ... OPC_DINS:
5420 gen_bitops(ctx, op1, rt, rs, sa, rd);
5423 op2 = MASK_DBSHFL(ctx->opcode);
5426 GEN_LOAD_REG_TN(T1, rt);
5430 GEN_LOAD_REG_TN(T1, rt);
5433 default: /* Invalid */
5434 MIPS_INVAL("dbshfl");
5435 generate_exception(ctx, EXCP_RI);
5438 GEN_STORE_TN_REG(rd, T0);
5440 default: /* Invalid */
5441 MIPS_INVAL("special3");
5442 generate_exception(ctx, EXCP_RI);
5447 op1 = MASK_REGIMM(ctx->opcode);
5449 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
5450 case OPC_BLTZAL ... OPC_BGEZALL:
5451 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
5453 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
5455 gen_trap(ctx, op1, rs, -1, imm);
5460 default: /* Invalid */
5461 MIPS_INVAL("REGIMM");
5462 generate_exception(ctx, EXCP_RI);
5467 save_cpu_state(ctx, 1);
5468 gen_op_cp0_enabled();
5469 op1 = MASK_CP0(ctx->opcode);
5473 #ifdef TARGET_MIPS64
5477 gen_cp0(ctx, op1, rt, rd);
5479 case OPC_C0_FIRST ... OPC_C0_LAST:
5480 gen_cp0(ctx, MASK_C0(ctx->opcode), rt, rd);
5483 op2 = MASK_MFMC0(ctx->opcode);
5487 /* Stop translation as we may have switched the execution mode */
5488 ctx->bstate = BS_STOP;
5492 /* Stop translation as we may have switched the execution mode */
5493 ctx->bstate = BS_STOP;
5495 default: /* Invalid */
5496 MIPS_INVAL("MFMC0");
5497 generate_exception(ctx, EXCP_RI);
5500 GEN_STORE_TN_REG(rt, T0);
5504 if ((env->CP0_Config0 & (0x7 << CP0C0_AR)) == (1 << CP0C0_AR)) {
5505 /* Shadow registers not implemented. */
5506 GEN_LOAD_REG_TN(T0, rt);
5507 GEN_STORE_TN_REG(rd, T0);
5509 generate_exception(ctx, EXCP_RI);
5512 generate_exception(ctx, EXCP_RI);
5516 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
5517 gen_arith_imm(ctx, op, rt, rs, imm);
5519 case OPC_J ... OPC_JAL: /* Jump */
5520 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
5521 gen_compute_branch(ctx, op, rs, rt, offset);
5523 case OPC_BEQ ... OPC_BGTZ: /* Branch */
5524 case OPC_BEQL ... OPC_BGTZL:
5525 gen_compute_branch(ctx, op, rs, rt, imm << 2);
5527 case OPC_LB ... OPC_LWR: /* Load and stores */
5528 case OPC_SB ... OPC_SW:
5532 gen_ldst(ctx, op, rt, rs, imm);
5535 /* Treat as a noop */
5538 /* Treat as a noop */
5541 /* Floating point. */
5546 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5547 save_cpu_state(ctx, 1);
5548 gen_op_cp1_enabled();
5549 gen_flt_ldst(ctx, op, rt, rs, imm);
5551 generate_exception_err(ctx, EXCP_CpU, 1);
5556 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5557 save_cpu_state(ctx, 1);
5558 gen_op_cp1_enabled();
5559 op1 = MASK_CP1(ctx->opcode);
5565 #ifdef TARGET_MIPS64
5571 gen_cp1(ctx, op1, rt, rd);
5574 gen_compute_branch1(ctx, MASK_BC1(ctx->opcode),
5575 (rt >> 2) & 0x7, imm << 2);
5582 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
5586 generate_exception (ctx, EXCP_RI);
5590 generate_exception_err(ctx, EXCP_CpU, 1);
5600 /* COP2: Not implemented. */
5601 generate_exception_err(ctx, EXCP_CpU, 2);
5605 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
5606 save_cpu_state(ctx, 1);
5607 gen_op_cp1_enabled();
5608 op1 = MASK_CP3(ctx->opcode);
5616 gen_flt3_ldst(ctx, op1, sa, rs, rt);
5634 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
5637 generate_exception (ctx, EXCP_RI);
5641 generate_exception_err(ctx, EXCP_CpU, 1);
5645 #ifdef TARGET_MIPS64
5646 /* MIPS64 opcodes */
5648 case OPC_LDL ... OPC_LDR:
5649 case OPC_SDL ... OPC_SDR:
5654 gen_ldst(ctx, op, rt, rs, imm);
5656 case OPC_DADDI ... OPC_DADDIU:
5657 gen_arith_imm(ctx, op, rt, rs, imm);
5660 #ifdef MIPS_HAS_MIPS16
5662 /* MIPS16: Not implemented. */
5664 #ifdef MIPS_HAS_MDMX
5666 /* MDMX: Not implemented. */
5668 default: /* Invalid */
5670 generate_exception(ctx, EXCP_RI);
5673 if (ctx->hflags & MIPS_HFLAG_BMASK) {
5674 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
5675 /* Branches completion */
5676 ctx->hflags &= ~MIPS_HFLAG_BMASK;
5677 ctx->bstate = BS_BRANCH;
5678 save_cpu_state(ctx, 0);
5681 /* unconditional branch */
5682 MIPS_DEBUG("unconditional branch");
5683 gen_goto_tb(ctx, 0, ctx->btarget);
5686 /* blikely taken case */
5687 MIPS_DEBUG("blikely branch taken");
5688 gen_goto_tb(ctx, 0, ctx->btarget);
5691 /* Conditional branch */
5692 MIPS_DEBUG("conditional branch");
5695 l1 = gen_new_label();
5697 gen_goto_tb(ctx, 1, ctx->pc + 4);
5699 gen_goto_tb(ctx, 0, ctx->btarget);
5703 /* unconditional branch to register */
5704 MIPS_DEBUG("branch to register");
5710 MIPS_DEBUG("unknown branch");
5717 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
5720 DisasContext ctx, *ctxp = &ctx;
5721 target_ulong pc_start;
5722 uint16_t *gen_opc_end;
5725 if (search_pc && loglevel)
5726 fprintf (logfile, "search pc %d\n", search_pc);
5729 gen_opc_ptr = gen_opc_buf;
5730 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
5731 gen_opparam_ptr = gen_opparam_buf;
5736 ctx.bstate = BS_NONE;
5737 /* Restore delay slot state from the tb context. */
5738 ctx.hflags = tb->flags;
5739 ctx.saved_hflags = ctx.hflags;
5740 switch (ctx.hflags & MIPS_HFLAG_BMASK) {
5742 gen_op_restore_breg_target();
5745 ctx.btarget = env->btarget;
5749 ctx.btarget = env->btarget;
5750 gen_op_restore_bcond();
5753 #if defined(CONFIG_USER_ONLY)
5756 ctx.mem_idx = !((ctx.hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM);
5758 ctx.CP0_Status = env->CP0_Status;
5760 if (loglevel & CPU_LOG_TB_CPU) {
5761 fprintf(logfile, "------------------------------------------------\n");
5762 /* FIXME: This may print out stale hflags from env... */
5763 cpu_dump_state(env, logfile, fprintf, 0);
5766 #if defined MIPS_DEBUG_DISAS
5767 if (loglevel & CPU_LOG_TB_IN_ASM)
5768 fprintf(logfile, "\ntb %p super %d cond %04x\n",
5769 tb, ctx.mem_idx, ctx.hflags);
5771 while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) {
5772 if (env->nb_breakpoints > 0) {
5773 for(j = 0; j < env->nb_breakpoints; j++) {
5774 if (env->breakpoints[j] == ctx.pc) {
5775 save_cpu_state(ctxp, 1);
5776 ctx.bstate = BS_BRANCH;
5778 goto done_generating;
5784 j = gen_opc_ptr - gen_opc_buf;
5788 gen_opc_instr_start[lj++] = 0;
5790 gen_opc_pc[lj] = ctx.pc;
5791 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
5792 gen_opc_instr_start[lj] = 1;
5794 ctx.opcode = ldl_code(ctx.pc);
5795 decode_opc(env, &ctx);
5798 if (env->singlestep_enabled)
5801 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
5804 #if defined (MIPS_SINGLE_STEP)
5808 if (env->singlestep_enabled) {
5809 save_cpu_state(ctxp, ctx.bstate == BS_NONE);
5812 switch (ctx.bstate) {
5814 gen_op_interrupt_restart();
5817 save_cpu_state(ctxp, 0);
5818 gen_goto_tb(&ctx, 0, ctx.pc);
5821 gen_op_interrupt_restart();
5831 *gen_opc_ptr = INDEX_op_end;
5833 j = gen_opc_ptr - gen_opc_buf;
5836 gen_opc_instr_start[lj++] = 0;
5839 tb->size = ctx.pc - pc_start;
5842 #if defined MIPS_DEBUG_DISAS
5843 if (loglevel & CPU_LOG_TB_IN_ASM)
5844 fprintf(logfile, "\n");
5846 if (loglevel & CPU_LOG_TB_IN_ASM) {
5847 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
5848 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
5849 fprintf(logfile, "\n");
5851 if (loglevel & CPU_LOG_TB_OP) {
5852 fprintf(logfile, "OP:\n");
5853 dump_ops(gen_opc_buf, gen_opparam_buf);
5854 fprintf(logfile, "\n");
5856 if (loglevel & CPU_LOG_TB_CPU) {
5857 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
5864 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
5866 return gen_intermediate_code_internal(env, tb, 0);
5869 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
5871 return gen_intermediate_code_internal(env, tb, 1);
5874 void fpu_dump_state(CPUState *env, FILE *f,
5875 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
5879 int is_fpu64 = !!(env->CP0_Status & (1 << CP0St_FR));
5881 #define printfpr(fp) \
5884 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
5885 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
5886 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
5889 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
5890 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
5891 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
5892 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
5893 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
5898 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
5899 env->fcr0, env->fcr31, is_fpu64, env->fp_status, get_float_exception_flags(&env->fp_status));
5900 fpu_fprintf(f, "FT0: "); printfpr(&env->ft0);
5901 fpu_fprintf(f, "FT1: "); printfpr(&env->ft1);
5902 fpu_fprintf(f, "FT2: "); printfpr(&env->ft2);
5903 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
5904 fpu_fprintf(f, "%3s: ", fregnames[i]);
5905 printfpr(&env->fpr[i]);
5911 void dump_fpu (CPUState *env)
5914 fprintf(logfile, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " %d\n",
5915 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
5916 fpu_dump_state(env, logfile, fprintf, 0);
5920 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
5921 /* Debug help: The architecture requires 32bit code to maintain proper
5922 sign-extened values on 64bit machines. */
5924 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
5926 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
5927 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5932 if (!SIGN_EXT_P(env->PC))
5933 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->PC);
5934 if (!SIGN_EXT_P(env->HI))
5935 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->HI);
5936 if (!SIGN_EXT_P(env->LO))
5937 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->LO);
5938 if (!SIGN_EXT_P(env->btarget))
5939 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
5941 for (i = 0; i < 32; i++) {
5942 if (!SIGN_EXT_P(env->gpr[i]))
5943 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->gpr[i]);
5946 if (!SIGN_EXT_P(env->CP0_EPC))
5947 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
5948 if (!SIGN_EXT_P(env->CP0_LLAddr))
5949 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
5953 void cpu_dump_state (CPUState *env, FILE *f,
5954 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5960 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",
5961 env->PC, env->HI, env->LO, env->hflags, env->btarget, env->bcond);
5962 for (i = 0; i < 32; i++) {
5964 cpu_fprintf(f, "GPR%02d:", i);
5965 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->gpr[i]);
5967 cpu_fprintf(f, "\n");
5970 c0_status = env->CP0_Status;
5972 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
5973 c0_status, env->CP0_Cause, env->CP0_EPC);
5974 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
5975 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
5976 if (c0_status & (1 << CP0St_CU1))
5977 fpu_dump_state(env, f, cpu_fprintf, flags);
5978 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
5979 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
5983 CPUMIPSState *cpu_mips_init (void)
5987 env = qemu_mallocz(sizeof(CPUMIPSState));
5995 void cpu_reset (CPUMIPSState *env)
5997 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
6002 #if !defined(CONFIG_USER_ONLY)
6003 if (env->hflags & MIPS_HFLAG_BMASK) {
6004 /* If the exception was raised from a delay slot,
6005 * come back to the jump. */
6006 env->CP0_ErrorEPC = env->PC - 4;
6007 env->hflags &= ~MIPS_HFLAG_BMASK;
6009 env->CP0_ErrorEPC = env->PC;
6012 env->PC = (int32_t)0xBFC00000;
6014 /* SMP not implemented */
6015 env->CP0_EBase = 0x80000000;
6016 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
6017 /* vectored interrupts not implemented, timer on int 7,
6018 no performance counters. */
6019 env->CP0_IntCtl = 0xe0000000;
6020 env->CP0_WatchLo = 0;
6021 env->CP0_WatchHi = 0;
6022 /* Count register increments in debug mode, EJTAG version 1 */
6023 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
6025 env->exception_index = EXCP_NONE;
6026 #if defined(CONFIG_USER_ONLY)
6027 env->hflags |= MIPS_HFLAG_UM;
6028 env->user_mode_only = 1;
6032 #include "translate_init.c"