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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL = (0x00 << 26),
46 OPC_REGIMM = (0x01 << 26),
47 OPC_CP0 = (0x10 << 26),
48 OPC_CP1 = (0x11 << 26),
49 OPC_CP2 = (0x12 << 26),
50 OPC_CP3 = (0x13 << 26),
51 OPC_SPECIAL2 = (0x1C << 26),
52 OPC_SPECIAL3 = (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI = (0x08 << 26),
55 OPC_ADDIU = (0x09 << 26),
56 OPC_SLTI = (0x0A << 26),
57 OPC_SLTIU = (0x0B << 26),
58 OPC_ANDI = (0x0C << 26),
59 OPC_ORI = (0x0D << 26),
60 OPC_XORI = (0x0E << 26),
61 OPC_LUI = (0x0F << 26),
62 OPC_DADDI = (0x18 << 26),
63 OPC_DADDIU = (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL = (0x03 << 26),
67 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL = (0x14 << 26),
69 OPC_BNE = (0x05 << 26),
70 OPC_BNEL = (0x15 << 26),
71 OPC_BLEZ = (0x06 << 26),
72 OPC_BLEZL = (0x16 << 26),
73 OPC_BGTZ = (0x07 << 26),
74 OPC_BGTZL = (0x17 << 26),
75 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL = (0x1A << 26),
78 OPC_LDR = (0x1B << 26),
79 OPC_LB = (0x20 << 26),
80 OPC_LH = (0x21 << 26),
81 OPC_LWL = (0x22 << 26),
82 OPC_LW = (0x23 << 26),
83 OPC_LBU = (0x24 << 26),
84 OPC_LHU = (0x25 << 26),
85 OPC_LWR = (0x26 << 26),
86 OPC_LWU = (0x27 << 26),
87 OPC_SB = (0x28 << 26),
88 OPC_SH = (0x29 << 26),
89 OPC_SWL = (0x2A << 26),
90 OPC_SW = (0x2B << 26),
91 OPC_SDL = (0x2C << 26),
92 OPC_SDR = (0x2D << 26),
93 OPC_SWR = (0x2E << 26),
94 OPC_LL = (0x30 << 26),
95 OPC_LLD = (0x34 << 26),
96 OPC_LD = (0x37 << 26),
97 OPC_SC = (0x38 << 26),
98 OPC_SCD = (0x3C << 26),
99 OPC_SD = (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1 = (0x31 << 26),
102 OPC_LWC2 = (0x32 << 26),
103 OPC_LDC1 = (0x35 << 26),
104 OPC_LDC2 = (0x36 << 26),
105 OPC_SWC1 = (0x39 << 26),
106 OPC_SWC2 = (0x3A << 26),
107 OPC_SDC1 = (0x3D << 26),
108 OPC_SDC2 = (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX = (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE = (0x2F << 26),
113 OPC_PREF = (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED = (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL = 0x00 | OPC_SPECIAL,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
128 OPC_SRA = 0x03 | OPC_SPECIAL,
129 OPC_SLLV = 0x04 | OPC_SPECIAL,
130 OPC_SRLV = 0x06 | OPC_SPECIAL, /* also ROTRV */
131 OPC_SRAV = 0x07 | OPC_SPECIAL,
132 OPC_DSLLV = 0x14 | OPC_SPECIAL,
133 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
134 OPC_DSRAV = 0x17 | OPC_SPECIAL,
135 OPC_DSLL = 0x38 | OPC_SPECIAL,
136 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
137 OPC_DSRA = 0x3B | OPC_SPECIAL,
138 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
139 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
140 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
141 /* Multiplication / division */
142 OPC_MULT = 0x18 | OPC_SPECIAL,
143 OPC_MULTU = 0x19 | OPC_SPECIAL,
144 OPC_DIV = 0x1A | OPC_SPECIAL,
145 OPC_DIVU = 0x1B | OPC_SPECIAL,
146 OPC_DMULT = 0x1C | OPC_SPECIAL,
147 OPC_DMULTU = 0x1D | OPC_SPECIAL,
148 OPC_DDIV = 0x1E | OPC_SPECIAL,
149 OPC_DDIVU = 0x1F | OPC_SPECIAL,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD = 0x20 | OPC_SPECIAL,
152 OPC_ADDU = 0x21 | OPC_SPECIAL,
153 OPC_SUB = 0x22 | OPC_SPECIAL,
154 OPC_SUBU = 0x23 | OPC_SPECIAL,
155 OPC_AND = 0x24 | OPC_SPECIAL,
156 OPC_OR = 0x25 | OPC_SPECIAL,
157 OPC_XOR = 0x26 | OPC_SPECIAL,
158 OPC_NOR = 0x27 | OPC_SPECIAL,
159 OPC_SLT = 0x2A | OPC_SPECIAL,
160 OPC_SLTU = 0x2B | OPC_SPECIAL,
161 OPC_DADD = 0x2C | OPC_SPECIAL,
162 OPC_DADDU = 0x2D | OPC_SPECIAL,
163 OPC_DSUB = 0x2E | OPC_SPECIAL,
164 OPC_DSUBU = 0x2F | OPC_SPECIAL,
166 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
167 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
169 OPC_TGE = 0x30 | OPC_SPECIAL,
170 OPC_TGEU = 0x31 | OPC_SPECIAL,
171 OPC_TLT = 0x32 | OPC_SPECIAL,
172 OPC_TLTU = 0x33 | OPC_SPECIAL,
173 OPC_TEQ = 0x34 | OPC_SPECIAL,
174 OPC_TNE = 0x36 | OPC_SPECIAL,
175 /* HI / LO registers load & stores */
176 OPC_MFHI = 0x10 | OPC_SPECIAL,
177 OPC_MTHI = 0x11 | OPC_SPECIAL,
178 OPC_MFLO = 0x12 | OPC_SPECIAL,
179 OPC_MTLO = 0x13 | OPC_SPECIAL,
180 /* Conditional moves */
181 OPC_MOVZ = 0x0A | OPC_SPECIAL,
182 OPC_MOVN = 0x0B | OPC_SPECIAL,
184 OPC_MOVCI = 0x01 | OPC_SPECIAL,
187 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
188 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
189 OPC_BREAK = 0x0D | OPC_SPECIAL,
190 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
191 OPC_SYNC = 0x0F | OPC_SPECIAL,
193 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
194 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
195 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
196 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
197 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
198 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
199 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS = (0x03 << 6) | OPC_MULT,
207 OPC_VR54XX_MULSU = (0x03 << 6) | OPC_MULTU,
208 OPC_VR54XX_MACC = (0x05 << 6) | OPC_MULT,
209 OPC_VR54XX_MACCU = (0x05 << 6) | OPC_MULTU,
210 OPC_VR54XX_MSAC = (0x07 << 6) | OPC_MULT,
211 OPC_VR54XX_MSACU = (0x07 << 6) | OPC_MULTU,
212 OPC_VR54XX_MULHI = (0x09 << 6) | OPC_MULT,
213 OPC_VR54XX_MULHIU = (0x09 << 6) | OPC_MULTU,
214 OPC_VR54XX_MULSHI = (0x0B << 6) | OPC_MULT,
215 OPC_VR54XX_MULSHIU = (0x0B << 6) | OPC_MULTU,
216 OPC_VR54XX_MACCHI = (0x0D << 6) | OPC_MULT,
217 OPC_VR54XX_MACCHIU = (0x0D << 6) | OPC_MULTU,
218 OPC_VR54XX_MSACHI = (0x0F << 6) | OPC_MULT,
219 OPC_VR54XX_MSACHIU = (0x0F << 6) | OPC_MULTU,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
227 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
228 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
229 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
230 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
231 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
232 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
233 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
234 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
235 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
236 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
237 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
238 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
239 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
240 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD = 0x00 | OPC_SPECIAL2,
249 OPC_MADDU = 0x01 | OPC_SPECIAL2,
250 OPC_MUL = 0x02 | OPC_SPECIAL2,
251 OPC_MSUB = 0x04 | OPC_SPECIAL2,
252 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
254 OPC_CLZ = 0x20 | OPC_SPECIAL2,
255 OPC_CLO = 0x21 | OPC_SPECIAL2,
256 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
257 OPC_DCLO = 0x25 | OPC_SPECIAL2,
259 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT = 0x00 | OPC_SPECIAL3,
267 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
268 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
269 OPC_DEXT = 0x03 | OPC_SPECIAL3,
270 OPC_INS = 0x04 | OPC_SPECIAL3,
271 OPC_DINSM = 0x05 | OPC_SPECIAL3,
272 OPC_DINSU = 0x06 | OPC_SPECIAL3,
273 OPC_DINS = 0x07 | OPC_SPECIAL3,
274 OPC_FORK = 0x08 | OPC_SPECIAL3,
275 OPC_YIELD = 0x09 | OPC_SPECIAL3,
276 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
277 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
278 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
286 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
287 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
295 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
303 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
304 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
305 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
306 OPC_MFTR = (0x08 << 21) | OPC_CP0,
307 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
308 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
309 OPC_MTTR = (0x0C << 21) | OPC_CP0,
310 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
311 OPC_C0 = (0x10 << 21) | OPC_CP0,
312 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
313 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
321 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
322 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
323 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
324 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
325 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR = 0x01 | OPC_C0,
333 OPC_TLBWI = 0x02 | OPC_C0,
334 OPC_TLBWR = 0x06 | OPC_C0,
335 OPC_TLBP = 0x08 | OPC_C0,
336 OPC_RFE = 0x10 | OPC_C0,
337 OPC_ERET = 0x18 | OPC_C0,
338 OPC_DERET = 0x1F | OPC_C0,
339 OPC_WAIT = 0x20 | OPC_C0,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
347 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
348 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
349 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
350 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
351 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
352 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
353 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
354 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
355 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
356 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
357 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
358 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
359 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
360 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
361 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
362 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F = (0x00 << 16) | OPC_BC1,
371 OPC_BC1T = (0x01 << 16) | OPC_BC1,
372 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
373 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
377 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
378 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
382 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
383 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
390 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
391 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
392 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
393 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
394 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
395 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
396 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
397 OPC_BC2 = (0x08 << 21) | OPC_CP2,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1 = 0x00 | OPC_CP3,
404 OPC_LDXC1 = 0x01 | OPC_CP3,
405 OPC_LUXC1 = 0x05 | OPC_CP3,
406 OPC_SWXC1 = 0x08 | OPC_CP3,
407 OPC_SDXC1 = 0x09 | OPC_CP3,
408 OPC_SUXC1 = 0x0D | OPC_CP3,
409 OPC_PREFX = 0x0F | OPC_CP3,
410 OPC_ALNV_PS = 0x1E | OPC_CP3,
411 OPC_MADD_S = 0x20 | OPC_CP3,
412 OPC_MADD_D = 0x21 | OPC_CP3,
413 OPC_MADD_PS = 0x26 | OPC_CP3,
414 OPC_MSUB_S = 0x28 | OPC_CP3,
415 OPC_MSUB_D = 0x29 | OPC_CP3,
416 OPC_MSUB_PS = 0x2E | OPC_CP3,
417 OPC_NMADD_S = 0x30 | OPC_CP3,
418 OPC_NMADD_D = 0x31 | OPC_CP3,
419 OPC_NMADD_PS= 0x36 | OPC_CP3,
420 OPC_NMSUB_S = 0x38 | OPC_CP3,
421 OPC_NMSUB_D = 0x39 | OPC_CP3,
422 OPC_NMSUB_PS= 0x3E | OPC_CP3,
425 /* global register indices */
426 static TCGv cpu_env, cpu_gpr[32], cpu_PC;
427 static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC], cpu_ACX[MIPS_DSP_ACC];
428 static TCGv cpu_dspctrl, bcond, btarget;
429 static TCGv fpu_fpr32[32], fpu_fpr32h[32], fpu_fpr64[32], fpu_fcr0, fpu_fcr31;
431 #include "gen-icount.h"
433 static inline void tcg_gen_helper_0_i(void *func, uint32_t arg)
436 TCGv tmp = tcg_const_i32(arg);
438 tcg_gen_helper_0_1(func, tmp);
442 static inline void tcg_gen_helper_0_ii(void *func, uint32_t arg1, uint32_t arg2)
444 TCGv tmp1 = tcg_const_i32(arg1);
445 TCGv tmp2 = tcg_const_i32(arg2);
447 tcg_gen_helper_0_2(func, tmp1, tmp2);
452 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg1, uint32_t arg2)
454 TCGv tmp = tcg_const_i32(arg2);
456 tcg_gen_helper_0_2(func, arg1, tmp);
460 static inline void tcg_gen_helper_0_2i(void *func, TCGv arg1, TCGv arg2, uint32_t arg3)
462 TCGv tmp = tcg_const_i32(arg3);
464 tcg_gen_helper_0_3(func, arg1, arg2, tmp);
468 static inline void tcg_gen_helper_0_1ii(void *func, TCGv arg1, uint32_t arg2, uint32_t arg3)
470 TCGv tmp1 = tcg_const_i32(arg2);
471 TCGv tmp2 = tcg_const_i32(arg3);
473 tcg_gen_helper_0_3(func, arg1, tmp1, tmp2);
478 static inline void tcg_gen_helper_1_i(void *func, TCGv ret, uint32_t arg)
480 TCGv tmp = tcg_const_i32(arg);
482 tcg_gen_helper_1_1(func, ret, tmp);
486 static inline void tcg_gen_helper_1_1i(void *func, TCGv ret, TCGv arg1, uint32_t arg2)
488 TCGv tmp = tcg_const_i32(arg2);
490 tcg_gen_helper_1_2(func, ret, arg1, tmp);
494 static inline void tcg_gen_helper_1_1ii(void *func, TCGv ret, TCGv arg1, uint32_t arg2, uint32_t arg3)
496 TCGv tmp1 = tcg_const_i32(arg2);
497 TCGv tmp2 = tcg_const_i32(arg3);
499 tcg_gen_helper_1_3(func, ret, arg1, tmp1, tmp2);
504 static inline void tcg_gen_helper_1_2i(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3)
506 TCGv tmp = tcg_const_i32(arg3);
508 tcg_gen_helper_1_3(func, ret, arg1, arg2, tmp);
512 static inline void tcg_gen_helper_1_2ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3, uint32_t arg4)
514 TCGv tmp1 = tcg_const_i32(arg3);
515 TCGv tmp2 = tcg_const_i32(arg4);
517 tcg_gen_helper_1_4(func, ret, arg1, arg2, tmp1, tmp2);
522 typedef struct DisasContext {
523 struct TranslationBlock *tb;
524 target_ulong pc, saved_pc;
526 /* Routine used to access memory */
528 uint32_t hflags, saved_hflags;
530 target_ulong btarget;
534 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
535 * exception condition */
536 BS_STOP = 1, /* We want to stop translation for any reason */
537 BS_BRANCH = 2, /* We reached a branch condition */
538 BS_EXCP = 3, /* We reached an exception condition */
541 static const char *regnames[] =
542 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
543 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
544 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
545 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
547 static const char *regnames_HI[] =
548 { "HI0", "HI1", "HI2", "HI3", };
550 static const char *regnames_LO[] =
551 { "LO0", "LO1", "LO2", "LO3", };
553 static const char *regnames_ACX[] =
554 { "ACX0", "ACX1", "ACX2", "ACX3", };
556 static const char *fregnames[] =
557 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
558 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
559 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
560 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
562 static const char *fregnames_64[] =
563 { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
564 "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15",
565 "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23",
566 "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31", };
568 static const char *fregnames_h[] =
569 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
570 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
571 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
572 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
574 #ifdef MIPS_DEBUG_DISAS
575 #define MIPS_DEBUG(fmt, args...) \
577 if (loglevel & CPU_LOG_TB_IN_ASM) { \
578 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
579 ctx->pc, ctx->opcode , ##args); \
583 #define MIPS_DEBUG(fmt, args...) do { } while(0)
586 #define MIPS_INVAL(op) \
588 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
589 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
592 /* General purpose registers moves. */
593 static inline void gen_load_gpr (TCGv t, int reg)
596 tcg_gen_movi_tl(t, 0);
598 tcg_gen_mov_tl(t, cpu_gpr[reg]);
601 static inline void gen_store_gpr (TCGv t, int reg)
604 tcg_gen_mov_tl(cpu_gpr[reg], t);
607 /* Moves to/from HI and LO registers. */
608 static inline void gen_load_HI (TCGv t, int reg)
610 tcg_gen_mov_tl(t, cpu_HI[reg]);
613 static inline void gen_store_HI (TCGv t, int reg)
615 tcg_gen_mov_tl(cpu_HI[reg], t);
618 static inline void gen_load_LO (TCGv t, int reg)
620 tcg_gen_mov_tl(t, cpu_LO[reg]);
623 static inline void gen_store_LO (TCGv t, int reg)
625 tcg_gen_mov_tl(cpu_LO[reg], t);
628 static inline void gen_load_ACX (TCGv t, int reg)
630 tcg_gen_mov_tl(t, cpu_ACX[reg]);
633 static inline void gen_store_ACX (TCGv t, int reg)
635 tcg_gen_mov_tl(cpu_ACX[reg], t);
638 /* Moves to/from shadow registers. */
639 static inline void gen_load_srsgpr (int from, int to)
641 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
644 tcg_gen_movi_tl(r_tmp1, 0);
646 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
648 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
649 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
650 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
651 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
652 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
654 tcg_gen_ld_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * from);
655 tcg_temp_free(r_tmp2);
657 gen_store_gpr(r_tmp1, to);
658 tcg_temp_free(r_tmp1);
661 static inline void gen_store_srsgpr (int from, int to)
664 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
665 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
667 gen_load_gpr(r_tmp1, from);
668 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
669 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
670 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
671 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
672 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
674 tcg_gen_st_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * to);
675 tcg_temp_free(r_tmp1);
676 tcg_temp_free(r_tmp2);
680 /* Floating point register moves. */
681 static inline void gen_load_fpr32 (TCGv t, int reg)
683 tcg_gen_mov_i32(t, fpu_fpr32[reg]);
686 static inline void gen_store_fpr32 (TCGv t, int reg)
688 tcg_gen_mov_i32(fpu_fpr32[reg], t);
691 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
693 if (ctx->hflags & MIPS_HFLAG_F64)
694 tcg_gen_mov_i64(t, fpu_fpr64[reg]);
696 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg & ~1], fpu_fpr32[reg | 1]);
700 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
702 if (ctx->hflags & MIPS_HFLAG_F64)
703 tcg_gen_mov_i64(fpu_fpr64[reg], t);
705 tcg_gen_trunc_i64_i32(fpu_fpr32[reg & ~1], t);
706 tcg_gen_shri_i64(t, t, 32);
707 tcg_gen_trunc_i64_i32(fpu_fpr32[reg | 1], t);
711 static inline void gen_load_fpr32h (TCGv t, int reg)
713 tcg_gen_mov_i32(t, fpu_fpr32h[reg]);
716 static inline void gen_store_fpr32h (TCGv t, int reg)
718 tcg_gen_mov_i32(fpu_fpr32h[reg], t);
721 static inline void get_fp_cond (TCGv t)
723 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
724 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
726 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
727 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
728 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
729 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
730 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
731 tcg_temp_free(r_tmp1);
732 tcg_temp_free(r_tmp2);
735 typedef void (fcmp_fun32)(uint32_t, uint32_t, int);
736 typedef void (fcmp_fun64)(uint64_t, uint64_t, int);
738 #define FOP_CONDS(fcmp_fun, type, fmt) \
739 static fcmp_fun * fcmp ## type ## _ ## fmt ## _table[16] = { \
740 do_cmp ## type ## _ ## fmt ## _f, \
741 do_cmp ## type ## _ ## fmt ## _un, \
742 do_cmp ## type ## _ ## fmt ## _eq, \
743 do_cmp ## type ## _ ## fmt ## _ueq, \
744 do_cmp ## type ## _ ## fmt ## _olt, \
745 do_cmp ## type ## _ ## fmt ## _ult, \
746 do_cmp ## type ## _ ## fmt ## _ole, \
747 do_cmp ## type ## _ ## fmt ## _ule, \
748 do_cmp ## type ## _ ## fmt ## _sf, \
749 do_cmp ## type ## _ ## fmt ## _ngle, \
750 do_cmp ## type ## _ ## fmt ## _seq, \
751 do_cmp ## type ## _ ## fmt ## _ngl, \
752 do_cmp ## type ## _ ## fmt ## _lt, \
753 do_cmp ## type ## _ ## fmt ## _nge, \
754 do_cmp ## type ## _ ## fmt ## _le, \
755 do_cmp ## type ## _ ## fmt ## _ngt, \
757 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv a, TCGv b, int cc) \
759 tcg_gen_helper_0_2i(fcmp ## type ## _ ## fmt ## _table[n], a, b, cc); \
762 FOP_CONDS(fcmp_fun64, , d)
763 FOP_CONDS(fcmp_fun64, abs, d)
764 FOP_CONDS(fcmp_fun32, , s)
765 FOP_CONDS(fcmp_fun32, abs, s)
766 FOP_CONDS(fcmp_fun64, , ps)
767 FOP_CONDS(fcmp_fun64, abs, ps)
771 #define OP_COND(name, cond) \
772 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
774 int l1 = gen_new_label(); \
775 int l2 = gen_new_label(); \
777 tcg_gen_brcond_tl(cond, t0, t1, l1); \
778 tcg_gen_movi_tl(t0, 0); \
781 tcg_gen_movi_tl(t0, 1); \
784 OP_COND(eq, TCG_COND_EQ);
785 OP_COND(ne, TCG_COND_NE);
786 OP_COND(ge, TCG_COND_GE);
787 OP_COND(geu, TCG_COND_GEU);
788 OP_COND(lt, TCG_COND_LT);
789 OP_COND(ltu, TCG_COND_LTU);
792 #define OP_CONDI(name, cond) \
793 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
795 int l1 = gen_new_label(); \
796 int l2 = gen_new_label(); \
798 tcg_gen_brcondi_tl(cond, t, val, l1); \
799 tcg_gen_movi_tl(t, 0); \
802 tcg_gen_movi_tl(t, 1); \
805 OP_CONDI(lti, TCG_COND_LT);
806 OP_CONDI(ltiu, TCG_COND_LTU);
809 #define OP_CONDZ(name, cond) \
810 static inline void glue(gen_op_, name) (TCGv t) \
812 int l1 = gen_new_label(); \
813 int l2 = gen_new_label(); \
815 tcg_gen_brcondi_tl(cond, t, 0, l1); \
816 tcg_gen_movi_tl(t, 0); \
819 tcg_gen_movi_tl(t, 1); \
822 OP_CONDZ(gez, TCG_COND_GE);
823 OP_CONDZ(gtz, TCG_COND_GT);
824 OP_CONDZ(lez, TCG_COND_LE);
825 OP_CONDZ(ltz, TCG_COND_LT);
828 static inline void gen_save_pc(target_ulong pc)
830 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
832 tcg_gen_movi_tl(r_tmp, pc);
833 tcg_gen_mov_tl(cpu_PC, r_tmp);
834 tcg_temp_free(r_tmp);
837 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
839 #if defined MIPS_DEBUG_DISAS
840 if (loglevel & CPU_LOG_TB_IN_ASM) {
841 fprintf(logfile, "hflags %08x saved %08x\n",
842 ctx->hflags, ctx->saved_hflags);
845 if (do_save_pc && ctx->pc != ctx->saved_pc) {
846 gen_save_pc(ctx->pc);
847 ctx->saved_pc = ctx->pc;
849 if (ctx->hflags != ctx->saved_hflags) {
850 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
852 tcg_gen_movi_i32(r_tmp, ctx->hflags);
853 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
854 tcg_temp_free(r_tmp);
855 ctx->saved_hflags = ctx->hflags;
856 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
862 tcg_gen_movi_tl(btarget, ctx->btarget);
868 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
870 ctx->saved_hflags = ctx->hflags;
871 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
877 ctx->btarget = env->btarget;
883 generate_exception_err (DisasContext *ctx, int excp, int err)
885 save_cpu_state(ctx, 1);
886 tcg_gen_helper_0_ii(do_raise_exception_err, excp, err);
887 tcg_gen_helper_0_0(do_interrupt_restart);
892 generate_exception (DisasContext *ctx, int excp)
894 save_cpu_state(ctx, 1);
895 tcg_gen_helper_0_i(do_raise_exception, excp);
896 tcg_gen_helper_0_0(do_interrupt_restart);
900 /* Addresses computation */
901 static inline void gen_op_addr_add (TCGv t0, TCGv t1)
903 tcg_gen_add_tl(t0, t0, t1);
905 #if defined(TARGET_MIPS64)
906 /* For compatibility with 32-bit code, data reference in user mode
907 with Status_UX = 0 should be casted to 32-bit and sign extended.
908 See the MIPS64 PRA manual, section 4.10. */
910 int l1 = gen_new_label();
911 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
913 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
914 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
915 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
916 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
917 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
918 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
919 tcg_temp_free(r_tmp);
920 tcg_gen_ext32s_i64(t0, t0);
926 static inline void check_cp0_enabled(DisasContext *ctx)
928 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
929 generate_exception_err(ctx, EXCP_CpU, 1);
932 static inline void check_cp1_enabled(DisasContext *ctx)
934 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
935 generate_exception_err(ctx, EXCP_CpU, 1);
938 /* Verify that the processor is running with COP1X instructions enabled.
939 This is associated with the nabla symbol in the MIPS32 and MIPS64
942 static inline void check_cop1x(DisasContext *ctx)
944 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
945 generate_exception(ctx, EXCP_RI);
948 /* Verify that the processor is running with 64-bit floating-point
949 operations enabled. */
951 static inline void check_cp1_64bitmode(DisasContext *ctx)
953 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
954 generate_exception(ctx, EXCP_RI);
958 * Verify if floating point register is valid; an operation is not defined
959 * if bit 0 of any register specification is set and the FR bit in the
960 * Status register equals zero, since the register numbers specify an
961 * even-odd pair of adjacent coprocessor general registers. When the FR bit
962 * in the Status register equals one, both even and odd register numbers
963 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
965 * Multiple 64 bit wide registers can be checked by calling
966 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
968 static inline void check_cp1_registers(DisasContext *ctx, int regs)
970 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
971 generate_exception(ctx, EXCP_RI);
974 /* This code generates a "reserved instruction" exception if the
975 CPU does not support the instruction set corresponding to flags. */
976 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
978 if (unlikely(!(env->insn_flags & flags)))
979 generate_exception(ctx, EXCP_RI);
982 /* This code generates a "reserved instruction" exception if 64-bit
983 instructions are not enabled. */
984 static inline void check_mips_64(DisasContext *ctx)
986 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
987 generate_exception(ctx, EXCP_RI);
990 /* load/store instructions. */
991 #define OP_LD(insn,fname) \
992 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
994 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1001 #if defined(TARGET_MIPS64)
1007 #define OP_ST(insn,fname) \
1008 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1010 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1015 #if defined(TARGET_MIPS64)
1020 #define OP_LD_ATOMIC(insn,fname) \
1021 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1023 tcg_gen_mov_tl(t1, t0); \
1024 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1025 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1027 OP_LD_ATOMIC(ll,ld32s);
1028 #if defined(TARGET_MIPS64)
1029 OP_LD_ATOMIC(lld,ld64);
1033 #define OP_ST_ATOMIC(insn,fname,almask) \
1034 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1036 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1037 int l1 = gen_new_label(); \
1038 int l2 = gen_new_label(); \
1039 int l3 = gen_new_label(); \
1041 tcg_gen_andi_tl(r_tmp, t0, almask); \
1042 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1043 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1044 generate_exception(ctx, EXCP_AdES); \
1045 gen_set_label(l1); \
1046 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1047 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1048 tcg_temp_free(r_tmp); \
1049 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1050 tcg_gen_movi_tl(t0, 1); \
1052 gen_set_label(l2); \
1053 tcg_gen_movi_tl(t0, 0); \
1054 gen_set_label(l3); \
1056 OP_ST_ATOMIC(sc,st32,0x3);
1057 #if defined(TARGET_MIPS64)
1058 OP_ST_ATOMIC(scd,st64,0x7);
1062 /* Load and store */
1063 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1064 int base, int16_t offset)
1066 const char *opn = "ldst";
1067 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1068 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1071 tcg_gen_movi_tl(t0, offset);
1072 } else if (offset == 0) {
1073 gen_load_gpr(t0, base);
1075 gen_load_gpr(t0, base);
1076 tcg_gen_movi_tl(t1, offset);
1077 gen_op_addr_add(t0, t1);
1079 /* Don't do NOP if destination is zero: we must perform the actual
1082 #if defined(TARGET_MIPS64)
1084 op_ldst_lwu(t0, ctx);
1085 gen_store_gpr(t0, rt);
1089 op_ldst_ld(t0, ctx);
1090 gen_store_gpr(t0, rt);
1094 op_ldst_lld(t0, t1, ctx);
1095 gen_store_gpr(t0, rt);
1099 gen_load_gpr(t1, rt);
1100 op_ldst_sd(t0, t1, ctx);
1104 save_cpu_state(ctx, 1);
1105 gen_load_gpr(t1, rt);
1106 op_ldst_scd(t0, t1, ctx);
1107 gen_store_gpr(t0, rt);
1111 save_cpu_state(ctx, 1);
1112 gen_load_gpr(t1, rt);
1113 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1114 gen_store_gpr(t1, rt);
1118 save_cpu_state(ctx, 1);
1119 gen_load_gpr(t1, rt);
1120 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1124 save_cpu_state(ctx, 1);
1125 gen_load_gpr(t1, rt);
1126 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1127 gen_store_gpr(t1, rt);
1131 save_cpu_state(ctx, 1);
1132 gen_load_gpr(t1, rt);
1133 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1138 op_ldst_lw(t0, ctx);
1139 gen_store_gpr(t0, rt);
1143 gen_load_gpr(t1, rt);
1144 op_ldst_sw(t0, t1, ctx);
1148 op_ldst_lh(t0, ctx);
1149 gen_store_gpr(t0, rt);
1153 gen_load_gpr(t1, rt);
1154 op_ldst_sh(t0, t1, ctx);
1158 op_ldst_lhu(t0, ctx);
1159 gen_store_gpr(t0, rt);
1163 op_ldst_lb(t0, ctx);
1164 gen_store_gpr(t0, rt);
1168 gen_load_gpr(t1, rt);
1169 op_ldst_sb(t0, t1, ctx);
1173 op_ldst_lbu(t0, ctx);
1174 gen_store_gpr(t0, rt);
1178 save_cpu_state(ctx, 1);
1179 gen_load_gpr(t1, rt);
1180 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1181 gen_store_gpr(t1, rt);
1185 save_cpu_state(ctx, 1);
1186 gen_load_gpr(t1, rt);
1187 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1191 save_cpu_state(ctx, 1);
1192 gen_load_gpr(t1, rt);
1193 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1194 gen_store_gpr(t1, rt);
1198 save_cpu_state(ctx, 1);
1199 gen_load_gpr(t1, rt);
1200 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1204 op_ldst_ll(t0, t1, ctx);
1205 gen_store_gpr(t0, rt);
1209 save_cpu_state(ctx, 1);
1210 gen_load_gpr(t1, rt);
1211 op_ldst_sc(t0, t1, ctx);
1212 gen_store_gpr(t0, rt);
1217 generate_exception(ctx, EXCP_RI);
1220 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1226 /* Load and store */
1227 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1228 int base, int16_t offset)
1230 const char *opn = "flt_ldst";
1231 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1234 tcg_gen_movi_tl(t0, offset);
1235 } else if (offset == 0) {
1236 gen_load_gpr(t0, base);
1238 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1240 gen_load_gpr(t0, base);
1241 tcg_gen_movi_tl(t1, offset);
1242 gen_op_addr_add(t0, t1);
1245 /* Don't do NOP if destination is zero: we must perform the actual
1250 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1252 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
1253 gen_store_fpr32(fp0, ft);
1260 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1262 gen_load_fpr32(fp0, ft);
1263 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
1270 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1272 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1273 gen_store_fpr64(ctx, fp0, ft);
1280 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1282 gen_load_fpr64(ctx, fp0, ft);
1283 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1290 generate_exception(ctx, EXCP_RI);
1293 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1298 /* Arithmetic with immediate operand */
1299 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1300 int rt, int rs, int16_t imm)
1303 const char *opn = "imm arith";
1304 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1306 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1307 /* If no destination, treat it as a NOP.
1308 For addi, we must generate the overflow exception when needed. */
1312 uimm = (uint16_t)imm;
1316 #if defined(TARGET_MIPS64)
1322 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1327 gen_load_gpr(t0, rs);
1330 tcg_gen_movi_tl(t0, imm << 16);
1335 #if defined(TARGET_MIPS64)
1344 gen_load_gpr(t0, rs);
1350 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1351 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1352 int l1 = gen_new_label();
1354 save_cpu_state(ctx, 1);
1355 tcg_gen_ext32s_tl(r_tmp1, t0);
1356 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1358 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1359 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1360 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1361 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1362 tcg_temp_free(r_tmp2);
1363 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1364 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1365 tcg_temp_free(r_tmp1);
1366 /* operands of same sign, result different sign */
1367 generate_exception(ctx, EXCP_OVERFLOW);
1370 tcg_gen_ext32s_tl(t0, t0);
1375 tcg_gen_ext32s_tl(t0, t0);
1376 tcg_gen_addi_tl(t0, t0, uimm);
1377 tcg_gen_ext32s_tl(t0, t0);
1380 #if defined(TARGET_MIPS64)
1383 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1384 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1385 int l1 = gen_new_label();
1387 save_cpu_state(ctx, 1);
1388 tcg_gen_mov_tl(r_tmp1, t0);
1389 tcg_gen_addi_tl(t0, t0, uimm);
1391 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1392 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1393 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1394 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1395 tcg_temp_free(r_tmp2);
1396 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1397 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1398 tcg_temp_free(r_tmp1);
1399 /* operands of same sign, result different sign */
1400 generate_exception(ctx, EXCP_OVERFLOW);
1406 tcg_gen_addi_tl(t0, t0, uimm);
1411 gen_op_lti(t0, uimm);
1415 gen_op_ltiu(t0, uimm);
1419 tcg_gen_andi_tl(t0, t0, uimm);
1423 tcg_gen_ori_tl(t0, t0, uimm);
1427 tcg_gen_xori_tl(t0, t0, uimm);
1434 tcg_gen_ext32u_tl(t0, t0);
1435 tcg_gen_shli_tl(t0, t0, uimm);
1436 tcg_gen_ext32s_tl(t0, t0);
1440 tcg_gen_ext32s_tl(t0, t0);
1441 tcg_gen_sari_tl(t0, t0, uimm);
1442 tcg_gen_ext32s_tl(t0, t0);
1446 switch ((ctx->opcode >> 21) & 0x1f) {
1448 tcg_gen_ext32u_tl(t0, t0);
1449 tcg_gen_shri_tl(t0, t0, uimm);
1450 tcg_gen_ext32s_tl(t0, t0);
1454 /* rotr is decoded as srl on non-R2 CPUs */
1455 if (env->insn_flags & ISA_MIPS32R2) {
1457 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1458 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1460 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1461 tcg_gen_movi_i32(r_tmp2, 0x20);
1462 tcg_gen_subi_i32(r_tmp2, r_tmp2, uimm);
1463 tcg_gen_shl_i32(r_tmp2, r_tmp1, r_tmp2);
1464 tcg_gen_shri_i32(r_tmp1, r_tmp1, uimm);
1465 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp2);
1466 tcg_gen_ext_i32_tl(t0, r_tmp1);
1467 tcg_temp_free(r_tmp1);
1468 tcg_temp_free(r_tmp2);
1472 tcg_gen_ext32u_tl(t0, t0);
1473 tcg_gen_shri_tl(t0, t0, uimm);
1474 tcg_gen_ext32s_tl(t0, t0);
1479 MIPS_INVAL("invalid srl flag");
1480 generate_exception(ctx, EXCP_RI);
1484 #if defined(TARGET_MIPS64)
1486 tcg_gen_shli_tl(t0, t0, uimm);
1490 tcg_gen_sari_tl(t0, t0, uimm);
1494 switch ((ctx->opcode >> 21) & 0x1f) {
1496 tcg_gen_shri_tl(t0, t0, uimm);
1500 /* drotr is decoded as dsrl on non-R2 CPUs */
1501 if (env->insn_flags & ISA_MIPS32R2) {
1503 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1505 tcg_gen_movi_tl(r_tmp1, 0x40);
1506 tcg_gen_subi_tl(r_tmp1, r_tmp1, uimm);
1507 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1508 tcg_gen_shri_tl(t0, t0, uimm);
1509 tcg_gen_or_tl(t0, t0, r_tmp1);
1510 tcg_temp_free(r_tmp1);
1514 tcg_gen_shri_tl(t0, t0, uimm);
1519 MIPS_INVAL("invalid dsrl flag");
1520 generate_exception(ctx, EXCP_RI);
1525 tcg_gen_shli_tl(t0, t0, uimm + 32);
1529 tcg_gen_sari_tl(t0, t0, uimm + 32);
1533 switch ((ctx->opcode >> 21) & 0x1f) {
1535 tcg_gen_shri_tl(t0, t0, uimm + 32);
1539 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1540 if (env->insn_flags & ISA_MIPS32R2) {
1541 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1542 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1544 tcg_gen_movi_tl(r_tmp1, 0x40);
1545 tcg_gen_movi_tl(r_tmp2, 32);
1546 tcg_gen_addi_tl(r_tmp2, r_tmp2, uimm);
1547 tcg_gen_sub_tl(r_tmp1, r_tmp1, r_tmp2);
1548 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1549 tcg_gen_shr_tl(t0, t0, r_tmp2);
1550 tcg_gen_or_tl(t0, t0, r_tmp1);
1551 tcg_temp_free(r_tmp1);
1552 tcg_temp_free(r_tmp2);
1555 tcg_gen_shri_tl(t0, t0, uimm + 32);
1560 MIPS_INVAL("invalid dsrl32 flag");
1561 generate_exception(ctx, EXCP_RI);
1568 generate_exception(ctx, EXCP_RI);
1571 gen_store_gpr(t0, rt);
1572 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1578 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1579 int rd, int rs, int rt)
1581 const char *opn = "arith";
1582 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1583 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1585 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1586 && opc != OPC_DADD && opc != OPC_DSUB) {
1587 /* If no destination, treat it as a NOP.
1588 For add & sub, we must generate the overflow exception when needed. */
1592 gen_load_gpr(t0, rs);
1593 /* Specialcase the conventional move operation. */
1594 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1595 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1596 gen_store_gpr(t0, rd);
1599 gen_load_gpr(t1, rt);
1603 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1604 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1605 int l1 = gen_new_label();
1607 save_cpu_state(ctx, 1);
1608 tcg_gen_ext32s_tl(r_tmp1, t0);
1609 tcg_gen_ext32s_tl(r_tmp2, t1);
1610 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1612 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1613 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1614 tcg_gen_xor_tl(r_tmp2, t0, t1);
1615 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1616 tcg_temp_free(r_tmp2);
1617 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1618 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1619 tcg_temp_free(r_tmp1);
1620 /* operands of same sign, result different sign */
1621 generate_exception(ctx, EXCP_OVERFLOW);
1624 tcg_gen_ext32s_tl(t0, t0);
1629 tcg_gen_ext32s_tl(t0, t0);
1630 tcg_gen_ext32s_tl(t1, t1);
1631 tcg_gen_add_tl(t0, t0, t1);
1632 tcg_gen_ext32s_tl(t0, t0);
1637 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1638 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1639 int l1 = gen_new_label();
1641 save_cpu_state(ctx, 1);
1642 tcg_gen_ext32s_tl(r_tmp1, t0);
1643 tcg_gen_ext32s_tl(r_tmp2, t1);
1644 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1646 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1647 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1648 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1649 tcg_temp_free(r_tmp2);
1650 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1651 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1652 tcg_temp_free(r_tmp1);
1653 /* operands of different sign, first operand and result different sign */
1654 generate_exception(ctx, EXCP_OVERFLOW);
1657 tcg_gen_ext32s_tl(t0, t0);
1662 tcg_gen_ext32s_tl(t0, t0);
1663 tcg_gen_ext32s_tl(t1, t1);
1664 tcg_gen_sub_tl(t0, t0, t1);
1665 tcg_gen_ext32s_tl(t0, t0);
1668 #if defined(TARGET_MIPS64)
1671 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1672 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1673 int l1 = gen_new_label();
1675 save_cpu_state(ctx, 1);
1676 tcg_gen_mov_tl(r_tmp1, t0);
1677 tcg_gen_add_tl(t0, t0, t1);
1679 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1680 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1681 tcg_gen_xor_tl(r_tmp2, t0, t1);
1682 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1683 tcg_temp_free(r_tmp2);
1684 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1685 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1686 tcg_temp_free(r_tmp1);
1687 /* operands of same sign, result different sign */
1688 generate_exception(ctx, EXCP_OVERFLOW);
1694 tcg_gen_add_tl(t0, t0, t1);
1699 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1700 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1701 int l1 = gen_new_label();
1703 save_cpu_state(ctx, 1);
1704 tcg_gen_mov_tl(r_tmp1, t0);
1705 tcg_gen_sub_tl(t0, t0, t1);
1707 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1708 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1709 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1710 tcg_temp_free(r_tmp2);
1711 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1712 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1713 tcg_temp_free(r_tmp1);
1714 /* operands of different sign, first operand and result different sign */
1715 generate_exception(ctx, EXCP_OVERFLOW);
1721 tcg_gen_sub_tl(t0, t0, t1);
1734 tcg_gen_and_tl(t0, t0, t1);
1738 tcg_gen_or_tl(t0, t0, t1);
1739 tcg_gen_not_tl(t0, t0);
1743 tcg_gen_or_tl(t0, t0, t1);
1747 tcg_gen_xor_tl(t0, t0, t1);
1751 tcg_gen_ext32s_tl(t0, t0);
1752 tcg_gen_ext32s_tl(t1, t1);
1753 tcg_gen_mul_tl(t0, t0, t1);
1754 tcg_gen_ext32s_tl(t0, t0);
1759 int l1 = gen_new_label();
1761 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1762 gen_store_gpr(t0, rd);
1769 int l1 = gen_new_label();
1771 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1772 gen_store_gpr(t0, rd);
1778 tcg_gen_ext32u_tl(t0, t0);
1779 tcg_gen_ext32u_tl(t1, t1);
1780 tcg_gen_andi_tl(t0, t0, 0x1f);
1781 tcg_gen_shl_tl(t0, t1, t0);
1782 tcg_gen_ext32s_tl(t0, t0);
1786 tcg_gen_ext32s_tl(t1, t1);
1787 tcg_gen_andi_tl(t0, t0, 0x1f);
1788 tcg_gen_sar_tl(t0, t1, t0);
1789 tcg_gen_ext32s_tl(t0, t0);
1793 switch ((ctx->opcode >> 6) & 0x1f) {
1795 tcg_gen_ext32u_tl(t1, t1);
1796 tcg_gen_andi_tl(t0, t0, 0x1f);
1797 tcg_gen_shr_tl(t0, t1, t0);
1798 tcg_gen_ext32s_tl(t0, t0);
1802 /* rotrv is decoded as srlv on non-R2 CPUs */
1803 if (env->insn_flags & ISA_MIPS32R2) {
1804 int l1 = gen_new_label();
1805 int l2 = gen_new_label();
1807 tcg_gen_andi_tl(t0, t0, 0x1f);
1808 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1810 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1811 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1812 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1814 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1815 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1816 tcg_gen_movi_i32(r_tmp3, 0x20);
1817 tcg_gen_sub_i32(r_tmp3, r_tmp3, r_tmp1);
1818 tcg_gen_shl_i32(r_tmp3, r_tmp2, r_tmp3);
1819 tcg_gen_shr_i32(r_tmp1, r_tmp2, r_tmp1);
1820 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp3);
1821 tcg_gen_ext_i32_tl(t0, r_tmp1);
1822 tcg_temp_free(r_tmp1);
1823 tcg_temp_free(r_tmp2);
1824 tcg_temp_free(r_tmp3);
1828 tcg_gen_mov_tl(t0, t1);
1832 tcg_gen_ext32u_tl(t1, t1);
1833 tcg_gen_andi_tl(t0, t0, 0x1f);
1834 tcg_gen_shr_tl(t0, t1, t0);
1835 tcg_gen_ext32s_tl(t0, t0);
1840 MIPS_INVAL("invalid srlv flag");
1841 generate_exception(ctx, EXCP_RI);
1845 #if defined(TARGET_MIPS64)
1847 tcg_gen_andi_tl(t0, t0, 0x3f);
1848 tcg_gen_shl_tl(t0, t1, t0);
1852 tcg_gen_andi_tl(t0, t0, 0x3f);
1853 tcg_gen_sar_tl(t0, t1, t0);
1857 switch ((ctx->opcode >> 6) & 0x1f) {
1859 tcg_gen_andi_tl(t0, t0, 0x3f);
1860 tcg_gen_shr_tl(t0, t1, t0);
1864 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1865 if (env->insn_flags & ISA_MIPS32R2) {
1866 int l1 = gen_new_label();
1867 int l2 = gen_new_label();
1869 tcg_gen_andi_tl(t0, t0, 0x3f);
1870 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1872 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1874 tcg_gen_movi_tl(r_tmp1, 0x40);
1875 tcg_gen_sub_tl(r_tmp1, r_tmp1, t0);
1876 tcg_gen_shl_tl(r_tmp1, t1, r_tmp1);
1877 tcg_gen_shr_tl(t0, t1, t0);
1878 tcg_gen_or_tl(t0, t0, r_tmp1);
1879 tcg_temp_free(r_tmp1);
1883 tcg_gen_mov_tl(t0, t1);
1887 tcg_gen_andi_tl(t0, t0, 0x3f);
1888 tcg_gen_shr_tl(t0, t1, t0);
1893 MIPS_INVAL("invalid dsrlv flag");
1894 generate_exception(ctx, EXCP_RI);
1901 generate_exception(ctx, EXCP_RI);
1904 gen_store_gpr(t0, rd);
1906 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1912 /* Arithmetic on HI/LO registers */
1913 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1915 const char *opn = "hilo";
1916 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1918 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1926 gen_store_gpr(t0, reg);
1931 gen_store_gpr(t0, reg);
1935 gen_load_gpr(t0, reg);
1936 gen_store_HI(t0, 0);
1940 gen_load_gpr(t0, reg);
1941 gen_store_LO(t0, 0);
1946 generate_exception(ctx, EXCP_RI);
1949 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1954 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1957 const char *opn = "mul/div";
1958 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1959 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1961 gen_load_gpr(t0, rs);
1962 gen_load_gpr(t1, rt);
1966 int l1 = gen_new_label();
1968 tcg_gen_ext32s_tl(t0, t0);
1969 tcg_gen_ext32s_tl(t1, t1);
1970 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1972 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1973 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1974 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1976 tcg_gen_ext_tl_i64(r_tmp1, t0);
1977 tcg_gen_ext_tl_i64(r_tmp2, t1);
1978 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1979 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1980 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1981 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1982 tcg_temp_free(r_tmp1);
1983 tcg_temp_free(r_tmp2);
1984 tcg_temp_free(r_tmp3);
1985 tcg_gen_ext32s_tl(t0, t0);
1986 tcg_gen_ext32s_tl(t1, t1);
1987 gen_store_LO(t0, 0);
1988 gen_store_HI(t1, 0);
1996 int l1 = gen_new_label();
1998 tcg_gen_ext32s_tl(t1, t1);
1999 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2001 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
2002 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
2003 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
2005 tcg_gen_trunc_tl_i32(r_tmp1, t0);
2006 tcg_gen_trunc_tl_i32(r_tmp2, t1);
2007 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
2008 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
2009 tcg_gen_ext_i32_tl(t0, r_tmp3);
2010 tcg_gen_ext_i32_tl(t1, r_tmp1);
2011 tcg_temp_free(r_tmp1);
2012 tcg_temp_free(r_tmp2);
2013 tcg_temp_free(r_tmp3);
2014 gen_store_LO(t0, 0);
2015 gen_store_HI(t1, 0);
2023 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2024 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2026 tcg_gen_ext32s_tl(t0, t0);
2027 tcg_gen_ext32s_tl(t1, t1);
2028 tcg_gen_ext_tl_i64(r_tmp1, t0);
2029 tcg_gen_ext_tl_i64(r_tmp2, t1);
2030 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2031 tcg_temp_free(r_tmp2);
2032 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2033 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2034 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2035 tcg_temp_free(r_tmp1);
2036 tcg_gen_ext32s_tl(t0, t0);
2037 tcg_gen_ext32s_tl(t1, t1);
2038 gen_store_LO(t0, 0);
2039 gen_store_HI(t1, 0);
2045 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2046 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2048 tcg_gen_ext32u_tl(t0, t0);
2049 tcg_gen_ext32u_tl(t1, t1);
2050 tcg_gen_extu_tl_i64(r_tmp1, t0);
2051 tcg_gen_extu_tl_i64(r_tmp2, t1);
2052 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2053 tcg_temp_free(r_tmp2);
2054 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2055 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2056 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2057 tcg_temp_free(r_tmp1);
2058 tcg_gen_ext32s_tl(t0, t0);
2059 tcg_gen_ext32s_tl(t1, t1);
2060 gen_store_LO(t0, 0);
2061 gen_store_HI(t1, 0);
2065 #if defined(TARGET_MIPS64)
2068 int l1 = gen_new_label();
2070 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2072 int l2 = gen_new_label();
2074 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2075 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2077 tcg_gen_movi_tl(t1, 0);
2078 gen_store_LO(t0, 0);
2079 gen_store_HI(t1, 0);
2084 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2085 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2087 tcg_gen_div_i64(r_tmp1, t0, t1);
2088 tcg_gen_rem_i64(r_tmp2, t0, t1);
2089 gen_store_LO(r_tmp1, 0);
2090 gen_store_HI(r_tmp2, 0);
2091 tcg_temp_free(r_tmp1);
2092 tcg_temp_free(r_tmp2);
2101 int l1 = gen_new_label();
2103 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2105 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2106 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2108 tcg_gen_divu_i64(r_tmp1, t0, t1);
2109 tcg_gen_remu_i64(r_tmp2, t0, t1);
2110 tcg_temp_free(r_tmp1);
2111 tcg_temp_free(r_tmp2);
2112 gen_store_LO(r_tmp1, 0);
2113 gen_store_HI(r_tmp2, 0);
2120 tcg_gen_helper_0_2(do_dmult, t0, t1);
2124 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2130 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2131 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2132 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2134 tcg_gen_ext32s_tl(t0, t0);
2135 tcg_gen_ext32s_tl(t1, t1);
2136 tcg_gen_ext_tl_i64(r_tmp1, t0);
2137 tcg_gen_ext_tl_i64(r_tmp2, t1);
2138 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2141 tcg_gen_extu_tl_i64(r_tmp2, t0);
2142 tcg_gen_extu_tl_i64(r_tmp3, t1);
2143 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2144 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2145 tcg_temp_free(r_tmp3);
2146 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2147 tcg_temp_free(r_tmp2);
2148 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2149 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2150 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2151 tcg_temp_free(r_tmp1);
2152 tcg_gen_ext32s_tl(t0, t0);
2153 tcg_gen_ext32s_tl(t1, t1);
2154 gen_store_LO(t0, 0);
2155 gen_store_HI(t1, 0);
2161 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2162 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2163 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2165 tcg_gen_ext32u_tl(t0, t0);
2166 tcg_gen_ext32u_tl(t1, t1);
2167 tcg_gen_extu_tl_i64(r_tmp1, t0);
2168 tcg_gen_extu_tl_i64(r_tmp2, t1);
2169 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2172 tcg_gen_extu_tl_i64(r_tmp2, t0);
2173 tcg_gen_extu_tl_i64(r_tmp3, t1);
2174 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2175 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2176 tcg_temp_free(r_tmp3);
2177 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2178 tcg_temp_free(r_tmp2);
2179 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2180 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2181 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2182 tcg_temp_free(r_tmp1);
2183 tcg_gen_ext32s_tl(t0, t0);
2184 tcg_gen_ext32s_tl(t1, t1);
2185 gen_store_LO(t0, 0);
2186 gen_store_HI(t1, 0);
2192 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2193 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2194 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2196 tcg_gen_ext32s_tl(t0, t0);
2197 tcg_gen_ext32s_tl(t1, t1);
2198 tcg_gen_ext_tl_i64(r_tmp1, t0);
2199 tcg_gen_ext_tl_i64(r_tmp2, t1);
2200 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2203 tcg_gen_extu_tl_i64(r_tmp2, t0);
2204 tcg_gen_extu_tl_i64(r_tmp3, t1);
2205 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2206 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2207 tcg_temp_free(r_tmp3);
2208 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2209 tcg_temp_free(r_tmp2);
2210 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2211 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2212 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2213 tcg_temp_free(r_tmp1);
2214 tcg_gen_ext32s_tl(t0, t0);
2215 tcg_gen_ext32s_tl(t1, t1);
2216 gen_store_LO(t0, 0);
2217 gen_store_HI(t1, 0);
2223 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2224 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2225 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2227 tcg_gen_ext32u_tl(t0, t0);
2228 tcg_gen_ext32u_tl(t1, t1);
2229 tcg_gen_extu_tl_i64(r_tmp1, t0);
2230 tcg_gen_extu_tl_i64(r_tmp2, t1);
2231 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2234 tcg_gen_extu_tl_i64(r_tmp2, t0);
2235 tcg_gen_extu_tl_i64(r_tmp3, t1);
2236 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2237 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2238 tcg_temp_free(r_tmp3);
2239 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2240 tcg_temp_free(r_tmp2);
2241 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2242 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2243 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2244 tcg_temp_free(r_tmp1);
2245 tcg_gen_ext32s_tl(t0, t0);
2246 tcg_gen_ext32s_tl(t1, t1);
2247 gen_store_LO(t0, 0);
2248 gen_store_HI(t1, 0);
2254 generate_exception(ctx, EXCP_RI);
2257 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2263 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2264 int rd, int rs, int rt)
2266 const char *opn = "mul vr54xx";
2267 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2268 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2270 gen_load_gpr(t0, rs);
2271 gen_load_gpr(t1, rt);
2274 case OPC_VR54XX_MULS:
2275 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2278 case OPC_VR54XX_MULSU:
2279 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2282 case OPC_VR54XX_MACC:
2283 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2286 case OPC_VR54XX_MACCU:
2287 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2290 case OPC_VR54XX_MSAC:
2291 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2294 case OPC_VR54XX_MSACU:
2295 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2298 case OPC_VR54XX_MULHI:
2299 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2302 case OPC_VR54XX_MULHIU:
2303 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2306 case OPC_VR54XX_MULSHI:
2307 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2310 case OPC_VR54XX_MULSHIU:
2311 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2314 case OPC_VR54XX_MACCHI:
2315 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2318 case OPC_VR54XX_MACCHIU:
2319 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2322 case OPC_VR54XX_MSACHI:
2323 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2326 case OPC_VR54XX_MSACHIU:
2327 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2331 MIPS_INVAL("mul vr54xx");
2332 generate_exception(ctx, EXCP_RI);
2335 gen_store_gpr(t0, rd);
2336 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2343 static void gen_cl (DisasContext *ctx, uint32_t opc,
2346 const char *opn = "CLx";
2347 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2354 gen_load_gpr(t0, rs);
2357 tcg_gen_helper_1_1(do_clo, t0, t0);
2361 tcg_gen_helper_1_1(do_clz, t0, t0);
2364 #if defined(TARGET_MIPS64)
2366 tcg_gen_helper_1_1(do_dclo, t0, t0);
2370 tcg_gen_helper_1_1(do_dclz, t0, t0);
2376 generate_exception(ctx, EXCP_RI);
2379 gen_store_gpr(t0, rd);
2380 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2387 static void gen_trap (DisasContext *ctx, uint32_t opc,
2388 int rs, int rt, int16_t imm)
2391 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2392 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2395 /* Load needed operands */
2403 /* Compare two registers */
2405 gen_load_gpr(t0, rs);
2406 gen_load_gpr(t1, rt);
2416 /* Compare register to immediate */
2417 if (rs != 0 || imm != 0) {
2418 gen_load_gpr(t0, rs);
2419 tcg_gen_movi_tl(t1, (int32_t)imm);
2426 case OPC_TEQ: /* rs == rs */
2427 case OPC_TEQI: /* r0 == 0 */
2428 case OPC_TGE: /* rs >= rs */
2429 case OPC_TGEI: /* r0 >= 0 */
2430 case OPC_TGEU: /* rs >= rs unsigned */
2431 case OPC_TGEIU: /* r0 >= 0 unsigned */
2433 tcg_gen_movi_tl(t0, 1);
2435 case OPC_TLT: /* rs < rs */
2436 case OPC_TLTI: /* r0 < 0 */
2437 case OPC_TLTU: /* rs < rs unsigned */
2438 case OPC_TLTIU: /* r0 < 0 unsigned */
2439 case OPC_TNE: /* rs != rs */
2440 case OPC_TNEI: /* r0 != 0 */
2441 /* Never trap: treat as NOP. */
2445 generate_exception(ctx, EXCP_RI);
2476 generate_exception(ctx, EXCP_RI);
2480 save_cpu_state(ctx, 1);
2482 int l1 = gen_new_label();
2484 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2485 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2488 ctx->bstate = BS_STOP;
2494 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2496 TranslationBlock *tb;
2498 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2501 tcg_gen_exit_tb((long)tb + n);
2508 /* Branches (before delay slot) */
2509 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2510 int rs, int rt, int32_t offset)
2512 target_ulong btgt = -1;
2514 int bcond_compute = 0;
2515 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2516 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2518 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2519 #ifdef MIPS_DEBUG_DISAS
2520 if (loglevel & CPU_LOG_TB_IN_ASM) {
2522 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2526 generate_exception(ctx, EXCP_RI);
2530 /* Load needed operands */
2536 /* Compare two registers */
2538 gen_load_gpr(t0, rs);
2539 gen_load_gpr(t1, rt);
2542 btgt = ctx->pc + 4 + offset;
2556 /* Compare to zero */
2558 gen_load_gpr(t0, rs);
2561 btgt = ctx->pc + 4 + offset;
2565 /* Jump to immediate */
2566 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2570 /* Jump to register */
2571 if (offset != 0 && offset != 16) {
2572 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2573 others are reserved. */
2574 MIPS_INVAL("jump hint");
2575 generate_exception(ctx, EXCP_RI);
2578 gen_load_gpr(btarget, rs);
2581 MIPS_INVAL("branch/jump");
2582 generate_exception(ctx, EXCP_RI);
2585 if (bcond_compute == 0) {
2586 /* No condition to be computed */
2588 case OPC_BEQ: /* rx == rx */
2589 case OPC_BEQL: /* rx == rx likely */
2590 case OPC_BGEZ: /* 0 >= 0 */
2591 case OPC_BGEZL: /* 0 >= 0 likely */
2592 case OPC_BLEZ: /* 0 <= 0 */
2593 case OPC_BLEZL: /* 0 <= 0 likely */
2595 ctx->hflags |= MIPS_HFLAG_B;
2596 MIPS_DEBUG("balways");
2598 case OPC_BGEZAL: /* 0 >= 0 */
2599 case OPC_BGEZALL: /* 0 >= 0 likely */
2600 /* Always take and link */
2602 ctx->hflags |= MIPS_HFLAG_B;
2603 MIPS_DEBUG("balways and link");
2605 case OPC_BNE: /* rx != rx */
2606 case OPC_BGTZ: /* 0 > 0 */
2607 case OPC_BLTZ: /* 0 < 0 */
2609 MIPS_DEBUG("bnever (NOP)");
2611 case OPC_BLTZAL: /* 0 < 0 */
2612 tcg_gen_movi_tl(t0, ctx->pc + 8);
2613 gen_store_gpr(t0, 31);
2614 MIPS_DEBUG("bnever and link");
2616 case OPC_BLTZALL: /* 0 < 0 likely */
2617 tcg_gen_movi_tl(t0, ctx->pc + 8);
2618 gen_store_gpr(t0, 31);
2619 /* Skip the instruction in the delay slot */
2620 MIPS_DEBUG("bnever, link and skip");
2623 case OPC_BNEL: /* rx != rx likely */
2624 case OPC_BGTZL: /* 0 > 0 likely */
2625 case OPC_BLTZL: /* 0 < 0 likely */
2626 /* Skip the instruction in the delay slot */
2627 MIPS_DEBUG("bnever and skip");
2631 ctx->hflags |= MIPS_HFLAG_B;
2632 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2636 ctx->hflags |= MIPS_HFLAG_B;
2637 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2640 ctx->hflags |= MIPS_HFLAG_BR;
2641 MIPS_DEBUG("jr %s", regnames[rs]);
2645 ctx->hflags |= MIPS_HFLAG_BR;
2646 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2649 MIPS_INVAL("branch/jump");
2650 generate_exception(ctx, EXCP_RI);
2657 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2658 regnames[rs], regnames[rt], btgt);
2662 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2663 regnames[rs], regnames[rt], btgt);
2667 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2668 regnames[rs], regnames[rt], btgt);
2672 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2673 regnames[rs], regnames[rt], btgt);
2677 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2681 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2685 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2691 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2695 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2699 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2703 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2707 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2711 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2715 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2720 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2722 ctx->hflags |= MIPS_HFLAG_BC;
2723 tcg_gen_trunc_tl_i32(bcond, t0);
2728 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2730 ctx->hflags |= MIPS_HFLAG_BL;
2731 tcg_gen_trunc_tl_i32(bcond, t0);
2734 MIPS_INVAL("conditional branch/jump");
2735 generate_exception(ctx, EXCP_RI);
2739 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2740 blink, ctx->hflags, btgt);
2742 ctx->btarget = btgt;
2744 tcg_gen_movi_tl(t0, ctx->pc + 8);
2745 gen_store_gpr(t0, blink);
2753 /* special3 bitfield operations */
2754 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2755 int rs, int lsb, int msb)
2757 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2758 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2760 gen_load_gpr(t1, rs);
2765 tcg_gen_helper_1_1ii(do_ext, t0, t1, lsb, msb + 1);
2767 #if defined(TARGET_MIPS64)
2771 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1 + 32);
2776 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb + 32, msb + 1);
2781 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1);
2787 gen_load_gpr(t0, rt);
2788 tcg_gen_helper_1_2ii(do_ins, t0, t0, t1, lsb, msb - lsb + 1);
2790 #if defined(TARGET_MIPS64)
2794 gen_load_gpr(t0, rt);
2795 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1 + 32);
2800 gen_load_gpr(t0, rt);
2801 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb + 32, msb - lsb + 1);
2806 gen_load_gpr(t0, rt);
2807 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1);
2812 MIPS_INVAL("bitops");
2813 generate_exception(ctx, EXCP_RI);
2818 gen_store_gpr(t0, rt);
2823 #ifndef CONFIG_USER_ONLY
2824 /* CP0 (MMU and control) */
2825 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2827 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2829 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2830 tcg_gen_ext_i32_tl(t, r_tmp);
2831 tcg_temp_free(r_tmp);
2834 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2836 tcg_gen_ld_tl(t, cpu_env, off);
2837 tcg_gen_ext32s_tl(t, t);
2840 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2842 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2844 tcg_gen_trunc_tl_i32(r_tmp, t);
2845 tcg_gen_st_i32(r_tmp, cpu_env, off);
2846 tcg_temp_free(r_tmp);
2849 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2851 tcg_gen_ext32s_tl(t, t);
2852 tcg_gen_st_tl(t, cpu_env, off);
2855 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2857 const char *rn = "invalid";
2860 check_insn(env, ctx, ISA_MIPS32);
2866 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2870 check_insn(env, ctx, ASE_MT);
2871 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2875 check_insn(env, ctx, ASE_MT);
2876 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2880 check_insn(env, ctx, ASE_MT);
2881 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2891 tcg_gen_helper_1_0(do_mfc0_random, t0);
2895 check_insn(env, ctx, ASE_MT);
2896 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2900 check_insn(env, ctx, ASE_MT);
2901 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2905 check_insn(env, ctx, ASE_MT);
2906 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2910 check_insn(env, ctx, ASE_MT);
2911 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2915 check_insn(env, ctx, ASE_MT);
2916 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2920 check_insn(env, ctx, ASE_MT);
2921 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2922 rn = "VPEScheFBack";
2925 check_insn(env, ctx, ASE_MT);
2926 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2936 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2937 tcg_gen_ext32s_tl(t0, t0);
2941 check_insn(env, ctx, ASE_MT);
2942 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2946 check_insn(env, ctx, ASE_MT);
2947 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2951 check_insn(env, ctx, ASE_MT);
2952 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2956 check_insn(env, ctx, ASE_MT);
2957 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2961 check_insn(env, ctx, ASE_MT);
2962 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2966 check_insn(env, ctx, ASE_MT);
2967 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2971 check_insn(env, ctx, ASE_MT);
2972 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2982 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2983 tcg_gen_ext32s_tl(t0, t0);
2993 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2994 tcg_gen_ext32s_tl(t0, t0);
2998 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2999 rn = "ContextConfig";
3008 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
3012 check_insn(env, ctx, ISA_MIPS32R2);
3013 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
3023 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
3027 check_insn(env, ctx, ISA_MIPS32R2);
3028 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
3032 check_insn(env, ctx, ISA_MIPS32R2);
3033 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
3037 check_insn(env, ctx, ISA_MIPS32R2);
3038 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
3042 check_insn(env, ctx, ISA_MIPS32R2);
3043 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
3047 check_insn(env, ctx, ISA_MIPS32R2);
3048 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
3058 check_insn(env, ctx, ISA_MIPS32R2);
3059 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
3069 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
3070 tcg_gen_ext32s_tl(t0, t0);
3080 /* Mark as an IO operation because we read the time. */
3083 tcg_gen_helper_1_0(do_mfc0_count, t0);
3086 ctx->bstate = BS_STOP;
3090 /* 6,7 are implementation dependent */
3098 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3099 tcg_gen_ext32s_tl(t0, t0);
3109 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3112 /* 6,7 are implementation dependent */
3120 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3124 check_insn(env, ctx, ISA_MIPS32R2);
3125 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3129 check_insn(env, ctx, ISA_MIPS32R2);
3130 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3134 check_insn(env, ctx, ISA_MIPS32R2);
3135 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3145 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3155 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3156 tcg_gen_ext32s_tl(t0, t0);
3166 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3170 check_insn(env, ctx, ISA_MIPS32R2);
3171 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3181 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3185 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3189 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3193 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3196 /* 4,5 are reserved */
3197 /* 6,7 are implementation dependent */
3199 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3203 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3213 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3223 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3233 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3243 #if defined(TARGET_MIPS64)
3244 check_insn(env, ctx, ISA_MIPS3);
3245 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3246 tcg_gen_ext32s_tl(t0, t0);
3255 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3258 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3267 rn = "'Diagnostic"; /* implementation dependent */
3272 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3276 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3277 rn = "TraceControl";
3280 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3281 rn = "TraceControl2";
3284 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3285 rn = "UserTraceData";
3288 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3299 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3300 tcg_gen_ext32s_tl(t0, t0);
3310 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3311 rn = "Performance0";
3314 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3315 rn = "Performance1";
3318 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3319 rn = "Performance2";
3322 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3323 rn = "Performance3";
3326 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3327 rn = "Performance4";
3330 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3331 rn = "Performance5";
3334 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3335 rn = "Performance6";
3338 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3339 rn = "Performance7";
3364 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3371 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3384 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3391 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3401 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3402 tcg_gen_ext32s_tl(t0, t0);
3413 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3423 #if defined MIPS_DEBUG_DISAS
3424 if (loglevel & CPU_LOG_TB_IN_ASM) {
3425 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3432 #if defined MIPS_DEBUG_DISAS
3433 if (loglevel & CPU_LOG_TB_IN_ASM) {
3434 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3438 generate_exception(ctx, EXCP_RI);
3441 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3443 const char *rn = "invalid";
3446 check_insn(env, ctx, ISA_MIPS32);
3455 tcg_gen_helper_0_1(do_mtc0_index, t0);
3459 check_insn(env, ctx, ASE_MT);
3460 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3464 check_insn(env, ctx, ASE_MT);
3469 check_insn(env, ctx, ASE_MT);
3484 check_insn(env, ctx, ASE_MT);
3485 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3489 check_insn(env, ctx, ASE_MT);
3490 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3494 check_insn(env, ctx, ASE_MT);
3495 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3499 check_insn(env, ctx, ASE_MT);
3500 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3504 check_insn(env, ctx, ASE_MT);
3505 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3509 check_insn(env, ctx, ASE_MT);
3510 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3511 rn = "VPEScheFBack";
3514 check_insn(env, ctx, ASE_MT);
3515 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3525 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3529 check_insn(env, ctx, ASE_MT);
3530 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3534 check_insn(env, ctx, ASE_MT);
3535 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3539 check_insn(env, ctx, ASE_MT);
3540 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3544 check_insn(env, ctx, ASE_MT);
3545 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3549 check_insn(env, ctx, ASE_MT);
3550 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3554 check_insn(env, ctx, ASE_MT);
3555 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3559 check_insn(env, ctx, ASE_MT);
3560 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3570 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3580 tcg_gen_helper_0_1(do_mtc0_context, t0);
3584 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3585 rn = "ContextConfig";
3594 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3598 check_insn(env, ctx, ISA_MIPS32R2);
3599 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3609 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3613 check_insn(env, ctx, ISA_MIPS32R2);
3614 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3618 check_insn(env, ctx, ISA_MIPS32R2);
3619 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3623 check_insn(env, ctx, ISA_MIPS32R2);
3624 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3628 check_insn(env, ctx, ISA_MIPS32R2);
3629 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3633 check_insn(env, ctx, ISA_MIPS32R2);
3634 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3644 check_insn(env, ctx, ISA_MIPS32R2);
3645 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3659 tcg_gen_helper_0_1(do_mtc0_count, t0);
3662 /* 6,7 are implementation dependent */
3666 /* Stop translation as we may have switched the execution mode */
3667 ctx->bstate = BS_STOP;
3672 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3682 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3685 /* 6,7 are implementation dependent */
3689 /* Stop translation as we may have switched the execution mode */
3690 ctx->bstate = BS_STOP;
3695 tcg_gen_helper_0_1(do_mtc0_status, t0);
3696 /* BS_STOP isn't good enough here, hflags may have changed. */
3697 gen_save_pc(ctx->pc + 4);
3698 ctx->bstate = BS_EXCP;
3702 check_insn(env, ctx, ISA_MIPS32R2);
3703 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3704 /* Stop translation as we may have switched the execution mode */
3705 ctx->bstate = BS_STOP;
3709 check_insn(env, ctx, ISA_MIPS32R2);
3710 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3711 /* Stop translation as we may have switched the execution mode */
3712 ctx->bstate = BS_STOP;
3716 check_insn(env, ctx, ISA_MIPS32R2);
3717 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3718 /* Stop translation as we may have switched the execution mode */
3719 ctx->bstate = BS_STOP;
3729 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3735 /* Stop translation as we may have switched the execution mode */
3736 ctx->bstate = BS_STOP;
3741 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3755 check_insn(env, ctx, ISA_MIPS32R2);
3756 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3766 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3768 /* Stop translation as we may have switched the execution mode */
3769 ctx->bstate = BS_STOP;
3772 /* ignored, read only */
3776 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3778 /* Stop translation as we may have switched the execution mode */
3779 ctx->bstate = BS_STOP;
3782 /* ignored, read only */
3785 /* 4,5 are reserved */
3786 /* 6,7 are implementation dependent */
3796 rn = "Invalid config selector";
3813 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3823 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3833 #if defined(TARGET_MIPS64)
3834 check_insn(env, ctx, ISA_MIPS3);
3835 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3844 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3847 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3856 rn = "Diagnostic"; /* implementation dependent */
3861 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3862 /* BS_STOP isn't good enough here, hflags may have changed. */
3863 gen_save_pc(ctx->pc + 4);
3864 ctx->bstate = BS_EXCP;
3868 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3869 rn = "TraceControl";
3870 /* Stop translation as we may have switched the execution mode */
3871 ctx->bstate = BS_STOP;
3874 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3875 rn = "TraceControl2";
3876 /* Stop translation as we may have switched the execution mode */
3877 ctx->bstate = BS_STOP;
3880 /* Stop translation as we may have switched the execution mode */
3881 ctx->bstate = BS_STOP;
3882 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3883 rn = "UserTraceData";
3884 /* Stop translation as we may have switched the execution mode */
3885 ctx->bstate = BS_STOP;
3888 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3889 /* Stop translation as we may have switched the execution mode */
3890 ctx->bstate = BS_STOP;
3901 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3911 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3912 rn = "Performance0";
3915 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3916 rn = "Performance1";
3919 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3920 rn = "Performance2";
3923 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3924 rn = "Performance3";
3927 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3928 rn = "Performance4";
3931 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3932 rn = "Performance5";
3935 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3936 rn = "Performance6";
3939 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3940 rn = "Performance7";
3966 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3973 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3986 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3993 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
4004 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
4015 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
4021 /* Stop translation as we may have switched the execution mode */
4022 ctx->bstate = BS_STOP;
4027 #if defined MIPS_DEBUG_DISAS
4028 if (loglevel & CPU_LOG_TB_IN_ASM) {
4029 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4033 /* For simplicity assume that all writes can cause interrupts. */
4036 ctx->bstate = BS_STOP;
4041 #if defined MIPS_DEBUG_DISAS
4042 if (loglevel & CPU_LOG_TB_IN_ASM) {
4043 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4047 generate_exception(ctx, EXCP_RI);
4050 #if defined(TARGET_MIPS64)
4051 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4053 const char *rn = "invalid";
4056 check_insn(env, ctx, ISA_MIPS64);
4062 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
4066 check_insn(env, ctx, ASE_MT);
4067 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
4071 check_insn(env, ctx, ASE_MT);
4072 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4076 check_insn(env, ctx, ASE_MT);
4077 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4087 tcg_gen_helper_1_0(do_mfc0_random, t0);
4091 check_insn(env, ctx, ASE_MT);
4092 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4096 check_insn(env, ctx, ASE_MT);
4097 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4101 check_insn(env, ctx, ASE_MT);
4102 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4106 check_insn(env, ctx, ASE_MT);
4107 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4111 check_insn(env, ctx, ASE_MT);
4112 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4116 check_insn(env, ctx, ASE_MT);
4117 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4118 rn = "VPEScheFBack";
4121 check_insn(env, ctx, ASE_MT);
4122 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4132 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4136 check_insn(env, ctx, ASE_MT);
4137 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4141 check_insn(env, ctx, ASE_MT);
4142 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4146 check_insn(env, ctx, ASE_MT);
4147 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4151 check_insn(env, ctx, ASE_MT);
4152 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4156 check_insn(env, ctx, ASE_MT);
4157 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4161 check_insn(env, ctx, ASE_MT);
4162 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4166 check_insn(env, ctx, ASE_MT);
4167 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4177 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4187 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4191 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4192 rn = "ContextConfig";
4201 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4205 check_insn(env, ctx, ISA_MIPS32R2);
4206 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4216 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4220 check_insn(env, ctx, ISA_MIPS32R2);
4221 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4225 check_insn(env, ctx, ISA_MIPS32R2);
4226 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4230 check_insn(env, ctx, ISA_MIPS32R2);
4231 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4235 check_insn(env, ctx, ISA_MIPS32R2);
4236 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4240 check_insn(env, ctx, ISA_MIPS32R2);
4241 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4251 check_insn(env, ctx, ISA_MIPS32R2);
4252 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4262 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4272 /* Mark as an IO operation because we read the time. */
4275 tcg_gen_helper_1_0(do_mfc0_count, t0);
4278 ctx->bstate = BS_STOP;
4282 /* 6,7 are implementation dependent */
4290 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4300 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4303 /* 6,7 are implementation dependent */
4311 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4315 check_insn(env, ctx, ISA_MIPS32R2);
4316 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4320 check_insn(env, ctx, ISA_MIPS32R2);
4321 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4325 check_insn(env, ctx, ISA_MIPS32R2);
4326 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4336 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4346 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4356 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4360 check_insn(env, ctx, ISA_MIPS32R2);
4361 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4371 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4375 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4379 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4383 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4386 /* 6,7 are implementation dependent */
4388 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4392 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4402 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4412 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4422 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4432 check_insn(env, ctx, ISA_MIPS3);
4433 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4441 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4444 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4453 rn = "'Diagnostic"; /* implementation dependent */
4458 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4462 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4463 rn = "TraceControl";
4466 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4467 rn = "TraceControl2";
4470 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4471 rn = "UserTraceData";
4474 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4485 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4495 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4496 rn = "Performance0";
4499 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4500 rn = "Performance1";
4503 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4504 rn = "Performance2";
4507 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4508 rn = "Performance3";
4511 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4512 rn = "Performance4";
4515 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4516 rn = "Performance5";
4519 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4520 rn = "Performance6";
4523 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4524 rn = "Performance7";
4549 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4556 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4569 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4576 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4586 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4597 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4607 #if defined MIPS_DEBUG_DISAS
4608 if (loglevel & CPU_LOG_TB_IN_ASM) {
4609 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4616 #if defined MIPS_DEBUG_DISAS
4617 if (loglevel & CPU_LOG_TB_IN_ASM) {
4618 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4622 generate_exception(ctx, EXCP_RI);
4625 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4627 const char *rn = "invalid";
4630 check_insn(env, ctx, ISA_MIPS64);
4639 tcg_gen_helper_0_1(do_mtc0_index, t0);
4643 check_insn(env, ctx, ASE_MT);
4644 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4648 check_insn(env, ctx, ASE_MT);
4653 check_insn(env, ctx, ASE_MT);
4668 check_insn(env, ctx, ASE_MT);
4669 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4673 check_insn(env, ctx, ASE_MT);
4674 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4678 check_insn(env, ctx, ASE_MT);
4679 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4683 check_insn(env, ctx, ASE_MT);
4684 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4688 check_insn(env, ctx, ASE_MT);
4689 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4693 check_insn(env, ctx, ASE_MT);
4694 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4695 rn = "VPEScheFBack";
4698 check_insn(env, ctx, ASE_MT);
4699 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4709 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4713 check_insn(env, ctx, ASE_MT);
4714 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4718 check_insn(env, ctx, ASE_MT);
4719 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4723 check_insn(env, ctx, ASE_MT);
4724 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4728 check_insn(env, ctx, ASE_MT);
4729 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4733 check_insn(env, ctx, ASE_MT);
4734 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4738 check_insn(env, ctx, ASE_MT);
4739 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4743 check_insn(env, ctx, ASE_MT);
4744 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4754 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4764 tcg_gen_helper_0_1(do_mtc0_context, t0);
4768 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4769 rn = "ContextConfig";
4778 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4782 check_insn(env, ctx, ISA_MIPS32R2);
4783 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4793 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4797 check_insn(env, ctx, ISA_MIPS32R2);
4798 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4802 check_insn(env, ctx, ISA_MIPS32R2);
4803 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4807 check_insn(env, ctx, ISA_MIPS32R2);
4808 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4812 check_insn(env, ctx, ISA_MIPS32R2);
4813 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4817 check_insn(env, ctx, ISA_MIPS32R2);
4818 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4828 check_insn(env, ctx, ISA_MIPS32R2);
4829 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4843 tcg_gen_helper_0_1(do_mtc0_count, t0);
4846 /* 6,7 are implementation dependent */
4850 /* Stop translation as we may have switched the execution mode */
4851 ctx->bstate = BS_STOP;
4856 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4866 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4869 /* 6,7 are implementation dependent */
4873 /* Stop translation as we may have switched the execution mode */
4874 ctx->bstate = BS_STOP;
4879 tcg_gen_helper_0_1(do_mtc0_status, t0);
4880 /* BS_STOP isn't good enough here, hflags may have changed. */
4881 gen_save_pc(ctx->pc + 4);
4882 ctx->bstate = BS_EXCP;
4886 check_insn(env, ctx, ISA_MIPS32R2);
4887 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4888 /* Stop translation as we may have switched the execution mode */
4889 ctx->bstate = BS_STOP;
4893 check_insn(env, ctx, ISA_MIPS32R2);
4894 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4895 /* Stop translation as we may have switched the execution mode */
4896 ctx->bstate = BS_STOP;
4900 check_insn(env, ctx, ISA_MIPS32R2);
4901 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4902 /* Stop translation as we may have switched the execution mode */
4903 ctx->bstate = BS_STOP;
4913 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4919 /* Stop translation as we may have switched the execution mode */
4920 ctx->bstate = BS_STOP;
4925 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4939 check_insn(env, ctx, ISA_MIPS32R2);
4940 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4950 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4952 /* Stop translation as we may have switched the execution mode */
4953 ctx->bstate = BS_STOP;
4960 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4962 /* Stop translation as we may have switched the execution mode */
4963 ctx->bstate = BS_STOP;
4969 /* 6,7 are implementation dependent */
4971 rn = "Invalid config selector";
4988 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4998 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
5008 check_insn(env, ctx, ISA_MIPS3);
5009 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
5017 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5020 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
5029 rn = "Diagnostic"; /* implementation dependent */
5034 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
5035 /* BS_STOP isn't good enough here, hflags may have changed. */
5036 gen_save_pc(ctx->pc + 4);
5037 ctx->bstate = BS_EXCP;
5041 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
5042 /* Stop translation as we may have switched the execution mode */
5043 ctx->bstate = BS_STOP;
5044 rn = "TraceControl";
5047 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
5048 /* Stop translation as we may have switched the execution mode */
5049 ctx->bstate = BS_STOP;
5050 rn = "TraceControl2";
5053 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5054 /* Stop translation as we may have switched the execution mode */
5055 ctx->bstate = BS_STOP;
5056 rn = "UserTraceData";
5059 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5060 /* Stop translation as we may have switched the execution mode */
5061 ctx->bstate = BS_STOP;
5072 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5082 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5083 rn = "Performance0";
5086 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5087 rn = "Performance1";
5090 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5091 rn = "Performance2";
5094 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5095 rn = "Performance3";
5098 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5099 rn = "Performance4";
5102 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5103 rn = "Performance5";
5106 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5107 rn = "Performance6";
5110 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5111 rn = "Performance7";
5137 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5144 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5157 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5164 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5175 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5186 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5192 /* Stop translation as we may have switched the execution mode */
5193 ctx->bstate = BS_STOP;
5198 #if defined MIPS_DEBUG_DISAS
5199 if (loglevel & CPU_LOG_TB_IN_ASM) {
5200 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5204 /* For simplicity assume that all writes can cause interrupts. */
5207 ctx->bstate = BS_STOP;
5212 #if defined MIPS_DEBUG_DISAS
5213 if (loglevel & CPU_LOG_TB_IN_ASM) {
5214 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5218 generate_exception(ctx, EXCP_RI);
5220 #endif /* TARGET_MIPS64 */
5222 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5223 int u, int sel, int h)
5225 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5226 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5228 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5229 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5230 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5231 tcg_gen_movi_tl(t0, -1);
5232 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5233 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5234 tcg_gen_movi_tl(t0, -1);
5240 tcg_gen_helper_1_1(do_mftc0_tcstatus, t0, t0);
5243 tcg_gen_helper_1_1(do_mftc0_tcbind, t0, t0);
5246 tcg_gen_helper_1_1(do_mftc0_tcrestart, t0, t0);
5249 tcg_gen_helper_1_1(do_mftc0_tchalt, t0, t0);
5252 tcg_gen_helper_1_1(do_mftc0_tccontext, t0, t0);
5255 tcg_gen_helper_1_1(do_mftc0_tcschedule, t0, t0);
5258 tcg_gen_helper_1_1(do_mftc0_tcschefback, t0, t0);
5261 gen_mfc0(env, ctx, t0, rt, sel);
5268 tcg_gen_helper_1_1(do_mftc0_entryhi, t0, t0);
5271 gen_mfc0(env, ctx, t0, rt, sel);
5277 tcg_gen_helper_1_1(do_mftc0_status, t0, t0);
5280 gen_mfc0(env, ctx, t0, rt, sel);
5286 tcg_gen_helper_1_1(do_mftc0_debug, t0, t0);
5289 gen_mfc0(env, ctx, t0, rt, sel);
5294 gen_mfc0(env, ctx, t0, rt, sel);
5296 } else switch (sel) {
5297 /* GPR registers. */
5299 tcg_gen_helper_1_1i(do_mftgpr, t0, t0, rt);
5301 /* Auxiliary CPU registers */
5305 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 0);
5308 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 0);
5311 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 0);
5314 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 1);
5317 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 1);
5320 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 1);
5323 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 2);
5326 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 2);
5329 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 2);
5332 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 3);
5335 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 3);
5338 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 3);
5341 tcg_gen_helper_1_1(do_mftdsp, t0, t0);
5347 /* Floating point (COP1). */
5349 /* XXX: For now we support only a single FPU context. */
5351 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5353 gen_load_fpr32(fp0, rt);
5354 tcg_gen_ext_i32_tl(t0, fp0);
5357 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5359 gen_load_fpr32h(fp0, rt);
5360 tcg_gen_ext_i32_tl(t0, fp0);
5365 /* XXX: For now we support only a single FPU context. */
5366 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5368 /* COP2: Not implemented. */
5375 #if defined MIPS_DEBUG_DISAS
5376 if (loglevel & CPU_LOG_TB_IN_ASM) {
5377 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5381 gen_store_gpr(t0, rd);
5387 #if defined MIPS_DEBUG_DISAS
5388 if (loglevel & CPU_LOG_TB_IN_ASM) {
5389 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5393 generate_exception(ctx, EXCP_RI);
5396 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5397 int u, int sel, int h)
5399 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5400 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5402 gen_load_gpr(t0, rt);
5403 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5404 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5405 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5407 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5408 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5415 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5418 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5421 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5424 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5427 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5430 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5433 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5436 gen_mtc0(env, ctx, t0, rd, sel);
5443 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5446 gen_mtc0(env, ctx, t0, rd, sel);
5452 tcg_gen_helper_0_1(do_mttc0_status, t0);
5455 gen_mtc0(env, ctx, t0, rd, sel);
5461 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5464 gen_mtc0(env, ctx, t0, rd, sel);
5469 gen_mtc0(env, ctx, t0, rd, sel);
5471 } else switch (sel) {
5472 /* GPR registers. */
5474 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5476 /* Auxiliary CPU registers */
5480 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5483 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5486 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5489 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5492 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5495 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5498 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5501 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5504 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5507 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5510 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5513 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5516 tcg_gen_helper_0_1(do_mttdsp, t0);
5522 /* Floating point (COP1). */
5524 /* XXX: For now we support only a single FPU context. */
5526 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5528 tcg_gen_trunc_tl_i32(fp0, t0);
5529 gen_store_fpr32(fp0, rd);
5532 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5534 tcg_gen_trunc_tl_i32(fp0, t0);
5535 gen_store_fpr32h(fp0, rd);
5540 /* XXX: For now we support only a single FPU context. */
5541 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5543 /* COP2: Not implemented. */
5550 #if defined MIPS_DEBUG_DISAS
5551 if (loglevel & CPU_LOG_TB_IN_ASM) {
5552 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5561 #if defined MIPS_DEBUG_DISAS
5562 if (loglevel & CPU_LOG_TB_IN_ASM) {
5563 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5567 generate_exception(ctx, EXCP_RI);
5570 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5572 const char *opn = "ldst";
5581 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5583 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5584 gen_store_gpr(t0, rt);
5591 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5593 gen_load_gpr(t0, rt);
5594 save_cpu_state(ctx, 1);
5595 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5600 #if defined(TARGET_MIPS64)
5602 check_insn(env, ctx, ISA_MIPS3);
5608 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5610 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5611 gen_store_gpr(t0, rt);
5617 check_insn(env, ctx, ISA_MIPS3);
5619 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5621 gen_load_gpr(t0, rt);
5622 save_cpu_state(ctx, 1);
5623 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5630 check_insn(env, ctx, ASE_MT);
5635 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5636 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5640 check_insn(env, ctx, ASE_MT);
5641 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5642 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5647 if (!env->tlb->do_tlbwi)
5649 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5653 if (!env->tlb->do_tlbwr)
5655 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5659 if (!env->tlb->do_tlbp)
5661 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5665 if (!env->tlb->do_tlbr)
5667 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5671 check_insn(env, ctx, ISA_MIPS2);
5672 save_cpu_state(ctx, 1);
5673 tcg_gen_helper_0_0(do_eret);
5674 ctx->bstate = BS_EXCP;
5678 check_insn(env, ctx, ISA_MIPS32);
5679 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5681 generate_exception(ctx, EXCP_RI);
5683 save_cpu_state(ctx, 1);
5684 tcg_gen_helper_0_0(do_deret);
5685 ctx->bstate = BS_EXCP;
5690 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5691 /* If we get an exception, we want to restart at next instruction */
5693 save_cpu_state(ctx, 1);
5695 tcg_gen_helper_0_0(do_wait);
5696 ctx->bstate = BS_EXCP;
5701 generate_exception(ctx, EXCP_RI);
5704 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5706 #endif /* !CONFIG_USER_ONLY */
5708 /* CP1 Branches (before delay slot) */
5709 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5710 int32_t cc, int32_t offset)
5712 target_ulong btarget;
5713 const char *opn = "cp1 cond branch";
5714 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5715 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5718 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5720 btarget = ctx->pc + 4 + offset;
5725 int l1 = gen_new_label();
5726 int l2 = gen_new_label();
5727 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5729 get_fp_cond(r_tmp1);
5730 tcg_gen_ext_i32_tl(t0, r_tmp1);
5731 tcg_temp_free(r_tmp1);
5732 tcg_gen_not_tl(t0, t0);
5733 tcg_gen_movi_tl(t1, 0x1 << cc);
5734 tcg_gen_and_tl(t0, t0, t1);
5735 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5736 tcg_gen_movi_tl(t0, 0);
5739 tcg_gen_movi_tl(t0, 1);
5746 int l1 = gen_new_label();
5747 int l2 = gen_new_label();
5748 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5750 get_fp_cond(r_tmp1);
5751 tcg_gen_ext_i32_tl(t0, r_tmp1);
5752 tcg_temp_free(r_tmp1);
5753 tcg_gen_not_tl(t0, t0);
5754 tcg_gen_movi_tl(t1, 0x1 << cc);
5755 tcg_gen_and_tl(t0, t0, t1);
5756 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5757 tcg_gen_movi_tl(t0, 0);
5760 tcg_gen_movi_tl(t0, 1);
5767 int l1 = gen_new_label();
5768 int l2 = gen_new_label();
5769 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5771 get_fp_cond(r_tmp1);
5772 tcg_gen_ext_i32_tl(t0, r_tmp1);
5773 tcg_temp_free(r_tmp1);
5774 tcg_gen_movi_tl(t1, 0x1 << cc);
5775 tcg_gen_and_tl(t0, t0, t1);
5776 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5777 tcg_gen_movi_tl(t0, 0);
5780 tcg_gen_movi_tl(t0, 1);
5787 int l1 = gen_new_label();
5788 int l2 = gen_new_label();
5789 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5791 get_fp_cond(r_tmp1);
5792 tcg_gen_ext_i32_tl(t0, r_tmp1);
5793 tcg_temp_free(r_tmp1);
5794 tcg_gen_movi_tl(t1, 0x1 << cc);
5795 tcg_gen_and_tl(t0, t0, t1);
5796 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5797 tcg_gen_movi_tl(t0, 0);
5800 tcg_gen_movi_tl(t0, 1);
5805 ctx->hflags |= MIPS_HFLAG_BL;
5806 tcg_gen_trunc_tl_i32(bcond, t0);
5810 int l1 = gen_new_label();
5811 int l2 = gen_new_label();
5812 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5814 get_fp_cond(r_tmp1);
5815 tcg_gen_ext_i32_tl(t0, r_tmp1);
5816 tcg_temp_free(r_tmp1);
5817 tcg_gen_not_tl(t0, t0);
5818 tcg_gen_movi_tl(t1, 0x3 << cc);
5819 tcg_gen_and_tl(t0, t0, t1);
5820 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5821 tcg_gen_movi_tl(t0, 0);
5824 tcg_gen_movi_tl(t0, 1);
5831 int l1 = gen_new_label();
5832 int l2 = gen_new_label();
5833 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5835 get_fp_cond(r_tmp1);
5836 tcg_gen_ext_i32_tl(t0, r_tmp1);
5837 tcg_temp_free(r_tmp1);
5838 tcg_gen_movi_tl(t1, 0x3 << cc);
5839 tcg_gen_and_tl(t0, t0, t1);
5840 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5841 tcg_gen_movi_tl(t0, 0);
5844 tcg_gen_movi_tl(t0, 1);
5851 int l1 = gen_new_label();
5852 int l2 = gen_new_label();
5853 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5855 get_fp_cond(r_tmp1);
5856 tcg_gen_ext_i32_tl(t0, r_tmp1);
5857 tcg_temp_free(r_tmp1);
5858 tcg_gen_not_tl(t0, t0);
5859 tcg_gen_movi_tl(t1, 0xf << cc);
5860 tcg_gen_and_tl(t0, t0, t1);
5861 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5862 tcg_gen_movi_tl(t0, 0);
5865 tcg_gen_movi_tl(t0, 1);
5872 int l1 = gen_new_label();
5873 int l2 = gen_new_label();
5874 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5876 get_fp_cond(r_tmp1);
5877 tcg_gen_ext_i32_tl(t0, r_tmp1);
5878 tcg_temp_free(r_tmp1);
5879 tcg_gen_movi_tl(t1, 0xf << cc);
5880 tcg_gen_and_tl(t0, t0, t1);
5881 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5882 tcg_gen_movi_tl(t0, 0);
5885 tcg_gen_movi_tl(t0, 1);
5890 ctx->hflags |= MIPS_HFLAG_BC;
5891 tcg_gen_trunc_tl_i32(bcond, t0);
5895 generate_exception (ctx, EXCP_RI);
5898 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5899 ctx->hflags, btarget);
5900 ctx->btarget = btarget;
5907 /* Coprocessor 1 (FPU) */
5909 #define FOP(func, fmt) (((fmt) << 21) | (func))
5911 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5913 const char *opn = "cp1 move";
5914 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5919 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5921 gen_load_fpr32(fp0, fs);
5922 tcg_gen_ext_i32_tl(t0, fp0);
5925 gen_store_gpr(t0, rt);
5929 gen_load_gpr(t0, rt);
5931 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5933 tcg_gen_trunc_tl_i32(fp0, t0);
5934 gen_store_fpr32(fp0, fs);
5940 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5941 gen_store_gpr(t0, rt);
5945 gen_load_gpr(t0, rt);
5946 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5951 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5953 gen_load_fpr64(ctx, fp0, fs);
5954 tcg_gen_mov_tl(t0, fp0);
5957 gen_store_gpr(t0, rt);
5961 gen_load_gpr(t0, rt);
5963 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5965 tcg_gen_mov_tl(fp0, t0);
5966 gen_store_fpr64(ctx, fp0, fs);
5973 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5975 gen_load_fpr32h(fp0, fs);
5976 tcg_gen_ext_i32_tl(t0, fp0);
5979 gen_store_gpr(t0, rt);
5983 gen_load_gpr(t0, rt);
5985 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5987 tcg_gen_trunc_tl_i32(fp0, t0);
5988 gen_store_fpr32h(fp0, fs);
5995 generate_exception (ctx, EXCP_RI);
5998 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
6004 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
6006 int l1 = gen_new_label();
6009 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6010 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
6011 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
6014 ccbit = 1 << (24 + cc);
6022 gen_load_gpr(t0, rd);
6023 gen_load_gpr(t1, rs);
6024 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
6025 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
6026 tcg_temp_free(r_tmp);
6028 tcg_gen_mov_tl(t0, t1);
6032 gen_store_gpr(t0, rd);
6036 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
6040 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6041 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6042 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6043 int l1 = gen_new_label();
6046 ccbit = 1 << (24 + cc);
6055 gen_load_fpr32(fp0, fs);
6056 gen_load_fpr32(fp1, fd);
6057 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6058 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6059 tcg_gen_mov_i32(fp1, fp0);
6062 tcg_temp_free(r_tmp1);
6063 gen_store_fpr32(fp1, fd);
6067 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
6071 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6072 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6073 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I64);
6074 int l1 = gen_new_label();
6077 ccbit = 1 << (24 + cc);
6086 gen_load_fpr64(ctx, fp0, fs);
6087 gen_load_fpr64(ctx, fp1, fd);
6088 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6089 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6090 tcg_gen_mov_i64(fp1, fp0);
6093 tcg_temp_free(r_tmp1);
6094 gen_store_fpr64(ctx, fp1, fd);
6098 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
6101 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6102 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6103 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6104 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
6105 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6106 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
6107 int l1 = gen_new_label();
6108 int l2 = gen_new_label();
6115 gen_load_fpr32(fp0, fs);
6116 gen_load_fpr32h(fph0, fs);
6117 gen_load_fpr32(fp1, fd);
6118 gen_load_fpr32h(fph1, fd);
6119 get_fp_cond(r_tmp1);
6120 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6121 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6122 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6123 tcg_gen_mov_i32(fp1, fp0);
6126 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6127 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6128 tcg_gen_mov_i32(fph1, fph0);
6129 tcg_temp_free(fph0);
6131 tcg_temp_free(r_tmp1);
6132 tcg_temp_free(r_tmp2);
6133 gen_store_fpr32(fp1, fd);
6134 gen_store_fpr32h(fph1, fd);
6136 tcg_temp_free(fph1);
6140 static void gen_farith (DisasContext *ctx, uint32_t op1,
6141 int ft, int fs, int fd, int cc)
6143 const char *opn = "farith";
6144 const char *condnames[] = {
6162 const char *condnames_abs[] = {
6180 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6181 uint32_t func = ctx->opcode & 0x3f;
6183 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6186 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6187 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6189 gen_load_fpr32(fp0, fs);
6190 gen_load_fpr32(fp1, ft);
6191 tcg_gen_helper_1_2(do_float_add_s, fp0, fp0, fp1);
6193 gen_store_fpr32(fp0, fd);
6201 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6202 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6204 gen_load_fpr32(fp0, fs);
6205 gen_load_fpr32(fp1, ft);
6206 tcg_gen_helper_1_2(do_float_sub_s, fp0, fp0, fp1);
6208 gen_store_fpr32(fp0, fd);
6216 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6217 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6219 gen_load_fpr32(fp0, fs);
6220 gen_load_fpr32(fp1, ft);
6221 tcg_gen_helper_1_2(do_float_mul_s, fp0, fp0, fp1);
6223 gen_store_fpr32(fp0, fd);
6231 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6232 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6234 gen_load_fpr32(fp0, fs);
6235 gen_load_fpr32(fp1, ft);
6236 tcg_gen_helper_1_2(do_float_div_s, fp0, fp0, fp1);
6238 gen_store_fpr32(fp0, fd);
6246 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6248 gen_load_fpr32(fp0, fs);
6249 tcg_gen_helper_1_1(do_float_sqrt_s, fp0, fp0);
6250 gen_store_fpr32(fp0, fd);
6257 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6259 gen_load_fpr32(fp0, fs);
6260 tcg_gen_helper_1_1(do_float_abs_s, fp0, fp0);
6261 gen_store_fpr32(fp0, fd);
6268 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6270 gen_load_fpr32(fp0, fs);
6271 gen_store_fpr32(fp0, fd);
6278 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6280 gen_load_fpr32(fp0, fs);
6281 tcg_gen_helper_1_1(do_float_chs_s, fp0, fp0);
6282 gen_store_fpr32(fp0, fd);
6288 check_cp1_64bitmode(ctx);
6290 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6291 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6293 gen_load_fpr32(fp32, fs);
6294 tcg_gen_helper_1_1(do_float_roundl_s, fp64, fp32);
6295 tcg_temp_free(fp32);
6296 gen_store_fpr64(ctx, fp64, fd);
6297 tcg_temp_free(fp64);
6302 check_cp1_64bitmode(ctx);
6304 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6305 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6307 gen_load_fpr32(fp32, fs);
6308 tcg_gen_helper_1_1(do_float_truncl_s, fp64, fp32);
6309 tcg_temp_free(fp32);
6310 gen_store_fpr64(ctx, fp64, fd);
6311 tcg_temp_free(fp64);
6316 check_cp1_64bitmode(ctx);
6318 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6319 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6321 gen_load_fpr32(fp32, fs);
6322 tcg_gen_helper_1_1(do_float_ceill_s, fp64, fp32);
6323 tcg_temp_free(fp32);
6324 gen_store_fpr64(ctx, fp64, fd);
6325 tcg_temp_free(fp64);
6330 check_cp1_64bitmode(ctx);
6332 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6333 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6335 gen_load_fpr32(fp32, fs);
6336 tcg_gen_helper_1_1(do_float_floorl_s, fp64, fp32);
6337 tcg_temp_free(fp32);
6338 gen_store_fpr64(ctx, fp64, fd);
6339 tcg_temp_free(fp64);
6345 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6347 gen_load_fpr32(fp0, fs);
6348 tcg_gen_helper_1_1(do_float_roundw_s, fp0, fp0);
6349 gen_store_fpr32(fp0, fd);
6356 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6358 gen_load_fpr32(fp0, fs);
6359 tcg_gen_helper_1_1(do_float_truncw_s, fp0, fp0);
6360 gen_store_fpr32(fp0, fd);
6367 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6369 gen_load_fpr32(fp0, fs);
6370 tcg_gen_helper_1_1(do_float_ceilw_s, fp0, fp0);
6371 gen_store_fpr32(fp0, fd);
6378 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6380 gen_load_fpr32(fp0, fs);
6381 tcg_gen_helper_1_1(do_float_floorw_s, fp0, fp0);
6382 gen_store_fpr32(fp0, fd);
6388 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6393 int l1 = gen_new_label();
6394 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6395 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6397 gen_load_gpr(t0, ft);
6398 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6400 gen_load_fpr32(fp0, fs);
6401 gen_store_fpr32(fp0, fd);
6409 int l1 = gen_new_label();
6410 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6411 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6413 gen_load_gpr(t0, ft);
6414 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6416 gen_load_fpr32(fp0, fs);
6417 gen_store_fpr32(fp0, fd);
6426 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6428 gen_load_fpr32(fp0, fs);
6429 tcg_gen_helper_1_1(do_float_recip_s, fp0, fp0);
6430 gen_store_fpr32(fp0, fd);
6438 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6440 gen_load_fpr32(fp0, fs);
6441 tcg_gen_helper_1_1(do_float_rsqrt_s, fp0, fp0);
6442 gen_store_fpr32(fp0, fd);
6448 check_cp1_64bitmode(ctx);
6450 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6451 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6453 gen_load_fpr32(fp0, fs);
6454 gen_load_fpr32(fp1, fd);
6455 tcg_gen_helper_1_2(do_float_recip2_s, fp0, fp0, fp1);
6457 gen_store_fpr32(fp0, fd);
6463 check_cp1_64bitmode(ctx);
6465 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6467 gen_load_fpr32(fp0, fs);
6468 tcg_gen_helper_1_1(do_float_recip1_s, fp0, fp0);
6469 gen_store_fpr32(fp0, fd);
6475 check_cp1_64bitmode(ctx);
6477 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6479 gen_load_fpr32(fp0, fs);
6480 tcg_gen_helper_1_1(do_float_rsqrt1_s, fp0, fp0);
6481 gen_store_fpr32(fp0, fd);
6487 check_cp1_64bitmode(ctx);
6489 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6490 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6492 gen_load_fpr32(fp0, fs);
6493 gen_load_fpr32(fp1, ft);
6494 tcg_gen_helper_1_2(do_float_rsqrt2_s, fp0, fp0, fp1);
6496 gen_store_fpr32(fp0, fd);
6502 check_cp1_registers(ctx, fd);
6504 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6505 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6507 gen_load_fpr32(fp32, fs);
6508 tcg_gen_helper_1_1(do_float_cvtd_s, fp64, fp32);
6509 tcg_temp_free(fp32);
6510 gen_store_fpr64(ctx, fp64, fd);
6511 tcg_temp_free(fp64);
6517 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6519 gen_load_fpr32(fp0, fs);
6520 tcg_gen_helper_1_1(do_float_cvtw_s, fp0, fp0);
6521 gen_store_fpr32(fp0, fd);
6527 check_cp1_64bitmode(ctx);
6529 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6530 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6532 gen_load_fpr32(fp32, fs);
6533 tcg_gen_helper_1_1(do_float_cvtl_s, fp64, fp32);
6534 tcg_temp_free(fp32);
6535 gen_store_fpr64(ctx, fp64, fd);
6536 tcg_temp_free(fp64);
6541 check_cp1_64bitmode(ctx);
6543 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6544 TCGv fp32_0 = tcg_temp_new(TCG_TYPE_I32);
6545 TCGv fp32_1 = tcg_temp_new(TCG_TYPE_I32);
6547 gen_load_fpr32(fp32_0, fs);
6548 gen_load_fpr32(fp32_1, ft);
6549 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6550 tcg_temp_free(fp32_1);
6551 tcg_temp_free(fp32_0);
6552 gen_store_fpr64(ctx, fp64, fd);
6553 tcg_temp_free(fp64);
6574 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6575 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6577 gen_load_fpr32(fp0, fs);
6578 gen_load_fpr32(fp1, ft);
6579 if (ctx->opcode & (1 << 6)) {
6581 gen_cmpabs_s(func-48, fp0, fp1, cc);
6582 opn = condnames_abs[func-48];
6584 gen_cmp_s(func-48, fp0, fp1, cc);
6585 opn = condnames[func-48];
6592 check_cp1_registers(ctx, fs | ft | fd);
6594 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6595 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6597 gen_load_fpr64(ctx, fp0, fs);
6598 gen_load_fpr64(ctx, fp1, ft);
6599 tcg_gen_helper_1_2(do_float_add_d, fp0, fp0, fp1);
6601 gen_store_fpr64(ctx, fp0, fd);
6608 check_cp1_registers(ctx, fs | ft | fd);
6610 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6611 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6613 gen_load_fpr64(ctx, fp0, fs);
6614 gen_load_fpr64(ctx, fp1, ft);
6615 tcg_gen_helper_1_2(do_float_sub_d, fp0, fp0, fp1);
6617 gen_store_fpr64(ctx, fp0, fd);
6624 check_cp1_registers(ctx, fs | ft | fd);
6626 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6627 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6629 gen_load_fpr64(ctx, fp0, fs);
6630 gen_load_fpr64(ctx, fp1, ft);
6631 tcg_gen_helper_1_2(do_float_mul_d, fp0, fp0, fp1);
6633 gen_store_fpr64(ctx, fp0, fd);
6640 check_cp1_registers(ctx, fs | ft | fd);
6642 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6643 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6645 gen_load_fpr64(ctx, fp0, fs);
6646 gen_load_fpr64(ctx, fp1, ft);
6647 tcg_gen_helper_1_2(do_float_div_d, fp0, fp0, fp1);
6649 gen_store_fpr64(ctx, fp0, fd);
6656 check_cp1_registers(ctx, fs | fd);
6658 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6660 gen_load_fpr64(ctx, fp0, fs);
6661 tcg_gen_helper_1_1(do_float_sqrt_d, fp0, fp0);
6662 gen_store_fpr64(ctx, fp0, fd);
6668 check_cp1_registers(ctx, fs | fd);
6670 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6672 gen_load_fpr64(ctx, fp0, fs);
6673 tcg_gen_helper_1_1(do_float_abs_d, fp0, fp0);
6674 gen_store_fpr64(ctx, fp0, fd);
6680 check_cp1_registers(ctx, fs | fd);
6682 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6684 gen_load_fpr64(ctx, fp0, fs);
6685 gen_store_fpr64(ctx, fp0, fd);
6691 check_cp1_registers(ctx, fs | fd);
6693 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6695 gen_load_fpr64(ctx, fp0, fs);
6696 tcg_gen_helper_1_1(do_float_chs_d, fp0, fp0);
6697 gen_store_fpr64(ctx, fp0, fd);
6703 check_cp1_64bitmode(ctx);
6705 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6707 gen_load_fpr64(ctx, fp0, fs);
6708 tcg_gen_helper_1_1(do_float_roundl_d, fp0, fp0);
6709 gen_store_fpr64(ctx, fp0, fd);
6715 check_cp1_64bitmode(ctx);
6717 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6719 gen_load_fpr64(ctx, fp0, fs);
6720 tcg_gen_helper_1_1(do_float_truncl_d, fp0, fp0);
6721 gen_store_fpr64(ctx, fp0, fd);
6727 check_cp1_64bitmode(ctx);
6729 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6731 gen_load_fpr64(ctx, fp0, fs);
6732 tcg_gen_helper_1_1(do_float_ceill_d, fp0, fp0);
6733 gen_store_fpr64(ctx, fp0, fd);
6739 check_cp1_64bitmode(ctx);
6741 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6743 gen_load_fpr64(ctx, fp0, fs);
6744 tcg_gen_helper_1_1(do_float_floorl_d, fp0, fp0);
6745 gen_store_fpr64(ctx, fp0, fd);
6751 check_cp1_registers(ctx, fs);
6753 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6754 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6756 gen_load_fpr64(ctx, fp64, fs);
6757 tcg_gen_helper_1_1(do_float_roundw_d, fp32, fp64);
6758 tcg_temp_free(fp64);
6759 gen_store_fpr32(fp32, fd);
6760 tcg_temp_free(fp32);
6765 check_cp1_registers(ctx, fs);
6767 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6768 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6770 gen_load_fpr64(ctx, fp64, fs);
6771 tcg_gen_helper_1_1(do_float_truncw_d, fp32, fp64);
6772 tcg_temp_free(fp64);
6773 gen_store_fpr32(fp32, fd);
6774 tcg_temp_free(fp32);
6779 check_cp1_registers(ctx, fs);
6781 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6782 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6784 gen_load_fpr64(ctx, fp64, fs);
6785 tcg_gen_helper_1_1(do_float_ceilw_d, fp32, fp64);
6786 tcg_temp_free(fp64);
6787 gen_store_fpr32(fp32, fd);
6788 tcg_temp_free(fp32);
6793 check_cp1_registers(ctx, fs);
6795 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6796 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6798 gen_load_fpr64(ctx, fp64, fs);
6799 tcg_gen_helper_1_1(do_float_floorw_d, fp32, fp64);
6800 tcg_temp_free(fp64);
6801 gen_store_fpr32(fp32, fd);
6802 tcg_temp_free(fp32);
6807 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6812 int l1 = gen_new_label();
6813 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6814 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6816 gen_load_gpr(t0, ft);
6817 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6819 gen_load_fpr64(ctx, fp0, fs);
6820 gen_store_fpr64(ctx, fp0, fd);
6828 int l1 = gen_new_label();
6829 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6830 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6832 gen_load_gpr(t0, ft);
6833 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6835 gen_load_fpr64(ctx, fp0, fs);
6836 gen_store_fpr64(ctx, fp0, fd);
6843 check_cp1_64bitmode(ctx);
6845 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6847 gen_load_fpr64(ctx, fp0, fs);
6848 tcg_gen_helper_1_1(do_float_recip_d, fp0, fp0);
6849 gen_store_fpr64(ctx, fp0, fd);
6855 check_cp1_64bitmode(ctx);
6857 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6859 gen_load_fpr64(ctx, fp0, fs);
6860 tcg_gen_helper_1_1(do_float_rsqrt_d, fp0, fp0);
6861 gen_store_fpr64(ctx, fp0, fd);
6867 check_cp1_64bitmode(ctx);
6869 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6870 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6872 gen_load_fpr64(ctx, fp0, fs);
6873 gen_load_fpr64(ctx, fp1, ft);
6874 tcg_gen_helper_1_2(do_float_recip2_d, fp0, fp0, fp1);
6876 gen_store_fpr64(ctx, fp0, fd);
6882 check_cp1_64bitmode(ctx);
6884 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6886 gen_load_fpr64(ctx, fp0, fs);
6887 tcg_gen_helper_1_1(do_float_recip1_d, fp0, fp0);
6888 gen_store_fpr64(ctx, fp0, fd);
6894 check_cp1_64bitmode(ctx);
6896 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6898 gen_load_fpr64(ctx, fp0, fs);
6899 tcg_gen_helper_1_1(do_float_rsqrt1_d, fp0, fp0);
6900 gen_store_fpr64(ctx, fp0, fd);
6906 check_cp1_64bitmode(ctx);
6908 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6909 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6911 gen_load_fpr64(ctx, fp0, fs);
6912 gen_load_fpr64(ctx, fp1, ft);
6913 tcg_gen_helper_1_2(do_float_rsqrt2_d, fp0, fp0, fp1);
6915 gen_store_fpr64(ctx, fp0, fd);
6937 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6938 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6940 gen_load_fpr64(ctx, fp0, fs);
6941 gen_load_fpr64(ctx, fp1, ft);
6942 if (ctx->opcode & (1 << 6)) {
6944 check_cp1_registers(ctx, fs | ft);
6945 gen_cmpabs_d(func-48, fp0, fp1, cc);
6946 opn = condnames_abs[func-48];
6948 check_cp1_registers(ctx, fs | ft);
6949 gen_cmp_d(func-48, fp0, fp1, cc);
6950 opn = condnames[func-48];
6957 check_cp1_registers(ctx, fs);
6959 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6960 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6962 gen_load_fpr64(ctx, fp64, fs);
6963 tcg_gen_helper_1_1(do_float_cvts_d, fp32, fp64);
6964 tcg_temp_free(fp64);
6965 gen_store_fpr32(fp32, fd);
6966 tcg_temp_free(fp32);
6971 check_cp1_registers(ctx, fs);
6973 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6974 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6976 gen_load_fpr64(ctx, fp64, fs);
6977 tcg_gen_helper_1_1(do_float_cvtw_d, fp32, fp64);
6978 tcg_temp_free(fp64);
6979 gen_store_fpr32(fp32, fd);
6980 tcg_temp_free(fp32);
6985 check_cp1_64bitmode(ctx);
6987 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6989 gen_load_fpr64(ctx, fp0, fs);
6990 tcg_gen_helper_1_1(do_float_cvtl_d, fp0, fp0);
6991 gen_store_fpr64(ctx, fp0, fd);
6998 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7000 gen_load_fpr32(fp0, fs);
7001 tcg_gen_helper_1_1(do_float_cvts_w, fp0, fp0);
7002 gen_store_fpr32(fp0, fd);
7008 check_cp1_registers(ctx, fd);
7010 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
7011 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
7013 gen_load_fpr32(fp32, fs);
7014 tcg_gen_helper_1_1(do_float_cvtd_w, fp64, fp32);
7015 tcg_temp_free(fp32);
7016 gen_store_fpr64(ctx, fp64, fd);
7017 tcg_temp_free(fp64);
7022 check_cp1_64bitmode(ctx);
7024 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
7025 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
7027 gen_load_fpr64(ctx, fp64, fs);
7028 tcg_gen_helper_1_1(do_float_cvts_l, fp32, fp64);
7029 tcg_temp_free(fp64);
7030 gen_store_fpr32(fp32, fd);
7031 tcg_temp_free(fp32);
7036 check_cp1_64bitmode(ctx);
7038 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7040 gen_load_fpr64(ctx, fp0, fs);
7041 tcg_gen_helper_1_1(do_float_cvtd_l, fp0, fp0);
7042 gen_store_fpr64(ctx, fp0, fd);
7048 check_cp1_64bitmode(ctx);
7050 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7052 gen_load_fpr64(ctx, fp0, fs);
7053 tcg_gen_helper_1_1(do_float_cvtps_pw, fp0, fp0);
7054 gen_store_fpr64(ctx, fp0, fd);
7060 check_cp1_64bitmode(ctx);
7062 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7063 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7065 gen_load_fpr64(ctx, fp0, fs);
7066 gen_load_fpr64(ctx, fp1, ft);
7067 tcg_gen_helper_1_2(do_float_add_ps, fp0, fp0, fp1);
7069 gen_store_fpr64(ctx, fp0, fd);
7075 check_cp1_64bitmode(ctx);
7077 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7078 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7080 gen_load_fpr64(ctx, fp0, fs);
7081 gen_load_fpr64(ctx, fp1, ft);
7082 tcg_gen_helper_1_2(do_float_sub_ps, fp0, fp0, fp1);
7084 gen_store_fpr64(ctx, fp0, fd);
7090 check_cp1_64bitmode(ctx);
7092 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7093 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7095 gen_load_fpr64(ctx, fp0, fs);
7096 gen_load_fpr64(ctx, fp1, ft);
7097 tcg_gen_helper_1_2(do_float_mul_ps, fp0, fp0, fp1);
7099 gen_store_fpr64(ctx, fp0, fd);
7105 check_cp1_64bitmode(ctx);
7107 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7109 gen_load_fpr64(ctx, fp0, fs);
7110 tcg_gen_helper_1_1(do_float_abs_ps, fp0, fp0);
7111 gen_store_fpr64(ctx, fp0, fd);
7117 check_cp1_64bitmode(ctx);
7119 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7121 gen_load_fpr64(ctx, fp0, fs);
7122 gen_store_fpr64(ctx, fp0, fd);
7128 check_cp1_64bitmode(ctx);
7130 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7132 gen_load_fpr64(ctx, fp0, fs);
7133 tcg_gen_helper_1_1(do_float_chs_ps, fp0, fp0);
7134 gen_store_fpr64(ctx, fp0, fd);
7140 check_cp1_64bitmode(ctx);
7141 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
7145 check_cp1_64bitmode(ctx);
7147 int l1 = gen_new_label();
7148 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7149 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7150 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7152 gen_load_gpr(t0, ft);
7153 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7155 gen_load_fpr32(fp0, fs);
7156 gen_load_fpr32h(fph0, fs);
7157 gen_store_fpr32(fp0, fd);
7158 gen_store_fpr32h(fph0, fd);
7160 tcg_temp_free(fph0);
7166 check_cp1_64bitmode(ctx);
7168 int l1 = gen_new_label();
7169 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7170 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7171 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7173 gen_load_gpr(t0, ft);
7174 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
7176 gen_load_fpr32(fp0, fs);
7177 gen_load_fpr32h(fph0, fs);
7178 gen_store_fpr32(fp0, fd);
7179 gen_store_fpr32h(fph0, fd);
7181 tcg_temp_free(fph0);
7187 check_cp1_64bitmode(ctx);
7189 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7190 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7192 gen_load_fpr64(ctx, fp0, ft);
7193 gen_load_fpr64(ctx, fp1, fs);
7194 tcg_gen_helper_1_2(do_float_addr_ps, fp0, fp0, fp1);
7196 gen_store_fpr64(ctx, fp0, fd);
7202 check_cp1_64bitmode(ctx);
7204 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7205 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7207 gen_load_fpr64(ctx, fp0, ft);
7208 gen_load_fpr64(ctx, fp1, fs);
7209 tcg_gen_helper_1_2(do_float_mulr_ps, fp0, fp0, fp1);
7211 gen_store_fpr64(ctx, fp0, fd);
7217 check_cp1_64bitmode(ctx);
7219 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7220 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7222 gen_load_fpr64(ctx, fp0, fs);
7223 gen_load_fpr64(ctx, fp1, fd);
7224 tcg_gen_helper_1_2(do_float_recip2_ps, fp0, fp0, fp1);
7226 gen_store_fpr64(ctx, fp0, fd);
7232 check_cp1_64bitmode(ctx);
7234 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7236 gen_load_fpr64(ctx, fp0, fs);
7237 tcg_gen_helper_1_1(do_float_recip1_ps, fp0, fp0);
7238 gen_store_fpr64(ctx, fp0, fd);
7244 check_cp1_64bitmode(ctx);
7246 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7248 gen_load_fpr64(ctx, fp0, fs);
7249 tcg_gen_helper_1_1(do_float_rsqrt1_ps, fp0, fp0);
7250 gen_store_fpr64(ctx, fp0, fd);
7256 check_cp1_64bitmode(ctx);
7258 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7259 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7261 gen_load_fpr64(ctx, fp0, fs);
7262 gen_load_fpr64(ctx, fp1, ft);
7263 tcg_gen_helper_1_2(do_float_rsqrt2_ps, fp0, fp0, fp1);
7265 gen_store_fpr64(ctx, fp0, fd);
7271 check_cp1_64bitmode(ctx);
7273 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7275 gen_load_fpr32h(fp0, fs);
7276 tcg_gen_helper_1_1(do_float_cvts_pu, fp0, fp0);
7277 gen_store_fpr32(fp0, fd);
7283 check_cp1_64bitmode(ctx);
7285 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7287 gen_load_fpr64(ctx, fp0, fs);
7288 tcg_gen_helper_1_1(do_float_cvtpw_ps, fp0, fp0);
7289 gen_store_fpr64(ctx, fp0, fd);
7295 check_cp1_64bitmode(ctx);
7297 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7299 gen_load_fpr32(fp0, fs);
7300 tcg_gen_helper_1_1(do_float_cvts_pl, fp0, fp0);
7301 gen_store_fpr32(fp0, fd);
7307 check_cp1_64bitmode(ctx);
7309 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7310 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7312 gen_load_fpr32(fp0, fs);
7313 gen_load_fpr32(fp1, ft);
7314 gen_store_fpr32h(fp0, fd);
7315 gen_store_fpr32(fp1, fd);
7322 check_cp1_64bitmode(ctx);
7324 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7325 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7327 gen_load_fpr32(fp0, fs);
7328 gen_load_fpr32h(fp1, ft);
7329 gen_store_fpr32(fp1, fd);
7330 gen_store_fpr32h(fp0, fd);
7337 check_cp1_64bitmode(ctx);
7339 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7340 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7342 gen_load_fpr32h(fp0, fs);
7343 gen_load_fpr32(fp1, ft);
7344 gen_store_fpr32(fp1, fd);
7345 gen_store_fpr32h(fp0, fd);
7352 check_cp1_64bitmode(ctx);
7354 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7355 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7357 gen_load_fpr32h(fp0, fs);
7358 gen_load_fpr32h(fp1, ft);
7359 gen_store_fpr32(fp1, fd);
7360 gen_store_fpr32h(fp0, fd);
7382 check_cp1_64bitmode(ctx);
7384 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7385 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7387 gen_load_fpr64(ctx, fp0, fs);
7388 gen_load_fpr64(ctx, fp1, ft);
7389 if (ctx->opcode & (1 << 6)) {
7390 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7391 opn = condnames_abs[func-48];
7393 gen_cmp_ps(func-48, fp0, fp1, cc);
7394 opn = condnames[func-48];
7402 generate_exception (ctx, EXCP_RI);
7407 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7410 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7413 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7418 /* Coprocessor 3 (FPU) */
7419 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7420 int fd, int fs, int base, int index)
7422 const char *opn = "extended float load/store";
7424 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7425 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7428 gen_load_gpr(t0, index);
7429 } else if (index == 0) {
7430 gen_load_gpr(t0, base);
7432 gen_load_gpr(t0, base);
7433 gen_load_gpr(t1, index);
7434 gen_op_addr_add(t0, t1);
7436 /* Don't do NOP if destination is zero: we must perform the actual
7442 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7444 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
7445 gen_store_fpr32(fp0, fd);
7452 check_cp1_registers(ctx, fd);
7454 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7456 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7457 gen_store_fpr64(ctx, fp0, fd);
7463 check_cp1_64bitmode(ctx);
7464 tcg_gen_andi_tl(t0, t0, ~0x7);
7466 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7468 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7469 gen_store_fpr64(ctx, fp0, fd);
7477 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7479 gen_load_fpr32(fp0, fs);
7480 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
7488 check_cp1_registers(ctx, fs);
7490 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7492 gen_load_fpr64(ctx, fp0, fs);
7493 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7500 check_cp1_64bitmode(ctx);
7501 tcg_gen_andi_tl(t0, t0, ~0x7);
7503 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7505 gen_load_fpr64(ctx, fp0, fs);
7506 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7514 generate_exception(ctx, EXCP_RI);
7521 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7522 regnames[index], regnames[base]);
7525 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7526 int fd, int fr, int fs, int ft)
7528 const char *opn = "flt3_arith";
7532 check_cp1_64bitmode(ctx);
7534 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7535 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7536 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7537 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
7538 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
7539 int l1 = gen_new_label();
7540 int l2 = gen_new_label();
7542 gen_load_gpr(t0, fr);
7543 tcg_gen_andi_tl(t0, t0, 0x7);
7544 gen_load_fpr32(fp0, fs);
7545 gen_load_fpr32h(fph0, fs);
7546 gen_load_fpr32(fp1, ft);
7547 gen_load_fpr32h(fph1, ft);
7549 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7550 gen_store_fpr32(fp0, fd);
7551 gen_store_fpr32h(fph0, fd);
7554 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7556 #ifdef TARGET_WORDS_BIGENDIAN
7557 gen_store_fpr32(fph1, fd);
7558 gen_store_fpr32h(fp0, fd);
7560 gen_store_fpr32(fph0, fd);
7561 gen_store_fpr32h(fp1, fd);
7565 tcg_temp_free(fph0);
7567 tcg_temp_free(fph1);
7574 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7575 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7576 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7578 gen_load_fpr32(fp0, fs);
7579 gen_load_fpr32(fp1, ft);
7580 gen_load_fpr32(fp2, fr);
7581 tcg_gen_helper_1_3(do_float_muladd_s, fp2, fp0, fp1, fp2);
7584 gen_store_fpr32(fp2, fd);
7591 check_cp1_registers(ctx, fd | fs | ft | fr);
7593 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7594 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7595 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7597 gen_load_fpr64(ctx, fp0, fs);
7598 gen_load_fpr64(ctx, fp1, ft);
7599 gen_load_fpr64(ctx, fp2, fr);
7600 tcg_gen_helper_1_3(do_float_muladd_d, fp2, fp0, fp1, fp2);
7603 gen_store_fpr64(ctx, fp2, fd);
7609 check_cp1_64bitmode(ctx);
7611 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7612 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7613 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7615 gen_load_fpr64(ctx, fp0, fs);
7616 gen_load_fpr64(ctx, fp1, ft);
7617 gen_load_fpr64(ctx, fp2, fr);
7618 tcg_gen_helper_1_3(do_float_muladd_ps, fp2, fp0, fp1, fp2);
7621 gen_store_fpr64(ctx, fp2, fd);
7629 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7630 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7631 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7633 gen_load_fpr32(fp0, fs);
7634 gen_load_fpr32(fp1, ft);
7635 gen_load_fpr32(fp2, fr);
7636 tcg_gen_helper_1_3(do_float_mulsub_s, fp2, fp0, fp1, fp2);
7639 gen_store_fpr32(fp2, fd);
7646 check_cp1_registers(ctx, fd | fs | ft | fr);
7648 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7649 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7650 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7652 gen_load_fpr64(ctx, fp0, fs);
7653 gen_load_fpr64(ctx, fp1, ft);
7654 gen_load_fpr64(ctx, fp2, fr);
7655 tcg_gen_helper_1_3(do_float_mulsub_d, fp2, fp0, fp1, fp2);
7658 gen_store_fpr64(ctx, fp2, fd);
7664 check_cp1_64bitmode(ctx);
7666 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7667 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7668 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7670 gen_load_fpr64(ctx, fp0, fs);
7671 gen_load_fpr64(ctx, fp1, ft);
7672 gen_load_fpr64(ctx, fp2, fr);
7673 tcg_gen_helper_1_3(do_float_mulsub_ps, fp2, fp0, fp1, fp2);
7676 gen_store_fpr64(ctx, fp2, fd);
7684 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7685 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7686 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7688 gen_load_fpr32(fp0, fs);
7689 gen_load_fpr32(fp1, ft);
7690 gen_load_fpr32(fp2, fr);
7691 tcg_gen_helper_1_3(do_float_nmuladd_s, fp2, fp0, fp1, fp2);
7694 gen_store_fpr32(fp2, fd);
7701 check_cp1_registers(ctx, fd | fs | ft | fr);
7703 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7704 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7705 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7707 gen_load_fpr64(ctx, fp0, fs);
7708 gen_load_fpr64(ctx, fp1, ft);
7709 gen_load_fpr64(ctx, fp2, fr);
7710 tcg_gen_helper_1_3(do_float_nmuladd_d, fp2, fp0, fp1, fp2);
7713 gen_store_fpr64(ctx, fp2, fd);
7719 check_cp1_64bitmode(ctx);
7721 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7722 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7723 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7725 gen_load_fpr64(ctx, fp0, fs);
7726 gen_load_fpr64(ctx, fp1, ft);
7727 gen_load_fpr64(ctx, fp2, fr);
7728 tcg_gen_helper_1_3(do_float_nmuladd_ps, fp2, fp0, fp1, fp2);
7731 gen_store_fpr64(ctx, fp2, fd);
7739 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7740 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7741 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7743 gen_load_fpr32(fp0, fs);
7744 gen_load_fpr32(fp1, ft);
7745 gen_load_fpr32(fp2, fr);
7746 tcg_gen_helper_1_3(do_float_nmulsub_s, fp2, fp0, fp1, fp2);
7749 gen_store_fpr32(fp2, fd);
7756 check_cp1_registers(ctx, fd | fs | ft | fr);
7758 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7759 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7760 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7762 gen_load_fpr64(ctx, fp0, fs);
7763 gen_load_fpr64(ctx, fp1, ft);
7764 gen_load_fpr64(ctx, fp2, fr);
7765 tcg_gen_helper_1_3(do_float_nmulsub_d, fp2, fp0, fp1, fp2);
7768 gen_store_fpr64(ctx, fp2, fd);
7774 check_cp1_64bitmode(ctx);
7776 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7777 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7778 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7780 gen_load_fpr64(ctx, fp0, fs);
7781 gen_load_fpr64(ctx, fp1, ft);
7782 gen_load_fpr64(ctx, fp2, fr);
7783 tcg_gen_helper_1_3(do_float_nmulsub_ps, fp2, fp0, fp1, fp2);
7786 gen_store_fpr64(ctx, fp2, fd);
7793 generate_exception (ctx, EXCP_RI);
7796 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7797 fregnames[fs], fregnames[ft]);
7800 /* ISA extensions (ASEs) */
7801 /* MIPS16 extension to MIPS32 */
7802 /* SmartMIPS extension to MIPS32 */
7804 #if defined(TARGET_MIPS64)
7806 /* MDMX extension to MIPS64 */
7810 static void decode_opc (CPUState *env, DisasContext *ctx)
7814 uint32_t op, op1, op2;
7817 /* make sure instructions are on a word boundary */
7818 if (ctx->pc & 0x3) {
7819 env->CP0_BadVAddr = ctx->pc;
7820 generate_exception(ctx, EXCP_AdEL);
7824 /* Handle blikely not taken case */
7825 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7826 int l1 = gen_new_label();
7828 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7829 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7831 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
7833 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7834 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7835 tcg_temp_free(r_tmp);
7837 gen_goto_tb(ctx, 1, ctx->pc + 4);
7840 op = MASK_OP_MAJOR(ctx->opcode);
7841 rs = (ctx->opcode >> 21) & 0x1f;
7842 rt = (ctx->opcode >> 16) & 0x1f;
7843 rd = (ctx->opcode >> 11) & 0x1f;
7844 sa = (ctx->opcode >> 6) & 0x1f;
7845 imm = (int16_t)ctx->opcode;
7848 op1 = MASK_SPECIAL(ctx->opcode);
7850 case OPC_SLL: /* Arithmetic with immediate */
7851 case OPC_SRL ... OPC_SRA:
7852 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7854 case OPC_MOVZ ... OPC_MOVN:
7855 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7856 case OPC_SLLV: /* Arithmetic */
7857 case OPC_SRLV ... OPC_SRAV:
7858 case OPC_ADD ... OPC_NOR:
7859 case OPC_SLT ... OPC_SLTU:
7860 gen_arith(env, ctx, op1, rd, rs, rt);
7862 case OPC_MULT ... OPC_DIVU:
7864 check_insn(env, ctx, INSN_VR54XX);
7865 op1 = MASK_MUL_VR54XX(ctx->opcode);
7866 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7868 gen_muldiv(ctx, op1, rs, rt);
7870 case OPC_JR ... OPC_JALR:
7871 gen_compute_branch(ctx, op1, rs, rd, sa);
7873 case OPC_TGE ... OPC_TEQ: /* Traps */
7875 gen_trap(ctx, op1, rs, rt, -1);
7877 case OPC_MFHI: /* Move from HI/LO */
7879 gen_HILO(ctx, op1, rd);
7882 case OPC_MTLO: /* Move to HI/LO */
7883 gen_HILO(ctx, op1, rs);
7885 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7886 #ifdef MIPS_STRICT_STANDARD
7887 MIPS_INVAL("PMON / selsl");
7888 generate_exception(ctx, EXCP_RI);
7890 tcg_gen_helper_0_i(do_pmon, sa);
7894 generate_exception(ctx, EXCP_SYSCALL);
7897 generate_exception(ctx, EXCP_BREAK);
7900 #ifdef MIPS_STRICT_STANDARD
7902 generate_exception(ctx, EXCP_RI);
7904 /* Implemented as RI exception for now. */
7905 MIPS_INVAL("spim (unofficial)");
7906 generate_exception(ctx, EXCP_RI);
7914 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7915 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7916 save_cpu_state(ctx, 1);
7917 check_cp1_enabled(ctx);
7918 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7919 (ctx->opcode >> 16) & 1);
7921 generate_exception_err(ctx, EXCP_CpU, 1);
7925 #if defined(TARGET_MIPS64)
7926 /* MIPS64 specific opcodes */
7928 case OPC_DSRL ... OPC_DSRA:
7930 case OPC_DSRL32 ... OPC_DSRA32:
7931 check_insn(env, ctx, ISA_MIPS3);
7933 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7936 case OPC_DSRLV ... OPC_DSRAV:
7937 case OPC_DADD ... OPC_DSUBU:
7938 check_insn(env, ctx, ISA_MIPS3);
7940 gen_arith(env, ctx, op1, rd, rs, rt);
7942 case OPC_DMULT ... OPC_DDIVU:
7943 check_insn(env, ctx, ISA_MIPS3);
7945 gen_muldiv(ctx, op1, rs, rt);
7948 default: /* Invalid */
7949 MIPS_INVAL("special");
7950 generate_exception(ctx, EXCP_RI);
7955 op1 = MASK_SPECIAL2(ctx->opcode);
7957 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7958 case OPC_MSUB ... OPC_MSUBU:
7959 check_insn(env, ctx, ISA_MIPS32);
7960 gen_muldiv(ctx, op1, rs, rt);
7963 gen_arith(env, ctx, op1, rd, rs, rt);
7965 case OPC_CLZ ... OPC_CLO:
7966 check_insn(env, ctx, ISA_MIPS32);
7967 gen_cl(ctx, op1, rd, rs);
7970 /* XXX: not clear which exception should be raised
7971 * when in debug mode...
7973 check_insn(env, ctx, ISA_MIPS32);
7974 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7975 generate_exception(ctx, EXCP_DBp);
7977 generate_exception(ctx, EXCP_DBp);
7981 #if defined(TARGET_MIPS64)
7982 case OPC_DCLZ ... OPC_DCLO:
7983 check_insn(env, ctx, ISA_MIPS64);
7985 gen_cl(ctx, op1, rd, rs);
7988 default: /* Invalid */
7989 MIPS_INVAL("special2");
7990 generate_exception(ctx, EXCP_RI);
7995 op1 = MASK_SPECIAL3(ctx->opcode);
7999 check_insn(env, ctx, ISA_MIPS32R2);
8000 gen_bitops(ctx, op1, rt, rs, sa, rd);
8003 check_insn(env, ctx, ISA_MIPS32R2);
8004 op2 = MASK_BSHFL(ctx->opcode);
8006 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8007 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8011 gen_load_gpr(t1, rt);
8012 tcg_gen_helper_1_1(do_wsbh, t0, t1);
8013 gen_store_gpr(t0, rd);
8016 gen_load_gpr(t1, rt);
8017 tcg_gen_ext8s_tl(t0, t1);
8018 gen_store_gpr(t0, rd);
8021 gen_load_gpr(t1, rt);
8022 tcg_gen_ext16s_tl(t0, t1);
8023 gen_store_gpr(t0, rd);
8025 default: /* Invalid */
8026 MIPS_INVAL("bshfl");
8027 generate_exception(ctx, EXCP_RI);
8035 check_insn(env, ctx, ISA_MIPS32R2);
8037 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8041 save_cpu_state(ctx, 1);
8042 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
8045 save_cpu_state(ctx, 1);
8046 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
8049 save_cpu_state(ctx, 1);
8050 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
8053 save_cpu_state(ctx, 1);
8054 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
8057 if (env->user_mode_only) {
8058 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
8061 /* XXX: Some CPUs implement this in hardware.
8062 Not supported yet. */
8064 default: /* Invalid */
8065 MIPS_INVAL("rdhwr");
8066 generate_exception(ctx, EXCP_RI);
8069 gen_store_gpr(t0, rt);
8074 check_insn(env, ctx, ASE_MT);
8076 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8077 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8079 gen_load_gpr(t0, rt);
8080 gen_load_gpr(t1, rs);
8081 tcg_gen_helper_0_2(do_fork, t0, t1);
8087 check_insn(env, ctx, ASE_MT);
8089 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8091 gen_load_gpr(t0, rs);
8092 tcg_gen_helper_1_1(do_yield, t0, t0);
8093 gen_store_gpr(t0, rd);
8097 #if defined(TARGET_MIPS64)
8098 case OPC_DEXTM ... OPC_DEXT:
8099 case OPC_DINSM ... OPC_DINS:
8100 check_insn(env, ctx, ISA_MIPS64R2);
8102 gen_bitops(ctx, op1, rt, rs, sa, rd);
8105 check_insn(env, ctx, ISA_MIPS64R2);
8107 op2 = MASK_DBSHFL(ctx->opcode);
8109 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8110 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8114 gen_load_gpr(t1, rt);
8115 tcg_gen_helper_1_1(do_dsbh, t0, t1);
8118 gen_load_gpr(t1, rt);
8119 tcg_gen_helper_1_1(do_dshd, t0, t1);
8121 default: /* Invalid */
8122 MIPS_INVAL("dbshfl");
8123 generate_exception(ctx, EXCP_RI);
8126 gen_store_gpr(t0, rd);
8132 default: /* Invalid */
8133 MIPS_INVAL("special3");
8134 generate_exception(ctx, EXCP_RI);
8139 op1 = MASK_REGIMM(ctx->opcode);
8141 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
8142 case OPC_BLTZAL ... OPC_BGEZALL:
8143 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
8145 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
8147 gen_trap(ctx, op1, rs, -1, imm);
8150 check_insn(env, ctx, ISA_MIPS32R2);
8153 default: /* Invalid */
8154 MIPS_INVAL("regimm");
8155 generate_exception(ctx, EXCP_RI);
8160 check_cp0_enabled(ctx);
8161 op1 = MASK_CP0(ctx->opcode);
8167 #if defined(TARGET_MIPS64)
8171 #ifndef CONFIG_USER_ONLY
8172 if (!env->user_mode_only)
8173 gen_cp0(env, ctx, op1, rt, rd);
8174 #endif /* !CONFIG_USER_ONLY */
8176 case OPC_C0_FIRST ... OPC_C0_LAST:
8177 #ifndef CONFIG_USER_ONLY
8178 if (!env->user_mode_only)
8179 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
8180 #endif /* !CONFIG_USER_ONLY */
8183 #ifndef CONFIG_USER_ONLY
8184 if (!env->user_mode_only) {
8185 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8187 op2 = MASK_MFMC0(ctx->opcode);
8190 check_insn(env, ctx, ASE_MT);
8191 tcg_gen_helper_1_1(do_dmt, t0, t0);
8194 check_insn(env, ctx, ASE_MT);
8195 tcg_gen_helper_1_1(do_emt, t0, t0);
8198 check_insn(env, ctx, ASE_MT);
8199 tcg_gen_helper_1_1(do_dvpe, t0, t0);
8202 check_insn(env, ctx, ASE_MT);
8203 tcg_gen_helper_1_1(do_evpe, t0, t0);
8206 check_insn(env, ctx, ISA_MIPS32R2);
8207 save_cpu_state(ctx, 1);
8208 tcg_gen_helper_1_0(do_di, t0);
8209 /* Stop translation as we may have switched the execution mode */
8210 ctx->bstate = BS_STOP;
8213 check_insn(env, ctx, ISA_MIPS32R2);
8214 save_cpu_state(ctx, 1);
8215 tcg_gen_helper_1_0(do_ei, t0);
8216 /* Stop translation as we may have switched the execution mode */
8217 ctx->bstate = BS_STOP;
8219 default: /* Invalid */
8220 MIPS_INVAL("mfmc0");
8221 generate_exception(ctx, EXCP_RI);
8224 gen_store_gpr(t0, rt);
8227 #endif /* !CONFIG_USER_ONLY */
8230 check_insn(env, ctx, ISA_MIPS32R2);
8231 gen_load_srsgpr(rt, rd);
8234 check_insn(env, ctx, ISA_MIPS32R2);
8235 gen_store_srsgpr(rt, rd);
8239 generate_exception(ctx, EXCP_RI);
8243 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
8244 gen_arith_imm(env, ctx, op, rt, rs, imm);
8246 case OPC_J ... OPC_JAL: /* Jump */
8247 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
8248 gen_compute_branch(ctx, op, rs, rt, offset);
8250 case OPC_BEQ ... OPC_BGTZ: /* Branch */
8251 case OPC_BEQL ... OPC_BGTZL:
8252 gen_compute_branch(ctx, op, rs, rt, imm << 2);
8254 case OPC_LB ... OPC_LWR: /* Load and stores */
8255 case OPC_SB ... OPC_SW:
8259 gen_ldst(ctx, op, rt, rs, imm);
8262 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
8266 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
8270 /* Floating point (COP1). */
8275 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8276 save_cpu_state(ctx, 1);
8277 check_cp1_enabled(ctx);
8278 gen_flt_ldst(ctx, op, rt, rs, imm);
8280 generate_exception_err(ctx, EXCP_CpU, 1);
8285 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8286 save_cpu_state(ctx, 1);
8287 check_cp1_enabled(ctx);
8288 op1 = MASK_CP1(ctx->opcode);
8292 check_insn(env, ctx, ISA_MIPS32R2);
8297 gen_cp1(ctx, op1, rt, rd);
8299 #if defined(TARGET_MIPS64)
8302 check_insn(env, ctx, ISA_MIPS3);
8303 gen_cp1(ctx, op1, rt, rd);
8309 check_insn(env, ctx, ASE_MIPS3D);
8312 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8313 (rt >> 2) & 0x7, imm << 2);
8320 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8325 generate_exception (ctx, EXCP_RI);
8329 generate_exception_err(ctx, EXCP_CpU, 1);
8339 /* COP2: Not implemented. */
8340 generate_exception_err(ctx, EXCP_CpU, 2);
8344 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8345 save_cpu_state(ctx, 1);
8346 check_cp1_enabled(ctx);
8347 op1 = MASK_CP3(ctx->opcode);
8355 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8373 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8377 generate_exception (ctx, EXCP_RI);
8381 generate_exception_err(ctx, EXCP_CpU, 1);
8385 #if defined(TARGET_MIPS64)
8386 /* MIPS64 opcodes */
8388 case OPC_LDL ... OPC_LDR:
8389 case OPC_SDL ... OPC_SDR:
8394 check_insn(env, ctx, ISA_MIPS3);
8396 gen_ldst(ctx, op, rt, rs, imm);
8398 case OPC_DADDI ... OPC_DADDIU:
8399 check_insn(env, ctx, ISA_MIPS3);
8401 gen_arith_imm(env, ctx, op, rt, rs, imm);
8405 check_insn(env, ctx, ASE_MIPS16);
8406 /* MIPS16: Not implemented. */
8408 check_insn(env, ctx, ASE_MDMX);
8409 /* MDMX: Not implemented. */
8410 default: /* Invalid */
8411 MIPS_INVAL("major opcode");
8412 generate_exception(ctx, EXCP_RI);
8415 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8416 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8417 /* Branches completion */
8418 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8419 ctx->bstate = BS_BRANCH;
8420 save_cpu_state(ctx, 0);
8421 /* FIXME: Need to clear can_do_io. */
8424 /* unconditional branch */
8425 MIPS_DEBUG("unconditional branch");
8426 gen_goto_tb(ctx, 0, ctx->btarget);
8429 /* blikely taken case */
8430 MIPS_DEBUG("blikely branch taken");
8431 gen_goto_tb(ctx, 0, ctx->btarget);
8434 /* Conditional branch */
8435 MIPS_DEBUG("conditional branch");
8437 int l1 = gen_new_label();
8439 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8440 gen_goto_tb(ctx, 1, ctx->pc + 4);
8442 gen_goto_tb(ctx, 0, ctx->btarget);
8446 /* unconditional branch to register */
8447 MIPS_DEBUG("branch to register");
8448 tcg_gen_mov_tl(cpu_PC, btarget);
8452 MIPS_DEBUG("unknown branch");
8459 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8463 target_ulong pc_start;
8464 uint16_t *gen_opc_end;
8469 if (search_pc && loglevel)
8470 fprintf (logfile, "search pc %d\n", search_pc);
8473 /* Leave some spare opc slots for branch handling. */
8474 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8478 ctx.bstate = BS_NONE;
8479 /* Restore delay slot state from the tb context. */
8480 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8481 restore_cpu_state(env, &ctx);
8482 if (env->user_mode_only)
8483 ctx.mem_idx = MIPS_HFLAG_UM;
8485 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8487 max_insns = tb->cflags & CF_COUNT_MASK;
8489 max_insns = CF_COUNT_MASK;
8491 if (loglevel & CPU_LOG_TB_CPU) {
8492 fprintf(logfile, "------------------------------------------------\n");
8493 /* FIXME: This may print out stale hflags from env... */
8494 cpu_dump_state(env, logfile, fprintf, 0);
8497 #ifdef MIPS_DEBUG_DISAS
8498 if (loglevel & CPU_LOG_TB_IN_ASM)
8499 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
8500 tb, ctx.mem_idx, ctx.hflags);
8503 while (ctx.bstate == BS_NONE) {
8504 if (env->nb_breakpoints > 0) {
8505 for(j = 0; j < env->nb_breakpoints; j++) {
8506 if (env->breakpoints[j] == ctx.pc) {
8507 save_cpu_state(&ctx, 1);
8508 ctx.bstate = BS_BRANCH;
8509 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8510 /* Include the breakpoint location or the tb won't
8511 * be flushed when it must be. */
8513 goto done_generating;
8519 j = gen_opc_ptr - gen_opc_buf;
8523 gen_opc_instr_start[lj++] = 0;
8525 gen_opc_pc[lj] = ctx.pc;
8526 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8527 gen_opc_instr_start[lj] = 1;
8528 gen_opc_icount[lj] = num_insns;
8530 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8532 ctx.opcode = ldl_code(ctx.pc);
8533 decode_opc(env, &ctx);
8537 if (env->singlestep_enabled)
8540 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8543 if (gen_opc_ptr >= gen_opc_end)
8546 if (num_insns >= max_insns)
8548 #if defined (MIPS_SINGLE_STEP)
8552 if (tb->cflags & CF_LAST_IO)
8554 if (env->singlestep_enabled) {
8555 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8556 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8558 switch (ctx.bstate) {
8560 tcg_gen_helper_0_0(do_interrupt_restart);
8561 gen_goto_tb(&ctx, 0, ctx.pc);
8564 save_cpu_state(&ctx, 0);
8565 gen_goto_tb(&ctx, 0, ctx.pc);
8568 tcg_gen_helper_0_0(do_interrupt_restart);
8577 gen_icount_end(tb, num_insns);
8578 *gen_opc_ptr = INDEX_op_end;
8580 j = gen_opc_ptr - gen_opc_buf;
8583 gen_opc_instr_start[lj++] = 0;
8585 tb->size = ctx.pc - pc_start;
8586 tb->icount = num_insns;
8589 #if defined MIPS_DEBUG_DISAS
8590 if (loglevel & CPU_LOG_TB_IN_ASM)
8591 fprintf(logfile, "\n");
8593 if (loglevel & CPU_LOG_TB_IN_ASM) {
8594 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
8595 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
8596 fprintf(logfile, "\n");
8598 if (loglevel & CPU_LOG_TB_CPU) {
8599 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8604 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8606 gen_intermediate_code_internal(env, tb, 0);
8609 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8611 gen_intermediate_code_internal(env, tb, 1);
8614 static void fpu_dump_state(CPUState *env, FILE *f,
8615 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8619 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8621 #define printfpr(fp) \
8624 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8625 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8626 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8629 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8630 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8631 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8632 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8633 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8638 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8639 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8640 get_float_exception_flags(&env->active_fpu.fp_status));
8641 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8642 fpu_fprintf(f, "%3s: ", fregnames[i]);
8643 printfpr(&env->active_fpu.fpr[i]);
8649 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8650 /* Debug help: The architecture requires 32bit code to maintain proper
8651 sign-extended values on 64bit machines. */
8653 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8656 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8657 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8662 if (!SIGN_EXT_P(env->active_tc.PC))
8663 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8664 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8665 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8666 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8667 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8668 if (!SIGN_EXT_P(env->btarget))
8669 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8671 for (i = 0; i < 32; i++) {
8672 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8673 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8676 if (!SIGN_EXT_P(env->CP0_EPC))
8677 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8678 if (!SIGN_EXT_P(env->CP0_LLAddr))
8679 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8683 void cpu_dump_state (CPUState *env, FILE *f,
8684 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8689 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",
8690 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8691 env->hflags, env->btarget, env->bcond);
8692 for (i = 0; i < 32; i++) {
8694 cpu_fprintf(f, "GPR%02d:", i);
8695 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8697 cpu_fprintf(f, "\n");
8700 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8701 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8702 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8703 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8704 if (env->hflags & MIPS_HFLAG_FPU)
8705 fpu_dump_state(env, f, cpu_fprintf, flags);
8706 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8707 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8711 static void mips_tcg_init(void)
8716 /* Initialize various static tables. */
8720 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8721 for (i = 0; i < 32; i++)
8722 cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8723 offsetof(CPUState, active_tc.gpr[i]),
8725 cpu_PC = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8726 offsetof(CPUState, active_tc.PC), "PC");
8727 for (i = 0; i < MIPS_DSP_ACC; i++) {
8728 cpu_HI[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8729 offsetof(CPUState, active_tc.HI[i]),
8731 cpu_LO[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8732 offsetof(CPUState, active_tc.LO[i]),
8734 cpu_ACX[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8735 offsetof(CPUState, active_tc.ACX[i]),
8738 cpu_dspctrl = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8739 offsetof(CPUState, active_tc.DSPControl),
8741 bcond = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8742 offsetof(CPUState, bcond), "bcond");
8743 btarget = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8744 offsetof(CPUState, btarget), "btarget");
8745 for (i = 0; i < 32; i++)
8746 fpu_fpr32[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8747 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8749 for (i = 0; i < 32; i++)
8750 fpu_fpr64[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
8751 offsetof(CPUState, active_fpu.fpr[i]),
8753 for (i = 0; i < 32; i++)
8754 fpu_fpr32h[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8755 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8757 fpu_fcr0 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8758 offsetof(CPUState, active_fpu.fcr0),
8760 fpu_fcr31 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8761 offsetof(CPUState, active_fpu.fcr31),
8764 /* register helpers */
8766 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8772 #include "translate_init.c"
8774 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8777 const mips_def_t *def;
8779 def = cpu_mips_find_by_name(cpu_model);
8782 env = qemu_mallocz(sizeof(CPUMIPSState));
8785 env->cpu_model = def;
8788 env->cpu_model_str = cpu_model;
8794 void cpu_reset (CPUMIPSState *env)
8796 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8801 #if defined(CONFIG_USER_ONLY)
8802 env->user_mode_only = 1;
8804 if (env->user_mode_only) {
8805 env->hflags = MIPS_HFLAG_UM;
8807 if (env->hflags & MIPS_HFLAG_BMASK) {
8808 /* If the exception was raised from a delay slot,
8809 come back to the jump. */
8810 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8812 env->CP0_ErrorEPC = env->active_tc.PC;
8814 env->active_tc.PC = (int32_t)0xBFC00000;
8816 /* SMP not implemented */
8817 env->CP0_EBase = 0x80000000;
8818 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8819 /* vectored interrupts not implemented, timer on int 7,
8820 no performance counters. */
8821 env->CP0_IntCtl = 0xe0000000;
8825 for (i = 0; i < 7; i++) {
8826 env->CP0_WatchLo[i] = 0;
8827 env->CP0_WatchHi[i] = 0x80000000;
8829 env->CP0_WatchLo[7] = 0;
8830 env->CP0_WatchHi[7] = 0;
8832 /* Count register increments in debug mode, EJTAG version 1 */
8833 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8834 env->hflags = MIPS_HFLAG_CP0;
8836 env->exception_index = EXCP_NONE;
8837 cpu_mips_register(env, env->cpu_model);
8840 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8841 unsigned long searched_pc, int pc_pos, void *puc)
8843 env->active_tc.PC = gen_opc_pc[pc_pos];
8844 env->hflags &= ~MIPS_HFLAG_BMASK;
8845 env->hflags |= gen_opc_hflags[pc_pos];