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, cpu_gpr[32], cpu_PC;
427 static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC], cpu_ACX[MIPS_DSP_ACC];
428 static TCGv cpu_dspctrl, bcond, btarget;
429 static TCGv fpu_fpr32[32], fpu_fpr32h[32], fpu_fpr64[32], fpu_fcr0, fpu_fcr31;
431 #include "gen-icount.h"
433 static inline void tcg_gen_helper_0_i(void *func, uint32_t arg)
436 TCGv tmp = tcg_const_i32(arg);
438 tcg_gen_helper_0_1(func, tmp);
442 static inline void tcg_gen_helper_0_ii(void *func, uint32_t arg1, uint32_t arg2)
444 TCGv tmp1 = tcg_const_i32(arg1);
445 TCGv tmp2 = tcg_const_i32(arg2);
447 tcg_gen_helper_0_2(func, tmp1, tmp2);
452 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg1, uint32_t arg2)
454 TCGv tmp = tcg_const_i32(arg2);
456 tcg_gen_helper_0_2(func, arg1, tmp);
460 static inline void tcg_gen_helper_0_2i(void *func, TCGv arg1, TCGv arg2, uint32_t arg3)
462 TCGv tmp = tcg_const_i32(arg3);
464 tcg_gen_helper_0_3(func, arg1, arg2, tmp);
468 static inline void tcg_gen_helper_0_1ii(void *func, TCGv arg1, uint32_t arg2, uint32_t arg3)
470 TCGv tmp1 = tcg_const_i32(arg2);
471 TCGv tmp2 = tcg_const_i32(arg3);
473 tcg_gen_helper_0_3(func, arg1, tmp1, tmp2);
478 static inline void tcg_gen_helper_1_i(void *func, TCGv ret, uint32_t arg)
480 TCGv tmp = tcg_const_i32(arg);
482 tcg_gen_helper_1_1(func, ret, tmp);
486 static inline void tcg_gen_helper_1_1i(void *func, TCGv ret, TCGv arg1, uint32_t arg2)
488 TCGv tmp = tcg_const_i32(arg2);
490 tcg_gen_helper_1_2(func, ret, arg1, tmp);
494 static inline void tcg_gen_helper_1_1ii(void *func, TCGv ret, TCGv arg1, uint32_t arg2, uint32_t arg3)
496 TCGv tmp1 = tcg_const_i32(arg2);
497 TCGv tmp2 = tcg_const_i32(arg3);
499 tcg_gen_helper_1_3(func, ret, arg1, tmp1, tmp2);
504 static inline void tcg_gen_helper_1_2i(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3)
506 TCGv tmp = tcg_const_i32(arg3);
508 tcg_gen_helper_1_3(func, ret, arg1, arg2, tmp);
512 static inline void tcg_gen_helper_1_2ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3, uint32_t arg4)
514 TCGv tmp1 = tcg_const_i32(arg3);
515 TCGv tmp2 = tcg_const_i32(arg4);
517 tcg_gen_helper_1_4(func, ret, arg1, arg2, tmp1, tmp2);
522 typedef struct DisasContext {
523 struct TranslationBlock *tb;
524 target_ulong pc, saved_pc;
526 /* Routine used to access memory */
528 uint32_t hflags, saved_hflags;
530 target_ulong btarget;
534 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
535 * exception condition */
536 BS_STOP = 1, /* We want to stop translation for any reason */
537 BS_BRANCH = 2, /* We reached a branch condition */
538 BS_EXCP = 3, /* We reached an exception condition */
541 static const char *regnames[] =
542 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
543 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
544 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
545 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
547 static const char *regnames_HI[] =
548 { "HI0", "HI1", "HI2", "HI3", };
550 static const char *regnames_LO[] =
551 { "LO0", "LO1", "LO2", "LO3", };
553 static const char *regnames_ACX[] =
554 { "ACX0", "ACX1", "ACX2", "ACX3", };
556 static const char *fregnames[] =
557 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
558 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
559 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
560 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
562 static const char *fregnames_64[] =
563 { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
564 "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15",
565 "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23",
566 "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31", };
568 static const char *fregnames_h[] =
569 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
570 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
571 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
572 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
574 #ifdef MIPS_DEBUG_DISAS
575 #define MIPS_DEBUG(fmt, args...) \
577 if (loglevel & CPU_LOG_TB_IN_ASM) { \
578 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
579 ctx->pc, ctx->opcode , ##args); \
583 #define MIPS_DEBUG(fmt, args...) do { } while(0)
586 #define MIPS_INVAL(op) \
588 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
589 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
592 /* General purpose registers moves. */
593 static inline void gen_load_gpr (TCGv t, int reg)
596 tcg_gen_movi_tl(t, 0);
598 tcg_gen_mov_tl(t, cpu_gpr[reg]);
601 static inline void gen_store_gpr (TCGv t, int reg)
604 tcg_gen_mov_tl(cpu_gpr[reg], t);
607 /* Moves to/from HI and LO registers. */
608 static inline void gen_load_HI (TCGv t, int reg)
610 tcg_gen_mov_tl(t, cpu_HI[reg]);
613 static inline void gen_store_HI (TCGv t, int reg)
615 tcg_gen_mov_tl(cpu_HI[reg], t);
618 static inline void gen_load_LO (TCGv t, int reg)
620 tcg_gen_mov_tl(t, cpu_LO[reg]);
623 static inline void gen_store_LO (TCGv t, int reg)
625 tcg_gen_mov_tl(cpu_LO[reg], t);
628 static inline void gen_load_ACX (TCGv t, int reg)
630 tcg_gen_mov_tl(t, cpu_ACX[reg]);
633 static inline void gen_store_ACX (TCGv t, int reg)
635 tcg_gen_mov_tl(cpu_ACX[reg], t);
638 /* Moves to/from shadow registers. */
639 static inline void gen_load_srsgpr (int from, int to)
641 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
644 tcg_gen_movi_tl(r_tmp1, 0);
646 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
648 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
649 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
650 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
651 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
652 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
654 tcg_gen_ld_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * from);
655 tcg_temp_free(r_tmp2);
657 gen_store_gpr(r_tmp1, to);
658 tcg_temp_free(r_tmp1);
661 static inline void gen_store_srsgpr (int from, int to)
664 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
665 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
667 gen_load_gpr(r_tmp1, from);
668 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
669 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
670 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
671 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
672 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
674 tcg_gen_st_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * to);
675 tcg_temp_free(r_tmp1);
676 tcg_temp_free(r_tmp2);
680 /* Floating point register moves. */
681 static inline void gen_load_fpr32 (TCGv t, int reg)
683 tcg_gen_mov_i32(t, fpu_fpr32[reg]);
686 static inline void gen_store_fpr32 (TCGv t, int reg)
688 tcg_gen_mov_i32(fpu_fpr32[reg], t);
691 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
693 if (ctx->hflags & MIPS_HFLAG_F64)
694 tcg_gen_mov_i64(t, fpu_fpr64[reg]);
696 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg & ~1], fpu_fpr32[reg | 1]);
700 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
702 if (ctx->hflags & MIPS_HFLAG_F64)
703 tcg_gen_mov_i64(fpu_fpr64[reg], t);
705 tcg_gen_trunc_i64_i32(fpu_fpr32[reg & ~1], t);
706 tcg_gen_shri_i64(t, t, 32);
707 tcg_gen_trunc_i64_i32(fpu_fpr32[reg | 1], t);
711 static inline void gen_load_fpr32h (TCGv t, int reg)
713 tcg_gen_mov_i32(t, fpu_fpr32h[reg]);
716 static inline void gen_store_fpr32h (TCGv t, int reg)
718 tcg_gen_mov_i32(fpu_fpr32h[reg], t);
721 static inline void get_fp_cond (TCGv t)
723 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
724 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
726 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
727 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
728 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
729 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
730 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
731 tcg_temp_free(r_tmp1);
732 tcg_temp_free(r_tmp2);
735 typedef void (fcmp_fun32)(uint32_t, uint32_t, int);
736 typedef void (fcmp_fun64)(uint64_t, uint64_t, int);
738 #define FOP_CONDS(fcmp_fun, type, fmt) \
739 static fcmp_fun * fcmp ## type ## _ ## fmt ## _table[16] = { \
740 do_cmp ## type ## _ ## fmt ## _f, \
741 do_cmp ## type ## _ ## fmt ## _un, \
742 do_cmp ## type ## _ ## fmt ## _eq, \
743 do_cmp ## type ## _ ## fmt ## _ueq, \
744 do_cmp ## type ## _ ## fmt ## _olt, \
745 do_cmp ## type ## _ ## fmt ## _ult, \
746 do_cmp ## type ## _ ## fmt ## _ole, \
747 do_cmp ## type ## _ ## fmt ## _ule, \
748 do_cmp ## type ## _ ## fmt ## _sf, \
749 do_cmp ## type ## _ ## fmt ## _ngle, \
750 do_cmp ## type ## _ ## fmt ## _seq, \
751 do_cmp ## type ## _ ## fmt ## _ngl, \
752 do_cmp ## type ## _ ## fmt ## _lt, \
753 do_cmp ## type ## _ ## fmt ## _nge, \
754 do_cmp ## type ## _ ## fmt ## _le, \
755 do_cmp ## type ## _ ## fmt ## _ngt, \
757 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv a, TCGv b, int cc) \
759 tcg_gen_helper_0_2i(fcmp ## type ## _ ## fmt ## _table[n], a, b, cc); \
762 FOP_CONDS(fcmp_fun64, , d)
763 FOP_CONDS(fcmp_fun64, abs, d)
764 FOP_CONDS(fcmp_fun32, , s)
765 FOP_CONDS(fcmp_fun32, abs, s)
766 FOP_CONDS(fcmp_fun64, , ps)
767 FOP_CONDS(fcmp_fun64, abs, ps)
771 #define OP_COND(name, cond) \
772 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
774 int l1 = gen_new_label(); \
775 int l2 = gen_new_label(); \
777 tcg_gen_brcond_tl(cond, t0, t1, l1); \
778 tcg_gen_movi_tl(t0, 0); \
781 tcg_gen_movi_tl(t0, 1); \
784 OP_COND(eq, TCG_COND_EQ);
785 OP_COND(ne, TCG_COND_NE);
786 OP_COND(ge, TCG_COND_GE);
787 OP_COND(geu, TCG_COND_GEU);
788 OP_COND(lt, TCG_COND_LT);
789 OP_COND(ltu, TCG_COND_LTU);
792 #define OP_CONDI(name, cond) \
793 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
795 int l1 = gen_new_label(); \
796 int l2 = gen_new_label(); \
798 tcg_gen_brcondi_tl(cond, t, val, l1); \
799 tcg_gen_movi_tl(t, 0); \
802 tcg_gen_movi_tl(t, 1); \
805 OP_CONDI(lti, TCG_COND_LT);
806 OP_CONDI(ltiu, TCG_COND_LTU);
809 #define OP_CONDZ(name, cond) \
810 static inline void glue(gen_op_, name) (TCGv t) \
812 int l1 = gen_new_label(); \
813 int l2 = gen_new_label(); \
815 tcg_gen_brcondi_tl(cond, t, 0, l1); \
816 tcg_gen_movi_tl(t, 0); \
819 tcg_gen_movi_tl(t, 1); \
822 OP_CONDZ(gez, TCG_COND_GE);
823 OP_CONDZ(gtz, TCG_COND_GT);
824 OP_CONDZ(lez, TCG_COND_LE);
825 OP_CONDZ(ltz, TCG_COND_LT);
828 static inline void gen_save_pc(target_ulong pc)
830 tcg_gen_movi_tl(cpu_PC, pc);
833 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
835 #if defined MIPS_DEBUG_DISAS
836 if (loglevel & CPU_LOG_TB_IN_ASM) {
837 fprintf(logfile, "hflags %08x saved %08x\n",
838 ctx->hflags, ctx->saved_hflags);
841 if (do_save_pc && ctx->pc != ctx->saved_pc) {
842 gen_save_pc(ctx->pc);
843 ctx->saved_pc = ctx->pc;
845 if (ctx->hflags != ctx->saved_hflags) {
846 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
848 tcg_gen_movi_i32(r_tmp, ctx->hflags);
849 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
850 tcg_temp_free(r_tmp);
851 ctx->saved_hflags = ctx->hflags;
852 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
858 tcg_gen_movi_tl(btarget, ctx->btarget);
864 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
866 ctx->saved_hflags = ctx->hflags;
867 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
873 ctx->btarget = env->btarget;
879 generate_exception_err (DisasContext *ctx, int excp, int err)
881 save_cpu_state(ctx, 1);
882 tcg_gen_helper_0_ii(do_raise_exception_err, excp, err);
883 tcg_gen_helper_0_0(do_interrupt_restart);
888 generate_exception (DisasContext *ctx, int excp)
890 save_cpu_state(ctx, 1);
891 tcg_gen_helper_0_i(do_raise_exception, excp);
892 tcg_gen_helper_0_0(do_interrupt_restart);
896 /* Addresses computation */
897 static inline void gen_op_addr_add (DisasContext *ctx, TCGv t0, TCGv t1)
899 tcg_gen_add_tl(t0, t0, t1);
901 #if defined(TARGET_MIPS64)
902 /* For compatibility with 32-bit code, data reference in user mode
903 with Status_UX = 0 should be casted to 32-bit and sign extended.
904 See the MIPS64 PRA manual, section 4.10. */
905 if (((ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
906 !(ctx->hflags & MIPS_HFLAG_UX)) {
907 tcg_gen_ext32s_i64(t0, t0);
912 static inline void check_cp0_enabled(DisasContext *ctx)
914 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
915 generate_exception_err(ctx, EXCP_CpU, 1);
918 static inline void check_cp1_enabled(DisasContext *ctx)
920 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
921 generate_exception_err(ctx, EXCP_CpU, 1);
924 /* Verify that the processor is running with COP1X instructions enabled.
925 This is associated with the nabla symbol in the MIPS32 and MIPS64
928 static inline void check_cop1x(DisasContext *ctx)
930 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
931 generate_exception(ctx, EXCP_RI);
934 /* Verify that the processor is running with 64-bit floating-point
935 operations enabled. */
937 static inline void check_cp1_64bitmode(DisasContext *ctx)
939 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
940 generate_exception(ctx, EXCP_RI);
944 * Verify if floating point register is valid; an operation is not defined
945 * if bit 0 of any register specification is set and the FR bit in the
946 * Status register equals zero, since the register numbers specify an
947 * even-odd pair of adjacent coprocessor general registers. When the FR bit
948 * in the Status register equals one, both even and odd register numbers
949 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
951 * Multiple 64 bit wide registers can be checked by calling
952 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
954 static inline void check_cp1_registers(DisasContext *ctx, int regs)
956 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
957 generate_exception(ctx, EXCP_RI);
960 /* This code generates a "reserved instruction" exception if the
961 CPU does not support the instruction set corresponding to flags. */
962 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
964 if (unlikely(!(env->insn_flags & flags)))
965 generate_exception(ctx, EXCP_RI);
968 /* This code generates a "reserved instruction" exception if 64-bit
969 instructions are not enabled. */
970 static inline void check_mips_64(DisasContext *ctx)
972 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
973 generate_exception(ctx, EXCP_RI);
976 /* load/store instructions. */
977 #define OP_LD(insn,fname) \
978 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
980 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
987 #if defined(TARGET_MIPS64)
993 #define OP_ST(insn,fname) \
994 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
996 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1001 #if defined(TARGET_MIPS64)
1006 #define OP_LD_ATOMIC(insn,fname) \
1007 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1009 tcg_gen_mov_tl(t1, t0); \
1010 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1011 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1013 OP_LD_ATOMIC(ll,ld32s);
1014 #if defined(TARGET_MIPS64)
1015 OP_LD_ATOMIC(lld,ld64);
1019 #define OP_ST_ATOMIC(insn,fname,almask) \
1020 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1022 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1023 int l1 = gen_new_label(); \
1024 int l2 = gen_new_label(); \
1025 int l3 = gen_new_label(); \
1027 tcg_gen_andi_tl(r_tmp, t0, almask); \
1028 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1029 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1030 generate_exception(ctx, EXCP_AdES); \
1031 gen_set_label(l1); \
1032 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1033 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1034 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1035 tcg_gen_movi_tl(t0, 1); \
1037 gen_set_label(l2); \
1038 tcg_gen_movi_tl(t0, 0); \
1039 gen_set_label(l3); \
1040 tcg_temp_free(r_tmp); \
1042 OP_ST_ATOMIC(sc,st32,0x3);
1043 #if defined(TARGET_MIPS64)
1044 OP_ST_ATOMIC(scd,st64,0x7);
1048 /* Load and store */
1049 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1050 int base, int16_t offset)
1052 const char *opn = "ldst";
1053 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1054 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1057 tcg_gen_movi_tl(t0, offset);
1058 } else if (offset == 0) {
1059 gen_load_gpr(t0, base);
1061 gen_load_gpr(t0, base);
1062 tcg_gen_movi_tl(t1, offset);
1063 gen_op_addr_add(ctx, t0, t1);
1065 /* Don't do NOP if destination is zero: we must perform the actual
1068 #if defined(TARGET_MIPS64)
1070 op_ldst_lwu(t0, ctx);
1071 gen_store_gpr(t0, rt);
1075 op_ldst_ld(t0, ctx);
1076 gen_store_gpr(t0, rt);
1080 op_ldst_lld(t0, t1, ctx);
1081 gen_store_gpr(t0, rt);
1085 gen_load_gpr(t1, rt);
1086 op_ldst_sd(t0, t1, ctx);
1090 save_cpu_state(ctx, 1);
1091 gen_load_gpr(t1, rt);
1092 op_ldst_scd(t0, t1, ctx);
1093 gen_store_gpr(t0, rt);
1097 save_cpu_state(ctx, 1);
1098 gen_load_gpr(t1, rt);
1099 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1100 gen_store_gpr(t1, rt);
1104 save_cpu_state(ctx, 1);
1105 gen_load_gpr(t1, rt);
1106 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1110 save_cpu_state(ctx, 1);
1111 gen_load_gpr(t1, rt);
1112 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1113 gen_store_gpr(t1, rt);
1117 save_cpu_state(ctx, 1);
1118 gen_load_gpr(t1, rt);
1119 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1124 op_ldst_lw(t0, ctx);
1125 gen_store_gpr(t0, rt);
1129 gen_load_gpr(t1, rt);
1130 op_ldst_sw(t0, t1, ctx);
1134 op_ldst_lh(t0, ctx);
1135 gen_store_gpr(t0, rt);
1139 gen_load_gpr(t1, rt);
1140 op_ldst_sh(t0, t1, ctx);
1144 op_ldst_lhu(t0, ctx);
1145 gen_store_gpr(t0, rt);
1149 op_ldst_lb(t0, ctx);
1150 gen_store_gpr(t0, rt);
1154 gen_load_gpr(t1, rt);
1155 op_ldst_sb(t0, t1, ctx);
1159 op_ldst_lbu(t0, ctx);
1160 gen_store_gpr(t0, rt);
1164 save_cpu_state(ctx, 1);
1165 gen_load_gpr(t1, rt);
1166 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1167 gen_store_gpr(t1, rt);
1171 save_cpu_state(ctx, 1);
1172 gen_load_gpr(t1, rt);
1173 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1177 save_cpu_state(ctx, 1);
1178 gen_load_gpr(t1, rt);
1179 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1180 gen_store_gpr(t1, rt);
1184 save_cpu_state(ctx, 1);
1185 gen_load_gpr(t1, rt);
1186 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1190 op_ldst_ll(t0, t1, ctx);
1191 gen_store_gpr(t0, rt);
1195 save_cpu_state(ctx, 1);
1196 gen_load_gpr(t1, rt);
1197 op_ldst_sc(t0, t1, ctx);
1198 gen_store_gpr(t0, rt);
1203 generate_exception(ctx, EXCP_RI);
1206 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1212 /* Load and store */
1213 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1214 int base, int16_t offset)
1216 const char *opn = "flt_ldst";
1217 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1220 tcg_gen_movi_tl(t0, offset);
1221 } else if (offset == 0) {
1222 gen_load_gpr(t0, base);
1224 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1226 gen_load_gpr(t0, base);
1227 tcg_gen_movi_tl(t1, offset);
1228 gen_op_addr_add(ctx, t0, t1);
1231 /* Don't do NOP if destination is zero: we must perform the actual
1236 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1238 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
1239 gen_store_fpr32(fp0, ft);
1246 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1248 gen_load_fpr32(fp0, ft);
1249 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
1256 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1258 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1259 gen_store_fpr64(ctx, fp0, ft);
1266 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1268 gen_load_fpr64(ctx, fp0, ft);
1269 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1276 generate_exception(ctx, EXCP_RI);
1279 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1284 /* Arithmetic with immediate operand */
1285 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1286 int rt, int rs, int16_t imm)
1289 const char *opn = "imm arith";
1290 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1292 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1293 /* If no destination, treat it as a NOP.
1294 For addi, we must generate the overflow exception when needed. */
1298 uimm = (uint16_t)imm;
1302 #if defined(TARGET_MIPS64)
1308 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1313 gen_load_gpr(t0, rs);
1316 tcg_gen_movi_tl(t0, imm << 16);
1321 #if defined(TARGET_MIPS64)
1330 gen_load_gpr(t0, rs);
1336 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1337 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1338 int l1 = gen_new_label();
1340 save_cpu_state(ctx, 1);
1341 tcg_gen_ext32s_tl(r_tmp1, t0);
1342 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1344 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1345 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1346 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1347 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1348 tcg_temp_free(r_tmp2);
1349 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1350 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1351 tcg_temp_free(r_tmp1);
1352 /* operands of same sign, result different sign */
1353 generate_exception(ctx, EXCP_OVERFLOW);
1356 tcg_gen_ext32s_tl(t0, t0);
1361 tcg_gen_ext32s_tl(t0, t0);
1362 tcg_gen_addi_tl(t0, t0, uimm);
1363 tcg_gen_ext32s_tl(t0, t0);
1366 #if defined(TARGET_MIPS64)
1369 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1370 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1371 int l1 = gen_new_label();
1373 save_cpu_state(ctx, 1);
1374 tcg_gen_mov_tl(r_tmp1, t0);
1375 tcg_gen_addi_tl(t0, t0, uimm);
1377 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1378 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1379 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1380 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1381 tcg_temp_free(r_tmp2);
1382 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1383 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1384 tcg_temp_free(r_tmp1);
1385 /* operands of same sign, result different sign */
1386 generate_exception(ctx, EXCP_OVERFLOW);
1392 tcg_gen_addi_tl(t0, t0, uimm);
1397 gen_op_lti(t0, uimm);
1401 gen_op_ltiu(t0, uimm);
1405 tcg_gen_andi_tl(t0, t0, uimm);
1409 tcg_gen_ori_tl(t0, t0, uimm);
1413 tcg_gen_xori_tl(t0, t0, uimm);
1420 tcg_gen_ext32u_tl(t0, t0);
1421 tcg_gen_shli_tl(t0, t0, uimm);
1422 tcg_gen_ext32s_tl(t0, t0);
1426 tcg_gen_ext32s_tl(t0, t0);
1427 tcg_gen_sari_tl(t0, t0, uimm);
1428 tcg_gen_ext32s_tl(t0, t0);
1432 switch ((ctx->opcode >> 21) & 0x1f) {
1434 tcg_gen_ext32u_tl(t0, t0);
1435 tcg_gen_shri_tl(t0, t0, uimm);
1436 tcg_gen_ext32s_tl(t0, t0);
1440 /* rotr is decoded as srl on non-R2 CPUs */
1441 if (env->insn_flags & ISA_MIPS32R2) {
1443 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1445 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1446 tcg_gen_rotri_i32(r_tmp1, r_tmp1, uimm);
1447 tcg_gen_ext_i32_tl(t0, r_tmp1);
1448 tcg_temp_free(r_tmp1);
1452 tcg_gen_ext32u_tl(t0, t0);
1453 tcg_gen_shri_tl(t0, t0, uimm);
1454 tcg_gen_ext32s_tl(t0, t0);
1459 MIPS_INVAL("invalid srl flag");
1460 generate_exception(ctx, EXCP_RI);
1464 #if defined(TARGET_MIPS64)
1466 tcg_gen_shli_tl(t0, t0, uimm);
1470 tcg_gen_sari_tl(t0, t0, uimm);
1474 switch ((ctx->opcode >> 21) & 0x1f) {
1476 tcg_gen_shri_tl(t0, t0, uimm);
1480 /* drotr is decoded as dsrl on non-R2 CPUs */
1481 if (env->insn_flags & ISA_MIPS32R2) {
1483 tcg_gen_rotri_tl(t0, t0, uimm);
1487 tcg_gen_shri_tl(t0, t0, uimm);
1492 MIPS_INVAL("invalid dsrl flag");
1493 generate_exception(ctx, EXCP_RI);
1498 tcg_gen_shli_tl(t0, t0, uimm + 32);
1502 tcg_gen_sari_tl(t0, t0, uimm + 32);
1506 switch ((ctx->opcode >> 21) & 0x1f) {
1508 tcg_gen_shri_tl(t0, t0, uimm + 32);
1512 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1513 if (env->insn_flags & ISA_MIPS32R2) {
1514 tcg_gen_rotri_tl(t0, t0, uimm + 32);
1517 tcg_gen_shri_tl(t0, t0, uimm + 32);
1522 MIPS_INVAL("invalid dsrl32 flag");
1523 generate_exception(ctx, EXCP_RI);
1530 generate_exception(ctx, EXCP_RI);
1533 gen_store_gpr(t0, rt);
1534 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1540 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1541 int rd, int rs, int rt)
1543 const char *opn = "arith";
1544 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1545 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1547 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1548 && opc != OPC_DADD && opc != OPC_DSUB) {
1549 /* If no destination, treat it as a NOP.
1550 For add & sub, we must generate the overflow exception when needed. */
1554 gen_load_gpr(t0, rs);
1555 /* Specialcase the conventional move operation. */
1556 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1557 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1558 gen_store_gpr(t0, rd);
1561 gen_load_gpr(t1, rt);
1565 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1566 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1567 int l1 = gen_new_label();
1569 save_cpu_state(ctx, 1);
1570 tcg_gen_ext32s_tl(r_tmp1, t0);
1571 tcg_gen_ext32s_tl(r_tmp2, t1);
1572 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1574 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1575 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1576 tcg_gen_xor_tl(r_tmp2, t0, t1);
1577 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1578 tcg_temp_free(r_tmp2);
1579 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1580 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1581 tcg_temp_free(r_tmp1);
1582 /* operands of same sign, result different sign */
1583 generate_exception(ctx, EXCP_OVERFLOW);
1586 tcg_gen_ext32s_tl(t0, t0);
1591 tcg_gen_ext32s_tl(t0, t0);
1592 tcg_gen_ext32s_tl(t1, t1);
1593 tcg_gen_add_tl(t0, t0, t1);
1594 tcg_gen_ext32s_tl(t0, t0);
1599 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1600 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1601 int l1 = gen_new_label();
1603 save_cpu_state(ctx, 1);
1604 tcg_gen_ext32s_tl(r_tmp1, t0);
1605 tcg_gen_ext32s_tl(r_tmp2, t1);
1606 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1608 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1609 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1610 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1611 tcg_temp_free(r_tmp2);
1612 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1613 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1614 tcg_temp_free(r_tmp1);
1615 /* operands of different sign, first operand and result different sign */
1616 generate_exception(ctx, EXCP_OVERFLOW);
1619 tcg_gen_ext32s_tl(t0, t0);
1624 tcg_gen_ext32s_tl(t0, t0);
1625 tcg_gen_ext32s_tl(t1, t1);
1626 tcg_gen_sub_tl(t0, t0, t1);
1627 tcg_gen_ext32s_tl(t0, t0);
1630 #if defined(TARGET_MIPS64)
1633 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1634 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1635 int l1 = gen_new_label();
1637 save_cpu_state(ctx, 1);
1638 tcg_gen_mov_tl(r_tmp1, t0);
1639 tcg_gen_add_tl(t0, t0, t1);
1641 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1642 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1643 tcg_gen_xor_tl(r_tmp2, t0, t1);
1644 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1645 tcg_temp_free(r_tmp2);
1646 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1647 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1648 tcg_temp_free(r_tmp1);
1649 /* operands of same sign, result different sign */
1650 generate_exception(ctx, EXCP_OVERFLOW);
1656 tcg_gen_add_tl(t0, t0, t1);
1661 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1662 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1663 int l1 = gen_new_label();
1665 save_cpu_state(ctx, 1);
1666 tcg_gen_mov_tl(r_tmp1, t0);
1667 tcg_gen_sub_tl(t0, t0, t1);
1669 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1670 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1671 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1672 tcg_temp_free(r_tmp2);
1673 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1674 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1675 tcg_temp_free(r_tmp1);
1676 /* operands of different sign, first operand and result different sign */
1677 generate_exception(ctx, EXCP_OVERFLOW);
1683 tcg_gen_sub_tl(t0, t0, t1);
1696 tcg_gen_and_tl(t0, t0, t1);
1700 tcg_gen_or_tl(t0, t0, t1);
1701 tcg_gen_not_tl(t0, t0);
1705 tcg_gen_or_tl(t0, t0, t1);
1709 tcg_gen_xor_tl(t0, t0, t1);
1713 tcg_gen_ext32s_tl(t0, t0);
1714 tcg_gen_ext32s_tl(t1, t1);
1715 tcg_gen_mul_tl(t0, t0, t1);
1716 tcg_gen_ext32s_tl(t0, t0);
1721 int l1 = gen_new_label();
1723 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1724 gen_store_gpr(t0, rd);
1731 int l1 = gen_new_label();
1733 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1734 gen_store_gpr(t0, rd);
1740 tcg_gen_ext32u_tl(t0, t0);
1741 tcg_gen_ext32u_tl(t1, t1);
1742 tcg_gen_andi_tl(t0, t0, 0x1f);
1743 tcg_gen_shl_tl(t0, t1, t0);
1744 tcg_gen_ext32s_tl(t0, t0);
1748 tcg_gen_ext32s_tl(t1, t1);
1749 tcg_gen_andi_tl(t0, t0, 0x1f);
1750 tcg_gen_sar_tl(t0, t1, t0);
1751 tcg_gen_ext32s_tl(t0, t0);
1755 switch ((ctx->opcode >> 6) & 0x1f) {
1757 tcg_gen_ext32u_tl(t1, t1);
1758 tcg_gen_andi_tl(t0, t0, 0x1f);
1759 tcg_gen_shr_tl(t0, t1, t0);
1760 tcg_gen_ext32s_tl(t0, t0);
1764 /* rotrv is decoded as srlv on non-R2 CPUs */
1765 if (env->insn_flags & ISA_MIPS32R2) {
1766 int l1 = gen_new_label();
1767 int l2 = gen_new_label();
1769 tcg_gen_andi_tl(t0, t0, 0x1f);
1770 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1772 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1773 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1775 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1776 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1777 tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2);
1778 tcg_temp_free(r_tmp1);
1779 tcg_temp_free(r_tmp2);
1783 tcg_gen_mov_tl(t0, t1);
1787 tcg_gen_ext32u_tl(t1, t1);
1788 tcg_gen_andi_tl(t0, t0, 0x1f);
1789 tcg_gen_shr_tl(t0, t1, t0);
1790 tcg_gen_ext32s_tl(t0, t0);
1795 MIPS_INVAL("invalid srlv flag");
1796 generate_exception(ctx, EXCP_RI);
1800 #if defined(TARGET_MIPS64)
1802 tcg_gen_andi_tl(t0, t0, 0x3f);
1803 tcg_gen_shl_tl(t0, t1, t0);
1807 tcg_gen_andi_tl(t0, t0, 0x3f);
1808 tcg_gen_sar_tl(t0, t1, t0);
1812 switch ((ctx->opcode >> 6) & 0x1f) {
1814 tcg_gen_andi_tl(t0, t0, 0x3f);
1815 tcg_gen_shr_tl(t0, t1, t0);
1819 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1820 if (env->insn_flags & ISA_MIPS32R2) {
1821 int l1 = gen_new_label();
1822 int l2 = gen_new_label();
1824 tcg_gen_andi_tl(t0, t0, 0x3f);
1825 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1827 tcg_gen_rotr_tl(t0, t1, t0);
1831 tcg_gen_mov_tl(t0, t1);
1835 tcg_gen_andi_tl(t0, t0, 0x3f);
1836 tcg_gen_shr_tl(t0, t1, t0);
1841 MIPS_INVAL("invalid dsrlv flag");
1842 generate_exception(ctx, EXCP_RI);
1849 generate_exception(ctx, EXCP_RI);
1852 gen_store_gpr(t0, rd);
1854 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1860 /* Arithmetic on HI/LO registers */
1861 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1863 const char *opn = "hilo";
1864 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1866 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1874 gen_store_gpr(t0, reg);
1879 gen_store_gpr(t0, reg);
1883 gen_load_gpr(t0, reg);
1884 gen_store_HI(t0, 0);
1888 gen_load_gpr(t0, reg);
1889 gen_store_LO(t0, 0);
1894 generate_exception(ctx, EXCP_RI);
1897 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1902 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1905 const char *opn = "mul/div";
1906 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1907 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1909 gen_load_gpr(t0, rs);
1910 gen_load_gpr(t1, rt);
1914 int l1 = gen_new_label();
1916 tcg_gen_ext32s_tl(t0, t0);
1917 tcg_gen_ext32s_tl(t1, t1);
1918 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1920 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1921 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1922 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1924 tcg_gen_ext_tl_i64(r_tmp1, t0);
1925 tcg_gen_ext_tl_i64(r_tmp2, t1);
1926 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1927 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1928 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1929 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1930 tcg_temp_free(r_tmp1);
1931 tcg_temp_free(r_tmp2);
1932 tcg_temp_free(r_tmp3);
1933 tcg_gen_ext32s_tl(t0, t0);
1934 tcg_gen_ext32s_tl(t1, t1);
1935 gen_store_LO(t0, 0);
1936 gen_store_HI(t1, 0);
1944 int l1 = gen_new_label();
1946 tcg_gen_ext32s_tl(t1, t1);
1947 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1949 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1950 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1951 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1953 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1954 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1955 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1956 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1957 tcg_gen_ext_i32_tl(t0, r_tmp3);
1958 tcg_gen_ext_i32_tl(t1, r_tmp1);
1959 tcg_temp_free(r_tmp1);
1960 tcg_temp_free(r_tmp2);
1961 tcg_temp_free(r_tmp3);
1962 gen_store_LO(t0, 0);
1963 gen_store_HI(t1, 0);
1971 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1972 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1974 tcg_gen_ext32s_tl(t0, t0);
1975 tcg_gen_ext32s_tl(t1, t1);
1976 tcg_gen_ext_tl_i64(r_tmp1, t0);
1977 tcg_gen_ext_tl_i64(r_tmp2, t1);
1978 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1979 tcg_temp_free(r_tmp2);
1980 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1981 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1982 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1983 tcg_temp_free(r_tmp1);
1984 tcg_gen_ext32s_tl(t0, t0);
1985 tcg_gen_ext32s_tl(t1, t1);
1986 gen_store_LO(t0, 0);
1987 gen_store_HI(t1, 0);
1993 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1994 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1996 tcg_gen_ext32u_tl(t0, t0);
1997 tcg_gen_ext32u_tl(t1, t1);
1998 tcg_gen_extu_tl_i64(r_tmp1, t0);
1999 tcg_gen_extu_tl_i64(r_tmp2, t1);
2000 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2001 tcg_temp_free(r_tmp2);
2002 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2003 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2004 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2005 tcg_temp_free(r_tmp1);
2006 tcg_gen_ext32s_tl(t0, t0);
2007 tcg_gen_ext32s_tl(t1, t1);
2008 gen_store_LO(t0, 0);
2009 gen_store_HI(t1, 0);
2013 #if defined(TARGET_MIPS64)
2016 int l1 = gen_new_label();
2018 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2020 int l2 = gen_new_label();
2022 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2023 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2025 tcg_gen_movi_tl(t1, 0);
2026 gen_store_LO(t0, 0);
2027 gen_store_HI(t1, 0);
2032 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2033 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2035 tcg_gen_div_i64(r_tmp1, t0, t1);
2036 tcg_gen_rem_i64(r_tmp2, t0, t1);
2037 gen_store_LO(r_tmp1, 0);
2038 gen_store_HI(r_tmp2, 0);
2039 tcg_temp_free(r_tmp1);
2040 tcg_temp_free(r_tmp2);
2049 int l1 = gen_new_label();
2051 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2053 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2054 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2056 tcg_gen_divu_i64(r_tmp1, t0, t1);
2057 tcg_gen_remu_i64(r_tmp2, t0, t1);
2058 tcg_temp_free(r_tmp1);
2059 tcg_temp_free(r_tmp2);
2060 gen_store_LO(r_tmp1, 0);
2061 gen_store_HI(r_tmp2, 0);
2068 tcg_gen_helper_0_2(do_dmult, t0, t1);
2072 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2078 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2079 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2081 tcg_gen_ext32s_tl(t0, t0);
2082 tcg_gen_ext32s_tl(t1, t1);
2083 tcg_gen_ext_tl_i64(r_tmp1, t0);
2084 tcg_gen_ext_tl_i64(r_tmp2, t1);
2085 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2088 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2089 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2090 tcg_temp_free(r_tmp2);
2091 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2092 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2093 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2094 tcg_temp_free(r_tmp1);
2095 tcg_gen_ext32s_tl(t0, t0);
2096 tcg_gen_ext32s_tl(t1, t1);
2097 gen_store_LO(t0, 0);
2098 gen_store_HI(t1, 0);
2104 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2105 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2107 tcg_gen_ext32u_tl(t0, t0);
2108 tcg_gen_ext32u_tl(t1, t1);
2109 tcg_gen_extu_tl_i64(r_tmp1, t0);
2110 tcg_gen_extu_tl_i64(r_tmp2, t1);
2111 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2114 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2115 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2116 tcg_temp_free(r_tmp2);
2117 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2118 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2119 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2120 tcg_temp_free(r_tmp1);
2121 tcg_gen_ext32s_tl(t0, t0);
2122 tcg_gen_ext32s_tl(t1, t1);
2123 gen_store_LO(t0, 0);
2124 gen_store_HI(t1, 0);
2130 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2131 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2133 tcg_gen_ext32s_tl(t0, t0);
2134 tcg_gen_ext32s_tl(t1, t1);
2135 tcg_gen_ext_tl_i64(r_tmp1, t0);
2136 tcg_gen_ext_tl_i64(r_tmp2, t1);
2137 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2140 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2141 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2142 tcg_temp_free(r_tmp2);
2143 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2144 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2145 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2146 tcg_temp_free(r_tmp1);
2147 tcg_gen_ext32s_tl(t0, t0);
2148 tcg_gen_ext32s_tl(t1, t1);
2149 gen_store_LO(t0, 0);
2150 gen_store_HI(t1, 0);
2156 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2157 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2159 tcg_gen_ext32u_tl(t0, t0);
2160 tcg_gen_ext32u_tl(t1, t1);
2161 tcg_gen_extu_tl_i64(r_tmp1, t0);
2162 tcg_gen_extu_tl_i64(r_tmp2, t1);
2163 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2166 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2167 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2168 tcg_temp_free(r_tmp2);
2169 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2170 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2171 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2172 tcg_temp_free(r_tmp1);
2173 tcg_gen_ext32s_tl(t0, t0);
2174 tcg_gen_ext32s_tl(t1, t1);
2175 gen_store_LO(t0, 0);
2176 gen_store_HI(t1, 0);
2182 generate_exception(ctx, EXCP_RI);
2185 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2191 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2192 int rd, int rs, int rt)
2194 const char *opn = "mul vr54xx";
2195 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2196 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2198 gen_load_gpr(t0, rs);
2199 gen_load_gpr(t1, rt);
2202 case OPC_VR54XX_MULS:
2203 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2206 case OPC_VR54XX_MULSU:
2207 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2210 case OPC_VR54XX_MACC:
2211 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2214 case OPC_VR54XX_MACCU:
2215 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2218 case OPC_VR54XX_MSAC:
2219 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2222 case OPC_VR54XX_MSACU:
2223 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2226 case OPC_VR54XX_MULHI:
2227 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2230 case OPC_VR54XX_MULHIU:
2231 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2234 case OPC_VR54XX_MULSHI:
2235 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2238 case OPC_VR54XX_MULSHIU:
2239 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2242 case OPC_VR54XX_MACCHI:
2243 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2246 case OPC_VR54XX_MACCHIU:
2247 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2250 case OPC_VR54XX_MSACHI:
2251 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2254 case OPC_VR54XX_MSACHIU:
2255 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2259 MIPS_INVAL("mul vr54xx");
2260 generate_exception(ctx, EXCP_RI);
2263 gen_store_gpr(t0, rd);
2264 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2271 static void gen_cl (DisasContext *ctx, uint32_t opc,
2274 const char *opn = "CLx";
2275 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2282 gen_load_gpr(t0, rs);
2285 tcg_gen_helper_1_1(do_clo, t0, t0);
2289 tcg_gen_helper_1_1(do_clz, t0, t0);
2292 #if defined(TARGET_MIPS64)
2294 tcg_gen_helper_1_1(do_dclo, t0, t0);
2298 tcg_gen_helper_1_1(do_dclz, t0, t0);
2304 generate_exception(ctx, EXCP_RI);
2307 gen_store_gpr(t0, rd);
2308 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2315 static void gen_trap (DisasContext *ctx, uint32_t opc,
2316 int rs, int rt, int16_t imm)
2319 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2320 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2323 /* Load needed operands */
2331 /* Compare two registers */
2333 gen_load_gpr(t0, rs);
2334 gen_load_gpr(t1, rt);
2344 /* Compare register to immediate */
2345 if (rs != 0 || imm != 0) {
2346 gen_load_gpr(t0, rs);
2347 tcg_gen_movi_tl(t1, (int32_t)imm);
2354 case OPC_TEQ: /* rs == rs */
2355 case OPC_TEQI: /* r0 == 0 */
2356 case OPC_TGE: /* rs >= rs */
2357 case OPC_TGEI: /* r0 >= 0 */
2358 case OPC_TGEU: /* rs >= rs unsigned */
2359 case OPC_TGEIU: /* r0 >= 0 unsigned */
2361 tcg_gen_movi_tl(t0, 1);
2363 case OPC_TLT: /* rs < rs */
2364 case OPC_TLTI: /* r0 < 0 */
2365 case OPC_TLTU: /* rs < rs unsigned */
2366 case OPC_TLTIU: /* r0 < 0 unsigned */
2367 case OPC_TNE: /* rs != rs */
2368 case OPC_TNEI: /* r0 != 0 */
2369 /* Never trap: treat as NOP. */
2373 generate_exception(ctx, EXCP_RI);
2404 generate_exception(ctx, EXCP_RI);
2408 save_cpu_state(ctx, 1);
2410 int l1 = gen_new_label();
2412 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2413 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2416 ctx->bstate = BS_STOP;
2422 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2424 TranslationBlock *tb;
2426 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2429 tcg_gen_exit_tb((long)tb + n);
2436 /* Branches (before delay slot) */
2437 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2438 int rs, int rt, int32_t offset)
2440 target_ulong btgt = -1;
2442 int bcond_compute = 0;
2443 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2444 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2446 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2447 #ifdef MIPS_DEBUG_DISAS
2448 if (loglevel & CPU_LOG_TB_IN_ASM) {
2450 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2454 generate_exception(ctx, EXCP_RI);
2458 /* Load needed operands */
2464 /* Compare two registers */
2466 gen_load_gpr(t0, rs);
2467 gen_load_gpr(t1, rt);
2470 btgt = ctx->pc + 4 + offset;
2484 /* Compare to zero */
2486 gen_load_gpr(t0, rs);
2489 btgt = ctx->pc + 4 + offset;
2493 /* Jump to immediate */
2494 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2498 /* Jump to register */
2499 if (offset != 0 && offset != 16) {
2500 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2501 others are reserved. */
2502 MIPS_INVAL("jump hint");
2503 generate_exception(ctx, EXCP_RI);
2506 gen_load_gpr(btarget, rs);
2509 MIPS_INVAL("branch/jump");
2510 generate_exception(ctx, EXCP_RI);
2513 if (bcond_compute == 0) {
2514 /* No condition to be computed */
2516 case OPC_BEQ: /* rx == rx */
2517 case OPC_BEQL: /* rx == rx likely */
2518 case OPC_BGEZ: /* 0 >= 0 */
2519 case OPC_BGEZL: /* 0 >= 0 likely */
2520 case OPC_BLEZ: /* 0 <= 0 */
2521 case OPC_BLEZL: /* 0 <= 0 likely */
2523 ctx->hflags |= MIPS_HFLAG_B;
2524 MIPS_DEBUG("balways");
2526 case OPC_BGEZAL: /* 0 >= 0 */
2527 case OPC_BGEZALL: /* 0 >= 0 likely */
2528 /* Always take and link */
2530 ctx->hflags |= MIPS_HFLAG_B;
2531 MIPS_DEBUG("balways and link");
2533 case OPC_BNE: /* rx != rx */
2534 case OPC_BGTZ: /* 0 > 0 */
2535 case OPC_BLTZ: /* 0 < 0 */
2537 MIPS_DEBUG("bnever (NOP)");
2539 case OPC_BLTZAL: /* 0 < 0 */
2540 tcg_gen_movi_tl(t0, ctx->pc + 8);
2541 gen_store_gpr(t0, 31);
2542 MIPS_DEBUG("bnever and link");
2544 case OPC_BLTZALL: /* 0 < 0 likely */
2545 tcg_gen_movi_tl(t0, ctx->pc + 8);
2546 gen_store_gpr(t0, 31);
2547 /* Skip the instruction in the delay slot */
2548 MIPS_DEBUG("bnever, link and skip");
2551 case OPC_BNEL: /* rx != rx likely */
2552 case OPC_BGTZL: /* 0 > 0 likely */
2553 case OPC_BLTZL: /* 0 < 0 likely */
2554 /* Skip the instruction in the delay slot */
2555 MIPS_DEBUG("bnever and skip");
2559 ctx->hflags |= MIPS_HFLAG_B;
2560 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2564 ctx->hflags |= MIPS_HFLAG_B;
2565 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2568 ctx->hflags |= MIPS_HFLAG_BR;
2569 MIPS_DEBUG("jr %s", regnames[rs]);
2573 ctx->hflags |= MIPS_HFLAG_BR;
2574 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2577 MIPS_INVAL("branch/jump");
2578 generate_exception(ctx, EXCP_RI);
2585 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2586 regnames[rs], regnames[rt], btgt);
2590 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2591 regnames[rs], regnames[rt], btgt);
2595 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2596 regnames[rs], regnames[rt], btgt);
2600 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2601 regnames[rs], regnames[rt], btgt);
2605 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2609 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2613 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2619 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2623 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2627 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2631 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2635 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2639 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2643 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2648 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2650 ctx->hflags |= MIPS_HFLAG_BC;
2651 tcg_gen_trunc_tl_i32(bcond, t0);
2656 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2658 ctx->hflags |= MIPS_HFLAG_BL;
2659 tcg_gen_trunc_tl_i32(bcond, t0);
2662 MIPS_INVAL("conditional branch/jump");
2663 generate_exception(ctx, EXCP_RI);
2667 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2668 blink, ctx->hflags, btgt);
2670 ctx->btarget = btgt;
2672 tcg_gen_movi_tl(t0, ctx->pc + 8);
2673 gen_store_gpr(t0, blink);
2681 /* special3 bitfield operations */
2682 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2683 int rs, int lsb, int msb)
2685 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2686 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2688 gen_load_gpr(t1, rs);
2693 tcg_gen_helper_1_1ii(do_ext, t0, t1, lsb, msb + 1);
2695 #if defined(TARGET_MIPS64)
2699 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1 + 32);
2704 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb + 32, msb + 1);
2709 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1);
2715 gen_load_gpr(t0, rt);
2716 tcg_gen_helper_1_2ii(do_ins, t0, t0, t1, lsb, msb - lsb + 1);
2718 #if defined(TARGET_MIPS64)
2722 gen_load_gpr(t0, rt);
2723 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1 + 32);
2728 gen_load_gpr(t0, rt);
2729 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb + 32, msb - lsb + 1);
2734 gen_load_gpr(t0, rt);
2735 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1);
2740 MIPS_INVAL("bitops");
2741 generate_exception(ctx, EXCP_RI);
2746 gen_store_gpr(t0, rt);
2751 #ifndef CONFIG_USER_ONLY
2752 /* CP0 (MMU and control) */
2753 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2755 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2757 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2758 tcg_gen_ext_i32_tl(t, r_tmp);
2759 tcg_temp_free(r_tmp);
2762 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2764 tcg_gen_ld_tl(t, cpu_env, off);
2765 tcg_gen_ext32s_tl(t, t);
2768 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2770 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2772 tcg_gen_trunc_tl_i32(r_tmp, t);
2773 tcg_gen_st_i32(r_tmp, cpu_env, off);
2774 tcg_temp_free(r_tmp);
2777 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2779 tcg_gen_ext32s_tl(t, t);
2780 tcg_gen_st_tl(t, cpu_env, off);
2783 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2785 const char *rn = "invalid";
2788 check_insn(env, ctx, ISA_MIPS32);
2794 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2798 check_insn(env, ctx, ASE_MT);
2799 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2803 check_insn(env, ctx, ASE_MT);
2804 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2808 check_insn(env, ctx, ASE_MT);
2809 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2819 tcg_gen_helper_1_0(do_mfc0_random, t0);
2823 check_insn(env, ctx, ASE_MT);
2824 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2828 check_insn(env, ctx, ASE_MT);
2829 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2833 check_insn(env, ctx, ASE_MT);
2834 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2838 check_insn(env, ctx, ASE_MT);
2839 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2843 check_insn(env, ctx, ASE_MT);
2844 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2848 check_insn(env, ctx, ASE_MT);
2849 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2850 rn = "VPEScheFBack";
2853 check_insn(env, ctx, ASE_MT);
2854 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2864 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2865 tcg_gen_ext32s_tl(t0, t0);
2869 check_insn(env, ctx, ASE_MT);
2870 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2874 check_insn(env, ctx, ASE_MT);
2875 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2879 check_insn(env, ctx, ASE_MT);
2880 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2884 check_insn(env, ctx, ASE_MT);
2885 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2889 check_insn(env, ctx, ASE_MT);
2890 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2894 check_insn(env, ctx, ASE_MT);
2895 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2899 check_insn(env, ctx, ASE_MT);
2900 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2910 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2911 tcg_gen_ext32s_tl(t0, t0);
2921 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2922 tcg_gen_ext32s_tl(t0, t0);
2926 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2927 rn = "ContextConfig";
2936 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2940 check_insn(env, ctx, ISA_MIPS32R2);
2941 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2951 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2955 check_insn(env, ctx, ISA_MIPS32R2);
2956 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2960 check_insn(env, ctx, ISA_MIPS32R2);
2961 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2965 check_insn(env, ctx, ISA_MIPS32R2);
2966 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2970 check_insn(env, ctx, ISA_MIPS32R2);
2971 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2975 check_insn(env, ctx, ISA_MIPS32R2);
2976 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2986 check_insn(env, ctx, ISA_MIPS32R2);
2987 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
2997 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
2998 tcg_gen_ext32s_tl(t0, t0);
3008 /* Mark as an IO operation because we read the time. */
3011 tcg_gen_helper_1_0(do_mfc0_count, t0);
3014 ctx->bstate = BS_STOP;
3018 /* 6,7 are implementation dependent */
3026 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3027 tcg_gen_ext32s_tl(t0, t0);
3037 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3040 /* 6,7 are implementation dependent */
3048 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3052 check_insn(env, ctx, ISA_MIPS32R2);
3053 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3057 check_insn(env, ctx, ISA_MIPS32R2);
3058 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3062 check_insn(env, ctx, ISA_MIPS32R2);
3063 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3073 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3083 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3084 tcg_gen_ext32s_tl(t0, t0);
3094 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3098 check_insn(env, ctx, ISA_MIPS32R2);
3099 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3109 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3113 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3117 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3121 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3124 /* 4,5 are reserved */
3125 /* 6,7 are implementation dependent */
3127 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3131 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3141 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3151 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3161 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3171 #if defined(TARGET_MIPS64)
3172 check_insn(env, ctx, ISA_MIPS3);
3173 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3174 tcg_gen_ext32s_tl(t0, t0);
3183 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3186 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3195 rn = "'Diagnostic"; /* implementation dependent */
3200 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3204 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3205 rn = "TraceControl";
3208 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3209 rn = "TraceControl2";
3212 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3213 rn = "UserTraceData";
3216 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3227 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3228 tcg_gen_ext32s_tl(t0, t0);
3238 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3239 rn = "Performance0";
3242 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3243 rn = "Performance1";
3246 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3247 rn = "Performance2";
3250 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3251 rn = "Performance3";
3254 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3255 rn = "Performance4";
3258 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3259 rn = "Performance5";
3262 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3263 rn = "Performance6";
3266 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3267 rn = "Performance7";
3292 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3299 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3312 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3319 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3329 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3330 tcg_gen_ext32s_tl(t0, t0);
3341 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3351 #if defined MIPS_DEBUG_DISAS
3352 if (loglevel & CPU_LOG_TB_IN_ASM) {
3353 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3360 #if defined MIPS_DEBUG_DISAS
3361 if (loglevel & CPU_LOG_TB_IN_ASM) {
3362 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3366 generate_exception(ctx, EXCP_RI);
3369 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3371 const char *rn = "invalid";
3374 check_insn(env, ctx, ISA_MIPS32);
3383 tcg_gen_helper_0_1(do_mtc0_index, t0);
3387 check_insn(env, ctx, ASE_MT);
3388 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3392 check_insn(env, ctx, ASE_MT);
3397 check_insn(env, ctx, ASE_MT);
3412 check_insn(env, ctx, ASE_MT);
3413 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3417 check_insn(env, ctx, ASE_MT);
3418 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3422 check_insn(env, ctx, ASE_MT);
3423 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3427 check_insn(env, ctx, ASE_MT);
3428 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3432 check_insn(env, ctx, ASE_MT);
3433 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3437 check_insn(env, ctx, ASE_MT);
3438 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3439 rn = "VPEScheFBack";
3442 check_insn(env, ctx, ASE_MT);
3443 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3453 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3457 check_insn(env, ctx, ASE_MT);
3458 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3462 check_insn(env, ctx, ASE_MT);
3463 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3467 check_insn(env, ctx, ASE_MT);
3468 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3472 check_insn(env, ctx, ASE_MT);
3473 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3477 check_insn(env, ctx, ASE_MT);
3478 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3482 check_insn(env, ctx, ASE_MT);
3483 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3487 check_insn(env, ctx, ASE_MT);
3488 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3498 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3508 tcg_gen_helper_0_1(do_mtc0_context, t0);
3512 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3513 rn = "ContextConfig";
3522 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3526 check_insn(env, ctx, ISA_MIPS32R2);
3527 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3537 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3541 check_insn(env, ctx, ISA_MIPS32R2);
3542 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3546 check_insn(env, ctx, ISA_MIPS32R2);
3547 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3551 check_insn(env, ctx, ISA_MIPS32R2);
3552 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3556 check_insn(env, ctx, ISA_MIPS32R2);
3557 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3561 check_insn(env, ctx, ISA_MIPS32R2);
3562 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3572 check_insn(env, ctx, ISA_MIPS32R2);
3573 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3587 tcg_gen_helper_0_1(do_mtc0_count, t0);
3590 /* 6,7 are implementation dependent */
3594 /* Stop translation as we may have switched the execution mode */
3595 ctx->bstate = BS_STOP;
3600 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3610 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3613 /* 6,7 are implementation dependent */
3617 /* Stop translation as we may have switched the execution mode */
3618 ctx->bstate = BS_STOP;
3623 tcg_gen_helper_0_1(do_mtc0_status, t0);
3624 /* BS_STOP isn't good enough here, hflags may have changed. */
3625 gen_save_pc(ctx->pc + 4);
3626 ctx->bstate = BS_EXCP;
3630 check_insn(env, ctx, ISA_MIPS32R2);
3631 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3632 /* Stop translation as we may have switched the execution mode */
3633 ctx->bstate = BS_STOP;
3637 check_insn(env, ctx, ISA_MIPS32R2);
3638 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3639 /* Stop translation as we may have switched the execution mode */
3640 ctx->bstate = BS_STOP;
3644 check_insn(env, ctx, ISA_MIPS32R2);
3645 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3646 /* Stop translation as we may have switched the execution mode */
3647 ctx->bstate = BS_STOP;
3657 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3663 /* Stop translation as we may have switched the execution mode */
3664 ctx->bstate = BS_STOP;
3669 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3683 check_insn(env, ctx, ISA_MIPS32R2);
3684 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3694 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3696 /* Stop translation as we may have switched the execution mode */
3697 ctx->bstate = BS_STOP;
3700 /* ignored, read only */
3704 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3706 /* Stop translation as we may have switched the execution mode */
3707 ctx->bstate = BS_STOP;
3710 /* ignored, read only */
3713 /* 4,5 are reserved */
3714 /* 6,7 are implementation dependent */
3724 rn = "Invalid config selector";
3741 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3751 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3761 #if defined(TARGET_MIPS64)
3762 check_insn(env, ctx, ISA_MIPS3);
3763 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3772 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3775 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3784 rn = "Diagnostic"; /* implementation dependent */
3789 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3790 /* BS_STOP isn't good enough here, hflags may have changed. */
3791 gen_save_pc(ctx->pc + 4);
3792 ctx->bstate = BS_EXCP;
3796 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3797 rn = "TraceControl";
3798 /* Stop translation as we may have switched the execution mode */
3799 ctx->bstate = BS_STOP;
3802 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3803 rn = "TraceControl2";
3804 /* Stop translation as we may have switched the execution mode */
3805 ctx->bstate = BS_STOP;
3808 /* Stop translation as we may have switched the execution mode */
3809 ctx->bstate = BS_STOP;
3810 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3811 rn = "UserTraceData";
3812 /* Stop translation as we may have switched the execution mode */
3813 ctx->bstate = BS_STOP;
3816 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3817 /* Stop translation as we may have switched the execution mode */
3818 ctx->bstate = BS_STOP;
3829 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3839 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3840 rn = "Performance0";
3843 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3844 rn = "Performance1";
3847 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3848 rn = "Performance2";
3851 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3852 rn = "Performance3";
3855 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3856 rn = "Performance4";
3859 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3860 rn = "Performance5";
3863 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3864 rn = "Performance6";
3867 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3868 rn = "Performance7";
3894 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3901 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3914 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3921 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
3932 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3943 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3949 /* Stop translation as we may have switched the execution mode */
3950 ctx->bstate = BS_STOP;
3955 #if defined MIPS_DEBUG_DISAS
3956 if (loglevel & CPU_LOG_TB_IN_ASM) {
3957 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3961 /* For simplicity assume that all writes can cause interrupts. */
3964 ctx->bstate = BS_STOP;
3969 #if defined MIPS_DEBUG_DISAS
3970 if (loglevel & CPU_LOG_TB_IN_ASM) {
3971 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3975 generate_exception(ctx, EXCP_RI);
3978 #if defined(TARGET_MIPS64)
3979 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3981 const char *rn = "invalid";
3984 check_insn(env, ctx, ISA_MIPS64);
3990 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
3994 check_insn(env, ctx, ASE_MT);
3995 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
3999 check_insn(env, ctx, ASE_MT);
4000 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4004 check_insn(env, ctx, ASE_MT);
4005 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4015 tcg_gen_helper_1_0(do_mfc0_random, t0);
4019 check_insn(env, ctx, ASE_MT);
4020 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4024 check_insn(env, ctx, ASE_MT);
4025 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4029 check_insn(env, ctx, ASE_MT);
4030 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4034 check_insn(env, ctx, ASE_MT);
4035 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4039 check_insn(env, ctx, ASE_MT);
4040 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4044 check_insn(env, ctx, ASE_MT);
4045 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4046 rn = "VPEScheFBack";
4049 check_insn(env, ctx, ASE_MT);
4050 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4060 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4064 check_insn(env, ctx, ASE_MT);
4065 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4069 check_insn(env, ctx, ASE_MT);
4070 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4074 check_insn(env, ctx, ASE_MT);
4075 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4079 check_insn(env, ctx, ASE_MT);
4080 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4084 check_insn(env, ctx, ASE_MT);
4085 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4089 check_insn(env, ctx, ASE_MT);
4090 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4094 check_insn(env, ctx, ASE_MT);
4095 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4105 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4115 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4119 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4120 rn = "ContextConfig";
4129 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4133 check_insn(env, ctx, ISA_MIPS32R2);
4134 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4144 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4148 check_insn(env, ctx, ISA_MIPS32R2);
4149 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4153 check_insn(env, ctx, ISA_MIPS32R2);
4154 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4158 check_insn(env, ctx, ISA_MIPS32R2);
4159 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4163 check_insn(env, ctx, ISA_MIPS32R2);
4164 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4168 check_insn(env, ctx, ISA_MIPS32R2);
4169 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4179 check_insn(env, ctx, ISA_MIPS32R2);
4180 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4190 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4200 /* Mark as an IO operation because we read the time. */
4203 tcg_gen_helper_1_0(do_mfc0_count, t0);
4206 ctx->bstate = BS_STOP;
4210 /* 6,7 are implementation dependent */
4218 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4228 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4231 /* 6,7 are implementation dependent */
4239 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4243 check_insn(env, ctx, ISA_MIPS32R2);
4244 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4248 check_insn(env, ctx, ISA_MIPS32R2);
4249 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4253 check_insn(env, ctx, ISA_MIPS32R2);
4254 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4264 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4274 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4284 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4288 check_insn(env, ctx, ISA_MIPS32R2);
4289 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4299 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4303 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4307 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4311 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4314 /* 6,7 are implementation dependent */
4316 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4320 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4330 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4340 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4350 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4360 check_insn(env, ctx, ISA_MIPS3);
4361 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4369 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4372 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4381 rn = "'Diagnostic"; /* implementation dependent */
4386 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4390 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4391 rn = "TraceControl";
4394 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4395 rn = "TraceControl2";
4398 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4399 rn = "UserTraceData";
4402 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4413 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4423 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4424 rn = "Performance0";
4427 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4428 rn = "Performance1";
4431 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4432 rn = "Performance2";
4435 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4436 rn = "Performance3";
4439 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4440 rn = "Performance4";
4443 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4444 rn = "Performance5";
4447 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4448 rn = "Performance6";
4451 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4452 rn = "Performance7";
4477 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4484 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4497 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4504 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4514 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4525 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4535 #if defined MIPS_DEBUG_DISAS
4536 if (loglevel & CPU_LOG_TB_IN_ASM) {
4537 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4544 #if defined MIPS_DEBUG_DISAS
4545 if (loglevel & CPU_LOG_TB_IN_ASM) {
4546 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4550 generate_exception(ctx, EXCP_RI);
4553 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4555 const char *rn = "invalid";
4558 check_insn(env, ctx, ISA_MIPS64);
4567 tcg_gen_helper_0_1(do_mtc0_index, t0);
4571 check_insn(env, ctx, ASE_MT);
4572 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4576 check_insn(env, ctx, ASE_MT);
4581 check_insn(env, ctx, ASE_MT);
4596 check_insn(env, ctx, ASE_MT);
4597 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4601 check_insn(env, ctx, ASE_MT);
4602 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4606 check_insn(env, ctx, ASE_MT);
4607 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4611 check_insn(env, ctx, ASE_MT);
4612 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4616 check_insn(env, ctx, ASE_MT);
4617 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4621 check_insn(env, ctx, ASE_MT);
4622 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4623 rn = "VPEScheFBack";
4626 check_insn(env, ctx, ASE_MT);
4627 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4637 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4641 check_insn(env, ctx, ASE_MT);
4642 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4646 check_insn(env, ctx, ASE_MT);
4647 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4651 check_insn(env, ctx, ASE_MT);
4652 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4656 check_insn(env, ctx, ASE_MT);
4657 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4661 check_insn(env, ctx, ASE_MT);
4662 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4666 check_insn(env, ctx, ASE_MT);
4667 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4671 check_insn(env, ctx, ASE_MT);
4672 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4682 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4692 tcg_gen_helper_0_1(do_mtc0_context, t0);
4696 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4697 rn = "ContextConfig";
4706 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4710 check_insn(env, ctx, ISA_MIPS32R2);
4711 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4721 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4725 check_insn(env, ctx, ISA_MIPS32R2);
4726 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4730 check_insn(env, ctx, ISA_MIPS32R2);
4731 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4735 check_insn(env, ctx, ISA_MIPS32R2);
4736 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4740 check_insn(env, ctx, ISA_MIPS32R2);
4741 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4745 check_insn(env, ctx, ISA_MIPS32R2);
4746 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4756 check_insn(env, ctx, ISA_MIPS32R2);
4757 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4771 tcg_gen_helper_0_1(do_mtc0_count, t0);
4774 /* 6,7 are implementation dependent */
4778 /* Stop translation as we may have switched the execution mode */
4779 ctx->bstate = BS_STOP;
4784 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4794 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4797 /* 6,7 are implementation dependent */
4801 /* Stop translation as we may have switched the execution mode */
4802 ctx->bstate = BS_STOP;
4807 tcg_gen_helper_0_1(do_mtc0_status, t0);
4808 /* BS_STOP isn't good enough here, hflags may have changed. */
4809 gen_save_pc(ctx->pc + 4);
4810 ctx->bstate = BS_EXCP;
4814 check_insn(env, ctx, ISA_MIPS32R2);
4815 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4816 /* Stop translation as we may have switched the execution mode */
4817 ctx->bstate = BS_STOP;
4821 check_insn(env, ctx, ISA_MIPS32R2);
4822 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4823 /* Stop translation as we may have switched the execution mode */
4824 ctx->bstate = BS_STOP;
4828 check_insn(env, ctx, ISA_MIPS32R2);
4829 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4830 /* Stop translation as we may have switched the execution mode */
4831 ctx->bstate = BS_STOP;
4841 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4847 /* Stop translation as we may have switched the execution mode */
4848 ctx->bstate = BS_STOP;
4853 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4867 check_insn(env, ctx, ISA_MIPS32R2);
4868 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4878 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4880 /* Stop translation as we may have switched the execution mode */
4881 ctx->bstate = BS_STOP;
4888 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4890 /* Stop translation as we may have switched the execution mode */
4891 ctx->bstate = BS_STOP;
4897 /* 6,7 are implementation dependent */
4899 rn = "Invalid config selector";
4916 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4926 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
4936 check_insn(env, ctx, ISA_MIPS3);
4937 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
4945 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4948 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
4957 rn = "Diagnostic"; /* implementation dependent */
4962 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
4963 /* BS_STOP isn't good enough here, hflags may have changed. */
4964 gen_save_pc(ctx->pc + 4);
4965 ctx->bstate = BS_EXCP;
4969 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
4970 /* Stop translation as we may have switched the execution mode */
4971 ctx->bstate = BS_STOP;
4972 rn = "TraceControl";
4975 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
4976 /* Stop translation as we may have switched the execution mode */
4977 ctx->bstate = BS_STOP;
4978 rn = "TraceControl2";
4981 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
4982 /* Stop translation as we may have switched the execution mode */
4983 ctx->bstate = BS_STOP;
4984 rn = "UserTraceData";
4987 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
4988 /* Stop translation as we may have switched the execution mode */
4989 ctx->bstate = BS_STOP;
5000 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5010 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5011 rn = "Performance0";
5014 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5015 rn = "Performance1";
5018 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5019 rn = "Performance2";
5022 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5023 rn = "Performance3";
5026 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5027 rn = "Performance4";
5030 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5031 rn = "Performance5";
5034 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5035 rn = "Performance6";
5038 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5039 rn = "Performance7";
5065 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5072 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5085 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5092 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5103 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5114 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5120 /* Stop translation as we may have switched the execution mode */
5121 ctx->bstate = BS_STOP;
5126 #if defined MIPS_DEBUG_DISAS
5127 if (loglevel & CPU_LOG_TB_IN_ASM) {
5128 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5132 /* For simplicity assume that all writes can cause interrupts. */
5135 ctx->bstate = BS_STOP;
5140 #if defined MIPS_DEBUG_DISAS
5141 if (loglevel & CPU_LOG_TB_IN_ASM) {
5142 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5146 generate_exception(ctx, EXCP_RI);
5148 #endif /* TARGET_MIPS64 */
5150 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5151 int u, int sel, int h)
5153 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5154 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5156 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5157 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5158 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5159 tcg_gen_movi_tl(t0, -1);
5160 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5161 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5162 tcg_gen_movi_tl(t0, -1);
5168 tcg_gen_helper_1_0(do_mftc0_tcstatus, t0);
5171 tcg_gen_helper_1_0(do_mftc0_tcbind, t0);
5174 tcg_gen_helper_1_0(do_mftc0_tcrestart, t0);
5177 tcg_gen_helper_1_0(do_mftc0_tchalt, t0);
5180 tcg_gen_helper_1_0(do_mftc0_tccontext, t0);
5183 tcg_gen_helper_1_0(do_mftc0_tcschedule, t0);
5186 tcg_gen_helper_1_0(do_mftc0_tcschefback, t0);
5189 gen_mfc0(env, ctx, t0, rt, sel);
5196 tcg_gen_helper_1_0(do_mftc0_entryhi, t0);
5199 gen_mfc0(env, ctx, t0, rt, sel);
5205 tcg_gen_helper_1_0(do_mftc0_status, t0);
5208 gen_mfc0(env, ctx, t0, rt, sel);
5214 tcg_gen_helper_1_0(do_mftc0_debug, t0);
5217 gen_mfc0(env, ctx, t0, rt, sel);
5222 gen_mfc0(env, ctx, t0, rt, sel);
5224 } else switch (sel) {
5225 /* GPR registers. */
5227 tcg_gen_helper_1_i(do_mftgpr, t0, rt);
5229 /* Auxiliary CPU registers */
5233 tcg_gen_helper_1_i(do_mftlo, t0, 0);
5236 tcg_gen_helper_1_i(do_mfthi, t0, 0);
5239 tcg_gen_helper_1_i(do_mftacx, t0, 0);
5242 tcg_gen_helper_1_i(do_mftlo, t0, 1);
5245 tcg_gen_helper_1_i(do_mfthi, t0, 1);
5248 tcg_gen_helper_1_i(do_mftacx, t0, 1);
5251 tcg_gen_helper_1_i(do_mftlo, t0, 2);
5254 tcg_gen_helper_1_i(do_mfthi, t0, 2);
5257 tcg_gen_helper_1_i(do_mftacx, t0, 2);
5260 tcg_gen_helper_1_i(do_mftlo, t0, 3);
5263 tcg_gen_helper_1_i(do_mfthi, t0, 3);
5266 tcg_gen_helper_1_i(do_mftacx, t0, 3);
5269 tcg_gen_helper_1_0(do_mftdsp, t0);
5275 /* Floating point (COP1). */
5277 /* XXX: For now we support only a single FPU context. */
5279 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5281 gen_load_fpr32(fp0, rt);
5282 tcg_gen_ext_i32_tl(t0, fp0);
5285 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5287 gen_load_fpr32h(fp0, rt);
5288 tcg_gen_ext_i32_tl(t0, fp0);
5293 /* XXX: For now we support only a single FPU context. */
5294 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5296 /* COP2: Not implemented. */
5303 #if defined MIPS_DEBUG_DISAS
5304 if (loglevel & CPU_LOG_TB_IN_ASM) {
5305 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5309 gen_store_gpr(t0, rd);
5315 #if defined MIPS_DEBUG_DISAS
5316 if (loglevel & CPU_LOG_TB_IN_ASM) {
5317 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5321 generate_exception(ctx, EXCP_RI);
5324 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5325 int u, int sel, int h)
5327 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5328 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5330 gen_load_gpr(t0, rt);
5331 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5332 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5333 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5335 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5336 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5343 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5346 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5349 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5352 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5355 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5358 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5361 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5364 gen_mtc0(env, ctx, t0, rd, sel);
5371 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5374 gen_mtc0(env, ctx, t0, rd, sel);
5380 tcg_gen_helper_0_1(do_mttc0_status, t0);
5383 gen_mtc0(env, ctx, t0, rd, sel);
5389 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5392 gen_mtc0(env, ctx, t0, rd, sel);
5397 gen_mtc0(env, ctx, t0, rd, sel);
5399 } else switch (sel) {
5400 /* GPR registers. */
5402 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5404 /* Auxiliary CPU registers */
5408 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5411 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5414 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5417 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5420 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5423 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5426 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5429 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5432 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5435 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5438 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5441 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5444 tcg_gen_helper_0_1(do_mttdsp, t0);
5450 /* Floating point (COP1). */
5452 /* XXX: For now we support only a single FPU context. */
5454 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5456 tcg_gen_trunc_tl_i32(fp0, t0);
5457 gen_store_fpr32(fp0, rd);
5460 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5462 tcg_gen_trunc_tl_i32(fp0, t0);
5463 gen_store_fpr32h(fp0, rd);
5468 /* XXX: For now we support only a single FPU context. */
5469 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5471 /* COP2: Not implemented. */
5478 #if defined MIPS_DEBUG_DISAS
5479 if (loglevel & CPU_LOG_TB_IN_ASM) {
5480 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5489 #if defined MIPS_DEBUG_DISAS
5490 if (loglevel & CPU_LOG_TB_IN_ASM) {
5491 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5495 generate_exception(ctx, EXCP_RI);
5498 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5500 const char *opn = "ldst";
5509 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5511 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5512 gen_store_gpr(t0, rt);
5519 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5521 gen_load_gpr(t0, rt);
5522 save_cpu_state(ctx, 1);
5523 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5528 #if defined(TARGET_MIPS64)
5530 check_insn(env, ctx, ISA_MIPS3);
5536 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5538 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5539 gen_store_gpr(t0, rt);
5545 check_insn(env, ctx, ISA_MIPS3);
5547 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5549 gen_load_gpr(t0, rt);
5550 save_cpu_state(ctx, 1);
5551 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5558 check_insn(env, ctx, ASE_MT);
5563 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5564 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5568 check_insn(env, ctx, ASE_MT);
5569 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5570 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5575 if (!env->tlb->do_tlbwi)
5577 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5581 if (!env->tlb->do_tlbwr)
5583 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5587 if (!env->tlb->do_tlbp)
5589 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5593 if (!env->tlb->do_tlbr)
5595 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5599 check_insn(env, ctx, ISA_MIPS2);
5600 save_cpu_state(ctx, 1);
5601 tcg_gen_helper_0_0(do_eret);
5602 ctx->bstate = BS_EXCP;
5606 check_insn(env, ctx, ISA_MIPS32);
5607 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5609 generate_exception(ctx, EXCP_RI);
5611 save_cpu_state(ctx, 1);
5612 tcg_gen_helper_0_0(do_deret);
5613 ctx->bstate = BS_EXCP;
5618 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5619 /* If we get an exception, we want to restart at next instruction */
5621 save_cpu_state(ctx, 1);
5623 tcg_gen_helper_0_0(do_wait);
5624 ctx->bstate = BS_EXCP;
5629 generate_exception(ctx, EXCP_RI);
5632 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5634 #endif /* !CONFIG_USER_ONLY */
5636 /* CP1 Branches (before delay slot) */
5637 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5638 int32_t cc, int32_t offset)
5640 target_ulong btarget;
5641 const char *opn = "cp1 cond branch";
5642 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5643 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5646 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5648 btarget = ctx->pc + 4 + offset;
5653 int l1 = gen_new_label();
5654 int l2 = gen_new_label();
5655 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5657 get_fp_cond(r_tmp1);
5658 tcg_gen_ext_i32_tl(t0, r_tmp1);
5659 tcg_temp_free(r_tmp1);
5660 tcg_gen_not_tl(t0, t0);
5661 tcg_gen_movi_tl(t1, 0x1 << cc);
5662 tcg_gen_and_tl(t0, t0, t1);
5663 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5664 tcg_gen_movi_tl(t0, 0);
5667 tcg_gen_movi_tl(t0, 1);
5674 int l1 = gen_new_label();
5675 int l2 = gen_new_label();
5676 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5678 get_fp_cond(r_tmp1);
5679 tcg_gen_ext_i32_tl(t0, r_tmp1);
5680 tcg_temp_free(r_tmp1);
5681 tcg_gen_not_tl(t0, t0);
5682 tcg_gen_movi_tl(t1, 0x1 << cc);
5683 tcg_gen_and_tl(t0, t0, t1);
5684 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5685 tcg_gen_movi_tl(t0, 0);
5688 tcg_gen_movi_tl(t0, 1);
5695 int l1 = gen_new_label();
5696 int l2 = gen_new_label();
5697 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5699 get_fp_cond(r_tmp1);
5700 tcg_gen_ext_i32_tl(t0, r_tmp1);
5701 tcg_temp_free(r_tmp1);
5702 tcg_gen_movi_tl(t1, 0x1 << cc);
5703 tcg_gen_and_tl(t0, t0, t1);
5704 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5705 tcg_gen_movi_tl(t0, 0);
5708 tcg_gen_movi_tl(t0, 1);
5715 int l1 = gen_new_label();
5716 int l2 = gen_new_label();
5717 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5719 get_fp_cond(r_tmp1);
5720 tcg_gen_ext_i32_tl(t0, r_tmp1);
5721 tcg_temp_free(r_tmp1);
5722 tcg_gen_movi_tl(t1, 0x1 << cc);
5723 tcg_gen_and_tl(t0, t0, t1);
5724 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5725 tcg_gen_movi_tl(t0, 0);
5728 tcg_gen_movi_tl(t0, 1);
5733 ctx->hflags |= MIPS_HFLAG_BL;
5734 tcg_gen_trunc_tl_i32(bcond, t0);
5738 int l1 = gen_new_label();
5739 int l2 = gen_new_label();
5740 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5742 get_fp_cond(r_tmp1);
5743 tcg_gen_ext_i32_tl(t0, r_tmp1);
5744 tcg_temp_free(r_tmp1);
5745 tcg_gen_not_tl(t0, t0);
5746 tcg_gen_movi_tl(t1, 0x3 << cc);
5747 tcg_gen_and_tl(t0, t0, t1);
5748 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5749 tcg_gen_movi_tl(t0, 0);
5752 tcg_gen_movi_tl(t0, 1);
5759 int l1 = gen_new_label();
5760 int l2 = gen_new_label();
5761 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5763 get_fp_cond(r_tmp1);
5764 tcg_gen_ext_i32_tl(t0, r_tmp1);
5765 tcg_temp_free(r_tmp1);
5766 tcg_gen_movi_tl(t1, 0x3 << cc);
5767 tcg_gen_and_tl(t0, t0, t1);
5768 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5769 tcg_gen_movi_tl(t0, 0);
5772 tcg_gen_movi_tl(t0, 1);
5779 int l1 = gen_new_label();
5780 int l2 = gen_new_label();
5781 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5783 get_fp_cond(r_tmp1);
5784 tcg_gen_ext_i32_tl(t0, r_tmp1);
5785 tcg_temp_free(r_tmp1);
5786 tcg_gen_not_tl(t0, t0);
5787 tcg_gen_movi_tl(t1, 0xf << cc);
5788 tcg_gen_and_tl(t0, t0, t1);
5789 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5790 tcg_gen_movi_tl(t0, 0);
5793 tcg_gen_movi_tl(t0, 1);
5800 int l1 = gen_new_label();
5801 int l2 = gen_new_label();
5802 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5804 get_fp_cond(r_tmp1);
5805 tcg_gen_ext_i32_tl(t0, r_tmp1);
5806 tcg_temp_free(r_tmp1);
5807 tcg_gen_movi_tl(t1, 0xf << cc);
5808 tcg_gen_and_tl(t0, t0, t1);
5809 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5810 tcg_gen_movi_tl(t0, 0);
5813 tcg_gen_movi_tl(t0, 1);
5818 ctx->hflags |= MIPS_HFLAG_BC;
5819 tcg_gen_trunc_tl_i32(bcond, t0);
5823 generate_exception (ctx, EXCP_RI);
5826 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5827 ctx->hflags, btarget);
5828 ctx->btarget = btarget;
5835 /* Coprocessor 1 (FPU) */
5837 #define FOP(func, fmt) (((fmt) << 21) | (func))
5839 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5841 const char *opn = "cp1 move";
5842 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5847 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5849 gen_load_fpr32(fp0, fs);
5850 tcg_gen_ext_i32_tl(t0, fp0);
5853 gen_store_gpr(t0, rt);
5857 gen_load_gpr(t0, rt);
5859 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5861 tcg_gen_trunc_tl_i32(fp0, t0);
5862 gen_store_fpr32(fp0, fs);
5868 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5869 gen_store_gpr(t0, rt);
5873 gen_load_gpr(t0, rt);
5874 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5879 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5881 gen_load_fpr64(ctx, fp0, fs);
5882 tcg_gen_mov_tl(t0, fp0);
5885 gen_store_gpr(t0, rt);
5889 gen_load_gpr(t0, rt);
5891 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5893 tcg_gen_mov_tl(fp0, t0);
5894 gen_store_fpr64(ctx, fp0, fs);
5901 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5903 gen_load_fpr32h(fp0, fs);
5904 tcg_gen_ext_i32_tl(t0, fp0);
5907 gen_store_gpr(t0, rt);
5911 gen_load_gpr(t0, rt);
5913 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5915 tcg_gen_trunc_tl_i32(fp0, t0);
5916 gen_store_fpr32h(fp0, fs);
5923 generate_exception (ctx, EXCP_RI);
5926 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5932 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5934 int l1 = gen_new_label();
5937 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5938 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5939 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
5942 ccbit = 1 << (24 + cc);
5950 gen_load_gpr(t0, rd);
5951 gen_load_gpr(t1, rs);
5952 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5953 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5954 tcg_temp_free(r_tmp);
5956 tcg_gen_mov_tl(t0, t1);
5960 gen_store_gpr(t0, rd);
5964 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5968 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
5969 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
5970 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
5971 int l1 = gen_new_label();
5974 ccbit = 1 << (24 + cc);
5983 gen_load_fpr32(fp0, fs);
5984 gen_load_fpr32(fp1, fd);
5985 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5986 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5987 tcg_gen_mov_i32(fp1, fp0);
5990 tcg_temp_free(r_tmp1);
5991 gen_store_fpr32(fp1, fd);
5995 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
5999 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6000 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6001 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I64);
6002 int l1 = gen_new_label();
6005 ccbit = 1 << (24 + cc);
6014 gen_load_fpr64(ctx, fp0, fs);
6015 gen_load_fpr64(ctx, fp1, fd);
6016 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6017 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6018 tcg_gen_mov_i64(fp1, fp0);
6021 tcg_temp_free(r_tmp1);
6022 gen_store_fpr64(ctx, fp1, fd);
6026 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
6029 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6030 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6031 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6032 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
6033 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6034 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
6035 int l1 = gen_new_label();
6036 int l2 = gen_new_label();
6043 gen_load_fpr32(fp0, fs);
6044 gen_load_fpr32h(fph0, fs);
6045 gen_load_fpr32(fp1, fd);
6046 gen_load_fpr32h(fph1, fd);
6047 get_fp_cond(r_tmp1);
6048 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6049 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6050 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6051 tcg_gen_mov_i32(fp1, fp0);
6054 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6055 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6056 tcg_gen_mov_i32(fph1, fph0);
6057 tcg_temp_free(fph0);
6059 tcg_temp_free(r_tmp1);
6060 tcg_temp_free(r_tmp2);
6061 gen_store_fpr32(fp1, fd);
6062 gen_store_fpr32h(fph1, fd);
6064 tcg_temp_free(fph1);
6068 static void gen_farith (DisasContext *ctx, uint32_t op1,
6069 int ft, int fs, int fd, int cc)
6071 const char *opn = "farith";
6072 const char *condnames[] = {
6090 const char *condnames_abs[] = {
6108 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6109 uint32_t func = ctx->opcode & 0x3f;
6111 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6114 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6115 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6117 gen_load_fpr32(fp0, fs);
6118 gen_load_fpr32(fp1, ft);
6119 tcg_gen_helper_1_2(do_float_add_s, fp0, fp0, fp1);
6121 gen_store_fpr32(fp0, fd);
6129 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6130 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6132 gen_load_fpr32(fp0, fs);
6133 gen_load_fpr32(fp1, ft);
6134 tcg_gen_helper_1_2(do_float_sub_s, fp0, fp0, fp1);
6136 gen_store_fpr32(fp0, fd);
6144 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6145 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6147 gen_load_fpr32(fp0, fs);
6148 gen_load_fpr32(fp1, ft);
6149 tcg_gen_helper_1_2(do_float_mul_s, fp0, fp0, fp1);
6151 gen_store_fpr32(fp0, fd);
6159 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6160 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6162 gen_load_fpr32(fp0, fs);
6163 gen_load_fpr32(fp1, ft);
6164 tcg_gen_helper_1_2(do_float_div_s, fp0, fp0, fp1);
6166 gen_store_fpr32(fp0, fd);
6174 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6176 gen_load_fpr32(fp0, fs);
6177 tcg_gen_helper_1_1(do_float_sqrt_s, fp0, fp0);
6178 gen_store_fpr32(fp0, fd);
6185 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6187 gen_load_fpr32(fp0, fs);
6188 tcg_gen_helper_1_1(do_float_abs_s, fp0, fp0);
6189 gen_store_fpr32(fp0, fd);
6196 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6198 gen_load_fpr32(fp0, fs);
6199 gen_store_fpr32(fp0, fd);
6206 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6208 gen_load_fpr32(fp0, fs);
6209 tcg_gen_helper_1_1(do_float_chs_s, fp0, fp0);
6210 gen_store_fpr32(fp0, fd);
6216 check_cp1_64bitmode(ctx);
6218 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6219 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6221 gen_load_fpr32(fp32, fs);
6222 tcg_gen_helper_1_1(do_float_roundl_s, fp64, fp32);
6223 tcg_temp_free(fp32);
6224 gen_store_fpr64(ctx, fp64, fd);
6225 tcg_temp_free(fp64);
6230 check_cp1_64bitmode(ctx);
6232 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6233 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6235 gen_load_fpr32(fp32, fs);
6236 tcg_gen_helper_1_1(do_float_truncl_s, fp64, fp32);
6237 tcg_temp_free(fp32);
6238 gen_store_fpr64(ctx, fp64, fd);
6239 tcg_temp_free(fp64);
6244 check_cp1_64bitmode(ctx);
6246 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6247 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6249 gen_load_fpr32(fp32, fs);
6250 tcg_gen_helper_1_1(do_float_ceill_s, fp64, fp32);
6251 tcg_temp_free(fp32);
6252 gen_store_fpr64(ctx, fp64, fd);
6253 tcg_temp_free(fp64);
6258 check_cp1_64bitmode(ctx);
6260 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6261 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6263 gen_load_fpr32(fp32, fs);
6264 tcg_gen_helper_1_1(do_float_floorl_s, fp64, fp32);
6265 tcg_temp_free(fp32);
6266 gen_store_fpr64(ctx, fp64, fd);
6267 tcg_temp_free(fp64);
6273 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6275 gen_load_fpr32(fp0, fs);
6276 tcg_gen_helper_1_1(do_float_roundw_s, fp0, fp0);
6277 gen_store_fpr32(fp0, fd);
6284 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6286 gen_load_fpr32(fp0, fs);
6287 tcg_gen_helper_1_1(do_float_truncw_s, fp0, fp0);
6288 gen_store_fpr32(fp0, fd);
6295 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6297 gen_load_fpr32(fp0, fs);
6298 tcg_gen_helper_1_1(do_float_ceilw_s, fp0, fp0);
6299 gen_store_fpr32(fp0, fd);
6306 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6308 gen_load_fpr32(fp0, fs);
6309 tcg_gen_helper_1_1(do_float_floorw_s, fp0, fp0);
6310 gen_store_fpr32(fp0, fd);
6316 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6321 int l1 = gen_new_label();
6322 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6323 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6325 gen_load_gpr(t0, ft);
6326 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6328 gen_load_fpr32(fp0, fs);
6329 gen_store_fpr32(fp0, fd);
6337 int l1 = gen_new_label();
6338 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6339 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6341 gen_load_gpr(t0, ft);
6342 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6344 gen_load_fpr32(fp0, fs);
6345 gen_store_fpr32(fp0, fd);
6354 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6356 gen_load_fpr32(fp0, fs);
6357 tcg_gen_helper_1_1(do_float_recip_s, fp0, fp0);
6358 gen_store_fpr32(fp0, fd);
6366 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6368 gen_load_fpr32(fp0, fs);
6369 tcg_gen_helper_1_1(do_float_rsqrt_s, fp0, fp0);
6370 gen_store_fpr32(fp0, fd);
6376 check_cp1_64bitmode(ctx);
6378 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6379 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6381 gen_load_fpr32(fp0, fs);
6382 gen_load_fpr32(fp1, fd);
6383 tcg_gen_helper_1_2(do_float_recip2_s, fp0, fp0, fp1);
6385 gen_store_fpr32(fp0, fd);
6391 check_cp1_64bitmode(ctx);
6393 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6395 gen_load_fpr32(fp0, fs);
6396 tcg_gen_helper_1_1(do_float_recip1_s, fp0, fp0);
6397 gen_store_fpr32(fp0, fd);
6403 check_cp1_64bitmode(ctx);
6405 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6407 gen_load_fpr32(fp0, fs);
6408 tcg_gen_helper_1_1(do_float_rsqrt1_s, fp0, fp0);
6409 gen_store_fpr32(fp0, fd);
6415 check_cp1_64bitmode(ctx);
6417 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6418 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6420 gen_load_fpr32(fp0, fs);
6421 gen_load_fpr32(fp1, ft);
6422 tcg_gen_helper_1_2(do_float_rsqrt2_s, fp0, fp0, fp1);
6424 gen_store_fpr32(fp0, fd);
6430 check_cp1_registers(ctx, fd);
6432 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6433 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6435 gen_load_fpr32(fp32, fs);
6436 tcg_gen_helper_1_1(do_float_cvtd_s, fp64, fp32);
6437 tcg_temp_free(fp32);
6438 gen_store_fpr64(ctx, fp64, fd);
6439 tcg_temp_free(fp64);
6445 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6447 gen_load_fpr32(fp0, fs);
6448 tcg_gen_helper_1_1(do_float_cvtw_s, fp0, fp0);
6449 gen_store_fpr32(fp0, fd);
6455 check_cp1_64bitmode(ctx);
6457 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6458 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6460 gen_load_fpr32(fp32, fs);
6461 tcg_gen_helper_1_1(do_float_cvtl_s, fp64, fp32);
6462 tcg_temp_free(fp32);
6463 gen_store_fpr64(ctx, fp64, fd);
6464 tcg_temp_free(fp64);
6469 check_cp1_64bitmode(ctx);
6471 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6472 TCGv fp32_0 = tcg_temp_new(TCG_TYPE_I32);
6473 TCGv fp32_1 = tcg_temp_new(TCG_TYPE_I32);
6475 gen_load_fpr32(fp32_0, fs);
6476 gen_load_fpr32(fp32_1, ft);
6477 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6478 tcg_temp_free(fp32_1);
6479 tcg_temp_free(fp32_0);
6480 gen_store_fpr64(ctx, fp64, fd);
6481 tcg_temp_free(fp64);
6502 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6503 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6505 gen_load_fpr32(fp0, fs);
6506 gen_load_fpr32(fp1, ft);
6507 if (ctx->opcode & (1 << 6)) {
6509 gen_cmpabs_s(func-48, fp0, fp1, cc);
6510 opn = condnames_abs[func-48];
6512 gen_cmp_s(func-48, fp0, fp1, cc);
6513 opn = condnames[func-48];
6520 check_cp1_registers(ctx, fs | ft | fd);
6522 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6523 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6525 gen_load_fpr64(ctx, fp0, fs);
6526 gen_load_fpr64(ctx, fp1, ft);
6527 tcg_gen_helper_1_2(do_float_add_d, fp0, fp0, fp1);
6529 gen_store_fpr64(ctx, fp0, fd);
6536 check_cp1_registers(ctx, fs | ft | fd);
6538 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6539 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6541 gen_load_fpr64(ctx, fp0, fs);
6542 gen_load_fpr64(ctx, fp1, ft);
6543 tcg_gen_helper_1_2(do_float_sub_d, fp0, fp0, fp1);
6545 gen_store_fpr64(ctx, fp0, fd);
6552 check_cp1_registers(ctx, fs | ft | fd);
6554 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6555 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6557 gen_load_fpr64(ctx, fp0, fs);
6558 gen_load_fpr64(ctx, fp1, ft);
6559 tcg_gen_helper_1_2(do_float_mul_d, fp0, fp0, fp1);
6561 gen_store_fpr64(ctx, fp0, fd);
6568 check_cp1_registers(ctx, fs | ft | fd);
6570 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6571 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6573 gen_load_fpr64(ctx, fp0, fs);
6574 gen_load_fpr64(ctx, fp1, ft);
6575 tcg_gen_helper_1_2(do_float_div_d, fp0, fp0, fp1);
6577 gen_store_fpr64(ctx, fp0, fd);
6584 check_cp1_registers(ctx, fs | fd);
6586 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6588 gen_load_fpr64(ctx, fp0, fs);
6589 tcg_gen_helper_1_1(do_float_sqrt_d, fp0, fp0);
6590 gen_store_fpr64(ctx, fp0, fd);
6596 check_cp1_registers(ctx, fs | fd);
6598 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6600 gen_load_fpr64(ctx, fp0, fs);
6601 tcg_gen_helper_1_1(do_float_abs_d, fp0, fp0);
6602 gen_store_fpr64(ctx, fp0, fd);
6608 check_cp1_registers(ctx, fs | fd);
6610 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6612 gen_load_fpr64(ctx, fp0, fs);
6613 gen_store_fpr64(ctx, fp0, fd);
6619 check_cp1_registers(ctx, fs | fd);
6621 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6623 gen_load_fpr64(ctx, fp0, fs);
6624 tcg_gen_helper_1_1(do_float_chs_d, fp0, fp0);
6625 gen_store_fpr64(ctx, fp0, fd);
6631 check_cp1_64bitmode(ctx);
6633 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6635 gen_load_fpr64(ctx, fp0, fs);
6636 tcg_gen_helper_1_1(do_float_roundl_d, fp0, fp0);
6637 gen_store_fpr64(ctx, fp0, fd);
6643 check_cp1_64bitmode(ctx);
6645 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6647 gen_load_fpr64(ctx, fp0, fs);
6648 tcg_gen_helper_1_1(do_float_truncl_d, fp0, fp0);
6649 gen_store_fpr64(ctx, fp0, fd);
6655 check_cp1_64bitmode(ctx);
6657 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6659 gen_load_fpr64(ctx, fp0, fs);
6660 tcg_gen_helper_1_1(do_float_ceill_d, fp0, fp0);
6661 gen_store_fpr64(ctx, fp0, fd);
6667 check_cp1_64bitmode(ctx);
6669 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6671 gen_load_fpr64(ctx, fp0, fs);
6672 tcg_gen_helper_1_1(do_float_floorl_d, fp0, fp0);
6673 gen_store_fpr64(ctx, fp0, fd);
6679 check_cp1_registers(ctx, fs);
6681 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6682 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6684 gen_load_fpr64(ctx, fp64, fs);
6685 tcg_gen_helper_1_1(do_float_roundw_d, fp32, fp64);
6686 tcg_temp_free(fp64);
6687 gen_store_fpr32(fp32, fd);
6688 tcg_temp_free(fp32);
6693 check_cp1_registers(ctx, fs);
6695 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6696 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6698 gen_load_fpr64(ctx, fp64, fs);
6699 tcg_gen_helper_1_1(do_float_truncw_d, fp32, fp64);
6700 tcg_temp_free(fp64);
6701 gen_store_fpr32(fp32, fd);
6702 tcg_temp_free(fp32);
6707 check_cp1_registers(ctx, fs);
6709 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6710 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6712 gen_load_fpr64(ctx, fp64, fs);
6713 tcg_gen_helper_1_1(do_float_ceilw_d, fp32, fp64);
6714 tcg_temp_free(fp64);
6715 gen_store_fpr32(fp32, fd);
6716 tcg_temp_free(fp32);
6721 check_cp1_registers(ctx, fs);
6723 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6724 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6726 gen_load_fpr64(ctx, fp64, fs);
6727 tcg_gen_helper_1_1(do_float_floorw_d, fp32, fp64);
6728 tcg_temp_free(fp64);
6729 gen_store_fpr32(fp32, fd);
6730 tcg_temp_free(fp32);
6735 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6740 int l1 = gen_new_label();
6741 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6742 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6744 gen_load_gpr(t0, ft);
6745 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6747 gen_load_fpr64(ctx, fp0, fs);
6748 gen_store_fpr64(ctx, fp0, fd);
6756 int l1 = gen_new_label();
6757 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6758 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6760 gen_load_gpr(t0, ft);
6761 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6763 gen_load_fpr64(ctx, fp0, fs);
6764 gen_store_fpr64(ctx, fp0, fd);
6771 check_cp1_64bitmode(ctx);
6773 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6775 gen_load_fpr64(ctx, fp0, fs);
6776 tcg_gen_helper_1_1(do_float_recip_d, fp0, fp0);
6777 gen_store_fpr64(ctx, fp0, fd);
6783 check_cp1_64bitmode(ctx);
6785 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6787 gen_load_fpr64(ctx, fp0, fs);
6788 tcg_gen_helper_1_1(do_float_rsqrt_d, fp0, fp0);
6789 gen_store_fpr64(ctx, fp0, fd);
6795 check_cp1_64bitmode(ctx);
6797 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6798 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6800 gen_load_fpr64(ctx, fp0, fs);
6801 gen_load_fpr64(ctx, fp1, ft);
6802 tcg_gen_helper_1_2(do_float_recip2_d, fp0, fp0, fp1);
6804 gen_store_fpr64(ctx, fp0, fd);
6810 check_cp1_64bitmode(ctx);
6812 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6814 gen_load_fpr64(ctx, fp0, fs);
6815 tcg_gen_helper_1_1(do_float_recip1_d, fp0, fp0);
6816 gen_store_fpr64(ctx, fp0, fd);
6822 check_cp1_64bitmode(ctx);
6824 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6826 gen_load_fpr64(ctx, fp0, fs);
6827 tcg_gen_helper_1_1(do_float_rsqrt1_d, fp0, fp0);
6828 gen_store_fpr64(ctx, fp0, fd);
6834 check_cp1_64bitmode(ctx);
6836 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6837 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6839 gen_load_fpr64(ctx, fp0, fs);
6840 gen_load_fpr64(ctx, fp1, ft);
6841 tcg_gen_helper_1_2(do_float_rsqrt2_d, fp0, fp0, fp1);
6843 gen_store_fpr64(ctx, fp0, fd);
6865 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6866 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6868 gen_load_fpr64(ctx, fp0, fs);
6869 gen_load_fpr64(ctx, fp1, ft);
6870 if (ctx->opcode & (1 << 6)) {
6872 check_cp1_registers(ctx, fs | ft);
6873 gen_cmpabs_d(func-48, fp0, fp1, cc);
6874 opn = condnames_abs[func-48];
6876 check_cp1_registers(ctx, fs | ft);
6877 gen_cmp_d(func-48, fp0, fp1, cc);
6878 opn = condnames[func-48];
6885 check_cp1_registers(ctx, fs);
6887 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6888 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6890 gen_load_fpr64(ctx, fp64, fs);
6891 tcg_gen_helper_1_1(do_float_cvts_d, fp32, fp64);
6892 tcg_temp_free(fp64);
6893 gen_store_fpr32(fp32, fd);
6894 tcg_temp_free(fp32);
6899 check_cp1_registers(ctx, fs);
6901 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6902 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6904 gen_load_fpr64(ctx, fp64, fs);
6905 tcg_gen_helper_1_1(do_float_cvtw_d, fp32, fp64);
6906 tcg_temp_free(fp64);
6907 gen_store_fpr32(fp32, fd);
6908 tcg_temp_free(fp32);
6913 check_cp1_64bitmode(ctx);
6915 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6917 gen_load_fpr64(ctx, fp0, fs);
6918 tcg_gen_helper_1_1(do_float_cvtl_d, fp0, fp0);
6919 gen_store_fpr64(ctx, fp0, fd);
6926 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6928 gen_load_fpr32(fp0, fs);
6929 tcg_gen_helper_1_1(do_float_cvts_w, fp0, fp0);
6930 gen_store_fpr32(fp0, fd);
6936 check_cp1_registers(ctx, fd);
6938 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6939 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6941 gen_load_fpr32(fp32, fs);
6942 tcg_gen_helper_1_1(do_float_cvtd_w, fp64, fp32);
6943 tcg_temp_free(fp32);
6944 gen_store_fpr64(ctx, fp64, fd);
6945 tcg_temp_free(fp64);
6950 check_cp1_64bitmode(ctx);
6952 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6953 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6955 gen_load_fpr64(ctx, fp64, fs);
6956 tcg_gen_helper_1_1(do_float_cvts_l, fp32, fp64);
6957 tcg_temp_free(fp64);
6958 gen_store_fpr32(fp32, fd);
6959 tcg_temp_free(fp32);
6964 check_cp1_64bitmode(ctx);
6966 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6968 gen_load_fpr64(ctx, fp0, fs);
6969 tcg_gen_helper_1_1(do_float_cvtd_l, fp0, fp0);
6970 gen_store_fpr64(ctx, fp0, fd);
6976 check_cp1_64bitmode(ctx);
6978 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6980 gen_load_fpr64(ctx, fp0, fs);
6981 tcg_gen_helper_1_1(do_float_cvtps_pw, fp0, fp0);
6982 gen_store_fpr64(ctx, fp0, fd);
6988 check_cp1_64bitmode(ctx);
6990 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6991 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6993 gen_load_fpr64(ctx, fp0, fs);
6994 gen_load_fpr64(ctx, fp1, ft);
6995 tcg_gen_helper_1_2(do_float_add_ps, fp0, fp0, fp1);
6997 gen_store_fpr64(ctx, fp0, fd);
7003 check_cp1_64bitmode(ctx);
7005 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7006 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7008 gen_load_fpr64(ctx, fp0, fs);
7009 gen_load_fpr64(ctx, fp1, ft);
7010 tcg_gen_helper_1_2(do_float_sub_ps, fp0, fp0, fp1);
7012 gen_store_fpr64(ctx, fp0, fd);
7018 check_cp1_64bitmode(ctx);
7020 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7021 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7023 gen_load_fpr64(ctx, fp0, fs);
7024 gen_load_fpr64(ctx, fp1, ft);
7025 tcg_gen_helper_1_2(do_float_mul_ps, fp0, fp0, fp1);
7027 gen_store_fpr64(ctx, fp0, fd);
7033 check_cp1_64bitmode(ctx);
7035 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7037 gen_load_fpr64(ctx, fp0, fs);
7038 tcg_gen_helper_1_1(do_float_abs_ps, fp0, fp0);
7039 gen_store_fpr64(ctx, fp0, fd);
7045 check_cp1_64bitmode(ctx);
7047 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7049 gen_load_fpr64(ctx, fp0, fs);
7050 gen_store_fpr64(ctx, fp0, fd);
7056 check_cp1_64bitmode(ctx);
7058 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7060 gen_load_fpr64(ctx, fp0, fs);
7061 tcg_gen_helper_1_1(do_float_chs_ps, fp0, fp0);
7062 gen_store_fpr64(ctx, fp0, fd);
7068 check_cp1_64bitmode(ctx);
7069 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
7073 check_cp1_64bitmode(ctx);
7075 int l1 = gen_new_label();
7076 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7077 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7078 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7080 gen_load_gpr(t0, ft);
7081 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7083 gen_load_fpr32(fp0, fs);
7084 gen_load_fpr32h(fph0, fs);
7085 gen_store_fpr32(fp0, fd);
7086 gen_store_fpr32h(fph0, fd);
7088 tcg_temp_free(fph0);
7094 check_cp1_64bitmode(ctx);
7096 int l1 = gen_new_label();
7097 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7098 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7099 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7101 gen_load_gpr(t0, ft);
7102 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
7104 gen_load_fpr32(fp0, fs);
7105 gen_load_fpr32h(fph0, fs);
7106 gen_store_fpr32(fp0, fd);
7107 gen_store_fpr32h(fph0, fd);
7109 tcg_temp_free(fph0);
7115 check_cp1_64bitmode(ctx);
7117 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7118 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7120 gen_load_fpr64(ctx, fp0, ft);
7121 gen_load_fpr64(ctx, fp1, fs);
7122 tcg_gen_helper_1_2(do_float_addr_ps, fp0, fp0, fp1);
7124 gen_store_fpr64(ctx, fp0, fd);
7130 check_cp1_64bitmode(ctx);
7132 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7133 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7135 gen_load_fpr64(ctx, fp0, ft);
7136 gen_load_fpr64(ctx, fp1, fs);
7137 tcg_gen_helper_1_2(do_float_mulr_ps, fp0, fp0, fp1);
7139 gen_store_fpr64(ctx, fp0, fd);
7145 check_cp1_64bitmode(ctx);
7147 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7148 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7150 gen_load_fpr64(ctx, fp0, fs);
7151 gen_load_fpr64(ctx, fp1, fd);
7152 tcg_gen_helper_1_2(do_float_recip2_ps, fp0, fp0, fp1);
7154 gen_store_fpr64(ctx, fp0, fd);
7160 check_cp1_64bitmode(ctx);
7162 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7164 gen_load_fpr64(ctx, fp0, fs);
7165 tcg_gen_helper_1_1(do_float_recip1_ps, fp0, fp0);
7166 gen_store_fpr64(ctx, fp0, fd);
7172 check_cp1_64bitmode(ctx);
7174 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7176 gen_load_fpr64(ctx, fp0, fs);
7177 tcg_gen_helper_1_1(do_float_rsqrt1_ps, fp0, fp0);
7178 gen_store_fpr64(ctx, fp0, fd);
7184 check_cp1_64bitmode(ctx);
7186 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7187 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7189 gen_load_fpr64(ctx, fp0, fs);
7190 gen_load_fpr64(ctx, fp1, ft);
7191 tcg_gen_helper_1_2(do_float_rsqrt2_ps, fp0, fp0, fp1);
7193 gen_store_fpr64(ctx, fp0, fd);
7199 check_cp1_64bitmode(ctx);
7201 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7203 gen_load_fpr32h(fp0, fs);
7204 tcg_gen_helper_1_1(do_float_cvts_pu, fp0, fp0);
7205 gen_store_fpr32(fp0, fd);
7211 check_cp1_64bitmode(ctx);
7213 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7215 gen_load_fpr64(ctx, fp0, fs);
7216 tcg_gen_helper_1_1(do_float_cvtpw_ps, fp0, fp0);
7217 gen_store_fpr64(ctx, fp0, fd);
7223 check_cp1_64bitmode(ctx);
7225 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7227 gen_load_fpr32(fp0, fs);
7228 tcg_gen_helper_1_1(do_float_cvts_pl, fp0, fp0);
7229 gen_store_fpr32(fp0, fd);
7235 check_cp1_64bitmode(ctx);
7237 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7238 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7240 gen_load_fpr32(fp0, fs);
7241 gen_load_fpr32(fp1, ft);
7242 gen_store_fpr32h(fp0, fd);
7243 gen_store_fpr32(fp1, fd);
7250 check_cp1_64bitmode(ctx);
7252 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7253 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7255 gen_load_fpr32(fp0, fs);
7256 gen_load_fpr32h(fp1, ft);
7257 gen_store_fpr32(fp1, fd);
7258 gen_store_fpr32h(fp0, fd);
7265 check_cp1_64bitmode(ctx);
7267 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7268 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7270 gen_load_fpr32h(fp0, fs);
7271 gen_load_fpr32(fp1, ft);
7272 gen_store_fpr32(fp1, fd);
7273 gen_store_fpr32h(fp0, fd);
7280 check_cp1_64bitmode(ctx);
7282 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7283 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7285 gen_load_fpr32h(fp0, fs);
7286 gen_load_fpr32h(fp1, ft);
7287 gen_store_fpr32(fp1, fd);
7288 gen_store_fpr32h(fp0, fd);
7310 check_cp1_64bitmode(ctx);
7312 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7313 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7315 gen_load_fpr64(ctx, fp0, fs);
7316 gen_load_fpr64(ctx, fp1, ft);
7317 if (ctx->opcode & (1 << 6)) {
7318 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7319 opn = condnames_abs[func-48];
7321 gen_cmp_ps(func-48, fp0, fp1, cc);
7322 opn = condnames[func-48];
7330 generate_exception (ctx, EXCP_RI);
7335 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7338 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7341 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7346 /* Coprocessor 3 (FPU) */
7347 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7348 int fd, int fs, int base, int index)
7350 const char *opn = "extended float load/store";
7352 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7353 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7356 gen_load_gpr(t0, index);
7357 } else if (index == 0) {
7358 gen_load_gpr(t0, base);
7360 gen_load_gpr(t0, base);
7361 gen_load_gpr(t1, index);
7362 gen_op_addr_add(ctx, t0, t1);
7364 /* Don't do NOP if destination is zero: we must perform the actual
7370 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7372 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
7373 gen_store_fpr32(fp0, fd);
7380 check_cp1_registers(ctx, fd);
7382 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7384 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7385 gen_store_fpr64(ctx, fp0, fd);
7391 check_cp1_64bitmode(ctx);
7392 tcg_gen_andi_tl(t0, t0, ~0x7);
7394 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7396 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7397 gen_store_fpr64(ctx, fp0, fd);
7405 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7407 gen_load_fpr32(fp0, fs);
7408 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
7416 check_cp1_registers(ctx, fs);
7418 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7420 gen_load_fpr64(ctx, fp0, fs);
7421 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7428 check_cp1_64bitmode(ctx);
7429 tcg_gen_andi_tl(t0, t0, ~0x7);
7431 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7433 gen_load_fpr64(ctx, fp0, fs);
7434 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7442 generate_exception(ctx, EXCP_RI);
7449 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7450 regnames[index], regnames[base]);
7453 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7454 int fd, int fr, int fs, int ft)
7456 const char *opn = "flt3_arith";
7460 check_cp1_64bitmode(ctx);
7462 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7463 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7464 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7465 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
7466 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
7467 int l1 = gen_new_label();
7468 int l2 = gen_new_label();
7470 gen_load_gpr(t0, fr);
7471 tcg_gen_andi_tl(t0, t0, 0x7);
7472 gen_load_fpr32(fp0, fs);
7473 gen_load_fpr32h(fph0, fs);
7474 gen_load_fpr32(fp1, ft);
7475 gen_load_fpr32h(fph1, ft);
7477 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7478 gen_store_fpr32(fp0, fd);
7479 gen_store_fpr32h(fph0, fd);
7482 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7484 #ifdef TARGET_WORDS_BIGENDIAN
7485 gen_store_fpr32(fph1, fd);
7486 gen_store_fpr32h(fp0, fd);
7488 gen_store_fpr32(fph0, fd);
7489 gen_store_fpr32h(fp1, fd);
7493 tcg_temp_free(fph0);
7495 tcg_temp_free(fph1);
7502 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7503 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7504 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7506 gen_load_fpr32(fp0, fs);
7507 gen_load_fpr32(fp1, ft);
7508 gen_load_fpr32(fp2, fr);
7509 tcg_gen_helper_1_3(do_float_muladd_s, fp2, fp0, fp1, fp2);
7512 gen_store_fpr32(fp2, fd);
7519 check_cp1_registers(ctx, fd | fs | ft | fr);
7521 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7522 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7523 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7525 gen_load_fpr64(ctx, fp0, fs);
7526 gen_load_fpr64(ctx, fp1, ft);
7527 gen_load_fpr64(ctx, fp2, fr);
7528 tcg_gen_helper_1_3(do_float_muladd_d, fp2, fp0, fp1, fp2);
7531 gen_store_fpr64(ctx, fp2, fd);
7537 check_cp1_64bitmode(ctx);
7539 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7540 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7541 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7543 gen_load_fpr64(ctx, fp0, fs);
7544 gen_load_fpr64(ctx, fp1, ft);
7545 gen_load_fpr64(ctx, fp2, fr);
7546 tcg_gen_helper_1_3(do_float_muladd_ps, fp2, fp0, fp1, fp2);
7549 gen_store_fpr64(ctx, fp2, fd);
7557 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7558 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7559 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7561 gen_load_fpr32(fp0, fs);
7562 gen_load_fpr32(fp1, ft);
7563 gen_load_fpr32(fp2, fr);
7564 tcg_gen_helper_1_3(do_float_mulsub_s, fp2, fp0, fp1, fp2);
7567 gen_store_fpr32(fp2, fd);
7574 check_cp1_registers(ctx, fd | fs | ft | fr);
7576 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7577 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7578 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7580 gen_load_fpr64(ctx, fp0, fs);
7581 gen_load_fpr64(ctx, fp1, ft);
7582 gen_load_fpr64(ctx, fp2, fr);
7583 tcg_gen_helper_1_3(do_float_mulsub_d, fp2, fp0, fp1, fp2);
7586 gen_store_fpr64(ctx, fp2, fd);
7592 check_cp1_64bitmode(ctx);
7594 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7595 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7596 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7598 gen_load_fpr64(ctx, fp0, fs);
7599 gen_load_fpr64(ctx, fp1, ft);
7600 gen_load_fpr64(ctx, fp2, fr);
7601 tcg_gen_helper_1_3(do_float_mulsub_ps, fp2, fp0, fp1, fp2);
7604 gen_store_fpr64(ctx, fp2, fd);
7612 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7613 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7614 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7616 gen_load_fpr32(fp0, fs);
7617 gen_load_fpr32(fp1, ft);
7618 gen_load_fpr32(fp2, fr);
7619 tcg_gen_helper_1_3(do_float_nmuladd_s, fp2, fp0, fp1, fp2);
7622 gen_store_fpr32(fp2, fd);
7629 check_cp1_registers(ctx, fd | fs | ft | fr);
7631 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7632 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7633 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7635 gen_load_fpr64(ctx, fp0, fs);
7636 gen_load_fpr64(ctx, fp1, ft);
7637 gen_load_fpr64(ctx, fp2, fr);
7638 tcg_gen_helper_1_3(do_float_nmuladd_d, fp2, fp0, fp1, fp2);
7641 gen_store_fpr64(ctx, fp2, fd);
7647 check_cp1_64bitmode(ctx);
7649 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7650 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7651 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7653 gen_load_fpr64(ctx, fp0, fs);
7654 gen_load_fpr64(ctx, fp1, ft);
7655 gen_load_fpr64(ctx, fp2, fr);
7656 tcg_gen_helper_1_3(do_float_nmuladd_ps, fp2, fp0, fp1, fp2);
7659 gen_store_fpr64(ctx, fp2, fd);
7667 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7668 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7669 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7671 gen_load_fpr32(fp0, fs);
7672 gen_load_fpr32(fp1, ft);
7673 gen_load_fpr32(fp2, fr);
7674 tcg_gen_helper_1_3(do_float_nmulsub_s, fp2, fp0, fp1, fp2);
7677 gen_store_fpr32(fp2, fd);
7684 check_cp1_registers(ctx, fd | fs | ft | fr);
7686 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7687 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7688 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7690 gen_load_fpr64(ctx, fp0, fs);
7691 gen_load_fpr64(ctx, fp1, ft);
7692 gen_load_fpr64(ctx, fp2, fr);
7693 tcg_gen_helper_1_3(do_float_nmulsub_d, fp2, fp0, fp1, fp2);
7696 gen_store_fpr64(ctx, fp2, fd);
7702 check_cp1_64bitmode(ctx);
7704 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7705 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7706 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7708 gen_load_fpr64(ctx, fp0, fs);
7709 gen_load_fpr64(ctx, fp1, ft);
7710 gen_load_fpr64(ctx, fp2, fr);
7711 tcg_gen_helper_1_3(do_float_nmulsub_ps, fp2, fp0, fp1, fp2);
7714 gen_store_fpr64(ctx, fp2, fd);
7721 generate_exception (ctx, EXCP_RI);
7724 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7725 fregnames[fs], fregnames[ft]);
7728 /* ISA extensions (ASEs) */
7729 /* MIPS16 extension to MIPS32 */
7730 /* SmartMIPS extension to MIPS32 */
7732 #if defined(TARGET_MIPS64)
7734 /* MDMX extension to MIPS64 */
7738 static void decode_opc (CPUState *env, DisasContext *ctx)
7742 uint32_t op, op1, op2;
7745 /* make sure instructions are on a word boundary */
7746 if (ctx->pc & 0x3) {
7747 env->CP0_BadVAddr = ctx->pc;
7748 generate_exception(ctx, EXCP_AdEL);
7752 /* Handle blikely not taken case */
7753 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7754 int l1 = gen_new_label();
7756 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7757 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7759 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
7761 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7762 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7763 tcg_temp_free(r_tmp);
7765 gen_goto_tb(ctx, 1, ctx->pc + 4);
7768 op = MASK_OP_MAJOR(ctx->opcode);
7769 rs = (ctx->opcode >> 21) & 0x1f;
7770 rt = (ctx->opcode >> 16) & 0x1f;
7771 rd = (ctx->opcode >> 11) & 0x1f;
7772 sa = (ctx->opcode >> 6) & 0x1f;
7773 imm = (int16_t)ctx->opcode;
7776 op1 = MASK_SPECIAL(ctx->opcode);
7778 case OPC_SLL: /* Arithmetic with immediate */
7779 case OPC_SRL ... OPC_SRA:
7780 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7782 case OPC_MOVZ ... OPC_MOVN:
7783 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7784 case OPC_SLLV: /* Arithmetic */
7785 case OPC_SRLV ... OPC_SRAV:
7786 case OPC_ADD ... OPC_NOR:
7787 case OPC_SLT ... OPC_SLTU:
7788 gen_arith(env, ctx, op1, rd, rs, rt);
7790 case OPC_MULT ... OPC_DIVU:
7792 check_insn(env, ctx, INSN_VR54XX);
7793 op1 = MASK_MUL_VR54XX(ctx->opcode);
7794 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7796 gen_muldiv(ctx, op1, rs, rt);
7798 case OPC_JR ... OPC_JALR:
7799 gen_compute_branch(ctx, op1, rs, rd, sa);
7801 case OPC_TGE ... OPC_TEQ: /* Traps */
7803 gen_trap(ctx, op1, rs, rt, -1);
7805 case OPC_MFHI: /* Move from HI/LO */
7807 gen_HILO(ctx, op1, rd);
7810 case OPC_MTLO: /* Move to HI/LO */
7811 gen_HILO(ctx, op1, rs);
7813 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7814 #ifdef MIPS_STRICT_STANDARD
7815 MIPS_INVAL("PMON / selsl");
7816 generate_exception(ctx, EXCP_RI);
7818 tcg_gen_helper_0_i(do_pmon, sa);
7822 generate_exception(ctx, EXCP_SYSCALL);
7825 generate_exception(ctx, EXCP_BREAK);
7828 #ifdef MIPS_STRICT_STANDARD
7830 generate_exception(ctx, EXCP_RI);
7832 /* Implemented as RI exception for now. */
7833 MIPS_INVAL("spim (unofficial)");
7834 generate_exception(ctx, EXCP_RI);
7842 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7843 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7844 save_cpu_state(ctx, 1);
7845 check_cp1_enabled(ctx);
7846 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7847 (ctx->opcode >> 16) & 1);
7849 generate_exception_err(ctx, EXCP_CpU, 1);
7853 #if defined(TARGET_MIPS64)
7854 /* MIPS64 specific opcodes */
7856 case OPC_DSRL ... OPC_DSRA:
7858 case OPC_DSRL32 ... OPC_DSRA32:
7859 check_insn(env, ctx, ISA_MIPS3);
7861 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7864 case OPC_DSRLV ... OPC_DSRAV:
7865 case OPC_DADD ... OPC_DSUBU:
7866 check_insn(env, ctx, ISA_MIPS3);
7868 gen_arith(env, ctx, op1, rd, rs, rt);
7870 case OPC_DMULT ... OPC_DDIVU:
7871 check_insn(env, ctx, ISA_MIPS3);
7873 gen_muldiv(ctx, op1, rs, rt);
7876 default: /* Invalid */
7877 MIPS_INVAL("special");
7878 generate_exception(ctx, EXCP_RI);
7883 op1 = MASK_SPECIAL2(ctx->opcode);
7885 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7886 case OPC_MSUB ... OPC_MSUBU:
7887 check_insn(env, ctx, ISA_MIPS32);
7888 gen_muldiv(ctx, op1, rs, rt);
7891 gen_arith(env, ctx, op1, rd, rs, rt);
7893 case OPC_CLZ ... OPC_CLO:
7894 check_insn(env, ctx, ISA_MIPS32);
7895 gen_cl(ctx, op1, rd, rs);
7898 /* XXX: not clear which exception should be raised
7899 * when in debug mode...
7901 check_insn(env, ctx, ISA_MIPS32);
7902 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7903 generate_exception(ctx, EXCP_DBp);
7905 generate_exception(ctx, EXCP_DBp);
7909 #if defined(TARGET_MIPS64)
7910 case OPC_DCLZ ... OPC_DCLO:
7911 check_insn(env, ctx, ISA_MIPS64);
7913 gen_cl(ctx, op1, rd, rs);
7916 default: /* Invalid */
7917 MIPS_INVAL("special2");
7918 generate_exception(ctx, EXCP_RI);
7923 op1 = MASK_SPECIAL3(ctx->opcode);
7927 check_insn(env, ctx, ISA_MIPS32R2);
7928 gen_bitops(ctx, op1, rt, rs, sa, rd);
7931 check_insn(env, ctx, ISA_MIPS32R2);
7932 op2 = MASK_BSHFL(ctx->opcode);
7934 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7935 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7939 gen_load_gpr(t1, rt);
7940 tcg_gen_helper_1_1(do_wsbh, t0, t1);
7941 gen_store_gpr(t0, rd);
7944 gen_load_gpr(t1, rt);
7945 tcg_gen_ext8s_tl(t0, t1);
7946 gen_store_gpr(t0, rd);
7949 gen_load_gpr(t1, rt);
7950 tcg_gen_ext16s_tl(t0, t1);
7951 gen_store_gpr(t0, rd);
7953 default: /* Invalid */
7954 MIPS_INVAL("bshfl");
7955 generate_exception(ctx, EXCP_RI);
7963 check_insn(env, ctx, ISA_MIPS32R2);
7965 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7969 save_cpu_state(ctx, 1);
7970 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
7973 save_cpu_state(ctx, 1);
7974 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
7977 save_cpu_state(ctx, 1);
7978 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
7981 save_cpu_state(ctx, 1);
7982 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
7985 if (env->user_mode_only) {
7986 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7989 /* XXX: Some CPUs implement this in hardware.
7990 Not supported yet. */
7992 default: /* Invalid */
7993 MIPS_INVAL("rdhwr");
7994 generate_exception(ctx, EXCP_RI);
7997 gen_store_gpr(t0, rt);
8002 check_insn(env, ctx, ASE_MT);
8004 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8005 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8007 gen_load_gpr(t0, rt);
8008 gen_load_gpr(t1, rs);
8009 tcg_gen_helper_0_2(do_fork, t0, t1);
8015 check_insn(env, ctx, ASE_MT);
8017 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8019 gen_load_gpr(t0, rs);
8020 tcg_gen_helper_1_1(do_yield, t0, t0);
8021 gen_store_gpr(t0, rd);
8025 #if defined(TARGET_MIPS64)
8026 case OPC_DEXTM ... OPC_DEXT:
8027 case OPC_DINSM ... OPC_DINS:
8028 check_insn(env, ctx, ISA_MIPS64R2);
8030 gen_bitops(ctx, op1, rt, rs, sa, rd);
8033 check_insn(env, ctx, ISA_MIPS64R2);
8035 op2 = MASK_DBSHFL(ctx->opcode);
8037 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8038 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8042 gen_load_gpr(t1, rt);
8043 tcg_gen_helper_1_1(do_dsbh, t0, t1);
8046 gen_load_gpr(t1, rt);
8047 tcg_gen_helper_1_1(do_dshd, t0, t1);
8049 default: /* Invalid */
8050 MIPS_INVAL("dbshfl");
8051 generate_exception(ctx, EXCP_RI);
8054 gen_store_gpr(t0, rd);
8060 default: /* Invalid */
8061 MIPS_INVAL("special3");
8062 generate_exception(ctx, EXCP_RI);
8067 op1 = MASK_REGIMM(ctx->opcode);
8069 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
8070 case OPC_BLTZAL ... OPC_BGEZALL:
8071 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
8073 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
8075 gen_trap(ctx, op1, rs, -1, imm);
8078 check_insn(env, ctx, ISA_MIPS32R2);
8081 default: /* Invalid */
8082 MIPS_INVAL("regimm");
8083 generate_exception(ctx, EXCP_RI);
8088 check_cp0_enabled(ctx);
8089 op1 = MASK_CP0(ctx->opcode);
8095 #if defined(TARGET_MIPS64)
8099 #ifndef CONFIG_USER_ONLY
8100 if (!env->user_mode_only)
8101 gen_cp0(env, ctx, op1, rt, rd);
8102 #endif /* !CONFIG_USER_ONLY */
8104 case OPC_C0_FIRST ... OPC_C0_LAST:
8105 #ifndef CONFIG_USER_ONLY
8106 if (!env->user_mode_only)
8107 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
8108 #endif /* !CONFIG_USER_ONLY */
8111 #ifndef CONFIG_USER_ONLY
8112 if (!env->user_mode_only) {
8113 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8115 op2 = MASK_MFMC0(ctx->opcode);
8118 check_insn(env, ctx, ASE_MT);
8119 tcg_gen_helper_1_1(do_dmt, t0, t0);
8122 check_insn(env, ctx, ASE_MT);
8123 tcg_gen_helper_1_1(do_emt, t0, t0);
8126 check_insn(env, ctx, ASE_MT);
8127 tcg_gen_helper_1_1(do_dvpe, t0, t0);
8130 check_insn(env, ctx, ASE_MT);
8131 tcg_gen_helper_1_1(do_evpe, t0, t0);
8134 check_insn(env, ctx, ISA_MIPS32R2);
8135 save_cpu_state(ctx, 1);
8136 tcg_gen_helper_1_0(do_di, t0);
8137 /* Stop translation as we may have switched the execution mode */
8138 ctx->bstate = BS_STOP;
8141 check_insn(env, ctx, ISA_MIPS32R2);
8142 save_cpu_state(ctx, 1);
8143 tcg_gen_helper_1_0(do_ei, t0);
8144 /* Stop translation as we may have switched the execution mode */
8145 ctx->bstate = BS_STOP;
8147 default: /* Invalid */
8148 MIPS_INVAL("mfmc0");
8149 generate_exception(ctx, EXCP_RI);
8152 gen_store_gpr(t0, rt);
8155 #endif /* !CONFIG_USER_ONLY */
8158 check_insn(env, ctx, ISA_MIPS32R2);
8159 gen_load_srsgpr(rt, rd);
8162 check_insn(env, ctx, ISA_MIPS32R2);
8163 gen_store_srsgpr(rt, rd);
8167 generate_exception(ctx, EXCP_RI);
8171 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
8172 gen_arith_imm(env, ctx, op, rt, rs, imm);
8174 case OPC_J ... OPC_JAL: /* Jump */
8175 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
8176 gen_compute_branch(ctx, op, rs, rt, offset);
8178 case OPC_BEQ ... OPC_BGTZ: /* Branch */
8179 case OPC_BEQL ... OPC_BGTZL:
8180 gen_compute_branch(ctx, op, rs, rt, imm << 2);
8182 case OPC_LB ... OPC_LWR: /* Load and stores */
8183 case OPC_SB ... OPC_SW:
8187 gen_ldst(ctx, op, rt, rs, imm);
8190 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
8194 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
8198 /* Floating point (COP1). */
8203 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8204 save_cpu_state(ctx, 1);
8205 check_cp1_enabled(ctx);
8206 gen_flt_ldst(ctx, op, rt, rs, imm);
8208 generate_exception_err(ctx, EXCP_CpU, 1);
8213 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8214 save_cpu_state(ctx, 1);
8215 check_cp1_enabled(ctx);
8216 op1 = MASK_CP1(ctx->opcode);
8220 check_insn(env, ctx, ISA_MIPS32R2);
8225 gen_cp1(ctx, op1, rt, rd);
8227 #if defined(TARGET_MIPS64)
8230 check_insn(env, ctx, ISA_MIPS3);
8231 gen_cp1(ctx, op1, rt, rd);
8237 check_insn(env, ctx, ASE_MIPS3D);
8240 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8241 (rt >> 2) & 0x7, imm << 2);
8248 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8253 generate_exception (ctx, EXCP_RI);
8257 generate_exception_err(ctx, EXCP_CpU, 1);
8267 /* COP2: Not implemented. */
8268 generate_exception_err(ctx, EXCP_CpU, 2);
8272 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8273 save_cpu_state(ctx, 1);
8274 check_cp1_enabled(ctx);
8275 op1 = MASK_CP3(ctx->opcode);
8283 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8301 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8305 generate_exception (ctx, EXCP_RI);
8309 generate_exception_err(ctx, EXCP_CpU, 1);
8313 #if defined(TARGET_MIPS64)
8314 /* MIPS64 opcodes */
8316 case OPC_LDL ... OPC_LDR:
8317 case OPC_SDL ... OPC_SDR:
8322 check_insn(env, ctx, ISA_MIPS3);
8324 gen_ldst(ctx, op, rt, rs, imm);
8326 case OPC_DADDI ... OPC_DADDIU:
8327 check_insn(env, ctx, ISA_MIPS3);
8329 gen_arith_imm(env, ctx, op, rt, rs, imm);
8333 check_insn(env, ctx, ASE_MIPS16);
8334 /* MIPS16: Not implemented. */
8336 check_insn(env, ctx, ASE_MDMX);
8337 /* MDMX: Not implemented. */
8338 default: /* Invalid */
8339 MIPS_INVAL("major opcode");
8340 generate_exception(ctx, EXCP_RI);
8343 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8344 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8345 /* Branches completion */
8346 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8347 ctx->bstate = BS_BRANCH;
8348 save_cpu_state(ctx, 0);
8349 /* FIXME: Need to clear can_do_io. */
8352 /* unconditional branch */
8353 MIPS_DEBUG("unconditional branch");
8354 gen_goto_tb(ctx, 0, ctx->btarget);
8357 /* blikely taken case */
8358 MIPS_DEBUG("blikely branch taken");
8359 gen_goto_tb(ctx, 0, ctx->btarget);
8362 /* Conditional branch */
8363 MIPS_DEBUG("conditional branch");
8365 int l1 = gen_new_label();
8367 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8368 gen_goto_tb(ctx, 1, ctx->pc + 4);
8370 gen_goto_tb(ctx, 0, ctx->btarget);
8374 /* unconditional branch to register */
8375 MIPS_DEBUG("branch to register");
8376 tcg_gen_mov_tl(cpu_PC, btarget);
8380 MIPS_DEBUG("unknown branch");
8387 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8391 target_ulong pc_start;
8392 uint16_t *gen_opc_end;
8397 if (search_pc && loglevel)
8398 fprintf (logfile, "search pc %d\n", search_pc);
8401 /* Leave some spare opc slots for branch handling. */
8402 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8406 ctx.bstate = BS_NONE;
8407 /* Restore delay slot state from the tb context. */
8408 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8409 restore_cpu_state(env, &ctx);
8410 if (env->user_mode_only)
8411 ctx.mem_idx = MIPS_HFLAG_UM;
8413 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8415 max_insns = tb->cflags & CF_COUNT_MASK;
8417 max_insns = CF_COUNT_MASK;
8419 if (loglevel & CPU_LOG_TB_CPU) {
8420 fprintf(logfile, "------------------------------------------------\n");
8421 /* FIXME: This may print out stale hflags from env... */
8422 cpu_dump_state(env, logfile, fprintf, 0);
8425 #ifdef MIPS_DEBUG_DISAS
8426 if (loglevel & CPU_LOG_TB_IN_ASM)
8427 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
8428 tb, ctx.mem_idx, ctx.hflags);
8431 while (ctx.bstate == BS_NONE) {
8432 if (env->nb_breakpoints > 0) {
8433 for(j = 0; j < env->nb_breakpoints; j++) {
8434 if (env->breakpoints[j] == ctx.pc) {
8435 save_cpu_state(&ctx, 1);
8436 ctx.bstate = BS_BRANCH;
8437 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8438 /* Include the breakpoint location or the tb won't
8439 * be flushed when it must be. */
8441 goto done_generating;
8447 j = gen_opc_ptr - gen_opc_buf;
8451 gen_opc_instr_start[lj++] = 0;
8453 gen_opc_pc[lj] = ctx.pc;
8454 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8455 gen_opc_instr_start[lj] = 1;
8456 gen_opc_icount[lj] = num_insns;
8458 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8460 ctx.opcode = ldl_code(ctx.pc);
8461 decode_opc(env, &ctx);
8465 if (env->singlestep_enabled)
8468 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8471 if (gen_opc_ptr >= gen_opc_end)
8474 if (num_insns >= max_insns)
8476 #if defined (MIPS_SINGLE_STEP)
8480 if (tb->cflags & CF_LAST_IO)
8482 if (env->singlestep_enabled) {
8483 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8484 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8486 switch (ctx.bstate) {
8488 tcg_gen_helper_0_0(do_interrupt_restart);
8489 gen_goto_tb(&ctx, 0, ctx.pc);
8492 save_cpu_state(&ctx, 0);
8493 gen_goto_tb(&ctx, 0, ctx.pc);
8496 tcg_gen_helper_0_0(do_interrupt_restart);
8505 gen_icount_end(tb, num_insns);
8506 *gen_opc_ptr = INDEX_op_end;
8508 j = gen_opc_ptr - gen_opc_buf;
8511 gen_opc_instr_start[lj++] = 0;
8513 tb->size = ctx.pc - pc_start;
8514 tb->icount = num_insns;
8517 #if defined MIPS_DEBUG_DISAS
8518 if (loglevel & CPU_LOG_TB_IN_ASM)
8519 fprintf(logfile, "\n");
8521 if (loglevel & CPU_LOG_TB_IN_ASM) {
8522 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
8523 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
8524 fprintf(logfile, "\n");
8526 if (loglevel & CPU_LOG_TB_CPU) {
8527 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8532 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8534 gen_intermediate_code_internal(env, tb, 0);
8537 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8539 gen_intermediate_code_internal(env, tb, 1);
8542 static void fpu_dump_state(CPUState *env, FILE *f,
8543 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8547 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8549 #define printfpr(fp) \
8552 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8553 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8554 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8557 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8558 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8559 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8560 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8561 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8566 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8567 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8568 get_float_exception_flags(&env->active_fpu.fp_status));
8569 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8570 fpu_fprintf(f, "%3s: ", fregnames[i]);
8571 printfpr(&env->active_fpu.fpr[i]);
8577 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8578 /* Debug help: The architecture requires 32bit code to maintain proper
8579 sign-extended values on 64bit machines. */
8581 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8584 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8585 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8590 if (!SIGN_EXT_P(env->active_tc.PC))
8591 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8592 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8593 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8594 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8595 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8596 if (!SIGN_EXT_P(env->btarget))
8597 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8599 for (i = 0; i < 32; i++) {
8600 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8601 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8604 if (!SIGN_EXT_P(env->CP0_EPC))
8605 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8606 if (!SIGN_EXT_P(env->CP0_LLAddr))
8607 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8611 void cpu_dump_state (CPUState *env, FILE *f,
8612 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8617 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",
8618 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8619 env->hflags, env->btarget, env->bcond);
8620 for (i = 0; i < 32; i++) {
8622 cpu_fprintf(f, "GPR%02d:", i);
8623 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8625 cpu_fprintf(f, "\n");
8628 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8629 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8630 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8631 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8632 if (env->hflags & MIPS_HFLAG_FPU)
8633 fpu_dump_state(env, f, cpu_fprintf, flags);
8634 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8635 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8639 static void mips_tcg_init(void)
8644 /* Initialize various static tables. */
8648 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8649 for (i = 0; i < 32; i++)
8650 cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8651 offsetof(CPUState, active_tc.gpr[i]),
8653 cpu_PC = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8654 offsetof(CPUState, active_tc.PC), "PC");
8655 for (i = 0; i < MIPS_DSP_ACC; i++) {
8656 cpu_HI[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8657 offsetof(CPUState, active_tc.HI[i]),
8659 cpu_LO[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8660 offsetof(CPUState, active_tc.LO[i]),
8662 cpu_ACX[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8663 offsetof(CPUState, active_tc.ACX[i]),
8666 cpu_dspctrl = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8667 offsetof(CPUState, active_tc.DSPControl),
8669 bcond = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8670 offsetof(CPUState, bcond), "bcond");
8671 btarget = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8672 offsetof(CPUState, btarget), "btarget");
8673 for (i = 0; i < 32; i++)
8674 fpu_fpr32[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8675 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8677 for (i = 0; i < 32; i++)
8678 fpu_fpr64[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
8679 offsetof(CPUState, active_fpu.fpr[i]),
8681 for (i = 0; i < 32; i++)
8682 fpu_fpr32h[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8683 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8685 fpu_fcr0 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8686 offsetof(CPUState, active_fpu.fcr0),
8688 fpu_fcr31 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8689 offsetof(CPUState, active_fpu.fcr31),
8692 /* register helpers */
8694 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8700 #include "translate_init.c"
8702 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8705 const mips_def_t *def;
8707 def = cpu_mips_find_by_name(cpu_model);
8710 env = qemu_mallocz(sizeof(CPUMIPSState));
8713 env->cpu_model = def;
8716 env->cpu_model_str = cpu_model;
8722 void cpu_reset (CPUMIPSState *env)
8724 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8729 #if defined(CONFIG_USER_ONLY)
8730 env->user_mode_only = 1;
8732 if (env->user_mode_only) {
8733 env->hflags = MIPS_HFLAG_UM;
8735 if (env->hflags & MIPS_HFLAG_BMASK) {
8736 /* If the exception was raised from a delay slot,
8737 come back to the jump. */
8738 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8740 env->CP0_ErrorEPC = env->active_tc.PC;
8742 env->active_tc.PC = (int32_t)0xBFC00000;
8744 /* SMP not implemented */
8745 env->CP0_EBase = 0x80000000;
8746 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8747 /* vectored interrupts not implemented, timer on int 7,
8748 no performance counters. */
8749 env->CP0_IntCtl = 0xe0000000;
8753 for (i = 0; i < 7; i++) {
8754 env->CP0_WatchLo[i] = 0;
8755 env->CP0_WatchHi[i] = 0x80000000;
8757 env->CP0_WatchLo[7] = 0;
8758 env->CP0_WatchHi[7] = 0;
8760 /* Count register increments in debug mode, EJTAG version 1 */
8761 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8762 env->hflags = MIPS_HFLAG_CP0;
8764 env->exception_index = EXCP_NONE;
8765 cpu_mips_register(env, env->cpu_model);
8768 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8769 unsigned long searched_pc, int pc_pos, void *puc)
8771 env->active_tc.PC = gen_opc_pc[pc_pos];
8772 env->hflags &= ~MIPS_HFLAG_BMASK;
8773 env->hflags |= gen_opc_hflags[pc_pos];