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, current_fpu;
428 #include "gen-icount.h"
430 static inline void tcg_gen_helper_0_i(void *func, TCGv arg)
432 TCGv tmp = tcg_const_i32(arg);
434 tcg_gen_helper_0_1(func, tmp);
438 static inline void tcg_gen_helper_0_ii(void *func, TCGv arg1, TCGv arg2)
440 TCGv tmp1 = tcg_const_i32(arg1);
441 TCGv tmp2 = tcg_const_i32(arg2);
443 tcg_gen_helper_0_2(func, tmp1, tmp2);
448 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg1, TCGv arg2)
450 TCGv tmp = tcg_const_i32(arg2);
452 tcg_gen_helper_0_2(func, arg1, tmp);
456 static inline void tcg_gen_helper_0_2i(void *func, TCGv arg1, TCGv arg2, TCGv arg3)
458 TCGv tmp = tcg_const_i32(arg3);
460 tcg_gen_helper_0_3(func, arg1, arg2, tmp);
464 static inline void tcg_gen_helper_0_1ii(void *func, TCGv arg1, TCGv arg2, TCGv arg3)
466 TCGv tmp1 = tcg_const_i32(arg2);
467 TCGv tmp2 = tcg_const_i32(arg3);
469 tcg_gen_helper_0_3(func, arg1, tmp1, tmp2);
474 static inline void tcg_gen_helper_1_i(void *func, TCGv ret, TCGv arg)
476 TCGv tmp = tcg_const_i32(arg);
478 tcg_gen_helper_1_1(func, ret, tmp);
482 static inline void tcg_gen_helper_1_1i(void *func, TCGv ret, TCGv arg1, TCGv arg2)
484 TCGv tmp = tcg_const_i32(arg2);
486 tcg_gen_helper_1_2(func, ret, arg1, tmp);
490 static inline void tcg_gen_helper_1_1ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3)
492 TCGv tmp1 = tcg_const_i32(arg2);
493 TCGv tmp2 = tcg_const_i32(arg3);
495 tcg_gen_helper_1_3(func, ret, arg1, tmp1, tmp2);
500 static inline void tcg_gen_helper_1_2i(void *func, TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3)
502 TCGv tmp = tcg_const_i32(arg3);
504 tcg_gen_helper_1_3(func, ret, arg1, arg2, tmp);
508 static inline void tcg_gen_helper_1_2ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3, TCGv arg4)
510 TCGv tmp1 = tcg_const_i32(arg3);
511 TCGv tmp2 = tcg_const_i32(arg4);
513 tcg_gen_helper_1_4(func, ret, arg1, arg2, tmp1, tmp2);
518 typedef struct DisasContext {
519 struct TranslationBlock *tb;
520 target_ulong pc, saved_pc;
522 /* Routine used to access memory */
524 uint32_t hflags, saved_hflags;
526 target_ulong btarget;
530 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
531 * exception condition */
532 BS_STOP = 1, /* We want to stop translation for any reason */
533 BS_BRANCH = 2, /* We reached a branch condition */
534 BS_EXCP = 3, /* We reached an exception condition */
537 static const char *regnames[] =
538 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
539 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
540 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
541 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
543 static const char *fregnames[] =
544 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
545 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
546 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
547 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
549 #ifdef MIPS_DEBUG_DISAS
550 #define MIPS_DEBUG(fmt, args...) \
552 if (loglevel & CPU_LOG_TB_IN_ASM) { \
553 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
554 ctx->pc, ctx->opcode , ##args); \
558 #define MIPS_DEBUG(fmt, args...) do { } while(0)
561 #define MIPS_INVAL(op) \
563 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
564 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
567 /* General purpose registers moves. */
568 static inline void gen_load_gpr (TCGv t, int reg)
571 tcg_gen_movi_tl(t, 0);
573 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
574 sizeof(target_ulong) * reg);
577 static inline void gen_store_gpr (TCGv t, int reg)
580 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.gpr) +
581 sizeof(target_ulong) * reg);
584 /* Moves to/from HI and LO registers. */
585 static inline void gen_load_LO (TCGv t, int reg)
587 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
588 sizeof(target_ulong) * reg);
591 static inline void gen_store_LO (TCGv t, int reg)
593 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.LO) +
594 sizeof(target_ulong) * reg);
597 static inline void gen_load_HI (TCGv t, int reg)
599 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
600 sizeof(target_ulong) * reg);
603 static inline void gen_store_HI (TCGv t, int reg)
605 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, active_tc.HI) +
606 sizeof(target_ulong) * reg);
609 /* Moves to/from shadow registers. */
610 static inline void gen_load_srsgpr (int from, int to)
612 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
615 tcg_gen_movi_tl(r_tmp1, 0);
617 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
619 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
620 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
621 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
622 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
623 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
625 tcg_gen_ld_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * from);
626 tcg_temp_free(r_tmp2);
628 gen_store_gpr(r_tmp1, to);
629 tcg_temp_free(r_tmp1);
632 static inline void gen_store_srsgpr (int from, int to)
635 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
636 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
638 gen_load_gpr(r_tmp1, from);
639 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
640 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
641 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
642 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
643 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
645 tcg_gen_st_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * to);
646 tcg_temp_free(r_tmp1);
647 tcg_temp_free(r_tmp2);
651 /* Floating point register moves. */
652 static inline void gen_load_fpr32 (TCGv t, int reg)
654 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
657 static inline void gen_store_fpr32 (TCGv t, int reg)
659 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
662 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
664 if (ctx->hflags & MIPS_HFLAG_F64) {
665 tcg_gen_ld_i64(t, current_fpu, 8 * reg);
667 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
668 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
670 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
671 tcg_gen_extu_i32_i64(t, r_tmp1);
672 tcg_gen_shli_i64(t, t, 32);
673 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
674 tcg_gen_extu_i32_i64(r_tmp2, r_tmp1);
675 tcg_gen_or_i64(t, t, r_tmp2);
676 tcg_temp_free(r_tmp1);
677 tcg_temp_free(r_tmp2);
681 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
683 if (ctx->hflags & MIPS_HFLAG_F64) {
684 tcg_gen_st_i64(t, current_fpu, 8 * reg);
686 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
688 tcg_gen_trunc_i64_i32(r_tmp, t);
689 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
690 tcg_gen_shri_i64(t, t, 32);
691 tcg_gen_trunc_i64_i32(r_tmp, t);
692 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
693 tcg_temp_free(r_tmp);
697 static inline void gen_load_fpr32h (TCGv t, int reg)
699 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
702 static inline void gen_store_fpr32h (TCGv t, int reg)
704 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
707 static inline void get_fp_cond (TCGv t)
709 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
710 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
712 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
713 tcg_gen_shri_i32(r_tmp2, r_tmp1, 24);
714 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
715 tcg_gen_shri_i32(r_tmp1, r_tmp1, 23);
716 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
717 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
718 tcg_temp_free(r_tmp1);
719 tcg_temp_free(r_tmp2);
722 typedef void (fcmp_fun32)(uint32_t, uint32_t, int);
723 typedef void (fcmp_fun64)(uint64_t, uint64_t, int);
725 #define FOP_CONDS(fcmp_fun, type, arg0, arg1, fmt) \
726 static fcmp_fun * fcmp ## type ## _ ## fmt ## _table[16] = { \
727 do_cmp ## type ## _ ## fmt ## _f, \
728 do_cmp ## type ## _ ## fmt ## _un, \
729 do_cmp ## type ## _ ## fmt ## _eq, \
730 do_cmp ## type ## _ ## fmt ## _ueq, \
731 do_cmp ## type ## _ ## fmt ## _olt, \
732 do_cmp ## type ## _ ## fmt ## _ult, \
733 do_cmp ## type ## _ ## fmt ## _ole, \
734 do_cmp ## type ## _ ## fmt ## _ule, \
735 do_cmp ## type ## _ ## fmt ## _sf, \
736 do_cmp ## type ## _ ## fmt ## _ngle, \
737 do_cmp ## type ## _ ## fmt ## _seq, \
738 do_cmp ## type ## _ ## fmt ## _ngl, \
739 do_cmp ## type ## _ ## fmt ## _lt, \
740 do_cmp ## type ## _ ## fmt ## _nge, \
741 do_cmp ## type ## _ ## fmt ## _le, \
742 do_cmp ## type ## _ ## fmt ## _ngt, \
744 static inline void gen_cmp ## type ## _ ## fmt(int n, arg0 a, arg1 b, int cc) \
746 tcg_gen_helper_0_2i(fcmp ## type ## _ ## fmt ## _table[n], a, b, cc); \
749 FOP_CONDS(fcmp_fun64, , uint64_t, uint64_t, d)
750 FOP_CONDS(fcmp_fun64, abs, uint64_t, uint64_t, d)
751 FOP_CONDS(fcmp_fun32, , uint32_t, uint32_t, s)
752 FOP_CONDS(fcmp_fun32, abs, uint32_t, uint32_t, s)
753 FOP_CONDS(fcmp_fun64, , uint64_t, uint64_t, ps)
754 FOP_CONDS(fcmp_fun64, abs, uint64_t, uint64_t, ps)
758 #define OP_COND(name, cond) \
759 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
761 int l1 = gen_new_label(); \
762 int l2 = gen_new_label(); \
764 tcg_gen_brcond_tl(cond, t0, t1, l1); \
765 tcg_gen_movi_tl(t0, 0); \
768 tcg_gen_movi_tl(t0, 1); \
771 OP_COND(eq, TCG_COND_EQ);
772 OP_COND(ne, TCG_COND_NE);
773 OP_COND(ge, TCG_COND_GE);
774 OP_COND(geu, TCG_COND_GEU);
775 OP_COND(lt, TCG_COND_LT);
776 OP_COND(ltu, TCG_COND_LTU);
779 #define OP_CONDI(name, cond) \
780 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
782 int l1 = gen_new_label(); \
783 int l2 = gen_new_label(); \
785 tcg_gen_brcondi_tl(cond, t, val, l1); \
786 tcg_gen_movi_tl(t, 0); \
789 tcg_gen_movi_tl(t, 1); \
792 OP_CONDI(lti, TCG_COND_LT);
793 OP_CONDI(ltiu, TCG_COND_LTU);
796 #define OP_CONDZ(name, cond) \
797 static inline void glue(gen_op_, name) (TCGv t) \
799 int l1 = gen_new_label(); \
800 int l2 = gen_new_label(); \
802 tcg_gen_brcondi_tl(cond, t, 0, l1); \
803 tcg_gen_movi_tl(t, 0); \
806 tcg_gen_movi_tl(t, 1); \
809 OP_CONDZ(gez, TCG_COND_GE);
810 OP_CONDZ(gtz, TCG_COND_GT);
811 OP_CONDZ(lez, TCG_COND_LE);
812 OP_CONDZ(ltz, TCG_COND_LT);
815 static inline void gen_save_pc(target_ulong pc)
817 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
819 tcg_gen_movi_tl(r_tmp, pc);
820 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, active_tc.PC));
821 tcg_temp_free(r_tmp);
824 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
826 #if defined MIPS_DEBUG_DISAS
827 if (loglevel & CPU_LOG_TB_IN_ASM) {
828 fprintf(logfile, "hflags %08x saved %08x\n",
829 ctx->hflags, ctx->saved_hflags);
832 if (do_save_pc && ctx->pc != ctx->saved_pc) {
833 gen_save_pc(ctx->pc);
834 ctx->saved_pc = ctx->pc;
836 if (ctx->hflags != ctx->saved_hflags) {
837 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
839 tcg_gen_movi_i32(r_tmp, ctx->hflags);
840 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
841 tcg_temp_free(r_tmp);
842 ctx->saved_hflags = ctx->hflags;
843 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
849 tcg_gen_movi_tl(btarget, ctx->btarget);
855 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
857 ctx->saved_hflags = ctx->hflags;
858 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
864 ctx->btarget = env->btarget;
870 generate_exception_err (DisasContext *ctx, int excp, int err)
872 save_cpu_state(ctx, 1);
873 tcg_gen_helper_0_ii(do_raise_exception_err, excp, err);
874 tcg_gen_helper_0_0(do_interrupt_restart);
879 generate_exception (DisasContext *ctx, int excp)
881 save_cpu_state(ctx, 1);
882 tcg_gen_helper_0_i(do_raise_exception, excp);
883 tcg_gen_helper_0_0(do_interrupt_restart);
887 /* Addresses computation */
888 static inline void gen_op_addr_add (TCGv t0, TCGv t1)
890 tcg_gen_add_tl(t0, t0, t1);
892 #if defined(TARGET_MIPS64)
893 /* For compatibility with 32-bit code, data reference in user mode
894 with Status_UX = 0 should be casted to 32-bit and sign extended.
895 See the MIPS64 PRA manual, section 4.10. */
897 int l1 = gen_new_label();
898 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
900 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
901 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
902 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
903 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
904 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
905 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
906 tcg_temp_free(r_tmp);
907 tcg_gen_ext32s_i64(t0, t0);
913 static inline void check_cp0_enabled(DisasContext *ctx)
915 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
916 generate_exception_err(ctx, EXCP_CpU, 1);
919 static inline void check_cp1_enabled(DisasContext *ctx)
921 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
922 generate_exception_err(ctx, EXCP_CpU, 1);
925 /* Verify that the processor is running with COP1X instructions enabled.
926 This is associated with the nabla symbol in the MIPS32 and MIPS64
929 static inline void check_cop1x(DisasContext *ctx)
931 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
932 generate_exception(ctx, EXCP_RI);
935 /* Verify that the processor is running with 64-bit floating-point
936 operations enabled. */
938 static inline void check_cp1_64bitmode(DisasContext *ctx)
940 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
941 generate_exception(ctx, EXCP_RI);
945 * Verify if floating point register is valid; an operation is not defined
946 * if bit 0 of any register specification is set and the FR bit in the
947 * Status register equals zero, since the register numbers specify an
948 * even-odd pair of adjacent coprocessor general registers. When the FR bit
949 * in the Status register equals one, both even and odd register numbers
950 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
952 * Multiple 64 bit wide registers can be checked by calling
953 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
955 static inline void check_cp1_registers(DisasContext *ctx, int regs)
957 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
958 generate_exception(ctx, EXCP_RI);
961 /* This code generates a "reserved instruction" exception if the
962 CPU does not support the instruction set corresponding to flags. */
963 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
965 if (unlikely(!(env->insn_flags & flags)))
966 generate_exception(ctx, EXCP_RI);
969 /* This code generates a "reserved instruction" exception if 64-bit
970 instructions are not enabled. */
971 static inline void check_mips_64(DisasContext *ctx)
973 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
974 generate_exception(ctx, EXCP_RI);
977 /* load/store instructions. */
978 #define OP_LD(insn,fname) \
979 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
981 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
988 #if defined(TARGET_MIPS64)
994 #define OP_ST(insn,fname) \
995 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
997 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1002 #if defined(TARGET_MIPS64)
1007 #define OP_LD_ATOMIC(insn,fname) \
1008 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1010 tcg_gen_mov_tl(t1, t0); \
1011 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1012 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1014 OP_LD_ATOMIC(ll,ld32s);
1015 #if defined(TARGET_MIPS64)
1016 OP_LD_ATOMIC(lld,ld64);
1020 #define OP_ST_ATOMIC(insn,fname,almask) \
1021 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1023 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1024 int l1 = gen_new_label(); \
1025 int l2 = gen_new_label(); \
1026 int l3 = gen_new_label(); \
1028 tcg_gen_andi_tl(r_tmp, t0, almask); \
1029 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1030 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1031 generate_exception(ctx, EXCP_AdES); \
1032 gen_set_label(l1); \
1033 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1034 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1035 tcg_temp_free(r_tmp); \
1036 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1037 tcg_gen_movi_tl(t0, 1); \
1039 gen_set_label(l2); \
1040 tcg_gen_movi_tl(t0, 0); \
1041 gen_set_label(l3); \
1043 OP_ST_ATOMIC(sc,st32,0x3);
1044 #if defined(TARGET_MIPS64)
1045 OP_ST_ATOMIC(scd,st64,0x7);
1049 /* Load and store */
1050 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1051 int base, int16_t offset)
1053 const char *opn = "ldst";
1054 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1055 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1058 tcg_gen_movi_tl(t0, offset);
1059 } else if (offset == 0) {
1060 gen_load_gpr(t0, base);
1062 gen_load_gpr(t0, base);
1063 tcg_gen_movi_tl(t1, offset);
1064 gen_op_addr_add(t0, t1);
1066 /* Don't do NOP if destination is zero: we must perform the actual
1069 #if defined(TARGET_MIPS64)
1071 op_ldst_lwu(t0, ctx);
1072 gen_store_gpr(t0, rt);
1076 op_ldst_ld(t0, ctx);
1077 gen_store_gpr(t0, rt);
1081 op_ldst_lld(t0, t1, ctx);
1082 gen_store_gpr(t0, rt);
1086 gen_load_gpr(t1, rt);
1087 op_ldst_sd(t0, t1, ctx);
1091 save_cpu_state(ctx, 1);
1092 gen_load_gpr(t1, rt);
1093 op_ldst_scd(t0, t1, ctx);
1094 gen_store_gpr(t0, rt);
1098 save_cpu_state(ctx, 1);
1099 gen_load_gpr(t1, rt);
1100 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1101 gen_store_gpr(t1, rt);
1105 save_cpu_state(ctx, 1);
1106 gen_load_gpr(t1, rt);
1107 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1111 save_cpu_state(ctx, 1);
1112 gen_load_gpr(t1, rt);
1113 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1114 gen_store_gpr(t1, rt);
1118 save_cpu_state(ctx, 1);
1119 gen_load_gpr(t1, rt);
1120 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1125 op_ldst_lw(t0, ctx);
1126 gen_store_gpr(t0, rt);
1130 gen_load_gpr(t1, rt);
1131 op_ldst_sw(t0, t1, ctx);
1135 op_ldst_lh(t0, ctx);
1136 gen_store_gpr(t0, rt);
1140 gen_load_gpr(t1, rt);
1141 op_ldst_sh(t0, t1, ctx);
1145 op_ldst_lhu(t0, ctx);
1146 gen_store_gpr(t0, rt);
1150 op_ldst_lb(t0, ctx);
1151 gen_store_gpr(t0, rt);
1155 gen_load_gpr(t1, rt);
1156 op_ldst_sb(t0, t1, ctx);
1160 op_ldst_lbu(t0, ctx);
1161 gen_store_gpr(t0, rt);
1165 save_cpu_state(ctx, 1);
1166 gen_load_gpr(t1, rt);
1167 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1168 gen_store_gpr(t1, rt);
1172 save_cpu_state(ctx, 1);
1173 gen_load_gpr(t1, rt);
1174 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1178 save_cpu_state(ctx, 1);
1179 gen_load_gpr(t1, rt);
1180 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1181 gen_store_gpr(t1, rt);
1185 save_cpu_state(ctx, 1);
1186 gen_load_gpr(t1, rt);
1187 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1191 op_ldst_ll(t0, t1, ctx);
1192 gen_store_gpr(t0, rt);
1196 save_cpu_state(ctx, 1);
1197 gen_load_gpr(t1, rt);
1198 op_ldst_sc(t0, t1, ctx);
1199 gen_store_gpr(t0, rt);
1204 generate_exception(ctx, EXCP_RI);
1207 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1213 /* Load and store */
1214 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1215 int base, int16_t offset)
1217 const char *opn = "flt_ldst";
1218 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1221 tcg_gen_movi_tl(t0, offset);
1222 } else if (offset == 0) {
1223 gen_load_gpr(t0, base);
1225 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1227 gen_load_gpr(t0, base);
1228 tcg_gen_movi_tl(t1, offset);
1229 gen_op_addr_add(t0, t1);
1232 /* Don't do NOP if destination is zero: we must perform the actual
1237 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1239 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
1240 gen_store_fpr32(fp0, ft);
1247 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1249 gen_load_fpr32(fp0, ft);
1250 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
1257 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1259 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1260 gen_store_fpr64(ctx, fp0, ft);
1267 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1269 gen_load_fpr64(ctx, fp0, ft);
1270 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1277 generate_exception(ctx, EXCP_RI);
1280 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1285 /* Arithmetic with immediate operand */
1286 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1287 int rt, int rs, int16_t imm)
1290 const char *opn = "imm arith";
1291 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1293 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1294 /* If no destination, treat it as a NOP.
1295 For addi, we must generate the overflow exception when needed. */
1299 uimm = (uint16_t)imm;
1303 #if defined(TARGET_MIPS64)
1309 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1314 gen_load_gpr(t0, rs);
1317 tcg_gen_movi_tl(t0, imm << 16);
1322 #if defined(TARGET_MIPS64)
1331 gen_load_gpr(t0, rs);
1337 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1338 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1339 int l1 = gen_new_label();
1341 save_cpu_state(ctx, 1);
1342 tcg_gen_ext32s_tl(r_tmp1, t0);
1343 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1345 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1346 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1347 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1348 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1349 tcg_temp_free(r_tmp2);
1350 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1351 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1352 tcg_temp_free(r_tmp1);
1353 /* operands of same sign, result different sign */
1354 generate_exception(ctx, EXCP_OVERFLOW);
1357 tcg_gen_ext32s_tl(t0, t0);
1362 tcg_gen_ext32s_tl(t0, t0);
1363 tcg_gen_addi_tl(t0, t0, uimm);
1364 tcg_gen_ext32s_tl(t0, t0);
1367 #if defined(TARGET_MIPS64)
1370 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1371 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1372 int l1 = gen_new_label();
1374 save_cpu_state(ctx, 1);
1375 tcg_gen_mov_tl(r_tmp1, t0);
1376 tcg_gen_addi_tl(t0, t0, uimm);
1378 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1379 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1380 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1381 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1382 tcg_temp_free(r_tmp2);
1383 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1384 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1385 tcg_temp_free(r_tmp1);
1386 /* operands of same sign, result different sign */
1387 generate_exception(ctx, EXCP_OVERFLOW);
1393 tcg_gen_addi_tl(t0, t0, uimm);
1398 gen_op_lti(t0, uimm);
1402 gen_op_ltiu(t0, uimm);
1406 tcg_gen_andi_tl(t0, t0, uimm);
1410 tcg_gen_ori_tl(t0, t0, uimm);
1414 tcg_gen_xori_tl(t0, t0, uimm);
1421 tcg_gen_ext32u_tl(t0, t0);
1422 tcg_gen_shli_tl(t0, t0, uimm);
1423 tcg_gen_ext32s_tl(t0, t0);
1427 tcg_gen_ext32s_tl(t0, t0);
1428 tcg_gen_sari_tl(t0, t0, uimm);
1429 tcg_gen_ext32s_tl(t0, t0);
1433 switch ((ctx->opcode >> 21) & 0x1f) {
1435 tcg_gen_ext32u_tl(t0, t0);
1436 tcg_gen_shri_tl(t0, t0, uimm);
1437 tcg_gen_ext32s_tl(t0, t0);
1441 /* rotr is decoded as srl on non-R2 CPUs */
1442 if (env->insn_flags & ISA_MIPS32R2) {
1444 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1445 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1447 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1448 tcg_gen_movi_i32(r_tmp2, 0x20);
1449 tcg_gen_subi_i32(r_tmp2, r_tmp2, uimm);
1450 tcg_gen_shl_i32(r_tmp2, r_tmp1, r_tmp2);
1451 tcg_gen_shri_i32(r_tmp1, r_tmp1, uimm);
1452 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp2);
1453 tcg_gen_ext_i32_tl(t0, r_tmp1);
1454 tcg_temp_free(r_tmp1);
1455 tcg_temp_free(r_tmp2);
1459 tcg_gen_ext32u_tl(t0, t0);
1460 tcg_gen_shri_tl(t0, t0, uimm);
1461 tcg_gen_ext32s_tl(t0, t0);
1466 MIPS_INVAL("invalid srl flag");
1467 generate_exception(ctx, EXCP_RI);
1471 #if defined(TARGET_MIPS64)
1473 tcg_gen_shli_tl(t0, t0, uimm);
1477 tcg_gen_sari_tl(t0, t0, uimm);
1481 switch ((ctx->opcode >> 21) & 0x1f) {
1483 tcg_gen_shri_tl(t0, t0, uimm);
1487 /* drotr is decoded as dsrl on non-R2 CPUs */
1488 if (env->insn_flags & ISA_MIPS32R2) {
1490 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1492 tcg_gen_movi_tl(r_tmp1, 0x40);
1493 tcg_gen_subi_tl(r_tmp1, r_tmp1, uimm);
1494 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1495 tcg_gen_shri_tl(t0, t0, uimm);
1496 tcg_gen_or_tl(t0, t0, r_tmp1);
1497 tcg_temp_free(r_tmp1);
1501 tcg_gen_shri_tl(t0, t0, uimm);
1506 MIPS_INVAL("invalid dsrl flag");
1507 generate_exception(ctx, EXCP_RI);
1512 tcg_gen_shli_tl(t0, t0, uimm + 32);
1516 tcg_gen_sari_tl(t0, t0, uimm + 32);
1520 switch ((ctx->opcode >> 21) & 0x1f) {
1522 tcg_gen_shri_tl(t0, t0, uimm + 32);
1526 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1527 if (env->insn_flags & ISA_MIPS32R2) {
1528 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1529 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1531 tcg_gen_movi_tl(r_tmp1, 0x40);
1532 tcg_gen_movi_tl(r_tmp2, 32);
1533 tcg_gen_addi_tl(r_tmp2, r_tmp2, uimm);
1534 tcg_gen_sub_tl(r_tmp1, r_tmp1, r_tmp2);
1535 tcg_gen_shl_tl(r_tmp1, t0, r_tmp1);
1536 tcg_gen_shr_tl(t0, t0, r_tmp2);
1537 tcg_gen_or_tl(t0, t0, r_tmp1);
1538 tcg_temp_free(r_tmp1);
1539 tcg_temp_free(r_tmp2);
1542 tcg_gen_shri_tl(t0, t0, uimm + 32);
1547 MIPS_INVAL("invalid dsrl32 flag");
1548 generate_exception(ctx, EXCP_RI);
1555 generate_exception(ctx, EXCP_RI);
1558 gen_store_gpr(t0, rt);
1559 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1565 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1566 int rd, int rs, int rt)
1568 const char *opn = "arith";
1569 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1570 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1572 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1573 && opc != OPC_DADD && opc != OPC_DSUB) {
1574 /* If no destination, treat it as a NOP.
1575 For add & sub, we must generate the overflow exception when needed. */
1579 gen_load_gpr(t0, rs);
1580 /* Specialcase the conventional move operation. */
1581 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1582 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1583 gen_store_gpr(t0, rd);
1586 gen_load_gpr(t1, rt);
1590 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1591 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1592 int l1 = gen_new_label();
1594 save_cpu_state(ctx, 1);
1595 tcg_gen_ext32s_tl(r_tmp1, t0);
1596 tcg_gen_ext32s_tl(r_tmp2, t1);
1597 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1599 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1600 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1601 tcg_gen_xor_tl(r_tmp2, t0, t1);
1602 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1603 tcg_temp_free(r_tmp2);
1604 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1605 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1606 tcg_temp_free(r_tmp1);
1607 /* operands of same sign, result different sign */
1608 generate_exception(ctx, EXCP_OVERFLOW);
1611 tcg_gen_ext32s_tl(t0, t0);
1616 tcg_gen_ext32s_tl(t0, t0);
1617 tcg_gen_ext32s_tl(t1, t1);
1618 tcg_gen_add_tl(t0, t0, t1);
1619 tcg_gen_ext32s_tl(t0, t0);
1624 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1625 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1626 int l1 = gen_new_label();
1628 save_cpu_state(ctx, 1);
1629 tcg_gen_ext32s_tl(r_tmp1, t0);
1630 tcg_gen_ext32s_tl(r_tmp2, t1);
1631 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1633 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1634 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1635 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1636 tcg_temp_free(r_tmp2);
1637 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1638 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1639 tcg_temp_free(r_tmp1);
1640 /* operands of different sign, first operand and result different sign */
1641 generate_exception(ctx, EXCP_OVERFLOW);
1644 tcg_gen_ext32s_tl(t0, t0);
1649 tcg_gen_ext32s_tl(t0, t0);
1650 tcg_gen_ext32s_tl(t1, t1);
1651 tcg_gen_sub_tl(t0, t0, t1);
1652 tcg_gen_ext32s_tl(t0, t0);
1655 #if defined(TARGET_MIPS64)
1658 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1659 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1660 int l1 = gen_new_label();
1662 save_cpu_state(ctx, 1);
1663 tcg_gen_mov_tl(r_tmp1, t0);
1664 tcg_gen_add_tl(t0, t0, t1);
1666 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1667 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1668 tcg_gen_xor_tl(r_tmp2, t0, t1);
1669 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1670 tcg_temp_free(r_tmp2);
1671 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1672 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1673 tcg_temp_free(r_tmp1);
1674 /* operands of same sign, result different sign */
1675 generate_exception(ctx, EXCP_OVERFLOW);
1681 tcg_gen_add_tl(t0, t0, t1);
1686 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1687 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1688 int l1 = gen_new_label();
1690 save_cpu_state(ctx, 1);
1691 tcg_gen_mov_tl(r_tmp1, t0);
1692 tcg_gen_sub_tl(t0, t0, t1);
1694 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1695 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1696 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1697 tcg_temp_free(r_tmp2);
1698 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1699 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1700 tcg_temp_free(r_tmp1);
1701 /* operands of different sign, first operand and result different sign */
1702 generate_exception(ctx, EXCP_OVERFLOW);
1708 tcg_gen_sub_tl(t0, t0, t1);
1721 tcg_gen_and_tl(t0, t0, t1);
1725 tcg_gen_or_tl(t0, t0, t1);
1726 tcg_gen_not_tl(t0, t0);
1730 tcg_gen_or_tl(t0, t0, t1);
1734 tcg_gen_xor_tl(t0, t0, t1);
1738 tcg_gen_ext32s_tl(t0, t0);
1739 tcg_gen_ext32s_tl(t1, t1);
1740 tcg_gen_mul_tl(t0, t0, t1);
1741 tcg_gen_ext32s_tl(t0, t0);
1746 int l1 = gen_new_label();
1748 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1749 gen_store_gpr(t0, rd);
1756 int l1 = gen_new_label();
1758 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1759 gen_store_gpr(t0, rd);
1765 tcg_gen_ext32u_tl(t0, t0);
1766 tcg_gen_ext32u_tl(t1, t1);
1767 tcg_gen_andi_tl(t0, t0, 0x1f);
1768 tcg_gen_shl_tl(t0, t1, t0);
1769 tcg_gen_ext32s_tl(t0, t0);
1773 tcg_gen_ext32s_tl(t1, t1);
1774 tcg_gen_andi_tl(t0, t0, 0x1f);
1775 tcg_gen_sar_tl(t0, t1, t0);
1776 tcg_gen_ext32s_tl(t0, t0);
1780 switch ((ctx->opcode >> 6) & 0x1f) {
1782 tcg_gen_ext32u_tl(t1, t1);
1783 tcg_gen_andi_tl(t0, t0, 0x1f);
1784 tcg_gen_shr_tl(t0, t1, t0);
1785 tcg_gen_ext32s_tl(t0, t0);
1789 /* rotrv is decoded as srlv on non-R2 CPUs */
1790 if (env->insn_flags & ISA_MIPS32R2) {
1791 int l1 = gen_new_label();
1792 int l2 = gen_new_label();
1794 tcg_gen_andi_tl(t0, t0, 0x1f);
1795 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1797 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1798 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1799 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1801 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1802 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1803 tcg_gen_movi_i32(r_tmp3, 0x20);
1804 tcg_gen_sub_i32(r_tmp3, r_tmp3, r_tmp1);
1805 tcg_gen_shl_i32(r_tmp3, r_tmp2, r_tmp3);
1806 tcg_gen_shr_i32(r_tmp1, r_tmp2, r_tmp1);
1807 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp3);
1808 tcg_gen_ext_i32_tl(t0, r_tmp1);
1809 tcg_temp_free(r_tmp1);
1810 tcg_temp_free(r_tmp2);
1811 tcg_temp_free(r_tmp3);
1815 tcg_gen_mov_tl(t0, t1);
1819 tcg_gen_ext32u_tl(t1, t1);
1820 tcg_gen_andi_tl(t0, t0, 0x1f);
1821 tcg_gen_shr_tl(t0, t1, t0);
1822 tcg_gen_ext32s_tl(t0, t0);
1827 MIPS_INVAL("invalid srlv flag");
1828 generate_exception(ctx, EXCP_RI);
1832 #if defined(TARGET_MIPS64)
1834 tcg_gen_andi_tl(t0, t0, 0x3f);
1835 tcg_gen_shl_tl(t0, t1, t0);
1839 tcg_gen_andi_tl(t0, t0, 0x3f);
1840 tcg_gen_sar_tl(t0, t1, t0);
1844 switch ((ctx->opcode >> 6) & 0x1f) {
1846 tcg_gen_andi_tl(t0, t0, 0x3f);
1847 tcg_gen_shr_tl(t0, t1, t0);
1851 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1852 if (env->insn_flags & ISA_MIPS32R2) {
1853 int l1 = gen_new_label();
1854 int l2 = gen_new_label();
1856 tcg_gen_andi_tl(t0, t0, 0x3f);
1857 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1859 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1861 tcg_gen_movi_tl(r_tmp1, 0x40);
1862 tcg_gen_sub_tl(r_tmp1, r_tmp1, t0);
1863 tcg_gen_shl_tl(r_tmp1, t1, r_tmp1);
1864 tcg_gen_shr_tl(t0, t1, t0);
1865 tcg_gen_or_tl(t0, t0, r_tmp1);
1866 tcg_temp_free(r_tmp1);
1870 tcg_gen_mov_tl(t0, t1);
1874 tcg_gen_andi_tl(t0, t0, 0x3f);
1875 tcg_gen_shr_tl(t0, t1, t0);
1880 MIPS_INVAL("invalid dsrlv flag");
1881 generate_exception(ctx, EXCP_RI);
1888 generate_exception(ctx, EXCP_RI);
1891 gen_store_gpr(t0, rd);
1893 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1899 /* Arithmetic on HI/LO registers */
1900 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1902 const char *opn = "hilo";
1903 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1905 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1913 gen_store_gpr(t0, reg);
1918 gen_store_gpr(t0, reg);
1922 gen_load_gpr(t0, reg);
1923 gen_store_HI(t0, 0);
1927 gen_load_gpr(t0, reg);
1928 gen_store_LO(t0, 0);
1933 generate_exception(ctx, EXCP_RI);
1936 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1941 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1944 const char *opn = "mul/div";
1945 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1946 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1948 gen_load_gpr(t0, rs);
1949 gen_load_gpr(t1, rt);
1953 int l1 = gen_new_label();
1955 tcg_gen_ext32s_tl(t0, t0);
1956 tcg_gen_ext32s_tl(t1, t1);
1957 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1959 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1960 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1961 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1963 tcg_gen_ext_tl_i64(r_tmp1, t0);
1964 tcg_gen_ext_tl_i64(r_tmp2, t1);
1965 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1966 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1967 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1968 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1969 tcg_temp_free(r_tmp1);
1970 tcg_temp_free(r_tmp2);
1971 tcg_temp_free(r_tmp3);
1972 tcg_gen_ext32s_tl(t0, t0);
1973 tcg_gen_ext32s_tl(t1, t1);
1974 gen_store_LO(t0, 0);
1975 gen_store_HI(t1, 0);
1983 int l1 = gen_new_label();
1985 tcg_gen_ext32s_tl(t1, t1);
1986 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1988 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1989 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1990 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1992 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1993 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1994 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1995 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1996 tcg_gen_ext_i32_tl(t0, r_tmp3);
1997 tcg_gen_ext_i32_tl(t1, r_tmp1);
1998 tcg_temp_free(r_tmp1);
1999 tcg_temp_free(r_tmp2);
2000 tcg_temp_free(r_tmp3);
2001 gen_store_LO(t0, 0);
2002 gen_store_HI(t1, 0);
2010 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2011 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2013 tcg_gen_ext32s_tl(t0, t0);
2014 tcg_gen_ext32s_tl(t1, t1);
2015 tcg_gen_ext_tl_i64(r_tmp1, t0);
2016 tcg_gen_ext_tl_i64(r_tmp2, t1);
2017 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2018 tcg_temp_free(r_tmp2);
2019 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2020 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2021 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2022 tcg_temp_free(r_tmp1);
2023 tcg_gen_ext32s_tl(t0, t0);
2024 tcg_gen_ext32s_tl(t1, t1);
2025 gen_store_LO(t0, 0);
2026 gen_store_HI(t1, 0);
2032 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2033 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2035 tcg_gen_ext32u_tl(t0, t0);
2036 tcg_gen_ext32u_tl(t1, t1);
2037 tcg_gen_extu_tl_i64(r_tmp1, t0);
2038 tcg_gen_extu_tl_i64(r_tmp2, t1);
2039 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2040 tcg_temp_free(r_tmp2);
2041 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2042 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2043 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2044 tcg_temp_free(r_tmp1);
2045 tcg_gen_ext32s_tl(t0, t0);
2046 tcg_gen_ext32s_tl(t1, t1);
2047 gen_store_LO(t0, 0);
2048 gen_store_HI(t1, 0);
2052 #if defined(TARGET_MIPS64)
2055 int l1 = gen_new_label();
2057 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2059 int l2 = gen_new_label();
2061 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2062 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2064 tcg_gen_movi_tl(t1, 0);
2065 gen_store_LO(t0, 0);
2066 gen_store_HI(t1, 0);
2071 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2072 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2074 tcg_gen_div_i64(r_tmp1, t0, t1);
2075 tcg_gen_rem_i64(r_tmp2, t0, t1);
2076 gen_store_LO(r_tmp1, 0);
2077 gen_store_HI(r_tmp2, 0);
2078 tcg_temp_free(r_tmp1);
2079 tcg_temp_free(r_tmp2);
2088 int l1 = gen_new_label();
2090 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2092 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2093 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2095 tcg_gen_divu_i64(r_tmp1, t0, t1);
2096 tcg_gen_remu_i64(r_tmp2, t0, t1);
2097 tcg_temp_free(r_tmp1);
2098 tcg_temp_free(r_tmp2);
2099 gen_store_LO(r_tmp1, 0);
2100 gen_store_HI(r_tmp2, 0);
2107 tcg_gen_helper_0_2(do_dmult, t0, t1);
2111 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2117 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2118 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2119 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2121 tcg_gen_ext32s_tl(t0, t0);
2122 tcg_gen_ext32s_tl(t1, t1);
2123 tcg_gen_ext_tl_i64(r_tmp1, t0);
2124 tcg_gen_ext_tl_i64(r_tmp2, t1);
2125 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2128 tcg_gen_extu_tl_i64(r_tmp2, t0);
2129 tcg_gen_extu_tl_i64(r_tmp3, t1);
2130 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2131 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2132 tcg_temp_free(r_tmp3);
2133 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2134 tcg_temp_free(r_tmp2);
2135 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2136 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2137 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2138 tcg_temp_free(r_tmp1);
2139 tcg_gen_ext32s_tl(t0, t0);
2140 tcg_gen_ext32s_tl(t1, t1);
2141 gen_store_LO(t0, 0);
2142 gen_store_HI(t1, 0);
2148 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2149 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2150 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2152 tcg_gen_ext32u_tl(t0, t0);
2153 tcg_gen_ext32u_tl(t1, t1);
2154 tcg_gen_extu_tl_i64(r_tmp1, t0);
2155 tcg_gen_extu_tl_i64(r_tmp2, t1);
2156 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2159 tcg_gen_extu_tl_i64(r_tmp2, t0);
2160 tcg_gen_extu_tl_i64(r_tmp3, t1);
2161 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2162 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2163 tcg_temp_free(r_tmp3);
2164 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2165 tcg_temp_free(r_tmp2);
2166 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2167 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2168 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2169 tcg_temp_free(r_tmp1);
2170 tcg_gen_ext32s_tl(t0, t0);
2171 tcg_gen_ext32s_tl(t1, t1);
2172 gen_store_LO(t0, 0);
2173 gen_store_HI(t1, 0);
2179 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2180 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2181 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2183 tcg_gen_ext32s_tl(t0, t0);
2184 tcg_gen_ext32s_tl(t1, t1);
2185 tcg_gen_ext_tl_i64(r_tmp1, t0);
2186 tcg_gen_ext_tl_i64(r_tmp2, t1);
2187 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2190 tcg_gen_extu_tl_i64(r_tmp2, t0);
2191 tcg_gen_extu_tl_i64(r_tmp3, t1);
2192 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2193 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2194 tcg_temp_free(r_tmp3);
2195 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2196 tcg_temp_free(r_tmp2);
2197 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2198 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2199 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2200 tcg_temp_free(r_tmp1);
2201 tcg_gen_ext32s_tl(t0, t0);
2202 tcg_gen_ext32s_tl(t1, t1);
2203 gen_store_LO(t0, 0);
2204 gen_store_HI(t1, 0);
2210 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2211 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2212 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2214 tcg_gen_ext32u_tl(t0, t0);
2215 tcg_gen_ext32u_tl(t1, t1);
2216 tcg_gen_extu_tl_i64(r_tmp1, t0);
2217 tcg_gen_extu_tl_i64(r_tmp2, t1);
2218 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2221 tcg_gen_extu_tl_i64(r_tmp2, t0);
2222 tcg_gen_extu_tl_i64(r_tmp3, t1);
2223 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2224 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2225 tcg_temp_free(r_tmp3);
2226 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2227 tcg_temp_free(r_tmp2);
2228 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2229 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2230 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2231 tcg_temp_free(r_tmp1);
2232 tcg_gen_ext32s_tl(t0, t0);
2233 tcg_gen_ext32s_tl(t1, t1);
2234 gen_store_LO(t0, 0);
2235 gen_store_HI(t1, 0);
2241 generate_exception(ctx, EXCP_RI);
2244 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2250 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2251 int rd, int rs, int rt)
2253 const char *opn = "mul vr54xx";
2254 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2255 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2257 gen_load_gpr(t0, rs);
2258 gen_load_gpr(t1, rt);
2261 case OPC_VR54XX_MULS:
2262 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2265 case OPC_VR54XX_MULSU:
2266 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2269 case OPC_VR54XX_MACC:
2270 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2273 case OPC_VR54XX_MACCU:
2274 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2277 case OPC_VR54XX_MSAC:
2278 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2281 case OPC_VR54XX_MSACU:
2282 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2285 case OPC_VR54XX_MULHI:
2286 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2289 case OPC_VR54XX_MULHIU:
2290 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2293 case OPC_VR54XX_MULSHI:
2294 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2297 case OPC_VR54XX_MULSHIU:
2298 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2301 case OPC_VR54XX_MACCHI:
2302 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2305 case OPC_VR54XX_MACCHIU:
2306 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2309 case OPC_VR54XX_MSACHI:
2310 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2313 case OPC_VR54XX_MSACHIU:
2314 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2318 MIPS_INVAL("mul vr54xx");
2319 generate_exception(ctx, EXCP_RI);
2322 gen_store_gpr(t0, rd);
2323 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2330 static void gen_cl (DisasContext *ctx, uint32_t opc,
2333 const char *opn = "CLx";
2334 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2341 gen_load_gpr(t0, rs);
2344 tcg_gen_helper_1_1(do_clo, t0, t0);
2348 tcg_gen_helper_1_1(do_clz, t0, t0);
2351 #if defined(TARGET_MIPS64)
2353 tcg_gen_helper_1_1(do_dclo, t0, t0);
2357 tcg_gen_helper_1_1(do_dclz, t0, t0);
2363 generate_exception(ctx, EXCP_RI);
2366 gen_store_gpr(t0, rd);
2367 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2374 static void gen_trap (DisasContext *ctx, uint32_t opc,
2375 int rs, int rt, int16_t imm)
2378 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2379 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2382 /* Load needed operands */
2390 /* Compare two registers */
2392 gen_load_gpr(t0, rs);
2393 gen_load_gpr(t1, rt);
2403 /* Compare register to immediate */
2404 if (rs != 0 || imm != 0) {
2405 gen_load_gpr(t0, rs);
2406 tcg_gen_movi_tl(t1, (int32_t)imm);
2413 case OPC_TEQ: /* rs == rs */
2414 case OPC_TEQI: /* r0 == 0 */
2415 case OPC_TGE: /* rs >= rs */
2416 case OPC_TGEI: /* r0 >= 0 */
2417 case OPC_TGEU: /* rs >= rs unsigned */
2418 case OPC_TGEIU: /* r0 >= 0 unsigned */
2420 tcg_gen_movi_tl(t0, 1);
2422 case OPC_TLT: /* rs < rs */
2423 case OPC_TLTI: /* r0 < 0 */
2424 case OPC_TLTU: /* rs < rs unsigned */
2425 case OPC_TLTIU: /* r0 < 0 unsigned */
2426 case OPC_TNE: /* rs != rs */
2427 case OPC_TNEI: /* r0 != 0 */
2428 /* Never trap: treat as NOP. */
2432 generate_exception(ctx, EXCP_RI);
2463 generate_exception(ctx, EXCP_RI);
2467 save_cpu_state(ctx, 1);
2469 int l1 = gen_new_label();
2471 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2472 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2475 ctx->bstate = BS_STOP;
2481 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2483 TranslationBlock *tb;
2485 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2488 tcg_gen_exit_tb((long)tb + n);
2495 /* Branches (before delay slot) */
2496 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2497 int rs, int rt, int32_t offset)
2499 target_ulong btgt = -1;
2502 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2503 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2505 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2506 #ifdef MIPS_DEBUG_DISAS
2507 if (loglevel & CPU_LOG_TB_IN_ASM) {
2509 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2513 generate_exception(ctx, EXCP_RI);
2517 /* Load needed operands */
2523 /* Compare two registers */
2525 gen_load_gpr(t0, rs);
2526 gen_load_gpr(t1, rt);
2529 btgt = ctx->pc + 4 + offset;
2543 /* Compare to zero */
2545 gen_load_gpr(t0, rs);
2548 btgt = ctx->pc + 4 + offset;
2552 /* Jump to immediate */
2553 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2557 /* Jump to register */
2558 if (offset != 0 && offset != 16) {
2559 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2560 others are reserved. */
2561 MIPS_INVAL("jump hint");
2562 generate_exception(ctx, EXCP_RI);
2565 gen_load_gpr(btarget, rs);
2568 MIPS_INVAL("branch/jump");
2569 generate_exception(ctx, EXCP_RI);
2573 /* No condition to be computed */
2575 case OPC_BEQ: /* rx == rx */
2576 case OPC_BEQL: /* rx == rx likely */
2577 case OPC_BGEZ: /* 0 >= 0 */
2578 case OPC_BGEZL: /* 0 >= 0 likely */
2579 case OPC_BLEZ: /* 0 <= 0 */
2580 case OPC_BLEZL: /* 0 <= 0 likely */
2582 ctx->hflags |= MIPS_HFLAG_B;
2583 MIPS_DEBUG("balways");
2585 case OPC_BGEZAL: /* 0 >= 0 */
2586 case OPC_BGEZALL: /* 0 >= 0 likely */
2587 /* Always take and link */
2589 ctx->hflags |= MIPS_HFLAG_B;
2590 MIPS_DEBUG("balways and link");
2592 case OPC_BNE: /* rx != rx */
2593 case OPC_BGTZ: /* 0 > 0 */
2594 case OPC_BLTZ: /* 0 < 0 */
2596 MIPS_DEBUG("bnever (NOP)");
2598 case OPC_BLTZAL: /* 0 < 0 */
2599 tcg_gen_movi_tl(t0, ctx->pc + 8);
2600 gen_store_gpr(t0, 31);
2601 MIPS_DEBUG("bnever and link");
2603 case OPC_BLTZALL: /* 0 < 0 likely */
2604 tcg_gen_movi_tl(t0, ctx->pc + 8);
2605 gen_store_gpr(t0, 31);
2606 /* Skip the instruction in the delay slot */
2607 MIPS_DEBUG("bnever, link and skip");
2610 case OPC_BNEL: /* rx != rx likely */
2611 case OPC_BGTZL: /* 0 > 0 likely */
2612 case OPC_BLTZL: /* 0 < 0 likely */
2613 /* Skip the instruction in the delay slot */
2614 MIPS_DEBUG("bnever and skip");
2618 ctx->hflags |= MIPS_HFLAG_B;
2619 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2623 ctx->hflags |= MIPS_HFLAG_B;
2624 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2627 ctx->hflags |= MIPS_HFLAG_BR;
2628 MIPS_DEBUG("jr %s", regnames[rs]);
2632 ctx->hflags |= MIPS_HFLAG_BR;
2633 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2636 MIPS_INVAL("branch/jump");
2637 generate_exception(ctx, EXCP_RI);
2644 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2645 regnames[rs], regnames[rt], btgt);
2649 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2650 regnames[rs], regnames[rt], btgt);
2654 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2655 regnames[rs], regnames[rt], btgt);
2659 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2660 regnames[rs], regnames[rt], btgt);
2664 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2668 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2672 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2678 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2682 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2686 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2690 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2694 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2698 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2702 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2707 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2709 ctx->hflags |= MIPS_HFLAG_BC;
2710 tcg_gen_trunc_tl_i32(bcond, t0);
2715 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2717 ctx->hflags |= MIPS_HFLAG_BL;
2718 tcg_gen_trunc_tl_i32(bcond, t0);
2721 MIPS_INVAL("conditional branch/jump");
2722 generate_exception(ctx, EXCP_RI);
2726 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2727 blink, ctx->hflags, btgt);
2729 ctx->btarget = btgt;
2731 tcg_gen_movi_tl(t0, ctx->pc + 8);
2732 gen_store_gpr(t0, blink);
2740 /* special3 bitfield operations */
2741 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2742 int rs, int lsb, int msb)
2744 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2745 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2747 gen_load_gpr(t1, rs);
2752 tcg_gen_helper_1_1ii(do_ext, t0, t1, lsb, msb + 1);
2754 #if defined(TARGET_MIPS64)
2758 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1 + 32);
2763 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb + 32, msb + 1);
2768 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1);
2774 gen_load_gpr(t0, rt);
2775 tcg_gen_helper_1_2ii(do_ins, t0, t0, t1, lsb, msb - lsb + 1);
2777 #if defined(TARGET_MIPS64)
2781 gen_load_gpr(t0, rt);
2782 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1 + 32);
2787 gen_load_gpr(t0, rt);
2788 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb + 32, msb - lsb + 1);
2793 gen_load_gpr(t0, rt);
2794 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1);
2799 MIPS_INVAL("bitops");
2800 generate_exception(ctx, EXCP_RI);
2805 gen_store_gpr(t0, rt);
2810 #ifndef CONFIG_USER_ONLY
2811 /* CP0 (MMU and control) */
2812 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2814 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2816 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2817 tcg_gen_ext_i32_tl(t, r_tmp);
2818 tcg_temp_free(r_tmp);
2821 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2823 tcg_gen_ld_tl(t, cpu_env, off);
2824 tcg_gen_ext32s_tl(t, t);
2827 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2829 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2831 tcg_gen_trunc_tl_i32(r_tmp, t);
2832 tcg_gen_st_i32(r_tmp, cpu_env, off);
2833 tcg_temp_free(r_tmp);
2836 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2838 tcg_gen_ext32s_tl(t, t);
2839 tcg_gen_st_tl(t, cpu_env, off);
2842 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2844 const char *rn = "invalid";
2847 check_insn(env, ctx, ISA_MIPS32);
2853 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2857 check_insn(env, ctx, ASE_MT);
2858 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2862 check_insn(env, ctx, ASE_MT);
2863 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2867 check_insn(env, ctx, ASE_MT);
2868 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2878 tcg_gen_helper_1_0(do_mfc0_random, t0);
2882 check_insn(env, ctx, ASE_MT);
2883 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2887 check_insn(env, ctx, ASE_MT);
2888 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2892 check_insn(env, ctx, ASE_MT);
2893 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2897 check_insn(env, ctx, ASE_MT);
2898 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2902 check_insn(env, ctx, ASE_MT);
2903 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2907 check_insn(env, ctx, ASE_MT);
2908 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2909 rn = "VPEScheFBack";
2912 check_insn(env, ctx, ASE_MT);
2913 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2923 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2924 tcg_gen_ext32s_tl(t0, t0);
2928 check_insn(env, ctx, ASE_MT);
2929 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2933 check_insn(env, ctx, ASE_MT);
2934 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2938 check_insn(env, ctx, ASE_MT);
2939 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2943 check_insn(env, ctx, ASE_MT);
2944 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2948 check_insn(env, ctx, ASE_MT);
2949 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2953 check_insn(env, ctx, ASE_MT);
2954 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2958 check_insn(env, ctx, ASE_MT);
2959 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2969 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2970 tcg_gen_ext32s_tl(t0, t0);
2980 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2981 tcg_gen_ext32s_tl(t0, t0);
2985 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2986 rn = "ContextConfig";
2995 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2999 check_insn(env, ctx, ISA_MIPS32R2);
3000 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
3010 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
3014 check_insn(env, ctx, ISA_MIPS32R2);
3015 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
3019 check_insn(env, ctx, ISA_MIPS32R2);
3020 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
3024 check_insn(env, ctx, ISA_MIPS32R2);
3025 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
3029 check_insn(env, ctx, ISA_MIPS32R2);
3030 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
3034 check_insn(env, ctx, ISA_MIPS32R2);
3035 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
3045 check_insn(env, ctx, ISA_MIPS32R2);
3046 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
3056 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
3057 tcg_gen_ext32s_tl(t0, t0);
3067 /* Mark as an IO operation because we read the time. */
3070 tcg_gen_helper_1_0(do_mfc0_count, t0);
3073 ctx->bstate = BS_STOP;
3077 /* 6,7 are implementation dependent */
3085 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3086 tcg_gen_ext32s_tl(t0, t0);
3096 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3099 /* 6,7 are implementation dependent */
3107 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3111 check_insn(env, ctx, ISA_MIPS32R2);
3112 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3116 check_insn(env, ctx, ISA_MIPS32R2);
3117 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3121 check_insn(env, ctx, ISA_MIPS32R2);
3122 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3132 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3142 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3143 tcg_gen_ext32s_tl(t0, t0);
3153 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3157 check_insn(env, ctx, ISA_MIPS32R2);
3158 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3168 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3172 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3176 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3180 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3183 /* 4,5 are reserved */
3184 /* 6,7 are implementation dependent */
3186 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3190 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3200 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3210 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3220 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3230 #if defined(TARGET_MIPS64)
3231 check_insn(env, ctx, ISA_MIPS3);
3232 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3233 tcg_gen_ext32s_tl(t0, t0);
3242 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3245 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3254 rn = "'Diagnostic"; /* implementation dependent */
3259 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3263 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3264 rn = "TraceControl";
3267 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3268 rn = "TraceControl2";
3271 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3272 rn = "UserTraceData";
3275 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3286 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3287 tcg_gen_ext32s_tl(t0, t0);
3297 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3298 rn = "Performance0";
3301 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3302 rn = "Performance1";
3305 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3306 rn = "Performance2";
3309 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3310 rn = "Performance3";
3313 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3314 rn = "Performance4";
3317 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3318 rn = "Performance5";
3321 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3322 rn = "Performance6";
3325 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3326 rn = "Performance7";
3351 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3358 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3371 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3378 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3388 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3389 tcg_gen_ext32s_tl(t0, t0);
3400 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3410 #if defined MIPS_DEBUG_DISAS
3411 if (loglevel & CPU_LOG_TB_IN_ASM) {
3412 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3419 #if defined MIPS_DEBUG_DISAS
3420 if (loglevel & CPU_LOG_TB_IN_ASM) {
3421 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3425 generate_exception(ctx, EXCP_RI);
3428 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3430 const char *rn = "invalid";
3433 check_insn(env, ctx, ISA_MIPS32);
3442 tcg_gen_helper_0_1(do_mtc0_index, t0);
3446 check_insn(env, ctx, ASE_MT);
3447 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3451 check_insn(env, ctx, ASE_MT);
3456 check_insn(env, ctx, ASE_MT);
3471 check_insn(env, ctx, ASE_MT);
3472 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3476 check_insn(env, ctx, ASE_MT);
3477 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3481 check_insn(env, ctx, ASE_MT);
3482 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3486 check_insn(env, ctx, ASE_MT);
3487 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3491 check_insn(env, ctx, ASE_MT);
3492 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3496 check_insn(env, ctx, ASE_MT);
3497 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3498 rn = "VPEScheFBack";
3501 check_insn(env, ctx, ASE_MT);
3502 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3512 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3516 check_insn(env, ctx, ASE_MT);
3517 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3521 check_insn(env, ctx, ASE_MT);
3522 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3526 check_insn(env, ctx, ASE_MT);
3527 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3531 check_insn(env, ctx, ASE_MT);
3532 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3536 check_insn(env, ctx, ASE_MT);
3537 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3541 check_insn(env, ctx, ASE_MT);
3542 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3546 check_insn(env, ctx, ASE_MT);
3547 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3557 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3567 tcg_gen_helper_0_1(do_mtc0_context, t0);
3571 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3572 rn = "ContextConfig";
3581 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3585 check_insn(env, ctx, ISA_MIPS32R2);
3586 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3596 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3600 check_insn(env, ctx, ISA_MIPS32R2);
3601 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3605 check_insn(env, ctx, ISA_MIPS32R2);
3606 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3610 check_insn(env, ctx, ISA_MIPS32R2);
3611 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3615 check_insn(env, ctx, ISA_MIPS32R2);
3616 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3620 check_insn(env, ctx, ISA_MIPS32R2);
3621 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3631 check_insn(env, ctx, ISA_MIPS32R2);
3632 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3646 tcg_gen_helper_0_1(do_mtc0_count, t0);
3649 /* 6,7 are implementation dependent */
3653 /* Stop translation as we may have switched the execution mode */
3654 ctx->bstate = BS_STOP;
3659 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3669 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3672 /* 6,7 are implementation dependent */
3676 /* Stop translation as we may have switched the execution mode */
3677 ctx->bstate = BS_STOP;
3682 tcg_gen_helper_0_1(do_mtc0_status, t0);
3683 /* BS_STOP isn't good enough here, hflags may have changed. */
3684 gen_save_pc(ctx->pc + 4);
3685 ctx->bstate = BS_EXCP;
3689 check_insn(env, ctx, ISA_MIPS32R2);
3690 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3691 /* Stop translation as we may have switched the execution mode */
3692 ctx->bstate = BS_STOP;
3696 check_insn(env, ctx, ISA_MIPS32R2);
3697 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3698 /* Stop translation as we may have switched the execution mode */
3699 ctx->bstate = BS_STOP;
3703 check_insn(env, ctx, ISA_MIPS32R2);
3704 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3705 /* Stop translation as we may have switched the execution mode */
3706 ctx->bstate = BS_STOP;
3716 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3722 /* Stop translation as we may have switched the execution mode */
3723 ctx->bstate = BS_STOP;
3728 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3742 check_insn(env, ctx, ISA_MIPS32R2);
3743 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3753 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3755 /* Stop translation as we may have switched the execution mode */
3756 ctx->bstate = BS_STOP;
3759 /* ignored, read only */
3763 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3765 /* Stop translation as we may have switched the execution mode */
3766 ctx->bstate = BS_STOP;
3769 /* ignored, read only */
3772 /* 4,5 are reserved */
3773 /* 6,7 are implementation dependent */
3783 rn = "Invalid config selector";
3800 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3810 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3820 #if defined(TARGET_MIPS64)
3821 check_insn(env, ctx, ISA_MIPS3);
3822 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3831 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3834 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3843 rn = "Diagnostic"; /* implementation dependent */
3848 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3849 /* BS_STOP isn't good enough here, hflags may have changed. */
3850 gen_save_pc(ctx->pc + 4);
3851 ctx->bstate = BS_EXCP;
3855 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3856 rn = "TraceControl";
3857 /* Stop translation as we may have switched the execution mode */
3858 ctx->bstate = BS_STOP;
3861 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3862 rn = "TraceControl2";
3863 /* Stop translation as we may have switched the execution mode */
3864 ctx->bstate = BS_STOP;
3867 /* Stop translation as we may have switched the execution mode */
3868 ctx->bstate = BS_STOP;
3869 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3870 rn = "UserTraceData";
3871 /* Stop translation as we may have switched the execution mode */
3872 ctx->bstate = BS_STOP;
3875 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3876 /* Stop translation as we may have switched the execution mode */
3877 ctx->bstate = BS_STOP;
3888 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3898 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3899 rn = "Performance0";
3902 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3903 rn = "Performance1";
3906 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3907 rn = "Performance2";
3910 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3911 rn = "Performance3";
3914 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3915 rn = "Performance4";
3918 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3919 rn = "Performance5";
3922 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3923 rn = "Performance6";
3926 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3927 rn = "Performance7";
3953 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3960 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3973 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3980 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
3991 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
4002 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
4008 /* Stop translation as we may have switched the execution mode */
4009 ctx->bstate = BS_STOP;
4014 #if defined MIPS_DEBUG_DISAS
4015 if (loglevel & CPU_LOG_TB_IN_ASM) {
4016 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4020 /* For simplicity assume that all writes can cause interrupts. */
4023 ctx->bstate = BS_STOP;
4028 #if defined MIPS_DEBUG_DISAS
4029 if (loglevel & CPU_LOG_TB_IN_ASM) {
4030 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
4034 generate_exception(ctx, EXCP_RI);
4037 #if defined(TARGET_MIPS64)
4038 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4040 const char *rn = "invalid";
4043 check_insn(env, ctx, ISA_MIPS64);
4049 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
4053 check_insn(env, ctx, ASE_MT);
4054 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
4058 check_insn(env, ctx, ASE_MT);
4059 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4063 check_insn(env, ctx, ASE_MT);
4064 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4074 tcg_gen_helper_1_0(do_mfc0_random, t0);
4078 check_insn(env, ctx, ASE_MT);
4079 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4083 check_insn(env, ctx, ASE_MT);
4084 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4088 check_insn(env, ctx, ASE_MT);
4089 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4093 check_insn(env, ctx, ASE_MT);
4094 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4098 check_insn(env, ctx, ASE_MT);
4099 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4103 check_insn(env, ctx, ASE_MT);
4104 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4105 rn = "VPEScheFBack";
4108 check_insn(env, ctx, ASE_MT);
4109 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4119 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4123 check_insn(env, ctx, ASE_MT);
4124 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4128 check_insn(env, ctx, ASE_MT);
4129 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4133 check_insn(env, ctx, ASE_MT);
4134 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4138 check_insn(env, ctx, ASE_MT);
4139 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4143 check_insn(env, ctx, ASE_MT);
4144 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4148 check_insn(env, ctx, ASE_MT);
4149 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4153 check_insn(env, ctx, ASE_MT);
4154 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4164 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4174 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4178 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4179 rn = "ContextConfig";
4188 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4192 check_insn(env, ctx, ISA_MIPS32R2);
4193 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4203 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4207 check_insn(env, ctx, ISA_MIPS32R2);
4208 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4212 check_insn(env, ctx, ISA_MIPS32R2);
4213 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4217 check_insn(env, ctx, ISA_MIPS32R2);
4218 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4222 check_insn(env, ctx, ISA_MIPS32R2);
4223 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4227 check_insn(env, ctx, ISA_MIPS32R2);
4228 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4238 check_insn(env, ctx, ISA_MIPS32R2);
4239 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4249 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4259 /* Mark as an IO operation because we read the time. */
4262 tcg_gen_helper_1_0(do_mfc0_count, t0);
4265 ctx->bstate = BS_STOP;
4269 /* 6,7 are implementation dependent */
4277 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4287 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4290 /* 6,7 are implementation dependent */
4298 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4302 check_insn(env, ctx, ISA_MIPS32R2);
4303 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4307 check_insn(env, ctx, ISA_MIPS32R2);
4308 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4312 check_insn(env, ctx, ISA_MIPS32R2);
4313 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4323 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4333 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4343 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4347 check_insn(env, ctx, ISA_MIPS32R2);
4348 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4358 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4362 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4366 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4370 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4373 /* 6,7 are implementation dependent */
4375 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4379 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4389 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4399 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4409 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4419 check_insn(env, ctx, ISA_MIPS3);
4420 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4428 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4431 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4440 rn = "'Diagnostic"; /* implementation dependent */
4445 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4449 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4450 rn = "TraceControl";
4453 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4454 rn = "TraceControl2";
4457 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4458 rn = "UserTraceData";
4461 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4472 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4482 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4483 rn = "Performance0";
4486 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4487 rn = "Performance1";
4490 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4491 rn = "Performance2";
4494 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4495 rn = "Performance3";
4498 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4499 rn = "Performance4";
4502 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4503 rn = "Performance5";
4506 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4507 rn = "Performance6";
4510 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4511 rn = "Performance7";
4536 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4543 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4556 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4563 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4573 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4584 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4594 #if defined MIPS_DEBUG_DISAS
4595 if (loglevel & CPU_LOG_TB_IN_ASM) {
4596 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4603 #if defined MIPS_DEBUG_DISAS
4604 if (loglevel & CPU_LOG_TB_IN_ASM) {
4605 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4609 generate_exception(ctx, EXCP_RI);
4612 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4614 const char *rn = "invalid";
4617 check_insn(env, ctx, ISA_MIPS64);
4626 tcg_gen_helper_0_1(do_mtc0_index, t0);
4630 check_insn(env, ctx, ASE_MT);
4631 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4635 check_insn(env, ctx, ASE_MT);
4640 check_insn(env, ctx, ASE_MT);
4655 check_insn(env, ctx, ASE_MT);
4656 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4660 check_insn(env, ctx, ASE_MT);
4661 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4665 check_insn(env, ctx, ASE_MT);
4666 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4670 check_insn(env, ctx, ASE_MT);
4671 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4675 check_insn(env, ctx, ASE_MT);
4676 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4680 check_insn(env, ctx, ASE_MT);
4681 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4682 rn = "VPEScheFBack";
4685 check_insn(env, ctx, ASE_MT);
4686 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4696 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4700 check_insn(env, ctx, ASE_MT);
4701 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4705 check_insn(env, ctx, ASE_MT);
4706 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4710 check_insn(env, ctx, ASE_MT);
4711 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4715 check_insn(env, ctx, ASE_MT);
4716 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4720 check_insn(env, ctx, ASE_MT);
4721 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4725 check_insn(env, ctx, ASE_MT);
4726 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4730 check_insn(env, ctx, ASE_MT);
4731 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4741 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4751 tcg_gen_helper_0_1(do_mtc0_context, t0);
4755 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4756 rn = "ContextConfig";
4765 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4769 check_insn(env, ctx, ISA_MIPS32R2);
4770 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4780 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4784 check_insn(env, ctx, ISA_MIPS32R2);
4785 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4789 check_insn(env, ctx, ISA_MIPS32R2);
4790 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4794 check_insn(env, ctx, ISA_MIPS32R2);
4795 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4799 check_insn(env, ctx, ISA_MIPS32R2);
4800 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4804 check_insn(env, ctx, ISA_MIPS32R2);
4805 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4815 check_insn(env, ctx, ISA_MIPS32R2);
4816 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4830 tcg_gen_helper_0_1(do_mtc0_count, t0);
4833 /* 6,7 are implementation dependent */
4837 /* Stop translation as we may have switched the execution mode */
4838 ctx->bstate = BS_STOP;
4843 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4853 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4856 /* 6,7 are implementation dependent */
4860 /* Stop translation as we may have switched the execution mode */
4861 ctx->bstate = BS_STOP;
4866 tcg_gen_helper_0_1(do_mtc0_status, t0);
4867 /* BS_STOP isn't good enough here, hflags may have changed. */
4868 gen_save_pc(ctx->pc + 4);
4869 ctx->bstate = BS_EXCP;
4873 check_insn(env, ctx, ISA_MIPS32R2);
4874 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4875 /* Stop translation as we may have switched the execution mode */
4876 ctx->bstate = BS_STOP;
4880 check_insn(env, ctx, ISA_MIPS32R2);
4881 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4882 /* Stop translation as we may have switched the execution mode */
4883 ctx->bstate = BS_STOP;
4887 check_insn(env, ctx, ISA_MIPS32R2);
4888 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4889 /* Stop translation as we may have switched the execution mode */
4890 ctx->bstate = BS_STOP;
4900 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4906 /* Stop translation as we may have switched the execution mode */
4907 ctx->bstate = BS_STOP;
4912 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4926 check_insn(env, ctx, ISA_MIPS32R2);
4927 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4937 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4939 /* Stop translation as we may have switched the execution mode */
4940 ctx->bstate = BS_STOP;
4947 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4949 /* Stop translation as we may have switched the execution mode */
4950 ctx->bstate = BS_STOP;
4956 /* 6,7 are implementation dependent */
4958 rn = "Invalid config selector";
4975 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4985 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
4995 check_insn(env, ctx, ISA_MIPS3);
4996 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
5004 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5007 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
5016 rn = "Diagnostic"; /* implementation dependent */
5021 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
5022 /* BS_STOP isn't good enough here, hflags may have changed. */
5023 gen_save_pc(ctx->pc + 4);
5024 ctx->bstate = BS_EXCP;
5028 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
5029 /* Stop translation as we may have switched the execution mode */
5030 ctx->bstate = BS_STOP;
5031 rn = "TraceControl";
5034 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
5035 /* Stop translation as we may have switched the execution mode */
5036 ctx->bstate = BS_STOP;
5037 rn = "TraceControl2";
5040 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5041 /* Stop translation as we may have switched the execution mode */
5042 ctx->bstate = BS_STOP;
5043 rn = "UserTraceData";
5046 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5047 /* Stop translation as we may have switched the execution mode */
5048 ctx->bstate = BS_STOP;
5059 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5069 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5070 rn = "Performance0";
5073 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5074 rn = "Performance1";
5077 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5078 rn = "Performance2";
5081 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5082 rn = "Performance3";
5085 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5086 rn = "Performance4";
5089 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5090 rn = "Performance5";
5093 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5094 rn = "Performance6";
5097 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5098 rn = "Performance7";
5124 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5131 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5144 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5151 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5162 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5173 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5179 /* Stop translation as we may have switched the execution mode */
5180 ctx->bstate = BS_STOP;
5185 #if defined MIPS_DEBUG_DISAS
5186 if (loglevel & CPU_LOG_TB_IN_ASM) {
5187 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5191 /* For simplicity assume that all writes can cause interrupts. */
5194 ctx->bstate = BS_STOP;
5199 #if defined MIPS_DEBUG_DISAS
5200 if (loglevel & CPU_LOG_TB_IN_ASM) {
5201 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5205 generate_exception(ctx, EXCP_RI);
5207 #endif /* TARGET_MIPS64 */
5209 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5210 int u, int sel, int h)
5212 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5213 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5215 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5216 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5217 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5218 tcg_gen_movi_tl(t0, -1);
5219 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5220 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5221 tcg_gen_movi_tl(t0, -1);
5227 tcg_gen_helper_1_1(do_mftc0_tcstatus, t0, t0);
5230 tcg_gen_helper_1_1(do_mftc0_tcbind, t0, t0);
5233 tcg_gen_helper_1_1(do_mftc0_tcrestart, t0, t0);
5236 tcg_gen_helper_1_1(do_mftc0_tchalt, t0, t0);
5239 tcg_gen_helper_1_1(do_mftc0_tccontext, t0, t0);
5242 tcg_gen_helper_1_1(do_mftc0_tcschedule, t0, t0);
5245 tcg_gen_helper_1_1(do_mftc0_tcschefback, t0, t0);
5248 gen_mfc0(env, ctx, t0, rt, sel);
5255 tcg_gen_helper_1_1(do_mftc0_entryhi, t0, t0);
5258 gen_mfc0(env, ctx, t0, rt, sel);
5264 tcg_gen_helper_1_1(do_mftc0_status, t0, t0);
5267 gen_mfc0(env, ctx, t0, rt, sel);
5273 tcg_gen_helper_1_1(do_mftc0_debug, t0, t0);
5276 gen_mfc0(env, ctx, t0, rt, sel);
5281 gen_mfc0(env, ctx, t0, rt, sel);
5283 } else switch (sel) {
5284 /* GPR registers. */
5286 tcg_gen_helper_1_1i(do_mftgpr, t0, t0, rt);
5288 /* Auxiliary CPU registers */
5292 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 0);
5295 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 0);
5298 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 0);
5301 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 1);
5304 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 1);
5307 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 1);
5310 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 2);
5313 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 2);
5316 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 2);
5319 tcg_gen_helper_1_1i(do_mftlo, t0, t0, 3);
5322 tcg_gen_helper_1_1i(do_mfthi, t0, t0, 3);
5325 tcg_gen_helper_1_1i(do_mftacx, t0, t0, 3);
5328 tcg_gen_helper_1_1(do_mftdsp, t0, t0);
5334 /* Floating point (COP1). */
5336 /* XXX: For now we support only a single FPU context. */
5338 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5340 gen_load_fpr32(fp0, rt);
5341 tcg_gen_ext_i32_tl(t0, fp0);
5344 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5346 gen_load_fpr32h(fp0, rt);
5347 tcg_gen_ext_i32_tl(t0, fp0);
5352 /* XXX: For now we support only a single FPU context. */
5353 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5355 /* COP2: Not implemented. */
5362 #if defined MIPS_DEBUG_DISAS
5363 if (loglevel & CPU_LOG_TB_IN_ASM) {
5364 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5368 gen_store_gpr(t0, rd);
5374 #if defined MIPS_DEBUG_DISAS
5375 if (loglevel & CPU_LOG_TB_IN_ASM) {
5376 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5380 generate_exception(ctx, EXCP_RI);
5383 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5384 int u, int sel, int h)
5386 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5387 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5389 gen_load_gpr(t0, rt);
5390 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5391 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5392 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5394 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5395 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5402 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5405 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5408 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5411 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5414 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5417 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5420 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5423 gen_mtc0(env, ctx, t0, rd, sel);
5430 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5433 gen_mtc0(env, ctx, t0, rd, sel);
5439 tcg_gen_helper_0_1(do_mttc0_status, t0);
5442 gen_mtc0(env, ctx, t0, rd, sel);
5448 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5451 gen_mtc0(env, ctx, t0, rd, sel);
5456 gen_mtc0(env, ctx, t0, rd, sel);
5458 } else switch (sel) {
5459 /* GPR registers. */
5461 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5463 /* Auxiliary CPU registers */
5467 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5470 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5473 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5476 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5479 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5482 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5485 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5488 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5491 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5494 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5497 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5500 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5503 tcg_gen_helper_0_1(do_mttdsp, t0);
5509 /* Floating point (COP1). */
5511 /* XXX: For now we support only a single FPU context. */
5513 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5515 tcg_gen_trunc_tl_i32(fp0, t0);
5516 gen_store_fpr32(fp0, rd);
5519 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5521 tcg_gen_trunc_tl_i32(fp0, t0);
5522 gen_store_fpr32h(fp0, rd);
5527 /* XXX: For now we support only a single FPU context. */
5528 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5530 /* COP2: Not implemented. */
5537 #if defined MIPS_DEBUG_DISAS
5538 if (loglevel & CPU_LOG_TB_IN_ASM) {
5539 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5548 #if defined MIPS_DEBUG_DISAS
5549 if (loglevel & CPU_LOG_TB_IN_ASM) {
5550 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5554 generate_exception(ctx, EXCP_RI);
5557 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5559 const char *opn = "ldst";
5568 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5570 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5571 gen_store_gpr(t0, rt);
5578 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5580 gen_load_gpr(t0, rt);
5581 save_cpu_state(ctx, 1);
5582 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5587 #if defined(TARGET_MIPS64)
5589 check_insn(env, ctx, ISA_MIPS3);
5595 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5597 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5598 gen_store_gpr(t0, rt);
5604 check_insn(env, ctx, ISA_MIPS3);
5606 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5608 gen_load_gpr(t0, rt);
5609 save_cpu_state(ctx, 1);
5610 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5617 check_insn(env, ctx, ASE_MT);
5622 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5623 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5627 check_insn(env, ctx, ASE_MT);
5628 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5629 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5634 if (!env->tlb->do_tlbwi)
5636 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5640 if (!env->tlb->do_tlbwr)
5642 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5646 if (!env->tlb->do_tlbp)
5648 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5652 if (!env->tlb->do_tlbr)
5654 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5658 check_insn(env, ctx, ISA_MIPS2);
5659 save_cpu_state(ctx, 1);
5660 tcg_gen_helper_0_0(do_eret);
5661 ctx->bstate = BS_EXCP;
5665 check_insn(env, ctx, ISA_MIPS32);
5666 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5668 generate_exception(ctx, EXCP_RI);
5670 save_cpu_state(ctx, 1);
5671 tcg_gen_helper_0_0(do_deret);
5672 ctx->bstate = BS_EXCP;
5677 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5678 /* If we get an exception, we want to restart at next instruction */
5680 save_cpu_state(ctx, 1);
5682 tcg_gen_helper_0_0(do_wait);
5683 ctx->bstate = BS_EXCP;
5688 generate_exception(ctx, EXCP_RI);
5691 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5693 #endif /* !CONFIG_USER_ONLY */
5695 /* CP1 Branches (before delay slot) */
5696 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5697 int32_t cc, int32_t offset)
5699 target_ulong btarget;
5700 const char *opn = "cp1 cond branch";
5701 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5702 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5705 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5707 btarget = ctx->pc + 4 + offset;
5712 int l1 = gen_new_label();
5713 int l2 = gen_new_label();
5714 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5716 get_fp_cond(r_tmp1);
5717 tcg_gen_ext_i32_tl(t0, r_tmp1);
5718 tcg_temp_free(r_tmp1);
5719 tcg_gen_not_tl(t0, t0);
5720 tcg_gen_movi_tl(t1, 0x1 << cc);
5721 tcg_gen_and_tl(t0, t0, t1);
5722 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5723 tcg_gen_movi_tl(t0, 0);
5726 tcg_gen_movi_tl(t0, 1);
5733 int l1 = gen_new_label();
5734 int l2 = gen_new_label();
5735 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5737 get_fp_cond(r_tmp1);
5738 tcg_gen_ext_i32_tl(t0, r_tmp1);
5739 tcg_temp_free(r_tmp1);
5740 tcg_gen_not_tl(t0, t0);
5741 tcg_gen_movi_tl(t1, 0x1 << cc);
5742 tcg_gen_and_tl(t0, t0, t1);
5743 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5744 tcg_gen_movi_tl(t0, 0);
5747 tcg_gen_movi_tl(t0, 1);
5754 int l1 = gen_new_label();
5755 int l2 = gen_new_label();
5756 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5758 get_fp_cond(r_tmp1);
5759 tcg_gen_ext_i32_tl(t0, r_tmp1);
5760 tcg_temp_free(r_tmp1);
5761 tcg_gen_movi_tl(t1, 0x1 << cc);
5762 tcg_gen_and_tl(t0, t0, t1);
5763 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5764 tcg_gen_movi_tl(t0, 0);
5767 tcg_gen_movi_tl(t0, 1);
5774 int l1 = gen_new_label();
5775 int l2 = gen_new_label();
5776 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5778 get_fp_cond(r_tmp1);
5779 tcg_gen_ext_i32_tl(t0, r_tmp1);
5780 tcg_temp_free(r_tmp1);
5781 tcg_gen_movi_tl(t1, 0x1 << cc);
5782 tcg_gen_and_tl(t0, t0, t1);
5783 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5784 tcg_gen_movi_tl(t0, 0);
5787 tcg_gen_movi_tl(t0, 1);
5792 ctx->hflags |= MIPS_HFLAG_BL;
5793 tcg_gen_trunc_tl_i32(bcond, t0);
5797 int l1 = gen_new_label();
5798 int l2 = gen_new_label();
5799 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5801 get_fp_cond(r_tmp1);
5802 tcg_gen_ext_i32_tl(t0, r_tmp1);
5803 tcg_temp_free(r_tmp1);
5804 tcg_gen_not_tl(t0, t0);
5805 tcg_gen_movi_tl(t1, 0x3 << cc);
5806 tcg_gen_and_tl(t0, t0, t1);
5807 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5808 tcg_gen_movi_tl(t0, 0);
5811 tcg_gen_movi_tl(t0, 1);
5818 int l1 = gen_new_label();
5819 int l2 = gen_new_label();
5820 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5822 get_fp_cond(r_tmp1);
5823 tcg_gen_ext_i32_tl(t0, r_tmp1);
5824 tcg_temp_free(r_tmp1);
5825 tcg_gen_movi_tl(t1, 0x3 << cc);
5826 tcg_gen_and_tl(t0, t0, t1);
5827 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5828 tcg_gen_movi_tl(t0, 0);
5831 tcg_gen_movi_tl(t0, 1);
5838 int l1 = gen_new_label();
5839 int l2 = gen_new_label();
5840 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5842 get_fp_cond(r_tmp1);
5843 tcg_gen_ext_i32_tl(t0, r_tmp1);
5844 tcg_temp_free(r_tmp1);
5845 tcg_gen_not_tl(t0, t0);
5846 tcg_gen_movi_tl(t1, 0xf << cc);
5847 tcg_gen_and_tl(t0, t0, t1);
5848 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5849 tcg_gen_movi_tl(t0, 0);
5852 tcg_gen_movi_tl(t0, 1);
5859 int l1 = gen_new_label();
5860 int l2 = gen_new_label();
5861 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5863 get_fp_cond(r_tmp1);
5864 tcg_gen_ext_i32_tl(t0, r_tmp1);
5865 tcg_temp_free(r_tmp1);
5866 tcg_gen_movi_tl(t1, 0xf << cc);
5867 tcg_gen_and_tl(t0, t0, t1);
5868 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5869 tcg_gen_movi_tl(t0, 0);
5872 tcg_gen_movi_tl(t0, 1);
5877 ctx->hflags |= MIPS_HFLAG_BC;
5878 tcg_gen_trunc_tl_i32(bcond, t0);
5882 generate_exception (ctx, EXCP_RI);
5885 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5886 ctx->hflags, btarget);
5887 ctx->btarget = btarget;
5894 /* Coprocessor 1 (FPU) */
5896 #define FOP(func, fmt) (((fmt) << 21) | (func))
5898 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5900 const char *opn = "cp1 move";
5901 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5906 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5908 gen_load_fpr32(fp0, fs);
5909 tcg_gen_ext_i32_tl(t0, fp0);
5912 gen_store_gpr(t0, rt);
5916 gen_load_gpr(t0, rt);
5918 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5920 tcg_gen_trunc_tl_i32(fp0, t0);
5921 gen_store_fpr32(fp0, fs);
5927 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5928 gen_store_gpr(t0, rt);
5932 gen_load_gpr(t0, rt);
5933 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5938 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5940 gen_load_fpr64(ctx, fp0, fs);
5941 tcg_gen_mov_tl(t0, fp0);
5944 gen_store_gpr(t0, rt);
5948 gen_load_gpr(t0, rt);
5950 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5952 tcg_gen_mov_tl(fp0, t0);
5953 gen_store_fpr64(ctx, fp0, fs);
5960 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5962 gen_load_fpr32h(fp0, fs);
5963 tcg_gen_ext_i32_tl(t0, fp0);
5966 gen_store_gpr(t0, rt);
5970 gen_load_gpr(t0, rt);
5972 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5974 tcg_gen_trunc_tl_i32(fp0, t0);
5975 gen_store_fpr32h(fp0, fs);
5982 generate_exception (ctx, EXCP_RI);
5985 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5991 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5993 int l1 = gen_new_label();
5996 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5997 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5998 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
6001 ccbit = 1 << (24 + cc);
6009 gen_load_gpr(t0, rd);
6010 gen_load_gpr(t1, rs);
6011 tcg_gen_ld_i32(r_tmp, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
6012 tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
6013 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
6014 tcg_temp_free(r_tmp);
6016 tcg_gen_mov_tl(t0, t1);
6020 gen_store_gpr(t0, rd);
6024 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
6028 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6029 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6030 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6031 int l1 = gen_new_label();
6034 ccbit = 1 << (24 + cc);
6043 gen_load_fpr32(fp0, fs);
6044 gen_load_fpr32(fp1, fd);
6045 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
6046 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
6047 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6048 tcg_gen_movi_i32(fp1, fp0);
6051 tcg_temp_free(r_tmp1);
6052 gen_store_fpr32(fp1, fd);
6056 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
6060 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6061 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6062 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I64);
6063 int l1 = gen_new_label();
6066 ccbit = 1 << (24 + cc);
6075 gen_load_fpr64(ctx, fp0, fs);
6076 gen_load_fpr64(ctx, fp1, fd);
6077 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
6078 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
6079 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6080 tcg_gen_movi_i64(fp1, fp0);
6083 tcg_temp_free(r_tmp1);
6084 gen_store_fpr64(ctx, fp1, fd);
6088 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
6091 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6092 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6093 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6094 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
6095 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6096 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
6097 int l1 = gen_new_label();
6098 int l2 = gen_new_label();
6105 gen_load_fpr32(fp0, fs);
6106 gen_load_fpr32h(fph0, fs);
6107 gen_load_fpr32(fp1, fd);
6108 gen_load_fpr32h(fph1, fd);
6109 get_fp_cond(r_tmp1);
6110 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6111 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6112 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6113 tcg_gen_movi_i32(fp1, fp0);
6116 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6117 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6118 tcg_gen_movi_i32(fph1, fph0);
6119 tcg_temp_free(fph0);
6121 tcg_temp_free(r_tmp1);
6122 tcg_temp_free(r_tmp2);
6123 gen_store_fpr32(fp1, fd);
6124 gen_store_fpr32h(fph1, fd);
6126 tcg_temp_free(fph1);
6130 static void gen_farith (DisasContext *ctx, uint32_t op1,
6131 int ft, int fs, int fd, int cc)
6133 const char *opn = "farith";
6134 const char *condnames[] = {
6152 const char *condnames_abs[] = {
6170 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6171 uint32_t func = ctx->opcode & 0x3f;
6173 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6176 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6177 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6179 gen_load_fpr32(fp0, fs);
6180 gen_load_fpr32(fp1, ft);
6181 tcg_gen_helper_1_2(do_float_add_s, fp0, fp0, fp1);
6183 gen_store_fpr32(fp0, fd);
6191 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6192 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6194 gen_load_fpr32(fp0, fs);
6195 gen_load_fpr32(fp1, ft);
6196 tcg_gen_helper_1_2(do_float_sub_s, fp0, fp0, fp1);
6198 gen_store_fpr32(fp0, fd);
6206 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6207 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6209 gen_load_fpr32(fp0, fs);
6210 gen_load_fpr32(fp1, ft);
6211 tcg_gen_helper_1_2(do_float_mul_s, fp0, fp0, fp1);
6213 gen_store_fpr32(fp0, fd);
6221 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6222 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6224 gen_load_fpr32(fp0, fs);
6225 gen_load_fpr32(fp1, ft);
6226 tcg_gen_helper_1_2(do_float_div_s, fp0, fp0, fp1);
6228 gen_store_fpr32(fp0, fd);
6236 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6238 gen_load_fpr32(fp0, fs);
6239 tcg_gen_helper_1_1(do_float_sqrt_s, fp0, fp0);
6240 gen_store_fpr32(fp0, fd);
6247 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6249 gen_load_fpr32(fp0, fs);
6250 tcg_gen_helper_1_1(do_float_abs_s, fp0, fp0);
6251 gen_store_fpr32(fp0, fd);
6258 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6260 gen_load_fpr32(fp0, fs);
6261 gen_store_fpr32(fp0, fd);
6268 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6270 gen_load_fpr32(fp0, fs);
6271 tcg_gen_helper_1_1(do_float_chs_s, fp0, fp0);
6272 gen_store_fpr32(fp0, fd);
6278 check_cp1_64bitmode(ctx);
6280 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6281 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6283 gen_load_fpr32(fp32, fs);
6284 tcg_gen_helper_1_1(do_float_roundl_s, fp64, fp32);
6285 tcg_temp_free(fp32);
6286 gen_store_fpr64(ctx, fp64, fd);
6287 tcg_temp_free(fp64);
6292 check_cp1_64bitmode(ctx);
6294 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6295 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6297 gen_load_fpr32(fp32, fs);
6298 tcg_gen_helper_1_1(do_float_truncl_s, fp64, fp32);
6299 tcg_temp_free(fp32);
6300 gen_store_fpr64(ctx, fp64, fd);
6301 tcg_temp_free(fp64);
6306 check_cp1_64bitmode(ctx);
6308 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6309 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6311 gen_load_fpr32(fp32, fs);
6312 tcg_gen_helper_1_1(do_float_ceill_s, fp64, fp32);
6313 tcg_temp_free(fp32);
6314 gen_store_fpr64(ctx, fp64, fd);
6315 tcg_temp_free(fp64);
6320 check_cp1_64bitmode(ctx);
6322 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6323 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6325 gen_load_fpr32(fp32, fs);
6326 tcg_gen_helper_1_1(do_float_floorl_s, fp64, fp32);
6327 tcg_temp_free(fp32);
6328 gen_store_fpr64(ctx, fp64, fd);
6329 tcg_temp_free(fp64);
6335 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6337 gen_load_fpr32(fp0, fs);
6338 tcg_gen_helper_1_1(do_float_roundw_s, fp0, fp0);
6339 gen_store_fpr32(fp0, fd);
6346 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6348 gen_load_fpr32(fp0, fs);
6349 tcg_gen_helper_1_1(do_float_truncw_s, fp0, fp0);
6350 gen_store_fpr32(fp0, fd);
6357 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6359 gen_load_fpr32(fp0, fs);
6360 tcg_gen_helper_1_1(do_float_ceilw_s, fp0, fp0);
6361 gen_store_fpr32(fp0, fd);
6368 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6370 gen_load_fpr32(fp0, fs);
6371 tcg_gen_helper_1_1(do_float_floorw_s, fp0, fp0);
6372 gen_store_fpr32(fp0, fd);
6378 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6383 int l1 = gen_new_label();
6384 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6385 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6387 gen_load_gpr(t0, ft);
6388 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6390 gen_load_fpr32(fp0, fs);
6391 gen_store_fpr32(fp0, fd);
6399 int l1 = gen_new_label();
6400 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6401 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6403 gen_load_gpr(t0, ft);
6404 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6406 gen_load_fpr32(fp0, fs);
6407 gen_store_fpr32(fp0, fd);
6416 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6418 gen_load_fpr32(fp0, fs);
6419 tcg_gen_helper_1_1(do_float_recip_s, fp0, fp0);
6420 gen_store_fpr32(fp0, fd);
6428 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6430 gen_load_fpr32(fp0, fs);
6431 tcg_gen_helper_1_1(do_float_rsqrt_s, fp0, fp0);
6432 gen_store_fpr32(fp0, fd);
6438 check_cp1_64bitmode(ctx);
6440 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6441 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6443 gen_load_fpr32(fp0, fs);
6444 gen_load_fpr32(fp1, fd);
6445 tcg_gen_helper_1_2(do_float_recip2_s, fp0, fp0, fp1);
6447 gen_store_fpr32(fp0, fd);
6453 check_cp1_64bitmode(ctx);
6455 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6457 gen_load_fpr32(fp0, fs);
6458 tcg_gen_helper_1_1(do_float_recip1_s, fp0, fp0);
6459 gen_store_fpr32(fp0, fd);
6465 check_cp1_64bitmode(ctx);
6467 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6469 gen_load_fpr32(fp0, fs);
6470 tcg_gen_helper_1_1(do_float_rsqrt1_s, fp0, fp0);
6471 gen_store_fpr32(fp0, fd);
6477 check_cp1_64bitmode(ctx);
6479 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6480 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6482 gen_load_fpr32(fp0, fs);
6483 gen_load_fpr32(fp1, ft);
6484 tcg_gen_helper_1_2(do_float_rsqrt2_s, fp0, fp0, fp1);
6486 gen_store_fpr32(fp0, fd);
6492 check_cp1_registers(ctx, fd);
6494 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6495 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6497 gen_load_fpr32(fp32, fs);
6498 tcg_gen_helper_1_1(do_float_cvtd_s, fp64, fp32);
6499 tcg_temp_free(fp32);
6500 gen_store_fpr64(ctx, fp64, fd);
6501 tcg_temp_free(fp64);
6507 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6509 gen_load_fpr32(fp0, fs);
6510 tcg_gen_helper_1_1(do_float_cvtw_s, fp0, fp0);
6511 gen_store_fpr32(fp0, fd);
6517 check_cp1_64bitmode(ctx);
6519 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6520 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6522 gen_load_fpr32(fp32, fs);
6523 tcg_gen_helper_1_1(do_float_cvtl_s, fp64, fp32);
6524 tcg_temp_free(fp32);
6525 gen_store_fpr64(ctx, fp64, fd);
6526 tcg_temp_free(fp64);
6531 check_cp1_64bitmode(ctx);
6533 TCGv fp64_0 = tcg_temp_new(TCG_TYPE_I64);
6534 TCGv fp64_1 = tcg_temp_new(TCG_TYPE_I64);
6535 TCGv fp32_0 = tcg_temp_new(TCG_TYPE_I32);
6536 TCGv fp32_1 = tcg_temp_new(TCG_TYPE_I32);
6538 gen_load_fpr32(fp32_0, fs);
6539 gen_load_fpr32(fp32_1, ft);
6540 tcg_gen_extu_i32_i64(fp64_0, fp32_0);
6541 tcg_gen_extu_i32_i64(fp64_1, fp32_1);
6542 tcg_temp_free(fp32_0);
6543 tcg_temp_free(fp32_1);
6544 tcg_gen_shli_i64(fp64_1, fp64_1, 32);
6545 tcg_gen_or_i64(fp64_0, fp64_0, fp64_1);
6546 tcg_temp_free(fp64_1);
6547 gen_store_fpr64(ctx, fp64_0, fd);
6548 tcg_temp_free(fp64_0);
6569 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6570 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6572 gen_load_fpr32(fp0, fs);
6573 gen_load_fpr32(fp1, ft);
6574 if (ctx->opcode & (1 << 6)) {
6576 gen_cmpabs_s(func-48, fp0, fp1, cc);
6577 opn = condnames_abs[func-48];
6579 gen_cmp_s(func-48, fp0, fp1, cc);
6580 opn = condnames[func-48];
6587 check_cp1_registers(ctx, fs | ft | fd);
6589 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6590 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6592 gen_load_fpr64(ctx, fp0, fs);
6593 gen_load_fpr64(ctx, fp1, ft);
6594 tcg_gen_helper_1_2(do_float_add_d, fp0, fp0, fp1);
6596 gen_store_fpr64(ctx, fp0, fd);
6603 check_cp1_registers(ctx, fs | ft | fd);
6605 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6606 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6608 gen_load_fpr64(ctx, fp0, fs);
6609 gen_load_fpr64(ctx, fp1, ft);
6610 tcg_gen_helper_1_2(do_float_sub_d, fp0, fp0, fp1);
6612 gen_store_fpr64(ctx, fp0, fd);
6619 check_cp1_registers(ctx, fs | ft | fd);
6621 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6622 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6624 gen_load_fpr64(ctx, fp0, fs);
6625 gen_load_fpr64(ctx, fp1, ft);
6626 tcg_gen_helper_1_2(do_float_mul_d, fp0, fp0, fp1);
6628 gen_store_fpr64(ctx, fp0, fd);
6635 check_cp1_registers(ctx, fs | ft | fd);
6637 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6638 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6640 gen_load_fpr64(ctx, fp0, fs);
6641 gen_load_fpr64(ctx, fp1, ft);
6642 tcg_gen_helper_1_2(do_float_div_d, fp0, fp0, fp1);
6644 gen_store_fpr64(ctx, fp0, fd);
6651 check_cp1_registers(ctx, fs | fd);
6653 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6655 gen_load_fpr64(ctx, fp0, fs);
6656 tcg_gen_helper_1_1(do_float_sqrt_d, fp0, fp0);
6657 gen_store_fpr64(ctx, fp0, fd);
6663 check_cp1_registers(ctx, fs | fd);
6665 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6667 gen_load_fpr64(ctx, fp0, fs);
6668 tcg_gen_helper_1_1(do_float_abs_d, fp0, fp0);
6669 gen_store_fpr64(ctx, fp0, fd);
6675 check_cp1_registers(ctx, fs | fd);
6677 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6679 gen_load_fpr64(ctx, fp0, fs);
6680 gen_store_fpr64(ctx, fp0, fd);
6686 check_cp1_registers(ctx, fs | fd);
6688 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6690 gen_load_fpr64(ctx, fp0, fs);
6691 tcg_gen_helper_1_1(do_float_chs_d, fp0, fp0);
6692 gen_store_fpr64(ctx, fp0, fd);
6698 check_cp1_64bitmode(ctx);
6700 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6702 gen_load_fpr64(ctx, fp0, fs);
6703 tcg_gen_helper_1_1(do_float_roundl_d, fp0, fp0);
6704 gen_store_fpr64(ctx, fp0, fd);
6710 check_cp1_64bitmode(ctx);
6712 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6714 gen_load_fpr64(ctx, fp0, fs);
6715 tcg_gen_helper_1_1(do_float_truncl_d, fp0, fp0);
6716 gen_store_fpr64(ctx, fp0, fd);
6722 check_cp1_64bitmode(ctx);
6724 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6726 gen_load_fpr64(ctx, fp0, fs);
6727 tcg_gen_helper_1_1(do_float_ceill_d, fp0, fp0);
6728 gen_store_fpr64(ctx, fp0, fd);
6734 check_cp1_64bitmode(ctx);
6736 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6738 gen_load_fpr64(ctx, fp0, fs);
6739 tcg_gen_helper_1_1(do_float_floorl_d, fp0, fp0);
6740 gen_store_fpr64(ctx, fp0, fd);
6746 check_cp1_registers(ctx, fs);
6748 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6749 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6751 gen_load_fpr64(ctx, fp64, fs);
6752 tcg_gen_helper_1_1(do_float_roundw_d, fp32, fp64);
6753 tcg_temp_free(fp64);
6754 gen_store_fpr32(fp32, fd);
6755 tcg_temp_free(fp32);
6760 check_cp1_registers(ctx, fs);
6762 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6763 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6765 gen_load_fpr64(ctx, fp64, fs);
6766 tcg_gen_helper_1_1(do_float_truncw_d, fp32, fp64);
6767 tcg_temp_free(fp64);
6768 gen_store_fpr32(fp32, fd);
6769 tcg_temp_free(fp32);
6774 check_cp1_registers(ctx, fs);
6776 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6777 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6779 gen_load_fpr64(ctx, fp64, fs);
6780 tcg_gen_helper_1_1(do_float_ceilw_d, fp32, fp64);
6781 tcg_temp_free(fp64);
6782 gen_store_fpr32(fp32, fd);
6783 tcg_temp_free(fp32);
6788 check_cp1_registers(ctx, fs);
6790 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6791 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6793 gen_load_fpr64(ctx, fp64, fs);
6794 tcg_gen_helper_1_1(do_float_floorw_d, fp32, fp64);
6795 tcg_temp_free(fp64);
6796 gen_store_fpr32(fp32, fd);
6797 tcg_temp_free(fp32);
6802 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6807 int l1 = gen_new_label();
6808 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6809 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6811 gen_load_gpr(t0, ft);
6812 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6814 gen_load_fpr64(ctx, fp0, fs);
6815 gen_store_fpr64(ctx, fp0, fd);
6823 int l1 = gen_new_label();
6824 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6825 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6827 gen_load_gpr(t0, ft);
6828 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6830 gen_load_fpr64(ctx, fp0, fs);
6831 gen_store_fpr64(ctx, fp0, fd);
6838 check_cp1_64bitmode(ctx);
6840 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6842 gen_load_fpr64(ctx, fp0, fs);
6843 tcg_gen_helper_1_1(do_float_recip_d, fp0, fp0);
6844 gen_store_fpr64(ctx, fp0, fd);
6850 check_cp1_64bitmode(ctx);
6852 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6854 gen_load_fpr64(ctx, fp0, fs);
6855 tcg_gen_helper_1_1(do_float_rsqrt_d, fp0, fp0);
6856 gen_store_fpr64(ctx, fp0, fd);
6862 check_cp1_64bitmode(ctx);
6864 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6865 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6867 gen_load_fpr64(ctx, fp0, fs);
6868 gen_load_fpr64(ctx, fp1, ft);
6869 tcg_gen_helper_1_2(do_float_recip2_d, fp0, fp0, fp1);
6871 gen_store_fpr64(ctx, fp0, fd);
6877 check_cp1_64bitmode(ctx);
6879 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6881 gen_load_fpr64(ctx, fp0, fs);
6882 tcg_gen_helper_1_1(do_float_recip1_d, fp0, fp0);
6883 gen_store_fpr64(ctx, fp0, fd);
6889 check_cp1_64bitmode(ctx);
6891 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6893 gen_load_fpr64(ctx, fp0, fs);
6894 tcg_gen_helper_1_1(do_float_rsqrt1_d, fp0, fp0);
6895 gen_store_fpr64(ctx, fp0, fd);
6901 check_cp1_64bitmode(ctx);
6903 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6904 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6906 gen_load_fpr64(ctx, fp0, fs);
6907 gen_load_fpr64(ctx, fp1, ft);
6908 tcg_gen_helper_1_2(do_float_rsqrt2_d, fp0, fp0, fp1);
6910 gen_store_fpr64(ctx, fp0, fd);
6932 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6933 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6935 gen_load_fpr64(ctx, fp0, fs);
6936 gen_load_fpr64(ctx, fp1, ft);
6937 if (ctx->opcode & (1 << 6)) {
6939 check_cp1_registers(ctx, fs | ft);
6940 gen_cmpabs_d(func-48, fp0, fp1, cc);
6941 opn = condnames_abs[func-48];
6943 check_cp1_registers(ctx, fs | ft);
6944 gen_cmp_d(func-48, fp0, fp1, cc);
6945 opn = condnames[func-48];
6952 check_cp1_registers(ctx, fs);
6954 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6955 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6957 gen_load_fpr64(ctx, fp64, fs);
6958 tcg_gen_helper_1_1(do_float_cvts_d, fp32, fp64);
6959 tcg_temp_free(fp64);
6960 gen_store_fpr32(fp32, fd);
6961 tcg_temp_free(fp32);
6966 check_cp1_registers(ctx, fs);
6968 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6969 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6971 gen_load_fpr64(ctx, fp64, fs);
6972 tcg_gen_helper_1_1(do_float_cvtw_d, fp32, fp64);
6973 tcg_temp_free(fp64);
6974 gen_store_fpr32(fp32, fd);
6975 tcg_temp_free(fp32);
6980 check_cp1_64bitmode(ctx);
6982 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6984 gen_load_fpr64(ctx, fp0, fs);
6985 tcg_gen_helper_1_1(do_float_cvtl_d, fp0, fp0);
6986 gen_store_fpr64(ctx, fp0, fd);
6993 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6995 gen_load_fpr32(fp0, fs);
6996 tcg_gen_helper_1_1(do_float_cvts_w, fp0, fp0);
6997 gen_store_fpr32(fp0, fd);
7003 check_cp1_registers(ctx, fd);
7005 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
7006 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
7008 gen_load_fpr32(fp32, fs);
7009 tcg_gen_helper_1_1(do_float_cvtd_w, fp64, fp32);
7010 tcg_temp_free(fp32);
7011 gen_store_fpr64(ctx, fp64, fd);
7012 tcg_temp_free(fp64);
7017 check_cp1_64bitmode(ctx);
7019 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
7020 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
7022 gen_load_fpr64(ctx, fp64, fs);
7023 tcg_gen_helper_1_1(do_float_cvts_l, fp32, fp64);
7024 tcg_temp_free(fp64);
7025 gen_store_fpr32(fp32, fd);
7026 tcg_temp_free(fp32);
7031 check_cp1_64bitmode(ctx);
7033 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7035 gen_load_fpr64(ctx, fp0, fs);
7036 tcg_gen_helper_1_1(do_float_cvtd_l, fp0, fp0);
7037 gen_store_fpr64(ctx, fp0, fd);
7043 check_cp1_64bitmode(ctx);
7045 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7047 gen_load_fpr64(ctx, fp0, fs);
7048 tcg_gen_helper_1_1(do_float_cvtps_pw, fp0, fp0);
7049 gen_store_fpr64(ctx, fp0, fd);
7055 check_cp1_64bitmode(ctx);
7057 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7058 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7060 gen_load_fpr64(ctx, fp0, fs);
7061 gen_load_fpr64(ctx, fp1, ft);
7062 tcg_gen_helper_1_2(do_float_add_ps, fp0, fp0, fp1);
7064 gen_store_fpr64(ctx, fp0, fd);
7070 check_cp1_64bitmode(ctx);
7072 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7073 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7075 gen_load_fpr64(ctx, fp0, fs);
7076 gen_load_fpr64(ctx, fp1, ft);
7077 tcg_gen_helper_1_2(do_float_sub_ps, fp0, fp0, fp1);
7079 gen_store_fpr64(ctx, fp0, fd);
7085 check_cp1_64bitmode(ctx);
7087 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7088 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7090 gen_load_fpr64(ctx, fp0, fs);
7091 gen_load_fpr64(ctx, fp1, ft);
7092 tcg_gen_helper_1_2(do_float_mul_ps, fp0, fp0, fp1);
7094 gen_store_fpr64(ctx, fp0, fd);
7100 check_cp1_64bitmode(ctx);
7102 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7104 gen_load_fpr64(ctx, fp0, fs);
7105 tcg_gen_helper_1_1(do_float_abs_ps, fp0, fp0);
7106 gen_store_fpr64(ctx, fp0, fd);
7112 check_cp1_64bitmode(ctx);
7114 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7116 gen_load_fpr64(ctx, fp0, fs);
7117 gen_store_fpr64(ctx, fp0, fd);
7123 check_cp1_64bitmode(ctx);
7125 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7127 gen_load_fpr64(ctx, fp0, fs);
7128 tcg_gen_helper_1_1(do_float_chs_ps, fp0, fp0);
7129 gen_store_fpr64(ctx, fp0, fd);
7135 check_cp1_64bitmode(ctx);
7136 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
7140 check_cp1_64bitmode(ctx);
7142 int l1 = gen_new_label();
7143 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7144 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7145 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7147 gen_load_gpr(t0, ft);
7148 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7150 gen_load_fpr32(fp0, fs);
7151 gen_load_fpr32h(fph0, fs);
7152 gen_store_fpr32(fp0, fd);
7153 gen_store_fpr32h(fph0, fd);
7155 tcg_temp_free(fph0);
7161 check_cp1_64bitmode(ctx);
7163 int l1 = gen_new_label();
7164 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7165 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7166 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7168 gen_load_gpr(t0, ft);
7169 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
7171 gen_load_fpr32(fp0, fs);
7172 gen_load_fpr32h(fph0, fs);
7173 gen_store_fpr32(fp0, fd);
7174 gen_store_fpr32h(fph0, fd);
7176 tcg_temp_free(fph0);
7182 check_cp1_64bitmode(ctx);
7184 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7185 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7187 gen_load_fpr64(ctx, fp0, ft);
7188 gen_load_fpr64(ctx, fp1, fs);
7189 tcg_gen_helper_1_2(do_float_addr_ps, fp0, fp0, fp1);
7191 gen_store_fpr64(ctx, fp0, fd);
7197 check_cp1_64bitmode(ctx);
7199 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7200 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7202 gen_load_fpr64(ctx, fp0, ft);
7203 gen_load_fpr64(ctx, fp1, fs);
7204 tcg_gen_helper_1_2(do_float_mulr_ps, fp0, fp0, fp1);
7206 gen_store_fpr64(ctx, fp0, fd);
7212 check_cp1_64bitmode(ctx);
7214 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7215 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7217 gen_load_fpr64(ctx, fp0, fs);
7218 gen_load_fpr64(ctx, fp1, fd);
7219 tcg_gen_helper_1_2(do_float_recip2_ps, fp0, fp0, fp1);
7221 gen_store_fpr64(ctx, fp0, fd);
7227 check_cp1_64bitmode(ctx);
7229 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7231 gen_load_fpr64(ctx, fp0, fs);
7232 tcg_gen_helper_1_1(do_float_recip1_ps, fp0, fp0);
7233 gen_store_fpr64(ctx, fp0, fd);
7239 check_cp1_64bitmode(ctx);
7241 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7243 gen_load_fpr64(ctx, fp0, fs);
7244 tcg_gen_helper_1_1(do_float_rsqrt1_ps, fp0, fp0);
7245 gen_store_fpr64(ctx, fp0, fd);
7251 check_cp1_64bitmode(ctx);
7253 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7254 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7256 gen_load_fpr64(ctx, fp0, fs);
7257 gen_load_fpr64(ctx, fp1, ft);
7258 tcg_gen_helper_1_2(do_float_rsqrt2_ps, fp0, fp0, fp1);
7260 gen_store_fpr64(ctx, fp0, fd);
7266 check_cp1_64bitmode(ctx);
7268 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7270 gen_load_fpr32h(fp0, fs);
7271 tcg_gen_helper_1_1(do_float_cvts_pu, fp0, fp0);
7272 gen_store_fpr32(fp0, fd);
7278 check_cp1_64bitmode(ctx);
7280 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7282 gen_load_fpr64(ctx, fp0, fs);
7283 tcg_gen_helper_1_1(do_float_cvtpw_ps, fp0, fp0);
7284 gen_store_fpr64(ctx, fp0, fd);
7290 check_cp1_64bitmode(ctx);
7292 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7294 gen_load_fpr32(fp0, fs);
7295 tcg_gen_helper_1_1(do_float_cvts_pl, fp0, fp0);
7296 gen_store_fpr32(fp0, fd);
7302 check_cp1_64bitmode(ctx);
7304 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7305 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7307 gen_load_fpr32(fp0, fs);
7308 gen_load_fpr32(fp1, ft);
7309 gen_store_fpr32h(fp0, fd);
7310 gen_store_fpr32(fp1, fd);
7317 check_cp1_64bitmode(ctx);
7319 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7320 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7322 gen_load_fpr32(fp0, fs);
7323 gen_load_fpr32h(fp1, ft);
7324 gen_store_fpr32(fp1, fd);
7325 gen_store_fpr32h(fp0, fd);
7332 check_cp1_64bitmode(ctx);
7334 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7335 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7337 gen_load_fpr32h(fp0, fs);
7338 gen_load_fpr32(fp1, ft);
7339 gen_store_fpr32(fp1, fd);
7340 gen_store_fpr32h(fp0, fd);
7347 check_cp1_64bitmode(ctx);
7349 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7350 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7352 gen_load_fpr32h(fp0, fs);
7353 gen_load_fpr32h(fp1, ft);
7354 gen_store_fpr32(fp1, fd);
7355 gen_store_fpr32h(fp0, fd);
7377 check_cp1_64bitmode(ctx);
7379 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7380 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7382 gen_load_fpr64(ctx, fp0, fs);
7383 gen_load_fpr64(ctx, fp1, ft);
7384 if (ctx->opcode & (1 << 6)) {
7385 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7386 opn = condnames_abs[func-48];
7388 gen_cmp_ps(func-48, fp0, fp1, cc);
7389 opn = condnames[func-48];
7397 generate_exception (ctx, EXCP_RI);
7402 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7405 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7408 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7413 /* Coprocessor 3 (FPU) */
7414 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7415 int fd, int fs, int base, int index)
7417 const char *opn = "extended float load/store";
7419 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7420 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7423 gen_load_gpr(t0, index);
7424 } else if (index == 0) {
7425 gen_load_gpr(t0, base);
7427 gen_load_gpr(t0, base);
7428 gen_load_gpr(t1, index);
7429 gen_op_addr_add(t0, t1);
7431 /* Don't do NOP if destination is zero: we must perform the actual
7437 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7439 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
7440 gen_store_fpr32(fp0, fd);
7447 check_cp1_registers(ctx, fd);
7449 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7451 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7452 gen_store_fpr64(ctx, fp0, fd);
7458 check_cp1_64bitmode(ctx);
7459 tcg_gen_andi_tl(t0, t0, ~0x7);
7461 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7463 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7464 gen_store_fpr64(ctx, fp0, fd);
7472 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7474 gen_load_fpr32(fp0, fs);
7475 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
7483 check_cp1_registers(ctx, fs);
7485 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7487 gen_load_fpr64(ctx, fp0, fs);
7488 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7495 check_cp1_64bitmode(ctx);
7496 tcg_gen_andi_tl(t0, t0, ~0x7);
7498 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7500 gen_load_fpr64(ctx, fp0, fs);
7501 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7509 generate_exception(ctx, EXCP_RI);
7516 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7517 regnames[index], regnames[base]);
7520 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7521 int fd, int fr, int fs, int ft)
7523 const char *opn = "flt3_arith";
7527 check_cp1_64bitmode(ctx);
7529 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7530 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7531 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7532 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
7533 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
7534 int l1 = gen_new_label();
7535 int l2 = gen_new_label();
7537 gen_load_gpr(t0, fr);
7538 tcg_gen_andi_tl(t0, t0, 0x7);
7539 gen_load_fpr32(fp0, fs);
7540 gen_load_fpr32h(fph0, fs);
7541 gen_load_fpr32(fp1, ft);
7542 gen_load_fpr32h(fph1, ft);
7544 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7545 gen_store_fpr32(fp0, fd);
7546 gen_store_fpr32h(fph0, fd);
7549 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7551 #ifdef TARGET_WORDS_BIGENDIAN
7552 gen_store_fpr32(fph1, fd);
7553 gen_store_fpr32h(fp0, fd);
7555 gen_store_fpr32(fph0, fd);
7556 gen_store_fpr32h(fp1, fd);
7560 tcg_temp_free(fph0);
7562 tcg_temp_free(fph1);
7569 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7570 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7571 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7573 gen_load_fpr32(fp0, fs);
7574 gen_load_fpr32(fp1, ft);
7575 gen_load_fpr32(fp2, fr);
7576 tcg_gen_helper_1_3(do_float_muladd_s, fp2, fp0, fp1, fp2);
7579 gen_store_fpr32(fp2, fd);
7586 check_cp1_registers(ctx, fd | fs | ft | fr);
7588 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7589 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7590 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7592 gen_load_fpr64(ctx, fp0, fs);
7593 gen_load_fpr64(ctx, fp1, ft);
7594 gen_load_fpr64(ctx, fp2, fr);
7595 tcg_gen_helper_1_3(do_float_muladd_d, fp2, fp0, fp1, fp2);
7598 gen_store_fpr64(ctx, fp2, fd);
7604 check_cp1_64bitmode(ctx);
7606 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7607 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7608 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7610 gen_load_fpr64(ctx, fp0, fs);
7611 gen_load_fpr64(ctx, fp1, ft);
7612 gen_load_fpr64(ctx, fp2, fr);
7613 tcg_gen_helper_1_3(do_float_muladd_ps, fp2, fp0, fp1, fp2);
7616 gen_store_fpr64(ctx, fp2, fd);
7624 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7625 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7626 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7628 gen_load_fpr32(fp0, fs);
7629 gen_load_fpr32(fp1, ft);
7630 gen_load_fpr32(fp2, fr);
7631 tcg_gen_helper_1_3(do_float_mulsub_s, fp2, fp0, fp1, fp2);
7634 gen_store_fpr32(fp2, fd);
7641 check_cp1_registers(ctx, fd | fs | ft | fr);
7643 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7644 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7645 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7647 gen_load_fpr64(ctx, fp0, fs);
7648 gen_load_fpr64(ctx, fp1, ft);
7649 gen_load_fpr64(ctx, fp2, fr);
7650 tcg_gen_helper_1_3(do_float_mulsub_d, fp2, fp0, fp1, fp2);
7653 gen_store_fpr64(ctx, fp2, fd);
7659 check_cp1_64bitmode(ctx);
7661 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7662 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7663 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7665 gen_load_fpr64(ctx, fp0, fs);
7666 gen_load_fpr64(ctx, fp1, ft);
7667 gen_load_fpr64(ctx, fp2, fr);
7668 tcg_gen_helper_1_3(do_float_mulsub_ps, fp2, fp0, fp1, fp2);
7671 gen_store_fpr64(ctx, fp2, fd);
7679 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7680 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7681 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7683 gen_load_fpr32(fp0, fs);
7684 gen_load_fpr32(fp1, ft);
7685 gen_load_fpr32(fp2, fr);
7686 tcg_gen_helper_1_3(do_float_nmuladd_s, fp2, fp0, fp1, fp2);
7689 gen_store_fpr32(fp2, fd);
7696 check_cp1_registers(ctx, fd | fs | ft | fr);
7698 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7699 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7700 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7702 gen_load_fpr64(ctx, fp0, fs);
7703 gen_load_fpr64(ctx, fp1, ft);
7704 gen_load_fpr64(ctx, fp2, fr);
7705 tcg_gen_helper_1_3(do_float_nmuladd_d, fp2, fp0, fp1, fp2);
7708 gen_store_fpr64(ctx, fp2, fd);
7714 check_cp1_64bitmode(ctx);
7716 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7717 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7718 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7720 gen_load_fpr64(ctx, fp0, fs);
7721 gen_load_fpr64(ctx, fp1, ft);
7722 gen_load_fpr64(ctx, fp2, fr);
7723 tcg_gen_helper_1_3(do_float_nmuladd_ps, fp2, fp0, fp1, fp2);
7726 gen_store_fpr64(ctx, fp2, fd);
7734 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7735 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7736 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7738 gen_load_fpr32(fp0, fs);
7739 gen_load_fpr32(fp1, ft);
7740 gen_load_fpr32(fp2, fr);
7741 tcg_gen_helper_1_3(do_float_nmulsub_s, fp2, fp0, fp1, fp2);
7744 gen_store_fpr32(fp2, fd);
7751 check_cp1_registers(ctx, fd | fs | ft | fr);
7753 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7754 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7755 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7757 gen_load_fpr64(ctx, fp0, fs);
7758 gen_load_fpr64(ctx, fp1, ft);
7759 gen_load_fpr64(ctx, fp2, fr);
7760 tcg_gen_helper_1_3(do_float_nmulsub_d, fp2, fp0, fp1, fp2);
7763 gen_store_fpr64(ctx, fp2, fd);
7769 check_cp1_64bitmode(ctx);
7771 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7772 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7773 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7775 gen_load_fpr64(ctx, fp0, fs);
7776 gen_load_fpr64(ctx, fp1, ft);
7777 gen_load_fpr64(ctx, fp2, fr);
7778 tcg_gen_helper_1_3(do_float_nmulsub_ps, fp2, fp0, fp1, fp2);
7781 gen_store_fpr64(ctx, fp2, fd);
7788 generate_exception (ctx, EXCP_RI);
7791 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7792 fregnames[fs], fregnames[ft]);
7795 /* ISA extensions (ASEs) */
7796 /* MIPS16 extension to MIPS32 */
7797 /* SmartMIPS extension to MIPS32 */
7799 #if defined(TARGET_MIPS64)
7801 /* MDMX extension to MIPS64 */
7805 static void decode_opc (CPUState *env, DisasContext *ctx)
7809 uint32_t op, op1, op2;
7812 /* make sure instructions are on a word boundary */
7813 if (ctx->pc & 0x3) {
7814 env->CP0_BadVAddr = ctx->pc;
7815 generate_exception(ctx, EXCP_AdEL);
7819 /* Handle blikely not taken case */
7820 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7821 int l1 = gen_new_label();
7823 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7824 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7826 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
7828 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7829 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7830 tcg_temp_free(r_tmp);
7832 gen_goto_tb(ctx, 1, ctx->pc + 4);
7835 op = MASK_OP_MAJOR(ctx->opcode);
7836 rs = (ctx->opcode >> 21) & 0x1f;
7837 rt = (ctx->opcode >> 16) & 0x1f;
7838 rd = (ctx->opcode >> 11) & 0x1f;
7839 sa = (ctx->opcode >> 6) & 0x1f;
7840 imm = (int16_t)ctx->opcode;
7843 op1 = MASK_SPECIAL(ctx->opcode);
7845 case OPC_SLL: /* Arithmetic with immediate */
7846 case OPC_SRL ... OPC_SRA:
7847 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7849 case OPC_MOVZ ... OPC_MOVN:
7850 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7851 case OPC_SLLV: /* Arithmetic */
7852 case OPC_SRLV ... OPC_SRAV:
7853 case OPC_ADD ... OPC_NOR:
7854 case OPC_SLT ... OPC_SLTU:
7855 gen_arith(env, ctx, op1, rd, rs, rt);
7857 case OPC_MULT ... OPC_DIVU:
7859 check_insn(env, ctx, INSN_VR54XX);
7860 op1 = MASK_MUL_VR54XX(ctx->opcode);
7861 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7863 gen_muldiv(ctx, op1, rs, rt);
7865 case OPC_JR ... OPC_JALR:
7866 gen_compute_branch(ctx, op1, rs, rd, sa);
7868 case OPC_TGE ... OPC_TEQ: /* Traps */
7870 gen_trap(ctx, op1, rs, rt, -1);
7872 case OPC_MFHI: /* Move from HI/LO */
7874 gen_HILO(ctx, op1, rd);
7877 case OPC_MTLO: /* Move to HI/LO */
7878 gen_HILO(ctx, op1, rs);
7880 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7881 #ifdef MIPS_STRICT_STANDARD
7882 MIPS_INVAL("PMON / selsl");
7883 generate_exception(ctx, EXCP_RI);
7885 tcg_gen_helper_0_i(do_pmon, sa);
7889 generate_exception(ctx, EXCP_SYSCALL);
7892 generate_exception(ctx, EXCP_BREAK);
7895 #ifdef MIPS_STRICT_STANDARD
7897 generate_exception(ctx, EXCP_RI);
7899 /* Implemented as RI exception for now. */
7900 MIPS_INVAL("spim (unofficial)");
7901 generate_exception(ctx, EXCP_RI);
7909 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7910 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7911 save_cpu_state(ctx, 1);
7912 check_cp1_enabled(ctx);
7913 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7914 (ctx->opcode >> 16) & 1);
7916 generate_exception_err(ctx, EXCP_CpU, 1);
7920 #if defined(TARGET_MIPS64)
7921 /* MIPS64 specific opcodes */
7923 case OPC_DSRL ... OPC_DSRA:
7925 case OPC_DSRL32 ... OPC_DSRA32:
7926 check_insn(env, ctx, ISA_MIPS3);
7928 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7931 case OPC_DSRLV ... OPC_DSRAV:
7932 case OPC_DADD ... OPC_DSUBU:
7933 check_insn(env, ctx, ISA_MIPS3);
7935 gen_arith(env, ctx, op1, rd, rs, rt);
7937 case OPC_DMULT ... OPC_DDIVU:
7938 check_insn(env, ctx, ISA_MIPS3);
7940 gen_muldiv(ctx, op1, rs, rt);
7943 default: /* Invalid */
7944 MIPS_INVAL("special");
7945 generate_exception(ctx, EXCP_RI);
7950 op1 = MASK_SPECIAL2(ctx->opcode);
7952 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7953 case OPC_MSUB ... OPC_MSUBU:
7954 check_insn(env, ctx, ISA_MIPS32);
7955 gen_muldiv(ctx, op1, rs, rt);
7958 gen_arith(env, ctx, op1, rd, rs, rt);
7960 case OPC_CLZ ... OPC_CLO:
7961 check_insn(env, ctx, ISA_MIPS32);
7962 gen_cl(ctx, op1, rd, rs);
7965 /* XXX: not clear which exception should be raised
7966 * when in debug mode...
7968 check_insn(env, ctx, ISA_MIPS32);
7969 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7970 generate_exception(ctx, EXCP_DBp);
7972 generate_exception(ctx, EXCP_DBp);
7976 #if defined(TARGET_MIPS64)
7977 case OPC_DCLZ ... OPC_DCLO:
7978 check_insn(env, ctx, ISA_MIPS64);
7980 gen_cl(ctx, op1, rd, rs);
7983 default: /* Invalid */
7984 MIPS_INVAL("special2");
7985 generate_exception(ctx, EXCP_RI);
7990 op1 = MASK_SPECIAL3(ctx->opcode);
7994 check_insn(env, ctx, ISA_MIPS32R2);
7995 gen_bitops(ctx, op1, rt, rs, sa, rd);
7998 check_insn(env, ctx, ISA_MIPS32R2);
7999 op2 = MASK_BSHFL(ctx->opcode);
8001 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8002 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8006 gen_load_gpr(t1, rt);
8007 tcg_gen_helper_1_1(do_wsbh, t0, t1);
8008 gen_store_gpr(t0, rd);
8011 gen_load_gpr(t1, rt);
8012 tcg_gen_ext8s_tl(t0, t1);
8013 gen_store_gpr(t0, rd);
8016 gen_load_gpr(t1, rt);
8017 tcg_gen_ext16s_tl(t0, t1);
8018 gen_store_gpr(t0, rd);
8020 default: /* Invalid */
8021 MIPS_INVAL("bshfl");
8022 generate_exception(ctx, EXCP_RI);
8030 check_insn(env, ctx, ISA_MIPS32R2);
8032 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8036 save_cpu_state(ctx, 1);
8037 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
8040 save_cpu_state(ctx, 1);
8041 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
8044 save_cpu_state(ctx, 1);
8045 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
8048 save_cpu_state(ctx, 1);
8049 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
8052 if (env->user_mode_only) {
8053 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
8056 /* XXX: Some CPUs implement this in hardware.
8057 Not supported yet. */
8059 default: /* Invalid */
8060 MIPS_INVAL("rdhwr");
8061 generate_exception(ctx, EXCP_RI);
8064 gen_store_gpr(t0, rt);
8069 check_insn(env, ctx, ASE_MT);
8071 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8072 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8074 gen_load_gpr(t0, rt);
8075 gen_load_gpr(t1, rs);
8076 tcg_gen_helper_0_2(do_fork, t0, t1);
8082 check_insn(env, ctx, ASE_MT);
8084 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8086 gen_load_gpr(t0, rs);
8087 tcg_gen_helper_1_1(do_yield, t0, t0);
8088 gen_store_gpr(t0, rd);
8092 #if defined(TARGET_MIPS64)
8093 case OPC_DEXTM ... OPC_DEXT:
8094 case OPC_DINSM ... OPC_DINS:
8095 check_insn(env, ctx, ISA_MIPS64R2);
8097 gen_bitops(ctx, op1, rt, rs, sa, rd);
8100 check_insn(env, ctx, ISA_MIPS64R2);
8102 op2 = MASK_DBSHFL(ctx->opcode);
8104 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8105 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8109 gen_load_gpr(t1, rt);
8110 tcg_gen_helper_1_1(do_dsbh, t0, t1);
8113 gen_load_gpr(t1, rt);
8114 tcg_gen_helper_1_1(do_dshd, t0, t1);
8116 default: /* Invalid */
8117 MIPS_INVAL("dbshfl");
8118 generate_exception(ctx, EXCP_RI);
8121 gen_store_gpr(t0, rd);
8127 default: /* Invalid */
8128 MIPS_INVAL("special3");
8129 generate_exception(ctx, EXCP_RI);
8134 op1 = MASK_REGIMM(ctx->opcode);
8136 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
8137 case OPC_BLTZAL ... OPC_BGEZALL:
8138 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
8140 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
8142 gen_trap(ctx, op1, rs, -1, imm);
8145 check_insn(env, ctx, ISA_MIPS32R2);
8148 default: /* Invalid */
8149 MIPS_INVAL("regimm");
8150 generate_exception(ctx, EXCP_RI);
8155 check_cp0_enabled(ctx);
8156 op1 = MASK_CP0(ctx->opcode);
8162 #if defined(TARGET_MIPS64)
8166 #ifndef CONFIG_USER_ONLY
8167 if (!env->user_mode_only)
8168 gen_cp0(env, ctx, op1, rt, rd);
8169 #endif /* !CONFIG_USER_ONLY */
8171 case OPC_C0_FIRST ... OPC_C0_LAST:
8172 #ifndef CONFIG_USER_ONLY
8173 if (!env->user_mode_only)
8174 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
8175 #endif /* !CONFIG_USER_ONLY */
8178 #ifndef CONFIG_USER_ONLY
8179 if (!env->user_mode_only) {
8180 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8182 op2 = MASK_MFMC0(ctx->opcode);
8185 check_insn(env, ctx, ASE_MT);
8186 tcg_gen_helper_1_1(do_dmt, t0, t0);
8189 check_insn(env, ctx, ASE_MT);
8190 tcg_gen_helper_1_1(do_emt, t0, t0);
8193 check_insn(env, ctx, ASE_MT);
8194 tcg_gen_helper_1_1(do_dvpe, t0, t0);
8197 check_insn(env, ctx, ASE_MT);
8198 tcg_gen_helper_1_1(do_evpe, t0, t0);
8201 check_insn(env, ctx, ISA_MIPS32R2);
8202 save_cpu_state(ctx, 1);
8203 tcg_gen_helper_1_0(do_di, t0);
8204 /* Stop translation as we may have switched the execution mode */
8205 ctx->bstate = BS_STOP;
8208 check_insn(env, ctx, ISA_MIPS32R2);
8209 save_cpu_state(ctx, 1);
8210 tcg_gen_helper_1_0(do_ei, t0);
8211 /* Stop translation as we may have switched the execution mode */
8212 ctx->bstate = BS_STOP;
8214 default: /* Invalid */
8215 MIPS_INVAL("mfmc0");
8216 generate_exception(ctx, EXCP_RI);
8219 gen_store_gpr(t0, rt);
8222 #endif /* !CONFIG_USER_ONLY */
8225 check_insn(env, ctx, ISA_MIPS32R2);
8226 gen_load_srsgpr(rt, rd);
8229 check_insn(env, ctx, ISA_MIPS32R2);
8230 gen_store_srsgpr(rt, rd);
8234 generate_exception(ctx, EXCP_RI);
8238 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
8239 gen_arith_imm(env, ctx, op, rt, rs, imm);
8241 case OPC_J ... OPC_JAL: /* Jump */
8242 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
8243 gen_compute_branch(ctx, op, rs, rt, offset);
8245 case OPC_BEQ ... OPC_BGTZ: /* Branch */
8246 case OPC_BEQL ... OPC_BGTZL:
8247 gen_compute_branch(ctx, op, rs, rt, imm << 2);
8249 case OPC_LB ... OPC_LWR: /* Load and stores */
8250 case OPC_SB ... OPC_SW:
8254 gen_ldst(ctx, op, rt, rs, imm);
8257 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
8261 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
8265 /* Floating point (COP1). */
8270 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8271 save_cpu_state(ctx, 1);
8272 check_cp1_enabled(ctx);
8273 gen_flt_ldst(ctx, op, rt, rs, imm);
8275 generate_exception_err(ctx, EXCP_CpU, 1);
8280 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8281 save_cpu_state(ctx, 1);
8282 check_cp1_enabled(ctx);
8283 op1 = MASK_CP1(ctx->opcode);
8287 check_insn(env, ctx, ISA_MIPS32R2);
8292 gen_cp1(ctx, op1, rt, rd);
8294 #if defined(TARGET_MIPS64)
8297 check_insn(env, ctx, ISA_MIPS3);
8298 gen_cp1(ctx, op1, rt, rd);
8304 check_insn(env, ctx, ASE_MIPS3D);
8307 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8308 (rt >> 2) & 0x7, imm << 2);
8315 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8320 generate_exception (ctx, EXCP_RI);
8324 generate_exception_err(ctx, EXCP_CpU, 1);
8334 /* COP2: Not implemented. */
8335 generate_exception_err(ctx, EXCP_CpU, 2);
8339 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8340 save_cpu_state(ctx, 1);
8341 check_cp1_enabled(ctx);
8342 op1 = MASK_CP3(ctx->opcode);
8350 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8368 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8372 generate_exception (ctx, EXCP_RI);
8376 generate_exception_err(ctx, EXCP_CpU, 1);
8380 #if defined(TARGET_MIPS64)
8381 /* MIPS64 opcodes */
8383 case OPC_LDL ... OPC_LDR:
8384 case OPC_SDL ... OPC_SDR:
8389 check_insn(env, ctx, ISA_MIPS3);
8391 gen_ldst(ctx, op, rt, rs, imm);
8393 case OPC_DADDI ... OPC_DADDIU:
8394 check_insn(env, ctx, ISA_MIPS3);
8396 gen_arith_imm(env, ctx, op, rt, rs, imm);
8400 check_insn(env, ctx, ASE_MIPS16);
8401 /* MIPS16: Not implemented. */
8403 check_insn(env, ctx, ASE_MDMX);
8404 /* MDMX: Not implemented. */
8405 default: /* Invalid */
8406 MIPS_INVAL("major opcode");
8407 generate_exception(ctx, EXCP_RI);
8410 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8411 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8412 /* Branches completion */
8413 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8414 ctx->bstate = BS_BRANCH;
8415 save_cpu_state(ctx, 0);
8416 /* FIXME: Need to clear can_do_io. */
8419 /* unconditional branch */
8420 MIPS_DEBUG("unconditional branch");
8421 gen_goto_tb(ctx, 0, ctx->btarget);
8424 /* blikely taken case */
8425 MIPS_DEBUG("blikely branch taken");
8426 gen_goto_tb(ctx, 0, ctx->btarget);
8429 /* Conditional branch */
8430 MIPS_DEBUG("conditional branch");
8432 int l1 = gen_new_label();
8434 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8435 gen_goto_tb(ctx, 1, ctx->pc + 4);
8437 gen_goto_tb(ctx, 0, ctx->btarget);
8441 /* unconditional branch to register */
8442 MIPS_DEBUG("branch to register");
8443 tcg_gen_st_tl(btarget, cpu_env, offsetof(CPUState, active_tc.PC));
8447 MIPS_DEBUG("unknown branch");
8454 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8458 target_ulong pc_start;
8459 uint16_t *gen_opc_end;
8464 if (search_pc && loglevel)
8465 fprintf (logfile, "search pc %d\n", search_pc);
8468 /* Leave some spare opc slots for branch handling. */
8469 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8473 ctx.bstate = BS_NONE;
8474 /* Restore delay slot state from the tb context. */
8475 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8476 restore_cpu_state(env, &ctx);
8477 if (env->user_mode_only)
8478 ctx.mem_idx = MIPS_HFLAG_UM;
8480 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8482 max_insns = tb->cflags & CF_COUNT_MASK;
8484 max_insns = CF_COUNT_MASK;
8486 if (loglevel & CPU_LOG_TB_CPU) {
8487 fprintf(logfile, "------------------------------------------------\n");
8488 /* FIXME: This may print out stale hflags from env... */
8489 cpu_dump_state(env, logfile, fprintf, 0);
8492 #ifdef MIPS_DEBUG_DISAS
8493 if (loglevel & CPU_LOG_TB_IN_ASM)
8494 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
8495 tb, ctx.mem_idx, ctx.hflags);
8498 while (ctx.bstate == BS_NONE) {
8499 if (env->nb_breakpoints > 0) {
8500 for(j = 0; j < env->nb_breakpoints; j++) {
8501 if (env->breakpoints[j] == ctx.pc) {
8502 save_cpu_state(&ctx, 1);
8503 ctx.bstate = BS_BRANCH;
8504 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8505 /* Include the breakpoint location or the tb won't
8506 * be flushed when it must be. */
8508 goto done_generating;
8514 j = gen_opc_ptr - gen_opc_buf;
8518 gen_opc_instr_start[lj++] = 0;
8520 gen_opc_pc[lj] = ctx.pc;
8521 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8522 gen_opc_instr_start[lj] = 1;
8523 gen_opc_icount[lj] = num_insns;
8525 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8527 ctx.opcode = ldl_code(ctx.pc);
8528 decode_opc(env, &ctx);
8532 if (env->singlestep_enabled)
8535 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8538 if (gen_opc_ptr >= gen_opc_end)
8541 if (num_insns >= max_insns)
8543 #if defined (MIPS_SINGLE_STEP)
8547 if (tb->cflags & CF_LAST_IO)
8549 if (env->singlestep_enabled) {
8550 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8551 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8553 switch (ctx.bstate) {
8555 tcg_gen_helper_0_0(do_interrupt_restart);
8556 gen_goto_tb(&ctx, 0, ctx.pc);
8559 save_cpu_state(&ctx, 0);
8560 gen_goto_tb(&ctx, 0, ctx.pc);
8563 tcg_gen_helper_0_0(do_interrupt_restart);
8572 gen_icount_end(tb, num_insns);
8573 *gen_opc_ptr = INDEX_op_end;
8575 j = gen_opc_ptr - gen_opc_buf;
8578 gen_opc_instr_start[lj++] = 0;
8580 tb->size = ctx.pc - pc_start;
8581 tb->icount = num_insns;
8584 #if defined MIPS_DEBUG_DISAS
8585 if (loglevel & CPU_LOG_TB_IN_ASM)
8586 fprintf(logfile, "\n");
8588 if (loglevel & CPU_LOG_TB_IN_ASM) {
8589 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
8590 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
8591 fprintf(logfile, "\n");
8593 if (loglevel & CPU_LOG_TB_CPU) {
8594 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8599 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8601 gen_intermediate_code_internal(env, tb, 0);
8604 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8606 gen_intermediate_code_internal(env, tb, 1);
8609 static void fpu_dump_state(CPUState *env, FILE *f,
8610 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8614 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8616 #define printfpr(fp) \
8619 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8620 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8621 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8624 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8625 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8626 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8627 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8628 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8633 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8634 env->fpu->fcr0, env->fpu->fcr31, is_fpu64, env->fpu->fp_status,
8635 get_float_exception_flags(&env->fpu->fp_status));
8636 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8637 fpu_fprintf(f, "%3s: ", fregnames[i]);
8638 printfpr(&env->fpu->fpr[i]);
8644 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8645 /* Debug help: The architecture requires 32bit code to maintain proper
8646 sign-extended values on 64bit machines. */
8648 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8651 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8652 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8657 if (!SIGN_EXT_P(env->active_tc.PC))
8658 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8659 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8660 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8661 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8662 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8663 if (!SIGN_EXT_P(env->btarget))
8664 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8666 for (i = 0; i < 32; i++) {
8667 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8668 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8671 if (!SIGN_EXT_P(env->CP0_EPC))
8672 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8673 if (!SIGN_EXT_P(env->CP0_LLAddr))
8674 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8678 void cpu_dump_state (CPUState *env, FILE *f,
8679 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8684 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",
8685 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8686 env->hflags, env->btarget, env->bcond);
8687 for (i = 0; i < 32; i++) {
8689 cpu_fprintf(f, "GPR%02d:", i);
8690 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8692 cpu_fprintf(f, "\n");
8695 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8696 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8697 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8698 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8699 if (env->hflags & MIPS_HFLAG_FPU)
8700 fpu_dump_state(env, f, cpu_fprintf, flags);
8701 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8702 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8706 static void mips_tcg_init(void)
8710 /* Initialize various static tables. */
8714 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8715 bcond = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8716 offsetof(CPUState, bcond), "bcond");
8717 btarget = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8718 offsetof(CPUState, btarget), "btarget");
8719 current_fpu = tcg_global_mem_new(TCG_TYPE_PTR,
8721 offsetof(CPUState, fpu),
8724 /* register helpers */
8726 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8732 #include "translate_init.c"
8734 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8737 const mips_def_t *def;
8739 def = cpu_mips_find_by_name(cpu_model);
8742 env = qemu_mallocz(sizeof(CPUMIPSState));
8745 env->cpu_model = def;
8748 env->cpu_model_str = cpu_model;
8754 void cpu_reset (CPUMIPSState *env)
8756 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8761 #if defined(CONFIG_USER_ONLY)
8762 env->user_mode_only = 1;
8764 if (env->user_mode_only) {
8765 env->hflags = MIPS_HFLAG_UM;
8767 if (env->hflags & MIPS_HFLAG_BMASK) {
8768 /* If the exception was raised from a delay slot,
8769 come back to the jump. */
8770 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8772 env->CP0_ErrorEPC = env->active_tc.PC;
8774 env->active_tc.PC = (int32_t)0xBFC00000;
8776 /* SMP not implemented */
8777 env->CP0_EBase = 0x80000000;
8778 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8779 /* vectored interrupts not implemented, timer on int 7,
8780 no performance counters. */
8781 env->CP0_IntCtl = 0xe0000000;
8785 for (i = 0; i < 7; i++) {
8786 env->CP0_WatchLo[i] = 0;
8787 env->CP0_WatchHi[i] = 0x80000000;
8789 env->CP0_WatchLo[7] = 0;
8790 env->CP0_WatchHi[7] = 0;
8792 /* Count register increments in debug mode, EJTAG version 1 */
8793 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8794 env->hflags = MIPS_HFLAG_CP0;
8796 env->exception_index = EXCP_NONE;
8797 cpu_mips_register(env, env->cpu_model);
8800 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8801 unsigned long searched_pc, int pc_pos, void *puc)
8803 env->active_tc.PC = gen_opc_pc[pc_pos];
8804 env->hflags &= ~MIPS_HFLAG_BMASK;
8805 env->hflags |= gen_opc_hflags[pc_pos];