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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
41 //#define MIPS_SINGLE_STEP
43 /* MIPS major opcodes */
44 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
47 /* indirect opcode tables */
48 OPC_SPECIAL = (0x00 << 26),
49 OPC_REGIMM = (0x01 << 26),
50 OPC_CP0 = (0x10 << 26),
51 OPC_CP1 = (0x11 << 26),
52 OPC_CP2 = (0x12 << 26),
53 OPC_CP3 = (0x13 << 26),
54 OPC_SPECIAL2 = (0x1C << 26),
55 OPC_SPECIAL3 = (0x1F << 26),
56 /* arithmetic with immediate */
57 OPC_ADDI = (0x08 << 26),
58 OPC_ADDIU = (0x09 << 26),
59 OPC_SLTI = (0x0A << 26),
60 OPC_SLTIU = (0x0B << 26),
61 OPC_ANDI = (0x0C << 26),
62 OPC_ORI = (0x0D << 26),
63 OPC_XORI = (0x0E << 26),
64 OPC_LUI = (0x0F << 26),
65 OPC_DADDI = (0x18 << 26),
66 OPC_DADDIU = (0x19 << 26),
67 /* Jump and branches */
69 OPC_JAL = (0x03 << 26),
70 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
71 OPC_BEQL = (0x14 << 26),
72 OPC_BNE = (0x05 << 26),
73 OPC_BNEL = (0x15 << 26),
74 OPC_BLEZ = (0x06 << 26),
75 OPC_BLEZL = (0x16 << 26),
76 OPC_BGTZ = (0x07 << 26),
77 OPC_BGTZL = (0x17 << 26),
78 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
80 OPC_LDL = (0x1A << 26),
81 OPC_LDR = (0x1B << 26),
82 OPC_LB = (0x20 << 26),
83 OPC_LH = (0x21 << 26),
84 OPC_LWL = (0x22 << 26),
85 OPC_LW = (0x23 << 26),
86 OPC_LBU = (0x24 << 26),
87 OPC_LHU = (0x25 << 26),
88 OPC_LWR = (0x26 << 26),
89 OPC_LWU = (0x27 << 26),
90 OPC_SB = (0x28 << 26),
91 OPC_SH = (0x29 << 26),
92 OPC_SWL = (0x2A << 26),
93 OPC_SW = (0x2B << 26),
94 OPC_SDL = (0x2C << 26),
95 OPC_SDR = (0x2D << 26),
96 OPC_SWR = (0x2E << 26),
97 OPC_LL = (0x30 << 26),
98 OPC_LLD = (0x34 << 26),
99 OPC_LD = (0x37 << 26),
100 OPC_SC = (0x38 << 26),
101 OPC_SCD = (0x3C << 26),
102 OPC_SD = (0x3F << 26),
103 /* Floating point load/store */
104 OPC_LWC1 = (0x31 << 26),
105 OPC_LWC2 = (0x32 << 26),
106 OPC_LDC1 = (0x35 << 26),
107 OPC_LDC2 = (0x36 << 26),
108 OPC_SWC1 = (0x39 << 26),
109 OPC_SWC2 = (0x3A << 26),
110 OPC_SDC1 = (0x3D << 26),
111 OPC_SDC2 = (0x3E << 26),
112 /* MDMX ASE specific */
113 OPC_MDMX = (0x1E << 26),
114 /* Cache and prefetch */
115 OPC_CACHE = (0x2F << 26),
116 OPC_PREF = (0x33 << 26),
117 /* Reserved major opcode */
118 OPC_MAJOR3B_RESERVED = (0x3B << 26),
121 /* MIPS special opcodes */
122 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
126 OPC_SLL = 0x00 | OPC_SPECIAL,
127 /* NOP is SLL r0, r0, 0 */
128 /* SSNOP is SLL r0, r0, 1 */
129 /* EHB is SLL r0, r0, 3 */
130 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
131 OPC_SRA = 0x03 | OPC_SPECIAL,
132 OPC_SLLV = 0x04 | OPC_SPECIAL,
133 OPC_SRLV = 0x06 | OPC_SPECIAL, /* also ROTRV */
134 OPC_SRAV = 0x07 | OPC_SPECIAL,
135 OPC_DSLLV = 0x14 | OPC_SPECIAL,
136 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
137 OPC_DSRAV = 0x17 | OPC_SPECIAL,
138 OPC_DSLL = 0x38 | OPC_SPECIAL,
139 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
140 OPC_DSRA = 0x3B | OPC_SPECIAL,
141 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
142 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
143 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
144 /* Multiplication / division */
145 OPC_MULT = 0x18 | OPC_SPECIAL,
146 OPC_MULTU = 0x19 | OPC_SPECIAL,
147 OPC_DIV = 0x1A | OPC_SPECIAL,
148 OPC_DIVU = 0x1B | OPC_SPECIAL,
149 OPC_DMULT = 0x1C | OPC_SPECIAL,
150 OPC_DMULTU = 0x1D | OPC_SPECIAL,
151 OPC_DDIV = 0x1E | OPC_SPECIAL,
152 OPC_DDIVU = 0x1F | OPC_SPECIAL,
153 /* 2 registers arithmetic / logic */
154 OPC_ADD = 0x20 | OPC_SPECIAL,
155 OPC_ADDU = 0x21 | OPC_SPECIAL,
156 OPC_SUB = 0x22 | OPC_SPECIAL,
157 OPC_SUBU = 0x23 | OPC_SPECIAL,
158 OPC_AND = 0x24 | OPC_SPECIAL,
159 OPC_OR = 0x25 | OPC_SPECIAL,
160 OPC_XOR = 0x26 | OPC_SPECIAL,
161 OPC_NOR = 0x27 | OPC_SPECIAL,
162 OPC_SLT = 0x2A | OPC_SPECIAL,
163 OPC_SLTU = 0x2B | OPC_SPECIAL,
164 OPC_DADD = 0x2C | OPC_SPECIAL,
165 OPC_DADDU = 0x2D | OPC_SPECIAL,
166 OPC_DSUB = 0x2E | OPC_SPECIAL,
167 OPC_DSUBU = 0x2F | OPC_SPECIAL,
169 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
170 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
172 OPC_TGE = 0x30 | OPC_SPECIAL,
173 OPC_TGEU = 0x31 | OPC_SPECIAL,
174 OPC_TLT = 0x32 | OPC_SPECIAL,
175 OPC_TLTU = 0x33 | OPC_SPECIAL,
176 OPC_TEQ = 0x34 | OPC_SPECIAL,
177 OPC_TNE = 0x36 | OPC_SPECIAL,
178 /* HI / LO registers load & stores */
179 OPC_MFHI = 0x10 | OPC_SPECIAL,
180 OPC_MTHI = 0x11 | OPC_SPECIAL,
181 OPC_MFLO = 0x12 | OPC_SPECIAL,
182 OPC_MTLO = 0x13 | OPC_SPECIAL,
183 /* Conditional moves */
184 OPC_MOVZ = 0x0A | OPC_SPECIAL,
185 OPC_MOVN = 0x0B | OPC_SPECIAL,
187 OPC_MOVCI = 0x01 | OPC_SPECIAL,
190 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
191 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
192 OPC_BREAK = 0x0D | OPC_SPECIAL,
193 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
194 OPC_SYNC = 0x0F | OPC_SPECIAL,
196 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
197 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
198 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
199 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
200 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
201 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
202 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
205 /* Multiplication variants of the vr54xx. */
206 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
209 OPC_VR54XX_MULS = (0x03 << 6) | OPC_MULT,
210 OPC_VR54XX_MULSU = (0x03 << 6) | OPC_MULTU,
211 OPC_VR54XX_MACC = (0x05 << 6) | OPC_MULT,
212 OPC_VR54XX_MACCU = (0x05 << 6) | OPC_MULTU,
213 OPC_VR54XX_MSAC = (0x07 << 6) | OPC_MULT,
214 OPC_VR54XX_MSACU = (0x07 << 6) | OPC_MULTU,
215 OPC_VR54XX_MULHI = (0x09 << 6) | OPC_MULT,
216 OPC_VR54XX_MULHIU = (0x09 << 6) | OPC_MULTU,
217 OPC_VR54XX_MULSHI = (0x0B << 6) | OPC_MULT,
218 OPC_VR54XX_MULSHIU = (0x0B << 6) | OPC_MULTU,
219 OPC_VR54XX_MACCHI = (0x0D << 6) | OPC_MULT,
220 OPC_VR54XX_MACCHIU = (0x0D << 6) | OPC_MULTU,
221 OPC_VR54XX_MSACHI = (0x0F << 6) | OPC_MULT,
222 OPC_VR54XX_MSACHIU = (0x0F << 6) | OPC_MULTU,
225 /* REGIMM (rt field) opcodes */
226 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
229 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
230 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
231 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
232 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
233 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
234 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
235 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
236 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
237 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
238 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
239 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
240 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
241 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
242 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
243 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
246 /* Special2 opcodes */
247 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
250 /* Multiply & xxx operations */
251 OPC_MADD = 0x00 | OPC_SPECIAL2,
252 OPC_MADDU = 0x01 | OPC_SPECIAL2,
253 OPC_MUL = 0x02 | OPC_SPECIAL2,
254 OPC_MSUB = 0x04 | OPC_SPECIAL2,
255 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
257 OPC_CLZ = 0x20 | OPC_SPECIAL2,
258 OPC_CLO = 0x21 | OPC_SPECIAL2,
259 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
260 OPC_DCLO = 0x25 | OPC_SPECIAL2,
262 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
265 /* Special3 opcodes */
266 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
269 OPC_EXT = 0x00 | OPC_SPECIAL3,
270 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
271 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
272 OPC_DEXT = 0x03 | OPC_SPECIAL3,
273 OPC_INS = 0x04 | OPC_SPECIAL3,
274 OPC_DINSM = 0x05 | OPC_SPECIAL3,
275 OPC_DINSU = 0x06 | OPC_SPECIAL3,
276 OPC_DINS = 0x07 | OPC_SPECIAL3,
277 OPC_FORK = 0x08 | OPC_SPECIAL3,
278 OPC_YIELD = 0x09 | OPC_SPECIAL3,
279 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
280 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
281 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
285 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
288 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
289 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
290 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
294 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
297 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
298 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
301 /* Coprocessor 0 (rs field) */
302 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
305 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
306 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
307 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
308 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
309 OPC_MFTR = (0x08 << 21) | OPC_CP0,
310 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
311 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
312 OPC_MTTR = (0x0C << 21) | OPC_CP0,
313 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
314 OPC_C0 = (0x10 << 21) | OPC_CP0,
315 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
316 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
320 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
323 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
324 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
325 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
326 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
327 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
328 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
331 /* Coprocessor 0 (with rs == C0) */
332 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
335 OPC_TLBR = 0x01 | OPC_C0,
336 OPC_TLBWI = 0x02 | OPC_C0,
337 OPC_TLBWR = 0x06 | OPC_C0,
338 OPC_TLBP = 0x08 | OPC_C0,
339 OPC_RFE = 0x10 | OPC_C0,
340 OPC_ERET = 0x18 | OPC_C0,
341 OPC_DERET = 0x1F | OPC_C0,
342 OPC_WAIT = 0x20 | OPC_C0,
345 /* Coprocessor 1 (rs field) */
346 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
349 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
350 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
351 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
352 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
353 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
354 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
355 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
356 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
357 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
358 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
359 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
360 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
361 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
362 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
363 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
364 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
365 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
366 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
369 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
370 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
373 OPC_BC1F = (0x00 << 16) | OPC_BC1,
374 OPC_BC1T = (0x01 << 16) | OPC_BC1,
375 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
376 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
380 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
381 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
385 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
386 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
389 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
392 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
393 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
394 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
395 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
396 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
397 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
398 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
399 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
400 OPC_BC2 = (0x08 << 21) | OPC_CP2,
403 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
406 OPC_LWXC1 = 0x00 | OPC_CP3,
407 OPC_LDXC1 = 0x01 | OPC_CP3,
408 OPC_LUXC1 = 0x05 | OPC_CP3,
409 OPC_SWXC1 = 0x08 | OPC_CP3,
410 OPC_SDXC1 = 0x09 | OPC_CP3,
411 OPC_SUXC1 = 0x0D | OPC_CP3,
412 OPC_PREFX = 0x0F | OPC_CP3,
413 OPC_ALNV_PS = 0x1E | OPC_CP3,
414 OPC_MADD_S = 0x20 | OPC_CP3,
415 OPC_MADD_D = 0x21 | OPC_CP3,
416 OPC_MADD_PS = 0x26 | OPC_CP3,
417 OPC_MSUB_S = 0x28 | OPC_CP3,
418 OPC_MSUB_D = 0x29 | OPC_CP3,
419 OPC_MSUB_PS = 0x2E | OPC_CP3,
420 OPC_NMADD_S = 0x30 | OPC_CP3,
421 OPC_NMADD_D = 0x31 | OPC_CP3,
422 OPC_NMADD_PS= 0x36 | OPC_CP3,
423 OPC_NMSUB_S = 0x38 | OPC_CP3,
424 OPC_NMSUB_D = 0x39 | OPC_CP3,
425 OPC_NMSUB_PS= 0x3E | OPC_CP3,
428 /* global register indices */
429 static TCGv_ptr cpu_env;
430 static TCGv cpu_gpr[32], cpu_PC;
431 static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC], cpu_ACX[MIPS_DSP_ACC];
432 static TCGv cpu_dspctrl, btarget;
433 static TCGv_i32 bcond;
434 static TCGv_i32 fpu_fpr32[32], fpu_fpr32h[32];
435 static TCGv_i32 fpu_fcr0, fpu_fcr31;
437 #include "gen-icount.h"
439 #define gen_helper_0i(name, arg) do { \
440 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
441 gen_helper_##name(helper_tmp); \
442 tcg_temp_free_i32(helper_tmp); \
445 #define gen_helper_1i(name, arg1, arg2) do { \
446 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
447 gen_helper_##name(arg1, helper_tmp); \
448 tcg_temp_free_i32(helper_tmp); \
451 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
452 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
453 gen_helper_##name(arg1, arg2, helper_tmp); \
454 tcg_temp_free_i32(helper_tmp); \
457 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
458 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
459 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
460 tcg_temp_free_i32(helper_tmp); \
463 typedef struct DisasContext {
464 struct TranslationBlock *tb;
465 target_ulong pc, saved_pc;
467 /* Routine used to access memory */
469 uint32_t hflags, saved_hflags;
471 target_ulong btarget;
475 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
476 * exception condition */
477 BS_STOP = 1, /* We want to stop translation for any reason */
478 BS_BRANCH = 2, /* We reached a branch condition */
479 BS_EXCP = 3, /* We reached an exception condition */
482 static const char *regnames[] =
483 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
484 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
485 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
486 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
488 static const char *regnames_HI[] =
489 { "HI0", "HI1", "HI2", "HI3", };
491 static const char *regnames_LO[] =
492 { "LO0", "LO1", "LO2", "LO3", };
494 static const char *regnames_ACX[] =
495 { "ACX0", "ACX1", "ACX2", "ACX3", };
497 static const char *fregnames[] =
498 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
499 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
500 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
501 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
503 static const char *fregnames_h[] =
504 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
505 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
506 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
507 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
509 #ifdef MIPS_DEBUG_DISAS
510 #define MIPS_DEBUG(fmt, args...) \
511 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
512 TARGET_FMT_lx ": %08x " fmt "\n", \
513 ctx->pc, ctx->opcode , ##args)
514 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
516 #define MIPS_DEBUG(fmt, args...) do { } while(0)
517 #define LOG_DISAS(...) do { } while (0)
520 #define MIPS_INVAL(op) \
522 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
523 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
526 /* General purpose registers moves. */
527 static inline void gen_load_gpr (TCGv t, int reg)
530 tcg_gen_movi_tl(t, 0);
532 tcg_gen_mov_tl(t, cpu_gpr[reg]);
535 static inline void gen_store_gpr (TCGv t, int reg)
538 tcg_gen_mov_tl(cpu_gpr[reg], t);
541 /* Moves to/from ACX register. */
542 static inline void gen_load_ACX (TCGv t, int reg)
544 tcg_gen_mov_tl(t, cpu_ACX[reg]);
547 static inline void gen_store_ACX (TCGv t, int reg)
549 tcg_gen_mov_tl(cpu_ACX[reg], t);
552 /* Moves to/from shadow registers. */
553 static inline void gen_load_srsgpr (int from, int to)
555 TCGv r_tmp1 = tcg_temp_new();
558 tcg_gen_movi_tl(r_tmp1, 0);
560 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
561 TCGv_ptr addr = tcg_temp_new_ptr();
563 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
564 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
565 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
566 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
567 tcg_gen_ext_i32_ptr(addr, r_tmp2);
568 tcg_gen_add_ptr(addr, cpu_env, addr);
570 tcg_gen_ld_tl(r_tmp1, addr, sizeof(target_ulong) * from);
571 tcg_temp_free_ptr(addr);
572 tcg_temp_free_i32(r_tmp2);
574 gen_store_gpr(r_tmp1, to);
575 tcg_temp_free(r_tmp1);
578 static inline void gen_store_srsgpr (int from, int to)
581 TCGv r_tmp1 = tcg_temp_new();
582 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
583 TCGv_ptr addr = tcg_temp_new_ptr();
585 gen_load_gpr(r_tmp1, from);
586 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
587 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
588 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
589 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
590 tcg_gen_ext_i32_ptr(addr, r_tmp2);
591 tcg_gen_add_ptr(addr, cpu_env, addr);
593 tcg_gen_st_tl(r_tmp1, addr, sizeof(target_ulong) * to);
594 tcg_temp_free_ptr(addr);
595 tcg_temp_free_i32(r_tmp2);
596 tcg_temp_free(r_tmp1);
600 /* Floating point register moves. */
601 static inline void gen_load_fpr32 (TCGv_i32 t, int reg)
603 tcg_gen_mov_i32(t, fpu_fpr32[reg]);
606 static inline void gen_store_fpr32 (TCGv_i32 t, int reg)
608 tcg_gen_mov_i32(fpu_fpr32[reg], t);
611 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
613 if (ctx->hflags & MIPS_HFLAG_F64) {
614 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg], fpu_fpr32h[reg]);
616 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg & ~1], fpu_fpr32[reg | 1]);
620 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
622 if (ctx->hflags & MIPS_HFLAG_F64) {
623 tcg_gen_trunc_i64_i32(fpu_fpr32[reg], t);
624 tcg_gen_shri_i64(t, t, 32);
625 tcg_gen_trunc_i64_i32(fpu_fpr32h[reg], t);
627 tcg_gen_trunc_i64_i32(fpu_fpr32[reg & ~1], t);
628 tcg_gen_shri_i64(t, t, 32);
629 tcg_gen_trunc_i64_i32(fpu_fpr32[reg | 1], t);
633 static inline void gen_load_fpr32h (TCGv_i32 t, int reg)
635 tcg_gen_mov_i32(t, fpu_fpr32h[reg]);
638 static inline void gen_store_fpr32h (TCGv_i32 t, int reg)
640 tcg_gen_mov_i32(fpu_fpr32h[reg], t);
643 static inline void get_fp_cond (TCGv_i32 t)
645 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
646 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
648 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
649 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
650 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
651 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
652 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
653 tcg_temp_free_i32(r_tmp1);
654 tcg_temp_free_i32(r_tmp2);
657 #define FOP_CONDS(type, fmt, bits) \
658 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
659 TCGv_i##bits b, int cc) \
662 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
663 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
664 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
665 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
666 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
667 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
668 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
669 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
670 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
671 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
672 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
673 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
674 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
675 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
676 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
677 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
683 FOP_CONDS(abs, d, 64)
685 FOP_CONDS(abs, s, 32)
687 FOP_CONDS(abs, ps, 64)
691 #define OP_COND(name, cond) \
692 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
694 int l1 = gen_new_label(); \
695 int l2 = gen_new_label(); \
697 tcg_gen_brcond_tl(cond, t0, t1, l1); \
698 tcg_gen_movi_tl(t0, 0); \
701 tcg_gen_movi_tl(t0, 1); \
704 OP_COND(eq, TCG_COND_EQ);
705 OP_COND(ne, TCG_COND_NE);
706 OP_COND(ge, TCG_COND_GE);
707 OP_COND(geu, TCG_COND_GEU);
708 OP_COND(lt, TCG_COND_LT);
709 OP_COND(ltu, TCG_COND_LTU);
712 #define OP_CONDI(name, cond) \
713 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
715 int l1 = gen_new_label(); \
716 int l2 = gen_new_label(); \
718 tcg_gen_brcondi_tl(cond, t, val, l1); \
719 tcg_gen_movi_tl(t, 0); \
722 tcg_gen_movi_tl(t, 1); \
725 OP_CONDI(lti, TCG_COND_LT);
726 OP_CONDI(ltiu, TCG_COND_LTU);
729 #define OP_CONDZ(name, cond) \
730 static inline void glue(gen_op_, name) (TCGv t) \
732 int l1 = gen_new_label(); \
733 int l2 = gen_new_label(); \
735 tcg_gen_brcondi_tl(cond, t, 0, l1); \
736 tcg_gen_movi_tl(t, 0); \
739 tcg_gen_movi_tl(t, 1); \
742 OP_CONDZ(gez, TCG_COND_GE);
743 OP_CONDZ(gtz, TCG_COND_GT);
744 OP_CONDZ(lez, TCG_COND_LE);
745 OP_CONDZ(ltz, TCG_COND_LT);
748 static inline void gen_save_pc(target_ulong pc)
750 tcg_gen_movi_tl(cpu_PC, pc);
753 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
755 LOG_DISAS("hflags %08x saved %08x\n", ctx->hflags, ctx->saved_hflags);
756 if (do_save_pc && ctx->pc != ctx->saved_pc) {
757 gen_save_pc(ctx->pc);
758 ctx->saved_pc = ctx->pc;
760 if (ctx->hflags != ctx->saved_hflags) {
761 TCGv_i32 r_tmp = tcg_temp_new_i32();
763 tcg_gen_movi_i32(r_tmp, ctx->hflags);
764 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
765 tcg_temp_free_i32(r_tmp);
766 ctx->saved_hflags = ctx->hflags;
767 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
773 tcg_gen_movi_tl(btarget, ctx->btarget);
779 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
781 ctx->saved_hflags = ctx->hflags;
782 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
788 ctx->btarget = env->btarget;
794 generate_exception_err (DisasContext *ctx, int excp, int err)
796 TCGv_i32 texcp = tcg_const_i32(excp);
797 TCGv_i32 terr = tcg_const_i32(err);
798 save_cpu_state(ctx, 1);
799 gen_helper_raise_exception_err(texcp, terr);
800 tcg_temp_free_i32(terr);
801 tcg_temp_free_i32(texcp);
802 gen_helper_interrupt_restart();
807 generate_exception (DisasContext *ctx, int excp)
809 save_cpu_state(ctx, 1);
810 gen_helper_0i(raise_exception, excp);
811 gen_helper_interrupt_restart();
815 /* Addresses computation */
816 static inline void gen_op_addr_add (DisasContext *ctx, TCGv t0, TCGv t1)
818 tcg_gen_add_tl(t0, t0, t1);
820 #if defined(TARGET_MIPS64)
821 /* For compatibility with 32-bit code, data reference in user mode
822 with Status_UX = 0 should be casted to 32-bit and sign extended.
823 See the MIPS64 PRA manual, section 4.10. */
824 if (((ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
825 !(ctx->hflags & MIPS_HFLAG_UX)) {
826 tcg_gen_ext32s_i64(t0, t0);
831 static inline void check_cp0_enabled(DisasContext *ctx)
833 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
834 generate_exception_err(ctx, EXCP_CpU, 1);
837 static inline void check_cp1_enabled(DisasContext *ctx)
839 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
840 generate_exception_err(ctx, EXCP_CpU, 1);
843 /* Verify that the processor is running with COP1X instructions enabled.
844 This is associated with the nabla symbol in the MIPS32 and MIPS64
847 static inline void check_cop1x(DisasContext *ctx)
849 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
850 generate_exception(ctx, EXCP_RI);
853 /* Verify that the processor is running with 64-bit floating-point
854 operations enabled. */
856 static inline void check_cp1_64bitmode(DisasContext *ctx)
858 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
859 generate_exception(ctx, EXCP_RI);
863 * Verify if floating point register is valid; an operation is not defined
864 * if bit 0 of any register specification is set and the FR bit in the
865 * Status register equals zero, since the register numbers specify an
866 * even-odd pair of adjacent coprocessor general registers. When the FR bit
867 * in the Status register equals one, both even and odd register numbers
868 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
870 * Multiple 64 bit wide registers can be checked by calling
871 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
873 static inline void check_cp1_registers(DisasContext *ctx, int regs)
875 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
876 generate_exception(ctx, EXCP_RI);
879 /* This code generates a "reserved instruction" exception if the
880 CPU does not support the instruction set corresponding to flags. */
881 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
883 if (unlikely(!(env->insn_flags & flags)))
884 generate_exception(ctx, EXCP_RI);
887 /* This code generates a "reserved instruction" exception if 64-bit
888 instructions are not enabled. */
889 static inline void check_mips_64(DisasContext *ctx)
891 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
892 generate_exception(ctx, EXCP_RI);
895 /* load/store instructions. */
896 #define OP_LD(insn,fname) \
897 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
899 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
906 #if defined(TARGET_MIPS64)
912 #define OP_ST(insn,fname) \
913 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
915 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
920 #if defined(TARGET_MIPS64)
925 #define OP_LD_ATOMIC(insn,fname) \
926 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
928 tcg_gen_mov_tl(t1, t0); \
929 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
930 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
932 OP_LD_ATOMIC(ll,ld32s);
933 #if defined(TARGET_MIPS64)
934 OP_LD_ATOMIC(lld,ld64);
938 #define OP_ST_ATOMIC(insn,fname,almask) \
939 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
941 TCGv r_tmp = tcg_temp_local_new(); \
942 int l1 = gen_new_label(); \
943 int l2 = gen_new_label(); \
944 int l3 = gen_new_label(); \
946 tcg_gen_andi_tl(r_tmp, t0, almask); \
947 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
948 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
949 generate_exception(ctx, EXCP_AdES); \
951 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
952 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
953 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
954 tcg_gen_movi_tl(t0, 1); \
957 tcg_gen_movi_tl(t0, 0); \
959 tcg_temp_free(r_tmp); \
961 OP_ST_ATOMIC(sc,st32,0x3);
962 #if defined(TARGET_MIPS64)
963 OP_ST_ATOMIC(scd,st64,0x7);
968 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
969 int base, int16_t offset)
971 const char *opn = "ldst";
972 TCGv t0 = tcg_temp_local_new();
973 TCGv t1 = tcg_temp_local_new();
976 tcg_gen_movi_tl(t0, offset);
977 } else if (offset == 0) {
978 gen_load_gpr(t0, base);
980 tcg_gen_movi_tl(t0, offset);
981 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
983 /* Don't do NOP if destination is zero: we must perform the actual
986 #if defined(TARGET_MIPS64)
988 op_ldst_lwu(t0, ctx);
989 gen_store_gpr(t0, rt);
994 gen_store_gpr(t0, rt);
998 op_ldst_lld(t0, t1, ctx);
999 gen_store_gpr(t0, rt);
1003 gen_load_gpr(t1, rt);
1004 op_ldst_sd(t0, t1, ctx);
1008 save_cpu_state(ctx, 1);
1009 gen_load_gpr(t1, rt);
1010 op_ldst_scd(t0, t1, ctx);
1011 gen_store_gpr(t0, rt);
1015 save_cpu_state(ctx, 1);
1016 gen_load_gpr(t1, rt);
1017 gen_helper_3i(ldl, t1, t0, t1, ctx->mem_idx);
1018 gen_store_gpr(t1, rt);
1022 save_cpu_state(ctx, 1);
1023 gen_load_gpr(t1, rt);
1024 gen_helper_2i(sdl, t0, t1, ctx->mem_idx);
1028 save_cpu_state(ctx, 1);
1029 gen_load_gpr(t1, rt);
1030 gen_helper_3i(ldr, t1, t0, t1, ctx->mem_idx);
1031 gen_store_gpr(t1, rt);
1035 save_cpu_state(ctx, 1);
1036 gen_load_gpr(t1, rt);
1037 gen_helper_2i(sdr, t0, t1, ctx->mem_idx);
1042 op_ldst_lw(t0, ctx);
1043 gen_store_gpr(t0, rt);
1047 gen_load_gpr(t1, rt);
1048 op_ldst_sw(t0, t1, ctx);
1052 op_ldst_lh(t0, ctx);
1053 gen_store_gpr(t0, rt);
1057 gen_load_gpr(t1, rt);
1058 op_ldst_sh(t0, t1, ctx);
1062 op_ldst_lhu(t0, ctx);
1063 gen_store_gpr(t0, rt);
1067 op_ldst_lb(t0, ctx);
1068 gen_store_gpr(t0, rt);
1072 gen_load_gpr(t1, rt);
1073 op_ldst_sb(t0, t1, ctx);
1077 op_ldst_lbu(t0, ctx);
1078 gen_store_gpr(t0, rt);
1082 save_cpu_state(ctx, 1);
1083 gen_load_gpr(t1, rt);
1084 gen_helper_3i(lwl, t1, t0, t1, ctx->mem_idx);
1085 gen_store_gpr(t1, rt);
1089 save_cpu_state(ctx, 1);
1090 gen_load_gpr(t1, rt);
1091 gen_helper_2i(swl, t0, t1, ctx->mem_idx);
1095 save_cpu_state(ctx, 1);
1096 gen_load_gpr(t1, rt);
1097 gen_helper_3i(lwr, t1, t0, t1, ctx->mem_idx);
1098 gen_store_gpr(t1, rt);
1102 save_cpu_state(ctx, 1);
1103 gen_load_gpr(t1, rt);
1104 gen_helper_2i(swr, t0, t1, ctx->mem_idx);
1108 op_ldst_ll(t0, t1, ctx);
1109 gen_store_gpr(t0, rt);
1113 save_cpu_state(ctx, 1);
1114 gen_load_gpr(t1, rt);
1115 op_ldst_sc(t0, t1, ctx);
1116 gen_store_gpr(t0, rt);
1121 generate_exception(ctx, EXCP_RI);
1124 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1130 /* Load and store */
1131 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1132 int base, int16_t offset)
1134 const char *opn = "flt_ldst";
1135 TCGv t0 = tcg_temp_local_new();
1138 tcg_gen_movi_tl(t0, offset);
1139 } else if (offset == 0) {
1140 gen_load_gpr(t0, base);
1142 tcg_gen_movi_tl(t0, offset);
1143 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
1145 /* Don't do NOP if destination is zero: we must perform the actual
1150 TCGv_i32 fp0 = tcg_temp_new_i32();
1151 TCGv t1 = tcg_temp_new();
1153 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
1154 tcg_gen_trunc_tl_i32(fp0, t1);
1155 gen_store_fpr32(fp0, ft);
1157 tcg_temp_free_i32(fp0);
1163 TCGv_i32 fp0 = tcg_temp_new_i32();
1164 TCGv t1 = tcg_temp_new();
1166 gen_load_fpr32(fp0, ft);
1167 tcg_gen_extu_i32_tl(t1, fp0);
1168 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
1170 tcg_temp_free_i32(fp0);
1176 TCGv_i64 fp0 = tcg_temp_new_i64();
1178 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1179 gen_store_fpr64(ctx, fp0, ft);
1180 tcg_temp_free_i64(fp0);
1186 TCGv_i64 fp0 = tcg_temp_new_i64();
1188 gen_load_fpr64(ctx, fp0, ft);
1189 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1190 tcg_temp_free_i64(fp0);
1196 generate_exception(ctx, EXCP_RI);
1199 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1204 /* Arithmetic with immediate operand */
1205 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1206 int rt, int rs, int16_t imm)
1209 const char *opn = "imm arith";
1210 TCGv t0 = tcg_temp_local_new();
1212 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1213 /* If no destination, treat it as a NOP.
1214 For addi, we must generate the overflow exception when needed. */
1218 uimm = (uint16_t)imm;
1222 #if defined(TARGET_MIPS64)
1228 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1233 gen_load_gpr(t0, rs);
1236 tcg_gen_movi_tl(t0, imm << 16);
1241 #if defined(TARGET_MIPS64)
1250 gen_load_gpr(t0, rs);
1256 TCGv r_tmp1 = tcg_temp_new();
1257 TCGv r_tmp2 = tcg_temp_new();
1258 int l1 = gen_new_label();
1260 save_cpu_state(ctx, 1);
1261 tcg_gen_ext32s_tl(r_tmp1, t0);
1262 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1264 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1265 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1266 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1267 tcg_temp_free(r_tmp2);
1268 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1269 /* operands of same sign, result different sign */
1270 generate_exception(ctx, EXCP_OVERFLOW);
1272 tcg_temp_free(r_tmp1);
1274 tcg_gen_ext32s_tl(t0, t0);
1279 tcg_gen_addi_tl(t0, t0, uimm);
1280 tcg_gen_ext32s_tl(t0, t0);
1283 #if defined(TARGET_MIPS64)
1286 TCGv r_tmp1 = tcg_temp_new();
1287 TCGv r_tmp2 = tcg_temp_new();
1288 int l1 = gen_new_label();
1290 save_cpu_state(ctx, 1);
1291 tcg_gen_mov_tl(r_tmp1, t0);
1292 tcg_gen_addi_tl(t0, t0, uimm);
1294 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1295 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1296 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1297 tcg_temp_free(r_tmp2);
1298 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1299 /* operands of same sign, result different sign */
1300 generate_exception(ctx, EXCP_OVERFLOW);
1302 tcg_temp_free(r_tmp1);
1307 tcg_gen_addi_tl(t0, t0, uimm);
1312 gen_op_lti(t0, uimm);
1316 gen_op_ltiu(t0, uimm);
1320 tcg_gen_andi_tl(t0, t0, uimm);
1324 tcg_gen_ori_tl(t0, t0, uimm);
1328 tcg_gen_xori_tl(t0, t0, uimm);
1335 tcg_gen_shli_tl(t0, t0, uimm);
1336 tcg_gen_ext32s_tl(t0, t0);
1340 tcg_gen_ext32s_tl(t0, t0);
1341 tcg_gen_sari_tl(t0, t0, uimm);
1345 switch ((ctx->opcode >> 21) & 0x1f) {
1348 tcg_gen_ext32u_tl(t0, t0);
1349 tcg_gen_shri_tl(t0, t0, uimm);
1351 tcg_gen_ext32s_tl(t0, t0);
1356 /* rotr is decoded as srl on non-R2 CPUs */
1357 if (env->insn_flags & ISA_MIPS32R2) {
1359 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1361 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1362 tcg_gen_rotri_i32(r_tmp1, r_tmp1, uimm);
1363 tcg_gen_ext_i32_tl(t0, r_tmp1);
1364 tcg_temp_free_i32(r_tmp1);
1369 tcg_gen_ext32u_tl(t0, t0);
1370 tcg_gen_shri_tl(t0, t0, uimm);
1372 tcg_gen_ext32s_tl(t0, t0);
1378 MIPS_INVAL("invalid srl flag");
1379 generate_exception(ctx, EXCP_RI);
1383 #if defined(TARGET_MIPS64)
1385 tcg_gen_shli_tl(t0, t0, uimm);
1389 tcg_gen_sari_tl(t0, t0, uimm);
1393 switch ((ctx->opcode >> 21) & 0x1f) {
1395 tcg_gen_shri_tl(t0, t0, uimm);
1399 /* drotr is decoded as dsrl on non-R2 CPUs */
1400 if (env->insn_flags & ISA_MIPS32R2) {
1402 tcg_gen_rotri_tl(t0, t0, uimm);
1406 tcg_gen_shri_tl(t0, t0, uimm);
1411 MIPS_INVAL("invalid dsrl flag");
1412 generate_exception(ctx, EXCP_RI);
1417 tcg_gen_shli_tl(t0, t0, uimm + 32);
1421 tcg_gen_sari_tl(t0, t0, uimm + 32);
1425 switch ((ctx->opcode >> 21) & 0x1f) {
1427 tcg_gen_shri_tl(t0, t0, uimm + 32);
1431 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1432 if (env->insn_flags & ISA_MIPS32R2) {
1433 tcg_gen_rotri_tl(t0, t0, uimm + 32);
1436 tcg_gen_shri_tl(t0, t0, uimm + 32);
1441 MIPS_INVAL("invalid dsrl32 flag");
1442 generate_exception(ctx, EXCP_RI);
1449 generate_exception(ctx, EXCP_RI);
1452 gen_store_gpr(t0, rt);
1453 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1459 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1460 int rd, int rs, int rt)
1462 const char *opn = "arith";
1463 TCGv t0 = tcg_temp_local_new();
1464 TCGv t1 = tcg_temp_local_new();
1466 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1467 && opc != OPC_DADD && opc != OPC_DSUB) {
1468 /* If no destination, treat it as a NOP.
1469 For add & sub, we must generate the overflow exception when needed. */
1473 gen_load_gpr(t0, rs);
1474 /* Specialcase the conventional move operation. */
1475 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1476 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1477 gen_store_gpr(t0, rd);
1480 gen_load_gpr(t1, rt);
1484 TCGv r_tmp1 = tcg_temp_new();
1485 TCGv r_tmp2 = tcg_temp_new();
1486 int l1 = gen_new_label();
1488 save_cpu_state(ctx, 1);
1489 tcg_gen_ext32s_tl(r_tmp1, t0);
1490 tcg_gen_ext32s_tl(r_tmp2, t1);
1491 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1493 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1494 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1495 tcg_gen_xor_tl(r_tmp2, t0, t1);
1496 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1497 tcg_temp_free(r_tmp2);
1498 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1499 /* operands of same sign, result different sign */
1500 generate_exception(ctx, EXCP_OVERFLOW);
1502 tcg_temp_free(r_tmp1);
1504 tcg_gen_ext32s_tl(t0, t0);
1509 tcg_gen_add_tl(t0, t0, t1);
1510 tcg_gen_ext32s_tl(t0, t0);
1515 TCGv r_tmp1 = tcg_temp_new();
1516 TCGv r_tmp2 = tcg_temp_new();
1517 int l1 = gen_new_label();
1519 save_cpu_state(ctx, 1);
1520 tcg_gen_ext32s_tl(r_tmp1, t0);
1521 tcg_gen_ext32s_tl(r_tmp2, t1);
1522 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1524 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1525 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1526 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1527 tcg_temp_free(r_tmp2);
1528 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1529 /* operands of different sign, first operand and result different sign */
1530 generate_exception(ctx, EXCP_OVERFLOW);
1532 tcg_temp_free(r_tmp1);
1534 tcg_gen_ext32s_tl(t0, t0);
1539 tcg_gen_sub_tl(t0, t0, t1);
1540 tcg_gen_ext32s_tl(t0, t0);
1543 #if defined(TARGET_MIPS64)
1546 TCGv r_tmp1 = tcg_temp_new();
1547 TCGv r_tmp2 = tcg_temp_new();
1548 int l1 = gen_new_label();
1550 save_cpu_state(ctx, 1);
1551 tcg_gen_mov_tl(r_tmp1, t0);
1552 tcg_gen_add_tl(t0, t0, t1);
1554 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1555 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1556 tcg_gen_xor_tl(r_tmp2, t0, t1);
1557 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1558 tcg_temp_free(r_tmp2);
1559 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1560 /* operands of same sign, result different sign */
1561 generate_exception(ctx, EXCP_OVERFLOW);
1563 tcg_temp_free(r_tmp1);
1568 tcg_gen_add_tl(t0, t0, t1);
1573 TCGv r_tmp1 = tcg_temp_new();
1574 TCGv r_tmp2 = tcg_temp_new();
1575 int l1 = gen_new_label();
1577 save_cpu_state(ctx, 1);
1578 tcg_gen_mov_tl(r_tmp1, t0);
1579 tcg_gen_sub_tl(t0, t0, t1);
1581 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1582 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1583 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1584 tcg_temp_free(r_tmp2);
1585 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1586 /* operands of different sign, first operand and result different sign */
1587 generate_exception(ctx, EXCP_OVERFLOW);
1589 tcg_temp_free(r_tmp1);
1594 tcg_gen_sub_tl(t0, t0, t1);
1607 tcg_gen_and_tl(t0, t0, t1);
1611 tcg_gen_nor_tl(t0, t0, t1);
1615 tcg_gen_or_tl(t0, t0, t1);
1619 tcg_gen_xor_tl(t0, t0, t1);
1623 tcg_gen_mul_tl(t0, t0, t1);
1624 tcg_gen_ext32s_tl(t0, t0);
1629 int l1 = gen_new_label();
1631 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1632 gen_store_gpr(t0, rd);
1639 int l1 = gen_new_label();
1641 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1642 gen_store_gpr(t0, rd);
1648 tcg_gen_andi_tl(t0, t0, 0x1f);
1649 tcg_gen_shl_tl(t0, t1, t0);
1650 tcg_gen_ext32s_tl(t0, t0);
1654 tcg_gen_ext32s_tl(t1, t1);
1655 tcg_gen_andi_tl(t0, t0, 0x1f);
1656 tcg_gen_sar_tl(t0, t1, t0);
1660 switch ((ctx->opcode >> 6) & 0x1f) {
1662 tcg_gen_ext32u_tl(t1, t1);
1663 tcg_gen_andi_tl(t0, t0, 0x1f);
1664 tcg_gen_shr_tl(t0, t1, t0);
1665 tcg_gen_ext32s_tl(t0, t0);
1669 /* rotrv is decoded as srlv on non-R2 CPUs */
1670 if (env->insn_flags & ISA_MIPS32R2) {
1671 int l1 = gen_new_label();
1672 int l2 = gen_new_label();
1674 tcg_gen_andi_tl(t0, t0, 0x1f);
1675 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1677 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1678 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
1680 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1681 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1682 tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2);
1683 tcg_temp_free_i32(r_tmp1);
1684 tcg_temp_free_i32(r_tmp2);
1688 tcg_gen_mov_tl(t0, t1);
1692 tcg_gen_ext32u_tl(t1, t1);
1693 tcg_gen_andi_tl(t0, t0, 0x1f);
1694 tcg_gen_shr_tl(t0, t1, t0);
1695 tcg_gen_ext32s_tl(t0, t0);
1700 MIPS_INVAL("invalid srlv flag");
1701 generate_exception(ctx, EXCP_RI);
1705 #if defined(TARGET_MIPS64)
1707 tcg_gen_andi_tl(t0, t0, 0x3f);
1708 tcg_gen_shl_tl(t0, t1, t0);
1712 tcg_gen_andi_tl(t0, t0, 0x3f);
1713 tcg_gen_sar_tl(t0, t1, t0);
1717 switch ((ctx->opcode >> 6) & 0x1f) {
1719 tcg_gen_andi_tl(t0, t0, 0x3f);
1720 tcg_gen_shr_tl(t0, t1, t0);
1724 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1725 if (env->insn_flags & ISA_MIPS32R2) {
1726 int l1 = gen_new_label();
1727 int l2 = gen_new_label();
1729 tcg_gen_andi_tl(t0, t0, 0x3f);
1730 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1732 tcg_gen_rotr_tl(t0, t1, t0);
1736 tcg_gen_mov_tl(t0, t1);
1740 tcg_gen_andi_tl(t0, t0, 0x3f);
1741 tcg_gen_shr_tl(t0, t1, t0);
1746 MIPS_INVAL("invalid dsrlv flag");
1747 generate_exception(ctx, EXCP_RI);
1754 generate_exception(ctx, EXCP_RI);
1757 gen_store_gpr(t0, rd);
1759 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1765 /* Arithmetic on HI/LO registers */
1766 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1768 const char *opn = "hilo";
1770 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1777 tcg_gen_mov_tl(cpu_gpr[reg], cpu_HI[0]);
1781 tcg_gen_mov_tl(cpu_gpr[reg], cpu_LO[0]);
1786 tcg_gen_mov_tl(cpu_HI[0], cpu_gpr[reg]);
1788 tcg_gen_movi_tl(cpu_HI[0], 0);
1793 tcg_gen_mov_tl(cpu_LO[0], cpu_gpr[reg]);
1795 tcg_gen_movi_tl(cpu_LO[0], 0);
1800 generate_exception(ctx, EXCP_RI);
1803 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1806 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1809 const char *opn = "mul/div";
1810 TCGv t0 = tcg_temp_local_new();
1811 TCGv t1 = tcg_temp_local_new();
1813 gen_load_gpr(t0, rs);
1814 gen_load_gpr(t1, rt);
1818 int l1 = gen_new_label();
1820 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1822 int l2 = gen_new_label();
1823 TCGv_i32 r_tmp1 = tcg_temp_local_new_i32();
1824 TCGv_i32 r_tmp2 = tcg_temp_local_new_i32();
1825 TCGv_i32 r_tmp3 = tcg_temp_local_new_i32();
1827 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1828 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1829 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp1, -1 << 31, l2);
1830 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp2, -1, l2);
1831 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1832 tcg_gen_movi_tl(cpu_HI[0], 0);
1835 tcg_gen_div_i32(r_tmp3, r_tmp1, r_tmp2);
1836 tcg_gen_rem_i32(r_tmp2, r_tmp1, r_tmp2);
1837 tcg_gen_ext_i32_tl(cpu_LO[0], r_tmp3);
1838 tcg_gen_ext_i32_tl(cpu_HI[0], r_tmp2);
1839 tcg_temp_free_i32(r_tmp1);
1840 tcg_temp_free_i32(r_tmp2);
1841 tcg_temp_free_i32(r_tmp3);
1849 int l1 = gen_new_label();
1851 tcg_gen_ext32s_tl(t1, t1);
1852 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1854 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1855 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
1856 TCGv_i32 r_tmp3 = tcg_temp_new_i32();
1858 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1859 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1860 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1861 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1862 tcg_gen_ext_i32_tl(cpu_LO[0], r_tmp3);
1863 tcg_gen_ext_i32_tl(cpu_HI[0], r_tmp1);
1864 tcg_temp_free_i32(r_tmp1);
1865 tcg_temp_free_i32(r_tmp2);
1866 tcg_temp_free_i32(r_tmp3);
1874 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1875 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1877 tcg_gen_ext_tl_i64(r_tmp1, t0);
1878 tcg_gen_ext_tl_i64(r_tmp2, t1);
1879 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1880 tcg_temp_free_i64(r_tmp2);
1881 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1882 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1883 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1884 tcg_temp_free_i64(r_tmp1);
1885 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1886 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1892 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1893 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1895 tcg_gen_ext32u_tl(t0, t0);
1896 tcg_gen_ext32u_tl(t1, t1);
1897 tcg_gen_extu_tl_i64(r_tmp1, t0);
1898 tcg_gen_extu_tl_i64(r_tmp2, t1);
1899 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1900 tcg_temp_free_i64(r_tmp2);
1901 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1902 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1903 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1904 tcg_temp_free_i64(r_tmp1);
1905 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1906 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1910 #if defined(TARGET_MIPS64)
1913 int l1 = gen_new_label();
1915 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1917 int l2 = gen_new_label();
1919 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
1920 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
1921 tcg_gen_mov_tl(cpu_LO[0], t0);
1922 tcg_gen_movi_tl(cpu_HI[0], 0);
1925 tcg_gen_div_i64(cpu_LO[0], t0, t1);
1926 tcg_gen_rem_i64(cpu_HI[0], t0, t1);
1934 int l1 = gen_new_label();
1936 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1937 tcg_gen_divu_i64(cpu_LO[0], t0, t1);
1938 tcg_gen_remu_i64(cpu_HI[0], t0, t1);
1944 gen_helper_dmult(t0, t1);
1948 gen_helper_dmultu(t0, t1);
1954 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1955 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1957 tcg_gen_ext_tl_i64(r_tmp1, t0);
1958 tcg_gen_ext_tl_i64(r_tmp2, t1);
1959 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1960 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
1961 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
1962 tcg_temp_free_i64(r_tmp2);
1963 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1964 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1965 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1966 tcg_temp_free_i64(r_tmp1);
1967 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1968 tcg_gen_ext32s_tl(cpu_LO[1], t1);
1974 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1975 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1977 tcg_gen_ext32u_tl(t0, t0);
1978 tcg_gen_ext32u_tl(t1, t1);
1979 tcg_gen_extu_tl_i64(r_tmp1, t0);
1980 tcg_gen_extu_tl_i64(r_tmp2, t1);
1981 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1982 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
1983 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
1984 tcg_temp_free_i64(r_tmp2);
1985 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1986 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1987 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1988 tcg_temp_free_i64(r_tmp1);
1989 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1990 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1996 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1997 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1999 tcg_gen_ext_tl_i64(r_tmp1, t0);
2000 tcg_gen_ext_tl_i64(r_tmp2, t1);
2001 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2002 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
2003 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2004 tcg_temp_free_i64(r_tmp2);
2005 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2006 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2007 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2008 tcg_temp_free_i64(r_tmp1);
2009 tcg_gen_ext32s_tl(cpu_LO[0], t0);
2010 tcg_gen_ext32s_tl(cpu_HI[0], t1);
2016 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
2017 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
2019 tcg_gen_ext32u_tl(t0, t0);
2020 tcg_gen_ext32u_tl(t1, t1);
2021 tcg_gen_extu_tl_i64(r_tmp1, t0);
2022 tcg_gen_extu_tl_i64(r_tmp2, t1);
2023 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2024 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
2025 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2026 tcg_temp_free_i64(r_tmp2);
2027 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2028 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2029 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2030 tcg_temp_free_i64(r_tmp1);
2031 tcg_gen_ext32s_tl(cpu_LO[0], t0);
2032 tcg_gen_ext32s_tl(cpu_HI[0], t1);
2038 generate_exception(ctx, EXCP_RI);
2041 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2047 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2048 int rd, int rs, int rt)
2050 const char *opn = "mul vr54xx";
2051 TCGv t0 = tcg_temp_new();
2052 TCGv t1 = tcg_temp_new();
2054 gen_load_gpr(t0, rs);
2055 gen_load_gpr(t1, rt);
2058 case OPC_VR54XX_MULS:
2059 gen_helper_muls(t0, t0, t1);
2062 case OPC_VR54XX_MULSU:
2063 gen_helper_mulsu(t0, t0, t1);
2066 case OPC_VR54XX_MACC:
2067 gen_helper_macc(t0, t0, t1);
2070 case OPC_VR54XX_MACCU:
2071 gen_helper_maccu(t0, t0, t1);
2074 case OPC_VR54XX_MSAC:
2075 gen_helper_msac(t0, t0, t1);
2078 case OPC_VR54XX_MSACU:
2079 gen_helper_msacu(t0, t0, t1);
2082 case OPC_VR54XX_MULHI:
2083 gen_helper_mulhi(t0, t0, t1);
2086 case OPC_VR54XX_MULHIU:
2087 gen_helper_mulhiu(t0, t0, t1);
2090 case OPC_VR54XX_MULSHI:
2091 gen_helper_mulshi(t0, t0, t1);
2094 case OPC_VR54XX_MULSHIU:
2095 gen_helper_mulshiu(t0, t0, t1);
2098 case OPC_VR54XX_MACCHI:
2099 gen_helper_macchi(t0, t0, t1);
2102 case OPC_VR54XX_MACCHIU:
2103 gen_helper_macchiu(t0, t0, t1);
2106 case OPC_VR54XX_MSACHI:
2107 gen_helper_msachi(t0, t0, t1);
2110 case OPC_VR54XX_MSACHIU:
2111 gen_helper_msachiu(t0, t0, t1);
2115 MIPS_INVAL("mul vr54xx");
2116 generate_exception(ctx, EXCP_RI);
2119 gen_store_gpr(t0, rd);
2120 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2127 static void gen_cl (DisasContext *ctx, uint32_t opc,
2130 const char *opn = "CLx";
2138 t0 = tcg_temp_new();
2139 gen_load_gpr(t0, rs);
2142 gen_helper_clo(cpu_gpr[rd], t0);
2146 gen_helper_clz(cpu_gpr[rd], t0);
2149 #if defined(TARGET_MIPS64)
2151 gen_helper_dclo(cpu_gpr[rd], t0);
2155 gen_helper_dclz(cpu_gpr[rd], t0);
2160 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2165 static void gen_trap (DisasContext *ctx, uint32_t opc,
2166 int rs, int rt, int16_t imm)
2169 TCGv t0 = tcg_temp_local_new();
2170 TCGv t1 = tcg_temp_local_new();
2173 /* Load needed operands */
2181 /* Compare two registers */
2183 gen_load_gpr(t0, rs);
2184 gen_load_gpr(t1, rt);
2194 /* Compare register to immediate */
2195 if (rs != 0 || imm != 0) {
2196 gen_load_gpr(t0, rs);
2197 tcg_gen_movi_tl(t1, (int32_t)imm);
2204 case OPC_TEQ: /* rs == rs */
2205 case OPC_TEQI: /* r0 == 0 */
2206 case OPC_TGE: /* rs >= rs */
2207 case OPC_TGEI: /* r0 >= 0 */
2208 case OPC_TGEU: /* rs >= rs unsigned */
2209 case OPC_TGEIU: /* r0 >= 0 unsigned */
2211 tcg_gen_movi_tl(t0, 1);
2213 case OPC_TLT: /* rs < rs */
2214 case OPC_TLTI: /* r0 < 0 */
2215 case OPC_TLTU: /* rs < rs unsigned */
2216 case OPC_TLTIU: /* r0 < 0 unsigned */
2217 case OPC_TNE: /* rs != rs */
2218 case OPC_TNEI: /* r0 != 0 */
2219 /* Never trap: treat as NOP. */
2223 generate_exception(ctx, EXCP_RI);
2254 generate_exception(ctx, EXCP_RI);
2258 save_cpu_state(ctx, 1);
2260 int l1 = gen_new_label();
2262 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2263 gen_helper_0i(raise_exception, EXCP_TRAP);
2266 ctx->bstate = BS_STOP;
2272 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2274 TranslationBlock *tb;
2276 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2279 tcg_gen_exit_tb((long)tb + n);
2286 /* Branches (before delay slot) */
2287 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2288 int rs, int rt, int32_t offset)
2290 target_ulong btgt = -1;
2292 int bcond_compute = 0;
2293 TCGv t0 = tcg_temp_local_new();
2294 TCGv t1 = tcg_temp_local_new();
2296 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2297 #ifdef MIPS_DEBUG_DISAS
2298 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx "\n", ctx->pc);
2300 generate_exception(ctx, EXCP_RI);
2304 /* Load needed operands */
2310 /* Compare two registers */
2312 gen_load_gpr(t0, rs);
2313 gen_load_gpr(t1, rt);
2316 btgt = ctx->pc + 4 + offset;
2330 /* Compare to zero */
2332 gen_load_gpr(t0, rs);
2335 btgt = ctx->pc + 4 + offset;
2339 /* Jump to immediate */
2340 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2344 /* Jump to register */
2345 if (offset != 0 && offset != 16) {
2346 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2347 others are reserved. */
2348 MIPS_INVAL("jump hint");
2349 generate_exception(ctx, EXCP_RI);
2352 gen_load_gpr(btarget, rs);
2355 MIPS_INVAL("branch/jump");
2356 generate_exception(ctx, EXCP_RI);
2359 if (bcond_compute == 0) {
2360 /* No condition to be computed */
2362 case OPC_BEQ: /* rx == rx */
2363 case OPC_BEQL: /* rx == rx likely */
2364 case OPC_BGEZ: /* 0 >= 0 */
2365 case OPC_BGEZL: /* 0 >= 0 likely */
2366 case OPC_BLEZ: /* 0 <= 0 */
2367 case OPC_BLEZL: /* 0 <= 0 likely */
2369 ctx->hflags |= MIPS_HFLAG_B;
2370 MIPS_DEBUG("balways");
2372 case OPC_BGEZAL: /* 0 >= 0 */
2373 case OPC_BGEZALL: /* 0 >= 0 likely */
2374 /* Always take and link */
2376 ctx->hflags |= MIPS_HFLAG_B;
2377 MIPS_DEBUG("balways and link");
2379 case OPC_BNE: /* rx != rx */
2380 case OPC_BGTZ: /* 0 > 0 */
2381 case OPC_BLTZ: /* 0 < 0 */
2383 MIPS_DEBUG("bnever (NOP)");
2385 case OPC_BLTZAL: /* 0 < 0 */
2386 tcg_gen_movi_tl(t0, ctx->pc + 8);
2387 gen_store_gpr(t0, 31);
2388 MIPS_DEBUG("bnever and link");
2390 case OPC_BLTZALL: /* 0 < 0 likely */
2391 tcg_gen_movi_tl(t0, ctx->pc + 8);
2392 gen_store_gpr(t0, 31);
2393 /* Skip the instruction in the delay slot */
2394 MIPS_DEBUG("bnever, link and skip");
2397 case OPC_BNEL: /* rx != rx likely */
2398 case OPC_BGTZL: /* 0 > 0 likely */
2399 case OPC_BLTZL: /* 0 < 0 likely */
2400 /* Skip the instruction in the delay slot */
2401 MIPS_DEBUG("bnever and skip");
2405 ctx->hflags |= MIPS_HFLAG_B;
2406 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2410 ctx->hflags |= MIPS_HFLAG_B;
2411 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2414 ctx->hflags |= MIPS_HFLAG_BR;
2415 MIPS_DEBUG("jr %s", regnames[rs]);
2419 ctx->hflags |= MIPS_HFLAG_BR;
2420 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2423 MIPS_INVAL("branch/jump");
2424 generate_exception(ctx, EXCP_RI);
2431 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2432 regnames[rs], regnames[rt], btgt);
2436 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2437 regnames[rs], regnames[rt], btgt);
2441 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2442 regnames[rs], regnames[rt], btgt);
2446 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2447 regnames[rs], regnames[rt], btgt);
2451 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2455 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2459 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2465 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2469 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2473 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2477 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2481 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2485 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2489 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2494 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2496 ctx->hflags |= MIPS_HFLAG_BC;
2497 tcg_gen_trunc_tl_i32(bcond, t0);
2502 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2504 ctx->hflags |= MIPS_HFLAG_BL;
2505 tcg_gen_trunc_tl_i32(bcond, t0);
2508 MIPS_INVAL("conditional branch/jump");
2509 generate_exception(ctx, EXCP_RI);
2513 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2514 blink, ctx->hflags, btgt);
2516 ctx->btarget = btgt;
2518 tcg_gen_movi_tl(t0, ctx->pc + 8);
2519 gen_store_gpr(t0, blink);
2527 /* special3 bitfield operations */
2528 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2529 int rs, int lsb, int msb)
2531 TCGv t0 = tcg_temp_new();
2532 TCGv t1 = tcg_temp_new();
2535 gen_load_gpr(t1, rs);
2540 tcg_gen_shri_tl(t0, t1, lsb);
2542 tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
2544 tcg_gen_ext32s_tl(t0, t0);
2547 #if defined(TARGET_MIPS64)
2549 tcg_gen_shri_tl(t0, t1, lsb);
2551 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
2555 tcg_gen_shri_tl(t0, t1, lsb + 32);
2556 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2559 tcg_gen_shri_tl(t0, t1, lsb);
2560 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2566 mask = ((msb - lsb + 1 < 32) ? ((1 << (msb - lsb + 1)) - 1) : ~0) << lsb;
2567 gen_load_gpr(t0, rt);
2568 tcg_gen_andi_tl(t0, t0, ~mask);
2569 tcg_gen_shli_tl(t1, t1, lsb);
2570 tcg_gen_andi_tl(t1, t1, mask);
2571 tcg_gen_or_tl(t0, t0, t1);
2572 tcg_gen_ext32s_tl(t0, t0);
2574 #if defined(TARGET_MIPS64)
2578 mask = ((msb - lsb + 1 + 32 < 64) ? ((1ULL << (msb - lsb + 1 + 32)) - 1) : ~0ULL) << lsb;
2579 gen_load_gpr(t0, rt);
2580 tcg_gen_andi_tl(t0, t0, ~mask);
2581 tcg_gen_shli_tl(t1, t1, lsb);
2582 tcg_gen_andi_tl(t1, t1, mask);
2583 tcg_gen_or_tl(t0, t0, t1);
2588 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2589 gen_load_gpr(t0, rt);
2590 tcg_gen_andi_tl(t0, t0, ~mask);
2591 tcg_gen_shli_tl(t1, t1, lsb + 32);
2592 tcg_gen_andi_tl(t1, t1, mask);
2593 tcg_gen_or_tl(t0, t0, t1);
2598 gen_load_gpr(t0, rt);
2599 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2600 gen_load_gpr(t0, rt);
2601 tcg_gen_andi_tl(t0, t0, ~mask);
2602 tcg_gen_shli_tl(t1, t1, lsb);
2603 tcg_gen_andi_tl(t1, t1, mask);
2604 tcg_gen_or_tl(t0, t0, t1);
2609 MIPS_INVAL("bitops");
2610 generate_exception(ctx, EXCP_RI);
2615 gen_store_gpr(t0, rt);
2620 static void gen_bshfl (DisasContext *ctx, uint32_t op2, int rt, int rd)
2622 TCGv t0 = tcg_temp_new();
2623 TCGv t1 = tcg_temp_new();
2625 gen_load_gpr(t1, rt);
2628 tcg_gen_shri_tl(t0, t1, 8);
2629 tcg_gen_andi_tl(t0, t0, 0x00FF00FF);
2630 tcg_gen_shli_tl(t1, t1, 8);
2631 tcg_gen_andi_tl(t1, t1, ~0x00FF00FF);
2632 tcg_gen_or_tl(t0, t0, t1);
2633 tcg_gen_ext32s_tl(t0, t0);
2636 tcg_gen_ext8s_tl(t0, t1);
2639 tcg_gen_ext16s_tl(t0, t1);
2641 #if defined(TARGET_MIPS64)
2643 gen_load_gpr(t1, rt);
2644 tcg_gen_shri_tl(t0, t1, 8);
2645 tcg_gen_andi_tl(t0, t0, 0x00FF00FF00FF00FFULL);
2646 tcg_gen_shli_tl(t1, t1, 8);
2647 tcg_gen_andi_tl(t1, t1, ~0x00FF00FF00FF00FFULL);
2648 tcg_gen_or_tl(t0, t0, t1);
2651 gen_load_gpr(t1, rt);
2652 tcg_gen_shri_tl(t0, t1, 16);
2653 tcg_gen_andi_tl(t0, t0, 0x0000FFFF0000FFFFULL);
2654 tcg_gen_shli_tl(t1, t1, 16);
2655 tcg_gen_andi_tl(t1, t1, ~0x0000FFFF0000FFFFULL);
2656 tcg_gen_or_tl(t1, t0, t1);
2657 tcg_gen_shri_tl(t0, t1, 32);
2658 tcg_gen_shli_tl(t1, t1, 32);
2659 tcg_gen_or_tl(t0, t0, t1);
2663 MIPS_INVAL("bsfhl");
2664 generate_exception(ctx, EXCP_RI);
2669 gen_store_gpr(t0, rd);
2674 #ifndef CONFIG_USER_ONLY
2675 /* CP0 (MMU and control) */
2676 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2678 TCGv_i32 r_tmp = tcg_temp_new_i32();
2680 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2681 tcg_gen_ext_i32_tl(t, r_tmp);
2682 tcg_temp_free_i32(r_tmp);
2685 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2687 tcg_gen_ld_tl(t, cpu_env, off);
2688 tcg_gen_ext32s_tl(t, t);
2691 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2693 TCGv_i32 r_tmp = tcg_temp_new_i32();
2695 tcg_gen_trunc_tl_i32(r_tmp, t);
2696 tcg_gen_st_i32(r_tmp, cpu_env, off);
2697 tcg_temp_free_i32(r_tmp);
2700 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2702 tcg_gen_ext32s_tl(t, t);
2703 tcg_gen_st_tl(t, cpu_env, off);
2706 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2708 const char *rn = "invalid";
2711 check_insn(env, ctx, ISA_MIPS32);
2717 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2721 check_insn(env, ctx, ASE_MT);
2722 gen_helper_mfc0_mvpcontrol(t0);
2726 check_insn(env, ctx, ASE_MT);
2727 gen_helper_mfc0_mvpconf0(t0);
2731 check_insn(env, ctx, ASE_MT);
2732 gen_helper_mfc0_mvpconf1(t0);
2742 gen_helper_mfc0_random(t0);
2746 check_insn(env, ctx, ASE_MT);
2747 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2751 check_insn(env, ctx, ASE_MT);
2752 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2756 check_insn(env, ctx, ASE_MT);
2757 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2761 check_insn(env, ctx, ASE_MT);
2762 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2766 check_insn(env, ctx, ASE_MT);
2767 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2771 check_insn(env, ctx, ASE_MT);
2772 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2773 rn = "VPEScheFBack";
2776 check_insn(env, ctx, ASE_MT);
2777 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2787 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2788 tcg_gen_ext32s_tl(t0, t0);
2792 check_insn(env, ctx, ASE_MT);
2793 gen_helper_mfc0_tcstatus(t0);
2797 check_insn(env, ctx, ASE_MT);
2798 gen_helper_mfc0_tcbind(t0);
2802 check_insn(env, ctx, ASE_MT);
2803 gen_helper_mfc0_tcrestart(t0);
2807 check_insn(env, ctx, ASE_MT);
2808 gen_helper_mfc0_tchalt(t0);
2812 check_insn(env, ctx, ASE_MT);
2813 gen_helper_mfc0_tccontext(t0);
2817 check_insn(env, ctx, ASE_MT);
2818 gen_helper_mfc0_tcschedule(t0);
2822 check_insn(env, ctx, ASE_MT);
2823 gen_helper_mfc0_tcschefback(t0);
2833 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2834 tcg_gen_ext32s_tl(t0, t0);
2844 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2845 tcg_gen_ext32s_tl(t0, t0);
2849 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2850 rn = "ContextConfig";
2859 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2863 check_insn(env, ctx, ISA_MIPS32R2);
2864 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2874 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2878 check_insn(env, ctx, ISA_MIPS32R2);
2879 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2883 check_insn(env, ctx, ISA_MIPS32R2);
2884 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2888 check_insn(env, ctx, ISA_MIPS32R2);
2889 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2893 check_insn(env, ctx, ISA_MIPS32R2);
2894 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2898 check_insn(env, ctx, ISA_MIPS32R2);
2899 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2909 check_insn(env, ctx, ISA_MIPS32R2);
2910 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
2920 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
2921 tcg_gen_ext32s_tl(t0, t0);
2931 /* Mark as an IO operation because we read the time. */
2934 gen_helper_mfc0_count(t0);
2937 ctx->bstate = BS_STOP;
2941 /* 6,7 are implementation dependent */
2949 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
2950 tcg_gen_ext32s_tl(t0, t0);
2960 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
2963 /* 6,7 are implementation dependent */
2971 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
2975 check_insn(env, ctx, ISA_MIPS32R2);
2976 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
2980 check_insn(env, ctx, ISA_MIPS32R2);
2981 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
2985 check_insn(env, ctx, ISA_MIPS32R2);
2986 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
2996 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3006 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3007 tcg_gen_ext32s_tl(t0, t0);
3017 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3021 check_insn(env, ctx, ISA_MIPS32R2);
3022 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3032 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3036 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3040 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3044 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3047 /* 4,5 are reserved */
3048 /* 6,7 are implementation dependent */
3050 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3054 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3064 gen_helper_mfc0_lladdr(t0);
3074 gen_helper_1i(mfc0_watchlo, t0, sel);
3084 gen_helper_1i(mfc0_watchhi, t0, sel);
3094 #if defined(TARGET_MIPS64)
3095 check_insn(env, ctx, ISA_MIPS3);
3096 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3097 tcg_gen_ext32s_tl(t0, t0);
3106 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3109 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3117 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3118 rn = "'Diagnostic"; /* implementation dependent */
3123 gen_helper_mfc0_debug(t0); /* EJTAG support */
3127 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3128 rn = "TraceControl";
3131 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3132 rn = "TraceControl2";
3135 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3136 rn = "UserTraceData";
3139 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3150 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3151 tcg_gen_ext32s_tl(t0, t0);
3161 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3162 rn = "Performance0";
3165 // gen_helper_mfc0_performance1(t0);
3166 rn = "Performance1";
3169 // gen_helper_mfc0_performance2(t0);
3170 rn = "Performance2";
3173 // gen_helper_mfc0_performance3(t0);
3174 rn = "Performance3";
3177 // gen_helper_mfc0_performance4(t0);
3178 rn = "Performance4";
3181 // gen_helper_mfc0_performance5(t0);
3182 rn = "Performance5";
3185 // gen_helper_mfc0_performance6(t0);
3186 rn = "Performance6";
3189 // gen_helper_mfc0_performance7(t0);
3190 rn = "Performance7";
3197 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3203 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3216 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3223 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3236 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3243 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3253 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3254 tcg_gen_ext32s_tl(t0, t0);
3265 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3275 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3279 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3280 generate_exception(ctx, EXCP_RI);
3283 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3285 const char *rn = "invalid";
3288 check_insn(env, ctx, ISA_MIPS32);
3297 gen_helper_mtc0_index(t0);
3301 check_insn(env, ctx, ASE_MT);
3302 gen_helper_mtc0_mvpcontrol(t0);
3306 check_insn(env, ctx, ASE_MT);
3311 check_insn(env, ctx, ASE_MT);
3326 check_insn(env, ctx, ASE_MT);
3327 gen_helper_mtc0_vpecontrol(t0);
3331 check_insn(env, ctx, ASE_MT);
3332 gen_helper_mtc0_vpeconf0(t0);
3336 check_insn(env, ctx, ASE_MT);
3337 gen_helper_mtc0_vpeconf1(t0);
3341 check_insn(env, ctx, ASE_MT);
3342 gen_helper_mtc0_yqmask(t0);
3346 check_insn(env, ctx, ASE_MT);
3347 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3351 check_insn(env, ctx, ASE_MT);
3352 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3353 rn = "VPEScheFBack";
3356 check_insn(env, ctx, ASE_MT);
3357 gen_helper_mtc0_vpeopt(t0);
3367 gen_helper_mtc0_entrylo0(t0);
3371 check_insn(env, ctx, ASE_MT);
3372 gen_helper_mtc0_tcstatus(t0);
3376 check_insn(env, ctx, ASE_MT);
3377 gen_helper_mtc0_tcbind(t0);
3381 check_insn(env, ctx, ASE_MT);
3382 gen_helper_mtc0_tcrestart(t0);
3386 check_insn(env, ctx, ASE_MT);
3387 gen_helper_mtc0_tchalt(t0);
3391 check_insn(env, ctx, ASE_MT);
3392 gen_helper_mtc0_tccontext(t0);
3396 check_insn(env, ctx, ASE_MT);
3397 gen_helper_mtc0_tcschedule(t0);
3401 check_insn(env, ctx, ASE_MT);
3402 gen_helper_mtc0_tcschefback(t0);
3412 gen_helper_mtc0_entrylo1(t0);
3422 gen_helper_mtc0_context(t0);
3426 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3427 rn = "ContextConfig";
3436 gen_helper_mtc0_pagemask(t0);
3440 check_insn(env, ctx, ISA_MIPS32R2);
3441 gen_helper_mtc0_pagegrain(t0);
3451 gen_helper_mtc0_wired(t0);
3455 check_insn(env, ctx, ISA_MIPS32R2);
3456 gen_helper_mtc0_srsconf0(t0);
3460 check_insn(env, ctx, ISA_MIPS32R2);
3461 gen_helper_mtc0_srsconf1(t0);
3465 check_insn(env, ctx, ISA_MIPS32R2);
3466 gen_helper_mtc0_srsconf2(t0);
3470 check_insn(env, ctx, ISA_MIPS32R2);
3471 gen_helper_mtc0_srsconf3(t0);
3475 check_insn(env, ctx, ISA_MIPS32R2);
3476 gen_helper_mtc0_srsconf4(t0);
3486 check_insn(env, ctx, ISA_MIPS32R2);
3487 gen_helper_mtc0_hwrena(t0);
3501 gen_helper_mtc0_count(t0);
3504 /* 6,7 are implementation dependent */
3508 /* Stop translation as we may have switched the execution mode */
3509 ctx->bstate = BS_STOP;
3514 gen_helper_mtc0_entryhi(t0);
3524 gen_helper_mtc0_compare(t0);
3527 /* 6,7 are implementation dependent */
3531 /* Stop translation as we may have switched the execution mode */
3532 ctx->bstate = BS_STOP;
3537 gen_helper_mtc0_status(t0);
3538 /* BS_STOP isn't good enough here, hflags may have changed. */
3539 gen_save_pc(ctx->pc + 4);
3540 ctx->bstate = BS_EXCP;
3544 check_insn(env, ctx, ISA_MIPS32R2);
3545 gen_helper_mtc0_intctl(t0);
3546 /* Stop translation as we may have switched the execution mode */
3547 ctx->bstate = BS_STOP;
3551 check_insn(env, ctx, ISA_MIPS32R2);
3552 gen_helper_mtc0_srsctl(t0);
3553 /* Stop translation as we may have switched the execution mode */
3554 ctx->bstate = BS_STOP;
3558 check_insn(env, ctx, ISA_MIPS32R2);
3559 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3560 /* Stop translation as we may have switched the execution mode */
3561 ctx->bstate = BS_STOP;
3571 gen_helper_mtc0_cause(t0);
3577 /* Stop translation as we may have switched the execution mode */
3578 ctx->bstate = BS_STOP;
3583 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3597 check_insn(env, ctx, ISA_MIPS32R2);
3598 gen_helper_mtc0_ebase(t0);
3608 gen_helper_mtc0_config0(t0);
3610 /* Stop translation as we may have switched the execution mode */
3611 ctx->bstate = BS_STOP;
3614 /* ignored, read only */
3618 gen_helper_mtc0_config2(t0);
3620 /* Stop translation as we may have switched the execution mode */
3621 ctx->bstate = BS_STOP;
3624 /* ignored, read only */
3627 /* 4,5 are reserved */
3628 /* 6,7 are implementation dependent */
3638 rn = "Invalid config selector";
3655 gen_helper_1i(mtc0_watchlo, t0, sel);
3665 gen_helper_1i(mtc0_watchhi, t0, sel);
3675 #if defined(TARGET_MIPS64)
3676 check_insn(env, ctx, ISA_MIPS3);
3677 gen_helper_mtc0_xcontext(t0);
3686 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3689 gen_helper_mtc0_framemask(t0);
3698 rn = "Diagnostic"; /* implementation dependent */
3703 gen_helper_mtc0_debug(t0); /* EJTAG support */
3704 /* BS_STOP isn't good enough here, hflags may have changed. */
3705 gen_save_pc(ctx->pc + 4);
3706 ctx->bstate = BS_EXCP;
3710 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3711 rn = "TraceControl";
3712 /* Stop translation as we may have switched the execution mode */
3713 ctx->bstate = BS_STOP;
3716 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3717 rn = "TraceControl2";
3718 /* Stop translation as we may have switched the execution mode */
3719 ctx->bstate = BS_STOP;
3722 /* Stop translation as we may have switched the execution mode */
3723 ctx->bstate = BS_STOP;
3724 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3725 rn = "UserTraceData";
3726 /* Stop translation as we may have switched the execution mode */
3727 ctx->bstate = BS_STOP;
3730 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3731 /* Stop translation as we may have switched the execution mode */
3732 ctx->bstate = BS_STOP;
3743 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3753 gen_helper_mtc0_performance0(t0);
3754 rn = "Performance0";
3757 // gen_helper_mtc0_performance1(t0);
3758 rn = "Performance1";
3761 // gen_helper_mtc0_performance2(t0);
3762 rn = "Performance2";
3765 // gen_helper_mtc0_performance3(t0);
3766 rn = "Performance3";
3769 // gen_helper_mtc0_performance4(t0);
3770 rn = "Performance4";
3773 // gen_helper_mtc0_performance5(t0);
3774 rn = "Performance5";
3777 // gen_helper_mtc0_performance6(t0);
3778 rn = "Performance6";
3781 // gen_helper_mtc0_performance7(t0);
3782 rn = "Performance7";
3808 gen_helper_mtc0_taglo(t0);
3815 gen_helper_mtc0_datalo(t0);
3828 gen_helper_mtc0_taghi(t0);
3835 gen_helper_mtc0_datahi(t0);
3846 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3857 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3863 /* Stop translation as we may have switched the execution mode */
3864 ctx->bstate = BS_STOP;
3869 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3870 /* For simplicity assume that all writes can cause interrupts. */
3873 ctx->bstate = BS_STOP;
3878 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3879 generate_exception(ctx, EXCP_RI);
3882 #if defined(TARGET_MIPS64)
3883 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3885 const char *rn = "invalid";
3888 check_insn(env, ctx, ISA_MIPS64);
3894 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
3898 check_insn(env, ctx, ASE_MT);
3899 gen_helper_mfc0_mvpcontrol(t0);
3903 check_insn(env, ctx, ASE_MT);
3904 gen_helper_mfc0_mvpconf0(t0);
3908 check_insn(env, ctx, ASE_MT);
3909 gen_helper_mfc0_mvpconf1(t0);
3919 gen_helper_mfc0_random(t0);
3923 check_insn(env, ctx, ASE_MT);
3924 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
3928 check_insn(env, ctx, ASE_MT);
3929 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
3933 check_insn(env, ctx, ASE_MT);
3934 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
3938 check_insn(env, ctx, ASE_MT);
3939 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
3943 check_insn(env, ctx, ASE_MT);
3944 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
3948 check_insn(env, ctx, ASE_MT);
3949 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3950 rn = "VPEScheFBack";
3953 check_insn(env, ctx, ASE_MT);
3954 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
3964 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
3968 check_insn(env, ctx, ASE_MT);
3969 gen_helper_mfc0_tcstatus(t0);
3973 check_insn(env, ctx, ASE_MT);
3974 gen_helper_mfc0_tcbind(t0);
3978 check_insn(env, ctx, ASE_MT);
3979 gen_helper_dmfc0_tcrestart(t0);
3983 check_insn(env, ctx, ASE_MT);
3984 gen_helper_dmfc0_tchalt(t0);
3988 check_insn(env, ctx, ASE_MT);
3989 gen_helper_dmfc0_tccontext(t0);
3993 check_insn(env, ctx, ASE_MT);
3994 gen_helper_dmfc0_tcschedule(t0);
3998 check_insn(env, ctx, ASE_MT);
3999 gen_helper_dmfc0_tcschefback(t0);
4009 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4019 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4023 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4024 rn = "ContextConfig";
4033 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4037 check_insn(env, ctx, ISA_MIPS32R2);
4038 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4048 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4052 check_insn(env, ctx, ISA_MIPS32R2);
4053 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4057 check_insn(env, ctx, ISA_MIPS32R2);
4058 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4062 check_insn(env, ctx, ISA_MIPS32R2);
4063 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4067 check_insn(env, ctx, ISA_MIPS32R2);
4068 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4072 check_insn(env, ctx, ISA_MIPS32R2);
4073 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4083 check_insn(env, ctx, ISA_MIPS32R2);
4084 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4094 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4104 /* Mark as an IO operation because we read the time. */
4107 gen_helper_mfc0_count(t0);
4110 ctx->bstate = BS_STOP;
4114 /* 6,7 are implementation dependent */
4122 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4132 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4135 /* 6,7 are implementation dependent */
4143 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4147 check_insn(env, ctx, ISA_MIPS32R2);
4148 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4152 check_insn(env, ctx, ISA_MIPS32R2);
4153 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4157 check_insn(env, ctx, ISA_MIPS32R2);
4158 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4168 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4178 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4188 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4192 check_insn(env, ctx, ISA_MIPS32R2);
4193 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4203 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4207 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4211 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4215 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4218 /* 6,7 are implementation dependent */
4220 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4224 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4234 gen_helper_dmfc0_lladdr(t0);
4244 gen_helper_1i(dmfc0_watchlo, t0, sel);
4254 gen_helper_1i(mfc0_watchhi, t0, sel);
4264 check_insn(env, ctx, ISA_MIPS3);
4265 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4273 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4276 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4284 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4285 rn = "'Diagnostic"; /* implementation dependent */
4290 gen_helper_mfc0_debug(t0); /* EJTAG support */
4294 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4295 rn = "TraceControl";
4298 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4299 rn = "TraceControl2";
4302 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4303 rn = "UserTraceData";
4306 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4317 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4327 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4328 rn = "Performance0";
4331 // gen_helper_dmfc0_performance1(t0);
4332 rn = "Performance1";
4335 // gen_helper_dmfc0_performance2(t0);
4336 rn = "Performance2";
4339 // gen_helper_dmfc0_performance3(t0);
4340 rn = "Performance3";
4343 // gen_helper_dmfc0_performance4(t0);
4344 rn = "Performance4";
4347 // gen_helper_dmfc0_performance5(t0);
4348 rn = "Performance5";
4351 // gen_helper_dmfc0_performance6(t0);
4352 rn = "Performance6";
4355 // gen_helper_dmfc0_performance7(t0);
4356 rn = "Performance7";
4363 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4370 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4383 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4390 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4403 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4410 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4420 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4431 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4441 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4445 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4446 generate_exception(ctx, EXCP_RI);
4449 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4451 const char *rn = "invalid";
4454 check_insn(env, ctx, ISA_MIPS64);
4463 gen_helper_mtc0_index(t0);
4467 check_insn(env, ctx, ASE_MT);
4468 gen_helper_mtc0_mvpcontrol(t0);
4472 check_insn(env, ctx, ASE_MT);
4477 check_insn(env, ctx, ASE_MT);
4492 check_insn(env, ctx, ASE_MT);
4493 gen_helper_mtc0_vpecontrol(t0);
4497 check_insn(env, ctx, ASE_MT);
4498 gen_helper_mtc0_vpeconf0(t0);
4502 check_insn(env, ctx, ASE_MT);
4503 gen_helper_mtc0_vpeconf1(t0);
4507 check_insn(env, ctx, ASE_MT);
4508 gen_helper_mtc0_yqmask(t0);
4512 check_insn(env, ctx, ASE_MT);
4513 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4517 check_insn(env, ctx, ASE_MT);
4518 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4519 rn = "VPEScheFBack";
4522 check_insn(env, ctx, ASE_MT);
4523 gen_helper_mtc0_vpeopt(t0);
4533 gen_helper_mtc0_entrylo0(t0);
4537 check_insn(env, ctx, ASE_MT);
4538 gen_helper_mtc0_tcstatus(t0);
4542 check_insn(env, ctx, ASE_MT);
4543 gen_helper_mtc0_tcbind(t0);
4547 check_insn(env, ctx, ASE_MT);
4548 gen_helper_mtc0_tcrestart(t0);
4552 check_insn(env, ctx, ASE_MT);
4553 gen_helper_mtc0_tchalt(t0);
4557 check_insn(env, ctx, ASE_MT);
4558 gen_helper_mtc0_tccontext(t0);
4562 check_insn(env, ctx, ASE_MT);
4563 gen_helper_mtc0_tcschedule(t0);
4567 check_insn(env, ctx, ASE_MT);
4568 gen_helper_mtc0_tcschefback(t0);
4578 gen_helper_mtc0_entrylo1(t0);
4588 gen_helper_mtc0_context(t0);
4592 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4593 rn = "ContextConfig";
4602 gen_helper_mtc0_pagemask(t0);
4606 check_insn(env, ctx, ISA_MIPS32R2);
4607 gen_helper_mtc0_pagegrain(t0);
4617 gen_helper_mtc0_wired(t0);
4621 check_insn(env, ctx, ISA_MIPS32R2);
4622 gen_helper_mtc0_srsconf0(t0);
4626 check_insn(env, ctx, ISA_MIPS32R2);
4627 gen_helper_mtc0_srsconf1(t0);
4631 check_insn(env, ctx, ISA_MIPS32R2);
4632 gen_helper_mtc0_srsconf2(t0);
4636 check_insn(env, ctx, ISA_MIPS32R2);
4637 gen_helper_mtc0_srsconf3(t0);
4641 check_insn(env, ctx, ISA_MIPS32R2);
4642 gen_helper_mtc0_srsconf4(t0);
4652 check_insn(env, ctx, ISA_MIPS32R2);
4653 gen_helper_mtc0_hwrena(t0);
4667 gen_helper_mtc0_count(t0);
4670 /* 6,7 are implementation dependent */
4674 /* Stop translation as we may have switched the execution mode */
4675 ctx->bstate = BS_STOP;
4680 gen_helper_mtc0_entryhi(t0);
4690 gen_helper_mtc0_compare(t0);
4693 /* 6,7 are implementation dependent */
4697 /* Stop translation as we may have switched the execution mode */
4698 ctx->bstate = BS_STOP;
4703 gen_helper_mtc0_status(t0);
4704 /* BS_STOP isn't good enough here, hflags may have changed. */
4705 gen_save_pc(ctx->pc + 4);
4706 ctx->bstate = BS_EXCP;
4710 check_insn(env, ctx, ISA_MIPS32R2);
4711 gen_helper_mtc0_intctl(t0);
4712 /* Stop translation as we may have switched the execution mode */
4713 ctx->bstate = BS_STOP;
4717 check_insn(env, ctx, ISA_MIPS32R2);
4718 gen_helper_mtc0_srsctl(t0);
4719 /* Stop translation as we may have switched the execution mode */
4720 ctx->bstate = BS_STOP;
4724 check_insn(env, ctx, ISA_MIPS32R2);
4725 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4726 /* Stop translation as we may have switched the execution mode */
4727 ctx->bstate = BS_STOP;
4737 gen_helper_mtc0_cause(t0);
4743 /* Stop translation as we may have switched the execution mode */
4744 ctx->bstate = BS_STOP;
4749 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4763 check_insn(env, ctx, ISA_MIPS32R2);
4764 gen_helper_mtc0_ebase(t0);
4774 gen_helper_mtc0_config0(t0);
4776 /* Stop translation as we may have switched the execution mode */
4777 ctx->bstate = BS_STOP;
4784 gen_helper_mtc0_config2(t0);
4786 /* Stop translation as we may have switched the execution mode */
4787 ctx->bstate = BS_STOP;
4793 /* 6,7 are implementation dependent */
4795 rn = "Invalid config selector";
4812 gen_helper_1i(mtc0_watchlo, t0, sel);
4822 gen_helper_1i(mtc0_watchhi, t0, sel);
4832 check_insn(env, ctx, ISA_MIPS3);
4833 gen_helper_mtc0_xcontext(t0);
4841 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4844 gen_helper_mtc0_framemask(t0);
4853 rn = "Diagnostic"; /* implementation dependent */
4858 gen_helper_mtc0_debug(t0); /* EJTAG support */
4859 /* BS_STOP isn't good enough here, hflags may have changed. */
4860 gen_save_pc(ctx->pc + 4);
4861 ctx->bstate = BS_EXCP;
4865 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4866 /* Stop translation as we may have switched the execution mode */
4867 ctx->bstate = BS_STOP;
4868 rn = "TraceControl";
4871 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4872 /* Stop translation as we may have switched the execution mode */
4873 ctx->bstate = BS_STOP;
4874 rn = "TraceControl2";
4877 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4878 /* Stop translation as we may have switched the execution mode */
4879 ctx->bstate = BS_STOP;
4880 rn = "UserTraceData";
4883 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4884 /* Stop translation as we may have switched the execution mode */
4885 ctx->bstate = BS_STOP;
4896 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4906 gen_helper_mtc0_performance0(t0);
4907 rn = "Performance0";
4910 // gen_helper_mtc0_performance1(t0);
4911 rn = "Performance1";
4914 // gen_helper_mtc0_performance2(t0);
4915 rn = "Performance2";
4918 // gen_helper_mtc0_performance3(t0);
4919 rn = "Performance3";
4922 // gen_helper_mtc0_performance4(t0);
4923 rn = "Performance4";
4926 // gen_helper_mtc0_performance5(t0);
4927 rn = "Performance5";
4930 // gen_helper_mtc0_performance6(t0);
4931 rn = "Performance6";
4934 // gen_helper_mtc0_performance7(t0);
4935 rn = "Performance7";
4961 gen_helper_mtc0_taglo(t0);
4968 gen_helper_mtc0_datalo(t0);
4981 gen_helper_mtc0_taghi(t0);
4988 gen_helper_mtc0_datahi(t0);
4999 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5010 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5016 /* Stop translation as we may have switched the execution mode */
5017 ctx->bstate = BS_STOP;
5022 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5023 /* For simplicity assume that all writes can cause interrupts. */
5026 ctx->bstate = BS_STOP;
5031 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5032 generate_exception(ctx, EXCP_RI);
5034 #endif /* TARGET_MIPS64 */
5036 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5037 int u, int sel, int h)
5039 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5040 TCGv t0 = tcg_temp_local_new();
5042 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5043 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5044 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5045 tcg_gen_movi_tl(t0, -1);
5046 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5047 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5048 tcg_gen_movi_tl(t0, -1);
5054 gen_helper_mftc0_tcstatus(t0);
5057 gen_helper_mftc0_tcbind(t0);
5060 gen_helper_mftc0_tcrestart(t0);
5063 gen_helper_mftc0_tchalt(t0);
5066 gen_helper_mftc0_tccontext(t0);
5069 gen_helper_mftc0_tcschedule(t0);
5072 gen_helper_mftc0_tcschefback(t0);
5075 gen_mfc0(env, ctx, t0, rt, sel);
5082 gen_helper_mftc0_entryhi(t0);
5085 gen_mfc0(env, ctx, t0, rt, sel);
5091 gen_helper_mftc0_status(t0);
5094 gen_mfc0(env, ctx, t0, rt, sel);
5100 gen_helper_mftc0_debug(t0);
5103 gen_mfc0(env, ctx, t0, rt, sel);
5108 gen_mfc0(env, ctx, t0, rt, sel);
5110 } else switch (sel) {
5111 /* GPR registers. */
5113 gen_helper_1i(mftgpr, t0, rt);
5115 /* Auxiliary CPU registers */
5119 gen_helper_1i(mftlo, t0, 0);
5122 gen_helper_1i(mfthi, t0, 0);
5125 gen_helper_1i(mftacx, t0, 0);
5128 gen_helper_1i(mftlo, t0, 1);
5131 gen_helper_1i(mfthi, t0, 1);
5134 gen_helper_1i(mftacx, t0, 1);
5137 gen_helper_1i(mftlo, t0, 2);
5140 gen_helper_1i(mfthi, t0, 2);
5143 gen_helper_1i(mftacx, t0, 2);
5146 gen_helper_1i(mftlo, t0, 3);
5149 gen_helper_1i(mfthi, t0, 3);
5152 gen_helper_1i(mftacx, t0, 3);
5155 gen_helper_mftdsp(t0);
5161 /* Floating point (COP1). */
5163 /* XXX: For now we support only a single FPU context. */
5165 TCGv_i32 fp0 = tcg_temp_new_i32();
5167 gen_load_fpr32(fp0, rt);
5168 tcg_gen_ext_i32_tl(t0, fp0);
5169 tcg_temp_free_i32(fp0);
5171 TCGv_i32 fp0 = tcg_temp_new_i32();
5173 gen_load_fpr32h(fp0, rt);
5174 tcg_gen_ext_i32_tl(t0, fp0);
5175 tcg_temp_free_i32(fp0);
5179 /* XXX: For now we support only a single FPU context. */
5180 gen_helper_1i(cfc1, t0, rt);
5182 /* COP2: Not implemented. */
5189 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5190 gen_store_gpr(t0, rd);
5196 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5197 generate_exception(ctx, EXCP_RI);
5200 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5201 int u, int sel, int h)
5203 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5204 TCGv t0 = tcg_temp_local_new();
5206 gen_load_gpr(t0, rt);
5207 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5208 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5209 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5211 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5212 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5219 gen_helper_mttc0_tcstatus(t0);
5222 gen_helper_mttc0_tcbind(t0);
5225 gen_helper_mttc0_tcrestart(t0);
5228 gen_helper_mttc0_tchalt(t0);
5231 gen_helper_mttc0_tccontext(t0);
5234 gen_helper_mttc0_tcschedule(t0);
5237 gen_helper_mttc0_tcschefback(t0);
5240 gen_mtc0(env, ctx, t0, rd, sel);
5247 gen_helper_mttc0_entryhi(t0);
5250 gen_mtc0(env, ctx, t0, rd, sel);
5256 gen_helper_mttc0_status(t0);
5259 gen_mtc0(env, ctx, t0, rd, sel);
5265 gen_helper_mttc0_debug(t0);
5268 gen_mtc0(env, ctx, t0, rd, sel);
5273 gen_mtc0(env, ctx, t0, rd, sel);
5275 } else switch (sel) {
5276 /* GPR registers. */
5278 gen_helper_1i(mttgpr, t0, rd);
5280 /* Auxiliary CPU registers */
5284 gen_helper_1i(mttlo, t0, 0);
5287 gen_helper_1i(mtthi, t0, 0);
5290 gen_helper_1i(mttacx, t0, 0);
5293 gen_helper_1i(mttlo, t0, 1);
5296 gen_helper_1i(mtthi, t0, 1);
5299 gen_helper_1i(mttacx, t0, 1);
5302 gen_helper_1i(mttlo, t0, 2);
5305 gen_helper_1i(mtthi, t0, 2);
5308 gen_helper_1i(mttacx, t0, 2);
5311 gen_helper_1i(mttlo, t0, 3);
5314 gen_helper_1i(mtthi, t0, 3);
5317 gen_helper_1i(mttacx, t0, 3);
5320 gen_helper_mttdsp(t0);
5326 /* Floating point (COP1). */
5328 /* XXX: For now we support only a single FPU context. */
5330 TCGv_i32 fp0 = tcg_temp_new_i32();
5332 tcg_gen_trunc_tl_i32(fp0, t0);
5333 gen_store_fpr32(fp0, rd);
5334 tcg_temp_free_i32(fp0);
5336 TCGv_i32 fp0 = tcg_temp_new_i32();
5338 tcg_gen_trunc_tl_i32(fp0, t0);
5339 gen_store_fpr32h(fp0, rd);
5340 tcg_temp_free_i32(fp0);
5344 /* XXX: For now we support only a single FPU context. */
5345 gen_helper_1i(ctc1, t0, rd);
5347 /* COP2: Not implemented. */
5354 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5360 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5361 generate_exception(ctx, EXCP_RI);
5364 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5366 const char *opn = "ldst";
5375 TCGv t0 = tcg_temp_local_new();
5377 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5378 gen_store_gpr(t0, rt);
5385 TCGv t0 = tcg_temp_local_new();
5387 gen_load_gpr(t0, rt);
5388 save_cpu_state(ctx, 1);
5389 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5394 #if defined(TARGET_MIPS64)
5396 check_insn(env, ctx, ISA_MIPS3);
5402 TCGv t0 = tcg_temp_local_new();
5404 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5405 gen_store_gpr(t0, rt);
5411 check_insn(env, ctx, ISA_MIPS3);
5413 TCGv t0 = tcg_temp_local_new();
5415 gen_load_gpr(t0, rt);
5416 save_cpu_state(ctx, 1);
5417 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5424 check_insn(env, ctx, ASE_MT);
5429 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5430 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5434 check_insn(env, ctx, ASE_MT);
5435 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5436 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5441 if (!env->tlb->helper_tlbwi)
5447 if (!env->tlb->helper_tlbwr)
5453 if (!env->tlb->helper_tlbp)
5459 if (!env->tlb->helper_tlbr)
5465 check_insn(env, ctx, ISA_MIPS2);
5466 save_cpu_state(ctx, 1);
5468 ctx->bstate = BS_EXCP;
5472 check_insn(env, ctx, ISA_MIPS32);
5473 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5475 generate_exception(ctx, EXCP_RI);
5477 save_cpu_state(ctx, 1);
5479 ctx->bstate = BS_EXCP;
5484 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5485 /* If we get an exception, we want to restart at next instruction */
5487 save_cpu_state(ctx, 1);
5490 ctx->bstate = BS_EXCP;
5495 generate_exception(ctx, EXCP_RI);
5498 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5500 #endif /* !CONFIG_USER_ONLY */
5502 /* CP1 Branches (before delay slot) */
5503 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5504 int32_t cc, int32_t offset)
5506 target_ulong btarget;
5507 const char *opn = "cp1 cond branch";
5508 TCGv_i32 t0 = tcg_temp_new_i32();
5511 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5513 btarget = ctx->pc + 4 + offset;
5518 int l1 = gen_new_label();
5519 int l2 = gen_new_label();
5522 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5523 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5524 tcg_gen_movi_i32(bcond, 0);
5527 tcg_gen_movi_i32(bcond, 1);
5534 int l1 = gen_new_label();
5535 int l2 = gen_new_label();
5538 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5539 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5540 tcg_gen_movi_i32(bcond, 0);
5543 tcg_gen_movi_i32(bcond, 1);
5550 int l1 = gen_new_label();
5551 int l2 = gen_new_label();
5554 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5555 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5556 tcg_gen_movi_i32(bcond, 0);
5559 tcg_gen_movi_i32(bcond, 1);
5566 int l1 = gen_new_label();
5567 int l2 = gen_new_label();
5570 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5571 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5572 tcg_gen_movi_i32(bcond, 0);
5575 tcg_gen_movi_i32(bcond, 1);
5580 ctx->hflags |= MIPS_HFLAG_BL;
5584 int l1 = gen_new_label();
5585 int l2 = gen_new_label();
5588 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5589 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5590 tcg_gen_movi_i32(bcond, 0);
5593 tcg_gen_movi_i32(bcond, 1);
5600 int l1 = gen_new_label();
5601 int l2 = gen_new_label();
5604 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5605 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5606 tcg_gen_movi_i32(bcond, 0);
5609 tcg_gen_movi_i32(bcond, 1);
5616 int l1 = gen_new_label();
5617 int l2 = gen_new_label();
5620 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5621 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5622 tcg_gen_movi_i32(bcond, 0);
5625 tcg_gen_movi_i32(bcond, 1);
5632 int l1 = gen_new_label();
5633 int l2 = gen_new_label();
5636 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5637 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5638 tcg_gen_movi_i32(bcond, 0);
5641 tcg_gen_movi_i32(bcond, 1);
5646 ctx->hflags |= MIPS_HFLAG_BC;
5650 generate_exception (ctx, EXCP_RI);
5653 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5654 ctx->hflags, btarget);
5655 ctx->btarget = btarget;
5658 tcg_temp_free_i32(t0);
5661 /* Coprocessor 1 (FPU) */
5663 #define FOP(func, fmt) (((fmt) << 21) | (func))
5665 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5667 const char *opn = "cp1 move";
5668 TCGv t0 = tcg_temp_local_new();
5673 TCGv_i32 fp0 = tcg_temp_new_i32();
5675 gen_load_fpr32(fp0, fs);
5676 tcg_gen_ext_i32_tl(t0, fp0);
5677 tcg_temp_free_i32(fp0);
5679 gen_store_gpr(t0, rt);
5683 gen_load_gpr(t0, rt);
5685 TCGv_i32 fp0 = tcg_temp_new_i32();
5687 tcg_gen_trunc_tl_i32(fp0, t0);
5688 gen_store_fpr32(fp0, fs);
5689 tcg_temp_free_i32(fp0);
5694 gen_helper_1i(cfc1, t0, fs);
5695 gen_store_gpr(t0, rt);
5699 gen_load_gpr(t0, rt);
5700 gen_helper_1i(ctc1, t0, fs);
5705 TCGv_i64 fp0 = tcg_temp_new_i64();
5707 gen_load_fpr64(ctx, fp0, fs);
5708 tcg_gen_trunc_i64_tl(t0, fp0);
5709 tcg_temp_free_i64(fp0);
5711 gen_store_gpr(t0, rt);
5715 gen_load_gpr(t0, rt);
5717 TCGv_i64 fp0 = tcg_temp_new_i64();
5719 tcg_gen_extu_tl_i64(fp0, t0);
5720 gen_store_fpr64(ctx, fp0, fs);
5721 tcg_temp_free_i64(fp0);
5727 TCGv_i32 fp0 = tcg_temp_new_i32();
5729 gen_load_fpr32h(fp0, fs);
5730 tcg_gen_ext_i32_tl(t0, fp0);
5731 tcg_temp_free_i32(fp0);
5733 gen_store_gpr(t0, rt);
5737 gen_load_gpr(t0, rt);
5739 TCGv_i32 fp0 = tcg_temp_new_i32();
5741 tcg_gen_trunc_tl_i32(fp0, t0);
5742 gen_store_fpr32h(fp0, fs);
5743 tcg_temp_free_i32(fp0);
5749 generate_exception (ctx, EXCP_RI);
5752 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5758 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5760 int l1 = gen_new_label();
5763 TCGv t0 = tcg_temp_local_new();
5764 TCGv_i32 r_tmp = tcg_temp_new_i32();
5767 ccbit = 1 << (24 + cc);
5775 gen_load_gpr(t0, rd);
5776 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5777 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5778 tcg_temp_free_i32(r_tmp);
5779 gen_load_gpr(t0, rs);
5781 gen_store_gpr(t0, rd);
5785 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5789 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5790 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5791 int l1 = gen_new_label();
5794 ccbit = 1 << (24 + cc);
5803 gen_load_fpr32(fp0, fd);
5804 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5805 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5806 tcg_temp_free_i32(r_tmp1);
5807 gen_load_fpr32(fp0, fs);
5809 gen_store_fpr32(fp0, fd);
5810 tcg_temp_free_i32(fp0);
5813 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
5817 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5818 TCGv_i64 fp0 = tcg_temp_local_new_i64();
5819 int l1 = gen_new_label();
5822 ccbit = 1 << (24 + cc);
5831 gen_load_fpr64(ctx, fp0, fd);
5832 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5833 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5834 tcg_temp_free_i32(r_tmp1);
5835 gen_load_fpr64(ctx, fp0, fs);
5837 gen_store_fpr64(ctx, fp0, fd);
5838 tcg_temp_free_i64(fp0);
5841 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
5843 uint32_t ccbit1, ccbit2;
5845 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5846 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5847 int l1 = gen_new_label();
5848 int l2 = gen_new_label();
5851 ccbit1 = 1 << (24 + cc);
5852 ccbit2 = 1 << (25 + cc);
5863 gen_load_fpr32(fp0, fd);
5864 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit1);
5865 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5866 gen_load_fpr32(fp0, fs);
5868 gen_store_fpr32(fp0, fd);
5870 gen_load_fpr32h(fp0, fd);
5871 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit2);
5872 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l2);
5873 gen_load_fpr32h(fp0, fs);
5875 gen_store_fpr32h(fp0, fd);
5877 tcg_temp_free_i32(r_tmp1);
5878 tcg_temp_free_i32(fp0);
5882 static void gen_farith (DisasContext *ctx, uint32_t op1,
5883 int ft, int fs, int fd, int cc)
5885 const char *opn = "farith";
5886 const char *condnames[] = {
5904 const char *condnames_abs[] = {
5922 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5923 uint32_t func = ctx->opcode & 0x3f;
5925 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5928 TCGv_i32 fp0 = tcg_temp_new_i32();
5929 TCGv_i32 fp1 = tcg_temp_new_i32();
5931 gen_load_fpr32(fp0, fs);
5932 gen_load_fpr32(fp1, ft);
5933 gen_helper_float_add_s(fp0, fp0, fp1);
5934 tcg_temp_free_i32(fp1);
5935 gen_store_fpr32(fp0, fd);
5936 tcg_temp_free_i32(fp0);
5943 TCGv_i32 fp0 = tcg_temp_new_i32();
5944 TCGv_i32 fp1 = tcg_temp_new_i32();
5946 gen_load_fpr32(fp0, fs);
5947 gen_load_fpr32(fp1, ft);
5948 gen_helper_float_sub_s(fp0, fp0, fp1);
5949 tcg_temp_free_i32(fp1);
5950 gen_store_fpr32(fp0, fd);
5951 tcg_temp_free_i32(fp0);
5958 TCGv_i32 fp0 = tcg_temp_new_i32();
5959 TCGv_i32 fp1 = tcg_temp_new_i32();
5961 gen_load_fpr32(fp0, fs);
5962 gen_load_fpr32(fp1, ft);
5963 gen_helper_float_mul_s(fp0, fp0, fp1);
5964 tcg_temp_free_i32(fp1);
5965 gen_store_fpr32(fp0, fd);
5966 tcg_temp_free_i32(fp0);
5973 TCGv_i32 fp0 = tcg_temp_new_i32();
5974 TCGv_i32 fp1 = tcg_temp_new_i32();
5976 gen_load_fpr32(fp0, fs);
5977 gen_load_fpr32(fp1, ft);
5978 gen_helper_float_div_s(fp0, fp0, fp1);
5979 tcg_temp_free_i32(fp1);
5980 gen_store_fpr32(fp0, fd);
5981 tcg_temp_free_i32(fp0);
5988 TCGv_i32 fp0 = tcg_temp_new_i32();
5990 gen_load_fpr32(fp0, fs);
5991 gen_helper_float_sqrt_s(fp0, fp0);
5992 gen_store_fpr32(fp0, fd);
5993 tcg_temp_free_i32(fp0);
5999 TCGv_i32 fp0 = tcg_temp_new_i32();
6001 gen_load_fpr32(fp0, fs);
6002 gen_helper_float_abs_s(fp0, fp0);
6003 gen_store_fpr32(fp0, fd);
6004 tcg_temp_free_i32(fp0);
6010 TCGv_i32 fp0 = tcg_temp_new_i32();
6012 gen_load_fpr32(fp0, fs);
6013 gen_store_fpr32(fp0, fd);
6014 tcg_temp_free_i32(fp0);
6020 TCGv_i32 fp0 = tcg_temp_new_i32();
6022 gen_load_fpr32(fp0, fs);
6023 gen_helper_float_chs_s(fp0, fp0);
6024 gen_store_fpr32(fp0, fd);
6025 tcg_temp_free_i32(fp0);
6030 check_cp1_64bitmode(ctx);
6032 TCGv_i32 fp32 = tcg_temp_new_i32();
6033 TCGv_i64 fp64 = tcg_temp_new_i64();
6035 gen_load_fpr32(fp32, fs);
6036 gen_helper_float_roundl_s(fp64, fp32);
6037 tcg_temp_free_i32(fp32);
6038 gen_store_fpr64(ctx, fp64, fd);
6039 tcg_temp_free_i64(fp64);
6044 check_cp1_64bitmode(ctx);
6046 TCGv_i32 fp32 = tcg_temp_new_i32();
6047 TCGv_i64 fp64 = tcg_temp_new_i64();
6049 gen_load_fpr32(fp32, fs);
6050 gen_helper_float_truncl_s(fp64, fp32);
6051 tcg_temp_free_i32(fp32);
6052 gen_store_fpr64(ctx, fp64, fd);
6053 tcg_temp_free_i64(fp64);
6058 check_cp1_64bitmode(ctx);
6060 TCGv_i32 fp32 = tcg_temp_new_i32();
6061 TCGv_i64 fp64 = tcg_temp_new_i64();
6063 gen_load_fpr32(fp32, fs);
6064 gen_helper_float_ceill_s(fp64, fp32);
6065 tcg_temp_free_i32(fp32);
6066 gen_store_fpr64(ctx, fp64, fd);
6067 tcg_temp_free_i64(fp64);
6072 check_cp1_64bitmode(ctx);
6074 TCGv_i32 fp32 = tcg_temp_new_i32();
6075 TCGv_i64 fp64 = tcg_temp_new_i64();
6077 gen_load_fpr32(fp32, fs);
6078 gen_helper_float_floorl_s(fp64, fp32);
6079 tcg_temp_free_i32(fp32);
6080 gen_store_fpr64(ctx, fp64, fd);
6081 tcg_temp_free_i64(fp64);
6087 TCGv_i32 fp0 = tcg_temp_new_i32();
6089 gen_load_fpr32(fp0, fs);
6090 gen_helper_float_roundw_s(fp0, fp0);
6091 gen_store_fpr32(fp0, fd);
6092 tcg_temp_free_i32(fp0);
6098 TCGv_i32 fp0 = tcg_temp_new_i32();
6100 gen_load_fpr32(fp0, fs);
6101 gen_helper_float_truncw_s(fp0, fp0);
6102 gen_store_fpr32(fp0, fd);
6103 tcg_temp_free_i32(fp0);
6109 TCGv_i32 fp0 = tcg_temp_new_i32();
6111 gen_load_fpr32(fp0, fs);
6112 gen_helper_float_ceilw_s(fp0, fp0);
6113 gen_store_fpr32(fp0, fd);
6114 tcg_temp_free_i32(fp0);
6120 TCGv_i32 fp0 = tcg_temp_new_i32();
6122 gen_load_fpr32(fp0, fs);
6123 gen_helper_float_floorw_s(fp0, fp0);
6124 gen_store_fpr32(fp0, fd);
6125 tcg_temp_free_i32(fp0);
6130 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6135 int l1 = gen_new_label();
6136 TCGv t0 = tcg_temp_new();
6137 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6139 gen_load_gpr(t0, ft);
6140 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6141 gen_load_fpr32(fp0, fs);
6142 gen_store_fpr32(fp0, fd);
6143 tcg_temp_free_i32(fp0);
6151 int l1 = gen_new_label();
6152 TCGv t0 = tcg_temp_new();
6153 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6155 gen_load_gpr(t0, ft);
6156 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6157 gen_load_fpr32(fp0, fs);
6158 gen_store_fpr32(fp0, fd);
6159 tcg_temp_free_i32(fp0);
6168 TCGv_i32 fp0 = tcg_temp_new_i32();
6170 gen_load_fpr32(fp0, fs);
6171 gen_helper_float_recip_s(fp0, fp0);
6172 gen_store_fpr32(fp0, fd);
6173 tcg_temp_free_i32(fp0);
6180 TCGv_i32 fp0 = tcg_temp_new_i32();
6182 gen_load_fpr32(fp0, fs);
6183 gen_helper_float_rsqrt_s(fp0, fp0);
6184 gen_store_fpr32(fp0, fd);
6185 tcg_temp_free_i32(fp0);
6190 check_cp1_64bitmode(ctx);
6192 TCGv_i32 fp0 = tcg_temp_new_i32();
6193 TCGv_i32 fp1 = tcg_temp_new_i32();
6195 gen_load_fpr32(fp0, fs);
6196 gen_load_fpr32(fp1, fd);
6197 gen_helper_float_recip2_s(fp0, fp0, fp1);
6198 tcg_temp_free_i32(fp1);
6199 gen_store_fpr32(fp0, fd);
6200 tcg_temp_free_i32(fp0);
6205 check_cp1_64bitmode(ctx);
6207 TCGv_i32 fp0 = tcg_temp_new_i32();
6209 gen_load_fpr32(fp0, fs);
6210 gen_helper_float_recip1_s(fp0, fp0);
6211 gen_store_fpr32(fp0, fd);
6212 tcg_temp_free_i32(fp0);
6217 check_cp1_64bitmode(ctx);
6219 TCGv_i32 fp0 = tcg_temp_new_i32();
6221 gen_load_fpr32(fp0, fs);
6222 gen_helper_float_rsqrt1_s(fp0, fp0);
6223 gen_store_fpr32(fp0, fd);
6224 tcg_temp_free_i32(fp0);
6229 check_cp1_64bitmode(ctx);
6231 TCGv_i32 fp0 = tcg_temp_new_i32();
6232 TCGv_i32 fp1 = tcg_temp_new_i32();
6234 gen_load_fpr32(fp0, fs);
6235 gen_load_fpr32(fp1, ft);
6236 gen_helper_float_rsqrt2_s(fp0, fp0, fp1);
6237 tcg_temp_free_i32(fp1);
6238 gen_store_fpr32(fp0, fd);
6239 tcg_temp_free_i32(fp0);
6244 check_cp1_registers(ctx, fd);
6246 TCGv_i32 fp32 = tcg_temp_new_i32();
6247 TCGv_i64 fp64 = tcg_temp_new_i64();
6249 gen_load_fpr32(fp32, fs);
6250 gen_helper_float_cvtd_s(fp64, fp32);
6251 tcg_temp_free_i32(fp32);
6252 gen_store_fpr64(ctx, fp64, fd);
6253 tcg_temp_free_i64(fp64);
6259 TCGv_i32 fp0 = tcg_temp_new_i32();
6261 gen_load_fpr32(fp0, fs);
6262 gen_helper_float_cvtw_s(fp0, fp0);
6263 gen_store_fpr32(fp0, fd);
6264 tcg_temp_free_i32(fp0);
6269 check_cp1_64bitmode(ctx);
6271 TCGv_i32 fp32 = tcg_temp_new_i32();
6272 TCGv_i64 fp64 = tcg_temp_new_i64();
6274 gen_load_fpr32(fp32, fs);
6275 gen_helper_float_cvtl_s(fp64, fp32);
6276 tcg_temp_free_i32(fp32);
6277 gen_store_fpr64(ctx, fp64, fd);
6278 tcg_temp_free_i64(fp64);
6283 check_cp1_64bitmode(ctx);
6285 TCGv_i64 fp64 = tcg_temp_new_i64();
6286 TCGv_i32 fp32_0 = tcg_temp_new_i32();
6287 TCGv_i32 fp32_1 = tcg_temp_new_i32();
6289 gen_load_fpr32(fp32_0, fs);
6290 gen_load_fpr32(fp32_1, ft);
6291 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6292 tcg_temp_free_i32(fp32_1);
6293 tcg_temp_free_i32(fp32_0);
6294 gen_store_fpr64(ctx, fp64, fd);
6295 tcg_temp_free_i64(fp64);
6316 TCGv_i32 fp0 = tcg_temp_new_i32();
6317 TCGv_i32 fp1 = tcg_temp_new_i32();
6319 gen_load_fpr32(fp0, fs);
6320 gen_load_fpr32(fp1, ft);
6321 if (ctx->opcode & (1 << 6)) {
6323 gen_cmpabs_s(func-48, fp0, fp1, cc);
6324 opn = condnames_abs[func-48];
6326 gen_cmp_s(func-48, fp0, fp1, cc);
6327 opn = condnames[func-48];
6329 tcg_temp_free_i32(fp0);
6330 tcg_temp_free_i32(fp1);
6334 check_cp1_registers(ctx, fs | ft | fd);
6336 TCGv_i64 fp0 = tcg_temp_new_i64();
6337 TCGv_i64 fp1 = tcg_temp_new_i64();
6339 gen_load_fpr64(ctx, fp0, fs);
6340 gen_load_fpr64(ctx, fp1, ft);
6341 gen_helper_float_add_d(fp0, fp0, fp1);
6342 tcg_temp_free_i64(fp1);
6343 gen_store_fpr64(ctx, fp0, fd);
6344 tcg_temp_free_i64(fp0);
6350 check_cp1_registers(ctx, fs | ft | fd);
6352 TCGv_i64 fp0 = tcg_temp_new_i64();
6353 TCGv_i64 fp1 = tcg_temp_new_i64();
6355 gen_load_fpr64(ctx, fp0, fs);
6356 gen_load_fpr64(ctx, fp1, ft);
6357 gen_helper_float_sub_d(fp0, fp0, fp1);
6358 tcg_temp_free_i64(fp1);
6359 gen_store_fpr64(ctx, fp0, fd);
6360 tcg_temp_free_i64(fp0);
6366 check_cp1_registers(ctx, fs | ft | fd);
6368 TCGv_i64 fp0 = tcg_temp_new_i64();
6369 TCGv_i64 fp1 = tcg_temp_new_i64();
6371 gen_load_fpr64(ctx, fp0, fs);
6372 gen_load_fpr64(ctx, fp1, ft);
6373 gen_helper_float_mul_d(fp0, fp0, fp1);
6374 tcg_temp_free_i64(fp1);
6375 gen_store_fpr64(ctx, fp0, fd);
6376 tcg_temp_free_i64(fp0);
6382 check_cp1_registers(ctx, fs | ft | fd);
6384 TCGv_i64 fp0 = tcg_temp_new_i64();
6385 TCGv_i64 fp1 = tcg_temp_new_i64();
6387 gen_load_fpr64(ctx, fp0, fs);
6388 gen_load_fpr64(ctx, fp1, ft);
6389 gen_helper_float_div_d(fp0, fp0, fp1);
6390 tcg_temp_free_i64(fp1);
6391 gen_store_fpr64(ctx, fp0, fd);
6392 tcg_temp_free_i64(fp0);
6398 check_cp1_registers(ctx, fs | fd);
6400 TCGv_i64 fp0 = tcg_temp_new_i64();
6402 gen_load_fpr64(ctx, fp0, fs);
6403 gen_helper_float_sqrt_d(fp0, fp0);
6404 gen_store_fpr64(ctx, fp0, fd);
6405 tcg_temp_free_i64(fp0);
6410 check_cp1_registers(ctx, fs | fd);
6412 TCGv_i64 fp0 = tcg_temp_new_i64();
6414 gen_load_fpr64(ctx, fp0, fs);
6415 gen_helper_float_abs_d(fp0, fp0);
6416 gen_store_fpr64(ctx, fp0, fd);
6417 tcg_temp_free_i64(fp0);
6422 check_cp1_registers(ctx, fs | fd);
6424 TCGv_i64 fp0 = tcg_temp_new_i64();
6426 gen_load_fpr64(ctx, fp0, fs);
6427 gen_store_fpr64(ctx, fp0, fd);
6428 tcg_temp_free_i64(fp0);
6433 check_cp1_registers(ctx, fs | fd);
6435 TCGv_i64 fp0 = tcg_temp_new_i64();
6437 gen_load_fpr64(ctx, fp0, fs);
6438 gen_helper_float_chs_d(fp0, fp0);
6439 gen_store_fpr64(ctx, fp0, fd);
6440 tcg_temp_free_i64(fp0);
6445 check_cp1_64bitmode(ctx);
6447 TCGv_i64 fp0 = tcg_temp_new_i64();
6449 gen_load_fpr64(ctx, fp0, fs);
6450 gen_helper_float_roundl_d(fp0, fp0);
6451 gen_store_fpr64(ctx, fp0, fd);
6452 tcg_temp_free_i64(fp0);
6457 check_cp1_64bitmode(ctx);
6459 TCGv_i64 fp0 = tcg_temp_new_i64();
6461 gen_load_fpr64(ctx, fp0, fs);
6462 gen_helper_float_truncl_d(fp0, fp0);
6463 gen_store_fpr64(ctx, fp0, fd);
6464 tcg_temp_free_i64(fp0);
6469 check_cp1_64bitmode(ctx);
6471 TCGv_i64 fp0 = tcg_temp_new_i64();
6473 gen_load_fpr64(ctx, fp0, fs);
6474 gen_helper_float_ceill_d(fp0, fp0);
6475 gen_store_fpr64(ctx, fp0, fd);
6476 tcg_temp_free_i64(fp0);
6481 check_cp1_64bitmode(ctx);
6483 TCGv_i64 fp0 = tcg_temp_new_i64();
6485 gen_load_fpr64(ctx, fp0, fs);
6486 gen_helper_float_floorl_d(fp0, fp0);
6487 gen_store_fpr64(ctx, fp0, fd);
6488 tcg_temp_free_i64(fp0);
6493 check_cp1_registers(ctx, fs);
6495 TCGv_i32 fp32 = tcg_temp_new_i32();
6496 TCGv_i64 fp64 = tcg_temp_new_i64();
6498 gen_load_fpr64(ctx, fp64, fs);
6499 gen_helper_float_roundw_d(fp32, fp64);
6500 tcg_temp_free_i64(fp64);
6501 gen_store_fpr32(fp32, fd);
6502 tcg_temp_free_i32(fp32);
6507 check_cp1_registers(ctx, fs);
6509 TCGv_i32 fp32 = tcg_temp_new_i32();
6510 TCGv_i64 fp64 = tcg_temp_new_i64();
6512 gen_load_fpr64(ctx, fp64, fs);
6513 gen_helper_float_truncw_d(fp32, fp64);
6514 tcg_temp_free_i64(fp64);
6515 gen_store_fpr32(fp32, fd);
6516 tcg_temp_free_i32(fp32);
6521 check_cp1_registers(ctx, fs);
6523 TCGv_i32 fp32 = tcg_temp_new_i32();
6524 TCGv_i64 fp64 = tcg_temp_new_i64();
6526 gen_load_fpr64(ctx, fp64, fs);
6527 gen_helper_float_ceilw_d(fp32, fp64);
6528 tcg_temp_free_i64(fp64);
6529 gen_store_fpr32(fp32, fd);
6530 tcg_temp_free_i32(fp32);
6535 check_cp1_registers(ctx, fs);
6537 TCGv_i32 fp32 = tcg_temp_new_i32();
6538 TCGv_i64 fp64 = tcg_temp_new_i64();
6540 gen_load_fpr64(ctx, fp64, fs);
6541 gen_helper_float_floorw_d(fp32, fp64);
6542 tcg_temp_free_i64(fp64);
6543 gen_store_fpr32(fp32, fd);
6544 tcg_temp_free_i32(fp32);
6549 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6554 int l1 = gen_new_label();
6555 TCGv t0 = tcg_temp_new();
6556 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6558 gen_load_gpr(t0, ft);
6559 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6560 gen_load_fpr64(ctx, fp0, fs);
6561 gen_store_fpr64(ctx, fp0, fd);
6562 tcg_temp_free_i64(fp0);
6570 int l1 = gen_new_label();
6571 TCGv t0 = tcg_temp_new();
6572 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6574 gen_load_gpr(t0, ft);
6575 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6576 gen_load_fpr64(ctx, fp0, fs);
6577 gen_store_fpr64(ctx, fp0, fd);
6578 tcg_temp_free_i64(fp0);
6585 check_cp1_64bitmode(ctx);
6587 TCGv_i64 fp0 = tcg_temp_new_i64();
6589 gen_load_fpr64(ctx, fp0, fs);
6590 gen_helper_float_recip_d(fp0, fp0);
6591 gen_store_fpr64(ctx, fp0, fd);
6592 tcg_temp_free_i64(fp0);
6597 check_cp1_64bitmode(ctx);
6599 TCGv_i64 fp0 = tcg_temp_new_i64();
6601 gen_load_fpr64(ctx, fp0, fs);
6602 gen_helper_float_rsqrt_d(fp0, fp0);
6603 gen_store_fpr64(ctx, fp0, fd);
6604 tcg_temp_free_i64(fp0);
6609 check_cp1_64bitmode(ctx);
6611 TCGv_i64 fp0 = tcg_temp_new_i64();
6612 TCGv_i64 fp1 = tcg_temp_new_i64();
6614 gen_load_fpr64(ctx, fp0, fs);
6615 gen_load_fpr64(ctx, fp1, ft);
6616 gen_helper_float_recip2_d(fp0, fp0, fp1);
6617 tcg_temp_free_i64(fp1);
6618 gen_store_fpr64(ctx, fp0, fd);
6619 tcg_temp_free_i64(fp0);
6624 check_cp1_64bitmode(ctx);
6626 TCGv_i64 fp0 = tcg_temp_new_i64();
6628 gen_load_fpr64(ctx, fp0, fs);
6629 gen_helper_float_recip1_d(fp0, fp0);
6630 gen_store_fpr64(ctx, fp0, fd);
6631 tcg_temp_free_i64(fp0);
6636 check_cp1_64bitmode(ctx);
6638 TCGv_i64 fp0 = tcg_temp_new_i64();
6640 gen_load_fpr64(ctx, fp0, fs);
6641 gen_helper_float_rsqrt1_d(fp0, fp0);
6642 gen_store_fpr64(ctx, fp0, fd);
6643 tcg_temp_free_i64(fp0);
6648 check_cp1_64bitmode(ctx);
6650 TCGv_i64 fp0 = tcg_temp_new_i64();
6651 TCGv_i64 fp1 = tcg_temp_new_i64();
6653 gen_load_fpr64(ctx, fp0, fs);
6654 gen_load_fpr64(ctx, fp1, ft);
6655 gen_helper_float_rsqrt2_d(fp0, fp0, fp1);
6656 tcg_temp_free_i64(fp1);
6657 gen_store_fpr64(ctx, fp0, fd);
6658 tcg_temp_free_i64(fp0);
6679 TCGv_i64 fp0 = tcg_temp_new_i64();
6680 TCGv_i64 fp1 = tcg_temp_new_i64();
6682 gen_load_fpr64(ctx, fp0, fs);
6683 gen_load_fpr64(ctx, fp1, ft);
6684 if (ctx->opcode & (1 << 6)) {
6686 check_cp1_registers(ctx, fs | ft);
6687 gen_cmpabs_d(func-48, fp0, fp1, cc);
6688 opn = condnames_abs[func-48];
6690 check_cp1_registers(ctx, fs | ft);
6691 gen_cmp_d(func-48, fp0, fp1, cc);
6692 opn = condnames[func-48];
6694 tcg_temp_free_i64(fp0);
6695 tcg_temp_free_i64(fp1);
6699 check_cp1_registers(ctx, fs);
6701 TCGv_i32 fp32 = tcg_temp_new_i32();
6702 TCGv_i64 fp64 = tcg_temp_new_i64();
6704 gen_load_fpr64(ctx, fp64, fs);
6705 gen_helper_float_cvts_d(fp32, fp64);
6706 tcg_temp_free_i64(fp64);
6707 gen_store_fpr32(fp32, fd);
6708 tcg_temp_free_i32(fp32);
6713 check_cp1_registers(ctx, fs);
6715 TCGv_i32 fp32 = tcg_temp_new_i32();
6716 TCGv_i64 fp64 = tcg_temp_new_i64();
6718 gen_load_fpr64(ctx, fp64, fs);
6719 gen_helper_float_cvtw_d(fp32, fp64);
6720 tcg_temp_free_i64(fp64);
6721 gen_store_fpr32(fp32, fd);
6722 tcg_temp_free_i32(fp32);
6727 check_cp1_64bitmode(ctx);
6729 TCGv_i64 fp0 = tcg_temp_new_i64();
6731 gen_load_fpr64(ctx, fp0, fs);
6732 gen_helper_float_cvtl_d(fp0, fp0);
6733 gen_store_fpr64(ctx, fp0, fd);
6734 tcg_temp_free_i64(fp0);
6740 TCGv_i32 fp0 = tcg_temp_new_i32();
6742 gen_load_fpr32(fp0, fs);
6743 gen_helper_float_cvts_w(fp0, fp0);
6744 gen_store_fpr32(fp0, fd);
6745 tcg_temp_free_i32(fp0);
6750 check_cp1_registers(ctx, fd);
6752 TCGv_i32 fp32 = tcg_temp_new_i32();
6753 TCGv_i64 fp64 = tcg_temp_new_i64();
6755 gen_load_fpr32(fp32, fs);
6756 gen_helper_float_cvtd_w(fp64, fp32);
6757 tcg_temp_free_i32(fp32);
6758 gen_store_fpr64(ctx, fp64, fd);
6759 tcg_temp_free_i64(fp64);
6764 check_cp1_64bitmode(ctx);
6766 TCGv_i32 fp32 = tcg_temp_new_i32();
6767 TCGv_i64 fp64 = tcg_temp_new_i64();
6769 gen_load_fpr64(ctx, fp64, fs);
6770 gen_helper_float_cvts_l(fp32, fp64);
6771 tcg_temp_free_i64(fp64);
6772 gen_store_fpr32(fp32, fd);
6773 tcg_temp_free_i32(fp32);
6778 check_cp1_64bitmode(ctx);
6780 TCGv_i64 fp0 = tcg_temp_new_i64();
6782 gen_load_fpr64(ctx, fp0, fs);
6783 gen_helper_float_cvtd_l(fp0, fp0);
6784 gen_store_fpr64(ctx, fp0, fd);
6785 tcg_temp_free_i64(fp0);
6790 check_cp1_64bitmode(ctx);
6792 TCGv_i64 fp0 = tcg_temp_new_i64();
6794 gen_load_fpr64(ctx, fp0, fs);
6795 gen_helper_float_cvtps_pw(fp0, fp0);
6796 gen_store_fpr64(ctx, fp0, fd);
6797 tcg_temp_free_i64(fp0);
6802 check_cp1_64bitmode(ctx);
6804 TCGv_i64 fp0 = tcg_temp_new_i64();
6805 TCGv_i64 fp1 = tcg_temp_new_i64();
6807 gen_load_fpr64(ctx, fp0, fs);
6808 gen_load_fpr64(ctx, fp1, ft);
6809 gen_helper_float_add_ps(fp0, fp0, fp1);
6810 tcg_temp_free_i64(fp1);
6811 gen_store_fpr64(ctx, fp0, fd);
6812 tcg_temp_free_i64(fp0);
6817 check_cp1_64bitmode(ctx);
6819 TCGv_i64 fp0 = tcg_temp_new_i64();
6820 TCGv_i64 fp1 = tcg_temp_new_i64();
6822 gen_load_fpr64(ctx, fp0, fs);
6823 gen_load_fpr64(ctx, fp1, ft);
6824 gen_helper_float_sub_ps(fp0, fp0, fp1);
6825 tcg_temp_free_i64(fp1);
6826 gen_store_fpr64(ctx, fp0, fd);
6827 tcg_temp_free_i64(fp0);
6832 check_cp1_64bitmode(ctx);
6834 TCGv_i64 fp0 = tcg_temp_new_i64();
6835 TCGv_i64 fp1 = tcg_temp_new_i64();
6837 gen_load_fpr64(ctx, fp0, fs);
6838 gen_load_fpr64(ctx, fp1, ft);
6839 gen_helper_float_mul_ps(fp0, fp0, fp1);
6840 tcg_temp_free_i64(fp1);
6841 gen_store_fpr64(ctx, fp0, fd);
6842 tcg_temp_free_i64(fp0);
6847 check_cp1_64bitmode(ctx);
6849 TCGv_i64 fp0 = tcg_temp_new_i64();
6851 gen_load_fpr64(ctx, fp0, fs);
6852 gen_helper_float_abs_ps(fp0, fp0);
6853 gen_store_fpr64(ctx, fp0, fd);
6854 tcg_temp_free_i64(fp0);
6859 check_cp1_64bitmode(ctx);
6861 TCGv_i64 fp0 = tcg_temp_new_i64();
6863 gen_load_fpr64(ctx, fp0, fs);
6864 gen_store_fpr64(ctx, fp0, fd);
6865 tcg_temp_free_i64(fp0);
6870 check_cp1_64bitmode(ctx);
6872 TCGv_i64 fp0 = tcg_temp_new_i64();
6874 gen_load_fpr64(ctx, fp0, fs);
6875 gen_helper_float_chs_ps(fp0, fp0);
6876 gen_store_fpr64(ctx, fp0, fd);
6877 tcg_temp_free_i64(fp0);
6882 check_cp1_64bitmode(ctx);
6883 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6887 check_cp1_64bitmode(ctx);
6889 int l1 = gen_new_label();
6890 TCGv t0 = tcg_temp_new();
6891 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6892 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6894 gen_load_gpr(t0, ft);
6895 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6896 gen_load_fpr32(fp0, fs);
6897 gen_load_fpr32h(fph0, fs);
6898 gen_store_fpr32(fp0, fd);
6899 gen_store_fpr32h(fph0, fd);
6900 tcg_temp_free_i32(fp0);
6901 tcg_temp_free_i32(fph0);
6908 check_cp1_64bitmode(ctx);
6910 int l1 = gen_new_label();
6911 TCGv t0 = tcg_temp_new();
6912 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6913 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6915 gen_load_gpr(t0, ft);
6916 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6917 gen_load_fpr32(fp0, fs);
6918 gen_load_fpr32h(fph0, fs);
6919 gen_store_fpr32(fp0, fd);
6920 gen_store_fpr32h(fph0, fd);
6921 tcg_temp_free_i32(fp0);
6922 tcg_temp_free_i32(fph0);
6929 check_cp1_64bitmode(ctx);
6931 TCGv_i64 fp0 = tcg_temp_new_i64();
6932 TCGv_i64 fp1 = tcg_temp_new_i64();
6934 gen_load_fpr64(ctx, fp0, ft);
6935 gen_load_fpr64(ctx, fp1, fs);
6936 gen_helper_float_addr_ps(fp0, fp0, fp1);
6937 tcg_temp_free_i64(fp1);
6938 gen_store_fpr64(ctx, fp0, fd);
6939 tcg_temp_free_i64(fp0);
6944 check_cp1_64bitmode(ctx);
6946 TCGv_i64 fp0 = tcg_temp_new_i64();
6947 TCGv_i64 fp1 = tcg_temp_new_i64();
6949 gen_load_fpr64(ctx, fp0, ft);
6950 gen_load_fpr64(ctx, fp1, fs);
6951 gen_helper_float_mulr_ps(fp0, fp0, fp1);
6952 tcg_temp_free_i64(fp1);
6953 gen_store_fpr64(ctx, fp0, fd);
6954 tcg_temp_free_i64(fp0);
6959 check_cp1_64bitmode(ctx);
6961 TCGv_i64 fp0 = tcg_temp_new_i64();
6962 TCGv_i64 fp1 = tcg_temp_new_i64();
6964 gen_load_fpr64(ctx, fp0, fs);
6965 gen_load_fpr64(ctx, fp1, fd);
6966 gen_helper_float_recip2_ps(fp0, fp0, fp1);
6967 tcg_temp_free_i64(fp1);
6968 gen_store_fpr64(ctx, fp0, fd);
6969 tcg_temp_free_i64(fp0);
6974 check_cp1_64bitmode(ctx);
6976 TCGv_i64 fp0 = tcg_temp_new_i64();
6978 gen_load_fpr64(ctx, fp0, fs);
6979 gen_helper_float_recip1_ps(fp0, fp0);
6980 gen_store_fpr64(ctx, fp0, fd);
6981 tcg_temp_free_i64(fp0);
6986 check_cp1_64bitmode(ctx);
6988 TCGv_i64 fp0 = tcg_temp_new_i64();
6990 gen_load_fpr64(ctx, fp0, fs);
6991 gen_helper_float_rsqrt1_ps(fp0, fp0);
6992 gen_store_fpr64(ctx, fp0, fd);
6993 tcg_temp_free_i64(fp0);
6998 check_cp1_64bitmode(ctx);
7000 TCGv_i64 fp0 = tcg_temp_new_i64();
7001 TCGv_i64 fp1 = tcg_temp_new_i64();
7003 gen_load_fpr64(ctx, fp0, fs);
7004 gen_load_fpr64(ctx, fp1, ft);
7005 gen_helper_float_rsqrt2_ps(fp0, fp0, fp1);
7006 tcg_temp_free_i64(fp1);
7007 gen_store_fpr64(ctx, fp0, fd);
7008 tcg_temp_free_i64(fp0);
7013 check_cp1_64bitmode(ctx);
7015 TCGv_i32 fp0 = tcg_temp_new_i32();
7017 gen_load_fpr32h(fp0, fs);
7018 gen_helper_float_cvts_pu(fp0, fp0);
7019 gen_store_fpr32(fp0, fd);
7020 tcg_temp_free_i32(fp0);
7025 check_cp1_64bitmode(ctx);
7027 TCGv_i64 fp0 = tcg_temp_new_i64();
7029 gen_load_fpr64(ctx, fp0, fs);
7030 gen_helper_float_cvtpw_ps(fp0, fp0);
7031 gen_store_fpr64(ctx, fp0, fd);
7032 tcg_temp_free_i64(fp0);
7037 check_cp1_64bitmode(ctx);
7039 TCGv_i32 fp0 = tcg_temp_new_i32();
7041 gen_load_fpr32(fp0, fs);
7042 gen_helper_float_cvts_pl(fp0, fp0);
7043 gen_store_fpr32(fp0, fd);
7044 tcg_temp_free_i32(fp0);
7049 check_cp1_64bitmode(ctx);
7051 TCGv_i32 fp0 = tcg_temp_new_i32();
7052 TCGv_i32 fp1 = tcg_temp_new_i32();
7054 gen_load_fpr32(fp0, fs);
7055 gen_load_fpr32(fp1, ft);
7056 gen_store_fpr32h(fp0, fd);
7057 gen_store_fpr32(fp1, fd);
7058 tcg_temp_free_i32(fp0);
7059 tcg_temp_free_i32(fp1);
7064 check_cp1_64bitmode(ctx);
7066 TCGv_i32 fp0 = tcg_temp_new_i32();
7067 TCGv_i32 fp1 = tcg_temp_new_i32();
7069 gen_load_fpr32(fp0, fs);
7070 gen_load_fpr32h(fp1, ft);
7071 gen_store_fpr32(fp1, fd);
7072 gen_store_fpr32h(fp0, fd);
7073 tcg_temp_free_i32(fp0);
7074 tcg_temp_free_i32(fp1);
7079 check_cp1_64bitmode(ctx);
7081 TCGv_i32 fp0 = tcg_temp_new_i32();
7082 TCGv_i32 fp1 = tcg_temp_new_i32();
7084 gen_load_fpr32h(fp0, fs);
7085 gen_load_fpr32(fp1, ft);
7086 gen_store_fpr32(fp1, fd);
7087 gen_store_fpr32h(fp0, fd);
7088 tcg_temp_free_i32(fp0);
7089 tcg_temp_free_i32(fp1);
7094 check_cp1_64bitmode(ctx);
7096 TCGv_i32 fp0 = tcg_temp_new_i32();
7097 TCGv_i32 fp1 = tcg_temp_new_i32();
7099 gen_load_fpr32h(fp0, fs);
7100 gen_load_fpr32h(fp1, ft);
7101 gen_store_fpr32(fp1, fd);
7102 gen_store_fpr32h(fp0, fd);
7103 tcg_temp_free_i32(fp0);
7104 tcg_temp_free_i32(fp1);
7124 check_cp1_64bitmode(ctx);
7126 TCGv_i64 fp0 = tcg_temp_new_i64();
7127 TCGv_i64 fp1 = tcg_temp_new_i64();
7129 gen_load_fpr64(ctx, fp0, fs);
7130 gen_load_fpr64(ctx, fp1, ft);
7131 if (ctx->opcode & (1 << 6)) {
7132 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7133 opn = condnames_abs[func-48];
7135 gen_cmp_ps(func-48, fp0, fp1, cc);
7136 opn = condnames[func-48];
7138 tcg_temp_free_i64(fp0);
7139 tcg_temp_free_i64(fp1);
7144 generate_exception (ctx, EXCP_RI);
7149 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7152 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7155 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7160 /* Coprocessor 3 (FPU) */
7161 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7162 int fd, int fs, int base, int index)
7164 const char *opn = "extended float load/store";
7166 TCGv t0 = tcg_temp_local_new();
7167 TCGv t1 = tcg_temp_local_new();
7170 gen_load_gpr(t0, index);
7171 } else if (index == 0) {
7172 gen_load_gpr(t0, base);
7174 gen_load_gpr(t0, index);
7175 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
7177 /* Don't do NOP if destination is zero: we must perform the actual
7183 TCGv_i32 fp0 = tcg_temp_new_i32();
7185 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
7186 tcg_gen_trunc_tl_i32(fp0, t1);
7187 gen_store_fpr32(fp0, fd);
7188 tcg_temp_free_i32(fp0);
7194 check_cp1_registers(ctx, fd);
7196 TCGv_i64 fp0 = tcg_temp_new_i64();
7198 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7199 gen_store_fpr64(ctx, fp0, fd);
7200 tcg_temp_free_i64(fp0);
7205 check_cp1_64bitmode(ctx);
7206 tcg_gen_andi_tl(t0, t0, ~0x7);
7208 TCGv_i64 fp0 = tcg_temp_new_i64();
7210 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7211 gen_store_fpr64(ctx, fp0, fd);
7212 tcg_temp_free_i64(fp0);
7219 TCGv_i32 fp0 = tcg_temp_new_i32();
7221 gen_load_fpr32(fp0, fs);
7222 tcg_gen_extu_i32_tl(t1, fp0);
7223 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
7224 tcg_temp_free_i32(fp0);
7231 check_cp1_registers(ctx, fs);
7233 TCGv_i64 fp0 = tcg_temp_new_i64();
7235 gen_load_fpr64(ctx, fp0, fs);
7236 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7237 tcg_temp_free_i64(fp0);
7243 check_cp1_64bitmode(ctx);
7244 tcg_gen_andi_tl(t0, t0, ~0x7);
7246 TCGv_i64 fp0 = tcg_temp_new_i64();
7248 gen_load_fpr64(ctx, fp0, fs);
7249 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7250 tcg_temp_free_i64(fp0);
7257 generate_exception(ctx, EXCP_RI);
7264 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7265 regnames[index], regnames[base]);
7268 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7269 int fd, int fr, int fs, int ft)
7271 const char *opn = "flt3_arith";
7275 check_cp1_64bitmode(ctx);
7277 TCGv t0 = tcg_temp_local_new();
7278 TCGv_i32 fp0 = tcg_temp_local_new_i32();
7279 TCGv_i32 fph0 = tcg_temp_local_new_i32();
7280 TCGv_i32 fp1 = tcg_temp_local_new_i32();
7281 TCGv_i32 fph1 = tcg_temp_local_new_i32();
7282 int l1 = gen_new_label();
7283 int l2 = gen_new_label();
7285 gen_load_gpr(t0, fr);
7286 tcg_gen_andi_tl(t0, t0, 0x7);
7287 gen_load_fpr32(fp0, fs);
7288 gen_load_fpr32h(fph0, fs);
7289 gen_load_fpr32(fp1, ft);
7290 gen_load_fpr32h(fph1, ft);
7292 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7293 gen_store_fpr32(fp0, fd);
7294 gen_store_fpr32h(fph0, fd);
7297 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7299 #ifdef TARGET_WORDS_BIGENDIAN
7300 gen_store_fpr32(fph1, fd);
7301 gen_store_fpr32h(fp0, fd);
7303 gen_store_fpr32(fph0, fd);
7304 gen_store_fpr32h(fp1, fd);
7307 tcg_temp_free_i32(fp0);
7308 tcg_temp_free_i32(fph0);
7309 tcg_temp_free_i32(fp1);
7310 tcg_temp_free_i32(fph1);
7317 TCGv_i32 fp0 = tcg_temp_new_i32();
7318 TCGv_i32 fp1 = tcg_temp_new_i32();
7319 TCGv_i32 fp2 = tcg_temp_new_i32();
7321 gen_load_fpr32(fp0, fs);
7322 gen_load_fpr32(fp1, ft);
7323 gen_load_fpr32(fp2, fr);
7324 gen_helper_float_muladd_s(fp2, fp0, fp1, fp2);
7325 tcg_temp_free_i32(fp0);
7326 tcg_temp_free_i32(fp1);
7327 gen_store_fpr32(fp2, fd);
7328 tcg_temp_free_i32(fp2);
7334 check_cp1_registers(ctx, fd | fs | ft | fr);
7336 TCGv_i64 fp0 = tcg_temp_new_i64();
7337 TCGv_i64 fp1 = tcg_temp_new_i64();
7338 TCGv_i64 fp2 = tcg_temp_new_i64();
7340 gen_load_fpr64(ctx, fp0, fs);
7341 gen_load_fpr64(ctx, fp1, ft);
7342 gen_load_fpr64(ctx, fp2, fr);
7343 gen_helper_float_muladd_d(fp2, fp0, fp1, fp2);
7344 tcg_temp_free_i64(fp0);
7345 tcg_temp_free_i64(fp1);
7346 gen_store_fpr64(ctx, fp2, fd);
7347 tcg_temp_free_i64(fp2);
7352 check_cp1_64bitmode(ctx);
7354 TCGv_i64 fp0 = tcg_temp_new_i64();
7355 TCGv_i64 fp1 = tcg_temp_new_i64();
7356 TCGv_i64 fp2 = tcg_temp_new_i64();
7358 gen_load_fpr64(ctx, fp0, fs);
7359 gen_load_fpr64(ctx, fp1, ft);
7360 gen_load_fpr64(ctx, fp2, fr);
7361 gen_helper_float_muladd_ps(fp2, fp0, fp1, fp2);
7362 tcg_temp_free_i64(fp0);
7363 tcg_temp_free_i64(fp1);
7364 gen_store_fpr64(ctx, fp2, fd);
7365 tcg_temp_free_i64(fp2);
7372 TCGv_i32 fp0 = tcg_temp_new_i32();
7373 TCGv_i32 fp1 = tcg_temp_new_i32();
7374 TCGv_i32 fp2 = tcg_temp_new_i32();
7376 gen_load_fpr32(fp0, fs);
7377 gen_load_fpr32(fp1, ft);
7378 gen_load_fpr32(fp2, fr);
7379 gen_helper_float_mulsub_s(fp2, fp0, fp1, fp2);
7380 tcg_temp_free_i32(fp0);
7381 tcg_temp_free_i32(fp1);
7382 gen_store_fpr32(fp2, fd);
7383 tcg_temp_free_i32(fp2);
7389 check_cp1_registers(ctx, fd | fs | ft | fr);
7391 TCGv_i64 fp0 = tcg_temp_new_i64();
7392 TCGv_i64 fp1 = tcg_temp_new_i64();
7393 TCGv_i64 fp2 = tcg_temp_new_i64();
7395 gen_load_fpr64(ctx, fp0, fs);
7396 gen_load_fpr64(ctx, fp1, ft);
7397 gen_load_fpr64(ctx, fp2, fr);
7398 gen_helper_float_mulsub_d(fp2, fp0, fp1, fp2);
7399 tcg_temp_free_i64(fp0);
7400 tcg_temp_free_i64(fp1);
7401 gen_store_fpr64(ctx, fp2, fd);
7402 tcg_temp_free_i64(fp2);
7407 check_cp1_64bitmode(ctx);
7409 TCGv_i64 fp0 = tcg_temp_new_i64();
7410 TCGv_i64 fp1 = tcg_temp_new_i64();
7411 TCGv_i64 fp2 = tcg_temp_new_i64();
7413 gen_load_fpr64(ctx, fp0, fs);
7414 gen_load_fpr64(ctx, fp1, ft);
7415 gen_load_fpr64(ctx, fp2, fr);
7416 gen_helper_float_mulsub_ps(fp2, fp0, fp1, fp2);
7417 tcg_temp_free_i64(fp0);
7418 tcg_temp_free_i64(fp1);
7419 gen_store_fpr64(ctx, fp2, fd);
7420 tcg_temp_free_i64(fp2);
7427 TCGv_i32 fp0 = tcg_temp_new_i32();
7428 TCGv_i32 fp1 = tcg_temp_new_i32();
7429 TCGv_i32 fp2 = tcg_temp_new_i32();
7431 gen_load_fpr32(fp0, fs);
7432 gen_load_fpr32(fp1, ft);
7433 gen_load_fpr32(fp2, fr);
7434 gen_helper_float_nmuladd_s(fp2, fp0, fp1, fp2);
7435 tcg_temp_free_i32(fp0);
7436 tcg_temp_free_i32(fp1);
7437 gen_store_fpr32(fp2, fd);
7438 tcg_temp_free_i32(fp2);
7444 check_cp1_registers(ctx, fd | fs | ft | fr);
7446 TCGv_i64 fp0 = tcg_temp_new_i64();
7447 TCGv_i64 fp1 = tcg_temp_new_i64();
7448 TCGv_i64 fp2 = tcg_temp_new_i64();
7450 gen_load_fpr64(ctx, fp0, fs);
7451 gen_load_fpr64(ctx, fp1, ft);
7452 gen_load_fpr64(ctx, fp2, fr);
7453 gen_helper_float_nmuladd_d(fp2, fp0, fp1, fp2);
7454 tcg_temp_free_i64(fp0);
7455 tcg_temp_free_i64(fp1);
7456 gen_store_fpr64(ctx, fp2, fd);
7457 tcg_temp_free_i64(fp2);
7462 check_cp1_64bitmode(ctx);
7464 TCGv_i64 fp0 = tcg_temp_new_i64();
7465 TCGv_i64 fp1 = tcg_temp_new_i64();
7466 TCGv_i64 fp2 = tcg_temp_new_i64();
7468 gen_load_fpr64(ctx, fp0, fs);
7469 gen_load_fpr64(ctx, fp1, ft);
7470 gen_load_fpr64(ctx, fp2, fr);
7471 gen_helper_float_nmuladd_ps(fp2, fp0, fp1, fp2);
7472 tcg_temp_free_i64(fp0);
7473 tcg_temp_free_i64(fp1);
7474 gen_store_fpr64(ctx, fp2, fd);
7475 tcg_temp_free_i64(fp2);
7482 TCGv_i32 fp0 = tcg_temp_new_i32();
7483 TCGv_i32 fp1 = tcg_temp_new_i32();
7484 TCGv_i32 fp2 = tcg_temp_new_i32();
7486 gen_load_fpr32(fp0, fs);
7487 gen_load_fpr32(fp1, ft);
7488 gen_load_fpr32(fp2, fr);
7489 gen_helper_float_nmulsub_s(fp2, fp0, fp1, fp2);
7490 tcg_temp_free_i32(fp0);
7491 tcg_temp_free_i32(fp1);
7492 gen_store_fpr32(fp2, fd);
7493 tcg_temp_free_i32(fp2);
7499 check_cp1_registers(ctx, fd | fs | ft | fr);
7501 TCGv_i64 fp0 = tcg_temp_new_i64();
7502 TCGv_i64 fp1 = tcg_temp_new_i64();
7503 TCGv_i64 fp2 = tcg_temp_new_i64();
7505 gen_load_fpr64(ctx, fp0, fs);
7506 gen_load_fpr64(ctx, fp1, ft);
7507 gen_load_fpr64(ctx, fp2, fr);
7508 gen_helper_float_nmulsub_d(fp2, fp0, fp1, fp2);
7509 tcg_temp_free_i64(fp0);
7510 tcg_temp_free_i64(fp1);
7511 gen_store_fpr64(ctx, fp2, fd);
7512 tcg_temp_free_i64(fp2);
7517 check_cp1_64bitmode(ctx);
7519 TCGv_i64 fp0 = tcg_temp_new_i64();
7520 TCGv_i64 fp1 = tcg_temp_new_i64();
7521 TCGv_i64 fp2 = tcg_temp_new_i64();
7523 gen_load_fpr64(ctx, fp0, fs);
7524 gen_load_fpr64(ctx, fp1, ft);
7525 gen_load_fpr64(ctx, fp2, fr);
7526 gen_helper_float_nmulsub_ps(fp2, fp0, fp1, fp2);
7527 tcg_temp_free_i64(fp0);
7528 tcg_temp_free_i64(fp1);
7529 gen_store_fpr64(ctx, fp2, fd);
7530 tcg_temp_free_i64(fp2);
7536 generate_exception (ctx, EXCP_RI);
7539 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7540 fregnames[fs], fregnames[ft]);
7543 /* ISA extensions (ASEs) */
7544 /* MIPS16 extension to MIPS32 */
7545 /* SmartMIPS extension to MIPS32 */
7547 #if defined(TARGET_MIPS64)
7549 /* MDMX extension to MIPS64 */
7553 static void decode_opc (CPUState *env, DisasContext *ctx)
7557 uint32_t op, op1, op2;
7560 /* make sure instructions are on a word boundary */
7561 if (ctx->pc & 0x3) {
7562 env->CP0_BadVAddr = ctx->pc;
7563 generate_exception(ctx, EXCP_AdEL);
7567 /* Handle blikely not taken case */
7568 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7569 int l1 = gen_new_label();
7571 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7572 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7574 TCGv_i32 r_tmp = tcg_temp_new_i32();
7576 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7577 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7578 tcg_temp_free_i32(r_tmp);
7580 gen_goto_tb(ctx, 1, ctx->pc + 4);
7583 op = MASK_OP_MAJOR(ctx->opcode);
7584 rs = (ctx->opcode >> 21) & 0x1f;
7585 rt = (ctx->opcode >> 16) & 0x1f;
7586 rd = (ctx->opcode >> 11) & 0x1f;
7587 sa = (ctx->opcode >> 6) & 0x1f;
7588 imm = (int16_t)ctx->opcode;
7591 op1 = MASK_SPECIAL(ctx->opcode);
7593 case OPC_SLL: /* Arithmetic with immediate */
7594 case OPC_SRL ... OPC_SRA:
7595 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7597 case OPC_MOVZ ... OPC_MOVN:
7598 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7599 case OPC_SLLV: /* Arithmetic */
7600 case OPC_SRLV ... OPC_SRAV:
7601 case OPC_ADD ... OPC_NOR:
7602 case OPC_SLT ... OPC_SLTU:
7603 gen_arith(env, ctx, op1, rd, rs, rt);
7605 case OPC_MULT ... OPC_DIVU:
7607 check_insn(env, ctx, INSN_VR54XX);
7608 op1 = MASK_MUL_VR54XX(ctx->opcode);
7609 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7611 gen_muldiv(ctx, op1, rs, rt);
7613 case OPC_JR ... OPC_JALR:
7614 gen_compute_branch(ctx, op1, rs, rd, sa);
7616 case OPC_TGE ... OPC_TEQ: /* Traps */
7618 gen_trap(ctx, op1, rs, rt, -1);
7620 case OPC_MFHI: /* Move from HI/LO */
7622 gen_HILO(ctx, op1, rd);
7625 case OPC_MTLO: /* Move to HI/LO */
7626 gen_HILO(ctx, op1, rs);
7628 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7629 #ifdef MIPS_STRICT_STANDARD
7630 MIPS_INVAL("PMON / selsl");
7631 generate_exception(ctx, EXCP_RI);
7633 gen_helper_0i(pmon, sa);
7637 generate_exception(ctx, EXCP_SYSCALL);
7640 generate_exception(ctx, EXCP_BREAK);
7643 #ifdef MIPS_STRICT_STANDARD
7645 generate_exception(ctx, EXCP_RI);
7647 /* Implemented as RI exception for now. */
7648 MIPS_INVAL("spim (unofficial)");
7649 generate_exception(ctx, EXCP_RI);
7657 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7658 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7659 save_cpu_state(ctx, 1);
7660 check_cp1_enabled(ctx);
7661 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7662 (ctx->opcode >> 16) & 1);
7664 generate_exception_err(ctx, EXCP_CpU, 1);
7668 #if defined(TARGET_MIPS64)
7669 /* MIPS64 specific opcodes */
7671 case OPC_DSRL ... OPC_DSRA:
7673 case OPC_DSRL32 ... OPC_DSRA32:
7674 check_insn(env, ctx, ISA_MIPS3);
7676 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7679 case OPC_DSRLV ... OPC_DSRAV:
7680 case OPC_DADD ... OPC_DSUBU:
7681 check_insn(env, ctx, ISA_MIPS3);
7683 gen_arith(env, ctx, op1, rd, rs, rt);
7685 case OPC_DMULT ... OPC_DDIVU:
7686 check_insn(env, ctx, ISA_MIPS3);
7688 gen_muldiv(ctx, op1, rs, rt);
7691 default: /* Invalid */
7692 MIPS_INVAL("special");
7693 generate_exception(ctx, EXCP_RI);
7698 op1 = MASK_SPECIAL2(ctx->opcode);
7700 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7701 case OPC_MSUB ... OPC_MSUBU:
7702 check_insn(env, ctx, ISA_MIPS32);
7703 gen_muldiv(ctx, op1, rs, rt);
7706 gen_arith(env, ctx, op1, rd, rs, rt);
7710 check_insn(env, ctx, ISA_MIPS32);
7711 gen_cl(ctx, op1, rd, rs);
7714 /* XXX: not clear which exception should be raised
7715 * when in debug mode...
7717 check_insn(env, ctx, ISA_MIPS32);
7718 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7719 generate_exception(ctx, EXCP_DBp);
7721 generate_exception(ctx, EXCP_DBp);
7725 #if defined(TARGET_MIPS64)
7728 check_insn(env, ctx, ISA_MIPS64);
7730 gen_cl(ctx, op1, rd, rs);
7733 default: /* Invalid */
7734 MIPS_INVAL("special2");
7735 generate_exception(ctx, EXCP_RI);
7740 op1 = MASK_SPECIAL3(ctx->opcode);
7744 check_insn(env, ctx, ISA_MIPS32R2);
7745 gen_bitops(ctx, op1, rt, rs, sa, rd);
7748 check_insn(env, ctx, ISA_MIPS32R2);
7749 op2 = MASK_BSHFL(ctx->opcode);
7750 gen_bshfl(ctx, op2, rt, rd);
7753 check_insn(env, ctx, ISA_MIPS32R2);
7755 TCGv t0 = tcg_temp_local_new();
7759 save_cpu_state(ctx, 1);
7760 gen_helper_rdhwr_cpunum(t0);
7763 save_cpu_state(ctx, 1);
7764 gen_helper_rdhwr_synci_step(t0);
7767 save_cpu_state(ctx, 1);
7768 gen_helper_rdhwr_cc(t0);
7771 save_cpu_state(ctx, 1);
7772 gen_helper_rdhwr_ccres(t0);
7775 #if defined(CONFIG_USER_ONLY)
7776 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7779 /* XXX: Some CPUs implement this in hardware.
7780 Not supported yet. */
7782 default: /* Invalid */
7783 MIPS_INVAL("rdhwr");
7784 generate_exception(ctx, EXCP_RI);
7787 gen_store_gpr(t0, rt);
7792 check_insn(env, ctx, ASE_MT);
7794 TCGv t0 = tcg_temp_local_new();
7795 TCGv t1 = tcg_temp_local_new();
7797 gen_load_gpr(t0, rt);
7798 gen_load_gpr(t1, rs);
7799 gen_helper_fork(t0, t1);
7805 check_insn(env, ctx, ASE_MT);
7807 TCGv t0 = tcg_temp_local_new();
7809 gen_load_gpr(t0, rs);
7810 gen_helper_yield(t0, t0);
7811 gen_store_gpr(t0, rd);
7815 #if defined(TARGET_MIPS64)
7816 case OPC_DEXTM ... OPC_DEXT:
7817 case OPC_DINSM ... OPC_DINS:
7818 check_insn(env, ctx, ISA_MIPS64R2);
7820 gen_bitops(ctx, op1, rt, rs, sa, rd);
7823 check_insn(env, ctx, ISA_MIPS64R2);
7825 op2 = MASK_DBSHFL(ctx->opcode);
7826 gen_bshfl(ctx, op2, rt, rd);
7829 default: /* Invalid */
7830 MIPS_INVAL("special3");
7831 generate_exception(ctx, EXCP_RI);
7836 op1 = MASK_REGIMM(ctx->opcode);
7838 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7839 case OPC_BLTZAL ... OPC_BGEZALL:
7840 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7842 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7844 gen_trap(ctx, op1, rs, -1, imm);
7847 check_insn(env, ctx, ISA_MIPS32R2);
7850 default: /* Invalid */
7851 MIPS_INVAL("regimm");
7852 generate_exception(ctx, EXCP_RI);
7857 check_cp0_enabled(ctx);
7858 op1 = MASK_CP0(ctx->opcode);
7864 #if defined(TARGET_MIPS64)
7868 #ifndef CONFIG_USER_ONLY
7869 gen_cp0(env, ctx, op1, rt, rd);
7870 #endif /* !CONFIG_USER_ONLY */
7872 case OPC_C0_FIRST ... OPC_C0_LAST:
7873 #ifndef CONFIG_USER_ONLY
7874 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7875 #endif /* !CONFIG_USER_ONLY */
7878 #ifndef CONFIG_USER_ONLY
7880 TCGv t0 = tcg_temp_local_new();
7882 op2 = MASK_MFMC0(ctx->opcode);
7885 check_insn(env, ctx, ASE_MT);
7886 gen_helper_dmt(t0, t0);
7889 check_insn(env, ctx, ASE_MT);
7890 gen_helper_emt(t0, t0);
7893 check_insn(env, ctx, ASE_MT);
7894 gen_helper_dvpe(t0, t0);
7897 check_insn(env, ctx, ASE_MT);
7898 gen_helper_evpe(t0, t0);
7901 check_insn(env, ctx, ISA_MIPS32R2);
7902 save_cpu_state(ctx, 1);
7904 /* Stop translation as we may have switched the execution mode */
7905 ctx->bstate = BS_STOP;
7908 check_insn(env, ctx, ISA_MIPS32R2);
7909 save_cpu_state(ctx, 1);
7911 /* Stop translation as we may have switched the execution mode */
7912 ctx->bstate = BS_STOP;
7914 default: /* Invalid */
7915 MIPS_INVAL("mfmc0");
7916 generate_exception(ctx, EXCP_RI);
7919 gen_store_gpr(t0, rt);
7922 #endif /* !CONFIG_USER_ONLY */
7925 check_insn(env, ctx, ISA_MIPS32R2);
7926 gen_load_srsgpr(rt, rd);
7929 check_insn(env, ctx, ISA_MIPS32R2);
7930 gen_store_srsgpr(rt, rd);
7934 generate_exception(ctx, EXCP_RI);
7938 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7939 gen_arith_imm(env, ctx, op, rt, rs, imm);
7941 case OPC_J ... OPC_JAL: /* Jump */
7942 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7943 gen_compute_branch(ctx, op, rs, rt, offset);
7945 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7946 case OPC_BEQL ... OPC_BGTZL:
7947 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7949 case OPC_LB ... OPC_LWR: /* Load and stores */
7950 case OPC_SB ... OPC_SW:
7954 gen_ldst(ctx, op, rt, rs, imm);
7957 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7961 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7965 /* Floating point (COP1). */
7970 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7971 save_cpu_state(ctx, 1);
7972 check_cp1_enabled(ctx);
7973 gen_flt_ldst(ctx, op, rt, rs, imm);
7975 generate_exception_err(ctx, EXCP_CpU, 1);
7980 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7981 save_cpu_state(ctx, 1);
7982 check_cp1_enabled(ctx);
7983 op1 = MASK_CP1(ctx->opcode);
7987 check_insn(env, ctx, ISA_MIPS32R2);
7992 gen_cp1(ctx, op1, rt, rd);
7994 #if defined(TARGET_MIPS64)
7997 check_insn(env, ctx, ISA_MIPS3);
7998 gen_cp1(ctx, op1, rt, rd);
8004 check_insn(env, ctx, ASE_MIPS3D);
8007 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8008 (rt >> 2) & 0x7, imm << 2);
8015 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8020 generate_exception (ctx, EXCP_RI);
8024 generate_exception_err(ctx, EXCP_CpU, 1);
8034 /* COP2: Not implemented. */
8035 generate_exception_err(ctx, EXCP_CpU, 2);
8039 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8040 save_cpu_state(ctx, 1);
8041 check_cp1_enabled(ctx);
8042 op1 = MASK_CP3(ctx->opcode);
8050 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8068 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8072 generate_exception (ctx, EXCP_RI);
8076 generate_exception_err(ctx, EXCP_CpU, 1);
8080 #if defined(TARGET_MIPS64)
8081 /* MIPS64 opcodes */
8083 case OPC_LDL ... OPC_LDR:
8084 case OPC_SDL ... OPC_SDR:
8089 check_insn(env, ctx, ISA_MIPS3);
8091 gen_ldst(ctx, op, rt, rs, imm);
8093 case OPC_DADDI ... OPC_DADDIU:
8094 check_insn(env, ctx, ISA_MIPS3);
8096 gen_arith_imm(env, ctx, op, rt, rs, imm);
8100 check_insn(env, ctx, ASE_MIPS16);
8101 /* MIPS16: Not implemented. */
8103 check_insn(env, ctx, ASE_MDMX);
8104 /* MDMX: Not implemented. */
8105 default: /* Invalid */
8106 MIPS_INVAL("major opcode");
8107 generate_exception(ctx, EXCP_RI);
8110 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8111 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8112 /* Branches completion */
8113 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8114 ctx->bstate = BS_BRANCH;
8115 save_cpu_state(ctx, 0);
8116 /* FIXME: Need to clear can_do_io. */
8119 /* unconditional branch */
8120 MIPS_DEBUG("unconditional branch");
8121 gen_goto_tb(ctx, 0, ctx->btarget);
8124 /* blikely taken case */
8125 MIPS_DEBUG("blikely branch taken");
8126 gen_goto_tb(ctx, 0, ctx->btarget);
8129 /* Conditional branch */
8130 MIPS_DEBUG("conditional branch");
8132 int l1 = gen_new_label();
8134 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8135 gen_goto_tb(ctx, 1, ctx->pc + 4);
8137 gen_goto_tb(ctx, 0, ctx->btarget);
8141 /* unconditional branch to register */
8142 MIPS_DEBUG("branch to register");
8143 tcg_gen_mov_tl(cpu_PC, btarget);
8147 MIPS_DEBUG("unknown branch");
8154 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8158 target_ulong pc_start;
8159 uint16_t *gen_opc_end;
8166 qemu_log("search pc %d\n", search_pc);
8169 /* Leave some spare opc slots for branch handling. */
8170 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8174 ctx.bstate = BS_NONE;
8175 /* Restore delay slot state from the tb context. */
8176 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8177 restore_cpu_state(env, &ctx);
8178 #ifdef CONFIG_USER_ONLY
8179 ctx.mem_idx = MIPS_HFLAG_UM;
8181 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8184 max_insns = tb->cflags & CF_COUNT_MASK;
8186 max_insns = CF_COUNT_MASK;
8188 qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n");
8189 /* FIXME: This may print out stale hflags from env... */
8190 log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
8192 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags);
8194 while (ctx.bstate == BS_NONE) {
8195 if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
8196 TAILQ_FOREACH(bp, &env->breakpoints, entry) {
8197 if (bp->pc == ctx.pc) {
8198 save_cpu_state(&ctx, 1);
8199 ctx.bstate = BS_BRANCH;
8200 gen_helper_0i(raise_exception, EXCP_DEBUG);
8201 /* Include the breakpoint location or the tb won't
8202 * be flushed when it must be. */
8204 goto done_generating;
8210 j = gen_opc_ptr - gen_opc_buf;
8214 gen_opc_instr_start[lj++] = 0;
8216 gen_opc_pc[lj] = ctx.pc;
8217 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8218 gen_opc_instr_start[lj] = 1;
8219 gen_opc_icount[lj] = num_insns;
8221 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8223 ctx.opcode = ldl_code(ctx.pc);
8224 decode_opc(env, &ctx);
8228 if (env->singlestep_enabled)
8231 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8234 if (gen_opc_ptr >= gen_opc_end)
8237 if (num_insns >= max_insns)
8239 #if defined (MIPS_SINGLE_STEP)
8243 if (tb->cflags & CF_LAST_IO)
8245 if (env->singlestep_enabled) {
8246 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8247 gen_helper_0i(raise_exception, EXCP_DEBUG);
8249 switch (ctx.bstate) {
8251 gen_helper_interrupt_restart();
8252 gen_goto_tb(&ctx, 0, ctx.pc);
8255 save_cpu_state(&ctx, 0);
8256 gen_goto_tb(&ctx, 0, ctx.pc);
8259 gen_helper_interrupt_restart();
8268 gen_icount_end(tb, num_insns);
8269 *gen_opc_ptr = INDEX_op_end;
8271 j = gen_opc_ptr - gen_opc_buf;
8274 gen_opc_instr_start[lj++] = 0;
8276 tb->size = ctx.pc - pc_start;
8277 tb->icount = num_insns;
8281 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
8282 qemu_log("IN: %s\n", lookup_symbol(pc_start));
8283 log_target_disas(pc_start, ctx.pc - pc_start, 0);
8286 qemu_log_mask(CPU_LOG_TB_CPU, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8290 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8292 gen_intermediate_code_internal(env, tb, 0);
8295 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8297 gen_intermediate_code_internal(env, tb, 1);
8300 static void fpu_dump_state(CPUState *env, FILE *f,
8301 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8305 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8307 #define printfpr(fp) \
8310 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8311 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8312 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8315 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8316 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8317 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8318 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8319 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8324 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8325 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8326 get_float_exception_flags(&env->active_fpu.fp_status));
8327 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8328 fpu_fprintf(f, "%3s: ", fregnames[i]);
8329 printfpr(&env->active_fpu.fpr[i]);
8335 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8336 /* Debug help: The architecture requires 32bit code to maintain proper
8337 sign-extended values on 64bit machines. */
8339 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8342 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8343 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8348 if (!SIGN_EXT_P(env->active_tc.PC))
8349 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8350 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8351 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8352 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8353 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8354 if (!SIGN_EXT_P(env->btarget))
8355 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8357 for (i = 0; i < 32; i++) {
8358 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8359 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8362 if (!SIGN_EXT_P(env->CP0_EPC))
8363 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8364 if (!SIGN_EXT_P(env->CP0_LLAddr))
8365 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8369 void cpu_dump_state (CPUState *env, FILE *f,
8370 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8375 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",
8376 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8377 env->hflags, env->btarget, env->bcond);
8378 for (i = 0; i < 32; i++) {
8380 cpu_fprintf(f, "GPR%02d:", i);
8381 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8383 cpu_fprintf(f, "\n");
8386 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8387 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8388 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8389 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8390 if (env->hflags & MIPS_HFLAG_FPU)
8391 fpu_dump_state(env, f, cpu_fprintf, flags);
8392 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8393 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8397 static void mips_tcg_init(void)
8402 /* Initialize various static tables. */
8406 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
8407 for (i = 0; i < 32; i++)
8408 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
8409 offsetof(CPUState, active_tc.gpr[i]),
8411 cpu_PC = tcg_global_mem_new(TCG_AREG0,
8412 offsetof(CPUState, active_tc.PC), "PC");
8413 for (i = 0; i < MIPS_DSP_ACC; i++) {
8414 cpu_HI[i] = tcg_global_mem_new(TCG_AREG0,
8415 offsetof(CPUState, active_tc.HI[i]),
8417 cpu_LO[i] = tcg_global_mem_new(TCG_AREG0,
8418 offsetof(CPUState, active_tc.LO[i]),
8420 cpu_ACX[i] = tcg_global_mem_new(TCG_AREG0,
8421 offsetof(CPUState, active_tc.ACX[i]),
8424 cpu_dspctrl = tcg_global_mem_new(TCG_AREG0,
8425 offsetof(CPUState, active_tc.DSPControl),
8427 bcond = tcg_global_mem_new_i32(TCG_AREG0,
8428 offsetof(CPUState, bcond), "bcond");
8429 btarget = tcg_global_mem_new(TCG_AREG0,
8430 offsetof(CPUState, btarget), "btarget");
8431 for (i = 0; i < 32; i++)
8432 fpu_fpr32[i] = tcg_global_mem_new_i32(TCG_AREG0,
8433 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8435 for (i = 0; i < 32; i++)
8436 fpu_fpr32h[i] = tcg_global_mem_new_i32(TCG_AREG0,
8437 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8439 fpu_fcr0 = tcg_global_mem_new_i32(TCG_AREG0,
8440 offsetof(CPUState, active_fpu.fcr0),
8442 fpu_fcr31 = tcg_global_mem_new_i32(TCG_AREG0,
8443 offsetof(CPUState, active_fpu.fcr31),
8446 /* register helpers */
8447 #define GEN_HELPER 2
8453 #include "translate_init.c"
8455 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8458 const mips_def_t *def;
8460 def = cpu_mips_find_by_name(cpu_model);
8463 env = qemu_mallocz(sizeof(CPUMIPSState));
8464 env->cpu_model = def;
8467 env->cpu_model_str = cpu_model;
8473 void cpu_reset (CPUMIPSState *env)
8475 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
8476 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
8477 log_cpu_state(env, 0);
8480 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8485 #if defined(CONFIG_USER_ONLY)
8486 env->hflags = MIPS_HFLAG_UM;
8488 if (env->hflags & MIPS_HFLAG_BMASK) {
8489 /* If the exception was raised from a delay slot,
8490 come back to the jump. */
8491 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8493 env->CP0_ErrorEPC = env->active_tc.PC;
8495 env->active_tc.PC = (int32_t)0xBFC00000;
8497 /* SMP not implemented */
8498 env->CP0_EBase = 0x80000000;
8499 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8500 /* vectored interrupts not implemented, timer on int 7,
8501 no performance counters. */
8502 env->CP0_IntCtl = 0xe0000000;
8506 for (i = 0; i < 7; i++) {
8507 env->CP0_WatchLo[i] = 0;
8508 env->CP0_WatchHi[i] = 0x80000000;
8510 env->CP0_WatchLo[7] = 0;
8511 env->CP0_WatchHi[7] = 0;
8513 /* Count register increments in debug mode, EJTAG version 1 */
8514 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8515 env->hflags = MIPS_HFLAG_CP0;
8517 env->exception_index = EXCP_NONE;
8518 cpu_mips_register(env, env->cpu_model);
8521 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8522 unsigned long searched_pc, int pc_pos, void *puc)
8524 env->active_tc.PC = gen_opc_pc[pc_pos];
8525 env->hflags &= ~MIPS_HFLAG_BMASK;
8526 env->hflags |= gen_opc_hflags[pc_pos];