2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
41 //#define MIPS_SINGLE_STEP
43 /* MIPS major opcodes */
44 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
47 /* indirect opcode tables */
48 OPC_SPECIAL = (0x00 << 26),
49 OPC_REGIMM = (0x01 << 26),
50 OPC_CP0 = (0x10 << 26),
51 OPC_CP1 = (0x11 << 26),
52 OPC_CP2 = (0x12 << 26),
53 OPC_CP3 = (0x13 << 26),
54 OPC_SPECIAL2 = (0x1C << 26),
55 OPC_SPECIAL3 = (0x1F << 26),
56 /* arithmetic with immediate */
57 OPC_ADDI = (0x08 << 26),
58 OPC_ADDIU = (0x09 << 26),
59 OPC_SLTI = (0x0A << 26),
60 OPC_SLTIU = (0x0B << 26),
61 OPC_ANDI = (0x0C << 26),
62 OPC_ORI = (0x0D << 26),
63 OPC_XORI = (0x0E << 26),
64 OPC_LUI = (0x0F << 26),
65 OPC_DADDI = (0x18 << 26),
66 OPC_DADDIU = (0x19 << 26),
67 /* Jump and branches */
69 OPC_JAL = (0x03 << 26),
70 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
71 OPC_BEQL = (0x14 << 26),
72 OPC_BNE = (0x05 << 26),
73 OPC_BNEL = (0x15 << 26),
74 OPC_BLEZ = (0x06 << 26),
75 OPC_BLEZL = (0x16 << 26),
76 OPC_BGTZ = (0x07 << 26),
77 OPC_BGTZL = (0x17 << 26),
78 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
80 OPC_LDL = (0x1A << 26),
81 OPC_LDR = (0x1B << 26),
82 OPC_LB = (0x20 << 26),
83 OPC_LH = (0x21 << 26),
84 OPC_LWL = (0x22 << 26),
85 OPC_LW = (0x23 << 26),
86 OPC_LBU = (0x24 << 26),
87 OPC_LHU = (0x25 << 26),
88 OPC_LWR = (0x26 << 26),
89 OPC_LWU = (0x27 << 26),
90 OPC_SB = (0x28 << 26),
91 OPC_SH = (0x29 << 26),
92 OPC_SWL = (0x2A << 26),
93 OPC_SW = (0x2B << 26),
94 OPC_SDL = (0x2C << 26),
95 OPC_SDR = (0x2D << 26),
96 OPC_SWR = (0x2E << 26),
97 OPC_LL = (0x30 << 26),
98 OPC_LLD = (0x34 << 26),
99 OPC_LD = (0x37 << 26),
100 OPC_SC = (0x38 << 26),
101 OPC_SCD = (0x3C << 26),
102 OPC_SD = (0x3F << 26),
103 /* Floating point load/store */
104 OPC_LWC1 = (0x31 << 26),
105 OPC_LWC2 = (0x32 << 26),
106 OPC_LDC1 = (0x35 << 26),
107 OPC_LDC2 = (0x36 << 26),
108 OPC_SWC1 = (0x39 << 26),
109 OPC_SWC2 = (0x3A << 26),
110 OPC_SDC1 = (0x3D << 26),
111 OPC_SDC2 = (0x3E << 26),
112 /* MDMX ASE specific */
113 OPC_MDMX = (0x1E << 26),
114 /* Cache and prefetch */
115 OPC_CACHE = (0x2F << 26),
116 OPC_PREF = (0x33 << 26),
117 /* Reserved major opcode */
118 OPC_MAJOR3B_RESERVED = (0x3B << 26),
121 /* MIPS special opcodes */
122 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
126 OPC_SLL = 0x00 | OPC_SPECIAL,
127 /* NOP is SLL r0, r0, 0 */
128 /* SSNOP is SLL r0, r0, 1 */
129 /* EHB is SLL r0, r0, 3 */
130 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
131 OPC_SRA = 0x03 | OPC_SPECIAL,
132 OPC_SLLV = 0x04 | OPC_SPECIAL,
133 OPC_SRLV = 0x06 | OPC_SPECIAL, /* also ROTRV */
134 OPC_SRAV = 0x07 | OPC_SPECIAL,
135 OPC_DSLLV = 0x14 | OPC_SPECIAL,
136 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
137 OPC_DSRAV = 0x17 | OPC_SPECIAL,
138 OPC_DSLL = 0x38 | OPC_SPECIAL,
139 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
140 OPC_DSRA = 0x3B | OPC_SPECIAL,
141 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
142 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
143 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
144 /* Multiplication / division */
145 OPC_MULT = 0x18 | OPC_SPECIAL,
146 OPC_MULTU = 0x19 | OPC_SPECIAL,
147 OPC_DIV = 0x1A | OPC_SPECIAL,
148 OPC_DIVU = 0x1B | OPC_SPECIAL,
149 OPC_DMULT = 0x1C | OPC_SPECIAL,
150 OPC_DMULTU = 0x1D | OPC_SPECIAL,
151 OPC_DDIV = 0x1E | OPC_SPECIAL,
152 OPC_DDIVU = 0x1F | OPC_SPECIAL,
153 /* 2 registers arithmetic / logic */
154 OPC_ADD = 0x20 | OPC_SPECIAL,
155 OPC_ADDU = 0x21 | OPC_SPECIAL,
156 OPC_SUB = 0x22 | OPC_SPECIAL,
157 OPC_SUBU = 0x23 | OPC_SPECIAL,
158 OPC_AND = 0x24 | OPC_SPECIAL,
159 OPC_OR = 0x25 | OPC_SPECIAL,
160 OPC_XOR = 0x26 | OPC_SPECIAL,
161 OPC_NOR = 0x27 | OPC_SPECIAL,
162 OPC_SLT = 0x2A | OPC_SPECIAL,
163 OPC_SLTU = 0x2B | OPC_SPECIAL,
164 OPC_DADD = 0x2C | OPC_SPECIAL,
165 OPC_DADDU = 0x2D | OPC_SPECIAL,
166 OPC_DSUB = 0x2E | OPC_SPECIAL,
167 OPC_DSUBU = 0x2F | OPC_SPECIAL,
169 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
170 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
172 OPC_TGE = 0x30 | OPC_SPECIAL,
173 OPC_TGEU = 0x31 | OPC_SPECIAL,
174 OPC_TLT = 0x32 | OPC_SPECIAL,
175 OPC_TLTU = 0x33 | OPC_SPECIAL,
176 OPC_TEQ = 0x34 | OPC_SPECIAL,
177 OPC_TNE = 0x36 | OPC_SPECIAL,
178 /* HI / LO registers load & stores */
179 OPC_MFHI = 0x10 | OPC_SPECIAL,
180 OPC_MTHI = 0x11 | OPC_SPECIAL,
181 OPC_MFLO = 0x12 | OPC_SPECIAL,
182 OPC_MTLO = 0x13 | OPC_SPECIAL,
183 /* Conditional moves */
184 OPC_MOVZ = 0x0A | OPC_SPECIAL,
185 OPC_MOVN = 0x0B | OPC_SPECIAL,
187 OPC_MOVCI = 0x01 | OPC_SPECIAL,
190 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
191 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
192 OPC_BREAK = 0x0D | OPC_SPECIAL,
193 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
194 OPC_SYNC = 0x0F | OPC_SPECIAL,
196 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
197 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
198 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
199 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
200 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
201 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
202 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
205 /* Multiplication variants of the vr54xx. */
206 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
209 OPC_VR54XX_MULS = (0x03 << 6) | OPC_MULT,
210 OPC_VR54XX_MULSU = (0x03 << 6) | OPC_MULTU,
211 OPC_VR54XX_MACC = (0x05 << 6) | OPC_MULT,
212 OPC_VR54XX_MACCU = (0x05 << 6) | OPC_MULTU,
213 OPC_VR54XX_MSAC = (0x07 << 6) | OPC_MULT,
214 OPC_VR54XX_MSACU = (0x07 << 6) | OPC_MULTU,
215 OPC_VR54XX_MULHI = (0x09 << 6) | OPC_MULT,
216 OPC_VR54XX_MULHIU = (0x09 << 6) | OPC_MULTU,
217 OPC_VR54XX_MULSHI = (0x0B << 6) | OPC_MULT,
218 OPC_VR54XX_MULSHIU = (0x0B << 6) | OPC_MULTU,
219 OPC_VR54XX_MACCHI = (0x0D << 6) | OPC_MULT,
220 OPC_VR54XX_MACCHIU = (0x0D << 6) | OPC_MULTU,
221 OPC_VR54XX_MSACHI = (0x0F << 6) | OPC_MULT,
222 OPC_VR54XX_MSACHIU = (0x0F << 6) | OPC_MULTU,
225 /* REGIMM (rt field) opcodes */
226 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
229 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
230 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
231 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
232 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
233 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
234 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
235 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
236 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
237 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
238 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
239 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
240 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
241 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
242 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
243 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
246 /* Special2 opcodes */
247 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
250 /* Multiply & xxx operations */
251 OPC_MADD = 0x00 | OPC_SPECIAL2,
252 OPC_MADDU = 0x01 | OPC_SPECIAL2,
253 OPC_MUL = 0x02 | OPC_SPECIAL2,
254 OPC_MSUB = 0x04 | OPC_SPECIAL2,
255 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
257 OPC_CLZ = 0x20 | OPC_SPECIAL2,
258 OPC_CLO = 0x21 | OPC_SPECIAL2,
259 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
260 OPC_DCLO = 0x25 | OPC_SPECIAL2,
262 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
265 /* Special3 opcodes */
266 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
269 OPC_EXT = 0x00 | OPC_SPECIAL3,
270 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
271 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
272 OPC_DEXT = 0x03 | OPC_SPECIAL3,
273 OPC_INS = 0x04 | OPC_SPECIAL3,
274 OPC_DINSM = 0x05 | OPC_SPECIAL3,
275 OPC_DINSU = 0x06 | OPC_SPECIAL3,
276 OPC_DINS = 0x07 | OPC_SPECIAL3,
277 OPC_FORK = 0x08 | OPC_SPECIAL3,
278 OPC_YIELD = 0x09 | OPC_SPECIAL3,
279 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
280 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
281 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
285 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
288 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
289 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
290 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
294 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
297 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
298 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
301 /* Coprocessor 0 (rs field) */
302 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
305 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
306 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
307 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
308 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
309 OPC_MFTR = (0x08 << 21) | OPC_CP0,
310 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
311 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
312 OPC_MTTR = (0x0C << 21) | OPC_CP0,
313 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
314 OPC_C0 = (0x10 << 21) | OPC_CP0,
315 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
316 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
320 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
323 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
324 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
325 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
326 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
327 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
328 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
331 /* Coprocessor 0 (with rs == C0) */
332 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
335 OPC_TLBR = 0x01 | OPC_C0,
336 OPC_TLBWI = 0x02 | OPC_C0,
337 OPC_TLBWR = 0x06 | OPC_C0,
338 OPC_TLBP = 0x08 | OPC_C0,
339 OPC_RFE = 0x10 | OPC_C0,
340 OPC_ERET = 0x18 | OPC_C0,
341 OPC_DERET = 0x1F | OPC_C0,
342 OPC_WAIT = 0x20 | OPC_C0,
345 /* Coprocessor 1 (rs field) */
346 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
349 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
350 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
351 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
352 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
353 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
354 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
355 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
356 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
357 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
358 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
359 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
360 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
361 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
362 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
363 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
364 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
365 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
366 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
369 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
370 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
373 OPC_BC1F = (0x00 << 16) | OPC_BC1,
374 OPC_BC1T = (0x01 << 16) | OPC_BC1,
375 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
376 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
380 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
381 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
385 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
386 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
389 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
392 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
393 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
394 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
395 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
396 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
397 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
398 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
399 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
400 OPC_BC2 = (0x08 << 21) | OPC_CP2,
403 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
406 OPC_LWXC1 = 0x00 | OPC_CP3,
407 OPC_LDXC1 = 0x01 | OPC_CP3,
408 OPC_LUXC1 = 0x05 | OPC_CP3,
409 OPC_SWXC1 = 0x08 | OPC_CP3,
410 OPC_SDXC1 = 0x09 | OPC_CP3,
411 OPC_SUXC1 = 0x0D | OPC_CP3,
412 OPC_PREFX = 0x0F | OPC_CP3,
413 OPC_ALNV_PS = 0x1E | OPC_CP3,
414 OPC_MADD_S = 0x20 | OPC_CP3,
415 OPC_MADD_D = 0x21 | OPC_CP3,
416 OPC_MADD_PS = 0x26 | OPC_CP3,
417 OPC_MSUB_S = 0x28 | OPC_CP3,
418 OPC_MSUB_D = 0x29 | OPC_CP3,
419 OPC_MSUB_PS = 0x2E | OPC_CP3,
420 OPC_NMADD_S = 0x30 | OPC_CP3,
421 OPC_NMADD_D = 0x31 | OPC_CP3,
422 OPC_NMADD_PS= 0x36 | OPC_CP3,
423 OPC_NMSUB_S = 0x38 | OPC_CP3,
424 OPC_NMSUB_D = 0x39 | OPC_CP3,
425 OPC_NMSUB_PS= 0x3E | OPC_CP3,
428 /* global register indices */
429 static TCGv_ptr cpu_env;
430 static TCGv cpu_gpr[32], cpu_PC;
431 static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC], cpu_ACX[MIPS_DSP_ACC];
432 static TCGv cpu_dspctrl, btarget;
433 static TCGv_i32 bcond;
434 static TCGv_i32 fpu_fpr32[32], fpu_fpr32h[32];
435 static TCGv_i32 fpu_fcr0, fpu_fcr31;
437 #include "gen-icount.h"
439 #define gen_helper_0i(name, arg) do { \
440 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
441 gen_helper_##name(helper_tmp); \
442 tcg_temp_free_i32(helper_tmp); \
445 #define gen_helper_1i(name, arg1, arg2) do { \
446 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
447 gen_helper_##name(arg1, helper_tmp); \
448 tcg_temp_free_i32(helper_tmp); \
451 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
452 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
453 gen_helper_##name(arg1, arg2, helper_tmp); \
454 tcg_temp_free_i32(helper_tmp); \
457 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
458 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
459 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
460 tcg_temp_free_i32(helper_tmp); \
463 typedef struct DisasContext {
464 struct TranslationBlock *tb;
465 target_ulong pc, saved_pc;
467 /* Routine used to access memory */
469 uint32_t hflags, saved_hflags;
471 target_ulong btarget;
475 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
476 * exception condition */
477 BS_STOP = 1, /* We want to stop translation for any reason */
478 BS_BRANCH = 2, /* We reached a branch condition */
479 BS_EXCP = 3, /* We reached an exception condition */
482 static const char *regnames[] =
483 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
484 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
485 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
486 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
488 static const char *regnames_HI[] =
489 { "HI0", "HI1", "HI2", "HI3", };
491 static const char *regnames_LO[] =
492 { "LO0", "LO1", "LO2", "LO3", };
494 static const char *regnames_ACX[] =
495 { "ACX0", "ACX1", "ACX2", "ACX3", };
497 static const char *fregnames[] =
498 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
499 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
500 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
501 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
503 static const char *fregnames_h[] =
504 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
505 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
506 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
507 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
509 #ifdef MIPS_DEBUG_DISAS
510 #define MIPS_DEBUG(fmt, args...) \
511 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
512 TARGET_FMT_lx ": %08x " fmt "\n", \
513 ctx->pc, ctx->opcode , ##args)
514 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
516 #define MIPS_DEBUG(fmt, args...) do { } while(0)
517 #define LOG_DISAS(...) do { } while (0)
520 #define MIPS_INVAL(op) \
522 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
523 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
526 /* General purpose registers moves. */
527 static inline void gen_load_gpr (TCGv t, int reg)
530 tcg_gen_movi_tl(t, 0);
532 tcg_gen_mov_tl(t, cpu_gpr[reg]);
535 static inline void gen_store_gpr (TCGv t, int reg)
538 tcg_gen_mov_tl(cpu_gpr[reg], t);
541 /* Moves to/from ACX register. */
542 static inline void gen_load_ACX (TCGv t, int reg)
544 tcg_gen_mov_tl(t, cpu_ACX[reg]);
547 static inline void gen_store_ACX (TCGv t, int reg)
549 tcg_gen_mov_tl(cpu_ACX[reg], t);
552 /* Moves to/from shadow registers. */
553 static inline void gen_load_srsgpr (int from, int to)
555 TCGv r_tmp1 = tcg_temp_new();
558 tcg_gen_movi_tl(r_tmp1, 0);
560 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
561 TCGv_ptr addr = tcg_temp_new_ptr();
563 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
564 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
565 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
566 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
567 tcg_gen_ext_i32_ptr(addr, r_tmp2);
568 tcg_gen_add_ptr(addr, cpu_env, addr);
570 tcg_gen_ld_tl(r_tmp1, addr, sizeof(target_ulong) * from);
571 tcg_temp_free_ptr(addr);
572 tcg_temp_free_i32(r_tmp2);
574 gen_store_gpr(r_tmp1, to);
575 tcg_temp_free(r_tmp1);
578 static inline void gen_store_srsgpr (int from, int to)
581 TCGv r_tmp1 = tcg_temp_new();
582 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
583 TCGv_ptr addr = tcg_temp_new_ptr();
585 gen_load_gpr(r_tmp1, from);
586 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
587 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
588 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
589 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
590 tcg_gen_ext_i32_ptr(addr, r_tmp2);
591 tcg_gen_add_ptr(addr, cpu_env, addr);
593 tcg_gen_st_tl(r_tmp1, addr, sizeof(target_ulong) * to);
594 tcg_temp_free_ptr(addr);
595 tcg_temp_free_i32(r_tmp2);
596 tcg_temp_free(r_tmp1);
600 /* Floating point register moves. */
601 static inline void gen_load_fpr32 (TCGv_i32 t, int reg)
603 tcg_gen_mov_i32(t, fpu_fpr32[reg]);
606 static inline void gen_store_fpr32 (TCGv_i32 t, int reg)
608 tcg_gen_mov_i32(fpu_fpr32[reg], t);
611 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
613 if (ctx->hflags & MIPS_HFLAG_F64) {
614 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg], fpu_fpr32h[reg]);
616 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg & ~1], fpu_fpr32[reg | 1]);
620 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
622 if (ctx->hflags & MIPS_HFLAG_F64) {
623 tcg_gen_trunc_i64_i32(fpu_fpr32[reg], t);
624 tcg_gen_shri_i64(t, t, 32);
625 tcg_gen_trunc_i64_i32(fpu_fpr32h[reg], t);
627 tcg_gen_trunc_i64_i32(fpu_fpr32[reg & ~1], t);
628 tcg_gen_shri_i64(t, t, 32);
629 tcg_gen_trunc_i64_i32(fpu_fpr32[reg | 1], t);
633 static inline void gen_load_fpr32h (TCGv_i32 t, int reg)
635 tcg_gen_mov_i32(t, fpu_fpr32h[reg]);
638 static inline void gen_store_fpr32h (TCGv_i32 t, int reg)
640 tcg_gen_mov_i32(fpu_fpr32h[reg], t);
643 static inline void get_fp_cond (TCGv_i32 t)
645 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
646 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
648 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
649 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
650 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
651 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
652 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
653 tcg_temp_free_i32(r_tmp1);
654 tcg_temp_free_i32(r_tmp2);
657 #define FOP_CONDS(type, fmt, bits) \
658 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
659 TCGv_i##bits b, int cc) \
662 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
663 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
664 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
665 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
666 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
667 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
668 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
669 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
670 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
671 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
672 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
673 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
674 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
675 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
676 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
677 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
683 FOP_CONDS(abs, d, 64)
685 FOP_CONDS(abs, s, 32)
687 FOP_CONDS(abs, ps, 64)
691 #define OP_COND(name, cond) \
692 static inline void glue(gen_op_, name) (TCGv 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_local_new();
2170 TCGv t1 = tcg_temp_local_new();
2173 /* Load needed operands */
2181 /* Compare two registers */
2183 gen_load_gpr(t0, rs);
2184 gen_load_gpr(t1, rt);
2194 /* Compare register to immediate */
2195 if (rs != 0 || imm != 0) {
2196 gen_load_gpr(t0, rs);
2197 tcg_gen_movi_tl(t1, (int32_t)imm);
2204 case OPC_TEQ: /* rs == rs */
2205 case OPC_TEQI: /* r0 == 0 */
2206 case OPC_TGE: /* rs >= rs */
2207 case OPC_TGEI: /* r0 >= 0 */
2208 case OPC_TGEU: /* rs >= rs unsigned */
2209 case OPC_TGEIU: /* r0 >= 0 unsigned */
2211 tcg_gen_movi_tl(t0, 1);
2213 case OPC_TLT: /* rs < rs */
2214 case OPC_TLTI: /* r0 < 0 */
2215 case OPC_TLTU: /* rs < rs unsigned */
2216 case OPC_TLTIU: /* r0 < 0 unsigned */
2217 case OPC_TNE: /* rs != rs */
2218 case OPC_TNEI: /* r0 != 0 */
2219 /* Never trap: treat as NOP. */
2223 generate_exception(ctx, EXCP_RI);
2230 gen_op_eq(t0, t0, t1);
2234 gen_op_ge(t0, t0, t1);
2238 gen_op_geu(t0, t0, t1);
2242 gen_op_lt(t0, t0, t1);
2246 gen_op_ltu(t0, t0, t1);
2250 gen_op_ne(t0, t0, t1);
2254 generate_exception(ctx, EXCP_RI);
2258 save_cpu_state(ctx, 1);
2260 int l1 = gen_new_label();
2262 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2263 gen_helper_0i(raise_exception, EXCP_TRAP);
2266 ctx->bstate = BS_STOP;
2272 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2274 TranslationBlock *tb;
2276 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2279 tcg_gen_exit_tb((long)tb + n);
2286 /* Branches (before delay slot) */
2287 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2288 int rs, int rt, int32_t offset)
2290 target_ulong btgt = -1;
2292 int bcond_compute = 0;
2293 TCGv t0 = tcg_temp_local_new();
2294 TCGv t1 = tcg_temp_local_new();
2296 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2297 #ifdef MIPS_DEBUG_DISAS
2298 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx "\n", ctx->pc);
2300 generate_exception(ctx, EXCP_RI);
2304 /* Load needed operands */
2310 /* Compare two registers */
2312 gen_load_gpr(t0, rs);
2313 gen_load_gpr(t1, rt);
2316 btgt = ctx->pc + 4 + offset;
2330 /* Compare to zero */
2332 gen_load_gpr(t0, rs);
2335 btgt = ctx->pc + 4 + offset;
2339 /* Jump to immediate */
2340 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2344 /* Jump to register */
2345 if (offset != 0 && offset != 16) {
2346 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2347 others are reserved. */
2348 MIPS_INVAL("jump hint");
2349 generate_exception(ctx, EXCP_RI);
2352 gen_load_gpr(btarget, rs);
2355 MIPS_INVAL("branch/jump");
2356 generate_exception(ctx, EXCP_RI);
2359 if (bcond_compute == 0) {
2360 /* No condition to be computed */
2362 case OPC_BEQ: /* rx == rx */
2363 case OPC_BEQL: /* rx == rx likely */
2364 case OPC_BGEZ: /* 0 >= 0 */
2365 case OPC_BGEZL: /* 0 >= 0 likely */
2366 case OPC_BLEZ: /* 0 <= 0 */
2367 case OPC_BLEZL: /* 0 <= 0 likely */
2369 ctx->hflags |= MIPS_HFLAG_B;
2370 MIPS_DEBUG("balways");
2372 case OPC_BGEZAL: /* 0 >= 0 */
2373 case OPC_BGEZALL: /* 0 >= 0 likely */
2374 /* Always take and link */
2376 ctx->hflags |= MIPS_HFLAG_B;
2377 MIPS_DEBUG("balways and link");
2379 case OPC_BNE: /* rx != rx */
2380 case OPC_BGTZ: /* 0 > 0 */
2381 case OPC_BLTZ: /* 0 < 0 */
2383 MIPS_DEBUG("bnever (NOP)");
2385 case OPC_BLTZAL: /* 0 < 0 */
2386 tcg_gen_movi_tl(t0, ctx->pc + 8);
2387 gen_store_gpr(t0, 31);
2388 MIPS_DEBUG("bnever and link");
2390 case OPC_BLTZALL: /* 0 < 0 likely */
2391 tcg_gen_movi_tl(t0, ctx->pc + 8);
2392 gen_store_gpr(t0, 31);
2393 /* Skip the instruction in the delay slot */
2394 MIPS_DEBUG("bnever, link and skip");
2397 case OPC_BNEL: /* rx != rx likely */
2398 case OPC_BGTZL: /* 0 > 0 likely */
2399 case OPC_BLTZL: /* 0 < 0 likely */
2400 /* Skip the instruction in the delay slot */
2401 MIPS_DEBUG("bnever and skip");
2405 ctx->hflags |= MIPS_HFLAG_B;
2406 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2410 ctx->hflags |= MIPS_HFLAG_B;
2411 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2414 ctx->hflags |= MIPS_HFLAG_BR;
2415 MIPS_DEBUG("jr %s", regnames[rs]);
2419 ctx->hflags |= MIPS_HFLAG_BR;
2420 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2423 MIPS_INVAL("branch/jump");
2424 generate_exception(ctx, EXCP_RI);
2430 gen_op_eq(t0, t0, t1);
2431 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2432 regnames[rs], regnames[rt], btgt);
2435 gen_op_eq(t0, t0, t1);
2436 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2437 regnames[rs], regnames[rt], btgt);
2440 gen_op_ne(t0, t0, t1);
2441 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2442 regnames[rs], regnames[rt], btgt);
2445 gen_op_ne(t0, t0, t1);
2446 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2447 regnames[rs], regnames[rt], btgt);
2451 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2455 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2459 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2465 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2469 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2473 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2477 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2481 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2485 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2489 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2494 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2496 ctx->hflags |= MIPS_HFLAG_BC;
2497 tcg_gen_trunc_tl_i32(bcond, t0);
2502 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2504 ctx->hflags |= MIPS_HFLAG_BL;
2505 tcg_gen_trunc_tl_i32(bcond, t0);
2508 MIPS_INVAL("conditional branch/jump");
2509 generate_exception(ctx, EXCP_RI);
2513 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2514 blink, ctx->hflags, btgt);
2516 ctx->btarget = btgt;
2518 tcg_gen_movi_tl(t0, ctx->pc + 8);
2519 gen_store_gpr(t0, blink);
2527 /* special3 bitfield operations */
2528 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2529 int rs, int lsb, int msb)
2531 TCGv t0 = tcg_temp_new();
2532 TCGv t1 = tcg_temp_new();
2535 gen_load_gpr(t1, rs);
2540 tcg_gen_shri_tl(t0, t1, lsb);
2542 tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
2544 tcg_gen_ext32s_tl(t0, t0);
2547 #if defined(TARGET_MIPS64)
2549 tcg_gen_shri_tl(t0, t1, lsb);
2551 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
2555 tcg_gen_shri_tl(t0, t1, lsb + 32);
2556 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2559 tcg_gen_shri_tl(t0, t1, lsb);
2560 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2566 mask = ((msb - lsb + 1 < 32) ? ((1 << (msb - lsb + 1)) - 1) : ~0) << lsb;
2567 gen_load_gpr(t0, rt);
2568 tcg_gen_andi_tl(t0, t0, ~mask);
2569 tcg_gen_shli_tl(t1, t1, lsb);
2570 tcg_gen_andi_tl(t1, t1, mask);
2571 tcg_gen_or_tl(t0, t0, t1);
2572 tcg_gen_ext32s_tl(t0, t0);
2574 #if defined(TARGET_MIPS64)
2578 mask = ((msb - lsb + 1 + 32 < 64) ? ((1ULL << (msb - lsb + 1 + 32)) - 1) : ~0ULL) << lsb;
2579 gen_load_gpr(t0, rt);
2580 tcg_gen_andi_tl(t0, t0, ~mask);
2581 tcg_gen_shli_tl(t1, t1, lsb);
2582 tcg_gen_andi_tl(t1, t1, mask);
2583 tcg_gen_or_tl(t0, t0, t1);
2588 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2589 gen_load_gpr(t0, rt);
2590 tcg_gen_andi_tl(t0, t0, ~mask);
2591 tcg_gen_shli_tl(t1, t1, lsb + 32);
2592 tcg_gen_andi_tl(t1, t1, mask);
2593 tcg_gen_or_tl(t0, t0, t1);
2598 gen_load_gpr(t0, rt);
2599 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2600 gen_load_gpr(t0, rt);
2601 tcg_gen_andi_tl(t0, t0, ~mask);
2602 tcg_gen_shli_tl(t1, t1, lsb);
2603 tcg_gen_andi_tl(t1, t1, mask);
2604 tcg_gen_or_tl(t0, t0, t1);
2609 MIPS_INVAL("bitops");
2610 generate_exception(ctx, EXCP_RI);
2615 gen_store_gpr(t0, rt);
2620 static void gen_bshfl (DisasContext *ctx, uint32_t op2, int rt, int rd)
2625 /* If no destination, treat it as a NOP. */
2630 t0 = tcg_temp_new();
2631 gen_load_gpr(t0, rt);
2635 TCGv t1 = tcg_temp_new();
2637 tcg_gen_shri_tl(t1, t0, 8);
2638 tcg_gen_andi_tl(t1, t1, 0x00FF00FF);
2639 tcg_gen_shli_tl(t0, t0, 8);
2640 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF);
2641 tcg_gen_or_tl(t0, t0, t1);
2643 tcg_gen_ext32s_tl(cpu_gpr[rd], t0);
2647 tcg_gen_ext8s_tl(cpu_gpr[rd], t0);
2650 tcg_gen_ext16s_tl(cpu_gpr[rd], t0);
2652 #if defined(TARGET_MIPS64)
2655 TCGv t1 = tcg_temp_new();
2657 tcg_gen_shri_tl(t1, t0, 8);
2658 tcg_gen_andi_tl(t1, t1, 0x00FF00FF00FF00FFULL);
2659 tcg_gen_shli_tl(t0, t0, 8);
2660 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF00FF00FFULL);
2661 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2667 TCGv t1 = tcg_temp_new();
2669 tcg_gen_shri_tl(t1, t0, 16);
2670 tcg_gen_andi_tl(t1, t1, 0x0000FFFF0000FFFFULL);
2671 tcg_gen_shli_tl(t0, t0, 16);
2672 tcg_gen_andi_tl(t0, t0, ~0x0000FFFF0000FFFFULL);
2673 tcg_gen_or_tl(t0, t0, t1);
2674 tcg_gen_shri_tl(t1, t0, 32);
2675 tcg_gen_shli_tl(t0, t0, 32);
2676 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2682 MIPS_INVAL("bsfhl");
2683 generate_exception(ctx, EXCP_RI);
2690 #ifndef CONFIG_USER_ONLY
2691 /* CP0 (MMU and control) */
2692 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2694 TCGv_i32 r_tmp = tcg_temp_new_i32();
2696 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2697 tcg_gen_ext_i32_tl(t, r_tmp);
2698 tcg_temp_free_i32(r_tmp);
2701 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2703 tcg_gen_ld_tl(t, cpu_env, off);
2704 tcg_gen_ext32s_tl(t, t);
2707 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2709 TCGv_i32 r_tmp = tcg_temp_new_i32();
2711 tcg_gen_trunc_tl_i32(r_tmp, t);
2712 tcg_gen_st_i32(r_tmp, cpu_env, off);
2713 tcg_temp_free_i32(r_tmp);
2716 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2718 tcg_gen_ext32s_tl(t, t);
2719 tcg_gen_st_tl(t, cpu_env, off);
2722 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2724 const char *rn = "invalid";
2727 check_insn(env, ctx, ISA_MIPS32);
2733 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2737 check_insn(env, ctx, ASE_MT);
2738 gen_helper_mfc0_mvpcontrol(t0);
2742 check_insn(env, ctx, ASE_MT);
2743 gen_helper_mfc0_mvpconf0(t0);
2747 check_insn(env, ctx, ASE_MT);
2748 gen_helper_mfc0_mvpconf1(t0);
2758 gen_helper_mfc0_random(t0);
2762 check_insn(env, ctx, ASE_MT);
2763 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2767 check_insn(env, ctx, ASE_MT);
2768 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2772 check_insn(env, ctx, ASE_MT);
2773 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2777 check_insn(env, ctx, ASE_MT);
2778 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2782 check_insn(env, ctx, ASE_MT);
2783 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2787 check_insn(env, ctx, ASE_MT);
2788 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2789 rn = "VPEScheFBack";
2792 check_insn(env, ctx, ASE_MT);
2793 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2803 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2804 tcg_gen_ext32s_tl(t0, t0);
2808 check_insn(env, ctx, ASE_MT);
2809 gen_helper_mfc0_tcstatus(t0);
2813 check_insn(env, ctx, ASE_MT);
2814 gen_helper_mfc0_tcbind(t0);
2818 check_insn(env, ctx, ASE_MT);
2819 gen_helper_mfc0_tcrestart(t0);
2823 check_insn(env, ctx, ASE_MT);
2824 gen_helper_mfc0_tchalt(t0);
2828 check_insn(env, ctx, ASE_MT);
2829 gen_helper_mfc0_tccontext(t0);
2833 check_insn(env, ctx, ASE_MT);
2834 gen_helper_mfc0_tcschedule(t0);
2838 check_insn(env, ctx, ASE_MT);
2839 gen_helper_mfc0_tcschefback(t0);
2849 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2850 tcg_gen_ext32s_tl(t0, t0);
2860 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2861 tcg_gen_ext32s_tl(t0, t0);
2865 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2866 rn = "ContextConfig";
2875 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2879 check_insn(env, ctx, ISA_MIPS32R2);
2880 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2890 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2894 check_insn(env, ctx, ISA_MIPS32R2);
2895 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2899 check_insn(env, ctx, ISA_MIPS32R2);
2900 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2904 check_insn(env, ctx, ISA_MIPS32R2);
2905 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2909 check_insn(env, ctx, ISA_MIPS32R2);
2910 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2914 check_insn(env, ctx, ISA_MIPS32R2);
2915 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2925 check_insn(env, ctx, ISA_MIPS32R2);
2926 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
2936 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
2937 tcg_gen_ext32s_tl(t0, t0);
2947 /* Mark as an IO operation because we read the time. */
2950 gen_helper_mfc0_count(t0);
2953 ctx->bstate = BS_STOP;
2957 /* 6,7 are implementation dependent */
2965 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
2966 tcg_gen_ext32s_tl(t0, t0);
2976 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
2979 /* 6,7 are implementation dependent */
2987 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
2991 check_insn(env, ctx, ISA_MIPS32R2);
2992 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
2996 check_insn(env, ctx, ISA_MIPS32R2);
2997 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3001 check_insn(env, ctx, ISA_MIPS32R2);
3002 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3012 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3022 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3023 tcg_gen_ext32s_tl(t0, t0);
3033 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3037 check_insn(env, ctx, ISA_MIPS32R2);
3038 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3048 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3052 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3056 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3060 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3063 /* 4,5 are reserved */
3064 /* 6,7 are implementation dependent */
3066 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3070 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3080 gen_helper_mfc0_lladdr(t0);
3090 gen_helper_1i(mfc0_watchlo, t0, sel);
3100 gen_helper_1i(mfc0_watchhi, t0, sel);
3110 #if defined(TARGET_MIPS64)
3111 check_insn(env, ctx, ISA_MIPS3);
3112 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3113 tcg_gen_ext32s_tl(t0, t0);
3122 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3125 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3133 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3134 rn = "'Diagnostic"; /* implementation dependent */
3139 gen_helper_mfc0_debug(t0); /* EJTAG support */
3143 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3144 rn = "TraceControl";
3147 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3148 rn = "TraceControl2";
3151 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3152 rn = "UserTraceData";
3155 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3166 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3167 tcg_gen_ext32s_tl(t0, t0);
3177 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3178 rn = "Performance0";
3181 // gen_helper_mfc0_performance1(t0);
3182 rn = "Performance1";
3185 // gen_helper_mfc0_performance2(t0);
3186 rn = "Performance2";
3189 // gen_helper_mfc0_performance3(t0);
3190 rn = "Performance3";
3193 // gen_helper_mfc0_performance4(t0);
3194 rn = "Performance4";
3197 // gen_helper_mfc0_performance5(t0);
3198 rn = "Performance5";
3201 // gen_helper_mfc0_performance6(t0);
3202 rn = "Performance6";
3205 // gen_helper_mfc0_performance7(t0);
3206 rn = "Performance7";
3213 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3219 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3232 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3239 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3252 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3259 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3269 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3270 tcg_gen_ext32s_tl(t0, t0);
3281 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3291 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3295 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3296 generate_exception(ctx, EXCP_RI);
3299 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3301 const char *rn = "invalid";
3304 check_insn(env, ctx, ISA_MIPS32);
3313 gen_helper_mtc0_index(t0);
3317 check_insn(env, ctx, ASE_MT);
3318 gen_helper_mtc0_mvpcontrol(t0);
3322 check_insn(env, ctx, ASE_MT);
3327 check_insn(env, ctx, ASE_MT);
3342 check_insn(env, ctx, ASE_MT);
3343 gen_helper_mtc0_vpecontrol(t0);
3347 check_insn(env, ctx, ASE_MT);
3348 gen_helper_mtc0_vpeconf0(t0);
3352 check_insn(env, ctx, ASE_MT);
3353 gen_helper_mtc0_vpeconf1(t0);
3357 check_insn(env, ctx, ASE_MT);
3358 gen_helper_mtc0_yqmask(t0);
3362 check_insn(env, ctx, ASE_MT);
3363 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3367 check_insn(env, ctx, ASE_MT);
3368 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3369 rn = "VPEScheFBack";
3372 check_insn(env, ctx, ASE_MT);
3373 gen_helper_mtc0_vpeopt(t0);
3383 gen_helper_mtc0_entrylo0(t0);
3387 check_insn(env, ctx, ASE_MT);
3388 gen_helper_mtc0_tcstatus(t0);
3392 check_insn(env, ctx, ASE_MT);
3393 gen_helper_mtc0_tcbind(t0);
3397 check_insn(env, ctx, ASE_MT);
3398 gen_helper_mtc0_tcrestart(t0);
3402 check_insn(env, ctx, ASE_MT);
3403 gen_helper_mtc0_tchalt(t0);
3407 check_insn(env, ctx, ASE_MT);
3408 gen_helper_mtc0_tccontext(t0);
3412 check_insn(env, ctx, ASE_MT);
3413 gen_helper_mtc0_tcschedule(t0);
3417 check_insn(env, ctx, ASE_MT);
3418 gen_helper_mtc0_tcschefback(t0);
3428 gen_helper_mtc0_entrylo1(t0);
3438 gen_helper_mtc0_context(t0);
3442 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3443 rn = "ContextConfig";
3452 gen_helper_mtc0_pagemask(t0);
3456 check_insn(env, ctx, ISA_MIPS32R2);
3457 gen_helper_mtc0_pagegrain(t0);
3467 gen_helper_mtc0_wired(t0);
3471 check_insn(env, ctx, ISA_MIPS32R2);
3472 gen_helper_mtc0_srsconf0(t0);
3476 check_insn(env, ctx, ISA_MIPS32R2);
3477 gen_helper_mtc0_srsconf1(t0);
3481 check_insn(env, ctx, ISA_MIPS32R2);
3482 gen_helper_mtc0_srsconf2(t0);
3486 check_insn(env, ctx, ISA_MIPS32R2);
3487 gen_helper_mtc0_srsconf3(t0);
3491 check_insn(env, ctx, ISA_MIPS32R2);
3492 gen_helper_mtc0_srsconf4(t0);
3502 check_insn(env, ctx, ISA_MIPS32R2);
3503 gen_helper_mtc0_hwrena(t0);
3517 gen_helper_mtc0_count(t0);
3520 /* 6,7 are implementation dependent */
3524 /* Stop translation as we may have switched the execution mode */
3525 ctx->bstate = BS_STOP;
3530 gen_helper_mtc0_entryhi(t0);
3540 gen_helper_mtc0_compare(t0);
3543 /* 6,7 are implementation dependent */
3547 /* Stop translation as we may have switched the execution mode */
3548 ctx->bstate = BS_STOP;
3553 gen_helper_mtc0_status(t0);
3554 /* BS_STOP isn't good enough here, hflags may have changed. */
3555 gen_save_pc(ctx->pc + 4);
3556 ctx->bstate = BS_EXCP;
3560 check_insn(env, ctx, ISA_MIPS32R2);
3561 gen_helper_mtc0_intctl(t0);
3562 /* Stop translation as we may have switched the execution mode */
3563 ctx->bstate = BS_STOP;
3567 check_insn(env, ctx, ISA_MIPS32R2);
3568 gen_helper_mtc0_srsctl(t0);
3569 /* Stop translation as we may have switched the execution mode */
3570 ctx->bstate = BS_STOP;
3574 check_insn(env, ctx, ISA_MIPS32R2);
3575 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3576 /* Stop translation as we may have switched the execution mode */
3577 ctx->bstate = BS_STOP;
3587 gen_helper_mtc0_cause(t0);
3593 /* Stop translation as we may have switched the execution mode */
3594 ctx->bstate = BS_STOP;
3599 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3613 check_insn(env, ctx, ISA_MIPS32R2);
3614 gen_helper_mtc0_ebase(t0);
3624 gen_helper_mtc0_config0(t0);
3626 /* Stop translation as we may have switched the execution mode */
3627 ctx->bstate = BS_STOP;
3630 /* ignored, read only */
3634 gen_helper_mtc0_config2(t0);
3636 /* Stop translation as we may have switched the execution mode */
3637 ctx->bstate = BS_STOP;
3640 /* ignored, read only */
3643 /* 4,5 are reserved */
3644 /* 6,7 are implementation dependent */
3654 rn = "Invalid config selector";
3671 gen_helper_1i(mtc0_watchlo, t0, sel);
3681 gen_helper_1i(mtc0_watchhi, t0, sel);
3691 #if defined(TARGET_MIPS64)
3692 check_insn(env, ctx, ISA_MIPS3);
3693 gen_helper_mtc0_xcontext(t0);
3702 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3705 gen_helper_mtc0_framemask(t0);
3714 rn = "Diagnostic"; /* implementation dependent */
3719 gen_helper_mtc0_debug(t0); /* EJTAG support */
3720 /* BS_STOP isn't good enough here, hflags may have changed. */
3721 gen_save_pc(ctx->pc + 4);
3722 ctx->bstate = BS_EXCP;
3726 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3727 rn = "TraceControl";
3728 /* Stop translation as we may have switched the execution mode */
3729 ctx->bstate = BS_STOP;
3732 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3733 rn = "TraceControl2";
3734 /* Stop translation as we may have switched the execution mode */
3735 ctx->bstate = BS_STOP;
3738 /* Stop translation as we may have switched the execution mode */
3739 ctx->bstate = BS_STOP;
3740 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3741 rn = "UserTraceData";
3742 /* Stop translation as we may have switched the execution mode */
3743 ctx->bstate = BS_STOP;
3746 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3747 /* Stop translation as we may have switched the execution mode */
3748 ctx->bstate = BS_STOP;
3759 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3769 gen_helper_mtc0_performance0(t0);
3770 rn = "Performance0";
3773 // gen_helper_mtc0_performance1(t0);
3774 rn = "Performance1";
3777 // gen_helper_mtc0_performance2(t0);
3778 rn = "Performance2";
3781 // gen_helper_mtc0_performance3(t0);
3782 rn = "Performance3";
3785 // gen_helper_mtc0_performance4(t0);
3786 rn = "Performance4";
3789 // gen_helper_mtc0_performance5(t0);
3790 rn = "Performance5";
3793 // gen_helper_mtc0_performance6(t0);
3794 rn = "Performance6";
3797 // gen_helper_mtc0_performance7(t0);
3798 rn = "Performance7";
3824 gen_helper_mtc0_taglo(t0);
3831 gen_helper_mtc0_datalo(t0);
3844 gen_helper_mtc0_taghi(t0);
3851 gen_helper_mtc0_datahi(t0);
3862 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3873 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3879 /* Stop translation as we may have switched the execution mode */
3880 ctx->bstate = BS_STOP;
3885 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3886 /* For simplicity assume that all writes can cause interrupts. */
3889 ctx->bstate = BS_STOP;
3894 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3895 generate_exception(ctx, EXCP_RI);
3898 #if defined(TARGET_MIPS64)
3899 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3901 const char *rn = "invalid";
3904 check_insn(env, ctx, ISA_MIPS64);
3910 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
3914 check_insn(env, ctx, ASE_MT);
3915 gen_helper_mfc0_mvpcontrol(t0);
3919 check_insn(env, ctx, ASE_MT);
3920 gen_helper_mfc0_mvpconf0(t0);
3924 check_insn(env, ctx, ASE_MT);
3925 gen_helper_mfc0_mvpconf1(t0);
3935 gen_helper_mfc0_random(t0);
3939 check_insn(env, ctx, ASE_MT);
3940 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
3944 check_insn(env, ctx, ASE_MT);
3945 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
3949 check_insn(env, ctx, ASE_MT);
3950 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
3954 check_insn(env, ctx, ASE_MT);
3955 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
3959 check_insn(env, ctx, ASE_MT);
3960 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
3964 check_insn(env, ctx, ASE_MT);
3965 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3966 rn = "VPEScheFBack";
3969 check_insn(env, ctx, ASE_MT);
3970 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
3980 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
3984 check_insn(env, ctx, ASE_MT);
3985 gen_helper_mfc0_tcstatus(t0);
3989 check_insn(env, ctx, ASE_MT);
3990 gen_helper_mfc0_tcbind(t0);
3994 check_insn(env, ctx, ASE_MT);
3995 gen_helper_dmfc0_tcrestart(t0);
3999 check_insn(env, ctx, ASE_MT);
4000 gen_helper_dmfc0_tchalt(t0);
4004 check_insn(env, ctx, ASE_MT);
4005 gen_helper_dmfc0_tccontext(t0);
4009 check_insn(env, ctx, ASE_MT);
4010 gen_helper_dmfc0_tcschedule(t0);
4014 check_insn(env, ctx, ASE_MT);
4015 gen_helper_dmfc0_tcschefback(t0);
4025 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4035 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4039 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4040 rn = "ContextConfig";
4049 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4053 check_insn(env, ctx, ISA_MIPS32R2);
4054 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4064 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4068 check_insn(env, ctx, ISA_MIPS32R2);
4069 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4073 check_insn(env, ctx, ISA_MIPS32R2);
4074 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4078 check_insn(env, ctx, ISA_MIPS32R2);
4079 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4083 check_insn(env, ctx, ISA_MIPS32R2);
4084 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4088 check_insn(env, ctx, ISA_MIPS32R2);
4089 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4099 check_insn(env, ctx, ISA_MIPS32R2);
4100 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4110 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4120 /* Mark as an IO operation because we read the time. */
4123 gen_helper_mfc0_count(t0);
4126 ctx->bstate = BS_STOP;
4130 /* 6,7 are implementation dependent */
4138 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4148 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4151 /* 6,7 are implementation dependent */
4159 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4163 check_insn(env, ctx, ISA_MIPS32R2);
4164 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4168 check_insn(env, ctx, ISA_MIPS32R2);
4169 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4173 check_insn(env, ctx, ISA_MIPS32R2);
4174 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4184 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4194 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4204 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4208 check_insn(env, ctx, ISA_MIPS32R2);
4209 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4219 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4223 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4227 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4231 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4234 /* 6,7 are implementation dependent */
4236 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4240 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4250 gen_helper_dmfc0_lladdr(t0);
4260 gen_helper_1i(dmfc0_watchlo, t0, sel);
4270 gen_helper_1i(mfc0_watchhi, t0, sel);
4280 check_insn(env, ctx, ISA_MIPS3);
4281 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4289 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4292 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4300 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4301 rn = "'Diagnostic"; /* implementation dependent */
4306 gen_helper_mfc0_debug(t0); /* EJTAG support */
4310 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4311 rn = "TraceControl";
4314 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4315 rn = "TraceControl2";
4318 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4319 rn = "UserTraceData";
4322 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4333 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4343 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4344 rn = "Performance0";
4347 // gen_helper_dmfc0_performance1(t0);
4348 rn = "Performance1";
4351 // gen_helper_dmfc0_performance2(t0);
4352 rn = "Performance2";
4355 // gen_helper_dmfc0_performance3(t0);
4356 rn = "Performance3";
4359 // gen_helper_dmfc0_performance4(t0);
4360 rn = "Performance4";
4363 // gen_helper_dmfc0_performance5(t0);
4364 rn = "Performance5";
4367 // gen_helper_dmfc0_performance6(t0);
4368 rn = "Performance6";
4371 // gen_helper_dmfc0_performance7(t0);
4372 rn = "Performance7";
4379 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4386 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4399 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4406 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4419 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4426 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4436 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4447 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4457 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4461 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4462 generate_exception(ctx, EXCP_RI);
4465 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4467 const char *rn = "invalid";
4470 check_insn(env, ctx, ISA_MIPS64);
4479 gen_helper_mtc0_index(t0);
4483 check_insn(env, ctx, ASE_MT);
4484 gen_helper_mtc0_mvpcontrol(t0);
4488 check_insn(env, ctx, ASE_MT);
4493 check_insn(env, ctx, ASE_MT);
4508 check_insn(env, ctx, ASE_MT);
4509 gen_helper_mtc0_vpecontrol(t0);
4513 check_insn(env, ctx, ASE_MT);
4514 gen_helper_mtc0_vpeconf0(t0);
4518 check_insn(env, ctx, ASE_MT);
4519 gen_helper_mtc0_vpeconf1(t0);
4523 check_insn(env, ctx, ASE_MT);
4524 gen_helper_mtc0_yqmask(t0);
4528 check_insn(env, ctx, ASE_MT);
4529 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4533 check_insn(env, ctx, ASE_MT);
4534 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4535 rn = "VPEScheFBack";
4538 check_insn(env, ctx, ASE_MT);
4539 gen_helper_mtc0_vpeopt(t0);
4549 gen_helper_mtc0_entrylo0(t0);
4553 check_insn(env, ctx, ASE_MT);
4554 gen_helper_mtc0_tcstatus(t0);
4558 check_insn(env, ctx, ASE_MT);
4559 gen_helper_mtc0_tcbind(t0);
4563 check_insn(env, ctx, ASE_MT);
4564 gen_helper_mtc0_tcrestart(t0);
4568 check_insn(env, ctx, ASE_MT);
4569 gen_helper_mtc0_tchalt(t0);
4573 check_insn(env, ctx, ASE_MT);
4574 gen_helper_mtc0_tccontext(t0);
4578 check_insn(env, ctx, ASE_MT);
4579 gen_helper_mtc0_tcschedule(t0);
4583 check_insn(env, ctx, ASE_MT);
4584 gen_helper_mtc0_tcschefback(t0);
4594 gen_helper_mtc0_entrylo1(t0);
4604 gen_helper_mtc0_context(t0);
4608 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4609 rn = "ContextConfig";
4618 gen_helper_mtc0_pagemask(t0);
4622 check_insn(env, ctx, ISA_MIPS32R2);
4623 gen_helper_mtc0_pagegrain(t0);
4633 gen_helper_mtc0_wired(t0);
4637 check_insn(env, ctx, ISA_MIPS32R2);
4638 gen_helper_mtc0_srsconf0(t0);
4642 check_insn(env, ctx, ISA_MIPS32R2);
4643 gen_helper_mtc0_srsconf1(t0);
4647 check_insn(env, ctx, ISA_MIPS32R2);
4648 gen_helper_mtc0_srsconf2(t0);
4652 check_insn(env, ctx, ISA_MIPS32R2);
4653 gen_helper_mtc0_srsconf3(t0);
4657 check_insn(env, ctx, ISA_MIPS32R2);
4658 gen_helper_mtc0_srsconf4(t0);
4668 check_insn(env, ctx, ISA_MIPS32R2);
4669 gen_helper_mtc0_hwrena(t0);
4683 gen_helper_mtc0_count(t0);
4686 /* 6,7 are implementation dependent */
4690 /* Stop translation as we may have switched the execution mode */
4691 ctx->bstate = BS_STOP;
4696 gen_helper_mtc0_entryhi(t0);
4706 gen_helper_mtc0_compare(t0);
4709 /* 6,7 are implementation dependent */
4713 /* Stop translation as we may have switched the execution mode */
4714 ctx->bstate = BS_STOP;
4719 gen_helper_mtc0_status(t0);
4720 /* BS_STOP isn't good enough here, hflags may have changed. */
4721 gen_save_pc(ctx->pc + 4);
4722 ctx->bstate = BS_EXCP;
4726 check_insn(env, ctx, ISA_MIPS32R2);
4727 gen_helper_mtc0_intctl(t0);
4728 /* Stop translation as we may have switched the execution mode */
4729 ctx->bstate = BS_STOP;
4733 check_insn(env, ctx, ISA_MIPS32R2);
4734 gen_helper_mtc0_srsctl(t0);
4735 /* Stop translation as we may have switched the execution mode */
4736 ctx->bstate = BS_STOP;
4740 check_insn(env, ctx, ISA_MIPS32R2);
4741 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4742 /* Stop translation as we may have switched the execution mode */
4743 ctx->bstate = BS_STOP;
4753 gen_helper_mtc0_cause(t0);
4759 /* Stop translation as we may have switched the execution mode */
4760 ctx->bstate = BS_STOP;
4765 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4779 check_insn(env, ctx, ISA_MIPS32R2);
4780 gen_helper_mtc0_ebase(t0);
4790 gen_helper_mtc0_config0(t0);
4792 /* Stop translation as we may have switched the execution mode */
4793 ctx->bstate = BS_STOP;
4800 gen_helper_mtc0_config2(t0);
4802 /* Stop translation as we may have switched the execution mode */
4803 ctx->bstate = BS_STOP;
4809 /* 6,7 are implementation dependent */
4811 rn = "Invalid config selector";
4828 gen_helper_1i(mtc0_watchlo, t0, sel);
4838 gen_helper_1i(mtc0_watchhi, t0, sel);
4848 check_insn(env, ctx, ISA_MIPS3);
4849 gen_helper_mtc0_xcontext(t0);
4857 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4860 gen_helper_mtc0_framemask(t0);
4869 rn = "Diagnostic"; /* implementation dependent */
4874 gen_helper_mtc0_debug(t0); /* EJTAG support */
4875 /* BS_STOP isn't good enough here, hflags may have changed. */
4876 gen_save_pc(ctx->pc + 4);
4877 ctx->bstate = BS_EXCP;
4881 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4882 /* Stop translation as we may have switched the execution mode */
4883 ctx->bstate = BS_STOP;
4884 rn = "TraceControl";
4887 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4888 /* Stop translation as we may have switched the execution mode */
4889 ctx->bstate = BS_STOP;
4890 rn = "TraceControl2";
4893 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4894 /* Stop translation as we may have switched the execution mode */
4895 ctx->bstate = BS_STOP;
4896 rn = "UserTraceData";
4899 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4900 /* Stop translation as we may have switched the execution mode */
4901 ctx->bstate = BS_STOP;
4912 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4922 gen_helper_mtc0_performance0(t0);
4923 rn = "Performance0";
4926 // gen_helper_mtc0_performance1(t0);
4927 rn = "Performance1";
4930 // gen_helper_mtc0_performance2(t0);
4931 rn = "Performance2";
4934 // gen_helper_mtc0_performance3(t0);
4935 rn = "Performance3";
4938 // gen_helper_mtc0_performance4(t0);
4939 rn = "Performance4";
4942 // gen_helper_mtc0_performance5(t0);
4943 rn = "Performance5";
4946 // gen_helper_mtc0_performance6(t0);
4947 rn = "Performance6";
4950 // gen_helper_mtc0_performance7(t0);
4951 rn = "Performance7";
4977 gen_helper_mtc0_taglo(t0);
4984 gen_helper_mtc0_datalo(t0);
4997 gen_helper_mtc0_taghi(t0);
5004 gen_helper_mtc0_datahi(t0);
5015 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5026 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5032 /* Stop translation as we may have switched the execution mode */
5033 ctx->bstate = BS_STOP;
5038 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5039 /* For simplicity assume that all writes can cause interrupts. */
5042 ctx->bstate = BS_STOP;
5047 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5048 generate_exception(ctx, EXCP_RI);
5050 #endif /* TARGET_MIPS64 */
5052 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5053 int u, int sel, int h)
5055 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5056 TCGv t0 = tcg_temp_local_new();
5058 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5059 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5060 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5061 tcg_gen_movi_tl(t0, -1);
5062 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5063 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5064 tcg_gen_movi_tl(t0, -1);
5070 gen_helper_mftc0_tcstatus(t0);
5073 gen_helper_mftc0_tcbind(t0);
5076 gen_helper_mftc0_tcrestart(t0);
5079 gen_helper_mftc0_tchalt(t0);
5082 gen_helper_mftc0_tccontext(t0);
5085 gen_helper_mftc0_tcschedule(t0);
5088 gen_helper_mftc0_tcschefback(t0);
5091 gen_mfc0(env, ctx, t0, rt, sel);
5098 gen_helper_mftc0_entryhi(t0);
5101 gen_mfc0(env, ctx, t0, rt, sel);
5107 gen_helper_mftc0_status(t0);
5110 gen_mfc0(env, ctx, t0, rt, sel);
5116 gen_helper_mftc0_debug(t0);
5119 gen_mfc0(env, ctx, t0, rt, sel);
5124 gen_mfc0(env, ctx, t0, rt, sel);
5126 } else switch (sel) {
5127 /* GPR registers. */
5129 gen_helper_1i(mftgpr, t0, rt);
5131 /* Auxiliary CPU registers */
5135 gen_helper_1i(mftlo, t0, 0);
5138 gen_helper_1i(mfthi, t0, 0);
5141 gen_helper_1i(mftacx, t0, 0);
5144 gen_helper_1i(mftlo, t0, 1);
5147 gen_helper_1i(mfthi, t0, 1);
5150 gen_helper_1i(mftacx, t0, 1);
5153 gen_helper_1i(mftlo, t0, 2);
5156 gen_helper_1i(mfthi, t0, 2);
5159 gen_helper_1i(mftacx, t0, 2);
5162 gen_helper_1i(mftlo, t0, 3);
5165 gen_helper_1i(mfthi, t0, 3);
5168 gen_helper_1i(mftacx, t0, 3);
5171 gen_helper_mftdsp(t0);
5177 /* Floating point (COP1). */
5179 /* XXX: For now we support only a single FPU context. */
5181 TCGv_i32 fp0 = tcg_temp_new_i32();
5183 gen_load_fpr32(fp0, rt);
5184 tcg_gen_ext_i32_tl(t0, fp0);
5185 tcg_temp_free_i32(fp0);
5187 TCGv_i32 fp0 = tcg_temp_new_i32();
5189 gen_load_fpr32h(fp0, rt);
5190 tcg_gen_ext_i32_tl(t0, fp0);
5191 tcg_temp_free_i32(fp0);
5195 /* XXX: For now we support only a single FPU context. */
5196 gen_helper_1i(cfc1, t0, rt);
5198 /* COP2: Not implemented. */
5205 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5206 gen_store_gpr(t0, rd);
5212 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5213 generate_exception(ctx, EXCP_RI);
5216 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5217 int u, int sel, int h)
5219 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5220 TCGv t0 = tcg_temp_local_new();
5222 gen_load_gpr(t0, rt);
5223 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5224 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5225 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5227 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5228 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5235 gen_helper_mttc0_tcstatus(t0);
5238 gen_helper_mttc0_tcbind(t0);
5241 gen_helper_mttc0_tcrestart(t0);
5244 gen_helper_mttc0_tchalt(t0);
5247 gen_helper_mttc0_tccontext(t0);
5250 gen_helper_mttc0_tcschedule(t0);
5253 gen_helper_mttc0_tcschefback(t0);
5256 gen_mtc0(env, ctx, t0, rd, sel);
5263 gen_helper_mttc0_entryhi(t0);
5266 gen_mtc0(env, ctx, t0, rd, sel);
5272 gen_helper_mttc0_status(t0);
5275 gen_mtc0(env, ctx, t0, rd, sel);
5281 gen_helper_mttc0_debug(t0);
5284 gen_mtc0(env, ctx, t0, rd, sel);
5289 gen_mtc0(env, ctx, t0, rd, sel);
5291 } else switch (sel) {
5292 /* GPR registers. */
5294 gen_helper_1i(mttgpr, t0, rd);
5296 /* Auxiliary CPU registers */
5300 gen_helper_1i(mttlo, t0, 0);
5303 gen_helper_1i(mtthi, t0, 0);
5306 gen_helper_1i(mttacx, t0, 0);
5309 gen_helper_1i(mttlo, t0, 1);
5312 gen_helper_1i(mtthi, t0, 1);
5315 gen_helper_1i(mttacx, t0, 1);
5318 gen_helper_1i(mttlo, t0, 2);
5321 gen_helper_1i(mtthi, t0, 2);
5324 gen_helper_1i(mttacx, t0, 2);
5327 gen_helper_1i(mttlo, t0, 3);
5330 gen_helper_1i(mtthi, t0, 3);
5333 gen_helper_1i(mttacx, t0, 3);
5336 gen_helper_mttdsp(t0);
5342 /* Floating point (COP1). */
5344 /* XXX: For now we support only a single FPU context. */
5346 TCGv_i32 fp0 = tcg_temp_new_i32();
5348 tcg_gen_trunc_tl_i32(fp0, t0);
5349 gen_store_fpr32(fp0, rd);
5350 tcg_temp_free_i32(fp0);
5352 TCGv_i32 fp0 = tcg_temp_new_i32();
5354 tcg_gen_trunc_tl_i32(fp0, t0);
5355 gen_store_fpr32h(fp0, rd);
5356 tcg_temp_free_i32(fp0);
5360 /* XXX: For now we support only a single FPU context. */
5361 gen_helper_1i(ctc1, t0, rd);
5363 /* COP2: Not implemented. */
5370 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5376 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5377 generate_exception(ctx, EXCP_RI);
5380 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5382 const char *opn = "ldst";
5391 TCGv t0 = tcg_temp_local_new();
5393 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5394 gen_store_gpr(t0, rt);
5401 TCGv t0 = tcg_temp_local_new();
5403 gen_load_gpr(t0, rt);
5404 save_cpu_state(ctx, 1);
5405 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5410 #if defined(TARGET_MIPS64)
5412 check_insn(env, ctx, ISA_MIPS3);
5418 TCGv t0 = tcg_temp_local_new();
5420 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5421 gen_store_gpr(t0, rt);
5427 check_insn(env, ctx, ISA_MIPS3);
5429 TCGv t0 = tcg_temp_local_new();
5431 gen_load_gpr(t0, rt);
5432 save_cpu_state(ctx, 1);
5433 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5440 check_insn(env, ctx, ASE_MT);
5445 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5446 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5450 check_insn(env, ctx, ASE_MT);
5451 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5452 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5457 if (!env->tlb->helper_tlbwi)
5463 if (!env->tlb->helper_tlbwr)
5469 if (!env->tlb->helper_tlbp)
5475 if (!env->tlb->helper_tlbr)
5481 check_insn(env, ctx, ISA_MIPS2);
5482 save_cpu_state(ctx, 1);
5484 ctx->bstate = BS_EXCP;
5488 check_insn(env, ctx, ISA_MIPS32);
5489 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5491 generate_exception(ctx, EXCP_RI);
5493 save_cpu_state(ctx, 1);
5495 ctx->bstate = BS_EXCP;
5500 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5501 /* If we get an exception, we want to restart at next instruction */
5503 save_cpu_state(ctx, 1);
5506 ctx->bstate = BS_EXCP;
5511 generate_exception(ctx, EXCP_RI);
5514 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5516 #endif /* !CONFIG_USER_ONLY */
5518 /* CP1 Branches (before delay slot) */
5519 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5520 int32_t cc, int32_t offset)
5522 target_ulong btarget;
5523 const char *opn = "cp1 cond branch";
5524 TCGv_i32 t0 = tcg_temp_new_i32();
5527 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5529 btarget = ctx->pc + 4 + offset;
5534 int l1 = gen_new_label();
5535 int l2 = gen_new_label();
5538 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5539 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5540 tcg_gen_movi_i32(bcond, 0);
5543 tcg_gen_movi_i32(bcond, 1);
5550 int l1 = gen_new_label();
5551 int l2 = gen_new_label();
5554 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5555 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5556 tcg_gen_movi_i32(bcond, 0);
5559 tcg_gen_movi_i32(bcond, 1);
5566 int l1 = gen_new_label();
5567 int l2 = gen_new_label();
5570 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5571 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5572 tcg_gen_movi_i32(bcond, 0);
5575 tcg_gen_movi_i32(bcond, 1);
5582 int l1 = gen_new_label();
5583 int l2 = gen_new_label();
5586 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5587 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5588 tcg_gen_movi_i32(bcond, 0);
5591 tcg_gen_movi_i32(bcond, 1);
5596 ctx->hflags |= MIPS_HFLAG_BL;
5600 int l1 = gen_new_label();
5601 int l2 = gen_new_label();
5604 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5605 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5606 tcg_gen_movi_i32(bcond, 0);
5609 tcg_gen_movi_i32(bcond, 1);
5616 int l1 = gen_new_label();
5617 int l2 = gen_new_label();
5620 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5621 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5622 tcg_gen_movi_i32(bcond, 0);
5625 tcg_gen_movi_i32(bcond, 1);
5632 int l1 = gen_new_label();
5633 int l2 = gen_new_label();
5636 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5637 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5638 tcg_gen_movi_i32(bcond, 0);
5641 tcg_gen_movi_i32(bcond, 1);
5648 int l1 = gen_new_label();
5649 int l2 = gen_new_label();
5652 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5653 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5654 tcg_gen_movi_i32(bcond, 0);
5657 tcg_gen_movi_i32(bcond, 1);
5662 ctx->hflags |= MIPS_HFLAG_BC;
5666 generate_exception (ctx, EXCP_RI);
5669 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5670 ctx->hflags, btarget);
5671 ctx->btarget = btarget;
5674 tcg_temp_free_i32(t0);
5677 /* Coprocessor 1 (FPU) */
5679 #define FOP(func, fmt) (((fmt) << 21) | (func))
5681 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5683 const char *opn = "cp1 move";
5684 TCGv t0 = tcg_temp_local_new();
5689 TCGv_i32 fp0 = tcg_temp_new_i32();
5691 gen_load_fpr32(fp0, fs);
5692 tcg_gen_ext_i32_tl(t0, fp0);
5693 tcg_temp_free_i32(fp0);
5695 gen_store_gpr(t0, rt);
5699 gen_load_gpr(t0, rt);
5701 TCGv_i32 fp0 = tcg_temp_new_i32();
5703 tcg_gen_trunc_tl_i32(fp0, t0);
5704 gen_store_fpr32(fp0, fs);
5705 tcg_temp_free_i32(fp0);
5710 gen_helper_1i(cfc1, t0, fs);
5711 gen_store_gpr(t0, rt);
5715 gen_load_gpr(t0, rt);
5716 gen_helper_1i(ctc1, t0, fs);
5721 TCGv_i64 fp0 = tcg_temp_new_i64();
5723 gen_load_fpr64(ctx, fp0, fs);
5724 tcg_gen_trunc_i64_tl(t0, fp0);
5725 tcg_temp_free_i64(fp0);
5727 gen_store_gpr(t0, rt);
5731 gen_load_gpr(t0, rt);
5733 TCGv_i64 fp0 = tcg_temp_new_i64();
5735 tcg_gen_extu_tl_i64(fp0, t0);
5736 gen_store_fpr64(ctx, fp0, fs);
5737 tcg_temp_free_i64(fp0);
5743 TCGv_i32 fp0 = tcg_temp_new_i32();
5745 gen_load_fpr32h(fp0, fs);
5746 tcg_gen_ext_i32_tl(t0, fp0);
5747 tcg_temp_free_i32(fp0);
5749 gen_store_gpr(t0, rt);
5753 gen_load_gpr(t0, rt);
5755 TCGv_i32 fp0 = tcg_temp_new_i32();
5757 tcg_gen_trunc_tl_i32(fp0, t0);
5758 gen_store_fpr32h(fp0, fs);
5759 tcg_temp_free_i32(fp0);
5765 generate_exception (ctx, EXCP_RI);
5768 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5774 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5776 int l1 = gen_new_label();
5779 TCGv t0 = tcg_temp_local_new();
5780 TCGv_i32 r_tmp = tcg_temp_new_i32();
5783 ccbit = 1 << (24 + cc);
5791 gen_load_gpr(t0, rd);
5792 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5793 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5794 tcg_temp_free_i32(r_tmp);
5795 gen_load_gpr(t0, rs);
5797 gen_store_gpr(t0, rd);
5801 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5805 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5806 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5807 int l1 = gen_new_label();
5810 ccbit = 1 << (24 + cc);
5819 gen_load_fpr32(fp0, fd);
5820 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5821 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5822 tcg_temp_free_i32(r_tmp1);
5823 gen_load_fpr32(fp0, fs);
5825 gen_store_fpr32(fp0, fd);
5826 tcg_temp_free_i32(fp0);
5829 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
5833 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5834 TCGv_i64 fp0 = tcg_temp_local_new_i64();
5835 int l1 = gen_new_label();
5838 ccbit = 1 << (24 + cc);
5847 gen_load_fpr64(ctx, fp0, fd);
5848 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5849 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5850 tcg_temp_free_i32(r_tmp1);
5851 gen_load_fpr64(ctx, fp0, fs);
5853 gen_store_fpr64(ctx, fp0, fd);
5854 tcg_temp_free_i64(fp0);
5857 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
5859 uint32_t ccbit1, ccbit2;
5861 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5862 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5863 int l1 = gen_new_label();
5864 int l2 = gen_new_label();
5867 ccbit1 = 1 << (24 + cc);
5868 ccbit2 = 1 << (25 + cc);
5879 gen_load_fpr32(fp0, fd);
5880 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit1);
5881 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5882 gen_load_fpr32(fp0, fs);
5884 gen_store_fpr32(fp0, fd);
5886 gen_load_fpr32h(fp0, fd);
5887 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit2);
5888 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l2);
5889 gen_load_fpr32h(fp0, fs);
5891 gen_store_fpr32h(fp0, fd);
5893 tcg_temp_free_i32(r_tmp1);
5894 tcg_temp_free_i32(fp0);
5898 static void gen_farith (DisasContext *ctx, uint32_t op1,
5899 int ft, int fs, int fd, int cc)
5901 const char *opn = "farith";
5902 const char *condnames[] = {
5920 const char *condnames_abs[] = {
5938 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5939 uint32_t func = ctx->opcode & 0x3f;
5941 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5944 TCGv_i32 fp0 = tcg_temp_new_i32();
5945 TCGv_i32 fp1 = tcg_temp_new_i32();
5947 gen_load_fpr32(fp0, fs);
5948 gen_load_fpr32(fp1, ft);
5949 gen_helper_float_add_s(fp0, fp0, fp1);
5950 tcg_temp_free_i32(fp1);
5951 gen_store_fpr32(fp0, fd);
5952 tcg_temp_free_i32(fp0);
5959 TCGv_i32 fp0 = tcg_temp_new_i32();
5960 TCGv_i32 fp1 = tcg_temp_new_i32();
5962 gen_load_fpr32(fp0, fs);
5963 gen_load_fpr32(fp1, ft);
5964 gen_helper_float_sub_s(fp0, fp0, fp1);
5965 tcg_temp_free_i32(fp1);
5966 gen_store_fpr32(fp0, fd);
5967 tcg_temp_free_i32(fp0);
5974 TCGv_i32 fp0 = tcg_temp_new_i32();
5975 TCGv_i32 fp1 = tcg_temp_new_i32();
5977 gen_load_fpr32(fp0, fs);
5978 gen_load_fpr32(fp1, ft);
5979 gen_helper_float_mul_s(fp0, fp0, fp1);
5980 tcg_temp_free_i32(fp1);
5981 gen_store_fpr32(fp0, fd);
5982 tcg_temp_free_i32(fp0);
5989 TCGv_i32 fp0 = tcg_temp_new_i32();
5990 TCGv_i32 fp1 = tcg_temp_new_i32();
5992 gen_load_fpr32(fp0, fs);
5993 gen_load_fpr32(fp1, ft);
5994 gen_helper_float_div_s(fp0, fp0, fp1);
5995 tcg_temp_free_i32(fp1);
5996 gen_store_fpr32(fp0, fd);
5997 tcg_temp_free_i32(fp0);
6004 TCGv_i32 fp0 = tcg_temp_new_i32();
6006 gen_load_fpr32(fp0, fs);
6007 gen_helper_float_sqrt_s(fp0, fp0);
6008 gen_store_fpr32(fp0, fd);
6009 tcg_temp_free_i32(fp0);
6015 TCGv_i32 fp0 = tcg_temp_new_i32();
6017 gen_load_fpr32(fp0, fs);
6018 gen_helper_float_abs_s(fp0, fp0);
6019 gen_store_fpr32(fp0, fd);
6020 tcg_temp_free_i32(fp0);
6026 TCGv_i32 fp0 = tcg_temp_new_i32();
6028 gen_load_fpr32(fp0, fs);
6029 gen_store_fpr32(fp0, fd);
6030 tcg_temp_free_i32(fp0);
6036 TCGv_i32 fp0 = tcg_temp_new_i32();
6038 gen_load_fpr32(fp0, fs);
6039 gen_helper_float_chs_s(fp0, fp0);
6040 gen_store_fpr32(fp0, fd);
6041 tcg_temp_free_i32(fp0);
6046 check_cp1_64bitmode(ctx);
6048 TCGv_i32 fp32 = tcg_temp_new_i32();
6049 TCGv_i64 fp64 = tcg_temp_new_i64();
6051 gen_load_fpr32(fp32, fs);
6052 gen_helper_float_roundl_s(fp64, fp32);
6053 tcg_temp_free_i32(fp32);
6054 gen_store_fpr64(ctx, fp64, fd);
6055 tcg_temp_free_i64(fp64);
6060 check_cp1_64bitmode(ctx);
6062 TCGv_i32 fp32 = tcg_temp_new_i32();
6063 TCGv_i64 fp64 = tcg_temp_new_i64();
6065 gen_load_fpr32(fp32, fs);
6066 gen_helper_float_truncl_s(fp64, fp32);
6067 tcg_temp_free_i32(fp32);
6068 gen_store_fpr64(ctx, fp64, fd);
6069 tcg_temp_free_i64(fp64);
6074 check_cp1_64bitmode(ctx);
6076 TCGv_i32 fp32 = tcg_temp_new_i32();
6077 TCGv_i64 fp64 = tcg_temp_new_i64();
6079 gen_load_fpr32(fp32, fs);
6080 gen_helper_float_ceill_s(fp64, fp32);
6081 tcg_temp_free_i32(fp32);
6082 gen_store_fpr64(ctx, fp64, fd);
6083 tcg_temp_free_i64(fp64);
6088 check_cp1_64bitmode(ctx);
6090 TCGv_i32 fp32 = tcg_temp_new_i32();
6091 TCGv_i64 fp64 = tcg_temp_new_i64();
6093 gen_load_fpr32(fp32, fs);
6094 gen_helper_float_floorl_s(fp64, fp32);
6095 tcg_temp_free_i32(fp32);
6096 gen_store_fpr64(ctx, fp64, fd);
6097 tcg_temp_free_i64(fp64);
6103 TCGv_i32 fp0 = tcg_temp_new_i32();
6105 gen_load_fpr32(fp0, fs);
6106 gen_helper_float_roundw_s(fp0, fp0);
6107 gen_store_fpr32(fp0, fd);
6108 tcg_temp_free_i32(fp0);
6114 TCGv_i32 fp0 = tcg_temp_new_i32();
6116 gen_load_fpr32(fp0, fs);
6117 gen_helper_float_truncw_s(fp0, fp0);
6118 gen_store_fpr32(fp0, fd);
6119 tcg_temp_free_i32(fp0);
6125 TCGv_i32 fp0 = tcg_temp_new_i32();
6127 gen_load_fpr32(fp0, fs);
6128 gen_helper_float_ceilw_s(fp0, fp0);
6129 gen_store_fpr32(fp0, fd);
6130 tcg_temp_free_i32(fp0);
6136 TCGv_i32 fp0 = tcg_temp_new_i32();
6138 gen_load_fpr32(fp0, fs);
6139 gen_helper_float_floorw_s(fp0, fp0);
6140 gen_store_fpr32(fp0, fd);
6141 tcg_temp_free_i32(fp0);
6146 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6151 int l1 = gen_new_label();
6152 TCGv t0 = tcg_temp_new();
6153 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6155 gen_load_gpr(t0, ft);
6156 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6157 gen_load_fpr32(fp0, fs);
6158 gen_store_fpr32(fp0, fd);
6159 tcg_temp_free_i32(fp0);
6167 int l1 = gen_new_label();
6168 TCGv t0 = tcg_temp_new();
6169 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6171 gen_load_gpr(t0, ft);
6172 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6173 gen_load_fpr32(fp0, fs);
6174 gen_store_fpr32(fp0, fd);
6175 tcg_temp_free_i32(fp0);
6184 TCGv_i32 fp0 = tcg_temp_new_i32();
6186 gen_load_fpr32(fp0, fs);
6187 gen_helper_float_recip_s(fp0, fp0);
6188 gen_store_fpr32(fp0, fd);
6189 tcg_temp_free_i32(fp0);
6196 TCGv_i32 fp0 = tcg_temp_new_i32();
6198 gen_load_fpr32(fp0, fs);
6199 gen_helper_float_rsqrt_s(fp0, fp0);
6200 gen_store_fpr32(fp0, fd);
6201 tcg_temp_free_i32(fp0);
6206 check_cp1_64bitmode(ctx);
6208 TCGv_i32 fp0 = tcg_temp_new_i32();
6209 TCGv_i32 fp1 = tcg_temp_new_i32();
6211 gen_load_fpr32(fp0, fs);
6212 gen_load_fpr32(fp1, fd);
6213 gen_helper_float_recip2_s(fp0, fp0, fp1);
6214 tcg_temp_free_i32(fp1);
6215 gen_store_fpr32(fp0, fd);
6216 tcg_temp_free_i32(fp0);
6221 check_cp1_64bitmode(ctx);
6223 TCGv_i32 fp0 = tcg_temp_new_i32();
6225 gen_load_fpr32(fp0, fs);
6226 gen_helper_float_recip1_s(fp0, fp0);
6227 gen_store_fpr32(fp0, fd);
6228 tcg_temp_free_i32(fp0);
6233 check_cp1_64bitmode(ctx);
6235 TCGv_i32 fp0 = tcg_temp_new_i32();
6237 gen_load_fpr32(fp0, fs);
6238 gen_helper_float_rsqrt1_s(fp0, fp0);
6239 gen_store_fpr32(fp0, fd);
6240 tcg_temp_free_i32(fp0);
6245 check_cp1_64bitmode(ctx);
6247 TCGv_i32 fp0 = tcg_temp_new_i32();
6248 TCGv_i32 fp1 = tcg_temp_new_i32();
6250 gen_load_fpr32(fp0, fs);
6251 gen_load_fpr32(fp1, ft);
6252 gen_helper_float_rsqrt2_s(fp0, fp0, fp1);
6253 tcg_temp_free_i32(fp1);
6254 gen_store_fpr32(fp0, fd);
6255 tcg_temp_free_i32(fp0);
6260 check_cp1_registers(ctx, fd);
6262 TCGv_i32 fp32 = tcg_temp_new_i32();
6263 TCGv_i64 fp64 = tcg_temp_new_i64();
6265 gen_load_fpr32(fp32, fs);
6266 gen_helper_float_cvtd_s(fp64, fp32);
6267 tcg_temp_free_i32(fp32);
6268 gen_store_fpr64(ctx, fp64, fd);
6269 tcg_temp_free_i64(fp64);
6275 TCGv_i32 fp0 = tcg_temp_new_i32();
6277 gen_load_fpr32(fp0, fs);
6278 gen_helper_float_cvtw_s(fp0, fp0);
6279 gen_store_fpr32(fp0, fd);
6280 tcg_temp_free_i32(fp0);
6285 check_cp1_64bitmode(ctx);
6287 TCGv_i32 fp32 = tcg_temp_new_i32();
6288 TCGv_i64 fp64 = tcg_temp_new_i64();
6290 gen_load_fpr32(fp32, fs);
6291 gen_helper_float_cvtl_s(fp64, fp32);
6292 tcg_temp_free_i32(fp32);
6293 gen_store_fpr64(ctx, fp64, fd);
6294 tcg_temp_free_i64(fp64);
6299 check_cp1_64bitmode(ctx);
6301 TCGv_i64 fp64 = tcg_temp_new_i64();
6302 TCGv_i32 fp32_0 = tcg_temp_new_i32();
6303 TCGv_i32 fp32_1 = tcg_temp_new_i32();
6305 gen_load_fpr32(fp32_0, fs);
6306 gen_load_fpr32(fp32_1, ft);
6307 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6308 tcg_temp_free_i32(fp32_1);
6309 tcg_temp_free_i32(fp32_0);
6310 gen_store_fpr64(ctx, fp64, fd);
6311 tcg_temp_free_i64(fp64);
6332 TCGv_i32 fp0 = tcg_temp_new_i32();
6333 TCGv_i32 fp1 = tcg_temp_new_i32();
6335 gen_load_fpr32(fp0, fs);
6336 gen_load_fpr32(fp1, ft);
6337 if (ctx->opcode & (1 << 6)) {
6339 gen_cmpabs_s(func-48, fp0, fp1, cc);
6340 opn = condnames_abs[func-48];
6342 gen_cmp_s(func-48, fp0, fp1, cc);
6343 opn = condnames[func-48];
6345 tcg_temp_free_i32(fp0);
6346 tcg_temp_free_i32(fp1);
6350 check_cp1_registers(ctx, fs | ft | fd);
6352 TCGv_i64 fp0 = tcg_temp_new_i64();
6353 TCGv_i64 fp1 = tcg_temp_new_i64();
6355 gen_load_fpr64(ctx, fp0, fs);
6356 gen_load_fpr64(ctx, fp1, ft);
6357 gen_helper_float_add_d(fp0, fp0, fp1);
6358 tcg_temp_free_i64(fp1);
6359 gen_store_fpr64(ctx, fp0, fd);
6360 tcg_temp_free_i64(fp0);
6366 check_cp1_registers(ctx, fs | ft | fd);
6368 TCGv_i64 fp0 = tcg_temp_new_i64();
6369 TCGv_i64 fp1 = tcg_temp_new_i64();
6371 gen_load_fpr64(ctx, fp0, fs);
6372 gen_load_fpr64(ctx, fp1, ft);
6373 gen_helper_float_sub_d(fp0, fp0, fp1);
6374 tcg_temp_free_i64(fp1);
6375 gen_store_fpr64(ctx, fp0, fd);
6376 tcg_temp_free_i64(fp0);
6382 check_cp1_registers(ctx, fs | ft | fd);
6384 TCGv_i64 fp0 = tcg_temp_new_i64();
6385 TCGv_i64 fp1 = tcg_temp_new_i64();
6387 gen_load_fpr64(ctx, fp0, fs);
6388 gen_load_fpr64(ctx, fp1, ft);
6389 gen_helper_float_mul_d(fp0, fp0, fp1);
6390 tcg_temp_free_i64(fp1);
6391 gen_store_fpr64(ctx, fp0, fd);
6392 tcg_temp_free_i64(fp0);
6398 check_cp1_registers(ctx, fs | ft | fd);
6400 TCGv_i64 fp0 = tcg_temp_new_i64();
6401 TCGv_i64 fp1 = tcg_temp_new_i64();
6403 gen_load_fpr64(ctx, fp0, fs);
6404 gen_load_fpr64(ctx, fp1, ft);
6405 gen_helper_float_div_d(fp0, fp0, fp1);
6406 tcg_temp_free_i64(fp1);
6407 gen_store_fpr64(ctx, fp0, fd);
6408 tcg_temp_free_i64(fp0);
6414 check_cp1_registers(ctx, fs | fd);
6416 TCGv_i64 fp0 = tcg_temp_new_i64();
6418 gen_load_fpr64(ctx, fp0, fs);
6419 gen_helper_float_sqrt_d(fp0, fp0);
6420 gen_store_fpr64(ctx, fp0, fd);
6421 tcg_temp_free_i64(fp0);
6426 check_cp1_registers(ctx, fs | fd);
6428 TCGv_i64 fp0 = tcg_temp_new_i64();
6430 gen_load_fpr64(ctx, fp0, fs);
6431 gen_helper_float_abs_d(fp0, fp0);
6432 gen_store_fpr64(ctx, fp0, fd);
6433 tcg_temp_free_i64(fp0);
6438 check_cp1_registers(ctx, fs | fd);
6440 TCGv_i64 fp0 = tcg_temp_new_i64();
6442 gen_load_fpr64(ctx, fp0, fs);
6443 gen_store_fpr64(ctx, fp0, fd);
6444 tcg_temp_free_i64(fp0);
6449 check_cp1_registers(ctx, fs | fd);
6451 TCGv_i64 fp0 = tcg_temp_new_i64();
6453 gen_load_fpr64(ctx, fp0, fs);
6454 gen_helper_float_chs_d(fp0, fp0);
6455 gen_store_fpr64(ctx, fp0, fd);
6456 tcg_temp_free_i64(fp0);
6461 check_cp1_64bitmode(ctx);
6463 TCGv_i64 fp0 = tcg_temp_new_i64();
6465 gen_load_fpr64(ctx, fp0, fs);
6466 gen_helper_float_roundl_d(fp0, fp0);
6467 gen_store_fpr64(ctx, fp0, fd);
6468 tcg_temp_free_i64(fp0);
6473 check_cp1_64bitmode(ctx);
6475 TCGv_i64 fp0 = tcg_temp_new_i64();
6477 gen_load_fpr64(ctx, fp0, fs);
6478 gen_helper_float_truncl_d(fp0, fp0);
6479 gen_store_fpr64(ctx, fp0, fd);
6480 tcg_temp_free_i64(fp0);
6485 check_cp1_64bitmode(ctx);
6487 TCGv_i64 fp0 = tcg_temp_new_i64();
6489 gen_load_fpr64(ctx, fp0, fs);
6490 gen_helper_float_ceill_d(fp0, fp0);
6491 gen_store_fpr64(ctx, fp0, fd);
6492 tcg_temp_free_i64(fp0);
6497 check_cp1_64bitmode(ctx);
6499 TCGv_i64 fp0 = tcg_temp_new_i64();
6501 gen_load_fpr64(ctx, fp0, fs);
6502 gen_helper_float_floorl_d(fp0, fp0);
6503 gen_store_fpr64(ctx, fp0, fd);
6504 tcg_temp_free_i64(fp0);
6509 check_cp1_registers(ctx, fs);
6511 TCGv_i32 fp32 = tcg_temp_new_i32();
6512 TCGv_i64 fp64 = tcg_temp_new_i64();
6514 gen_load_fpr64(ctx, fp64, fs);
6515 gen_helper_float_roundw_d(fp32, fp64);
6516 tcg_temp_free_i64(fp64);
6517 gen_store_fpr32(fp32, fd);
6518 tcg_temp_free_i32(fp32);
6523 check_cp1_registers(ctx, fs);
6525 TCGv_i32 fp32 = tcg_temp_new_i32();
6526 TCGv_i64 fp64 = tcg_temp_new_i64();
6528 gen_load_fpr64(ctx, fp64, fs);
6529 gen_helper_float_truncw_d(fp32, fp64);
6530 tcg_temp_free_i64(fp64);
6531 gen_store_fpr32(fp32, fd);
6532 tcg_temp_free_i32(fp32);
6537 check_cp1_registers(ctx, fs);
6539 TCGv_i32 fp32 = tcg_temp_new_i32();
6540 TCGv_i64 fp64 = tcg_temp_new_i64();
6542 gen_load_fpr64(ctx, fp64, fs);
6543 gen_helper_float_ceilw_d(fp32, fp64);
6544 tcg_temp_free_i64(fp64);
6545 gen_store_fpr32(fp32, fd);
6546 tcg_temp_free_i32(fp32);
6551 check_cp1_registers(ctx, fs);
6553 TCGv_i32 fp32 = tcg_temp_new_i32();
6554 TCGv_i64 fp64 = tcg_temp_new_i64();
6556 gen_load_fpr64(ctx, fp64, fs);
6557 gen_helper_float_floorw_d(fp32, fp64);
6558 tcg_temp_free_i64(fp64);
6559 gen_store_fpr32(fp32, fd);
6560 tcg_temp_free_i32(fp32);
6565 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6570 int l1 = gen_new_label();
6571 TCGv t0 = tcg_temp_new();
6572 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6574 gen_load_gpr(t0, ft);
6575 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6576 gen_load_fpr64(ctx, fp0, fs);
6577 gen_store_fpr64(ctx, fp0, fd);
6578 tcg_temp_free_i64(fp0);
6586 int l1 = gen_new_label();
6587 TCGv t0 = tcg_temp_new();
6588 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6590 gen_load_gpr(t0, ft);
6591 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6592 gen_load_fpr64(ctx, fp0, fs);
6593 gen_store_fpr64(ctx, fp0, fd);
6594 tcg_temp_free_i64(fp0);
6601 check_cp1_64bitmode(ctx);
6603 TCGv_i64 fp0 = tcg_temp_new_i64();
6605 gen_load_fpr64(ctx, fp0, fs);
6606 gen_helper_float_recip_d(fp0, fp0);
6607 gen_store_fpr64(ctx, fp0, fd);
6608 tcg_temp_free_i64(fp0);
6613 check_cp1_64bitmode(ctx);
6615 TCGv_i64 fp0 = tcg_temp_new_i64();
6617 gen_load_fpr64(ctx, fp0, fs);
6618 gen_helper_float_rsqrt_d(fp0, fp0);
6619 gen_store_fpr64(ctx, fp0, fd);
6620 tcg_temp_free_i64(fp0);
6625 check_cp1_64bitmode(ctx);
6627 TCGv_i64 fp0 = tcg_temp_new_i64();
6628 TCGv_i64 fp1 = tcg_temp_new_i64();
6630 gen_load_fpr64(ctx, fp0, fs);
6631 gen_load_fpr64(ctx, fp1, ft);
6632 gen_helper_float_recip2_d(fp0, fp0, fp1);
6633 tcg_temp_free_i64(fp1);
6634 gen_store_fpr64(ctx, fp0, fd);
6635 tcg_temp_free_i64(fp0);
6640 check_cp1_64bitmode(ctx);
6642 TCGv_i64 fp0 = tcg_temp_new_i64();
6644 gen_load_fpr64(ctx, fp0, fs);
6645 gen_helper_float_recip1_d(fp0, fp0);
6646 gen_store_fpr64(ctx, fp0, fd);
6647 tcg_temp_free_i64(fp0);
6652 check_cp1_64bitmode(ctx);
6654 TCGv_i64 fp0 = tcg_temp_new_i64();
6656 gen_load_fpr64(ctx, fp0, fs);
6657 gen_helper_float_rsqrt1_d(fp0, fp0);
6658 gen_store_fpr64(ctx, fp0, fd);
6659 tcg_temp_free_i64(fp0);
6664 check_cp1_64bitmode(ctx);
6666 TCGv_i64 fp0 = tcg_temp_new_i64();
6667 TCGv_i64 fp1 = tcg_temp_new_i64();
6669 gen_load_fpr64(ctx, fp0, fs);
6670 gen_load_fpr64(ctx, fp1, ft);
6671 gen_helper_float_rsqrt2_d(fp0, fp0, fp1);
6672 tcg_temp_free_i64(fp1);
6673 gen_store_fpr64(ctx, fp0, fd);
6674 tcg_temp_free_i64(fp0);
6695 TCGv_i64 fp0 = tcg_temp_new_i64();
6696 TCGv_i64 fp1 = tcg_temp_new_i64();
6698 gen_load_fpr64(ctx, fp0, fs);
6699 gen_load_fpr64(ctx, fp1, ft);
6700 if (ctx->opcode & (1 << 6)) {
6702 check_cp1_registers(ctx, fs | ft);
6703 gen_cmpabs_d(func-48, fp0, fp1, cc);
6704 opn = condnames_abs[func-48];
6706 check_cp1_registers(ctx, fs | ft);
6707 gen_cmp_d(func-48, fp0, fp1, cc);
6708 opn = condnames[func-48];
6710 tcg_temp_free_i64(fp0);
6711 tcg_temp_free_i64(fp1);
6715 check_cp1_registers(ctx, fs);
6717 TCGv_i32 fp32 = tcg_temp_new_i32();
6718 TCGv_i64 fp64 = tcg_temp_new_i64();
6720 gen_load_fpr64(ctx, fp64, fs);
6721 gen_helper_float_cvts_d(fp32, fp64);
6722 tcg_temp_free_i64(fp64);
6723 gen_store_fpr32(fp32, fd);
6724 tcg_temp_free_i32(fp32);
6729 check_cp1_registers(ctx, fs);
6731 TCGv_i32 fp32 = tcg_temp_new_i32();
6732 TCGv_i64 fp64 = tcg_temp_new_i64();
6734 gen_load_fpr64(ctx, fp64, fs);
6735 gen_helper_float_cvtw_d(fp32, fp64);
6736 tcg_temp_free_i64(fp64);
6737 gen_store_fpr32(fp32, fd);
6738 tcg_temp_free_i32(fp32);
6743 check_cp1_64bitmode(ctx);
6745 TCGv_i64 fp0 = tcg_temp_new_i64();
6747 gen_load_fpr64(ctx, fp0, fs);
6748 gen_helper_float_cvtl_d(fp0, fp0);
6749 gen_store_fpr64(ctx, fp0, fd);
6750 tcg_temp_free_i64(fp0);
6756 TCGv_i32 fp0 = tcg_temp_new_i32();
6758 gen_load_fpr32(fp0, fs);
6759 gen_helper_float_cvts_w(fp0, fp0);
6760 gen_store_fpr32(fp0, fd);
6761 tcg_temp_free_i32(fp0);
6766 check_cp1_registers(ctx, fd);
6768 TCGv_i32 fp32 = tcg_temp_new_i32();
6769 TCGv_i64 fp64 = tcg_temp_new_i64();
6771 gen_load_fpr32(fp32, fs);
6772 gen_helper_float_cvtd_w(fp64, fp32);
6773 tcg_temp_free_i32(fp32);
6774 gen_store_fpr64(ctx, fp64, fd);
6775 tcg_temp_free_i64(fp64);
6780 check_cp1_64bitmode(ctx);
6782 TCGv_i32 fp32 = tcg_temp_new_i32();
6783 TCGv_i64 fp64 = tcg_temp_new_i64();
6785 gen_load_fpr64(ctx, fp64, fs);
6786 gen_helper_float_cvts_l(fp32, fp64);
6787 tcg_temp_free_i64(fp64);
6788 gen_store_fpr32(fp32, fd);
6789 tcg_temp_free_i32(fp32);
6794 check_cp1_64bitmode(ctx);
6796 TCGv_i64 fp0 = tcg_temp_new_i64();
6798 gen_load_fpr64(ctx, fp0, fs);
6799 gen_helper_float_cvtd_l(fp0, fp0);
6800 gen_store_fpr64(ctx, fp0, fd);
6801 tcg_temp_free_i64(fp0);
6806 check_cp1_64bitmode(ctx);
6808 TCGv_i64 fp0 = tcg_temp_new_i64();
6810 gen_load_fpr64(ctx, fp0, fs);
6811 gen_helper_float_cvtps_pw(fp0, fp0);
6812 gen_store_fpr64(ctx, fp0, fd);
6813 tcg_temp_free_i64(fp0);
6818 check_cp1_64bitmode(ctx);
6820 TCGv_i64 fp0 = tcg_temp_new_i64();
6821 TCGv_i64 fp1 = tcg_temp_new_i64();
6823 gen_load_fpr64(ctx, fp0, fs);
6824 gen_load_fpr64(ctx, fp1, ft);
6825 gen_helper_float_add_ps(fp0, fp0, fp1);
6826 tcg_temp_free_i64(fp1);
6827 gen_store_fpr64(ctx, fp0, fd);
6828 tcg_temp_free_i64(fp0);
6833 check_cp1_64bitmode(ctx);
6835 TCGv_i64 fp0 = tcg_temp_new_i64();
6836 TCGv_i64 fp1 = tcg_temp_new_i64();
6838 gen_load_fpr64(ctx, fp0, fs);
6839 gen_load_fpr64(ctx, fp1, ft);
6840 gen_helper_float_sub_ps(fp0, fp0, fp1);
6841 tcg_temp_free_i64(fp1);
6842 gen_store_fpr64(ctx, fp0, fd);
6843 tcg_temp_free_i64(fp0);
6848 check_cp1_64bitmode(ctx);
6850 TCGv_i64 fp0 = tcg_temp_new_i64();
6851 TCGv_i64 fp1 = tcg_temp_new_i64();
6853 gen_load_fpr64(ctx, fp0, fs);
6854 gen_load_fpr64(ctx, fp1, ft);
6855 gen_helper_float_mul_ps(fp0, fp0, fp1);
6856 tcg_temp_free_i64(fp1);
6857 gen_store_fpr64(ctx, fp0, fd);
6858 tcg_temp_free_i64(fp0);
6863 check_cp1_64bitmode(ctx);
6865 TCGv_i64 fp0 = tcg_temp_new_i64();
6867 gen_load_fpr64(ctx, fp0, fs);
6868 gen_helper_float_abs_ps(fp0, fp0);
6869 gen_store_fpr64(ctx, fp0, fd);
6870 tcg_temp_free_i64(fp0);
6875 check_cp1_64bitmode(ctx);
6877 TCGv_i64 fp0 = tcg_temp_new_i64();
6879 gen_load_fpr64(ctx, fp0, fs);
6880 gen_store_fpr64(ctx, fp0, fd);
6881 tcg_temp_free_i64(fp0);
6886 check_cp1_64bitmode(ctx);
6888 TCGv_i64 fp0 = tcg_temp_new_i64();
6890 gen_load_fpr64(ctx, fp0, fs);
6891 gen_helper_float_chs_ps(fp0, fp0);
6892 gen_store_fpr64(ctx, fp0, fd);
6893 tcg_temp_free_i64(fp0);
6898 check_cp1_64bitmode(ctx);
6899 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6903 check_cp1_64bitmode(ctx);
6905 int l1 = gen_new_label();
6906 TCGv t0 = tcg_temp_new();
6907 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6908 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6910 gen_load_gpr(t0, ft);
6911 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6912 gen_load_fpr32(fp0, fs);
6913 gen_load_fpr32h(fph0, fs);
6914 gen_store_fpr32(fp0, fd);
6915 gen_store_fpr32h(fph0, fd);
6916 tcg_temp_free_i32(fp0);
6917 tcg_temp_free_i32(fph0);
6924 check_cp1_64bitmode(ctx);
6926 int l1 = gen_new_label();
6927 TCGv t0 = tcg_temp_new();
6928 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6929 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6931 gen_load_gpr(t0, ft);
6932 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6933 gen_load_fpr32(fp0, fs);
6934 gen_load_fpr32h(fph0, fs);
6935 gen_store_fpr32(fp0, fd);
6936 gen_store_fpr32h(fph0, fd);
6937 tcg_temp_free_i32(fp0);
6938 tcg_temp_free_i32(fph0);
6945 check_cp1_64bitmode(ctx);
6947 TCGv_i64 fp0 = tcg_temp_new_i64();
6948 TCGv_i64 fp1 = tcg_temp_new_i64();
6950 gen_load_fpr64(ctx, fp0, ft);
6951 gen_load_fpr64(ctx, fp1, fs);
6952 gen_helper_float_addr_ps(fp0, fp0, fp1);
6953 tcg_temp_free_i64(fp1);
6954 gen_store_fpr64(ctx, fp0, fd);
6955 tcg_temp_free_i64(fp0);
6960 check_cp1_64bitmode(ctx);
6962 TCGv_i64 fp0 = tcg_temp_new_i64();
6963 TCGv_i64 fp1 = tcg_temp_new_i64();
6965 gen_load_fpr64(ctx, fp0, ft);
6966 gen_load_fpr64(ctx, fp1, fs);
6967 gen_helper_float_mulr_ps(fp0, fp0, fp1);
6968 tcg_temp_free_i64(fp1);
6969 gen_store_fpr64(ctx, fp0, fd);
6970 tcg_temp_free_i64(fp0);
6975 check_cp1_64bitmode(ctx);
6977 TCGv_i64 fp0 = tcg_temp_new_i64();
6978 TCGv_i64 fp1 = tcg_temp_new_i64();
6980 gen_load_fpr64(ctx, fp0, fs);
6981 gen_load_fpr64(ctx, fp1, fd);
6982 gen_helper_float_recip2_ps(fp0, fp0, fp1);
6983 tcg_temp_free_i64(fp1);
6984 gen_store_fpr64(ctx, fp0, fd);
6985 tcg_temp_free_i64(fp0);
6990 check_cp1_64bitmode(ctx);
6992 TCGv_i64 fp0 = tcg_temp_new_i64();
6994 gen_load_fpr64(ctx, fp0, fs);
6995 gen_helper_float_recip1_ps(fp0, fp0);
6996 gen_store_fpr64(ctx, fp0, fd);
6997 tcg_temp_free_i64(fp0);
7002 check_cp1_64bitmode(ctx);
7004 TCGv_i64 fp0 = tcg_temp_new_i64();
7006 gen_load_fpr64(ctx, fp0, fs);
7007 gen_helper_float_rsqrt1_ps(fp0, fp0);
7008 gen_store_fpr64(ctx, fp0, fd);
7009 tcg_temp_free_i64(fp0);
7014 check_cp1_64bitmode(ctx);
7016 TCGv_i64 fp0 = tcg_temp_new_i64();
7017 TCGv_i64 fp1 = tcg_temp_new_i64();
7019 gen_load_fpr64(ctx, fp0, fs);
7020 gen_load_fpr64(ctx, fp1, ft);
7021 gen_helper_float_rsqrt2_ps(fp0, fp0, fp1);
7022 tcg_temp_free_i64(fp1);
7023 gen_store_fpr64(ctx, fp0, fd);
7024 tcg_temp_free_i64(fp0);
7029 check_cp1_64bitmode(ctx);
7031 TCGv_i32 fp0 = tcg_temp_new_i32();
7033 gen_load_fpr32h(fp0, fs);
7034 gen_helper_float_cvts_pu(fp0, fp0);
7035 gen_store_fpr32(fp0, fd);
7036 tcg_temp_free_i32(fp0);
7041 check_cp1_64bitmode(ctx);
7043 TCGv_i64 fp0 = tcg_temp_new_i64();
7045 gen_load_fpr64(ctx, fp0, fs);
7046 gen_helper_float_cvtpw_ps(fp0, fp0);
7047 gen_store_fpr64(ctx, fp0, fd);
7048 tcg_temp_free_i64(fp0);
7053 check_cp1_64bitmode(ctx);
7055 TCGv_i32 fp0 = tcg_temp_new_i32();
7057 gen_load_fpr32(fp0, fs);
7058 gen_helper_float_cvts_pl(fp0, fp0);
7059 gen_store_fpr32(fp0, fd);
7060 tcg_temp_free_i32(fp0);
7065 check_cp1_64bitmode(ctx);
7067 TCGv_i32 fp0 = tcg_temp_new_i32();
7068 TCGv_i32 fp1 = tcg_temp_new_i32();
7070 gen_load_fpr32(fp0, fs);
7071 gen_load_fpr32(fp1, ft);
7072 gen_store_fpr32h(fp0, fd);
7073 gen_store_fpr32(fp1, fd);
7074 tcg_temp_free_i32(fp0);
7075 tcg_temp_free_i32(fp1);
7080 check_cp1_64bitmode(ctx);
7082 TCGv_i32 fp0 = tcg_temp_new_i32();
7083 TCGv_i32 fp1 = tcg_temp_new_i32();
7085 gen_load_fpr32(fp0, fs);
7086 gen_load_fpr32h(fp1, ft);
7087 gen_store_fpr32(fp1, fd);
7088 gen_store_fpr32h(fp0, fd);
7089 tcg_temp_free_i32(fp0);
7090 tcg_temp_free_i32(fp1);
7095 check_cp1_64bitmode(ctx);
7097 TCGv_i32 fp0 = tcg_temp_new_i32();
7098 TCGv_i32 fp1 = tcg_temp_new_i32();
7100 gen_load_fpr32h(fp0, fs);
7101 gen_load_fpr32(fp1, ft);
7102 gen_store_fpr32(fp1, fd);
7103 gen_store_fpr32h(fp0, fd);
7104 tcg_temp_free_i32(fp0);
7105 tcg_temp_free_i32(fp1);
7110 check_cp1_64bitmode(ctx);
7112 TCGv_i32 fp0 = tcg_temp_new_i32();
7113 TCGv_i32 fp1 = tcg_temp_new_i32();
7115 gen_load_fpr32h(fp0, fs);
7116 gen_load_fpr32h(fp1, ft);
7117 gen_store_fpr32(fp1, fd);
7118 gen_store_fpr32h(fp0, fd);
7119 tcg_temp_free_i32(fp0);
7120 tcg_temp_free_i32(fp1);
7140 check_cp1_64bitmode(ctx);
7142 TCGv_i64 fp0 = tcg_temp_new_i64();
7143 TCGv_i64 fp1 = tcg_temp_new_i64();
7145 gen_load_fpr64(ctx, fp0, fs);
7146 gen_load_fpr64(ctx, fp1, ft);
7147 if (ctx->opcode & (1 << 6)) {
7148 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7149 opn = condnames_abs[func-48];
7151 gen_cmp_ps(func-48, fp0, fp1, cc);
7152 opn = condnames[func-48];
7154 tcg_temp_free_i64(fp0);
7155 tcg_temp_free_i64(fp1);
7160 generate_exception (ctx, EXCP_RI);
7165 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7168 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7171 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7176 /* Coprocessor 3 (FPU) */
7177 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7178 int fd, int fs, int base, int index)
7180 const char *opn = "extended float load/store";
7182 TCGv t0 = tcg_temp_local_new();
7183 TCGv t1 = tcg_temp_local_new();
7186 gen_load_gpr(t0, index);
7187 } else if (index == 0) {
7188 gen_load_gpr(t0, base);
7190 gen_load_gpr(t0, index);
7191 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
7193 /* Don't do NOP if destination is zero: we must perform the actual
7199 TCGv_i32 fp0 = tcg_temp_new_i32();
7201 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
7202 tcg_gen_trunc_tl_i32(fp0, t1);
7203 gen_store_fpr32(fp0, fd);
7204 tcg_temp_free_i32(fp0);
7210 check_cp1_registers(ctx, fd);
7212 TCGv_i64 fp0 = tcg_temp_new_i64();
7214 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7215 gen_store_fpr64(ctx, fp0, fd);
7216 tcg_temp_free_i64(fp0);
7221 check_cp1_64bitmode(ctx);
7222 tcg_gen_andi_tl(t0, t0, ~0x7);
7224 TCGv_i64 fp0 = tcg_temp_new_i64();
7226 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7227 gen_store_fpr64(ctx, fp0, fd);
7228 tcg_temp_free_i64(fp0);
7235 TCGv_i32 fp0 = tcg_temp_new_i32();
7237 gen_load_fpr32(fp0, fs);
7238 tcg_gen_extu_i32_tl(t1, fp0);
7239 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
7240 tcg_temp_free_i32(fp0);
7247 check_cp1_registers(ctx, fs);
7249 TCGv_i64 fp0 = tcg_temp_new_i64();
7251 gen_load_fpr64(ctx, fp0, fs);
7252 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7253 tcg_temp_free_i64(fp0);
7259 check_cp1_64bitmode(ctx);
7260 tcg_gen_andi_tl(t0, t0, ~0x7);
7262 TCGv_i64 fp0 = tcg_temp_new_i64();
7264 gen_load_fpr64(ctx, fp0, fs);
7265 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7266 tcg_temp_free_i64(fp0);
7273 generate_exception(ctx, EXCP_RI);
7280 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7281 regnames[index], regnames[base]);
7284 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7285 int fd, int fr, int fs, int ft)
7287 const char *opn = "flt3_arith";
7291 check_cp1_64bitmode(ctx);
7293 TCGv t0 = tcg_temp_local_new();
7294 TCGv_i32 fp0 = tcg_temp_local_new_i32();
7295 TCGv_i32 fph0 = tcg_temp_local_new_i32();
7296 TCGv_i32 fp1 = tcg_temp_local_new_i32();
7297 TCGv_i32 fph1 = tcg_temp_local_new_i32();
7298 int l1 = gen_new_label();
7299 int l2 = gen_new_label();
7301 gen_load_gpr(t0, fr);
7302 tcg_gen_andi_tl(t0, t0, 0x7);
7303 gen_load_fpr32(fp0, fs);
7304 gen_load_fpr32h(fph0, fs);
7305 gen_load_fpr32(fp1, ft);
7306 gen_load_fpr32h(fph1, ft);
7308 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7309 gen_store_fpr32(fp0, fd);
7310 gen_store_fpr32h(fph0, fd);
7313 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7315 #ifdef TARGET_WORDS_BIGENDIAN
7316 gen_store_fpr32(fph1, fd);
7317 gen_store_fpr32h(fp0, fd);
7319 gen_store_fpr32(fph0, fd);
7320 gen_store_fpr32h(fp1, fd);
7323 tcg_temp_free_i32(fp0);
7324 tcg_temp_free_i32(fph0);
7325 tcg_temp_free_i32(fp1);
7326 tcg_temp_free_i32(fph1);
7333 TCGv_i32 fp0 = tcg_temp_new_i32();
7334 TCGv_i32 fp1 = tcg_temp_new_i32();
7335 TCGv_i32 fp2 = tcg_temp_new_i32();
7337 gen_load_fpr32(fp0, fs);
7338 gen_load_fpr32(fp1, ft);
7339 gen_load_fpr32(fp2, fr);
7340 gen_helper_float_muladd_s(fp2, fp0, fp1, fp2);
7341 tcg_temp_free_i32(fp0);
7342 tcg_temp_free_i32(fp1);
7343 gen_store_fpr32(fp2, fd);
7344 tcg_temp_free_i32(fp2);
7350 check_cp1_registers(ctx, fd | fs | ft | fr);
7352 TCGv_i64 fp0 = tcg_temp_new_i64();
7353 TCGv_i64 fp1 = tcg_temp_new_i64();
7354 TCGv_i64 fp2 = tcg_temp_new_i64();
7356 gen_load_fpr64(ctx, fp0, fs);
7357 gen_load_fpr64(ctx, fp1, ft);
7358 gen_load_fpr64(ctx, fp2, fr);
7359 gen_helper_float_muladd_d(fp2, fp0, fp1, fp2);
7360 tcg_temp_free_i64(fp0);
7361 tcg_temp_free_i64(fp1);
7362 gen_store_fpr64(ctx, fp2, fd);
7363 tcg_temp_free_i64(fp2);
7368 check_cp1_64bitmode(ctx);
7370 TCGv_i64 fp0 = tcg_temp_new_i64();
7371 TCGv_i64 fp1 = tcg_temp_new_i64();
7372 TCGv_i64 fp2 = tcg_temp_new_i64();
7374 gen_load_fpr64(ctx, fp0, fs);
7375 gen_load_fpr64(ctx, fp1, ft);
7376 gen_load_fpr64(ctx, fp2, fr);
7377 gen_helper_float_muladd_ps(fp2, fp0, fp1, fp2);
7378 tcg_temp_free_i64(fp0);
7379 tcg_temp_free_i64(fp1);
7380 gen_store_fpr64(ctx, fp2, fd);
7381 tcg_temp_free_i64(fp2);
7388 TCGv_i32 fp0 = tcg_temp_new_i32();
7389 TCGv_i32 fp1 = tcg_temp_new_i32();
7390 TCGv_i32 fp2 = tcg_temp_new_i32();
7392 gen_load_fpr32(fp0, fs);
7393 gen_load_fpr32(fp1, ft);
7394 gen_load_fpr32(fp2, fr);
7395 gen_helper_float_mulsub_s(fp2, fp0, fp1, fp2);
7396 tcg_temp_free_i32(fp0);
7397 tcg_temp_free_i32(fp1);
7398 gen_store_fpr32(fp2, fd);
7399 tcg_temp_free_i32(fp2);
7405 check_cp1_registers(ctx, fd | fs | ft | fr);
7407 TCGv_i64 fp0 = tcg_temp_new_i64();
7408 TCGv_i64 fp1 = tcg_temp_new_i64();
7409 TCGv_i64 fp2 = tcg_temp_new_i64();
7411 gen_load_fpr64(ctx, fp0, fs);
7412 gen_load_fpr64(ctx, fp1, ft);
7413 gen_load_fpr64(ctx, fp2, fr);
7414 gen_helper_float_mulsub_d(fp2, fp0, fp1, fp2);
7415 tcg_temp_free_i64(fp0);
7416 tcg_temp_free_i64(fp1);
7417 gen_store_fpr64(ctx, fp2, fd);
7418 tcg_temp_free_i64(fp2);
7423 check_cp1_64bitmode(ctx);
7425 TCGv_i64 fp0 = tcg_temp_new_i64();
7426 TCGv_i64 fp1 = tcg_temp_new_i64();
7427 TCGv_i64 fp2 = tcg_temp_new_i64();
7429 gen_load_fpr64(ctx, fp0, fs);
7430 gen_load_fpr64(ctx, fp1, ft);
7431 gen_load_fpr64(ctx, fp2, fr);
7432 gen_helper_float_mulsub_ps(fp2, fp0, fp1, fp2);
7433 tcg_temp_free_i64(fp0);
7434 tcg_temp_free_i64(fp1);
7435 gen_store_fpr64(ctx, fp2, fd);
7436 tcg_temp_free_i64(fp2);
7443 TCGv_i32 fp0 = tcg_temp_new_i32();
7444 TCGv_i32 fp1 = tcg_temp_new_i32();
7445 TCGv_i32 fp2 = tcg_temp_new_i32();
7447 gen_load_fpr32(fp0, fs);
7448 gen_load_fpr32(fp1, ft);
7449 gen_load_fpr32(fp2, fr);
7450 gen_helper_float_nmuladd_s(fp2, fp0, fp1, fp2);
7451 tcg_temp_free_i32(fp0);
7452 tcg_temp_free_i32(fp1);
7453 gen_store_fpr32(fp2, fd);
7454 tcg_temp_free_i32(fp2);
7460 check_cp1_registers(ctx, fd | fs | ft | fr);
7462 TCGv_i64 fp0 = tcg_temp_new_i64();
7463 TCGv_i64 fp1 = tcg_temp_new_i64();
7464 TCGv_i64 fp2 = tcg_temp_new_i64();
7466 gen_load_fpr64(ctx, fp0, fs);
7467 gen_load_fpr64(ctx, fp1, ft);
7468 gen_load_fpr64(ctx, fp2, fr);
7469 gen_helper_float_nmuladd_d(fp2, fp0, fp1, fp2);
7470 tcg_temp_free_i64(fp0);
7471 tcg_temp_free_i64(fp1);
7472 gen_store_fpr64(ctx, fp2, fd);
7473 tcg_temp_free_i64(fp2);
7478 check_cp1_64bitmode(ctx);
7480 TCGv_i64 fp0 = tcg_temp_new_i64();
7481 TCGv_i64 fp1 = tcg_temp_new_i64();
7482 TCGv_i64 fp2 = tcg_temp_new_i64();
7484 gen_load_fpr64(ctx, fp0, fs);
7485 gen_load_fpr64(ctx, fp1, ft);
7486 gen_load_fpr64(ctx, fp2, fr);
7487 gen_helper_float_nmuladd_ps(fp2, fp0, fp1, fp2);
7488 tcg_temp_free_i64(fp0);
7489 tcg_temp_free_i64(fp1);
7490 gen_store_fpr64(ctx, fp2, fd);
7491 tcg_temp_free_i64(fp2);
7498 TCGv_i32 fp0 = tcg_temp_new_i32();
7499 TCGv_i32 fp1 = tcg_temp_new_i32();
7500 TCGv_i32 fp2 = tcg_temp_new_i32();
7502 gen_load_fpr32(fp0, fs);
7503 gen_load_fpr32(fp1, ft);
7504 gen_load_fpr32(fp2, fr);
7505 gen_helper_float_nmulsub_s(fp2, fp0, fp1, fp2);
7506 tcg_temp_free_i32(fp0);
7507 tcg_temp_free_i32(fp1);
7508 gen_store_fpr32(fp2, fd);
7509 tcg_temp_free_i32(fp2);
7515 check_cp1_registers(ctx, fd | fs | ft | fr);
7517 TCGv_i64 fp0 = tcg_temp_new_i64();
7518 TCGv_i64 fp1 = tcg_temp_new_i64();
7519 TCGv_i64 fp2 = tcg_temp_new_i64();
7521 gen_load_fpr64(ctx, fp0, fs);
7522 gen_load_fpr64(ctx, fp1, ft);
7523 gen_load_fpr64(ctx, fp2, fr);
7524 gen_helper_float_nmulsub_d(fp2, fp0, fp1, fp2);
7525 tcg_temp_free_i64(fp0);
7526 tcg_temp_free_i64(fp1);
7527 gen_store_fpr64(ctx, fp2, fd);
7528 tcg_temp_free_i64(fp2);
7533 check_cp1_64bitmode(ctx);
7535 TCGv_i64 fp0 = tcg_temp_new_i64();
7536 TCGv_i64 fp1 = tcg_temp_new_i64();
7537 TCGv_i64 fp2 = tcg_temp_new_i64();
7539 gen_load_fpr64(ctx, fp0, fs);
7540 gen_load_fpr64(ctx, fp1, ft);
7541 gen_load_fpr64(ctx, fp2, fr);
7542 gen_helper_float_nmulsub_ps(fp2, fp0, fp1, fp2);
7543 tcg_temp_free_i64(fp0);
7544 tcg_temp_free_i64(fp1);
7545 gen_store_fpr64(ctx, fp2, fd);
7546 tcg_temp_free_i64(fp2);
7552 generate_exception (ctx, EXCP_RI);
7555 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7556 fregnames[fs], fregnames[ft]);
7559 /* ISA extensions (ASEs) */
7560 /* MIPS16 extension to MIPS32 */
7561 /* SmartMIPS extension to MIPS32 */
7563 #if defined(TARGET_MIPS64)
7565 /* MDMX extension to MIPS64 */
7569 static void decode_opc (CPUState *env, DisasContext *ctx)
7573 uint32_t op, op1, op2;
7576 /* make sure instructions are on a word boundary */
7577 if (ctx->pc & 0x3) {
7578 env->CP0_BadVAddr = ctx->pc;
7579 generate_exception(ctx, EXCP_AdEL);
7583 /* Handle blikely not taken case */
7584 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7585 int l1 = gen_new_label();
7587 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7588 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7590 TCGv_i32 r_tmp = tcg_temp_new_i32();
7592 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7593 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7594 tcg_temp_free_i32(r_tmp);
7596 gen_goto_tb(ctx, 1, ctx->pc + 4);
7599 op = MASK_OP_MAJOR(ctx->opcode);
7600 rs = (ctx->opcode >> 21) & 0x1f;
7601 rt = (ctx->opcode >> 16) & 0x1f;
7602 rd = (ctx->opcode >> 11) & 0x1f;
7603 sa = (ctx->opcode >> 6) & 0x1f;
7604 imm = (int16_t)ctx->opcode;
7607 op1 = MASK_SPECIAL(ctx->opcode);
7609 case OPC_SLL: /* Arithmetic with immediate */
7610 case OPC_SRL ... OPC_SRA:
7611 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7613 case OPC_MOVZ ... OPC_MOVN:
7614 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7615 case OPC_SLLV: /* Arithmetic */
7616 case OPC_SRLV ... OPC_SRAV:
7617 case OPC_ADD ... OPC_NOR:
7618 case OPC_SLT ... OPC_SLTU:
7619 gen_arith(env, ctx, op1, rd, rs, rt);
7621 case OPC_MULT ... OPC_DIVU:
7623 check_insn(env, ctx, INSN_VR54XX);
7624 op1 = MASK_MUL_VR54XX(ctx->opcode);
7625 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7627 gen_muldiv(ctx, op1, rs, rt);
7629 case OPC_JR ... OPC_JALR:
7630 gen_compute_branch(ctx, op1, rs, rd, sa);
7632 case OPC_TGE ... OPC_TEQ: /* Traps */
7634 gen_trap(ctx, op1, rs, rt, -1);
7636 case OPC_MFHI: /* Move from HI/LO */
7638 gen_HILO(ctx, op1, rd);
7641 case OPC_MTLO: /* Move to HI/LO */
7642 gen_HILO(ctx, op1, rs);
7644 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7645 #ifdef MIPS_STRICT_STANDARD
7646 MIPS_INVAL("PMON / selsl");
7647 generate_exception(ctx, EXCP_RI);
7649 gen_helper_0i(pmon, sa);
7653 generate_exception(ctx, EXCP_SYSCALL);
7656 generate_exception(ctx, EXCP_BREAK);
7659 #ifdef MIPS_STRICT_STANDARD
7661 generate_exception(ctx, EXCP_RI);
7663 /* Implemented as RI exception for now. */
7664 MIPS_INVAL("spim (unofficial)");
7665 generate_exception(ctx, EXCP_RI);
7673 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7674 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7675 save_cpu_state(ctx, 1);
7676 check_cp1_enabled(ctx);
7677 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7678 (ctx->opcode >> 16) & 1);
7680 generate_exception_err(ctx, EXCP_CpU, 1);
7684 #if defined(TARGET_MIPS64)
7685 /* MIPS64 specific opcodes */
7687 case OPC_DSRL ... OPC_DSRA:
7689 case OPC_DSRL32 ... OPC_DSRA32:
7690 check_insn(env, ctx, ISA_MIPS3);
7692 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7695 case OPC_DSRLV ... OPC_DSRAV:
7696 case OPC_DADD ... OPC_DSUBU:
7697 check_insn(env, ctx, ISA_MIPS3);
7699 gen_arith(env, ctx, op1, rd, rs, rt);
7701 case OPC_DMULT ... OPC_DDIVU:
7702 check_insn(env, ctx, ISA_MIPS3);
7704 gen_muldiv(ctx, op1, rs, rt);
7707 default: /* Invalid */
7708 MIPS_INVAL("special");
7709 generate_exception(ctx, EXCP_RI);
7714 op1 = MASK_SPECIAL2(ctx->opcode);
7716 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7717 case OPC_MSUB ... OPC_MSUBU:
7718 check_insn(env, ctx, ISA_MIPS32);
7719 gen_muldiv(ctx, op1, rs, rt);
7722 gen_arith(env, ctx, op1, rd, rs, rt);
7726 check_insn(env, ctx, ISA_MIPS32);
7727 gen_cl(ctx, op1, rd, rs);
7730 /* XXX: not clear which exception should be raised
7731 * when in debug mode...
7733 check_insn(env, ctx, ISA_MIPS32);
7734 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7735 generate_exception(ctx, EXCP_DBp);
7737 generate_exception(ctx, EXCP_DBp);
7741 #if defined(TARGET_MIPS64)
7744 check_insn(env, ctx, ISA_MIPS64);
7746 gen_cl(ctx, op1, rd, rs);
7749 default: /* Invalid */
7750 MIPS_INVAL("special2");
7751 generate_exception(ctx, EXCP_RI);
7756 op1 = MASK_SPECIAL3(ctx->opcode);
7760 check_insn(env, ctx, ISA_MIPS32R2);
7761 gen_bitops(ctx, op1, rt, rs, sa, rd);
7764 check_insn(env, ctx, ISA_MIPS32R2);
7765 op2 = MASK_BSHFL(ctx->opcode);
7766 gen_bshfl(ctx, op2, rt, rd);
7769 check_insn(env, ctx, ISA_MIPS32R2);
7771 TCGv t0 = tcg_temp_local_new();
7775 save_cpu_state(ctx, 1);
7776 gen_helper_rdhwr_cpunum(t0);
7779 save_cpu_state(ctx, 1);
7780 gen_helper_rdhwr_synci_step(t0);
7783 save_cpu_state(ctx, 1);
7784 gen_helper_rdhwr_cc(t0);
7787 save_cpu_state(ctx, 1);
7788 gen_helper_rdhwr_ccres(t0);
7791 #if defined(CONFIG_USER_ONLY)
7792 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7795 /* XXX: Some CPUs implement this in hardware.
7796 Not supported yet. */
7798 default: /* Invalid */
7799 MIPS_INVAL("rdhwr");
7800 generate_exception(ctx, EXCP_RI);
7803 gen_store_gpr(t0, rt);
7808 check_insn(env, ctx, ASE_MT);
7810 TCGv t0 = tcg_temp_local_new();
7811 TCGv t1 = tcg_temp_local_new();
7813 gen_load_gpr(t0, rt);
7814 gen_load_gpr(t1, rs);
7815 gen_helper_fork(t0, t1);
7821 check_insn(env, ctx, ASE_MT);
7823 TCGv t0 = tcg_temp_local_new();
7825 gen_load_gpr(t0, rs);
7826 gen_helper_yield(t0, t0);
7827 gen_store_gpr(t0, rd);
7831 #if defined(TARGET_MIPS64)
7832 case OPC_DEXTM ... OPC_DEXT:
7833 case OPC_DINSM ... OPC_DINS:
7834 check_insn(env, ctx, ISA_MIPS64R2);
7836 gen_bitops(ctx, op1, rt, rs, sa, rd);
7839 check_insn(env, ctx, ISA_MIPS64R2);
7841 op2 = MASK_DBSHFL(ctx->opcode);
7842 gen_bshfl(ctx, op2, rt, rd);
7845 default: /* Invalid */
7846 MIPS_INVAL("special3");
7847 generate_exception(ctx, EXCP_RI);
7852 op1 = MASK_REGIMM(ctx->opcode);
7854 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7855 case OPC_BLTZAL ... OPC_BGEZALL:
7856 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7858 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7860 gen_trap(ctx, op1, rs, -1, imm);
7863 check_insn(env, ctx, ISA_MIPS32R2);
7866 default: /* Invalid */
7867 MIPS_INVAL("regimm");
7868 generate_exception(ctx, EXCP_RI);
7873 check_cp0_enabled(ctx);
7874 op1 = MASK_CP0(ctx->opcode);
7880 #if defined(TARGET_MIPS64)
7884 #ifndef CONFIG_USER_ONLY
7885 gen_cp0(env, ctx, op1, rt, rd);
7886 #endif /* !CONFIG_USER_ONLY */
7888 case OPC_C0_FIRST ... OPC_C0_LAST:
7889 #ifndef CONFIG_USER_ONLY
7890 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7891 #endif /* !CONFIG_USER_ONLY */
7894 #ifndef CONFIG_USER_ONLY
7896 TCGv t0 = tcg_temp_local_new();
7898 op2 = MASK_MFMC0(ctx->opcode);
7901 check_insn(env, ctx, ASE_MT);
7902 gen_helper_dmt(t0, t0);
7905 check_insn(env, ctx, ASE_MT);
7906 gen_helper_emt(t0, t0);
7909 check_insn(env, ctx, ASE_MT);
7910 gen_helper_dvpe(t0, t0);
7913 check_insn(env, ctx, ASE_MT);
7914 gen_helper_evpe(t0, t0);
7917 check_insn(env, ctx, ISA_MIPS32R2);
7918 save_cpu_state(ctx, 1);
7920 /* Stop translation as we may have switched the execution mode */
7921 ctx->bstate = BS_STOP;
7924 check_insn(env, ctx, ISA_MIPS32R2);
7925 save_cpu_state(ctx, 1);
7927 /* Stop translation as we may have switched the execution mode */
7928 ctx->bstate = BS_STOP;
7930 default: /* Invalid */
7931 MIPS_INVAL("mfmc0");
7932 generate_exception(ctx, EXCP_RI);
7935 gen_store_gpr(t0, rt);
7938 #endif /* !CONFIG_USER_ONLY */
7941 check_insn(env, ctx, ISA_MIPS32R2);
7942 gen_load_srsgpr(rt, rd);
7945 check_insn(env, ctx, ISA_MIPS32R2);
7946 gen_store_srsgpr(rt, rd);
7950 generate_exception(ctx, EXCP_RI);
7954 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7955 gen_arith_imm(env, ctx, op, rt, rs, imm);
7957 case OPC_J ... OPC_JAL: /* Jump */
7958 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7959 gen_compute_branch(ctx, op, rs, rt, offset);
7961 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7962 case OPC_BEQL ... OPC_BGTZL:
7963 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7965 case OPC_LB ... OPC_LWR: /* Load and stores */
7966 case OPC_SB ... OPC_SW:
7970 gen_ldst(ctx, op, rt, rs, imm);
7973 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7977 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7981 /* Floating point (COP1). */
7986 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7987 save_cpu_state(ctx, 1);
7988 check_cp1_enabled(ctx);
7989 gen_flt_ldst(ctx, op, rt, rs, imm);
7991 generate_exception_err(ctx, EXCP_CpU, 1);
7996 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7997 save_cpu_state(ctx, 1);
7998 check_cp1_enabled(ctx);
7999 op1 = MASK_CP1(ctx->opcode);
8003 check_insn(env, ctx, ISA_MIPS32R2);
8008 gen_cp1(ctx, op1, rt, rd);
8010 #if defined(TARGET_MIPS64)
8013 check_insn(env, ctx, ISA_MIPS3);
8014 gen_cp1(ctx, op1, rt, rd);
8020 check_insn(env, ctx, ASE_MIPS3D);
8023 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8024 (rt >> 2) & 0x7, imm << 2);
8031 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8036 generate_exception (ctx, EXCP_RI);
8040 generate_exception_err(ctx, EXCP_CpU, 1);
8050 /* COP2: Not implemented. */
8051 generate_exception_err(ctx, EXCP_CpU, 2);
8055 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8056 save_cpu_state(ctx, 1);
8057 check_cp1_enabled(ctx);
8058 op1 = MASK_CP3(ctx->opcode);
8066 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8084 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8088 generate_exception (ctx, EXCP_RI);
8092 generate_exception_err(ctx, EXCP_CpU, 1);
8096 #if defined(TARGET_MIPS64)
8097 /* MIPS64 opcodes */
8099 case OPC_LDL ... OPC_LDR:
8100 case OPC_SDL ... OPC_SDR:
8105 check_insn(env, ctx, ISA_MIPS3);
8107 gen_ldst(ctx, op, rt, rs, imm);
8109 case OPC_DADDI ... OPC_DADDIU:
8110 check_insn(env, ctx, ISA_MIPS3);
8112 gen_arith_imm(env, ctx, op, rt, rs, imm);
8116 check_insn(env, ctx, ASE_MIPS16);
8117 /* MIPS16: Not implemented. */
8119 check_insn(env, ctx, ASE_MDMX);
8120 /* MDMX: Not implemented. */
8121 default: /* Invalid */
8122 MIPS_INVAL("major opcode");
8123 generate_exception(ctx, EXCP_RI);
8126 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8127 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8128 /* Branches completion */
8129 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8130 ctx->bstate = BS_BRANCH;
8131 save_cpu_state(ctx, 0);
8132 /* FIXME: Need to clear can_do_io. */
8135 /* unconditional branch */
8136 MIPS_DEBUG("unconditional branch");
8137 gen_goto_tb(ctx, 0, ctx->btarget);
8140 /* blikely taken case */
8141 MIPS_DEBUG("blikely branch taken");
8142 gen_goto_tb(ctx, 0, ctx->btarget);
8145 /* Conditional branch */
8146 MIPS_DEBUG("conditional branch");
8148 int l1 = gen_new_label();
8150 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8151 gen_goto_tb(ctx, 1, ctx->pc + 4);
8153 gen_goto_tb(ctx, 0, ctx->btarget);
8157 /* unconditional branch to register */
8158 MIPS_DEBUG("branch to register");
8159 tcg_gen_mov_tl(cpu_PC, btarget);
8163 MIPS_DEBUG("unknown branch");
8170 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8174 target_ulong pc_start;
8175 uint16_t *gen_opc_end;
8182 qemu_log("search pc %d\n", search_pc);
8185 /* Leave some spare opc slots for branch handling. */
8186 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8190 ctx.bstate = BS_NONE;
8191 /* Restore delay slot state from the tb context. */
8192 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8193 restore_cpu_state(env, &ctx);
8194 #ifdef CONFIG_USER_ONLY
8195 ctx.mem_idx = MIPS_HFLAG_UM;
8197 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8200 max_insns = tb->cflags & CF_COUNT_MASK;
8202 max_insns = CF_COUNT_MASK;
8204 qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n");
8205 /* FIXME: This may print out stale hflags from env... */
8206 log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
8208 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags);
8210 while (ctx.bstate == BS_NONE) {
8211 if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
8212 TAILQ_FOREACH(bp, &env->breakpoints, entry) {
8213 if (bp->pc == ctx.pc) {
8214 save_cpu_state(&ctx, 1);
8215 ctx.bstate = BS_BRANCH;
8216 gen_helper_0i(raise_exception, EXCP_DEBUG);
8217 /* Include the breakpoint location or the tb won't
8218 * be flushed when it must be. */
8220 goto done_generating;
8226 j = gen_opc_ptr - gen_opc_buf;
8230 gen_opc_instr_start[lj++] = 0;
8232 gen_opc_pc[lj] = ctx.pc;
8233 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8234 gen_opc_instr_start[lj] = 1;
8235 gen_opc_icount[lj] = num_insns;
8237 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8239 ctx.opcode = ldl_code(ctx.pc);
8240 decode_opc(env, &ctx);
8244 if (env->singlestep_enabled)
8247 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8250 if (gen_opc_ptr >= gen_opc_end)
8253 if (num_insns >= max_insns)
8255 #if defined (MIPS_SINGLE_STEP)
8259 if (tb->cflags & CF_LAST_IO)
8261 if (env->singlestep_enabled) {
8262 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8263 gen_helper_0i(raise_exception, EXCP_DEBUG);
8265 switch (ctx.bstate) {
8267 gen_helper_interrupt_restart();
8268 gen_goto_tb(&ctx, 0, ctx.pc);
8271 save_cpu_state(&ctx, 0);
8272 gen_goto_tb(&ctx, 0, ctx.pc);
8275 gen_helper_interrupt_restart();
8284 gen_icount_end(tb, num_insns);
8285 *gen_opc_ptr = INDEX_op_end;
8287 j = gen_opc_ptr - gen_opc_buf;
8290 gen_opc_instr_start[lj++] = 0;
8292 tb->size = ctx.pc - pc_start;
8293 tb->icount = num_insns;
8297 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
8298 qemu_log("IN: %s\n", lookup_symbol(pc_start));
8299 log_target_disas(pc_start, ctx.pc - pc_start, 0);
8302 qemu_log_mask(CPU_LOG_TB_CPU, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8306 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8308 gen_intermediate_code_internal(env, tb, 0);
8311 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8313 gen_intermediate_code_internal(env, tb, 1);
8316 static void fpu_dump_state(CPUState *env, FILE *f,
8317 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8321 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8323 #define printfpr(fp) \
8326 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8327 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8328 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8331 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8332 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8333 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8334 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8335 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8340 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8341 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8342 get_float_exception_flags(&env->active_fpu.fp_status));
8343 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8344 fpu_fprintf(f, "%3s: ", fregnames[i]);
8345 printfpr(&env->active_fpu.fpr[i]);
8351 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8352 /* Debug help: The architecture requires 32bit code to maintain proper
8353 sign-extended values on 64bit machines. */
8355 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8358 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8359 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8364 if (!SIGN_EXT_P(env->active_tc.PC))
8365 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8366 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8367 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8368 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8369 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8370 if (!SIGN_EXT_P(env->btarget))
8371 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8373 for (i = 0; i < 32; i++) {
8374 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8375 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8378 if (!SIGN_EXT_P(env->CP0_EPC))
8379 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8380 if (!SIGN_EXT_P(env->CP0_LLAddr))
8381 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8385 void cpu_dump_state (CPUState *env, FILE *f,
8386 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8391 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",
8392 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8393 env->hflags, env->btarget, env->bcond);
8394 for (i = 0; i < 32; i++) {
8396 cpu_fprintf(f, "GPR%02d:", i);
8397 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8399 cpu_fprintf(f, "\n");
8402 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8403 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8404 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8405 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8406 if (env->hflags & MIPS_HFLAG_FPU)
8407 fpu_dump_state(env, f, cpu_fprintf, flags);
8408 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8409 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8413 static void mips_tcg_init(void)
8418 /* Initialize various static tables. */
8422 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
8423 for (i = 0; i < 32; i++)
8424 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
8425 offsetof(CPUState, active_tc.gpr[i]),
8427 cpu_PC = tcg_global_mem_new(TCG_AREG0,
8428 offsetof(CPUState, active_tc.PC), "PC");
8429 for (i = 0; i < MIPS_DSP_ACC; i++) {
8430 cpu_HI[i] = tcg_global_mem_new(TCG_AREG0,
8431 offsetof(CPUState, active_tc.HI[i]),
8433 cpu_LO[i] = tcg_global_mem_new(TCG_AREG0,
8434 offsetof(CPUState, active_tc.LO[i]),
8436 cpu_ACX[i] = tcg_global_mem_new(TCG_AREG0,
8437 offsetof(CPUState, active_tc.ACX[i]),
8440 cpu_dspctrl = tcg_global_mem_new(TCG_AREG0,
8441 offsetof(CPUState, active_tc.DSPControl),
8443 bcond = tcg_global_mem_new_i32(TCG_AREG0,
8444 offsetof(CPUState, bcond), "bcond");
8445 btarget = tcg_global_mem_new(TCG_AREG0,
8446 offsetof(CPUState, btarget), "btarget");
8447 for (i = 0; i < 32; i++)
8448 fpu_fpr32[i] = tcg_global_mem_new_i32(TCG_AREG0,
8449 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8451 for (i = 0; i < 32; i++)
8452 fpu_fpr32h[i] = tcg_global_mem_new_i32(TCG_AREG0,
8453 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8455 fpu_fcr0 = tcg_global_mem_new_i32(TCG_AREG0,
8456 offsetof(CPUState, active_fpu.fcr0),
8458 fpu_fcr31 = tcg_global_mem_new_i32(TCG_AREG0,
8459 offsetof(CPUState, active_fpu.fcr31),
8462 /* register helpers */
8463 #define GEN_HELPER 2
8469 #include "translate_init.c"
8471 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8474 const mips_def_t *def;
8476 def = cpu_mips_find_by_name(cpu_model);
8479 env = qemu_mallocz(sizeof(CPUMIPSState));
8480 env->cpu_model = def;
8483 env->cpu_model_str = cpu_model;
8489 void cpu_reset (CPUMIPSState *env)
8491 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
8492 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
8493 log_cpu_state(env, 0);
8496 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8501 #if defined(CONFIG_USER_ONLY)
8502 env->hflags = MIPS_HFLAG_UM;
8504 if (env->hflags & MIPS_HFLAG_BMASK) {
8505 /* If the exception was raised from a delay slot,
8506 come back to the jump. */
8507 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8509 env->CP0_ErrorEPC = env->active_tc.PC;
8511 env->active_tc.PC = (int32_t)0xBFC00000;
8513 /* SMP not implemented */
8514 env->CP0_EBase = 0x80000000;
8515 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8516 /* vectored interrupts not implemented, timer on int 7,
8517 no performance counters. */
8518 env->CP0_IntCtl = 0xe0000000;
8522 for (i = 0; i < 7; i++) {
8523 env->CP0_WatchLo[i] = 0;
8524 env->CP0_WatchHi[i] = 0x80000000;
8526 env->CP0_WatchLo[7] = 0;
8527 env->CP0_WatchHi[7] = 0;
8529 /* Count register increments in debug mode, EJTAG version 1 */
8530 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8531 env->hflags = MIPS_HFLAG_CP0;
8533 env->exception_index = EXCP_NONE;
8534 cpu_mips_register(env, env->cpu_model);
8537 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8538 unsigned long searched_pc, int pc_pos, void *puc)
8540 env->active_tc.PC = gen_opc_pc[pc_pos];
8541 env->hflags &= ~MIPS_HFLAG_BMASK;
8542 env->hflags |= gen_opc_hflags[pc_pos];