2 * MIPS32 emulation for qemu: main translation routines.
4 * Copyright (c) 2004-2005 Jocelyn Mayer
5 * Copyright (c) 2006 Marius Groeger (FPU operations)
6 * Copyright (c) 2006 Thiemo Seufer (MIPS32R2 support)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "qemu-common.h"
36 //#define MIPS_DEBUG_DISAS
37 //#define MIPS_DEBUG_SIGN_EXTENSIONS
38 //#define MIPS_SINGLE_STEP
40 /* MIPS major opcodes */
41 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
44 /* indirect opcode tables */
45 OPC_SPECIAL
= (0x00 << 26),
46 OPC_REGIMM
= (0x01 << 26),
47 OPC_CP0
= (0x10 << 26),
48 OPC_CP1
= (0x11 << 26),
49 OPC_CP2
= (0x12 << 26),
50 OPC_CP3
= (0x13 << 26),
51 OPC_SPECIAL2
= (0x1C << 26),
52 OPC_SPECIAL3
= (0x1F << 26),
53 /* arithmetic with immediate */
54 OPC_ADDI
= (0x08 << 26),
55 OPC_ADDIU
= (0x09 << 26),
56 OPC_SLTI
= (0x0A << 26),
57 OPC_SLTIU
= (0x0B << 26),
58 OPC_ANDI
= (0x0C << 26),
59 OPC_ORI
= (0x0D << 26),
60 OPC_XORI
= (0x0E << 26),
61 OPC_LUI
= (0x0F << 26),
62 OPC_DADDI
= (0x18 << 26),
63 OPC_DADDIU
= (0x19 << 26),
64 /* Jump and branches */
66 OPC_JAL
= (0x03 << 26),
67 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
68 OPC_BEQL
= (0x14 << 26),
69 OPC_BNE
= (0x05 << 26),
70 OPC_BNEL
= (0x15 << 26),
71 OPC_BLEZ
= (0x06 << 26),
72 OPC_BLEZL
= (0x16 << 26),
73 OPC_BGTZ
= (0x07 << 26),
74 OPC_BGTZL
= (0x17 << 26),
75 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
77 OPC_LDL
= (0x1A << 26),
78 OPC_LDR
= (0x1B << 26),
79 OPC_LB
= (0x20 << 26),
80 OPC_LH
= (0x21 << 26),
81 OPC_LWL
= (0x22 << 26),
82 OPC_LW
= (0x23 << 26),
83 OPC_LBU
= (0x24 << 26),
84 OPC_LHU
= (0x25 << 26),
85 OPC_LWR
= (0x26 << 26),
86 OPC_LWU
= (0x27 << 26),
87 OPC_SB
= (0x28 << 26),
88 OPC_SH
= (0x29 << 26),
89 OPC_SWL
= (0x2A << 26),
90 OPC_SW
= (0x2B << 26),
91 OPC_SDL
= (0x2C << 26),
92 OPC_SDR
= (0x2D << 26),
93 OPC_SWR
= (0x2E << 26),
94 OPC_LL
= (0x30 << 26),
95 OPC_LLD
= (0x34 << 26),
96 OPC_LD
= (0x37 << 26),
97 OPC_SC
= (0x38 << 26),
98 OPC_SCD
= (0x3C << 26),
99 OPC_SD
= (0x3F << 26),
100 /* Floating point load/store */
101 OPC_LWC1
= (0x31 << 26),
102 OPC_LWC2
= (0x32 << 26),
103 OPC_LDC1
= (0x35 << 26),
104 OPC_LDC2
= (0x36 << 26),
105 OPC_SWC1
= (0x39 << 26),
106 OPC_SWC2
= (0x3A << 26),
107 OPC_SDC1
= (0x3D << 26),
108 OPC_SDC2
= (0x3E << 26),
109 /* MDMX ASE specific */
110 OPC_MDMX
= (0x1E << 26),
111 /* Cache and prefetch */
112 OPC_CACHE
= (0x2F << 26),
113 OPC_PREF
= (0x33 << 26),
114 /* Reserved major opcode */
115 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
118 /* MIPS special opcodes */
119 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
123 OPC_SLL
= 0x00 | OPC_SPECIAL
,
124 /* NOP is SLL r0, r0, 0 */
125 /* SSNOP is SLL r0, r0, 1 */
126 /* EHB is SLL r0, r0, 3 */
127 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
128 OPC_SRA
= 0x03 | OPC_SPECIAL
,
129 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
130 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
131 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
132 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
133 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
134 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
135 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
136 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
137 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
138 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
139 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
140 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
141 /* Multiplication / division */
142 OPC_MULT
= 0x18 | OPC_SPECIAL
,
143 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
144 OPC_DIV
= 0x1A | OPC_SPECIAL
,
145 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
146 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
147 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
148 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
149 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
150 /* 2 registers arithmetic / logic */
151 OPC_ADD
= 0x20 | OPC_SPECIAL
,
152 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
153 OPC_SUB
= 0x22 | OPC_SPECIAL
,
154 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
155 OPC_AND
= 0x24 | OPC_SPECIAL
,
156 OPC_OR
= 0x25 | OPC_SPECIAL
,
157 OPC_XOR
= 0x26 | OPC_SPECIAL
,
158 OPC_NOR
= 0x27 | OPC_SPECIAL
,
159 OPC_SLT
= 0x2A | OPC_SPECIAL
,
160 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
161 OPC_DADD
= 0x2C | OPC_SPECIAL
,
162 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
163 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
164 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
166 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
167 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
169 OPC_TGE
= 0x30 | OPC_SPECIAL
,
170 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
171 OPC_TLT
= 0x32 | OPC_SPECIAL
,
172 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
173 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
174 OPC_TNE
= 0x36 | OPC_SPECIAL
,
175 /* HI / LO registers load & stores */
176 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
177 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
178 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
179 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
180 /* Conditional moves */
181 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
182 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
184 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
187 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
188 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
189 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
190 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
191 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
193 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
194 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
195 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
196 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
197 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
198 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
199 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
202 /* Multiplication variants of the vr54xx. */
203 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
206 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
207 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
208 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
209 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
210 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
211 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
212 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
213 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
214 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
215 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
216 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
217 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
218 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
219 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
222 /* REGIMM (rt field) opcodes */
223 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
226 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
227 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
228 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
229 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
230 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
231 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
232 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
233 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
234 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
235 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
236 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
237 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
238 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
239 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
240 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
243 /* Special2 opcodes */
244 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
247 /* Multiply & xxx operations */
248 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
249 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
250 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
251 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
252 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
254 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
255 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
256 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
257 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
259 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
262 /* Special3 opcodes */
263 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
266 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
267 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
268 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
269 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
270 OPC_INS
= 0x04 | OPC_SPECIAL3
,
271 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
272 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
273 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
274 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
275 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
276 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
277 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
278 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
282 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
285 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
286 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
287 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
291 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
294 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
295 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
298 /* Coprocessor 0 (rs field) */
299 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
302 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
303 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
304 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
305 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
306 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
307 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
308 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
309 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
310 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
311 OPC_C0
= (0x10 << 21) | OPC_CP0
,
312 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
313 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
317 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
320 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
321 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
322 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
323 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
324 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
325 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
328 /* Coprocessor 0 (with rs == C0) */
329 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
332 OPC_TLBR
= 0x01 | OPC_C0
,
333 OPC_TLBWI
= 0x02 | OPC_C0
,
334 OPC_TLBWR
= 0x06 | OPC_C0
,
335 OPC_TLBP
= 0x08 | OPC_C0
,
336 OPC_RFE
= 0x10 | OPC_C0
,
337 OPC_ERET
= 0x18 | OPC_C0
,
338 OPC_DERET
= 0x1F | OPC_C0
,
339 OPC_WAIT
= 0x20 | OPC_C0
,
342 /* Coprocessor 1 (rs field) */
343 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
346 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
347 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
348 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
349 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
350 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
351 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
352 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
353 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
354 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
355 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
356 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
357 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
358 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
359 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
360 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
361 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
362 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
363 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
366 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
367 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
370 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
371 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
372 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
373 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
377 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
378 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
382 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
383 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
386 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
389 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
390 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
391 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
392 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
393 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
394 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
395 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
396 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
397 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
400 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
403 OPC_LWXC1
= 0x00 | OPC_CP3
,
404 OPC_LDXC1
= 0x01 | OPC_CP3
,
405 OPC_LUXC1
= 0x05 | OPC_CP3
,
406 OPC_SWXC1
= 0x08 | OPC_CP3
,
407 OPC_SDXC1
= 0x09 | OPC_CP3
,
408 OPC_SUXC1
= 0x0D | OPC_CP3
,
409 OPC_PREFX
= 0x0F | OPC_CP3
,
410 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
411 OPC_MADD_S
= 0x20 | OPC_CP3
,
412 OPC_MADD_D
= 0x21 | OPC_CP3
,
413 OPC_MADD_PS
= 0x26 | OPC_CP3
,
414 OPC_MSUB_S
= 0x28 | OPC_CP3
,
415 OPC_MSUB_D
= 0x29 | OPC_CP3
,
416 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
417 OPC_NMADD_S
= 0x30 | OPC_CP3
,
418 OPC_NMADD_D
= 0x31 | OPC_CP3
,
419 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
420 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
421 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
422 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
425 /* global register indices */
426 static TCGv cpu_env
, bcond
, btarget
, current_fpu
;
428 #include "gen-icount.h"
430 static inline void tcg_gen_helper_0_i(void *func
, TCGv arg
)
432 TCGv tmp
= tcg_const_i32(arg
);
434 tcg_gen_helper_0_1(func
, tmp
);
438 static inline void tcg_gen_helper_0_ii(void *func
, TCGv arg1
, TCGv arg2
)
440 TCGv tmp1
= tcg_const_i32(arg1
);
441 TCGv tmp2
= tcg_const_i32(arg2
);
443 tcg_gen_helper_0_2(func
, tmp1
, tmp2
);
448 static inline void tcg_gen_helper_0_1i(void *func
, TCGv arg1
, TCGv arg2
)
450 TCGv tmp
= tcg_const_i32(arg2
);
452 tcg_gen_helper_0_2(func
, arg1
, tmp
);
456 static inline void tcg_gen_helper_0_2i(void *func
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
458 TCGv tmp
= tcg_const_i32(arg3
);
460 tcg_gen_helper_0_3(func
, arg1
, arg2
, tmp
);
464 static inline void tcg_gen_helper_0_1ii(void *func
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
466 TCGv tmp1
= tcg_const_i32(arg2
);
467 TCGv tmp2
= tcg_const_i32(arg3
);
469 tcg_gen_helper_0_3(func
, arg1
, tmp1
, tmp2
);
474 static inline void tcg_gen_helper_1_i(void *func
, TCGv ret
, TCGv arg
)
476 TCGv tmp
= tcg_const_i32(arg
);
478 tcg_gen_helper_1_1(func
, ret
, tmp
);
482 static inline void tcg_gen_helper_1_1i(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
)
484 TCGv tmp
= tcg_const_i32(arg2
);
486 tcg_gen_helper_1_2(func
, ret
, arg1
, tmp
);
490 static inline void tcg_gen_helper_1_1ii(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
492 TCGv tmp1
= tcg_const_i32(arg2
);
493 TCGv tmp2
= tcg_const_i32(arg3
);
495 tcg_gen_helper_1_3(func
, ret
, arg1
, tmp1
, tmp2
);
500 static inline void tcg_gen_helper_1_2i(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
, TCGv arg3
)
502 TCGv tmp
= tcg_const_i32(arg3
);
504 tcg_gen_helper_1_3(func
, ret
, arg1
, arg2
, tmp
);
508 static inline void tcg_gen_helper_1_2ii(void *func
, TCGv ret
, TCGv arg1
, TCGv arg2
, TCGv arg3
, TCGv arg4
)
510 TCGv tmp1
= tcg_const_i32(arg3
);
511 TCGv tmp2
= tcg_const_i32(arg4
);
513 tcg_gen_helper_1_4(func
, ret
, arg1
, arg2
, tmp1
, tmp2
);
518 typedef struct DisasContext
{
519 struct TranslationBlock
*tb
;
520 target_ulong pc
, saved_pc
;
522 /* Routine used to access memory */
524 uint32_t hflags
, saved_hflags
;
526 target_ulong btarget
;
530 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
531 * exception condition */
532 BS_STOP
= 1, /* We want to stop translation for any reason */
533 BS_BRANCH
= 2, /* We reached a branch condition */
534 BS_EXCP
= 3, /* We reached an exception condition */
537 static const char *regnames
[] =
538 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
539 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
540 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
541 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
543 static const char *fregnames
[] =
544 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
545 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
546 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
547 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
549 #ifdef MIPS_DEBUG_DISAS
550 #define MIPS_DEBUG(fmt, args...) \
552 if (loglevel & CPU_LOG_TB_IN_ASM) { \
553 fprintf(logfile, TARGET_FMT_lx ": %08x " fmt "\n", \
554 ctx->pc, ctx->opcode , ##args); \
558 #define MIPS_DEBUG(fmt, args...) do { } while(0)
561 #define MIPS_INVAL(op) \
563 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
564 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
567 /* General purpose registers moves. */
568 static inline void gen_load_gpr (TCGv t
, int reg
)
571 tcg_gen_movi_tl(t
, 0);
573 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUState
, active_tc
.gpr
) +
574 sizeof(target_ulong
) * reg
);
577 static inline void gen_store_gpr (TCGv t
, int reg
)
580 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUState
, active_tc
.gpr
) +
581 sizeof(target_ulong
) * reg
);
584 /* Moves to/from HI and LO registers. */
585 static inline void gen_load_LO (TCGv t
, int reg
)
587 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUState
, active_tc
.LO
) +
588 sizeof(target_ulong
) * reg
);
591 static inline void gen_store_LO (TCGv t
, int reg
)
593 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUState
, active_tc
.LO
) +
594 sizeof(target_ulong
) * reg
);
597 static inline void gen_load_HI (TCGv t
, int reg
)
599 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUState
, active_tc
.HI
) +
600 sizeof(target_ulong
) * reg
);
603 static inline void gen_store_HI (TCGv t
, int reg
)
605 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUState
, active_tc
.HI
) +
606 sizeof(target_ulong
) * reg
);
609 /* Moves to/from shadow registers. */
610 static inline void gen_load_srsgpr (int from
, int to
)
612 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
615 tcg_gen_movi_tl(r_tmp1
, 0);
617 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
619 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
620 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
621 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
622 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
623 tcg_gen_add_i32(r_tmp2
, cpu_env
, r_tmp2
);
625 tcg_gen_ld_tl(r_tmp1
, r_tmp2
, sizeof(target_ulong
) * from
);
626 tcg_temp_free(r_tmp2
);
628 gen_store_gpr(r_tmp1
, to
);
629 tcg_temp_free(r_tmp1
);
632 static inline void gen_store_srsgpr (int from
, int to
)
635 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
636 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
638 gen_load_gpr(r_tmp1
, from
);
639 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
640 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
641 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
642 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
643 tcg_gen_add_i32(r_tmp2
, cpu_env
, r_tmp2
);
645 tcg_gen_st_tl(r_tmp1
, r_tmp2
, sizeof(target_ulong
) * to
);
646 tcg_temp_free(r_tmp1
);
647 tcg_temp_free(r_tmp2
);
651 /* Floating point register moves. */
652 static inline void gen_load_fpr32 (TCGv t
, int reg
)
654 tcg_gen_ld_i32(t
, current_fpu
, 8 * reg
+ 4 * FP_ENDIAN_IDX
);
657 static inline void gen_store_fpr32 (TCGv t
, int reg
)
659 tcg_gen_st_i32(t
, current_fpu
, 8 * reg
+ 4 * FP_ENDIAN_IDX
);
662 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv t
, int reg
)
664 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
665 tcg_gen_ld_i64(t
, current_fpu
, 8 * reg
);
667 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
668 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
670 tcg_gen_ld_i32(r_tmp1
, current_fpu
, 8 * (reg
| 1) + 4 * FP_ENDIAN_IDX
);
671 tcg_gen_extu_i32_i64(t
, r_tmp1
);
672 tcg_gen_shli_i64(t
, t
, 32);
673 tcg_gen_ld_i32(r_tmp1
, current_fpu
, 8 * (reg
& ~1) + 4 * FP_ENDIAN_IDX
);
674 tcg_gen_extu_i32_i64(r_tmp2
, r_tmp1
);
675 tcg_gen_or_i64(t
, t
, r_tmp2
);
676 tcg_temp_free(r_tmp1
);
677 tcg_temp_free(r_tmp2
);
681 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv t
, int reg
)
683 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
684 tcg_gen_st_i64(t
, current_fpu
, 8 * reg
);
686 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
688 tcg_gen_trunc_i64_i32(r_tmp
, t
);
689 tcg_gen_st_i32(r_tmp
, current_fpu
, 8 * (reg
& ~1) + 4 * FP_ENDIAN_IDX
);
690 tcg_gen_shri_i64(t
, t
, 32);
691 tcg_gen_trunc_i64_i32(r_tmp
, t
);
692 tcg_gen_st_i32(r_tmp
, current_fpu
, 8 * (reg
| 1) + 4 * FP_ENDIAN_IDX
);
693 tcg_temp_free(r_tmp
);
697 static inline void gen_load_fpr32h (TCGv t
, int reg
)
699 tcg_gen_ld_i32(t
, current_fpu
, 8 * reg
+ 4 * !FP_ENDIAN_IDX
);
702 static inline void gen_store_fpr32h (TCGv t
, int reg
)
704 tcg_gen_st_i32(t
, current_fpu
, 8 * reg
+ 4 * !FP_ENDIAN_IDX
);
707 static inline void get_fp_cond (TCGv t
)
709 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
710 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
712 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
713 tcg_gen_shri_i32(r_tmp2
, r_tmp1
, 24);
714 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xfe);
715 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, 23);
716 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, 0x1);
717 tcg_gen_or_i32(t
, r_tmp1
, r_tmp2
);
718 tcg_temp_free(r_tmp1
);
719 tcg_temp_free(r_tmp2
);
722 typedef void (fcmp_fun32
)(uint32_t, uint32_t, int);
723 typedef void (fcmp_fun64
)(uint64_t, uint64_t, int);
725 #define FOP_CONDS(fcmp_fun, type, arg0, arg1, fmt) \
726 static fcmp_fun * fcmp ## type ## _ ## fmt ## _table[16] = { \
727 do_cmp ## type ## _ ## fmt ## _f, \
728 do_cmp ## type ## _ ## fmt ## _un, \
729 do_cmp ## type ## _ ## fmt ## _eq, \
730 do_cmp ## type ## _ ## fmt ## _ueq, \
731 do_cmp ## type ## _ ## fmt ## _olt, \
732 do_cmp ## type ## _ ## fmt ## _ult, \
733 do_cmp ## type ## _ ## fmt ## _ole, \
734 do_cmp ## type ## _ ## fmt ## _ule, \
735 do_cmp ## type ## _ ## fmt ## _sf, \
736 do_cmp ## type ## _ ## fmt ## _ngle, \
737 do_cmp ## type ## _ ## fmt ## _seq, \
738 do_cmp ## type ## _ ## fmt ## _ngl, \
739 do_cmp ## type ## _ ## fmt ## _lt, \
740 do_cmp ## type ## _ ## fmt ## _nge, \
741 do_cmp ## type ## _ ## fmt ## _le, \
742 do_cmp ## type ## _ ## fmt ## _ngt, \
744 static inline void gen_cmp ## type ## _ ## fmt(int n, arg0 a, arg1 b, int cc) \
746 tcg_gen_helper_0_2i(fcmp ## type ## _ ## fmt ## _table[n], a, b, cc); \
749 FOP_CONDS(fcmp_fun64
, , uint64_t, uint64_t, d
)
750 FOP_CONDS(fcmp_fun64
, abs
, uint64_t, uint64_t, d
)
751 FOP_CONDS(fcmp_fun32
, , uint32_t, uint32_t, s
)
752 FOP_CONDS(fcmp_fun32
, abs
, uint32_t, uint32_t, s
)
753 FOP_CONDS(fcmp_fun64
, , uint64_t, uint64_t, ps
)
754 FOP_CONDS(fcmp_fun64
, abs
, uint64_t, uint64_t, ps
)
758 #define OP_COND(name, cond) \
759 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
761 int l1 = gen_new_label(); \
762 int l2 = gen_new_label(); \
764 tcg_gen_brcond_tl(cond, t0, t1, l1); \
765 tcg_gen_movi_tl(t0, 0); \
768 tcg_gen_movi_tl(t0, 1); \
771 OP_COND(eq
, TCG_COND_EQ
);
772 OP_COND(ne
, TCG_COND_NE
);
773 OP_COND(ge
, TCG_COND_GE
);
774 OP_COND(geu
, TCG_COND_GEU
);
775 OP_COND(lt
, TCG_COND_LT
);
776 OP_COND(ltu
, TCG_COND_LTU
);
779 #define OP_CONDI(name, cond) \
780 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
782 int l1 = gen_new_label(); \
783 int l2 = gen_new_label(); \
785 tcg_gen_brcondi_tl(cond, t, val, l1); \
786 tcg_gen_movi_tl(t, 0); \
789 tcg_gen_movi_tl(t, 1); \
792 OP_CONDI(lti
, TCG_COND_LT
);
793 OP_CONDI(ltiu
, TCG_COND_LTU
);
796 #define OP_CONDZ(name, cond) \
797 static inline void glue(gen_op_, name) (TCGv t) \
799 int l1 = gen_new_label(); \
800 int l2 = gen_new_label(); \
802 tcg_gen_brcondi_tl(cond, t, 0, l1); \
803 tcg_gen_movi_tl(t, 0); \
806 tcg_gen_movi_tl(t, 1); \
809 OP_CONDZ(gez
, TCG_COND_GE
);
810 OP_CONDZ(gtz
, TCG_COND_GT
);
811 OP_CONDZ(lez
, TCG_COND_LE
);
812 OP_CONDZ(ltz
, TCG_COND_LT
);
815 static inline void gen_save_pc(target_ulong pc
)
817 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_TL
);
819 tcg_gen_movi_tl(r_tmp
, pc
);
820 tcg_gen_st_tl(r_tmp
, cpu_env
, offsetof(CPUState
, active_tc
.PC
));
821 tcg_temp_free(r_tmp
);
824 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
826 #if defined MIPS_DEBUG_DISAS
827 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
828 fprintf(logfile
, "hflags %08x saved %08x\n",
829 ctx
->hflags
, ctx
->saved_hflags
);
832 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
833 gen_save_pc(ctx
->pc
);
834 ctx
->saved_pc
= ctx
->pc
;
836 if (ctx
->hflags
!= ctx
->saved_hflags
) {
837 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
839 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
);
840 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
841 tcg_temp_free(r_tmp
);
842 ctx
->saved_hflags
= ctx
->hflags
;
843 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
849 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
855 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
857 ctx
->saved_hflags
= ctx
->hflags
;
858 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
864 ctx
->btarget
= env
->btarget
;
870 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
872 save_cpu_state(ctx
, 1);
873 tcg_gen_helper_0_ii(do_raise_exception_err
, excp
, err
);
874 tcg_gen_helper_0_0(do_interrupt_restart
);
879 generate_exception (DisasContext
*ctx
, int excp
)
881 save_cpu_state(ctx
, 1);
882 tcg_gen_helper_0_i(do_raise_exception
, excp
);
883 tcg_gen_helper_0_0(do_interrupt_restart
);
887 /* Addresses computation */
888 static inline void gen_op_addr_add (TCGv t0
, TCGv t1
)
890 tcg_gen_add_tl(t0
, t0
, t1
);
892 #if defined(TARGET_MIPS64)
893 /* For compatibility with 32-bit code, data reference in user mode
894 with Status_UX = 0 should be casted to 32-bit and sign extended.
895 See the MIPS64 PRA manual, section 4.10. */
897 int l1
= gen_new_label();
898 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_I32
);
900 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
901 tcg_gen_andi_i32(r_tmp
, r_tmp
, MIPS_HFLAG_KSU
);
902 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, MIPS_HFLAG_UM
, l1
);
903 tcg_gen_ld_i32(r_tmp
, cpu_env
, offsetof(CPUState
, CP0_Status
));
904 tcg_gen_andi_i32(r_tmp
, r_tmp
, (1 << CP0St_UX
));
905 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp
, 0, l1
);
906 tcg_temp_free(r_tmp
);
907 tcg_gen_ext32s_i64(t0
, t0
);
913 static inline void check_cp0_enabled(DisasContext
*ctx
)
915 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
916 generate_exception_err(ctx
, EXCP_CpU
, 1);
919 static inline void check_cp1_enabled(DisasContext
*ctx
)
921 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
922 generate_exception_err(ctx
, EXCP_CpU
, 1);
925 /* Verify that the processor is running with COP1X instructions enabled.
926 This is associated with the nabla symbol in the MIPS32 and MIPS64
929 static inline void check_cop1x(DisasContext
*ctx
)
931 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
932 generate_exception(ctx
, EXCP_RI
);
935 /* Verify that the processor is running with 64-bit floating-point
936 operations enabled. */
938 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
940 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
941 generate_exception(ctx
, EXCP_RI
);
945 * Verify if floating point register is valid; an operation is not defined
946 * if bit 0 of any register specification is set and the FR bit in the
947 * Status register equals zero, since the register numbers specify an
948 * even-odd pair of adjacent coprocessor general registers. When the FR bit
949 * in the Status register equals one, both even and odd register numbers
950 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
952 * Multiple 64 bit wide registers can be checked by calling
953 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
955 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
957 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
958 generate_exception(ctx
, EXCP_RI
);
961 /* This code generates a "reserved instruction" exception if the
962 CPU does not support the instruction set corresponding to flags. */
963 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
965 if (unlikely(!(env
->insn_flags
& flags
)))
966 generate_exception(ctx
, EXCP_RI
);
969 /* This code generates a "reserved instruction" exception if 64-bit
970 instructions are not enabled. */
971 static inline void check_mips_64(DisasContext
*ctx
)
973 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
974 generate_exception(ctx
, EXCP_RI
);
977 /* load/store instructions. */
978 #define OP_LD(insn,fname) \
979 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
981 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
988 #if defined(TARGET_MIPS64)
994 #define OP_ST(insn,fname) \
995 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
997 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1002 #if defined(TARGET_MIPS64)
1007 #define OP_LD_ATOMIC(insn,fname) \
1008 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1010 tcg_gen_mov_tl(t1, t0); \
1011 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
1012 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1014 OP_LD_ATOMIC(ll
,ld32s
);
1015 #if defined(TARGET_MIPS64)
1016 OP_LD_ATOMIC(lld
,ld64
);
1020 #define OP_ST_ATOMIC(insn,fname,almask) \
1021 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
1023 TCGv r_tmp = tcg_temp_local_new(TCG_TYPE_TL); \
1024 int l1 = gen_new_label(); \
1025 int l2 = gen_new_label(); \
1026 int l3 = gen_new_label(); \
1028 tcg_gen_andi_tl(r_tmp, t0, almask); \
1029 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
1030 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
1031 generate_exception(ctx, EXCP_AdES); \
1032 gen_set_label(l1); \
1033 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
1034 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
1035 tcg_temp_free(r_tmp); \
1036 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
1037 tcg_gen_movi_tl(t0, 1); \
1039 gen_set_label(l2); \
1040 tcg_gen_movi_tl(t0, 0); \
1041 gen_set_label(l3); \
1043 OP_ST_ATOMIC(sc
,st32
,0x3);
1044 #if defined(TARGET_MIPS64)
1045 OP_ST_ATOMIC(scd
,st64
,0x7);
1049 /* Load and store */
1050 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
1051 int base
, int16_t offset
)
1053 const char *opn
= "ldst";
1054 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1055 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1058 tcg_gen_movi_tl(t0
, offset
);
1059 } else if (offset
== 0) {
1060 gen_load_gpr(t0
, base
);
1062 gen_load_gpr(t0
, base
);
1063 tcg_gen_movi_tl(t1
, offset
);
1064 gen_op_addr_add(t0
, t1
);
1066 /* Don't do NOP if destination is zero: we must perform the actual
1069 #if defined(TARGET_MIPS64)
1071 op_ldst_lwu(t0
, ctx
);
1072 gen_store_gpr(t0
, rt
);
1076 op_ldst_ld(t0
, ctx
);
1077 gen_store_gpr(t0
, rt
);
1081 op_ldst_lld(t0
, t1
, ctx
);
1082 gen_store_gpr(t0
, rt
);
1086 gen_load_gpr(t1
, rt
);
1087 op_ldst_sd(t0
, t1
, ctx
);
1091 save_cpu_state(ctx
, 1);
1092 gen_load_gpr(t1
, rt
);
1093 op_ldst_scd(t0
, t1
, ctx
);
1094 gen_store_gpr(t0
, rt
);
1098 save_cpu_state(ctx
, 1);
1099 gen_load_gpr(t1
, rt
);
1100 tcg_gen_helper_1_2i(do_ldl
, t1
, t0
, t1
, ctx
->mem_idx
);
1101 gen_store_gpr(t1
, rt
);
1105 save_cpu_state(ctx
, 1);
1106 gen_load_gpr(t1
, rt
);
1107 tcg_gen_helper_0_2i(do_sdl
, t0
, t1
, ctx
->mem_idx
);
1111 save_cpu_state(ctx
, 1);
1112 gen_load_gpr(t1
, rt
);
1113 tcg_gen_helper_1_2i(do_ldr
, t1
, t0
, t1
, ctx
->mem_idx
);
1114 gen_store_gpr(t1
, rt
);
1118 save_cpu_state(ctx
, 1);
1119 gen_load_gpr(t1
, rt
);
1120 tcg_gen_helper_0_2i(do_sdr
, t0
, t1
, ctx
->mem_idx
);
1125 op_ldst_lw(t0
, ctx
);
1126 gen_store_gpr(t0
, rt
);
1130 gen_load_gpr(t1
, rt
);
1131 op_ldst_sw(t0
, t1
, ctx
);
1135 op_ldst_lh(t0
, ctx
);
1136 gen_store_gpr(t0
, rt
);
1140 gen_load_gpr(t1
, rt
);
1141 op_ldst_sh(t0
, t1
, ctx
);
1145 op_ldst_lhu(t0
, ctx
);
1146 gen_store_gpr(t0
, rt
);
1150 op_ldst_lb(t0
, ctx
);
1151 gen_store_gpr(t0
, rt
);
1155 gen_load_gpr(t1
, rt
);
1156 op_ldst_sb(t0
, t1
, ctx
);
1160 op_ldst_lbu(t0
, ctx
);
1161 gen_store_gpr(t0
, rt
);
1165 save_cpu_state(ctx
, 1);
1166 gen_load_gpr(t1
, rt
);
1167 tcg_gen_helper_1_2i(do_lwl
, t1
, t0
, t1
, ctx
->mem_idx
);
1168 gen_store_gpr(t1
, rt
);
1172 save_cpu_state(ctx
, 1);
1173 gen_load_gpr(t1
, rt
);
1174 tcg_gen_helper_0_2i(do_swl
, t0
, t1
, ctx
->mem_idx
);
1178 save_cpu_state(ctx
, 1);
1179 gen_load_gpr(t1
, rt
);
1180 tcg_gen_helper_1_2i(do_lwr
, t1
, t0
, t1
, ctx
->mem_idx
);
1181 gen_store_gpr(t1
, rt
);
1185 save_cpu_state(ctx
, 1);
1186 gen_load_gpr(t1
, rt
);
1187 tcg_gen_helper_0_2i(do_swr
, t0
, t1
, ctx
->mem_idx
);
1191 op_ldst_ll(t0
, t1
, ctx
);
1192 gen_store_gpr(t0
, rt
);
1196 save_cpu_state(ctx
, 1);
1197 gen_load_gpr(t1
, rt
);
1198 op_ldst_sc(t0
, t1
, ctx
);
1199 gen_store_gpr(t0
, rt
);
1204 generate_exception(ctx
, EXCP_RI
);
1207 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1213 /* Load and store */
1214 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1215 int base
, int16_t offset
)
1217 const char *opn
= "flt_ldst";
1218 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1221 tcg_gen_movi_tl(t0
, offset
);
1222 } else if (offset
== 0) {
1223 gen_load_gpr(t0
, base
);
1225 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1227 gen_load_gpr(t0
, base
);
1228 tcg_gen_movi_tl(t1
, offset
);
1229 gen_op_addr_add(t0
, t1
);
1232 /* Don't do NOP if destination is zero: we must perform the actual
1237 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
1239 tcg_gen_qemu_ld32s(fp0
, t0
, ctx
->mem_idx
);
1240 gen_store_fpr32(fp0
, ft
);
1247 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
1249 gen_load_fpr32(fp0
, ft
);
1250 tcg_gen_qemu_st32(fp0
, t0
, ctx
->mem_idx
);
1257 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
1259 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1260 gen_store_fpr64(ctx
, fp0
, ft
);
1267 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
1269 gen_load_fpr64(ctx
, fp0
, ft
);
1270 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1277 generate_exception(ctx
, EXCP_RI
);
1280 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1285 /* Arithmetic with immediate operand */
1286 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1287 int rt
, int rs
, int16_t imm
)
1290 const char *opn
= "imm arith";
1291 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1293 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1294 /* If no destination, treat it as a NOP.
1295 For addi, we must generate the overflow exception when needed. */
1299 uimm
= (uint16_t)imm
;
1303 #if defined(TARGET_MIPS64)
1309 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1314 gen_load_gpr(t0
, rs
);
1317 tcg_gen_movi_tl(t0
, imm
<< 16);
1322 #if defined(TARGET_MIPS64)
1331 gen_load_gpr(t0
, rs
);
1337 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1338 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1339 int l1
= gen_new_label();
1341 save_cpu_state(ctx
, 1);
1342 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1343 tcg_gen_addi_tl(t0
, r_tmp1
, uimm
);
1345 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1346 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1347 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1348 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1349 tcg_temp_free(r_tmp2
);
1350 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1351 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1352 tcg_temp_free(r_tmp1
);
1353 /* operands of same sign, result different sign */
1354 generate_exception(ctx
, EXCP_OVERFLOW
);
1357 tcg_gen_ext32s_tl(t0
, t0
);
1362 tcg_gen_ext32s_tl(t0
, t0
);
1363 tcg_gen_addi_tl(t0
, t0
, uimm
);
1364 tcg_gen_ext32s_tl(t0
, t0
);
1367 #if defined(TARGET_MIPS64)
1370 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1371 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1372 int l1
= gen_new_label();
1374 save_cpu_state(ctx
, 1);
1375 tcg_gen_mov_tl(r_tmp1
, t0
);
1376 tcg_gen_addi_tl(t0
, t0
, uimm
);
1378 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, uimm
);
1379 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1380 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1381 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1382 tcg_temp_free(r_tmp2
);
1383 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1384 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1385 tcg_temp_free(r_tmp1
);
1386 /* operands of same sign, result different sign */
1387 generate_exception(ctx
, EXCP_OVERFLOW
);
1393 tcg_gen_addi_tl(t0
, t0
, uimm
);
1398 gen_op_lti(t0
, uimm
);
1402 gen_op_ltiu(t0
, uimm
);
1406 tcg_gen_andi_tl(t0
, t0
, uimm
);
1410 tcg_gen_ori_tl(t0
, t0
, uimm
);
1414 tcg_gen_xori_tl(t0
, t0
, uimm
);
1421 tcg_gen_ext32u_tl(t0
, t0
);
1422 tcg_gen_shli_tl(t0
, t0
, uimm
);
1423 tcg_gen_ext32s_tl(t0
, t0
);
1427 tcg_gen_ext32s_tl(t0
, t0
);
1428 tcg_gen_sari_tl(t0
, t0
, uimm
);
1429 tcg_gen_ext32s_tl(t0
, t0
);
1433 switch ((ctx
->opcode
>> 21) & 0x1f) {
1435 tcg_gen_ext32u_tl(t0
, t0
);
1436 tcg_gen_shri_tl(t0
, t0
, uimm
);
1437 tcg_gen_ext32s_tl(t0
, t0
);
1441 /* rotr is decoded as srl on non-R2 CPUs */
1442 if (env
->insn_flags
& ISA_MIPS32R2
) {
1444 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1445 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1447 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1448 tcg_gen_movi_i32(r_tmp2
, 0x20);
1449 tcg_gen_subi_i32(r_tmp2
, r_tmp2
, uimm
);
1450 tcg_gen_shl_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1451 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, uimm
);
1452 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1453 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
1454 tcg_temp_free(r_tmp1
);
1455 tcg_temp_free(r_tmp2
);
1459 tcg_gen_ext32u_tl(t0
, t0
);
1460 tcg_gen_shri_tl(t0
, t0
, uimm
);
1461 tcg_gen_ext32s_tl(t0
, t0
);
1466 MIPS_INVAL("invalid srl flag");
1467 generate_exception(ctx
, EXCP_RI
);
1471 #if defined(TARGET_MIPS64)
1473 tcg_gen_shli_tl(t0
, t0
, uimm
);
1477 tcg_gen_sari_tl(t0
, t0
, uimm
);
1481 switch ((ctx
->opcode
>> 21) & 0x1f) {
1483 tcg_gen_shri_tl(t0
, t0
, uimm
);
1487 /* drotr is decoded as dsrl on non-R2 CPUs */
1488 if (env
->insn_flags
& ISA_MIPS32R2
) {
1490 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1492 tcg_gen_movi_tl(r_tmp1
, 0x40);
1493 tcg_gen_subi_tl(r_tmp1
, r_tmp1
, uimm
);
1494 tcg_gen_shl_tl(r_tmp1
, t0
, r_tmp1
);
1495 tcg_gen_shri_tl(t0
, t0
, uimm
);
1496 tcg_gen_or_tl(t0
, t0
, r_tmp1
);
1497 tcg_temp_free(r_tmp1
);
1501 tcg_gen_shri_tl(t0
, t0
, uimm
);
1506 MIPS_INVAL("invalid dsrl flag");
1507 generate_exception(ctx
, EXCP_RI
);
1512 tcg_gen_shli_tl(t0
, t0
, uimm
+ 32);
1516 tcg_gen_sari_tl(t0
, t0
, uimm
+ 32);
1520 switch ((ctx
->opcode
>> 21) & 0x1f) {
1522 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1526 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1527 if (env
->insn_flags
& ISA_MIPS32R2
) {
1528 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1529 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1531 tcg_gen_movi_tl(r_tmp1
, 0x40);
1532 tcg_gen_movi_tl(r_tmp2
, 32);
1533 tcg_gen_addi_tl(r_tmp2
, r_tmp2
, uimm
);
1534 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1535 tcg_gen_shl_tl(r_tmp1
, t0
, r_tmp1
);
1536 tcg_gen_shr_tl(t0
, t0
, r_tmp2
);
1537 tcg_gen_or_tl(t0
, t0
, r_tmp1
);
1538 tcg_temp_free(r_tmp1
);
1539 tcg_temp_free(r_tmp2
);
1542 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1547 MIPS_INVAL("invalid dsrl32 flag");
1548 generate_exception(ctx
, EXCP_RI
);
1555 generate_exception(ctx
, EXCP_RI
);
1558 gen_store_gpr(t0
, rt
);
1559 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1565 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1566 int rd
, int rs
, int rt
)
1568 const char *opn
= "arith";
1569 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1570 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1572 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1573 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1574 /* If no destination, treat it as a NOP.
1575 For add & sub, we must generate the overflow exception when needed. */
1579 gen_load_gpr(t0
, rs
);
1580 /* Specialcase the conventional move operation. */
1581 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1582 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1583 gen_store_gpr(t0
, rd
);
1586 gen_load_gpr(t1
, rt
);
1590 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1591 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1592 int l1
= gen_new_label();
1594 save_cpu_state(ctx
, 1);
1595 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1596 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1597 tcg_gen_add_tl(t0
, r_tmp1
, r_tmp2
);
1599 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1600 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1601 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1602 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1603 tcg_temp_free(r_tmp2
);
1604 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1605 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1606 tcg_temp_free(r_tmp1
);
1607 /* operands of same sign, result different sign */
1608 generate_exception(ctx
, EXCP_OVERFLOW
);
1611 tcg_gen_ext32s_tl(t0
, t0
);
1616 tcg_gen_ext32s_tl(t0
, t0
);
1617 tcg_gen_ext32s_tl(t1
, t1
);
1618 tcg_gen_add_tl(t0
, t0
, t1
);
1619 tcg_gen_ext32s_tl(t0
, t0
);
1624 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1625 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1626 int l1
= gen_new_label();
1628 save_cpu_state(ctx
, 1);
1629 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1630 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1631 tcg_gen_sub_tl(t0
, r_tmp1
, r_tmp2
);
1633 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1634 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1635 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1636 tcg_temp_free(r_tmp2
);
1637 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 31);
1638 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1639 tcg_temp_free(r_tmp1
);
1640 /* operands of different sign, first operand and result different sign */
1641 generate_exception(ctx
, EXCP_OVERFLOW
);
1644 tcg_gen_ext32s_tl(t0
, t0
);
1649 tcg_gen_ext32s_tl(t0
, t0
);
1650 tcg_gen_ext32s_tl(t1
, t1
);
1651 tcg_gen_sub_tl(t0
, t0
, t1
);
1652 tcg_gen_ext32s_tl(t0
, t0
);
1655 #if defined(TARGET_MIPS64)
1658 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1659 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1660 int l1
= gen_new_label();
1662 save_cpu_state(ctx
, 1);
1663 tcg_gen_mov_tl(r_tmp1
, t0
);
1664 tcg_gen_add_tl(t0
, t0
, t1
);
1666 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1667 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1668 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1669 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1670 tcg_temp_free(r_tmp2
);
1671 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1672 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1673 tcg_temp_free(r_tmp1
);
1674 /* operands of same sign, result different sign */
1675 generate_exception(ctx
, EXCP_OVERFLOW
);
1681 tcg_gen_add_tl(t0
, t0
, t1
);
1686 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_TL
);
1687 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_TL
);
1688 int l1
= gen_new_label();
1690 save_cpu_state(ctx
, 1);
1691 tcg_gen_mov_tl(r_tmp1
, t0
);
1692 tcg_gen_sub_tl(t0
, t0
, t1
);
1694 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1695 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1696 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1697 tcg_temp_free(r_tmp2
);
1698 tcg_gen_shri_tl(r_tmp1
, r_tmp1
, 63);
1699 tcg_gen_brcondi_tl(TCG_COND_EQ
, r_tmp1
, 0, l1
);
1700 tcg_temp_free(r_tmp1
);
1701 /* operands of different sign, first operand and result different sign */
1702 generate_exception(ctx
, EXCP_OVERFLOW
);
1708 tcg_gen_sub_tl(t0
, t0
, t1
);
1721 tcg_gen_and_tl(t0
, t0
, t1
);
1725 tcg_gen_or_tl(t0
, t0
, t1
);
1726 tcg_gen_not_tl(t0
, t0
);
1730 tcg_gen_or_tl(t0
, t0
, t1
);
1734 tcg_gen_xor_tl(t0
, t0
, t1
);
1738 tcg_gen_ext32s_tl(t0
, t0
);
1739 tcg_gen_ext32s_tl(t1
, t1
);
1740 tcg_gen_mul_tl(t0
, t0
, t1
);
1741 tcg_gen_ext32s_tl(t0
, t0
);
1746 int l1
= gen_new_label();
1748 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1749 gen_store_gpr(t0
, rd
);
1756 int l1
= gen_new_label();
1758 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
1759 gen_store_gpr(t0
, rd
);
1765 tcg_gen_ext32u_tl(t0
, t0
);
1766 tcg_gen_ext32u_tl(t1
, t1
);
1767 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1768 tcg_gen_shl_tl(t0
, t1
, t0
);
1769 tcg_gen_ext32s_tl(t0
, t0
);
1773 tcg_gen_ext32s_tl(t1
, t1
);
1774 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1775 tcg_gen_sar_tl(t0
, t1
, t0
);
1776 tcg_gen_ext32s_tl(t0
, t0
);
1780 switch ((ctx
->opcode
>> 6) & 0x1f) {
1782 tcg_gen_ext32u_tl(t1
, t1
);
1783 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1784 tcg_gen_shr_tl(t0
, t1
, t0
);
1785 tcg_gen_ext32s_tl(t0
, t0
);
1789 /* rotrv is decoded as srlv on non-R2 CPUs */
1790 if (env
->insn_flags
& ISA_MIPS32R2
) {
1791 int l1
= gen_new_label();
1792 int l2
= gen_new_label();
1794 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1795 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1797 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1798 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1799 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
1801 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1802 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1803 tcg_gen_movi_i32(r_tmp3
, 0x20);
1804 tcg_gen_sub_i32(r_tmp3
, r_tmp3
, r_tmp1
);
1805 tcg_gen_shl_i32(r_tmp3
, r_tmp2
, r_tmp3
);
1806 tcg_gen_shr_i32(r_tmp1
, r_tmp2
, r_tmp1
);
1807 tcg_gen_or_i32(r_tmp1
, r_tmp1
, r_tmp3
);
1808 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
1809 tcg_temp_free(r_tmp1
);
1810 tcg_temp_free(r_tmp2
);
1811 tcg_temp_free(r_tmp3
);
1815 tcg_gen_mov_tl(t0
, t1
);
1819 tcg_gen_ext32u_tl(t1
, t1
);
1820 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1821 tcg_gen_shr_tl(t0
, t1
, t0
);
1822 tcg_gen_ext32s_tl(t0
, t0
);
1827 MIPS_INVAL("invalid srlv flag");
1828 generate_exception(ctx
, EXCP_RI
);
1832 #if defined(TARGET_MIPS64)
1834 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1835 tcg_gen_shl_tl(t0
, t1
, t0
);
1839 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1840 tcg_gen_sar_tl(t0
, t1
, t0
);
1844 switch ((ctx
->opcode
>> 6) & 0x1f) {
1846 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1847 tcg_gen_shr_tl(t0
, t1
, t0
);
1851 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1852 if (env
->insn_flags
& ISA_MIPS32R2
) {
1853 int l1
= gen_new_label();
1854 int l2
= gen_new_label();
1856 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1857 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1859 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_TL
);
1861 tcg_gen_movi_tl(r_tmp1
, 0x40);
1862 tcg_gen_sub_tl(r_tmp1
, r_tmp1
, t0
);
1863 tcg_gen_shl_tl(r_tmp1
, t1
, r_tmp1
);
1864 tcg_gen_shr_tl(t0
, t1
, t0
);
1865 tcg_gen_or_tl(t0
, t0
, r_tmp1
);
1866 tcg_temp_free(r_tmp1
);
1870 tcg_gen_mov_tl(t0
, t1
);
1874 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1875 tcg_gen_shr_tl(t0
, t1
, t0
);
1880 MIPS_INVAL("invalid dsrlv flag");
1881 generate_exception(ctx
, EXCP_RI
);
1888 generate_exception(ctx
, EXCP_RI
);
1891 gen_store_gpr(t0
, rd
);
1893 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1899 /* Arithmetic on HI/LO registers */
1900 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1902 const char *opn
= "hilo";
1903 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1905 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1913 gen_store_gpr(t0
, reg
);
1918 gen_store_gpr(t0
, reg
);
1922 gen_load_gpr(t0
, reg
);
1923 gen_store_HI(t0
, 0);
1927 gen_load_gpr(t0
, reg
);
1928 gen_store_LO(t0
, 0);
1933 generate_exception(ctx
, EXCP_RI
);
1936 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1941 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1944 const char *opn
= "mul/div";
1945 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
1946 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
1948 gen_load_gpr(t0
, rs
);
1949 gen_load_gpr(t1
, rt
);
1953 int l1
= gen_new_label();
1955 tcg_gen_ext32s_tl(t0
, t0
);
1956 tcg_gen_ext32s_tl(t1
, t1
);
1957 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1959 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
1960 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
1961 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
1963 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
1964 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
1965 tcg_gen_div_i64(r_tmp3
, r_tmp1
, r_tmp2
);
1966 tcg_gen_rem_i64(r_tmp2
, r_tmp1
, r_tmp2
);
1967 tcg_gen_trunc_i64_tl(t0
, r_tmp3
);
1968 tcg_gen_trunc_i64_tl(t1
, r_tmp2
);
1969 tcg_temp_free(r_tmp1
);
1970 tcg_temp_free(r_tmp2
);
1971 tcg_temp_free(r_tmp3
);
1972 tcg_gen_ext32s_tl(t0
, t0
);
1973 tcg_gen_ext32s_tl(t1
, t1
);
1974 gen_store_LO(t0
, 0);
1975 gen_store_HI(t1
, 0);
1983 int l1
= gen_new_label();
1985 tcg_gen_ext32s_tl(t1
, t1
);
1986 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1988 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
1989 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I32
);
1990 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I32
);
1992 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1993 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1994 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1995 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1996 tcg_gen_ext_i32_tl(t0
, r_tmp3
);
1997 tcg_gen_ext_i32_tl(t1
, r_tmp1
);
1998 tcg_temp_free(r_tmp1
);
1999 tcg_temp_free(r_tmp2
);
2000 tcg_temp_free(r_tmp3
);
2001 gen_store_LO(t0
, 0);
2002 gen_store_HI(t1
, 0);
2010 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2011 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2013 tcg_gen_ext32s_tl(t0
, t0
);
2014 tcg_gen_ext32s_tl(t1
, t1
);
2015 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2016 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2017 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2018 tcg_temp_free(r_tmp2
);
2019 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2020 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2021 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2022 tcg_temp_free(r_tmp1
);
2023 tcg_gen_ext32s_tl(t0
, t0
);
2024 tcg_gen_ext32s_tl(t1
, t1
);
2025 gen_store_LO(t0
, 0);
2026 gen_store_HI(t1
, 0);
2032 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2033 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2035 tcg_gen_ext32u_tl(t0
, t0
);
2036 tcg_gen_ext32u_tl(t1
, t1
);
2037 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2038 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2039 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2040 tcg_temp_free(r_tmp2
);
2041 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2042 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2043 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2044 tcg_temp_free(r_tmp1
);
2045 tcg_gen_ext32s_tl(t0
, t0
);
2046 tcg_gen_ext32s_tl(t1
, t1
);
2047 gen_store_LO(t0
, 0);
2048 gen_store_HI(t1
, 0);
2052 #if defined(TARGET_MIPS64)
2055 int l1
= gen_new_label();
2057 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2059 int l2
= gen_new_label();
2061 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2062 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2064 tcg_gen_movi_tl(t1
, 0);
2065 gen_store_LO(t0
, 0);
2066 gen_store_HI(t1
, 0);
2071 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2072 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2074 tcg_gen_div_i64(r_tmp1
, t0
, t1
);
2075 tcg_gen_rem_i64(r_tmp2
, t0
, t1
);
2076 gen_store_LO(r_tmp1
, 0);
2077 gen_store_HI(r_tmp2
, 0);
2078 tcg_temp_free(r_tmp1
);
2079 tcg_temp_free(r_tmp2
);
2088 int l1
= gen_new_label();
2090 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2092 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2093 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2095 tcg_gen_divu_i64(r_tmp1
, t0
, t1
);
2096 tcg_gen_remu_i64(r_tmp2
, t0
, t1
);
2097 tcg_temp_free(r_tmp1
);
2098 tcg_temp_free(r_tmp2
);
2099 gen_store_LO(r_tmp1
, 0);
2100 gen_store_HI(r_tmp2
, 0);
2107 tcg_gen_helper_0_2(do_dmult
, t0
, t1
);
2111 tcg_gen_helper_0_2(do_dmultu
, t0
, t1
);
2117 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2118 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2119 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2121 tcg_gen_ext32s_tl(t0
, t0
);
2122 tcg_gen_ext32s_tl(t1
, t1
);
2123 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2124 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2125 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2128 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2129 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2130 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2131 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2132 tcg_temp_free(r_tmp3
);
2133 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2134 tcg_temp_free(r_tmp2
);
2135 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2136 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2137 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2138 tcg_temp_free(r_tmp1
);
2139 tcg_gen_ext32s_tl(t0
, t0
);
2140 tcg_gen_ext32s_tl(t1
, t1
);
2141 gen_store_LO(t0
, 0);
2142 gen_store_HI(t1
, 0);
2148 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2149 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2150 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2152 tcg_gen_ext32u_tl(t0
, t0
);
2153 tcg_gen_ext32u_tl(t1
, t1
);
2154 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2155 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2156 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2159 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2160 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2161 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2162 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2163 tcg_temp_free(r_tmp3
);
2164 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2165 tcg_temp_free(r_tmp2
);
2166 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2167 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2168 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2169 tcg_temp_free(r_tmp1
);
2170 tcg_gen_ext32s_tl(t0
, t0
);
2171 tcg_gen_ext32s_tl(t1
, t1
);
2172 gen_store_LO(t0
, 0);
2173 gen_store_HI(t1
, 0);
2179 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2180 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2181 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2183 tcg_gen_ext32s_tl(t0
, t0
);
2184 tcg_gen_ext32s_tl(t1
, t1
);
2185 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2186 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2187 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2190 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2191 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2192 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2193 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2194 tcg_temp_free(r_tmp3
);
2195 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2196 tcg_temp_free(r_tmp2
);
2197 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2198 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2199 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2200 tcg_temp_free(r_tmp1
);
2201 tcg_gen_ext32s_tl(t0
, t0
);
2202 tcg_gen_ext32s_tl(t1
, t1
);
2203 gen_store_LO(t0
, 0);
2204 gen_store_HI(t1
, 0);
2210 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I64
);
2211 TCGv r_tmp2
= tcg_temp_new(TCG_TYPE_I64
);
2212 TCGv r_tmp3
= tcg_temp_new(TCG_TYPE_I64
);
2214 tcg_gen_ext32u_tl(t0
, t0
);
2215 tcg_gen_ext32u_tl(t1
, t1
);
2216 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2217 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2218 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2221 tcg_gen_extu_tl_i64(r_tmp2
, t0
);
2222 tcg_gen_extu_tl_i64(r_tmp3
, t1
);
2223 tcg_gen_shli_i64(r_tmp3
, r_tmp3
, 32);
2224 tcg_gen_or_i64(r_tmp2
, r_tmp2
, r_tmp3
);
2225 tcg_temp_free(r_tmp3
);
2226 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2227 tcg_temp_free(r_tmp2
);
2228 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2229 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2230 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2231 tcg_temp_free(r_tmp1
);
2232 tcg_gen_ext32s_tl(t0
, t0
);
2233 tcg_gen_ext32s_tl(t1
, t1
);
2234 gen_store_LO(t0
, 0);
2235 gen_store_HI(t1
, 0);
2241 generate_exception(ctx
, EXCP_RI
);
2244 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2250 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2251 int rd
, int rs
, int rt
)
2253 const char *opn
= "mul vr54xx";
2254 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2255 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2257 gen_load_gpr(t0
, rs
);
2258 gen_load_gpr(t1
, rt
);
2261 case OPC_VR54XX_MULS
:
2262 tcg_gen_helper_1_2(do_muls
, t0
, t0
, t1
);
2265 case OPC_VR54XX_MULSU
:
2266 tcg_gen_helper_1_2(do_mulsu
, t0
, t0
, t1
);
2269 case OPC_VR54XX_MACC
:
2270 tcg_gen_helper_1_2(do_macc
, t0
, t0
, t1
);
2273 case OPC_VR54XX_MACCU
:
2274 tcg_gen_helper_1_2(do_maccu
, t0
, t0
, t1
);
2277 case OPC_VR54XX_MSAC
:
2278 tcg_gen_helper_1_2(do_msac
, t0
, t0
, t1
);
2281 case OPC_VR54XX_MSACU
:
2282 tcg_gen_helper_1_2(do_msacu
, t0
, t0
, t1
);
2285 case OPC_VR54XX_MULHI
:
2286 tcg_gen_helper_1_2(do_mulhi
, t0
, t0
, t1
);
2289 case OPC_VR54XX_MULHIU
:
2290 tcg_gen_helper_1_2(do_mulhiu
, t0
, t0
, t1
);
2293 case OPC_VR54XX_MULSHI
:
2294 tcg_gen_helper_1_2(do_mulshi
, t0
, t0
, t1
);
2297 case OPC_VR54XX_MULSHIU
:
2298 tcg_gen_helper_1_2(do_mulshiu
, t0
, t0
, t1
);
2301 case OPC_VR54XX_MACCHI
:
2302 tcg_gen_helper_1_2(do_macchi
, t0
, t0
, t1
);
2305 case OPC_VR54XX_MACCHIU
:
2306 tcg_gen_helper_1_2(do_macchiu
, t0
, t0
, t1
);
2309 case OPC_VR54XX_MSACHI
:
2310 tcg_gen_helper_1_2(do_msachi
, t0
, t0
, t1
);
2313 case OPC_VR54XX_MSACHIU
:
2314 tcg_gen_helper_1_2(do_msachiu
, t0
, t0
, t1
);
2318 MIPS_INVAL("mul vr54xx");
2319 generate_exception(ctx
, EXCP_RI
);
2322 gen_store_gpr(t0
, rd
);
2323 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2330 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2333 const char *opn
= "CLx";
2334 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2341 gen_load_gpr(t0
, rs
);
2344 tcg_gen_helper_1_1(do_clo
, t0
, t0
);
2348 tcg_gen_helper_1_1(do_clz
, t0
, t0
);
2351 #if defined(TARGET_MIPS64)
2353 tcg_gen_helper_1_1(do_dclo
, t0
, t0
);
2357 tcg_gen_helper_1_1(do_dclz
, t0
, t0
);
2363 generate_exception(ctx
, EXCP_RI
);
2366 gen_store_gpr(t0
, rd
);
2367 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2374 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2375 int rs
, int rt
, int16_t imm
)
2378 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2379 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2382 /* Load needed operands */
2390 /* Compare two registers */
2392 gen_load_gpr(t0
, rs
);
2393 gen_load_gpr(t1
, rt
);
2403 /* Compare register to immediate */
2404 if (rs
!= 0 || imm
!= 0) {
2405 gen_load_gpr(t0
, rs
);
2406 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2413 case OPC_TEQ
: /* rs == rs */
2414 case OPC_TEQI
: /* r0 == 0 */
2415 case OPC_TGE
: /* rs >= rs */
2416 case OPC_TGEI
: /* r0 >= 0 */
2417 case OPC_TGEU
: /* rs >= rs unsigned */
2418 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2420 tcg_gen_movi_tl(t0
, 1);
2422 case OPC_TLT
: /* rs < rs */
2423 case OPC_TLTI
: /* r0 < 0 */
2424 case OPC_TLTU
: /* rs < rs unsigned */
2425 case OPC_TLTIU
: /* r0 < 0 unsigned */
2426 case OPC_TNE
: /* rs != rs */
2427 case OPC_TNEI
: /* r0 != 0 */
2428 /* Never trap: treat as NOP. */
2432 generate_exception(ctx
, EXCP_RI
);
2463 generate_exception(ctx
, EXCP_RI
);
2467 save_cpu_state(ctx
, 1);
2469 int l1
= gen_new_label();
2471 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2472 tcg_gen_helper_0_i(do_raise_exception
, EXCP_TRAP
);
2475 ctx
->bstate
= BS_STOP
;
2481 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2483 TranslationBlock
*tb
;
2485 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2488 tcg_gen_exit_tb((long)tb
+ n
);
2495 /* Branches (before delay slot) */
2496 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2497 int rs
, int rt
, int32_t offset
)
2499 target_ulong btgt
= -1;
2502 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2503 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2505 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2506 #ifdef MIPS_DEBUG_DISAS
2507 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2509 "Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n",
2513 generate_exception(ctx
, EXCP_RI
);
2517 /* Load needed operands */
2523 /* Compare two registers */
2525 gen_load_gpr(t0
, rs
);
2526 gen_load_gpr(t1
, rt
);
2529 btgt
= ctx
->pc
+ 4 + offset
;
2543 /* Compare to zero */
2545 gen_load_gpr(t0
, rs
);
2548 btgt
= ctx
->pc
+ 4 + offset
;
2552 /* Jump to immediate */
2553 btgt
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2557 /* Jump to register */
2558 if (offset
!= 0 && offset
!= 16) {
2559 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2560 others are reserved. */
2561 MIPS_INVAL("jump hint");
2562 generate_exception(ctx
, EXCP_RI
);
2565 gen_load_gpr(btarget
, rs
);
2568 MIPS_INVAL("branch/jump");
2569 generate_exception(ctx
, EXCP_RI
);
2573 /* No condition to be computed */
2575 case OPC_BEQ
: /* rx == rx */
2576 case OPC_BEQL
: /* rx == rx likely */
2577 case OPC_BGEZ
: /* 0 >= 0 */
2578 case OPC_BGEZL
: /* 0 >= 0 likely */
2579 case OPC_BLEZ
: /* 0 <= 0 */
2580 case OPC_BLEZL
: /* 0 <= 0 likely */
2582 ctx
->hflags
|= MIPS_HFLAG_B
;
2583 MIPS_DEBUG("balways");
2585 case OPC_BGEZAL
: /* 0 >= 0 */
2586 case OPC_BGEZALL
: /* 0 >= 0 likely */
2587 /* Always take and link */
2589 ctx
->hflags
|= MIPS_HFLAG_B
;
2590 MIPS_DEBUG("balways and link");
2592 case OPC_BNE
: /* rx != rx */
2593 case OPC_BGTZ
: /* 0 > 0 */
2594 case OPC_BLTZ
: /* 0 < 0 */
2596 MIPS_DEBUG("bnever (NOP)");
2598 case OPC_BLTZAL
: /* 0 < 0 */
2599 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2600 gen_store_gpr(t0
, 31);
2601 MIPS_DEBUG("bnever and link");
2603 case OPC_BLTZALL
: /* 0 < 0 likely */
2604 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2605 gen_store_gpr(t0
, 31);
2606 /* Skip the instruction in the delay slot */
2607 MIPS_DEBUG("bnever, link and skip");
2610 case OPC_BNEL
: /* rx != rx likely */
2611 case OPC_BGTZL
: /* 0 > 0 likely */
2612 case OPC_BLTZL
: /* 0 < 0 likely */
2613 /* Skip the instruction in the delay slot */
2614 MIPS_DEBUG("bnever and skip");
2618 ctx
->hflags
|= MIPS_HFLAG_B
;
2619 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2623 ctx
->hflags
|= MIPS_HFLAG_B
;
2624 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2627 ctx
->hflags
|= MIPS_HFLAG_BR
;
2628 MIPS_DEBUG("jr %s", regnames
[rs
]);
2632 ctx
->hflags
|= MIPS_HFLAG_BR
;
2633 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2636 MIPS_INVAL("branch/jump");
2637 generate_exception(ctx
, EXCP_RI
);
2644 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2645 regnames
[rs
], regnames
[rt
], btgt
);
2649 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2650 regnames
[rs
], regnames
[rt
], btgt
);
2654 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2655 regnames
[rs
], regnames
[rt
], btgt
);
2659 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2660 regnames
[rs
], regnames
[rt
], btgt
);
2664 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2668 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2672 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2678 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2682 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2686 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2690 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2694 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2698 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2702 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2707 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2709 ctx
->hflags
|= MIPS_HFLAG_BC
;
2710 tcg_gen_trunc_tl_i32(bcond
, t0
);
2715 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2717 ctx
->hflags
|= MIPS_HFLAG_BL
;
2718 tcg_gen_trunc_tl_i32(bcond
, t0
);
2721 MIPS_INVAL("conditional branch/jump");
2722 generate_exception(ctx
, EXCP_RI
);
2726 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2727 blink
, ctx
->hflags
, btgt
);
2729 ctx
->btarget
= btgt
;
2731 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2732 gen_store_gpr(t0
, blink
);
2740 /* special3 bitfield operations */
2741 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2742 int rs
, int lsb
, int msb
)
2744 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
2745 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
2747 gen_load_gpr(t1
, rs
);
2752 tcg_gen_helper_1_1ii(do_ext
, t0
, t1
, lsb
, msb
+ 1);
2754 #if defined(TARGET_MIPS64)
2758 tcg_gen_helper_1_1ii(do_dext
, t0
, t1
, lsb
, msb
+ 1 + 32);
2763 tcg_gen_helper_1_1ii(do_dext
, t0
, t1
, lsb
+ 32, msb
+ 1);
2768 tcg_gen_helper_1_1ii(do_dext
, t0
, t1
, lsb
, msb
+ 1);
2774 gen_load_gpr(t0
, rt
);
2775 tcg_gen_helper_1_2ii(do_ins
, t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
2777 #if defined(TARGET_MIPS64)
2781 gen_load_gpr(t0
, rt
);
2782 tcg_gen_helper_1_2ii(do_dins
, t0
, t0
, t1
, lsb
, msb
- lsb
+ 1 + 32);
2787 gen_load_gpr(t0
, rt
);
2788 tcg_gen_helper_1_2ii(do_dins
, t0
, t0
, t1
, lsb
+ 32, msb
- lsb
+ 1);
2793 gen_load_gpr(t0
, rt
);
2794 tcg_gen_helper_1_2ii(do_dins
, t0
, t0
, t1
, lsb
, msb
- lsb
+ 1);
2799 MIPS_INVAL("bitops");
2800 generate_exception(ctx
, EXCP_RI
);
2805 gen_store_gpr(t0
, rt
);
2810 #ifndef CONFIG_USER_ONLY
2811 /* CP0 (MMU and control) */
2812 static inline void gen_mfc0_load32 (TCGv t
, target_ulong off
)
2814 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
2816 tcg_gen_ld_i32(r_tmp
, cpu_env
, off
);
2817 tcg_gen_ext_i32_tl(t
, r_tmp
);
2818 tcg_temp_free(r_tmp
);
2821 static inline void gen_mfc0_load64 (TCGv t
, target_ulong off
)
2823 tcg_gen_ld_tl(t
, cpu_env
, off
);
2824 tcg_gen_ext32s_tl(t
, t
);
2827 static inline void gen_mtc0_store32 (TCGv t
, target_ulong off
)
2829 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
2831 tcg_gen_trunc_tl_i32(r_tmp
, t
);
2832 tcg_gen_st_i32(r_tmp
, cpu_env
, off
);
2833 tcg_temp_free(r_tmp
);
2836 static inline void gen_mtc0_store64 (TCGv t
, target_ulong off
)
2838 tcg_gen_ext32s_tl(t
, t
);
2839 tcg_gen_st_tl(t
, cpu_env
, off
);
2842 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
2844 const char *rn
= "invalid";
2847 check_insn(env
, ctx
, ISA_MIPS32
);
2853 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
2857 check_insn(env
, ctx
, ASE_MT
);
2858 tcg_gen_helper_1_0(do_mfc0_mvpcontrol
, t0
);
2862 check_insn(env
, ctx
, ASE_MT
);
2863 tcg_gen_helper_1_0(do_mfc0_mvpconf0
, t0
);
2867 check_insn(env
, ctx
, ASE_MT
);
2868 tcg_gen_helper_1_0(do_mfc0_mvpconf1
, t0
);
2878 tcg_gen_helper_1_0(do_mfc0_random
, t0
);
2882 check_insn(env
, ctx
, ASE_MT
);
2883 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
2887 check_insn(env
, ctx
, ASE_MT
);
2888 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
2892 check_insn(env
, ctx
, ASE_MT
);
2893 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
2897 check_insn(env
, ctx
, ASE_MT
);
2898 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_YQMask
));
2902 check_insn(env
, ctx
, ASE_MT
);
2903 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
2907 check_insn(env
, ctx
, ASE_MT
);
2908 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
2909 rn
= "VPEScheFBack";
2912 check_insn(env
, ctx
, ASE_MT
);
2913 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
2923 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2924 tcg_gen_ext32s_tl(t0
, t0
);
2928 check_insn(env
, ctx
, ASE_MT
);
2929 tcg_gen_helper_1_0(do_mfc0_tcstatus
, t0
);
2933 check_insn(env
, ctx
, ASE_MT
);
2934 tcg_gen_helper_1_0(do_mfc0_tcbind
, t0
);
2938 check_insn(env
, ctx
, ASE_MT
);
2939 tcg_gen_helper_1_0(do_mfc0_tcrestart
, t0
);
2943 check_insn(env
, ctx
, ASE_MT
);
2944 tcg_gen_helper_1_0(do_mfc0_tchalt
, t0
);
2948 check_insn(env
, ctx
, ASE_MT
);
2949 tcg_gen_helper_1_0(do_mfc0_tccontext
, t0
);
2953 check_insn(env
, ctx
, ASE_MT
);
2954 tcg_gen_helper_1_0(do_mfc0_tcschedule
, t0
);
2958 check_insn(env
, ctx
, ASE_MT
);
2959 tcg_gen_helper_1_0(do_mfc0_tcschefback
, t0
);
2969 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2970 tcg_gen_ext32s_tl(t0
, t0
);
2980 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
2981 tcg_gen_ext32s_tl(t0
, t0
);
2985 // tcg_gen_helper_1_0(do_mfc0_contextconfig, t0); /* SmartMIPS ASE */
2986 rn
= "ContextConfig";
2995 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
2999 check_insn(env
, ctx
, ISA_MIPS32R2
);
3000 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
3010 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
3014 check_insn(env
, ctx
, ISA_MIPS32R2
);
3015 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
3019 check_insn(env
, ctx
, ISA_MIPS32R2
);
3020 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
3024 check_insn(env
, ctx
, ISA_MIPS32R2
);
3025 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
3029 check_insn(env
, ctx
, ISA_MIPS32R2
);
3030 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
3034 check_insn(env
, ctx
, ISA_MIPS32R2
);
3035 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
3045 check_insn(env
, ctx
, ISA_MIPS32R2
);
3046 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
3056 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3057 tcg_gen_ext32s_tl(t0
, t0
);
3067 /* Mark as an IO operation because we read the time. */
3070 tcg_gen_helper_1_0(do_mfc0_count
, t0
);
3073 ctx
->bstate
= BS_STOP
;
3077 /* 6,7 are implementation dependent */
3085 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3086 tcg_gen_ext32s_tl(t0
, t0
);
3096 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
3099 /* 6,7 are implementation dependent */
3107 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
3111 check_insn(env
, ctx
, ISA_MIPS32R2
);
3112 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
3116 check_insn(env
, ctx
, ISA_MIPS32R2
);
3117 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
3121 check_insn(env
, ctx
, ISA_MIPS32R2
);
3122 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3132 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
3142 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3143 tcg_gen_ext32s_tl(t0
, t0
);
3153 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
3157 check_insn(env
, ctx
, ISA_MIPS32R2
);
3158 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
3168 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
3172 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
3176 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
3180 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
3183 /* 4,5 are reserved */
3184 /* 6,7 are implementation dependent */
3186 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
3190 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
3200 tcg_gen_helper_1_0(do_mfc0_lladdr
, t0
);
3210 tcg_gen_helper_1_i(do_mfc0_watchlo
, t0
, sel
);
3220 tcg_gen_helper_1_i(do_mfc0_watchhi
, t0
, sel
);
3230 #if defined(TARGET_MIPS64)
3231 check_insn(env
, ctx
, ISA_MIPS3
);
3232 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3233 tcg_gen_ext32s_tl(t0
, t0
);
3242 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3245 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
3254 rn
= "'Diagnostic"; /* implementation dependent */
3259 tcg_gen_helper_1_0(do_mfc0_debug
, t0
); /* EJTAG support */
3263 // tcg_gen_helper_1_0(do_mfc0_tracecontrol, t0); /* PDtrace support */
3264 rn
= "TraceControl";
3267 // tcg_gen_helper_1_0(do_mfc0_tracecontrol2, t0); /* PDtrace support */
3268 rn
= "TraceControl2";
3271 // tcg_gen_helper_1_0(do_mfc0_usertracedata, t0); /* PDtrace support */
3272 rn
= "UserTraceData";
3275 // tcg_gen_helper_1_0(do_mfc0_tracebpc, t0); /* PDtrace support */
3286 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3287 tcg_gen_ext32s_tl(t0
, t0
);
3297 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
3298 rn
= "Performance0";
3301 // tcg_gen_helper_1_0(do_mfc0_performance1, t0);
3302 rn
= "Performance1";
3305 // tcg_gen_helper_1_0(do_mfc0_performance2, t0);
3306 rn
= "Performance2";
3309 // tcg_gen_helper_1_0(do_mfc0_performance3, t0);
3310 rn
= "Performance3";
3313 // tcg_gen_helper_1_0(do_mfc0_performance4, t0);
3314 rn
= "Performance4";
3317 // tcg_gen_helper_1_0(do_mfc0_performance5, t0);
3318 rn
= "Performance5";
3321 // tcg_gen_helper_1_0(do_mfc0_performance6, t0);
3322 rn
= "Performance6";
3325 // tcg_gen_helper_1_0(do_mfc0_performance7, t0);
3326 rn
= "Performance7";
3351 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
3358 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
3371 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
3378 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
3388 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3389 tcg_gen_ext32s_tl(t0
, t0
);
3400 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
3410 #if defined MIPS_DEBUG_DISAS
3411 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3412 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3419 #if defined MIPS_DEBUG_DISAS
3420 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
3421 fprintf(logfile
, "mfc0 %s (reg %d sel %d)\n",
3425 generate_exception(ctx
, EXCP_RI
);
3428 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
3430 const char *rn
= "invalid";
3433 check_insn(env
, ctx
, ISA_MIPS32
);
3442 tcg_gen_helper_0_1(do_mtc0_index
, t0
);
3446 check_insn(env
, ctx
, ASE_MT
);
3447 tcg_gen_helper_0_1(do_mtc0_mvpcontrol
, t0
);
3451 check_insn(env
, ctx
, ASE_MT
);
3456 check_insn(env
, ctx
, ASE_MT
);
3471 check_insn(env
, ctx
, ASE_MT
);
3472 tcg_gen_helper_0_1(do_mtc0_vpecontrol
, t0
);
3476 check_insn(env
, ctx
, ASE_MT
);
3477 tcg_gen_helper_0_1(do_mtc0_vpeconf0
, t0
);
3481 check_insn(env
, ctx
, ASE_MT
);
3482 tcg_gen_helper_0_1(do_mtc0_vpeconf1
, t0
);
3486 check_insn(env
, ctx
, ASE_MT
);
3487 tcg_gen_helper_0_1(do_mtc0_yqmask
, t0
);
3491 check_insn(env
, ctx
, ASE_MT
);
3492 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
3496 check_insn(env
, ctx
, ASE_MT
);
3497 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
3498 rn
= "VPEScheFBack";
3501 check_insn(env
, ctx
, ASE_MT
);
3502 tcg_gen_helper_0_1(do_mtc0_vpeopt
, t0
);
3512 tcg_gen_helper_0_1(do_mtc0_entrylo0
, t0
);
3516 check_insn(env
, ctx
, ASE_MT
);
3517 tcg_gen_helper_0_1(do_mtc0_tcstatus
, t0
);
3521 check_insn(env
, ctx
, ASE_MT
);
3522 tcg_gen_helper_0_1(do_mtc0_tcbind
, t0
);
3526 check_insn(env
, ctx
, ASE_MT
);
3527 tcg_gen_helper_0_1(do_mtc0_tcrestart
, t0
);
3531 check_insn(env
, ctx
, ASE_MT
);
3532 tcg_gen_helper_0_1(do_mtc0_tchalt
, t0
);
3536 check_insn(env
, ctx
, ASE_MT
);
3537 tcg_gen_helper_0_1(do_mtc0_tccontext
, t0
);
3541 check_insn(env
, ctx
, ASE_MT
);
3542 tcg_gen_helper_0_1(do_mtc0_tcschedule
, t0
);
3546 check_insn(env
, ctx
, ASE_MT
);
3547 tcg_gen_helper_0_1(do_mtc0_tcschefback
, t0
);
3557 tcg_gen_helper_0_1(do_mtc0_entrylo1
, t0
);
3567 tcg_gen_helper_0_1(do_mtc0_context
, t0
);
3571 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
3572 rn
= "ContextConfig";
3581 tcg_gen_helper_0_1(do_mtc0_pagemask
, t0
);
3585 check_insn(env
, ctx
, ISA_MIPS32R2
);
3586 tcg_gen_helper_0_1(do_mtc0_pagegrain
, t0
);
3596 tcg_gen_helper_0_1(do_mtc0_wired
, t0
);
3600 check_insn(env
, ctx
, ISA_MIPS32R2
);
3601 tcg_gen_helper_0_1(do_mtc0_srsconf0
, t0
);
3605 check_insn(env
, ctx
, ISA_MIPS32R2
);
3606 tcg_gen_helper_0_1(do_mtc0_srsconf1
, t0
);
3610 check_insn(env
, ctx
, ISA_MIPS32R2
);
3611 tcg_gen_helper_0_1(do_mtc0_srsconf2
, t0
);
3615 check_insn(env
, ctx
, ISA_MIPS32R2
);
3616 tcg_gen_helper_0_1(do_mtc0_srsconf3
, t0
);
3620 check_insn(env
, ctx
, ISA_MIPS32R2
);
3621 tcg_gen_helper_0_1(do_mtc0_srsconf4
, t0
);
3631 check_insn(env
, ctx
, ISA_MIPS32R2
);
3632 tcg_gen_helper_0_1(do_mtc0_hwrena
, t0
);
3646 tcg_gen_helper_0_1(do_mtc0_count
, t0
);
3649 /* 6,7 are implementation dependent */
3653 /* Stop translation as we may have switched the execution mode */
3654 ctx
->bstate
= BS_STOP
;
3659 tcg_gen_helper_0_1(do_mtc0_entryhi
, t0
);
3669 tcg_gen_helper_0_1(do_mtc0_compare
, t0
);
3672 /* 6,7 are implementation dependent */
3676 /* Stop translation as we may have switched the execution mode */
3677 ctx
->bstate
= BS_STOP
;
3682 tcg_gen_helper_0_1(do_mtc0_status
, t0
);
3683 /* BS_STOP isn't good enough here, hflags may have changed. */
3684 gen_save_pc(ctx
->pc
+ 4);
3685 ctx
->bstate
= BS_EXCP
;
3689 check_insn(env
, ctx
, ISA_MIPS32R2
);
3690 tcg_gen_helper_0_1(do_mtc0_intctl
, t0
);
3691 /* Stop translation as we may have switched the execution mode */
3692 ctx
->bstate
= BS_STOP
;
3696 check_insn(env
, ctx
, ISA_MIPS32R2
);
3697 tcg_gen_helper_0_1(do_mtc0_srsctl
, t0
);
3698 /* Stop translation as we may have switched the execution mode */
3699 ctx
->bstate
= BS_STOP
;
3703 check_insn(env
, ctx
, ISA_MIPS32R2
);
3704 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3705 /* Stop translation as we may have switched the execution mode */
3706 ctx
->bstate
= BS_STOP
;
3716 tcg_gen_helper_0_1(do_mtc0_cause
, t0
);
3722 /* Stop translation as we may have switched the execution mode */
3723 ctx
->bstate
= BS_STOP
;
3728 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_EPC
));
3742 check_insn(env
, ctx
, ISA_MIPS32R2
);
3743 tcg_gen_helper_0_1(do_mtc0_ebase
, t0
);
3753 tcg_gen_helper_0_1(do_mtc0_config0
, t0
);
3755 /* Stop translation as we may have switched the execution mode */
3756 ctx
->bstate
= BS_STOP
;
3759 /* ignored, read only */
3763 tcg_gen_helper_0_1(do_mtc0_config2
, t0
);
3765 /* Stop translation as we may have switched the execution mode */
3766 ctx
->bstate
= BS_STOP
;
3769 /* ignored, read only */
3772 /* 4,5 are reserved */
3773 /* 6,7 are implementation dependent */
3783 rn
= "Invalid config selector";
3800 tcg_gen_helper_0_1i(do_mtc0_watchlo
, t0
, sel
);
3810 tcg_gen_helper_0_1i(do_mtc0_watchhi
, t0
, sel
);
3820 #if defined(TARGET_MIPS64)
3821 check_insn(env
, ctx
, ISA_MIPS3
);
3822 tcg_gen_helper_0_1(do_mtc0_xcontext
, t0
);
3831 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3834 tcg_gen_helper_0_1(do_mtc0_framemask
, t0
);
3843 rn
= "Diagnostic"; /* implementation dependent */
3848 tcg_gen_helper_0_1(do_mtc0_debug
, t0
); /* EJTAG support */
3849 /* BS_STOP isn't good enough here, hflags may have changed. */
3850 gen_save_pc(ctx
->pc
+ 4);
3851 ctx
->bstate
= BS_EXCP
;
3855 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
3856 rn
= "TraceControl";
3857 /* Stop translation as we may have switched the execution mode */
3858 ctx
->bstate
= BS_STOP
;
3861 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
3862 rn
= "TraceControl2";
3863 /* Stop translation as we may have switched the execution mode */
3864 ctx
->bstate
= BS_STOP
;
3867 /* Stop translation as we may have switched the execution mode */
3868 ctx
->bstate
= BS_STOP
;
3869 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
3870 rn
= "UserTraceData";
3871 /* Stop translation as we may have switched the execution mode */
3872 ctx
->bstate
= BS_STOP
;
3875 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
3876 /* Stop translation as we may have switched the execution mode */
3877 ctx
->bstate
= BS_STOP
;
3888 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_DEPC
));
3898 tcg_gen_helper_0_1(do_mtc0_performance0
, t0
);
3899 rn
= "Performance0";
3902 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
3903 rn
= "Performance1";
3906 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
3907 rn
= "Performance2";
3910 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
3911 rn
= "Performance3";
3914 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
3915 rn
= "Performance4";
3918 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
3919 rn
= "Performance5";
3922 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
3923 rn
= "Performance6";
3926 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
3927 rn
= "Performance7";
3953 tcg_gen_helper_0_1(do_mtc0_taglo
, t0
);
3960 tcg_gen_helper_0_1(do_mtc0_datalo
, t0
);
3973 tcg_gen_helper_0_1(do_mtc0_taghi
, t0
);
3980 tcg_gen_helper_0_1(do_mtc0_datahi
, t0
);
3991 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_ErrorEPC
));
4002 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
4008 /* Stop translation as we may have switched the execution mode */
4009 ctx
->bstate
= BS_STOP
;
4014 #if defined MIPS_DEBUG_DISAS
4015 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4016 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
4020 /* For simplicity assume that all writes can cause interrupts. */
4023 ctx
->bstate
= BS_STOP
;
4028 #if defined MIPS_DEBUG_DISAS
4029 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4030 fprintf(logfile
, "mtc0 %s (reg %d sel %d)\n",
4034 generate_exception(ctx
, EXCP_RI
);
4037 #if defined(TARGET_MIPS64)
4038 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
4040 const char *rn
= "invalid";
4043 check_insn(env
, ctx
, ISA_MIPS64
);
4049 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
4053 check_insn(env
, ctx
, ASE_MT
);
4054 tcg_gen_helper_1_0(do_mfc0_mvpcontrol
, t0
);
4058 check_insn(env
, ctx
, ASE_MT
);
4059 tcg_gen_helper_1_0(do_mfc0_mvpconf0
, t0
);
4063 check_insn(env
, ctx
, ASE_MT
);
4064 tcg_gen_helper_1_0(do_mfc0_mvpconf1
, t0
);
4074 tcg_gen_helper_1_0(do_mfc0_random
, t0
);
4078 check_insn(env
, ctx
, ASE_MT
);
4079 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
4083 check_insn(env
, ctx
, ASE_MT
);
4084 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
4088 check_insn(env
, ctx
, ASE_MT
);
4089 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
4093 check_insn(env
, ctx
, ASE_MT
);
4094 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4098 check_insn(env
, ctx
, ASE_MT
);
4099 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4103 check_insn(env
, ctx
, ASE_MT
);
4104 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4105 rn
= "VPEScheFBack";
4108 check_insn(env
, ctx
, ASE_MT
);
4109 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
4119 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4123 check_insn(env
, ctx
, ASE_MT
);
4124 tcg_gen_helper_1_0(do_mfc0_tcstatus
, t0
);
4128 check_insn(env
, ctx
, ASE_MT
);
4129 tcg_gen_helper_1_0(do_mfc0_tcbind
, t0
);
4133 check_insn(env
, ctx
, ASE_MT
);
4134 tcg_gen_helper_1_0(do_dmfc0_tcrestart
, t0
);
4138 check_insn(env
, ctx
, ASE_MT
);
4139 tcg_gen_helper_1_0(do_dmfc0_tchalt
, t0
);
4143 check_insn(env
, ctx
, ASE_MT
);
4144 tcg_gen_helper_1_0(do_dmfc0_tccontext
, t0
);
4148 check_insn(env
, ctx
, ASE_MT
);
4149 tcg_gen_helper_1_0(do_dmfc0_tcschedule
, t0
);
4153 check_insn(env
, ctx
, ASE_MT
);
4154 tcg_gen_helper_1_0(do_dmfc0_tcschefback
, t0
);
4164 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4174 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4178 // tcg_gen_helper_1_0(do_dmfc0_contextconfig, t0); /* SmartMIPS ASE */
4179 rn
= "ContextConfig";
4188 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
4192 check_insn(env
, ctx
, ISA_MIPS32R2
);
4193 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
4203 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
4207 check_insn(env
, ctx
, ISA_MIPS32R2
);
4208 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
4212 check_insn(env
, ctx
, ISA_MIPS32R2
);
4213 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
4217 check_insn(env
, ctx
, ISA_MIPS32R2
);
4218 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
4222 check_insn(env
, ctx
, ISA_MIPS32R2
);
4223 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
4227 check_insn(env
, ctx
, ISA_MIPS32R2
);
4228 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
4238 check_insn(env
, ctx
, ISA_MIPS32R2
);
4239 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
4249 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4259 /* Mark as an IO operation because we read the time. */
4262 tcg_gen_helper_1_0(do_mfc0_count
, t0
);
4265 ctx
->bstate
= BS_STOP
;
4269 /* 6,7 are implementation dependent */
4277 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4287 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
4290 /* 6,7 are implementation dependent */
4298 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
4302 check_insn(env
, ctx
, ISA_MIPS32R2
);
4303 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
4307 check_insn(env
, ctx
, ISA_MIPS32R2
);
4308 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
4312 check_insn(env
, ctx
, ISA_MIPS32R2
);
4313 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4323 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
4333 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4343 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
4347 check_insn(env
, ctx
, ISA_MIPS32R2
);
4348 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
4358 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
4362 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
4366 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
4370 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
4373 /* 6,7 are implementation dependent */
4375 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
4379 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
4389 tcg_gen_helper_1_0(do_dmfc0_lladdr
, t0
);
4399 tcg_gen_helper_1_i(do_dmfc0_watchlo
, t0
, sel
);
4409 tcg_gen_helper_1_i(do_mfc0_watchhi
, t0
, sel
);
4419 check_insn(env
, ctx
, ISA_MIPS3
);
4420 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4428 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4431 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
4440 rn
= "'Diagnostic"; /* implementation dependent */
4445 tcg_gen_helper_1_0(do_mfc0_debug
, t0
); /* EJTAG support */
4449 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol, t0); /* PDtrace support */
4450 rn
= "TraceControl";
4453 // tcg_gen_helper_1_0(do_dmfc0_tracecontrol2, t0); /* PDtrace support */
4454 rn
= "TraceControl2";
4457 // tcg_gen_helper_1_0(do_dmfc0_usertracedata, t0); /* PDtrace support */
4458 rn
= "UserTraceData";
4461 // tcg_gen_helper_1_0(do_dmfc0_tracebpc, t0); /* PDtrace support */
4472 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4482 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
4483 rn
= "Performance0";
4486 // tcg_gen_helper_1_0(do_dmfc0_performance1, t0);
4487 rn
= "Performance1";
4490 // tcg_gen_helper_1_0(do_dmfc0_performance2, t0);
4491 rn
= "Performance2";
4494 // tcg_gen_helper_1_0(do_dmfc0_performance3, t0);
4495 rn
= "Performance3";
4498 // tcg_gen_helper_1_0(do_dmfc0_performance4, t0);
4499 rn
= "Performance4";
4502 // tcg_gen_helper_1_0(do_dmfc0_performance5, t0);
4503 rn
= "Performance5";
4506 // tcg_gen_helper_1_0(do_dmfc0_performance6, t0);
4507 rn
= "Performance6";
4510 // tcg_gen_helper_1_0(do_dmfc0_performance7, t0);
4511 rn
= "Performance7";
4536 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
4543 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
4556 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
4563 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
4573 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4584 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
4594 #if defined MIPS_DEBUG_DISAS
4595 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4596 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4603 #if defined MIPS_DEBUG_DISAS
4604 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
4605 fprintf(logfile
, "dmfc0 %s (reg %d sel %d)\n",
4609 generate_exception(ctx
, EXCP_RI
);
4612 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
4614 const char *rn
= "invalid";
4617 check_insn(env
, ctx
, ISA_MIPS64
);
4626 tcg_gen_helper_0_1(do_mtc0_index
, t0
);
4630 check_insn(env
, ctx
, ASE_MT
);
4631 tcg_gen_helper_0_1(do_mtc0_mvpcontrol
, t0
);
4635 check_insn(env
, ctx
, ASE_MT
);
4640 check_insn(env
, ctx
, ASE_MT
);
4655 check_insn(env
, ctx
, ASE_MT
);
4656 tcg_gen_helper_0_1(do_mtc0_vpecontrol
, t0
);
4660 check_insn(env
, ctx
, ASE_MT
);
4661 tcg_gen_helper_0_1(do_mtc0_vpeconf0
, t0
);
4665 check_insn(env
, ctx
, ASE_MT
);
4666 tcg_gen_helper_0_1(do_mtc0_vpeconf1
, t0
);
4670 check_insn(env
, ctx
, ASE_MT
);
4671 tcg_gen_helper_0_1(do_mtc0_yqmask
, t0
);
4675 check_insn(env
, ctx
, ASE_MT
);
4676 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4680 check_insn(env
, ctx
, ASE_MT
);
4681 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4682 rn
= "VPEScheFBack";
4685 check_insn(env
, ctx
, ASE_MT
);
4686 tcg_gen_helper_0_1(do_mtc0_vpeopt
, t0
);
4696 tcg_gen_helper_0_1(do_mtc0_entrylo0
, t0
);
4700 check_insn(env
, ctx
, ASE_MT
);
4701 tcg_gen_helper_0_1(do_mtc0_tcstatus
, t0
);
4705 check_insn(env
, ctx
, ASE_MT
);
4706 tcg_gen_helper_0_1(do_mtc0_tcbind
, t0
);
4710 check_insn(env
, ctx
, ASE_MT
);
4711 tcg_gen_helper_0_1(do_mtc0_tcrestart
, t0
);
4715 check_insn(env
, ctx
, ASE_MT
);
4716 tcg_gen_helper_0_1(do_mtc0_tchalt
, t0
);
4720 check_insn(env
, ctx
, ASE_MT
);
4721 tcg_gen_helper_0_1(do_mtc0_tccontext
, t0
);
4725 check_insn(env
, ctx
, ASE_MT
);
4726 tcg_gen_helper_0_1(do_mtc0_tcschedule
, t0
);
4730 check_insn(env
, ctx
, ASE_MT
);
4731 tcg_gen_helper_0_1(do_mtc0_tcschefback
, t0
);
4741 tcg_gen_helper_0_1(do_mtc0_entrylo1
, t0
);
4751 tcg_gen_helper_0_1(do_mtc0_context
, t0
);
4755 // tcg_gen_helper_0_1(do_mtc0_contextconfig, t0); /* SmartMIPS ASE */
4756 rn
= "ContextConfig";
4765 tcg_gen_helper_0_1(do_mtc0_pagemask
, t0
);
4769 check_insn(env
, ctx
, ISA_MIPS32R2
);
4770 tcg_gen_helper_0_1(do_mtc0_pagegrain
, t0
);
4780 tcg_gen_helper_0_1(do_mtc0_wired
, t0
);
4784 check_insn(env
, ctx
, ISA_MIPS32R2
);
4785 tcg_gen_helper_0_1(do_mtc0_srsconf0
, t0
);
4789 check_insn(env
, ctx
, ISA_MIPS32R2
);
4790 tcg_gen_helper_0_1(do_mtc0_srsconf1
, t0
);
4794 check_insn(env
, ctx
, ISA_MIPS32R2
);
4795 tcg_gen_helper_0_1(do_mtc0_srsconf2
, t0
);
4799 check_insn(env
, ctx
, ISA_MIPS32R2
);
4800 tcg_gen_helper_0_1(do_mtc0_srsconf3
, t0
);
4804 check_insn(env
, ctx
, ISA_MIPS32R2
);
4805 tcg_gen_helper_0_1(do_mtc0_srsconf4
, t0
);
4815 check_insn(env
, ctx
, ISA_MIPS32R2
);
4816 tcg_gen_helper_0_1(do_mtc0_hwrena
, t0
);
4830 tcg_gen_helper_0_1(do_mtc0_count
, t0
);
4833 /* 6,7 are implementation dependent */
4837 /* Stop translation as we may have switched the execution mode */
4838 ctx
->bstate
= BS_STOP
;
4843 tcg_gen_helper_0_1(do_mtc0_entryhi
, t0
);
4853 tcg_gen_helper_0_1(do_mtc0_compare
, t0
);
4856 /* 6,7 are implementation dependent */
4860 /* Stop translation as we may have switched the execution mode */
4861 ctx
->bstate
= BS_STOP
;
4866 tcg_gen_helper_0_1(do_mtc0_status
, t0
);
4867 /* BS_STOP isn't good enough here, hflags may have changed. */
4868 gen_save_pc(ctx
->pc
+ 4);
4869 ctx
->bstate
= BS_EXCP
;
4873 check_insn(env
, ctx
, ISA_MIPS32R2
);
4874 tcg_gen_helper_0_1(do_mtc0_intctl
, t0
);
4875 /* Stop translation as we may have switched the execution mode */
4876 ctx
->bstate
= BS_STOP
;
4880 check_insn(env
, ctx
, ISA_MIPS32R2
);
4881 tcg_gen_helper_0_1(do_mtc0_srsctl
, t0
);
4882 /* Stop translation as we may have switched the execution mode */
4883 ctx
->bstate
= BS_STOP
;
4887 check_insn(env
, ctx
, ISA_MIPS32R2
);
4888 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4889 /* Stop translation as we may have switched the execution mode */
4890 ctx
->bstate
= BS_STOP
;
4900 tcg_gen_helper_0_1(do_mtc0_cause
, t0
);
4906 /* Stop translation as we may have switched the execution mode */
4907 ctx
->bstate
= BS_STOP
;
4912 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4926 check_insn(env
, ctx
, ISA_MIPS32R2
);
4927 tcg_gen_helper_0_1(do_mtc0_ebase
, t0
);
4937 tcg_gen_helper_0_1(do_mtc0_config0
, t0
);
4939 /* Stop translation as we may have switched the execution mode */
4940 ctx
->bstate
= BS_STOP
;
4947 tcg_gen_helper_0_1(do_mtc0_config2
, t0
);
4949 /* Stop translation as we may have switched the execution mode */
4950 ctx
->bstate
= BS_STOP
;
4956 /* 6,7 are implementation dependent */
4958 rn
= "Invalid config selector";
4975 tcg_gen_helper_0_1i(do_mtc0_watchlo
, t0
, sel
);
4985 tcg_gen_helper_0_1i(do_mtc0_watchhi
, t0
, sel
);
4995 check_insn(env
, ctx
, ISA_MIPS3
);
4996 tcg_gen_helper_0_1(do_mtc0_xcontext
, t0
);
5004 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5007 tcg_gen_helper_0_1(do_mtc0_framemask
, t0
);
5016 rn
= "Diagnostic"; /* implementation dependent */
5021 tcg_gen_helper_0_1(do_mtc0_debug
, t0
); /* EJTAG support */
5022 /* BS_STOP isn't good enough here, hflags may have changed. */
5023 gen_save_pc(ctx
->pc
+ 4);
5024 ctx
->bstate
= BS_EXCP
;
5028 // tcg_gen_helper_0_1(do_mtc0_tracecontrol, t0); /* PDtrace support */
5029 /* Stop translation as we may have switched the execution mode */
5030 ctx
->bstate
= BS_STOP
;
5031 rn
= "TraceControl";
5034 // tcg_gen_helper_0_1(do_mtc0_tracecontrol2, t0); /* PDtrace support */
5035 /* Stop translation as we may have switched the execution mode */
5036 ctx
->bstate
= BS_STOP
;
5037 rn
= "TraceControl2";
5040 // tcg_gen_helper_0_1(do_mtc0_usertracedata, t0); /* PDtrace support */
5041 /* Stop translation as we may have switched the execution mode */
5042 ctx
->bstate
= BS_STOP
;
5043 rn
= "UserTraceData";
5046 // tcg_gen_helper_0_1(do_mtc0_tracebpc, t0); /* PDtrace support */
5047 /* Stop translation as we may have switched the execution mode */
5048 ctx
->bstate
= BS_STOP
;
5059 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5069 tcg_gen_helper_0_1(do_mtc0_performance0
, t0
);
5070 rn
= "Performance0";
5073 // tcg_gen_helper_0_1(do_mtc0_performance1, t0);
5074 rn
= "Performance1";
5077 // tcg_gen_helper_0_1(do_mtc0_performance2, t0);
5078 rn
= "Performance2";
5081 // tcg_gen_helper_0_1(do_mtc0_performance3, t0);
5082 rn
= "Performance3";
5085 // tcg_gen_helper_0_1(do_mtc0_performance4, t0);
5086 rn
= "Performance4";
5089 // tcg_gen_helper_0_1(do_mtc0_performance5, t0);
5090 rn
= "Performance5";
5093 // tcg_gen_helper_0_1(do_mtc0_performance6, t0);
5094 rn
= "Performance6";
5097 // tcg_gen_helper_0_1(do_mtc0_performance7, t0);
5098 rn
= "Performance7";
5124 tcg_gen_helper_0_1(do_mtc0_taglo
, t0
);
5131 tcg_gen_helper_0_1(do_mtc0_datalo
, t0
);
5144 tcg_gen_helper_0_1(do_mtc0_taghi
, t0
);
5151 tcg_gen_helper_0_1(do_mtc0_datahi
, t0
);
5162 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5173 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
5179 /* Stop translation as we may have switched the execution mode */
5180 ctx
->bstate
= BS_STOP
;
5185 #if defined MIPS_DEBUG_DISAS
5186 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5187 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
5192 /* For simplicity assume that all writes can cause interrupts. */
5195 ctx
->bstate
= BS_STOP
;
5201 #if defined MIPS_DEBUG_DISAS
5202 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5203 fprintf(logfile
, "dmtc0 %s (reg %d sel %d)\n",
5207 generate_exception(ctx
, EXCP_RI
);
5209 #endif /* TARGET_MIPS64 */
5211 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5212 int u
, int sel
, int h
)
5214 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5215 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5217 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5218 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5219 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5220 tcg_gen_movi_tl(t0
, -1);
5221 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5222 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5223 tcg_gen_movi_tl(t0
, -1);
5229 tcg_gen_helper_1_1(do_mftc0_tcstatus
, t0
, t0
);
5232 tcg_gen_helper_1_1(do_mftc0_tcbind
, t0
, t0
);
5235 tcg_gen_helper_1_1(do_mftc0_tcrestart
, t0
, t0
);
5238 tcg_gen_helper_1_1(do_mftc0_tchalt
, t0
, t0
);
5241 tcg_gen_helper_1_1(do_mftc0_tccontext
, t0
, t0
);
5244 tcg_gen_helper_1_1(do_mftc0_tcschedule
, t0
, t0
);
5247 tcg_gen_helper_1_1(do_mftc0_tcschefback
, t0
, t0
);
5250 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5257 tcg_gen_helper_1_1(do_mftc0_entryhi
, t0
, t0
);
5260 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5266 tcg_gen_helper_1_1(do_mftc0_status
, t0
, t0
);
5269 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5275 tcg_gen_helper_1_1(do_mftc0_debug
, t0
, t0
);
5278 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5283 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5285 } else switch (sel
) {
5286 /* GPR registers. */
5288 tcg_gen_helper_1_1i(do_mftgpr
, t0
, t0
, rt
);
5290 /* Auxiliary CPU registers */
5294 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 0);
5297 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 0);
5300 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 0);
5303 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 1);
5306 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 1);
5309 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 1);
5312 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 2);
5315 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 2);
5318 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 2);
5321 tcg_gen_helper_1_1i(do_mftlo
, t0
, t0
, 3);
5324 tcg_gen_helper_1_1i(do_mfthi
, t0
, t0
, 3);
5327 tcg_gen_helper_1_1i(do_mftacx
, t0
, t0
, 3);
5330 tcg_gen_helper_1_1(do_mftdsp
, t0
, t0
);
5336 /* Floating point (COP1). */
5338 /* XXX: For now we support only a single FPU context. */
5340 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5342 gen_load_fpr32(fp0
, rt
);
5343 tcg_gen_ext_i32_tl(t0
, fp0
);
5346 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5348 gen_load_fpr32h(fp0
, rt
);
5349 tcg_gen_ext_i32_tl(t0
, fp0
);
5354 /* XXX: For now we support only a single FPU context. */
5355 tcg_gen_helper_1_1i(do_cfc1
, t0
, t0
, rt
);
5357 /* COP2: Not implemented. */
5364 #if defined MIPS_DEBUG_DISAS
5365 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5366 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5370 gen_store_gpr(t0
, rd
);
5376 #if defined MIPS_DEBUG_DISAS
5377 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5378 fprintf(logfile
, "mftr (reg %d u %d sel %d h %d)\n",
5382 generate_exception(ctx
, EXCP_RI
);
5385 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5386 int u
, int sel
, int h
)
5388 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5389 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5391 gen_load_gpr(t0
, rt
);
5392 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5393 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5394 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5396 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5397 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5404 tcg_gen_helper_0_1(do_mttc0_tcstatus
, t0
);
5407 tcg_gen_helper_0_1(do_mttc0_tcbind
, t0
);
5410 tcg_gen_helper_0_1(do_mttc0_tcrestart
, t0
);
5413 tcg_gen_helper_0_1(do_mttc0_tchalt
, t0
);
5416 tcg_gen_helper_0_1(do_mttc0_tccontext
, t0
);
5419 tcg_gen_helper_0_1(do_mttc0_tcschedule
, t0
);
5422 tcg_gen_helper_0_1(do_mttc0_tcschefback
, t0
);
5425 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5432 tcg_gen_helper_0_1(do_mttc0_entryhi
, t0
);
5435 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5441 tcg_gen_helper_0_1(do_mttc0_status
, t0
);
5444 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5450 tcg_gen_helper_0_1(do_mttc0_debug
, t0
);
5453 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5458 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5460 } else switch (sel
) {
5461 /* GPR registers. */
5463 tcg_gen_helper_0_1i(do_mttgpr
, t0
, rd
);
5465 /* Auxiliary CPU registers */
5469 tcg_gen_helper_0_1i(do_mttlo
, t0
, 0);
5472 tcg_gen_helper_0_1i(do_mtthi
, t0
, 0);
5475 tcg_gen_helper_0_1i(do_mttacx
, t0
, 0);
5478 tcg_gen_helper_0_1i(do_mttlo
, t0
, 1);
5481 tcg_gen_helper_0_1i(do_mtthi
, t0
, 1);
5484 tcg_gen_helper_0_1i(do_mttacx
, t0
, 1);
5487 tcg_gen_helper_0_1i(do_mttlo
, t0
, 2);
5490 tcg_gen_helper_0_1i(do_mtthi
, t0
, 2);
5493 tcg_gen_helper_0_1i(do_mttacx
, t0
, 2);
5496 tcg_gen_helper_0_1i(do_mttlo
, t0
, 3);
5499 tcg_gen_helper_0_1i(do_mtthi
, t0
, 3);
5502 tcg_gen_helper_0_1i(do_mttacx
, t0
, 3);
5505 tcg_gen_helper_0_1(do_mttdsp
, t0
);
5511 /* Floating point (COP1). */
5513 /* XXX: For now we support only a single FPU context. */
5515 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5517 tcg_gen_trunc_tl_i32(fp0
, t0
);
5518 gen_store_fpr32(fp0
, rd
);
5521 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5523 tcg_gen_trunc_tl_i32(fp0
, t0
);
5524 gen_store_fpr32h(fp0
, rd
);
5529 /* XXX: For now we support only a single FPU context. */
5530 tcg_gen_helper_0_1i(do_ctc1
, t0
, rd
);
5532 /* COP2: Not implemented. */
5539 #if defined MIPS_DEBUG_DISAS
5540 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5541 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5550 #if defined MIPS_DEBUG_DISAS
5551 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
5552 fprintf(logfile
, "mttr (reg %d u %d sel %d h %d)\n",
5556 generate_exception(ctx
, EXCP_RI
);
5559 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5561 const char *opn
= "ldst";
5570 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5572 gen_mfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5573 gen_store_gpr(t0
, rt
);
5580 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5582 gen_load_gpr(t0
, rt
);
5583 save_cpu_state(ctx
, 1);
5584 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5589 #if defined(TARGET_MIPS64)
5591 check_insn(env
, ctx
, ISA_MIPS3
);
5597 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5599 gen_dmfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5600 gen_store_gpr(t0
, rt
);
5606 check_insn(env
, ctx
, ISA_MIPS3
);
5608 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5610 gen_load_gpr(t0
, rt
);
5611 save_cpu_state(ctx
, 1);
5612 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5619 check_insn(env
, ctx
, ASE_MT
);
5624 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5625 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5629 check_insn(env
, ctx
, ASE_MT
);
5630 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5631 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5636 if (!env
->tlb
->do_tlbwi
)
5638 tcg_gen_helper_0_0(env
->tlb
->do_tlbwi
);
5642 if (!env
->tlb
->do_tlbwr
)
5644 tcg_gen_helper_0_0(env
->tlb
->do_tlbwr
);
5648 if (!env
->tlb
->do_tlbp
)
5650 tcg_gen_helper_0_0(env
->tlb
->do_tlbp
);
5654 if (!env
->tlb
->do_tlbr
)
5656 tcg_gen_helper_0_0(env
->tlb
->do_tlbr
);
5660 check_insn(env
, ctx
, ISA_MIPS2
);
5661 save_cpu_state(ctx
, 1);
5662 tcg_gen_helper_0_0(do_eret
);
5663 ctx
->bstate
= BS_EXCP
;
5667 check_insn(env
, ctx
, ISA_MIPS32
);
5668 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5670 generate_exception(ctx
, EXCP_RI
);
5672 save_cpu_state(ctx
, 1);
5673 tcg_gen_helper_0_0(do_deret
);
5674 ctx
->bstate
= BS_EXCP
;
5679 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5680 /* If we get an exception, we want to restart at next instruction */
5682 save_cpu_state(ctx
, 1);
5684 tcg_gen_helper_0_0(do_wait
);
5685 ctx
->bstate
= BS_EXCP
;
5690 generate_exception(ctx
, EXCP_RI
);
5693 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5695 #endif /* !CONFIG_USER_ONLY */
5697 /* CP1 Branches (before delay slot) */
5698 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5699 int32_t cc
, int32_t offset
)
5701 target_ulong btarget
;
5702 const char *opn
= "cp1 cond branch";
5703 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5704 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
5707 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5709 btarget
= ctx
->pc
+ 4 + offset
;
5714 int l1
= gen_new_label();
5715 int l2
= gen_new_label();
5716 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5718 get_fp_cond(r_tmp1
);
5719 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5720 tcg_temp_free(r_tmp1
);
5721 tcg_gen_not_tl(t0
, t0
);
5722 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5723 tcg_gen_and_tl(t0
, t0
, t1
);
5724 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5725 tcg_gen_movi_tl(t0
, 0);
5728 tcg_gen_movi_tl(t0
, 1);
5735 int l1
= gen_new_label();
5736 int l2
= gen_new_label();
5737 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5739 get_fp_cond(r_tmp1
);
5740 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5741 tcg_temp_free(r_tmp1
);
5742 tcg_gen_not_tl(t0
, t0
);
5743 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5744 tcg_gen_and_tl(t0
, t0
, t1
);
5745 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5746 tcg_gen_movi_tl(t0
, 0);
5749 tcg_gen_movi_tl(t0
, 1);
5756 int l1
= gen_new_label();
5757 int l2
= gen_new_label();
5758 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5760 get_fp_cond(r_tmp1
);
5761 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5762 tcg_temp_free(r_tmp1
);
5763 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5764 tcg_gen_and_tl(t0
, t0
, t1
);
5765 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5766 tcg_gen_movi_tl(t0
, 0);
5769 tcg_gen_movi_tl(t0
, 1);
5776 int l1
= gen_new_label();
5777 int l2
= gen_new_label();
5778 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5780 get_fp_cond(r_tmp1
);
5781 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5782 tcg_temp_free(r_tmp1
);
5783 tcg_gen_movi_tl(t1
, 0x1 << cc
);
5784 tcg_gen_and_tl(t0
, t0
, t1
);
5785 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5786 tcg_gen_movi_tl(t0
, 0);
5789 tcg_gen_movi_tl(t0
, 1);
5794 ctx
->hflags
|= MIPS_HFLAG_BL
;
5795 tcg_gen_trunc_tl_i32(bcond
, t0
);
5799 int l1
= gen_new_label();
5800 int l2
= gen_new_label();
5801 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5803 get_fp_cond(r_tmp1
);
5804 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5805 tcg_temp_free(r_tmp1
);
5806 tcg_gen_not_tl(t0
, t0
);
5807 tcg_gen_movi_tl(t1
, 0x3 << cc
);
5808 tcg_gen_and_tl(t0
, t0
, t1
);
5809 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5810 tcg_gen_movi_tl(t0
, 0);
5813 tcg_gen_movi_tl(t0
, 1);
5820 int l1
= gen_new_label();
5821 int l2
= gen_new_label();
5822 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5824 get_fp_cond(r_tmp1
);
5825 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5826 tcg_temp_free(r_tmp1
);
5827 tcg_gen_movi_tl(t1
, 0x3 << cc
);
5828 tcg_gen_and_tl(t0
, t0
, t1
);
5829 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5830 tcg_gen_movi_tl(t0
, 0);
5833 tcg_gen_movi_tl(t0
, 1);
5840 int l1
= gen_new_label();
5841 int l2
= gen_new_label();
5842 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5844 get_fp_cond(r_tmp1
);
5845 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5846 tcg_temp_free(r_tmp1
);
5847 tcg_gen_not_tl(t0
, t0
);
5848 tcg_gen_movi_tl(t1
, 0xf << cc
);
5849 tcg_gen_and_tl(t0
, t0
, t1
);
5850 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5851 tcg_gen_movi_tl(t0
, 0);
5854 tcg_gen_movi_tl(t0
, 1);
5861 int l1
= gen_new_label();
5862 int l2
= gen_new_label();
5863 TCGv r_tmp1
= tcg_temp_new(TCG_TYPE_I32
);
5865 get_fp_cond(r_tmp1
);
5866 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
5867 tcg_temp_free(r_tmp1
);
5868 tcg_gen_movi_tl(t1
, 0xf << cc
);
5869 tcg_gen_and_tl(t0
, t0
, t1
);
5870 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
5871 tcg_gen_movi_tl(t0
, 0);
5874 tcg_gen_movi_tl(t0
, 1);
5879 ctx
->hflags
|= MIPS_HFLAG_BC
;
5880 tcg_gen_trunc_tl_i32(bcond
, t0
);
5884 generate_exception (ctx
, EXCP_RI
);
5887 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5888 ctx
->hflags
, btarget
);
5889 ctx
->btarget
= btarget
;
5896 /* Coprocessor 1 (FPU) */
5898 #define FOP(func, fmt) (((fmt) << 21) | (func))
5900 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5902 const char *opn
= "cp1 move";
5903 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5908 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5910 gen_load_fpr32(fp0
, fs
);
5911 tcg_gen_ext_i32_tl(t0
, fp0
);
5914 gen_store_gpr(t0
, rt
);
5918 gen_load_gpr(t0
, rt
);
5920 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5922 tcg_gen_trunc_tl_i32(fp0
, t0
);
5923 gen_store_fpr32(fp0
, fs
);
5929 tcg_gen_helper_1_i(do_cfc1
, t0
, fs
);
5930 gen_store_gpr(t0
, rt
);
5934 gen_load_gpr(t0
, rt
);
5935 tcg_gen_helper_0_1i(do_ctc1
, t0
, fs
);
5940 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
5942 gen_load_fpr64(ctx
, fp0
, fs
);
5943 tcg_gen_mov_tl(t0
, fp0
);
5946 gen_store_gpr(t0
, rt
);
5950 gen_load_gpr(t0
, rt
);
5952 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
5954 tcg_gen_mov_tl(fp0
, t0
);
5955 gen_store_fpr64(ctx
, fp0
, fs
);
5962 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5964 gen_load_fpr32h(fp0
, fs
);
5965 tcg_gen_ext_i32_tl(t0
, fp0
);
5968 gen_store_gpr(t0
, rt
);
5972 gen_load_gpr(t0
, rt
);
5974 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
5976 tcg_gen_trunc_tl_i32(fp0
, t0
);
5977 gen_store_fpr32h(fp0
, fs
);
5984 generate_exception (ctx
, EXCP_RI
);
5987 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5993 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5995 int l1
= gen_new_label();
5998 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
5999 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
6000 TCGv r_tmp
= tcg_temp_local_new(TCG_TYPE_I32
);
6003 ccbit
= 1 << (24 + cc
);
6011 gen_load_gpr(t0
, rd
);
6012 gen_load_gpr(t1
, rs
);
6013 tcg_gen_ld_i32(r_tmp
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
6014 tcg_gen_andi_i32(r_tmp
, r_tmp
, ccbit
);
6015 tcg_gen_brcondi_i32(cond
, r_tmp
, 0, l1
);
6016 tcg_temp_free(r_tmp
);
6018 tcg_gen_mov_tl(t0
, t1
);
6022 gen_store_gpr(t0
, rd
);
6026 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
6030 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_I32
);
6031 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I32
);
6032 TCGv fp1
= tcg_temp_local_new(TCG_TYPE_I32
);
6033 int l1
= gen_new_label();
6036 ccbit
= 1 << (24 + cc
);
6045 gen_load_fpr32(fp0
, fs
);
6046 gen_load_fpr32(fp1
, fd
);
6047 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
6048 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, ccbit
);
6049 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
6050 tcg_gen_movi_i32(fp1
, fp0
);
6053 tcg_temp_free(r_tmp1
);
6054 gen_store_fpr32(fp1
, fd
);
6058 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
6062 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_I32
);
6063 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I64
);
6064 TCGv fp1
= tcg_temp_local_new(TCG_TYPE_I64
);
6065 int l1
= gen_new_label();
6068 ccbit
= 1 << (24 + cc
);
6077 gen_load_fpr64(ctx
, fp0
, fs
);
6078 gen_load_fpr64(ctx
, fp1
, fd
);
6079 tcg_gen_ld_i32(r_tmp1
, current_fpu
, offsetof(CPUMIPSFPUContext
, fcr31
));
6080 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, ccbit
);
6081 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
6082 tcg_gen_movi_i64(fp1
, fp0
);
6085 tcg_temp_free(r_tmp1
);
6086 gen_store_fpr64(ctx
, fp1
, fd
);
6090 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
6093 TCGv r_tmp1
= tcg_temp_local_new(TCG_TYPE_I32
);
6094 TCGv r_tmp2
= tcg_temp_local_new(TCG_TYPE_I32
);
6095 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I32
);
6096 TCGv fph0
= tcg_temp_local_new(TCG_TYPE_I32
);
6097 TCGv fp1
= tcg_temp_local_new(TCG_TYPE_I32
);
6098 TCGv fph1
= tcg_temp_local_new(TCG_TYPE_I32
);
6099 int l1
= gen_new_label();
6100 int l2
= gen_new_label();
6107 gen_load_fpr32(fp0
, fs
);
6108 gen_load_fpr32h(fph0
, fs
);
6109 gen_load_fpr32(fp1
, fd
);
6110 gen_load_fpr32h(fph1
, fd
);
6111 get_fp_cond(r_tmp1
);
6112 tcg_gen_shri_i32(r_tmp1
, r_tmp1
, cc
);
6113 tcg_gen_andi_i32(r_tmp2
, r_tmp1
, 0x1);
6114 tcg_gen_brcondi_i32(cond
, r_tmp2
, 0, l1
);
6115 tcg_gen_movi_i32(fp1
, fp0
);
6118 tcg_gen_andi_i32(r_tmp2
, r_tmp1
, 0x2);
6119 tcg_gen_brcondi_i32(cond
, r_tmp2
, 0, l2
);
6120 tcg_gen_movi_i32(fph1
, fph0
);
6121 tcg_temp_free(fph0
);
6123 tcg_temp_free(r_tmp1
);
6124 tcg_temp_free(r_tmp2
);
6125 gen_store_fpr32(fp1
, fd
);
6126 gen_store_fpr32h(fph1
, fd
);
6128 tcg_temp_free(fph1
);
6132 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
6133 int ft
, int fs
, int fd
, int cc
)
6135 const char *opn
= "farith";
6136 const char *condnames
[] = {
6154 const char *condnames_abs
[] = {
6172 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6173 uint32_t func
= ctx
->opcode
& 0x3f;
6175 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
6178 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6179 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
6181 gen_load_fpr32(fp0
, fs
);
6182 gen_load_fpr32(fp1
, ft
);
6183 tcg_gen_helper_1_2(do_float_add_s
, fp0
, fp0
, fp1
);
6185 gen_store_fpr32(fp0
, fd
);
6193 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6194 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
6196 gen_load_fpr32(fp0
, fs
);
6197 gen_load_fpr32(fp1
, ft
);
6198 tcg_gen_helper_1_2(do_float_sub_s
, fp0
, fp0
, fp1
);
6200 gen_store_fpr32(fp0
, fd
);
6208 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6209 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
6211 gen_load_fpr32(fp0
, fs
);
6212 gen_load_fpr32(fp1
, ft
);
6213 tcg_gen_helper_1_2(do_float_mul_s
, fp0
, fp0
, fp1
);
6215 gen_store_fpr32(fp0
, fd
);
6223 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6224 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
6226 gen_load_fpr32(fp0
, fs
);
6227 gen_load_fpr32(fp1
, ft
);
6228 tcg_gen_helper_1_2(do_float_div_s
, fp0
, fp0
, fp1
);
6230 gen_store_fpr32(fp0
, fd
);
6238 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6240 gen_load_fpr32(fp0
, fs
);
6241 tcg_gen_helper_1_1(do_float_sqrt_s
, fp0
, fp0
);
6242 gen_store_fpr32(fp0
, fd
);
6249 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6251 gen_load_fpr32(fp0
, fs
);
6252 tcg_gen_helper_1_1(do_float_abs_s
, fp0
, fp0
);
6253 gen_store_fpr32(fp0
, fd
);
6260 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6262 gen_load_fpr32(fp0
, fs
);
6263 gen_store_fpr32(fp0
, fd
);
6270 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6272 gen_load_fpr32(fp0
, fs
);
6273 tcg_gen_helper_1_1(do_float_chs_s
, fp0
, fp0
);
6274 gen_store_fpr32(fp0
, fd
);
6280 check_cp1_64bitmode(ctx
);
6282 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6283 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6285 gen_load_fpr32(fp32
, fs
);
6286 tcg_gen_helper_1_1(do_float_roundl_s
, fp64
, fp32
);
6287 tcg_temp_free(fp32
);
6288 gen_store_fpr64(ctx
, fp64
, fd
);
6289 tcg_temp_free(fp64
);
6294 check_cp1_64bitmode(ctx
);
6296 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6297 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6299 gen_load_fpr32(fp32
, fs
);
6300 tcg_gen_helper_1_1(do_float_truncl_s
, fp64
, fp32
);
6301 tcg_temp_free(fp32
);
6302 gen_store_fpr64(ctx
, fp64
, fd
);
6303 tcg_temp_free(fp64
);
6308 check_cp1_64bitmode(ctx
);
6310 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6311 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6313 gen_load_fpr32(fp32
, fs
);
6314 tcg_gen_helper_1_1(do_float_ceill_s
, fp64
, fp32
);
6315 tcg_temp_free(fp32
);
6316 gen_store_fpr64(ctx
, fp64
, fd
);
6317 tcg_temp_free(fp64
);
6322 check_cp1_64bitmode(ctx
);
6324 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6325 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6327 gen_load_fpr32(fp32
, fs
);
6328 tcg_gen_helper_1_1(do_float_floorl_s
, fp64
, fp32
);
6329 tcg_temp_free(fp32
);
6330 gen_store_fpr64(ctx
, fp64
, fd
);
6331 tcg_temp_free(fp64
);
6337 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6339 gen_load_fpr32(fp0
, fs
);
6340 tcg_gen_helper_1_1(do_float_roundw_s
, fp0
, fp0
);
6341 gen_store_fpr32(fp0
, fd
);
6348 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6350 gen_load_fpr32(fp0
, fs
);
6351 tcg_gen_helper_1_1(do_float_truncw_s
, fp0
, fp0
);
6352 gen_store_fpr32(fp0
, fd
);
6359 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6361 gen_load_fpr32(fp0
, fs
);
6362 tcg_gen_helper_1_1(do_float_ceilw_s
, fp0
, fp0
);
6363 gen_store_fpr32(fp0
, fd
);
6370 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6372 gen_load_fpr32(fp0
, fs
);
6373 tcg_gen_helper_1_1(do_float_floorw_s
, fp0
, fp0
);
6374 gen_store_fpr32(fp0
, fd
);
6380 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6385 int l1
= gen_new_label();
6386 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6387 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I32
);
6389 gen_load_gpr(t0
, ft
);
6390 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6392 gen_load_fpr32(fp0
, fs
);
6393 gen_store_fpr32(fp0
, fd
);
6401 int l1
= gen_new_label();
6402 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6403 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I32
);
6405 gen_load_gpr(t0
, ft
);
6406 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6408 gen_load_fpr32(fp0
, fs
);
6409 gen_store_fpr32(fp0
, fd
);
6418 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6420 gen_load_fpr32(fp0
, fs
);
6421 tcg_gen_helper_1_1(do_float_recip_s
, fp0
, fp0
);
6422 gen_store_fpr32(fp0
, fd
);
6430 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6432 gen_load_fpr32(fp0
, fs
);
6433 tcg_gen_helper_1_1(do_float_rsqrt_s
, fp0
, fp0
);
6434 gen_store_fpr32(fp0
, fd
);
6440 check_cp1_64bitmode(ctx
);
6442 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6443 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
6445 gen_load_fpr32(fp0
, fs
);
6446 gen_load_fpr32(fp1
, fd
);
6447 tcg_gen_helper_1_2(do_float_recip2_s
, fp0
, fp0
, fp1
);
6449 gen_store_fpr32(fp0
, fd
);
6455 check_cp1_64bitmode(ctx
);
6457 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6459 gen_load_fpr32(fp0
, fs
);
6460 tcg_gen_helper_1_1(do_float_recip1_s
, fp0
, fp0
);
6461 gen_store_fpr32(fp0
, fd
);
6467 check_cp1_64bitmode(ctx
);
6469 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6471 gen_load_fpr32(fp0
, fs
);
6472 tcg_gen_helper_1_1(do_float_rsqrt1_s
, fp0
, fp0
);
6473 gen_store_fpr32(fp0
, fd
);
6479 check_cp1_64bitmode(ctx
);
6481 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6482 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
6484 gen_load_fpr32(fp0
, fs
);
6485 gen_load_fpr32(fp1
, ft
);
6486 tcg_gen_helper_1_2(do_float_rsqrt2_s
, fp0
, fp0
, fp1
);
6488 gen_store_fpr32(fp0
, fd
);
6494 check_cp1_registers(ctx
, fd
);
6496 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6497 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6499 gen_load_fpr32(fp32
, fs
);
6500 tcg_gen_helper_1_1(do_float_cvtd_s
, fp64
, fp32
);
6501 tcg_temp_free(fp32
);
6502 gen_store_fpr64(ctx
, fp64
, fd
);
6503 tcg_temp_free(fp64
);
6509 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6511 gen_load_fpr32(fp0
, fs
);
6512 tcg_gen_helper_1_1(do_float_cvtw_s
, fp0
, fp0
);
6513 gen_store_fpr32(fp0
, fd
);
6519 check_cp1_64bitmode(ctx
);
6521 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6522 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6524 gen_load_fpr32(fp32
, fs
);
6525 tcg_gen_helper_1_1(do_float_cvtl_s
, fp64
, fp32
);
6526 tcg_temp_free(fp32
);
6527 gen_store_fpr64(ctx
, fp64
, fd
);
6528 tcg_temp_free(fp64
);
6533 check_cp1_64bitmode(ctx
);
6535 TCGv fp64_0
= tcg_temp_new(TCG_TYPE_I64
);
6536 TCGv fp64_1
= tcg_temp_new(TCG_TYPE_I64
);
6537 TCGv fp32_0
= tcg_temp_new(TCG_TYPE_I32
);
6538 TCGv fp32_1
= tcg_temp_new(TCG_TYPE_I32
);
6540 gen_load_fpr32(fp32_0
, fs
);
6541 gen_load_fpr32(fp32_1
, ft
);
6542 tcg_gen_extu_i32_i64(fp64_0
, fp32_0
);
6543 tcg_gen_extu_i32_i64(fp64_1
, fp32_1
);
6544 tcg_temp_free(fp32_0
);
6545 tcg_temp_free(fp32_1
);
6546 tcg_gen_shli_i64(fp64_1
, fp64_1
, 32);
6547 tcg_gen_or_i64(fp64_0
, fp64_0
, fp64_1
);
6548 tcg_temp_free(fp64_1
);
6549 gen_store_fpr64(ctx
, fp64_0
, fd
);
6550 tcg_temp_free(fp64_0
);
6571 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6572 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
6574 gen_load_fpr32(fp0
, fs
);
6575 gen_load_fpr32(fp1
, ft
);
6576 if (ctx
->opcode
& (1 << 6)) {
6578 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6579 opn
= condnames_abs
[func
-48];
6581 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6582 opn
= condnames
[func
-48];
6589 check_cp1_registers(ctx
, fs
| ft
| fd
);
6591 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6592 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
6594 gen_load_fpr64(ctx
, fp0
, fs
);
6595 gen_load_fpr64(ctx
, fp1
, ft
);
6596 tcg_gen_helper_1_2(do_float_add_d
, fp0
, fp0
, fp1
);
6598 gen_store_fpr64(ctx
, fp0
, fd
);
6605 check_cp1_registers(ctx
, fs
| ft
| fd
);
6607 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6608 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
6610 gen_load_fpr64(ctx
, fp0
, fs
);
6611 gen_load_fpr64(ctx
, fp1
, ft
);
6612 tcg_gen_helper_1_2(do_float_sub_d
, fp0
, fp0
, fp1
);
6614 gen_store_fpr64(ctx
, fp0
, fd
);
6621 check_cp1_registers(ctx
, fs
| ft
| fd
);
6623 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6624 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
6626 gen_load_fpr64(ctx
, fp0
, fs
);
6627 gen_load_fpr64(ctx
, fp1
, ft
);
6628 tcg_gen_helper_1_2(do_float_mul_d
, fp0
, fp0
, fp1
);
6630 gen_store_fpr64(ctx
, fp0
, fd
);
6637 check_cp1_registers(ctx
, fs
| ft
| fd
);
6639 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6640 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
6642 gen_load_fpr64(ctx
, fp0
, fs
);
6643 gen_load_fpr64(ctx
, fp1
, ft
);
6644 tcg_gen_helper_1_2(do_float_div_d
, fp0
, fp0
, fp1
);
6646 gen_store_fpr64(ctx
, fp0
, fd
);
6653 check_cp1_registers(ctx
, fs
| fd
);
6655 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6657 gen_load_fpr64(ctx
, fp0
, fs
);
6658 tcg_gen_helper_1_1(do_float_sqrt_d
, fp0
, fp0
);
6659 gen_store_fpr64(ctx
, fp0
, fd
);
6665 check_cp1_registers(ctx
, fs
| fd
);
6667 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6669 gen_load_fpr64(ctx
, fp0
, fs
);
6670 tcg_gen_helper_1_1(do_float_abs_d
, fp0
, fp0
);
6671 gen_store_fpr64(ctx
, fp0
, fd
);
6677 check_cp1_registers(ctx
, fs
| fd
);
6679 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6681 gen_load_fpr64(ctx
, fp0
, fs
);
6682 gen_store_fpr64(ctx
, fp0
, fd
);
6688 check_cp1_registers(ctx
, fs
| fd
);
6690 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6692 gen_load_fpr64(ctx
, fp0
, fs
);
6693 tcg_gen_helper_1_1(do_float_chs_d
, fp0
, fp0
);
6694 gen_store_fpr64(ctx
, fp0
, fd
);
6700 check_cp1_64bitmode(ctx
);
6702 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6704 gen_load_fpr64(ctx
, fp0
, fs
);
6705 tcg_gen_helper_1_1(do_float_roundl_d
, fp0
, fp0
);
6706 gen_store_fpr64(ctx
, fp0
, fd
);
6712 check_cp1_64bitmode(ctx
);
6714 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6716 gen_load_fpr64(ctx
, fp0
, fs
);
6717 tcg_gen_helper_1_1(do_float_truncl_d
, fp0
, fp0
);
6718 gen_store_fpr64(ctx
, fp0
, fd
);
6724 check_cp1_64bitmode(ctx
);
6726 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6728 gen_load_fpr64(ctx
, fp0
, fs
);
6729 tcg_gen_helper_1_1(do_float_ceill_d
, fp0
, fp0
);
6730 gen_store_fpr64(ctx
, fp0
, fd
);
6736 check_cp1_64bitmode(ctx
);
6738 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6740 gen_load_fpr64(ctx
, fp0
, fs
);
6741 tcg_gen_helper_1_1(do_float_floorl_d
, fp0
, fp0
);
6742 gen_store_fpr64(ctx
, fp0
, fd
);
6748 check_cp1_registers(ctx
, fs
);
6750 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6751 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6753 gen_load_fpr64(ctx
, fp64
, fs
);
6754 tcg_gen_helper_1_1(do_float_roundw_d
, fp32
, fp64
);
6755 tcg_temp_free(fp64
);
6756 gen_store_fpr32(fp32
, fd
);
6757 tcg_temp_free(fp32
);
6762 check_cp1_registers(ctx
, fs
);
6764 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6765 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6767 gen_load_fpr64(ctx
, fp64
, fs
);
6768 tcg_gen_helper_1_1(do_float_truncw_d
, fp32
, fp64
);
6769 tcg_temp_free(fp64
);
6770 gen_store_fpr32(fp32
, fd
);
6771 tcg_temp_free(fp32
);
6776 check_cp1_registers(ctx
, fs
);
6778 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6779 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6781 gen_load_fpr64(ctx
, fp64
, fs
);
6782 tcg_gen_helper_1_1(do_float_ceilw_d
, fp32
, fp64
);
6783 tcg_temp_free(fp64
);
6784 gen_store_fpr32(fp32
, fd
);
6785 tcg_temp_free(fp32
);
6790 check_cp1_registers(ctx
, fs
);
6792 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6793 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6795 gen_load_fpr64(ctx
, fp64
, fs
);
6796 tcg_gen_helper_1_1(do_float_floorw_d
, fp32
, fp64
);
6797 tcg_temp_free(fp64
);
6798 gen_store_fpr32(fp32
, fd
);
6799 tcg_temp_free(fp32
);
6804 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6809 int l1
= gen_new_label();
6810 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6811 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I64
);
6813 gen_load_gpr(t0
, ft
);
6814 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6816 gen_load_fpr64(ctx
, fp0
, fs
);
6817 gen_store_fpr64(ctx
, fp0
, fd
);
6825 int l1
= gen_new_label();
6826 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
6827 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I64
);
6829 gen_load_gpr(t0
, ft
);
6830 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6832 gen_load_fpr64(ctx
, fp0
, fs
);
6833 gen_store_fpr64(ctx
, fp0
, fd
);
6840 check_cp1_64bitmode(ctx
);
6842 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6844 gen_load_fpr64(ctx
, fp0
, fs
);
6845 tcg_gen_helper_1_1(do_float_recip_d
, fp0
, fp0
);
6846 gen_store_fpr64(ctx
, fp0
, fd
);
6852 check_cp1_64bitmode(ctx
);
6854 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6856 gen_load_fpr64(ctx
, fp0
, fs
);
6857 tcg_gen_helper_1_1(do_float_rsqrt_d
, fp0
, fp0
);
6858 gen_store_fpr64(ctx
, fp0
, fd
);
6864 check_cp1_64bitmode(ctx
);
6866 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6867 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
6869 gen_load_fpr64(ctx
, fp0
, fs
);
6870 gen_load_fpr64(ctx
, fp1
, ft
);
6871 tcg_gen_helper_1_2(do_float_recip2_d
, fp0
, fp0
, fp1
);
6873 gen_store_fpr64(ctx
, fp0
, fd
);
6879 check_cp1_64bitmode(ctx
);
6881 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6883 gen_load_fpr64(ctx
, fp0
, fs
);
6884 tcg_gen_helper_1_1(do_float_recip1_d
, fp0
, fp0
);
6885 gen_store_fpr64(ctx
, fp0
, fd
);
6891 check_cp1_64bitmode(ctx
);
6893 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6895 gen_load_fpr64(ctx
, fp0
, fs
);
6896 tcg_gen_helper_1_1(do_float_rsqrt1_d
, fp0
, fp0
);
6897 gen_store_fpr64(ctx
, fp0
, fd
);
6903 check_cp1_64bitmode(ctx
);
6905 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6906 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
6908 gen_load_fpr64(ctx
, fp0
, fs
);
6909 gen_load_fpr64(ctx
, fp1
, ft
);
6910 tcg_gen_helper_1_2(do_float_rsqrt2_d
, fp0
, fp0
, fp1
);
6912 gen_store_fpr64(ctx
, fp0
, fd
);
6934 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6935 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
6937 gen_load_fpr64(ctx
, fp0
, fs
);
6938 gen_load_fpr64(ctx
, fp1
, ft
);
6939 if (ctx
->opcode
& (1 << 6)) {
6941 check_cp1_registers(ctx
, fs
| ft
);
6942 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6943 opn
= condnames_abs
[func
-48];
6945 check_cp1_registers(ctx
, fs
| ft
);
6946 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6947 opn
= condnames
[func
-48];
6954 check_cp1_registers(ctx
, fs
);
6956 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6957 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6959 gen_load_fpr64(ctx
, fp64
, fs
);
6960 tcg_gen_helper_1_1(do_float_cvts_d
, fp32
, fp64
);
6961 tcg_temp_free(fp64
);
6962 gen_store_fpr32(fp32
, fd
);
6963 tcg_temp_free(fp32
);
6968 check_cp1_registers(ctx
, fs
);
6970 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
6971 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
6973 gen_load_fpr64(ctx
, fp64
, fs
);
6974 tcg_gen_helper_1_1(do_float_cvtw_d
, fp32
, fp64
);
6975 tcg_temp_free(fp64
);
6976 gen_store_fpr32(fp32
, fd
);
6977 tcg_temp_free(fp32
);
6982 check_cp1_64bitmode(ctx
);
6984 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
6986 gen_load_fpr64(ctx
, fp0
, fs
);
6987 tcg_gen_helper_1_1(do_float_cvtl_d
, fp0
, fp0
);
6988 gen_store_fpr64(ctx
, fp0
, fd
);
6995 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
6997 gen_load_fpr32(fp0
, fs
);
6998 tcg_gen_helper_1_1(do_float_cvts_w
, fp0
, fp0
);
6999 gen_store_fpr32(fp0
, fd
);
7005 check_cp1_registers(ctx
, fd
);
7007 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
7008 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
7010 gen_load_fpr32(fp32
, fs
);
7011 tcg_gen_helper_1_1(do_float_cvtd_w
, fp64
, fp32
);
7012 tcg_temp_free(fp32
);
7013 gen_store_fpr64(ctx
, fp64
, fd
);
7014 tcg_temp_free(fp64
);
7019 check_cp1_64bitmode(ctx
);
7021 TCGv fp32
= tcg_temp_new(TCG_TYPE_I32
);
7022 TCGv fp64
= tcg_temp_new(TCG_TYPE_I64
);
7024 gen_load_fpr64(ctx
, fp64
, fs
);
7025 tcg_gen_helper_1_1(do_float_cvts_l
, fp32
, fp64
);
7026 tcg_temp_free(fp64
);
7027 gen_store_fpr32(fp32
, fd
);
7028 tcg_temp_free(fp32
);
7033 check_cp1_64bitmode(ctx
);
7035 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7037 gen_load_fpr64(ctx
, fp0
, fs
);
7038 tcg_gen_helper_1_1(do_float_cvtd_l
, fp0
, fp0
);
7039 gen_store_fpr64(ctx
, fp0
, fd
);
7045 check_cp1_64bitmode(ctx
);
7047 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7049 gen_load_fpr64(ctx
, fp0
, fs
);
7050 tcg_gen_helper_1_1(do_float_cvtps_pw
, fp0
, fp0
);
7051 gen_store_fpr64(ctx
, fp0
, fd
);
7057 check_cp1_64bitmode(ctx
);
7059 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7060 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7062 gen_load_fpr64(ctx
, fp0
, fs
);
7063 gen_load_fpr64(ctx
, fp1
, ft
);
7064 tcg_gen_helper_1_2(do_float_add_ps
, fp0
, fp0
, fp1
);
7066 gen_store_fpr64(ctx
, fp0
, fd
);
7072 check_cp1_64bitmode(ctx
);
7074 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7075 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7077 gen_load_fpr64(ctx
, fp0
, fs
);
7078 gen_load_fpr64(ctx
, fp1
, ft
);
7079 tcg_gen_helper_1_2(do_float_sub_ps
, fp0
, fp0
, fp1
);
7081 gen_store_fpr64(ctx
, fp0
, fd
);
7087 check_cp1_64bitmode(ctx
);
7089 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7090 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7092 gen_load_fpr64(ctx
, fp0
, fs
);
7093 gen_load_fpr64(ctx
, fp1
, ft
);
7094 tcg_gen_helper_1_2(do_float_mul_ps
, fp0
, fp0
, fp1
);
7096 gen_store_fpr64(ctx
, fp0
, fd
);
7102 check_cp1_64bitmode(ctx
);
7104 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7106 gen_load_fpr64(ctx
, fp0
, fs
);
7107 tcg_gen_helper_1_1(do_float_abs_ps
, fp0
, fp0
);
7108 gen_store_fpr64(ctx
, fp0
, fd
);
7114 check_cp1_64bitmode(ctx
);
7116 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7118 gen_load_fpr64(ctx
, fp0
, fs
);
7119 gen_store_fpr64(ctx
, fp0
, fd
);
7125 check_cp1_64bitmode(ctx
);
7127 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7129 gen_load_fpr64(ctx
, fp0
, fs
);
7130 tcg_gen_helper_1_1(do_float_chs_ps
, fp0
, fp0
);
7131 gen_store_fpr64(ctx
, fp0
, fd
);
7137 check_cp1_64bitmode(ctx
);
7138 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
7142 check_cp1_64bitmode(ctx
);
7144 int l1
= gen_new_label();
7145 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7146 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I32
);
7147 TCGv fph0
= tcg_temp_local_new(TCG_TYPE_I32
);
7149 gen_load_gpr(t0
, ft
);
7150 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7152 gen_load_fpr32(fp0
, fs
);
7153 gen_load_fpr32h(fph0
, fs
);
7154 gen_store_fpr32(fp0
, fd
);
7155 gen_store_fpr32h(fph0
, fd
);
7157 tcg_temp_free(fph0
);
7163 check_cp1_64bitmode(ctx
);
7165 int l1
= gen_new_label();
7166 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7167 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I32
);
7168 TCGv fph0
= tcg_temp_local_new(TCG_TYPE_I32
);
7170 gen_load_gpr(t0
, ft
);
7171 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
7173 gen_load_fpr32(fp0
, fs
);
7174 gen_load_fpr32h(fph0
, fs
);
7175 gen_store_fpr32(fp0
, fd
);
7176 gen_store_fpr32h(fph0
, fd
);
7178 tcg_temp_free(fph0
);
7184 check_cp1_64bitmode(ctx
);
7186 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7187 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7189 gen_load_fpr64(ctx
, fp0
, ft
);
7190 gen_load_fpr64(ctx
, fp1
, fs
);
7191 tcg_gen_helper_1_2(do_float_addr_ps
, fp0
, fp0
, fp1
);
7193 gen_store_fpr64(ctx
, fp0
, fd
);
7199 check_cp1_64bitmode(ctx
);
7201 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7202 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7204 gen_load_fpr64(ctx
, fp0
, ft
);
7205 gen_load_fpr64(ctx
, fp1
, fs
);
7206 tcg_gen_helper_1_2(do_float_mulr_ps
, fp0
, fp0
, fp1
);
7208 gen_store_fpr64(ctx
, fp0
, fd
);
7214 check_cp1_64bitmode(ctx
);
7216 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7217 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7219 gen_load_fpr64(ctx
, fp0
, fs
);
7220 gen_load_fpr64(ctx
, fp1
, fd
);
7221 tcg_gen_helper_1_2(do_float_recip2_ps
, fp0
, fp0
, fp1
);
7223 gen_store_fpr64(ctx
, fp0
, fd
);
7229 check_cp1_64bitmode(ctx
);
7231 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7233 gen_load_fpr64(ctx
, fp0
, fs
);
7234 tcg_gen_helper_1_1(do_float_recip1_ps
, fp0
, fp0
);
7235 gen_store_fpr64(ctx
, fp0
, fd
);
7241 check_cp1_64bitmode(ctx
);
7243 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7245 gen_load_fpr64(ctx
, fp0
, fs
);
7246 tcg_gen_helper_1_1(do_float_rsqrt1_ps
, fp0
, fp0
);
7247 gen_store_fpr64(ctx
, fp0
, fd
);
7253 check_cp1_64bitmode(ctx
);
7255 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7256 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7258 gen_load_fpr64(ctx
, fp0
, fs
);
7259 gen_load_fpr64(ctx
, fp1
, ft
);
7260 tcg_gen_helper_1_2(do_float_rsqrt2_ps
, fp0
, fp0
, fp1
);
7262 gen_store_fpr64(ctx
, fp0
, fd
);
7268 check_cp1_64bitmode(ctx
);
7270 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7272 gen_load_fpr32h(fp0
, fs
);
7273 tcg_gen_helper_1_1(do_float_cvts_pu
, fp0
, fp0
);
7274 gen_store_fpr32(fp0
, fd
);
7280 check_cp1_64bitmode(ctx
);
7282 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7284 gen_load_fpr64(ctx
, fp0
, fs
);
7285 tcg_gen_helper_1_1(do_float_cvtpw_ps
, fp0
, fp0
);
7286 gen_store_fpr64(ctx
, fp0
, fd
);
7292 check_cp1_64bitmode(ctx
);
7294 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7296 gen_load_fpr32(fp0
, fs
);
7297 tcg_gen_helper_1_1(do_float_cvts_pl
, fp0
, fp0
);
7298 gen_store_fpr32(fp0
, fd
);
7304 check_cp1_64bitmode(ctx
);
7306 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7307 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7309 gen_load_fpr32(fp0
, fs
);
7310 gen_load_fpr32(fp1
, ft
);
7311 gen_store_fpr32h(fp0
, fd
);
7312 gen_store_fpr32(fp1
, fd
);
7319 check_cp1_64bitmode(ctx
);
7321 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7322 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7324 gen_load_fpr32(fp0
, fs
);
7325 gen_load_fpr32h(fp1
, ft
);
7326 gen_store_fpr32(fp1
, fd
);
7327 gen_store_fpr32h(fp0
, fd
);
7334 check_cp1_64bitmode(ctx
);
7336 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7337 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7339 gen_load_fpr32h(fp0
, fs
);
7340 gen_load_fpr32(fp1
, ft
);
7341 gen_store_fpr32(fp1
, fd
);
7342 gen_store_fpr32h(fp0
, fd
);
7349 check_cp1_64bitmode(ctx
);
7351 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7352 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7354 gen_load_fpr32h(fp0
, fs
);
7355 gen_load_fpr32h(fp1
, ft
);
7356 gen_store_fpr32(fp1
, fd
);
7357 gen_store_fpr32h(fp0
, fd
);
7379 check_cp1_64bitmode(ctx
);
7381 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7382 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7384 gen_load_fpr64(ctx
, fp0
, fs
);
7385 gen_load_fpr64(ctx
, fp1
, ft
);
7386 if (ctx
->opcode
& (1 << 6)) {
7387 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7388 opn
= condnames_abs
[func
-48];
7390 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7391 opn
= condnames
[func
-48];
7399 generate_exception (ctx
, EXCP_RI
);
7404 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7407 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7410 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7415 /* Coprocessor 3 (FPU) */
7416 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7417 int fd
, int fs
, int base
, int index
)
7419 const char *opn
= "extended float load/store";
7421 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7422 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
7425 gen_load_gpr(t0
, index
);
7426 } else if (index
== 0) {
7427 gen_load_gpr(t0
, base
);
7429 gen_load_gpr(t0
, base
);
7430 gen_load_gpr(t1
, index
);
7431 gen_op_addr_add(t0
, t1
);
7433 /* Don't do NOP if destination is zero: we must perform the actual
7439 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7441 tcg_gen_qemu_ld32s(fp0
, t0
, ctx
->mem_idx
);
7442 gen_store_fpr32(fp0
, fd
);
7449 check_cp1_registers(ctx
, fd
);
7451 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7453 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7454 gen_store_fpr64(ctx
, fp0
, fd
);
7460 check_cp1_64bitmode(ctx
);
7461 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7463 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7465 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7466 gen_store_fpr64(ctx
, fp0
, fd
);
7474 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7476 gen_load_fpr32(fp0
, fs
);
7477 tcg_gen_qemu_st32(fp0
, t0
, ctx
->mem_idx
);
7485 check_cp1_registers(ctx
, fs
);
7487 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7489 gen_load_fpr64(ctx
, fp0
, fs
);
7490 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7497 check_cp1_64bitmode(ctx
);
7498 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7500 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7502 gen_load_fpr64(ctx
, fp0
, fs
);
7503 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7511 generate_exception(ctx
, EXCP_RI
);
7518 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7519 regnames
[index
], regnames
[base
]);
7522 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7523 int fd
, int fr
, int fs
, int ft
)
7525 const char *opn
= "flt3_arith";
7529 check_cp1_64bitmode(ctx
);
7531 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
7532 TCGv fp0
= tcg_temp_local_new(TCG_TYPE_I32
);
7533 TCGv fph0
= tcg_temp_local_new(TCG_TYPE_I32
);
7534 TCGv fp1
= tcg_temp_local_new(TCG_TYPE_I32
);
7535 TCGv fph1
= tcg_temp_local_new(TCG_TYPE_I32
);
7536 int l1
= gen_new_label();
7537 int l2
= gen_new_label();
7539 gen_load_gpr(t0
, fr
);
7540 tcg_gen_andi_tl(t0
, t0
, 0x7);
7541 gen_load_fpr32(fp0
, fs
);
7542 gen_load_fpr32h(fph0
, fs
);
7543 gen_load_fpr32(fp1
, ft
);
7544 gen_load_fpr32h(fph1
, ft
);
7546 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7547 gen_store_fpr32(fp0
, fd
);
7548 gen_store_fpr32h(fph0
, fd
);
7551 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7553 #ifdef TARGET_WORDS_BIGENDIAN
7554 gen_store_fpr32(fph1
, fd
);
7555 gen_store_fpr32h(fp0
, fd
);
7557 gen_store_fpr32(fph0
, fd
);
7558 gen_store_fpr32h(fp1
, fd
);
7562 tcg_temp_free(fph0
);
7564 tcg_temp_free(fph1
);
7571 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7572 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7573 TCGv fp2
= tcg_temp_new(TCG_TYPE_I32
);
7575 gen_load_fpr32(fp0
, fs
);
7576 gen_load_fpr32(fp1
, ft
);
7577 gen_load_fpr32(fp2
, fr
);
7578 tcg_gen_helper_1_3(do_float_muladd_s
, fp2
, fp0
, fp1
, fp2
);
7581 gen_store_fpr32(fp2
, fd
);
7588 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7590 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7591 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7592 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7594 gen_load_fpr64(ctx
, fp0
, fs
);
7595 gen_load_fpr64(ctx
, fp1
, ft
);
7596 gen_load_fpr64(ctx
, fp2
, fr
);
7597 tcg_gen_helper_1_3(do_float_muladd_d
, fp2
, fp0
, fp1
, fp2
);
7600 gen_store_fpr64(ctx
, fp2
, fd
);
7606 check_cp1_64bitmode(ctx
);
7608 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7609 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7610 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7612 gen_load_fpr64(ctx
, fp0
, fs
);
7613 gen_load_fpr64(ctx
, fp1
, ft
);
7614 gen_load_fpr64(ctx
, fp2
, fr
);
7615 tcg_gen_helper_1_3(do_float_muladd_ps
, fp2
, fp0
, fp1
, fp2
);
7618 gen_store_fpr64(ctx
, fp2
, fd
);
7626 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7627 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7628 TCGv fp2
= tcg_temp_new(TCG_TYPE_I32
);
7630 gen_load_fpr32(fp0
, fs
);
7631 gen_load_fpr32(fp1
, ft
);
7632 gen_load_fpr32(fp2
, fr
);
7633 tcg_gen_helper_1_3(do_float_mulsub_s
, fp2
, fp0
, fp1
, fp2
);
7636 gen_store_fpr32(fp2
, fd
);
7643 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7645 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7646 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7647 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7649 gen_load_fpr64(ctx
, fp0
, fs
);
7650 gen_load_fpr64(ctx
, fp1
, ft
);
7651 gen_load_fpr64(ctx
, fp2
, fr
);
7652 tcg_gen_helper_1_3(do_float_mulsub_d
, fp2
, fp0
, fp1
, fp2
);
7655 gen_store_fpr64(ctx
, fp2
, fd
);
7661 check_cp1_64bitmode(ctx
);
7663 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7664 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7665 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7667 gen_load_fpr64(ctx
, fp0
, fs
);
7668 gen_load_fpr64(ctx
, fp1
, ft
);
7669 gen_load_fpr64(ctx
, fp2
, fr
);
7670 tcg_gen_helper_1_3(do_float_mulsub_ps
, fp2
, fp0
, fp1
, fp2
);
7673 gen_store_fpr64(ctx
, fp2
, fd
);
7681 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7682 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7683 TCGv fp2
= tcg_temp_new(TCG_TYPE_I32
);
7685 gen_load_fpr32(fp0
, fs
);
7686 gen_load_fpr32(fp1
, ft
);
7687 gen_load_fpr32(fp2
, fr
);
7688 tcg_gen_helper_1_3(do_float_nmuladd_s
, fp2
, fp0
, fp1
, fp2
);
7691 gen_store_fpr32(fp2
, fd
);
7698 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7700 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7701 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7702 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7704 gen_load_fpr64(ctx
, fp0
, fs
);
7705 gen_load_fpr64(ctx
, fp1
, ft
);
7706 gen_load_fpr64(ctx
, fp2
, fr
);
7707 tcg_gen_helper_1_3(do_float_nmuladd_d
, fp2
, fp0
, fp1
, fp2
);
7710 gen_store_fpr64(ctx
, fp2
, fd
);
7716 check_cp1_64bitmode(ctx
);
7718 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7719 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7720 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7722 gen_load_fpr64(ctx
, fp0
, fs
);
7723 gen_load_fpr64(ctx
, fp1
, ft
);
7724 gen_load_fpr64(ctx
, fp2
, fr
);
7725 tcg_gen_helper_1_3(do_float_nmuladd_ps
, fp2
, fp0
, fp1
, fp2
);
7728 gen_store_fpr64(ctx
, fp2
, fd
);
7736 TCGv fp0
= tcg_temp_new(TCG_TYPE_I32
);
7737 TCGv fp1
= tcg_temp_new(TCG_TYPE_I32
);
7738 TCGv fp2
= tcg_temp_new(TCG_TYPE_I32
);
7740 gen_load_fpr32(fp0
, fs
);
7741 gen_load_fpr32(fp1
, ft
);
7742 gen_load_fpr32(fp2
, fr
);
7743 tcg_gen_helper_1_3(do_float_nmulsub_s
, fp2
, fp0
, fp1
, fp2
);
7746 gen_store_fpr32(fp2
, fd
);
7753 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7755 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7756 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7757 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7759 gen_load_fpr64(ctx
, fp0
, fs
);
7760 gen_load_fpr64(ctx
, fp1
, ft
);
7761 gen_load_fpr64(ctx
, fp2
, fr
);
7762 tcg_gen_helper_1_3(do_float_nmulsub_d
, fp2
, fp0
, fp1
, fp2
);
7765 gen_store_fpr64(ctx
, fp2
, fd
);
7771 check_cp1_64bitmode(ctx
);
7773 TCGv fp0
= tcg_temp_new(TCG_TYPE_I64
);
7774 TCGv fp1
= tcg_temp_new(TCG_TYPE_I64
);
7775 TCGv fp2
= tcg_temp_new(TCG_TYPE_I64
);
7777 gen_load_fpr64(ctx
, fp0
, fs
);
7778 gen_load_fpr64(ctx
, fp1
, ft
);
7779 gen_load_fpr64(ctx
, fp2
, fr
);
7780 tcg_gen_helper_1_3(do_float_nmulsub_ps
, fp2
, fp0
, fp1
, fp2
);
7783 gen_store_fpr64(ctx
, fp2
, fd
);
7790 generate_exception (ctx
, EXCP_RI
);
7793 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7794 fregnames
[fs
], fregnames
[ft
]);
7797 /* ISA extensions (ASEs) */
7798 /* MIPS16 extension to MIPS32 */
7799 /* SmartMIPS extension to MIPS32 */
7801 #if defined(TARGET_MIPS64)
7803 /* MDMX extension to MIPS64 */
7807 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7811 uint32_t op
, op1
, op2
;
7814 /* make sure instructions are on a word boundary */
7815 if (ctx
->pc
& 0x3) {
7816 env
->CP0_BadVAddr
= ctx
->pc
;
7817 generate_exception(ctx
, EXCP_AdEL
);
7821 /* Handle blikely not taken case */
7822 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7823 int l1
= gen_new_label();
7825 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7826 tcg_gen_brcondi_i32(TCG_COND_NE
, bcond
, 0, l1
);
7828 TCGv r_tmp
= tcg_temp_new(TCG_TYPE_I32
);
7830 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7831 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
7832 tcg_temp_free(r_tmp
);
7834 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7837 op
= MASK_OP_MAJOR(ctx
->opcode
);
7838 rs
= (ctx
->opcode
>> 21) & 0x1f;
7839 rt
= (ctx
->opcode
>> 16) & 0x1f;
7840 rd
= (ctx
->opcode
>> 11) & 0x1f;
7841 sa
= (ctx
->opcode
>> 6) & 0x1f;
7842 imm
= (int16_t)ctx
->opcode
;
7845 op1
= MASK_SPECIAL(ctx
->opcode
);
7847 case OPC_SLL
: /* Arithmetic with immediate */
7848 case OPC_SRL
... OPC_SRA
:
7849 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7851 case OPC_MOVZ
... OPC_MOVN
:
7852 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7853 case OPC_SLLV
: /* Arithmetic */
7854 case OPC_SRLV
... OPC_SRAV
:
7855 case OPC_ADD
... OPC_NOR
:
7856 case OPC_SLT
... OPC_SLTU
:
7857 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7859 case OPC_MULT
... OPC_DIVU
:
7861 check_insn(env
, ctx
, INSN_VR54XX
);
7862 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7863 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7865 gen_muldiv(ctx
, op1
, rs
, rt
);
7867 case OPC_JR
... OPC_JALR
:
7868 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7870 case OPC_TGE
... OPC_TEQ
: /* Traps */
7872 gen_trap(ctx
, op1
, rs
, rt
, -1);
7874 case OPC_MFHI
: /* Move from HI/LO */
7876 gen_HILO(ctx
, op1
, rd
);
7879 case OPC_MTLO
: /* Move to HI/LO */
7880 gen_HILO(ctx
, op1
, rs
);
7882 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7883 #ifdef MIPS_STRICT_STANDARD
7884 MIPS_INVAL("PMON / selsl");
7885 generate_exception(ctx
, EXCP_RI
);
7887 tcg_gen_helper_0_i(do_pmon
, sa
);
7891 generate_exception(ctx
, EXCP_SYSCALL
);
7894 generate_exception(ctx
, EXCP_BREAK
);
7897 #ifdef MIPS_STRICT_STANDARD
7899 generate_exception(ctx
, EXCP_RI
);
7901 /* Implemented as RI exception for now. */
7902 MIPS_INVAL("spim (unofficial)");
7903 generate_exception(ctx
, EXCP_RI
);
7911 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7912 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7913 save_cpu_state(ctx
, 1);
7914 check_cp1_enabled(ctx
);
7915 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7916 (ctx
->opcode
>> 16) & 1);
7918 generate_exception_err(ctx
, EXCP_CpU
, 1);
7922 #if defined(TARGET_MIPS64)
7923 /* MIPS64 specific opcodes */
7925 case OPC_DSRL
... OPC_DSRA
:
7927 case OPC_DSRL32
... OPC_DSRA32
:
7928 check_insn(env
, ctx
, ISA_MIPS3
);
7930 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7933 case OPC_DSRLV
... OPC_DSRAV
:
7934 case OPC_DADD
... OPC_DSUBU
:
7935 check_insn(env
, ctx
, ISA_MIPS3
);
7937 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7939 case OPC_DMULT
... OPC_DDIVU
:
7940 check_insn(env
, ctx
, ISA_MIPS3
);
7942 gen_muldiv(ctx
, op1
, rs
, rt
);
7945 default: /* Invalid */
7946 MIPS_INVAL("special");
7947 generate_exception(ctx
, EXCP_RI
);
7952 op1
= MASK_SPECIAL2(ctx
->opcode
);
7954 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7955 case OPC_MSUB
... OPC_MSUBU
:
7956 check_insn(env
, ctx
, ISA_MIPS32
);
7957 gen_muldiv(ctx
, op1
, rs
, rt
);
7960 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7962 case OPC_CLZ
... OPC_CLO
:
7963 check_insn(env
, ctx
, ISA_MIPS32
);
7964 gen_cl(ctx
, op1
, rd
, rs
);
7967 /* XXX: not clear which exception should be raised
7968 * when in debug mode...
7970 check_insn(env
, ctx
, ISA_MIPS32
);
7971 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7972 generate_exception(ctx
, EXCP_DBp
);
7974 generate_exception(ctx
, EXCP_DBp
);
7978 #if defined(TARGET_MIPS64)
7979 case OPC_DCLZ
... OPC_DCLO
:
7980 check_insn(env
, ctx
, ISA_MIPS64
);
7982 gen_cl(ctx
, op1
, rd
, rs
);
7985 default: /* Invalid */
7986 MIPS_INVAL("special2");
7987 generate_exception(ctx
, EXCP_RI
);
7992 op1
= MASK_SPECIAL3(ctx
->opcode
);
7996 check_insn(env
, ctx
, ISA_MIPS32R2
);
7997 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
8000 check_insn(env
, ctx
, ISA_MIPS32R2
);
8001 op2
= MASK_BSHFL(ctx
->opcode
);
8003 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
8004 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
8008 gen_load_gpr(t1
, rt
);
8009 tcg_gen_helper_1_1(do_wsbh
, t0
, t1
);
8010 gen_store_gpr(t0
, rd
);
8013 gen_load_gpr(t1
, rt
);
8014 tcg_gen_ext8s_tl(t0
, t1
);
8015 gen_store_gpr(t0
, rd
);
8018 gen_load_gpr(t1
, rt
);
8019 tcg_gen_ext16s_tl(t0
, t1
);
8020 gen_store_gpr(t0
, rd
);
8022 default: /* Invalid */
8023 MIPS_INVAL("bshfl");
8024 generate_exception(ctx
, EXCP_RI
);
8032 check_insn(env
, ctx
, ISA_MIPS32R2
);
8034 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
8038 save_cpu_state(ctx
, 1);
8039 tcg_gen_helper_1_0(do_rdhwr_cpunum
, t0
);
8042 save_cpu_state(ctx
, 1);
8043 tcg_gen_helper_1_0(do_rdhwr_synci_step
, t0
);
8046 save_cpu_state(ctx
, 1);
8047 tcg_gen_helper_1_0(do_rdhwr_cc
, t0
);
8050 save_cpu_state(ctx
, 1);
8051 tcg_gen_helper_1_0(do_rdhwr_ccres
, t0
);
8054 if (env
->user_mode_only
) {
8055 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
8058 /* XXX: Some CPUs implement this in hardware.
8059 Not supported yet. */
8061 default: /* Invalid */
8062 MIPS_INVAL("rdhwr");
8063 generate_exception(ctx
, EXCP_RI
);
8066 gen_store_gpr(t0
, rt
);
8071 check_insn(env
, ctx
, ASE_MT
);
8073 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
8074 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
8076 gen_load_gpr(t0
, rt
);
8077 gen_load_gpr(t1
, rs
);
8078 tcg_gen_helper_0_2(do_fork
, t0
, t1
);
8084 check_insn(env
, ctx
, ASE_MT
);
8086 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
8088 gen_load_gpr(t0
, rs
);
8089 tcg_gen_helper_1_1(do_yield
, t0
, t0
);
8090 gen_store_gpr(t0
, rd
);
8094 #if defined(TARGET_MIPS64)
8095 case OPC_DEXTM
... OPC_DEXT
:
8096 case OPC_DINSM
... OPC_DINS
:
8097 check_insn(env
, ctx
, ISA_MIPS64R2
);
8099 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
8102 check_insn(env
, ctx
, ISA_MIPS64R2
);
8104 op2
= MASK_DBSHFL(ctx
->opcode
);
8106 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
8107 TCGv t1
= tcg_temp_local_new(TCG_TYPE_TL
);
8111 gen_load_gpr(t1
, rt
);
8112 tcg_gen_helper_1_1(do_dsbh
, t0
, t1
);
8115 gen_load_gpr(t1
, rt
);
8116 tcg_gen_helper_1_1(do_dshd
, t0
, t1
);
8118 default: /* Invalid */
8119 MIPS_INVAL("dbshfl");
8120 generate_exception(ctx
, EXCP_RI
);
8123 gen_store_gpr(t0
, rd
);
8129 default: /* Invalid */
8130 MIPS_INVAL("special3");
8131 generate_exception(ctx
, EXCP_RI
);
8136 op1
= MASK_REGIMM(ctx
->opcode
);
8138 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
8139 case OPC_BLTZAL
... OPC_BGEZALL
:
8140 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
8142 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
8144 gen_trap(ctx
, op1
, rs
, -1, imm
);
8147 check_insn(env
, ctx
, ISA_MIPS32R2
);
8150 default: /* Invalid */
8151 MIPS_INVAL("regimm");
8152 generate_exception(ctx
, EXCP_RI
);
8157 check_cp0_enabled(ctx
);
8158 op1
= MASK_CP0(ctx
->opcode
);
8164 #if defined(TARGET_MIPS64)
8168 #ifndef CONFIG_USER_ONLY
8169 if (!env
->user_mode_only
)
8170 gen_cp0(env
, ctx
, op1
, rt
, rd
);
8171 #endif /* !CONFIG_USER_ONLY */
8173 case OPC_C0_FIRST
... OPC_C0_LAST
:
8174 #ifndef CONFIG_USER_ONLY
8175 if (!env
->user_mode_only
)
8176 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
8177 #endif /* !CONFIG_USER_ONLY */
8180 #ifndef CONFIG_USER_ONLY
8181 if (!env
->user_mode_only
) {
8182 TCGv t0
= tcg_temp_local_new(TCG_TYPE_TL
);
8184 op2
= MASK_MFMC0(ctx
->opcode
);
8187 check_insn(env
, ctx
, ASE_MT
);
8188 tcg_gen_helper_1_1(do_dmt
, t0
, t0
);
8191 check_insn(env
, ctx
, ASE_MT
);
8192 tcg_gen_helper_1_1(do_emt
, t0
, t0
);
8195 check_insn(env
, ctx
, ASE_MT
);
8196 tcg_gen_helper_1_1(do_dvpe
, t0
, t0
);
8199 check_insn(env
, ctx
, ASE_MT
);
8200 tcg_gen_helper_1_1(do_evpe
, t0
, t0
);
8203 check_insn(env
, ctx
, ISA_MIPS32R2
);
8204 save_cpu_state(ctx
, 1);
8205 tcg_gen_helper_1_0(do_di
, t0
);
8206 /* Stop translation as we may have switched the execution mode */
8207 ctx
->bstate
= BS_STOP
;
8210 check_insn(env
, ctx
, ISA_MIPS32R2
);
8211 save_cpu_state(ctx
, 1);
8212 tcg_gen_helper_1_0(do_ei
, t0
);
8213 /* Stop translation as we may have switched the execution mode */
8214 ctx
->bstate
= BS_STOP
;
8216 default: /* Invalid */
8217 MIPS_INVAL("mfmc0");
8218 generate_exception(ctx
, EXCP_RI
);
8221 gen_store_gpr(t0
, rt
);
8224 #endif /* !CONFIG_USER_ONLY */
8227 check_insn(env
, ctx
, ISA_MIPS32R2
);
8228 gen_load_srsgpr(rt
, rd
);
8231 check_insn(env
, ctx
, ISA_MIPS32R2
);
8232 gen_store_srsgpr(rt
, rd
);
8236 generate_exception(ctx
, EXCP_RI
);
8240 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
8241 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8243 case OPC_J
... OPC_JAL
: /* Jump */
8244 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
8245 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
8247 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
8248 case OPC_BEQL
... OPC_BGTZL
:
8249 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
8251 case OPC_LB
... OPC_LWR
: /* Load and stores */
8252 case OPC_SB
... OPC_SW
:
8256 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8259 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
8263 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8267 /* Floating point (COP1). */
8272 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8273 save_cpu_state(ctx
, 1);
8274 check_cp1_enabled(ctx
);
8275 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
8277 generate_exception_err(ctx
, EXCP_CpU
, 1);
8282 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8283 save_cpu_state(ctx
, 1);
8284 check_cp1_enabled(ctx
);
8285 op1
= MASK_CP1(ctx
->opcode
);
8289 check_insn(env
, ctx
, ISA_MIPS32R2
);
8294 gen_cp1(ctx
, op1
, rt
, rd
);
8296 #if defined(TARGET_MIPS64)
8299 check_insn(env
, ctx
, ISA_MIPS3
);
8300 gen_cp1(ctx
, op1
, rt
, rd
);
8306 check_insn(env
, ctx
, ASE_MIPS3D
);
8309 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
8310 (rt
>> 2) & 0x7, imm
<< 2);
8317 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
8322 generate_exception (ctx
, EXCP_RI
);
8326 generate_exception_err(ctx
, EXCP_CpU
, 1);
8336 /* COP2: Not implemented. */
8337 generate_exception_err(ctx
, EXCP_CpU
, 2);
8341 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8342 save_cpu_state(ctx
, 1);
8343 check_cp1_enabled(ctx
);
8344 op1
= MASK_CP3(ctx
->opcode
);
8352 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
8370 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
8374 generate_exception (ctx
, EXCP_RI
);
8378 generate_exception_err(ctx
, EXCP_CpU
, 1);
8382 #if defined(TARGET_MIPS64)
8383 /* MIPS64 opcodes */
8385 case OPC_LDL
... OPC_LDR
:
8386 case OPC_SDL
... OPC_SDR
:
8391 check_insn(env
, ctx
, ISA_MIPS3
);
8393 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8395 case OPC_DADDI
... OPC_DADDIU
:
8396 check_insn(env
, ctx
, ISA_MIPS3
);
8398 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8402 check_insn(env
, ctx
, ASE_MIPS16
);
8403 /* MIPS16: Not implemented. */
8405 check_insn(env
, ctx
, ASE_MDMX
);
8406 /* MDMX: Not implemented. */
8407 default: /* Invalid */
8408 MIPS_INVAL("major opcode");
8409 generate_exception(ctx
, EXCP_RI
);
8412 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8413 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8414 /* Branches completion */
8415 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8416 ctx
->bstate
= BS_BRANCH
;
8417 save_cpu_state(ctx
, 0);
8418 /* FIXME: Need to clear can_do_io. */
8421 /* unconditional branch */
8422 MIPS_DEBUG("unconditional branch");
8423 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8426 /* blikely taken case */
8427 MIPS_DEBUG("blikely branch taken");
8428 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8431 /* Conditional branch */
8432 MIPS_DEBUG("conditional branch");
8434 int l1
= gen_new_label();
8436 tcg_gen_brcondi_i32(TCG_COND_NE
, bcond
, 0, l1
);
8437 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8439 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8443 /* unconditional branch to register */
8444 MIPS_DEBUG("branch to register");
8445 tcg_gen_st_tl(btarget
, cpu_env
, offsetof(CPUState
, active_tc
.PC
));
8449 MIPS_DEBUG("unknown branch");
8456 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
8460 target_ulong pc_start
;
8461 uint16_t *gen_opc_end
;
8466 if (search_pc
&& loglevel
)
8467 fprintf (logfile
, "search pc %d\n", search_pc
);
8470 /* Leave some spare opc slots for branch handling. */
8471 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
- 16;
8475 ctx
.bstate
= BS_NONE
;
8476 /* Restore delay slot state from the tb context. */
8477 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
8478 restore_cpu_state(env
, &ctx
);
8479 if (env
->user_mode_only
)
8480 ctx
.mem_idx
= MIPS_HFLAG_UM
;
8482 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
8484 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8486 max_insns
= CF_COUNT_MASK
;
8488 if (loglevel
& CPU_LOG_TB_CPU
) {
8489 fprintf(logfile
, "------------------------------------------------\n");
8490 /* FIXME: This may print out stale hflags from env... */
8491 cpu_dump_state(env
, logfile
, fprintf
, 0);
8494 #ifdef MIPS_DEBUG_DISAS
8495 if (loglevel
& CPU_LOG_TB_IN_ASM
)
8496 fprintf(logfile
, "\ntb %p idx %d hflags %04x\n",
8497 tb
, ctx
.mem_idx
, ctx
.hflags
);
8500 while (ctx
.bstate
== BS_NONE
) {
8501 if (env
->nb_breakpoints
> 0) {
8502 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
8503 if (env
->breakpoints
[j
] == ctx
.pc
) {
8504 save_cpu_state(&ctx
, 1);
8505 ctx
.bstate
= BS_BRANCH
;
8506 tcg_gen_helper_0_i(do_raise_exception
, EXCP_DEBUG
);
8507 /* Include the breakpoint location or the tb won't
8508 * be flushed when it must be. */
8510 goto done_generating
;
8516 j
= gen_opc_ptr
- gen_opc_buf
;
8520 gen_opc_instr_start
[lj
++] = 0;
8522 gen_opc_pc
[lj
] = ctx
.pc
;
8523 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
8524 gen_opc_instr_start
[lj
] = 1;
8525 gen_opc_icount
[lj
] = num_insns
;
8527 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8529 ctx
.opcode
= ldl_code(ctx
.pc
);
8530 decode_opc(env
, &ctx
);
8534 if (env
->singlestep_enabled
)
8537 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
8540 if (gen_opc_ptr
>= gen_opc_end
)
8543 if (num_insns
>= max_insns
)
8545 #if defined (MIPS_SINGLE_STEP)
8549 if (tb
->cflags
& CF_LAST_IO
)
8551 if (env
->singlestep_enabled
) {
8552 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
8553 tcg_gen_helper_0_i(do_raise_exception
, EXCP_DEBUG
);
8555 switch (ctx
.bstate
) {
8557 tcg_gen_helper_0_0(do_interrupt_restart
);
8558 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8561 save_cpu_state(&ctx
, 0);
8562 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8565 tcg_gen_helper_0_0(do_interrupt_restart
);
8574 gen_icount_end(tb
, num_insns
);
8575 *gen_opc_ptr
= INDEX_op_end
;
8577 j
= gen_opc_ptr
- gen_opc_buf
;
8580 gen_opc_instr_start
[lj
++] = 0;
8582 tb
->size
= ctx
.pc
- pc_start
;
8583 tb
->icount
= num_insns
;
8586 #if defined MIPS_DEBUG_DISAS
8587 if (loglevel
& CPU_LOG_TB_IN_ASM
)
8588 fprintf(logfile
, "\n");
8590 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
8591 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
8592 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 0);
8593 fprintf(logfile
, "\n");
8595 if (loglevel
& CPU_LOG_TB_CPU
) {
8596 fprintf(logfile
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
8601 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8603 gen_intermediate_code_internal(env
, tb
, 0);
8606 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8608 gen_intermediate_code_internal(env
, tb
, 1);
8611 static void fpu_dump_state(CPUState
*env
, FILE *f
,
8612 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8616 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
8618 #define printfpr(fp) \
8621 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8622 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8623 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8626 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8627 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8628 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8629 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8630 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8635 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8636 env
->fpu
->fcr0
, env
->fpu
->fcr31
, is_fpu64
, env
->fpu
->fp_status
,
8637 get_float_exception_flags(&env
->fpu
->fp_status
));
8638 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
8639 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
8640 printfpr(&env
->fpu
->fpr
[i
]);
8646 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8647 /* Debug help: The architecture requires 32bit code to maintain proper
8648 sign-extended values on 64bit machines. */
8650 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8653 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8654 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8659 if (!SIGN_EXT_P(env
->active_tc
.PC
))
8660 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
8661 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
8662 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
8663 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
8664 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
8665 if (!SIGN_EXT_P(env
->btarget
))
8666 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8668 for (i
= 0; i
< 32; i
++) {
8669 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
8670 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
8673 if (!SIGN_EXT_P(env
->CP0_EPC
))
8674 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8675 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
8676 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
8680 void cpu_dump_state (CPUState
*env
, FILE *f
,
8681 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8686 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",
8687 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
8688 env
->hflags
, env
->btarget
, env
->bcond
);
8689 for (i
= 0; i
< 32; i
++) {
8691 cpu_fprintf(f
, "GPR%02d:", i
);
8692 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
8694 cpu_fprintf(f
, "\n");
8697 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8698 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8699 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8700 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
8701 if (env
->hflags
& MIPS_HFLAG_FPU
)
8702 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8703 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8704 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8708 static void mips_tcg_init(void)
8712 /* Initialize various static tables. */
8716 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
8717 bcond
= tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
,
8718 offsetof(CPUState
, bcond
), "bcond");
8719 btarget
= tcg_global_mem_new(TCG_TYPE_TL
, TCG_AREG0
,
8720 offsetof(CPUState
, btarget
), "btarget");
8721 current_fpu
= tcg_global_mem_new(TCG_TYPE_PTR
,
8723 offsetof(CPUState
, fpu
),
8726 /* register helpers */
8728 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
8734 #include "translate_init.c"
8736 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8739 const mips_def_t
*def
;
8741 def
= cpu_mips_find_by_name(cpu_model
);
8744 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8747 env
->cpu_model
= def
;
8750 env
->cpu_model_str
= cpu_model
;
8756 void cpu_reset (CPUMIPSState
*env
)
8758 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8763 #if defined(CONFIG_USER_ONLY)
8764 env
->user_mode_only
= 1;
8766 if (env
->user_mode_only
) {
8767 env
->hflags
= MIPS_HFLAG_UM
;
8769 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8770 /* If the exception was raised from a delay slot,
8771 come back to the jump. */
8772 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
8774 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
8776 env
->active_tc
.PC
= (int32_t)0xBFC00000;
8778 /* SMP not implemented */
8779 env
->CP0_EBase
= 0x80000000;
8780 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8781 /* vectored interrupts not implemented, timer on int 7,
8782 no performance counters. */
8783 env
->CP0_IntCtl
= 0xe0000000;
8787 for (i
= 0; i
< 7; i
++) {
8788 env
->CP0_WatchLo
[i
] = 0;
8789 env
->CP0_WatchHi
[i
] = 0x80000000;
8791 env
->CP0_WatchLo
[7] = 0;
8792 env
->CP0_WatchHi
[7] = 0;
8794 /* Count register increments in debug mode, EJTAG version 1 */
8795 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8796 env
->hflags
= MIPS_HFLAG_CP0
;
8798 env
->exception_index
= EXCP_NONE
;
8799 cpu_mips_register(env
, env
->cpu_model
);
8802 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8803 unsigned long searched_pc
, int pc_pos
, void *puc
)
8805 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
8806 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8807 env
->hflags
|= gen_opc_hflags
[pc_pos
];