2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL = (0x00 << 26),
46 OPC_REGIMM = (0x01 << 26),
47 OPC_CP0 = (0x10 << 26),
48 OPC_CP1 = (0x11 << 26),
49 OPC_CP2 = (0x12 << 26),
50 OPC_CP3 = (0x13 << 26),
51 OPC_SPECIAL2 = (0x1C << 26),
52 OPC_SPECIAL3 = (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI = (0x08 << 26),
55 OPC_ADDIU = (0x09 << 26),
56 OPC_SLTI = (0x0A << 26),
57 OPC_SLTIU = (0x0B << 26),
58 OPC_ANDI = (0x0C << 26),
59 OPC_ORI = (0x0D << 26),
60 OPC_XORI = (0x0E << 26),
61 OPC_LUI = (0x0F << 26),
62 OPC_DADDI = (0x18 << 26),
63 OPC_DADDIU = (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL = (0x03 << 26),
67 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL = (0x14 << 26),
69 OPC_BNE = (0x05 << 26),
70 OPC_BNEL = (0x15 << 26),
71 OPC_BLEZ = (0x06 << 26),
72 OPC_BLEZL = (0x16 << 26),
73 OPC_BGTZ = (0x07 << 26),
74 OPC_BGTZL = (0x17 << 26),
75 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL = (0x1A << 26),
78 OPC_LDR = (0x1B << 26),
79 OPC_LB = (0x20 << 26),
80 OPC_LH = (0x21 << 26),
81 OPC_LWL = (0x22 << 26),
82 OPC_LW = (0x23 << 26),
83 OPC_LBU = (0x24 << 26),
84 OPC_LHU = (0x25 << 26),
85 OPC_LWR = (0x26 << 26),
86 OPC_LWU = (0x27 << 26),
87 OPC_SB = (0x28 << 26),
88 OPC_SH = (0x29 << 26),
89 OPC_SWL = (0x2A << 26),
90 OPC_SW = (0x2B << 26),
91 OPC_SDL = (0x2C << 26),
92 OPC_SDR = (0x2D << 26),
93 OPC_SWR = (0x2E << 26),
94 OPC_LL = (0x30 << 26),
95 OPC_LLD = (0x34 << 26),
96 OPC_LD = (0x37 << 26),
97 OPC_SC = (0x38 << 26),
98 OPC_SCD = (0x3C << 26),
99 OPC_SD = (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1 = (0x31 << 26),
102 OPC_LWC2 = (0x32 << 26),
103 OPC_LDC1 = (0x35 << 26),
104 OPC_LDC2 = (0x36 << 26),
105 OPC_SWC1 = (0x39 << 26),
106 OPC_SWC2 = (0x3A << 26),
107 OPC_SDC1 = (0x3D << 26),
108 OPC_SDC2 = (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX = (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE = (0x2F << 26),
113 OPC_PREF = (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED = (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL = 0x00 | OPC_SPECIAL,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
128 OPC_SRA = 0x03 | OPC_SPECIAL,
129 OPC_SLLV = 0x04 | OPC_SPECIAL,
130 OPC_SRLV = 0x06 | OPC_SPECIAL, /* also ROTRV */
131 OPC_SRAV = 0x07 | OPC_SPECIAL,
132 OPC_DSLLV = 0x14 | OPC_SPECIAL,
133 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
134 OPC_DSRAV = 0x17 | OPC_SPECIAL,
135 OPC_DSLL = 0x38 | OPC_SPECIAL,
136 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
137 OPC_DSRA = 0x3B | OPC_SPECIAL,
138 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
139 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
140 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
141 /* Multiplication / division */
142 OPC_MULT = 0x18 | OPC_SPECIAL,
143 OPC_MULTU = 0x19 | OPC_SPECIAL,
144 OPC_DIV = 0x1A | OPC_SPECIAL,
145 OPC_DIVU = 0x1B | OPC_SPECIAL,
146 OPC_DMULT = 0x1C | OPC_SPECIAL,
147 OPC_DMULTU = 0x1D | OPC_SPECIAL,
148 OPC_DDIV = 0x1E | OPC_SPECIAL,
149 OPC_DDIVU = 0x1F | OPC_SPECIAL,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD = 0x20 | OPC_SPECIAL,
152 OPC_ADDU = 0x21 | OPC_SPECIAL,
153 OPC_SUB = 0x22 | OPC_SPECIAL,
154 OPC_SUBU = 0x23 | OPC_SPECIAL,
155 OPC_AND = 0x24 | OPC_SPECIAL,
156 OPC_OR = 0x25 | OPC_SPECIAL,
157 OPC_XOR = 0x26 | OPC_SPECIAL,
158 OPC_NOR = 0x27 | OPC_SPECIAL,
159 OPC_SLT = 0x2A | OPC_SPECIAL,
160 OPC_SLTU = 0x2B | OPC_SPECIAL,
161 OPC_DADD = 0x2C | OPC_SPECIAL,
162 OPC_DADDU = 0x2D | OPC_SPECIAL,
163 OPC_DSUB = 0x2E | OPC_SPECIAL,
164 OPC_DSUBU = 0x2F | OPC_SPECIAL,
166 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
167 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
169 OPC_TGE = 0x30 | OPC_SPECIAL,
170 OPC_TGEU = 0x31 | OPC_SPECIAL,
171 OPC_TLT = 0x32 | OPC_SPECIAL,
172 OPC_TLTU = 0x33 | OPC_SPECIAL,
173 OPC_TEQ = 0x34 | OPC_SPECIAL,
174 OPC_TNE = 0x36 | OPC_SPECIAL,
175 /* HI / LO registers load & stores */
176 OPC_MFHI = 0x10 | OPC_SPECIAL,
177 OPC_MTHI = 0x11 | OPC_SPECIAL,
178 OPC_MFLO = 0x12 | OPC_SPECIAL,
179 OPC_MTLO = 0x13 | OPC_SPECIAL,
180 /* Conditional moves */
181 OPC_MOVZ = 0x0A | OPC_SPECIAL,
182 OPC_MOVN = 0x0B | OPC_SPECIAL,
184 OPC_MOVCI = 0x01 | OPC_SPECIAL,
187 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
188 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
189 OPC_BREAK = 0x0D | OPC_SPECIAL,
190 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
191 OPC_SYNC = 0x0F | OPC_SPECIAL,
193 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
194 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
195 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
196 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
197 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
198 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
199 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS = (0x03 << 6) | OPC_MULT,
207 OPC_VR54XX_MULSU = (0x03 << 6) | OPC_MULTU,
208 OPC_VR54XX_MACC = (0x05 << 6) | OPC_MULT,
209 OPC_VR54XX_MACCU = (0x05 << 6) | OPC_MULTU,
210 OPC_VR54XX_MSAC = (0x07 << 6) | OPC_MULT,
211 OPC_VR54XX_MSACU = (0x07 << 6) | OPC_MULTU,
212 OPC_VR54XX_MULHI = (0x09 << 6) | OPC_MULT,
213 OPC_VR54XX_MULHIU = (0x09 << 6) | OPC_MULTU,
214 OPC_VR54XX_MULSHI = (0x0B << 6) | OPC_MULT,
215 OPC_VR54XX_MULSHIU = (0x0B << 6) | OPC_MULTU,
216 OPC_VR54XX_MACCHI = (0x0D << 6) | OPC_MULT,
217 OPC_VR54XX_MACCHIU = (0x0D << 6) | OPC_MULTU,
218 OPC_VR54XX_MSACHI = (0x0F << 6) | OPC_MULT,
219 OPC_VR54XX_MSACHIU = (0x0F << 6) | OPC_MULTU,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
227 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
228 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
229 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
230 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
231 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
232 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
233 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
234 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
235 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
236 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
237 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
238 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
239 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
240 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD = 0x00 | OPC_SPECIAL2,
249 OPC_MADDU = 0x01 | OPC_SPECIAL2,
250 OPC_MUL = 0x02 | OPC_SPECIAL2,
251 OPC_MSUB = 0x04 | OPC_SPECIAL2,
252 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
254 OPC_CLZ = 0x20 | OPC_SPECIAL2,
255 OPC_CLO = 0x21 | OPC_SPECIAL2,
256 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
257 OPC_DCLO = 0x25 | OPC_SPECIAL2,
259 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT = 0x00 | OPC_SPECIAL3,
267 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
268 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
269 OPC_DEXT = 0x03 | OPC_SPECIAL3,
270 OPC_INS = 0x04 | OPC_SPECIAL3,
271 OPC_DINSM = 0x05 | OPC_SPECIAL3,
272 OPC_DINSU = 0x06 | OPC_SPECIAL3,
273 OPC_DINS = 0x07 | OPC_SPECIAL3,
274 OPC_FORK = 0x08 | OPC_SPECIAL3,
275 OPC_YIELD = 0x09 | OPC_SPECIAL3,
276 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
277 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
278 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
286 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
287 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
295 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
303 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
304 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
305 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
306 OPC_MFTR = (0x08 << 21) | OPC_CP0,
307 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
308 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
309 OPC_MTTR = (0x0C << 21) | OPC_CP0,
310 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
311 OPC_C0 = (0x10 << 21) | OPC_CP0,
312 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
313 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
321 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
322 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
323 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
324 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
325 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR = 0x01 | OPC_C0,
333 OPC_TLBWI = 0x02 | OPC_C0,
334 OPC_TLBWR = 0x06 | OPC_C0,
335 OPC_TLBP = 0x08 | OPC_C0,
336 OPC_RFE = 0x10 | OPC_C0,
337 OPC_ERET = 0x18 | OPC_C0,
338 OPC_DERET = 0x1F | OPC_C0,
339 OPC_WAIT = 0x20 | OPC_C0,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
347 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
348 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
349 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
350 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
351 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
352 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
353 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
354 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
355 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
356 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
357 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
358 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
359 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
360 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
361 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
362 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F = (0x00 << 16) | OPC_BC1,
371 OPC_BC1T = (0x01 << 16) | OPC_BC1,
372 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
373 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
377 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
378 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
382 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
383 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
390 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
391 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
392 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
393 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
394 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
395 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
396 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
397 OPC_BC2 = (0x08 << 21) | OPC_CP2,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1 = 0x00 | OPC_CP3,
404 OPC_LDXC1 = 0x01 | OPC_CP3,
405 OPC_LUXC1 = 0x05 | OPC_CP3,
406 OPC_SWXC1 = 0x08 | OPC_CP3,
407 OPC_SDXC1 = 0x09 | OPC_CP3,
408 OPC_SUXC1 = 0x0D | OPC_CP3,
409 OPC_PREFX = 0x0F | OPC_CP3,
410 OPC_ALNV_PS = 0x1E | OPC_CP3,
411 OPC_MADD_S = 0x20 | OPC_CP3,
412 OPC_MADD_D = 0x21 | OPC_CP3,
413 OPC_MADD_PS = 0x26 | OPC_CP3,
414 OPC_MSUB_S = 0x28 | OPC_CP3,
415 OPC_MSUB_D = 0x29 | OPC_CP3,
416 OPC_MSUB_PS = 0x2E | OPC_CP3,
417 OPC_NMADD_S = 0x30 | OPC_CP3,
418 OPC_NMADD_D = 0x31 | OPC_CP3,
419 OPC_NMADD_PS= 0x36 | OPC_CP3,
420 OPC_NMSUB_S = 0x38 | OPC_CP3,
421 OPC_NMSUB_D = 0x39 | OPC_CP3,
422 OPC_NMSUB_PS= 0x3E | OPC_CP3,
425 /* global register indices */
426 static TCGv cpu_env, current_fpu;
428 /* FPU TNs, global for now. */
429 static TCGv fpu32_T[3], fpu64_T[3], fpu32h_T[3];
431 #include "gen-icount.h"
433 static inline void tcg_gen_helper_0_i(void *func, TCGv arg)
435 TCGv tmp = tcg_const_i32(arg);
437 tcg_gen_helper_0_1(func, tmp);
441 static inline void tcg_gen_helper_0_ii(void *func, TCGv arg1, TCGv arg2)
443 TCGv tmp1 = tcg_const_i32(arg1);
444 TCGv tmp2 = tcg_const_i32(arg2);
446 tcg_gen_helper_0_2(func, tmp1, tmp2);
451 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg1, TCGv arg2)
453 TCGv tmp = tcg_const_i32(arg2);
455 tcg_gen_helper_0_2(func, arg1, tmp);
459 static inline void tcg_gen_helper_0_2i(void *func, TCGv arg1, TCGv arg2, TCGv arg3)
461 TCGv tmp = tcg_const_i32(arg3);
463 tcg_gen_helper_0_3(func, arg1, arg2, tmp);
467 static inline void tcg_gen_helper_0_2ii(void *func, TCGv arg1, TCGv arg2, TCGv arg3, TCGv arg4)
469 TCGv tmp1 = tcg_const_i32(arg3);
470 TCGv tmp2 = tcg_const_i32(arg3);
472 tcg_gen_helper_0_4(func, arg1, arg2, tmp1, tmp2);
477 static inline void tcg_gen_helper_1_i(void *func, TCGv ret, TCGv arg)
479 TCGv tmp = tcg_const_i32(arg);
481 tcg_gen_helper_1_1(func, ret, tmp);
485 static inline void tcg_gen_helper_1_1i(void *func, TCGv ret, TCGv arg1, TCGv arg2)
487 TCGv tmp = tcg_const_i32(arg2);
489 tcg_gen_helper_1_2(func, ret, arg1, tmp);
493 static inline void tcg_gen_helper_1_2i(void *func, TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3)
495 TCGv tmp = tcg_const_i32(arg3);
497 tcg_gen_helper_1_3(func, ret, arg1, arg2, tmp);
501 static inline void tcg_gen_helper_1_2ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, TCGv arg4)
503 TCGv tmp1 = tcg_const_i32(arg3);
504 TCGv tmp2 = tcg_const_i32(arg3);
506 tcg_gen_helper_1_4(func, ret, arg1, arg2, tmp1, tmp2);
511 typedef struct DisasContext {
512 struct TranslationBlock *tb;
513 target_ulong pc, saved_pc;
516 /* Routine used to access memory */
518 uint32_t hflags, saved_hflags;
520 target_ulong btarget;
524 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
525 * exception condition
527 BS_STOP = 1, /* We want to stop translation for any reason */
528 BS_BRANCH = 2, /* We reached a branch condition */
529 BS_EXCP = 3, /* We reached an exception condition */
532 static const char *regnames[] =
533 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
534 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
535 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
536 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
538 static const char *fregnames[] =
539 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
540 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
541 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
542 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
544 #ifdef MIPS_DEBUG_DISAS
545 #define MIPS_DEBUG(fmt, args...) \
547 if (loglevel & CPU_LOG_TB_IN_ASM) { \
548 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
549 ctx->pc, ctx->opcode , ##args); \
553 #define MIPS_DEBUG(fmt, args...) do { } while(0)
556 #define MIPS_INVAL(op) \
558 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
559 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
562 /* General purpose registers moves. */
563 static inline void gen_load_gpr (TCGv t, int reg)
566 tcg_gen_movi_tl(t, 0);
568 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
569 sizeof(target_ulong) * reg);
572 static inline void gen_store_gpr (TCGv t, int reg)
575 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
576 sizeof(target_ulong) * reg);
579 /* Moves to/from HI and LO registers. */
580 static inline void gen_load_LO (TCGv t, int reg)
582 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
583 sizeof(target_ulong) * reg);
586 static inline void gen_store_LO (TCGv t, int reg)
588 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
589 sizeof(target_ulong) * reg);
592 static inline void gen_load_HI (TCGv t, int reg)
594 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
595 sizeof(target_ulong) * reg);
598 static inline void gen_store_HI (TCGv t, int reg)
600 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
601 sizeof(target_ulong) * reg);
604 /* Moves to/from shadow registers. */
605 static inline void gen_load_srsgpr (int from, int to)
607 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
610 tcg_gen_movi_tl(r_tmp1, 0);
612 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
614 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
615 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
616 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
617 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
618 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
620 tcg_gen_ld_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * from);
621 tcg_temp_free(r_tmp2);
623 gen_store_gpr(r_tmp1, to);
624 tcg_temp_free(r_tmp1);
627 static inline void gen_store_srsgpr (int from, int to)
630 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
631 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
633 gen_load_gpr(r_tmp1, from);
634 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
635 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
636 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
637 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
638 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
640 tcg_gen_st_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * to);
641 tcg_temp_free(r_tmp1);
642 tcg_temp_free(r_tmp2);
646 /* Floating point register moves. */
647 static inline void gen_load_fpr32 (TCGv t, int reg)
649 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
652 static inline void gen_store_fpr32 (TCGv t, int reg)
654 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
657 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
659 if (ctx->hflags & MIPS_HFLAG_F64) {
660 tcg_gen_ld_i64(t, current_fpu, 8 * reg);
662 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
663 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
665 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
666 tcg_gen_extu_i32_i64(t, r_tmp1);
667 tcg_gen_shli_i64(t, t, 32);
668 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
669 tcg_gen_extu_i32_i64(r_tmp2, r_tmp1);
670 tcg_gen_or_i64(t, t, r_tmp2);
671 tcg_temp_free(r_tmp1);
672 tcg_temp_free(r_tmp2);
676 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
678 if (ctx->hflags & MIPS_HFLAG_F64) {
679 tcg_gen_st_i64(t, current_fpu, 8 * reg);
681 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
683 tcg_gen_trunc_i64_i32(r_tmp, t);
684 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
685 tcg_gen_shri_i64(t, t, 32);
686 tcg_gen_trunc_i64_i32(r_tmp, t);
687 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
688 tcg_temp_free(r_tmp);
692 static inline void gen_load_fpr32h (TCGv t, int reg)
694 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
697 static inline void gen_store_fpr32h (TCGv t, int reg)
699 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
702 static inline void get_fp_cond (TCGv t)
704 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
705 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
707 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
708 tcg_gen_shri_i32(r_tmp2, r_tmp1, 24);
709 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
710 tcg_gen_shri_i32(r_tmp1, r_tmp1, 23);
711 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
712 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
713 tcg_temp_free(r_tmp1);
714 tcg_temp_free(r_tmp2);
717 #define FOP_CONDS(type, fmt) \
718 static GenOpFunc1 * fcmp ## type ## _ ## fmt ## _table[16] = { \
719 do_cmp ## type ## _ ## fmt ## _f, \
720 do_cmp ## type ## _ ## fmt ## _un, \
721 do_cmp ## type ## _ ## fmt ## _eq, \
722 do_cmp ## type ## _ ## fmt ## _ueq, \
723 do_cmp ## type ## _ ## fmt ## _olt, \
724 do_cmp ## type ## _ ## fmt ## _ult, \
725 do_cmp ## type ## _ ## fmt ## _ole, \
726 do_cmp ## type ## _ ## fmt ## _ule, \
727 do_cmp ## type ## _ ## fmt ## _sf, \
728 do_cmp ## type ## _ ## fmt ## _ngle, \
729 do_cmp ## type ## _ ## fmt ## _seq, \
730 do_cmp ## type ## _ ## fmt ## _ngl, \
731 do_cmp ## type ## _ ## fmt ## _lt, \
732 do_cmp ## type ## _ ## fmt ## _nge, \
733 do_cmp ## type ## _ ## fmt ## _le, \
734 do_cmp ## type ## _ ## fmt ## _ngt, \
736 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
738 tcg_gen_helper_0_i(fcmp ## type ## _ ## fmt ## _table[n], cc); \
750 #define OP_COND(name, cond) \
751 void glue(gen_op_, name) (TCGv t0, TCGv t1) \
753 int l1 = gen_new_label(); \
754 int l2 = gen_new_label(); \
756 tcg_gen_brcond_tl(cond, t0, t1, l1); \
757 tcg_gen_movi_tl(t0, 0); \
760 tcg_gen_movi_tl(t0, 1); \
763 OP_COND(eq, TCG_COND_EQ);
764 OP_COND(ne, TCG_COND_NE);
765 OP_COND(ge, TCG_COND_GE);
766 OP_COND(geu, TCG_COND_GEU);
767 OP_COND(lt, TCG_COND_LT);
768 OP_COND(ltu, TCG_COND_LTU);
771 #define OP_CONDI(name, cond) \
772 void glue(gen_op_, name) (TCGv t, target_ulong val) \
774 int l1 = gen_new_label(); \
775 int l2 = gen_new_label(); \
777 tcg_gen_brcondi_tl(cond, t, val, l1); \
778 tcg_gen_movi_tl(t, 0); \
781 tcg_gen_movi_tl(t, 1); \
784 OP_CONDI(lti, TCG_COND_LT);
785 OP_CONDI(ltiu, TCG_COND_LTU);
788 #define OP_CONDZ(name, cond) \
789 void glue(gen_op_, name) (TCGv t) \
791 int l1 = gen_new_label(); \
792 int l2 = gen_new_label(); \
794 tcg_gen_brcondi_tl(cond, t, 0, l1); \
795 tcg_gen_movi_tl(t, 0); \
798 tcg_gen_movi_tl(t, 1); \
801 OP_CONDZ(gez, TCG_COND_GE);
802 OP_CONDZ(gtz, TCG_COND_GT);
803 OP_CONDZ(lez, TCG_COND_LE);
804 OP_CONDZ(ltz, TCG_COND_LT);
807 static inline void gen_save_pc(target_ulong pc)
809 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
811 tcg_gen_movi_tl(r_tmp, pc);
812 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, active_tc.PC));
813 tcg_temp_free(r_tmp);
816 static inline void gen_breg_pc(void)
818 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
820 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
821 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, active_tc.PC));
822 tcg_temp_free(r_tmp);
825 static inline void gen_save_btarget(target_ulong btarget)
827 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
829 tcg_gen_movi_tl(r_tmp, btarget);
830 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
831 tcg_temp_free(r_tmp);
834 static always_inline void gen_save_breg_target(int reg)
836 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
838 gen_load_gpr(r_tmp, reg);
839 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
840 tcg_temp_free(r_tmp);
843 static always_inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
845 #if defined MIPS_DEBUG_DISAS
846 if (loglevel & CPU_LOG_TB_IN_ASM) {
847 fprintf(logfile, "hflags %08x saved %08x\n",
848 ctx->hflags, ctx->saved_hflags);
851 if (do_save_pc && ctx->pc != ctx->saved_pc) {
852 gen_save_pc(ctx->pc);
853 ctx->saved_pc = ctx->pc;
855 if (ctx->hflags != ctx->saved_hflags) {
856 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
858 tcg_gen_movi_i32(r_tmp, ctx->hflags);
859 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
860 tcg_temp_free(r_tmp);
861 ctx->saved_hflags = ctx->hflags;
862 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
868 gen_save_btarget(ctx->btarget);
874 static always_inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
876 ctx->saved_hflags = ctx->hflags;
877 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
883 ctx->btarget = env->btarget;
888 static always_inline void
889 generate_exception_err (DisasContext *ctx, int excp, int err)
891 save_cpu_state(ctx, 1);
892 tcg_gen_helper_0_ii(do_raise_exception_err, excp, err);
893 tcg_gen_helper_0_0(do_interrupt_restart);
897 static always_inline void
898 generate_exception (DisasContext *ctx, int excp)
900 save_cpu_state(ctx, 1);
901 tcg_gen_helper_0_i(do_raise_exception, excp);
902 tcg_gen_helper_0_0(do_interrupt_restart);
906 /* Addresses computation */
907 static inline void gen_op_addr_add (TCGv t0, TCGv t1)
909 tcg_gen_add_tl(t0, t0, t1);
911 #if defined(TARGET_MIPS64)
912 /* For compatibility with 32-bit code, data reference in user mode
913 with Status_UX = 0 should be casted to 32-bit and sign extended.
914 See the MIPS64 PRA manual, section 4.10. */
916 int l1 = gen_new_label();
917 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
919 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
920 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
921 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
922 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
923 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
924 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
925 tcg_temp_free(r_tmp);
926 tcg_gen_ext32s_i64(t0, t0);
932 static always_inline void check_cp0_enabled(DisasContext *ctx)
934 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
935 generate_exception_err(ctx, EXCP_CpU, 1);
938 static always_inline void check_cp1_enabled(DisasContext *ctx)
940 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
941 generate_exception_err(ctx, EXCP_CpU, 1);
944 /* Verify that the processor is running with COP1X instructions enabled.
945 This is associated with the nabla symbol in the MIPS32 and MIPS64
948 static always_inline void check_cop1x(DisasContext *ctx)
950 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
951 generate_exception(ctx, EXCP_RI);
954 /* Verify that the processor is running with 64-bit floating-point
955 operations enabled. */
957 static always_inline void check_cp1_64bitmode(DisasContext *ctx)
959 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
960 generate_exception(ctx, EXCP_RI);
964 * Verify if floating point register is valid; an operation is not defined
965 * if bit 0 of any register specification is set and the FR bit in the
966 * Status register equals zero, since the register numbers specify an
967 * even-odd pair of adjacent coprocessor general registers. When the FR bit
968 * in the Status register equals one, both even and odd register numbers
969 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
971 * Multiple 64 bit wide registers can be checked by calling
972 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
974 void check_cp1_registers(DisasContext *ctx, int regs)
976 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
977 generate_exception(ctx, EXCP_RI);
980 /* This code generates a "reserved instruction" exception if the
981 CPU does not support the instruction set corresponding to flags. */
982 static always_inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
984 if (unlikely(!(env->insn_flags & flags)))
985 generate_exception(ctx, EXCP_RI);
988 /* This code generates a "reserved instruction" exception if 64-bit
989 instructions are not enabled. */
990 static always_inline void check_mips_64(DisasContext *ctx)
992 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
993 generate_exception(ctx, EXCP_RI);
996 /* load/store instructions. */
997 #define OP_LD(insn,fname) \
998 void inline op_ldst_##insn(TCGv t0, DisasContext *ctx) \
1000 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1007 #if defined(TARGET_MIPS64)
1013 #define OP_ST(insn,fname) \
1014 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1016 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1021 #if defined(TARGET_MIPS64)
1026 #define OP_LD_ATOMIC(insn,fname) \
1027 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1029 tcg_gen_mov_tl(t1, t0); \
1030 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1031 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1033 OP_LD_ATOMIC(ll,ld32s);
1034 #if defined(TARGET_MIPS64)
1035 OP_LD_ATOMIC(lld,ld64);
1039 #define OP_ST_ATOMIC(insn,fname,almask) \
1040 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1042 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1043 int l1 = gen_new_label(); \
1044 int l2 = gen_new_label(); \
1045 int l3 = gen_new_label(); \
1047 tcg_gen_andi_tl(r_tmp, t0, almask); \
1048 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1049 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1050 generate_exception(ctx, EXCP_AdES); \
1051 gen_set_label(l1); \
1052 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1053 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1054 tcg_temp_free(r_tmp); \
1055 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1056 tcg_gen_movi_tl(t0, 1); \
1058 gen_set_label(l2); \
1059 tcg_gen_movi_tl(t0, 0); \
1060 gen_set_label(l3); \
1062 OP_ST_ATOMIC(sc,st32,0x3);
1063 #if defined(TARGET_MIPS64)
1064 OP_ST_ATOMIC(scd,st64,0x7);
1068 /* Load and store */
1069 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1070 int base, int16_t offset)
1072 const char *opn = "ldst";
1073 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1074 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1077 tcg_gen_movi_tl(t0, offset);
1078 } else if (offset == 0) {
1079 gen_load_gpr(t0, base);
1081 gen_load_gpr(t0, base);
1082 tcg_gen_movi_tl(t1, offset);
1083 gen_op_addr_add(t0, t1);
1085 /* Don't do NOP if destination is zero: we must perform the actual
1088 #if defined(TARGET_MIPS64)
1090 op_ldst_lwu(t0, ctx);
1091 gen_store_gpr(t0, rt);
1095 op_ldst_ld(t0, ctx);
1096 gen_store_gpr(t0, rt);
1100 op_ldst_lld(t0, t1, ctx);
1101 gen_store_gpr(t0, rt);
1105 gen_load_gpr(t1, rt);
1106 op_ldst_sd(t0, t1, ctx);
1110 save_cpu_state(ctx, 1);
1111 gen_load_gpr(t1, rt);
1112 op_ldst_scd(t0, t1, ctx);
1113 gen_store_gpr(t0, rt);
1117 save_cpu_state(ctx, 1);
1118 gen_load_gpr(t1, rt);
1119 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1120 gen_store_gpr(t1, rt);
1124 save_cpu_state(ctx, 1);
1125 gen_load_gpr(t1, rt);
1126 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1130 save_cpu_state(ctx, 1);
1131 gen_load_gpr(t1, rt);
1132 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1133 gen_store_gpr(t1, rt);
1137 save_cpu_state(ctx, 1);
1138 gen_load_gpr(t1, rt);
1139 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1144 op_ldst_lw(t0, ctx);
1145 gen_store_gpr(t0, rt);
1149 gen_load_gpr(t1, rt);
1150 op_ldst_sw(t0, t1, ctx);
1154 op_ldst_lh(t0, ctx);
1155 gen_store_gpr(t0, rt);
1159 gen_load_gpr(t1, rt);
1160 op_ldst_sh(t0, t1, ctx);
1164 op_ldst_lhu(t0, ctx);
1165 gen_store_gpr(t0, rt);
1169 op_ldst_lb(t0, ctx);
1170 gen_store_gpr(t0, rt);
1174 gen_load_gpr(t1, rt);
1175 op_ldst_sb(t0, t1, ctx);
1179 op_ldst_lbu(t0, ctx);
1180 gen_store_gpr(t0, rt);
1184 save_cpu_state(ctx, 1);
1185 gen_load_gpr(t1, rt);
1186 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1187 gen_store_gpr(t1, rt);
1191 save_cpu_state(ctx, 1);
1192 gen_load_gpr(t1, rt);
1193 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1197 save_cpu_state(ctx, 1);
1198 gen_load_gpr(t1, rt);
1199 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1200 gen_store_gpr(t1, rt);
1204 save_cpu_state(ctx, 1);
1205 gen_load_gpr(t1, rt);
1206 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1210 op_ldst_ll(t0, t1, ctx);
1211 gen_store_gpr(t0, rt);
1215 save_cpu_state(ctx, 1);
1216 gen_load_gpr(t1, rt);
1217 op_ldst_sc(t0, t1, ctx);
1218 gen_store_gpr(t0, rt);
1223 generate_exception(ctx, EXCP_RI);
1226 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1232 /* Load and store */
1233 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1234 int base, int16_t offset)
1236 const char *opn = "flt_ldst";
1237 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1240 tcg_gen_movi_tl(t0, offset);
1241 } else if (offset == 0) {
1242 gen_load_gpr(t0, base);
1244 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1246 gen_load_gpr(t0, base);
1247 tcg_gen_movi_tl(t1, offset);
1248 gen_op_addr_add(t0, t1);
1251 /* Don't do NOP if destination is zero: we must perform the actual
1255 tcg_gen_qemu_ld32s(fpu32_T[0], t0, ctx->mem_idx);
1256 gen_store_fpr32(fpu32_T[0], ft);
1260 gen_load_fpr32(fpu32_T[0], ft);
1261 tcg_gen_qemu_st32(fpu32_T[0], t0, ctx->mem_idx);
1265 tcg_gen_qemu_ld64(fpu64_T[0], t0, ctx->mem_idx);
1266 gen_store_fpr64(ctx, fpu64_T[0], ft);
1270 gen_load_fpr64(ctx, fpu64_T[0], ft);
1271 tcg_gen_qemu_st64(fpu64_T[0], 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);
1444 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1446 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1447 tcg_gen_movi_i32(r_tmp2, 0x20);
1448 tcg_gen_subi_i32(r_tmp2, r_tmp2, uimm);
1449 tcg_gen_shl_i32(r_tmp2, r_tmp1, r_tmp2);
1450 tcg_gen_shri_i32(r_tmp1, r_tmp1, uimm);
1451 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp2);
1452 tcg_gen_ext_i32_tl(t0, r_tmp1);
1453 tcg_temp_free(r_tmp1);
1454 tcg_temp_free(r_tmp2);
1458 tcg_gen_ext32u_tl(t0, t0);
1459 tcg_gen_shri_tl(t0, t0, uimm);
1460 tcg_gen_ext32s_tl(t0, t0);
1465 MIPS_INVAL("invalid srl flag");
1466 generate_exception(ctx, EXCP_RI);
1470 #if defined(TARGET_MIPS64)
1472 tcg_gen_shli_tl(t0, t0, uimm);
1476 tcg_gen_sari_tl(t0, t0, uimm);
1480 switch ((ctx->opcode >> 21) & 0x1f) {
1482 tcg_gen_shri_tl(t0, t0, uimm);
1486 /* drotr is decoded as dsrl on non-R2 CPUs */
1487 if (env->insn_flags & ISA_MIPS32R2) {
1489 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1491 tcg_gen_movi_tl(r_tmp1, 0x40);
1492 tcg_gen_subi_tl(r_tmp1, r_tmp1, uimm);
1493 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1494 tcg_gen_shri_tl(t0, t0, uimm);
1495 tcg_gen_or_tl(t0, t0, r_tmp1);
1496 tcg_temp_free(r_tmp1);
1500 tcg_gen_shri_tl(t0, t0, uimm);
1505 MIPS_INVAL("invalid dsrl flag");
1506 generate_exception(ctx, EXCP_RI);
1511 tcg_gen_shli_tl(t0, t0, uimm + 32);
1515 tcg_gen_sari_tl(t0, t0, uimm + 32);
1519 switch ((ctx->opcode >> 21) & 0x1f) {
1521 tcg_gen_shri_tl(t0, t0, uimm + 32);
1525 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1526 if (env->insn_flags & ISA_MIPS32R2) {
1527 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1528 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1530 tcg_gen_movi_tl(r_tmp1, 0x40);
1531 tcg_gen_movi_tl(r_tmp2, 32);
1532 tcg_gen_addi_tl(r_tmp2, r_tmp2, uimm);
1533 tcg_gen_sub_tl(r_tmp1, r_tmp1, r_tmp2);
1534 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1535 tcg_gen_shr_tl(t0, t0, r_tmp2);
1536 tcg_gen_or_tl(t0, t0, r_tmp1);
1537 tcg_temp_free(r_tmp1);
1538 tcg_temp_free(r_tmp2);
1541 tcg_gen_shri_tl(t0, t0, uimm + 32);
1546 MIPS_INVAL("invalid dsrl32 flag");
1547 generate_exception(ctx, EXCP_RI);
1554 generate_exception(ctx, EXCP_RI);
1557 gen_store_gpr(t0, rt);
1558 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1564 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1565 int rd, int rs, int rt)
1567 const char *opn = "arith";
1568 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1569 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1571 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1572 && opc != OPC_DADD && opc != OPC_DSUB) {
1573 /* If no destination, treat it as a NOP.
1574 For add & sub, we must generate the overflow exception when needed. */
1578 gen_load_gpr(t0, rs);
1579 /* Specialcase the conventional move operation. */
1580 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1581 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1582 gen_store_gpr(t0, rd);
1585 gen_load_gpr(t1, rt);
1589 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1590 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1591 int l1 = gen_new_label();
1593 save_cpu_state(ctx, 1);
1594 tcg_gen_ext32s_tl(r_tmp1, t0);
1595 tcg_gen_ext32s_tl(r_tmp2, t1);
1596 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1598 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1599 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1600 tcg_gen_xor_tl(r_tmp2, t0, t1);
1601 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1602 tcg_temp_free(r_tmp2);
1603 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1604 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1605 tcg_temp_free(r_tmp1);
1606 /* operands of same sign, result different sign */
1607 generate_exception(ctx, EXCP_OVERFLOW);
1610 tcg_gen_ext32s_tl(t0, t0);
1615 tcg_gen_ext32s_tl(t0, t0);
1616 tcg_gen_ext32s_tl(t1, t1);
1617 tcg_gen_add_tl(t0, t0, t1);
1618 tcg_gen_ext32s_tl(t0, t0);
1623 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1624 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1625 int l1 = gen_new_label();
1627 save_cpu_state(ctx, 1);
1628 tcg_gen_ext32s_tl(r_tmp1, t0);
1629 tcg_gen_ext32s_tl(r_tmp2, t1);
1630 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1632 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1633 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1634 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1635 tcg_temp_free(r_tmp2);
1636 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1637 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1638 tcg_temp_free(r_tmp1);
1639 /* operands of different sign, first operand and result different sign */
1640 generate_exception(ctx, EXCP_OVERFLOW);
1643 tcg_gen_ext32s_tl(t0, t0);
1648 tcg_gen_ext32s_tl(t0, t0);
1649 tcg_gen_ext32s_tl(t1, t1);
1650 tcg_gen_sub_tl(t0, t0, t1);
1651 tcg_gen_ext32s_tl(t0, t0);
1654 #if defined(TARGET_MIPS64)
1657 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1658 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1659 int l1 = gen_new_label();
1661 save_cpu_state(ctx, 1);
1662 tcg_gen_mov_tl(r_tmp1, t0);
1663 tcg_gen_add_tl(t0, t0, t1);
1665 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1666 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1667 tcg_gen_xor_tl(r_tmp2, t0, t1);
1668 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1669 tcg_temp_free(r_tmp2);
1670 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1671 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1672 tcg_temp_free(r_tmp1);
1673 /* operands of same sign, result different sign */
1674 generate_exception(ctx, EXCP_OVERFLOW);
1680 tcg_gen_add_tl(t0, t0, t1);
1685 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1686 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1687 int l1 = gen_new_label();
1689 save_cpu_state(ctx, 1);
1690 tcg_gen_mov_tl(r_tmp1, t0);
1691 tcg_gen_sub_tl(t0, t0, t1);
1693 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1694 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1695 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1696 tcg_temp_free(r_tmp2);
1697 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1698 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1699 tcg_temp_free(r_tmp1);
1700 /* operands of different sign, first operand and result different sign */
1701 generate_exception(ctx, EXCP_OVERFLOW);
1707 tcg_gen_sub_tl(t0, t0, t1);
1720 tcg_gen_and_tl(t0, t0, t1);
1724 tcg_gen_or_tl(t0, t0, t1);
1725 tcg_gen_not_tl(t0, t0);
1729 tcg_gen_or_tl(t0, t0, t1);
1733 tcg_gen_xor_tl(t0, t0, t1);
1737 tcg_gen_ext32s_tl(t0, t0);
1738 tcg_gen_ext32s_tl(t1, t1);
1739 tcg_gen_mul_tl(t0, t0, t1);
1740 tcg_gen_ext32s_tl(t0, t0);
1745 int l1 = gen_new_label();
1747 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1748 gen_store_gpr(t0, rd);
1755 int l1 = gen_new_label();
1757 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1758 gen_store_gpr(t0, rd);
1764 tcg_gen_ext32u_tl(t0, t0);
1765 tcg_gen_ext32u_tl(t1, t1);
1766 tcg_gen_andi_tl(t0, t0, 0x1f);
1767 tcg_gen_shl_tl(t0, t1, t0);
1768 tcg_gen_ext32s_tl(t0, t0);
1772 tcg_gen_ext32s_tl(t1, t1);
1773 tcg_gen_andi_tl(t0, t0, 0x1f);
1774 tcg_gen_sar_tl(t0, t1, t0);
1775 tcg_gen_ext32s_tl(t0, t0);
1779 switch ((ctx->opcode >> 6) & 0x1f) {
1781 tcg_gen_ext32u_tl(t1, t1);
1782 tcg_gen_andi_tl(t0, t0, 0x1f);
1783 tcg_gen_shr_tl(t0, t1, t0);
1784 tcg_gen_ext32s_tl(t0, t0);
1788 /* rotrv is decoded as srlv on non-R2 CPUs */
1789 if (env->insn_flags & ISA_MIPS32R2) {
1790 int l1 = gen_new_label();
1791 int l2 = gen_new_label();
1793 tcg_gen_andi_tl(t0, t0, 0x1f);
1794 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1796 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1797 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1798 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1800 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1801 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1802 tcg_gen_movi_i32(r_tmp3, 0x20);
1803 tcg_gen_sub_i32(r_tmp3, r_tmp3, r_tmp1);
1804 tcg_gen_shl_i32(r_tmp3, r_tmp2, r_tmp3);
1805 tcg_gen_shr_i32(r_tmp1, r_tmp2, r_tmp1);
1806 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp3);
1807 tcg_gen_ext_i32_tl(t0, r_tmp1);
1808 tcg_temp_free(r_tmp1);
1809 tcg_temp_free(r_tmp2);
1810 tcg_temp_free(r_tmp3);
1814 tcg_gen_mov_tl(t0, t1);
1818 tcg_gen_ext32u_tl(t1, t1);
1819 tcg_gen_andi_tl(t0, t0, 0x1f);
1820 tcg_gen_shr_tl(t0, t1, t0);
1821 tcg_gen_ext32s_tl(t0, t0);
1826 MIPS_INVAL("invalid srlv flag");
1827 generate_exception(ctx, EXCP_RI);
1831 #if defined(TARGET_MIPS64)
1833 tcg_gen_andi_tl(t0, t0, 0x3f);
1834 tcg_gen_shl_tl(t0, t1, t0);
1838 tcg_gen_andi_tl(t0, t0, 0x3f);
1839 tcg_gen_sar_tl(t0, t1, t0);
1843 switch ((ctx->opcode >> 6) & 0x1f) {
1845 tcg_gen_andi_tl(t0, t0, 0x3f);
1846 tcg_gen_shr_tl(t0, t1, t0);
1850 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1851 if (env->insn_flags & ISA_MIPS32R2) {
1852 int l1 = gen_new_label();
1853 int l2 = gen_new_label();
1855 tcg_gen_andi_tl(t0, t0, 0x3f);
1856 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1858 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1860 tcg_gen_movi_tl(r_tmp1, 0x40);
1861 tcg_gen_sub_tl(r_tmp1, r_tmp1, t0);
1862 tcg_gen_shl_tl(r_tmp1, t1, r_tmp1);
1863 tcg_gen_shr_tl(t0, t1, t0);
1864 tcg_gen_or_tl(t0, t0, r_tmp1);
1865 tcg_temp_free(r_tmp1);
1869 tcg_gen_mov_tl(t0, t1);
1873 tcg_gen_andi_tl(t0, t0, 0x3f);
1874 tcg_gen_shr_tl(t0, t1, t0);
1879 MIPS_INVAL("invalid dsrlv flag");
1880 generate_exception(ctx, EXCP_RI);
1887 generate_exception(ctx, EXCP_RI);
1890 gen_store_gpr(t0, rd);
1892 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1898 /* Arithmetic on HI/LO registers */
1899 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1901 const char *opn = "hilo";
1902 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1904 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1912 gen_store_gpr(t0, reg);
1917 gen_store_gpr(t0, reg);
1921 gen_load_gpr(t0, reg);
1922 gen_store_HI(t0, 0);
1926 gen_load_gpr(t0, reg);
1927 gen_store_LO(t0, 0);
1932 generate_exception(ctx, EXCP_RI);
1935 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1940 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1943 const char *opn = "mul/div";
1944 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1945 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1947 gen_load_gpr(t0, rs);
1948 gen_load_gpr(t1, rt);
1952 int l1 = gen_new_label();
1954 tcg_gen_ext32s_tl(t0, t0);
1955 tcg_gen_ext32s_tl(t1, t1);
1956 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1958 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1959 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1960 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1962 tcg_gen_ext_tl_i64(r_tmp1, t0);
1963 tcg_gen_ext_tl_i64(r_tmp2, t1);
1964 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1965 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1966 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1967 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1968 tcg_temp_free(r_tmp1);
1969 tcg_temp_free(r_tmp2);
1970 tcg_temp_free(r_tmp3);
1971 tcg_gen_ext32s_tl(t0, t0);
1972 tcg_gen_ext32s_tl(t1, t1);
1973 gen_store_LO(t0, 0);
1974 gen_store_HI(t1, 0);
1982 int l1 = gen_new_label();
1984 tcg_gen_ext32s_tl(t1, t1);
1985 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1987 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1988 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1989 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1991 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1992 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1993 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1994 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1995 tcg_gen_ext_i32_tl(t0, r_tmp3);
1996 tcg_gen_ext_i32_tl(t1, r_tmp1);
1997 tcg_temp_free(r_tmp1);
1998 tcg_temp_free(r_tmp2);
1999 tcg_temp_free(r_tmp3);
2000 gen_store_LO(t0, 0);
2001 gen_store_HI(t1, 0);
2009 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2010 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2012 tcg_gen_ext32s_tl(t0, t0);
2013 tcg_gen_ext32s_tl(t1, t1);
2014 tcg_gen_ext_tl_i64(r_tmp1, t0);
2015 tcg_gen_ext_tl_i64(r_tmp2, t1);
2016 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2017 tcg_temp_free(r_tmp2);
2018 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2019 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2020 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2021 tcg_temp_free(r_tmp1);
2022 tcg_gen_ext32s_tl(t0, t0);
2023 tcg_gen_ext32s_tl(t1, t1);
2024 gen_store_LO(t0, 0);
2025 gen_store_HI(t1, 0);
2031 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2032 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2034 tcg_gen_ext32u_tl(t0, t0);
2035 tcg_gen_ext32u_tl(t1, t1);
2036 tcg_gen_extu_tl_i64(r_tmp1, t0);
2037 tcg_gen_extu_tl_i64(r_tmp2, t1);
2038 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2039 tcg_temp_free(r_tmp2);
2040 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2041 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2042 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2043 tcg_temp_free(r_tmp1);
2044 tcg_gen_ext32s_tl(t0, t0);
2045 tcg_gen_ext32s_tl(t1, t1);
2046 gen_store_LO(t0, 0);
2047 gen_store_HI(t1, 0);
2051 #if defined(TARGET_MIPS64)
2054 int l1 = gen_new_label();
2056 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2058 int l2 = gen_new_label();
2060 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2061 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2063 tcg_gen_movi_tl(t1, 0);
2064 gen_store_LO(t0, 0);
2065 gen_store_HI(t1, 0);
2070 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2071 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2073 tcg_gen_div_i64(r_tmp1, t0, t1);
2074 tcg_gen_rem_i64(r_tmp2, t0, t1);
2075 gen_store_LO(r_tmp1, 0);
2076 gen_store_HI(r_tmp2, 0);
2077 tcg_temp_free(r_tmp1);
2078 tcg_temp_free(r_tmp2);
2087 int l1 = gen_new_label();
2089 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2091 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2092 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2094 tcg_gen_divu_i64(r_tmp1, t0, t1);
2095 tcg_gen_remu_i64(r_tmp2, t0, t1);
2096 tcg_temp_free(r_tmp1);
2097 tcg_temp_free(r_tmp2);
2098 gen_store_LO(r_tmp1, 0);
2099 gen_store_HI(r_tmp2, 0);
2106 tcg_gen_helper_0_2(do_dmult, t0, t1);
2110 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2116 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2117 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2118 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2120 tcg_gen_ext32s_tl(t0, t0);
2121 tcg_gen_ext32s_tl(t1, t1);
2122 tcg_gen_ext_tl_i64(r_tmp1, t0);
2123 tcg_gen_ext_tl_i64(r_tmp2, t1);
2124 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2127 tcg_gen_extu_tl_i64(r_tmp2, t0);
2128 tcg_gen_extu_tl_i64(r_tmp3, t1);
2129 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2130 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2131 tcg_temp_free(r_tmp3);
2132 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2133 tcg_temp_free(r_tmp2);
2134 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2135 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2136 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2137 tcg_temp_free(r_tmp1);
2138 tcg_gen_ext32s_tl(t0, t0);
2139 tcg_gen_ext32s_tl(t1, t1);
2140 gen_store_LO(t0, 0);
2141 gen_store_HI(t1, 0);
2147 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2148 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2149 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2151 tcg_gen_ext32u_tl(t0, t0);
2152 tcg_gen_ext32u_tl(t1, t1);
2153 tcg_gen_extu_tl_i64(r_tmp1, t0);
2154 tcg_gen_extu_tl_i64(r_tmp2, t1);
2155 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2158 tcg_gen_extu_tl_i64(r_tmp2, t0);
2159 tcg_gen_extu_tl_i64(r_tmp3, t1);
2160 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2161 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2162 tcg_temp_free(r_tmp3);
2163 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2164 tcg_temp_free(r_tmp2);
2165 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2166 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2167 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2168 tcg_temp_free(r_tmp1);
2169 tcg_gen_ext32s_tl(t0, t0);
2170 tcg_gen_ext32s_tl(t1, t1);
2171 gen_store_LO(t0, 0);
2172 gen_store_HI(t1, 0);
2178 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2179 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2180 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2182 tcg_gen_ext32s_tl(t0, t0);
2183 tcg_gen_ext32s_tl(t1, t1);
2184 tcg_gen_ext_tl_i64(r_tmp1, t0);
2185 tcg_gen_ext_tl_i64(r_tmp2, t1);
2186 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2189 tcg_gen_extu_tl_i64(r_tmp2, t0);
2190 tcg_gen_extu_tl_i64(r_tmp3, t1);
2191 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2192 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2193 tcg_temp_free(r_tmp3);
2194 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2195 tcg_temp_free(r_tmp2);
2196 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2197 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2198 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2199 tcg_temp_free(r_tmp1);
2200 tcg_gen_ext32s_tl(t0, t0);
2201 tcg_gen_ext32s_tl(t1, t1);
2202 gen_store_LO(t0, 0);
2203 gen_store_HI(t1, 0);
2209 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2210 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2211 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2213 tcg_gen_ext32u_tl(t0, t0);
2214 tcg_gen_ext32u_tl(t1, t1);
2215 tcg_gen_extu_tl_i64(r_tmp1, t0);
2216 tcg_gen_extu_tl_i64(r_tmp2, t1);
2217 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2220 tcg_gen_extu_tl_i64(r_tmp2, t0);
2221 tcg_gen_extu_tl_i64(r_tmp3, t1);
2222 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2223 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2224 tcg_temp_free(r_tmp3);
2225 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2226 tcg_temp_free(r_tmp2);
2227 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2228 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2229 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2230 tcg_temp_free(r_tmp1);
2231 tcg_gen_ext32s_tl(t0, t0);
2232 tcg_gen_ext32s_tl(t1, t1);
2233 gen_store_LO(t0, 0);
2234 gen_store_HI(t1, 0);
2240 generate_exception(ctx, EXCP_RI);
2243 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2249 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2250 int rd, int rs, int rt)
2252 const char *opn = "mul vr54xx";
2253 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2254 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2256 gen_load_gpr(t0, rs);
2257 gen_load_gpr(t1, rt);
2260 case OPC_VR54XX_MULS:
2261 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2264 case OPC_VR54XX_MULSU:
2265 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2268 case OPC_VR54XX_MACC:
2269 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2272 case OPC_VR54XX_MACCU:
2273 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2276 case OPC_VR54XX_MSAC:
2277 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2280 case OPC_VR54XX_MSACU:
2281 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2284 case OPC_VR54XX_MULHI:
2285 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2288 case OPC_VR54XX_MULHIU:
2289 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2292 case OPC_VR54XX_MULSHI:
2293 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2296 case OPC_VR54XX_MULSHIU:
2297 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2300 case OPC_VR54XX_MACCHI:
2301 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2304 case OPC_VR54XX_MACCHIU:
2305 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2308 case OPC_VR54XX_MSACHI:
2309 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2312 case OPC_VR54XX_MSACHIU:
2313 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2317 MIPS_INVAL("mul vr54xx");
2318 generate_exception(ctx, EXCP_RI);
2321 gen_store_gpr(t0, rd);
2322 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2329 static void gen_cl (DisasContext *ctx, uint32_t opc,
2332 const char *opn = "CLx";
2333 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2340 gen_load_gpr(t0, rs);
2343 tcg_gen_helper_1_1(do_clo, t0, t0);
2347 tcg_gen_helper_1_1(do_clz, t0, t0);
2350 #if defined(TARGET_MIPS64)
2352 tcg_gen_helper_1_1(do_dclo, t0, t0);
2356 tcg_gen_helper_1_1(do_dclz, t0, t0);
2362 generate_exception(ctx, EXCP_RI);
2365 gen_store_gpr(t0, rd);
2366 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2373 static void gen_trap (DisasContext *ctx, uint32_t opc,
2374 int rs, int rt, int16_t imm)
2377 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2378 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2381 /* Load needed operands */
2389 /* Compare two registers */
2391 gen_load_gpr(t0, rs);
2392 gen_load_gpr(t1, rt);
2402 /* Compare register to immediate */
2403 if (rs != 0 || imm != 0) {
2404 gen_load_gpr(t0, rs);
2405 tcg_gen_movi_tl(t1, (int32_t)imm);
2412 case OPC_TEQ: /* rs == rs */
2413 case OPC_TEQI: /* r0 == 0 */
2414 case OPC_TGE: /* rs >= rs */
2415 case OPC_TGEI: /* r0 >= 0 */
2416 case OPC_TGEU: /* rs >= rs unsigned */
2417 case OPC_TGEIU: /* r0 >= 0 unsigned */
2419 tcg_gen_movi_tl(t0, 1);
2421 case OPC_TLT: /* rs < rs */
2422 case OPC_TLTI: /* r0 < 0 */
2423 case OPC_TLTU: /* rs < rs unsigned */
2424 case OPC_TLTIU: /* r0 < 0 unsigned */
2425 case OPC_TNE: /* rs != rs */
2426 case OPC_TNEI: /* r0 != 0 */
2427 /* Never trap: treat as NOP. */
2431 generate_exception(ctx, EXCP_RI);
2462 generate_exception(ctx, EXCP_RI);
2466 save_cpu_state(ctx, 1);
2468 int l1 = gen_new_label();
2470 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2471 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2474 ctx->bstate = BS_STOP;
2480 static always_inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2482 TranslationBlock *tb;
2484 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2487 tcg_gen_exit_tb((long)tb + n);
2494 /* Branches (before delay slot) */
2495 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2496 int rs, int rt, int32_t offset)
2498 target_ulong btarget = -1;
2501 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2502 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2504 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2505 #ifdef MIPS_DEBUG_DISAS
2506 if (loglevel & CPU_LOG_TB_IN_ASM) {
2508 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2512 generate_exception(ctx, EXCP_RI);
2516 /* Load needed operands */
2522 /* Compare two registers */
2524 gen_load_gpr(t0, rs);
2525 gen_load_gpr(t1, rt);
2528 btarget = ctx->pc + 4 + offset;
2542 /* Compare to zero */
2544 gen_load_gpr(t0, rs);
2547 btarget = ctx->pc + 4 + offset;
2551 /* Jump to immediate */
2552 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2556 /* Jump to register */
2557 if (offset != 0 && offset != 16) {
2558 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2559 others are reserved. */
2560 MIPS_INVAL("jump hint");
2561 generate_exception(ctx, EXCP_RI);
2564 gen_save_breg_target(rs);
2567 MIPS_INVAL("branch/jump");
2568 generate_exception(ctx, EXCP_RI);
2572 /* No condition to be computed */
2574 case OPC_BEQ: /* rx == rx */
2575 case OPC_BEQL: /* rx == rx likely */
2576 case OPC_BGEZ: /* 0 >= 0 */
2577 case OPC_BGEZL: /* 0 >= 0 likely */
2578 case OPC_BLEZ: /* 0 <= 0 */
2579 case OPC_BLEZL: /* 0 <= 0 likely */
2581 ctx->hflags |= MIPS_HFLAG_B;
2582 MIPS_DEBUG("balways");
2584 case OPC_BGEZAL: /* 0 >= 0 */
2585 case OPC_BGEZALL: /* 0 >= 0 likely */
2586 /* Always take and link */
2588 ctx->hflags |= MIPS_HFLAG_B;
2589 MIPS_DEBUG("balways and link");
2591 case OPC_BNE: /* rx != rx */
2592 case OPC_BGTZ: /* 0 > 0 */
2593 case OPC_BLTZ: /* 0 < 0 */
2595 MIPS_DEBUG("bnever (NOP)");
2597 case OPC_BLTZAL: /* 0 < 0 */
2598 tcg_gen_movi_tl(t0, ctx->pc + 8);
2599 gen_store_gpr(t0, 31);
2600 MIPS_DEBUG("bnever and link");
2602 case OPC_BLTZALL: /* 0 < 0 likely */
2603 tcg_gen_movi_tl(t0, ctx->pc + 8);
2604 gen_store_gpr(t0, 31);
2605 /* Skip the instruction in the delay slot */
2606 MIPS_DEBUG("bnever, link and skip");
2609 case OPC_BNEL: /* rx != rx likely */
2610 case OPC_BGTZL: /* 0 > 0 likely */
2611 case OPC_BLTZL: /* 0 < 0 likely */
2612 /* Skip the instruction in the delay slot */
2613 MIPS_DEBUG("bnever and skip");
2617 ctx->hflags |= MIPS_HFLAG_B;
2618 MIPS_DEBUG("j " TARGET_FMT_lx, btarget);
2622 ctx->hflags |= MIPS_HFLAG_B;
2623 MIPS_DEBUG("jal " TARGET_FMT_lx, btarget);
2626 ctx->hflags |= MIPS_HFLAG_BR;
2627 MIPS_DEBUG("jr %s", regnames[rs]);
2631 ctx->hflags |= MIPS_HFLAG_BR;
2632 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2635 MIPS_INVAL("branch/jump");
2636 generate_exception(ctx, EXCP_RI);
2643 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2644 regnames[rs], regnames[rt], btarget);
2648 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2649 regnames[rs], regnames[rt], btarget);
2653 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2654 regnames[rs], regnames[rt], btarget);
2658 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2659 regnames[rs], regnames[rt], btarget);
2663 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2667 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2671 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2677 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2681 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2685 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2689 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2693 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2697 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2701 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2706 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2708 ctx->hflags |= MIPS_HFLAG_BC;
2709 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
2714 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2716 ctx->hflags |= MIPS_HFLAG_BL;
2717 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
2720 MIPS_INVAL("conditional branch/jump");
2721 generate_exception(ctx, EXCP_RI);
2725 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2726 blink, ctx->hflags, btarget);
2728 ctx->btarget = btarget;
2730 tcg_gen_movi_tl(t0, ctx->pc + 8);
2731 gen_store_gpr(t0, blink);
2739 /* special3 bitfield operations */
2740 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2741 int rs, int lsb, int msb)
2743 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2744 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2746 gen_load_gpr(t1, rs);
2751 tcg_gen_helper_1_2ii(do_ext, t0, t0, t1, lsb, msb + 1);
2753 #if defined(TARGET_MIPS64)
2757 tcg_gen_helper_1_2ii(do_dext, t0, t0, t1, lsb, msb + 1 + 32);
2762 tcg_gen_helper_1_2ii(do_dext, t0, t0, t1, lsb + 32, msb + 1);
2767 tcg_gen_helper_1_2ii(do_dext, t0, t0, t1, lsb, msb + 1);
2773 gen_load_gpr(t0, rt);
2774 tcg_gen_helper_1_2ii(do_ins, t0, t0, t1, lsb, msb - lsb + 1);
2776 #if defined(TARGET_MIPS64)
2780 gen_load_gpr(t0, rt);
2781 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1 + 32);
2786 gen_load_gpr(t0, rt);
2787 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb + 32, msb - lsb + 1);
2792 gen_load_gpr(t0, rt);
2793 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1);
2798 MIPS_INVAL("bitops");
2799 generate_exception(ctx, EXCP_RI);
2804 gen_store_gpr(t0, rt);
2809 /* CP0 (MMU and control) */
2810 #ifndef CONFIG_USER_ONLY
2811 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2813 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2815 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2816 tcg_gen_ext_i32_tl(t, r_tmp);
2817 tcg_temp_free(r_tmp);
2820 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2822 tcg_gen_ld_tl(t, cpu_env, off);
2823 tcg_gen_ext32s_tl(t, t);
2826 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2828 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2830 tcg_gen_trunc_tl_i32(r_tmp, t);
2831 tcg_gen_st_i32(r_tmp, cpu_env, off);
2832 tcg_temp_free(r_tmp);
2835 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2837 tcg_gen_ext32s_tl(t, t);
2838 tcg_gen_st_tl(t, cpu_env, off);
2841 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2843 const char *rn = "invalid";
2846 check_insn(env, ctx, ISA_MIPS32);
2852 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2856 check_insn(env, ctx, ASE_MT);
2857 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2861 check_insn(env, ctx, ASE_MT);
2862 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2866 check_insn(env, ctx, ASE_MT);
2867 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2877 tcg_gen_helper_1_0(do_mfc0_random, t0);
2881 check_insn(env, ctx, ASE_MT);
2882 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2886 check_insn(env, ctx, ASE_MT);
2887 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2891 check_insn(env, ctx, ASE_MT);
2892 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2896 check_insn(env, ctx, ASE_MT);
2897 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2901 check_insn(env, ctx, ASE_MT);
2902 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2906 check_insn(env, ctx, ASE_MT);
2907 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2908 rn = "VPEScheFBack";
2911 check_insn(env, ctx, ASE_MT);
2912 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2922 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2923 tcg_gen_ext32s_tl(t0, t0);
2927 check_insn(env, ctx, ASE_MT);
2928 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2932 check_insn(env, ctx, ASE_MT);
2933 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2937 check_insn(env, ctx, ASE_MT);
2938 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2942 check_insn(env, ctx, ASE_MT);
2943 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2947 check_insn(env, ctx, ASE_MT);
2948 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2952 check_insn(env, ctx, ASE_MT);
2953 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2957 check_insn(env, ctx, ASE_MT);
2958 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2968 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2969 tcg_gen_ext32s_tl(t0, t0);
2979 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2980 tcg_gen_ext32s_tl(t0, t0);
2984 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2985 rn = "ContextConfig";
2994 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2998 check_insn(env, ctx, ISA_MIPS32R2);
2999 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
3009 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
3013 check_insn(env, ctx, ISA_MIPS32R2);
3014 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
3018 check_insn(env, ctx, ISA_MIPS32R2);
3019 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
3023 check_insn(env, ctx, ISA_MIPS32R2);
3024 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
3028 check_insn(env, ctx, ISA_MIPS32R2);
3029 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
3033 check_insn(env, ctx, ISA_MIPS32R2);
3034 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
3044 check_insn(env, ctx, ISA_MIPS32R2);
3045 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
3055 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
3056 tcg_gen_ext32s_tl(t0, t0);
3066 /* Mark as an IO operation because we read the time. */
3069 tcg_gen_helper_1_0(do_mfc0_count, t0);
3072 ctx->bstate = BS_STOP;
3076 /* 6,7 are implementation dependent */
3084 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3085 tcg_gen_ext32s_tl(t0, t0);
3095 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3098 /* 6,7 are implementation dependent */
3106 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3110 check_insn(env, ctx, ISA_MIPS32R2);
3111 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3115 check_insn(env, ctx, ISA_MIPS32R2);
3116 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3120 check_insn(env, ctx, ISA_MIPS32R2);
3121 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3131 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3141 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3142 tcg_gen_ext32s_tl(t0, t0);
3152 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3156 check_insn(env, ctx, ISA_MIPS32R2);
3157 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3167 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3171 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3175 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3179 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3182 /* 4,5 are reserved */
3183 /* 6,7 are implementation dependent */
3185 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3189 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3199 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3209 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3219 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3229 #if defined(TARGET_MIPS64)
3230 check_insn(env, ctx, ISA_MIPS3);
3231 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3232 tcg_gen_ext32s_tl(t0, t0);
3241 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3244 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3253 rn = "'Diagnostic"; /* implementation dependent */
3258 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3262 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3263 rn = "TraceControl";
3266 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3267 rn = "TraceControl2";
3270 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3271 rn = "UserTraceData";
3274 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3285 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3286 tcg_gen_ext32s_tl(t0, t0);
3296 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3297 rn = "Performance0";
3300 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3301 rn = "Performance1";
3304 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3305 rn = "Performance2";
3308 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3309 rn = "Performance3";
3312 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3313 rn = "Performance4";
3316 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3317 rn = "Performance5";
3320 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3321 rn = "Performance6";
3324 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3325 rn = "Performance7";
3350 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3357 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3370 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3377 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3387 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3388 tcg_gen_ext32s_tl(t0, t0);
3399 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3409 #if defined MIPS_DEBUG_DISAS
3410 if (loglevel & CPU_LOG_TB_IN_ASM) {
3411 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3418 #if defined MIPS_DEBUG_DISAS
3419 if (loglevel & CPU_LOG_TB_IN_ASM) {
3420 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3424 generate_exception(ctx, EXCP_RI);
3427 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3429 const char *rn = "invalid";
3432 check_insn(env, ctx, ISA_MIPS32);
3441 tcg_gen_helper_0_1(do_mtc0_index, t0);
3445 check_insn(env, ctx, ASE_MT);
3446 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3450 check_insn(env, ctx, ASE_MT);
3455 check_insn(env, ctx, ASE_MT);
3470 check_insn(env, ctx, ASE_MT);
3471 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3475 check_insn(env, ctx, ASE_MT);
3476 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3480 check_insn(env, ctx, ASE_MT);
3481 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3485 check_insn(env, ctx, ASE_MT);
3486 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3490 check_insn(env, ctx, ASE_MT);
3491 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3495 check_insn(env, ctx, ASE_MT);
3496 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3497 rn = "VPEScheFBack";
3500 check_insn(env, ctx, ASE_MT);
3501 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3511 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3515 check_insn(env, ctx, ASE_MT);
3516 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3520 check_insn(env, ctx, ASE_MT);
3521 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3525 check_insn(env, ctx, ASE_MT);
3526 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3530 check_insn(env, ctx, ASE_MT);
3531 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3535 check_insn(env, ctx, ASE_MT);
3536 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3540 check_insn(env, ctx, ASE_MT);
3541 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3545 check_insn(env, ctx, ASE_MT);
3546 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3556 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3566 tcg_gen_helper_0_1(do_mtc0_context, t0);
3570 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3571 rn = "ContextConfig";
3580 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3584 check_insn(env, ctx, ISA_MIPS32R2);
3585 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3595 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3599 check_insn(env, ctx, ISA_MIPS32R2);
3600 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3604 check_insn(env, ctx, ISA_MIPS32R2);
3605 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3609 check_insn(env, ctx, ISA_MIPS32R2);
3610 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3614 check_insn(env, ctx, ISA_MIPS32R2);
3615 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3619 check_insn(env, ctx, ISA_MIPS32R2);
3620 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3630 check_insn(env, ctx, ISA_MIPS32R2);
3631 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3645 tcg_gen_helper_0_1(do_mtc0_count, t0);
3648 /* 6,7 are implementation dependent */
3652 /* Stop translation as we may have switched the execution mode */
3653 ctx->bstate = BS_STOP;
3658 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3668 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3671 /* 6,7 are implementation dependent */
3675 /* Stop translation as we may have switched the execution mode */
3676 ctx->bstate = BS_STOP;
3681 tcg_gen_helper_0_1(do_mtc0_status, t0);
3682 /* BS_STOP isn't good enough here, hflags may have changed. */
3683 gen_save_pc(ctx->pc + 4);
3684 ctx->bstate = BS_EXCP;
3688 check_insn(env, ctx, ISA_MIPS32R2);
3689 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3690 /* Stop translation as we may have switched the execution mode */
3691 ctx->bstate = BS_STOP;
3695 check_insn(env, ctx, ISA_MIPS32R2);
3696 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3697 /* Stop translation as we may have switched the execution mode */
3698 ctx->bstate = BS_STOP;
3702 check_insn(env, ctx, ISA_MIPS32R2);
3703 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3704 /* Stop translation as we may have switched the execution mode */
3705 ctx->bstate = BS_STOP;
3715 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3721 /* Stop translation as we may have switched the execution mode */
3722 ctx->bstate = BS_STOP;
3727 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3741 check_insn(env, ctx, ISA_MIPS32R2);
3742 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3752 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3754 /* Stop translation as we may have switched the execution mode */
3755 ctx->bstate = BS_STOP;
3758 /* ignored, read only */
3762 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3764 /* Stop translation as we may have switched the execution mode */
3765 ctx->bstate = BS_STOP;
3768 /* ignored, read only */
3771 /* 4,5 are reserved */
3772 /* 6,7 are implementation dependent */
3782 rn = "Invalid config selector";
3799 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3809 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3819 #if defined(TARGET_MIPS64)
3820 check_insn(env, ctx, ISA_MIPS3);
3821 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3830 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3833 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3842 rn = "Diagnostic"; /* implementation dependent */
3847 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3848 /* BS_STOP isn't good enough here, hflags may have changed. */
3849 gen_save_pc(ctx->pc + 4);
3850 ctx->bstate = BS_EXCP;
3854 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3855 rn = "TraceControl";
3856 /* Stop translation as we may have switched the execution mode */
3857 ctx->bstate = BS_STOP;
3860 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3861 rn = "TraceControl2";
3862 /* Stop translation as we may have switched the execution mode */
3863 ctx->bstate = BS_STOP;
3866 /* Stop translation as we may have switched the execution mode */
3867 ctx->bstate = BS_STOP;
3868 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3869 rn = "UserTraceData";
3870 /* Stop translation as we may have switched the execution mode */
3871 ctx->bstate = BS_STOP;
3874 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3875 /* Stop translation as we may have switched the execution mode */
3876 ctx->bstate = BS_STOP;
3887 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3897 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3898 rn = "Performance0";
3901 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3902 rn = "Performance1";
3905 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3906 rn = "Performance2";
3909 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3910 rn = "Performance3";
3913 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3914 rn = "Performance4";
3917 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3918 rn = "Performance5";
3921 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3922 rn = "Performance6";
3925 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3926 rn = "Performance7";
3952 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3959 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3972 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3979 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
3990 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
4001 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
4007 /* Stop translation as we may have switched the execution mode */
4008 ctx->bstate = BS_STOP;
4013 #if defined MIPS_DEBUG_DISAS
4014 if (loglevel & CPU_LOG_TB_IN_ASM) {
4015 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4019 /* For simplicitly assume that all writes can cause interrupts. */
4022 ctx->bstate = BS_STOP;
4027 #if defined MIPS_DEBUG_DISAS
4028 if (loglevel & CPU_LOG_TB_IN_ASM) {
4029 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4033 generate_exception(ctx, EXCP_RI);
4036 #if defined(TARGET_MIPS64)
4037 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4039 const char *rn = "invalid";
4042 check_insn(env, ctx, ISA_MIPS64);
4048 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
4052 check_insn(env, ctx, ASE_MT);
4053 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
4057 check_insn(env, ctx, ASE_MT);
4058 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4062 check_insn(env, ctx, ASE_MT);
4063 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4073 tcg_gen_helper_1_0(do_mfc0_random, t0);
4077 check_insn(env, ctx, ASE_MT);
4078 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4082 check_insn(env, ctx, ASE_MT);
4083 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4087 check_insn(env, ctx, ASE_MT);
4088 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4092 check_insn(env, ctx, ASE_MT);
4093 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4097 check_insn(env, ctx, ASE_MT);
4098 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4102 check_insn(env, ctx, ASE_MT);
4103 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4104 rn = "VPEScheFBack";
4107 check_insn(env, ctx, ASE_MT);
4108 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4118 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4122 check_insn(env, ctx, ASE_MT);
4123 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4127 check_insn(env, ctx, ASE_MT);
4128 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4132 check_insn(env, ctx, ASE_MT);
4133 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4137 check_insn(env, ctx, ASE_MT);
4138 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4142 check_insn(env, ctx, ASE_MT);
4143 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4147 check_insn(env, ctx, ASE_MT);
4148 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4152 check_insn(env, ctx, ASE_MT);
4153 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4163 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4173 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4177 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4178 rn = "ContextConfig";
4187 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4191 check_insn(env, ctx, ISA_MIPS32R2);
4192 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4202 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4206 check_insn(env, ctx, ISA_MIPS32R2);
4207 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4211 check_insn(env, ctx, ISA_MIPS32R2);
4212 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4216 check_insn(env, ctx, ISA_MIPS32R2);
4217 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4221 check_insn(env, ctx, ISA_MIPS32R2);
4222 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4226 check_insn(env, ctx, ISA_MIPS32R2);
4227 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4237 check_insn(env, ctx, ISA_MIPS32R2);
4238 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4248 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4258 /* Mark as an IO operation because we read the time. */
4261 tcg_gen_helper_1_0(do_mfc0_count, t0);
4264 ctx->bstate = BS_STOP;
4268 /* 6,7 are implementation dependent */
4276 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4286 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4289 /* 6,7 are implementation dependent */
4297 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4301 check_insn(env, ctx, ISA_MIPS32R2);
4302 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4306 check_insn(env, ctx, ISA_MIPS32R2);
4307 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4311 check_insn(env, ctx, ISA_MIPS32R2);
4312 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4322 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4332 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4342 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4346 check_insn(env, ctx, ISA_MIPS32R2);
4347 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4357 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4361 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4365 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4369 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4372 /* 6,7 are implementation dependent */
4374 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4378 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4388 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4398 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4408 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4418 check_insn(env, ctx, ISA_MIPS3);
4419 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4427 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4430 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4439 rn = "'Diagnostic"; /* implementation dependent */
4444 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4448 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4449 rn = "TraceControl";
4452 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4453 rn = "TraceControl2";
4456 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4457 rn = "UserTraceData";
4460 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4471 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4481 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4482 rn = "Performance0";
4485 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4486 rn = "Performance1";
4489 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4490 rn = "Performance2";
4493 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4494 rn = "Performance3";
4497 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4498 rn = "Performance4";
4501 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4502 rn = "Performance5";
4505 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4506 rn = "Performance6";
4509 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4510 rn = "Performance7";
4535 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4542 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4555 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4562 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4572 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4583 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4593 #if defined MIPS_DEBUG_DISAS
4594 if (loglevel & CPU_LOG_TB_IN_ASM) {
4595 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4602 #if defined MIPS_DEBUG_DISAS
4603 if (loglevel & CPU_LOG_TB_IN_ASM) {
4604 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4608 generate_exception(ctx, EXCP_RI);
4611 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4613 const char *rn = "invalid";
4616 check_insn(env, ctx, ISA_MIPS64);
4625 tcg_gen_helper_0_1(do_mtc0_index, t0);
4629 check_insn(env, ctx, ASE_MT);
4630 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4634 check_insn(env, ctx, ASE_MT);
4639 check_insn(env, ctx, ASE_MT);
4654 check_insn(env, ctx, ASE_MT);
4655 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4659 check_insn(env, ctx, ASE_MT);
4660 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4664 check_insn(env, ctx, ASE_MT);
4665 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4669 check_insn(env, ctx, ASE_MT);
4670 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4674 check_insn(env, ctx, ASE_MT);
4675 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4679 check_insn(env, ctx, ASE_MT);
4680 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4681 rn = "VPEScheFBack";
4684 check_insn(env, ctx, ASE_MT);
4685 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4695 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4699 check_insn(env, ctx, ASE_MT);
4700 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4704 check_insn(env, ctx, ASE_MT);
4705 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4709 check_insn(env, ctx, ASE_MT);
4710 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4714 check_insn(env, ctx, ASE_MT);
4715 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4719 check_insn(env, ctx, ASE_MT);
4720 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4724 check_insn(env, ctx, ASE_MT);
4725 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4729 check_insn(env, ctx, ASE_MT);
4730 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4740 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4750 tcg_gen_helper_0_1(do_mtc0_context, t0);
4754 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4755 rn = "ContextConfig";
4764 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4768 check_insn(env, ctx, ISA_MIPS32R2);
4769 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4779 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4783 check_insn(env, ctx, ISA_MIPS32R2);
4784 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4788 check_insn(env, ctx, ISA_MIPS32R2);
4789 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4793 check_insn(env, ctx, ISA_MIPS32R2);
4794 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4798 check_insn(env, ctx, ISA_MIPS32R2);
4799 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4803 check_insn(env, ctx, ISA_MIPS32R2);
4804 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4814 check_insn(env, ctx, ISA_MIPS32R2);
4815 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4829 tcg_gen_helper_0_1(do_mtc0_count, t0);
4832 /* 6,7 are implementation dependent */
4836 /* Stop translation as we may have switched the execution mode */
4837 ctx->bstate = BS_STOP;
4842 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4852 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4855 /* 6,7 are implementation dependent */
4859 /* Stop translation as we may have switched the execution mode */
4860 ctx->bstate = BS_STOP;
4865 tcg_gen_helper_0_1(do_mtc0_status, t0);
4866 /* BS_STOP isn't good enough here, hflags may have changed. */
4867 gen_save_pc(ctx->pc + 4);
4868 ctx->bstate = BS_EXCP;
4872 check_insn(env, ctx, ISA_MIPS32R2);
4873 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4874 /* Stop translation as we may have switched the execution mode */
4875 ctx->bstate = BS_STOP;
4879 check_insn(env, ctx, ISA_MIPS32R2);
4880 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4881 /* Stop translation as we may have switched the execution mode */
4882 ctx->bstate = BS_STOP;
4886 check_insn(env, ctx, ISA_MIPS32R2);
4887 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4888 /* Stop translation as we may have switched the execution mode */
4889 ctx->bstate = BS_STOP;
4899 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4905 /* Stop translation as we may have switched the execution mode */
4906 ctx->bstate = BS_STOP;
4911 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4925 check_insn(env, ctx, ISA_MIPS32R2);
4926 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4936 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4938 /* Stop translation as we may have switched the execution mode */
4939 ctx->bstate = BS_STOP;
4946 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4948 /* Stop translation as we may have switched the execution mode */
4949 ctx->bstate = BS_STOP;
4955 /* 6,7 are implementation dependent */
4957 rn = "Invalid config selector";
4974 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4984 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
4994 check_insn(env, ctx, ISA_MIPS3);
4995 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
5003 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5006 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
5015 rn = "Diagnostic"; /* implementation dependent */
5020 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
5021 /* BS_STOP isn't good enough here, hflags may have changed. */
5022 gen_save_pc(ctx->pc + 4);
5023 ctx->bstate = BS_EXCP;
5027 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
5028 /* Stop translation as we may have switched the execution mode */
5029 ctx->bstate = BS_STOP;
5030 rn = "TraceControl";
5033 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
5034 /* Stop translation as we may have switched the execution mode */
5035 ctx->bstate = BS_STOP;
5036 rn = "TraceControl2";
5039 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5040 /* Stop translation as we may have switched the execution mode */
5041 ctx->bstate = BS_STOP;
5042 rn = "UserTraceData";
5045 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5046 /* Stop translation as we may have switched the execution mode */
5047 ctx->bstate = BS_STOP;
5058 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5068 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5069 rn = "Performance0";
5072 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5073 rn = "Performance1";
5076 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5077 rn = "Performance2";
5080 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5081 rn = "Performance3";
5084 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5085 rn = "Performance4";
5088 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5089 rn = "Performance5";
5092 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5093 rn = "Performance6";
5096 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5097 rn = "Performance7";
5123 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5130 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5143 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5150 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5161 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5172 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5178 /* Stop translation as we may have switched the execution mode */
5179 ctx->bstate = BS_STOP;
5184 #if defined MIPS_DEBUG_DISAS
5185 if (loglevel & CPU_LOG_TB_IN_ASM) {
5186 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5191 /* For simplicitly assume that all writes can cause interrupts. */
5194 ctx->bstate = BS_STOP;
5200 #if defined MIPS_DEBUG_DISAS
5201 if (loglevel & CPU_LOG_TB_IN_ASM) {
5202 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5206 generate_exception(ctx, EXCP_RI);
5208 #endif /* TARGET_MIPS64 */
5210 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5211 int u, int sel, int h)
5213 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5214 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5216 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5217 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5218 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5219 tcg_gen_movi_tl(t0, -1);
5220 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5221 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5222 tcg_gen_movi_tl(t0, -1);
5228 tcg_gen_helper_1_1(do_mftc0_tcstatus, t0, t0);
5231 tcg_gen_helper_1_1(do_mftc0_tcbind, t0, t0);
5234 tcg_gen_helper_1_1(do_mftc0_tcrestart, t0, t0);
5237 tcg_gen_helper_1_1(do_mftc0_tchalt, t0, t0);
5240 tcg_gen_helper_1_1(do_mftc0_tccontext, t0, t0);
5243 tcg_gen_helper_1_1(do_mftc0_tcschedule, t0, t0);
5246 tcg_gen_helper_1_1(do_mftc0_tcschefback, t0, t0);
5249 gen_mfc0(env, ctx, t0, rt, sel);
5256 tcg_gen_helper_1_1(do_mftc0_entryhi, t0, t0);
5259 gen_mfc0(env, ctx, t0, rt, sel);
5265 tcg_gen_helper_1_1(do_mftc0_status, t0, t0);
5268 gen_mfc0(env, ctx, t0, rt, sel);
5274 tcg_gen_helper_1_1(do_mftc0_debug, t0, t0);
5277 gen_mfc0(env, ctx, t0, rt, sel);
5282 gen_mfc0(env, ctx, t0, rt, sel);
5284 } else switch (sel) {
5285 /* GPR registers. */
5287 tcg_gen_helper_1_1i(do_mftgpr, t0, t0, rt);
5289 /* Auxiliary CPU registers */
5293 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 0);
5296 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 0);
5299 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 0);
5302 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 1);
5305 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 1);
5308 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 1);
5311 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 2);
5314 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 2);
5317 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 2);
5320 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 3);
5323 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 3);
5326 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 3);
5329 tcg_gen_helper_1_1(do_mftdsp, t0, t0);
5335 /* Floating point (COP1). */
5337 /* XXX: For now we support only a single FPU context. */
5339 gen_load_fpr32(fpu32_T[0], rt);
5340 tcg_gen_ext_i32_tl(t0, fpu32_T[0]);
5342 gen_load_fpr32h(fpu32h_T[0], rt);
5343 tcg_gen_ext_i32_tl(t0, fpu32h_T[0]);
5347 /* XXX: For now we support only a single FPU context. */
5348 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5350 /* COP2: Not implemented. */
5357 #if defined MIPS_DEBUG_DISAS
5358 if (loglevel & CPU_LOG_TB_IN_ASM) {
5359 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5363 gen_store_gpr(t0, rd);
5369 #if defined MIPS_DEBUG_DISAS
5370 if (loglevel & CPU_LOG_TB_IN_ASM) {
5371 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5375 generate_exception(ctx, EXCP_RI);
5378 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5379 int u, int sel, int h)
5381 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5382 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5384 gen_load_gpr(t0, rt);
5385 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5386 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5387 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5389 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5390 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5397 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5400 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5403 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5406 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5409 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5412 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5415 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5418 gen_mtc0(env, ctx, t0, rd, sel);
5425 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5428 gen_mtc0(env, ctx, t0, rd, sel);
5434 tcg_gen_helper_0_1(do_mttc0_status, t0);
5437 gen_mtc0(env, ctx, t0, rd, sel);
5443 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5446 gen_mtc0(env, ctx, t0, rd, sel);
5451 gen_mtc0(env, ctx, t0, rd, sel);
5453 } else switch (sel) {
5454 /* GPR registers. */
5456 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5458 /* Auxiliary CPU registers */
5462 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5465 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5468 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5471 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5474 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5477 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5480 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5483 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5486 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5489 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5492 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5495 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5498 tcg_gen_helper_0_1(do_mttdsp, t0);
5504 /* Floating point (COP1). */
5506 /* XXX: For now we support only a single FPU context. */
5508 tcg_gen_trunc_tl_i32(fpu32_T[0], t0);
5509 gen_store_fpr32(fpu32_T[0], rd);
5511 tcg_gen_trunc_tl_i32(fpu32h_T[0], t0);
5512 gen_store_fpr32h(fpu32h_T[0], rd);
5516 /* XXX: For now we support only a single FPU context. */
5517 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5519 /* COP2: Not implemented. */
5526 #if defined MIPS_DEBUG_DISAS
5527 if (loglevel & CPU_LOG_TB_IN_ASM) {
5528 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5537 #if defined MIPS_DEBUG_DISAS
5538 if (loglevel & CPU_LOG_TB_IN_ASM) {
5539 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5543 generate_exception(ctx, EXCP_RI);
5546 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5548 const char *opn = "ldst";
5557 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5559 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5560 gen_store_gpr(t0, rt);
5567 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5569 gen_load_gpr(t0, rt);
5570 save_cpu_state(ctx, 1);
5571 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5576 #if defined(TARGET_MIPS64)
5578 check_insn(env, ctx, ISA_MIPS3);
5584 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5586 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5587 gen_store_gpr(t0, rt);
5593 check_insn(env, ctx, ISA_MIPS3);
5595 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5597 gen_load_gpr(t0, rt);
5598 save_cpu_state(ctx, 1);
5599 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5606 check_insn(env, ctx, ASE_MT);
5611 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5612 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5616 check_insn(env, ctx, ASE_MT);
5617 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5618 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5623 if (!env->tlb->do_tlbwi)
5625 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5629 if (!env->tlb->do_tlbwr)
5631 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5635 if (!env->tlb->do_tlbp)
5637 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5641 if (!env->tlb->do_tlbr)
5643 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5647 check_insn(env, ctx, ISA_MIPS2);
5648 save_cpu_state(ctx, 1);
5649 tcg_gen_helper_0_0(do_eret);
5650 ctx->bstate = BS_EXCP;
5654 check_insn(env, ctx, ISA_MIPS32);
5655 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5657 generate_exception(ctx, EXCP_RI);
5659 save_cpu_state(ctx, 1);
5660 tcg_gen_helper_0_0(do_deret);
5661 ctx->bstate = BS_EXCP;
5666 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5667 /* If we get an exception, we want to restart at next instruction */
5669 save_cpu_state(ctx, 1);
5671 tcg_gen_helper_0_0(do_wait);
5672 ctx->bstate = BS_EXCP;
5677 generate_exception(ctx, EXCP_RI);
5680 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5682 #endif /* !CONFIG_USER_ONLY */
5684 /* CP1 Branches (before delay slot) */
5685 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5686 int32_t cc, int32_t offset)
5688 target_ulong btarget;
5689 const char *opn = "cp1 cond branch";
5690 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5691 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5694 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5696 btarget = ctx->pc + 4 + offset;
5701 int l1 = gen_new_label();
5702 int l2 = gen_new_label();
5703 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5705 get_fp_cond(r_tmp1);
5706 tcg_gen_ext_i32_tl(t0, r_tmp1);
5707 tcg_temp_free(r_tmp1);
5708 tcg_gen_not_tl(t0, t0);
5709 tcg_gen_movi_tl(t1, 0x1 << cc);
5710 tcg_gen_and_tl(t0, t0, t1);
5711 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5712 tcg_gen_movi_tl(t0, 0);
5715 tcg_gen_movi_tl(t0, 1);
5722 int l1 = gen_new_label();
5723 int l2 = gen_new_label();
5724 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5726 get_fp_cond(r_tmp1);
5727 tcg_gen_ext_i32_tl(t0, r_tmp1);
5728 tcg_temp_free(r_tmp1);
5729 tcg_gen_not_tl(t0, t0);
5730 tcg_gen_movi_tl(t1, 0x1 << cc);
5731 tcg_gen_and_tl(t0, t0, t1);
5732 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5733 tcg_gen_movi_tl(t0, 0);
5736 tcg_gen_movi_tl(t0, 1);
5743 int l1 = gen_new_label();
5744 int l2 = gen_new_label();
5745 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5747 get_fp_cond(r_tmp1);
5748 tcg_gen_ext_i32_tl(t0, r_tmp1);
5749 tcg_temp_free(r_tmp1);
5750 tcg_gen_movi_tl(t1, 0x1 << cc);
5751 tcg_gen_and_tl(t0, t0, t1);
5752 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5753 tcg_gen_movi_tl(t0, 0);
5756 tcg_gen_movi_tl(t0, 1);
5763 int l1 = gen_new_label();
5764 int l2 = gen_new_label();
5765 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5767 get_fp_cond(r_tmp1);
5768 tcg_gen_ext_i32_tl(t0, r_tmp1);
5769 tcg_temp_free(r_tmp1);
5770 tcg_gen_movi_tl(t1, 0x1 << cc);
5771 tcg_gen_and_tl(t0, t0, t1);
5772 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5773 tcg_gen_movi_tl(t0, 0);
5776 tcg_gen_movi_tl(t0, 1);
5781 ctx->hflags |= MIPS_HFLAG_BL;
5782 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
5786 int l1 = gen_new_label();
5787 int l2 = gen_new_label();
5788 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5790 get_fp_cond(r_tmp1);
5791 tcg_gen_ext_i32_tl(t0, r_tmp1);
5792 tcg_temp_free(r_tmp1);
5793 tcg_gen_not_tl(t0, t0);
5794 tcg_gen_movi_tl(t1, 0x3 << cc);
5795 tcg_gen_and_tl(t0, t0, t1);
5796 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5797 tcg_gen_movi_tl(t0, 0);
5800 tcg_gen_movi_tl(t0, 1);
5807 int l1 = gen_new_label();
5808 int l2 = gen_new_label();
5809 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5811 get_fp_cond(r_tmp1);
5812 tcg_gen_ext_i32_tl(t0, r_tmp1);
5813 tcg_temp_free(r_tmp1);
5814 tcg_gen_movi_tl(t1, 0x3 << cc);
5815 tcg_gen_and_tl(t0, t0, t1);
5816 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5817 tcg_gen_movi_tl(t0, 0);
5820 tcg_gen_movi_tl(t0, 1);
5827 int l1 = gen_new_label();
5828 int l2 = gen_new_label();
5829 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5831 get_fp_cond(r_tmp1);
5832 tcg_gen_ext_i32_tl(t0, r_tmp1);
5833 tcg_temp_free(r_tmp1);
5834 tcg_gen_not_tl(t0, t0);
5835 tcg_gen_movi_tl(t1, 0xf << cc);
5836 tcg_gen_and_tl(t0, t0, t1);
5837 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5838 tcg_gen_movi_tl(t0, 0);
5841 tcg_gen_movi_tl(t0, 1);
5848 int l1 = gen_new_label();
5849 int l2 = gen_new_label();
5850 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5852 get_fp_cond(r_tmp1);
5853 tcg_gen_ext_i32_tl(t0, r_tmp1);
5854 tcg_temp_free(r_tmp1);
5855 tcg_gen_movi_tl(t1, 0xf << cc);
5856 tcg_gen_and_tl(t0, t0, t1);
5857 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5858 tcg_gen_movi_tl(t0, 0);
5861 tcg_gen_movi_tl(t0, 1);
5866 ctx->hflags |= MIPS_HFLAG_BC;
5867 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
5871 generate_exception (ctx, EXCP_RI);
5874 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5875 ctx->hflags, btarget);
5876 ctx->btarget = btarget;
5883 /* Coprocessor 1 (FPU) */
5885 #define FOP(func, fmt) (((fmt) << 21) | (func))
5887 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5889 const char *opn = "cp1 move";
5890 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5894 gen_load_fpr32(fpu32_T[0], fs);
5895 tcg_gen_ext_i32_tl(t0, fpu32_T[0]);
5896 gen_store_gpr(t0, rt);
5900 gen_load_gpr(t0, rt);
5901 tcg_gen_trunc_tl_i32(fpu32_T[0], t0);
5902 gen_store_fpr32(fpu32_T[0], fs);
5906 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5907 gen_store_gpr(t0, rt);
5911 gen_load_gpr(t0, rt);
5912 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5916 gen_load_fpr64(ctx, fpu64_T[0], fs);
5917 tcg_gen_mov_tl(t0, fpu64_T[0]);
5918 gen_store_gpr(t0, rt);
5922 gen_load_gpr(t0, rt);
5923 tcg_gen_mov_tl(fpu64_T[0], t0);
5924 gen_store_fpr64(ctx, fpu64_T[0], fs);
5928 gen_load_fpr32h(fpu32h_T[0], fs);
5929 tcg_gen_ext_i32_tl(t0, fpu32h_T[0]);
5930 gen_store_gpr(t0, rt);
5934 gen_load_gpr(t0, rt);
5935 tcg_gen_trunc_tl_i32(fpu32h_T[0], t0);
5936 gen_store_fpr32h(fpu32h_T[0], fs);
5941 generate_exception (ctx, EXCP_RI);
5944 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5950 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5952 int l1 = gen_new_label();
5955 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5956 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5959 ccbit = 1 << (24 + cc);
5967 gen_load_gpr(t0, rd);
5968 gen_load_gpr(t1, rs);
5970 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
5971 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
5973 tcg_gen_ld_ptr(r_ptr, cpu_env, offsetof(CPUState, fpu));
5974 tcg_gen_ld_i32(r_tmp, r_ptr, offsetof(CPUMIPSFPUContext, fcr31));
5975 tcg_temp_free(r_ptr);
5976 tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
5977 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5978 tcg_temp_free(r_tmp);
5980 tcg_gen_mov_tl(t0, t1);
5984 gen_store_gpr(t0, rd);
5988 static inline void gen_movcf_s (int cc, int tf)
5992 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5993 int l1 = gen_new_label();
5996 ccbit = 1 << (24 + cc);
6005 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
6006 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
6007 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6008 tcg_gen_movi_i32(fpu32_T[2], fpu32_T[0]);
6010 tcg_temp_free(r_tmp1);
6013 static inline void gen_movcf_d (int cc, int tf)
6017 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
6018 int l1 = gen_new_label();
6021 ccbit = 1 << (24 + cc);
6030 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
6031 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
6032 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6033 tcg_gen_movi_i64(fpu64_T[2], fpu64_T[0]);
6035 tcg_temp_free(r_tmp1);
6038 static inline void gen_movcf_ps (int cc, int tf)
6041 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6042 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6043 int l1 = gen_new_label();
6044 int l2 = gen_new_label();
6051 get_fp_cond(r_tmp1);
6052 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6053 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6054 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6055 tcg_gen_movi_i32(fpu32_T[2], fpu32_T[0]);
6057 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6058 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6059 tcg_gen_movi_i32(fpu32h_T[2], fpu32h_T[0]);
6061 tcg_temp_free(r_tmp1);
6062 tcg_temp_free(r_tmp2);
6066 static void gen_farith (DisasContext *ctx, uint32_t op1,
6067 int ft, int fs, int fd, int cc)
6069 const char *opn = "farith";
6070 const char *condnames[] = {
6088 const char *condnames_abs[] = {
6106 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6107 uint32_t func = ctx->opcode & 0x3f;
6109 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6111 gen_load_fpr32(fpu32_T[0], fs);
6112 gen_load_fpr32(fpu32_T[1], ft);
6113 tcg_gen_helper_0_0(do_float_add_s);
6114 gen_store_fpr32(fpu32_T[2], fd);
6119 gen_load_fpr32(fpu32_T[0], fs);
6120 gen_load_fpr32(fpu32_T[1], ft);
6121 tcg_gen_helper_0_0(do_float_sub_s);
6122 gen_store_fpr32(fpu32_T[2], fd);
6127 gen_load_fpr32(fpu32_T[0], fs);
6128 gen_load_fpr32(fpu32_T[1], ft);
6129 tcg_gen_helper_0_0(do_float_mul_s);
6130 gen_store_fpr32(fpu32_T[2], fd);
6135 gen_load_fpr32(fpu32_T[0], fs);
6136 gen_load_fpr32(fpu32_T[1], ft);
6137 tcg_gen_helper_0_0(do_float_div_s);
6138 gen_store_fpr32(fpu32_T[2], fd);
6143 gen_load_fpr32(fpu32_T[0], fs);
6144 tcg_gen_helper_0_0(do_float_sqrt_s);
6145 gen_store_fpr32(fpu32_T[2], fd);
6149 gen_load_fpr32(fpu32_T[0], fs);
6150 tcg_gen_helper_0_0(do_float_abs_s);
6151 gen_store_fpr32(fpu32_T[2], fd);
6155 gen_load_fpr32(fpu32_T[0], fs);
6156 gen_store_fpr32(fpu32_T[0], fd);
6160 gen_load_fpr32(fpu32_T[0], fs);
6161 tcg_gen_helper_0_0(do_float_chs_s);
6162 gen_store_fpr32(fpu32_T[2], fd);
6166 check_cp1_64bitmode(ctx);
6167 gen_load_fpr32(fpu32_T[0], fs);
6168 tcg_gen_helper_0_0(do_float_roundl_s);
6169 gen_store_fpr64(ctx, fpu64_T[2], fd);
6173 check_cp1_64bitmode(ctx);
6174 gen_load_fpr32(fpu32_T[0], fs);
6175 tcg_gen_helper_0_0(do_float_truncl_s);
6176 gen_store_fpr64(ctx, fpu64_T[2], fd);
6180 check_cp1_64bitmode(ctx);
6181 gen_load_fpr32(fpu32_T[0], fs);
6182 tcg_gen_helper_0_0(do_float_ceill_s);
6183 gen_store_fpr64(ctx, fpu64_T[2], fd);
6187 check_cp1_64bitmode(ctx);
6188 gen_load_fpr32(fpu32_T[0], fs);
6189 tcg_gen_helper_0_0(do_float_floorl_s);
6190 gen_store_fpr64(ctx, fpu64_T[2], fd);
6194 gen_load_fpr32(fpu32_T[0], fs);
6195 tcg_gen_helper_0_0(do_float_roundw_s);
6196 gen_store_fpr32(fpu32_T[2], fd);
6200 gen_load_fpr32(fpu32_T[0], fs);
6201 tcg_gen_helper_0_0(do_float_truncw_s);
6202 gen_store_fpr32(fpu32_T[2], fd);
6206 gen_load_fpr32(fpu32_T[0], fs);
6207 tcg_gen_helper_0_0(do_float_ceilw_s);
6208 gen_store_fpr32(fpu32_T[2], fd);
6212 gen_load_fpr32(fpu32_T[0], fs);
6213 tcg_gen_helper_0_0(do_float_floorw_s);
6214 gen_store_fpr32(fpu32_T[2], fd);
6218 gen_load_fpr32(fpu32_T[0], fs);
6219 gen_load_fpr32(fpu32_T[2], fd);
6220 gen_movcf_s((ft >> 2) & 0x7, ft & 0x1);
6221 gen_store_fpr32(fpu32_T[2], fd);
6225 gen_load_fpr32(fpu32_T[0], fs);
6226 gen_load_fpr32(fpu32_T[2], fd);
6228 int l1 = gen_new_label();
6229 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6231 gen_load_gpr(t0, ft);
6232 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6234 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6237 gen_store_fpr32(fpu32_T[2], fd);
6241 gen_load_fpr32(fpu32_T[0], fs);
6242 gen_load_fpr32(fpu32_T[2], fd);
6244 int l1 = gen_new_label();
6245 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6247 gen_load_gpr(t0, ft);
6248 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6250 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6253 gen_store_fpr32(fpu32_T[2], fd);
6258 gen_load_fpr32(fpu32_T[0], fs);
6259 tcg_gen_helper_0_0(do_float_recip_s);
6260 gen_store_fpr32(fpu32_T[2], fd);
6265 gen_load_fpr32(fpu32_T[0], fs);
6266 tcg_gen_helper_0_0(do_float_rsqrt_s);
6267 gen_store_fpr32(fpu32_T[2], fd);
6271 check_cp1_64bitmode(ctx);
6272 gen_load_fpr32(fpu32_T[0], fs);
6273 gen_load_fpr32(fpu32_T[2], fd);
6274 tcg_gen_helper_0_0(do_float_recip2_s);
6275 gen_store_fpr32(fpu32_T[2], fd);
6279 check_cp1_64bitmode(ctx);
6280 gen_load_fpr32(fpu32_T[0], fs);
6281 tcg_gen_helper_0_0(do_float_recip1_s);
6282 gen_store_fpr32(fpu32_T[2], fd);
6286 check_cp1_64bitmode(ctx);
6287 gen_load_fpr32(fpu32_T[0], fs);
6288 tcg_gen_helper_0_0(do_float_rsqrt1_s);
6289 gen_store_fpr32(fpu32_T[2], fd);
6293 check_cp1_64bitmode(ctx);
6294 gen_load_fpr32(fpu32_T[0], fs);
6295 gen_load_fpr32(fpu32_T[2], ft);
6296 tcg_gen_helper_0_0(do_float_rsqrt2_s);
6297 gen_store_fpr32(fpu32_T[2], fd);
6301 check_cp1_registers(ctx, fd);
6302 gen_load_fpr32(fpu32_T[0], fs);
6303 tcg_gen_helper_0_0(do_float_cvtd_s);
6304 gen_store_fpr64(ctx, fpu64_T[2], fd);
6308 gen_load_fpr32(fpu32_T[0], fs);
6309 tcg_gen_helper_0_0(do_float_cvtw_s);
6310 gen_store_fpr32(fpu32_T[2], fd);
6314 check_cp1_64bitmode(ctx);
6315 gen_load_fpr32(fpu32_T[0], fs);
6316 tcg_gen_helper_0_0(do_float_cvtl_s);
6317 gen_store_fpr64(ctx, fpu64_T[2], fd);
6321 check_cp1_64bitmode(ctx);
6322 gen_load_fpr32(fpu32_T[0], fs);
6323 gen_load_fpr32(fpu32_T[1], ft);
6324 tcg_gen_extu_i32_i64(fpu64_T[0], fpu32_T[0]);
6325 tcg_gen_extu_i32_i64(fpu64_T[1], fpu32_T[1]);
6326 tcg_gen_shli_i64(fpu64_T[1], fpu64_T[1], 32);
6327 tcg_gen_or_i64(fpu64_T[2], fpu64_T[0], fpu64_T[1]);
6328 gen_store_fpr64(ctx, fpu64_T[2], fd);
6347 gen_load_fpr32(fpu32_T[0], fs);
6348 gen_load_fpr32(fpu32_T[1], ft);
6349 if (ctx->opcode & (1 << 6)) {
6351 gen_cmpabs_s(func-48, cc);
6352 opn = condnames_abs[func-48];
6354 gen_cmp_s(func-48, cc);
6355 opn = condnames[func-48];
6359 check_cp1_registers(ctx, fs | ft | fd);
6360 gen_load_fpr64(ctx, fpu64_T[0], fs);
6361 gen_load_fpr64(ctx, fpu64_T[1], ft);
6362 tcg_gen_helper_0_0(do_float_add_d);
6363 gen_store_fpr64(ctx, fpu64_T[2], fd);
6368 check_cp1_registers(ctx, fs | ft | fd);
6369 gen_load_fpr64(ctx, fpu64_T[0], fs);
6370 gen_load_fpr64(ctx, fpu64_T[1], ft);
6371 tcg_gen_helper_0_0(do_float_sub_d);
6372 gen_store_fpr64(ctx, fpu64_T[2], fd);
6377 check_cp1_registers(ctx, fs | ft | fd);
6378 gen_load_fpr64(ctx, fpu64_T[0], fs);
6379 gen_load_fpr64(ctx, fpu64_T[1], ft);
6380 tcg_gen_helper_0_0(do_float_mul_d);
6381 gen_store_fpr64(ctx, fpu64_T[2], fd);
6386 check_cp1_registers(ctx, fs | ft | fd);
6387 gen_load_fpr64(ctx, fpu64_T[0], fs);
6388 gen_load_fpr64(ctx, fpu64_T[1], ft);
6389 tcg_gen_helper_0_0(do_float_div_d);
6390 gen_store_fpr64(ctx, fpu64_T[2], fd);
6395 check_cp1_registers(ctx, fs | fd);
6396 gen_load_fpr64(ctx, fpu64_T[0], fs);
6397 tcg_gen_helper_0_0(do_float_sqrt_d);
6398 gen_store_fpr64(ctx, fpu64_T[2], fd);
6402 check_cp1_registers(ctx, fs | fd);
6403 gen_load_fpr64(ctx, fpu64_T[0], fs);
6404 tcg_gen_helper_0_0(do_float_abs_d);
6405 gen_store_fpr64(ctx, fpu64_T[2], fd);
6409 check_cp1_registers(ctx, fs | fd);
6410 gen_load_fpr64(ctx, fpu64_T[0], fs);
6411 gen_store_fpr64(ctx, fpu64_T[0], fd);
6415 check_cp1_registers(ctx, fs | fd);
6416 gen_load_fpr64(ctx, fpu64_T[0], fs);
6417 tcg_gen_helper_0_0(do_float_chs_d);
6418 gen_store_fpr64(ctx, fpu64_T[2], fd);
6422 check_cp1_64bitmode(ctx);
6423 gen_load_fpr64(ctx, fpu64_T[0], fs);
6424 tcg_gen_helper_0_0(do_float_roundl_d);
6425 gen_store_fpr64(ctx, fpu64_T[2], fd);
6429 check_cp1_64bitmode(ctx);
6430 gen_load_fpr64(ctx, fpu64_T[0], fs);
6431 tcg_gen_helper_0_0(do_float_truncl_d);
6432 gen_store_fpr64(ctx, fpu64_T[2], fd);
6436 check_cp1_64bitmode(ctx);
6437 gen_load_fpr64(ctx, fpu64_T[0], fs);
6438 tcg_gen_helper_0_0(do_float_ceill_d);
6439 gen_store_fpr64(ctx, fpu64_T[2], fd);
6443 check_cp1_64bitmode(ctx);
6444 gen_load_fpr64(ctx, fpu64_T[0], fs);
6445 tcg_gen_helper_0_0(do_float_floorl_d);
6446 gen_store_fpr64(ctx, fpu64_T[2], fd);
6450 check_cp1_registers(ctx, fs);
6451 gen_load_fpr64(ctx, fpu64_T[0], fs);
6452 tcg_gen_helper_0_0(do_float_roundw_d);
6453 gen_store_fpr32(fpu32_T[2], fd);
6457 check_cp1_registers(ctx, fs);
6458 gen_load_fpr64(ctx, fpu64_T[0], fs);
6459 tcg_gen_helper_0_0(do_float_truncw_d);
6460 gen_store_fpr32(fpu32_T[2], fd);
6464 check_cp1_registers(ctx, fs);
6465 gen_load_fpr64(ctx, fpu64_T[0], fs);
6466 tcg_gen_helper_0_0(do_float_ceilw_d);
6467 gen_store_fpr32(fpu32_T[2], fd);
6471 check_cp1_registers(ctx, fs);
6472 gen_load_fpr64(ctx, fpu64_T[0], fs);
6473 tcg_gen_helper_0_0(do_float_floorw_d);
6474 gen_store_fpr32(fpu32_T[2], fd);
6478 gen_load_fpr64(ctx, fpu64_T[0], fs);
6479 gen_load_fpr64(ctx, fpu64_T[2], fd);
6480 gen_movcf_d((ft >> 2) & 0x7, ft & 0x1);
6481 gen_store_fpr64(ctx, fpu64_T[2], fd);
6485 gen_load_fpr64(ctx, fpu64_T[0], fs);
6486 gen_load_fpr64(ctx, fpu64_T[2], fd);
6488 int l1 = gen_new_label();
6489 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6491 gen_load_gpr(t0, ft);
6492 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6494 tcg_gen_mov_i64(fpu64_T[2], fpu64_T[0]);
6497 gen_store_fpr64(ctx, fpu64_T[2], fd);
6501 gen_load_fpr64(ctx, fpu64_T[0], fs);
6502 gen_load_fpr64(ctx, fpu64_T[2], fd);
6504 int l1 = gen_new_label();
6505 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6507 gen_load_gpr(t0, ft);
6508 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6510 tcg_gen_mov_i64(fpu64_T[2], fpu64_T[0]);
6513 gen_store_fpr64(ctx, fpu64_T[2], fd);
6517 check_cp1_64bitmode(ctx);
6518 gen_load_fpr64(ctx, fpu64_T[0], fs);
6519 tcg_gen_helper_0_0(do_float_recip_d);
6520 gen_store_fpr64(ctx, fpu64_T[2], fd);
6524 check_cp1_64bitmode(ctx);
6525 gen_load_fpr64(ctx, fpu64_T[0], fs);
6526 tcg_gen_helper_0_0(do_float_rsqrt_d);
6527 gen_store_fpr64(ctx, fpu64_T[2], fd);
6531 check_cp1_64bitmode(ctx);
6532 gen_load_fpr64(ctx, fpu64_T[0], fs);
6533 gen_load_fpr64(ctx, fpu64_T[2], ft);
6534 tcg_gen_helper_0_0(do_float_recip2_d);
6535 gen_store_fpr64(ctx, fpu64_T[2], fd);
6539 check_cp1_64bitmode(ctx);
6540 gen_load_fpr64(ctx, fpu64_T[0], fs);
6541 tcg_gen_helper_0_0(do_float_recip1_d);
6542 gen_store_fpr64(ctx, fpu64_T[2], fd);
6546 check_cp1_64bitmode(ctx);
6547 gen_load_fpr64(ctx, fpu64_T[0], fs);
6548 tcg_gen_helper_0_0(do_float_rsqrt1_d);
6549 gen_store_fpr64(ctx, fpu64_T[2], fd);
6553 check_cp1_64bitmode(ctx);
6554 gen_load_fpr64(ctx, fpu64_T[0], fs);
6555 gen_load_fpr64(ctx, fpu64_T[2], ft);
6556 tcg_gen_helper_0_0(do_float_rsqrt2_d);
6557 gen_store_fpr64(ctx, fpu64_T[2], fd);
6576 gen_load_fpr64(ctx, fpu64_T[0], fs);
6577 gen_load_fpr64(ctx, fpu64_T[1], ft);
6578 if (ctx->opcode & (1 << 6)) {
6580 check_cp1_registers(ctx, fs | ft);
6581 gen_cmpabs_d(func-48, cc);
6582 opn = condnames_abs[func-48];
6584 check_cp1_registers(ctx, fs | ft);
6585 gen_cmp_d(func-48, cc);
6586 opn = condnames[func-48];
6590 check_cp1_registers(ctx, fs);
6591 gen_load_fpr64(ctx, fpu64_T[0], fs);
6592 tcg_gen_helper_0_0(do_float_cvts_d);
6593 gen_store_fpr32(fpu32_T[2], fd);
6597 check_cp1_registers(ctx, fs);
6598 gen_load_fpr64(ctx, fpu64_T[0], fs);
6599 tcg_gen_helper_0_0(do_float_cvtw_d);
6600 gen_store_fpr32(fpu32_T[2], fd);
6604 check_cp1_64bitmode(ctx);
6605 gen_load_fpr64(ctx, fpu64_T[0], fs);
6606 tcg_gen_helper_0_0(do_float_cvtl_d);
6607 gen_store_fpr64(ctx, fpu64_T[2], fd);
6611 gen_load_fpr32(fpu32_T[0], fs);
6612 tcg_gen_helper_0_0(do_float_cvts_w);
6613 gen_store_fpr32(fpu32_T[2], fd);
6617 check_cp1_registers(ctx, fd);
6618 gen_load_fpr32(fpu32_T[0], fs);
6619 tcg_gen_helper_0_0(do_float_cvtd_w);
6620 gen_store_fpr64(ctx, fpu64_T[2], fd);
6624 check_cp1_64bitmode(ctx);
6625 gen_load_fpr64(ctx, fpu64_T[0], fs);
6626 tcg_gen_helper_0_0(do_float_cvts_l);
6627 gen_store_fpr32(fpu32_T[2], fd);
6631 check_cp1_64bitmode(ctx);
6632 gen_load_fpr64(ctx, fpu64_T[0], fs);
6633 tcg_gen_helper_0_0(do_float_cvtd_l);
6634 gen_store_fpr64(ctx, fpu64_T[2], fd);
6638 check_cp1_64bitmode(ctx);
6639 gen_load_fpr32(fpu32_T[0], fs);
6640 gen_load_fpr32h(fpu32h_T[0], fs);
6641 tcg_gen_helper_0_0(do_float_cvtps_pw);
6642 gen_store_fpr32(fpu32_T[2], fd);
6643 gen_store_fpr32h(fpu32h_T[2], fd);
6647 check_cp1_64bitmode(ctx);
6648 gen_load_fpr32(fpu32_T[0], fs);
6649 gen_load_fpr32h(fpu32h_T[0], fs);
6650 gen_load_fpr32(fpu32_T[1], ft);
6651 gen_load_fpr32h(fpu32h_T[1], ft);
6652 tcg_gen_helper_0_0(do_float_add_ps);
6653 gen_store_fpr32(fpu32_T[2], fd);
6654 gen_store_fpr32h(fpu32h_T[2], fd);
6658 check_cp1_64bitmode(ctx);
6659 gen_load_fpr32(fpu32_T[0], fs);
6660 gen_load_fpr32h(fpu32h_T[0], fs);
6661 gen_load_fpr32(fpu32_T[1], ft);
6662 gen_load_fpr32h(fpu32h_T[1], ft);
6663 tcg_gen_helper_0_0(do_float_sub_ps);
6664 gen_store_fpr32(fpu32_T[2], fd);
6665 gen_store_fpr32h(fpu32h_T[2], fd);
6669 check_cp1_64bitmode(ctx);
6670 gen_load_fpr32(fpu32_T[0], fs);
6671 gen_load_fpr32h(fpu32h_T[0], fs);
6672 gen_load_fpr32(fpu32_T[1], ft);
6673 gen_load_fpr32h(fpu32h_T[1], ft);
6674 tcg_gen_helper_0_0(do_float_mul_ps);
6675 gen_store_fpr32(fpu32_T[2], fd);
6676 gen_store_fpr32h(fpu32h_T[2], fd);
6680 check_cp1_64bitmode(ctx);
6681 gen_load_fpr32(fpu32_T[0], fs);
6682 gen_load_fpr32h(fpu32h_T[0], fs);
6683 tcg_gen_helper_0_0(do_float_abs_ps);
6684 gen_store_fpr32(fpu32_T[2], fd);
6685 gen_store_fpr32h(fpu32h_T[2], fd);
6689 check_cp1_64bitmode(ctx);
6690 gen_load_fpr32(fpu32_T[0], fs);
6691 gen_load_fpr32h(fpu32h_T[0], fs);
6692 gen_store_fpr32(fpu32_T[0], fd);
6693 gen_store_fpr32h(fpu32h_T[0], fd);
6697 check_cp1_64bitmode(ctx);
6698 gen_load_fpr32(fpu32_T[0], fs);
6699 gen_load_fpr32h(fpu32h_T[0], fs);
6700 tcg_gen_helper_0_0(do_float_chs_ps);
6701 gen_store_fpr32(fpu32_T[2], fd);
6702 gen_store_fpr32h(fpu32h_T[2], fd);
6706 check_cp1_64bitmode(ctx);
6707 gen_load_fpr32(fpu32_T[0], fs);
6708 gen_load_fpr32h(fpu32h_T[0], fs);
6709 gen_load_fpr32(fpu32_T[2], fd);
6710 gen_load_fpr32h(fpu32h_T[2], fd);
6711 gen_movcf_ps((ft >> 2) & 0x7, ft & 0x1);
6712 gen_store_fpr32(fpu32_T[2], fd);
6713 gen_store_fpr32h(fpu32h_T[2], fd);
6717 check_cp1_64bitmode(ctx);
6718 gen_load_fpr32(fpu32_T[0], fs);
6719 gen_load_fpr32h(fpu32h_T[0], fs);
6720 gen_load_fpr32(fpu32_T[2], fd);
6721 gen_load_fpr32h(fpu32h_T[2], fd);
6723 int l1 = gen_new_label();
6724 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6726 gen_load_gpr(t0, ft);
6727 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6729 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6730 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
6733 gen_store_fpr32(fpu32_T[2], fd);
6734 gen_store_fpr32h(fpu32h_T[2], fd);
6738 check_cp1_64bitmode(ctx);
6739 gen_load_fpr32(fpu32_T[0], fs);
6740 gen_load_fpr32h(fpu32h_T[0], fs);
6741 gen_load_fpr32(fpu32_T[2], fd);
6742 gen_load_fpr32h(fpu32h_T[2], fd);
6744 int l1 = gen_new_label();
6745 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6747 gen_load_gpr(t0, ft);
6748 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6750 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6751 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
6754 gen_store_fpr32(fpu32_T[2], fd);
6755 gen_store_fpr32h(fpu32h_T[2], fd);
6759 check_cp1_64bitmode(ctx);
6760 gen_load_fpr32(fpu32_T[0], ft);
6761 gen_load_fpr32h(fpu32h_T[0], ft);
6762 gen_load_fpr32(fpu32_T[1], fs);
6763 gen_load_fpr32h(fpu32h_T[1], fs);
6764 tcg_gen_helper_0_0(do_float_addr_ps);
6765 gen_store_fpr32(fpu32_T[2], fd);
6766 gen_store_fpr32h(fpu32h_T[2], fd);
6770 check_cp1_64bitmode(ctx);
6771 gen_load_fpr32(fpu32_T[0], ft);
6772 gen_load_fpr32h(fpu32h_T[0], ft);
6773 gen_load_fpr32(fpu32_T[1], fs);
6774 gen_load_fpr32h(fpu32h_T[1], fs);
6775 tcg_gen_helper_0_0(do_float_mulr_ps);
6776 gen_store_fpr32(fpu32_T[2], fd);
6777 gen_store_fpr32h(fpu32h_T[2], fd);
6781 check_cp1_64bitmode(ctx);
6782 gen_load_fpr32(fpu32_T[0], fs);
6783 gen_load_fpr32h(fpu32h_T[0], fs);
6784 gen_load_fpr32(fpu32_T[2], fd);
6785 gen_load_fpr32h(fpu32h_T[2], fd);
6786 tcg_gen_helper_0_0(do_float_recip2_ps);
6787 gen_store_fpr32(fpu32_T[2], fd);
6788 gen_store_fpr32h(fpu32h_T[2], fd);
6792 check_cp1_64bitmode(ctx);
6793 gen_load_fpr32(fpu32_T[0], fs);
6794 gen_load_fpr32h(fpu32h_T[0], fs);
6795 tcg_gen_helper_0_0(do_float_recip1_ps);
6796 gen_store_fpr32(fpu32_T[2], fd);
6797 gen_store_fpr32h(fpu32h_T[2], fd);
6801 check_cp1_64bitmode(ctx);
6802 gen_load_fpr32(fpu32_T[0], fs);
6803 gen_load_fpr32h(fpu32h_T[0], fs);
6804 tcg_gen_helper_0_0(do_float_rsqrt1_ps);
6805 gen_store_fpr32(fpu32_T[2], fd);
6806 gen_store_fpr32h(fpu32h_T[2], fd);
6810 check_cp1_64bitmode(ctx);
6811 gen_load_fpr32(fpu32_T[0], fs);
6812 gen_load_fpr32h(fpu32h_T[0], fs);
6813 gen_load_fpr32(fpu32_T[2], ft);
6814 gen_load_fpr32h(fpu32h_T[2], ft);
6815 tcg_gen_helper_0_0(do_float_rsqrt2_ps);
6816 gen_store_fpr32(fpu32_T[2], fd);
6817 gen_store_fpr32h(fpu32h_T[2], fd);
6821 check_cp1_64bitmode(ctx);
6822 gen_load_fpr32h(fpu32h_T[0], fs);
6823 tcg_gen_helper_0_0(do_float_cvts_pu);
6824 gen_store_fpr32(fpu32_T[2], fd);
6828 check_cp1_64bitmode(ctx);
6829 gen_load_fpr32(fpu32_T[0], fs);
6830 gen_load_fpr32h(fpu32h_T[0], fs);
6831 tcg_gen_helper_0_0(do_float_cvtpw_ps);
6832 gen_store_fpr32(fpu32_T[2], fd);
6833 gen_store_fpr32h(fpu32h_T[2], fd);
6837 check_cp1_64bitmode(ctx);
6838 gen_load_fpr32(fpu32_T[0], fs);
6839 tcg_gen_helper_0_0(do_float_cvts_pl);
6840 gen_store_fpr32(fpu32_T[2], fd);
6844 check_cp1_64bitmode(ctx);
6845 gen_load_fpr32(fpu32_T[0], fs);
6846 gen_load_fpr32(fpu32_T[1], ft);
6847 gen_store_fpr32h(fpu32_T[0], fd);
6848 gen_store_fpr32(fpu32_T[1], fd);
6852 check_cp1_64bitmode(ctx);
6853 gen_load_fpr32(fpu32_T[0], fs);
6854 gen_load_fpr32h(fpu32h_T[1], ft);
6855 gen_store_fpr32(fpu32h_T[1], fd);
6856 gen_store_fpr32h(fpu32_T[0], fd);
6860 check_cp1_64bitmode(ctx);
6861 gen_load_fpr32h(fpu32h_T[0], fs);
6862 gen_load_fpr32(fpu32_T[1], ft);
6863 gen_store_fpr32(fpu32_T[1], fd);
6864 gen_store_fpr32h(fpu32h_T[0], fd);
6868 check_cp1_64bitmode(ctx);
6869 gen_load_fpr32h(fpu32h_T[0], fs);
6870 gen_load_fpr32h(fpu32h_T[1], ft);
6871 gen_store_fpr32(fpu32h_T[1], fd);
6872 gen_store_fpr32h(fpu32h_T[0], fd);
6891 check_cp1_64bitmode(ctx);
6892 gen_load_fpr32(fpu32_T[0], fs);
6893 gen_load_fpr32h(fpu32h_T[0], fs);
6894 gen_load_fpr32(fpu32_T[1], ft);
6895 gen_load_fpr32h(fpu32h_T[1], ft);
6896 if (ctx->opcode & (1 << 6)) {
6897 gen_cmpabs_ps(func-48, cc);
6898 opn = condnames_abs[func-48];
6900 gen_cmp_ps(func-48, cc);
6901 opn = condnames[func-48];
6906 generate_exception (ctx, EXCP_RI);
6911 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
6914 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
6917 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
6922 /* Coprocessor 3 (FPU) */
6923 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
6924 int fd, int fs, int base, int index)
6926 const char *opn = "extended float load/store";
6928 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6929 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
6932 gen_load_gpr(t0, index);
6933 } else if (index == 0) {
6934 gen_load_gpr(t0, base);
6936 gen_load_gpr(t0, base);
6937 gen_load_gpr(t1, index);
6938 gen_op_addr_add(t0, t1);
6940 /* Don't do NOP if destination is zero: we must perform the actual
6945 tcg_gen_qemu_ld32s(fpu32_T[0], t0, ctx->mem_idx);
6946 gen_store_fpr32(fpu32_T[0], fd);
6951 check_cp1_registers(ctx, fd);
6952 tcg_gen_qemu_ld64(fpu64_T[0], t0, ctx->mem_idx);
6953 gen_store_fpr64(ctx, fpu64_T[0], fd);
6957 check_cp1_64bitmode(ctx);
6958 tcg_gen_andi_tl(t0, t0, ~0x7);
6959 tcg_gen_qemu_ld64(fpu64_T[0], t0, ctx->mem_idx);
6960 gen_store_fpr64(ctx, fpu64_T[0], fd);
6965 gen_load_fpr32(fpu32_T[0], fs);
6966 tcg_gen_qemu_st32(fpu32_T[0], t0, ctx->mem_idx);
6972 check_cp1_registers(ctx, fs);
6973 gen_load_fpr64(ctx, fpu64_T[0], fs);
6974 tcg_gen_qemu_st64(fpu64_T[0], t0, ctx->mem_idx);
6979 check_cp1_64bitmode(ctx);
6980 gen_load_fpr64(ctx, fpu64_T[0], fs);
6981 tcg_gen_andi_tl(t0, t0, ~0x7);
6982 tcg_gen_qemu_st64(fpu64_T[0], t0, ctx->mem_idx);
6988 generate_exception(ctx, EXCP_RI);
6995 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
6996 regnames[index], regnames[base]);
6999 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7000 int fd, int fr, int fs, int ft)
7002 const char *opn = "flt3_arith";
7006 check_cp1_64bitmode(ctx);
7008 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7009 int l1 = gen_new_label();
7010 int l2 = gen_new_label();
7012 gen_load_gpr(t0, fr);
7013 tcg_gen_andi_tl(t0, t0, 0x7);
7014 gen_load_fpr32(fpu32_T[0], fs);
7015 gen_load_fpr32h(fpu32h_T[0], fs);
7016 gen_load_fpr32(fpu32_T[1], ft);
7017 gen_load_fpr32h(fpu32h_T[1], ft);
7019 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7020 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
7021 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
7024 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7026 #ifdef TARGET_WORDS_BIGENDIAN
7027 tcg_gen_mov_i32(fpu32h_T[2], fpu32_T[0]);
7028 tcg_gen_mov_i32(fpu32_T[2], fpu32h_T[1]);
7030 tcg_gen_mov_i32(fpu32h_T[2], fpu32_T[1]);
7031 tcg_gen_mov_i32(fpu32_T[2], fpu32h_T[0]);
7035 gen_store_fpr32(fpu32_T[2], fd);
7036 gen_store_fpr32h(fpu32h_T[2], fd);
7041 gen_load_fpr32(fpu32_T[0], fs);
7042 gen_load_fpr32(fpu32_T[1], ft);
7043 gen_load_fpr32(fpu32_T[2], fr);
7044 tcg_gen_helper_0_0(do_float_muladd_s);
7045 gen_store_fpr32(fpu32_T[2], fd);
7050 check_cp1_registers(ctx, fd | fs | ft | fr);
7051 gen_load_fpr64(ctx, fpu64_T[0], fs);
7052 gen_load_fpr64(ctx, fpu64_T[1], ft);
7053 gen_load_fpr64(ctx, fpu64_T[2], fr);
7054 tcg_gen_helper_0_0(do_float_muladd_d);
7055 gen_store_fpr64(ctx, fpu64_T[2], fd);
7059 check_cp1_64bitmode(ctx);
7060 gen_load_fpr32(fpu32_T[0], fs);
7061 gen_load_fpr32h(fpu32h_T[0], fs);
7062 gen_load_fpr32(fpu32_T[1], ft);
7063 gen_load_fpr32h(fpu32h_T[1], ft);
7064 gen_load_fpr32(fpu32_T[2], fr);
7065 gen_load_fpr32h(fpu32h_T[2], fr);
7066 tcg_gen_helper_0_0(do_float_muladd_ps);
7067 gen_store_fpr32(fpu32_T[2], fd);
7068 gen_store_fpr32h(fpu32h_T[2], fd);
7073 gen_load_fpr32(fpu32_T[0], fs);
7074 gen_load_fpr32(fpu32_T[1], ft);
7075 gen_load_fpr32(fpu32_T[2], fr);
7076 tcg_gen_helper_0_0(do_float_mulsub_s);
7077 gen_store_fpr32(fpu32_T[2], fd);
7082 check_cp1_registers(ctx, fd | fs | ft | fr);
7083 gen_load_fpr64(ctx, fpu64_T[0], fs);
7084 gen_load_fpr64(ctx, fpu64_T[1], ft);
7085 gen_load_fpr64(ctx, fpu64_T[2], fr);
7086 tcg_gen_helper_0_0(do_float_mulsub_d);
7087 gen_store_fpr64(ctx, fpu64_T[2], fd);
7091 check_cp1_64bitmode(ctx);
7092 gen_load_fpr32(fpu32_T[0], fs);
7093 gen_load_fpr32h(fpu32h_T[0], fs);
7094 gen_load_fpr32(fpu32_T[1], ft);
7095 gen_load_fpr32h(fpu32h_T[1], ft);
7096 gen_load_fpr32(fpu32_T[2], fr);
7097 gen_load_fpr32h(fpu32h_T[2], fr);
7098 tcg_gen_helper_0_0(do_float_mulsub_ps);
7099 gen_store_fpr32(fpu32_T[2], fd);
7100 gen_store_fpr32h(fpu32h_T[2], fd);
7105 gen_load_fpr32(fpu32_T[0], fs);
7106 gen_load_fpr32(fpu32_T[1], ft);
7107 gen_load_fpr32(fpu32_T[2], fr);
7108 tcg_gen_helper_0_0(do_float_nmuladd_s);
7109 gen_store_fpr32(fpu32_T[2], fd);
7114 check_cp1_registers(ctx, fd | fs | ft | fr);
7115 gen_load_fpr64(ctx, fpu64_T[0], fs);
7116 gen_load_fpr64(ctx, fpu64_T[1], ft);
7117 gen_load_fpr64(ctx, fpu64_T[2], fr);
7118 tcg_gen_helper_0_0(do_float_nmuladd_d);
7119 gen_store_fpr64(ctx, fpu64_T[2], fd);
7123 check_cp1_64bitmode(ctx);
7124 gen_load_fpr32(fpu32_T[0], fs);
7125 gen_load_fpr32h(fpu32h_T[0], fs);
7126 gen_load_fpr32(fpu32_T[1], ft);
7127 gen_load_fpr32h(fpu32h_T[1], ft);
7128 gen_load_fpr32(fpu32_T[2], fr);
7129 gen_load_fpr32h(fpu32h_T[2], fr);
7130 tcg_gen_helper_0_0(do_float_nmuladd_ps);
7131 gen_store_fpr32(fpu32_T[2], fd);
7132 gen_store_fpr32h(fpu32h_T[2], fd);
7137 gen_load_fpr32(fpu32_T[0], fs);
7138 gen_load_fpr32(fpu32_T[1], ft);
7139 gen_load_fpr32(fpu32_T[2], fr);
7140 tcg_gen_helper_0_0(do_float_nmulsub_s);
7141 gen_store_fpr32(fpu32_T[2], fd);
7146 check_cp1_registers(ctx, fd | fs | ft | fr);
7147 gen_load_fpr64(ctx, fpu64_T[0], fs);
7148 gen_load_fpr64(ctx, fpu64_T[1], ft);
7149 gen_load_fpr64(ctx, fpu64_T[2], fr);
7150 tcg_gen_helper_0_0(do_float_nmulsub_d);
7151 gen_store_fpr64(ctx, fpu64_T[2], fd);
7155 check_cp1_64bitmode(ctx);
7156 gen_load_fpr32(fpu32_T[0], fs);
7157 gen_load_fpr32h(fpu32h_T[0], fs);
7158 gen_load_fpr32(fpu32_T[1], ft);
7159 gen_load_fpr32h(fpu32h_T[1], ft);
7160 gen_load_fpr32(fpu32_T[2], fr);
7161 gen_load_fpr32h(fpu32h_T[2], fr);
7162 tcg_gen_helper_0_0(do_float_nmulsub_ps);
7163 gen_store_fpr32(fpu32_T[2], fd);
7164 gen_store_fpr32h(fpu32h_T[2], fd);
7169 generate_exception (ctx, EXCP_RI);
7172 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7173 fregnames[fs], fregnames[ft]);
7176 /* ISA extensions (ASEs) */
7177 /* MIPS16 extension to MIPS32 */
7178 /* SmartMIPS extension to MIPS32 */
7180 #if defined(TARGET_MIPS64)
7182 /* MDMX extension to MIPS64 */
7186 static void decode_opc (CPUState *env, DisasContext *ctx)
7190 uint32_t op, op1, op2;
7193 /* make sure instructions are on a word boundary */
7194 if (ctx->pc & 0x3) {
7195 env->CP0_BadVAddr = ctx->pc;
7196 generate_exception(ctx, EXCP_AdEL);
7200 /* Handle blikely not taken case */
7201 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7202 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL);
7203 int l1 = gen_new_label();
7205 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7206 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
7207 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
7208 tcg_temp_free(r_tmp);
7210 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
7212 tcg_gen_movi_i32(r_tmp2, ctx->hflags & ~MIPS_HFLAG_BMASK);
7213 tcg_gen_st_i32(r_tmp2, cpu_env, offsetof(CPUState, hflags));
7214 tcg_temp_free(r_tmp2);
7216 gen_goto_tb(ctx, 1, ctx->pc + 4);
7219 op = MASK_OP_MAJOR(ctx->opcode);
7220 rs = (ctx->opcode >> 21) & 0x1f;
7221 rt = (ctx->opcode >> 16) & 0x1f;
7222 rd = (ctx->opcode >> 11) & 0x1f;
7223 sa = (ctx->opcode >> 6) & 0x1f;
7224 imm = (int16_t)ctx->opcode;
7227 op1 = MASK_SPECIAL(ctx->opcode);
7229 case OPC_SLL: /* Arithmetic with immediate */
7230 case OPC_SRL ... OPC_SRA:
7231 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7233 case OPC_MOVZ ... OPC_MOVN:
7234 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7235 case OPC_SLLV: /* Arithmetic */
7236 case OPC_SRLV ... OPC_SRAV:
7237 case OPC_ADD ... OPC_NOR:
7238 case OPC_SLT ... OPC_SLTU:
7239 gen_arith(env, ctx, op1, rd, rs, rt);
7241 case OPC_MULT ... OPC_DIVU:
7243 check_insn(env, ctx, INSN_VR54XX);
7244 op1 = MASK_MUL_VR54XX(ctx->opcode);
7245 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7247 gen_muldiv(ctx, op1, rs, rt);
7249 case OPC_JR ... OPC_JALR:
7250 gen_compute_branch(ctx, op1, rs, rd, sa);
7252 case OPC_TGE ... OPC_TEQ: /* Traps */
7254 gen_trap(ctx, op1, rs, rt, -1);
7256 case OPC_MFHI: /* Move from HI/LO */
7258 gen_HILO(ctx, op1, rd);
7261 case OPC_MTLO: /* Move to HI/LO */
7262 gen_HILO(ctx, op1, rs);
7264 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7265 #ifdef MIPS_STRICT_STANDARD
7266 MIPS_INVAL("PMON / selsl");
7267 generate_exception(ctx, EXCP_RI);
7269 tcg_gen_helper_0_i(do_pmon, sa);
7273 generate_exception(ctx, EXCP_SYSCALL);
7276 generate_exception(ctx, EXCP_BREAK);
7279 #ifdef MIPS_STRICT_STANDARD
7281 generate_exception(ctx, EXCP_RI);
7283 /* Implemented as RI exception for now. */
7284 MIPS_INVAL("spim (unofficial)");
7285 generate_exception(ctx, EXCP_RI);
7293 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7294 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7295 save_cpu_state(ctx, 1);
7296 check_cp1_enabled(ctx);
7297 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7298 (ctx->opcode >> 16) & 1);
7300 generate_exception_err(ctx, EXCP_CpU, 1);
7304 #if defined(TARGET_MIPS64)
7305 /* MIPS64 specific opcodes */
7307 case OPC_DSRL ... OPC_DSRA:
7309 case OPC_DSRL32 ... OPC_DSRA32:
7310 check_insn(env, ctx, ISA_MIPS3);
7312 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7315 case OPC_DSRLV ... OPC_DSRAV:
7316 case OPC_DADD ... OPC_DSUBU:
7317 check_insn(env, ctx, ISA_MIPS3);
7319 gen_arith(env, ctx, op1, rd, rs, rt);
7321 case OPC_DMULT ... OPC_DDIVU:
7322 check_insn(env, ctx, ISA_MIPS3);
7324 gen_muldiv(ctx, op1, rs, rt);
7327 default: /* Invalid */
7328 MIPS_INVAL("special");
7329 generate_exception(ctx, EXCP_RI);
7334 op1 = MASK_SPECIAL2(ctx->opcode);
7336 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7337 case OPC_MSUB ... OPC_MSUBU:
7338 check_insn(env, ctx, ISA_MIPS32);
7339 gen_muldiv(ctx, op1, rs, rt);
7342 gen_arith(env, ctx, op1, rd, rs, rt);
7344 case OPC_CLZ ... OPC_CLO:
7345 check_insn(env, ctx, ISA_MIPS32);
7346 gen_cl(ctx, op1, rd, rs);
7349 /* XXX: not clear which exception should be raised
7350 * when in debug mode...
7352 check_insn(env, ctx, ISA_MIPS32);
7353 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7354 generate_exception(ctx, EXCP_DBp);
7356 generate_exception(ctx, EXCP_DBp);
7360 #if defined(TARGET_MIPS64)
7361 case OPC_DCLZ ... OPC_DCLO:
7362 check_insn(env, ctx, ISA_MIPS64);
7364 gen_cl(ctx, op1, rd, rs);
7367 default: /* Invalid */
7368 MIPS_INVAL("special2");
7369 generate_exception(ctx, EXCP_RI);
7374 op1 = MASK_SPECIAL3(ctx->opcode);
7378 check_insn(env, ctx, ISA_MIPS32R2);
7379 gen_bitops(ctx, op1, rt, rs, sa, rd);
7382 check_insn(env, ctx, ISA_MIPS32R2);
7383 op2 = MASK_BSHFL(ctx->opcode);
7385 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7386 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7390 gen_load_gpr(t1, rt);
7391 tcg_gen_helper_1_2(do_wsbh, t0, t0, t1);
7392 gen_store_gpr(t0, rd);
7395 gen_load_gpr(t1, rt);
7396 tcg_gen_ext8s_tl(t0, t1);
7397 gen_store_gpr(t0, rd);
7400 gen_load_gpr(t1, rt);
7401 tcg_gen_ext16s_tl(t0, t1);
7402 gen_store_gpr(t0, rd);
7404 default: /* Invalid */
7405 MIPS_INVAL("bshfl");
7406 generate_exception(ctx, EXCP_RI);
7414 check_insn(env, ctx, ISA_MIPS32R2);
7416 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7420 save_cpu_state(ctx, 1);
7421 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
7424 save_cpu_state(ctx, 1);
7425 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
7428 save_cpu_state(ctx, 1);
7429 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
7432 save_cpu_state(ctx, 1);
7433 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
7436 #if defined (CONFIG_USER_ONLY)
7437 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7440 /* XXX: Some CPUs implement this in hardware. Not supported yet. */
7442 default: /* Invalid */
7443 MIPS_INVAL("rdhwr");
7444 generate_exception(ctx, EXCP_RI);
7447 gen_store_gpr(t0, rt);
7452 check_insn(env, ctx, ASE_MT);
7454 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7455 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7457 gen_load_gpr(t0, rt);
7458 gen_load_gpr(t1, rs);
7459 tcg_gen_helper_0_2(do_fork, t0, t1);
7465 check_insn(env, ctx, ASE_MT);
7467 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7469 gen_load_gpr(t0, rs);
7470 tcg_gen_helper_1_1(do_yield, t0, t0);
7471 gen_store_gpr(t0, rd);
7475 #if defined(TARGET_MIPS64)
7476 case OPC_DEXTM ... OPC_DEXT:
7477 case OPC_DINSM ... OPC_DINS:
7478 check_insn(env, ctx, ISA_MIPS64R2);
7480 gen_bitops(ctx, op1, rt, rs, sa, rd);
7483 check_insn(env, ctx, ISA_MIPS64R2);
7485 op2 = MASK_DBSHFL(ctx->opcode);
7487 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7488 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7492 gen_load_gpr(t1, rt);
7493 tcg_gen_helper_1_2(do_dsbh, t0, t0, t1);
7496 gen_load_gpr(t1, rt);
7497 tcg_gen_helper_1_2(do_dshd, t0, t0, t1);
7499 default: /* Invalid */
7500 MIPS_INVAL("dbshfl");
7501 generate_exception(ctx, EXCP_RI);
7504 gen_store_gpr(t0, rd);
7510 default: /* Invalid */
7511 MIPS_INVAL("special3");
7512 generate_exception(ctx, EXCP_RI);
7517 op1 = MASK_REGIMM(ctx->opcode);
7519 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7520 case OPC_BLTZAL ... OPC_BGEZALL:
7521 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7523 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7525 gen_trap(ctx, op1, rs, -1, imm);
7528 check_insn(env, ctx, ISA_MIPS32R2);
7531 default: /* Invalid */
7532 MIPS_INVAL("regimm");
7533 generate_exception(ctx, EXCP_RI);
7538 check_cp0_enabled(ctx);
7539 op1 = MASK_CP0(ctx->opcode);
7545 #if defined(TARGET_MIPS64)
7549 #ifndef CONFIG_USER_ONLY
7550 gen_cp0(env, ctx, op1, rt, rd);
7553 case OPC_C0_FIRST ... OPC_C0_LAST:
7554 #ifndef CONFIG_USER_ONLY
7555 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7559 op2 = MASK_MFMC0(ctx->opcode);
7561 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7565 check_insn(env, ctx, ASE_MT);
7566 tcg_gen_helper_1_1(do_dmt, t0, t0);
7569 check_insn(env, ctx, ASE_MT);
7570 tcg_gen_helper_1_1(do_emt, t0, t0);
7573 check_insn(env, ctx, ASE_MT);
7574 tcg_gen_helper_1_1(do_dvpe, t0, t0);
7577 check_insn(env, ctx, ASE_MT);
7578 tcg_gen_helper_1_1(do_evpe, t0, t0);
7581 check_insn(env, ctx, ISA_MIPS32R2);
7582 save_cpu_state(ctx, 1);
7583 tcg_gen_helper_1_0(do_di, t0);
7584 /* Stop translation as we may have switched the execution mode */
7585 ctx->bstate = BS_STOP;
7588 check_insn(env, ctx, ISA_MIPS32R2);
7589 save_cpu_state(ctx, 1);
7590 tcg_gen_helper_1_0(do_ei, t0);
7591 /* Stop translation as we may have switched the execution mode */
7592 ctx->bstate = BS_STOP;
7594 default: /* Invalid */
7595 MIPS_INVAL("mfmc0");
7596 generate_exception(ctx, EXCP_RI);
7599 gen_store_gpr(t0, rt);
7604 check_insn(env, ctx, ISA_MIPS32R2);
7605 gen_load_srsgpr(rt, rd);
7608 check_insn(env, ctx, ISA_MIPS32R2);
7609 gen_store_srsgpr(rt, rd);
7613 generate_exception(ctx, EXCP_RI);
7617 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7618 gen_arith_imm(env, ctx, op, rt, rs, imm);
7620 case OPC_J ... OPC_JAL: /* Jump */
7621 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7622 gen_compute_branch(ctx, op, rs, rt, offset);
7624 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7625 case OPC_BEQL ... OPC_BGTZL:
7626 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7628 case OPC_LB ... OPC_LWR: /* Load and stores */
7629 case OPC_SB ... OPC_SW:
7633 gen_ldst(ctx, op, rt, rs, imm);
7636 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7640 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7644 /* Floating point (COP1). */
7649 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7650 save_cpu_state(ctx, 1);
7651 check_cp1_enabled(ctx);
7652 gen_flt_ldst(ctx, op, rt, rs, imm);
7654 generate_exception_err(ctx, EXCP_CpU, 1);
7659 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7660 save_cpu_state(ctx, 1);
7661 check_cp1_enabled(ctx);
7662 op1 = MASK_CP1(ctx->opcode);
7666 check_insn(env, ctx, ISA_MIPS32R2);
7671 gen_cp1(ctx, op1, rt, rd);
7673 #if defined(TARGET_MIPS64)
7676 check_insn(env, ctx, ISA_MIPS3);
7677 gen_cp1(ctx, op1, rt, rd);
7683 check_insn(env, ctx, ASE_MIPS3D);
7686 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
7687 (rt >> 2) & 0x7, imm << 2);
7694 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
7699 generate_exception (ctx, EXCP_RI);
7703 generate_exception_err(ctx, EXCP_CpU, 1);
7713 /* COP2: Not implemented. */
7714 generate_exception_err(ctx, EXCP_CpU, 2);
7718 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7719 save_cpu_state(ctx, 1);
7720 check_cp1_enabled(ctx);
7721 op1 = MASK_CP3(ctx->opcode);
7729 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
7747 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
7751 generate_exception (ctx, EXCP_RI);
7755 generate_exception_err(ctx, EXCP_CpU, 1);
7759 #if defined(TARGET_MIPS64)
7760 /* MIPS64 opcodes */
7762 case OPC_LDL ... OPC_LDR:
7763 case OPC_SDL ... OPC_SDR:
7768 check_insn(env, ctx, ISA_MIPS3);
7770 gen_ldst(ctx, op, rt, rs, imm);
7772 case OPC_DADDI ... OPC_DADDIU:
7773 check_insn(env, ctx, ISA_MIPS3);
7775 gen_arith_imm(env, ctx, op, rt, rs, imm);
7779 check_insn(env, ctx, ASE_MIPS16);
7780 /* MIPS16: Not implemented. */
7782 check_insn(env, ctx, ASE_MDMX);
7783 /* MDMX: Not implemented. */
7784 default: /* Invalid */
7785 MIPS_INVAL("major opcode");
7786 generate_exception(ctx, EXCP_RI);
7789 if (ctx->hflags & MIPS_HFLAG_BMASK) {
7790 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
7791 /* Branches completion */
7792 ctx->hflags &= ~MIPS_HFLAG_BMASK;
7793 ctx->bstate = BS_BRANCH;
7794 save_cpu_state(ctx, 0);
7795 /* FIXME: Need to clear can_do_io. */
7798 /* unconditional branch */
7799 MIPS_DEBUG("unconditional branch");
7800 gen_goto_tb(ctx, 0, ctx->btarget);
7803 /* blikely taken case */
7804 MIPS_DEBUG("blikely branch taken");
7805 gen_goto_tb(ctx, 0, ctx->btarget);
7808 /* Conditional branch */
7809 MIPS_DEBUG("conditional branch");
7811 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL);
7812 int l1 = gen_new_label();
7814 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
7815 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
7816 tcg_temp_free(r_tmp);
7817 gen_goto_tb(ctx, 1, ctx->pc + 4);
7819 gen_goto_tb(ctx, 0, ctx->btarget);
7823 /* unconditional branch to register */
7824 MIPS_DEBUG("branch to register");
7829 MIPS_DEBUG("unknown branch");
7835 static always_inline int
7836 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
7840 target_ulong pc_start;
7841 uint16_t *gen_opc_end;
7846 if (search_pc && loglevel)
7847 fprintf (logfile, "search pc %d\n", search_pc);
7850 /* Leave some spare opc slots for branch handling. */
7851 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
7855 ctx.bstate = BS_NONE;
7856 /* Restore delay slot state from the tb context. */
7857 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
7858 restore_cpu_state(env, &ctx);
7859 #if defined(CONFIG_USER_ONLY)
7860 ctx.mem_idx = MIPS_HFLAG_UM;
7862 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
7866 max_insns = tb->cflags & CF_COUNT_MASK;
7868 max_insns = CF_COUNT_MASK;
7870 if (loglevel & CPU_LOG_TB_CPU) {
7871 fprintf(logfile, "------------------------------------------------\n");
7872 /* FIXME: This may print out stale hflags from env... */
7873 cpu_dump_state(env, logfile, fprintf, 0);
7876 #ifdef MIPS_DEBUG_DISAS
7877 if (loglevel & CPU_LOG_TB_IN_ASM)
7878 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
7879 tb, ctx.mem_idx, ctx.hflags);
7882 while (ctx.bstate == BS_NONE) {
7883 if (env->nb_breakpoints > 0) {
7884 for(j = 0; j < env->nb_breakpoints; j++) {
7885 if (env->breakpoints[j] == ctx.pc) {
7886 save_cpu_state(&ctx, 1);
7887 ctx.bstate = BS_BRANCH;
7888 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
7889 /* Include the breakpoint location or the tb won't
7890 * be flushed when it must be. */
7892 goto done_generating;
7898 j = gen_opc_ptr - gen_opc_buf;
7902 gen_opc_instr_start[lj++] = 0;
7904 gen_opc_pc[lj] = ctx.pc;
7905 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
7906 gen_opc_instr_start[lj] = 1;
7907 gen_opc_icount[lj] = num_insns;
7909 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
7911 ctx.opcode = ldl_code(ctx.pc);
7912 decode_opc(env, &ctx);
7916 if (env->singlestep_enabled)
7919 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
7922 if (gen_opc_ptr >= gen_opc_end)
7925 if (gen_opc_ptr >= gen_opc_end)
7928 if (num_insns >= max_insns)
7930 #if defined (MIPS_SINGLE_STEP)
7934 if (tb->cflags & CF_LAST_IO)
7936 if (env->singlestep_enabled) {
7937 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
7938 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
7940 switch (ctx.bstate) {
7942 tcg_gen_helper_0_0(do_interrupt_restart);
7943 gen_goto_tb(&ctx, 0, ctx.pc);
7946 save_cpu_state(&ctx, 0);
7947 gen_goto_tb(&ctx, 0, ctx.pc);
7950 tcg_gen_helper_0_0(do_interrupt_restart);
7959 gen_icount_end(tb, num_insns);
7960 *gen_opc_ptr = INDEX_op_end;
7962 j = gen_opc_ptr - gen_opc_buf;
7965 gen_opc_instr_start[lj++] = 0;
7967 tb->size = ctx.pc - pc_start;
7968 tb->icount = num_insns;
7971 #if defined MIPS_DEBUG_DISAS
7972 if (loglevel & CPU_LOG_TB_IN_ASM)
7973 fprintf(logfile, "\n");
7975 if (loglevel & CPU_LOG_TB_IN_ASM) {
7976 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
7977 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
7978 fprintf(logfile, "\n");
7980 if (loglevel & CPU_LOG_TB_CPU) {
7981 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
7988 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
7990 return gen_intermediate_code_internal(env, tb, 0);
7993 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
7995 return gen_intermediate_code_internal(env, tb, 1);
7998 void fpu_dump_state(CPUState *env, FILE *f,
7999 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8003 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8005 #define printfpr(fp) \
8008 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8009 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8010 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8013 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8014 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8015 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8016 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8017 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8022 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8023 env->fpu->fcr0, env->fpu->fcr31, is_fpu64, env->fpu->fp_status,
8024 get_float_exception_flags(&env->fpu->fp_status));
8025 fpu_fprintf(f, "FT0: "); printfpr(&env->ft0);
8026 fpu_fprintf(f, "FT1: "); printfpr(&env->ft1);
8027 fpu_fprintf(f, "FT2: "); printfpr(&env->ft2);
8028 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8029 fpu_fprintf(f, "%3s: ", fregnames[i]);
8030 printfpr(&env->fpu->fpr[i]);
8036 void dump_fpu (CPUState *env)
8040 "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx
8041 " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx
8043 env->active_tc.PC, env->active_tc.HI[0],
8044 env->active_tc.LO[0], env->hflags, env->btarget,
8046 fpu_dump_state(env, logfile, fprintf, 0);
8050 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8051 /* Debug help: The architecture requires 32bit code to maintain proper
8052 sign-extened values on 64bit machines. */
8054 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8056 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8057 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8062 if (!SIGN_EXT_P(env->active_tc.PC))
8063 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8064 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8065 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8066 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8067 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8068 if (!SIGN_EXT_P(env->btarget))
8069 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8071 for (i = 0; i < 32; i++) {
8072 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8073 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8076 if (!SIGN_EXT_P(env->CP0_EPC))
8077 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8078 if (!SIGN_EXT_P(env->CP0_LLAddr))
8079 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8083 void cpu_dump_state (CPUState *env, FILE *f,
8084 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8089 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",
8090 env->active_tc.PC, env->active_tc.HI, env->active_tc.LO, env->hflags, env->btarget, env->bcond);
8091 for (i = 0; i < 32; i++) {
8093 cpu_fprintf(f, "GPR%02d:", i);
8094 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8096 cpu_fprintf(f, "\n");
8099 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8100 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8101 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8102 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8103 if (env->hflags & MIPS_HFLAG_FPU)
8104 fpu_dump_state(env, f, cpu_fprintf, flags);
8105 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8106 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8110 static void mips_tcg_init(void)
8114 /* Initialize various static tables. */
8118 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8119 current_fpu = tcg_global_mem_new(TCG_TYPE_PTR,
8121 offsetof(CPUState, fpu),
8124 /* register helpers */
8126 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8129 fpu32_T[0] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft0.w[FP_ENDIAN_IDX]), "WT0");
8130 fpu32_T[1] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft1.w[FP_ENDIAN_IDX]), "WT1");
8131 fpu32_T[2] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft2.w[FP_ENDIAN_IDX]), "WT2");
8132 fpu64_T[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft0.d), "DT0");
8133 fpu64_T[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft1.d), "DT1");
8134 fpu64_T[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft2.d), "DT2");
8135 fpu32h_T[0] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft0.w[!FP_ENDIAN_IDX]), "WTH0");
8136 fpu32h_T[1] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft1.w[!FP_ENDIAN_IDX]), "WTH1");
8137 fpu32h_T[2] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft2.w[!FP_ENDIAN_IDX]), "WTH2");
8142 #include "translate_init.c"
8144 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8147 const mips_def_t *def;
8149 def = cpu_mips_find_by_name(cpu_model);
8152 env = qemu_mallocz(sizeof(CPUMIPSState));
8155 env->cpu_model = def;
8158 env->cpu_model_str = cpu_model;
8164 void cpu_reset (CPUMIPSState *env)
8166 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8171 #if !defined(CONFIG_USER_ONLY)
8172 if (env->hflags & MIPS_HFLAG_BMASK) {
8173 /* If the exception was raised from a delay slot,
8174 * come back to the jump. */
8175 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8177 env->CP0_ErrorEPC = env->active_tc.PC;
8179 env->active_tc.PC = (int32_t)0xBFC00000;
8181 /* SMP not implemented */
8182 env->CP0_EBase = 0x80000000;
8183 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8184 /* vectored interrupts not implemented, timer on int 7,
8185 no performance counters. */
8186 env->CP0_IntCtl = 0xe0000000;
8190 for (i = 0; i < 7; i++) {
8191 env->CP0_WatchLo[i] = 0;
8192 env->CP0_WatchHi[i] = 0x80000000;
8194 env->CP0_WatchLo[7] = 0;
8195 env->CP0_WatchHi[7] = 0;
8197 /* Count register increments in debug mode, EJTAG version 1 */
8198 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8200 env->exception_index = EXCP_NONE;
8201 #if defined(CONFIG_USER_ONLY)
8202 env->hflags = MIPS_HFLAG_UM;
8203 env->user_mode_only = 1;
8205 env->hflags = MIPS_HFLAG_CP0;
8207 cpu_mips_register(env, env->cpu_model);
8210 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8211 unsigned long searched_pc, int pc_pos, void *puc)
8213 env->active_tc.PC = gen_opc_pc[pc_pos];
8214 env->hflags &= ~MIPS_HFLAG_BMASK;
8215 env->hflags |= gen_opc_hflags[pc_pos];