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, current_tc_gprs, current_tc_hi, current_fpu, cpu_T[2];
428 /* FPU TNs, global for now. */
429 static TCGv fpu32_T[3], fpu64_T[3], fpu32h_T[3];
431 static inline void tcg_gen_helper_0_1i(void *func, TCGv arg)
433 TCGv t = tcg_const_i32(arg);
435 tcg_gen_helper_0_1(func, t);
439 static inline void tcg_gen_helper_0_2ii(void *func, TCGv arg1, TCGv arg2)
441 TCGv t1 = tcg_const_i32(arg1);
442 TCGv t2 = tcg_const_i32(arg2);
444 tcg_gen_helper_0_2(func, t1, t2);
449 typedef struct DisasContext {
450 struct TranslationBlock *tb;
451 target_ulong pc, saved_pc;
454 /* Routine used to access memory */
456 uint32_t hflags, saved_hflags;
458 target_ulong btarget;
462 BS_NONE = 0, /* We go out of the TB without reaching a branch or an
463 * exception condition
465 BS_STOP = 1, /* We want to stop translation for any reason */
466 BS_BRANCH = 2, /* We reached a branch condition */
467 BS_EXCP = 3, /* We reached an exception condition */
470 static const char *regnames[] =
471 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
472 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
473 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
474 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
476 static const char *fregnames[] =
477 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
478 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
479 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
480 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
482 #ifdef MIPS_DEBUG_DISAS
483 #define MIPS_DEBUG(fmt, args...) \
485 if (loglevel & CPU_LOG_TB_IN_ASM) { \
486 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
487 ctx->pc, ctx->opcode , ##args); \
491 #define MIPS_DEBUG(fmt, args...) do { } while(0)
494 #define MIPS_INVAL(op) \
496 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
497 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
500 /* General purpose registers moves. */
501 static inline void gen_load_gpr (TCGv t, int reg)
504 tcg_gen_movi_tl(t, 0);
506 tcg_gen_ld_tl(t, current_tc_gprs, sizeof(target_ulong) * reg);
509 static inline void gen_store_gpr (TCGv t, int reg)
512 tcg_gen_st_tl(t, current_tc_gprs, sizeof(target_ulong) * reg);
515 /* Moves to/from HI and LO registers. */
516 static inline void gen_load_LO (TCGv t, int reg)
518 tcg_gen_ld_tl(t, current_tc_hi,
519 offsetof(CPUState, LO)
520 - offsetof(CPUState, HI)
521 + sizeof(target_ulong) * reg);
524 static inline void gen_store_LO (TCGv t, int reg)
526 tcg_gen_st_tl(t, current_tc_hi,
527 offsetof(CPUState, LO)
528 - offsetof(CPUState, HI)
529 + sizeof(target_ulong) * reg);
532 static inline void gen_load_HI (TCGv t, int reg)
534 tcg_gen_ld_tl(t, current_tc_hi, sizeof(target_ulong) * reg);
537 static inline void gen_store_HI (TCGv t, int reg)
539 tcg_gen_st_tl(t, current_tc_hi, sizeof(target_ulong) * reg);
542 /* Moves to/from shadow registers. */
543 static inline void gen_load_srsgpr (TCGv t, int reg)
546 tcg_gen_movi_tl(t, 0);
548 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
550 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl));
551 tcg_gen_shri_i32(r_tmp, r_tmp, CP0SRSCtl_PSS);
552 tcg_gen_andi_i32(r_tmp, r_tmp, 0xf);
553 tcg_gen_muli_i32(r_tmp, r_tmp, sizeof(target_ulong) * 32);
554 tcg_gen_add_i32(r_tmp, cpu_env, r_tmp);
556 tcg_gen_ld_tl(t, r_tmp, sizeof(target_ulong) * reg);
557 tcg_temp_free(r_tmp);
561 static inline void gen_store_srsgpr (TCGv t, int reg)
564 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
566 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl));
567 tcg_gen_shri_i32(r_tmp, r_tmp, CP0SRSCtl_PSS);
568 tcg_gen_andi_i32(r_tmp, r_tmp, 0xf);
569 tcg_gen_muli_i32(r_tmp, r_tmp, sizeof(target_ulong) * 32);
570 tcg_gen_add_i32(r_tmp, cpu_env, r_tmp);
572 tcg_gen_st_tl(t, r_tmp, sizeof(target_ulong) * reg);
573 tcg_temp_free(r_tmp);
577 /* Floating point register moves. */
578 static inline void gen_load_fpr32 (TCGv t, int reg)
580 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
583 static inline void gen_store_fpr32 (TCGv t, int reg)
585 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * FP_ENDIAN_IDX);
588 static inline void gen_load_fpr64 (DisasContext *ctx, TCGv t, int reg)
590 if (ctx->hflags & MIPS_HFLAG_F64) {
591 tcg_gen_ld_i64(t, current_fpu, 8 * reg);
593 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
594 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
596 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
597 tcg_gen_extu_i32_i64(t, r_tmp1);
598 tcg_gen_shli_i64(t, t, 32);
599 tcg_gen_ld_i32(r_tmp1, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
600 tcg_gen_extu_i32_i64(r_tmp2, r_tmp1);
601 tcg_gen_or_i64(t, t, r_tmp2);
602 tcg_temp_free(r_tmp1);
603 tcg_temp_free(r_tmp2);
607 static inline void gen_store_fpr64 (DisasContext *ctx, TCGv t, int reg)
609 if (ctx->hflags & MIPS_HFLAG_F64) {
610 tcg_gen_st_i64(t, current_fpu, 8 * reg);
612 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
614 tcg_gen_trunc_i64_i32(r_tmp, t);
615 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg & ~1) + 4 * FP_ENDIAN_IDX);
616 tcg_gen_shri_i64(t, t, 32);
617 tcg_gen_trunc_i64_i32(r_tmp, t);
618 tcg_gen_st_i32(r_tmp, current_fpu, 8 * (reg | 1) + 4 * FP_ENDIAN_IDX);
619 tcg_temp_free(r_tmp);
623 static inline void gen_load_fpr32h (TCGv t, int reg)
625 tcg_gen_ld_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
628 static inline void gen_store_fpr32h (TCGv t, int reg)
630 tcg_gen_st_i32(t, current_fpu, 8 * reg + 4 * !FP_ENDIAN_IDX);
633 static inline void get_fp_cond (TCGv t)
635 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
636 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
638 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
639 tcg_gen_shri_i32(r_tmp2, r_tmp1, 24);
640 tcg_gen_andi_i32(r_tmp2, r_tmp2, 0xfe);
641 tcg_gen_shri_i32(r_tmp1, r_tmp1, 23);
642 tcg_gen_andi_i32(r_tmp1, r_tmp1, 0x1);
643 tcg_gen_or_i32(t, r_tmp1, r_tmp2);
644 tcg_temp_free(r_tmp1);
645 tcg_temp_free(r_tmp2);
648 #define FOP_CONDS(type, fmt) \
649 static GenOpFunc1 * fcmp ## type ## _ ## fmt ## _table[16] = { \
650 do_cmp ## type ## _ ## fmt ## _f, \
651 do_cmp ## type ## _ ## fmt ## _un, \
652 do_cmp ## type ## _ ## fmt ## _eq, \
653 do_cmp ## type ## _ ## fmt ## _ueq, \
654 do_cmp ## type ## _ ## fmt ## _olt, \
655 do_cmp ## type ## _ ## fmt ## _ult, \
656 do_cmp ## type ## _ ## fmt ## _ole, \
657 do_cmp ## type ## _ ## fmt ## _ule, \
658 do_cmp ## type ## _ ## fmt ## _sf, \
659 do_cmp ## type ## _ ## fmt ## _ngle, \
660 do_cmp ## type ## _ ## fmt ## _seq, \
661 do_cmp ## type ## _ ## fmt ## _ngl, \
662 do_cmp ## type ## _ ## fmt ## _lt, \
663 do_cmp ## type ## _ ## fmt ## _nge, \
664 do_cmp ## type ## _ ## fmt ## _le, \
665 do_cmp ## type ## _ ## fmt ## _ngt, \
667 static inline void gen_cmp ## type ## _ ## fmt(int n, long cc) \
669 tcg_gen_helper_0_1i(fcmp ## type ## _ ## fmt ## _table[n], cc); \
681 #define OP_COND(name, cond) \
682 void glue(gen_op_, name) (void) \
684 int l1 = gen_new_label(); \
685 int l2 = gen_new_label(); \
687 tcg_gen_brcond_tl(cond, cpu_T[0], cpu_T[1], l1); \
688 tcg_gen_movi_tl(cpu_T[0], 0); \
691 tcg_gen_movi_tl(cpu_T[0], 1); \
694 OP_COND(eq, TCG_COND_EQ);
695 OP_COND(ne, TCG_COND_NE);
696 OP_COND(ge, TCG_COND_GE);
697 OP_COND(geu, TCG_COND_GEU);
698 OP_COND(lt, TCG_COND_LT);
699 OP_COND(ltu, TCG_COND_LTU);
702 #define OP_CONDI(name, cond) \
703 void glue(gen_op_, name) (target_ulong val) \
705 int l1 = gen_new_label(); \
706 int l2 = gen_new_label(); \
708 tcg_gen_brcondi_tl(cond, cpu_T[0], val, l1); \
709 tcg_gen_movi_tl(cpu_T[0], 0); \
712 tcg_gen_movi_tl(cpu_T[0], 1); \
715 OP_CONDI(lti, TCG_COND_LT);
716 OP_CONDI(ltiu, TCG_COND_LTU);
719 #define OP_CONDZ(name, cond) \
720 void glue(gen_op_, name) (void) \
722 int l1 = gen_new_label(); \
723 int l2 = gen_new_label(); \
725 tcg_gen_brcondi_tl(cond, cpu_T[0], 0, l1); \
726 tcg_gen_movi_tl(cpu_T[0], 0); \
729 tcg_gen_movi_tl(cpu_T[0], 1); \
732 OP_CONDZ(gez, TCG_COND_GE);
733 OP_CONDZ(gtz, TCG_COND_GT);
734 OP_CONDZ(lez, TCG_COND_LE);
735 OP_CONDZ(ltz, TCG_COND_LT);
738 static inline void gen_save_pc(target_ulong pc)
740 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
741 TCGv r_tc_off = tcg_temp_new(TCG_TYPE_I32);
742 TCGv r_tc_off_ptr = tcg_temp_new(TCG_TYPE_PTR);
743 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
745 tcg_gen_movi_tl(r_tmp, pc);
746 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
747 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
748 tcg_gen_ext_i32_ptr(r_tc_off_ptr, r_tc_off);
749 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_ptr);
750 tcg_gen_st_tl(r_tmp, r_ptr, offsetof(CPUState, PC));
751 tcg_temp_free(r_tc_off);
752 tcg_temp_free(r_tc_off_ptr);
753 tcg_temp_free(r_ptr);
754 tcg_temp_free(r_tmp);
757 static inline void gen_breg_pc(void)
759 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
760 TCGv r_tc_off = tcg_temp_new(TCG_TYPE_I32);
761 TCGv r_tc_off_ptr = tcg_temp_new(TCG_TYPE_PTR);
762 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
764 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
765 tcg_gen_ld_i32(r_tc_off, cpu_env, offsetof(CPUState, current_tc));
766 tcg_gen_muli_i32(r_tc_off, r_tc_off, sizeof(target_ulong));
767 tcg_gen_ext_i32_ptr(r_tc_off_ptr, r_tc_off);
768 tcg_gen_add_ptr(r_ptr, cpu_env, r_tc_off_ptr);
769 tcg_gen_st_tl(r_tmp, r_ptr, offsetof(CPUState, PC));
770 tcg_temp_free(r_tc_off);
771 tcg_temp_free(r_tc_off_ptr);
772 tcg_temp_free(r_ptr);
773 tcg_temp_free(r_tmp);
776 static inline void gen_save_btarget(target_ulong btarget)
778 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
780 tcg_gen_movi_tl(r_tmp, btarget);
781 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
782 tcg_temp_free(r_tmp);
785 static always_inline void gen_save_breg_target(int reg)
787 TCGv r_tmp = tcg_temp_new(TCG_TYPE_TL);
789 gen_load_gpr(r_tmp, reg);
790 tcg_gen_st_tl(r_tmp, cpu_env, offsetof(CPUState, btarget));
791 tcg_temp_free(r_tmp);
794 static always_inline void save_cpu_state (DisasContext *ctx, int do_save_pc)
796 #if defined MIPS_DEBUG_DISAS
797 if (loglevel & CPU_LOG_TB_IN_ASM) {
798 fprintf(logfile, "hflags %08x saved %08x\n",
799 ctx->hflags, ctx->saved_hflags);
802 if (do_save_pc && ctx->pc != ctx->saved_pc) {
803 gen_save_pc(ctx->pc);
804 ctx->saved_pc = ctx->pc;
806 if (ctx->hflags != ctx->saved_hflags) {
807 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
809 tcg_gen_movi_i32(r_tmp, ctx->hflags);
810 tcg_gen_st_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
811 tcg_temp_free(r_tmp);
812 ctx->saved_hflags = ctx->hflags;
813 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
819 gen_save_btarget(ctx->btarget);
825 static always_inline void restore_cpu_state (CPUState *env, DisasContext *ctx)
827 ctx->saved_hflags = ctx->hflags;
828 switch (ctx->hflags & MIPS_HFLAG_BMASK) {
834 ctx->btarget = env->btarget;
839 static always_inline void
840 generate_exception_err (DisasContext *ctx, int excp, int err)
842 save_cpu_state(ctx, 1);
843 tcg_gen_helper_0_2ii(do_raise_exception_err, excp, err);
844 tcg_gen_helper_0_0(do_interrupt_restart);
848 static always_inline void
849 generate_exception (DisasContext *ctx, int excp)
851 save_cpu_state(ctx, 1);
852 tcg_gen_helper_0_1i(do_raise_exception, excp);
853 tcg_gen_helper_0_0(do_interrupt_restart);
857 /* Addresses computation */
858 static inline void gen_op_addr_add (void)
860 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
862 #if defined(TARGET_MIPS64)
863 /* For compatibility with 32-bit code, data reference in user mode
864 with Status_UX = 0 should be casted to 32-bit and sign extended.
865 See the MIPS64 PRA manual, section 4.10. */
867 int l1 = gen_new_label();
868 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
870 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, hflags));
871 tcg_gen_andi_i32(r_tmp, r_tmp, MIPS_HFLAG_KSU);
872 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, MIPS_HFLAG_UM, l1);
873 tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_Status));
874 tcg_gen_andi_i32(r_tmp, r_tmp, (1 << CP0St_UX));
875 tcg_gen_brcondi_i32(TCG_COND_NE, r_tmp, 0, l1);
876 tcg_temp_free(r_tmp);
877 tcg_gen_ext32s_i64(cpu_T[0], cpu_T[0]);
883 static always_inline void check_cp0_enabled(DisasContext *ctx)
885 if (unlikely(!(ctx->hflags & MIPS_HFLAG_CP0)))
886 generate_exception_err(ctx, EXCP_CpU, 1);
889 static always_inline void check_cp1_enabled(DisasContext *ctx)
891 if (unlikely(!(ctx->hflags & MIPS_HFLAG_FPU)))
892 generate_exception_err(ctx, EXCP_CpU, 1);
895 /* Verify that the processor is running with COP1X instructions enabled.
896 This is associated with the nabla symbol in the MIPS32 and MIPS64
899 static always_inline void check_cop1x(DisasContext *ctx)
901 if (unlikely(!(ctx->hflags & MIPS_HFLAG_COP1X)))
902 generate_exception(ctx, EXCP_RI);
905 /* Verify that the processor is running with 64-bit floating-point
906 operations enabled. */
908 static always_inline void check_cp1_64bitmode(DisasContext *ctx)
910 if (unlikely(~ctx->hflags & (MIPS_HFLAG_F64 | MIPS_HFLAG_COP1X)))
911 generate_exception(ctx, EXCP_RI);
915 * Verify if floating point register is valid; an operation is not defined
916 * if bit 0 of any register specification is set and the FR bit in the
917 * Status register equals zero, since the register numbers specify an
918 * even-odd pair of adjacent coprocessor general registers. When the FR bit
919 * in the Status register equals one, both even and odd register numbers
920 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
922 * Multiple 64 bit wide registers can be checked by calling
923 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
925 void check_cp1_registers(DisasContext *ctx, int regs)
927 if (unlikely(!(ctx->hflags & MIPS_HFLAG_F64) && (regs & 1)))
928 generate_exception(ctx, EXCP_RI);
931 /* This code generates a "reserved instruction" exception if the
932 CPU does not support the instruction set corresponding to flags. */
933 static always_inline void check_insn(CPUState *env, DisasContext *ctx, int flags)
935 if (unlikely(!(env->insn_flags & flags)))
936 generate_exception(ctx, EXCP_RI);
939 /* This code generates a "reserved instruction" exception if 64-bit
940 instructions are not enabled. */
941 static always_inline void check_mips_64(DisasContext *ctx)
943 if (unlikely(!(ctx->hflags & MIPS_HFLAG_64)))
944 generate_exception(ctx, EXCP_RI);
947 /* load/store instructions. */
948 #define OP_LD(insn,fname) \
949 void inline op_ldst_##insn(DisasContext *ctx) \
951 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
958 #if defined(TARGET_MIPS64)
964 #define OP_ST(insn,fname) \
965 void inline op_ldst_##insn(DisasContext *ctx) \
967 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
972 #if defined(TARGET_MIPS64)
977 #define OP_LD_ATOMIC(insn,fname) \
978 void inline op_ldst_##insn(DisasContext *ctx) \
980 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]); \
981 tcg_gen_qemu_##fname(cpu_T[0], cpu_T[0], ctx->mem_idx); \
982 tcg_gen_st_tl(cpu_T[1], cpu_env, offsetof(CPUState, CP0_LLAddr)); \
984 OP_LD_ATOMIC(ll,ld32s);
985 #if defined(TARGET_MIPS64)
986 OP_LD_ATOMIC(lld,ld64);
990 #define OP_ST_ATOMIC(insn,fname,almask) \
991 void inline op_ldst_##insn(DisasContext *ctx) \
993 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
994 int l1 = gen_new_label(); \
995 int l2 = gen_new_label(); \
996 int l3 = gen_new_label(); \
998 tcg_gen_andi_tl(r_tmp, cpu_T[0], almask); \
999 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1000 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1001 generate_exception(ctx, EXCP_AdES); \
1002 gen_set_label(l1); \
1003 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1004 tcg_gen_brcond_tl(TCG_COND_NE, cpu_T[0], r_tmp, l2); \
1005 tcg_temp_free(r_tmp); \
1006 tcg_gen_qemu_##fname(cpu_T[1], cpu_T[0], ctx->mem_idx); \
1007 tcg_gen_movi_tl(cpu_T[0], 1); \
1009 gen_set_label(l2); \
1010 tcg_gen_movi_tl(cpu_T[0], 0); \
1011 gen_set_label(l3); \
1013 OP_ST_ATOMIC(sc,st32,0x3);
1014 #if defined(TARGET_MIPS64)
1015 OP_ST_ATOMIC(scd,st64,0x7);
1019 /* Load and store */
1020 static void gen_ldst (DisasContext *ctx, uint32_t opc, int rt,
1021 int base, int16_t offset)
1023 const char *opn = "ldst";
1026 tcg_gen_movi_tl(cpu_T[0], offset);
1027 } else if (offset == 0) {
1028 gen_load_gpr(cpu_T[0], base);
1030 gen_load_gpr(cpu_T[0], base);
1031 tcg_gen_movi_tl(cpu_T[1], offset);
1034 /* Don't do NOP if destination is zero: we must perform the actual
1037 #if defined(TARGET_MIPS64)
1040 gen_store_gpr(cpu_T[0], rt);
1045 gen_store_gpr(cpu_T[0], rt);
1050 gen_store_gpr(cpu_T[0], rt);
1054 gen_load_gpr(cpu_T[1], rt);
1059 save_cpu_state(ctx, 1);
1060 gen_load_gpr(cpu_T[1], rt);
1062 gen_store_gpr(cpu_T[0], rt);
1066 save_cpu_state(ctx, 1);
1067 gen_load_gpr(cpu_T[1], rt);
1068 tcg_gen_helper_0_1i(do_ldl, ctx->mem_idx);
1069 gen_store_gpr(cpu_T[1], rt);
1073 save_cpu_state(ctx, 1);
1074 gen_load_gpr(cpu_T[1], rt);
1075 tcg_gen_helper_0_1i(do_sdl, ctx->mem_idx);
1079 save_cpu_state(ctx, 1);
1080 gen_load_gpr(cpu_T[1], rt);
1081 tcg_gen_helper_0_1i(do_ldr, ctx->mem_idx);
1082 gen_store_gpr(cpu_T[1], rt);
1086 save_cpu_state(ctx, 1);
1087 gen_load_gpr(cpu_T[1], rt);
1088 tcg_gen_helper_0_1i(do_sdr, ctx->mem_idx);
1094 gen_store_gpr(cpu_T[0], rt);
1098 gen_load_gpr(cpu_T[1], rt);
1104 gen_store_gpr(cpu_T[0], rt);
1108 gen_load_gpr(cpu_T[1], rt);
1114 gen_store_gpr(cpu_T[0], rt);
1119 gen_store_gpr(cpu_T[0], rt);
1123 gen_load_gpr(cpu_T[1], rt);
1129 gen_store_gpr(cpu_T[0], rt);
1133 save_cpu_state(ctx, 1);
1134 gen_load_gpr(cpu_T[1], rt);
1135 tcg_gen_helper_0_1i(do_lwl, ctx->mem_idx);
1136 gen_store_gpr(cpu_T[1], rt);
1140 save_cpu_state(ctx, 1);
1141 gen_load_gpr(cpu_T[1], rt);
1142 tcg_gen_helper_0_1i(do_swl, ctx->mem_idx);
1146 save_cpu_state(ctx, 1);
1147 gen_load_gpr(cpu_T[1], rt);
1148 tcg_gen_helper_0_1i(do_lwr, ctx->mem_idx);
1149 gen_store_gpr(cpu_T[1], rt);
1153 save_cpu_state(ctx, 1);
1154 gen_load_gpr(cpu_T[1], rt);
1155 tcg_gen_helper_0_1i(do_swr, ctx->mem_idx);
1160 gen_store_gpr(cpu_T[0], rt);
1164 save_cpu_state(ctx, 1);
1165 gen_load_gpr(cpu_T[1], rt);
1167 gen_store_gpr(cpu_T[0], rt);
1172 generate_exception(ctx, EXCP_RI);
1175 MIPS_DEBUG("%s %s, %d(%s)", opn, regnames[rt], offset, regnames[base]);
1178 /* Load and store */
1179 static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,
1180 int base, int16_t offset)
1182 const char *opn = "flt_ldst";
1185 tcg_gen_movi_tl(cpu_T[0], offset);
1186 } else if (offset == 0) {
1187 gen_load_gpr(cpu_T[0], base);
1189 gen_load_gpr(cpu_T[0], base);
1190 tcg_gen_movi_tl(cpu_T[1], offset);
1193 /* Don't do NOP if destination is zero: we must perform the actual
1197 tcg_gen_qemu_ld32s(fpu32_T[0], cpu_T[0], ctx->mem_idx);
1198 gen_store_fpr32(fpu32_T[0], ft);
1202 gen_load_fpr32(fpu32_T[0], ft);
1203 tcg_gen_qemu_st32(fpu32_T[0], cpu_T[0], ctx->mem_idx);
1207 tcg_gen_qemu_ld64(fpu64_T[0], cpu_T[0], ctx->mem_idx);
1208 gen_store_fpr64(ctx, fpu64_T[0], ft);
1212 gen_load_fpr64(ctx, fpu64_T[0], ft);
1213 tcg_gen_qemu_st64(fpu64_T[0], cpu_T[0], ctx->mem_idx);
1218 generate_exception(ctx, EXCP_RI);
1221 MIPS_DEBUG("%s %s, %d(%s)", opn, fregnames[ft], offset, regnames[base]);
1224 /* Arithmetic with immediate operand */
1225 static void gen_arith_imm (CPUState *env, DisasContext *ctx, uint32_t opc,
1226 int rt, int rs, int16_t imm)
1229 const char *opn = "imm arith";
1231 if (rt == 0 && opc != OPC_ADDI && opc != OPC_DADDI) {
1232 /* If no destination, treat it as a NOP.
1233 For addi, we must generate the overflow exception when needed. */
1237 uimm = (uint16_t)imm;
1241 #if defined(TARGET_MIPS64)
1247 uimm = (target_long)imm; /* Sign extend to 32/64 bits */
1248 tcg_gen_movi_tl(cpu_T[1], uimm);
1253 gen_load_gpr(cpu_T[0], rs);
1256 tcg_gen_movi_tl(cpu_T[0], imm << 16);
1261 #if defined(TARGET_MIPS64)
1270 gen_load_gpr(cpu_T[0], rs);
1276 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1277 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1278 int l1 = gen_new_label();
1280 save_cpu_state(ctx, 1);
1281 tcg_gen_ext32s_tl(r_tmp1, cpu_T[0]);
1282 tcg_gen_addi_tl(cpu_T[0], r_tmp1, uimm);
1284 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1285 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1286 tcg_gen_xori_tl(r_tmp2, cpu_T[0], uimm);
1287 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1288 tcg_temp_free(r_tmp2);
1289 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1290 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1291 tcg_temp_free(r_tmp1);
1292 /* operands of same sign, result different sign */
1293 generate_exception(ctx, EXCP_OVERFLOW);
1296 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1301 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1302 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], uimm);
1303 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1306 #if defined(TARGET_MIPS64)
1309 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1310 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1311 int l1 = gen_new_label();
1313 save_cpu_state(ctx, 1);
1314 tcg_gen_mov_tl(r_tmp1, cpu_T[0]);
1315 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], uimm);
1317 tcg_gen_xori_tl(r_tmp1, r_tmp1, uimm);
1318 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1319 tcg_gen_xori_tl(r_tmp2, cpu_T[0], uimm);
1320 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1321 tcg_temp_free(r_tmp2);
1322 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1323 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1324 tcg_temp_free(r_tmp1);
1325 /* operands of same sign, result different sign */
1326 generate_exception(ctx, EXCP_OVERFLOW);
1332 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], uimm);
1345 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], uimm);
1349 tcg_gen_ori_tl(cpu_T[0], cpu_T[0], uimm);
1353 tcg_gen_xori_tl(cpu_T[0], cpu_T[0], uimm);
1360 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1361 tcg_gen_shli_tl(cpu_T[0], cpu_T[0], uimm);
1362 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1366 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1367 tcg_gen_sari_tl(cpu_T[0], cpu_T[0], uimm);
1368 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1372 switch ((ctx->opcode >> 21) & 0x1f) {
1374 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1375 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1376 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1380 /* rotr is decoded as srl on non-R2 CPUs */
1381 if (env->insn_flags & ISA_MIPS32R2) {
1383 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1384 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1386 tcg_gen_trunc_tl_i32(r_tmp1, cpu_T[0]);
1387 tcg_gen_movi_i32(r_tmp2, 0x20);
1388 tcg_gen_subi_i32(r_tmp2, r_tmp2, uimm);
1389 tcg_gen_shl_i32(r_tmp2, r_tmp1, r_tmp2);
1390 tcg_gen_shri_i32(r_tmp1, r_tmp1, uimm);
1391 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp2);
1392 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
1393 tcg_temp_free(r_tmp1);
1394 tcg_temp_free(r_tmp2);
1398 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1399 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1400 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1405 MIPS_INVAL("invalid srl flag");
1406 generate_exception(ctx, EXCP_RI);
1410 #if defined(TARGET_MIPS64)
1412 tcg_gen_shli_tl(cpu_T[0], cpu_T[0], uimm);
1416 tcg_gen_sari_tl(cpu_T[0], cpu_T[0], uimm);
1420 switch ((ctx->opcode >> 21) & 0x1f) {
1422 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1426 /* drotr is decoded as dsrl on non-R2 CPUs */
1427 if (env->insn_flags & ISA_MIPS32R2) {
1429 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1431 tcg_gen_movi_tl(r_tmp1, 0x40);
1432 tcg_gen_subi_tl(r_tmp1, r_tmp1, uimm);
1433 tcg_gen_shl_tl(r_tmp1, cpu_T[0], r_tmp1);
1434 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1435 tcg_gen_or_tl(cpu_T[0], cpu_T[0], r_tmp1);
1436 tcg_temp_free(r_tmp1);
1440 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm);
1445 MIPS_INVAL("invalid dsrl flag");
1446 generate_exception(ctx, EXCP_RI);
1451 tcg_gen_shli_tl(cpu_T[0], cpu_T[0], uimm + 32);
1455 tcg_gen_sari_tl(cpu_T[0], cpu_T[0], uimm + 32);
1459 switch ((ctx->opcode >> 21) & 0x1f) {
1461 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm + 32);
1465 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1466 if (env->insn_flags & ISA_MIPS32R2) {
1467 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1468 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1470 tcg_gen_movi_tl(r_tmp1, 0x40);
1471 tcg_gen_movi_tl(r_tmp2, 32);
1472 tcg_gen_addi_tl(r_tmp2, r_tmp2, uimm);
1473 tcg_gen_sub_tl(r_tmp1, r_tmp1, r_tmp2);
1474 tcg_gen_shl_tl(r_tmp1, cpu_T[0], r_tmp1);
1475 tcg_gen_shr_tl(cpu_T[0], cpu_T[0], r_tmp2);
1476 tcg_gen_or_tl(cpu_T[0], cpu_T[0], r_tmp1);
1477 tcg_temp_free(r_tmp1);
1478 tcg_temp_free(r_tmp2);
1481 tcg_gen_shri_tl(cpu_T[0], cpu_T[0], uimm + 32);
1486 MIPS_INVAL("invalid dsrl32 flag");
1487 generate_exception(ctx, EXCP_RI);
1494 generate_exception(ctx, EXCP_RI);
1497 gen_store_gpr(cpu_T[0], rt);
1498 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx, opn, regnames[rt], regnames[rs], uimm);
1502 static void gen_arith (CPUState *env, DisasContext *ctx, uint32_t opc,
1503 int rd, int rs, int rt)
1505 const char *opn = "arith";
1507 if (rd == 0 && opc != OPC_ADD && opc != OPC_SUB
1508 && opc != OPC_DADD && opc != OPC_DSUB) {
1509 /* If no destination, treat it as a NOP.
1510 For add & sub, we must generate the overflow exception when needed. */
1514 gen_load_gpr(cpu_T[0], rs);
1515 /* Specialcase the conventional move operation. */
1516 if (rt == 0 && (opc == OPC_ADDU || opc == OPC_DADDU
1517 || opc == OPC_SUBU || opc == OPC_DSUBU)) {
1518 gen_store_gpr(cpu_T[0], rd);
1521 gen_load_gpr(cpu_T[1], rt);
1525 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1526 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1527 int l1 = gen_new_label();
1529 save_cpu_state(ctx, 1);
1530 tcg_gen_ext32s_tl(r_tmp1, cpu_T[0]);
1531 tcg_gen_ext32s_tl(r_tmp2, cpu_T[1]);
1532 tcg_gen_add_tl(cpu_T[0], r_tmp1, r_tmp2);
1534 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[1]);
1535 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1536 tcg_gen_xor_tl(r_tmp2, cpu_T[0], cpu_T[1]);
1537 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1538 tcg_temp_free(r_tmp2);
1539 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1540 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1541 tcg_temp_free(r_tmp1);
1542 /* operands of same sign, result different sign */
1543 generate_exception(ctx, EXCP_OVERFLOW);
1546 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1551 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1552 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1553 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1554 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1559 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1560 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1561 int l1 = gen_new_label();
1563 save_cpu_state(ctx, 1);
1564 tcg_gen_ext32s_tl(r_tmp1, cpu_T[0]);
1565 tcg_gen_ext32s_tl(r_tmp2, cpu_T[1]);
1566 tcg_gen_sub_tl(cpu_T[0], r_tmp1, r_tmp2);
1568 tcg_gen_xor_tl(r_tmp2, r_tmp1, cpu_T[1]);
1569 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[0]);
1570 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1571 tcg_temp_free(r_tmp2);
1572 tcg_gen_shri_tl(r_tmp1, r_tmp1, 31);
1573 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1574 tcg_temp_free(r_tmp1);
1575 /* operands of different sign, first operand and result different sign */
1576 generate_exception(ctx, EXCP_OVERFLOW);
1579 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1584 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1585 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1586 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1587 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1590 #if defined(TARGET_MIPS64)
1593 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1594 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1595 int l1 = gen_new_label();
1597 save_cpu_state(ctx, 1);
1598 tcg_gen_mov_tl(r_tmp1, cpu_T[0]);
1599 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1601 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[1]);
1602 tcg_gen_xori_tl(r_tmp1, r_tmp1, -1);
1603 tcg_gen_xor_tl(r_tmp2, cpu_T[0], cpu_T[1]);
1604 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1605 tcg_temp_free(r_tmp2);
1606 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1607 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1608 tcg_temp_free(r_tmp1);
1609 /* operands of same sign, result different sign */
1610 generate_exception(ctx, EXCP_OVERFLOW);
1616 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1621 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_TL);
1622 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_TL);
1623 int l1 = gen_new_label();
1625 save_cpu_state(ctx, 1);
1626 tcg_gen_mov_tl(r_tmp1, cpu_T[0]);
1627 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1629 tcg_gen_xor_tl(r_tmp2, r_tmp1, cpu_T[1]);
1630 tcg_gen_xor_tl(r_tmp1, r_tmp1, cpu_T[0]);
1631 tcg_gen_and_tl(r_tmp1, r_tmp1, r_tmp2);
1632 tcg_temp_free(r_tmp2);
1633 tcg_gen_shri_tl(r_tmp1, r_tmp1, 63);
1634 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp1, 0, l1);
1635 tcg_temp_free(r_tmp1);
1636 /* operands of different sign, first operand and result different sign */
1637 generate_exception(ctx, EXCP_OVERFLOW);
1643 tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1656 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1660 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1661 tcg_gen_not_tl(cpu_T[0], cpu_T[0]);
1665 tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1669 tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1673 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1674 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1675 tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
1676 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1681 int l1 = gen_new_label();
1683 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1684 gen_store_gpr(cpu_T[0], rd);
1691 int l1 = gen_new_label();
1693 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[1], 0, l1);
1694 gen_store_gpr(cpu_T[0], rd);
1700 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1701 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
1702 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1703 tcg_gen_shl_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1704 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1708 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1709 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1710 tcg_gen_sar_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1711 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1715 switch ((ctx->opcode >> 6) & 0x1f) {
1717 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
1718 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1719 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1720 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1724 /* rotrv is decoded as srlv on non-R2 CPUs */
1725 if (env->insn_flags & ISA_MIPS32R2) {
1726 int l1 = gen_new_label();
1727 int l2 = gen_new_label();
1729 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1730 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
1732 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1733 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1734 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1736 tcg_gen_trunc_tl_i32(r_tmp1, cpu_T[0]);
1737 tcg_gen_trunc_tl_i32(r_tmp2, cpu_T[1]);
1738 tcg_gen_movi_i32(r_tmp3, 0x20);
1739 tcg_gen_sub_i32(r_tmp3, r_tmp3, r_tmp1);
1740 tcg_gen_shl_i32(r_tmp3, r_tmp2, r_tmp3);
1741 tcg_gen_shr_i32(r_tmp1, r_tmp2, r_tmp1);
1742 tcg_gen_or_i32(r_tmp1, r_tmp1, r_tmp3);
1743 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
1744 tcg_temp_free(r_tmp1);
1745 tcg_temp_free(r_tmp2);
1746 tcg_temp_free(r_tmp3);
1750 tcg_gen_mov_tl(cpu_T[0], cpu_T[1]);
1754 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
1755 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x1f);
1756 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1757 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1762 MIPS_INVAL("invalid srlv flag");
1763 generate_exception(ctx, EXCP_RI);
1767 #if defined(TARGET_MIPS64)
1769 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1770 tcg_gen_shl_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1774 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1775 tcg_gen_sar_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1779 switch ((ctx->opcode >> 6) & 0x1f) {
1781 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1782 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1786 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1787 if (env->insn_flags & ISA_MIPS32R2) {
1788 int l1 = gen_new_label();
1789 int l2 = gen_new_label();
1791 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1792 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
1794 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_TL);
1796 tcg_gen_movi_tl(r_tmp1, 0x40);
1797 tcg_gen_sub_tl(r_tmp1, r_tmp1, cpu_T[0]);
1798 tcg_gen_shl_tl(r_tmp1, cpu_T[1], r_tmp1);
1799 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1800 tcg_gen_or_tl(cpu_T[0], cpu_T[0], r_tmp1);
1801 tcg_temp_free(r_tmp1);
1805 tcg_gen_mov_tl(cpu_T[0], cpu_T[1]);
1809 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x3f);
1810 tcg_gen_shr_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1815 MIPS_INVAL("invalid dsrlv flag");
1816 generate_exception(ctx, EXCP_RI);
1823 generate_exception(ctx, EXCP_RI);
1826 gen_store_gpr(cpu_T[0], rd);
1828 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
1831 /* Arithmetic on HI/LO registers */
1832 static void gen_HILO (DisasContext *ctx, uint32_t opc, int reg)
1834 const char *opn = "hilo";
1836 if (reg == 0 && (opc == OPC_MFHI || opc == OPC_MFLO)) {
1843 gen_load_HI(cpu_T[0], 0);
1844 gen_store_gpr(cpu_T[0], reg);
1848 gen_load_LO(cpu_T[0], 0);
1849 gen_store_gpr(cpu_T[0], reg);
1853 gen_load_gpr(cpu_T[0], reg);
1854 gen_store_HI(cpu_T[0], 0);
1858 gen_load_gpr(cpu_T[0], reg);
1859 gen_store_LO(cpu_T[0], 0);
1864 generate_exception(ctx, EXCP_RI);
1867 MIPS_DEBUG("%s %s", opn, regnames[reg]);
1870 static void gen_muldiv (DisasContext *ctx, uint32_t opc,
1873 const char *opn = "mul/div";
1875 gen_load_gpr(cpu_T[0], rs);
1876 gen_load_gpr(cpu_T[1], rt);
1880 int l1 = gen_new_label();
1882 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1883 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1884 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1886 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1887 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1888 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
1890 tcg_gen_ext_tl_i64(r_tmp1, cpu_T[0]);
1891 tcg_gen_ext_tl_i64(r_tmp2, cpu_T[1]);
1892 tcg_gen_div_i64(r_tmp3, r_tmp1, r_tmp2);
1893 tcg_gen_rem_i64(r_tmp2, r_tmp1, r_tmp2);
1894 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp3);
1895 tcg_gen_trunc_i64_tl(cpu_T[1], r_tmp2);
1896 tcg_temp_free(r_tmp1);
1897 tcg_temp_free(r_tmp2);
1898 tcg_temp_free(r_tmp3);
1899 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1900 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1901 gen_store_LO(cpu_T[0], 0);
1902 gen_store_HI(cpu_T[1], 0);
1910 int l1 = gen_new_label();
1912 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1913 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1915 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
1916 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
1917 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I32);
1919 tcg_gen_trunc_tl_i32(r_tmp1, cpu_T[0]);
1920 tcg_gen_trunc_tl_i32(r_tmp2, cpu_T[1]);
1921 tcg_gen_divu_i32(r_tmp3, r_tmp1, r_tmp2);
1922 tcg_gen_remu_i32(r_tmp1, r_tmp1, r_tmp2);
1923 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp3);
1924 tcg_gen_ext_i32_tl(cpu_T[1], r_tmp1);
1925 tcg_temp_free(r_tmp1);
1926 tcg_temp_free(r_tmp2);
1927 tcg_temp_free(r_tmp3);
1928 gen_store_LO(cpu_T[0], 0);
1929 gen_store_HI(cpu_T[1], 0);
1937 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1938 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1940 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1941 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1942 tcg_gen_ext_tl_i64(r_tmp1, cpu_T[0]);
1943 tcg_gen_ext_tl_i64(r_tmp2, cpu_T[1]);
1944 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1945 tcg_temp_free(r_tmp2);
1946 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp1);
1947 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1948 tcg_gen_trunc_i64_tl(cpu_T[1], r_tmp1);
1949 tcg_temp_free(r_tmp1);
1950 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1951 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1952 gen_store_LO(cpu_T[0], 0);
1953 gen_store_HI(cpu_T[1], 0);
1959 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1960 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
1962 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
1963 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
1964 tcg_gen_extu_tl_i64(r_tmp1, cpu_T[0]);
1965 tcg_gen_extu_tl_i64(r_tmp2, cpu_T[1]);
1966 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
1967 tcg_temp_free(r_tmp2);
1968 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp1);
1969 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
1970 tcg_gen_trunc_i64_tl(cpu_T[1], r_tmp1);
1971 tcg_temp_free(r_tmp1);
1972 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
1973 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
1974 gen_store_LO(cpu_T[0], 0);
1975 gen_store_HI(cpu_T[1], 0);
1979 #if defined(TARGET_MIPS64)
1982 int l1 = gen_new_label();
1984 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
1986 int l2 = gen_new_label();
1988 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], -1LL << 63, l2);
1989 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[1], -1LL, l2);
1991 tcg_gen_movi_tl(cpu_T[1], 0);
1992 gen_store_LO(cpu_T[0], 0);
1993 gen_store_HI(cpu_T[1], 0);
1998 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
1999 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2001 tcg_gen_div_i64(r_tmp1, cpu_T[0], cpu_T[1]);
2002 tcg_gen_rem_i64(r_tmp2, cpu_T[0], cpu_T[1]);
2003 gen_store_LO(r_tmp1, 0);
2004 gen_store_HI(r_tmp2, 0);
2005 tcg_temp_free(r_tmp1);
2006 tcg_temp_free(r_tmp2);
2015 int l1 = gen_new_label();
2017 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, l1);
2019 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2020 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2022 tcg_gen_divu_i64(r_tmp1, cpu_T[0], cpu_T[1]);
2023 tcg_gen_remu_i64(r_tmp2, cpu_T[0], cpu_T[1]);
2024 tcg_temp_free(r_tmp1);
2025 tcg_temp_free(r_tmp2);
2026 gen_store_LO(r_tmp1, 0);
2027 gen_store_HI(r_tmp2, 0);
2034 tcg_gen_helper_0_0(do_dmult);
2038 tcg_gen_helper_0_0(do_dmultu);
2044 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2045 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2046 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2048 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2049 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
2050 tcg_gen_ext_tl_i64(r_tmp1, cpu_T[0]);
2051 tcg_gen_ext_tl_i64(r_tmp2, cpu_T[1]);
2052 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2053 gen_load_LO(cpu_T[0], 0);
2054 gen_load_HI(cpu_T[1], 0);
2055 tcg_gen_extu_tl_i64(r_tmp2, cpu_T[0]);
2056 tcg_gen_extu_tl_i64(r_tmp3, cpu_T[1]);
2057 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2058 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2059 tcg_temp_free(r_tmp3);
2060 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2061 tcg_temp_free(r_tmp2);
2062 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp1);
2063 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2064 tcg_gen_trunc_i64_tl(cpu_T[1], r_tmp1);
2065 tcg_temp_free(r_tmp1);
2066 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2067 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
2068 gen_store_LO(cpu_T[0], 0);
2069 gen_store_HI(cpu_T[1], 0);
2075 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2076 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2077 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2079 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
2080 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
2081 tcg_gen_extu_tl_i64(r_tmp1, cpu_T[0]);
2082 tcg_gen_extu_tl_i64(r_tmp2, cpu_T[1]);
2083 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2084 gen_load_LO(cpu_T[0], 0);
2085 gen_load_HI(cpu_T[1], 0);
2086 tcg_gen_extu_tl_i64(r_tmp2, cpu_T[0]);
2087 tcg_gen_extu_tl_i64(r_tmp3, cpu_T[1]);
2088 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2089 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2090 tcg_temp_free(r_tmp3);
2091 tcg_gen_add_i64(r_tmp1, r_tmp1, r_tmp2);
2092 tcg_temp_free(r_tmp2);
2093 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp1);
2094 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2095 tcg_gen_trunc_i64_tl(cpu_T[1], r_tmp1);
2096 tcg_temp_free(r_tmp1);
2097 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2098 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
2099 gen_store_LO(cpu_T[0], 0);
2100 gen_store_HI(cpu_T[1], 0);
2106 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2107 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2108 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2110 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2111 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
2112 tcg_gen_ext_tl_i64(r_tmp1, cpu_T[0]);
2113 tcg_gen_ext_tl_i64(r_tmp2, cpu_T[1]);
2114 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2115 gen_load_LO(cpu_T[0], 0);
2116 gen_load_HI(cpu_T[1], 0);
2117 tcg_gen_extu_tl_i64(r_tmp2, cpu_T[0]);
2118 tcg_gen_extu_tl_i64(r_tmp3, cpu_T[1]);
2119 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2120 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2121 tcg_temp_free(r_tmp3);
2122 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2123 tcg_temp_free(r_tmp2);
2124 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp1);
2125 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2126 tcg_gen_trunc_i64_tl(cpu_T[1], r_tmp1);
2127 tcg_temp_free(r_tmp1);
2128 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2129 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
2130 gen_store_LO(cpu_T[0], 0);
2131 gen_store_HI(cpu_T[1], 0);
2137 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I64);
2138 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I64);
2139 TCGv r_tmp3 = tcg_temp_new(TCG_TYPE_I64);
2141 tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]);
2142 tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]);
2143 tcg_gen_extu_tl_i64(r_tmp1, cpu_T[0]);
2144 tcg_gen_extu_tl_i64(r_tmp2, cpu_T[1]);
2145 tcg_gen_mul_i64(r_tmp1, r_tmp1, r_tmp2);
2146 gen_load_LO(cpu_T[0], 0);
2147 gen_load_HI(cpu_T[1], 0);
2148 tcg_gen_extu_tl_i64(r_tmp2, cpu_T[0]);
2149 tcg_gen_extu_tl_i64(r_tmp3, cpu_T[1]);
2150 tcg_gen_shli_i64(r_tmp3, r_tmp3, 32);
2151 tcg_gen_or_i64(r_tmp2, r_tmp2, r_tmp3);
2152 tcg_temp_free(r_tmp3);
2153 tcg_gen_sub_i64(r_tmp1, r_tmp1, r_tmp2);
2154 tcg_temp_free(r_tmp2);
2155 tcg_gen_trunc_i64_tl(cpu_T[0], r_tmp1);
2156 tcg_gen_shri_i64(r_tmp1, r_tmp1, 32);
2157 tcg_gen_trunc_i64_tl(cpu_T[1], r_tmp1);
2158 tcg_temp_free(r_tmp1);
2159 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2160 tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]);
2161 gen_store_LO(cpu_T[0], 0);
2162 gen_store_HI(cpu_T[1], 0);
2168 generate_exception(ctx, EXCP_RI);
2171 MIPS_DEBUG("%s %s %s", opn, regnames[rs], regnames[rt]);
2174 static void gen_mul_vr54xx (DisasContext *ctx, uint32_t opc,
2175 int rd, int rs, int rt)
2177 const char *opn = "mul vr54xx";
2179 gen_load_gpr(cpu_T[0], rs);
2180 gen_load_gpr(cpu_T[1], rt);
2183 case OPC_VR54XX_MULS:
2184 tcg_gen_helper_0_0(do_muls);
2187 case OPC_VR54XX_MULSU:
2188 tcg_gen_helper_0_0(do_mulsu);
2191 case OPC_VR54XX_MACC:
2192 tcg_gen_helper_0_0(do_macc);
2195 case OPC_VR54XX_MACCU:
2196 tcg_gen_helper_0_0(do_maccu);
2199 case OPC_VR54XX_MSAC:
2200 tcg_gen_helper_0_0(do_msac);
2203 case OPC_VR54XX_MSACU:
2204 tcg_gen_helper_0_0(do_msacu);
2207 case OPC_VR54XX_MULHI:
2208 tcg_gen_helper_0_0(do_mulhi);
2211 case OPC_VR54XX_MULHIU:
2212 tcg_gen_helper_0_0(do_mulhiu);
2215 case OPC_VR54XX_MULSHI:
2216 tcg_gen_helper_0_0(do_mulshi);
2219 case OPC_VR54XX_MULSHIU:
2220 tcg_gen_helper_0_0(do_mulshiu);
2223 case OPC_VR54XX_MACCHI:
2224 tcg_gen_helper_0_0(do_macchi);
2227 case OPC_VR54XX_MACCHIU:
2228 tcg_gen_helper_0_0(do_macchiu);
2231 case OPC_VR54XX_MSACHI:
2232 tcg_gen_helper_0_0(do_msachi);
2235 case OPC_VR54XX_MSACHIU:
2236 tcg_gen_helper_0_0(do_msachiu);
2240 MIPS_INVAL("mul vr54xx");
2241 generate_exception(ctx, EXCP_RI);
2244 gen_store_gpr(cpu_T[0], rd);
2245 MIPS_DEBUG("%s %s, %s, %s", opn, regnames[rd], regnames[rs], regnames[rt]);
2248 static void gen_cl (DisasContext *ctx, uint32_t opc,
2251 const char *opn = "CLx";
2257 gen_load_gpr(cpu_T[0], rs);
2260 tcg_gen_helper_0_0(do_clo);
2264 tcg_gen_helper_0_0(do_clz);
2267 #if defined(TARGET_MIPS64)
2269 tcg_gen_helper_0_0(do_dclo);
2273 tcg_gen_helper_0_0(do_dclz);
2279 generate_exception(ctx, EXCP_RI);
2282 gen_store_gpr(cpu_T[0], rd);
2283 MIPS_DEBUG("%s %s, %s", opn, regnames[rd], regnames[rs]);
2287 static void gen_trap (DisasContext *ctx, uint32_t opc,
2288 int rs, int rt, int16_t imm)
2293 /* Load needed operands */
2301 /* Compare two registers */
2303 gen_load_gpr(cpu_T[0], rs);
2304 gen_load_gpr(cpu_T[1], rt);
2314 /* Compare register to immediate */
2315 if (rs != 0 || imm != 0) {
2316 gen_load_gpr(cpu_T[0], rs);
2317 tcg_gen_movi_tl(cpu_T[1], (int32_t)imm);
2324 case OPC_TEQ: /* rs == rs */
2325 case OPC_TEQI: /* r0 == 0 */
2326 case OPC_TGE: /* rs >= rs */
2327 case OPC_TGEI: /* r0 >= 0 */
2328 case OPC_TGEU: /* rs >= rs unsigned */
2329 case OPC_TGEIU: /* r0 >= 0 unsigned */
2331 tcg_gen_movi_tl(cpu_T[0], 1);
2333 case OPC_TLT: /* rs < rs */
2334 case OPC_TLTI: /* r0 < 0 */
2335 case OPC_TLTU: /* rs < rs unsigned */
2336 case OPC_TLTIU: /* r0 < 0 unsigned */
2337 case OPC_TNE: /* rs != rs */
2338 case OPC_TNEI: /* r0 != 0 */
2339 /* Never trap: treat as NOP. */
2343 generate_exception(ctx, EXCP_RI);
2374 generate_exception(ctx, EXCP_RI);
2378 save_cpu_state(ctx, 1);
2380 int l1 = gen_new_label();
2382 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
2383 tcg_gen_helper_0_1i(do_raise_exception, EXCP_TRAP);
2386 ctx->bstate = BS_STOP;
2389 static always_inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
2391 TranslationBlock *tb;
2393 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2396 tcg_gen_exit_tb((long)tb + n);
2403 /* Branches (before delay slot) */
2404 static void gen_compute_branch (DisasContext *ctx, uint32_t opc,
2405 int rs, int rt, int32_t offset)
2407 target_ulong btarget = -1;
2411 if (ctx->hflags & MIPS_HFLAG_BMASK) {
2412 #ifdef MIPS_DEBUG_DISAS
2413 if (loglevel & CPU_LOG_TB_IN_ASM) {
2415 "Branch in delay slot at PC 0x" TARGET_FMT_lx "\n",
2419 generate_exception(ctx, EXCP_RI);
2423 /* Load needed operands */
2429 /* Compare two registers */
2431 gen_load_gpr(cpu_T[0], rs);
2432 gen_load_gpr(cpu_T[1], rt);
2435 btarget = ctx->pc + 4 + offset;
2449 /* Compare to zero */
2451 gen_load_gpr(cpu_T[0], rs);
2454 btarget = ctx->pc + 4 + offset;
2458 /* Jump to immediate */
2459 btarget = ((ctx->pc + 4) & (int32_t)0xF0000000) | (uint32_t)offset;
2463 /* Jump to register */
2464 if (offset != 0 && offset != 16) {
2465 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2466 others are reserved. */
2467 MIPS_INVAL("jump hint");
2468 generate_exception(ctx, EXCP_RI);
2471 gen_save_breg_target(rs);
2474 MIPS_INVAL("branch/jump");
2475 generate_exception(ctx, EXCP_RI);
2479 /* No condition to be computed */
2481 case OPC_BEQ: /* rx == rx */
2482 case OPC_BEQL: /* rx == rx likely */
2483 case OPC_BGEZ: /* 0 >= 0 */
2484 case OPC_BGEZL: /* 0 >= 0 likely */
2485 case OPC_BLEZ: /* 0 <= 0 */
2486 case OPC_BLEZL: /* 0 <= 0 likely */
2488 ctx->hflags |= MIPS_HFLAG_B;
2489 MIPS_DEBUG("balways");
2491 case OPC_BGEZAL: /* 0 >= 0 */
2492 case OPC_BGEZALL: /* 0 >= 0 likely */
2493 /* Always take and link */
2495 ctx->hflags |= MIPS_HFLAG_B;
2496 MIPS_DEBUG("balways and link");
2498 case OPC_BNE: /* rx != rx */
2499 case OPC_BGTZ: /* 0 > 0 */
2500 case OPC_BLTZ: /* 0 < 0 */
2502 MIPS_DEBUG("bnever (NOP)");
2504 case OPC_BLTZAL: /* 0 < 0 */
2505 tcg_gen_movi_tl(cpu_T[0], ctx->pc + 8);
2506 gen_store_gpr(cpu_T[0], 31);
2507 MIPS_DEBUG("bnever and link");
2509 case OPC_BLTZALL: /* 0 < 0 likely */
2510 tcg_gen_movi_tl(cpu_T[0], ctx->pc + 8);
2511 gen_store_gpr(cpu_T[0], 31);
2512 /* Skip the instruction in the delay slot */
2513 MIPS_DEBUG("bnever, link and skip");
2516 case OPC_BNEL: /* rx != rx likely */
2517 case OPC_BGTZL: /* 0 > 0 likely */
2518 case OPC_BLTZL: /* 0 < 0 likely */
2519 /* Skip the instruction in the delay slot */
2520 MIPS_DEBUG("bnever and skip");
2524 ctx->hflags |= MIPS_HFLAG_B;
2525 MIPS_DEBUG("j " TARGET_FMT_lx, btarget);
2529 ctx->hflags |= MIPS_HFLAG_B;
2530 MIPS_DEBUG("jal " TARGET_FMT_lx, btarget);
2533 ctx->hflags |= MIPS_HFLAG_BR;
2534 MIPS_DEBUG("jr %s", regnames[rs]);
2538 ctx->hflags |= MIPS_HFLAG_BR;
2539 MIPS_DEBUG("jalr %s, %s", regnames[rt], regnames[rs]);
2542 MIPS_INVAL("branch/jump");
2543 generate_exception(ctx, EXCP_RI);
2550 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx,
2551 regnames[rs], regnames[rt], btarget);
2555 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx,
2556 regnames[rs], regnames[rt], btarget);
2560 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx,
2561 regnames[rs], regnames[rt], btarget);
2565 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx,
2566 regnames[rs], regnames[rt], btarget);
2570 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2574 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2578 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2584 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2588 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2592 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2596 MIPS_DEBUG("blez %s, " TARGET_FMT_lx, regnames[rs], btarget);
2600 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2604 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx, regnames[rs], btarget);
2608 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx, regnames[rs], btarget);
2613 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx, regnames[rs], btarget);
2615 ctx->hflags |= MIPS_HFLAG_BC;
2616 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
2621 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx, regnames[rs], btarget);
2623 ctx->hflags |= MIPS_HFLAG_BL;
2624 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
2627 MIPS_INVAL("conditional branch/jump");
2628 generate_exception(ctx, EXCP_RI);
2632 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx,
2633 blink, ctx->hflags, btarget);
2635 ctx->btarget = btarget;
2637 tcg_gen_movi_tl(cpu_T[0], ctx->pc + 8);
2638 gen_store_gpr(cpu_T[0], blink);
2642 /* special3 bitfield operations */
2643 static void gen_bitops (DisasContext *ctx, uint32_t opc, int rt,
2644 int rs, int lsb, int msb)
2646 gen_load_gpr(cpu_T[1], rs);
2651 tcg_gen_helper_0_2ii(do_ext, lsb, msb + 1);
2653 #if defined(TARGET_MIPS64)
2657 tcg_gen_helper_0_2ii(do_dext, lsb, msb + 1 + 32);
2662 tcg_gen_helper_0_2ii(do_dext, lsb + 32, msb + 1);
2667 tcg_gen_helper_0_2ii(do_dext, lsb, msb + 1);
2673 gen_load_gpr(cpu_T[0], rt);
2674 tcg_gen_helper_0_2ii(do_ins, lsb, msb - lsb + 1);
2676 #if defined(TARGET_MIPS64)
2680 gen_load_gpr(cpu_T[0], rt);
2681 tcg_gen_helper_0_2ii(do_dins, lsb, msb - lsb + 1 + 32);
2686 gen_load_gpr(cpu_T[0], rt);
2687 tcg_gen_helper_0_2ii(do_dins, lsb + 32, msb - lsb + 1);
2692 gen_load_gpr(cpu_T[0], rt);
2693 tcg_gen_helper_0_2ii(do_dins, lsb, msb - lsb + 1);
2698 MIPS_INVAL("bitops");
2699 generate_exception(ctx, EXCP_RI);
2702 gen_store_gpr(cpu_T[0], rt);
2705 /* CP0 (MMU and control) */
2706 #ifndef CONFIG_USER_ONLY
2707 static inline void gen_mfc0_load32 (TCGv t, target_ulong off)
2709 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2711 tcg_gen_ld_i32(r_tmp, cpu_env, off);
2712 tcg_gen_ext_i32_tl(t, r_tmp);
2713 tcg_temp_free(r_tmp);
2716 static inline void gen_mfc0_load64 (TCGv t, target_ulong off)
2718 tcg_gen_ld_tl(t, cpu_env, off);
2719 tcg_gen_ext32s_tl(t, t);
2722 static inline void gen_mtc0_store32 (TCGv t, target_ulong off)
2724 TCGv r_tmp = tcg_temp_new(TCG_TYPE_I32);
2726 tcg_gen_trunc_tl_i32(r_tmp, t);
2727 tcg_gen_st_i32(r_tmp, cpu_env, off);
2728 tcg_temp_free(r_tmp);
2731 static inline void gen_mtc0_store64 (TCGv t, target_ulong off)
2733 tcg_gen_ext32s_tl(t, t);
2734 tcg_gen_st_tl(t, cpu_env, off);
2737 static void gen_mfc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
2739 const char *rn = "invalid";
2742 check_insn(env, ctx, ISA_MIPS32);
2748 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Index));
2752 check_insn(env, ctx, ASE_MT);
2753 tcg_gen_helper_0_0(do_mfc0_mvpcontrol);
2757 check_insn(env, ctx, ASE_MT);
2758 tcg_gen_helper_0_0(do_mfc0_mvpconf0);
2762 check_insn(env, ctx, ASE_MT);
2763 tcg_gen_helper_0_0(do_mfc0_mvpconf1);
2773 tcg_gen_helper_0_0(do_mfc0_random);
2777 check_insn(env, ctx, ASE_MT);
2778 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEControl));
2782 check_insn(env, ctx, ASE_MT);
2783 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEConf0));
2787 check_insn(env, ctx, ASE_MT);
2788 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEConf1));
2792 check_insn(env, ctx, ASE_MT);
2793 gen_mfc0_load64(cpu_T[0], offsetof(CPUState, CP0_YQMask));
2797 check_insn(env, ctx, ASE_MT);
2798 gen_mfc0_load64(cpu_T[0], offsetof(CPUState, CP0_VPESchedule));
2802 check_insn(env, ctx, ASE_MT);
2803 gen_mfc0_load64(cpu_T[0], offsetof(CPUState, CP0_VPEScheFBack));
2804 rn = "VPEScheFBack";
2807 check_insn(env, ctx, ASE_MT);
2808 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEOpt));
2818 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo0));
2819 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2823 check_insn(env, ctx, ASE_MT);
2824 tcg_gen_helper_0_0(do_mfc0_tcstatus);
2828 check_insn(env, ctx, ASE_MT);
2829 tcg_gen_helper_0_0(do_mfc0_tcbind);
2833 check_insn(env, ctx, ASE_MT);
2834 tcg_gen_helper_0_0(do_mfc0_tcrestart);
2838 check_insn(env, ctx, ASE_MT);
2839 tcg_gen_helper_0_0(do_mfc0_tchalt);
2843 check_insn(env, ctx, ASE_MT);
2844 tcg_gen_helper_0_0(do_mfc0_tccontext);
2848 check_insn(env, ctx, ASE_MT);
2849 tcg_gen_helper_0_0(do_mfc0_tcschedule);
2853 check_insn(env, ctx, ASE_MT);
2854 tcg_gen_helper_0_0(do_mfc0_tcschefback);
2864 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo1));
2865 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2875 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_Context));
2876 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2880 // tcg_gen_helper_0_0(do_mfc0_contextconfig); /* SmartMIPS ASE */
2881 rn = "ContextConfig";
2890 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_PageMask));
2894 check_insn(env, ctx, ISA_MIPS32R2);
2895 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_PageGrain));
2905 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Wired));
2909 check_insn(env, ctx, ISA_MIPS32R2);
2910 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf0));
2914 check_insn(env, ctx, ISA_MIPS32R2);
2915 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf1));
2919 check_insn(env, ctx, ISA_MIPS32R2);
2920 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf2));
2924 check_insn(env, ctx, ISA_MIPS32R2);
2925 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf3));
2929 check_insn(env, ctx, ISA_MIPS32R2);
2930 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf4));
2940 check_insn(env, ctx, ISA_MIPS32R2);
2941 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_HWREna));
2951 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr));
2952 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2962 tcg_gen_helper_0_0(do_mfc0_count);
2965 /* 6,7 are implementation dependent */
2973 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryHi));
2974 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
2984 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Compare));
2987 /* 6,7 are implementation dependent */
2995 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Status));
2999 check_insn(env, ctx, ISA_MIPS32R2);
3000 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_IntCtl));
3004 check_insn(env, ctx, ISA_MIPS32R2);
3005 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSCtl));
3009 check_insn(env, ctx, ISA_MIPS32R2);
3010 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSMap));
3020 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Cause));
3030 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EPC));
3031 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
3041 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_PRid));
3045 check_insn(env, ctx, ISA_MIPS32R2);
3046 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_EBase));
3056 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config0));
3060 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config1));
3064 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config2));
3068 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config3));
3071 /* 4,5 are reserved */
3072 /* 6,7 are implementation dependent */
3074 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config6));
3078 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config7));
3088 tcg_gen_helper_0_0(do_mfc0_lladdr);
3098 tcg_gen_helper_0_1i(do_mfc0_watchlo, sel);
3108 tcg_gen_helper_0_1i(do_mfc0_watchhi, sel);
3118 #if defined(TARGET_MIPS64)
3119 check_insn(env, ctx, ISA_MIPS3);
3120 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_XContext));
3121 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
3130 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3133 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Framemask));
3142 rn = "'Diagnostic"; /* implementation dependent */
3147 tcg_gen_helper_0_0(do_mfc0_debug); /* EJTAG support */
3151 // tcg_gen_helper_0_0(do_mfc0_tracecontrol); /* PDtrace support */
3152 rn = "TraceControl";
3155 // tcg_gen_helper_0_0(do_mfc0_tracecontrol2); /* PDtrace support */
3156 rn = "TraceControl2";
3159 // tcg_gen_helper_0_0(do_mfc0_usertracedata); /* PDtrace support */
3160 rn = "UserTraceData";
3163 // tcg_gen_helper_0_0(do_mfc0_debug); /* PDtrace support */
3174 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_DEPC));
3175 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
3185 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Performance0));
3186 rn = "Performance0";
3189 // tcg_gen_helper_0_0(do_mfc0_performance1);
3190 rn = "Performance1";
3193 // tcg_gen_helper_0_0(do_mfc0_performance2);
3194 rn = "Performance2";
3197 // tcg_gen_helper_0_0(do_mfc0_performance3);
3198 rn = "Performance3";
3201 // tcg_gen_helper_0_0(do_mfc0_performance4);
3202 rn = "Performance4";
3205 // tcg_gen_helper_0_0(do_mfc0_performance5);
3206 rn = "Performance5";
3209 // tcg_gen_helper_0_0(do_mfc0_performance6);
3210 rn = "Performance6";
3213 // tcg_gen_helper_0_0(do_mfc0_performance7);
3214 rn = "Performance7";
3239 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_TagLo));
3246 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_DataLo));
3259 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_TagHi));
3266 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_DataHi));
3276 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_ErrorEPC));
3277 tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]);
3288 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_DESAVE));
3298 #if defined MIPS_DEBUG_DISAS
3299 if (loglevel & CPU_LOG_TB_IN_ASM) {
3300 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3307 #if defined MIPS_DEBUG_DISAS
3308 if (loglevel & CPU_LOG_TB_IN_ASM) {
3309 fprintf(logfile, "mfc0 %s (reg %d sel %d)\n",
3313 generate_exception(ctx, EXCP_RI);
3316 static void gen_mtc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
3318 const char *rn = "invalid";
3321 check_insn(env, ctx, ISA_MIPS32);
3327 tcg_gen_helper_0_0(do_mtc0_index);
3331 check_insn(env, ctx, ASE_MT);
3332 tcg_gen_helper_0_0(do_mtc0_mvpcontrol);
3336 check_insn(env, ctx, ASE_MT);
3341 check_insn(env, ctx, ASE_MT);
3356 check_insn(env, ctx, ASE_MT);
3357 tcg_gen_helper_0_0(do_mtc0_vpecontrol);
3361 check_insn(env, ctx, ASE_MT);
3362 tcg_gen_helper_0_0(do_mtc0_vpeconf0);
3366 check_insn(env, ctx, ASE_MT);
3367 tcg_gen_helper_0_0(do_mtc0_vpeconf1);
3371 check_insn(env, ctx, ASE_MT);
3372 tcg_gen_helper_0_0(do_mtc0_yqmask);
3376 check_insn(env, ctx, ASE_MT);
3377 gen_mtc0_store64(cpu_T[0], offsetof(CPUState, CP0_VPESchedule));
3381 check_insn(env, ctx, ASE_MT);
3382 gen_mtc0_store64(cpu_T[0], offsetof(CPUState, CP0_VPEScheFBack));
3383 rn = "VPEScheFBack";
3386 check_insn(env, ctx, ASE_MT);
3387 tcg_gen_helper_0_0(do_mtc0_vpeopt);
3397 tcg_gen_helper_0_0(do_mtc0_entrylo0);
3401 check_insn(env, ctx, ASE_MT);
3402 tcg_gen_helper_0_0(do_mtc0_tcstatus);
3406 check_insn(env, ctx, ASE_MT);
3407 tcg_gen_helper_0_0(do_mtc0_tcbind);
3411 check_insn(env, ctx, ASE_MT);
3412 tcg_gen_helper_0_0(do_mtc0_tcrestart);
3416 check_insn(env, ctx, ASE_MT);
3417 tcg_gen_helper_0_0(do_mtc0_tchalt);
3421 check_insn(env, ctx, ASE_MT);
3422 tcg_gen_helper_0_0(do_mtc0_tccontext);
3426 check_insn(env, ctx, ASE_MT);
3427 tcg_gen_helper_0_0(do_mtc0_tcschedule);
3431 check_insn(env, ctx, ASE_MT);
3432 tcg_gen_helper_0_0(do_mtc0_tcschefback);
3442 tcg_gen_helper_0_0(do_mtc0_entrylo1);
3452 tcg_gen_helper_0_0(do_mtc0_context);
3456 // tcg_gen_helper_0_0(do_mtc0_contextconfig); /* SmartMIPS ASE */
3457 rn = "ContextConfig";
3466 tcg_gen_helper_0_0(do_mtc0_pagemask);
3470 check_insn(env, ctx, ISA_MIPS32R2);
3471 tcg_gen_helper_0_0(do_mtc0_pagegrain);
3481 tcg_gen_helper_0_0(do_mtc0_wired);
3485 check_insn(env, ctx, ISA_MIPS32R2);
3486 tcg_gen_helper_0_0(do_mtc0_srsconf0);
3490 check_insn(env, ctx, ISA_MIPS32R2);
3491 tcg_gen_helper_0_0(do_mtc0_srsconf1);
3495 check_insn(env, ctx, ISA_MIPS32R2);
3496 tcg_gen_helper_0_0(do_mtc0_srsconf2);
3500 check_insn(env, ctx, ISA_MIPS32R2);
3501 tcg_gen_helper_0_0(do_mtc0_srsconf3);
3505 check_insn(env, ctx, ISA_MIPS32R2);
3506 tcg_gen_helper_0_0(do_mtc0_srsconf4);
3516 check_insn(env, ctx, ISA_MIPS32R2);
3517 tcg_gen_helper_0_0(do_mtc0_hwrena);
3531 tcg_gen_helper_0_0(do_mtc0_count);
3534 /* 6,7 are implementation dependent */
3538 /* Stop translation as we may have switched the execution mode */
3539 ctx->bstate = BS_STOP;
3544 tcg_gen_helper_0_0(do_mtc0_entryhi);
3554 tcg_gen_helper_0_0(do_mtc0_compare);
3557 /* 6,7 are implementation dependent */
3561 /* Stop translation as we may have switched the execution mode */
3562 ctx->bstate = BS_STOP;
3567 tcg_gen_helper_0_0(do_mtc0_status);
3568 /* BS_STOP isn't good enough here, hflags may have changed. */
3569 gen_save_pc(ctx->pc + 4);
3570 ctx->bstate = BS_EXCP;
3574 check_insn(env, ctx, ISA_MIPS32R2);
3575 tcg_gen_helper_0_0(do_mtc0_intctl);
3576 /* Stop translation as we may have switched the execution mode */
3577 ctx->bstate = BS_STOP;
3581 check_insn(env, ctx, ISA_MIPS32R2);
3582 tcg_gen_helper_0_0(do_mtc0_srsctl);
3583 /* Stop translation as we may have switched the execution mode */
3584 ctx->bstate = BS_STOP;
3588 check_insn(env, ctx, ISA_MIPS32R2);
3589 gen_mtc0_store32(cpu_T[0], offsetof(CPUState, CP0_SRSMap));
3590 /* Stop translation as we may have switched the execution mode */
3591 ctx->bstate = BS_STOP;
3601 tcg_gen_helper_0_0(do_mtc0_cause);
3607 /* Stop translation as we may have switched the execution mode */
3608 ctx->bstate = BS_STOP;
3613 gen_mtc0_store64(cpu_T[0], offsetof(CPUState, CP0_EPC));
3627 check_insn(env, ctx, ISA_MIPS32R2);
3628 tcg_gen_helper_0_0(do_mtc0_ebase);
3638 tcg_gen_helper_0_0(do_mtc0_config0);
3640 /* Stop translation as we may have switched the execution mode */
3641 ctx->bstate = BS_STOP;
3644 /* ignored, read only */
3648 tcg_gen_helper_0_0(do_mtc0_config2);
3650 /* Stop translation as we may have switched the execution mode */
3651 ctx->bstate = BS_STOP;
3654 /* ignored, read only */
3657 /* 4,5 are reserved */
3658 /* 6,7 are implementation dependent */
3668 rn = "Invalid config selector";
3685 tcg_gen_helper_0_1i(do_mtc0_watchlo, sel);
3695 tcg_gen_helper_0_1i(do_mtc0_watchhi, sel);
3705 #if defined(TARGET_MIPS64)
3706 check_insn(env, ctx, ISA_MIPS3);
3707 tcg_gen_helper_0_0(do_mtc0_xcontext);
3716 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3719 tcg_gen_helper_0_0(do_mtc0_framemask);
3728 rn = "Diagnostic"; /* implementation dependent */
3733 tcg_gen_helper_0_0(do_mtc0_debug); /* EJTAG support */
3734 /* BS_STOP isn't good enough here, hflags may have changed. */
3735 gen_save_pc(ctx->pc + 4);
3736 ctx->bstate = BS_EXCP;
3740 // tcg_gen_helper_0_0(do_mtc0_tracecontrol); /* PDtrace support */
3741 rn = "TraceControl";
3742 /* Stop translation as we may have switched the execution mode */
3743 ctx->bstate = BS_STOP;
3746 // tcg_gen_helper_0_0(do_mtc0_tracecontrol2); /* PDtrace support */
3747 rn = "TraceControl2";
3748 /* Stop translation as we may have switched the execution mode */
3749 ctx->bstate = BS_STOP;
3752 /* Stop translation as we may have switched the execution mode */
3753 ctx->bstate = BS_STOP;
3754 // tcg_gen_helper_0_0(do_mtc0_usertracedata); /* PDtrace support */
3755 rn = "UserTraceData";
3756 /* Stop translation as we may have switched the execution mode */
3757 ctx->bstate = BS_STOP;
3760 // tcg_gen_helper_0_0(do_mtc0_debug); /* PDtrace support */
3761 /* Stop translation as we may have switched the execution mode */
3762 ctx->bstate = BS_STOP;
3773 gen_mtc0_store64(cpu_T[0], offsetof(CPUState, CP0_DEPC));
3783 tcg_gen_helper_0_0(do_mtc0_performance0);
3784 rn = "Performance0";
3787 // tcg_gen_helper_0_0(do_mtc0_performance1);
3788 rn = "Performance1";
3791 // tcg_gen_helper_0_0(do_mtc0_performance2);
3792 rn = "Performance2";
3795 // tcg_gen_helper_0_0(do_mtc0_performance3);
3796 rn = "Performance3";
3799 // tcg_gen_helper_0_0(do_mtc0_performance4);
3800 rn = "Performance4";
3803 // tcg_gen_helper_0_0(do_mtc0_performance5);
3804 rn = "Performance5";
3807 // tcg_gen_helper_0_0(do_mtc0_performance6);
3808 rn = "Performance6";
3811 // tcg_gen_helper_0_0(do_mtc0_performance7);
3812 rn = "Performance7";
3838 tcg_gen_helper_0_0(do_mtc0_taglo);
3845 tcg_gen_helper_0_0(do_mtc0_datalo);
3858 tcg_gen_helper_0_0(do_mtc0_taghi);
3865 tcg_gen_helper_0_0(do_mtc0_datahi);
3876 gen_mtc0_store64(cpu_T[0], offsetof(CPUState, CP0_ErrorEPC));
3887 gen_mtc0_store32(cpu_T[0], offsetof(CPUState, CP0_DESAVE));
3893 /* Stop translation as we may have switched the execution mode */
3894 ctx->bstate = BS_STOP;
3899 #if defined MIPS_DEBUG_DISAS
3900 if (loglevel & CPU_LOG_TB_IN_ASM) {
3901 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3908 #if defined MIPS_DEBUG_DISAS
3909 if (loglevel & CPU_LOG_TB_IN_ASM) {
3910 fprintf(logfile, "mtc0 %s (reg %d sel %d)\n",
3914 generate_exception(ctx, EXCP_RI);
3917 #if defined(TARGET_MIPS64)
3918 static void gen_dmfc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
3920 const char *rn = "invalid";
3923 check_insn(env, ctx, ISA_MIPS64);
3929 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Index));
3933 check_insn(env, ctx, ASE_MT);
3934 tcg_gen_helper_0_0(do_mfc0_mvpcontrol);
3938 check_insn(env, ctx, ASE_MT);
3939 tcg_gen_helper_0_0(do_mfc0_mvpconf0);
3943 check_insn(env, ctx, ASE_MT);
3944 tcg_gen_helper_0_0(do_mfc0_mvpconf1);
3954 tcg_gen_helper_0_0(do_mfc0_random);
3958 check_insn(env, ctx, ASE_MT);
3959 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEControl));
3963 check_insn(env, ctx, ASE_MT);
3964 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEConf0));
3968 check_insn(env, ctx, ASE_MT);
3969 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEConf1));
3973 check_insn(env, ctx, ASE_MT);
3974 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_YQMask));
3978 check_insn(env, ctx, ASE_MT);
3979 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_VPESchedule));
3983 check_insn(env, ctx, ASE_MT);
3984 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
3985 rn = "VPEScheFBack";
3988 check_insn(env, ctx, ASE_MT);
3989 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_VPEOpt));
3999 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo0));
4003 check_insn(env, ctx, ASE_MT);
4004 tcg_gen_helper_0_0(do_mfc0_tcstatus);
4008 check_insn(env, ctx, ASE_MT);
4009 tcg_gen_helper_0_0(do_mfc0_tcbind);
4013 check_insn(env, ctx, ASE_MT);
4014 tcg_gen_helper_0_0(do_dmfc0_tcrestart);
4018 check_insn(env, ctx, ASE_MT);
4019 tcg_gen_helper_0_0(do_dmfc0_tchalt);
4023 check_insn(env, ctx, ASE_MT);
4024 tcg_gen_helper_0_0(do_dmfc0_tccontext);
4028 check_insn(env, ctx, ASE_MT);
4029 tcg_gen_helper_0_0(do_dmfc0_tcschedule);
4033 check_insn(env, ctx, ASE_MT);
4034 tcg_gen_helper_0_0(do_dmfc0_tcschefback);
4044 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryLo1));
4054 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_Context));
4058 // tcg_gen_helper_0_0(do_dmfc0_contextconfig); /* SmartMIPS ASE */
4059 rn = "ContextConfig";
4068 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_PageMask));
4072 check_insn(env, ctx, ISA_MIPS32R2);
4073 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_PageGrain));
4083 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Wired));
4087 check_insn(env, ctx, ISA_MIPS32R2);
4088 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf0));
4092 check_insn(env, ctx, ISA_MIPS32R2);
4093 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf1));
4097 check_insn(env, ctx, ISA_MIPS32R2);
4098 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf2));
4102 check_insn(env, ctx, ISA_MIPS32R2);
4103 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf3));
4107 check_insn(env, ctx, ISA_MIPS32R2);
4108 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSConf4));
4118 check_insn(env, ctx, ISA_MIPS32R2);
4119 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_HWREna));
4129 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_BadVAddr));
4139 tcg_gen_helper_0_0(do_mfc0_count);
4142 /* 6,7 are implementation dependent */
4150 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EntryHi));
4160 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Compare));
4163 /* 6,7 are implementation dependent */
4171 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Status));
4175 check_insn(env, ctx, ISA_MIPS32R2);
4176 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_IntCtl));
4180 check_insn(env, ctx, ISA_MIPS32R2);
4181 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSCtl));
4185 check_insn(env, ctx, ISA_MIPS32R2);
4186 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_SRSMap));
4196 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Cause));
4206 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EPC));
4216 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_PRid));
4220 check_insn(env, ctx, ISA_MIPS32R2);
4221 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_EBase));
4231 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config0));
4235 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config1));
4239 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config2));
4243 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config3));
4246 /* 6,7 are implementation dependent */
4248 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config6));
4252 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Config7));
4262 tcg_gen_helper_0_0(do_dmfc0_lladdr);
4272 tcg_gen_helper_0_1i(do_dmfc0_watchlo, sel);
4282 tcg_gen_helper_0_1i(do_mfc0_watchhi, sel);
4292 check_insn(env, ctx, ISA_MIPS3);
4293 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_XContext));
4301 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4304 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Framemask));
4313 rn = "'Diagnostic"; /* implementation dependent */
4318 tcg_gen_helper_0_0(do_mfc0_debug); /* EJTAG support */
4322 // tcg_gen_helper_0_0(do_dmfc0_tracecontrol); /* PDtrace support */
4323 rn = "TraceControl";
4326 // tcg_gen_helper_0_0(do_dmfc0_tracecontrol2); /* PDtrace support */
4327 rn = "TraceControl2";
4330 // tcg_gen_helper_0_0(do_dmfc0_usertracedata); /* PDtrace support */
4331 rn = "UserTraceData";
4334 // tcg_gen_helper_0_0(do_dmfc0_debug); /* PDtrace support */
4345 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_DEPC));
4355 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_Performance0));
4356 rn = "Performance0";
4359 // tcg_gen_helper_0_0(do_dmfc0_performance1);
4360 rn = "Performance1";
4363 // tcg_gen_helper_0_0(do_dmfc0_performance2);
4364 rn = "Performance2";
4367 // tcg_gen_helper_0_0(do_dmfc0_performance3);
4368 rn = "Performance3";
4371 // tcg_gen_helper_0_0(do_dmfc0_performance4);
4372 rn = "Performance4";
4375 // tcg_gen_helper_0_0(do_dmfc0_performance5);
4376 rn = "Performance5";
4379 // tcg_gen_helper_0_0(do_dmfc0_performance6);
4380 rn = "Performance6";
4383 // tcg_gen_helper_0_0(do_dmfc0_performance7);
4384 rn = "Performance7";
4409 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_TagLo));
4416 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_DataLo));
4429 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_TagHi));
4436 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_DataHi));
4446 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_ErrorEPC));
4457 gen_mfc0_load32(cpu_T[0], offsetof(CPUState, CP0_DESAVE));
4467 #if defined MIPS_DEBUG_DISAS
4468 if (loglevel & CPU_LOG_TB_IN_ASM) {
4469 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4476 #if defined MIPS_DEBUG_DISAS
4477 if (loglevel & CPU_LOG_TB_IN_ASM) {
4478 fprintf(logfile, "dmfc0 %s (reg %d sel %d)\n",
4482 generate_exception(ctx, EXCP_RI);
4485 static void gen_dmtc0 (CPUState *env, DisasContext *ctx, int reg, int sel)
4487 const char *rn = "invalid";
4490 check_insn(env, ctx, ISA_MIPS64);
4496 tcg_gen_helper_0_0(do_mtc0_index);
4500 check_insn(env, ctx, ASE_MT);
4501 tcg_gen_helper_0_0(do_mtc0_mvpcontrol);
4505 check_insn(env, ctx, ASE_MT);
4510 check_insn(env, ctx, ASE_MT);
4525 check_insn(env, ctx, ASE_MT);
4526 tcg_gen_helper_0_0(do_mtc0_vpecontrol);
4530 check_insn(env, ctx, ASE_MT);
4531 tcg_gen_helper_0_0(do_mtc0_vpeconf0);
4535 check_insn(env, ctx, ASE_MT);
4536 tcg_gen_helper_0_0(do_mtc0_vpeconf1);
4540 check_insn(env, ctx, ASE_MT);
4541 tcg_gen_helper_0_0(do_mtc0_yqmask);
4545 check_insn(env, ctx, ASE_MT);
4546 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_VPESchedule));
4550 check_insn(env, ctx, ASE_MT);
4551 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_VPEScheFBack));
4552 rn = "VPEScheFBack";
4555 check_insn(env, ctx, ASE_MT);
4556 tcg_gen_helper_0_0(do_mtc0_vpeopt);
4566 tcg_gen_helper_0_0(do_mtc0_entrylo0);
4570 check_insn(env, ctx, ASE_MT);
4571 tcg_gen_helper_0_0(do_mtc0_tcstatus);
4575 check_insn(env, ctx, ASE_MT);
4576 tcg_gen_helper_0_0(do_mtc0_tcbind);
4580 check_insn(env, ctx, ASE_MT);
4581 tcg_gen_helper_0_0(do_mtc0_tcrestart);
4585 check_insn(env, ctx, ASE_MT);
4586 tcg_gen_helper_0_0(do_mtc0_tchalt);
4590 check_insn(env, ctx, ASE_MT);
4591 tcg_gen_helper_0_0(do_mtc0_tccontext);
4595 check_insn(env, ctx, ASE_MT);
4596 tcg_gen_helper_0_0(do_mtc0_tcschedule);
4600 check_insn(env, ctx, ASE_MT);
4601 tcg_gen_helper_0_0(do_mtc0_tcschefback);
4611 tcg_gen_helper_0_0(do_mtc0_entrylo1);
4621 tcg_gen_helper_0_0(do_mtc0_context);
4625 // tcg_gen_helper_0_0(do_mtc0_contextconfig); /* SmartMIPS ASE */
4626 rn = "ContextConfig";
4635 tcg_gen_helper_0_0(do_mtc0_pagemask);
4639 check_insn(env, ctx, ISA_MIPS32R2);
4640 tcg_gen_helper_0_0(do_mtc0_pagegrain);
4650 tcg_gen_helper_0_0(do_mtc0_wired);
4654 check_insn(env, ctx, ISA_MIPS32R2);
4655 tcg_gen_helper_0_0(do_mtc0_srsconf0);
4659 check_insn(env, ctx, ISA_MIPS32R2);
4660 tcg_gen_helper_0_0(do_mtc0_srsconf1);
4664 check_insn(env, ctx, ISA_MIPS32R2);
4665 tcg_gen_helper_0_0(do_mtc0_srsconf2);
4669 check_insn(env, ctx, ISA_MIPS32R2);
4670 tcg_gen_helper_0_0(do_mtc0_srsconf3);
4674 check_insn(env, ctx, ISA_MIPS32R2);
4675 tcg_gen_helper_0_0(do_mtc0_srsconf4);
4685 check_insn(env, ctx, ISA_MIPS32R2);
4686 tcg_gen_helper_0_0(do_mtc0_hwrena);
4700 tcg_gen_helper_0_0(do_mtc0_count);
4703 /* 6,7 are implementation dependent */
4707 /* Stop translation as we may have switched the execution mode */
4708 ctx->bstate = BS_STOP;
4713 tcg_gen_helper_0_0(do_mtc0_entryhi);
4723 tcg_gen_helper_0_0(do_mtc0_compare);
4726 /* 6,7 are implementation dependent */
4730 /* Stop translation as we may have switched the execution mode */
4731 ctx->bstate = BS_STOP;
4736 tcg_gen_helper_0_0(do_mtc0_status);
4737 /* BS_STOP isn't good enough here, hflags may have changed. */
4738 gen_save_pc(ctx->pc + 4);
4739 ctx->bstate = BS_EXCP;
4743 check_insn(env, ctx, ISA_MIPS32R2);
4744 tcg_gen_helper_0_0(do_mtc0_intctl);
4745 /* Stop translation as we may have switched the execution mode */
4746 ctx->bstate = BS_STOP;
4750 check_insn(env, ctx, ISA_MIPS32R2);
4751 tcg_gen_helper_0_0(do_mtc0_srsctl);
4752 /* Stop translation as we may have switched the execution mode */
4753 ctx->bstate = BS_STOP;
4757 check_insn(env, ctx, ISA_MIPS32R2);
4758 gen_mtc0_store32(cpu_T[0], offsetof(CPUState, CP0_SRSMap));
4759 /* Stop translation as we may have switched the execution mode */
4760 ctx->bstate = BS_STOP;
4770 tcg_gen_helper_0_0(do_mtc0_cause);
4776 /* Stop translation as we may have switched the execution mode */
4777 ctx->bstate = BS_STOP;
4782 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_EPC));
4796 check_insn(env, ctx, ISA_MIPS32R2);
4797 tcg_gen_helper_0_0(do_mtc0_ebase);
4807 tcg_gen_helper_0_0(do_mtc0_config0);
4809 /* Stop translation as we may have switched the execution mode */
4810 ctx->bstate = BS_STOP;
4817 tcg_gen_helper_0_0(do_mtc0_config2);
4819 /* Stop translation as we may have switched the execution mode */
4820 ctx->bstate = BS_STOP;
4826 /* 6,7 are implementation dependent */
4828 rn = "Invalid config selector";
4845 tcg_gen_helper_0_1i(do_mtc0_watchlo, sel);
4855 tcg_gen_helper_0_1i(do_mtc0_watchhi, sel);
4865 check_insn(env, ctx, ISA_MIPS3);
4866 tcg_gen_helper_0_0(do_mtc0_xcontext);
4874 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4877 tcg_gen_helper_0_0(do_mtc0_framemask);
4886 rn = "Diagnostic"; /* implementation dependent */
4891 tcg_gen_helper_0_0(do_mtc0_debug); /* EJTAG support */
4892 /* BS_STOP isn't good enough here, hflags may have changed. */
4893 gen_save_pc(ctx->pc + 4);
4894 ctx->bstate = BS_EXCP;
4898 // tcg_gen_helper_0_0(do_mtc0_tracecontrol); /* PDtrace support */
4899 /* Stop translation as we may have switched the execution mode */
4900 ctx->bstate = BS_STOP;
4901 rn = "TraceControl";
4904 // tcg_gen_helper_0_0(do_mtc0_tracecontrol2); /* PDtrace support */
4905 /* Stop translation as we may have switched the execution mode */
4906 ctx->bstate = BS_STOP;
4907 rn = "TraceControl2";
4910 // tcg_gen_helper_0_0(do_mtc0_usertracedata); /* PDtrace support */
4911 /* Stop translation as we may have switched the execution mode */
4912 ctx->bstate = BS_STOP;
4913 rn = "UserTraceData";
4916 // tcg_gen_helper_0_0(do_mtc0_debug); /* PDtrace support */
4917 /* Stop translation as we may have switched the execution mode */
4918 ctx->bstate = BS_STOP;
4929 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_DEPC));
4939 tcg_gen_helper_0_0(do_mtc0_performance0);
4940 rn = "Performance0";
4943 // tcg_gen_helper_0_0(do_mtc0_performance1);
4944 rn = "Performance1";
4947 // tcg_gen_helper_0_0(do_mtc0_performance2);
4948 rn = "Performance2";
4951 // tcg_gen_helper_0_0(do_mtc0_performance3);
4952 rn = "Performance3";
4955 // tcg_gen_helper_0_0(do_mtc0_performance4);
4956 rn = "Performance4";
4959 // tcg_gen_helper_0_0(do_mtc0_performance5);
4960 rn = "Performance5";
4963 // tcg_gen_helper_0_0(do_mtc0_performance6);
4964 rn = "Performance6";
4967 // tcg_gen_helper_0_0(do_mtc0_performance7);
4968 rn = "Performance7";
4994 tcg_gen_helper_0_0(do_mtc0_taglo);
5001 tcg_gen_helper_0_0(do_mtc0_datalo);
5014 tcg_gen_helper_0_0(do_mtc0_taghi);
5021 tcg_gen_helper_0_0(do_mtc0_datahi);
5032 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, CP0_ErrorEPC));
5043 gen_mtc0_store32(cpu_T[0], offsetof(CPUState, CP0_DESAVE));
5049 /* Stop translation as we may have switched the execution mode */
5050 ctx->bstate = BS_STOP;
5055 #if defined MIPS_DEBUG_DISAS
5056 if (loglevel & CPU_LOG_TB_IN_ASM) {
5057 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5064 #if defined MIPS_DEBUG_DISAS
5065 if (loglevel & CPU_LOG_TB_IN_ASM) {
5066 fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n",
5070 generate_exception(ctx, EXCP_RI);
5072 #endif /* TARGET_MIPS64 */
5074 static void gen_mftr(CPUState *env, DisasContext *ctx, int rt,
5075 int u, int sel, int h)
5077 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5079 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5080 ((env->CP0_TCBind[other_tc] & (0xf << CP0TCBd_CurVPE)) !=
5081 (env->CP0_TCBind[env->current_tc] & (0xf << CP0TCBd_CurVPE))))
5082 tcg_gen_movi_tl(cpu_T[0], -1);
5083 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5084 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5085 tcg_gen_movi_tl(cpu_T[0], -1);
5091 tcg_gen_helper_0_0(do_mftc0_tcstatus);
5094 tcg_gen_helper_0_0(do_mftc0_tcbind);
5097 tcg_gen_helper_0_0(do_mftc0_tcrestart);
5100 tcg_gen_helper_0_0(do_mftc0_tchalt);
5103 tcg_gen_helper_0_0(do_mftc0_tccontext);
5106 tcg_gen_helper_0_0(do_mftc0_tcschedule);
5109 tcg_gen_helper_0_0(do_mftc0_tcschefback);
5112 gen_mfc0(env, ctx, rt, sel);
5119 tcg_gen_helper_0_0(do_mftc0_entryhi);
5122 gen_mfc0(env, ctx, rt, sel);
5128 tcg_gen_helper_0_0(do_mftc0_status);
5131 gen_mfc0(env, ctx, rt, sel);
5137 tcg_gen_helper_0_0(do_mftc0_debug);
5140 gen_mfc0(env, ctx, rt, sel);
5145 gen_mfc0(env, ctx, rt, sel);
5147 } else switch (sel) {
5148 /* GPR registers. */
5150 tcg_gen_helper_0_1i(do_mftgpr, rt);
5152 /* Auxiliary CPU registers */
5156 tcg_gen_helper_0_1i(do_mftlo, 0);
5159 tcg_gen_helper_0_1i(do_mfthi, 0);
5162 tcg_gen_helper_0_1i(do_mftacx, 0);
5165 tcg_gen_helper_0_1i(do_mftlo, 1);
5168 tcg_gen_helper_0_1i(do_mfthi, 1);
5171 tcg_gen_helper_0_1i(do_mftacx, 1);
5174 tcg_gen_helper_0_1i(do_mftlo, 2);
5177 tcg_gen_helper_0_1i(do_mfthi, 2);
5180 tcg_gen_helper_0_1i(do_mftacx, 2);
5183 tcg_gen_helper_0_1i(do_mftlo, 3);
5186 tcg_gen_helper_0_1i(do_mfthi, 3);
5189 tcg_gen_helper_0_1i(do_mftacx, 3);
5192 tcg_gen_helper_0_0(do_mftdsp);
5198 /* Floating point (COP1). */
5200 /* XXX: For now we support only a single FPU context. */
5202 gen_load_fpr32(fpu32_T[0], rt);
5203 tcg_gen_ext_i32_tl(cpu_T[0], fpu32_T[0]);
5205 gen_load_fpr32h(fpu32h_T[0], rt);
5206 tcg_gen_ext_i32_tl(cpu_T[0], fpu32h_T[0]);
5210 /* XXX: For now we support only a single FPU context. */
5211 tcg_gen_helper_0_1i(do_cfc1, rt);
5213 /* COP2: Not implemented. */
5220 #if defined MIPS_DEBUG_DISAS
5221 if (loglevel & CPU_LOG_TB_IN_ASM) {
5222 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5229 #if defined MIPS_DEBUG_DISAS
5230 if (loglevel & CPU_LOG_TB_IN_ASM) {
5231 fprintf(logfile, "mftr (reg %d u %d sel %d h %d)\n",
5235 generate_exception(ctx, EXCP_RI);
5238 static void gen_mttr(CPUState *env, DisasContext *ctx, int rd,
5239 int u, int sel, int h)
5241 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
5243 if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 &&
5244 ((env->CP0_TCBind[other_tc] & (0xf << CP0TCBd_CurVPE)) !=
5245 (env->CP0_TCBind[env->current_tc] & (0xf << CP0TCBd_CurVPE))))
5247 else if ((env->CP0_VPEControl & (0xff << CP0VPECo_TargTC)) >
5248 (env->mvp->CP0_MVPConf0 & (0xff << CP0MVPC0_PTC)))
5255 tcg_gen_helper_0_0(do_mttc0_tcstatus);
5258 tcg_gen_helper_0_0(do_mttc0_tcbind);
5261 tcg_gen_helper_0_0(do_mttc0_tcrestart);
5264 tcg_gen_helper_0_0(do_mttc0_tchalt);
5267 tcg_gen_helper_0_0(do_mttc0_tccontext);
5270 tcg_gen_helper_0_0(do_mttc0_tcschedule);
5273 tcg_gen_helper_0_0(do_mttc0_tcschefback);
5276 gen_mtc0(env, ctx, rd, sel);
5283 tcg_gen_helper_0_0(do_mttc0_entryhi);
5286 gen_mtc0(env, ctx, rd, sel);
5292 tcg_gen_helper_0_0(do_mttc0_status);
5295 gen_mtc0(env, ctx, rd, sel);
5301 tcg_gen_helper_0_0(do_mttc0_debug);
5304 gen_mtc0(env, ctx, rd, sel);
5309 gen_mtc0(env, ctx, rd, sel);
5311 } else switch (sel) {
5312 /* GPR registers. */
5314 tcg_gen_helper_0_1i(do_mttgpr, rd);
5316 /* Auxiliary CPU registers */
5320 tcg_gen_helper_0_1i(do_mttlo, 0);
5323 tcg_gen_helper_0_1i(do_mtthi, 0);
5326 tcg_gen_helper_0_1i(do_mttacx, 0);
5329 tcg_gen_helper_0_1i(do_mttlo, 1);
5332 tcg_gen_helper_0_1i(do_mtthi, 1);
5335 tcg_gen_helper_0_1i(do_mttacx, 1);
5338 tcg_gen_helper_0_1i(do_mttlo, 2);
5341 tcg_gen_helper_0_1i(do_mtthi, 2);
5344 tcg_gen_helper_0_1i(do_mttacx, 2);
5347 tcg_gen_helper_0_1i(do_mttlo, 3);
5350 tcg_gen_helper_0_1i(do_mtthi, 3);
5353 tcg_gen_helper_0_1i(do_mttacx, 3);
5356 tcg_gen_helper_0_0(do_mttdsp);
5362 /* Floating point (COP1). */
5364 /* XXX: For now we support only a single FPU context. */
5366 tcg_gen_trunc_tl_i32(fpu32_T[0], cpu_T[0]);
5367 gen_store_fpr32(fpu32_T[0], rd);
5369 tcg_gen_trunc_tl_i32(fpu32h_T[0], cpu_T[0]);
5370 gen_store_fpr32h(fpu32h_T[0], rd);
5374 /* XXX: For now we support only a single FPU context. */
5375 tcg_gen_helper_0_1i(do_ctc1, rd);
5377 /* COP2: Not implemented. */
5384 #if defined MIPS_DEBUG_DISAS
5385 if (loglevel & CPU_LOG_TB_IN_ASM) {
5386 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5393 #if defined MIPS_DEBUG_DISAS
5394 if (loglevel & CPU_LOG_TB_IN_ASM) {
5395 fprintf(logfile, "mttr (reg %d u %d sel %d h %d)\n",
5399 generate_exception(ctx, EXCP_RI);
5402 static void gen_cp0 (CPUState *env, DisasContext *ctx, uint32_t opc, int rt, int rd)
5404 const char *opn = "ldst";
5412 gen_mfc0(env, ctx, rd, ctx->opcode & 0x7);
5413 gen_store_gpr(cpu_T[0], rt);
5417 gen_load_gpr(cpu_T[0], rt);
5418 save_cpu_state(ctx, 1);
5419 gen_mtc0(env, ctx, rd, ctx->opcode & 0x7);
5422 #if defined(TARGET_MIPS64)
5424 check_insn(env, ctx, ISA_MIPS3);
5429 gen_dmfc0(env, ctx, rd, ctx->opcode & 0x7);
5430 gen_store_gpr(cpu_T[0], rt);
5434 check_insn(env, ctx, ISA_MIPS3);
5435 gen_load_gpr(cpu_T[0], rt);
5436 save_cpu_state(ctx, 1);
5437 gen_dmtc0(env, ctx, rd, ctx->opcode & 0x7);
5442 check_insn(env, ctx, ASE_MT);
5447 gen_mftr(env, ctx, rt, (ctx->opcode >> 5) & 1,
5448 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5449 gen_store_gpr(cpu_T[0], rd);
5453 check_insn(env, ctx, ASE_MT);
5454 gen_load_gpr(cpu_T[0], rt);
5455 gen_mttr(env, ctx, rd, (ctx->opcode >> 5) & 1,
5456 ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
5461 if (!env->tlb->do_tlbwi)
5463 tcg_gen_helper_0_0(env->tlb->do_tlbwi);
5467 if (!env->tlb->do_tlbwr)
5469 tcg_gen_helper_0_0(env->tlb->do_tlbwr);
5473 if (!env->tlb->do_tlbp)
5475 tcg_gen_helper_0_0(env->tlb->do_tlbp);
5479 if (!env->tlb->do_tlbr)
5481 tcg_gen_helper_0_0(env->tlb->do_tlbr);
5485 check_insn(env, ctx, ISA_MIPS2);
5486 save_cpu_state(ctx, 1);
5487 tcg_gen_helper_0_0(do_eret);
5488 ctx->bstate = BS_EXCP;
5492 check_insn(env, ctx, ISA_MIPS32);
5493 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
5495 generate_exception(ctx, EXCP_RI);
5497 save_cpu_state(ctx, 1);
5498 tcg_gen_helper_0_0(do_deret);
5499 ctx->bstate = BS_EXCP;
5504 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
5505 /* If we get an exception, we want to restart at next instruction */
5507 save_cpu_state(ctx, 1);
5509 tcg_gen_helper_0_0(do_wait);
5510 ctx->bstate = BS_EXCP;
5515 generate_exception(ctx, EXCP_RI);
5518 MIPS_DEBUG("%s %s %d", opn, regnames[rt], rd);
5520 #endif /* !CONFIG_USER_ONLY */
5522 /* CP1 Branches (before delay slot) */
5523 static void gen_compute_branch1 (CPUState *env, DisasContext *ctx, uint32_t op,
5524 int32_t cc, int32_t offset)
5526 target_ulong btarget;
5527 const char *opn = "cp1 cond branch";
5530 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
5532 btarget = ctx->pc + 4 + offset;
5537 int l1 = gen_new_label();
5538 int l2 = gen_new_label();
5539 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5541 get_fp_cond(r_tmp1);
5542 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
5543 tcg_temp_free(r_tmp1);
5544 tcg_gen_not_tl(cpu_T[0], cpu_T[0]);
5545 tcg_gen_movi_tl(cpu_T[1], 0x1 << cc);
5546 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5547 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5548 tcg_gen_movi_tl(cpu_T[0], 0);
5551 tcg_gen_movi_tl(cpu_T[0], 1);
5558 int l1 = gen_new_label();
5559 int l2 = gen_new_label();
5560 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5562 get_fp_cond(r_tmp1);
5563 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
5564 tcg_temp_free(r_tmp1);
5565 tcg_gen_not_tl(cpu_T[0], cpu_T[0]);
5566 tcg_gen_movi_tl(cpu_T[1], 0x1 << cc);
5567 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5568 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5569 tcg_gen_movi_tl(cpu_T[0], 0);
5572 tcg_gen_movi_tl(cpu_T[0], 1);
5579 int l1 = gen_new_label();
5580 int l2 = gen_new_label();
5581 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5583 get_fp_cond(r_tmp1);
5584 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
5585 tcg_temp_free(r_tmp1);
5586 tcg_gen_movi_tl(cpu_T[1], 0x1 << cc);
5587 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5588 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5589 tcg_gen_movi_tl(cpu_T[0], 0);
5592 tcg_gen_movi_tl(cpu_T[0], 1);
5599 int l1 = gen_new_label();
5600 int l2 = gen_new_label();
5601 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5603 get_fp_cond(r_tmp1);
5604 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
5605 tcg_temp_free(r_tmp1);
5606 tcg_gen_movi_tl(cpu_T[1], 0x1 << cc);
5607 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5608 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5609 tcg_gen_movi_tl(cpu_T[0], 0);
5612 tcg_gen_movi_tl(cpu_T[0], 1);
5617 ctx->hflags |= MIPS_HFLAG_BL;
5618 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
5622 int l1 = gen_new_label();
5623 int l2 = gen_new_label();
5624 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5626 get_fp_cond(r_tmp1);
5627 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
5628 tcg_temp_free(r_tmp1);
5629 tcg_gen_not_tl(cpu_T[0], cpu_T[0]);
5630 tcg_gen_movi_tl(cpu_T[1], 0x3 << cc);
5631 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5632 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5633 tcg_gen_movi_tl(cpu_T[0], 0);
5636 tcg_gen_movi_tl(cpu_T[0], 1);
5643 int l1 = gen_new_label();
5644 int l2 = gen_new_label();
5645 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5647 get_fp_cond(r_tmp1);
5648 tcg_gen_ext_i32_tl(cpu_T[0], r_tmp1);
5649 tcg_temp_free(r_tmp1);
5650 tcg_gen_movi_tl(cpu_T[1], 0x3 << cc);
5651 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5652 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5653 tcg_gen_movi_tl(cpu_T[0], 0);
5656 tcg_gen_movi_tl(cpu_T[0], 1);
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(cpu_T[0], r_tmp1);
5669 tcg_temp_free(r_tmp1);
5670 tcg_gen_not_tl(cpu_T[0], cpu_T[0]);
5671 tcg_gen_movi_tl(cpu_T[1], 0xf << cc);
5672 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5673 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5674 tcg_gen_movi_tl(cpu_T[0], 0);
5677 tcg_gen_movi_tl(cpu_T[0], 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(cpu_T[0], r_tmp1);
5690 tcg_temp_free(r_tmp1);
5691 tcg_gen_movi_tl(cpu_T[1], 0xf << cc);
5692 tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
5693 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
5694 tcg_gen_movi_tl(cpu_T[0], 0);
5697 tcg_gen_movi_tl(cpu_T[0], 1);
5702 ctx->hflags |= MIPS_HFLAG_BC;
5703 tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, bcond));
5707 generate_exception (ctx, EXCP_RI);
5710 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx, opn,
5711 ctx->hflags, btarget);
5712 ctx->btarget = btarget;
5715 /* Coprocessor 1 (FPU) */
5717 #define FOP(func, fmt) (((fmt) << 21) | (func))
5719 static void gen_cp1 (DisasContext *ctx, uint32_t opc, int rt, int fs)
5721 const char *opn = "cp1 move";
5725 gen_load_fpr32(fpu32_T[0], fs);
5726 tcg_gen_ext_i32_tl(cpu_T[0], fpu32_T[0]);
5727 gen_store_gpr(cpu_T[0], rt);
5731 gen_load_gpr(cpu_T[0], rt);
5732 tcg_gen_trunc_tl_i32(fpu32_T[0], cpu_T[0]);
5733 gen_store_fpr32(fpu32_T[0], fs);
5737 tcg_gen_helper_0_1i(do_cfc1, fs);
5738 gen_store_gpr(cpu_T[0], rt);
5742 gen_load_gpr(cpu_T[0], rt);
5743 tcg_gen_helper_0_1i(do_ctc1, fs);
5747 gen_load_fpr64(ctx, fpu64_T[0], fs);
5748 tcg_gen_mov_tl(cpu_T[0], fpu64_T[0]);
5749 gen_store_gpr(cpu_T[0], rt);
5753 gen_load_gpr(cpu_T[0], rt);
5754 tcg_gen_mov_tl(fpu64_T[0], cpu_T[0]);
5755 gen_store_fpr64(ctx, fpu64_T[0], fs);
5759 gen_load_fpr32h(fpu32h_T[0], fs);
5760 tcg_gen_ext_i32_tl(cpu_T[0], fpu32h_T[0]);
5761 gen_store_gpr(cpu_T[0], rt);
5765 gen_load_gpr(cpu_T[0], rt);
5766 tcg_gen_trunc_tl_i32(fpu32h_T[0], cpu_T[0]);
5767 gen_store_fpr32h(fpu32h_T[0], fs);
5772 generate_exception (ctx, EXCP_RI);
5775 MIPS_DEBUG("%s %s %s", opn, regnames[rt], fregnames[fs]);
5778 static void gen_movci (DisasContext *ctx, int rd, int rs, int cc, int tf)
5780 int l1 = gen_new_label();
5785 ccbit = 1 << (24 + cc);
5793 gen_load_gpr(cpu_T[0], rd);
5794 gen_load_gpr(cpu_T[1], rs);
5796 TCGv r_ptr = tcg_temp_new(TCG_TYPE_PTR);
5797 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_I32);
5799 tcg_gen_ld_ptr(r_ptr, cpu_env, offsetof(CPUState, fpu));
5800 tcg_gen_ld_i32(r_tmp, r_ptr, offsetof(CPUMIPSFPUContext, fcr31));
5801 tcg_temp_free(r_ptr);
5802 tcg_gen_andi_i32(r_tmp, r_tmp, ccbit);
5803 tcg_gen_brcondi_i32(cond, r_tmp, 0, l1);
5804 tcg_temp_free(r_tmp);
5806 tcg_gen_mov_tl(cpu_T[0], cpu_T[1]);
5809 gen_store_gpr(cpu_T[0], rd);
5812 static inline void gen_movcf_s (int cc, int tf)
5816 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5817 int l1 = gen_new_label();
5820 ccbit = 1 << (24 + cc);
5829 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
5830 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
5831 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5832 tcg_gen_movi_i32(fpu32_T[2], fpu32_T[0]);
5834 tcg_temp_free(r_tmp1);
5837 static inline void gen_movcf_d (int cc, int tf)
5841 TCGv r_tmp1 = tcg_temp_new(TCG_TYPE_I32);
5842 int l1 = gen_new_label();
5845 ccbit = 1 << (24 + cc);
5854 tcg_gen_ld_i32(r_tmp1, current_fpu, offsetof(CPUMIPSFPUContext, fcr31));
5855 tcg_gen_andi_i32(r_tmp1, r_tmp1, ccbit);
5856 tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1);
5857 tcg_gen_movi_i64(fpu64_T[2], fpu64_T[0]);
5859 tcg_temp_free(r_tmp1);
5862 static inline void gen_movcf_ps (int cc, int tf)
5865 TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32);
5866 TCGv r_tmp2 = tcg_temp_local_new(TCG_TYPE_I32);
5867 int l1 = gen_new_label();
5868 int l2 = gen_new_label();
5875 get_fp_cond(r_tmp1);
5876 tcg_gen_shri_i32(r_tmp1, r_tmp1, cc);
5877 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x1);
5878 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l1);
5879 tcg_gen_movi_i32(fpu32_T[2], fpu32_T[0]);
5881 tcg_gen_andi_i32(r_tmp2, r_tmp1, 0x2);
5882 tcg_gen_brcondi_i32(cond, r_tmp2, 0, l2);
5883 tcg_gen_movi_i32(fpu32h_T[2], fpu32h_T[0]);
5885 tcg_temp_free(r_tmp1);
5886 tcg_temp_free(r_tmp2);
5890 static void gen_farith (DisasContext *ctx, uint32_t op1,
5891 int ft, int fs, int fd, int cc)
5893 const char *opn = "farith";
5894 const char *condnames[] = {
5912 const char *condnames_abs[] = {
5930 enum { BINOP, CMPOP, OTHEROP } optype = OTHEROP;
5931 uint32_t func = ctx->opcode & 0x3f;
5933 switch (ctx->opcode & FOP(0x3f, 0x1f)) {
5935 gen_load_fpr32(fpu32_T[0], fs);
5936 gen_load_fpr32(fpu32_T[1], ft);
5937 tcg_gen_helper_0_0(do_float_add_s);
5938 gen_store_fpr32(fpu32_T[2], fd);
5943 gen_load_fpr32(fpu32_T[0], fs);
5944 gen_load_fpr32(fpu32_T[1], ft);
5945 tcg_gen_helper_0_0(do_float_sub_s);
5946 gen_store_fpr32(fpu32_T[2], fd);
5951 gen_load_fpr32(fpu32_T[0], fs);
5952 gen_load_fpr32(fpu32_T[1], ft);
5953 tcg_gen_helper_0_0(do_float_mul_s);
5954 gen_store_fpr32(fpu32_T[2], fd);
5959 gen_load_fpr32(fpu32_T[0], fs);
5960 gen_load_fpr32(fpu32_T[1], ft);
5961 tcg_gen_helper_0_0(do_float_div_s);
5962 gen_store_fpr32(fpu32_T[2], fd);
5967 gen_load_fpr32(fpu32_T[0], fs);
5968 tcg_gen_helper_0_0(do_float_sqrt_s);
5969 gen_store_fpr32(fpu32_T[2], fd);
5973 gen_load_fpr32(fpu32_T[0], fs);
5974 tcg_gen_helper_0_0(do_float_abs_s);
5975 gen_store_fpr32(fpu32_T[2], fd);
5979 gen_load_fpr32(fpu32_T[0], fs);
5980 gen_store_fpr32(fpu32_T[0], fd);
5984 gen_load_fpr32(fpu32_T[0], fs);
5985 tcg_gen_helper_0_0(do_float_chs_s);
5986 gen_store_fpr32(fpu32_T[2], fd);
5990 check_cp1_64bitmode(ctx);
5991 gen_load_fpr32(fpu32_T[0], fs);
5992 tcg_gen_helper_0_0(do_float_roundl_s);
5993 gen_store_fpr64(ctx, fpu64_T[2], fd);
5997 check_cp1_64bitmode(ctx);
5998 gen_load_fpr32(fpu32_T[0], fs);
5999 tcg_gen_helper_0_0(do_float_truncl_s);
6000 gen_store_fpr64(ctx, fpu64_T[2], fd);
6004 check_cp1_64bitmode(ctx);
6005 gen_load_fpr32(fpu32_T[0], fs);
6006 tcg_gen_helper_0_0(do_float_ceill_s);
6007 gen_store_fpr64(ctx, fpu64_T[2], fd);
6011 check_cp1_64bitmode(ctx);
6012 gen_load_fpr32(fpu32_T[0], fs);
6013 tcg_gen_helper_0_0(do_float_floorl_s);
6014 gen_store_fpr64(ctx, fpu64_T[2], fd);
6018 gen_load_fpr32(fpu32_T[0], fs);
6019 tcg_gen_helper_0_0(do_float_roundw_s);
6020 gen_store_fpr32(fpu32_T[2], fd);
6024 gen_load_fpr32(fpu32_T[0], fs);
6025 tcg_gen_helper_0_0(do_float_truncw_s);
6026 gen_store_fpr32(fpu32_T[2], fd);
6030 gen_load_fpr32(fpu32_T[0], fs);
6031 tcg_gen_helper_0_0(do_float_ceilw_s);
6032 gen_store_fpr32(fpu32_T[2], fd);
6036 gen_load_fpr32(fpu32_T[0], fs);
6037 tcg_gen_helper_0_0(do_float_floorw_s);
6038 gen_store_fpr32(fpu32_T[2], fd);
6042 gen_load_fpr32(fpu32_T[0], fs);
6043 gen_load_fpr32(fpu32_T[2], fd);
6044 gen_movcf_s((ft >> 2) & 0x7, ft & 0x1);
6045 gen_store_fpr32(fpu32_T[2], fd);
6049 gen_load_gpr(cpu_T[0], ft);
6050 gen_load_fpr32(fpu32_T[0], fs);
6051 gen_load_fpr32(fpu32_T[2], fd);
6053 int l1 = gen_new_label();
6055 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
6056 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6059 gen_store_fpr32(fpu32_T[2], fd);
6063 gen_load_gpr(cpu_T[0], ft);
6064 gen_load_fpr32(fpu32_T[0], fs);
6065 gen_load_fpr32(fpu32_T[2], fd);
6067 int l1 = gen_new_label();
6069 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
6070 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6073 gen_store_fpr32(fpu32_T[2], fd);
6078 gen_load_fpr32(fpu32_T[0], fs);
6079 tcg_gen_helper_0_0(do_float_recip_s);
6080 gen_store_fpr32(fpu32_T[2], fd);
6085 gen_load_fpr32(fpu32_T[0], fs);
6086 tcg_gen_helper_0_0(do_float_rsqrt_s);
6087 gen_store_fpr32(fpu32_T[2], fd);
6091 check_cp1_64bitmode(ctx);
6092 gen_load_fpr32(fpu32_T[0], fs);
6093 gen_load_fpr32(fpu32_T[2], fd);
6094 tcg_gen_helper_0_0(do_float_recip2_s);
6095 gen_store_fpr32(fpu32_T[2], fd);
6099 check_cp1_64bitmode(ctx);
6100 gen_load_fpr32(fpu32_T[0], fs);
6101 tcg_gen_helper_0_0(do_float_recip1_s);
6102 gen_store_fpr32(fpu32_T[2], fd);
6106 check_cp1_64bitmode(ctx);
6107 gen_load_fpr32(fpu32_T[0], fs);
6108 tcg_gen_helper_0_0(do_float_rsqrt1_s);
6109 gen_store_fpr32(fpu32_T[2], fd);
6113 check_cp1_64bitmode(ctx);
6114 gen_load_fpr32(fpu32_T[0], fs);
6115 gen_load_fpr32(fpu32_T[2], ft);
6116 tcg_gen_helper_0_0(do_float_rsqrt2_s);
6117 gen_store_fpr32(fpu32_T[2], fd);
6121 check_cp1_registers(ctx, fd);
6122 gen_load_fpr32(fpu32_T[0], fs);
6123 tcg_gen_helper_0_0(do_float_cvtd_s);
6124 gen_store_fpr64(ctx, fpu64_T[2], fd);
6128 gen_load_fpr32(fpu32_T[0], fs);
6129 tcg_gen_helper_0_0(do_float_cvtw_s);
6130 gen_store_fpr32(fpu32_T[2], fd);
6134 check_cp1_64bitmode(ctx);
6135 gen_load_fpr32(fpu32_T[0], fs);
6136 tcg_gen_helper_0_0(do_float_cvtl_s);
6137 gen_store_fpr64(ctx, fpu64_T[2], fd);
6141 check_cp1_64bitmode(ctx);
6142 gen_load_fpr32(fpu32_T[0], fs);
6143 gen_load_fpr32(fpu32_T[1], ft);
6144 tcg_gen_extu_i32_i64(fpu64_T[0], fpu32_T[0]);
6145 tcg_gen_extu_i32_i64(fpu64_T[1], fpu32_T[1]);
6146 tcg_gen_shli_i64(fpu64_T[1], fpu64_T[1], 32);
6147 tcg_gen_or_i64(fpu64_T[2], fpu64_T[0], fpu64_T[1]);
6148 gen_store_fpr64(ctx, fpu64_T[2], fd);
6167 gen_load_fpr32(fpu32_T[0], fs);
6168 gen_load_fpr32(fpu32_T[1], ft);
6169 if (ctx->opcode & (1 << 6)) {
6171 gen_cmpabs_s(func-48, cc);
6172 opn = condnames_abs[func-48];
6174 gen_cmp_s(func-48, cc);
6175 opn = condnames[func-48];
6179 check_cp1_registers(ctx, fs | ft | fd);
6180 gen_load_fpr64(ctx, fpu64_T[0], fs);
6181 gen_load_fpr64(ctx, fpu64_T[1], ft);
6182 tcg_gen_helper_0_0(do_float_add_d);
6183 gen_store_fpr64(ctx, fpu64_T[2], fd);
6188 check_cp1_registers(ctx, fs | ft | fd);
6189 gen_load_fpr64(ctx, fpu64_T[0], fs);
6190 gen_load_fpr64(ctx, fpu64_T[1], ft);
6191 tcg_gen_helper_0_0(do_float_sub_d);
6192 gen_store_fpr64(ctx, fpu64_T[2], fd);
6197 check_cp1_registers(ctx, fs | ft | fd);
6198 gen_load_fpr64(ctx, fpu64_T[0], fs);
6199 gen_load_fpr64(ctx, fpu64_T[1], ft);
6200 tcg_gen_helper_0_0(do_float_mul_d);
6201 gen_store_fpr64(ctx, fpu64_T[2], fd);
6206 check_cp1_registers(ctx, fs | ft | fd);
6207 gen_load_fpr64(ctx, fpu64_T[0], fs);
6208 gen_load_fpr64(ctx, fpu64_T[1], ft);
6209 tcg_gen_helper_0_0(do_float_div_d);
6210 gen_store_fpr64(ctx, fpu64_T[2], fd);
6215 check_cp1_registers(ctx, fs | fd);
6216 gen_load_fpr64(ctx, fpu64_T[0], fs);
6217 tcg_gen_helper_0_0(do_float_sqrt_d);
6218 gen_store_fpr64(ctx, fpu64_T[2], fd);
6222 check_cp1_registers(ctx, fs | fd);
6223 gen_load_fpr64(ctx, fpu64_T[0], fs);
6224 tcg_gen_helper_0_0(do_float_abs_d);
6225 gen_store_fpr64(ctx, fpu64_T[2], fd);
6229 check_cp1_registers(ctx, fs | fd);
6230 gen_load_fpr64(ctx, fpu64_T[0], fs);
6231 gen_store_fpr64(ctx, fpu64_T[0], fd);
6235 check_cp1_registers(ctx, fs | fd);
6236 gen_load_fpr64(ctx, fpu64_T[0], fs);
6237 tcg_gen_helper_0_0(do_float_chs_d);
6238 gen_store_fpr64(ctx, fpu64_T[2], fd);
6242 check_cp1_64bitmode(ctx);
6243 gen_load_fpr64(ctx, fpu64_T[0], fs);
6244 tcg_gen_helper_0_0(do_float_roundl_d);
6245 gen_store_fpr64(ctx, fpu64_T[2], fd);
6249 check_cp1_64bitmode(ctx);
6250 gen_load_fpr64(ctx, fpu64_T[0], fs);
6251 tcg_gen_helper_0_0(do_float_truncl_d);
6252 gen_store_fpr64(ctx, fpu64_T[2], fd);
6256 check_cp1_64bitmode(ctx);
6257 gen_load_fpr64(ctx, fpu64_T[0], fs);
6258 tcg_gen_helper_0_0(do_float_ceill_d);
6259 gen_store_fpr64(ctx, fpu64_T[2], fd);
6263 check_cp1_64bitmode(ctx);
6264 gen_load_fpr64(ctx, fpu64_T[0], fs);
6265 tcg_gen_helper_0_0(do_float_floorl_d);
6266 gen_store_fpr64(ctx, fpu64_T[2], fd);
6270 check_cp1_registers(ctx, fs);
6271 gen_load_fpr64(ctx, fpu64_T[0], fs);
6272 tcg_gen_helper_0_0(do_float_roundw_d);
6273 gen_store_fpr32(fpu32_T[2], fd);
6277 check_cp1_registers(ctx, fs);
6278 gen_load_fpr64(ctx, fpu64_T[0], fs);
6279 tcg_gen_helper_0_0(do_float_truncw_d);
6280 gen_store_fpr32(fpu32_T[2], fd);
6284 check_cp1_registers(ctx, fs);
6285 gen_load_fpr64(ctx, fpu64_T[0], fs);
6286 tcg_gen_helper_0_0(do_float_ceilw_d);
6287 gen_store_fpr32(fpu32_T[2], fd);
6291 check_cp1_registers(ctx, fs);
6292 gen_load_fpr64(ctx, fpu64_T[0], fs);
6293 tcg_gen_helper_0_0(do_float_floorw_d);
6294 gen_store_fpr32(fpu32_T[2], fd);
6298 gen_load_fpr64(ctx, fpu64_T[0], fs);
6299 gen_load_fpr64(ctx, fpu64_T[2], fd);
6300 gen_movcf_d((ft >> 2) & 0x7, ft & 0x1);
6301 gen_store_fpr64(ctx, fpu64_T[2], fd);
6305 gen_load_gpr(cpu_T[0], ft);
6306 gen_load_fpr64(ctx, fpu64_T[0], fs);
6307 gen_load_fpr64(ctx, fpu64_T[2], fd);
6309 int l1 = gen_new_label();
6311 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
6312 tcg_gen_mov_i64(fpu64_T[2], fpu64_T[0]);
6315 gen_store_fpr64(ctx, fpu64_T[2], fd);
6319 gen_load_gpr(cpu_T[0], ft);
6320 gen_load_fpr64(ctx, fpu64_T[0], fs);
6321 gen_load_fpr64(ctx, fpu64_T[2], fd);
6323 int l1 = gen_new_label();
6325 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
6326 tcg_gen_mov_i64(fpu64_T[2], fpu64_T[0]);
6329 gen_store_fpr64(ctx, fpu64_T[2], fd);
6333 check_cp1_64bitmode(ctx);
6334 gen_load_fpr64(ctx, fpu64_T[0], fs);
6335 tcg_gen_helper_0_0(do_float_recip_d);
6336 gen_store_fpr64(ctx, fpu64_T[2], fd);
6340 check_cp1_64bitmode(ctx);
6341 gen_load_fpr64(ctx, fpu64_T[0], fs);
6342 tcg_gen_helper_0_0(do_float_rsqrt_d);
6343 gen_store_fpr64(ctx, fpu64_T[2], fd);
6347 check_cp1_64bitmode(ctx);
6348 gen_load_fpr64(ctx, fpu64_T[0], fs);
6349 gen_load_fpr64(ctx, fpu64_T[2], ft);
6350 tcg_gen_helper_0_0(do_float_recip2_d);
6351 gen_store_fpr64(ctx, fpu64_T[2], fd);
6355 check_cp1_64bitmode(ctx);
6356 gen_load_fpr64(ctx, fpu64_T[0], fs);
6357 tcg_gen_helper_0_0(do_float_recip1_d);
6358 gen_store_fpr64(ctx, fpu64_T[2], fd);
6362 check_cp1_64bitmode(ctx);
6363 gen_load_fpr64(ctx, fpu64_T[0], fs);
6364 tcg_gen_helper_0_0(do_float_rsqrt1_d);
6365 gen_store_fpr64(ctx, fpu64_T[2], fd);
6369 check_cp1_64bitmode(ctx);
6370 gen_load_fpr64(ctx, fpu64_T[0], fs);
6371 gen_load_fpr64(ctx, fpu64_T[2], ft);
6372 tcg_gen_helper_0_0(do_float_rsqrt2_d);
6373 gen_store_fpr64(ctx, fpu64_T[2], fd);
6392 gen_load_fpr64(ctx, fpu64_T[0], fs);
6393 gen_load_fpr64(ctx, fpu64_T[1], ft);
6394 if (ctx->opcode & (1 << 6)) {
6396 check_cp1_registers(ctx, fs | ft);
6397 gen_cmpabs_d(func-48, cc);
6398 opn = condnames_abs[func-48];
6400 check_cp1_registers(ctx, fs | ft);
6401 gen_cmp_d(func-48, cc);
6402 opn = condnames[func-48];
6406 check_cp1_registers(ctx, fs);
6407 gen_load_fpr64(ctx, fpu64_T[0], fs);
6408 tcg_gen_helper_0_0(do_float_cvts_d);
6409 gen_store_fpr32(fpu32_T[2], fd);
6413 check_cp1_registers(ctx, fs);
6414 gen_load_fpr64(ctx, fpu64_T[0], fs);
6415 tcg_gen_helper_0_0(do_float_cvtw_d);
6416 gen_store_fpr32(fpu32_T[2], fd);
6420 check_cp1_64bitmode(ctx);
6421 gen_load_fpr64(ctx, fpu64_T[0], fs);
6422 tcg_gen_helper_0_0(do_float_cvtl_d);
6423 gen_store_fpr64(ctx, fpu64_T[2], fd);
6427 gen_load_fpr32(fpu32_T[0], fs);
6428 tcg_gen_helper_0_0(do_float_cvts_w);
6429 gen_store_fpr32(fpu32_T[2], fd);
6433 check_cp1_registers(ctx, fd);
6434 gen_load_fpr32(fpu32_T[0], fs);
6435 tcg_gen_helper_0_0(do_float_cvtd_w);
6436 gen_store_fpr64(ctx, fpu64_T[2], fd);
6440 check_cp1_64bitmode(ctx);
6441 gen_load_fpr64(ctx, fpu64_T[0], fs);
6442 tcg_gen_helper_0_0(do_float_cvts_l);
6443 gen_store_fpr32(fpu32_T[2], fd);
6447 check_cp1_64bitmode(ctx);
6448 gen_load_fpr64(ctx, fpu64_T[0], fs);
6449 tcg_gen_helper_0_0(do_float_cvtd_l);
6450 gen_store_fpr64(ctx, fpu64_T[2], fd);
6454 check_cp1_64bitmode(ctx);
6455 gen_load_fpr32(fpu32_T[0], fs);
6456 gen_load_fpr32h(fpu32h_T[0], fs);
6457 tcg_gen_helper_0_0(do_float_cvtps_pw);
6458 gen_store_fpr32(fpu32_T[2], fd);
6459 gen_store_fpr32h(fpu32h_T[2], fd);
6463 check_cp1_64bitmode(ctx);
6464 gen_load_fpr32(fpu32_T[0], fs);
6465 gen_load_fpr32h(fpu32h_T[0], fs);
6466 gen_load_fpr32(fpu32_T[1], ft);
6467 gen_load_fpr32h(fpu32h_T[1], ft);
6468 tcg_gen_helper_0_0(do_float_add_ps);
6469 gen_store_fpr32(fpu32_T[2], fd);
6470 gen_store_fpr32h(fpu32h_T[2], fd);
6474 check_cp1_64bitmode(ctx);
6475 gen_load_fpr32(fpu32_T[0], fs);
6476 gen_load_fpr32h(fpu32h_T[0], fs);
6477 gen_load_fpr32(fpu32_T[1], ft);
6478 gen_load_fpr32h(fpu32h_T[1], ft);
6479 tcg_gen_helper_0_0(do_float_sub_ps);
6480 gen_store_fpr32(fpu32_T[2], fd);
6481 gen_store_fpr32h(fpu32h_T[2], fd);
6485 check_cp1_64bitmode(ctx);
6486 gen_load_fpr32(fpu32_T[0], fs);
6487 gen_load_fpr32h(fpu32h_T[0], fs);
6488 gen_load_fpr32(fpu32_T[1], ft);
6489 gen_load_fpr32h(fpu32h_T[1], ft);
6490 tcg_gen_helper_0_0(do_float_mul_ps);
6491 gen_store_fpr32(fpu32_T[2], fd);
6492 gen_store_fpr32h(fpu32h_T[2], fd);
6496 check_cp1_64bitmode(ctx);
6497 gen_load_fpr32(fpu32_T[0], fs);
6498 gen_load_fpr32h(fpu32h_T[0], fs);
6499 tcg_gen_helper_0_0(do_float_abs_ps);
6500 gen_store_fpr32(fpu32_T[2], fd);
6501 gen_store_fpr32h(fpu32h_T[2], fd);
6505 check_cp1_64bitmode(ctx);
6506 gen_load_fpr32(fpu32_T[0], fs);
6507 gen_load_fpr32h(fpu32h_T[0], fs);
6508 gen_store_fpr32(fpu32_T[0], fd);
6509 gen_store_fpr32h(fpu32h_T[0], fd);
6513 check_cp1_64bitmode(ctx);
6514 gen_load_fpr32(fpu32_T[0], fs);
6515 gen_load_fpr32h(fpu32h_T[0], fs);
6516 tcg_gen_helper_0_0(do_float_chs_ps);
6517 gen_store_fpr32(fpu32_T[2], fd);
6518 gen_store_fpr32h(fpu32h_T[2], fd);
6522 check_cp1_64bitmode(ctx);
6523 gen_load_fpr32(fpu32_T[0], fs);
6524 gen_load_fpr32h(fpu32h_T[0], fs);
6525 gen_load_fpr32(fpu32_T[2], fd);
6526 gen_load_fpr32h(fpu32h_T[2], fd);
6527 gen_movcf_ps((ft >> 2) & 0x7, ft & 0x1);
6528 gen_store_fpr32(fpu32_T[2], fd);
6529 gen_store_fpr32h(fpu32h_T[2], fd);
6533 check_cp1_64bitmode(ctx);
6534 gen_load_gpr(cpu_T[0], ft);
6535 gen_load_fpr32(fpu32_T[0], fs);
6536 gen_load_fpr32h(fpu32h_T[0], fs);
6537 gen_load_fpr32(fpu32_T[2], fd);
6538 gen_load_fpr32h(fpu32h_T[2], fd);
6540 int l1 = gen_new_label();
6542 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
6543 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6544 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
6547 gen_store_fpr32(fpu32_T[2], fd);
6548 gen_store_fpr32h(fpu32h_T[2], fd);
6552 check_cp1_64bitmode(ctx);
6553 gen_load_gpr(cpu_T[0], ft);
6554 gen_load_fpr32(fpu32_T[0], fs);
6555 gen_load_fpr32h(fpu32h_T[0], fs);
6556 gen_load_fpr32(fpu32_T[2], fd);
6557 gen_load_fpr32h(fpu32h_T[2], fd);
6559 int l1 = gen_new_label();
6561 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[0], 0, l1);
6562 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6563 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
6566 gen_store_fpr32(fpu32_T[2], fd);
6567 gen_store_fpr32h(fpu32h_T[2], fd);
6571 check_cp1_64bitmode(ctx);
6572 gen_load_fpr32(fpu32_T[0], ft);
6573 gen_load_fpr32h(fpu32h_T[0], ft);
6574 gen_load_fpr32(fpu32_T[1], fs);
6575 gen_load_fpr32h(fpu32h_T[1], fs);
6576 tcg_gen_helper_0_0(do_float_addr_ps);
6577 gen_store_fpr32(fpu32_T[2], fd);
6578 gen_store_fpr32h(fpu32h_T[2], fd);
6582 check_cp1_64bitmode(ctx);
6583 gen_load_fpr32(fpu32_T[0], ft);
6584 gen_load_fpr32h(fpu32h_T[0], ft);
6585 gen_load_fpr32(fpu32_T[1], fs);
6586 gen_load_fpr32h(fpu32h_T[1], fs);
6587 tcg_gen_helper_0_0(do_float_mulr_ps);
6588 gen_store_fpr32(fpu32_T[2], fd);
6589 gen_store_fpr32h(fpu32h_T[2], fd);
6593 check_cp1_64bitmode(ctx);
6594 gen_load_fpr32(fpu32_T[0], fs);
6595 gen_load_fpr32h(fpu32h_T[0], fs);
6596 gen_load_fpr32(fpu32_T[2], fd);
6597 gen_load_fpr32h(fpu32h_T[2], fd);
6598 tcg_gen_helper_0_0(do_float_recip2_ps);
6599 gen_store_fpr32(fpu32_T[2], fd);
6600 gen_store_fpr32h(fpu32h_T[2], fd);
6604 check_cp1_64bitmode(ctx);
6605 gen_load_fpr32(fpu32_T[0], fs);
6606 gen_load_fpr32h(fpu32h_T[0], fs);
6607 tcg_gen_helper_0_0(do_float_recip1_ps);
6608 gen_store_fpr32(fpu32_T[2], fd);
6609 gen_store_fpr32h(fpu32h_T[2], fd);
6613 check_cp1_64bitmode(ctx);
6614 gen_load_fpr32(fpu32_T[0], fs);
6615 gen_load_fpr32h(fpu32h_T[0], fs);
6616 tcg_gen_helper_0_0(do_float_rsqrt1_ps);
6617 gen_store_fpr32(fpu32_T[2], fd);
6618 gen_store_fpr32h(fpu32h_T[2], fd);
6622 check_cp1_64bitmode(ctx);
6623 gen_load_fpr32(fpu32_T[0], fs);
6624 gen_load_fpr32h(fpu32h_T[0], fs);
6625 gen_load_fpr32(fpu32_T[2], ft);
6626 gen_load_fpr32h(fpu32h_T[2], ft);
6627 tcg_gen_helper_0_0(do_float_rsqrt2_ps);
6628 gen_store_fpr32(fpu32_T[2], fd);
6629 gen_store_fpr32h(fpu32h_T[2], fd);
6633 check_cp1_64bitmode(ctx);
6634 gen_load_fpr32h(fpu32h_T[0], fs);
6635 tcg_gen_helper_0_0(do_float_cvts_pu);
6636 gen_store_fpr32(fpu32_T[2], fd);
6640 check_cp1_64bitmode(ctx);
6641 gen_load_fpr32(fpu32_T[0], fs);
6642 gen_load_fpr32h(fpu32h_T[0], fs);
6643 tcg_gen_helper_0_0(do_float_cvtpw_ps);
6644 gen_store_fpr32(fpu32_T[2], fd);
6645 gen_store_fpr32h(fpu32h_T[2], fd);
6649 check_cp1_64bitmode(ctx);
6650 gen_load_fpr32(fpu32_T[0], fs);
6651 tcg_gen_helper_0_0(do_float_cvts_pl);
6652 gen_store_fpr32(fpu32_T[2], fd);
6656 check_cp1_64bitmode(ctx);
6657 gen_load_fpr32(fpu32_T[0], fs);
6658 gen_load_fpr32(fpu32_T[1], ft);
6659 gen_store_fpr32h(fpu32_T[0], fd);
6660 gen_store_fpr32(fpu32_T[1], fd);
6664 check_cp1_64bitmode(ctx);
6665 gen_load_fpr32(fpu32_T[0], fs);
6666 gen_load_fpr32h(fpu32h_T[1], ft);
6667 gen_store_fpr32(fpu32h_T[1], fd);
6668 gen_store_fpr32h(fpu32_T[0], fd);
6672 check_cp1_64bitmode(ctx);
6673 gen_load_fpr32h(fpu32h_T[0], fs);
6674 gen_load_fpr32(fpu32_T[1], ft);
6675 gen_store_fpr32(fpu32_T[1], fd);
6676 gen_store_fpr32h(fpu32h_T[0], fd);
6680 check_cp1_64bitmode(ctx);
6681 gen_load_fpr32h(fpu32h_T[0], fs);
6682 gen_load_fpr32h(fpu32h_T[1], ft);
6683 gen_store_fpr32(fpu32h_T[1], fd);
6684 gen_store_fpr32h(fpu32h_T[0], fd);
6703 check_cp1_64bitmode(ctx);
6704 gen_load_fpr32(fpu32_T[0], fs);
6705 gen_load_fpr32h(fpu32h_T[0], fs);
6706 gen_load_fpr32(fpu32_T[1], ft);
6707 gen_load_fpr32h(fpu32h_T[1], ft);
6708 if (ctx->opcode & (1 << 6)) {
6709 gen_cmpabs_ps(func-48, cc);
6710 opn = condnames_abs[func-48];
6712 gen_cmp_ps(func-48, cc);
6713 opn = condnames[func-48];
6718 generate_exception (ctx, EXCP_RI);
6723 MIPS_DEBUG("%s %s, %s, %s", opn, fregnames[fd], fregnames[fs], fregnames[ft]);
6726 MIPS_DEBUG("%s %s,%s", opn, fregnames[fs], fregnames[ft]);
6729 MIPS_DEBUG("%s %s,%s", opn, fregnames[fd], fregnames[fs]);
6734 /* Coprocessor 3 (FPU) */
6735 static void gen_flt3_ldst (DisasContext *ctx, uint32_t opc,
6736 int fd, int fs, int base, int index)
6738 const char *opn = "extended float load/store";
6742 gen_load_gpr(cpu_T[0], index);
6743 } else if (index == 0) {
6744 gen_load_gpr(cpu_T[0], base);
6746 gen_load_gpr(cpu_T[0], base);
6747 gen_load_gpr(cpu_T[1], index);
6750 /* Don't do NOP if destination is zero: we must perform the actual
6755 tcg_gen_qemu_ld32s(fpu32_T[0], cpu_T[0], ctx->mem_idx);
6756 gen_store_fpr32(fpu32_T[0], fd);
6761 check_cp1_registers(ctx, fd);
6762 tcg_gen_qemu_ld64(fpu64_T[0], cpu_T[0], ctx->mem_idx);
6763 gen_store_fpr64(ctx, fpu64_T[0], fd);
6767 check_cp1_64bitmode(ctx);
6768 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], ~0x7);
6769 tcg_gen_qemu_ld64(fpu64_T[0], cpu_T[0], ctx->mem_idx);
6770 gen_store_fpr64(ctx, fpu64_T[0], fd);
6775 gen_load_fpr32(fpu32_T[0], fs);
6776 tcg_gen_qemu_st32(fpu32_T[0], cpu_T[0], ctx->mem_idx);
6782 check_cp1_registers(ctx, fs);
6783 gen_load_fpr64(ctx, fpu64_T[0], fs);
6784 tcg_gen_qemu_st64(fpu64_T[0], cpu_T[0], ctx->mem_idx);
6789 check_cp1_64bitmode(ctx);
6790 gen_load_fpr64(ctx, fpu64_T[0], fs);
6791 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], ~0x7);
6792 tcg_gen_qemu_st64(fpu64_T[0], cpu_T[0], ctx->mem_idx);
6798 generate_exception(ctx, EXCP_RI);
6801 MIPS_DEBUG("%s %s, %s(%s)", opn, fregnames[store ? fs : fd],
6802 regnames[index], regnames[base]);
6805 static void gen_flt3_arith (DisasContext *ctx, uint32_t opc,
6806 int fd, int fr, int fs, int ft)
6808 const char *opn = "flt3_arith";
6812 check_cp1_64bitmode(ctx);
6813 gen_load_gpr(cpu_T[0], fr);
6814 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0x7);
6815 gen_load_fpr32(fpu32_T[0], fs);
6816 gen_load_fpr32h(fpu32h_T[0], fs);
6817 gen_load_fpr32(fpu32_T[1], ft);
6818 gen_load_fpr32h(fpu32h_T[1], ft);
6820 int l1 = gen_new_label();
6821 int l2 = gen_new_label();
6823 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 0, l1);
6824 tcg_gen_mov_i32(fpu32_T[2], fpu32_T[0]);
6825 tcg_gen_mov_i32(fpu32h_T[2], fpu32h_T[0]);
6828 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_T[0], 4, l2);
6829 #ifdef TARGET_WORDS_BIGENDIAN
6830 tcg_gen_mov_i32(fpu32h_T[2], fpu32_T[0]);
6831 tcg_gen_mov_i32(fpu32_T[2], fpu32h_T[1]);
6833 tcg_gen_mov_i32(fpu32h_T[2], fpu32_T[1]);
6834 tcg_gen_mov_i32(fpu32_T[2], fpu32h_T[0]);
6838 gen_store_fpr32(fpu32_T[2], fd);
6839 gen_store_fpr32h(fpu32h_T[2], fd);
6844 gen_load_fpr32(fpu32_T[0], fs);
6845 gen_load_fpr32(fpu32_T[1], ft);
6846 gen_load_fpr32(fpu32_T[2], fr);
6847 tcg_gen_helper_0_0(do_float_muladd_s);
6848 gen_store_fpr32(fpu32_T[2], fd);
6853 check_cp1_registers(ctx, fd | fs | ft | fr);
6854 gen_load_fpr64(ctx, fpu64_T[0], fs);
6855 gen_load_fpr64(ctx, fpu64_T[1], ft);
6856 gen_load_fpr64(ctx, fpu64_T[2], fr);
6857 tcg_gen_helper_0_0(do_float_muladd_d);
6858 gen_store_fpr64(ctx, fpu64_T[2], fd);
6862 check_cp1_64bitmode(ctx);
6863 gen_load_fpr32(fpu32_T[0], fs);
6864 gen_load_fpr32h(fpu32h_T[0], fs);
6865 gen_load_fpr32(fpu32_T[1], ft);
6866 gen_load_fpr32h(fpu32h_T[1], ft);
6867 gen_load_fpr32(fpu32_T[2], fr);
6868 gen_load_fpr32h(fpu32h_T[2], fr);
6869 tcg_gen_helper_0_0(do_float_muladd_ps);
6870 gen_store_fpr32(fpu32_T[2], fd);
6871 gen_store_fpr32h(fpu32h_T[2], fd);
6876 gen_load_fpr32(fpu32_T[0], fs);
6877 gen_load_fpr32(fpu32_T[1], ft);
6878 gen_load_fpr32(fpu32_T[2], fr);
6879 tcg_gen_helper_0_0(do_float_mulsub_s);
6880 gen_store_fpr32(fpu32_T[2], fd);
6885 check_cp1_registers(ctx, fd | fs | ft | fr);
6886 gen_load_fpr64(ctx, fpu64_T[0], fs);
6887 gen_load_fpr64(ctx, fpu64_T[1], ft);
6888 gen_load_fpr64(ctx, fpu64_T[2], fr);
6889 tcg_gen_helper_0_0(do_float_mulsub_d);
6890 gen_store_fpr64(ctx, fpu64_T[2], fd);
6894 check_cp1_64bitmode(ctx);
6895 gen_load_fpr32(fpu32_T[0], fs);
6896 gen_load_fpr32h(fpu32h_T[0], fs);
6897 gen_load_fpr32(fpu32_T[1], ft);
6898 gen_load_fpr32h(fpu32h_T[1], ft);
6899 gen_load_fpr32(fpu32_T[2], fr);
6900 gen_load_fpr32h(fpu32h_T[2], fr);
6901 tcg_gen_helper_0_0(do_float_mulsub_ps);
6902 gen_store_fpr32(fpu32_T[2], fd);
6903 gen_store_fpr32h(fpu32h_T[2], fd);
6908 gen_load_fpr32(fpu32_T[0], fs);
6909 gen_load_fpr32(fpu32_T[1], ft);
6910 gen_load_fpr32(fpu32_T[2], fr);
6911 tcg_gen_helper_0_0(do_float_nmuladd_s);
6912 gen_store_fpr32(fpu32_T[2], fd);
6917 check_cp1_registers(ctx, fd | fs | ft | fr);
6918 gen_load_fpr64(ctx, fpu64_T[0], fs);
6919 gen_load_fpr64(ctx, fpu64_T[1], ft);
6920 gen_load_fpr64(ctx, fpu64_T[2], fr);
6921 tcg_gen_helper_0_0(do_float_nmuladd_d);
6922 gen_store_fpr64(ctx, fpu64_T[2], fd);
6926 check_cp1_64bitmode(ctx);
6927 gen_load_fpr32(fpu32_T[0], fs);
6928 gen_load_fpr32h(fpu32h_T[0], fs);
6929 gen_load_fpr32(fpu32_T[1], ft);
6930 gen_load_fpr32h(fpu32h_T[1], ft);
6931 gen_load_fpr32(fpu32_T[2], fr);
6932 gen_load_fpr32h(fpu32h_T[2], fr);
6933 tcg_gen_helper_0_0(do_float_nmuladd_ps);
6934 gen_store_fpr32(fpu32_T[2], fd);
6935 gen_store_fpr32h(fpu32h_T[2], fd);
6940 gen_load_fpr32(fpu32_T[0], fs);
6941 gen_load_fpr32(fpu32_T[1], ft);
6942 gen_load_fpr32(fpu32_T[2], fr);
6943 tcg_gen_helper_0_0(do_float_nmulsub_s);
6944 gen_store_fpr32(fpu32_T[2], fd);
6949 check_cp1_registers(ctx, fd | fs | ft | fr);
6950 gen_load_fpr64(ctx, fpu64_T[0], fs);
6951 gen_load_fpr64(ctx, fpu64_T[1], ft);
6952 gen_load_fpr64(ctx, fpu64_T[2], fr);
6953 tcg_gen_helper_0_0(do_float_nmulsub_d);
6954 gen_store_fpr64(ctx, fpu64_T[2], fd);
6958 check_cp1_64bitmode(ctx);
6959 gen_load_fpr32(fpu32_T[0], fs);
6960 gen_load_fpr32h(fpu32h_T[0], fs);
6961 gen_load_fpr32(fpu32_T[1], ft);
6962 gen_load_fpr32h(fpu32h_T[1], ft);
6963 gen_load_fpr32(fpu32_T[2], fr);
6964 gen_load_fpr32h(fpu32h_T[2], fr);
6965 tcg_gen_helper_0_0(do_float_nmulsub_ps);
6966 gen_store_fpr32(fpu32_T[2], fd);
6967 gen_store_fpr32h(fpu32h_T[2], fd);
6972 generate_exception (ctx, EXCP_RI);
6975 MIPS_DEBUG("%s %s, %s, %s, %s", opn, fregnames[fd], fregnames[fr],
6976 fregnames[fs], fregnames[ft]);
6979 /* ISA extensions (ASEs) */
6980 /* MIPS16 extension to MIPS32 */
6981 /* SmartMIPS extension to MIPS32 */
6983 #if defined(TARGET_MIPS64)
6985 /* MDMX extension to MIPS64 */
6989 static void decode_opc (CPUState *env, DisasContext *ctx)
6993 uint32_t op, op1, op2;
6996 /* make sure instructions are on a word boundary */
6997 if (ctx->pc & 0x3) {
6998 env->CP0_BadVAddr = ctx->pc;
6999 generate_exception(ctx, EXCP_AdEL);
7003 /* Handle blikely not taken case */
7004 if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
7005 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL);
7006 int l1 = gen_new_label();
7008 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx ")", ctx->pc + 4);
7009 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
7010 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
7011 tcg_temp_free(r_tmp);
7013 TCGv r_tmp2 = tcg_temp_new(TCG_TYPE_I32);
7015 tcg_gen_movi_i32(r_tmp2, ctx->hflags & ~MIPS_HFLAG_BMASK);
7016 tcg_gen_st_i32(r_tmp2, cpu_env, offsetof(CPUState, hflags));
7017 tcg_temp_free(r_tmp2);
7019 gen_goto_tb(ctx, 1, ctx->pc + 4);
7022 op = MASK_OP_MAJOR(ctx->opcode);
7023 rs = (ctx->opcode >> 21) & 0x1f;
7024 rt = (ctx->opcode >> 16) & 0x1f;
7025 rd = (ctx->opcode >> 11) & 0x1f;
7026 sa = (ctx->opcode >> 6) & 0x1f;
7027 imm = (int16_t)ctx->opcode;
7030 op1 = MASK_SPECIAL(ctx->opcode);
7032 case OPC_SLL: /* Arithmetic with immediate */
7033 case OPC_SRL ... OPC_SRA:
7034 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7036 case OPC_MOVZ ... OPC_MOVN:
7037 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7038 case OPC_SLLV: /* Arithmetic */
7039 case OPC_SRLV ... OPC_SRAV:
7040 case OPC_ADD ... OPC_NOR:
7041 case OPC_SLT ... OPC_SLTU:
7042 gen_arith(env, ctx, op1, rd, rs, rt);
7044 case OPC_MULT ... OPC_DIVU:
7046 check_insn(env, ctx, INSN_VR54XX);
7047 op1 = MASK_MUL_VR54XX(ctx->opcode);
7048 gen_mul_vr54xx(ctx, op1, rd, rs, rt);
7050 gen_muldiv(ctx, op1, rs, rt);
7052 case OPC_JR ... OPC_JALR:
7053 gen_compute_branch(ctx, op1, rs, rd, sa);
7055 case OPC_TGE ... OPC_TEQ: /* Traps */
7057 gen_trap(ctx, op1, rs, rt, -1);
7059 case OPC_MFHI: /* Move from HI/LO */
7061 gen_HILO(ctx, op1, rd);
7064 case OPC_MTLO: /* Move to HI/LO */
7065 gen_HILO(ctx, op1, rs);
7067 case OPC_PMON: /* Pmon entry point, also R4010 selsl */
7068 #ifdef MIPS_STRICT_STANDARD
7069 MIPS_INVAL("PMON / selsl");
7070 generate_exception(ctx, EXCP_RI);
7072 tcg_gen_helper_0_1i(do_pmon, sa);
7076 generate_exception(ctx, EXCP_SYSCALL);
7079 generate_exception(ctx, EXCP_BREAK);
7082 #ifdef MIPS_STRICT_STANDARD
7084 generate_exception(ctx, EXCP_RI);
7086 /* Implemented as RI exception for now. */
7087 MIPS_INVAL("spim (unofficial)");
7088 generate_exception(ctx, EXCP_RI);
7096 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7097 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7098 save_cpu_state(ctx, 1);
7099 check_cp1_enabled(ctx);
7100 gen_movci(ctx, rd, rs, (ctx->opcode >> 18) & 0x7,
7101 (ctx->opcode >> 16) & 1);
7103 generate_exception_err(ctx, EXCP_CpU, 1);
7107 #if defined(TARGET_MIPS64)
7108 /* MIPS64 specific opcodes */
7110 case OPC_DSRL ... OPC_DSRA:
7112 case OPC_DSRL32 ... OPC_DSRA32:
7113 check_insn(env, ctx, ISA_MIPS3);
7115 gen_arith_imm(env, ctx, op1, rd, rt, sa);
7118 case OPC_DSRLV ... OPC_DSRAV:
7119 case OPC_DADD ... OPC_DSUBU:
7120 check_insn(env, ctx, ISA_MIPS3);
7122 gen_arith(env, ctx, op1, rd, rs, rt);
7124 case OPC_DMULT ... OPC_DDIVU:
7125 check_insn(env, ctx, ISA_MIPS3);
7127 gen_muldiv(ctx, op1, rs, rt);
7130 default: /* Invalid */
7131 MIPS_INVAL("special");
7132 generate_exception(ctx, EXCP_RI);
7137 op1 = MASK_SPECIAL2(ctx->opcode);
7139 case OPC_MADD ... OPC_MADDU: /* Multiply and add/sub */
7140 case OPC_MSUB ... OPC_MSUBU:
7141 check_insn(env, ctx, ISA_MIPS32);
7142 gen_muldiv(ctx, op1, rs, rt);
7145 gen_arith(env, ctx, op1, rd, rs, rt);
7147 case OPC_CLZ ... OPC_CLO:
7148 check_insn(env, ctx, ISA_MIPS32);
7149 gen_cl(ctx, op1, rd, rs);
7152 /* XXX: not clear which exception should be raised
7153 * when in debug mode...
7155 check_insn(env, ctx, ISA_MIPS32);
7156 if (!(ctx->hflags & MIPS_HFLAG_DM)) {
7157 generate_exception(ctx, EXCP_DBp);
7159 generate_exception(ctx, EXCP_DBp);
7163 #if defined(TARGET_MIPS64)
7164 case OPC_DCLZ ... OPC_DCLO:
7165 check_insn(env, ctx, ISA_MIPS64);
7167 gen_cl(ctx, op1, rd, rs);
7170 default: /* Invalid */
7171 MIPS_INVAL("special2");
7172 generate_exception(ctx, EXCP_RI);
7177 op1 = MASK_SPECIAL3(ctx->opcode);
7181 check_insn(env, ctx, ISA_MIPS32R2);
7182 gen_bitops(ctx, op1, rt, rs, sa, rd);
7185 check_insn(env, ctx, ISA_MIPS32R2);
7186 op2 = MASK_BSHFL(ctx->opcode);
7189 gen_load_gpr(cpu_T[1], rt);
7190 tcg_gen_helper_0_0(do_wsbh);
7193 gen_load_gpr(cpu_T[1], rt);
7194 tcg_gen_ext8s_tl(cpu_T[0], cpu_T[1]);
7197 gen_load_gpr(cpu_T[1], rt);
7198 tcg_gen_ext16s_tl(cpu_T[0], cpu_T[1]);
7200 default: /* Invalid */
7201 MIPS_INVAL("bshfl");
7202 generate_exception(ctx, EXCP_RI);
7205 gen_store_gpr(cpu_T[0], rd);
7208 check_insn(env, ctx, ISA_MIPS32R2);
7211 save_cpu_state(ctx, 1);
7212 tcg_gen_helper_0_0(do_rdhwr_cpunum);
7215 save_cpu_state(ctx, 1);
7216 tcg_gen_helper_0_0(do_rdhwr_synci_step);
7219 save_cpu_state(ctx, 1);
7220 tcg_gen_helper_0_0(do_rdhwr_cc);
7223 save_cpu_state(ctx, 1);
7224 tcg_gen_helper_0_0(do_rdhwr_ccres);
7227 #if defined (CONFIG_USER_ONLY)
7228 tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUState, tls_value));
7231 /* XXX: Some CPUs implement this in hardware. Not supported yet. */
7233 default: /* Invalid */
7234 MIPS_INVAL("rdhwr");
7235 generate_exception(ctx, EXCP_RI);
7238 gen_store_gpr(cpu_T[0], rt);
7241 check_insn(env, ctx, ASE_MT);
7242 gen_load_gpr(cpu_T[0], rt);
7243 gen_load_gpr(cpu_T[1], rs);
7244 tcg_gen_helper_0_0(do_fork);
7247 check_insn(env, ctx, ASE_MT);
7248 gen_load_gpr(cpu_T[0], rs);
7249 tcg_gen_helper_0_0(do_yield);
7250 gen_store_gpr(cpu_T[0], rd);
7252 #if defined(TARGET_MIPS64)
7253 case OPC_DEXTM ... OPC_DEXT:
7254 case OPC_DINSM ... OPC_DINS:
7255 check_insn(env, ctx, ISA_MIPS64R2);
7257 gen_bitops(ctx, op1, rt, rs, sa, rd);
7260 check_insn(env, ctx, ISA_MIPS64R2);
7262 op2 = MASK_DBSHFL(ctx->opcode);
7265 gen_load_gpr(cpu_T[1], rt);
7266 tcg_gen_helper_0_0(do_dsbh);
7269 gen_load_gpr(cpu_T[1], rt);
7270 tcg_gen_helper_0_0(do_dshd);
7272 default: /* Invalid */
7273 MIPS_INVAL("dbshfl");
7274 generate_exception(ctx, EXCP_RI);
7277 gen_store_gpr(cpu_T[0], rd);
7280 default: /* Invalid */
7281 MIPS_INVAL("special3");
7282 generate_exception(ctx, EXCP_RI);
7287 op1 = MASK_REGIMM(ctx->opcode);
7289 case OPC_BLTZ ... OPC_BGEZL: /* REGIMM branches */
7290 case OPC_BLTZAL ... OPC_BGEZALL:
7291 gen_compute_branch(ctx, op1, rs, -1, imm << 2);
7293 case OPC_TGEI ... OPC_TEQI: /* REGIMM traps */
7295 gen_trap(ctx, op1, rs, -1, imm);
7298 check_insn(env, ctx, ISA_MIPS32R2);
7301 default: /* Invalid */
7302 MIPS_INVAL("regimm");
7303 generate_exception(ctx, EXCP_RI);
7308 check_cp0_enabled(ctx);
7309 op1 = MASK_CP0(ctx->opcode);
7315 #if defined(TARGET_MIPS64)
7319 #ifndef CONFIG_USER_ONLY
7320 gen_cp0(env, ctx, op1, rt, rd);
7323 case OPC_C0_FIRST ... OPC_C0_LAST:
7324 #ifndef CONFIG_USER_ONLY
7325 gen_cp0(env, ctx, MASK_C0(ctx->opcode), rt, rd);
7329 op2 = MASK_MFMC0(ctx->opcode);
7332 check_insn(env, ctx, ASE_MT);
7333 tcg_gen_helper_0_0(do_dmt);
7336 check_insn(env, ctx, ASE_MT);
7337 tcg_gen_helper_0_0(do_emt);
7340 check_insn(env, ctx, ASE_MT);
7341 tcg_gen_helper_0_0(do_dvpe);
7344 check_insn(env, ctx, ASE_MT);
7345 tcg_gen_helper_0_0(do_evpe);
7348 check_insn(env, ctx, ISA_MIPS32R2);
7349 save_cpu_state(ctx, 1);
7350 tcg_gen_helper_0_0(do_di);
7351 /* Stop translation as we may have switched the execution mode */
7352 ctx->bstate = BS_STOP;
7355 check_insn(env, ctx, ISA_MIPS32R2);
7356 save_cpu_state(ctx, 1);
7357 tcg_gen_helper_0_0(do_ei);
7358 /* Stop translation as we may have switched the execution mode */
7359 ctx->bstate = BS_STOP;
7361 default: /* Invalid */
7362 MIPS_INVAL("mfmc0");
7363 generate_exception(ctx, EXCP_RI);
7366 gen_store_gpr(cpu_T[0], rt);
7369 check_insn(env, ctx, ISA_MIPS32R2);
7370 gen_load_srsgpr(cpu_T[0], rt);
7371 gen_store_gpr(cpu_T[0], rd);
7374 check_insn(env, ctx, ISA_MIPS32R2);
7375 gen_load_gpr(cpu_T[0], rt);
7376 gen_store_srsgpr(cpu_T[0], rd);
7380 generate_exception(ctx, EXCP_RI);
7384 case OPC_ADDI ... OPC_LUI: /* Arithmetic with immediate opcode */
7385 gen_arith_imm(env, ctx, op, rt, rs, imm);
7387 case OPC_J ... OPC_JAL: /* Jump */
7388 offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2;
7389 gen_compute_branch(ctx, op, rs, rt, offset);
7391 case OPC_BEQ ... OPC_BGTZ: /* Branch */
7392 case OPC_BEQL ... OPC_BGTZL:
7393 gen_compute_branch(ctx, op, rs, rt, imm << 2);
7395 case OPC_LB ... OPC_LWR: /* Load and stores */
7396 case OPC_SB ... OPC_SW:
7400 gen_ldst(ctx, op, rt, rs, imm);
7403 check_insn(env, ctx, ISA_MIPS3 | ISA_MIPS32);
7407 check_insn(env, ctx, ISA_MIPS4 | ISA_MIPS32);
7411 /* Floating point (COP1). */
7416 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7417 save_cpu_state(ctx, 1);
7418 check_cp1_enabled(ctx);
7419 gen_flt_ldst(ctx, op, rt, rs, imm);
7421 generate_exception_err(ctx, EXCP_CpU, 1);
7426 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7427 save_cpu_state(ctx, 1);
7428 check_cp1_enabled(ctx);
7429 op1 = MASK_CP1(ctx->opcode);
7433 check_insn(env, ctx, ISA_MIPS32R2);
7438 gen_cp1(ctx, op1, rt, rd);
7440 #if defined(TARGET_MIPS64)
7443 check_insn(env, ctx, ISA_MIPS3);
7444 gen_cp1(ctx, op1, rt, rd);
7450 check_insn(env, ctx, ASE_MIPS3D);
7453 gen_compute_branch1(env, ctx, MASK_BC1(ctx->opcode),
7454 (rt >> 2) & 0x7, imm << 2);
7461 gen_farith(ctx, MASK_CP1_FUNC(ctx->opcode), rt, rd, sa,
7466 generate_exception (ctx, EXCP_RI);
7470 generate_exception_err(ctx, EXCP_CpU, 1);
7480 /* COP2: Not implemented. */
7481 generate_exception_err(ctx, EXCP_CpU, 2);
7485 if (env->CP0_Config1 & (1 << CP0C1_FP)) {
7486 save_cpu_state(ctx, 1);
7487 check_cp1_enabled(ctx);
7488 op1 = MASK_CP3(ctx->opcode);
7496 gen_flt3_ldst(ctx, op1, sa, rd, rs, rt);
7514 gen_flt3_arith(ctx, op1, sa, rs, rd, rt);
7518 generate_exception (ctx, EXCP_RI);
7522 generate_exception_err(ctx, EXCP_CpU, 1);
7526 #if defined(TARGET_MIPS64)
7527 /* MIPS64 opcodes */
7529 case OPC_LDL ... OPC_LDR:
7530 case OPC_SDL ... OPC_SDR:
7535 check_insn(env, ctx, ISA_MIPS3);
7537 gen_ldst(ctx, op, rt, rs, imm);
7539 case OPC_DADDI ... OPC_DADDIU:
7540 check_insn(env, ctx, ISA_MIPS3);
7542 gen_arith_imm(env, ctx, op, rt, rs, imm);
7546 check_insn(env, ctx, ASE_MIPS16);
7547 /* MIPS16: Not implemented. */
7549 check_insn(env, ctx, ASE_MDMX);
7550 /* MDMX: Not implemented. */
7551 default: /* Invalid */
7552 MIPS_INVAL("major opcode");
7553 generate_exception(ctx, EXCP_RI);
7556 if (ctx->hflags & MIPS_HFLAG_BMASK) {
7557 int hflags = ctx->hflags & MIPS_HFLAG_BMASK;
7558 /* Branches completion */
7559 ctx->hflags &= ~MIPS_HFLAG_BMASK;
7560 ctx->bstate = BS_BRANCH;
7561 save_cpu_state(ctx, 0);
7564 /* unconditional branch */
7565 MIPS_DEBUG("unconditional branch");
7566 gen_goto_tb(ctx, 0, ctx->btarget);
7569 /* blikely taken case */
7570 MIPS_DEBUG("blikely branch taken");
7571 gen_goto_tb(ctx, 0, ctx->btarget);
7574 /* Conditional branch */
7575 MIPS_DEBUG("conditional branch");
7577 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL);
7578 int l1 = gen_new_label();
7580 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, bcond));
7581 tcg_gen_brcondi_tl(TCG_COND_NE, r_tmp, 0, l1);
7582 tcg_temp_free(r_tmp);
7583 gen_goto_tb(ctx, 1, ctx->pc + 4);
7585 gen_goto_tb(ctx, 0, ctx->btarget);
7589 /* unconditional branch to register */
7590 MIPS_DEBUG("branch to register");
7595 MIPS_DEBUG("unknown branch");
7601 static always_inline int
7602 gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb,
7606 target_ulong pc_start;
7607 uint16_t *gen_opc_end;
7610 if (search_pc && loglevel)
7611 fprintf (logfile, "search pc %d\n", search_pc);
7614 /* Leave some spare opc slots for branch handling. */
7615 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE - 16;
7619 ctx.bstate = BS_NONE;
7620 /* Restore delay slot state from the tb context. */
7621 ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */
7622 restore_cpu_state(env, &ctx);
7623 #if defined(CONFIG_USER_ONLY)
7624 ctx.mem_idx = MIPS_HFLAG_UM;
7626 ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU;
7629 if (loglevel & CPU_LOG_TB_CPU) {
7630 fprintf(logfile, "------------------------------------------------\n");
7631 /* FIXME: This may print out stale hflags from env... */
7632 cpu_dump_state(env, logfile, fprintf, 0);
7635 #ifdef MIPS_DEBUG_DISAS
7636 if (loglevel & CPU_LOG_TB_IN_ASM)
7637 fprintf(logfile, "\ntb %p idx %d hflags %04x\n",
7638 tb, ctx.mem_idx, ctx.hflags);
7640 while (ctx.bstate == BS_NONE) {
7641 if (env->nb_breakpoints > 0) {
7642 for(j = 0; j < env->nb_breakpoints; j++) {
7643 if (env->breakpoints[j] == ctx.pc) {
7644 save_cpu_state(&ctx, 1);
7645 ctx.bstate = BS_BRANCH;
7646 tcg_gen_helper_0_1i(do_raise_exception, EXCP_DEBUG);
7647 /* Include the breakpoint location or the tb won't
7648 * be flushed when it must be. */
7650 goto done_generating;
7656 j = gen_opc_ptr - gen_opc_buf;
7660 gen_opc_instr_start[lj++] = 0;
7662 gen_opc_pc[lj] = ctx.pc;
7663 gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
7664 gen_opc_instr_start[lj] = 1;
7666 ctx.opcode = ldl_code(ctx.pc);
7667 decode_opc(env, &ctx);
7670 if (env->singlestep_enabled)
7673 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
7676 if (gen_opc_ptr >= gen_opc_end)
7679 if (gen_opc_ptr >= gen_opc_end)
7682 #if defined (MIPS_SINGLE_STEP)
7686 if (env->singlestep_enabled) {
7687 save_cpu_state(&ctx, ctx.bstate == BS_NONE);
7688 tcg_gen_helper_0_1i(do_raise_exception, EXCP_DEBUG);
7690 switch (ctx.bstate) {
7692 tcg_gen_helper_0_0(do_interrupt_restart);
7693 gen_goto_tb(&ctx, 0, ctx.pc);
7696 save_cpu_state(&ctx, 0);
7697 gen_goto_tb(&ctx, 0, ctx.pc);
7700 tcg_gen_helper_0_0(do_interrupt_restart);
7709 *gen_opc_ptr = INDEX_op_end;
7711 j = gen_opc_ptr - gen_opc_buf;
7714 gen_opc_instr_start[lj++] = 0;
7716 tb->size = ctx.pc - pc_start;
7719 #if defined MIPS_DEBUG_DISAS
7720 if (loglevel & CPU_LOG_TB_IN_ASM)
7721 fprintf(logfile, "\n");
7723 if (loglevel & CPU_LOG_TB_IN_ASM) {
7724 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
7725 target_disas(logfile, pc_start, ctx.pc - pc_start, 0);
7726 fprintf(logfile, "\n");
7728 if (loglevel & CPU_LOG_TB_CPU) {
7729 fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags);
7736 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
7738 return gen_intermediate_code_internal(env, tb, 0);
7741 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
7743 return gen_intermediate_code_internal(env, tb, 1);
7746 void fpu_dump_state(CPUState *env, FILE *f,
7747 int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
7751 int is_fpu64 = !!(env->hflags & MIPS_HFLAG_F64);
7753 #define printfpr(fp) \
7756 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
7757 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
7758 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
7761 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
7762 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
7763 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
7764 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
7765 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
7770 fpu_fprintf(f, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
7771 env->fpu->fcr0, env->fpu->fcr31, is_fpu64, env->fpu->fp_status,
7772 get_float_exception_flags(&env->fpu->fp_status));
7773 fpu_fprintf(f, "FT0: "); printfpr(&env->ft0);
7774 fpu_fprintf(f, "FT1: "); printfpr(&env->ft1);
7775 fpu_fprintf(f, "FT2: "); printfpr(&env->ft2);
7776 for (i = 0; i < 32; (is_fpu64) ? i++ : (i += 2)) {
7777 fpu_fprintf(f, "%3s: ", fregnames[i]);
7778 printfpr(&env->fpu->fpr[i]);
7784 void dump_fpu (CPUState *env)
7788 "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx
7789 " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx
7791 env->PC[env->current_tc], env->HI[env->current_tc][0],
7792 env->LO[env->current_tc][0], env->hflags, env->btarget,
7794 fpu_dump_state(env, logfile, fprintf, 0);
7798 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7799 /* Debug help: The architecture requires 32bit code to maintain proper
7800 sign-extened values on 64bit machines. */
7802 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
7804 void cpu_mips_check_sign_extensions (CPUState *env, FILE *f,
7805 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
7810 if (!SIGN_EXT_P(env->PC[env->current_tc]))
7811 cpu_fprintf(f, "BROKEN: pc=0x" TARGET_FMT_lx "\n", env->PC[env->current_tc]);
7812 if (!SIGN_EXT_P(env->HI[env->current_tc][0]))
7813 cpu_fprintf(f, "BROKEN: HI=0x" TARGET_FMT_lx "\n", env->HI[env->current_tc][0]);
7814 if (!SIGN_EXT_P(env->LO[env->current_tc][0]))
7815 cpu_fprintf(f, "BROKEN: LO=0x" TARGET_FMT_lx "\n", env->LO[env->current_tc][0]);
7816 if (!SIGN_EXT_P(env->btarget))
7817 cpu_fprintf(f, "BROKEN: btarget=0x" TARGET_FMT_lx "\n", env->btarget);
7819 for (i = 0; i < 32; i++) {
7820 if (!SIGN_EXT_P(env->gpr[env->current_tc][i]))
7821 cpu_fprintf(f, "BROKEN: %s=0x" TARGET_FMT_lx "\n", regnames[i], env->gpr[env->current_tc][i]);
7824 if (!SIGN_EXT_P(env->CP0_EPC))
7825 cpu_fprintf(f, "BROKEN: EPC=0x" TARGET_FMT_lx "\n", env->CP0_EPC);
7826 if (!SIGN_EXT_P(env->CP0_LLAddr))
7827 cpu_fprintf(f, "BROKEN: LLAddr=0x" TARGET_FMT_lx "\n", env->CP0_LLAddr);
7831 void cpu_dump_state (CPUState *env, FILE *f,
7832 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
7837 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",
7838 env->PC[env->current_tc], env->HI[env->current_tc], env->LO[env->current_tc], env->hflags, env->btarget, env->bcond);
7839 for (i = 0; i < 32; i++) {
7841 cpu_fprintf(f, "GPR%02d:", i);
7842 cpu_fprintf(f, " %s " TARGET_FMT_lx, regnames[i], env->gpr[env->current_tc][i]);
7844 cpu_fprintf(f, "\n");
7847 cpu_fprintf(f, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx "\n",
7848 env->CP0_Status, env->CP0_Cause, env->CP0_EPC);
7849 cpu_fprintf(f, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx "\n",
7850 env->CP0_Config0, env->CP0_Config1, env->CP0_LLAddr);
7851 if (env->hflags & MIPS_HFLAG_FPU)
7852 fpu_dump_state(env, f, cpu_fprintf, flags);
7853 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
7854 cpu_mips_check_sign_extensions(env, f, cpu_fprintf, flags);
7858 static void mips_tcg_init(void)
7862 /* Initialize various static tables. */
7866 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
7867 current_tc_gprs = tcg_global_mem_new(TCG_TYPE_PTR,
7869 offsetof(CPUState, current_tc_gprs),
7871 current_tc_hi = tcg_global_mem_new(TCG_TYPE_PTR,
7873 offsetof(CPUState, current_tc_hi),
7875 current_fpu = tcg_global_mem_new(TCG_TYPE_PTR,
7877 offsetof(CPUState, fpu),
7879 #if TARGET_LONG_BITS > HOST_LONG_BITS
7880 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
7881 TCG_AREG0, offsetof(CPUState, t0), "T0");
7882 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
7883 TCG_AREG0, offsetof(CPUState, t1), "T1");
7885 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
7886 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
7889 /* register helpers */
7891 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
7894 fpu32_T[0] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft0.w[FP_ENDIAN_IDX]), "WT0");
7895 fpu32_T[1] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft1.w[FP_ENDIAN_IDX]), "WT1");
7896 fpu32_T[2] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft2.w[FP_ENDIAN_IDX]), "WT2");
7897 fpu64_T[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft0.d), "DT0");
7898 fpu64_T[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft1.d), "DT1");
7899 fpu64_T[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0, offsetof(CPUState, ft2.d), "DT2");
7900 fpu32h_T[0] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft0.w[!FP_ENDIAN_IDX]), "WTH0");
7901 fpu32h_T[1] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft1.w[!FP_ENDIAN_IDX]), "WTH1");
7902 fpu32h_T[2] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0, offsetof(CPUState, ft2.w[!FP_ENDIAN_IDX]), "WTH2");
7907 #include "translate_init.c"
7909 CPUMIPSState *cpu_mips_init (const char *cpu_model)
7912 const mips_def_t *def;
7914 def = cpu_mips_find_by_name(cpu_model);
7917 env = qemu_mallocz(sizeof(CPUMIPSState));
7920 env->cpu_model = def;
7923 env->cpu_model_str = cpu_model;
7929 void cpu_reset (CPUMIPSState *env)
7931 memset(env, 0, offsetof(CPUMIPSState, breakpoints));
7936 #if !defined(CONFIG_USER_ONLY)
7937 if (env->hflags & MIPS_HFLAG_BMASK) {
7938 /* If the exception was raised from a delay slot,
7939 * come back to the jump. */
7940 env->CP0_ErrorEPC = env->PC[env->current_tc] - 4;
7942 env->CP0_ErrorEPC = env->PC[env->current_tc];
7944 env->PC[env->current_tc] = (int32_t)0xBFC00000;
7946 /* SMP not implemented */
7947 env->CP0_EBase = 0x80000000;
7948 env->CP0_Status = (1 << CP0St_BEV) | (1 << CP0St_ERL);
7949 /* vectored interrupts not implemented, timer on int 7,
7950 no performance counters. */
7951 env->CP0_IntCtl = 0xe0000000;
7955 for (i = 0; i < 7; i++) {
7956 env->CP0_WatchLo[i] = 0;
7957 env->CP0_WatchHi[i] = 0x80000000;
7959 env->CP0_WatchLo[7] = 0;
7960 env->CP0_WatchHi[7] = 0;
7962 /* Count register increments in debug mode, EJTAG version 1 */
7963 env->CP0_Debug = (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);
7965 env->exception_index = EXCP_NONE;
7966 #if defined(CONFIG_USER_ONLY)
7967 env->hflags = MIPS_HFLAG_UM;
7968 env->user_mode_only = 1;
7970 env->hflags = MIPS_HFLAG_CP0;
7972 cpu_mips_register(env, env->cpu_model);
7975 void gen_pc_load(CPUState *env, TranslationBlock *tb,
7976 unsigned long searched_pc, int pc_pos, void *puc)
7978 env->PC[env->current_tc] = gen_opc_pc[pc_pos];
7979 env->hflags &= ~MIPS_HFLAG_BMASK;
7980 env->hflags |= gen_opc_hflags[pc_pos];