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 int get_fp_bit (int cc)
654 #define FOP_CONDS(type, fmt, bits) \
655 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
656 TCGv_i##bits b, int cc) \
659 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
660 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
661 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
662 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
663 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
664 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
665 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
666 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
667 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
668 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
669 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
670 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
671 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
672 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
673 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
674 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
680 FOP_CONDS(abs, d, 64)
682 FOP_CONDS(abs, s, 32)
684 FOP_CONDS(abs, ps, 64)
688 #define OP_COND(name, cond) \
689 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
691 int l1 = gen_new_label(); \
692 int l2 = gen_new_label(); \
694 tcg_gen_brcond_tl(cond, t0, t1, l1); \
695 tcg_gen_movi_tl(ret, 0); \
698 tcg_gen_movi_tl(ret, 1); \
701 OP_COND(eq, TCG_COND_EQ);
702 OP_COND(ne, TCG_COND_NE);
703 OP_COND(ge, TCG_COND_GE);
704 OP_COND(geu, TCG_COND_GEU);
705 OP_COND(lt, TCG_COND_LT);
706 OP_COND(ltu, TCG_COND_LTU);
709 #define OP_CONDI(name, cond) \
710 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
712 int l1 = gen_new_label(); \
713 int l2 = gen_new_label(); \
715 tcg_gen_brcondi_tl(cond, t0, val, l1); \
716 tcg_gen_movi_tl(ret, 0); \
719 tcg_gen_movi_tl(ret, 1); \
722 OP_CONDI(lti, TCG_COND_LT);
723 OP_CONDI(ltiu, TCG_COND_LTU);
726 #define OP_CONDZ(name, cond) \
727 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
729 int l1 = gen_new_label(); \
730 int l2 = gen_new_label(); \
732 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
733 tcg_gen_movi_tl(ret, 0); \
736 tcg_gen_movi_tl(ret, 1); \
739 OP_CONDZ(gez, TCG_COND_GE);
740 OP_CONDZ(gtz, TCG_COND_GT);
741 OP_CONDZ(lez, TCG_COND_LE);
742 OP_CONDZ(ltz, TCG_COND_LT);
745 static inline void gen_save_pc(target_ulong pc)
747 tcg_gen_movi_tl(cpu_PC, pc);
750 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
752 LOG_DISAS("hflags %08x saved %08x\n", ctx->hflags, ctx->saved_hflags);
753 if (do_save_pc && ctx->pc != ctx->saved_pc) {
754 gen_save_pc(ctx->pc);
755 ctx->saved_pc = ctx->pc;
757 if (ctx->hflags != ctx->saved_hflags) {
758 tcg_gen_movi_i32(hflags, ctx->hflags);
759 ctx->saved_hflags = ctx->hflags;
760 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
766 tcg_gen_movi_tl(btarget, ctx->btarget);
772 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
774 ctx->saved_hflags = ctx->hflags;
775 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
781 ctx->btarget = env->btarget;
787 generate_exception_err (DisasContext *ctx, int excp, int err)
789 TCGv_i32 texcp = tcg_const_i32(excp);
790 TCGv_i32 terr = tcg_const_i32(err);
791 save_cpu_state(ctx, 1);
792 gen_helper_raise_exception_err(texcp, terr);
793 tcg_temp_free_i32(terr);
794 tcg_temp_free_i32(texcp);
795 gen_helper_interrupt_restart();
800 generate_exception (DisasContext *ctx, int excp)
802 save_cpu_state(ctx, 1);
803 gen_helper_0i(raise_exception, excp);
804 gen_helper_interrupt_restart();
808 /* Addresses computation */
809 static inline void gen_op_addr_add (DisasContext *ctx, TCGv t0, TCGv t1)
811 tcg_gen_add_tl(t0, t0, t1);
813 #if defined(TARGET_MIPS64)
814 /* For compatibility with 32-bit code, data reference in user mode
815 with Status_UX = 0 should be casted to 32-bit and sign extended.
816 See the MIPS64 PRA manual, section 4.10. */
817 if (((ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
818 !(ctx->hflags & MIPS_HFLAG_UX)) {
819 tcg_gen_ext32s_i64(t0, t0);
824 static inline void check_cp0_enabled(DisasContext *ctx)
826 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
827 generate_exception_err(ctx, EXCP_CpU, 1);
830 static inline void check_cp1_enabled(DisasContext *ctx)
832 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
833 generate_exception_err(ctx, EXCP_CpU, 1);
836 /* Verify that the processor is running with COP1X instructions enabled.
837 This is associated with the nabla symbol in the MIPS32 and MIPS64
840 static inline void check_cop1x(DisasContext *ctx)
842 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
843 generate_exception(ctx, EXCP_RI);
846 /* Verify that the processor is running with 64-bit floating-point
847 operations enabled. */
849 static inline void check_cp1_64bitmode(DisasContext *ctx)
851 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
852 generate_exception(ctx, EXCP_RI);
856 * Verify if floating point register is valid; an operation is not defined
857 * if bit 0 of any register specification is set and the FR bit in the
858 * Status register equals zero, since the register numbers specify an
859 * even-odd pair of adjacent coprocessor general registers. When the FR bit
860 * in the Status register equals one, both even and odd register numbers
861 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
863 * Multiple 64 bit wide registers can be checked by calling
864 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
866 static inline void check_cp1_registers(DisasContext *ctx, int regs)
868 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
869 generate_exception(ctx, EXCP_RI);
872 /* This code generates a "reserved instruction" exception if the
873 CPU does not support the instruction set corresponding to flags. */
874 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
876 if (unlikely(!(env->insn_flags & flags)))
877 generate_exception(ctx, EXCP_RI);
880 /* This code generates a "reserved instruction" exception if 64-bit
881 instructions are not enabled. */
882 static inline void check_mips_64(DisasContext *ctx)
884 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
885 generate_exception(ctx, EXCP_RI);
888 /* load/store instructions. */
889 #define OP_LD(insn,fname) \
890 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
892 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
899 #if defined(TARGET_MIPS64)
905 #define OP_ST(insn,fname) \
906 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
908 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
913 #if defined(TARGET_MIPS64)
918 #define OP_LD_ATOMIC(insn,fname) \
919 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
921 tcg_gen_mov_tl(t1, t0); \
922 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
923 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
925 OP_LD_ATOMIC(ll,ld32s);
926 #if defined(TARGET_MIPS64)
927 OP_LD_ATOMIC(lld,ld64);
931 #define OP_ST_ATOMIC(insn,fname,almask) \
932 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
934 TCGv r_tmp = tcg_temp_local_new(); \
935 int l1 = gen_new_label(); \
936 int l2 = gen_new_label(); \
937 int l3 = gen_new_label(); \
939 tcg_gen_andi_tl(r_tmp, t0, almask); \
940 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
941 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
942 generate_exception(ctx, EXCP_AdES); \
944 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
945 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
946 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
947 tcg_gen_movi_tl(t0, 1); \
950 tcg_gen_movi_tl(t0, 0); \
952 tcg_temp_free(r_tmp); \
954 OP_ST_ATOMIC(sc,st32,0x3);
955 #if defined(TARGET_MIPS64)
956 OP_ST_ATOMIC(scd,st64,0x7);
961 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
962 int base, int16_t offset)
964 const char *opn = "ldst";
965 TCGv t0 = tcg_temp_local_new();
966 TCGv t1 = tcg_temp_local_new();
969 tcg_gen_movi_tl(t0, offset);
970 } else if (offset == 0) {
971 gen_load_gpr(t0, base);
973 tcg_gen_movi_tl(t0, offset);
974 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
976 /* Don't do NOP if destination is zero: we must perform the actual
979 #if defined(TARGET_MIPS64)
981 op_ldst_lwu(t0, ctx);
982 gen_store_gpr(t0, rt);
987 gen_store_gpr(t0, rt);
991 op_ldst_lld(t0, t1, ctx);
992 gen_store_gpr(t0, rt);
996 gen_load_gpr(t1, rt);
997 op_ldst_sd(t0, t1, ctx);
1001 save_cpu_state(ctx, 1);
1002 gen_load_gpr(t1, rt);
1003 op_ldst_scd(t0, t1, ctx);
1004 gen_store_gpr(t0, rt);
1008 save_cpu_state(ctx, 1);
1009 gen_load_gpr(t1, rt);
1010 gen_helper_3i(ldl, t1, t0, t1, ctx->mem_idx);
1011 gen_store_gpr(t1, rt);
1015 save_cpu_state(ctx, 1);
1016 gen_load_gpr(t1, rt);
1017 gen_helper_2i(sdl, t0, t1, ctx->mem_idx);
1021 save_cpu_state(ctx, 1);
1022 gen_load_gpr(t1, rt);
1023 gen_helper_3i(ldr, t1, t0, t1, ctx->mem_idx);
1024 gen_store_gpr(t1, rt);
1028 save_cpu_state(ctx, 1);
1029 gen_load_gpr(t1, rt);
1030 gen_helper_2i(sdr, t0, t1, ctx->mem_idx);
1035 op_ldst_lw(t0, ctx);
1036 gen_store_gpr(t0, rt);
1040 gen_load_gpr(t1, rt);
1041 op_ldst_sw(t0, t1, ctx);
1045 op_ldst_lh(t0, ctx);
1046 gen_store_gpr(t0, rt);
1050 gen_load_gpr(t1, rt);
1051 op_ldst_sh(t0, t1, ctx);
1055 op_ldst_lhu(t0, ctx);
1056 gen_store_gpr(t0, rt);
1060 op_ldst_lb(t0, ctx);
1061 gen_store_gpr(t0, rt);
1065 gen_load_gpr(t1, rt);
1066 op_ldst_sb(t0, t1, ctx);
1070 op_ldst_lbu(t0, ctx);
1071 gen_store_gpr(t0, rt);
1075 save_cpu_state(ctx, 1);
1076 gen_load_gpr(t1, rt);
1077 gen_helper_3i(lwl, t1, t0, t1, ctx->mem_idx);
1078 gen_store_gpr(t1, rt);
1082 save_cpu_state(ctx, 1);
1083 gen_load_gpr(t1, rt);
1084 gen_helper_2i(swl, t0, t1, ctx->mem_idx);
1088 save_cpu_state(ctx, 1);
1089 gen_load_gpr(t1, rt);
1090 gen_helper_3i(lwr, t1, t0, t1, ctx->mem_idx);
1091 gen_store_gpr(t1, rt);
1095 save_cpu_state(ctx, 1);
1096 gen_load_gpr(t1, rt);
1097 gen_helper_2i(swr, t0, t1, ctx->mem_idx);
1101 op_ldst_ll(t0, t1, ctx);
1102 gen_store_gpr(t0, rt);
1106 save_cpu_state(ctx, 1);
1107 gen_load_gpr(t1, rt);
1108 op_ldst_sc(t0, t1, ctx);
1109 gen_store_gpr(t0, rt);
1114 generate_exception(ctx, EXCP_RI);
1117 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1123 /* Load and store */
1124 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1125 int base, int16_t offset)
1127 const char *opn = "flt_ldst";
1128 TCGv t0 = tcg_temp_local_new();
1131 tcg_gen_movi_tl(t0, offset);
1132 } else if (offset == 0) {
1133 gen_load_gpr(t0, base);
1135 tcg_gen_movi_tl(t0, offset);
1136 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
1138 /* Don't do NOP if destination is zero: we must perform the actual
1143 TCGv_i32 fp0 = tcg_temp_new_i32();
1144 TCGv t1 = tcg_temp_new();
1146 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
1147 tcg_gen_trunc_tl_i32(fp0, t1);
1148 gen_store_fpr32(fp0, ft);
1150 tcg_temp_free_i32(fp0);
1156 TCGv_i32 fp0 = tcg_temp_new_i32();
1157 TCGv t1 = tcg_temp_new();
1159 gen_load_fpr32(fp0, ft);
1160 tcg_gen_extu_i32_tl(t1, fp0);
1161 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
1163 tcg_temp_free_i32(fp0);
1169 TCGv_i64 fp0 = tcg_temp_new_i64();
1171 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1172 gen_store_fpr64(ctx, fp0, ft);
1173 tcg_temp_free_i64(fp0);
1179 TCGv_i64 fp0 = tcg_temp_new_i64();
1181 gen_load_fpr64(ctx, fp0, ft);
1182 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1183 tcg_temp_free_i64(fp0);
1189 generate_exception(ctx, EXCP_RI);
1192 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1197 /* Arithmetic with immediate operand */
1198 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1199 int rt, int rs, int16_t imm)
1202 const char *opn = "imm arith";
1203 TCGv t0 = tcg_temp_local_new();
1205 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1206 /* If no destination, treat it as a NOP.
1207 For addi, we must generate the overflow exception when needed. */
1211 uimm = (uint16_t)imm;
1215 #if defined(TARGET_MIPS64)
1221 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1226 gen_load_gpr(t0, rs);
1229 tcg_gen_movi_tl(t0, imm << 16);
1234 #if defined(TARGET_MIPS64)
1243 gen_load_gpr(t0, rs);
1249 TCGv r_tmp1 = tcg_temp_new();
1250 TCGv r_tmp2 = tcg_temp_new();
1251 int l1 = gen_new_label();
1253 save_cpu_state(ctx, 1);
1254 tcg_gen_ext32s_tl(r_tmp1, t0);
1255 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1257 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1258 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1259 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1260 tcg_temp_free(r_tmp2);
1261 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1262 /* operands of same sign, result different sign */
1263 generate_exception(ctx, EXCP_OVERFLOW);
1265 tcg_temp_free(r_tmp1);
1267 tcg_gen_ext32s_tl(t0, t0);
1272 tcg_gen_addi_tl(t0, t0, uimm);
1273 tcg_gen_ext32s_tl(t0, t0);
1276 #if defined(TARGET_MIPS64)
1279 TCGv r_tmp1 = tcg_temp_new();
1280 TCGv r_tmp2 = tcg_temp_new();
1281 int l1 = gen_new_label();
1283 save_cpu_state(ctx, 1);
1284 tcg_gen_mov_tl(r_tmp1, t0);
1285 tcg_gen_addi_tl(t0, t0, uimm);
1287 tcg_gen_xori_tl(r_tmp1, r_tmp1, ~uimm);
1288 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1289 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1290 tcg_temp_free(r_tmp2);
1291 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1292 /* operands of same sign, result different sign */
1293 generate_exception(ctx, EXCP_OVERFLOW);
1295 tcg_temp_free(r_tmp1);
1300 tcg_gen_addi_tl(t0, t0, uimm);
1305 gen_op_lti(t0, t0, uimm);
1309 gen_op_ltiu(t0, t0, uimm);
1313 tcg_gen_andi_tl(t0, t0, uimm);
1317 tcg_gen_ori_tl(t0, t0, uimm);
1321 tcg_gen_xori_tl(t0, t0, uimm);
1328 tcg_gen_shli_tl(t0, t0, uimm);
1329 tcg_gen_ext32s_tl(t0, t0);
1333 tcg_gen_ext32s_tl(t0, t0);
1334 tcg_gen_sari_tl(t0, t0, uimm);
1338 switch ((ctx->opcode >> 21) & 0x1f) {
1341 tcg_gen_ext32u_tl(t0, t0);
1342 tcg_gen_shri_tl(t0, t0, uimm);
1344 tcg_gen_ext32s_tl(t0, t0);
1349 /* rotr is decoded as srl on non-R2 CPUs */
1350 if (env->insn_flags & ISA_MIPS32R2) {
1352 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1354 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1355 tcg_gen_rotri_i32(r_tmp1, r_tmp1, uimm);
1356 tcg_gen_ext_i32_tl(t0, r_tmp1);
1357 tcg_temp_free_i32(r_tmp1);
1362 tcg_gen_ext32u_tl(t0, t0);
1363 tcg_gen_shri_tl(t0, t0, uimm);
1365 tcg_gen_ext32s_tl(t0, t0);
1371 MIPS_INVAL("invalid srl flag");
1372 generate_exception(ctx, EXCP_RI);
1376 #if defined(TARGET_MIPS64)
1378 tcg_gen_shli_tl(t0, t0, uimm);
1382 tcg_gen_sari_tl(t0, t0, uimm);
1386 switch ((ctx->opcode >> 21) & 0x1f) {
1388 tcg_gen_shri_tl(t0, t0, uimm);
1392 /* drotr is decoded as dsrl on non-R2 CPUs */
1393 if (env->insn_flags & ISA_MIPS32R2) {
1395 tcg_gen_rotri_tl(t0, t0, uimm);
1399 tcg_gen_shri_tl(t0, t0, uimm);
1404 MIPS_INVAL("invalid dsrl flag");
1405 generate_exception(ctx, EXCP_RI);
1410 tcg_gen_shli_tl(t0, t0, uimm + 32);
1414 tcg_gen_sari_tl(t0, t0, uimm + 32);
1418 switch ((ctx->opcode >> 21) & 0x1f) {
1420 tcg_gen_shri_tl(t0, t0, uimm + 32);
1424 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1425 if (env->insn_flags & ISA_MIPS32R2) {
1426 tcg_gen_rotri_tl(t0, t0, uimm + 32);
1429 tcg_gen_shri_tl(t0, t0, uimm + 32);
1434 MIPS_INVAL("invalid dsrl32 flag");
1435 generate_exception(ctx, EXCP_RI);
1442 generate_exception(ctx, EXCP_RI);
1445 gen_store_gpr(t0, rt);
1446 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1452 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1453 int rd, int rs, int rt)
1455 const char *opn = "arith";
1456 TCGv t0 = tcg_temp_local_new();
1457 TCGv t1 = tcg_temp_local_new();
1459 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1460 && opc != OPC_DADD && opc != OPC_DSUB) {
1461 /* If no destination, treat it as a NOP.
1462 For add & sub, we must generate the overflow exception when needed. */
1466 gen_load_gpr(t0, rs);
1467 /* Specialcase the conventional move operation. */
1468 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1469 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1470 gen_store_gpr(t0, rd);
1473 gen_load_gpr(t1, rt);
1477 TCGv r_tmp1 = tcg_temp_new();
1478 TCGv r_tmp2 = tcg_temp_new();
1479 int l1 = gen_new_label();
1481 save_cpu_state(ctx, 1);
1482 tcg_gen_ext32s_tl(r_tmp1, t0);
1483 tcg_gen_ext32s_tl(r_tmp2, t1);
1484 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1486 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1487 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1488 tcg_gen_xor_tl(r_tmp2, t0, t1);
1489 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1490 tcg_temp_free(r_tmp2);
1491 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1492 /* operands of same sign, result different sign */
1493 generate_exception(ctx, EXCP_OVERFLOW);
1495 tcg_temp_free(r_tmp1);
1497 tcg_gen_ext32s_tl(t0, t0);
1502 tcg_gen_add_tl(t0, t0, t1);
1503 tcg_gen_ext32s_tl(t0, t0);
1508 TCGv r_tmp1 = tcg_temp_new();
1509 TCGv r_tmp2 = tcg_temp_new();
1510 int l1 = gen_new_label();
1512 save_cpu_state(ctx, 1);
1513 tcg_gen_ext32s_tl(r_tmp1, t0);
1514 tcg_gen_ext32s_tl(r_tmp2, t1);
1515 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1517 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1518 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1519 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1520 tcg_temp_free(r_tmp2);
1521 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1522 /* operands of different sign, first operand and result different sign */
1523 generate_exception(ctx, EXCP_OVERFLOW);
1525 tcg_temp_free(r_tmp1);
1527 tcg_gen_ext32s_tl(t0, t0);
1532 tcg_gen_sub_tl(t0, t0, t1);
1533 tcg_gen_ext32s_tl(t0, t0);
1536 #if defined(TARGET_MIPS64)
1539 TCGv r_tmp1 = tcg_temp_new();
1540 TCGv r_tmp2 = tcg_temp_new();
1541 int l1 = gen_new_label();
1543 save_cpu_state(ctx, 1);
1544 tcg_gen_mov_tl(r_tmp1, t0);
1545 tcg_gen_add_tl(t0, t0, t1);
1547 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1548 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1549 tcg_gen_xor_tl(r_tmp2, t0, t1);
1550 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1551 tcg_temp_free(r_tmp2);
1552 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1553 /* operands of same sign, result different sign */
1554 generate_exception(ctx, EXCP_OVERFLOW);
1556 tcg_temp_free(r_tmp1);
1561 tcg_gen_add_tl(t0, t0, t1);
1566 TCGv r_tmp1 = tcg_temp_new();
1567 TCGv r_tmp2 = tcg_temp_new();
1568 int l1 = gen_new_label();
1570 save_cpu_state(ctx, 1);
1571 tcg_gen_mov_tl(r_tmp1, t0);
1572 tcg_gen_sub_tl(t0, t0, t1);
1574 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1575 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1576 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1577 tcg_temp_free(r_tmp2);
1578 tcg_gen_brcondi_tl(TCG_COND_GE, r_tmp1, 0, l1);
1579 /* operands of different sign, first operand and result different sign */
1580 generate_exception(ctx, EXCP_OVERFLOW);
1582 tcg_temp_free(r_tmp1);
1587 tcg_gen_sub_tl(t0, t0, t1);
1592 gen_op_lt(t0, t0, t1);
1596 gen_op_ltu(t0, t0, t1);
1600 tcg_gen_and_tl(t0, t0, t1);
1604 tcg_gen_nor_tl(t0, t0, t1);
1608 tcg_gen_or_tl(t0, t0, t1);
1612 tcg_gen_xor_tl(t0, t0, t1);
1616 tcg_gen_mul_tl(t0, t0, t1);
1617 tcg_gen_ext32s_tl(t0, t0);
1622 int l1 = gen_new_label();
1624 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1625 gen_store_gpr(t0, rd);
1632 int l1 = gen_new_label();
1634 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1635 gen_store_gpr(t0, rd);
1641 tcg_gen_andi_tl(t0, t0, 0x1f);
1642 tcg_gen_shl_tl(t0, t1, t0);
1643 tcg_gen_ext32s_tl(t0, t0);
1647 tcg_gen_ext32s_tl(t1, t1);
1648 tcg_gen_andi_tl(t0, t0, 0x1f);
1649 tcg_gen_sar_tl(t0, t1, t0);
1653 switch ((ctx->opcode >> 6) & 0x1f) {
1655 tcg_gen_ext32u_tl(t1, t1);
1656 tcg_gen_andi_tl(t0, t0, 0x1f);
1657 tcg_gen_shr_tl(t0, t1, t0);
1658 tcg_gen_ext32s_tl(t0, t0);
1662 /* rotrv is decoded as srlv on non-R2 CPUs */
1663 if (env->insn_flags & ISA_MIPS32R2) {
1664 int l1 = gen_new_label();
1665 int l2 = gen_new_label();
1667 tcg_gen_andi_tl(t0, t0, 0x1f);
1668 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1670 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
1671 TCGv_i32 r_tmp2 = tcg_temp_new_i32();
1673 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1674 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1675 tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2);
1676 tcg_temp_free_i32(r_tmp1);
1677 tcg_temp_free_i32(r_tmp2);
1681 tcg_gen_mov_tl(t0, t1);
1685 tcg_gen_ext32u_tl(t1, t1);
1686 tcg_gen_andi_tl(t0, t0, 0x1f);
1687 tcg_gen_shr_tl(t0, t1, t0);
1688 tcg_gen_ext32s_tl(t0, t0);
1693 MIPS_INVAL("invalid srlv flag");
1694 generate_exception(ctx, EXCP_RI);
1698 #if defined(TARGET_MIPS64)
1700 tcg_gen_andi_tl(t0, t0, 0x3f);
1701 tcg_gen_shl_tl(t0, t1, t0);
1705 tcg_gen_andi_tl(t0, t0, 0x3f);
1706 tcg_gen_sar_tl(t0, t1, t0);
1710 switch ((ctx->opcode >> 6) & 0x1f) {
1712 tcg_gen_andi_tl(t0, t0, 0x3f);
1713 tcg_gen_shr_tl(t0, t1, t0);
1717 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1718 if (env->insn_flags & ISA_MIPS32R2) {
1719 int l1 = gen_new_label();
1720 int l2 = gen_new_label();
1722 tcg_gen_andi_tl(t0, t0, 0x3f);
1723 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1725 tcg_gen_rotr_tl(t0, t1, t0);
1729 tcg_gen_mov_tl(t0, t1);
1733 tcg_gen_andi_tl(t0, t0, 0x3f);
1734 tcg_gen_shr_tl(t0, t1, t0);
1739 MIPS_INVAL("invalid dsrlv flag");
1740 generate_exception(ctx, EXCP_RI);
1747 generate_exception(ctx, EXCP_RI);
1750 gen_store_gpr(t0, rd);
1752 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1758 /* Arithmetic on HI/LO registers */
1759 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1761 const char *opn = "hilo";
1763 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1770 tcg_gen_mov_tl(cpu_gpr[reg], cpu_HI[0]);
1774 tcg_gen_mov_tl(cpu_gpr[reg], cpu_LO[0]);
1779 tcg_gen_mov_tl(cpu_HI[0], cpu_gpr[reg]);
1781 tcg_gen_movi_tl(cpu_HI[0], 0);
1786 tcg_gen_mov_tl(cpu_LO[0], cpu_gpr[reg]);
1788 tcg_gen_movi_tl(cpu_LO[0], 0);
1792 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1795 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1798 const char *opn = "mul/div";
1804 #if defined(TARGET_MIPS64)
1808 t0 = tcg_temp_local_new();
1809 t1 = tcg_temp_local_new();
1812 t0 = tcg_temp_new();
1813 t1 = tcg_temp_new();
1817 gen_load_gpr(t0, rs);
1818 gen_load_gpr(t1, rt);
1822 int l1 = gen_new_label();
1823 int l2 = gen_new_label();
1825 tcg_gen_ext32s_tl(t0, t0);
1826 tcg_gen_ext32s_tl(t1, t1);
1827 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1828 tcg_gen_brcondi_tl(TCG_COND_NE, t0, INT_MIN, l2);
1829 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1, l2);
1831 tcg_gen_mov_tl(cpu_LO[0], t0);
1832 tcg_gen_movi_tl(cpu_HI[0], 0);
1835 tcg_gen_div_tl(cpu_LO[0], t0, t1);
1836 tcg_gen_rem_tl(cpu_HI[0], t0, t1);
1837 tcg_gen_ext32s_tl(cpu_LO[0], cpu_LO[0]);
1838 tcg_gen_ext32s_tl(cpu_HI[0], cpu_HI[0]);
1845 int l1 = gen_new_label();
1847 tcg_gen_ext32u_tl(t0, t0);
1848 tcg_gen_ext32u_tl(t1, t1);
1849 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1850 tcg_gen_divu_tl(cpu_LO[0], t0, t1);
1851 tcg_gen_remu_tl(cpu_HI[0], t0, t1);
1852 tcg_gen_ext32s_tl(cpu_LO[0], cpu_LO[0]);
1853 tcg_gen_ext32s_tl(cpu_HI[0], cpu_HI[0]);
1860 TCGv_i64 t2 = tcg_temp_new_i64();
1861 TCGv_i64 t3 = tcg_temp_new_i64();
1863 tcg_gen_ext_tl_i64(t2, t0);
1864 tcg_gen_ext_tl_i64(t3, t1);
1865 tcg_gen_mul_i64(t2, t2, t3);
1866 tcg_temp_free_i64(t3);
1867 tcg_gen_trunc_i64_tl(t0, t2);
1868 tcg_gen_shri_i64(t2, t2, 32);
1869 tcg_gen_trunc_i64_tl(t1, t2);
1870 tcg_temp_free_i64(t2);
1871 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1872 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1878 TCGv_i64 t2 = tcg_temp_new_i64();
1879 TCGv_i64 t3 = tcg_temp_new_i64();
1881 tcg_gen_ext32u_tl(t0, t0);
1882 tcg_gen_ext32u_tl(t1, t1);
1883 tcg_gen_extu_tl_i64(t2, t0);
1884 tcg_gen_extu_tl_i64(t3, t1);
1885 tcg_gen_mul_i64(t2, t2, t3);
1886 tcg_temp_free_i64(t3);
1887 tcg_gen_trunc_i64_tl(t0, t2);
1888 tcg_gen_shri_i64(t2, t2, 32);
1889 tcg_gen_trunc_i64_tl(t1, t2);
1890 tcg_temp_free_i64(t2);
1891 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1892 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1896 #if defined(TARGET_MIPS64)
1899 int l1 = gen_new_label();
1900 int l2 = gen_new_label();
1902 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1903 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
1904 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
1905 tcg_gen_mov_tl(cpu_LO[0], t0);
1906 tcg_gen_movi_tl(cpu_HI[0], 0);
1909 tcg_gen_div_i64(cpu_LO[0], t0, t1);
1910 tcg_gen_rem_i64(cpu_HI[0], t0, t1);
1917 int l1 = gen_new_label();
1919 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1920 tcg_gen_divu_i64(cpu_LO[0], t0, t1);
1921 tcg_gen_remu_i64(cpu_HI[0], t0, t1);
1927 gen_helper_dmult(t0, t1);
1931 gen_helper_dmultu(t0, t1);
1937 TCGv_i64 t2 = tcg_temp_new_i64();
1938 TCGv_i64 t3 = tcg_temp_new_i64();
1940 tcg_gen_ext_tl_i64(t2, t0);
1941 tcg_gen_ext_tl_i64(t3, t1);
1942 tcg_gen_mul_i64(t2, t2, t3);
1943 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
1944 tcg_gen_add_i64(t2, t2, t3);
1945 tcg_temp_free_i64(t3);
1946 tcg_gen_trunc_i64_tl(t0, t2);
1947 tcg_gen_shri_i64(t2, t2, 32);
1948 tcg_gen_trunc_i64_tl(t1, t2);
1949 tcg_temp_free_i64(t2);
1950 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1951 tcg_gen_ext32s_tl(cpu_LO[1], t1);
1957 TCGv_i64 t2 = tcg_temp_new_i64();
1958 TCGv_i64 t3 = tcg_temp_new_i64();
1960 tcg_gen_ext32u_tl(t0, t0);
1961 tcg_gen_ext32u_tl(t1, t1);
1962 tcg_gen_extu_tl_i64(t2, t0);
1963 tcg_gen_extu_tl_i64(t3, t1);
1964 tcg_gen_mul_i64(t2, t2, t3);
1965 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
1966 tcg_gen_add_i64(t2, t2, t3);
1967 tcg_temp_free_i64(t3);
1968 tcg_gen_trunc_i64_tl(t0, t2);
1969 tcg_gen_shri_i64(t2, t2, 32);
1970 tcg_gen_trunc_i64_tl(t1, t2);
1971 tcg_temp_free_i64(t2);
1972 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1973 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1979 TCGv_i64 t2 = tcg_temp_new_i64();
1980 TCGv_i64 t3 = tcg_temp_new_i64();
1982 tcg_gen_ext_tl_i64(t2, t0);
1983 tcg_gen_ext_tl_i64(t3, t1);
1984 tcg_gen_mul_i64(t2, t2, t3);
1985 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
1986 tcg_gen_sub_i64(t2, t2, t3);
1987 tcg_temp_free_i64(t3);
1988 tcg_gen_trunc_i64_tl(t0, t2);
1989 tcg_gen_shri_i64(t2, t2, 32);
1990 tcg_gen_trunc_i64_tl(t1, t2);
1991 tcg_temp_free_i64(t2);
1992 tcg_gen_ext32s_tl(cpu_LO[0], t0);
1993 tcg_gen_ext32s_tl(cpu_HI[0], t1);
1999 TCGv_i64 t2 = tcg_temp_new_i64();
2000 TCGv_i64 t3 = tcg_temp_new_i64();
2002 tcg_gen_ext32u_tl(t0, t0);
2003 tcg_gen_ext32u_tl(t1, t1);
2004 tcg_gen_extu_tl_i64(t2, t0);
2005 tcg_gen_extu_tl_i64(t3, t1);
2006 tcg_gen_mul_i64(t2, t2, t3);
2007 tcg_gen_concat_tl_i64(t3, cpu_LO[0], cpu_HI[0]);
2008 tcg_gen_sub_i64(t2, t2, t3);
2009 tcg_temp_free_i64(t3);
2010 tcg_gen_trunc_i64_tl(t0, t2);
2011 tcg_gen_shri_i64(t2, t2, 32);
2012 tcg_gen_trunc_i64_tl(t1, t2);
2013 tcg_temp_free_i64(t2);
2014 tcg_gen_ext32s_tl(cpu_LO[0], t0);
2015 tcg_gen_ext32s_tl(cpu_HI[0], t1);
2021 generate_exception(ctx, EXCP_RI);
2024 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2030 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2031 int rd, int rs, int rt)
2033 const char *opn = "mul vr54xx";
2034 TCGv t0 = tcg_temp_new();
2035 TCGv t1 = tcg_temp_new();
2037 gen_load_gpr(t0, rs);
2038 gen_load_gpr(t1, rt);
2041 case OPC_VR54XX_MULS:
2042 gen_helper_muls(t0, t0, t1);
2045 case OPC_VR54XX_MULSU:
2046 gen_helper_mulsu(t0, t0, t1);
2049 case OPC_VR54XX_MACC:
2050 gen_helper_macc(t0, t0, t1);
2053 case OPC_VR54XX_MACCU:
2054 gen_helper_maccu(t0, t0, t1);
2057 case OPC_VR54XX_MSAC:
2058 gen_helper_msac(t0, t0, t1);
2061 case OPC_VR54XX_MSACU:
2062 gen_helper_msacu(t0, t0, t1);
2065 case OPC_VR54XX_MULHI:
2066 gen_helper_mulhi(t0, t0, t1);
2069 case OPC_VR54XX_MULHIU:
2070 gen_helper_mulhiu(t0, t0, t1);
2073 case OPC_VR54XX_MULSHI:
2074 gen_helper_mulshi(t0, t0, t1);
2077 case OPC_VR54XX_MULSHIU:
2078 gen_helper_mulshiu(t0, t0, t1);
2081 case OPC_VR54XX_MACCHI:
2082 gen_helper_macchi(t0, t0, t1);
2085 case OPC_VR54XX_MACCHIU:
2086 gen_helper_macchiu(t0, t0, t1);
2089 case OPC_VR54XX_MSACHI:
2090 gen_helper_msachi(t0, t0, t1);
2093 case OPC_VR54XX_MSACHIU:
2094 gen_helper_msachiu(t0, t0, t1);
2098 MIPS_INVAL("mul vr54xx");
2099 generate_exception(ctx, EXCP_RI);
2102 gen_store_gpr(t0, rd);
2103 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2110 static void gen_cl (DisasContext *ctx, uint32_t opc,
2113 const char *opn = "CLx";
2121 t0 = tcg_temp_new();
2122 gen_load_gpr(t0, rs);
2125 gen_helper_clo(cpu_gpr[rd], t0);
2129 gen_helper_clz(cpu_gpr[rd], t0);
2132 #if defined(TARGET_MIPS64)
2134 gen_helper_dclo(cpu_gpr[rd], t0);
2138 gen_helper_dclz(cpu_gpr[rd], t0);
2143 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2148 static void gen_trap (DisasContext *ctx, uint32_t opc,
2149 int rs, int rt, int16_t imm)
2152 TCGv t0 = tcg_temp_new();
2153 TCGv t1 = tcg_temp_new();
2156 /* Load needed operands */
2164 /* Compare two registers */
2166 gen_load_gpr(t0, rs);
2167 gen_load_gpr(t1, rt);
2177 /* Compare register to immediate */
2178 if (rs != 0 || imm != 0) {
2179 gen_load_gpr(t0, rs);
2180 tcg_gen_movi_tl(t1, (int32_t)imm);
2187 case OPC_TEQ: /* rs == rs */
2188 case OPC_TEQI: /* r0 == 0 */
2189 case OPC_TGE: /* rs >= rs */
2190 case OPC_TGEI: /* r0 >= 0 */
2191 case OPC_TGEU: /* rs >= rs unsigned */
2192 case OPC_TGEIU: /* r0 >= 0 unsigned */
2194 generate_exception(ctx, EXCP_TRAP);
2196 case OPC_TLT: /* rs < rs */
2197 case OPC_TLTI: /* r0 < 0 */
2198 case OPC_TLTU: /* rs < rs unsigned */
2199 case OPC_TLTIU: /* r0 < 0 unsigned */
2200 case OPC_TNE: /* rs != rs */
2201 case OPC_TNEI: /* r0 != 0 */
2202 /* Never trap: treat as NOP. */
2206 int l1 = gen_new_label();
2211 tcg_gen_brcond_tl(TCG_COND_NE, t0, t1, l1);
2215 tcg_gen_brcond_tl(TCG_COND_LT, t0, t1, l1);
2219 tcg_gen_brcond_tl(TCG_COND_LTU, t0, t1, l1);
2223 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
2227 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
2231 tcg_gen_brcond_tl(TCG_COND_EQ, t0, t1, l1);
2234 generate_exception(ctx, EXCP_TRAP);
2241 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2243 TranslationBlock *tb;
2245 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2248 tcg_gen_exit_tb((long)tb + n);
2255 /* Branches (before delay slot) */
2256 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2257 int rs, int rt, int32_t offset)
2259 target_ulong btgt = -1;
2261 int bcond_compute = 0;
2262 TCGv t0 = tcg_temp_new();
2263 TCGv t1 = tcg_temp_new();
2265 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2266 #ifdef MIPS_DEBUG_DISAS
2267 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx "\n", ctx->pc);
2269 generate_exception(ctx, EXCP_RI);
2273 /* Load needed operands */
2279 /* Compare two registers */
2281 gen_load_gpr(t0, rs);
2282 gen_load_gpr(t1, rt);
2285 btgt = ctx->pc + 4 + offset;
2299 /* Compare to zero */
2301 gen_load_gpr(t0, rs);
2304 btgt = ctx->pc + 4 + offset;
2308 /* Jump to immediate */
2309 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2313 /* Jump to register */
2314 if (offset != 0 && offset != 16) {
2315 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2316 others are reserved. */
2317 MIPS_INVAL("jump hint");
2318 generate_exception(ctx, EXCP_RI);
2321 gen_load_gpr(btarget, rs);
2324 MIPS_INVAL("branch/jump");
2325 generate_exception(ctx, EXCP_RI);
2328 if (bcond_compute == 0) {
2329 /* No condition to be computed */
2331 case OPC_BEQ: /* rx == rx */
2332 case OPC_BEQL: /* rx == rx likely */
2333 case OPC_BGEZ: /* 0 >= 0 */
2334 case OPC_BGEZL: /* 0 >= 0 likely */
2335 case OPC_BLEZ: /* 0 <= 0 */
2336 case OPC_BLEZL: /* 0 <= 0 likely */
2338 ctx->hflags |= MIPS_HFLAG_B;
2339 MIPS_DEBUG("balways");
2341 case OPC_BGEZAL: /* 0 >= 0 */
2342 case OPC_BGEZALL: /* 0 >= 0 likely */
2343 /* Always take and link */
2345 ctx->hflags |= MIPS_HFLAG_B;
2346 MIPS_DEBUG("balways and link");
2348 case OPC_BNE: /* rx != rx */
2349 case OPC_BGTZ: /* 0 > 0 */
2350 case OPC_BLTZ: /* 0 < 0 */
2352 MIPS_DEBUG("bnever (NOP)");
2354 case OPC_BLTZAL: /* 0 < 0 */
2355 tcg_gen_movi_tl(cpu_gpr[31], ctx->pc + 8);
2356 MIPS_DEBUG("bnever and link");
2358 case OPC_BLTZALL: /* 0 < 0 likely */
2359 tcg_gen_movi_tl(cpu_gpr[31], ctx->pc + 8);
2360 /* Skip the instruction in the delay slot */
2361 MIPS_DEBUG("bnever, link and skip");
2364 case OPC_BNEL: /* rx != rx likely */
2365 case OPC_BGTZL: /* 0 > 0 likely */
2366 case OPC_BLTZL: /* 0 < 0 likely */
2367 /* Skip the instruction in the delay slot */
2368 MIPS_DEBUG("bnever and skip");
2372 ctx->hflags |= MIPS_HFLAG_B;
2373 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2377 ctx->hflags |= MIPS_HFLAG_B;
2378 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2381 ctx->hflags |= MIPS_HFLAG_BR;
2382 MIPS_DEBUG("jr %s", regnames[rs]);
2386 ctx->hflags |= MIPS_HFLAG_BR;
2387 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2390 MIPS_INVAL("branch/jump");
2391 generate_exception(ctx, EXCP_RI);
2397 gen_op_eq(bcond, t0, t1);
2398 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2399 regnames[rs], regnames[rt], btgt);
2402 gen_op_eq(bcond, t0, t1);
2403 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2404 regnames[rs], regnames[rt], btgt);
2407 gen_op_ne(bcond, t0, t1);
2408 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2409 regnames[rs], regnames[rt], btgt);
2412 gen_op_ne(bcond, t0, t1);
2413 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2414 regnames[rs], regnames[rt], btgt);
2417 gen_op_gez(bcond, t0);
2418 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2421 gen_op_gez(bcond, t0);
2422 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2425 gen_op_gez(bcond, t0);
2426 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2430 gen_op_gez(bcond, t0);
2432 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2435 gen_op_gtz(bcond, t0);
2436 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2439 gen_op_gtz(bcond, t0);
2440 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2443 gen_op_lez(bcond, t0);
2444 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2447 gen_op_lez(bcond, t0);
2448 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2451 gen_op_ltz(bcond, t0);
2452 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2455 gen_op_ltz(bcond, t0);
2456 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2459 gen_op_ltz(bcond, t0);
2461 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2463 ctx->hflags |= MIPS_HFLAG_BC;
2466 gen_op_ltz(bcond, t0);
2468 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2470 ctx->hflags |= MIPS_HFLAG_BL;
2473 MIPS_INVAL("conditional branch/jump");
2474 generate_exception(ctx, EXCP_RI);
2478 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2479 blink, ctx->hflags, btgt);
2481 ctx->btarget = btgt;
2483 tcg_gen_movi_tl(cpu_gpr[blink], ctx->pc + 8);
2491 /* special3 bitfield operations */
2492 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2493 int rs, int lsb, int msb)
2495 TCGv t0 = tcg_temp_new();
2496 TCGv t1 = tcg_temp_new();
2499 gen_load_gpr(t1, rs);
2504 tcg_gen_shri_tl(t0, t1, lsb);
2506 tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
2508 tcg_gen_ext32s_tl(t0, t0);
2511 #if defined(TARGET_MIPS64)
2513 tcg_gen_shri_tl(t0, t1, lsb);
2515 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
2519 tcg_gen_shri_tl(t0, t1, lsb + 32);
2520 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2523 tcg_gen_shri_tl(t0, t1, lsb);
2524 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2530 mask = ((msb - lsb + 1 < 32) ? ((1 << (msb - lsb + 1)) - 1) : ~0) << lsb;
2531 gen_load_gpr(t0, rt);
2532 tcg_gen_andi_tl(t0, t0, ~mask);
2533 tcg_gen_shli_tl(t1, t1, lsb);
2534 tcg_gen_andi_tl(t1, t1, mask);
2535 tcg_gen_or_tl(t0, t0, t1);
2536 tcg_gen_ext32s_tl(t0, t0);
2538 #if defined(TARGET_MIPS64)
2542 mask = ((msb - lsb + 1 + 32 < 64) ? ((1ULL << (msb - lsb + 1 + 32)) - 1) : ~0ULL) << lsb;
2543 gen_load_gpr(t0, rt);
2544 tcg_gen_andi_tl(t0, t0, ~mask);
2545 tcg_gen_shli_tl(t1, t1, lsb);
2546 tcg_gen_andi_tl(t1, t1, mask);
2547 tcg_gen_or_tl(t0, t0, t1);
2552 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2553 gen_load_gpr(t0, rt);
2554 tcg_gen_andi_tl(t0, t0, ~mask);
2555 tcg_gen_shli_tl(t1, t1, lsb + 32);
2556 tcg_gen_andi_tl(t1, t1, mask);
2557 tcg_gen_or_tl(t0, t0, t1);
2562 gen_load_gpr(t0, rt);
2563 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2564 gen_load_gpr(t0, rt);
2565 tcg_gen_andi_tl(t0, t0, ~mask);
2566 tcg_gen_shli_tl(t1, t1, lsb);
2567 tcg_gen_andi_tl(t1, t1, mask);
2568 tcg_gen_or_tl(t0, t0, t1);
2573 MIPS_INVAL("bitops");
2574 generate_exception(ctx, EXCP_RI);
2579 gen_store_gpr(t0, rt);
2584 static void gen_bshfl (DisasContext *ctx, uint32_t op2, int rt, int rd)
2589 /* If no destination, treat it as a NOP. */
2594 t0 = tcg_temp_new();
2595 gen_load_gpr(t0, rt);
2599 TCGv t1 = tcg_temp_new();
2601 tcg_gen_shri_tl(t1, t0, 8);
2602 tcg_gen_andi_tl(t1, t1, 0x00FF00FF);
2603 tcg_gen_shli_tl(t0, t0, 8);
2604 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF);
2605 tcg_gen_or_tl(t0, t0, t1);
2607 tcg_gen_ext32s_tl(cpu_gpr[rd], t0);
2611 tcg_gen_ext8s_tl(cpu_gpr[rd], t0);
2614 tcg_gen_ext16s_tl(cpu_gpr[rd], t0);
2616 #if defined(TARGET_MIPS64)
2619 TCGv t1 = tcg_temp_new();
2621 tcg_gen_shri_tl(t1, t0, 8);
2622 tcg_gen_andi_tl(t1, t1, 0x00FF00FF00FF00FFULL);
2623 tcg_gen_shli_tl(t0, t0, 8);
2624 tcg_gen_andi_tl(t0, t0, ~0x00FF00FF00FF00FFULL);
2625 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2631 TCGv t1 = tcg_temp_new();
2633 tcg_gen_shri_tl(t1, t0, 16);
2634 tcg_gen_andi_tl(t1, t1, 0x0000FFFF0000FFFFULL);
2635 tcg_gen_shli_tl(t0, t0, 16);
2636 tcg_gen_andi_tl(t0, t0, ~0x0000FFFF0000FFFFULL);
2637 tcg_gen_or_tl(t0, t0, t1);
2638 tcg_gen_shri_tl(t1, t0, 32);
2639 tcg_gen_shli_tl(t0, t0, 32);
2640 tcg_gen_or_tl(cpu_gpr[rd], t0, t1);
2646 MIPS_INVAL("bsfhl");
2647 generate_exception(ctx, EXCP_RI);
2654 #ifndef CONFIG_USER_ONLY
2655 /* CP0 (MMU and control) */
2656 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2658 TCGv_i32 r_tmp = tcg_temp_new_i32();
2660 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2661 tcg_gen_ext_i32_tl(t, r_tmp);
2662 tcg_temp_free_i32(r_tmp);
2665 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2667 tcg_gen_ld_tl(t, cpu_env, off);
2668 tcg_gen_ext32s_tl(t, t);
2671 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2673 TCGv_i32 r_tmp = tcg_temp_new_i32();
2675 tcg_gen_trunc_tl_i32(r_tmp, t);
2676 tcg_gen_st_i32(r_tmp, cpu_env, off);
2677 tcg_temp_free_i32(r_tmp);
2680 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2682 tcg_gen_ext32s_tl(t, t);
2683 tcg_gen_st_tl(t, cpu_env, off);
2686 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2688 const char *rn = "invalid";
2691 check_insn(env, ctx, ISA_MIPS32);
2697 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2701 check_insn(env, ctx, ASE_MT);
2702 gen_helper_mfc0_mvpcontrol(t0);
2706 check_insn(env, ctx, ASE_MT);
2707 gen_helper_mfc0_mvpconf0(t0);
2711 check_insn(env, ctx, ASE_MT);
2712 gen_helper_mfc0_mvpconf1(t0);
2722 gen_helper_mfc0_random(t0);
2726 check_insn(env, ctx, ASE_MT);
2727 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2731 check_insn(env, ctx, ASE_MT);
2732 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2736 check_insn(env, ctx, ASE_MT);
2737 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2741 check_insn(env, ctx, ASE_MT);
2742 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2746 check_insn(env, ctx, ASE_MT);
2747 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2751 check_insn(env, ctx, ASE_MT);
2752 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2753 rn = "VPEScheFBack";
2756 check_insn(env, ctx, ASE_MT);
2757 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2767 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2768 tcg_gen_ext32s_tl(t0, t0);
2772 check_insn(env, ctx, ASE_MT);
2773 gen_helper_mfc0_tcstatus(t0);
2777 check_insn(env, ctx, ASE_MT);
2778 gen_helper_mfc0_tcbind(t0);
2782 check_insn(env, ctx, ASE_MT);
2783 gen_helper_mfc0_tcrestart(t0);
2787 check_insn(env, ctx, ASE_MT);
2788 gen_helper_mfc0_tchalt(t0);
2792 check_insn(env, ctx, ASE_MT);
2793 gen_helper_mfc0_tccontext(t0);
2797 check_insn(env, ctx, ASE_MT);
2798 gen_helper_mfc0_tcschedule(t0);
2802 check_insn(env, ctx, ASE_MT);
2803 gen_helper_mfc0_tcschefback(t0);
2813 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2814 tcg_gen_ext32s_tl(t0, t0);
2824 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2825 tcg_gen_ext32s_tl(t0, t0);
2829 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2830 rn = "ContextConfig";
2839 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2843 check_insn(env, ctx, ISA_MIPS32R2);
2844 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2854 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2858 check_insn(env, ctx, ISA_MIPS32R2);
2859 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2863 check_insn(env, ctx, ISA_MIPS32R2);
2864 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2868 check_insn(env, ctx, ISA_MIPS32R2);
2869 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2873 check_insn(env, ctx, ISA_MIPS32R2);
2874 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2878 check_insn(env, ctx, ISA_MIPS32R2);
2879 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2889 check_insn(env, ctx, ISA_MIPS32R2);
2890 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
2900 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
2901 tcg_gen_ext32s_tl(t0, t0);
2911 /* Mark as an IO operation because we read the time. */
2914 gen_helper_mfc0_count(t0);
2917 ctx->bstate = BS_STOP;
2921 /* 6,7 are implementation dependent */
2929 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
2930 tcg_gen_ext32s_tl(t0, t0);
2940 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
2943 /* 6,7 are implementation dependent */
2951 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
2955 check_insn(env, ctx, ISA_MIPS32R2);
2956 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
2960 check_insn(env, ctx, ISA_MIPS32R2);
2961 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
2965 check_insn(env, ctx, ISA_MIPS32R2);
2966 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
2976 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
2986 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
2987 tcg_gen_ext32s_tl(t0, t0);
2997 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3001 check_insn(env, ctx, ISA_MIPS32R2);
3002 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3012 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3016 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3020 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3024 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3027 /* 4,5 are reserved */
3028 /* 6,7 are implementation dependent */
3030 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3034 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3044 gen_helper_mfc0_lladdr(t0);
3054 gen_helper_1i(mfc0_watchlo, t0, sel);
3064 gen_helper_1i(mfc0_watchhi, t0, sel);
3074 #if defined(TARGET_MIPS64)
3075 check_insn(env, ctx, ISA_MIPS3);
3076 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3077 tcg_gen_ext32s_tl(t0, t0);
3086 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3089 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3097 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3098 rn = "'Diagnostic"; /* implementation dependent */
3103 gen_helper_mfc0_debug(t0); /* EJTAG support */
3107 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3108 rn = "TraceControl";
3111 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3112 rn = "TraceControl2";
3115 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3116 rn = "UserTraceData";
3119 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3130 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3131 tcg_gen_ext32s_tl(t0, t0);
3141 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3142 rn = "Performance0";
3145 // gen_helper_mfc0_performance1(t0);
3146 rn = "Performance1";
3149 // gen_helper_mfc0_performance2(t0);
3150 rn = "Performance2";
3153 // gen_helper_mfc0_performance3(t0);
3154 rn = "Performance3";
3157 // gen_helper_mfc0_performance4(t0);
3158 rn = "Performance4";
3161 // gen_helper_mfc0_performance5(t0);
3162 rn = "Performance5";
3165 // gen_helper_mfc0_performance6(t0);
3166 rn = "Performance6";
3169 // gen_helper_mfc0_performance7(t0);
3170 rn = "Performance7";
3177 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3183 tcg_gen_movi_tl(t0, 0); /* unimplemented */
3196 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3203 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3216 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3223 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3233 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3234 tcg_gen_ext32s_tl(t0, t0);
3245 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3255 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3259 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn, reg, sel);
3260 generate_exception(ctx, EXCP_RI);
3263 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3265 const char *rn = "invalid";
3268 check_insn(env, ctx, ISA_MIPS32);
3277 gen_helper_mtc0_index(t0);
3281 check_insn(env, ctx, ASE_MT);
3282 gen_helper_mtc0_mvpcontrol(t0);
3286 check_insn(env, ctx, ASE_MT);
3291 check_insn(env, ctx, ASE_MT);
3306 check_insn(env, ctx, ASE_MT);
3307 gen_helper_mtc0_vpecontrol(t0);
3311 check_insn(env, ctx, ASE_MT);
3312 gen_helper_mtc0_vpeconf0(t0);
3316 check_insn(env, ctx, ASE_MT);
3317 gen_helper_mtc0_vpeconf1(t0);
3321 check_insn(env, ctx, ASE_MT);
3322 gen_helper_mtc0_yqmask(t0);
3326 check_insn(env, ctx, ASE_MT);
3327 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3331 check_insn(env, ctx, ASE_MT);
3332 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3333 rn = "VPEScheFBack";
3336 check_insn(env, ctx, ASE_MT);
3337 gen_helper_mtc0_vpeopt(t0);
3347 gen_helper_mtc0_entrylo0(t0);
3351 check_insn(env, ctx, ASE_MT);
3352 gen_helper_mtc0_tcstatus(t0);
3356 check_insn(env, ctx, ASE_MT);
3357 gen_helper_mtc0_tcbind(t0);
3361 check_insn(env, ctx, ASE_MT);
3362 gen_helper_mtc0_tcrestart(t0);
3366 check_insn(env, ctx, ASE_MT);
3367 gen_helper_mtc0_tchalt(t0);
3371 check_insn(env, ctx, ASE_MT);
3372 gen_helper_mtc0_tccontext(t0);
3376 check_insn(env, ctx, ASE_MT);
3377 gen_helper_mtc0_tcschedule(t0);
3381 check_insn(env, ctx, ASE_MT);
3382 gen_helper_mtc0_tcschefback(t0);
3392 gen_helper_mtc0_entrylo1(t0);
3402 gen_helper_mtc0_context(t0);
3406 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3407 rn = "ContextConfig";
3416 gen_helper_mtc0_pagemask(t0);
3420 check_insn(env, ctx, ISA_MIPS32R2);
3421 gen_helper_mtc0_pagegrain(t0);
3431 gen_helper_mtc0_wired(t0);
3435 check_insn(env, ctx, ISA_MIPS32R2);
3436 gen_helper_mtc0_srsconf0(t0);
3440 check_insn(env, ctx, ISA_MIPS32R2);
3441 gen_helper_mtc0_srsconf1(t0);
3445 check_insn(env, ctx, ISA_MIPS32R2);
3446 gen_helper_mtc0_srsconf2(t0);
3450 check_insn(env, ctx, ISA_MIPS32R2);
3451 gen_helper_mtc0_srsconf3(t0);
3455 check_insn(env, ctx, ISA_MIPS32R2);
3456 gen_helper_mtc0_srsconf4(t0);
3466 check_insn(env, ctx, ISA_MIPS32R2);
3467 gen_helper_mtc0_hwrena(t0);
3481 gen_helper_mtc0_count(t0);
3484 /* 6,7 are implementation dependent */
3488 /* Stop translation as we may have switched the execution mode */
3489 ctx->bstate = BS_STOP;
3494 gen_helper_mtc0_entryhi(t0);
3504 gen_helper_mtc0_compare(t0);
3507 /* 6,7 are implementation dependent */
3511 /* Stop translation as we may have switched the execution mode */
3512 ctx->bstate = BS_STOP;
3517 gen_helper_mtc0_status(t0);
3518 /* BS_STOP isn't good enough here, hflags may have changed. */
3519 gen_save_pc(ctx->pc + 4);
3520 ctx->bstate = BS_EXCP;
3524 check_insn(env, ctx, ISA_MIPS32R2);
3525 gen_helper_mtc0_intctl(t0);
3526 /* Stop translation as we may have switched the execution mode */
3527 ctx->bstate = BS_STOP;
3531 check_insn(env, ctx, ISA_MIPS32R2);
3532 gen_helper_mtc0_srsctl(t0);
3533 /* Stop translation as we may have switched the execution mode */
3534 ctx->bstate = BS_STOP;
3538 check_insn(env, ctx, ISA_MIPS32R2);
3539 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3540 /* Stop translation as we may have switched the execution mode */
3541 ctx->bstate = BS_STOP;
3551 gen_helper_mtc0_cause(t0);
3557 /* Stop translation as we may have switched the execution mode */
3558 ctx->bstate = BS_STOP;
3563 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3577 check_insn(env, ctx, ISA_MIPS32R2);
3578 gen_helper_mtc0_ebase(t0);
3588 gen_helper_mtc0_config0(t0);
3590 /* Stop translation as we may have switched the execution mode */
3591 ctx->bstate = BS_STOP;
3594 /* ignored, read only */
3598 gen_helper_mtc0_config2(t0);
3600 /* Stop translation as we may have switched the execution mode */
3601 ctx->bstate = BS_STOP;
3604 /* ignored, read only */
3607 /* 4,5 are reserved */
3608 /* 6,7 are implementation dependent */
3618 rn = "Invalid config selector";
3635 gen_helper_1i(mtc0_watchlo, t0, sel);
3645 gen_helper_1i(mtc0_watchhi, t0, sel);
3655 #if defined(TARGET_MIPS64)
3656 check_insn(env, ctx, ISA_MIPS3);
3657 gen_helper_mtc0_xcontext(t0);
3666 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3669 gen_helper_mtc0_framemask(t0);
3678 rn = "Diagnostic"; /* implementation dependent */
3683 gen_helper_mtc0_debug(t0); /* EJTAG support */
3684 /* BS_STOP isn't good enough here, hflags may have changed. */
3685 gen_save_pc(ctx->pc + 4);
3686 ctx->bstate = BS_EXCP;
3690 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3691 rn = "TraceControl";
3692 /* Stop translation as we may have switched the execution mode */
3693 ctx->bstate = BS_STOP;
3696 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3697 rn = "TraceControl2";
3698 /* Stop translation as we may have switched the execution mode */
3699 ctx->bstate = BS_STOP;
3702 /* Stop translation as we may have switched the execution mode */
3703 ctx->bstate = BS_STOP;
3704 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3705 rn = "UserTraceData";
3706 /* Stop translation as we may have switched the execution mode */
3707 ctx->bstate = BS_STOP;
3710 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3711 /* Stop translation as we may have switched the execution mode */
3712 ctx->bstate = BS_STOP;
3723 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3733 gen_helper_mtc0_performance0(t0);
3734 rn = "Performance0";
3737 // gen_helper_mtc0_performance1(t0);
3738 rn = "Performance1";
3741 // gen_helper_mtc0_performance2(t0);
3742 rn = "Performance2";
3745 // gen_helper_mtc0_performance3(t0);
3746 rn = "Performance3";
3749 // gen_helper_mtc0_performance4(t0);
3750 rn = "Performance4";
3753 // gen_helper_mtc0_performance5(t0);
3754 rn = "Performance5";
3757 // gen_helper_mtc0_performance6(t0);
3758 rn = "Performance6";
3761 // gen_helper_mtc0_performance7(t0);
3762 rn = "Performance7";
3788 gen_helper_mtc0_taglo(t0);
3795 gen_helper_mtc0_datalo(t0);
3808 gen_helper_mtc0_taghi(t0);
3815 gen_helper_mtc0_datahi(t0);
3826 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3837 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3843 /* Stop translation as we may have switched the execution mode */
3844 ctx->bstate = BS_STOP;
3849 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3850 /* For simplicity assume that all writes can cause interrupts. */
3853 ctx->bstate = BS_STOP;
3858 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn, reg, sel);
3859 generate_exception(ctx, EXCP_RI);
3862 #if defined(TARGET_MIPS64)
3863 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3865 const char *rn = "invalid";
3868 check_insn(env, ctx, ISA_MIPS64);
3874 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
3878 check_insn(env, ctx, ASE_MT);
3879 gen_helper_mfc0_mvpcontrol(t0);
3883 check_insn(env, ctx, ASE_MT);
3884 gen_helper_mfc0_mvpconf0(t0);
3888 check_insn(env, ctx, ASE_MT);
3889 gen_helper_mfc0_mvpconf1(t0);
3899 gen_helper_mfc0_random(t0);
3903 check_insn(env, ctx, ASE_MT);
3904 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
3908 check_insn(env, ctx, ASE_MT);
3909 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
3913 check_insn(env, ctx, ASE_MT);
3914 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
3918 check_insn(env, ctx, ASE_MT);
3919 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
3923 check_insn(env, ctx, ASE_MT);
3924 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
3928 check_insn(env, ctx, ASE_MT);
3929 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3930 rn = "VPEScheFBack";
3933 check_insn(env, ctx, ASE_MT);
3934 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
3944 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
3948 check_insn(env, ctx, ASE_MT);
3949 gen_helper_mfc0_tcstatus(t0);
3953 check_insn(env, ctx, ASE_MT);
3954 gen_helper_mfc0_tcbind(t0);
3958 check_insn(env, ctx, ASE_MT);
3959 gen_helper_dmfc0_tcrestart(t0);
3963 check_insn(env, ctx, ASE_MT);
3964 gen_helper_dmfc0_tchalt(t0);
3968 check_insn(env, ctx, ASE_MT);
3969 gen_helper_dmfc0_tccontext(t0);
3973 check_insn(env, ctx, ASE_MT);
3974 gen_helper_dmfc0_tcschedule(t0);
3978 check_insn(env, ctx, ASE_MT);
3979 gen_helper_dmfc0_tcschefback(t0);
3989 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
3999 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4003 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4004 rn = "ContextConfig";
4013 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4017 check_insn(env, ctx, ISA_MIPS32R2);
4018 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4028 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4032 check_insn(env, ctx, ISA_MIPS32R2);
4033 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4037 check_insn(env, ctx, ISA_MIPS32R2);
4038 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4042 check_insn(env, ctx, ISA_MIPS32R2);
4043 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4047 check_insn(env, ctx, ISA_MIPS32R2);
4048 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4052 check_insn(env, ctx, ISA_MIPS32R2);
4053 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4063 check_insn(env, ctx, ISA_MIPS32R2);
4064 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4074 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4084 /* Mark as an IO operation because we read the time. */
4087 gen_helper_mfc0_count(t0);
4090 ctx->bstate = BS_STOP;
4094 /* 6,7 are implementation dependent */
4102 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4112 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4115 /* 6,7 are implementation dependent */
4123 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4127 check_insn(env, ctx, ISA_MIPS32R2);
4128 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4132 check_insn(env, ctx, ISA_MIPS32R2);
4133 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4137 check_insn(env, ctx, ISA_MIPS32R2);
4138 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4148 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4158 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4168 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4172 check_insn(env, ctx, ISA_MIPS32R2);
4173 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4183 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4187 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4191 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4195 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4198 /* 6,7 are implementation dependent */
4200 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4204 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4214 gen_helper_dmfc0_lladdr(t0);
4224 gen_helper_1i(dmfc0_watchlo, t0, sel);
4234 gen_helper_1i(mfc0_watchhi, t0, sel);
4244 check_insn(env, ctx, ISA_MIPS3);
4245 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4253 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4256 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4264 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4265 rn = "'Diagnostic"; /* implementation dependent */
4270 gen_helper_mfc0_debug(t0); /* EJTAG support */
4274 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4275 rn = "TraceControl";
4278 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4279 rn = "TraceControl2";
4282 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4283 rn = "UserTraceData";
4286 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4297 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4307 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4308 rn = "Performance0";
4311 // gen_helper_dmfc0_performance1(t0);
4312 rn = "Performance1";
4315 // gen_helper_dmfc0_performance2(t0);
4316 rn = "Performance2";
4319 // gen_helper_dmfc0_performance3(t0);
4320 rn = "Performance3";
4323 // gen_helper_dmfc0_performance4(t0);
4324 rn = "Performance4";
4327 // gen_helper_dmfc0_performance5(t0);
4328 rn = "Performance5";
4331 // gen_helper_dmfc0_performance6(t0);
4332 rn = "Performance6";
4335 // gen_helper_dmfc0_performance7(t0);
4336 rn = "Performance7";
4343 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4350 tcg_gen_movi_tl(t0, 0); /* unimplemented */
4363 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4370 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4383 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4390 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4400 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4411 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4421 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4425 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn, reg, sel);
4426 generate_exception(ctx, EXCP_RI);
4429 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4431 const char *rn = "invalid";
4434 check_insn(env, ctx, ISA_MIPS64);
4443 gen_helper_mtc0_index(t0);
4447 check_insn(env, ctx, ASE_MT);
4448 gen_helper_mtc0_mvpcontrol(t0);
4452 check_insn(env, ctx, ASE_MT);
4457 check_insn(env, ctx, ASE_MT);
4472 check_insn(env, ctx, ASE_MT);
4473 gen_helper_mtc0_vpecontrol(t0);
4477 check_insn(env, ctx, ASE_MT);
4478 gen_helper_mtc0_vpeconf0(t0);
4482 check_insn(env, ctx, ASE_MT);
4483 gen_helper_mtc0_vpeconf1(t0);
4487 check_insn(env, ctx, ASE_MT);
4488 gen_helper_mtc0_yqmask(t0);
4492 check_insn(env, ctx, ASE_MT);
4493 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4497 check_insn(env, ctx, ASE_MT);
4498 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4499 rn = "VPEScheFBack";
4502 check_insn(env, ctx, ASE_MT);
4503 gen_helper_mtc0_vpeopt(t0);
4513 gen_helper_mtc0_entrylo0(t0);
4517 check_insn(env, ctx, ASE_MT);
4518 gen_helper_mtc0_tcstatus(t0);
4522 check_insn(env, ctx, ASE_MT);
4523 gen_helper_mtc0_tcbind(t0);
4527 check_insn(env, ctx, ASE_MT);
4528 gen_helper_mtc0_tcrestart(t0);
4532 check_insn(env, ctx, ASE_MT);
4533 gen_helper_mtc0_tchalt(t0);
4537 check_insn(env, ctx, ASE_MT);
4538 gen_helper_mtc0_tccontext(t0);
4542 check_insn(env, ctx, ASE_MT);
4543 gen_helper_mtc0_tcschedule(t0);
4547 check_insn(env, ctx, ASE_MT);
4548 gen_helper_mtc0_tcschefback(t0);
4558 gen_helper_mtc0_entrylo1(t0);
4568 gen_helper_mtc0_context(t0);
4572 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4573 rn = "ContextConfig";
4582 gen_helper_mtc0_pagemask(t0);
4586 check_insn(env, ctx, ISA_MIPS32R2);
4587 gen_helper_mtc0_pagegrain(t0);
4597 gen_helper_mtc0_wired(t0);
4601 check_insn(env, ctx, ISA_MIPS32R2);
4602 gen_helper_mtc0_srsconf0(t0);
4606 check_insn(env, ctx, ISA_MIPS32R2);
4607 gen_helper_mtc0_srsconf1(t0);
4611 check_insn(env, ctx, ISA_MIPS32R2);
4612 gen_helper_mtc0_srsconf2(t0);
4616 check_insn(env, ctx, ISA_MIPS32R2);
4617 gen_helper_mtc0_srsconf3(t0);
4621 check_insn(env, ctx, ISA_MIPS32R2);
4622 gen_helper_mtc0_srsconf4(t0);
4632 check_insn(env, ctx, ISA_MIPS32R2);
4633 gen_helper_mtc0_hwrena(t0);
4647 gen_helper_mtc0_count(t0);
4650 /* 6,7 are implementation dependent */
4654 /* Stop translation as we may have switched the execution mode */
4655 ctx->bstate = BS_STOP;
4660 gen_helper_mtc0_entryhi(t0);
4670 gen_helper_mtc0_compare(t0);
4673 /* 6,7 are implementation dependent */
4677 /* Stop translation as we may have switched the execution mode */
4678 ctx->bstate = BS_STOP;
4683 gen_helper_mtc0_status(t0);
4684 /* BS_STOP isn't good enough here, hflags may have changed. */
4685 gen_save_pc(ctx->pc + 4);
4686 ctx->bstate = BS_EXCP;
4690 check_insn(env, ctx, ISA_MIPS32R2);
4691 gen_helper_mtc0_intctl(t0);
4692 /* Stop translation as we may have switched the execution mode */
4693 ctx->bstate = BS_STOP;
4697 check_insn(env, ctx, ISA_MIPS32R2);
4698 gen_helper_mtc0_srsctl(t0);
4699 /* Stop translation as we may have switched the execution mode */
4700 ctx->bstate = BS_STOP;
4704 check_insn(env, ctx, ISA_MIPS32R2);
4705 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4706 /* Stop translation as we may have switched the execution mode */
4707 ctx->bstate = BS_STOP;
4717 gen_helper_mtc0_cause(t0);
4723 /* Stop translation as we may have switched the execution mode */
4724 ctx->bstate = BS_STOP;
4729 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4743 check_insn(env, ctx, ISA_MIPS32R2);
4744 gen_helper_mtc0_ebase(t0);
4754 gen_helper_mtc0_config0(t0);
4756 /* Stop translation as we may have switched the execution mode */
4757 ctx->bstate = BS_STOP;
4764 gen_helper_mtc0_config2(t0);
4766 /* Stop translation as we may have switched the execution mode */
4767 ctx->bstate = BS_STOP;
4773 /* 6,7 are implementation dependent */
4775 rn = "Invalid config selector";
4792 gen_helper_1i(mtc0_watchlo, t0, sel);
4802 gen_helper_1i(mtc0_watchhi, t0, sel);
4812 check_insn(env, ctx, ISA_MIPS3);
4813 gen_helper_mtc0_xcontext(t0);
4821 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4824 gen_helper_mtc0_framemask(t0);
4833 rn = "Diagnostic"; /* implementation dependent */
4838 gen_helper_mtc0_debug(t0); /* EJTAG support */
4839 /* BS_STOP isn't good enough here, hflags may have changed. */
4840 gen_save_pc(ctx->pc + 4);
4841 ctx->bstate = BS_EXCP;
4845 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4846 /* Stop translation as we may have switched the execution mode */
4847 ctx->bstate = BS_STOP;
4848 rn = "TraceControl";
4851 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4852 /* Stop translation as we may have switched the execution mode */
4853 ctx->bstate = BS_STOP;
4854 rn = "TraceControl2";
4857 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4858 /* Stop translation as we may have switched the execution mode */
4859 ctx->bstate = BS_STOP;
4860 rn = "UserTraceData";
4863 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4864 /* Stop translation as we may have switched the execution mode */
4865 ctx->bstate = BS_STOP;
4876 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4886 gen_helper_mtc0_performance0(t0);
4887 rn = "Performance0";
4890 // gen_helper_mtc0_performance1(t0);
4891 rn = "Performance1";
4894 // gen_helper_mtc0_performance2(t0);
4895 rn = "Performance2";
4898 // gen_helper_mtc0_performance3(t0);
4899 rn = "Performance3";
4902 // gen_helper_mtc0_performance4(t0);
4903 rn = "Performance4";
4906 // gen_helper_mtc0_performance5(t0);
4907 rn = "Performance5";
4910 // gen_helper_mtc0_performance6(t0);
4911 rn = "Performance6";
4914 // gen_helper_mtc0_performance7(t0);
4915 rn = "Performance7";
4941 gen_helper_mtc0_taglo(t0);
4948 gen_helper_mtc0_datalo(t0);
4961 gen_helper_mtc0_taghi(t0);
4968 gen_helper_mtc0_datahi(t0);
4979 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4990 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
4996 /* Stop translation as we may have switched the execution mode */
4997 ctx->bstate = BS_STOP;
5002 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5003 /* For simplicity assume that all writes can cause interrupts. */
5006 ctx->bstate = BS_STOP;
5011 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn, reg, sel);
5012 generate_exception(ctx, EXCP_RI);
5014 #endif /* TARGET_MIPS64 */
5016 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5017 int u, int sel, int h)
5019 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5020 TCGv t0 = tcg_temp_local_new();
5022 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5023 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5024 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5025 tcg_gen_movi_tl(t0, -1);
5026 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5027 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5028 tcg_gen_movi_tl(t0, -1);
5034 gen_helper_mftc0_tcstatus(t0);
5037 gen_helper_mftc0_tcbind(t0);
5040 gen_helper_mftc0_tcrestart(t0);
5043 gen_helper_mftc0_tchalt(t0);
5046 gen_helper_mftc0_tccontext(t0);
5049 gen_helper_mftc0_tcschedule(t0);
5052 gen_helper_mftc0_tcschefback(t0);
5055 gen_mfc0(env, ctx, t0, rt, sel);
5062 gen_helper_mftc0_entryhi(t0);
5065 gen_mfc0(env, ctx, t0, rt, sel);
5071 gen_helper_mftc0_status(t0);
5074 gen_mfc0(env, ctx, t0, rt, sel);
5080 gen_helper_mftc0_debug(t0);
5083 gen_mfc0(env, ctx, t0, rt, sel);
5088 gen_mfc0(env, ctx, t0, rt, sel);
5090 } else switch (sel) {
5091 /* GPR registers. */
5093 gen_helper_1i(mftgpr, t0, rt);
5095 /* Auxiliary CPU registers */
5099 gen_helper_1i(mftlo, t0, 0);
5102 gen_helper_1i(mfthi, t0, 0);
5105 gen_helper_1i(mftacx, t0, 0);
5108 gen_helper_1i(mftlo, t0, 1);
5111 gen_helper_1i(mfthi, t0, 1);
5114 gen_helper_1i(mftacx, t0, 1);
5117 gen_helper_1i(mftlo, t0, 2);
5120 gen_helper_1i(mfthi, t0, 2);
5123 gen_helper_1i(mftacx, t0, 2);
5126 gen_helper_1i(mftlo, t0, 3);
5129 gen_helper_1i(mfthi, t0, 3);
5132 gen_helper_1i(mftacx, t0, 3);
5135 gen_helper_mftdsp(t0);
5141 /* Floating point (COP1). */
5143 /* XXX: For now we support only a single FPU context. */
5145 TCGv_i32 fp0 = tcg_temp_new_i32();
5147 gen_load_fpr32(fp0, rt);
5148 tcg_gen_ext_i32_tl(t0, fp0);
5149 tcg_temp_free_i32(fp0);
5151 TCGv_i32 fp0 = tcg_temp_new_i32();
5153 gen_load_fpr32h(fp0, rt);
5154 tcg_gen_ext_i32_tl(t0, fp0);
5155 tcg_temp_free_i32(fp0);
5159 /* XXX: For now we support only a single FPU context. */
5160 gen_helper_1i(cfc1, t0, rt);
5162 /* COP2: Not implemented. */
5169 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5170 gen_store_gpr(t0, rd);
5176 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt, u, sel, h);
5177 generate_exception(ctx, EXCP_RI);
5180 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5181 int u, int sel, int h)
5183 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5184 TCGv t0 = tcg_temp_local_new();
5186 gen_load_gpr(t0, rt);
5187 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5188 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5189 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5191 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5192 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5199 gen_helper_mttc0_tcstatus(t0);
5202 gen_helper_mttc0_tcbind(t0);
5205 gen_helper_mttc0_tcrestart(t0);
5208 gen_helper_mttc0_tchalt(t0);
5211 gen_helper_mttc0_tccontext(t0);
5214 gen_helper_mttc0_tcschedule(t0);
5217 gen_helper_mttc0_tcschefback(t0);
5220 gen_mtc0(env, ctx, t0, rd, sel);
5227 gen_helper_mttc0_entryhi(t0);
5230 gen_mtc0(env, ctx, t0, rd, sel);
5236 gen_helper_mttc0_status(t0);
5239 gen_mtc0(env, ctx, t0, rd, sel);
5245 gen_helper_mttc0_debug(t0);
5248 gen_mtc0(env, ctx, t0, rd, sel);
5253 gen_mtc0(env, ctx, t0, rd, sel);
5255 } else switch (sel) {
5256 /* GPR registers. */
5258 gen_helper_1i(mttgpr, t0, rd);
5260 /* Auxiliary CPU registers */
5264 gen_helper_1i(mttlo, t0, 0);
5267 gen_helper_1i(mtthi, t0, 0);
5270 gen_helper_1i(mttacx, t0, 0);
5273 gen_helper_1i(mttlo, t0, 1);
5276 gen_helper_1i(mtthi, t0, 1);
5279 gen_helper_1i(mttacx, t0, 1);
5282 gen_helper_1i(mttlo, t0, 2);
5285 gen_helper_1i(mtthi, t0, 2);
5288 gen_helper_1i(mttacx, t0, 2);
5291 gen_helper_1i(mttlo, t0, 3);
5294 gen_helper_1i(mtthi, t0, 3);
5297 gen_helper_1i(mttacx, t0, 3);
5300 gen_helper_mttdsp(t0);
5306 /* Floating point (COP1). */
5308 /* XXX: For now we support only a single FPU context. */
5310 TCGv_i32 fp0 = tcg_temp_new_i32();
5312 tcg_gen_trunc_tl_i32(fp0, t0);
5313 gen_store_fpr32(fp0, rd);
5314 tcg_temp_free_i32(fp0);
5316 TCGv_i32 fp0 = tcg_temp_new_i32();
5318 tcg_gen_trunc_tl_i32(fp0, t0);
5319 gen_store_fpr32h(fp0, rd);
5320 tcg_temp_free_i32(fp0);
5324 /* XXX: For now we support only a single FPU context. */
5325 gen_helper_1i(ctc1, t0, rd);
5327 /* COP2: Not implemented. */
5334 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5340 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd, u, sel, h);
5341 generate_exception(ctx, EXCP_RI);
5344 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5346 const char *opn = "ldst";
5355 TCGv t0 = tcg_temp_local_new();
5357 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5358 gen_store_gpr(t0, rt);
5365 TCGv t0 = tcg_temp_local_new();
5367 gen_load_gpr(t0, rt);
5368 save_cpu_state(ctx, 1);
5369 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5374 #if defined(TARGET_MIPS64)
5376 check_insn(env, ctx, ISA_MIPS3);
5382 TCGv t0 = tcg_temp_local_new();
5384 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5385 gen_store_gpr(t0, rt);
5391 check_insn(env, ctx, ISA_MIPS3);
5393 TCGv t0 = tcg_temp_local_new();
5395 gen_load_gpr(t0, rt);
5396 save_cpu_state(ctx, 1);
5397 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5404 check_insn(env, ctx, ASE_MT);
5409 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5410 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5414 check_insn(env, ctx, ASE_MT);
5415 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5416 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5421 if (!env->tlb->helper_tlbwi)
5427 if (!env->tlb->helper_tlbwr)
5433 if (!env->tlb->helper_tlbp)
5439 if (!env->tlb->helper_tlbr)
5445 check_insn(env, ctx, ISA_MIPS2);
5446 save_cpu_state(ctx, 1);
5448 ctx->bstate = BS_EXCP;
5452 check_insn(env, ctx, ISA_MIPS32);
5453 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5455 generate_exception(ctx, EXCP_RI);
5457 save_cpu_state(ctx, 1);
5459 ctx->bstate = BS_EXCP;
5464 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5465 /* If we get an exception, we want to restart at next instruction */
5467 save_cpu_state(ctx, 1);
5470 ctx->bstate = BS_EXCP;
5475 generate_exception(ctx, EXCP_RI);
5478 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5480 #endif /* !CONFIG_USER_ONLY */
5482 /* CP1 Branches (before delay slot) */
5483 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5484 int32_t cc, int32_t offset)
5486 target_ulong btarget;
5487 const char *opn = "cp1 cond branch";
5488 TCGv_i32 t0 = tcg_temp_new_i32();
5491 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5493 btarget = ctx->pc + 4 + offset;
5497 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5498 tcg_gen_not_i32(t0, t0);
5499 tcg_gen_andi_i32(t0, t0, 1);
5500 tcg_gen_extu_i32_tl(bcond, t0);
5504 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5505 tcg_gen_not_i32(t0, t0);
5506 tcg_gen_andi_i32(t0, t0, 1);
5507 tcg_gen_extu_i32_tl(bcond, t0);
5511 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5512 tcg_gen_andi_i32(t0, t0, 1);
5513 tcg_gen_extu_i32_tl(bcond, t0);
5517 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5518 tcg_gen_andi_i32(t0, t0, 1);
5519 tcg_gen_extu_i32_tl(bcond, t0);
5522 ctx->hflags |= MIPS_HFLAG_BL;
5526 TCGv_i32 t1 = tcg_temp_new_i32();
5527 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5528 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+1));
5529 tcg_gen_or_i32(t0, t0, t1);
5530 tcg_temp_free_i32(t1);
5531 tcg_gen_not_i32(t0, t0);
5532 tcg_gen_andi_i32(t0, t0, 1);
5533 tcg_gen_extu_i32_tl(bcond, t0);
5539 TCGv_i32 t1 = tcg_temp_new_i32();
5540 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5541 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+1));
5542 tcg_gen_or_i32(t0, t0, t1);
5543 tcg_temp_free_i32(t1);
5544 tcg_gen_andi_i32(t0, t0, 1);
5545 tcg_gen_extu_i32_tl(bcond, t0);
5551 TCGv_i32 t1 = tcg_temp_new_i32();
5552 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5553 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+1));
5554 tcg_gen_or_i32(t0, t0, t1);
5555 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+2));
5556 tcg_gen_or_i32(t0, t0, t1);
5557 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+3));
5558 tcg_gen_or_i32(t0, t0, t1);
5559 tcg_temp_free_i32(t1);
5560 tcg_gen_not_i32(t0, t0);
5561 tcg_gen_andi_i32(t0, t0, 1);
5562 tcg_gen_extu_i32_tl(bcond, t0);
5568 TCGv_i32 t1 = tcg_temp_new_i32();
5569 tcg_gen_shri_i32(t0, fpu_fcr31, get_fp_bit(cc));
5570 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+1));
5571 tcg_gen_or_i32(t0, t0, t1);
5572 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+2));
5573 tcg_gen_or_i32(t0, t0, t1);
5574 tcg_gen_shri_i32(t1, fpu_fcr31, get_fp_bit(cc+3));
5575 tcg_gen_or_i32(t0, t0, t1);
5576 tcg_temp_free_i32(t1);
5577 tcg_gen_andi_i32(t0, t0, 1);
5578 tcg_gen_extu_i32_tl(bcond, t0);
5582 ctx->hflags |= MIPS_HFLAG_BC;
5586 generate_exception (ctx, EXCP_RI);
5589 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5590 ctx->hflags, btarget);
5591 ctx->btarget = btarget;
5594 tcg_temp_free_i32(t0);
5597 /* Coprocessor 1 (FPU) */
5599 #define FOP(func, fmt) (((fmt) << 21) | (func))
5601 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5603 const char *opn = "cp1 move";
5604 TCGv t0 = tcg_temp_local_new();
5609 TCGv_i32 fp0 = tcg_temp_new_i32();
5611 gen_load_fpr32(fp0, fs);
5612 tcg_gen_ext_i32_tl(t0, fp0);
5613 tcg_temp_free_i32(fp0);
5615 gen_store_gpr(t0, rt);
5619 gen_load_gpr(t0, rt);
5621 TCGv_i32 fp0 = tcg_temp_new_i32();
5623 tcg_gen_trunc_tl_i32(fp0, t0);
5624 gen_store_fpr32(fp0, fs);
5625 tcg_temp_free_i32(fp0);
5630 gen_helper_1i(cfc1, t0, fs);
5631 gen_store_gpr(t0, rt);
5635 gen_load_gpr(t0, rt);
5636 gen_helper_1i(ctc1, t0, fs);
5641 TCGv_i64 fp0 = tcg_temp_new_i64();
5643 gen_load_fpr64(ctx, fp0, fs);
5644 tcg_gen_trunc_i64_tl(t0, fp0);
5645 tcg_temp_free_i64(fp0);
5647 gen_store_gpr(t0, rt);
5651 gen_load_gpr(t0, rt);
5653 TCGv_i64 fp0 = tcg_temp_new_i64();
5655 tcg_gen_extu_tl_i64(fp0, t0);
5656 gen_store_fpr64(ctx, fp0, fs);
5657 tcg_temp_free_i64(fp0);
5663 TCGv_i32 fp0 = tcg_temp_new_i32();
5665 gen_load_fpr32h(fp0, fs);
5666 tcg_gen_ext_i32_tl(t0, fp0);
5667 tcg_temp_free_i32(fp0);
5669 gen_store_gpr(t0, rt);
5673 gen_load_gpr(t0, rt);
5675 TCGv_i32 fp0 = tcg_temp_new_i32();
5677 tcg_gen_trunc_tl_i32(fp0, t0);
5678 gen_store_fpr32h(fp0, fs);
5679 tcg_temp_free_i32(fp0);
5685 generate_exception (ctx, EXCP_RI);
5688 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5694 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5710 l1 = gen_new_label();
5711 t0 = tcg_temp_new_i32();
5712 tcg_gen_andi_i32(t0, fpu_fcr31, get_fp_bit(cc));
5713 tcg_gen_brcondi_i32(cond, t0, 0, l1);
5715 tcg_gen_movi_tl(cpu_gpr[rd], 0);
5717 tcg_gen_mov_tl(cpu_gpr[rd], cpu_gpr[rs]);
5720 tcg_temp_free_i32(t0);
5723 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5727 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5728 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5729 int l1 = gen_new_label();
5732 ccbit = 1 << (24 + cc);
5741 gen_load_fpr32(fp0, fd);
5742 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5743 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5744 tcg_temp_free_i32(r_tmp1);
5745 gen_load_fpr32(fp0, fs);
5747 gen_store_fpr32(fp0, fd);
5748 tcg_temp_free_i32(fp0);
5751 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
5755 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5756 TCGv_i64 fp0 = tcg_temp_local_new_i64();
5757 int l1 = gen_new_label();
5760 ccbit = 1 << (24 + cc);
5769 gen_load_fpr64(ctx, fp0, fd);
5770 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5771 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5772 tcg_temp_free_i32(r_tmp1);
5773 gen_load_fpr64(ctx, fp0, fs);
5775 gen_store_fpr64(ctx, fp0, fd);
5776 tcg_temp_free_i64(fp0);
5779 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
5781 uint32_t ccbit1, ccbit2;
5783 TCGv_i32 r_tmp1 = tcg_temp_new_i32();
5784 TCGv_i32 fp0 = tcg_temp_local_new_i32();
5785 int l1 = gen_new_label();
5786 int l2 = gen_new_label();
5789 ccbit1 = 1 << (24 + cc);
5790 ccbit2 = 1 << (25 + cc);
5801 gen_load_fpr32(fp0, fd);
5802 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit1);
5803 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5804 gen_load_fpr32(fp0, fs);
5806 gen_store_fpr32(fp0, fd);
5808 gen_load_fpr32h(fp0, fd);
5809 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit2);
5810 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l2);
5811 gen_load_fpr32h(fp0, fs);
5813 gen_store_fpr32h(fp0, fd);
5815 tcg_temp_free_i32(r_tmp1);
5816 tcg_temp_free_i32(fp0);
5820 static void gen_farith (DisasContext *ctx, uint32_t op1,
5821 int ft, int fs, int fd, int cc)
5823 const char *opn = "farith";
5824 const char *condnames[] = {
5842 const char *condnames_abs[] = {
5860 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5861 uint32_t func = ctx->opcode & 0x3f;
5863 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5866 TCGv_i32 fp0 = tcg_temp_new_i32();
5867 TCGv_i32 fp1 = tcg_temp_new_i32();
5869 gen_load_fpr32(fp0, fs);
5870 gen_load_fpr32(fp1, ft);
5871 gen_helper_float_add_s(fp0, fp0, fp1);
5872 tcg_temp_free_i32(fp1);
5873 gen_store_fpr32(fp0, fd);
5874 tcg_temp_free_i32(fp0);
5881 TCGv_i32 fp0 = tcg_temp_new_i32();
5882 TCGv_i32 fp1 = tcg_temp_new_i32();
5884 gen_load_fpr32(fp0, fs);
5885 gen_load_fpr32(fp1, ft);
5886 gen_helper_float_sub_s(fp0, fp0, fp1);
5887 tcg_temp_free_i32(fp1);
5888 gen_store_fpr32(fp0, fd);
5889 tcg_temp_free_i32(fp0);
5896 TCGv_i32 fp0 = tcg_temp_new_i32();
5897 TCGv_i32 fp1 = tcg_temp_new_i32();
5899 gen_load_fpr32(fp0, fs);
5900 gen_load_fpr32(fp1, ft);
5901 gen_helper_float_mul_s(fp0, fp0, fp1);
5902 tcg_temp_free_i32(fp1);
5903 gen_store_fpr32(fp0, fd);
5904 tcg_temp_free_i32(fp0);
5911 TCGv_i32 fp0 = tcg_temp_new_i32();
5912 TCGv_i32 fp1 = tcg_temp_new_i32();
5914 gen_load_fpr32(fp0, fs);
5915 gen_load_fpr32(fp1, ft);
5916 gen_helper_float_div_s(fp0, fp0, fp1);
5917 tcg_temp_free_i32(fp1);
5918 gen_store_fpr32(fp0, fd);
5919 tcg_temp_free_i32(fp0);
5926 TCGv_i32 fp0 = tcg_temp_new_i32();
5928 gen_load_fpr32(fp0, fs);
5929 gen_helper_float_sqrt_s(fp0, fp0);
5930 gen_store_fpr32(fp0, fd);
5931 tcg_temp_free_i32(fp0);
5937 TCGv_i32 fp0 = tcg_temp_new_i32();
5939 gen_load_fpr32(fp0, fs);
5940 gen_helper_float_abs_s(fp0, fp0);
5941 gen_store_fpr32(fp0, fd);
5942 tcg_temp_free_i32(fp0);
5948 TCGv_i32 fp0 = tcg_temp_new_i32();
5950 gen_load_fpr32(fp0, fs);
5951 gen_store_fpr32(fp0, fd);
5952 tcg_temp_free_i32(fp0);
5958 TCGv_i32 fp0 = tcg_temp_new_i32();
5960 gen_load_fpr32(fp0, fs);
5961 gen_helper_float_chs_s(fp0, fp0);
5962 gen_store_fpr32(fp0, fd);
5963 tcg_temp_free_i32(fp0);
5968 check_cp1_64bitmode(ctx);
5970 TCGv_i32 fp32 = tcg_temp_new_i32();
5971 TCGv_i64 fp64 = tcg_temp_new_i64();
5973 gen_load_fpr32(fp32, fs);
5974 gen_helper_float_roundl_s(fp64, fp32);
5975 tcg_temp_free_i32(fp32);
5976 gen_store_fpr64(ctx, fp64, fd);
5977 tcg_temp_free_i64(fp64);
5982 check_cp1_64bitmode(ctx);
5984 TCGv_i32 fp32 = tcg_temp_new_i32();
5985 TCGv_i64 fp64 = tcg_temp_new_i64();
5987 gen_load_fpr32(fp32, fs);
5988 gen_helper_float_truncl_s(fp64, fp32);
5989 tcg_temp_free_i32(fp32);
5990 gen_store_fpr64(ctx, fp64, fd);
5991 tcg_temp_free_i64(fp64);
5996 check_cp1_64bitmode(ctx);
5998 TCGv_i32 fp32 = tcg_temp_new_i32();
5999 TCGv_i64 fp64 = tcg_temp_new_i64();
6001 gen_load_fpr32(fp32, fs);
6002 gen_helper_float_ceill_s(fp64, fp32);
6003 tcg_temp_free_i32(fp32);
6004 gen_store_fpr64(ctx, fp64, fd);
6005 tcg_temp_free_i64(fp64);
6010 check_cp1_64bitmode(ctx);
6012 TCGv_i32 fp32 = tcg_temp_new_i32();
6013 TCGv_i64 fp64 = tcg_temp_new_i64();
6015 gen_load_fpr32(fp32, fs);
6016 gen_helper_float_floorl_s(fp64, fp32);
6017 tcg_temp_free_i32(fp32);
6018 gen_store_fpr64(ctx, fp64, fd);
6019 tcg_temp_free_i64(fp64);
6025 TCGv_i32 fp0 = tcg_temp_new_i32();
6027 gen_load_fpr32(fp0, fs);
6028 gen_helper_float_roundw_s(fp0, fp0);
6029 gen_store_fpr32(fp0, fd);
6030 tcg_temp_free_i32(fp0);
6036 TCGv_i32 fp0 = tcg_temp_new_i32();
6038 gen_load_fpr32(fp0, fs);
6039 gen_helper_float_truncw_s(fp0, fp0);
6040 gen_store_fpr32(fp0, fd);
6041 tcg_temp_free_i32(fp0);
6047 TCGv_i32 fp0 = tcg_temp_new_i32();
6049 gen_load_fpr32(fp0, fs);
6050 gen_helper_float_ceilw_s(fp0, fp0);
6051 gen_store_fpr32(fp0, fd);
6052 tcg_temp_free_i32(fp0);
6058 TCGv_i32 fp0 = tcg_temp_new_i32();
6060 gen_load_fpr32(fp0, fs);
6061 gen_helper_float_floorw_s(fp0, fp0);
6062 gen_store_fpr32(fp0, fd);
6063 tcg_temp_free_i32(fp0);
6068 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6073 int l1 = gen_new_label();
6074 TCGv t0 = tcg_temp_new();
6075 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6077 gen_load_gpr(t0, ft);
6078 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6079 gen_load_fpr32(fp0, fs);
6080 gen_store_fpr32(fp0, fd);
6081 tcg_temp_free_i32(fp0);
6089 int l1 = gen_new_label();
6090 TCGv t0 = tcg_temp_new();
6091 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6093 gen_load_gpr(t0, ft);
6094 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6095 gen_load_fpr32(fp0, fs);
6096 gen_store_fpr32(fp0, fd);
6097 tcg_temp_free_i32(fp0);
6106 TCGv_i32 fp0 = tcg_temp_new_i32();
6108 gen_load_fpr32(fp0, fs);
6109 gen_helper_float_recip_s(fp0, fp0);
6110 gen_store_fpr32(fp0, fd);
6111 tcg_temp_free_i32(fp0);
6118 TCGv_i32 fp0 = tcg_temp_new_i32();
6120 gen_load_fpr32(fp0, fs);
6121 gen_helper_float_rsqrt_s(fp0, fp0);
6122 gen_store_fpr32(fp0, fd);
6123 tcg_temp_free_i32(fp0);
6128 check_cp1_64bitmode(ctx);
6130 TCGv_i32 fp0 = tcg_temp_new_i32();
6131 TCGv_i32 fp1 = tcg_temp_new_i32();
6133 gen_load_fpr32(fp0, fs);
6134 gen_load_fpr32(fp1, fd);
6135 gen_helper_float_recip2_s(fp0, fp0, fp1);
6136 tcg_temp_free_i32(fp1);
6137 gen_store_fpr32(fp0, fd);
6138 tcg_temp_free_i32(fp0);
6143 check_cp1_64bitmode(ctx);
6145 TCGv_i32 fp0 = tcg_temp_new_i32();
6147 gen_load_fpr32(fp0, fs);
6148 gen_helper_float_recip1_s(fp0, fp0);
6149 gen_store_fpr32(fp0, fd);
6150 tcg_temp_free_i32(fp0);
6155 check_cp1_64bitmode(ctx);
6157 TCGv_i32 fp0 = tcg_temp_new_i32();
6159 gen_load_fpr32(fp0, fs);
6160 gen_helper_float_rsqrt1_s(fp0, fp0);
6161 gen_store_fpr32(fp0, fd);
6162 tcg_temp_free_i32(fp0);
6167 check_cp1_64bitmode(ctx);
6169 TCGv_i32 fp0 = tcg_temp_new_i32();
6170 TCGv_i32 fp1 = tcg_temp_new_i32();
6172 gen_load_fpr32(fp0, fs);
6173 gen_load_fpr32(fp1, ft);
6174 gen_helper_float_rsqrt2_s(fp0, fp0, fp1);
6175 tcg_temp_free_i32(fp1);
6176 gen_store_fpr32(fp0, fd);
6177 tcg_temp_free_i32(fp0);
6182 check_cp1_registers(ctx, fd);
6184 TCGv_i32 fp32 = tcg_temp_new_i32();
6185 TCGv_i64 fp64 = tcg_temp_new_i64();
6187 gen_load_fpr32(fp32, fs);
6188 gen_helper_float_cvtd_s(fp64, fp32);
6189 tcg_temp_free_i32(fp32);
6190 gen_store_fpr64(ctx, fp64, fd);
6191 tcg_temp_free_i64(fp64);
6197 TCGv_i32 fp0 = tcg_temp_new_i32();
6199 gen_load_fpr32(fp0, fs);
6200 gen_helper_float_cvtw_s(fp0, fp0);
6201 gen_store_fpr32(fp0, fd);
6202 tcg_temp_free_i32(fp0);
6207 check_cp1_64bitmode(ctx);
6209 TCGv_i32 fp32 = tcg_temp_new_i32();
6210 TCGv_i64 fp64 = tcg_temp_new_i64();
6212 gen_load_fpr32(fp32, fs);
6213 gen_helper_float_cvtl_s(fp64, fp32);
6214 tcg_temp_free_i32(fp32);
6215 gen_store_fpr64(ctx, fp64, fd);
6216 tcg_temp_free_i64(fp64);
6221 check_cp1_64bitmode(ctx);
6223 TCGv_i64 fp64 = tcg_temp_new_i64();
6224 TCGv_i32 fp32_0 = tcg_temp_new_i32();
6225 TCGv_i32 fp32_1 = tcg_temp_new_i32();
6227 gen_load_fpr32(fp32_0, fs);
6228 gen_load_fpr32(fp32_1, ft);
6229 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6230 tcg_temp_free_i32(fp32_1);
6231 tcg_temp_free_i32(fp32_0);
6232 gen_store_fpr64(ctx, fp64, fd);
6233 tcg_temp_free_i64(fp64);
6254 TCGv_i32 fp0 = tcg_temp_new_i32();
6255 TCGv_i32 fp1 = tcg_temp_new_i32();
6257 gen_load_fpr32(fp0, fs);
6258 gen_load_fpr32(fp1, ft);
6259 if (ctx->opcode & (1 << 6)) {
6261 gen_cmpabs_s(func-48, fp0, fp1, cc);
6262 opn = condnames_abs[func-48];
6264 gen_cmp_s(func-48, fp0, fp1, cc);
6265 opn = condnames[func-48];
6267 tcg_temp_free_i32(fp0);
6268 tcg_temp_free_i32(fp1);
6272 check_cp1_registers(ctx, fs | ft | fd);
6274 TCGv_i64 fp0 = tcg_temp_new_i64();
6275 TCGv_i64 fp1 = tcg_temp_new_i64();
6277 gen_load_fpr64(ctx, fp0, fs);
6278 gen_load_fpr64(ctx, fp1, ft);
6279 gen_helper_float_add_d(fp0, fp0, fp1);
6280 tcg_temp_free_i64(fp1);
6281 gen_store_fpr64(ctx, fp0, fd);
6282 tcg_temp_free_i64(fp0);
6288 check_cp1_registers(ctx, fs | ft | fd);
6290 TCGv_i64 fp0 = tcg_temp_new_i64();
6291 TCGv_i64 fp1 = tcg_temp_new_i64();
6293 gen_load_fpr64(ctx, fp0, fs);
6294 gen_load_fpr64(ctx, fp1, ft);
6295 gen_helper_float_sub_d(fp0, fp0, fp1);
6296 tcg_temp_free_i64(fp1);
6297 gen_store_fpr64(ctx, fp0, fd);
6298 tcg_temp_free_i64(fp0);
6304 check_cp1_registers(ctx, fs | ft | fd);
6306 TCGv_i64 fp0 = tcg_temp_new_i64();
6307 TCGv_i64 fp1 = tcg_temp_new_i64();
6309 gen_load_fpr64(ctx, fp0, fs);
6310 gen_load_fpr64(ctx, fp1, ft);
6311 gen_helper_float_mul_d(fp0, fp0, fp1);
6312 tcg_temp_free_i64(fp1);
6313 gen_store_fpr64(ctx, fp0, fd);
6314 tcg_temp_free_i64(fp0);
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_div_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 | fd);
6338 TCGv_i64 fp0 = tcg_temp_new_i64();
6340 gen_load_fpr64(ctx, fp0, fs);
6341 gen_helper_float_sqrt_d(fp0, fp0);
6342 gen_store_fpr64(ctx, fp0, fd);
6343 tcg_temp_free_i64(fp0);
6348 check_cp1_registers(ctx, fs | fd);
6350 TCGv_i64 fp0 = tcg_temp_new_i64();
6352 gen_load_fpr64(ctx, fp0, fs);
6353 gen_helper_float_abs_d(fp0, fp0);
6354 gen_store_fpr64(ctx, fp0, fd);
6355 tcg_temp_free_i64(fp0);
6360 check_cp1_registers(ctx, fs | fd);
6362 TCGv_i64 fp0 = tcg_temp_new_i64();
6364 gen_load_fpr64(ctx, fp0, fs);
6365 gen_store_fpr64(ctx, fp0, fd);
6366 tcg_temp_free_i64(fp0);
6371 check_cp1_registers(ctx, fs | fd);
6373 TCGv_i64 fp0 = tcg_temp_new_i64();
6375 gen_load_fpr64(ctx, fp0, fs);
6376 gen_helper_float_chs_d(fp0, fp0);
6377 gen_store_fpr64(ctx, fp0, fd);
6378 tcg_temp_free_i64(fp0);
6383 check_cp1_64bitmode(ctx);
6385 TCGv_i64 fp0 = tcg_temp_new_i64();
6387 gen_load_fpr64(ctx, fp0, fs);
6388 gen_helper_float_roundl_d(fp0, fp0);
6389 gen_store_fpr64(ctx, fp0, fd);
6390 tcg_temp_free_i64(fp0);
6395 check_cp1_64bitmode(ctx);
6397 TCGv_i64 fp0 = tcg_temp_new_i64();
6399 gen_load_fpr64(ctx, fp0, fs);
6400 gen_helper_float_truncl_d(fp0, fp0);
6401 gen_store_fpr64(ctx, fp0, fd);
6402 tcg_temp_free_i64(fp0);
6407 check_cp1_64bitmode(ctx);
6409 TCGv_i64 fp0 = tcg_temp_new_i64();
6411 gen_load_fpr64(ctx, fp0, fs);
6412 gen_helper_float_ceill_d(fp0, fp0);
6413 gen_store_fpr64(ctx, fp0, fd);
6414 tcg_temp_free_i64(fp0);
6419 check_cp1_64bitmode(ctx);
6421 TCGv_i64 fp0 = tcg_temp_new_i64();
6423 gen_load_fpr64(ctx, fp0, fs);
6424 gen_helper_float_floorl_d(fp0, fp0);
6425 gen_store_fpr64(ctx, fp0, fd);
6426 tcg_temp_free_i64(fp0);
6431 check_cp1_registers(ctx, fs);
6433 TCGv_i32 fp32 = tcg_temp_new_i32();
6434 TCGv_i64 fp64 = tcg_temp_new_i64();
6436 gen_load_fpr64(ctx, fp64, fs);
6437 gen_helper_float_roundw_d(fp32, fp64);
6438 tcg_temp_free_i64(fp64);
6439 gen_store_fpr32(fp32, fd);
6440 tcg_temp_free_i32(fp32);
6445 check_cp1_registers(ctx, fs);
6447 TCGv_i32 fp32 = tcg_temp_new_i32();
6448 TCGv_i64 fp64 = tcg_temp_new_i64();
6450 gen_load_fpr64(ctx, fp64, fs);
6451 gen_helper_float_truncw_d(fp32, fp64);
6452 tcg_temp_free_i64(fp64);
6453 gen_store_fpr32(fp32, fd);
6454 tcg_temp_free_i32(fp32);
6459 check_cp1_registers(ctx, fs);
6461 TCGv_i32 fp32 = tcg_temp_new_i32();
6462 TCGv_i64 fp64 = tcg_temp_new_i64();
6464 gen_load_fpr64(ctx, fp64, fs);
6465 gen_helper_float_ceilw_d(fp32, fp64);
6466 tcg_temp_free_i64(fp64);
6467 gen_store_fpr32(fp32, fd);
6468 tcg_temp_free_i32(fp32);
6473 check_cp1_registers(ctx, fs);
6475 TCGv_i32 fp32 = tcg_temp_new_i32();
6476 TCGv_i64 fp64 = tcg_temp_new_i64();
6478 gen_load_fpr64(ctx, fp64, fs);
6479 gen_helper_float_floorw_d(fp32, fp64);
6480 tcg_temp_free_i64(fp64);
6481 gen_store_fpr32(fp32, fd);
6482 tcg_temp_free_i32(fp32);
6487 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6492 int l1 = gen_new_label();
6493 TCGv t0 = tcg_temp_new();
6494 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6496 gen_load_gpr(t0, ft);
6497 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6498 gen_load_fpr64(ctx, fp0, fs);
6499 gen_store_fpr64(ctx, fp0, fd);
6500 tcg_temp_free_i64(fp0);
6508 int l1 = gen_new_label();
6509 TCGv t0 = tcg_temp_new();
6510 TCGv_i64 fp0 = tcg_temp_local_new_i64();
6512 gen_load_gpr(t0, ft);
6513 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6514 gen_load_fpr64(ctx, fp0, fs);
6515 gen_store_fpr64(ctx, fp0, fd);
6516 tcg_temp_free_i64(fp0);
6523 check_cp1_64bitmode(ctx);
6525 TCGv_i64 fp0 = tcg_temp_new_i64();
6527 gen_load_fpr64(ctx, fp0, fs);
6528 gen_helper_float_recip_d(fp0, fp0);
6529 gen_store_fpr64(ctx, fp0, fd);
6530 tcg_temp_free_i64(fp0);
6535 check_cp1_64bitmode(ctx);
6537 TCGv_i64 fp0 = tcg_temp_new_i64();
6539 gen_load_fpr64(ctx, fp0, fs);
6540 gen_helper_float_rsqrt_d(fp0, fp0);
6541 gen_store_fpr64(ctx, fp0, fd);
6542 tcg_temp_free_i64(fp0);
6547 check_cp1_64bitmode(ctx);
6549 TCGv_i64 fp0 = tcg_temp_new_i64();
6550 TCGv_i64 fp1 = tcg_temp_new_i64();
6552 gen_load_fpr64(ctx, fp0, fs);
6553 gen_load_fpr64(ctx, fp1, ft);
6554 gen_helper_float_recip2_d(fp0, fp0, fp1);
6555 tcg_temp_free_i64(fp1);
6556 gen_store_fpr64(ctx, fp0, fd);
6557 tcg_temp_free_i64(fp0);
6562 check_cp1_64bitmode(ctx);
6564 TCGv_i64 fp0 = tcg_temp_new_i64();
6566 gen_load_fpr64(ctx, fp0, fs);
6567 gen_helper_float_recip1_d(fp0, fp0);
6568 gen_store_fpr64(ctx, fp0, fd);
6569 tcg_temp_free_i64(fp0);
6574 check_cp1_64bitmode(ctx);
6576 TCGv_i64 fp0 = tcg_temp_new_i64();
6578 gen_load_fpr64(ctx, fp0, fs);
6579 gen_helper_float_rsqrt1_d(fp0, fp0);
6580 gen_store_fpr64(ctx, fp0, fd);
6581 tcg_temp_free_i64(fp0);
6586 check_cp1_64bitmode(ctx);
6588 TCGv_i64 fp0 = tcg_temp_new_i64();
6589 TCGv_i64 fp1 = tcg_temp_new_i64();
6591 gen_load_fpr64(ctx, fp0, fs);
6592 gen_load_fpr64(ctx, fp1, ft);
6593 gen_helper_float_rsqrt2_d(fp0, fp0, fp1);
6594 tcg_temp_free_i64(fp1);
6595 gen_store_fpr64(ctx, fp0, fd);
6596 tcg_temp_free_i64(fp0);
6617 TCGv_i64 fp0 = tcg_temp_new_i64();
6618 TCGv_i64 fp1 = tcg_temp_new_i64();
6620 gen_load_fpr64(ctx, fp0, fs);
6621 gen_load_fpr64(ctx, fp1, ft);
6622 if (ctx->opcode & (1 << 6)) {
6624 check_cp1_registers(ctx, fs | ft);
6625 gen_cmpabs_d(func-48, fp0, fp1, cc);
6626 opn = condnames_abs[func-48];
6628 check_cp1_registers(ctx, fs | ft);
6629 gen_cmp_d(func-48, fp0, fp1, cc);
6630 opn = condnames[func-48];
6632 tcg_temp_free_i64(fp0);
6633 tcg_temp_free_i64(fp1);
6637 check_cp1_registers(ctx, fs);
6639 TCGv_i32 fp32 = tcg_temp_new_i32();
6640 TCGv_i64 fp64 = tcg_temp_new_i64();
6642 gen_load_fpr64(ctx, fp64, fs);
6643 gen_helper_float_cvts_d(fp32, fp64);
6644 tcg_temp_free_i64(fp64);
6645 gen_store_fpr32(fp32, fd);
6646 tcg_temp_free_i32(fp32);
6651 check_cp1_registers(ctx, fs);
6653 TCGv_i32 fp32 = tcg_temp_new_i32();
6654 TCGv_i64 fp64 = tcg_temp_new_i64();
6656 gen_load_fpr64(ctx, fp64, fs);
6657 gen_helper_float_cvtw_d(fp32, fp64);
6658 tcg_temp_free_i64(fp64);
6659 gen_store_fpr32(fp32, fd);
6660 tcg_temp_free_i32(fp32);
6665 check_cp1_64bitmode(ctx);
6667 TCGv_i64 fp0 = tcg_temp_new_i64();
6669 gen_load_fpr64(ctx, fp0, fs);
6670 gen_helper_float_cvtl_d(fp0, fp0);
6671 gen_store_fpr64(ctx, fp0, fd);
6672 tcg_temp_free_i64(fp0);
6678 TCGv_i32 fp0 = tcg_temp_new_i32();
6680 gen_load_fpr32(fp0, fs);
6681 gen_helper_float_cvts_w(fp0, fp0);
6682 gen_store_fpr32(fp0, fd);
6683 tcg_temp_free_i32(fp0);
6688 check_cp1_registers(ctx, fd);
6690 TCGv_i32 fp32 = tcg_temp_new_i32();
6691 TCGv_i64 fp64 = tcg_temp_new_i64();
6693 gen_load_fpr32(fp32, fs);
6694 gen_helper_float_cvtd_w(fp64, fp32);
6695 tcg_temp_free_i32(fp32);
6696 gen_store_fpr64(ctx, fp64, fd);
6697 tcg_temp_free_i64(fp64);
6702 check_cp1_64bitmode(ctx);
6704 TCGv_i32 fp32 = tcg_temp_new_i32();
6705 TCGv_i64 fp64 = tcg_temp_new_i64();
6707 gen_load_fpr64(ctx, fp64, fs);
6708 gen_helper_float_cvts_l(fp32, fp64);
6709 tcg_temp_free_i64(fp64);
6710 gen_store_fpr32(fp32, fd);
6711 tcg_temp_free_i32(fp32);
6716 check_cp1_64bitmode(ctx);
6718 TCGv_i64 fp0 = tcg_temp_new_i64();
6720 gen_load_fpr64(ctx, fp0, fs);
6721 gen_helper_float_cvtd_l(fp0, fp0);
6722 gen_store_fpr64(ctx, fp0, fd);
6723 tcg_temp_free_i64(fp0);
6728 check_cp1_64bitmode(ctx);
6730 TCGv_i64 fp0 = tcg_temp_new_i64();
6732 gen_load_fpr64(ctx, fp0, fs);
6733 gen_helper_float_cvtps_pw(fp0, fp0);
6734 gen_store_fpr64(ctx, fp0, fd);
6735 tcg_temp_free_i64(fp0);
6740 check_cp1_64bitmode(ctx);
6742 TCGv_i64 fp0 = tcg_temp_new_i64();
6743 TCGv_i64 fp1 = tcg_temp_new_i64();
6745 gen_load_fpr64(ctx, fp0, fs);
6746 gen_load_fpr64(ctx, fp1, ft);
6747 gen_helper_float_add_ps(fp0, fp0, fp1);
6748 tcg_temp_free_i64(fp1);
6749 gen_store_fpr64(ctx, fp0, fd);
6750 tcg_temp_free_i64(fp0);
6755 check_cp1_64bitmode(ctx);
6757 TCGv_i64 fp0 = tcg_temp_new_i64();
6758 TCGv_i64 fp1 = tcg_temp_new_i64();
6760 gen_load_fpr64(ctx, fp0, fs);
6761 gen_load_fpr64(ctx, fp1, ft);
6762 gen_helper_float_sub_ps(fp0, fp0, fp1);
6763 tcg_temp_free_i64(fp1);
6764 gen_store_fpr64(ctx, fp0, fd);
6765 tcg_temp_free_i64(fp0);
6770 check_cp1_64bitmode(ctx);
6772 TCGv_i64 fp0 = tcg_temp_new_i64();
6773 TCGv_i64 fp1 = tcg_temp_new_i64();
6775 gen_load_fpr64(ctx, fp0, fs);
6776 gen_load_fpr64(ctx, fp1, ft);
6777 gen_helper_float_mul_ps(fp0, fp0, fp1);
6778 tcg_temp_free_i64(fp1);
6779 gen_store_fpr64(ctx, fp0, fd);
6780 tcg_temp_free_i64(fp0);
6785 check_cp1_64bitmode(ctx);
6787 TCGv_i64 fp0 = tcg_temp_new_i64();
6789 gen_load_fpr64(ctx, fp0, fs);
6790 gen_helper_float_abs_ps(fp0, fp0);
6791 gen_store_fpr64(ctx, fp0, fd);
6792 tcg_temp_free_i64(fp0);
6797 check_cp1_64bitmode(ctx);
6799 TCGv_i64 fp0 = tcg_temp_new_i64();
6801 gen_load_fpr64(ctx, fp0, fs);
6802 gen_store_fpr64(ctx, fp0, fd);
6803 tcg_temp_free_i64(fp0);
6808 check_cp1_64bitmode(ctx);
6810 TCGv_i64 fp0 = tcg_temp_new_i64();
6812 gen_load_fpr64(ctx, fp0, fs);
6813 gen_helper_float_chs_ps(fp0, fp0);
6814 gen_store_fpr64(ctx, fp0, fd);
6815 tcg_temp_free_i64(fp0);
6820 check_cp1_64bitmode(ctx);
6821 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6825 check_cp1_64bitmode(ctx);
6827 int l1 = gen_new_label();
6828 TCGv t0 = tcg_temp_new();
6829 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6830 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6832 gen_load_gpr(t0, ft);
6833 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6834 gen_load_fpr32(fp0, fs);
6835 gen_load_fpr32h(fph0, fs);
6836 gen_store_fpr32(fp0, fd);
6837 gen_store_fpr32h(fph0, fd);
6838 tcg_temp_free_i32(fp0);
6839 tcg_temp_free_i32(fph0);
6846 check_cp1_64bitmode(ctx);
6848 int l1 = gen_new_label();
6849 TCGv t0 = tcg_temp_new();
6850 TCGv_i32 fp0 = tcg_temp_local_new_i32();
6851 TCGv_i32 fph0 = tcg_temp_local_new_i32();
6853 gen_load_gpr(t0, ft);
6854 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6855 gen_load_fpr32(fp0, fs);
6856 gen_load_fpr32h(fph0, fs);
6857 gen_store_fpr32(fp0, fd);
6858 gen_store_fpr32h(fph0, fd);
6859 tcg_temp_free_i32(fp0);
6860 tcg_temp_free_i32(fph0);
6867 check_cp1_64bitmode(ctx);
6869 TCGv_i64 fp0 = tcg_temp_new_i64();
6870 TCGv_i64 fp1 = tcg_temp_new_i64();
6872 gen_load_fpr64(ctx, fp0, ft);
6873 gen_load_fpr64(ctx, fp1, fs);
6874 gen_helper_float_addr_ps(fp0, fp0, fp1);
6875 tcg_temp_free_i64(fp1);
6876 gen_store_fpr64(ctx, fp0, fd);
6877 tcg_temp_free_i64(fp0);
6882 check_cp1_64bitmode(ctx);
6884 TCGv_i64 fp0 = tcg_temp_new_i64();
6885 TCGv_i64 fp1 = tcg_temp_new_i64();
6887 gen_load_fpr64(ctx, fp0, ft);
6888 gen_load_fpr64(ctx, fp1, fs);
6889 gen_helper_float_mulr_ps(fp0, fp0, fp1);
6890 tcg_temp_free_i64(fp1);
6891 gen_store_fpr64(ctx, fp0, fd);
6892 tcg_temp_free_i64(fp0);
6897 check_cp1_64bitmode(ctx);
6899 TCGv_i64 fp0 = tcg_temp_new_i64();
6900 TCGv_i64 fp1 = tcg_temp_new_i64();
6902 gen_load_fpr64(ctx, fp0, fs);
6903 gen_load_fpr64(ctx, fp1, fd);
6904 gen_helper_float_recip2_ps(fp0, fp0, fp1);
6905 tcg_temp_free_i64(fp1);
6906 gen_store_fpr64(ctx, fp0, fd);
6907 tcg_temp_free_i64(fp0);
6912 check_cp1_64bitmode(ctx);
6914 TCGv_i64 fp0 = tcg_temp_new_i64();
6916 gen_load_fpr64(ctx, fp0, fs);
6917 gen_helper_float_recip1_ps(fp0, fp0);
6918 gen_store_fpr64(ctx, fp0, fd);
6919 tcg_temp_free_i64(fp0);
6924 check_cp1_64bitmode(ctx);
6926 TCGv_i64 fp0 = tcg_temp_new_i64();
6928 gen_load_fpr64(ctx, fp0, fs);
6929 gen_helper_float_rsqrt1_ps(fp0, fp0);
6930 gen_store_fpr64(ctx, fp0, fd);
6931 tcg_temp_free_i64(fp0);
6936 check_cp1_64bitmode(ctx);
6938 TCGv_i64 fp0 = tcg_temp_new_i64();
6939 TCGv_i64 fp1 = tcg_temp_new_i64();
6941 gen_load_fpr64(ctx, fp0, fs);
6942 gen_load_fpr64(ctx, fp1, ft);
6943 gen_helper_float_rsqrt2_ps(fp0, fp0, fp1);
6944 tcg_temp_free_i64(fp1);
6945 gen_store_fpr64(ctx, fp0, fd);
6946 tcg_temp_free_i64(fp0);
6951 check_cp1_64bitmode(ctx);
6953 TCGv_i32 fp0 = tcg_temp_new_i32();
6955 gen_load_fpr32h(fp0, fs);
6956 gen_helper_float_cvts_pu(fp0, fp0);
6957 gen_store_fpr32(fp0, fd);
6958 tcg_temp_free_i32(fp0);
6963 check_cp1_64bitmode(ctx);
6965 TCGv_i64 fp0 = tcg_temp_new_i64();
6967 gen_load_fpr64(ctx, fp0, fs);
6968 gen_helper_float_cvtpw_ps(fp0, fp0);
6969 gen_store_fpr64(ctx, fp0, fd);
6970 tcg_temp_free_i64(fp0);
6975 check_cp1_64bitmode(ctx);
6977 TCGv_i32 fp0 = tcg_temp_new_i32();
6979 gen_load_fpr32(fp0, fs);
6980 gen_helper_float_cvts_pl(fp0, fp0);
6981 gen_store_fpr32(fp0, fd);
6982 tcg_temp_free_i32(fp0);
6987 check_cp1_64bitmode(ctx);
6989 TCGv_i32 fp0 = tcg_temp_new_i32();
6990 TCGv_i32 fp1 = tcg_temp_new_i32();
6992 gen_load_fpr32(fp0, fs);
6993 gen_load_fpr32(fp1, ft);
6994 gen_store_fpr32h(fp0, fd);
6995 gen_store_fpr32(fp1, fd);
6996 tcg_temp_free_i32(fp0);
6997 tcg_temp_free_i32(fp1);
7002 check_cp1_64bitmode(ctx);
7004 TCGv_i32 fp0 = tcg_temp_new_i32();
7005 TCGv_i32 fp1 = tcg_temp_new_i32();
7007 gen_load_fpr32(fp0, fs);
7008 gen_load_fpr32h(fp1, ft);
7009 gen_store_fpr32(fp1, fd);
7010 gen_store_fpr32h(fp0, fd);
7011 tcg_temp_free_i32(fp0);
7012 tcg_temp_free_i32(fp1);
7017 check_cp1_64bitmode(ctx);
7019 TCGv_i32 fp0 = tcg_temp_new_i32();
7020 TCGv_i32 fp1 = tcg_temp_new_i32();
7022 gen_load_fpr32h(fp0, fs);
7023 gen_load_fpr32(fp1, ft);
7024 gen_store_fpr32(fp1, fd);
7025 gen_store_fpr32h(fp0, fd);
7026 tcg_temp_free_i32(fp0);
7027 tcg_temp_free_i32(fp1);
7032 check_cp1_64bitmode(ctx);
7034 TCGv_i32 fp0 = tcg_temp_new_i32();
7035 TCGv_i32 fp1 = tcg_temp_new_i32();
7037 gen_load_fpr32h(fp0, fs);
7038 gen_load_fpr32h(fp1, ft);
7039 gen_store_fpr32(fp1, fd);
7040 gen_store_fpr32h(fp0, fd);
7041 tcg_temp_free_i32(fp0);
7042 tcg_temp_free_i32(fp1);
7062 check_cp1_64bitmode(ctx);
7064 TCGv_i64 fp0 = tcg_temp_new_i64();
7065 TCGv_i64 fp1 = tcg_temp_new_i64();
7067 gen_load_fpr64(ctx, fp0, fs);
7068 gen_load_fpr64(ctx, fp1, ft);
7069 if (ctx->opcode & (1 << 6)) {
7070 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7071 opn = condnames_abs[func-48];
7073 gen_cmp_ps(func-48, fp0, fp1, cc);
7074 opn = condnames[func-48];
7076 tcg_temp_free_i64(fp0);
7077 tcg_temp_free_i64(fp1);
7082 generate_exception (ctx, EXCP_RI);
7087 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7090 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7093 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7098 /* Coprocessor 3 (FPU) */
7099 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7100 int fd, int fs, int base, int index)
7102 const char *opn = "extended float load/store";
7104 TCGv t0 = tcg_temp_local_new();
7105 TCGv t1 = tcg_temp_local_new();
7108 gen_load_gpr(t0, index);
7109 } else if (index == 0) {
7110 gen_load_gpr(t0, base);
7112 gen_load_gpr(t0, index);
7113 gen_op_addr_add(ctx, t0, cpu_gpr[base]);
7115 /* Don't do NOP if destination is zero: we must perform the actual
7121 TCGv_i32 fp0 = tcg_temp_new_i32();
7123 tcg_gen_qemu_ld32s(t1, t0, ctx->mem_idx);
7124 tcg_gen_trunc_tl_i32(fp0, t1);
7125 gen_store_fpr32(fp0, fd);
7126 tcg_temp_free_i32(fp0);
7132 check_cp1_registers(ctx, fd);
7134 TCGv_i64 fp0 = tcg_temp_new_i64();
7136 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7137 gen_store_fpr64(ctx, fp0, fd);
7138 tcg_temp_free_i64(fp0);
7143 check_cp1_64bitmode(ctx);
7144 tcg_gen_andi_tl(t0, t0, ~0x7);
7146 TCGv_i64 fp0 = tcg_temp_new_i64();
7148 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7149 gen_store_fpr64(ctx, fp0, fd);
7150 tcg_temp_free_i64(fp0);
7157 TCGv_i32 fp0 = tcg_temp_new_i32();
7159 gen_load_fpr32(fp0, fs);
7160 tcg_gen_extu_i32_tl(t1, fp0);
7161 tcg_gen_qemu_st32(t1, t0, ctx->mem_idx);
7162 tcg_temp_free_i32(fp0);
7169 check_cp1_registers(ctx, fs);
7171 TCGv_i64 fp0 = tcg_temp_new_i64();
7173 gen_load_fpr64(ctx, fp0, fs);
7174 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7175 tcg_temp_free_i64(fp0);
7181 check_cp1_64bitmode(ctx);
7182 tcg_gen_andi_tl(t0, t0, ~0x7);
7184 TCGv_i64 fp0 = tcg_temp_new_i64();
7186 gen_load_fpr64(ctx, fp0, fs);
7187 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7188 tcg_temp_free_i64(fp0);
7195 generate_exception(ctx, EXCP_RI);
7202 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7203 regnames[index], regnames[base]);
7206 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7207 int fd, int fr, int fs, int ft)
7209 const char *opn = "flt3_arith";
7213 check_cp1_64bitmode(ctx);
7215 TCGv t0 = tcg_temp_local_new();
7216 TCGv_i32 fp0 = tcg_temp_local_new_i32();
7217 TCGv_i32 fph0 = tcg_temp_local_new_i32();
7218 TCGv_i32 fp1 = tcg_temp_local_new_i32();
7219 TCGv_i32 fph1 = tcg_temp_local_new_i32();
7220 int l1 = gen_new_label();
7221 int l2 = gen_new_label();
7223 gen_load_gpr(t0, fr);
7224 tcg_gen_andi_tl(t0, t0, 0x7);
7225 gen_load_fpr32(fp0, fs);
7226 gen_load_fpr32h(fph0, fs);
7227 gen_load_fpr32(fp1, ft);
7228 gen_load_fpr32h(fph1, ft);
7230 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7231 gen_store_fpr32(fp0, fd);
7232 gen_store_fpr32h(fph0, fd);
7235 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7237 #ifdef TARGET_WORDS_BIGENDIAN
7238 gen_store_fpr32(fph1, fd);
7239 gen_store_fpr32h(fp0, fd);
7241 gen_store_fpr32(fph0, fd);
7242 gen_store_fpr32h(fp1, fd);
7245 tcg_temp_free_i32(fp0);
7246 tcg_temp_free_i32(fph0);
7247 tcg_temp_free_i32(fp1);
7248 tcg_temp_free_i32(fph1);
7255 TCGv_i32 fp0 = tcg_temp_new_i32();
7256 TCGv_i32 fp1 = tcg_temp_new_i32();
7257 TCGv_i32 fp2 = tcg_temp_new_i32();
7259 gen_load_fpr32(fp0, fs);
7260 gen_load_fpr32(fp1, ft);
7261 gen_load_fpr32(fp2, fr);
7262 gen_helper_float_muladd_s(fp2, fp0, fp1, fp2);
7263 tcg_temp_free_i32(fp0);
7264 tcg_temp_free_i32(fp1);
7265 gen_store_fpr32(fp2, fd);
7266 tcg_temp_free_i32(fp2);
7272 check_cp1_registers(ctx, fd | fs | ft | fr);
7274 TCGv_i64 fp0 = tcg_temp_new_i64();
7275 TCGv_i64 fp1 = tcg_temp_new_i64();
7276 TCGv_i64 fp2 = tcg_temp_new_i64();
7278 gen_load_fpr64(ctx, fp0, fs);
7279 gen_load_fpr64(ctx, fp1, ft);
7280 gen_load_fpr64(ctx, fp2, fr);
7281 gen_helper_float_muladd_d(fp2, fp0, fp1, fp2);
7282 tcg_temp_free_i64(fp0);
7283 tcg_temp_free_i64(fp1);
7284 gen_store_fpr64(ctx, fp2, fd);
7285 tcg_temp_free_i64(fp2);
7290 check_cp1_64bitmode(ctx);
7292 TCGv_i64 fp0 = tcg_temp_new_i64();
7293 TCGv_i64 fp1 = tcg_temp_new_i64();
7294 TCGv_i64 fp2 = tcg_temp_new_i64();
7296 gen_load_fpr64(ctx, fp0, fs);
7297 gen_load_fpr64(ctx, fp1, ft);
7298 gen_load_fpr64(ctx, fp2, fr);
7299 gen_helper_float_muladd_ps(fp2, fp0, fp1, fp2);
7300 tcg_temp_free_i64(fp0);
7301 tcg_temp_free_i64(fp1);
7302 gen_store_fpr64(ctx, fp2, fd);
7303 tcg_temp_free_i64(fp2);
7310 TCGv_i32 fp0 = tcg_temp_new_i32();
7311 TCGv_i32 fp1 = tcg_temp_new_i32();
7312 TCGv_i32 fp2 = tcg_temp_new_i32();
7314 gen_load_fpr32(fp0, fs);
7315 gen_load_fpr32(fp1, ft);
7316 gen_load_fpr32(fp2, fr);
7317 gen_helper_float_mulsub_s(fp2, fp0, fp1, fp2);
7318 tcg_temp_free_i32(fp0);
7319 tcg_temp_free_i32(fp1);
7320 gen_store_fpr32(fp2, fd);
7321 tcg_temp_free_i32(fp2);
7327 check_cp1_registers(ctx, fd | fs | ft | fr);
7329 TCGv_i64 fp0 = tcg_temp_new_i64();
7330 TCGv_i64 fp1 = tcg_temp_new_i64();
7331 TCGv_i64 fp2 = tcg_temp_new_i64();
7333 gen_load_fpr64(ctx, fp0, fs);
7334 gen_load_fpr64(ctx, fp1, ft);
7335 gen_load_fpr64(ctx, fp2, fr);
7336 gen_helper_float_mulsub_d(fp2, fp0, fp1, fp2);
7337 tcg_temp_free_i64(fp0);
7338 tcg_temp_free_i64(fp1);
7339 gen_store_fpr64(ctx, fp2, fd);
7340 tcg_temp_free_i64(fp2);
7345 check_cp1_64bitmode(ctx);
7347 TCGv_i64 fp0 = tcg_temp_new_i64();
7348 TCGv_i64 fp1 = tcg_temp_new_i64();
7349 TCGv_i64 fp2 = tcg_temp_new_i64();
7351 gen_load_fpr64(ctx, fp0, fs);
7352 gen_load_fpr64(ctx, fp1, ft);
7353 gen_load_fpr64(ctx, fp2, fr);
7354 gen_helper_float_mulsub_ps(fp2, fp0, fp1, fp2);
7355 tcg_temp_free_i64(fp0);
7356 tcg_temp_free_i64(fp1);
7357 gen_store_fpr64(ctx, fp2, fd);
7358 tcg_temp_free_i64(fp2);
7365 TCGv_i32 fp0 = tcg_temp_new_i32();
7366 TCGv_i32 fp1 = tcg_temp_new_i32();
7367 TCGv_i32 fp2 = tcg_temp_new_i32();
7369 gen_load_fpr32(fp0, fs);
7370 gen_load_fpr32(fp1, ft);
7371 gen_load_fpr32(fp2, fr);
7372 gen_helper_float_nmuladd_s(fp2, fp0, fp1, fp2);
7373 tcg_temp_free_i32(fp0);
7374 tcg_temp_free_i32(fp1);
7375 gen_store_fpr32(fp2, fd);
7376 tcg_temp_free_i32(fp2);
7382 check_cp1_registers(ctx, fd | fs | ft | fr);
7384 TCGv_i64 fp0 = tcg_temp_new_i64();
7385 TCGv_i64 fp1 = tcg_temp_new_i64();
7386 TCGv_i64 fp2 = tcg_temp_new_i64();
7388 gen_load_fpr64(ctx, fp0, fs);
7389 gen_load_fpr64(ctx, fp1, ft);
7390 gen_load_fpr64(ctx, fp2, fr);
7391 gen_helper_float_nmuladd_d(fp2, fp0, fp1, fp2);
7392 tcg_temp_free_i64(fp0);
7393 tcg_temp_free_i64(fp1);
7394 gen_store_fpr64(ctx, fp2, fd);
7395 tcg_temp_free_i64(fp2);
7400 check_cp1_64bitmode(ctx);
7402 TCGv_i64 fp0 = tcg_temp_new_i64();
7403 TCGv_i64 fp1 = tcg_temp_new_i64();
7404 TCGv_i64 fp2 = tcg_temp_new_i64();
7406 gen_load_fpr64(ctx, fp0, fs);
7407 gen_load_fpr64(ctx, fp1, ft);
7408 gen_load_fpr64(ctx, fp2, fr);
7409 gen_helper_float_nmuladd_ps(fp2, fp0, fp1, fp2);
7410 tcg_temp_free_i64(fp0);
7411 tcg_temp_free_i64(fp1);
7412 gen_store_fpr64(ctx, fp2, fd);
7413 tcg_temp_free_i64(fp2);
7420 TCGv_i32 fp0 = tcg_temp_new_i32();
7421 TCGv_i32 fp1 = tcg_temp_new_i32();
7422 TCGv_i32 fp2 = tcg_temp_new_i32();
7424 gen_load_fpr32(fp0, fs);
7425 gen_load_fpr32(fp1, ft);
7426 gen_load_fpr32(fp2, fr);
7427 gen_helper_float_nmulsub_s(fp2, fp0, fp1, fp2);
7428 tcg_temp_free_i32(fp0);
7429 tcg_temp_free_i32(fp1);
7430 gen_store_fpr32(fp2, fd);
7431 tcg_temp_free_i32(fp2);
7437 check_cp1_registers(ctx, fd | fs | ft | fr);
7439 TCGv_i64 fp0 = tcg_temp_new_i64();
7440 TCGv_i64 fp1 = tcg_temp_new_i64();
7441 TCGv_i64 fp2 = tcg_temp_new_i64();
7443 gen_load_fpr64(ctx, fp0, fs);
7444 gen_load_fpr64(ctx, fp1, ft);
7445 gen_load_fpr64(ctx, fp2, fr);
7446 gen_helper_float_nmulsub_d(fp2, fp0, fp1, fp2);
7447 tcg_temp_free_i64(fp0);
7448 tcg_temp_free_i64(fp1);
7449 gen_store_fpr64(ctx, fp2, fd);
7450 tcg_temp_free_i64(fp2);
7455 check_cp1_64bitmode(ctx);
7457 TCGv_i64 fp0 = tcg_temp_new_i64();
7458 TCGv_i64 fp1 = tcg_temp_new_i64();
7459 TCGv_i64 fp2 = tcg_temp_new_i64();
7461 gen_load_fpr64(ctx, fp0, fs);
7462 gen_load_fpr64(ctx, fp1, ft);
7463 gen_load_fpr64(ctx, fp2, fr);
7464 gen_helper_float_nmulsub_ps(fp2, fp0, fp1, fp2);
7465 tcg_temp_free_i64(fp0);
7466 tcg_temp_free_i64(fp1);
7467 gen_store_fpr64(ctx, fp2, fd);
7468 tcg_temp_free_i64(fp2);
7474 generate_exception (ctx, EXCP_RI);
7477 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7478 fregnames[fs], fregnames[ft]);
7481 /* ISA extensions (ASEs) */
7482 /* MIPS16 extension to MIPS32 */
7483 /* SmartMIPS extension to MIPS32 */
7485 #if defined(TARGET_MIPS64)
7487 /* MDMX extension to MIPS64 */
7491 static void decode_opc (CPUState *env, DisasContext *ctx)
7495 uint32_t op, op1, op2;
7498 /* make sure instructions are on a word boundary */
7499 if (ctx->pc & 0x3) {
7500 env->CP0_BadVAddr = ctx->pc;
7501 generate_exception(ctx, EXCP_AdEL);
7505 /* Handle blikely not taken case */
7506 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7507 int l1 = gen_new_label();
7509 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7510 tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
7511 tcg_gen_movi_i32(hflags, ctx->hflags & ~MIPS_HFLAG_BMASK);
7512 gen_goto_tb(ctx, 1, ctx->pc + 4);
7515 op = MASK_OP_MAJOR(ctx->opcode);
7516 rs = (ctx->opcode >> 21) & 0x1f;
7517 rt = (ctx->opcode >> 16) & 0x1f;
7518 rd = (ctx->opcode >> 11) & 0x1f;
7519 sa = (ctx->opcode >> 6) & 0x1f;
7520 imm = (int16_t)ctx->opcode;
7523 op1 = MASK_SPECIAL(ctx->opcode);
7525 case OPC_SLL: /* Arithmetic with immediate */
7526 case OPC_SRL ... OPC_SRA:
7527 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7529 case OPC_MOVZ ... OPC_MOVN:
7530 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7531 case OPC_SLLV: /* Arithmetic */
7532 case OPC_SRLV ... OPC_SRAV:
7533 case OPC_ADD ... OPC_NOR:
7534 case OPC_SLT ... OPC_SLTU:
7535 gen_arith(env, ctx, op1, rd, rs, rt);
7537 case OPC_MULT ... OPC_DIVU:
7539 check_insn(env, ctx, INSN_VR54XX);
7540 op1 = MASK_MUL_VR54XX(ctx->opcode);
7541 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7543 gen_muldiv(ctx, op1, rs, rt);
7545 case OPC_JR ... OPC_JALR:
7546 gen_compute_branch(ctx, op1, rs, rd, sa);
7548 case OPC_TGE ... OPC_TEQ: /* Traps */
7550 gen_trap(ctx, op1, rs, rt, -1);
7552 case OPC_MFHI: /* Move from HI/LO */
7554 gen_HILO(ctx, op1, rd);
7557 case OPC_MTLO: /* Move to HI/LO */
7558 gen_HILO(ctx, op1, rs);
7560 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7561 #ifdef MIPS_STRICT_STANDARD
7562 MIPS_INVAL("PMON / selsl");
7563 generate_exception(ctx, EXCP_RI);
7565 gen_helper_0i(pmon, sa);
7569 generate_exception(ctx, EXCP_SYSCALL);
7572 generate_exception(ctx, EXCP_BREAK);
7575 #ifdef MIPS_STRICT_STANDARD
7577 generate_exception(ctx, EXCP_RI);
7579 /* Implemented as RI exception for now. */
7580 MIPS_INVAL("spim (unofficial)");
7581 generate_exception(ctx, EXCP_RI);
7589 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7590 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7591 save_cpu_state(ctx, 1);
7592 check_cp1_enabled(ctx);
7593 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7594 (ctx->opcode >> 16) & 1);
7596 generate_exception_err(ctx, EXCP_CpU, 1);
7600 #if defined(TARGET_MIPS64)
7601 /* MIPS64 specific opcodes */
7603 case OPC_DSRL ... OPC_DSRA:
7605 case OPC_DSRL32 ... OPC_DSRA32:
7606 check_insn(env, ctx, ISA_MIPS3);
7608 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7611 case OPC_DSRLV ... OPC_DSRAV:
7612 case OPC_DADD ... OPC_DSUBU:
7613 check_insn(env, ctx, ISA_MIPS3);
7615 gen_arith(env, ctx, op1, rd, rs, rt);
7617 case OPC_DMULT ... OPC_DDIVU:
7618 check_insn(env, ctx, ISA_MIPS3);
7620 gen_muldiv(ctx, op1, rs, rt);
7623 default: /* Invalid */
7624 MIPS_INVAL("special");
7625 generate_exception(ctx, EXCP_RI);
7630 op1 = MASK_SPECIAL2(ctx->opcode);
7632 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7633 case OPC_MSUB ... OPC_MSUBU:
7634 check_insn(env, ctx, ISA_MIPS32);
7635 gen_muldiv(ctx, op1, rs, rt);
7638 gen_arith(env, ctx, op1, rd, rs, rt);
7642 check_insn(env, ctx, ISA_MIPS32);
7643 gen_cl(ctx, op1, rd, rs);
7646 /* XXX: not clear which exception should be raised
7647 * when in debug mode...
7649 check_insn(env, ctx, ISA_MIPS32);
7650 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7651 generate_exception(ctx, EXCP_DBp);
7653 generate_exception(ctx, EXCP_DBp);
7657 #if defined(TARGET_MIPS64)
7660 check_insn(env, ctx, ISA_MIPS64);
7662 gen_cl(ctx, op1, rd, rs);
7665 default: /* Invalid */
7666 MIPS_INVAL("special2");
7667 generate_exception(ctx, EXCP_RI);
7672 op1 = MASK_SPECIAL3(ctx->opcode);
7676 check_insn(env, ctx, ISA_MIPS32R2);
7677 gen_bitops(ctx, op1, rt, rs, sa, rd);
7680 check_insn(env, ctx, ISA_MIPS32R2);
7681 op2 = MASK_BSHFL(ctx->opcode);
7682 gen_bshfl(ctx, op2, rt, rd);
7685 check_insn(env, ctx, ISA_MIPS32R2);
7687 TCGv t0 = tcg_temp_local_new();
7691 save_cpu_state(ctx, 1);
7692 gen_helper_rdhwr_cpunum(t0);
7695 save_cpu_state(ctx, 1);
7696 gen_helper_rdhwr_synci_step(t0);
7699 save_cpu_state(ctx, 1);
7700 gen_helper_rdhwr_cc(t0);
7703 save_cpu_state(ctx, 1);
7704 gen_helper_rdhwr_ccres(t0);
7707 #if defined(CONFIG_USER_ONLY)
7708 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7711 /* XXX: Some CPUs implement this in hardware.
7712 Not supported yet. */
7714 default: /* Invalid */
7715 MIPS_INVAL("rdhwr");
7716 generate_exception(ctx, EXCP_RI);
7719 gen_store_gpr(t0, rt);
7724 check_insn(env, ctx, ASE_MT);
7726 TCGv t0 = tcg_temp_local_new();
7727 TCGv t1 = tcg_temp_local_new();
7729 gen_load_gpr(t0, rt);
7730 gen_load_gpr(t1, rs);
7731 gen_helper_fork(t0, t1);
7737 check_insn(env, ctx, ASE_MT);
7739 TCGv t0 = tcg_temp_local_new();
7741 gen_load_gpr(t0, rs);
7742 gen_helper_yield(t0, t0);
7743 gen_store_gpr(t0, rd);
7747 #if defined(TARGET_MIPS64)
7748 case OPC_DEXTM ... OPC_DEXT:
7749 case OPC_DINSM ... OPC_DINS:
7750 check_insn(env, ctx, ISA_MIPS64R2);
7752 gen_bitops(ctx, op1, rt, rs, sa, rd);
7755 check_insn(env, ctx, ISA_MIPS64R2);
7757 op2 = MASK_DBSHFL(ctx->opcode);
7758 gen_bshfl(ctx, op2, rt, rd);
7761 default: /* Invalid */
7762 MIPS_INVAL("special3");
7763 generate_exception(ctx, EXCP_RI);
7768 op1 = MASK_REGIMM(ctx->opcode);
7770 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7771 case OPC_BLTZAL ... OPC_BGEZALL:
7772 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7774 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7776 gen_trap(ctx, op1, rs, -1, imm);
7779 check_insn(env, ctx, ISA_MIPS32R2);
7782 default: /* Invalid */
7783 MIPS_INVAL("regimm");
7784 generate_exception(ctx, EXCP_RI);
7789 check_cp0_enabled(ctx);
7790 op1 = MASK_CP0(ctx->opcode);
7796 #if defined(TARGET_MIPS64)
7800 #ifndef CONFIG_USER_ONLY
7801 gen_cp0(env, ctx, op1, rt, rd);
7802 #endif /* !CONFIG_USER_ONLY */
7804 case OPC_C0_FIRST ... OPC_C0_LAST:
7805 #ifndef CONFIG_USER_ONLY
7806 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7807 #endif /* !CONFIG_USER_ONLY */
7810 #ifndef CONFIG_USER_ONLY
7812 TCGv t0 = tcg_temp_local_new();
7814 op2 = MASK_MFMC0(ctx->opcode);
7817 check_insn(env, ctx, ASE_MT);
7818 gen_helper_dmt(t0, t0);
7821 check_insn(env, ctx, ASE_MT);
7822 gen_helper_emt(t0, t0);
7825 check_insn(env, ctx, ASE_MT);
7826 gen_helper_dvpe(t0, t0);
7829 check_insn(env, ctx, ASE_MT);
7830 gen_helper_evpe(t0, t0);
7833 check_insn(env, ctx, ISA_MIPS32R2);
7834 save_cpu_state(ctx, 1);
7836 /* Stop translation as we may have switched the execution mode */
7837 ctx->bstate = BS_STOP;
7840 check_insn(env, ctx, ISA_MIPS32R2);
7841 save_cpu_state(ctx, 1);
7843 /* Stop translation as we may have switched the execution mode */
7844 ctx->bstate = BS_STOP;
7846 default: /* Invalid */
7847 MIPS_INVAL("mfmc0");
7848 generate_exception(ctx, EXCP_RI);
7851 gen_store_gpr(t0, rt);
7854 #endif /* !CONFIG_USER_ONLY */
7857 check_insn(env, ctx, ISA_MIPS32R2);
7858 gen_load_srsgpr(rt, rd);
7861 check_insn(env, ctx, ISA_MIPS32R2);
7862 gen_store_srsgpr(rt, rd);
7866 generate_exception(ctx, EXCP_RI);
7870 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7871 gen_arith_imm(env, ctx, op, rt, rs, imm);
7873 case OPC_J ... OPC_JAL: /* Jump */
7874 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7875 gen_compute_branch(ctx, op, rs, rt, offset);
7877 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7878 case OPC_BEQL ... OPC_BGTZL:
7879 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7881 case OPC_LB ... OPC_LWR: /* Load and stores */
7882 case OPC_SB ... OPC_SW:
7886 gen_ldst(ctx, op, rt, rs, imm);
7889 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7893 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7897 /* Floating point (COP1). */
7902 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7903 save_cpu_state(ctx, 1);
7904 check_cp1_enabled(ctx);
7905 gen_flt_ldst(ctx, op, rt, rs, imm);
7907 generate_exception_err(ctx, EXCP_CpU, 1);
7912 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7913 save_cpu_state(ctx, 1);
7914 check_cp1_enabled(ctx);
7915 op1 = MASK_CP1(ctx->opcode);
7919 check_insn(env, ctx, ISA_MIPS32R2);
7924 gen_cp1(ctx, op1, rt, rd);
7926 #if defined(TARGET_MIPS64)
7929 check_insn(env, ctx, ISA_MIPS3);
7930 gen_cp1(ctx, op1, rt, rd);
7936 check_insn(env, ctx, ASE_MIPS3D);
7939 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
7940 (rt >> 2) & 0x7, imm << 2);
7947 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
7952 generate_exception (ctx, EXCP_RI);
7956 generate_exception_err(ctx, EXCP_CpU, 1);
7966 /* COP2: Not implemented. */
7967 generate_exception_err(ctx, EXCP_CpU, 2);
7971 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7972 save_cpu_state(ctx, 1);
7973 check_cp1_enabled(ctx);
7974 op1 = MASK_CP3(ctx->opcode);
7982 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8000 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8004 generate_exception (ctx, EXCP_RI);
8008 generate_exception_err(ctx, EXCP_CpU, 1);
8012 #if defined(TARGET_MIPS64)
8013 /* MIPS64 opcodes */
8015 case OPC_LDL ... OPC_LDR:
8016 case OPC_SDL ... OPC_SDR:
8021 check_insn(env, ctx, ISA_MIPS3);
8023 gen_ldst(ctx, op, rt, rs, imm);
8025 case OPC_DADDI ... OPC_DADDIU:
8026 check_insn(env, ctx, ISA_MIPS3);
8028 gen_arith_imm(env, ctx, op, rt, rs, imm);
8032 check_insn(env, ctx, ASE_MIPS16);
8033 /* MIPS16: Not implemented. */
8035 check_insn(env, ctx, ASE_MDMX);
8036 /* MDMX: Not implemented. */
8037 default: /* Invalid */
8038 MIPS_INVAL("major opcode");
8039 generate_exception(ctx, EXCP_RI);
8042 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8043 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8044 /* Branches completion */
8045 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8046 ctx->bstate = BS_BRANCH;
8047 save_cpu_state(ctx, 0);
8048 /* FIXME: Need to clear can_do_io. */
8051 /* unconditional branch */
8052 MIPS_DEBUG("unconditional branch");
8053 gen_goto_tb(ctx, 0, ctx->btarget);
8056 /* blikely taken case */
8057 MIPS_DEBUG("blikely branch taken");
8058 gen_goto_tb(ctx, 0, ctx->btarget);
8061 /* Conditional branch */
8062 MIPS_DEBUG("conditional branch");
8064 int l1 = gen_new_label();
8066 tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);
8067 gen_goto_tb(ctx, 1, ctx->pc + 4);
8069 gen_goto_tb(ctx, 0, ctx->btarget);
8073 /* unconditional branch to register */
8074 MIPS_DEBUG("branch to register");
8075 tcg_gen_mov_tl(cpu_PC, btarget);
8079 MIPS_DEBUG("unknown branch");
8086 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8090 target_ulong pc_start;
8091 uint16_t *gen_opc_end;
8098 qemu_log("search pc %d\n", search_pc);
8101 /* Leave some spare opc slots for branch handling. */
8102 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8106 ctx.bstate = BS_NONE;
8107 /* Restore delay slot state from the tb context. */
8108 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8109 restore_cpu_state(env, &ctx);
8110 #ifdef CONFIG_USER_ONLY
8111 ctx.mem_idx = MIPS_HFLAG_UM;
8113 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8116 max_insns = tb->cflags & CF_COUNT_MASK;
8118 max_insns = CF_COUNT_MASK;
8120 qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n");
8121 /* FIXME: This may print out stale hflags from env... */
8122 log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
8124 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags);
8126 while (ctx.bstate == BS_NONE) {
8127 if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
8128 TAILQ_FOREACH(bp, &env->breakpoints, entry) {
8129 if (bp->pc == ctx.pc) {
8130 save_cpu_state(&ctx, 1);
8131 ctx.bstate = BS_BRANCH;
8132 gen_helper_0i(raise_exception, EXCP_DEBUG);
8133 /* Include the breakpoint location or the tb won't
8134 * be flushed when it must be. */
8136 goto done_generating;
8142 j = gen_opc_ptr - gen_opc_buf;
8146 gen_opc_instr_start[lj++] = 0;
8148 gen_opc_pc[lj] = ctx.pc;
8149 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8150 gen_opc_instr_start[lj] = 1;
8151 gen_opc_icount[lj] = num_insns;
8153 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8155 ctx.opcode = ldl_code(ctx.pc);
8156 decode_opc(env, &ctx);
8160 if (env->singlestep_enabled)
8163 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8166 if (gen_opc_ptr >= gen_opc_end)
8169 if (num_insns >= max_insns)
8171 #if defined (MIPS_SINGLE_STEP)
8175 if (tb->cflags & CF_LAST_IO)
8177 if (env->singlestep_enabled) {
8178 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8179 gen_helper_0i(raise_exception, EXCP_DEBUG);
8181 switch (ctx.bstate) {
8183 gen_helper_interrupt_restart();
8184 gen_goto_tb(&ctx, 0, ctx.pc);
8187 save_cpu_state(&ctx, 0);
8188 gen_goto_tb(&ctx, 0, ctx.pc);
8191 gen_helper_interrupt_restart();
8200 gen_icount_end(tb, num_insns);
8201 *gen_opc_ptr = INDEX_op_end;
8203 j = gen_opc_ptr - gen_opc_buf;
8206 gen_opc_instr_start[lj++] = 0;
8208 tb->size = ctx.pc - pc_start;
8209 tb->icount = num_insns;
8213 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
8214 qemu_log("IN: %s\n", lookup_symbol(pc_start));
8215 log_target_disas(pc_start, ctx.pc - pc_start, 0);
8218 qemu_log_mask(CPU_LOG_TB_CPU, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8222 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8224 gen_intermediate_code_internal(env, tb, 0);
8227 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8229 gen_intermediate_code_internal(env, tb, 1);
8232 static void fpu_dump_state(CPUState *env, FILE *f,
8233 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8237 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8239 #define printfpr(fp) \
8242 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8243 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8244 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8247 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8248 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8249 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8250 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8251 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8256 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8257 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8258 get_float_exception_flags(&env->active_fpu.fp_status));
8259 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8260 fpu_fprintf(f, "%3s: ", fregnames[i]);
8261 printfpr(&env->active_fpu.fpr[i]);
8267 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8268 /* Debug help: The architecture requires 32bit code to maintain proper
8269 sign-extended values on 64bit machines. */
8271 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8274 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8275 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8280 if (!SIGN_EXT_P(env->active_tc.PC))
8281 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8282 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8283 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8284 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8285 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8286 if (!SIGN_EXT_P(env->btarget))
8287 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8289 for (i = 0; i < 32; i++) {
8290 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8291 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8294 if (!SIGN_EXT_P(env->CP0_EPC))
8295 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8296 if (!SIGN_EXT_P(env->CP0_LLAddr))
8297 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8301 void cpu_dump_state (CPUState *env, FILE *f,
8302 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8307 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",
8308 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8309 env->hflags, env->btarget, env->bcond);
8310 for (i = 0; i < 32; i++) {
8312 cpu_fprintf(f, "GPR%02d:", i);
8313 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8315 cpu_fprintf(f, "\n");
8318 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8319 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8320 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8321 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8322 if (env->hflags & MIPS_HFLAG_FPU)
8323 fpu_dump_state(env, f, cpu_fprintf, flags);
8324 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8325 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8329 static void mips_tcg_init(void)
8334 /* Initialize various static tables. */
8338 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
8339 for (i = 0; i < 32; i++)
8340 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
8341 offsetof(CPUState, active_tc.gpr[i]),
8343 cpu_PC = tcg_global_mem_new(TCG_AREG0,
8344 offsetof(CPUState, active_tc.PC), "PC");
8345 for (i = 0; i < MIPS_DSP_ACC; i++) {
8346 cpu_HI[i] = tcg_global_mem_new(TCG_AREG0,
8347 offsetof(CPUState, active_tc.HI[i]),
8349 cpu_LO[i] = tcg_global_mem_new(TCG_AREG0,
8350 offsetof(CPUState, active_tc.LO[i]),
8352 cpu_ACX[i] = tcg_global_mem_new(TCG_AREG0,
8353 offsetof(CPUState, active_tc.ACX[i]),
8356 cpu_dspctrl = tcg_global_mem_new(TCG_AREG0,
8357 offsetof(CPUState, active_tc.DSPControl),
8359 bcond = tcg_global_mem_new(TCG_AREG0,
8360 offsetof(CPUState, bcond), "bcond");
8361 btarget = tcg_global_mem_new(TCG_AREG0,
8362 offsetof(CPUState, btarget), "btarget");
8363 hflags = tcg_global_mem_new_i32(TCG_AREG0,
8364 offsetof(CPUState, hflags), "hflags");
8366 fpu_fcr0 = tcg_global_mem_new_i32(TCG_AREG0,
8367 offsetof(CPUState, active_fpu.fcr0),
8369 fpu_fcr31 = tcg_global_mem_new_i32(TCG_AREG0,
8370 offsetof(CPUState, active_fpu.fcr31),
8373 /* register helpers */
8374 #define GEN_HELPER 2
8380 #include "translate_init.c"
8382 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8385 const mips_def_t *def;
8387 def = cpu_mips_find_by_name(cpu_model);
8390 env = qemu_mallocz(sizeof(CPUMIPSState));
8391 env->cpu_model = def;
8394 env->cpu_model_str = cpu_model;
8400 void cpu_reset (CPUMIPSState *env)
8402 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
8403 qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
8404 log_cpu_state(env, 0);
8407 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8412 #if defined(CONFIG_USER_ONLY)
8413 env->hflags = MIPS_HFLAG_UM;
8415 if (env->hflags & MIPS_HFLAG_BMASK) {
8416 /* If the exception was raised from a delay slot,
8417 come back to the jump. */
8418 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8420 env->CP0_ErrorEPC = env->active_tc.PC;
8422 env->active_tc.PC = (int32_t)0xBFC00000;
8424 /* SMP not implemented */
8425 env->CP0_EBase = 0x80000000;
8426 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8427 /* vectored interrupts not implemented, timer on int 7,
8428 no performance counters. */
8429 env->CP0_IntCtl = 0xe0000000;
8433 for (i = 0; i < 7; i++) {
8434 env->CP0_WatchLo[i] = 0;
8435 env->CP0_WatchHi[i] = 0x80000000;
8437 env->CP0_WatchLo[7] = 0;
8438 env->CP0_WatchHi[7] = 0;
8440 /* Count register increments in debug mode, EJTAG version 1 */
8441 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8442 env->hflags = MIPS_HFLAG_CP0;
8444 env->exception_index = EXCP_NONE;
8445 cpu_mips_register(env, env->cpu_model);
8448 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8449 unsigned long searched_pc, int pc_pos, void *puc)
8451 env->active_tc.PC = gen_opc_pc[pc_pos];
8452 env->hflags &= ~MIPS_HFLAG_BMASK;
8453 env->hflags |= gen_opc_hflags[pc_pos];