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
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL = (0x00 << 26),
46 OPC_REGIMM = (0x01 << 26),
47 OPC_CP0 = (0x10 << 26),
48 OPC_CP1 = (0x11 << 26),
49 OPC_CP2 = (0x12 << 26),
50 OPC_CP3 = (0x13 << 26),
51 OPC_SPECIAL2 = (0x1C << 26),
52 OPC_SPECIAL3 = (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI = (0x08 << 26),
55 OPC_ADDIU = (0x09 << 26),
56 OPC_SLTI = (0x0A << 26),
57 OPC_SLTIU = (0x0B << 26),
58 OPC_ANDI = (0x0C << 26),
59 OPC_ORI = (0x0D << 26),
60 OPC_XORI = (0x0E << 26),
61 OPC_LUI = (0x0F << 26),
62 OPC_DADDI = (0x18 << 26),
63 OPC_DADDIU = (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL = (0x03 << 26),
67 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL = (0x14 << 26),
69 OPC_BNE = (0x05 << 26),
70 OPC_BNEL = (0x15 << 26),
71 OPC_BLEZ = (0x06 << 26),
72 OPC_BLEZL = (0x16 << 26),
73 OPC_BGTZ = (0x07 << 26),
74 OPC_BGTZL = (0x17 << 26),
75 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL = (0x1A << 26),
78 OPC_LDR = (0x1B << 26),
79 OPC_LB = (0x20 << 26),
80 OPC_LH = (0x21 << 26),
81 OPC_LWL = (0x22 << 26),
82 OPC_LW = (0x23 << 26),
83 OPC_LBU = (0x24 << 26),
84 OPC_LHU = (0x25 << 26),
85 OPC_LWR = (0x26 << 26),
86 OPC_LWU = (0x27 << 26),
87 OPC_SB = (0x28 << 26),
88 OPC_SH = (0x29 << 26),
89 OPC_SWL = (0x2A << 26),
90 OPC_SW = (0x2B << 26),
91 OPC_SDL = (0x2C << 26),
92 OPC_SDR = (0x2D << 26),
93 OPC_SWR = (0x2E << 26),
94 OPC_LL = (0x30 << 26),
95 OPC_LLD = (0x34 << 26),
96 OPC_LD = (0x37 << 26),
97 OPC_SC = (0x38 << 26),
98 OPC_SCD = (0x3C << 26),
99 OPC_SD = (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1 = (0x31 << 26),
102 OPC_LWC2 = (0x32 << 26),
103 OPC_LDC1 = (0x35 << 26),
104 OPC_LDC2 = (0x36 << 26),
105 OPC_SWC1 = (0x39 << 26),
106 OPC_SWC2 = (0x3A << 26),
107 OPC_SDC1 = (0x3D << 26),
108 OPC_SDC2 = (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX = (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE = (0x2F << 26),
113 OPC_PREF = (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED = (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL = 0x00 | OPC_SPECIAL,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
128 OPC_SRA = 0x03 | OPC_SPECIAL,
129 OPC_SLLV = 0x04 | OPC_SPECIAL,
130 OPC_SRLV = 0x06 | OPC_SPECIAL, /* also ROTRV */
131 OPC_SRAV = 0x07 | OPC_SPECIAL,
132 OPC_DSLLV = 0x14 | OPC_SPECIAL,
133 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
134 OPC_DSRAV = 0x17 | OPC_SPECIAL,
135 OPC_DSLL = 0x38 | OPC_SPECIAL,
136 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
137 OPC_DSRA = 0x3B | OPC_SPECIAL,
138 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
139 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
140 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
141 /* Multiplication / division */
142 OPC_MULT = 0x18 | OPC_SPECIAL,
143 OPC_MULTU = 0x19 | OPC_SPECIAL,
144 OPC_DIV = 0x1A | OPC_SPECIAL,
145 OPC_DIVU = 0x1B | OPC_SPECIAL,
146 OPC_DMULT = 0x1C | OPC_SPECIAL,
147 OPC_DMULTU = 0x1D | OPC_SPECIAL,
148 OPC_DDIV = 0x1E | OPC_SPECIAL,
149 OPC_DDIVU = 0x1F | OPC_SPECIAL,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD = 0x20 | OPC_SPECIAL,
152 OPC_ADDU = 0x21 | OPC_SPECIAL,
153 OPC_SUB = 0x22 | OPC_SPECIAL,
154 OPC_SUBU = 0x23 | OPC_SPECIAL,
155 OPC_AND = 0x24 | OPC_SPECIAL,
156 OPC_OR = 0x25 | OPC_SPECIAL,
157 OPC_XOR = 0x26 | OPC_SPECIAL,
158 OPC_NOR = 0x27 | OPC_SPECIAL,
159 OPC_SLT = 0x2A | OPC_SPECIAL,
160 OPC_SLTU = 0x2B | OPC_SPECIAL,
161 OPC_DADD = 0x2C | OPC_SPECIAL,
162 OPC_DADDU = 0x2D | OPC_SPECIAL,
163 OPC_DSUB = 0x2E | OPC_SPECIAL,
164 OPC_DSUBU = 0x2F | OPC_SPECIAL,
166 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
167 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
169 OPC_TGE = 0x30 | OPC_SPECIAL,
170 OPC_TGEU = 0x31 | OPC_SPECIAL,
171 OPC_TLT = 0x32 | OPC_SPECIAL,
172 OPC_TLTU = 0x33 | OPC_SPECIAL,
173 OPC_TEQ = 0x34 | OPC_SPECIAL,
174 OPC_TNE = 0x36 | OPC_SPECIAL,
175 /* HI / LO registers load & stores */
176 OPC_MFHI = 0x10 | OPC_SPECIAL,
177 OPC_MTHI = 0x11 | OPC_SPECIAL,
178 OPC_MFLO = 0x12 | OPC_SPECIAL,
179 OPC_MTLO = 0x13 | OPC_SPECIAL,
180 /* Conditional moves */
181 OPC_MOVZ = 0x0A | OPC_SPECIAL,
182 OPC_MOVN = 0x0B | OPC_SPECIAL,
184 OPC_MOVCI = 0x01 | OPC_SPECIAL,
187 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
188 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
189 OPC_BREAK = 0x0D | OPC_SPECIAL,
190 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
191 OPC_SYNC = 0x0F | OPC_SPECIAL,
193 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
194 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
195 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
196 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
197 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
198 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
199 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS = (0x03 << 6) | OPC_MULT,
207 OPC_VR54XX_MULSU = (0x03 << 6) | OPC_MULTU,
208 OPC_VR54XX_MACC = (0x05 << 6) | OPC_MULT,
209 OPC_VR54XX_MACCU = (0x05 << 6) | OPC_MULTU,
210 OPC_VR54XX_MSAC = (0x07 << 6) | OPC_MULT,
211 OPC_VR54XX_MSACU = (0x07 << 6) | OPC_MULTU,
212 OPC_VR54XX_MULHI = (0x09 << 6) | OPC_MULT,
213 OPC_VR54XX_MULHIU = (0x09 << 6) | OPC_MULTU,
214 OPC_VR54XX_MULSHI = (0x0B << 6) | OPC_MULT,
215 OPC_VR54XX_MULSHIU = (0x0B << 6) | OPC_MULTU,
216 OPC_VR54XX_MACCHI = (0x0D << 6) | OPC_MULT,
217 OPC_VR54XX_MACCHIU = (0x0D << 6) | OPC_MULTU,
218 OPC_VR54XX_MSACHI = (0x0F << 6) | OPC_MULT,
219 OPC_VR54XX_MSACHIU = (0x0F << 6) | OPC_MULTU,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
227 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
228 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
229 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
230 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
231 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
232 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
233 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
234 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
235 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
236 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
237 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
238 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
239 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
240 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD = 0x00 | OPC_SPECIAL2,
249 OPC_MADDU = 0x01 | OPC_SPECIAL2,
250 OPC_MUL = 0x02 | OPC_SPECIAL2,
251 OPC_MSUB = 0x04 | OPC_SPECIAL2,
252 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
254 OPC_CLZ = 0x20 | OPC_SPECIAL2,
255 OPC_CLO = 0x21 | OPC_SPECIAL2,
256 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
257 OPC_DCLO = 0x25 | OPC_SPECIAL2,
259 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT = 0x00 | OPC_SPECIAL3,
267 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
268 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
269 OPC_DEXT = 0x03 | OPC_SPECIAL3,
270 OPC_INS = 0x04 | OPC_SPECIAL3,
271 OPC_DINSM = 0x05 | OPC_SPECIAL3,
272 OPC_DINSU = 0x06 | OPC_SPECIAL3,
273 OPC_DINS = 0x07 | OPC_SPECIAL3,
274 OPC_FORK = 0x08 | OPC_SPECIAL3,
275 OPC_YIELD = 0x09 | OPC_SPECIAL3,
276 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
277 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
278 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
286 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
287 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
295 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
303 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
304 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
305 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
306 OPC_MFTR = (0x08 << 21) | OPC_CP0,
307 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
308 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
309 OPC_MTTR = (0x0C << 21) | OPC_CP0,
310 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
311 OPC_C0 = (0x10 << 21) | OPC_CP0,
312 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
313 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
321 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
322 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
323 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
324 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
325 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR = 0x01 | OPC_C0,
333 OPC_TLBWI = 0x02 | OPC_C0,
334 OPC_TLBWR = 0x06 | OPC_C0,
335 OPC_TLBP = 0x08 | OPC_C0,
336 OPC_RFE = 0x10 | OPC_C0,
337 OPC_ERET = 0x18 | OPC_C0,
338 OPC_DERET = 0x1F | OPC_C0,
339 OPC_WAIT = 0x20 | OPC_C0,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
347 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
348 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
349 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
350 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
351 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
352 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
353 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
354 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
355 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
356 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
357 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
358 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
359 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
360 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
361 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
362 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F = (0x00 << 16) | OPC_BC1,
371 OPC_BC1T = (0x01 << 16) | OPC_BC1,
372 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
373 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
377 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
378 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
382 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
383 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
390 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
391 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
392 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
393 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
394 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
395 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
396 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
397 OPC_BC2 = (0x08 << 21) | OPC_CP2,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1 = 0x00 | OPC_CP3,
404 OPC_LDXC1 = 0x01 | OPC_CP3,
405 OPC_LUXC1 = 0x05 | OPC_CP3,
406 OPC_SWXC1 = 0x08 | OPC_CP3,
407 OPC_SDXC1 = 0x09 | OPC_CP3,
408 OPC_SUXC1 = 0x0D | OPC_CP3,
409 OPC_PREFX = 0x0F | OPC_CP3,
410 OPC_ALNV_PS = 0x1E | OPC_CP3,
411 OPC_MADD_S = 0x20 | OPC_CP3,
412 OPC_MADD_D = 0x21 | OPC_CP3,
413 OPC_MADD_PS = 0x26 | OPC_CP3,
414 OPC_MSUB_S = 0x28 | OPC_CP3,
415 OPC_MSUB_D = 0x29 | OPC_CP3,
416 OPC_MSUB_PS = 0x2E | OPC_CP3,
417 OPC_NMADD_S = 0x30 | OPC_CP3,
418 OPC_NMADD_D = 0x31 | OPC_CP3,
419 OPC_NMADD_PS= 0x36 | OPC_CP3,
420 OPC_NMSUB_S = 0x38 | OPC_CP3,
421 OPC_NMSUB_D = 0x39 | OPC_CP3,
422 OPC_NMSUB_PS= 0x3E | OPC_CP3,
425 /* global register indices */
426 static TCGv cpu_env, current_tc_gprs, cpu_T[2];
428 /* The code generator doesn't like lots of temporaries, so maintain our own
429 cache for reuse within a function. */
431 static int num_temps;
432 static TCGv temps[MAX_TEMPS];
434 /* Allocate a temporary variable. */
435 static TCGv new_tmp(void)
438 if (num_temps == MAX_TEMPS)
441 if (GET_TCGV(temps[num_temps]))
442 return temps[num_temps++];
444 tmp = tcg_temp_new(TCG_TYPE_I32);
445 temps[num_temps++] = tmp;
449 /* Release a temporary variable. */
450 static void dead_tmp(TCGv tmp)
455 if (GET_TCGV(temps[i]) == GET_TCGV(tmp))
458 /* Shuffle this temp to the last slot. */
459 while (GET_TCGV(temps[i]) != GET_TCGV(tmp))
461 while (i < num_temps) {
462 temps[i] = temps[i + 1];
468 typedef struct DisasContext {
469 struct TranslationBlock *tb;
470 target_ulong pc, saved_pc;
473 /* Routine used to access memory */
475 uint32_t hflags, saved_hflags;
477 target_ulong btarget;
481 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
482 * exception condition
484 BS_STOP = 1, /* We want to stop translation for any reason */
485 BS_BRANCH = 2, /* We reached a branch condition */
486 BS_EXCP = 3, /* We reached an exception condition */
489 static const char *regnames[] =
490 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
491 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
492 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
493 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
495 static const char *fregnames[] =
496 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
497 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
498 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
499 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
501 #ifdef MIPS_DEBUG_DISAS
502 #define MIPS_DEBUG(fmt, args...) \
504 if (loglevel & CPU_LOG_TB_IN_ASM) { \
505 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
506 ctx->pc, ctx->opcode , ##args); \
510 #define MIPS_DEBUG(fmt, args...) do { } while(0)
513 #define MIPS_INVAL(op) \
515 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
516 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
519 /* General purpose registers moves. */
520 static inline void gen_load_gpr (TCGv t, int reg)
523 tcg_gen_movi_tl(t, 0);
525 tcg_gen_ld_tl(t, current_tc_gprs, sizeof(target_ulong) * reg);
528 static inline void gen_store_gpr (TCGv t, int reg)
531 tcg_gen_st_tl(t, current_tc_gprs, sizeof(target_ulong) * reg);
534 /* Moves to/from shadow registers. */
535 static inline void gen_load_srsgpr (TCGv t, int reg)
538 tcg_gen_movi_tl(t, 0);
540 TCGv r_tmp = new_tmp();
542 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl));
543 tcg_gen_shri_i32(r_tmp, r_tmp, CP0SRSCtl_PSS);
544 tcg_gen_andi_i32(r_tmp, r_tmp, 0xf);
545 tcg_gen_muli_i32(r_tmp, r_tmp, sizeof(target_ulong) * 32);
546 tcg_gen_add_i32(r_tmp, cpu_env, r_tmp);
548 tcg_gen_ld_tl(t, r_tmp, sizeof(target_ulong) * reg);
553 static inline void gen_store_srsgpr (TCGv t, int reg)
556 TCGv r_tmp = new_tmp();
558 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl));
559 tcg_gen_shri_i32(r_tmp, r_tmp, CP0SRSCtl_PSS);
560 tcg_gen_andi_i32(r_tmp, r_tmp, 0xf);
561 tcg_gen_muli_i32(r_tmp, r_tmp, sizeof(target_ulong) * 32);
562 tcg_gen_add_i32(r_tmp, cpu_env, r_tmp);
564 tcg_gen_st_tl(t, r_tmp, sizeof(target_ulong) * reg);
569 /* Floating point register moves. */
570 #define FGEN32(func, NAME) \
571 static GenOpFunc *NAME ## _table [32] = { \
572 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
573 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
574 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
575 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
576 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
577 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
578 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
579 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
581 static always_inline void func(int n) \
583 NAME ## _table[n](); \
586 FGEN32(gen_op_load_fpr_WT0, gen_op_load_fpr_WT0_fpr);
587 FGEN32(gen_op_store_fpr_WT0, gen_op_store_fpr_WT0_fpr);
589 FGEN32(gen_op_load_fpr_WT1, gen_op_load_fpr_WT1_fpr);
590 FGEN32(gen_op_store_fpr_WT1, gen_op_store_fpr_WT1_fpr);
592 FGEN32(gen_op_load_fpr_WT2, gen_op_load_fpr_WT2_fpr);
593 FGEN32(gen_op_store_fpr_WT2, gen_op_store_fpr_WT2_fpr);
595 FGEN32(gen_op_load_fpr_DT0, gen_op_load_fpr_DT0_fpr);
596 FGEN32(gen_op_store_fpr_DT0, gen_op_store_fpr_DT0_fpr);
598 FGEN32(gen_op_load_fpr_DT1, gen_op_load_fpr_DT1_fpr);
599 FGEN32(gen_op_store_fpr_DT1, gen_op_store_fpr_DT1_fpr);
601 FGEN32(gen_op_load_fpr_DT2, gen_op_load_fpr_DT2_fpr);
602 FGEN32(gen_op_store_fpr_DT2, gen_op_store_fpr_DT2_fpr);
604 FGEN32(gen_op_load_fpr_WTH0, gen_op_load_fpr_WTH0_fpr);
605 FGEN32(gen_op_store_fpr_WTH0, gen_op_store_fpr_WTH0_fpr);
607 FGEN32(gen_op_load_fpr_WTH1, gen_op_load_fpr_WTH1_fpr);
608 FGEN32(gen_op_store_fpr_WTH1, gen_op_store_fpr_WTH1_fpr);
610 FGEN32(gen_op_load_fpr_WTH2, gen_op_load_fpr_WTH2_fpr);
611 FGEN32(gen_op_store_fpr_WTH2, gen_op_store_fpr_WTH2_fpr);
613 #define GEN_LOAD_FREG_FTN(FTn, Fn) \
615 glue(gen_op_load_fpr_, FTn)(Fn); \
618 #define GEN_STORE_FTN_FREG(Fn, FTn) \
620 glue(gen_op_store_fpr_, FTn)(Fn); \
623 #define FOP_CONDS(type, fmt) \
624 static GenOpFunc1 * gen_op_cmp ## type ## _ ## fmt ## _table[16] = { \
625 gen_op_cmp ## type ## _ ## fmt ## _f, \
626 gen_op_cmp ## type ## _ ## fmt ## _un, \
627 gen_op_cmp ## type ## _ ## fmt ## _eq, \
628 gen_op_cmp ## type ## _ ## fmt ## _ueq, \
629 gen_op_cmp ## type ## _ ## fmt ## _olt, \
630 gen_op_cmp ## type ## _ ## fmt ## _ult, \
631 gen_op_cmp ## type ## _ ## fmt ## _ole, \
632 gen_op_cmp ## type ## _ ## fmt ## _ule, \
633 gen_op_cmp ## type ## _ ## fmt ## _sf, \
634 gen_op_cmp ## type ## _ ## fmt ## _ngle, \
635 gen_op_cmp ## type ## _ ## fmt ## _seq, \
636 gen_op_cmp ## type ## _ ## fmt ## _ngl, \
637 gen_op_cmp ## type ## _ ## fmt ## _lt, \
638 gen_op_cmp ## type ## _ ## fmt ## _nge, \
639 gen_op_cmp ## type ## _ ## fmt ## _le, \
640 gen_op_cmp ## type ## _ ## fmt ## _ngt, \
642 static always_inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
644 gen_op_cmp ## type ## _ ## fmt ## _table[n](cc); \
655 #define OP_COND(name, cond) \
656 void glue(gen_op_, name) (void) \
658 int l1 = gen_new_label(); \
659 int l2 = gen_new_label(); \
661 tcg_gen_brcond_tl(cond, cpu_T[0], cpu_T[1], l1); \
662 tcg_gen_movi_tl(cpu_T[0], 0); \
665 tcg_gen_movi_tl(cpu_T[0], 1); \
668 OP_COND(eq, TCG_COND_EQ);
669 OP_COND(ne, TCG_COND_NE);
670 OP_COND(ge, TCG_COND_GE);
671 OP_COND(geu, TCG_COND_GEU);
672 OP_COND(lt, TCG_COND_LT);
673 OP_COND(ltu, TCG_COND_LTU);
676 #define OP_CONDI(name, cond) \
677 void glue(gen_op_, name) (target_ulong val) \
679 int l1 = gen_new_label(); \
680 int l2 = gen_new_label(); \
682 tcg_gen_brcondi_tl(cond, cpu_T[0], val, l1); \
683 tcg_gen_movi_tl(cpu_T[0], 0); \
686 tcg_gen_movi_tl(cpu_T[0], 1); \
689 OP_CONDI(lti, TCG_COND_LT);
690 OP_CONDI(ltiu, TCG_COND_LTU);
693 #define OP_CONDZ(name, cond) \
694 void glue(gen_op_, name) (void) \
696 int l1 = gen_new_label(); \
697 int l2 = gen_new_label(); \
699 tcg_gen_brcondi_tl(cond, cpu_T[0], 0, l1); \
700 tcg_gen_movi_tl(cpu_T[0], 0); \
703 tcg_gen_movi_tl(cpu_T[0], 1); \
706 OP_CONDZ(gez, TCG_COND_GE);
707 OP_CONDZ(gtz, TCG_COND_GT);
708 OP_CONDZ(lez, TCG_COND_LE);
709 OP_CONDZ(ltz, TCG_COND_LT);
712 static inline void gen_save_pc(target_ulong pc)
714 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
715 TCGv r_tc_off = new_tmp();
716 TCGv r_tc_off_tl = tcg_temp_new(TCG_TYPE_TL);
717 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
719 tcg_gen_movi_tl(r_tmp, pc);
720 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
721 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
722 tcg_gen_ext_i32_ptr(r_tc_off_tl, r_tc_off);
723 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_tl);
724 tcg_gen_st_tl(r_tmp, r_ptr, offsetof(CPUState, PC));
728 static inline void gen_breg_pc(void)
730 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
731 TCGv r_tc_off = new_tmp();
732 TCGv r_tc_off_tl = tcg_temp_new(TCG_TYPE_TL);
733 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
735 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
736 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
737 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
738 tcg_gen_ext_i32_ptr(r_tc_off_tl, r_tc_off);
739 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_tl);
740 tcg_gen_st_tl(r_tmp, r_ptr, offsetof(CPUState, PC));
744 static inline void gen_save_btarget(target_ulong btarget)
746 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
748 tcg_gen_movi_tl(r_tmp, btarget);
749 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
752 static always_inline void gen_save_breg_target(int reg)
754 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
756 gen_load_gpr(r_tmp, reg);
757 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
760 static always_inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
762 #if defined MIPS_DEBUG_DISAS
763 if (loglevel & CPU_LOG_TB_IN_ASM) {
764 fprintf(logfile, "hflags %08x saved %08x\n",
765 ctx->hflags, ctx->saved_hflags);
768 if (do_save_pc && ctx->pc != ctx->saved_pc) {
769 gen_save_pc(ctx->pc);
770 ctx->saved_pc = ctx->pc;
772 if (ctx->hflags != ctx->saved_hflags) {
773 gen_op_save_state(ctx->hflags);
774 ctx->saved_hflags = ctx->hflags;
775 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
781 gen_save_btarget(ctx->btarget);
787 static always_inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
789 ctx->saved_hflags = ctx->hflags;
790 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
796 ctx->btarget = env->btarget;
801 static always_inline void
802 generate_exception_err (DisasContext *ctx, int excp, int err)
804 save_cpu_state(ctx, 1);
805 tcg_gen_helper_0_2(do_raise_exception_err, tcg_const_i32(excp), tcg_const_i32(err));
806 tcg_gen_helper_0_0(do_interrupt_restart);
810 static always_inline void
811 generate_exception (DisasContext *ctx, int excp)
813 save_cpu_state(ctx, 1);
814 tcg_gen_helper_0_1(do_raise_exception, tcg_const_i32(excp));
815 tcg_gen_helper_0_0(do_interrupt_restart);
819 /* Addresses computation */
820 static inline void gen_op_addr_add (void)
822 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
824 #if defined(TARGET_MIPS64)
825 /* For compatibility with 32-bit code, data reference in user mode
826 with Status_UX = 0 should be casted to 32-bit and sign extended.
827 See the MIPS64 PRA manual, section 4.10. */
829 TCGv r_tmp = new_tmp();
830 int l1 = gen_new_label();
832 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
833 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
834 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
835 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
836 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
837 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
838 tcg_gen_ext32s_i64(cpu_T[0], cpu_T[0]);
845 static always_inline void check_cp0_enabled(DisasContext *ctx)
847 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
848 generate_exception_err(ctx, EXCP_CpU, 1);
851 static always_inline void check_cp1_enabled(DisasContext *ctx)
853 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
854 generate_exception_err(ctx, EXCP_CpU, 1);
857 /* Verify that the processor is running with COP1X instructions enabled.
858 This is associated with the nabla symbol in the MIPS32 and MIPS64
861 static always_inline void check_cop1x(DisasContext *ctx)
863 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
864 generate_exception(ctx, EXCP_RI);
867 /* Verify that the processor is running with 64-bit floating-point
868 operations enabled. */
870 static always_inline void check_cp1_64bitmode(DisasContext *ctx)
872 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
873 generate_exception(ctx, EXCP_RI);
877 * Verify if floating point register is valid; an operation is not defined
878 * if bit 0 of any register specification is set and the FR bit in the
879 * Status register equals zero, since the register numbers specify an
880 * even-odd pair of adjacent coprocessor general registers. When the FR bit
881 * in the Status register equals one, both even and odd register numbers
882 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
884 * Multiple 64 bit wide registers can be checked by calling
885 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
887 void check_cp1_registers(DisasContext *ctx, int regs)
889 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
890 generate_exception(ctx, EXCP_RI);
893 /* This code generates a "reserved instruction" exception if the
894 CPU does not support the instruction set corresponding to flags. */
895 static always_inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
897 if (unlikely(!(env->insn_flags & flags)))
898 generate_exception(ctx, EXCP_RI);
901 /* This code generates a "reserved instruction" exception if 64-bit
902 instructions are not enabled. */
903 static always_inline void check_mips_64(DisasContext *ctx)
905 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
906 generate_exception(ctx, EXCP_RI);
909 /* load/store instructions. */
910 #if defined(CONFIG_USER_ONLY)
911 #define op_ldst(name) gen_op_##name##_raw()
912 #define OP_LD_TABLE(width)
913 #define OP_ST_TABLE(width)
915 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
916 #define OP_LD_TABLE(width) \
917 static GenOpFunc *gen_op_l##width[] = { \
918 &gen_op_l##width##_kernel, \
919 &gen_op_l##width##_super, \
920 &gen_op_l##width##_user, \
922 #define OP_ST_TABLE(width) \
923 static GenOpFunc *gen_op_s##width[] = { \
924 &gen_op_s##width##_kernel, \
925 &gen_op_s##width##_super, \
926 &gen_op_s##width##_user, \
930 #if defined(TARGET_MIPS64)
947 #define OP_LD(insn,fname) \
948 void inline op_ldst_##insn(DisasContext *ctx) \
950 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
957 #if defined(TARGET_MIPS64)
963 #define OP_ST(insn,fname) \
964 void inline op_ldst_##insn(DisasContext *ctx) \
966 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
971 #if defined(TARGET_MIPS64)
976 #define OP_LD_ATOMIC(insn,fname) \
977 void inline op_ldst_##insn(DisasContext *ctx) \
979 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]); \
980 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
981 tcg_gen_st_tl(cpu_T[1], cpu_env, offsetof(CPUState, CP0_LLAddr)); \
983 OP_LD_ATOMIC(ll,ld32s);
984 #if defined(TARGET_MIPS64)
985 OP_LD_ATOMIC(lld,ld64);
989 #define OP_ST_ATOMIC(insn,fname,almask) \
990 void inline op_ldst_##insn(DisasContext *ctx) \
992 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL); \
993 int l1 = gen_new_label(); \
994 int l2 = gen_new_label(); \
995 int l3 = gen_new_label(); \
997 tcg_gen_andi_tl(r_tmp, cpu_T[0], almask); \
998 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
999 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1000 generate_exception(ctx, EXCP_AdES); \
1001 gen_set_label(l1); \
1002 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1003 tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[0], r_tmp, l2); \
1004 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
1005 tcg_gen_movi_tl(cpu_T[0], 1); \
1007 gen_set_label(l2); \
1008 tcg_gen_movi_tl(cpu_T[0], 0); \
1009 gen_set_label(l3); \
1011 OP_ST_ATOMIC(sc,st32,0x3);
1012 #if defined(TARGET_MIPS64)
1013 OP_ST_ATOMIC(scd,st64,0x7);
1017 void inline op_ldst_lwc1(DisasContext *ctx)
1022 void inline op_ldst_ldc1(DisasContext *ctx)
1027 void inline op_ldst_swc1(DisasContext *ctx)
1032 void inline op_ldst_sdc1(DisasContext *ctx)
1037 /* Load and store */
1038 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1039 int base, int16_t offset)
1041 const char *opn = "ldst";
1044 tcg_gen_movi_tl(cpu_T[0], offset);
1045 } else if (offset == 0) {
1046 gen_load_gpr(cpu_T[0], base);
1048 gen_load_gpr(cpu_T[0], base);
1049 tcg_gen_movi_tl(cpu_T[1], offset);
1052 /* Don't do NOP if destination is zero: we must perform the actual
1055 #if defined(TARGET_MIPS64)
1058 gen_store_gpr(cpu_T[0], rt);
1063 gen_store_gpr(cpu_T[0], rt);
1068 gen_store_gpr(cpu_T[0], rt);
1072 gen_load_gpr(cpu_T[1], rt);
1077 save_cpu_state(ctx, 1);
1078 gen_load_gpr(cpu_T[1], rt);
1080 gen_store_gpr(cpu_T[0], rt);
1084 gen_load_gpr(cpu_T[1], rt);
1086 gen_store_gpr(cpu_T[1], rt);
1090 gen_load_gpr(cpu_T[1], rt);
1095 gen_load_gpr(cpu_T[1], rt);
1097 gen_store_gpr(cpu_T[1], rt);
1101 gen_load_gpr(cpu_T[1], rt);
1108 gen_store_gpr(cpu_T[0], rt);
1112 gen_load_gpr(cpu_T[1], rt);
1118 gen_store_gpr(cpu_T[0], rt);
1122 gen_load_gpr(cpu_T[1], rt);
1128 gen_store_gpr(cpu_T[0], rt);
1133 gen_store_gpr(cpu_T[0], rt);
1137 gen_load_gpr(cpu_T[1], rt);
1143 gen_store_gpr(cpu_T[0], rt);
1147 gen_load_gpr(cpu_T[1], rt);
1149 gen_store_gpr(cpu_T[1], rt);
1153 gen_load_gpr(cpu_T[1], rt);
1158 gen_load_gpr(cpu_T[1], rt);
1160 gen_store_gpr(cpu_T[1], rt);
1164 gen_load_gpr(cpu_T[1], rt);
1170 gen_store_gpr(cpu_T[0], rt);
1174 save_cpu_state(ctx, 1);
1175 gen_load_gpr(cpu_T[1], rt);
1177 gen_store_gpr(cpu_T[0], rt);
1182 generate_exception(ctx, EXCP_RI);
1185 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1188 /* Load and store */
1189 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1190 int base, int16_t offset)
1192 const char *opn = "flt_ldst";
1195 tcg_gen_movi_tl(cpu_T[0], offset);
1196 } else if (offset == 0) {
1197 gen_load_gpr(cpu_T[0], base);
1199 gen_load_gpr(cpu_T[0], base);
1200 tcg_gen_movi_tl(cpu_T[1], offset);
1203 /* Don't do NOP if destination is zero: we must perform the actual
1208 GEN_STORE_FTN_FREG(ft, WT0);
1212 GEN_LOAD_FREG_FTN(WT0, ft);
1218 GEN_STORE_FTN_FREG(ft, DT0);
1222 GEN_LOAD_FREG_FTN(DT0, ft);
1228 generate_exception(ctx, EXCP_RI);
1231 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1234 /* Arithmetic with immediate operand */
1235 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1236 int rt, int rs, int16_t imm)
1239 const char *opn = "imm arith";
1241 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1242 /* If no destination, treat it as a NOP.
1243 For addi, we must generate the overflow exception when needed. */
1247 uimm = (uint16_t)imm;
1251 #if defined(TARGET_MIPS64)
1257 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1258 tcg_gen_movi_tl(cpu_T[1], uimm);
1263 gen_load_gpr(cpu_T[0], rs);
1266 tcg_gen_movi_tl(cpu_T[0], imm << 16);
1271 #if defined(TARGET_MIPS64)
1280 gen_load_gpr(cpu_T[0], rs);
1286 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1287 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1288 int l1 = gen_new_label();
1290 save_cpu_state(ctx, 1);
1291 tcg_gen_ext32s_tl(r_tmp1, cpu_T[0]);
1292 tcg_gen_addi_tl(cpu_T[0], r_tmp1, uimm);
1294 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1295 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1296 tcg_gen_xori_tl(r_tmp2, cpu_T[0], uimm);
1297 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1298 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1299 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1300 /* operands of same sign, result different sign */
1301 generate_exception(ctx, EXCP_OVERFLOW);
1304 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1309 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1310 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], uimm);
1311 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1314 #if defined(TARGET_MIPS64)
1317 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1318 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1319 int l1 = gen_new_label();
1321 save_cpu_state(ctx, 1);
1322 tcg_gen_mov_tl(r_tmp1, cpu_T[0]);
1323 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], uimm);
1325 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1326 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1327 tcg_gen_xori_tl(r_tmp2, cpu_T[0], uimm);
1328 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1329 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1330 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1331 /* operands of same sign, result different sign */
1332 generate_exception(ctx, EXCP_OVERFLOW);
1338 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], uimm);
1351 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], uimm);
1355 tcg_gen_ori_tl(cpu_T[0], cpu_T[0], uimm);
1359 tcg_gen_xori_tl(cpu_T[0], cpu_T[0], uimm);
1366 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1367 tcg_gen_shli_tl(cpu_T[0], cpu_T[0], uimm);
1368 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1372 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1373 tcg_gen_sari_tl(cpu_T[0], cpu_T[0], uimm);
1374 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1378 switch ((ctx->opcode >> 21) & 0x1f) {
1380 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1381 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1382 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1386 /* rotr is decoded as srl on non-R2 CPUs */
1387 if (env->insn_flags & ISA_MIPS32R2) {
1389 TCGv r_tmp1 = new_tmp();
1390 TCGv r_tmp2 = new_tmp();
1392 tcg_gen_trunc_tl_i32(r_tmp1, cpu_T[0]);
1393 tcg_gen_movi_i32(r_tmp2, 0x20);
1394 tcg_gen_subi_i32(r_tmp2, r_tmp2, uimm);
1395 tcg_gen_shl_i32(r_tmp2, r_tmp1, r_tmp2);
1396 tcg_gen_shri_i32(r_tmp1, r_tmp1, uimm);
1397 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp2);
1398 tcg_gen_ext_i32_tl(r_tmp1, cpu_T[0]);
1404 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1405 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1406 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1411 MIPS_INVAL("invalid srl flag");
1412 generate_exception(ctx, EXCP_RI);
1416 #if defined(TARGET_MIPS64)
1418 tcg_gen_shli_tl(cpu_T[0], cpu_T[0], uimm);
1422 tcg_gen_sari_tl(cpu_T[0], cpu_T[0], uimm);
1426 switch ((ctx->opcode >> 21) & 0x1f) {
1428 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1432 /* drotr is decoded as dsrl on non-R2 CPUs */
1433 if (env->insn_flags & ISA_MIPS32R2) {
1435 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1437 tcg_gen_movi_tl(r_tmp1, 0x40);
1438 tcg_gen_subi_tl(r_tmp1, r_tmp1, uimm);
1439 tcg_gen_shl_tl(r_tmp1, cpu_T[0], r_tmp1);
1440 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1441 tcg_gen_or_tl(cpu_T[0], cpu_T[0], r_tmp1);
1445 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1450 MIPS_INVAL("invalid dsrl flag");
1451 generate_exception(ctx, EXCP_RI);
1456 tcg_gen_shli_tl(cpu_T[0], cpu_T[0], uimm + 32);
1460 tcg_gen_sari_tl(cpu_T[0], cpu_T[0], uimm + 32);
1464 switch ((ctx->opcode >> 21) & 0x1f) {
1466 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm + 32);
1470 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1471 if (env->insn_flags & ISA_MIPS32R2) {
1472 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1473 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1475 tcg_gen_movi_tl(r_tmp1, 0x40);
1476 tcg_gen_movi_tl(r_tmp2, 32);
1477 tcg_gen_addi_tl(r_tmp2, r_tmp2, uimm);
1478 tcg_gen_sub_tl(r_tmp1, r_tmp1, r_tmp2);
1479 tcg_gen_shl_tl(r_tmp1, cpu_T[0], r_tmp1);
1480 tcg_gen_shr_tl(cpu_T[0], cpu_T[0], r_tmp2);
1481 tcg_gen_or_tl(cpu_T[0], cpu_T[0], r_tmp1);
1484 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm + 32);
1489 MIPS_INVAL("invalid dsrl32 flag");
1490 generate_exception(ctx, EXCP_RI);
1497 generate_exception(ctx, EXCP_RI);
1500 gen_store_gpr(cpu_T[0], rt);
1501 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1505 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1506 int rd, int rs, int rt)
1508 const char *opn = "arith";
1510 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1511 && opc != OPC_DADD && opc != OPC_DSUB) {
1512 /* If no destination, treat it as a NOP.
1513 For add & sub, we must generate the overflow exception when needed. */
1517 gen_load_gpr(cpu_T[0], rs);
1518 /* Specialcase the conventional move operation. */
1519 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1520 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1521 gen_store_gpr(cpu_T[0], rd);
1524 gen_load_gpr(cpu_T[1], rt);
1528 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1529 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1530 int l1 = gen_new_label();
1532 save_cpu_state(ctx, 1);
1533 tcg_gen_ext32s_tl(r_tmp1, cpu_T[0]);
1534 tcg_gen_ext32s_tl(r_tmp2, cpu_T[1]);
1535 tcg_gen_add_tl(cpu_T[0], r_tmp1, r_tmp2);
1537 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[1]);
1538 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1539 tcg_gen_xor_tl(r_tmp2, cpu_T[0], cpu_T[1]);
1540 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1541 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1542 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1543 /* operands of same sign, result different sign */
1544 generate_exception(ctx, EXCP_OVERFLOW);
1547 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1552 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1553 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1554 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1555 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1560 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1561 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1562 int l1 = gen_new_label();
1564 save_cpu_state(ctx, 1);
1565 tcg_gen_ext32s_tl(r_tmp1, cpu_T[0]);
1566 tcg_gen_ext32s_tl(r_tmp2, cpu_T[1]);
1567 tcg_gen_sub_tl(cpu_T[0], r_tmp1, r_tmp2);
1569 tcg_gen_xor_tl(r_tmp2, r_tmp1, cpu_T[1]);
1570 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[0]);
1571 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1572 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1573 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1574 /* operands of different sign, first operand and result different sign */
1575 generate_exception(ctx, EXCP_OVERFLOW);
1578 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1583 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1584 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1585 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1586 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1589 #if defined(TARGET_MIPS64)
1592 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1593 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1594 int l1 = gen_new_label();
1596 save_cpu_state(ctx, 1);
1597 tcg_gen_mov_tl(r_tmp1, cpu_T[0]);
1598 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1600 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[1]);
1601 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1602 tcg_gen_xor_tl(r_tmp2, cpu_T[0], cpu_T[1]);
1603 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1604 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1605 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1606 /* operands of same sign, result different sign */
1607 generate_exception(ctx, EXCP_OVERFLOW);
1613 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1618 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1619 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1620 int l1 = gen_new_label();
1622 save_cpu_state(ctx, 1);
1623 tcg_gen_mov_tl(r_tmp1, cpu_T[0]);
1624 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1626 tcg_gen_xor_tl(r_tmp2, r_tmp1, cpu_T[1]);
1627 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[0]);
1628 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1629 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1630 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1631 /* operands of different sign, first operand and result different sign */
1632 generate_exception(ctx, EXCP_OVERFLOW);
1638 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1651 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1655 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1656 tcg_gen_not_tl(cpu_T[0], cpu_T[0]);
1660 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1664 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1668 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1669 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1670 tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1671 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1676 int l1 = gen_new_label();
1678 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1679 gen_store_gpr(cpu_T[0], rd);
1686 int l1 = gen_new_label();
1688 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[1], 0, l1);
1689 gen_store_gpr(cpu_T[0], rd);
1695 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1696 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
1697 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1698 tcg_gen_shl_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1699 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1703 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1704 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1705 tcg_gen_sar_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1706 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1710 switch ((ctx->opcode >> 6) & 0x1f) {
1712 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
1713 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1714 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1715 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1719 /* rotrv is decoded as srlv on non-R2 CPUs */
1720 if (env->insn_flags & ISA_MIPS32R2) {
1721 int l1 = gen_new_label();
1722 int l2 = gen_new_label();
1724 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1725 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
1727 TCGv r_tmp1 = new_tmp();
1728 TCGv r_tmp2 = new_tmp();
1729 TCGv r_tmp3 = new_tmp();
1731 tcg_gen_trunc_tl_i32(r_tmp1, cpu_T[0]);
1732 tcg_gen_trunc_tl_i32(r_tmp2, cpu_T[1]);
1733 tcg_gen_movi_i32(r_tmp3, 0x20);
1734 tcg_gen_sub_i32(r_tmp3, r_tmp3, r_tmp1);
1735 tcg_gen_shl_i32(r_tmp3, r_tmp2, r_tmp3);
1736 tcg_gen_shr_i32(r_tmp1, r_tmp2, r_tmp1);
1737 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp3);
1738 tcg_gen_ext_i32_tl(r_tmp1, cpu_T[0]);
1745 tcg_gen_mov_tl(cpu_T[0], cpu_T[1]);
1749 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
1750 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1751 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1752 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1757 MIPS_INVAL("invalid srlv flag");
1758 generate_exception(ctx, EXCP_RI);
1762 #if defined(TARGET_MIPS64)
1764 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1765 tcg_gen_shl_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1769 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1770 tcg_gen_sar_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1774 switch ((ctx->opcode >> 6) & 0x1f) {
1776 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1777 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1781 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1782 if (env->insn_flags & ISA_MIPS32R2) {
1783 int l1 = gen_new_label();
1784 int l2 = gen_new_label();
1786 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1787 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
1789 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1791 tcg_gen_movi_tl(r_tmp1, 0x40);
1792 tcg_gen_sub_tl(r_tmp1, r_tmp1, cpu_T[0]);
1793 tcg_gen_shl_tl(r_tmp1, cpu_T[1], r_tmp1);
1794 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1795 tcg_gen_or_tl(cpu_T[0], cpu_T[0], r_tmp1);
1799 tcg_gen_mov_tl(cpu_T[0], cpu_T[1]);
1803 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1804 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1809 MIPS_INVAL("invalid dsrlv flag");
1810 generate_exception(ctx, EXCP_RI);
1817 generate_exception(ctx, EXCP_RI);
1820 gen_store_gpr(cpu_T[0], rd);
1822 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1825 /* Arithmetic on HI/LO registers */
1826 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1828 const char *opn = "hilo";
1830 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1837 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, HI[0]));
1838 gen_store_gpr(cpu_T[0], reg);
1842 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, LO[0]));
1843 gen_store_gpr(cpu_T[0], reg);
1847 gen_load_gpr(cpu_T[0], reg);
1848 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, HI[0]));
1852 gen_load_gpr(cpu_T[0], reg);
1853 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, LO[0]));
1858 generate_exception(ctx, EXCP_RI);
1861 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1864 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1867 const char *opn = "mul/div";
1869 gen_load_gpr(cpu_T[0], rs);
1870 gen_load_gpr(cpu_T[1], rt);
1874 int l1 = gen_new_label();
1876 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1878 TCGv r_tmp1 = new_tmp();
1879 TCGv r_tmp2 = new_tmp();
1880 TCGv r_tmp3 = new_tmp();
1881 TCGv r_tc_off = new_tmp();
1882 TCGv r_tc_off_tl = tcg_temp_new(TCG_TYPE_TL);
1883 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
1885 tcg_gen_ext_i32_tl(r_tmp1, cpu_T[0]);
1886 tcg_gen_ext_i32_tl(r_tmp2, cpu_T[1]);
1887 tcg_gen_div_i32(r_tmp3, r_tmp1, r_tmp2);
1888 tcg_gen_rem_i32(r_tmp1, r_tmp1, r_tmp2);
1889 tcg_gen_trunc_tl_i32(cpu_T[0], r_tmp3);
1890 tcg_gen_trunc_tl_i32(cpu_T[1], r_tmp1);
1894 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
1895 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
1896 tcg_gen_ext_i32_ptr(r_tc_off_tl, r_tc_off);
1897 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_tl);
1898 tcg_gen_st_tl(cpu_T[0], r_ptr, offsetof(CPUState, LO));
1899 tcg_gen_st_tl(cpu_T[1], r_ptr, offsetof(CPUState, HI));
1908 int l1 = gen_new_label();
1910 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1912 TCGv r_tmp1 = new_tmp();
1913 TCGv r_tmp2 = new_tmp();
1914 TCGv r_tmp3 = new_tmp();
1915 TCGv r_tc_off = new_tmp();
1916 TCGv r_tc_off_tl = tcg_temp_new(TCG_TYPE_TL);
1917 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
1919 tcg_gen_ext_i32_tl(r_tmp1, cpu_T[0]);
1920 tcg_gen_ext_i32_tl(r_tmp2, cpu_T[1]);
1921 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1922 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1923 tcg_gen_trunc_tl_i32(cpu_T[0], r_tmp3);
1924 tcg_gen_trunc_tl_i32(cpu_T[1], r_tmp1);
1928 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
1929 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
1930 tcg_gen_ext_i32_ptr(r_tc_off_tl, r_tc_off);
1931 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_tl);
1932 tcg_gen_st_tl(cpu_T[0], r_ptr, offsetof(CPUState, LO));
1933 tcg_gen_st_tl(cpu_T[1], r_ptr, offsetof(CPUState, HI));
1948 #if defined(TARGET_MIPS64)
1951 int l1 = gen_new_label();
1953 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1955 TCGv r_tc_off = new_tmp();
1956 TCGv r_tc_off_tl = tcg_temp_new(TCG_TYPE_TL);
1957 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
1958 int l2 = gen_new_label();
1959 int l3 = gen_new_label();
1961 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 1ULL << 63, l2);
1962 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[1], -1ULL, l2);
1963 tcg_gen_div_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
1964 tcg_gen_movi_tl(cpu_T[1], 0);
1967 tcg_gen_div_i64(cpu_T[0], cpu_T[0], cpu_T[1]);
1968 tcg_gen_rem_i64(cpu_T[1], cpu_T[0], cpu_T[1]);
1971 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
1972 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
1973 tcg_gen_ext_i32_ptr(r_tc_off_tl, r_tc_off);
1974 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_tl);
1975 tcg_gen_st_tl(cpu_T[0], r_ptr, offsetof(CPUState, LO));
1976 tcg_gen_st_tl(cpu_T[1], r_ptr, offsetof(CPUState, HI));
1985 int l1 = gen_new_label();
1987 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1989 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1990 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1991 TCGv r_tc_off = new_tmp();
1992 TCGv r_tc_off_tl = tcg_temp_new(TCG_TYPE_TL);
1993 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
1995 tcg_gen_divu_i64(r_tmp1, cpu_T[0], cpu_T[1]);
1996 tcg_gen_remu_i64(r_tmp2, cpu_T[0], cpu_T[1]);
1997 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
1998 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
1999 tcg_gen_ext_i32_ptr(r_tc_off_tl, r_tc_off);
2000 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_tl);
2001 tcg_gen_st_tl(r_tmp1, r_ptr, offsetof(CPUState, LO));
2002 tcg_gen_st_tl(r_tmp2, r_ptr, offsetof(CPUState, HI));
2036 generate_exception(ctx, EXCP_RI);
2039 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2042 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2043 int rd, int rs, int rt)
2045 const char *opn = "mul vr54xx";
2047 gen_load_gpr(cpu_T[0], rs);
2048 gen_load_gpr(cpu_T[1], rt);
2051 case OPC_VR54XX_MULS:
2055 case OPC_VR54XX_MULSU:
2059 case OPC_VR54XX_MACC:
2063 case OPC_VR54XX_MACCU:
2067 case OPC_VR54XX_MSAC:
2071 case OPC_VR54XX_MSACU:
2075 case OPC_VR54XX_MULHI:
2079 case OPC_VR54XX_MULHIU:
2083 case OPC_VR54XX_MULSHI:
2087 case OPC_VR54XX_MULSHIU:
2091 case OPC_VR54XX_MACCHI:
2095 case OPC_VR54XX_MACCHIU:
2099 case OPC_VR54XX_MSACHI:
2103 case OPC_VR54XX_MSACHIU:
2108 MIPS_INVAL("mul vr54xx");
2109 generate_exception(ctx, EXCP_RI);
2112 gen_store_gpr(cpu_T[0], rd);
2113 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2116 static void gen_cl (DisasContext *ctx, uint32_t opc,
2119 const char *opn = "CLx";
2125 gen_load_gpr(cpu_T[0], rs);
2128 tcg_gen_helper_0_0(do_clo);
2132 tcg_gen_helper_0_0(do_clz);
2135 #if defined(TARGET_MIPS64)
2137 tcg_gen_helper_0_0(do_dclo);
2141 tcg_gen_helper_0_0(do_dclz);
2147 generate_exception(ctx, EXCP_RI);
2150 gen_store_gpr(cpu_T[0], rd);
2151 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2155 static void gen_trap (DisasContext *ctx, uint32_t opc,
2156 int rs, int rt, int16_t imm)
2161 /* Load needed operands */
2169 /* Compare two registers */
2171 gen_load_gpr(cpu_T[0], rs);
2172 gen_load_gpr(cpu_T[1], rt);
2182 /* Compare register to immediate */
2183 if (rs != 0 || imm != 0) {
2184 gen_load_gpr(cpu_T[0], rs);
2185 tcg_gen_movi_tl(cpu_T[1], (int32_t)imm);
2192 case OPC_TEQ: /* rs == rs */
2193 case OPC_TEQI: /* r0 == 0 */
2194 case OPC_TGE: /* rs >= rs */
2195 case OPC_TGEI: /* r0 >= 0 */
2196 case OPC_TGEU: /* rs >= rs unsigned */
2197 case OPC_TGEIU: /* r0 >= 0 unsigned */
2199 tcg_gen_movi_tl(cpu_T[0], 1);
2201 case OPC_TLT: /* rs < rs */
2202 case OPC_TLTI: /* r0 < 0 */
2203 case OPC_TLTU: /* rs < rs unsigned */
2204 case OPC_TLTIU: /* r0 < 0 unsigned */
2205 case OPC_TNE: /* rs != rs */
2206 case OPC_TNEI: /* r0 != 0 */
2207 /* Never trap: treat as NOP. */
2211 generate_exception(ctx, EXCP_RI);
2242 generate_exception(ctx, EXCP_RI);
2246 save_cpu_state(ctx, 1);
2248 ctx->bstate = BS_STOP;
2251 static always_inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2253 TranslationBlock *tb;
2255 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2258 tcg_gen_exit_tb((long)tb + n);
2265 /* Branches (before delay slot) */
2266 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2267 int rs, int rt, int32_t offset)
2269 target_ulong btarget = -1;
2273 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2274 #ifdef MIPS_DEBUG_DISAS
2275 if (loglevel & CPU_LOG_TB_IN_ASM) {
2277 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2281 generate_exception(ctx, EXCP_RI);
2285 /* Load needed operands */
2291 /* Compare two registers */
2293 gen_load_gpr(cpu_T[0], rs);
2294 gen_load_gpr(cpu_T[1], rt);
2297 btarget = ctx->pc + 4 + offset;
2311 /* Compare to zero */
2313 gen_load_gpr(cpu_T[0], rs);
2316 btarget = ctx->pc + 4 + offset;
2320 /* Jump to immediate */
2321 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2325 /* Jump to register */
2326 if (offset != 0 && offset != 16) {
2327 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2328 others are reserved. */
2329 MIPS_INVAL("jump hint");
2330 generate_exception(ctx, EXCP_RI);
2333 gen_save_breg_target(rs);
2336 MIPS_INVAL("branch/jump");
2337 generate_exception(ctx, EXCP_RI);
2341 /* No condition to be computed */
2343 case OPC_BEQ: /* rx == rx */
2344 case OPC_BEQL: /* rx == rx likely */
2345 case OPC_BGEZ: /* 0 >= 0 */
2346 case OPC_BGEZL: /* 0 >= 0 likely */
2347 case OPC_BLEZ: /* 0 <= 0 */
2348 case OPC_BLEZL: /* 0 <= 0 likely */
2350 ctx->hflags |= MIPS_HFLAG_B;
2351 MIPS_DEBUG("balways");
2353 case OPC_BGEZAL: /* 0 >= 0 */
2354 case OPC_BGEZALL: /* 0 >= 0 likely */
2355 /* Always take and link */
2357 ctx->hflags |= MIPS_HFLAG_B;
2358 MIPS_DEBUG("balways and link");
2360 case OPC_BNE: /* rx != rx */
2361 case OPC_BGTZ: /* 0 > 0 */
2362 case OPC_BLTZ: /* 0 < 0 */
2364 MIPS_DEBUG("bnever (NOP)");
2366 case OPC_BLTZAL: /* 0 < 0 */
2367 tcg_gen_movi_tl(cpu_T[0], ctx->pc + 8);
2368 gen_store_gpr(cpu_T[0], 31);
2369 MIPS_DEBUG("bnever and link");
2371 case OPC_BLTZALL: /* 0 < 0 likely */
2372 tcg_gen_movi_tl(cpu_T[0], ctx->pc + 8);
2373 gen_store_gpr(cpu_T[0], 31);
2374 /* Skip the instruction in the delay slot */
2375 MIPS_DEBUG("bnever, link and skip");
2378 case OPC_BNEL: /* rx != rx likely */
2379 case OPC_BGTZL: /* 0 > 0 likely */
2380 case OPC_BLTZL: /* 0 < 0 likely */
2381 /* Skip the instruction in the delay slot */
2382 MIPS_DEBUG("bnever and skip");
2386 ctx->hflags |= MIPS_HFLAG_B;
2387 MIPS_DEBUG("j " TARGET_FMT_lx, btarget);
2391 ctx->hflags |= MIPS_HFLAG_B;
2392 MIPS_DEBUG("jal " TARGET_FMT_lx, btarget);
2395 ctx->hflags |= MIPS_HFLAG_BR;
2396 MIPS_DEBUG("jr %s", regnames[rs]);
2400 ctx->hflags |= MIPS_HFLAG_BR;
2401 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2404 MIPS_INVAL("branch/jump");
2405 generate_exception(ctx, EXCP_RI);
2412 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2413 regnames[rs], regnames[rt], btarget);
2417 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2418 regnames[rs], regnames[rt], btarget);
2422 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2423 regnames[rs], regnames[rt], btarget);
2427 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2428 regnames[rs], regnames[rt], btarget);
2432 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2436 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2440 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2446 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2450 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2454 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2458 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2462 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2466 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2470 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2475 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2477 ctx->hflags |= MIPS_HFLAG_BC;
2478 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
2483 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2485 ctx->hflags |= MIPS_HFLAG_BL;
2486 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
2489 MIPS_INVAL("conditional branch/jump");
2490 generate_exception(ctx, EXCP_RI);
2494 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2495 blink, ctx->hflags, btarget);
2497 ctx->btarget = btarget;
2499 tcg_gen_movi_tl(cpu_T[0], ctx->pc + 8);
2500 gen_store_gpr(cpu_T[0], blink);
2504 /* special3 bitfield operations */
2505 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2506 int rs, int lsb, int msb)
2508 gen_load_gpr(cpu_T[1], rs);
2513 gen_op_ext(lsb, msb + 1);
2515 #if defined(TARGET_MIPS64)
2519 gen_op_dext(lsb, msb + 1 + 32);
2524 gen_op_dext(lsb + 32, msb + 1);
2529 gen_op_dext(lsb, msb + 1);
2535 gen_load_gpr(cpu_T[0], rt);
2536 gen_op_ins(lsb, msb - lsb + 1);
2538 #if defined(TARGET_MIPS64)
2542 gen_load_gpr(cpu_T[0], rt);
2543 gen_op_dins(lsb, msb - lsb + 1 + 32);
2548 gen_load_gpr(cpu_T[0], rt);
2549 gen_op_dins(lsb + 32, msb - lsb + 1);
2554 gen_load_gpr(cpu_T[0], rt);
2555 gen_op_dins(lsb, msb - lsb + 1);
2560 MIPS_INVAL("bitops");
2561 generate_exception(ctx, EXCP_RI);
2564 gen_store_gpr(cpu_T[0], rt);
2567 /* CP0 (MMU and control) */
2568 static void gen_mfc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
2570 const char *rn = "invalid";
2571 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2572 TCGv r_tmp64 = tcg_temp_new(TCG_TYPE_I64);
2575 check_insn(env, ctx, ISA_MIPS32);
2581 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Index));
2582 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2586 check_insn(env, ctx, ASE_MT);
2587 gen_op_mfc0_mvpcontrol();
2591 check_insn(env, ctx, ASE_MT);
2592 gen_op_mfc0_mvpconf0();
2596 check_insn(env, ctx, ASE_MT);
2597 gen_op_mfc0_mvpconf1();
2607 gen_op_mfc0_random();
2611 check_insn(env, ctx, ASE_MT);
2612 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEControl));
2613 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2617 check_insn(env, ctx, ASE_MT);
2618 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEConf0));
2619 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2623 check_insn(env, ctx, ASE_MT);
2624 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEConf1));
2625 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2629 check_insn(env, ctx, ASE_MT);
2630 tcg_gen_ld_i64(r_tmp64, cpu_env, offsetof(CPUState, CP0_YQMask));
2631 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp64);
2635 check_insn(env, ctx, ASE_MT);
2636 tcg_gen_ld_tl(r_tmp64, cpu_env, offsetof(CPUState, CP0_VPESchedule));
2637 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp64);
2641 check_insn(env, ctx, ASE_MT);
2642 tcg_gen_ld_tl(r_tmp64, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
2643 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp64);
2644 rn = "VPEScheFBack";
2647 check_insn(env, ctx, ASE_MT);
2648 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEOpt));
2649 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2659 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo0));
2660 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2664 check_insn(env, ctx, ASE_MT);
2665 gen_op_mfc0_tcstatus();
2669 check_insn(env, ctx, ASE_MT);
2670 gen_op_mfc0_tcbind();
2674 check_insn(env, ctx, ASE_MT);
2675 gen_op_mfc0_tcrestart();
2679 check_insn(env, ctx, ASE_MT);
2680 gen_op_mfc0_tchalt();
2684 check_insn(env, ctx, ASE_MT);
2685 gen_op_mfc0_tccontext();
2689 check_insn(env, ctx, ASE_MT);
2690 gen_op_mfc0_tcschedule();
2694 check_insn(env, ctx, ASE_MT);
2695 gen_op_mfc0_tcschefback();
2705 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo1));
2706 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2716 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_Context));
2717 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2721 // gen_op_mfc0_contextconfig(); /* SmartMIPS ASE */
2722 rn = "ContextConfig";
2731 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_PageMask));
2732 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2736 check_insn(env, ctx, ISA_MIPS32R2);
2737 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_PageGrain));
2738 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2748 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Wired));
2749 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2753 check_insn(env, ctx, ISA_MIPS32R2);
2754 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf0));
2755 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2759 check_insn(env, ctx, ISA_MIPS32R2);
2760 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf1));
2761 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2765 check_insn(env, ctx, ISA_MIPS32R2);
2766 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf2));
2767 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2771 check_insn(env, ctx, ISA_MIPS32R2);
2772 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf3));
2773 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2777 check_insn(env, ctx, ISA_MIPS32R2);
2778 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf4));
2779 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2789 check_insn(env, ctx, ISA_MIPS32R2);
2790 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_HWREna));
2791 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2801 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr));
2802 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2812 gen_op_mfc0_count();
2815 /* 6,7 are implementation dependent */
2823 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryHi));
2824 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2834 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Compare));
2835 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2838 /* 6,7 are implementation dependent */
2846 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
2847 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2851 check_insn(env, ctx, ISA_MIPS32R2);
2852 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_IntCtl));
2853 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2857 check_insn(env, ctx, ISA_MIPS32R2);
2858 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl));
2859 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2863 check_insn(env, ctx, ISA_MIPS32R2);
2864 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSMap));
2865 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2875 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Cause));
2876 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2886 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EPC));
2887 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2897 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_PRid));
2898 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2902 check_insn(env, ctx, ISA_MIPS32R2);
2903 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_EBase));
2904 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2914 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config0));
2915 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2919 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config1));
2920 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2924 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config2));
2925 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2929 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config3));
2930 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2933 /* 4,5 are reserved */
2934 /* 6,7 are implementation dependent */
2936 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config6));
2937 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2941 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config7));
2942 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
2952 gen_op_mfc0_lladdr();
2962 gen_op_mfc0_watchlo(sel);
2972 gen_op_mfc0_watchhi(sel);
2982 #if defined(TARGET_MIPS64)
2983 check_insn(env, ctx, ISA_MIPS3);
2984 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_XContext));
2985 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2994 /* Officially reserved, but sel 0 is used for R1x000 framemask */
2997 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Framemask));
2998 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3007 rn = "'Diagnostic"; /* implementation dependent */
3012 gen_op_mfc0_debug(); /* EJTAG support */
3016 // gen_op_mfc0_tracecontrol(); /* PDtrace support */
3017 rn = "TraceControl";
3020 // gen_op_mfc0_tracecontrol2(); /* PDtrace support */
3021 rn = "TraceControl2";
3024 // gen_op_mfc0_usertracedata(); /* PDtrace support */
3025 rn = "UserTraceData";
3028 // gen_op_mfc0_debug(); /* PDtrace support */
3039 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_DEPC));
3040 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
3050 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Performance0));
3051 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3052 rn = "Performance0";
3055 // gen_op_mfc0_performance1();
3056 rn = "Performance1";
3059 // gen_op_mfc0_performance2();
3060 rn = "Performance2";
3063 // gen_op_mfc0_performance3();
3064 rn = "Performance3";
3067 // gen_op_mfc0_performance4();
3068 rn = "Performance4";
3071 // gen_op_mfc0_performance5();
3072 rn = "Performance5";
3075 // gen_op_mfc0_performance6();
3076 rn = "Performance6";
3079 // gen_op_mfc0_performance7();
3080 rn = "Performance7";
3105 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_TagLo));
3106 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3113 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_DataLo));
3114 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3127 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_TagHi));
3128 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3135 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_DataHi));
3136 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3146 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3147 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
3158 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_DESAVE));
3159 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3169 #if defined MIPS_DEBUG_DISAS
3170 if (loglevel & CPU_LOG_TB_IN_ASM) {
3171 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3178 #if defined MIPS_DEBUG_DISAS
3179 if (loglevel & CPU_LOG_TB_IN_ASM) {
3180 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3184 generate_exception(ctx, EXCP_RI);
3187 static void gen_mtc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
3189 const char *rn = "invalid";
3192 check_insn(env, ctx, ISA_MIPS32);
3198 gen_op_mtc0_index();
3202 check_insn(env, ctx, ASE_MT);
3203 gen_op_mtc0_mvpcontrol();
3207 check_insn(env, ctx, ASE_MT);
3212 check_insn(env, ctx, ASE_MT);
3227 check_insn(env, ctx, ASE_MT);
3228 gen_op_mtc0_vpecontrol();
3232 check_insn(env, ctx, ASE_MT);
3233 gen_op_mtc0_vpeconf0();
3237 check_insn(env, ctx, ASE_MT);
3238 gen_op_mtc0_vpeconf1();
3242 check_insn(env, ctx, ASE_MT);
3243 gen_op_mtc0_yqmask();
3247 check_insn(env, ctx, ASE_MT);
3248 gen_op_mtc0_vpeschedule();
3252 check_insn(env, ctx, ASE_MT);
3253 gen_op_mtc0_vpeschefback();
3254 rn = "VPEScheFBack";
3257 check_insn(env, ctx, ASE_MT);
3258 gen_op_mtc0_vpeopt();
3268 gen_op_mtc0_entrylo0();
3272 check_insn(env, ctx, ASE_MT);
3273 gen_op_mtc0_tcstatus();
3277 check_insn(env, ctx, ASE_MT);
3278 gen_op_mtc0_tcbind();
3282 check_insn(env, ctx, ASE_MT);
3283 gen_op_mtc0_tcrestart();
3287 check_insn(env, ctx, ASE_MT);
3288 gen_op_mtc0_tchalt();
3292 check_insn(env, ctx, ASE_MT);
3293 gen_op_mtc0_tccontext();
3297 check_insn(env, ctx, ASE_MT);
3298 gen_op_mtc0_tcschedule();
3302 check_insn(env, ctx, ASE_MT);
3303 gen_op_mtc0_tcschefback();
3313 gen_op_mtc0_entrylo1();
3323 gen_op_mtc0_context();
3327 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
3328 rn = "ContextConfig";
3337 gen_op_mtc0_pagemask();
3341 check_insn(env, ctx, ISA_MIPS32R2);
3342 gen_op_mtc0_pagegrain();
3352 gen_op_mtc0_wired();
3356 check_insn(env, ctx, ISA_MIPS32R2);
3357 gen_op_mtc0_srsconf0();
3361 check_insn(env, ctx, ISA_MIPS32R2);
3362 gen_op_mtc0_srsconf1();
3366 check_insn(env, ctx, ISA_MIPS32R2);
3367 gen_op_mtc0_srsconf2();
3371 check_insn(env, ctx, ISA_MIPS32R2);
3372 gen_op_mtc0_srsconf3();
3376 check_insn(env, ctx, ISA_MIPS32R2);
3377 gen_op_mtc0_srsconf4();
3387 check_insn(env, ctx, ISA_MIPS32R2);
3388 gen_op_mtc0_hwrena();
3402 gen_op_mtc0_count();
3405 /* 6,7 are implementation dependent */
3409 /* Stop translation as we may have switched the execution mode */
3410 ctx->bstate = BS_STOP;
3415 gen_op_mtc0_entryhi();
3425 gen_op_mtc0_compare();
3428 /* 6,7 are implementation dependent */
3432 /* Stop translation as we may have switched the execution mode */
3433 ctx->bstate = BS_STOP;
3438 gen_op_mtc0_status();
3439 /* BS_STOP isn't good enough here, hflags may have changed. */
3440 gen_save_pc(ctx->pc + 4);
3441 ctx->bstate = BS_EXCP;
3445 check_insn(env, ctx, ISA_MIPS32R2);
3446 gen_op_mtc0_intctl();
3447 /* Stop translation as we may have switched the execution mode */
3448 ctx->bstate = BS_STOP;
3452 check_insn(env, ctx, ISA_MIPS32R2);
3453 gen_op_mtc0_srsctl();
3454 /* Stop translation as we may have switched the execution mode */
3455 ctx->bstate = BS_STOP;
3459 check_insn(env, ctx, ISA_MIPS32R2);
3460 gen_op_mtc0_srsmap();
3461 /* Stop translation as we may have switched the execution mode */
3462 ctx->bstate = BS_STOP;
3472 gen_op_mtc0_cause();
3478 /* Stop translation as we may have switched the execution mode */
3479 ctx->bstate = BS_STOP;
3498 check_insn(env, ctx, ISA_MIPS32R2);
3499 gen_op_mtc0_ebase();
3509 gen_op_mtc0_config0();
3511 /* Stop translation as we may have switched the execution mode */
3512 ctx->bstate = BS_STOP;
3515 /* ignored, read only */
3519 gen_op_mtc0_config2();
3521 /* Stop translation as we may have switched the execution mode */
3522 ctx->bstate = BS_STOP;
3525 /* ignored, read only */
3528 /* 4,5 are reserved */
3529 /* 6,7 are implementation dependent */
3539 rn = "Invalid config selector";
3556 gen_op_mtc0_watchlo(sel);
3566 gen_op_mtc0_watchhi(sel);
3576 #if defined(TARGET_MIPS64)
3577 check_insn(env, ctx, ISA_MIPS3);
3578 gen_op_mtc0_xcontext();
3587 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3590 gen_op_mtc0_framemask();
3599 rn = "Diagnostic"; /* implementation dependent */
3604 gen_op_mtc0_debug(); /* EJTAG support */
3605 /* BS_STOP isn't good enough here, hflags may have changed. */
3606 gen_save_pc(ctx->pc + 4);
3607 ctx->bstate = BS_EXCP;
3611 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
3612 rn = "TraceControl";
3613 /* Stop translation as we may have switched the execution mode */
3614 ctx->bstate = BS_STOP;
3617 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
3618 rn = "TraceControl2";
3619 /* Stop translation as we may have switched the execution mode */
3620 ctx->bstate = BS_STOP;
3623 /* Stop translation as we may have switched the execution mode */
3624 ctx->bstate = BS_STOP;
3625 // gen_op_mtc0_usertracedata(); /* PDtrace support */
3626 rn = "UserTraceData";
3627 /* Stop translation as we may have switched the execution mode */
3628 ctx->bstate = BS_STOP;
3631 // gen_op_mtc0_debug(); /* PDtrace support */
3632 /* Stop translation as we may have switched the execution mode */
3633 ctx->bstate = BS_STOP;
3643 gen_op_mtc0_depc(); /* EJTAG support */
3653 gen_op_mtc0_performance0();
3654 rn = "Performance0";
3657 // gen_op_mtc0_performance1();
3658 rn = "Performance1";
3661 // gen_op_mtc0_performance2();
3662 rn = "Performance2";
3665 // gen_op_mtc0_performance3();
3666 rn = "Performance3";
3669 // gen_op_mtc0_performance4();
3670 rn = "Performance4";
3673 // gen_op_mtc0_performance5();
3674 rn = "Performance5";
3677 // gen_op_mtc0_performance6();
3678 rn = "Performance6";
3681 // gen_op_mtc0_performance7();
3682 rn = "Performance7";
3708 gen_op_mtc0_taglo();
3715 gen_op_mtc0_datalo();
3728 gen_op_mtc0_taghi();
3735 gen_op_mtc0_datahi();
3746 gen_op_mtc0_errorepc();
3756 gen_op_mtc0_desave(); /* EJTAG support */
3762 /* Stop translation as we may have switched the execution mode */
3763 ctx->bstate = BS_STOP;
3768 #if defined MIPS_DEBUG_DISAS
3769 if (loglevel & CPU_LOG_TB_IN_ASM) {
3770 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3777 #if defined MIPS_DEBUG_DISAS
3778 if (loglevel & CPU_LOG_TB_IN_ASM) {
3779 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3783 generate_exception(ctx, EXCP_RI);
3786 #if defined(TARGET_MIPS64)
3787 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
3789 const char *rn = "invalid";
3790 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
3793 check_insn(env, ctx, ISA_MIPS64);
3799 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Index));
3800 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3804 check_insn(env, ctx, ASE_MT);
3805 gen_op_mfc0_mvpcontrol();
3809 check_insn(env, ctx, ASE_MT);
3810 gen_op_mfc0_mvpconf0();
3814 check_insn(env, ctx, ASE_MT);
3815 gen_op_mfc0_mvpconf1();
3825 gen_op_mfc0_random();
3829 check_insn(env, ctx, ASE_MT);
3830 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEControl));
3831 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3835 check_insn(env, ctx, ASE_MT);
3836 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEConf0));
3837 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3841 check_insn(env, ctx, ASE_MT);
3842 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEConf1));
3843 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3847 check_insn(env, ctx, ASE_MT);
3848 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_YQMask));
3852 check_insn(env, ctx, ASE_MT);
3853 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_VPESchedule));
3857 check_insn(env, ctx, ASE_MT);
3858 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3859 rn = "VPEScheFBack";
3862 check_insn(env, ctx, ASE_MT);
3863 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_VPEOpt));
3864 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3874 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo0));
3878 check_insn(env, ctx, ASE_MT);
3879 gen_op_mfc0_tcstatus();
3883 check_insn(env, ctx, ASE_MT);
3884 gen_op_mfc0_tcbind();
3888 check_insn(env, ctx, ASE_MT);
3889 gen_op_dmfc0_tcrestart();
3893 check_insn(env, ctx, ASE_MT);
3894 gen_op_dmfc0_tchalt();
3898 check_insn(env, ctx, ASE_MT);
3899 gen_op_dmfc0_tccontext();
3903 check_insn(env, ctx, ASE_MT);
3904 gen_op_dmfc0_tcschedule();
3908 check_insn(env, ctx, ASE_MT);
3909 gen_op_dmfc0_tcschefback();
3919 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo1));
3929 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_Context));
3933 // gen_op_dmfc0_contextconfig(); /* SmartMIPS ASE */
3934 rn = "ContextConfig";
3943 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_PageMask));
3944 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3948 check_insn(env, ctx, ISA_MIPS32R2);
3949 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_PageGrain));
3950 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3960 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Wired));
3961 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3965 check_insn(env, ctx, ISA_MIPS32R2);
3966 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf0));
3967 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3971 check_insn(env, ctx, ISA_MIPS32R2);
3972 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf1));
3973 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3977 check_insn(env, ctx, ISA_MIPS32R2);
3978 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf2));
3979 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3983 check_insn(env, ctx, ISA_MIPS32R2);
3984 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf3));
3985 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
3989 check_insn(env, ctx, ISA_MIPS32R2);
3990 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSConf4));
3991 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4001 check_insn(env, ctx, ISA_MIPS32R2);
4002 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_HWREna));
4003 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4013 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr));
4023 gen_op_mfc0_count();
4026 /* 6,7 are implementation dependent */
4034 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryHi));
4044 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Compare));
4045 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4048 /* 6,7 are implementation dependent */
4056 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
4057 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4061 check_insn(env, ctx, ISA_MIPS32R2);
4062 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_IntCtl));
4063 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4067 check_insn(env, ctx, ISA_MIPS32R2);
4068 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl));
4069 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4073 check_insn(env, ctx, ISA_MIPS32R2);
4074 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSMap));
4075 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4085 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Cause));
4086 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4096 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EPC));
4106 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_PRid));
4107 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4111 check_insn(env, ctx, ISA_MIPS32R2);
4112 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_EBase));
4113 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4123 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config0));
4124 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4128 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config1));
4129 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4133 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config2));
4134 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4138 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config3));
4139 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4142 /* 6,7 are implementation dependent */
4144 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config6));
4145 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4149 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Config7));
4150 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4160 gen_op_dmfc0_lladdr();
4170 gen_op_dmfc0_watchlo(sel);
4180 gen_op_mfc0_watchhi(sel);
4190 check_insn(env, ctx, ISA_MIPS3);
4191 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_XContext));
4199 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4202 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Framemask));
4203 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4212 rn = "'Diagnostic"; /* implementation dependent */
4217 gen_op_mfc0_debug(); /* EJTAG support */
4221 // gen_op_dmfc0_tracecontrol(); /* PDtrace support */
4222 rn = "TraceControl";
4225 // gen_op_dmfc0_tracecontrol2(); /* PDtrace support */
4226 rn = "TraceControl2";
4229 // gen_op_dmfc0_usertracedata(); /* PDtrace support */
4230 rn = "UserTraceData";
4233 // gen_op_dmfc0_debug(); /* PDtrace support */
4244 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_DEPC));
4254 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Performance0));
4255 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4256 rn = "Performance0";
4259 // gen_op_dmfc0_performance1();
4260 rn = "Performance1";
4263 // gen_op_dmfc0_performance2();
4264 rn = "Performance2";
4267 // gen_op_dmfc0_performance3();
4268 rn = "Performance3";
4271 // gen_op_dmfc0_performance4();
4272 rn = "Performance4";
4275 // gen_op_dmfc0_performance5();
4276 rn = "Performance5";
4279 // gen_op_dmfc0_performance6();
4280 rn = "Performance6";
4283 // gen_op_dmfc0_performance7();
4284 rn = "Performance7";
4309 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_TagLo));
4310 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4317 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_DataLo));
4318 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4331 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_TagHi));
4332 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4339 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_DataHi));
4340 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4350 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4361 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_DESAVE));
4362 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp);
4372 #if defined MIPS_DEBUG_DISAS
4373 if (loglevel & CPU_LOG_TB_IN_ASM) {
4374 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4381 #if defined MIPS_DEBUG_DISAS
4382 if (loglevel & CPU_LOG_TB_IN_ASM) {
4383 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4387 generate_exception(ctx, EXCP_RI);
4390 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
4392 const char *rn = "invalid";
4395 check_insn(env, ctx, ISA_MIPS64);
4401 gen_op_mtc0_index();
4405 check_insn(env, ctx, ASE_MT);
4406 gen_op_mtc0_mvpcontrol();
4410 check_insn(env, ctx, ASE_MT);
4415 check_insn(env, ctx, ASE_MT);
4430 check_insn(env, ctx, ASE_MT);
4431 gen_op_mtc0_vpecontrol();
4435 check_insn(env, ctx, ASE_MT);
4436 gen_op_mtc0_vpeconf0();
4440 check_insn(env, ctx, ASE_MT);
4441 gen_op_mtc0_vpeconf1();
4445 check_insn(env, ctx, ASE_MT);
4446 gen_op_mtc0_yqmask();
4450 check_insn(env, ctx, ASE_MT);
4451 gen_op_mtc0_vpeschedule();
4455 check_insn(env, ctx, ASE_MT);
4456 gen_op_mtc0_vpeschefback();
4457 rn = "VPEScheFBack";
4460 check_insn(env, ctx, ASE_MT);
4461 gen_op_mtc0_vpeopt();
4471 gen_op_mtc0_entrylo0();
4475 check_insn(env, ctx, ASE_MT);
4476 gen_op_mtc0_tcstatus();
4480 check_insn(env, ctx, ASE_MT);
4481 gen_op_mtc0_tcbind();
4485 check_insn(env, ctx, ASE_MT);
4486 gen_op_mtc0_tcrestart();
4490 check_insn(env, ctx, ASE_MT);
4491 gen_op_mtc0_tchalt();
4495 check_insn(env, ctx, ASE_MT);
4496 gen_op_mtc0_tccontext();
4500 check_insn(env, ctx, ASE_MT);
4501 gen_op_mtc0_tcschedule();
4505 check_insn(env, ctx, ASE_MT);
4506 gen_op_mtc0_tcschefback();
4516 gen_op_mtc0_entrylo1();
4526 gen_op_mtc0_context();
4530 // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */
4531 rn = "ContextConfig";
4540 gen_op_mtc0_pagemask();
4544 check_insn(env, ctx, ISA_MIPS32R2);
4545 gen_op_mtc0_pagegrain();
4555 gen_op_mtc0_wired();
4559 check_insn(env, ctx, ISA_MIPS32R2);
4560 gen_op_mtc0_srsconf0();
4564 check_insn(env, ctx, ISA_MIPS32R2);
4565 gen_op_mtc0_srsconf1();
4569 check_insn(env, ctx, ISA_MIPS32R2);
4570 gen_op_mtc0_srsconf2();
4574 check_insn(env, ctx, ISA_MIPS32R2);
4575 gen_op_mtc0_srsconf3();
4579 check_insn(env, ctx, ISA_MIPS32R2);
4580 gen_op_mtc0_srsconf4();
4590 check_insn(env, ctx, ISA_MIPS32R2);
4591 gen_op_mtc0_hwrena();
4605 gen_op_mtc0_count();
4608 /* 6,7 are implementation dependent */
4612 /* Stop translation as we may have switched the execution mode */
4613 ctx->bstate = BS_STOP;
4618 gen_op_mtc0_entryhi();
4628 gen_op_mtc0_compare();
4631 /* 6,7 are implementation dependent */
4635 /* Stop translation as we may have switched the execution mode */
4636 ctx->bstate = BS_STOP;
4641 gen_op_mtc0_status();
4642 /* BS_STOP isn't good enough here, hflags may have changed. */
4643 gen_save_pc(ctx->pc + 4);
4644 ctx->bstate = BS_EXCP;
4648 check_insn(env, ctx, ISA_MIPS32R2);
4649 gen_op_mtc0_intctl();
4650 /* Stop translation as we may have switched the execution mode */
4651 ctx->bstate = BS_STOP;
4655 check_insn(env, ctx, ISA_MIPS32R2);
4656 gen_op_mtc0_srsctl();
4657 /* Stop translation as we may have switched the execution mode */
4658 ctx->bstate = BS_STOP;
4662 check_insn(env, ctx, ISA_MIPS32R2);
4663 gen_op_mtc0_srsmap();
4664 /* Stop translation as we may have switched the execution mode */
4665 ctx->bstate = BS_STOP;
4675 gen_op_mtc0_cause();
4681 /* Stop translation as we may have switched the execution mode */
4682 ctx->bstate = BS_STOP;
4701 check_insn(env, ctx, ISA_MIPS32R2);
4702 gen_op_mtc0_ebase();
4712 gen_op_mtc0_config0();
4714 /* Stop translation as we may have switched the execution mode */
4715 ctx->bstate = BS_STOP;
4722 gen_op_mtc0_config2();
4724 /* Stop translation as we may have switched the execution mode */
4725 ctx->bstate = BS_STOP;
4731 /* 6,7 are implementation dependent */
4733 rn = "Invalid config selector";
4750 gen_op_mtc0_watchlo(sel);
4760 gen_op_mtc0_watchhi(sel);
4770 check_insn(env, ctx, ISA_MIPS3);
4771 gen_op_mtc0_xcontext();
4779 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4782 gen_op_mtc0_framemask();
4791 rn = "Diagnostic"; /* implementation dependent */
4796 gen_op_mtc0_debug(); /* EJTAG support */
4797 /* BS_STOP isn't good enough here, hflags may have changed. */
4798 gen_save_pc(ctx->pc + 4);
4799 ctx->bstate = BS_EXCP;
4803 // gen_op_mtc0_tracecontrol(); /* PDtrace support */
4804 /* Stop translation as we may have switched the execution mode */
4805 ctx->bstate = BS_STOP;
4806 rn = "TraceControl";
4809 // gen_op_mtc0_tracecontrol2(); /* PDtrace support */
4810 /* Stop translation as we may have switched the execution mode */
4811 ctx->bstate = BS_STOP;
4812 rn = "TraceControl2";
4815 // gen_op_mtc0_usertracedata(); /* PDtrace support */
4816 /* Stop translation as we may have switched the execution mode */
4817 ctx->bstate = BS_STOP;
4818 rn = "UserTraceData";
4821 // gen_op_mtc0_debug(); /* PDtrace support */
4822 /* Stop translation as we may have switched the execution mode */
4823 ctx->bstate = BS_STOP;
4833 gen_op_mtc0_depc(); /* EJTAG support */
4843 gen_op_mtc0_performance0();
4844 rn = "Performance0";
4847 // gen_op_mtc0_performance1();
4848 rn = "Performance1";
4851 // gen_op_mtc0_performance2();
4852 rn = "Performance2";
4855 // gen_op_mtc0_performance3();
4856 rn = "Performance3";
4859 // gen_op_mtc0_performance4();
4860 rn = "Performance4";
4863 // gen_op_mtc0_performance5();
4864 rn = "Performance5";
4867 // gen_op_mtc0_performance6();
4868 rn = "Performance6";
4871 // gen_op_mtc0_performance7();
4872 rn = "Performance7";
4898 gen_op_mtc0_taglo();
4905 gen_op_mtc0_datalo();
4918 gen_op_mtc0_taghi();
4925 gen_op_mtc0_datahi();
4936 gen_op_mtc0_errorepc();
4946 gen_op_mtc0_desave(); /* EJTAG support */
4952 /* Stop translation as we may have switched the execution mode */
4953 ctx->bstate = BS_STOP;
4958 #if defined MIPS_DEBUG_DISAS
4959 if (loglevel & CPU_LOG_TB_IN_ASM) {
4960 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4967 #if defined MIPS_DEBUG_DISAS
4968 if (loglevel & CPU_LOG_TB_IN_ASM) {
4969 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
4973 generate_exception(ctx, EXCP_RI);
4975 #endif /* TARGET_MIPS64 */
4977 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt,
4978 int u, int sel, int h)
4980 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
4982 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
4983 ((env->CP0_TCBind[other_tc] & (0xf << CP0TCBd_CurVPE)) !=
4984 (env->CP0_TCBind[env->current_tc] & (0xf << CP0TCBd_CurVPE))))
4985 tcg_gen_movi_tl(cpu_T[0], -1);
4986 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
4987 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
4988 tcg_gen_movi_tl(cpu_T[0], -1);
4994 gen_op_mftc0_tcstatus();
4997 gen_op_mftc0_tcbind();
5000 gen_op_mftc0_tcrestart();
5003 gen_op_mftc0_tchalt();
5006 gen_op_mftc0_tccontext();
5009 gen_op_mftc0_tcschedule();
5012 gen_op_mftc0_tcschefback();
5015 gen_mfc0(env, ctx, rt, sel);
5022 gen_op_mftc0_entryhi();
5025 gen_mfc0(env, ctx, rt, sel);
5031 gen_op_mftc0_status();
5034 gen_mfc0(env, ctx, rt, sel);
5040 gen_op_mftc0_debug();
5043 gen_mfc0(env, ctx, rt, sel);
5048 gen_mfc0(env, ctx, rt, sel);
5050 } else switch (sel) {
5051 /* GPR registers. */
5055 /* Auxiliary CPU registers */
5101 /* Floating point (COP1). */
5103 /* XXX: For now we support only a single FPU context. */
5105 GEN_LOAD_FREG_FTN(WT0, rt);
5108 GEN_LOAD_FREG_FTN(WTH0, rt);
5113 /* XXX: For now we support only a single FPU context. */
5116 /* COP2: Not implemented. */
5123 #if defined MIPS_DEBUG_DISAS
5124 if (loglevel & CPU_LOG_TB_IN_ASM) {
5125 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5132 #if defined MIPS_DEBUG_DISAS
5133 if (loglevel & CPU_LOG_TB_IN_ASM) {
5134 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5138 generate_exception(ctx, EXCP_RI);
5141 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd,
5142 int u, int sel, int h)
5144 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5146 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5147 ((env->CP0_TCBind[other_tc] & (0xf << CP0TCBd_CurVPE)) !=
5148 (env->CP0_TCBind[env->current_tc] & (0xf << CP0TCBd_CurVPE))))
5150 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5151 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5158 gen_op_mttc0_tcstatus();
5161 gen_op_mttc0_tcbind();
5164 gen_op_mttc0_tcrestart();
5167 gen_op_mttc0_tchalt();
5170 gen_op_mttc0_tccontext();
5173 gen_op_mttc0_tcschedule();
5176 gen_op_mttc0_tcschefback();
5179 gen_mtc0(env, ctx, rd, sel);
5186 gen_op_mttc0_entryhi();
5189 gen_mtc0(env, ctx, rd, sel);
5195 gen_op_mttc0_status();
5198 gen_mtc0(env, ctx, rd, sel);
5204 gen_op_mttc0_debug();
5207 gen_mtc0(env, ctx, rd, sel);
5212 gen_mtc0(env, ctx, rd, sel);
5214 } else switch (sel) {
5215 /* GPR registers. */
5219 /* Auxiliary CPU registers */
5265 /* Floating point (COP1). */
5267 /* XXX: For now we support only a single FPU context. */
5270 GEN_STORE_FTN_FREG(rd, WT0);
5273 GEN_STORE_FTN_FREG(rd, WTH0);
5277 /* XXX: For now we support only a single FPU context. */
5280 /* COP2: Not implemented. */
5287 #if defined MIPS_DEBUG_DISAS
5288 if (loglevel & CPU_LOG_TB_IN_ASM) {
5289 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5296 #if defined MIPS_DEBUG_DISAS
5297 if (loglevel & CPU_LOG_TB_IN_ASM) {
5298 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5302 generate_exception(ctx, EXCP_RI);
5305 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5307 const char *opn = "ldst";
5315 gen_mfc0(env, ctx, rd, ctx->opcode & 0x7);
5316 gen_store_gpr(cpu_T[0], rt);
5320 gen_load_gpr(cpu_T[0], rt);
5321 save_cpu_state(ctx, 1);
5322 gen_mtc0(env, ctx, rd, ctx->opcode & 0x7);
5325 #if defined(TARGET_MIPS64)
5327 check_insn(env, ctx, ISA_MIPS3);
5332 gen_dmfc0(env, ctx, rd, ctx->opcode & 0x7);
5333 gen_store_gpr(cpu_T[0], rt);
5337 check_insn(env, ctx, ISA_MIPS3);
5338 gen_load_gpr(cpu_T[0], rt);
5339 save_cpu_state(ctx, 1);
5340 gen_dmtc0(env, ctx, rd, ctx->opcode & 0x7);
5345 check_insn(env, ctx, ASE_MT);
5350 gen_mftr(env, ctx, rt, (ctx->opcode >> 5) & 1,
5351 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5352 gen_store_gpr(cpu_T[0], rd);
5356 check_insn(env, ctx, ASE_MT);
5357 gen_load_gpr(cpu_T[0], rt);
5358 gen_mttr(env, ctx, rd, (ctx->opcode >> 5) & 1,
5359 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5364 if (!env->tlb->do_tlbwi)
5370 if (!env->tlb->do_tlbwr)
5376 if (!env->tlb->do_tlbp)
5382 if (!env->tlb->do_tlbr)
5388 check_insn(env, ctx, ISA_MIPS2);
5389 save_cpu_state(ctx, 1);
5391 ctx->bstate = BS_EXCP;
5395 check_insn(env, ctx, ISA_MIPS32);
5396 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5398 generate_exception(ctx, EXCP_RI);
5400 save_cpu_state(ctx, 1);
5402 ctx->bstate = BS_EXCP;
5407 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5408 /* If we get an exception, we want to restart at next instruction */
5410 save_cpu_state(ctx, 1);
5413 ctx->bstate = BS_EXCP;
5418 generate_exception(ctx, EXCP_RI);
5421 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5424 /* CP1 Branches (before delay slot) */
5425 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5426 int32_t cc, int32_t offset)
5428 target_ulong btarget;
5429 const char *opn = "cp1 cond branch";
5432 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5434 btarget = ctx->pc + 4 + offset;
5453 ctx->hflags |= MIPS_HFLAG_BL;
5454 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
5457 gen_op_bc1any2f(cc);
5461 gen_op_bc1any2t(cc);
5465 gen_op_bc1any4f(cc);
5469 gen_op_bc1any4t(cc);
5472 ctx->hflags |= MIPS_HFLAG_BC;
5473 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
5477 generate_exception (ctx, EXCP_RI);
5480 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5481 ctx->hflags, btarget);
5482 ctx->btarget = btarget;
5485 /* Coprocessor 1 (FPU) */
5487 #define FOP(func, fmt) (((fmt) << 21) | (func))
5489 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5491 const char *opn = "cp1 move";
5495 GEN_LOAD_FREG_FTN(WT0, fs);
5497 gen_store_gpr(cpu_T[0], rt);
5501 gen_load_gpr(cpu_T[0], rt);
5503 GEN_STORE_FTN_FREG(fs, WT0);
5508 gen_store_gpr(cpu_T[0], rt);
5512 gen_load_gpr(cpu_T[0], rt);
5517 GEN_LOAD_FREG_FTN(DT0, fs);
5519 gen_store_gpr(cpu_T[0], rt);
5523 gen_load_gpr(cpu_T[0], rt);
5525 GEN_STORE_FTN_FREG(fs, DT0);
5529 GEN_LOAD_FREG_FTN(WTH0, fs);
5531 gen_store_gpr(cpu_T[0], rt);
5535 gen_load_gpr(cpu_T[0], rt);
5537 GEN_STORE_FTN_FREG(fs, WTH0);
5542 generate_exception (ctx, EXCP_RI);
5545 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5548 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5550 int l1 = gen_new_label();
5555 ccbit = 1 << (24 + cc);
5563 gen_load_gpr(cpu_T[0], rd);
5564 gen_load_gpr(cpu_T[1], rs);
5566 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
5567 TCGv r_tmp = new_tmp();
5569 tcg_gen_ld_ptr(r_ptr, cpu_env, offsetof(CPUState, fpu));
5570 tcg_gen_ld_i32(r_tmp, r_ptr, offsetof(CPUMIPSFPUContext, fcr31));
5571 tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
5572 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5575 tcg_gen_mov_tl(cpu_T[0], cpu_T[1]);
5578 gen_store_gpr(cpu_T[0], rd);
5581 #define GEN_MOVCF(fmt) \
5582 static void glue(gen_movcf_, fmt) (DisasContext *ctx, int cc, int tf) \
5587 ccbit = 1 << (24 + cc); \
5591 glue(gen_op_float_movf_, fmt)(ccbit); \
5593 glue(gen_op_float_movt_, fmt)(ccbit); \
5600 static void gen_farith (DisasContext *ctx, uint32_t op1,
5601 int ft, int fs, int fd, int cc)
5603 const char *opn = "farith";
5604 const char *condnames[] = {
5622 const char *condnames_abs[] = {
5640 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5641 uint32_t func = ctx->opcode & 0x3f;
5643 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5645 GEN_LOAD_FREG_FTN(WT0, fs);
5646 GEN_LOAD_FREG_FTN(WT1, ft);
5647 gen_op_float_add_s();
5648 GEN_STORE_FTN_FREG(fd, WT2);
5653 GEN_LOAD_FREG_FTN(WT0, fs);
5654 GEN_LOAD_FREG_FTN(WT1, ft);
5655 gen_op_float_sub_s();
5656 GEN_STORE_FTN_FREG(fd, WT2);
5661 GEN_LOAD_FREG_FTN(WT0, fs);
5662 GEN_LOAD_FREG_FTN(WT1, ft);
5663 gen_op_float_mul_s();
5664 GEN_STORE_FTN_FREG(fd, WT2);
5669 GEN_LOAD_FREG_FTN(WT0, fs);
5670 GEN_LOAD_FREG_FTN(WT1, ft);
5671 gen_op_float_div_s();
5672 GEN_STORE_FTN_FREG(fd, WT2);
5677 GEN_LOAD_FREG_FTN(WT0, fs);
5678 gen_op_float_sqrt_s();
5679 GEN_STORE_FTN_FREG(fd, WT2);
5683 GEN_LOAD_FREG_FTN(WT0, fs);
5684 gen_op_float_abs_s();
5685 GEN_STORE_FTN_FREG(fd, WT2);
5689 GEN_LOAD_FREG_FTN(WT0, fs);
5690 gen_op_float_mov_s();
5691 GEN_STORE_FTN_FREG(fd, WT2);
5695 GEN_LOAD_FREG_FTN(WT0, fs);
5696 gen_op_float_chs_s();
5697 GEN_STORE_FTN_FREG(fd, WT2);
5701 check_cp1_64bitmode(ctx);
5702 GEN_LOAD_FREG_FTN(WT0, fs);
5703 gen_op_float_roundl_s();
5704 GEN_STORE_FTN_FREG(fd, DT2);
5708 check_cp1_64bitmode(ctx);
5709 GEN_LOAD_FREG_FTN(WT0, fs);
5710 gen_op_float_truncl_s();
5711 GEN_STORE_FTN_FREG(fd, DT2);
5715 check_cp1_64bitmode(ctx);
5716 GEN_LOAD_FREG_FTN(WT0, fs);
5717 gen_op_float_ceill_s();
5718 GEN_STORE_FTN_FREG(fd, DT2);
5722 check_cp1_64bitmode(ctx);
5723 GEN_LOAD_FREG_FTN(WT0, fs);
5724 gen_op_float_floorl_s();
5725 GEN_STORE_FTN_FREG(fd, DT2);
5729 GEN_LOAD_FREG_FTN(WT0, fs);
5730 gen_op_float_roundw_s();
5731 GEN_STORE_FTN_FREG(fd, WT2);
5735 GEN_LOAD_FREG_FTN(WT0, fs);
5736 gen_op_float_truncw_s();
5737 GEN_STORE_FTN_FREG(fd, WT2);
5741 GEN_LOAD_FREG_FTN(WT0, fs);
5742 gen_op_float_ceilw_s();
5743 GEN_STORE_FTN_FREG(fd, WT2);
5747 GEN_LOAD_FREG_FTN(WT0, fs);
5748 gen_op_float_floorw_s();
5749 GEN_STORE_FTN_FREG(fd, WT2);
5753 gen_load_gpr(cpu_T[0], ft);
5754 GEN_LOAD_FREG_FTN(WT0, fs);
5755 GEN_LOAD_FREG_FTN(WT2, fd);
5756 gen_movcf_s(ctx, (ft >> 2) & 0x7, ft & 0x1);
5757 GEN_STORE_FTN_FREG(fd, WT2);
5761 gen_load_gpr(cpu_T[0], ft);
5762 GEN_LOAD_FREG_FTN(WT0, fs);
5763 GEN_LOAD_FREG_FTN(WT2, fd);
5764 gen_op_float_movz_s();
5765 GEN_STORE_FTN_FREG(fd, WT2);
5769 gen_load_gpr(cpu_T[0], ft);
5770 GEN_LOAD_FREG_FTN(WT0, fs);
5771 GEN_LOAD_FREG_FTN(WT2, fd);
5772 gen_op_float_movn_s();
5773 GEN_STORE_FTN_FREG(fd, WT2);
5778 GEN_LOAD_FREG_FTN(WT0, fs);
5779 gen_op_float_recip_s();
5780 GEN_STORE_FTN_FREG(fd, WT2);
5785 GEN_LOAD_FREG_FTN(WT0, fs);
5786 gen_op_float_rsqrt_s();
5787 GEN_STORE_FTN_FREG(fd, WT2);
5791 check_cp1_64bitmode(ctx);
5792 GEN_LOAD_FREG_FTN(WT0, fs);
5793 GEN_LOAD_FREG_FTN(WT2, fd);
5794 gen_op_float_recip2_s();
5795 GEN_STORE_FTN_FREG(fd, WT2);
5799 check_cp1_64bitmode(ctx);
5800 GEN_LOAD_FREG_FTN(WT0, fs);
5801 gen_op_float_recip1_s();
5802 GEN_STORE_FTN_FREG(fd, WT2);
5806 check_cp1_64bitmode(ctx);
5807 GEN_LOAD_FREG_FTN(WT0, fs);
5808 gen_op_float_rsqrt1_s();
5809 GEN_STORE_FTN_FREG(fd, WT2);
5813 check_cp1_64bitmode(ctx);
5814 GEN_LOAD_FREG_FTN(WT0, fs);
5815 GEN_LOAD_FREG_FTN(WT2, ft);
5816 gen_op_float_rsqrt2_s();
5817 GEN_STORE_FTN_FREG(fd, WT2);
5821 check_cp1_registers(ctx, fd);
5822 GEN_LOAD_FREG_FTN(WT0, fs);
5823 gen_op_float_cvtd_s();
5824 GEN_STORE_FTN_FREG(fd, DT2);
5828 GEN_LOAD_FREG_FTN(WT0, fs);
5829 gen_op_float_cvtw_s();
5830 GEN_STORE_FTN_FREG(fd, WT2);
5834 check_cp1_64bitmode(ctx);
5835 GEN_LOAD_FREG_FTN(WT0, fs);
5836 gen_op_float_cvtl_s();
5837 GEN_STORE_FTN_FREG(fd, DT2);
5841 check_cp1_64bitmode(ctx);
5842 GEN_LOAD_FREG_FTN(WT1, fs);
5843 GEN_LOAD_FREG_FTN(WT0, ft);
5844 gen_op_float_cvtps_s();
5845 GEN_STORE_FTN_FREG(fd, DT2);
5864 GEN_LOAD_FREG_FTN(WT0, fs);
5865 GEN_LOAD_FREG_FTN(WT1, ft);
5866 if (ctx->opcode & (1 << 6)) {
5868 gen_cmpabs_s(func-48, cc);
5869 opn = condnames_abs[func-48];
5871 gen_cmp_s(func-48, cc);
5872 opn = condnames[func-48];
5876 check_cp1_registers(ctx, fs | ft | fd);
5877 GEN_LOAD_FREG_FTN(DT0, fs);
5878 GEN_LOAD_FREG_FTN(DT1, ft);
5879 gen_op_float_add_d();
5880 GEN_STORE_FTN_FREG(fd, DT2);
5885 check_cp1_registers(ctx, fs | ft | fd);
5886 GEN_LOAD_FREG_FTN(DT0, fs);
5887 GEN_LOAD_FREG_FTN(DT1, ft);
5888 gen_op_float_sub_d();
5889 GEN_STORE_FTN_FREG(fd, DT2);
5894 check_cp1_registers(ctx, fs | ft | fd);
5895 GEN_LOAD_FREG_FTN(DT0, fs);
5896 GEN_LOAD_FREG_FTN(DT1, ft);
5897 gen_op_float_mul_d();
5898 GEN_STORE_FTN_FREG(fd, DT2);
5903 check_cp1_registers(ctx, fs | ft | fd);
5904 GEN_LOAD_FREG_FTN(DT0, fs);
5905 GEN_LOAD_FREG_FTN(DT1, ft);
5906 gen_op_float_div_d();
5907 GEN_STORE_FTN_FREG(fd, DT2);
5912 check_cp1_registers(ctx, fs | fd);
5913 GEN_LOAD_FREG_FTN(DT0, fs);
5914 gen_op_float_sqrt_d();
5915 GEN_STORE_FTN_FREG(fd, DT2);
5919 check_cp1_registers(ctx, fs | fd);
5920 GEN_LOAD_FREG_FTN(DT0, fs);
5921 gen_op_float_abs_d();
5922 GEN_STORE_FTN_FREG(fd, DT2);
5926 check_cp1_registers(ctx, fs | fd);
5927 GEN_LOAD_FREG_FTN(DT0, fs);
5928 gen_op_float_mov_d();
5929 GEN_STORE_FTN_FREG(fd, DT2);
5933 check_cp1_registers(ctx, fs | fd);
5934 GEN_LOAD_FREG_FTN(DT0, fs);
5935 gen_op_float_chs_d();
5936 GEN_STORE_FTN_FREG(fd, DT2);
5940 check_cp1_64bitmode(ctx);
5941 GEN_LOAD_FREG_FTN(DT0, fs);
5942 gen_op_float_roundl_d();
5943 GEN_STORE_FTN_FREG(fd, DT2);
5947 check_cp1_64bitmode(ctx);
5948 GEN_LOAD_FREG_FTN(DT0, fs);
5949 gen_op_float_truncl_d();
5950 GEN_STORE_FTN_FREG(fd, DT2);
5954 check_cp1_64bitmode(ctx);
5955 GEN_LOAD_FREG_FTN(DT0, fs);
5956 gen_op_float_ceill_d();
5957 GEN_STORE_FTN_FREG(fd, DT2);
5961 check_cp1_64bitmode(ctx);
5962 GEN_LOAD_FREG_FTN(DT0, fs);
5963 gen_op_float_floorl_d();
5964 GEN_STORE_FTN_FREG(fd, DT2);
5968 check_cp1_registers(ctx, fs);
5969 GEN_LOAD_FREG_FTN(DT0, fs);
5970 gen_op_float_roundw_d();
5971 GEN_STORE_FTN_FREG(fd, WT2);
5975 check_cp1_registers(ctx, fs);
5976 GEN_LOAD_FREG_FTN(DT0, fs);
5977 gen_op_float_truncw_d();
5978 GEN_STORE_FTN_FREG(fd, WT2);
5982 check_cp1_registers(ctx, fs);
5983 GEN_LOAD_FREG_FTN(DT0, fs);
5984 gen_op_float_ceilw_d();
5985 GEN_STORE_FTN_FREG(fd, WT2);
5989 check_cp1_registers(ctx, fs);
5990 GEN_LOAD_FREG_FTN(DT0, fs);
5991 gen_op_float_floorw_d();
5992 GEN_STORE_FTN_FREG(fd, WT2);
5996 gen_load_gpr(cpu_T[0], ft);
5997 GEN_LOAD_FREG_FTN(DT0, fs);
5998 GEN_LOAD_FREG_FTN(DT2, fd);
5999 gen_movcf_d(ctx, (ft >> 2) & 0x7, ft & 0x1);
6000 GEN_STORE_FTN_FREG(fd, DT2);
6004 gen_load_gpr(cpu_T[0], ft);
6005 GEN_LOAD_FREG_FTN(DT0, fs);
6006 GEN_LOAD_FREG_FTN(DT2, fd);
6007 gen_op_float_movz_d();
6008 GEN_STORE_FTN_FREG(fd, DT2);
6012 gen_load_gpr(cpu_T[0], ft);
6013 GEN_LOAD_FREG_FTN(DT0, fs);
6014 GEN_LOAD_FREG_FTN(DT2, fd);
6015 gen_op_float_movn_d();
6016 GEN_STORE_FTN_FREG(fd, DT2);
6020 check_cp1_64bitmode(ctx);
6021 GEN_LOAD_FREG_FTN(DT0, fs);
6022 gen_op_float_recip_d();
6023 GEN_STORE_FTN_FREG(fd, DT2);
6027 check_cp1_64bitmode(ctx);
6028 GEN_LOAD_FREG_FTN(DT0, fs);
6029 gen_op_float_rsqrt_d();
6030 GEN_STORE_FTN_FREG(fd, DT2);
6034 check_cp1_64bitmode(ctx);
6035 GEN_LOAD_FREG_FTN(DT0, fs);
6036 GEN_LOAD_FREG_FTN(DT2, ft);
6037 gen_op_float_recip2_d();
6038 GEN_STORE_FTN_FREG(fd, DT2);
6042 check_cp1_64bitmode(ctx);
6043 GEN_LOAD_FREG_FTN(DT0, fs);
6044 gen_op_float_recip1_d();
6045 GEN_STORE_FTN_FREG(fd, DT2);
6049 check_cp1_64bitmode(ctx);
6050 GEN_LOAD_FREG_FTN(DT0, fs);
6051 gen_op_float_rsqrt1_d();
6052 GEN_STORE_FTN_FREG(fd, DT2);
6056 check_cp1_64bitmode(ctx);
6057 GEN_LOAD_FREG_FTN(DT0, fs);
6058 GEN_LOAD_FREG_FTN(DT2, ft);
6059 gen_op_float_rsqrt2_d();
6060 GEN_STORE_FTN_FREG(fd, DT2);
6079 GEN_LOAD_FREG_FTN(DT0, fs);
6080 GEN_LOAD_FREG_FTN(DT1, ft);
6081 if (ctx->opcode & (1 << 6)) {
6083 check_cp1_registers(ctx, fs | ft);
6084 gen_cmpabs_d(func-48, cc);
6085 opn = condnames_abs[func-48];
6087 check_cp1_registers(ctx, fs | ft);
6088 gen_cmp_d(func-48, cc);
6089 opn = condnames[func-48];
6093 check_cp1_registers(ctx, fs);
6094 GEN_LOAD_FREG_FTN(DT0, fs);
6095 gen_op_float_cvts_d();
6096 GEN_STORE_FTN_FREG(fd, WT2);
6100 check_cp1_registers(ctx, fs);
6101 GEN_LOAD_FREG_FTN(DT0, fs);
6102 gen_op_float_cvtw_d();
6103 GEN_STORE_FTN_FREG(fd, WT2);
6107 check_cp1_64bitmode(ctx);
6108 GEN_LOAD_FREG_FTN(DT0, fs);
6109 gen_op_float_cvtl_d();
6110 GEN_STORE_FTN_FREG(fd, DT2);
6114 GEN_LOAD_FREG_FTN(WT0, fs);
6115 gen_op_float_cvts_w();
6116 GEN_STORE_FTN_FREG(fd, WT2);
6120 check_cp1_registers(ctx, fd);
6121 GEN_LOAD_FREG_FTN(WT0, fs);
6122 gen_op_float_cvtd_w();
6123 GEN_STORE_FTN_FREG(fd, DT2);
6127 check_cp1_64bitmode(ctx);
6128 GEN_LOAD_FREG_FTN(DT0, fs);
6129 gen_op_float_cvts_l();
6130 GEN_STORE_FTN_FREG(fd, WT2);
6134 check_cp1_64bitmode(ctx);
6135 GEN_LOAD_FREG_FTN(DT0, fs);
6136 gen_op_float_cvtd_l();
6137 GEN_STORE_FTN_FREG(fd, DT2);
6141 check_cp1_64bitmode(ctx);
6142 GEN_LOAD_FREG_FTN(WT0, fs);
6143 GEN_LOAD_FREG_FTN(WTH0, fs);
6144 gen_op_float_cvtps_pw();
6145 GEN_STORE_FTN_FREG(fd, WT2);
6146 GEN_STORE_FTN_FREG(fd, WTH2);
6150 check_cp1_64bitmode(ctx);
6151 GEN_LOAD_FREG_FTN(WT0, fs);
6152 GEN_LOAD_FREG_FTN(WTH0, fs);
6153 GEN_LOAD_FREG_FTN(WT1, ft);
6154 GEN_LOAD_FREG_FTN(WTH1, ft);
6155 gen_op_float_add_ps();
6156 GEN_STORE_FTN_FREG(fd, WT2);
6157 GEN_STORE_FTN_FREG(fd, WTH2);
6161 check_cp1_64bitmode(ctx);
6162 GEN_LOAD_FREG_FTN(WT0, fs);
6163 GEN_LOAD_FREG_FTN(WTH0, fs);
6164 GEN_LOAD_FREG_FTN(WT1, ft);
6165 GEN_LOAD_FREG_FTN(WTH1, ft);
6166 gen_op_float_sub_ps();
6167 GEN_STORE_FTN_FREG(fd, WT2);
6168 GEN_STORE_FTN_FREG(fd, WTH2);
6172 check_cp1_64bitmode(ctx);
6173 GEN_LOAD_FREG_FTN(WT0, fs);
6174 GEN_LOAD_FREG_FTN(WTH0, fs);
6175 GEN_LOAD_FREG_FTN(WT1, ft);
6176 GEN_LOAD_FREG_FTN(WTH1, ft);
6177 gen_op_float_mul_ps();
6178 GEN_STORE_FTN_FREG(fd, WT2);
6179 GEN_STORE_FTN_FREG(fd, WTH2);
6183 check_cp1_64bitmode(ctx);
6184 GEN_LOAD_FREG_FTN(WT0, fs);
6185 GEN_LOAD_FREG_FTN(WTH0, fs);
6186 gen_op_float_abs_ps();
6187 GEN_STORE_FTN_FREG(fd, WT2);
6188 GEN_STORE_FTN_FREG(fd, WTH2);
6192 check_cp1_64bitmode(ctx);
6193 GEN_LOAD_FREG_FTN(WT0, fs);
6194 GEN_LOAD_FREG_FTN(WTH0, fs);
6195 gen_op_float_mov_ps();
6196 GEN_STORE_FTN_FREG(fd, WT2);
6197 GEN_STORE_FTN_FREG(fd, WTH2);
6201 check_cp1_64bitmode(ctx);
6202 GEN_LOAD_FREG_FTN(WT0, fs);
6203 GEN_LOAD_FREG_FTN(WTH0, fs);
6204 gen_op_float_chs_ps();
6205 GEN_STORE_FTN_FREG(fd, WT2);
6206 GEN_STORE_FTN_FREG(fd, WTH2);
6210 check_cp1_64bitmode(ctx);
6211 gen_load_gpr(cpu_T[0], ft);
6212 GEN_LOAD_FREG_FTN(WT0, fs);
6213 GEN_LOAD_FREG_FTN(WTH0, fs);
6214 GEN_LOAD_FREG_FTN(WT2, fd);
6215 GEN_LOAD_FREG_FTN(WTH2, fd);
6216 gen_movcf_ps(ctx, (ft >> 2) & 0x7, ft & 0x1);
6217 GEN_STORE_FTN_FREG(fd, WT2);
6218 GEN_STORE_FTN_FREG(fd, WTH2);
6222 check_cp1_64bitmode(ctx);
6223 gen_load_gpr(cpu_T[0], ft);
6224 GEN_LOAD_FREG_FTN(WT0, fs);
6225 GEN_LOAD_FREG_FTN(WTH0, fs);
6226 GEN_LOAD_FREG_FTN(WT2, fd);
6227 GEN_LOAD_FREG_FTN(WTH2, fd);
6228 gen_op_float_movz_ps();
6229 GEN_STORE_FTN_FREG(fd, WT2);
6230 GEN_STORE_FTN_FREG(fd, WTH2);
6234 check_cp1_64bitmode(ctx);
6235 gen_load_gpr(cpu_T[0], ft);
6236 GEN_LOAD_FREG_FTN(WT0, fs);
6237 GEN_LOAD_FREG_FTN(WTH0, fs);
6238 GEN_LOAD_FREG_FTN(WT2, fd);
6239 GEN_LOAD_FREG_FTN(WTH2, fd);
6240 gen_op_float_movn_ps();
6241 GEN_STORE_FTN_FREG(fd, WT2);
6242 GEN_STORE_FTN_FREG(fd, WTH2);
6246 check_cp1_64bitmode(ctx);
6247 GEN_LOAD_FREG_FTN(WT0, ft);
6248 GEN_LOAD_FREG_FTN(WTH0, ft);
6249 GEN_LOAD_FREG_FTN(WT1, fs);
6250 GEN_LOAD_FREG_FTN(WTH1, fs);
6251 gen_op_float_addr_ps();
6252 GEN_STORE_FTN_FREG(fd, WT2);
6253 GEN_STORE_FTN_FREG(fd, WTH2);
6257 check_cp1_64bitmode(ctx);
6258 GEN_LOAD_FREG_FTN(WT0, ft);
6259 GEN_LOAD_FREG_FTN(WTH0, ft);
6260 GEN_LOAD_FREG_FTN(WT1, fs);
6261 GEN_LOAD_FREG_FTN(WTH1, fs);
6262 gen_op_float_mulr_ps();
6263 GEN_STORE_FTN_FREG(fd, WT2);
6264 GEN_STORE_FTN_FREG(fd, WTH2);
6268 check_cp1_64bitmode(ctx);
6269 GEN_LOAD_FREG_FTN(WT0, fs);
6270 GEN_LOAD_FREG_FTN(WTH0, fs);
6271 GEN_LOAD_FREG_FTN(WT2, fd);
6272 GEN_LOAD_FREG_FTN(WTH2, fd);
6273 gen_op_float_recip2_ps();
6274 GEN_STORE_FTN_FREG(fd, WT2);
6275 GEN_STORE_FTN_FREG(fd, WTH2);
6279 check_cp1_64bitmode(ctx);
6280 GEN_LOAD_FREG_FTN(WT0, fs);
6281 GEN_LOAD_FREG_FTN(WTH0, fs);
6282 gen_op_float_recip1_ps();
6283 GEN_STORE_FTN_FREG(fd, WT2);
6284 GEN_STORE_FTN_FREG(fd, WTH2);
6288 check_cp1_64bitmode(ctx);
6289 GEN_LOAD_FREG_FTN(WT0, fs);
6290 GEN_LOAD_FREG_FTN(WTH0, fs);
6291 gen_op_float_rsqrt1_ps();
6292 GEN_STORE_FTN_FREG(fd, WT2);
6293 GEN_STORE_FTN_FREG(fd, WTH2);
6297 check_cp1_64bitmode(ctx);
6298 GEN_LOAD_FREG_FTN(WT0, fs);
6299 GEN_LOAD_FREG_FTN(WTH0, fs);
6300 GEN_LOAD_FREG_FTN(WT2, ft);
6301 GEN_LOAD_FREG_FTN(WTH2, ft);
6302 gen_op_float_rsqrt2_ps();
6303 GEN_STORE_FTN_FREG(fd, WT2);
6304 GEN_STORE_FTN_FREG(fd, WTH2);
6308 check_cp1_64bitmode(ctx);
6309 GEN_LOAD_FREG_FTN(WTH0, fs);
6310 gen_op_float_cvts_pu();
6311 GEN_STORE_FTN_FREG(fd, WT2);
6315 check_cp1_64bitmode(ctx);
6316 GEN_LOAD_FREG_FTN(WT0, fs);
6317 GEN_LOAD_FREG_FTN(WTH0, fs);
6318 gen_op_float_cvtpw_ps();
6319 GEN_STORE_FTN_FREG(fd, WT2);
6320 GEN_STORE_FTN_FREG(fd, WTH2);
6324 check_cp1_64bitmode(ctx);
6325 GEN_LOAD_FREG_FTN(WT0, fs);
6326 gen_op_float_cvts_pl();
6327 GEN_STORE_FTN_FREG(fd, WT2);
6331 check_cp1_64bitmode(ctx);
6332 GEN_LOAD_FREG_FTN(WT0, fs);
6333 GEN_LOAD_FREG_FTN(WT1, ft);
6334 gen_op_float_pll_ps();
6335 GEN_STORE_FTN_FREG(fd, DT2);
6339 check_cp1_64bitmode(ctx);
6340 GEN_LOAD_FREG_FTN(WT0, fs);
6341 GEN_LOAD_FREG_FTN(WTH1, ft);
6342 gen_op_float_plu_ps();
6343 GEN_STORE_FTN_FREG(fd, DT2);
6347 check_cp1_64bitmode(ctx);
6348 GEN_LOAD_FREG_FTN(WTH0, fs);
6349 GEN_LOAD_FREG_FTN(WT1, ft);
6350 gen_op_float_pul_ps();
6351 GEN_STORE_FTN_FREG(fd, DT2);
6355 check_cp1_64bitmode(ctx);
6356 GEN_LOAD_FREG_FTN(WTH0, fs);
6357 GEN_LOAD_FREG_FTN(WTH1, ft);
6358 gen_op_float_puu_ps();
6359 GEN_STORE_FTN_FREG(fd, DT2);
6378 check_cp1_64bitmode(ctx);
6379 GEN_LOAD_FREG_FTN(WT0, fs);
6380 GEN_LOAD_FREG_FTN(WTH0, fs);
6381 GEN_LOAD_FREG_FTN(WT1, ft);
6382 GEN_LOAD_FREG_FTN(WTH1, ft);
6383 if (ctx->opcode & (1 << 6)) {
6384 gen_cmpabs_ps(func-48, cc);
6385 opn = condnames_abs[func-48];
6387 gen_cmp_ps(func-48, cc);
6388 opn = condnames[func-48];
6393 generate_exception (ctx, EXCP_RI);
6398 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
6401 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
6404 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
6409 /* Coprocessor 3 (FPU) */
6410 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
6411 int fd, int fs, int base, int index)
6413 const char *opn = "extended float load/store";
6417 gen_load_gpr(cpu_T[0], index);
6418 } else if (index == 0) {
6419 gen_load_gpr(cpu_T[0], base);
6421 gen_load_gpr(cpu_T[0], base);
6422 gen_load_gpr(cpu_T[1], index);
6425 /* Don't do NOP if destination is zero: we must perform the actual
6431 GEN_STORE_FTN_FREG(fd, WT0);
6436 check_cp1_registers(ctx, fd);
6438 GEN_STORE_FTN_FREG(fd, DT0);
6442 check_cp1_64bitmode(ctx);
6444 GEN_STORE_FTN_FREG(fd, DT0);
6449 GEN_LOAD_FREG_FTN(WT0, fs);
6456 check_cp1_registers(ctx, fs);
6457 GEN_LOAD_FREG_FTN(DT0, fs);
6463 check_cp1_64bitmode(ctx);
6464 GEN_LOAD_FREG_FTN(DT0, fs);
6471 generate_exception(ctx, EXCP_RI);
6474 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
6475 regnames[index], regnames[base]);
6478 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
6479 int fd, int fr, int fs, int ft)
6481 const char *opn = "flt3_arith";
6485 check_cp1_64bitmode(ctx);
6486 gen_load_gpr(cpu_T[0], fr);
6487 GEN_LOAD_FREG_FTN(DT0, fs);
6488 GEN_LOAD_FREG_FTN(DT1, ft);
6489 gen_op_float_alnv_ps();
6490 GEN_STORE_FTN_FREG(fd, DT2);
6495 GEN_LOAD_FREG_FTN(WT0, fs);
6496 GEN_LOAD_FREG_FTN(WT1, ft);
6497 GEN_LOAD_FREG_FTN(WT2, fr);
6498 gen_op_float_muladd_s();
6499 GEN_STORE_FTN_FREG(fd, WT2);
6504 check_cp1_registers(ctx, fd | fs | ft | fr);
6505 GEN_LOAD_FREG_FTN(DT0, fs);
6506 GEN_LOAD_FREG_FTN(DT1, ft);
6507 GEN_LOAD_FREG_FTN(DT2, fr);
6508 gen_op_float_muladd_d();
6509 GEN_STORE_FTN_FREG(fd, DT2);
6513 check_cp1_64bitmode(ctx);
6514 GEN_LOAD_FREG_FTN(WT0, fs);
6515 GEN_LOAD_FREG_FTN(WTH0, fs);
6516 GEN_LOAD_FREG_FTN(WT1, ft);
6517 GEN_LOAD_FREG_FTN(WTH1, ft);
6518 GEN_LOAD_FREG_FTN(WT2, fr);
6519 GEN_LOAD_FREG_FTN(WTH2, fr);
6520 gen_op_float_muladd_ps();
6521 GEN_STORE_FTN_FREG(fd, WT2);
6522 GEN_STORE_FTN_FREG(fd, WTH2);
6527 GEN_LOAD_FREG_FTN(WT0, fs);
6528 GEN_LOAD_FREG_FTN(WT1, ft);
6529 GEN_LOAD_FREG_FTN(WT2, fr);
6530 gen_op_float_mulsub_s();
6531 GEN_STORE_FTN_FREG(fd, WT2);
6536 check_cp1_registers(ctx, fd | fs | ft | fr);
6537 GEN_LOAD_FREG_FTN(DT0, fs);
6538 GEN_LOAD_FREG_FTN(DT1, ft);
6539 GEN_LOAD_FREG_FTN(DT2, fr);
6540 gen_op_float_mulsub_d();
6541 GEN_STORE_FTN_FREG(fd, DT2);
6545 check_cp1_64bitmode(ctx);
6546 GEN_LOAD_FREG_FTN(WT0, fs);
6547 GEN_LOAD_FREG_FTN(WTH0, fs);
6548 GEN_LOAD_FREG_FTN(WT1, ft);
6549 GEN_LOAD_FREG_FTN(WTH1, ft);
6550 GEN_LOAD_FREG_FTN(WT2, fr);
6551 GEN_LOAD_FREG_FTN(WTH2, fr);
6552 gen_op_float_mulsub_ps();
6553 GEN_STORE_FTN_FREG(fd, WT2);
6554 GEN_STORE_FTN_FREG(fd, WTH2);
6559 GEN_LOAD_FREG_FTN(WT0, fs);
6560 GEN_LOAD_FREG_FTN(WT1, ft);
6561 GEN_LOAD_FREG_FTN(WT2, fr);
6562 gen_op_float_nmuladd_s();
6563 GEN_STORE_FTN_FREG(fd, WT2);
6568 check_cp1_registers(ctx, fd | fs | ft | fr);
6569 GEN_LOAD_FREG_FTN(DT0, fs);
6570 GEN_LOAD_FREG_FTN(DT1, ft);
6571 GEN_LOAD_FREG_FTN(DT2, fr);
6572 gen_op_float_nmuladd_d();
6573 GEN_STORE_FTN_FREG(fd, DT2);
6577 check_cp1_64bitmode(ctx);
6578 GEN_LOAD_FREG_FTN(WT0, fs);
6579 GEN_LOAD_FREG_FTN(WTH0, fs);
6580 GEN_LOAD_FREG_FTN(WT1, ft);
6581 GEN_LOAD_FREG_FTN(WTH1, ft);
6582 GEN_LOAD_FREG_FTN(WT2, fr);
6583 GEN_LOAD_FREG_FTN(WTH2, fr);
6584 gen_op_float_nmuladd_ps();
6585 GEN_STORE_FTN_FREG(fd, WT2);
6586 GEN_STORE_FTN_FREG(fd, WTH2);
6591 GEN_LOAD_FREG_FTN(WT0, fs);
6592 GEN_LOAD_FREG_FTN(WT1, ft);
6593 GEN_LOAD_FREG_FTN(WT2, fr);
6594 gen_op_float_nmulsub_s();
6595 GEN_STORE_FTN_FREG(fd, WT2);
6600 check_cp1_registers(ctx, fd | fs | ft | fr);
6601 GEN_LOAD_FREG_FTN(DT0, fs);
6602 GEN_LOAD_FREG_FTN(DT1, ft);
6603 GEN_LOAD_FREG_FTN(DT2, fr);
6604 gen_op_float_nmulsub_d();
6605 GEN_STORE_FTN_FREG(fd, DT2);
6609 check_cp1_64bitmode(ctx);
6610 GEN_LOAD_FREG_FTN(WT0, fs);
6611 GEN_LOAD_FREG_FTN(WTH0, fs);
6612 GEN_LOAD_FREG_FTN(WT1, ft);
6613 GEN_LOAD_FREG_FTN(WTH1, ft);
6614 GEN_LOAD_FREG_FTN(WT2, fr);
6615 GEN_LOAD_FREG_FTN(WTH2, fr);
6616 gen_op_float_nmulsub_ps();
6617 GEN_STORE_FTN_FREG(fd, WT2);
6618 GEN_STORE_FTN_FREG(fd, WTH2);
6623 generate_exception (ctx, EXCP_RI);
6626 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
6627 fregnames[fs], fregnames[ft]);
6630 /* ISA extensions (ASEs) */
6631 /* MIPS16 extension to MIPS32 */
6632 /* SmartMIPS extension to MIPS32 */
6634 #if defined(TARGET_MIPS64)
6636 /* MDMX extension to MIPS64 */
6640 static void decode_opc (CPUState *env, DisasContext *ctx)
6644 uint32_t op, op1, op2;
6647 /* make sure instructions are on a word boundary */
6648 if (ctx->pc & 0x3) {
6649 env->CP0_BadVAddr = ctx->pc;
6650 generate_exception(ctx, EXCP_AdEL);
6654 /* Handle blikely not taken case */
6655 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
6656 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
6657 int l1 = gen_new_label();
6659 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
6660 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
6661 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
6662 gen_op_save_state(ctx->hflags & ~MIPS_HFLAG_BMASK);
6663 gen_goto_tb(ctx, 1, ctx->pc + 4);
6666 op = MASK_OP_MAJOR(ctx->opcode);
6667 rs = (ctx->opcode >> 21) & 0x1f;
6668 rt = (ctx->opcode >> 16) & 0x1f;
6669 rd = (ctx->opcode >> 11) & 0x1f;
6670 sa = (ctx->opcode >> 6) & 0x1f;
6671 imm = (int16_t)ctx->opcode;
6674 op1 = MASK_SPECIAL(ctx->opcode);
6676 case OPC_SLL: /* Arithmetic with immediate */
6677 case OPC_SRL ... OPC_SRA:
6678 gen_arith_imm(env, ctx, op1, rd, rt, sa);
6680 case OPC_MOVZ ... OPC_MOVN:
6681 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
6682 case OPC_SLLV: /* Arithmetic */
6683 case OPC_SRLV ... OPC_SRAV:
6684 case OPC_ADD ... OPC_NOR:
6685 case OPC_SLT ... OPC_SLTU:
6686 gen_arith(env, ctx, op1, rd, rs, rt);
6688 case OPC_MULT ... OPC_DIVU:
6690 check_insn(env, ctx, INSN_VR54XX);
6691 op1 = MASK_MUL_VR54XX(ctx->opcode);
6692 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
6694 gen_muldiv(ctx, op1, rs, rt);
6696 case OPC_JR ... OPC_JALR:
6697 gen_compute_branch(ctx, op1, rs, rd, sa);
6699 case OPC_TGE ... OPC_TEQ: /* Traps */
6701 gen_trap(ctx, op1, rs, rt, -1);
6703 case OPC_MFHI: /* Move from HI/LO */
6705 gen_HILO(ctx, op1, rd);
6708 case OPC_MTLO: /* Move to HI/LO */
6709 gen_HILO(ctx, op1, rs);
6711 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
6712 #ifdef MIPS_STRICT_STANDARD
6713 MIPS_INVAL("PMON / selsl");
6714 generate_exception(ctx, EXCP_RI);
6720 generate_exception(ctx, EXCP_SYSCALL);
6723 generate_exception(ctx, EXCP_BREAK);
6726 #ifdef MIPS_STRICT_STANDARD
6728 generate_exception(ctx, EXCP_RI);
6730 /* Implemented as RI exception for now. */
6731 MIPS_INVAL("spim (unofficial)");
6732 generate_exception(ctx, EXCP_RI);
6740 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
6741 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
6742 save_cpu_state(ctx, 1);
6743 check_cp1_enabled(ctx);
6744 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
6745 (ctx->opcode >> 16) & 1);
6747 generate_exception_err(ctx, EXCP_CpU, 1);
6751 #if defined(TARGET_MIPS64)
6752 /* MIPS64 specific opcodes */
6754 case OPC_DSRL ... OPC_DSRA:
6756 case OPC_DSRL32 ... OPC_DSRA32:
6757 check_insn(env, ctx, ISA_MIPS3);
6759 gen_arith_imm(env, ctx, op1, rd, rt, sa);
6762 case OPC_DSRLV ... OPC_DSRAV:
6763 case OPC_DADD ... OPC_DSUBU:
6764 check_insn(env, ctx, ISA_MIPS3);
6766 gen_arith(env, ctx, op1, rd, rs, rt);
6768 case OPC_DMULT ... OPC_DDIVU:
6769 check_insn(env, ctx, ISA_MIPS3);
6771 gen_muldiv(ctx, op1, rs, rt);
6774 default: /* Invalid */
6775 MIPS_INVAL("special");
6776 generate_exception(ctx, EXCP_RI);
6781 op1 = MASK_SPECIAL2(ctx->opcode);
6783 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
6784 case OPC_MSUB ... OPC_MSUBU:
6785 check_insn(env, ctx, ISA_MIPS32);
6786 gen_muldiv(ctx, op1, rs, rt);
6789 gen_arith(env, ctx, op1, rd, rs, rt);
6791 case OPC_CLZ ... OPC_CLO:
6792 check_insn(env, ctx, ISA_MIPS32);
6793 gen_cl(ctx, op1, rd, rs);
6796 /* XXX: not clear which exception should be raised
6797 * when in debug mode...
6799 check_insn(env, ctx, ISA_MIPS32);
6800 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
6801 generate_exception(ctx, EXCP_DBp);
6803 generate_exception(ctx, EXCP_DBp);
6807 #if defined(TARGET_MIPS64)
6808 case OPC_DCLZ ... OPC_DCLO:
6809 check_insn(env, ctx, ISA_MIPS64);
6811 gen_cl(ctx, op1, rd, rs);
6814 default: /* Invalid */
6815 MIPS_INVAL("special2");
6816 generate_exception(ctx, EXCP_RI);
6821 op1 = MASK_SPECIAL3(ctx->opcode);
6825 check_insn(env, ctx, ISA_MIPS32R2);
6826 gen_bitops(ctx, op1, rt, rs, sa, rd);
6829 check_insn(env, ctx, ISA_MIPS32R2);
6830 op2 = MASK_BSHFL(ctx->opcode);
6833 gen_load_gpr(cpu_T[1], rt);
6837 gen_load_gpr(cpu_T[1], rt);
6838 tcg_gen_ext8s_tl(cpu_T[0], cpu_T[1]);
6841 gen_load_gpr(cpu_T[1], rt);
6842 tcg_gen_ext16s_tl(cpu_T[0], cpu_T[1]);
6844 default: /* Invalid */
6845 MIPS_INVAL("bshfl");
6846 generate_exception(ctx, EXCP_RI);
6849 gen_store_gpr(cpu_T[0], rd);
6852 check_insn(env, ctx, ISA_MIPS32R2);
6855 save_cpu_state(ctx, 1);
6856 gen_op_rdhwr_cpunum();
6859 save_cpu_state(ctx, 1);
6860 gen_op_rdhwr_synci_step();
6863 save_cpu_state(ctx, 1);
6867 save_cpu_state(ctx, 1);
6868 gen_op_rdhwr_ccres();
6871 #if defined (CONFIG_USER_ONLY)
6875 default: /* Invalid */
6876 MIPS_INVAL("rdhwr");
6877 generate_exception(ctx, EXCP_RI);
6880 gen_store_gpr(cpu_T[0], rt);
6883 check_insn(env, ctx, ASE_MT);
6884 gen_load_gpr(cpu_T[0], rt);
6885 gen_load_gpr(cpu_T[1], rs);
6889 check_insn(env, ctx, ASE_MT);
6890 gen_load_gpr(cpu_T[0], rs);
6892 gen_store_gpr(cpu_T[0], rd);
6894 #if defined(TARGET_MIPS64)
6895 case OPC_DEXTM ... OPC_DEXT:
6896 case OPC_DINSM ... OPC_DINS:
6897 check_insn(env, ctx, ISA_MIPS64R2);
6899 gen_bitops(ctx, op1, rt, rs, sa, rd);
6902 check_insn(env, ctx, ISA_MIPS64R2);
6904 op2 = MASK_DBSHFL(ctx->opcode);
6907 gen_load_gpr(cpu_T[1], rt);
6911 gen_load_gpr(cpu_T[1], rt);
6914 default: /* Invalid */
6915 MIPS_INVAL("dbshfl");
6916 generate_exception(ctx, EXCP_RI);
6919 gen_store_gpr(cpu_T[0], rd);
6922 default: /* Invalid */
6923 MIPS_INVAL("special3");
6924 generate_exception(ctx, EXCP_RI);
6929 op1 = MASK_REGIMM(ctx->opcode);
6931 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
6932 case OPC_BLTZAL ... OPC_BGEZALL:
6933 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
6935 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
6937 gen_trap(ctx, op1, rs, -1, imm);
6940 check_insn(env, ctx, ISA_MIPS32R2);
6943 default: /* Invalid */
6944 MIPS_INVAL("regimm");
6945 generate_exception(ctx, EXCP_RI);
6950 check_cp0_enabled(ctx);
6951 op1 = MASK_CP0(ctx->opcode);
6957 #if defined(TARGET_MIPS64)
6961 gen_cp0(env, ctx, op1, rt, rd);
6963 case OPC_C0_FIRST ... OPC_C0_LAST:
6964 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
6967 op2 = MASK_MFMC0(ctx->opcode);
6970 check_insn(env, ctx, ASE_MT);
6974 check_insn(env, ctx, ASE_MT);
6978 check_insn(env, ctx, ASE_MT);
6982 check_insn(env, ctx, ASE_MT);
6986 check_insn(env, ctx, ISA_MIPS32R2);
6987 save_cpu_state(ctx, 1);
6989 /* Stop translation as we may have switched the execution mode */
6990 ctx->bstate = BS_STOP;
6993 check_insn(env, ctx, ISA_MIPS32R2);
6994 save_cpu_state(ctx, 1);
6996 /* Stop translation as we may have switched the execution mode */
6997 ctx->bstate = BS_STOP;
6999 default: /* Invalid */
7000 MIPS_INVAL("mfmc0");
7001 generate_exception(ctx, EXCP_RI);
7004 gen_store_gpr(cpu_T[0], rt);
7007 check_insn(env, ctx, ISA_MIPS32R2);
7008 gen_load_srsgpr(cpu_T[0], rt);
7009 gen_store_gpr(cpu_T[0], rd);
7012 check_insn(env, ctx, ISA_MIPS32R2);
7013 gen_load_gpr(cpu_T[0], rt);
7014 gen_store_srsgpr(cpu_T[0], rd);
7018 generate_exception(ctx, EXCP_RI);
7022 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7023 gen_arith_imm(env, ctx, op, rt, rs, imm);
7025 case OPC_J ... OPC_JAL: /* Jump */
7026 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7027 gen_compute_branch(ctx, op, rs, rt, offset);
7029 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7030 case OPC_BEQL ... OPC_BGTZL:
7031 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7033 case OPC_LB ... OPC_LWR: /* Load and stores */
7034 case OPC_SB ... OPC_SW:
7038 gen_ldst(ctx, op, rt, rs, imm);
7041 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7045 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7049 /* Floating point (COP1). */
7054 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7055 save_cpu_state(ctx, 1);
7056 check_cp1_enabled(ctx);
7057 gen_flt_ldst(ctx, op, rt, rs, imm);
7059 generate_exception_err(ctx, EXCP_CpU, 1);
7064 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7065 save_cpu_state(ctx, 1);
7066 check_cp1_enabled(ctx);
7067 op1 = MASK_CP1(ctx->opcode);
7071 check_insn(env, ctx, ISA_MIPS32R2);
7076 gen_cp1(ctx, op1, rt, rd);
7078 #if defined(TARGET_MIPS64)
7081 check_insn(env, ctx, ISA_MIPS3);
7082 gen_cp1(ctx, op1, rt, rd);
7088 check_insn(env, ctx, ASE_MIPS3D);
7091 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
7092 (rt >> 2) & 0x7, imm << 2);
7099 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
7104 generate_exception (ctx, EXCP_RI);
7108 generate_exception_err(ctx, EXCP_CpU, 1);
7118 /* COP2: Not implemented. */
7119 generate_exception_err(ctx, EXCP_CpU, 2);
7123 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7124 save_cpu_state(ctx, 1);
7125 check_cp1_enabled(ctx);
7126 op1 = MASK_CP3(ctx->opcode);
7134 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
7152 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
7156 generate_exception (ctx, EXCP_RI);
7160 generate_exception_err(ctx, EXCP_CpU, 1);
7164 #if defined(TARGET_MIPS64)
7165 /* MIPS64 opcodes */
7167 case OPC_LDL ... OPC_LDR:
7168 case OPC_SDL ... OPC_SDR:
7173 check_insn(env, ctx, ISA_MIPS3);
7175 gen_ldst(ctx, op, rt, rs, imm);
7177 case OPC_DADDI ... OPC_DADDIU:
7178 check_insn(env, ctx, ISA_MIPS3);
7180 gen_arith_imm(env, ctx, op, rt, rs, imm);
7184 check_insn(env, ctx, ASE_MIPS16);
7185 /* MIPS16: Not implemented. */
7187 check_insn(env, ctx, ASE_MDMX);
7188 /* MDMX: Not implemented. */
7189 default: /* Invalid */
7190 MIPS_INVAL("major opcode");
7191 generate_exception(ctx, EXCP_RI);
7194 if (ctx->hflags & MIPS_HFLAG_BMASK) {
7195 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
7196 /* Branches completion */
7197 ctx->hflags &= ~MIPS_HFLAG_BMASK;
7198 ctx->bstate = BS_BRANCH;
7199 save_cpu_state(ctx, 0);
7202 /* unconditional branch */
7203 MIPS_DEBUG("unconditional branch");
7204 gen_goto_tb(ctx, 0, ctx->btarget);
7207 /* blikely taken case */
7208 MIPS_DEBUG("blikely branch taken");
7209 gen_goto_tb(ctx, 0, ctx->btarget);
7212 /* Conditional branch */
7213 MIPS_DEBUG("conditional branch");
7215 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
7216 int l1 = gen_new_label();
7218 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
7219 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
7220 gen_goto_tb(ctx, 1, ctx->pc + 4);
7222 gen_goto_tb(ctx, 0, ctx->btarget);
7226 /* unconditional branch to register */
7227 MIPS_DEBUG("branch to register");
7232 MIPS_DEBUG("unknown branch");
7238 static always_inline int
7239 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
7243 target_ulong pc_start;
7244 uint16_t *gen_opc_end;
7247 if (search_pc && loglevel)
7248 fprintf (logfile, "search pc %d\n", search_pc);
7251 memset(temps, 0, sizeof(temps));
7254 memset(temps, 0, sizeof(temps));
7257 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
7261 ctx.bstate = BS_NONE;
7262 /* Restore delay slot state from the tb context. */
7263 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
7264 restore_cpu_state(env, &ctx);
7265 #if defined(CONFIG_USER_ONLY)
7266 ctx.mem_idx = MIPS_HFLAG_UM;
7268 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
7271 if (loglevel & CPU_LOG_TB_CPU) {
7272 fprintf(logfile, "------------------------------------------------\n");
7273 /* FIXME: This may print out stale hflags from env... */
7274 cpu_dump_state(env, logfile, fprintf, 0);
7277 #ifdef MIPS_DEBUG_DISAS
7278 if (loglevel & CPU_LOG_TB_IN_ASM)
7279 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
7280 tb, ctx.mem_idx, ctx.hflags);
7282 while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) {
7283 if (env->nb_breakpoints > 0) {
7284 for(j = 0; j < env->nb_breakpoints; j++) {
7285 if (env->breakpoints[j] == ctx.pc) {
7286 save_cpu_state(&ctx, 1);
7287 ctx.bstate = BS_BRANCH;
7289 /* Include the breakpoint location or the tb won't
7290 * be flushed when it must be. */
7292 goto done_generating;
7298 j = gen_opc_ptr - gen_opc_buf;
7302 gen_opc_instr_start[lj++] = 0;
7304 gen_opc_pc[lj] = ctx.pc;
7305 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
7306 gen_opc_instr_start[lj] = 1;
7308 ctx.opcode = ldl_code(ctx.pc);
7309 decode_opc(env, &ctx);
7312 "Internal resource leak before " TARGET_FMT_lx "\n",
7318 if (env->singlestep_enabled)
7321 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
7324 #if defined (MIPS_SINGLE_STEP)
7328 if (env->singlestep_enabled) {
7329 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
7332 switch (ctx.bstate) {
7334 tcg_gen_helper_0_0(do_interrupt_restart);
7335 gen_goto_tb(&ctx, 0, ctx.pc);
7338 save_cpu_state(&ctx, 0);
7339 gen_goto_tb(&ctx, 0, ctx.pc);
7342 tcg_gen_helper_0_0(do_interrupt_restart);
7351 *gen_opc_ptr = INDEX_op_end;
7353 j = gen_opc_ptr - gen_opc_buf;
7356 gen_opc_instr_start[lj++] = 0;
7358 tb->size = ctx.pc - pc_start;
7361 #if defined MIPS_DEBUG_DISAS
7362 if (loglevel & CPU_LOG_TB_IN_ASM)
7363 fprintf(logfile, "\n");
7365 if (loglevel & CPU_LOG_TB_IN_ASM) {
7366 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
7367 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
7368 fprintf(logfile, "\n");
7370 if (loglevel & CPU_LOG_TB_CPU) {
7371 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
7378 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
7380 return gen_intermediate_code_internal(env, tb, 0);
7383 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
7385 return gen_intermediate_code_internal(env, tb, 1);
7388 void fpu_dump_state(CPUState *env, FILE *f,
7389 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
7393 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
7395 #define printfpr(fp) \
7398 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7399 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7400 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7403 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7404 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7405 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7406 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7407 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7412 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7413 env->fpu->fcr0, env->fpu->fcr31, is_fpu64, env->fpu->fp_status,
7414 get_float_exception_flags(&env->fpu->fp_status));
7415 fpu_fprintf(f, "FT0: "); printfpr(&env->fpu->ft0);
7416 fpu_fprintf(f, "FT1: "); printfpr(&env->fpu->ft1);
7417 fpu_fprintf(f, "FT2: "); printfpr(&env->fpu->ft2);
7418 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
7419 fpu_fprintf(f, "%3s: ", fregnames[i]);
7420 printfpr(&env->fpu->fpr[i]);
7426 void dump_fpu (CPUState *env)
7430 "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx
7431 " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx
7433 env->PC[env->current_tc], env->HI[env->current_tc][0],
7434 env->LO[env->current_tc][0], env->hflags, env->btarget,
7436 fpu_dump_state(env, logfile, fprintf, 0);
7440 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7441 /* Debug help: The architecture requires 32bit code to maintain proper
7442 sign-extened values on 64bit machines. */
7444 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
7446 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
7447 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
7452 if (!SIGN_EXT_P(env->PC[env->current_tc]))
7453 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->PC[env->current_tc]);
7454 if (!SIGN_EXT_P(env->HI[env->current_tc][0]))
7455 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->HI[env->current_tc][0]);
7456 if (!SIGN_EXT_P(env->LO[env->current_tc][0]))
7457 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->LO[env->current_tc][0]);
7458 if (!SIGN_EXT_P(env->btarget))
7459 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
7461 for (i = 0; i < 32; i++) {
7462 if (!SIGN_EXT_P(env->gpr[env->current_tc][i]))
7463 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->gpr[env->current_tc][i]);
7466 if (!SIGN_EXT_P(env->CP0_EPC))
7467 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
7468 if (!SIGN_EXT_P(env->CP0_LLAddr))
7469 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
7473 void cpu_dump_state (CPUState *env, FILE *f,
7474 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
7479 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",
7480 env->PC[env->current_tc], env->HI[env->current_tc], env->LO[env->current_tc], env->hflags, env->btarget, env->bcond);
7481 for (i = 0; i < 32; i++) {
7483 cpu_fprintf(f, "GPR%02d:", i);
7484 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->gpr[env->current_tc][i]);
7486 cpu_fprintf(f, "\n");
7489 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
7490 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
7491 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
7492 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
7493 if (env->hflags & MIPS_HFLAG_FPU)
7494 fpu_dump_state(env, f, cpu_fprintf, flags);
7495 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7496 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
7500 static void mips_tcg_init(void)
7504 /* Initialize various static tables. */
7508 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
7509 current_tc_gprs = tcg_global_mem_new(TCG_TYPE_PTR,
7511 offsetof(CPUState, current_tc_gprs),
7513 #if TARGET_LONG_BITS > HOST_LONG_BITS
7514 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
7515 TCG_AREG0, offsetof(CPUState, t0), "T0");
7516 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
7517 TCG_AREG0, offsetof(CPUState, t1), "T1");
7519 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
7520 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
7526 #include "translate_init.c"
7528 CPUMIPSState *cpu_mips_init (const char *cpu_model)
7531 const mips_def_t *def;
7533 def = cpu_mips_find_by_name(cpu_model);
7536 env = qemu_mallocz(sizeof(CPUMIPSState));
7539 env->cpu_model = def;
7542 env->cpu_model_str = cpu_model;
7548 void cpu_reset (CPUMIPSState *env)
7550 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
7555 #if !defined(CONFIG_USER_ONLY)
7556 if (env->hflags & MIPS_HFLAG_BMASK) {
7557 /* If the exception was raised from a delay slot,
7558 * come back to the jump. */
7559 env->CP0_ErrorEPC = env->PC[env->current_tc] - 4;
7561 env->CP0_ErrorEPC = env->PC[env->current_tc];
7563 env->PC[env->current_tc] = (int32_t)0xBFC00000;
7565 /* SMP not implemented */
7566 env->CP0_EBase = 0x80000000;
7567 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
7568 /* vectored interrupts not implemented, timer on int 7,
7569 no performance counters. */
7570 env->CP0_IntCtl = 0xe0000000;
7574 for (i = 0; i < 7; i++) {
7575 env->CP0_WatchLo[i] = 0;
7576 env->CP0_WatchHi[i] = 0x80000000;
7578 env->CP0_WatchLo[7] = 0;
7579 env->CP0_WatchHi[7] = 0;
7581 /* Count register increments in debug mode, EJTAG version 1 */
7582 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
7584 env->exception_index = EXCP_NONE;
7585 #if defined(CONFIG_USER_ONLY)
7586 env->hflags = MIPS_HFLAG_UM;
7587 env->user_mode_only = 1;
7589 env->hflags = MIPS_HFLAG_CP0;
7591 cpu_mips_register(env, env->cpu_model);
7594 void gen_pc_load(CPUState *env, TranslationBlock *tb,
7595 unsigned long searched_pc, int pc_pos, void *puc)
7597 env->PC[env->current_tc] = gen_opc_pc[pc_pos];
7598 env->hflags &= ~MIPS_HFLAG_BMASK;
7599 env->hflags |= gen_opc_hflags[pc_pos];