2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL = (0x00 << 26),
46 OPC_REGIMM = (0x01 << 26),
47 OPC_CP0 = (0x10 << 26),
48 OPC_CP1 = (0x11 << 26),
49 OPC_CP2 = (0x12 << 26),
50 OPC_CP3 = (0x13 << 26),
51 OPC_SPECIAL2 = (0x1C << 26),
52 OPC_SPECIAL3 = (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI = (0x08 << 26),
55 OPC_ADDIU = (0x09 << 26),
56 OPC_SLTI = (0x0A << 26),
57 OPC_SLTIU = (0x0B << 26),
58 OPC_ANDI = (0x0C << 26),
59 OPC_ORI = (0x0D << 26),
60 OPC_XORI = (0x0E << 26),
61 OPC_LUI = (0x0F << 26),
62 OPC_DADDI = (0x18 << 26),
63 OPC_DADDIU = (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL = (0x03 << 26),
67 OPC_BEQ = (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL = (0x14 << 26),
69 OPC_BNE = (0x05 << 26),
70 OPC_BNEL = (0x15 << 26),
71 OPC_BLEZ = (0x06 << 26),
72 OPC_BLEZL = (0x16 << 26),
73 OPC_BGTZ = (0x07 << 26),
74 OPC_BGTZL = (0x17 << 26),
75 OPC_JALX = (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL = (0x1A << 26),
78 OPC_LDR = (0x1B << 26),
79 OPC_LB = (0x20 << 26),
80 OPC_LH = (0x21 << 26),
81 OPC_LWL = (0x22 << 26),
82 OPC_LW = (0x23 << 26),
83 OPC_LBU = (0x24 << 26),
84 OPC_LHU = (0x25 << 26),
85 OPC_LWR = (0x26 << 26),
86 OPC_LWU = (0x27 << 26),
87 OPC_SB = (0x28 << 26),
88 OPC_SH = (0x29 << 26),
89 OPC_SWL = (0x2A << 26),
90 OPC_SW = (0x2B << 26),
91 OPC_SDL = (0x2C << 26),
92 OPC_SDR = (0x2D << 26),
93 OPC_SWR = (0x2E << 26),
94 OPC_LL = (0x30 << 26),
95 OPC_LLD = (0x34 << 26),
96 OPC_LD = (0x37 << 26),
97 OPC_SC = (0x38 << 26),
98 OPC_SCD = (0x3C << 26),
99 OPC_SD = (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1 = (0x31 << 26),
102 OPC_LWC2 = (0x32 << 26),
103 OPC_LDC1 = (0x35 << 26),
104 OPC_LDC2 = (0x36 << 26),
105 OPC_SWC1 = (0x39 << 26),
106 OPC_SWC2 = (0x3A << 26),
107 OPC_SDC1 = (0x3D << 26),
108 OPC_SDC2 = (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX = (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE = (0x2F << 26),
113 OPC_PREF = (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED = (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL = 0x00 | OPC_SPECIAL,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL = 0x02 | OPC_SPECIAL, /* also ROTR */
128 OPC_SRA = 0x03 | OPC_SPECIAL,
129 OPC_SLLV = 0x04 | OPC_SPECIAL,
130 OPC_SRLV = 0x06 | OPC_SPECIAL, /* also ROTRV */
131 OPC_SRAV = 0x07 | OPC_SPECIAL,
132 OPC_DSLLV = 0x14 | OPC_SPECIAL,
133 OPC_DSRLV = 0x16 | OPC_SPECIAL, /* also DROTRV */
134 OPC_DSRAV = 0x17 | OPC_SPECIAL,
135 OPC_DSLL = 0x38 | OPC_SPECIAL,
136 OPC_DSRL = 0x3A | OPC_SPECIAL, /* also DROTR */
137 OPC_DSRA = 0x3B | OPC_SPECIAL,
138 OPC_DSLL32 = 0x3C | OPC_SPECIAL,
139 OPC_DSRL32 = 0x3E | OPC_SPECIAL, /* also DROTR32 */
140 OPC_DSRA32 = 0x3F | OPC_SPECIAL,
141 /* Multiplication / division */
142 OPC_MULT = 0x18 | OPC_SPECIAL,
143 OPC_MULTU = 0x19 | OPC_SPECIAL,
144 OPC_DIV = 0x1A | OPC_SPECIAL,
145 OPC_DIVU = 0x1B | OPC_SPECIAL,
146 OPC_DMULT = 0x1C | OPC_SPECIAL,
147 OPC_DMULTU = 0x1D | OPC_SPECIAL,
148 OPC_DDIV = 0x1E | OPC_SPECIAL,
149 OPC_DDIVU = 0x1F | OPC_SPECIAL,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD = 0x20 | OPC_SPECIAL,
152 OPC_ADDU = 0x21 | OPC_SPECIAL,
153 OPC_SUB = 0x22 | OPC_SPECIAL,
154 OPC_SUBU = 0x23 | OPC_SPECIAL,
155 OPC_AND = 0x24 | OPC_SPECIAL,
156 OPC_OR = 0x25 | OPC_SPECIAL,
157 OPC_XOR = 0x26 | OPC_SPECIAL,
158 OPC_NOR = 0x27 | OPC_SPECIAL,
159 OPC_SLT = 0x2A | OPC_SPECIAL,
160 OPC_SLTU = 0x2B | OPC_SPECIAL,
161 OPC_DADD = 0x2C | OPC_SPECIAL,
162 OPC_DADDU = 0x2D | OPC_SPECIAL,
163 OPC_DSUB = 0x2E | OPC_SPECIAL,
164 OPC_DSUBU = 0x2F | OPC_SPECIAL,
166 OPC_JR = 0x08 | OPC_SPECIAL, /* Also JR.HB */
167 OPC_JALR = 0x09 | OPC_SPECIAL, /* Also JALR.HB */
169 OPC_TGE = 0x30 | OPC_SPECIAL,
170 OPC_TGEU = 0x31 | OPC_SPECIAL,
171 OPC_TLT = 0x32 | OPC_SPECIAL,
172 OPC_TLTU = 0x33 | OPC_SPECIAL,
173 OPC_TEQ = 0x34 | OPC_SPECIAL,
174 OPC_TNE = 0x36 | OPC_SPECIAL,
175 /* HI / LO registers load & stores */
176 OPC_MFHI = 0x10 | OPC_SPECIAL,
177 OPC_MTHI = 0x11 | OPC_SPECIAL,
178 OPC_MFLO = 0x12 | OPC_SPECIAL,
179 OPC_MTLO = 0x13 | OPC_SPECIAL,
180 /* Conditional moves */
181 OPC_MOVZ = 0x0A | OPC_SPECIAL,
182 OPC_MOVN = 0x0B | OPC_SPECIAL,
184 OPC_MOVCI = 0x01 | OPC_SPECIAL,
187 OPC_PMON = 0x05 | OPC_SPECIAL, /* inofficial */
188 OPC_SYSCALL = 0x0C | OPC_SPECIAL,
189 OPC_BREAK = 0x0D | OPC_SPECIAL,
190 OPC_SPIM = 0x0E | OPC_SPECIAL, /* inofficial */
191 OPC_SYNC = 0x0F | OPC_SPECIAL,
193 OPC_SPECIAL15_RESERVED = 0x15 | OPC_SPECIAL,
194 OPC_SPECIAL28_RESERVED = 0x28 | OPC_SPECIAL,
195 OPC_SPECIAL29_RESERVED = 0x29 | OPC_SPECIAL,
196 OPC_SPECIAL35_RESERVED = 0x35 | OPC_SPECIAL,
197 OPC_SPECIAL37_RESERVED = 0x37 | OPC_SPECIAL,
198 OPC_SPECIAL39_RESERVED = 0x39 | OPC_SPECIAL,
199 OPC_SPECIAL3D_RESERVED = 0x3D | OPC_SPECIAL,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS = (0x03 << 6) | OPC_MULT,
207 OPC_VR54XX_MULSU = (0x03 << 6) | OPC_MULTU,
208 OPC_VR54XX_MACC = (0x05 << 6) | OPC_MULT,
209 OPC_VR54XX_MACCU = (0x05 << 6) | OPC_MULTU,
210 OPC_VR54XX_MSAC = (0x07 << 6) | OPC_MULT,
211 OPC_VR54XX_MSACU = (0x07 << 6) | OPC_MULTU,
212 OPC_VR54XX_MULHI = (0x09 << 6) | OPC_MULT,
213 OPC_VR54XX_MULHIU = (0x09 << 6) | OPC_MULTU,
214 OPC_VR54XX_MULSHI = (0x0B << 6) | OPC_MULT,
215 OPC_VR54XX_MULSHIU = (0x0B << 6) | OPC_MULTU,
216 OPC_VR54XX_MACCHI = (0x0D << 6) | OPC_MULT,
217 OPC_VR54XX_MACCHIU = (0x0D << 6) | OPC_MULTU,
218 OPC_VR54XX_MSACHI = (0x0F << 6) | OPC_MULT,
219 OPC_VR54XX_MSACHIU = (0x0F << 6) | OPC_MULTU,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ = (0x00 << 16) | OPC_REGIMM,
227 OPC_BLTZL = (0x02 << 16) | OPC_REGIMM,
228 OPC_BGEZ = (0x01 << 16) | OPC_REGIMM,
229 OPC_BGEZL = (0x03 << 16) | OPC_REGIMM,
230 OPC_BLTZAL = (0x10 << 16) | OPC_REGIMM,
231 OPC_BLTZALL = (0x12 << 16) | OPC_REGIMM,
232 OPC_BGEZAL = (0x11 << 16) | OPC_REGIMM,
233 OPC_BGEZALL = (0x13 << 16) | OPC_REGIMM,
234 OPC_TGEI = (0x08 << 16) | OPC_REGIMM,
235 OPC_TGEIU = (0x09 << 16) | OPC_REGIMM,
236 OPC_TLTI = (0x0A << 16) | OPC_REGIMM,
237 OPC_TLTIU = (0x0B << 16) | OPC_REGIMM,
238 OPC_TEQI = (0x0C << 16) | OPC_REGIMM,
239 OPC_TNEI = (0x0E << 16) | OPC_REGIMM,
240 OPC_SYNCI = (0x1F << 16) | OPC_REGIMM,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD = 0x00 | OPC_SPECIAL2,
249 OPC_MADDU = 0x01 | OPC_SPECIAL2,
250 OPC_MUL = 0x02 | OPC_SPECIAL2,
251 OPC_MSUB = 0x04 | OPC_SPECIAL2,
252 OPC_MSUBU = 0x05 | OPC_SPECIAL2,
254 OPC_CLZ = 0x20 | OPC_SPECIAL2,
255 OPC_CLO = 0x21 | OPC_SPECIAL2,
256 OPC_DCLZ = 0x24 | OPC_SPECIAL2,
257 OPC_DCLO = 0x25 | OPC_SPECIAL2,
259 OPC_SDBBP = 0x3F | OPC_SPECIAL2,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT = 0x00 | OPC_SPECIAL3,
267 OPC_DEXTM = 0x01 | OPC_SPECIAL3,
268 OPC_DEXTU = 0x02 | OPC_SPECIAL3,
269 OPC_DEXT = 0x03 | OPC_SPECIAL3,
270 OPC_INS = 0x04 | OPC_SPECIAL3,
271 OPC_DINSM = 0x05 | OPC_SPECIAL3,
272 OPC_DINSU = 0x06 | OPC_SPECIAL3,
273 OPC_DINS = 0x07 | OPC_SPECIAL3,
274 OPC_FORK = 0x08 | OPC_SPECIAL3,
275 OPC_YIELD = 0x09 | OPC_SPECIAL3,
276 OPC_BSHFL = 0x20 | OPC_SPECIAL3,
277 OPC_DBSHFL = 0x24 | OPC_SPECIAL3,
278 OPC_RDHWR = 0x3B | OPC_SPECIAL3,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH = (0x02 << 6) | OPC_BSHFL,
286 OPC_SEB = (0x10 << 6) | OPC_BSHFL,
287 OPC_SEH = (0x18 << 6) | OPC_BSHFL,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH = (0x02 << 6) | OPC_DBSHFL,
295 OPC_DSHD = (0x05 << 6) | OPC_DBSHFL,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0 = (0x00 << 21) | OPC_CP0,
303 OPC_DMFC0 = (0x01 << 21) | OPC_CP0,
304 OPC_MTC0 = (0x04 << 21) | OPC_CP0,
305 OPC_DMTC0 = (0x05 << 21) | OPC_CP0,
306 OPC_MFTR = (0x08 << 21) | OPC_CP0,
307 OPC_RDPGPR = (0x0A << 21) | OPC_CP0,
308 OPC_MFMC0 = (0x0B << 21) | OPC_CP0,
309 OPC_MTTR = (0x0C << 21) | OPC_CP0,
310 OPC_WRPGPR = (0x0E << 21) | OPC_CP0,
311 OPC_C0 = (0x10 << 21) | OPC_CP0,
312 OPC_C0_FIRST = (0x10 << 21) | OPC_CP0,
313 OPC_C0_LAST = (0x1F << 21) | OPC_CP0,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT = 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
321 OPC_EMT = 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0,
322 OPC_DVPE = 0x01 | (0 << 5) | OPC_MFMC0,
323 OPC_EVPE = 0x01 | (1 << 5) | OPC_MFMC0,
324 OPC_DI = (0 << 5) | (0x0C << 11) | OPC_MFMC0,
325 OPC_EI = (1 << 5) | (0x0C << 11) | OPC_MFMC0,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR = 0x01 | OPC_C0,
333 OPC_TLBWI = 0x02 | OPC_C0,
334 OPC_TLBWR = 0x06 | OPC_C0,
335 OPC_TLBP = 0x08 | OPC_C0,
336 OPC_RFE = 0x10 | OPC_C0,
337 OPC_ERET = 0x18 | OPC_C0,
338 OPC_DERET = 0x1F | OPC_C0,
339 OPC_WAIT = 0x20 | OPC_C0,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1 = (0x00 << 21) | OPC_CP1,
347 OPC_DMFC1 = (0x01 << 21) | OPC_CP1,
348 OPC_CFC1 = (0x02 << 21) | OPC_CP1,
349 OPC_MFHC1 = (0x03 << 21) | OPC_CP1,
350 OPC_MTC1 = (0x04 << 21) | OPC_CP1,
351 OPC_DMTC1 = (0x05 << 21) | OPC_CP1,
352 OPC_CTC1 = (0x06 << 21) | OPC_CP1,
353 OPC_MTHC1 = (0x07 << 21) | OPC_CP1,
354 OPC_BC1 = (0x08 << 21) | OPC_CP1, /* bc */
355 OPC_BC1ANY2 = (0x09 << 21) | OPC_CP1,
356 OPC_BC1ANY4 = (0x0A << 21) | OPC_CP1,
357 OPC_S_FMT = (0x10 << 21) | OPC_CP1, /* 16: fmt=single fp */
358 OPC_D_FMT = (0x11 << 21) | OPC_CP1, /* 17: fmt=double fp */
359 OPC_E_FMT = (0x12 << 21) | OPC_CP1, /* 18: fmt=extended fp */
360 OPC_Q_FMT = (0x13 << 21) | OPC_CP1, /* 19: fmt=quad fp */
361 OPC_W_FMT = (0x14 << 21) | OPC_CP1, /* 20: fmt=32bit fixed */
362 OPC_L_FMT = (0x15 << 21) | OPC_CP1, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT = (0x16 << 21) | OPC_CP1, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F = (0x00 << 16) | OPC_BC1,
371 OPC_BC1T = (0x01 << 16) | OPC_BC1,
372 OPC_BC1FL = (0x02 << 16) | OPC_BC1,
373 OPC_BC1TL = (0x03 << 16) | OPC_BC1,
377 OPC_BC1FANY2 = (0x00 << 16) | OPC_BC1ANY2,
378 OPC_BC1TANY2 = (0x01 << 16) | OPC_BC1ANY2,
382 OPC_BC1FANY4 = (0x00 << 16) | OPC_BC1ANY4,
383 OPC_BC1TANY4 = (0x01 << 16) | OPC_BC1ANY4,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2 = (0x00 << 21) | OPC_CP2,
390 OPC_DMFC2 = (0x01 << 21) | OPC_CP2,
391 OPC_CFC2 = (0x02 << 21) | OPC_CP2,
392 OPC_MFHC2 = (0x03 << 21) | OPC_CP2,
393 OPC_MTC2 = (0x04 << 21) | OPC_CP2,
394 OPC_DMTC2 = (0x05 << 21) | OPC_CP2,
395 OPC_CTC2 = (0x06 << 21) | OPC_CP2,
396 OPC_MTHC2 = (0x07 << 21) | OPC_CP2,
397 OPC_BC2 = (0x08 << 21) | OPC_CP2,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1 = 0x00 | OPC_CP3,
404 OPC_LDXC1 = 0x01 | OPC_CP3,
405 OPC_LUXC1 = 0x05 | OPC_CP3,
406 OPC_SWXC1 = 0x08 | OPC_CP3,
407 OPC_SDXC1 = 0x09 | OPC_CP3,
408 OPC_SUXC1 = 0x0D | OPC_CP3,
409 OPC_PREFX = 0x0F | OPC_CP3,
410 OPC_ALNV_PS = 0x1E | OPC_CP3,
411 OPC_MADD_S = 0x20 | OPC_CP3,
412 OPC_MADD_D = 0x21 | OPC_CP3,
413 OPC_MADD_PS = 0x26 | OPC_CP3,
414 OPC_MSUB_S = 0x28 | OPC_CP3,
415 OPC_MSUB_D = 0x29 | OPC_CP3,
416 OPC_MSUB_PS = 0x2E | OPC_CP3,
417 OPC_NMADD_S = 0x30 | OPC_CP3,
418 OPC_NMADD_D = 0x31 | OPC_CP3,
419 OPC_NMADD_PS= 0x36 | OPC_CP3,
420 OPC_NMSUB_S = 0x38 | OPC_CP3,
421 OPC_NMSUB_D = 0x39 | OPC_CP3,
422 OPC_NMSUB_PS= 0x3E | OPC_CP3,
425 /* global register indices */
426 static TCGv cpu_env, cpu_gpr[32], cpu_PC;
427 static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC], cpu_ACX[MIPS_DSP_ACC];
428 static TCGv cpu_dspctrl, bcond, btarget;
429 static TCGv fpu_fpr32[32], fpu_fpr32h[32], fpu_fpr64[32], fpu_fcr0, fpu_fcr31;
431 #include "gen-icount.h"
433 static inline void tcg_gen_helper_0_i(void *func, uint32_t arg)
436 TCGv tmp = tcg_const_i32(arg);
438 tcg_gen_helper_0_1(func, tmp);
442 static inline void tcg_gen_helper_0_ii(void *func, uint32_t arg1, uint32_t arg2)
444 TCGv tmp1 = tcg_const_i32(arg1);
445 TCGv tmp2 = tcg_const_i32(arg2);
447 tcg_gen_helper_0_2(func, tmp1, tmp2);
452 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg1, uint32_t arg2)
454 TCGv tmp = tcg_const_i32(arg2);
456 tcg_gen_helper_0_2(func, arg1, tmp);
460 static inline void tcg_gen_helper_0_2i(void *func, TCGv arg1, TCGv arg2, uint32_t arg3)
462 TCGv tmp = tcg_const_i32(arg3);
464 tcg_gen_helper_0_3(func, arg1, arg2, tmp);
468 static inline void tcg_gen_helper_0_1ii(void *func, TCGv arg1, uint32_t arg2, uint32_t arg3)
470 TCGv tmp1 = tcg_const_i32(arg2);
471 TCGv tmp2 = tcg_const_i32(arg3);
473 tcg_gen_helper_0_3(func, arg1, tmp1, tmp2);
478 static inline void tcg_gen_helper_1_i(void *func, TCGv ret, uint32_t arg)
480 TCGv tmp = tcg_const_i32(arg);
482 tcg_gen_helper_1_1(func, ret, tmp);
486 static inline void tcg_gen_helper_1_1i(void *func, TCGv ret, TCGv arg1, uint32_t arg2)
488 TCGv tmp = tcg_const_i32(arg2);
490 tcg_gen_helper_1_2(func, ret, arg1, tmp);
494 static inline void tcg_gen_helper_1_1ii(void *func, TCGv ret, TCGv arg1, uint32_t arg2, uint32_t arg3)
496 TCGv tmp1 = tcg_const_i32(arg2);
497 TCGv tmp2 = tcg_const_i32(arg3);
499 tcg_gen_helper_1_3(func, ret, arg1, tmp1, tmp2);
504 static inline void tcg_gen_helper_1_2i(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3)
506 TCGv tmp = tcg_const_i32(arg3);
508 tcg_gen_helper_1_3(func, ret, arg1, arg2, tmp);
512 static inline void tcg_gen_helper_1_2ii(void *func, TCGv ret, TCGv arg1, TCGv arg2, uint32_t arg3, uint32_t arg4)
514 TCGv tmp1 = tcg_const_i32(arg3);
515 TCGv tmp2 = tcg_const_i32(arg4);
517 tcg_gen_helper_1_4(func, ret, arg1, arg2, tmp1, tmp2);
522 typedef struct DisasContext {
523 struct TranslationBlock *tb;
524 target_ulong pc, saved_pc;
526 /* Routine used to access memory */
528 uint32_t hflags, saved_hflags;
530 target_ulong btarget;
534 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
535 * exception condition */
536 BS_STOP = 1, /* We want to stop translation for any reason */
537 BS_BRANCH = 2, /* We reached a branch condition */
538 BS_EXCP = 3, /* We reached an exception condition */
541 static const char *regnames[] =
542 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
543 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
544 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
545 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
547 static const char *regnames_HI[] =
548 { "HI0", "HI1", "HI2", "HI3", };
550 static const char *regnames_LO[] =
551 { "LO0", "LO1", "LO2", "LO3", };
553 static const char *regnames_ACX[] =
554 { "ACX0", "ACX1", "ACX2", "ACX3", };
556 static const char *fregnames[] =
557 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
558 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
559 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
560 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
562 static const char *fregnames_64[] =
563 { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
564 "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15",
565 "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23",
566 "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31", };
568 static const char *fregnames_h[] =
569 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
570 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
571 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
572 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
574 #ifdef MIPS_DEBUG_DISAS
575 #define MIPS_DEBUG(fmt, args...) \
577 if (loglevel & CPU_LOG_TB_IN_ASM) { \
578 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
579 ctx->pc, ctx->opcode , ##args); \
583 #define MIPS_DEBUG(fmt, args...) do { } while(0)
586 #define MIPS_INVAL(op) \
588 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
589 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
592 /* General purpose registers moves. */
593 static inline void gen_load_gpr (TCGv t, int reg)
596 tcg_gen_movi_tl(t, 0);
598 tcg_gen_mov_tl(t, cpu_gpr[reg]);
601 static inline void gen_store_gpr (TCGv t, int reg)
604 tcg_gen_mov_tl(cpu_gpr[reg], t);
607 /* Moves to/from HI and LO registers. */
608 static inline void gen_load_HI (TCGv t, int reg)
610 tcg_gen_mov_tl(t, cpu_HI[reg]);
613 static inline void gen_store_HI (TCGv t, int reg)
615 tcg_gen_mov_tl(cpu_HI[reg], t);
618 static inline void gen_load_LO (TCGv t, int reg)
620 tcg_gen_mov_tl(t, cpu_LO[reg]);
623 static inline void gen_store_LO (TCGv t, int reg)
625 tcg_gen_mov_tl(cpu_LO[reg], t);
628 static inline void gen_load_ACX (TCGv t, int reg)
630 tcg_gen_mov_tl(t, cpu_ACX[reg]);
633 static inline void gen_store_ACX (TCGv t, int reg)
635 tcg_gen_mov_tl(cpu_ACX[reg], t);
638 /* Moves to/from shadow registers. */
639 static inline void gen_load_srsgpr (int from, int to)
641 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
644 tcg_gen_movi_tl(r_tmp1, 0);
646 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
648 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
649 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
650 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
651 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
652 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
654 tcg_gen_ld_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * from);
655 tcg_temp_free(r_tmp2);
657 gen_store_gpr(r_tmp1, to);
658 tcg_temp_free(r_tmp1);
661 static inline void gen_store_srsgpr (int from, int to)
664 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
665 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
667 gen_load_gpr(r_tmp1, from);
668 tcg_gen_ld_i32(r_tmp2, cpu_env, offsetof(CPUState, CP0_SRSCtl));
669 tcg_gen_shri_i32(r_tmp2, r_tmp2, CP0SRSCtl_PSS);
670 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xf);
671 tcg_gen_muli_i32(r_tmp2, r_tmp2, sizeof(target_ulong) * 32);
672 tcg_gen_add_i32(r_tmp2, cpu_env, r_tmp2);
674 tcg_gen_st_tl(r_tmp1, r_tmp2, sizeof(target_ulong) * to);
675 tcg_temp_free(r_tmp1);
676 tcg_temp_free(r_tmp2);
680 /* Floating point register moves. */
681 static inline void gen_load_fpr32 (TCGv t, int reg)
683 tcg_gen_mov_i32(t, fpu_fpr32[reg]);
686 static inline void gen_store_fpr32 (TCGv t, int reg)
688 tcg_gen_mov_i32(fpu_fpr32[reg], t);
691 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
693 if (ctx->hflags & MIPS_HFLAG_F64)
694 tcg_gen_mov_i64(t, fpu_fpr64[reg]);
696 tcg_gen_concat_i32_i64(t, fpu_fpr32[reg & ~1], fpu_fpr32[reg | 1]);
700 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
702 if (ctx->hflags & MIPS_HFLAG_F64)
703 tcg_gen_mov_i64(fpu_fpr64[reg], t);
705 tcg_gen_trunc_i64_i32(fpu_fpr32[reg & ~1], t);
706 tcg_gen_shri_i64(t, t, 32);
707 tcg_gen_trunc_i64_i32(fpu_fpr32[reg | 1], t);
711 static inline void gen_load_fpr32h (TCGv t, int reg)
713 tcg_gen_mov_i32(t, fpu_fpr32h[reg]);
716 static inline void gen_store_fpr32h (TCGv t, int reg)
718 tcg_gen_mov_i32(fpu_fpr32h[reg], t);
721 static inline void get_fp_cond (TCGv t)
723 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
724 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
726 tcg_gen_shri_i32(r_tmp2, fpu_fcr31, 24);
727 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
728 tcg_gen_shri_i32(r_tmp1, fpu_fcr31, 23);
729 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
730 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
731 tcg_temp_free(r_tmp1);
732 tcg_temp_free(r_tmp2);
735 typedef void (fcmp_fun32)(uint32_t, uint32_t, int);
736 typedef void (fcmp_fun64)(uint64_t, uint64_t, int);
738 #define FOP_CONDS(fcmp_fun, type, fmt) \
739 static fcmp_fun * fcmp ## type ## _ ## fmt ## _table[16] = { \
740 do_cmp ## type ## _ ## fmt ## _f, \
741 do_cmp ## type ## _ ## fmt ## _un, \
742 do_cmp ## type ## _ ## fmt ## _eq, \
743 do_cmp ## type ## _ ## fmt ## _ueq, \
744 do_cmp ## type ## _ ## fmt ## _olt, \
745 do_cmp ## type ## _ ## fmt ## _ult, \
746 do_cmp ## type ## _ ## fmt ## _ole, \
747 do_cmp ## type ## _ ## fmt ## _ule, \
748 do_cmp ## type ## _ ## fmt ## _sf, \
749 do_cmp ## type ## _ ## fmt ## _ngle, \
750 do_cmp ## type ## _ ## fmt ## _seq, \
751 do_cmp ## type ## _ ## fmt ## _ngl, \
752 do_cmp ## type ## _ ## fmt ## _lt, \
753 do_cmp ## type ## _ ## fmt ## _nge, \
754 do_cmp ## type ## _ ## fmt ## _le, \
755 do_cmp ## type ## _ ## fmt ## _ngt, \
757 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv a, TCGv b, int cc) \
759 tcg_gen_helper_0_2i(fcmp ## type ## _ ## fmt ## _table[n], a, b, cc); \
762 FOP_CONDS(fcmp_fun64, , d)
763 FOP_CONDS(fcmp_fun64, abs, d)
764 FOP_CONDS(fcmp_fun32, , s)
765 FOP_CONDS(fcmp_fun32, abs, s)
766 FOP_CONDS(fcmp_fun64, , ps)
767 FOP_CONDS(fcmp_fun64, abs, ps)
771 #define OP_COND(name, cond) \
772 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
774 int l1 = gen_new_label(); \
775 int l2 = gen_new_label(); \
777 tcg_gen_brcond_tl(cond, t0, t1, l1); \
778 tcg_gen_movi_tl(t0, 0); \
781 tcg_gen_movi_tl(t0, 1); \
784 OP_COND(eq, TCG_COND_EQ);
785 OP_COND(ne, TCG_COND_NE);
786 OP_COND(ge, TCG_COND_GE);
787 OP_COND(geu, TCG_COND_GEU);
788 OP_COND(lt, TCG_COND_LT);
789 OP_COND(ltu, TCG_COND_LTU);
792 #define OP_CONDI(name, cond) \
793 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
795 int l1 = gen_new_label(); \
796 int l2 = gen_new_label(); \
798 tcg_gen_brcondi_tl(cond, t, val, l1); \
799 tcg_gen_movi_tl(t, 0); \
802 tcg_gen_movi_tl(t, 1); \
805 OP_CONDI(lti, TCG_COND_LT);
806 OP_CONDI(ltiu, TCG_COND_LTU);
809 #define OP_CONDZ(name, cond) \
810 static inline void glue(gen_op_, name) (TCGv t) \
812 int l1 = gen_new_label(); \
813 int l2 = gen_new_label(); \
815 tcg_gen_brcondi_tl(cond, t, 0, l1); \
816 tcg_gen_movi_tl(t, 0); \
819 tcg_gen_movi_tl(t, 1); \
822 OP_CONDZ(gez, TCG_COND_GE);
823 OP_CONDZ(gtz, TCG_COND_GT);
824 OP_CONDZ(lez, TCG_COND_LE);
825 OP_CONDZ(ltz, TCG_COND_LT);
828 static inline void gen_save_pc(target_ulong pc)
830 tcg_gen_movi_tl(cpu_PC, pc);
833 static inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
835 #if defined MIPS_DEBUG_DISAS
836 if (loglevel & CPU_LOG_TB_IN_ASM) {
837 fprintf(logfile, "hflags %08x saved %08x\n",
838 ctx->hflags, ctx->saved_hflags);
841 if (do_save_pc && ctx->pc != ctx->saved_pc) {
842 gen_save_pc(ctx->pc);
843 ctx->saved_pc = ctx->pc;
845 if (ctx->hflags != ctx->saved_hflags) {
846 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
848 tcg_gen_movi_i32(r_tmp, ctx->hflags);
849 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
850 tcg_temp_free(r_tmp);
851 ctx->saved_hflags = ctx->hflags;
852 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
858 tcg_gen_movi_tl(btarget, ctx->btarget);
864 static inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
866 ctx->saved_hflags = ctx->hflags;
867 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
873 ctx->btarget = env->btarget;
879 generate_exception_err (DisasContext *ctx, int excp, int err)
881 save_cpu_state(ctx, 1);
882 tcg_gen_helper_0_ii(do_raise_exception_err, excp, err);
883 tcg_gen_helper_0_0(do_interrupt_restart);
888 generate_exception (DisasContext *ctx, int excp)
890 save_cpu_state(ctx, 1);
891 tcg_gen_helper_0_i(do_raise_exception, excp);
892 tcg_gen_helper_0_0(do_interrupt_restart);
896 /* Addresses computation */
897 static inline void gen_op_addr_add (DisasContext *ctx, TCGv t0, TCGv t1)
899 tcg_gen_add_tl(t0, t0, t1);
901 #if defined(TARGET_MIPS64)
902 /* For compatibility with 32-bit code, data reference in user mode
903 with Status_UX = 0 should be casted to 32-bit and sign extended.
904 See the MIPS64 PRA manual, section 4.10. */
905 if (((ctx->hflags & MIPS_HFLAG_KSU) == MIPS_HFLAG_UM) &&
906 !(ctx->hflags & MIPS_HFLAG_UX)) {
907 tcg_gen_ext32s_i64(t0, t0);
912 static inline void check_cp0_enabled(DisasContext *ctx)
914 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
915 generate_exception_err(ctx, EXCP_CpU, 1);
918 static inline void check_cp1_enabled(DisasContext *ctx)
920 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
921 generate_exception_err(ctx, EXCP_CpU, 1);
924 /* Verify that the processor is running with COP1X instructions enabled.
925 This is associated with the nabla symbol in the MIPS32 and MIPS64
928 static inline void check_cop1x(DisasContext *ctx)
930 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
931 generate_exception(ctx, EXCP_RI);
934 /* Verify that the processor is running with 64-bit floating-point
935 operations enabled. */
937 static inline void check_cp1_64bitmode(DisasContext *ctx)
939 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
940 generate_exception(ctx, EXCP_RI);
944 * Verify if floating point register is valid; an operation is not defined
945 * if bit 0 of any register specification is set and the FR bit in the
946 * Status register equals zero, since the register numbers specify an
947 * even-odd pair of adjacent coprocessor general registers. When the FR bit
948 * in the Status register equals one, both even and odd register numbers
949 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
951 * Multiple 64 bit wide registers can be checked by calling
952 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
954 static inline void check_cp1_registers(DisasContext *ctx, int regs)
956 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
957 generate_exception(ctx, EXCP_RI);
960 /* This code generates a "reserved instruction" exception if the
961 CPU does not support the instruction set corresponding to flags. */
962 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
964 if (unlikely(!(env->insn_flags & flags)))
965 generate_exception(ctx, EXCP_RI);
968 /* This code generates a "reserved instruction" exception if 64-bit
969 instructions are not enabled. */
970 static inline void check_mips_64(DisasContext *ctx)
972 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
973 generate_exception(ctx, EXCP_RI);
976 /* load/store instructions. */
977 #define OP_LD(insn,fname) \
978 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
980 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
987 #if defined(TARGET_MIPS64)
993 #define OP_ST(insn,fname) \
994 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
996 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1001 #if defined(TARGET_MIPS64)
1006 #define OP_LD_ATOMIC(insn,fname) \
1007 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1009 tcg_gen_mov_tl(t1, t0); \
1010 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1011 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1013 OP_LD_ATOMIC(ll,ld32s);
1014 #if defined(TARGET_MIPS64)
1015 OP_LD_ATOMIC(lld,ld64);
1019 #define OP_ST_ATOMIC(insn,fname,almask) \
1020 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1022 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1023 int l1 = gen_new_label(); \
1024 int l2 = gen_new_label(); \
1025 int l3 = gen_new_label(); \
1027 tcg_gen_andi_tl(r_tmp, t0, almask); \
1028 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1029 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1030 generate_exception(ctx, EXCP_AdES); \
1031 gen_set_label(l1); \
1032 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1033 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1034 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1035 tcg_gen_movi_tl(t0, 1); \
1037 gen_set_label(l2); \
1038 tcg_gen_movi_tl(t0, 0); \
1039 gen_set_label(l3); \
1040 tcg_temp_free(r_tmp); \
1042 OP_ST_ATOMIC(sc,st32,0x3);
1043 #if defined(TARGET_MIPS64)
1044 OP_ST_ATOMIC(scd,st64,0x7);
1048 /* Load and store */
1049 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1050 int base, int16_t offset)
1052 const char *opn = "ldst";
1053 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1054 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1057 tcg_gen_movi_tl(t0, offset);
1058 } else if (offset == 0) {
1059 gen_load_gpr(t0, base);
1061 gen_load_gpr(t0, base);
1062 tcg_gen_movi_tl(t1, offset);
1063 gen_op_addr_add(ctx, t0, t1);
1065 /* Don't do NOP if destination is zero: we must perform the actual
1068 #if defined(TARGET_MIPS64)
1070 op_ldst_lwu(t0, ctx);
1071 gen_store_gpr(t0, rt);
1075 op_ldst_ld(t0, ctx);
1076 gen_store_gpr(t0, rt);
1080 op_ldst_lld(t0, t1, ctx);
1081 gen_store_gpr(t0, rt);
1085 gen_load_gpr(t1, rt);
1086 op_ldst_sd(t0, t1, ctx);
1090 save_cpu_state(ctx, 1);
1091 gen_load_gpr(t1, rt);
1092 op_ldst_scd(t0, t1, ctx);
1093 gen_store_gpr(t0, rt);
1097 save_cpu_state(ctx, 1);
1098 gen_load_gpr(t1, rt);
1099 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1100 gen_store_gpr(t1, rt);
1104 save_cpu_state(ctx, 1);
1105 gen_load_gpr(t1, rt);
1106 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1110 save_cpu_state(ctx, 1);
1111 gen_load_gpr(t1, rt);
1112 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1113 gen_store_gpr(t1, rt);
1117 save_cpu_state(ctx, 1);
1118 gen_load_gpr(t1, rt);
1119 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1124 op_ldst_lw(t0, ctx);
1125 gen_store_gpr(t0, rt);
1129 gen_load_gpr(t1, rt);
1130 op_ldst_sw(t0, t1, ctx);
1134 op_ldst_lh(t0, ctx);
1135 gen_store_gpr(t0, rt);
1139 gen_load_gpr(t1, rt);
1140 op_ldst_sh(t0, t1, ctx);
1144 op_ldst_lhu(t0, ctx);
1145 gen_store_gpr(t0, rt);
1149 op_ldst_lb(t0, ctx);
1150 gen_store_gpr(t0, rt);
1154 gen_load_gpr(t1, rt);
1155 op_ldst_sb(t0, t1, ctx);
1159 op_ldst_lbu(t0, ctx);
1160 gen_store_gpr(t0, rt);
1164 save_cpu_state(ctx, 1);
1165 gen_load_gpr(t1, rt);
1166 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1167 gen_store_gpr(t1, rt);
1171 save_cpu_state(ctx, 1);
1172 gen_load_gpr(t1, rt);
1173 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1177 save_cpu_state(ctx, 1);
1178 gen_load_gpr(t1, rt);
1179 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1180 gen_store_gpr(t1, rt);
1184 save_cpu_state(ctx, 1);
1185 gen_load_gpr(t1, rt);
1186 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1190 op_ldst_ll(t0, t1, ctx);
1191 gen_store_gpr(t0, rt);
1195 save_cpu_state(ctx, 1);
1196 gen_load_gpr(t1, rt);
1197 op_ldst_sc(t0, t1, ctx);
1198 gen_store_gpr(t0, rt);
1203 generate_exception(ctx, EXCP_RI);
1206 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1212 /* Load and store */
1213 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1214 int base, int16_t offset)
1216 const char *opn = "flt_ldst";
1217 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1220 tcg_gen_movi_tl(t0, offset);
1221 } else if (offset == 0) {
1222 gen_load_gpr(t0, base);
1224 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1226 gen_load_gpr(t0, base);
1227 tcg_gen_movi_tl(t1, offset);
1228 gen_op_addr_add(ctx, t0, t1);
1231 /* Don't do NOP if destination is zero: we must perform the actual
1236 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1238 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
1239 gen_store_fpr32(fp0, ft);
1246 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1248 gen_load_fpr32(fp0, ft);
1249 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
1256 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1258 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1259 gen_store_fpr64(ctx, fp0, ft);
1266 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1268 gen_load_fpr64(ctx, fp0, ft);
1269 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1276 generate_exception(ctx, EXCP_RI);
1279 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1284 /* Arithmetic with immediate operand */
1285 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1286 int rt, int rs, int16_t imm)
1289 const char *opn = "imm arith";
1290 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1292 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1293 /* If no destination, treat it as a NOP.
1294 For addi, we must generate the overflow exception when needed. */
1298 uimm = (uint16_t)imm;
1302 #if defined(TARGET_MIPS64)
1308 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1313 gen_load_gpr(t0, rs);
1316 tcg_gen_movi_tl(t0, imm << 16);
1321 #if defined(TARGET_MIPS64)
1330 gen_load_gpr(t0, rs);
1336 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1337 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1338 int l1 = gen_new_label();
1340 save_cpu_state(ctx, 1);
1341 tcg_gen_ext32s_tl(r_tmp1, t0);
1342 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1344 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1345 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1346 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1347 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1348 tcg_temp_free(r_tmp2);
1349 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1350 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1351 tcg_temp_free(r_tmp1);
1352 /* operands of same sign, result different sign */
1353 generate_exception(ctx, EXCP_OVERFLOW);
1356 tcg_gen_ext32s_tl(t0, t0);
1361 tcg_gen_ext32s_tl(t0, t0);
1362 tcg_gen_addi_tl(t0, t0, uimm);
1363 tcg_gen_ext32s_tl(t0, t0);
1366 #if defined(TARGET_MIPS64)
1369 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1370 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1371 int l1 = gen_new_label();
1373 save_cpu_state(ctx, 1);
1374 tcg_gen_mov_tl(r_tmp1, t0);
1375 tcg_gen_addi_tl(t0, t0, uimm);
1377 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1378 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1379 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1380 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1381 tcg_temp_free(r_tmp2);
1382 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1383 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1384 tcg_temp_free(r_tmp1);
1385 /* operands of same sign, result different sign */
1386 generate_exception(ctx, EXCP_OVERFLOW);
1392 tcg_gen_addi_tl(t0, t0, uimm);
1397 gen_op_lti(t0, uimm);
1401 gen_op_ltiu(t0, uimm);
1405 tcg_gen_andi_tl(t0, t0, uimm);
1409 tcg_gen_ori_tl(t0, t0, uimm);
1413 tcg_gen_xori_tl(t0, t0, uimm);
1420 tcg_gen_ext32u_tl(t0, t0);
1421 tcg_gen_shli_tl(t0, t0, uimm);
1422 tcg_gen_ext32s_tl(t0, t0);
1426 tcg_gen_ext32s_tl(t0, t0);
1427 tcg_gen_sari_tl(t0, t0, uimm);
1428 tcg_gen_ext32s_tl(t0, t0);
1432 switch ((ctx->opcode >> 21) & 0x1f) {
1434 tcg_gen_ext32u_tl(t0, t0);
1435 tcg_gen_shri_tl(t0, t0, uimm);
1436 tcg_gen_ext32s_tl(t0, t0);
1440 /* rotr is decoded as srl on non-R2 CPUs */
1441 if (env->insn_flags & ISA_MIPS32R2) {
1443 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1445 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1446 tcg_gen_rotri_i32(r_tmp1, r_tmp1, uimm);
1447 tcg_gen_ext_i32_tl(t0, r_tmp1);
1448 tcg_temp_free(r_tmp1);
1452 tcg_gen_ext32u_tl(t0, t0);
1453 tcg_gen_shri_tl(t0, t0, uimm);
1454 tcg_gen_ext32s_tl(t0, t0);
1459 MIPS_INVAL("invalid srl flag");
1460 generate_exception(ctx, EXCP_RI);
1464 #if defined(TARGET_MIPS64)
1466 tcg_gen_shli_tl(t0, t0, uimm);
1470 tcg_gen_sari_tl(t0, t0, uimm);
1474 switch ((ctx->opcode >> 21) & 0x1f) {
1476 tcg_gen_shri_tl(t0, t0, uimm);
1480 /* drotr is decoded as dsrl on non-R2 CPUs */
1481 if (env->insn_flags & ISA_MIPS32R2) {
1483 tcg_gen_rotri_tl(t0, t0, uimm);
1487 tcg_gen_shri_tl(t0, t0, uimm);
1492 MIPS_INVAL("invalid dsrl flag");
1493 generate_exception(ctx, EXCP_RI);
1498 tcg_gen_shli_tl(t0, t0, uimm + 32);
1502 tcg_gen_sari_tl(t0, t0, uimm + 32);
1506 switch ((ctx->opcode >> 21) & 0x1f) {
1508 tcg_gen_shri_tl(t0, t0, uimm + 32);
1512 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1513 if (env->insn_flags & ISA_MIPS32R2) {
1514 tcg_gen_rotri_tl(t0, t0, uimm + 32);
1517 tcg_gen_shri_tl(t0, t0, uimm + 32);
1522 MIPS_INVAL("invalid dsrl32 flag");
1523 generate_exception(ctx, EXCP_RI);
1530 generate_exception(ctx, EXCP_RI);
1533 gen_store_gpr(t0, rt);
1534 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1540 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1541 int rd, int rs, int rt)
1543 const char *opn = "arith";
1544 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1545 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1547 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1548 && opc != OPC_DADD && opc != OPC_DSUB) {
1549 /* If no destination, treat it as a NOP.
1550 For add & sub, we must generate the overflow exception when needed. */
1554 gen_load_gpr(t0, rs);
1555 /* Specialcase the conventional move operation. */
1556 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1557 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1558 gen_store_gpr(t0, rd);
1561 gen_load_gpr(t1, rt);
1565 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1566 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1567 int l1 = gen_new_label();
1569 save_cpu_state(ctx, 1);
1570 tcg_gen_ext32s_tl(r_tmp1, t0);
1571 tcg_gen_ext32s_tl(r_tmp2, t1);
1572 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1574 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1575 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1576 tcg_gen_xor_tl(r_tmp2, t0, t1);
1577 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1578 tcg_temp_free(r_tmp2);
1579 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1580 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1581 tcg_temp_free(r_tmp1);
1582 /* operands of same sign, result different sign */
1583 generate_exception(ctx, EXCP_OVERFLOW);
1586 tcg_gen_ext32s_tl(t0, t0);
1591 tcg_gen_ext32s_tl(t0, t0);
1592 tcg_gen_ext32s_tl(t1, t1);
1593 tcg_gen_add_tl(t0, t0, t1);
1594 tcg_gen_ext32s_tl(t0, t0);
1599 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1600 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1601 int l1 = gen_new_label();
1603 save_cpu_state(ctx, 1);
1604 tcg_gen_ext32s_tl(r_tmp1, t0);
1605 tcg_gen_ext32s_tl(r_tmp2, t1);
1606 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1608 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1609 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1610 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1611 tcg_temp_free(r_tmp2);
1612 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1613 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1614 tcg_temp_free(r_tmp1);
1615 /* operands of different sign, first operand and result different sign */
1616 generate_exception(ctx, EXCP_OVERFLOW);
1619 tcg_gen_ext32s_tl(t0, t0);
1624 tcg_gen_ext32s_tl(t0, t0);
1625 tcg_gen_ext32s_tl(t1, t1);
1626 tcg_gen_sub_tl(t0, t0, t1);
1627 tcg_gen_ext32s_tl(t0, t0);
1630 #if defined(TARGET_MIPS64)
1633 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1634 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1635 int l1 = gen_new_label();
1637 save_cpu_state(ctx, 1);
1638 tcg_gen_mov_tl(r_tmp1, t0);
1639 tcg_gen_add_tl(t0, t0, t1);
1641 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1642 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1643 tcg_gen_xor_tl(r_tmp2, t0, t1);
1644 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1645 tcg_temp_free(r_tmp2);
1646 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1647 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1648 tcg_temp_free(r_tmp1);
1649 /* operands of same sign, result different sign */
1650 generate_exception(ctx, EXCP_OVERFLOW);
1656 tcg_gen_add_tl(t0, t0, t1);
1661 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1662 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1663 int l1 = gen_new_label();
1665 save_cpu_state(ctx, 1);
1666 tcg_gen_mov_tl(r_tmp1, t0);
1667 tcg_gen_sub_tl(t0, t0, t1);
1669 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1670 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1671 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1672 tcg_temp_free(r_tmp2);
1673 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1674 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1675 tcg_temp_free(r_tmp1);
1676 /* operands of different sign, first operand and result different sign */
1677 generate_exception(ctx, EXCP_OVERFLOW);
1683 tcg_gen_sub_tl(t0, t0, t1);
1696 tcg_gen_and_tl(t0, t0, t1);
1700 tcg_gen_or_tl(t0, t0, t1);
1701 tcg_gen_not_tl(t0, t0);
1705 tcg_gen_or_tl(t0, t0, t1);
1709 tcg_gen_xor_tl(t0, t0, t1);
1713 tcg_gen_ext32s_tl(t0, t0);
1714 tcg_gen_ext32s_tl(t1, t1);
1715 tcg_gen_mul_tl(t0, t0, t1);
1716 tcg_gen_ext32s_tl(t0, t0);
1721 int l1 = gen_new_label();
1723 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1724 gen_store_gpr(t0, rd);
1731 int l1 = gen_new_label();
1733 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1734 gen_store_gpr(t0, rd);
1740 tcg_gen_ext32u_tl(t0, t0);
1741 tcg_gen_ext32u_tl(t1, t1);
1742 tcg_gen_andi_tl(t0, t0, 0x1f);
1743 tcg_gen_shl_tl(t0, t1, t0);
1744 tcg_gen_ext32s_tl(t0, t0);
1748 tcg_gen_ext32s_tl(t1, t1);
1749 tcg_gen_andi_tl(t0, t0, 0x1f);
1750 tcg_gen_sar_tl(t0, t1, t0);
1751 tcg_gen_ext32s_tl(t0, t0);
1755 switch ((ctx->opcode >> 6) & 0x1f) {
1757 tcg_gen_ext32u_tl(t1, t1);
1758 tcg_gen_andi_tl(t0, t0, 0x1f);
1759 tcg_gen_shr_tl(t0, t1, t0);
1760 tcg_gen_ext32s_tl(t0, t0);
1764 /* rotrv is decoded as srlv on non-R2 CPUs */
1765 if (env->insn_flags & ISA_MIPS32R2) {
1766 int l1 = gen_new_label();
1767 int l2 = gen_new_label();
1769 tcg_gen_andi_tl(t0, t0, 0x1f);
1770 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1772 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1773 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1775 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1776 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1777 tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2);
1778 tcg_temp_free(r_tmp1);
1779 tcg_temp_free(r_tmp2);
1783 tcg_gen_mov_tl(t0, t1);
1787 tcg_gen_ext32u_tl(t1, t1);
1788 tcg_gen_andi_tl(t0, t0, 0x1f);
1789 tcg_gen_shr_tl(t0, t1, t0);
1790 tcg_gen_ext32s_tl(t0, t0);
1795 MIPS_INVAL("invalid srlv flag");
1796 generate_exception(ctx, EXCP_RI);
1800 #if defined(TARGET_MIPS64)
1802 tcg_gen_andi_tl(t0, t0, 0x3f);
1803 tcg_gen_shl_tl(t0, t1, t0);
1807 tcg_gen_andi_tl(t0, t0, 0x3f);
1808 tcg_gen_sar_tl(t0, t1, t0);
1812 switch ((ctx->opcode >> 6) & 0x1f) {
1814 tcg_gen_andi_tl(t0, t0, 0x3f);
1815 tcg_gen_shr_tl(t0, t1, t0);
1819 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1820 if (env->insn_flags & ISA_MIPS32R2) {
1821 int l1 = gen_new_label();
1822 int l2 = gen_new_label();
1824 tcg_gen_andi_tl(t0, t0, 0x3f);
1825 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1827 tcg_gen_rotr_tl(t0, t1, t0);
1831 tcg_gen_mov_tl(t0, t1);
1835 tcg_gen_andi_tl(t0, t0, 0x3f);
1836 tcg_gen_shr_tl(t0, t1, t0);
1841 MIPS_INVAL("invalid dsrlv flag");
1842 generate_exception(ctx, EXCP_RI);
1849 generate_exception(ctx, EXCP_RI);
1852 gen_store_gpr(t0, rd);
1854 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1860 /* Arithmetic on HI/LO registers */
1861 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1863 const char *opn = "hilo";
1864 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1866 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1874 gen_store_gpr(t0, reg);
1879 gen_store_gpr(t0, reg);
1883 gen_load_gpr(t0, reg);
1884 gen_store_HI(t0, 0);
1888 gen_load_gpr(t0, reg);
1889 gen_store_LO(t0, 0);
1894 generate_exception(ctx, EXCP_RI);
1897 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1902 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1905 const char *opn = "mul/div";
1906 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1907 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1909 gen_load_gpr(t0, rs);
1910 gen_load_gpr(t1, rt);
1914 int l1 = gen_new_label();
1916 tcg_gen_ext32s_tl(t0, t0);
1917 tcg_gen_ext32s_tl(t1, t1);
1918 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1920 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1921 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1922 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1924 tcg_gen_ext_tl_i64(r_tmp1, t0);
1925 tcg_gen_ext_tl_i64(r_tmp2, t1);
1926 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1927 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1928 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1929 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1930 tcg_temp_free(r_tmp1);
1931 tcg_temp_free(r_tmp2);
1932 tcg_temp_free(r_tmp3);
1933 tcg_gen_ext32s_tl(t0, t0);
1934 tcg_gen_ext32s_tl(t1, t1);
1935 gen_store_LO(t0, 0);
1936 gen_store_HI(t1, 0);
1944 int l1 = gen_new_label();
1946 tcg_gen_ext32s_tl(t1, t1);
1947 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1949 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1950 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1951 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1953 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1954 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1955 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1956 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1957 tcg_gen_ext_i32_tl(t0, r_tmp3);
1958 tcg_gen_ext_i32_tl(t1, r_tmp1);
1959 tcg_temp_free(r_tmp1);
1960 tcg_temp_free(r_tmp2);
1961 tcg_temp_free(r_tmp3);
1962 gen_store_LO(t0, 0);
1963 gen_store_HI(t1, 0);
1971 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1972 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1974 tcg_gen_ext32s_tl(t0, t0);
1975 tcg_gen_ext32s_tl(t1, t1);
1976 tcg_gen_ext_tl_i64(r_tmp1, t0);
1977 tcg_gen_ext_tl_i64(r_tmp2, t1);
1978 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1979 tcg_temp_free(r_tmp2);
1980 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1981 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1982 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1983 tcg_temp_free(r_tmp1);
1984 tcg_gen_ext32s_tl(t0, t0);
1985 tcg_gen_ext32s_tl(t1, t1);
1986 gen_store_LO(t0, 0);
1987 gen_store_HI(t1, 0);
1993 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1994 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1996 tcg_gen_ext32u_tl(t0, t0);
1997 tcg_gen_ext32u_tl(t1, t1);
1998 tcg_gen_extu_tl_i64(r_tmp1, t0);
1999 tcg_gen_extu_tl_i64(r_tmp2, t1);
2000 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2001 tcg_temp_free(r_tmp2);
2002 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2003 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2004 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2005 tcg_temp_free(r_tmp1);
2006 tcg_gen_ext32s_tl(t0, t0);
2007 tcg_gen_ext32s_tl(t1, t1);
2008 gen_store_LO(t0, 0);
2009 gen_store_HI(t1, 0);
2013 #if defined(TARGET_MIPS64)
2016 int l1 = gen_new_label();
2018 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2020 int l2 = gen_new_label();
2022 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2023 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2025 tcg_gen_movi_tl(t1, 0);
2026 gen_store_LO(t0, 0);
2027 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_div_i64(r_tmp1, t0, t1);
2036 tcg_gen_rem_i64(r_tmp2, t0, t1);
2037 gen_store_LO(r_tmp1, 0);
2038 gen_store_HI(r_tmp2, 0);
2039 tcg_temp_free(r_tmp1);
2040 tcg_temp_free(r_tmp2);
2049 int l1 = gen_new_label();
2051 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2053 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2054 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2056 tcg_gen_divu_i64(r_tmp1, t0, t1);
2057 tcg_gen_remu_i64(r_tmp2, t0, t1);
2058 tcg_temp_free(r_tmp1);
2059 tcg_temp_free(r_tmp2);
2060 gen_store_LO(r_tmp1, 0);
2061 gen_store_HI(r_tmp2, 0);
2068 tcg_gen_helper_0_2(do_dmult, t0, t1);
2072 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2078 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2079 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2081 tcg_gen_ext32s_tl(t0, t0);
2082 tcg_gen_ext32s_tl(t1, t1);
2083 tcg_gen_ext_tl_i64(r_tmp1, t0);
2084 tcg_gen_ext_tl_i64(r_tmp2, t1);
2085 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2088 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2089 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2090 tcg_temp_free(r_tmp2);
2091 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2092 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2093 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2094 tcg_temp_free(r_tmp1);
2095 tcg_gen_ext32s_tl(t0, t0);
2096 tcg_gen_ext32s_tl(t1, t1);
2097 gen_store_LO(t0, 0);
2098 gen_store_HI(t1, 0);
2104 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2105 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2107 tcg_gen_ext32u_tl(t0, t0);
2108 tcg_gen_ext32u_tl(t1, t1);
2109 tcg_gen_extu_tl_i64(r_tmp1, t0);
2110 tcg_gen_extu_tl_i64(r_tmp2, t1);
2111 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2114 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2115 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2116 tcg_temp_free(r_tmp2);
2117 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2118 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2119 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2120 tcg_temp_free(r_tmp1);
2121 tcg_gen_ext32s_tl(t0, t0);
2122 tcg_gen_ext32s_tl(t1, t1);
2123 gen_store_LO(t0, 0);
2124 gen_store_HI(t1, 0);
2130 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2131 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2133 tcg_gen_ext32s_tl(t0, t0);
2134 tcg_gen_ext32s_tl(t1, t1);
2135 tcg_gen_ext_tl_i64(r_tmp1, t0);
2136 tcg_gen_ext_tl_i64(r_tmp2, t1);
2137 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2140 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2141 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2142 tcg_temp_free(r_tmp2);
2143 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2144 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2145 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2146 tcg_temp_free(r_tmp1);
2147 tcg_gen_ext32s_tl(t0, t0);
2148 tcg_gen_ext32s_tl(t1, t1);
2149 gen_store_LO(t0, 0);
2150 gen_store_HI(t1, 0);
2156 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2157 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2159 tcg_gen_ext32u_tl(t0, t0);
2160 tcg_gen_ext32u_tl(t1, t1);
2161 tcg_gen_extu_tl_i64(r_tmp1, t0);
2162 tcg_gen_extu_tl_i64(r_tmp2, t1);
2163 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2166 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2167 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2168 tcg_temp_free(r_tmp2);
2169 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2170 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2171 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2172 tcg_temp_free(r_tmp1);
2173 tcg_gen_ext32s_tl(t0, t0);
2174 tcg_gen_ext32s_tl(t1, t1);
2175 gen_store_LO(t0, 0);
2176 gen_store_HI(t1, 0);
2182 generate_exception(ctx, EXCP_RI);
2185 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2191 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2192 int rd, int rs, int rt)
2194 const char *opn = "mul vr54xx";
2195 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2196 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2198 gen_load_gpr(t0, rs);
2199 gen_load_gpr(t1, rt);
2202 case OPC_VR54XX_MULS:
2203 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2206 case OPC_VR54XX_MULSU:
2207 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2210 case OPC_VR54XX_MACC:
2211 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2214 case OPC_VR54XX_MACCU:
2215 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2218 case OPC_VR54XX_MSAC:
2219 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2222 case OPC_VR54XX_MSACU:
2223 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2226 case OPC_VR54XX_MULHI:
2227 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2230 case OPC_VR54XX_MULHIU:
2231 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2234 case OPC_VR54XX_MULSHI:
2235 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2238 case OPC_VR54XX_MULSHIU:
2239 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2242 case OPC_VR54XX_MACCHI:
2243 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2246 case OPC_VR54XX_MACCHIU:
2247 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2250 case OPC_VR54XX_MSACHI:
2251 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2254 case OPC_VR54XX_MSACHIU:
2255 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2259 MIPS_INVAL("mul vr54xx");
2260 generate_exception(ctx, EXCP_RI);
2263 gen_store_gpr(t0, rd);
2264 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2271 static void gen_cl (DisasContext *ctx, uint32_t opc,
2274 const char *opn = "CLx";
2275 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2282 gen_load_gpr(t0, rs);
2285 tcg_gen_helper_1_1(do_clo, t0, t0);
2289 tcg_gen_helper_1_1(do_clz, t0, t0);
2292 #if defined(TARGET_MIPS64)
2294 tcg_gen_helper_1_1(do_dclo, t0, t0);
2298 tcg_gen_helper_1_1(do_dclz, t0, t0);
2304 generate_exception(ctx, EXCP_RI);
2307 gen_store_gpr(t0, rd);
2308 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2315 static void gen_trap (DisasContext *ctx, uint32_t opc,
2316 int rs, int rt, int16_t imm)
2319 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2320 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2323 /* Load needed operands */
2331 /* Compare two registers */
2333 gen_load_gpr(t0, rs);
2334 gen_load_gpr(t1, rt);
2344 /* Compare register to immediate */
2345 if (rs != 0 || imm != 0) {
2346 gen_load_gpr(t0, rs);
2347 tcg_gen_movi_tl(t1, (int32_t)imm);
2354 case OPC_TEQ: /* rs == rs */
2355 case OPC_TEQI: /* r0 == 0 */
2356 case OPC_TGE: /* rs >= rs */
2357 case OPC_TGEI: /* r0 >= 0 */
2358 case OPC_TGEU: /* rs >= rs unsigned */
2359 case OPC_TGEIU: /* r0 >= 0 unsigned */
2361 tcg_gen_movi_tl(t0, 1);
2363 case OPC_TLT: /* rs < rs */
2364 case OPC_TLTI: /* r0 < 0 */
2365 case OPC_TLTU: /* rs < rs unsigned */
2366 case OPC_TLTIU: /* r0 < 0 unsigned */
2367 case OPC_TNE: /* rs != rs */
2368 case OPC_TNEI: /* r0 != 0 */
2369 /* Never trap: treat as NOP. */
2373 generate_exception(ctx, EXCP_RI);
2404 generate_exception(ctx, EXCP_RI);
2408 save_cpu_state(ctx, 1);
2410 int l1 = gen_new_label();
2412 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2413 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2416 ctx->bstate = BS_STOP;
2422 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2424 TranslationBlock *tb;
2426 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2429 tcg_gen_exit_tb((long)tb + n);
2436 /* Branches (before delay slot) */
2437 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2438 int rs, int rt, int32_t offset)
2440 target_ulong btgt = -1;
2442 int bcond_compute = 0;
2443 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2444 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2446 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2447 #ifdef MIPS_DEBUG_DISAS
2448 if (loglevel & CPU_LOG_TB_IN_ASM) {
2450 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2454 generate_exception(ctx, EXCP_RI);
2458 /* Load needed operands */
2464 /* Compare two registers */
2466 gen_load_gpr(t0, rs);
2467 gen_load_gpr(t1, rt);
2470 btgt = ctx->pc + 4 + offset;
2484 /* Compare to zero */
2486 gen_load_gpr(t0, rs);
2489 btgt = ctx->pc + 4 + offset;
2493 /* Jump to immediate */
2494 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2498 /* Jump to register */
2499 if (offset != 0 && offset != 16) {
2500 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2501 others are reserved. */
2502 MIPS_INVAL("jump hint");
2503 generate_exception(ctx, EXCP_RI);
2506 gen_load_gpr(btarget, rs);
2509 MIPS_INVAL("branch/jump");
2510 generate_exception(ctx, EXCP_RI);
2513 if (bcond_compute == 0) {
2514 /* No condition to be computed */
2516 case OPC_BEQ: /* rx == rx */
2517 case OPC_BEQL: /* rx == rx likely */
2518 case OPC_BGEZ: /* 0 >= 0 */
2519 case OPC_BGEZL: /* 0 >= 0 likely */
2520 case OPC_BLEZ: /* 0 <= 0 */
2521 case OPC_BLEZL: /* 0 <= 0 likely */
2523 ctx->hflags |= MIPS_HFLAG_B;
2524 MIPS_DEBUG("balways");
2526 case OPC_BGEZAL: /* 0 >= 0 */
2527 case OPC_BGEZALL: /* 0 >= 0 likely */
2528 /* Always take and link */
2530 ctx->hflags |= MIPS_HFLAG_B;
2531 MIPS_DEBUG("balways and link");
2533 case OPC_BNE: /* rx != rx */
2534 case OPC_BGTZ: /* 0 > 0 */
2535 case OPC_BLTZ: /* 0 < 0 */
2537 MIPS_DEBUG("bnever (NOP)");
2539 case OPC_BLTZAL: /* 0 < 0 */
2540 tcg_gen_movi_tl(t0, ctx->pc + 8);
2541 gen_store_gpr(t0, 31);
2542 MIPS_DEBUG("bnever and link");
2544 case OPC_BLTZALL: /* 0 < 0 likely */
2545 tcg_gen_movi_tl(t0, ctx->pc + 8);
2546 gen_store_gpr(t0, 31);
2547 /* Skip the instruction in the delay slot */
2548 MIPS_DEBUG("bnever, link and skip");
2551 case OPC_BNEL: /* rx != rx likely */
2552 case OPC_BGTZL: /* 0 > 0 likely */
2553 case OPC_BLTZL: /* 0 < 0 likely */
2554 /* Skip the instruction in the delay slot */
2555 MIPS_DEBUG("bnever and skip");
2559 ctx->hflags |= MIPS_HFLAG_B;
2560 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2564 ctx->hflags |= MIPS_HFLAG_B;
2565 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2568 ctx->hflags |= MIPS_HFLAG_BR;
2569 MIPS_DEBUG("jr %s", regnames[rs]);
2573 ctx->hflags |= MIPS_HFLAG_BR;
2574 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2577 MIPS_INVAL("branch/jump");
2578 generate_exception(ctx, EXCP_RI);
2585 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2586 regnames[rs], regnames[rt], btgt);
2590 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2591 regnames[rs], regnames[rt], btgt);
2595 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2596 regnames[rs], regnames[rt], btgt);
2600 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2601 regnames[rs], regnames[rt], btgt);
2605 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2609 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2613 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2619 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2623 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2627 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2631 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2635 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2639 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2643 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2648 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2650 ctx->hflags |= MIPS_HFLAG_BC;
2651 tcg_gen_trunc_tl_i32(bcond, t0);
2656 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2658 ctx->hflags |= MIPS_HFLAG_BL;
2659 tcg_gen_trunc_tl_i32(bcond, t0);
2662 MIPS_INVAL("conditional branch/jump");
2663 generate_exception(ctx, EXCP_RI);
2667 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2668 blink, ctx->hflags, btgt);
2670 ctx->btarget = btgt;
2672 tcg_gen_movi_tl(t0, ctx->pc + 8);
2673 gen_store_gpr(t0, blink);
2681 /* special3 bitfield operations */
2682 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2683 int rs, int lsb, int msb)
2685 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
2686 TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
2689 gen_load_gpr(t1, rs);
2694 tcg_gen_shri_tl(t0, t1, lsb);
2696 tcg_gen_andi_tl(t0, t0, (1 << (msb + 1)) - 1);
2698 tcg_gen_ext32s_tl(t0, t0);
2701 #if defined(TARGET_MIPS64)
2703 tcg_gen_shri_tl(t0, t1, lsb);
2705 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1 + 32)) - 1);
2709 tcg_gen_shri_tl(t0, t1, lsb + 32);
2710 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2713 tcg_gen_shri_tl(t0, t1, lsb);
2714 tcg_gen_andi_tl(t0, t0, (1ULL << (msb + 1)) - 1);
2720 mask = ((msb - lsb + 1 < 32) ? ((1 << (msb - lsb + 1)) - 1) : ~0) << lsb;
2721 gen_load_gpr(t0, rt);
2722 tcg_gen_andi_tl(t0, t0, ~mask);
2723 tcg_gen_shli_tl(t1, t1, lsb);
2724 tcg_gen_andi_tl(t1, t1, mask);
2725 tcg_gen_or_tl(t0, t0, t1);
2726 tcg_gen_ext32s_tl(t0, t0);
2728 #if defined(TARGET_MIPS64)
2732 mask = ((msb - lsb + 1 + 32 < 64) ? ((1ULL << (msb - lsb + 1 + 32)) - 1) : ~0ULL) << lsb;
2733 gen_load_gpr(t0, rt);
2734 tcg_gen_andi_tl(t0, t0, ~mask);
2735 tcg_gen_shli_tl(t1, t1, lsb);
2736 tcg_gen_andi_tl(t1, t1, mask);
2737 tcg_gen_or_tl(t0, t0, t1);
2742 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2743 gen_load_gpr(t0, rt);
2744 tcg_gen_andi_tl(t0, t0, ~mask);
2745 tcg_gen_shli_tl(t1, t1, lsb + 32);
2746 tcg_gen_andi_tl(t1, t1, mask);
2747 tcg_gen_or_tl(t0, t0, t1);
2752 gen_load_gpr(t0, rt);
2753 mask = ((1ULL << (msb - lsb + 1)) - 1) << lsb;
2754 gen_load_gpr(t0, rt);
2755 tcg_gen_andi_tl(t0, t0, ~mask);
2756 tcg_gen_shli_tl(t1, t1, lsb);
2757 tcg_gen_andi_tl(t1, t1, mask);
2758 tcg_gen_or_tl(t0, t0, t1);
2763 MIPS_INVAL("bitops");
2764 generate_exception(ctx, EXCP_RI);
2769 gen_store_gpr(t0, rt);
2774 #ifndef CONFIG_USER_ONLY
2775 /* CP0 (MMU and control) */
2776 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2778 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2780 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2781 tcg_gen_ext_i32_tl(t, r_tmp);
2782 tcg_temp_free(r_tmp);
2785 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2787 tcg_gen_ld_tl(t, cpu_env, off);
2788 tcg_gen_ext32s_tl(t, t);
2791 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2793 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2795 tcg_gen_trunc_tl_i32(r_tmp, t);
2796 tcg_gen_st_i32(r_tmp, cpu_env, off);
2797 tcg_temp_free(r_tmp);
2800 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2802 tcg_gen_ext32s_tl(t, t);
2803 tcg_gen_st_tl(t, cpu_env, off);
2806 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2808 const char *rn = "invalid";
2811 check_insn(env, ctx, ISA_MIPS32);
2817 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2821 check_insn(env, ctx, ASE_MT);
2822 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2826 check_insn(env, ctx, ASE_MT);
2827 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2831 check_insn(env, ctx, ASE_MT);
2832 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2842 tcg_gen_helper_1_0(do_mfc0_random, t0);
2846 check_insn(env, ctx, ASE_MT);
2847 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2851 check_insn(env, ctx, ASE_MT);
2852 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2856 check_insn(env, ctx, ASE_MT);
2857 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2861 check_insn(env, ctx, ASE_MT);
2862 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2866 check_insn(env, ctx, ASE_MT);
2867 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2871 check_insn(env, ctx, ASE_MT);
2872 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2873 rn = "VPEScheFBack";
2876 check_insn(env, ctx, ASE_MT);
2877 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2887 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2888 tcg_gen_ext32s_tl(t0, t0);
2892 check_insn(env, ctx, ASE_MT);
2893 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2897 check_insn(env, ctx, ASE_MT);
2898 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2902 check_insn(env, ctx, ASE_MT);
2903 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2907 check_insn(env, ctx, ASE_MT);
2908 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2912 check_insn(env, ctx, ASE_MT);
2913 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2917 check_insn(env, ctx, ASE_MT);
2918 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2922 check_insn(env, ctx, ASE_MT);
2923 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2933 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2934 tcg_gen_ext32s_tl(t0, t0);
2944 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2945 tcg_gen_ext32s_tl(t0, t0);
2949 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2950 rn = "ContextConfig";
2959 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2963 check_insn(env, ctx, ISA_MIPS32R2);
2964 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2974 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2978 check_insn(env, ctx, ISA_MIPS32R2);
2979 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2983 check_insn(env, ctx, ISA_MIPS32R2);
2984 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2988 check_insn(env, ctx, ISA_MIPS32R2);
2989 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2993 check_insn(env, ctx, ISA_MIPS32R2);
2994 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2998 check_insn(env, ctx, ISA_MIPS32R2);
2999 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
3009 check_insn(env, ctx, ISA_MIPS32R2);
3010 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
3020 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
3021 tcg_gen_ext32s_tl(t0, t0);
3031 /* Mark as an IO operation because we read the time. */
3034 tcg_gen_helper_1_0(do_mfc0_count, t0);
3037 ctx->bstate = BS_STOP;
3041 /* 6,7 are implementation dependent */
3049 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3050 tcg_gen_ext32s_tl(t0, t0);
3060 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3063 /* 6,7 are implementation dependent */
3071 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3075 check_insn(env, ctx, ISA_MIPS32R2);
3076 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3080 check_insn(env, ctx, ISA_MIPS32R2);
3081 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3085 check_insn(env, ctx, ISA_MIPS32R2);
3086 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3096 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3106 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3107 tcg_gen_ext32s_tl(t0, t0);
3117 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3121 check_insn(env, ctx, ISA_MIPS32R2);
3122 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3132 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3136 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3140 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3144 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3147 /* 4,5 are reserved */
3148 /* 6,7 are implementation dependent */
3150 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3154 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3164 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3174 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3184 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3194 #if defined(TARGET_MIPS64)
3195 check_insn(env, ctx, ISA_MIPS3);
3196 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3197 tcg_gen_ext32s_tl(t0, t0);
3206 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3209 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3218 rn = "'Diagnostic"; /* implementation dependent */
3223 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3227 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3228 rn = "TraceControl";
3231 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3232 rn = "TraceControl2";
3235 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3236 rn = "UserTraceData";
3239 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3250 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3251 tcg_gen_ext32s_tl(t0, t0);
3261 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3262 rn = "Performance0";
3265 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3266 rn = "Performance1";
3269 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3270 rn = "Performance2";
3273 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3274 rn = "Performance3";
3277 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3278 rn = "Performance4";
3281 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3282 rn = "Performance5";
3285 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3286 rn = "Performance6";
3289 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3290 rn = "Performance7";
3315 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3322 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3335 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3342 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3352 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3353 tcg_gen_ext32s_tl(t0, t0);
3364 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3374 #if defined MIPS_DEBUG_DISAS
3375 if (loglevel & CPU_LOG_TB_IN_ASM) {
3376 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3383 #if defined MIPS_DEBUG_DISAS
3384 if (loglevel & CPU_LOG_TB_IN_ASM) {
3385 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3389 generate_exception(ctx, EXCP_RI);
3392 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3394 const char *rn = "invalid";
3397 check_insn(env, ctx, ISA_MIPS32);
3406 tcg_gen_helper_0_1(do_mtc0_index, t0);
3410 check_insn(env, ctx, ASE_MT);
3411 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3415 check_insn(env, ctx, ASE_MT);
3420 check_insn(env, ctx, ASE_MT);
3435 check_insn(env, ctx, ASE_MT);
3436 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3440 check_insn(env, ctx, ASE_MT);
3441 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3445 check_insn(env, ctx, ASE_MT);
3446 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3450 check_insn(env, ctx, ASE_MT);
3451 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3455 check_insn(env, ctx, ASE_MT);
3456 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3460 check_insn(env, ctx, ASE_MT);
3461 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3462 rn = "VPEScheFBack";
3465 check_insn(env, ctx, ASE_MT);
3466 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3476 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3480 check_insn(env, ctx, ASE_MT);
3481 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3485 check_insn(env, ctx, ASE_MT);
3486 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3490 check_insn(env, ctx, ASE_MT);
3491 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3495 check_insn(env, ctx, ASE_MT);
3496 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3500 check_insn(env, ctx, ASE_MT);
3501 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3505 check_insn(env, ctx, ASE_MT);
3506 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3510 check_insn(env, ctx, ASE_MT);
3511 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3521 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3531 tcg_gen_helper_0_1(do_mtc0_context, t0);
3535 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3536 rn = "ContextConfig";
3545 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3549 check_insn(env, ctx, ISA_MIPS32R2);
3550 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3560 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3564 check_insn(env, ctx, ISA_MIPS32R2);
3565 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3569 check_insn(env, ctx, ISA_MIPS32R2);
3570 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3574 check_insn(env, ctx, ISA_MIPS32R2);
3575 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3579 check_insn(env, ctx, ISA_MIPS32R2);
3580 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3584 check_insn(env, ctx, ISA_MIPS32R2);
3585 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3595 check_insn(env, ctx, ISA_MIPS32R2);
3596 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3610 tcg_gen_helper_0_1(do_mtc0_count, t0);
3613 /* 6,7 are implementation dependent */
3617 /* Stop translation as we may have switched the execution mode */
3618 ctx->bstate = BS_STOP;
3623 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3633 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3636 /* 6,7 are implementation dependent */
3640 /* Stop translation as we may have switched the execution mode */
3641 ctx->bstate = BS_STOP;
3646 tcg_gen_helper_0_1(do_mtc0_status, t0);
3647 /* BS_STOP isn't good enough here, hflags may have changed. */
3648 gen_save_pc(ctx->pc + 4);
3649 ctx->bstate = BS_EXCP;
3653 check_insn(env, ctx, ISA_MIPS32R2);
3654 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3655 /* Stop translation as we may have switched the execution mode */
3656 ctx->bstate = BS_STOP;
3660 check_insn(env, ctx, ISA_MIPS32R2);
3661 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3662 /* Stop translation as we may have switched the execution mode */
3663 ctx->bstate = BS_STOP;
3667 check_insn(env, ctx, ISA_MIPS32R2);
3668 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3669 /* Stop translation as we may have switched the execution mode */
3670 ctx->bstate = BS_STOP;
3680 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3686 /* Stop translation as we may have switched the execution mode */
3687 ctx->bstate = BS_STOP;
3692 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3706 check_insn(env, ctx, ISA_MIPS32R2);
3707 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3717 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3719 /* Stop translation as we may have switched the execution mode */
3720 ctx->bstate = BS_STOP;
3723 /* ignored, read only */
3727 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3729 /* Stop translation as we may have switched the execution mode */
3730 ctx->bstate = BS_STOP;
3733 /* ignored, read only */
3736 /* 4,5 are reserved */
3737 /* 6,7 are implementation dependent */
3747 rn = "Invalid config selector";
3764 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3774 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3784 #if defined(TARGET_MIPS64)
3785 check_insn(env, ctx, ISA_MIPS3);
3786 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3795 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3798 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3807 rn = "Diagnostic"; /* implementation dependent */
3812 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3813 /* BS_STOP isn't good enough here, hflags may have changed. */
3814 gen_save_pc(ctx->pc + 4);
3815 ctx->bstate = BS_EXCP;
3819 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3820 rn = "TraceControl";
3821 /* Stop translation as we may have switched the execution mode */
3822 ctx->bstate = BS_STOP;
3825 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3826 rn = "TraceControl2";
3827 /* Stop translation as we may have switched the execution mode */
3828 ctx->bstate = BS_STOP;
3831 /* Stop translation as we may have switched the execution mode */
3832 ctx->bstate = BS_STOP;
3833 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3834 rn = "UserTraceData";
3835 /* Stop translation as we may have switched the execution mode */
3836 ctx->bstate = BS_STOP;
3839 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3840 /* Stop translation as we may have switched the execution mode */
3841 ctx->bstate = BS_STOP;
3852 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3862 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3863 rn = "Performance0";
3866 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3867 rn = "Performance1";
3870 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3871 rn = "Performance2";
3874 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3875 rn = "Performance3";
3878 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3879 rn = "Performance4";
3882 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3883 rn = "Performance5";
3886 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3887 rn = "Performance6";
3890 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3891 rn = "Performance7";
3917 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3924 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3937 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3944 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
3955 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3966 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3972 /* Stop translation as we may have switched the execution mode */
3973 ctx->bstate = BS_STOP;
3978 #if defined MIPS_DEBUG_DISAS
3979 if (loglevel & CPU_LOG_TB_IN_ASM) {
3980 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3984 /* For simplicity assume that all writes can cause interrupts. */
3987 ctx->bstate = BS_STOP;
3992 #if defined MIPS_DEBUG_DISAS
3993 if (loglevel & CPU_LOG_TB_IN_ASM) {
3994 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3998 generate_exception(ctx, EXCP_RI);
4001 #if defined(TARGET_MIPS64)
4002 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4004 const char *rn = "invalid";
4007 check_insn(env, ctx, ISA_MIPS64);
4013 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
4017 check_insn(env, ctx, ASE_MT);
4018 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
4022 check_insn(env, ctx, ASE_MT);
4023 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4027 check_insn(env, ctx, ASE_MT);
4028 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4038 tcg_gen_helper_1_0(do_mfc0_random, t0);
4042 check_insn(env, ctx, ASE_MT);
4043 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4047 check_insn(env, ctx, ASE_MT);
4048 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4052 check_insn(env, ctx, ASE_MT);
4053 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4057 check_insn(env, ctx, ASE_MT);
4058 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4062 check_insn(env, ctx, ASE_MT);
4063 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4067 check_insn(env, ctx, ASE_MT);
4068 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4069 rn = "VPEScheFBack";
4072 check_insn(env, ctx, ASE_MT);
4073 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4083 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4087 check_insn(env, ctx, ASE_MT);
4088 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4092 check_insn(env, ctx, ASE_MT);
4093 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4097 check_insn(env, ctx, ASE_MT);
4098 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4102 check_insn(env, ctx, ASE_MT);
4103 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4107 check_insn(env, ctx, ASE_MT);
4108 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4112 check_insn(env, ctx, ASE_MT);
4113 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4117 check_insn(env, ctx, ASE_MT);
4118 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4128 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4138 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4142 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4143 rn = "ContextConfig";
4152 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4156 check_insn(env, ctx, ISA_MIPS32R2);
4157 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4167 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4171 check_insn(env, ctx, ISA_MIPS32R2);
4172 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4176 check_insn(env, ctx, ISA_MIPS32R2);
4177 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4181 check_insn(env, ctx, ISA_MIPS32R2);
4182 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4186 check_insn(env, ctx, ISA_MIPS32R2);
4187 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4191 check_insn(env, ctx, ISA_MIPS32R2);
4192 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4202 check_insn(env, ctx, ISA_MIPS32R2);
4203 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4213 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4223 /* Mark as an IO operation because we read the time. */
4226 tcg_gen_helper_1_0(do_mfc0_count, t0);
4229 ctx->bstate = BS_STOP;
4233 /* 6,7 are implementation dependent */
4241 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4251 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4254 /* 6,7 are implementation dependent */
4262 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4266 check_insn(env, ctx, ISA_MIPS32R2);
4267 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4271 check_insn(env, ctx, ISA_MIPS32R2);
4272 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4276 check_insn(env, ctx, ISA_MIPS32R2);
4277 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4287 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4297 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4307 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4311 check_insn(env, ctx, ISA_MIPS32R2);
4312 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4322 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4326 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4330 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4334 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4337 /* 6,7 are implementation dependent */
4339 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4343 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4353 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4363 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4373 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4383 check_insn(env, ctx, ISA_MIPS3);
4384 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4392 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4395 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4404 rn = "'Diagnostic"; /* implementation dependent */
4409 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4413 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4414 rn = "TraceControl";
4417 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4418 rn = "TraceControl2";
4421 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4422 rn = "UserTraceData";
4425 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4436 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4446 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4447 rn = "Performance0";
4450 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4451 rn = "Performance1";
4454 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4455 rn = "Performance2";
4458 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4459 rn = "Performance3";
4462 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4463 rn = "Performance4";
4466 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4467 rn = "Performance5";
4470 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4471 rn = "Performance6";
4474 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4475 rn = "Performance7";
4500 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4507 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4520 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4527 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4537 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4548 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4558 #if defined MIPS_DEBUG_DISAS
4559 if (loglevel & CPU_LOG_TB_IN_ASM) {
4560 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4567 #if defined MIPS_DEBUG_DISAS
4568 if (loglevel & CPU_LOG_TB_IN_ASM) {
4569 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4573 generate_exception(ctx, EXCP_RI);
4576 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4578 const char *rn = "invalid";
4581 check_insn(env, ctx, ISA_MIPS64);
4590 tcg_gen_helper_0_1(do_mtc0_index, t0);
4594 check_insn(env, ctx, ASE_MT);
4595 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4599 check_insn(env, ctx, ASE_MT);
4604 check_insn(env, ctx, ASE_MT);
4619 check_insn(env, ctx, ASE_MT);
4620 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4624 check_insn(env, ctx, ASE_MT);
4625 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4629 check_insn(env, ctx, ASE_MT);
4630 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4634 check_insn(env, ctx, ASE_MT);
4635 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4639 check_insn(env, ctx, ASE_MT);
4640 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4644 check_insn(env, ctx, ASE_MT);
4645 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4646 rn = "VPEScheFBack";
4649 check_insn(env, ctx, ASE_MT);
4650 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4660 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4664 check_insn(env, ctx, ASE_MT);
4665 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4669 check_insn(env, ctx, ASE_MT);
4670 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4674 check_insn(env, ctx, ASE_MT);
4675 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4679 check_insn(env, ctx, ASE_MT);
4680 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4684 check_insn(env, ctx, ASE_MT);
4685 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4689 check_insn(env, ctx, ASE_MT);
4690 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4694 check_insn(env, ctx, ASE_MT);
4695 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4705 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4715 tcg_gen_helper_0_1(do_mtc0_context, t0);
4719 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4720 rn = "ContextConfig";
4729 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4733 check_insn(env, ctx, ISA_MIPS32R2);
4734 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4744 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4748 check_insn(env, ctx, ISA_MIPS32R2);
4749 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4753 check_insn(env, ctx, ISA_MIPS32R2);
4754 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4758 check_insn(env, ctx, ISA_MIPS32R2);
4759 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4763 check_insn(env, ctx, ISA_MIPS32R2);
4764 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4768 check_insn(env, ctx, ISA_MIPS32R2);
4769 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4779 check_insn(env, ctx, ISA_MIPS32R2);
4780 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4794 tcg_gen_helper_0_1(do_mtc0_count, t0);
4797 /* 6,7 are implementation dependent */
4801 /* Stop translation as we may have switched the execution mode */
4802 ctx->bstate = BS_STOP;
4807 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4817 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4820 /* 6,7 are implementation dependent */
4824 /* Stop translation as we may have switched the execution mode */
4825 ctx->bstate = BS_STOP;
4830 tcg_gen_helper_0_1(do_mtc0_status, t0);
4831 /* BS_STOP isn't good enough here, hflags may have changed. */
4832 gen_save_pc(ctx->pc + 4);
4833 ctx->bstate = BS_EXCP;
4837 check_insn(env, ctx, ISA_MIPS32R2);
4838 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4839 /* Stop translation as we may have switched the execution mode */
4840 ctx->bstate = BS_STOP;
4844 check_insn(env, ctx, ISA_MIPS32R2);
4845 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4846 /* Stop translation as we may have switched the execution mode */
4847 ctx->bstate = BS_STOP;
4851 check_insn(env, ctx, ISA_MIPS32R2);
4852 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4853 /* Stop translation as we may have switched the execution mode */
4854 ctx->bstate = BS_STOP;
4864 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4870 /* Stop translation as we may have switched the execution mode */
4871 ctx->bstate = BS_STOP;
4876 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4890 check_insn(env, ctx, ISA_MIPS32R2);
4891 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4901 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4903 /* Stop translation as we may have switched the execution mode */
4904 ctx->bstate = BS_STOP;
4911 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4913 /* Stop translation as we may have switched the execution mode */
4914 ctx->bstate = BS_STOP;
4920 /* 6,7 are implementation dependent */
4922 rn = "Invalid config selector";
4939 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4949 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
4959 check_insn(env, ctx, ISA_MIPS3);
4960 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
4968 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4971 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
4980 rn = "Diagnostic"; /* implementation dependent */
4985 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
4986 /* BS_STOP isn't good enough here, hflags may have changed. */
4987 gen_save_pc(ctx->pc + 4);
4988 ctx->bstate = BS_EXCP;
4992 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
4993 /* Stop translation as we may have switched the execution mode */
4994 ctx->bstate = BS_STOP;
4995 rn = "TraceControl";
4998 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
4999 /* Stop translation as we may have switched the execution mode */
5000 ctx->bstate = BS_STOP;
5001 rn = "TraceControl2";
5004 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5005 /* Stop translation as we may have switched the execution mode */
5006 ctx->bstate = BS_STOP;
5007 rn = "UserTraceData";
5010 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5011 /* Stop translation as we may have switched the execution mode */
5012 ctx->bstate = BS_STOP;
5023 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5033 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5034 rn = "Performance0";
5037 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5038 rn = "Performance1";
5041 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5042 rn = "Performance2";
5045 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5046 rn = "Performance3";
5049 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5050 rn = "Performance4";
5053 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5054 rn = "Performance5";
5057 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5058 rn = "Performance6";
5061 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5062 rn = "Performance7";
5088 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5095 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5108 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5115 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5126 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5137 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5143 /* Stop translation as we may have switched the execution mode */
5144 ctx->bstate = BS_STOP;
5149 #if defined MIPS_DEBUG_DISAS
5150 if (loglevel & CPU_LOG_TB_IN_ASM) {
5151 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5155 /* For simplicity assume that all writes can cause interrupts. */
5158 ctx->bstate = BS_STOP;
5163 #if defined MIPS_DEBUG_DISAS
5164 if (loglevel & CPU_LOG_TB_IN_ASM) {
5165 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5169 generate_exception(ctx, EXCP_RI);
5171 #endif /* TARGET_MIPS64 */
5173 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5174 int u, int sel, int h)
5176 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5177 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5179 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5180 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5181 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5182 tcg_gen_movi_tl(t0, -1);
5183 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5184 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5185 tcg_gen_movi_tl(t0, -1);
5191 tcg_gen_helper_1_0(do_mftc0_tcstatus, t0);
5194 tcg_gen_helper_1_0(do_mftc0_tcbind, t0);
5197 tcg_gen_helper_1_0(do_mftc0_tcrestart, t0);
5200 tcg_gen_helper_1_0(do_mftc0_tchalt, t0);
5203 tcg_gen_helper_1_0(do_mftc0_tccontext, t0);
5206 tcg_gen_helper_1_0(do_mftc0_tcschedule, t0);
5209 tcg_gen_helper_1_0(do_mftc0_tcschefback, t0);
5212 gen_mfc0(env, ctx, t0, rt, sel);
5219 tcg_gen_helper_1_0(do_mftc0_entryhi, t0);
5222 gen_mfc0(env, ctx, t0, rt, sel);
5228 tcg_gen_helper_1_0(do_mftc0_status, t0);
5231 gen_mfc0(env, ctx, t0, rt, sel);
5237 tcg_gen_helper_1_0(do_mftc0_debug, t0);
5240 gen_mfc0(env, ctx, t0, rt, sel);
5245 gen_mfc0(env, ctx, t0, rt, sel);
5247 } else switch (sel) {
5248 /* GPR registers. */
5250 tcg_gen_helper_1_i(do_mftgpr, t0, rt);
5252 /* Auxiliary CPU registers */
5256 tcg_gen_helper_1_i(do_mftlo, t0, 0);
5259 tcg_gen_helper_1_i(do_mfthi, t0, 0);
5262 tcg_gen_helper_1_i(do_mftacx, t0, 0);
5265 tcg_gen_helper_1_i(do_mftlo, t0, 1);
5268 tcg_gen_helper_1_i(do_mfthi, t0, 1);
5271 tcg_gen_helper_1_i(do_mftacx, t0, 1);
5274 tcg_gen_helper_1_i(do_mftlo, t0, 2);
5277 tcg_gen_helper_1_i(do_mfthi, t0, 2);
5280 tcg_gen_helper_1_i(do_mftacx, t0, 2);
5283 tcg_gen_helper_1_i(do_mftlo, t0, 3);
5286 tcg_gen_helper_1_i(do_mfthi, t0, 3);
5289 tcg_gen_helper_1_i(do_mftacx, t0, 3);
5292 tcg_gen_helper_1_0(do_mftdsp, t0);
5298 /* Floating point (COP1). */
5300 /* XXX: For now we support only a single FPU context. */
5302 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5304 gen_load_fpr32(fp0, rt);
5305 tcg_gen_ext_i32_tl(t0, fp0);
5308 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5310 gen_load_fpr32h(fp0, rt);
5311 tcg_gen_ext_i32_tl(t0, fp0);
5316 /* XXX: For now we support only a single FPU context. */
5317 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5319 /* COP2: Not implemented. */
5326 #if defined MIPS_DEBUG_DISAS
5327 if (loglevel & CPU_LOG_TB_IN_ASM) {
5328 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5332 gen_store_gpr(t0, rd);
5338 #if defined MIPS_DEBUG_DISAS
5339 if (loglevel & CPU_LOG_TB_IN_ASM) {
5340 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5344 generate_exception(ctx, EXCP_RI);
5347 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5348 int u, int sel, int h)
5350 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5351 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5353 gen_load_gpr(t0, rt);
5354 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5355 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5356 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5358 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5359 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5366 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5369 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5372 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5375 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5378 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5381 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5384 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5387 gen_mtc0(env, ctx, t0, rd, sel);
5394 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5397 gen_mtc0(env, ctx, t0, rd, sel);
5403 tcg_gen_helper_0_1(do_mttc0_status, t0);
5406 gen_mtc0(env, ctx, t0, rd, sel);
5412 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5415 gen_mtc0(env, ctx, t0, rd, sel);
5420 gen_mtc0(env, ctx, t0, rd, sel);
5422 } else switch (sel) {
5423 /* GPR registers. */
5425 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5427 /* Auxiliary CPU registers */
5431 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5434 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5437 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5440 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5443 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5446 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5449 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5452 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5455 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5458 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5461 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5464 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5467 tcg_gen_helper_0_1(do_mttdsp, t0);
5473 /* Floating point (COP1). */
5475 /* XXX: For now we support only a single FPU context. */
5477 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5479 tcg_gen_trunc_tl_i32(fp0, t0);
5480 gen_store_fpr32(fp0, rd);
5483 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5485 tcg_gen_trunc_tl_i32(fp0, t0);
5486 gen_store_fpr32h(fp0, rd);
5491 /* XXX: For now we support only a single FPU context. */
5492 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5494 /* COP2: Not implemented. */
5501 #if defined MIPS_DEBUG_DISAS
5502 if (loglevel & CPU_LOG_TB_IN_ASM) {
5503 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5512 #if defined MIPS_DEBUG_DISAS
5513 if (loglevel & CPU_LOG_TB_IN_ASM) {
5514 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5518 generate_exception(ctx, EXCP_RI);
5521 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5523 const char *opn = "ldst";
5532 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5534 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5535 gen_store_gpr(t0, rt);
5542 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5544 gen_load_gpr(t0, rt);
5545 save_cpu_state(ctx, 1);
5546 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5551 #if defined(TARGET_MIPS64)
5553 check_insn(env, ctx, ISA_MIPS3);
5559 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5561 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5562 gen_store_gpr(t0, rt);
5568 check_insn(env, ctx, ISA_MIPS3);
5570 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5572 gen_load_gpr(t0, rt);
5573 save_cpu_state(ctx, 1);
5574 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5581 check_insn(env, ctx, ASE_MT);
5586 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5587 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5591 check_insn(env, ctx, ASE_MT);
5592 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5593 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5598 if (!env->tlb->do_tlbwi)
5600 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5604 if (!env->tlb->do_tlbwr)
5606 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5610 if (!env->tlb->do_tlbp)
5612 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5616 if (!env->tlb->do_tlbr)
5618 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5622 check_insn(env, ctx, ISA_MIPS2);
5623 save_cpu_state(ctx, 1);
5624 tcg_gen_helper_0_0(do_eret);
5625 ctx->bstate = BS_EXCP;
5629 check_insn(env, ctx, ISA_MIPS32);
5630 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5632 generate_exception(ctx, EXCP_RI);
5634 save_cpu_state(ctx, 1);
5635 tcg_gen_helper_0_0(do_deret);
5636 ctx->bstate = BS_EXCP;
5641 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5642 /* If we get an exception, we want to restart at next instruction */
5644 save_cpu_state(ctx, 1);
5646 tcg_gen_helper_0_0(do_wait);
5647 ctx->bstate = BS_EXCP;
5652 generate_exception(ctx, EXCP_RI);
5655 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5657 #endif /* !CONFIG_USER_ONLY */
5659 /* CP1 Branches (before delay slot) */
5660 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5661 int32_t cc, int32_t offset)
5663 target_ulong btarget;
5664 const char *opn = "cp1 cond branch";
5665 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5666 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5669 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5671 btarget = ctx->pc + 4 + offset;
5676 int l1 = gen_new_label();
5677 int l2 = gen_new_label();
5678 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5680 get_fp_cond(r_tmp1);
5681 tcg_gen_ext_i32_tl(t0, r_tmp1);
5682 tcg_temp_free(r_tmp1);
5683 tcg_gen_not_tl(t0, t0);
5684 tcg_gen_movi_tl(t1, 0x1 << cc);
5685 tcg_gen_and_tl(t0, t0, t1);
5686 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5687 tcg_gen_movi_tl(t0, 0);
5690 tcg_gen_movi_tl(t0, 1);
5697 int l1 = gen_new_label();
5698 int l2 = gen_new_label();
5699 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5701 get_fp_cond(r_tmp1);
5702 tcg_gen_ext_i32_tl(t0, r_tmp1);
5703 tcg_temp_free(r_tmp1);
5704 tcg_gen_not_tl(t0, t0);
5705 tcg_gen_movi_tl(t1, 0x1 << cc);
5706 tcg_gen_and_tl(t0, t0, t1);
5707 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5708 tcg_gen_movi_tl(t0, 0);
5711 tcg_gen_movi_tl(t0, 1);
5718 int l1 = gen_new_label();
5719 int l2 = gen_new_label();
5720 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5722 get_fp_cond(r_tmp1);
5723 tcg_gen_ext_i32_tl(t0, r_tmp1);
5724 tcg_temp_free(r_tmp1);
5725 tcg_gen_movi_tl(t1, 0x1 << cc);
5726 tcg_gen_and_tl(t0, t0, t1);
5727 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5728 tcg_gen_movi_tl(t0, 0);
5731 tcg_gen_movi_tl(t0, 1);
5738 int l1 = gen_new_label();
5739 int l2 = gen_new_label();
5740 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5742 get_fp_cond(r_tmp1);
5743 tcg_gen_ext_i32_tl(t0, r_tmp1);
5744 tcg_temp_free(r_tmp1);
5745 tcg_gen_movi_tl(t1, 0x1 << cc);
5746 tcg_gen_and_tl(t0, t0, t1);
5747 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5748 tcg_gen_movi_tl(t0, 0);
5751 tcg_gen_movi_tl(t0, 1);
5756 ctx->hflags |= MIPS_HFLAG_BL;
5757 tcg_gen_trunc_tl_i32(bcond, t0);
5761 int l1 = gen_new_label();
5762 int l2 = gen_new_label();
5763 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5765 get_fp_cond(r_tmp1);
5766 tcg_gen_ext_i32_tl(t0, r_tmp1);
5767 tcg_temp_free(r_tmp1);
5768 tcg_gen_not_tl(t0, t0);
5769 tcg_gen_movi_tl(t1, 0x3 << cc);
5770 tcg_gen_and_tl(t0, t0, t1);
5771 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5772 tcg_gen_movi_tl(t0, 0);
5775 tcg_gen_movi_tl(t0, 1);
5782 int l1 = gen_new_label();
5783 int l2 = gen_new_label();
5784 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5786 get_fp_cond(r_tmp1);
5787 tcg_gen_ext_i32_tl(t0, r_tmp1);
5788 tcg_temp_free(r_tmp1);
5789 tcg_gen_movi_tl(t1, 0x3 << cc);
5790 tcg_gen_and_tl(t0, t0, t1);
5791 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5792 tcg_gen_movi_tl(t0, 0);
5795 tcg_gen_movi_tl(t0, 1);
5802 int l1 = gen_new_label();
5803 int l2 = gen_new_label();
5804 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5806 get_fp_cond(r_tmp1);
5807 tcg_gen_ext_i32_tl(t0, r_tmp1);
5808 tcg_temp_free(r_tmp1);
5809 tcg_gen_not_tl(t0, t0);
5810 tcg_gen_movi_tl(t1, 0xf << cc);
5811 tcg_gen_and_tl(t0, t0, t1);
5812 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5813 tcg_gen_movi_tl(t0, 0);
5816 tcg_gen_movi_tl(t0, 1);
5823 int l1 = gen_new_label();
5824 int l2 = gen_new_label();
5825 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5827 get_fp_cond(r_tmp1);
5828 tcg_gen_ext_i32_tl(t0, r_tmp1);
5829 tcg_temp_free(r_tmp1);
5830 tcg_gen_movi_tl(t1, 0xf << cc);
5831 tcg_gen_and_tl(t0, t0, t1);
5832 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5833 tcg_gen_movi_tl(t0, 0);
5836 tcg_gen_movi_tl(t0, 1);
5841 ctx->hflags |= MIPS_HFLAG_BC;
5842 tcg_gen_trunc_tl_i32(bcond, t0);
5846 generate_exception (ctx, EXCP_RI);
5849 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5850 ctx->hflags, btarget);
5851 ctx->btarget = btarget;
5858 /* Coprocessor 1 (FPU) */
5860 #define FOP(func, fmt) (((fmt) << 21) | (func))
5862 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5864 const char *opn = "cp1 move";
5865 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5870 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5872 gen_load_fpr32(fp0, fs);
5873 tcg_gen_ext_i32_tl(t0, fp0);
5876 gen_store_gpr(t0, rt);
5880 gen_load_gpr(t0, rt);
5882 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5884 tcg_gen_trunc_tl_i32(fp0, t0);
5885 gen_store_fpr32(fp0, fs);
5891 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5892 gen_store_gpr(t0, rt);
5896 gen_load_gpr(t0, rt);
5897 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5902 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5904 gen_load_fpr64(ctx, fp0, fs);
5905 tcg_gen_mov_tl(t0, fp0);
5908 gen_store_gpr(t0, rt);
5912 gen_load_gpr(t0, rt);
5914 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5916 tcg_gen_mov_tl(fp0, t0);
5917 gen_store_fpr64(ctx, fp0, fs);
5924 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5926 gen_load_fpr32h(fp0, fs);
5927 tcg_gen_ext_i32_tl(t0, fp0);
5930 gen_store_gpr(t0, rt);
5934 gen_load_gpr(t0, rt);
5936 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5938 tcg_gen_trunc_tl_i32(fp0, t0);
5939 gen_store_fpr32h(fp0, fs);
5946 generate_exception (ctx, EXCP_RI);
5949 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5955 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5957 int l1 = gen_new_label();
5960 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5961 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5962 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
5965 ccbit = 1 << (24 + cc);
5973 gen_load_gpr(t0, rd);
5974 gen_load_gpr(t1, rs);
5975 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5976 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5977 tcg_temp_free(r_tmp);
5979 tcg_gen_mov_tl(t0, t1);
5983 gen_store_gpr(t0, rd);
5987 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5991 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
5992 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
5993 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
5994 int l1 = gen_new_label();
5997 ccbit = 1 << (24 + cc);
6006 gen_load_fpr32(fp0, fs);
6007 gen_load_fpr32(fp1, fd);
6008 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6009 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6010 tcg_gen_mov_i32(fp1, fp0);
6013 tcg_temp_free(r_tmp1);
6014 gen_store_fpr32(fp1, fd);
6018 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
6022 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6023 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6024 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I64);
6025 int l1 = gen_new_label();
6028 ccbit = 1 << (24 + cc);
6037 gen_load_fpr64(ctx, fp0, fs);
6038 gen_load_fpr64(ctx, fp1, fd);
6039 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6040 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6041 tcg_gen_mov_i64(fp1, fp0);
6044 tcg_temp_free(r_tmp1);
6045 gen_store_fpr64(ctx, fp1, fd);
6049 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
6052 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6053 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6054 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6055 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
6056 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6057 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
6058 int l1 = gen_new_label();
6059 int l2 = gen_new_label();
6066 gen_load_fpr32(fp0, fs);
6067 gen_load_fpr32h(fph0, fs);
6068 gen_load_fpr32(fp1, fd);
6069 gen_load_fpr32h(fph1, fd);
6070 get_fp_cond(r_tmp1);
6071 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6072 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6073 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6074 tcg_gen_mov_i32(fp1, fp0);
6077 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6078 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6079 tcg_gen_mov_i32(fph1, fph0);
6080 tcg_temp_free(fph0);
6082 tcg_temp_free(r_tmp1);
6083 tcg_temp_free(r_tmp2);
6084 gen_store_fpr32(fp1, fd);
6085 gen_store_fpr32h(fph1, fd);
6087 tcg_temp_free(fph1);
6091 static void gen_farith (DisasContext *ctx, uint32_t op1,
6092 int ft, int fs, int fd, int cc)
6094 const char *opn = "farith";
6095 const char *condnames[] = {
6113 const char *condnames_abs[] = {
6131 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6132 uint32_t func = ctx->opcode & 0x3f;
6134 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6137 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6138 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6140 gen_load_fpr32(fp0, fs);
6141 gen_load_fpr32(fp1, ft);
6142 tcg_gen_helper_1_2(do_float_add_s, fp0, fp0, fp1);
6144 gen_store_fpr32(fp0, fd);
6152 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6153 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6155 gen_load_fpr32(fp0, fs);
6156 gen_load_fpr32(fp1, ft);
6157 tcg_gen_helper_1_2(do_float_sub_s, fp0, fp0, fp1);
6159 gen_store_fpr32(fp0, fd);
6167 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6168 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6170 gen_load_fpr32(fp0, fs);
6171 gen_load_fpr32(fp1, ft);
6172 tcg_gen_helper_1_2(do_float_mul_s, fp0, fp0, fp1);
6174 gen_store_fpr32(fp0, fd);
6182 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6183 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6185 gen_load_fpr32(fp0, fs);
6186 gen_load_fpr32(fp1, ft);
6187 tcg_gen_helper_1_2(do_float_div_s, fp0, fp0, fp1);
6189 gen_store_fpr32(fp0, fd);
6197 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6199 gen_load_fpr32(fp0, fs);
6200 tcg_gen_helper_1_1(do_float_sqrt_s, fp0, fp0);
6201 gen_store_fpr32(fp0, fd);
6208 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6210 gen_load_fpr32(fp0, fs);
6211 tcg_gen_helper_1_1(do_float_abs_s, fp0, fp0);
6212 gen_store_fpr32(fp0, fd);
6219 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6221 gen_load_fpr32(fp0, fs);
6222 gen_store_fpr32(fp0, fd);
6229 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6231 gen_load_fpr32(fp0, fs);
6232 tcg_gen_helper_1_1(do_float_chs_s, fp0, fp0);
6233 gen_store_fpr32(fp0, fd);
6239 check_cp1_64bitmode(ctx);
6241 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6242 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6244 gen_load_fpr32(fp32, fs);
6245 tcg_gen_helper_1_1(do_float_roundl_s, fp64, fp32);
6246 tcg_temp_free(fp32);
6247 gen_store_fpr64(ctx, fp64, fd);
6248 tcg_temp_free(fp64);
6253 check_cp1_64bitmode(ctx);
6255 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6256 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6258 gen_load_fpr32(fp32, fs);
6259 tcg_gen_helper_1_1(do_float_truncl_s, fp64, fp32);
6260 tcg_temp_free(fp32);
6261 gen_store_fpr64(ctx, fp64, fd);
6262 tcg_temp_free(fp64);
6267 check_cp1_64bitmode(ctx);
6269 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6270 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6272 gen_load_fpr32(fp32, fs);
6273 tcg_gen_helper_1_1(do_float_ceill_s, fp64, fp32);
6274 tcg_temp_free(fp32);
6275 gen_store_fpr64(ctx, fp64, fd);
6276 tcg_temp_free(fp64);
6281 check_cp1_64bitmode(ctx);
6283 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6284 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6286 gen_load_fpr32(fp32, fs);
6287 tcg_gen_helper_1_1(do_float_floorl_s, fp64, fp32);
6288 tcg_temp_free(fp32);
6289 gen_store_fpr64(ctx, fp64, fd);
6290 tcg_temp_free(fp64);
6296 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6298 gen_load_fpr32(fp0, fs);
6299 tcg_gen_helper_1_1(do_float_roundw_s, fp0, fp0);
6300 gen_store_fpr32(fp0, fd);
6307 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6309 gen_load_fpr32(fp0, fs);
6310 tcg_gen_helper_1_1(do_float_truncw_s, fp0, fp0);
6311 gen_store_fpr32(fp0, fd);
6318 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6320 gen_load_fpr32(fp0, fs);
6321 tcg_gen_helper_1_1(do_float_ceilw_s, fp0, fp0);
6322 gen_store_fpr32(fp0, fd);
6329 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6331 gen_load_fpr32(fp0, fs);
6332 tcg_gen_helper_1_1(do_float_floorw_s, fp0, fp0);
6333 gen_store_fpr32(fp0, fd);
6339 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6344 int l1 = gen_new_label();
6345 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6346 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6348 gen_load_gpr(t0, ft);
6349 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6351 gen_load_fpr32(fp0, fs);
6352 gen_store_fpr32(fp0, fd);
6360 int l1 = gen_new_label();
6361 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6362 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6364 gen_load_gpr(t0, ft);
6365 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6367 gen_load_fpr32(fp0, fs);
6368 gen_store_fpr32(fp0, fd);
6377 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6379 gen_load_fpr32(fp0, fs);
6380 tcg_gen_helper_1_1(do_float_recip_s, fp0, fp0);
6381 gen_store_fpr32(fp0, fd);
6389 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6391 gen_load_fpr32(fp0, fs);
6392 tcg_gen_helper_1_1(do_float_rsqrt_s, fp0, fp0);
6393 gen_store_fpr32(fp0, fd);
6399 check_cp1_64bitmode(ctx);
6401 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6402 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6404 gen_load_fpr32(fp0, fs);
6405 gen_load_fpr32(fp1, fd);
6406 tcg_gen_helper_1_2(do_float_recip2_s, fp0, fp0, fp1);
6408 gen_store_fpr32(fp0, fd);
6414 check_cp1_64bitmode(ctx);
6416 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6418 gen_load_fpr32(fp0, fs);
6419 tcg_gen_helper_1_1(do_float_recip1_s, fp0, fp0);
6420 gen_store_fpr32(fp0, fd);
6426 check_cp1_64bitmode(ctx);
6428 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6430 gen_load_fpr32(fp0, fs);
6431 tcg_gen_helper_1_1(do_float_rsqrt1_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, ft);
6445 tcg_gen_helper_1_2(do_float_rsqrt2_s, fp0, fp0, fp1);
6447 gen_store_fpr32(fp0, fd);
6453 check_cp1_registers(ctx, fd);
6455 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6456 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6458 gen_load_fpr32(fp32, fs);
6459 tcg_gen_helper_1_1(do_float_cvtd_s, fp64, fp32);
6460 tcg_temp_free(fp32);
6461 gen_store_fpr64(ctx, fp64, fd);
6462 tcg_temp_free(fp64);
6468 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6470 gen_load_fpr32(fp0, fs);
6471 tcg_gen_helper_1_1(do_float_cvtw_s, fp0, fp0);
6472 gen_store_fpr32(fp0, fd);
6478 check_cp1_64bitmode(ctx);
6480 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6481 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6483 gen_load_fpr32(fp32, fs);
6484 tcg_gen_helper_1_1(do_float_cvtl_s, fp64, fp32);
6485 tcg_temp_free(fp32);
6486 gen_store_fpr64(ctx, fp64, fd);
6487 tcg_temp_free(fp64);
6492 check_cp1_64bitmode(ctx);
6494 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6495 TCGv fp32_0 = tcg_temp_new(TCG_TYPE_I32);
6496 TCGv fp32_1 = tcg_temp_new(TCG_TYPE_I32);
6498 gen_load_fpr32(fp32_0, fs);
6499 gen_load_fpr32(fp32_1, ft);
6500 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6501 tcg_temp_free(fp32_1);
6502 tcg_temp_free(fp32_0);
6503 gen_store_fpr64(ctx, fp64, fd);
6504 tcg_temp_free(fp64);
6525 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6526 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6528 gen_load_fpr32(fp0, fs);
6529 gen_load_fpr32(fp1, ft);
6530 if (ctx->opcode & (1 << 6)) {
6532 gen_cmpabs_s(func-48, fp0, fp1, cc);
6533 opn = condnames_abs[func-48];
6535 gen_cmp_s(func-48, fp0, fp1, cc);
6536 opn = condnames[func-48];
6543 check_cp1_registers(ctx, fs | ft | fd);
6545 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6546 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6548 gen_load_fpr64(ctx, fp0, fs);
6549 gen_load_fpr64(ctx, fp1, ft);
6550 tcg_gen_helper_1_2(do_float_add_d, fp0, fp0, fp1);
6552 gen_store_fpr64(ctx, fp0, fd);
6559 check_cp1_registers(ctx, fs | ft | fd);
6561 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6562 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6564 gen_load_fpr64(ctx, fp0, fs);
6565 gen_load_fpr64(ctx, fp1, ft);
6566 tcg_gen_helper_1_2(do_float_sub_d, fp0, fp0, fp1);
6568 gen_store_fpr64(ctx, fp0, fd);
6575 check_cp1_registers(ctx, fs | ft | fd);
6577 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6578 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6580 gen_load_fpr64(ctx, fp0, fs);
6581 gen_load_fpr64(ctx, fp1, ft);
6582 tcg_gen_helper_1_2(do_float_mul_d, fp0, fp0, fp1);
6584 gen_store_fpr64(ctx, fp0, fd);
6591 check_cp1_registers(ctx, fs | ft | fd);
6593 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6594 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6596 gen_load_fpr64(ctx, fp0, fs);
6597 gen_load_fpr64(ctx, fp1, ft);
6598 tcg_gen_helper_1_2(do_float_div_d, fp0, fp0, fp1);
6600 gen_store_fpr64(ctx, fp0, fd);
6607 check_cp1_registers(ctx, fs | fd);
6609 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6611 gen_load_fpr64(ctx, fp0, fs);
6612 tcg_gen_helper_1_1(do_float_sqrt_d, fp0, fp0);
6613 gen_store_fpr64(ctx, fp0, fd);
6619 check_cp1_registers(ctx, fs | fd);
6621 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6623 gen_load_fpr64(ctx, fp0, fs);
6624 tcg_gen_helper_1_1(do_float_abs_d, fp0, fp0);
6625 gen_store_fpr64(ctx, fp0, fd);
6631 check_cp1_registers(ctx, fs | fd);
6633 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6635 gen_load_fpr64(ctx, fp0, fs);
6636 gen_store_fpr64(ctx, fp0, fd);
6642 check_cp1_registers(ctx, fs | fd);
6644 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6646 gen_load_fpr64(ctx, fp0, fs);
6647 tcg_gen_helper_1_1(do_float_chs_d, fp0, fp0);
6648 gen_store_fpr64(ctx, fp0, fd);
6654 check_cp1_64bitmode(ctx);
6656 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6658 gen_load_fpr64(ctx, fp0, fs);
6659 tcg_gen_helper_1_1(do_float_roundl_d, fp0, fp0);
6660 gen_store_fpr64(ctx, fp0, fd);
6666 check_cp1_64bitmode(ctx);
6668 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6670 gen_load_fpr64(ctx, fp0, fs);
6671 tcg_gen_helper_1_1(do_float_truncl_d, fp0, fp0);
6672 gen_store_fpr64(ctx, fp0, fd);
6678 check_cp1_64bitmode(ctx);
6680 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6682 gen_load_fpr64(ctx, fp0, fs);
6683 tcg_gen_helper_1_1(do_float_ceill_d, fp0, fp0);
6684 gen_store_fpr64(ctx, fp0, fd);
6690 check_cp1_64bitmode(ctx);
6692 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6694 gen_load_fpr64(ctx, fp0, fs);
6695 tcg_gen_helper_1_1(do_float_floorl_d, fp0, fp0);
6696 gen_store_fpr64(ctx, fp0, fd);
6702 check_cp1_registers(ctx, fs);
6704 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6705 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6707 gen_load_fpr64(ctx, fp64, fs);
6708 tcg_gen_helper_1_1(do_float_roundw_d, fp32, fp64);
6709 tcg_temp_free(fp64);
6710 gen_store_fpr32(fp32, fd);
6711 tcg_temp_free(fp32);
6716 check_cp1_registers(ctx, fs);
6718 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6719 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6721 gen_load_fpr64(ctx, fp64, fs);
6722 tcg_gen_helper_1_1(do_float_truncw_d, fp32, fp64);
6723 tcg_temp_free(fp64);
6724 gen_store_fpr32(fp32, fd);
6725 tcg_temp_free(fp32);
6730 check_cp1_registers(ctx, fs);
6732 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6733 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6735 gen_load_fpr64(ctx, fp64, fs);
6736 tcg_gen_helper_1_1(do_float_ceilw_d, fp32, fp64);
6737 tcg_temp_free(fp64);
6738 gen_store_fpr32(fp32, fd);
6739 tcg_temp_free(fp32);
6744 check_cp1_registers(ctx, fs);
6746 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6747 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6749 gen_load_fpr64(ctx, fp64, fs);
6750 tcg_gen_helper_1_1(do_float_floorw_d, fp32, fp64);
6751 tcg_temp_free(fp64);
6752 gen_store_fpr32(fp32, fd);
6753 tcg_temp_free(fp32);
6758 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6763 int l1 = gen_new_label();
6764 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6765 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6767 gen_load_gpr(t0, ft);
6768 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6770 gen_load_fpr64(ctx, fp0, fs);
6771 gen_store_fpr64(ctx, fp0, fd);
6779 int l1 = gen_new_label();
6780 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6781 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6783 gen_load_gpr(t0, ft);
6784 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6786 gen_load_fpr64(ctx, fp0, fs);
6787 gen_store_fpr64(ctx, fp0, fd);
6794 check_cp1_64bitmode(ctx);
6796 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6798 gen_load_fpr64(ctx, fp0, fs);
6799 tcg_gen_helper_1_1(do_float_recip_d, fp0, fp0);
6800 gen_store_fpr64(ctx, fp0, fd);
6806 check_cp1_64bitmode(ctx);
6808 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6810 gen_load_fpr64(ctx, fp0, fs);
6811 tcg_gen_helper_1_1(do_float_rsqrt_d, fp0, fp0);
6812 gen_store_fpr64(ctx, fp0, fd);
6818 check_cp1_64bitmode(ctx);
6820 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6821 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6823 gen_load_fpr64(ctx, fp0, fs);
6824 gen_load_fpr64(ctx, fp1, ft);
6825 tcg_gen_helper_1_2(do_float_recip2_d, fp0, fp0, fp1);
6827 gen_store_fpr64(ctx, fp0, fd);
6833 check_cp1_64bitmode(ctx);
6835 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6837 gen_load_fpr64(ctx, fp0, fs);
6838 tcg_gen_helper_1_1(do_float_recip1_d, fp0, fp0);
6839 gen_store_fpr64(ctx, fp0, fd);
6845 check_cp1_64bitmode(ctx);
6847 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6849 gen_load_fpr64(ctx, fp0, fs);
6850 tcg_gen_helper_1_1(do_float_rsqrt1_d, fp0, fp0);
6851 gen_store_fpr64(ctx, fp0, fd);
6857 check_cp1_64bitmode(ctx);
6859 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6860 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6862 gen_load_fpr64(ctx, fp0, fs);
6863 gen_load_fpr64(ctx, fp1, ft);
6864 tcg_gen_helper_1_2(do_float_rsqrt2_d, fp0, fp0, fp1);
6866 gen_store_fpr64(ctx, fp0, fd);
6888 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6889 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6891 gen_load_fpr64(ctx, fp0, fs);
6892 gen_load_fpr64(ctx, fp1, ft);
6893 if (ctx->opcode & (1 << 6)) {
6895 check_cp1_registers(ctx, fs | ft);
6896 gen_cmpabs_d(func-48, fp0, fp1, cc);
6897 opn = condnames_abs[func-48];
6899 check_cp1_registers(ctx, fs | ft);
6900 gen_cmp_d(func-48, fp0, fp1, cc);
6901 opn = condnames[func-48];
6908 check_cp1_registers(ctx, fs);
6910 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6911 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6913 gen_load_fpr64(ctx, fp64, fs);
6914 tcg_gen_helper_1_1(do_float_cvts_d, fp32, fp64);
6915 tcg_temp_free(fp64);
6916 gen_store_fpr32(fp32, fd);
6917 tcg_temp_free(fp32);
6922 check_cp1_registers(ctx, fs);
6924 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6925 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6927 gen_load_fpr64(ctx, fp64, fs);
6928 tcg_gen_helper_1_1(do_float_cvtw_d, fp32, fp64);
6929 tcg_temp_free(fp64);
6930 gen_store_fpr32(fp32, fd);
6931 tcg_temp_free(fp32);
6936 check_cp1_64bitmode(ctx);
6938 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6940 gen_load_fpr64(ctx, fp0, fs);
6941 tcg_gen_helper_1_1(do_float_cvtl_d, fp0, fp0);
6942 gen_store_fpr64(ctx, fp0, fd);
6949 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6951 gen_load_fpr32(fp0, fs);
6952 tcg_gen_helper_1_1(do_float_cvts_w, fp0, fp0);
6953 gen_store_fpr32(fp0, fd);
6959 check_cp1_registers(ctx, fd);
6961 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6962 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6964 gen_load_fpr32(fp32, fs);
6965 tcg_gen_helper_1_1(do_float_cvtd_w, fp64, fp32);
6966 tcg_temp_free(fp32);
6967 gen_store_fpr64(ctx, fp64, fd);
6968 tcg_temp_free(fp64);
6973 check_cp1_64bitmode(ctx);
6975 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6976 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6978 gen_load_fpr64(ctx, fp64, fs);
6979 tcg_gen_helper_1_1(do_float_cvts_l, fp32, fp64);
6980 tcg_temp_free(fp64);
6981 gen_store_fpr32(fp32, fd);
6982 tcg_temp_free(fp32);
6987 check_cp1_64bitmode(ctx);
6989 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6991 gen_load_fpr64(ctx, fp0, fs);
6992 tcg_gen_helper_1_1(do_float_cvtd_l, fp0, fp0);
6993 gen_store_fpr64(ctx, fp0, fd);
6999 check_cp1_64bitmode(ctx);
7001 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7003 gen_load_fpr64(ctx, fp0, fs);
7004 tcg_gen_helper_1_1(do_float_cvtps_pw, fp0, fp0);
7005 gen_store_fpr64(ctx, fp0, fd);
7011 check_cp1_64bitmode(ctx);
7013 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7014 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7016 gen_load_fpr64(ctx, fp0, fs);
7017 gen_load_fpr64(ctx, fp1, ft);
7018 tcg_gen_helper_1_2(do_float_add_ps, fp0, fp0, fp1);
7020 gen_store_fpr64(ctx, fp0, fd);
7026 check_cp1_64bitmode(ctx);
7028 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7029 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7031 gen_load_fpr64(ctx, fp0, fs);
7032 gen_load_fpr64(ctx, fp1, ft);
7033 tcg_gen_helper_1_2(do_float_sub_ps, fp0, fp0, fp1);
7035 gen_store_fpr64(ctx, fp0, fd);
7041 check_cp1_64bitmode(ctx);
7043 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7044 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7046 gen_load_fpr64(ctx, fp0, fs);
7047 gen_load_fpr64(ctx, fp1, ft);
7048 tcg_gen_helper_1_2(do_float_mul_ps, fp0, fp0, fp1);
7050 gen_store_fpr64(ctx, fp0, fd);
7056 check_cp1_64bitmode(ctx);
7058 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7060 gen_load_fpr64(ctx, fp0, fs);
7061 tcg_gen_helper_1_1(do_float_abs_ps, fp0, fp0);
7062 gen_store_fpr64(ctx, fp0, fd);
7068 check_cp1_64bitmode(ctx);
7070 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7072 gen_load_fpr64(ctx, fp0, fs);
7073 gen_store_fpr64(ctx, fp0, fd);
7079 check_cp1_64bitmode(ctx);
7081 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7083 gen_load_fpr64(ctx, fp0, fs);
7084 tcg_gen_helper_1_1(do_float_chs_ps, fp0, fp0);
7085 gen_store_fpr64(ctx, fp0, fd);
7091 check_cp1_64bitmode(ctx);
7092 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
7096 check_cp1_64bitmode(ctx);
7098 int l1 = gen_new_label();
7099 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7100 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7101 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7103 gen_load_gpr(t0, ft);
7104 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7106 gen_load_fpr32(fp0, fs);
7107 gen_load_fpr32h(fph0, fs);
7108 gen_store_fpr32(fp0, fd);
7109 gen_store_fpr32h(fph0, fd);
7111 tcg_temp_free(fph0);
7117 check_cp1_64bitmode(ctx);
7119 int l1 = gen_new_label();
7120 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7121 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7122 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7124 gen_load_gpr(t0, ft);
7125 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
7127 gen_load_fpr32(fp0, fs);
7128 gen_load_fpr32h(fph0, fs);
7129 gen_store_fpr32(fp0, fd);
7130 gen_store_fpr32h(fph0, fd);
7132 tcg_temp_free(fph0);
7138 check_cp1_64bitmode(ctx);
7140 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7141 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7143 gen_load_fpr64(ctx, fp0, ft);
7144 gen_load_fpr64(ctx, fp1, fs);
7145 tcg_gen_helper_1_2(do_float_addr_ps, fp0, fp0, fp1);
7147 gen_store_fpr64(ctx, fp0, fd);
7153 check_cp1_64bitmode(ctx);
7155 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7156 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7158 gen_load_fpr64(ctx, fp0, ft);
7159 gen_load_fpr64(ctx, fp1, fs);
7160 tcg_gen_helper_1_2(do_float_mulr_ps, fp0, fp0, fp1);
7162 gen_store_fpr64(ctx, fp0, fd);
7168 check_cp1_64bitmode(ctx);
7170 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7171 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7173 gen_load_fpr64(ctx, fp0, fs);
7174 gen_load_fpr64(ctx, fp1, fd);
7175 tcg_gen_helper_1_2(do_float_recip2_ps, fp0, fp0, fp1);
7177 gen_store_fpr64(ctx, fp0, fd);
7183 check_cp1_64bitmode(ctx);
7185 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7187 gen_load_fpr64(ctx, fp0, fs);
7188 tcg_gen_helper_1_1(do_float_recip1_ps, fp0, fp0);
7189 gen_store_fpr64(ctx, fp0, fd);
7195 check_cp1_64bitmode(ctx);
7197 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7199 gen_load_fpr64(ctx, fp0, fs);
7200 tcg_gen_helper_1_1(do_float_rsqrt1_ps, fp0, fp0);
7201 gen_store_fpr64(ctx, fp0, fd);
7207 check_cp1_64bitmode(ctx);
7209 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7210 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7212 gen_load_fpr64(ctx, fp0, fs);
7213 gen_load_fpr64(ctx, fp1, ft);
7214 tcg_gen_helper_1_2(do_float_rsqrt2_ps, fp0, fp0, fp1);
7216 gen_store_fpr64(ctx, fp0, fd);
7222 check_cp1_64bitmode(ctx);
7224 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7226 gen_load_fpr32h(fp0, fs);
7227 tcg_gen_helper_1_1(do_float_cvts_pu, fp0, fp0);
7228 gen_store_fpr32(fp0, fd);
7234 check_cp1_64bitmode(ctx);
7236 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7238 gen_load_fpr64(ctx, fp0, fs);
7239 tcg_gen_helper_1_1(do_float_cvtpw_ps, fp0, fp0);
7240 gen_store_fpr64(ctx, fp0, fd);
7246 check_cp1_64bitmode(ctx);
7248 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7250 gen_load_fpr32(fp0, fs);
7251 tcg_gen_helper_1_1(do_float_cvts_pl, fp0, fp0);
7252 gen_store_fpr32(fp0, fd);
7258 check_cp1_64bitmode(ctx);
7260 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7261 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7263 gen_load_fpr32(fp0, fs);
7264 gen_load_fpr32(fp1, ft);
7265 gen_store_fpr32h(fp0, fd);
7266 gen_store_fpr32(fp1, fd);
7273 check_cp1_64bitmode(ctx);
7275 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7276 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7278 gen_load_fpr32(fp0, fs);
7279 gen_load_fpr32h(fp1, ft);
7280 gen_store_fpr32(fp1, fd);
7281 gen_store_fpr32h(fp0, fd);
7288 check_cp1_64bitmode(ctx);
7290 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7291 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7293 gen_load_fpr32h(fp0, fs);
7294 gen_load_fpr32(fp1, ft);
7295 gen_store_fpr32(fp1, fd);
7296 gen_store_fpr32h(fp0, fd);
7303 check_cp1_64bitmode(ctx);
7305 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7306 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7308 gen_load_fpr32h(fp0, fs);
7309 gen_load_fpr32h(fp1, ft);
7310 gen_store_fpr32(fp1, fd);
7311 gen_store_fpr32h(fp0, fd);
7333 check_cp1_64bitmode(ctx);
7335 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7336 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7338 gen_load_fpr64(ctx, fp0, fs);
7339 gen_load_fpr64(ctx, fp1, ft);
7340 if (ctx->opcode & (1 << 6)) {
7341 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7342 opn = condnames_abs[func-48];
7344 gen_cmp_ps(func-48, fp0, fp1, cc);
7345 opn = condnames[func-48];
7353 generate_exception (ctx, EXCP_RI);
7358 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7361 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7364 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7369 /* Coprocessor 3 (FPU) */
7370 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7371 int fd, int fs, int base, int index)
7373 const char *opn = "extended float load/store";
7375 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7376 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7379 gen_load_gpr(t0, index);
7380 } else if (index == 0) {
7381 gen_load_gpr(t0, base);
7383 gen_load_gpr(t0, base);
7384 gen_load_gpr(t1, index);
7385 gen_op_addr_add(ctx, t0, t1);
7387 /* Don't do NOP if destination is zero: we must perform the actual
7393 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7395 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
7396 gen_store_fpr32(fp0, fd);
7403 check_cp1_registers(ctx, fd);
7405 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7407 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7408 gen_store_fpr64(ctx, fp0, fd);
7414 check_cp1_64bitmode(ctx);
7415 tcg_gen_andi_tl(t0, t0, ~0x7);
7417 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7419 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7420 gen_store_fpr64(ctx, fp0, fd);
7428 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7430 gen_load_fpr32(fp0, fs);
7431 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
7439 check_cp1_registers(ctx, fs);
7441 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7443 gen_load_fpr64(ctx, fp0, fs);
7444 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7451 check_cp1_64bitmode(ctx);
7452 tcg_gen_andi_tl(t0, t0, ~0x7);
7454 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7456 gen_load_fpr64(ctx, fp0, fs);
7457 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7465 generate_exception(ctx, EXCP_RI);
7472 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7473 regnames[index], regnames[base]);
7476 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7477 int fd, int fr, int fs, int ft)
7479 const char *opn = "flt3_arith";
7483 check_cp1_64bitmode(ctx);
7485 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7486 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7487 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7488 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
7489 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
7490 int l1 = gen_new_label();
7491 int l2 = gen_new_label();
7493 gen_load_gpr(t0, fr);
7494 tcg_gen_andi_tl(t0, t0, 0x7);
7495 gen_load_fpr32(fp0, fs);
7496 gen_load_fpr32h(fph0, fs);
7497 gen_load_fpr32(fp1, ft);
7498 gen_load_fpr32h(fph1, ft);
7500 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7501 gen_store_fpr32(fp0, fd);
7502 gen_store_fpr32h(fph0, fd);
7505 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7507 #ifdef TARGET_WORDS_BIGENDIAN
7508 gen_store_fpr32(fph1, fd);
7509 gen_store_fpr32h(fp0, fd);
7511 gen_store_fpr32(fph0, fd);
7512 gen_store_fpr32h(fp1, fd);
7516 tcg_temp_free(fph0);
7518 tcg_temp_free(fph1);
7525 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7526 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7527 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7529 gen_load_fpr32(fp0, fs);
7530 gen_load_fpr32(fp1, ft);
7531 gen_load_fpr32(fp2, fr);
7532 tcg_gen_helper_1_3(do_float_muladd_s, fp2, fp0, fp1, fp2);
7535 gen_store_fpr32(fp2, fd);
7542 check_cp1_registers(ctx, fd | fs | ft | fr);
7544 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7545 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7546 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7548 gen_load_fpr64(ctx, fp0, fs);
7549 gen_load_fpr64(ctx, fp1, ft);
7550 gen_load_fpr64(ctx, fp2, fr);
7551 tcg_gen_helper_1_3(do_float_muladd_d, fp2, fp0, fp1, fp2);
7554 gen_store_fpr64(ctx, fp2, fd);
7560 check_cp1_64bitmode(ctx);
7562 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7563 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7564 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7566 gen_load_fpr64(ctx, fp0, fs);
7567 gen_load_fpr64(ctx, fp1, ft);
7568 gen_load_fpr64(ctx, fp2, fr);
7569 tcg_gen_helper_1_3(do_float_muladd_ps, fp2, fp0, fp1, fp2);
7572 gen_store_fpr64(ctx, fp2, fd);
7580 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7581 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7582 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7584 gen_load_fpr32(fp0, fs);
7585 gen_load_fpr32(fp1, ft);
7586 gen_load_fpr32(fp2, fr);
7587 tcg_gen_helper_1_3(do_float_mulsub_s, fp2, fp0, fp1, fp2);
7590 gen_store_fpr32(fp2, fd);
7597 check_cp1_registers(ctx, fd | fs | ft | fr);
7599 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7600 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7601 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7603 gen_load_fpr64(ctx, fp0, fs);
7604 gen_load_fpr64(ctx, fp1, ft);
7605 gen_load_fpr64(ctx, fp2, fr);
7606 tcg_gen_helper_1_3(do_float_mulsub_d, fp2, fp0, fp1, fp2);
7609 gen_store_fpr64(ctx, fp2, fd);
7615 check_cp1_64bitmode(ctx);
7617 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7618 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7619 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7621 gen_load_fpr64(ctx, fp0, fs);
7622 gen_load_fpr64(ctx, fp1, ft);
7623 gen_load_fpr64(ctx, fp2, fr);
7624 tcg_gen_helper_1_3(do_float_mulsub_ps, fp2, fp0, fp1, fp2);
7627 gen_store_fpr64(ctx, fp2, fd);
7635 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7636 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7637 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7639 gen_load_fpr32(fp0, fs);
7640 gen_load_fpr32(fp1, ft);
7641 gen_load_fpr32(fp2, fr);
7642 tcg_gen_helper_1_3(do_float_nmuladd_s, fp2, fp0, fp1, fp2);
7645 gen_store_fpr32(fp2, fd);
7652 check_cp1_registers(ctx, fd | fs | ft | fr);
7654 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7655 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7656 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7658 gen_load_fpr64(ctx, fp0, fs);
7659 gen_load_fpr64(ctx, fp1, ft);
7660 gen_load_fpr64(ctx, fp2, fr);
7661 tcg_gen_helper_1_3(do_float_nmuladd_d, fp2, fp0, fp1, fp2);
7664 gen_store_fpr64(ctx, fp2, fd);
7670 check_cp1_64bitmode(ctx);
7672 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7673 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7674 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7676 gen_load_fpr64(ctx, fp0, fs);
7677 gen_load_fpr64(ctx, fp1, ft);
7678 gen_load_fpr64(ctx, fp2, fr);
7679 tcg_gen_helper_1_3(do_float_nmuladd_ps, fp2, fp0, fp1, fp2);
7682 gen_store_fpr64(ctx, fp2, fd);
7690 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7691 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7692 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7694 gen_load_fpr32(fp0, fs);
7695 gen_load_fpr32(fp1, ft);
7696 gen_load_fpr32(fp2, fr);
7697 tcg_gen_helper_1_3(do_float_nmulsub_s, fp2, fp0, fp1, fp2);
7700 gen_store_fpr32(fp2, fd);
7707 check_cp1_registers(ctx, fd | fs | ft | fr);
7709 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7710 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7711 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7713 gen_load_fpr64(ctx, fp0, fs);
7714 gen_load_fpr64(ctx, fp1, ft);
7715 gen_load_fpr64(ctx, fp2, fr);
7716 tcg_gen_helper_1_3(do_float_nmulsub_d, fp2, fp0, fp1, fp2);
7719 gen_store_fpr64(ctx, fp2, fd);
7725 check_cp1_64bitmode(ctx);
7727 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7728 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7729 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7731 gen_load_fpr64(ctx, fp0, fs);
7732 gen_load_fpr64(ctx, fp1, ft);
7733 gen_load_fpr64(ctx, fp2, fr);
7734 tcg_gen_helper_1_3(do_float_nmulsub_ps, fp2, fp0, fp1, fp2);
7737 gen_store_fpr64(ctx, fp2, fd);
7744 generate_exception (ctx, EXCP_RI);
7747 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7748 fregnames[fs], fregnames[ft]);
7751 /* ISA extensions (ASEs) */
7752 /* MIPS16 extension to MIPS32 */
7753 /* SmartMIPS extension to MIPS32 */
7755 #if defined(TARGET_MIPS64)
7757 /* MDMX extension to MIPS64 */
7761 static void decode_opc (CPUState *env, DisasContext *ctx)
7765 uint32_t op, op1, op2;
7768 /* make sure instructions are on a word boundary */
7769 if (ctx->pc & 0x3) {
7770 env->CP0_BadVAddr = ctx->pc;
7771 generate_exception(ctx, EXCP_AdEL);
7775 /* Handle blikely not taken case */
7776 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7777 int l1 = gen_new_label();
7779 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7780 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7782 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
7784 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7785 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7786 tcg_temp_free(r_tmp);
7788 gen_goto_tb(ctx, 1, ctx->pc + 4);
7791 op = MASK_OP_MAJOR(ctx->opcode);
7792 rs = (ctx->opcode >> 21) & 0x1f;
7793 rt = (ctx->opcode >> 16) & 0x1f;
7794 rd = (ctx->opcode >> 11) & 0x1f;
7795 sa = (ctx->opcode >> 6) & 0x1f;
7796 imm = (int16_t)ctx->opcode;
7799 op1 = MASK_SPECIAL(ctx->opcode);
7801 case OPC_SLL: /* Arithmetic with immediate */
7802 case OPC_SRL ... OPC_SRA:
7803 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7805 case OPC_MOVZ ... OPC_MOVN:
7806 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7807 case OPC_SLLV: /* Arithmetic */
7808 case OPC_SRLV ... OPC_SRAV:
7809 case OPC_ADD ... OPC_NOR:
7810 case OPC_SLT ... OPC_SLTU:
7811 gen_arith(env, ctx, op1, rd, rs, rt);
7813 case OPC_MULT ... OPC_DIVU:
7815 check_insn(env, ctx, INSN_VR54XX);
7816 op1 = MASK_MUL_VR54XX(ctx->opcode);
7817 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7819 gen_muldiv(ctx, op1, rs, rt);
7821 case OPC_JR ... OPC_JALR:
7822 gen_compute_branch(ctx, op1, rs, rd, sa);
7824 case OPC_TGE ... OPC_TEQ: /* Traps */
7826 gen_trap(ctx, op1, rs, rt, -1);
7828 case OPC_MFHI: /* Move from HI/LO */
7830 gen_HILO(ctx, op1, rd);
7833 case OPC_MTLO: /* Move to HI/LO */
7834 gen_HILO(ctx, op1, rs);
7836 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7837 #ifdef MIPS_STRICT_STANDARD
7838 MIPS_INVAL("PMON / selsl");
7839 generate_exception(ctx, EXCP_RI);
7841 tcg_gen_helper_0_i(do_pmon, sa);
7845 generate_exception(ctx, EXCP_SYSCALL);
7848 generate_exception(ctx, EXCP_BREAK);
7851 #ifdef MIPS_STRICT_STANDARD
7853 generate_exception(ctx, EXCP_RI);
7855 /* Implemented as RI exception for now. */
7856 MIPS_INVAL("spim (unofficial)");
7857 generate_exception(ctx, EXCP_RI);
7865 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7866 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7867 save_cpu_state(ctx, 1);
7868 check_cp1_enabled(ctx);
7869 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7870 (ctx->opcode >> 16) & 1);
7872 generate_exception_err(ctx, EXCP_CpU, 1);
7876 #if defined(TARGET_MIPS64)
7877 /* MIPS64 specific opcodes */
7879 case OPC_DSRL ... OPC_DSRA:
7881 case OPC_DSRL32 ... OPC_DSRA32:
7882 check_insn(env, ctx, ISA_MIPS3);
7884 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7887 case OPC_DSRLV ... OPC_DSRAV:
7888 case OPC_DADD ... OPC_DSUBU:
7889 check_insn(env, ctx, ISA_MIPS3);
7891 gen_arith(env, ctx, op1, rd, rs, rt);
7893 case OPC_DMULT ... OPC_DDIVU:
7894 check_insn(env, ctx, ISA_MIPS3);
7896 gen_muldiv(ctx, op1, rs, rt);
7899 default: /* Invalid */
7900 MIPS_INVAL("special");
7901 generate_exception(ctx, EXCP_RI);
7906 op1 = MASK_SPECIAL2(ctx->opcode);
7908 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7909 case OPC_MSUB ... OPC_MSUBU:
7910 check_insn(env, ctx, ISA_MIPS32);
7911 gen_muldiv(ctx, op1, rs, rt);
7914 gen_arith(env, ctx, op1, rd, rs, rt);
7916 case OPC_CLZ ... OPC_CLO:
7917 check_insn(env, ctx, ISA_MIPS32);
7918 gen_cl(ctx, op1, rd, rs);
7921 /* XXX: not clear which exception should be raised
7922 * when in debug mode...
7924 check_insn(env, ctx, ISA_MIPS32);
7925 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7926 generate_exception(ctx, EXCP_DBp);
7928 generate_exception(ctx, EXCP_DBp);
7932 #if defined(TARGET_MIPS64)
7933 case OPC_DCLZ ... OPC_DCLO:
7934 check_insn(env, ctx, ISA_MIPS64);
7936 gen_cl(ctx, op1, rd, rs);
7939 default: /* Invalid */
7940 MIPS_INVAL("special2");
7941 generate_exception(ctx, EXCP_RI);
7946 op1 = MASK_SPECIAL3(ctx->opcode);
7950 check_insn(env, ctx, ISA_MIPS32R2);
7951 gen_bitops(ctx, op1, rt, rs, sa, rd);
7954 check_insn(env, ctx, ISA_MIPS32R2);
7955 op2 = MASK_BSHFL(ctx->opcode);
7957 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7958 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7962 gen_load_gpr(t1, rt);
7963 tcg_gen_helper_1_1(do_wsbh, t0, t1);
7964 gen_store_gpr(t0, rd);
7967 gen_load_gpr(t1, rt);
7968 tcg_gen_ext8s_tl(t0, t1);
7969 gen_store_gpr(t0, rd);
7972 gen_load_gpr(t1, rt);
7973 tcg_gen_ext16s_tl(t0, t1);
7974 gen_store_gpr(t0, rd);
7976 default: /* Invalid */
7977 MIPS_INVAL("bshfl");
7978 generate_exception(ctx, EXCP_RI);
7986 check_insn(env, ctx, ISA_MIPS32R2);
7988 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7992 save_cpu_state(ctx, 1);
7993 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
7996 save_cpu_state(ctx, 1);
7997 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
8000 save_cpu_state(ctx, 1);
8001 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
8004 save_cpu_state(ctx, 1);
8005 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
8008 if (env->user_mode_only) {
8009 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
8012 /* XXX: Some CPUs implement this in hardware.
8013 Not supported yet. */
8015 default: /* Invalid */
8016 MIPS_INVAL("rdhwr");
8017 generate_exception(ctx, EXCP_RI);
8020 gen_store_gpr(t0, rt);
8025 check_insn(env, ctx, ASE_MT);
8027 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8028 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8030 gen_load_gpr(t0, rt);
8031 gen_load_gpr(t1, rs);
8032 tcg_gen_helper_0_2(do_fork, t0, t1);
8038 check_insn(env, ctx, ASE_MT);
8040 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8042 gen_load_gpr(t0, rs);
8043 tcg_gen_helper_1_1(do_yield, t0, t0);
8044 gen_store_gpr(t0, rd);
8048 #if defined(TARGET_MIPS64)
8049 case OPC_DEXTM ... OPC_DEXT:
8050 case OPC_DINSM ... OPC_DINS:
8051 check_insn(env, ctx, ISA_MIPS64R2);
8053 gen_bitops(ctx, op1, rt, rs, sa, rd);
8056 check_insn(env, ctx, ISA_MIPS64R2);
8058 op2 = MASK_DBSHFL(ctx->opcode);
8060 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8061 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8065 gen_load_gpr(t1, rt);
8066 tcg_gen_helper_1_1(do_dsbh, t0, t1);
8069 gen_load_gpr(t1, rt);
8070 tcg_gen_helper_1_1(do_dshd, t0, t1);
8072 default: /* Invalid */
8073 MIPS_INVAL("dbshfl");
8074 generate_exception(ctx, EXCP_RI);
8077 gen_store_gpr(t0, rd);
8083 default: /* Invalid */
8084 MIPS_INVAL("special3");
8085 generate_exception(ctx, EXCP_RI);
8090 op1 = MASK_REGIMM(ctx->opcode);
8092 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
8093 case OPC_BLTZAL ... OPC_BGEZALL:
8094 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
8096 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
8098 gen_trap(ctx, op1, rs, -1, imm);
8101 check_insn(env, ctx, ISA_MIPS32R2);
8104 default: /* Invalid */
8105 MIPS_INVAL("regimm");
8106 generate_exception(ctx, EXCP_RI);
8111 check_cp0_enabled(ctx);
8112 op1 = MASK_CP0(ctx->opcode);
8118 #if defined(TARGET_MIPS64)
8122 #ifndef CONFIG_USER_ONLY
8123 if (!env->user_mode_only)
8124 gen_cp0(env, ctx, op1, rt, rd);
8125 #endif /* !CONFIG_USER_ONLY */
8127 case OPC_C0_FIRST ... OPC_C0_LAST:
8128 #ifndef CONFIG_USER_ONLY
8129 if (!env->user_mode_only)
8130 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
8131 #endif /* !CONFIG_USER_ONLY */
8134 #ifndef CONFIG_USER_ONLY
8135 if (!env->user_mode_only) {
8136 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8138 op2 = MASK_MFMC0(ctx->opcode);
8141 check_insn(env, ctx, ASE_MT);
8142 tcg_gen_helper_1_1(do_dmt, t0, t0);
8145 check_insn(env, ctx, ASE_MT);
8146 tcg_gen_helper_1_1(do_emt, t0, t0);
8149 check_insn(env, ctx, ASE_MT);
8150 tcg_gen_helper_1_1(do_dvpe, t0, t0);
8153 check_insn(env, ctx, ASE_MT);
8154 tcg_gen_helper_1_1(do_evpe, t0, t0);
8157 check_insn(env, ctx, ISA_MIPS32R2);
8158 save_cpu_state(ctx, 1);
8159 tcg_gen_helper_1_0(do_di, t0);
8160 /* Stop translation as we may have switched the execution mode */
8161 ctx->bstate = BS_STOP;
8164 check_insn(env, ctx, ISA_MIPS32R2);
8165 save_cpu_state(ctx, 1);
8166 tcg_gen_helper_1_0(do_ei, t0);
8167 /* Stop translation as we may have switched the execution mode */
8168 ctx->bstate = BS_STOP;
8170 default: /* Invalid */
8171 MIPS_INVAL("mfmc0");
8172 generate_exception(ctx, EXCP_RI);
8175 gen_store_gpr(t0, rt);
8178 #endif /* !CONFIG_USER_ONLY */
8181 check_insn(env, ctx, ISA_MIPS32R2);
8182 gen_load_srsgpr(rt, rd);
8185 check_insn(env, ctx, ISA_MIPS32R2);
8186 gen_store_srsgpr(rt, rd);
8190 generate_exception(ctx, EXCP_RI);
8194 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
8195 gen_arith_imm(env, ctx, op, rt, rs, imm);
8197 case OPC_J ... OPC_JAL: /* Jump */
8198 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
8199 gen_compute_branch(ctx, op, rs, rt, offset);
8201 case OPC_BEQ ... OPC_BGTZ: /* Branch */
8202 case OPC_BEQL ... OPC_BGTZL:
8203 gen_compute_branch(ctx, op, rs, rt, imm << 2);
8205 case OPC_LB ... OPC_LWR: /* Load and stores */
8206 case OPC_SB ... OPC_SW:
8210 gen_ldst(ctx, op, rt, rs, imm);
8213 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
8217 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
8221 /* Floating point (COP1). */
8226 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8227 save_cpu_state(ctx, 1);
8228 check_cp1_enabled(ctx);
8229 gen_flt_ldst(ctx, op, rt, rs, imm);
8231 generate_exception_err(ctx, EXCP_CpU, 1);
8236 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8237 save_cpu_state(ctx, 1);
8238 check_cp1_enabled(ctx);
8239 op1 = MASK_CP1(ctx->opcode);
8243 check_insn(env, ctx, ISA_MIPS32R2);
8248 gen_cp1(ctx, op1, rt, rd);
8250 #if defined(TARGET_MIPS64)
8253 check_insn(env, ctx, ISA_MIPS3);
8254 gen_cp1(ctx, op1, rt, rd);
8260 check_insn(env, ctx, ASE_MIPS3D);
8263 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8264 (rt >> 2) & 0x7, imm << 2);
8271 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8276 generate_exception (ctx, EXCP_RI);
8280 generate_exception_err(ctx, EXCP_CpU, 1);
8290 /* COP2: Not implemented. */
8291 generate_exception_err(ctx, EXCP_CpU, 2);
8295 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8296 save_cpu_state(ctx, 1);
8297 check_cp1_enabled(ctx);
8298 op1 = MASK_CP3(ctx->opcode);
8306 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8324 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8328 generate_exception (ctx, EXCP_RI);
8332 generate_exception_err(ctx, EXCP_CpU, 1);
8336 #if defined(TARGET_MIPS64)
8337 /* MIPS64 opcodes */
8339 case OPC_LDL ... OPC_LDR:
8340 case OPC_SDL ... OPC_SDR:
8345 check_insn(env, ctx, ISA_MIPS3);
8347 gen_ldst(ctx, op, rt, rs, imm);
8349 case OPC_DADDI ... OPC_DADDIU:
8350 check_insn(env, ctx, ISA_MIPS3);
8352 gen_arith_imm(env, ctx, op, rt, rs, imm);
8356 check_insn(env, ctx, ASE_MIPS16);
8357 /* MIPS16: Not implemented. */
8359 check_insn(env, ctx, ASE_MDMX);
8360 /* MDMX: Not implemented. */
8361 default: /* Invalid */
8362 MIPS_INVAL("major opcode");
8363 generate_exception(ctx, EXCP_RI);
8366 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8367 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8368 /* Branches completion */
8369 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8370 ctx->bstate = BS_BRANCH;
8371 save_cpu_state(ctx, 0);
8372 /* FIXME: Need to clear can_do_io. */
8375 /* unconditional branch */
8376 MIPS_DEBUG("unconditional branch");
8377 gen_goto_tb(ctx, 0, ctx->btarget);
8380 /* blikely taken case */
8381 MIPS_DEBUG("blikely branch taken");
8382 gen_goto_tb(ctx, 0, ctx->btarget);
8385 /* Conditional branch */
8386 MIPS_DEBUG("conditional branch");
8388 int l1 = gen_new_label();
8390 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8391 gen_goto_tb(ctx, 1, ctx->pc + 4);
8393 gen_goto_tb(ctx, 0, ctx->btarget);
8397 /* unconditional branch to register */
8398 MIPS_DEBUG("branch to register");
8399 tcg_gen_mov_tl(cpu_PC, btarget);
8403 MIPS_DEBUG("unknown branch");
8410 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8414 target_ulong pc_start;
8415 uint16_t *gen_opc_end;
8420 if (search_pc && loglevel)
8421 fprintf (logfile, "search pc %d\n", search_pc);
8424 /* Leave some spare opc slots for branch handling. */
8425 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8429 ctx.bstate = BS_NONE;
8430 /* Restore delay slot state from the tb context. */
8431 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8432 restore_cpu_state(env, &ctx);
8433 if (env->user_mode_only)
8434 ctx.mem_idx = MIPS_HFLAG_UM;
8436 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8438 max_insns = tb->cflags & CF_COUNT_MASK;
8440 max_insns = CF_COUNT_MASK;
8442 if (loglevel & CPU_LOG_TB_CPU) {
8443 fprintf(logfile, "------------------------------------------------\n");
8444 /* FIXME: This may print out stale hflags from env... */
8445 cpu_dump_state(env, logfile, fprintf, 0);
8448 #ifdef MIPS_DEBUG_DISAS
8449 if (loglevel & CPU_LOG_TB_IN_ASM)
8450 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
8451 tb, ctx.mem_idx, ctx.hflags);
8454 while (ctx.bstate == BS_NONE) {
8455 if (env->nb_breakpoints > 0) {
8456 for(j = 0; j < env->nb_breakpoints; j++) {
8457 if (env->breakpoints[j] == ctx.pc) {
8458 save_cpu_state(&ctx, 1);
8459 ctx.bstate = BS_BRANCH;
8460 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8461 /* Include the breakpoint location or the tb won't
8462 * be flushed when it must be. */
8464 goto done_generating;
8470 j = gen_opc_ptr - gen_opc_buf;
8474 gen_opc_instr_start[lj++] = 0;
8476 gen_opc_pc[lj] = ctx.pc;
8477 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8478 gen_opc_instr_start[lj] = 1;
8479 gen_opc_icount[lj] = num_insns;
8481 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8483 ctx.opcode = ldl_code(ctx.pc);
8484 decode_opc(env, &ctx);
8488 if (env->singlestep_enabled)
8491 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8494 if (gen_opc_ptr >= gen_opc_end)
8497 if (num_insns >= max_insns)
8499 #if defined (MIPS_SINGLE_STEP)
8503 if (tb->cflags & CF_LAST_IO)
8505 if (env->singlestep_enabled) {
8506 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8507 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8509 switch (ctx.bstate) {
8511 tcg_gen_helper_0_0(do_interrupt_restart);
8512 gen_goto_tb(&ctx, 0, ctx.pc);
8515 save_cpu_state(&ctx, 0);
8516 gen_goto_tb(&ctx, 0, ctx.pc);
8519 tcg_gen_helper_0_0(do_interrupt_restart);
8528 gen_icount_end(tb, num_insns);
8529 *gen_opc_ptr = INDEX_op_end;
8531 j = gen_opc_ptr - gen_opc_buf;
8534 gen_opc_instr_start[lj++] = 0;
8536 tb->size = ctx.pc - pc_start;
8537 tb->icount = num_insns;
8540 #if defined MIPS_DEBUG_DISAS
8541 if (loglevel & CPU_LOG_TB_IN_ASM)
8542 fprintf(logfile, "\n");
8544 if (loglevel & CPU_LOG_TB_IN_ASM) {
8545 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
8546 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
8547 fprintf(logfile, "\n");
8549 if (loglevel & CPU_LOG_TB_CPU) {
8550 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8555 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8557 gen_intermediate_code_internal(env, tb, 0);
8560 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8562 gen_intermediate_code_internal(env, tb, 1);
8565 static void fpu_dump_state(CPUState *env, FILE *f,
8566 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8570 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8572 #define printfpr(fp) \
8575 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8576 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8577 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8580 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8581 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8582 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8583 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8584 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8589 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8590 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8591 get_float_exception_flags(&env->active_fpu.fp_status));
8592 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8593 fpu_fprintf(f, "%3s: ", fregnames[i]);
8594 printfpr(&env->active_fpu.fpr[i]);
8600 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8601 /* Debug help: The architecture requires 32bit code to maintain proper
8602 sign-extended values on 64bit machines. */
8604 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8607 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8608 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8613 if (!SIGN_EXT_P(env->active_tc.PC))
8614 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8615 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8616 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8617 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8618 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8619 if (!SIGN_EXT_P(env->btarget))
8620 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8622 for (i = 0; i < 32; i++) {
8623 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8624 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8627 if (!SIGN_EXT_P(env->CP0_EPC))
8628 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8629 if (!SIGN_EXT_P(env->CP0_LLAddr))
8630 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8634 void cpu_dump_state (CPUState *env, FILE *f,
8635 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8640 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",
8641 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8642 env->hflags, env->btarget, env->bcond);
8643 for (i = 0; i < 32; i++) {
8645 cpu_fprintf(f, "GPR%02d:", i);
8646 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8648 cpu_fprintf(f, "\n");
8651 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8652 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8653 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8654 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8655 if (env->hflags & MIPS_HFLAG_FPU)
8656 fpu_dump_state(env, f, cpu_fprintf, flags);
8657 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8658 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8662 static void mips_tcg_init(void)
8667 /* Initialize various static tables. */
8671 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8672 for (i = 0; i < 32; i++)
8673 cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8674 offsetof(CPUState, active_tc.gpr[i]),
8676 cpu_PC = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8677 offsetof(CPUState, active_tc.PC), "PC");
8678 for (i = 0; i < MIPS_DSP_ACC; i++) {
8679 cpu_HI[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8680 offsetof(CPUState, active_tc.HI[i]),
8682 cpu_LO[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8683 offsetof(CPUState, active_tc.LO[i]),
8685 cpu_ACX[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8686 offsetof(CPUState, active_tc.ACX[i]),
8689 cpu_dspctrl = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8690 offsetof(CPUState, active_tc.DSPControl),
8692 bcond = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8693 offsetof(CPUState, bcond), "bcond");
8694 btarget = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8695 offsetof(CPUState, btarget), "btarget");
8696 for (i = 0; i < 32; i++)
8697 fpu_fpr32[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8698 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8700 for (i = 0; i < 32; i++)
8701 fpu_fpr64[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
8702 offsetof(CPUState, active_fpu.fpr[i]),
8704 for (i = 0; i < 32; i++)
8705 fpu_fpr32h[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8706 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8708 fpu_fcr0 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8709 offsetof(CPUState, active_fpu.fcr0),
8711 fpu_fcr31 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8712 offsetof(CPUState, active_fpu.fcr31),
8715 /* register helpers */
8717 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8723 #include "translate_init.c"
8725 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8728 const mips_def_t *def;
8730 def = cpu_mips_find_by_name(cpu_model);
8733 env = qemu_mallocz(sizeof(CPUMIPSState));
8736 env->cpu_model = def;
8739 env->cpu_model_str = cpu_model;
8745 void cpu_reset (CPUMIPSState *env)
8747 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8752 #if defined(CONFIG_USER_ONLY)
8753 env->user_mode_only = 1;
8755 if (env->user_mode_only) {
8756 env->hflags = MIPS_HFLAG_UM;
8758 if (env->hflags & MIPS_HFLAG_BMASK) {
8759 /* If the exception was raised from a delay slot,
8760 come back to the jump. */
8761 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8763 env->CP0_ErrorEPC = env->active_tc.PC;
8765 env->active_tc.PC = (int32_t)0xBFC00000;
8767 /* SMP not implemented */
8768 env->CP0_EBase = 0x80000000;
8769 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8770 /* vectored interrupts not implemented, timer on int 7,
8771 no performance counters. */
8772 env->CP0_IntCtl = 0xe0000000;
8776 for (i = 0; i < 7; i++) {
8777 env->CP0_WatchLo[i] = 0;
8778 env->CP0_WatchHi[i] = 0x80000000;
8780 env->CP0_WatchLo[7] = 0;
8781 env->CP0_WatchHi[7] = 0;
8783 /* Count register increments in debug mode, EJTAG version 1 */
8784 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8785 env->hflags = MIPS_HFLAG_CP0;
8787 env->exception_index = EXCP_NONE;
8788 cpu_mips_register(env, env->cpu_model);
8791 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8792 unsigned long searched_pc, int pc_pos, void *puc)
8794 env->active_tc.PC = gen_opc_pc[pc_pos];
8795 env->hflags &= ~MIPS_HFLAG_BMASK;
8796 env->hflags |= gen_opc_hflags[pc_pos];