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 (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. */
906 int l1 = gen_new_label();
907 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
909 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
910 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
911 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
912 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
913 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
914 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
915 tcg_temp_free(r_tmp);
916 tcg_gen_ext32s_i64(t0, t0);
922 static inline void check_cp0_enabled(DisasContext *ctx)
924 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
925 generate_exception_err(ctx, EXCP_CpU, 1);
928 static inline void check_cp1_enabled(DisasContext *ctx)
930 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
931 generate_exception_err(ctx, EXCP_CpU, 1);
934 /* Verify that the processor is running with COP1X instructions enabled.
935 This is associated with the nabla symbol in the MIPS32 and MIPS64
938 static inline void check_cop1x(DisasContext *ctx)
940 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
941 generate_exception(ctx, EXCP_RI);
944 /* Verify that the processor is running with 64-bit floating-point
945 operations enabled. */
947 static inline void check_cp1_64bitmode(DisasContext *ctx)
949 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
950 generate_exception(ctx, EXCP_RI);
954 * Verify if floating point register is valid; an operation is not defined
955 * if bit 0 of any register specification is set and the FR bit in the
956 * Status register equals zero, since the register numbers specify an
957 * even-odd pair of adjacent coprocessor general registers. When the FR bit
958 * in the Status register equals one, both even and odd register numbers
959 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
961 * Multiple 64 bit wide registers can be checked by calling
962 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
964 static inline void check_cp1_registers(DisasContext *ctx, int regs)
966 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
967 generate_exception(ctx, EXCP_RI);
970 /* This code generates a "reserved instruction" exception if the
971 CPU does not support the instruction set corresponding to flags. */
972 static inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
974 if (unlikely(!(env->insn_flags & flags)))
975 generate_exception(ctx, EXCP_RI);
978 /* This code generates a "reserved instruction" exception if 64-bit
979 instructions are not enabled. */
980 static inline void check_mips_64(DisasContext *ctx)
982 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
983 generate_exception(ctx, EXCP_RI);
986 /* load/store instructions. */
987 #define OP_LD(insn,fname) \
988 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
990 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
997 #if defined(TARGET_MIPS64)
1003 #define OP_ST(insn,fname) \
1004 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1006 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1011 #if defined(TARGET_MIPS64)
1016 #define OP_LD_ATOMIC(insn,fname) \
1017 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1019 tcg_gen_mov_tl(t1, t0); \
1020 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1021 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1023 OP_LD_ATOMIC(ll,ld32s);
1024 #if defined(TARGET_MIPS64)
1025 OP_LD_ATOMIC(lld,ld64);
1029 #define OP_ST_ATOMIC(insn,fname,almask) \
1030 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1032 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1033 int l1 = gen_new_label(); \
1034 int l2 = gen_new_label(); \
1035 int l3 = gen_new_label(); \
1037 tcg_gen_andi_tl(r_tmp, t0, almask); \
1038 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1039 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1040 generate_exception(ctx, EXCP_AdES); \
1041 gen_set_label(l1); \
1042 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1043 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1044 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1045 tcg_gen_movi_tl(t0, 1); \
1047 gen_set_label(l2); \
1048 tcg_gen_movi_tl(t0, 0); \
1049 gen_set_label(l3); \
1050 tcg_temp_free(r_tmp); \
1052 OP_ST_ATOMIC(sc,st32,0x3);
1053 #if defined(TARGET_MIPS64)
1054 OP_ST_ATOMIC(scd,st64,0x7);
1058 /* Load and store */
1059 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1060 int base, int16_t offset)
1062 const char *opn = "ldst";
1063 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1064 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1067 tcg_gen_movi_tl(t0, offset);
1068 } else if (offset == 0) {
1069 gen_load_gpr(t0, base);
1071 gen_load_gpr(t0, base);
1072 tcg_gen_movi_tl(t1, offset);
1073 gen_op_addr_add(t0, t1);
1075 /* Don't do NOP if destination is zero: we must perform the actual
1078 #if defined(TARGET_MIPS64)
1080 op_ldst_lwu(t0, ctx);
1081 gen_store_gpr(t0, rt);
1085 op_ldst_ld(t0, ctx);
1086 gen_store_gpr(t0, rt);
1090 op_ldst_lld(t0, t1, ctx);
1091 gen_store_gpr(t0, rt);
1095 gen_load_gpr(t1, rt);
1096 op_ldst_sd(t0, t1, ctx);
1100 save_cpu_state(ctx, 1);
1101 gen_load_gpr(t1, rt);
1102 op_ldst_scd(t0, t1, ctx);
1103 gen_store_gpr(t0, rt);
1107 save_cpu_state(ctx, 1);
1108 gen_load_gpr(t1, rt);
1109 tcg_gen_helper_1_2i(do_ldl, t1, t0, t1, ctx->mem_idx);
1110 gen_store_gpr(t1, rt);
1114 save_cpu_state(ctx, 1);
1115 gen_load_gpr(t1, rt);
1116 tcg_gen_helper_0_2i(do_sdl, t0, t1, ctx->mem_idx);
1120 save_cpu_state(ctx, 1);
1121 gen_load_gpr(t1, rt);
1122 tcg_gen_helper_1_2i(do_ldr, t1, t0, t1, ctx->mem_idx);
1123 gen_store_gpr(t1, rt);
1127 save_cpu_state(ctx, 1);
1128 gen_load_gpr(t1, rt);
1129 tcg_gen_helper_0_2i(do_sdr, t0, t1, ctx->mem_idx);
1134 op_ldst_lw(t0, ctx);
1135 gen_store_gpr(t0, rt);
1139 gen_load_gpr(t1, rt);
1140 op_ldst_sw(t0, t1, ctx);
1144 op_ldst_lh(t0, ctx);
1145 gen_store_gpr(t0, rt);
1149 gen_load_gpr(t1, rt);
1150 op_ldst_sh(t0, t1, ctx);
1154 op_ldst_lhu(t0, ctx);
1155 gen_store_gpr(t0, rt);
1159 op_ldst_lb(t0, ctx);
1160 gen_store_gpr(t0, rt);
1164 gen_load_gpr(t1, rt);
1165 op_ldst_sb(t0, t1, ctx);
1169 op_ldst_lbu(t0, ctx);
1170 gen_store_gpr(t0, rt);
1174 save_cpu_state(ctx, 1);
1175 gen_load_gpr(t1, rt);
1176 tcg_gen_helper_1_2i(do_lwl, t1, t0, t1, ctx->mem_idx);
1177 gen_store_gpr(t1, rt);
1181 save_cpu_state(ctx, 1);
1182 gen_load_gpr(t1, rt);
1183 tcg_gen_helper_0_2i(do_swl, t0, t1, ctx->mem_idx);
1187 save_cpu_state(ctx, 1);
1188 gen_load_gpr(t1, rt);
1189 tcg_gen_helper_1_2i(do_lwr, t1, t0, t1, ctx->mem_idx);
1190 gen_store_gpr(t1, rt);
1194 save_cpu_state(ctx, 1);
1195 gen_load_gpr(t1, rt);
1196 tcg_gen_helper_0_2i(do_swr, t0, t1, ctx->mem_idx);
1200 op_ldst_ll(t0, t1, ctx);
1201 gen_store_gpr(t0, rt);
1205 save_cpu_state(ctx, 1);
1206 gen_load_gpr(t1, rt);
1207 op_ldst_sc(t0, t1, ctx);
1208 gen_store_gpr(t0, rt);
1213 generate_exception(ctx, EXCP_RI);
1216 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1222 /* Load and store */
1223 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1224 int base, int16_t offset)
1226 const char *opn = "flt_ldst";
1227 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1230 tcg_gen_movi_tl(t0, offset);
1231 } else if (offset == 0) {
1232 gen_load_gpr(t0, base);
1234 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1236 gen_load_gpr(t0, base);
1237 tcg_gen_movi_tl(t1, offset);
1238 gen_op_addr_add(t0, t1);
1241 /* Don't do NOP if destination is zero: we must perform the actual
1246 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1248 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
1249 gen_store_fpr32(fp0, ft);
1256 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
1258 gen_load_fpr32(fp0, ft);
1259 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
1266 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1268 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
1269 gen_store_fpr64(ctx, fp0, ft);
1276 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
1278 gen_load_fpr64(ctx, fp0, ft);
1279 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
1286 generate_exception(ctx, EXCP_RI);
1289 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1294 /* Arithmetic with immediate operand */
1295 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1296 int rt, int rs, int16_t imm)
1299 const char *opn = "imm arith";
1300 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1302 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1303 /* If no destination, treat it as a NOP.
1304 For addi, we must generate the overflow exception when needed. */
1308 uimm = (uint16_t)imm;
1312 #if defined(TARGET_MIPS64)
1318 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1323 gen_load_gpr(t0, rs);
1326 tcg_gen_movi_tl(t0, imm << 16);
1331 #if defined(TARGET_MIPS64)
1340 gen_load_gpr(t0, rs);
1346 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1347 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1348 int l1 = gen_new_label();
1350 save_cpu_state(ctx, 1);
1351 tcg_gen_ext32s_tl(r_tmp1, t0);
1352 tcg_gen_addi_tl(t0, r_tmp1, uimm);
1354 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1355 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1356 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1357 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1358 tcg_temp_free(r_tmp2);
1359 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1360 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1361 tcg_temp_free(r_tmp1);
1362 /* operands of same sign, result different sign */
1363 generate_exception(ctx, EXCP_OVERFLOW);
1366 tcg_gen_ext32s_tl(t0, t0);
1371 tcg_gen_ext32s_tl(t0, t0);
1372 tcg_gen_addi_tl(t0, t0, uimm);
1373 tcg_gen_ext32s_tl(t0, t0);
1376 #if defined(TARGET_MIPS64)
1379 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1380 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1381 int l1 = gen_new_label();
1383 save_cpu_state(ctx, 1);
1384 tcg_gen_mov_tl(r_tmp1, t0);
1385 tcg_gen_addi_tl(t0, t0, uimm);
1387 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1388 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1389 tcg_gen_xori_tl(r_tmp2, t0, uimm);
1390 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1391 tcg_temp_free(r_tmp2);
1392 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1393 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1394 tcg_temp_free(r_tmp1);
1395 /* operands of same sign, result different sign */
1396 generate_exception(ctx, EXCP_OVERFLOW);
1402 tcg_gen_addi_tl(t0, t0, uimm);
1407 gen_op_lti(t0, uimm);
1411 gen_op_ltiu(t0, uimm);
1415 tcg_gen_andi_tl(t0, t0, uimm);
1419 tcg_gen_ori_tl(t0, t0, uimm);
1423 tcg_gen_xori_tl(t0, t0, uimm);
1430 tcg_gen_ext32u_tl(t0, t0);
1431 tcg_gen_shli_tl(t0, t0, uimm);
1432 tcg_gen_ext32s_tl(t0, t0);
1436 tcg_gen_ext32s_tl(t0, t0);
1437 tcg_gen_sari_tl(t0, t0, uimm);
1438 tcg_gen_ext32s_tl(t0, t0);
1442 switch ((ctx->opcode >> 21) & 0x1f) {
1444 tcg_gen_ext32u_tl(t0, t0);
1445 tcg_gen_shri_tl(t0, t0, uimm);
1446 tcg_gen_ext32s_tl(t0, t0);
1450 /* rotr is decoded as srl on non-R2 CPUs */
1451 if (env->insn_flags & ISA_MIPS32R2) {
1453 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1455 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1456 tcg_gen_rotri_i32(r_tmp1, r_tmp1, uimm);
1457 tcg_gen_ext_i32_tl(t0, r_tmp1);
1458 tcg_temp_free(r_tmp1);
1462 tcg_gen_ext32u_tl(t0, t0);
1463 tcg_gen_shri_tl(t0, t0, uimm);
1464 tcg_gen_ext32s_tl(t0, t0);
1469 MIPS_INVAL("invalid srl flag");
1470 generate_exception(ctx, EXCP_RI);
1474 #if defined(TARGET_MIPS64)
1476 tcg_gen_shli_tl(t0, t0, uimm);
1480 tcg_gen_sari_tl(t0, t0, uimm);
1484 switch ((ctx->opcode >> 21) & 0x1f) {
1486 tcg_gen_shri_tl(t0, t0, uimm);
1490 /* drotr is decoded as dsrl on non-R2 CPUs */
1491 if (env->insn_flags & ISA_MIPS32R2) {
1493 tcg_gen_rotri_tl(t0, t0, uimm);
1497 tcg_gen_shri_tl(t0, t0, uimm);
1502 MIPS_INVAL("invalid dsrl flag");
1503 generate_exception(ctx, EXCP_RI);
1508 tcg_gen_shli_tl(t0, t0, uimm + 32);
1512 tcg_gen_sari_tl(t0, t0, uimm + 32);
1516 switch ((ctx->opcode >> 21) & 0x1f) {
1518 tcg_gen_shri_tl(t0, t0, uimm + 32);
1522 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1523 if (env->insn_flags & ISA_MIPS32R2) {
1524 tcg_gen_rotri_tl(t0, t0, uimm + 32);
1527 tcg_gen_shri_tl(t0, t0, uimm + 32);
1532 MIPS_INVAL("invalid dsrl32 flag");
1533 generate_exception(ctx, EXCP_RI);
1540 generate_exception(ctx, EXCP_RI);
1543 gen_store_gpr(t0, rt);
1544 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1550 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1551 int rd, int rs, int rt)
1553 const char *opn = "arith";
1554 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1555 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1557 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1558 && opc != OPC_DADD && opc != OPC_DSUB) {
1559 /* If no destination, treat it as a NOP.
1560 For add & sub, we must generate the overflow exception when needed. */
1564 gen_load_gpr(t0, rs);
1565 /* Specialcase the conventional move operation. */
1566 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1567 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1568 gen_store_gpr(t0, rd);
1571 gen_load_gpr(t1, rt);
1575 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1576 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1577 int l1 = gen_new_label();
1579 save_cpu_state(ctx, 1);
1580 tcg_gen_ext32s_tl(r_tmp1, t0);
1581 tcg_gen_ext32s_tl(r_tmp2, t1);
1582 tcg_gen_add_tl(t0, r_tmp1, r_tmp2);
1584 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1585 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1586 tcg_gen_xor_tl(r_tmp2, t0, t1);
1587 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1588 tcg_temp_free(r_tmp2);
1589 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1590 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1591 tcg_temp_free(r_tmp1);
1592 /* operands of same sign, result different sign */
1593 generate_exception(ctx, EXCP_OVERFLOW);
1596 tcg_gen_ext32s_tl(t0, t0);
1601 tcg_gen_ext32s_tl(t0, t0);
1602 tcg_gen_ext32s_tl(t1, t1);
1603 tcg_gen_add_tl(t0, t0, t1);
1604 tcg_gen_ext32s_tl(t0, t0);
1609 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1610 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1611 int l1 = gen_new_label();
1613 save_cpu_state(ctx, 1);
1614 tcg_gen_ext32s_tl(r_tmp1, t0);
1615 tcg_gen_ext32s_tl(r_tmp2, t1);
1616 tcg_gen_sub_tl(t0, r_tmp1, r_tmp2);
1618 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1619 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1620 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1621 tcg_temp_free(r_tmp2);
1622 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1623 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1624 tcg_temp_free(r_tmp1);
1625 /* operands of different sign, first operand and result different sign */
1626 generate_exception(ctx, EXCP_OVERFLOW);
1629 tcg_gen_ext32s_tl(t0, t0);
1634 tcg_gen_ext32s_tl(t0, t0);
1635 tcg_gen_ext32s_tl(t1, t1);
1636 tcg_gen_sub_tl(t0, t0, t1);
1637 tcg_gen_ext32s_tl(t0, t0);
1640 #if defined(TARGET_MIPS64)
1643 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1644 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1645 int l1 = gen_new_label();
1647 save_cpu_state(ctx, 1);
1648 tcg_gen_mov_tl(r_tmp1, t0);
1649 tcg_gen_add_tl(t0, t0, t1);
1651 tcg_gen_xor_tl(r_tmp1, r_tmp1, t1);
1652 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1653 tcg_gen_xor_tl(r_tmp2, t0, t1);
1654 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1655 tcg_temp_free(r_tmp2);
1656 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1657 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1658 tcg_temp_free(r_tmp1);
1659 /* operands of same sign, result different sign */
1660 generate_exception(ctx, EXCP_OVERFLOW);
1666 tcg_gen_add_tl(t0, t0, t1);
1671 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1672 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1673 int l1 = gen_new_label();
1675 save_cpu_state(ctx, 1);
1676 tcg_gen_mov_tl(r_tmp1, t0);
1677 tcg_gen_sub_tl(t0, t0, t1);
1679 tcg_gen_xor_tl(r_tmp2, r_tmp1, t1);
1680 tcg_gen_xor_tl(r_tmp1, r_tmp1, t0);
1681 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1682 tcg_temp_free(r_tmp2);
1683 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1684 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1685 tcg_temp_free(r_tmp1);
1686 /* operands of different sign, first operand and result different sign */
1687 generate_exception(ctx, EXCP_OVERFLOW);
1693 tcg_gen_sub_tl(t0, t0, t1);
1706 tcg_gen_and_tl(t0, t0, t1);
1710 tcg_gen_or_tl(t0, t0, t1);
1711 tcg_gen_not_tl(t0, t0);
1715 tcg_gen_or_tl(t0, t0, t1);
1719 tcg_gen_xor_tl(t0, t0, t1);
1723 tcg_gen_ext32s_tl(t0, t0);
1724 tcg_gen_ext32s_tl(t1, t1);
1725 tcg_gen_mul_tl(t0, t0, t1);
1726 tcg_gen_ext32s_tl(t0, t0);
1731 int l1 = gen_new_label();
1733 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1734 gen_store_gpr(t0, rd);
1741 int l1 = gen_new_label();
1743 tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
1744 gen_store_gpr(t0, rd);
1750 tcg_gen_ext32u_tl(t0, t0);
1751 tcg_gen_ext32u_tl(t1, t1);
1752 tcg_gen_andi_tl(t0, t0, 0x1f);
1753 tcg_gen_shl_tl(t0, t1, t0);
1754 tcg_gen_ext32s_tl(t0, t0);
1758 tcg_gen_ext32s_tl(t1, t1);
1759 tcg_gen_andi_tl(t0, t0, 0x1f);
1760 tcg_gen_sar_tl(t0, t1, t0);
1761 tcg_gen_ext32s_tl(t0, t0);
1765 switch ((ctx->opcode >> 6) & 0x1f) {
1767 tcg_gen_ext32u_tl(t1, t1);
1768 tcg_gen_andi_tl(t0, t0, 0x1f);
1769 tcg_gen_shr_tl(t0, t1, t0);
1770 tcg_gen_ext32s_tl(t0, t0);
1774 /* rotrv is decoded as srlv on non-R2 CPUs */
1775 if (env->insn_flags & ISA_MIPS32R2) {
1776 int l1 = gen_new_label();
1777 int l2 = gen_new_label();
1779 tcg_gen_andi_tl(t0, t0, 0x1f);
1780 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1782 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1783 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1785 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1786 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1787 tcg_gen_rotr_i32(r_tmp1, r_tmp1, r_tmp2);
1788 tcg_temp_free(r_tmp1);
1789 tcg_temp_free(r_tmp2);
1793 tcg_gen_mov_tl(t0, t1);
1797 tcg_gen_ext32u_tl(t1, t1);
1798 tcg_gen_andi_tl(t0, t0, 0x1f);
1799 tcg_gen_shr_tl(t0, t1, t0);
1800 tcg_gen_ext32s_tl(t0, t0);
1805 MIPS_INVAL("invalid srlv flag");
1806 generate_exception(ctx, EXCP_RI);
1810 #if defined(TARGET_MIPS64)
1812 tcg_gen_andi_tl(t0, t0, 0x3f);
1813 tcg_gen_shl_tl(t0, t1, t0);
1817 tcg_gen_andi_tl(t0, t0, 0x3f);
1818 tcg_gen_sar_tl(t0, t1, t0);
1822 switch ((ctx->opcode >> 6) & 0x1f) {
1824 tcg_gen_andi_tl(t0, t0, 0x3f);
1825 tcg_gen_shr_tl(t0, t1, t0);
1829 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1830 if (env->insn_flags & ISA_MIPS32R2) {
1831 int l1 = gen_new_label();
1832 int l2 = gen_new_label();
1834 tcg_gen_andi_tl(t0, t0, 0x3f);
1835 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1837 tcg_gen_rotr_tl(t0, t1, t0);
1841 tcg_gen_mov_tl(t0, t1);
1845 tcg_gen_andi_tl(t0, t0, 0x3f);
1846 tcg_gen_shr_tl(t0, t1, t0);
1851 MIPS_INVAL("invalid dsrlv flag");
1852 generate_exception(ctx, EXCP_RI);
1859 generate_exception(ctx, EXCP_RI);
1862 gen_store_gpr(t0, rd);
1864 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1870 /* Arithmetic on HI/LO registers */
1871 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1873 const char *opn = "hilo";
1874 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1876 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1884 gen_store_gpr(t0, reg);
1889 gen_store_gpr(t0, reg);
1893 gen_load_gpr(t0, reg);
1894 gen_store_HI(t0, 0);
1898 gen_load_gpr(t0, reg);
1899 gen_store_LO(t0, 0);
1904 generate_exception(ctx, EXCP_RI);
1907 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1912 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1915 const char *opn = "mul/div";
1916 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1917 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
1919 gen_load_gpr(t0, rs);
1920 gen_load_gpr(t1, rt);
1924 int l1 = gen_new_label();
1926 tcg_gen_ext32s_tl(t0, t0);
1927 tcg_gen_ext32s_tl(t1, t1);
1928 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1930 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1931 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1932 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1934 tcg_gen_ext_tl_i64(r_tmp1, t0);
1935 tcg_gen_ext_tl_i64(r_tmp2, t1);
1936 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1937 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1938 tcg_gen_trunc_i64_tl(t0, r_tmp3);
1939 tcg_gen_trunc_i64_tl(t1, r_tmp2);
1940 tcg_temp_free(r_tmp1);
1941 tcg_temp_free(r_tmp2);
1942 tcg_temp_free(r_tmp3);
1943 tcg_gen_ext32s_tl(t0, t0);
1944 tcg_gen_ext32s_tl(t1, t1);
1945 gen_store_LO(t0, 0);
1946 gen_store_HI(t1, 0);
1954 int l1 = gen_new_label();
1956 tcg_gen_ext32s_tl(t1, t1);
1957 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
1959 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1960 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1961 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1963 tcg_gen_trunc_tl_i32(r_tmp1, t0);
1964 tcg_gen_trunc_tl_i32(r_tmp2, t1);
1965 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1966 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1967 tcg_gen_ext_i32_tl(t0, r_tmp3);
1968 tcg_gen_ext_i32_tl(t1, r_tmp1);
1969 tcg_temp_free(r_tmp1);
1970 tcg_temp_free(r_tmp2);
1971 tcg_temp_free(r_tmp3);
1972 gen_store_LO(t0, 0);
1973 gen_store_HI(t1, 0);
1981 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1982 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1984 tcg_gen_ext32s_tl(t0, t0);
1985 tcg_gen_ext32s_tl(t1, t1);
1986 tcg_gen_ext_tl_i64(r_tmp1, t0);
1987 tcg_gen_ext_tl_i64(r_tmp2, t1);
1988 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1989 tcg_temp_free(r_tmp2);
1990 tcg_gen_trunc_i64_tl(t0, r_tmp1);
1991 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1992 tcg_gen_trunc_i64_tl(t1, r_tmp1);
1993 tcg_temp_free(r_tmp1);
1994 tcg_gen_ext32s_tl(t0, t0);
1995 tcg_gen_ext32s_tl(t1, t1);
1996 gen_store_LO(t0, 0);
1997 gen_store_HI(t1, 0);
2003 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2004 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2006 tcg_gen_ext32u_tl(t0, t0);
2007 tcg_gen_ext32u_tl(t1, t1);
2008 tcg_gen_extu_tl_i64(r_tmp1, t0);
2009 tcg_gen_extu_tl_i64(r_tmp2, t1);
2010 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2011 tcg_temp_free(r_tmp2);
2012 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2013 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2014 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2015 tcg_temp_free(r_tmp1);
2016 tcg_gen_ext32s_tl(t0, t0);
2017 tcg_gen_ext32s_tl(t1, t1);
2018 gen_store_LO(t0, 0);
2019 gen_store_HI(t1, 0);
2023 #if defined(TARGET_MIPS64)
2026 int l1 = gen_new_label();
2028 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2030 int l2 = gen_new_label();
2032 tcg_gen_brcondi_tl(TCG_COND_NE, t0, -1LL << 63, l2);
2033 tcg_gen_brcondi_tl(TCG_COND_NE, t1, -1LL, l2);
2035 tcg_gen_movi_tl(t1, 0);
2036 gen_store_LO(t0, 0);
2037 gen_store_HI(t1, 0);
2042 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2043 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2045 tcg_gen_div_i64(r_tmp1, t0, t1);
2046 tcg_gen_rem_i64(r_tmp2, t0, t1);
2047 gen_store_LO(r_tmp1, 0);
2048 gen_store_HI(r_tmp2, 0);
2049 tcg_temp_free(r_tmp1);
2050 tcg_temp_free(r_tmp2);
2059 int l1 = gen_new_label();
2061 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
2063 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2064 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2066 tcg_gen_divu_i64(r_tmp1, t0, t1);
2067 tcg_gen_remu_i64(r_tmp2, t0, t1);
2068 tcg_temp_free(r_tmp1);
2069 tcg_temp_free(r_tmp2);
2070 gen_store_LO(r_tmp1, 0);
2071 gen_store_HI(r_tmp2, 0);
2078 tcg_gen_helper_0_2(do_dmult, t0, t1);
2082 tcg_gen_helper_0_2(do_dmultu, t0, t1);
2088 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2089 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2091 tcg_gen_ext32s_tl(t0, t0);
2092 tcg_gen_ext32s_tl(t1, t1);
2093 tcg_gen_ext_tl_i64(r_tmp1, t0);
2094 tcg_gen_ext_tl_i64(r_tmp2, t1);
2095 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2098 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2099 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2100 tcg_temp_free(r_tmp2);
2101 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2102 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2103 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2104 tcg_temp_free(r_tmp1);
2105 tcg_gen_ext32s_tl(t0, t0);
2106 tcg_gen_ext32s_tl(t1, t1);
2107 gen_store_LO(t0, 0);
2108 gen_store_HI(t1, 0);
2114 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2115 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2117 tcg_gen_ext32u_tl(t0, t0);
2118 tcg_gen_ext32u_tl(t1, t1);
2119 tcg_gen_extu_tl_i64(r_tmp1, t0);
2120 tcg_gen_extu_tl_i64(r_tmp2, t1);
2121 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2124 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2125 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2126 tcg_temp_free(r_tmp2);
2127 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2128 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2129 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2130 tcg_temp_free(r_tmp1);
2131 tcg_gen_ext32s_tl(t0, t0);
2132 tcg_gen_ext32s_tl(t1, t1);
2133 gen_store_LO(t0, 0);
2134 gen_store_HI(t1, 0);
2140 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2141 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2143 tcg_gen_ext32s_tl(t0, t0);
2144 tcg_gen_ext32s_tl(t1, t1);
2145 tcg_gen_ext_tl_i64(r_tmp1, t0);
2146 tcg_gen_ext_tl_i64(r_tmp2, t1);
2147 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2150 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2151 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2152 tcg_temp_free(r_tmp2);
2153 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2154 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2155 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2156 tcg_temp_free(r_tmp1);
2157 tcg_gen_ext32s_tl(t0, t0);
2158 tcg_gen_ext32s_tl(t1, t1);
2159 gen_store_LO(t0, 0);
2160 gen_store_HI(t1, 0);
2166 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2167 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2169 tcg_gen_ext32u_tl(t0, t0);
2170 tcg_gen_ext32u_tl(t1, t1);
2171 tcg_gen_extu_tl_i64(r_tmp1, t0);
2172 tcg_gen_extu_tl_i64(r_tmp2, t1);
2173 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2176 tcg_gen_concat_tl_i64(r_tmp2, t0, t1);
2177 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2178 tcg_temp_free(r_tmp2);
2179 tcg_gen_trunc_i64_tl(t0, r_tmp1);
2180 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2181 tcg_gen_trunc_i64_tl(t1, r_tmp1);
2182 tcg_temp_free(r_tmp1);
2183 tcg_gen_ext32s_tl(t0, t0);
2184 tcg_gen_ext32s_tl(t1, t1);
2185 gen_store_LO(t0, 0);
2186 gen_store_HI(t1, 0);
2192 generate_exception(ctx, EXCP_RI);
2195 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2201 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2202 int rd, int rs, int rt)
2204 const char *opn = "mul vr54xx";
2205 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2206 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2208 gen_load_gpr(t0, rs);
2209 gen_load_gpr(t1, rt);
2212 case OPC_VR54XX_MULS:
2213 tcg_gen_helper_1_2(do_muls, t0, t0, t1);
2216 case OPC_VR54XX_MULSU:
2217 tcg_gen_helper_1_2(do_mulsu, t0, t0, t1);
2220 case OPC_VR54XX_MACC:
2221 tcg_gen_helper_1_2(do_macc, t0, t0, t1);
2224 case OPC_VR54XX_MACCU:
2225 tcg_gen_helper_1_2(do_maccu, t0, t0, t1);
2228 case OPC_VR54XX_MSAC:
2229 tcg_gen_helper_1_2(do_msac, t0, t0, t1);
2232 case OPC_VR54XX_MSACU:
2233 tcg_gen_helper_1_2(do_msacu, t0, t0, t1);
2236 case OPC_VR54XX_MULHI:
2237 tcg_gen_helper_1_2(do_mulhi, t0, t0, t1);
2240 case OPC_VR54XX_MULHIU:
2241 tcg_gen_helper_1_2(do_mulhiu, t0, t0, t1);
2244 case OPC_VR54XX_MULSHI:
2245 tcg_gen_helper_1_2(do_mulshi, t0, t0, t1);
2248 case OPC_VR54XX_MULSHIU:
2249 tcg_gen_helper_1_2(do_mulshiu, t0, t0, t1);
2252 case OPC_VR54XX_MACCHI:
2253 tcg_gen_helper_1_2(do_macchi, t0, t0, t1);
2256 case OPC_VR54XX_MACCHIU:
2257 tcg_gen_helper_1_2(do_macchiu, t0, t0, t1);
2260 case OPC_VR54XX_MSACHI:
2261 tcg_gen_helper_1_2(do_msachi, t0, t0, t1);
2264 case OPC_VR54XX_MSACHIU:
2265 tcg_gen_helper_1_2(do_msachiu, t0, t0, t1);
2269 MIPS_INVAL("mul vr54xx");
2270 generate_exception(ctx, EXCP_RI);
2273 gen_store_gpr(t0, rd);
2274 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2281 static void gen_cl (DisasContext *ctx, uint32_t opc,
2284 const char *opn = "CLx";
2285 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2292 gen_load_gpr(t0, rs);
2295 tcg_gen_helper_1_1(do_clo, t0, t0);
2299 tcg_gen_helper_1_1(do_clz, t0, t0);
2302 #if defined(TARGET_MIPS64)
2304 tcg_gen_helper_1_1(do_dclo, t0, t0);
2308 tcg_gen_helper_1_1(do_dclz, t0, t0);
2314 generate_exception(ctx, EXCP_RI);
2317 gen_store_gpr(t0, rd);
2318 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2325 static void gen_trap (DisasContext *ctx, uint32_t opc,
2326 int rs, int rt, int16_t imm)
2329 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2330 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2333 /* Load needed operands */
2341 /* Compare two registers */
2343 gen_load_gpr(t0, rs);
2344 gen_load_gpr(t1, rt);
2354 /* Compare register to immediate */
2355 if (rs != 0 || imm != 0) {
2356 gen_load_gpr(t0, rs);
2357 tcg_gen_movi_tl(t1, (int32_t)imm);
2364 case OPC_TEQ: /* rs == rs */
2365 case OPC_TEQI: /* r0 == 0 */
2366 case OPC_TGE: /* rs >= rs */
2367 case OPC_TGEI: /* r0 >= 0 */
2368 case OPC_TGEU: /* rs >= rs unsigned */
2369 case OPC_TGEIU: /* r0 >= 0 unsigned */
2371 tcg_gen_movi_tl(t0, 1);
2373 case OPC_TLT: /* rs < rs */
2374 case OPC_TLTI: /* r0 < 0 */
2375 case OPC_TLTU: /* rs < rs unsigned */
2376 case OPC_TLTIU: /* r0 < 0 unsigned */
2377 case OPC_TNE: /* rs != rs */
2378 case OPC_TNEI: /* r0 != 0 */
2379 /* Never trap: treat as NOP. */
2383 generate_exception(ctx, EXCP_RI);
2414 generate_exception(ctx, EXCP_RI);
2418 save_cpu_state(ctx, 1);
2420 int l1 = gen_new_label();
2422 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2423 tcg_gen_helper_0_i(do_raise_exception, EXCP_TRAP);
2426 ctx->bstate = BS_STOP;
2432 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2434 TranslationBlock *tb;
2436 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2439 tcg_gen_exit_tb((long)tb + n);
2446 /* Branches (before delay slot) */
2447 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2448 int rs, int rt, int32_t offset)
2450 target_ulong btgt = -1;
2452 int bcond_compute = 0;
2453 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2454 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2456 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2457 #ifdef MIPS_DEBUG_DISAS
2458 if (loglevel & CPU_LOG_TB_IN_ASM) {
2460 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2464 generate_exception(ctx, EXCP_RI);
2468 /* Load needed operands */
2474 /* Compare two registers */
2476 gen_load_gpr(t0, rs);
2477 gen_load_gpr(t1, rt);
2480 btgt = ctx->pc + 4 + offset;
2494 /* Compare to zero */
2496 gen_load_gpr(t0, rs);
2499 btgt = ctx->pc + 4 + offset;
2503 /* Jump to immediate */
2504 btgt = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2508 /* Jump to register */
2509 if (offset != 0 && offset != 16) {
2510 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2511 others are reserved. */
2512 MIPS_INVAL("jump hint");
2513 generate_exception(ctx, EXCP_RI);
2516 gen_load_gpr(btarget, rs);
2519 MIPS_INVAL("branch/jump");
2520 generate_exception(ctx, EXCP_RI);
2523 if (bcond_compute == 0) {
2524 /* No condition to be computed */
2526 case OPC_BEQ: /* rx == rx */
2527 case OPC_BEQL: /* rx == rx likely */
2528 case OPC_BGEZ: /* 0 >= 0 */
2529 case OPC_BGEZL: /* 0 >= 0 likely */
2530 case OPC_BLEZ: /* 0 <= 0 */
2531 case OPC_BLEZL: /* 0 <= 0 likely */
2533 ctx->hflags |= MIPS_HFLAG_B;
2534 MIPS_DEBUG("balways");
2536 case OPC_BGEZAL: /* 0 >= 0 */
2537 case OPC_BGEZALL: /* 0 >= 0 likely */
2538 /* Always take and link */
2540 ctx->hflags |= MIPS_HFLAG_B;
2541 MIPS_DEBUG("balways and link");
2543 case OPC_BNE: /* rx != rx */
2544 case OPC_BGTZ: /* 0 > 0 */
2545 case OPC_BLTZ: /* 0 < 0 */
2547 MIPS_DEBUG("bnever (NOP)");
2549 case OPC_BLTZAL: /* 0 < 0 */
2550 tcg_gen_movi_tl(t0, ctx->pc + 8);
2551 gen_store_gpr(t0, 31);
2552 MIPS_DEBUG("bnever and link");
2554 case OPC_BLTZALL: /* 0 < 0 likely */
2555 tcg_gen_movi_tl(t0, ctx->pc + 8);
2556 gen_store_gpr(t0, 31);
2557 /* Skip the instruction in the delay slot */
2558 MIPS_DEBUG("bnever, link and skip");
2561 case OPC_BNEL: /* rx != rx likely */
2562 case OPC_BGTZL: /* 0 > 0 likely */
2563 case OPC_BLTZL: /* 0 < 0 likely */
2564 /* Skip the instruction in the delay slot */
2565 MIPS_DEBUG("bnever and skip");
2569 ctx->hflags |= MIPS_HFLAG_B;
2570 MIPS_DEBUG("j " TARGET_FMT_lx, btgt);
2574 ctx->hflags |= MIPS_HFLAG_B;
2575 MIPS_DEBUG("jal " TARGET_FMT_lx, btgt);
2578 ctx->hflags |= MIPS_HFLAG_BR;
2579 MIPS_DEBUG("jr %s", regnames[rs]);
2583 ctx->hflags |= MIPS_HFLAG_BR;
2584 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2587 MIPS_INVAL("branch/jump");
2588 generate_exception(ctx, EXCP_RI);
2595 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2596 regnames[rs], regnames[rt], btgt);
2600 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2601 regnames[rs], regnames[rt], btgt);
2605 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2606 regnames[rs], regnames[rt], btgt);
2610 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2611 regnames[rs], regnames[rt], btgt);
2615 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2619 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2623 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2629 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2633 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2637 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2641 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btgt);
2645 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2649 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btgt);
2653 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btgt);
2658 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btgt);
2660 ctx->hflags |= MIPS_HFLAG_BC;
2661 tcg_gen_trunc_tl_i32(bcond, t0);
2666 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btgt);
2668 ctx->hflags |= MIPS_HFLAG_BL;
2669 tcg_gen_trunc_tl_i32(bcond, t0);
2672 MIPS_INVAL("conditional branch/jump");
2673 generate_exception(ctx, EXCP_RI);
2677 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2678 blink, ctx->hflags, btgt);
2680 ctx->btarget = btgt;
2682 tcg_gen_movi_tl(t0, ctx->pc + 8);
2683 gen_store_gpr(t0, blink);
2691 /* special3 bitfield operations */
2692 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2693 int rs, int lsb, int msb)
2695 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
2696 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
2698 gen_load_gpr(t1, rs);
2703 tcg_gen_helper_1_1ii(do_ext, t0, t1, lsb, msb + 1);
2705 #if defined(TARGET_MIPS64)
2709 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1 + 32);
2714 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb + 32, msb + 1);
2719 tcg_gen_helper_1_1ii(do_dext, t0, t1, lsb, msb + 1);
2725 gen_load_gpr(t0, rt);
2726 tcg_gen_helper_1_2ii(do_ins, t0, t0, t1, lsb, msb - lsb + 1);
2728 #if defined(TARGET_MIPS64)
2732 gen_load_gpr(t0, rt);
2733 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1 + 32);
2738 gen_load_gpr(t0, rt);
2739 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb + 32, msb - lsb + 1);
2744 gen_load_gpr(t0, rt);
2745 tcg_gen_helper_1_2ii(do_dins, t0, t0, t1, lsb, msb - lsb + 1);
2750 MIPS_INVAL("bitops");
2751 generate_exception(ctx, EXCP_RI);
2756 gen_store_gpr(t0, rt);
2761 #ifndef CONFIG_USER_ONLY
2762 /* CP0 (MMU and control) */
2763 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2765 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2767 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2768 tcg_gen_ext_i32_tl(t, r_tmp);
2769 tcg_temp_free(r_tmp);
2772 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2774 tcg_gen_ld_tl(t, cpu_env, off);
2775 tcg_gen_ext32s_tl(t, t);
2778 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2780 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2782 tcg_gen_trunc_tl_i32(r_tmp, t);
2783 tcg_gen_st_i32(r_tmp, cpu_env, off);
2784 tcg_temp_free(r_tmp);
2787 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2789 tcg_gen_ext32s_tl(t, t);
2790 tcg_gen_st_tl(t, cpu_env, off);
2793 static void gen_mfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
2795 const char *rn = "invalid";
2798 check_insn(env, ctx, ISA_MIPS32);
2804 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
2808 check_insn(env, ctx, ASE_MT);
2809 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
2813 check_insn(env, ctx, ASE_MT);
2814 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
2818 check_insn(env, ctx, ASE_MT);
2819 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
2829 tcg_gen_helper_1_0(do_mfc0_random, t0);
2833 check_insn(env, ctx, ASE_MT);
2834 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
2838 check_insn(env, ctx, ASE_MT);
2839 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
2843 check_insn(env, ctx, ASE_MT);
2844 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
2848 check_insn(env, ctx, ASE_MT);
2849 gen_mfc0_load64(t0, offsetof(CPUState, CP0_YQMask));
2853 check_insn(env, ctx, ASE_MT);
2854 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPESchedule));
2858 check_insn(env, ctx, ASE_MT);
2859 gen_mfc0_load64(t0, offsetof(CPUState, CP0_VPEScheFBack));
2860 rn = "VPEScheFBack";
2863 check_insn(env, ctx, ASE_MT);
2864 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
2874 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
2875 tcg_gen_ext32s_tl(t0, t0);
2879 check_insn(env, ctx, ASE_MT);
2880 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
2884 check_insn(env, ctx, ASE_MT);
2885 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
2889 check_insn(env, ctx, ASE_MT);
2890 tcg_gen_helper_1_0(do_mfc0_tcrestart, t0);
2894 check_insn(env, ctx, ASE_MT);
2895 tcg_gen_helper_1_0(do_mfc0_tchalt, t0);
2899 check_insn(env, ctx, ASE_MT);
2900 tcg_gen_helper_1_0(do_mfc0_tccontext, t0);
2904 check_insn(env, ctx, ASE_MT);
2905 tcg_gen_helper_1_0(do_mfc0_tcschedule, t0);
2909 check_insn(env, ctx, ASE_MT);
2910 tcg_gen_helper_1_0(do_mfc0_tcschefback, t0);
2920 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
2921 tcg_gen_ext32s_tl(t0, t0);
2931 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
2932 tcg_gen_ext32s_tl(t0, t0);
2936 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2937 rn = "ContextConfig";
2946 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
2950 check_insn(env, ctx, ISA_MIPS32R2);
2951 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
2961 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
2965 check_insn(env, ctx, ISA_MIPS32R2);
2966 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
2970 check_insn(env, ctx, ISA_MIPS32R2);
2971 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
2975 check_insn(env, ctx, ISA_MIPS32R2);
2976 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
2980 check_insn(env, ctx, ISA_MIPS32R2);
2981 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
2985 check_insn(env, ctx, ISA_MIPS32R2);
2986 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
2996 check_insn(env, ctx, ISA_MIPS32R2);
2997 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
3007 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
3008 tcg_gen_ext32s_tl(t0, t0);
3018 /* Mark as an IO operation because we read the time. */
3021 tcg_gen_helper_1_0(do_mfc0_count, t0);
3024 ctx->bstate = BS_STOP;
3028 /* 6,7 are implementation dependent */
3036 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
3037 tcg_gen_ext32s_tl(t0, t0);
3047 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
3050 /* 6,7 are implementation dependent */
3058 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
3062 check_insn(env, ctx, ISA_MIPS32R2);
3063 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
3067 check_insn(env, ctx, ISA_MIPS32R2);
3068 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
3072 check_insn(env, ctx, ISA_MIPS32R2);
3073 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
3083 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
3093 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
3094 tcg_gen_ext32s_tl(t0, t0);
3104 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
3108 check_insn(env, ctx, ISA_MIPS32R2);
3109 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
3119 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
3123 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
3127 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
3131 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
3134 /* 4,5 are reserved */
3135 /* 6,7 are implementation dependent */
3137 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
3141 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
3151 tcg_gen_helper_1_0(do_mfc0_lladdr, t0);
3161 tcg_gen_helper_1_i(do_mfc0_watchlo, t0, sel);
3171 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
3181 #if defined(TARGET_MIPS64)
3182 check_insn(env, ctx, ISA_MIPS3);
3183 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
3184 tcg_gen_ext32s_tl(t0, t0);
3193 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3196 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
3205 rn = "'Diagnostic"; /* implementation dependent */
3210 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
3214 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3215 rn = "TraceControl";
3218 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3219 rn = "TraceControl2";
3222 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3223 rn = "UserTraceData";
3226 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3237 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
3238 tcg_gen_ext32s_tl(t0, t0);
3248 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
3249 rn = "Performance0";
3252 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3253 rn = "Performance1";
3256 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3257 rn = "Performance2";
3260 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3261 rn = "Performance3";
3264 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3265 rn = "Performance4";
3268 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3269 rn = "Performance5";
3272 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3273 rn = "Performance6";
3276 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3277 rn = "Performance7";
3302 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
3309 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
3322 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
3329 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
3339 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3340 tcg_gen_ext32s_tl(t0, t0);
3351 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
3361 #if defined MIPS_DEBUG_DISAS
3362 if (loglevel & CPU_LOG_TB_IN_ASM) {
3363 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3370 #if defined MIPS_DEBUG_DISAS
3371 if (loglevel & CPU_LOG_TB_IN_ASM) {
3372 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3376 generate_exception(ctx, EXCP_RI);
3379 static void gen_mtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3381 const char *rn = "invalid";
3384 check_insn(env, ctx, ISA_MIPS32);
3393 tcg_gen_helper_0_1(do_mtc0_index, t0);
3397 check_insn(env, ctx, ASE_MT);
3398 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
3402 check_insn(env, ctx, ASE_MT);
3407 check_insn(env, ctx, ASE_MT);
3422 check_insn(env, ctx, ASE_MT);
3423 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
3427 check_insn(env, ctx, ASE_MT);
3428 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
3432 check_insn(env, ctx, ASE_MT);
3433 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
3437 check_insn(env, ctx, ASE_MT);
3438 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
3442 check_insn(env, ctx, ASE_MT);
3443 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPESchedule));
3447 check_insn(env, ctx, ASE_MT);
3448 gen_mtc0_store64(t0, offsetof(CPUState, CP0_VPEScheFBack));
3449 rn = "VPEScheFBack";
3452 check_insn(env, ctx, ASE_MT);
3453 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
3463 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
3467 check_insn(env, ctx, ASE_MT);
3468 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
3472 check_insn(env, ctx, ASE_MT);
3473 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
3477 check_insn(env, ctx, ASE_MT);
3478 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
3482 check_insn(env, ctx, ASE_MT);
3483 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
3487 check_insn(env, ctx, ASE_MT);
3488 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
3492 check_insn(env, ctx, ASE_MT);
3493 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
3497 check_insn(env, ctx, ASE_MT);
3498 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
3508 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
3518 tcg_gen_helper_0_1(do_mtc0_context, t0);
3522 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3523 rn = "ContextConfig";
3532 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
3536 check_insn(env, ctx, ISA_MIPS32R2);
3537 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
3547 tcg_gen_helper_0_1(do_mtc0_wired, t0);
3551 check_insn(env, ctx, ISA_MIPS32R2);
3552 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
3556 check_insn(env, ctx, ISA_MIPS32R2);
3557 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
3561 check_insn(env, ctx, ISA_MIPS32R2);
3562 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
3566 check_insn(env, ctx, ISA_MIPS32R2);
3567 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
3571 check_insn(env, ctx, ISA_MIPS32R2);
3572 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
3582 check_insn(env, ctx, ISA_MIPS32R2);
3583 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
3597 tcg_gen_helper_0_1(do_mtc0_count, t0);
3600 /* 6,7 are implementation dependent */
3604 /* Stop translation as we may have switched the execution mode */
3605 ctx->bstate = BS_STOP;
3610 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
3620 tcg_gen_helper_0_1(do_mtc0_compare, t0);
3623 /* 6,7 are implementation dependent */
3627 /* Stop translation as we may have switched the execution mode */
3628 ctx->bstate = BS_STOP;
3633 tcg_gen_helper_0_1(do_mtc0_status, t0);
3634 /* BS_STOP isn't good enough here, hflags may have changed. */
3635 gen_save_pc(ctx->pc + 4);
3636 ctx->bstate = BS_EXCP;
3640 check_insn(env, ctx, ISA_MIPS32R2);
3641 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
3642 /* Stop translation as we may have switched the execution mode */
3643 ctx->bstate = BS_STOP;
3647 check_insn(env, ctx, ISA_MIPS32R2);
3648 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
3649 /* Stop translation as we may have switched the execution mode */
3650 ctx->bstate = BS_STOP;
3654 check_insn(env, ctx, ISA_MIPS32R2);
3655 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
3656 /* Stop translation as we may have switched the execution mode */
3657 ctx->bstate = BS_STOP;
3667 tcg_gen_helper_0_1(do_mtc0_cause, t0);
3673 /* Stop translation as we may have switched the execution mode */
3674 ctx->bstate = BS_STOP;
3679 gen_mtc0_store64(t0, offsetof(CPUState, CP0_EPC));
3693 check_insn(env, ctx, ISA_MIPS32R2);
3694 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
3704 tcg_gen_helper_0_1(do_mtc0_config0, t0);
3706 /* Stop translation as we may have switched the execution mode */
3707 ctx->bstate = BS_STOP;
3710 /* ignored, read only */
3714 tcg_gen_helper_0_1(do_mtc0_config2, t0);
3716 /* Stop translation as we may have switched the execution mode */
3717 ctx->bstate = BS_STOP;
3720 /* ignored, read only */
3723 /* 4,5 are reserved */
3724 /* 6,7 are implementation dependent */
3734 rn = "Invalid config selector";
3751 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
3761 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
3771 #if defined(TARGET_MIPS64)
3772 check_insn(env, ctx, ISA_MIPS3);
3773 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
3782 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3785 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
3794 rn = "Diagnostic"; /* implementation dependent */
3799 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
3800 /* BS_STOP isn't good enough here, hflags may have changed. */
3801 gen_save_pc(ctx->pc + 4);
3802 ctx->bstate = BS_EXCP;
3806 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3807 rn = "TraceControl";
3808 /* Stop translation as we may have switched the execution mode */
3809 ctx->bstate = BS_STOP;
3812 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3813 rn = "TraceControl2";
3814 /* Stop translation as we may have switched the execution mode */
3815 ctx->bstate = BS_STOP;
3818 /* Stop translation as we may have switched the execution mode */
3819 ctx->bstate = BS_STOP;
3820 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3821 rn = "UserTraceData";
3822 /* Stop translation as we may have switched the execution mode */
3823 ctx->bstate = BS_STOP;
3826 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3827 /* Stop translation as we may have switched the execution mode */
3828 ctx->bstate = BS_STOP;
3839 gen_mtc0_store64(t0, offsetof(CPUState, CP0_DEPC));
3849 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
3850 rn = "Performance0";
3853 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3854 rn = "Performance1";
3857 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3858 rn = "Performance2";
3861 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3862 rn = "Performance3";
3865 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3866 rn = "Performance4";
3869 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3870 rn = "Performance5";
3873 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3874 rn = "Performance6";
3877 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3878 rn = "Performance7";
3904 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
3911 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
3924 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
3931 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
3942 gen_mtc0_store64(t0, offsetof(CPUState, CP0_ErrorEPC));
3953 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
3959 /* Stop translation as we may have switched the execution mode */
3960 ctx->bstate = BS_STOP;
3965 #if defined MIPS_DEBUG_DISAS
3966 if (loglevel & CPU_LOG_TB_IN_ASM) {
3967 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3971 /* For simplicity assume that all writes can cause interrupts. */
3974 ctx->bstate = BS_STOP;
3979 #if defined MIPS_DEBUG_DISAS
3980 if (loglevel & CPU_LOG_TB_IN_ASM) {
3981 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3985 generate_exception(ctx, EXCP_RI);
3988 #if defined(TARGET_MIPS64)
3989 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
3991 const char *rn = "invalid";
3994 check_insn(env, ctx, ISA_MIPS64);
4000 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Index));
4004 check_insn(env, ctx, ASE_MT);
4005 tcg_gen_helper_1_0(do_mfc0_mvpcontrol, t0);
4009 check_insn(env, ctx, ASE_MT);
4010 tcg_gen_helper_1_0(do_mfc0_mvpconf0, t0);
4014 check_insn(env, ctx, ASE_MT);
4015 tcg_gen_helper_1_0(do_mfc0_mvpconf1, t0);
4025 tcg_gen_helper_1_0(do_mfc0_random, t0);
4029 check_insn(env, ctx, ASE_MT);
4030 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEControl));
4034 check_insn(env, ctx, ASE_MT);
4035 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf0));
4039 check_insn(env, ctx, ASE_MT);
4040 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEConf1));
4044 check_insn(env, ctx, ASE_MT);
4045 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_YQMask));
4049 check_insn(env, ctx, ASE_MT);
4050 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4054 check_insn(env, ctx, ASE_MT);
4055 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4056 rn = "VPEScheFBack";
4059 check_insn(env, ctx, ASE_MT);
4060 gen_mfc0_load32(t0, offsetof(CPUState, CP0_VPEOpt));
4070 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo0));
4074 check_insn(env, ctx, ASE_MT);
4075 tcg_gen_helper_1_0(do_mfc0_tcstatus, t0);
4079 check_insn(env, ctx, ASE_MT);
4080 tcg_gen_helper_1_0(do_mfc0_tcbind, t0);
4084 check_insn(env, ctx, ASE_MT);
4085 tcg_gen_helper_1_0(do_dmfc0_tcrestart, t0);
4089 check_insn(env, ctx, ASE_MT);
4090 tcg_gen_helper_1_0(do_dmfc0_tchalt, t0);
4094 check_insn(env, ctx, ASE_MT);
4095 tcg_gen_helper_1_0(do_dmfc0_tccontext, t0);
4099 check_insn(env, ctx, ASE_MT);
4100 tcg_gen_helper_1_0(do_dmfc0_tcschedule, t0);
4104 check_insn(env, ctx, ASE_MT);
4105 tcg_gen_helper_1_0(do_dmfc0_tcschefback, t0);
4115 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryLo1));
4125 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_Context));
4129 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4130 rn = "ContextConfig";
4139 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageMask));
4143 check_insn(env, ctx, ISA_MIPS32R2);
4144 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PageGrain));
4154 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Wired));
4158 check_insn(env, ctx, ISA_MIPS32R2);
4159 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf0));
4163 check_insn(env, ctx, ISA_MIPS32R2);
4164 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf1));
4168 check_insn(env, ctx, ISA_MIPS32R2);
4169 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf2));
4173 check_insn(env, ctx, ISA_MIPS32R2);
4174 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf3));
4178 check_insn(env, ctx, ISA_MIPS32R2);
4179 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSConf4));
4189 check_insn(env, ctx, ISA_MIPS32R2);
4190 gen_mfc0_load32(t0, offsetof(CPUState, CP0_HWREna));
4200 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr));
4210 /* Mark as an IO operation because we read the time. */
4213 tcg_gen_helper_1_0(do_mfc0_count, t0);
4216 ctx->bstate = BS_STOP;
4220 /* 6,7 are implementation dependent */
4228 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EntryHi));
4238 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Compare));
4241 /* 6,7 are implementation dependent */
4249 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Status));
4253 check_insn(env, ctx, ISA_MIPS32R2);
4254 gen_mfc0_load32(t0, offsetof(CPUState, CP0_IntCtl));
4258 check_insn(env, ctx, ISA_MIPS32R2);
4259 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSCtl));
4263 check_insn(env, ctx, ISA_MIPS32R2);
4264 gen_mfc0_load32(t0, offsetof(CPUState, CP0_SRSMap));
4274 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Cause));
4284 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4294 gen_mfc0_load32(t0, offsetof(CPUState, CP0_PRid));
4298 check_insn(env, ctx, ISA_MIPS32R2);
4299 gen_mfc0_load32(t0, offsetof(CPUState, CP0_EBase));
4309 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config0));
4313 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config1));
4317 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config2));
4321 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config3));
4324 /* 6,7 are implementation dependent */
4326 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config6));
4330 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Config7));
4340 tcg_gen_helper_1_0(do_dmfc0_lladdr, t0);
4350 tcg_gen_helper_1_i(do_dmfc0_watchlo, t0, sel);
4360 tcg_gen_helper_1_i(do_mfc0_watchhi, t0, sel);
4370 check_insn(env, ctx, ISA_MIPS3);
4371 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_XContext));
4379 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4382 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Framemask));
4391 rn = "'Diagnostic"; /* implementation dependent */
4396 tcg_gen_helper_1_0(do_mfc0_debug, t0); /* EJTAG support */
4400 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4401 rn = "TraceControl";
4404 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4405 rn = "TraceControl2";
4408 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4409 rn = "UserTraceData";
4412 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4423 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
4433 gen_mfc0_load32(t0, offsetof(CPUState, CP0_Performance0));
4434 rn = "Performance0";
4437 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4438 rn = "Performance1";
4441 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4442 rn = "Performance2";
4445 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4446 rn = "Performance3";
4449 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4450 rn = "Performance4";
4453 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4454 rn = "Performance5";
4457 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4458 rn = "Performance6";
4461 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4462 rn = "Performance7";
4487 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagLo));
4494 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataLo));
4507 gen_mfc0_load32(t0, offsetof(CPUState, CP0_TagHi));
4514 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DataHi));
4524 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4535 gen_mfc0_load32(t0, offsetof(CPUState, CP0_DESAVE));
4545 #if defined MIPS_DEBUG_DISAS
4546 if (loglevel & CPU_LOG_TB_IN_ASM) {
4547 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4554 #if defined MIPS_DEBUG_DISAS
4555 if (loglevel & CPU_LOG_TB_IN_ASM) {
4556 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4560 generate_exception(ctx, EXCP_RI);
4563 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, TCGv t0, int reg, int sel)
4565 const char *rn = "invalid";
4568 check_insn(env, ctx, ISA_MIPS64);
4577 tcg_gen_helper_0_1(do_mtc0_index, t0);
4581 check_insn(env, ctx, ASE_MT);
4582 tcg_gen_helper_0_1(do_mtc0_mvpcontrol, t0);
4586 check_insn(env, ctx, ASE_MT);
4591 check_insn(env, ctx, ASE_MT);
4606 check_insn(env, ctx, ASE_MT);
4607 tcg_gen_helper_0_1(do_mtc0_vpecontrol, t0);
4611 check_insn(env, ctx, ASE_MT);
4612 tcg_gen_helper_0_1(do_mtc0_vpeconf0, t0);
4616 check_insn(env, ctx, ASE_MT);
4617 tcg_gen_helper_0_1(do_mtc0_vpeconf1, t0);
4621 check_insn(env, ctx, ASE_MT);
4622 tcg_gen_helper_0_1(do_mtc0_yqmask, t0);
4626 check_insn(env, ctx, ASE_MT);
4627 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPESchedule));
4631 check_insn(env, ctx, ASE_MT);
4632 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4633 rn = "VPEScheFBack";
4636 check_insn(env, ctx, ASE_MT);
4637 tcg_gen_helper_0_1(do_mtc0_vpeopt, t0);
4647 tcg_gen_helper_0_1(do_mtc0_entrylo0, t0);
4651 check_insn(env, ctx, ASE_MT);
4652 tcg_gen_helper_0_1(do_mtc0_tcstatus, t0);
4656 check_insn(env, ctx, ASE_MT);
4657 tcg_gen_helper_0_1(do_mtc0_tcbind, t0);
4661 check_insn(env, ctx, ASE_MT);
4662 tcg_gen_helper_0_1(do_mtc0_tcrestart, t0);
4666 check_insn(env, ctx, ASE_MT);
4667 tcg_gen_helper_0_1(do_mtc0_tchalt, t0);
4671 check_insn(env, ctx, ASE_MT);
4672 tcg_gen_helper_0_1(do_mtc0_tccontext, t0);
4676 check_insn(env, ctx, ASE_MT);
4677 tcg_gen_helper_0_1(do_mtc0_tcschedule, t0);
4681 check_insn(env, ctx, ASE_MT);
4682 tcg_gen_helper_0_1(do_mtc0_tcschefback, t0);
4692 tcg_gen_helper_0_1(do_mtc0_entrylo1, t0);
4702 tcg_gen_helper_0_1(do_mtc0_context, t0);
4706 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4707 rn = "ContextConfig";
4716 tcg_gen_helper_0_1(do_mtc0_pagemask, t0);
4720 check_insn(env, ctx, ISA_MIPS32R2);
4721 tcg_gen_helper_0_1(do_mtc0_pagegrain, t0);
4731 tcg_gen_helper_0_1(do_mtc0_wired, t0);
4735 check_insn(env, ctx, ISA_MIPS32R2);
4736 tcg_gen_helper_0_1(do_mtc0_srsconf0, t0);
4740 check_insn(env, ctx, ISA_MIPS32R2);
4741 tcg_gen_helper_0_1(do_mtc0_srsconf1, t0);
4745 check_insn(env, ctx, ISA_MIPS32R2);
4746 tcg_gen_helper_0_1(do_mtc0_srsconf2, t0);
4750 check_insn(env, ctx, ISA_MIPS32R2);
4751 tcg_gen_helper_0_1(do_mtc0_srsconf3, t0);
4755 check_insn(env, ctx, ISA_MIPS32R2);
4756 tcg_gen_helper_0_1(do_mtc0_srsconf4, t0);
4766 check_insn(env, ctx, ISA_MIPS32R2);
4767 tcg_gen_helper_0_1(do_mtc0_hwrena, t0);
4781 tcg_gen_helper_0_1(do_mtc0_count, t0);
4784 /* 6,7 are implementation dependent */
4788 /* Stop translation as we may have switched the execution mode */
4789 ctx->bstate = BS_STOP;
4794 tcg_gen_helper_0_1(do_mtc0_entryhi, t0);
4804 tcg_gen_helper_0_1(do_mtc0_compare, t0);
4807 /* 6,7 are implementation dependent */
4811 /* Stop translation as we may have switched the execution mode */
4812 ctx->bstate = BS_STOP;
4817 tcg_gen_helper_0_1(do_mtc0_status, t0);
4818 /* BS_STOP isn't good enough here, hflags may have changed. */
4819 gen_save_pc(ctx->pc + 4);
4820 ctx->bstate = BS_EXCP;
4824 check_insn(env, ctx, ISA_MIPS32R2);
4825 tcg_gen_helper_0_1(do_mtc0_intctl, t0);
4826 /* Stop translation as we may have switched the execution mode */
4827 ctx->bstate = BS_STOP;
4831 check_insn(env, ctx, ISA_MIPS32R2);
4832 tcg_gen_helper_0_1(do_mtc0_srsctl, t0);
4833 /* Stop translation as we may have switched the execution mode */
4834 ctx->bstate = BS_STOP;
4838 check_insn(env, ctx, ISA_MIPS32R2);
4839 gen_mtc0_store32(t0, offsetof(CPUState, CP0_SRSMap));
4840 /* Stop translation as we may have switched the execution mode */
4841 ctx->bstate = BS_STOP;
4851 tcg_gen_helper_0_1(do_mtc0_cause, t0);
4857 /* Stop translation as we may have switched the execution mode */
4858 ctx->bstate = BS_STOP;
4863 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_EPC));
4877 check_insn(env, ctx, ISA_MIPS32R2);
4878 tcg_gen_helper_0_1(do_mtc0_ebase, t0);
4888 tcg_gen_helper_0_1(do_mtc0_config0, t0);
4890 /* Stop translation as we may have switched the execution mode */
4891 ctx->bstate = BS_STOP;
4898 tcg_gen_helper_0_1(do_mtc0_config2, t0);
4900 /* Stop translation as we may have switched the execution mode */
4901 ctx->bstate = BS_STOP;
4907 /* 6,7 are implementation dependent */
4909 rn = "Invalid config selector";
4926 tcg_gen_helper_0_1i(do_mtc0_watchlo, t0, sel);
4936 tcg_gen_helper_0_1i(do_mtc0_watchhi, t0, sel);
4946 check_insn(env, ctx, ISA_MIPS3);
4947 tcg_gen_helper_0_1(do_mtc0_xcontext, t0);
4955 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4958 tcg_gen_helper_0_1(do_mtc0_framemask, t0);
4967 rn = "Diagnostic"; /* implementation dependent */
4972 tcg_gen_helper_0_1(do_mtc0_debug, t0); /* EJTAG support */
4973 /* BS_STOP isn't good enough here, hflags may have changed. */
4974 gen_save_pc(ctx->pc + 4);
4975 ctx->bstate = BS_EXCP;
4979 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
4980 /* Stop translation as we may have switched the execution mode */
4981 ctx->bstate = BS_STOP;
4982 rn = "TraceControl";
4985 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
4986 /* Stop translation as we may have switched the execution mode */
4987 ctx->bstate = BS_STOP;
4988 rn = "TraceControl2";
4991 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
4992 /* Stop translation as we may have switched the execution mode */
4993 ctx->bstate = BS_STOP;
4994 rn = "UserTraceData";
4997 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
4998 /* Stop translation as we may have switched the execution mode */
4999 ctx->bstate = BS_STOP;
5010 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_DEPC));
5020 tcg_gen_helper_0_1(do_mtc0_performance0, t0);
5021 rn = "Performance0";
5024 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5025 rn = "Performance1";
5028 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5029 rn = "Performance2";
5032 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5033 rn = "Performance3";
5036 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5037 rn = "Performance4";
5040 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5041 rn = "Performance5";
5044 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5045 rn = "Performance6";
5048 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5049 rn = "Performance7";
5075 tcg_gen_helper_0_1(do_mtc0_taglo, t0);
5082 tcg_gen_helper_0_1(do_mtc0_datalo, t0);
5095 tcg_gen_helper_0_1(do_mtc0_taghi, t0);
5102 tcg_gen_helper_0_1(do_mtc0_datahi, t0);
5113 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5124 gen_mtc0_store32(t0, offsetof(CPUState, CP0_DESAVE));
5130 /* Stop translation as we may have switched the execution mode */
5131 ctx->bstate = BS_STOP;
5136 #if defined MIPS_DEBUG_DISAS
5137 if (loglevel & CPU_LOG_TB_IN_ASM) {
5138 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5142 /* For simplicity assume that all writes can cause interrupts. */
5145 ctx->bstate = BS_STOP;
5150 #if defined MIPS_DEBUG_DISAS
5151 if (loglevel & CPU_LOG_TB_IN_ASM) {
5152 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5156 generate_exception(ctx, EXCP_RI);
5158 #endif /* TARGET_MIPS64 */
5160 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt, int rd,
5161 int u, int sel, int h)
5163 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5164 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5166 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5167 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5168 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5169 tcg_gen_movi_tl(t0, -1);
5170 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5171 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5172 tcg_gen_movi_tl(t0, -1);
5178 tcg_gen_helper_1_0(do_mftc0_tcstatus, t0);
5181 tcg_gen_helper_1_0(do_mftc0_tcbind, t0);
5184 tcg_gen_helper_1_0(do_mftc0_tcrestart, t0);
5187 tcg_gen_helper_1_0(do_mftc0_tchalt, t0);
5190 tcg_gen_helper_1_0(do_mftc0_tccontext, t0);
5193 tcg_gen_helper_1_0(do_mftc0_tcschedule, t0);
5196 tcg_gen_helper_1_0(do_mftc0_tcschefback, t0);
5199 gen_mfc0(env, ctx, t0, rt, sel);
5206 tcg_gen_helper_1_0(do_mftc0_entryhi, t0);
5209 gen_mfc0(env, ctx, t0, rt, sel);
5215 tcg_gen_helper_1_0(do_mftc0_status, t0);
5218 gen_mfc0(env, ctx, t0, rt, sel);
5224 tcg_gen_helper_1_0(do_mftc0_debug, t0);
5227 gen_mfc0(env, ctx, t0, rt, sel);
5232 gen_mfc0(env, ctx, t0, rt, sel);
5234 } else switch (sel) {
5235 /* GPR registers. */
5237 tcg_gen_helper_1_i(do_mftgpr, t0, rt);
5239 /* Auxiliary CPU registers */
5243 tcg_gen_helper_1_i(do_mftlo, t0, 0);
5246 tcg_gen_helper_1_i(do_mfthi, t0, 0);
5249 tcg_gen_helper_1_i(do_mftacx, t0, 0);
5252 tcg_gen_helper_1_i(do_mftlo, t0, 1);
5255 tcg_gen_helper_1_i(do_mfthi, t0, 1);
5258 tcg_gen_helper_1_i(do_mftacx, t0, 1);
5261 tcg_gen_helper_1_i(do_mftlo, t0, 2);
5264 tcg_gen_helper_1_i(do_mfthi, t0, 2);
5267 tcg_gen_helper_1_i(do_mftacx, t0, 2);
5270 tcg_gen_helper_1_i(do_mftlo, t0, 3);
5273 tcg_gen_helper_1_i(do_mfthi, t0, 3);
5276 tcg_gen_helper_1_i(do_mftacx, t0, 3);
5279 tcg_gen_helper_1_0(do_mftdsp, t0);
5285 /* Floating point (COP1). */
5287 /* XXX: For now we support only a single FPU context. */
5289 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5291 gen_load_fpr32(fp0, rt);
5292 tcg_gen_ext_i32_tl(t0, fp0);
5295 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5297 gen_load_fpr32h(fp0, rt);
5298 tcg_gen_ext_i32_tl(t0, fp0);
5303 /* XXX: For now we support only a single FPU context. */
5304 tcg_gen_helper_1_1i(do_cfc1, t0, t0, rt);
5306 /* COP2: Not implemented. */
5313 #if defined MIPS_DEBUG_DISAS
5314 if (loglevel & CPU_LOG_TB_IN_ASM) {
5315 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5319 gen_store_gpr(t0, rd);
5325 #if defined MIPS_DEBUG_DISAS
5326 if (loglevel & CPU_LOG_TB_IN_ASM) {
5327 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5331 generate_exception(ctx, EXCP_RI);
5334 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd, int rt,
5335 int u, int sel, int h)
5337 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5338 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5340 gen_load_gpr(t0, rt);
5341 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5342 ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) !=
5343 (env->active_tc.CP0_TCBind & (0xf << CP0TCBd_CurVPE))))
5345 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5346 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5353 tcg_gen_helper_0_1(do_mttc0_tcstatus, t0);
5356 tcg_gen_helper_0_1(do_mttc0_tcbind, t0);
5359 tcg_gen_helper_0_1(do_mttc0_tcrestart, t0);
5362 tcg_gen_helper_0_1(do_mttc0_tchalt, t0);
5365 tcg_gen_helper_0_1(do_mttc0_tccontext, t0);
5368 tcg_gen_helper_0_1(do_mttc0_tcschedule, t0);
5371 tcg_gen_helper_0_1(do_mttc0_tcschefback, t0);
5374 gen_mtc0(env, ctx, t0, rd, sel);
5381 tcg_gen_helper_0_1(do_mttc0_entryhi, t0);
5384 gen_mtc0(env, ctx, t0, rd, sel);
5390 tcg_gen_helper_0_1(do_mttc0_status, t0);
5393 gen_mtc0(env, ctx, t0, rd, sel);
5399 tcg_gen_helper_0_1(do_mttc0_debug, t0);
5402 gen_mtc0(env, ctx, t0, rd, sel);
5407 gen_mtc0(env, ctx, t0, rd, sel);
5409 } else switch (sel) {
5410 /* GPR registers. */
5412 tcg_gen_helper_0_1i(do_mttgpr, t0, rd);
5414 /* Auxiliary CPU registers */
5418 tcg_gen_helper_0_1i(do_mttlo, t0, 0);
5421 tcg_gen_helper_0_1i(do_mtthi, t0, 0);
5424 tcg_gen_helper_0_1i(do_mttacx, t0, 0);
5427 tcg_gen_helper_0_1i(do_mttlo, t0, 1);
5430 tcg_gen_helper_0_1i(do_mtthi, t0, 1);
5433 tcg_gen_helper_0_1i(do_mttacx, t0, 1);
5436 tcg_gen_helper_0_1i(do_mttlo, t0, 2);
5439 tcg_gen_helper_0_1i(do_mtthi, t0, 2);
5442 tcg_gen_helper_0_1i(do_mttacx, t0, 2);
5445 tcg_gen_helper_0_1i(do_mttlo, t0, 3);
5448 tcg_gen_helper_0_1i(do_mtthi, t0, 3);
5451 tcg_gen_helper_0_1i(do_mttacx, t0, 3);
5454 tcg_gen_helper_0_1(do_mttdsp, t0);
5460 /* Floating point (COP1). */
5462 /* XXX: For now we support only a single FPU context. */
5464 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5466 tcg_gen_trunc_tl_i32(fp0, t0);
5467 gen_store_fpr32(fp0, rd);
5470 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5472 tcg_gen_trunc_tl_i32(fp0, t0);
5473 gen_store_fpr32h(fp0, rd);
5478 /* XXX: For now we support only a single FPU context. */
5479 tcg_gen_helper_0_1i(do_ctc1, t0, rd);
5481 /* COP2: Not implemented. */
5488 #if defined MIPS_DEBUG_DISAS
5489 if (loglevel & CPU_LOG_TB_IN_ASM) {
5490 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5499 #if defined MIPS_DEBUG_DISAS
5500 if (loglevel & CPU_LOG_TB_IN_ASM) {
5501 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5505 generate_exception(ctx, EXCP_RI);
5508 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5510 const char *opn = "ldst";
5519 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5521 gen_mfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5522 gen_store_gpr(t0, rt);
5529 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5531 gen_load_gpr(t0, rt);
5532 save_cpu_state(ctx, 1);
5533 gen_mtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5538 #if defined(TARGET_MIPS64)
5540 check_insn(env, ctx, ISA_MIPS3);
5546 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5548 gen_dmfc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5549 gen_store_gpr(t0, rt);
5555 check_insn(env, ctx, ISA_MIPS3);
5557 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5559 gen_load_gpr(t0, rt);
5560 save_cpu_state(ctx, 1);
5561 gen_dmtc0(env, ctx, t0, rd, ctx->opcode & 0x7);
5568 check_insn(env, ctx, ASE_MT);
5573 gen_mftr(env, ctx, rt, rd, (ctx->opcode >> 5) & 1,
5574 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5578 check_insn(env, ctx, ASE_MT);
5579 gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
5580 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5585 if (!env->tlb->do_tlbwi)
5587 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5591 if (!env->tlb->do_tlbwr)
5593 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5597 if (!env->tlb->do_tlbp)
5599 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5603 if (!env->tlb->do_tlbr)
5605 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5609 check_insn(env, ctx, ISA_MIPS2);
5610 save_cpu_state(ctx, 1);
5611 tcg_gen_helper_0_0(do_eret);
5612 ctx->bstate = BS_EXCP;
5616 check_insn(env, ctx, ISA_MIPS32);
5617 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5619 generate_exception(ctx, EXCP_RI);
5621 save_cpu_state(ctx, 1);
5622 tcg_gen_helper_0_0(do_deret);
5623 ctx->bstate = BS_EXCP;
5628 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5629 /* If we get an exception, we want to restart at next instruction */
5631 save_cpu_state(ctx, 1);
5633 tcg_gen_helper_0_0(do_wait);
5634 ctx->bstate = BS_EXCP;
5639 generate_exception(ctx, EXCP_RI);
5642 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5644 #endif /* !CONFIG_USER_ONLY */
5646 /* CP1 Branches (before delay slot) */
5647 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5648 int32_t cc, int32_t offset)
5650 target_ulong btarget;
5651 const char *opn = "cp1 cond branch";
5652 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5653 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5656 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5658 btarget = ctx->pc + 4 + offset;
5663 int l1 = gen_new_label();
5664 int l2 = gen_new_label();
5665 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5667 get_fp_cond(r_tmp1);
5668 tcg_gen_ext_i32_tl(t0, r_tmp1);
5669 tcg_temp_free(r_tmp1);
5670 tcg_gen_not_tl(t0, t0);
5671 tcg_gen_movi_tl(t1, 0x1 << cc);
5672 tcg_gen_and_tl(t0, t0, t1);
5673 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5674 tcg_gen_movi_tl(t0, 0);
5677 tcg_gen_movi_tl(t0, 1);
5684 int l1 = gen_new_label();
5685 int l2 = gen_new_label();
5686 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5688 get_fp_cond(r_tmp1);
5689 tcg_gen_ext_i32_tl(t0, r_tmp1);
5690 tcg_temp_free(r_tmp1);
5691 tcg_gen_not_tl(t0, t0);
5692 tcg_gen_movi_tl(t1, 0x1 << cc);
5693 tcg_gen_and_tl(t0, t0, t1);
5694 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5695 tcg_gen_movi_tl(t0, 0);
5698 tcg_gen_movi_tl(t0, 1);
5705 int l1 = gen_new_label();
5706 int l2 = gen_new_label();
5707 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5709 get_fp_cond(r_tmp1);
5710 tcg_gen_ext_i32_tl(t0, r_tmp1);
5711 tcg_temp_free(r_tmp1);
5712 tcg_gen_movi_tl(t1, 0x1 << cc);
5713 tcg_gen_and_tl(t0, t0, t1);
5714 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5715 tcg_gen_movi_tl(t0, 0);
5718 tcg_gen_movi_tl(t0, 1);
5725 int l1 = gen_new_label();
5726 int l2 = gen_new_label();
5727 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5729 get_fp_cond(r_tmp1);
5730 tcg_gen_ext_i32_tl(t0, r_tmp1);
5731 tcg_temp_free(r_tmp1);
5732 tcg_gen_movi_tl(t1, 0x1 << cc);
5733 tcg_gen_and_tl(t0, t0, t1);
5734 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5735 tcg_gen_movi_tl(t0, 0);
5738 tcg_gen_movi_tl(t0, 1);
5743 ctx->hflags |= MIPS_HFLAG_BL;
5744 tcg_gen_trunc_tl_i32(bcond, t0);
5748 int l1 = gen_new_label();
5749 int l2 = gen_new_label();
5750 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5752 get_fp_cond(r_tmp1);
5753 tcg_gen_ext_i32_tl(t0, r_tmp1);
5754 tcg_temp_free(r_tmp1);
5755 tcg_gen_not_tl(t0, t0);
5756 tcg_gen_movi_tl(t1, 0x3 << cc);
5757 tcg_gen_and_tl(t0, t0, t1);
5758 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5759 tcg_gen_movi_tl(t0, 0);
5762 tcg_gen_movi_tl(t0, 1);
5769 int l1 = gen_new_label();
5770 int l2 = gen_new_label();
5771 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5773 get_fp_cond(r_tmp1);
5774 tcg_gen_ext_i32_tl(t0, r_tmp1);
5775 tcg_temp_free(r_tmp1);
5776 tcg_gen_movi_tl(t1, 0x3 << cc);
5777 tcg_gen_and_tl(t0, t0, t1);
5778 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5779 tcg_gen_movi_tl(t0, 0);
5782 tcg_gen_movi_tl(t0, 1);
5789 int l1 = gen_new_label();
5790 int l2 = gen_new_label();
5791 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5793 get_fp_cond(r_tmp1);
5794 tcg_gen_ext_i32_tl(t0, r_tmp1);
5795 tcg_temp_free(r_tmp1);
5796 tcg_gen_not_tl(t0, t0);
5797 tcg_gen_movi_tl(t1, 0xf << cc);
5798 tcg_gen_and_tl(t0, t0, t1);
5799 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5800 tcg_gen_movi_tl(t0, 0);
5803 tcg_gen_movi_tl(t0, 1);
5810 int l1 = gen_new_label();
5811 int l2 = gen_new_label();
5812 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5814 get_fp_cond(r_tmp1);
5815 tcg_gen_ext_i32_tl(t0, r_tmp1);
5816 tcg_temp_free(r_tmp1);
5817 tcg_gen_movi_tl(t1, 0xf << cc);
5818 tcg_gen_and_tl(t0, t0, t1);
5819 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
5820 tcg_gen_movi_tl(t0, 0);
5823 tcg_gen_movi_tl(t0, 1);
5828 ctx->hflags |= MIPS_HFLAG_BC;
5829 tcg_gen_trunc_tl_i32(bcond, t0);
5833 generate_exception (ctx, EXCP_RI);
5836 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5837 ctx->hflags, btarget);
5838 ctx->btarget = btarget;
5845 /* Coprocessor 1 (FPU) */
5847 #define FOP(func, fmt) (((fmt) << 21) | (func))
5849 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5851 const char *opn = "cp1 move";
5852 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5857 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5859 gen_load_fpr32(fp0, fs);
5860 tcg_gen_ext_i32_tl(t0, fp0);
5863 gen_store_gpr(t0, rt);
5867 gen_load_gpr(t0, rt);
5869 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5871 tcg_gen_trunc_tl_i32(fp0, t0);
5872 gen_store_fpr32(fp0, fs);
5878 tcg_gen_helper_1_i(do_cfc1, t0, fs);
5879 gen_store_gpr(t0, rt);
5883 gen_load_gpr(t0, rt);
5884 tcg_gen_helper_0_1i(do_ctc1, t0, fs);
5889 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5891 gen_load_fpr64(ctx, fp0, fs);
5892 tcg_gen_mov_tl(t0, fp0);
5895 gen_store_gpr(t0, rt);
5899 gen_load_gpr(t0, rt);
5901 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
5903 tcg_gen_mov_tl(fp0, t0);
5904 gen_store_fpr64(ctx, fp0, fs);
5911 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5913 gen_load_fpr32h(fp0, fs);
5914 tcg_gen_ext_i32_tl(t0, fp0);
5917 gen_store_gpr(t0, rt);
5921 gen_load_gpr(t0, rt);
5923 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
5925 tcg_gen_trunc_tl_i32(fp0, t0);
5926 gen_store_fpr32h(fp0, fs);
5933 generate_exception (ctx, EXCP_RI);
5936 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5942 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5944 int l1 = gen_new_label();
5947 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
5948 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
5949 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
5952 ccbit = 1 << (24 + cc);
5960 gen_load_gpr(t0, rd);
5961 gen_load_gpr(t1, rs);
5962 tcg_gen_andi_i32(r_tmp, fpu_fcr31, ccbit);
5963 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5964 tcg_temp_free(r_tmp);
5966 tcg_gen_mov_tl(t0, t1);
5970 gen_store_gpr(t0, rd);
5974 static inline void gen_movcf_s (int fs, int fd, int cc, int tf)
5978 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
5979 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
5980 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
5981 int l1 = gen_new_label();
5984 ccbit = 1 << (24 + cc);
5993 gen_load_fpr32(fp0, fs);
5994 gen_load_fpr32(fp1, fd);
5995 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
5996 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5997 tcg_gen_mov_i32(fp1, fp0);
6000 tcg_temp_free(r_tmp1);
6001 gen_store_fpr32(fp1, fd);
6005 static inline void gen_movcf_d (DisasContext *ctx, int fs, int fd, int cc, int tf)
6009 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6010 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6011 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I64);
6012 int l1 = gen_new_label();
6015 ccbit = 1 << (24 + cc);
6024 gen_load_fpr64(ctx, fp0, fs);
6025 gen_load_fpr64(ctx, fp1, fd);
6026 tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit);
6027 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
6028 tcg_gen_mov_i64(fp1, fp0);
6031 tcg_temp_free(r_tmp1);
6032 gen_store_fpr64(ctx, fp1, fd);
6036 static inline void gen_movcf_ps (int fs, int fd, int cc, int tf)
6039 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
6040 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
6041 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6042 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
6043 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
6044 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
6045 int l1 = gen_new_label();
6046 int l2 = gen_new_label();
6053 gen_load_fpr32(fp0, fs);
6054 gen_load_fpr32h(fph0, fs);
6055 gen_load_fpr32(fp1, fd);
6056 gen_load_fpr32h(fph1, fd);
6057 get_fp_cond(r_tmp1);
6058 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
6059 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
6060 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
6061 tcg_gen_mov_i32(fp1, fp0);
6064 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
6065 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
6066 tcg_gen_mov_i32(fph1, fph0);
6067 tcg_temp_free(fph0);
6069 tcg_temp_free(r_tmp1);
6070 tcg_temp_free(r_tmp2);
6071 gen_store_fpr32(fp1, fd);
6072 gen_store_fpr32h(fph1, fd);
6074 tcg_temp_free(fph1);
6078 static void gen_farith (DisasContext *ctx, uint32_t op1,
6079 int ft, int fs, int fd, int cc)
6081 const char *opn = "farith";
6082 const char *condnames[] = {
6100 const char *condnames_abs[] = {
6118 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
6119 uint32_t func = ctx->opcode & 0x3f;
6121 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
6124 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6125 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6127 gen_load_fpr32(fp0, fs);
6128 gen_load_fpr32(fp1, ft);
6129 tcg_gen_helper_1_2(do_float_add_s, fp0, fp0, fp1);
6131 gen_store_fpr32(fp0, fd);
6139 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6140 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6142 gen_load_fpr32(fp0, fs);
6143 gen_load_fpr32(fp1, ft);
6144 tcg_gen_helper_1_2(do_float_sub_s, fp0, fp0, fp1);
6146 gen_store_fpr32(fp0, fd);
6154 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6155 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6157 gen_load_fpr32(fp0, fs);
6158 gen_load_fpr32(fp1, ft);
6159 tcg_gen_helper_1_2(do_float_mul_s, fp0, fp0, fp1);
6161 gen_store_fpr32(fp0, fd);
6169 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6170 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6172 gen_load_fpr32(fp0, fs);
6173 gen_load_fpr32(fp1, ft);
6174 tcg_gen_helper_1_2(do_float_div_s, fp0, fp0, fp1);
6176 gen_store_fpr32(fp0, fd);
6184 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6186 gen_load_fpr32(fp0, fs);
6187 tcg_gen_helper_1_1(do_float_sqrt_s, fp0, fp0);
6188 gen_store_fpr32(fp0, fd);
6195 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6197 gen_load_fpr32(fp0, fs);
6198 tcg_gen_helper_1_1(do_float_abs_s, fp0, fp0);
6199 gen_store_fpr32(fp0, fd);
6206 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6208 gen_load_fpr32(fp0, fs);
6209 gen_store_fpr32(fp0, fd);
6216 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6218 gen_load_fpr32(fp0, fs);
6219 tcg_gen_helper_1_1(do_float_chs_s, fp0, fp0);
6220 gen_store_fpr32(fp0, fd);
6226 check_cp1_64bitmode(ctx);
6228 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6229 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6231 gen_load_fpr32(fp32, fs);
6232 tcg_gen_helper_1_1(do_float_roundl_s, fp64, fp32);
6233 tcg_temp_free(fp32);
6234 gen_store_fpr64(ctx, fp64, fd);
6235 tcg_temp_free(fp64);
6240 check_cp1_64bitmode(ctx);
6242 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6243 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6245 gen_load_fpr32(fp32, fs);
6246 tcg_gen_helper_1_1(do_float_truncl_s, fp64, fp32);
6247 tcg_temp_free(fp32);
6248 gen_store_fpr64(ctx, fp64, fd);
6249 tcg_temp_free(fp64);
6254 check_cp1_64bitmode(ctx);
6256 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6257 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6259 gen_load_fpr32(fp32, fs);
6260 tcg_gen_helper_1_1(do_float_ceill_s, fp64, fp32);
6261 tcg_temp_free(fp32);
6262 gen_store_fpr64(ctx, fp64, fd);
6263 tcg_temp_free(fp64);
6268 check_cp1_64bitmode(ctx);
6270 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6271 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6273 gen_load_fpr32(fp32, fs);
6274 tcg_gen_helper_1_1(do_float_floorl_s, fp64, fp32);
6275 tcg_temp_free(fp32);
6276 gen_store_fpr64(ctx, fp64, fd);
6277 tcg_temp_free(fp64);
6283 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6285 gen_load_fpr32(fp0, fs);
6286 tcg_gen_helper_1_1(do_float_roundw_s, fp0, fp0);
6287 gen_store_fpr32(fp0, fd);
6294 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6296 gen_load_fpr32(fp0, fs);
6297 tcg_gen_helper_1_1(do_float_truncw_s, fp0, fp0);
6298 gen_store_fpr32(fp0, fd);
6305 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6307 gen_load_fpr32(fp0, fs);
6308 tcg_gen_helper_1_1(do_float_ceilw_s, fp0, fp0);
6309 gen_store_fpr32(fp0, fd);
6316 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6318 gen_load_fpr32(fp0, fs);
6319 tcg_gen_helper_1_1(do_float_floorw_s, fp0, fp0);
6320 gen_store_fpr32(fp0, fd);
6326 gen_movcf_s(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6331 int l1 = gen_new_label();
6332 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6333 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6335 gen_load_gpr(t0, ft);
6336 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6338 gen_load_fpr32(fp0, fs);
6339 gen_store_fpr32(fp0, fd);
6347 int l1 = gen_new_label();
6348 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6349 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
6351 gen_load_gpr(t0, ft);
6352 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6354 gen_load_fpr32(fp0, fs);
6355 gen_store_fpr32(fp0, fd);
6364 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6366 gen_load_fpr32(fp0, fs);
6367 tcg_gen_helper_1_1(do_float_recip_s, fp0, fp0);
6368 gen_store_fpr32(fp0, fd);
6376 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6378 gen_load_fpr32(fp0, fs);
6379 tcg_gen_helper_1_1(do_float_rsqrt_s, fp0, fp0);
6380 gen_store_fpr32(fp0, fd);
6386 check_cp1_64bitmode(ctx);
6388 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6389 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6391 gen_load_fpr32(fp0, fs);
6392 gen_load_fpr32(fp1, fd);
6393 tcg_gen_helper_1_2(do_float_recip2_s, fp0, fp0, fp1);
6395 gen_store_fpr32(fp0, fd);
6401 check_cp1_64bitmode(ctx);
6403 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6405 gen_load_fpr32(fp0, fs);
6406 tcg_gen_helper_1_1(do_float_recip1_s, fp0, fp0);
6407 gen_store_fpr32(fp0, fd);
6413 check_cp1_64bitmode(ctx);
6415 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6417 gen_load_fpr32(fp0, fs);
6418 tcg_gen_helper_1_1(do_float_rsqrt1_s, fp0, fp0);
6419 gen_store_fpr32(fp0, fd);
6425 check_cp1_64bitmode(ctx);
6427 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6428 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6430 gen_load_fpr32(fp0, fs);
6431 gen_load_fpr32(fp1, ft);
6432 tcg_gen_helper_1_2(do_float_rsqrt2_s, fp0, fp0, fp1);
6434 gen_store_fpr32(fp0, fd);
6440 check_cp1_registers(ctx, fd);
6442 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6443 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6445 gen_load_fpr32(fp32, fs);
6446 tcg_gen_helper_1_1(do_float_cvtd_s, fp64, fp32);
6447 tcg_temp_free(fp32);
6448 gen_store_fpr64(ctx, fp64, fd);
6449 tcg_temp_free(fp64);
6455 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6457 gen_load_fpr32(fp0, fs);
6458 tcg_gen_helper_1_1(do_float_cvtw_s, fp0, fp0);
6459 gen_store_fpr32(fp0, fd);
6465 check_cp1_64bitmode(ctx);
6467 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6468 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6470 gen_load_fpr32(fp32, fs);
6471 tcg_gen_helper_1_1(do_float_cvtl_s, fp64, fp32);
6472 tcg_temp_free(fp32);
6473 gen_store_fpr64(ctx, fp64, fd);
6474 tcg_temp_free(fp64);
6479 check_cp1_64bitmode(ctx);
6481 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6482 TCGv fp32_0 = tcg_temp_new(TCG_TYPE_I32);
6483 TCGv fp32_1 = tcg_temp_new(TCG_TYPE_I32);
6485 gen_load_fpr32(fp32_0, fs);
6486 gen_load_fpr32(fp32_1, ft);
6487 tcg_gen_concat_i32_i64(fp64, fp32_0, fp32_1);
6488 tcg_temp_free(fp32_1);
6489 tcg_temp_free(fp32_0);
6490 gen_store_fpr64(ctx, fp64, fd);
6491 tcg_temp_free(fp64);
6512 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6513 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
6515 gen_load_fpr32(fp0, fs);
6516 gen_load_fpr32(fp1, ft);
6517 if (ctx->opcode & (1 << 6)) {
6519 gen_cmpabs_s(func-48, fp0, fp1, cc);
6520 opn = condnames_abs[func-48];
6522 gen_cmp_s(func-48, fp0, fp1, cc);
6523 opn = condnames[func-48];
6530 check_cp1_registers(ctx, fs | ft | fd);
6532 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6533 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6535 gen_load_fpr64(ctx, fp0, fs);
6536 gen_load_fpr64(ctx, fp1, ft);
6537 tcg_gen_helper_1_2(do_float_add_d, fp0, fp0, fp1);
6539 gen_store_fpr64(ctx, fp0, fd);
6546 check_cp1_registers(ctx, fs | ft | fd);
6548 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6549 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6551 gen_load_fpr64(ctx, fp0, fs);
6552 gen_load_fpr64(ctx, fp1, ft);
6553 tcg_gen_helper_1_2(do_float_sub_d, fp0, fp0, fp1);
6555 gen_store_fpr64(ctx, fp0, fd);
6562 check_cp1_registers(ctx, fs | ft | fd);
6564 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6565 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6567 gen_load_fpr64(ctx, fp0, fs);
6568 gen_load_fpr64(ctx, fp1, ft);
6569 tcg_gen_helper_1_2(do_float_mul_d, fp0, fp0, fp1);
6571 gen_store_fpr64(ctx, fp0, fd);
6578 check_cp1_registers(ctx, fs | ft | fd);
6580 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6581 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6583 gen_load_fpr64(ctx, fp0, fs);
6584 gen_load_fpr64(ctx, fp1, ft);
6585 tcg_gen_helper_1_2(do_float_div_d, fp0, fp0, fp1);
6587 gen_store_fpr64(ctx, fp0, fd);
6594 check_cp1_registers(ctx, fs | fd);
6596 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6598 gen_load_fpr64(ctx, fp0, fs);
6599 tcg_gen_helper_1_1(do_float_sqrt_d, fp0, fp0);
6600 gen_store_fpr64(ctx, fp0, fd);
6606 check_cp1_registers(ctx, fs | fd);
6608 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6610 gen_load_fpr64(ctx, fp0, fs);
6611 tcg_gen_helper_1_1(do_float_abs_d, fp0, fp0);
6612 gen_store_fpr64(ctx, fp0, fd);
6618 check_cp1_registers(ctx, fs | fd);
6620 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6622 gen_load_fpr64(ctx, fp0, fs);
6623 gen_store_fpr64(ctx, fp0, fd);
6629 check_cp1_registers(ctx, fs | fd);
6631 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6633 gen_load_fpr64(ctx, fp0, fs);
6634 tcg_gen_helper_1_1(do_float_chs_d, fp0, fp0);
6635 gen_store_fpr64(ctx, fp0, fd);
6641 check_cp1_64bitmode(ctx);
6643 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6645 gen_load_fpr64(ctx, fp0, fs);
6646 tcg_gen_helper_1_1(do_float_roundl_d, fp0, fp0);
6647 gen_store_fpr64(ctx, fp0, fd);
6653 check_cp1_64bitmode(ctx);
6655 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6657 gen_load_fpr64(ctx, fp0, fs);
6658 tcg_gen_helper_1_1(do_float_truncl_d, fp0, fp0);
6659 gen_store_fpr64(ctx, fp0, fd);
6665 check_cp1_64bitmode(ctx);
6667 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6669 gen_load_fpr64(ctx, fp0, fs);
6670 tcg_gen_helper_1_1(do_float_ceill_d, fp0, fp0);
6671 gen_store_fpr64(ctx, fp0, fd);
6677 check_cp1_64bitmode(ctx);
6679 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6681 gen_load_fpr64(ctx, fp0, fs);
6682 tcg_gen_helper_1_1(do_float_floorl_d, fp0, fp0);
6683 gen_store_fpr64(ctx, fp0, fd);
6689 check_cp1_registers(ctx, fs);
6691 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6692 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6694 gen_load_fpr64(ctx, fp64, fs);
6695 tcg_gen_helper_1_1(do_float_roundw_d, fp32, fp64);
6696 tcg_temp_free(fp64);
6697 gen_store_fpr32(fp32, fd);
6698 tcg_temp_free(fp32);
6703 check_cp1_registers(ctx, fs);
6705 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6706 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6708 gen_load_fpr64(ctx, fp64, fs);
6709 tcg_gen_helper_1_1(do_float_truncw_d, fp32, fp64);
6710 tcg_temp_free(fp64);
6711 gen_store_fpr32(fp32, fd);
6712 tcg_temp_free(fp32);
6717 check_cp1_registers(ctx, fs);
6719 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6720 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6722 gen_load_fpr64(ctx, fp64, fs);
6723 tcg_gen_helper_1_1(do_float_ceilw_d, fp32, fp64);
6724 tcg_temp_free(fp64);
6725 gen_store_fpr32(fp32, fd);
6726 tcg_temp_free(fp32);
6731 check_cp1_registers(ctx, fs);
6733 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6734 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6736 gen_load_fpr64(ctx, fp64, fs);
6737 tcg_gen_helper_1_1(do_float_floorw_d, fp32, fp64);
6738 tcg_temp_free(fp64);
6739 gen_store_fpr32(fp32, fd);
6740 tcg_temp_free(fp32);
6745 gen_movcf_d(ctx, fs, fd, (ft >> 2) & 0x7, ft & 0x1);
6750 int l1 = gen_new_label();
6751 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6752 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6754 gen_load_gpr(t0, ft);
6755 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
6757 gen_load_fpr64(ctx, fp0, fs);
6758 gen_store_fpr64(ctx, fp0, fd);
6766 int l1 = gen_new_label();
6767 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
6768 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I64);
6770 gen_load_gpr(t0, ft);
6771 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
6773 gen_load_fpr64(ctx, fp0, fs);
6774 gen_store_fpr64(ctx, fp0, fd);
6781 check_cp1_64bitmode(ctx);
6783 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6785 gen_load_fpr64(ctx, fp0, fs);
6786 tcg_gen_helper_1_1(do_float_recip_d, fp0, fp0);
6787 gen_store_fpr64(ctx, fp0, fd);
6793 check_cp1_64bitmode(ctx);
6795 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6797 gen_load_fpr64(ctx, fp0, fs);
6798 tcg_gen_helper_1_1(do_float_rsqrt_d, fp0, fp0);
6799 gen_store_fpr64(ctx, fp0, fd);
6805 check_cp1_64bitmode(ctx);
6807 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6808 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6810 gen_load_fpr64(ctx, fp0, fs);
6811 gen_load_fpr64(ctx, fp1, ft);
6812 tcg_gen_helper_1_2(do_float_recip2_d, fp0, fp0, fp1);
6814 gen_store_fpr64(ctx, fp0, fd);
6820 check_cp1_64bitmode(ctx);
6822 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6824 gen_load_fpr64(ctx, fp0, fs);
6825 tcg_gen_helper_1_1(do_float_recip1_d, fp0, fp0);
6826 gen_store_fpr64(ctx, fp0, fd);
6832 check_cp1_64bitmode(ctx);
6834 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6836 gen_load_fpr64(ctx, fp0, fs);
6837 tcg_gen_helper_1_1(do_float_rsqrt1_d, fp0, fp0);
6838 gen_store_fpr64(ctx, fp0, fd);
6844 check_cp1_64bitmode(ctx);
6846 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6847 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6849 gen_load_fpr64(ctx, fp0, fs);
6850 gen_load_fpr64(ctx, fp1, ft);
6851 tcg_gen_helper_1_2(do_float_rsqrt2_d, fp0, fp0, fp1);
6853 gen_store_fpr64(ctx, fp0, fd);
6875 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6876 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
6878 gen_load_fpr64(ctx, fp0, fs);
6879 gen_load_fpr64(ctx, fp1, ft);
6880 if (ctx->opcode & (1 << 6)) {
6882 check_cp1_registers(ctx, fs | ft);
6883 gen_cmpabs_d(func-48, fp0, fp1, cc);
6884 opn = condnames_abs[func-48];
6886 check_cp1_registers(ctx, fs | ft);
6887 gen_cmp_d(func-48, fp0, fp1, cc);
6888 opn = condnames[func-48];
6895 check_cp1_registers(ctx, fs);
6897 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6898 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6900 gen_load_fpr64(ctx, fp64, fs);
6901 tcg_gen_helper_1_1(do_float_cvts_d, fp32, fp64);
6902 tcg_temp_free(fp64);
6903 gen_store_fpr32(fp32, fd);
6904 tcg_temp_free(fp32);
6909 check_cp1_registers(ctx, fs);
6911 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6912 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6914 gen_load_fpr64(ctx, fp64, fs);
6915 tcg_gen_helper_1_1(do_float_cvtw_d, fp32, fp64);
6916 tcg_temp_free(fp64);
6917 gen_store_fpr32(fp32, fd);
6918 tcg_temp_free(fp32);
6923 check_cp1_64bitmode(ctx);
6925 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6927 gen_load_fpr64(ctx, fp0, fs);
6928 tcg_gen_helper_1_1(do_float_cvtl_d, fp0, fp0);
6929 gen_store_fpr64(ctx, fp0, fd);
6936 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
6938 gen_load_fpr32(fp0, fs);
6939 tcg_gen_helper_1_1(do_float_cvts_w, fp0, fp0);
6940 gen_store_fpr32(fp0, fd);
6946 check_cp1_registers(ctx, fd);
6948 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6949 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6951 gen_load_fpr32(fp32, fs);
6952 tcg_gen_helper_1_1(do_float_cvtd_w, fp64, fp32);
6953 tcg_temp_free(fp32);
6954 gen_store_fpr64(ctx, fp64, fd);
6955 tcg_temp_free(fp64);
6960 check_cp1_64bitmode(ctx);
6962 TCGv fp32 = tcg_temp_new(TCG_TYPE_I32);
6963 TCGv fp64 = tcg_temp_new(TCG_TYPE_I64);
6965 gen_load_fpr64(ctx, fp64, fs);
6966 tcg_gen_helper_1_1(do_float_cvts_l, fp32, fp64);
6967 tcg_temp_free(fp64);
6968 gen_store_fpr32(fp32, fd);
6969 tcg_temp_free(fp32);
6974 check_cp1_64bitmode(ctx);
6976 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6978 gen_load_fpr64(ctx, fp0, fs);
6979 tcg_gen_helper_1_1(do_float_cvtd_l, fp0, fp0);
6980 gen_store_fpr64(ctx, fp0, fd);
6986 check_cp1_64bitmode(ctx);
6988 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
6990 gen_load_fpr64(ctx, fp0, fs);
6991 tcg_gen_helper_1_1(do_float_cvtps_pw, fp0, fp0);
6992 gen_store_fpr64(ctx, fp0, fd);
6998 check_cp1_64bitmode(ctx);
7000 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7001 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7003 gen_load_fpr64(ctx, fp0, fs);
7004 gen_load_fpr64(ctx, fp1, ft);
7005 tcg_gen_helper_1_2(do_float_add_ps, fp0, fp0, fp1);
7007 gen_store_fpr64(ctx, fp0, fd);
7013 check_cp1_64bitmode(ctx);
7015 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7016 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7018 gen_load_fpr64(ctx, fp0, fs);
7019 gen_load_fpr64(ctx, fp1, ft);
7020 tcg_gen_helper_1_2(do_float_sub_ps, fp0, fp0, fp1);
7022 gen_store_fpr64(ctx, fp0, fd);
7028 check_cp1_64bitmode(ctx);
7030 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7031 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7033 gen_load_fpr64(ctx, fp0, fs);
7034 gen_load_fpr64(ctx, fp1, ft);
7035 tcg_gen_helper_1_2(do_float_mul_ps, fp0, fp0, fp1);
7037 gen_store_fpr64(ctx, fp0, fd);
7043 check_cp1_64bitmode(ctx);
7045 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7047 gen_load_fpr64(ctx, fp0, fs);
7048 tcg_gen_helper_1_1(do_float_abs_ps, fp0, fp0);
7049 gen_store_fpr64(ctx, fp0, fd);
7055 check_cp1_64bitmode(ctx);
7057 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7059 gen_load_fpr64(ctx, fp0, fs);
7060 gen_store_fpr64(ctx, fp0, fd);
7066 check_cp1_64bitmode(ctx);
7068 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7070 gen_load_fpr64(ctx, fp0, fs);
7071 tcg_gen_helper_1_1(do_float_chs_ps, fp0, fp0);
7072 gen_store_fpr64(ctx, fp0, fd);
7078 check_cp1_64bitmode(ctx);
7079 gen_movcf_ps(fs, fd, (ft >> 2) & 0x7, ft & 0x1);
7083 check_cp1_64bitmode(ctx);
7085 int l1 = gen_new_label();
7086 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7087 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7088 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7090 gen_load_gpr(t0, ft);
7091 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7093 gen_load_fpr32(fp0, fs);
7094 gen_load_fpr32h(fph0, fs);
7095 gen_store_fpr32(fp0, fd);
7096 gen_store_fpr32h(fph0, fd);
7098 tcg_temp_free(fph0);
7104 check_cp1_64bitmode(ctx);
7106 int l1 = gen_new_label();
7107 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7108 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7109 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7111 gen_load_gpr(t0, ft);
7112 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
7114 gen_load_fpr32(fp0, fs);
7115 gen_load_fpr32h(fph0, fs);
7116 gen_store_fpr32(fp0, fd);
7117 gen_store_fpr32h(fph0, fd);
7119 tcg_temp_free(fph0);
7125 check_cp1_64bitmode(ctx);
7127 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7128 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7130 gen_load_fpr64(ctx, fp0, ft);
7131 gen_load_fpr64(ctx, fp1, fs);
7132 tcg_gen_helper_1_2(do_float_addr_ps, fp0, fp0, fp1);
7134 gen_store_fpr64(ctx, fp0, fd);
7140 check_cp1_64bitmode(ctx);
7142 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7143 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7145 gen_load_fpr64(ctx, fp0, ft);
7146 gen_load_fpr64(ctx, fp1, fs);
7147 tcg_gen_helper_1_2(do_float_mulr_ps, fp0, fp0, fp1);
7149 gen_store_fpr64(ctx, fp0, fd);
7155 check_cp1_64bitmode(ctx);
7157 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7158 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7160 gen_load_fpr64(ctx, fp0, fs);
7161 gen_load_fpr64(ctx, fp1, fd);
7162 tcg_gen_helper_1_2(do_float_recip2_ps, fp0, fp0, fp1);
7164 gen_store_fpr64(ctx, fp0, fd);
7170 check_cp1_64bitmode(ctx);
7172 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7174 gen_load_fpr64(ctx, fp0, fs);
7175 tcg_gen_helper_1_1(do_float_recip1_ps, fp0, fp0);
7176 gen_store_fpr64(ctx, fp0, fd);
7182 check_cp1_64bitmode(ctx);
7184 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7186 gen_load_fpr64(ctx, fp0, fs);
7187 tcg_gen_helper_1_1(do_float_rsqrt1_ps, fp0, fp0);
7188 gen_store_fpr64(ctx, fp0, fd);
7194 check_cp1_64bitmode(ctx);
7196 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7197 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7199 gen_load_fpr64(ctx, fp0, fs);
7200 gen_load_fpr64(ctx, fp1, ft);
7201 tcg_gen_helper_1_2(do_float_rsqrt2_ps, fp0, fp0, fp1);
7203 gen_store_fpr64(ctx, fp0, fd);
7209 check_cp1_64bitmode(ctx);
7211 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7213 gen_load_fpr32h(fp0, fs);
7214 tcg_gen_helper_1_1(do_float_cvts_pu, fp0, fp0);
7215 gen_store_fpr32(fp0, fd);
7221 check_cp1_64bitmode(ctx);
7223 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7225 gen_load_fpr64(ctx, fp0, fs);
7226 tcg_gen_helper_1_1(do_float_cvtpw_ps, fp0, fp0);
7227 gen_store_fpr64(ctx, fp0, fd);
7233 check_cp1_64bitmode(ctx);
7235 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7237 gen_load_fpr32(fp0, fs);
7238 tcg_gen_helper_1_1(do_float_cvts_pl, fp0, fp0);
7239 gen_store_fpr32(fp0, fd);
7245 check_cp1_64bitmode(ctx);
7247 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7248 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7250 gen_load_fpr32(fp0, fs);
7251 gen_load_fpr32(fp1, ft);
7252 gen_store_fpr32h(fp0, fd);
7253 gen_store_fpr32(fp1, fd);
7260 check_cp1_64bitmode(ctx);
7262 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7263 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7265 gen_load_fpr32(fp0, fs);
7266 gen_load_fpr32h(fp1, ft);
7267 gen_store_fpr32(fp1, fd);
7268 gen_store_fpr32h(fp0, fd);
7275 check_cp1_64bitmode(ctx);
7277 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7278 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7280 gen_load_fpr32h(fp0, fs);
7281 gen_load_fpr32(fp1, ft);
7282 gen_store_fpr32(fp1, fd);
7283 gen_store_fpr32h(fp0, fd);
7290 check_cp1_64bitmode(ctx);
7292 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7293 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7295 gen_load_fpr32h(fp0, fs);
7296 gen_load_fpr32h(fp1, ft);
7297 gen_store_fpr32(fp1, fd);
7298 gen_store_fpr32h(fp0, fd);
7320 check_cp1_64bitmode(ctx);
7322 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7323 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7325 gen_load_fpr64(ctx, fp0, fs);
7326 gen_load_fpr64(ctx, fp1, ft);
7327 if (ctx->opcode & (1 << 6)) {
7328 gen_cmpabs_ps(func-48, fp0, fp1, cc);
7329 opn = condnames_abs[func-48];
7331 gen_cmp_ps(func-48, fp0, fp1, cc);
7332 opn = condnames[func-48];
7340 generate_exception (ctx, EXCP_RI);
7345 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
7348 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
7351 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
7356 /* Coprocessor 3 (FPU) */
7357 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
7358 int fd, int fs, int base, int index)
7360 const char *opn = "extended float load/store";
7362 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7363 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7366 gen_load_gpr(t0, index);
7367 } else if (index == 0) {
7368 gen_load_gpr(t0, base);
7370 gen_load_gpr(t0, base);
7371 gen_load_gpr(t1, index);
7372 gen_op_addr_add(t0, t1);
7374 /* Don't do NOP if destination is zero: we must perform the actual
7380 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7382 tcg_gen_qemu_ld32s(fp0, t0, ctx->mem_idx);
7383 gen_store_fpr32(fp0, fd);
7390 check_cp1_registers(ctx, fd);
7392 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7394 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7395 gen_store_fpr64(ctx, fp0, fd);
7401 check_cp1_64bitmode(ctx);
7402 tcg_gen_andi_tl(t0, t0, ~0x7);
7404 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7406 tcg_gen_qemu_ld64(fp0, t0, ctx->mem_idx);
7407 gen_store_fpr64(ctx, fp0, fd);
7415 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7417 gen_load_fpr32(fp0, fs);
7418 tcg_gen_qemu_st32(fp0, t0, ctx->mem_idx);
7426 check_cp1_registers(ctx, fs);
7428 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7430 gen_load_fpr64(ctx, fp0, fs);
7431 tcg_gen_qemu_st64(fp0, t0, ctx->mem_idx);
7438 check_cp1_64bitmode(ctx);
7439 tcg_gen_andi_tl(t0, t0, ~0x7);
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);
7452 generate_exception(ctx, EXCP_RI);
7459 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
7460 regnames[index], regnames[base]);
7463 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
7464 int fd, int fr, int fs, int ft)
7466 const char *opn = "flt3_arith";
7470 check_cp1_64bitmode(ctx);
7472 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7473 TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32);
7474 TCGv fph0 = tcg_temp_local_new(TCG_TYPE_I32);
7475 TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32);
7476 TCGv fph1 = tcg_temp_local_new(TCG_TYPE_I32);
7477 int l1 = gen_new_label();
7478 int l2 = gen_new_label();
7480 gen_load_gpr(t0, fr);
7481 tcg_gen_andi_tl(t0, t0, 0x7);
7482 gen_load_fpr32(fp0, fs);
7483 gen_load_fpr32h(fph0, fs);
7484 gen_load_fpr32(fp1, ft);
7485 gen_load_fpr32h(fph1, ft);
7487 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0, l1);
7488 gen_store_fpr32(fp0, fd);
7489 gen_store_fpr32h(fph0, fd);
7492 tcg_gen_brcondi_tl(TCG_COND_NE, t0, 4, l2);
7494 #ifdef TARGET_WORDS_BIGENDIAN
7495 gen_store_fpr32(fph1, fd);
7496 gen_store_fpr32h(fp0, fd);
7498 gen_store_fpr32(fph0, fd);
7499 gen_store_fpr32h(fp1, fd);
7503 tcg_temp_free(fph0);
7505 tcg_temp_free(fph1);
7512 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7513 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7514 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7516 gen_load_fpr32(fp0, fs);
7517 gen_load_fpr32(fp1, ft);
7518 gen_load_fpr32(fp2, fr);
7519 tcg_gen_helper_1_3(do_float_muladd_s, fp2, fp0, fp1, fp2);
7522 gen_store_fpr32(fp2, fd);
7529 check_cp1_registers(ctx, fd | fs | ft | fr);
7531 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7532 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7533 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7535 gen_load_fpr64(ctx, fp0, fs);
7536 gen_load_fpr64(ctx, fp1, ft);
7537 gen_load_fpr64(ctx, fp2, fr);
7538 tcg_gen_helper_1_3(do_float_muladd_d, fp2, fp0, fp1, fp2);
7541 gen_store_fpr64(ctx, fp2, fd);
7547 check_cp1_64bitmode(ctx);
7549 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7550 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7551 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7553 gen_load_fpr64(ctx, fp0, fs);
7554 gen_load_fpr64(ctx, fp1, ft);
7555 gen_load_fpr64(ctx, fp2, fr);
7556 tcg_gen_helper_1_3(do_float_muladd_ps, fp2, fp0, fp1, fp2);
7559 gen_store_fpr64(ctx, fp2, fd);
7567 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7568 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7569 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7571 gen_load_fpr32(fp0, fs);
7572 gen_load_fpr32(fp1, ft);
7573 gen_load_fpr32(fp2, fr);
7574 tcg_gen_helper_1_3(do_float_mulsub_s, fp2, fp0, fp1, fp2);
7577 gen_store_fpr32(fp2, fd);
7584 check_cp1_registers(ctx, fd | fs | ft | fr);
7586 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7587 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7588 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7590 gen_load_fpr64(ctx, fp0, fs);
7591 gen_load_fpr64(ctx, fp1, ft);
7592 gen_load_fpr64(ctx, fp2, fr);
7593 tcg_gen_helper_1_3(do_float_mulsub_d, fp2, fp0, fp1, fp2);
7596 gen_store_fpr64(ctx, fp2, fd);
7602 check_cp1_64bitmode(ctx);
7604 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7605 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7606 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7608 gen_load_fpr64(ctx, fp0, fs);
7609 gen_load_fpr64(ctx, fp1, ft);
7610 gen_load_fpr64(ctx, fp2, fr);
7611 tcg_gen_helper_1_3(do_float_mulsub_ps, fp2, fp0, fp1, fp2);
7614 gen_store_fpr64(ctx, fp2, fd);
7622 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7623 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7624 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7626 gen_load_fpr32(fp0, fs);
7627 gen_load_fpr32(fp1, ft);
7628 gen_load_fpr32(fp2, fr);
7629 tcg_gen_helper_1_3(do_float_nmuladd_s, fp2, fp0, fp1, fp2);
7632 gen_store_fpr32(fp2, fd);
7639 check_cp1_registers(ctx, fd | fs | ft | fr);
7641 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7642 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7643 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7645 gen_load_fpr64(ctx, fp0, fs);
7646 gen_load_fpr64(ctx, fp1, ft);
7647 gen_load_fpr64(ctx, fp2, fr);
7648 tcg_gen_helper_1_3(do_float_nmuladd_d, fp2, fp0, fp1, fp2);
7651 gen_store_fpr64(ctx, fp2, fd);
7657 check_cp1_64bitmode(ctx);
7659 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7660 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7661 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7663 gen_load_fpr64(ctx, fp0, fs);
7664 gen_load_fpr64(ctx, fp1, ft);
7665 gen_load_fpr64(ctx, fp2, fr);
7666 tcg_gen_helper_1_3(do_float_nmuladd_ps, fp2, fp0, fp1, fp2);
7669 gen_store_fpr64(ctx, fp2, fd);
7677 TCGv fp0 = tcg_temp_new(TCG_TYPE_I32);
7678 TCGv fp1 = tcg_temp_new(TCG_TYPE_I32);
7679 TCGv fp2 = tcg_temp_new(TCG_TYPE_I32);
7681 gen_load_fpr32(fp0, fs);
7682 gen_load_fpr32(fp1, ft);
7683 gen_load_fpr32(fp2, fr);
7684 tcg_gen_helper_1_3(do_float_nmulsub_s, fp2, fp0, fp1, fp2);
7687 gen_store_fpr32(fp2, fd);
7694 check_cp1_registers(ctx, fd | fs | ft | fr);
7696 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7697 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7698 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7700 gen_load_fpr64(ctx, fp0, fs);
7701 gen_load_fpr64(ctx, fp1, ft);
7702 gen_load_fpr64(ctx, fp2, fr);
7703 tcg_gen_helper_1_3(do_float_nmulsub_d, fp2, fp0, fp1, fp2);
7706 gen_store_fpr64(ctx, fp2, fd);
7712 check_cp1_64bitmode(ctx);
7714 TCGv fp0 = tcg_temp_new(TCG_TYPE_I64);
7715 TCGv fp1 = tcg_temp_new(TCG_TYPE_I64);
7716 TCGv fp2 = tcg_temp_new(TCG_TYPE_I64);
7718 gen_load_fpr64(ctx, fp0, fs);
7719 gen_load_fpr64(ctx, fp1, ft);
7720 gen_load_fpr64(ctx, fp2, fr);
7721 tcg_gen_helper_1_3(do_float_nmulsub_ps, fp2, fp0, fp1, fp2);
7724 gen_store_fpr64(ctx, fp2, fd);
7731 generate_exception (ctx, EXCP_RI);
7734 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
7735 fregnames[fs], fregnames[ft]);
7738 /* ISA extensions (ASEs) */
7739 /* MIPS16 extension to MIPS32 */
7740 /* SmartMIPS extension to MIPS32 */
7742 #if defined(TARGET_MIPS64)
7744 /* MDMX extension to MIPS64 */
7748 static void decode_opc (CPUState *env, DisasContext *ctx)
7752 uint32_t op, op1, op2;
7755 /* make sure instructions are on a word boundary */
7756 if (ctx->pc & 0x3) {
7757 env->CP0_BadVAddr = ctx->pc;
7758 generate_exception(ctx, EXCP_AdEL);
7762 /* Handle blikely not taken case */
7763 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7764 int l1 = gen_new_label();
7766 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7767 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
7769 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
7771 tcg_gen_movi_i32(r_tmp, ctx->hflags & ~MIPS_HFLAG_BMASK);
7772 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
7773 tcg_temp_free(r_tmp);
7775 gen_goto_tb(ctx, 1, ctx->pc + 4);
7778 op = MASK_OP_MAJOR(ctx->opcode);
7779 rs = (ctx->opcode >> 21) & 0x1f;
7780 rt = (ctx->opcode >> 16) & 0x1f;
7781 rd = (ctx->opcode >> 11) & 0x1f;
7782 sa = (ctx->opcode >> 6) & 0x1f;
7783 imm = (int16_t)ctx->opcode;
7786 op1 = MASK_SPECIAL(ctx->opcode);
7788 case OPC_SLL: /* Arithmetic with immediate */
7789 case OPC_SRL ... OPC_SRA:
7790 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7792 case OPC_MOVZ ... OPC_MOVN:
7793 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7794 case OPC_SLLV: /* Arithmetic */
7795 case OPC_SRLV ... OPC_SRAV:
7796 case OPC_ADD ... OPC_NOR:
7797 case OPC_SLT ... OPC_SLTU:
7798 gen_arith(env, ctx, op1, rd, rs, rt);
7800 case OPC_MULT ... OPC_DIVU:
7802 check_insn(env, ctx, INSN_VR54XX);
7803 op1 = MASK_MUL_VR54XX(ctx->opcode);
7804 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7806 gen_muldiv(ctx, op1, rs, rt);
7808 case OPC_JR ... OPC_JALR:
7809 gen_compute_branch(ctx, op1, rs, rd, sa);
7811 case OPC_TGE ... OPC_TEQ: /* Traps */
7813 gen_trap(ctx, op1, rs, rt, -1);
7815 case OPC_MFHI: /* Move from HI/LO */
7817 gen_HILO(ctx, op1, rd);
7820 case OPC_MTLO: /* Move to HI/LO */
7821 gen_HILO(ctx, op1, rs);
7823 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7824 #ifdef MIPS_STRICT_STANDARD
7825 MIPS_INVAL("PMON / selsl");
7826 generate_exception(ctx, EXCP_RI);
7828 tcg_gen_helper_0_i(do_pmon, sa);
7832 generate_exception(ctx, EXCP_SYSCALL);
7835 generate_exception(ctx, EXCP_BREAK);
7838 #ifdef MIPS_STRICT_STANDARD
7840 generate_exception(ctx, EXCP_RI);
7842 /* Implemented as RI exception for now. */
7843 MIPS_INVAL("spim (unofficial)");
7844 generate_exception(ctx, EXCP_RI);
7852 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7853 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7854 save_cpu_state(ctx, 1);
7855 check_cp1_enabled(ctx);
7856 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7857 (ctx->opcode >> 16) & 1);
7859 generate_exception_err(ctx, EXCP_CpU, 1);
7863 #if defined(TARGET_MIPS64)
7864 /* MIPS64 specific opcodes */
7866 case OPC_DSRL ... OPC_DSRA:
7868 case OPC_DSRL32 ... OPC_DSRA32:
7869 check_insn(env, ctx, ISA_MIPS3);
7871 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7874 case OPC_DSRLV ... OPC_DSRAV:
7875 case OPC_DADD ... OPC_DSUBU:
7876 check_insn(env, ctx, ISA_MIPS3);
7878 gen_arith(env, ctx, op1, rd, rs, rt);
7880 case OPC_DMULT ... OPC_DDIVU:
7881 check_insn(env, ctx, ISA_MIPS3);
7883 gen_muldiv(ctx, op1, rs, rt);
7886 default: /* Invalid */
7887 MIPS_INVAL("special");
7888 generate_exception(ctx, EXCP_RI);
7893 op1 = MASK_SPECIAL2(ctx->opcode);
7895 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7896 case OPC_MSUB ... OPC_MSUBU:
7897 check_insn(env, ctx, ISA_MIPS32);
7898 gen_muldiv(ctx, op1, rs, rt);
7901 gen_arith(env, ctx, op1, rd, rs, rt);
7903 case OPC_CLZ ... OPC_CLO:
7904 check_insn(env, ctx, ISA_MIPS32);
7905 gen_cl(ctx, op1, rd, rs);
7908 /* XXX: not clear which exception should be raised
7909 * when in debug mode...
7911 check_insn(env, ctx, ISA_MIPS32);
7912 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7913 generate_exception(ctx, EXCP_DBp);
7915 generate_exception(ctx, EXCP_DBp);
7919 #if defined(TARGET_MIPS64)
7920 case OPC_DCLZ ... OPC_DCLO:
7921 check_insn(env, ctx, ISA_MIPS64);
7923 gen_cl(ctx, op1, rd, rs);
7926 default: /* Invalid */
7927 MIPS_INVAL("special2");
7928 generate_exception(ctx, EXCP_RI);
7933 op1 = MASK_SPECIAL3(ctx->opcode);
7937 check_insn(env, ctx, ISA_MIPS32R2);
7938 gen_bitops(ctx, op1, rt, rs, sa, rd);
7941 check_insn(env, ctx, ISA_MIPS32R2);
7942 op2 = MASK_BSHFL(ctx->opcode);
7944 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7945 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
7949 gen_load_gpr(t1, rt);
7950 tcg_gen_helper_1_1(do_wsbh, t0, t1);
7951 gen_store_gpr(t0, rd);
7954 gen_load_gpr(t1, rt);
7955 tcg_gen_ext8s_tl(t0, t1);
7956 gen_store_gpr(t0, rd);
7959 gen_load_gpr(t1, rt);
7960 tcg_gen_ext16s_tl(t0, t1);
7961 gen_store_gpr(t0, rd);
7963 default: /* Invalid */
7964 MIPS_INVAL("bshfl");
7965 generate_exception(ctx, EXCP_RI);
7973 check_insn(env, ctx, ISA_MIPS32R2);
7975 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
7979 save_cpu_state(ctx, 1);
7980 tcg_gen_helper_1_0(do_rdhwr_cpunum, t0);
7983 save_cpu_state(ctx, 1);
7984 tcg_gen_helper_1_0(do_rdhwr_synci_step, t0);
7987 save_cpu_state(ctx, 1);
7988 tcg_gen_helper_1_0(do_rdhwr_cc, t0);
7991 save_cpu_state(ctx, 1);
7992 tcg_gen_helper_1_0(do_rdhwr_ccres, t0);
7995 if (env->user_mode_only) {
7996 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, tls_value));
7999 /* XXX: Some CPUs implement this in hardware.
8000 Not supported yet. */
8002 default: /* Invalid */
8003 MIPS_INVAL("rdhwr");
8004 generate_exception(ctx, EXCP_RI);
8007 gen_store_gpr(t0, rt);
8012 check_insn(env, ctx, ASE_MT);
8014 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8015 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8017 gen_load_gpr(t0, rt);
8018 gen_load_gpr(t1, rs);
8019 tcg_gen_helper_0_2(do_fork, t0, t1);
8025 check_insn(env, ctx, ASE_MT);
8027 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8029 gen_load_gpr(t0, rs);
8030 tcg_gen_helper_1_1(do_yield, t0, t0);
8031 gen_store_gpr(t0, rd);
8035 #if defined(TARGET_MIPS64)
8036 case OPC_DEXTM ... OPC_DEXT:
8037 case OPC_DINSM ... OPC_DINS:
8038 check_insn(env, ctx, ISA_MIPS64R2);
8040 gen_bitops(ctx, op1, rt, rs, sa, rd);
8043 check_insn(env, ctx, ISA_MIPS64R2);
8045 op2 = MASK_DBSHFL(ctx->opcode);
8047 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8048 TCGv t1 = tcg_temp_local_new(TCG_TYPE_TL);
8052 gen_load_gpr(t1, rt);
8053 tcg_gen_helper_1_1(do_dsbh, t0, t1);
8056 gen_load_gpr(t1, rt);
8057 tcg_gen_helper_1_1(do_dshd, t0, t1);
8059 default: /* Invalid */
8060 MIPS_INVAL("dbshfl");
8061 generate_exception(ctx, EXCP_RI);
8064 gen_store_gpr(t0, rd);
8070 default: /* Invalid */
8071 MIPS_INVAL("special3");
8072 generate_exception(ctx, EXCP_RI);
8077 op1 = MASK_REGIMM(ctx->opcode);
8079 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
8080 case OPC_BLTZAL ... OPC_BGEZALL:
8081 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
8083 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
8085 gen_trap(ctx, op1, rs, -1, imm);
8088 check_insn(env, ctx, ISA_MIPS32R2);
8091 default: /* Invalid */
8092 MIPS_INVAL("regimm");
8093 generate_exception(ctx, EXCP_RI);
8098 check_cp0_enabled(ctx);
8099 op1 = MASK_CP0(ctx->opcode);
8105 #if defined(TARGET_MIPS64)
8109 #ifndef CONFIG_USER_ONLY
8110 if (!env->user_mode_only)
8111 gen_cp0(env, ctx, op1, rt, rd);
8112 #endif /* !CONFIG_USER_ONLY */
8114 case OPC_C0_FIRST ... OPC_C0_LAST:
8115 #ifndef CONFIG_USER_ONLY
8116 if (!env->user_mode_only)
8117 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
8118 #endif /* !CONFIG_USER_ONLY */
8121 #ifndef CONFIG_USER_ONLY
8122 if (!env->user_mode_only) {
8123 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
8125 op2 = MASK_MFMC0(ctx->opcode);
8128 check_insn(env, ctx, ASE_MT);
8129 tcg_gen_helper_1_1(do_dmt, t0, t0);
8132 check_insn(env, ctx, ASE_MT);
8133 tcg_gen_helper_1_1(do_emt, t0, t0);
8136 check_insn(env, ctx, ASE_MT);
8137 tcg_gen_helper_1_1(do_dvpe, t0, t0);
8140 check_insn(env, ctx, ASE_MT);
8141 tcg_gen_helper_1_1(do_evpe, t0, t0);
8144 check_insn(env, ctx, ISA_MIPS32R2);
8145 save_cpu_state(ctx, 1);
8146 tcg_gen_helper_1_0(do_di, t0);
8147 /* Stop translation as we may have switched the execution mode */
8148 ctx->bstate = BS_STOP;
8151 check_insn(env, ctx, ISA_MIPS32R2);
8152 save_cpu_state(ctx, 1);
8153 tcg_gen_helper_1_0(do_ei, t0);
8154 /* Stop translation as we may have switched the execution mode */
8155 ctx->bstate = BS_STOP;
8157 default: /* Invalid */
8158 MIPS_INVAL("mfmc0");
8159 generate_exception(ctx, EXCP_RI);
8162 gen_store_gpr(t0, rt);
8165 #endif /* !CONFIG_USER_ONLY */
8168 check_insn(env, ctx, ISA_MIPS32R2);
8169 gen_load_srsgpr(rt, rd);
8172 check_insn(env, ctx, ISA_MIPS32R2);
8173 gen_store_srsgpr(rt, rd);
8177 generate_exception(ctx, EXCP_RI);
8181 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
8182 gen_arith_imm(env, ctx, op, rt, rs, imm);
8184 case OPC_J ... OPC_JAL: /* Jump */
8185 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
8186 gen_compute_branch(ctx, op, rs, rt, offset);
8188 case OPC_BEQ ... OPC_BGTZ: /* Branch */
8189 case OPC_BEQL ... OPC_BGTZL:
8190 gen_compute_branch(ctx, op, rs, rt, imm << 2);
8192 case OPC_LB ... OPC_LWR: /* Load and stores */
8193 case OPC_SB ... OPC_SW:
8197 gen_ldst(ctx, op, rt, rs, imm);
8200 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
8204 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
8208 /* Floating point (COP1). */
8213 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8214 save_cpu_state(ctx, 1);
8215 check_cp1_enabled(ctx);
8216 gen_flt_ldst(ctx, op, rt, rs, imm);
8218 generate_exception_err(ctx, EXCP_CpU, 1);
8223 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8224 save_cpu_state(ctx, 1);
8225 check_cp1_enabled(ctx);
8226 op1 = MASK_CP1(ctx->opcode);
8230 check_insn(env, ctx, ISA_MIPS32R2);
8235 gen_cp1(ctx, op1, rt, rd);
8237 #if defined(TARGET_MIPS64)
8240 check_insn(env, ctx, ISA_MIPS3);
8241 gen_cp1(ctx, op1, rt, rd);
8247 check_insn(env, ctx, ASE_MIPS3D);
8250 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
8251 (rt >> 2) & 0x7, imm << 2);
8258 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
8263 generate_exception (ctx, EXCP_RI);
8267 generate_exception_err(ctx, EXCP_CpU, 1);
8277 /* COP2: Not implemented. */
8278 generate_exception_err(ctx, EXCP_CpU, 2);
8282 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
8283 save_cpu_state(ctx, 1);
8284 check_cp1_enabled(ctx);
8285 op1 = MASK_CP3(ctx->opcode);
8293 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
8311 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
8315 generate_exception (ctx, EXCP_RI);
8319 generate_exception_err(ctx, EXCP_CpU, 1);
8323 #if defined(TARGET_MIPS64)
8324 /* MIPS64 opcodes */
8326 case OPC_LDL ... OPC_LDR:
8327 case OPC_SDL ... OPC_SDR:
8332 check_insn(env, ctx, ISA_MIPS3);
8334 gen_ldst(ctx, op, rt, rs, imm);
8336 case OPC_DADDI ... OPC_DADDIU:
8337 check_insn(env, ctx, ISA_MIPS3);
8339 gen_arith_imm(env, ctx, op, rt, rs, imm);
8343 check_insn(env, ctx, ASE_MIPS16);
8344 /* MIPS16: Not implemented. */
8346 check_insn(env, ctx, ASE_MDMX);
8347 /* MDMX: Not implemented. */
8348 default: /* Invalid */
8349 MIPS_INVAL("major opcode");
8350 generate_exception(ctx, EXCP_RI);
8353 if (ctx->hflags & MIPS_HFLAG_BMASK) {
8354 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
8355 /* Branches completion */
8356 ctx->hflags &= ~MIPS_HFLAG_BMASK;
8357 ctx->bstate = BS_BRANCH;
8358 save_cpu_state(ctx, 0);
8359 /* FIXME: Need to clear can_do_io. */
8362 /* unconditional branch */
8363 MIPS_DEBUG("unconditional branch");
8364 gen_goto_tb(ctx, 0, ctx->btarget);
8367 /* blikely taken case */
8368 MIPS_DEBUG("blikely branch taken");
8369 gen_goto_tb(ctx, 0, ctx->btarget);
8372 /* Conditional branch */
8373 MIPS_DEBUG("conditional branch");
8375 int l1 = gen_new_label();
8377 tcg_gen_brcondi_i32(TCG_COND_NE, bcond, 0, l1);
8378 gen_goto_tb(ctx, 1, ctx->pc + 4);
8380 gen_goto_tb(ctx, 0, ctx->btarget);
8384 /* unconditional branch to register */
8385 MIPS_DEBUG("branch to register");
8386 tcg_gen_mov_tl(cpu_PC, btarget);
8390 MIPS_DEBUG("unknown branch");
8397 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
8401 target_ulong pc_start;
8402 uint16_t *gen_opc_end;
8407 if (search_pc && loglevel)
8408 fprintf (logfile, "search pc %d\n", search_pc);
8411 /* Leave some spare opc slots for branch handling. */
8412 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
8416 ctx.bstate = BS_NONE;
8417 /* Restore delay slot state from the tb context. */
8418 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
8419 restore_cpu_state(env, &ctx);
8420 if (env->user_mode_only)
8421 ctx.mem_idx = MIPS_HFLAG_UM;
8423 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
8425 max_insns = tb->cflags & CF_COUNT_MASK;
8427 max_insns = CF_COUNT_MASK;
8429 if (loglevel & CPU_LOG_TB_CPU) {
8430 fprintf(logfile, "------------------------------------------------\n");
8431 /* FIXME: This may print out stale hflags from env... */
8432 cpu_dump_state(env, logfile, fprintf, 0);
8435 #ifdef MIPS_DEBUG_DISAS
8436 if (loglevel & CPU_LOG_TB_IN_ASM)
8437 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
8438 tb, ctx.mem_idx, ctx.hflags);
8441 while (ctx.bstate == BS_NONE) {
8442 if (env->nb_breakpoints > 0) {
8443 for(j = 0; j < env->nb_breakpoints; j++) {
8444 if (env->breakpoints[j] == ctx.pc) {
8445 save_cpu_state(&ctx, 1);
8446 ctx.bstate = BS_BRANCH;
8447 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8448 /* Include the breakpoint location or the tb won't
8449 * be flushed when it must be. */
8451 goto done_generating;
8457 j = gen_opc_ptr - gen_opc_buf;
8461 gen_opc_instr_start[lj++] = 0;
8463 gen_opc_pc[lj] = ctx.pc;
8464 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
8465 gen_opc_instr_start[lj] = 1;
8466 gen_opc_icount[lj] = num_insns;
8468 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
8470 ctx.opcode = ldl_code(ctx.pc);
8471 decode_opc(env, &ctx);
8475 if (env->singlestep_enabled)
8478 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
8481 if (gen_opc_ptr >= gen_opc_end)
8484 if (num_insns >= max_insns)
8486 #if defined (MIPS_SINGLE_STEP)
8490 if (tb->cflags & CF_LAST_IO)
8492 if (env->singlestep_enabled) {
8493 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
8494 tcg_gen_helper_0_i(do_raise_exception, EXCP_DEBUG);
8496 switch (ctx.bstate) {
8498 tcg_gen_helper_0_0(do_interrupt_restart);
8499 gen_goto_tb(&ctx, 0, ctx.pc);
8502 save_cpu_state(&ctx, 0);
8503 gen_goto_tb(&ctx, 0, ctx.pc);
8506 tcg_gen_helper_0_0(do_interrupt_restart);
8515 gen_icount_end(tb, num_insns);
8516 *gen_opc_ptr = INDEX_op_end;
8518 j = gen_opc_ptr - gen_opc_buf;
8521 gen_opc_instr_start[lj++] = 0;
8523 tb->size = ctx.pc - pc_start;
8524 tb->icount = num_insns;
8527 #if defined MIPS_DEBUG_DISAS
8528 if (loglevel & CPU_LOG_TB_IN_ASM)
8529 fprintf(logfile, "\n");
8531 if (loglevel & CPU_LOG_TB_IN_ASM) {
8532 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
8533 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
8534 fprintf(logfile, "\n");
8536 if (loglevel & CPU_LOG_TB_CPU) {
8537 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
8542 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
8544 gen_intermediate_code_internal(env, tb, 0);
8547 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
8549 gen_intermediate_code_internal(env, tb, 1);
8552 static void fpu_dump_state(CPUState *env, FILE *f,
8553 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
8557 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
8559 #define printfpr(fp) \
8562 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8563 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8564 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8567 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8568 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8569 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8570 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8571 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8576 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8577 env->active_fpu.fcr0, env->active_fpu.fcr31, is_fpu64, env->active_fpu.fp_status,
8578 get_float_exception_flags(&env->active_fpu.fp_status));
8579 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
8580 fpu_fprintf(f, "%3s: ", fregnames[i]);
8581 printfpr(&env->active_fpu.fpr[i]);
8587 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8588 /* Debug help: The architecture requires 32bit code to maintain proper
8589 sign-extended values on 64bit machines. */
8591 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8594 cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
8595 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8600 if (!SIGN_EXT_P(env->active_tc.PC))
8601 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->active_tc.PC);
8602 if (!SIGN_EXT_P(env->active_tc.HI[0]))
8603 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->active_tc.HI[0]);
8604 if (!SIGN_EXT_P(env->active_tc.LO[0]))
8605 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->active_tc.LO[0]);
8606 if (!SIGN_EXT_P(env->btarget))
8607 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
8609 for (i = 0; i < 32; i++) {
8610 if (!SIGN_EXT_P(env->active_tc.gpr[i]))
8611 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->active_tc.gpr[i]);
8614 if (!SIGN_EXT_P(env->CP0_EPC))
8615 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
8616 if (!SIGN_EXT_P(env->CP0_LLAddr))
8617 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
8621 void cpu_dump_state (CPUState *env, FILE *f,
8622 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
8627 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",
8628 env->active_tc.PC, env->active_tc.HI[0], env->active_tc.LO[0],
8629 env->hflags, env->btarget, env->bcond);
8630 for (i = 0; i < 32; i++) {
8632 cpu_fprintf(f, "GPR%02d:", i);
8633 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->active_tc.gpr[i]);
8635 cpu_fprintf(f, "\n");
8638 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
8639 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
8640 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
8641 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
8642 if (env->hflags & MIPS_HFLAG_FPU)
8643 fpu_dump_state(env, f, cpu_fprintf, flags);
8644 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8645 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
8649 static void mips_tcg_init(void)
8654 /* Initialize various static tables. */
8658 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
8659 for (i = 0; i < 32; i++)
8660 cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8661 offsetof(CPUState, active_tc.gpr[i]),
8663 cpu_PC = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8664 offsetof(CPUState, active_tc.PC), "PC");
8665 for (i = 0; i < MIPS_DSP_ACC; i++) {
8666 cpu_HI[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8667 offsetof(CPUState, active_tc.HI[i]),
8669 cpu_LO[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8670 offsetof(CPUState, active_tc.LO[i]),
8672 cpu_ACX[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8673 offsetof(CPUState, active_tc.ACX[i]),
8676 cpu_dspctrl = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8677 offsetof(CPUState, active_tc.DSPControl),
8679 bcond = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8680 offsetof(CPUState, bcond), "bcond");
8681 btarget = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
8682 offsetof(CPUState, btarget), "btarget");
8683 for (i = 0; i < 32; i++)
8684 fpu_fpr32[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8685 offsetof(CPUState, active_fpu.fpr[i].w[FP_ENDIAN_IDX]),
8687 for (i = 0; i < 32; i++)
8688 fpu_fpr64[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
8689 offsetof(CPUState, active_fpu.fpr[i]),
8691 for (i = 0; i < 32; i++)
8692 fpu_fpr32h[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8693 offsetof(CPUState, active_fpu.fpr[i].w[!FP_ENDIAN_IDX]),
8695 fpu_fcr0 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8696 offsetof(CPUState, active_fpu.fcr0),
8698 fpu_fcr31 = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
8699 offsetof(CPUState, active_fpu.fcr31),
8702 /* register helpers */
8704 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8710 #include "translate_init.c"
8712 CPUMIPSState *cpu_mips_init (const char *cpu_model)
8715 const mips_def_t *def;
8717 def = cpu_mips_find_by_name(cpu_model);
8720 env = qemu_mallocz(sizeof(CPUMIPSState));
8723 env->cpu_model = def;
8726 env->cpu_model_str = cpu_model;
8732 void cpu_reset (CPUMIPSState *env)
8734 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
8739 #if defined(CONFIG_USER_ONLY)
8740 env->user_mode_only = 1;
8742 if (env->user_mode_only) {
8743 env->hflags = MIPS_HFLAG_UM;
8745 if (env->hflags & MIPS_HFLAG_BMASK) {
8746 /* If the exception was raised from a delay slot,
8747 come back to the jump. */
8748 env->CP0_ErrorEPC = env->active_tc.PC - 4;
8750 env->CP0_ErrorEPC = env->active_tc.PC;
8752 env->active_tc.PC = (int32_t)0xBFC00000;
8754 /* SMP not implemented */
8755 env->CP0_EBase = 0x80000000;
8756 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
8757 /* vectored interrupts not implemented, timer on int 7,
8758 no performance counters. */
8759 env->CP0_IntCtl = 0xe0000000;
8763 for (i = 0; i < 7; i++) {
8764 env->CP0_WatchLo[i] = 0;
8765 env->CP0_WatchHi[i] = 0x80000000;
8767 env->CP0_WatchLo[7] = 0;
8768 env->CP0_WatchHi[7] = 0;
8770 /* Count register increments in debug mode, EJTAG version 1 */
8771 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
8772 env->hflags = MIPS_HFLAG_CP0;
8774 env->exception_index = EXCP_NONE;
8775 cpu_mips_register(env, env->cpu_model);
8778 void gen_pc_load(CPUState *env, TranslationBlock *tb,
8779 unsigned long searched_pc, int pc_pos, void *puc)
8781 env->active_tc.PC = gen_opc_pc[pc_pos];
8782 env->hflags &= ~MIPS_HFLAG_BMASK;
8783 env->hflags |= gen_opc_hflags[pc_pos];