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, bcond;
433 static TCGv_i32 hflags;
434 static TCGv_i32 fpu_fcr0, fpu_fcr31;
436 #include "gen-icount.h"
438 #define gen_helper_0i(name, arg) do { \
439 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
440 gen_helper_##name(helper_tmp); \
441 tcg_temp_free_i32(helper_tmp); \
444 #define gen_helper_1i(name, arg1, arg2) do { \
445 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
446 gen_helper_##name(arg1, helper_tmp); \
447 tcg_temp_free_i32(helper_tmp); \
450 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
451 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
452 gen_helper_##name(arg1, arg2, helper_tmp); \
453 tcg_temp_free_i32(helper_tmp); \
456 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
457 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
458 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
459 tcg_temp_free_i32(helper_tmp); \
462 typedef struct DisasContext {
463 struct TranslationBlock *tb;
464 target_ulong pc, saved_pc;
466 /* Routine used to access memory */
468 uint32_t hflags, saved_hflags;
470 target_ulong btarget;
474 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
475 * exception condition */
476 BS_STOP = 1, /* We want to stop translation for any reason */
477 BS_BRANCH = 2, /* We reached a branch condition */
478 BS_EXCP = 3, /* We reached an exception condition */
481 static const char *regnames[] =
482 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
483 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
484 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
485 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
487 static const char *regnames_HI[] =
488 { "HI0", "HI1", "HI2", "HI3", };
490 static const char *regnames_LO[] =
491 { "LO0", "LO1", "LO2", "LO3", };
493 static const char *regnames_ACX[] =
494 { "ACX0", "ACX1", "ACX2", "ACX3", };
496 static const char *fregnames[] =
497 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
498 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
499 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
500 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
502 #ifdef MIPS_DEBUG_DISAS
503 #define MIPS_DEBUG(fmt, args...) \
504 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
505 TARGET_FMT_lx ": %08x " fmt "\n", \
506 ctx->pc, ctx->opcode , ##args)
507 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
509 #define MIPS_DEBUG(fmt, args...) do { } while(0)
510 #define LOG_DISAS(...) do { } while (0)
513 #define MIPS_INVAL(op) \
515 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
516 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
519 /* General purpose registers moves. */
520 static inline void gen_load_gpr (TCGv t, int reg)
523 tcg_gen_movi_tl(t, 0);
525 tcg_gen_mov_tl(t, cpu_gpr[reg]);
528 static inline void gen_store_gpr (TCGv t, int reg)
531 tcg_gen_mov_tl(cpu_gpr[reg], t);
534 /* Moves to/from ACX register. */
535 static inline void gen_load_ACX (TCGv t, int reg)
537 tcg_gen_mov_tl(t, cpu_ACX[reg]);
540 static inline void gen_store_ACX (TCGv t, int reg)
542 tcg_gen_mov_tl(cpu_ACX[reg], t);
545 /* Moves to/from shadow registers. */
546 static inline void gen_load_srsgpr (int from, int to)
548 TCGv r_tmp1 = tcg_temp_new();
551 tcg_gen_movi_tl(r_tmp1, 0);
553 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
554 TCGv_ptr addr = tcg_temp_new_ptr();
556 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
557 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
558 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
559 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
560 tcg_gen_ext_i32_ptr(addr, r_tmp2);
561 tcg_gen_add_ptr(addr, cpu_env, addr);
563 tcg_gen_ld_tl(r_tmp1, addr, sizeof(target_ulong) * from);
564 tcg_temp_free_ptr(addr);
565 tcg_temp_free_i32(r_tmp2);
567 gen_store_gpr(r_tmp1, to);
568 tcg_temp_free(r_tmp1);
571 static inline void gen_store_srsgpr (int from, int to)
574 TCGv r_tmp1 = tcg_temp_new();
575 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
576 TCGv_ptr addr = tcg_temp_new_ptr();
578 gen_load_gpr(r_tmp1, from);
579 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
580 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
581 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
582 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
583 tcg_gen_ext_i32_ptr(addr, r_tmp2);
584 tcg_gen_add_ptr(addr, cpu_env, addr);
586 tcg_gen_st_tl(r_tmp1, addr, sizeof(target_ulong) * to);
587 tcg_temp_free_ptr(addr);
588 tcg_temp_free_i32(r_tmp2);
589 tcg_temp_free(r_tmp1);
593 /* Floating point register moves. */
594 static inline void gen_load_fpr32 (TCGv_i32 t, int reg)
596 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUState, active_fpu.fpr[reg].w[FP_ENDIAN_IDX]));
599 static inline void gen_store_fpr32 (TCGv_i32 t, int reg)
601 tcg_gen_st_i32(t, cpu_env, offsetof(CPUState, active_fpu.fpr[reg].w[FP_ENDIAN_IDX]));
604 static inline void gen_load_fpr32h (TCGv_i32 t, int reg)
606 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUState, active_fpu.fpr[reg].w[!FP_ENDIAN_IDX]));
609 static inline void gen_store_fpr32h (TCGv_i32 t, int reg)
611 tcg_gen_st_i32(t, cpu_env, offsetof(CPUState, active_fpu.fpr[reg].w[!FP_ENDIAN_IDX]));
614 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
616 if (ctx->hflags & MIPS_HFLAG_F64) {
617 tcg_gen_ld_i64(t, cpu_env, offsetof(CPUState, active_fpu.fpr[reg].d));
619 TCGv_i32 t0 = tcg_temp_new_i32();
620 TCGv_i32 t1 = tcg_temp_new_i32();
621 gen_load_fpr32(t0, reg & ~1);
622 gen_load_fpr32(t1, reg | 1);
623 tcg_gen_concat_i32_i64(t, t0, t1);
624 tcg_temp_free_i32(t0);
625 tcg_temp_free_i32(t1);
629 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv_i64 t, int reg)
631 if (ctx->hflags & MIPS_HFLAG_F64) {
632 tcg_gen_st_i64(t, cpu_env, offsetof(CPUState, active_fpu.fpr[reg].d));
634 TCGv_i64 t0 = tcg_temp_new_i64();
635 TCGv_i32 t1 = tcg_temp_new_i32();
636 tcg_gen_trunc_i64_i32(t1, t);
637 gen_store_fpr32(t1, reg & ~1);
638 tcg_gen_shri_i64(t0, t, 32);
639 tcg_gen_trunc_i64_i32(t1, t0);
640 gen_store_fpr32(t1, reg | 1);
641 tcg_temp_free_i32(t1);
642 tcg_temp_free_i64(t0);
646 static inline void get_fp_cond (TCGv_i32 t)
648 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
649 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
651 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
652 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
653 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
654 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
655 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
656 tcg_temp_free_i32(r_tmp1);
657 tcg_temp_free_i32(r_tmp2);
660 #define FOP_CONDS(type, fmt, bits) \
661 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
662 TCGv_i##bits b, int cc) \
665 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
666 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
667 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
668 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
669 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
670 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
671 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
672 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
673 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
674 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
675 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
676 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
677 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
678 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
679 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
680 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
686 FOP_CONDS(abs, d, 64)
688 FOP_CONDS(abs, s, 32)
690 FOP_CONDS(abs, ps, 64)
694 #define OP_COND(name, cond) \
695 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
697 int l1 = gen_new_label(); \
698 int l2 = gen_new_label(); \
700 tcg_gen_brcond_tl(cond, t0, t1, l1); \
701 tcg_gen_movi_tl(ret, 0); \
704 tcg_gen_movi_tl(ret, 1); \
707 OP_COND(eq, TCG_COND_EQ);
708 OP_COND(ne, TCG_COND_NE);
709 OP_COND(ge, TCG_COND_GE);
710 OP_COND(geu, TCG_COND_GEU);
711 OP_COND(lt, TCG_COND_LT);
712 OP_COND(ltu, TCG_COND_LTU);
715 #define OP_CONDI(name, cond) \
716 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
718 int l1 = gen_new_label(); \
719 int l2 = gen_new_label(); \
721 tcg_gen_brcondi_tl(cond, t0, val, l1); \
722 tcg_gen_movi_tl(ret, 0); \
725 tcg_gen_movi_tl(ret, 1); \
728 OP_CONDI(lti, TCG_COND_LT);
729 OP_CONDI(ltiu, TCG_COND_LTU);
732 #define OP_CONDZ(name, cond) \
733 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
735 int l1 = gen_new_label(); \
736 int l2 = gen_new_label(); \
738 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
739 tcg_gen_movi_tl(ret, 0); \
742 tcg_gen_movi_tl(ret, 1); \
745 OP_CONDZ(gez, TCG_COND_GE);
746 OP_CONDZ(gtz, TCG_COND_GT);
747 OP_CONDZ(lez, TCG_COND_LE);
748 OP_CONDZ(ltz, TCG_COND_LT);
751 static inline void gen_save_pc(target_ulong pc)
753 tcg_gen_movi_tl(cpu_PC, pc);
756 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
758 LOG_DISAS("hflags %08x saved %08x\n", ctx->hflags, ctx->saved_hflags);
759 if (do_save_pc && ctx->pc != ctx->saved_pc) {
760 gen_save_pc(ctx->pc);
761 ctx->saved_pc = ctx->pc;
763 if (ctx->hflags != ctx->saved_hflags) {
764 tcg_gen_movi_i32(hflags, ctx->hflags);
765 ctx->saved_hflags = ctx->hflags;
766 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
772 tcg_gen_movi_tl(btarget, ctx->btarget);
778 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
780 ctx->saved_hflags = ctx->hflags;
781 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
787 ctx->btarget = env->btarget;
793 generate_exception_err (DisasContext *ctx, int excp, int err)
795 TCGv_i32 texcp = tcg_const_i32(excp);
796 TCGv_i32 terr = tcg_const_i32(err);
797 save_cpu_state(ctx, 1);
798 gen_helper_raise_exception_err(texcp, terr);
799 tcg_temp_free_i32(terr);
800 tcg_temp_free_i32(texcp);
801 gen_helper_interrupt_restart();
806 generate_exception (DisasContext *ctx, int excp)
808 save_cpu_state(ctx, 1);
809 gen_helper_0i(raise_exception, excp);
810 gen_helper_interrupt_restart();
814 /* Addresses computation */
815 static inline void gen_op_addr_add (DisasContext *ctx, TCGv t0, TCGv t1)
817 tcg_gen_add_tl(t0, t0, t1);
819 #if defined(TARGET_MIPS64)
820 /* For compatibility with 32-bit code, data reference in user mode
821 with Status_UX = 0 should be casted to 32-bit and sign extended.
822 See the MIPS64 PRA manual, section 4.10. */
823 if (((ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
824 !(ctx->hflags & MIPS_HFLAG_UX)) {
825 tcg_gen_ext32s_i64(t0, t0);
830 static inline void check_cp0_enabled(DisasContext *ctx)
832 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
833 generate_exception_err(ctx, EXCP_CpU, 1);
836 static inline void check_cp1_enabled(DisasContext *ctx)
838 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
839 generate_exception_err(ctx, EXCP_CpU, 1);
842 /* Verify that the processor is running with COP1X instructions enabled.
843 This is associated with the nabla symbol in the MIPS32 and MIPS64
846 static inline void check_cop1x(DisasContext *ctx)
848 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
849 generate_exception(ctx, EXCP_RI);
852 /* Verify that the processor is running with 64-bit floating-point
853 operations enabled. */
855 static inline void check_cp1_64bitmode(DisasContext *ctx)
857 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
858 generate_exception(ctx, EXCP_RI);
862 * Verify if floating point register is valid; an operation is not defined
863 * if bit 0 of any register specification is set and the FR bit in the
864 * Status register equals zero, since the register numbers specify an
865 * even-odd pair of adjacent coprocessor general registers. When the FR bit
866 * in the Status register equals one, both even and odd register numbers
867 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
869 * Multiple 64 bit wide registers can be checked by calling
870 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
872 static inline void check_cp1_registers(DisasContext *ctx, int regs)
874 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
875 generate_exception(ctx, EXCP_RI);
878 /* This code generates a "reserved instruction" exception if the
879 CPU does not support the instruction set corresponding to flags. */
880 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
882 if (unlikely(!(env->insn_flags & flags)))
883 generate_exception(ctx, EXCP_RI);
886 /* This code generates a "reserved instruction" exception if 64-bit
887 instructions are not enabled. */
888 static inline void check_mips_64(DisasContext *ctx)
890 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
891 generate_exception(ctx, EXCP_RI);
894 /* load/store instructions. */
895 #define OP_LD(insn,fname) \
896 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
898 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
905 #if defined(TARGET_MIPS64)
911 #define OP_ST(insn,fname) \
912 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
914 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
919 #if defined(TARGET_MIPS64)
924 #define OP_LD_ATOMIC(insn,fname) \
925 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
927 tcg_gen_mov_tl(t1, t0); \
928 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
929 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
931 OP_LD_ATOMIC(ll,ld32s);
932 #if defined(TARGET_MIPS64)
933 OP_LD_ATOMIC(lld,ld64);
937 #define OP_ST_ATOMIC(insn,fname,almask) \
938 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
940 TCGv r_tmp = tcg_temp_local_new(); \
941 int l1 = gen_new_label(); \
942 int l2 = gen_new_label(); \
943 int l3 = gen_new_label(); \
945 tcg_gen_andi_tl(r_tmp, t0, almask); \
946 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
947 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
948 generate_exception(ctx, EXCP_AdES); \
950 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
951 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
952 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
953 tcg_gen_movi_tl(t0, 1); \
956 tcg_gen_movi_tl(t0, 0); \
958 tcg_temp_free(r_tmp); \
960 OP_ST_ATOMIC(sc,st32,0x3);
961 #if defined(TARGET_MIPS64)
962 OP_ST_ATOMIC(scd,st64,0x7);
967 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
968 int base, int16_t offset)
970 const char *opn = "ldst";
971 TCGv t0 = tcg_temp_local_new();
972 TCGv t1 = tcg_temp_local_new();
975 tcg_gen_movi_tl(t0, offset);
976 } else if (offset == 0) {
977 gen_load_gpr(t0, base);
979 tcg_gen_movi_tl(t0, offset);
980 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
982 /* Don't do NOP if destination is zero: we must perform the actual
985 #if defined(TARGET_MIPS64)
987 op_ldst_lwu(t0, ctx);
988 gen_store_gpr(t0, rt);
993 gen_store_gpr(t0, rt);
997 op_ldst_lld(t0, t1, ctx);
998 gen_store_gpr(t0, rt);
1002 gen_load_gpr(t1, rt);
1003 op_ldst_sd(t0, t1, ctx);
1007 save_cpu_state(ctx, 1);
1008 gen_load_gpr(t1, rt);
1009 op_ldst_scd(t0, t1, ctx);
1010 gen_store_gpr(t0, rt);
1014 save_cpu_state(ctx, 1);
1015 gen_load_gpr(t1, rt);
1016 gen_helper_3i(ldl, t1, t0, t1, ctx->mem_idx);
1017 gen_store_gpr(t1, rt);
1021 save_cpu_state(ctx, 1);
1022 gen_load_gpr(t1, rt);
1023 gen_helper_2i(sdl, t0, t1, ctx->mem_idx);
1027 save_cpu_state(ctx, 1);
1028 gen_load_gpr(t1, rt);
1029 gen_helper_3i(ldr, t1, t0, t1, ctx->mem_idx);
1030 gen_store_gpr(t1, rt);
1034 save_cpu_state(ctx, 1);
1035 gen_load_gpr(t1, rt);
1036 gen_helper_2i(sdr, t0, t1, ctx->mem_idx);
1041 op_ldst_lw(t0, ctx);
1042 gen_store_gpr(t0, rt);
1046 gen_load_gpr(t1, rt);
1047 op_ldst_sw(t0, t1, ctx);
1051 op_ldst_lh(t0, ctx);
1052 gen_store_gpr(t0, rt);
1056 gen_load_gpr(t1, rt);
1057 op_ldst_sh(t0, t1, ctx);
1061 op_ldst_lhu(t0, ctx);
1062 gen_store_gpr(t0, rt);
1066 op_ldst_lb(t0, ctx);
1067 gen_store_gpr(t0, rt);
1071 gen_load_gpr(t1, rt);
1072 op_ldst_sb(t0, t1, ctx);
1076 op_ldst_lbu(t0, ctx);
1077 gen_store_gpr(t0, rt);
1081 save_cpu_state(ctx, 1);
1082 gen_load_gpr(t1, rt);
1083 gen_helper_3i(lwl, t1, t0, t1, ctx->mem_idx);
1084 gen_store_gpr(t1, rt);
1088 save_cpu_state(ctx, 1);
1089 gen_load_gpr(t1, rt);
1090 gen_helper_2i(swl, t0, t1, ctx->mem_idx);
1094 save_cpu_state(ctx, 1);
1095 gen_load_gpr(t1, rt);
1096 gen_helper_3i(lwr, t1, t0, t1, ctx->mem_idx);
1097 gen_store_gpr(t1, rt);
1101 save_cpu_state(ctx, 1);
1102 gen_load_gpr(t1, rt);
1103 gen_helper_2i(swr, t0, t1, ctx->mem_idx);
1107 op_ldst_ll(t0, t1, ctx);
1108 gen_store_gpr(t0, rt);
1112 save_cpu_state(ctx, 1);
1113 gen_load_gpr(t1, rt);
1114 op_ldst_sc(t0, t1, ctx);
1115 gen_store_gpr(t0, rt);
1120 generate_exception(ctx, EXCP_RI);
1123 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1129 /* Load and store */
1130 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1131 int base, int16_t offset)
1133 const char *opn = "flt_ldst";
1134 TCGv t0 = tcg_temp_local_new();
1137 tcg_gen_movi_tl(t0, offset);
1138 } else if (offset == 0) {
1139 gen_load_gpr(t0, base);
1141 tcg_gen_movi_tl(t0, offset);
1142 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
1144 /* Don't do NOP if destination is zero: we must perform the actual
1149 TCGv_i32 fp0 = tcg_temp_new_i32();
1150 TCGv t1 = tcg_temp_new();
1152 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
1153 tcg_gen_trunc_tl_i32(fp0, t1);
1154 gen_store_fpr32(fp0, ft);
1156 tcg_temp_free_i32(fp0);
1162 TCGv_i32 fp0 = tcg_temp_new_i32();
1163 TCGv t1 = tcg_temp_new();
1165 gen_load_fpr32(fp0, ft);
1166 tcg_gen_extu_i32_tl(t1, fp0);
1167 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
1169 tcg_temp_free_i32(fp0);
1175 TCGv_i64 fp0 = tcg_temp_new_i64();
1177 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1178 gen_store_fpr64(ctx, fp0, ft);
1179 tcg_temp_free_i64(fp0);
1185 TCGv_i64 fp0 = tcg_temp_new_i64();
1187 gen_load_fpr64(ctx, fp0, ft);
1188 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1189 tcg_temp_free_i64(fp0);
1195 generate_exception(ctx, EXCP_RI);
1198 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1203 /* Arithmetic with immediate operand */
1204 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1205 int rt, int rs, int16_t imm)
1208 const char *opn = "imm arith";
1209 TCGv t0 = tcg_temp_local_new();
1211 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1212 /* If no destination, treat it as a NOP.
1213 For addi, we must generate the overflow exception when needed. */
1217 uimm = (uint16_t)imm;
1221 #if defined(TARGET_MIPS64)
1227 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1232 gen_load_gpr(t0, rs);
1235 tcg_gen_movi_tl(t0, imm << 16);
1240 #if defined(TARGET_MIPS64)
1249 gen_load_gpr(t0, rs);
1255 TCGv r_tmp1 = tcg_temp_new();
1256 TCGv r_tmp2 = tcg_temp_new();
1257 int l1 = gen_new_label();
1259 save_cpu_state(ctx, 1);
1260 tcg_gen_ext32s_tl(r_tmp1, t0);
1261 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1263 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1264 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1265 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1266 tcg_temp_free(r_tmp2);
1267 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1268 /* operands of same sign, result different sign */
1269 generate_exception(ctx, EXCP_OVERFLOW);
1271 tcg_temp_free(r_tmp1);
1273 tcg_gen_ext32s_tl(t0, t0);
1278 tcg_gen_addi_tl(t0, t0, uimm);
1279 tcg_gen_ext32s_tl(t0, t0);
1282 #if defined(TARGET_MIPS64)
1285 TCGv r_tmp1 = tcg_temp_new();
1286 TCGv r_tmp2 = tcg_temp_new();
1287 int l1 = gen_new_label();
1289 save_cpu_state(ctx, 1);
1290 tcg_gen_mov_tl(r_tmp1, t0);
1291 tcg_gen_addi_tl(t0, t0, uimm);
1293 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1294 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1295 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1296 tcg_temp_free(r_tmp2);
1297 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1298 /* operands of same sign, result different sign */
1299 generate_exception(ctx, EXCP_OVERFLOW);
1301 tcg_temp_free(r_tmp1);
1306 tcg_gen_addi_tl(t0, t0, uimm);
1311 gen_op_lti(t0, t0, uimm);
1315 gen_op_ltiu(t0, t0, uimm);
1319 tcg_gen_andi_tl(t0, t0, uimm);
1323 tcg_gen_ori_tl(t0, t0, uimm);
1327 tcg_gen_xori_tl(t0, t0, uimm);
1334 tcg_gen_shli_tl(t0, t0, uimm);
1335 tcg_gen_ext32s_tl(t0, t0);
1339 tcg_gen_ext32s_tl(t0, t0);
1340 tcg_gen_sari_tl(t0, t0, uimm);
1344 switch ((ctx->opcode >> 21) & 0x1f) {
1347 tcg_gen_ext32u_tl(t0, t0);
1348 tcg_gen_shri_tl(t0, t0, uimm);
1350 tcg_gen_ext32s_tl(t0, t0);
1355 /* rotr is decoded as srl on non-R2 CPUs */
1356 if (env->insn_flags & ISA_MIPS32R2) {
1358 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1360 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1361 tcg_gen_rotri_i32(r_tmp1, r_tmp1, uimm);
1362 tcg_gen_ext_i32_tl(t0, r_tmp1);
1363 tcg_temp_free_i32(r_tmp1);
1368 tcg_gen_ext32u_tl(t0, t0);
1369 tcg_gen_shri_tl(t0, t0, uimm);
1371 tcg_gen_ext32s_tl(t0, t0);
1377 MIPS_INVAL("invalid srl flag");
1378 generate_exception(ctx, EXCP_RI);
1382 #if defined(TARGET_MIPS64)
1384 tcg_gen_shli_tl(t0, t0, uimm);
1388 tcg_gen_sari_tl(t0, t0, uimm);
1392 switch ((ctx->opcode >> 21) & 0x1f) {
1394 tcg_gen_shri_tl(t0, t0, uimm);
1398 /* drotr is decoded as dsrl on non-R2 CPUs */
1399 if (env->insn_flags & ISA_MIPS32R2) {
1401 tcg_gen_rotri_tl(t0, t0, uimm);
1405 tcg_gen_shri_tl(t0, t0, uimm);
1410 MIPS_INVAL("invalid dsrl flag");
1411 generate_exception(ctx, EXCP_RI);
1416 tcg_gen_shli_tl(t0, t0, uimm + 32);
1420 tcg_gen_sari_tl(t0, t0, uimm + 32);
1424 switch ((ctx->opcode >> 21) & 0x1f) {
1426 tcg_gen_shri_tl(t0, t0, uimm + 32);
1430 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1431 if (env->insn_flags & ISA_MIPS32R2) {
1432 tcg_gen_rotri_tl(t0, t0, uimm + 32);
1435 tcg_gen_shri_tl(t0, t0, uimm + 32);
1440 MIPS_INVAL("invalid dsrl32 flag");
1441 generate_exception(ctx, EXCP_RI);
1448 generate_exception(ctx, EXCP_RI);
1451 gen_store_gpr(t0, rt);
1452 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1458 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1459 int rd, int rs, int rt)
1461 const char *opn = "arith";
1462 TCGv t0 = tcg_temp_local_new();
1463 TCGv t1 = tcg_temp_local_new();
1465 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1466 && opc != OPC_DADD && opc != OPC_DSUB) {
1467 /* If no destination, treat it as a NOP.
1468 For add & sub, we must generate the overflow exception when needed. */
1472 gen_load_gpr(t0, rs);
1473 /* Specialcase the conventional move operation. */
1474 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1475 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1476 gen_store_gpr(t0, rd);
1479 gen_load_gpr(t1, rt);
1483 TCGv r_tmp1 = tcg_temp_new();
1484 TCGv r_tmp2 = tcg_temp_new();
1485 int l1 = gen_new_label();
1487 save_cpu_state(ctx, 1);
1488 tcg_gen_ext32s_tl(r_tmp1, t0);
1489 tcg_gen_ext32s_tl(r_tmp2, t1);
1490 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1492 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1493 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1494 tcg_gen_xor_tl(r_tmp2, t0, t1);
1495 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1496 tcg_temp_free(r_tmp2);
1497 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1498 /* operands of same sign, result different sign */
1499 generate_exception(ctx, EXCP_OVERFLOW);
1501 tcg_temp_free(r_tmp1);
1503 tcg_gen_ext32s_tl(t0, t0);
1508 tcg_gen_add_tl(t0, t0, t1);
1509 tcg_gen_ext32s_tl(t0, t0);
1514 TCGv r_tmp1 = tcg_temp_new();
1515 TCGv r_tmp2 = tcg_temp_new();
1516 int l1 = gen_new_label();
1518 save_cpu_state(ctx, 1);
1519 tcg_gen_ext32s_tl(r_tmp1, t0);
1520 tcg_gen_ext32s_tl(r_tmp2, t1);
1521 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1523 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1524 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1525 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1526 tcg_temp_free(r_tmp2);
1527 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1528 /* operands of different sign, first operand and result different sign */
1529 generate_exception(ctx, EXCP_OVERFLOW);
1531 tcg_temp_free(r_tmp1);
1533 tcg_gen_ext32s_tl(t0, t0);
1538 tcg_gen_sub_tl(t0, t0, t1);
1539 tcg_gen_ext32s_tl(t0, t0);
1542 #if defined(TARGET_MIPS64)
1545 TCGv r_tmp1 = tcg_temp_new();
1546 TCGv r_tmp2 = tcg_temp_new();
1547 int l1 = gen_new_label();
1549 save_cpu_state(ctx, 1);
1550 tcg_gen_mov_tl(r_tmp1, t0);
1551 tcg_gen_add_tl(t0, t0, t1);
1553 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1554 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1555 tcg_gen_xor_tl(r_tmp2, t0, t1);
1556 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1557 tcg_temp_free(r_tmp2);
1558 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1559 /* operands of same sign, result different sign */
1560 generate_exception(ctx, EXCP_OVERFLOW);
1562 tcg_temp_free(r_tmp1);
1567 tcg_gen_add_tl(t0, t0, t1);
1572 TCGv r_tmp1 = tcg_temp_new();
1573 TCGv r_tmp2 = tcg_temp_new();
1574 int l1 = gen_new_label();
1576 save_cpu_state(ctx, 1);
1577 tcg_gen_mov_tl(r_tmp1, t0);
1578 tcg_gen_sub_tl(t0, t0, t1);
1580 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1581 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1582 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1583 tcg_temp_free(r_tmp2);
1584 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1585 /* operands of different sign, first operand and result different sign */
1586 generate_exception(ctx, EXCP_OVERFLOW);
1588 tcg_temp_free(r_tmp1);
1593 tcg_gen_sub_tl(t0, t0, t1);
1598 gen_op_lt(t0, t0, t1);
1602 gen_op_ltu(t0, t0, t1);
1606 tcg_gen_and_tl(t0, t0, t1);
1610 tcg_gen_nor_tl(t0, t0, t1);
1614 tcg_gen_or_tl(t0, t0, t1);
1618 tcg_gen_xor_tl(t0, t0, t1);
1622 tcg_gen_mul_tl(t0, t0, t1);
1623 tcg_gen_ext32s_tl(t0, t0);
1628 int l1 = gen_new_label();
1630 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1631 gen_store_gpr(t0, rd);
1638 int l1 = gen_new_label();
1640 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1641 gen_store_gpr(t0, rd);
1647 tcg_gen_andi_tl(t0, t0, 0x1f);
1648 tcg_gen_shl_tl(t0, t1, t0);
1649 tcg_gen_ext32s_tl(t0, t0);
1653 tcg_gen_ext32s_tl(t1, t1);
1654 tcg_gen_andi_tl(t0, t0, 0x1f);
1655 tcg_gen_sar_tl(t0, t1, t0);
1659 switch ((ctx->opcode >> 6) & 0x1f) {
1661 tcg_gen_ext32u_tl(t1, t1);
1662 tcg_gen_andi_tl(t0, t0, 0x1f);
1663 tcg_gen_shr_tl(t0, t1, t0);
1664 tcg_gen_ext32s_tl(t0, t0);
1668 /* rotrv is decoded as srlv on non-R2 CPUs */
1669 if (env->insn_flags & ISA_MIPS32R2) {
1670 int l1 = gen_new_label();
1671 int l2 = gen_new_label();
1673 tcg_gen_andi_tl(t0, t0, 0x1f);
1674 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1676 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1677 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
1679 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1680 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1681 tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2);
1682 tcg_temp_free_i32(r_tmp1);
1683 tcg_temp_free_i32(r_tmp2);
1687 tcg_gen_mov_tl(t0, t1);
1691 tcg_gen_ext32u_tl(t1, t1);
1692 tcg_gen_andi_tl(t0, t0, 0x1f);
1693 tcg_gen_shr_tl(t0, t1, t0);
1694 tcg_gen_ext32s_tl(t0, t0);
1699 MIPS_INVAL("invalid srlv flag");
1700 generate_exception(ctx, EXCP_RI);
1704 #if defined(TARGET_MIPS64)
1706 tcg_gen_andi_tl(t0, t0, 0x3f);
1707 tcg_gen_shl_tl(t0, t1, t0);
1711 tcg_gen_andi_tl(t0, t0, 0x3f);
1712 tcg_gen_sar_tl(t0, t1, t0);
1716 switch ((ctx->opcode >> 6) & 0x1f) {
1718 tcg_gen_andi_tl(t0, t0, 0x3f);
1719 tcg_gen_shr_tl(t0, t1, t0);
1723 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1724 if (env->insn_flags & ISA_MIPS32R2) {
1725 int l1 = gen_new_label();
1726 int l2 = gen_new_label();
1728 tcg_gen_andi_tl(t0, t0, 0x3f);
1729 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1731 tcg_gen_rotr_tl(t0, t1, t0);
1735 tcg_gen_mov_tl(t0, t1);
1739 tcg_gen_andi_tl(t0, t0, 0x3f);
1740 tcg_gen_shr_tl(t0, t1, t0);
1745 MIPS_INVAL("invalid dsrlv flag");
1746 generate_exception(ctx, EXCP_RI);
1753 generate_exception(ctx, EXCP_RI);
1756 gen_store_gpr(t0, rd);
1758 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1764 /* Arithmetic on HI/LO registers */
1765 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1767 const char *opn = "hilo";
1769 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1776 tcg_gen_mov_tl(cpu_gpr[reg], cpu_HI[0]);
1780 tcg_gen_mov_tl(cpu_gpr[reg], cpu_LO[0]);
1785 tcg_gen_mov_tl(cpu_HI[0], cpu_gpr[reg]);
1787 tcg_gen_movi_tl(cpu_HI[0], 0);
1792 tcg_gen_mov_tl(cpu_LO[0], cpu_gpr[reg]);
1794 tcg_gen_movi_tl(cpu_LO[0], 0);
1798 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1801 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1804 const char *opn = "mul/div";
1810 #if defined(TARGET_MIPS64)
1814 t0 = tcg_temp_local_new();
1815 t1 = tcg_temp_local_new();
1818 t0 = tcg_temp_new();
1819 t1 = tcg_temp_new();
1823 gen_load_gpr(t0, rs);
1824 gen_load_gpr(t1, rt);
1828 int l1 = gen_new_label();
1829 int l2 = gen_new_label();
1831 tcg_gen_ext32s_tl(t0, t0);
1832 tcg_gen_ext32s_tl(t1, t1);
1833 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1834 tcg_gen_brcondi_tl(TCG_COND_NE, t0, INT_MIN, l2);
1835 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1, l2);
1837 tcg_gen_mov_tl(cpu_LO[0], t0);
1838 tcg_gen_movi_tl(cpu_HI[0], 0);
1841 tcg_gen_div_tl(cpu_LO[0], t0, t1);
1842 tcg_gen_rem_tl(cpu_HI[0], t0, t1);
1843 tcg_gen_ext32s_tl(cpu_LO[0], cpu_LO[0]);
1844 tcg_gen_ext32s_tl(cpu_HI[0], cpu_HI[0]);
1851 int l1 = gen_new_label();
1853 tcg_gen_ext32u_tl(t0, t0);
1854 tcg_gen_ext32u_tl(t1, t1);
1855 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1856 tcg_gen_divu_tl(cpu_LO[0], t0, t1);
1857 tcg_gen_remu_tl(cpu_HI[0], t0, t1);
1858 tcg_gen_ext32s_tl(cpu_LO[0], cpu_LO[0]);
1859 tcg_gen_ext32s_tl(cpu_HI[0], cpu_HI[0]);
1866 TCGv_i64 t2 = tcg_temp_new_i64();
1867 TCGv_i64 t3 = tcg_temp_new_i64();
1869 tcg_gen_ext_tl_i64(t2, t0);
1870 tcg_gen_ext_tl_i64(t3, t1);
1871 tcg_gen_mul_i64(t2, t2, t3);
1872 tcg_temp_free_i64(t3);
1873 tcg_gen_trunc_i64_tl(t0, t2);
1874 tcg_gen_shri_i64(t2, t2, 32);
1875 tcg_gen_trunc_i64_tl(t1, t2);
1876 tcg_temp_free_i64(t2);
1877 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1878 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1884 TCGv_i64 t2 = tcg_temp_new_i64();
1885 TCGv_i64 t3 = tcg_temp_new_i64();
1887 tcg_gen_ext32u_tl(t0, t0);
1888 tcg_gen_ext32u_tl(t1, t1);
1889 tcg_gen_extu_tl_i64(t2, t0);
1890 tcg_gen_extu_tl_i64(t3, t1);
1891 tcg_gen_mul_i64(t2, t2, t3);
1892 tcg_temp_free_i64(t3);
1893 tcg_gen_trunc_i64_tl(t0, t2);
1894 tcg_gen_shri_i64(t2, t2, 32);
1895 tcg_gen_trunc_i64_tl(t1, t2);
1896 tcg_temp_free_i64(t2);
1897 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1898 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1902 #if defined(TARGET_MIPS64)
1905 int l1 = gen_new_label();
1906 int l2 = gen_new_label();
1908 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1909 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
1910 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
1911 tcg_gen_mov_tl(cpu_LO[0], t0);
1912 tcg_gen_movi_tl(cpu_HI[0], 0);
1915 tcg_gen_div_i64(cpu_LO[0], t0, t1);
1916 tcg_gen_rem_i64(cpu_HI[0], t0, t1);
1923 int l1 = gen_new_label();
1925 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1926 tcg_gen_divu_i64(cpu_LO[0], t0, t1);
1927 tcg_gen_remu_i64(cpu_HI[0], t0, t1);
1933 gen_helper_dmult(t0, t1);
1937 gen_helper_dmultu(t0, t1);
1943 TCGv_i64 t2 = tcg_temp_new_i64();
1944 TCGv_i64 t3 = tcg_temp_new_i64();
1946 tcg_gen_ext_tl_i64(t2, t0);
1947 tcg_gen_ext_tl_i64(t3, t1);
1948 tcg_gen_mul_i64(t2, t2, t3);
1949 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
1950 tcg_gen_add_i64(t2, t2, t3);
1951 tcg_temp_free_i64(t3);
1952 tcg_gen_trunc_i64_tl(t0, t2);
1953 tcg_gen_shri_i64(t2, t2, 32);
1954 tcg_gen_trunc_i64_tl(t1, t2);
1955 tcg_temp_free_i64(t2);
1956 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1957 tcg_gen_ext32s_tl(cpu_LO[1], t1);
1963 TCGv_i64 t2 = tcg_temp_new_i64();
1964 TCGv_i64 t3 = tcg_temp_new_i64();
1966 tcg_gen_ext32u_tl(t0, t0);
1967 tcg_gen_ext32u_tl(t1, t1);
1968 tcg_gen_extu_tl_i64(t2, t0);
1969 tcg_gen_extu_tl_i64(t3, t1);
1970 tcg_gen_mul_i64(t2, t2, t3);
1971 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
1972 tcg_gen_add_i64(t2, t2, t3);
1973 tcg_temp_free_i64(t3);
1974 tcg_gen_trunc_i64_tl(t0, t2);
1975 tcg_gen_shri_i64(t2, t2, 32);
1976 tcg_gen_trunc_i64_tl(t1, t2);
1977 tcg_temp_free_i64(t2);
1978 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1979 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1985 TCGv_i64 t2 = tcg_temp_new_i64();
1986 TCGv_i64 t3 = tcg_temp_new_i64();
1988 tcg_gen_ext_tl_i64(t2, t0);
1989 tcg_gen_ext_tl_i64(t3, t1);
1990 tcg_gen_mul_i64(t2, t2, t3);
1991 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
1992 tcg_gen_sub_i64(t2, t2, t3);
1993 tcg_temp_free_i64(t3);
1994 tcg_gen_trunc_i64_tl(t0, t2);
1995 tcg_gen_shri_i64(t2, t2, 32);
1996 tcg_gen_trunc_i64_tl(t1, t2);
1997 tcg_temp_free_i64(t2);
1998 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1999 tcg_gen_ext32s_tl(cpu_HI[0], t1);
2005 TCGv_i64 t2 = tcg_temp_new_i64();
2006 TCGv_i64 t3 = tcg_temp_new_i64();
2008 tcg_gen_ext32u_tl(t0, t0);
2009 tcg_gen_ext32u_tl(t1, t1);
2010 tcg_gen_extu_tl_i64(t2, t0);
2011 tcg_gen_extu_tl_i64(t3, t1);
2012 tcg_gen_mul_i64(t2, t2, t3);
2013 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
2014 tcg_gen_sub_i64(t2, t2, t3);
2015 tcg_temp_free_i64(t3);
2016 tcg_gen_trunc_i64_tl(t0, t2);
2017 tcg_gen_shri_i64(t2, t2, 32);
2018 tcg_gen_trunc_i64_tl(t1, t2);
2019 tcg_temp_free_i64(t2);
2020 tcg_gen_ext32s_tl(cpu_LO[0], t0);
2021 tcg_gen_ext32s_tl(cpu_HI[0], t1);
2027 generate_exception(ctx, EXCP_RI);
2030 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2036 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2037 int rd, int rs, int rt)
2039 const char *opn = "mul vr54xx";
2040 TCGv t0 = tcg_temp_new();
2041 TCGv t1 = tcg_temp_new();
2043 gen_load_gpr(t0, rs);
2044 gen_load_gpr(t1, rt);
2047 case OPC_VR54XX_MULS:
2048 gen_helper_muls(t0, t0, t1);
2051 case OPC_VR54XX_MULSU:
2052 gen_helper_mulsu(t0, t0, t1);
2055 case OPC_VR54XX_MACC:
2056 gen_helper_macc(t0, t0, t1);
2059 case OPC_VR54XX_MACCU:
2060 gen_helper_maccu(t0, t0, t1);
2063 case OPC_VR54XX_MSAC:
2064 gen_helper_msac(t0, t0, t1);
2067 case OPC_VR54XX_MSACU:
2068 gen_helper_msacu(t0, t0, t1);
2071 case OPC_VR54XX_MULHI:
2072 gen_helper_mulhi(t0, t0, t1);
2075 case OPC_VR54XX_MULHIU:
2076 gen_helper_mulhiu(t0, t0, t1);
2079 case OPC_VR54XX_MULSHI:
2080 gen_helper_mulshi(t0, t0, t1);
2083 case OPC_VR54XX_MULSHIU:
2084 gen_helper_mulshiu(t0, t0, t1);
2087 case OPC_VR54XX_MACCHI:
2088 gen_helper_macchi(t0, t0, t1);
2091 case OPC_VR54XX_MACCHIU:
2092 gen_helper_macchiu(t0, t0, t1);
2095 case OPC_VR54XX_MSACHI:
2096 gen_helper_msachi(t0, t0, t1);
2099 case OPC_VR54XX_MSACHIU:
2100 gen_helper_msachiu(t0, t0, t1);
2104 MIPS_INVAL("mul vr54xx");
2105 generate_exception(ctx, EXCP_RI);
2108 gen_store_gpr(t0, rd);
2109 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2116 static void gen_cl (DisasContext *ctx, uint32_t opc,
2119 const char *opn = "CLx";
2127 t0 = tcg_temp_new();
2128 gen_load_gpr(t0, rs);
2131 gen_helper_clo(cpu_gpr[rd], t0);
2135 gen_helper_clz(cpu_gpr[rd], t0);
2138 #if defined(TARGET_MIPS64)
2140 gen_helper_dclo(cpu_gpr[rd], t0);
2144 gen_helper_dclz(cpu_gpr[rd], t0);
2149 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2154 static void gen_trap (DisasContext *ctx, uint32_t opc,
2155 int rs, int rt, int16_t imm)
2158 TCGv t0 = tcg_temp_new();
2159 TCGv t1 = tcg_temp_new();
2162 /* Load needed operands */
2170 /* Compare two registers */
2172 gen_load_gpr(t0, rs);
2173 gen_load_gpr(t1, rt);
2183 /* Compare register to immediate */
2184 if (rs != 0 || imm != 0) {
2185 gen_load_gpr(t0, rs);
2186 tcg_gen_movi_tl(t1, (int32_t)imm);
2193 case OPC_TEQ: /* rs == rs */
2194 case OPC_TEQI: /* r0 == 0 */
2195 case OPC_TGE: /* rs >= rs */
2196 case OPC_TGEI: /* r0 >= 0 */
2197 case OPC_TGEU: /* rs >= rs unsigned */
2198 case OPC_TGEIU: /* r0 >= 0 unsigned */
2200 generate_exception(ctx, EXCP_TRAP);
2202 case OPC_TLT: /* rs < rs */
2203 case OPC_TLTI: /* r0 < 0 */
2204 case OPC_TLTU: /* rs < rs unsigned */
2205 case OPC_TLTIU: /* r0 < 0 unsigned */
2206 case OPC_TNE: /* rs != rs */
2207 case OPC_TNEI: /* r0 != 0 */
2208 /* Never trap: treat as NOP. */
2212 int l1 = gen_new_label();
2217 tcg_gen_brcond_tl(TCG_COND_NE, t0, t1, l1);
2221 tcg_gen_brcond_tl(TCG_COND_LT, t0, t1, l1);
2225 tcg_gen_brcond_tl(TCG_COND_LTU, t0, t1, l1);
2229 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
2233 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
2237 tcg_gen_brcond_tl(TCG_COND_EQ, t0, t1, l1);
2240 generate_exception(ctx, EXCP_TRAP);
2247 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2249 TranslationBlock *tb;
2251 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2254 tcg_gen_exit_tb((long)tb + n);
2261 /* Branches (before delay slot) */
2262 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2263 int rs, int rt, int32_t offset)
2265 target_ulong btgt = -1;
2267 int bcond_compute = 0;
2268 TCGv t0 = tcg_temp_new();
2269 TCGv t1 = tcg_temp_new();
2271 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2272 #ifdef MIPS_DEBUG_DISAS
2273 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx "\n", ctx->pc);
2275 generate_exception(ctx, EXCP_RI);
2279 /* Load needed operands */
2285 /* Compare two registers */
2287 gen_load_gpr(t0, rs);
2288 gen_load_gpr(t1, rt);
2291 btgt = ctx->pc + 4 + offset;
2305 /* Compare to zero */
2307 gen_load_gpr(t0, rs);
2310 btgt = ctx->pc + 4 + offset;
2314 /* Jump to immediate */
2315 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2319 /* Jump to register */
2320 if (offset != 0 && offset != 16) {
2321 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2322 others are reserved. */
2323 MIPS_INVAL("jump hint");
2324 generate_exception(ctx, EXCP_RI);
2327 gen_load_gpr(btarget, rs);
2330 MIPS_INVAL("branch/jump");
2331 generate_exception(ctx, EXCP_RI);
2334 if (bcond_compute == 0) {
2335 /* No condition to be computed */
2337 case OPC_BEQ: /* rx == rx */
2338 case OPC_BEQL: /* rx == rx likely */
2339 case OPC_BGEZ: /* 0 >= 0 */
2340 case OPC_BGEZL: /* 0 >= 0 likely */
2341 case OPC_BLEZ: /* 0 <= 0 */
2342 case OPC_BLEZL: /* 0 <= 0 likely */
2344 ctx->hflags |= MIPS_HFLAG_B;
2345 MIPS_DEBUG("balways");
2347 case OPC_BGEZAL: /* 0 >= 0 */
2348 case OPC_BGEZALL: /* 0 >= 0 likely */
2349 /* Always take and link */
2351 ctx->hflags |= MIPS_HFLAG_B;
2352 MIPS_DEBUG("balways and link");
2354 case OPC_BNE: /* rx != rx */
2355 case OPC_BGTZ: /* 0 > 0 */
2356 case OPC_BLTZ: /* 0 < 0 */
2358 MIPS_DEBUG("bnever (NOP)");
2360 case OPC_BLTZAL: /* 0 < 0 */
2361 tcg_gen_movi_tl(cpu_gpr[31], ctx->pc + 8);
2362 MIPS_DEBUG("bnever and link");
2364 case OPC_BLTZALL: /* 0 < 0 likely */
2365 tcg_gen_movi_tl(cpu_gpr[31], ctx->pc + 8);
2366 /* Skip the instruction in the delay slot */
2367 MIPS_DEBUG("bnever, link and skip");
2370 case OPC_BNEL: /* rx != rx likely */
2371 case OPC_BGTZL: /* 0 > 0 likely */
2372 case OPC_BLTZL: /* 0 < 0 likely */
2373 /* Skip the instruction in the delay slot */
2374 MIPS_DEBUG("bnever and skip");
2378 ctx->hflags |= MIPS_HFLAG_B;
2379 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2383 ctx->hflags |= MIPS_HFLAG_B;
2384 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2387 ctx->hflags |= MIPS_HFLAG_BR;
2388 MIPS_DEBUG("jr %s", regnames[rs]);
2392 ctx->hflags |= MIPS_HFLAG_BR;
2393 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2396 MIPS_INVAL("branch/jump");
2397 generate_exception(ctx, EXCP_RI);
2403 gen_op_eq(bcond, t0, t1);
2404 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2405 regnames[rs], regnames[rt], btgt);
2408 gen_op_eq(bcond, t0, t1);
2409 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2410 regnames[rs], regnames[rt], btgt);
2413 gen_op_ne(bcond, t0, t1);
2414 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2415 regnames[rs], regnames[rt], btgt);
2418 gen_op_ne(bcond, t0, t1);
2419 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2420 regnames[rs], regnames[rt], btgt);
2423 gen_op_gez(bcond, t0);
2424 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2427 gen_op_gez(bcond, t0);
2428 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2431 gen_op_gez(bcond, t0);
2432 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2436 gen_op_gez(bcond, t0);
2438 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2441 gen_op_gtz(bcond, t0);
2442 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2445 gen_op_gtz(bcond, t0);
2446 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2449 gen_op_lez(bcond, t0);
2450 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2453 gen_op_lez(bcond, t0);
2454 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2457 gen_op_ltz(bcond, t0);
2458 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2461 gen_op_ltz(bcond, t0);
2462 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2465 gen_op_ltz(bcond, t0);
2467 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2469 ctx->hflags |= MIPS_HFLAG_BC;
2472 gen_op_ltz(bcond, t0);
2474 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2476 ctx->hflags |= MIPS_HFLAG_BL;
2479 MIPS_INVAL("conditional branch/jump");
2480 generate_exception(ctx, EXCP_RI);
2484 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2485 blink, ctx->hflags, btgt);
2487 ctx->btarget = btgt;
2489 tcg_gen_movi_tl(cpu_gpr[blink], ctx->pc + 8);
2497 /* special3 bitfield operations */
2498 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2499 int rs, int lsb, int msb)
2501 TCGv t0 = tcg_temp_new();
2502 TCGv t1 = tcg_temp_new();
2505 gen_load_gpr(t1, rs);
2510 tcg_gen_shri_tl(t0, t1, lsb);
2512 tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
2514 tcg_gen_ext32s_tl(t0, t0);
2517 #if defined(TARGET_MIPS64)
2519 tcg_gen_shri_tl(t0, t1, lsb);
2521 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
2525 tcg_gen_shri_tl(t0, t1, lsb + 32);
2526 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2529 tcg_gen_shri_tl(t0, t1, lsb);
2530 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2536 mask = ((msb - lsb + 1 < 32) ? ((1 << (msb - lsb + 1)) - 1) : ~0) << lsb;
2537 gen_load_gpr(t0, rt);
2538 tcg_gen_andi_tl(t0, t0, ~mask);
2539 tcg_gen_shli_tl(t1, t1, lsb);
2540 tcg_gen_andi_tl(t1, t1, mask);
2541 tcg_gen_or_tl(t0, t0, t1);
2542 tcg_gen_ext32s_tl(t0, t0);
2544 #if defined(TARGET_MIPS64)
2548 mask = ((msb - lsb + 1 + 32 < 64) ? ((1ULL << (msb - lsb + 1 + 32)) - 1) : ~0ULL) << lsb;
2549 gen_load_gpr(t0, rt);
2550 tcg_gen_andi_tl(t0, t0, ~mask);
2551 tcg_gen_shli_tl(t1, t1, lsb);
2552 tcg_gen_andi_tl(t1, t1, mask);
2553 tcg_gen_or_tl(t0, t0, t1);
2558 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2559 gen_load_gpr(t0, rt);
2560 tcg_gen_andi_tl(t0, t0, ~mask);
2561 tcg_gen_shli_tl(t1, t1, lsb + 32);
2562 tcg_gen_andi_tl(t1, t1, mask);
2563 tcg_gen_or_tl(t0, t0, t1);
2568 gen_load_gpr(t0, rt);
2569 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2570 gen_load_gpr(t0, rt);
2571 tcg_gen_andi_tl(t0, t0, ~mask);
2572 tcg_gen_shli_tl(t1, t1, lsb);
2573 tcg_gen_andi_tl(t1, t1, mask);
2574 tcg_gen_or_tl(t0, t0, t1);
2579 MIPS_INVAL("bitops");
2580 generate_exception(ctx, EXCP_RI);
2585 gen_store_gpr(t0, rt);
2590 static void gen_bshfl (DisasContext *ctx, uint32_t op2, int rt, int rd)
2595 /* If no destination, treat it as a NOP. */
2600 t0 = tcg_temp_new();
2601 gen_load_gpr(t0, rt);
2605 TCGv t1 = tcg_temp_new();
2607 tcg_gen_shri_tl(t1, t0, 8);
2608 tcg_gen_andi_tl(t1, t1, 0x00FF00FF);
2609 tcg_gen_shli_tl(t0, t0, 8);
2610 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF);
2611 tcg_gen_or_tl(t0, t0, t1);
2613 tcg_gen_ext32s_tl(cpu_gpr[rd], t0);
2617 tcg_gen_ext8s_tl(cpu_gpr[rd], t0);
2620 tcg_gen_ext16s_tl(cpu_gpr[rd], t0);
2622 #if defined(TARGET_MIPS64)
2625 TCGv t1 = tcg_temp_new();
2627 tcg_gen_shri_tl(t1, t0, 8);
2628 tcg_gen_andi_tl(t1, t1, 0x00FF00FF00FF00FFULL);
2629 tcg_gen_shli_tl(t0, t0, 8);
2630 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF00FF00FFULL);
2631 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2637 TCGv t1 = tcg_temp_new();
2639 tcg_gen_shri_tl(t1, t0, 16);
2640 tcg_gen_andi_tl(t1, t1, 0x0000FFFF0000FFFFULL);
2641 tcg_gen_shli_tl(t0, t0, 16);
2642 tcg_gen_andi_tl(t0, t0, ~0x0000FFFF0000FFFFULL);
2643 tcg_gen_or_tl(t0, t0, t1);
2644 tcg_gen_shri_tl(t1, t0, 32);
2645 tcg_gen_shli_tl(t0, t0, 32);
2646 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2652 MIPS_INVAL("bsfhl");
2653 generate_exception(ctx, EXCP_RI);
2660 #ifndef CONFIG_USER_ONLY
2661 /* CP0 (MMU and control) */
2662 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2664 TCGv_i32 r_tmp = tcg_temp_new_i32();
2666 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2667 tcg_gen_ext_i32_tl(t, r_tmp);
2668 tcg_temp_free_i32(r_tmp);
2671 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2673 tcg_gen_ld_tl(t, cpu_env, off);
2674 tcg_gen_ext32s_tl(t, t);
2677 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2679 TCGv_i32 r_tmp = tcg_temp_new_i32();
2681 tcg_gen_trunc_tl_i32(r_tmp, t);
2682 tcg_gen_st_i32(r_tmp, cpu_env, off);
2683 tcg_temp_free_i32(r_tmp);
2686 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2688 tcg_gen_ext32s_tl(t, t);
2689 tcg_gen_st_tl(t, cpu_env, off);
2692 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2694 const char *rn = "invalid";
2697 check_insn(env, ctx, ISA_MIPS32);
2703 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2707 check_insn(env, ctx, ASE_MT);
2708 gen_helper_mfc0_mvpcontrol(t0);
2712 check_insn(env, ctx, ASE_MT);
2713 gen_helper_mfc0_mvpconf0(t0);
2717 check_insn(env, ctx, ASE_MT);
2718 gen_helper_mfc0_mvpconf1(t0);
2728 gen_helper_mfc0_random(t0);
2732 check_insn(env, ctx, ASE_MT);
2733 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2737 check_insn(env, ctx, ASE_MT);
2738 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2742 check_insn(env, ctx, ASE_MT);
2743 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2747 check_insn(env, ctx, ASE_MT);
2748 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2752 check_insn(env, ctx, ASE_MT);
2753 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2757 check_insn(env, ctx, ASE_MT);
2758 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2759 rn = "VPEScheFBack";
2762 check_insn(env, ctx, ASE_MT);
2763 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2773 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2774 tcg_gen_ext32s_tl(t0, t0);
2778 check_insn(env, ctx, ASE_MT);
2779 gen_helper_mfc0_tcstatus(t0);
2783 check_insn(env, ctx, ASE_MT);
2784 gen_helper_mfc0_tcbind(t0);
2788 check_insn(env, ctx, ASE_MT);
2789 gen_helper_mfc0_tcrestart(t0);
2793 check_insn(env, ctx, ASE_MT);
2794 gen_helper_mfc0_tchalt(t0);
2798 check_insn(env, ctx, ASE_MT);
2799 gen_helper_mfc0_tccontext(t0);
2803 check_insn(env, ctx, ASE_MT);
2804 gen_helper_mfc0_tcschedule(t0);
2808 check_insn(env, ctx, ASE_MT);
2809 gen_helper_mfc0_tcschefback(t0);
2819 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2820 tcg_gen_ext32s_tl(t0, t0);
2830 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2831 tcg_gen_ext32s_tl(t0, t0);
2835 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2836 rn = "ContextConfig";
2845 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2849 check_insn(env, ctx, ISA_MIPS32R2);
2850 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2860 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2864 check_insn(env, ctx, ISA_MIPS32R2);
2865 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2869 check_insn(env, ctx, ISA_MIPS32R2);
2870 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2874 check_insn(env, ctx, ISA_MIPS32R2);
2875 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2879 check_insn(env, ctx, ISA_MIPS32R2);
2880 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2884 check_insn(env, ctx, ISA_MIPS32R2);
2885 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2895 check_insn(env, ctx, ISA_MIPS32R2);
2896 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
2906 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
2907 tcg_gen_ext32s_tl(t0, t0);
2917 /* Mark as an IO operation because we read the time. */
2920 gen_helper_mfc0_count(t0);
2923 ctx->bstate = BS_STOP;
2927 /* 6,7 are implementation dependent */
2935 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
2936 tcg_gen_ext32s_tl(t0, t0);
2946 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
2949 /* 6,7 are implementation dependent */
2957 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
2961 check_insn(env, ctx, ISA_MIPS32R2);
2962 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
2966 check_insn(env, ctx, ISA_MIPS32R2);
2967 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
2971 check_insn(env, ctx, ISA_MIPS32R2);
2972 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
2982 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
2992 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
2993 tcg_gen_ext32s_tl(t0, t0);
3003 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3007 check_insn(env, ctx, ISA_MIPS32R2);
3008 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3018 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3022 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3026 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3030 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3033 /* 4,5 are reserved */
3034 /* 6,7 are implementation dependent */
3036 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3040 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3050 gen_helper_mfc0_lladdr(t0);
3060 gen_helper_1i(mfc0_watchlo, t0, sel);
3070 gen_helper_1i(mfc0_watchhi, t0, sel);
3080 #if defined(TARGET_MIPS64)
3081 check_insn(env, ctx, ISA_MIPS3);
3082 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3083 tcg_gen_ext32s_tl(t0, t0);
3092 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3095 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3103 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3104 rn = "'Diagnostic"; /* implementation dependent */
3109 gen_helper_mfc0_debug(t0); /* EJTAG support */
3113 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3114 rn = "TraceControl";
3117 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3118 rn = "TraceControl2";
3121 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3122 rn = "UserTraceData";
3125 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3136 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3137 tcg_gen_ext32s_tl(t0, t0);
3147 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3148 rn = "Performance0";
3151 // gen_helper_mfc0_performance1(t0);
3152 rn = "Performance1";
3155 // gen_helper_mfc0_performance2(t0);
3156 rn = "Performance2";
3159 // gen_helper_mfc0_performance3(t0);
3160 rn = "Performance3";
3163 // gen_helper_mfc0_performance4(t0);
3164 rn = "Performance4";
3167 // gen_helper_mfc0_performance5(t0);
3168 rn = "Performance5";
3171 // gen_helper_mfc0_performance6(t0);
3172 rn = "Performance6";
3175 // gen_helper_mfc0_performance7(t0);
3176 rn = "Performance7";
3183 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3189 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3202 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3209 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3222 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3229 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3239 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3240 tcg_gen_ext32s_tl(t0, t0);
3251 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3261 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3265 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3266 generate_exception(ctx, EXCP_RI);
3269 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3271 const char *rn = "invalid";
3274 check_insn(env, ctx, ISA_MIPS32);
3283 gen_helper_mtc0_index(t0);
3287 check_insn(env, ctx, ASE_MT);
3288 gen_helper_mtc0_mvpcontrol(t0);
3292 check_insn(env, ctx, ASE_MT);
3297 check_insn(env, ctx, ASE_MT);
3312 check_insn(env, ctx, ASE_MT);
3313 gen_helper_mtc0_vpecontrol(t0);
3317 check_insn(env, ctx, ASE_MT);
3318 gen_helper_mtc0_vpeconf0(t0);
3322 check_insn(env, ctx, ASE_MT);
3323 gen_helper_mtc0_vpeconf1(t0);
3327 check_insn(env, ctx, ASE_MT);
3328 gen_helper_mtc0_yqmask(t0);
3332 check_insn(env, ctx, ASE_MT);
3333 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3337 check_insn(env, ctx, ASE_MT);
3338 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3339 rn = "VPEScheFBack";
3342 check_insn(env, ctx, ASE_MT);
3343 gen_helper_mtc0_vpeopt(t0);
3353 gen_helper_mtc0_entrylo0(t0);
3357 check_insn(env, ctx, ASE_MT);
3358 gen_helper_mtc0_tcstatus(t0);
3362 check_insn(env, ctx, ASE_MT);
3363 gen_helper_mtc0_tcbind(t0);
3367 check_insn(env, ctx, ASE_MT);
3368 gen_helper_mtc0_tcrestart(t0);
3372 check_insn(env, ctx, ASE_MT);
3373 gen_helper_mtc0_tchalt(t0);
3377 check_insn(env, ctx, ASE_MT);
3378 gen_helper_mtc0_tccontext(t0);
3382 check_insn(env, ctx, ASE_MT);
3383 gen_helper_mtc0_tcschedule(t0);
3387 check_insn(env, ctx, ASE_MT);
3388 gen_helper_mtc0_tcschefback(t0);
3398 gen_helper_mtc0_entrylo1(t0);
3408 gen_helper_mtc0_context(t0);
3412 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3413 rn = "ContextConfig";
3422 gen_helper_mtc0_pagemask(t0);
3426 check_insn(env, ctx, ISA_MIPS32R2);
3427 gen_helper_mtc0_pagegrain(t0);
3437 gen_helper_mtc0_wired(t0);
3441 check_insn(env, ctx, ISA_MIPS32R2);
3442 gen_helper_mtc0_srsconf0(t0);
3446 check_insn(env, ctx, ISA_MIPS32R2);
3447 gen_helper_mtc0_srsconf1(t0);
3451 check_insn(env, ctx, ISA_MIPS32R2);
3452 gen_helper_mtc0_srsconf2(t0);
3456 check_insn(env, ctx, ISA_MIPS32R2);
3457 gen_helper_mtc0_srsconf3(t0);
3461 check_insn(env, ctx, ISA_MIPS32R2);
3462 gen_helper_mtc0_srsconf4(t0);
3472 check_insn(env, ctx, ISA_MIPS32R2);
3473 gen_helper_mtc0_hwrena(t0);
3487 gen_helper_mtc0_count(t0);
3490 /* 6,7 are implementation dependent */
3494 /* Stop translation as we may have switched the execution mode */
3495 ctx->bstate = BS_STOP;
3500 gen_helper_mtc0_entryhi(t0);
3510 gen_helper_mtc0_compare(t0);
3513 /* 6,7 are implementation dependent */
3517 /* Stop translation as we may have switched the execution mode */
3518 ctx->bstate = BS_STOP;
3523 gen_helper_mtc0_status(t0);
3524 /* BS_STOP isn't good enough here, hflags may have changed. */
3525 gen_save_pc(ctx->pc + 4);
3526 ctx->bstate = BS_EXCP;
3530 check_insn(env, ctx, ISA_MIPS32R2);
3531 gen_helper_mtc0_intctl(t0);
3532 /* Stop translation as we may have switched the execution mode */
3533 ctx->bstate = BS_STOP;
3537 check_insn(env, ctx, ISA_MIPS32R2);
3538 gen_helper_mtc0_srsctl(t0);
3539 /* Stop translation as we may have switched the execution mode */
3540 ctx->bstate = BS_STOP;
3544 check_insn(env, ctx, ISA_MIPS32R2);
3545 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3546 /* Stop translation as we may have switched the execution mode */
3547 ctx->bstate = BS_STOP;
3557 gen_helper_mtc0_cause(t0);
3563 /* Stop translation as we may have switched the execution mode */
3564 ctx->bstate = BS_STOP;
3569 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3583 check_insn(env, ctx, ISA_MIPS32R2);
3584 gen_helper_mtc0_ebase(t0);
3594 gen_helper_mtc0_config0(t0);
3596 /* Stop translation as we may have switched the execution mode */
3597 ctx->bstate = BS_STOP;
3600 /* ignored, read only */
3604 gen_helper_mtc0_config2(t0);
3606 /* Stop translation as we may have switched the execution mode */
3607 ctx->bstate = BS_STOP;
3610 /* ignored, read only */
3613 /* 4,5 are reserved */
3614 /* 6,7 are implementation dependent */
3624 rn = "Invalid config selector";
3641 gen_helper_1i(mtc0_watchlo, t0, sel);
3651 gen_helper_1i(mtc0_watchhi, t0, sel);
3661 #if defined(TARGET_MIPS64)
3662 check_insn(env, ctx, ISA_MIPS3);
3663 gen_helper_mtc0_xcontext(t0);
3672 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3675 gen_helper_mtc0_framemask(t0);
3684 rn = "Diagnostic"; /* implementation dependent */
3689 gen_helper_mtc0_debug(t0); /* EJTAG support */
3690 /* BS_STOP isn't good enough here, hflags may have changed. */
3691 gen_save_pc(ctx->pc + 4);
3692 ctx->bstate = BS_EXCP;
3696 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3697 rn = "TraceControl";
3698 /* Stop translation as we may have switched the execution mode */
3699 ctx->bstate = BS_STOP;
3702 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3703 rn = "TraceControl2";
3704 /* Stop translation as we may have switched the execution mode */
3705 ctx->bstate = BS_STOP;
3708 /* Stop translation as we may have switched the execution mode */
3709 ctx->bstate = BS_STOP;
3710 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3711 rn = "UserTraceData";
3712 /* Stop translation as we may have switched the execution mode */
3713 ctx->bstate = BS_STOP;
3716 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3717 /* Stop translation as we may have switched the execution mode */
3718 ctx->bstate = BS_STOP;
3729 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3739 gen_helper_mtc0_performance0(t0);
3740 rn = "Performance0";
3743 // gen_helper_mtc0_performance1(t0);
3744 rn = "Performance1";
3747 // gen_helper_mtc0_performance2(t0);
3748 rn = "Performance2";
3751 // gen_helper_mtc0_performance3(t0);
3752 rn = "Performance3";
3755 // gen_helper_mtc0_performance4(t0);
3756 rn = "Performance4";
3759 // gen_helper_mtc0_performance5(t0);
3760 rn = "Performance5";
3763 // gen_helper_mtc0_performance6(t0);
3764 rn = "Performance6";
3767 // gen_helper_mtc0_performance7(t0);
3768 rn = "Performance7";
3794 gen_helper_mtc0_taglo(t0);
3801 gen_helper_mtc0_datalo(t0);
3814 gen_helper_mtc0_taghi(t0);
3821 gen_helper_mtc0_datahi(t0);
3832 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3843 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3849 /* Stop translation as we may have switched the execution mode */
3850 ctx->bstate = BS_STOP;
3855 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3856 /* For simplicity assume that all writes can cause interrupts. */
3859 ctx->bstate = BS_STOP;
3864 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3865 generate_exception(ctx, EXCP_RI);
3868 #if defined(TARGET_MIPS64)
3869 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3871 const char *rn = "invalid";
3874 check_insn(env, ctx, ISA_MIPS64);
3880 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
3884 check_insn(env, ctx, ASE_MT);
3885 gen_helper_mfc0_mvpcontrol(t0);
3889 check_insn(env, ctx, ASE_MT);
3890 gen_helper_mfc0_mvpconf0(t0);
3894 check_insn(env, ctx, ASE_MT);
3895 gen_helper_mfc0_mvpconf1(t0);
3905 gen_helper_mfc0_random(t0);
3909 check_insn(env, ctx, ASE_MT);
3910 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
3914 check_insn(env, ctx, ASE_MT);
3915 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
3919 check_insn(env, ctx, ASE_MT);
3920 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
3924 check_insn(env, ctx, ASE_MT);
3925 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
3929 check_insn(env, ctx, ASE_MT);
3930 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
3934 check_insn(env, ctx, ASE_MT);
3935 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3936 rn = "VPEScheFBack";
3939 check_insn(env, ctx, ASE_MT);
3940 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
3950 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
3954 check_insn(env, ctx, ASE_MT);
3955 gen_helper_mfc0_tcstatus(t0);
3959 check_insn(env, ctx, ASE_MT);
3960 gen_helper_mfc0_tcbind(t0);
3964 check_insn(env, ctx, ASE_MT);
3965 gen_helper_dmfc0_tcrestart(t0);
3969 check_insn(env, ctx, ASE_MT);
3970 gen_helper_dmfc0_tchalt(t0);
3974 check_insn(env, ctx, ASE_MT);
3975 gen_helper_dmfc0_tccontext(t0);
3979 check_insn(env, ctx, ASE_MT);
3980 gen_helper_dmfc0_tcschedule(t0);
3984 check_insn(env, ctx, ASE_MT);
3985 gen_helper_dmfc0_tcschefback(t0);
3995 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4005 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4009 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4010 rn = "ContextConfig";
4019 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4023 check_insn(env, ctx, ISA_MIPS32R2);
4024 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4034 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4038 check_insn(env, ctx, ISA_MIPS32R2);
4039 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4043 check_insn(env, ctx, ISA_MIPS32R2);
4044 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4048 check_insn(env, ctx, ISA_MIPS32R2);
4049 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4053 check_insn(env, ctx, ISA_MIPS32R2);
4054 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4058 check_insn(env, ctx, ISA_MIPS32R2);
4059 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4069 check_insn(env, ctx, ISA_MIPS32R2);
4070 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4080 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4090 /* Mark as an IO operation because we read the time. */
4093 gen_helper_mfc0_count(t0);
4096 ctx->bstate = BS_STOP;
4100 /* 6,7 are implementation dependent */
4108 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4118 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4121 /* 6,7 are implementation dependent */
4129 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4133 check_insn(env, ctx, ISA_MIPS32R2);
4134 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4138 check_insn(env, ctx, ISA_MIPS32R2);
4139 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4143 check_insn(env, ctx, ISA_MIPS32R2);
4144 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4154 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4164 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4174 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4178 check_insn(env, ctx, ISA_MIPS32R2);
4179 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4189 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4193 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4197 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4201 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4204 /* 6,7 are implementation dependent */
4206 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4210 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4220 gen_helper_dmfc0_lladdr(t0);
4230 gen_helper_1i(dmfc0_watchlo, t0, sel);
4240 gen_helper_1i(mfc0_watchhi, t0, sel);
4250 check_insn(env, ctx, ISA_MIPS3);
4251 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4259 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4262 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4270 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4271 rn = "'Diagnostic"; /* implementation dependent */
4276 gen_helper_mfc0_debug(t0); /* EJTAG support */
4280 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4281 rn = "TraceControl";
4284 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4285 rn = "TraceControl2";
4288 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4289 rn = "UserTraceData";
4292 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4303 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4313 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4314 rn = "Performance0";
4317 // gen_helper_dmfc0_performance1(t0);
4318 rn = "Performance1";
4321 // gen_helper_dmfc0_performance2(t0);
4322 rn = "Performance2";
4325 // gen_helper_dmfc0_performance3(t0);
4326 rn = "Performance3";
4329 // gen_helper_dmfc0_performance4(t0);
4330 rn = "Performance4";
4333 // gen_helper_dmfc0_performance5(t0);
4334 rn = "Performance5";
4337 // gen_helper_dmfc0_performance6(t0);
4338 rn = "Performance6";
4341 // gen_helper_dmfc0_performance7(t0);
4342 rn = "Performance7";
4349 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4356 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4369 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4376 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4389 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4396 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4406 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4417 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4427 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4431 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4432 generate_exception(ctx, EXCP_RI);
4435 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4437 const char *rn = "invalid";
4440 check_insn(env, ctx, ISA_MIPS64);
4449 gen_helper_mtc0_index(t0);
4453 check_insn(env, ctx, ASE_MT);
4454 gen_helper_mtc0_mvpcontrol(t0);
4458 check_insn(env, ctx, ASE_MT);
4463 check_insn(env, ctx, ASE_MT);
4478 check_insn(env, ctx, ASE_MT);
4479 gen_helper_mtc0_vpecontrol(t0);
4483 check_insn(env, ctx, ASE_MT);
4484 gen_helper_mtc0_vpeconf0(t0);
4488 check_insn(env, ctx, ASE_MT);
4489 gen_helper_mtc0_vpeconf1(t0);
4493 check_insn(env, ctx, ASE_MT);
4494 gen_helper_mtc0_yqmask(t0);
4498 check_insn(env, ctx, ASE_MT);
4499 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4503 check_insn(env, ctx, ASE_MT);
4504 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4505 rn = "VPEScheFBack";
4508 check_insn(env, ctx, ASE_MT);
4509 gen_helper_mtc0_vpeopt(t0);
4519 gen_helper_mtc0_entrylo0(t0);
4523 check_insn(env, ctx, ASE_MT);
4524 gen_helper_mtc0_tcstatus(t0);
4528 check_insn(env, ctx, ASE_MT);
4529 gen_helper_mtc0_tcbind(t0);
4533 check_insn(env, ctx, ASE_MT);
4534 gen_helper_mtc0_tcrestart(t0);
4538 check_insn(env, ctx, ASE_MT);
4539 gen_helper_mtc0_tchalt(t0);
4543 check_insn(env, ctx, ASE_MT);
4544 gen_helper_mtc0_tccontext(t0);
4548 check_insn(env, ctx, ASE_MT);
4549 gen_helper_mtc0_tcschedule(t0);
4553 check_insn(env, ctx, ASE_MT);
4554 gen_helper_mtc0_tcschefback(t0);
4564 gen_helper_mtc0_entrylo1(t0);
4574 gen_helper_mtc0_context(t0);
4578 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4579 rn = "ContextConfig";
4588 gen_helper_mtc0_pagemask(t0);
4592 check_insn(env, ctx, ISA_MIPS32R2);
4593 gen_helper_mtc0_pagegrain(t0);
4603 gen_helper_mtc0_wired(t0);
4607 check_insn(env, ctx, ISA_MIPS32R2);
4608 gen_helper_mtc0_srsconf0(t0);
4612 check_insn(env, ctx, ISA_MIPS32R2);
4613 gen_helper_mtc0_srsconf1(t0);
4617 check_insn(env, ctx, ISA_MIPS32R2);
4618 gen_helper_mtc0_srsconf2(t0);
4622 check_insn(env, ctx, ISA_MIPS32R2);
4623 gen_helper_mtc0_srsconf3(t0);
4627 check_insn(env, ctx, ISA_MIPS32R2);
4628 gen_helper_mtc0_srsconf4(t0);
4638 check_insn(env, ctx, ISA_MIPS32R2);
4639 gen_helper_mtc0_hwrena(t0);
4653 gen_helper_mtc0_count(t0);
4656 /* 6,7 are implementation dependent */
4660 /* Stop translation as we may have switched the execution mode */
4661 ctx->bstate = BS_STOP;
4666 gen_helper_mtc0_entryhi(t0);
4676 gen_helper_mtc0_compare(t0);
4679 /* 6,7 are implementation dependent */
4683 /* Stop translation as we may have switched the execution mode */
4684 ctx->bstate = BS_STOP;
4689 gen_helper_mtc0_status(t0);
4690 /* BS_STOP isn't good enough here, hflags may have changed. */
4691 gen_save_pc(ctx->pc + 4);
4692 ctx->bstate = BS_EXCP;
4696 check_insn(env, ctx, ISA_MIPS32R2);
4697 gen_helper_mtc0_intctl(t0);
4698 /* Stop translation as we may have switched the execution mode */
4699 ctx->bstate = BS_STOP;
4703 check_insn(env, ctx, ISA_MIPS32R2);
4704 gen_helper_mtc0_srsctl(t0);
4705 /* Stop translation as we may have switched the execution mode */
4706 ctx->bstate = BS_STOP;
4710 check_insn(env, ctx, ISA_MIPS32R2);
4711 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4712 /* Stop translation as we may have switched the execution mode */
4713 ctx->bstate = BS_STOP;
4723 gen_helper_mtc0_cause(t0);
4729 /* Stop translation as we may have switched the execution mode */
4730 ctx->bstate = BS_STOP;
4735 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4749 check_insn(env, ctx, ISA_MIPS32R2);
4750 gen_helper_mtc0_ebase(t0);
4760 gen_helper_mtc0_config0(t0);
4762 /* Stop translation as we may have switched the execution mode */
4763 ctx->bstate = BS_STOP;
4770 gen_helper_mtc0_config2(t0);
4772 /* Stop translation as we may have switched the execution mode */
4773 ctx->bstate = BS_STOP;
4779 /* 6,7 are implementation dependent */
4781 rn = "Invalid config selector";
4798 gen_helper_1i(mtc0_watchlo, t0, sel);
4808 gen_helper_1i(mtc0_watchhi, t0, sel);
4818 check_insn(env, ctx, ISA_MIPS3);
4819 gen_helper_mtc0_xcontext(t0);
4827 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4830 gen_helper_mtc0_framemask(t0);
4839 rn = "Diagnostic"; /* implementation dependent */
4844 gen_helper_mtc0_debug(t0); /* EJTAG support */
4845 /* BS_STOP isn't good enough here, hflags may have changed. */
4846 gen_save_pc(ctx->pc + 4);
4847 ctx->bstate = BS_EXCP;
4851 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4852 /* Stop translation as we may have switched the execution mode */
4853 ctx->bstate = BS_STOP;
4854 rn = "TraceControl";
4857 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4858 /* Stop translation as we may have switched the execution mode */
4859 ctx->bstate = BS_STOP;
4860 rn = "TraceControl2";
4863 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4864 /* Stop translation as we may have switched the execution mode */
4865 ctx->bstate = BS_STOP;
4866 rn = "UserTraceData";
4869 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4870 /* Stop translation as we may have switched the execution mode */
4871 ctx->bstate = BS_STOP;
4882 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4892 gen_helper_mtc0_performance0(t0);
4893 rn = "Performance0";
4896 // gen_helper_mtc0_performance1(t0);
4897 rn = "Performance1";
4900 // gen_helper_mtc0_performance2(t0);
4901 rn = "Performance2";
4904 // gen_helper_mtc0_performance3(t0);
4905 rn = "Performance3";
4908 // gen_helper_mtc0_performance4(t0);
4909 rn = "Performance4";
4912 // gen_helper_mtc0_performance5(t0);
4913 rn = "Performance5";
4916 // gen_helper_mtc0_performance6(t0);
4917 rn = "Performance6";
4920 // gen_helper_mtc0_performance7(t0);
4921 rn = "Performance7";
4947 gen_helper_mtc0_taglo(t0);
4954 gen_helper_mtc0_datalo(t0);
4967 gen_helper_mtc0_taghi(t0);
4974 gen_helper_mtc0_datahi(t0);
4985 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4996 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5002 /* Stop translation as we may have switched the execution mode */
5003 ctx->bstate = BS_STOP;
5008 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5009 /* For simplicity assume that all writes can cause interrupts. */
5012 ctx->bstate = BS_STOP;
5017 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5018 generate_exception(ctx, EXCP_RI);
5020 #endif /* TARGET_MIPS64 */
5022 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5023 int u, int sel, int h)
5025 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5026 TCGv t0 = tcg_temp_local_new();
5028 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5029 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5030 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5031 tcg_gen_movi_tl(t0, -1);
5032 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5033 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5034 tcg_gen_movi_tl(t0, -1);
5040 gen_helper_mftc0_tcstatus(t0);
5043 gen_helper_mftc0_tcbind(t0);
5046 gen_helper_mftc0_tcrestart(t0);
5049 gen_helper_mftc0_tchalt(t0);
5052 gen_helper_mftc0_tccontext(t0);
5055 gen_helper_mftc0_tcschedule(t0);
5058 gen_helper_mftc0_tcschefback(t0);
5061 gen_mfc0(env, ctx, t0, rt, sel);
5068 gen_helper_mftc0_entryhi(t0);
5071 gen_mfc0(env, ctx, t0, rt, sel);
5077 gen_helper_mftc0_status(t0);
5080 gen_mfc0(env, ctx, t0, rt, sel);
5086 gen_helper_mftc0_debug(t0);
5089 gen_mfc0(env, ctx, t0, rt, sel);
5094 gen_mfc0(env, ctx, t0, rt, sel);
5096 } else switch (sel) {
5097 /* GPR registers. */
5099 gen_helper_1i(mftgpr, t0, rt);
5101 /* Auxiliary CPU registers */
5105 gen_helper_1i(mftlo, t0, 0);
5108 gen_helper_1i(mfthi, t0, 0);
5111 gen_helper_1i(mftacx, t0, 0);
5114 gen_helper_1i(mftlo, t0, 1);
5117 gen_helper_1i(mfthi, t0, 1);
5120 gen_helper_1i(mftacx, t0, 1);
5123 gen_helper_1i(mftlo, t0, 2);
5126 gen_helper_1i(mfthi, t0, 2);
5129 gen_helper_1i(mftacx, t0, 2);
5132 gen_helper_1i(mftlo, t0, 3);
5135 gen_helper_1i(mfthi, t0, 3);
5138 gen_helper_1i(mftacx, t0, 3);
5141 gen_helper_mftdsp(t0);
5147 /* Floating point (COP1). */
5149 /* XXX: For now we support only a single FPU context. */
5151 TCGv_i32 fp0 = tcg_temp_new_i32();
5153 gen_load_fpr32(fp0, rt);
5154 tcg_gen_ext_i32_tl(t0, fp0);
5155 tcg_temp_free_i32(fp0);
5157 TCGv_i32 fp0 = tcg_temp_new_i32();
5159 gen_load_fpr32h(fp0, rt);
5160 tcg_gen_ext_i32_tl(t0, fp0);
5161 tcg_temp_free_i32(fp0);
5165 /* XXX: For now we support only a single FPU context. */
5166 gen_helper_1i(cfc1, t0, rt);
5168 /* COP2: Not implemented. */
5175 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5176 gen_store_gpr(t0, rd);
5182 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5183 generate_exception(ctx, EXCP_RI);
5186 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5187 int u, int sel, int h)
5189 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5190 TCGv t0 = tcg_temp_local_new();
5192 gen_load_gpr(t0, rt);
5193 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5194 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5195 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5197 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5198 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5205 gen_helper_mttc0_tcstatus(t0);
5208 gen_helper_mttc0_tcbind(t0);
5211 gen_helper_mttc0_tcrestart(t0);
5214 gen_helper_mttc0_tchalt(t0);
5217 gen_helper_mttc0_tccontext(t0);
5220 gen_helper_mttc0_tcschedule(t0);
5223 gen_helper_mttc0_tcschefback(t0);
5226 gen_mtc0(env, ctx, t0, rd, sel);
5233 gen_helper_mttc0_entryhi(t0);
5236 gen_mtc0(env, ctx, t0, rd, sel);
5242 gen_helper_mttc0_status(t0);
5245 gen_mtc0(env, ctx, t0, rd, sel);
5251 gen_helper_mttc0_debug(t0);
5254 gen_mtc0(env, ctx, t0, rd, sel);
5259 gen_mtc0(env, ctx, t0, rd, sel);
5261 } else switch (sel) {
5262 /* GPR registers. */
5264 gen_helper_1i(mttgpr, t0, rd);
5266 /* Auxiliary CPU registers */
5270 gen_helper_1i(mttlo, t0, 0);
5273 gen_helper_1i(mtthi, t0, 0);
5276 gen_helper_1i(mttacx, t0, 0);
5279 gen_helper_1i(mttlo, t0, 1);
5282 gen_helper_1i(mtthi, t0, 1);
5285 gen_helper_1i(mttacx, t0, 1);
5288 gen_helper_1i(mttlo, t0, 2);
5291 gen_helper_1i(mtthi, t0, 2);
5294 gen_helper_1i(mttacx, t0, 2);
5297 gen_helper_1i(mttlo, t0, 3);
5300 gen_helper_1i(mtthi, t0, 3);
5303 gen_helper_1i(mttacx, t0, 3);
5306 gen_helper_mttdsp(t0);
5312 /* Floating point (COP1). */
5314 /* XXX: For now we support only a single FPU context. */
5316 TCGv_i32 fp0 = tcg_temp_new_i32();
5318 tcg_gen_trunc_tl_i32(fp0, t0);
5319 gen_store_fpr32(fp0, rd);
5320 tcg_temp_free_i32(fp0);
5322 TCGv_i32 fp0 = tcg_temp_new_i32();
5324 tcg_gen_trunc_tl_i32(fp0, t0);
5325 gen_store_fpr32h(fp0, rd);
5326 tcg_temp_free_i32(fp0);
5330 /* XXX: For now we support only a single FPU context. */
5331 gen_helper_1i(ctc1, t0, rd);
5333 /* COP2: Not implemented. */
5340 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5346 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5347 generate_exception(ctx, EXCP_RI);
5350 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5352 const char *opn = "ldst";
5361 TCGv t0 = tcg_temp_local_new();
5363 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5364 gen_store_gpr(t0, rt);
5371 TCGv t0 = tcg_temp_local_new();
5373 gen_load_gpr(t0, rt);
5374 save_cpu_state(ctx, 1);
5375 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5380 #if defined(TARGET_MIPS64)
5382 check_insn(env, ctx, ISA_MIPS3);
5388 TCGv t0 = tcg_temp_local_new();
5390 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5391 gen_store_gpr(t0, rt);
5397 check_insn(env, ctx, ISA_MIPS3);
5399 TCGv t0 = tcg_temp_local_new();
5401 gen_load_gpr(t0, rt);
5402 save_cpu_state(ctx, 1);
5403 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5410 check_insn(env, ctx, ASE_MT);
5415 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5416 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5420 check_insn(env, ctx, ASE_MT);
5421 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5422 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5427 if (!env->tlb->helper_tlbwi)
5433 if (!env->tlb->helper_tlbwr)
5439 if (!env->tlb->helper_tlbp)
5445 if (!env->tlb->helper_tlbr)
5451 check_insn(env, ctx, ISA_MIPS2);
5452 save_cpu_state(ctx, 1);
5454 ctx->bstate = BS_EXCP;
5458 check_insn(env, ctx, ISA_MIPS32);
5459 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5461 generate_exception(ctx, EXCP_RI);
5463 save_cpu_state(ctx, 1);
5465 ctx->bstate = BS_EXCP;
5470 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5471 /* If we get an exception, we want to restart at next instruction */
5473 save_cpu_state(ctx, 1);
5476 ctx->bstate = BS_EXCP;
5481 generate_exception(ctx, EXCP_RI);
5484 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5486 #endif /* !CONFIG_USER_ONLY */
5488 /* CP1 Branches (before delay slot) */
5489 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5490 int32_t cc, int32_t offset)
5492 target_ulong btarget;
5493 const char *opn = "cp1 cond branch";
5494 TCGv_i32 t0 = tcg_temp_new_i32();
5497 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5499 btarget = ctx->pc + 4 + offset;
5504 int l1 = gen_new_label();
5505 int l2 = gen_new_label();
5508 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5509 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5510 tcg_gen_movi_tl(bcond, 0);
5513 tcg_gen_movi_tl(bcond, 1);
5520 int l1 = gen_new_label();
5521 int l2 = gen_new_label();
5524 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5525 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5526 tcg_gen_movi_tl(bcond, 0);
5529 tcg_gen_movi_tl(bcond, 1);
5536 int l1 = gen_new_label();
5537 int l2 = gen_new_label();
5540 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5541 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5542 tcg_gen_movi_tl(bcond, 0);
5545 tcg_gen_movi_tl(bcond, 1);
5552 int l1 = gen_new_label();
5553 int l2 = gen_new_label();
5556 tcg_gen_andi_i32(t0, t0, 0x1 << cc);
5557 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5558 tcg_gen_movi_tl(bcond, 0);
5561 tcg_gen_movi_tl(bcond, 1);
5566 ctx->hflags |= MIPS_HFLAG_BL;
5570 int l1 = gen_new_label();
5571 int l2 = gen_new_label();
5574 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5575 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5576 tcg_gen_movi_tl(bcond, 0);
5579 tcg_gen_movi_tl(bcond, 1);
5586 int l1 = gen_new_label();
5587 int l2 = gen_new_label();
5590 tcg_gen_andi_i32(t0, t0, 0x3 << cc);
5591 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5592 tcg_gen_movi_tl(bcond, 0);
5595 tcg_gen_movi_tl(bcond, 1);
5602 int l1 = gen_new_label();
5603 int l2 = gen_new_label();
5606 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5607 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
5608 tcg_gen_movi_tl(bcond, 0);
5611 tcg_gen_movi_tl(bcond, 1);
5618 int l1 = gen_new_label();
5619 int l2 = gen_new_label();
5622 tcg_gen_andi_i32(t0, t0, 0xf << cc);
5623 tcg_gen_brcondi_i32(TCG_COND_NE, t0, 0, l1);
5624 tcg_gen_movi_tl(bcond, 0);
5627 tcg_gen_movi_tl(bcond, 1);
5632 ctx->hflags |= MIPS_HFLAG_BC;
5636 generate_exception (ctx, EXCP_RI);
5639 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5640 ctx->hflags, btarget);
5641 ctx->btarget = btarget;
5644 tcg_temp_free_i32(t0);
5647 /* Coprocessor 1 (FPU) */
5649 #define FOP(func, fmt) (((fmt) << 21) | (func))
5651 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5653 const char *opn = "cp1 move";
5654 TCGv t0 = tcg_temp_local_new();
5659 TCGv_i32 fp0 = tcg_temp_new_i32();
5661 gen_load_fpr32(fp0, fs);
5662 tcg_gen_ext_i32_tl(t0, fp0);
5663 tcg_temp_free_i32(fp0);
5665 gen_store_gpr(t0, rt);
5669 gen_load_gpr(t0, rt);
5671 TCGv_i32 fp0 = tcg_temp_new_i32();
5673 tcg_gen_trunc_tl_i32(fp0, t0);
5674 gen_store_fpr32(fp0, fs);
5675 tcg_temp_free_i32(fp0);
5680 gen_helper_1i(cfc1, t0, fs);
5681 gen_store_gpr(t0, rt);
5685 gen_load_gpr(t0, rt);
5686 gen_helper_1i(ctc1, t0, fs);
5691 TCGv_i64 fp0 = tcg_temp_new_i64();
5693 gen_load_fpr64(ctx, fp0, fs);
5694 tcg_gen_trunc_i64_tl(t0, fp0);
5695 tcg_temp_free_i64(fp0);
5697 gen_store_gpr(t0, rt);
5701 gen_load_gpr(t0, rt);
5703 TCGv_i64 fp0 = tcg_temp_new_i64();
5705 tcg_gen_extu_tl_i64(fp0, t0);
5706 gen_store_fpr64(ctx, fp0, fs);
5707 tcg_temp_free_i64(fp0);
5713 TCGv_i32 fp0 = tcg_temp_new_i32();
5715 gen_load_fpr32h(fp0, fs);
5716 tcg_gen_ext_i32_tl(t0, fp0);
5717 tcg_temp_free_i32(fp0);
5719 gen_store_gpr(t0, rt);
5723 gen_load_gpr(t0, rt);
5725 TCGv_i32 fp0 = tcg_temp_new_i32();
5727 tcg_gen_trunc_tl_i32(fp0, t0);
5728 gen_store_fpr32h(fp0, fs);
5729 tcg_temp_free_i32(fp0);
5735 generate_exception (ctx, EXCP_RI);
5738 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5744 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5746 int l1 = gen_new_label();
5749 TCGv t0 = tcg_temp_local_new();
5750 TCGv_i32 r_tmp = tcg_temp_new_i32();
5753 ccbit = 1 << (24 + cc);
5761 gen_load_gpr(t0, rd);
5762 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5763 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5764 tcg_temp_free_i32(r_tmp);
5765 gen_load_gpr(t0, rs);
5767 gen_store_gpr(t0, rd);
5771 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5775 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5776 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5777 int l1 = gen_new_label();
5780 ccbit = 1 << (24 + cc);
5789 gen_load_fpr32(fp0, fd);
5790 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5791 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5792 tcg_temp_free_i32(r_tmp1);
5793 gen_load_fpr32(fp0, fs);
5795 gen_store_fpr32(fp0, fd);
5796 tcg_temp_free_i32(fp0);
5799 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
5803 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5804 TCGv_i64 fp0 = tcg_temp_local_new_i64();
5805 int l1 = gen_new_label();
5808 ccbit = 1 << (24 + cc);
5817 gen_load_fpr64(ctx, fp0, fd);
5818 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5819 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5820 tcg_temp_free_i32(r_tmp1);
5821 gen_load_fpr64(ctx, fp0, fs);
5823 gen_store_fpr64(ctx, fp0, fd);
5824 tcg_temp_free_i64(fp0);
5827 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
5829 uint32_t ccbit1, ccbit2;
5831 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5832 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5833 int l1 = gen_new_label();
5834 int l2 = gen_new_label();
5837 ccbit1 = 1 << (24 + cc);
5838 ccbit2 = 1 << (25 + cc);
5849 gen_load_fpr32(fp0, fd);
5850 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit1);
5851 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5852 gen_load_fpr32(fp0, fs);
5854 gen_store_fpr32(fp0, fd);
5856 gen_load_fpr32h(fp0, fd);
5857 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit2);
5858 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l2);
5859 gen_load_fpr32h(fp0, fs);
5861 gen_store_fpr32h(fp0, fd);
5863 tcg_temp_free_i32(r_tmp1);
5864 tcg_temp_free_i32(fp0);
5868 static void gen_farith (DisasContext *ctx, uint32_t op1,
5869 int ft, int fs, int fd, int cc)
5871 const char *opn = "farith";
5872 const char *condnames[] = {
5890 const char *condnames_abs[] = {
5908 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5909 uint32_t func = ctx->opcode & 0x3f;
5911 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5914 TCGv_i32 fp0 = tcg_temp_new_i32();
5915 TCGv_i32 fp1 = tcg_temp_new_i32();
5917 gen_load_fpr32(fp0, fs);
5918 gen_load_fpr32(fp1, ft);
5919 gen_helper_float_add_s(fp0, fp0, fp1);
5920 tcg_temp_free_i32(fp1);
5921 gen_store_fpr32(fp0, fd);
5922 tcg_temp_free_i32(fp0);
5929 TCGv_i32 fp0 = tcg_temp_new_i32();
5930 TCGv_i32 fp1 = tcg_temp_new_i32();
5932 gen_load_fpr32(fp0, fs);
5933 gen_load_fpr32(fp1, ft);
5934 gen_helper_float_sub_s(fp0, fp0, fp1);
5935 tcg_temp_free_i32(fp1);
5936 gen_store_fpr32(fp0, fd);
5937 tcg_temp_free_i32(fp0);
5944 TCGv_i32 fp0 = tcg_temp_new_i32();
5945 TCGv_i32 fp1 = tcg_temp_new_i32();
5947 gen_load_fpr32(fp0, fs);
5948 gen_load_fpr32(fp1, ft);
5949 gen_helper_float_mul_s(fp0, fp0, fp1);
5950 tcg_temp_free_i32(fp1);
5951 gen_store_fpr32(fp0, fd);
5952 tcg_temp_free_i32(fp0);
5959 TCGv_i32 fp0 = tcg_temp_new_i32();
5960 TCGv_i32 fp1 = tcg_temp_new_i32();
5962 gen_load_fpr32(fp0, fs);
5963 gen_load_fpr32(fp1, ft);
5964 gen_helper_float_div_s(fp0, fp0, fp1);
5965 tcg_temp_free_i32(fp1);
5966 gen_store_fpr32(fp0, fd);
5967 tcg_temp_free_i32(fp0);
5974 TCGv_i32 fp0 = tcg_temp_new_i32();
5976 gen_load_fpr32(fp0, fs);
5977 gen_helper_float_sqrt_s(fp0, fp0);
5978 gen_store_fpr32(fp0, fd);
5979 tcg_temp_free_i32(fp0);
5985 TCGv_i32 fp0 = tcg_temp_new_i32();
5987 gen_load_fpr32(fp0, fs);
5988 gen_helper_float_abs_s(fp0, fp0);
5989 gen_store_fpr32(fp0, fd);
5990 tcg_temp_free_i32(fp0);
5996 TCGv_i32 fp0 = tcg_temp_new_i32();
5998 gen_load_fpr32(fp0, fs);
5999 gen_store_fpr32(fp0, fd);
6000 tcg_temp_free_i32(fp0);
6006 TCGv_i32 fp0 = tcg_temp_new_i32();
6008 gen_load_fpr32(fp0, fs);
6009 gen_helper_float_chs_s(fp0, fp0);
6010 gen_store_fpr32(fp0, fd);
6011 tcg_temp_free_i32(fp0);
6016 check_cp1_64bitmode(ctx);
6018 TCGv_i32 fp32 = tcg_temp_new_i32();
6019 TCGv_i64 fp64 = tcg_temp_new_i64();
6021 gen_load_fpr32(fp32, fs);
6022 gen_helper_float_roundl_s(fp64, fp32);
6023 tcg_temp_free_i32(fp32);
6024 gen_store_fpr64(ctx, fp64, fd);
6025 tcg_temp_free_i64(fp64);
6030 check_cp1_64bitmode(ctx);
6032 TCGv_i32 fp32 = tcg_temp_new_i32();
6033 TCGv_i64 fp64 = tcg_temp_new_i64();
6035 gen_load_fpr32(fp32, fs);
6036 gen_helper_float_truncl_s(fp64, fp32);
6037 tcg_temp_free_i32(fp32);
6038 gen_store_fpr64(ctx, fp64, fd);
6039 tcg_temp_free_i64(fp64);
6044 check_cp1_64bitmode(ctx);
6046 TCGv_i32 fp32 = tcg_temp_new_i32();
6047 TCGv_i64 fp64 = tcg_temp_new_i64();
6049 gen_load_fpr32(fp32, fs);
6050 gen_helper_float_ceill_s(fp64, fp32);
6051 tcg_temp_free_i32(fp32);
6052 gen_store_fpr64(ctx, fp64, fd);
6053 tcg_temp_free_i64(fp64);
6058 check_cp1_64bitmode(ctx);
6060 TCGv_i32 fp32 = tcg_temp_new_i32();
6061 TCGv_i64 fp64 = tcg_temp_new_i64();
6063 gen_load_fpr32(fp32, fs);
6064 gen_helper_float_floorl_s(fp64, fp32);
6065 tcg_temp_free_i32(fp32);
6066 gen_store_fpr64(ctx, fp64, fd);
6067 tcg_temp_free_i64(fp64);
6073 TCGv_i32 fp0 = tcg_temp_new_i32();
6075 gen_load_fpr32(fp0, fs);
6076 gen_helper_float_roundw_s(fp0, fp0);
6077 gen_store_fpr32(fp0, fd);
6078 tcg_temp_free_i32(fp0);
6084 TCGv_i32 fp0 = tcg_temp_new_i32();
6086 gen_load_fpr32(fp0, fs);
6087 gen_helper_float_truncw_s(fp0, fp0);
6088 gen_store_fpr32(fp0, fd);
6089 tcg_temp_free_i32(fp0);
6095 TCGv_i32 fp0 = tcg_temp_new_i32();
6097 gen_load_fpr32(fp0, fs);
6098 gen_helper_float_ceilw_s(fp0, fp0);
6099 gen_store_fpr32(fp0, fd);
6100 tcg_temp_free_i32(fp0);
6106 TCGv_i32 fp0 = tcg_temp_new_i32();
6108 gen_load_fpr32(fp0, fs);
6109 gen_helper_float_floorw_s(fp0, fp0);
6110 gen_store_fpr32(fp0, fd);
6111 tcg_temp_free_i32(fp0);
6116 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6121 int l1 = gen_new_label();
6122 TCGv t0 = tcg_temp_new();
6123 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6125 gen_load_gpr(t0, ft);
6126 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6127 gen_load_fpr32(fp0, fs);
6128 gen_store_fpr32(fp0, fd);
6129 tcg_temp_free_i32(fp0);
6137 int l1 = gen_new_label();
6138 TCGv t0 = tcg_temp_new();
6139 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6141 gen_load_gpr(t0, ft);
6142 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6143 gen_load_fpr32(fp0, fs);
6144 gen_store_fpr32(fp0, fd);
6145 tcg_temp_free_i32(fp0);
6154 TCGv_i32 fp0 = tcg_temp_new_i32();
6156 gen_load_fpr32(fp0, fs);
6157 gen_helper_float_recip_s(fp0, fp0);
6158 gen_store_fpr32(fp0, fd);
6159 tcg_temp_free_i32(fp0);
6166 TCGv_i32 fp0 = tcg_temp_new_i32();
6168 gen_load_fpr32(fp0, fs);
6169 gen_helper_float_rsqrt_s(fp0, fp0);
6170 gen_store_fpr32(fp0, fd);
6171 tcg_temp_free_i32(fp0);
6176 check_cp1_64bitmode(ctx);
6178 TCGv_i32 fp0 = tcg_temp_new_i32();
6179 TCGv_i32 fp1 = tcg_temp_new_i32();
6181 gen_load_fpr32(fp0, fs);
6182 gen_load_fpr32(fp1, fd);
6183 gen_helper_float_recip2_s(fp0, fp0, fp1);
6184 tcg_temp_free_i32(fp1);
6185 gen_store_fpr32(fp0, fd);
6186 tcg_temp_free_i32(fp0);
6191 check_cp1_64bitmode(ctx);
6193 TCGv_i32 fp0 = tcg_temp_new_i32();
6195 gen_load_fpr32(fp0, fs);
6196 gen_helper_float_recip1_s(fp0, fp0);
6197 gen_store_fpr32(fp0, fd);
6198 tcg_temp_free_i32(fp0);
6203 check_cp1_64bitmode(ctx);
6205 TCGv_i32 fp0 = tcg_temp_new_i32();
6207 gen_load_fpr32(fp0, fs);
6208 gen_helper_float_rsqrt1_s(fp0, fp0);
6209 gen_store_fpr32(fp0, fd);
6210 tcg_temp_free_i32(fp0);
6215 check_cp1_64bitmode(ctx);
6217 TCGv_i32 fp0 = tcg_temp_new_i32();
6218 TCGv_i32 fp1 = tcg_temp_new_i32();
6220 gen_load_fpr32(fp0, fs);
6221 gen_load_fpr32(fp1, ft);
6222 gen_helper_float_rsqrt2_s(fp0, fp0, fp1);
6223 tcg_temp_free_i32(fp1);
6224 gen_store_fpr32(fp0, fd);
6225 tcg_temp_free_i32(fp0);
6230 check_cp1_registers(ctx, fd);
6232 TCGv_i32 fp32 = tcg_temp_new_i32();
6233 TCGv_i64 fp64 = tcg_temp_new_i64();
6235 gen_load_fpr32(fp32, fs);
6236 gen_helper_float_cvtd_s(fp64, fp32);
6237 tcg_temp_free_i32(fp32);
6238 gen_store_fpr64(ctx, fp64, fd);
6239 tcg_temp_free_i64(fp64);
6245 TCGv_i32 fp0 = tcg_temp_new_i32();
6247 gen_load_fpr32(fp0, fs);
6248 gen_helper_float_cvtw_s(fp0, fp0);
6249 gen_store_fpr32(fp0, fd);
6250 tcg_temp_free_i32(fp0);
6255 check_cp1_64bitmode(ctx);
6257 TCGv_i32 fp32 = tcg_temp_new_i32();
6258 TCGv_i64 fp64 = tcg_temp_new_i64();
6260 gen_load_fpr32(fp32, fs);
6261 gen_helper_float_cvtl_s(fp64, fp32);
6262 tcg_temp_free_i32(fp32);
6263 gen_store_fpr64(ctx, fp64, fd);
6264 tcg_temp_free_i64(fp64);
6269 check_cp1_64bitmode(ctx);
6271 TCGv_i64 fp64 = tcg_temp_new_i64();
6272 TCGv_i32 fp32_0 = tcg_temp_new_i32();
6273 TCGv_i32 fp32_1 = tcg_temp_new_i32();
6275 gen_load_fpr32(fp32_0, fs);
6276 gen_load_fpr32(fp32_1, ft);
6277 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6278 tcg_temp_free_i32(fp32_1);
6279 tcg_temp_free_i32(fp32_0);
6280 gen_store_fpr64(ctx, fp64, fd);
6281 tcg_temp_free_i64(fp64);
6302 TCGv_i32 fp0 = tcg_temp_new_i32();
6303 TCGv_i32 fp1 = tcg_temp_new_i32();
6305 gen_load_fpr32(fp0, fs);
6306 gen_load_fpr32(fp1, ft);
6307 if (ctx->opcode & (1 << 6)) {
6309 gen_cmpabs_s(func-48, fp0, fp1, cc);
6310 opn = condnames_abs[func-48];
6312 gen_cmp_s(func-48, fp0, fp1, cc);
6313 opn = condnames[func-48];
6315 tcg_temp_free_i32(fp0);
6316 tcg_temp_free_i32(fp1);
6320 check_cp1_registers(ctx, fs | ft | fd);
6322 TCGv_i64 fp0 = tcg_temp_new_i64();
6323 TCGv_i64 fp1 = tcg_temp_new_i64();
6325 gen_load_fpr64(ctx, fp0, fs);
6326 gen_load_fpr64(ctx, fp1, ft);
6327 gen_helper_float_add_d(fp0, fp0, fp1);
6328 tcg_temp_free_i64(fp1);
6329 gen_store_fpr64(ctx, fp0, fd);
6330 tcg_temp_free_i64(fp0);
6336 check_cp1_registers(ctx, fs | ft | fd);
6338 TCGv_i64 fp0 = tcg_temp_new_i64();
6339 TCGv_i64 fp1 = tcg_temp_new_i64();
6341 gen_load_fpr64(ctx, fp0, fs);
6342 gen_load_fpr64(ctx, fp1, ft);
6343 gen_helper_float_sub_d(fp0, fp0, fp1);
6344 tcg_temp_free_i64(fp1);
6345 gen_store_fpr64(ctx, fp0, fd);
6346 tcg_temp_free_i64(fp0);
6352 check_cp1_registers(ctx, fs | ft | fd);
6354 TCGv_i64 fp0 = tcg_temp_new_i64();
6355 TCGv_i64 fp1 = tcg_temp_new_i64();
6357 gen_load_fpr64(ctx, fp0, fs);
6358 gen_load_fpr64(ctx, fp1, ft);
6359 gen_helper_float_mul_d(fp0, fp0, fp1);
6360 tcg_temp_free_i64(fp1);
6361 gen_store_fpr64(ctx, fp0, fd);
6362 tcg_temp_free_i64(fp0);
6368 check_cp1_registers(ctx, fs | ft | fd);
6370 TCGv_i64 fp0 = tcg_temp_new_i64();
6371 TCGv_i64 fp1 = tcg_temp_new_i64();
6373 gen_load_fpr64(ctx, fp0, fs);
6374 gen_load_fpr64(ctx, fp1, ft);
6375 gen_helper_float_div_d(fp0, fp0, fp1);
6376 tcg_temp_free_i64(fp1);
6377 gen_store_fpr64(ctx, fp0, fd);
6378 tcg_temp_free_i64(fp0);
6384 check_cp1_registers(ctx, fs | fd);
6386 TCGv_i64 fp0 = tcg_temp_new_i64();
6388 gen_load_fpr64(ctx, fp0, fs);
6389 gen_helper_float_sqrt_d(fp0, fp0);
6390 gen_store_fpr64(ctx, fp0, fd);
6391 tcg_temp_free_i64(fp0);
6396 check_cp1_registers(ctx, fs | fd);
6398 TCGv_i64 fp0 = tcg_temp_new_i64();
6400 gen_load_fpr64(ctx, fp0, fs);
6401 gen_helper_float_abs_d(fp0, fp0);
6402 gen_store_fpr64(ctx, fp0, fd);
6403 tcg_temp_free_i64(fp0);
6408 check_cp1_registers(ctx, fs | fd);
6410 TCGv_i64 fp0 = tcg_temp_new_i64();
6412 gen_load_fpr64(ctx, fp0, fs);
6413 gen_store_fpr64(ctx, fp0, fd);
6414 tcg_temp_free_i64(fp0);
6419 check_cp1_registers(ctx, fs | fd);
6421 TCGv_i64 fp0 = tcg_temp_new_i64();
6423 gen_load_fpr64(ctx, fp0, fs);
6424 gen_helper_float_chs_d(fp0, fp0);
6425 gen_store_fpr64(ctx, fp0, fd);
6426 tcg_temp_free_i64(fp0);
6431 check_cp1_64bitmode(ctx);
6433 TCGv_i64 fp0 = tcg_temp_new_i64();
6435 gen_load_fpr64(ctx, fp0, fs);
6436 gen_helper_float_roundl_d(fp0, fp0);
6437 gen_store_fpr64(ctx, fp0, fd);
6438 tcg_temp_free_i64(fp0);
6443 check_cp1_64bitmode(ctx);
6445 TCGv_i64 fp0 = tcg_temp_new_i64();
6447 gen_load_fpr64(ctx, fp0, fs);
6448 gen_helper_float_truncl_d(fp0, fp0);
6449 gen_store_fpr64(ctx, fp0, fd);
6450 tcg_temp_free_i64(fp0);
6455 check_cp1_64bitmode(ctx);
6457 TCGv_i64 fp0 = tcg_temp_new_i64();
6459 gen_load_fpr64(ctx, fp0, fs);
6460 gen_helper_float_ceill_d(fp0, fp0);
6461 gen_store_fpr64(ctx, fp0, fd);
6462 tcg_temp_free_i64(fp0);
6467 check_cp1_64bitmode(ctx);
6469 TCGv_i64 fp0 = tcg_temp_new_i64();
6471 gen_load_fpr64(ctx, fp0, fs);
6472 gen_helper_float_floorl_d(fp0, fp0);
6473 gen_store_fpr64(ctx, fp0, fd);
6474 tcg_temp_free_i64(fp0);
6479 check_cp1_registers(ctx, fs);
6481 TCGv_i32 fp32 = tcg_temp_new_i32();
6482 TCGv_i64 fp64 = tcg_temp_new_i64();
6484 gen_load_fpr64(ctx, fp64, fs);
6485 gen_helper_float_roundw_d(fp32, fp64);
6486 tcg_temp_free_i64(fp64);
6487 gen_store_fpr32(fp32, fd);
6488 tcg_temp_free_i32(fp32);
6493 check_cp1_registers(ctx, fs);
6495 TCGv_i32 fp32 = tcg_temp_new_i32();
6496 TCGv_i64 fp64 = tcg_temp_new_i64();
6498 gen_load_fpr64(ctx, fp64, fs);
6499 gen_helper_float_truncw_d(fp32, fp64);
6500 tcg_temp_free_i64(fp64);
6501 gen_store_fpr32(fp32, fd);
6502 tcg_temp_free_i32(fp32);
6507 check_cp1_registers(ctx, fs);
6509 TCGv_i32 fp32 = tcg_temp_new_i32();
6510 TCGv_i64 fp64 = tcg_temp_new_i64();
6512 gen_load_fpr64(ctx, fp64, fs);
6513 gen_helper_float_ceilw_d(fp32, fp64);
6514 tcg_temp_free_i64(fp64);
6515 gen_store_fpr32(fp32, fd);
6516 tcg_temp_free_i32(fp32);
6521 check_cp1_registers(ctx, fs);
6523 TCGv_i32 fp32 = tcg_temp_new_i32();
6524 TCGv_i64 fp64 = tcg_temp_new_i64();
6526 gen_load_fpr64(ctx, fp64, fs);
6527 gen_helper_float_floorw_d(fp32, fp64);
6528 tcg_temp_free_i64(fp64);
6529 gen_store_fpr32(fp32, fd);
6530 tcg_temp_free_i32(fp32);
6535 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6540 int l1 = gen_new_label();
6541 TCGv t0 = tcg_temp_new();
6542 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6544 gen_load_gpr(t0, ft);
6545 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6546 gen_load_fpr64(ctx, fp0, fs);
6547 gen_store_fpr64(ctx, fp0, fd);
6548 tcg_temp_free_i64(fp0);
6556 int l1 = gen_new_label();
6557 TCGv t0 = tcg_temp_new();
6558 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6560 gen_load_gpr(t0, ft);
6561 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6562 gen_load_fpr64(ctx, fp0, fs);
6563 gen_store_fpr64(ctx, fp0, fd);
6564 tcg_temp_free_i64(fp0);
6571 check_cp1_64bitmode(ctx);
6573 TCGv_i64 fp0 = tcg_temp_new_i64();
6575 gen_load_fpr64(ctx, fp0, fs);
6576 gen_helper_float_recip_d(fp0, fp0);
6577 gen_store_fpr64(ctx, fp0, fd);
6578 tcg_temp_free_i64(fp0);
6583 check_cp1_64bitmode(ctx);
6585 TCGv_i64 fp0 = tcg_temp_new_i64();
6587 gen_load_fpr64(ctx, fp0, fs);
6588 gen_helper_float_rsqrt_d(fp0, fp0);
6589 gen_store_fpr64(ctx, fp0, fd);
6590 tcg_temp_free_i64(fp0);
6595 check_cp1_64bitmode(ctx);
6597 TCGv_i64 fp0 = tcg_temp_new_i64();
6598 TCGv_i64 fp1 = tcg_temp_new_i64();
6600 gen_load_fpr64(ctx, fp0, fs);
6601 gen_load_fpr64(ctx, fp1, ft);
6602 gen_helper_float_recip2_d(fp0, fp0, fp1);
6603 tcg_temp_free_i64(fp1);
6604 gen_store_fpr64(ctx, fp0, fd);
6605 tcg_temp_free_i64(fp0);
6610 check_cp1_64bitmode(ctx);
6612 TCGv_i64 fp0 = tcg_temp_new_i64();
6614 gen_load_fpr64(ctx, fp0, fs);
6615 gen_helper_float_recip1_d(fp0, fp0);
6616 gen_store_fpr64(ctx, fp0, fd);
6617 tcg_temp_free_i64(fp0);
6622 check_cp1_64bitmode(ctx);
6624 TCGv_i64 fp0 = tcg_temp_new_i64();
6626 gen_load_fpr64(ctx, fp0, fs);
6627 gen_helper_float_rsqrt1_d(fp0, fp0);
6628 gen_store_fpr64(ctx, fp0, fd);
6629 tcg_temp_free_i64(fp0);
6634 check_cp1_64bitmode(ctx);
6636 TCGv_i64 fp0 = tcg_temp_new_i64();
6637 TCGv_i64 fp1 = tcg_temp_new_i64();
6639 gen_load_fpr64(ctx, fp0, fs);
6640 gen_load_fpr64(ctx, fp1, ft);
6641 gen_helper_float_rsqrt2_d(fp0, fp0, fp1);
6642 tcg_temp_free_i64(fp1);
6643 gen_store_fpr64(ctx, fp0, fd);
6644 tcg_temp_free_i64(fp0);
6665 TCGv_i64 fp0 = tcg_temp_new_i64();
6666 TCGv_i64 fp1 = tcg_temp_new_i64();
6668 gen_load_fpr64(ctx, fp0, fs);
6669 gen_load_fpr64(ctx, fp1, ft);
6670 if (ctx->opcode & (1 << 6)) {
6672 check_cp1_registers(ctx, fs | ft);
6673 gen_cmpabs_d(func-48, fp0, fp1, cc);
6674 opn = condnames_abs[func-48];
6676 check_cp1_registers(ctx, fs | ft);
6677 gen_cmp_d(func-48, fp0, fp1, cc);
6678 opn = condnames[func-48];
6680 tcg_temp_free_i64(fp0);
6681 tcg_temp_free_i64(fp1);
6685 check_cp1_registers(ctx, fs);
6687 TCGv_i32 fp32 = tcg_temp_new_i32();
6688 TCGv_i64 fp64 = tcg_temp_new_i64();
6690 gen_load_fpr64(ctx, fp64, fs);
6691 gen_helper_float_cvts_d(fp32, fp64);
6692 tcg_temp_free_i64(fp64);
6693 gen_store_fpr32(fp32, fd);
6694 tcg_temp_free_i32(fp32);
6699 check_cp1_registers(ctx, fs);
6701 TCGv_i32 fp32 = tcg_temp_new_i32();
6702 TCGv_i64 fp64 = tcg_temp_new_i64();
6704 gen_load_fpr64(ctx, fp64, fs);
6705 gen_helper_float_cvtw_d(fp32, fp64);
6706 tcg_temp_free_i64(fp64);
6707 gen_store_fpr32(fp32, fd);
6708 tcg_temp_free_i32(fp32);
6713 check_cp1_64bitmode(ctx);
6715 TCGv_i64 fp0 = tcg_temp_new_i64();
6717 gen_load_fpr64(ctx, fp0, fs);
6718 gen_helper_float_cvtl_d(fp0, fp0);
6719 gen_store_fpr64(ctx, fp0, fd);
6720 tcg_temp_free_i64(fp0);
6726 TCGv_i32 fp0 = tcg_temp_new_i32();
6728 gen_load_fpr32(fp0, fs);
6729 gen_helper_float_cvts_w(fp0, fp0);
6730 gen_store_fpr32(fp0, fd);
6731 tcg_temp_free_i32(fp0);
6736 check_cp1_registers(ctx, fd);
6738 TCGv_i32 fp32 = tcg_temp_new_i32();
6739 TCGv_i64 fp64 = tcg_temp_new_i64();
6741 gen_load_fpr32(fp32, fs);
6742 gen_helper_float_cvtd_w(fp64, fp32);
6743 tcg_temp_free_i32(fp32);
6744 gen_store_fpr64(ctx, fp64, fd);
6745 tcg_temp_free_i64(fp64);
6750 check_cp1_64bitmode(ctx);
6752 TCGv_i32 fp32 = tcg_temp_new_i32();
6753 TCGv_i64 fp64 = tcg_temp_new_i64();
6755 gen_load_fpr64(ctx, fp64, fs);
6756 gen_helper_float_cvts_l(fp32, fp64);
6757 tcg_temp_free_i64(fp64);
6758 gen_store_fpr32(fp32, fd);
6759 tcg_temp_free_i32(fp32);
6764 check_cp1_64bitmode(ctx);
6766 TCGv_i64 fp0 = tcg_temp_new_i64();
6768 gen_load_fpr64(ctx, fp0, fs);
6769 gen_helper_float_cvtd_l(fp0, fp0);
6770 gen_store_fpr64(ctx, fp0, fd);
6771 tcg_temp_free_i64(fp0);
6776 check_cp1_64bitmode(ctx);
6778 TCGv_i64 fp0 = tcg_temp_new_i64();
6780 gen_load_fpr64(ctx, fp0, fs);
6781 gen_helper_float_cvtps_pw(fp0, fp0);
6782 gen_store_fpr64(ctx, fp0, fd);
6783 tcg_temp_free_i64(fp0);
6788 check_cp1_64bitmode(ctx);
6790 TCGv_i64 fp0 = tcg_temp_new_i64();
6791 TCGv_i64 fp1 = tcg_temp_new_i64();
6793 gen_load_fpr64(ctx, fp0, fs);
6794 gen_load_fpr64(ctx, fp1, ft);
6795 gen_helper_float_add_ps(fp0, fp0, fp1);
6796 tcg_temp_free_i64(fp1);
6797 gen_store_fpr64(ctx, fp0, fd);
6798 tcg_temp_free_i64(fp0);
6803 check_cp1_64bitmode(ctx);
6805 TCGv_i64 fp0 = tcg_temp_new_i64();
6806 TCGv_i64 fp1 = tcg_temp_new_i64();
6808 gen_load_fpr64(ctx, fp0, fs);
6809 gen_load_fpr64(ctx, fp1, ft);
6810 gen_helper_float_sub_ps(fp0, fp0, fp1);
6811 tcg_temp_free_i64(fp1);
6812 gen_store_fpr64(ctx, fp0, fd);
6813 tcg_temp_free_i64(fp0);
6818 check_cp1_64bitmode(ctx);
6820 TCGv_i64 fp0 = tcg_temp_new_i64();
6821 TCGv_i64 fp1 = tcg_temp_new_i64();
6823 gen_load_fpr64(ctx, fp0, fs);
6824 gen_load_fpr64(ctx, fp1, ft);
6825 gen_helper_float_mul_ps(fp0, fp0, fp1);
6826 tcg_temp_free_i64(fp1);
6827 gen_store_fpr64(ctx, fp0, fd);
6828 tcg_temp_free_i64(fp0);
6833 check_cp1_64bitmode(ctx);
6835 TCGv_i64 fp0 = tcg_temp_new_i64();
6837 gen_load_fpr64(ctx, fp0, fs);
6838 gen_helper_float_abs_ps(fp0, fp0);
6839 gen_store_fpr64(ctx, fp0, fd);
6840 tcg_temp_free_i64(fp0);
6845 check_cp1_64bitmode(ctx);
6847 TCGv_i64 fp0 = tcg_temp_new_i64();
6849 gen_load_fpr64(ctx, fp0, fs);
6850 gen_store_fpr64(ctx, fp0, fd);
6851 tcg_temp_free_i64(fp0);
6856 check_cp1_64bitmode(ctx);
6858 TCGv_i64 fp0 = tcg_temp_new_i64();
6860 gen_load_fpr64(ctx, fp0, fs);
6861 gen_helper_float_chs_ps(fp0, fp0);
6862 gen_store_fpr64(ctx, fp0, fd);
6863 tcg_temp_free_i64(fp0);
6868 check_cp1_64bitmode(ctx);
6869 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6873 check_cp1_64bitmode(ctx);
6875 int l1 = gen_new_label();
6876 TCGv t0 = tcg_temp_new();
6877 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6878 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6880 gen_load_gpr(t0, ft);
6881 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6882 gen_load_fpr32(fp0, fs);
6883 gen_load_fpr32h(fph0, fs);
6884 gen_store_fpr32(fp0, fd);
6885 gen_store_fpr32h(fph0, fd);
6886 tcg_temp_free_i32(fp0);
6887 tcg_temp_free_i32(fph0);
6894 check_cp1_64bitmode(ctx);
6896 int l1 = gen_new_label();
6897 TCGv t0 = tcg_temp_new();
6898 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6899 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6901 gen_load_gpr(t0, ft);
6902 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6903 gen_load_fpr32(fp0, fs);
6904 gen_load_fpr32h(fph0, fs);
6905 gen_store_fpr32(fp0, fd);
6906 gen_store_fpr32h(fph0, fd);
6907 tcg_temp_free_i32(fp0);
6908 tcg_temp_free_i32(fph0);
6915 check_cp1_64bitmode(ctx);
6917 TCGv_i64 fp0 = tcg_temp_new_i64();
6918 TCGv_i64 fp1 = tcg_temp_new_i64();
6920 gen_load_fpr64(ctx, fp0, ft);
6921 gen_load_fpr64(ctx, fp1, fs);
6922 gen_helper_float_addr_ps(fp0, fp0, fp1);
6923 tcg_temp_free_i64(fp1);
6924 gen_store_fpr64(ctx, fp0, fd);
6925 tcg_temp_free_i64(fp0);
6930 check_cp1_64bitmode(ctx);
6932 TCGv_i64 fp0 = tcg_temp_new_i64();
6933 TCGv_i64 fp1 = tcg_temp_new_i64();
6935 gen_load_fpr64(ctx, fp0, ft);
6936 gen_load_fpr64(ctx, fp1, fs);
6937 gen_helper_float_mulr_ps(fp0, fp0, fp1);
6938 tcg_temp_free_i64(fp1);
6939 gen_store_fpr64(ctx, fp0, fd);
6940 tcg_temp_free_i64(fp0);
6945 check_cp1_64bitmode(ctx);
6947 TCGv_i64 fp0 = tcg_temp_new_i64();
6948 TCGv_i64 fp1 = tcg_temp_new_i64();
6950 gen_load_fpr64(ctx, fp0, fs);
6951 gen_load_fpr64(ctx, fp1, fd);
6952 gen_helper_float_recip2_ps(fp0, fp0, fp1);
6953 tcg_temp_free_i64(fp1);
6954 gen_store_fpr64(ctx, fp0, fd);
6955 tcg_temp_free_i64(fp0);
6960 check_cp1_64bitmode(ctx);
6962 TCGv_i64 fp0 = tcg_temp_new_i64();
6964 gen_load_fpr64(ctx, fp0, fs);
6965 gen_helper_float_recip1_ps(fp0, fp0);
6966 gen_store_fpr64(ctx, fp0, fd);
6967 tcg_temp_free_i64(fp0);
6972 check_cp1_64bitmode(ctx);
6974 TCGv_i64 fp0 = tcg_temp_new_i64();
6976 gen_load_fpr64(ctx, fp0, fs);
6977 gen_helper_float_rsqrt1_ps(fp0, fp0);
6978 gen_store_fpr64(ctx, fp0, fd);
6979 tcg_temp_free_i64(fp0);
6984 check_cp1_64bitmode(ctx);
6986 TCGv_i64 fp0 = tcg_temp_new_i64();
6987 TCGv_i64 fp1 = tcg_temp_new_i64();
6989 gen_load_fpr64(ctx, fp0, fs);
6990 gen_load_fpr64(ctx, fp1, ft);
6991 gen_helper_float_rsqrt2_ps(fp0, fp0, fp1);
6992 tcg_temp_free_i64(fp1);
6993 gen_store_fpr64(ctx, fp0, fd);
6994 tcg_temp_free_i64(fp0);
6999 check_cp1_64bitmode(ctx);
7001 TCGv_i32 fp0 = tcg_temp_new_i32();
7003 gen_load_fpr32h(fp0, fs);
7004 gen_helper_float_cvts_pu(fp0, fp0);
7005 gen_store_fpr32(fp0, fd);
7006 tcg_temp_free_i32(fp0);
7011 check_cp1_64bitmode(ctx);
7013 TCGv_i64 fp0 = tcg_temp_new_i64();
7015 gen_load_fpr64(ctx, fp0, fs);
7016 gen_helper_float_cvtpw_ps(fp0, fp0);
7017 gen_store_fpr64(ctx, fp0, fd);
7018 tcg_temp_free_i64(fp0);
7023 check_cp1_64bitmode(ctx);
7025 TCGv_i32 fp0 = tcg_temp_new_i32();
7027 gen_load_fpr32(fp0, fs);
7028 gen_helper_float_cvts_pl(fp0, fp0);
7029 gen_store_fpr32(fp0, fd);
7030 tcg_temp_free_i32(fp0);
7035 check_cp1_64bitmode(ctx);
7037 TCGv_i32 fp0 = tcg_temp_new_i32();
7038 TCGv_i32 fp1 = tcg_temp_new_i32();
7040 gen_load_fpr32(fp0, fs);
7041 gen_load_fpr32(fp1, ft);
7042 gen_store_fpr32h(fp0, fd);
7043 gen_store_fpr32(fp1, fd);
7044 tcg_temp_free_i32(fp0);
7045 tcg_temp_free_i32(fp1);
7050 check_cp1_64bitmode(ctx);
7052 TCGv_i32 fp0 = tcg_temp_new_i32();
7053 TCGv_i32 fp1 = tcg_temp_new_i32();
7055 gen_load_fpr32(fp0, fs);
7056 gen_load_fpr32h(fp1, ft);
7057 gen_store_fpr32(fp1, fd);
7058 gen_store_fpr32h(fp0, fd);
7059 tcg_temp_free_i32(fp0);
7060 tcg_temp_free_i32(fp1);
7065 check_cp1_64bitmode(ctx);
7067 TCGv_i32 fp0 = tcg_temp_new_i32();
7068 TCGv_i32 fp1 = tcg_temp_new_i32();
7070 gen_load_fpr32h(fp0, fs);
7071 gen_load_fpr32(fp1, ft);
7072 gen_store_fpr32(fp1, fd);
7073 gen_store_fpr32h(fp0, fd);
7074 tcg_temp_free_i32(fp0);
7075 tcg_temp_free_i32(fp1);
7080 check_cp1_64bitmode(ctx);
7082 TCGv_i32 fp0 = tcg_temp_new_i32();
7083 TCGv_i32 fp1 = tcg_temp_new_i32();
7085 gen_load_fpr32h(fp0, fs);
7086 gen_load_fpr32h(fp1, ft);
7087 gen_store_fpr32(fp1, fd);
7088 gen_store_fpr32h(fp0, fd);
7089 tcg_temp_free_i32(fp0);
7090 tcg_temp_free_i32(fp1);
7110 check_cp1_64bitmode(ctx);
7112 TCGv_i64 fp0 = tcg_temp_new_i64();
7113 TCGv_i64 fp1 = tcg_temp_new_i64();
7115 gen_load_fpr64(ctx, fp0, fs);
7116 gen_load_fpr64(ctx, fp1, ft);
7117 if (ctx->opcode & (1 << 6)) {
7118 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7119 opn = condnames_abs[func-48];
7121 gen_cmp_ps(func-48, fp0, fp1, cc);
7122 opn = condnames[func-48];
7124 tcg_temp_free_i64(fp0);
7125 tcg_temp_free_i64(fp1);
7130 generate_exception (ctx, EXCP_RI);
7135 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7138 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7141 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7146 /* Coprocessor 3 (FPU) */
7147 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7148 int fd, int fs, int base, int index)
7150 const char *opn = "extended float load/store";
7152 TCGv t0 = tcg_temp_local_new();
7153 TCGv t1 = tcg_temp_local_new();
7156 gen_load_gpr(t0, index);
7157 } else if (index == 0) {
7158 gen_load_gpr(t0, base);
7160 gen_load_gpr(t0, index);
7161 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
7163 /* Don't do NOP if destination is zero: we must perform the actual
7169 TCGv_i32 fp0 = tcg_temp_new_i32();
7171 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
7172 tcg_gen_trunc_tl_i32(fp0, t1);
7173 gen_store_fpr32(fp0, fd);
7174 tcg_temp_free_i32(fp0);
7180 check_cp1_registers(ctx, fd);
7182 TCGv_i64 fp0 = tcg_temp_new_i64();
7184 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7185 gen_store_fpr64(ctx, fp0, fd);
7186 tcg_temp_free_i64(fp0);
7191 check_cp1_64bitmode(ctx);
7192 tcg_gen_andi_tl(t0, t0, ~0x7);
7194 TCGv_i64 fp0 = tcg_temp_new_i64();
7196 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7197 gen_store_fpr64(ctx, fp0, fd);
7198 tcg_temp_free_i64(fp0);
7205 TCGv_i32 fp0 = tcg_temp_new_i32();
7207 gen_load_fpr32(fp0, fs);
7208 tcg_gen_extu_i32_tl(t1, fp0);
7209 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
7210 tcg_temp_free_i32(fp0);
7217 check_cp1_registers(ctx, fs);
7219 TCGv_i64 fp0 = tcg_temp_new_i64();
7221 gen_load_fpr64(ctx, fp0, fs);
7222 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7223 tcg_temp_free_i64(fp0);
7229 check_cp1_64bitmode(ctx);
7230 tcg_gen_andi_tl(t0, t0, ~0x7);
7232 TCGv_i64 fp0 = tcg_temp_new_i64();
7234 gen_load_fpr64(ctx, fp0, fs);
7235 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7236 tcg_temp_free_i64(fp0);
7243 generate_exception(ctx, EXCP_RI);
7250 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7251 regnames[index], regnames[base]);
7254 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7255 int fd, int fr, int fs, int ft)
7257 const char *opn = "flt3_arith";
7261 check_cp1_64bitmode(ctx);
7263 TCGv t0 = tcg_temp_local_new();
7264 TCGv_i32 fp0 = tcg_temp_local_new_i32();
7265 TCGv_i32 fph0 = tcg_temp_local_new_i32();
7266 TCGv_i32 fp1 = tcg_temp_local_new_i32();
7267 TCGv_i32 fph1 = tcg_temp_local_new_i32();
7268 int l1 = gen_new_label();
7269 int l2 = gen_new_label();
7271 gen_load_gpr(t0, fr);
7272 tcg_gen_andi_tl(t0, t0, 0x7);
7273 gen_load_fpr32(fp0, fs);
7274 gen_load_fpr32h(fph0, fs);
7275 gen_load_fpr32(fp1, ft);
7276 gen_load_fpr32h(fph1, ft);
7278 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7279 gen_store_fpr32(fp0, fd);
7280 gen_store_fpr32h(fph0, fd);
7283 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7285 #ifdef TARGET_WORDS_BIGENDIAN
7286 gen_store_fpr32(fph1, fd);
7287 gen_store_fpr32h(fp0, fd);
7289 gen_store_fpr32(fph0, fd);
7290 gen_store_fpr32h(fp1, fd);
7293 tcg_temp_free_i32(fp0);
7294 tcg_temp_free_i32(fph0);
7295 tcg_temp_free_i32(fp1);
7296 tcg_temp_free_i32(fph1);
7303 TCGv_i32 fp0 = tcg_temp_new_i32();
7304 TCGv_i32 fp1 = tcg_temp_new_i32();
7305 TCGv_i32 fp2 = tcg_temp_new_i32();
7307 gen_load_fpr32(fp0, fs);
7308 gen_load_fpr32(fp1, ft);
7309 gen_load_fpr32(fp2, fr);
7310 gen_helper_float_muladd_s(fp2, fp0, fp1, fp2);
7311 tcg_temp_free_i32(fp0);
7312 tcg_temp_free_i32(fp1);
7313 gen_store_fpr32(fp2, fd);
7314 tcg_temp_free_i32(fp2);
7320 check_cp1_registers(ctx, fd | fs | ft | fr);
7322 TCGv_i64 fp0 = tcg_temp_new_i64();
7323 TCGv_i64 fp1 = tcg_temp_new_i64();
7324 TCGv_i64 fp2 = tcg_temp_new_i64();
7326 gen_load_fpr64(ctx, fp0, fs);
7327 gen_load_fpr64(ctx, fp1, ft);
7328 gen_load_fpr64(ctx, fp2, fr);
7329 gen_helper_float_muladd_d(fp2, fp0, fp1, fp2);
7330 tcg_temp_free_i64(fp0);
7331 tcg_temp_free_i64(fp1);
7332 gen_store_fpr64(ctx, fp2, fd);
7333 tcg_temp_free_i64(fp2);
7338 check_cp1_64bitmode(ctx);
7340 TCGv_i64 fp0 = tcg_temp_new_i64();
7341 TCGv_i64 fp1 = tcg_temp_new_i64();
7342 TCGv_i64 fp2 = tcg_temp_new_i64();
7344 gen_load_fpr64(ctx, fp0, fs);
7345 gen_load_fpr64(ctx, fp1, ft);
7346 gen_load_fpr64(ctx, fp2, fr);
7347 gen_helper_float_muladd_ps(fp2, fp0, fp1, fp2);
7348 tcg_temp_free_i64(fp0);
7349 tcg_temp_free_i64(fp1);
7350 gen_store_fpr64(ctx, fp2, fd);
7351 tcg_temp_free_i64(fp2);
7358 TCGv_i32 fp0 = tcg_temp_new_i32();
7359 TCGv_i32 fp1 = tcg_temp_new_i32();
7360 TCGv_i32 fp2 = tcg_temp_new_i32();
7362 gen_load_fpr32(fp0, fs);
7363 gen_load_fpr32(fp1, ft);
7364 gen_load_fpr32(fp2, fr);
7365 gen_helper_float_mulsub_s(fp2, fp0, fp1, fp2);
7366 tcg_temp_free_i32(fp0);
7367 tcg_temp_free_i32(fp1);
7368 gen_store_fpr32(fp2, fd);
7369 tcg_temp_free_i32(fp2);
7375 check_cp1_registers(ctx, fd | fs | ft | fr);
7377 TCGv_i64 fp0 = tcg_temp_new_i64();
7378 TCGv_i64 fp1 = tcg_temp_new_i64();
7379 TCGv_i64 fp2 = tcg_temp_new_i64();
7381 gen_load_fpr64(ctx, fp0, fs);
7382 gen_load_fpr64(ctx, fp1, ft);
7383 gen_load_fpr64(ctx, fp2, fr);
7384 gen_helper_float_mulsub_d(fp2, fp0, fp1, fp2);
7385 tcg_temp_free_i64(fp0);
7386 tcg_temp_free_i64(fp1);
7387 gen_store_fpr64(ctx, fp2, fd);
7388 tcg_temp_free_i64(fp2);
7393 check_cp1_64bitmode(ctx);
7395 TCGv_i64 fp0 = tcg_temp_new_i64();
7396 TCGv_i64 fp1 = tcg_temp_new_i64();
7397 TCGv_i64 fp2 = tcg_temp_new_i64();
7399 gen_load_fpr64(ctx, fp0, fs);
7400 gen_load_fpr64(ctx, fp1, ft);
7401 gen_load_fpr64(ctx, fp2, fr);
7402 gen_helper_float_mulsub_ps(fp2, fp0, fp1, fp2);
7403 tcg_temp_free_i64(fp0);
7404 tcg_temp_free_i64(fp1);
7405 gen_store_fpr64(ctx, fp2, fd);
7406 tcg_temp_free_i64(fp2);
7413 TCGv_i32 fp0 = tcg_temp_new_i32();
7414 TCGv_i32 fp1 = tcg_temp_new_i32();
7415 TCGv_i32 fp2 = tcg_temp_new_i32();
7417 gen_load_fpr32(fp0, fs);
7418 gen_load_fpr32(fp1, ft);
7419 gen_load_fpr32(fp2, fr);
7420 gen_helper_float_nmuladd_s(fp2, fp0, fp1, fp2);
7421 tcg_temp_free_i32(fp0);
7422 tcg_temp_free_i32(fp1);
7423 gen_store_fpr32(fp2, fd);
7424 tcg_temp_free_i32(fp2);
7430 check_cp1_registers(ctx, fd | fs | ft | fr);
7432 TCGv_i64 fp0 = tcg_temp_new_i64();
7433 TCGv_i64 fp1 = tcg_temp_new_i64();
7434 TCGv_i64 fp2 = tcg_temp_new_i64();
7436 gen_load_fpr64(ctx, fp0, fs);
7437 gen_load_fpr64(ctx, fp1, ft);
7438 gen_load_fpr64(ctx, fp2, fr);
7439 gen_helper_float_nmuladd_d(fp2, fp0, fp1, fp2);
7440 tcg_temp_free_i64(fp0);
7441 tcg_temp_free_i64(fp1);
7442 gen_store_fpr64(ctx, fp2, fd);
7443 tcg_temp_free_i64(fp2);
7448 check_cp1_64bitmode(ctx);
7450 TCGv_i64 fp0 = tcg_temp_new_i64();
7451 TCGv_i64 fp1 = tcg_temp_new_i64();
7452 TCGv_i64 fp2 = tcg_temp_new_i64();
7454 gen_load_fpr64(ctx, fp0, fs);
7455 gen_load_fpr64(ctx, fp1, ft);
7456 gen_load_fpr64(ctx, fp2, fr);
7457 gen_helper_float_nmuladd_ps(fp2, fp0, fp1, fp2);
7458 tcg_temp_free_i64(fp0);
7459 tcg_temp_free_i64(fp1);
7460 gen_store_fpr64(ctx, fp2, fd);
7461 tcg_temp_free_i64(fp2);
7468 TCGv_i32 fp0 = tcg_temp_new_i32();
7469 TCGv_i32 fp1 = tcg_temp_new_i32();
7470 TCGv_i32 fp2 = tcg_temp_new_i32();
7472 gen_load_fpr32(fp0, fs);
7473 gen_load_fpr32(fp1, ft);
7474 gen_load_fpr32(fp2, fr);
7475 gen_helper_float_nmulsub_s(fp2, fp0, fp1, fp2);
7476 tcg_temp_free_i32(fp0);
7477 tcg_temp_free_i32(fp1);
7478 gen_store_fpr32(fp2, fd);
7479 tcg_temp_free_i32(fp2);
7485 check_cp1_registers(ctx, fd | fs | ft | fr);
7487 TCGv_i64 fp0 = tcg_temp_new_i64();
7488 TCGv_i64 fp1 = tcg_temp_new_i64();
7489 TCGv_i64 fp2 = tcg_temp_new_i64();
7491 gen_load_fpr64(ctx, fp0, fs);
7492 gen_load_fpr64(ctx, fp1, ft);
7493 gen_load_fpr64(ctx, fp2, fr);
7494 gen_helper_float_nmulsub_d(fp2, fp0, fp1, fp2);
7495 tcg_temp_free_i64(fp0);
7496 tcg_temp_free_i64(fp1);
7497 gen_store_fpr64(ctx, fp2, fd);
7498 tcg_temp_free_i64(fp2);
7503 check_cp1_64bitmode(ctx);
7505 TCGv_i64 fp0 = tcg_temp_new_i64();
7506 TCGv_i64 fp1 = tcg_temp_new_i64();
7507 TCGv_i64 fp2 = tcg_temp_new_i64();
7509 gen_load_fpr64(ctx, fp0, fs);
7510 gen_load_fpr64(ctx, fp1, ft);
7511 gen_load_fpr64(ctx, fp2, fr);
7512 gen_helper_float_nmulsub_ps(fp2, fp0, fp1, fp2);
7513 tcg_temp_free_i64(fp0);
7514 tcg_temp_free_i64(fp1);
7515 gen_store_fpr64(ctx, fp2, fd);
7516 tcg_temp_free_i64(fp2);
7522 generate_exception (ctx, EXCP_RI);
7525 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7526 fregnames[fs], fregnames[ft]);
7529 /* ISA extensions (ASEs) */
7530 /* MIPS16 extension to MIPS32 */
7531 /* SmartMIPS extension to MIPS32 */
7533 #if defined(TARGET_MIPS64)
7535 /* MDMX extension to MIPS64 */
7539 static void decode_opc (CPUState *env, DisasContext *ctx)
7543 uint32_t op, op1, op2;
7546 /* make sure instructions are on a word boundary */
7547 if (ctx->pc & 0x3) {
7548 env->CP0_BadVAddr = ctx->pc;
7549 generate_exception(ctx, EXCP_AdEL);
7553 /* Handle blikely not taken case */
7554 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7555 int l1 = gen_new_label();
7557 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7558 tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
7559 tcg_gen_movi_i32(hflags, ctx->hflags & ~MIPS_HFLAG_BMASK);
7560 gen_goto_tb(ctx, 1, ctx->pc + 4);
7563 op = MASK_OP_MAJOR(ctx->opcode);
7564 rs = (ctx->opcode >> 21) & 0x1f;
7565 rt = (ctx->opcode >> 16) & 0x1f;
7566 rd = (ctx->opcode >> 11) & 0x1f;
7567 sa = (ctx->opcode >> 6) & 0x1f;
7568 imm = (int16_t)ctx->opcode;
7571 op1 = MASK_SPECIAL(ctx->opcode);
7573 case OPC_SLL: /* Arithmetic with immediate */
7574 case OPC_SRL ... OPC_SRA:
7575 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7577 case OPC_MOVZ ... OPC_MOVN:
7578 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7579 case OPC_SLLV: /* Arithmetic */
7580 case OPC_SRLV ... OPC_SRAV:
7581 case OPC_ADD ... OPC_NOR:
7582 case OPC_SLT ... OPC_SLTU:
7583 gen_arith(env, ctx, op1, rd, rs, rt);
7585 case OPC_MULT ... OPC_DIVU:
7587 check_insn(env, ctx, INSN_VR54XX);
7588 op1 = MASK_MUL_VR54XX(ctx->opcode);
7589 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7591 gen_muldiv(ctx, op1, rs, rt);
7593 case OPC_JR ... OPC_JALR:
7594 gen_compute_branch(ctx, op1, rs, rd, sa);
7596 case OPC_TGE ... OPC_TEQ: /* Traps */
7598 gen_trap(ctx, op1, rs, rt, -1);
7600 case OPC_MFHI: /* Move from HI/LO */
7602 gen_HILO(ctx, op1, rd);
7605 case OPC_MTLO: /* Move to HI/LO */
7606 gen_HILO(ctx, op1, rs);
7608 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7609 #ifdef MIPS_STRICT_STANDARD
7610 MIPS_INVAL("PMON / selsl");
7611 generate_exception(ctx, EXCP_RI);
7613 gen_helper_0i(pmon, sa);
7617 generate_exception(ctx, EXCP_SYSCALL);
7620 generate_exception(ctx, EXCP_BREAK);
7623 #ifdef MIPS_STRICT_STANDARD
7625 generate_exception(ctx, EXCP_RI);
7627 /* Implemented as RI exception for now. */
7628 MIPS_INVAL("spim (unofficial)");
7629 generate_exception(ctx, EXCP_RI);
7637 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7638 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7639 save_cpu_state(ctx, 1);
7640 check_cp1_enabled(ctx);
7641 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7642 (ctx->opcode >> 16) & 1);
7644 generate_exception_err(ctx, EXCP_CpU, 1);
7648 #if defined(TARGET_MIPS64)
7649 /* MIPS64 specific opcodes */
7651 case OPC_DSRL ... OPC_DSRA:
7653 case OPC_DSRL32 ... OPC_DSRA32:
7654 check_insn(env, ctx, ISA_MIPS3);
7656 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7659 case OPC_DSRLV ... OPC_DSRAV:
7660 case OPC_DADD ... OPC_DSUBU:
7661 check_insn(env, ctx, ISA_MIPS3);
7663 gen_arith(env, ctx, op1, rd, rs, rt);
7665 case OPC_DMULT ... OPC_DDIVU:
7666 check_insn(env, ctx, ISA_MIPS3);
7668 gen_muldiv(ctx, op1, rs, rt);
7671 default: /* Invalid */
7672 MIPS_INVAL("special");
7673 generate_exception(ctx, EXCP_RI);
7678 op1 = MASK_SPECIAL2(ctx->opcode);
7680 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7681 case OPC_MSUB ... OPC_MSUBU:
7682 check_insn(env, ctx, ISA_MIPS32);
7683 gen_muldiv(ctx, op1, rs, rt);
7686 gen_arith(env, ctx, op1, rd, rs, rt);
7690 check_insn(env, ctx, ISA_MIPS32);
7691 gen_cl(ctx, op1, rd, rs);
7694 /* XXX: not clear which exception should be raised
7695 * when in debug mode...
7697 check_insn(env, ctx, ISA_MIPS32);
7698 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7699 generate_exception(ctx, EXCP_DBp);
7701 generate_exception(ctx, EXCP_DBp);
7705 #if defined(TARGET_MIPS64)
7708 check_insn(env, ctx, ISA_MIPS64);
7710 gen_cl(ctx, op1, rd, rs);
7713 default: /* Invalid */
7714 MIPS_INVAL("special2");
7715 generate_exception(ctx, EXCP_RI);
7720 op1 = MASK_SPECIAL3(ctx->opcode);
7724 check_insn(env, ctx, ISA_MIPS32R2);
7725 gen_bitops(ctx, op1, rt, rs, sa, rd);
7728 check_insn(env, ctx, ISA_MIPS32R2);
7729 op2 = MASK_BSHFL(ctx->opcode);
7730 gen_bshfl(ctx, op2, rt, rd);
7733 check_insn(env, ctx, ISA_MIPS32R2);
7735 TCGv t0 = tcg_temp_local_new();
7739 save_cpu_state(ctx, 1);
7740 gen_helper_rdhwr_cpunum(t0);
7743 save_cpu_state(ctx, 1);
7744 gen_helper_rdhwr_synci_step(t0);
7747 save_cpu_state(ctx, 1);
7748 gen_helper_rdhwr_cc(t0);
7751 save_cpu_state(ctx, 1);
7752 gen_helper_rdhwr_ccres(t0);
7755 #if defined(CONFIG_USER_ONLY)
7756 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7759 /* XXX: Some CPUs implement this in hardware.
7760 Not supported yet. */
7762 default: /* Invalid */
7763 MIPS_INVAL("rdhwr");
7764 generate_exception(ctx, EXCP_RI);
7767 gen_store_gpr(t0, rt);
7772 check_insn(env, ctx, ASE_MT);
7774 TCGv t0 = tcg_temp_local_new();
7775 TCGv t1 = tcg_temp_local_new();
7777 gen_load_gpr(t0, rt);
7778 gen_load_gpr(t1, rs);
7779 gen_helper_fork(t0, t1);
7785 check_insn(env, ctx, ASE_MT);
7787 TCGv t0 = tcg_temp_local_new();
7789 gen_load_gpr(t0, rs);
7790 gen_helper_yield(t0, t0);
7791 gen_store_gpr(t0, rd);
7795 #if defined(TARGET_MIPS64)
7796 case OPC_DEXTM ... OPC_DEXT:
7797 case OPC_DINSM ... OPC_DINS:
7798 check_insn(env, ctx, ISA_MIPS64R2);
7800 gen_bitops(ctx, op1, rt, rs, sa, rd);
7803 check_insn(env, ctx, ISA_MIPS64R2);
7805 op2 = MASK_DBSHFL(ctx->opcode);
7806 gen_bshfl(ctx, op2, rt, rd);
7809 default: /* Invalid */
7810 MIPS_INVAL("special3");
7811 generate_exception(ctx, EXCP_RI);
7816 op1 = MASK_REGIMM(ctx->opcode);
7818 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7819 case OPC_BLTZAL ... OPC_BGEZALL:
7820 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7822 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7824 gen_trap(ctx, op1, rs, -1, imm);
7827 check_insn(env, ctx, ISA_MIPS32R2);
7830 default: /* Invalid */
7831 MIPS_INVAL("regimm");
7832 generate_exception(ctx, EXCP_RI);
7837 check_cp0_enabled(ctx);
7838 op1 = MASK_CP0(ctx->opcode);
7844 #if defined(TARGET_MIPS64)
7848 #ifndef CONFIG_USER_ONLY
7849 gen_cp0(env, ctx, op1, rt, rd);
7850 #endif /* !CONFIG_USER_ONLY */
7852 case OPC_C0_FIRST ... OPC_C0_LAST:
7853 #ifndef CONFIG_USER_ONLY
7854 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7855 #endif /* !CONFIG_USER_ONLY */
7858 #ifndef CONFIG_USER_ONLY
7860 TCGv t0 = tcg_temp_local_new();
7862 op2 = MASK_MFMC0(ctx->opcode);
7865 check_insn(env, ctx, ASE_MT);
7866 gen_helper_dmt(t0, t0);
7869 check_insn(env, ctx, ASE_MT);
7870 gen_helper_emt(t0, t0);
7873 check_insn(env, ctx, ASE_MT);
7874 gen_helper_dvpe(t0, t0);
7877 check_insn(env, ctx, ASE_MT);
7878 gen_helper_evpe(t0, t0);
7881 check_insn(env, ctx, ISA_MIPS32R2);
7882 save_cpu_state(ctx, 1);
7884 /* Stop translation as we may have switched the execution mode */
7885 ctx->bstate = BS_STOP;
7888 check_insn(env, ctx, ISA_MIPS32R2);
7889 save_cpu_state(ctx, 1);
7891 /* Stop translation as we may have switched the execution mode */
7892 ctx->bstate = BS_STOP;
7894 default: /* Invalid */
7895 MIPS_INVAL("mfmc0");
7896 generate_exception(ctx, EXCP_RI);
7899 gen_store_gpr(t0, rt);
7902 #endif /* !CONFIG_USER_ONLY */
7905 check_insn(env, ctx, ISA_MIPS32R2);
7906 gen_load_srsgpr(rt, rd);
7909 check_insn(env, ctx, ISA_MIPS32R2);
7910 gen_store_srsgpr(rt, rd);
7914 generate_exception(ctx, EXCP_RI);
7918 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7919 gen_arith_imm(env, ctx, op, rt, rs, imm);
7921 case OPC_J ... OPC_JAL: /* Jump */
7922 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7923 gen_compute_branch(ctx, op, rs, rt, offset);
7925 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7926 case OPC_BEQL ... OPC_BGTZL:
7927 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7929 case OPC_LB ... OPC_LWR: /* Load and stores */
7930 case OPC_SB ... OPC_SW:
7934 gen_ldst(ctx, op, rt, rs, imm);
7937 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7941 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7945 /* Floating point (COP1). */
7950 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7951 save_cpu_state(ctx, 1);
7952 check_cp1_enabled(ctx);
7953 gen_flt_ldst(ctx, op, rt, rs, imm);
7955 generate_exception_err(ctx, EXCP_CpU, 1);
7960 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7961 save_cpu_state(ctx, 1);
7962 check_cp1_enabled(ctx);
7963 op1 = MASK_CP1(ctx->opcode);
7967 check_insn(env, ctx, ISA_MIPS32R2);
7972 gen_cp1(ctx, op1, rt, rd);
7974 #if defined(TARGET_MIPS64)
7977 check_insn(env, ctx, ISA_MIPS3);
7978 gen_cp1(ctx, op1, rt, rd);
7984 check_insn(env, ctx, ASE_MIPS3D);
7987 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
7988 (rt >> 2) & 0x7, imm << 2);
7995 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8000 generate_exception (ctx, EXCP_RI);
8004 generate_exception_err(ctx, EXCP_CpU, 1);
8014 /* COP2: Not implemented. */
8015 generate_exception_err(ctx, EXCP_CpU, 2);
8019 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8020 save_cpu_state(ctx, 1);
8021 check_cp1_enabled(ctx);
8022 op1 = MASK_CP3(ctx->opcode);
8030 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8048 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8052 generate_exception (ctx, EXCP_RI);
8056 generate_exception_err(ctx, EXCP_CpU, 1);
8060 #if defined(TARGET_MIPS64)
8061 /* MIPS64 opcodes */
8063 case OPC_LDL ... OPC_LDR:
8064 case OPC_SDL ... OPC_SDR:
8069 check_insn(env, ctx, ISA_MIPS3);
8071 gen_ldst(ctx, op, rt, rs, imm);
8073 case OPC_DADDI ... OPC_DADDIU:
8074 check_insn(env, ctx, ISA_MIPS3);
8076 gen_arith_imm(env, ctx, op, rt, rs, imm);
8080 check_insn(env, ctx, ASE_MIPS16);
8081 /* MIPS16: Not implemented. */
8083 check_insn(env, ctx, ASE_MDMX);
8084 /* MDMX: Not implemented. */
8085 default: /* Invalid */
8086 MIPS_INVAL("major opcode");
8087 generate_exception(ctx, EXCP_RI);
8090 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8091 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8092 /* Branches completion */
8093 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8094 ctx->bstate = BS_BRANCH;
8095 save_cpu_state(ctx, 0);
8096 /* FIXME: Need to clear can_do_io. */
8099 /* unconditional branch */
8100 MIPS_DEBUG("unconditional branch");
8101 gen_goto_tb(ctx, 0, ctx->btarget);
8104 /* blikely taken case */
8105 MIPS_DEBUG("blikely branch taken");
8106 gen_goto_tb(ctx, 0, ctx->btarget);
8109 /* Conditional branch */
8110 MIPS_DEBUG("conditional branch");
8112 int l1 = gen_new_label();
8114 tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
8115 gen_goto_tb(ctx, 1, ctx->pc + 4);
8117 gen_goto_tb(ctx, 0, ctx->btarget);
8121 /* unconditional branch to register */
8122 MIPS_DEBUG("branch to register");
8123 tcg_gen_mov_tl(cpu_PC, btarget);
8127 MIPS_DEBUG("unknown branch");
8134 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8138 target_ulong pc_start;
8139 uint16_t *gen_opc_end;
8146 qemu_log("search pc %d\n", search_pc);
8149 /* Leave some spare opc slots for branch handling. */
8150 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8154 ctx.bstate = BS_NONE;
8155 /* Restore delay slot state from the tb context. */
8156 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8157 restore_cpu_state(env, &ctx);
8158 #ifdef CONFIG_USER_ONLY
8159 ctx.mem_idx = MIPS_HFLAG_UM;
8161 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8164 max_insns = tb->cflags & CF_COUNT_MASK;
8166 max_insns = CF_COUNT_MASK;
8168 qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n");
8169 /* FIXME: This may print out stale hflags from env... */
8170 log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
8172 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags);
8174 while (ctx.bstate == BS_NONE) {
8175 if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
8176 TAILQ_FOREACH(bp, &env->breakpoints, entry) {
8177 if (bp->pc == ctx.pc) {
8178 save_cpu_state(&ctx, 1);
8179 ctx.bstate = BS_BRANCH;
8180 gen_helper_0i(raise_exception, EXCP_DEBUG);
8181 /* Include the breakpoint location or the tb won't
8182 * be flushed when it must be. */
8184 goto done_generating;
8190 j = gen_opc_ptr - gen_opc_buf;
8194 gen_opc_instr_start[lj++] = 0;
8196 gen_opc_pc[lj] = ctx.pc;
8197 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8198 gen_opc_instr_start[lj] = 1;
8199 gen_opc_icount[lj] = num_insns;
8201 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8203 ctx.opcode = ldl_code(ctx.pc);
8204 decode_opc(env, &ctx);
8208 if (env->singlestep_enabled)
8211 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8214 if (gen_opc_ptr >= gen_opc_end)
8217 if (num_insns >= max_insns)
8219 #if defined (MIPS_SINGLE_STEP)
8223 if (tb->cflags & CF_LAST_IO)
8225 if (env->singlestep_enabled) {
8226 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8227 gen_helper_0i(raise_exception, EXCP_DEBUG);
8229 switch (ctx.bstate) {
8231 gen_helper_interrupt_restart();
8232 gen_goto_tb(&ctx, 0, ctx.pc);
8235 save_cpu_state(&ctx, 0);
8236 gen_goto_tb(&ctx, 0, ctx.pc);
8239 gen_helper_interrupt_restart();
8248 gen_icount_end(tb, num_insns);
8249 *gen_opc_ptr = INDEX_op_end;
8251 j = gen_opc_ptr - gen_opc_buf;
8254 gen_opc_instr_start[lj++] = 0;
8256 tb->size = ctx.pc - pc_start;
8257 tb->icount = num_insns;
8261 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
8262 qemu_log("IN: %s\n", lookup_symbol(pc_start));
8263 log_target_disas(pc_start, ctx.pc - pc_start, 0);
8266 qemu_log_mask(CPU_LOG_TB_CPU, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8270 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8272 gen_intermediate_code_internal(env, tb, 0);
8275 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8277 gen_intermediate_code_internal(env, tb, 1);
8280 static void fpu_dump_state(CPUState *env, FILE *f,
8281 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8285 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8287 #define printfpr(fp) \
8290 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8291 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8292 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8295 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8296 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8297 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8298 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8299 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8304 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8305 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8306 get_float_exception_flags(&env->active_fpu.fp_status));
8307 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8308 fpu_fprintf(f, "%3s: ", fregnames[i]);
8309 printfpr(&env->active_fpu.fpr[i]);
8315 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8316 /* Debug help: The architecture requires 32bit code to maintain proper
8317 sign-extended values on 64bit machines. */
8319 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8322 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8323 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8328 if (!SIGN_EXT_P(env->active_tc.PC))
8329 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8330 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8331 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8332 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8333 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8334 if (!SIGN_EXT_P(env->btarget))
8335 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8337 for (i = 0; i < 32; i++) {
8338 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8339 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8342 if (!SIGN_EXT_P(env->CP0_EPC))
8343 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8344 if (!SIGN_EXT_P(env->CP0_LLAddr))
8345 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8349 void cpu_dump_state (CPUState *env, FILE *f,
8350 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8355 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",
8356 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8357 env->hflags, env->btarget, env->bcond);
8358 for (i = 0; i < 32; i++) {
8360 cpu_fprintf(f, "GPR%02d:", i);
8361 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8363 cpu_fprintf(f, "\n");
8366 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8367 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8368 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8369 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8370 if (env->hflags & MIPS_HFLAG_FPU)
8371 fpu_dump_state(env, f, cpu_fprintf, flags);
8372 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8373 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8377 static void mips_tcg_init(void)
8382 /* Initialize various static tables. */
8386 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
8387 for (i = 0; i < 32; i++)
8388 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
8389 offsetof(CPUState, active_tc.gpr[i]),
8391 cpu_PC = tcg_global_mem_new(TCG_AREG0,
8392 offsetof(CPUState, active_tc.PC), "PC");
8393 for (i = 0; i < MIPS_DSP_ACC; i++) {
8394 cpu_HI[i] = tcg_global_mem_new(TCG_AREG0,
8395 offsetof(CPUState, active_tc.HI[i]),
8397 cpu_LO[i] = tcg_global_mem_new(TCG_AREG0,
8398 offsetof(CPUState, active_tc.LO[i]),
8400 cpu_ACX[i] = tcg_global_mem_new(TCG_AREG0,
8401 offsetof(CPUState, active_tc.ACX[i]),
8404 cpu_dspctrl = tcg_global_mem_new(TCG_AREG0,
8405 offsetof(CPUState, active_tc.DSPControl),
8407 bcond = tcg_global_mem_new(TCG_AREG0,
8408 offsetof(CPUState, bcond), "bcond");
8409 btarget = tcg_global_mem_new(TCG_AREG0,
8410 offsetof(CPUState, btarget), "btarget");
8411 hflags = tcg_global_mem_new_i32(TCG_AREG0,
8412 offsetof(CPUState, hflags), "hflags");
8414 fpu_fcr0 = tcg_global_mem_new_i32(TCG_AREG0,
8415 offsetof(CPUState, active_fpu.fcr0),
8417 fpu_fcr31 = tcg_global_mem_new_i32(TCG_AREG0,
8418 offsetof(CPUState, active_fpu.fcr31),
8421 /* register helpers */
8422 #define GEN_HELPER 2
8428 #include "translate_init.c"
8430 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8433 const mips_def_t *def;
8435 def = cpu_mips_find_by_name(cpu_model);
8438 env = qemu_mallocz(sizeof(CPUMIPSState));
8439 env->cpu_model = def;
8442 env->cpu_model_str = cpu_model;
8448 void cpu_reset (CPUMIPSState *env)
8450 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
8451 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
8452 log_cpu_state(env, 0);
8455 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8460 #if defined(CONFIG_USER_ONLY)
8461 env->hflags = MIPS_HFLAG_UM;
8463 if (env->hflags & MIPS_HFLAG_BMASK) {
8464 /* If the exception was raised from a delay slot,
8465 come back to the jump. */
8466 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8468 env->CP0_ErrorEPC = env->active_tc.PC;
8470 env->active_tc.PC = (int32_t)0xBFC00000;
8472 /* SMP not implemented */
8473 env->CP0_EBase = 0x80000000;
8474 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8475 /* vectored interrupts not implemented, timer on int 7,
8476 no performance counters. */
8477 env->CP0_IntCtl = 0xe0000000;
8481 for (i = 0; i < 7; i++) {
8482 env->CP0_WatchLo[i] = 0;
8483 env->CP0_WatchHi[i] = 0x80000000;
8485 env->CP0_WatchLo[7] = 0;
8486 env->CP0_WatchHi[7] = 0;
8488 /* Count register increments in debug mode, EJTAG version 1 */
8489 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8490 env->hflags = MIPS_HFLAG_CP0;
8492 env->exception_index = EXCP_NONE;
8493 cpu_mips_register(env, env->cpu_model);
8496 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8497 unsigned long searched_pc, int pc_pos, void *puc)
8499 env->active_tc.PC = gen_opc_pc[pc_pos];
8500 env->hflags &= ~MIPS_HFLAG_BMASK;
8501 env->hflags |= gen_opc_hflags[pc_pos];