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;
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 ret, 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(ret, 0); \
701 tcg_gen_movi_tl(ret, 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 ret, TCGv t0, target_ulong val) \
715 int l1 = gen_new_label(); \
716 int l2 = gen_new_label(); \
718 tcg_gen_brcondi_tl(cond, t0, val, l1); \
719 tcg_gen_movi_tl(ret, 0); \
722 tcg_gen_movi_tl(ret, 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 ret, TCGv t0) \
732 int l1 = gen_new_label(); \
733 int l2 = gen_new_label(); \
735 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
736 tcg_gen_movi_tl(ret, 0); \
739 tcg_gen_movi_tl(ret, 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, t0, uimm);
1316 gen_op_ltiu(t0, 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);
1599 gen_op_lt(t0, t0, t1);
1603 gen_op_ltu(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_new();
2170 TCGv t1 = tcg_temp_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 generate_exception(ctx, EXCP_TRAP);
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 int l1 = gen_new_label();
2228 tcg_gen_brcond_tl(TCG_COND_NE, t0, t1, l1);
2232 tcg_gen_brcond_tl(TCG_COND_LT, t0, t1, l1);
2236 tcg_gen_brcond_tl(TCG_COND_LTU, t0, t1, l1);
2240 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
2244 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
2248 tcg_gen_brcond_tl(TCG_COND_EQ, t0, t1, l1);
2251 generate_exception(ctx, EXCP_TRAP);
2258 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2260 TranslationBlock *tb;
2262 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2265 tcg_gen_exit_tb((long)tb + n);
2272 /* Branches (before delay slot) */
2273 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2274 int rs, int rt, int32_t offset)
2276 target_ulong btgt = -1;
2278 int bcond_compute = 0;
2279 TCGv t0 = tcg_temp_new();
2280 TCGv t1 = tcg_temp_new();
2282 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2283 #ifdef MIPS_DEBUG_DISAS
2284 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx "\n", ctx->pc);
2286 generate_exception(ctx, EXCP_RI);
2290 /* Load needed operands */
2296 /* Compare two registers */
2298 gen_load_gpr(t0, rs);
2299 gen_load_gpr(t1, rt);
2302 btgt = ctx->pc + 4 + offset;
2316 /* Compare to zero */
2318 gen_load_gpr(t0, rs);
2321 btgt = ctx->pc + 4 + offset;
2325 /* Jump to immediate */
2326 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2330 /* Jump to register */
2331 if (offset != 0 && offset != 16) {
2332 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2333 others are reserved. */
2334 MIPS_INVAL("jump hint");
2335 generate_exception(ctx, EXCP_RI);
2338 gen_load_gpr(btarget, rs);
2341 MIPS_INVAL("branch/jump");
2342 generate_exception(ctx, EXCP_RI);
2345 if (bcond_compute == 0) {
2346 /* No condition to be computed */
2348 case OPC_BEQ: /* rx == rx */
2349 case OPC_BEQL: /* rx == rx likely */
2350 case OPC_BGEZ: /* 0 >= 0 */
2351 case OPC_BGEZL: /* 0 >= 0 likely */
2352 case OPC_BLEZ: /* 0 <= 0 */
2353 case OPC_BLEZL: /* 0 <= 0 likely */
2355 ctx->hflags |= MIPS_HFLAG_B;
2356 MIPS_DEBUG("balways");
2358 case OPC_BGEZAL: /* 0 >= 0 */
2359 case OPC_BGEZALL: /* 0 >= 0 likely */
2360 /* Always take and link */
2362 ctx->hflags |= MIPS_HFLAG_B;
2363 MIPS_DEBUG("balways and link");
2365 case OPC_BNE: /* rx != rx */
2366 case OPC_BGTZ: /* 0 > 0 */
2367 case OPC_BLTZ: /* 0 < 0 */
2369 MIPS_DEBUG("bnever (NOP)");
2371 case OPC_BLTZAL: /* 0 < 0 */
2372 tcg_gen_movi_tl(cpu_gpr[31], ctx->pc + 8);
2373 MIPS_DEBUG("bnever and link");
2375 case OPC_BLTZALL: /* 0 < 0 likely */
2376 tcg_gen_movi_tl(cpu_gpr[31], ctx->pc + 8);
2377 /* Skip the instruction in the delay slot */
2378 MIPS_DEBUG("bnever, link and skip");
2381 case OPC_BNEL: /* rx != rx likely */
2382 case OPC_BGTZL: /* 0 > 0 likely */
2383 case OPC_BLTZL: /* 0 < 0 likely */
2384 /* Skip the instruction in the delay slot */
2385 MIPS_DEBUG("bnever and skip");
2389 ctx->hflags |= MIPS_HFLAG_B;
2390 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2394 ctx->hflags |= MIPS_HFLAG_B;
2395 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2398 ctx->hflags |= MIPS_HFLAG_BR;
2399 MIPS_DEBUG("jr %s", regnames[rs]);
2403 ctx->hflags |= MIPS_HFLAG_BR;
2404 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2407 MIPS_INVAL("branch/jump");
2408 generate_exception(ctx, EXCP_RI);
2414 gen_op_eq(bcond, t0, t1);
2415 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2416 regnames[rs], regnames[rt], btgt);
2419 gen_op_eq(bcond, t0, t1);
2420 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2421 regnames[rs], regnames[rt], btgt);
2424 gen_op_ne(bcond, t0, t1);
2425 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2426 regnames[rs], regnames[rt], btgt);
2429 gen_op_ne(bcond, t0, t1);
2430 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2431 regnames[rs], regnames[rt], btgt);
2434 gen_op_gez(bcond, t0);
2435 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2438 gen_op_gez(bcond, t0);
2439 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2442 gen_op_gez(bcond, t0);
2443 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2447 gen_op_gez(bcond, t0);
2449 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2452 gen_op_gtz(bcond, t0);
2453 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2456 gen_op_gtz(bcond, t0);
2457 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2460 gen_op_lez(bcond, t0);
2461 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2464 gen_op_lez(bcond, t0);
2465 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2468 gen_op_ltz(bcond, t0);
2469 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2472 gen_op_ltz(bcond, t0);
2473 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2476 gen_op_ltz(bcond, t0);
2478 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2480 ctx->hflags |= MIPS_HFLAG_BC;
2483 gen_op_ltz(bcond, t0);
2485 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2487 ctx->hflags |= MIPS_HFLAG_BL;
2490 MIPS_INVAL("conditional branch/jump");
2491 generate_exception(ctx, EXCP_RI);
2495 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2496 blink, ctx->hflags, btgt);
2498 ctx->btarget = btgt;
2500 tcg_gen_movi_tl(cpu_gpr[blink], ctx->pc + 8);
2508 /* special3 bitfield operations */
2509 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2510 int rs, int lsb, int msb)
2512 TCGv t0 = tcg_temp_new();
2513 TCGv t1 = tcg_temp_new();
2516 gen_load_gpr(t1, rs);
2521 tcg_gen_shri_tl(t0, t1, lsb);
2523 tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
2525 tcg_gen_ext32s_tl(t0, t0);
2528 #if defined(TARGET_MIPS64)
2530 tcg_gen_shri_tl(t0, t1, lsb);
2532 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
2536 tcg_gen_shri_tl(t0, t1, lsb + 32);
2537 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2540 tcg_gen_shri_tl(t0, t1, lsb);
2541 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2547 mask = ((msb - lsb + 1 < 32) ? ((1 << (msb - lsb + 1)) - 1) : ~0) << lsb;
2548 gen_load_gpr(t0, rt);
2549 tcg_gen_andi_tl(t0, t0, ~mask);
2550 tcg_gen_shli_tl(t1, t1, lsb);
2551 tcg_gen_andi_tl(t1, t1, mask);
2552 tcg_gen_or_tl(t0, t0, t1);
2553 tcg_gen_ext32s_tl(t0, t0);
2555 #if defined(TARGET_MIPS64)
2559 mask = ((msb - lsb + 1 + 32 < 64) ? ((1ULL << (msb - lsb + 1 + 32)) - 1) : ~0ULL) << lsb;
2560 gen_load_gpr(t0, rt);
2561 tcg_gen_andi_tl(t0, t0, ~mask);
2562 tcg_gen_shli_tl(t1, t1, lsb);
2563 tcg_gen_andi_tl(t1, t1, mask);
2564 tcg_gen_or_tl(t0, t0, t1);
2569 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2570 gen_load_gpr(t0, rt);
2571 tcg_gen_andi_tl(t0, t0, ~mask);
2572 tcg_gen_shli_tl(t1, t1, lsb + 32);
2573 tcg_gen_andi_tl(t1, t1, mask);
2574 tcg_gen_or_tl(t0, t0, t1);
2579 gen_load_gpr(t0, rt);
2580 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2581 gen_load_gpr(t0, rt);
2582 tcg_gen_andi_tl(t0, t0, ~mask);
2583 tcg_gen_shli_tl(t1, t1, lsb);
2584 tcg_gen_andi_tl(t1, t1, mask);
2585 tcg_gen_or_tl(t0, t0, t1);
2590 MIPS_INVAL("bitops");
2591 generate_exception(ctx, EXCP_RI);
2596 gen_store_gpr(t0, rt);
2601 static void gen_bshfl (DisasContext *ctx, uint32_t op2, int rt, int rd)
2606 /* If no destination, treat it as a NOP. */
2611 t0 = tcg_temp_new();
2612 gen_load_gpr(t0, rt);
2616 TCGv t1 = tcg_temp_new();
2618 tcg_gen_shri_tl(t1, t0, 8);
2619 tcg_gen_andi_tl(t1, t1, 0x00FF00FF);
2620 tcg_gen_shli_tl(t0, t0, 8);
2621 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF);
2622 tcg_gen_or_tl(t0, t0, t1);
2624 tcg_gen_ext32s_tl(cpu_gpr[rd], t0);
2628 tcg_gen_ext8s_tl(cpu_gpr[rd], t0);
2631 tcg_gen_ext16s_tl(cpu_gpr[rd], t0);
2633 #if defined(TARGET_MIPS64)
2636 TCGv t1 = tcg_temp_new();
2638 tcg_gen_shri_tl(t1, t0, 8);
2639 tcg_gen_andi_tl(t1, t1, 0x00FF00FF00FF00FFULL);
2640 tcg_gen_shli_tl(t0, t0, 8);
2641 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF00FF00FFULL);
2642 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2648 TCGv t1 = tcg_temp_new();
2650 tcg_gen_shri_tl(t1, t0, 16);
2651 tcg_gen_andi_tl(t1, t1, 0x0000FFFF0000FFFFULL);
2652 tcg_gen_shli_tl(t0, t0, 16);
2653 tcg_gen_andi_tl(t0, t0, ~0x0000FFFF0000FFFFULL);
2654 tcg_gen_or_tl(t0, t0, t1);
2655 tcg_gen_shri_tl(t1, t0, 32);
2656 tcg_gen_shli_tl(t0, t0, 32);
2657 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2663 MIPS_INVAL("bsfhl");
2664 generate_exception(ctx, EXCP_RI);
2671 #ifndef CONFIG_USER_ONLY
2672 /* CP0 (MMU and control) */
2673 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2675 TCGv_i32 r_tmp = tcg_temp_new_i32();
2677 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2678 tcg_gen_ext_i32_tl(t, r_tmp);
2679 tcg_temp_free_i32(r_tmp);
2682 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2684 tcg_gen_ld_tl(t, cpu_env, off);
2685 tcg_gen_ext32s_tl(t, t);
2688 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2690 TCGv_i32 r_tmp = tcg_temp_new_i32();
2692 tcg_gen_trunc_tl_i32(r_tmp, t);
2693 tcg_gen_st_i32(r_tmp, cpu_env, off);
2694 tcg_temp_free_i32(r_tmp);
2697 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2699 tcg_gen_ext32s_tl(t, t);
2700 tcg_gen_st_tl(t, cpu_env, off);
2703 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2705 const char *rn = "invalid";
2708 check_insn(env, ctx, ISA_MIPS32);
2714 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2718 check_insn(env, ctx, ASE_MT);
2719 gen_helper_mfc0_mvpcontrol(t0);
2723 check_insn(env, ctx, ASE_MT);
2724 gen_helper_mfc0_mvpconf0(t0);
2728 check_insn(env, ctx, ASE_MT);
2729 gen_helper_mfc0_mvpconf1(t0);
2739 gen_helper_mfc0_random(t0);
2743 check_insn(env, ctx, ASE_MT);
2744 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2748 check_insn(env, ctx, ASE_MT);
2749 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2753 check_insn(env, ctx, ASE_MT);
2754 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2758 check_insn(env, ctx, ASE_MT);
2759 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2763 check_insn(env, ctx, ASE_MT);
2764 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2768 check_insn(env, ctx, ASE_MT);
2769 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2770 rn = "VPEScheFBack";
2773 check_insn(env, ctx, ASE_MT);
2774 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2784 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2785 tcg_gen_ext32s_tl(t0, t0);
2789 check_insn(env, ctx, ASE_MT);
2790 gen_helper_mfc0_tcstatus(t0);
2794 check_insn(env, ctx, ASE_MT);
2795 gen_helper_mfc0_tcbind(t0);
2799 check_insn(env, ctx, ASE_MT);
2800 gen_helper_mfc0_tcrestart(t0);
2804 check_insn(env, ctx, ASE_MT);
2805 gen_helper_mfc0_tchalt(t0);
2809 check_insn(env, ctx, ASE_MT);
2810 gen_helper_mfc0_tccontext(t0);
2814 check_insn(env, ctx, ASE_MT);
2815 gen_helper_mfc0_tcschedule(t0);
2819 check_insn(env, ctx, ASE_MT);
2820 gen_helper_mfc0_tcschefback(t0);
2830 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2831 tcg_gen_ext32s_tl(t0, t0);
2841 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2842 tcg_gen_ext32s_tl(t0, t0);
2846 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2847 rn = "ContextConfig";
2856 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2860 check_insn(env, ctx, ISA_MIPS32R2);
2861 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2871 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2875 check_insn(env, ctx, ISA_MIPS32R2);
2876 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2880 check_insn(env, ctx, ISA_MIPS32R2);
2881 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2885 check_insn(env, ctx, ISA_MIPS32R2);
2886 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2890 check_insn(env, ctx, ISA_MIPS32R2);
2891 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2895 check_insn(env, ctx, ISA_MIPS32R2);
2896 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2906 check_insn(env, ctx, ISA_MIPS32R2);
2907 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
2917 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
2918 tcg_gen_ext32s_tl(t0, t0);
2928 /* Mark as an IO operation because we read the time. */
2931 gen_helper_mfc0_count(t0);
2934 ctx->bstate = BS_STOP;
2938 /* 6,7 are implementation dependent */
2946 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
2947 tcg_gen_ext32s_tl(t0, t0);
2957 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
2960 /* 6,7 are implementation dependent */
2968 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
2972 check_insn(env, ctx, ISA_MIPS32R2);
2973 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
2977 check_insn(env, ctx, ISA_MIPS32R2);
2978 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
2982 check_insn(env, ctx, ISA_MIPS32R2);
2983 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
2993 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3003 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3004 tcg_gen_ext32s_tl(t0, t0);
3014 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3018 check_insn(env, ctx, ISA_MIPS32R2);
3019 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3029 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3033 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3037 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3041 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3044 /* 4,5 are reserved */
3045 /* 6,7 are implementation dependent */
3047 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3051 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3061 gen_helper_mfc0_lladdr(t0);
3071 gen_helper_1i(mfc0_watchlo, t0, sel);
3081 gen_helper_1i(mfc0_watchhi, t0, sel);
3091 #if defined(TARGET_MIPS64)
3092 check_insn(env, ctx, ISA_MIPS3);
3093 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3094 tcg_gen_ext32s_tl(t0, t0);
3103 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3106 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3114 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3115 rn = "'Diagnostic"; /* implementation dependent */
3120 gen_helper_mfc0_debug(t0); /* EJTAG support */
3124 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3125 rn = "TraceControl";
3128 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3129 rn = "TraceControl2";
3132 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3133 rn = "UserTraceData";
3136 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3147 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3148 tcg_gen_ext32s_tl(t0, t0);
3158 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3159 rn = "Performance0";
3162 // gen_helper_mfc0_performance1(t0);
3163 rn = "Performance1";
3166 // gen_helper_mfc0_performance2(t0);
3167 rn = "Performance2";
3170 // gen_helper_mfc0_performance3(t0);
3171 rn = "Performance3";
3174 // gen_helper_mfc0_performance4(t0);
3175 rn = "Performance4";
3178 // gen_helper_mfc0_performance5(t0);
3179 rn = "Performance5";
3182 // gen_helper_mfc0_performance6(t0);
3183 rn = "Performance6";
3186 // gen_helper_mfc0_performance7(t0);
3187 rn = "Performance7";
3194 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3200 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3213 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3220 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3233 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3240 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3250 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3251 tcg_gen_ext32s_tl(t0, t0);
3262 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3272 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3276 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3277 generate_exception(ctx, EXCP_RI);
3280 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3282 const char *rn = "invalid";
3285 check_insn(env, ctx, ISA_MIPS32);
3294 gen_helper_mtc0_index(t0);
3298 check_insn(env, ctx, ASE_MT);
3299 gen_helper_mtc0_mvpcontrol(t0);
3303 check_insn(env, ctx, ASE_MT);
3308 check_insn(env, ctx, ASE_MT);
3323 check_insn(env, ctx, ASE_MT);
3324 gen_helper_mtc0_vpecontrol(t0);
3328 check_insn(env, ctx, ASE_MT);
3329 gen_helper_mtc0_vpeconf0(t0);
3333 check_insn(env, ctx, ASE_MT);
3334 gen_helper_mtc0_vpeconf1(t0);
3338 check_insn(env, ctx, ASE_MT);
3339 gen_helper_mtc0_yqmask(t0);
3343 check_insn(env, ctx, ASE_MT);
3344 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3348 check_insn(env, ctx, ASE_MT);
3349 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3350 rn = "VPEScheFBack";
3353 check_insn(env, ctx, ASE_MT);
3354 gen_helper_mtc0_vpeopt(t0);
3364 gen_helper_mtc0_entrylo0(t0);
3368 check_insn(env, ctx, ASE_MT);
3369 gen_helper_mtc0_tcstatus(t0);
3373 check_insn(env, ctx, ASE_MT);
3374 gen_helper_mtc0_tcbind(t0);
3378 check_insn(env, ctx, ASE_MT);
3379 gen_helper_mtc0_tcrestart(t0);
3383 check_insn(env, ctx, ASE_MT);
3384 gen_helper_mtc0_tchalt(t0);
3388 check_insn(env, ctx, ASE_MT);
3389 gen_helper_mtc0_tccontext(t0);
3393 check_insn(env, ctx, ASE_MT);
3394 gen_helper_mtc0_tcschedule(t0);
3398 check_insn(env, ctx, ASE_MT);
3399 gen_helper_mtc0_tcschefback(t0);
3409 gen_helper_mtc0_entrylo1(t0);
3419 gen_helper_mtc0_context(t0);
3423 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3424 rn = "ContextConfig";
3433 gen_helper_mtc0_pagemask(t0);
3437 check_insn(env, ctx, ISA_MIPS32R2);
3438 gen_helper_mtc0_pagegrain(t0);
3448 gen_helper_mtc0_wired(t0);
3452 check_insn(env, ctx, ISA_MIPS32R2);
3453 gen_helper_mtc0_srsconf0(t0);
3457 check_insn(env, ctx, ISA_MIPS32R2);
3458 gen_helper_mtc0_srsconf1(t0);
3462 check_insn(env, ctx, ISA_MIPS32R2);
3463 gen_helper_mtc0_srsconf2(t0);
3467 check_insn(env, ctx, ISA_MIPS32R2);
3468 gen_helper_mtc0_srsconf3(t0);
3472 check_insn(env, ctx, ISA_MIPS32R2);
3473 gen_helper_mtc0_srsconf4(t0);
3483 check_insn(env, ctx, ISA_MIPS32R2);
3484 gen_helper_mtc0_hwrena(t0);
3498 gen_helper_mtc0_count(t0);
3501 /* 6,7 are implementation dependent */
3505 /* Stop translation as we may have switched the execution mode */
3506 ctx->bstate = BS_STOP;
3511 gen_helper_mtc0_entryhi(t0);
3521 gen_helper_mtc0_compare(t0);
3524 /* 6,7 are implementation dependent */
3528 /* Stop translation as we may have switched the execution mode */
3529 ctx->bstate = BS_STOP;
3534 gen_helper_mtc0_status(t0);
3535 /* BS_STOP isn't good enough here, hflags may have changed. */
3536 gen_save_pc(ctx->pc + 4);
3537 ctx->bstate = BS_EXCP;
3541 check_insn(env, ctx, ISA_MIPS32R2);
3542 gen_helper_mtc0_intctl(t0);
3543 /* Stop translation as we may have switched the execution mode */
3544 ctx->bstate = BS_STOP;
3548 check_insn(env, ctx, ISA_MIPS32R2);
3549 gen_helper_mtc0_srsctl(t0);
3550 /* Stop translation as we may have switched the execution mode */
3551 ctx->bstate = BS_STOP;
3555 check_insn(env, ctx, ISA_MIPS32R2);
3556 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3557 /* Stop translation as we may have switched the execution mode */
3558 ctx->bstate = BS_STOP;
3568 gen_helper_mtc0_cause(t0);
3574 /* Stop translation as we may have switched the execution mode */
3575 ctx->bstate = BS_STOP;
3580 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3594 check_insn(env, ctx, ISA_MIPS32R2);
3595 gen_helper_mtc0_ebase(t0);
3605 gen_helper_mtc0_config0(t0);
3607 /* Stop translation as we may have switched the execution mode */
3608 ctx->bstate = BS_STOP;
3611 /* ignored, read only */
3615 gen_helper_mtc0_config2(t0);
3617 /* Stop translation as we may have switched the execution mode */
3618 ctx->bstate = BS_STOP;
3621 /* ignored, read only */
3624 /* 4,5 are reserved */
3625 /* 6,7 are implementation dependent */
3635 rn = "Invalid config selector";
3652 gen_helper_1i(mtc0_watchlo, t0, sel);
3662 gen_helper_1i(mtc0_watchhi, t0, sel);
3672 #if defined(TARGET_MIPS64)
3673 check_insn(env, ctx, ISA_MIPS3);
3674 gen_helper_mtc0_xcontext(t0);
3683 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3686 gen_helper_mtc0_framemask(t0);
3695 rn = "Diagnostic"; /* implementation dependent */
3700 gen_helper_mtc0_debug(t0); /* EJTAG support */
3701 /* BS_STOP isn't good enough here, hflags may have changed. */
3702 gen_save_pc(ctx->pc + 4);
3703 ctx->bstate = BS_EXCP;
3707 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3708 rn = "TraceControl";
3709 /* Stop translation as we may have switched the execution mode */
3710 ctx->bstate = BS_STOP;
3713 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3714 rn = "TraceControl2";
3715 /* Stop translation as we may have switched the execution mode */
3716 ctx->bstate = BS_STOP;
3719 /* Stop translation as we may have switched the execution mode */
3720 ctx->bstate = BS_STOP;
3721 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3722 rn = "UserTraceData";
3723 /* Stop translation as we may have switched the execution mode */
3724 ctx->bstate = BS_STOP;
3727 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3728 /* Stop translation as we may have switched the execution mode */
3729 ctx->bstate = BS_STOP;
3740 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3750 gen_helper_mtc0_performance0(t0);
3751 rn = "Performance0";
3754 // gen_helper_mtc0_performance1(t0);
3755 rn = "Performance1";
3758 // gen_helper_mtc0_performance2(t0);
3759 rn = "Performance2";
3762 // gen_helper_mtc0_performance3(t0);
3763 rn = "Performance3";
3766 // gen_helper_mtc0_performance4(t0);
3767 rn = "Performance4";
3770 // gen_helper_mtc0_performance5(t0);
3771 rn = "Performance5";
3774 // gen_helper_mtc0_performance6(t0);
3775 rn = "Performance6";
3778 // gen_helper_mtc0_performance7(t0);
3779 rn = "Performance7";
3805 gen_helper_mtc0_taglo(t0);
3812 gen_helper_mtc0_datalo(t0);
3825 gen_helper_mtc0_taghi(t0);
3832 gen_helper_mtc0_datahi(t0);
3843 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3854 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3860 /* Stop translation as we may have switched the execution mode */
3861 ctx->bstate = BS_STOP;
3866 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3867 /* For simplicity assume that all writes can cause interrupts. */
3870 ctx->bstate = BS_STOP;
3875 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3876 generate_exception(ctx, EXCP_RI);
3879 #if defined(TARGET_MIPS64)
3880 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3882 const char *rn = "invalid";
3885 check_insn(env, ctx, ISA_MIPS64);
3891 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
3895 check_insn(env, ctx, ASE_MT);
3896 gen_helper_mfc0_mvpcontrol(t0);
3900 check_insn(env, ctx, ASE_MT);
3901 gen_helper_mfc0_mvpconf0(t0);
3905 check_insn(env, ctx, ASE_MT);
3906 gen_helper_mfc0_mvpconf1(t0);
3916 gen_helper_mfc0_random(t0);
3920 check_insn(env, ctx, ASE_MT);
3921 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
3925 check_insn(env, ctx, ASE_MT);
3926 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
3930 check_insn(env, ctx, ASE_MT);
3931 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
3935 check_insn(env, ctx, ASE_MT);
3936 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
3940 check_insn(env, ctx, ASE_MT);
3941 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
3945 check_insn(env, ctx, ASE_MT);
3946 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3947 rn = "VPEScheFBack";
3950 check_insn(env, ctx, ASE_MT);
3951 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
3961 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
3965 check_insn(env, ctx, ASE_MT);
3966 gen_helper_mfc0_tcstatus(t0);
3970 check_insn(env, ctx, ASE_MT);
3971 gen_helper_mfc0_tcbind(t0);
3975 check_insn(env, ctx, ASE_MT);
3976 gen_helper_dmfc0_tcrestart(t0);
3980 check_insn(env, ctx, ASE_MT);
3981 gen_helper_dmfc0_tchalt(t0);
3985 check_insn(env, ctx, ASE_MT);
3986 gen_helper_dmfc0_tccontext(t0);
3990 check_insn(env, ctx, ASE_MT);
3991 gen_helper_dmfc0_tcschedule(t0);
3995 check_insn(env, ctx, ASE_MT);
3996 gen_helper_dmfc0_tcschefback(t0);
4006 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4016 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4020 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4021 rn = "ContextConfig";
4030 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4034 check_insn(env, ctx, ISA_MIPS32R2);
4035 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4045 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4049 check_insn(env, ctx, ISA_MIPS32R2);
4050 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4054 check_insn(env, ctx, ISA_MIPS32R2);
4055 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4059 check_insn(env, ctx, ISA_MIPS32R2);
4060 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4064 check_insn(env, ctx, ISA_MIPS32R2);
4065 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4069 check_insn(env, ctx, ISA_MIPS32R2);
4070 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4080 check_insn(env, ctx, ISA_MIPS32R2);
4081 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4091 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4101 /* Mark as an IO operation because we read the time. */
4104 gen_helper_mfc0_count(t0);
4107 ctx->bstate = BS_STOP;
4111 /* 6,7 are implementation dependent */
4119 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4129 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4132 /* 6,7 are implementation dependent */
4140 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4144 check_insn(env, ctx, ISA_MIPS32R2);
4145 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4149 check_insn(env, ctx, ISA_MIPS32R2);
4150 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4154 check_insn(env, ctx, ISA_MIPS32R2);
4155 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4165 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4175 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4185 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4189 check_insn(env, ctx, ISA_MIPS32R2);
4190 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4200 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4204 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4208 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4212 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4215 /* 6,7 are implementation dependent */
4217 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4221 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4231 gen_helper_dmfc0_lladdr(t0);
4241 gen_helper_1i(dmfc0_watchlo, t0, sel);
4251 gen_helper_1i(mfc0_watchhi, t0, sel);
4261 check_insn(env, ctx, ISA_MIPS3);
4262 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4270 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4273 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4281 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4282 rn = "'Diagnostic"; /* implementation dependent */
4287 gen_helper_mfc0_debug(t0); /* EJTAG support */
4291 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4292 rn = "TraceControl";
4295 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4296 rn = "TraceControl2";
4299 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4300 rn = "UserTraceData";
4303 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4314 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4324 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4325 rn = "Performance0";
4328 // gen_helper_dmfc0_performance1(t0);
4329 rn = "Performance1";
4332 // gen_helper_dmfc0_performance2(t0);
4333 rn = "Performance2";
4336 // gen_helper_dmfc0_performance3(t0);
4337 rn = "Performance3";
4340 // gen_helper_dmfc0_performance4(t0);
4341 rn = "Performance4";
4344 // gen_helper_dmfc0_performance5(t0);
4345 rn = "Performance5";
4348 // gen_helper_dmfc0_performance6(t0);
4349 rn = "Performance6";
4352 // gen_helper_dmfc0_performance7(t0);
4353 rn = "Performance7";
4360 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4367 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4380 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4387 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4400 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4407 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4417 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4428 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4438 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4442 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4443 generate_exception(ctx, EXCP_RI);
4446 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4448 const char *rn = "invalid";
4451 check_insn(env, ctx, ISA_MIPS64);
4460 gen_helper_mtc0_index(t0);
4464 check_insn(env, ctx, ASE_MT);
4465 gen_helper_mtc0_mvpcontrol(t0);
4469 check_insn(env, ctx, ASE_MT);
4474 check_insn(env, ctx, ASE_MT);
4489 check_insn(env, ctx, ASE_MT);
4490 gen_helper_mtc0_vpecontrol(t0);
4494 check_insn(env, ctx, ASE_MT);
4495 gen_helper_mtc0_vpeconf0(t0);
4499 check_insn(env, ctx, ASE_MT);
4500 gen_helper_mtc0_vpeconf1(t0);
4504 check_insn(env, ctx, ASE_MT);
4505 gen_helper_mtc0_yqmask(t0);
4509 check_insn(env, ctx, ASE_MT);
4510 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4514 check_insn(env, ctx, ASE_MT);
4515 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4516 rn = "VPEScheFBack";
4519 check_insn(env, ctx, ASE_MT);
4520 gen_helper_mtc0_vpeopt(t0);
4530 gen_helper_mtc0_entrylo0(t0);
4534 check_insn(env, ctx, ASE_MT);
4535 gen_helper_mtc0_tcstatus(t0);
4539 check_insn(env, ctx, ASE_MT);
4540 gen_helper_mtc0_tcbind(t0);
4544 check_insn(env, ctx, ASE_MT);
4545 gen_helper_mtc0_tcrestart(t0);
4549 check_insn(env, ctx, ASE_MT);
4550 gen_helper_mtc0_tchalt(t0);
4554 check_insn(env, ctx, ASE_MT);
4555 gen_helper_mtc0_tccontext(t0);
4559 check_insn(env, ctx, ASE_MT);
4560 gen_helper_mtc0_tcschedule(t0);
4564 check_insn(env, ctx, ASE_MT);
4565 gen_helper_mtc0_tcschefback(t0);
4575 gen_helper_mtc0_entrylo1(t0);
4585 gen_helper_mtc0_context(t0);
4589 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4590 rn = "ContextConfig";
4599 gen_helper_mtc0_pagemask(t0);
4603 check_insn(env, ctx, ISA_MIPS32R2);
4604 gen_helper_mtc0_pagegrain(t0);
4614 gen_helper_mtc0_wired(t0);
4618 check_insn(env, ctx, ISA_MIPS32R2);
4619 gen_helper_mtc0_srsconf0(t0);
4623 check_insn(env, ctx, ISA_MIPS32R2);
4624 gen_helper_mtc0_srsconf1(t0);
4628 check_insn(env, ctx, ISA_MIPS32R2);
4629 gen_helper_mtc0_srsconf2(t0);
4633 check_insn(env, ctx, ISA_MIPS32R2);
4634 gen_helper_mtc0_srsconf3(t0);
4638 check_insn(env, ctx, ISA_MIPS32R2);
4639 gen_helper_mtc0_srsconf4(t0);
4649 check_insn(env, ctx, ISA_MIPS32R2);
4650 gen_helper_mtc0_hwrena(t0);
4664 gen_helper_mtc0_count(t0);
4667 /* 6,7 are implementation dependent */
4671 /* Stop translation as we may have switched the execution mode */
4672 ctx->bstate = BS_STOP;
4677 gen_helper_mtc0_entryhi(t0);
4687 gen_helper_mtc0_compare(t0);
4690 /* 6,7 are implementation dependent */
4694 /* Stop translation as we may have switched the execution mode */
4695 ctx->bstate = BS_STOP;
4700 gen_helper_mtc0_status(t0);
4701 /* BS_STOP isn't good enough here, hflags may have changed. */
4702 gen_save_pc(ctx->pc + 4);
4703 ctx->bstate = BS_EXCP;
4707 check_insn(env, ctx, ISA_MIPS32R2);
4708 gen_helper_mtc0_intctl(t0);
4709 /* Stop translation as we may have switched the execution mode */
4710 ctx->bstate = BS_STOP;
4714 check_insn(env, ctx, ISA_MIPS32R2);
4715 gen_helper_mtc0_srsctl(t0);
4716 /* Stop translation as we may have switched the execution mode */
4717 ctx->bstate = BS_STOP;
4721 check_insn(env, ctx, ISA_MIPS32R2);
4722 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4723 /* Stop translation as we may have switched the execution mode */
4724 ctx->bstate = BS_STOP;
4734 gen_helper_mtc0_cause(t0);
4740 /* Stop translation as we may have switched the execution mode */
4741 ctx->bstate = BS_STOP;
4746 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4760 check_insn(env, ctx, ISA_MIPS32R2);
4761 gen_helper_mtc0_ebase(t0);
4771 gen_helper_mtc0_config0(t0);
4773 /* Stop translation as we may have switched the execution mode */
4774 ctx->bstate = BS_STOP;
4781 gen_helper_mtc0_config2(t0);
4783 /* Stop translation as we may have switched the execution mode */
4784 ctx->bstate = BS_STOP;
4790 /* 6,7 are implementation dependent */
4792 rn = "Invalid config selector";
4809 gen_helper_1i(mtc0_watchlo, t0, sel);
4819 gen_helper_1i(mtc0_watchhi, t0, sel);
4829 check_insn(env, ctx, ISA_MIPS3);
4830 gen_helper_mtc0_xcontext(t0);
4838 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4841 gen_helper_mtc0_framemask(t0);
4850 rn = "Diagnostic"; /* implementation dependent */
4855 gen_helper_mtc0_debug(t0); /* EJTAG support */
4856 /* BS_STOP isn't good enough here, hflags may have changed. */
4857 gen_save_pc(ctx->pc + 4);
4858 ctx->bstate = BS_EXCP;
4862 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4863 /* Stop translation as we may have switched the execution mode */
4864 ctx->bstate = BS_STOP;
4865 rn = "TraceControl";
4868 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4869 /* Stop translation as we may have switched the execution mode */
4870 ctx->bstate = BS_STOP;
4871 rn = "TraceControl2";
4874 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4875 /* Stop translation as we may have switched the execution mode */
4876 ctx->bstate = BS_STOP;
4877 rn = "UserTraceData";
4880 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4881 /* Stop translation as we may have switched the execution mode */
4882 ctx->bstate = BS_STOP;
4893 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4903 gen_helper_mtc0_performance0(t0);
4904 rn = "Performance0";
4907 // gen_helper_mtc0_performance1(t0);
4908 rn = "Performance1";
4911 // gen_helper_mtc0_performance2(t0);
4912 rn = "Performance2";
4915 // gen_helper_mtc0_performance3(t0);
4916 rn = "Performance3";
4919 // gen_helper_mtc0_performance4(t0);
4920 rn = "Performance4";
4923 // gen_helper_mtc0_performance5(t0);
4924 rn = "Performance5";
4927 // gen_helper_mtc0_performance6(t0);
4928 rn = "Performance6";
4931 // gen_helper_mtc0_performance7(t0);
4932 rn = "Performance7";
4958 gen_helper_mtc0_taglo(t0);
4965 gen_helper_mtc0_datalo(t0);
4978 gen_helper_mtc0_taghi(t0);
4985 gen_helper_mtc0_datahi(t0);
4996 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5007 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5013 /* Stop translation as we may have switched the execution mode */
5014 ctx->bstate = BS_STOP;
5019 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5020 /* For simplicity assume that all writes can cause interrupts. */
5023 ctx->bstate = BS_STOP;
5028 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5029 generate_exception(ctx, EXCP_RI);
5031 #endif /* TARGET_MIPS64 */
5033 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5034 int u, int sel, int h)
5036 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5037 TCGv t0 = tcg_temp_local_new();
5039 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5040 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5041 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5042 tcg_gen_movi_tl(t0, -1);
5043 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5044 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5045 tcg_gen_movi_tl(t0, -1);
5051 gen_helper_mftc0_tcstatus(t0);
5054 gen_helper_mftc0_tcbind(t0);
5057 gen_helper_mftc0_tcrestart(t0);
5060 gen_helper_mftc0_tchalt(t0);
5063 gen_helper_mftc0_tccontext(t0);
5066 gen_helper_mftc0_tcschedule(t0);
5069 gen_helper_mftc0_tcschefback(t0);
5072 gen_mfc0(env, ctx, t0, rt, sel);
5079 gen_helper_mftc0_entryhi(t0);
5082 gen_mfc0(env, ctx, t0, rt, sel);
5088 gen_helper_mftc0_status(t0);
5091 gen_mfc0(env, ctx, t0, rt, sel);
5097 gen_helper_mftc0_debug(t0);
5100 gen_mfc0(env, ctx, t0, rt, sel);
5105 gen_mfc0(env, ctx, t0, rt, sel);
5107 } else switch (sel) {
5108 /* GPR registers. */
5110 gen_helper_1i(mftgpr, t0, rt);
5112 /* Auxiliary CPU registers */
5116 gen_helper_1i(mftlo, t0, 0);
5119 gen_helper_1i(mfthi, t0, 0);
5122 gen_helper_1i(mftacx, t0, 0);
5125 gen_helper_1i(mftlo, t0, 1);
5128 gen_helper_1i(mfthi, t0, 1);
5131 gen_helper_1i(mftacx, t0, 1);
5134 gen_helper_1i(mftlo, t0, 2);
5137 gen_helper_1i(mfthi, t0, 2);
5140 gen_helper_1i(mftacx, t0, 2);
5143 gen_helper_1i(mftlo, t0, 3);
5146 gen_helper_1i(mfthi, t0, 3);
5149 gen_helper_1i(mftacx, t0, 3);
5152 gen_helper_mftdsp(t0);
5158 /* Floating point (COP1). */
5160 /* XXX: For now we support only a single FPU context. */
5162 TCGv_i32 fp0 = tcg_temp_new_i32();
5164 gen_load_fpr32(fp0, rt);
5165 tcg_gen_ext_i32_tl(t0, fp0);
5166 tcg_temp_free_i32(fp0);
5168 TCGv_i32 fp0 = tcg_temp_new_i32();
5170 gen_load_fpr32h(fp0, rt);
5171 tcg_gen_ext_i32_tl(t0, fp0);
5172 tcg_temp_free_i32(fp0);
5176 /* XXX: For now we support only a single FPU context. */
5177 gen_helper_1i(cfc1, t0, rt);
5179 /* COP2: Not implemented. */
5186 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5187 gen_store_gpr(t0, rd);
5193 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5194 generate_exception(ctx, EXCP_RI);
5197 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5198 int u, int sel, int h)
5200 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5201 TCGv t0 = tcg_temp_local_new();
5203 gen_load_gpr(t0, rt);
5204 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5205 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5206 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5208 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5209 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5216 gen_helper_mttc0_tcstatus(t0);
5219 gen_helper_mttc0_tcbind(t0);
5222 gen_helper_mttc0_tcrestart(t0);
5225 gen_helper_mttc0_tchalt(t0);
5228 gen_helper_mttc0_tccontext(t0);
5231 gen_helper_mttc0_tcschedule(t0);
5234 gen_helper_mttc0_tcschefback(t0);
5237 gen_mtc0(env, ctx, t0, rd, sel);
5244 gen_helper_mttc0_entryhi(t0);
5247 gen_mtc0(env, ctx, t0, rd, sel);
5253 gen_helper_mttc0_status(t0);
5256 gen_mtc0(env, ctx, t0, rd, sel);
5262 gen_helper_mttc0_debug(t0);
5265 gen_mtc0(env, ctx, t0, rd, sel);
5270 gen_mtc0(env, ctx, t0, rd, sel);
5272 } else switch (sel) {
5273 /* GPR registers. */
5275 gen_helper_1i(mttgpr, t0, rd);
5277 /* Auxiliary CPU registers */
5281 gen_helper_1i(mttlo, t0, 0);
5284 gen_helper_1i(mtthi, t0, 0);
5287 gen_helper_1i(mttacx, t0, 0);
5290 gen_helper_1i(mttlo, t0, 1);
5293 gen_helper_1i(mtthi, t0, 1);
5296 gen_helper_1i(mttacx, t0, 1);
5299 gen_helper_1i(mttlo, t0, 2);
5302 gen_helper_1i(mtthi, t0, 2);
5305 gen_helper_1i(mttacx, t0, 2);
5308 gen_helper_1i(mttlo, t0, 3);
5311 gen_helper_1i(mtthi, t0, 3);
5314 gen_helper_1i(mttacx, t0, 3);
5317 gen_helper_mttdsp(t0);
5323 /* Floating point (COP1). */
5325 /* XXX: For now we support only a single FPU context. */
5327 TCGv_i32 fp0 = tcg_temp_new_i32();
5329 tcg_gen_trunc_tl_i32(fp0, t0);
5330 gen_store_fpr32(fp0, rd);
5331 tcg_temp_free_i32(fp0);
5333 TCGv_i32 fp0 = tcg_temp_new_i32();
5335 tcg_gen_trunc_tl_i32(fp0, t0);
5336 gen_store_fpr32h(fp0, rd);
5337 tcg_temp_free_i32(fp0);
5341 /* XXX: For now we support only a single FPU context. */
5342 gen_helper_1i(ctc1, t0, rd);
5344 /* COP2: Not implemented. */
5351 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5357 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5358 generate_exception(ctx, EXCP_RI);
5361 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5363 const char *opn = "ldst";
5372 TCGv t0 = tcg_temp_local_new();
5374 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5375 gen_store_gpr(t0, rt);
5382 TCGv t0 = tcg_temp_local_new();
5384 gen_load_gpr(t0, rt);
5385 save_cpu_state(ctx, 1);
5386 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5391 #if defined(TARGET_MIPS64)
5393 check_insn(env, ctx, ISA_MIPS3);
5399 TCGv t0 = tcg_temp_local_new();
5401 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5402 gen_store_gpr(t0, rt);
5408 check_insn(env, ctx, ISA_MIPS3);
5410 TCGv t0 = tcg_temp_local_new();
5412 gen_load_gpr(t0, rt);
5413 save_cpu_state(ctx, 1);
5414 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5421 check_insn(env, ctx, ASE_MT);
5426 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5427 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5431 check_insn(env, ctx, ASE_MT);
5432 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5433 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5438 if (!env->tlb->helper_tlbwi)
5444 if (!env->tlb->helper_tlbwr)
5450 if (!env->tlb->helper_tlbp)
5456 if (!env->tlb->helper_tlbr)
5462 check_insn(env, ctx, ISA_MIPS2);
5463 save_cpu_state(ctx, 1);
5465 ctx->bstate = BS_EXCP;
5469 check_insn(env, ctx, ISA_MIPS32);
5470 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5472 generate_exception(ctx, EXCP_RI);
5474 save_cpu_state(ctx, 1);
5476 ctx->bstate = BS_EXCP;
5481 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5482 /* If we get an exception, we want to restart at next instruction */
5484 save_cpu_state(ctx, 1);
5487 ctx->bstate = BS_EXCP;
5492 generate_exception(ctx, EXCP_RI);
5495 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5497 #endif /* !CONFIG_USER_ONLY */
5499 /* CP1 Branches (before delay slot) */
5500 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5501 int32_t cc, int32_t offset)
5503 target_ulong btarget;
5504 const char *opn = "cp1 cond branch";
5505 TCGv_i32 t0 = tcg_temp_new_i32();
5508 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5510 btarget = ctx->pc + 4 + offset;
5515 int l1 = gen_new_label();
5516 int l2 = gen_new_label();
5519 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5520 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5521 tcg_gen_movi_tl(bcond, 0);
5524 tcg_gen_movi_tl(bcond, 1);
5531 int l1 = gen_new_label();
5532 int l2 = gen_new_label();
5535 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5536 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5537 tcg_gen_movi_tl(bcond, 0);
5540 tcg_gen_movi_tl(bcond, 1);
5547 int l1 = gen_new_label();
5548 int l2 = gen_new_label();
5551 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5552 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5553 tcg_gen_movi_tl(bcond, 0);
5556 tcg_gen_movi_tl(bcond, 1);
5563 int l1 = gen_new_label();
5564 int l2 = gen_new_label();
5567 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5568 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5569 tcg_gen_movi_tl(bcond, 0);
5572 tcg_gen_movi_tl(bcond, 1);
5577 ctx->hflags |= MIPS_HFLAG_BL;
5581 int l1 = gen_new_label();
5582 int l2 = gen_new_label();
5585 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5586 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5587 tcg_gen_movi_tl(bcond, 0);
5590 tcg_gen_movi_tl(bcond, 1);
5597 int l1 = gen_new_label();
5598 int l2 = gen_new_label();
5601 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5602 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5603 tcg_gen_movi_tl(bcond, 0);
5606 tcg_gen_movi_tl(bcond, 1);
5613 int l1 = gen_new_label();
5614 int l2 = gen_new_label();
5617 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5618 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5619 tcg_gen_movi_tl(bcond, 0);
5622 tcg_gen_movi_tl(bcond, 1);
5629 int l1 = gen_new_label();
5630 int l2 = gen_new_label();
5633 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5634 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5635 tcg_gen_movi_tl(bcond, 0);
5638 tcg_gen_movi_tl(bcond, 1);
5643 ctx->hflags |= MIPS_HFLAG_BC;
5647 generate_exception (ctx, EXCP_RI);
5650 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5651 ctx->hflags, btarget);
5652 ctx->btarget = btarget;
5655 tcg_temp_free_i32(t0);
5658 /* Coprocessor 1 (FPU) */
5660 #define FOP(func, fmt) (((fmt) << 21) | (func))
5662 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5664 const char *opn = "cp1 move";
5665 TCGv t0 = tcg_temp_local_new();
5670 TCGv_i32 fp0 = tcg_temp_new_i32();
5672 gen_load_fpr32(fp0, fs);
5673 tcg_gen_ext_i32_tl(t0, fp0);
5674 tcg_temp_free_i32(fp0);
5676 gen_store_gpr(t0, rt);
5680 gen_load_gpr(t0, rt);
5682 TCGv_i32 fp0 = tcg_temp_new_i32();
5684 tcg_gen_trunc_tl_i32(fp0, t0);
5685 gen_store_fpr32(fp0, fs);
5686 tcg_temp_free_i32(fp0);
5691 gen_helper_1i(cfc1, t0, fs);
5692 gen_store_gpr(t0, rt);
5696 gen_load_gpr(t0, rt);
5697 gen_helper_1i(ctc1, t0, fs);
5702 TCGv_i64 fp0 = tcg_temp_new_i64();
5704 gen_load_fpr64(ctx, fp0, fs);
5705 tcg_gen_trunc_i64_tl(t0, fp0);
5706 tcg_temp_free_i64(fp0);
5708 gen_store_gpr(t0, rt);
5712 gen_load_gpr(t0, rt);
5714 TCGv_i64 fp0 = tcg_temp_new_i64();
5716 tcg_gen_extu_tl_i64(fp0, t0);
5717 gen_store_fpr64(ctx, fp0, fs);
5718 tcg_temp_free_i64(fp0);
5724 TCGv_i32 fp0 = tcg_temp_new_i32();
5726 gen_load_fpr32h(fp0, fs);
5727 tcg_gen_ext_i32_tl(t0, fp0);
5728 tcg_temp_free_i32(fp0);
5730 gen_store_gpr(t0, rt);
5734 gen_load_gpr(t0, rt);
5736 TCGv_i32 fp0 = tcg_temp_new_i32();
5738 tcg_gen_trunc_tl_i32(fp0, t0);
5739 gen_store_fpr32h(fp0, fs);
5740 tcg_temp_free_i32(fp0);
5746 generate_exception (ctx, EXCP_RI);
5749 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5755 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5757 int l1 = gen_new_label();
5760 TCGv t0 = tcg_temp_local_new();
5761 TCGv_i32 r_tmp = tcg_temp_new_i32();
5764 ccbit = 1 << (24 + cc);
5772 gen_load_gpr(t0, rd);
5773 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5774 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5775 tcg_temp_free_i32(r_tmp);
5776 gen_load_gpr(t0, rs);
5778 gen_store_gpr(t0, rd);
5782 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5786 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5787 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5788 int l1 = gen_new_label();
5791 ccbit = 1 << (24 + cc);
5800 gen_load_fpr32(fp0, fd);
5801 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5802 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5803 tcg_temp_free_i32(r_tmp1);
5804 gen_load_fpr32(fp0, fs);
5806 gen_store_fpr32(fp0, fd);
5807 tcg_temp_free_i32(fp0);
5810 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
5814 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5815 TCGv_i64 fp0 = tcg_temp_local_new_i64();
5816 int l1 = gen_new_label();
5819 ccbit = 1 << (24 + cc);
5828 gen_load_fpr64(ctx, fp0, fd);
5829 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5830 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5831 tcg_temp_free_i32(r_tmp1);
5832 gen_load_fpr64(ctx, fp0, fs);
5834 gen_store_fpr64(ctx, fp0, fd);
5835 tcg_temp_free_i64(fp0);
5838 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
5840 uint32_t ccbit1, ccbit2;
5842 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5843 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5844 int l1 = gen_new_label();
5845 int l2 = gen_new_label();
5848 ccbit1 = 1 << (24 + cc);
5849 ccbit2 = 1 << (25 + cc);
5860 gen_load_fpr32(fp0, fd);
5861 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit1);
5862 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5863 gen_load_fpr32(fp0, fs);
5865 gen_store_fpr32(fp0, fd);
5867 gen_load_fpr32h(fp0, fd);
5868 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit2);
5869 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l2);
5870 gen_load_fpr32h(fp0, fs);
5872 gen_store_fpr32h(fp0, fd);
5874 tcg_temp_free_i32(r_tmp1);
5875 tcg_temp_free_i32(fp0);
5879 static void gen_farith (DisasContext *ctx, uint32_t op1,
5880 int ft, int fs, int fd, int cc)
5882 const char *opn = "farith";
5883 const char *condnames[] = {
5901 const char *condnames_abs[] = {
5919 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5920 uint32_t func = ctx->opcode & 0x3f;
5922 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5925 TCGv_i32 fp0 = tcg_temp_new_i32();
5926 TCGv_i32 fp1 = tcg_temp_new_i32();
5928 gen_load_fpr32(fp0, fs);
5929 gen_load_fpr32(fp1, ft);
5930 gen_helper_float_add_s(fp0, fp0, fp1);
5931 tcg_temp_free_i32(fp1);
5932 gen_store_fpr32(fp0, fd);
5933 tcg_temp_free_i32(fp0);
5940 TCGv_i32 fp0 = tcg_temp_new_i32();
5941 TCGv_i32 fp1 = tcg_temp_new_i32();
5943 gen_load_fpr32(fp0, fs);
5944 gen_load_fpr32(fp1, ft);
5945 gen_helper_float_sub_s(fp0, fp0, fp1);
5946 tcg_temp_free_i32(fp1);
5947 gen_store_fpr32(fp0, fd);
5948 tcg_temp_free_i32(fp0);
5955 TCGv_i32 fp0 = tcg_temp_new_i32();
5956 TCGv_i32 fp1 = tcg_temp_new_i32();
5958 gen_load_fpr32(fp0, fs);
5959 gen_load_fpr32(fp1, ft);
5960 gen_helper_float_mul_s(fp0, fp0, fp1);
5961 tcg_temp_free_i32(fp1);
5962 gen_store_fpr32(fp0, fd);
5963 tcg_temp_free_i32(fp0);
5970 TCGv_i32 fp0 = tcg_temp_new_i32();
5971 TCGv_i32 fp1 = tcg_temp_new_i32();
5973 gen_load_fpr32(fp0, fs);
5974 gen_load_fpr32(fp1, ft);
5975 gen_helper_float_div_s(fp0, fp0, fp1);
5976 tcg_temp_free_i32(fp1);
5977 gen_store_fpr32(fp0, fd);
5978 tcg_temp_free_i32(fp0);
5985 TCGv_i32 fp0 = tcg_temp_new_i32();
5987 gen_load_fpr32(fp0, fs);
5988 gen_helper_float_sqrt_s(fp0, fp0);
5989 gen_store_fpr32(fp0, fd);
5990 tcg_temp_free_i32(fp0);
5996 TCGv_i32 fp0 = tcg_temp_new_i32();
5998 gen_load_fpr32(fp0, fs);
5999 gen_helper_float_abs_s(fp0, fp0);
6000 gen_store_fpr32(fp0, fd);
6001 tcg_temp_free_i32(fp0);
6007 TCGv_i32 fp0 = tcg_temp_new_i32();
6009 gen_load_fpr32(fp0, fs);
6010 gen_store_fpr32(fp0, fd);
6011 tcg_temp_free_i32(fp0);
6017 TCGv_i32 fp0 = tcg_temp_new_i32();
6019 gen_load_fpr32(fp0, fs);
6020 gen_helper_float_chs_s(fp0, fp0);
6021 gen_store_fpr32(fp0, fd);
6022 tcg_temp_free_i32(fp0);
6027 check_cp1_64bitmode(ctx);
6029 TCGv_i32 fp32 = tcg_temp_new_i32();
6030 TCGv_i64 fp64 = tcg_temp_new_i64();
6032 gen_load_fpr32(fp32, fs);
6033 gen_helper_float_roundl_s(fp64, fp32);
6034 tcg_temp_free_i32(fp32);
6035 gen_store_fpr64(ctx, fp64, fd);
6036 tcg_temp_free_i64(fp64);
6041 check_cp1_64bitmode(ctx);
6043 TCGv_i32 fp32 = tcg_temp_new_i32();
6044 TCGv_i64 fp64 = tcg_temp_new_i64();
6046 gen_load_fpr32(fp32, fs);
6047 gen_helper_float_truncl_s(fp64, fp32);
6048 tcg_temp_free_i32(fp32);
6049 gen_store_fpr64(ctx, fp64, fd);
6050 tcg_temp_free_i64(fp64);
6055 check_cp1_64bitmode(ctx);
6057 TCGv_i32 fp32 = tcg_temp_new_i32();
6058 TCGv_i64 fp64 = tcg_temp_new_i64();
6060 gen_load_fpr32(fp32, fs);
6061 gen_helper_float_ceill_s(fp64, fp32);
6062 tcg_temp_free_i32(fp32);
6063 gen_store_fpr64(ctx, fp64, fd);
6064 tcg_temp_free_i64(fp64);
6069 check_cp1_64bitmode(ctx);
6071 TCGv_i32 fp32 = tcg_temp_new_i32();
6072 TCGv_i64 fp64 = tcg_temp_new_i64();
6074 gen_load_fpr32(fp32, fs);
6075 gen_helper_float_floorl_s(fp64, fp32);
6076 tcg_temp_free_i32(fp32);
6077 gen_store_fpr64(ctx, fp64, fd);
6078 tcg_temp_free_i64(fp64);
6084 TCGv_i32 fp0 = tcg_temp_new_i32();
6086 gen_load_fpr32(fp0, fs);
6087 gen_helper_float_roundw_s(fp0, fp0);
6088 gen_store_fpr32(fp0, fd);
6089 tcg_temp_free_i32(fp0);
6095 TCGv_i32 fp0 = tcg_temp_new_i32();
6097 gen_load_fpr32(fp0, fs);
6098 gen_helper_float_truncw_s(fp0, fp0);
6099 gen_store_fpr32(fp0, fd);
6100 tcg_temp_free_i32(fp0);
6106 TCGv_i32 fp0 = tcg_temp_new_i32();
6108 gen_load_fpr32(fp0, fs);
6109 gen_helper_float_ceilw_s(fp0, fp0);
6110 gen_store_fpr32(fp0, fd);
6111 tcg_temp_free_i32(fp0);
6117 TCGv_i32 fp0 = tcg_temp_new_i32();
6119 gen_load_fpr32(fp0, fs);
6120 gen_helper_float_floorw_s(fp0, fp0);
6121 gen_store_fpr32(fp0, fd);
6122 tcg_temp_free_i32(fp0);
6127 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6132 int l1 = gen_new_label();
6133 TCGv t0 = tcg_temp_new();
6134 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6136 gen_load_gpr(t0, ft);
6137 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6138 gen_load_fpr32(fp0, fs);
6139 gen_store_fpr32(fp0, fd);
6140 tcg_temp_free_i32(fp0);
6148 int l1 = gen_new_label();
6149 TCGv t0 = tcg_temp_new();
6150 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6152 gen_load_gpr(t0, ft);
6153 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6154 gen_load_fpr32(fp0, fs);
6155 gen_store_fpr32(fp0, fd);
6156 tcg_temp_free_i32(fp0);
6165 TCGv_i32 fp0 = tcg_temp_new_i32();
6167 gen_load_fpr32(fp0, fs);
6168 gen_helper_float_recip_s(fp0, fp0);
6169 gen_store_fpr32(fp0, fd);
6170 tcg_temp_free_i32(fp0);
6177 TCGv_i32 fp0 = tcg_temp_new_i32();
6179 gen_load_fpr32(fp0, fs);
6180 gen_helper_float_rsqrt_s(fp0, fp0);
6181 gen_store_fpr32(fp0, fd);
6182 tcg_temp_free_i32(fp0);
6187 check_cp1_64bitmode(ctx);
6189 TCGv_i32 fp0 = tcg_temp_new_i32();
6190 TCGv_i32 fp1 = tcg_temp_new_i32();
6192 gen_load_fpr32(fp0, fs);
6193 gen_load_fpr32(fp1, fd);
6194 gen_helper_float_recip2_s(fp0, fp0, fp1);
6195 tcg_temp_free_i32(fp1);
6196 gen_store_fpr32(fp0, fd);
6197 tcg_temp_free_i32(fp0);
6202 check_cp1_64bitmode(ctx);
6204 TCGv_i32 fp0 = tcg_temp_new_i32();
6206 gen_load_fpr32(fp0, fs);
6207 gen_helper_float_recip1_s(fp0, fp0);
6208 gen_store_fpr32(fp0, fd);
6209 tcg_temp_free_i32(fp0);
6214 check_cp1_64bitmode(ctx);
6216 TCGv_i32 fp0 = tcg_temp_new_i32();
6218 gen_load_fpr32(fp0, fs);
6219 gen_helper_float_rsqrt1_s(fp0, fp0);
6220 gen_store_fpr32(fp0, fd);
6221 tcg_temp_free_i32(fp0);
6226 check_cp1_64bitmode(ctx);
6228 TCGv_i32 fp0 = tcg_temp_new_i32();
6229 TCGv_i32 fp1 = tcg_temp_new_i32();
6231 gen_load_fpr32(fp0, fs);
6232 gen_load_fpr32(fp1, ft);
6233 gen_helper_float_rsqrt2_s(fp0, fp0, fp1);
6234 tcg_temp_free_i32(fp1);
6235 gen_store_fpr32(fp0, fd);
6236 tcg_temp_free_i32(fp0);
6241 check_cp1_registers(ctx, fd);
6243 TCGv_i32 fp32 = tcg_temp_new_i32();
6244 TCGv_i64 fp64 = tcg_temp_new_i64();
6246 gen_load_fpr32(fp32, fs);
6247 gen_helper_float_cvtd_s(fp64, fp32);
6248 tcg_temp_free_i32(fp32);
6249 gen_store_fpr64(ctx, fp64, fd);
6250 tcg_temp_free_i64(fp64);
6256 TCGv_i32 fp0 = tcg_temp_new_i32();
6258 gen_load_fpr32(fp0, fs);
6259 gen_helper_float_cvtw_s(fp0, fp0);
6260 gen_store_fpr32(fp0, fd);
6261 tcg_temp_free_i32(fp0);
6266 check_cp1_64bitmode(ctx);
6268 TCGv_i32 fp32 = tcg_temp_new_i32();
6269 TCGv_i64 fp64 = tcg_temp_new_i64();
6271 gen_load_fpr32(fp32, fs);
6272 gen_helper_float_cvtl_s(fp64, fp32);
6273 tcg_temp_free_i32(fp32);
6274 gen_store_fpr64(ctx, fp64, fd);
6275 tcg_temp_free_i64(fp64);
6280 check_cp1_64bitmode(ctx);
6282 TCGv_i64 fp64 = tcg_temp_new_i64();
6283 TCGv_i32 fp32_0 = tcg_temp_new_i32();
6284 TCGv_i32 fp32_1 = tcg_temp_new_i32();
6286 gen_load_fpr32(fp32_0, fs);
6287 gen_load_fpr32(fp32_1, ft);
6288 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6289 tcg_temp_free_i32(fp32_1);
6290 tcg_temp_free_i32(fp32_0);
6291 gen_store_fpr64(ctx, fp64, fd);
6292 tcg_temp_free_i64(fp64);
6313 TCGv_i32 fp0 = tcg_temp_new_i32();
6314 TCGv_i32 fp1 = tcg_temp_new_i32();
6316 gen_load_fpr32(fp0, fs);
6317 gen_load_fpr32(fp1, ft);
6318 if (ctx->opcode & (1 << 6)) {
6320 gen_cmpabs_s(func-48, fp0, fp1, cc);
6321 opn = condnames_abs[func-48];
6323 gen_cmp_s(func-48, fp0, fp1, cc);
6324 opn = condnames[func-48];
6326 tcg_temp_free_i32(fp0);
6327 tcg_temp_free_i32(fp1);
6331 check_cp1_registers(ctx, fs | ft | fd);
6333 TCGv_i64 fp0 = tcg_temp_new_i64();
6334 TCGv_i64 fp1 = tcg_temp_new_i64();
6336 gen_load_fpr64(ctx, fp0, fs);
6337 gen_load_fpr64(ctx, fp1, ft);
6338 gen_helper_float_add_d(fp0, fp0, fp1);
6339 tcg_temp_free_i64(fp1);
6340 gen_store_fpr64(ctx, fp0, fd);
6341 tcg_temp_free_i64(fp0);
6347 check_cp1_registers(ctx, fs | ft | fd);
6349 TCGv_i64 fp0 = tcg_temp_new_i64();
6350 TCGv_i64 fp1 = tcg_temp_new_i64();
6352 gen_load_fpr64(ctx, fp0, fs);
6353 gen_load_fpr64(ctx, fp1, ft);
6354 gen_helper_float_sub_d(fp0, fp0, fp1);
6355 tcg_temp_free_i64(fp1);
6356 gen_store_fpr64(ctx, fp0, fd);
6357 tcg_temp_free_i64(fp0);
6363 check_cp1_registers(ctx, fs | ft | fd);
6365 TCGv_i64 fp0 = tcg_temp_new_i64();
6366 TCGv_i64 fp1 = tcg_temp_new_i64();
6368 gen_load_fpr64(ctx, fp0, fs);
6369 gen_load_fpr64(ctx, fp1, ft);
6370 gen_helper_float_mul_d(fp0, fp0, fp1);
6371 tcg_temp_free_i64(fp1);
6372 gen_store_fpr64(ctx, fp0, fd);
6373 tcg_temp_free_i64(fp0);
6379 check_cp1_registers(ctx, fs | ft | fd);
6381 TCGv_i64 fp0 = tcg_temp_new_i64();
6382 TCGv_i64 fp1 = tcg_temp_new_i64();
6384 gen_load_fpr64(ctx, fp0, fs);
6385 gen_load_fpr64(ctx, fp1, ft);
6386 gen_helper_float_div_d(fp0, fp0, fp1);
6387 tcg_temp_free_i64(fp1);
6388 gen_store_fpr64(ctx, fp0, fd);
6389 tcg_temp_free_i64(fp0);
6395 check_cp1_registers(ctx, fs | fd);
6397 TCGv_i64 fp0 = tcg_temp_new_i64();
6399 gen_load_fpr64(ctx, fp0, fs);
6400 gen_helper_float_sqrt_d(fp0, fp0);
6401 gen_store_fpr64(ctx, fp0, fd);
6402 tcg_temp_free_i64(fp0);
6407 check_cp1_registers(ctx, fs | fd);
6409 TCGv_i64 fp0 = tcg_temp_new_i64();
6411 gen_load_fpr64(ctx, fp0, fs);
6412 gen_helper_float_abs_d(fp0, fp0);
6413 gen_store_fpr64(ctx, fp0, fd);
6414 tcg_temp_free_i64(fp0);
6419 check_cp1_registers(ctx, fs | fd);
6421 TCGv_i64 fp0 = tcg_temp_new_i64();
6423 gen_load_fpr64(ctx, fp0, fs);
6424 gen_store_fpr64(ctx, fp0, fd);
6425 tcg_temp_free_i64(fp0);
6430 check_cp1_registers(ctx, fs | fd);
6432 TCGv_i64 fp0 = tcg_temp_new_i64();
6434 gen_load_fpr64(ctx, fp0, fs);
6435 gen_helper_float_chs_d(fp0, fp0);
6436 gen_store_fpr64(ctx, fp0, fd);
6437 tcg_temp_free_i64(fp0);
6442 check_cp1_64bitmode(ctx);
6444 TCGv_i64 fp0 = tcg_temp_new_i64();
6446 gen_load_fpr64(ctx, fp0, fs);
6447 gen_helper_float_roundl_d(fp0, fp0);
6448 gen_store_fpr64(ctx, fp0, fd);
6449 tcg_temp_free_i64(fp0);
6454 check_cp1_64bitmode(ctx);
6456 TCGv_i64 fp0 = tcg_temp_new_i64();
6458 gen_load_fpr64(ctx, fp0, fs);
6459 gen_helper_float_truncl_d(fp0, fp0);
6460 gen_store_fpr64(ctx, fp0, fd);
6461 tcg_temp_free_i64(fp0);
6466 check_cp1_64bitmode(ctx);
6468 TCGv_i64 fp0 = tcg_temp_new_i64();
6470 gen_load_fpr64(ctx, fp0, fs);
6471 gen_helper_float_ceill_d(fp0, fp0);
6472 gen_store_fpr64(ctx, fp0, fd);
6473 tcg_temp_free_i64(fp0);
6478 check_cp1_64bitmode(ctx);
6480 TCGv_i64 fp0 = tcg_temp_new_i64();
6482 gen_load_fpr64(ctx, fp0, fs);
6483 gen_helper_float_floorl_d(fp0, fp0);
6484 gen_store_fpr64(ctx, fp0, fd);
6485 tcg_temp_free_i64(fp0);
6490 check_cp1_registers(ctx, fs);
6492 TCGv_i32 fp32 = tcg_temp_new_i32();
6493 TCGv_i64 fp64 = tcg_temp_new_i64();
6495 gen_load_fpr64(ctx, fp64, fs);
6496 gen_helper_float_roundw_d(fp32, fp64);
6497 tcg_temp_free_i64(fp64);
6498 gen_store_fpr32(fp32, fd);
6499 tcg_temp_free_i32(fp32);
6504 check_cp1_registers(ctx, fs);
6506 TCGv_i32 fp32 = tcg_temp_new_i32();
6507 TCGv_i64 fp64 = tcg_temp_new_i64();
6509 gen_load_fpr64(ctx, fp64, fs);
6510 gen_helper_float_truncw_d(fp32, fp64);
6511 tcg_temp_free_i64(fp64);
6512 gen_store_fpr32(fp32, fd);
6513 tcg_temp_free_i32(fp32);
6518 check_cp1_registers(ctx, fs);
6520 TCGv_i32 fp32 = tcg_temp_new_i32();
6521 TCGv_i64 fp64 = tcg_temp_new_i64();
6523 gen_load_fpr64(ctx, fp64, fs);
6524 gen_helper_float_ceilw_d(fp32, fp64);
6525 tcg_temp_free_i64(fp64);
6526 gen_store_fpr32(fp32, fd);
6527 tcg_temp_free_i32(fp32);
6532 check_cp1_registers(ctx, fs);
6534 TCGv_i32 fp32 = tcg_temp_new_i32();
6535 TCGv_i64 fp64 = tcg_temp_new_i64();
6537 gen_load_fpr64(ctx, fp64, fs);
6538 gen_helper_float_floorw_d(fp32, fp64);
6539 tcg_temp_free_i64(fp64);
6540 gen_store_fpr32(fp32, fd);
6541 tcg_temp_free_i32(fp32);
6546 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6551 int l1 = gen_new_label();
6552 TCGv t0 = tcg_temp_new();
6553 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6555 gen_load_gpr(t0, ft);
6556 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6557 gen_load_fpr64(ctx, fp0, fs);
6558 gen_store_fpr64(ctx, fp0, fd);
6559 tcg_temp_free_i64(fp0);
6567 int l1 = gen_new_label();
6568 TCGv t0 = tcg_temp_new();
6569 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6571 gen_load_gpr(t0, ft);
6572 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6573 gen_load_fpr64(ctx, fp0, fs);
6574 gen_store_fpr64(ctx, fp0, fd);
6575 tcg_temp_free_i64(fp0);
6582 check_cp1_64bitmode(ctx);
6584 TCGv_i64 fp0 = tcg_temp_new_i64();
6586 gen_load_fpr64(ctx, fp0, fs);
6587 gen_helper_float_recip_d(fp0, fp0);
6588 gen_store_fpr64(ctx, fp0, fd);
6589 tcg_temp_free_i64(fp0);
6594 check_cp1_64bitmode(ctx);
6596 TCGv_i64 fp0 = tcg_temp_new_i64();
6598 gen_load_fpr64(ctx, fp0, fs);
6599 gen_helper_float_rsqrt_d(fp0, fp0);
6600 gen_store_fpr64(ctx, fp0, fd);
6601 tcg_temp_free_i64(fp0);
6606 check_cp1_64bitmode(ctx);
6608 TCGv_i64 fp0 = tcg_temp_new_i64();
6609 TCGv_i64 fp1 = tcg_temp_new_i64();
6611 gen_load_fpr64(ctx, fp0, fs);
6612 gen_load_fpr64(ctx, fp1, ft);
6613 gen_helper_float_recip2_d(fp0, fp0, fp1);
6614 tcg_temp_free_i64(fp1);
6615 gen_store_fpr64(ctx, fp0, fd);
6616 tcg_temp_free_i64(fp0);
6621 check_cp1_64bitmode(ctx);
6623 TCGv_i64 fp0 = tcg_temp_new_i64();
6625 gen_load_fpr64(ctx, fp0, fs);
6626 gen_helper_float_recip1_d(fp0, fp0);
6627 gen_store_fpr64(ctx, fp0, fd);
6628 tcg_temp_free_i64(fp0);
6633 check_cp1_64bitmode(ctx);
6635 TCGv_i64 fp0 = tcg_temp_new_i64();
6637 gen_load_fpr64(ctx, fp0, fs);
6638 gen_helper_float_rsqrt1_d(fp0, fp0);
6639 gen_store_fpr64(ctx, fp0, fd);
6640 tcg_temp_free_i64(fp0);
6645 check_cp1_64bitmode(ctx);
6647 TCGv_i64 fp0 = tcg_temp_new_i64();
6648 TCGv_i64 fp1 = tcg_temp_new_i64();
6650 gen_load_fpr64(ctx, fp0, fs);
6651 gen_load_fpr64(ctx, fp1, ft);
6652 gen_helper_float_rsqrt2_d(fp0, fp0, fp1);
6653 tcg_temp_free_i64(fp1);
6654 gen_store_fpr64(ctx, fp0, fd);
6655 tcg_temp_free_i64(fp0);
6676 TCGv_i64 fp0 = tcg_temp_new_i64();
6677 TCGv_i64 fp1 = tcg_temp_new_i64();
6679 gen_load_fpr64(ctx, fp0, fs);
6680 gen_load_fpr64(ctx, fp1, ft);
6681 if (ctx->opcode & (1 << 6)) {
6683 check_cp1_registers(ctx, fs | ft);
6684 gen_cmpabs_d(func-48, fp0, fp1, cc);
6685 opn = condnames_abs[func-48];
6687 check_cp1_registers(ctx, fs | ft);
6688 gen_cmp_d(func-48, fp0, fp1, cc);
6689 opn = condnames[func-48];
6691 tcg_temp_free_i64(fp0);
6692 tcg_temp_free_i64(fp1);
6696 check_cp1_registers(ctx, fs);
6698 TCGv_i32 fp32 = tcg_temp_new_i32();
6699 TCGv_i64 fp64 = tcg_temp_new_i64();
6701 gen_load_fpr64(ctx, fp64, fs);
6702 gen_helper_float_cvts_d(fp32, fp64);
6703 tcg_temp_free_i64(fp64);
6704 gen_store_fpr32(fp32, fd);
6705 tcg_temp_free_i32(fp32);
6710 check_cp1_registers(ctx, fs);
6712 TCGv_i32 fp32 = tcg_temp_new_i32();
6713 TCGv_i64 fp64 = tcg_temp_new_i64();
6715 gen_load_fpr64(ctx, fp64, fs);
6716 gen_helper_float_cvtw_d(fp32, fp64);
6717 tcg_temp_free_i64(fp64);
6718 gen_store_fpr32(fp32, fd);
6719 tcg_temp_free_i32(fp32);
6724 check_cp1_64bitmode(ctx);
6726 TCGv_i64 fp0 = tcg_temp_new_i64();
6728 gen_load_fpr64(ctx, fp0, fs);
6729 gen_helper_float_cvtl_d(fp0, fp0);
6730 gen_store_fpr64(ctx, fp0, fd);
6731 tcg_temp_free_i64(fp0);
6737 TCGv_i32 fp0 = tcg_temp_new_i32();
6739 gen_load_fpr32(fp0, fs);
6740 gen_helper_float_cvts_w(fp0, fp0);
6741 gen_store_fpr32(fp0, fd);
6742 tcg_temp_free_i32(fp0);
6747 check_cp1_registers(ctx, fd);
6749 TCGv_i32 fp32 = tcg_temp_new_i32();
6750 TCGv_i64 fp64 = tcg_temp_new_i64();
6752 gen_load_fpr32(fp32, fs);
6753 gen_helper_float_cvtd_w(fp64, fp32);
6754 tcg_temp_free_i32(fp32);
6755 gen_store_fpr64(ctx, fp64, fd);
6756 tcg_temp_free_i64(fp64);
6761 check_cp1_64bitmode(ctx);
6763 TCGv_i32 fp32 = tcg_temp_new_i32();
6764 TCGv_i64 fp64 = tcg_temp_new_i64();
6766 gen_load_fpr64(ctx, fp64, fs);
6767 gen_helper_float_cvts_l(fp32, fp64);
6768 tcg_temp_free_i64(fp64);
6769 gen_store_fpr32(fp32, fd);
6770 tcg_temp_free_i32(fp32);
6775 check_cp1_64bitmode(ctx);
6777 TCGv_i64 fp0 = tcg_temp_new_i64();
6779 gen_load_fpr64(ctx, fp0, fs);
6780 gen_helper_float_cvtd_l(fp0, fp0);
6781 gen_store_fpr64(ctx, fp0, fd);
6782 tcg_temp_free_i64(fp0);
6787 check_cp1_64bitmode(ctx);
6789 TCGv_i64 fp0 = tcg_temp_new_i64();
6791 gen_load_fpr64(ctx, fp0, fs);
6792 gen_helper_float_cvtps_pw(fp0, fp0);
6793 gen_store_fpr64(ctx, fp0, fd);
6794 tcg_temp_free_i64(fp0);
6799 check_cp1_64bitmode(ctx);
6801 TCGv_i64 fp0 = tcg_temp_new_i64();
6802 TCGv_i64 fp1 = tcg_temp_new_i64();
6804 gen_load_fpr64(ctx, fp0, fs);
6805 gen_load_fpr64(ctx, fp1, ft);
6806 gen_helper_float_add_ps(fp0, fp0, fp1);
6807 tcg_temp_free_i64(fp1);
6808 gen_store_fpr64(ctx, fp0, fd);
6809 tcg_temp_free_i64(fp0);
6814 check_cp1_64bitmode(ctx);
6816 TCGv_i64 fp0 = tcg_temp_new_i64();
6817 TCGv_i64 fp1 = tcg_temp_new_i64();
6819 gen_load_fpr64(ctx, fp0, fs);
6820 gen_load_fpr64(ctx, fp1, ft);
6821 gen_helper_float_sub_ps(fp0, fp0, fp1);
6822 tcg_temp_free_i64(fp1);
6823 gen_store_fpr64(ctx, fp0, fd);
6824 tcg_temp_free_i64(fp0);
6829 check_cp1_64bitmode(ctx);
6831 TCGv_i64 fp0 = tcg_temp_new_i64();
6832 TCGv_i64 fp1 = tcg_temp_new_i64();
6834 gen_load_fpr64(ctx, fp0, fs);
6835 gen_load_fpr64(ctx, fp1, ft);
6836 gen_helper_float_mul_ps(fp0, fp0, fp1);
6837 tcg_temp_free_i64(fp1);
6838 gen_store_fpr64(ctx, fp0, fd);
6839 tcg_temp_free_i64(fp0);
6844 check_cp1_64bitmode(ctx);
6846 TCGv_i64 fp0 = tcg_temp_new_i64();
6848 gen_load_fpr64(ctx, fp0, fs);
6849 gen_helper_float_abs_ps(fp0, fp0);
6850 gen_store_fpr64(ctx, fp0, fd);
6851 tcg_temp_free_i64(fp0);
6856 check_cp1_64bitmode(ctx);
6858 TCGv_i64 fp0 = tcg_temp_new_i64();
6860 gen_load_fpr64(ctx, fp0, fs);
6861 gen_store_fpr64(ctx, fp0, fd);
6862 tcg_temp_free_i64(fp0);
6867 check_cp1_64bitmode(ctx);
6869 TCGv_i64 fp0 = tcg_temp_new_i64();
6871 gen_load_fpr64(ctx, fp0, fs);
6872 gen_helper_float_chs_ps(fp0, fp0);
6873 gen_store_fpr64(ctx, fp0, fd);
6874 tcg_temp_free_i64(fp0);
6879 check_cp1_64bitmode(ctx);
6880 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6884 check_cp1_64bitmode(ctx);
6886 int l1 = gen_new_label();
6887 TCGv t0 = tcg_temp_new();
6888 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6889 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6891 gen_load_gpr(t0, ft);
6892 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6893 gen_load_fpr32(fp0, fs);
6894 gen_load_fpr32h(fph0, fs);
6895 gen_store_fpr32(fp0, fd);
6896 gen_store_fpr32h(fph0, fd);
6897 tcg_temp_free_i32(fp0);
6898 tcg_temp_free_i32(fph0);
6905 check_cp1_64bitmode(ctx);
6907 int l1 = gen_new_label();
6908 TCGv t0 = tcg_temp_new();
6909 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6910 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6912 gen_load_gpr(t0, ft);
6913 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6914 gen_load_fpr32(fp0, fs);
6915 gen_load_fpr32h(fph0, fs);
6916 gen_store_fpr32(fp0, fd);
6917 gen_store_fpr32h(fph0, fd);
6918 tcg_temp_free_i32(fp0);
6919 tcg_temp_free_i32(fph0);
6926 check_cp1_64bitmode(ctx);
6928 TCGv_i64 fp0 = tcg_temp_new_i64();
6929 TCGv_i64 fp1 = tcg_temp_new_i64();
6931 gen_load_fpr64(ctx, fp0, ft);
6932 gen_load_fpr64(ctx, fp1, fs);
6933 gen_helper_float_addr_ps(fp0, fp0, fp1);
6934 tcg_temp_free_i64(fp1);
6935 gen_store_fpr64(ctx, fp0, fd);
6936 tcg_temp_free_i64(fp0);
6941 check_cp1_64bitmode(ctx);
6943 TCGv_i64 fp0 = tcg_temp_new_i64();
6944 TCGv_i64 fp1 = tcg_temp_new_i64();
6946 gen_load_fpr64(ctx, fp0, ft);
6947 gen_load_fpr64(ctx, fp1, fs);
6948 gen_helper_float_mulr_ps(fp0, fp0, fp1);
6949 tcg_temp_free_i64(fp1);
6950 gen_store_fpr64(ctx, fp0, fd);
6951 tcg_temp_free_i64(fp0);
6956 check_cp1_64bitmode(ctx);
6958 TCGv_i64 fp0 = tcg_temp_new_i64();
6959 TCGv_i64 fp1 = tcg_temp_new_i64();
6961 gen_load_fpr64(ctx, fp0, fs);
6962 gen_load_fpr64(ctx, fp1, fd);
6963 gen_helper_float_recip2_ps(fp0, fp0, fp1);
6964 tcg_temp_free_i64(fp1);
6965 gen_store_fpr64(ctx, fp0, fd);
6966 tcg_temp_free_i64(fp0);
6971 check_cp1_64bitmode(ctx);
6973 TCGv_i64 fp0 = tcg_temp_new_i64();
6975 gen_load_fpr64(ctx, fp0, fs);
6976 gen_helper_float_recip1_ps(fp0, fp0);
6977 gen_store_fpr64(ctx, fp0, fd);
6978 tcg_temp_free_i64(fp0);
6983 check_cp1_64bitmode(ctx);
6985 TCGv_i64 fp0 = tcg_temp_new_i64();
6987 gen_load_fpr64(ctx, fp0, fs);
6988 gen_helper_float_rsqrt1_ps(fp0, fp0);
6989 gen_store_fpr64(ctx, fp0, fd);
6990 tcg_temp_free_i64(fp0);
6995 check_cp1_64bitmode(ctx);
6997 TCGv_i64 fp0 = tcg_temp_new_i64();
6998 TCGv_i64 fp1 = tcg_temp_new_i64();
7000 gen_load_fpr64(ctx, fp0, fs);
7001 gen_load_fpr64(ctx, fp1, ft);
7002 gen_helper_float_rsqrt2_ps(fp0, fp0, fp1);
7003 tcg_temp_free_i64(fp1);
7004 gen_store_fpr64(ctx, fp0, fd);
7005 tcg_temp_free_i64(fp0);
7010 check_cp1_64bitmode(ctx);
7012 TCGv_i32 fp0 = tcg_temp_new_i32();
7014 gen_load_fpr32h(fp0, fs);
7015 gen_helper_float_cvts_pu(fp0, fp0);
7016 gen_store_fpr32(fp0, fd);
7017 tcg_temp_free_i32(fp0);
7022 check_cp1_64bitmode(ctx);
7024 TCGv_i64 fp0 = tcg_temp_new_i64();
7026 gen_load_fpr64(ctx, fp0, fs);
7027 gen_helper_float_cvtpw_ps(fp0, fp0);
7028 gen_store_fpr64(ctx, fp0, fd);
7029 tcg_temp_free_i64(fp0);
7034 check_cp1_64bitmode(ctx);
7036 TCGv_i32 fp0 = tcg_temp_new_i32();
7038 gen_load_fpr32(fp0, fs);
7039 gen_helper_float_cvts_pl(fp0, fp0);
7040 gen_store_fpr32(fp0, fd);
7041 tcg_temp_free_i32(fp0);
7046 check_cp1_64bitmode(ctx);
7048 TCGv_i32 fp0 = tcg_temp_new_i32();
7049 TCGv_i32 fp1 = tcg_temp_new_i32();
7051 gen_load_fpr32(fp0, fs);
7052 gen_load_fpr32(fp1, ft);
7053 gen_store_fpr32h(fp0, fd);
7054 gen_store_fpr32(fp1, fd);
7055 tcg_temp_free_i32(fp0);
7056 tcg_temp_free_i32(fp1);
7061 check_cp1_64bitmode(ctx);
7063 TCGv_i32 fp0 = tcg_temp_new_i32();
7064 TCGv_i32 fp1 = tcg_temp_new_i32();
7066 gen_load_fpr32(fp0, fs);
7067 gen_load_fpr32h(fp1, ft);
7068 gen_store_fpr32(fp1, fd);
7069 gen_store_fpr32h(fp0, fd);
7070 tcg_temp_free_i32(fp0);
7071 tcg_temp_free_i32(fp1);
7076 check_cp1_64bitmode(ctx);
7078 TCGv_i32 fp0 = tcg_temp_new_i32();
7079 TCGv_i32 fp1 = tcg_temp_new_i32();
7081 gen_load_fpr32h(fp0, fs);
7082 gen_load_fpr32(fp1, ft);
7083 gen_store_fpr32(fp1, fd);
7084 gen_store_fpr32h(fp0, fd);
7085 tcg_temp_free_i32(fp0);
7086 tcg_temp_free_i32(fp1);
7091 check_cp1_64bitmode(ctx);
7093 TCGv_i32 fp0 = tcg_temp_new_i32();
7094 TCGv_i32 fp1 = tcg_temp_new_i32();
7096 gen_load_fpr32h(fp0, fs);
7097 gen_load_fpr32h(fp1, ft);
7098 gen_store_fpr32(fp1, fd);
7099 gen_store_fpr32h(fp0, fd);
7100 tcg_temp_free_i32(fp0);
7101 tcg_temp_free_i32(fp1);
7121 check_cp1_64bitmode(ctx);
7123 TCGv_i64 fp0 = tcg_temp_new_i64();
7124 TCGv_i64 fp1 = tcg_temp_new_i64();
7126 gen_load_fpr64(ctx, fp0, fs);
7127 gen_load_fpr64(ctx, fp1, ft);
7128 if (ctx->opcode & (1 << 6)) {
7129 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7130 opn = condnames_abs[func-48];
7132 gen_cmp_ps(func-48, fp0, fp1, cc);
7133 opn = condnames[func-48];
7135 tcg_temp_free_i64(fp0);
7136 tcg_temp_free_i64(fp1);
7141 generate_exception (ctx, EXCP_RI);
7146 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7149 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7152 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7157 /* Coprocessor 3 (FPU) */
7158 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7159 int fd, int fs, int base, int index)
7161 const char *opn = "extended float load/store";
7163 TCGv t0 = tcg_temp_local_new();
7164 TCGv t1 = tcg_temp_local_new();
7167 gen_load_gpr(t0, index);
7168 } else if (index == 0) {
7169 gen_load_gpr(t0, base);
7171 gen_load_gpr(t0, index);
7172 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
7174 /* Don't do NOP if destination is zero: we must perform the actual
7180 TCGv_i32 fp0 = tcg_temp_new_i32();
7182 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
7183 tcg_gen_trunc_tl_i32(fp0, t1);
7184 gen_store_fpr32(fp0, fd);
7185 tcg_temp_free_i32(fp0);
7191 check_cp1_registers(ctx, fd);
7193 TCGv_i64 fp0 = tcg_temp_new_i64();
7195 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7196 gen_store_fpr64(ctx, fp0, fd);
7197 tcg_temp_free_i64(fp0);
7202 check_cp1_64bitmode(ctx);
7203 tcg_gen_andi_tl(t0, t0, ~0x7);
7205 TCGv_i64 fp0 = tcg_temp_new_i64();
7207 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7208 gen_store_fpr64(ctx, fp0, fd);
7209 tcg_temp_free_i64(fp0);
7216 TCGv_i32 fp0 = tcg_temp_new_i32();
7218 gen_load_fpr32(fp0, fs);
7219 tcg_gen_extu_i32_tl(t1, fp0);
7220 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
7221 tcg_temp_free_i32(fp0);
7228 check_cp1_registers(ctx, fs);
7230 TCGv_i64 fp0 = tcg_temp_new_i64();
7232 gen_load_fpr64(ctx, fp0, fs);
7233 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7234 tcg_temp_free_i64(fp0);
7240 check_cp1_64bitmode(ctx);
7241 tcg_gen_andi_tl(t0, t0, ~0x7);
7243 TCGv_i64 fp0 = tcg_temp_new_i64();
7245 gen_load_fpr64(ctx, fp0, fs);
7246 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7247 tcg_temp_free_i64(fp0);
7254 generate_exception(ctx, EXCP_RI);
7261 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7262 regnames[index], regnames[base]);
7265 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7266 int fd, int fr, int fs, int ft)
7268 const char *opn = "flt3_arith";
7272 check_cp1_64bitmode(ctx);
7274 TCGv t0 = tcg_temp_local_new();
7275 TCGv_i32 fp0 = tcg_temp_local_new_i32();
7276 TCGv_i32 fph0 = tcg_temp_local_new_i32();
7277 TCGv_i32 fp1 = tcg_temp_local_new_i32();
7278 TCGv_i32 fph1 = tcg_temp_local_new_i32();
7279 int l1 = gen_new_label();
7280 int l2 = gen_new_label();
7282 gen_load_gpr(t0, fr);
7283 tcg_gen_andi_tl(t0, t0, 0x7);
7284 gen_load_fpr32(fp0, fs);
7285 gen_load_fpr32h(fph0, fs);
7286 gen_load_fpr32(fp1, ft);
7287 gen_load_fpr32h(fph1, ft);
7289 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7290 gen_store_fpr32(fp0, fd);
7291 gen_store_fpr32h(fph0, fd);
7294 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7296 #ifdef TARGET_WORDS_BIGENDIAN
7297 gen_store_fpr32(fph1, fd);
7298 gen_store_fpr32h(fp0, fd);
7300 gen_store_fpr32(fph0, fd);
7301 gen_store_fpr32h(fp1, fd);
7304 tcg_temp_free_i32(fp0);
7305 tcg_temp_free_i32(fph0);
7306 tcg_temp_free_i32(fp1);
7307 tcg_temp_free_i32(fph1);
7314 TCGv_i32 fp0 = tcg_temp_new_i32();
7315 TCGv_i32 fp1 = tcg_temp_new_i32();
7316 TCGv_i32 fp2 = tcg_temp_new_i32();
7318 gen_load_fpr32(fp0, fs);
7319 gen_load_fpr32(fp1, ft);
7320 gen_load_fpr32(fp2, fr);
7321 gen_helper_float_muladd_s(fp2, fp0, fp1, fp2);
7322 tcg_temp_free_i32(fp0);
7323 tcg_temp_free_i32(fp1);
7324 gen_store_fpr32(fp2, fd);
7325 tcg_temp_free_i32(fp2);
7331 check_cp1_registers(ctx, fd | fs | ft | fr);
7333 TCGv_i64 fp0 = tcg_temp_new_i64();
7334 TCGv_i64 fp1 = tcg_temp_new_i64();
7335 TCGv_i64 fp2 = tcg_temp_new_i64();
7337 gen_load_fpr64(ctx, fp0, fs);
7338 gen_load_fpr64(ctx, fp1, ft);
7339 gen_load_fpr64(ctx, fp2, fr);
7340 gen_helper_float_muladd_d(fp2, fp0, fp1, fp2);
7341 tcg_temp_free_i64(fp0);
7342 tcg_temp_free_i64(fp1);
7343 gen_store_fpr64(ctx, fp2, fd);
7344 tcg_temp_free_i64(fp2);
7349 check_cp1_64bitmode(ctx);
7351 TCGv_i64 fp0 = tcg_temp_new_i64();
7352 TCGv_i64 fp1 = tcg_temp_new_i64();
7353 TCGv_i64 fp2 = tcg_temp_new_i64();
7355 gen_load_fpr64(ctx, fp0, fs);
7356 gen_load_fpr64(ctx, fp1, ft);
7357 gen_load_fpr64(ctx, fp2, fr);
7358 gen_helper_float_muladd_ps(fp2, fp0, fp1, fp2);
7359 tcg_temp_free_i64(fp0);
7360 tcg_temp_free_i64(fp1);
7361 gen_store_fpr64(ctx, fp2, fd);
7362 tcg_temp_free_i64(fp2);
7369 TCGv_i32 fp0 = tcg_temp_new_i32();
7370 TCGv_i32 fp1 = tcg_temp_new_i32();
7371 TCGv_i32 fp2 = tcg_temp_new_i32();
7373 gen_load_fpr32(fp0, fs);
7374 gen_load_fpr32(fp1, ft);
7375 gen_load_fpr32(fp2, fr);
7376 gen_helper_float_mulsub_s(fp2, fp0, fp1, fp2);
7377 tcg_temp_free_i32(fp0);
7378 tcg_temp_free_i32(fp1);
7379 gen_store_fpr32(fp2, fd);
7380 tcg_temp_free_i32(fp2);
7386 check_cp1_registers(ctx, fd | fs | ft | fr);
7388 TCGv_i64 fp0 = tcg_temp_new_i64();
7389 TCGv_i64 fp1 = tcg_temp_new_i64();
7390 TCGv_i64 fp2 = tcg_temp_new_i64();
7392 gen_load_fpr64(ctx, fp0, fs);
7393 gen_load_fpr64(ctx, fp1, ft);
7394 gen_load_fpr64(ctx, fp2, fr);
7395 gen_helper_float_mulsub_d(fp2, fp0, fp1, fp2);
7396 tcg_temp_free_i64(fp0);
7397 tcg_temp_free_i64(fp1);
7398 gen_store_fpr64(ctx, fp2, fd);
7399 tcg_temp_free_i64(fp2);
7404 check_cp1_64bitmode(ctx);
7406 TCGv_i64 fp0 = tcg_temp_new_i64();
7407 TCGv_i64 fp1 = tcg_temp_new_i64();
7408 TCGv_i64 fp2 = tcg_temp_new_i64();
7410 gen_load_fpr64(ctx, fp0, fs);
7411 gen_load_fpr64(ctx, fp1, ft);
7412 gen_load_fpr64(ctx, fp2, fr);
7413 gen_helper_float_mulsub_ps(fp2, fp0, fp1, fp2);
7414 tcg_temp_free_i64(fp0);
7415 tcg_temp_free_i64(fp1);
7416 gen_store_fpr64(ctx, fp2, fd);
7417 tcg_temp_free_i64(fp2);
7424 TCGv_i32 fp0 = tcg_temp_new_i32();
7425 TCGv_i32 fp1 = tcg_temp_new_i32();
7426 TCGv_i32 fp2 = tcg_temp_new_i32();
7428 gen_load_fpr32(fp0, fs);
7429 gen_load_fpr32(fp1, ft);
7430 gen_load_fpr32(fp2, fr);
7431 gen_helper_float_nmuladd_s(fp2, fp0, fp1, fp2);
7432 tcg_temp_free_i32(fp0);
7433 tcg_temp_free_i32(fp1);
7434 gen_store_fpr32(fp2, fd);
7435 tcg_temp_free_i32(fp2);
7441 check_cp1_registers(ctx, fd | fs | ft | fr);
7443 TCGv_i64 fp0 = tcg_temp_new_i64();
7444 TCGv_i64 fp1 = tcg_temp_new_i64();
7445 TCGv_i64 fp2 = tcg_temp_new_i64();
7447 gen_load_fpr64(ctx, fp0, fs);
7448 gen_load_fpr64(ctx, fp1, ft);
7449 gen_load_fpr64(ctx, fp2, fr);
7450 gen_helper_float_nmuladd_d(fp2, fp0, fp1, fp2);
7451 tcg_temp_free_i64(fp0);
7452 tcg_temp_free_i64(fp1);
7453 gen_store_fpr64(ctx, fp2, fd);
7454 tcg_temp_free_i64(fp2);
7459 check_cp1_64bitmode(ctx);
7461 TCGv_i64 fp0 = tcg_temp_new_i64();
7462 TCGv_i64 fp1 = tcg_temp_new_i64();
7463 TCGv_i64 fp2 = tcg_temp_new_i64();
7465 gen_load_fpr64(ctx, fp0, fs);
7466 gen_load_fpr64(ctx, fp1, ft);
7467 gen_load_fpr64(ctx, fp2, fr);
7468 gen_helper_float_nmuladd_ps(fp2, fp0, fp1, fp2);
7469 tcg_temp_free_i64(fp0);
7470 tcg_temp_free_i64(fp1);
7471 gen_store_fpr64(ctx, fp2, fd);
7472 tcg_temp_free_i64(fp2);
7479 TCGv_i32 fp0 = tcg_temp_new_i32();
7480 TCGv_i32 fp1 = tcg_temp_new_i32();
7481 TCGv_i32 fp2 = tcg_temp_new_i32();
7483 gen_load_fpr32(fp0, fs);
7484 gen_load_fpr32(fp1, ft);
7485 gen_load_fpr32(fp2, fr);
7486 gen_helper_float_nmulsub_s(fp2, fp0, fp1, fp2);
7487 tcg_temp_free_i32(fp0);
7488 tcg_temp_free_i32(fp1);
7489 gen_store_fpr32(fp2, fd);
7490 tcg_temp_free_i32(fp2);
7496 check_cp1_registers(ctx, fd | fs | ft | fr);
7498 TCGv_i64 fp0 = tcg_temp_new_i64();
7499 TCGv_i64 fp1 = tcg_temp_new_i64();
7500 TCGv_i64 fp2 = tcg_temp_new_i64();
7502 gen_load_fpr64(ctx, fp0, fs);
7503 gen_load_fpr64(ctx, fp1, ft);
7504 gen_load_fpr64(ctx, fp2, fr);
7505 gen_helper_float_nmulsub_d(fp2, fp0, fp1, fp2);
7506 tcg_temp_free_i64(fp0);
7507 tcg_temp_free_i64(fp1);
7508 gen_store_fpr64(ctx, fp2, fd);
7509 tcg_temp_free_i64(fp2);
7514 check_cp1_64bitmode(ctx);
7516 TCGv_i64 fp0 = tcg_temp_new_i64();
7517 TCGv_i64 fp1 = tcg_temp_new_i64();
7518 TCGv_i64 fp2 = tcg_temp_new_i64();
7520 gen_load_fpr64(ctx, fp0, fs);
7521 gen_load_fpr64(ctx, fp1, ft);
7522 gen_load_fpr64(ctx, fp2, fr);
7523 gen_helper_float_nmulsub_ps(fp2, fp0, fp1, fp2);
7524 tcg_temp_free_i64(fp0);
7525 tcg_temp_free_i64(fp1);
7526 gen_store_fpr64(ctx, fp2, fd);
7527 tcg_temp_free_i64(fp2);
7533 generate_exception (ctx, EXCP_RI);
7536 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7537 fregnames[fs], fregnames[ft]);
7540 /* ISA extensions (ASEs) */
7541 /* MIPS16 extension to MIPS32 */
7542 /* SmartMIPS extension to MIPS32 */
7544 #if defined(TARGET_MIPS64)
7546 /* MDMX extension to MIPS64 */
7550 static void decode_opc (CPUState *env, DisasContext *ctx)
7554 uint32_t op, op1, op2;
7557 /* make sure instructions are on a word boundary */
7558 if (ctx->pc & 0x3) {
7559 env->CP0_BadVAddr = ctx->pc;
7560 generate_exception(ctx, EXCP_AdEL);
7564 /* Handle blikely not taken case */
7565 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7566 int l1 = gen_new_label();
7568 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7569 tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
7571 TCGv_i32 r_tmp = tcg_temp_new_i32();
7573 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7574 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7575 tcg_temp_free_i32(r_tmp);
7577 gen_goto_tb(ctx, 1, ctx->pc + 4);
7580 op = MASK_OP_MAJOR(ctx->opcode);
7581 rs = (ctx->opcode >> 21) & 0x1f;
7582 rt = (ctx->opcode >> 16) & 0x1f;
7583 rd = (ctx->opcode >> 11) & 0x1f;
7584 sa = (ctx->opcode >> 6) & 0x1f;
7585 imm = (int16_t)ctx->opcode;
7588 op1 = MASK_SPECIAL(ctx->opcode);
7590 case OPC_SLL: /* Arithmetic with immediate */
7591 case OPC_SRL ... OPC_SRA:
7592 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7594 case OPC_MOVZ ... OPC_MOVN:
7595 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7596 case OPC_SLLV: /* Arithmetic */
7597 case OPC_SRLV ... OPC_SRAV:
7598 case OPC_ADD ... OPC_NOR:
7599 case OPC_SLT ... OPC_SLTU:
7600 gen_arith(env, ctx, op1, rd, rs, rt);
7602 case OPC_MULT ... OPC_DIVU:
7604 check_insn(env, ctx, INSN_VR54XX);
7605 op1 = MASK_MUL_VR54XX(ctx->opcode);
7606 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7608 gen_muldiv(ctx, op1, rs, rt);
7610 case OPC_JR ... OPC_JALR:
7611 gen_compute_branch(ctx, op1, rs, rd, sa);
7613 case OPC_TGE ... OPC_TEQ: /* Traps */
7615 gen_trap(ctx, op1, rs, rt, -1);
7617 case OPC_MFHI: /* Move from HI/LO */
7619 gen_HILO(ctx, op1, rd);
7622 case OPC_MTLO: /* Move to HI/LO */
7623 gen_HILO(ctx, op1, rs);
7625 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7626 #ifdef MIPS_STRICT_STANDARD
7627 MIPS_INVAL("PMON / selsl");
7628 generate_exception(ctx, EXCP_RI);
7630 gen_helper_0i(pmon, sa);
7634 generate_exception(ctx, EXCP_SYSCALL);
7637 generate_exception(ctx, EXCP_BREAK);
7640 #ifdef MIPS_STRICT_STANDARD
7642 generate_exception(ctx, EXCP_RI);
7644 /* Implemented as RI exception for now. */
7645 MIPS_INVAL("spim (unofficial)");
7646 generate_exception(ctx, EXCP_RI);
7654 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7655 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7656 save_cpu_state(ctx, 1);
7657 check_cp1_enabled(ctx);
7658 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7659 (ctx->opcode >> 16) & 1);
7661 generate_exception_err(ctx, EXCP_CpU, 1);
7665 #if defined(TARGET_MIPS64)
7666 /* MIPS64 specific opcodes */
7668 case OPC_DSRL ... OPC_DSRA:
7670 case OPC_DSRL32 ... OPC_DSRA32:
7671 check_insn(env, ctx, ISA_MIPS3);
7673 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7676 case OPC_DSRLV ... OPC_DSRAV:
7677 case OPC_DADD ... OPC_DSUBU:
7678 check_insn(env, ctx, ISA_MIPS3);
7680 gen_arith(env, ctx, op1, rd, rs, rt);
7682 case OPC_DMULT ... OPC_DDIVU:
7683 check_insn(env, ctx, ISA_MIPS3);
7685 gen_muldiv(ctx, op1, rs, rt);
7688 default: /* Invalid */
7689 MIPS_INVAL("special");
7690 generate_exception(ctx, EXCP_RI);
7695 op1 = MASK_SPECIAL2(ctx->opcode);
7697 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7698 case OPC_MSUB ... OPC_MSUBU:
7699 check_insn(env, ctx, ISA_MIPS32);
7700 gen_muldiv(ctx, op1, rs, rt);
7703 gen_arith(env, ctx, op1, rd, rs, rt);
7707 check_insn(env, ctx, ISA_MIPS32);
7708 gen_cl(ctx, op1, rd, rs);
7711 /* XXX: not clear which exception should be raised
7712 * when in debug mode...
7714 check_insn(env, ctx, ISA_MIPS32);
7715 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7716 generate_exception(ctx, EXCP_DBp);
7718 generate_exception(ctx, EXCP_DBp);
7722 #if defined(TARGET_MIPS64)
7725 check_insn(env, ctx, ISA_MIPS64);
7727 gen_cl(ctx, op1, rd, rs);
7730 default: /* Invalid */
7731 MIPS_INVAL("special2");
7732 generate_exception(ctx, EXCP_RI);
7737 op1 = MASK_SPECIAL3(ctx->opcode);
7741 check_insn(env, ctx, ISA_MIPS32R2);
7742 gen_bitops(ctx, op1, rt, rs, sa, rd);
7745 check_insn(env, ctx, ISA_MIPS32R2);
7746 op2 = MASK_BSHFL(ctx->opcode);
7747 gen_bshfl(ctx, op2, rt, rd);
7750 check_insn(env, ctx, ISA_MIPS32R2);
7752 TCGv t0 = tcg_temp_local_new();
7756 save_cpu_state(ctx, 1);
7757 gen_helper_rdhwr_cpunum(t0);
7760 save_cpu_state(ctx, 1);
7761 gen_helper_rdhwr_synci_step(t0);
7764 save_cpu_state(ctx, 1);
7765 gen_helper_rdhwr_cc(t0);
7768 save_cpu_state(ctx, 1);
7769 gen_helper_rdhwr_ccres(t0);
7772 #if defined(CONFIG_USER_ONLY)
7773 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7776 /* XXX: Some CPUs implement this in hardware.
7777 Not supported yet. */
7779 default: /* Invalid */
7780 MIPS_INVAL("rdhwr");
7781 generate_exception(ctx, EXCP_RI);
7784 gen_store_gpr(t0, rt);
7789 check_insn(env, ctx, ASE_MT);
7791 TCGv t0 = tcg_temp_local_new();
7792 TCGv t1 = tcg_temp_local_new();
7794 gen_load_gpr(t0, rt);
7795 gen_load_gpr(t1, rs);
7796 gen_helper_fork(t0, t1);
7802 check_insn(env, ctx, ASE_MT);
7804 TCGv t0 = tcg_temp_local_new();
7806 gen_load_gpr(t0, rs);
7807 gen_helper_yield(t0, t0);
7808 gen_store_gpr(t0, rd);
7812 #if defined(TARGET_MIPS64)
7813 case OPC_DEXTM ... OPC_DEXT:
7814 case OPC_DINSM ... OPC_DINS:
7815 check_insn(env, ctx, ISA_MIPS64R2);
7817 gen_bitops(ctx, op1, rt, rs, sa, rd);
7820 check_insn(env, ctx, ISA_MIPS64R2);
7822 op2 = MASK_DBSHFL(ctx->opcode);
7823 gen_bshfl(ctx, op2, rt, rd);
7826 default: /* Invalid */
7827 MIPS_INVAL("special3");
7828 generate_exception(ctx, EXCP_RI);
7833 op1 = MASK_REGIMM(ctx->opcode);
7835 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7836 case OPC_BLTZAL ... OPC_BGEZALL:
7837 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7839 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7841 gen_trap(ctx, op1, rs, -1, imm);
7844 check_insn(env, ctx, ISA_MIPS32R2);
7847 default: /* Invalid */
7848 MIPS_INVAL("regimm");
7849 generate_exception(ctx, EXCP_RI);
7854 check_cp0_enabled(ctx);
7855 op1 = MASK_CP0(ctx->opcode);
7861 #if defined(TARGET_MIPS64)
7865 #ifndef CONFIG_USER_ONLY
7866 gen_cp0(env, ctx, op1, rt, rd);
7867 #endif /* !CONFIG_USER_ONLY */
7869 case OPC_C0_FIRST ... OPC_C0_LAST:
7870 #ifndef CONFIG_USER_ONLY
7871 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7872 #endif /* !CONFIG_USER_ONLY */
7875 #ifndef CONFIG_USER_ONLY
7877 TCGv t0 = tcg_temp_local_new();
7879 op2 = MASK_MFMC0(ctx->opcode);
7882 check_insn(env, ctx, ASE_MT);
7883 gen_helper_dmt(t0, t0);
7886 check_insn(env, ctx, ASE_MT);
7887 gen_helper_emt(t0, t0);
7890 check_insn(env, ctx, ASE_MT);
7891 gen_helper_dvpe(t0, t0);
7894 check_insn(env, ctx, ASE_MT);
7895 gen_helper_evpe(t0, t0);
7898 check_insn(env, ctx, ISA_MIPS32R2);
7899 save_cpu_state(ctx, 1);
7901 /* Stop translation as we may have switched the execution mode */
7902 ctx->bstate = BS_STOP;
7905 check_insn(env, ctx, ISA_MIPS32R2);
7906 save_cpu_state(ctx, 1);
7908 /* Stop translation as we may have switched the execution mode */
7909 ctx->bstate = BS_STOP;
7911 default: /* Invalid */
7912 MIPS_INVAL("mfmc0");
7913 generate_exception(ctx, EXCP_RI);
7916 gen_store_gpr(t0, rt);
7919 #endif /* !CONFIG_USER_ONLY */
7922 check_insn(env, ctx, ISA_MIPS32R2);
7923 gen_load_srsgpr(rt, rd);
7926 check_insn(env, ctx, ISA_MIPS32R2);
7927 gen_store_srsgpr(rt, rd);
7931 generate_exception(ctx, EXCP_RI);
7935 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7936 gen_arith_imm(env, ctx, op, rt, rs, imm);
7938 case OPC_J ... OPC_JAL: /* Jump */
7939 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7940 gen_compute_branch(ctx, op, rs, rt, offset);
7942 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7943 case OPC_BEQL ... OPC_BGTZL:
7944 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7946 case OPC_LB ... OPC_LWR: /* Load and stores */
7947 case OPC_SB ... OPC_SW:
7951 gen_ldst(ctx, op, rt, rs, imm);
7954 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7958 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7962 /* Floating point (COP1). */
7967 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7968 save_cpu_state(ctx, 1);
7969 check_cp1_enabled(ctx);
7970 gen_flt_ldst(ctx, op, rt, rs, imm);
7972 generate_exception_err(ctx, EXCP_CpU, 1);
7977 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7978 save_cpu_state(ctx, 1);
7979 check_cp1_enabled(ctx);
7980 op1 = MASK_CP1(ctx->opcode);
7984 check_insn(env, ctx, ISA_MIPS32R2);
7989 gen_cp1(ctx, op1, rt, rd);
7991 #if defined(TARGET_MIPS64)
7994 check_insn(env, ctx, ISA_MIPS3);
7995 gen_cp1(ctx, op1, rt, rd);
8001 check_insn(env, ctx, ASE_MIPS3D);
8004 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8005 (rt >> 2) & 0x7, imm << 2);
8012 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8017 generate_exception (ctx, EXCP_RI);
8021 generate_exception_err(ctx, EXCP_CpU, 1);
8031 /* COP2: Not implemented. */
8032 generate_exception_err(ctx, EXCP_CpU, 2);
8036 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8037 save_cpu_state(ctx, 1);
8038 check_cp1_enabled(ctx);
8039 op1 = MASK_CP3(ctx->opcode);
8047 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8065 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8069 generate_exception (ctx, EXCP_RI);
8073 generate_exception_err(ctx, EXCP_CpU, 1);
8077 #if defined(TARGET_MIPS64)
8078 /* MIPS64 opcodes */
8080 case OPC_LDL ... OPC_LDR:
8081 case OPC_SDL ... OPC_SDR:
8086 check_insn(env, ctx, ISA_MIPS3);
8088 gen_ldst(ctx, op, rt, rs, imm);
8090 case OPC_DADDI ... OPC_DADDIU:
8091 check_insn(env, ctx, ISA_MIPS3);
8093 gen_arith_imm(env, ctx, op, rt, rs, imm);
8097 check_insn(env, ctx, ASE_MIPS16);
8098 /* MIPS16: Not implemented. */
8100 check_insn(env, ctx, ASE_MDMX);
8101 /* MDMX: Not implemented. */
8102 default: /* Invalid */
8103 MIPS_INVAL("major opcode");
8104 generate_exception(ctx, EXCP_RI);
8107 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8108 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8109 /* Branches completion */
8110 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8111 ctx->bstate = BS_BRANCH;
8112 save_cpu_state(ctx, 0);
8113 /* FIXME: Need to clear can_do_io. */
8116 /* unconditional branch */
8117 MIPS_DEBUG("unconditional branch");
8118 gen_goto_tb(ctx, 0, ctx->btarget);
8121 /* blikely taken case */
8122 MIPS_DEBUG("blikely branch taken");
8123 gen_goto_tb(ctx, 0, ctx->btarget);
8126 /* Conditional branch */
8127 MIPS_DEBUG("conditional branch");
8129 int l1 = gen_new_label();
8131 tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
8132 gen_goto_tb(ctx, 1, ctx->pc + 4);
8134 gen_goto_tb(ctx, 0, ctx->btarget);
8138 /* unconditional branch to register */
8139 MIPS_DEBUG("branch to register");
8140 tcg_gen_mov_tl(cpu_PC, btarget);
8144 MIPS_DEBUG("unknown branch");
8151 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8155 target_ulong pc_start;
8156 uint16_t *gen_opc_end;
8163 qemu_log("search pc %d\n", search_pc);
8166 /* Leave some spare opc slots for branch handling. */
8167 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8171 ctx.bstate = BS_NONE;
8172 /* Restore delay slot state from the tb context. */
8173 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8174 restore_cpu_state(env, &ctx);
8175 #ifdef CONFIG_USER_ONLY
8176 ctx.mem_idx = MIPS_HFLAG_UM;
8178 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8181 max_insns = tb->cflags & CF_COUNT_MASK;
8183 max_insns = CF_COUNT_MASK;
8185 qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n");
8186 /* FIXME: This may print out stale hflags from env... */
8187 log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
8189 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags);
8191 while (ctx.bstate == BS_NONE) {
8192 if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
8193 TAILQ_FOREACH(bp, &env->breakpoints, entry) {
8194 if (bp->pc == ctx.pc) {
8195 save_cpu_state(&ctx, 1);
8196 ctx.bstate = BS_BRANCH;
8197 gen_helper_0i(raise_exception, EXCP_DEBUG);
8198 /* Include the breakpoint location or the tb won't
8199 * be flushed when it must be. */
8201 goto done_generating;
8207 j = gen_opc_ptr - gen_opc_buf;
8211 gen_opc_instr_start[lj++] = 0;
8213 gen_opc_pc[lj] = ctx.pc;
8214 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8215 gen_opc_instr_start[lj] = 1;
8216 gen_opc_icount[lj] = num_insns;
8218 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8220 ctx.opcode = ldl_code(ctx.pc);
8221 decode_opc(env, &ctx);
8225 if (env->singlestep_enabled)
8228 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8231 if (gen_opc_ptr >= gen_opc_end)
8234 if (num_insns >= max_insns)
8236 #if defined (MIPS_SINGLE_STEP)
8240 if (tb->cflags & CF_LAST_IO)
8242 if (env->singlestep_enabled) {
8243 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8244 gen_helper_0i(raise_exception, EXCP_DEBUG);
8246 switch (ctx.bstate) {
8248 gen_helper_interrupt_restart();
8249 gen_goto_tb(&ctx, 0, ctx.pc);
8252 save_cpu_state(&ctx, 0);
8253 gen_goto_tb(&ctx, 0, ctx.pc);
8256 gen_helper_interrupt_restart();
8265 gen_icount_end(tb, num_insns);
8266 *gen_opc_ptr = INDEX_op_end;
8268 j = gen_opc_ptr - gen_opc_buf;
8271 gen_opc_instr_start[lj++] = 0;
8273 tb->size = ctx.pc - pc_start;
8274 tb->icount = num_insns;
8278 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
8279 qemu_log("IN: %s\n", lookup_symbol(pc_start));
8280 log_target_disas(pc_start, ctx.pc - pc_start, 0);
8283 qemu_log_mask(CPU_LOG_TB_CPU, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8287 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8289 gen_intermediate_code_internal(env, tb, 0);
8292 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8294 gen_intermediate_code_internal(env, tb, 1);
8297 static void fpu_dump_state(CPUState *env, FILE *f,
8298 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8302 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8304 #define printfpr(fp) \
8307 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8308 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8309 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8312 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8313 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8314 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8315 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8316 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8321 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8322 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8323 get_float_exception_flags(&env->active_fpu.fp_status));
8324 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8325 fpu_fprintf(f, "%3s: ", fregnames[i]);
8326 printfpr(&env->active_fpu.fpr[i]);
8332 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8333 /* Debug help: The architecture requires 32bit code to maintain proper
8334 sign-extended values on 64bit machines. */
8336 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8339 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8340 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8345 if (!SIGN_EXT_P(env->active_tc.PC))
8346 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8347 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8348 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8349 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8350 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8351 if (!SIGN_EXT_P(env->btarget))
8352 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8354 for (i = 0; i < 32; i++) {
8355 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8356 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8359 if (!SIGN_EXT_P(env->CP0_EPC))
8360 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8361 if (!SIGN_EXT_P(env->CP0_LLAddr))
8362 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8366 void cpu_dump_state (CPUState *env, FILE *f,
8367 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8372 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",
8373 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8374 env->hflags, env->btarget, env->bcond);
8375 for (i = 0; i < 32; i++) {
8377 cpu_fprintf(f, "GPR%02d:", i);
8378 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8380 cpu_fprintf(f, "\n");
8383 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8384 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8385 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8386 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8387 if (env->hflags & MIPS_HFLAG_FPU)
8388 fpu_dump_state(env, f, cpu_fprintf, flags);
8389 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8390 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8394 static void mips_tcg_init(void)
8399 /* Initialize various static tables. */
8403 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
8404 for (i = 0; i < 32; i++)
8405 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
8406 offsetof(CPUState, active_tc.gpr[i]),
8408 cpu_PC = tcg_global_mem_new(TCG_AREG0,
8409 offsetof(CPUState, active_tc.PC), "PC");
8410 for (i = 0; i < MIPS_DSP_ACC; i++) {
8411 cpu_HI[i] = tcg_global_mem_new(TCG_AREG0,
8412 offsetof(CPUState, active_tc.HI[i]),
8414 cpu_LO[i] = tcg_global_mem_new(TCG_AREG0,
8415 offsetof(CPUState, active_tc.LO[i]),
8417 cpu_ACX[i] = tcg_global_mem_new(TCG_AREG0,
8418 offsetof(CPUState, active_tc.ACX[i]),
8421 cpu_dspctrl = tcg_global_mem_new(TCG_AREG0,
8422 offsetof(CPUState, active_tc.DSPControl),
8424 bcond = tcg_global_mem_new(TCG_AREG0,
8425 offsetof(CPUState, bcond), "bcond");
8426 btarget = tcg_global_mem_new(TCG_AREG0,
8427 offsetof(CPUState, btarget), "btarget");
8428 for (i = 0; i < 32; i++)
8429 fpu_fpr32[i] = tcg_global_mem_new_i32(TCG_AREG0,
8430 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8432 for (i = 0; i < 32; i++)
8433 fpu_fpr32h[i] = tcg_global_mem_new_i32(TCG_AREG0,
8434 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8436 fpu_fcr0 = tcg_global_mem_new_i32(TCG_AREG0,
8437 offsetof(CPUState, active_fpu.fcr0),
8439 fpu_fcr31 = tcg_global_mem_new_i32(TCG_AREG0,
8440 offsetof(CPUState, active_fpu.fcr31),
8443 /* register helpers */
8444 #define GEN_HELPER 2
8450 #include "translate_init.c"
8452 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8455 const mips_def_t *def;
8457 def = cpu_mips_find_by_name(cpu_model);
8460 env = qemu_mallocz(sizeof(CPUMIPSState));
8461 env->cpu_model = def;
8464 env->cpu_model_str = cpu_model;
8470 void cpu_reset (CPUMIPSState *env)
8472 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
8473 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
8474 log_cpu_state(env, 0);
8477 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8482 #if defined(CONFIG_USER_ONLY)
8483 env->hflags = MIPS_HFLAG_UM;
8485 if (env->hflags & MIPS_HFLAG_BMASK) {
8486 /* If the exception was raised from a delay slot,
8487 come back to the jump. */
8488 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8490 env->CP0_ErrorEPC = env->active_tc.PC;
8492 env->active_tc.PC = (int32_t)0xBFC00000;
8494 /* SMP not implemented */
8495 env->CP0_EBase = 0x80000000;
8496 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8497 /* vectored interrupts not implemented, timer on int 7,
8498 no performance counters. */
8499 env->CP0_IntCtl = 0xe0000000;
8503 for (i = 0; i < 7; i++) {
8504 env->CP0_WatchLo[i] = 0;
8505 env->CP0_WatchHi[i] = 0x80000000;
8507 env->CP0_WatchLo[7] = 0;
8508 env->CP0_WatchHi[7] = 0;
8510 /* Count register increments in debug mode, EJTAG version 1 */
8511 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8512 env->hflags = MIPS_HFLAG_CP0;
8514 env->exception_index = EXCP_NONE;
8515 cpu_mips_register(env, env->cpu_model);
8518 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8519 unsigned long searched_pc, int pc_pos, void *puc)
8521 env->active_tc.PC = gen_opc_pc[pc_pos];
8522 env->hflags &= ~MIPS_HFLAG_BMASK;
8523 env->hflags |= gen_opc_hflags[pc_pos];