2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
41 //#define MIPS_SINGLE_STEP
43 /* MIPS major opcodes */
44 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
47 /* indirect opcode tables */
48 OPC_SPECIAL = (0x00 << 26),
49 OPC_REGIMM = (0x01 << 26),
50 OPC_CP0 = (0x10 << 26),
51 OPC_CP1 = (0x11 << 26),
52 OPC_CP2 = (0x12 << 26),
53 OPC_CP3 = (0x13 << 26),
54 OPC_SPECIAL2 = (0x1C << 26),
55 OPC_SPECIAL3 = (0x1F << 26),
56 /* arithmetic with immediate */
57 OPC_ADDI = (0x08 << 26),
58 OPC_ADDIU = (0x09 << 26),
59 OPC_SLTI = (0x0A << 26),
60 OPC_SLTIU = (0x0B << 26),
61 OPC_ANDI = (0x0C << 26),
62 OPC_ORI = (0x0D << 26),
63 OPC_XORI = (0x0E << 26),
64 OPC_LUI = (0x0F << 26),
65 OPC_DADDI = (0x18 << 26),
66 OPC_DADDIU = (0x19 << 26),
67 /* Jump and branches */
69 OPC_JAL = (0x03 << 26),
70 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
71 OPC_BEQL = (0x14 << 26),
72 OPC_BNE = (0x05 << 26),
73 OPC_BNEL = (0x15 << 26),
74 OPC_BLEZ = (0x06 << 26),
75 OPC_BLEZL = (0x16 << 26),
76 OPC_BGTZ = (0x07 << 26),
77 OPC_BGTZL = (0x17 << 26),
78 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
80 OPC_LDL = (0x1A << 26),
81 OPC_LDR = (0x1B << 26),
82 OPC_LB = (0x20 << 26),
83 OPC_LH = (0x21 << 26),
84 OPC_LWL = (0x22 << 26),
85 OPC_LW = (0x23 << 26),
86 OPC_LBU = (0x24 << 26),
87 OPC_LHU = (0x25 << 26),
88 OPC_LWR = (0x26 << 26),
89 OPC_LWU = (0x27 << 26),
90 OPC_SB = (0x28 << 26),
91 OPC_SH = (0x29 << 26),
92 OPC_SWL = (0x2A << 26),
93 OPC_SW = (0x2B << 26),
94 OPC_SDL = (0x2C << 26),
95 OPC_SDR = (0x2D << 26),
96 OPC_SWR = (0x2E << 26),
97 OPC_LL = (0x30 << 26),
98 OPC_LLD = (0x34 << 26),
99 OPC_LD = (0x37 << 26),
100 OPC_SC = (0x38 << 26),
101 OPC_SCD = (0x3C << 26),
102 OPC_SD = (0x3F << 26),
103 /* Floating point load/store */
104 OPC_LWC1 = (0x31 << 26),
105 OPC_LWC2 = (0x32 << 26),
106 OPC_LDC1 = (0x35 << 26),
107 OPC_LDC2 = (0x36 << 26),
108 OPC_SWC1 = (0x39 << 26),
109 OPC_SWC2 = (0x3A << 26),
110 OPC_SDC1 = (0x3D << 26),
111 OPC_SDC2 = (0x3E << 26),
112 /* MDMX ASE specific */
113 OPC_MDMX = (0x1E << 26),
114 /* Cache and prefetch */
115 OPC_CACHE = (0x2F << 26),
116 OPC_PREF = (0x33 << 26),
117 /* Reserved major opcode */
118 OPC_MAJOR3B_RESERVED = (0x3B << 26),
121 /* MIPS special opcodes */
122 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
126 OPC_SLL = 0x00 | OPC_SPECIAL,
127 /* NOP is SLL r0, r0, 0 */
128 /* SSNOP is SLL r0, r0, 1 */
129 /* EHB is SLL r0, r0, 3 */
130 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
131 OPC_SRA = 0x03 | OPC_SPECIAL,
132 OPC_SLLV = 0x04 | OPC_SPECIAL,
133 OPC_SRLV = 0x06 | OPC_SPECIAL, /* also ROTRV */
134 OPC_SRAV = 0x07 | OPC_SPECIAL,
135 OPC_DSLLV = 0x14 | OPC_SPECIAL,
136 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
137 OPC_DSRAV = 0x17 | OPC_SPECIAL,
138 OPC_DSLL = 0x38 | OPC_SPECIAL,
139 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
140 OPC_DSRA = 0x3B | OPC_SPECIAL,
141 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
142 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
143 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
144 /* Multiplication / division */
145 OPC_MULT = 0x18 | OPC_SPECIAL,
146 OPC_MULTU = 0x19 | OPC_SPECIAL,
147 OPC_DIV = 0x1A | OPC_SPECIAL,
148 OPC_DIVU = 0x1B | OPC_SPECIAL,
149 OPC_DMULT = 0x1C | OPC_SPECIAL,
150 OPC_DMULTU = 0x1D | OPC_SPECIAL,
151 OPC_DDIV = 0x1E | OPC_SPECIAL,
152 OPC_DDIVU = 0x1F | OPC_SPECIAL,
153 /* 2 registers arithmetic / logic */
154 OPC_ADD = 0x20 | OPC_SPECIAL,
155 OPC_ADDU = 0x21 | OPC_SPECIAL,
156 OPC_SUB = 0x22 | OPC_SPECIAL,
157 OPC_SUBU = 0x23 | OPC_SPECIAL,
158 OPC_AND = 0x24 | OPC_SPECIAL,
159 OPC_OR = 0x25 | OPC_SPECIAL,
160 OPC_XOR = 0x26 | OPC_SPECIAL,
161 OPC_NOR = 0x27 | OPC_SPECIAL,
162 OPC_SLT = 0x2A | OPC_SPECIAL,
163 OPC_SLTU = 0x2B | OPC_SPECIAL,
164 OPC_DADD = 0x2C | OPC_SPECIAL,
165 OPC_DADDU = 0x2D | OPC_SPECIAL,
166 OPC_DSUB = 0x2E | OPC_SPECIAL,
167 OPC_DSUBU = 0x2F | OPC_SPECIAL,
169 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
170 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
172 OPC_TGE = 0x30 | OPC_SPECIAL,
173 OPC_TGEU = 0x31 | OPC_SPECIAL,
174 OPC_TLT = 0x32 | OPC_SPECIAL,
175 OPC_TLTU = 0x33 | OPC_SPECIAL,
176 OPC_TEQ = 0x34 | OPC_SPECIAL,
177 OPC_TNE = 0x36 | OPC_SPECIAL,
178 /* HI / LO registers load & stores */
179 OPC_MFHI = 0x10 | OPC_SPECIAL,
180 OPC_MTHI = 0x11 | OPC_SPECIAL,
181 OPC_MFLO = 0x12 | OPC_SPECIAL,
182 OPC_MTLO = 0x13 | OPC_SPECIAL,
183 /* Conditional moves */
184 OPC_MOVZ = 0x0A | OPC_SPECIAL,
185 OPC_MOVN = 0x0B | OPC_SPECIAL,
187 OPC_MOVCI = 0x01 | OPC_SPECIAL,
190 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
191 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
192 OPC_BREAK = 0x0D | OPC_SPECIAL,
193 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
194 OPC_SYNC = 0x0F | OPC_SPECIAL,
196 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
197 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
198 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
199 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
200 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
201 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
202 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
205 /* Multiplication variants of the vr54xx. */
206 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
209 OPC_VR54XX_MULS = (0x03 << 6) | OPC_MULT,
210 OPC_VR54XX_MULSU = (0x03 << 6) | OPC_MULTU,
211 OPC_VR54XX_MACC = (0x05 << 6) | OPC_MULT,
212 OPC_VR54XX_MACCU = (0x05 << 6) | OPC_MULTU,
213 OPC_VR54XX_MSAC = (0x07 << 6) | OPC_MULT,
214 OPC_VR54XX_MSACU = (0x07 << 6) | OPC_MULTU,
215 OPC_VR54XX_MULHI = (0x09 << 6) | OPC_MULT,
216 OPC_VR54XX_MULHIU = (0x09 << 6) | OPC_MULTU,
217 OPC_VR54XX_MULSHI = (0x0B << 6) | OPC_MULT,
218 OPC_VR54XX_MULSHIU = (0x0B << 6) | OPC_MULTU,
219 OPC_VR54XX_MACCHI = (0x0D << 6) | OPC_MULT,
220 OPC_VR54XX_MACCHIU = (0x0D << 6) | OPC_MULTU,
221 OPC_VR54XX_MSACHI = (0x0F << 6) | OPC_MULT,
222 OPC_VR54XX_MSACHIU = (0x0F << 6) | OPC_MULTU,
225 /* REGIMM (rt field) opcodes */
226 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
229 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
230 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
231 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
232 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
233 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
234 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
235 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
236 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
237 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
238 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
239 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
240 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
241 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
242 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
243 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
246 /* Special2 opcodes */
247 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
250 /* Multiply & xxx operations */
251 OPC_MADD = 0x00 | OPC_SPECIAL2,
252 OPC_MADDU = 0x01 | OPC_SPECIAL2,
253 OPC_MUL = 0x02 | OPC_SPECIAL2,
254 OPC_MSUB = 0x04 | OPC_SPECIAL2,
255 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
257 OPC_CLZ = 0x20 | OPC_SPECIAL2,
258 OPC_CLO = 0x21 | OPC_SPECIAL2,
259 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
260 OPC_DCLO = 0x25 | OPC_SPECIAL2,
262 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
265 /* Special3 opcodes */
266 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
269 OPC_EXT = 0x00 | OPC_SPECIAL3,
270 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
271 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
272 OPC_DEXT = 0x03 | OPC_SPECIAL3,
273 OPC_INS = 0x04 | OPC_SPECIAL3,
274 OPC_DINSM = 0x05 | OPC_SPECIAL3,
275 OPC_DINSU = 0x06 | OPC_SPECIAL3,
276 OPC_DINS = 0x07 | OPC_SPECIAL3,
277 OPC_FORK = 0x08 | OPC_SPECIAL3,
278 OPC_YIELD = 0x09 | OPC_SPECIAL3,
279 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
280 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
281 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
285 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
288 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
289 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
290 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
294 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
297 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
298 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
301 /* Coprocessor 0 (rs field) */
302 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
305 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
306 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
307 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
308 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
309 OPC_MFTR = (0x08 << 21) | OPC_CP0,
310 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
311 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
312 OPC_MTTR = (0x0C << 21) | OPC_CP0,
313 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
314 OPC_C0 = (0x10 << 21) | OPC_CP0,
315 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
316 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
320 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
323 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
324 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
325 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
326 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
327 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
328 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
331 /* Coprocessor 0 (with rs == C0) */
332 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
335 OPC_TLBR = 0x01 | OPC_C0,
336 OPC_TLBWI = 0x02 | OPC_C0,
337 OPC_TLBWR = 0x06 | OPC_C0,
338 OPC_TLBP = 0x08 | OPC_C0,
339 OPC_RFE = 0x10 | OPC_C0,
340 OPC_ERET = 0x18 | OPC_C0,
341 OPC_DERET = 0x1F | OPC_C0,
342 OPC_WAIT = 0x20 | OPC_C0,
345 /* Coprocessor 1 (rs field) */
346 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
349 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
350 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
351 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
352 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
353 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
354 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
355 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
356 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
357 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
358 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
359 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
360 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
361 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
362 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
363 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
364 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
365 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
366 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
369 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
370 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
373 OPC_BC1F = (0x00 << 16) | OPC_BC1,
374 OPC_BC1T = (0x01 << 16) | OPC_BC1,
375 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
376 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
380 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
381 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
385 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
386 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
389 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
392 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
393 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
394 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
395 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
396 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
397 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
398 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
399 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
400 OPC_BC2 = (0x08 << 21) | OPC_CP2,
403 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
406 OPC_LWXC1 = 0x00 | OPC_CP3,
407 OPC_LDXC1 = 0x01 | OPC_CP3,
408 OPC_LUXC1 = 0x05 | OPC_CP3,
409 OPC_SWXC1 = 0x08 | OPC_CP3,
410 OPC_SDXC1 = 0x09 | OPC_CP3,
411 OPC_SUXC1 = 0x0D | OPC_CP3,
412 OPC_PREFX = 0x0F | OPC_CP3,
413 OPC_ALNV_PS = 0x1E | OPC_CP3,
414 OPC_MADD_S = 0x20 | OPC_CP3,
415 OPC_MADD_D = 0x21 | OPC_CP3,
416 OPC_MADD_PS = 0x26 | OPC_CP3,
417 OPC_MSUB_S = 0x28 | OPC_CP3,
418 OPC_MSUB_D = 0x29 | OPC_CP3,
419 OPC_MSUB_PS = 0x2E | OPC_CP3,
420 OPC_NMADD_S = 0x30 | OPC_CP3,
421 OPC_NMADD_D = 0x31 | OPC_CP3,
422 OPC_NMADD_PS= 0x36 | OPC_CP3,
423 OPC_NMSUB_S = 0x38 | OPC_CP3,
424 OPC_NMSUB_D = 0x39 | OPC_CP3,
425 OPC_NMSUB_PS= 0x3E | OPC_CP3,
428 /* global register indices */
429 static TCGv_ptr cpu_env;
430 static TCGv cpu_gpr[32], cpu_PC;
431 static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC], cpu_ACX[MIPS_DSP_ACC];
432 static TCGv cpu_dspctrl, btarget;
433 static TCGv_i32 bcond;
434 static TCGv_i32 fpu_fpr32[32], fpu_fpr32h[32];
435 static TCGv_i32 fpu_fcr0, fpu_fcr31;
437 #include "gen-icount.h"
439 #define gen_helper_0i(name, arg) do { \
440 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
441 gen_helper_##name(helper_tmp); \
442 tcg_temp_free_i32(helper_tmp); \
445 #define gen_helper_1i(name, arg1, arg2) do { \
446 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
447 gen_helper_##name(arg1, helper_tmp); \
448 tcg_temp_free_i32(helper_tmp); \
451 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
452 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
453 gen_helper_##name(arg1, arg2, helper_tmp); \
454 tcg_temp_free_i32(helper_tmp); \
457 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
458 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
459 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
460 tcg_temp_free_i32(helper_tmp); \
463 typedef struct DisasContext {
464 struct TranslationBlock *tb;
465 target_ulong pc, saved_pc;
467 /* Routine used to access memory */
469 uint32_t hflags, saved_hflags;
471 target_ulong btarget;
475 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
476 * exception condition */
477 BS_STOP = 1, /* We want to stop translation for any reason */
478 BS_BRANCH = 2, /* We reached a branch condition */
479 BS_EXCP = 3, /* We reached an exception condition */
482 static const char *regnames[] =
483 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
484 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
485 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
486 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
488 static const char *regnames_HI[] =
489 { "HI0", "HI1", "HI2", "HI3", };
491 static const char *regnames_LO[] =
492 { "LO0", "LO1", "LO2", "LO3", };
494 static const char *regnames_ACX[] =
495 { "ACX0", "ACX1", "ACX2", "ACX3", };
497 static const char *fregnames[] =
498 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
499 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
500 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
501 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
503 static const char *fregnames_h[] =
504 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
505 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
506 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
507 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
509 #ifdef MIPS_DEBUG_DISAS
510 #define MIPS_DEBUG(fmt, args...) \
511 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
512 TARGET_FMT_lx ": %08x " fmt "\n", \
513 ctx->pc, ctx->opcode , ##args)
514 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
516 #define MIPS_DEBUG(fmt, args...) do { } while(0)
517 #define LOG_DISAS(...) do { } while (0)
520 #define MIPS_INVAL(op) \
522 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
523 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
526 /* General purpose registers moves. */
527 static inline void gen_load_gpr (TCGv t, int reg)
530 tcg_gen_movi_tl(t, 0);
532 tcg_gen_mov_tl(t, cpu_gpr[reg]);
535 static inline void gen_store_gpr (TCGv t, int reg)
538 tcg_gen_mov_tl(cpu_gpr[reg], t);
541 /* Moves to/from ACX register. */
542 static inline void gen_load_ACX (TCGv t, int reg)
544 tcg_gen_mov_tl(t, cpu_ACX[reg]);
547 static inline void gen_store_ACX (TCGv t, int reg)
549 tcg_gen_mov_tl(cpu_ACX[reg], t);
552 /* Moves to/from shadow registers. */
553 static inline void gen_load_srsgpr (int from, int to)
555 TCGv r_tmp1 = tcg_temp_new();
558 tcg_gen_movi_tl(r_tmp1, 0);
560 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
561 TCGv_ptr addr = tcg_temp_new_ptr();
563 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
564 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
565 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
566 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
567 tcg_gen_ext_i32_ptr(addr, r_tmp2);
568 tcg_gen_add_ptr(addr, cpu_env, addr);
570 tcg_gen_ld_tl(r_tmp1, addr, sizeof(target_ulong) * from);
571 tcg_temp_free_ptr(addr);
572 tcg_temp_free_i32(r_tmp2);
574 gen_store_gpr(r_tmp1, to);
575 tcg_temp_free(r_tmp1);
578 static inline void gen_store_srsgpr (int from, int to)
581 TCGv r_tmp1 = tcg_temp_new();
582 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
583 TCGv_ptr addr = tcg_temp_new_ptr();
585 gen_load_gpr(r_tmp1, from);
586 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
587 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
588 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
589 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
590 tcg_gen_ext_i32_ptr(addr, r_tmp2);
591 tcg_gen_add_ptr(addr, cpu_env, addr);
593 tcg_gen_st_tl(r_tmp1, addr, sizeof(target_ulong) * to);
594 tcg_temp_free_ptr(addr);
595 tcg_temp_free_i32(r_tmp2);
596 tcg_temp_free(r_tmp1);
600 /* Floating point register moves. */
601 static inline void gen_load_fpr32 (TCGv_i32 t, int reg)
603 tcg_gen_mov_i32(t, fpu_fpr32[reg]);
606 static inline void gen_store_fpr32 (TCGv_i32 t, int reg)
608 tcg_gen_mov_i32(fpu_fpr32[reg], t);
611 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
613 if (ctx->hflags & MIPS_HFLAG_F64) {
614 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg], fpu_fpr32h[reg]);
616 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg & ~1], fpu_fpr32[reg | 1]);
620 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
622 if (ctx->hflags & MIPS_HFLAG_F64) {
623 tcg_gen_trunc_i64_i32(fpu_fpr32[reg], t);
624 tcg_gen_shri_i64(t, t, 32);
625 tcg_gen_trunc_i64_i32(fpu_fpr32h[reg], t);
627 tcg_gen_trunc_i64_i32(fpu_fpr32[reg & ~1], t);
628 tcg_gen_shri_i64(t, t, 32);
629 tcg_gen_trunc_i64_i32(fpu_fpr32[reg | 1], t);
633 static inline void gen_load_fpr32h (TCGv_i32 t, int reg)
635 tcg_gen_mov_i32(t, fpu_fpr32h[reg]);
638 static inline void gen_store_fpr32h (TCGv_i32 t, int reg)
640 tcg_gen_mov_i32(fpu_fpr32h[reg], t);
643 static inline void get_fp_cond (TCGv_i32 t)
645 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
646 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
648 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
649 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
650 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
651 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
652 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
653 tcg_temp_free_i32(r_tmp1);
654 tcg_temp_free_i32(r_tmp2);
657 #define FOP_CONDS(type, fmt, bits) \
658 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
659 TCGv_i##bits b, int cc) \
662 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
663 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
664 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
665 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
666 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
667 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
668 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
669 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
670 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
671 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
672 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
673 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
674 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
675 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
676 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
677 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
683 FOP_CONDS(abs, d, 64)
685 FOP_CONDS(abs, s, 32)
687 FOP_CONDS(abs, ps, 64)
691 #define OP_COND(name, cond) \
692 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
694 int l1 = gen_new_label(); \
695 int l2 = gen_new_label(); \
697 tcg_gen_brcond_tl(cond, t0, t1, l1); \
698 tcg_gen_movi_tl(t0, 0); \
701 tcg_gen_movi_tl(t0, 1); \
704 OP_COND(eq, TCG_COND_EQ);
705 OP_COND(ne, TCG_COND_NE);
706 OP_COND(ge, TCG_COND_GE);
707 OP_COND(geu, TCG_COND_GEU);
708 OP_COND(lt, TCG_COND_LT);
709 OP_COND(ltu, TCG_COND_LTU);
712 #define OP_CONDI(name, cond) \
713 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
715 int l1 = gen_new_label(); \
716 int l2 = gen_new_label(); \
718 tcg_gen_brcondi_tl(cond, t, val, l1); \
719 tcg_gen_movi_tl(t, 0); \
722 tcg_gen_movi_tl(t, 1); \
725 OP_CONDI(lti, TCG_COND_LT);
726 OP_CONDI(ltiu, TCG_COND_LTU);
729 #define OP_CONDZ(name, cond) \
730 static inline void glue(gen_op_, name) (TCGv t) \
732 int l1 = gen_new_label(); \
733 int l2 = gen_new_label(); \
735 tcg_gen_brcondi_tl(cond, t, 0, l1); \
736 tcg_gen_movi_tl(t, 0); \
739 tcg_gen_movi_tl(t, 1); \
742 OP_CONDZ(gez, TCG_COND_GE);
743 OP_CONDZ(gtz, TCG_COND_GT);
744 OP_CONDZ(lez, TCG_COND_LE);
745 OP_CONDZ(ltz, TCG_COND_LT);
748 static inline void gen_save_pc(target_ulong pc)
750 tcg_gen_movi_tl(cpu_PC, pc);
753 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
755 LOG_DISAS("hflags %08x saved %08x\n", ctx->hflags, ctx->saved_hflags);
756 if (do_save_pc && ctx->pc != ctx->saved_pc) {
757 gen_save_pc(ctx->pc);
758 ctx->saved_pc = ctx->pc;
760 if (ctx->hflags != ctx->saved_hflags) {
761 TCGv_i32 r_tmp = tcg_temp_new_i32();
763 tcg_gen_movi_i32(r_tmp, ctx->hflags);
764 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
765 tcg_temp_free_i32(r_tmp);
766 ctx->saved_hflags = ctx->hflags;
767 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
773 tcg_gen_movi_tl(btarget, ctx->btarget);
779 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
781 ctx->saved_hflags = ctx->hflags;
782 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
788 ctx->btarget = env->btarget;
794 generate_exception_err (DisasContext *ctx, int excp, int err)
796 TCGv_i32 texcp = tcg_const_i32(excp);
797 TCGv_i32 terr = tcg_const_i32(err);
798 save_cpu_state(ctx, 1);
799 gen_helper_raise_exception_err(texcp, terr);
800 tcg_temp_free_i32(terr);
801 tcg_temp_free_i32(texcp);
802 gen_helper_interrupt_restart();
807 generate_exception (DisasContext *ctx, int excp)
809 save_cpu_state(ctx, 1);
810 gen_helper_0i(raise_exception, excp);
811 gen_helper_interrupt_restart();
815 /* Addresses computation */
816 static inline void gen_op_addr_add (DisasContext *ctx, TCGv t0, TCGv t1)
818 tcg_gen_add_tl(t0, t0, t1);
820 #if defined(TARGET_MIPS64)
821 /* For compatibility with 32-bit code, data reference in user mode
822 with Status_UX = 0 should be casted to 32-bit and sign extended.
823 See the MIPS64 PRA manual, section 4.10. */
824 if (((ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
825 !(ctx->hflags & MIPS_HFLAG_UX)) {
826 tcg_gen_ext32s_i64(t0, t0);
831 static inline void check_cp0_enabled(DisasContext *ctx)
833 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
834 generate_exception_err(ctx, EXCP_CpU, 1);
837 static inline void check_cp1_enabled(DisasContext *ctx)
839 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
840 generate_exception_err(ctx, EXCP_CpU, 1);
843 /* Verify that the processor is running with COP1X instructions enabled.
844 This is associated with the nabla symbol in the MIPS32 and MIPS64
847 static inline void check_cop1x(DisasContext *ctx)
849 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
850 generate_exception(ctx, EXCP_RI);
853 /* Verify that the processor is running with 64-bit floating-point
854 operations enabled. */
856 static inline void check_cp1_64bitmode(DisasContext *ctx)
858 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
859 generate_exception(ctx, EXCP_RI);
863 * Verify if floating point register is valid; an operation is not defined
864 * if bit 0 of any register specification is set and the FR bit in the
865 * Status register equals zero, since the register numbers specify an
866 * even-odd pair of adjacent coprocessor general registers. When the FR bit
867 * in the Status register equals one, both even and odd register numbers
868 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
870 * Multiple 64 bit wide registers can be checked by calling
871 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
873 static inline void check_cp1_registers(DisasContext *ctx, int regs)
875 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
876 generate_exception(ctx, EXCP_RI);
879 /* This code generates a "reserved instruction" exception if the
880 CPU does not support the instruction set corresponding to flags. */
881 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
883 if (unlikely(!(env->insn_flags & flags)))
884 generate_exception(ctx, EXCP_RI);
887 /* This code generates a "reserved instruction" exception if 64-bit
888 instructions are not enabled. */
889 static inline void check_mips_64(DisasContext *ctx)
891 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
892 generate_exception(ctx, EXCP_RI);
895 /* load/store instructions. */
896 #define OP_LD(insn,fname) \
897 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
899 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
906 #if defined(TARGET_MIPS64)
912 #define OP_ST(insn,fname) \
913 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
915 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
920 #if defined(TARGET_MIPS64)
925 #define OP_LD_ATOMIC(insn,fname) \
926 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
928 tcg_gen_mov_tl(t1, t0); \
929 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
930 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
932 OP_LD_ATOMIC(ll,ld32s);
933 #if defined(TARGET_MIPS64)
934 OP_LD_ATOMIC(lld,ld64);
938 #define OP_ST_ATOMIC(insn,fname,almask) \
939 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
941 TCGv r_tmp = tcg_temp_local_new(); \
942 int l1 = gen_new_label(); \
943 int l2 = gen_new_label(); \
944 int l3 = gen_new_label(); \
946 tcg_gen_andi_tl(r_tmp, t0, almask); \
947 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
948 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
949 generate_exception(ctx, EXCP_AdES); \
951 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
952 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
953 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
954 tcg_gen_movi_tl(t0, 1); \
957 tcg_gen_movi_tl(t0, 0); \
959 tcg_temp_free(r_tmp); \
961 OP_ST_ATOMIC(sc,st32,0x3);
962 #if defined(TARGET_MIPS64)
963 OP_ST_ATOMIC(scd,st64,0x7);
968 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
969 int base, int16_t offset)
971 const char *opn = "ldst";
972 TCGv t0 = tcg_temp_local_new();
973 TCGv t1 = tcg_temp_local_new();
976 tcg_gen_movi_tl(t0, offset);
977 } else if (offset == 0) {
978 gen_load_gpr(t0, base);
980 tcg_gen_movi_tl(t0, offset);
981 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
983 /* Don't do NOP if destination is zero: we must perform the actual
986 #if defined(TARGET_MIPS64)
988 op_ldst_lwu(t0, ctx);
989 gen_store_gpr(t0, rt);
994 gen_store_gpr(t0, rt);
998 op_ldst_lld(t0, t1, ctx);
999 gen_store_gpr(t0, rt);
1003 gen_load_gpr(t1, rt);
1004 op_ldst_sd(t0, t1, ctx);
1008 save_cpu_state(ctx, 1);
1009 gen_load_gpr(t1, rt);
1010 op_ldst_scd(t0, t1, ctx);
1011 gen_store_gpr(t0, rt);
1015 save_cpu_state(ctx, 1);
1016 gen_load_gpr(t1, rt);
1017 gen_helper_3i(ldl, t1, t0, t1, ctx->mem_idx);
1018 gen_store_gpr(t1, rt);
1022 save_cpu_state(ctx, 1);
1023 gen_load_gpr(t1, rt);
1024 gen_helper_2i(sdl, t0, t1, ctx->mem_idx);
1028 save_cpu_state(ctx, 1);
1029 gen_load_gpr(t1, rt);
1030 gen_helper_3i(ldr, t1, t0, t1, ctx->mem_idx);
1031 gen_store_gpr(t1, rt);
1035 save_cpu_state(ctx, 1);
1036 gen_load_gpr(t1, rt);
1037 gen_helper_2i(sdr, t0, t1, ctx->mem_idx);
1042 op_ldst_lw(t0, ctx);
1043 gen_store_gpr(t0, rt);
1047 gen_load_gpr(t1, rt);
1048 op_ldst_sw(t0, t1, ctx);
1052 op_ldst_lh(t0, ctx);
1053 gen_store_gpr(t0, rt);
1057 gen_load_gpr(t1, rt);
1058 op_ldst_sh(t0, t1, ctx);
1062 op_ldst_lhu(t0, ctx);
1063 gen_store_gpr(t0, rt);
1067 op_ldst_lb(t0, ctx);
1068 gen_store_gpr(t0, rt);
1072 gen_load_gpr(t1, rt);
1073 op_ldst_sb(t0, t1, ctx);
1077 op_ldst_lbu(t0, ctx);
1078 gen_store_gpr(t0, rt);
1082 save_cpu_state(ctx, 1);
1083 gen_load_gpr(t1, rt);
1084 gen_helper_3i(lwl, t1, t0, t1, ctx->mem_idx);
1085 gen_store_gpr(t1, rt);
1089 save_cpu_state(ctx, 1);
1090 gen_load_gpr(t1, rt);
1091 gen_helper_2i(swl, t0, t1, ctx->mem_idx);
1095 save_cpu_state(ctx, 1);
1096 gen_load_gpr(t1, rt);
1097 gen_helper_3i(lwr, t1, t0, t1, ctx->mem_idx);
1098 gen_store_gpr(t1, rt);
1102 save_cpu_state(ctx, 1);
1103 gen_load_gpr(t1, rt);
1104 gen_helper_2i(swr, t0, t1, ctx->mem_idx);
1108 op_ldst_ll(t0, t1, ctx);
1109 gen_store_gpr(t0, rt);
1113 save_cpu_state(ctx, 1);
1114 gen_load_gpr(t1, rt);
1115 op_ldst_sc(t0, t1, ctx);
1116 gen_store_gpr(t0, rt);
1121 generate_exception(ctx, EXCP_RI);
1124 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1130 /* Load and store */
1131 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1132 int base, int16_t offset)
1134 const char *opn = "flt_ldst";
1135 TCGv t0 = tcg_temp_local_new();
1138 tcg_gen_movi_tl(t0, offset);
1139 } else if (offset == 0) {
1140 gen_load_gpr(t0, base);
1142 tcg_gen_movi_tl(t0, offset);
1143 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
1145 /* Don't do NOP if destination is zero: we must perform the actual
1150 TCGv_i32 fp0 = tcg_temp_new_i32();
1151 TCGv t1 = tcg_temp_new();
1153 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
1154 tcg_gen_trunc_tl_i32(fp0, t1);
1155 gen_store_fpr32(fp0, ft);
1157 tcg_temp_free_i32(fp0);
1163 TCGv_i32 fp0 = tcg_temp_new_i32();
1164 TCGv t1 = tcg_temp_new();
1166 gen_load_fpr32(fp0, ft);
1167 tcg_gen_extu_i32_tl(t1, fp0);
1168 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
1170 tcg_temp_free_i32(fp0);
1176 TCGv_i64 fp0 = tcg_temp_new_i64();
1178 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1179 gen_store_fpr64(ctx, fp0, ft);
1180 tcg_temp_free_i64(fp0);
1186 TCGv_i64 fp0 = tcg_temp_new_i64();
1188 gen_load_fpr64(ctx, fp0, ft);
1189 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1190 tcg_temp_free_i64(fp0);
1196 generate_exception(ctx, EXCP_RI);
1199 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1204 /* Arithmetic with immediate operand */
1205 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1206 int rt, int rs, int16_t imm)
1209 const char *opn = "imm arith";
1210 TCGv t0 = tcg_temp_local_new();
1212 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1213 /* If no destination, treat it as a NOP.
1214 For addi, we must generate the overflow exception when needed. */
1218 uimm = (uint16_t)imm;
1222 #if defined(TARGET_MIPS64)
1228 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1233 gen_load_gpr(t0, rs);
1236 tcg_gen_movi_tl(t0, imm << 16);
1241 #if defined(TARGET_MIPS64)
1250 gen_load_gpr(t0, rs);
1256 TCGv r_tmp1 = tcg_temp_new();
1257 TCGv r_tmp2 = tcg_temp_new();
1258 int l1 = gen_new_label();
1260 save_cpu_state(ctx, 1);
1261 tcg_gen_ext32s_tl(r_tmp1, t0);
1262 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1264 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1265 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1266 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1267 tcg_temp_free(r_tmp2);
1268 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1269 /* operands of same sign, result different sign */
1270 generate_exception(ctx, EXCP_OVERFLOW);
1272 tcg_temp_free(r_tmp1);
1274 tcg_gen_ext32s_tl(t0, t0);
1279 tcg_gen_addi_tl(t0, t0, uimm);
1280 tcg_gen_ext32s_tl(t0, t0);
1283 #if defined(TARGET_MIPS64)
1286 TCGv r_tmp1 = tcg_temp_new();
1287 TCGv r_tmp2 = tcg_temp_new();
1288 int l1 = gen_new_label();
1290 save_cpu_state(ctx, 1);
1291 tcg_gen_mov_tl(r_tmp1, t0);
1292 tcg_gen_addi_tl(t0, t0, uimm);
1294 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1295 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1296 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1297 tcg_temp_free(r_tmp2);
1298 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1299 /* operands of same sign, result different sign */
1300 generate_exception(ctx, EXCP_OVERFLOW);
1302 tcg_temp_free(r_tmp1);
1307 tcg_gen_addi_tl(t0, t0, uimm);
1312 gen_op_lti(t0, uimm);
1316 gen_op_ltiu(t0, uimm);
1320 tcg_gen_andi_tl(t0, t0, uimm);
1324 tcg_gen_ori_tl(t0, t0, uimm);
1328 tcg_gen_xori_tl(t0, t0, uimm);
1335 tcg_gen_shli_tl(t0, t0, uimm);
1336 tcg_gen_ext32s_tl(t0, t0);
1340 tcg_gen_ext32s_tl(t0, t0);
1341 tcg_gen_sari_tl(t0, t0, uimm);
1345 switch ((ctx->opcode >> 21) & 0x1f) {
1348 tcg_gen_ext32u_tl(t0, t0);
1349 tcg_gen_shri_tl(t0, t0, uimm);
1351 tcg_gen_ext32s_tl(t0, t0);
1356 /* rotr is decoded as srl on non-R2 CPUs */
1357 if (env->insn_flags & ISA_MIPS32R2) {
1359 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1361 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1362 tcg_gen_rotri_i32(r_tmp1, r_tmp1, uimm);
1363 tcg_gen_ext_i32_tl(t0, r_tmp1);
1364 tcg_temp_free_i32(r_tmp1);
1369 tcg_gen_ext32u_tl(t0, t0);
1370 tcg_gen_shri_tl(t0, t0, uimm);
1372 tcg_gen_ext32s_tl(t0, t0);
1378 MIPS_INVAL("invalid srl flag");
1379 generate_exception(ctx, EXCP_RI);
1383 #if defined(TARGET_MIPS64)
1385 tcg_gen_shli_tl(t0, t0, uimm);
1389 tcg_gen_sari_tl(t0, t0, uimm);
1393 switch ((ctx->opcode >> 21) & 0x1f) {
1395 tcg_gen_shri_tl(t0, t0, uimm);
1399 /* drotr is decoded as dsrl on non-R2 CPUs */
1400 if (env->insn_flags & ISA_MIPS32R2) {
1402 tcg_gen_rotri_tl(t0, t0, uimm);
1406 tcg_gen_shri_tl(t0, t0, uimm);
1411 MIPS_INVAL("invalid dsrl flag");
1412 generate_exception(ctx, EXCP_RI);
1417 tcg_gen_shli_tl(t0, t0, uimm + 32);
1421 tcg_gen_sari_tl(t0, t0, uimm + 32);
1425 switch ((ctx->opcode >> 21) & 0x1f) {
1427 tcg_gen_shri_tl(t0, t0, uimm + 32);
1431 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1432 if (env->insn_flags & ISA_MIPS32R2) {
1433 tcg_gen_rotri_tl(t0, t0, uimm + 32);
1436 tcg_gen_shri_tl(t0, t0, uimm + 32);
1441 MIPS_INVAL("invalid dsrl32 flag");
1442 generate_exception(ctx, EXCP_RI);
1449 generate_exception(ctx, EXCP_RI);
1452 gen_store_gpr(t0, rt);
1453 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1459 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1460 int rd, int rs, int rt)
1462 const char *opn = "arith";
1463 TCGv t0 = tcg_temp_local_new();
1464 TCGv t1 = tcg_temp_local_new();
1466 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1467 && opc != OPC_DADD && opc != OPC_DSUB) {
1468 /* If no destination, treat it as a NOP.
1469 For add & sub, we must generate the overflow exception when needed. */
1473 gen_load_gpr(t0, rs);
1474 /* Specialcase the conventional move operation. */
1475 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1476 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1477 gen_store_gpr(t0, rd);
1480 gen_load_gpr(t1, rt);
1484 TCGv r_tmp1 = tcg_temp_new();
1485 TCGv r_tmp2 = tcg_temp_new();
1486 int l1 = gen_new_label();
1488 save_cpu_state(ctx, 1);
1489 tcg_gen_ext32s_tl(r_tmp1, t0);
1490 tcg_gen_ext32s_tl(r_tmp2, t1);
1491 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1493 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1494 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1495 tcg_gen_xor_tl(r_tmp2, t0, t1);
1496 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1497 tcg_temp_free(r_tmp2);
1498 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1499 /* operands of same sign, result different sign */
1500 generate_exception(ctx, EXCP_OVERFLOW);
1502 tcg_temp_free(r_tmp1);
1504 tcg_gen_ext32s_tl(t0, t0);
1509 tcg_gen_add_tl(t0, t0, t1);
1510 tcg_gen_ext32s_tl(t0, t0);
1515 TCGv r_tmp1 = tcg_temp_new();
1516 TCGv r_tmp2 = tcg_temp_new();
1517 int l1 = gen_new_label();
1519 save_cpu_state(ctx, 1);
1520 tcg_gen_ext32s_tl(r_tmp1, t0);
1521 tcg_gen_ext32s_tl(r_tmp2, t1);
1522 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1524 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1525 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1526 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1527 tcg_temp_free(r_tmp2);
1528 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1529 /* operands of different sign, first operand and result different sign */
1530 generate_exception(ctx, EXCP_OVERFLOW);
1532 tcg_temp_free(r_tmp1);
1534 tcg_gen_ext32s_tl(t0, t0);
1539 tcg_gen_sub_tl(t0, t0, t1);
1540 tcg_gen_ext32s_tl(t0, t0);
1543 #if defined(TARGET_MIPS64)
1546 TCGv r_tmp1 = tcg_temp_new();
1547 TCGv r_tmp2 = tcg_temp_new();
1548 int l1 = gen_new_label();
1550 save_cpu_state(ctx, 1);
1551 tcg_gen_mov_tl(r_tmp1, t0);
1552 tcg_gen_add_tl(t0, t0, t1);
1554 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1555 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1556 tcg_gen_xor_tl(r_tmp2, t0, t1);
1557 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1558 tcg_temp_free(r_tmp2);
1559 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1560 /* operands of same sign, result different sign */
1561 generate_exception(ctx, EXCP_OVERFLOW);
1563 tcg_temp_free(r_tmp1);
1568 tcg_gen_add_tl(t0, t0, t1);
1573 TCGv r_tmp1 = tcg_temp_new();
1574 TCGv r_tmp2 = tcg_temp_new();
1575 int l1 = gen_new_label();
1577 save_cpu_state(ctx, 1);
1578 tcg_gen_mov_tl(r_tmp1, t0);
1579 tcg_gen_sub_tl(t0, t0, t1);
1581 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1582 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1583 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1584 tcg_temp_free(r_tmp2);
1585 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1586 /* operands of different sign, first operand and result different sign */
1587 generate_exception(ctx, EXCP_OVERFLOW);
1589 tcg_temp_free(r_tmp1);
1594 tcg_gen_sub_tl(t0, t0, t1);
1607 tcg_gen_and_tl(t0, t0, t1);
1611 tcg_gen_nor_tl(t0, t0, t1);
1615 tcg_gen_or_tl(t0, t0, t1);
1619 tcg_gen_xor_tl(t0, t0, t1);
1623 tcg_gen_mul_tl(t0, t0, t1);
1624 tcg_gen_ext32s_tl(t0, t0);
1629 int l1 = gen_new_label();
1631 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1632 gen_store_gpr(t0, rd);
1639 int l1 = gen_new_label();
1641 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1642 gen_store_gpr(t0, rd);
1648 tcg_gen_andi_tl(t0, t0, 0x1f);
1649 tcg_gen_shl_tl(t0, t1, t0);
1650 tcg_gen_ext32s_tl(t0, t0);
1654 tcg_gen_ext32s_tl(t1, t1);
1655 tcg_gen_andi_tl(t0, t0, 0x1f);
1656 tcg_gen_sar_tl(t0, t1, t0);
1660 switch ((ctx->opcode >> 6) & 0x1f) {
1662 tcg_gen_ext32u_tl(t1, t1);
1663 tcg_gen_andi_tl(t0, t0, 0x1f);
1664 tcg_gen_shr_tl(t0, t1, t0);
1665 tcg_gen_ext32s_tl(t0, t0);
1669 /* rotrv is decoded as srlv on non-R2 CPUs */
1670 if (env->insn_flags & ISA_MIPS32R2) {
1671 int l1 = gen_new_label();
1672 int l2 = gen_new_label();
1674 tcg_gen_andi_tl(t0, t0, 0x1f);
1675 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1677 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1678 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
1680 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1681 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1682 tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2);
1683 tcg_temp_free_i32(r_tmp1);
1684 tcg_temp_free_i32(r_tmp2);
1688 tcg_gen_mov_tl(t0, t1);
1692 tcg_gen_ext32u_tl(t1, t1);
1693 tcg_gen_andi_tl(t0, t0, 0x1f);
1694 tcg_gen_shr_tl(t0, t1, t0);
1695 tcg_gen_ext32s_tl(t0, t0);
1700 MIPS_INVAL("invalid srlv flag");
1701 generate_exception(ctx, EXCP_RI);
1705 #if defined(TARGET_MIPS64)
1707 tcg_gen_andi_tl(t0, t0, 0x3f);
1708 tcg_gen_shl_tl(t0, t1, t0);
1712 tcg_gen_andi_tl(t0, t0, 0x3f);
1713 tcg_gen_sar_tl(t0, t1, t0);
1717 switch ((ctx->opcode >> 6) & 0x1f) {
1719 tcg_gen_andi_tl(t0, t0, 0x3f);
1720 tcg_gen_shr_tl(t0, t1, t0);
1724 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1725 if (env->insn_flags & ISA_MIPS32R2) {
1726 int l1 = gen_new_label();
1727 int l2 = gen_new_label();
1729 tcg_gen_andi_tl(t0, t0, 0x3f);
1730 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1732 tcg_gen_rotr_tl(t0, t1, t0);
1736 tcg_gen_mov_tl(t0, t1);
1740 tcg_gen_andi_tl(t0, t0, 0x3f);
1741 tcg_gen_shr_tl(t0, t1, t0);
1746 MIPS_INVAL("invalid dsrlv flag");
1747 generate_exception(ctx, EXCP_RI);
1754 generate_exception(ctx, EXCP_RI);
1757 gen_store_gpr(t0, rd);
1759 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1765 /* Arithmetic on HI/LO registers */
1766 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1768 const char *opn = "hilo";
1770 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1777 tcg_gen_mov_tl(cpu_gpr[reg], cpu_HI[0]);
1781 tcg_gen_mov_tl(cpu_gpr[reg], cpu_LO[0]);
1786 tcg_gen_mov_tl(cpu_HI[0], cpu_gpr[reg]);
1788 tcg_gen_movi_tl(cpu_HI[0], 0);
1793 tcg_gen_mov_tl(cpu_LO[0], cpu_gpr[reg]);
1795 tcg_gen_movi_tl(cpu_LO[0], 0);
1800 generate_exception(ctx, EXCP_RI);
1803 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1806 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1809 const char *opn = "mul/div";
1810 TCGv t0 = tcg_temp_local_new();
1811 TCGv t1 = tcg_temp_local_new();
1813 gen_load_gpr(t0, rs);
1814 gen_load_gpr(t1, rt);
1818 int l1 = gen_new_label();
1820 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1822 int l2 = gen_new_label();
1823 TCGv_i32 r_tmp1 = tcg_temp_local_new_i32();
1824 TCGv_i32 r_tmp2 = tcg_temp_local_new_i32();
1825 TCGv_i32 r_tmp3 = tcg_temp_local_new_i32();
1827 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1828 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1829 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp1, -1 << 31, l2);
1830 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp2, -1, l2);
1831 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1832 tcg_gen_movi_tl(cpu_HI[0], 0);
1835 tcg_gen_div_i32(r_tmp3, r_tmp1, r_tmp2);
1836 tcg_gen_rem_i32(r_tmp2, r_tmp1, r_tmp2);
1837 tcg_gen_ext_i32_tl(cpu_LO[0], r_tmp3);
1838 tcg_gen_ext_i32_tl(cpu_HI[0], r_tmp2);
1839 tcg_temp_free_i32(r_tmp1);
1840 tcg_temp_free_i32(r_tmp2);
1841 tcg_temp_free_i32(r_tmp3);
1849 int l1 = gen_new_label();
1851 tcg_gen_ext32s_tl(t1, t1);
1852 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1854 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1855 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
1856 TCGv_i32 r_tmp3 = tcg_temp_new_i32();
1858 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1859 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1860 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1861 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1862 tcg_gen_ext_i32_tl(cpu_LO[0], r_tmp3);
1863 tcg_gen_ext_i32_tl(cpu_HI[0], r_tmp1);
1864 tcg_temp_free_i32(r_tmp1);
1865 tcg_temp_free_i32(r_tmp2);
1866 tcg_temp_free_i32(r_tmp3);
1874 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1875 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1877 tcg_gen_ext_tl_i64(r_tmp1, t0);
1878 tcg_gen_ext_tl_i64(r_tmp2, t1);
1879 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1880 tcg_temp_free_i64(r_tmp2);
1881 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1882 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1883 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1884 tcg_temp_free_i64(r_tmp1);
1885 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1886 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1892 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1893 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1895 tcg_gen_ext32u_tl(t0, t0);
1896 tcg_gen_ext32u_tl(t1, t1);
1897 tcg_gen_extu_tl_i64(r_tmp1, t0);
1898 tcg_gen_extu_tl_i64(r_tmp2, t1);
1899 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1900 tcg_temp_free_i64(r_tmp2);
1901 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1902 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1903 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1904 tcg_temp_free_i64(r_tmp1);
1905 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1906 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1910 #if defined(TARGET_MIPS64)
1913 int l1 = gen_new_label();
1915 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1917 int l2 = gen_new_label();
1919 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
1920 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
1921 tcg_gen_mov_tl(cpu_LO[0], t0);
1922 tcg_gen_movi_tl(cpu_HI[0], 0);
1925 tcg_gen_div_i64(cpu_LO[0], t0, t1);
1926 tcg_gen_rem_i64(cpu_HI[0], t0, t1);
1934 int l1 = gen_new_label();
1936 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1937 tcg_gen_divu_i64(cpu_LO[0], t0, t1);
1938 tcg_gen_remu_i64(cpu_HI[0], t0, t1);
1944 gen_helper_dmult(t0, t1);
1948 gen_helper_dmultu(t0, t1);
1954 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1955 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1957 tcg_gen_ext_tl_i64(r_tmp1, t0);
1958 tcg_gen_ext_tl_i64(r_tmp2, t1);
1959 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1960 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
1961 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
1962 tcg_temp_free_i64(r_tmp2);
1963 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1964 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1965 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1966 tcg_temp_free_i64(r_tmp1);
1967 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1968 tcg_gen_ext32s_tl(cpu_LO[1], t1);
1974 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1975 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1977 tcg_gen_ext32u_tl(t0, t0);
1978 tcg_gen_ext32u_tl(t1, t1);
1979 tcg_gen_extu_tl_i64(r_tmp1, t0);
1980 tcg_gen_extu_tl_i64(r_tmp2, t1);
1981 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1982 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
1983 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
1984 tcg_temp_free_i64(r_tmp2);
1985 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1986 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1987 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1988 tcg_temp_free_i64(r_tmp1);
1989 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1990 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1996 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
1997 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
1999 tcg_gen_ext_tl_i64(r_tmp1, t0);
2000 tcg_gen_ext_tl_i64(r_tmp2, t1);
2001 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2002 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
2003 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2004 tcg_temp_free_i64(r_tmp2);
2005 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2006 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2007 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2008 tcg_temp_free_i64(r_tmp1);
2009 tcg_gen_ext32s_tl(cpu_LO[0], t0);
2010 tcg_gen_ext32s_tl(cpu_HI[0], t1);
2016 TCGv_i64 r_tmp1 = tcg_temp_new_i64();
2017 TCGv_i64 r_tmp2 = tcg_temp_new_i64();
2019 tcg_gen_ext32u_tl(t0, t0);
2020 tcg_gen_ext32u_tl(t1, t1);
2021 tcg_gen_extu_tl_i64(r_tmp1, t0);
2022 tcg_gen_extu_tl_i64(r_tmp2, t1);
2023 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2024 tcg_gen_concat_tl_i64(r_tmp2, cpu_LO[0], cpu_HI[0]);
2025 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2026 tcg_temp_free_i64(r_tmp2);
2027 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2028 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2029 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2030 tcg_temp_free_i64(r_tmp1);
2031 tcg_gen_ext32s_tl(cpu_LO[0], t0);
2032 tcg_gen_ext32s_tl(cpu_HI[0], t1);
2038 generate_exception(ctx, EXCP_RI);
2041 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2047 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2048 int rd, int rs, int rt)
2050 const char *opn = "mul vr54xx";
2051 TCGv t0 = tcg_temp_local_new();
2052 TCGv t1 = tcg_temp_local_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";
2131 TCGv t0 = tcg_temp_local_new();
2138 gen_load_gpr(t0, rs);
2141 gen_helper_clo(t0, t0);
2145 gen_helper_clz(t0, t0);
2148 #if defined(TARGET_MIPS64)
2150 gen_helper_dclo(t0, t0);
2154 gen_helper_dclz(t0, t0);
2160 generate_exception(ctx, EXCP_RI);
2163 gen_store_gpr(t0, rd);
2164 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2171 static void gen_trap (DisasContext *ctx, uint32_t opc,
2172 int rs, int rt, int16_t imm)
2175 TCGv t0 = tcg_temp_local_new();
2176 TCGv t1 = tcg_temp_local_new();
2179 /* Load needed operands */
2187 /* Compare two registers */
2189 gen_load_gpr(t0, rs);
2190 gen_load_gpr(t1, rt);
2200 /* Compare register to immediate */
2201 if (rs != 0 || imm != 0) {
2202 gen_load_gpr(t0, rs);
2203 tcg_gen_movi_tl(t1, (int32_t)imm);
2210 case OPC_TEQ: /* rs == rs */
2211 case OPC_TEQI: /* r0 == 0 */
2212 case OPC_TGE: /* rs >= rs */
2213 case OPC_TGEI: /* r0 >= 0 */
2214 case OPC_TGEU: /* rs >= rs unsigned */
2215 case OPC_TGEIU: /* r0 >= 0 unsigned */
2217 tcg_gen_movi_tl(t0, 1);
2219 case OPC_TLT: /* rs < rs */
2220 case OPC_TLTI: /* r0 < 0 */
2221 case OPC_TLTU: /* rs < rs unsigned */
2222 case OPC_TLTIU: /* r0 < 0 unsigned */
2223 case OPC_TNE: /* rs != rs */
2224 case OPC_TNEI: /* r0 != 0 */
2225 /* Never trap: treat as NOP. */
2229 generate_exception(ctx, EXCP_RI);
2260 generate_exception(ctx, EXCP_RI);
2264 save_cpu_state(ctx, 1);
2266 int l1 = gen_new_label();
2268 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2269 gen_helper_0i(raise_exception, EXCP_TRAP);
2272 ctx->bstate = BS_STOP;
2278 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2280 TranslationBlock *tb;
2282 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2285 tcg_gen_exit_tb((long)tb + n);
2292 /* Branches (before delay slot) */
2293 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2294 int rs, int rt, int32_t offset)
2296 target_ulong btgt = -1;
2298 int bcond_compute = 0;
2299 TCGv t0 = tcg_temp_local_new();
2300 TCGv t1 = tcg_temp_local_new();
2302 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2303 #ifdef MIPS_DEBUG_DISAS
2304 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx "\n", ctx->pc);
2306 generate_exception(ctx, EXCP_RI);
2310 /* Load needed operands */
2316 /* Compare two registers */
2318 gen_load_gpr(t0, rs);
2319 gen_load_gpr(t1, rt);
2322 btgt = ctx->pc + 4 + offset;
2336 /* Compare to zero */
2338 gen_load_gpr(t0, rs);
2341 btgt = ctx->pc + 4 + offset;
2345 /* Jump to immediate */
2346 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2350 /* Jump to register */
2351 if (offset != 0 && offset != 16) {
2352 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2353 others are reserved. */
2354 MIPS_INVAL("jump hint");
2355 generate_exception(ctx, EXCP_RI);
2358 gen_load_gpr(btarget, rs);
2361 MIPS_INVAL("branch/jump");
2362 generate_exception(ctx, EXCP_RI);
2365 if (bcond_compute == 0) {
2366 /* No condition to be computed */
2368 case OPC_BEQ: /* rx == rx */
2369 case OPC_BEQL: /* rx == rx likely */
2370 case OPC_BGEZ: /* 0 >= 0 */
2371 case OPC_BGEZL: /* 0 >= 0 likely */
2372 case OPC_BLEZ: /* 0 <= 0 */
2373 case OPC_BLEZL: /* 0 <= 0 likely */
2375 ctx->hflags |= MIPS_HFLAG_B;
2376 MIPS_DEBUG("balways");
2378 case OPC_BGEZAL: /* 0 >= 0 */
2379 case OPC_BGEZALL: /* 0 >= 0 likely */
2380 /* Always take and link */
2382 ctx->hflags |= MIPS_HFLAG_B;
2383 MIPS_DEBUG("balways and link");
2385 case OPC_BNE: /* rx != rx */
2386 case OPC_BGTZ: /* 0 > 0 */
2387 case OPC_BLTZ: /* 0 < 0 */
2389 MIPS_DEBUG("bnever (NOP)");
2391 case OPC_BLTZAL: /* 0 < 0 */
2392 tcg_gen_movi_tl(t0, ctx->pc + 8);
2393 gen_store_gpr(t0, 31);
2394 MIPS_DEBUG("bnever and link");
2396 case OPC_BLTZALL: /* 0 < 0 likely */
2397 tcg_gen_movi_tl(t0, ctx->pc + 8);
2398 gen_store_gpr(t0, 31);
2399 /* Skip the instruction in the delay slot */
2400 MIPS_DEBUG("bnever, link and skip");
2403 case OPC_BNEL: /* rx != rx likely */
2404 case OPC_BGTZL: /* 0 > 0 likely */
2405 case OPC_BLTZL: /* 0 < 0 likely */
2406 /* Skip the instruction in the delay slot */
2407 MIPS_DEBUG("bnever and skip");
2411 ctx->hflags |= MIPS_HFLAG_B;
2412 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2416 ctx->hflags |= MIPS_HFLAG_B;
2417 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2420 ctx->hflags |= MIPS_HFLAG_BR;
2421 MIPS_DEBUG("jr %s", regnames[rs]);
2425 ctx->hflags |= MIPS_HFLAG_BR;
2426 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2429 MIPS_INVAL("branch/jump");
2430 generate_exception(ctx, EXCP_RI);
2437 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2438 regnames[rs], regnames[rt], btgt);
2442 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2443 regnames[rs], regnames[rt], btgt);
2447 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2448 regnames[rs], regnames[rt], btgt);
2452 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2453 regnames[rs], regnames[rt], btgt);
2457 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2461 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2465 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2471 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2475 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2479 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2483 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2487 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2491 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2495 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2500 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2502 ctx->hflags |= MIPS_HFLAG_BC;
2503 tcg_gen_trunc_tl_i32(bcond, t0);
2508 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2510 ctx->hflags |= MIPS_HFLAG_BL;
2511 tcg_gen_trunc_tl_i32(bcond, t0);
2514 MIPS_INVAL("conditional branch/jump");
2515 generate_exception(ctx, EXCP_RI);
2519 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2520 blink, ctx->hflags, btgt);
2522 ctx->btarget = btgt;
2524 tcg_gen_movi_tl(t0, ctx->pc + 8);
2525 gen_store_gpr(t0, blink);
2533 /* special3 bitfield operations */
2534 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2535 int rs, int lsb, int msb)
2537 TCGv t0 = tcg_temp_new();
2538 TCGv t1 = tcg_temp_new();
2541 gen_load_gpr(t1, rs);
2546 tcg_gen_shri_tl(t0, t1, lsb);
2548 tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
2550 tcg_gen_ext32s_tl(t0, t0);
2553 #if defined(TARGET_MIPS64)
2555 tcg_gen_shri_tl(t0, t1, lsb);
2557 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
2561 tcg_gen_shri_tl(t0, t1, lsb + 32);
2562 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2565 tcg_gen_shri_tl(t0, t1, lsb);
2566 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2572 mask = ((msb - lsb + 1 < 32) ? ((1 << (msb - lsb + 1)) - 1) : ~0) << lsb;
2573 gen_load_gpr(t0, rt);
2574 tcg_gen_andi_tl(t0, t0, ~mask);
2575 tcg_gen_shli_tl(t1, t1, lsb);
2576 tcg_gen_andi_tl(t1, t1, mask);
2577 tcg_gen_or_tl(t0, t0, t1);
2578 tcg_gen_ext32s_tl(t0, t0);
2580 #if defined(TARGET_MIPS64)
2584 mask = ((msb - lsb + 1 + 32 < 64) ? ((1ULL << (msb - lsb + 1 + 32)) - 1) : ~0ULL) << lsb;
2585 gen_load_gpr(t0, rt);
2586 tcg_gen_andi_tl(t0, t0, ~mask);
2587 tcg_gen_shli_tl(t1, t1, lsb);
2588 tcg_gen_andi_tl(t1, t1, mask);
2589 tcg_gen_or_tl(t0, t0, t1);
2594 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2595 gen_load_gpr(t0, rt);
2596 tcg_gen_andi_tl(t0, t0, ~mask);
2597 tcg_gen_shli_tl(t1, t1, lsb + 32);
2598 tcg_gen_andi_tl(t1, t1, mask);
2599 tcg_gen_or_tl(t0, t0, t1);
2604 gen_load_gpr(t0, rt);
2605 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2606 gen_load_gpr(t0, rt);
2607 tcg_gen_andi_tl(t0, t0, ~mask);
2608 tcg_gen_shli_tl(t1, t1, lsb);
2609 tcg_gen_andi_tl(t1, t1, mask);
2610 tcg_gen_or_tl(t0, t0, t1);
2615 MIPS_INVAL("bitops");
2616 generate_exception(ctx, EXCP_RI);
2621 gen_store_gpr(t0, rt);
2626 static void gen_bshfl (DisasContext *ctx, uint32_t op2, int rt, int rd)
2628 TCGv t0 = tcg_temp_new();
2629 TCGv t1 = tcg_temp_new();
2631 gen_load_gpr(t1, rt);
2634 tcg_gen_shri_tl(t0, t1, 8);
2635 tcg_gen_andi_tl(t0, t0, 0x00FF00FF);
2636 tcg_gen_shli_tl(t1, t1, 8);
2637 tcg_gen_andi_tl(t1, t1, ~0x00FF00FF);
2638 tcg_gen_or_tl(t0, t0, t1);
2639 tcg_gen_ext32s_tl(t0, t0);
2642 tcg_gen_ext8s_tl(t0, t1);
2645 tcg_gen_ext16s_tl(t0, t1);
2647 #if defined(TARGET_MIPS64)
2649 gen_load_gpr(t1, rt);
2650 tcg_gen_shri_tl(t0, t1, 8);
2651 tcg_gen_andi_tl(t0, t0, 0x00FF00FF00FF00FFULL);
2652 tcg_gen_shli_tl(t1, t1, 8);
2653 tcg_gen_andi_tl(t1, t1, ~0x00FF00FF00FF00FFULL);
2654 tcg_gen_or_tl(t0, t0, t1);
2657 gen_load_gpr(t1, rt);
2658 tcg_gen_shri_tl(t0, t1, 16);
2659 tcg_gen_andi_tl(t0, t0, 0x0000FFFF0000FFFFULL);
2660 tcg_gen_shli_tl(t1, t1, 16);
2661 tcg_gen_andi_tl(t1, t1, ~0x0000FFFF0000FFFFULL);
2662 tcg_gen_or_tl(t1, t0, t1);
2663 tcg_gen_shri_tl(t0, t1, 32);
2664 tcg_gen_shli_tl(t1, t1, 32);
2665 tcg_gen_or_tl(t0, t0, t1);
2669 MIPS_INVAL("bsfhl");
2670 generate_exception(ctx, EXCP_RI);
2675 gen_store_gpr(t0, rd);
2680 #ifndef CONFIG_USER_ONLY
2681 /* CP0 (MMU and control) */
2682 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2684 TCGv_i32 r_tmp = tcg_temp_new_i32();
2686 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2687 tcg_gen_ext_i32_tl(t, r_tmp);
2688 tcg_temp_free_i32(r_tmp);
2691 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2693 tcg_gen_ld_tl(t, cpu_env, off);
2694 tcg_gen_ext32s_tl(t, t);
2697 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2699 TCGv_i32 r_tmp = tcg_temp_new_i32();
2701 tcg_gen_trunc_tl_i32(r_tmp, t);
2702 tcg_gen_st_i32(r_tmp, cpu_env, off);
2703 tcg_temp_free_i32(r_tmp);
2706 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2708 tcg_gen_ext32s_tl(t, t);
2709 tcg_gen_st_tl(t, cpu_env, off);
2712 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2714 const char *rn = "invalid";
2717 check_insn(env, ctx, ISA_MIPS32);
2723 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2727 check_insn(env, ctx, ASE_MT);
2728 gen_helper_mfc0_mvpcontrol(t0);
2732 check_insn(env, ctx, ASE_MT);
2733 gen_helper_mfc0_mvpconf0(t0);
2737 check_insn(env, ctx, ASE_MT);
2738 gen_helper_mfc0_mvpconf1(t0);
2748 gen_helper_mfc0_random(t0);
2752 check_insn(env, ctx, ASE_MT);
2753 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2757 check_insn(env, ctx, ASE_MT);
2758 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2762 check_insn(env, ctx, ASE_MT);
2763 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2767 check_insn(env, ctx, ASE_MT);
2768 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2772 check_insn(env, ctx, ASE_MT);
2773 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2777 check_insn(env, ctx, ASE_MT);
2778 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2779 rn = "VPEScheFBack";
2782 check_insn(env, ctx, ASE_MT);
2783 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2793 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2794 tcg_gen_ext32s_tl(t0, t0);
2798 check_insn(env, ctx, ASE_MT);
2799 gen_helper_mfc0_tcstatus(t0);
2803 check_insn(env, ctx, ASE_MT);
2804 gen_helper_mfc0_tcbind(t0);
2808 check_insn(env, ctx, ASE_MT);
2809 gen_helper_mfc0_tcrestart(t0);
2813 check_insn(env, ctx, ASE_MT);
2814 gen_helper_mfc0_tchalt(t0);
2818 check_insn(env, ctx, ASE_MT);
2819 gen_helper_mfc0_tccontext(t0);
2823 check_insn(env, ctx, ASE_MT);
2824 gen_helper_mfc0_tcschedule(t0);
2828 check_insn(env, ctx, ASE_MT);
2829 gen_helper_mfc0_tcschefback(t0);
2839 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2840 tcg_gen_ext32s_tl(t0, t0);
2850 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2851 tcg_gen_ext32s_tl(t0, t0);
2855 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2856 rn = "ContextConfig";
2865 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2869 check_insn(env, ctx, ISA_MIPS32R2);
2870 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2880 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2884 check_insn(env, ctx, ISA_MIPS32R2);
2885 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2889 check_insn(env, ctx, ISA_MIPS32R2);
2890 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2894 check_insn(env, ctx, ISA_MIPS32R2);
2895 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2899 check_insn(env, ctx, ISA_MIPS32R2);
2900 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2904 check_insn(env, ctx, ISA_MIPS32R2);
2905 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2915 check_insn(env, ctx, ISA_MIPS32R2);
2916 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
2926 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
2927 tcg_gen_ext32s_tl(t0, t0);
2937 /* Mark as an IO operation because we read the time. */
2940 gen_helper_mfc0_count(t0);
2943 ctx->bstate = BS_STOP;
2947 /* 6,7 are implementation dependent */
2955 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
2956 tcg_gen_ext32s_tl(t0, t0);
2966 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
2969 /* 6,7 are implementation dependent */
2977 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
2981 check_insn(env, ctx, ISA_MIPS32R2);
2982 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
2986 check_insn(env, ctx, ISA_MIPS32R2);
2987 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
2991 check_insn(env, ctx, ISA_MIPS32R2);
2992 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3002 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3012 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3013 tcg_gen_ext32s_tl(t0, t0);
3023 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3027 check_insn(env, ctx, ISA_MIPS32R2);
3028 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3038 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3042 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3046 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3050 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3053 /* 4,5 are reserved */
3054 /* 6,7 are implementation dependent */
3056 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3060 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3070 gen_helper_mfc0_lladdr(t0);
3080 gen_helper_1i(mfc0_watchlo, t0, sel);
3090 gen_helper_1i(mfc0_watchhi, t0, sel);
3100 #if defined(TARGET_MIPS64)
3101 check_insn(env, ctx, ISA_MIPS3);
3102 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3103 tcg_gen_ext32s_tl(t0, t0);
3112 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3115 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3123 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3124 rn = "'Diagnostic"; /* implementation dependent */
3129 gen_helper_mfc0_debug(t0); /* EJTAG support */
3133 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3134 rn = "TraceControl";
3137 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3138 rn = "TraceControl2";
3141 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3142 rn = "UserTraceData";
3145 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3156 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3157 tcg_gen_ext32s_tl(t0, t0);
3167 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3168 rn = "Performance0";
3171 // gen_helper_mfc0_performance1(t0);
3172 rn = "Performance1";
3175 // gen_helper_mfc0_performance2(t0);
3176 rn = "Performance2";
3179 // gen_helper_mfc0_performance3(t0);
3180 rn = "Performance3";
3183 // gen_helper_mfc0_performance4(t0);
3184 rn = "Performance4";
3187 // gen_helper_mfc0_performance5(t0);
3188 rn = "Performance5";
3191 // gen_helper_mfc0_performance6(t0);
3192 rn = "Performance6";
3195 // gen_helper_mfc0_performance7(t0);
3196 rn = "Performance7";
3203 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3209 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3222 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3229 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3242 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3249 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3259 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3260 tcg_gen_ext32s_tl(t0, t0);
3271 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3281 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3285 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3286 generate_exception(ctx, EXCP_RI);
3289 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3291 const char *rn = "invalid";
3294 check_insn(env, ctx, ISA_MIPS32);
3303 gen_helper_mtc0_index(t0);
3307 check_insn(env, ctx, ASE_MT);
3308 gen_helper_mtc0_mvpcontrol(t0);
3312 check_insn(env, ctx, ASE_MT);
3317 check_insn(env, ctx, ASE_MT);
3332 check_insn(env, ctx, ASE_MT);
3333 gen_helper_mtc0_vpecontrol(t0);
3337 check_insn(env, ctx, ASE_MT);
3338 gen_helper_mtc0_vpeconf0(t0);
3342 check_insn(env, ctx, ASE_MT);
3343 gen_helper_mtc0_vpeconf1(t0);
3347 check_insn(env, ctx, ASE_MT);
3348 gen_helper_mtc0_yqmask(t0);
3352 check_insn(env, ctx, ASE_MT);
3353 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3357 check_insn(env, ctx, ASE_MT);
3358 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3359 rn = "VPEScheFBack";
3362 check_insn(env, ctx, ASE_MT);
3363 gen_helper_mtc0_vpeopt(t0);
3373 gen_helper_mtc0_entrylo0(t0);
3377 check_insn(env, ctx, ASE_MT);
3378 gen_helper_mtc0_tcstatus(t0);
3382 check_insn(env, ctx, ASE_MT);
3383 gen_helper_mtc0_tcbind(t0);
3387 check_insn(env, ctx, ASE_MT);
3388 gen_helper_mtc0_tcrestart(t0);
3392 check_insn(env, ctx, ASE_MT);
3393 gen_helper_mtc0_tchalt(t0);
3397 check_insn(env, ctx, ASE_MT);
3398 gen_helper_mtc0_tccontext(t0);
3402 check_insn(env, ctx, ASE_MT);
3403 gen_helper_mtc0_tcschedule(t0);
3407 check_insn(env, ctx, ASE_MT);
3408 gen_helper_mtc0_tcschefback(t0);
3418 gen_helper_mtc0_entrylo1(t0);
3428 gen_helper_mtc0_context(t0);
3432 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3433 rn = "ContextConfig";
3442 gen_helper_mtc0_pagemask(t0);
3446 check_insn(env, ctx, ISA_MIPS32R2);
3447 gen_helper_mtc0_pagegrain(t0);
3457 gen_helper_mtc0_wired(t0);
3461 check_insn(env, ctx, ISA_MIPS32R2);
3462 gen_helper_mtc0_srsconf0(t0);
3466 check_insn(env, ctx, ISA_MIPS32R2);
3467 gen_helper_mtc0_srsconf1(t0);
3471 check_insn(env, ctx, ISA_MIPS32R2);
3472 gen_helper_mtc0_srsconf2(t0);
3476 check_insn(env, ctx, ISA_MIPS32R2);
3477 gen_helper_mtc0_srsconf3(t0);
3481 check_insn(env, ctx, ISA_MIPS32R2);
3482 gen_helper_mtc0_srsconf4(t0);
3492 check_insn(env, ctx, ISA_MIPS32R2);
3493 gen_helper_mtc0_hwrena(t0);
3507 gen_helper_mtc0_count(t0);
3510 /* 6,7 are implementation dependent */
3514 /* Stop translation as we may have switched the execution mode */
3515 ctx->bstate = BS_STOP;
3520 gen_helper_mtc0_entryhi(t0);
3530 gen_helper_mtc0_compare(t0);
3533 /* 6,7 are implementation dependent */
3537 /* Stop translation as we may have switched the execution mode */
3538 ctx->bstate = BS_STOP;
3543 gen_helper_mtc0_status(t0);
3544 /* BS_STOP isn't good enough here, hflags may have changed. */
3545 gen_save_pc(ctx->pc + 4);
3546 ctx->bstate = BS_EXCP;
3550 check_insn(env, ctx, ISA_MIPS32R2);
3551 gen_helper_mtc0_intctl(t0);
3552 /* Stop translation as we may have switched the execution mode */
3553 ctx->bstate = BS_STOP;
3557 check_insn(env, ctx, ISA_MIPS32R2);
3558 gen_helper_mtc0_srsctl(t0);
3559 /* Stop translation as we may have switched the execution mode */
3560 ctx->bstate = BS_STOP;
3564 check_insn(env, ctx, ISA_MIPS32R2);
3565 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3566 /* Stop translation as we may have switched the execution mode */
3567 ctx->bstate = BS_STOP;
3577 gen_helper_mtc0_cause(t0);
3583 /* Stop translation as we may have switched the execution mode */
3584 ctx->bstate = BS_STOP;
3589 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3603 check_insn(env, ctx, ISA_MIPS32R2);
3604 gen_helper_mtc0_ebase(t0);
3614 gen_helper_mtc0_config0(t0);
3616 /* Stop translation as we may have switched the execution mode */
3617 ctx->bstate = BS_STOP;
3620 /* ignored, read only */
3624 gen_helper_mtc0_config2(t0);
3626 /* Stop translation as we may have switched the execution mode */
3627 ctx->bstate = BS_STOP;
3630 /* ignored, read only */
3633 /* 4,5 are reserved */
3634 /* 6,7 are implementation dependent */
3644 rn = "Invalid config selector";
3661 gen_helper_1i(mtc0_watchlo, t0, sel);
3671 gen_helper_1i(mtc0_watchhi, t0, sel);
3681 #if defined(TARGET_MIPS64)
3682 check_insn(env, ctx, ISA_MIPS3);
3683 gen_helper_mtc0_xcontext(t0);
3692 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3695 gen_helper_mtc0_framemask(t0);
3704 rn = "Diagnostic"; /* implementation dependent */
3709 gen_helper_mtc0_debug(t0); /* EJTAG support */
3710 /* BS_STOP isn't good enough here, hflags may have changed. */
3711 gen_save_pc(ctx->pc + 4);
3712 ctx->bstate = BS_EXCP;
3716 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3717 rn = "TraceControl";
3718 /* Stop translation as we may have switched the execution mode */
3719 ctx->bstate = BS_STOP;
3722 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3723 rn = "TraceControl2";
3724 /* Stop translation as we may have switched the execution mode */
3725 ctx->bstate = BS_STOP;
3728 /* Stop translation as we may have switched the execution mode */
3729 ctx->bstate = BS_STOP;
3730 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3731 rn = "UserTraceData";
3732 /* Stop translation as we may have switched the execution mode */
3733 ctx->bstate = BS_STOP;
3736 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3737 /* Stop translation as we may have switched the execution mode */
3738 ctx->bstate = BS_STOP;
3749 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3759 gen_helper_mtc0_performance0(t0);
3760 rn = "Performance0";
3763 // gen_helper_mtc0_performance1(t0);
3764 rn = "Performance1";
3767 // gen_helper_mtc0_performance2(t0);
3768 rn = "Performance2";
3771 // gen_helper_mtc0_performance3(t0);
3772 rn = "Performance3";
3775 // gen_helper_mtc0_performance4(t0);
3776 rn = "Performance4";
3779 // gen_helper_mtc0_performance5(t0);
3780 rn = "Performance5";
3783 // gen_helper_mtc0_performance6(t0);
3784 rn = "Performance6";
3787 // gen_helper_mtc0_performance7(t0);
3788 rn = "Performance7";
3814 gen_helper_mtc0_taglo(t0);
3821 gen_helper_mtc0_datalo(t0);
3834 gen_helper_mtc0_taghi(t0);
3841 gen_helper_mtc0_datahi(t0);
3852 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3863 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3869 /* Stop translation as we may have switched the execution mode */
3870 ctx->bstate = BS_STOP;
3875 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3876 /* For simplicity assume that all writes can cause interrupts. */
3879 ctx->bstate = BS_STOP;
3884 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3885 generate_exception(ctx, EXCP_RI);
3888 #if defined(TARGET_MIPS64)
3889 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3891 const char *rn = "invalid";
3894 check_insn(env, ctx, ISA_MIPS64);
3900 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
3904 check_insn(env, ctx, ASE_MT);
3905 gen_helper_mfc0_mvpcontrol(t0);
3909 check_insn(env, ctx, ASE_MT);
3910 gen_helper_mfc0_mvpconf0(t0);
3914 check_insn(env, ctx, ASE_MT);
3915 gen_helper_mfc0_mvpconf1(t0);
3925 gen_helper_mfc0_random(t0);
3929 check_insn(env, ctx, ASE_MT);
3930 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
3934 check_insn(env, ctx, ASE_MT);
3935 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
3939 check_insn(env, ctx, ASE_MT);
3940 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
3944 check_insn(env, ctx, ASE_MT);
3945 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
3949 check_insn(env, ctx, ASE_MT);
3950 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
3954 check_insn(env, ctx, ASE_MT);
3955 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3956 rn = "VPEScheFBack";
3959 check_insn(env, ctx, ASE_MT);
3960 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
3970 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
3974 check_insn(env, ctx, ASE_MT);
3975 gen_helper_mfc0_tcstatus(t0);
3979 check_insn(env, ctx, ASE_MT);
3980 gen_helper_mfc0_tcbind(t0);
3984 check_insn(env, ctx, ASE_MT);
3985 gen_helper_dmfc0_tcrestart(t0);
3989 check_insn(env, ctx, ASE_MT);
3990 gen_helper_dmfc0_tchalt(t0);
3994 check_insn(env, ctx, ASE_MT);
3995 gen_helper_dmfc0_tccontext(t0);
3999 check_insn(env, ctx, ASE_MT);
4000 gen_helper_dmfc0_tcschedule(t0);
4004 check_insn(env, ctx, ASE_MT);
4005 gen_helper_dmfc0_tcschefback(t0);
4015 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4025 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4029 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4030 rn = "ContextConfig";
4039 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4043 check_insn(env, ctx, ISA_MIPS32R2);
4044 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4054 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4058 check_insn(env, ctx, ISA_MIPS32R2);
4059 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4063 check_insn(env, ctx, ISA_MIPS32R2);
4064 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4068 check_insn(env, ctx, ISA_MIPS32R2);
4069 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4073 check_insn(env, ctx, ISA_MIPS32R2);
4074 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4078 check_insn(env, ctx, ISA_MIPS32R2);
4079 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4089 check_insn(env, ctx, ISA_MIPS32R2);
4090 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4100 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4110 /* Mark as an IO operation because we read the time. */
4113 gen_helper_mfc0_count(t0);
4116 ctx->bstate = BS_STOP;
4120 /* 6,7 are implementation dependent */
4128 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4138 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4141 /* 6,7 are implementation dependent */
4149 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4153 check_insn(env, ctx, ISA_MIPS32R2);
4154 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4158 check_insn(env, ctx, ISA_MIPS32R2);
4159 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4163 check_insn(env, ctx, ISA_MIPS32R2);
4164 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4174 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4184 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4194 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4198 check_insn(env, ctx, ISA_MIPS32R2);
4199 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4209 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4213 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4217 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4221 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4224 /* 6,7 are implementation dependent */
4226 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4230 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4240 gen_helper_dmfc0_lladdr(t0);
4250 gen_helper_1i(dmfc0_watchlo, t0, sel);
4260 gen_helper_1i(mfc0_watchhi, t0, sel);
4270 check_insn(env, ctx, ISA_MIPS3);
4271 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4279 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4282 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4290 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4291 rn = "'Diagnostic"; /* implementation dependent */
4296 gen_helper_mfc0_debug(t0); /* EJTAG support */
4300 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4301 rn = "TraceControl";
4304 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4305 rn = "TraceControl2";
4308 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4309 rn = "UserTraceData";
4312 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4323 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4333 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4334 rn = "Performance0";
4337 // gen_helper_dmfc0_performance1(t0);
4338 rn = "Performance1";
4341 // gen_helper_dmfc0_performance2(t0);
4342 rn = "Performance2";
4345 // gen_helper_dmfc0_performance3(t0);
4346 rn = "Performance3";
4349 // gen_helper_dmfc0_performance4(t0);
4350 rn = "Performance4";
4353 // gen_helper_dmfc0_performance5(t0);
4354 rn = "Performance5";
4357 // gen_helper_dmfc0_performance6(t0);
4358 rn = "Performance6";
4361 // gen_helper_dmfc0_performance7(t0);
4362 rn = "Performance7";
4369 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4376 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4389 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4396 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4409 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4416 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4426 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4437 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4447 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4451 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4452 generate_exception(ctx, EXCP_RI);
4455 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4457 const char *rn = "invalid";
4460 check_insn(env, ctx, ISA_MIPS64);
4469 gen_helper_mtc0_index(t0);
4473 check_insn(env, ctx, ASE_MT);
4474 gen_helper_mtc0_mvpcontrol(t0);
4478 check_insn(env, ctx, ASE_MT);
4483 check_insn(env, ctx, ASE_MT);
4498 check_insn(env, ctx, ASE_MT);
4499 gen_helper_mtc0_vpecontrol(t0);
4503 check_insn(env, ctx, ASE_MT);
4504 gen_helper_mtc0_vpeconf0(t0);
4508 check_insn(env, ctx, ASE_MT);
4509 gen_helper_mtc0_vpeconf1(t0);
4513 check_insn(env, ctx, ASE_MT);
4514 gen_helper_mtc0_yqmask(t0);
4518 check_insn(env, ctx, ASE_MT);
4519 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4523 check_insn(env, ctx, ASE_MT);
4524 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4525 rn = "VPEScheFBack";
4528 check_insn(env, ctx, ASE_MT);
4529 gen_helper_mtc0_vpeopt(t0);
4539 gen_helper_mtc0_entrylo0(t0);
4543 check_insn(env, ctx, ASE_MT);
4544 gen_helper_mtc0_tcstatus(t0);
4548 check_insn(env, ctx, ASE_MT);
4549 gen_helper_mtc0_tcbind(t0);
4553 check_insn(env, ctx, ASE_MT);
4554 gen_helper_mtc0_tcrestart(t0);
4558 check_insn(env, ctx, ASE_MT);
4559 gen_helper_mtc0_tchalt(t0);
4563 check_insn(env, ctx, ASE_MT);
4564 gen_helper_mtc0_tccontext(t0);
4568 check_insn(env, ctx, ASE_MT);
4569 gen_helper_mtc0_tcschedule(t0);
4573 check_insn(env, ctx, ASE_MT);
4574 gen_helper_mtc0_tcschefback(t0);
4584 gen_helper_mtc0_entrylo1(t0);
4594 gen_helper_mtc0_context(t0);
4598 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4599 rn = "ContextConfig";
4608 gen_helper_mtc0_pagemask(t0);
4612 check_insn(env, ctx, ISA_MIPS32R2);
4613 gen_helper_mtc0_pagegrain(t0);
4623 gen_helper_mtc0_wired(t0);
4627 check_insn(env, ctx, ISA_MIPS32R2);
4628 gen_helper_mtc0_srsconf0(t0);
4632 check_insn(env, ctx, ISA_MIPS32R2);
4633 gen_helper_mtc0_srsconf1(t0);
4637 check_insn(env, ctx, ISA_MIPS32R2);
4638 gen_helper_mtc0_srsconf2(t0);
4642 check_insn(env, ctx, ISA_MIPS32R2);
4643 gen_helper_mtc0_srsconf3(t0);
4647 check_insn(env, ctx, ISA_MIPS32R2);
4648 gen_helper_mtc0_srsconf4(t0);
4658 check_insn(env, ctx, ISA_MIPS32R2);
4659 gen_helper_mtc0_hwrena(t0);
4673 gen_helper_mtc0_count(t0);
4676 /* 6,7 are implementation dependent */
4680 /* Stop translation as we may have switched the execution mode */
4681 ctx->bstate = BS_STOP;
4686 gen_helper_mtc0_entryhi(t0);
4696 gen_helper_mtc0_compare(t0);
4699 /* 6,7 are implementation dependent */
4703 /* Stop translation as we may have switched the execution mode */
4704 ctx->bstate = BS_STOP;
4709 gen_helper_mtc0_status(t0);
4710 /* BS_STOP isn't good enough here, hflags may have changed. */
4711 gen_save_pc(ctx->pc + 4);
4712 ctx->bstate = BS_EXCP;
4716 check_insn(env, ctx, ISA_MIPS32R2);
4717 gen_helper_mtc0_intctl(t0);
4718 /* Stop translation as we may have switched the execution mode */
4719 ctx->bstate = BS_STOP;
4723 check_insn(env, ctx, ISA_MIPS32R2);
4724 gen_helper_mtc0_srsctl(t0);
4725 /* Stop translation as we may have switched the execution mode */
4726 ctx->bstate = BS_STOP;
4730 check_insn(env, ctx, ISA_MIPS32R2);
4731 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4732 /* Stop translation as we may have switched the execution mode */
4733 ctx->bstate = BS_STOP;
4743 gen_helper_mtc0_cause(t0);
4749 /* Stop translation as we may have switched the execution mode */
4750 ctx->bstate = BS_STOP;
4755 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4769 check_insn(env, ctx, ISA_MIPS32R2);
4770 gen_helper_mtc0_ebase(t0);
4780 gen_helper_mtc0_config0(t0);
4782 /* Stop translation as we may have switched the execution mode */
4783 ctx->bstate = BS_STOP;
4790 gen_helper_mtc0_config2(t0);
4792 /* Stop translation as we may have switched the execution mode */
4793 ctx->bstate = BS_STOP;
4799 /* 6,7 are implementation dependent */
4801 rn = "Invalid config selector";
4818 gen_helper_1i(mtc0_watchlo, t0, sel);
4828 gen_helper_1i(mtc0_watchhi, t0, sel);
4838 check_insn(env, ctx, ISA_MIPS3);
4839 gen_helper_mtc0_xcontext(t0);
4847 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4850 gen_helper_mtc0_framemask(t0);
4859 rn = "Diagnostic"; /* implementation dependent */
4864 gen_helper_mtc0_debug(t0); /* EJTAG support */
4865 /* BS_STOP isn't good enough here, hflags may have changed. */
4866 gen_save_pc(ctx->pc + 4);
4867 ctx->bstate = BS_EXCP;
4871 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4872 /* Stop translation as we may have switched the execution mode */
4873 ctx->bstate = BS_STOP;
4874 rn = "TraceControl";
4877 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4878 /* Stop translation as we may have switched the execution mode */
4879 ctx->bstate = BS_STOP;
4880 rn = "TraceControl2";
4883 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4884 /* Stop translation as we may have switched the execution mode */
4885 ctx->bstate = BS_STOP;
4886 rn = "UserTraceData";
4889 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4890 /* Stop translation as we may have switched the execution mode */
4891 ctx->bstate = BS_STOP;
4902 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4912 gen_helper_mtc0_performance0(t0);
4913 rn = "Performance0";
4916 // gen_helper_mtc0_performance1(t0);
4917 rn = "Performance1";
4920 // gen_helper_mtc0_performance2(t0);
4921 rn = "Performance2";
4924 // gen_helper_mtc0_performance3(t0);
4925 rn = "Performance3";
4928 // gen_helper_mtc0_performance4(t0);
4929 rn = "Performance4";
4932 // gen_helper_mtc0_performance5(t0);
4933 rn = "Performance5";
4936 // gen_helper_mtc0_performance6(t0);
4937 rn = "Performance6";
4940 // gen_helper_mtc0_performance7(t0);
4941 rn = "Performance7";
4967 gen_helper_mtc0_taglo(t0);
4974 gen_helper_mtc0_datalo(t0);
4987 gen_helper_mtc0_taghi(t0);
4994 gen_helper_mtc0_datahi(t0);
5005 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5016 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5022 /* Stop translation as we may have switched the execution mode */
5023 ctx->bstate = BS_STOP;
5028 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5029 /* For simplicity assume that all writes can cause interrupts. */
5032 ctx->bstate = BS_STOP;
5037 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5038 generate_exception(ctx, EXCP_RI);
5040 #endif /* TARGET_MIPS64 */
5042 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5043 int u, int sel, int h)
5045 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5046 TCGv t0 = tcg_temp_local_new();
5048 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5049 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5050 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5051 tcg_gen_movi_tl(t0, -1);
5052 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5053 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5054 tcg_gen_movi_tl(t0, -1);
5060 gen_helper_mftc0_tcstatus(t0);
5063 gen_helper_mftc0_tcbind(t0);
5066 gen_helper_mftc0_tcrestart(t0);
5069 gen_helper_mftc0_tchalt(t0);
5072 gen_helper_mftc0_tccontext(t0);
5075 gen_helper_mftc0_tcschedule(t0);
5078 gen_helper_mftc0_tcschefback(t0);
5081 gen_mfc0(env, ctx, t0, rt, sel);
5088 gen_helper_mftc0_entryhi(t0);
5091 gen_mfc0(env, ctx, t0, rt, sel);
5097 gen_helper_mftc0_status(t0);
5100 gen_mfc0(env, ctx, t0, rt, sel);
5106 gen_helper_mftc0_debug(t0);
5109 gen_mfc0(env, ctx, t0, rt, sel);
5114 gen_mfc0(env, ctx, t0, rt, sel);
5116 } else switch (sel) {
5117 /* GPR registers. */
5119 gen_helper_1i(mftgpr, t0, rt);
5121 /* Auxiliary CPU registers */
5125 gen_helper_1i(mftlo, t0, 0);
5128 gen_helper_1i(mfthi, t0, 0);
5131 gen_helper_1i(mftacx, t0, 0);
5134 gen_helper_1i(mftlo, t0, 1);
5137 gen_helper_1i(mfthi, t0, 1);
5140 gen_helper_1i(mftacx, t0, 1);
5143 gen_helper_1i(mftlo, t0, 2);
5146 gen_helper_1i(mfthi, t0, 2);
5149 gen_helper_1i(mftacx, t0, 2);
5152 gen_helper_1i(mftlo, t0, 3);
5155 gen_helper_1i(mfthi, t0, 3);
5158 gen_helper_1i(mftacx, t0, 3);
5161 gen_helper_mftdsp(t0);
5167 /* Floating point (COP1). */
5169 /* XXX: For now we support only a single FPU context. */
5171 TCGv_i32 fp0 = tcg_temp_new_i32();
5173 gen_load_fpr32(fp0, rt);
5174 tcg_gen_ext_i32_tl(t0, fp0);
5175 tcg_temp_free_i32(fp0);
5177 TCGv_i32 fp0 = tcg_temp_new_i32();
5179 gen_load_fpr32h(fp0, rt);
5180 tcg_gen_ext_i32_tl(t0, fp0);
5181 tcg_temp_free_i32(fp0);
5185 /* XXX: For now we support only a single FPU context. */
5186 gen_helper_1i(cfc1, t0, rt);
5188 /* COP2: Not implemented. */
5195 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5196 gen_store_gpr(t0, rd);
5202 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5203 generate_exception(ctx, EXCP_RI);
5206 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5207 int u, int sel, int h)
5209 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5210 TCGv t0 = tcg_temp_local_new();
5212 gen_load_gpr(t0, rt);
5213 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5214 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5215 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5217 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5218 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5225 gen_helper_mttc0_tcstatus(t0);
5228 gen_helper_mttc0_tcbind(t0);
5231 gen_helper_mttc0_tcrestart(t0);
5234 gen_helper_mttc0_tchalt(t0);
5237 gen_helper_mttc0_tccontext(t0);
5240 gen_helper_mttc0_tcschedule(t0);
5243 gen_helper_mttc0_tcschefback(t0);
5246 gen_mtc0(env, ctx, t0, rd, sel);
5253 gen_helper_mttc0_entryhi(t0);
5256 gen_mtc0(env, ctx, t0, rd, sel);
5262 gen_helper_mttc0_status(t0);
5265 gen_mtc0(env, ctx, t0, rd, sel);
5271 gen_helper_mttc0_debug(t0);
5274 gen_mtc0(env, ctx, t0, rd, sel);
5279 gen_mtc0(env, ctx, t0, rd, sel);
5281 } else switch (sel) {
5282 /* GPR registers. */
5284 gen_helper_1i(mttgpr, t0, rd);
5286 /* Auxiliary CPU registers */
5290 gen_helper_1i(mttlo, t0, 0);
5293 gen_helper_1i(mtthi, t0, 0);
5296 gen_helper_1i(mttacx, t0, 0);
5299 gen_helper_1i(mttlo, t0, 1);
5302 gen_helper_1i(mtthi, t0, 1);
5305 gen_helper_1i(mttacx, t0, 1);
5308 gen_helper_1i(mttlo, t0, 2);
5311 gen_helper_1i(mtthi, t0, 2);
5314 gen_helper_1i(mttacx, t0, 2);
5317 gen_helper_1i(mttlo, t0, 3);
5320 gen_helper_1i(mtthi, t0, 3);
5323 gen_helper_1i(mttacx, t0, 3);
5326 gen_helper_mttdsp(t0);
5332 /* Floating point (COP1). */
5334 /* XXX: For now we support only a single FPU context. */
5336 TCGv_i32 fp0 = tcg_temp_new_i32();
5338 tcg_gen_trunc_tl_i32(fp0, t0);
5339 gen_store_fpr32(fp0, rd);
5340 tcg_temp_free_i32(fp0);
5342 TCGv_i32 fp0 = tcg_temp_new_i32();
5344 tcg_gen_trunc_tl_i32(fp0, t0);
5345 gen_store_fpr32h(fp0, rd);
5346 tcg_temp_free_i32(fp0);
5350 /* XXX: For now we support only a single FPU context. */
5351 gen_helper_1i(ctc1, t0, rd);
5353 /* COP2: Not implemented. */
5360 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5366 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5367 generate_exception(ctx, EXCP_RI);
5370 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5372 const char *opn = "ldst";
5381 TCGv t0 = tcg_temp_local_new();
5383 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5384 gen_store_gpr(t0, rt);
5391 TCGv t0 = tcg_temp_local_new();
5393 gen_load_gpr(t0, rt);
5394 save_cpu_state(ctx, 1);
5395 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5400 #if defined(TARGET_MIPS64)
5402 check_insn(env, ctx, ISA_MIPS3);
5408 TCGv t0 = tcg_temp_local_new();
5410 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5411 gen_store_gpr(t0, rt);
5417 check_insn(env, ctx, ISA_MIPS3);
5419 TCGv t0 = tcg_temp_local_new();
5421 gen_load_gpr(t0, rt);
5422 save_cpu_state(ctx, 1);
5423 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5430 check_insn(env, ctx, ASE_MT);
5435 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5436 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5440 check_insn(env, ctx, ASE_MT);
5441 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5442 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5447 if (!env->tlb->helper_tlbwi)
5453 if (!env->tlb->helper_tlbwr)
5459 if (!env->tlb->helper_tlbp)
5465 if (!env->tlb->helper_tlbr)
5471 check_insn(env, ctx, ISA_MIPS2);
5472 save_cpu_state(ctx, 1);
5474 ctx->bstate = BS_EXCP;
5478 check_insn(env, ctx, ISA_MIPS32);
5479 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5481 generate_exception(ctx, EXCP_RI);
5483 save_cpu_state(ctx, 1);
5485 ctx->bstate = BS_EXCP;
5490 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5491 /* If we get an exception, we want to restart at next instruction */
5493 save_cpu_state(ctx, 1);
5496 ctx->bstate = BS_EXCP;
5501 generate_exception(ctx, EXCP_RI);
5504 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5506 #endif /* !CONFIG_USER_ONLY */
5508 /* CP1 Branches (before delay slot) */
5509 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5510 int32_t cc, int32_t offset)
5512 target_ulong btarget;
5513 const char *opn = "cp1 cond branch";
5514 TCGv_i32 t0 = tcg_temp_new_i32();
5517 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5519 btarget = ctx->pc + 4 + offset;
5524 int l1 = gen_new_label();
5525 int l2 = gen_new_label();
5528 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5529 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5530 tcg_gen_movi_i32(bcond, 0);
5533 tcg_gen_movi_i32(bcond, 1);
5540 int l1 = gen_new_label();
5541 int l2 = gen_new_label();
5544 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5545 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5546 tcg_gen_movi_i32(bcond, 0);
5549 tcg_gen_movi_i32(bcond, 1);
5556 int l1 = gen_new_label();
5557 int l2 = gen_new_label();
5560 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5561 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5562 tcg_gen_movi_i32(bcond, 0);
5565 tcg_gen_movi_i32(bcond, 1);
5572 int l1 = gen_new_label();
5573 int l2 = gen_new_label();
5576 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5577 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5578 tcg_gen_movi_i32(bcond, 0);
5581 tcg_gen_movi_i32(bcond, 1);
5586 ctx->hflags |= MIPS_HFLAG_BL;
5590 int l1 = gen_new_label();
5591 int l2 = gen_new_label();
5594 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5595 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5596 tcg_gen_movi_i32(bcond, 0);
5599 tcg_gen_movi_i32(bcond, 1);
5606 int l1 = gen_new_label();
5607 int l2 = gen_new_label();
5610 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5611 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5612 tcg_gen_movi_i32(bcond, 0);
5615 tcg_gen_movi_i32(bcond, 1);
5622 int l1 = gen_new_label();
5623 int l2 = gen_new_label();
5626 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5627 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5628 tcg_gen_movi_i32(bcond, 0);
5631 tcg_gen_movi_i32(bcond, 1);
5638 int l1 = gen_new_label();
5639 int l2 = gen_new_label();
5642 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5643 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5644 tcg_gen_movi_i32(bcond, 0);
5647 tcg_gen_movi_i32(bcond, 1);
5652 ctx->hflags |= MIPS_HFLAG_BC;
5656 generate_exception (ctx, EXCP_RI);
5659 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5660 ctx->hflags, btarget);
5661 ctx->btarget = btarget;
5664 tcg_temp_free_i32(t0);
5667 /* Coprocessor 1 (FPU) */
5669 #define FOP(func, fmt) (((fmt) << 21) | (func))
5671 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5673 const char *opn = "cp1 move";
5674 TCGv t0 = tcg_temp_local_new();
5679 TCGv_i32 fp0 = tcg_temp_new_i32();
5681 gen_load_fpr32(fp0, fs);
5682 tcg_gen_ext_i32_tl(t0, fp0);
5683 tcg_temp_free_i32(fp0);
5685 gen_store_gpr(t0, rt);
5689 gen_load_gpr(t0, rt);
5691 TCGv_i32 fp0 = tcg_temp_new_i32();
5693 tcg_gen_trunc_tl_i32(fp0, t0);
5694 gen_store_fpr32(fp0, fs);
5695 tcg_temp_free_i32(fp0);
5700 gen_helper_1i(cfc1, t0, fs);
5701 gen_store_gpr(t0, rt);
5705 gen_load_gpr(t0, rt);
5706 gen_helper_1i(ctc1, t0, fs);
5711 TCGv_i64 fp0 = tcg_temp_new_i64();
5713 gen_load_fpr64(ctx, fp0, fs);
5714 tcg_gen_trunc_i64_tl(t0, fp0);
5715 tcg_temp_free_i64(fp0);
5717 gen_store_gpr(t0, rt);
5721 gen_load_gpr(t0, rt);
5723 TCGv_i64 fp0 = tcg_temp_new_i64();
5725 tcg_gen_extu_tl_i64(fp0, t0);
5726 gen_store_fpr64(ctx, fp0, fs);
5727 tcg_temp_free_i64(fp0);
5733 TCGv_i32 fp0 = tcg_temp_new_i32();
5735 gen_load_fpr32h(fp0, fs);
5736 tcg_gen_ext_i32_tl(t0, fp0);
5737 tcg_temp_free_i32(fp0);
5739 gen_store_gpr(t0, rt);
5743 gen_load_gpr(t0, rt);
5745 TCGv_i32 fp0 = tcg_temp_new_i32();
5747 tcg_gen_trunc_tl_i32(fp0, t0);
5748 gen_store_fpr32h(fp0, fs);
5749 tcg_temp_free_i32(fp0);
5755 generate_exception (ctx, EXCP_RI);
5758 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5764 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5766 int l1 = gen_new_label();
5769 TCGv t0 = tcg_temp_local_new();
5770 TCGv_i32 r_tmp = tcg_temp_new_i32();
5773 ccbit = 1 << (24 + cc);
5781 gen_load_gpr(t0, rd);
5782 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5783 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5784 tcg_temp_free_i32(r_tmp);
5785 gen_load_gpr(t0, rs);
5787 gen_store_gpr(t0, rd);
5791 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5795 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5796 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5797 int l1 = gen_new_label();
5800 ccbit = 1 << (24 + cc);
5809 gen_load_fpr32(fp0, fd);
5810 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5811 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5812 tcg_temp_free_i32(r_tmp1);
5813 gen_load_fpr32(fp0, fs);
5815 gen_store_fpr32(fp0, fd);
5816 tcg_temp_free_i32(fp0);
5819 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
5823 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5824 TCGv_i64 fp0 = tcg_temp_local_new_i64();
5825 int l1 = gen_new_label();
5828 ccbit = 1 << (24 + cc);
5837 gen_load_fpr64(ctx, fp0, fd);
5838 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5839 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5840 tcg_temp_free_i32(r_tmp1);
5841 gen_load_fpr64(ctx, fp0, fs);
5843 gen_store_fpr64(ctx, fp0, fd);
5844 tcg_temp_free_i64(fp0);
5847 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
5849 uint32_t ccbit1, ccbit2;
5851 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5852 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5853 int l1 = gen_new_label();
5854 int l2 = gen_new_label();
5857 ccbit1 = 1 << (24 + cc);
5858 ccbit2 = 1 << (25 + cc);
5869 gen_load_fpr32(fp0, fd);
5870 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit1);
5871 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5872 gen_load_fpr32(fp0, fs);
5874 gen_store_fpr32(fp0, fd);
5876 gen_load_fpr32h(fp0, fd);
5877 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit2);
5878 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l2);
5879 gen_load_fpr32h(fp0, fs);
5881 gen_store_fpr32h(fp0, fd);
5883 tcg_temp_free_i32(r_tmp1);
5884 tcg_temp_free_i32(fp0);
5888 static void gen_farith (DisasContext *ctx, uint32_t op1,
5889 int ft, int fs, int fd, int cc)
5891 const char *opn = "farith";
5892 const char *condnames[] = {
5910 const char *condnames_abs[] = {
5928 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5929 uint32_t func = ctx->opcode & 0x3f;
5931 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5934 TCGv_i32 fp0 = tcg_temp_new_i32();
5935 TCGv_i32 fp1 = tcg_temp_new_i32();
5937 gen_load_fpr32(fp0, fs);
5938 gen_load_fpr32(fp1, ft);
5939 gen_helper_float_add_s(fp0, fp0, fp1);
5940 tcg_temp_free_i32(fp1);
5941 gen_store_fpr32(fp0, fd);
5942 tcg_temp_free_i32(fp0);
5949 TCGv_i32 fp0 = tcg_temp_new_i32();
5950 TCGv_i32 fp1 = tcg_temp_new_i32();
5952 gen_load_fpr32(fp0, fs);
5953 gen_load_fpr32(fp1, ft);
5954 gen_helper_float_sub_s(fp0, fp0, fp1);
5955 tcg_temp_free_i32(fp1);
5956 gen_store_fpr32(fp0, fd);
5957 tcg_temp_free_i32(fp0);
5964 TCGv_i32 fp0 = tcg_temp_new_i32();
5965 TCGv_i32 fp1 = tcg_temp_new_i32();
5967 gen_load_fpr32(fp0, fs);
5968 gen_load_fpr32(fp1, ft);
5969 gen_helper_float_mul_s(fp0, fp0, fp1);
5970 tcg_temp_free_i32(fp1);
5971 gen_store_fpr32(fp0, fd);
5972 tcg_temp_free_i32(fp0);
5979 TCGv_i32 fp0 = tcg_temp_new_i32();
5980 TCGv_i32 fp1 = tcg_temp_new_i32();
5982 gen_load_fpr32(fp0, fs);
5983 gen_load_fpr32(fp1, ft);
5984 gen_helper_float_div_s(fp0, fp0, fp1);
5985 tcg_temp_free_i32(fp1);
5986 gen_store_fpr32(fp0, fd);
5987 tcg_temp_free_i32(fp0);
5994 TCGv_i32 fp0 = tcg_temp_new_i32();
5996 gen_load_fpr32(fp0, fs);
5997 gen_helper_float_sqrt_s(fp0, fp0);
5998 gen_store_fpr32(fp0, fd);
5999 tcg_temp_free_i32(fp0);
6005 TCGv_i32 fp0 = tcg_temp_new_i32();
6007 gen_load_fpr32(fp0, fs);
6008 gen_helper_float_abs_s(fp0, fp0);
6009 gen_store_fpr32(fp0, fd);
6010 tcg_temp_free_i32(fp0);
6016 TCGv_i32 fp0 = tcg_temp_new_i32();
6018 gen_load_fpr32(fp0, fs);
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_helper_float_chs_s(fp0, fp0);
6030 gen_store_fpr32(fp0, fd);
6031 tcg_temp_free_i32(fp0);
6036 check_cp1_64bitmode(ctx);
6038 TCGv_i32 fp32 = tcg_temp_new_i32();
6039 TCGv_i64 fp64 = tcg_temp_new_i64();
6041 gen_load_fpr32(fp32, fs);
6042 gen_helper_float_roundl_s(fp64, fp32);
6043 tcg_temp_free_i32(fp32);
6044 gen_store_fpr64(ctx, fp64, fd);
6045 tcg_temp_free_i64(fp64);
6050 check_cp1_64bitmode(ctx);
6052 TCGv_i32 fp32 = tcg_temp_new_i32();
6053 TCGv_i64 fp64 = tcg_temp_new_i64();
6055 gen_load_fpr32(fp32, fs);
6056 gen_helper_float_truncl_s(fp64, fp32);
6057 tcg_temp_free_i32(fp32);
6058 gen_store_fpr64(ctx, fp64, fd);
6059 tcg_temp_free_i64(fp64);
6064 check_cp1_64bitmode(ctx);
6066 TCGv_i32 fp32 = tcg_temp_new_i32();
6067 TCGv_i64 fp64 = tcg_temp_new_i64();
6069 gen_load_fpr32(fp32, fs);
6070 gen_helper_float_ceill_s(fp64, fp32);
6071 tcg_temp_free_i32(fp32);
6072 gen_store_fpr64(ctx, fp64, fd);
6073 tcg_temp_free_i64(fp64);
6078 check_cp1_64bitmode(ctx);
6080 TCGv_i32 fp32 = tcg_temp_new_i32();
6081 TCGv_i64 fp64 = tcg_temp_new_i64();
6083 gen_load_fpr32(fp32, fs);
6084 gen_helper_float_floorl_s(fp64, fp32);
6085 tcg_temp_free_i32(fp32);
6086 gen_store_fpr64(ctx, fp64, fd);
6087 tcg_temp_free_i64(fp64);
6093 TCGv_i32 fp0 = tcg_temp_new_i32();
6095 gen_load_fpr32(fp0, fs);
6096 gen_helper_float_roundw_s(fp0, fp0);
6097 gen_store_fpr32(fp0, fd);
6098 tcg_temp_free_i32(fp0);
6104 TCGv_i32 fp0 = tcg_temp_new_i32();
6106 gen_load_fpr32(fp0, fs);
6107 gen_helper_float_truncw_s(fp0, fp0);
6108 gen_store_fpr32(fp0, fd);
6109 tcg_temp_free_i32(fp0);
6115 TCGv_i32 fp0 = tcg_temp_new_i32();
6117 gen_load_fpr32(fp0, fs);
6118 gen_helper_float_ceilw_s(fp0, fp0);
6119 gen_store_fpr32(fp0, fd);
6120 tcg_temp_free_i32(fp0);
6126 TCGv_i32 fp0 = tcg_temp_new_i32();
6128 gen_load_fpr32(fp0, fs);
6129 gen_helper_float_floorw_s(fp0, fp0);
6130 gen_store_fpr32(fp0, fd);
6131 tcg_temp_free_i32(fp0);
6136 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6141 int l1 = gen_new_label();
6142 TCGv t0 = tcg_temp_new();
6143 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6145 gen_load_gpr(t0, ft);
6146 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6147 gen_load_fpr32(fp0, fs);
6148 gen_store_fpr32(fp0, fd);
6149 tcg_temp_free_i32(fp0);
6157 int l1 = gen_new_label();
6158 TCGv t0 = tcg_temp_new();
6159 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6161 gen_load_gpr(t0, ft);
6162 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6163 gen_load_fpr32(fp0, fs);
6164 gen_store_fpr32(fp0, fd);
6165 tcg_temp_free_i32(fp0);
6174 TCGv_i32 fp0 = tcg_temp_new_i32();
6176 gen_load_fpr32(fp0, fs);
6177 gen_helper_float_recip_s(fp0, fp0);
6178 gen_store_fpr32(fp0, fd);
6179 tcg_temp_free_i32(fp0);
6186 TCGv_i32 fp0 = tcg_temp_new_i32();
6188 gen_load_fpr32(fp0, fs);
6189 gen_helper_float_rsqrt_s(fp0, fp0);
6190 gen_store_fpr32(fp0, fd);
6191 tcg_temp_free_i32(fp0);
6196 check_cp1_64bitmode(ctx);
6198 TCGv_i32 fp0 = tcg_temp_new_i32();
6199 TCGv_i32 fp1 = tcg_temp_new_i32();
6201 gen_load_fpr32(fp0, fs);
6202 gen_load_fpr32(fp1, fd);
6203 gen_helper_float_recip2_s(fp0, fp0, fp1);
6204 tcg_temp_free_i32(fp1);
6205 gen_store_fpr32(fp0, fd);
6206 tcg_temp_free_i32(fp0);
6211 check_cp1_64bitmode(ctx);
6213 TCGv_i32 fp0 = tcg_temp_new_i32();
6215 gen_load_fpr32(fp0, fs);
6216 gen_helper_float_recip1_s(fp0, fp0);
6217 gen_store_fpr32(fp0, fd);
6218 tcg_temp_free_i32(fp0);
6223 check_cp1_64bitmode(ctx);
6225 TCGv_i32 fp0 = tcg_temp_new_i32();
6227 gen_load_fpr32(fp0, fs);
6228 gen_helper_float_rsqrt1_s(fp0, fp0);
6229 gen_store_fpr32(fp0, fd);
6230 tcg_temp_free_i32(fp0);
6235 check_cp1_64bitmode(ctx);
6237 TCGv_i32 fp0 = tcg_temp_new_i32();
6238 TCGv_i32 fp1 = tcg_temp_new_i32();
6240 gen_load_fpr32(fp0, fs);
6241 gen_load_fpr32(fp1, ft);
6242 gen_helper_float_rsqrt2_s(fp0, fp0, fp1);
6243 tcg_temp_free_i32(fp1);
6244 gen_store_fpr32(fp0, fd);
6245 tcg_temp_free_i32(fp0);
6250 check_cp1_registers(ctx, fd);
6252 TCGv_i32 fp32 = tcg_temp_new_i32();
6253 TCGv_i64 fp64 = tcg_temp_new_i64();
6255 gen_load_fpr32(fp32, fs);
6256 gen_helper_float_cvtd_s(fp64, fp32);
6257 tcg_temp_free_i32(fp32);
6258 gen_store_fpr64(ctx, fp64, fd);
6259 tcg_temp_free_i64(fp64);
6265 TCGv_i32 fp0 = tcg_temp_new_i32();
6267 gen_load_fpr32(fp0, fs);
6268 gen_helper_float_cvtw_s(fp0, fp0);
6269 gen_store_fpr32(fp0, fd);
6270 tcg_temp_free_i32(fp0);
6275 check_cp1_64bitmode(ctx);
6277 TCGv_i32 fp32 = tcg_temp_new_i32();
6278 TCGv_i64 fp64 = tcg_temp_new_i64();
6280 gen_load_fpr32(fp32, fs);
6281 gen_helper_float_cvtl_s(fp64, fp32);
6282 tcg_temp_free_i32(fp32);
6283 gen_store_fpr64(ctx, fp64, fd);
6284 tcg_temp_free_i64(fp64);
6289 check_cp1_64bitmode(ctx);
6291 TCGv_i64 fp64 = tcg_temp_new_i64();
6292 TCGv_i32 fp32_0 = tcg_temp_new_i32();
6293 TCGv_i32 fp32_1 = tcg_temp_new_i32();
6295 gen_load_fpr32(fp32_0, fs);
6296 gen_load_fpr32(fp32_1, ft);
6297 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6298 tcg_temp_free_i32(fp32_1);
6299 tcg_temp_free_i32(fp32_0);
6300 gen_store_fpr64(ctx, fp64, fd);
6301 tcg_temp_free_i64(fp64);
6322 TCGv_i32 fp0 = tcg_temp_new_i32();
6323 TCGv_i32 fp1 = tcg_temp_new_i32();
6325 gen_load_fpr32(fp0, fs);
6326 gen_load_fpr32(fp1, ft);
6327 if (ctx->opcode & (1 << 6)) {
6329 gen_cmpabs_s(func-48, fp0, fp1, cc);
6330 opn = condnames_abs[func-48];
6332 gen_cmp_s(func-48, fp0, fp1, cc);
6333 opn = condnames[func-48];
6335 tcg_temp_free_i32(fp0);
6336 tcg_temp_free_i32(fp1);
6340 check_cp1_registers(ctx, fs | ft | fd);
6342 TCGv_i64 fp0 = tcg_temp_new_i64();
6343 TCGv_i64 fp1 = tcg_temp_new_i64();
6345 gen_load_fpr64(ctx, fp0, fs);
6346 gen_load_fpr64(ctx, fp1, ft);
6347 gen_helper_float_add_d(fp0, fp0, fp1);
6348 tcg_temp_free_i64(fp1);
6349 gen_store_fpr64(ctx, fp0, fd);
6350 tcg_temp_free_i64(fp0);
6356 check_cp1_registers(ctx, fs | ft | fd);
6358 TCGv_i64 fp0 = tcg_temp_new_i64();
6359 TCGv_i64 fp1 = tcg_temp_new_i64();
6361 gen_load_fpr64(ctx, fp0, fs);
6362 gen_load_fpr64(ctx, fp1, ft);
6363 gen_helper_float_sub_d(fp0, fp0, fp1);
6364 tcg_temp_free_i64(fp1);
6365 gen_store_fpr64(ctx, fp0, fd);
6366 tcg_temp_free_i64(fp0);
6372 check_cp1_registers(ctx, fs | ft | fd);
6374 TCGv_i64 fp0 = tcg_temp_new_i64();
6375 TCGv_i64 fp1 = tcg_temp_new_i64();
6377 gen_load_fpr64(ctx, fp0, fs);
6378 gen_load_fpr64(ctx, fp1, ft);
6379 gen_helper_float_mul_d(fp0, fp0, fp1);
6380 tcg_temp_free_i64(fp1);
6381 gen_store_fpr64(ctx, fp0, fd);
6382 tcg_temp_free_i64(fp0);
6388 check_cp1_registers(ctx, fs | ft | fd);
6390 TCGv_i64 fp0 = tcg_temp_new_i64();
6391 TCGv_i64 fp1 = tcg_temp_new_i64();
6393 gen_load_fpr64(ctx, fp0, fs);
6394 gen_load_fpr64(ctx, fp1, ft);
6395 gen_helper_float_div_d(fp0, fp0, fp1);
6396 tcg_temp_free_i64(fp1);
6397 gen_store_fpr64(ctx, fp0, fd);
6398 tcg_temp_free_i64(fp0);
6404 check_cp1_registers(ctx, fs | fd);
6406 TCGv_i64 fp0 = tcg_temp_new_i64();
6408 gen_load_fpr64(ctx, fp0, fs);
6409 gen_helper_float_sqrt_d(fp0, fp0);
6410 gen_store_fpr64(ctx, fp0, fd);
6411 tcg_temp_free_i64(fp0);
6416 check_cp1_registers(ctx, fs | fd);
6418 TCGv_i64 fp0 = tcg_temp_new_i64();
6420 gen_load_fpr64(ctx, fp0, fs);
6421 gen_helper_float_abs_d(fp0, fp0);
6422 gen_store_fpr64(ctx, fp0, fd);
6423 tcg_temp_free_i64(fp0);
6428 check_cp1_registers(ctx, fs | fd);
6430 TCGv_i64 fp0 = tcg_temp_new_i64();
6432 gen_load_fpr64(ctx, fp0, fs);
6433 gen_store_fpr64(ctx, fp0, fd);
6434 tcg_temp_free_i64(fp0);
6439 check_cp1_registers(ctx, fs | fd);
6441 TCGv_i64 fp0 = tcg_temp_new_i64();
6443 gen_load_fpr64(ctx, fp0, fs);
6444 gen_helper_float_chs_d(fp0, fp0);
6445 gen_store_fpr64(ctx, fp0, fd);
6446 tcg_temp_free_i64(fp0);
6451 check_cp1_64bitmode(ctx);
6453 TCGv_i64 fp0 = tcg_temp_new_i64();
6455 gen_load_fpr64(ctx, fp0, fs);
6456 gen_helper_float_roundl_d(fp0, fp0);
6457 gen_store_fpr64(ctx, fp0, fd);
6458 tcg_temp_free_i64(fp0);
6463 check_cp1_64bitmode(ctx);
6465 TCGv_i64 fp0 = tcg_temp_new_i64();
6467 gen_load_fpr64(ctx, fp0, fs);
6468 gen_helper_float_truncl_d(fp0, fp0);
6469 gen_store_fpr64(ctx, fp0, fd);
6470 tcg_temp_free_i64(fp0);
6475 check_cp1_64bitmode(ctx);
6477 TCGv_i64 fp0 = tcg_temp_new_i64();
6479 gen_load_fpr64(ctx, fp0, fs);
6480 gen_helper_float_ceill_d(fp0, fp0);
6481 gen_store_fpr64(ctx, fp0, fd);
6482 tcg_temp_free_i64(fp0);
6487 check_cp1_64bitmode(ctx);
6489 TCGv_i64 fp0 = tcg_temp_new_i64();
6491 gen_load_fpr64(ctx, fp0, fs);
6492 gen_helper_float_floorl_d(fp0, fp0);
6493 gen_store_fpr64(ctx, fp0, fd);
6494 tcg_temp_free_i64(fp0);
6499 check_cp1_registers(ctx, fs);
6501 TCGv_i32 fp32 = tcg_temp_new_i32();
6502 TCGv_i64 fp64 = tcg_temp_new_i64();
6504 gen_load_fpr64(ctx, fp64, fs);
6505 gen_helper_float_roundw_d(fp32, fp64);
6506 tcg_temp_free_i64(fp64);
6507 gen_store_fpr32(fp32, fd);
6508 tcg_temp_free_i32(fp32);
6513 check_cp1_registers(ctx, fs);
6515 TCGv_i32 fp32 = tcg_temp_new_i32();
6516 TCGv_i64 fp64 = tcg_temp_new_i64();
6518 gen_load_fpr64(ctx, fp64, fs);
6519 gen_helper_float_truncw_d(fp32, fp64);
6520 tcg_temp_free_i64(fp64);
6521 gen_store_fpr32(fp32, fd);
6522 tcg_temp_free_i32(fp32);
6527 check_cp1_registers(ctx, fs);
6529 TCGv_i32 fp32 = tcg_temp_new_i32();
6530 TCGv_i64 fp64 = tcg_temp_new_i64();
6532 gen_load_fpr64(ctx, fp64, fs);
6533 gen_helper_float_ceilw_d(fp32, fp64);
6534 tcg_temp_free_i64(fp64);
6535 gen_store_fpr32(fp32, fd);
6536 tcg_temp_free_i32(fp32);
6541 check_cp1_registers(ctx, fs);
6543 TCGv_i32 fp32 = tcg_temp_new_i32();
6544 TCGv_i64 fp64 = tcg_temp_new_i64();
6546 gen_load_fpr64(ctx, fp64, fs);
6547 gen_helper_float_floorw_d(fp32, fp64);
6548 tcg_temp_free_i64(fp64);
6549 gen_store_fpr32(fp32, fd);
6550 tcg_temp_free_i32(fp32);
6555 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6560 int l1 = gen_new_label();
6561 TCGv t0 = tcg_temp_new();
6562 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6564 gen_load_gpr(t0, ft);
6565 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6566 gen_load_fpr64(ctx, fp0, fs);
6567 gen_store_fpr64(ctx, fp0, fd);
6568 tcg_temp_free_i64(fp0);
6576 int l1 = gen_new_label();
6577 TCGv t0 = tcg_temp_new();
6578 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6580 gen_load_gpr(t0, ft);
6581 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6582 gen_load_fpr64(ctx, fp0, fs);
6583 gen_store_fpr64(ctx, fp0, fd);
6584 tcg_temp_free_i64(fp0);
6591 check_cp1_64bitmode(ctx);
6593 TCGv_i64 fp0 = tcg_temp_new_i64();
6595 gen_load_fpr64(ctx, fp0, fs);
6596 gen_helper_float_recip_d(fp0, fp0);
6597 gen_store_fpr64(ctx, fp0, fd);
6598 tcg_temp_free_i64(fp0);
6603 check_cp1_64bitmode(ctx);
6605 TCGv_i64 fp0 = tcg_temp_new_i64();
6607 gen_load_fpr64(ctx, fp0, fs);
6608 gen_helper_float_rsqrt_d(fp0, fp0);
6609 gen_store_fpr64(ctx, fp0, fd);
6610 tcg_temp_free_i64(fp0);
6615 check_cp1_64bitmode(ctx);
6617 TCGv_i64 fp0 = tcg_temp_new_i64();
6618 TCGv_i64 fp1 = tcg_temp_new_i64();
6620 gen_load_fpr64(ctx, fp0, fs);
6621 gen_load_fpr64(ctx, fp1, ft);
6622 gen_helper_float_recip2_d(fp0, fp0, fp1);
6623 tcg_temp_free_i64(fp1);
6624 gen_store_fpr64(ctx, fp0, fd);
6625 tcg_temp_free_i64(fp0);
6630 check_cp1_64bitmode(ctx);
6632 TCGv_i64 fp0 = tcg_temp_new_i64();
6634 gen_load_fpr64(ctx, fp0, fs);
6635 gen_helper_float_recip1_d(fp0, fp0);
6636 gen_store_fpr64(ctx, fp0, fd);
6637 tcg_temp_free_i64(fp0);
6642 check_cp1_64bitmode(ctx);
6644 TCGv_i64 fp0 = tcg_temp_new_i64();
6646 gen_load_fpr64(ctx, fp0, fs);
6647 gen_helper_float_rsqrt1_d(fp0, fp0);
6648 gen_store_fpr64(ctx, fp0, fd);
6649 tcg_temp_free_i64(fp0);
6654 check_cp1_64bitmode(ctx);
6656 TCGv_i64 fp0 = tcg_temp_new_i64();
6657 TCGv_i64 fp1 = tcg_temp_new_i64();
6659 gen_load_fpr64(ctx, fp0, fs);
6660 gen_load_fpr64(ctx, fp1, ft);
6661 gen_helper_float_rsqrt2_d(fp0, fp0, fp1);
6662 tcg_temp_free_i64(fp1);
6663 gen_store_fpr64(ctx, fp0, fd);
6664 tcg_temp_free_i64(fp0);
6685 TCGv_i64 fp0 = tcg_temp_new_i64();
6686 TCGv_i64 fp1 = tcg_temp_new_i64();
6688 gen_load_fpr64(ctx, fp0, fs);
6689 gen_load_fpr64(ctx, fp1, ft);
6690 if (ctx->opcode & (1 << 6)) {
6692 check_cp1_registers(ctx, fs | ft);
6693 gen_cmpabs_d(func-48, fp0, fp1, cc);
6694 opn = condnames_abs[func-48];
6696 check_cp1_registers(ctx, fs | ft);
6697 gen_cmp_d(func-48, fp0, fp1, cc);
6698 opn = condnames[func-48];
6700 tcg_temp_free_i64(fp0);
6701 tcg_temp_free_i64(fp1);
6705 check_cp1_registers(ctx, fs);
6707 TCGv_i32 fp32 = tcg_temp_new_i32();
6708 TCGv_i64 fp64 = tcg_temp_new_i64();
6710 gen_load_fpr64(ctx, fp64, fs);
6711 gen_helper_float_cvts_d(fp32, fp64);
6712 tcg_temp_free_i64(fp64);
6713 gen_store_fpr32(fp32, fd);
6714 tcg_temp_free_i32(fp32);
6719 check_cp1_registers(ctx, fs);
6721 TCGv_i32 fp32 = tcg_temp_new_i32();
6722 TCGv_i64 fp64 = tcg_temp_new_i64();
6724 gen_load_fpr64(ctx, fp64, fs);
6725 gen_helper_float_cvtw_d(fp32, fp64);
6726 tcg_temp_free_i64(fp64);
6727 gen_store_fpr32(fp32, fd);
6728 tcg_temp_free_i32(fp32);
6733 check_cp1_64bitmode(ctx);
6735 TCGv_i64 fp0 = tcg_temp_new_i64();
6737 gen_load_fpr64(ctx, fp0, fs);
6738 gen_helper_float_cvtl_d(fp0, fp0);
6739 gen_store_fpr64(ctx, fp0, fd);
6740 tcg_temp_free_i64(fp0);
6746 TCGv_i32 fp0 = tcg_temp_new_i32();
6748 gen_load_fpr32(fp0, fs);
6749 gen_helper_float_cvts_w(fp0, fp0);
6750 gen_store_fpr32(fp0, fd);
6751 tcg_temp_free_i32(fp0);
6756 check_cp1_registers(ctx, fd);
6758 TCGv_i32 fp32 = tcg_temp_new_i32();
6759 TCGv_i64 fp64 = tcg_temp_new_i64();
6761 gen_load_fpr32(fp32, fs);
6762 gen_helper_float_cvtd_w(fp64, fp32);
6763 tcg_temp_free_i32(fp32);
6764 gen_store_fpr64(ctx, fp64, fd);
6765 tcg_temp_free_i64(fp64);
6770 check_cp1_64bitmode(ctx);
6772 TCGv_i32 fp32 = tcg_temp_new_i32();
6773 TCGv_i64 fp64 = tcg_temp_new_i64();
6775 gen_load_fpr64(ctx, fp64, fs);
6776 gen_helper_float_cvts_l(fp32, fp64);
6777 tcg_temp_free_i64(fp64);
6778 gen_store_fpr32(fp32, fd);
6779 tcg_temp_free_i32(fp32);
6784 check_cp1_64bitmode(ctx);
6786 TCGv_i64 fp0 = tcg_temp_new_i64();
6788 gen_load_fpr64(ctx, fp0, fs);
6789 gen_helper_float_cvtd_l(fp0, fp0);
6790 gen_store_fpr64(ctx, fp0, fd);
6791 tcg_temp_free_i64(fp0);
6796 check_cp1_64bitmode(ctx);
6798 TCGv_i64 fp0 = tcg_temp_new_i64();
6800 gen_load_fpr64(ctx, fp0, fs);
6801 gen_helper_float_cvtps_pw(fp0, fp0);
6802 gen_store_fpr64(ctx, fp0, fd);
6803 tcg_temp_free_i64(fp0);
6808 check_cp1_64bitmode(ctx);
6810 TCGv_i64 fp0 = tcg_temp_new_i64();
6811 TCGv_i64 fp1 = tcg_temp_new_i64();
6813 gen_load_fpr64(ctx, fp0, fs);
6814 gen_load_fpr64(ctx, fp1, ft);
6815 gen_helper_float_add_ps(fp0, fp0, fp1);
6816 tcg_temp_free_i64(fp1);
6817 gen_store_fpr64(ctx, fp0, fd);
6818 tcg_temp_free_i64(fp0);
6823 check_cp1_64bitmode(ctx);
6825 TCGv_i64 fp0 = tcg_temp_new_i64();
6826 TCGv_i64 fp1 = tcg_temp_new_i64();
6828 gen_load_fpr64(ctx, fp0, fs);
6829 gen_load_fpr64(ctx, fp1, ft);
6830 gen_helper_float_sub_ps(fp0, fp0, fp1);
6831 tcg_temp_free_i64(fp1);
6832 gen_store_fpr64(ctx, fp0, fd);
6833 tcg_temp_free_i64(fp0);
6838 check_cp1_64bitmode(ctx);
6840 TCGv_i64 fp0 = tcg_temp_new_i64();
6841 TCGv_i64 fp1 = tcg_temp_new_i64();
6843 gen_load_fpr64(ctx, fp0, fs);
6844 gen_load_fpr64(ctx, fp1, ft);
6845 gen_helper_float_mul_ps(fp0, fp0, fp1);
6846 tcg_temp_free_i64(fp1);
6847 gen_store_fpr64(ctx, fp0, fd);
6848 tcg_temp_free_i64(fp0);
6853 check_cp1_64bitmode(ctx);
6855 TCGv_i64 fp0 = tcg_temp_new_i64();
6857 gen_load_fpr64(ctx, fp0, fs);
6858 gen_helper_float_abs_ps(fp0, fp0);
6859 gen_store_fpr64(ctx, fp0, fd);
6860 tcg_temp_free_i64(fp0);
6865 check_cp1_64bitmode(ctx);
6867 TCGv_i64 fp0 = tcg_temp_new_i64();
6869 gen_load_fpr64(ctx, fp0, fs);
6870 gen_store_fpr64(ctx, fp0, fd);
6871 tcg_temp_free_i64(fp0);
6876 check_cp1_64bitmode(ctx);
6878 TCGv_i64 fp0 = tcg_temp_new_i64();
6880 gen_load_fpr64(ctx, fp0, fs);
6881 gen_helper_float_chs_ps(fp0, fp0);
6882 gen_store_fpr64(ctx, fp0, fd);
6883 tcg_temp_free_i64(fp0);
6888 check_cp1_64bitmode(ctx);
6889 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6893 check_cp1_64bitmode(ctx);
6895 int l1 = gen_new_label();
6896 TCGv t0 = tcg_temp_new();
6897 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6898 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6900 gen_load_gpr(t0, ft);
6901 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6902 gen_load_fpr32(fp0, fs);
6903 gen_load_fpr32h(fph0, fs);
6904 gen_store_fpr32(fp0, fd);
6905 gen_store_fpr32h(fph0, fd);
6906 tcg_temp_free_i32(fp0);
6907 tcg_temp_free_i32(fph0);
6914 check_cp1_64bitmode(ctx);
6916 int l1 = gen_new_label();
6917 TCGv t0 = tcg_temp_new();
6918 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6919 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6921 gen_load_gpr(t0, ft);
6922 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6923 gen_load_fpr32(fp0, fs);
6924 gen_load_fpr32h(fph0, fs);
6925 gen_store_fpr32(fp0, fd);
6926 gen_store_fpr32h(fph0, fd);
6927 tcg_temp_free_i32(fp0);
6928 tcg_temp_free_i32(fph0);
6935 check_cp1_64bitmode(ctx);
6937 TCGv_i64 fp0 = tcg_temp_new_i64();
6938 TCGv_i64 fp1 = tcg_temp_new_i64();
6940 gen_load_fpr64(ctx, fp0, ft);
6941 gen_load_fpr64(ctx, fp1, fs);
6942 gen_helper_float_addr_ps(fp0, fp0, fp1);
6943 tcg_temp_free_i64(fp1);
6944 gen_store_fpr64(ctx, fp0, fd);
6945 tcg_temp_free_i64(fp0);
6950 check_cp1_64bitmode(ctx);
6952 TCGv_i64 fp0 = tcg_temp_new_i64();
6953 TCGv_i64 fp1 = tcg_temp_new_i64();
6955 gen_load_fpr64(ctx, fp0, ft);
6956 gen_load_fpr64(ctx, fp1, fs);
6957 gen_helper_float_mulr_ps(fp0, fp0, fp1);
6958 tcg_temp_free_i64(fp1);
6959 gen_store_fpr64(ctx, fp0, fd);
6960 tcg_temp_free_i64(fp0);
6965 check_cp1_64bitmode(ctx);
6967 TCGv_i64 fp0 = tcg_temp_new_i64();
6968 TCGv_i64 fp1 = tcg_temp_new_i64();
6970 gen_load_fpr64(ctx, fp0, fs);
6971 gen_load_fpr64(ctx, fp1, fd);
6972 gen_helper_float_recip2_ps(fp0, fp0, fp1);
6973 tcg_temp_free_i64(fp1);
6974 gen_store_fpr64(ctx, fp0, fd);
6975 tcg_temp_free_i64(fp0);
6980 check_cp1_64bitmode(ctx);
6982 TCGv_i64 fp0 = tcg_temp_new_i64();
6984 gen_load_fpr64(ctx, fp0, fs);
6985 gen_helper_float_recip1_ps(fp0, fp0);
6986 gen_store_fpr64(ctx, fp0, fd);
6987 tcg_temp_free_i64(fp0);
6992 check_cp1_64bitmode(ctx);
6994 TCGv_i64 fp0 = tcg_temp_new_i64();
6996 gen_load_fpr64(ctx, fp0, fs);
6997 gen_helper_float_rsqrt1_ps(fp0, fp0);
6998 gen_store_fpr64(ctx, fp0, fd);
6999 tcg_temp_free_i64(fp0);
7004 check_cp1_64bitmode(ctx);
7006 TCGv_i64 fp0 = tcg_temp_new_i64();
7007 TCGv_i64 fp1 = tcg_temp_new_i64();
7009 gen_load_fpr64(ctx, fp0, fs);
7010 gen_load_fpr64(ctx, fp1, ft);
7011 gen_helper_float_rsqrt2_ps(fp0, fp0, fp1);
7012 tcg_temp_free_i64(fp1);
7013 gen_store_fpr64(ctx, fp0, fd);
7014 tcg_temp_free_i64(fp0);
7019 check_cp1_64bitmode(ctx);
7021 TCGv_i32 fp0 = tcg_temp_new_i32();
7023 gen_load_fpr32h(fp0, fs);
7024 gen_helper_float_cvts_pu(fp0, fp0);
7025 gen_store_fpr32(fp0, fd);
7026 tcg_temp_free_i32(fp0);
7031 check_cp1_64bitmode(ctx);
7033 TCGv_i64 fp0 = tcg_temp_new_i64();
7035 gen_load_fpr64(ctx, fp0, fs);
7036 gen_helper_float_cvtpw_ps(fp0, fp0);
7037 gen_store_fpr64(ctx, fp0, fd);
7038 tcg_temp_free_i64(fp0);
7043 check_cp1_64bitmode(ctx);
7045 TCGv_i32 fp0 = tcg_temp_new_i32();
7047 gen_load_fpr32(fp0, fs);
7048 gen_helper_float_cvts_pl(fp0, fp0);
7049 gen_store_fpr32(fp0, fd);
7050 tcg_temp_free_i32(fp0);
7055 check_cp1_64bitmode(ctx);
7057 TCGv_i32 fp0 = tcg_temp_new_i32();
7058 TCGv_i32 fp1 = tcg_temp_new_i32();
7060 gen_load_fpr32(fp0, fs);
7061 gen_load_fpr32(fp1, ft);
7062 gen_store_fpr32h(fp0, fd);
7063 gen_store_fpr32(fp1, fd);
7064 tcg_temp_free_i32(fp0);
7065 tcg_temp_free_i32(fp1);
7070 check_cp1_64bitmode(ctx);
7072 TCGv_i32 fp0 = tcg_temp_new_i32();
7073 TCGv_i32 fp1 = tcg_temp_new_i32();
7075 gen_load_fpr32(fp0, fs);
7076 gen_load_fpr32h(fp1, ft);
7077 gen_store_fpr32(fp1, fd);
7078 gen_store_fpr32h(fp0, fd);
7079 tcg_temp_free_i32(fp0);
7080 tcg_temp_free_i32(fp1);
7085 check_cp1_64bitmode(ctx);
7087 TCGv_i32 fp0 = tcg_temp_new_i32();
7088 TCGv_i32 fp1 = tcg_temp_new_i32();
7090 gen_load_fpr32h(fp0, fs);
7091 gen_load_fpr32(fp1, ft);
7092 gen_store_fpr32(fp1, fd);
7093 gen_store_fpr32h(fp0, fd);
7094 tcg_temp_free_i32(fp0);
7095 tcg_temp_free_i32(fp1);
7100 check_cp1_64bitmode(ctx);
7102 TCGv_i32 fp0 = tcg_temp_new_i32();
7103 TCGv_i32 fp1 = tcg_temp_new_i32();
7105 gen_load_fpr32h(fp0, fs);
7106 gen_load_fpr32h(fp1, ft);
7107 gen_store_fpr32(fp1, fd);
7108 gen_store_fpr32h(fp0, fd);
7109 tcg_temp_free_i32(fp0);
7110 tcg_temp_free_i32(fp1);
7130 check_cp1_64bitmode(ctx);
7132 TCGv_i64 fp0 = tcg_temp_new_i64();
7133 TCGv_i64 fp1 = tcg_temp_new_i64();
7135 gen_load_fpr64(ctx, fp0, fs);
7136 gen_load_fpr64(ctx, fp1, ft);
7137 if (ctx->opcode & (1 << 6)) {
7138 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7139 opn = condnames_abs[func-48];
7141 gen_cmp_ps(func-48, fp0, fp1, cc);
7142 opn = condnames[func-48];
7144 tcg_temp_free_i64(fp0);
7145 tcg_temp_free_i64(fp1);
7150 generate_exception (ctx, EXCP_RI);
7155 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7158 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7161 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7166 /* Coprocessor 3 (FPU) */
7167 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7168 int fd, int fs, int base, int index)
7170 const char *opn = "extended float load/store";
7172 TCGv t0 = tcg_temp_local_new();
7173 TCGv t1 = tcg_temp_local_new();
7176 gen_load_gpr(t0, index);
7177 } else if (index == 0) {
7178 gen_load_gpr(t0, base);
7180 gen_load_gpr(t0, index);
7181 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
7183 /* Don't do NOP if destination is zero: we must perform the actual
7189 TCGv_i32 fp0 = tcg_temp_new_i32();
7191 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
7192 tcg_gen_trunc_tl_i32(fp0, t1);
7193 gen_store_fpr32(fp0, fd);
7194 tcg_temp_free_i32(fp0);
7200 check_cp1_registers(ctx, fd);
7202 TCGv_i64 fp0 = tcg_temp_new_i64();
7204 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7205 gen_store_fpr64(ctx, fp0, fd);
7206 tcg_temp_free_i64(fp0);
7211 check_cp1_64bitmode(ctx);
7212 tcg_gen_andi_tl(t0, t0, ~0x7);
7214 TCGv_i64 fp0 = tcg_temp_new_i64();
7216 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7217 gen_store_fpr64(ctx, fp0, fd);
7218 tcg_temp_free_i64(fp0);
7225 TCGv_i32 fp0 = tcg_temp_new_i32();
7227 gen_load_fpr32(fp0, fs);
7228 tcg_gen_extu_i32_tl(t1, fp0);
7229 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
7230 tcg_temp_free_i32(fp0);
7237 check_cp1_registers(ctx, fs);
7239 TCGv_i64 fp0 = tcg_temp_new_i64();
7241 gen_load_fpr64(ctx, fp0, fs);
7242 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7243 tcg_temp_free_i64(fp0);
7249 check_cp1_64bitmode(ctx);
7250 tcg_gen_andi_tl(t0, t0, ~0x7);
7252 TCGv_i64 fp0 = tcg_temp_new_i64();
7254 gen_load_fpr64(ctx, fp0, fs);
7255 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7256 tcg_temp_free_i64(fp0);
7263 generate_exception(ctx, EXCP_RI);
7270 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7271 regnames[index], regnames[base]);
7274 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7275 int fd, int fr, int fs, int ft)
7277 const char *opn = "flt3_arith";
7281 check_cp1_64bitmode(ctx);
7283 TCGv t0 = tcg_temp_local_new();
7284 TCGv_i32 fp0 = tcg_temp_local_new_i32();
7285 TCGv_i32 fph0 = tcg_temp_local_new_i32();
7286 TCGv_i32 fp1 = tcg_temp_local_new_i32();
7287 TCGv_i32 fph1 = tcg_temp_local_new_i32();
7288 int l1 = gen_new_label();
7289 int l2 = gen_new_label();
7291 gen_load_gpr(t0, fr);
7292 tcg_gen_andi_tl(t0, t0, 0x7);
7293 gen_load_fpr32(fp0, fs);
7294 gen_load_fpr32h(fph0, fs);
7295 gen_load_fpr32(fp1, ft);
7296 gen_load_fpr32h(fph1, ft);
7298 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7299 gen_store_fpr32(fp0, fd);
7300 gen_store_fpr32h(fph0, fd);
7303 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7305 #ifdef TARGET_WORDS_BIGENDIAN
7306 gen_store_fpr32(fph1, fd);
7307 gen_store_fpr32h(fp0, fd);
7309 gen_store_fpr32(fph0, fd);
7310 gen_store_fpr32h(fp1, fd);
7313 tcg_temp_free_i32(fp0);
7314 tcg_temp_free_i32(fph0);
7315 tcg_temp_free_i32(fp1);
7316 tcg_temp_free_i32(fph1);
7323 TCGv_i32 fp0 = tcg_temp_new_i32();
7324 TCGv_i32 fp1 = tcg_temp_new_i32();
7325 TCGv_i32 fp2 = tcg_temp_new_i32();
7327 gen_load_fpr32(fp0, fs);
7328 gen_load_fpr32(fp1, ft);
7329 gen_load_fpr32(fp2, fr);
7330 gen_helper_float_muladd_s(fp2, fp0, fp1, fp2);
7331 tcg_temp_free_i32(fp0);
7332 tcg_temp_free_i32(fp1);
7333 gen_store_fpr32(fp2, fd);
7334 tcg_temp_free_i32(fp2);
7340 check_cp1_registers(ctx, fd | fs | ft | fr);
7342 TCGv_i64 fp0 = tcg_temp_new_i64();
7343 TCGv_i64 fp1 = tcg_temp_new_i64();
7344 TCGv_i64 fp2 = tcg_temp_new_i64();
7346 gen_load_fpr64(ctx, fp0, fs);
7347 gen_load_fpr64(ctx, fp1, ft);
7348 gen_load_fpr64(ctx, fp2, fr);
7349 gen_helper_float_muladd_d(fp2, fp0, fp1, fp2);
7350 tcg_temp_free_i64(fp0);
7351 tcg_temp_free_i64(fp1);
7352 gen_store_fpr64(ctx, fp2, fd);
7353 tcg_temp_free_i64(fp2);
7358 check_cp1_64bitmode(ctx);
7360 TCGv_i64 fp0 = tcg_temp_new_i64();
7361 TCGv_i64 fp1 = tcg_temp_new_i64();
7362 TCGv_i64 fp2 = tcg_temp_new_i64();
7364 gen_load_fpr64(ctx, fp0, fs);
7365 gen_load_fpr64(ctx, fp1, ft);
7366 gen_load_fpr64(ctx, fp2, fr);
7367 gen_helper_float_muladd_ps(fp2, fp0, fp1, fp2);
7368 tcg_temp_free_i64(fp0);
7369 tcg_temp_free_i64(fp1);
7370 gen_store_fpr64(ctx, fp2, fd);
7371 tcg_temp_free_i64(fp2);
7378 TCGv_i32 fp0 = tcg_temp_new_i32();
7379 TCGv_i32 fp1 = tcg_temp_new_i32();
7380 TCGv_i32 fp2 = tcg_temp_new_i32();
7382 gen_load_fpr32(fp0, fs);
7383 gen_load_fpr32(fp1, ft);
7384 gen_load_fpr32(fp2, fr);
7385 gen_helper_float_mulsub_s(fp2, fp0, fp1, fp2);
7386 tcg_temp_free_i32(fp0);
7387 tcg_temp_free_i32(fp1);
7388 gen_store_fpr32(fp2, fd);
7389 tcg_temp_free_i32(fp2);
7395 check_cp1_registers(ctx, fd | fs | ft | fr);
7397 TCGv_i64 fp0 = tcg_temp_new_i64();
7398 TCGv_i64 fp1 = tcg_temp_new_i64();
7399 TCGv_i64 fp2 = tcg_temp_new_i64();
7401 gen_load_fpr64(ctx, fp0, fs);
7402 gen_load_fpr64(ctx, fp1, ft);
7403 gen_load_fpr64(ctx, fp2, fr);
7404 gen_helper_float_mulsub_d(fp2, fp0, fp1, fp2);
7405 tcg_temp_free_i64(fp0);
7406 tcg_temp_free_i64(fp1);
7407 gen_store_fpr64(ctx, fp2, fd);
7408 tcg_temp_free_i64(fp2);
7413 check_cp1_64bitmode(ctx);
7415 TCGv_i64 fp0 = tcg_temp_new_i64();
7416 TCGv_i64 fp1 = tcg_temp_new_i64();
7417 TCGv_i64 fp2 = tcg_temp_new_i64();
7419 gen_load_fpr64(ctx, fp0, fs);
7420 gen_load_fpr64(ctx, fp1, ft);
7421 gen_load_fpr64(ctx, fp2, fr);
7422 gen_helper_float_mulsub_ps(fp2, fp0, fp1, fp2);
7423 tcg_temp_free_i64(fp0);
7424 tcg_temp_free_i64(fp1);
7425 gen_store_fpr64(ctx, fp2, fd);
7426 tcg_temp_free_i64(fp2);
7433 TCGv_i32 fp0 = tcg_temp_new_i32();
7434 TCGv_i32 fp1 = tcg_temp_new_i32();
7435 TCGv_i32 fp2 = tcg_temp_new_i32();
7437 gen_load_fpr32(fp0, fs);
7438 gen_load_fpr32(fp1, ft);
7439 gen_load_fpr32(fp2, fr);
7440 gen_helper_float_nmuladd_s(fp2, fp0, fp1, fp2);
7441 tcg_temp_free_i32(fp0);
7442 tcg_temp_free_i32(fp1);
7443 gen_store_fpr32(fp2, fd);
7444 tcg_temp_free_i32(fp2);
7450 check_cp1_registers(ctx, fd | fs | ft | fr);
7452 TCGv_i64 fp0 = tcg_temp_new_i64();
7453 TCGv_i64 fp1 = tcg_temp_new_i64();
7454 TCGv_i64 fp2 = tcg_temp_new_i64();
7456 gen_load_fpr64(ctx, fp0, fs);
7457 gen_load_fpr64(ctx, fp1, ft);
7458 gen_load_fpr64(ctx, fp2, fr);
7459 gen_helper_float_nmuladd_d(fp2, fp0, fp1, fp2);
7460 tcg_temp_free_i64(fp0);
7461 tcg_temp_free_i64(fp1);
7462 gen_store_fpr64(ctx, fp2, fd);
7463 tcg_temp_free_i64(fp2);
7468 check_cp1_64bitmode(ctx);
7470 TCGv_i64 fp0 = tcg_temp_new_i64();
7471 TCGv_i64 fp1 = tcg_temp_new_i64();
7472 TCGv_i64 fp2 = tcg_temp_new_i64();
7474 gen_load_fpr64(ctx, fp0, fs);
7475 gen_load_fpr64(ctx, fp1, ft);
7476 gen_load_fpr64(ctx, fp2, fr);
7477 gen_helper_float_nmuladd_ps(fp2, fp0, fp1, fp2);
7478 tcg_temp_free_i64(fp0);
7479 tcg_temp_free_i64(fp1);
7480 gen_store_fpr64(ctx, fp2, fd);
7481 tcg_temp_free_i64(fp2);
7488 TCGv_i32 fp0 = tcg_temp_new_i32();
7489 TCGv_i32 fp1 = tcg_temp_new_i32();
7490 TCGv_i32 fp2 = tcg_temp_new_i32();
7492 gen_load_fpr32(fp0, fs);
7493 gen_load_fpr32(fp1, ft);
7494 gen_load_fpr32(fp2, fr);
7495 gen_helper_float_nmulsub_s(fp2, fp0, fp1, fp2);
7496 tcg_temp_free_i32(fp0);
7497 tcg_temp_free_i32(fp1);
7498 gen_store_fpr32(fp2, fd);
7499 tcg_temp_free_i32(fp2);
7505 check_cp1_registers(ctx, fd | fs | ft | fr);
7507 TCGv_i64 fp0 = tcg_temp_new_i64();
7508 TCGv_i64 fp1 = tcg_temp_new_i64();
7509 TCGv_i64 fp2 = tcg_temp_new_i64();
7511 gen_load_fpr64(ctx, fp0, fs);
7512 gen_load_fpr64(ctx, fp1, ft);
7513 gen_load_fpr64(ctx, fp2, fr);
7514 gen_helper_float_nmulsub_d(fp2, fp0, fp1, fp2);
7515 tcg_temp_free_i64(fp0);
7516 tcg_temp_free_i64(fp1);
7517 gen_store_fpr64(ctx, fp2, fd);
7518 tcg_temp_free_i64(fp2);
7523 check_cp1_64bitmode(ctx);
7525 TCGv_i64 fp0 = tcg_temp_new_i64();
7526 TCGv_i64 fp1 = tcg_temp_new_i64();
7527 TCGv_i64 fp2 = tcg_temp_new_i64();
7529 gen_load_fpr64(ctx, fp0, fs);
7530 gen_load_fpr64(ctx, fp1, ft);
7531 gen_load_fpr64(ctx, fp2, fr);
7532 gen_helper_float_nmulsub_ps(fp2, fp0, fp1, fp2);
7533 tcg_temp_free_i64(fp0);
7534 tcg_temp_free_i64(fp1);
7535 gen_store_fpr64(ctx, fp2, fd);
7536 tcg_temp_free_i64(fp2);
7542 generate_exception (ctx, EXCP_RI);
7545 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7546 fregnames[fs], fregnames[ft]);
7549 /* ISA extensions (ASEs) */
7550 /* MIPS16 extension to MIPS32 */
7551 /* SmartMIPS extension to MIPS32 */
7553 #if defined(TARGET_MIPS64)
7555 /* MDMX extension to MIPS64 */
7559 static void decode_opc (CPUState *env, DisasContext *ctx)
7563 uint32_t op, op1, op2;
7566 /* make sure instructions are on a word boundary */
7567 if (ctx->pc & 0x3) {
7568 env->CP0_BadVAddr = ctx->pc;
7569 generate_exception(ctx, EXCP_AdEL);
7573 /* Handle blikely not taken case */
7574 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7575 int l1 = gen_new_label();
7577 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7578 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7580 TCGv_i32 r_tmp = tcg_temp_new_i32();
7582 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7583 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7584 tcg_temp_free_i32(r_tmp);
7586 gen_goto_tb(ctx, 1, ctx->pc + 4);
7589 op = MASK_OP_MAJOR(ctx->opcode);
7590 rs = (ctx->opcode >> 21) & 0x1f;
7591 rt = (ctx->opcode >> 16) & 0x1f;
7592 rd = (ctx->opcode >> 11) & 0x1f;
7593 sa = (ctx->opcode >> 6) & 0x1f;
7594 imm = (int16_t)ctx->opcode;
7597 op1 = MASK_SPECIAL(ctx->opcode);
7599 case OPC_SLL: /* Arithmetic with immediate */
7600 case OPC_SRL ... OPC_SRA:
7601 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7603 case OPC_MOVZ ... OPC_MOVN:
7604 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7605 case OPC_SLLV: /* Arithmetic */
7606 case OPC_SRLV ... OPC_SRAV:
7607 case OPC_ADD ... OPC_NOR:
7608 case OPC_SLT ... OPC_SLTU:
7609 gen_arith(env, ctx, op1, rd, rs, rt);
7611 case OPC_MULT ... OPC_DIVU:
7613 check_insn(env, ctx, INSN_VR54XX);
7614 op1 = MASK_MUL_VR54XX(ctx->opcode);
7615 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7617 gen_muldiv(ctx, op1, rs, rt);
7619 case OPC_JR ... OPC_JALR:
7620 gen_compute_branch(ctx, op1, rs, rd, sa);
7622 case OPC_TGE ... OPC_TEQ: /* Traps */
7624 gen_trap(ctx, op1, rs, rt, -1);
7626 case OPC_MFHI: /* Move from HI/LO */
7628 gen_HILO(ctx, op1, rd);
7631 case OPC_MTLO: /* Move to HI/LO */
7632 gen_HILO(ctx, op1, rs);
7634 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7635 #ifdef MIPS_STRICT_STANDARD
7636 MIPS_INVAL("PMON / selsl");
7637 generate_exception(ctx, EXCP_RI);
7639 gen_helper_0i(pmon, sa);
7643 generate_exception(ctx, EXCP_SYSCALL);
7646 generate_exception(ctx, EXCP_BREAK);
7649 #ifdef MIPS_STRICT_STANDARD
7651 generate_exception(ctx, EXCP_RI);
7653 /* Implemented as RI exception for now. */
7654 MIPS_INVAL("spim (unofficial)");
7655 generate_exception(ctx, EXCP_RI);
7663 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7664 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7665 save_cpu_state(ctx, 1);
7666 check_cp1_enabled(ctx);
7667 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7668 (ctx->opcode >> 16) & 1);
7670 generate_exception_err(ctx, EXCP_CpU, 1);
7674 #if defined(TARGET_MIPS64)
7675 /* MIPS64 specific opcodes */
7677 case OPC_DSRL ... OPC_DSRA:
7679 case OPC_DSRL32 ... OPC_DSRA32:
7680 check_insn(env, ctx, ISA_MIPS3);
7682 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7685 case OPC_DSRLV ... OPC_DSRAV:
7686 case OPC_DADD ... OPC_DSUBU:
7687 check_insn(env, ctx, ISA_MIPS3);
7689 gen_arith(env, ctx, op1, rd, rs, rt);
7691 case OPC_DMULT ... OPC_DDIVU:
7692 check_insn(env, ctx, ISA_MIPS3);
7694 gen_muldiv(ctx, op1, rs, rt);
7697 default: /* Invalid */
7698 MIPS_INVAL("special");
7699 generate_exception(ctx, EXCP_RI);
7704 op1 = MASK_SPECIAL2(ctx->opcode);
7706 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7707 case OPC_MSUB ... OPC_MSUBU:
7708 check_insn(env, ctx, ISA_MIPS32);
7709 gen_muldiv(ctx, op1, rs, rt);
7712 gen_arith(env, ctx, op1, rd, rs, rt);
7714 case OPC_CLZ ... OPC_CLO:
7715 check_insn(env, ctx, ISA_MIPS32);
7716 gen_cl(ctx, op1, rd, rs);
7719 /* XXX: not clear which exception should be raised
7720 * when in debug mode...
7722 check_insn(env, ctx, ISA_MIPS32);
7723 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7724 generate_exception(ctx, EXCP_DBp);
7726 generate_exception(ctx, EXCP_DBp);
7730 #if defined(TARGET_MIPS64)
7731 case OPC_DCLZ ... OPC_DCLO:
7732 check_insn(env, ctx, ISA_MIPS64);
7734 gen_cl(ctx, op1, rd, rs);
7737 default: /* Invalid */
7738 MIPS_INVAL("special2");
7739 generate_exception(ctx, EXCP_RI);
7744 op1 = MASK_SPECIAL3(ctx->opcode);
7748 check_insn(env, ctx, ISA_MIPS32R2);
7749 gen_bitops(ctx, op1, rt, rs, sa, rd);
7752 check_insn(env, ctx, ISA_MIPS32R2);
7753 op2 = MASK_BSHFL(ctx->opcode);
7754 gen_bshfl(ctx, op2, rt, rd);
7757 check_insn(env, ctx, ISA_MIPS32R2);
7759 TCGv t0 = tcg_temp_local_new();
7763 save_cpu_state(ctx, 1);
7764 gen_helper_rdhwr_cpunum(t0);
7767 save_cpu_state(ctx, 1);
7768 gen_helper_rdhwr_synci_step(t0);
7771 save_cpu_state(ctx, 1);
7772 gen_helper_rdhwr_cc(t0);
7775 save_cpu_state(ctx, 1);
7776 gen_helper_rdhwr_ccres(t0);
7779 #if defined(CONFIG_USER_ONLY)
7780 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7783 /* XXX: Some CPUs implement this in hardware.
7784 Not supported yet. */
7786 default: /* Invalid */
7787 MIPS_INVAL("rdhwr");
7788 generate_exception(ctx, EXCP_RI);
7791 gen_store_gpr(t0, rt);
7796 check_insn(env, ctx, ASE_MT);
7798 TCGv t0 = tcg_temp_local_new();
7799 TCGv t1 = tcg_temp_local_new();
7801 gen_load_gpr(t0, rt);
7802 gen_load_gpr(t1, rs);
7803 gen_helper_fork(t0, t1);
7809 check_insn(env, ctx, ASE_MT);
7811 TCGv t0 = tcg_temp_local_new();
7813 gen_load_gpr(t0, rs);
7814 gen_helper_yield(t0, t0);
7815 gen_store_gpr(t0, rd);
7819 #if defined(TARGET_MIPS64)
7820 case OPC_DEXTM ... OPC_DEXT:
7821 case OPC_DINSM ... OPC_DINS:
7822 check_insn(env, ctx, ISA_MIPS64R2);
7824 gen_bitops(ctx, op1, rt, rs, sa, rd);
7827 check_insn(env, ctx, ISA_MIPS64R2);
7829 op2 = MASK_DBSHFL(ctx->opcode);
7830 gen_bshfl(ctx, op2, rt, rd);
7833 default: /* Invalid */
7834 MIPS_INVAL("special3");
7835 generate_exception(ctx, EXCP_RI);
7840 op1 = MASK_REGIMM(ctx->opcode);
7842 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7843 case OPC_BLTZAL ... OPC_BGEZALL:
7844 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7846 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7848 gen_trap(ctx, op1, rs, -1, imm);
7851 check_insn(env, ctx, ISA_MIPS32R2);
7854 default: /* Invalid */
7855 MIPS_INVAL("regimm");
7856 generate_exception(ctx, EXCP_RI);
7861 check_cp0_enabled(ctx);
7862 op1 = MASK_CP0(ctx->opcode);
7868 #if defined(TARGET_MIPS64)
7872 #ifndef CONFIG_USER_ONLY
7873 gen_cp0(env, ctx, op1, rt, rd);
7874 #endif /* !CONFIG_USER_ONLY */
7876 case OPC_C0_FIRST ... OPC_C0_LAST:
7877 #ifndef CONFIG_USER_ONLY
7878 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7879 #endif /* !CONFIG_USER_ONLY */
7882 #ifndef CONFIG_USER_ONLY
7884 TCGv t0 = tcg_temp_local_new();
7886 op2 = MASK_MFMC0(ctx->opcode);
7889 check_insn(env, ctx, ASE_MT);
7890 gen_helper_dmt(t0, t0);
7893 check_insn(env, ctx, ASE_MT);
7894 gen_helper_emt(t0, t0);
7897 check_insn(env, ctx, ASE_MT);
7898 gen_helper_dvpe(t0, t0);
7901 check_insn(env, ctx, ASE_MT);
7902 gen_helper_evpe(t0, t0);
7905 check_insn(env, ctx, ISA_MIPS32R2);
7906 save_cpu_state(ctx, 1);
7908 /* Stop translation as we may have switched the execution mode */
7909 ctx->bstate = BS_STOP;
7912 check_insn(env, ctx, ISA_MIPS32R2);
7913 save_cpu_state(ctx, 1);
7915 /* Stop translation as we may have switched the execution mode */
7916 ctx->bstate = BS_STOP;
7918 default: /* Invalid */
7919 MIPS_INVAL("mfmc0");
7920 generate_exception(ctx, EXCP_RI);
7923 gen_store_gpr(t0, rt);
7926 #endif /* !CONFIG_USER_ONLY */
7929 check_insn(env, ctx, ISA_MIPS32R2);
7930 gen_load_srsgpr(rt, rd);
7933 check_insn(env, ctx, ISA_MIPS32R2);
7934 gen_store_srsgpr(rt, rd);
7938 generate_exception(ctx, EXCP_RI);
7942 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7943 gen_arith_imm(env, ctx, op, rt, rs, imm);
7945 case OPC_J ... OPC_JAL: /* Jump */
7946 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7947 gen_compute_branch(ctx, op, rs, rt, offset);
7949 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7950 case OPC_BEQL ... OPC_BGTZL:
7951 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7953 case OPC_LB ... OPC_LWR: /* Load and stores */
7954 case OPC_SB ... OPC_SW:
7958 gen_ldst(ctx, op, rt, rs, imm);
7961 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7965 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7969 /* Floating point (COP1). */
7974 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7975 save_cpu_state(ctx, 1);
7976 check_cp1_enabled(ctx);
7977 gen_flt_ldst(ctx, op, rt, rs, imm);
7979 generate_exception_err(ctx, EXCP_CpU, 1);
7984 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7985 save_cpu_state(ctx, 1);
7986 check_cp1_enabled(ctx);
7987 op1 = MASK_CP1(ctx->opcode);
7991 check_insn(env, ctx, ISA_MIPS32R2);
7996 gen_cp1(ctx, op1, rt, rd);
7998 #if defined(TARGET_MIPS64)
8001 check_insn(env, ctx, ISA_MIPS3);
8002 gen_cp1(ctx, op1, rt, rd);
8008 check_insn(env, ctx, ASE_MIPS3D);
8011 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8012 (rt >> 2) & 0x7, imm << 2);
8019 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8024 generate_exception (ctx, EXCP_RI);
8028 generate_exception_err(ctx, EXCP_CpU, 1);
8038 /* COP2: Not implemented. */
8039 generate_exception_err(ctx, EXCP_CpU, 2);
8043 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8044 save_cpu_state(ctx, 1);
8045 check_cp1_enabled(ctx);
8046 op1 = MASK_CP3(ctx->opcode);
8054 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8072 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8076 generate_exception (ctx, EXCP_RI);
8080 generate_exception_err(ctx, EXCP_CpU, 1);
8084 #if defined(TARGET_MIPS64)
8085 /* MIPS64 opcodes */
8087 case OPC_LDL ... OPC_LDR:
8088 case OPC_SDL ... OPC_SDR:
8093 check_insn(env, ctx, ISA_MIPS3);
8095 gen_ldst(ctx, op, rt, rs, imm);
8097 case OPC_DADDI ... OPC_DADDIU:
8098 check_insn(env, ctx, ISA_MIPS3);
8100 gen_arith_imm(env, ctx, op, rt, rs, imm);
8104 check_insn(env, ctx, ASE_MIPS16);
8105 /* MIPS16: Not implemented. */
8107 check_insn(env, ctx, ASE_MDMX);
8108 /* MDMX: Not implemented. */
8109 default: /* Invalid */
8110 MIPS_INVAL("major opcode");
8111 generate_exception(ctx, EXCP_RI);
8114 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8115 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8116 /* Branches completion */
8117 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8118 ctx->bstate = BS_BRANCH;
8119 save_cpu_state(ctx, 0);
8120 /* FIXME: Need to clear can_do_io. */
8123 /* unconditional branch */
8124 MIPS_DEBUG("unconditional branch");
8125 gen_goto_tb(ctx, 0, ctx->btarget);
8128 /* blikely taken case */
8129 MIPS_DEBUG("blikely branch taken");
8130 gen_goto_tb(ctx, 0, ctx->btarget);
8133 /* Conditional branch */
8134 MIPS_DEBUG("conditional branch");
8136 int l1 = gen_new_label();
8138 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8139 gen_goto_tb(ctx, 1, ctx->pc + 4);
8141 gen_goto_tb(ctx, 0, ctx->btarget);
8145 /* unconditional branch to register */
8146 MIPS_DEBUG("branch to register");
8147 tcg_gen_mov_tl(cpu_PC, btarget);
8151 MIPS_DEBUG("unknown branch");
8158 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8162 target_ulong pc_start;
8163 uint16_t *gen_opc_end;
8170 qemu_log("search pc %d\n", search_pc);
8173 /* Leave some spare opc slots for branch handling. */
8174 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8178 ctx.bstate = BS_NONE;
8179 /* Restore delay slot state from the tb context. */
8180 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8181 restore_cpu_state(env, &ctx);
8182 #ifdef CONFIG_USER_ONLY
8183 ctx.mem_idx = MIPS_HFLAG_UM;
8185 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8188 max_insns = tb->cflags & CF_COUNT_MASK;
8190 max_insns = CF_COUNT_MASK;
8192 qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n");
8193 /* FIXME: This may print out stale hflags from env... */
8194 log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
8196 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags);
8198 while (ctx.bstate == BS_NONE) {
8199 if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
8200 TAILQ_FOREACH(bp, &env->breakpoints, entry) {
8201 if (bp->pc == ctx.pc) {
8202 save_cpu_state(&ctx, 1);
8203 ctx.bstate = BS_BRANCH;
8204 gen_helper_0i(raise_exception, EXCP_DEBUG);
8205 /* Include the breakpoint location or the tb won't
8206 * be flushed when it must be. */
8208 goto done_generating;
8214 j = gen_opc_ptr - gen_opc_buf;
8218 gen_opc_instr_start[lj++] = 0;
8220 gen_opc_pc[lj] = ctx.pc;
8221 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8222 gen_opc_instr_start[lj] = 1;
8223 gen_opc_icount[lj] = num_insns;
8225 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8227 ctx.opcode = ldl_code(ctx.pc);
8228 decode_opc(env, &ctx);
8232 if (env->singlestep_enabled)
8235 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8238 if (gen_opc_ptr >= gen_opc_end)
8241 if (num_insns >= max_insns)
8243 #if defined (MIPS_SINGLE_STEP)
8247 if (tb->cflags & CF_LAST_IO)
8249 if (env->singlestep_enabled) {
8250 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8251 gen_helper_0i(raise_exception, EXCP_DEBUG);
8253 switch (ctx.bstate) {
8255 gen_helper_interrupt_restart();
8256 gen_goto_tb(&ctx, 0, ctx.pc);
8259 save_cpu_state(&ctx, 0);
8260 gen_goto_tb(&ctx, 0, ctx.pc);
8263 gen_helper_interrupt_restart();
8272 gen_icount_end(tb, num_insns);
8273 *gen_opc_ptr = INDEX_op_end;
8275 j = gen_opc_ptr - gen_opc_buf;
8278 gen_opc_instr_start[lj++] = 0;
8280 tb->size = ctx.pc - pc_start;
8281 tb->icount = num_insns;
8285 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
8286 qemu_log("IN: %s\n", lookup_symbol(pc_start));
8287 log_target_disas(pc_start, ctx.pc - pc_start, 0);
8290 qemu_log_mask(CPU_LOG_TB_CPU, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8294 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8296 gen_intermediate_code_internal(env, tb, 0);
8299 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8301 gen_intermediate_code_internal(env, tb, 1);
8304 static void fpu_dump_state(CPUState *env, FILE *f,
8305 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8309 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8311 #define printfpr(fp) \
8314 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8315 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8316 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8319 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8320 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8321 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8322 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8323 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8328 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8329 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8330 get_float_exception_flags(&env->active_fpu.fp_status));
8331 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8332 fpu_fprintf(f, "%3s: ", fregnames[i]);
8333 printfpr(&env->active_fpu.fpr[i]);
8339 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8340 /* Debug help: The architecture requires 32bit code to maintain proper
8341 sign-extended values on 64bit machines. */
8343 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8346 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8347 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8352 if (!SIGN_EXT_P(env->active_tc.PC))
8353 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8354 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8355 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8356 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8357 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8358 if (!SIGN_EXT_P(env->btarget))
8359 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8361 for (i = 0; i < 32; i++) {
8362 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8363 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8366 if (!SIGN_EXT_P(env->CP0_EPC))
8367 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8368 if (!SIGN_EXT_P(env->CP0_LLAddr))
8369 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8373 void cpu_dump_state (CPUState *env, FILE *f,
8374 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8379 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",
8380 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8381 env->hflags, env->btarget, env->bcond);
8382 for (i = 0; i < 32; i++) {
8384 cpu_fprintf(f, "GPR%02d:", i);
8385 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8387 cpu_fprintf(f, "\n");
8390 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8391 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8392 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8393 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8394 if (env->hflags & MIPS_HFLAG_FPU)
8395 fpu_dump_state(env, f, cpu_fprintf, flags);
8396 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8397 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8401 static void mips_tcg_init(void)
8406 /* Initialize various static tables. */
8410 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
8411 for (i = 0; i < 32; i++)
8412 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
8413 offsetof(CPUState, active_tc.gpr[i]),
8415 cpu_PC = tcg_global_mem_new(TCG_AREG0,
8416 offsetof(CPUState, active_tc.PC), "PC");
8417 for (i = 0; i < MIPS_DSP_ACC; i++) {
8418 cpu_HI[i] = tcg_global_mem_new(TCG_AREG0,
8419 offsetof(CPUState, active_tc.HI[i]),
8421 cpu_LO[i] = tcg_global_mem_new(TCG_AREG0,
8422 offsetof(CPUState, active_tc.LO[i]),
8424 cpu_ACX[i] = tcg_global_mem_new(TCG_AREG0,
8425 offsetof(CPUState, active_tc.ACX[i]),
8428 cpu_dspctrl = tcg_global_mem_new(TCG_AREG0,
8429 offsetof(CPUState, active_tc.DSPControl),
8431 bcond = tcg_global_mem_new_i32(TCG_AREG0,
8432 offsetof(CPUState, bcond), "bcond");
8433 btarget = tcg_global_mem_new(TCG_AREG0,
8434 offsetof(CPUState, btarget), "btarget");
8435 for (i = 0; i < 32; i++)
8436 fpu_fpr32[i] = tcg_global_mem_new_i32(TCG_AREG0,
8437 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8439 for (i = 0; i < 32; i++)
8440 fpu_fpr32h[i] = tcg_global_mem_new_i32(TCG_AREG0,
8441 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8443 fpu_fcr0 = tcg_global_mem_new_i32(TCG_AREG0,
8444 offsetof(CPUState, active_fpu.fcr0),
8446 fpu_fcr31 = tcg_global_mem_new_i32(TCG_AREG0,
8447 offsetof(CPUState, active_fpu.fcr31),
8450 /* register helpers */
8451 #define GEN_HELPER 2
8457 #include "translate_init.c"
8459 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8462 const mips_def_t *def;
8464 def = cpu_mips_find_by_name(cpu_model);
8467 env = qemu_mallocz(sizeof(CPUMIPSState));
8468 env->cpu_model = def;
8471 env->cpu_model_str = cpu_model;
8477 void cpu_reset (CPUMIPSState *env)
8479 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
8480 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
8481 log_cpu_state(env, 0);
8484 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8489 #if defined(CONFIG_USER_ONLY)
8490 env->hflags = MIPS_HFLAG_UM;
8492 if (env->hflags & MIPS_HFLAG_BMASK) {
8493 /* If the exception was raised from a delay slot,
8494 come back to the jump. */
8495 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8497 env->CP0_ErrorEPC = env->active_tc.PC;
8499 env->active_tc.PC = (int32_t)0xBFC00000;
8501 /* SMP not implemented */
8502 env->CP0_EBase = 0x80000000;
8503 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8504 /* vectored interrupts not implemented, timer on int 7,
8505 no performance counters. */
8506 env->CP0_IntCtl = 0xe0000000;
8510 for (i = 0; i < 7; i++) {
8511 env->CP0_WatchLo[i] = 0;
8512 env->CP0_WatchHi[i] = 0x80000000;
8514 env->CP0_WatchLo[7] = 0;
8515 env->CP0_WatchHi[7] = 0;
8517 /* Count register increments in debug mode, EJTAG version 1 */
8518 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8519 env->hflags = MIPS_HFLAG_CP0;
8521 env->exception_index = EXCP_NONE;
8522 cpu_mips_register(env, env->cpu_model);
8525 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8526 unsigned long searched_pc, int pc_pos, void *puc)
8528 env->active_tc.PC = gen_opc_pc[pc_pos];
8529 env->hflags &= ~MIPS_HFLAG_BMASK;
8530 env->hflags |= gen_opc_hflags[pc_pos];