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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
33 #include "qemu-common.h"
39 //#define MIPS_DEBUG_DISAS
40 //#define MIPS_DEBUG_SIGN_EXTENSIONS
42 /* MIPS major opcodes */
43 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
46 /* indirect opcode tables */
47 OPC_SPECIAL
= (0x00 << 26),
48 OPC_REGIMM
= (0x01 << 26),
49 OPC_CP0
= (0x10 << 26),
50 OPC_CP1
= (0x11 << 26),
51 OPC_CP2
= (0x12 << 26),
52 OPC_CP3
= (0x13 << 26),
53 OPC_SPECIAL2
= (0x1C << 26),
54 OPC_SPECIAL3
= (0x1F << 26),
55 /* arithmetic with immediate */
56 OPC_ADDI
= (0x08 << 26),
57 OPC_ADDIU
= (0x09 << 26),
58 OPC_SLTI
= (0x0A << 26),
59 OPC_SLTIU
= (0x0B << 26),
60 /* logic with immediate */
61 OPC_ANDI
= (0x0C << 26),
62 OPC_ORI
= (0x0D << 26),
63 OPC_XORI
= (0x0E << 26),
64 OPC_LUI
= (0x0F << 26),
65 /* arithmetic with immediate */
66 OPC_DADDI
= (0x18 << 26),
67 OPC_DADDIU
= (0x19 << 26),
68 /* Jump and branches */
70 OPC_JAL
= (0x03 << 26),
71 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
72 OPC_BEQL
= (0x14 << 26),
73 OPC_BNE
= (0x05 << 26),
74 OPC_BNEL
= (0x15 << 26),
75 OPC_BLEZ
= (0x06 << 26),
76 OPC_BLEZL
= (0x16 << 26),
77 OPC_BGTZ
= (0x07 << 26),
78 OPC_BGTZL
= (0x17 << 26),
79 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
81 OPC_LDL
= (0x1A << 26),
82 OPC_LDR
= (0x1B << 26),
83 OPC_LB
= (0x20 << 26),
84 OPC_LH
= (0x21 << 26),
85 OPC_LWL
= (0x22 << 26),
86 OPC_LW
= (0x23 << 26),
87 OPC_LBU
= (0x24 << 26),
88 OPC_LHU
= (0x25 << 26),
89 OPC_LWR
= (0x26 << 26),
90 OPC_LWU
= (0x27 << 26),
91 OPC_SB
= (0x28 << 26),
92 OPC_SH
= (0x29 << 26),
93 OPC_SWL
= (0x2A << 26),
94 OPC_SW
= (0x2B << 26),
95 OPC_SDL
= (0x2C << 26),
96 OPC_SDR
= (0x2D << 26),
97 OPC_SWR
= (0x2E << 26),
98 OPC_LL
= (0x30 << 26),
99 OPC_LLD
= (0x34 << 26),
100 OPC_LD
= (0x37 << 26),
101 OPC_SC
= (0x38 << 26),
102 OPC_SCD
= (0x3C << 26),
103 OPC_SD
= (0x3F << 26),
104 /* Floating point load/store */
105 OPC_LWC1
= (0x31 << 26),
106 OPC_LWC2
= (0x32 << 26),
107 OPC_LDC1
= (0x35 << 26),
108 OPC_LDC2
= (0x36 << 26),
109 OPC_SWC1
= (0x39 << 26),
110 OPC_SWC2
= (0x3A << 26),
111 OPC_SDC1
= (0x3D << 26),
112 OPC_SDC2
= (0x3E << 26),
113 /* MDMX ASE specific */
114 OPC_MDMX
= (0x1E << 26),
115 /* Cache and prefetch */
116 OPC_CACHE
= (0x2F << 26),
117 OPC_PREF
= (0x33 << 26),
118 /* Reserved major opcode */
119 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
122 /* MIPS special opcodes */
123 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
127 OPC_SLL
= 0x00 | OPC_SPECIAL
,
128 /* NOP is SLL r0, r0, 0 */
129 /* SSNOP is SLL r0, r0, 1 */
130 /* EHB is SLL r0, r0, 3 */
131 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
132 OPC_SRA
= 0x03 | OPC_SPECIAL
,
133 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
134 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
135 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
136 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
137 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
138 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
139 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
140 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
141 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
142 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
143 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
144 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
145 /* Multiplication / division */
146 OPC_MULT
= 0x18 | OPC_SPECIAL
,
147 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
148 OPC_DIV
= 0x1A | OPC_SPECIAL
,
149 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
150 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
151 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
152 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
153 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
154 /* 2 registers arithmetic / logic */
155 OPC_ADD
= 0x20 | OPC_SPECIAL
,
156 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
157 OPC_SUB
= 0x22 | OPC_SPECIAL
,
158 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
159 OPC_AND
= 0x24 | OPC_SPECIAL
,
160 OPC_OR
= 0x25 | OPC_SPECIAL
,
161 OPC_XOR
= 0x26 | OPC_SPECIAL
,
162 OPC_NOR
= 0x27 | OPC_SPECIAL
,
163 OPC_SLT
= 0x2A | OPC_SPECIAL
,
164 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
165 OPC_DADD
= 0x2C | OPC_SPECIAL
,
166 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
167 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
168 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
170 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
171 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
173 OPC_TGE
= 0x30 | OPC_SPECIAL
,
174 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
175 OPC_TLT
= 0x32 | OPC_SPECIAL
,
176 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
177 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
178 OPC_TNE
= 0x36 | OPC_SPECIAL
,
179 /* HI / LO registers load & stores */
180 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
181 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
182 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
183 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
184 /* Conditional moves */
185 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
186 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
188 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
191 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
192 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
193 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
194 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
195 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
197 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
198 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
199 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
200 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
201 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
202 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
203 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
206 /* Multiplication variants of the vr54xx. */
207 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
210 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
211 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
212 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
213 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
214 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
215 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
216 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
217 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
218 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
219 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
220 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
221 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
222 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
223 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
226 /* REGIMM (rt field) opcodes */
227 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
230 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
231 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
232 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
233 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
234 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
235 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
236 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
237 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
238 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
239 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
240 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
241 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
242 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
243 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
244 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
247 /* Special2 opcodes */
248 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
251 /* Multiply & xxx operations */
252 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
253 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
254 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
255 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
256 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
258 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
259 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
260 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
261 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
263 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
266 /* Special3 opcodes */
267 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
270 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
271 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
272 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
273 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
274 OPC_INS
= 0x04 | OPC_SPECIAL3
,
275 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
276 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
277 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
278 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
279 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
280 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
281 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
282 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
286 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
289 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
290 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
291 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
295 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
298 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
299 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
302 /* Coprocessor 0 (rs field) */
303 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
306 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
307 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
308 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
309 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
310 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
311 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
312 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
313 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
314 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
315 OPC_C0
= (0x10 << 21) | OPC_CP0
,
316 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
317 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
321 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
324 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
325 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
326 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
327 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
328 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
329 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
332 /* Coprocessor 0 (with rs == C0) */
333 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
336 OPC_TLBR
= 0x01 | OPC_C0
,
337 OPC_TLBWI
= 0x02 | OPC_C0
,
338 OPC_TLBWR
= 0x06 | OPC_C0
,
339 OPC_TLBP
= 0x08 | OPC_C0
,
340 OPC_RFE
= 0x10 | OPC_C0
,
341 OPC_ERET
= 0x18 | OPC_C0
,
342 OPC_DERET
= 0x1F | OPC_C0
,
343 OPC_WAIT
= 0x20 | OPC_C0
,
346 /* Coprocessor 1 (rs field) */
347 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
350 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
351 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
352 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
353 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
354 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
355 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
356 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
357 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
358 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
359 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
360 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
361 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
362 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
363 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
364 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
365 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
366 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
367 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
370 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
371 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
374 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
375 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
376 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
377 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
381 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
382 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
386 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
387 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
390 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
393 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
394 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
395 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
396 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
397 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
398 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
399 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
400 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
401 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
404 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
407 OPC_LWXC1
= 0x00 | OPC_CP3
,
408 OPC_LDXC1
= 0x01 | OPC_CP3
,
409 OPC_LUXC1
= 0x05 | OPC_CP3
,
410 OPC_SWXC1
= 0x08 | OPC_CP3
,
411 OPC_SDXC1
= 0x09 | OPC_CP3
,
412 OPC_SUXC1
= 0x0D | OPC_CP3
,
413 OPC_PREFX
= 0x0F | OPC_CP3
,
414 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
415 OPC_MADD_S
= 0x20 | OPC_CP3
,
416 OPC_MADD_D
= 0x21 | OPC_CP3
,
417 OPC_MADD_PS
= 0x26 | OPC_CP3
,
418 OPC_MSUB_S
= 0x28 | OPC_CP3
,
419 OPC_MSUB_D
= 0x29 | OPC_CP3
,
420 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
421 OPC_NMADD_S
= 0x30 | OPC_CP3
,
422 OPC_NMADD_D
= 0x31 | OPC_CP3
,
423 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
424 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
425 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
426 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
429 /* global register indices */
430 static TCGv_ptr cpu_env
;
431 static TCGv cpu_gpr
[32], cpu_PC
;
432 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
433 static TCGv cpu_dspctrl
, btarget
, bcond
;
434 static TCGv_i32 hflags
;
435 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
437 #include "gen-icount.h"
439 #define gen_helper_0i(name, arg) do { \
440 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
441 gen_helper_##name(helper_tmp); \
442 tcg_temp_free_i32(helper_tmp); \
445 #define gen_helper_1i(name, arg1, arg2) do { \
446 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
447 gen_helper_##name(arg1, helper_tmp); \
448 tcg_temp_free_i32(helper_tmp); \
451 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
452 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
453 gen_helper_##name(arg1, arg2, helper_tmp); \
454 tcg_temp_free_i32(helper_tmp); \
457 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
458 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
459 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
460 tcg_temp_free_i32(helper_tmp); \
463 typedef struct DisasContext
{
464 struct TranslationBlock
*tb
;
465 target_ulong pc
, saved_pc
;
467 /* Routine used to access memory */
469 uint32_t hflags
, saved_hflags
;
471 target_ulong btarget
;
475 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
476 * exception condition */
477 BS_STOP
= 1, /* We want to stop translation for any reason */
478 BS_BRANCH
= 2, /* We reached a branch condition */
479 BS_EXCP
= 3, /* We reached an exception condition */
482 static const char *regnames
[] =
483 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
484 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
485 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
486 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
488 static const char *regnames_HI
[] =
489 { "HI0", "HI1", "HI2", "HI3", };
491 static const char *regnames_LO
[] =
492 { "LO0", "LO1", "LO2", "LO3", };
494 static const char *regnames_ACX
[] =
495 { "ACX0", "ACX1", "ACX2", "ACX3", };
497 static const char *fregnames
[] =
498 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
499 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
500 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
501 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
503 #ifdef MIPS_DEBUG_DISAS
504 #define MIPS_DEBUG(fmt, ...) \
505 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
506 TARGET_FMT_lx ": %08x " fmt "\n", \
507 ctx->pc, ctx->opcode , ## __VA_ARGS__)
508 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
510 #define MIPS_DEBUG(fmt, ...) do { } while(0)
511 #define LOG_DISAS(...) do { } while (0)
514 #define MIPS_INVAL(op) \
516 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
517 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
520 /* General purpose registers moves. */
521 static inline void gen_load_gpr (TCGv t
, int reg
)
524 tcg_gen_movi_tl(t
, 0);
526 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
529 static inline void gen_store_gpr (TCGv t
, int reg
)
532 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
535 /* Moves to/from ACX register. */
536 static inline void gen_load_ACX (TCGv t
, int reg
)
538 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
541 static inline void gen_store_ACX (TCGv t
, int reg
)
543 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
546 /* Moves to/from shadow registers. */
547 static inline void gen_load_srsgpr (int from
, int to
)
549 TCGv t0
= tcg_temp_new();
552 tcg_gen_movi_tl(t0
, 0);
554 TCGv_i32 t2
= tcg_temp_new_i32();
555 TCGv_ptr addr
= tcg_temp_new_ptr();
557 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
558 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
559 tcg_gen_andi_i32(t2
, t2
, 0xf);
560 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
561 tcg_gen_ext_i32_ptr(addr
, t2
);
562 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
564 tcg_gen_ld_tl(t0
, addr
, sizeof(target_ulong
) * from
);
565 tcg_temp_free_ptr(addr
);
566 tcg_temp_free_i32(t2
);
568 gen_store_gpr(t0
, to
);
572 static inline void gen_store_srsgpr (int from
, int to
)
575 TCGv t0
= tcg_temp_new();
576 TCGv_i32 t2
= tcg_temp_new_i32();
577 TCGv_ptr addr
= tcg_temp_new_ptr();
579 gen_load_gpr(t0
, from
);
580 tcg_gen_ld_i32(t2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
581 tcg_gen_shri_i32(t2
, t2
, CP0SRSCtl_PSS
);
582 tcg_gen_andi_i32(t2
, t2
, 0xf);
583 tcg_gen_muli_i32(t2
, t2
, sizeof(target_ulong
) * 32);
584 tcg_gen_ext_i32_ptr(addr
, t2
);
585 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
587 tcg_gen_st_tl(t0
, addr
, sizeof(target_ulong
) * to
);
588 tcg_temp_free_ptr(addr
);
589 tcg_temp_free_i32(t2
);
594 /* Floating point register moves. */
595 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
597 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
600 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
602 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[FP_ENDIAN_IDX
]));
605 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
607 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
610 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
612 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].w
[!FP_ENDIAN_IDX
]));
615 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
617 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
618 tcg_gen_ld_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
620 TCGv_i32 t0
= tcg_temp_new_i32();
621 TCGv_i32 t1
= tcg_temp_new_i32();
622 gen_load_fpr32(t0
, reg
& ~1);
623 gen_load_fpr32(t1
, reg
| 1);
624 tcg_gen_concat_i32_i64(t
, t0
, t1
);
625 tcg_temp_free_i32(t0
);
626 tcg_temp_free_i32(t1
);
630 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
632 if (ctx
->hflags
& MIPS_HFLAG_F64
) {
633 tcg_gen_st_i64(t
, cpu_env
, offsetof(CPUState
, active_fpu
.fpr
[reg
].d
));
635 TCGv_i64 t0
= tcg_temp_new_i64();
636 TCGv_i32 t1
= tcg_temp_new_i32();
637 tcg_gen_trunc_i64_i32(t1
, t
);
638 gen_store_fpr32(t1
, reg
& ~1);
639 tcg_gen_shri_i64(t0
, t
, 32);
640 tcg_gen_trunc_i64_i32(t1
, t0
);
641 gen_store_fpr32(t1
, reg
| 1);
642 tcg_temp_free_i32(t1
);
643 tcg_temp_free_i64(t0
);
647 static inline int get_fp_bit (int cc
)
655 #define FOP_CONDS(type, fmt, bits) \
656 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
657 TCGv_i##bits b, int cc) \
660 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
661 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
662 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
663 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
664 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
665 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
666 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
667 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
668 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
669 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
670 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
671 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
672 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
673 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
674 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
675 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
681 FOP_CONDS(abs
, d
, 64)
683 FOP_CONDS(abs
, s
, 32)
685 FOP_CONDS(abs
, ps
, 64)
689 #define OP_COND(name, cond) \
690 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, TCGv t1) \
692 int l1 = gen_new_label(); \
693 int l2 = gen_new_label(); \
695 tcg_gen_brcond_tl(cond, t0, t1, l1); \
696 tcg_gen_movi_tl(ret, 0); \
699 tcg_gen_movi_tl(ret, 1); \
702 OP_COND(eq
, TCG_COND_EQ
);
703 OP_COND(ne
, TCG_COND_NE
);
704 OP_COND(ge
, TCG_COND_GE
);
705 OP_COND(geu
, TCG_COND_GEU
);
706 OP_COND(lt
, TCG_COND_LT
);
707 OP_COND(ltu
, TCG_COND_LTU
);
710 #define OP_CONDI(name, cond) \
711 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0, target_ulong val) \
713 int l1 = gen_new_label(); \
714 int l2 = gen_new_label(); \
716 tcg_gen_brcondi_tl(cond, t0, val, l1); \
717 tcg_gen_movi_tl(ret, 0); \
720 tcg_gen_movi_tl(ret, 1); \
723 OP_CONDI(lti
, TCG_COND_LT
);
724 OP_CONDI(ltiu
, TCG_COND_LTU
);
727 #define OP_CONDZ(name, cond) \
728 static inline void glue(gen_op_, name) (TCGv ret, TCGv t0) \
730 int l1 = gen_new_label(); \
731 int l2 = gen_new_label(); \
733 tcg_gen_brcondi_tl(cond, t0, 0, l1); \
734 tcg_gen_movi_tl(ret, 0); \
737 tcg_gen_movi_tl(ret, 1); \
740 OP_CONDZ(gez
, TCG_COND_GE
);
741 OP_CONDZ(gtz
, TCG_COND_GT
);
742 OP_CONDZ(lez
, TCG_COND_LE
);
743 OP_CONDZ(ltz
, TCG_COND_LT
);
746 static inline void gen_save_pc(target_ulong pc
)
748 tcg_gen_movi_tl(cpu_PC
, pc
);
751 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
753 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
754 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
755 gen_save_pc(ctx
->pc
);
756 ctx
->saved_pc
= ctx
->pc
;
758 if (ctx
->hflags
!= ctx
->saved_hflags
) {
759 tcg_gen_movi_i32(hflags
, ctx
->hflags
);
760 ctx
->saved_hflags
= ctx
->hflags
;
761 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
767 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
773 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
775 ctx
->saved_hflags
= ctx
->hflags
;
776 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
782 ctx
->btarget
= env
->btarget
;
788 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
790 TCGv_i32 texcp
= tcg_const_i32(excp
);
791 TCGv_i32 terr
= tcg_const_i32(err
);
792 save_cpu_state(ctx
, 1);
793 gen_helper_raise_exception_err(texcp
, terr
);
794 tcg_temp_free_i32(terr
);
795 tcg_temp_free_i32(texcp
);
799 generate_exception (DisasContext
*ctx
, int excp
)
801 save_cpu_state(ctx
, 1);
802 gen_helper_0i(raise_exception
, excp
);
805 /* Addresses computation */
806 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv t0
, TCGv t1
)
808 tcg_gen_add_tl(t0
, t0
, t1
);
810 #if defined(TARGET_MIPS64)
811 /* For compatibility with 32-bit code, data reference in user mode
812 with Status_UX = 0 should be casted to 32-bit and sign extended.
813 See the MIPS64 PRA manual, section 4.10. */
814 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
815 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
816 tcg_gen_ext32s_i64(t0
, t0
);
821 static inline void check_cp0_enabled(DisasContext
*ctx
)
823 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
824 generate_exception_err(ctx
, EXCP_CpU
, 1);
827 static inline void check_cp1_enabled(DisasContext
*ctx
)
829 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
830 generate_exception_err(ctx
, EXCP_CpU
, 1);
833 /* Verify that the processor is running with COP1X instructions enabled.
834 This is associated with the nabla symbol in the MIPS32 and MIPS64
837 static inline void check_cop1x(DisasContext
*ctx
)
839 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
840 generate_exception(ctx
, EXCP_RI
);
843 /* Verify that the processor is running with 64-bit floating-point
844 operations enabled. */
846 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
848 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
849 generate_exception(ctx
, EXCP_RI
);
853 * Verify if floating point register is valid; an operation is not defined
854 * if bit 0 of any register specification is set and the FR bit in the
855 * Status register equals zero, since the register numbers specify an
856 * even-odd pair of adjacent coprocessor general registers. When the FR bit
857 * in the Status register equals one, both even and odd register numbers
858 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
860 * Multiple 64 bit wide registers can be checked by calling
861 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
863 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
865 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
866 generate_exception(ctx
, EXCP_RI
);
869 /* This code generates a "reserved instruction" exception if the
870 CPU does not support the instruction set corresponding to flags. */
871 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
873 if (unlikely(!(env
->insn_flags
& flags
)))
874 generate_exception(ctx
, EXCP_RI
);
877 /* This code generates a "reserved instruction" exception if 64-bit
878 instructions are not enabled. */
879 static inline void check_mips_64(DisasContext
*ctx
)
881 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
882 generate_exception(ctx
, EXCP_RI
);
885 /* load/store instructions. */
886 #define OP_LD(insn,fname) \
887 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
889 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
896 #if defined(TARGET_MIPS64)
902 #define OP_ST(insn,fname) \
903 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, DisasContext *ctx) \
905 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
910 #if defined(TARGET_MIPS64)
915 #define OP_LD_ATOMIC(insn,fname) \
916 static inline void op_ldst_##insn(TCGv ret, TCGv arg1, DisasContext *ctx) \
918 TCGv t0 = tcg_temp_new(); \
919 tcg_gen_mov_tl(t0, arg1); \
920 tcg_gen_qemu_##fname(ret, arg1, ctx->mem_idx); \
921 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
922 tcg_gen_st_tl(ret, cpu_env, offsetof(CPUState, llval)); \
925 OP_LD_ATOMIC(ll
,ld32s
);
926 #if defined(TARGET_MIPS64)
927 OP_LD_ATOMIC(lld
,ld64
);
931 #ifdef CONFIG_USER_ONLY
932 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
933 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
935 TCGv t0 = tcg_temp_new(); \
936 int l1 = gen_new_label(); \
937 int l2 = gen_new_label(); \
939 tcg_gen_andi_tl(t0, arg2, almask); \
940 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
941 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
942 generate_exception(ctx, EXCP_AdES); \
944 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
945 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
946 tcg_gen_movi_tl(t0, rt | ((almask << 3) & 0x20)); \
947 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, llreg)); \
948 tcg_gen_st_tl(arg1, cpu_env, offsetof(CPUState, llnewval)); \
949 gen_helper_0i(raise_exception, EXCP_SC); \
951 tcg_gen_movi_tl(t0, 0); \
952 gen_store_gpr(t0, rt); \
956 #define OP_ST_ATOMIC(insn,fname,ldname,almask) \
957 static inline void op_ldst_##insn(TCGv arg1, TCGv arg2, int rt, DisasContext *ctx) \
959 TCGv t0 = tcg_temp_new(); \
960 TCGv t1 = tcg_temp_new(); \
961 int l1 = gen_new_label(); \
962 int l2 = gen_new_label(); \
963 int l3 = gen_new_label(); \
965 tcg_gen_andi_tl(t0, arg2, almask); \
966 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); \
967 tcg_gen_st_tl(arg2, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
968 generate_exception(ctx, EXCP_AdES); \
970 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
971 tcg_gen_brcond_tl(TCG_COND_NE, arg2, t0, l2); \
972 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, llval)); \
973 tcg_gen_qemu_##ldname(t1, arg2, ctx->mem_idx); \
974 tcg_gen_brcond_tl(TCG_COND_NE, t0, t1, l2); \
976 tcg_gen_qemu_##fname(arg1, arg2, ctx->mem_idx); \
977 tcg_gen_movi_tl(t0, 1); \
978 gen_store_gpr(t0, rt); \
981 tcg_gen_movi_tl(t0, 0); \
982 gen_store_gpr(t0, rt); \
988 OP_ST_ATOMIC(sc
,st32
,ld32s
,0x3);
989 #if defined(TARGET_MIPS64)
990 OP_ST_ATOMIC(scd
,st64
,ld64
,0x7);
995 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
996 int base
, int16_t offset
)
998 const char *opn
= "ldst";
999 TCGv t0
= tcg_temp_new();
1000 TCGv t1
= tcg_temp_new();
1003 tcg_gen_movi_tl(t0
, offset
);
1004 } else if (offset
== 0) {
1005 gen_load_gpr(t0
, base
);
1007 tcg_gen_movi_tl(t0
, offset
);
1008 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1010 /* Don't do NOP if destination is zero: we must perform the actual
1013 #if defined(TARGET_MIPS64)
1015 save_cpu_state(ctx
, 0);
1016 op_ldst_lwu(t0
, t0
, ctx
);
1017 gen_store_gpr(t0
, rt
);
1021 save_cpu_state(ctx
, 0);
1022 op_ldst_ld(t0
, t0
, ctx
);
1023 gen_store_gpr(t0
, rt
);
1027 save_cpu_state(ctx
, 0);
1028 op_ldst_lld(t0
, t0
, ctx
);
1029 gen_store_gpr(t0
, rt
);
1033 save_cpu_state(ctx
, 0);
1034 gen_load_gpr(t1
, rt
);
1035 op_ldst_sd(t1
, t0
, ctx
);
1039 save_cpu_state(ctx
, 1);
1040 gen_load_gpr(t1
, rt
);
1041 gen_helper_3i(ldl
, t1
, t1
, t0
, ctx
->mem_idx
);
1042 gen_store_gpr(t1
, rt
);
1046 save_cpu_state(ctx
, 1);
1047 gen_load_gpr(t1
, rt
);
1048 gen_helper_2i(sdl
, t1
, t0
, ctx
->mem_idx
);
1052 save_cpu_state(ctx
, 1);
1053 gen_load_gpr(t1
, rt
);
1054 gen_helper_3i(ldr
, t1
, t1
, t0
, ctx
->mem_idx
);
1055 gen_store_gpr(t1
, rt
);
1059 save_cpu_state(ctx
, 1);
1060 gen_load_gpr(t1
, rt
);
1061 gen_helper_2i(sdr
, t1
, t0
, ctx
->mem_idx
);
1066 save_cpu_state(ctx
, 0);
1067 op_ldst_lw(t0
, t0
, ctx
);
1068 gen_store_gpr(t0
, rt
);
1072 save_cpu_state(ctx
, 0);
1073 gen_load_gpr(t1
, rt
);
1074 op_ldst_sw(t1
, t0
, ctx
);
1078 save_cpu_state(ctx
, 0);
1079 op_ldst_lh(t0
, t0
, ctx
);
1080 gen_store_gpr(t0
, rt
);
1084 save_cpu_state(ctx
, 0);
1085 gen_load_gpr(t1
, rt
);
1086 op_ldst_sh(t1
, t0
, ctx
);
1090 save_cpu_state(ctx
, 0);
1091 op_ldst_lhu(t0
, t0
, ctx
);
1092 gen_store_gpr(t0
, rt
);
1096 save_cpu_state(ctx
, 0);
1097 op_ldst_lb(t0
, t0
, ctx
);
1098 gen_store_gpr(t0
, rt
);
1102 save_cpu_state(ctx
, 0);
1103 gen_load_gpr(t1
, rt
);
1104 op_ldst_sb(t1
, t0
, ctx
);
1108 save_cpu_state(ctx
, 0);
1109 op_ldst_lbu(t0
, t0
, ctx
);
1110 gen_store_gpr(t0
, rt
);
1114 save_cpu_state(ctx
, 1);
1115 gen_load_gpr(t1
, rt
);
1116 gen_helper_3i(lwl
, t1
, t1
, t0
, ctx
->mem_idx
);
1117 gen_store_gpr(t1
, rt
);
1121 save_cpu_state(ctx
, 1);
1122 gen_load_gpr(t1
, rt
);
1123 gen_helper_2i(swl
, t1
, t0
, ctx
->mem_idx
);
1127 save_cpu_state(ctx
, 1);
1128 gen_load_gpr(t1
, rt
);
1129 gen_helper_3i(lwr
, t1
, t1
, t0
, ctx
->mem_idx
);
1130 gen_store_gpr(t1
, rt
);
1134 save_cpu_state(ctx
, 1);
1135 gen_load_gpr(t1
, rt
);
1136 gen_helper_2i(swr
, t1
, t0
, ctx
->mem_idx
);
1140 save_cpu_state(ctx
, 0);
1141 op_ldst_ll(t0
, t0
, ctx
);
1142 gen_store_gpr(t0
, rt
);
1146 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1151 /* Store conditional */
1152 static void gen_st_cond (DisasContext
*ctx
, uint32_t opc
, int rt
,
1153 int base
, int16_t offset
)
1155 const char *opn
= "st_cond";
1158 t0
= tcg_temp_local_new();
1161 tcg_gen_movi_tl(t0
, offset
);
1162 } else if (offset
== 0) {
1163 gen_load_gpr(t0
, base
);
1165 tcg_gen_movi_tl(t0
, offset
);
1166 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1168 /* Don't do NOP if destination is zero: we must perform the actual
1171 t1
= tcg_temp_local_new();
1172 gen_load_gpr(t1
, rt
);
1174 #if defined(TARGET_MIPS64)
1176 save_cpu_state(ctx
, 0);
1177 op_ldst_scd(t0
, t1
, t0
, ctx
);
1182 save_cpu_state(ctx
, 0);
1183 op_ldst_sc(t0
, t1
, t0
, ctx
);
1187 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1189 gen_store_gpr(t0
, rt
);
1193 /* Load and store */
1194 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1195 int base
, int16_t offset
)
1197 const char *opn
= "flt_ldst";
1198 TCGv t0
= tcg_temp_new();
1201 tcg_gen_movi_tl(t0
, offset
);
1202 } else if (offset
== 0) {
1203 gen_load_gpr(t0
, base
);
1205 tcg_gen_movi_tl(t0
, offset
);
1206 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1208 /* Don't do NOP if destination is zero: we must perform the actual
1213 TCGv_i32 fp0
= tcg_temp_new_i32();
1215 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
1216 tcg_gen_trunc_tl_i32(fp0
, t0
);
1217 gen_store_fpr32(fp0
, ft
);
1218 tcg_temp_free_i32(fp0
);
1224 TCGv_i32 fp0
= tcg_temp_new_i32();
1225 TCGv t1
= tcg_temp_new();
1227 gen_load_fpr32(fp0
, ft
);
1228 tcg_gen_extu_i32_tl(t1
, fp0
);
1229 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1231 tcg_temp_free_i32(fp0
);
1237 TCGv_i64 fp0
= tcg_temp_new_i64();
1239 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1240 gen_store_fpr64(ctx
, fp0
, ft
);
1241 tcg_temp_free_i64(fp0
);
1247 TCGv_i64 fp0
= tcg_temp_new_i64();
1249 gen_load_fpr64(ctx
, fp0
, ft
);
1250 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1251 tcg_temp_free_i64(fp0
);
1257 generate_exception(ctx
, EXCP_RI
);
1260 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1265 /* Arithmetic with immediate operand */
1266 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1267 int rt
, int rs
, int16_t imm
)
1269 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1270 const char *opn
= "imm arith";
1272 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1273 /* If no destination, treat it as a NOP.
1274 For addi, we must generate the overflow exception when needed. */
1281 TCGv t0
= tcg_temp_local_new();
1282 TCGv t1
= tcg_temp_new();
1283 TCGv t2
= tcg_temp_new();
1284 int l1
= gen_new_label();
1286 gen_load_gpr(t1
, rs
);
1287 tcg_gen_addi_tl(t0
, t1
, uimm
);
1288 tcg_gen_ext32s_tl(t0
, t0
);
1290 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1291 tcg_gen_xori_tl(t2
, t0
, uimm
);
1292 tcg_gen_and_tl(t1
, t1
, t2
);
1294 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1296 /* operands of same sign, result different sign */
1297 generate_exception(ctx
, EXCP_OVERFLOW
);
1299 tcg_gen_ext32s_tl(t0
, t0
);
1300 gen_store_gpr(t0
, rt
);
1307 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1308 tcg_gen_ext32s_tl(cpu_gpr
[rt
], cpu_gpr
[rt
]);
1310 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1314 #if defined(TARGET_MIPS64)
1317 TCGv t0
= tcg_temp_local_new();
1318 TCGv t1
= tcg_temp_new();
1319 TCGv t2
= tcg_temp_new();
1320 int l1
= gen_new_label();
1322 gen_load_gpr(t1
, rs
);
1323 tcg_gen_addi_tl(t0
, t1
, uimm
);
1325 tcg_gen_xori_tl(t1
, t1
, ~uimm
);
1326 tcg_gen_xori_tl(t2
, t0
, uimm
);
1327 tcg_gen_and_tl(t1
, t1
, t2
);
1329 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1331 /* operands of same sign, result different sign */
1332 generate_exception(ctx
, EXCP_OVERFLOW
);
1334 gen_store_gpr(t0
, rt
);
1341 tcg_gen_addi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1343 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1349 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1352 /* Logic with immediate operand */
1353 static void gen_logic_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1356 const char *opn
= "imm logic";
1359 /* If no destination, treat it as a NOP. */
1363 uimm
= (uint16_t)imm
;
1366 if (likely(rs
!= 0))
1367 tcg_gen_andi_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1369 tcg_gen_movi_tl(cpu_gpr
[rt
], 0);
1374 tcg_gen_ori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1376 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1380 if (likely(rs
!= 0))
1381 tcg_gen_xori_tl(cpu_gpr
[rt
], cpu_gpr
[rs
], uimm
);
1383 tcg_gen_movi_tl(cpu_gpr
[rt
], uimm
);
1387 tcg_gen_movi_tl(cpu_gpr
[rt
], imm
<< 16);
1391 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1394 /* Set on less than with immediate operand */
1395 static void gen_slt_imm (CPUState
*env
, uint32_t opc
, int rt
, int rs
, int16_t imm
)
1397 target_ulong uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1398 const char *opn
= "imm arith";
1402 /* If no destination, treat it as a NOP. */
1406 t0
= tcg_temp_new();
1407 gen_load_gpr(t0
, rs
);
1410 gen_op_lti(cpu_gpr
[rt
], t0
, uimm
);
1414 gen_op_ltiu(cpu_gpr
[rt
], t0
, uimm
);
1418 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1422 /* Shifts with immediate operand */
1423 static void gen_shift_imm(CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1424 int rt
, int rs
, int16_t imm
)
1426 target_ulong uimm
= ((uint16_t)imm
) & 0x1f;
1427 const char *opn
= "imm shift";
1431 /* If no destination, treat it as a NOP. */
1436 t0
= tcg_temp_new();
1437 gen_load_gpr(t0
, rs
);
1440 tcg_gen_shli_tl(t0
, t0
, uimm
);
1441 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1445 tcg_gen_ext32s_tl(t0
, t0
);
1446 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1450 switch ((ctx
->opcode
>> 21) & 0x1f) {
1453 tcg_gen_ext32u_tl(t0
, t0
);
1454 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1456 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1461 /* rotr is decoded as srl on non-R2 CPUs */
1462 if (env
->insn_flags
& ISA_MIPS32R2
) {
1464 TCGv_i32 t1
= tcg_temp_new_i32();
1466 tcg_gen_trunc_tl_i32(t1
, t0
);
1467 tcg_gen_rotri_i32(t1
, t1
, uimm
);
1468 tcg_gen_ext_i32_tl(cpu_gpr
[rt
], t1
);
1469 tcg_temp_free_i32(t1
);
1474 tcg_gen_ext32u_tl(t0
, t0
);
1475 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1477 tcg_gen_ext32s_tl(cpu_gpr
[rt
], t0
);
1483 MIPS_INVAL("invalid srl flag");
1484 generate_exception(ctx
, EXCP_RI
);
1488 #if defined(TARGET_MIPS64)
1490 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
);
1494 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
);
1498 switch ((ctx
->opcode
>> 21) & 0x1f) {
1500 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1504 /* drotr is decoded as dsrl on non-R2 CPUs */
1505 if (env
->insn_flags
& ISA_MIPS32R2
) {
1507 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
);
1511 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
);
1516 MIPS_INVAL("invalid dsrl flag");
1517 generate_exception(ctx
, EXCP_RI
);
1522 tcg_gen_shli_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1526 tcg_gen_sari_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1530 switch ((ctx
->opcode
>> 21) & 0x1f) {
1532 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1536 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1537 if (env
->insn_flags
& ISA_MIPS32R2
) {
1538 tcg_gen_rotri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1541 tcg_gen_shri_tl(cpu_gpr
[rt
], t0
, uimm
+ 32);
1546 MIPS_INVAL("invalid dsrl32 flag");
1547 generate_exception(ctx
, EXCP_RI
);
1553 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1558 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1559 int rd
, int rs
, int rt
)
1561 const char *opn
= "arith";
1563 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1564 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1565 /* If no destination, treat it as a NOP.
1566 For add & sub, we must generate the overflow exception when needed. */
1574 TCGv t0
= tcg_temp_local_new();
1575 TCGv t1
= tcg_temp_new();
1576 TCGv t2
= tcg_temp_new();
1577 int l1
= gen_new_label();
1579 gen_load_gpr(t1
, rs
);
1580 gen_load_gpr(t2
, rt
);
1581 tcg_gen_add_tl(t0
, t1
, t2
);
1582 tcg_gen_ext32s_tl(t0
, t0
);
1583 tcg_gen_xor_tl(t1
, t1
, t2
);
1584 tcg_gen_not_tl(t1
, t1
);
1585 tcg_gen_xor_tl(t2
, t0
, t2
);
1586 tcg_gen_and_tl(t1
, t1
, t2
);
1588 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1590 /* operands of same sign, result different sign */
1591 generate_exception(ctx
, EXCP_OVERFLOW
);
1593 gen_store_gpr(t0
, rd
);
1599 if (rs
!= 0 && rt
!= 0) {
1600 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1601 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1602 } else if (rs
== 0 && rt
!= 0) {
1603 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1604 } else if (rs
!= 0 && rt
== 0) {
1605 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1607 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1613 TCGv t0
= tcg_temp_local_new();
1614 TCGv t1
= tcg_temp_new();
1615 TCGv t2
= tcg_temp_new();
1616 int l1
= gen_new_label();
1618 gen_load_gpr(t1
, rs
);
1619 gen_load_gpr(t2
, rt
);
1620 tcg_gen_sub_tl(t0
, t1
, t2
);
1621 tcg_gen_ext32s_tl(t0
, t0
);
1622 tcg_gen_xor_tl(t2
, t1
, t2
);
1623 tcg_gen_xor_tl(t1
, t0
, t1
);
1624 tcg_gen_and_tl(t1
, t1
, t2
);
1626 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1628 /* operands of different sign, first operand and result different sign */
1629 generate_exception(ctx
, EXCP_OVERFLOW
);
1631 gen_store_gpr(t0
, rd
);
1637 if (rs
!= 0 && rt
!= 0) {
1638 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1639 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1640 } else if (rs
== 0 && rt
!= 0) {
1641 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1642 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1643 } else if (rs
!= 0 && rt
== 0) {
1644 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1646 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1650 #if defined(TARGET_MIPS64)
1653 TCGv t0
= tcg_temp_local_new();
1654 TCGv t1
= tcg_temp_new();
1655 TCGv t2
= tcg_temp_new();
1656 int l1
= gen_new_label();
1658 gen_load_gpr(t1
, rs
);
1659 gen_load_gpr(t2
, rt
);
1660 tcg_gen_add_tl(t0
, t1
, t2
);
1661 tcg_gen_xor_tl(t1
, t1
, t2
);
1662 tcg_gen_not_tl(t1
, t1
);
1663 tcg_gen_xor_tl(t2
, t0
, t2
);
1664 tcg_gen_and_tl(t1
, t1
, t2
);
1666 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1668 /* operands of same sign, result different sign */
1669 generate_exception(ctx
, EXCP_OVERFLOW
);
1671 gen_store_gpr(t0
, rd
);
1677 if (rs
!= 0 && rt
!= 0) {
1678 tcg_gen_add_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1679 } else if (rs
== 0 && rt
!= 0) {
1680 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1681 } else if (rs
!= 0 && rt
== 0) {
1682 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1684 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1690 TCGv t0
= tcg_temp_local_new();
1691 TCGv t1
= tcg_temp_new();
1692 TCGv t2
= tcg_temp_new();
1693 int l1
= gen_new_label();
1695 gen_load_gpr(t1
, rs
);
1696 gen_load_gpr(t2
, rt
);
1697 tcg_gen_sub_tl(t0
, t1
, t2
);
1698 tcg_gen_xor_tl(t2
, t1
, t2
);
1699 tcg_gen_xor_tl(t1
, t0
, t1
);
1700 tcg_gen_and_tl(t1
, t1
, t2
);
1702 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
1704 /* operands of different sign, first operand and result different sign */
1705 generate_exception(ctx
, EXCP_OVERFLOW
);
1707 gen_store_gpr(t0
, rd
);
1713 if (rs
!= 0 && rt
!= 0) {
1714 tcg_gen_sub_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1715 } else if (rs
== 0 && rt
!= 0) {
1716 tcg_gen_neg_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1717 } else if (rs
!= 0 && rt
== 0) {
1718 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1720 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1726 if (likely(rs
!= 0 && rt
!= 0)) {
1727 tcg_gen_mul_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1728 tcg_gen_ext32s_tl(cpu_gpr
[rd
], cpu_gpr
[rd
]);
1730 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1735 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1738 /* Conditional move */
1739 static void gen_cond_move (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1741 const char *opn
= "cond move";
1745 /* If no destination, treat it as a NOP.
1746 For add & sub, we must generate the overflow exception when needed. */
1751 l1
= gen_new_label();
1754 if (likely(rt
!= 0))
1755 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rt
], 0, l1
);
1761 if (likely(rt
!= 0))
1762 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rt
], 0, l1
);
1767 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1769 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1772 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1776 static void gen_logic (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1778 const char *opn
= "logic";
1781 /* If no destination, treat it as a NOP. */
1788 if (likely(rs
!= 0 && rt
!= 0)) {
1789 tcg_gen_and_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1791 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1796 if (rs
!= 0 && rt
!= 0) {
1797 tcg_gen_nor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1798 } else if (rs
== 0 && rt
!= 0) {
1799 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1800 } else if (rs
!= 0 && rt
== 0) {
1801 tcg_gen_not_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1803 tcg_gen_movi_tl(cpu_gpr
[rd
], ~((target_ulong
)0));
1808 if (likely(rs
!= 0 && rt
!= 0)) {
1809 tcg_gen_or_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1810 } else if (rs
== 0 && rt
!= 0) {
1811 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1812 } else if (rs
!= 0 && rt
== 0) {
1813 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1815 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1820 if (likely(rs
!= 0 && rt
!= 0)) {
1821 tcg_gen_xor_tl(cpu_gpr
[rd
], cpu_gpr
[rs
], cpu_gpr
[rt
]);
1822 } else if (rs
== 0 && rt
!= 0) {
1823 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rt
]);
1824 } else if (rs
!= 0 && rt
== 0) {
1825 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
1827 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
1832 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1835 /* Set on lower than */
1836 static void gen_slt (CPUState
*env
, uint32_t opc
, int rd
, int rs
, int rt
)
1838 const char *opn
= "slt";
1842 /* If no destination, treat it as a NOP. */
1847 t0
= tcg_temp_new();
1848 t1
= tcg_temp_new();
1849 gen_load_gpr(t0
, rs
);
1850 gen_load_gpr(t1
, rt
);
1853 gen_op_lt(cpu_gpr
[rd
], t0
, t1
);
1857 gen_op_ltu(cpu_gpr
[rd
], t0
, t1
);
1861 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1867 static void gen_shift (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1868 int rd
, int rs
, int rt
)
1870 const char *opn
= "shifts";
1874 /* If no destination, treat it as a NOP.
1875 For add & sub, we must generate the overflow exception when needed. */
1880 t0
= tcg_temp_new();
1881 t1
= tcg_temp_new();
1882 gen_load_gpr(t0
, rs
);
1883 gen_load_gpr(t1
, rt
);
1886 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1887 tcg_gen_shl_tl(t0
, t1
, t0
);
1888 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1892 tcg_gen_ext32s_tl(t1
, t1
);
1893 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1894 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1898 switch ((ctx
->opcode
>> 6) & 0x1f) {
1900 tcg_gen_ext32u_tl(t1
, t1
);
1901 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1902 tcg_gen_shr_tl(t0
, t1
, t0
);
1903 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1907 /* rotrv is decoded as srlv on non-R2 CPUs */
1908 if (env
->insn_flags
& ISA_MIPS32R2
) {
1909 TCGv_i32 t2
= tcg_temp_new_i32();
1910 TCGv_i32 t3
= tcg_temp_new_i32();
1912 tcg_gen_trunc_tl_i32(t2
, t0
);
1913 tcg_gen_trunc_tl_i32(t3
, t1
);
1914 tcg_gen_andi_i32(t2
, t2
, 0x1f);
1915 tcg_gen_rotr_i32(t2
, t3
, t2
);
1916 tcg_gen_ext_i32_tl(cpu_gpr
[rd
], t2
);
1917 tcg_temp_free_i32(t2
);
1918 tcg_temp_free_i32(t3
);
1921 tcg_gen_ext32u_tl(t1
, t1
);
1922 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1923 tcg_gen_shr_tl(t0
, t1
, t0
);
1924 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
1929 MIPS_INVAL("invalid srlv flag");
1930 generate_exception(ctx
, EXCP_RI
);
1934 #if defined(TARGET_MIPS64)
1936 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1937 tcg_gen_shl_tl(cpu_gpr
[rd
], t1
, t0
);
1941 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1942 tcg_gen_sar_tl(cpu_gpr
[rd
], t1
, t0
);
1946 switch ((ctx
->opcode
>> 6) & 0x1f) {
1948 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1949 tcg_gen_shr_tl(cpu_gpr
[rd
], t1
, t0
);
1953 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1954 if (env
->insn_flags
& ISA_MIPS32R2
) {
1955 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1956 tcg_gen_rotr_tl(cpu_gpr
[rd
], t1
, t0
);
1959 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1960 tcg_gen_shr_tl(t0
, t1
, t0
);
1965 MIPS_INVAL("invalid dsrlv flag");
1966 generate_exception(ctx
, EXCP_RI
);
1972 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1977 /* Arithmetic on HI/LO registers */
1978 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1980 const char *opn
= "hilo";
1982 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1989 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1993 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1998 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
2000 tcg_gen_movi_tl(cpu_HI
[0], 0);
2005 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
2007 tcg_gen_movi_tl(cpu_LO
[0], 0);
2011 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
2014 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
2017 const char *opn
= "mul/div";
2023 #if defined(TARGET_MIPS64)
2027 t0
= tcg_temp_local_new();
2028 t1
= tcg_temp_local_new();
2031 t0
= tcg_temp_new();
2032 t1
= tcg_temp_new();
2036 gen_load_gpr(t0
, rs
);
2037 gen_load_gpr(t1
, rt
);
2041 int l1
= gen_new_label();
2042 int l2
= gen_new_label();
2044 tcg_gen_ext32s_tl(t0
, t0
);
2045 tcg_gen_ext32s_tl(t1
, t1
);
2046 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2047 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, INT_MIN
, l2
);
2048 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1, l2
);
2050 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2051 tcg_gen_movi_tl(cpu_HI
[0], 0);
2054 tcg_gen_div_tl(cpu_LO
[0], t0
, t1
);
2055 tcg_gen_rem_tl(cpu_HI
[0], t0
, t1
);
2056 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2057 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2064 int l1
= gen_new_label();
2066 tcg_gen_ext32u_tl(t0
, t0
);
2067 tcg_gen_ext32u_tl(t1
, t1
);
2068 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2069 tcg_gen_divu_tl(cpu_LO
[0], t0
, t1
);
2070 tcg_gen_remu_tl(cpu_HI
[0], t0
, t1
);
2071 tcg_gen_ext32s_tl(cpu_LO
[0], cpu_LO
[0]);
2072 tcg_gen_ext32s_tl(cpu_HI
[0], cpu_HI
[0]);
2079 TCGv_i64 t2
= tcg_temp_new_i64();
2080 TCGv_i64 t3
= tcg_temp_new_i64();
2082 tcg_gen_ext_tl_i64(t2
, t0
);
2083 tcg_gen_ext_tl_i64(t3
, t1
);
2084 tcg_gen_mul_i64(t2
, t2
, t3
);
2085 tcg_temp_free_i64(t3
);
2086 tcg_gen_trunc_i64_tl(t0
, t2
);
2087 tcg_gen_shri_i64(t2
, t2
, 32);
2088 tcg_gen_trunc_i64_tl(t1
, t2
);
2089 tcg_temp_free_i64(t2
);
2090 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2091 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2097 TCGv_i64 t2
= tcg_temp_new_i64();
2098 TCGv_i64 t3
= tcg_temp_new_i64();
2100 tcg_gen_ext32u_tl(t0
, t0
);
2101 tcg_gen_ext32u_tl(t1
, t1
);
2102 tcg_gen_extu_tl_i64(t2
, t0
);
2103 tcg_gen_extu_tl_i64(t3
, t1
);
2104 tcg_gen_mul_i64(t2
, t2
, t3
);
2105 tcg_temp_free_i64(t3
);
2106 tcg_gen_trunc_i64_tl(t0
, t2
);
2107 tcg_gen_shri_i64(t2
, t2
, 32);
2108 tcg_gen_trunc_i64_tl(t1
, t2
);
2109 tcg_temp_free_i64(t2
);
2110 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2111 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2115 #if defined(TARGET_MIPS64)
2118 int l1
= gen_new_label();
2119 int l2
= gen_new_label();
2121 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2122 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
2123 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
2124 tcg_gen_mov_tl(cpu_LO
[0], t0
);
2125 tcg_gen_movi_tl(cpu_HI
[0], 0);
2128 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
2129 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
2136 int l1
= gen_new_label();
2138 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
2139 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
2140 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
2146 gen_helper_dmult(t0
, t1
);
2150 gen_helper_dmultu(t0
, t1
);
2156 TCGv_i64 t2
= tcg_temp_new_i64();
2157 TCGv_i64 t3
= tcg_temp_new_i64();
2159 tcg_gen_ext_tl_i64(t2
, t0
);
2160 tcg_gen_ext_tl_i64(t3
, t1
);
2161 tcg_gen_mul_i64(t2
, t2
, t3
);
2162 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2163 tcg_gen_add_i64(t2
, t2
, t3
);
2164 tcg_temp_free_i64(t3
);
2165 tcg_gen_trunc_i64_tl(t0
, t2
);
2166 tcg_gen_shri_i64(t2
, t2
, 32);
2167 tcg_gen_trunc_i64_tl(t1
, t2
);
2168 tcg_temp_free_i64(t2
);
2169 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2170 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2176 TCGv_i64 t2
= tcg_temp_new_i64();
2177 TCGv_i64 t3
= tcg_temp_new_i64();
2179 tcg_gen_ext32u_tl(t0
, t0
);
2180 tcg_gen_ext32u_tl(t1
, t1
);
2181 tcg_gen_extu_tl_i64(t2
, t0
);
2182 tcg_gen_extu_tl_i64(t3
, t1
);
2183 tcg_gen_mul_i64(t2
, t2
, t3
);
2184 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2185 tcg_gen_add_i64(t2
, t2
, t3
);
2186 tcg_temp_free_i64(t3
);
2187 tcg_gen_trunc_i64_tl(t0
, t2
);
2188 tcg_gen_shri_i64(t2
, t2
, 32);
2189 tcg_gen_trunc_i64_tl(t1
, t2
);
2190 tcg_temp_free_i64(t2
);
2191 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2192 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2198 TCGv_i64 t2
= tcg_temp_new_i64();
2199 TCGv_i64 t3
= tcg_temp_new_i64();
2201 tcg_gen_ext_tl_i64(t2
, t0
);
2202 tcg_gen_ext_tl_i64(t3
, t1
);
2203 tcg_gen_mul_i64(t2
, t2
, t3
);
2204 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2205 tcg_gen_sub_i64(t2
, t3
, t2
);
2206 tcg_temp_free_i64(t3
);
2207 tcg_gen_trunc_i64_tl(t0
, t2
);
2208 tcg_gen_shri_i64(t2
, t2
, 32);
2209 tcg_gen_trunc_i64_tl(t1
, t2
);
2210 tcg_temp_free_i64(t2
);
2211 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2212 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2218 TCGv_i64 t2
= tcg_temp_new_i64();
2219 TCGv_i64 t3
= tcg_temp_new_i64();
2221 tcg_gen_ext32u_tl(t0
, t0
);
2222 tcg_gen_ext32u_tl(t1
, t1
);
2223 tcg_gen_extu_tl_i64(t2
, t0
);
2224 tcg_gen_extu_tl_i64(t3
, t1
);
2225 tcg_gen_mul_i64(t2
, t2
, t3
);
2226 tcg_gen_concat_tl_i64(t3
, cpu_LO
[0], cpu_HI
[0]);
2227 tcg_gen_sub_i64(t2
, t3
, t2
);
2228 tcg_temp_free_i64(t3
);
2229 tcg_gen_trunc_i64_tl(t0
, t2
);
2230 tcg_gen_shri_i64(t2
, t2
, 32);
2231 tcg_gen_trunc_i64_tl(t1
, t2
);
2232 tcg_temp_free_i64(t2
);
2233 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2234 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2240 generate_exception(ctx
, EXCP_RI
);
2243 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2249 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2250 int rd
, int rs
, int rt
)
2252 const char *opn
= "mul vr54xx";
2253 TCGv t0
= tcg_temp_new();
2254 TCGv t1
= tcg_temp_new();
2256 gen_load_gpr(t0
, rs
);
2257 gen_load_gpr(t1
, rt
);
2260 case OPC_VR54XX_MULS
:
2261 gen_helper_muls(t0
, t0
, t1
);
2264 case OPC_VR54XX_MULSU
:
2265 gen_helper_mulsu(t0
, t0
, t1
);
2268 case OPC_VR54XX_MACC
:
2269 gen_helper_macc(t0
, t0
, t1
);
2272 case OPC_VR54XX_MACCU
:
2273 gen_helper_maccu(t0
, t0
, t1
);
2276 case OPC_VR54XX_MSAC
:
2277 gen_helper_msac(t0
, t0
, t1
);
2280 case OPC_VR54XX_MSACU
:
2281 gen_helper_msacu(t0
, t0
, t1
);
2284 case OPC_VR54XX_MULHI
:
2285 gen_helper_mulhi(t0
, t0
, t1
);
2288 case OPC_VR54XX_MULHIU
:
2289 gen_helper_mulhiu(t0
, t0
, t1
);
2292 case OPC_VR54XX_MULSHI
:
2293 gen_helper_mulshi(t0
, t0
, t1
);
2296 case OPC_VR54XX_MULSHIU
:
2297 gen_helper_mulshiu(t0
, t0
, t1
);
2300 case OPC_VR54XX_MACCHI
:
2301 gen_helper_macchi(t0
, t0
, t1
);
2304 case OPC_VR54XX_MACCHIU
:
2305 gen_helper_macchiu(t0
, t0
, t1
);
2308 case OPC_VR54XX_MSACHI
:
2309 gen_helper_msachi(t0
, t0
, t1
);
2312 case OPC_VR54XX_MSACHIU
:
2313 gen_helper_msachiu(t0
, t0
, t1
);
2317 MIPS_INVAL("mul vr54xx");
2318 generate_exception(ctx
, EXCP_RI
);
2321 gen_store_gpr(t0
, rd
);
2322 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2329 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2332 const char *opn
= "CLx";
2340 t0
= tcg_temp_new();
2341 gen_load_gpr(t0
, rs
);
2344 gen_helper_clo(cpu_gpr
[rd
], t0
);
2348 gen_helper_clz(cpu_gpr
[rd
], t0
);
2351 #if defined(TARGET_MIPS64)
2353 gen_helper_dclo(cpu_gpr
[rd
], t0
);
2357 gen_helper_dclz(cpu_gpr
[rd
], t0
);
2362 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2367 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2368 int rs
, int rt
, int16_t imm
)
2371 TCGv t0
= tcg_temp_new();
2372 TCGv t1
= tcg_temp_new();
2375 /* Load needed operands */
2383 /* Compare two registers */
2385 gen_load_gpr(t0
, rs
);
2386 gen_load_gpr(t1
, rt
);
2396 /* Compare register to immediate */
2397 if (rs
!= 0 || imm
!= 0) {
2398 gen_load_gpr(t0
, rs
);
2399 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2406 case OPC_TEQ
: /* rs == rs */
2407 case OPC_TEQI
: /* r0 == 0 */
2408 case OPC_TGE
: /* rs >= rs */
2409 case OPC_TGEI
: /* r0 >= 0 */
2410 case OPC_TGEU
: /* rs >= rs unsigned */
2411 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2413 generate_exception(ctx
, EXCP_TRAP
);
2415 case OPC_TLT
: /* rs < rs */
2416 case OPC_TLTI
: /* r0 < 0 */
2417 case OPC_TLTU
: /* rs < rs unsigned */
2418 case OPC_TLTIU
: /* r0 < 0 unsigned */
2419 case OPC_TNE
: /* rs != rs */
2420 case OPC_TNEI
: /* r0 != 0 */
2421 /* Never trap: treat as NOP. */
2425 int l1
= gen_new_label();
2430 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, t1
, l1
);
2434 tcg_gen_brcond_tl(TCG_COND_LT
, t0
, t1
, l1
);
2438 tcg_gen_brcond_tl(TCG_COND_LTU
, t0
, t1
, l1
);
2442 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
2446 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
2450 tcg_gen_brcond_tl(TCG_COND_EQ
, t0
, t1
, l1
);
2453 generate_exception(ctx
, EXCP_TRAP
);
2460 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2462 TranslationBlock
*tb
;
2464 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2467 tcg_gen_exit_tb((long)tb
+ n
);
2474 /* Branches (before delay slot) */
2475 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2476 int rs
, int rt
, int32_t offset
)
2478 target_ulong btgt
= -1;
2480 int bcond_compute
= 0;
2481 TCGv t0
= tcg_temp_new();
2482 TCGv t1
= tcg_temp_new();
2484 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2485 #ifdef MIPS_DEBUG_DISAS
2486 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2488 generate_exception(ctx
, EXCP_RI
);
2492 /* Load needed operands */
2498 /* Compare two registers */
2500 gen_load_gpr(t0
, rs
);
2501 gen_load_gpr(t1
, rt
);
2504 btgt
= ctx
->pc
+ 4 + offset
;
2518 /* Compare to zero */
2520 gen_load_gpr(t0
, rs
);
2523 btgt
= ctx
->pc
+ 4 + offset
;
2527 /* Jump to immediate */
2528 btgt
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2532 /* Jump to register */
2533 if (offset
!= 0 && offset
!= 16) {
2534 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2535 others are reserved. */
2536 MIPS_INVAL("jump hint");
2537 generate_exception(ctx
, EXCP_RI
);
2540 gen_load_gpr(btarget
, rs
);
2543 MIPS_INVAL("branch/jump");
2544 generate_exception(ctx
, EXCP_RI
);
2547 if (bcond_compute
== 0) {
2548 /* No condition to be computed */
2550 case OPC_BEQ
: /* rx == rx */
2551 case OPC_BEQL
: /* rx == rx likely */
2552 case OPC_BGEZ
: /* 0 >= 0 */
2553 case OPC_BGEZL
: /* 0 >= 0 likely */
2554 case OPC_BLEZ
: /* 0 <= 0 */
2555 case OPC_BLEZL
: /* 0 <= 0 likely */
2557 ctx
->hflags
|= MIPS_HFLAG_B
;
2558 MIPS_DEBUG("balways");
2560 case OPC_BGEZAL
: /* 0 >= 0 */
2561 case OPC_BGEZALL
: /* 0 >= 0 likely */
2562 /* Always take and link */
2564 ctx
->hflags
|= MIPS_HFLAG_B
;
2565 MIPS_DEBUG("balways and link");
2567 case OPC_BNE
: /* rx != rx */
2568 case OPC_BGTZ
: /* 0 > 0 */
2569 case OPC_BLTZ
: /* 0 < 0 */
2571 MIPS_DEBUG("bnever (NOP)");
2573 case OPC_BLTZAL
: /* 0 < 0 */
2574 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2575 MIPS_DEBUG("bnever and link");
2577 case OPC_BLTZALL
: /* 0 < 0 likely */
2578 tcg_gen_movi_tl(cpu_gpr
[31], ctx
->pc
+ 8);
2579 /* Skip the instruction in the delay slot */
2580 MIPS_DEBUG("bnever, link and skip");
2583 case OPC_BNEL
: /* rx != rx likely */
2584 case OPC_BGTZL
: /* 0 > 0 likely */
2585 case OPC_BLTZL
: /* 0 < 0 likely */
2586 /* Skip the instruction in the delay slot */
2587 MIPS_DEBUG("bnever and skip");
2591 ctx
->hflags
|= MIPS_HFLAG_B
;
2592 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2596 ctx
->hflags
|= MIPS_HFLAG_B
;
2597 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2600 ctx
->hflags
|= MIPS_HFLAG_BR
;
2601 MIPS_DEBUG("jr %s", regnames
[rs
]);
2605 ctx
->hflags
|= MIPS_HFLAG_BR
;
2606 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2609 MIPS_INVAL("branch/jump");
2610 generate_exception(ctx
, EXCP_RI
);
2616 gen_op_eq(bcond
, t0
, t1
);
2617 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2618 regnames
[rs
], regnames
[rt
], btgt
);
2621 gen_op_eq(bcond
, t0
, t1
);
2622 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2623 regnames
[rs
], regnames
[rt
], btgt
);
2626 gen_op_ne(bcond
, t0
, t1
);
2627 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2628 regnames
[rs
], regnames
[rt
], btgt
);
2631 gen_op_ne(bcond
, t0
, t1
);
2632 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2633 regnames
[rs
], regnames
[rt
], btgt
);
2636 gen_op_gez(bcond
, t0
);
2637 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2640 gen_op_gez(bcond
, t0
);
2641 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2644 gen_op_gez(bcond
, t0
);
2645 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2649 gen_op_gez(bcond
, t0
);
2651 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2654 gen_op_gtz(bcond
, t0
);
2655 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2658 gen_op_gtz(bcond
, t0
);
2659 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2662 gen_op_lez(bcond
, t0
);
2663 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2666 gen_op_lez(bcond
, t0
);
2667 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2670 gen_op_ltz(bcond
, t0
);
2671 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2674 gen_op_ltz(bcond
, t0
);
2675 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2678 gen_op_ltz(bcond
, t0
);
2680 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2682 ctx
->hflags
|= MIPS_HFLAG_BC
;
2685 gen_op_ltz(bcond
, t0
);
2687 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2689 ctx
->hflags
|= MIPS_HFLAG_BL
;
2692 MIPS_INVAL("conditional branch/jump");
2693 generate_exception(ctx
, EXCP_RI
);
2697 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2698 blink
, ctx
->hflags
, btgt
);
2700 ctx
->btarget
= btgt
;
2702 tcg_gen_movi_tl(cpu_gpr
[blink
], ctx
->pc
+ 8);
2710 /* special3 bitfield operations */
2711 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2712 int rs
, int lsb
, int msb
)
2714 TCGv t0
= tcg_temp_new();
2715 TCGv t1
= tcg_temp_new();
2718 gen_load_gpr(t1
, rs
);
2723 tcg_gen_shri_tl(t0
, t1
, lsb
);
2725 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2727 tcg_gen_ext32s_tl(t0
, t0
);
2730 #if defined(TARGET_MIPS64)
2732 tcg_gen_shri_tl(t0
, t1
, lsb
);
2734 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2738 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2739 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2742 tcg_gen_shri_tl(t0
, t1
, lsb
);
2743 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2749 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2750 gen_load_gpr(t0
, rt
);
2751 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2752 tcg_gen_shli_tl(t1
, t1
, lsb
);
2753 tcg_gen_andi_tl(t1
, t1
, mask
);
2754 tcg_gen_or_tl(t0
, t0
, t1
);
2755 tcg_gen_ext32s_tl(t0
, t0
);
2757 #if defined(TARGET_MIPS64)
2761 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2762 gen_load_gpr(t0
, rt
);
2763 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2764 tcg_gen_shli_tl(t1
, t1
, lsb
);
2765 tcg_gen_andi_tl(t1
, t1
, mask
);
2766 tcg_gen_or_tl(t0
, t0
, t1
);
2771 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2772 gen_load_gpr(t0
, rt
);
2773 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2774 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2775 tcg_gen_andi_tl(t1
, t1
, mask
);
2776 tcg_gen_or_tl(t0
, t0
, t1
);
2781 gen_load_gpr(t0
, rt
);
2782 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2783 gen_load_gpr(t0
, rt
);
2784 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2785 tcg_gen_shli_tl(t1
, t1
, lsb
);
2786 tcg_gen_andi_tl(t1
, t1
, mask
);
2787 tcg_gen_or_tl(t0
, t0
, t1
);
2792 MIPS_INVAL("bitops");
2793 generate_exception(ctx
, EXCP_RI
);
2798 gen_store_gpr(t0
, rt
);
2803 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2808 /* If no destination, treat it as a NOP. */
2813 t0
= tcg_temp_new();
2814 gen_load_gpr(t0
, rt
);
2818 TCGv t1
= tcg_temp_new();
2820 tcg_gen_shri_tl(t1
, t0
, 8);
2821 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF);
2822 tcg_gen_shli_tl(t0
, t0
, 8);
2823 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF);
2824 tcg_gen_or_tl(t0
, t0
, t1
);
2826 tcg_gen_ext32s_tl(cpu_gpr
[rd
], t0
);
2830 tcg_gen_ext8s_tl(cpu_gpr
[rd
], t0
);
2833 tcg_gen_ext16s_tl(cpu_gpr
[rd
], t0
);
2835 #if defined(TARGET_MIPS64)
2838 TCGv t1
= tcg_temp_new();
2840 tcg_gen_shri_tl(t1
, t0
, 8);
2841 tcg_gen_andi_tl(t1
, t1
, 0x00FF00FF00FF00FFULL
);
2842 tcg_gen_shli_tl(t0
, t0
, 8);
2843 tcg_gen_andi_tl(t0
, t0
, ~0x00FF00FF00FF00FFULL
);
2844 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2850 TCGv t1
= tcg_temp_new();
2852 tcg_gen_shri_tl(t1
, t0
, 16);
2853 tcg_gen_andi_tl(t1
, t1
, 0x0000FFFF0000FFFFULL
);
2854 tcg_gen_shli_tl(t0
, t0
, 16);
2855 tcg_gen_andi_tl(t0
, t0
, ~0x0000FFFF0000FFFFULL
);
2856 tcg_gen_or_tl(t0
, t0
, t1
);
2857 tcg_gen_shri_tl(t1
, t0
, 32);
2858 tcg_gen_shli_tl(t0
, t0
, 32);
2859 tcg_gen_or_tl(cpu_gpr
[rd
], t0
, t1
);
2865 MIPS_INVAL("bsfhl");
2866 generate_exception(ctx
, EXCP_RI
);
2873 #ifndef CONFIG_USER_ONLY
2874 /* CP0 (MMU and control) */
2875 static inline void gen_mfc0_load32 (TCGv arg
, target_ulong off
)
2877 TCGv_i32 t0
= tcg_temp_new_i32();
2879 tcg_gen_ld_i32(t0
, cpu_env
, off
);
2880 tcg_gen_ext_i32_tl(arg
, t0
);
2881 tcg_temp_free_i32(t0
);
2884 static inline void gen_mfc0_load64 (TCGv arg
, target_ulong off
)
2886 tcg_gen_ld_tl(arg
, cpu_env
, off
);
2887 tcg_gen_ext32s_tl(arg
, arg
);
2890 static inline void gen_mtc0_store32 (TCGv arg
, target_ulong off
)
2892 TCGv_i32 t0
= tcg_temp_new_i32();
2894 tcg_gen_trunc_tl_i32(t0
, arg
);
2895 tcg_gen_st_i32(t0
, cpu_env
, off
);
2896 tcg_temp_free_i32(t0
);
2899 static inline void gen_mtc0_store64 (TCGv arg
, target_ulong off
)
2901 tcg_gen_ext32s_tl(arg
, arg
);
2902 tcg_gen_st_tl(arg
, cpu_env
, off
);
2905 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
2907 const char *rn
= "invalid";
2910 check_insn(env
, ctx
, ISA_MIPS32
);
2916 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
2920 check_insn(env
, ctx
, ASE_MT
);
2921 gen_helper_mfc0_mvpcontrol(arg
);
2925 check_insn(env
, ctx
, ASE_MT
);
2926 gen_helper_mfc0_mvpconf0(arg
);
2930 check_insn(env
, ctx
, ASE_MT
);
2931 gen_helper_mfc0_mvpconf1(arg
);
2941 gen_helper_mfc0_random(arg
);
2945 check_insn(env
, ctx
, ASE_MT
);
2946 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
2950 check_insn(env
, ctx
, ASE_MT
);
2951 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
2955 check_insn(env
, ctx
, ASE_MT
);
2956 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
2960 check_insn(env
, ctx
, ASE_MT
);
2961 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_YQMask
));
2965 check_insn(env
, ctx
, ASE_MT
);
2966 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
2970 check_insn(env
, ctx
, ASE_MT
);
2971 gen_mfc0_load64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
2972 rn
= "VPEScheFBack";
2975 check_insn(env
, ctx
, ASE_MT
);
2976 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
2986 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2987 tcg_gen_ext32s_tl(arg
, arg
);
2991 check_insn(env
, ctx
, ASE_MT
);
2992 gen_helper_mfc0_tcstatus(arg
);
2996 check_insn(env
, ctx
, ASE_MT
);
2997 gen_helper_mfc0_tcbind(arg
);
3001 check_insn(env
, ctx
, ASE_MT
);
3002 gen_helper_mfc0_tcrestart(arg
);
3006 check_insn(env
, ctx
, ASE_MT
);
3007 gen_helper_mfc0_tchalt(arg
);
3011 check_insn(env
, ctx
, ASE_MT
);
3012 gen_helper_mfc0_tccontext(arg
);
3016 check_insn(env
, ctx
, ASE_MT
);
3017 gen_helper_mfc0_tcschedule(arg
);
3021 check_insn(env
, ctx
, ASE_MT
);
3022 gen_helper_mfc0_tcschefback(arg
);
3032 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
3033 tcg_gen_ext32s_tl(arg
, arg
);
3043 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
3044 tcg_gen_ext32s_tl(arg
, arg
);
3048 // gen_helper_mfc0_contextconfig(arg); /* SmartMIPS ASE */
3049 rn
= "ContextConfig";
3058 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
3062 check_insn(env
, ctx
, ISA_MIPS32R2
);
3063 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
3073 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
3077 check_insn(env
, ctx
, ISA_MIPS32R2
);
3078 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
3082 check_insn(env
, ctx
, ISA_MIPS32R2
);
3083 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
3087 check_insn(env
, ctx
, ISA_MIPS32R2
);
3088 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
3092 check_insn(env
, ctx
, ISA_MIPS32R2
);
3093 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
3097 check_insn(env
, ctx
, ISA_MIPS32R2
);
3098 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
3108 check_insn(env
, ctx
, ISA_MIPS32R2
);
3109 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
3119 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
3120 tcg_gen_ext32s_tl(arg
, arg
);
3130 /* Mark as an IO operation because we read the time. */
3133 gen_helper_mfc0_count(arg
);
3136 ctx
->bstate
= BS_STOP
;
3140 /* 6,7 are implementation dependent */
3148 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
3149 tcg_gen_ext32s_tl(arg
, arg
);
3159 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
3162 /* 6,7 are implementation dependent */
3170 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
3174 check_insn(env
, ctx
, ISA_MIPS32R2
);
3175 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
3179 check_insn(env
, ctx
, ISA_MIPS32R2
);
3180 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
3184 check_insn(env
, ctx
, ISA_MIPS32R2
);
3185 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3195 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
3205 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3206 tcg_gen_ext32s_tl(arg
, arg
);
3216 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
3220 check_insn(env
, ctx
, ISA_MIPS32R2
);
3221 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
3231 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
3235 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
3239 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
3243 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
3246 /* 4,5 are reserved */
3247 /* 6,7 are implementation dependent */
3249 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
3253 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
3263 gen_helper_mfc0_lladdr(arg
);
3273 gen_helper_1i(mfc0_watchlo
, arg
, sel
);
3283 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
3293 #if defined(TARGET_MIPS64)
3294 check_insn(env
, ctx
, ISA_MIPS3
);
3295 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3296 tcg_gen_ext32s_tl(arg
, arg
);
3305 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3308 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
3316 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3317 rn
= "'Diagnostic"; /* implementation dependent */
3322 gen_helper_mfc0_debug(arg
); /* EJTAG support */
3326 // gen_helper_mfc0_tracecontrol(arg); /* PDtrace support */
3327 rn
= "TraceControl";
3330 // gen_helper_mfc0_tracecontrol2(arg); /* PDtrace support */
3331 rn
= "TraceControl2";
3334 // gen_helper_mfc0_usertracedata(arg); /* PDtrace support */
3335 rn
= "UserTraceData";
3338 // gen_helper_mfc0_tracebpc(arg); /* PDtrace support */
3349 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3350 tcg_gen_ext32s_tl(arg
, arg
);
3360 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
3361 rn
= "Performance0";
3364 // gen_helper_mfc0_performance1(arg);
3365 rn
= "Performance1";
3368 // gen_helper_mfc0_performance2(arg);
3369 rn
= "Performance2";
3372 // gen_helper_mfc0_performance3(arg);
3373 rn
= "Performance3";
3376 // gen_helper_mfc0_performance4(arg);
3377 rn
= "Performance4";
3380 // gen_helper_mfc0_performance5(arg);
3381 rn
= "Performance5";
3384 // gen_helper_mfc0_performance6(arg);
3385 rn
= "Performance6";
3388 // gen_helper_mfc0_performance7(arg);
3389 rn
= "Performance7";
3396 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3402 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
3415 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
3422 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
3435 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
3442 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
3452 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3453 tcg_gen_ext32s_tl(arg
, arg
);
3464 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
3474 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3478 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3479 generate_exception(ctx
, EXCP_RI
);
3482 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
3484 const char *rn
= "invalid";
3487 check_insn(env
, ctx
, ISA_MIPS32
);
3496 gen_helper_mtc0_index(arg
);
3500 check_insn(env
, ctx
, ASE_MT
);
3501 gen_helper_mtc0_mvpcontrol(arg
);
3505 check_insn(env
, ctx
, ASE_MT
);
3510 check_insn(env
, ctx
, ASE_MT
);
3525 check_insn(env
, ctx
, ASE_MT
);
3526 gen_helper_mtc0_vpecontrol(arg
);
3530 check_insn(env
, ctx
, ASE_MT
);
3531 gen_helper_mtc0_vpeconf0(arg
);
3535 check_insn(env
, ctx
, ASE_MT
);
3536 gen_helper_mtc0_vpeconf1(arg
);
3540 check_insn(env
, ctx
, ASE_MT
);
3541 gen_helper_mtc0_yqmask(arg
);
3545 check_insn(env
, ctx
, ASE_MT
);
3546 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPESchedule
));
3550 check_insn(env
, ctx
, ASE_MT
);
3551 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_VPEScheFBack
));
3552 rn
= "VPEScheFBack";
3555 check_insn(env
, ctx
, ASE_MT
);
3556 gen_helper_mtc0_vpeopt(arg
);
3566 gen_helper_mtc0_entrylo0(arg
);
3570 check_insn(env
, ctx
, ASE_MT
);
3571 gen_helper_mtc0_tcstatus(arg
);
3575 check_insn(env
, ctx
, ASE_MT
);
3576 gen_helper_mtc0_tcbind(arg
);
3580 check_insn(env
, ctx
, ASE_MT
);
3581 gen_helper_mtc0_tcrestart(arg
);
3585 check_insn(env
, ctx
, ASE_MT
);
3586 gen_helper_mtc0_tchalt(arg
);
3590 check_insn(env
, ctx
, ASE_MT
);
3591 gen_helper_mtc0_tccontext(arg
);
3595 check_insn(env
, ctx
, ASE_MT
);
3596 gen_helper_mtc0_tcschedule(arg
);
3600 check_insn(env
, ctx
, ASE_MT
);
3601 gen_helper_mtc0_tcschefback(arg
);
3611 gen_helper_mtc0_entrylo1(arg
);
3621 gen_helper_mtc0_context(arg
);
3625 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
3626 rn
= "ContextConfig";
3635 gen_helper_mtc0_pagemask(arg
);
3639 check_insn(env
, ctx
, ISA_MIPS32R2
);
3640 gen_helper_mtc0_pagegrain(arg
);
3650 gen_helper_mtc0_wired(arg
);
3654 check_insn(env
, ctx
, ISA_MIPS32R2
);
3655 gen_helper_mtc0_srsconf0(arg
);
3659 check_insn(env
, ctx
, ISA_MIPS32R2
);
3660 gen_helper_mtc0_srsconf1(arg
);
3664 check_insn(env
, ctx
, ISA_MIPS32R2
);
3665 gen_helper_mtc0_srsconf2(arg
);
3669 check_insn(env
, ctx
, ISA_MIPS32R2
);
3670 gen_helper_mtc0_srsconf3(arg
);
3674 check_insn(env
, ctx
, ISA_MIPS32R2
);
3675 gen_helper_mtc0_srsconf4(arg
);
3685 check_insn(env
, ctx
, ISA_MIPS32R2
);
3686 gen_helper_mtc0_hwrena(arg
);
3700 gen_helper_mtc0_count(arg
);
3703 /* 6,7 are implementation dependent */
3711 gen_helper_mtc0_entryhi(arg
);
3721 gen_helper_mtc0_compare(arg
);
3724 /* 6,7 are implementation dependent */
3732 save_cpu_state(ctx
, 1);
3733 gen_helper_mtc0_status(arg
);
3734 /* BS_STOP isn't good enough here, hflags may have changed. */
3735 gen_save_pc(ctx
->pc
+ 4);
3736 ctx
->bstate
= BS_EXCP
;
3740 check_insn(env
, ctx
, ISA_MIPS32R2
);
3741 gen_helper_mtc0_intctl(arg
);
3742 /* Stop translation as we may have switched the execution mode */
3743 ctx
->bstate
= BS_STOP
;
3747 check_insn(env
, ctx
, ISA_MIPS32R2
);
3748 gen_helper_mtc0_srsctl(arg
);
3749 /* Stop translation as we may have switched the execution mode */
3750 ctx
->bstate
= BS_STOP
;
3754 check_insn(env
, ctx
, ISA_MIPS32R2
);
3755 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
3756 /* Stop translation as we may have switched the execution mode */
3757 ctx
->bstate
= BS_STOP
;
3767 save_cpu_state(ctx
, 1);
3768 gen_helper_mtc0_cause(arg
);
3778 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_EPC
));
3792 check_insn(env
, ctx
, ISA_MIPS32R2
);
3793 gen_helper_mtc0_ebase(arg
);
3803 gen_helper_mtc0_config0(arg
);
3805 /* Stop translation as we may have switched the execution mode */
3806 ctx
->bstate
= BS_STOP
;
3809 /* ignored, read only */
3813 gen_helper_mtc0_config2(arg
);
3815 /* Stop translation as we may have switched the execution mode */
3816 ctx
->bstate
= BS_STOP
;
3819 /* ignored, read only */
3822 /* 4,5 are reserved */
3823 /* 6,7 are implementation dependent */
3833 rn
= "Invalid config selector";
3850 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
3860 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
3870 #if defined(TARGET_MIPS64)
3871 check_insn(env
, ctx
, ISA_MIPS3
);
3872 gen_helper_mtc0_xcontext(arg
);
3881 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3884 gen_helper_mtc0_framemask(arg
);
3893 rn
= "Diagnostic"; /* implementation dependent */
3898 gen_helper_mtc0_debug(arg
); /* EJTAG support */
3899 /* BS_STOP isn't good enough here, hflags may have changed. */
3900 gen_save_pc(ctx
->pc
+ 4);
3901 ctx
->bstate
= BS_EXCP
;
3905 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
3906 rn
= "TraceControl";
3907 /* Stop translation as we may have switched the execution mode */
3908 ctx
->bstate
= BS_STOP
;
3911 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
3912 rn
= "TraceControl2";
3913 /* Stop translation as we may have switched the execution mode */
3914 ctx
->bstate
= BS_STOP
;
3917 /* Stop translation as we may have switched the execution mode */
3918 ctx
->bstate
= BS_STOP
;
3919 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
3920 rn
= "UserTraceData";
3921 /* Stop translation as we may have switched the execution mode */
3922 ctx
->bstate
= BS_STOP
;
3925 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
3926 /* Stop translation as we may have switched the execution mode */
3927 ctx
->bstate
= BS_STOP
;
3938 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_DEPC
));
3948 gen_helper_mtc0_performance0(arg
);
3949 rn
= "Performance0";
3952 // gen_helper_mtc0_performance1(arg);
3953 rn
= "Performance1";
3956 // gen_helper_mtc0_performance2(arg);
3957 rn
= "Performance2";
3960 // gen_helper_mtc0_performance3(arg);
3961 rn
= "Performance3";
3964 // gen_helper_mtc0_performance4(arg);
3965 rn
= "Performance4";
3968 // gen_helper_mtc0_performance5(arg);
3969 rn
= "Performance5";
3972 // gen_helper_mtc0_performance6(arg);
3973 rn
= "Performance6";
3976 // gen_helper_mtc0_performance7(arg);
3977 rn
= "Performance7";
4003 gen_helper_mtc0_taglo(arg
);
4010 gen_helper_mtc0_datalo(arg
);
4023 gen_helper_mtc0_taghi(arg
);
4030 gen_helper_mtc0_datahi(arg
);
4041 gen_mtc0_store64(arg
, offsetof(CPUState
, CP0_ErrorEPC
));
4052 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4058 /* Stop translation as we may have switched the execution mode */
4059 ctx
->bstate
= BS_STOP
;
4064 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4065 /* For simplicity assume that all writes can cause interrupts. */
4068 ctx
->bstate
= BS_STOP
;
4073 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4074 generate_exception(ctx
, EXCP_RI
);
4077 #if defined(TARGET_MIPS64)
4078 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4080 const char *rn
= "invalid";
4083 check_insn(env
, ctx
, ISA_MIPS64
);
4089 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Index
));
4093 check_insn(env
, ctx
, ASE_MT
);
4094 gen_helper_mfc0_mvpcontrol(arg
);
4098 check_insn(env
, ctx
, ASE_MT
);
4099 gen_helper_mfc0_mvpconf0(arg
);
4103 check_insn(env
, ctx
, ASE_MT
);
4104 gen_helper_mfc0_mvpconf1(arg
);
4114 gen_helper_mfc0_random(arg
);
4118 check_insn(env
, ctx
, ASE_MT
);
4119 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEControl
));
4123 check_insn(env
, ctx
, ASE_MT
);
4124 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf0
));
4128 check_insn(env
, ctx
, ASE_MT
);
4129 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEConf1
));
4133 check_insn(env
, ctx
, ASE_MT
);
4134 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
4138 check_insn(env
, ctx
, ASE_MT
);
4139 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4143 check_insn(env
, ctx
, ASE_MT
);
4144 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4145 rn
= "VPEScheFBack";
4148 check_insn(env
, ctx
, ASE_MT
);
4149 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_VPEOpt
));
4159 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
4163 check_insn(env
, ctx
, ASE_MT
);
4164 gen_helper_mfc0_tcstatus(arg
);
4168 check_insn(env
, ctx
, ASE_MT
);
4169 gen_helper_mfc0_tcbind(arg
);
4173 check_insn(env
, ctx
, ASE_MT
);
4174 gen_helper_dmfc0_tcrestart(arg
);
4178 check_insn(env
, ctx
, ASE_MT
);
4179 gen_helper_dmfc0_tchalt(arg
);
4183 check_insn(env
, ctx
, ASE_MT
);
4184 gen_helper_dmfc0_tccontext(arg
);
4188 check_insn(env
, ctx
, ASE_MT
);
4189 gen_helper_dmfc0_tcschedule(arg
);
4193 check_insn(env
, ctx
, ASE_MT
);
4194 gen_helper_dmfc0_tcschefback(arg
);
4204 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4214 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4218 // gen_helper_dmfc0_contextconfig(arg); /* SmartMIPS ASE */
4219 rn
= "ContextConfig";
4228 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageMask
));
4232 check_insn(env
, ctx
, ISA_MIPS32R2
);
4233 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PageGrain
));
4243 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Wired
));
4247 check_insn(env
, ctx
, ISA_MIPS32R2
);
4248 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf0
));
4252 check_insn(env
, ctx
, ISA_MIPS32R2
);
4253 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf1
));
4257 check_insn(env
, ctx
, ISA_MIPS32R2
);
4258 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf2
));
4262 check_insn(env
, ctx
, ISA_MIPS32R2
);
4263 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf3
));
4267 check_insn(env
, ctx
, ISA_MIPS32R2
);
4268 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSConf4
));
4278 check_insn(env
, ctx
, ISA_MIPS32R2
);
4279 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_HWREna
));
4289 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4299 /* Mark as an IO operation because we read the time. */
4302 gen_helper_mfc0_count(arg
);
4305 ctx
->bstate
= BS_STOP
;
4309 /* 6,7 are implementation dependent */
4317 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4327 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Compare
));
4330 /* 6,7 are implementation dependent */
4338 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Status
));
4342 check_insn(env
, ctx
, ISA_MIPS32R2
);
4343 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_IntCtl
));
4347 check_insn(env
, ctx
, ISA_MIPS32R2
);
4348 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSCtl
));
4352 check_insn(env
, ctx
, ISA_MIPS32R2
);
4353 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4363 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Cause
));
4373 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4383 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_PRid
));
4387 check_insn(env
, ctx
, ISA_MIPS32R2
);
4388 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_EBase
));
4398 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config0
));
4402 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config1
));
4406 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config2
));
4410 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config3
));
4413 /* 6,7 are implementation dependent */
4415 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config6
));
4419 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Config7
));
4429 gen_helper_dmfc0_lladdr(arg
);
4439 gen_helper_1i(dmfc0_watchlo
, arg
, sel
);
4449 gen_helper_1i(mfc0_watchhi
, arg
, sel
);
4459 check_insn(env
, ctx
, ISA_MIPS3
);
4460 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4468 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4471 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Framemask
));
4479 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4480 rn
= "'Diagnostic"; /* implementation dependent */
4485 gen_helper_mfc0_debug(arg
); /* EJTAG support */
4489 // gen_helper_dmfc0_tracecontrol(arg); /* PDtrace support */
4490 rn
= "TraceControl";
4493 // gen_helper_dmfc0_tracecontrol2(arg); /* PDtrace support */
4494 rn
= "TraceControl2";
4497 // gen_helper_dmfc0_usertracedata(arg); /* PDtrace support */
4498 rn
= "UserTraceData";
4501 // gen_helper_dmfc0_tracebpc(arg); /* PDtrace support */
4512 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4522 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_Performance0
));
4523 rn
= "Performance0";
4526 // gen_helper_dmfc0_performance1(arg);
4527 rn
= "Performance1";
4530 // gen_helper_dmfc0_performance2(arg);
4531 rn
= "Performance2";
4534 // gen_helper_dmfc0_performance3(arg);
4535 rn
= "Performance3";
4538 // gen_helper_dmfc0_performance4(arg);
4539 rn
= "Performance4";
4542 // gen_helper_dmfc0_performance5(arg);
4543 rn
= "Performance5";
4546 // gen_helper_dmfc0_performance6(arg);
4547 rn
= "Performance6";
4550 // gen_helper_dmfc0_performance7(arg);
4551 rn
= "Performance7";
4558 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4565 tcg_gen_movi_tl(arg
, 0); /* unimplemented */
4578 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagLo
));
4585 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataLo
));
4598 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_TagHi
));
4605 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DataHi
));
4615 tcg_gen_ld_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4626 gen_mfc0_load32(arg
, offsetof(CPUState
, CP0_DESAVE
));
4636 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4640 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4641 generate_exception(ctx
, EXCP_RI
);
4644 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv arg
, int reg
, int sel
)
4646 const char *rn
= "invalid";
4649 check_insn(env
, ctx
, ISA_MIPS64
);
4658 gen_helper_mtc0_index(arg
);
4662 check_insn(env
, ctx
, ASE_MT
);
4663 gen_helper_mtc0_mvpcontrol(arg
);
4667 check_insn(env
, ctx
, ASE_MT
);
4672 check_insn(env
, ctx
, ASE_MT
);
4687 check_insn(env
, ctx
, ASE_MT
);
4688 gen_helper_mtc0_vpecontrol(arg
);
4692 check_insn(env
, ctx
, ASE_MT
);
4693 gen_helper_mtc0_vpeconf0(arg
);
4697 check_insn(env
, ctx
, ASE_MT
);
4698 gen_helper_mtc0_vpeconf1(arg
);
4702 check_insn(env
, ctx
, ASE_MT
);
4703 gen_helper_mtc0_yqmask(arg
);
4707 check_insn(env
, ctx
, ASE_MT
);
4708 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4712 check_insn(env
, ctx
, ASE_MT
);
4713 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4714 rn
= "VPEScheFBack";
4717 check_insn(env
, ctx
, ASE_MT
);
4718 gen_helper_mtc0_vpeopt(arg
);
4728 gen_helper_mtc0_entrylo0(arg
);
4732 check_insn(env
, ctx
, ASE_MT
);
4733 gen_helper_mtc0_tcstatus(arg
);
4737 check_insn(env
, ctx
, ASE_MT
);
4738 gen_helper_mtc0_tcbind(arg
);
4742 check_insn(env
, ctx
, ASE_MT
);
4743 gen_helper_mtc0_tcrestart(arg
);
4747 check_insn(env
, ctx
, ASE_MT
);
4748 gen_helper_mtc0_tchalt(arg
);
4752 check_insn(env
, ctx
, ASE_MT
);
4753 gen_helper_mtc0_tccontext(arg
);
4757 check_insn(env
, ctx
, ASE_MT
);
4758 gen_helper_mtc0_tcschedule(arg
);
4762 check_insn(env
, ctx
, ASE_MT
);
4763 gen_helper_mtc0_tcschefback(arg
);
4773 gen_helper_mtc0_entrylo1(arg
);
4783 gen_helper_mtc0_context(arg
);
4787 // gen_helper_mtc0_contextconfig(arg); /* SmartMIPS ASE */
4788 rn
= "ContextConfig";
4797 gen_helper_mtc0_pagemask(arg
);
4801 check_insn(env
, ctx
, ISA_MIPS32R2
);
4802 gen_helper_mtc0_pagegrain(arg
);
4812 gen_helper_mtc0_wired(arg
);
4816 check_insn(env
, ctx
, ISA_MIPS32R2
);
4817 gen_helper_mtc0_srsconf0(arg
);
4821 check_insn(env
, ctx
, ISA_MIPS32R2
);
4822 gen_helper_mtc0_srsconf1(arg
);
4826 check_insn(env
, ctx
, ISA_MIPS32R2
);
4827 gen_helper_mtc0_srsconf2(arg
);
4831 check_insn(env
, ctx
, ISA_MIPS32R2
);
4832 gen_helper_mtc0_srsconf3(arg
);
4836 check_insn(env
, ctx
, ISA_MIPS32R2
);
4837 gen_helper_mtc0_srsconf4(arg
);
4847 check_insn(env
, ctx
, ISA_MIPS32R2
);
4848 gen_helper_mtc0_hwrena(arg
);
4862 gen_helper_mtc0_count(arg
);
4865 /* 6,7 are implementation dependent */
4869 /* Stop translation as we may have switched the execution mode */
4870 ctx
->bstate
= BS_STOP
;
4875 gen_helper_mtc0_entryhi(arg
);
4885 gen_helper_mtc0_compare(arg
);
4888 /* 6,7 are implementation dependent */
4892 /* Stop translation as we may have switched the execution mode */
4893 ctx
->bstate
= BS_STOP
;
4898 save_cpu_state(ctx
, 1);
4899 gen_helper_mtc0_status(arg
);
4900 /* BS_STOP isn't good enough here, hflags may have changed. */
4901 gen_save_pc(ctx
->pc
+ 4);
4902 ctx
->bstate
= BS_EXCP
;
4906 check_insn(env
, ctx
, ISA_MIPS32R2
);
4907 gen_helper_mtc0_intctl(arg
);
4908 /* Stop translation as we may have switched the execution mode */
4909 ctx
->bstate
= BS_STOP
;
4913 check_insn(env
, ctx
, ISA_MIPS32R2
);
4914 gen_helper_mtc0_srsctl(arg
);
4915 /* Stop translation as we may have switched the execution mode */
4916 ctx
->bstate
= BS_STOP
;
4920 check_insn(env
, ctx
, ISA_MIPS32R2
);
4921 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_SRSMap
));
4922 /* Stop translation as we may have switched the execution mode */
4923 ctx
->bstate
= BS_STOP
;
4933 save_cpu_state(ctx
, 1);
4934 gen_helper_mtc0_cause(arg
);
4944 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4958 check_insn(env
, ctx
, ISA_MIPS32R2
);
4959 gen_helper_mtc0_ebase(arg
);
4969 gen_helper_mtc0_config0(arg
);
4971 /* Stop translation as we may have switched the execution mode */
4972 ctx
->bstate
= BS_STOP
;
4975 /* ignored, read only */
4979 gen_helper_mtc0_config2(arg
);
4981 /* Stop translation as we may have switched the execution mode */
4982 ctx
->bstate
= BS_STOP
;
4988 /* 6,7 are implementation dependent */
4990 rn
= "Invalid config selector";
5007 gen_helper_1i(mtc0_watchlo
, arg
, sel
);
5017 gen_helper_1i(mtc0_watchhi
, arg
, sel
);
5027 check_insn(env
, ctx
, ISA_MIPS3
);
5028 gen_helper_mtc0_xcontext(arg
);
5036 /* Officially reserved, but sel 0 is used for R1x000 framemask */
5039 gen_helper_mtc0_framemask(arg
);
5048 rn
= "Diagnostic"; /* implementation dependent */
5053 gen_helper_mtc0_debug(arg
); /* EJTAG support */
5054 /* BS_STOP isn't good enough here, hflags may have changed. */
5055 gen_save_pc(ctx
->pc
+ 4);
5056 ctx
->bstate
= BS_EXCP
;
5060 // gen_helper_mtc0_tracecontrol(arg); /* PDtrace support */
5061 /* Stop translation as we may have switched the execution mode */
5062 ctx
->bstate
= BS_STOP
;
5063 rn
= "TraceControl";
5066 // gen_helper_mtc0_tracecontrol2(arg); /* PDtrace support */
5067 /* Stop translation as we may have switched the execution mode */
5068 ctx
->bstate
= BS_STOP
;
5069 rn
= "TraceControl2";
5072 // gen_helper_mtc0_usertracedata(arg); /* PDtrace support */
5073 /* Stop translation as we may have switched the execution mode */
5074 ctx
->bstate
= BS_STOP
;
5075 rn
= "UserTraceData";
5078 // gen_helper_mtc0_tracebpc(arg); /* PDtrace support */
5079 /* Stop translation as we may have switched the execution mode */
5080 ctx
->bstate
= BS_STOP
;
5091 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
5101 gen_helper_mtc0_performance0(arg
);
5102 rn
= "Performance0";
5105 // gen_helper_mtc0_performance1(arg);
5106 rn
= "Performance1";
5109 // gen_helper_mtc0_performance2(arg);
5110 rn
= "Performance2";
5113 // gen_helper_mtc0_performance3(arg);
5114 rn
= "Performance3";
5117 // gen_helper_mtc0_performance4(arg);
5118 rn
= "Performance4";
5121 // gen_helper_mtc0_performance5(arg);
5122 rn
= "Performance5";
5125 // gen_helper_mtc0_performance6(arg);
5126 rn
= "Performance6";
5129 // gen_helper_mtc0_performance7(arg);
5130 rn
= "Performance7";
5156 gen_helper_mtc0_taglo(arg
);
5163 gen_helper_mtc0_datalo(arg
);
5176 gen_helper_mtc0_taghi(arg
);
5183 gen_helper_mtc0_datahi(arg
);
5194 tcg_gen_st_tl(arg
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5205 gen_mtc0_store32(arg
, offsetof(CPUState
, CP0_DESAVE
));
5211 /* Stop translation as we may have switched the execution mode */
5212 ctx
->bstate
= BS_STOP
;
5217 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5218 /* For simplicity assume that all writes can cause interrupts. */
5221 ctx
->bstate
= BS_STOP
;
5226 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5227 generate_exception(ctx
, EXCP_RI
);
5229 #endif /* TARGET_MIPS64 */
5231 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5232 int u
, int sel
, int h
)
5234 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5235 TCGv t0
= tcg_temp_local_new();
5237 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5238 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5239 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5240 tcg_gen_movi_tl(t0
, -1);
5241 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5242 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5243 tcg_gen_movi_tl(t0
, -1);
5249 gen_helper_mftc0_tcstatus(t0
);
5252 gen_helper_mftc0_tcbind(t0
);
5255 gen_helper_mftc0_tcrestart(t0
);
5258 gen_helper_mftc0_tchalt(t0
);
5261 gen_helper_mftc0_tccontext(t0
);
5264 gen_helper_mftc0_tcschedule(t0
);
5267 gen_helper_mftc0_tcschefback(t0
);
5270 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5277 gen_helper_mftc0_entryhi(t0
);
5280 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5286 gen_helper_mftc0_status(t0
);
5289 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5295 gen_helper_mftc0_debug(t0
);
5298 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5303 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5305 } else switch (sel
) {
5306 /* GPR registers. */
5308 gen_helper_1i(mftgpr
, t0
, rt
);
5310 /* Auxiliary CPU registers */
5314 gen_helper_1i(mftlo
, t0
, 0);
5317 gen_helper_1i(mfthi
, t0
, 0);
5320 gen_helper_1i(mftacx
, t0
, 0);
5323 gen_helper_1i(mftlo
, t0
, 1);
5326 gen_helper_1i(mfthi
, t0
, 1);
5329 gen_helper_1i(mftacx
, t0
, 1);
5332 gen_helper_1i(mftlo
, t0
, 2);
5335 gen_helper_1i(mfthi
, t0
, 2);
5338 gen_helper_1i(mftacx
, t0
, 2);
5341 gen_helper_1i(mftlo
, t0
, 3);
5344 gen_helper_1i(mfthi
, t0
, 3);
5347 gen_helper_1i(mftacx
, t0
, 3);
5350 gen_helper_mftdsp(t0
);
5356 /* Floating point (COP1). */
5358 /* XXX: For now we support only a single FPU context. */
5360 TCGv_i32 fp0
= tcg_temp_new_i32();
5362 gen_load_fpr32(fp0
, rt
);
5363 tcg_gen_ext_i32_tl(t0
, fp0
);
5364 tcg_temp_free_i32(fp0
);
5366 TCGv_i32 fp0
= tcg_temp_new_i32();
5368 gen_load_fpr32h(fp0
, rt
);
5369 tcg_gen_ext_i32_tl(t0
, fp0
);
5370 tcg_temp_free_i32(fp0
);
5374 /* XXX: For now we support only a single FPU context. */
5375 gen_helper_1i(cfc1
, t0
, rt
);
5377 /* COP2: Not implemented. */
5384 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5385 gen_store_gpr(t0
, rd
);
5391 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5392 generate_exception(ctx
, EXCP_RI
);
5395 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5396 int u
, int sel
, int h
)
5398 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5399 TCGv t0
= tcg_temp_local_new();
5401 gen_load_gpr(t0
, rt
);
5402 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5403 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5404 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5406 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5407 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5414 gen_helper_mttc0_tcstatus(t0
);
5417 gen_helper_mttc0_tcbind(t0
);
5420 gen_helper_mttc0_tcrestart(t0
);
5423 gen_helper_mttc0_tchalt(t0
);
5426 gen_helper_mttc0_tccontext(t0
);
5429 gen_helper_mttc0_tcschedule(t0
);
5432 gen_helper_mttc0_tcschefback(t0
);
5435 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5442 gen_helper_mttc0_entryhi(t0
);
5445 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5451 gen_helper_mttc0_status(t0
);
5454 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5460 gen_helper_mttc0_debug(t0
);
5463 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5468 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5470 } else switch (sel
) {
5471 /* GPR registers. */
5473 gen_helper_1i(mttgpr
, t0
, rd
);
5475 /* Auxiliary CPU registers */
5479 gen_helper_1i(mttlo
, t0
, 0);
5482 gen_helper_1i(mtthi
, t0
, 0);
5485 gen_helper_1i(mttacx
, t0
, 0);
5488 gen_helper_1i(mttlo
, t0
, 1);
5491 gen_helper_1i(mtthi
, t0
, 1);
5494 gen_helper_1i(mttacx
, t0
, 1);
5497 gen_helper_1i(mttlo
, t0
, 2);
5500 gen_helper_1i(mtthi
, t0
, 2);
5503 gen_helper_1i(mttacx
, t0
, 2);
5506 gen_helper_1i(mttlo
, t0
, 3);
5509 gen_helper_1i(mtthi
, t0
, 3);
5512 gen_helper_1i(mttacx
, t0
, 3);
5515 gen_helper_mttdsp(t0
);
5521 /* Floating point (COP1). */
5523 /* XXX: For now we support only a single FPU context. */
5525 TCGv_i32 fp0
= tcg_temp_new_i32();
5527 tcg_gen_trunc_tl_i32(fp0
, t0
);
5528 gen_store_fpr32(fp0
, rd
);
5529 tcg_temp_free_i32(fp0
);
5531 TCGv_i32 fp0
= tcg_temp_new_i32();
5533 tcg_gen_trunc_tl_i32(fp0
, t0
);
5534 gen_store_fpr32h(fp0
, rd
);
5535 tcg_temp_free_i32(fp0
);
5539 /* XXX: For now we support only a single FPU context. */
5540 gen_helper_1i(ctc1
, t0
, rd
);
5542 /* COP2: Not implemented. */
5549 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5555 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
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";
5569 gen_mfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5574 TCGv t0
= tcg_temp_new();
5576 gen_load_gpr(t0
, rt
);
5577 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5582 #if defined(TARGET_MIPS64)
5584 check_insn(env
, ctx
, ISA_MIPS3
);
5589 gen_dmfc0(env
, ctx
, cpu_gpr
[rt
], rd
, ctx
->opcode
& 0x7);
5593 check_insn(env
, ctx
, ISA_MIPS3
);
5595 TCGv t0
= tcg_temp_new();
5597 gen_load_gpr(t0
, rt
);
5598 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5605 check_insn(env
, ctx
, ASE_MT
);
5610 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5611 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5615 check_insn(env
, ctx
, ASE_MT
);
5616 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5617 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5622 if (!env
->tlb
->helper_tlbwi
)
5628 if (!env
->tlb
->helper_tlbwr
)
5634 if (!env
->tlb
->helper_tlbp
)
5640 if (!env
->tlb
->helper_tlbr
)
5646 check_insn(env
, ctx
, ISA_MIPS2
);
5648 ctx
->bstate
= BS_EXCP
;
5652 check_insn(env
, ctx
, ISA_MIPS32
);
5653 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5655 generate_exception(ctx
, EXCP_RI
);
5658 ctx
->bstate
= BS_EXCP
;
5663 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5664 /* If we get an exception, we want to restart at next instruction */
5666 save_cpu_state(ctx
, 1);
5669 ctx
->bstate
= BS_EXCP
;
5674 generate_exception(ctx
, EXCP_RI
);
5677 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5679 #endif /* !CONFIG_USER_ONLY */
5681 /* CP1 Branches (before delay slot) */
5682 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5683 int32_t cc
, int32_t offset
)
5685 target_ulong btarget
;
5686 const char *opn
= "cp1 cond branch";
5687 TCGv_i32 t0
= tcg_temp_new_i32();
5690 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5692 btarget
= ctx
->pc
+ 4 + offset
;
5696 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5697 tcg_gen_not_i32(t0
, t0
);
5698 tcg_gen_andi_i32(t0
, t0
, 1);
5699 tcg_gen_extu_i32_tl(bcond
, t0
);
5703 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5704 tcg_gen_not_i32(t0
, t0
);
5705 tcg_gen_andi_i32(t0
, t0
, 1);
5706 tcg_gen_extu_i32_tl(bcond
, t0
);
5710 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5711 tcg_gen_andi_i32(t0
, t0
, 1);
5712 tcg_gen_extu_i32_tl(bcond
, t0
);
5716 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5717 tcg_gen_andi_i32(t0
, t0
, 1);
5718 tcg_gen_extu_i32_tl(bcond
, t0
);
5721 ctx
->hflags
|= MIPS_HFLAG_BL
;
5725 TCGv_i32 t1
= tcg_temp_new_i32();
5726 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5727 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5728 tcg_gen_or_i32(t0
, t0
, t1
);
5729 tcg_temp_free_i32(t1
);
5730 tcg_gen_not_i32(t0
, t0
);
5731 tcg_gen_andi_i32(t0
, t0
, 1);
5732 tcg_gen_extu_i32_tl(bcond
, t0
);
5738 TCGv_i32 t1
= tcg_temp_new_i32();
5739 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5740 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5741 tcg_gen_or_i32(t0
, t0
, t1
);
5742 tcg_temp_free_i32(t1
);
5743 tcg_gen_andi_i32(t0
, t0
, 1);
5744 tcg_gen_extu_i32_tl(bcond
, t0
);
5750 TCGv_i32 t1
= tcg_temp_new_i32();
5751 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5752 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5753 tcg_gen_or_i32(t0
, t0
, t1
);
5754 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5755 tcg_gen_or_i32(t0
, t0
, t1
);
5756 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5757 tcg_gen_or_i32(t0
, t0
, t1
);
5758 tcg_temp_free_i32(t1
);
5759 tcg_gen_not_i32(t0
, t0
);
5760 tcg_gen_andi_i32(t0
, t0
, 1);
5761 tcg_gen_extu_i32_tl(bcond
, t0
);
5767 TCGv_i32 t1
= tcg_temp_new_i32();
5768 tcg_gen_shri_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5769 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+1));
5770 tcg_gen_or_i32(t0
, t0
, t1
);
5771 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+2));
5772 tcg_gen_or_i32(t0
, t0
, t1
);
5773 tcg_gen_shri_i32(t1
, fpu_fcr31
, get_fp_bit(cc
+3));
5774 tcg_gen_or_i32(t0
, t0
, t1
);
5775 tcg_temp_free_i32(t1
);
5776 tcg_gen_andi_i32(t0
, t0
, 1);
5777 tcg_gen_extu_i32_tl(bcond
, t0
);
5781 ctx
->hflags
|= MIPS_HFLAG_BC
;
5785 generate_exception (ctx
, EXCP_RI
);
5788 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5789 ctx
->hflags
, btarget
);
5790 ctx
->btarget
= btarget
;
5793 tcg_temp_free_i32(t0
);
5796 /* Coprocessor 1 (FPU) */
5798 #define FOP(func, fmt) (((fmt) << 21) | (func))
5800 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5802 const char *opn
= "cp1 move";
5803 TCGv t0
= tcg_temp_new();
5808 TCGv_i32 fp0
= tcg_temp_new_i32();
5810 gen_load_fpr32(fp0
, fs
);
5811 tcg_gen_ext_i32_tl(t0
, fp0
);
5812 tcg_temp_free_i32(fp0
);
5814 gen_store_gpr(t0
, rt
);
5818 gen_load_gpr(t0
, rt
);
5820 TCGv_i32 fp0
= tcg_temp_new_i32();
5822 tcg_gen_trunc_tl_i32(fp0
, t0
);
5823 gen_store_fpr32(fp0
, fs
);
5824 tcg_temp_free_i32(fp0
);
5829 gen_helper_1i(cfc1
, t0
, fs
);
5830 gen_store_gpr(t0
, rt
);
5834 gen_load_gpr(t0
, rt
);
5835 gen_helper_1i(ctc1
, t0
, fs
);
5838 #if defined(TARGET_MIPS64)
5840 gen_load_fpr64(ctx
, t0
, fs
);
5841 gen_store_gpr(t0
, rt
);
5845 gen_load_gpr(t0
, rt
);
5846 gen_store_fpr64(ctx
, t0
, fs
);
5852 TCGv_i32 fp0
= tcg_temp_new_i32();
5854 gen_load_fpr32h(fp0
, fs
);
5855 tcg_gen_ext_i32_tl(t0
, fp0
);
5856 tcg_temp_free_i32(fp0
);
5858 gen_store_gpr(t0
, rt
);
5862 gen_load_gpr(t0
, rt
);
5864 TCGv_i32 fp0
= tcg_temp_new_i32();
5866 tcg_gen_trunc_tl_i32(fp0
, t0
);
5867 gen_store_fpr32h(fp0
, fs
);
5868 tcg_temp_free_i32(fp0
);
5874 generate_exception (ctx
, EXCP_RI
);
5877 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5883 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5899 l1
= gen_new_label();
5900 t0
= tcg_temp_new_i32();
5901 tcg_gen_andi_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5902 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5903 tcg_temp_free_i32(t0
);
5905 tcg_gen_movi_tl(cpu_gpr
[rd
], 0);
5907 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_gpr
[rs
]);
5912 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5915 TCGv_i32 t0
= tcg_temp_new_i32();
5916 int l1
= gen_new_label();
5923 tcg_gen_andi_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5924 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5925 gen_load_fpr32(t0
, fs
);
5926 gen_store_fpr32(t0
, fd
);
5928 tcg_temp_free_i32(t0
);
5931 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5934 TCGv_i32 t0
= tcg_temp_new_i32();
5936 int l1
= gen_new_label();
5943 tcg_gen_andi_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5944 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5945 tcg_temp_free_i32(t0
);
5946 fp0
= tcg_temp_new_i64();
5947 gen_load_fpr64(ctx
, fp0
, fs
);
5948 gen_store_fpr64(ctx
, fp0
, fd
);
5949 tcg_temp_free_i64(fp0
);
5953 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5956 TCGv_i32 t0
= tcg_temp_new_i32();
5957 int l1
= gen_new_label();
5958 int l2
= gen_new_label();
5965 tcg_gen_andi_i32(t0
, fpu_fcr31
, get_fp_bit(cc
));
5966 tcg_gen_brcondi_i32(cond
, t0
, 0, l1
);
5967 gen_load_fpr32(t0
, fs
);
5968 gen_store_fpr32(t0
, fd
);
5971 tcg_gen_andi_i32(t0
, fpu_fcr31
, get_fp_bit(cc
+1));
5972 tcg_gen_brcondi_i32(cond
, t0
, 0, l2
);
5973 gen_load_fpr32h(t0
, fs
);
5974 gen_store_fpr32h(t0
, fd
);
5975 tcg_temp_free_i32(t0
);
5980 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5981 int ft
, int fs
, int fd
, int cc
)
5983 const char *opn
= "farith";
5984 const char *condnames
[] = {
6002 const char *condnames_abs
[] = {
6020 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
6021 uint32_t func
= ctx
->opcode
& 0x3f;
6023 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
6026 TCGv_i32 fp0
= tcg_temp_new_i32();
6027 TCGv_i32 fp1
= tcg_temp_new_i32();
6029 gen_load_fpr32(fp0
, fs
);
6030 gen_load_fpr32(fp1
, ft
);
6031 gen_helper_float_add_s(fp0
, fp0
, fp1
);
6032 tcg_temp_free_i32(fp1
);
6033 gen_store_fpr32(fp0
, fd
);
6034 tcg_temp_free_i32(fp0
);
6041 TCGv_i32 fp0
= tcg_temp_new_i32();
6042 TCGv_i32 fp1
= tcg_temp_new_i32();
6044 gen_load_fpr32(fp0
, fs
);
6045 gen_load_fpr32(fp1
, ft
);
6046 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
6047 tcg_temp_free_i32(fp1
);
6048 gen_store_fpr32(fp0
, fd
);
6049 tcg_temp_free_i32(fp0
);
6056 TCGv_i32 fp0
= tcg_temp_new_i32();
6057 TCGv_i32 fp1
= tcg_temp_new_i32();
6059 gen_load_fpr32(fp0
, fs
);
6060 gen_load_fpr32(fp1
, ft
);
6061 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
6062 tcg_temp_free_i32(fp1
);
6063 gen_store_fpr32(fp0
, fd
);
6064 tcg_temp_free_i32(fp0
);
6071 TCGv_i32 fp0
= tcg_temp_new_i32();
6072 TCGv_i32 fp1
= tcg_temp_new_i32();
6074 gen_load_fpr32(fp0
, fs
);
6075 gen_load_fpr32(fp1
, ft
);
6076 gen_helper_float_div_s(fp0
, fp0
, fp1
);
6077 tcg_temp_free_i32(fp1
);
6078 gen_store_fpr32(fp0
, fd
);
6079 tcg_temp_free_i32(fp0
);
6086 TCGv_i32 fp0
= tcg_temp_new_i32();
6088 gen_load_fpr32(fp0
, fs
);
6089 gen_helper_float_sqrt_s(fp0
, fp0
);
6090 gen_store_fpr32(fp0
, fd
);
6091 tcg_temp_free_i32(fp0
);
6097 TCGv_i32 fp0
= tcg_temp_new_i32();
6099 gen_load_fpr32(fp0
, fs
);
6100 gen_helper_float_abs_s(fp0
, fp0
);
6101 gen_store_fpr32(fp0
, fd
);
6102 tcg_temp_free_i32(fp0
);
6108 TCGv_i32 fp0
= tcg_temp_new_i32();
6110 gen_load_fpr32(fp0
, fs
);
6111 gen_store_fpr32(fp0
, fd
);
6112 tcg_temp_free_i32(fp0
);
6118 TCGv_i32 fp0
= tcg_temp_new_i32();
6120 gen_load_fpr32(fp0
, fs
);
6121 gen_helper_float_chs_s(fp0
, fp0
);
6122 gen_store_fpr32(fp0
, fd
);
6123 tcg_temp_free_i32(fp0
);
6128 check_cp1_64bitmode(ctx
);
6130 TCGv_i32 fp32
= tcg_temp_new_i32();
6131 TCGv_i64 fp64
= tcg_temp_new_i64();
6133 gen_load_fpr32(fp32
, fs
);
6134 gen_helper_float_roundl_s(fp64
, fp32
);
6135 tcg_temp_free_i32(fp32
);
6136 gen_store_fpr64(ctx
, fp64
, fd
);
6137 tcg_temp_free_i64(fp64
);
6142 check_cp1_64bitmode(ctx
);
6144 TCGv_i32 fp32
= tcg_temp_new_i32();
6145 TCGv_i64 fp64
= tcg_temp_new_i64();
6147 gen_load_fpr32(fp32
, fs
);
6148 gen_helper_float_truncl_s(fp64
, fp32
);
6149 tcg_temp_free_i32(fp32
);
6150 gen_store_fpr64(ctx
, fp64
, fd
);
6151 tcg_temp_free_i64(fp64
);
6156 check_cp1_64bitmode(ctx
);
6158 TCGv_i32 fp32
= tcg_temp_new_i32();
6159 TCGv_i64 fp64
= tcg_temp_new_i64();
6161 gen_load_fpr32(fp32
, fs
);
6162 gen_helper_float_ceill_s(fp64
, fp32
);
6163 tcg_temp_free_i32(fp32
);
6164 gen_store_fpr64(ctx
, fp64
, fd
);
6165 tcg_temp_free_i64(fp64
);
6170 check_cp1_64bitmode(ctx
);
6172 TCGv_i32 fp32
= tcg_temp_new_i32();
6173 TCGv_i64 fp64
= tcg_temp_new_i64();
6175 gen_load_fpr32(fp32
, fs
);
6176 gen_helper_float_floorl_s(fp64
, fp32
);
6177 tcg_temp_free_i32(fp32
);
6178 gen_store_fpr64(ctx
, fp64
, fd
);
6179 tcg_temp_free_i64(fp64
);
6185 TCGv_i32 fp0
= tcg_temp_new_i32();
6187 gen_load_fpr32(fp0
, fs
);
6188 gen_helper_float_roundw_s(fp0
, fp0
);
6189 gen_store_fpr32(fp0
, fd
);
6190 tcg_temp_free_i32(fp0
);
6196 TCGv_i32 fp0
= tcg_temp_new_i32();
6198 gen_load_fpr32(fp0
, fs
);
6199 gen_helper_float_truncw_s(fp0
, fp0
);
6200 gen_store_fpr32(fp0
, fd
);
6201 tcg_temp_free_i32(fp0
);
6207 TCGv_i32 fp0
= tcg_temp_new_i32();
6209 gen_load_fpr32(fp0
, fs
);
6210 gen_helper_float_ceilw_s(fp0
, fp0
);
6211 gen_store_fpr32(fp0
, fd
);
6212 tcg_temp_free_i32(fp0
);
6218 TCGv_i32 fp0
= tcg_temp_new_i32();
6220 gen_load_fpr32(fp0
, fs
);
6221 gen_helper_float_floorw_s(fp0
, fp0
);
6222 gen_store_fpr32(fp0
, fd
);
6223 tcg_temp_free_i32(fp0
);
6228 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6233 int l1
= gen_new_label();
6237 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6239 fp0
= tcg_temp_new_i32();
6240 gen_load_fpr32(fp0
, fs
);
6241 gen_store_fpr32(fp0
, fd
);
6242 tcg_temp_free_i32(fp0
);
6249 int l1
= gen_new_label();
6253 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6254 fp0
= tcg_temp_new_i32();
6255 gen_load_fpr32(fp0
, fs
);
6256 gen_store_fpr32(fp0
, fd
);
6257 tcg_temp_free_i32(fp0
);
6266 TCGv_i32 fp0
= tcg_temp_new_i32();
6268 gen_load_fpr32(fp0
, fs
);
6269 gen_helper_float_recip_s(fp0
, fp0
);
6270 gen_store_fpr32(fp0
, fd
);
6271 tcg_temp_free_i32(fp0
);
6278 TCGv_i32 fp0
= tcg_temp_new_i32();
6280 gen_load_fpr32(fp0
, fs
);
6281 gen_helper_float_rsqrt_s(fp0
, fp0
);
6282 gen_store_fpr32(fp0
, fd
);
6283 tcg_temp_free_i32(fp0
);
6288 check_cp1_64bitmode(ctx
);
6290 TCGv_i32 fp0
= tcg_temp_new_i32();
6291 TCGv_i32 fp1
= tcg_temp_new_i32();
6293 gen_load_fpr32(fp0
, fs
);
6294 gen_load_fpr32(fp1
, fd
);
6295 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6296 tcg_temp_free_i32(fp1
);
6297 gen_store_fpr32(fp0
, fd
);
6298 tcg_temp_free_i32(fp0
);
6303 check_cp1_64bitmode(ctx
);
6305 TCGv_i32 fp0
= tcg_temp_new_i32();
6307 gen_load_fpr32(fp0
, fs
);
6308 gen_helper_float_recip1_s(fp0
, fp0
);
6309 gen_store_fpr32(fp0
, fd
);
6310 tcg_temp_free_i32(fp0
);
6315 check_cp1_64bitmode(ctx
);
6317 TCGv_i32 fp0
= tcg_temp_new_i32();
6319 gen_load_fpr32(fp0
, fs
);
6320 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6321 gen_store_fpr32(fp0
, fd
);
6322 tcg_temp_free_i32(fp0
);
6327 check_cp1_64bitmode(ctx
);
6329 TCGv_i32 fp0
= tcg_temp_new_i32();
6330 TCGv_i32 fp1
= tcg_temp_new_i32();
6332 gen_load_fpr32(fp0
, fs
);
6333 gen_load_fpr32(fp1
, ft
);
6334 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6335 tcg_temp_free_i32(fp1
);
6336 gen_store_fpr32(fp0
, fd
);
6337 tcg_temp_free_i32(fp0
);
6342 check_cp1_registers(ctx
, fd
);
6344 TCGv_i32 fp32
= tcg_temp_new_i32();
6345 TCGv_i64 fp64
= tcg_temp_new_i64();
6347 gen_load_fpr32(fp32
, fs
);
6348 gen_helper_float_cvtd_s(fp64
, fp32
);
6349 tcg_temp_free_i32(fp32
);
6350 gen_store_fpr64(ctx
, fp64
, fd
);
6351 tcg_temp_free_i64(fp64
);
6357 TCGv_i32 fp0
= tcg_temp_new_i32();
6359 gen_load_fpr32(fp0
, fs
);
6360 gen_helper_float_cvtw_s(fp0
, fp0
);
6361 gen_store_fpr32(fp0
, fd
);
6362 tcg_temp_free_i32(fp0
);
6367 check_cp1_64bitmode(ctx
);
6369 TCGv_i32 fp32
= tcg_temp_new_i32();
6370 TCGv_i64 fp64
= tcg_temp_new_i64();
6372 gen_load_fpr32(fp32
, fs
);
6373 gen_helper_float_cvtl_s(fp64
, fp32
);
6374 tcg_temp_free_i32(fp32
);
6375 gen_store_fpr64(ctx
, fp64
, fd
);
6376 tcg_temp_free_i64(fp64
);
6381 check_cp1_64bitmode(ctx
);
6383 TCGv_i64 fp64
= tcg_temp_new_i64();
6384 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6385 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6387 gen_load_fpr32(fp32_0
, fs
);
6388 gen_load_fpr32(fp32_1
, ft
);
6389 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6390 tcg_temp_free_i32(fp32_1
);
6391 tcg_temp_free_i32(fp32_0
);
6392 gen_store_fpr64(ctx
, fp64
, fd
);
6393 tcg_temp_free_i64(fp64
);
6414 TCGv_i32 fp0
= tcg_temp_new_i32();
6415 TCGv_i32 fp1
= tcg_temp_new_i32();
6417 gen_load_fpr32(fp0
, fs
);
6418 gen_load_fpr32(fp1
, ft
);
6419 if (ctx
->opcode
& (1 << 6)) {
6421 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6422 opn
= condnames_abs
[func
-48];
6424 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6425 opn
= condnames
[func
-48];
6427 tcg_temp_free_i32(fp0
);
6428 tcg_temp_free_i32(fp1
);
6432 check_cp1_registers(ctx
, fs
| ft
| fd
);
6434 TCGv_i64 fp0
= tcg_temp_new_i64();
6435 TCGv_i64 fp1
= tcg_temp_new_i64();
6437 gen_load_fpr64(ctx
, fp0
, fs
);
6438 gen_load_fpr64(ctx
, fp1
, ft
);
6439 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6440 tcg_temp_free_i64(fp1
);
6441 gen_store_fpr64(ctx
, fp0
, fd
);
6442 tcg_temp_free_i64(fp0
);
6448 check_cp1_registers(ctx
, fs
| ft
| fd
);
6450 TCGv_i64 fp0
= tcg_temp_new_i64();
6451 TCGv_i64 fp1
= tcg_temp_new_i64();
6453 gen_load_fpr64(ctx
, fp0
, fs
);
6454 gen_load_fpr64(ctx
, fp1
, ft
);
6455 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6456 tcg_temp_free_i64(fp1
);
6457 gen_store_fpr64(ctx
, fp0
, fd
);
6458 tcg_temp_free_i64(fp0
);
6464 check_cp1_registers(ctx
, fs
| ft
| fd
);
6466 TCGv_i64 fp0
= tcg_temp_new_i64();
6467 TCGv_i64 fp1
= tcg_temp_new_i64();
6469 gen_load_fpr64(ctx
, fp0
, fs
);
6470 gen_load_fpr64(ctx
, fp1
, ft
);
6471 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6472 tcg_temp_free_i64(fp1
);
6473 gen_store_fpr64(ctx
, fp0
, fd
);
6474 tcg_temp_free_i64(fp0
);
6480 check_cp1_registers(ctx
, fs
| ft
| fd
);
6482 TCGv_i64 fp0
= tcg_temp_new_i64();
6483 TCGv_i64 fp1
= tcg_temp_new_i64();
6485 gen_load_fpr64(ctx
, fp0
, fs
);
6486 gen_load_fpr64(ctx
, fp1
, ft
);
6487 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6488 tcg_temp_free_i64(fp1
);
6489 gen_store_fpr64(ctx
, fp0
, fd
);
6490 tcg_temp_free_i64(fp0
);
6496 check_cp1_registers(ctx
, fs
| fd
);
6498 TCGv_i64 fp0
= tcg_temp_new_i64();
6500 gen_load_fpr64(ctx
, fp0
, fs
);
6501 gen_helper_float_sqrt_d(fp0
, fp0
);
6502 gen_store_fpr64(ctx
, fp0
, fd
);
6503 tcg_temp_free_i64(fp0
);
6508 check_cp1_registers(ctx
, fs
| fd
);
6510 TCGv_i64 fp0
= tcg_temp_new_i64();
6512 gen_load_fpr64(ctx
, fp0
, fs
);
6513 gen_helper_float_abs_d(fp0
, fp0
);
6514 gen_store_fpr64(ctx
, fp0
, fd
);
6515 tcg_temp_free_i64(fp0
);
6520 check_cp1_registers(ctx
, fs
| fd
);
6522 TCGv_i64 fp0
= tcg_temp_new_i64();
6524 gen_load_fpr64(ctx
, fp0
, fs
);
6525 gen_store_fpr64(ctx
, fp0
, fd
);
6526 tcg_temp_free_i64(fp0
);
6531 check_cp1_registers(ctx
, fs
| fd
);
6533 TCGv_i64 fp0
= tcg_temp_new_i64();
6535 gen_load_fpr64(ctx
, fp0
, fs
);
6536 gen_helper_float_chs_d(fp0
, fp0
);
6537 gen_store_fpr64(ctx
, fp0
, fd
);
6538 tcg_temp_free_i64(fp0
);
6543 check_cp1_64bitmode(ctx
);
6545 TCGv_i64 fp0
= tcg_temp_new_i64();
6547 gen_load_fpr64(ctx
, fp0
, fs
);
6548 gen_helper_float_roundl_d(fp0
, fp0
);
6549 gen_store_fpr64(ctx
, fp0
, fd
);
6550 tcg_temp_free_i64(fp0
);
6555 check_cp1_64bitmode(ctx
);
6557 TCGv_i64 fp0
= tcg_temp_new_i64();
6559 gen_load_fpr64(ctx
, fp0
, fs
);
6560 gen_helper_float_truncl_d(fp0
, fp0
);
6561 gen_store_fpr64(ctx
, fp0
, fd
);
6562 tcg_temp_free_i64(fp0
);
6567 check_cp1_64bitmode(ctx
);
6569 TCGv_i64 fp0
= tcg_temp_new_i64();
6571 gen_load_fpr64(ctx
, fp0
, fs
);
6572 gen_helper_float_ceill_d(fp0
, fp0
);
6573 gen_store_fpr64(ctx
, fp0
, fd
);
6574 tcg_temp_free_i64(fp0
);
6579 check_cp1_64bitmode(ctx
);
6581 TCGv_i64 fp0
= tcg_temp_new_i64();
6583 gen_load_fpr64(ctx
, fp0
, fs
);
6584 gen_helper_float_floorl_d(fp0
, fp0
);
6585 gen_store_fpr64(ctx
, fp0
, fd
);
6586 tcg_temp_free_i64(fp0
);
6591 check_cp1_registers(ctx
, fs
);
6593 TCGv_i32 fp32
= tcg_temp_new_i32();
6594 TCGv_i64 fp64
= tcg_temp_new_i64();
6596 gen_load_fpr64(ctx
, fp64
, fs
);
6597 gen_helper_float_roundw_d(fp32
, fp64
);
6598 tcg_temp_free_i64(fp64
);
6599 gen_store_fpr32(fp32
, fd
);
6600 tcg_temp_free_i32(fp32
);
6605 check_cp1_registers(ctx
, fs
);
6607 TCGv_i32 fp32
= tcg_temp_new_i32();
6608 TCGv_i64 fp64
= tcg_temp_new_i64();
6610 gen_load_fpr64(ctx
, fp64
, fs
);
6611 gen_helper_float_truncw_d(fp32
, fp64
);
6612 tcg_temp_free_i64(fp64
);
6613 gen_store_fpr32(fp32
, fd
);
6614 tcg_temp_free_i32(fp32
);
6619 check_cp1_registers(ctx
, fs
);
6621 TCGv_i32 fp32
= tcg_temp_new_i32();
6622 TCGv_i64 fp64
= tcg_temp_new_i64();
6624 gen_load_fpr64(ctx
, fp64
, fs
);
6625 gen_helper_float_ceilw_d(fp32
, fp64
);
6626 tcg_temp_free_i64(fp64
);
6627 gen_store_fpr32(fp32
, fd
);
6628 tcg_temp_free_i32(fp32
);
6633 check_cp1_registers(ctx
, fs
);
6635 TCGv_i32 fp32
= tcg_temp_new_i32();
6636 TCGv_i64 fp64
= tcg_temp_new_i64();
6638 gen_load_fpr64(ctx
, fp64
, fs
);
6639 gen_helper_float_floorw_d(fp32
, fp64
);
6640 tcg_temp_free_i64(fp64
);
6641 gen_store_fpr32(fp32
, fd
);
6642 tcg_temp_free_i32(fp32
);
6647 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6652 int l1
= gen_new_label();
6656 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6658 fp0
= tcg_temp_new_i64();
6659 gen_load_fpr64(ctx
, fp0
, fs
);
6660 gen_store_fpr64(ctx
, fp0
, fd
);
6661 tcg_temp_free_i64(fp0
);
6668 int l1
= gen_new_label();
6672 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
6673 fp0
= tcg_temp_new_i64();
6674 gen_load_fpr64(ctx
, fp0
, fs
);
6675 gen_store_fpr64(ctx
, fp0
, fd
);
6676 tcg_temp_free_i64(fp0
);
6683 check_cp1_64bitmode(ctx
);
6685 TCGv_i64 fp0
= tcg_temp_new_i64();
6687 gen_load_fpr64(ctx
, fp0
, fs
);
6688 gen_helper_float_recip_d(fp0
, fp0
);
6689 gen_store_fpr64(ctx
, fp0
, fd
);
6690 tcg_temp_free_i64(fp0
);
6695 check_cp1_64bitmode(ctx
);
6697 TCGv_i64 fp0
= tcg_temp_new_i64();
6699 gen_load_fpr64(ctx
, fp0
, fs
);
6700 gen_helper_float_rsqrt_d(fp0
, fp0
);
6701 gen_store_fpr64(ctx
, fp0
, fd
);
6702 tcg_temp_free_i64(fp0
);
6707 check_cp1_64bitmode(ctx
);
6709 TCGv_i64 fp0
= tcg_temp_new_i64();
6710 TCGv_i64 fp1
= tcg_temp_new_i64();
6712 gen_load_fpr64(ctx
, fp0
, fs
);
6713 gen_load_fpr64(ctx
, fp1
, ft
);
6714 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6715 tcg_temp_free_i64(fp1
);
6716 gen_store_fpr64(ctx
, fp0
, fd
);
6717 tcg_temp_free_i64(fp0
);
6722 check_cp1_64bitmode(ctx
);
6724 TCGv_i64 fp0
= tcg_temp_new_i64();
6726 gen_load_fpr64(ctx
, fp0
, fs
);
6727 gen_helper_float_recip1_d(fp0
, fp0
);
6728 gen_store_fpr64(ctx
, fp0
, fd
);
6729 tcg_temp_free_i64(fp0
);
6734 check_cp1_64bitmode(ctx
);
6736 TCGv_i64 fp0
= tcg_temp_new_i64();
6738 gen_load_fpr64(ctx
, fp0
, fs
);
6739 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6740 gen_store_fpr64(ctx
, fp0
, fd
);
6741 tcg_temp_free_i64(fp0
);
6746 check_cp1_64bitmode(ctx
);
6748 TCGv_i64 fp0
= tcg_temp_new_i64();
6749 TCGv_i64 fp1
= tcg_temp_new_i64();
6751 gen_load_fpr64(ctx
, fp0
, fs
);
6752 gen_load_fpr64(ctx
, fp1
, ft
);
6753 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6754 tcg_temp_free_i64(fp1
);
6755 gen_store_fpr64(ctx
, fp0
, fd
);
6756 tcg_temp_free_i64(fp0
);
6777 TCGv_i64 fp0
= tcg_temp_new_i64();
6778 TCGv_i64 fp1
= tcg_temp_new_i64();
6780 gen_load_fpr64(ctx
, fp0
, fs
);
6781 gen_load_fpr64(ctx
, fp1
, ft
);
6782 if (ctx
->opcode
& (1 << 6)) {
6784 check_cp1_registers(ctx
, fs
| ft
);
6785 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6786 opn
= condnames_abs
[func
-48];
6788 check_cp1_registers(ctx
, fs
| ft
);
6789 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6790 opn
= condnames
[func
-48];
6792 tcg_temp_free_i64(fp0
);
6793 tcg_temp_free_i64(fp1
);
6797 check_cp1_registers(ctx
, fs
);
6799 TCGv_i32 fp32
= tcg_temp_new_i32();
6800 TCGv_i64 fp64
= tcg_temp_new_i64();
6802 gen_load_fpr64(ctx
, fp64
, fs
);
6803 gen_helper_float_cvts_d(fp32
, fp64
);
6804 tcg_temp_free_i64(fp64
);
6805 gen_store_fpr32(fp32
, fd
);
6806 tcg_temp_free_i32(fp32
);
6811 check_cp1_registers(ctx
, fs
);
6813 TCGv_i32 fp32
= tcg_temp_new_i32();
6814 TCGv_i64 fp64
= tcg_temp_new_i64();
6816 gen_load_fpr64(ctx
, fp64
, fs
);
6817 gen_helper_float_cvtw_d(fp32
, fp64
);
6818 tcg_temp_free_i64(fp64
);
6819 gen_store_fpr32(fp32
, fd
);
6820 tcg_temp_free_i32(fp32
);
6825 check_cp1_64bitmode(ctx
);
6827 TCGv_i64 fp0
= tcg_temp_new_i64();
6829 gen_load_fpr64(ctx
, fp0
, fs
);
6830 gen_helper_float_cvtl_d(fp0
, fp0
);
6831 gen_store_fpr64(ctx
, fp0
, fd
);
6832 tcg_temp_free_i64(fp0
);
6838 TCGv_i32 fp0
= tcg_temp_new_i32();
6840 gen_load_fpr32(fp0
, fs
);
6841 gen_helper_float_cvts_w(fp0
, fp0
);
6842 gen_store_fpr32(fp0
, fd
);
6843 tcg_temp_free_i32(fp0
);
6848 check_cp1_registers(ctx
, fd
);
6850 TCGv_i32 fp32
= tcg_temp_new_i32();
6851 TCGv_i64 fp64
= tcg_temp_new_i64();
6853 gen_load_fpr32(fp32
, fs
);
6854 gen_helper_float_cvtd_w(fp64
, fp32
);
6855 tcg_temp_free_i32(fp32
);
6856 gen_store_fpr64(ctx
, fp64
, fd
);
6857 tcg_temp_free_i64(fp64
);
6862 check_cp1_64bitmode(ctx
);
6864 TCGv_i32 fp32
= tcg_temp_new_i32();
6865 TCGv_i64 fp64
= tcg_temp_new_i64();
6867 gen_load_fpr64(ctx
, fp64
, fs
);
6868 gen_helper_float_cvts_l(fp32
, fp64
);
6869 tcg_temp_free_i64(fp64
);
6870 gen_store_fpr32(fp32
, fd
);
6871 tcg_temp_free_i32(fp32
);
6876 check_cp1_64bitmode(ctx
);
6878 TCGv_i64 fp0
= tcg_temp_new_i64();
6880 gen_load_fpr64(ctx
, fp0
, fs
);
6881 gen_helper_float_cvtd_l(fp0
, fp0
);
6882 gen_store_fpr64(ctx
, fp0
, fd
);
6883 tcg_temp_free_i64(fp0
);
6888 check_cp1_64bitmode(ctx
);
6890 TCGv_i64 fp0
= tcg_temp_new_i64();
6892 gen_load_fpr64(ctx
, fp0
, fs
);
6893 gen_helper_float_cvtps_pw(fp0
, fp0
);
6894 gen_store_fpr64(ctx
, fp0
, fd
);
6895 tcg_temp_free_i64(fp0
);
6900 check_cp1_64bitmode(ctx
);
6902 TCGv_i64 fp0
= tcg_temp_new_i64();
6903 TCGv_i64 fp1
= tcg_temp_new_i64();
6905 gen_load_fpr64(ctx
, fp0
, fs
);
6906 gen_load_fpr64(ctx
, fp1
, ft
);
6907 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6908 tcg_temp_free_i64(fp1
);
6909 gen_store_fpr64(ctx
, fp0
, fd
);
6910 tcg_temp_free_i64(fp0
);
6915 check_cp1_64bitmode(ctx
);
6917 TCGv_i64 fp0
= tcg_temp_new_i64();
6918 TCGv_i64 fp1
= tcg_temp_new_i64();
6920 gen_load_fpr64(ctx
, fp0
, fs
);
6921 gen_load_fpr64(ctx
, fp1
, ft
);
6922 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6923 tcg_temp_free_i64(fp1
);
6924 gen_store_fpr64(ctx
, fp0
, fd
);
6925 tcg_temp_free_i64(fp0
);
6930 check_cp1_64bitmode(ctx
);
6932 TCGv_i64 fp0
= tcg_temp_new_i64();
6933 TCGv_i64 fp1
= tcg_temp_new_i64();
6935 gen_load_fpr64(ctx
, fp0
, fs
);
6936 gen_load_fpr64(ctx
, fp1
, ft
);
6937 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6938 tcg_temp_free_i64(fp1
);
6939 gen_store_fpr64(ctx
, fp0
, fd
);
6940 tcg_temp_free_i64(fp0
);
6945 check_cp1_64bitmode(ctx
);
6947 TCGv_i64 fp0
= tcg_temp_new_i64();
6949 gen_load_fpr64(ctx
, fp0
, fs
);
6950 gen_helper_float_abs_ps(fp0
, fp0
);
6951 gen_store_fpr64(ctx
, fp0
, fd
);
6952 tcg_temp_free_i64(fp0
);
6957 check_cp1_64bitmode(ctx
);
6959 TCGv_i64 fp0
= tcg_temp_new_i64();
6961 gen_load_fpr64(ctx
, fp0
, fs
);
6962 gen_store_fpr64(ctx
, fp0
, fd
);
6963 tcg_temp_free_i64(fp0
);
6968 check_cp1_64bitmode(ctx
);
6970 TCGv_i64 fp0
= tcg_temp_new_i64();
6972 gen_load_fpr64(ctx
, fp0
, fs
);
6973 gen_helper_float_chs_ps(fp0
, fp0
);
6974 gen_store_fpr64(ctx
, fp0
, fd
);
6975 tcg_temp_free_i64(fp0
);
6980 check_cp1_64bitmode(ctx
);
6981 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6985 check_cp1_64bitmode(ctx
);
6987 int l1
= gen_new_label();
6991 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[ft
], 0, l1
);
6992 fp0
= tcg_temp_new_i64();
6993 gen_load_fpr64(ctx
, fp0
, fs
);
6994 gen_store_fpr64(ctx
, fp0
, fd
);
6995 tcg_temp_free_i64(fp0
);
7001 check_cp1_64bitmode(ctx
);
7003 int l1
= gen_new_label();
7007 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[ft
], 0, l1
);
7008 fp0
= tcg_temp_new_i64();
7009 gen_load_fpr64(ctx
, fp0
, fs
);
7010 gen_store_fpr64(ctx
, fp0
, fd
);
7011 tcg_temp_free_i64(fp0
);
7018 check_cp1_64bitmode(ctx
);
7020 TCGv_i64 fp0
= tcg_temp_new_i64();
7021 TCGv_i64 fp1
= tcg_temp_new_i64();
7023 gen_load_fpr64(ctx
, fp0
, ft
);
7024 gen_load_fpr64(ctx
, fp1
, fs
);
7025 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
7026 tcg_temp_free_i64(fp1
);
7027 gen_store_fpr64(ctx
, fp0
, fd
);
7028 tcg_temp_free_i64(fp0
);
7033 check_cp1_64bitmode(ctx
);
7035 TCGv_i64 fp0
= tcg_temp_new_i64();
7036 TCGv_i64 fp1
= tcg_temp_new_i64();
7038 gen_load_fpr64(ctx
, fp0
, ft
);
7039 gen_load_fpr64(ctx
, fp1
, fs
);
7040 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
7041 tcg_temp_free_i64(fp1
);
7042 gen_store_fpr64(ctx
, fp0
, fd
);
7043 tcg_temp_free_i64(fp0
);
7048 check_cp1_64bitmode(ctx
);
7050 TCGv_i64 fp0
= tcg_temp_new_i64();
7051 TCGv_i64 fp1
= tcg_temp_new_i64();
7053 gen_load_fpr64(ctx
, fp0
, fs
);
7054 gen_load_fpr64(ctx
, fp1
, fd
);
7055 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
7056 tcg_temp_free_i64(fp1
);
7057 gen_store_fpr64(ctx
, fp0
, fd
);
7058 tcg_temp_free_i64(fp0
);
7063 check_cp1_64bitmode(ctx
);
7065 TCGv_i64 fp0
= tcg_temp_new_i64();
7067 gen_load_fpr64(ctx
, fp0
, fs
);
7068 gen_helper_float_recip1_ps(fp0
, fp0
);
7069 gen_store_fpr64(ctx
, fp0
, fd
);
7070 tcg_temp_free_i64(fp0
);
7075 check_cp1_64bitmode(ctx
);
7077 TCGv_i64 fp0
= tcg_temp_new_i64();
7079 gen_load_fpr64(ctx
, fp0
, fs
);
7080 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7081 gen_store_fpr64(ctx
, fp0
, fd
);
7082 tcg_temp_free_i64(fp0
);
7087 check_cp1_64bitmode(ctx
);
7089 TCGv_i64 fp0
= tcg_temp_new_i64();
7090 TCGv_i64 fp1
= tcg_temp_new_i64();
7092 gen_load_fpr64(ctx
, fp0
, fs
);
7093 gen_load_fpr64(ctx
, fp1
, ft
);
7094 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7095 tcg_temp_free_i64(fp1
);
7096 gen_store_fpr64(ctx
, fp0
, fd
);
7097 tcg_temp_free_i64(fp0
);
7102 check_cp1_64bitmode(ctx
);
7104 TCGv_i32 fp0
= tcg_temp_new_i32();
7106 gen_load_fpr32h(fp0
, fs
);
7107 gen_helper_float_cvts_pu(fp0
, fp0
);
7108 gen_store_fpr32(fp0
, fd
);
7109 tcg_temp_free_i32(fp0
);
7114 check_cp1_64bitmode(ctx
);
7116 TCGv_i64 fp0
= tcg_temp_new_i64();
7118 gen_load_fpr64(ctx
, fp0
, fs
);
7119 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7120 gen_store_fpr64(ctx
, fp0
, fd
);
7121 tcg_temp_free_i64(fp0
);
7126 check_cp1_64bitmode(ctx
);
7128 TCGv_i32 fp0
= tcg_temp_new_i32();
7130 gen_load_fpr32(fp0
, fs
);
7131 gen_helper_float_cvts_pl(fp0
, fp0
);
7132 gen_store_fpr32(fp0
, fd
);
7133 tcg_temp_free_i32(fp0
);
7138 check_cp1_64bitmode(ctx
);
7140 TCGv_i32 fp0
= tcg_temp_new_i32();
7141 TCGv_i32 fp1
= tcg_temp_new_i32();
7143 gen_load_fpr32(fp0
, fs
);
7144 gen_load_fpr32(fp1
, ft
);
7145 gen_store_fpr32h(fp0
, fd
);
7146 gen_store_fpr32(fp1
, fd
);
7147 tcg_temp_free_i32(fp0
);
7148 tcg_temp_free_i32(fp1
);
7153 check_cp1_64bitmode(ctx
);
7155 TCGv_i32 fp0
= tcg_temp_new_i32();
7156 TCGv_i32 fp1
= tcg_temp_new_i32();
7158 gen_load_fpr32(fp0
, fs
);
7159 gen_load_fpr32h(fp1
, ft
);
7160 gen_store_fpr32(fp1
, fd
);
7161 gen_store_fpr32h(fp0
, fd
);
7162 tcg_temp_free_i32(fp0
);
7163 tcg_temp_free_i32(fp1
);
7168 check_cp1_64bitmode(ctx
);
7170 TCGv_i32 fp0
= tcg_temp_new_i32();
7171 TCGv_i32 fp1
= tcg_temp_new_i32();
7173 gen_load_fpr32h(fp0
, fs
);
7174 gen_load_fpr32(fp1
, ft
);
7175 gen_store_fpr32(fp1
, fd
);
7176 gen_store_fpr32h(fp0
, fd
);
7177 tcg_temp_free_i32(fp0
);
7178 tcg_temp_free_i32(fp1
);
7183 check_cp1_64bitmode(ctx
);
7185 TCGv_i32 fp0
= tcg_temp_new_i32();
7186 TCGv_i32 fp1
= tcg_temp_new_i32();
7188 gen_load_fpr32h(fp0
, fs
);
7189 gen_load_fpr32h(fp1
, ft
);
7190 gen_store_fpr32(fp1
, fd
);
7191 gen_store_fpr32h(fp0
, fd
);
7192 tcg_temp_free_i32(fp0
);
7193 tcg_temp_free_i32(fp1
);
7213 check_cp1_64bitmode(ctx
);
7215 TCGv_i64 fp0
= tcg_temp_new_i64();
7216 TCGv_i64 fp1
= tcg_temp_new_i64();
7218 gen_load_fpr64(ctx
, fp0
, fs
);
7219 gen_load_fpr64(ctx
, fp1
, ft
);
7220 if (ctx
->opcode
& (1 << 6)) {
7221 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7222 opn
= condnames_abs
[func
-48];
7224 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7225 opn
= condnames
[func
-48];
7227 tcg_temp_free_i64(fp0
);
7228 tcg_temp_free_i64(fp1
);
7233 generate_exception (ctx
, EXCP_RI
);
7238 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7241 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7244 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7249 /* Coprocessor 3 (FPU) */
7250 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7251 int fd
, int fs
, int base
, int index
)
7253 const char *opn
= "extended float load/store";
7255 TCGv t0
= tcg_temp_new();
7258 gen_load_gpr(t0
, index
);
7259 } else if (index
== 0) {
7260 gen_load_gpr(t0
, base
);
7262 gen_load_gpr(t0
, index
);
7263 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
7265 /* Don't do NOP if destination is zero: we must perform the actual
7267 save_cpu_state(ctx
, 0);
7272 TCGv_i32 fp0
= tcg_temp_new_i32();
7274 tcg_gen_qemu_ld32s(t0
, t0
, ctx
->mem_idx
);
7275 tcg_gen_trunc_tl_i32(fp0
, t0
);
7276 gen_store_fpr32(fp0
, fd
);
7277 tcg_temp_free_i32(fp0
);
7283 check_cp1_registers(ctx
, fd
);
7285 TCGv_i64 fp0
= tcg_temp_new_i64();
7287 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7288 gen_store_fpr64(ctx
, fp0
, fd
);
7289 tcg_temp_free_i64(fp0
);
7294 check_cp1_64bitmode(ctx
);
7295 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7297 TCGv_i64 fp0
= tcg_temp_new_i64();
7299 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7300 gen_store_fpr64(ctx
, fp0
, fd
);
7301 tcg_temp_free_i64(fp0
);
7308 TCGv_i32 fp0
= tcg_temp_new_i32();
7309 TCGv t1
= tcg_temp_new();
7311 gen_load_fpr32(fp0
, fs
);
7312 tcg_gen_extu_i32_tl(t1
, fp0
);
7313 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7314 tcg_temp_free_i32(fp0
);
7322 check_cp1_registers(ctx
, fs
);
7324 TCGv_i64 fp0
= tcg_temp_new_i64();
7326 gen_load_fpr64(ctx
, fp0
, fs
);
7327 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7328 tcg_temp_free_i64(fp0
);
7334 check_cp1_64bitmode(ctx
);
7335 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7337 TCGv_i64 fp0
= tcg_temp_new_i64();
7339 gen_load_fpr64(ctx
, fp0
, fs
);
7340 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7341 tcg_temp_free_i64(fp0
);
7348 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7349 regnames
[index
], regnames
[base
]);
7352 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7353 int fd
, int fr
, int fs
, int ft
)
7355 const char *opn
= "flt3_arith";
7359 check_cp1_64bitmode(ctx
);
7361 TCGv t0
= tcg_temp_local_new();
7362 TCGv_i32 fp
= tcg_temp_new_i32();
7363 TCGv_i32 fph
= tcg_temp_new_i32();
7364 int l1
= gen_new_label();
7365 int l2
= gen_new_label();
7367 gen_load_gpr(t0
, fr
);
7368 tcg_gen_andi_tl(t0
, t0
, 0x7);
7370 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7371 gen_load_fpr32(fp
, fs
);
7372 gen_load_fpr32h(fph
, fs
);
7373 gen_store_fpr32(fp
, fd
);
7374 gen_store_fpr32h(fph
, fd
);
7377 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7379 #ifdef TARGET_WORDS_BIGENDIAN
7380 gen_load_fpr32(fp
, fs
);
7381 gen_load_fpr32h(fph
, ft
);
7382 gen_store_fpr32h(fp
, fd
);
7383 gen_store_fpr32(fph
, fd
);
7385 gen_load_fpr32h(fph
, fs
);
7386 gen_load_fpr32(fp
, ft
);
7387 gen_store_fpr32(fph
, fd
);
7388 gen_store_fpr32h(fp
, fd
);
7391 tcg_temp_free_i32(fp
);
7392 tcg_temp_free_i32(fph
);
7399 TCGv_i32 fp0
= tcg_temp_new_i32();
7400 TCGv_i32 fp1
= tcg_temp_new_i32();
7401 TCGv_i32 fp2
= tcg_temp_new_i32();
7403 gen_load_fpr32(fp0
, fs
);
7404 gen_load_fpr32(fp1
, ft
);
7405 gen_load_fpr32(fp2
, fr
);
7406 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7407 tcg_temp_free_i32(fp0
);
7408 tcg_temp_free_i32(fp1
);
7409 gen_store_fpr32(fp2
, fd
);
7410 tcg_temp_free_i32(fp2
);
7416 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7418 TCGv_i64 fp0
= tcg_temp_new_i64();
7419 TCGv_i64 fp1
= tcg_temp_new_i64();
7420 TCGv_i64 fp2
= tcg_temp_new_i64();
7422 gen_load_fpr64(ctx
, fp0
, fs
);
7423 gen_load_fpr64(ctx
, fp1
, ft
);
7424 gen_load_fpr64(ctx
, fp2
, fr
);
7425 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7426 tcg_temp_free_i64(fp0
);
7427 tcg_temp_free_i64(fp1
);
7428 gen_store_fpr64(ctx
, fp2
, fd
);
7429 tcg_temp_free_i64(fp2
);
7434 check_cp1_64bitmode(ctx
);
7436 TCGv_i64 fp0
= tcg_temp_new_i64();
7437 TCGv_i64 fp1
= tcg_temp_new_i64();
7438 TCGv_i64 fp2
= tcg_temp_new_i64();
7440 gen_load_fpr64(ctx
, fp0
, fs
);
7441 gen_load_fpr64(ctx
, fp1
, ft
);
7442 gen_load_fpr64(ctx
, fp2
, fr
);
7443 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7444 tcg_temp_free_i64(fp0
);
7445 tcg_temp_free_i64(fp1
);
7446 gen_store_fpr64(ctx
, fp2
, fd
);
7447 tcg_temp_free_i64(fp2
);
7454 TCGv_i32 fp0
= tcg_temp_new_i32();
7455 TCGv_i32 fp1
= tcg_temp_new_i32();
7456 TCGv_i32 fp2
= tcg_temp_new_i32();
7458 gen_load_fpr32(fp0
, fs
);
7459 gen_load_fpr32(fp1
, ft
);
7460 gen_load_fpr32(fp2
, fr
);
7461 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7462 tcg_temp_free_i32(fp0
);
7463 tcg_temp_free_i32(fp1
);
7464 gen_store_fpr32(fp2
, fd
);
7465 tcg_temp_free_i32(fp2
);
7471 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7473 TCGv_i64 fp0
= tcg_temp_new_i64();
7474 TCGv_i64 fp1
= tcg_temp_new_i64();
7475 TCGv_i64 fp2
= tcg_temp_new_i64();
7477 gen_load_fpr64(ctx
, fp0
, fs
);
7478 gen_load_fpr64(ctx
, fp1
, ft
);
7479 gen_load_fpr64(ctx
, fp2
, fr
);
7480 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7481 tcg_temp_free_i64(fp0
);
7482 tcg_temp_free_i64(fp1
);
7483 gen_store_fpr64(ctx
, fp2
, fd
);
7484 tcg_temp_free_i64(fp2
);
7489 check_cp1_64bitmode(ctx
);
7491 TCGv_i64 fp0
= tcg_temp_new_i64();
7492 TCGv_i64 fp1
= tcg_temp_new_i64();
7493 TCGv_i64 fp2
= tcg_temp_new_i64();
7495 gen_load_fpr64(ctx
, fp0
, fs
);
7496 gen_load_fpr64(ctx
, fp1
, ft
);
7497 gen_load_fpr64(ctx
, fp2
, fr
);
7498 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7499 tcg_temp_free_i64(fp0
);
7500 tcg_temp_free_i64(fp1
);
7501 gen_store_fpr64(ctx
, fp2
, fd
);
7502 tcg_temp_free_i64(fp2
);
7509 TCGv_i32 fp0
= tcg_temp_new_i32();
7510 TCGv_i32 fp1
= tcg_temp_new_i32();
7511 TCGv_i32 fp2
= tcg_temp_new_i32();
7513 gen_load_fpr32(fp0
, fs
);
7514 gen_load_fpr32(fp1
, ft
);
7515 gen_load_fpr32(fp2
, fr
);
7516 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7517 tcg_temp_free_i32(fp0
);
7518 tcg_temp_free_i32(fp1
);
7519 gen_store_fpr32(fp2
, fd
);
7520 tcg_temp_free_i32(fp2
);
7526 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7528 TCGv_i64 fp0
= tcg_temp_new_i64();
7529 TCGv_i64 fp1
= tcg_temp_new_i64();
7530 TCGv_i64 fp2
= tcg_temp_new_i64();
7532 gen_load_fpr64(ctx
, fp0
, fs
);
7533 gen_load_fpr64(ctx
, fp1
, ft
);
7534 gen_load_fpr64(ctx
, fp2
, fr
);
7535 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7536 tcg_temp_free_i64(fp0
);
7537 tcg_temp_free_i64(fp1
);
7538 gen_store_fpr64(ctx
, fp2
, fd
);
7539 tcg_temp_free_i64(fp2
);
7544 check_cp1_64bitmode(ctx
);
7546 TCGv_i64 fp0
= tcg_temp_new_i64();
7547 TCGv_i64 fp1
= tcg_temp_new_i64();
7548 TCGv_i64 fp2
= tcg_temp_new_i64();
7550 gen_load_fpr64(ctx
, fp0
, fs
);
7551 gen_load_fpr64(ctx
, fp1
, ft
);
7552 gen_load_fpr64(ctx
, fp2
, fr
);
7553 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7554 tcg_temp_free_i64(fp0
);
7555 tcg_temp_free_i64(fp1
);
7556 gen_store_fpr64(ctx
, fp2
, fd
);
7557 tcg_temp_free_i64(fp2
);
7564 TCGv_i32 fp0
= tcg_temp_new_i32();
7565 TCGv_i32 fp1
= tcg_temp_new_i32();
7566 TCGv_i32 fp2
= tcg_temp_new_i32();
7568 gen_load_fpr32(fp0
, fs
);
7569 gen_load_fpr32(fp1
, ft
);
7570 gen_load_fpr32(fp2
, fr
);
7571 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7572 tcg_temp_free_i32(fp0
);
7573 tcg_temp_free_i32(fp1
);
7574 gen_store_fpr32(fp2
, fd
);
7575 tcg_temp_free_i32(fp2
);
7581 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7583 TCGv_i64 fp0
= tcg_temp_new_i64();
7584 TCGv_i64 fp1
= tcg_temp_new_i64();
7585 TCGv_i64 fp2
= tcg_temp_new_i64();
7587 gen_load_fpr64(ctx
, fp0
, fs
);
7588 gen_load_fpr64(ctx
, fp1
, ft
);
7589 gen_load_fpr64(ctx
, fp2
, fr
);
7590 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7591 tcg_temp_free_i64(fp0
);
7592 tcg_temp_free_i64(fp1
);
7593 gen_store_fpr64(ctx
, fp2
, fd
);
7594 tcg_temp_free_i64(fp2
);
7599 check_cp1_64bitmode(ctx
);
7601 TCGv_i64 fp0
= tcg_temp_new_i64();
7602 TCGv_i64 fp1
= tcg_temp_new_i64();
7603 TCGv_i64 fp2
= tcg_temp_new_i64();
7605 gen_load_fpr64(ctx
, fp0
, fs
);
7606 gen_load_fpr64(ctx
, fp1
, ft
);
7607 gen_load_fpr64(ctx
, fp2
, fr
);
7608 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7609 tcg_temp_free_i64(fp0
);
7610 tcg_temp_free_i64(fp1
);
7611 gen_store_fpr64(ctx
, fp2
, fd
);
7612 tcg_temp_free_i64(fp2
);
7618 generate_exception (ctx
, EXCP_RI
);
7621 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7622 fregnames
[fs
], fregnames
[ft
]);
7625 /* ISA extensions (ASEs) */
7626 /* MIPS16 extension to MIPS32 */
7627 /* SmartMIPS extension to MIPS32 */
7629 #if defined(TARGET_MIPS64)
7631 /* MDMX extension to MIPS64 */
7635 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7639 uint32_t op
, op1
, op2
;
7642 /* make sure instructions are on a word boundary */
7643 if (ctx
->pc
& 0x3) {
7644 env
->CP0_BadVAddr
= ctx
->pc
;
7645 generate_exception(ctx
, EXCP_AdEL
);
7649 /* Handle blikely not taken case */
7650 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7651 int l1
= gen_new_label();
7653 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7654 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
7655 tcg_gen_movi_i32(hflags
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7656 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7659 op
= MASK_OP_MAJOR(ctx
->opcode
);
7660 rs
= (ctx
->opcode
>> 21) & 0x1f;
7661 rt
= (ctx
->opcode
>> 16) & 0x1f;
7662 rd
= (ctx
->opcode
>> 11) & 0x1f;
7663 sa
= (ctx
->opcode
>> 6) & 0x1f;
7664 imm
= (int16_t)ctx
->opcode
;
7667 op1
= MASK_SPECIAL(ctx
->opcode
);
7669 case OPC_SLL
: /* Shift with immediate */
7672 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7674 case OPC_MOVN
: /* Conditional move */
7676 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7677 gen_cond_move(env
, op1
, rd
, rs
, rt
);
7679 case OPC_ADD
... OPC_SUBU
:
7680 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7682 case OPC_SLLV
: /* Shifts */
7685 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7687 case OPC_SLT
: /* Set on less than */
7689 gen_slt(env
, op1
, rd
, rs
, rt
);
7691 case OPC_AND
: /* Logic*/
7695 gen_logic(env
, op1
, rd
, rs
, rt
);
7697 case OPC_MULT
... OPC_DIVU
:
7699 check_insn(env
, ctx
, INSN_VR54XX
);
7700 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7701 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7703 gen_muldiv(ctx
, op1
, rs
, rt
);
7705 case OPC_JR
... OPC_JALR
:
7706 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7708 case OPC_TGE
... OPC_TEQ
: /* Traps */
7710 gen_trap(ctx
, op1
, rs
, rt
, -1);
7712 case OPC_MFHI
: /* Move from HI/LO */
7714 gen_HILO(ctx
, op1
, rd
);
7717 case OPC_MTLO
: /* Move to HI/LO */
7718 gen_HILO(ctx
, op1
, rs
);
7720 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7721 #ifdef MIPS_STRICT_STANDARD
7722 MIPS_INVAL("PMON / selsl");
7723 generate_exception(ctx
, EXCP_RI
);
7725 gen_helper_0i(pmon
, sa
);
7729 generate_exception(ctx
, EXCP_SYSCALL
);
7730 ctx
->bstate
= BS_STOP
;
7733 generate_exception(ctx
, EXCP_BREAK
);
7736 #ifdef MIPS_STRICT_STANDARD
7738 generate_exception(ctx
, EXCP_RI
);
7740 /* Implemented as RI exception for now. */
7741 MIPS_INVAL("spim (unofficial)");
7742 generate_exception(ctx
, EXCP_RI
);
7750 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7751 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7752 check_cp1_enabled(ctx
);
7753 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7754 (ctx
->opcode
>> 16) & 1);
7756 generate_exception_err(ctx
, EXCP_CpU
, 1);
7760 #if defined(TARGET_MIPS64)
7761 /* MIPS64 specific opcodes */
7768 check_insn(env
, ctx
, ISA_MIPS3
);
7770 gen_shift_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7772 case OPC_DADD
... OPC_DSUBU
:
7773 check_insn(env
, ctx
, ISA_MIPS3
);
7775 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7780 check_insn(env
, ctx
, ISA_MIPS3
);
7782 gen_shift(env
, ctx
, op1
, rd
, rs
, rt
);
7784 case OPC_DMULT
... OPC_DDIVU
:
7785 check_insn(env
, ctx
, ISA_MIPS3
);
7787 gen_muldiv(ctx
, op1
, rs
, rt
);
7790 default: /* Invalid */
7791 MIPS_INVAL("special");
7792 generate_exception(ctx
, EXCP_RI
);
7797 op1
= MASK_SPECIAL2(ctx
->opcode
);
7799 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7800 case OPC_MSUB
... OPC_MSUBU
:
7801 check_insn(env
, ctx
, ISA_MIPS32
);
7802 gen_muldiv(ctx
, op1
, rs
, rt
);
7805 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7809 check_insn(env
, ctx
, ISA_MIPS32
);
7810 gen_cl(ctx
, op1
, rd
, rs
);
7813 /* XXX: not clear which exception should be raised
7814 * when in debug mode...
7816 check_insn(env
, ctx
, ISA_MIPS32
);
7817 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7818 generate_exception(ctx
, EXCP_DBp
);
7820 generate_exception(ctx
, EXCP_DBp
);
7824 #if defined(TARGET_MIPS64)
7827 check_insn(env
, ctx
, ISA_MIPS64
);
7829 gen_cl(ctx
, op1
, rd
, rs
);
7832 default: /* Invalid */
7833 MIPS_INVAL("special2");
7834 generate_exception(ctx
, EXCP_RI
);
7839 op1
= MASK_SPECIAL3(ctx
->opcode
);
7843 check_insn(env
, ctx
, ISA_MIPS32R2
);
7844 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7847 check_insn(env
, ctx
, ISA_MIPS32R2
);
7848 op2
= MASK_BSHFL(ctx
->opcode
);
7849 gen_bshfl(ctx
, op2
, rt
, rd
);
7852 check_insn(env
, ctx
, ISA_MIPS32R2
);
7854 TCGv t0
= tcg_temp_new();
7858 save_cpu_state(ctx
, 1);
7859 gen_helper_rdhwr_cpunum(t0
);
7860 gen_store_gpr(t0
, rt
);
7863 save_cpu_state(ctx
, 1);
7864 gen_helper_rdhwr_synci_step(t0
);
7865 gen_store_gpr(t0
, rt
);
7868 save_cpu_state(ctx
, 1);
7869 gen_helper_rdhwr_cc(t0
);
7870 gen_store_gpr(t0
, rt
);
7873 save_cpu_state(ctx
, 1);
7874 gen_helper_rdhwr_ccres(t0
);
7875 gen_store_gpr(t0
, rt
);
7878 #if defined(CONFIG_USER_ONLY)
7879 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7880 gen_store_gpr(t0
, rt
);
7883 /* XXX: Some CPUs implement this in hardware.
7884 Not supported yet. */
7886 default: /* Invalid */
7887 MIPS_INVAL("rdhwr");
7888 generate_exception(ctx
, EXCP_RI
);
7895 check_insn(env
, ctx
, ASE_MT
);
7897 TCGv t0
= tcg_temp_new();
7898 TCGv t1
= tcg_temp_new();
7900 gen_load_gpr(t0
, rt
);
7901 gen_load_gpr(t1
, rs
);
7902 gen_helper_fork(t0
, t1
);
7908 check_insn(env
, ctx
, ASE_MT
);
7910 TCGv t0
= tcg_temp_new();
7912 save_cpu_state(ctx
, 1);
7913 gen_load_gpr(t0
, rs
);
7914 gen_helper_yield(t0
, t0
);
7915 gen_store_gpr(t0
, rd
);
7919 #if defined(TARGET_MIPS64)
7920 case OPC_DEXTM
... OPC_DEXT
:
7921 case OPC_DINSM
... OPC_DINS
:
7922 check_insn(env
, ctx
, ISA_MIPS64R2
);
7924 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7927 check_insn(env
, ctx
, ISA_MIPS64R2
);
7929 op2
= MASK_DBSHFL(ctx
->opcode
);
7930 gen_bshfl(ctx
, op2
, rt
, rd
);
7933 default: /* Invalid */
7934 MIPS_INVAL("special3");
7935 generate_exception(ctx
, EXCP_RI
);
7940 op1
= MASK_REGIMM(ctx
->opcode
);
7942 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7943 case OPC_BLTZAL
... OPC_BGEZALL
:
7944 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
7946 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7948 gen_trap(ctx
, op1
, rs
, -1, imm
);
7951 check_insn(env
, ctx
, ISA_MIPS32R2
);
7954 default: /* Invalid */
7955 MIPS_INVAL("regimm");
7956 generate_exception(ctx
, EXCP_RI
);
7961 check_cp0_enabled(ctx
);
7962 op1
= MASK_CP0(ctx
->opcode
);
7968 #if defined(TARGET_MIPS64)
7972 #ifndef CONFIG_USER_ONLY
7973 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7974 #endif /* !CONFIG_USER_ONLY */
7976 case OPC_C0_FIRST
... OPC_C0_LAST
:
7977 #ifndef CONFIG_USER_ONLY
7978 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7979 #endif /* !CONFIG_USER_ONLY */
7982 #ifndef CONFIG_USER_ONLY
7984 TCGv t0
= tcg_temp_new();
7986 op2
= MASK_MFMC0(ctx
->opcode
);
7989 check_insn(env
, ctx
, ASE_MT
);
7990 gen_helper_dmt(t0
, t0
);
7991 gen_store_gpr(t0
, rt
);
7994 check_insn(env
, ctx
, ASE_MT
);
7995 gen_helper_emt(t0
, t0
);
7996 gen_store_gpr(t0
, rt
);
7999 check_insn(env
, ctx
, ASE_MT
);
8000 gen_helper_dvpe(t0
, t0
);
8001 gen_store_gpr(t0
, rt
);
8004 check_insn(env
, ctx
, ASE_MT
);
8005 gen_helper_evpe(t0
, t0
);
8006 gen_store_gpr(t0
, rt
);
8009 check_insn(env
, ctx
, ISA_MIPS32R2
);
8010 save_cpu_state(ctx
, 1);
8012 gen_store_gpr(t0
, rt
);
8013 /* Stop translation as we may have switched the execution mode */
8014 ctx
->bstate
= BS_STOP
;
8017 check_insn(env
, ctx
, ISA_MIPS32R2
);
8018 save_cpu_state(ctx
, 1);
8020 gen_store_gpr(t0
, rt
);
8021 /* Stop translation as we may have switched the execution mode */
8022 ctx
->bstate
= BS_STOP
;
8024 default: /* Invalid */
8025 MIPS_INVAL("mfmc0");
8026 generate_exception(ctx
, EXCP_RI
);
8031 #endif /* !CONFIG_USER_ONLY */
8034 check_insn(env
, ctx
, ISA_MIPS32R2
);
8035 gen_load_srsgpr(rt
, rd
);
8038 check_insn(env
, ctx
, ISA_MIPS32R2
);
8039 gen_store_srsgpr(rt
, rd
);
8043 generate_exception(ctx
, EXCP_RI
);
8047 case OPC_ADDI
: /* Arithmetic with immediate opcode */
8049 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8051 case OPC_SLTI
: /* Set on less than with immediate opcode */
8053 gen_slt_imm(env
, op
, rt
, rs
, imm
);
8055 case OPC_ANDI
: /* Arithmetic with immediate opcode */
8059 gen_logic_imm(env
, op
, rt
, rs
, imm
);
8061 case OPC_J
... OPC_JAL
: /* Jump */
8062 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
8063 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
8065 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
8066 case OPC_BEQL
... OPC_BGTZL
:
8067 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
8069 case OPC_LB
... OPC_LWR
: /* Load and stores */
8070 case OPC_SB
... OPC_SW
:
8073 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8076 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8079 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
8083 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
8087 /* Floating point (COP1). */
8092 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8093 check_cp1_enabled(ctx
);
8094 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
8096 generate_exception_err(ctx
, EXCP_CpU
, 1);
8101 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8102 check_cp1_enabled(ctx
);
8103 op1
= MASK_CP1(ctx
->opcode
);
8107 check_insn(env
, ctx
, ISA_MIPS32R2
);
8112 gen_cp1(ctx
, op1
, rt
, rd
);
8114 #if defined(TARGET_MIPS64)
8117 check_insn(env
, ctx
, ISA_MIPS3
);
8118 gen_cp1(ctx
, op1
, rt
, rd
);
8124 check_insn(env
, ctx
, ASE_MIPS3D
);
8127 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
8128 (rt
>> 2) & 0x7, imm
<< 2);
8135 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
8140 generate_exception (ctx
, EXCP_RI
);
8144 generate_exception_err(ctx
, EXCP_CpU
, 1);
8154 /* COP2: Not implemented. */
8155 generate_exception_err(ctx
, EXCP_CpU
, 2);
8159 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8160 check_cp1_enabled(ctx
);
8161 op1
= MASK_CP3(ctx
->opcode
);
8169 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
8187 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
8191 generate_exception (ctx
, EXCP_RI
);
8195 generate_exception_err(ctx
, EXCP_CpU
, 1);
8199 #if defined(TARGET_MIPS64)
8200 /* MIPS64 opcodes */
8202 case OPC_LDL
... OPC_LDR
:
8203 case OPC_SDL
... OPC_SDR
:
8207 check_insn(env
, ctx
, ISA_MIPS3
);
8209 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8212 check_insn(env
, ctx
, ISA_MIPS3
);
8214 gen_st_cond(ctx
, op
, rt
, rs
, imm
);
8218 check_insn(env
, ctx
, ISA_MIPS3
);
8220 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8224 check_insn(env
, ctx
, ASE_MIPS16
);
8225 /* MIPS16: Not implemented. */
8227 check_insn(env
, ctx
, ASE_MDMX
);
8228 /* MDMX: Not implemented. */
8229 default: /* Invalid */
8230 MIPS_INVAL("major opcode");
8231 generate_exception(ctx
, EXCP_RI
);
8234 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8235 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8236 /* Branches completion */
8237 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8238 ctx
->bstate
= BS_BRANCH
;
8239 save_cpu_state(ctx
, 0);
8240 /* FIXME: Need to clear can_do_io. */
8243 /* unconditional branch */
8244 MIPS_DEBUG("unconditional branch");
8245 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8248 /* blikely taken case */
8249 MIPS_DEBUG("blikely branch taken");
8250 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8253 /* Conditional branch */
8254 MIPS_DEBUG("conditional branch");
8256 int l1
= gen_new_label();
8258 tcg_gen_brcondi_tl(TCG_COND_NE
, bcond
, 0, l1
);
8259 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8261 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8265 /* unconditional branch to register */
8266 MIPS_DEBUG("branch to register");
8267 tcg_gen_mov_tl(cpu_PC
, btarget
);
8271 MIPS_DEBUG("unknown branch");
8278 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
8282 target_ulong pc_start
;
8283 uint16_t *gen_opc_end
;
8290 qemu_log("search pc %d\n", search_pc
);
8293 /* Leave some spare opc slots for branch handling. */
8294 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
- 16;
8298 ctx
.bstate
= BS_NONE
;
8299 /* Restore delay slot state from the tb context. */
8300 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
8301 restore_cpu_state(env
, &ctx
);
8302 #ifdef CONFIG_USER_ONLY
8303 ctx
.mem_idx
= MIPS_HFLAG_UM
;
8305 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
8308 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8310 max_insns
= CF_COUNT_MASK
;
8312 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
8313 /* FIXME: This may print out stale hflags from env... */
8314 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
8316 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
8318 while (ctx
.bstate
== BS_NONE
) {
8319 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
8320 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8321 if (bp
->pc
== ctx
.pc
) {
8322 save_cpu_state(&ctx
, 1);
8323 ctx
.bstate
= BS_BRANCH
;
8324 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8325 /* Include the breakpoint location or the tb won't
8326 * be flushed when it must be. */
8328 goto done_generating
;
8334 j
= gen_opc_ptr
- gen_opc_buf
;
8338 gen_opc_instr_start
[lj
++] = 0;
8340 gen_opc_pc
[lj
] = ctx
.pc
;
8341 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
8342 gen_opc_instr_start
[lj
] = 1;
8343 gen_opc_icount
[lj
] = num_insns
;
8345 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8347 ctx
.opcode
= ldl_code(ctx
.pc
);
8348 decode_opc(env
, &ctx
);
8352 if (env
->singlestep_enabled
)
8355 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
8358 if (gen_opc_ptr
>= gen_opc_end
)
8361 if (num_insns
>= max_insns
)
8367 if (tb
->cflags
& CF_LAST_IO
)
8369 if (env
->singlestep_enabled
) {
8370 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
8371 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8373 switch (ctx
.bstate
) {
8375 gen_helper_interrupt_restart();
8376 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8379 save_cpu_state(&ctx
, 0);
8380 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8383 gen_helper_interrupt_restart();
8392 gen_icount_end(tb
, num_insns
);
8393 *gen_opc_ptr
= INDEX_op_end
;
8395 j
= gen_opc_ptr
- gen_opc_buf
;
8398 gen_opc_instr_start
[lj
++] = 0;
8400 tb
->size
= ctx
.pc
- pc_start
;
8401 tb
->icount
= num_insns
;
8405 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8406 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8407 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
8410 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
8414 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8416 gen_intermediate_code_internal(env
, tb
, 0);
8419 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8421 gen_intermediate_code_internal(env
, tb
, 1);
8424 static void fpu_dump_state(CPUState
*env
, FILE *f
,
8425 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8429 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
8431 #define printfpr(fp) \
8434 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8435 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8436 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8439 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8440 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8441 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8442 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8443 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8448 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8449 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
8450 get_float_exception_flags(&env
->active_fpu
.fp_status
));
8451 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
8452 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
8453 printfpr(&env
->active_fpu
.fpr
[i
]);
8459 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8460 /* Debug help: The architecture requires 32bit code to maintain proper
8461 sign-extended values on 64bit machines. */
8463 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8466 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8467 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8472 if (!SIGN_EXT_P(env
->active_tc
.PC
))
8473 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
8474 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
8475 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
8476 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
8477 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
8478 if (!SIGN_EXT_P(env
->btarget
))
8479 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8481 for (i
= 0; i
< 32; i
++) {
8482 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
8483 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
8486 if (!SIGN_EXT_P(env
->CP0_EPC
))
8487 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8488 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
8489 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
8493 void cpu_dump_state (CPUState
*env
, FILE *f
,
8494 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8499 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",
8500 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
8501 env
->hflags
, env
->btarget
, env
->bcond
);
8502 for (i
= 0; i
< 32; i
++) {
8504 cpu_fprintf(f
, "GPR%02d:", i
);
8505 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
8507 cpu_fprintf(f
, "\n");
8510 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8511 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8512 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8513 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
8514 if (env
->hflags
& MIPS_HFLAG_FPU
)
8515 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8516 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8517 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8521 static void mips_tcg_init(void)
8526 /* Initialize various static tables. */
8530 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
8531 TCGV_UNUSED(cpu_gpr
[0]);
8532 for (i
= 1; i
< 32; i
++)
8533 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
8534 offsetof(CPUState
, active_tc
.gpr
[i
]),
8536 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
8537 offsetof(CPUState
, active_tc
.PC
), "PC");
8538 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
8539 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
8540 offsetof(CPUState
, active_tc
.HI
[i
]),
8542 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
8543 offsetof(CPUState
, active_tc
.LO
[i
]),
8545 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
8546 offsetof(CPUState
, active_tc
.ACX
[i
]),
8549 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
8550 offsetof(CPUState
, active_tc
.DSPControl
),
8552 bcond
= tcg_global_mem_new(TCG_AREG0
,
8553 offsetof(CPUState
, bcond
), "bcond");
8554 btarget
= tcg_global_mem_new(TCG_AREG0
,
8555 offsetof(CPUState
, btarget
), "btarget");
8556 hflags
= tcg_global_mem_new_i32(TCG_AREG0
,
8557 offsetof(CPUState
, hflags
), "hflags");
8559 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
8560 offsetof(CPUState
, active_fpu
.fcr0
),
8562 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
8563 offsetof(CPUState
, active_fpu
.fcr31
),
8566 /* register helpers */
8567 #define GEN_HELPER 2
8573 #include "translate_init.c"
8575 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8578 const mips_def_t
*def
;
8580 def
= cpu_mips_find_by_name(cpu_model
);
8583 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8584 env
->cpu_model
= def
;
8587 env
->cpu_model_str
= cpu_model
;
8590 qemu_init_vcpu(env
);
8594 void cpu_reset (CPUMIPSState
*env
)
8596 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
8597 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
8598 log_cpu_state(env
, 0);
8601 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8606 #if defined(CONFIG_USER_ONLY)
8607 env
->hflags
= MIPS_HFLAG_UM
;
8608 /* Enable access to the SYNCI_Step register. */
8609 env
->CP0_HWREna
|= (1 << 1);
8611 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8612 /* If the exception was raised from a delay slot,
8613 come back to the jump. */
8614 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
8616 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
8618 env
->active_tc
.PC
= (int32_t)0xBFC00000;
8620 /* SMP not implemented */
8621 env
->CP0_EBase
= 0x80000000;
8622 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8623 /* vectored interrupts not implemented, timer on int 7,
8624 no performance counters. */
8625 env
->CP0_IntCtl
= 0xe0000000;
8629 for (i
= 0; i
< 7; i
++) {
8630 env
->CP0_WatchLo
[i
] = 0;
8631 env
->CP0_WatchHi
[i
] = 0x80000000;
8633 env
->CP0_WatchLo
[7] = 0;
8634 env
->CP0_WatchHi
[7] = 0;
8636 /* Count register increments in debug mode, EJTAG version 1 */
8637 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8638 env
->hflags
= MIPS_HFLAG_CP0
;
8640 env
->exception_index
= EXCP_NONE
;
8641 cpu_mips_register(env
, env
->cpu_model
);
8644 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8645 unsigned long searched_pc
, int pc_pos
, void *puc
)
8647 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
8648 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8649 env
->hflags
|= gen_opc_hflags
[pc_pos
];