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, bcond, btarget;
427 static TCGv fpu_fpr32[32], fpu_fpr32h[32], fpu_fpr64[32], fpu_fcr0, fpu_fcr31;
429 #include "gen-icount.h"
431 static inline void tcg_gen_helper_0_i(void *func, uint32_t arg)
434 TCGv tmp = tcg_const_i32(arg);
436 tcg_gen_helper_0_1(func, tmp);
440 static inline void tcg_gen_helper_0_ii(void *func, uint32_t arg1, uint32_t arg2)
442 TCGv tmp1 = tcg_const_i32(arg1);
443 TCGv tmp2 = tcg_const_i32(arg2);
445 tcg_gen_helper_0_2(func, tmp1, tmp2);
450 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg1, uint32_t arg2)
452 TCGv tmp = tcg_const_i32(arg2);
454 tcg_gen_helper_0_2(func, arg1, tmp);
458 static inline void tcg_gen_helper_0_2i(void *func, TCGv arg1, TCGv arg2, uint32_t arg3)
460 TCGv tmp = tcg_const_i32(arg3);
462 tcg_gen_helper_0_3(func, arg1, arg2, tmp);
466 static inline void tcg_gen_helper_0_1ii(void *func, TCGv arg1, uint32_t arg2, uint32_t arg3)
468 TCGv tmp1 = tcg_const_i32(arg2);
469 TCGv tmp2 = tcg_const_i32(arg3);
471 tcg_gen_helper_0_3(func, arg1, tmp1, tmp2);
476 static inline void tcg_gen_helper_1_i(void *func, TCGv ret, uint32_t arg)
478 TCGv tmp = tcg_const_i32(arg);
480 tcg_gen_helper_1_1(func, ret, tmp);
484 static inline void tcg_gen_helper_1_1i(void *func, TCGv ret, TCGv arg1, uint32_t arg2)
486 TCGv tmp = tcg_const_i32(arg2);
488 tcg_gen_helper_1_2(func, ret, arg1, tmp);
492 static inline void tcg_gen_helper_1_1ii(void *func, TCGv ret, TCGv arg1, uint32_t arg2, uint32_t arg3)
494 TCGv tmp1 = tcg_const_i32(arg2);
495 TCGv tmp2 = tcg_const_i32(arg3);
497 tcg_gen_helper_1_3(func, ret, arg1, tmp1, tmp2);
502 static inline void tcg_gen_helper_1_2i(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3)
504 TCGv tmp = tcg_const_i32(arg3);
506 tcg_gen_helper_1_3(func, ret, arg1, arg2, tmp);
510 static inline void tcg_gen_helper_1_2ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3, uint32_t arg4)
512 TCGv tmp1 = tcg_const_i32(arg3);
513 TCGv tmp2 = tcg_const_i32(arg4);
515 tcg_gen_helper_1_4(func, ret, arg1, arg2, tmp1, tmp2);
520 typedef struct DisasContext {
521 struct TranslationBlock *tb;
522 target_ulong pc, saved_pc;
524 /* Routine used to access memory */
526 uint32_t hflags, saved_hflags;
528 target_ulong btarget;
532 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
533 * exception condition */
534 BS_STOP = 1, /* We want to stop translation for any reason */
535 BS_BRANCH = 2, /* We reached a branch condition */
536 BS_EXCP = 3, /* We reached an exception condition */
539 static const char *regnames[] =
540 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
541 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
542 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
543 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
545 static const char *fregnames[] =
546 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
547 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
548 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
549 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
551 static const char *fregnames_64[] =
552 { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
553 "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15",
554 "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23",
555 "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31", };
557 static const char *fregnames_h[] =
558 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
559 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
560 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
561 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
563 #ifdef MIPS_DEBUG_DISAS
564 #define MIPS_DEBUG(fmt, args...) \
566 if (loglevel & CPU_LOG_TB_IN_ASM) { \
567 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
568 ctx->pc, ctx->opcode , ##args); \
572 #define MIPS_DEBUG(fmt, args...) do { } while(0)
575 #define MIPS_INVAL(op) \
577 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
578 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
581 /* General purpose registers moves. */
582 static inline void gen_load_gpr (TCGv t, int reg)
585 tcg_gen_movi_tl(t, 0);
587 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
588 sizeof(target_ulong) * reg);
591 static inline void gen_store_gpr (TCGv t, int reg)
594 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
595 sizeof(target_ulong) * reg);
598 /* Moves to/from HI and LO registers. */
599 static inline void gen_load_LO (TCGv t, int reg)
601 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
602 sizeof(target_ulong) * reg);
605 static inline void gen_store_LO (TCGv t, int reg)
607 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
608 sizeof(target_ulong) * reg);
611 static inline void gen_load_HI (TCGv t, int reg)
613 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
614 sizeof(target_ulong) * reg);
617 static inline void gen_store_HI (TCGv t, int reg)
619 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
620 sizeof(target_ulong) * reg);
623 /* Moves to/from shadow registers. */
624 static inline void gen_load_srsgpr (int from, int to)
626 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
629 tcg_gen_movi_tl(r_tmp1, 0);
631 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
633 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
634 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
635 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
636 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
637 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
639 tcg_gen_ld_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * from);
640 tcg_temp_free(r_tmp2);
642 gen_store_gpr(r_tmp1, to);
643 tcg_temp_free(r_tmp1);
646 static inline void gen_store_srsgpr (int from, int to)
649 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
650 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
652 gen_load_gpr(r_tmp1, from);
653 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
654 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
655 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
656 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
657 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
659 tcg_gen_st_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * to);
660 tcg_temp_free(r_tmp1);
661 tcg_temp_free(r_tmp2);
665 /* Floating point register moves. */
666 static inline void gen_load_fpr32 (TCGv t, int reg)
668 tcg_gen_mov_i32(t, fpu_fpr32[reg]);
671 static inline void gen_store_fpr32 (TCGv t, int reg)
673 tcg_gen_mov_i32(fpu_fpr32[reg], t);
676 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
678 if (ctx->hflags & MIPS_HFLAG_F64)
679 tcg_gen_mov_i64(t, fpu_fpr64[reg]);
681 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
683 tcg_gen_extu_i32_i64(t, fpu_fpr32[reg | 1]);
684 tcg_gen_shli_i64(t, t, 32);
685 tcg_gen_extu_i32_i64(r_tmp2, fpu_fpr32[reg & ~1]);
686 tcg_gen_or_i64(t, t, r_tmp2);
687 tcg_temp_free(r_tmp2);
691 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
693 if (ctx->hflags & MIPS_HFLAG_F64)
694 tcg_gen_mov_i64(fpu_fpr64[reg], t);
696 tcg_gen_trunc_i64_i32(fpu_fpr32[reg & ~1], t);
697 tcg_gen_shri_i64(t, t, 32);
698 tcg_gen_trunc_i64_i32(fpu_fpr32[reg | 1], t);
702 static inline void gen_load_fpr32h (TCGv t, int reg)
704 tcg_gen_mov_i32(t, fpu_fpr32h[reg]);
707 static inline void gen_store_fpr32h (TCGv t, int reg)
709 tcg_gen_mov_i32(fpu_fpr32h[reg], t);
712 static inline void get_fp_cond (TCGv t)
714 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
715 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
717 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
718 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
719 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
720 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
721 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
722 tcg_temp_free(r_tmp1);
723 tcg_temp_free(r_tmp2);
726 typedef void (fcmp_fun32)(uint32_t, uint32_t, int);
727 typedef void (fcmp_fun64)(uint64_t, uint64_t, int);
729 #define FOP_CONDS(fcmp_fun, type, fmt) \
730 static fcmp_fun * fcmp ## type ## _ ## fmt ## _table[16] = { \
731 do_cmp ## type ## _ ## fmt ## _f, \
732 do_cmp ## type ## _ ## fmt ## _un, \
733 do_cmp ## type ## _ ## fmt ## _eq, \
734 do_cmp ## type ## _ ## fmt ## _ueq, \
735 do_cmp ## type ## _ ## fmt ## _olt, \
736 do_cmp ## type ## _ ## fmt ## _ult, \
737 do_cmp ## type ## _ ## fmt ## _ole, \
738 do_cmp ## type ## _ ## fmt ## _ule, \
739 do_cmp ## type ## _ ## fmt ## _sf, \
740 do_cmp ## type ## _ ## fmt ## _ngle, \
741 do_cmp ## type ## _ ## fmt ## _seq, \
742 do_cmp ## type ## _ ## fmt ## _ngl, \
743 do_cmp ## type ## _ ## fmt ## _lt, \
744 do_cmp ## type ## _ ## fmt ## _nge, \
745 do_cmp ## type ## _ ## fmt ## _le, \
746 do_cmp ## type ## _ ## fmt ## _ngt, \
748 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv a, TCGv b, int cc) \
750 tcg_gen_helper_0_2i(fcmp ## type ## _ ## fmt ## _table[n], a, b, cc); \
753 FOP_CONDS(fcmp_fun64, , d)
754 FOP_CONDS(fcmp_fun64, abs, d)
755 FOP_CONDS(fcmp_fun32, , s)
756 FOP_CONDS(fcmp_fun32, abs, s)
757 FOP_CONDS(fcmp_fun64, , ps)
758 FOP_CONDS(fcmp_fun64, abs, ps)
762 #define OP_COND(name, cond) \
763 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
765 int l1 = gen_new_label(); \
766 int l2 = gen_new_label(); \
768 tcg_gen_brcond_tl(cond, t0, t1, l1); \
769 tcg_gen_movi_tl(t0, 0); \
772 tcg_gen_movi_tl(t0, 1); \
775 OP_COND(eq, TCG_COND_EQ);
776 OP_COND(ne, TCG_COND_NE);
777 OP_COND(ge, TCG_COND_GE);
778 OP_COND(geu, TCG_COND_GEU);
779 OP_COND(lt, TCG_COND_LT);
780 OP_COND(ltu, TCG_COND_LTU);
783 #define OP_CONDI(name, cond) \
784 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
786 int l1 = gen_new_label(); \
787 int l2 = gen_new_label(); \
789 tcg_gen_brcondi_tl(cond, t, val, l1); \
790 tcg_gen_movi_tl(t, 0); \
793 tcg_gen_movi_tl(t, 1); \
796 OP_CONDI(lti, TCG_COND_LT);
797 OP_CONDI(ltiu, TCG_COND_LTU);
800 #define OP_CONDZ(name, cond) \
801 static inline void glue(gen_op_, name) (TCGv t) \
803 int l1 = gen_new_label(); \
804 int l2 = gen_new_label(); \
806 tcg_gen_brcondi_tl(cond, t, 0, l1); \
807 tcg_gen_movi_tl(t, 0); \
810 tcg_gen_movi_tl(t, 1); \
813 OP_CONDZ(gez, TCG_COND_GE);
814 OP_CONDZ(gtz, TCG_COND_GT);
815 OP_CONDZ(lez, TCG_COND_LE);
816 OP_CONDZ(ltz, TCG_COND_LT);
819 static inline void gen_save_pc(target_ulong pc)
821 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
823 tcg_gen_movi_tl(r_tmp, pc);
824 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, active_tc.PC));
825 tcg_temp_free(r_tmp);
828 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
830 #if defined MIPS_DEBUG_DISAS
831 if (loglevel & CPU_LOG_TB_IN_ASM) {
832 fprintf(logfile, "hflags %08x saved %08x\n",
833 ctx->hflags, ctx->saved_hflags);
836 if (do_save_pc && ctx->pc != ctx->saved_pc) {
837 gen_save_pc(ctx->pc);
838 ctx->saved_pc = ctx->pc;
840 if (ctx->hflags != ctx->saved_hflags) {
841 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
843 tcg_gen_movi_i32(r_tmp, ctx->hflags);
844 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
845 tcg_temp_free(r_tmp);
846 ctx->saved_hflags = ctx->hflags;
847 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
853 tcg_gen_movi_tl(btarget, ctx->btarget);
859 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
861 ctx->saved_hflags = ctx->hflags;
862 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
868 ctx->btarget = env->btarget;
874 generate_exception_err (DisasContext *ctx, int excp, int err)
876 save_cpu_state(ctx, 1);
877 tcg_gen_helper_0_ii(do_raise_exception_err, excp, err);
878 tcg_gen_helper_0_0(do_interrupt_restart);
883 generate_exception (DisasContext *ctx, int excp)
885 save_cpu_state(ctx, 1);
886 tcg_gen_helper_0_i(do_raise_exception, excp);
887 tcg_gen_helper_0_0(do_interrupt_restart);
891 /* Addresses computation */
892 static inline void gen_op_addr_add (TCGv t0, TCGv t1)
894 tcg_gen_add_tl(t0, t0, t1);
896 #if defined(TARGET_MIPS64)
897 /* For compatibility with 32-bit code, data reference in user mode
898 with Status_UX = 0 should be casted to 32-bit and sign extended.
899 See the MIPS64 PRA manual, section 4.10. */
901 int l1 = gen_new_label();
902 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
904 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
905 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
906 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
907 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
908 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
909 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
910 tcg_temp_free(r_tmp);
911 tcg_gen_ext32s_i64(t0, t0);
917 static inline void check_cp0_enabled(DisasContext *ctx)
919 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
920 generate_exception_err(ctx, EXCP_CpU, 1);
923 static inline void check_cp1_enabled(DisasContext *ctx)
925 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
926 generate_exception_err(ctx, EXCP_CpU, 1);
929 /* Verify that the processor is running with COP1X instructions enabled.
930 This is associated with the nabla symbol in the MIPS32 and MIPS64
933 static inline void check_cop1x(DisasContext *ctx)
935 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
936 generate_exception(ctx, EXCP_RI);
939 /* Verify that the processor is running with 64-bit floating-point
940 operations enabled. */
942 static inline void check_cp1_64bitmode(DisasContext *ctx)
944 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
945 generate_exception(ctx, EXCP_RI);
949 * Verify if floating point register is valid; an operation is not defined
950 * if bit 0 of any register specification is set and the FR bit in the
951 * Status register equals zero, since the register numbers specify an
952 * even-odd pair of adjacent coprocessor general registers. When the FR bit
953 * in the Status register equals one, both even and odd register numbers
954 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
956 * Multiple 64 bit wide registers can be checked by calling
957 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
959 static inline void check_cp1_registers(DisasContext *ctx, int regs)
961 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
962 generate_exception(ctx, EXCP_RI);
965 /* This code generates a "reserved instruction" exception if the
966 CPU does not support the instruction set corresponding to flags. */
967 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
969 if (unlikely(!(env->insn_flags & flags)))
970 generate_exception(ctx, EXCP_RI);
973 /* This code generates a "reserved instruction" exception if 64-bit
974 instructions are not enabled. */
975 static inline void check_mips_64(DisasContext *ctx)
977 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
978 generate_exception(ctx, EXCP_RI);
981 /* load/store instructions. */
982 #define OP_LD(insn,fname) \
983 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
985 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
992 #if defined(TARGET_MIPS64)
998 #define OP_ST(insn,fname) \
999 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1001 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1006 #if defined(TARGET_MIPS64)
1011 #define OP_LD_ATOMIC(insn,fname) \
1012 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1014 tcg_gen_mov_tl(t1, t0); \
1015 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1016 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1018 OP_LD_ATOMIC(ll,ld32s);
1019 #if defined(TARGET_MIPS64)
1020 OP_LD_ATOMIC(lld,ld64);
1024 #define OP_ST_ATOMIC(insn,fname,almask) \
1025 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1027 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1028 int l1 = gen_new_label(); \
1029 int l2 = gen_new_label(); \
1030 int l3 = gen_new_label(); \
1032 tcg_gen_andi_tl(r_tmp, t0, almask); \
1033 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1034 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1035 generate_exception(ctx, EXCP_AdES); \
1036 gen_set_label(l1); \
1037 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1038 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1039 tcg_temp_free(r_tmp); \
1040 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1041 tcg_gen_movi_tl(t0, 1); \
1043 gen_set_label(l2); \
1044 tcg_gen_movi_tl(t0, 0); \
1045 gen_set_label(l3); \
1047 OP_ST_ATOMIC(sc,st32,0x3);
1048 #if defined(TARGET_MIPS64)
1049 OP_ST_ATOMIC(scd,st64,0x7);
1053 /* Load and store */
1054 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1055 int base, int16_t offset)
1057 const char *opn = "ldst";
1058 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1059 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1062 tcg_gen_movi_tl(t0, offset);
1063 } else if (offset == 0) {
1064 gen_load_gpr(t0, base);
1066 gen_load_gpr(t0, base);
1067 tcg_gen_movi_tl(t1, offset);
1068 gen_op_addr_add(t0, t1);
1070 /* Don't do NOP if destination is zero: we must perform the actual
1073 #if defined(TARGET_MIPS64)
1075 op_ldst_lwu(t0, ctx);
1076 gen_store_gpr(t0, rt);
1080 op_ldst_ld(t0, ctx);
1081 gen_store_gpr(t0, rt);
1085 op_ldst_lld(t0, t1, ctx);
1086 gen_store_gpr(t0, rt);
1090 gen_load_gpr(t1, rt);
1091 op_ldst_sd(t0, t1, ctx);
1095 save_cpu_state(ctx, 1);
1096 gen_load_gpr(t1, rt);
1097 op_ldst_scd(t0, t1, ctx);
1098 gen_store_gpr(t0, rt);
1102 save_cpu_state(ctx, 1);
1103 gen_load_gpr(t1, rt);
1104 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1105 gen_store_gpr(t1, rt);
1109 save_cpu_state(ctx, 1);
1110 gen_load_gpr(t1, rt);
1111 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1115 save_cpu_state(ctx, 1);
1116 gen_load_gpr(t1, rt);
1117 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1118 gen_store_gpr(t1, rt);
1122 save_cpu_state(ctx, 1);
1123 gen_load_gpr(t1, rt);
1124 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1129 op_ldst_lw(t0, ctx);
1130 gen_store_gpr(t0, rt);
1134 gen_load_gpr(t1, rt);
1135 op_ldst_sw(t0, t1, ctx);
1139 op_ldst_lh(t0, ctx);
1140 gen_store_gpr(t0, rt);
1144 gen_load_gpr(t1, rt);
1145 op_ldst_sh(t0, t1, ctx);
1149 op_ldst_lhu(t0, ctx);
1150 gen_store_gpr(t0, rt);
1154 op_ldst_lb(t0, ctx);
1155 gen_store_gpr(t0, rt);
1159 gen_load_gpr(t1, rt);
1160 op_ldst_sb(t0, t1, ctx);
1164 op_ldst_lbu(t0, ctx);
1165 gen_store_gpr(t0, rt);
1169 save_cpu_state(ctx, 1);
1170 gen_load_gpr(t1, rt);
1171 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1172 gen_store_gpr(t1, rt);
1176 save_cpu_state(ctx, 1);
1177 gen_load_gpr(t1, rt);
1178 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1182 save_cpu_state(ctx, 1);
1183 gen_load_gpr(t1, rt);
1184 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1185 gen_store_gpr(t1, rt);
1189 save_cpu_state(ctx, 1);
1190 gen_load_gpr(t1, rt);
1191 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1195 op_ldst_ll(t0, t1, ctx);
1196 gen_store_gpr(t0, rt);
1200 save_cpu_state(ctx, 1);
1201 gen_load_gpr(t1, rt);
1202 op_ldst_sc(t0, t1, ctx);
1203 gen_store_gpr(t0, rt);
1208 generate_exception(ctx, EXCP_RI);
1211 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1217 /* Load and store */
1218 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1219 int base, int16_t offset)
1221 const char *opn = "flt_ldst";
1222 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1225 tcg_gen_movi_tl(t0, offset);
1226 } else if (offset == 0) {
1227 gen_load_gpr(t0, base);
1229 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1231 gen_load_gpr(t0, base);
1232 tcg_gen_movi_tl(t1, offset);
1233 gen_op_addr_add(t0, t1);
1236 /* Don't do NOP if destination is zero: we must perform the actual
1241 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1243 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
1244 gen_store_fpr32(fp0, ft);
1251 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1253 gen_load_fpr32(fp0, ft);
1254 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
1261 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1263 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1264 gen_store_fpr64(ctx, fp0, ft);
1271 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1273 gen_load_fpr64(ctx, fp0, ft);
1274 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1281 generate_exception(ctx, EXCP_RI);
1284 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1289 /* Arithmetic with immediate operand */
1290 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1291 int rt, int rs, int16_t imm)
1294 const char *opn = "imm arith";
1295 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1297 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1298 /* If no destination, treat it as a NOP.
1299 For addi, we must generate the overflow exception when needed. */
1303 uimm = (uint16_t)imm;
1307 #if defined(TARGET_MIPS64)
1313 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1318 gen_load_gpr(t0, rs);
1321 tcg_gen_movi_tl(t0, imm << 16);
1326 #if defined(TARGET_MIPS64)
1335 gen_load_gpr(t0, rs);
1341 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1342 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1343 int l1 = gen_new_label();
1345 save_cpu_state(ctx, 1);
1346 tcg_gen_ext32s_tl(r_tmp1, t0);
1347 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1349 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1350 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1351 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1352 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1353 tcg_temp_free(r_tmp2);
1354 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1355 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1356 tcg_temp_free(r_tmp1);
1357 /* operands of same sign, result different sign */
1358 generate_exception(ctx, EXCP_OVERFLOW);
1361 tcg_gen_ext32s_tl(t0, t0);
1366 tcg_gen_ext32s_tl(t0, t0);
1367 tcg_gen_addi_tl(t0, t0, uimm);
1368 tcg_gen_ext32s_tl(t0, t0);
1371 #if defined(TARGET_MIPS64)
1374 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1375 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1376 int l1 = gen_new_label();
1378 save_cpu_state(ctx, 1);
1379 tcg_gen_mov_tl(r_tmp1, t0);
1380 tcg_gen_addi_tl(t0, t0, uimm);
1382 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1383 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1384 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1385 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1386 tcg_temp_free(r_tmp2);
1387 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1388 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1389 tcg_temp_free(r_tmp1);
1390 /* operands of same sign, result different sign */
1391 generate_exception(ctx, EXCP_OVERFLOW);
1397 tcg_gen_addi_tl(t0, t0, uimm);
1402 gen_op_lti(t0, uimm);
1406 gen_op_ltiu(t0, uimm);
1410 tcg_gen_andi_tl(t0, t0, uimm);
1414 tcg_gen_ori_tl(t0, t0, uimm);
1418 tcg_gen_xori_tl(t0, t0, uimm);
1425 tcg_gen_ext32u_tl(t0, t0);
1426 tcg_gen_shli_tl(t0, t0, uimm);
1427 tcg_gen_ext32s_tl(t0, t0);
1431 tcg_gen_ext32s_tl(t0, t0);
1432 tcg_gen_sari_tl(t0, t0, uimm);
1433 tcg_gen_ext32s_tl(t0, t0);
1437 switch ((ctx->opcode >> 21) & 0x1f) {
1439 tcg_gen_ext32u_tl(t0, t0);
1440 tcg_gen_shri_tl(t0, t0, uimm);
1441 tcg_gen_ext32s_tl(t0, t0);
1445 /* rotr is decoded as srl on non-R2 CPUs */
1446 if (env->insn_flags & ISA_MIPS32R2) {
1448 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1449 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1451 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1452 tcg_gen_movi_i32(r_tmp2, 0x20);
1453 tcg_gen_subi_i32(r_tmp2, r_tmp2, uimm);
1454 tcg_gen_shl_i32(r_tmp2, r_tmp1, r_tmp2);
1455 tcg_gen_shri_i32(r_tmp1, r_tmp1, uimm);
1456 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp2);
1457 tcg_gen_ext_i32_tl(t0, r_tmp1);
1458 tcg_temp_free(r_tmp1);
1459 tcg_temp_free(r_tmp2);
1463 tcg_gen_ext32u_tl(t0, t0);
1464 tcg_gen_shri_tl(t0, t0, uimm);
1465 tcg_gen_ext32s_tl(t0, t0);
1470 MIPS_INVAL("invalid srl flag");
1471 generate_exception(ctx, EXCP_RI);
1475 #if defined(TARGET_MIPS64)
1477 tcg_gen_shli_tl(t0, t0, uimm);
1481 tcg_gen_sari_tl(t0, t0, uimm);
1485 switch ((ctx->opcode >> 21) & 0x1f) {
1487 tcg_gen_shri_tl(t0, t0, uimm);
1491 /* drotr is decoded as dsrl on non-R2 CPUs */
1492 if (env->insn_flags & ISA_MIPS32R2) {
1494 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1496 tcg_gen_movi_tl(r_tmp1, 0x40);
1497 tcg_gen_subi_tl(r_tmp1, r_tmp1, uimm);
1498 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1499 tcg_gen_shri_tl(t0, t0, uimm);
1500 tcg_gen_or_tl(t0, t0, r_tmp1);
1501 tcg_temp_free(r_tmp1);
1505 tcg_gen_shri_tl(t0, t0, uimm);
1510 MIPS_INVAL("invalid dsrl flag");
1511 generate_exception(ctx, EXCP_RI);
1516 tcg_gen_shli_tl(t0, t0, uimm + 32);
1520 tcg_gen_sari_tl(t0, t0, uimm + 32);
1524 switch ((ctx->opcode >> 21) & 0x1f) {
1526 tcg_gen_shri_tl(t0, t0, uimm + 32);
1530 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1531 if (env->insn_flags & ISA_MIPS32R2) {
1532 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1533 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1535 tcg_gen_movi_tl(r_tmp1, 0x40);
1536 tcg_gen_movi_tl(r_tmp2, 32);
1537 tcg_gen_addi_tl(r_tmp2, r_tmp2, uimm);
1538 tcg_gen_sub_tl(r_tmp1, r_tmp1, r_tmp2);
1539 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1540 tcg_gen_shr_tl(t0, t0, r_tmp2);
1541 tcg_gen_or_tl(t0, t0, r_tmp1);
1542 tcg_temp_free(r_tmp1);
1543 tcg_temp_free(r_tmp2);
1546 tcg_gen_shri_tl(t0, t0, uimm + 32);
1551 MIPS_INVAL("invalid dsrl32 flag");
1552 generate_exception(ctx, EXCP_RI);
1559 generate_exception(ctx, EXCP_RI);
1562 gen_store_gpr(t0, rt);
1563 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1569 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1570 int rd, int rs, int rt)
1572 const char *opn = "arith";
1573 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1574 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1576 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1577 && opc != OPC_DADD && opc != OPC_DSUB) {
1578 /* If no destination, treat it as a NOP.
1579 For add & sub, we must generate the overflow exception when needed. */
1583 gen_load_gpr(t0, rs);
1584 /* Specialcase the conventional move operation. */
1585 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1586 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1587 gen_store_gpr(t0, rd);
1590 gen_load_gpr(t1, rt);
1594 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1595 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1596 int l1 = gen_new_label();
1598 save_cpu_state(ctx, 1);
1599 tcg_gen_ext32s_tl(r_tmp1, t0);
1600 tcg_gen_ext32s_tl(r_tmp2, t1);
1601 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1603 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1604 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1605 tcg_gen_xor_tl(r_tmp2, t0, t1);
1606 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1607 tcg_temp_free(r_tmp2);
1608 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1609 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1610 tcg_temp_free(r_tmp1);
1611 /* operands of same sign, result different sign */
1612 generate_exception(ctx, EXCP_OVERFLOW);
1615 tcg_gen_ext32s_tl(t0, t0);
1620 tcg_gen_ext32s_tl(t0, t0);
1621 tcg_gen_ext32s_tl(t1, t1);
1622 tcg_gen_add_tl(t0, t0, t1);
1623 tcg_gen_ext32s_tl(t0, t0);
1628 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1629 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1630 int l1 = gen_new_label();
1632 save_cpu_state(ctx, 1);
1633 tcg_gen_ext32s_tl(r_tmp1, t0);
1634 tcg_gen_ext32s_tl(r_tmp2, t1);
1635 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1637 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1638 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1639 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1640 tcg_temp_free(r_tmp2);
1641 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1642 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1643 tcg_temp_free(r_tmp1);
1644 /* operands of different sign, first operand and result different sign */
1645 generate_exception(ctx, EXCP_OVERFLOW);
1648 tcg_gen_ext32s_tl(t0, t0);
1653 tcg_gen_ext32s_tl(t0, t0);
1654 tcg_gen_ext32s_tl(t1, t1);
1655 tcg_gen_sub_tl(t0, t0, t1);
1656 tcg_gen_ext32s_tl(t0, t0);
1659 #if defined(TARGET_MIPS64)
1662 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1663 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1664 int l1 = gen_new_label();
1666 save_cpu_state(ctx, 1);
1667 tcg_gen_mov_tl(r_tmp1, t0);
1668 tcg_gen_add_tl(t0, t0, t1);
1670 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1671 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1672 tcg_gen_xor_tl(r_tmp2, t0, t1);
1673 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1674 tcg_temp_free(r_tmp2);
1675 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1676 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1677 tcg_temp_free(r_tmp1);
1678 /* operands of same sign, result different sign */
1679 generate_exception(ctx, EXCP_OVERFLOW);
1685 tcg_gen_add_tl(t0, t0, t1);
1690 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1691 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1692 int l1 = gen_new_label();
1694 save_cpu_state(ctx, 1);
1695 tcg_gen_mov_tl(r_tmp1, t0);
1696 tcg_gen_sub_tl(t0, t0, t1);
1698 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1699 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1700 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1701 tcg_temp_free(r_tmp2);
1702 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1703 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1704 tcg_temp_free(r_tmp1);
1705 /* operands of different sign, first operand and result different sign */
1706 generate_exception(ctx, EXCP_OVERFLOW);
1712 tcg_gen_sub_tl(t0, t0, t1);
1725 tcg_gen_and_tl(t0, t0, t1);
1729 tcg_gen_or_tl(t0, t0, t1);
1730 tcg_gen_not_tl(t0, t0);
1734 tcg_gen_or_tl(t0, t0, t1);
1738 tcg_gen_xor_tl(t0, t0, t1);
1742 tcg_gen_ext32s_tl(t0, t0);
1743 tcg_gen_ext32s_tl(t1, t1);
1744 tcg_gen_mul_tl(t0, t0, t1);
1745 tcg_gen_ext32s_tl(t0, t0);
1750 int l1 = gen_new_label();
1752 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1753 gen_store_gpr(t0, rd);
1760 int l1 = gen_new_label();
1762 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1763 gen_store_gpr(t0, rd);
1769 tcg_gen_ext32u_tl(t0, t0);
1770 tcg_gen_ext32u_tl(t1, t1);
1771 tcg_gen_andi_tl(t0, t0, 0x1f);
1772 tcg_gen_shl_tl(t0, t1, t0);
1773 tcg_gen_ext32s_tl(t0, t0);
1777 tcg_gen_ext32s_tl(t1, t1);
1778 tcg_gen_andi_tl(t0, t0, 0x1f);
1779 tcg_gen_sar_tl(t0, t1, t0);
1780 tcg_gen_ext32s_tl(t0, t0);
1784 switch ((ctx->opcode >> 6) & 0x1f) {
1786 tcg_gen_ext32u_tl(t1, t1);
1787 tcg_gen_andi_tl(t0, t0, 0x1f);
1788 tcg_gen_shr_tl(t0, t1, t0);
1789 tcg_gen_ext32s_tl(t0, t0);
1793 /* rotrv is decoded as srlv on non-R2 CPUs */
1794 if (env->insn_flags & ISA_MIPS32R2) {
1795 int l1 = gen_new_label();
1796 int l2 = gen_new_label();
1798 tcg_gen_andi_tl(t0, t0, 0x1f);
1799 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1801 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1802 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1803 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1805 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1806 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1807 tcg_gen_movi_i32(r_tmp3, 0x20);
1808 tcg_gen_sub_i32(r_tmp3, r_tmp3, r_tmp1);
1809 tcg_gen_shl_i32(r_tmp3, r_tmp2, r_tmp3);
1810 tcg_gen_shr_i32(r_tmp1, r_tmp2, r_tmp1);
1811 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp3);
1812 tcg_gen_ext_i32_tl(t0, r_tmp1);
1813 tcg_temp_free(r_tmp1);
1814 tcg_temp_free(r_tmp2);
1815 tcg_temp_free(r_tmp3);
1819 tcg_gen_mov_tl(t0, t1);
1823 tcg_gen_ext32u_tl(t1, t1);
1824 tcg_gen_andi_tl(t0, t0, 0x1f);
1825 tcg_gen_shr_tl(t0, t1, t0);
1826 tcg_gen_ext32s_tl(t0, t0);
1831 MIPS_INVAL("invalid srlv flag");
1832 generate_exception(ctx, EXCP_RI);
1836 #if defined(TARGET_MIPS64)
1838 tcg_gen_andi_tl(t0, t0, 0x3f);
1839 tcg_gen_shl_tl(t0, t1, t0);
1843 tcg_gen_andi_tl(t0, t0, 0x3f);
1844 tcg_gen_sar_tl(t0, t1, t0);
1848 switch ((ctx->opcode >> 6) & 0x1f) {
1850 tcg_gen_andi_tl(t0, t0, 0x3f);
1851 tcg_gen_shr_tl(t0, t1, t0);
1855 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1856 if (env->insn_flags & ISA_MIPS32R2) {
1857 int l1 = gen_new_label();
1858 int l2 = gen_new_label();
1860 tcg_gen_andi_tl(t0, t0, 0x3f);
1861 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1863 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1865 tcg_gen_movi_tl(r_tmp1, 0x40);
1866 tcg_gen_sub_tl(r_tmp1, r_tmp1, t0);
1867 tcg_gen_shl_tl(r_tmp1, t1, r_tmp1);
1868 tcg_gen_shr_tl(t0, t1, t0);
1869 tcg_gen_or_tl(t0, t0, r_tmp1);
1870 tcg_temp_free(r_tmp1);
1874 tcg_gen_mov_tl(t0, t1);
1878 tcg_gen_andi_tl(t0, t0, 0x3f);
1879 tcg_gen_shr_tl(t0, t1, t0);
1884 MIPS_INVAL("invalid dsrlv flag");
1885 generate_exception(ctx, EXCP_RI);
1892 generate_exception(ctx, EXCP_RI);
1895 gen_store_gpr(t0, rd);
1897 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1903 /* Arithmetic on HI/LO registers */
1904 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1906 const char *opn = "hilo";
1907 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1909 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1917 gen_store_gpr(t0, reg);
1922 gen_store_gpr(t0, reg);
1926 gen_load_gpr(t0, reg);
1927 gen_store_HI(t0, 0);
1931 gen_load_gpr(t0, reg);
1932 gen_store_LO(t0, 0);
1937 generate_exception(ctx, EXCP_RI);
1940 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1945 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1948 const char *opn = "mul/div";
1949 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1950 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1952 gen_load_gpr(t0, rs);
1953 gen_load_gpr(t1, rt);
1957 int l1 = gen_new_label();
1959 tcg_gen_ext32s_tl(t0, t0);
1960 tcg_gen_ext32s_tl(t1, t1);
1961 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1963 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1964 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1965 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1967 tcg_gen_ext_tl_i64(r_tmp1, t0);
1968 tcg_gen_ext_tl_i64(r_tmp2, t1);
1969 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1970 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1971 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1972 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1973 tcg_temp_free(r_tmp1);
1974 tcg_temp_free(r_tmp2);
1975 tcg_temp_free(r_tmp3);
1976 tcg_gen_ext32s_tl(t0, t0);
1977 tcg_gen_ext32s_tl(t1, t1);
1978 gen_store_LO(t0, 0);
1979 gen_store_HI(t1, 0);
1987 int l1 = gen_new_label();
1989 tcg_gen_ext32s_tl(t1, t1);
1990 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1992 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1993 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1994 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1996 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1997 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1998 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1999 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
2000 tcg_gen_ext_i32_tl(t0, r_tmp3);
2001 tcg_gen_ext_i32_tl(t1, r_tmp1);
2002 tcg_temp_free(r_tmp1);
2003 tcg_temp_free(r_tmp2);
2004 tcg_temp_free(r_tmp3);
2005 gen_store_LO(t0, 0);
2006 gen_store_HI(t1, 0);
2014 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2015 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2017 tcg_gen_ext32s_tl(t0, t0);
2018 tcg_gen_ext32s_tl(t1, t1);
2019 tcg_gen_ext_tl_i64(r_tmp1, t0);
2020 tcg_gen_ext_tl_i64(r_tmp2, t1);
2021 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2022 tcg_temp_free(r_tmp2);
2023 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2024 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2025 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2026 tcg_temp_free(r_tmp1);
2027 tcg_gen_ext32s_tl(t0, t0);
2028 tcg_gen_ext32s_tl(t1, t1);
2029 gen_store_LO(t0, 0);
2030 gen_store_HI(t1, 0);
2036 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2037 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2039 tcg_gen_ext32u_tl(t0, t0);
2040 tcg_gen_ext32u_tl(t1, t1);
2041 tcg_gen_extu_tl_i64(r_tmp1, t0);
2042 tcg_gen_extu_tl_i64(r_tmp2, t1);
2043 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2044 tcg_temp_free(r_tmp2);
2045 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2046 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2047 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2048 tcg_temp_free(r_tmp1);
2049 tcg_gen_ext32s_tl(t0, t0);
2050 tcg_gen_ext32s_tl(t1, t1);
2051 gen_store_LO(t0, 0);
2052 gen_store_HI(t1, 0);
2056 #if defined(TARGET_MIPS64)
2059 int l1 = gen_new_label();
2061 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2063 int l2 = gen_new_label();
2065 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2066 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2068 tcg_gen_movi_tl(t1, 0);
2069 gen_store_LO(t0, 0);
2070 gen_store_HI(t1, 0);
2075 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2076 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2078 tcg_gen_div_i64(r_tmp1, t0, t1);
2079 tcg_gen_rem_i64(r_tmp2, t0, t1);
2080 gen_store_LO(r_tmp1, 0);
2081 gen_store_HI(r_tmp2, 0);
2082 tcg_temp_free(r_tmp1);
2083 tcg_temp_free(r_tmp2);
2092 int l1 = gen_new_label();
2094 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2096 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2097 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2099 tcg_gen_divu_i64(r_tmp1, t0, t1);
2100 tcg_gen_remu_i64(r_tmp2, t0, t1);
2101 tcg_temp_free(r_tmp1);
2102 tcg_temp_free(r_tmp2);
2103 gen_store_LO(r_tmp1, 0);
2104 gen_store_HI(r_tmp2, 0);
2111 tcg_gen_helper_0_2(do_dmult, t0, t1);
2115 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2121 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2122 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2123 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2125 tcg_gen_ext32s_tl(t0, t0);
2126 tcg_gen_ext32s_tl(t1, t1);
2127 tcg_gen_ext_tl_i64(r_tmp1, t0);
2128 tcg_gen_ext_tl_i64(r_tmp2, t1);
2129 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2132 tcg_gen_extu_tl_i64(r_tmp2, t0);
2133 tcg_gen_extu_tl_i64(r_tmp3, t1);
2134 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2135 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2136 tcg_temp_free(r_tmp3);
2137 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2138 tcg_temp_free(r_tmp2);
2139 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2140 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2141 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2142 tcg_temp_free(r_tmp1);
2143 tcg_gen_ext32s_tl(t0, t0);
2144 tcg_gen_ext32s_tl(t1, t1);
2145 gen_store_LO(t0, 0);
2146 gen_store_HI(t1, 0);
2152 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2153 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2154 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2156 tcg_gen_ext32u_tl(t0, t0);
2157 tcg_gen_ext32u_tl(t1, t1);
2158 tcg_gen_extu_tl_i64(r_tmp1, t0);
2159 tcg_gen_extu_tl_i64(r_tmp2, t1);
2160 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2163 tcg_gen_extu_tl_i64(r_tmp2, t0);
2164 tcg_gen_extu_tl_i64(r_tmp3, t1);
2165 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2166 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2167 tcg_temp_free(r_tmp3);
2168 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2169 tcg_temp_free(r_tmp2);
2170 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2171 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2172 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2173 tcg_temp_free(r_tmp1);
2174 tcg_gen_ext32s_tl(t0, t0);
2175 tcg_gen_ext32s_tl(t1, t1);
2176 gen_store_LO(t0, 0);
2177 gen_store_HI(t1, 0);
2183 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2184 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2185 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2187 tcg_gen_ext32s_tl(t0, t0);
2188 tcg_gen_ext32s_tl(t1, t1);
2189 tcg_gen_ext_tl_i64(r_tmp1, t0);
2190 tcg_gen_ext_tl_i64(r_tmp2, t1);
2191 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2194 tcg_gen_extu_tl_i64(r_tmp2, t0);
2195 tcg_gen_extu_tl_i64(r_tmp3, t1);
2196 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2197 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2198 tcg_temp_free(r_tmp3);
2199 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2200 tcg_temp_free(r_tmp2);
2201 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2202 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2203 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2204 tcg_temp_free(r_tmp1);
2205 tcg_gen_ext32s_tl(t0, t0);
2206 tcg_gen_ext32s_tl(t1, t1);
2207 gen_store_LO(t0, 0);
2208 gen_store_HI(t1, 0);
2214 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2215 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2216 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2218 tcg_gen_ext32u_tl(t0, t0);
2219 tcg_gen_ext32u_tl(t1, t1);
2220 tcg_gen_extu_tl_i64(r_tmp1, t0);
2221 tcg_gen_extu_tl_i64(r_tmp2, t1);
2222 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2225 tcg_gen_extu_tl_i64(r_tmp2, t0);
2226 tcg_gen_extu_tl_i64(r_tmp3, t1);
2227 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2228 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2229 tcg_temp_free(r_tmp3);
2230 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2231 tcg_temp_free(r_tmp2);
2232 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2233 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2234 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2235 tcg_temp_free(r_tmp1);
2236 tcg_gen_ext32s_tl(t0, t0);
2237 tcg_gen_ext32s_tl(t1, t1);
2238 gen_store_LO(t0, 0);
2239 gen_store_HI(t1, 0);
2245 generate_exception(ctx, EXCP_RI);
2248 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2254 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2255 int rd, int rs, int rt)
2257 const char *opn = "mul vr54xx";
2258 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2259 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2261 gen_load_gpr(t0, rs);
2262 gen_load_gpr(t1, rt);
2265 case OPC_VR54XX_MULS:
2266 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2269 case OPC_VR54XX_MULSU:
2270 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2273 case OPC_VR54XX_MACC:
2274 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2277 case OPC_VR54XX_MACCU:
2278 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2281 case OPC_VR54XX_MSAC:
2282 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2285 case OPC_VR54XX_MSACU:
2286 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2289 case OPC_VR54XX_MULHI:
2290 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2293 case OPC_VR54XX_MULHIU:
2294 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2297 case OPC_VR54XX_MULSHI:
2298 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2301 case OPC_VR54XX_MULSHIU:
2302 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2305 case OPC_VR54XX_MACCHI:
2306 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2309 case OPC_VR54XX_MACCHIU:
2310 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2313 case OPC_VR54XX_MSACHI:
2314 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2317 case OPC_VR54XX_MSACHIU:
2318 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2322 MIPS_INVAL("mul vr54xx");
2323 generate_exception(ctx, EXCP_RI);
2326 gen_store_gpr(t0, rd);
2327 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2334 static void gen_cl (DisasContext *ctx, uint32_t opc,
2337 const char *opn = "CLx";
2338 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2345 gen_load_gpr(t0, rs);
2348 tcg_gen_helper_1_1(do_clo, t0, t0);
2352 tcg_gen_helper_1_1(do_clz, t0, t0);
2355 #if defined(TARGET_MIPS64)
2357 tcg_gen_helper_1_1(do_dclo, t0, t0);
2361 tcg_gen_helper_1_1(do_dclz, t0, t0);
2367 generate_exception(ctx, EXCP_RI);
2370 gen_store_gpr(t0, rd);
2371 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2378 static void gen_trap (DisasContext *ctx, uint32_t opc,
2379 int rs, int rt, int16_t imm)
2382 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2383 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2386 /* Load needed operands */
2394 /* Compare two registers */
2396 gen_load_gpr(t0, rs);
2397 gen_load_gpr(t1, rt);
2407 /* Compare register to immediate */
2408 if (rs != 0 || imm != 0) {
2409 gen_load_gpr(t0, rs);
2410 tcg_gen_movi_tl(t1, (int32_t)imm);
2417 case OPC_TEQ: /* rs == rs */
2418 case OPC_TEQI: /* r0 == 0 */
2419 case OPC_TGE: /* rs >= rs */
2420 case OPC_TGEI: /* r0 >= 0 */
2421 case OPC_TGEU: /* rs >= rs unsigned */
2422 case OPC_TGEIU: /* r0 >= 0 unsigned */
2424 tcg_gen_movi_tl(t0, 1);
2426 case OPC_TLT: /* rs < rs */
2427 case OPC_TLTI: /* r0 < 0 */
2428 case OPC_TLTU: /* rs < rs unsigned */
2429 case OPC_TLTIU: /* r0 < 0 unsigned */
2430 case OPC_TNE: /* rs != rs */
2431 case OPC_TNEI: /* r0 != 0 */
2432 /* Never trap: treat as NOP. */
2436 generate_exception(ctx, EXCP_RI);
2467 generate_exception(ctx, EXCP_RI);
2471 save_cpu_state(ctx, 1);
2473 int l1 = gen_new_label();
2475 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2476 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2479 ctx->bstate = BS_STOP;
2485 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2487 TranslationBlock *tb;
2489 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2492 tcg_gen_exit_tb((long)tb + n);
2499 /* Branches (before delay slot) */
2500 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2501 int rs, int rt, int32_t offset)
2503 target_ulong btgt = -1;
2505 int bcond_compute = 0;
2506 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2507 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2509 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2510 #ifdef MIPS_DEBUG_DISAS
2511 if (loglevel & CPU_LOG_TB_IN_ASM) {
2513 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2517 generate_exception(ctx, EXCP_RI);
2521 /* Load needed operands */
2527 /* Compare two registers */
2529 gen_load_gpr(t0, rs);
2530 gen_load_gpr(t1, rt);
2533 btgt = ctx->pc + 4 + offset;
2547 /* Compare to zero */
2549 gen_load_gpr(t0, rs);
2552 btgt = ctx->pc + 4 + offset;
2556 /* Jump to immediate */
2557 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2561 /* Jump to register */
2562 if (offset != 0 && offset != 16) {
2563 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2564 others are reserved. */
2565 MIPS_INVAL("jump hint");
2566 generate_exception(ctx, EXCP_RI);
2569 gen_load_gpr(btarget, rs);
2572 MIPS_INVAL("branch/jump");
2573 generate_exception(ctx, EXCP_RI);
2576 if (bcond_compute == 0) {
2577 /* No condition to be computed */
2579 case OPC_BEQ: /* rx == rx */
2580 case OPC_BEQL: /* rx == rx likely */
2581 case OPC_BGEZ: /* 0 >= 0 */
2582 case OPC_BGEZL: /* 0 >= 0 likely */
2583 case OPC_BLEZ: /* 0 <= 0 */
2584 case OPC_BLEZL: /* 0 <= 0 likely */
2586 ctx->hflags |= MIPS_HFLAG_B;
2587 MIPS_DEBUG("balways");
2589 case OPC_BGEZAL: /* 0 >= 0 */
2590 case OPC_BGEZALL: /* 0 >= 0 likely */
2591 /* Always take and link */
2593 ctx->hflags |= MIPS_HFLAG_B;
2594 MIPS_DEBUG("balways and link");
2596 case OPC_BNE: /* rx != rx */
2597 case OPC_BGTZ: /* 0 > 0 */
2598 case OPC_BLTZ: /* 0 < 0 */
2600 MIPS_DEBUG("bnever (NOP)");
2602 case OPC_BLTZAL: /* 0 < 0 */
2603 tcg_gen_movi_tl(t0, ctx->pc + 8);
2604 gen_store_gpr(t0, 31);
2605 MIPS_DEBUG("bnever and link");
2607 case OPC_BLTZALL: /* 0 < 0 likely */
2608 tcg_gen_movi_tl(t0, ctx->pc + 8);
2609 gen_store_gpr(t0, 31);
2610 /* Skip the instruction in the delay slot */
2611 MIPS_DEBUG("bnever, link and skip");
2614 case OPC_BNEL: /* rx != rx likely */
2615 case OPC_BGTZL: /* 0 > 0 likely */
2616 case OPC_BLTZL: /* 0 < 0 likely */
2617 /* Skip the instruction in the delay slot */
2618 MIPS_DEBUG("bnever and skip");
2622 ctx->hflags |= MIPS_HFLAG_B;
2623 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2627 ctx->hflags |= MIPS_HFLAG_B;
2628 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2631 ctx->hflags |= MIPS_HFLAG_BR;
2632 MIPS_DEBUG("jr %s", regnames[rs]);
2636 ctx->hflags |= MIPS_HFLAG_BR;
2637 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2640 MIPS_INVAL("branch/jump");
2641 generate_exception(ctx, EXCP_RI);
2648 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2649 regnames[rs], regnames[rt], btgt);
2653 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2654 regnames[rs], regnames[rt], btgt);
2658 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2659 regnames[rs], regnames[rt], btgt);
2663 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2664 regnames[rs], regnames[rt], btgt);
2668 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2672 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2676 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2682 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2686 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2690 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2694 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2698 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2702 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2706 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2711 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2713 ctx->hflags |= MIPS_HFLAG_BC;
2714 tcg_gen_trunc_tl_i32(bcond, t0);
2719 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2721 ctx->hflags |= MIPS_HFLAG_BL;
2722 tcg_gen_trunc_tl_i32(bcond, t0);
2725 MIPS_INVAL("conditional branch/jump");
2726 generate_exception(ctx, EXCP_RI);
2730 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2731 blink, ctx->hflags, btgt);
2733 ctx->btarget = btgt;
2735 tcg_gen_movi_tl(t0, ctx->pc + 8);
2736 gen_store_gpr(t0, blink);
2744 /* special3 bitfield operations */
2745 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2746 int rs, int lsb, int msb)
2748 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2749 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2751 gen_load_gpr(t1, rs);
2756 tcg_gen_helper_1_1ii(do_ext, t0, t1, lsb, msb + 1);
2758 #if defined(TARGET_MIPS64)
2762 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1 + 32);
2767 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb + 32, msb + 1);
2772 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1);
2778 gen_load_gpr(t0, rt);
2779 tcg_gen_helper_1_2ii(do_ins, t0, t0, t1, lsb, msb - lsb + 1);
2781 #if defined(TARGET_MIPS64)
2785 gen_load_gpr(t0, rt);
2786 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1 + 32);
2791 gen_load_gpr(t0, rt);
2792 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb + 32, msb - lsb + 1);
2797 gen_load_gpr(t0, rt);
2798 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1);
2803 MIPS_INVAL("bitops");
2804 generate_exception(ctx, EXCP_RI);
2809 gen_store_gpr(t0, rt);
2814 #ifndef CONFIG_USER_ONLY
2815 /* CP0 (MMU and control) */
2816 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2818 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2820 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2821 tcg_gen_ext_i32_tl(t, r_tmp);
2822 tcg_temp_free(r_tmp);
2825 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2827 tcg_gen_ld_tl(t, cpu_env, off);
2828 tcg_gen_ext32s_tl(t, t);
2831 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2833 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2835 tcg_gen_trunc_tl_i32(r_tmp, t);
2836 tcg_gen_st_i32(r_tmp, cpu_env, off);
2837 tcg_temp_free(r_tmp);
2840 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2842 tcg_gen_ext32s_tl(t, t);
2843 tcg_gen_st_tl(t, cpu_env, off);
2846 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2848 const char *rn = "invalid";
2851 check_insn(env, ctx, ISA_MIPS32);
2857 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2861 check_insn(env, ctx, ASE_MT);
2862 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2866 check_insn(env, ctx, ASE_MT);
2867 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2871 check_insn(env, ctx, ASE_MT);
2872 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2882 tcg_gen_helper_1_0(do_mfc0_random, t0);
2886 check_insn(env, ctx, ASE_MT);
2887 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2891 check_insn(env, ctx, ASE_MT);
2892 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2896 check_insn(env, ctx, ASE_MT);
2897 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2901 check_insn(env, ctx, ASE_MT);
2902 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2906 check_insn(env, ctx, ASE_MT);
2907 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2911 check_insn(env, ctx, ASE_MT);
2912 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2913 rn = "VPEScheFBack";
2916 check_insn(env, ctx, ASE_MT);
2917 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2927 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2928 tcg_gen_ext32s_tl(t0, t0);
2932 check_insn(env, ctx, ASE_MT);
2933 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2937 check_insn(env, ctx, ASE_MT);
2938 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2942 check_insn(env, ctx, ASE_MT);
2943 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2947 check_insn(env, ctx, ASE_MT);
2948 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2952 check_insn(env, ctx, ASE_MT);
2953 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2957 check_insn(env, ctx, ASE_MT);
2958 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2962 check_insn(env, ctx, ASE_MT);
2963 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2973 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2974 tcg_gen_ext32s_tl(t0, t0);
2984 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2985 tcg_gen_ext32s_tl(t0, t0);
2989 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2990 rn = "ContextConfig";
2999 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
3003 check_insn(env, ctx, ISA_MIPS32R2);
3004 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
3014 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
3018 check_insn(env, ctx, ISA_MIPS32R2);
3019 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
3023 check_insn(env, ctx, ISA_MIPS32R2);
3024 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
3028 check_insn(env, ctx, ISA_MIPS32R2);
3029 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
3033 check_insn(env, ctx, ISA_MIPS32R2);
3034 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
3038 check_insn(env, ctx, ISA_MIPS32R2);
3039 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
3049 check_insn(env, ctx, ISA_MIPS32R2);
3050 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
3060 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
3061 tcg_gen_ext32s_tl(t0, t0);
3071 /* Mark as an IO operation because we read the time. */
3074 tcg_gen_helper_1_0(do_mfc0_count, t0);
3077 ctx->bstate = BS_STOP;
3081 /* 6,7 are implementation dependent */
3089 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3090 tcg_gen_ext32s_tl(t0, t0);
3100 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3103 /* 6,7 are implementation dependent */
3111 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3115 check_insn(env, ctx, ISA_MIPS32R2);
3116 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3120 check_insn(env, ctx, ISA_MIPS32R2);
3121 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3125 check_insn(env, ctx, ISA_MIPS32R2);
3126 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3136 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3146 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3147 tcg_gen_ext32s_tl(t0, t0);
3157 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3161 check_insn(env, ctx, ISA_MIPS32R2);
3162 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3172 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3176 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3180 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3184 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3187 /* 4,5 are reserved */
3188 /* 6,7 are implementation dependent */
3190 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3194 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3204 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3214 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3224 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3234 #if defined(TARGET_MIPS64)
3235 check_insn(env, ctx, ISA_MIPS3);
3236 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3237 tcg_gen_ext32s_tl(t0, t0);
3246 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3249 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3258 rn = "'Diagnostic"; /* implementation dependent */
3263 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3267 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3268 rn = "TraceControl";
3271 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3272 rn = "TraceControl2";
3275 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3276 rn = "UserTraceData";
3279 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3290 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3291 tcg_gen_ext32s_tl(t0, t0);
3301 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3302 rn = "Performance0";
3305 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3306 rn = "Performance1";
3309 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3310 rn = "Performance2";
3313 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3314 rn = "Performance3";
3317 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3318 rn = "Performance4";
3321 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3322 rn = "Performance5";
3325 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3326 rn = "Performance6";
3329 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3330 rn = "Performance7";
3355 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3362 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3375 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3382 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3392 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3393 tcg_gen_ext32s_tl(t0, t0);
3404 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3414 #if defined MIPS_DEBUG_DISAS
3415 if (loglevel & CPU_LOG_TB_IN_ASM) {
3416 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3423 #if defined MIPS_DEBUG_DISAS
3424 if (loglevel & CPU_LOG_TB_IN_ASM) {
3425 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3429 generate_exception(ctx, EXCP_RI);
3432 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3434 const char *rn = "invalid";
3437 check_insn(env, ctx, ISA_MIPS32);
3446 tcg_gen_helper_0_1(do_mtc0_index, t0);
3450 check_insn(env, ctx, ASE_MT);
3451 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3455 check_insn(env, ctx, ASE_MT);
3460 check_insn(env, ctx, ASE_MT);
3475 check_insn(env, ctx, ASE_MT);
3476 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3480 check_insn(env, ctx, ASE_MT);
3481 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3485 check_insn(env, ctx, ASE_MT);
3486 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3490 check_insn(env, ctx, ASE_MT);
3491 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3495 check_insn(env, ctx, ASE_MT);
3496 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3500 check_insn(env, ctx, ASE_MT);
3501 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3502 rn = "VPEScheFBack";
3505 check_insn(env, ctx, ASE_MT);
3506 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3516 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3520 check_insn(env, ctx, ASE_MT);
3521 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3525 check_insn(env, ctx, ASE_MT);
3526 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3530 check_insn(env, ctx, ASE_MT);
3531 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3535 check_insn(env, ctx, ASE_MT);
3536 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3540 check_insn(env, ctx, ASE_MT);
3541 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3545 check_insn(env, ctx, ASE_MT);
3546 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3550 check_insn(env, ctx, ASE_MT);
3551 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3561 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3571 tcg_gen_helper_0_1(do_mtc0_context, t0);
3575 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3576 rn = "ContextConfig";
3585 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3589 check_insn(env, ctx, ISA_MIPS32R2);
3590 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3600 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3604 check_insn(env, ctx, ISA_MIPS32R2);
3605 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3609 check_insn(env, ctx, ISA_MIPS32R2);
3610 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3614 check_insn(env, ctx, ISA_MIPS32R2);
3615 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3619 check_insn(env, ctx, ISA_MIPS32R2);
3620 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3624 check_insn(env, ctx, ISA_MIPS32R2);
3625 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3635 check_insn(env, ctx, ISA_MIPS32R2);
3636 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3650 tcg_gen_helper_0_1(do_mtc0_count, t0);
3653 /* 6,7 are implementation dependent */
3657 /* Stop translation as we may have switched the execution mode */
3658 ctx->bstate = BS_STOP;
3663 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3673 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3676 /* 6,7 are implementation dependent */
3680 /* Stop translation as we may have switched the execution mode */
3681 ctx->bstate = BS_STOP;
3686 tcg_gen_helper_0_1(do_mtc0_status, t0);
3687 /* BS_STOP isn't good enough here, hflags may have changed. */
3688 gen_save_pc(ctx->pc + 4);
3689 ctx->bstate = BS_EXCP;
3693 check_insn(env, ctx, ISA_MIPS32R2);
3694 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3695 /* Stop translation as we may have switched the execution mode */
3696 ctx->bstate = BS_STOP;
3700 check_insn(env, ctx, ISA_MIPS32R2);
3701 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3702 /* Stop translation as we may have switched the execution mode */
3703 ctx->bstate = BS_STOP;
3707 check_insn(env, ctx, ISA_MIPS32R2);
3708 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3709 /* Stop translation as we may have switched the execution mode */
3710 ctx->bstate = BS_STOP;
3720 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3726 /* Stop translation as we may have switched the execution mode */
3727 ctx->bstate = BS_STOP;
3732 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3746 check_insn(env, ctx, ISA_MIPS32R2);
3747 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3757 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3759 /* Stop translation as we may have switched the execution mode */
3760 ctx->bstate = BS_STOP;
3763 /* ignored, read only */
3767 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3769 /* Stop translation as we may have switched the execution mode */
3770 ctx->bstate = BS_STOP;
3773 /* ignored, read only */
3776 /* 4,5 are reserved */
3777 /* 6,7 are implementation dependent */
3787 rn = "Invalid config selector";
3804 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3814 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3824 #if defined(TARGET_MIPS64)
3825 check_insn(env, ctx, ISA_MIPS3);
3826 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3835 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3838 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3847 rn = "Diagnostic"; /* implementation dependent */
3852 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3853 /* BS_STOP isn't good enough here, hflags may have changed. */
3854 gen_save_pc(ctx->pc + 4);
3855 ctx->bstate = BS_EXCP;
3859 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3860 rn = "TraceControl";
3861 /* Stop translation as we may have switched the execution mode */
3862 ctx->bstate = BS_STOP;
3865 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3866 rn = "TraceControl2";
3867 /* Stop translation as we may have switched the execution mode */
3868 ctx->bstate = BS_STOP;
3871 /* Stop translation as we may have switched the execution mode */
3872 ctx->bstate = BS_STOP;
3873 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3874 rn = "UserTraceData";
3875 /* Stop translation as we may have switched the execution mode */
3876 ctx->bstate = BS_STOP;
3879 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3880 /* Stop translation as we may have switched the execution mode */
3881 ctx->bstate = BS_STOP;
3892 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3902 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3903 rn = "Performance0";
3906 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3907 rn = "Performance1";
3910 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3911 rn = "Performance2";
3914 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3915 rn = "Performance3";
3918 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3919 rn = "Performance4";
3922 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3923 rn = "Performance5";
3926 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3927 rn = "Performance6";
3930 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3931 rn = "Performance7";
3957 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3964 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3977 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3984 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
3995 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
4006 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
4012 /* Stop translation as we may have switched the execution mode */
4013 ctx->bstate = BS_STOP;
4018 #if defined MIPS_DEBUG_DISAS
4019 if (loglevel & CPU_LOG_TB_IN_ASM) {
4020 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4024 /* For simplicity assume that all writes can cause interrupts. */
4027 ctx->bstate = BS_STOP;
4032 #if defined MIPS_DEBUG_DISAS
4033 if (loglevel & CPU_LOG_TB_IN_ASM) {
4034 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4038 generate_exception(ctx, EXCP_RI);
4041 #if defined(TARGET_MIPS64)
4042 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4044 const char *rn = "invalid";
4047 check_insn(env, ctx, ISA_MIPS64);
4053 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
4057 check_insn(env, ctx, ASE_MT);
4058 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
4062 check_insn(env, ctx, ASE_MT);
4063 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4067 check_insn(env, ctx, ASE_MT);
4068 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4078 tcg_gen_helper_1_0(do_mfc0_random, t0);
4082 check_insn(env, ctx, ASE_MT);
4083 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4087 check_insn(env, ctx, ASE_MT);
4088 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4092 check_insn(env, ctx, ASE_MT);
4093 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4097 check_insn(env, ctx, ASE_MT);
4098 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4102 check_insn(env, ctx, ASE_MT);
4103 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4107 check_insn(env, ctx, ASE_MT);
4108 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4109 rn = "VPEScheFBack";
4112 check_insn(env, ctx, ASE_MT);
4113 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4123 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4127 check_insn(env, ctx, ASE_MT);
4128 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4132 check_insn(env, ctx, ASE_MT);
4133 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4137 check_insn(env, ctx, ASE_MT);
4138 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4142 check_insn(env, ctx, ASE_MT);
4143 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4147 check_insn(env, ctx, ASE_MT);
4148 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4152 check_insn(env, ctx, ASE_MT);
4153 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4157 check_insn(env, ctx, ASE_MT);
4158 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4168 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4178 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4182 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4183 rn = "ContextConfig";
4192 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4196 check_insn(env, ctx, ISA_MIPS32R2);
4197 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4207 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4211 check_insn(env, ctx, ISA_MIPS32R2);
4212 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4216 check_insn(env, ctx, ISA_MIPS32R2);
4217 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4221 check_insn(env, ctx, ISA_MIPS32R2);
4222 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4226 check_insn(env, ctx, ISA_MIPS32R2);
4227 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4231 check_insn(env, ctx, ISA_MIPS32R2);
4232 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4242 check_insn(env, ctx, ISA_MIPS32R2);
4243 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4253 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4263 /* Mark as an IO operation because we read the time. */
4266 tcg_gen_helper_1_0(do_mfc0_count, t0);
4269 ctx->bstate = BS_STOP;
4273 /* 6,7 are implementation dependent */
4281 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4291 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4294 /* 6,7 are implementation dependent */
4302 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4306 check_insn(env, ctx, ISA_MIPS32R2);
4307 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4311 check_insn(env, ctx, ISA_MIPS32R2);
4312 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4316 check_insn(env, ctx, ISA_MIPS32R2);
4317 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4327 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4337 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4347 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4351 check_insn(env, ctx, ISA_MIPS32R2);
4352 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4362 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4366 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4370 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4374 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4377 /* 6,7 are implementation dependent */
4379 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4383 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4393 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4403 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4413 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4423 check_insn(env, ctx, ISA_MIPS3);
4424 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4432 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4435 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4444 rn = "'Diagnostic"; /* implementation dependent */
4449 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4453 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4454 rn = "TraceControl";
4457 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4458 rn = "TraceControl2";
4461 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4462 rn = "UserTraceData";
4465 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4476 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4486 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4487 rn = "Performance0";
4490 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4491 rn = "Performance1";
4494 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4495 rn = "Performance2";
4498 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4499 rn = "Performance3";
4502 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4503 rn = "Performance4";
4506 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4507 rn = "Performance5";
4510 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4511 rn = "Performance6";
4514 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4515 rn = "Performance7";
4540 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4547 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4560 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4567 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4577 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4588 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4598 #if defined MIPS_DEBUG_DISAS
4599 if (loglevel & CPU_LOG_TB_IN_ASM) {
4600 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4607 #if defined MIPS_DEBUG_DISAS
4608 if (loglevel & CPU_LOG_TB_IN_ASM) {
4609 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4613 generate_exception(ctx, EXCP_RI);
4616 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4618 const char *rn = "invalid";
4621 check_insn(env, ctx, ISA_MIPS64);
4630 tcg_gen_helper_0_1(do_mtc0_index, t0);
4634 check_insn(env, ctx, ASE_MT);
4635 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4639 check_insn(env, ctx, ASE_MT);
4644 check_insn(env, ctx, ASE_MT);
4659 check_insn(env, ctx, ASE_MT);
4660 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4664 check_insn(env, ctx, ASE_MT);
4665 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4669 check_insn(env, ctx, ASE_MT);
4670 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4674 check_insn(env, ctx, ASE_MT);
4675 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4679 check_insn(env, ctx, ASE_MT);
4680 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4684 check_insn(env, ctx, ASE_MT);
4685 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4686 rn = "VPEScheFBack";
4689 check_insn(env, ctx, ASE_MT);
4690 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4700 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4704 check_insn(env, ctx, ASE_MT);
4705 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4709 check_insn(env, ctx, ASE_MT);
4710 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4714 check_insn(env, ctx, ASE_MT);
4715 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4719 check_insn(env, ctx, ASE_MT);
4720 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4724 check_insn(env, ctx, ASE_MT);
4725 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4729 check_insn(env, ctx, ASE_MT);
4730 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4734 check_insn(env, ctx, ASE_MT);
4735 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4745 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4755 tcg_gen_helper_0_1(do_mtc0_context, t0);
4759 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4760 rn = "ContextConfig";
4769 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4773 check_insn(env, ctx, ISA_MIPS32R2);
4774 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4784 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4788 check_insn(env, ctx, ISA_MIPS32R2);
4789 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4793 check_insn(env, ctx, ISA_MIPS32R2);
4794 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4798 check_insn(env, ctx, ISA_MIPS32R2);
4799 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4803 check_insn(env, ctx, ISA_MIPS32R2);
4804 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4808 check_insn(env, ctx, ISA_MIPS32R2);
4809 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4819 check_insn(env, ctx, ISA_MIPS32R2);
4820 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4834 tcg_gen_helper_0_1(do_mtc0_count, t0);
4837 /* 6,7 are implementation dependent */
4841 /* Stop translation as we may have switched the execution mode */
4842 ctx->bstate = BS_STOP;
4847 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4857 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4860 /* 6,7 are implementation dependent */
4864 /* Stop translation as we may have switched the execution mode */
4865 ctx->bstate = BS_STOP;
4870 tcg_gen_helper_0_1(do_mtc0_status, t0);
4871 /* BS_STOP isn't good enough here, hflags may have changed. */
4872 gen_save_pc(ctx->pc + 4);
4873 ctx->bstate = BS_EXCP;
4877 check_insn(env, ctx, ISA_MIPS32R2);
4878 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4879 /* Stop translation as we may have switched the execution mode */
4880 ctx->bstate = BS_STOP;
4884 check_insn(env, ctx, ISA_MIPS32R2);
4885 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4886 /* Stop translation as we may have switched the execution mode */
4887 ctx->bstate = BS_STOP;
4891 check_insn(env, ctx, ISA_MIPS32R2);
4892 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4893 /* Stop translation as we may have switched the execution mode */
4894 ctx->bstate = BS_STOP;
4904 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4910 /* Stop translation as we may have switched the execution mode */
4911 ctx->bstate = BS_STOP;
4916 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4930 check_insn(env, ctx, ISA_MIPS32R2);
4931 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4941 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4943 /* Stop translation as we may have switched the execution mode */
4944 ctx->bstate = BS_STOP;
4951 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4953 /* Stop translation as we may have switched the execution mode */
4954 ctx->bstate = BS_STOP;
4960 /* 6,7 are implementation dependent */
4962 rn = "Invalid config selector";
4979 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4989 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
4999 check_insn(env, ctx, ISA_MIPS3);
5000 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
5008 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5011 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
5020 rn = "Diagnostic"; /* implementation dependent */
5025 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
5026 /* BS_STOP isn't good enough here, hflags may have changed. */
5027 gen_save_pc(ctx->pc + 4);
5028 ctx->bstate = BS_EXCP;
5032 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
5033 /* Stop translation as we may have switched the execution mode */
5034 ctx->bstate = BS_STOP;
5035 rn = "TraceControl";
5038 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
5039 /* Stop translation as we may have switched the execution mode */
5040 ctx->bstate = BS_STOP;
5041 rn = "TraceControl2";
5044 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5045 /* Stop translation as we may have switched the execution mode */
5046 ctx->bstate = BS_STOP;
5047 rn = "UserTraceData";
5050 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5051 /* Stop translation as we may have switched the execution mode */
5052 ctx->bstate = BS_STOP;
5063 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5073 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5074 rn = "Performance0";
5077 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5078 rn = "Performance1";
5081 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5082 rn = "Performance2";
5085 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5086 rn = "Performance3";
5089 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5090 rn = "Performance4";
5093 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5094 rn = "Performance5";
5097 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5098 rn = "Performance6";
5101 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5102 rn = "Performance7";
5128 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5135 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5148 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5155 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5166 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5177 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5183 /* Stop translation as we may have switched the execution mode */
5184 ctx->bstate = BS_STOP;
5189 #if defined MIPS_DEBUG_DISAS
5190 if (loglevel & CPU_LOG_TB_IN_ASM) {
5191 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5195 /* For simplicity assume that all writes can cause interrupts. */
5198 ctx->bstate = BS_STOP;
5203 #if defined MIPS_DEBUG_DISAS
5204 if (loglevel & CPU_LOG_TB_IN_ASM) {
5205 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5209 generate_exception(ctx, EXCP_RI);
5211 #endif /* TARGET_MIPS64 */
5213 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5214 int u, int sel, int h)
5216 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5217 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5219 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5220 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5221 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5222 tcg_gen_movi_tl(t0, -1);
5223 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5224 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5225 tcg_gen_movi_tl(t0, -1);
5231 tcg_gen_helper_1_1(do_mftc0_tcstatus, t0, t0);
5234 tcg_gen_helper_1_1(do_mftc0_tcbind, t0, t0);
5237 tcg_gen_helper_1_1(do_mftc0_tcrestart, t0, t0);
5240 tcg_gen_helper_1_1(do_mftc0_tchalt, t0, t0);
5243 tcg_gen_helper_1_1(do_mftc0_tccontext, t0, t0);
5246 tcg_gen_helper_1_1(do_mftc0_tcschedule, t0, t0);
5249 tcg_gen_helper_1_1(do_mftc0_tcschefback, t0, t0);
5252 gen_mfc0(env, ctx, t0, rt, sel);
5259 tcg_gen_helper_1_1(do_mftc0_entryhi, t0, t0);
5262 gen_mfc0(env, ctx, t0, rt, sel);
5268 tcg_gen_helper_1_1(do_mftc0_status, t0, t0);
5271 gen_mfc0(env, ctx, t0, rt, sel);
5277 tcg_gen_helper_1_1(do_mftc0_debug, t0, t0);
5280 gen_mfc0(env, ctx, t0, rt, sel);
5285 gen_mfc0(env, ctx, t0, rt, sel);
5287 } else switch (sel) {
5288 /* GPR registers. */
5290 tcg_gen_helper_1_1i(do_mftgpr, t0, t0, rt);
5292 /* Auxiliary CPU registers */
5296 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 0);
5299 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 0);
5302 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 0);
5305 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 1);
5308 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 1);
5311 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 1);
5314 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 2);
5317 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 2);
5320 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 2);
5323 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 3);
5326 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 3);
5329 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 3);
5332 tcg_gen_helper_1_1(do_mftdsp, t0, t0);
5338 /* Floating point (COP1). */
5340 /* XXX: For now we support only a single FPU context. */
5342 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5344 gen_load_fpr32(fp0, rt);
5345 tcg_gen_ext_i32_tl(t0, fp0);
5348 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5350 gen_load_fpr32h(fp0, rt);
5351 tcg_gen_ext_i32_tl(t0, fp0);
5356 /* XXX: For now we support only a single FPU context. */
5357 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5359 /* COP2: Not implemented. */
5366 #if defined MIPS_DEBUG_DISAS
5367 if (loglevel & CPU_LOG_TB_IN_ASM) {
5368 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5372 gen_store_gpr(t0, rd);
5378 #if defined MIPS_DEBUG_DISAS
5379 if (loglevel & CPU_LOG_TB_IN_ASM) {
5380 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5384 generate_exception(ctx, EXCP_RI);
5387 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5388 int u, int sel, int h)
5390 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5391 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5393 gen_load_gpr(t0, rt);
5394 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5395 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5396 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5398 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5399 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5406 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5409 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5412 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5415 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5418 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5421 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5424 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5427 gen_mtc0(env, ctx, t0, rd, sel);
5434 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5437 gen_mtc0(env, ctx, t0, rd, sel);
5443 tcg_gen_helper_0_1(do_mttc0_status, t0);
5446 gen_mtc0(env, ctx, t0, rd, sel);
5452 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5455 gen_mtc0(env, ctx, t0, rd, sel);
5460 gen_mtc0(env, ctx, t0, rd, sel);
5462 } else switch (sel) {
5463 /* GPR registers. */
5465 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5467 /* Auxiliary CPU registers */
5471 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5474 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5477 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5480 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5483 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5486 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5489 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5492 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5495 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5498 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5501 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5504 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5507 tcg_gen_helper_0_1(do_mttdsp, t0);
5513 /* Floating point (COP1). */
5515 /* XXX: For now we support only a single FPU context. */
5517 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5519 tcg_gen_trunc_tl_i32(fp0, t0);
5520 gen_store_fpr32(fp0, rd);
5523 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5525 tcg_gen_trunc_tl_i32(fp0, t0);
5526 gen_store_fpr32h(fp0, rd);
5531 /* XXX: For now we support only a single FPU context. */
5532 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5534 /* COP2: Not implemented. */
5541 #if defined MIPS_DEBUG_DISAS
5542 if (loglevel & CPU_LOG_TB_IN_ASM) {
5543 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5552 #if defined MIPS_DEBUG_DISAS
5553 if (loglevel & CPU_LOG_TB_IN_ASM) {
5554 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5558 generate_exception(ctx, EXCP_RI);
5561 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5563 const char *opn = "ldst";
5572 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5574 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5575 gen_store_gpr(t0, rt);
5582 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5584 gen_load_gpr(t0, rt);
5585 save_cpu_state(ctx, 1);
5586 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5591 #if defined(TARGET_MIPS64)
5593 check_insn(env, ctx, ISA_MIPS3);
5599 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5601 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5602 gen_store_gpr(t0, rt);
5608 check_insn(env, ctx, ISA_MIPS3);
5610 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5612 gen_load_gpr(t0, rt);
5613 save_cpu_state(ctx, 1);
5614 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5621 check_insn(env, ctx, ASE_MT);
5626 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5627 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5631 check_insn(env, ctx, ASE_MT);
5632 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5633 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5638 if (!env->tlb->do_tlbwi)
5640 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5644 if (!env->tlb->do_tlbwr)
5646 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5650 if (!env->tlb->do_tlbp)
5652 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5656 if (!env->tlb->do_tlbr)
5658 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5662 check_insn(env, ctx, ISA_MIPS2);
5663 save_cpu_state(ctx, 1);
5664 tcg_gen_helper_0_0(do_eret);
5665 ctx->bstate = BS_EXCP;
5669 check_insn(env, ctx, ISA_MIPS32);
5670 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5672 generate_exception(ctx, EXCP_RI);
5674 save_cpu_state(ctx, 1);
5675 tcg_gen_helper_0_0(do_deret);
5676 ctx->bstate = BS_EXCP;
5681 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5682 /* If we get an exception, we want to restart at next instruction */
5684 save_cpu_state(ctx, 1);
5686 tcg_gen_helper_0_0(do_wait);
5687 ctx->bstate = BS_EXCP;
5692 generate_exception(ctx, EXCP_RI);
5695 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5697 #endif /* !CONFIG_USER_ONLY */
5699 /* CP1 Branches (before delay slot) */
5700 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5701 int32_t cc, int32_t offset)
5703 target_ulong btarget;
5704 const char *opn = "cp1 cond branch";
5705 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5706 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5709 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5711 btarget = ctx->pc + 4 + offset;
5716 int l1 = gen_new_label();
5717 int l2 = gen_new_label();
5718 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5720 get_fp_cond(r_tmp1);
5721 tcg_gen_ext_i32_tl(t0, r_tmp1);
5722 tcg_temp_free(r_tmp1);
5723 tcg_gen_not_tl(t0, t0);
5724 tcg_gen_movi_tl(t1, 0x1 << cc);
5725 tcg_gen_and_tl(t0, t0, t1);
5726 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5727 tcg_gen_movi_tl(t0, 0);
5730 tcg_gen_movi_tl(t0, 1);
5737 int l1 = gen_new_label();
5738 int l2 = gen_new_label();
5739 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5741 get_fp_cond(r_tmp1);
5742 tcg_gen_ext_i32_tl(t0, r_tmp1);
5743 tcg_temp_free(r_tmp1);
5744 tcg_gen_not_tl(t0, t0);
5745 tcg_gen_movi_tl(t1, 0x1 << cc);
5746 tcg_gen_and_tl(t0, t0, t1);
5747 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5748 tcg_gen_movi_tl(t0, 0);
5751 tcg_gen_movi_tl(t0, 1);
5758 int l1 = gen_new_label();
5759 int l2 = gen_new_label();
5760 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5762 get_fp_cond(r_tmp1);
5763 tcg_gen_ext_i32_tl(t0, r_tmp1);
5764 tcg_temp_free(r_tmp1);
5765 tcg_gen_movi_tl(t1, 0x1 << cc);
5766 tcg_gen_and_tl(t0, t0, t1);
5767 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5768 tcg_gen_movi_tl(t0, 0);
5771 tcg_gen_movi_tl(t0, 1);
5778 int l1 = gen_new_label();
5779 int l2 = gen_new_label();
5780 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5782 get_fp_cond(r_tmp1);
5783 tcg_gen_ext_i32_tl(t0, r_tmp1);
5784 tcg_temp_free(r_tmp1);
5785 tcg_gen_movi_tl(t1, 0x1 << cc);
5786 tcg_gen_and_tl(t0, t0, t1);
5787 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5788 tcg_gen_movi_tl(t0, 0);
5791 tcg_gen_movi_tl(t0, 1);
5796 ctx->hflags |= MIPS_HFLAG_BL;
5797 tcg_gen_trunc_tl_i32(bcond, t0);
5801 int l1 = gen_new_label();
5802 int l2 = gen_new_label();
5803 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5805 get_fp_cond(r_tmp1);
5806 tcg_gen_ext_i32_tl(t0, r_tmp1);
5807 tcg_temp_free(r_tmp1);
5808 tcg_gen_not_tl(t0, t0);
5809 tcg_gen_movi_tl(t1, 0x3 << cc);
5810 tcg_gen_and_tl(t0, t0, t1);
5811 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5812 tcg_gen_movi_tl(t0, 0);
5815 tcg_gen_movi_tl(t0, 1);
5822 int l1 = gen_new_label();
5823 int l2 = gen_new_label();
5824 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5826 get_fp_cond(r_tmp1);
5827 tcg_gen_ext_i32_tl(t0, r_tmp1);
5828 tcg_temp_free(r_tmp1);
5829 tcg_gen_movi_tl(t1, 0x3 << cc);
5830 tcg_gen_and_tl(t0, t0, t1);
5831 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5832 tcg_gen_movi_tl(t0, 0);
5835 tcg_gen_movi_tl(t0, 1);
5842 int l1 = gen_new_label();
5843 int l2 = gen_new_label();
5844 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5846 get_fp_cond(r_tmp1);
5847 tcg_gen_ext_i32_tl(t0, r_tmp1);
5848 tcg_temp_free(r_tmp1);
5849 tcg_gen_not_tl(t0, t0);
5850 tcg_gen_movi_tl(t1, 0xf << cc);
5851 tcg_gen_and_tl(t0, t0, t1);
5852 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5853 tcg_gen_movi_tl(t0, 0);
5856 tcg_gen_movi_tl(t0, 1);
5863 int l1 = gen_new_label();
5864 int l2 = gen_new_label();
5865 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5867 get_fp_cond(r_tmp1);
5868 tcg_gen_ext_i32_tl(t0, r_tmp1);
5869 tcg_temp_free(r_tmp1);
5870 tcg_gen_movi_tl(t1, 0xf << cc);
5871 tcg_gen_and_tl(t0, t0, t1);
5872 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5873 tcg_gen_movi_tl(t0, 0);
5876 tcg_gen_movi_tl(t0, 1);
5881 ctx->hflags |= MIPS_HFLAG_BC;
5882 tcg_gen_trunc_tl_i32(bcond, t0);
5886 generate_exception (ctx, EXCP_RI);
5889 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5890 ctx->hflags, btarget);
5891 ctx->btarget = btarget;
5898 /* Coprocessor 1 (FPU) */
5900 #define FOP(func, fmt) (((fmt) << 21) | (func))
5902 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5904 const char *opn = "cp1 move";
5905 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5910 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5912 gen_load_fpr32(fp0, fs);
5913 tcg_gen_ext_i32_tl(t0, fp0);
5916 gen_store_gpr(t0, rt);
5920 gen_load_gpr(t0, rt);
5922 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5924 tcg_gen_trunc_tl_i32(fp0, t0);
5925 gen_store_fpr32(fp0, fs);
5931 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5932 gen_store_gpr(t0, rt);
5936 gen_load_gpr(t0, rt);
5937 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5942 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5944 gen_load_fpr64(ctx, fp0, fs);
5945 tcg_gen_mov_tl(t0, fp0);
5948 gen_store_gpr(t0, rt);
5952 gen_load_gpr(t0, rt);
5954 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5956 tcg_gen_mov_tl(fp0, t0);
5957 gen_store_fpr64(ctx, fp0, fs);
5964 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5966 gen_load_fpr32h(fp0, fs);
5967 tcg_gen_ext_i32_tl(t0, fp0);
5970 gen_store_gpr(t0, rt);
5974 gen_load_gpr(t0, rt);
5976 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5978 tcg_gen_trunc_tl_i32(fp0, t0);
5979 gen_store_fpr32h(fp0, fs);
5986 generate_exception (ctx, EXCP_RI);
5989 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5995 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5997 int l1 = gen_new_label();
6000 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6001 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
6002 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
6005 ccbit = 1 << (24 + cc);
6013 gen_load_gpr(t0, rd);
6014 gen_load_gpr(t1, rs);
6015 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
6016 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
6017 tcg_temp_free(r_tmp);
6019 tcg_gen_mov_tl(t0, t1);
6023 gen_store_gpr(t0, rd);
6027 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
6031 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6032 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6033 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6034 int l1 = gen_new_label();
6037 ccbit = 1 << (24 + cc);
6046 gen_load_fpr32(fp0, fs);
6047 gen_load_fpr32(fp1, fd);
6048 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6049 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6050 tcg_gen_mov_i32(fp1, fp0);
6053 tcg_temp_free(r_tmp1);
6054 gen_store_fpr32(fp1, fd);
6058 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
6062 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6063 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6064 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I64);
6065 int l1 = gen_new_label();
6068 ccbit = 1 << (24 + cc);
6077 gen_load_fpr64(ctx, fp0, fs);
6078 gen_load_fpr64(ctx, fp1, fd);
6079 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6080 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6081 tcg_gen_mov_i64(fp1, fp0);
6084 tcg_temp_free(r_tmp1);
6085 gen_store_fpr64(ctx, fp1, fd);
6089 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
6092 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6093 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6094 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6095 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
6096 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6097 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
6098 int l1 = gen_new_label();
6099 int l2 = gen_new_label();
6106 gen_load_fpr32(fp0, fs);
6107 gen_load_fpr32h(fph0, fs);
6108 gen_load_fpr32(fp1, fd);
6109 gen_load_fpr32h(fph1, fd);
6110 get_fp_cond(r_tmp1);
6111 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6112 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6113 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6114 tcg_gen_mov_i32(fp1, fp0);
6117 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6118 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6119 tcg_gen_mov_i32(fph1, fph0);
6120 tcg_temp_free(fph0);
6122 tcg_temp_free(r_tmp1);
6123 tcg_temp_free(r_tmp2);
6124 gen_store_fpr32(fp1, fd);
6125 gen_store_fpr32h(fph1, fd);
6127 tcg_temp_free(fph1);
6131 static void gen_farith (DisasContext *ctx, uint32_t op1,
6132 int ft, int fs, int fd, int cc)
6134 const char *opn = "farith";
6135 const char *condnames[] = {
6153 const char *condnames_abs[] = {
6171 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6172 uint32_t func = ctx->opcode & 0x3f;
6174 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6177 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6178 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6180 gen_load_fpr32(fp0, fs);
6181 gen_load_fpr32(fp1, ft);
6182 tcg_gen_helper_1_2(do_float_add_s, fp0, fp0, fp1);
6184 gen_store_fpr32(fp0, fd);
6192 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6193 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6195 gen_load_fpr32(fp0, fs);
6196 gen_load_fpr32(fp1, ft);
6197 tcg_gen_helper_1_2(do_float_sub_s, fp0, fp0, fp1);
6199 gen_store_fpr32(fp0, fd);
6207 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6208 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6210 gen_load_fpr32(fp0, fs);
6211 gen_load_fpr32(fp1, ft);
6212 tcg_gen_helper_1_2(do_float_mul_s, fp0, fp0, fp1);
6214 gen_store_fpr32(fp0, fd);
6222 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6223 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6225 gen_load_fpr32(fp0, fs);
6226 gen_load_fpr32(fp1, ft);
6227 tcg_gen_helper_1_2(do_float_div_s, fp0, fp0, fp1);
6229 gen_store_fpr32(fp0, fd);
6237 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6239 gen_load_fpr32(fp0, fs);
6240 tcg_gen_helper_1_1(do_float_sqrt_s, fp0, fp0);
6241 gen_store_fpr32(fp0, fd);
6248 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6250 gen_load_fpr32(fp0, fs);
6251 tcg_gen_helper_1_1(do_float_abs_s, fp0, fp0);
6252 gen_store_fpr32(fp0, fd);
6259 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6261 gen_load_fpr32(fp0, fs);
6262 gen_store_fpr32(fp0, fd);
6269 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6271 gen_load_fpr32(fp0, fs);
6272 tcg_gen_helper_1_1(do_float_chs_s, fp0, fp0);
6273 gen_store_fpr32(fp0, fd);
6279 check_cp1_64bitmode(ctx);
6281 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6282 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6284 gen_load_fpr32(fp32, fs);
6285 tcg_gen_helper_1_1(do_float_roundl_s, fp64, fp32);
6286 tcg_temp_free(fp32);
6287 gen_store_fpr64(ctx, fp64, fd);
6288 tcg_temp_free(fp64);
6293 check_cp1_64bitmode(ctx);
6295 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6296 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6298 gen_load_fpr32(fp32, fs);
6299 tcg_gen_helper_1_1(do_float_truncl_s, fp64, fp32);
6300 tcg_temp_free(fp32);
6301 gen_store_fpr64(ctx, fp64, fd);
6302 tcg_temp_free(fp64);
6307 check_cp1_64bitmode(ctx);
6309 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6310 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6312 gen_load_fpr32(fp32, fs);
6313 tcg_gen_helper_1_1(do_float_ceill_s, fp64, fp32);
6314 tcg_temp_free(fp32);
6315 gen_store_fpr64(ctx, fp64, fd);
6316 tcg_temp_free(fp64);
6321 check_cp1_64bitmode(ctx);
6323 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6324 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6326 gen_load_fpr32(fp32, fs);
6327 tcg_gen_helper_1_1(do_float_floorl_s, fp64, fp32);
6328 tcg_temp_free(fp32);
6329 gen_store_fpr64(ctx, fp64, fd);
6330 tcg_temp_free(fp64);
6336 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6338 gen_load_fpr32(fp0, fs);
6339 tcg_gen_helper_1_1(do_float_roundw_s, fp0, fp0);
6340 gen_store_fpr32(fp0, fd);
6347 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6349 gen_load_fpr32(fp0, fs);
6350 tcg_gen_helper_1_1(do_float_truncw_s, fp0, fp0);
6351 gen_store_fpr32(fp0, fd);
6358 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6360 gen_load_fpr32(fp0, fs);
6361 tcg_gen_helper_1_1(do_float_ceilw_s, fp0, fp0);
6362 gen_store_fpr32(fp0, fd);
6369 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6371 gen_load_fpr32(fp0, fs);
6372 tcg_gen_helper_1_1(do_float_floorw_s, fp0, fp0);
6373 gen_store_fpr32(fp0, fd);
6379 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6384 int l1 = gen_new_label();
6385 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6386 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6388 gen_load_gpr(t0, ft);
6389 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6391 gen_load_fpr32(fp0, fs);
6392 gen_store_fpr32(fp0, fd);
6400 int l1 = gen_new_label();
6401 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6402 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6404 gen_load_gpr(t0, ft);
6405 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6407 gen_load_fpr32(fp0, fs);
6408 gen_store_fpr32(fp0, fd);
6417 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6419 gen_load_fpr32(fp0, fs);
6420 tcg_gen_helper_1_1(do_float_recip_s, fp0, fp0);
6421 gen_store_fpr32(fp0, fd);
6429 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6431 gen_load_fpr32(fp0, fs);
6432 tcg_gen_helper_1_1(do_float_rsqrt_s, fp0, fp0);
6433 gen_store_fpr32(fp0, fd);
6439 check_cp1_64bitmode(ctx);
6441 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6442 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6444 gen_load_fpr32(fp0, fs);
6445 gen_load_fpr32(fp1, fd);
6446 tcg_gen_helper_1_2(do_float_recip2_s, fp0, fp0, fp1);
6448 gen_store_fpr32(fp0, fd);
6454 check_cp1_64bitmode(ctx);
6456 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6458 gen_load_fpr32(fp0, fs);
6459 tcg_gen_helper_1_1(do_float_recip1_s, fp0, fp0);
6460 gen_store_fpr32(fp0, fd);
6466 check_cp1_64bitmode(ctx);
6468 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6470 gen_load_fpr32(fp0, fs);
6471 tcg_gen_helper_1_1(do_float_rsqrt1_s, fp0, fp0);
6472 gen_store_fpr32(fp0, fd);
6478 check_cp1_64bitmode(ctx);
6480 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6481 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6483 gen_load_fpr32(fp0, fs);
6484 gen_load_fpr32(fp1, ft);
6485 tcg_gen_helper_1_2(do_float_rsqrt2_s, fp0, fp0, fp1);
6487 gen_store_fpr32(fp0, fd);
6493 check_cp1_registers(ctx, fd);
6495 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6496 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6498 gen_load_fpr32(fp32, fs);
6499 tcg_gen_helper_1_1(do_float_cvtd_s, fp64, fp32);
6500 tcg_temp_free(fp32);
6501 gen_store_fpr64(ctx, fp64, fd);
6502 tcg_temp_free(fp64);
6508 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6510 gen_load_fpr32(fp0, fs);
6511 tcg_gen_helper_1_1(do_float_cvtw_s, fp0, fp0);
6512 gen_store_fpr32(fp0, fd);
6518 check_cp1_64bitmode(ctx);
6520 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6521 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6523 gen_load_fpr32(fp32, fs);
6524 tcg_gen_helper_1_1(do_float_cvtl_s, fp64, fp32);
6525 tcg_temp_free(fp32);
6526 gen_store_fpr64(ctx, fp64, fd);
6527 tcg_temp_free(fp64);
6532 check_cp1_64bitmode(ctx);
6534 TCGv fp64_0 = tcg_temp_new(TCG_TYPE_I64);
6535 TCGv fp64_1 = tcg_temp_new(TCG_TYPE_I64);
6536 TCGv fp32_0 = tcg_temp_new(TCG_TYPE_I32);
6537 TCGv fp32_1 = tcg_temp_new(TCG_TYPE_I32);
6539 gen_load_fpr32(fp32_0, fs);
6540 gen_load_fpr32(fp32_1, ft);
6541 tcg_gen_extu_i32_i64(fp64_0, fp32_0);
6542 tcg_gen_extu_i32_i64(fp64_1, fp32_1);
6543 tcg_temp_free(fp32_0);
6544 tcg_temp_free(fp32_1);
6545 tcg_gen_shli_i64(fp64_1, fp64_1, 32);
6546 tcg_gen_or_i64(fp64_0, fp64_0, fp64_1);
6547 tcg_temp_free(fp64_1);
6548 gen_store_fpr64(ctx, fp64_0, fd);
6549 tcg_temp_free(fp64_0);
6570 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6571 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6573 gen_load_fpr32(fp0, fs);
6574 gen_load_fpr32(fp1, ft);
6575 if (ctx->opcode & (1 << 6)) {
6577 gen_cmpabs_s(func-48, fp0, fp1, cc);
6578 opn = condnames_abs[func-48];
6580 gen_cmp_s(func-48, fp0, fp1, cc);
6581 opn = condnames[func-48];
6588 check_cp1_registers(ctx, fs | ft | fd);
6590 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6591 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6593 gen_load_fpr64(ctx, fp0, fs);
6594 gen_load_fpr64(ctx, fp1, ft);
6595 tcg_gen_helper_1_2(do_float_add_d, fp0, fp0, fp1);
6597 gen_store_fpr64(ctx, fp0, fd);
6604 check_cp1_registers(ctx, fs | ft | fd);
6606 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6607 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6609 gen_load_fpr64(ctx, fp0, fs);
6610 gen_load_fpr64(ctx, fp1, ft);
6611 tcg_gen_helper_1_2(do_float_sub_d, fp0, fp0, fp1);
6613 gen_store_fpr64(ctx, fp0, fd);
6620 check_cp1_registers(ctx, fs | ft | fd);
6622 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6623 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6625 gen_load_fpr64(ctx, fp0, fs);
6626 gen_load_fpr64(ctx, fp1, ft);
6627 tcg_gen_helper_1_2(do_float_mul_d, fp0, fp0, fp1);
6629 gen_store_fpr64(ctx, fp0, fd);
6636 check_cp1_registers(ctx, fs | ft | fd);
6638 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6639 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6641 gen_load_fpr64(ctx, fp0, fs);
6642 gen_load_fpr64(ctx, fp1, ft);
6643 tcg_gen_helper_1_2(do_float_div_d, fp0, fp0, fp1);
6645 gen_store_fpr64(ctx, fp0, fd);
6652 check_cp1_registers(ctx, fs | fd);
6654 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6656 gen_load_fpr64(ctx, fp0, fs);
6657 tcg_gen_helper_1_1(do_float_sqrt_d, fp0, fp0);
6658 gen_store_fpr64(ctx, fp0, fd);
6664 check_cp1_registers(ctx, fs | fd);
6666 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6668 gen_load_fpr64(ctx, fp0, fs);
6669 tcg_gen_helper_1_1(do_float_abs_d, fp0, fp0);
6670 gen_store_fpr64(ctx, fp0, fd);
6676 check_cp1_registers(ctx, fs | fd);
6678 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6680 gen_load_fpr64(ctx, fp0, fs);
6681 gen_store_fpr64(ctx, fp0, fd);
6687 check_cp1_registers(ctx, fs | fd);
6689 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6691 gen_load_fpr64(ctx, fp0, fs);
6692 tcg_gen_helper_1_1(do_float_chs_d, fp0, fp0);
6693 gen_store_fpr64(ctx, fp0, fd);
6699 check_cp1_64bitmode(ctx);
6701 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6703 gen_load_fpr64(ctx, fp0, fs);
6704 tcg_gen_helper_1_1(do_float_roundl_d, fp0, fp0);
6705 gen_store_fpr64(ctx, fp0, fd);
6711 check_cp1_64bitmode(ctx);
6713 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6715 gen_load_fpr64(ctx, fp0, fs);
6716 tcg_gen_helper_1_1(do_float_truncl_d, fp0, fp0);
6717 gen_store_fpr64(ctx, fp0, fd);
6723 check_cp1_64bitmode(ctx);
6725 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6727 gen_load_fpr64(ctx, fp0, fs);
6728 tcg_gen_helper_1_1(do_float_ceill_d, fp0, fp0);
6729 gen_store_fpr64(ctx, fp0, fd);
6735 check_cp1_64bitmode(ctx);
6737 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6739 gen_load_fpr64(ctx, fp0, fs);
6740 tcg_gen_helper_1_1(do_float_floorl_d, fp0, fp0);
6741 gen_store_fpr64(ctx, fp0, fd);
6747 check_cp1_registers(ctx, fs);
6749 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6750 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6752 gen_load_fpr64(ctx, fp64, fs);
6753 tcg_gen_helper_1_1(do_float_roundw_d, fp32, fp64);
6754 tcg_temp_free(fp64);
6755 gen_store_fpr32(fp32, fd);
6756 tcg_temp_free(fp32);
6761 check_cp1_registers(ctx, fs);
6763 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6764 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6766 gen_load_fpr64(ctx, fp64, fs);
6767 tcg_gen_helper_1_1(do_float_truncw_d, fp32, fp64);
6768 tcg_temp_free(fp64);
6769 gen_store_fpr32(fp32, fd);
6770 tcg_temp_free(fp32);
6775 check_cp1_registers(ctx, fs);
6777 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6778 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6780 gen_load_fpr64(ctx, fp64, fs);
6781 tcg_gen_helper_1_1(do_float_ceilw_d, fp32, fp64);
6782 tcg_temp_free(fp64);
6783 gen_store_fpr32(fp32, fd);
6784 tcg_temp_free(fp32);
6789 check_cp1_registers(ctx, fs);
6791 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6792 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6794 gen_load_fpr64(ctx, fp64, fs);
6795 tcg_gen_helper_1_1(do_float_floorw_d, fp32, fp64);
6796 tcg_temp_free(fp64);
6797 gen_store_fpr32(fp32, fd);
6798 tcg_temp_free(fp32);
6803 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6808 int l1 = gen_new_label();
6809 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6810 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6812 gen_load_gpr(t0, ft);
6813 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6815 gen_load_fpr64(ctx, fp0, fs);
6816 gen_store_fpr64(ctx, fp0, fd);
6824 int l1 = gen_new_label();
6825 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6826 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6828 gen_load_gpr(t0, ft);
6829 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6831 gen_load_fpr64(ctx, fp0, fs);
6832 gen_store_fpr64(ctx, fp0, fd);
6839 check_cp1_64bitmode(ctx);
6841 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6843 gen_load_fpr64(ctx, fp0, fs);
6844 tcg_gen_helper_1_1(do_float_recip_d, fp0, fp0);
6845 gen_store_fpr64(ctx, fp0, fd);
6851 check_cp1_64bitmode(ctx);
6853 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6855 gen_load_fpr64(ctx, fp0, fs);
6856 tcg_gen_helper_1_1(do_float_rsqrt_d, fp0, fp0);
6857 gen_store_fpr64(ctx, fp0, fd);
6863 check_cp1_64bitmode(ctx);
6865 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6866 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6868 gen_load_fpr64(ctx, fp0, fs);
6869 gen_load_fpr64(ctx, fp1, ft);
6870 tcg_gen_helper_1_2(do_float_recip2_d, fp0, fp0, fp1);
6872 gen_store_fpr64(ctx, fp0, fd);
6878 check_cp1_64bitmode(ctx);
6880 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6882 gen_load_fpr64(ctx, fp0, fs);
6883 tcg_gen_helper_1_1(do_float_recip1_d, fp0, fp0);
6884 gen_store_fpr64(ctx, fp0, fd);
6890 check_cp1_64bitmode(ctx);
6892 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6894 gen_load_fpr64(ctx, fp0, fs);
6895 tcg_gen_helper_1_1(do_float_rsqrt1_d, fp0, fp0);
6896 gen_store_fpr64(ctx, fp0, fd);
6902 check_cp1_64bitmode(ctx);
6904 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6905 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6907 gen_load_fpr64(ctx, fp0, fs);
6908 gen_load_fpr64(ctx, fp1, ft);
6909 tcg_gen_helper_1_2(do_float_rsqrt2_d, fp0, fp0, fp1);
6911 gen_store_fpr64(ctx, fp0, fd);
6933 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6934 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6936 gen_load_fpr64(ctx, fp0, fs);
6937 gen_load_fpr64(ctx, fp1, ft);
6938 if (ctx->opcode & (1 << 6)) {
6940 check_cp1_registers(ctx, fs | ft);
6941 gen_cmpabs_d(func-48, fp0, fp1, cc);
6942 opn = condnames_abs[func-48];
6944 check_cp1_registers(ctx, fs | ft);
6945 gen_cmp_d(func-48, fp0, fp1, cc);
6946 opn = condnames[func-48];
6953 check_cp1_registers(ctx, fs);
6955 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6956 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6958 gen_load_fpr64(ctx, fp64, fs);
6959 tcg_gen_helper_1_1(do_float_cvts_d, fp32, fp64);
6960 tcg_temp_free(fp64);
6961 gen_store_fpr32(fp32, fd);
6962 tcg_temp_free(fp32);
6967 check_cp1_registers(ctx, fs);
6969 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6970 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6972 gen_load_fpr64(ctx, fp64, fs);
6973 tcg_gen_helper_1_1(do_float_cvtw_d, fp32, fp64);
6974 tcg_temp_free(fp64);
6975 gen_store_fpr32(fp32, fd);
6976 tcg_temp_free(fp32);
6981 check_cp1_64bitmode(ctx);
6983 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6985 gen_load_fpr64(ctx, fp0, fs);
6986 tcg_gen_helper_1_1(do_float_cvtl_d, fp0, fp0);
6987 gen_store_fpr64(ctx, fp0, fd);
6994 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6996 gen_load_fpr32(fp0, fs);
6997 tcg_gen_helper_1_1(do_float_cvts_w, fp0, fp0);
6998 gen_store_fpr32(fp0, fd);
7004 check_cp1_registers(ctx, fd);
7006 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
7007 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
7009 gen_load_fpr32(fp32, fs);
7010 tcg_gen_helper_1_1(do_float_cvtd_w, fp64, fp32);
7011 tcg_temp_free(fp32);
7012 gen_store_fpr64(ctx, fp64, fd);
7013 tcg_temp_free(fp64);
7018 check_cp1_64bitmode(ctx);
7020 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
7021 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
7023 gen_load_fpr64(ctx, fp64, fs);
7024 tcg_gen_helper_1_1(do_float_cvts_l, fp32, fp64);
7025 tcg_temp_free(fp64);
7026 gen_store_fpr32(fp32, fd);
7027 tcg_temp_free(fp32);
7032 check_cp1_64bitmode(ctx);
7034 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7036 gen_load_fpr64(ctx, fp0, fs);
7037 tcg_gen_helper_1_1(do_float_cvtd_l, fp0, fp0);
7038 gen_store_fpr64(ctx, fp0, fd);
7044 check_cp1_64bitmode(ctx);
7046 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7048 gen_load_fpr64(ctx, fp0, fs);
7049 tcg_gen_helper_1_1(do_float_cvtps_pw, fp0, fp0);
7050 gen_store_fpr64(ctx, fp0, fd);
7056 check_cp1_64bitmode(ctx);
7058 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7059 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7061 gen_load_fpr64(ctx, fp0, fs);
7062 gen_load_fpr64(ctx, fp1, ft);
7063 tcg_gen_helper_1_2(do_float_add_ps, fp0, fp0, fp1);
7065 gen_store_fpr64(ctx, fp0, fd);
7071 check_cp1_64bitmode(ctx);
7073 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7074 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7076 gen_load_fpr64(ctx, fp0, fs);
7077 gen_load_fpr64(ctx, fp1, ft);
7078 tcg_gen_helper_1_2(do_float_sub_ps, fp0, fp0, fp1);
7080 gen_store_fpr64(ctx, fp0, fd);
7086 check_cp1_64bitmode(ctx);
7088 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7089 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7091 gen_load_fpr64(ctx, fp0, fs);
7092 gen_load_fpr64(ctx, fp1, ft);
7093 tcg_gen_helper_1_2(do_float_mul_ps, fp0, fp0, fp1);
7095 gen_store_fpr64(ctx, fp0, fd);
7101 check_cp1_64bitmode(ctx);
7103 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7105 gen_load_fpr64(ctx, fp0, fs);
7106 tcg_gen_helper_1_1(do_float_abs_ps, fp0, fp0);
7107 gen_store_fpr64(ctx, fp0, fd);
7113 check_cp1_64bitmode(ctx);
7115 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7117 gen_load_fpr64(ctx, fp0, fs);
7118 gen_store_fpr64(ctx, fp0, fd);
7124 check_cp1_64bitmode(ctx);
7126 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7128 gen_load_fpr64(ctx, fp0, fs);
7129 tcg_gen_helper_1_1(do_float_chs_ps, fp0, fp0);
7130 gen_store_fpr64(ctx, fp0, fd);
7136 check_cp1_64bitmode(ctx);
7137 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
7141 check_cp1_64bitmode(ctx);
7143 int l1 = gen_new_label();
7144 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7145 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7146 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7148 gen_load_gpr(t0, ft);
7149 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7151 gen_load_fpr32(fp0, fs);
7152 gen_load_fpr32h(fph0, fs);
7153 gen_store_fpr32(fp0, fd);
7154 gen_store_fpr32h(fph0, fd);
7156 tcg_temp_free(fph0);
7162 check_cp1_64bitmode(ctx);
7164 int l1 = gen_new_label();
7165 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7166 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7167 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7169 gen_load_gpr(t0, ft);
7170 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
7172 gen_load_fpr32(fp0, fs);
7173 gen_load_fpr32h(fph0, fs);
7174 gen_store_fpr32(fp0, fd);
7175 gen_store_fpr32h(fph0, fd);
7177 tcg_temp_free(fph0);
7183 check_cp1_64bitmode(ctx);
7185 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7186 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7188 gen_load_fpr64(ctx, fp0, ft);
7189 gen_load_fpr64(ctx, fp1, fs);
7190 tcg_gen_helper_1_2(do_float_addr_ps, fp0, fp0, fp1);
7192 gen_store_fpr64(ctx, fp0, fd);
7198 check_cp1_64bitmode(ctx);
7200 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7201 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7203 gen_load_fpr64(ctx, fp0, ft);
7204 gen_load_fpr64(ctx, fp1, fs);
7205 tcg_gen_helper_1_2(do_float_mulr_ps, fp0, fp0, fp1);
7207 gen_store_fpr64(ctx, fp0, fd);
7213 check_cp1_64bitmode(ctx);
7215 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7216 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7218 gen_load_fpr64(ctx, fp0, fs);
7219 gen_load_fpr64(ctx, fp1, fd);
7220 tcg_gen_helper_1_2(do_float_recip2_ps, fp0, fp0, fp1);
7222 gen_store_fpr64(ctx, fp0, fd);
7228 check_cp1_64bitmode(ctx);
7230 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7232 gen_load_fpr64(ctx, fp0, fs);
7233 tcg_gen_helper_1_1(do_float_recip1_ps, fp0, fp0);
7234 gen_store_fpr64(ctx, fp0, fd);
7240 check_cp1_64bitmode(ctx);
7242 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7244 gen_load_fpr64(ctx, fp0, fs);
7245 tcg_gen_helper_1_1(do_float_rsqrt1_ps, fp0, fp0);
7246 gen_store_fpr64(ctx, fp0, fd);
7252 check_cp1_64bitmode(ctx);
7254 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7255 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7257 gen_load_fpr64(ctx, fp0, fs);
7258 gen_load_fpr64(ctx, fp1, ft);
7259 tcg_gen_helper_1_2(do_float_rsqrt2_ps, fp0, fp0, fp1);
7261 gen_store_fpr64(ctx, fp0, fd);
7267 check_cp1_64bitmode(ctx);
7269 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7271 gen_load_fpr32h(fp0, fs);
7272 tcg_gen_helper_1_1(do_float_cvts_pu, fp0, fp0);
7273 gen_store_fpr32(fp0, fd);
7279 check_cp1_64bitmode(ctx);
7281 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7283 gen_load_fpr64(ctx, fp0, fs);
7284 tcg_gen_helper_1_1(do_float_cvtpw_ps, fp0, fp0);
7285 gen_store_fpr64(ctx, fp0, fd);
7291 check_cp1_64bitmode(ctx);
7293 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7295 gen_load_fpr32(fp0, fs);
7296 tcg_gen_helper_1_1(do_float_cvts_pl, fp0, fp0);
7297 gen_store_fpr32(fp0, fd);
7303 check_cp1_64bitmode(ctx);
7305 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7306 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7308 gen_load_fpr32(fp0, fs);
7309 gen_load_fpr32(fp1, ft);
7310 gen_store_fpr32h(fp0, fd);
7311 gen_store_fpr32(fp1, fd);
7318 check_cp1_64bitmode(ctx);
7320 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7321 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7323 gen_load_fpr32(fp0, fs);
7324 gen_load_fpr32h(fp1, ft);
7325 gen_store_fpr32(fp1, fd);
7326 gen_store_fpr32h(fp0, fd);
7333 check_cp1_64bitmode(ctx);
7335 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7336 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7338 gen_load_fpr32h(fp0, fs);
7339 gen_load_fpr32(fp1, ft);
7340 gen_store_fpr32(fp1, fd);
7341 gen_store_fpr32h(fp0, fd);
7348 check_cp1_64bitmode(ctx);
7350 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7351 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7353 gen_load_fpr32h(fp0, fs);
7354 gen_load_fpr32h(fp1, ft);
7355 gen_store_fpr32(fp1, fd);
7356 gen_store_fpr32h(fp0, fd);
7378 check_cp1_64bitmode(ctx);
7380 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7381 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7383 gen_load_fpr64(ctx, fp0, fs);
7384 gen_load_fpr64(ctx, fp1, ft);
7385 if (ctx->opcode & (1 << 6)) {
7386 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7387 opn = condnames_abs[func-48];
7389 gen_cmp_ps(func-48, fp0, fp1, cc);
7390 opn = condnames[func-48];
7398 generate_exception (ctx, EXCP_RI);
7403 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7406 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7409 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7414 /* Coprocessor 3 (FPU) */
7415 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7416 int fd, int fs, int base, int index)
7418 const char *opn = "extended float load/store";
7420 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7421 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7424 gen_load_gpr(t0, index);
7425 } else if (index == 0) {
7426 gen_load_gpr(t0, base);
7428 gen_load_gpr(t0, base);
7429 gen_load_gpr(t1, index);
7430 gen_op_addr_add(t0, t1);
7432 /* Don't do NOP if destination is zero: we must perform the actual
7438 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7440 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
7441 gen_store_fpr32(fp0, fd);
7448 check_cp1_registers(ctx, fd);
7450 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7452 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7453 gen_store_fpr64(ctx, fp0, fd);
7459 check_cp1_64bitmode(ctx);
7460 tcg_gen_andi_tl(t0, t0, ~0x7);
7462 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7464 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7465 gen_store_fpr64(ctx, fp0, fd);
7473 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7475 gen_load_fpr32(fp0, fs);
7476 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
7484 check_cp1_registers(ctx, fs);
7486 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7488 gen_load_fpr64(ctx, fp0, fs);
7489 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7496 check_cp1_64bitmode(ctx);
7497 tcg_gen_andi_tl(t0, t0, ~0x7);
7499 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7501 gen_load_fpr64(ctx, fp0, fs);
7502 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7510 generate_exception(ctx, EXCP_RI);
7517 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7518 regnames[index], regnames[base]);
7521 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7522 int fd, int fr, int fs, int ft)
7524 const char *opn = "flt3_arith";
7528 check_cp1_64bitmode(ctx);
7530 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7531 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7532 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7533 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
7534 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
7535 int l1 = gen_new_label();
7536 int l2 = gen_new_label();
7538 gen_load_gpr(t0, fr);
7539 tcg_gen_andi_tl(t0, t0, 0x7);
7540 gen_load_fpr32(fp0, fs);
7541 gen_load_fpr32h(fph0, fs);
7542 gen_load_fpr32(fp1, ft);
7543 gen_load_fpr32h(fph1, ft);
7545 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7546 gen_store_fpr32(fp0, fd);
7547 gen_store_fpr32h(fph0, fd);
7550 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7552 #ifdef TARGET_WORDS_BIGENDIAN
7553 gen_store_fpr32(fph1, fd);
7554 gen_store_fpr32h(fp0, fd);
7556 gen_store_fpr32(fph0, fd);
7557 gen_store_fpr32h(fp1, fd);
7561 tcg_temp_free(fph0);
7563 tcg_temp_free(fph1);
7570 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7571 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7572 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7574 gen_load_fpr32(fp0, fs);
7575 gen_load_fpr32(fp1, ft);
7576 gen_load_fpr32(fp2, fr);
7577 tcg_gen_helper_1_3(do_float_muladd_s, fp2, fp0, fp1, fp2);
7580 gen_store_fpr32(fp2, fd);
7587 check_cp1_registers(ctx, fd | fs | ft | fr);
7589 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7590 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7591 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7593 gen_load_fpr64(ctx, fp0, fs);
7594 gen_load_fpr64(ctx, fp1, ft);
7595 gen_load_fpr64(ctx, fp2, fr);
7596 tcg_gen_helper_1_3(do_float_muladd_d, fp2, fp0, fp1, fp2);
7599 gen_store_fpr64(ctx, fp2, fd);
7605 check_cp1_64bitmode(ctx);
7607 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7608 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7609 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7611 gen_load_fpr64(ctx, fp0, fs);
7612 gen_load_fpr64(ctx, fp1, ft);
7613 gen_load_fpr64(ctx, fp2, fr);
7614 tcg_gen_helper_1_3(do_float_muladd_ps, fp2, fp0, fp1, fp2);
7617 gen_store_fpr64(ctx, fp2, fd);
7625 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7626 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7627 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7629 gen_load_fpr32(fp0, fs);
7630 gen_load_fpr32(fp1, ft);
7631 gen_load_fpr32(fp2, fr);
7632 tcg_gen_helper_1_3(do_float_mulsub_s, fp2, fp0, fp1, fp2);
7635 gen_store_fpr32(fp2, fd);
7642 check_cp1_registers(ctx, fd | fs | ft | fr);
7644 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7645 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7646 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7648 gen_load_fpr64(ctx, fp0, fs);
7649 gen_load_fpr64(ctx, fp1, ft);
7650 gen_load_fpr64(ctx, fp2, fr);
7651 tcg_gen_helper_1_3(do_float_mulsub_d, fp2, fp0, fp1, fp2);
7654 gen_store_fpr64(ctx, fp2, fd);
7660 check_cp1_64bitmode(ctx);
7662 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7663 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7664 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7666 gen_load_fpr64(ctx, fp0, fs);
7667 gen_load_fpr64(ctx, fp1, ft);
7668 gen_load_fpr64(ctx, fp2, fr);
7669 tcg_gen_helper_1_3(do_float_mulsub_ps, fp2, fp0, fp1, fp2);
7672 gen_store_fpr64(ctx, fp2, fd);
7680 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7681 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7682 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7684 gen_load_fpr32(fp0, fs);
7685 gen_load_fpr32(fp1, ft);
7686 gen_load_fpr32(fp2, fr);
7687 tcg_gen_helper_1_3(do_float_nmuladd_s, fp2, fp0, fp1, fp2);
7690 gen_store_fpr32(fp2, fd);
7697 check_cp1_registers(ctx, fd | fs | ft | fr);
7699 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7700 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7701 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7703 gen_load_fpr64(ctx, fp0, fs);
7704 gen_load_fpr64(ctx, fp1, ft);
7705 gen_load_fpr64(ctx, fp2, fr);
7706 tcg_gen_helper_1_3(do_float_nmuladd_d, fp2, fp0, fp1, fp2);
7709 gen_store_fpr64(ctx, fp2, fd);
7715 check_cp1_64bitmode(ctx);
7717 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7718 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7719 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7721 gen_load_fpr64(ctx, fp0, fs);
7722 gen_load_fpr64(ctx, fp1, ft);
7723 gen_load_fpr64(ctx, fp2, fr);
7724 tcg_gen_helper_1_3(do_float_nmuladd_ps, fp2, fp0, fp1, fp2);
7727 gen_store_fpr64(ctx, fp2, fd);
7735 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7736 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7737 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7739 gen_load_fpr32(fp0, fs);
7740 gen_load_fpr32(fp1, ft);
7741 gen_load_fpr32(fp2, fr);
7742 tcg_gen_helper_1_3(do_float_nmulsub_s, fp2, fp0, fp1, fp2);
7745 gen_store_fpr32(fp2, fd);
7752 check_cp1_registers(ctx, fd | fs | ft | fr);
7754 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7755 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7756 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7758 gen_load_fpr64(ctx, fp0, fs);
7759 gen_load_fpr64(ctx, fp1, ft);
7760 gen_load_fpr64(ctx, fp2, fr);
7761 tcg_gen_helper_1_3(do_float_nmulsub_d, fp2, fp0, fp1, fp2);
7764 gen_store_fpr64(ctx, fp2, fd);
7770 check_cp1_64bitmode(ctx);
7772 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7773 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7774 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7776 gen_load_fpr64(ctx, fp0, fs);
7777 gen_load_fpr64(ctx, fp1, ft);
7778 gen_load_fpr64(ctx, fp2, fr);
7779 tcg_gen_helper_1_3(do_float_nmulsub_ps, fp2, fp0, fp1, fp2);
7782 gen_store_fpr64(ctx, fp2, fd);
7789 generate_exception (ctx, EXCP_RI);
7792 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7793 fregnames[fs], fregnames[ft]);
7796 /* ISA extensions (ASEs) */
7797 /* MIPS16 extension to MIPS32 */
7798 /* SmartMIPS extension to MIPS32 */
7800 #if defined(TARGET_MIPS64)
7802 /* MDMX extension to MIPS64 */
7806 static void decode_opc (CPUState *env, DisasContext *ctx)
7810 uint32_t op, op1, op2;
7813 /* make sure instructions are on a word boundary */
7814 if (ctx->pc & 0x3) {
7815 env->CP0_BadVAddr = ctx->pc;
7816 generate_exception(ctx, EXCP_AdEL);
7820 /* Handle blikely not taken case */
7821 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7822 int l1 = gen_new_label();
7824 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7825 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7827 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
7829 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7830 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7831 tcg_temp_free(r_tmp);
7833 gen_goto_tb(ctx, 1, ctx->pc + 4);
7836 op = MASK_OP_MAJOR(ctx->opcode);
7837 rs = (ctx->opcode >> 21) & 0x1f;
7838 rt = (ctx->opcode >> 16) & 0x1f;
7839 rd = (ctx->opcode >> 11) & 0x1f;
7840 sa = (ctx->opcode >> 6) & 0x1f;
7841 imm = (int16_t)ctx->opcode;
7844 op1 = MASK_SPECIAL(ctx->opcode);
7846 case OPC_SLL: /* Arithmetic with immediate */
7847 case OPC_SRL ... OPC_SRA:
7848 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7850 case OPC_MOVZ ... OPC_MOVN:
7851 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7852 case OPC_SLLV: /* Arithmetic */
7853 case OPC_SRLV ... OPC_SRAV:
7854 case OPC_ADD ... OPC_NOR:
7855 case OPC_SLT ... OPC_SLTU:
7856 gen_arith(env, ctx, op1, rd, rs, rt);
7858 case OPC_MULT ... OPC_DIVU:
7860 check_insn(env, ctx, INSN_VR54XX);
7861 op1 = MASK_MUL_VR54XX(ctx->opcode);
7862 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7864 gen_muldiv(ctx, op1, rs, rt);
7866 case OPC_JR ... OPC_JALR:
7867 gen_compute_branch(ctx, op1, rs, rd, sa);
7869 case OPC_TGE ... OPC_TEQ: /* Traps */
7871 gen_trap(ctx, op1, rs, rt, -1);
7873 case OPC_MFHI: /* Move from HI/LO */
7875 gen_HILO(ctx, op1, rd);
7878 case OPC_MTLO: /* Move to HI/LO */
7879 gen_HILO(ctx, op1, rs);
7881 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7882 #ifdef MIPS_STRICT_STANDARD
7883 MIPS_INVAL("PMON / selsl");
7884 generate_exception(ctx, EXCP_RI);
7886 tcg_gen_helper_0_i(do_pmon, sa);
7890 generate_exception(ctx, EXCP_SYSCALL);
7893 generate_exception(ctx, EXCP_BREAK);
7896 #ifdef MIPS_STRICT_STANDARD
7898 generate_exception(ctx, EXCP_RI);
7900 /* Implemented as RI exception for now. */
7901 MIPS_INVAL("spim (unofficial)");
7902 generate_exception(ctx, EXCP_RI);
7910 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7911 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7912 save_cpu_state(ctx, 1);
7913 check_cp1_enabled(ctx);
7914 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7915 (ctx->opcode >> 16) & 1);
7917 generate_exception_err(ctx, EXCP_CpU, 1);
7921 #if defined(TARGET_MIPS64)
7922 /* MIPS64 specific opcodes */
7924 case OPC_DSRL ... OPC_DSRA:
7926 case OPC_DSRL32 ... OPC_DSRA32:
7927 check_insn(env, ctx, ISA_MIPS3);
7929 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7932 case OPC_DSRLV ... OPC_DSRAV:
7933 case OPC_DADD ... OPC_DSUBU:
7934 check_insn(env, ctx, ISA_MIPS3);
7936 gen_arith(env, ctx, op1, rd, rs, rt);
7938 case OPC_DMULT ... OPC_DDIVU:
7939 check_insn(env, ctx, ISA_MIPS3);
7941 gen_muldiv(ctx, op1, rs, rt);
7944 default: /* Invalid */
7945 MIPS_INVAL("special");
7946 generate_exception(ctx, EXCP_RI);
7951 op1 = MASK_SPECIAL2(ctx->opcode);
7953 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7954 case OPC_MSUB ... OPC_MSUBU:
7955 check_insn(env, ctx, ISA_MIPS32);
7956 gen_muldiv(ctx, op1, rs, rt);
7959 gen_arith(env, ctx, op1, rd, rs, rt);
7961 case OPC_CLZ ... OPC_CLO:
7962 check_insn(env, ctx, ISA_MIPS32);
7963 gen_cl(ctx, op1, rd, rs);
7966 /* XXX: not clear which exception should be raised
7967 * when in debug mode...
7969 check_insn(env, ctx, ISA_MIPS32);
7970 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7971 generate_exception(ctx, EXCP_DBp);
7973 generate_exception(ctx, EXCP_DBp);
7977 #if defined(TARGET_MIPS64)
7978 case OPC_DCLZ ... OPC_DCLO:
7979 check_insn(env, ctx, ISA_MIPS64);
7981 gen_cl(ctx, op1, rd, rs);
7984 default: /* Invalid */
7985 MIPS_INVAL("special2");
7986 generate_exception(ctx, EXCP_RI);
7991 op1 = MASK_SPECIAL3(ctx->opcode);
7995 check_insn(env, ctx, ISA_MIPS32R2);
7996 gen_bitops(ctx, op1, rt, rs, sa, rd);
7999 check_insn(env, ctx, ISA_MIPS32R2);
8000 op2 = MASK_BSHFL(ctx->opcode);
8002 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8003 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8007 gen_load_gpr(t1, rt);
8008 tcg_gen_helper_1_1(do_wsbh, t0, t1);
8009 gen_store_gpr(t0, rd);
8012 gen_load_gpr(t1, rt);
8013 tcg_gen_ext8s_tl(t0, t1);
8014 gen_store_gpr(t0, rd);
8017 gen_load_gpr(t1, rt);
8018 tcg_gen_ext16s_tl(t0, t1);
8019 gen_store_gpr(t0, rd);
8021 default: /* Invalid */
8022 MIPS_INVAL("bshfl");
8023 generate_exception(ctx, EXCP_RI);
8031 check_insn(env, ctx, ISA_MIPS32R2);
8033 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8037 save_cpu_state(ctx, 1);
8038 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
8041 save_cpu_state(ctx, 1);
8042 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
8045 save_cpu_state(ctx, 1);
8046 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
8049 save_cpu_state(ctx, 1);
8050 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
8053 if (env->user_mode_only) {
8054 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
8057 /* XXX: Some CPUs implement this in hardware.
8058 Not supported yet. */
8060 default: /* Invalid */
8061 MIPS_INVAL("rdhwr");
8062 generate_exception(ctx, EXCP_RI);
8065 gen_store_gpr(t0, rt);
8070 check_insn(env, ctx, ASE_MT);
8072 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8073 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8075 gen_load_gpr(t0, rt);
8076 gen_load_gpr(t1, rs);
8077 tcg_gen_helper_0_2(do_fork, t0, t1);
8083 check_insn(env, ctx, ASE_MT);
8085 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8087 gen_load_gpr(t0, rs);
8088 tcg_gen_helper_1_1(do_yield, t0, t0);
8089 gen_store_gpr(t0, rd);
8093 #if defined(TARGET_MIPS64)
8094 case OPC_DEXTM ... OPC_DEXT:
8095 case OPC_DINSM ... OPC_DINS:
8096 check_insn(env, ctx, ISA_MIPS64R2);
8098 gen_bitops(ctx, op1, rt, rs, sa, rd);
8101 check_insn(env, ctx, ISA_MIPS64R2);
8103 op2 = MASK_DBSHFL(ctx->opcode);
8105 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8106 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8110 gen_load_gpr(t1, rt);
8111 tcg_gen_helper_1_1(do_dsbh, t0, t1);
8114 gen_load_gpr(t1, rt);
8115 tcg_gen_helper_1_1(do_dshd, t0, t1);
8117 default: /* Invalid */
8118 MIPS_INVAL("dbshfl");
8119 generate_exception(ctx, EXCP_RI);
8122 gen_store_gpr(t0, rd);
8128 default: /* Invalid */
8129 MIPS_INVAL("special3");
8130 generate_exception(ctx, EXCP_RI);
8135 op1 = MASK_REGIMM(ctx->opcode);
8137 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
8138 case OPC_BLTZAL ... OPC_BGEZALL:
8139 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
8141 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
8143 gen_trap(ctx, op1, rs, -1, imm);
8146 check_insn(env, ctx, ISA_MIPS32R2);
8149 default: /* Invalid */
8150 MIPS_INVAL("regimm");
8151 generate_exception(ctx, EXCP_RI);
8156 check_cp0_enabled(ctx);
8157 op1 = MASK_CP0(ctx->opcode);
8163 #if defined(TARGET_MIPS64)
8167 #ifndef CONFIG_USER_ONLY
8168 if (!env->user_mode_only)
8169 gen_cp0(env, ctx, op1, rt, rd);
8170 #endif /* !CONFIG_USER_ONLY */
8172 case OPC_C0_FIRST ... OPC_C0_LAST:
8173 #ifndef CONFIG_USER_ONLY
8174 if (!env->user_mode_only)
8175 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
8176 #endif /* !CONFIG_USER_ONLY */
8179 #ifndef CONFIG_USER_ONLY
8180 if (!env->user_mode_only) {
8181 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8183 op2 = MASK_MFMC0(ctx->opcode);
8186 check_insn(env, ctx, ASE_MT);
8187 tcg_gen_helper_1_1(do_dmt, t0, t0);
8190 check_insn(env, ctx, ASE_MT);
8191 tcg_gen_helper_1_1(do_emt, t0, t0);
8194 check_insn(env, ctx, ASE_MT);
8195 tcg_gen_helper_1_1(do_dvpe, t0, t0);
8198 check_insn(env, ctx, ASE_MT);
8199 tcg_gen_helper_1_1(do_evpe, t0, t0);
8202 check_insn(env, ctx, ISA_MIPS32R2);
8203 save_cpu_state(ctx, 1);
8204 tcg_gen_helper_1_0(do_di, t0);
8205 /* Stop translation as we may have switched the execution mode */
8206 ctx->bstate = BS_STOP;
8209 check_insn(env, ctx, ISA_MIPS32R2);
8210 save_cpu_state(ctx, 1);
8211 tcg_gen_helper_1_0(do_ei, t0);
8212 /* Stop translation as we may have switched the execution mode */
8213 ctx->bstate = BS_STOP;
8215 default: /* Invalid */
8216 MIPS_INVAL("mfmc0");
8217 generate_exception(ctx, EXCP_RI);
8220 gen_store_gpr(t0, rt);
8223 #endif /* !CONFIG_USER_ONLY */
8226 check_insn(env, ctx, ISA_MIPS32R2);
8227 gen_load_srsgpr(rt, rd);
8230 check_insn(env, ctx, ISA_MIPS32R2);
8231 gen_store_srsgpr(rt, rd);
8235 generate_exception(ctx, EXCP_RI);
8239 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
8240 gen_arith_imm(env, ctx, op, rt, rs, imm);
8242 case OPC_J ... OPC_JAL: /* Jump */
8243 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
8244 gen_compute_branch(ctx, op, rs, rt, offset);
8246 case OPC_BEQ ... OPC_BGTZ: /* Branch */
8247 case OPC_BEQL ... OPC_BGTZL:
8248 gen_compute_branch(ctx, op, rs, rt, imm << 2);
8250 case OPC_LB ... OPC_LWR: /* Load and stores */
8251 case OPC_SB ... OPC_SW:
8255 gen_ldst(ctx, op, rt, rs, imm);
8258 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
8262 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
8266 /* Floating point (COP1). */
8271 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8272 save_cpu_state(ctx, 1);
8273 check_cp1_enabled(ctx);
8274 gen_flt_ldst(ctx, op, rt, rs, imm);
8276 generate_exception_err(ctx, EXCP_CpU, 1);
8281 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8282 save_cpu_state(ctx, 1);
8283 check_cp1_enabled(ctx);
8284 op1 = MASK_CP1(ctx->opcode);
8288 check_insn(env, ctx, ISA_MIPS32R2);
8293 gen_cp1(ctx, op1, rt, rd);
8295 #if defined(TARGET_MIPS64)
8298 check_insn(env, ctx, ISA_MIPS3);
8299 gen_cp1(ctx, op1, rt, rd);
8305 check_insn(env, ctx, ASE_MIPS3D);
8308 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8309 (rt >> 2) & 0x7, imm << 2);
8316 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8321 generate_exception (ctx, EXCP_RI);
8325 generate_exception_err(ctx, EXCP_CpU, 1);
8335 /* COP2: Not implemented. */
8336 generate_exception_err(ctx, EXCP_CpU, 2);
8340 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8341 save_cpu_state(ctx, 1);
8342 check_cp1_enabled(ctx);
8343 op1 = MASK_CP3(ctx->opcode);
8351 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8369 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8373 generate_exception (ctx, EXCP_RI);
8377 generate_exception_err(ctx, EXCP_CpU, 1);
8381 #if defined(TARGET_MIPS64)
8382 /* MIPS64 opcodes */
8384 case OPC_LDL ... OPC_LDR:
8385 case OPC_SDL ... OPC_SDR:
8390 check_insn(env, ctx, ISA_MIPS3);
8392 gen_ldst(ctx, op, rt, rs, imm);
8394 case OPC_DADDI ... OPC_DADDIU:
8395 check_insn(env, ctx, ISA_MIPS3);
8397 gen_arith_imm(env, ctx, op, rt, rs, imm);
8401 check_insn(env, ctx, ASE_MIPS16);
8402 /* MIPS16: Not implemented. */
8404 check_insn(env, ctx, ASE_MDMX);
8405 /* MDMX: Not implemented. */
8406 default: /* Invalid */
8407 MIPS_INVAL("major opcode");
8408 generate_exception(ctx, EXCP_RI);
8411 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8412 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8413 /* Branches completion */
8414 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8415 ctx->bstate = BS_BRANCH;
8416 save_cpu_state(ctx, 0);
8417 /* FIXME: Need to clear can_do_io. */
8420 /* unconditional branch */
8421 MIPS_DEBUG("unconditional branch");
8422 gen_goto_tb(ctx, 0, ctx->btarget);
8425 /* blikely taken case */
8426 MIPS_DEBUG("blikely branch taken");
8427 gen_goto_tb(ctx, 0, ctx->btarget);
8430 /* Conditional branch */
8431 MIPS_DEBUG("conditional branch");
8433 int l1 = gen_new_label();
8435 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8436 gen_goto_tb(ctx, 1, ctx->pc + 4);
8438 gen_goto_tb(ctx, 0, ctx->btarget);
8442 /* unconditional branch to register */
8443 MIPS_DEBUG("branch to register");
8444 tcg_gen_st_tl(btarget, cpu_env, offsetof(CPUState, active_tc.PC));
8448 MIPS_DEBUG("unknown branch");
8455 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8459 target_ulong pc_start;
8460 uint16_t *gen_opc_end;
8465 if (search_pc && loglevel)
8466 fprintf (logfile, "search pc %d\n", search_pc);
8469 /* Leave some spare opc slots for branch handling. */
8470 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8474 ctx.bstate = BS_NONE;
8475 /* Restore delay slot state from the tb context. */
8476 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8477 restore_cpu_state(env, &ctx);
8478 if (env->user_mode_only)
8479 ctx.mem_idx = MIPS_HFLAG_UM;
8481 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8483 max_insns = tb->cflags & CF_COUNT_MASK;
8485 max_insns = CF_COUNT_MASK;
8487 if (loglevel & CPU_LOG_TB_CPU) {
8488 fprintf(logfile, "------------------------------------------------\n");
8489 /* FIXME: This may print out stale hflags from env... */
8490 cpu_dump_state(env, logfile, fprintf, 0);
8493 #ifdef MIPS_DEBUG_DISAS
8494 if (loglevel & CPU_LOG_TB_IN_ASM)
8495 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
8496 tb, ctx.mem_idx, ctx.hflags);
8499 while (ctx.bstate == BS_NONE) {
8500 if (env->nb_breakpoints > 0) {
8501 for(j = 0; j < env->nb_breakpoints; j++) {
8502 if (env->breakpoints[j] == ctx.pc) {
8503 save_cpu_state(&ctx, 1);
8504 ctx.bstate = BS_BRANCH;
8505 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8506 /* Include the breakpoint location or the tb won't
8507 * be flushed when it must be. */
8509 goto done_generating;
8515 j = gen_opc_ptr - gen_opc_buf;
8519 gen_opc_instr_start[lj++] = 0;
8521 gen_opc_pc[lj] = ctx.pc;
8522 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8523 gen_opc_instr_start[lj] = 1;
8524 gen_opc_icount[lj] = num_insns;
8526 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8528 ctx.opcode = ldl_code(ctx.pc);
8529 decode_opc(env, &ctx);
8533 if (env->singlestep_enabled)
8536 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8539 if (gen_opc_ptr >= gen_opc_end)
8542 if (num_insns >= max_insns)
8544 #if defined (MIPS_SINGLE_STEP)
8548 if (tb->cflags & CF_LAST_IO)
8550 if (env->singlestep_enabled) {
8551 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8552 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8554 switch (ctx.bstate) {
8556 tcg_gen_helper_0_0(do_interrupt_restart);
8557 gen_goto_tb(&ctx, 0, ctx.pc);
8560 save_cpu_state(&ctx, 0);
8561 gen_goto_tb(&ctx, 0, ctx.pc);
8564 tcg_gen_helper_0_0(do_interrupt_restart);
8573 gen_icount_end(tb, num_insns);
8574 *gen_opc_ptr = INDEX_op_end;
8576 j = gen_opc_ptr - gen_opc_buf;
8579 gen_opc_instr_start[lj++] = 0;
8581 tb->size = ctx.pc - pc_start;
8582 tb->icount = num_insns;
8585 #if defined MIPS_DEBUG_DISAS
8586 if (loglevel & CPU_LOG_TB_IN_ASM)
8587 fprintf(logfile, "\n");
8589 if (loglevel & CPU_LOG_TB_IN_ASM) {
8590 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
8591 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
8592 fprintf(logfile, "\n");
8594 if (loglevel & CPU_LOG_TB_CPU) {
8595 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8600 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8602 gen_intermediate_code_internal(env, tb, 0);
8605 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8607 gen_intermediate_code_internal(env, tb, 1);
8610 static void fpu_dump_state(CPUState *env, FILE *f,
8611 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8615 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8617 #define printfpr(fp) \
8620 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8621 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8622 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8625 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8626 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8627 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8628 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8629 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8634 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8635 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8636 get_float_exception_flags(&env->active_fpu.fp_status));
8637 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8638 fpu_fprintf(f, "%3s: ", fregnames[i]);
8639 printfpr(&env->active_fpu.fpr[i]);
8645 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8646 /* Debug help: The architecture requires 32bit code to maintain proper
8647 sign-extended values on 64bit machines. */
8649 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8652 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8653 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8658 if (!SIGN_EXT_P(env->active_tc.PC))
8659 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8660 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8661 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8662 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8663 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8664 if (!SIGN_EXT_P(env->btarget))
8665 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8667 for (i = 0; i < 32; i++) {
8668 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8669 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8672 if (!SIGN_EXT_P(env->CP0_EPC))
8673 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8674 if (!SIGN_EXT_P(env->CP0_LLAddr))
8675 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8679 void cpu_dump_state (CPUState *env, FILE *f,
8680 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8685 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",
8686 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8687 env->hflags, env->btarget, env->bcond);
8688 for (i = 0; i < 32; i++) {
8690 cpu_fprintf(f, "GPR%02d:", i);
8691 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8693 cpu_fprintf(f, "\n");
8696 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8697 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8698 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8699 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8700 if (env->hflags & MIPS_HFLAG_FPU)
8701 fpu_dump_state(env, f, cpu_fprintf, flags);
8702 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8703 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8707 static void mips_tcg_init(void)
8712 /* Initialize various static tables. */
8716 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8717 bcond = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8718 offsetof(CPUState, bcond), "bcond");
8719 btarget = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8720 offsetof(CPUState, btarget), "btarget");
8721 for (i = 0; i < 32; i++)
8722 fpu_fpr32[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8723 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8725 for (i = 0; i < 32; i++)
8726 fpu_fpr64[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
8727 offsetof(CPUState, active_fpu.fpr[i]),
8729 for (i = 0; i < 32; i++)
8730 fpu_fpr32h[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8731 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8733 fpu_fcr0 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8734 offsetof(CPUState, active_fpu.fcr0),
8736 fpu_fcr31 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8737 offsetof(CPUState, active_fpu.fcr31),
8740 /* register helpers */
8742 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8748 #include "translate_init.c"
8750 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8753 const mips_def_t *def;
8755 def = cpu_mips_find_by_name(cpu_model);
8758 env = qemu_mallocz(sizeof(CPUMIPSState));
8761 env->cpu_model = def;
8764 env->cpu_model_str = cpu_model;
8770 void cpu_reset (CPUMIPSState *env)
8772 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8777 #if defined(CONFIG_USER_ONLY)
8778 env->user_mode_only = 1;
8780 if (env->user_mode_only) {
8781 env->hflags = MIPS_HFLAG_UM;
8783 if (env->hflags & MIPS_HFLAG_BMASK) {
8784 /* If the exception was raised from a delay slot,
8785 come back to the jump. */
8786 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8788 env->CP0_ErrorEPC = env->active_tc.PC;
8790 env->active_tc.PC = (int32_t)0xBFC00000;
8792 /* SMP not implemented */
8793 env->CP0_EBase = 0x80000000;
8794 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8795 /* vectored interrupts not implemented, timer on int 7,
8796 no performance counters. */
8797 env->CP0_IntCtl = 0xe0000000;
8801 for (i = 0; i < 7; i++) {
8802 env->CP0_WatchLo[i] = 0;
8803 env->CP0_WatchHi[i] = 0x80000000;
8805 env->CP0_WatchLo[7] = 0;
8806 env->CP0_WatchHi[7] = 0;
8808 /* Count register increments in debug mode, EJTAG version 1 */
8809 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8810 env->hflags = MIPS_HFLAG_CP0;
8812 env->exception_index = EXCP_NONE;
8813 cpu_mips_register(env, env->cpu_model);
8816 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8817 unsigned long searched_pc, int pc_pos, void *puc)
8819 env->active_tc.PC = gen_opc_pc[pc_pos];
8820 env->hflags &= ~MIPS_HFLAG_BMASK;
8821 env->hflags |= gen_opc_hflags[pc_pos];