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 static inline void tcg_gen_helper_0_i(void *func, TCGv arg)
433 TCGv tmp = tcg_const_i32(arg);
435 tcg_gen_helper_0_1(func, tmp);
439 static inline void tcg_gen_helper_0_ii(void *func, TCGv arg1, TCGv arg2)
441 TCGv tmp1 = tcg_const_i32(arg1);
442 TCGv tmp2 = tcg_const_i32(arg2);
444 tcg_gen_helper_0_2(func, tmp1, tmp2);
449 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg1, TCGv arg2)
451 TCGv tmp = tcg_const_i32(arg2);
453 tcg_gen_helper_0_2(func, arg1, tmp);
457 static inline void tcg_gen_helper_0_2i(void *func, TCGv arg1, TCGv arg2, TCGv arg3)
459 TCGv tmp = tcg_const_i32(arg3);
461 tcg_gen_helper_0_3(func, arg1, arg2, tmp);
465 static inline void tcg_gen_helper_0_2ii(void *func, TCGv arg1, TCGv arg2, TCGv arg3, TCGv arg4)
467 TCGv tmp1 = tcg_const_i32(arg3);
468 TCGv tmp2 = tcg_const_i32(arg3);
470 tcg_gen_helper_0_4(func, arg1, arg2, tmp1, tmp2);
475 static inline void tcg_gen_helper_1_i(void *func, TCGv ret, TCGv arg)
477 TCGv tmp = tcg_const_i32(arg);
479 tcg_gen_helper_1_1(func, ret, tmp);
483 static inline void tcg_gen_helper_1_1i(void *func, TCGv ret, TCGv arg1, TCGv arg2)
485 TCGv tmp = tcg_const_i32(arg2);
487 tcg_gen_helper_1_2(func, ret, arg1, tmp);
491 static inline void tcg_gen_helper_1_2i(void *func, TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3)
493 TCGv tmp = tcg_const_i32(arg3);
495 tcg_gen_helper_1_3(func, ret, arg1, arg2, tmp);
499 static inline void tcg_gen_helper_1_2ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, TCGv arg4)
501 TCGv tmp1 = tcg_const_i32(arg3);
502 TCGv tmp2 = tcg_const_i32(arg3);
504 tcg_gen_helper_1_4(func, ret, arg1, arg2, tmp1, tmp2);
509 typedef struct DisasContext {
510 struct TranslationBlock *tb;
511 target_ulong pc, saved_pc;
514 /* Routine used to access memory */
516 uint32_t hflags, saved_hflags;
518 target_ulong btarget;
522 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
523 * exception condition
525 BS_STOP = 1, /* We want to stop translation for any reason */
526 BS_BRANCH = 2, /* We reached a branch condition */
527 BS_EXCP = 3, /* We reached an exception condition */
530 static const char *regnames[] =
531 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
532 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
533 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
534 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
536 static const char *fregnames[] =
537 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
538 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
539 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
540 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
542 #ifdef MIPS_DEBUG_DISAS
543 #define MIPS_DEBUG(fmt, args...) \
545 if (loglevel & CPU_LOG_TB_IN_ASM) { \
546 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
547 ctx->pc, ctx->opcode , ##args); \
551 #define MIPS_DEBUG(fmt, args...) do { } while(0)
554 #define MIPS_INVAL(op) \
556 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
557 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
560 /* General purpose registers moves. */
561 static inline void gen_load_gpr (TCGv t, int reg)
564 tcg_gen_movi_tl(t, 0);
566 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
567 sizeof(target_ulong) * reg);
570 static inline void gen_store_gpr (TCGv t, int reg)
573 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
574 sizeof(target_ulong) * reg);
577 /* Moves to/from HI and LO registers. */
578 static inline void gen_load_LO (TCGv t, int reg)
580 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
581 sizeof(target_ulong) * reg);
584 static inline void gen_store_LO (TCGv t, int reg)
586 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
587 sizeof(target_ulong) * reg);
590 static inline void gen_load_HI (TCGv t, int reg)
592 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
593 sizeof(target_ulong) * reg);
596 static inline void gen_store_HI (TCGv t, int reg)
598 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
599 sizeof(target_ulong) * reg);
602 /* Moves to/from shadow registers. */
603 static inline void gen_load_srsgpr (int from, int to)
605 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
608 tcg_gen_movi_tl(r_tmp1, 0);
610 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
612 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
613 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
614 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
615 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
616 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
618 tcg_gen_ld_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * from);
619 tcg_temp_free(r_tmp2);
621 gen_store_gpr(r_tmp1, to);
622 tcg_temp_free(r_tmp1);
625 static inline void gen_store_srsgpr (int from, int to)
628 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
629 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
631 gen_load_gpr(r_tmp1, from);
632 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
633 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
634 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
635 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
636 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
638 tcg_gen_st_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * to);
639 tcg_temp_free(r_tmp1);
640 tcg_temp_free(r_tmp2);
644 /* Floating point register moves. */
645 static inline void gen_load_fpr32 (TCGv t, int reg)
647 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
650 static inline void gen_store_fpr32 (TCGv t, int reg)
652 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
655 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
657 if (ctx->hflags & MIPS_HFLAG_F64) {
658 tcg_gen_ld_i64(t, current_fpu, 8 * reg);
660 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
661 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
663 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
664 tcg_gen_extu_i32_i64(t, r_tmp1);
665 tcg_gen_shli_i64(t, t, 32);
666 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
667 tcg_gen_extu_i32_i64(r_tmp2, r_tmp1);
668 tcg_gen_or_i64(t, t, r_tmp2);
669 tcg_temp_free(r_tmp1);
670 tcg_temp_free(r_tmp2);
674 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
676 if (ctx->hflags & MIPS_HFLAG_F64) {
677 tcg_gen_st_i64(t, current_fpu, 8 * reg);
679 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
681 tcg_gen_trunc_i64_i32(r_tmp, t);
682 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
683 tcg_gen_shri_i64(t, t, 32);
684 tcg_gen_trunc_i64_i32(r_tmp, t);
685 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
686 tcg_temp_free(r_tmp);
690 static inline void gen_load_fpr32h (TCGv t, int reg)
692 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
695 static inline void gen_store_fpr32h (TCGv t, int reg)
697 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
700 static inline void get_fp_cond (TCGv t)
702 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
703 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
705 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
706 tcg_gen_shri_i32(r_tmp2, r_tmp1, 24);
707 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
708 tcg_gen_shri_i32(r_tmp1, r_tmp1, 23);
709 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
710 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
711 tcg_temp_free(r_tmp1);
712 tcg_temp_free(r_tmp2);
715 #define FOP_CONDS(type, fmt) \
716 static GenOpFunc1 * fcmp ## type ## _ ## fmt ## _table[16] = { \
717 do_cmp ## type ## _ ## fmt ## _f, \
718 do_cmp ## type ## _ ## fmt ## _un, \
719 do_cmp ## type ## _ ## fmt ## _eq, \
720 do_cmp ## type ## _ ## fmt ## _ueq, \
721 do_cmp ## type ## _ ## fmt ## _olt, \
722 do_cmp ## type ## _ ## fmt ## _ult, \
723 do_cmp ## type ## _ ## fmt ## _ole, \
724 do_cmp ## type ## _ ## fmt ## _ule, \
725 do_cmp ## type ## _ ## fmt ## _sf, \
726 do_cmp ## type ## _ ## fmt ## _ngle, \
727 do_cmp ## type ## _ ## fmt ## _seq, \
728 do_cmp ## type ## _ ## fmt ## _ngl, \
729 do_cmp ## type ## _ ## fmt ## _lt, \
730 do_cmp ## type ## _ ## fmt ## _nge, \
731 do_cmp ## type ## _ ## fmt ## _le, \
732 do_cmp ## type ## _ ## fmt ## _ngt, \
734 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
736 tcg_gen_helper_0_i(fcmp ## type ## _ ## fmt ## _table[n], cc); \
748 #define OP_COND(name, cond) \
749 void glue(gen_op_, name) (TCGv t0, TCGv t1) \
751 int l1 = gen_new_label(); \
752 int l2 = gen_new_label(); \
754 tcg_gen_brcond_tl(cond, t0, t1, l1); \
755 tcg_gen_movi_tl(t0, 0); \
758 tcg_gen_movi_tl(t0, 1); \
761 OP_COND(eq, TCG_COND_EQ);
762 OP_COND(ne, TCG_COND_NE);
763 OP_COND(ge, TCG_COND_GE);
764 OP_COND(geu, TCG_COND_GEU);
765 OP_COND(lt, TCG_COND_LT);
766 OP_COND(ltu, TCG_COND_LTU);
769 #define OP_CONDI(name, cond) \
770 void glue(gen_op_, name) (TCGv t, target_ulong val) \
772 int l1 = gen_new_label(); \
773 int l2 = gen_new_label(); \
775 tcg_gen_brcondi_tl(cond, t, val, l1); \
776 tcg_gen_movi_tl(t, 0); \
779 tcg_gen_movi_tl(t, 1); \
782 OP_CONDI(lti, TCG_COND_LT);
783 OP_CONDI(ltiu, TCG_COND_LTU);
786 #define OP_CONDZ(name, cond) \
787 void glue(gen_op_, name) (TCGv t) \
789 int l1 = gen_new_label(); \
790 int l2 = gen_new_label(); \
792 tcg_gen_brcondi_tl(cond, t, 0, l1); \
793 tcg_gen_movi_tl(t, 0); \
796 tcg_gen_movi_tl(t, 1); \
799 OP_CONDZ(gez, TCG_COND_GE);
800 OP_CONDZ(gtz, TCG_COND_GT);
801 OP_CONDZ(lez, TCG_COND_LE);
802 OP_CONDZ(ltz, TCG_COND_LT);
805 static inline void gen_save_pc(target_ulong pc)
807 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
809 tcg_gen_movi_tl(r_tmp, pc);
810 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, active_tc.PC));
811 tcg_temp_free(r_tmp);
814 static inline void gen_breg_pc(void)
816 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
818 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
819 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, active_tc.PC));
820 tcg_temp_free(r_tmp);
823 static inline void gen_save_btarget(target_ulong btarget)
825 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
827 tcg_gen_movi_tl(r_tmp, btarget);
828 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
829 tcg_temp_free(r_tmp);
832 static always_inline void gen_save_breg_target(int reg)
834 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
836 gen_load_gpr(r_tmp, reg);
837 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
838 tcg_temp_free(r_tmp);
841 static always_inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
843 #if defined MIPS_DEBUG_DISAS
844 if (loglevel & CPU_LOG_TB_IN_ASM) {
845 fprintf(logfile, "hflags %08x saved %08x\n",
846 ctx->hflags, ctx->saved_hflags);
849 if (do_save_pc && ctx->pc != ctx->saved_pc) {
850 gen_save_pc(ctx->pc);
851 ctx->saved_pc = ctx->pc;
853 if (ctx->hflags != ctx->saved_hflags) {
854 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
856 tcg_gen_movi_i32(r_tmp, ctx->hflags);
857 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
858 tcg_temp_free(r_tmp);
859 ctx->saved_hflags = ctx->hflags;
860 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
866 gen_save_btarget(ctx->btarget);
872 static always_inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
874 ctx->saved_hflags = ctx->hflags;
875 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
881 ctx->btarget = env->btarget;
886 static always_inline void
887 generate_exception_err (DisasContext *ctx, int excp, int err)
889 save_cpu_state(ctx, 1);
890 tcg_gen_helper_0_ii(do_raise_exception_err, excp, err);
891 tcg_gen_helper_0_0(do_interrupt_restart);
895 static always_inline void
896 generate_exception (DisasContext *ctx, int excp)
898 save_cpu_state(ctx, 1);
899 tcg_gen_helper_0_i(do_raise_exception, excp);
900 tcg_gen_helper_0_0(do_interrupt_restart);
904 /* Addresses computation */
905 static inline void gen_op_addr_add (TCGv t0, TCGv t1)
907 tcg_gen_add_tl(t0, t0, t1);
909 #if defined(TARGET_MIPS64)
910 /* For compatibility with 32-bit code, data reference in user mode
911 with Status_UX = 0 should be casted to 32-bit and sign extended.
912 See the MIPS64 PRA manual, section 4.10. */
914 int l1 = gen_new_label();
915 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
917 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
918 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
919 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
920 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
921 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
922 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
923 tcg_temp_free(r_tmp);
924 tcg_gen_ext32s_i64(t0, t0);
930 static always_inline void check_cp0_enabled(DisasContext *ctx)
932 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
933 generate_exception_err(ctx, EXCP_CpU, 1);
936 static always_inline void check_cp1_enabled(DisasContext *ctx)
938 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
939 generate_exception_err(ctx, EXCP_CpU, 1);
942 /* Verify that the processor is running with COP1X instructions enabled.
943 This is associated with the nabla symbol in the MIPS32 and MIPS64
946 static always_inline void check_cop1x(DisasContext *ctx)
948 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
949 generate_exception(ctx, EXCP_RI);
952 /* Verify that the processor is running with 64-bit floating-point
953 operations enabled. */
955 static always_inline void check_cp1_64bitmode(DisasContext *ctx)
957 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
958 generate_exception(ctx, EXCP_RI);
962 * Verify if floating point register is valid; an operation is not defined
963 * if bit 0 of any register specification is set and the FR bit in the
964 * Status register equals zero, since the register numbers specify an
965 * even-odd pair of adjacent coprocessor general registers. When the FR bit
966 * in the Status register equals one, both even and odd register numbers
967 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
969 * Multiple 64 bit wide registers can be checked by calling
970 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
972 void check_cp1_registers(DisasContext *ctx, int regs)
974 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
975 generate_exception(ctx, EXCP_RI);
978 /* This code generates a "reserved instruction" exception if the
979 CPU does not support the instruction set corresponding to flags. */
980 static always_inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
982 if (unlikely(!(env->insn_flags & flags)))
983 generate_exception(ctx, EXCP_RI);
986 /* This code generates a "reserved instruction" exception if 64-bit
987 instructions are not enabled. */
988 static always_inline void check_mips_64(DisasContext *ctx)
990 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
991 generate_exception(ctx, EXCP_RI);
994 /* load/store instructions. */
995 #define OP_LD(insn,fname) \
996 void inline op_ldst_##insn(TCGv t0, DisasContext *ctx) \
998 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1005 #if defined(TARGET_MIPS64)
1011 #define OP_ST(insn,fname) \
1012 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1014 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1019 #if defined(TARGET_MIPS64)
1024 #define OP_LD_ATOMIC(insn,fname) \
1025 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1027 tcg_gen_mov_tl(t1, t0); \
1028 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1029 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1031 OP_LD_ATOMIC(ll,ld32s);
1032 #if defined(TARGET_MIPS64)
1033 OP_LD_ATOMIC(lld,ld64);
1037 #define OP_ST_ATOMIC(insn,fname,almask) \
1038 void inline op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1040 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1041 int l1 = gen_new_label(); \
1042 int l2 = gen_new_label(); \
1043 int l3 = gen_new_label(); \
1045 tcg_gen_andi_tl(r_tmp, t0, almask); \
1046 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1047 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1048 generate_exception(ctx, EXCP_AdES); \
1049 gen_set_label(l1); \
1050 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1051 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1052 tcg_temp_free(r_tmp); \
1053 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1054 tcg_gen_movi_tl(t0, 1); \
1056 gen_set_label(l2); \
1057 tcg_gen_movi_tl(t0, 0); \
1058 gen_set_label(l3); \
1060 OP_ST_ATOMIC(sc,st32,0x3);
1061 #if defined(TARGET_MIPS64)
1062 OP_ST_ATOMIC(scd,st64,0x7);
1066 /* Load and store */
1067 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1068 int base, int16_t offset)
1070 const char *opn = "ldst";
1071 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1072 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1075 tcg_gen_movi_tl(t0, offset);
1076 } else if (offset == 0) {
1077 gen_load_gpr(t0, base);
1079 gen_load_gpr(t0, base);
1080 tcg_gen_movi_tl(t1, offset);
1081 gen_op_addr_add(t0, t1);
1083 /* Don't do NOP if destination is zero: we must perform the actual
1086 #if defined(TARGET_MIPS64)
1088 op_ldst_lwu(t0, ctx);
1089 gen_store_gpr(t0, rt);
1093 op_ldst_ld(t0, ctx);
1094 gen_store_gpr(t0, rt);
1098 op_ldst_lld(t0, t1, ctx);
1099 gen_store_gpr(t0, rt);
1103 gen_load_gpr(t1, rt);
1104 op_ldst_sd(t0, t1, ctx);
1108 save_cpu_state(ctx, 1);
1109 gen_load_gpr(t1, rt);
1110 op_ldst_scd(t0, t1, ctx);
1111 gen_store_gpr(t0, rt);
1115 save_cpu_state(ctx, 1);
1116 gen_load_gpr(t1, rt);
1117 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1118 gen_store_gpr(t1, rt);
1122 save_cpu_state(ctx, 1);
1123 gen_load_gpr(t1, rt);
1124 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1128 save_cpu_state(ctx, 1);
1129 gen_load_gpr(t1, rt);
1130 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1131 gen_store_gpr(t1, rt);
1135 save_cpu_state(ctx, 1);
1136 gen_load_gpr(t1, rt);
1137 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1142 op_ldst_lw(t0, ctx);
1143 gen_store_gpr(t0, rt);
1147 gen_load_gpr(t1, rt);
1148 op_ldst_sw(t0, t1, ctx);
1152 op_ldst_lh(t0, ctx);
1153 gen_store_gpr(t0, rt);
1157 gen_load_gpr(t1, rt);
1158 op_ldst_sh(t0, t1, ctx);
1162 op_ldst_lhu(t0, ctx);
1163 gen_store_gpr(t0, rt);
1167 op_ldst_lb(t0, ctx);
1168 gen_store_gpr(t0, rt);
1172 gen_load_gpr(t1, rt);
1173 op_ldst_sb(t0, t1, ctx);
1177 op_ldst_lbu(t0, ctx);
1178 gen_store_gpr(t0, rt);
1182 save_cpu_state(ctx, 1);
1183 gen_load_gpr(t1, rt);
1184 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1185 gen_store_gpr(t1, rt);
1189 save_cpu_state(ctx, 1);
1190 gen_load_gpr(t1, rt);
1191 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1195 save_cpu_state(ctx, 1);
1196 gen_load_gpr(t1, rt);
1197 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1198 gen_store_gpr(t1, rt);
1202 save_cpu_state(ctx, 1);
1203 gen_load_gpr(t1, rt);
1204 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1208 op_ldst_ll(t0, t1, ctx);
1209 gen_store_gpr(t0, rt);
1213 save_cpu_state(ctx, 1);
1214 gen_load_gpr(t1, rt);
1215 op_ldst_sc(t0, t1, ctx);
1216 gen_store_gpr(t0, rt);
1221 generate_exception(ctx, EXCP_RI);
1224 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1230 /* Load and store */
1231 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1232 int base, int16_t offset)
1234 const char *opn = "flt_ldst";
1235 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1238 tcg_gen_movi_tl(t0, offset);
1239 } else if (offset == 0) {
1240 gen_load_gpr(t0, base);
1242 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1244 gen_load_gpr(t0, base);
1245 tcg_gen_movi_tl(t1, offset);
1246 gen_op_addr_add(t0, t1);
1249 /* Don't do NOP if destination is zero: we must perform the actual
1253 tcg_gen_qemu_ld32s(fpu32_T[0], t0, ctx->mem_idx);
1254 gen_store_fpr32(fpu32_T[0], ft);
1258 gen_load_fpr32(fpu32_T[0], ft);
1259 tcg_gen_qemu_st32(fpu32_T[0], t0, ctx->mem_idx);
1263 tcg_gen_qemu_ld64(fpu64_T[0], t0, ctx->mem_idx);
1264 gen_store_fpr64(ctx, fpu64_T[0], ft);
1268 gen_load_fpr64(ctx, fpu64_T[0], ft);
1269 tcg_gen_qemu_st64(fpu64_T[0], t0, ctx->mem_idx);
1274 generate_exception(ctx, EXCP_RI);
1277 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1282 /* Arithmetic with immediate operand */
1283 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1284 int rt, int rs, int16_t imm)
1287 const char *opn = "imm arith";
1288 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1290 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1291 /* If no destination, treat it as a NOP.
1292 For addi, we must generate the overflow exception when needed. */
1296 uimm = (uint16_t)imm;
1300 #if defined(TARGET_MIPS64)
1306 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1311 gen_load_gpr(t0, rs);
1314 tcg_gen_movi_tl(t0, imm << 16);
1319 #if defined(TARGET_MIPS64)
1328 gen_load_gpr(t0, rs);
1334 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1335 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1336 int l1 = gen_new_label();
1338 save_cpu_state(ctx, 1);
1339 tcg_gen_ext32s_tl(r_tmp1, t0);
1340 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1342 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1343 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1344 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1345 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1346 tcg_temp_free(r_tmp2);
1347 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1348 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1349 tcg_temp_free(r_tmp1);
1350 /* operands of same sign, result different sign */
1351 generate_exception(ctx, EXCP_OVERFLOW);
1354 tcg_gen_ext32s_tl(t0, t0);
1359 tcg_gen_ext32s_tl(t0, t0);
1360 tcg_gen_addi_tl(t0, t0, uimm);
1361 tcg_gen_ext32s_tl(t0, t0);
1364 #if defined(TARGET_MIPS64)
1367 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1368 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1369 int l1 = gen_new_label();
1371 save_cpu_state(ctx, 1);
1372 tcg_gen_mov_tl(r_tmp1, t0);
1373 tcg_gen_addi_tl(t0, t0, uimm);
1375 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1376 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1377 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1378 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1379 tcg_temp_free(r_tmp2);
1380 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1381 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1382 tcg_temp_free(r_tmp1);
1383 /* operands of same sign, result different sign */
1384 generate_exception(ctx, EXCP_OVERFLOW);
1390 tcg_gen_addi_tl(t0, t0, uimm);
1395 gen_op_lti(t0, uimm);
1399 gen_op_ltiu(t0, uimm);
1403 tcg_gen_andi_tl(t0, t0, uimm);
1407 tcg_gen_ori_tl(t0, t0, uimm);
1411 tcg_gen_xori_tl(t0, t0, uimm);
1418 tcg_gen_ext32u_tl(t0, t0);
1419 tcg_gen_shli_tl(t0, t0, uimm);
1420 tcg_gen_ext32s_tl(t0, t0);
1424 tcg_gen_ext32s_tl(t0, t0);
1425 tcg_gen_sari_tl(t0, t0, uimm);
1426 tcg_gen_ext32s_tl(t0, t0);
1430 switch ((ctx->opcode >> 21) & 0x1f) {
1432 tcg_gen_ext32u_tl(t0, t0);
1433 tcg_gen_shri_tl(t0, t0, uimm);
1434 tcg_gen_ext32s_tl(t0, t0);
1438 /* rotr is decoded as srl on non-R2 CPUs */
1439 if (env->insn_flags & ISA_MIPS32R2) {
1441 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1442 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1444 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1445 tcg_gen_movi_i32(r_tmp2, 0x20);
1446 tcg_gen_subi_i32(r_tmp2, r_tmp2, uimm);
1447 tcg_gen_shl_i32(r_tmp2, r_tmp1, r_tmp2);
1448 tcg_gen_shri_i32(r_tmp1, r_tmp1, uimm);
1449 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp2);
1450 tcg_gen_ext_i32_tl(t0, r_tmp1);
1451 tcg_temp_free(r_tmp1);
1452 tcg_temp_free(r_tmp2);
1456 tcg_gen_ext32u_tl(t0, t0);
1457 tcg_gen_shri_tl(t0, t0, uimm);
1458 tcg_gen_ext32s_tl(t0, t0);
1463 MIPS_INVAL("invalid srl flag");
1464 generate_exception(ctx, EXCP_RI);
1468 #if defined(TARGET_MIPS64)
1470 tcg_gen_shli_tl(t0, t0, uimm);
1474 tcg_gen_sari_tl(t0, t0, uimm);
1478 switch ((ctx->opcode >> 21) & 0x1f) {
1480 tcg_gen_shri_tl(t0, t0, uimm);
1484 /* drotr is decoded as dsrl on non-R2 CPUs */
1485 if (env->insn_flags & ISA_MIPS32R2) {
1487 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1489 tcg_gen_movi_tl(r_tmp1, 0x40);
1490 tcg_gen_subi_tl(r_tmp1, r_tmp1, uimm);
1491 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1492 tcg_gen_shri_tl(t0, t0, uimm);
1493 tcg_gen_or_tl(t0, t0, r_tmp1);
1494 tcg_temp_free(r_tmp1);
1498 tcg_gen_shri_tl(t0, t0, uimm);
1503 MIPS_INVAL("invalid dsrl flag");
1504 generate_exception(ctx, EXCP_RI);
1509 tcg_gen_shli_tl(t0, t0, uimm + 32);
1513 tcg_gen_sari_tl(t0, t0, uimm + 32);
1517 switch ((ctx->opcode >> 21) & 0x1f) {
1519 tcg_gen_shri_tl(t0, t0, uimm + 32);
1523 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1524 if (env->insn_flags & ISA_MIPS32R2) {
1525 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1526 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1528 tcg_gen_movi_tl(r_tmp1, 0x40);
1529 tcg_gen_movi_tl(r_tmp2, 32);
1530 tcg_gen_addi_tl(r_tmp2, r_tmp2, uimm);
1531 tcg_gen_sub_tl(r_tmp1, r_tmp1, r_tmp2);
1532 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1533 tcg_gen_shr_tl(t0, t0, r_tmp2);
1534 tcg_gen_or_tl(t0, t0, r_tmp1);
1535 tcg_temp_free(r_tmp1);
1536 tcg_temp_free(r_tmp2);
1539 tcg_gen_shri_tl(t0, t0, uimm + 32);
1544 MIPS_INVAL("invalid dsrl32 flag");
1545 generate_exception(ctx, EXCP_RI);
1552 generate_exception(ctx, EXCP_RI);
1555 gen_store_gpr(t0, rt);
1556 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1562 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1563 int rd, int rs, int rt)
1565 const char *opn = "arith";
1566 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1567 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1569 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1570 && opc != OPC_DADD && opc != OPC_DSUB) {
1571 /* If no destination, treat it as a NOP.
1572 For add & sub, we must generate the overflow exception when needed. */
1576 gen_load_gpr(t0, rs);
1577 /* Specialcase the conventional move operation. */
1578 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1579 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1580 gen_store_gpr(t0, rd);
1583 gen_load_gpr(t1, rt);
1587 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1588 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1589 int l1 = gen_new_label();
1591 save_cpu_state(ctx, 1);
1592 tcg_gen_ext32s_tl(r_tmp1, t0);
1593 tcg_gen_ext32s_tl(r_tmp2, t1);
1594 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1596 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1597 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1598 tcg_gen_xor_tl(r_tmp2, t0, t1);
1599 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1600 tcg_temp_free(r_tmp2);
1601 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1602 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1603 tcg_temp_free(r_tmp1);
1604 /* operands of same sign, result different sign */
1605 generate_exception(ctx, EXCP_OVERFLOW);
1608 tcg_gen_ext32s_tl(t0, t0);
1613 tcg_gen_ext32s_tl(t0, t0);
1614 tcg_gen_ext32s_tl(t1, t1);
1615 tcg_gen_add_tl(t0, t0, t1);
1616 tcg_gen_ext32s_tl(t0, t0);
1621 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1622 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1623 int l1 = gen_new_label();
1625 save_cpu_state(ctx, 1);
1626 tcg_gen_ext32s_tl(r_tmp1, t0);
1627 tcg_gen_ext32s_tl(r_tmp2, t1);
1628 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1630 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1631 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1632 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1633 tcg_temp_free(r_tmp2);
1634 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1635 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1636 tcg_temp_free(r_tmp1);
1637 /* operands of different sign, first operand and result different sign */
1638 generate_exception(ctx, EXCP_OVERFLOW);
1641 tcg_gen_ext32s_tl(t0, t0);
1646 tcg_gen_ext32s_tl(t0, t0);
1647 tcg_gen_ext32s_tl(t1, t1);
1648 tcg_gen_sub_tl(t0, t0, t1);
1649 tcg_gen_ext32s_tl(t0, t0);
1652 #if defined(TARGET_MIPS64)
1655 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1656 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1657 int l1 = gen_new_label();
1659 save_cpu_state(ctx, 1);
1660 tcg_gen_mov_tl(r_tmp1, t0);
1661 tcg_gen_add_tl(t0, t0, t1);
1663 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1664 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1665 tcg_gen_xor_tl(r_tmp2, t0, t1);
1666 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1667 tcg_temp_free(r_tmp2);
1668 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1669 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1670 tcg_temp_free(r_tmp1);
1671 /* operands of same sign, result different sign */
1672 generate_exception(ctx, EXCP_OVERFLOW);
1678 tcg_gen_add_tl(t0, t0, t1);
1683 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1684 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1685 int l1 = gen_new_label();
1687 save_cpu_state(ctx, 1);
1688 tcg_gen_mov_tl(r_tmp1, t0);
1689 tcg_gen_sub_tl(t0, t0, t1);
1691 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1692 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1693 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1694 tcg_temp_free(r_tmp2);
1695 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1696 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1697 tcg_temp_free(r_tmp1);
1698 /* operands of different sign, first operand and result different sign */
1699 generate_exception(ctx, EXCP_OVERFLOW);
1705 tcg_gen_sub_tl(t0, t0, t1);
1718 tcg_gen_and_tl(t0, t0, t1);
1722 tcg_gen_or_tl(t0, t0, t1);
1723 tcg_gen_not_tl(t0, t0);
1727 tcg_gen_or_tl(t0, t0, t1);
1731 tcg_gen_xor_tl(t0, t0, t1);
1735 tcg_gen_ext32s_tl(t0, t0);
1736 tcg_gen_ext32s_tl(t1, t1);
1737 tcg_gen_mul_tl(t0, t0, t1);
1738 tcg_gen_ext32s_tl(t0, t0);
1743 int l1 = gen_new_label();
1745 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1746 gen_store_gpr(t0, rd);
1753 int l1 = gen_new_label();
1755 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1756 gen_store_gpr(t0, rd);
1762 tcg_gen_ext32u_tl(t0, t0);
1763 tcg_gen_ext32u_tl(t1, t1);
1764 tcg_gen_andi_tl(t0, t0, 0x1f);
1765 tcg_gen_shl_tl(t0, t1, t0);
1766 tcg_gen_ext32s_tl(t0, t0);
1770 tcg_gen_ext32s_tl(t1, t1);
1771 tcg_gen_andi_tl(t0, t0, 0x1f);
1772 tcg_gen_sar_tl(t0, t1, t0);
1773 tcg_gen_ext32s_tl(t0, t0);
1777 switch ((ctx->opcode >> 6) & 0x1f) {
1779 tcg_gen_ext32u_tl(t1, t1);
1780 tcg_gen_andi_tl(t0, t0, 0x1f);
1781 tcg_gen_shr_tl(t0, t1, t0);
1782 tcg_gen_ext32s_tl(t0, t0);
1786 /* rotrv is decoded as srlv on non-R2 CPUs */
1787 if (env->insn_flags & ISA_MIPS32R2) {
1788 int l1 = gen_new_label();
1789 int l2 = gen_new_label();
1791 tcg_gen_andi_tl(t0, t0, 0x1f);
1792 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1794 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1795 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1796 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1798 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1799 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1800 tcg_gen_movi_i32(r_tmp3, 0x20);
1801 tcg_gen_sub_i32(r_tmp3, r_tmp3, r_tmp1);
1802 tcg_gen_shl_i32(r_tmp3, r_tmp2, r_tmp3);
1803 tcg_gen_shr_i32(r_tmp1, r_tmp2, r_tmp1);
1804 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp3);
1805 tcg_gen_ext_i32_tl(t0, r_tmp1);
1806 tcg_temp_free(r_tmp1);
1807 tcg_temp_free(r_tmp2);
1808 tcg_temp_free(r_tmp3);
1812 tcg_gen_mov_tl(t0, t1);
1816 tcg_gen_ext32u_tl(t1, t1);
1817 tcg_gen_andi_tl(t0, t0, 0x1f);
1818 tcg_gen_shr_tl(t0, t1, t0);
1819 tcg_gen_ext32s_tl(t0, t0);
1824 MIPS_INVAL("invalid srlv flag");
1825 generate_exception(ctx, EXCP_RI);
1829 #if defined(TARGET_MIPS64)
1831 tcg_gen_andi_tl(t0, t0, 0x3f);
1832 tcg_gen_shl_tl(t0, t1, t0);
1836 tcg_gen_andi_tl(t0, t0, 0x3f);
1837 tcg_gen_sar_tl(t0, t1, t0);
1841 switch ((ctx->opcode >> 6) & 0x1f) {
1843 tcg_gen_andi_tl(t0, t0, 0x3f);
1844 tcg_gen_shr_tl(t0, t1, t0);
1848 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1849 if (env->insn_flags & ISA_MIPS32R2) {
1850 int l1 = gen_new_label();
1851 int l2 = gen_new_label();
1853 tcg_gen_andi_tl(t0, t0, 0x3f);
1854 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1856 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1858 tcg_gen_movi_tl(r_tmp1, 0x40);
1859 tcg_gen_sub_tl(r_tmp1, r_tmp1, t0);
1860 tcg_gen_shl_tl(r_tmp1, t1, r_tmp1);
1861 tcg_gen_shr_tl(t0, t1, t0);
1862 tcg_gen_or_tl(t0, t0, r_tmp1);
1863 tcg_temp_free(r_tmp1);
1867 tcg_gen_mov_tl(t0, t1);
1871 tcg_gen_andi_tl(t0, t0, 0x3f);
1872 tcg_gen_shr_tl(t0, t1, t0);
1877 MIPS_INVAL("invalid dsrlv flag");
1878 generate_exception(ctx, EXCP_RI);
1885 generate_exception(ctx, EXCP_RI);
1888 gen_store_gpr(t0, rd);
1890 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1896 /* Arithmetic on HI/LO registers */
1897 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1899 const char *opn = "hilo";
1900 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1902 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1910 gen_store_gpr(t0, reg);
1915 gen_store_gpr(t0, reg);
1919 gen_load_gpr(t0, reg);
1920 gen_store_HI(t0, 0);
1924 gen_load_gpr(t0, reg);
1925 gen_store_LO(t0, 0);
1930 generate_exception(ctx, EXCP_RI);
1933 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1938 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1941 const char *opn = "mul/div";
1942 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1943 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1945 gen_load_gpr(t0, rs);
1946 gen_load_gpr(t1, rt);
1950 int l1 = gen_new_label();
1952 tcg_gen_ext32s_tl(t0, t0);
1953 tcg_gen_ext32s_tl(t1, t1);
1954 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1956 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1957 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1958 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1960 tcg_gen_ext_tl_i64(r_tmp1, t0);
1961 tcg_gen_ext_tl_i64(r_tmp2, t1);
1962 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1963 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1964 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1965 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1966 tcg_temp_free(r_tmp1);
1967 tcg_temp_free(r_tmp2);
1968 tcg_temp_free(r_tmp3);
1969 tcg_gen_ext32s_tl(t0, t0);
1970 tcg_gen_ext32s_tl(t1, t1);
1971 gen_store_LO(t0, 0);
1972 gen_store_HI(t1, 0);
1980 int l1 = gen_new_label();
1982 tcg_gen_ext32s_tl(t1, t1);
1983 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1985 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1986 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1987 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1989 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1990 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1991 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1992 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1993 tcg_gen_ext_i32_tl(t0, r_tmp3);
1994 tcg_gen_ext_i32_tl(t1, r_tmp1);
1995 tcg_temp_free(r_tmp1);
1996 tcg_temp_free(r_tmp2);
1997 tcg_temp_free(r_tmp3);
1998 gen_store_LO(t0, 0);
1999 gen_store_HI(t1, 0);
2007 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2008 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2010 tcg_gen_ext32s_tl(t0, t0);
2011 tcg_gen_ext32s_tl(t1, t1);
2012 tcg_gen_ext_tl_i64(r_tmp1, t0);
2013 tcg_gen_ext_tl_i64(r_tmp2, t1);
2014 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2015 tcg_temp_free(r_tmp2);
2016 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2017 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2018 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2019 tcg_temp_free(r_tmp1);
2020 tcg_gen_ext32s_tl(t0, t0);
2021 tcg_gen_ext32s_tl(t1, t1);
2022 gen_store_LO(t0, 0);
2023 gen_store_HI(t1, 0);
2029 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2030 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2032 tcg_gen_ext32u_tl(t0, t0);
2033 tcg_gen_ext32u_tl(t1, t1);
2034 tcg_gen_extu_tl_i64(r_tmp1, t0);
2035 tcg_gen_extu_tl_i64(r_tmp2, t1);
2036 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2037 tcg_temp_free(r_tmp2);
2038 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2039 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2040 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2041 tcg_temp_free(r_tmp1);
2042 tcg_gen_ext32s_tl(t0, t0);
2043 tcg_gen_ext32s_tl(t1, t1);
2044 gen_store_LO(t0, 0);
2045 gen_store_HI(t1, 0);
2049 #if defined(TARGET_MIPS64)
2052 int l1 = gen_new_label();
2054 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2056 int l2 = gen_new_label();
2058 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2059 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2061 tcg_gen_movi_tl(t1, 0);
2062 gen_store_LO(t0, 0);
2063 gen_store_HI(t1, 0);
2068 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2069 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2071 tcg_gen_div_i64(r_tmp1, t0, t1);
2072 tcg_gen_rem_i64(r_tmp2, t0, t1);
2073 gen_store_LO(r_tmp1, 0);
2074 gen_store_HI(r_tmp2, 0);
2075 tcg_temp_free(r_tmp1);
2076 tcg_temp_free(r_tmp2);
2085 int l1 = gen_new_label();
2087 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2089 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2090 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2092 tcg_gen_divu_i64(r_tmp1, t0, t1);
2093 tcg_gen_remu_i64(r_tmp2, t0, t1);
2094 tcg_temp_free(r_tmp1);
2095 tcg_temp_free(r_tmp2);
2096 gen_store_LO(r_tmp1, 0);
2097 gen_store_HI(r_tmp2, 0);
2104 tcg_gen_helper_0_2(do_dmult, t0, t1);
2108 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2114 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2115 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2116 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2118 tcg_gen_ext32s_tl(t0, t0);
2119 tcg_gen_ext32s_tl(t1, t1);
2120 tcg_gen_ext_tl_i64(r_tmp1, t0);
2121 tcg_gen_ext_tl_i64(r_tmp2, t1);
2122 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2125 tcg_gen_extu_tl_i64(r_tmp2, t0);
2126 tcg_gen_extu_tl_i64(r_tmp3, t1);
2127 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2128 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2129 tcg_temp_free(r_tmp3);
2130 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2131 tcg_temp_free(r_tmp2);
2132 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2133 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2134 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2135 tcg_temp_free(r_tmp1);
2136 tcg_gen_ext32s_tl(t0, t0);
2137 tcg_gen_ext32s_tl(t1, t1);
2138 gen_store_LO(t0, 0);
2139 gen_store_HI(t1, 0);
2145 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2146 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2147 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2149 tcg_gen_ext32u_tl(t0, t0);
2150 tcg_gen_ext32u_tl(t1, t1);
2151 tcg_gen_extu_tl_i64(r_tmp1, t0);
2152 tcg_gen_extu_tl_i64(r_tmp2, t1);
2153 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2156 tcg_gen_extu_tl_i64(r_tmp2, t0);
2157 tcg_gen_extu_tl_i64(r_tmp3, t1);
2158 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2159 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2160 tcg_temp_free(r_tmp3);
2161 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2162 tcg_temp_free(r_tmp2);
2163 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2164 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2165 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2166 tcg_temp_free(r_tmp1);
2167 tcg_gen_ext32s_tl(t0, t0);
2168 tcg_gen_ext32s_tl(t1, t1);
2169 gen_store_LO(t0, 0);
2170 gen_store_HI(t1, 0);
2176 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2177 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2178 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2180 tcg_gen_ext32s_tl(t0, t0);
2181 tcg_gen_ext32s_tl(t1, t1);
2182 tcg_gen_ext_tl_i64(r_tmp1, t0);
2183 tcg_gen_ext_tl_i64(r_tmp2, t1);
2184 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2187 tcg_gen_extu_tl_i64(r_tmp2, t0);
2188 tcg_gen_extu_tl_i64(r_tmp3, t1);
2189 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2190 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2191 tcg_temp_free(r_tmp3);
2192 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2193 tcg_temp_free(r_tmp2);
2194 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2195 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2196 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2197 tcg_temp_free(r_tmp1);
2198 tcg_gen_ext32s_tl(t0, t0);
2199 tcg_gen_ext32s_tl(t1, t1);
2200 gen_store_LO(t0, 0);
2201 gen_store_HI(t1, 0);
2207 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2208 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2209 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2211 tcg_gen_ext32u_tl(t0, t0);
2212 tcg_gen_ext32u_tl(t1, t1);
2213 tcg_gen_extu_tl_i64(r_tmp1, t0);
2214 tcg_gen_extu_tl_i64(r_tmp2, t1);
2215 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2218 tcg_gen_extu_tl_i64(r_tmp2, t0);
2219 tcg_gen_extu_tl_i64(r_tmp3, t1);
2220 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2221 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2222 tcg_temp_free(r_tmp3);
2223 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2224 tcg_temp_free(r_tmp2);
2225 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2226 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2227 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2228 tcg_temp_free(r_tmp1);
2229 tcg_gen_ext32s_tl(t0, t0);
2230 tcg_gen_ext32s_tl(t1, t1);
2231 gen_store_LO(t0, 0);
2232 gen_store_HI(t1, 0);
2238 generate_exception(ctx, EXCP_RI);
2241 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2247 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2248 int rd, int rs, int rt)
2250 const char *opn = "mul vr54xx";
2251 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2252 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2254 gen_load_gpr(t0, rs);
2255 gen_load_gpr(t1, rt);
2258 case OPC_VR54XX_MULS:
2259 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2262 case OPC_VR54XX_MULSU:
2263 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2266 case OPC_VR54XX_MACC:
2267 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2270 case OPC_VR54XX_MACCU:
2271 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2274 case OPC_VR54XX_MSAC:
2275 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2278 case OPC_VR54XX_MSACU:
2279 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2282 case OPC_VR54XX_MULHI:
2283 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2286 case OPC_VR54XX_MULHIU:
2287 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2290 case OPC_VR54XX_MULSHI:
2291 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2294 case OPC_VR54XX_MULSHIU:
2295 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2298 case OPC_VR54XX_MACCHI:
2299 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2302 case OPC_VR54XX_MACCHIU:
2303 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2306 case OPC_VR54XX_MSACHI:
2307 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2310 case OPC_VR54XX_MSACHIU:
2311 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2315 MIPS_INVAL("mul vr54xx");
2316 generate_exception(ctx, EXCP_RI);
2319 gen_store_gpr(t0, rd);
2320 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2327 static void gen_cl (DisasContext *ctx, uint32_t opc,
2330 const char *opn = "CLx";
2331 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2338 gen_load_gpr(t0, rs);
2341 tcg_gen_helper_1_1(do_clo, t0, t0);
2345 tcg_gen_helper_1_1(do_clz, t0, t0);
2348 #if defined(TARGET_MIPS64)
2350 tcg_gen_helper_1_1(do_dclo, t0, t0);
2354 tcg_gen_helper_1_1(do_dclz, t0, t0);
2360 generate_exception(ctx, EXCP_RI);
2363 gen_store_gpr(t0, rd);
2364 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2371 static void gen_trap (DisasContext *ctx, uint32_t opc,
2372 int rs, int rt, int16_t imm)
2375 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2376 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2379 /* Load needed operands */
2387 /* Compare two registers */
2389 gen_load_gpr(t0, rs);
2390 gen_load_gpr(t1, rt);
2400 /* Compare register to immediate */
2401 if (rs != 0 || imm != 0) {
2402 gen_load_gpr(t0, rs);
2403 tcg_gen_movi_tl(t1, (int32_t)imm);
2410 case OPC_TEQ: /* rs == rs */
2411 case OPC_TEQI: /* r0 == 0 */
2412 case OPC_TGE: /* rs >= rs */
2413 case OPC_TGEI: /* r0 >= 0 */
2414 case OPC_TGEU: /* rs >= rs unsigned */
2415 case OPC_TGEIU: /* r0 >= 0 unsigned */
2417 tcg_gen_movi_tl(t0, 1);
2419 case OPC_TLT: /* rs < rs */
2420 case OPC_TLTI: /* r0 < 0 */
2421 case OPC_TLTU: /* rs < rs unsigned */
2422 case OPC_TLTIU: /* r0 < 0 unsigned */
2423 case OPC_TNE: /* rs != rs */
2424 case OPC_TNEI: /* r0 != 0 */
2425 /* Never trap: treat as NOP. */
2429 generate_exception(ctx, EXCP_RI);
2460 generate_exception(ctx, EXCP_RI);
2464 save_cpu_state(ctx, 1);
2466 int l1 = gen_new_label();
2468 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2469 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2472 ctx->bstate = BS_STOP;
2478 static always_inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2480 TranslationBlock *tb;
2482 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2485 tcg_gen_exit_tb((long)tb + n);
2492 /* Branches (before delay slot) */
2493 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2494 int rs, int rt, int32_t offset)
2496 target_ulong btarget = -1;
2499 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2500 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2502 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2503 #ifdef MIPS_DEBUG_DISAS
2504 if (loglevel & CPU_LOG_TB_IN_ASM) {
2506 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2510 generate_exception(ctx, EXCP_RI);
2514 /* Load needed operands */
2520 /* Compare two registers */
2522 gen_load_gpr(t0, rs);
2523 gen_load_gpr(t1, rt);
2526 btarget = ctx->pc + 4 + offset;
2540 /* Compare to zero */
2542 gen_load_gpr(t0, rs);
2545 btarget = ctx->pc + 4 + offset;
2549 /* Jump to immediate */
2550 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2554 /* Jump to register */
2555 if (offset != 0 && offset != 16) {
2556 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2557 others are reserved. */
2558 MIPS_INVAL("jump hint");
2559 generate_exception(ctx, EXCP_RI);
2562 gen_save_breg_target(rs);
2565 MIPS_INVAL("branch/jump");
2566 generate_exception(ctx, EXCP_RI);
2570 /* No condition to be computed */
2572 case OPC_BEQ: /* rx == rx */
2573 case OPC_BEQL: /* rx == rx likely */
2574 case OPC_BGEZ: /* 0 >= 0 */
2575 case OPC_BGEZL: /* 0 >= 0 likely */
2576 case OPC_BLEZ: /* 0 <= 0 */
2577 case OPC_BLEZL: /* 0 <= 0 likely */
2579 ctx->hflags |= MIPS_HFLAG_B;
2580 MIPS_DEBUG("balways");
2582 case OPC_BGEZAL: /* 0 >= 0 */
2583 case OPC_BGEZALL: /* 0 >= 0 likely */
2584 /* Always take and link */
2586 ctx->hflags |= MIPS_HFLAG_B;
2587 MIPS_DEBUG("balways and link");
2589 case OPC_BNE: /* rx != rx */
2590 case OPC_BGTZ: /* 0 > 0 */
2591 case OPC_BLTZ: /* 0 < 0 */
2593 MIPS_DEBUG("bnever (NOP)");
2595 case OPC_BLTZAL: /* 0 < 0 */
2596 tcg_gen_movi_tl(t0, ctx->pc + 8);
2597 gen_store_gpr(t0, 31);
2598 MIPS_DEBUG("bnever and link");
2600 case OPC_BLTZALL: /* 0 < 0 likely */
2601 tcg_gen_movi_tl(t0, ctx->pc + 8);
2602 gen_store_gpr(t0, 31);
2603 /* Skip the instruction in the delay slot */
2604 MIPS_DEBUG("bnever, link and skip");
2607 case OPC_BNEL: /* rx != rx likely */
2608 case OPC_BGTZL: /* 0 > 0 likely */
2609 case OPC_BLTZL: /* 0 < 0 likely */
2610 /* Skip the instruction in the delay slot */
2611 MIPS_DEBUG("bnever and skip");
2615 ctx->hflags |= MIPS_HFLAG_B;
2616 MIPS_DEBUG("j " TARGET_FMT_lx, btarget);
2620 ctx->hflags |= MIPS_HFLAG_B;
2621 MIPS_DEBUG("jal " TARGET_FMT_lx, btarget);
2624 ctx->hflags |= MIPS_HFLAG_BR;
2625 MIPS_DEBUG("jr %s", regnames[rs]);
2629 ctx->hflags |= MIPS_HFLAG_BR;
2630 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2633 MIPS_INVAL("branch/jump");
2634 generate_exception(ctx, EXCP_RI);
2641 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2642 regnames[rs], regnames[rt], btarget);
2646 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2647 regnames[rs], regnames[rt], btarget);
2651 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2652 regnames[rs], regnames[rt], btarget);
2656 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2657 regnames[rs], regnames[rt], btarget);
2661 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2665 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2669 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2675 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2679 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2683 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2687 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2691 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2695 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2699 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2704 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2706 ctx->hflags |= MIPS_HFLAG_BC;
2707 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
2712 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2714 ctx->hflags |= MIPS_HFLAG_BL;
2715 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
2718 MIPS_INVAL("conditional branch/jump");
2719 generate_exception(ctx, EXCP_RI);
2723 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2724 blink, ctx->hflags, btarget);
2726 ctx->btarget = btarget;
2728 tcg_gen_movi_tl(t0, ctx->pc + 8);
2729 gen_store_gpr(t0, blink);
2737 /* special3 bitfield operations */
2738 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2739 int rs, int lsb, int msb)
2741 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2742 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2744 gen_load_gpr(t1, rs);
2749 tcg_gen_helper_1_2ii(do_ext, t0, t0, t1, lsb, msb + 1);
2751 #if defined(TARGET_MIPS64)
2755 tcg_gen_helper_1_2ii(do_dext, t0, t0, t1, lsb, msb + 1 + 32);
2760 tcg_gen_helper_1_2ii(do_dext, t0, t0, t1, lsb + 32, msb + 1);
2765 tcg_gen_helper_1_2ii(do_dext, t0, t0, t1, lsb, msb + 1);
2771 gen_load_gpr(t0, rt);
2772 tcg_gen_helper_1_2ii(do_ins, t0, t0, t1, lsb, msb - lsb + 1);
2774 #if defined(TARGET_MIPS64)
2778 gen_load_gpr(t0, rt);
2779 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1 + 32);
2784 gen_load_gpr(t0, rt);
2785 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb + 32, msb - lsb + 1);
2790 gen_load_gpr(t0, rt);
2791 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1);
2796 MIPS_INVAL("bitops");
2797 generate_exception(ctx, EXCP_RI);
2802 gen_store_gpr(t0, rt);
2807 /* CP0 (MMU and control) */
2808 #ifndef CONFIG_USER_ONLY
2809 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2811 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2813 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2814 tcg_gen_ext_i32_tl(t, r_tmp);
2815 tcg_temp_free(r_tmp);
2818 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2820 tcg_gen_ld_tl(t, cpu_env, off);
2821 tcg_gen_ext32s_tl(t, t);
2824 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2826 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2828 tcg_gen_trunc_tl_i32(r_tmp, t);
2829 tcg_gen_st_i32(r_tmp, cpu_env, off);
2830 tcg_temp_free(r_tmp);
2833 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2835 tcg_gen_ext32s_tl(t, t);
2836 tcg_gen_st_tl(t, cpu_env, off);
2839 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2841 const char *rn = "invalid";
2844 check_insn(env, ctx, ISA_MIPS32);
2850 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2854 check_insn(env, ctx, ASE_MT);
2855 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2859 check_insn(env, ctx, ASE_MT);
2860 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2864 check_insn(env, ctx, ASE_MT);
2865 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2875 tcg_gen_helper_1_0(do_mfc0_random, t0);
2879 check_insn(env, ctx, ASE_MT);
2880 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2884 check_insn(env, ctx, ASE_MT);
2885 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2889 check_insn(env, ctx, ASE_MT);
2890 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2894 check_insn(env, ctx, ASE_MT);
2895 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2899 check_insn(env, ctx, ASE_MT);
2900 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2904 check_insn(env, ctx, ASE_MT);
2905 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2906 rn = "VPEScheFBack";
2909 check_insn(env, ctx, ASE_MT);
2910 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2920 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2921 tcg_gen_ext32s_tl(t0, t0);
2925 check_insn(env, ctx, ASE_MT);
2926 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2930 check_insn(env, ctx, ASE_MT);
2931 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2935 check_insn(env, ctx, ASE_MT);
2936 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2940 check_insn(env, ctx, ASE_MT);
2941 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2945 check_insn(env, ctx, ASE_MT);
2946 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2950 check_insn(env, ctx, ASE_MT);
2951 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2955 check_insn(env, ctx, ASE_MT);
2956 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2966 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2967 tcg_gen_ext32s_tl(t0, t0);
2977 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2978 tcg_gen_ext32s_tl(t0, t0);
2982 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2983 rn = "ContextConfig";
2992 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2996 check_insn(env, ctx, ISA_MIPS32R2);
2997 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
3007 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
3011 check_insn(env, ctx, ISA_MIPS32R2);
3012 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
3016 check_insn(env, ctx, ISA_MIPS32R2);
3017 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
3021 check_insn(env, ctx, ISA_MIPS32R2);
3022 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
3026 check_insn(env, ctx, ISA_MIPS32R2);
3027 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
3031 check_insn(env, ctx, ISA_MIPS32R2);
3032 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
3042 check_insn(env, ctx, ISA_MIPS32R2);
3043 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
3053 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
3054 tcg_gen_ext32s_tl(t0, t0);
3064 tcg_gen_helper_1_0(do_mfc0_count, t0);
3067 /* 6,7 are implementation dependent */
3075 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3076 tcg_gen_ext32s_tl(t0, t0);
3086 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3089 /* 6,7 are implementation dependent */
3097 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3101 check_insn(env, ctx, ISA_MIPS32R2);
3102 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3106 check_insn(env, ctx, ISA_MIPS32R2);
3107 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3111 check_insn(env, ctx, ISA_MIPS32R2);
3112 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3122 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3132 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3133 tcg_gen_ext32s_tl(t0, t0);
3143 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3147 check_insn(env, ctx, ISA_MIPS32R2);
3148 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3158 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3162 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3166 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3170 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3173 /* 4,5 are reserved */
3174 /* 6,7 are implementation dependent */
3176 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3180 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3190 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3200 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3210 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3220 #if defined(TARGET_MIPS64)
3221 check_insn(env, ctx, ISA_MIPS3);
3222 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3223 tcg_gen_ext32s_tl(t0, t0);
3232 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3235 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3244 rn = "'Diagnostic"; /* implementation dependent */
3249 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3253 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3254 rn = "TraceControl";
3257 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3258 rn = "TraceControl2";
3261 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3262 rn = "UserTraceData";
3265 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3276 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3277 tcg_gen_ext32s_tl(t0, t0);
3287 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3288 rn = "Performance0";
3291 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3292 rn = "Performance1";
3295 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3296 rn = "Performance2";
3299 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3300 rn = "Performance3";
3303 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3304 rn = "Performance4";
3307 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3308 rn = "Performance5";
3311 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3312 rn = "Performance6";
3315 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3316 rn = "Performance7";
3341 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3348 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3361 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3368 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3378 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3379 tcg_gen_ext32s_tl(t0, t0);
3390 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3400 #if defined MIPS_DEBUG_DISAS
3401 if (loglevel & CPU_LOG_TB_IN_ASM) {
3402 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3409 #if defined MIPS_DEBUG_DISAS
3410 if (loglevel & CPU_LOG_TB_IN_ASM) {
3411 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3415 generate_exception(ctx, EXCP_RI);
3418 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3420 const char *rn = "invalid";
3423 check_insn(env, ctx, ISA_MIPS32);
3429 tcg_gen_helper_0_1(do_mtc0_index, t0);
3433 check_insn(env, ctx, ASE_MT);
3434 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3438 check_insn(env, ctx, ASE_MT);
3443 check_insn(env, ctx, ASE_MT);
3458 check_insn(env, ctx, ASE_MT);
3459 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3463 check_insn(env, ctx, ASE_MT);
3464 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3468 check_insn(env, ctx, ASE_MT);
3469 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3473 check_insn(env, ctx, ASE_MT);
3474 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3478 check_insn(env, ctx, ASE_MT);
3479 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3483 check_insn(env, ctx, ASE_MT);
3484 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3485 rn = "VPEScheFBack";
3488 check_insn(env, ctx, ASE_MT);
3489 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3499 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3503 check_insn(env, ctx, ASE_MT);
3504 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3508 check_insn(env, ctx, ASE_MT);
3509 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3513 check_insn(env, ctx, ASE_MT);
3514 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3518 check_insn(env, ctx, ASE_MT);
3519 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3523 check_insn(env, ctx, ASE_MT);
3524 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3528 check_insn(env, ctx, ASE_MT);
3529 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3533 check_insn(env, ctx, ASE_MT);
3534 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3544 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3554 tcg_gen_helper_0_1(do_mtc0_context, t0);
3558 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3559 rn = "ContextConfig";
3568 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3572 check_insn(env, ctx, ISA_MIPS32R2);
3573 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3583 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3587 check_insn(env, ctx, ISA_MIPS32R2);
3588 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3592 check_insn(env, ctx, ISA_MIPS32R2);
3593 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3597 check_insn(env, ctx, ISA_MIPS32R2);
3598 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3602 check_insn(env, ctx, ISA_MIPS32R2);
3603 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3607 check_insn(env, ctx, ISA_MIPS32R2);
3608 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3618 check_insn(env, ctx, ISA_MIPS32R2);
3619 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3633 tcg_gen_helper_0_1(do_mtc0_count, t0);
3636 /* 6,7 are implementation dependent */
3640 /* Stop translation as we may have switched the execution mode */
3641 ctx->bstate = BS_STOP;
3646 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3656 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3659 /* 6,7 are implementation dependent */
3663 /* Stop translation as we may have switched the execution mode */
3664 ctx->bstate = BS_STOP;
3669 tcg_gen_helper_0_1(do_mtc0_status, t0);
3670 /* BS_STOP isn't good enough here, hflags may have changed. */
3671 gen_save_pc(ctx->pc + 4);
3672 ctx->bstate = BS_EXCP;
3676 check_insn(env, ctx, ISA_MIPS32R2);
3677 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3678 /* Stop translation as we may have switched the execution mode */
3679 ctx->bstate = BS_STOP;
3683 check_insn(env, ctx, ISA_MIPS32R2);
3684 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3685 /* Stop translation as we may have switched the execution mode */
3686 ctx->bstate = BS_STOP;
3690 check_insn(env, ctx, ISA_MIPS32R2);
3691 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3692 /* Stop translation as we may have switched the execution mode */
3693 ctx->bstate = BS_STOP;
3703 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3709 /* Stop translation as we may have switched the execution mode */
3710 ctx->bstate = BS_STOP;
3715 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3729 check_insn(env, ctx, ISA_MIPS32R2);
3730 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3740 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3742 /* Stop translation as we may have switched the execution mode */
3743 ctx->bstate = BS_STOP;
3746 /* ignored, read only */
3750 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3752 /* Stop translation as we may have switched the execution mode */
3753 ctx->bstate = BS_STOP;
3756 /* ignored, read only */
3759 /* 4,5 are reserved */
3760 /* 6,7 are implementation dependent */
3770 rn = "Invalid config selector";
3787 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3797 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3807 #if defined(TARGET_MIPS64)
3808 check_insn(env, ctx, ISA_MIPS3);
3809 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3818 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3821 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3830 rn = "Diagnostic"; /* implementation dependent */
3835 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3836 /* BS_STOP isn't good enough here, hflags may have changed. */
3837 gen_save_pc(ctx->pc + 4);
3838 ctx->bstate = BS_EXCP;
3842 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3843 rn = "TraceControl";
3844 /* Stop translation as we may have switched the execution mode */
3845 ctx->bstate = BS_STOP;
3848 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3849 rn = "TraceControl2";
3850 /* Stop translation as we may have switched the execution mode */
3851 ctx->bstate = BS_STOP;
3854 /* Stop translation as we may have switched the execution mode */
3855 ctx->bstate = BS_STOP;
3856 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3857 rn = "UserTraceData";
3858 /* Stop translation as we may have switched the execution mode */
3859 ctx->bstate = BS_STOP;
3862 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3863 /* Stop translation as we may have switched the execution mode */
3864 ctx->bstate = BS_STOP;
3875 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3885 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3886 rn = "Performance0";
3889 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3890 rn = "Performance1";
3893 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3894 rn = "Performance2";
3897 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3898 rn = "Performance3";
3901 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3902 rn = "Performance4";
3905 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3906 rn = "Performance5";
3909 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3910 rn = "Performance6";
3913 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3914 rn = "Performance7";
3940 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3947 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3960 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3967 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
3978 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3989 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3995 /* Stop translation as we may have switched the execution mode */
3996 ctx->bstate = BS_STOP;
4001 #if defined MIPS_DEBUG_DISAS
4002 if (loglevel & CPU_LOG_TB_IN_ASM) {
4003 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4010 #if defined MIPS_DEBUG_DISAS
4011 if (loglevel & CPU_LOG_TB_IN_ASM) {
4012 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4016 generate_exception(ctx, EXCP_RI);
4019 #if defined(TARGET_MIPS64)
4020 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4022 const char *rn = "invalid";
4025 check_insn(env, ctx, ISA_MIPS64);
4031 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
4035 check_insn(env, ctx, ASE_MT);
4036 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
4040 check_insn(env, ctx, ASE_MT);
4041 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4045 check_insn(env, ctx, ASE_MT);
4046 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4056 tcg_gen_helper_1_0(do_mfc0_random, t0);
4060 check_insn(env, ctx, ASE_MT);
4061 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4065 check_insn(env, ctx, ASE_MT);
4066 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4070 check_insn(env, ctx, ASE_MT);
4071 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4075 check_insn(env, ctx, ASE_MT);
4076 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4080 check_insn(env, ctx, ASE_MT);
4081 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4085 check_insn(env, ctx, ASE_MT);
4086 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4087 rn = "VPEScheFBack";
4090 check_insn(env, ctx, ASE_MT);
4091 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4101 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4105 check_insn(env, ctx, ASE_MT);
4106 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4110 check_insn(env, ctx, ASE_MT);
4111 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4115 check_insn(env, ctx, ASE_MT);
4116 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4120 check_insn(env, ctx, ASE_MT);
4121 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4125 check_insn(env, ctx, ASE_MT);
4126 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4130 check_insn(env, ctx, ASE_MT);
4131 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4135 check_insn(env, ctx, ASE_MT);
4136 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4146 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4156 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4160 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4161 rn = "ContextConfig";
4170 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4174 check_insn(env, ctx, ISA_MIPS32R2);
4175 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4185 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4189 check_insn(env, ctx, ISA_MIPS32R2);
4190 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4194 check_insn(env, ctx, ISA_MIPS32R2);
4195 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4199 check_insn(env, ctx, ISA_MIPS32R2);
4200 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4204 check_insn(env, ctx, ISA_MIPS32R2);
4205 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4209 check_insn(env, ctx, ISA_MIPS32R2);
4210 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4220 check_insn(env, ctx, ISA_MIPS32R2);
4221 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4231 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4241 tcg_gen_helper_1_0(do_mfc0_count, t0);
4244 /* 6,7 are implementation dependent */
4252 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4262 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4265 /* 6,7 are implementation dependent */
4273 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4277 check_insn(env, ctx, ISA_MIPS32R2);
4278 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4282 check_insn(env, ctx, ISA_MIPS32R2);
4283 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4287 check_insn(env, ctx, ISA_MIPS32R2);
4288 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4298 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4308 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4318 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4322 check_insn(env, ctx, ISA_MIPS32R2);
4323 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4333 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4337 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4341 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4345 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4348 /* 6,7 are implementation dependent */
4350 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4354 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4364 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4374 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4384 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4394 check_insn(env, ctx, ISA_MIPS3);
4395 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4403 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4406 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4415 rn = "'Diagnostic"; /* implementation dependent */
4420 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4424 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4425 rn = "TraceControl";
4428 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4429 rn = "TraceControl2";
4432 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4433 rn = "UserTraceData";
4436 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4447 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4457 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4458 rn = "Performance0";
4461 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4462 rn = "Performance1";
4465 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4466 rn = "Performance2";
4469 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4470 rn = "Performance3";
4473 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4474 rn = "Performance4";
4477 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4478 rn = "Performance5";
4481 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4482 rn = "Performance6";
4485 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4486 rn = "Performance7";
4511 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4518 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4531 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4538 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4548 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4559 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4569 #if defined MIPS_DEBUG_DISAS
4570 if (loglevel & CPU_LOG_TB_IN_ASM) {
4571 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4578 #if defined MIPS_DEBUG_DISAS
4579 if (loglevel & CPU_LOG_TB_IN_ASM) {
4580 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4584 generate_exception(ctx, EXCP_RI);
4587 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4589 const char *rn = "invalid";
4592 check_insn(env, ctx, ISA_MIPS64);
4598 tcg_gen_helper_0_1(do_mtc0_index, t0);
4602 check_insn(env, ctx, ASE_MT);
4603 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4607 check_insn(env, ctx, ASE_MT);
4612 check_insn(env, ctx, ASE_MT);
4627 check_insn(env, ctx, ASE_MT);
4628 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4632 check_insn(env, ctx, ASE_MT);
4633 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4637 check_insn(env, ctx, ASE_MT);
4638 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4642 check_insn(env, ctx, ASE_MT);
4643 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4647 check_insn(env, ctx, ASE_MT);
4648 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4652 check_insn(env, ctx, ASE_MT);
4653 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4654 rn = "VPEScheFBack";
4657 check_insn(env, ctx, ASE_MT);
4658 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4668 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4672 check_insn(env, ctx, ASE_MT);
4673 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4677 check_insn(env, ctx, ASE_MT);
4678 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4682 check_insn(env, ctx, ASE_MT);
4683 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4687 check_insn(env, ctx, ASE_MT);
4688 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4692 check_insn(env, ctx, ASE_MT);
4693 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4697 check_insn(env, ctx, ASE_MT);
4698 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4702 check_insn(env, ctx, ASE_MT);
4703 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4713 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4723 tcg_gen_helper_0_1(do_mtc0_context, t0);
4727 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4728 rn = "ContextConfig";
4737 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4741 check_insn(env, ctx, ISA_MIPS32R2);
4742 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4752 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4756 check_insn(env, ctx, ISA_MIPS32R2);
4757 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4761 check_insn(env, ctx, ISA_MIPS32R2);
4762 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4766 check_insn(env, ctx, ISA_MIPS32R2);
4767 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4771 check_insn(env, ctx, ISA_MIPS32R2);
4772 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4776 check_insn(env, ctx, ISA_MIPS32R2);
4777 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4787 check_insn(env, ctx, ISA_MIPS32R2);
4788 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4802 tcg_gen_helper_0_1(do_mtc0_count, t0);
4805 /* 6,7 are implementation dependent */
4809 /* Stop translation as we may have switched the execution mode */
4810 ctx->bstate = BS_STOP;
4815 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4825 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4828 /* 6,7 are implementation dependent */
4832 /* Stop translation as we may have switched the execution mode */
4833 ctx->bstate = BS_STOP;
4838 tcg_gen_helper_0_1(do_mtc0_status, t0);
4839 /* BS_STOP isn't good enough here, hflags may have changed. */
4840 gen_save_pc(ctx->pc + 4);
4841 ctx->bstate = BS_EXCP;
4845 check_insn(env, ctx, ISA_MIPS32R2);
4846 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4847 /* Stop translation as we may have switched the execution mode */
4848 ctx->bstate = BS_STOP;
4852 check_insn(env, ctx, ISA_MIPS32R2);
4853 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4854 /* Stop translation as we may have switched the execution mode */
4855 ctx->bstate = BS_STOP;
4859 check_insn(env, ctx, ISA_MIPS32R2);
4860 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4861 /* Stop translation as we may have switched the execution mode */
4862 ctx->bstate = BS_STOP;
4872 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4878 /* Stop translation as we may have switched the execution mode */
4879 ctx->bstate = BS_STOP;
4884 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4898 check_insn(env, ctx, ISA_MIPS32R2);
4899 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4909 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4911 /* Stop translation as we may have switched the execution mode */
4912 ctx->bstate = BS_STOP;
4919 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4921 /* Stop translation as we may have switched the execution mode */
4922 ctx->bstate = BS_STOP;
4928 /* 6,7 are implementation dependent */
4930 rn = "Invalid config selector";
4947 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4957 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
4967 check_insn(env, ctx, ISA_MIPS3);
4968 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
4976 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4979 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
4988 rn = "Diagnostic"; /* implementation dependent */
4993 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
4994 /* BS_STOP isn't good enough here, hflags may have changed. */
4995 gen_save_pc(ctx->pc + 4);
4996 ctx->bstate = BS_EXCP;
5000 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
5001 /* Stop translation as we may have switched the execution mode */
5002 ctx->bstate = BS_STOP;
5003 rn = "TraceControl";
5006 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
5007 /* Stop translation as we may have switched the execution mode */
5008 ctx->bstate = BS_STOP;
5009 rn = "TraceControl2";
5012 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5013 /* Stop translation as we may have switched the execution mode */
5014 ctx->bstate = BS_STOP;
5015 rn = "UserTraceData";
5018 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5019 /* Stop translation as we may have switched the execution mode */
5020 ctx->bstate = BS_STOP;
5031 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5041 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5042 rn = "Performance0";
5045 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5046 rn = "Performance1";
5049 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5050 rn = "Performance2";
5053 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5054 rn = "Performance3";
5057 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5058 rn = "Performance4";
5061 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5062 rn = "Performance5";
5065 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5066 rn = "Performance6";
5069 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5070 rn = "Performance7";
5096 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5103 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5116 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5123 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5134 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5145 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5151 /* Stop translation as we may have switched the execution mode */
5152 ctx->bstate = BS_STOP;
5157 #if defined MIPS_DEBUG_DISAS
5158 if (loglevel & CPU_LOG_TB_IN_ASM) {
5159 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5168 #if defined MIPS_DEBUG_DISAS
5169 if (loglevel & CPU_LOG_TB_IN_ASM) {
5170 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5174 generate_exception(ctx, EXCP_RI);
5176 #endif /* TARGET_MIPS64 */
5178 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5179 int u, int sel, int h)
5181 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5182 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5184 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5185 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5186 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5187 tcg_gen_movi_tl(t0, -1);
5188 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5189 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5190 tcg_gen_movi_tl(t0, -1);
5196 tcg_gen_helper_1_1(do_mftc0_tcstatus, t0, t0);
5199 tcg_gen_helper_1_1(do_mftc0_tcbind, t0, t0);
5202 tcg_gen_helper_1_1(do_mftc0_tcrestart, t0, t0);
5205 tcg_gen_helper_1_1(do_mftc0_tchalt, t0, t0);
5208 tcg_gen_helper_1_1(do_mftc0_tccontext, t0, t0);
5211 tcg_gen_helper_1_1(do_mftc0_tcschedule, t0, t0);
5214 tcg_gen_helper_1_1(do_mftc0_tcschefback, t0, t0);
5217 gen_mfc0(env, ctx, t0, rt, sel);
5224 tcg_gen_helper_1_1(do_mftc0_entryhi, t0, t0);
5227 gen_mfc0(env, ctx, t0, rt, sel);
5233 tcg_gen_helper_1_1(do_mftc0_status, t0, t0);
5236 gen_mfc0(env, ctx, t0, rt, sel);
5242 tcg_gen_helper_1_1(do_mftc0_debug, t0, t0);
5245 gen_mfc0(env, ctx, t0, rt, sel);
5250 gen_mfc0(env, ctx, t0, rt, sel);
5252 } else switch (sel) {
5253 /* GPR registers. */
5255 tcg_gen_helper_1_1i(do_mftgpr, t0, t0, rt);
5257 /* Auxiliary CPU registers */
5261 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 0);
5264 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 0);
5267 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 0);
5270 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 1);
5273 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 1);
5276 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 1);
5279 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 2);
5282 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 2);
5285 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 2);
5288 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 3);
5291 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 3);
5294 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 3);
5297 tcg_gen_helper_1_1(do_mftdsp, t0, t0);
5303 /* Floating point (COP1). */
5305 /* XXX: For now we support only a single FPU context. */
5307 gen_load_fpr32(fpu32_T[0], rt);
5308 tcg_gen_ext_i32_tl(t0, fpu32_T[0]);
5310 gen_load_fpr32h(fpu32h_T[0], rt);
5311 tcg_gen_ext_i32_tl(t0, fpu32h_T[0]);
5315 /* XXX: For now we support only a single FPU context. */
5316 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5318 /* COP2: Not implemented. */
5325 #if defined MIPS_DEBUG_DISAS
5326 if (loglevel & CPU_LOG_TB_IN_ASM) {
5327 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5331 gen_store_gpr(t0, rd);
5337 #if defined MIPS_DEBUG_DISAS
5338 if (loglevel & CPU_LOG_TB_IN_ASM) {
5339 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5343 generate_exception(ctx, EXCP_RI);
5346 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5347 int u, int sel, int h)
5349 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5350 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5352 gen_load_gpr(t0, rt);
5353 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5354 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5355 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5357 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5358 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5365 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5368 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5371 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5374 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5377 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5380 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5383 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5386 gen_mtc0(env, ctx, t0, rd, sel);
5393 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5396 gen_mtc0(env, ctx, t0, rd, sel);
5402 tcg_gen_helper_0_1(do_mttc0_status, t0);
5405 gen_mtc0(env, ctx, t0, rd, sel);
5411 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5414 gen_mtc0(env, ctx, t0, rd, sel);
5419 gen_mtc0(env, ctx, t0, rd, sel);
5421 } else switch (sel) {
5422 /* GPR registers. */
5424 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5426 /* Auxiliary CPU registers */
5430 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5433 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5436 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5439 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5442 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5445 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5448 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5451 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5454 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5457 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5460 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5463 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5466 tcg_gen_helper_0_1(do_mttdsp, t0);
5472 /* Floating point (COP1). */
5474 /* XXX: For now we support only a single FPU context. */
5476 tcg_gen_trunc_tl_i32(fpu32_T[0], t0);
5477 gen_store_fpr32(fpu32_T[0], rd);
5479 tcg_gen_trunc_tl_i32(fpu32h_T[0], t0);
5480 gen_store_fpr32h(fpu32h_T[0], rd);
5484 /* XXX: For now we support only a single FPU context. */
5485 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5487 /* COP2: Not implemented. */
5494 #if defined MIPS_DEBUG_DISAS
5495 if (loglevel & CPU_LOG_TB_IN_ASM) {
5496 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5505 #if defined MIPS_DEBUG_DISAS
5506 if (loglevel & CPU_LOG_TB_IN_ASM) {
5507 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5511 generate_exception(ctx, EXCP_RI);
5514 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5516 const char *opn = "ldst";
5525 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5527 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5528 gen_store_gpr(t0, rt);
5535 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5537 gen_load_gpr(t0, rt);
5538 save_cpu_state(ctx, 1);
5539 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5544 #if defined(TARGET_MIPS64)
5546 check_insn(env, ctx, ISA_MIPS3);
5552 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5554 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5555 gen_store_gpr(t0, rt);
5561 check_insn(env, ctx, ISA_MIPS3);
5563 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5565 gen_load_gpr(t0, rt);
5566 save_cpu_state(ctx, 1);
5567 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5574 check_insn(env, ctx, ASE_MT);
5579 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5580 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5584 check_insn(env, ctx, ASE_MT);
5585 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5586 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5591 if (!env->tlb->do_tlbwi)
5593 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5597 if (!env->tlb->do_tlbwr)
5599 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5603 if (!env->tlb->do_tlbp)
5605 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5609 if (!env->tlb->do_tlbr)
5611 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5615 check_insn(env, ctx, ISA_MIPS2);
5616 save_cpu_state(ctx, 1);
5617 tcg_gen_helper_0_0(do_eret);
5618 ctx->bstate = BS_EXCP;
5622 check_insn(env, ctx, ISA_MIPS32);
5623 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5625 generate_exception(ctx, EXCP_RI);
5627 save_cpu_state(ctx, 1);
5628 tcg_gen_helper_0_0(do_deret);
5629 ctx->bstate = BS_EXCP;
5634 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5635 /* If we get an exception, we want to restart at next instruction */
5637 save_cpu_state(ctx, 1);
5639 tcg_gen_helper_0_0(do_wait);
5640 ctx->bstate = BS_EXCP;
5645 generate_exception(ctx, EXCP_RI);
5648 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5650 #endif /* !CONFIG_USER_ONLY */
5652 /* CP1 Branches (before delay slot) */
5653 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5654 int32_t cc, int32_t offset)
5656 target_ulong btarget;
5657 const char *opn = "cp1 cond branch";
5658 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5659 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5662 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5664 btarget = ctx->pc + 4 + offset;
5669 int l1 = gen_new_label();
5670 int l2 = gen_new_label();
5671 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5673 get_fp_cond(r_tmp1);
5674 tcg_gen_ext_i32_tl(t0, r_tmp1);
5675 tcg_temp_free(r_tmp1);
5676 tcg_gen_not_tl(t0, t0);
5677 tcg_gen_movi_tl(t1, 0x1 << cc);
5678 tcg_gen_and_tl(t0, t0, t1);
5679 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5680 tcg_gen_movi_tl(t0, 0);
5683 tcg_gen_movi_tl(t0, 1);
5690 int l1 = gen_new_label();
5691 int l2 = gen_new_label();
5692 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5694 get_fp_cond(r_tmp1);
5695 tcg_gen_ext_i32_tl(t0, r_tmp1);
5696 tcg_temp_free(r_tmp1);
5697 tcg_gen_not_tl(t0, t0);
5698 tcg_gen_movi_tl(t1, 0x1 << cc);
5699 tcg_gen_and_tl(t0, t0, t1);
5700 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5701 tcg_gen_movi_tl(t0, 0);
5704 tcg_gen_movi_tl(t0, 1);
5711 int l1 = gen_new_label();
5712 int l2 = gen_new_label();
5713 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5715 get_fp_cond(r_tmp1);
5716 tcg_gen_ext_i32_tl(t0, r_tmp1);
5717 tcg_temp_free(r_tmp1);
5718 tcg_gen_movi_tl(t1, 0x1 << cc);
5719 tcg_gen_and_tl(t0, t0, t1);
5720 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5721 tcg_gen_movi_tl(t0, 0);
5724 tcg_gen_movi_tl(t0, 1);
5731 int l1 = gen_new_label();
5732 int l2 = gen_new_label();
5733 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5735 get_fp_cond(r_tmp1);
5736 tcg_gen_ext_i32_tl(t0, r_tmp1);
5737 tcg_temp_free(r_tmp1);
5738 tcg_gen_movi_tl(t1, 0x1 << cc);
5739 tcg_gen_and_tl(t0, t0, t1);
5740 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5741 tcg_gen_movi_tl(t0, 0);
5744 tcg_gen_movi_tl(t0, 1);
5749 ctx->hflags |= MIPS_HFLAG_BL;
5750 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
5754 int l1 = gen_new_label();
5755 int l2 = gen_new_label();
5756 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5758 get_fp_cond(r_tmp1);
5759 tcg_gen_ext_i32_tl(t0, r_tmp1);
5760 tcg_temp_free(r_tmp1);
5761 tcg_gen_not_tl(t0, t0);
5762 tcg_gen_movi_tl(t1, 0x3 << cc);
5763 tcg_gen_and_tl(t0, t0, t1);
5764 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5765 tcg_gen_movi_tl(t0, 0);
5768 tcg_gen_movi_tl(t0, 1);
5775 int l1 = gen_new_label();
5776 int l2 = gen_new_label();
5777 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5779 get_fp_cond(r_tmp1);
5780 tcg_gen_ext_i32_tl(t0, r_tmp1);
5781 tcg_temp_free(r_tmp1);
5782 tcg_gen_movi_tl(t1, 0x3 << cc);
5783 tcg_gen_and_tl(t0, t0, t1);
5784 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5785 tcg_gen_movi_tl(t0, 0);
5788 tcg_gen_movi_tl(t0, 1);
5795 int l1 = gen_new_label();
5796 int l2 = gen_new_label();
5797 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5799 get_fp_cond(r_tmp1);
5800 tcg_gen_ext_i32_tl(t0, r_tmp1);
5801 tcg_temp_free(r_tmp1);
5802 tcg_gen_not_tl(t0, t0);
5803 tcg_gen_movi_tl(t1, 0xf << cc);
5804 tcg_gen_and_tl(t0, t0, t1);
5805 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5806 tcg_gen_movi_tl(t0, 0);
5809 tcg_gen_movi_tl(t0, 1);
5816 int l1 = gen_new_label();
5817 int l2 = gen_new_label();
5818 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5820 get_fp_cond(r_tmp1);
5821 tcg_gen_ext_i32_tl(t0, r_tmp1);
5822 tcg_temp_free(r_tmp1);
5823 tcg_gen_movi_tl(t1, 0xf << cc);
5824 tcg_gen_and_tl(t0, t0, t1);
5825 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5826 tcg_gen_movi_tl(t0, 0);
5829 tcg_gen_movi_tl(t0, 1);
5834 ctx->hflags |= MIPS_HFLAG_BC;
5835 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, bcond));
5839 generate_exception (ctx, EXCP_RI);
5842 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5843 ctx->hflags, btarget);
5844 ctx->btarget = btarget;
5851 /* Coprocessor 1 (FPU) */
5853 #define FOP(func, fmt) (((fmt) << 21) | (func))
5855 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5857 const char *opn = "cp1 move";
5858 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5862 gen_load_fpr32(fpu32_T[0], fs);
5863 tcg_gen_ext_i32_tl(t0, fpu32_T[0]);
5864 gen_store_gpr(t0, rt);
5868 gen_load_gpr(t0, rt);
5869 tcg_gen_trunc_tl_i32(fpu32_T[0], t0);
5870 gen_store_fpr32(fpu32_T[0], fs);
5874 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5875 gen_store_gpr(t0, rt);
5879 gen_load_gpr(t0, rt);
5880 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5884 gen_load_fpr64(ctx, fpu64_T[0], fs);
5885 tcg_gen_mov_tl(t0, fpu64_T[0]);
5886 gen_store_gpr(t0, rt);
5890 gen_load_gpr(t0, rt);
5891 tcg_gen_mov_tl(fpu64_T[0], t0);
5892 gen_store_fpr64(ctx, fpu64_T[0], fs);
5896 gen_load_fpr32h(fpu32h_T[0], fs);
5897 tcg_gen_ext_i32_tl(t0, fpu32h_T[0]);
5898 gen_store_gpr(t0, rt);
5902 gen_load_gpr(t0, rt);
5903 tcg_gen_trunc_tl_i32(fpu32h_T[0], t0);
5904 gen_store_fpr32h(fpu32h_T[0], fs);
5909 generate_exception (ctx, EXCP_RI);
5912 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5918 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5920 int l1 = gen_new_label();
5923 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5924 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5927 ccbit = 1 << (24 + cc);
5935 gen_load_gpr(t0, rd);
5936 gen_load_gpr(t1, rs);
5938 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
5939 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
5941 tcg_gen_ld_ptr(r_ptr, cpu_env, offsetof(CPUState, fpu));
5942 tcg_gen_ld_i32(r_tmp, r_ptr, offsetof(CPUMIPSFPUContext, fcr31));
5943 tcg_temp_free(r_ptr);
5944 tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
5945 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5946 tcg_temp_free(r_tmp);
5948 tcg_gen_mov_tl(t0, t1);
5952 gen_store_gpr(t0, rd);
5956 static inline void gen_movcf_s (int cc, int tf)
5960 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5961 int l1 = gen_new_label();
5964 ccbit = 1 << (24 + cc);
5973 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
5974 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
5975 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5976 tcg_gen_movi_i32(fpu32_T[2], fpu32_T[0]);
5978 tcg_temp_free(r_tmp1);
5981 static inline void gen_movcf_d (int cc, int tf)
5985 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5986 int l1 = gen_new_label();
5989 ccbit = 1 << (24 + cc);
5998 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
5999 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
6000 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6001 tcg_gen_movi_i64(fpu64_T[2], fpu64_T[0]);
6003 tcg_temp_free(r_tmp1);
6006 static inline void gen_movcf_ps (int cc, int tf)
6009 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6010 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6011 int l1 = gen_new_label();
6012 int l2 = gen_new_label();
6019 get_fp_cond(r_tmp1);
6020 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6021 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6022 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6023 tcg_gen_movi_i32(fpu32_T[2], fpu32_T[0]);
6025 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6026 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6027 tcg_gen_movi_i32(fpu32h_T[2], fpu32h_T[0]);
6029 tcg_temp_free(r_tmp1);
6030 tcg_temp_free(r_tmp2);
6034 static void gen_farith (DisasContext *ctx, uint32_t op1,
6035 int ft, int fs, int fd, int cc)
6037 const char *opn = "farith";
6038 const char *condnames[] = {
6056 const char *condnames_abs[] = {
6074 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6075 uint32_t func = ctx->opcode & 0x3f;
6077 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6079 gen_load_fpr32(fpu32_T[0], fs);
6080 gen_load_fpr32(fpu32_T[1], ft);
6081 tcg_gen_helper_0_0(do_float_add_s);
6082 gen_store_fpr32(fpu32_T[2], fd);
6087 gen_load_fpr32(fpu32_T[0], fs);
6088 gen_load_fpr32(fpu32_T[1], ft);
6089 tcg_gen_helper_0_0(do_float_sub_s);
6090 gen_store_fpr32(fpu32_T[2], fd);
6095 gen_load_fpr32(fpu32_T[0], fs);
6096 gen_load_fpr32(fpu32_T[1], ft);
6097 tcg_gen_helper_0_0(do_float_mul_s);
6098 gen_store_fpr32(fpu32_T[2], fd);
6103 gen_load_fpr32(fpu32_T[0], fs);
6104 gen_load_fpr32(fpu32_T[1], ft);
6105 tcg_gen_helper_0_0(do_float_div_s);
6106 gen_store_fpr32(fpu32_T[2], fd);
6111 gen_load_fpr32(fpu32_T[0], fs);
6112 tcg_gen_helper_0_0(do_float_sqrt_s);
6113 gen_store_fpr32(fpu32_T[2], fd);
6117 gen_load_fpr32(fpu32_T[0], fs);
6118 tcg_gen_helper_0_0(do_float_abs_s);
6119 gen_store_fpr32(fpu32_T[2], fd);
6123 gen_load_fpr32(fpu32_T[0], fs);
6124 gen_store_fpr32(fpu32_T[0], fd);
6128 gen_load_fpr32(fpu32_T[0], fs);
6129 tcg_gen_helper_0_0(do_float_chs_s);
6130 gen_store_fpr32(fpu32_T[2], fd);
6134 check_cp1_64bitmode(ctx);
6135 gen_load_fpr32(fpu32_T[0], fs);
6136 tcg_gen_helper_0_0(do_float_roundl_s);
6137 gen_store_fpr64(ctx, fpu64_T[2], fd);
6141 check_cp1_64bitmode(ctx);
6142 gen_load_fpr32(fpu32_T[0], fs);
6143 tcg_gen_helper_0_0(do_float_truncl_s);
6144 gen_store_fpr64(ctx, fpu64_T[2], fd);
6148 check_cp1_64bitmode(ctx);
6149 gen_load_fpr32(fpu32_T[0], fs);
6150 tcg_gen_helper_0_0(do_float_ceill_s);
6151 gen_store_fpr64(ctx, fpu64_T[2], fd);
6155 check_cp1_64bitmode(ctx);
6156 gen_load_fpr32(fpu32_T[0], fs);
6157 tcg_gen_helper_0_0(do_float_floorl_s);
6158 gen_store_fpr64(ctx, fpu64_T[2], fd);
6162 gen_load_fpr32(fpu32_T[0], fs);
6163 tcg_gen_helper_0_0(do_float_roundw_s);
6164 gen_store_fpr32(fpu32_T[2], fd);
6168 gen_load_fpr32(fpu32_T[0], fs);
6169 tcg_gen_helper_0_0(do_float_truncw_s);
6170 gen_store_fpr32(fpu32_T[2], fd);
6174 gen_load_fpr32(fpu32_T[0], fs);
6175 tcg_gen_helper_0_0(do_float_ceilw_s);
6176 gen_store_fpr32(fpu32_T[2], fd);
6180 gen_load_fpr32(fpu32_T[0], fs);
6181 tcg_gen_helper_0_0(do_float_floorw_s);
6182 gen_store_fpr32(fpu32_T[2], fd);
6186 gen_load_fpr32(fpu32_T[0], fs);
6187 gen_load_fpr32(fpu32_T[2], fd);
6188 gen_movcf_s((ft >> 2) & 0x7, ft & 0x1);
6189 gen_store_fpr32(fpu32_T[2], fd);
6193 gen_load_fpr32(fpu32_T[0], fs);
6194 gen_load_fpr32(fpu32_T[2], fd);
6196 int l1 = gen_new_label();
6197 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6199 gen_load_gpr(t0, ft);
6200 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6202 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6205 gen_store_fpr32(fpu32_T[2], fd);
6209 gen_load_fpr32(fpu32_T[0], fs);
6210 gen_load_fpr32(fpu32_T[2], fd);
6212 int l1 = gen_new_label();
6213 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6215 gen_load_gpr(t0, ft);
6216 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6218 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6221 gen_store_fpr32(fpu32_T[2], fd);
6226 gen_load_fpr32(fpu32_T[0], fs);
6227 tcg_gen_helper_0_0(do_float_recip_s);
6228 gen_store_fpr32(fpu32_T[2], fd);
6233 gen_load_fpr32(fpu32_T[0], fs);
6234 tcg_gen_helper_0_0(do_float_rsqrt_s);
6235 gen_store_fpr32(fpu32_T[2], fd);
6239 check_cp1_64bitmode(ctx);
6240 gen_load_fpr32(fpu32_T[0], fs);
6241 gen_load_fpr32(fpu32_T[2], fd);
6242 tcg_gen_helper_0_0(do_float_recip2_s);
6243 gen_store_fpr32(fpu32_T[2], fd);
6247 check_cp1_64bitmode(ctx);
6248 gen_load_fpr32(fpu32_T[0], fs);
6249 tcg_gen_helper_0_0(do_float_recip1_s);
6250 gen_store_fpr32(fpu32_T[2], fd);
6254 check_cp1_64bitmode(ctx);
6255 gen_load_fpr32(fpu32_T[0], fs);
6256 tcg_gen_helper_0_0(do_float_rsqrt1_s);
6257 gen_store_fpr32(fpu32_T[2], fd);
6261 check_cp1_64bitmode(ctx);
6262 gen_load_fpr32(fpu32_T[0], fs);
6263 gen_load_fpr32(fpu32_T[2], ft);
6264 tcg_gen_helper_0_0(do_float_rsqrt2_s);
6265 gen_store_fpr32(fpu32_T[2], fd);
6269 check_cp1_registers(ctx, fd);
6270 gen_load_fpr32(fpu32_T[0], fs);
6271 tcg_gen_helper_0_0(do_float_cvtd_s);
6272 gen_store_fpr64(ctx, fpu64_T[2], fd);
6276 gen_load_fpr32(fpu32_T[0], fs);
6277 tcg_gen_helper_0_0(do_float_cvtw_s);
6278 gen_store_fpr32(fpu32_T[2], fd);
6282 check_cp1_64bitmode(ctx);
6283 gen_load_fpr32(fpu32_T[0], fs);
6284 tcg_gen_helper_0_0(do_float_cvtl_s);
6285 gen_store_fpr64(ctx, fpu64_T[2], fd);
6289 check_cp1_64bitmode(ctx);
6290 gen_load_fpr32(fpu32_T[0], fs);
6291 gen_load_fpr32(fpu32_T[1], ft);
6292 tcg_gen_extu_i32_i64(fpu64_T[0], fpu32_T[0]);
6293 tcg_gen_extu_i32_i64(fpu64_T[1], fpu32_T[1]);
6294 tcg_gen_shli_i64(fpu64_T[1], fpu64_T[1], 32);
6295 tcg_gen_or_i64(fpu64_T[2], fpu64_T[0], fpu64_T[1]);
6296 gen_store_fpr64(ctx, fpu64_T[2], fd);
6315 gen_load_fpr32(fpu32_T[0], fs);
6316 gen_load_fpr32(fpu32_T[1], ft);
6317 if (ctx->opcode & (1 << 6)) {
6319 gen_cmpabs_s(func-48, cc);
6320 opn = condnames_abs[func-48];
6322 gen_cmp_s(func-48, cc);
6323 opn = condnames[func-48];
6327 check_cp1_registers(ctx, fs | ft | fd);
6328 gen_load_fpr64(ctx, fpu64_T[0], fs);
6329 gen_load_fpr64(ctx, fpu64_T[1], ft);
6330 tcg_gen_helper_0_0(do_float_add_d);
6331 gen_store_fpr64(ctx, fpu64_T[2], fd);
6336 check_cp1_registers(ctx, fs | ft | fd);
6337 gen_load_fpr64(ctx, fpu64_T[0], fs);
6338 gen_load_fpr64(ctx, fpu64_T[1], ft);
6339 tcg_gen_helper_0_0(do_float_sub_d);
6340 gen_store_fpr64(ctx, fpu64_T[2], fd);
6345 check_cp1_registers(ctx, fs | ft | fd);
6346 gen_load_fpr64(ctx, fpu64_T[0], fs);
6347 gen_load_fpr64(ctx, fpu64_T[1], ft);
6348 tcg_gen_helper_0_0(do_float_mul_d);
6349 gen_store_fpr64(ctx, fpu64_T[2], fd);
6354 check_cp1_registers(ctx, fs | ft | fd);
6355 gen_load_fpr64(ctx, fpu64_T[0], fs);
6356 gen_load_fpr64(ctx, fpu64_T[1], ft);
6357 tcg_gen_helper_0_0(do_float_div_d);
6358 gen_store_fpr64(ctx, fpu64_T[2], fd);
6363 check_cp1_registers(ctx, fs | fd);
6364 gen_load_fpr64(ctx, fpu64_T[0], fs);
6365 tcg_gen_helper_0_0(do_float_sqrt_d);
6366 gen_store_fpr64(ctx, fpu64_T[2], fd);
6370 check_cp1_registers(ctx, fs | fd);
6371 gen_load_fpr64(ctx, fpu64_T[0], fs);
6372 tcg_gen_helper_0_0(do_float_abs_d);
6373 gen_store_fpr64(ctx, fpu64_T[2], fd);
6377 check_cp1_registers(ctx, fs | fd);
6378 gen_load_fpr64(ctx, fpu64_T[0], fs);
6379 gen_store_fpr64(ctx, fpu64_T[0], fd);
6383 check_cp1_registers(ctx, fs | fd);
6384 gen_load_fpr64(ctx, fpu64_T[0], fs);
6385 tcg_gen_helper_0_0(do_float_chs_d);
6386 gen_store_fpr64(ctx, fpu64_T[2], fd);
6390 check_cp1_64bitmode(ctx);
6391 gen_load_fpr64(ctx, fpu64_T[0], fs);
6392 tcg_gen_helper_0_0(do_float_roundl_d);
6393 gen_store_fpr64(ctx, fpu64_T[2], fd);
6397 check_cp1_64bitmode(ctx);
6398 gen_load_fpr64(ctx, fpu64_T[0], fs);
6399 tcg_gen_helper_0_0(do_float_truncl_d);
6400 gen_store_fpr64(ctx, fpu64_T[2], fd);
6404 check_cp1_64bitmode(ctx);
6405 gen_load_fpr64(ctx, fpu64_T[0], fs);
6406 tcg_gen_helper_0_0(do_float_ceill_d);
6407 gen_store_fpr64(ctx, fpu64_T[2], fd);
6411 check_cp1_64bitmode(ctx);
6412 gen_load_fpr64(ctx, fpu64_T[0], fs);
6413 tcg_gen_helper_0_0(do_float_floorl_d);
6414 gen_store_fpr64(ctx, fpu64_T[2], fd);
6418 check_cp1_registers(ctx, fs);
6419 gen_load_fpr64(ctx, fpu64_T[0], fs);
6420 tcg_gen_helper_0_0(do_float_roundw_d);
6421 gen_store_fpr32(fpu32_T[2], fd);
6425 check_cp1_registers(ctx, fs);
6426 gen_load_fpr64(ctx, fpu64_T[0], fs);
6427 tcg_gen_helper_0_0(do_float_truncw_d);
6428 gen_store_fpr32(fpu32_T[2], fd);
6432 check_cp1_registers(ctx, fs);
6433 gen_load_fpr64(ctx, fpu64_T[0], fs);
6434 tcg_gen_helper_0_0(do_float_ceilw_d);
6435 gen_store_fpr32(fpu32_T[2], fd);
6439 check_cp1_registers(ctx, fs);
6440 gen_load_fpr64(ctx, fpu64_T[0], fs);
6441 tcg_gen_helper_0_0(do_float_floorw_d);
6442 gen_store_fpr32(fpu32_T[2], fd);
6446 gen_load_fpr64(ctx, fpu64_T[0], fs);
6447 gen_load_fpr64(ctx, fpu64_T[2], fd);
6448 gen_movcf_d((ft >> 2) & 0x7, ft & 0x1);
6449 gen_store_fpr64(ctx, fpu64_T[2], fd);
6453 gen_load_fpr64(ctx, fpu64_T[0], fs);
6454 gen_load_fpr64(ctx, fpu64_T[2], fd);
6456 int l1 = gen_new_label();
6457 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6459 gen_load_gpr(t0, ft);
6460 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6462 tcg_gen_mov_i64(fpu64_T[2], fpu64_T[0]);
6465 gen_store_fpr64(ctx, fpu64_T[2], fd);
6469 gen_load_fpr64(ctx, fpu64_T[0], fs);
6470 gen_load_fpr64(ctx, fpu64_T[2], fd);
6472 int l1 = gen_new_label();
6473 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6475 gen_load_gpr(t0, ft);
6476 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6478 tcg_gen_mov_i64(fpu64_T[2], fpu64_T[0]);
6481 gen_store_fpr64(ctx, fpu64_T[2], fd);
6485 check_cp1_64bitmode(ctx);
6486 gen_load_fpr64(ctx, fpu64_T[0], fs);
6487 tcg_gen_helper_0_0(do_float_recip_d);
6488 gen_store_fpr64(ctx, fpu64_T[2], fd);
6492 check_cp1_64bitmode(ctx);
6493 gen_load_fpr64(ctx, fpu64_T[0], fs);
6494 tcg_gen_helper_0_0(do_float_rsqrt_d);
6495 gen_store_fpr64(ctx, fpu64_T[2], fd);
6499 check_cp1_64bitmode(ctx);
6500 gen_load_fpr64(ctx, fpu64_T[0], fs);
6501 gen_load_fpr64(ctx, fpu64_T[2], ft);
6502 tcg_gen_helper_0_0(do_float_recip2_d);
6503 gen_store_fpr64(ctx, fpu64_T[2], fd);
6507 check_cp1_64bitmode(ctx);
6508 gen_load_fpr64(ctx, fpu64_T[0], fs);
6509 tcg_gen_helper_0_0(do_float_recip1_d);
6510 gen_store_fpr64(ctx, fpu64_T[2], fd);
6514 check_cp1_64bitmode(ctx);
6515 gen_load_fpr64(ctx, fpu64_T[0], fs);
6516 tcg_gen_helper_0_0(do_float_rsqrt1_d);
6517 gen_store_fpr64(ctx, fpu64_T[2], fd);
6521 check_cp1_64bitmode(ctx);
6522 gen_load_fpr64(ctx, fpu64_T[0], fs);
6523 gen_load_fpr64(ctx, fpu64_T[2], ft);
6524 tcg_gen_helper_0_0(do_float_rsqrt2_d);
6525 gen_store_fpr64(ctx, fpu64_T[2], fd);
6544 gen_load_fpr64(ctx, fpu64_T[0], fs);
6545 gen_load_fpr64(ctx, fpu64_T[1], ft);
6546 if (ctx->opcode & (1 << 6)) {
6548 check_cp1_registers(ctx, fs | ft);
6549 gen_cmpabs_d(func-48, cc);
6550 opn = condnames_abs[func-48];
6552 check_cp1_registers(ctx, fs | ft);
6553 gen_cmp_d(func-48, cc);
6554 opn = condnames[func-48];
6558 check_cp1_registers(ctx, fs);
6559 gen_load_fpr64(ctx, fpu64_T[0], fs);
6560 tcg_gen_helper_0_0(do_float_cvts_d);
6561 gen_store_fpr32(fpu32_T[2], fd);
6565 check_cp1_registers(ctx, fs);
6566 gen_load_fpr64(ctx, fpu64_T[0], fs);
6567 tcg_gen_helper_0_0(do_float_cvtw_d);
6568 gen_store_fpr32(fpu32_T[2], fd);
6572 check_cp1_64bitmode(ctx);
6573 gen_load_fpr64(ctx, fpu64_T[0], fs);
6574 tcg_gen_helper_0_0(do_float_cvtl_d);
6575 gen_store_fpr64(ctx, fpu64_T[2], fd);
6579 gen_load_fpr32(fpu32_T[0], fs);
6580 tcg_gen_helper_0_0(do_float_cvts_w);
6581 gen_store_fpr32(fpu32_T[2], fd);
6585 check_cp1_registers(ctx, fd);
6586 gen_load_fpr32(fpu32_T[0], fs);
6587 tcg_gen_helper_0_0(do_float_cvtd_w);
6588 gen_store_fpr64(ctx, fpu64_T[2], fd);
6592 check_cp1_64bitmode(ctx);
6593 gen_load_fpr64(ctx, fpu64_T[0], fs);
6594 tcg_gen_helper_0_0(do_float_cvts_l);
6595 gen_store_fpr32(fpu32_T[2], fd);
6599 check_cp1_64bitmode(ctx);
6600 gen_load_fpr64(ctx, fpu64_T[0], fs);
6601 tcg_gen_helper_0_0(do_float_cvtd_l);
6602 gen_store_fpr64(ctx, fpu64_T[2], fd);
6606 check_cp1_64bitmode(ctx);
6607 gen_load_fpr32(fpu32_T[0], fs);
6608 gen_load_fpr32h(fpu32h_T[0], fs);
6609 tcg_gen_helper_0_0(do_float_cvtps_pw);
6610 gen_store_fpr32(fpu32_T[2], fd);
6611 gen_store_fpr32h(fpu32h_T[2], fd);
6615 check_cp1_64bitmode(ctx);
6616 gen_load_fpr32(fpu32_T[0], fs);
6617 gen_load_fpr32h(fpu32h_T[0], fs);
6618 gen_load_fpr32(fpu32_T[1], ft);
6619 gen_load_fpr32h(fpu32h_T[1], ft);
6620 tcg_gen_helper_0_0(do_float_add_ps);
6621 gen_store_fpr32(fpu32_T[2], fd);
6622 gen_store_fpr32h(fpu32h_T[2], fd);
6626 check_cp1_64bitmode(ctx);
6627 gen_load_fpr32(fpu32_T[0], fs);
6628 gen_load_fpr32h(fpu32h_T[0], fs);
6629 gen_load_fpr32(fpu32_T[1], ft);
6630 gen_load_fpr32h(fpu32h_T[1], ft);
6631 tcg_gen_helper_0_0(do_float_sub_ps);
6632 gen_store_fpr32(fpu32_T[2], fd);
6633 gen_store_fpr32h(fpu32h_T[2], fd);
6637 check_cp1_64bitmode(ctx);
6638 gen_load_fpr32(fpu32_T[0], fs);
6639 gen_load_fpr32h(fpu32h_T[0], fs);
6640 gen_load_fpr32(fpu32_T[1], ft);
6641 gen_load_fpr32h(fpu32h_T[1], ft);
6642 tcg_gen_helper_0_0(do_float_mul_ps);
6643 gen_store_fpr32(fpu32_T[2], fd);
6644 gen_store_fpr32h(fpu32h_T[2], fd);
6648 check_cp1_64bitmode(ctx);
6649 gen_load_fpr32(fpu32_T[0], fs);
6650 gen_load_fpr32h(fpu32h_T[0], fs);
6651 tcg_gen_helper_0_0(do_float_abs_ps);
6652 gen_store_fpr32(fpu32_T[2], fd);
6653 gen_store_fpr32h(fpu32h_T[2], fd);
6657 check_cp1_64bitmode(ctx);
6658 gen_load_fpr32(fpu32_T[0], fs);
6659 gen_load_fpr32h(fpu32h_T[0], fs);
6660 gen_store_fpr32(fpu32_T[0], fd);
6661 gen_store_fpr32h(fpu32h_T[0], fd);
6665 check_cp1_64bitmode(ctx);
6666 gen_load_fpr32(fpu32_T[0], fs);
6667 gen_load_fpr32h(fpu32h_T[0], fs);
6668 tcg_gen_helper_0_0(do_float_chs_ps);
6669 gen_store_fpr32(fpu32_T[2], fd);
6670 gen_store_fpr32h(fpu32h_T[2], fd);
6674 check_cp1_64bitmode(ctx);
6675 gen_load_fpr32(fpu32_T[0], fs);
6676 gen_load_fpr32h(fpu32h_T[0], fs);
6677 gen_load_fpr32(fpu32_T[2], fd);
6678 gen_load_fpr32h(fpu32h_T[2], fd);
6679 gen_movcf_ps((ft >> 2) & 0x7, ft & 0x1);
6680 gen_store_fpr32(fpu32_T[2], fd);
6681 gen_store_fpr32h(fpu32h_T[2], fd);
6685 check_cp1_64bitmode(ctx);
6686 gen_load_fpr32(fpu32_T[0], fs);
6687 gen_load_fpr32h(fpu32h_T[0], fs);
6688 gen_load_fpr32(fpu32_T[2], fd);
6689 gen_load_fpr32h(fpu32h_T[2], fd);
6691 int l1 = gen_new_label();
6692 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6694 gen_load_gpr(t0, ft);
6695 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6697 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6698 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
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);
6712 int l1 = gen_new_label();
6713 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6715 gen_load_gpr(t0, ft);
6716 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6718 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6719 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
6722 gen_store_fpr32(fpu32_T[2], fd);
6723 gen_store_fpr32h(fpu32h_T[2], fd);
6727 check_cp1_64bitmode(ctx);
6728 gen_load_fpr32(fpu32_T[0], ft);
6729 gen_load_fpr32h(fpu32h_T[0], ft);
6730 gen_load_fpr32(fpu32_T[1], fs);
6731 gen_load_fpr32h(fpu32h_T[1], fs);
6732 tcg_gen_helper_0_0(do_float_addr_ps);
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], ft);
6740 gen_load_fpr32h(fpu32h_T[0], ft);
6741 gen_load_fpr32(fpu32_T[1], fs);
6742 gen_load_fpr32h(fpu32h_T[1], fs);
6743 tcg_gen_helper_0_0(do_float_mulr_ps);
6744 gen_store_fpr32(fpu32_T[2], fd);
6745 gen_store_fpr32h(fpu32h_T[2], fd);
6749 check_cp1_64bitmode(ctx);
6750 gen_load_fpr32(fpu32_T[0], fs);
6751 gen_load_fpr32h(fpu32h_T[0], fs);
6752 gen_load_fpr32(fpu32_T[2], fd);
6753 gen_load_fpr32h(fpu32h_T[2], fd);
6754 tcg_gen_helper_0_0(do_float_recip2_ps);
6755 gen_store_fpr32(fpu32_T[2], fd);
6756 gen_store_fpr32h(fpu32h_T[2], fd);
6760 check_cp1_64bitmode(ctx);
6761 gen_load_fpr32(fpu32_T[0], fs);
6762 gen_load_fpr32h(fpu32h_T[0], fs);
6763 tcg_gen_helper_0_0(do_float_recip1_ps);
6764 gen_store_fpr32(fpu32_T[2], fd);
6765 gen_store_fpr32h(fpu32h_T[2], fd);
6769 check_cp1_64bitmode(ctx);
6770 gen_load_fpr32(fpu32_T[0], fs);
6771 gen_load_fpr32h(fpu32h_T[0], fs);
6772 tcg_gen_helper_0_0(do_float_rsqrt1_ps);
6773 gen_store_fpr32(fpu32_T[2], fd);
6774 gen_store_fpr32h(fpu32h_T[2], fd);
6778 check_cp1_64bitmode(ctx);
6779 gen_load_fpr32(fpu32_T[0], fs);
6780 gen_load_fpr32h(fpu32h_T[0], fs);
6781 gen_load_fpr32(fpu32_T[2], ft);
6782 gen_load_fpr32h(fpu32h_T[2], ft);
6783 tcg_gen_helper_0_0(do_float_rsqrt2_ps);
6784 gen_store_fpr32(fpu32_T[2], fd);
6785 gen_store_fpr32h(fpu32h_T[2], fd);
6789 check_cp1_64bitmode(ctx);
6790 gen_load_fpr32h(fpu32h_T[0], fs);
6791 tcg_gen_helper_0_0(do_float_cvts_pu);
6792 gen_store_fpr32(fpu32_T[2], fd);
6796 check_cp1_64bitmode(ctx);
6797 gen_load_fpr32(fpu32_T[0], fs);
6798 gen_load_fpr32h(fpu32h_T[0], fs);
6799 tcg_gen_helper_0_0(do_float_cvtpw_ps);
6800 gen_store_fpr32(fpu32_T[2], fd);
6801 gen_store_fpr32h(fpu32h_T[2], fd);
6805 check_cp1_64bitmode(ctx);
6806 gen_load_fpr32(fpu32_T[0], fs);
6807 tcg_gen_helper_0_0(do_float_cvts_pl);
6808 gen_store_fpr32(fpu32_T[2], fd);
6812 check_cp1_64bitmode(ctx);
6813 gen_load_fpr32(fpu32_T[0], fs);
6814 gen_load_fpr32(fpu32_T[1], ft);
6815 gen_store_fpr32h(fpu32_T[0], fd);
6816 gen_store_fpr32(fpu32_T[1], fd);
6820 check_cp1_64bitmode(ctx);
6821 gen_load_fpr32(fpu32_T[0], fs);
6822 gen_load_fpr32h(fpu32h_T[1], ft);
6823 gen_store_fpr32(fpu32h_T[1], fd);
6824 gen_store_fpr32h(fpu32_T[0], fd);
6828 check_cp1_64bitmode(ctx);
6829 gen_load_fpr32h(fpu32h_T[0], fs);
6830 gen_load_fpr32(fpu32_T[1], ft);
6831 gen_store_fpr32(fpu32_T[1], fd);
6832 gen_store_fpr32h(fpu32h_T[0], fd);
6836 check_cp1_64bitmode(ctx);
6837 gen_load_fpr32h(fpu32h_T[0], fs);
6838 gen_load_fpr32h(fpu32h_T[1], ft);
6839 gen_store_fpr32(fpu32h_T[1], fd);
6840 gen_store_fpr32h(fpu32h_T[0], fd);
6859 check_cp1_64bitmode(ctx);
6860 gen_load_fpr32(fpu32_T[0], fs);
6861 gen_load_fpr32h(fpu32h_T[0], fs);
6862 gen_load_fpr32(fpu32_T[1], ft);
6863 gen_load_fpr32h(fpu32h_T[1], ft);
6864 if (ctx->opcode & (1 << 6)) {
6865 gen_cmpabs_ps(func-48, cc);
6866 opn = condnames_abs[func-48];
6868 gen_cmp_ps(func-48, cc);
6869 opn = condnames[func-48];
6874 generate_exception (ctx, EXCP_RI);
6879 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
6882 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
6885 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
6890 /* Coprocessor 3 (FPU) */
6891 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
6892 int fd, int fs, int base, int index)
6894 const char *opn = "extended float load/store";
6896 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6897 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
6900 gen_load_gpr(t0, index);
6901 } else if (index == 0) {
6902 gen_load_gpr(t0, base);
6904 gen_load_gpr(t0, base);
6905 gen_load_gpr(t1, index);
6906 gen_op_addr_add(t0, t1);
6908 /* Don't do NOP if destination is zero: we must perform the actual
6913 tcg_gen_qemu_ld32s(fpu32_T[0], t0, ctx->mem_idx);
6914 gen_store_fpr32(fpu32_T[0], fd);
6919 check_cp1_registers(ctx, fd);
6920 tcg_gen_qemu_ld64(fpu64_T[0], t0, ctx->mem_idx);
6921 gen_store_fpr64(ctx, fpu64_T[0], fd);
6925 check_cp1_64bitmode(ctx);
6926 tcg_gen_andi_tl(t0, t0, ~0x7);
6927 tcg_gen_qemu_ld64(fpu64_T[0], t0, ctx->mem_idx);
6928 gen_store_fpr64(ctx, fpu64_T[0], fd);
6933 gen_load_fpr32(fpu32_T[0], fs);
6934 tcg_gen_qemu_st32(fpu32_T[0], t0, ctx->mem_idx);
6940 check_cp1_registers(ctx, fs);
6941 gen_load_fpr64(ctx, fpu64_T[0], fs);
6942 tcg_gen_qemu_st64(fpu64_T[0], t0, ctx->mem_idx);
6947 check_cp1_64bitmode(ctx);
6948 gen_load_fpr64(ctx, fpu64_T[0], fs);
6949 tcg_gen_andi_tl(t0, t0, ~0x7);
6950 tcg_gen_qemu_st64(fpu64_T[0], t0, ctx->mem_idx);
6956 generate_exception(ctx, EXCP_RI);
6963 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
6964 regnames[index], regnames[base]);
6967 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
6968 int fd, int fr, int fs, int ft)
6970 const char *opn = "flt3_arith";
6974 check_cp1_64bitmode(ctx);
6976 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6977 int l1 = gen_new_label();
6978 int l2 = gen_new_label();
6980 gen_load_gpr(t0, fr);
6981 tcg_gen_andi_tl(t0, t0, 0x7);
6982 gen_load_fpr32(fpu32_T[0], fs);
6983 gen_load_fpr32h(fpu32h_T[0], fs);
6984 gen_load_fpr32(fpu32_T[1], ft);
6985 gen_load_fpr32h(fpu32h_T[1], ft);
6987 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6988 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6989 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
6992 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
6994 #ifdef TARGET_WORDS_BIGENDIAN
6995 tcg_gen_mov_i32(fpu32h_T[2], fpu32_T[0]);
6996 tcg_gen_mov_i32(fpu32_T[2], fpu32h_T[1]);
6998 tcg_gen_mov_i32(fpu32h_T[2], fpu32_T[1]);
6999 tcg_gen_mov_i32(fpu32_T[2], fpu32h_T[0]);
7003 gen_store_fpr32(fpu32_T[2], fd);
7004 gen_store_fpr32h(fpu32h_T[2], fd);
7009 gen_load_fpr32(fpu32_T[0], fs);
7010 gen_load_fpr32(fpu32_T[1], ft);
7011 gen_load_fpr32(fpu32_T[2], fr);
7012 tcg_gen_helper_0_0(do_float_muladd_s);
7013 gen_store_fpr32(fpu32_T[2], fd);
7018 check_cp1_registers(ctx, fd | fs | ft | fr);
7019 gen_load_fpr64(ctx, fpu64_T[0], fs);
7020 gen_load_fpr64(ctx, fpu64_T[1], ft);
7021 gen_load_fpr64(ctx, fpu64_T[2], fr);
7022 tcg_gen_helper_0_0(do_float_muladd_d);
7023 gen_store_fpr64(ctx, fpu64_T[2], fd);
7027 check_cp1_64bitmode(ctx);
7028 gen_load_fpr32(fpu32_T[0], fs);
7029 gen_load_fpr32h(fpu32h_T[0], fs);
7030 gen_load_fpr32(fpu32_T[1], ft);
7031 gen_load_fpr32h(fpu32h_T[1], ft);
7032 gen_load_fpr32(fpu32_T[2], fr);
7033 gen_load_fpr32h(fpu32h_T[2], fr);
7034 tcg_gen_helper_0_0(do_float_muladd_ps);
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_mulsub_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_mulsub_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_mulsub_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_nmuladd_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_nmuladd_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_nmuladd_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_nmulsub_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_nmulsub_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_nmulsub_ps);
7131 gen_store_fpr32(fpu32_T[2], fd);
7132 gen_store_fpr32h(fpu32h_T[2], fd);
7137 generate_exception (ctx, EXCP_RI);
7140 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7141 fregnames[fs], fregnames[ft]);
7144 /* ISA extensions (ASEs) */
7145 /* MIPS16 extension to MIPS32 */
7146 /* SmartMIPS extension to MIPS32 */
7148 #if defined(TARGET_MIPS64)
7150 /* MDMX extension to MIPS64 */
7154 static void decode_opc (CPUState *env, DisasContext *ctx)
7158 uint32_t op, op1, op2;
7161 /* make sure instructions are on a word boundary */
7162 if (ctx->pc & 0x3) {
7163 env->CP0_BadVAddr = ctx->pc;
7164 generate_exception(ctx, EXCP_AdEL);
7168 /* Handle blikely not taken case */
7169 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7170 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL);
7171 int l1 = gen_new_label();
7173 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7174 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
7175 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
7176 tcg_temp_free(r_tmp);
7178 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
7180 tcg_gen_movi_i32(r_tmp2, ctx->hflags & ~MIPS_HFLAG_BMASK);
7181 tcg_gen_st_i32(r_tmp2, cpu_env, offsetof(CPUState, hflags));
7182 tcg_temp_free(r_tmp2);
7184 gen_goto_tb(ctx, 1, ctx->pc + 4);
7187 op = MASK_OP_MAJOR(ctx->opcode);
7188 rs = (ctx->opcode >> 21) & 0x1f;
7189 rt = (ctx->opcode >> 16) & 0x1f;
7190 rd = (ctx->opcode >> 11) & 0x1f;
7191 sa = (ctx->opcode >> 6) & 0x1f;
7192 imm = (int16_t)ctx->opcode;
7195 op1 = MASK_SPECIAL(ctx->opcode);
7197 case OPC_SLL: /* Arithmetic with immediate */
7198 case OPC_SRL ... OPC_SRA:
7199 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7201 case OPC_MOVZ ... OPC_MOVN:
7202 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7203 case OPC_SLLV: /* Arithmetic */
7204 case OPC_SRLV ... OPC_SRAV:
7205 case OPC_ADD ... OPC_NOR:
7206 case OPC_SLT ... OPC_SLTU:
7207 gen_arith(env, ctx, op1, rd, rs, rt);
7209 case OPC_MULT ... OPC_DIVU:
7211 check_insn(env, ctx, INSN_VR54XX);
7212 op1 = MASK_MUL_VR54XX(ctx->opcode);
7213 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7215 gen_muldiv(ctx, op1, rs, rt);
7217 case OPC_JR ... OPC_JALR:
7218 gen_compute_branch(ctx, op1, rs, rd, sa);
7220 case OPC_TGE ... OPC_TEQ: /* Traps */
7222 gen_trap(ctx, op1, rs, rt, -1);
7224 case OPC_MFHI: /* Move from HI/LO */
7226 gen_HILO(ctx, op1, rd);
7229 case OPC_MTLO: /* Move to HI/LO */
7230 gen_HILO(ctx, op1, rs);
7232 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7233 #ifdef MIPS_STRICT_STANDARD
7234 MIPS_INVAL("PMON / selsl");
7235 generate_exception(ctx, EXCP_RI);
7237 tcg_gen_helper_0_i(do_pmon, sa);
7241 generate_exception(ctx, EXCP_SYSCALL);
7244 generate_exception(ctx, EXCP_BREAK);
7247 #ifdef MIPS_STRICT_STANDARD
7249 generate_exception(ctx, EXCP_RI);
7251 /* Implemented as RI exception for now. */
7252 MIPS_INVAL("spim (unofficial)");
7253 generate_exception(ctx, EXCP_RI);
7261 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7262 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7263 save_cpu_state(ctx, 1);
7264 check_cp1_enabled(ctx);
7265 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7266 (ctx->opcode >> 16) & 1);
7268 generate_exception_err(ctx, EXCP_CpU, 1);
7272 #if defined(TARGET_MIPS64)
7273 /* MIPS64 specific opcodes */
7275 case OPC_DSRL ... OPC_DSRA:
7277 case OPC_DSRL32 ... OPC_DSRA32:
7278 check_insn(env, ctx, ISA_MIPS3);
7280 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7283 case OPC_DSRLV ... OPC_DSRAV:
7284 case OPC_DADD ... OPC_DSUBU:
7285 check_insn(env, ctx, ISA_MIPS3);
7287 gen_arith(env, ctx, op1, rd, rs, rt);
7289 case OPC_DMULT ... OPC_DDIVU:
7290 check_insn(env, ctx, ISA_MIPS3);
7292 gen_muldiv(ctx, op1, rs, rt);
7295 default: /* Invalid */
7296 MIPS_INVAL("special");
7297 generate_exception(ctx, EXCP_RI);
7302 op1 = MASK_SPECIAL2(ctx->opcode);
7304 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7305 case OPC_MSUB ... OPC_MSUBU:
7306 check_insn(env, ctx, ISA_MIPS32);
7307 gen_muldiv(ctx, op1, rs, rt);
7310 gen_arith(env, ctx, op1, rd, rs, rt);
7312 case OPC_CLZ ... OPC_CLO:
7313 check_insn(env, ctx, ISA_MIPS32);
7314 gen_cl(ctx, op1, rd, rs);
7317 /* XXX: not clear which exception should be raised
7318 * when in debug mode...
7320 check_insn(env, ctx, ISA_MIPS32);
7321 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7322 generate_exception(ctx, EXCP_DBp);
7324 generate_exception(ctx, EXCP_DBp);
7328 #if defined(TARGET_MIPS64)
7329 case OPC_DCLZ ... OPC_DCLO:
7330 check_insn(env, ctx, ISA_MIPS64);
7332 gen_cl(ctx, op1, rd, rs);
7335 default: /* Invalid */
7336 MIPS_INVAL("special2");
7337 generate_exception(ctx, EXCP_RI);
7342 op1 = MASK_SPECIAL3(ctx->opcode);
7346 check_insn(env, ctx, ISA_MIPS32R2);
7347 gen_bitops(ctx, op1, rt, rs, sa, rd);
7350 check_insn(env, ctx, ISA_MIPS32R2);
7351 op2 = MASK_BSHFL(ctx->opcode);
7353 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7354 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7358 gen_load_gpr(t1, rt);
7359 tcg_gen_helper_1_2(do_wsbh, t0, t0, t1);
7360 gen_store_gpr(t0, rd);
7363 gen_load_gpr(t1, rt);
7364 tcg_gen_ext8s_tl(t0, t1);
7365 gen_store_gpr(t0, rd);
7368 gen_load_gpr(t1, rt);
7369 tcg_gen_ext16s_tl(t0, t1);
7370 gen_store_gpr(t0, rd);
7372 default: /* Invalid */
7373 MIPS_INVAL("bshfl");
7374 generate_exception(ctx, EXCP_RI);
7382 check_insn(env, ctx, ISA_MIPS32R2);
7384 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7388 save_cpu_state(ctx, 1);
7389 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
7392 save_cpu_state(ctx, 1);
7393 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
7396 save_cpu_state(ctx, 1);
7397 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
7400 save_cpu_state(ctx, 1);
7401 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
7404 #if defined (CONFIG_USER_ONLY)
7405 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7408 /* XXX: Some CPUs implement this in hardware. Not supported yet. */
7410 default: /* Invalid */
7411 MIPS_INVAL("rdhwr");
7412 generate_exception(ctx, EXCP_RI);
7415 gen_store_gpr(t0, rt);
7420 check_insn(env, ctx, ASE_MT);
7422 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7423 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7425 gen_load_gpr(t0, rt);
7426 gen_load_gpr(t1, rs);
7427 tcg_gen_helper_0_2(do_fork, t0, t1);
7433 check_insn(env, ctx, ASE_MT);
7435 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7437 gen_load_gpr(t0, rs);
7438 tcg_gen_helper_1_1(do_yield, t0, t0);
7439 gen_store_gpr(t0, rd);
7443 #if defined(TARGET_MIPS64)
7444 case OPC_DEXTM ... OPC_DEXT:
7445 case OPC_DINSM ... OPC_DINS:
7446 check_insn(env, ctx, ISA_MIPS64R2);
7448 gen_bitops(ctx, op1, rt, rs, sa, rd);
7451 check_insn(env, ctx, ISA_MIPS64R2);
7453 op2 = MASK_DBSHFL(ctx->opcode);
7455 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7456 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7460 gen_load_gpr(t1, rt);
7461 tcg_gen_helper_1_2(do_dsbh, t0, t0, t1);
7464 gen_load_gpr(t1, rt);
7465 tcg_gen_helper_1_2(do_dshd, t0, t0, t1);
7467 default: /* Invalid */
7468 MIPS_INVAL("dbshfl");
7469 generate_exception(ctx, EXCP_RI);
7472 gen_store_gpr(t0, rd);
7478 default: /* Invalid */
7479 MIPS_INVAL("special3");
7480 generate_exception(ctx, EXCP_RI);
7485 op1 = MASK_REGIMM(ctx->opcode);
7487 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7488 case OPC_BLTZAL ... OPC_BGEZALL:
7489 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7491 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7493 gen_trap(ctx, op1, rs, -1, imm);
7496 check_insn(env, ctx, ISA_MIPS32R2);
7499 default: /* Invalid */
7500 MIPS_INVAL("regimm");
7501 generate_exception(ctx, EXCP_RI);
7506 check_cp0_enabled(ctx);
7507 op1 = MASK_CP0(ctx->opcode);
7513 #if defined(TARGET_MIPS64)
7517 #ifndef CONFIG_USER_ONLY
7518 gen_cp0(env, ctx, op1, rt, rd);
7521 case OPC_C0_FIRST ... OPC_C0_LAST:
7522 #ifndef CONFIG_USER_ONLY
7523 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7527 op2 = MASK_MFMC0(ctx->opcode);
7529 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7533 check_insn(env, ctx, ASE_MT);
7534 tcg_gen_helper_1_1(do_dmt, t0, t0);
7537 check_insn(env, ctx, ASE_MT);
7538 tcg_gen_helper_1_1(do_emt, t0, t0);
7541 check_insn(env, ctx, ASE_MT);
7542 tcg_gen_helper_1_1(do_dvpe, t0, t0);
7545 check_insn(env, ctx, ASE_MT);
7546 tcg_gen_helper_1_1(do_evpe, t0, t0);
7549 check_insn(env, ctx, ISA_MIPS32R2);
7550 save_cpu_state(ctx, 1);
7551 tcg_gen_helper_1_0(do_di, t0);
7552 /* Stop translation as we may have switched the execution mode */
7553 ctx->bstate = BS_STOP;
7556 check_insn(env, ctx, ISA_MIPS32R2);
7557 save_cpu_state(ctx, 1);
7558 tcg_gen_helper_1_0(do_ei, t0);
7559 /* Stop translation as we may have switched the execution mode */
7560 ctx->bstate = BS_STOP;
7562 default: /* Invalid */
7563 MIPS_INVAL("mfmc0");
7564 generate_exception(ctx, EXCP_RI);
7567 gen_store_gpr(t0, rt);
7572 check_insn(env, ctx, ISA_MIPS32R2);
7573 gen_load_srsgpr(rt, rd);
7576 check_insn(env, ctx, ISA_MIPS32R2);
7577 gen_store_srsgpr(rt, rd);
7581 generate_exception(ctx, EXCP_RI);
7585 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7586 gen_arith_imm(env, ctx, op, rt, rs, imm);
7588 case OPC_J ... OPC_JAL: /* Jump */
7589 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7590 gen_compute_branch(ctx, op, rs, rt, offset);
7592 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7593 case OPC_BEQL ... OPC_BGTZL:
7594 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7596 case OPC_LB ... OPC_LWR: /* Load and stores */
7597 case OPC_SB ... OPC_SW:
7601 gen_ldst(ctx, op, rt, rs, imm);
7604 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7608 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7612 /* Floating point (COP1). */
7617 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7618 save_cpu_state(ctx, 1);
7619 check_cp1_enabled(ctx);
7620 gen_flt_ldst(ctx, op, rt, rs, imm);
7622 generate_exception_err(ctx, EXCP_CpU, 1);
7627 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7628 save_cpu_state(ctx, 1);
7629 check_cp1_enabled(ctx);
7630 op1 = MASK_CP1(ctx->opcode);
7634 check_insn(env, ctx, ISA_MIPS32R2);
7639 gen_cp1(ctx, op1, rt, rd);
7641 #if defined(TARGET_MIPS64)
7644 check_insn(env, ctx, ISA_MIPS3);
7645 gen_cp1(ctx, op1, rt, rd);
7651 check_insn(env, ctx, ASE_MIPS3D);
7654 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
7655 (rt >> 2) & 0x7, imm << 2);
7662 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
7667 generate_exception (ctx, EXCP_RI);
7671 generate_exception_err(ctx, EXCP_CpU, 1);
7681 /* COP2: Not implemented. */
7682 generate_exception_err(ctx, EXCP_CpU, 2);
7686 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7687 save_cpu_state(ctx, 1);
7688 check_cp1_enabled(ctx);
7689 op1 = MASK_CP3(ctx->opcode);
7697 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
7715 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
7719 generate_exception (ctx, EXCP_RI);
7723 generate_exception_err(ctx, EXCP_CpU, 1);
7727 #if defined(TARGET_MIPS64)
7728 /* MIPS64 opcodes */
7730 case OPC_LDL ... OPC_LDR:
7731 case OPC_SDL ... OPC_SDR:
7736 check_insn(env, ctx, ISA_MIPS3);
7738 gen_ldst(ctx, op, rt, rs, imm);
7740 case OPC_DADDI ... OPC_DADDIU:
7741 check_insn(env, ctx, ISA_MIPS3);
7743 gen_arith_imm(env, ctx, op, rt, rs, imm);
7747 check_insn(env, ctx, ASE_MIPS16);
7748 /* MIPS16: Not implemented. */
7750 check_insn(env, ctx, ASE_MDMX);
7751 /* MDMX: Not implemented. */
7752 default: /* Invalid */
7753 MIPS_INVAL("major opcode");
7754 generate_exception(ctx, EXCP_RI);
7757 if (ctx->hflags & MIPS_HFLAG_BMASK) {
7758 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
7759 /* Branches completion */
7760 ctx->hflags &= ~MIPS_HFLAG_BMASK;
7761 ctx->bstate = BS_BRANCH;
7762 save_cpu_state(ctx, 0);
7765 /* unconditional branch */
7766 MIPS_DEBUG("unconditional branch");
7767 gen_goto_tb(ctx, 0, ctx->btarget);
7770 /* blikely taken case */
7771 MIPS_DEBUG("blikely branch taken");
7772 gen_goto_tb(ctx, 0, ctx->btarget);
7775 /* Conditional branch */
7776 MIPS_DEBUG("conditional branch");
7778 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL);
7779 int l1 = gen_new_label();
7781 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
7782 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
7783 tcg_temp_free(r_tmp);
7784 gen_goto_tb(ctx, 1, ctx->pc + 4);
7786 gen_goto_tb(ctx, 0, ctx->btarget);
7790 /* unconditional branch to register */
7791 MIPS_DEBUG("branch to register");
7796 MIPS_DEBUG("unknown branch");
7802 static always_inline int
7803 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
7807 target_ulong pc_start;
7808 uint16_t *gen_opc_end;
7811 if (search_pc && loglevel)
7812 fprintf (logfile, "search pc %d\n", search_pc);
7815 /* Leave some spare opc slots for branch handling. */
7816 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
7820 ctx.bstate = BS_NONE;
7821 /* Restore delay slot state from the tb context. */
7822 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
7823 restore_cpu_state(env, &ctx);
7824 #if defined(CONFIG_USER_ONLY)
7825 ctx.mem_idx = MIPS_HFLAG_UM;
7827 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
7830 if (loglevel & CPU_LOG_TB_CPU) {
7831 fprintf(logfile, "------------------------------------------------\n");
7832 /* FIXME: This may print out stale hflags from env... */
7833 cpu_dump_state(env, logfile, fprintf, 0);
7836 #ifdef MIPS_DEBUG_DISAS
7837 if (loglevel & CPU_LOG_TB_IN_ASM)
7838 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
7839 tb, ctx.mem_idx, ctx.hflags);
7841 while (ctx.bstate == BS_NONE) {
7842 if (env->nb_breakpoints > 0) {
7843 for(j = 0; j < env->nb_breakpoints; j++) {
7844 if (env->breakpoints[j] == ctx.pc) {
7845 save_cpu_state(&ctx, 1);
7846 ctx.bstate = BS_BRANCH;
7847 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
7848 /* Include the breakpoint location or the tb won't
7849 * be flushed when it must be. */
7851 goto done_generating;
7857 j = gen_opc_ptr - gen_opc_buf;
7861 gen_opc_instr_start[lj++] = 0;
7863 gen_opc_pc[lj] = ctx.pc;
7864 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
7865 gen_opc_instr_start[lj] = 1;
7867 ctx.opcode = ldl_code(ctx.pc);
7868 decode_opc(env, &ctx);
7871 if (env->singlestep_enabled)
7874 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
7877 if (gen_opc_ptr >= gen_opc_end)
7880 if (gen_opc_ptr >= gen_opc_end)
7883 #if defined (MIPS_SINGLE_STEP)
7887 if (env->singlestep_enabled) {
7888 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
7889 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
7891 switch (ctx.bstate) {
7893 tcg_gen_helper_0_0(do_interrupt_restart);
7894 gen_goto_tb(&ctx, 0, ctx.pc);
7897 save_cpu_state(&ctx, 0);
7898 gen_goto_tb(&ctx, 0, ctx.pc);
7901 tcg_gen_helper_0_0(do_interrupt_restart);
7910 *gen_opc_ptr = INDEX_op_end;
7912 j = gen_opc_ptr - gen_opc_buf;
7915 gen_opc_instr_start[lj++] = 0;
7917 tb->size = ctx.pc - pc_start;
7920 #if defined MIPS_DEBUG_DISAS
7921 if (loglevel & CPU_LOG_TB_IN_ASM)
7922 fprintf(logfile, "\n");
7924 if (loglevel & CPU_LOG_TB_IN_ASM) {
7925 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
7926 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
7927 fprintf(logfile, "\n");
7929 if (loglevel & CPU_LOG_TB_CPU) {
7930 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
7937 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
7939 return gen_intermediate_code_internal(env, tb, 0);
7942 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
7944 return gen_intermediate_code_internal(env, tb, 1);
7947 void fpu_dump_state(CPUState *env, FILE *f,
7948 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
7952 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
7954 #define printfpr(fp) \
7957 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7958 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7959 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7962 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7963 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7964 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7965 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7966 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7971 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7972 env->fpu->fcr0, env->fpu->fcr31, is_fpu64, env->fpu->fp_status,
7973 get_float_exception_flags(&env->fpu->fp_status));
7974 fpu_fprintf(f, "FT0: "); printfpr(&env->ft0);
7975 fpu_fprintf(f, "FT1: "); printfpr(&env->ft1);
7976 fpu_fprintf(f, "FT2: "); printfpr(&env->ft2);
7977 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
7978 fpu_fprintf(f, "%3s: ", fregnames[i]);
7979 printfpr(&env->fpu->fpr[i]);
7985 void dump_fpu (CPUState *env)
7989 "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx
7990 " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx
7992 env->active_tc.PC, env->active_tc.HI[0],
7993 env->active_tc.LO[0], env->hflags, env->btarget,
7995 fpu_dump_state(env, logfile, fprintf, 0);
7999 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8000 /* Debug help: The architecture requires 32bit code to maintain proper
8001 sign-extened values on 64bit machines. */
8003 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8005 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8006 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8011 if (!SIGN_EXT_P(env->active_tc.PC))
8012 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8013 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8014 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8015 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8016 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8017 if (!SIGN_EXT_P(env->btarget))
8018 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8020 for (i = 0; i < 32; i++) {
8021 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8022 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8025 if (!SIGN_EXT_P(env->CP0_EPC))
8026 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8027 if (!SIGN_EXT_P(env->CP0_LLAddr))
8028 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8032 void cpu_dump_state (CPUState *env, FILE *f,
8033 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8038 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",
8039 env->active_tc.PC, env->active_tc.HI, env->active_tc.LO, env->hflags, env->btarget, env->bcond);
8040 for (i = 0; i < 32; i++) {
8042 cpu_fprintf(f, "GPR%02d:", i);
8043 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8045 cpu_fprintf(f, "\n");
8048 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8049 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8050 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8051 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8052 if (env->hflags & MIPS_HFLAG_FPU)
8053 fpu_dump_state(env, f, cpu_fprintf, flags);
8054 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8055 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8059 static void mips_tcg_init(void)
8063 /* Initialize various static tables. */
8067 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8068 current_fpu = tcg_global_mem_new(TCG_TYPE_PTR,
8070 offsetof(CPUState, fpu),
8073 /* register helpers */
8075 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8078 fpu32_T[0] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft0.w[FP_ENDIAN_IDX]), "WT0");
8079 fpu32_T[1] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft1.w[FP_ENDIAN_IDX]), "WT1");
8080 fpu32_T[2] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft2.w[FP_ENDIAN_IDX]), "WT2");
8081 fpu64_T[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft0.d), "DT0");
8082 fpu64_T[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft1.d), "DT1");
8083 fpu64_T[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft2.d), "DT2");
8084 fpu32h_T[0] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft0.w[!FP_ENDIAN_IDX]), "WTH0");
8085 fpu32h_T[1] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft1.w[!FP_ENDIAN_IDX]), "WTH1");
8086 fpu32h_T[2] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft2.w[!FP_ENDIAN_IDX]), "WTH2");
8091 #include "translate_init.c"
8093 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8096 const mips_def_t *def;
8098 def = cpu_mips_find_by_name(cpu_model);
8101 env = qemu_mallocz(sizeof(CPUMIPSState));
8104 env->cpu_model = def;
8107 env->cpu_model_str = cpu_model;
8113 void cpu_reset (CPUMIPSState *env)
8115 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8120 #if !defined(CONFIG_USER_ONLY)
8121 if (env->hflags & MIPS_HFLAG_BMASK) {
8122 /* If the exception was raised from a delay slot,
8123 * come back to the jump. */
8124 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8126 env->CP0_ErrorEPC = env->active_tc.PC;
8128 env->active_tc.PC = (int32_t)0xBFC00000;
8130 /* SMP not implemented */
8131 env->CP0_EBase = 0x80000000;
8132 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8133 /* vectored interrupts not implemented, timer on int 7,
8134 no performance counters. */
8135 env->CP0_IntCtl = 0xe0000000;
8139 for (i = 0; i < 7; i++) {
8140 env->CP0_WatchLo[i] = 0;
8141 env->CP0_WatchHi[i] = 0x80000000;
8143 env->CP0_WatchLo[7] = 0;
8144 env->CP0_WatchHi[7] = 0;
8146 /* Count register increments in debug mode, EJTAG version 1 */
8147 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8149 env->exception_index = EXCP_NONE;
8150 #if defined(CONFIG_USER_ONLY)
8151 env->hflags = MIPS_HFLAG_UM;
8152 env->user_mode_only = 1;
8154 env->hflags = MIPS_HFLAG_CP0;
8156 cpu_mips_register(env, env->cpu_model);
8159 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8160 unsigned long searched_pc, int pc_pos, void *puc)
8162 env->active_tc.PC = gen_opc_pc[pc_pos];
8163 env->hflags &= ~MIPS_HFLAG_BMASK;
8164 env->hflags |= gen_opc_hflags[pc_pos];