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
41 //#define MIPS_SINGLE_STEP
43 /* MIPS major opcodes */
44 #define MASK_OP_MAJOR(op) (op & (0x3F << 26))
47 /* indirect opcode tables */
48 OPC_SPECIAL
= (0x00 << 26),
49 OPC_REGIMM
= (0x01 << 26),
50 OPC_CP0
= (0x10 << 26),
51 OPC_CP1
= (0x11 << 26),
52 OPC_CP2
= (0x12 << 26),
53 OPC_CP3
= (0x13 << 26),
54 OPC_SPECIAL2
= (0x1C << 26),
55 OPC_SPECIAL3
= (0x1F << 26),
56 /* arithmetic with immediate */
57 OPC_ADDI
= (0x08 << 26),
58 OPC_ADDIU
= (0x09 << 26),
59 OPC_SLTI
= (0x0A << 26),
60 OPC_SLTIU
= (0x0B << 26),
61 OPC_ANDI
= (0x0C << 26),
62 OPC_ORI
= (0x0D << 26),
63 OPC_XORI
= (0x0E << 26),
64 OPC_LUI
= (0x0F << 26),
65 OPC_DADDI
= (0x18 << 26),
66 OPC_DADDIU
= (0x19 << 26),
67 /* Jump and branches */
69 OPC_JAL
= (0x03 << 26),
70 OPC_BEQ
= (0x04 << 26), /* Unconditional if rs = rt = 0 (B) */
71 OPC_BEQL
= (0x14 << 26),
72 OPC_BNE
= (0x05 << 26),
73 OPC_BNEL
= (0x15 << 26),
74 OPC_BLEZ
= (0x06 << 26),
75 OPC_BLEZL
= (0x16 << 26),
76 OPC_BGTZ
= (0x07 << 26),
77 OPC_BGTZL
= (0x17 << 26),
78 OPC_JALX
= (0x1D << 26), /* MIPS 16 only */
80 OPC_LDL
= (0x1A << 26),
81 OPC_LDR
= (0x1B << 26),
82 OPC_LB
= (0x20 << 26),
83 OPC_LH
= (0x21 << 26),
84 OPC_LWL
= (0x22 << 26),
85 OPC_LW
= (0x23 << 26),
86 OPC_LBU
= (0x24 << 26),
87 OPC_LHU
= (0x25 << 26),
88 OPC_LWR
= (0x26 << 26),
89 OPC_LWU
= (0x27 << 26),
90 OPC_SB
= (0x28 << 26),
91 OPC_SH
= (0x29 << 26),
92 OPC_SWL
= (0x2A << 26),
93 OPC_SW
= (0x2B << 26),
94 OPC_SDL
= (0x2C << 26),
95 OPC_SDR
= (0x2D << 26),
96 OPC_SWR
= (0x2E << 26),
97 OPC_LL
= (0x30 << 26),
98 OPC_LLD
= (0x34 << 26),
99 OPC_LD
= (0x37 << 26),
100 OPC_SC
= (0x38 << 26),
101 OPC_SCD
= (0x3C << 26),
102 OPC_SD
= (0x3F << 26),
103 /* Floating point load/store */
104 OPC_LWC1
= (0x31 << 26),
105 OPC_LWC2
= (0x32 << 26),
106 OPC_LDC1
= (0x35 << 26),
107 OPC_LDC2
= (0x36 << 26),
108 OPC_SWC1
= (0x39 << 26),
109 OPC_SWC2
= (0x3A << 26),
110 OPC_SDC1
= (0x3D << 26),
111 OPC_SDC2
= (0x3E << 26),
112 /* MDMX ASE specific */
113 OPC_MDMX
= (0x1E << 26),
114 /* Cache and prefetch */
115 OPC_CACHE
= (0x2F << 26),
116 OPC_PREF
= (0x33 << 26),
117 /* Reserved major opcode */
118 OPC_MAJOR3B_RESERVED
= (0x3B << 26),
121 /* MIPS special opcodes */
122 #define MASK_SPECIAL(op) MASK_OP_MAJOR(op) | (op & 0x3F)
126 OPC_SLL
= 0x00 | OPC_SPECIAL
,
127 /* NOP is SLL r0, r0, 0 */
128 /* SSNOP is SLL r0, r0, 1 */
129 /* EHB is SLL r0, r0, 3 */
130 OPC_SRL
= 0x02 | OPC_SPECIAL
, /* also ROTR */
131 OPC_SRA
= 0x03 | OPC_SPECIAL
,
132 OPC_SLLV
= 0x04 | OPC_SPECIAL
,
133 OPC_SRLV
= 0x06 | OPC_SPECIAL
, /* also ROTRV */
134 OPC_SRAV
= 0x07 | OPC_SPECIAL
,
135 OPC_DSLLV
= 0x14 | OPC_SPECIAL
,
136 OPC_DSRLV
= 0x16 | OPC_SPECIAL
, /* also DROTRV */
137 OPC_DSRAV
= 0x17 | OPC_SPECIAL
,
138 OPC_DSLL
= 0x38 | OPC_SPECIAL
,
139 OPC_DSRL
= 0x3A | OPC_SPECIAL
, /* also DROTR */
140 OPC_DSRA
= 0x3B | OPC_SPECIAL
,
141 OPC_DSLL32
= 0x3C | OPC_SPECIAL
,
142 OPC_DSRL32
= 0x3E | OPC_SPECIAL
, /* also DROTR32 */
143 OPC_DSRA32
= 0x3F | OPC_SPECIAL
,
144 /* Multiplication / division */
145 OPC_MULT
= 0x18 | OPC_SPECIAL
,
146 OPC_MULTU
= 0x19 | OPC_SPECIAL
,
147 OPC_DIV
= 0x1A | OPC_SPECIAL
,
148 OPC_DIVU
= 0x1B | OPC_SPECIAL
,
149 OPC_DMULT
= 0x1C | OPC_SPECIAL
,
150 OPC_DMULTU
= 0x1D | OPC_SPECIAL
,
151 OPC_DDIV
= 0x1E | OPC_SPECIAL
,
152 OPC_DDIVU
= 0x1F | OPC_SPECIAL
,
153 /* 2 registers arithmetic / logic */
154 OPC_ADD
= 0x20 | OPC_SPECIAL
,
155 OPC_ADDU
= 0x21 | OPC_SPECIAL
,
156 OPC_SUB
= 0x22 | OPC_SPECIAL
,
157 OPC_SUBU
= 0x23 | OPC_SPECIAL
,
158 OPC_AND
= 0x24 | OPC_SPECIAL
,
159 OPC_OR
= 0x25 | OPC_SPECIAL
,
160 OPC_XOR
= 0x26 | OPC_SPECIAL
,
161 OPC_NOR
= 0x27 | OPC_SPECIAL
,
162 OPC_SLT
= 0x2A | OPC_SPECIAL
,
163 OPC_SLTU
= 0x2B | OPC_SPECIAL
,
164 OPC_DADD
= 0x2C | OPC_SPECIAL
,
165 OPC_DADDU
= 0x2D | OPC_SPECIAL
,
166 OPC_DSUB
= 0x2E | OPC_SPECIAL
,
167 OPC_DSUBU
= 0x2F | OPC_SPECIAL
,
169 OPC_JR
= 0x08 | OPC_SPECIAL
, /* Also JR.HB */
170 OPC_JALR
= 0x09 | OPC_SPECIAL
, /* Also JALR.HB */
172 OPC_TGE
= 0x30 | OPC_SPECIAL
,
173 OPC_TGEU
= 0x31 | OPC_SPECIAL
,
174 OPC_TLT
= 0x32 | OPC_SPECIAL
,
175 OPC_TLTU
= 0x33 | OPC_SPECIAL
,
176 OPC_TEQ
= 0x34 | OPC_SPECIAL
,
177 OPC_TNE
= 0x36 | OPC_SPECIAL
,
178 /* HI / LO registers load & stores */
179 OPC_MFHI
= 0x10 | OPC_SPECIAL
,
180 OPC_MTHI
= 0x11 | OPC_SPECIAL
,
181 OPC_MFLO
= 0x12 | OPC_SPECIAL
,
182 OPC_MTLO
= 0x13 | OPC_SPECIAL
,
183 /* Conditional moves */
184 OPC_MOVZ
= 0x0A | OPC_SPECIAL
,
185 OPC_MOVN
= 0x0B | OPC_SPECIAL
,
187 OPC_MOVCI
= 0x01 | OPC_SPECIAL
,
190 OPC_PMON
= 0x05 | OPC_SPECIAL
, /* inofficial */
191 OPC_SYSCALL
= 0x0C | OPC_SPECIAL
,
192 OPC_BREAK
= 0x0D | OPC_SPECIAL
,
193 OPC_SPIM
= 0x0E | OPC_SPECIAL
, /* inofficial */
194 OPC_SYNC
= 0x0F | OPC_SPECIAL
,
196 OPC_SPECIAL15_RESERVED
= 0x15 | OPC_SPECIAL
,
197 OPC_SPECIAL28_RESERVED
= 0x28 | OPC_SPECIAL
,
198 OPC_SPECIAL29_RESERVED
= 0x29 | OPC_SPECIAL
,
199 OPC_SPECIAL35_RESERVED
= 0x35 | OPC_SPECIAL
,
200 OPC_SPECIAL37_RESERVED
= 0x37 | OPC_SPECIAL
,
201 OPC_SPECIAL39_RESERVED
= 0x39 | OPC_SPECIAL
,
202 OPC_SPECIAL3D_RESERVED
= 0x3D | OPC_SPECIAL
,
205 /* Multiplication variants of the vr54xx. */
206 #define MASK_MUL_VR54XX(op) MASK_SPECIAL(op) | (op & (0x1F << 6))
209 OPC_VR54XX_MULS
= (0x03 << 6) | OPC_MULT
,
210 OPC_VR54XX_MULSU
= (0x03 << 6) | OPC_MULTU
,
211 OPC_VR54XX_MACC
= (0x05 << 6) | OPC_MULT
,
212 OPC_VR54XX_MACCU
= (0x05 << 6) | OPC_MULTU
,
213 OPC_VR54XX_MSAC
= (0x07 << 6) | OPC_MULT
,
214 OPC_VR54XX_MSACU
= (0x07 << 6) | OPC_MULTU
,
215 OPC_VR54XX_MULHI
= (0x09 << 6) | OPC_MULT
,
216 OPC_VR54XX_MULHIU
= (0x09 << 6) | OPC_MULTU
,
217 OPC_VR54XX_MULSHI
= (0x0B << 6) | OPC_MULT
,
218 OPC_VR54XX_MULSHIU
= (0x0B << 6) | OPC_MULTU
,
219 OPC_VR54XX_MACCHI
= (0x0D << 6) | OPC_MULT
,
220 OPC_VR54XX_MACCHIU
= (0x0D << 6) | OPC_MULTU
,
221 OPC_VR54XX_MSACHI
= (0x0F << 6) | OPC_MULT
,
222 OPC_VR54XX_MSACHIU
= (0x0F << 6) | OPC_MULTU
,
225 /* REGIMM (rt field) opcodes */
226 #define MASK_REGIMM(op) MASK_OP_MAJOR(op) | (op & (0x1F << 16))
229 OPC_BLTZ
= (0x00 << 16) | OPC_REGIMM
,
230 OPC_BLTZL
= (0x02 << 16) | OPC_REGIMM
,
231 OPC_BGEZ
= (0x01 << 16) | OPC_REGIMM
,
232 OPC_BGEZL
= (0x03 << 16) | OPC_REGIMM
,
233 OPC_BLTZAL
= (0x10 << 16) | OPC_REGIMM
,
234 OPC_BLTZALL
= (0x12 << 16) | OPC_REGIMM
,
235 OPC_BGEZAL
= (0x11 << 16) | OPC_REGIMM
,
236 OPC_BGEZALL
= (0x13 << 16) | OPC_REGIMM
,
237 OPC_TGEI
= (0x08 << 16) | OPC_REGIMM
,
238 OPC_TGEIU
= (0x09 << 16) | OPC_REGIMM
,
239 OPC_TLTI
= (0x0A << 16) | OPC_REGIMM
,
240 OPC_TLTIU
= (0x0B << 16) | OPC_REGIMM
,
241 OPC_TEQI
= (0x0C << 16) | OPC_REGIMM
,
242 OPC_TNEI
= (0x0E << 16) | OPC_REGIMM
,
243 OPC_SYNCI
= (0x1F << 16) | OPC_REGIMM
,
246 /* Special2 opcodes */
247 #define MASK_SPECIAL2(op) MASK_OP_MAJOR(op) | (op & 0x3F)
250 /* Multiply & xxx operations */
251 OPC_MADD
= 0x00 | OPC_SPECIAL2
,
252 OPC_MADDU
= 0x01 | OPC_SPECIAL2
,
253 OPC_MUL
= 0x02 | OPC_SPECIAL2
,
254 OPC_MSUB
= 0x04 | OPC_SPECIAL2
,
255 OPC_MSUBU
= 0x05 | OPC_SPECIAL2
,
257 OPC_CLZ
= 0x20 | OPC_SPECIAL2
,
258 OPC_CLO
= 0x21 | OPC_SPECIAL2
,
259 OPC_DCLZ
= 0x24 | OPC_SPECIAL2
,
260 OPC_DCLO
= 0x25 | OPC_SPECIAL2
,
262 OPC_SDBBP
= 0x3F | OPC_SPECIAL2
,
265 /* Special3 opcodes */
266 #define MASK_SPECIAL3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
269 OPC_EXT
= 0x00 | OPC_SPECIAL3
,
270 OPC_DEXTM
= 0x01 | OPC_SPECIAL3
,
271 OPC_DEXTU
= 0x02 | OPC_SPECIAL3
,
272 OPC_DEXT
= 0x03 | OPC_SPECIAL3
,
273 OPC_INS
= 0x04 | OPC_SPECIAL3
,
274 OPC_DINSM
= 0x05 | OPC_SPECIAL3
,
275 OPC_DINSU
= 0x06 | OPC_SPECIAL3
,
276 OPC_DINS
= 0x07 | OPC_SPECIAL3
,
277 OPC_FORK
= 0x08 | OPC_SPECIAL3
,
278 OPC_YIELD
= 0x09 | OPC_SPECIAL3
,
279 OPC_BSHFL
= 0x20 | OPC_SPECIAL3
,
280 OPC_DBSHFL
= 0x24 | OPC_SPECIAL3
,
281 OPC_RDHWR
= 0x3B | OPC_SPECIAL3
,
285 #define MASK_BSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
288 OPC_WSBH
= (0x02 << 6) | OPC_BSHFL
,
289 OPC_SEB
= (0x10 << 6) | OPC_BSHFL
,
290 OPC_SEH
= (0x18 << 6) | OPC_BSHFL
,
294 #define MASK_DBSHFL(op) MASK_SPECIAL3(op) | (op & (0x1F << 6))
297 OPC_DSBH
= (0x02 << 6) | OPC_DBSHFL
,
298 OPC_DSHD
= (0x05 << 6) | OPC_DBSHFL
,
301 /* Coprocessor 0 (rs field) */
302 #define MASK_CP0(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
305 OPC_MFC0
= (0x00 << 21) | OPC_CP0
,
306 OPC_DMFC0
= (0x01 << 21) | OPC_CP0
,
307 OPC_MTC0
= (0x04 << 21) | OPC_CP0
,
308 OPC_DMTC0
= (0x05 << 21) | OPC_CP0
,
309 OPC_MFTR
= (0x08 << 21) | OPC_CP0
,
310 OPC_RDPGPR
= (0x0A << 21) | OPC_CP0
,
311 OPC_MFMC0
= (0x0B << 21) | OPC_CP0
,
312 OPC_MTTR
= (0x0C << 21) | OPC_CP0
,
313 OPC_WRPGPR
= (0x0E << 21) | OPC_CP0
,
314 OPC_C0
= (0x10 << 21) | OPC_CP0
,
315 OPC_C0_FIRST
= (0x10 << 21) | OPC_CP0
,
316 OPC_C0_LAST
= (0x1F << 21) | OPC_CP0
,
320 #define MASK_MFMC0(op) MASK_CP0(op) | (op & 0xFFFF)
323 OPC_DMT
= 0x01 | (0 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
324 OPC_EMT
= 0x01 | (1 << 5) | (0x0F << 6) | (0x01 << 11) | OPC_MFMC0
,
325 OPC_DVPE
= 0x01 | (0 << 5) | OPC_MFMC0
,
326 OPC_EVPE
= 0x01 | (1 << 5) | OPC_MFMC0
,
327 OPC_DI
= (0 << 5) | (0x0C << 11) | OPC_MFMC0
,
328 OPC_EI
= (1 << 5) | (0x0C << 11) | OPC_MFMC0
,
331 /* Coprocessor 0 (with rs == C0) */
332 #define MASK_C0(op) MASK_CP0(op) | (op & 0x3F)
335 OPC_TLBR
= 0x01 | OPC_C0
,
336 OPC_TLBWI
= 0x02 | OPC_C0
,
337 OPC_TLBWR
= 0x06 | OPC_C0
,
338 OPC_TLBP
= 0x08 | OPC_C0
,
339 OPC_RFE
= 0x10 | OPC_C0
,
340 OPC_ERET
= 0x18 | OPC_C0
,
341 OPC_DERET
= 0x1F | OPC_C0
,
342 OPC_WAIT
= 0x20 | OPC_C0
,
345 /* Coprocessor 1 (rs field) */
346 #define MASK_CP1(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
349 OPC_MFC1
= (0x00 << 21) | OPC_CP1
,
350 OPC_DMFC1
= (0x01 << 21) | OPC_CP1
,
351 OPC_CFC1
= (0x02 << 21) | OPC_CP1
,
352 OPC_MFHC1
= (0x03 << 21) | OPC_CP1
,
353 OPC_MTC1
= (0x04 << 21) | OPC_CP1
,
354 OPC_DMTC1
= (0x05 << 21) | OPC_CP1
,
355 OPC_CTC1
= (0x06 << 21) | OPC_CP1
,
356 OPC_MTHC1
= (0x07 << 21) | OPC_CP1
,
357 OPC_BC1
= (0x08 << 21) | OPC_CP1
, /* bc */
358 OPC_BC1ANY2
= (0x09 << 21) | OPC_CP1
,
359 OPC_BC1ANY4
= (0x0A << 21) | OPC_CP1
,
360 OPC_S_FMT
= (0x10 << 21) | OPC_CP1
, /* 16: fmt=single fp */
361 OPC_D_FMT
= (0x11 << 21) | OPC_CP1
, /* 17: fmt=double fp */
362 OPC_E_FMT
= (0x12 << 21) | OPC_CP1
, /* 18: fmt=extended fp */
363 OPC_Q_FMT
= (0x13 << 21) | OPC_CP1
, /* 19: fmt=quad fp */
364 OPC_W_FMT
= (0x14 << 21) | OPC_CP1
, /* 20: fmt=32bit fixed */
365 OPC_L_FMT
= (0x15 << 21) | OPC_CP1
, /* 21: fmt=64bit fixed */
366 OPC_PS_FMT
= (0x16 << 21) | OPC_CP1
, /* 22: fmt=paired single fp */
369 #define MASK_CP1_FUNC(op) MASK_CP1(op) | (op & 0x3F)
370 #define MASK_BC1(op) MASK_CP1(op) | (op & (0x3 << 16))
373 OPC_BC1F
= (0x00 << 16) | OPC_BC1
,
374 OPC_BC1T
= (0x01 << 16) | OPC_BC1
,
375 OPC_BC1FL
= (0x02 << 16) | OPC_BC1
,
376 OPC_BC1TL
= (0x03 << 16) | OPC_BC1
,
380 OPC_BC1FANY2
= (0x00 << 16) | OPC_BC1ANY2
,
381 OPC_BC1TANY2
= (0x01 << 16) | OPC_BC1ANY2
,
385 OPC_BC1FANY4
= (0x00 << 16) | OPC_BC1ANY4
,
386 OPC_BC1TANY4
= (0x01 << 16) | OPC_BC1ANY4
,
389 #define MASK_CP2(op) MASK_OP_MAJOR(op) | (op & (0x1F << 21))
392 OPC_MFC2
= (0x00 << 21) | OPC_CP2
,
393 OPC_DMFC2
= (0x01 << 21) | OPC_CP2
,
394 OPC_CFC2
= (0x02 << 21) | OPC_CP2
,
395 OPC_MFHC2
= (0x03 << 21) | OPC_CP2
,
396 OPC_MTC2
= (0x04 << 21) | OPC_CP2
,
397 OPC_DMTC2
= (0x05 << 21) | OPC_CP2
,
398 OPC_CTC2
= (0x06 << 21) | OPC_CP2
,
399 OPC_MTHC2
= (0x07 << 21) | OPC_CP2
,
400 OPC_BC2
= (0x08 << 21) | OPC_CP2
,
403 #define MASK_CP3(op) MASK_OP_MAJOR(op) | (op & 0x3F)
406 OPC_LWXC1
= 0x00 | OPC_CP3
,
407 OPC_LDXC1
= 0x01 | OPC_CP3
,
408 OPC_LUXC1
= 0x05 | OPC_CP3
,
409 OPC_SWXC1
= 0x08 | OPC_CP3
,
410 OPC_SDXC1
= 0x09 | OPC_CP3
,
411 OPC_SUXC1
= 0x0D | OPC_CP3
,
412 OPC_PREFX
= 0x0F | OPC_CP3
,
413 OPC_ALNV_PS
= 0x1E | OPC_CP3
,
414 OPC_MADD_S
= 0x20 | OPC_CP3
,
415 OPC_MADD_D
= 0x21 | OPC_CP3
,
416 OPC_MADD_PS
= 0x26 | OPC_CP3
,
417 OPC_MSUB_S
= 0x28 | OPC_CP3
,
418 OPC_MSUB_D
= 0x29 | OPC_CP3
,
419 OPC_MSUB_PS
= 0x2E | OPC_CP3
,
420 OPC_NMADD_S
= 0x30 | OPC_CP3
,
421 OPC_NMADD_D
= 0x31 | OPC_CP3
,
422 OPC_NMADD_PS
= 0x36 | OPC_CP3
,
423 OPC_NMSUB_S
= 0x38 | OPC_CP3
,
424 OPC_NMSUB_D
= 0x39 | OPC_CP3
,
425 OPC_NMSUB_PS
= 0x3E | OPC_CP3
,
428 /* global register indices */
429 static TCGv_ptr cpu_env
;
430 static TCGv cpu_gpr
[32], cpu_PC
;
431 static TCGv cpu_HI
[MIPS_DSP_ACC
], cpu_LO
[MIPS_DSP_ACC
], cpu_ACX
[MIPS_DSP_ACC
];
432 static TCGv cpu_dspctrl
, btarget
;
433 static TCGv_i32 bcond
;
434 static TCGv_i32 fpu_fpr32
[32], fpu_fpr32h
[32];
435 static TCGv_i64 fpu_fpr64
[32];
436 static TCGv_i32 fpu_fcr0
, fpu_fcr31
;
438 #include "gen-icount.h"
440 #define gen_helper_0i(name, arg) do { \
441 TCGv_i32 helper_tmp = tcg_const_i32(arg); \
442 gen_helper_##name(helper_tmp); \
443 tcg_temp_free_i32(helper_tmp); \
446 #define gen_helper_1i(name, arg1, arg2) do { \
447 TCGv_i32 helper_tmp = tcg_const_i32(arg2); \
448 gen_helper_##name(arg1, helper_tmp); \
449 tcg_temp_free_i32(helper_tmp); \
452 #define gen_helper_2i(name, arg1, arg2, arg3) do { \
453 TCGv_i32 helper_tmp = tcg_const_i32(arg3); \
454 gen_helper_##name(arg1, arg2, helper_tmp); \
455 tcg_temp_free_i32(helper_tmp); \
458 #define gen_helper_3i(name, arg1, arg2, arg3, arg4) do { \
459 TCGv_i32 helper_tmp = tcg_const_i32(arg4); \
460 gen_helper_##name(arg1, arg2, arg3, helper_tmp); \
461 tcg_temp_free_i32(helper_tmp); \
464 typedef struct DisasContext
{
465 struct TranslationBlock
*tb
;
466 target_ulong pc
, saved_pc
;
468 /* Routine used to access memory */
470 uint32_t hflags
, saved_hflags
;
472 target_ulong btarget
;
476 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
477 * exception condition */
478 BS_STOP
= 1, /* We want to stop translation for any reason */
479 BS_BRANCH
= 2, /* We reached a branch condition */
480 BS_EXCP
= 3, /* We reached an exception condition */
483 static const char *regnames
[] =
484 { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
485 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
486 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
487 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", };
489 static const char *regnames_HI
[] =
490 { "HI0", "HI1", "HI2", "HI3", };
492 static const char *regnames_LO
[] =
493 { "LO0", "LO1", "LO2", "LO3", };
495 static const char *regnames_ACX
[] =
496 { "ACX0", "ACX1", "ACX2", "ACX3", };
498 static const char *fregnames
[] =
499 { "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
500 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
501 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
502 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", };
504 static const char *fregnames_64
[] =
505 { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
506 "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15",
507 "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23",
508 "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31", };
510 static const char *fregnames_h
[] =
511 { "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
512 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
513 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
514 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31", };
516 #ifdef MIPS_DEBUG_DISAS
517 #define MIPS_DEBUG(fmt, args...) \
518 qemu_log_mask(CPU_LOG_TB_IN_ASM, \
519 TARGET_FMT_lx ": %08x " fmt "\n", \
520 ctx->pc, ctx->opcode , ##args)
521 #define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
523 #define MIPS_DEBUG(fmt, args...) do { } while(0)
524 #define LOG_DISAS(...) do { } while (0)
527 #define MIPS_INVAL(op) \
529 MIPS_DEBUG("Invalid %s %03x %03x %03x", op, ctx->opcode >> 26, \
530 ctx->opcode & 0x3F, ((ctx->opcode >> 16) & 0x1F)); \
533 /* General purpose registers moves. */
534 static inline void gen_load_gpr (TCGv t
, int reg
)
537 tcg_gen_movi_tl(t
, 0);
539 tcg_gen_mov_tl(t
, cpu_gpr
[reg
]);
542 static inline void gen_store_gpr (TCGv t
, int reg
)
545 tcg_gen_mov_tl(cpu_gpr
[reg
], t
);
548 /* Moves to/from ACX register. */
549 static inline void gen_load_ACX (TCGv t
, int reg
)
551 tcg_gen_mov_tl(t
, cpu_ACX
[reg
]);
554 static inline void gen_store_ACX (TCGv t
, int reg
)
556 tcg_gen_mov_tl(cpu_ACX
[reg
], t
);
559 /* Moves to/from shadow registers. */
560 static inline void gen_load_srsgpr (int from
, int to
)
562 TCGv r_tmp1
= tcg_temp_new();
565 tcg_gen_movi_tl(r_tmp1
, 0);
567 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
568 TCGv_ptr addr
= tcg_temp_new_ptr();
570 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
571 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
572 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
573 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
574 tcg_gen_ext_i32_ptr(addr
, r_tmp2
);
575 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
577 tcg_gen_ld_tl(r_tmp1
, addr
, sizeof(target_ulong
) * from
);
578 tcg_temp_free_ptr(addr
);
579 tcg_temp_free_i32(r_tmp2
);
581 gen_store_gpr(r_tmp1
, to
);
582 tcg_temp_free(r_tmp1
);
585 static inline void gen_store_srsgpr (int from
, int to
)
588 TCGv r_tmp1
= tcg_temp_new();
589 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
590 TCGv_ptr addr
= tcg_temp_new_ptr();
592 gen_load_gpr(r_tmp1
, from
);
593 tcg_gen_ld_i32(r_tmp2
, cpu_env
, offsetof(CPUState
, CP0_SRSCtl
));
594 tcg_gen_shri_i32(r_tmp2
, r_tmp2
, CP0SRSCtl_PSS
);
595 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xf);
596 tcg_gen_muli_i32(r_tmp2
, r_tmp2
, sizeof(target_ulong
) * 32);
597 tcg_gen_ext_i32_ptr(addr
, r_tmp2
);
598 tcg_gen_add_ptr(addr
, cpu_env
, addr
);
600 tcg_gen_st_tl(r_tmp1
, addr
, sizeof(target_ulong
) * to
);
601 tcg_temp_free_ptr(addr
);
602 tcg_temp_free_i32(r_tmp2
);
603 tcg_temp_free(r_tmp1
);
607 /* Floating point register moves. */
608 static inline void gen_load_fpr32 (TCGv_i32 t
, int reg
)
610 tcg_gen_mov_i32(t
, fpu_fpr32
[reg
]);
613 static inline void gen_store_fpr32 (TCGv_i32 t
, int reg
)
615 tcg_gen_mov_i32(fpu_fpr32
[reg
], t
);
618 static inline void gen_load_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
620 if (ctx
->hflags
& MIPS_HFLAG_F64
)
621 tcg_gen_mov_i64(t
, fpu_fpr64
[reg
]);
623 tcg_gen_concat_i32_i64(t
, fpu_fpr32
[reg
& ~1], fpu_fpr32
[reg
| 1]);
627 static inline void gen_store_fpr64 (DisasContext
*ctx
, TCGv_i64 t
, int reg
)
629 if (ctx
->hflags
& MIPS_HFLAG_F64
)
630 tcg_gen_mov_i64(fpu_fpr64
[reg
], t
);
632 tcg_gen_trunc_i64_i32(fpu_fpr32
[reg
& ~1], t
);
633 tcg_gen_shri_i64(t
, t
, 32);
634 tcg_gen_trunc_i64_i32(fpu_fpr32
[reg
| 1], t
);
638 static inline void gen_load_fpr32h (TCGv_i32 t
, int reg
)
640 tcg_gen_mov_i32(t
, fpu_fpr32h
[reg
]);
643 static inline void gen_store_fpr32h (TCGv_i32 t
, int reg
)
645 tcg_gen_mov_i32(fpu_fpr32h
[reg
], t
);
648 static inline void get_fp_cond (TCGv_i32 t
)
650 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
651 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
653 tcg_gen_shri_i32(r_tmp2
, fpu_fcr31
, 24);
654 tcg_gen_andi_i32(r_tmp2
, r_tmp2
, 0xfe);
655 tcg_gen_shri_i32(r_tmp1
, fpu_fcr31
, 23);
656 tcg_gen_andi_i32(r_tmp1
, r_tmp1
, 0x1);
657 tcg_gen_or_i32(t
, r_tmp1
, r_tmp2
);
658 tcg_temp_free_i32(r_tmp1
);
659 tcg_temp_free_i32(r_tmp2
);
662 #define FOP_CONDS(type, fmt, bits) \
663 static inline void gen_cmp ## type ## _ ## fmt(int n, TCGv_i##bits a, \
664 TCGv_i##bits b, int cc) \
667 case 0: gen_helper_2i(cmp ## type ## _ ## fmt ## _f, a, b, cc); break;\
668 case 1: gen_helper_2i(cmp ## type ## _ ## fmt ## _un, a, b, cc); break;\
669 case 2: gen_helper_2i(cmp ## type ## _ ## fmt ## _eq, a, b, cc); break;\
670 case 3: gen_helper_2i(cmp ## type ## _ ## fmt ## _ueq, a, b, cc); break;\
671 case 4: gen_helper_2i(cmp ## type ## _ ## fmt ## _olt, a, b, cc); break;\
672 case 5: gen_helper_2i(cmp ## type ## _ ## fmt ## _ult, a, b, cc); break;\
673 case 6: gen_helper_2i(cmp ## type ## _ ## fmt ## _ole, a, b, cc); break;\
674 case 7: gen_helper_2i(cmp ## type ## _ ## fmt ## _ule, a, b, cc); break;\
675 case 8: gen_helper_2i(cmp ## type ## _ ## fmt ## _sf, a, b, cc); break;\
676 case 9: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngle, a, b, cc); break;\
677 case 10: gen_helper_2i(cmp ## type ## _ ## fmt ## _seq, a, b, cc); break;\
678 case 11: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngl, a, b, cc); break;\
679 case 12: gen_helper_2i(cmp ## type ## _ ## fmt ## _lt, a, b, cc); break;\
680 case 13: gen_helper_2i(cmp ## type ## _ ## fmt ## _nge, a, b, cc); break;\
681 case 14: gen_helper_2i(cmp ## type ## _ ## fmt ## _le, a, b, cc); break;\
682 case 15: gen_helper_2i(cmp ## type ## _ ## fmt ## _ngt, a, b, cc); break;\
688 FOP_CONDS(abs
, d
, 64)
690 FOP_CONDS(abs
, s
, 32)
692 FOP_CONDS(abs
, ps
, 64)
696 #define OP_COND(name, cond) \
697 static inline void glue(gen_op_, name) (TCGv t0, TCGv t1) \
699 int l1 = gen_new_label(); \
700 int l2 = gen_new_label(); \
702 tcg_gen_brcond_tl(cond, t0, t1, l1); \
703 tcg_gen_movi_tl(t0, 0); \
706 tcg_gen_movi_tl(t0, 1); \
709 OP_COND(eq
, TCG_COND_EQ
);
710 OP_COND(ne
, TCG_COND_NE
);
711 OP_COND(ge
, TCG_COND_GE
);
712 OP_COND(geu
, TCG_COND_GEU
);
713 OP_COND(lt
, TCG_COND_LT
);
714 OP_COND(ltu
, TCG_COND_LTU
);
717 #define OP_CONDI(name, cond) \
718 static inline void glue(gen_op_, name) (TCGv t, target_ulong val) \
720 int l1 = gen_new_label(); \
721 int l2 = gen_new_label(); \
723 tcg_gen_brcondi_tl(cond, t, val, l1); \
724 tcg_gen_movi_tl(t, 0); \
727 tcg_gen_movi_tl(t, 1); \
730 OP_CONDI(lti
, TCG_COND_LT
);
731 OP_CONDI(ltiu
, TCG_COND_LTU
);
734 #define OP_CONDZ(name, cond) \
735 static inline void glue(gen_op_, name) (TCGv t) \
737 int l1 = gen_new_label(); \
738 int l2 = gen_new_label(); \
740 tcg_gen_brcondi_tl(cond, t, 0, l1); \
741 tcg_gen_movi_tl(t, 0); \
744 tcg_gen_movi_tl(t, 1); \
747 OP_CONDZ(gez
, TCG_COND_GE
);
748 OP_CONDZ(gtz
, TCG_COND_GT
);
749 OP_CONDZ(lez
, TCG_COND_LE
);
750 OP_CONDZ(ltz
, TCG_COND_LT
);
753 static inline void gen_save_pc(target_ulong pc
)
755 tcg_gen_movi_tl(cpu_PC
, pc
);
758 static inline void save_cpu_state (DisasContext
*ctx
, int do_save_pc
)
760 LOG_DISAS("hflags %08x saved %08x\n", ctx
->hflags
, ctx
->saved_hflags
);
761 if (do_save_pc
&& ctx
->pc
!= ctx
->saved_pc
) {
762 gen_save_pc(ctx
->pc
);
763 ctx
->saved_pc
= ctx
->pc
;
765 if (ctx
->hflags
!= ctx
->saved_hflags
) {
766 TCGv_i32 r_tmp
= tcg_temp_new_i32();
768 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
);
769 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
770 tcg_temp_free_i32(r_tmp
);
771 ctx
->saved_hflags
= ctx
->hflags
;
772 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
778 tcg_gen_movi_tl(btarget
, ctx
->btarget
);
784 static inline void restore_cpu_state (CPUState
*env
, DisasContext
*ctx
)
786 ctx
->saved_hflags
= ctx
->hflags
;
787 switch (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
793 ctx
->btarget
= env
->btarget
;
799 generate_exception_err (DisasContext
*ctx
, int excp
, int err
)
801 TCGv_i32 texcp
= tcg_const_i32(excp
);
802 TCGv_i32 terr
= tcg_const_i32(err
);
803 save_cpu_state(ctx
, 1);
804 gen_helper_raise_exception_err(texcp
, terr
);
805 tcg_temp_free_i32(terr
);
806 tcg_temp_free_i32(texcp
);
807 gen_helper_interrupt_restart();
812 generate_exception (DisasContext
*ctx
, int excp
)
814 save_cpu_state(ctx
, 1);
815 gen_helper_0i(raise_exception
, excp
);
816 gen_helper_interrupt_restart();
820 /* Addresses computation */
821 static inline void gen_op_addr_add (DisasContext
*ctx
, TCGv t0
, TCGv t1
)
823 tcg_gen_add_tl(t0
, t0
, t1
);
825 #if defined(TARGET_MIPS64)
826 /* For compatibility with 32-bit code, data reference in user mode
827 with Status_UX = 0 should be casted to 32-bit and sign extended.
828 See the MIPS64 PRA manual, section 4.10. */
829 if (((ctx
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
830 !(ctx
->hflags
& MIPS_HFLAG_UX
)) {
831 tcg_gen_ext32s_i64(t0
, t0
);
836 static inline void check_cp0_enabled(DisasContext
*ctx
)
838 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_CP0
)))
839 generate_exception_err(ctx
, EXCP_CpU
, 1);
842 static inline void check_cp1_enabled(DisasContext
*ctx
)
844 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_FPU
)))
845 generate_exception_err(ctx
, EXCP_CpU
, 1);
848 /* Verify that the processor is running with COP1X instructions enabled.
849 This is associated with the nabla symbol in the MIPS32 and MIPS64
852 static inline void check_cop1x(DisasContext
*ctx
)
854 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_COP1X
)))
855 generate_exception(ctx
, EXCP_RI
);
858 /* Verify that the processor is running with 64-bit floating-point
859 operations enabled. */
861 static inline void check_cp1_64bitmode(DisasContext
*ctx
)
863 if (unlikely(~ctx
->hflags
& (MIPS_HFLAG_F64
| MIPS_HFLAG_COP1X
)))
864 generate_exception(ctx
, EXCP_RI
);
868 * Verify if floating point register is valid; an operation is not defined
869 * if bit 0 of any register specification is set and the FR bit in the
870 * Status register equals zero, since the register numbers specify an
871 * even-odd pair of adjacent coprocessor general registers. When the FR bit
872 * in the Status register equals one, both even and odd register numbers
873 * are valid. This limitation exists only for 64 bit wide (d,l,ps) registers.
875 * Multiple 64 bit wide registers can be checked by calling
876 * gen_op_cp1_registers(freg1 | freg2 | ... | fregN);
878 static inline void check_cp1_registers(DisasContext
*ctx
, int regs
)
880 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_F64
) && (regs
& 1)))
881 generate_exception(ctx
, EXCP_RI
);
884 /* This code generates a "reserved instruction" exception if the
885 CPU does not support the instruction set corresponding to flags. */
886 static inline void check_insn(CPUState
*env
, DisasContext
*ctx
, int flags
)
888 if (unlikely(!(env
->insn_flags
& flags
)))
889 generate_exception(ctx
, EXCP_RI
);
892 /* This code generates a "reserved instruction" exception if 64-bit
893 instructions are not enabled. */
894 static inline void check_mips_64(DisasContext
*ctx
)
896 if (unlikely(!(ctx
->hflags
& MIPS_HFLAG_64
)))
897 generate_exception(ctx
, EXCP_RI
);
900 /* load/store instructions. */
901 #define OP_LD(insn,fname) \
902 static inline void op_ldst_##insn(TCGv t0, DisasContext *ctx) \
904 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
911 #if defined(TARGET_MIPS64)
917 #define OP_ST(insn,fname) \
918 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
920 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
925 #if defined(TARGET_MIPS64)
930 #define OP_LD_ATOMIC(insn,fname) \
931 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
933 tcg_gen_mov_tl(t1, t0); \
934 tcg_gen_qemu_##fname(t0, t0, ctx->mem_idx); \
935 tcg_gen_st_tl(t1, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
937 OP_LD_ATOMIC(ll
,ld32s
);
938 #if defined(TARGET_MIPS64)
939 OP_LD_ATOMIC(lld
,ld64
);
943 #define OP_ST_ATOMIC(insn,fname,almask) \
944 static inline void op_ldst_##insn(TCGv t0, TCGv t1, DisasContext *ctx) \
946 TCGv r_tmp = tcg_temp_local_new(); \
947 int l1 = gen_new_label(); \
948 int l2 = gen_new_label(); \
949 int l3 = gen_new_label(); \
951 tcg_gen_andi_tl(r_tmp, t0, almask); \
952 tcg_gen_brcondi_tl(TCG_COND_EQ, r_tmp, 0, l1); \
953 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, CP0_BadVAddr)); \
954 generate_exception(ctx, EXCP_AdES); \
956 tcg_gen_ld_tl(r_tmp, cpu_env, offsetof(CPUState, CP0_LLAddr)); \
957 tcg_gen_brcond_tl(TCG_COND_NE, t0, r_tmp, l2); \
958 tcg_gen_qemu_##fname(t1, t0, ctx->mem_idx); \
959 tcg_gen_movi_tl(t0, 1); \
962 tcg_gen_movi_tl(t0, 0); \
964 tcg_temp_free(r_tmp); \
966 OP_ST_ATOMIC(sc
,st32
,0x3);
967 #if defined(TARGET_MIPS64)
968 OP_ST_ATOMIC(scd
,st64
,0x7);
973 static void gen_ldst (DisasContext
*ctx
, uint32_t opc
, int rt
,
974 int base
, int16_t offset
)
976 const char *opn
= "ldst";
977 TCGv t0
= tcg_temp_local_new();
978 TCGv t1
= tcg_temp_local_new();
981 tcg_gen_movi_tl(t0
, offset
);
982 } else if (offset
== 0) {
983 gen_load_gpr(t0
, base
);
985 tcg_gen_movi_tl(t0
, offset
);
986 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
988 /* Don't do NOP if destination is zero: we must perform the actual
991 #if defined(TARGET_MIPS64)
993 op_ldst_lwu(t0
, ctx
);
994 gen_store_gpr(t0
, rt
);
999 gen_store_gpr(t0
, rt
);
1003 op_ldst_lld(t0
, t1
, ctx
);
1004 gen_store_gpr(t0
, rt
);
1008 gen_load_gpr(t1
, rt
);
1009 op_ldst_sd(t0
, t1
, ctx
);
1013 save_cpu_state(ctx
, 1);
1014 gen_load_gpr(t1
, rt
);
1015 op_ldst_scd(t0
, t1
, ctx
);
1016 gen_store_gpr(t0
, rt
);
1020 save_cpu_state(ctx
, 1);
1021 gen_load_gpr(t1
, rt
);
1022 gen_helper_3i(ldl
, t1
, t0
, t1
, ctx
->mem_idx
);
1023 gen_store_gpr(t1
, rt
);
1027 save_cpu_state(ctx
, 1);
1028 gen_load_gpr(t1
, rt
);
1029 gen_helper_2i(sdl
, t0
, t1
, ctx
->mem_idx
);
1033 save_cpu_state(ctx
, 1);
1034 gen_load_gpr(t1
, rt
);
1035 gen_helper_3i(ldr
, t1
, t0
, t1
, ctx
->mem_idx
);
1036 gen_store_gpr(t1
, rt
);
1040 save_cpu_state(ctx
, 1);
1041 gen_load_gpr(t1
, rt
);
1042 gen_helper_2i(sdr
, t0
, t1
, ctx
->mem_idx
);
1047 op_ldst_lw(t0
, ctx
);
1048 gen_store_gpr(t0
, rt
);
1052 gen_load_gpr(t1
, rt
);
1053 op_ldst_sw(t0
, t1
, ctx
);
1057 op_ldst_lh(t0
, ctx
);
1058 gen_store_gpr(t0
, rt
);
1062 gen_load_gpr(t1
, rt
);
1063 op_ldst_sh(t0
, t1
, ctx
);
1067 op_ldst_lhu(t0
, ctx
);
1068 gen_store_gpr(t0
, rt
);
1072 op_ldst_lb(t0
, ctx
);
1073 gen_store_gpr(t0
, rt
);
1077 gen_load_gpr(t1
, rt
);
1078 op_ldst_sb(t0
, t1
, ctx
);
1082 op_ldst_lbu(t0
, ctx
);
1083 gen_store_gpr(t0
, rt
);
1087 save_cpu_state(ctx
, 1);
1088 gen_load_gpr(t1
, rt
);
1089 gen_helper_3i(lwl
, t1
, t0
, t1
, ctx
->mem_idx
);
1090 gen_store_gpr(t1
, rt
);
1094 save_cpu_state(ctx
, 1);
1095 gen_load_gpr(t1
, rt
);
1096 gen_helper_2i(swl
, t0
, t1
, ctx
->mem_idx
);
1100 save_cpu_state(ctx
, 1);
1101 gen_load_gpr(t1
, rt
);
1102 gen_helper_3i(lwr
, t1
, t0
, t1
, ctx
->mem_idx
);
1103 gen_store_gpr(t1
, rt
);
1107 save_cpu_state(ctx
, 1);
1108 gen_load_gpr(t1
, rt
);
1109 gen_helper_2i(swr
, t0
, t1
, ctx
->mem_idx
);
1113 op_ldst_ll(t0
, t1
, ctx
);
1114 gen_store_gpr(t0
, rt
);
1118 save_cpu_state(ctx
, 1);
1119 gen_load_gpr(t1
, rt
);
1120 op_ldst_sc(t0
, t1
, ctx
);
1121 gen_store_gpr(t0
, rt
);
1126 generate_exception(ctx
, EXCP_RI
);
1129 MIPS_DEBUG("%s %s, %d(%s)", opn
, regnames
[rt
], offset
, regnames
[base
]);
1135 /* Load and store */
1136 static void gen_flt_ldst (DisasContext
*ctx
, uint32_t opc
, int ft
,
1137 int base
, int16_t offset
)
1139 const char *opn
= "flt_ldst";
1140 TCGv t0
= tcg_temp_local_new();
1143 tcg_gen_movi_tl(t0
, offset
);
1144 } else if (offset
== 0) {
1145 gen_load_gpr(t0
, base
);
1147 tcg_gen_movi_tl(t0
, offset
);
1148 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
1150 /* Don't do NOP if destination is zero: we must perform the actual
1155 TCGv_i32 fp0
= tcg_temp_new_i32();
1156 TCGv t1
= tcg_temp_new();
1158 tcg_gen_qemu_ld32s(t1
, t0
, ctx
->mem_idx
);
1159 tcg_gen_trunc_tl_i32(fp0
, t1
);
1160 gen_store_fpr32(fp0
, ft
);
1162 tcg_temp_free_i32(fp0
);
1168 TCGv_i32 fp0
= tcg_temp_new_i32();
1169 TCGv t1
= tcg_temp_new();
1171 gen_load_fpr32(fp0
, ft
);
1172 tcg_gen_extu_i32_tl(t1
, fp0
);
1173 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
1175 tcg_temp_free_i32(fp0
);
1181 TCGv_i64 fp0
= tcg_temp_new_i64();
1183 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
1184 gen_store_fpr64(ctx
, fp0
, ft
);
1185 tcg_temp_free_i64(fp0
);
1191 TCGv_i64 fp0
= tcg_temp_new_i64();
1193 gen_load_fpr64(ctx
, fp0
, ft
);
1194 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
1195 tcg_temp_free_i64(fp0
);
1201 generate_exception(ctx
, EXCP_RI
);
1204 MIPS_DEBUG("%s %s, %d(%s)", opn
, fregnames
[ft
], offset
, regnames
[base
]);
1209 /* Arithmetic with immediate operand */
1210 static void gen_arith_imm (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1211 int rt
, int rs
, int16_t imm
)
1214 const char *opn
= "imm arith";
1215 TCGv t0
= tcg_temp_local_new();
1217 if (rt
== 0 && opc
!= OPC_ADDI
&& opc
!= OPC_DADDI
) {
1218 /* If no destination, treat it as a NOP.
1219 For addi, we must generate the overflow exception when needed. */
1223 uimm
= (uint16_t)imm
;
1227 #if defined(TARGET_MIPS64)
1233 uimm
= (target_long
)imm
; /* Sign extend to 32/64 bits */
1238 gen_load_gpr(t0
, rs
);
1241 tcg_gen_movi_tl(t0
, imm
<< 16);
1246 #if defined(TARGET_MIPS64)
1255 gen_load_gpr(t0
, rs
);
1261 TCGv r_tmp1
= tcg_temp_new();
1262 TCGv r_tmp2
= tcg_temp_new();
1263 int l1
= gen_new_label();
1265 save_cpu_state(ctx
, 1);
1266 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1267 tcg_gen_addi_tl(t0
, r_tmp1
, uimm
);
1269 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, ~uimm
);
1270 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1271 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1272 tcg_temp_free(r_tmp2
);
1273 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1274 /* operands of same sign, result different sign */
1275 generate_exception(ctx
, EXCP_OVERFLOW
);
1277 tcg_temp_free(r_tmp1
);
1279 tcg_gen_ext32s_tl(t0
, t0
);
1284 tcg_gen_addi_tl(t0
, t0
, uimm
);
1285 tcg_gen_ext32s_tl(t0
, t0
);
1288 #if defined(TARGET_MIPS64)
1291 TCGv r_tmp1
= tcg_temp_new();
1292 TCGv r_tmp2
= tcg_temp_new();
1293 int l1
= gen_new_label();
1295 save_cpu_state(ctx
, 1);
1296 tcg_gen_mov_tl(r_tmp1
, t0
);
1297 tcg_gen_addi_tl(t0
, t0
, uimm
);
1299 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, ~uimm
);
1300 tcg_gen_xori_tl(r_tmp2
, t0
, uimm
);
1301 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1302 tcg_temp_free(r_tmp2
);
1303 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1304 /* operands of same sign, result different sign */
1305 generate_exception(ctx
, EXCP_OVERFLOW
);
1307 tcg_temp_free(r_tmp1
);
1312 tcg_gen_addi_tl(t0
, t0
, uimm
);
1317 gen_op_lti(t0
, uimm
);
1321 gen_op_ltiu(t0
, uimm
);
1325 tcg_gen_andi_tl(t0
, t0
, uimm
);
1329 tcg_gen_ori_tl(t0
, t0
, uimm
);
1333 tcg_gen_xori_tl(t0
, t0
, uimm
);
1340 tcg_gen_shli_tl(t0
, t0
, uimm
);
1341 tcg_gen_ext32s_tl(t0
, t0
);
1345 tcg_gen_ext32s_tl(t0
, t0
);
1346 tcg_gen_sari_tl(t0
, t0
, uimm
);
1350 switch ((ctx
->opcode
>> 21) & 0x1f) {
1353 tcg_gen_ext32u_tl(t0
, t0
);
1354 tcg_gen_shri_tl(t0
, t0
, uimm
);
1356 tcg_gen_ext32s_tl(t0
, t0
);
1361 /* rotr is decoded as srl on non-R2 CPUs */
1362 if (env
->insn_flags
& ISA_MIPS32R2
) {
1364 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
1366 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1367 tcg_gen_rotri_i32(r_tmp1
, r_tmp1
, uimm
);
1368 tcg_gen_ext_i32_tl(t0
, r_tmp1
);
1369 tcg_temp_free_i32(r_tmp1
);
1374 tcg_gen_ext32u_tl(t0
, t0
);
1375 tcg_gen_shri_tl(t0
, t0
, uimm
);
1377 tcg_gen_ext32s_tl(t0
, t0
);
1383 MIPS_INVAL("invalid srl flag");
1384 generate_exception(ctx
, EXCP_RI
);
1388 #if defined(TARGET_MIPS64)
1390 tcg_gen_shli_tl(t0
, t0
, uimm
);
1394 tcg_gen_sari_tl(t0
, t0
, uimm
);
1398 switch ((ctx
->opcode
>> 21) & 0x1f) {
1400 tcg_gen_shri_tl(t0
, t0
, uimm
);
1404 /* drotr is decoded as dsrl on non-R2 CPUs */
1405 if (env
->insn_flags
& ISA_MIPS32R2
) {
1407 tcg_gen_rotri_tl(t0
, t0
, uimm
);
1411 tcg_gen_shri_tl(t0
, t0
, uimm
);
1416 MIPS_INVAL("invalid dsrl flag");
1417 generate_exception(ctx
, EXCP_RI
);
1422 tcg_gen_shli_tl(t0
, t0
, uimm
+ 32);
1426 tcg_gen_sari_tl(t0
, t0
, uimm
+ 32);
1430 switch ((ctx
->opcode
>> 21) & 0x1f) {
1432 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1436 /* drotr32 is decoded as dsrl32 on non-R2 CPUs */
1437 if (env
->insn_flags
& ISA_MIPS32R2
) {
1438 tcg_gen_rotri_tl(t0
, t0
, uimm
+ 32);
1441 tcg_gen_shri_tl(t0
, t0
, uimm
+ 32);
1446 MIPS_INVAL("invalid dsrl32 flag");
1447 generate_exception(ctx
, EXCP_RI
);
1454 generate_exception(ctx
, EXCP_RI
);
1457 gen_store_gpr(t0
, rt
);
1458 MIPS_DEBUG("%s %s, %s, " TARGET_FMT_lx
, opn
, regnames
[rt
], regnames
[rs
], uimm
);
1464 static void gen_arith (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
,
1465 int rd
, int rs
, int rt
)
1467 const char *opn
= "arith";
1468 TCGv t0
= tcg_temp_local_new();
1469 TCGv t1
= tcg_temp_local_new();
1471 if (rd
== 0 && opc
!= OPC_ADD
&& opc
!= OPC_SUB
1472 && opc
!= OPC_DADD
&& opc
!= OPC_DSUB
) {
1473 /* If no destination, treat it as a NOP.
1474 For add & sub, we must generate the overflow exception when needed. */
1478 gen_load_gpr(t0
, rs
);
1479 /* Specialcase the conventional move operation. */
1480 if (rt
== 0 && (opc
== OPC_ADDU
|| opc
== OPC_DADDU
1481 || opc
== OPC_SUBU
|| opc
== OPC_DSUBU
)) {
1482 gen_store_gpr(t0
, rd
);
1485 gen_load_gpr(t1
, rt
);
1489 TCGv r_tmp1
= tcg_temp_new();
1490 TCGv r_tmp2
= tcg_temp_new();
1491 int l1
= gen_new_label();
1493 save_cpu_state(ctx
, 1);
1494 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1495 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1496 tcg_gen_add_tl(t0
, r_tmp1
, r_tmp2
);
1498 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1499 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1500 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1501 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1502 tcg_temp_free(r_tmp2
);
1503 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1504 /* operands of same sign, result different sign */
1505 generate_exception(ctx
, EXCP_OVERFLOW
);
1507 tcg_temp_free(r_tmp1
);
1509 tcg_gen_ext32s_tl(t0
, t0
);
1514 tcg_gen_add_tl(t0
, t0
, t1
);
1515 tcg_gen_ext32s_tl(t0
, t0
);
1520 TCGv r_tmp1
= tcg_temp_new();
1521 TCGv r_tmp2
= tcg_temp_new();
1522 int l1
= gen_new_label();
1524 save_cpu_state(ctx
, 1);
1525 tcg_gen_ext32s_tl(r_tmp1
, t0
);
1526 tcg_gen_ext32s_tl(r_tmp2
, t1
);
1527 tcg_gen_sub_tl(t0
, r_tmp1
, r_tmp2
);
1529 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1530 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1531 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1532 tcg_temp_free(r_tmp2
);
1533 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1534 /* operands of different sign, first operand and result different sign */
1535 generate_exception(ctx
, EXCP_OVERFLOW
);
1537 tcg_temp_free(r_tmp1
);
1539 tcg_gen_ext32s_tl(t0
, t0
);
1544 tcg_gen_sub_tl(t0
, t0
, t1
);
1545 tcg_gen_ext32s_tl(t0
, t0
);
1548 #if defined(TARGET_MIPS64)
1551 TCGv r_tmp1
= tcg_temp_new();
1552 TCGv r_tmp2
= tcg_temp_new();
1553 int l1
= gen_new_label();
1555 save_cpu_state(ctx
, 1);
1556 tcg_gen_mov_tl(r_tmp1
, t0
);
1557 tcg_gen_add_tl(t0
, t0
, t1
);
1559 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t1
);
1560 tcg_gen_xori_tl(r_tmp1
, r_tmp1
, -1);
1561 tcg_gen_xor_tl(r_tmp2
, t0
, t1
);
1562 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1563 tcg_temp_free(r_tmp2
);
1564 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1565 /* operands of same sign, result different sign */
1566 generate_exception(ctx
, EXCP_OVERFLOW
);
1568 tcg_temp_free(r_tmp1
);
1573 tcg_gen_add_tl(t0
, t0
, t1
);
1578 TCGv r_tmp1
= tcg_temp_new();
1579 TCGv r_tmp2
= tcg_temp_new();
1580 int l1
= gen_new_label();
1582 save_cpu_state(ctx
, 1);
1583 tcg_gen_mov_tl(r_tmp1
, t0
);
1584 tcg_gen_sub_tl(t0
, t0
, t1
);
1586 tcg_gen_xor_tl(r_tmp2
, r_tmp1
, t1
);
1587 tcg_gen_xor_tl(r_tmp1
, r_tmp1
, t0
);
1588 tcg_gen_and_tl(r_tmp1
, r_tmp1
, r_tmp2
);
1589 tcg_temp_free(r_tmp2
);
1590 tcg_gen_brcondi_tl(TCG_COND_GE
, r_tmp1
, 0, l1
);
1591 /* operands of different sign, first operand and result different sign */
1592 generate_exception(ctx
, EXCP_OVERFLOW
);
1594 tcg_temp_free(r_tmp1
);
1599 tcg_gen_sub_tl(t0
, t0
, t1
);
1612 tcg_gen_and_tl(t0
, t0
, t1
);
1616 tcg_gen_nor_tl(t0
, t0
, t1
);
1620 tcg_gen_or_tl(t0
, t0
, t1
);
1624 tcg_gen_xor_tl(t0
, t0
, t1
);
1628 tcg_gen_mul_tl(t0
, t0
, t1
);
1629 tcg_gen_ext32s_tl(t0
, t0
);
1634 int l1
= gen_new_label();
1636 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1637 gen_store_gpr(t0
, rd
);
1644 int l1
= gen_new_label();
1646 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, 0, l1
);
1647 gen_store_gpr(t0
, rd
);
1653 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1654 tcg_gen_shl_tl(t0
, t1
, t0
);
1655 tcg_gen_ext32s_tl(t0
, t0
);
1659 tcg_gen_ext32s_tl(t1
, t1
);
1660 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1661 tcg_gen_sar_tl(t0
, t1
, t0
);
1665 switch ((ctx
->opcode
>> 6) & 0x1f) {
1667 tcg_gen_ext32u_tl(t1
, t1
);
1668 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1669 tcg_gen_shr_tl(t0
, t1
, t0
);
1670 tcg_gen_ext32s_tl(t0
, t0
);
1674 /* rotrv is decoded as srlv on non-R2 CPUs */
1675 if (env
->insn_flags
& ISA_MIPS32R2
) {
1676 int l1
= gen_new_label();
1677 int l2
= gen_new_label();
1679 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1680 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1682 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
1683 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
1685 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1686 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1687 tcg_gen_rotr_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1688 tcg_temp_free_i32(r_tmp1
);
1689 tcg_temp_free_i32(r_tmp2
);
1693 tcg_gen_mov_tl(t0
, t1
);
1697 tcg_gen_ext32u_tl(t1
, t1
);
1698 tcg_gen_andi_tl(t0
, t0
, 0x1f);
1699 tcg_gen_shr_tl(t0
, t1
, t0
);
1700 tcg_gen_ext32s_tl(t0
, t0
);
1705 MIPS_INVAL("invalid srlv flag");
1706 generate_exception(ctx
, EXCP_RI
);
1710 #if defined(TARGET_MIPS64)
1712 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1713 tcg_gen_shl_tl(t0
, t1
, t0
);
1717 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1718 tcg_gen_sar_tl(t0
, t1
, t0
);
1722 switch ((ctx
->opcode
>> 6) & 0x1f) {
1724 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1725 tcg_gen_shr_tl(t0
, t1
, t0
);
1729 /* drotrv is decoded as dsrlv on non-R2 CPUs */
1730 if (env
->insn_flags
& ISA_MIPS32R2
) {
1731 int l1
= gen_new_label();
1732 int l2
= gen_new_label();
1734 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1735 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1737 tcg_gen_rotr_tl(t0
, t1
, t0
);
1741 tcg_gen_mov_tl(t0
, t1
);
1745 tcg_gen_andi_tl(t0
, t0
, 0x3f);
1746 tcg_gen_shr_tl(t0
, t1
, t0
);
1751 MIPS_INVAL("invalid dsrlv flag");
1752 generate_exception(ctx
, EXCP_RI
);
1759 generate_exception(ctx
, EXCP_RI
);
1762 gen_store_gpr(t0
, rd
);
1764 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
1770 /* Arithmetic on HI/LO registers */
1771 static void gen_HILO (DisasContext
*ctx
, uint32_t opc
, int reg
)
1773 const char *opn
= "hilo";
1775 if (reg
== 0 && (opc
== OPC_MFHI
|| opc
== OPC_MFLO
)) {
1782 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_HI
[0]);
1786 tcg_gen_mov_tl(cpu_gpr
[reg
], cpu_LO
[0]);
1791 tcg_gen_mov_tl(cpu_HI
[0], cpu_gpr
[reg
]);
1793 tcg_gen_movi_tl(cpu_HI
[0], 0);
1798 tcg_gen_mov_tl(cpu_LO
[0], cpu_gpr
[reg
]);
1800 tcg_gen_movi_tl(cpu_LO
[0], 0);
1805 generate_exception(ctx
, EXCP_RI
);
1808 MIPS_DEBUG("%s %s", opn
, regnames
[reg
]);
1811 static void gen_muldiv (DisasContext
*ctx
, uint32_t opc
,
1814 const char *opn
= "mul/div";
1815 TCGv t0
= tcg_temp_local_new();
1816 TCGv t1
= tcg_temp_local_new();
1818 gen_load_gpr(t0
, rs
);
1819 gen_load_gpr(t1
, rt
);
1823 int l1
= gen_new_label();
1825 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1827 int l2
= gen_new_label();
1828 TCGv_i32 r_tmp1
= tcg_temp_local_new_i32();
1829 TCGv_i32 r_tmp2
= tcg_temp_local_new_i32();
1830 TCGv_i32 r_tmp3
= tcg_temp_local_new_i32();
1832 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1833 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1834 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp1
, -1 << 31, l2
);
1835 tcg_gen_brcondi_i32(TCG_COND_NE
, r_tmp2
, -1, l2
);
1836 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1837 tcg_gen_movi_tl(cpu_HI
[0], 0);
1840 tcg_gen_div_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1841 tcg_gen_rem_i32(r_tmp2
, r_tmp1
, r_tmp2
);
1842 tcg_gen_ext_i32_tl(cpu_LO
[0], r_tmp3
);
1843 tcg_gen_ext_i32_tl(cpu_HI
[0], r_tmp2
);
1844 tcg_temp_free_i32(r_tmp1
);
1845 tcg_temp_free_i32(r_tmp2
);
1846 tcg_temp_free_i32(r_tmp3
);
1854 int l1
= gen_new_label();
1856 tcg_gen_ext32s_tl(t1
, t1
);
1857 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1859 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
1860 TCGv_i32 r_tmp2
= tcg_temp_new_i32();
1861 TCGv_i32 r_tmp3
= tcg_temp_new_i32();
1863 tcg_gen_trunc_tl_i32(r_tmp1
, t0
);
1864 tcg_gen_trunc_tl_i32(r_tmp2
, t1
);
1865 tcg_gen_divu_i32(r_tmp3
, r_tmp1
, r_tmp2
);
1866 tcg_gen_remu_i32(r_tmp1
, r_tmp1
, r_tmp2
);
1867 tcg_gen_ext_i32_tl(cpu_LO
[0], r_tmp3
);
1868 tcg_gen_ext_i32_tl(cpu_HI
[0], r_tmp1
);
1869 tcg_temp_free_i32(r_tmp1
);
1870 tcg_temp_free_i32(r_tmp2
);
1871 tcg_temp_free_i32(r_tmp3
);
1879 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1880 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1882 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
1883 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
1884 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1885 tcg_temp_free_i64(r_tmp2
);
1886 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1887 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1888 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1889 tcg_temp_free_i64(r_tmp1
);
1890 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1891 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
1897 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1898 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1900 tcg_gen_ext32u_tl(t0
, t0
);
1901 tcg_gen_ext32u_tl(t1
, t1
);
1902 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
1903 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
1904 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1905 tcg_temp_free_i64(r_tmp2
);
1906 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1907 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1908 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1909 tcg_temp_free_i64(r_tmp1
);
1910 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1911 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
1915 #if defined(TARGET_MIPS64)
1918 int l1
= gen_new_label();
1920 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1922 int l2
= gen_new_label();
1924 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, -1LL << 63, l2
);
1925 tcg_gen_brcondi_tl(TCG_COND_NE
, t1
, -1LL, l2
);
1926 tcg_gen_mov_tl(cpu_LO
[0], t0
);
1927 tcg_gen_movi_tl(cpu_HI
[0], 0);
1930 tcg_gen_div_i64(cpu_LO
[0], t0
, t1
);
1931 tcg_gen_rem_i64(cpu_HI
[0], t0
, t1
);
1939 int l1
= gen_new_label();
1941 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
1942 tcg_gen_divu_i64(cpu_LO
[0], t0
, t1
);
1943 tcg_gen_remu_i64(cpu_HI
[0], t0
, t1
);
1949 gen_helper_dmult(t0
, t1
);
1953 gen_helper_dmultu(t0
, t1
);
1959 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1960 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1962 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
1963 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
1964 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1965 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
1966 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1967 tcg_temp_free_i64(r_tmp2
);
1968 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1969 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1970 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1971 tcg_temp_free_i64(r_tmp1
);
1972 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1973 tcg_gen_ext32s_tl(cpu_LO
[1], t1
);
1979 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
1980 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
1982 tcg_gen_ext32u_tl(t0
, t0
);
1983 tcg_gen_ext32u_tl(t1
, t1
);
1984 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
1985 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
1986 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1987 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
1988 tcg_gen_add_i64(r_tmp1
, r_tmp1
, r_tmp2
);
1989 tcg_temp_free_i64(r_tmp2
);
1990 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
1991 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
1992 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
1993 tcg_temp_free_i64(r_tmp1
);
1994 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
1995 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2001 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
2002 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
2004 tcg_gen_ext_tl_i64(r_tmp1
, t0
);
2005 tcg_gen_ext_tl_i64(r_tmp2
, t1
);
2006 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2007 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
2008 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2009 tcg_temp_free_i64(r_tmp2
);
2010 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2011 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2012 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2013 tcg_temp_free_i64(r_tmp1
);
2014 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2015 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2021 TCGv_i64 r_tmp1
= tcg_temp_new_i64();
2022 TCGv_i64 r_tmp2
= tcg_temp_new_i64();
2024 tcg_gen_ext32u_tl(t0
, t0
);
2025 tcg_gen_ext32u_tl(t1
, t1
);
2026 tcg_gen_extu_tl_i64(r_tmp1
, t0
);
2027 tcg_gen_extu_tl_i64(r_tmp2
, t1
);
2028 tcg_gen_mul_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2029 tcg_gen_concat_tl_i64(r_tmp2
, cpu_LO
[0], cpu_HI
[0]);
2030 tcg_gen_sub_i64(r_tmp1
, r_tmp1
, r_tmp2
);
2031 tcg_temp_free_i64(r_tmp2
);
2032 tcg_gen_trunc_i64_tl(t0
, r_tmp1
);
2033 tcg_gen_shri_i64(r_tmp1
, r_tmp1
, 32);
2034 tcg_gen_trunc_i64_tl(t1
, r_tmp1
);
2035 tcg_temp_free_i64(r_tmp1
);
2036 tcg_gen_ext32s_tl(cpu_LO
[0], t0
);
2037 tcg_gen_ext32s_tl(cpu_HI
[0], t1
);
2043 generate_exception(ctx
, EXCP_RI
);
2046 MIPS_DEBUG("%s %s %s", opn
, regnames
[rs
], regnames
[rt
]);
2052 static void gen_mul_vr54xx (DisasContext
*ctx
, uint32_t opc
,
2053 int rd
, int rs
, int rt
)
2055 const char *opn
= "mul vr54xx";
2056 TCGv t0
= tcg_temp_local_new();
2057 TCGv t1
= tcg_temp_local_new();
2059 gen_load_gpr(t0
, rs
);
2060 gen_load_gpr(t1
, rt
);
2063 case OPC_VR54XX_MULS
:
2064 gen_helper_muls(t0
, t0
, t1
);
2067 case OPC_VR54XX_MULSU
:
2068 gen_helper_mulsu(t0
, t0
, t1
);
2071 case OPC_VR54XX_MACC
:
2072 gen_helper_macc(t0
, t0
, t1
);
2075 case OPC_VR54XX_MACCU
:
2076 gen_helper_maccu(t0
, t0
, t1
);
2079 case OPC_VR54XX_MSAC
:
2080 gen_helper_msac(t0
, t0
, t1
);
2083 case OPC_VR54XX_MSACU
:
2084 gen_helper_msacu(t0
, t0
, t1
);
2087 case OPC_VR54XX_MULHI
:
2088 gen_helper_mulhi(t0
, t0
, t1
);
2091 case OPC_VR54XX_MULHIU
:
2092 gen_helper_mulhiu(t0
, t0
, t1
);
2095 case OPC_VR54XX_MULSHI
:
2096 gen_helper_mulshi(t0
, t0
, t1
);
2099 case OPC_VR54XX_MULSHIU
:
2100 gen_helper_mulshiu(t0
, t0
, t1
);
2103 case OPC_VR54XX_MACCHI
:
2104 gen_helper_macchi(t0
, t0
, t1
);
2107 case OPC_VR54XX_MACCHIU
:
2108 gen_helper_macchiu(t0
, t0
, t1
);
2111 case OPC_VR54XX_MSACHI
:
2112 gen_helper_msachi(t0
, t0
, t1
);
2115 case OPC_VR54XX_MSACHIU
:
2116 gen_helper_msachiu(t0
, t0
, t1
);
2120 MIPS_INVAL("mul vr54xx");
2121 generate_exception(ctx
, EXCP_RI
);
2124 gen_store_gpr(t0
, rd
);
2125 MIPS_DEBUG("%s %s, %s, %s", opn
, regnames
[rd
], regnames
[rs
], regnames
[rt
]);
2132 static void gen_cl (DisasContext
*ctx
, uint32_t opc
,
2135 const char *opn
= "CLx";
2136 TCGv t0
= tcg_temp_local_new();
2143 gen_load_gpr(t0
, rs
);
2146 gen_helper_clo(t0
, t0
);
2150 gen_helper_clz(t0
, t0
);
2153 #if defined(TARGET_MIPS64)
2155 gen_helper_dclo(t0
, t0
);
2159 gen_helper_dclz(t0
, t0
);
2165 generate_exception(ctx
, EXCP_RI
);
2168 gen_store_gpr(t0
, rd
);
2169 MIPS_DEBUG("%s %s, %s", opn
, regnames
[rd
], regnames
[rs
]);
2176 static void gen_trap (DisasContext
*ctx
, uint32_t opc
,
2177 int rs
, int rt
, int16_t imm
)
2180 TCGv t0
= tcg_temp_local_new();
2181 TCGv t1
= tcg_temp_local_new();
2184 /* Load needed operands */
2192 /* Compare two registers */
2194 gen_load_gpr(t0
, rs
);
2195 gen_load_gpr(t1
, rt
);
2205 /* Compare register to immediate */
2206 if (rs
!= 0 || imm
!= 0) {
2207 gen_load_gpr(t0
, rs
);
2208 tcg_gen_movi_tl(t1
, (int32_t)imm
);
2215 case OPC_TEQ
: /* rs == rs */
2216 case OPC_TEQI
: /* r0 == 0 */
2217 case OPC_TGE
: /* rs >= rs */
2218 case OPC_TGEI
: /* r0 >= 0 */
2219 case OPC_TGEU
: /* rs >= rs unsigned */
2220 case OPC_TGEIU
: /* r0 >= 0 unsigned */
2222 tcg_gen_movi_tl(t0
, 1);
2224 case OPC_TLT
: /* rs < rs */
2225 case OPC_TLTI
: /* r0 < 0 */
2226 case OPC_TLTU
: /* rs < rs unsigned */
2227 case OPC_TLTIU
: /* r0 < 0 unsigned */
2228 case OPC_TNE
: /* rs != rs */
2229 case OPC_TNEI
: /* r0 != 0 */
2230 /* Never trap: treat as NOP. */
2234 generate_exception(ctx
, EXCP_RI
);
2265 generate_exception(ctx
, EXCP_RI
);
2269 save_cpu_state(ctx
, 1);
2271 int l1
= gen_new_label();
2273 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2274 gen_helper_0i(raise_exception
, EXCP_TRAP
);
2277 ctx
->bstate
= BS_STOP
;
2283 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
2285 TranslationBlock
*tb
;
2287 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
2290 tcg_gen_exit_tb((long)tb
+ n
);
2297 /* Branches (before delay slot) */
2298 static void gen_compute_branch (DisasContext
*ctx
, uint32_t opc
,
2299 int rs
, int rt
, int32_t offset
)
2301 target_ulong btgt
= -1;
2303 int bcond_compute
= 0;
2304 TCGv t0
= tcg_temp_local_new();
2305 TCGv t1
= tcg_temp_local_new();
2307 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
2308 #ifdef MIPS_DEBUG_DISAS
2309 LOG_DISAS("Branch in delay slot at PC 0x" TARGET_FMT_lx
"\n", ctx
->pc
);
2311 generate_exception(ctx
, EXCP_RI
);
2315 /* Load needed operands */
2321 /* Compare two registers */
2323 gen_load_gpr(t0
, rs
);
2324 gen_load_gpr(t1
, rt
);
2327 btgt
= ctx
->pc
+ 4 + offset
;
2341 /* Compare to zero */
2343 gen_load_gpr(t0
, rs
);
2346 btgt
= ctx
->pc
+ 4 + offset
;
2350 /* Jump to immediate */
2351 btgt
= ((ctx
->pc
+ 4) & (int32_t)0xF0000000) | (uint32_t)offset
;
2355 /* Jump to register */
2356 if (offset
!= 0 && offset
!= 16) {
2357 /* Hint = 0 is JR/JALR, hint 16 is JR.HB/JALR.HB, the
2358 others are reserved. */
2359 MIPS_INVAL("jump hint");
2360 generate_exception(ctx
, EXCP_RI
);
2363 gen_load_gpr(btarget
, rs
);
2366 MIPS_INVAL("branch/jump");
2367 generate_exception(ctx
, EXCP_RI
);
2370 if (bcond_compute
== 0) {
2371 /* No condition to be computed */
2373 case OPC_BEQ
: /* rx == rx */
2374 case OPC_BEQL
: /* rx == rx likely */
2375 case OPC_BGEZ
: /* 0 >= 0 */
2376 case OPC_BGEZL
: /* 0 >= 0 likely */
2377 case OPC_BLEZ
: /* 0 <= 0 */
2378 case OPC_BLEZL
: /* 0 <= 0 likely */
2380 ctx
->hflags
|= MIPS_HFLAG_B
;
2381 MIPS_DEBUG("balways");
2383 case OPC_BGEZAL
: /* 0 >= 0 */
2384 case OPC_BGEZALL
: /* 0 >= 0 likely */
2385 /* Always take and link */
2387 ctx
->hflags
|= MIPS_HFLAG_B
;
2388 MIPS_DEBUG("balways and link");
2390 case OPC_BNE
: /* rx != rx */
2391 case OPC_BGTZ
: /* 0 > 0 */
2392 case OPC_BLTZ
: /* 0 < 0 */
2394 MIPS_DEBUG("bnever (NOP)");
2396 case OPC_BLTZAL
: /* 0 < 0 */
2397 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2398 gen_store_gpr(t0
, 31);
2399 MIPS_DEBUG("bnever and link");
2401 case OPC_BLTZALL
: /* 0 < 0 likely */
2402 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2403 gen_store_gpr(t0
, 31);
2404 /* Skip the instruction in the delay slot */
2405 MIPS_DEBUG("bnever, link and skip");
2408 case OPC_BNEL
: /* rx != rx likely */
2409 case OPC_BGTZL
: /* 0 > 0 likely */
2410 case OPC_BLTZL
: /* 0 < 0 likely */
2411 /* Skip the instruction in the delay slot */
2412 MIPS_DEBUG("bnever and skip");
2416 ctx
->hflags
|= MIPS_HFLAG_B
;
2417 MIPS_DEBUG("j " TARGET_FMT_lx
, btgt
);
2421 ctx
->hflags
|= MIPS_HFLAG_B
;
2422 MIPS_DEBUG("jal " TARGET_FMT_lx
, btgt
);
2425 ctx
->hflags
|= MIPS_HFLAG_BR
;
2426 MIPS_DEBUG("jr %s", regnames
[rs
]);
2430 ctx
->hflags
|= MIPS_HFLAG_BR
;
2431 MIPS_DEBUG("jalr %s, %s", regnames
[rt
], regnames
[rs
]);
2434 MIPS_INVAL("branch/jump");
2435 generate_exception(ctx
, EXCP_RI
);
2442 MIPS_DEBUG("beq %s, %s, " TARGET_FMT_lx
,
2443 regnames
[rs
], regnames
[rt
], btgt
);
2447 MIPS_DEBUG("beql %s, %s, " TARGET_FMT_lx
,
2448 regnames
[rs
], regnames
[rt
], btgt
);
2452 MIPS_DEBUG("bne %s, %s, " TARGET_FMT_lx
,
2453 regnames
[rs
], regnames
[rt
], btgt
);
2457 MIPS_DEBUG("bnel %s, %s, " TARGET_FMT_lx
,
2458 regnames
[rs
], regnames
[rt
], btgt
);
2462 MIPS_DEBUG("bgez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2466 MIPS_DEBUG("bgezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2470 MIPS_DEBUG("bgezal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2476 MIPS_DEBUG("bgezall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2480 MIPS_DEBUG("bgtz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2484 MIPS_DEBUG("bgtzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2488 MIPS_DEBUG("blez %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2492 MIPS_DEBUG("blezl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2496 MIPS_DEBUG("bltz %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2500 MIPS_DEBUG("bltzl %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2505 MIPS_DEBUG("bltzal %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2507 ctx
->hflags
|= MIPS_HFLAG_BC
;
2508 tcg_gen_trunc_tl_i32(bcond
, t0
);
2513 MIPS_DEBUG("bltzall %s, " TARGET_FMT_lx
, regnames
[rs
], btgt
);
2515 ctx
->hflags
|= MIPS_HFLAG_BL
;
2516 tcg_gen_trunc_tl_i32(bcond
, t0
);
2519 MIPS_INVAL("conditional branch/jump");
2520 generate_exception(ctx
, EXCP_RI
);
2524 MIPS_DEBUG("enter ds: link %d cond %02x target " TARGET_FMT_lx
,
2525 blink
, ctx
->hflags
, btgt
);
2527 ctx
->btarget
= btgt
;
2529 tcg_gen_movi_tl(t0
, ctx
->pc
+ 8);
2530 gen_store_gpr(t0
, blink
);
2538 /* special3 bitfield operations */
2539 static void gen_bitops (DisasContext
*ctx
, uint32_t opc
, int rt
,
2540 int rs
, int lsb
, int msb
)
2542 TCGv t0
= tcg_temp_new();
2543 TCGv t1
= tcg_temp_new();
2546 gen_load_gpr(t1
, rs
);
2551 tcg_gen_shri_tl(t0
, t1
, lsb
);
2553 tcg_gen_andi_tl(t0
, t0
, (1 << (msb
+ 1)) - 1);
2555 tcg_gen_ext32s_tl(t0
, t0
);
2558 #if defined(TARGET_MIPS64)
2560 tcg_gen_shri_tl(t0
, t1
, lsb
);
2562 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1 + 32)) - 1);
2566 tcg_gen_shri_tl(t0
, t1
, lsb
+ 32);
2567 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2570 tcg_gen_shri_tl(t0
, t1
, lsb
);
2571 tcg_gen_andi_tl(t0
, t0
, (1ULL << (msb
+ 1)) - 1);
2577 mask
= ((msb
- lsb
+ 1 < 32) ? ((1 << (msb
- lsb
+ 1)) - 1) : ~0) << lsb
;
2578 gen_load_gpr(t0
, rt
);
2579 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2580 tcg_gen_shli_tl(t1
, t1
, lsb
);
2581 tcg_gen_andi_tl(t1
, t1
, mask
);
2582 tcg_gen_or_tl(t0
, t0
, t1
);
2583 tcg_gen_ext32s_tl(t0
, t0
);
2585 #if defined(TARGET_MIPS64)
2589 mask
= ((msb
- lsb
+ 1 + 32 < 64) ? ((1ULL << (msb
- lsb
+ 1 + 32)) - 1) : ~0ULL) << lsb
;
2590 gen_load_gpr(t0
, rt
);
2591 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2592 tcg_gen_shli_tl(t1
, t1
, lsb
);
2593 tcg_gen_andi_tl(t1
, t1
, mask
);
2594 tcg_gen_or_tl(t0
, t0
, t1
);
2599 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2600 gen_load_gpr(t0
, rt
);
2601 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2602 tcg_gen_shli_tl(t1
, t1
, lsb
+ 32);
2603 tcg_gen_andi_tl(t1
, t1
, mask
);
2604 tcg_gen_or_tl(t0
, t0
, t1
);
2609 gen_load_gpr(t0
, rt
);
2610 mask
= ((1ULL << (msb
- lsb
+ 1)) - 1) << lsb
;
2611 gen_load_gpr(t0
, rt
);
2612 tcg_gen_andi_tl(t0
, t0
, ~mask
);
2613 tcg_gen_shli_tl(t1
, t1
, lsb
);
2614 tcg_gen_andi_tl(t1
, t1
, mask
);
2615 tcg_gen_or_tl(t0
, t0
, t1
);
2620 MIPS_INVAL("bitops");
2621 generate_exception(ctx
, EXCP_RI
);
2626 gen_store_gpr(t0
, rt
);
2631 static void gen_bshfl (DisasContext
*ctx
, uint32_t op2
, int rt
, int rd
)
2633 TCGv t0
= tcg_temp_new();
2634 TCGv t1
= tcg_temp_new();
2636 gen_load_gpr(t1
, rt
);
2639 tcg_gen_shri_tl(t0
, t1
, 8);
2640 tcg_gen_andi_tl(t0
, t0
, 0x00FF00FF);
2641 tcg_gen_shli_tl(t1
, t1
, 8);
2642 tcg_gen_andi_tl(t1
, t1
, ~0x00FF00FF);
2643 tcg_gen_or_tl(t0
, t0
, t1
);
2644 tcg_gen_ext32s_tl(t0
, t0
);
2647 tcg_gen_ext8s_tl(t0
, t1
);
2650 tcg_gen_ext16s_tl(t0
, t1
);
2652 #if defined(TARGET_MIPS64)
2654 gen_load_gpr(t1
, rt
);
2655 tcg_gen_shri_tl(t0
, t1
, 8);
2656 tcg_gen_andi_tl(t0
, t0
, 0x00FF00FF00FF00FFULL
);
2657 tcg_gen_shli_tl(t1
, t1
, 8);
2658 tcg_gen_andi_tl(t1
, t1
, ~0x00FF00FF00FF00FFULL
);
2659 tcg_gen_or_tl(t0
, t0
, t1
);
2662 gen_load_gpr(t1
, rt
);
2663 tcg_gen_shri_tl(t0
, t1
, 16);
2664 tcg_gen_andi_tl(t0
, t0
, 0x0000FFFF0000FFFFULL
);
2665 tcg_gen_shli_tl(t1
, t1
, 16);
2666 tcg_gen_andi_tl(t1
, t1
, ~0x0000FFFF0000FFFFULL
);
2667 tcg_gen_or_tl(t1
, t0
, t1
);
2668 tcg_gen_shri_tl(t0
, t1
, 32);
2669 tcg_gen_shli_tl(t1
, t1
, 32);
2670 tcg_gen_or_tl(t0
, t0
, t1
);
2674 MIPS_INVAL("bsfhl");
2675 generate_exception(ctx
, EXCP_RI
);
2680 gen_store_gpr(t0
, rd
);
2685 #ifndef CONFIG_USER_ONLY
2686 /* CP0 (MMU and control) */
2687 static inline void gen_mfc0_load32 (TCGv t
, target_ulong off
)
2689 TCGv_i32 r_tmp
= tcg_temp_new_i32();
2691 tcg_gen_ld_i32(r_tmp
, cpu_env
, off
);
2692 tcg_gen_ext_i32_tl(t
, r_tmp
);
2693 tcg_temp_free_i32(r_tmp
);
2696 static inline void gen_mfc0_load64 (TCGv t
, target_ulong off
)
2698 tcg_gen_ld_tl(t
, cpu_env
, off
);
2699 tcg_gen_ext32s_tl(t
, t
);
2702 static inline void gen_mtc0_store32 (TCGv t
, target_ulong off
)
2704 TCGv_i32 r_tmp
= tcg_temp_new_i32();
2706 tcg_gen_trunc_tl_i32(r_tmp
, t
);
2707 tcg_gen_st_i32(r_tmp
, cpu_env
, off
);
2708 tcg_temp_free_i32(r_tmp
);
2711 static inline void gen_mtc0_store64 (TCGv t
, target_ulong off
)
2713 tcg_gen_ext32s_tl(t
, t
);
2714 tcg_gen_st_tl(t
, cpu_env
, off
);
2717 static void gen_mfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
2719 const char *rn
= "invalid";
2722 check_insn(env
, ctx
, ISA_MIPS32
);
2728 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
2732 check_insn(env
, ctx
, ASE_MT
);
2733 gen_helper_mfc0_mvpcontrol(t0
);
2737 check_insn(env
, ctx
, ASE_MT
);
2738 gen_helper_mfc0_mvpconf0(t0
);
2742 check_insn(env
, ctx
, ASE_MT
);
2743 gen_helper_mfc0_mvpconf1(t0
);
2753 gen_helper_mfc0_random(t0
);
2757 check_insn(env
, ctx
, ASE_MT
);
2758 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
2762 check_insn(env
, ctx
, ASE_MT
);
2763 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
2767 check_insn(env
, ctx
, ASE_MT
);
2768 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
2772 check_insn(env
, ctx
, ASE_MT
);
2773 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_YQMask
));
2777 check_insn(env
, ctx
, ASE_MT
);
2778 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
2782 check_insn(env
, ctx
, ASE_MT
);
2783 gen_mfc0_load64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
2784 rn
= "VPEScheFBack";
2787 check_insn(env
, ctx
, ASE_MT
);
2788 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
2798 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
2799 tcg_gen_ext32s_tl(t0
, t0
);
2803 check_insn(env
, ctx
, ASE_MT
);
2804 gen_helper_mfc0_tcstatus(t0
);
2808 check_insn(env
, ctx
, ASE_MT
);
2809 gen_helper_mfc0_tcbind(t0
);
2813 check_insn(env
, ctx
, ASE_MT
);
2814 gen_helper_mfc0_tcrestart(t0
);
2818 check_insn(env
, ctx
, ASE_MT
);
2819 gen_helper_mfc0_tchalt(t0
);
2823 check_insn(env
, ctx
, ASE_MT
);
2824 gen_helper_mfc0_tccontext(t0
);
2828 check_insn(env
, ctx
, ASE_MT
);
2829 gen_helper_mfc0_tcschedule(t0
);
2833 check_insn(env
, ctx
, ASE_MT
);
2834 gen_helper_mfc0_tcschefback(t0
);
2844 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
2845 tcg_gen_ext32s_tl(t0
, t0
);
2855 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
2856 tcg_gen_ext32s_tl(t0
, t0
);
2860 // gen_helper_mfc0_contextconfig(t0); /* SmartMIPS ASE */
2861 rn
= "ContextConfig";
2870 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
2874 check_insn(env
, ctx
, ISA_MIPS32R2
);
2875 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
2885 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
2889 check_insn(env
, ctx
, ISA_MIPS32R2
);
2890 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
2894 check_insn(env
, ctx
, ISA_MIPS32R2
);
2895 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
2899 check_insn(env
, ctx
, ISA_MIPS32R2
);
2900 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
2904 check_insn(env
, ctx
, ISA_MIPS32R2
);
2905 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
2909 check_insn(env
, ctx
, ISA_MIPS32R2
);
2910 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
2920 check_insn(env
, ctx
, ISA_MIPS32R2
);
2921 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
2931 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
2932 tcg_gen_ext32s_tl(t0
, t0
);
2942 /* Mark as an IO operation because we read the time. */
2945 gen_helper_mfc0_count(t0
);
2948 ctx
->bstate
= BS_STOP
;
2952 /* 6,7 are implementation dependent */
2960 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
2961 tcg_gen_ext32s_tl(t0
, t0
);
2971 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
2974 /* 6,7 are implementation dependent */
2982 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
2986 check_insn(env
, ctx
, ISA_MIPS32R2
);
2987 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
2991 check_insn(env
, ctx
, ISA_MIPS32R2
);
2992 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
2996 check_insn(env
, ctx
, ISA_MIPS32R2
);
2997 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3007 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
3017 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
3018 tcg_gen_ext32s_tl(t0
, t0
);
3028 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
3032 check_insn(env
, ctx
, ISA_MIPS32R2
);
3033 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
3043 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
3047 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
3051 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
3055 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
3058 /* 4,5 are reserved */
3059 /* 6,7 are implementation dependent */
3061 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
3065 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
3075 gen_helper_mfc0_lladdr(t0
);
3085 gen_helper_1i(mfc0_watchlo
, t0
, sel
);
3095 gen_helper_1i(mfc0_watchhi
, t0
, sel
);
3105 #if defined(TARGET_MIPS64)
3106 check_insn(env
, ctx
, ISA_MIPS3
);
3107 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
3108 tcg_gen_ext32s_tl(t0
, t0
);
3117 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3120 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
3128 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
3129 rn
= "'Diagnostic"; /* implementation dependent */
3134 gen_helper_mfc0_debug(t0
); /* EJTAG support */
3138 // gen_helper_mfc0_tracecontrol(t0); /* PDtrace support */
3139 rn
= "TraceControl";
3142 // gen_helper_mfc0_tracecontrol2(t0); /* PDtrace support */
3143 rn
= "TraceControl2";
3146 // gen_helper_mfc0_usertracedata(t0); /* PDtrace support */
3147 rn
= "UserTraceData";
3150 // gen_helper_mfc0_tracebpc(t0); /* PDtrace support */
3161 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
3162 tcg_gen_ext32s_tl(t0
, t0
);
3172 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
3173 rn
= "Performance0";
3176 // gen_helper_mfc0_performance1(t0);
3177 rn
= "Performance1";
3180 // gen_helper_mfc0_performance2(t0);
3181 rn
= "Performance2";
3184 // gen_helper_mfc0_performance3(t0);
3185 rn
= "Performance3";
3188 // gen_helper_mfc0_performance4(t0);
3189 rn
= "Performance4";
3192 // gen_helper_mfc0_performance5(t0);
3193 rn
= "Performance5";
3196 // gen_helper_mfc0_performance6(t0);
3197 rn
= "Performance6";
3200 // gen_helper_mfc0_performance7(t0);
3201 rn
= "Performance7";
3208 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
3214 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
3227 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
3234 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
3247 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
3254 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
3264 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
3265 tcg_gen_ext32s_tl(t0
, t0
);
3276 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
3286 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3290 LOG_DISAS("mfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3291 generate_exception(ctx
, EXCP_RI
);
3294 static void gen_mtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
3296 const char *rn
= "invalid";
3299 check_insn(env
, ctx
, ISA_MIPS32
);
3308 gen_helper_mtc0_index(t0
);
3312 check_insn(env
, ctx
, ASE_MT
);
3313 gen_helper_mtc0_mvpcontrol(t0
);
3317 check_insn(env
, ctx
, ASE_MT
);
3322 check_insn(env
, ctx
, ASE_MT
);
3337 check_insn(env
, ctx
, ASE_MT
);
3338 gen_helper_mtc0_vpecontrol(t0
);
3342 check_insn(env
, ctx
, ASE_MT
);
3343 gen_helper_mtc0_vpeconf0(t0
);
3347 check_insn(env
, ctx
, ASE_MT
);
3348 gen_helper_mtc0_vpeconf1(t0
);
3352 check_insn(env
, ctx
, ASE_MT
);
3353 gen_helper_mtc0_yqmask(t0
);
3357 check_insn(env
, ctx
, ASE_MT
);
3358 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPESchedule
));
3362 check_insn(env
, ctx
, ASE_MT
);
3363 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_VPEScheFBack
));
3364 rn
= "VPEScheFBack";
3367 check_insn(env
, ctx
, ASE_MT
);
3368 gen_helper_mtc0_vpeopt(t0
);
3378 gen_helper_mtc0_entrylo0(t0
);
3382 check_insn(env
, ctx
, ASE_MT
);
3383 gen_helper_mtc0_tcstatus(t0
);
3387 check_insn(env
, ctx
, ASE_MT
);
3388 gen_helper_mtc0_tcbind(t0
);
3392 check_insn(env
, ctx
, ASE_MT
);
3393 gen_helper_mtc0_tcrestart(t0
);
3397 check_insn(env
, ctx
, ASE_MT
);
3398 gen_helper_mtc0_tchalt(t0
);
3402 check_insn(env
, ctx
, ASE_MT
);
3403 gen_helper_mtc0_tccontext(t0
);
3407 check_insn(env
, ctx
, ASE_MT
);
3408 gen_helper_mtc0_tcschedule(t0
);
3412 check_insn(env
, ctx
, ASE_MT
);
3413 gen_helper_mtc0_tcschefback(t0
);
3423 gen_helper_mtc0_entrylo1(t0
);
3433 gen_helper_mtc0_context(t0
);
3437 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
3438 rn
= "ContextConfig";
3447 gen_helper_mtc0_pagemask(t0
);
3451 check_insn(env
, ctx
, ISA_MIPS32R2
);
3452 gen_helper_mtc0_pagegrain(t0
);
3462 gen_helper_mtc0_wired(t0
);
3466 check_insn(env
, ctx
, ISA_MIPS32R2
);
3467 gen_helper_mtc0_srsconf0(t0
);
3471 check_insn(env
, ctx
, ISA_MIPS32R2
);
3472 gen_helper_mtc0_srsconf1(t0
);
3476 check_insn(env
, ctx
, ISA_MIPS32R2
);
3477 gen_helper_mtc0_srsconf2(t0
);
3481 check_insn(env
, ctx
, ISA_MIPS32R2
);
3482 gen_helper_mtc0_srsconf3(t0
);
3486 check_insn(env
, ctx
, ISA_MIPS32R2
);
3487 gen_helper_mtc0_srsconf4(t0
);
3497 check_insn(env
, ctx
, ISA_MIPS32R2
);
3498 gen_helper_mtc0_hwrena(t0
);
3512 gen_helper_mtc0_count(t0
);
3515 /* 6,7 are implementation dependent */
3519 /* Stop translation as we may have switched the execution mode */
3520 ctx
->bstate
= BS_STOP
;
3525 gen_helper_mtc0_entryhi(t0
);
3535 gen_helper_mtc0_compare(t0
);
3538 /* 6,7 are implementation dependent */
3542 /* Stop translation as we may have switched the execution mode */
3543 ctx
->bstate
= BS_STOP
;
3548 gen_helper_mtc0_status(t0
);
3549 /* BS_STOP isn't good enough here, hflags may have changed. */
3550 gen_save_pc(ctx
->pc
+ 4);
3551 ctx
->bstate
= BS_EXCP
;
3555 check_insn(env
, ctx
, ISA_MIPS32R2
);
3556 gen_helper_mtc0_intctl(t0
);
3557 /* Stop translation as we may have switched the execution mode */
3558 ctx
->bstate
= BS_STOP
;
3562 check_insn(env
, ctx
, ISA_MIPS32R2
);
3563 gen_helper_mtc0_srsctl(t0
);
3564 /* Stop translation as we may have switched the execution mode */
3565 ctx
->bstate
= BS_STOP
;
3569 check_insn(env
, ctx
, ISA_MIPS32R2
);
3570 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
3571 /* Stop translation as we may have switched the execution mode */
3572 ctx
->bstate
= BS_STOP
;
3582 gen_helper_mtc0_cause(t0
);
3588 /* Stop translation as we may have switched the execution mode */
3589 ctx
->bstate
= BS_STOP
;
3594 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_EPC
));
3608 check_insn(env
, ctx
, ISA_MIPS32R2
);
3609 gen_helper_mtc0_ebase(t0
);
3619 gen_helper_mtc0_config0(t0
);
3621 /* Stop translation as we may have switched the execution mode */
3622 ctx
->bstate
= BS_STOP
;
3625 /* ignored, read only */
3629 gen_helper_mtc0_config2(t0
);
3631 /* Stop translation as we may have switched the execution mode */
3632 ctx
->bstate
= BS_STOP
;
3635 /* ignored, read only */
3638 /* 4,5 are reserved */
3639 /* 6,7 are implementation dependent */
3649 rn
= "Invalid config selector";
3666 gen_helper_1i(mtc0_watchlo
, t0
, sel
);
3676 gen_helper_1i(mtc0_watchhi
, t0
, sel
);
3686 #if defined(TARGET_MIPS64)
3687 check_insn(env
, ctx
, ISA_MIPS3
);
3688 gen_helper_mtc0_xcontext(t0
);
3697 /* Officially reserved, but sel 0 is used for R1x000 framemask */
3700 gen_helper_mtc0_framemask(t0
);
3709 rn
= "Diagnostic"; /* implementation dependent */
3714 gen_helper_mtc0_debug(t0
); /* EJTAG support */
3715 /* BS_STOP isn't good enough here, hflags may have changed. */
3716 gen_save_pc(ctx
->pc
+ 4);
3717 ctx
->bstate
= BS_EXCP
;
3721 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
3722 rn
= "TraceControl";
3723 /* Stop translation as we may have switched the execution mode */
3724 ctx
->bstate
= BS_STOP
;
3727 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
3728 rn
= "TraceControl2";
3729 /* Stop translation as we may have switched the execution mode */
3730 ctx
->bstate
= BS_STOP
;
3733 /* Stop translation as we may have switched the execution mode */
3734 ctx
->bstate
= BS_STOP
;
3735 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
3736 rn
= "UserTraceData";
3737 /* Stop translation as we may have switched the execution mode */
3738 ctx
->bstate
= BS_STOP
;
3741 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
3742 /* Stop translation as we may have switched the execution mode */
3743 ctx
->bstate
= BS_STOP
;
3754 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_DEPC
));
3764 gen_helper_mtc0_performance0(t0
);
3765 rn
= "Performance0";
3768 // gen_helper_mtc0_performance1(t0);
3769 rn
= "Performance1";
3772 // gen_helper_mtc0_performance2(t0);
3773 rn
= "Performance2";
3776 // gen_helper_mtc0_performance3(t0);
3777 rn
= "Performance3";
3780 // gen_helper_mtc0_performance4(t0);
3781 rn
= "Performance4";
3784 // gen_helper_mtc0_performance5(t0);
3785 rn
= "Performance5";
3788 // gen_helper_mtc0_performance6(t0);
3789 rn
= "Performance6";
3792 // gen_helper_mtc0_performance7(t0);
3793 rn
= "Performance7";
3819 gen_helper_mtc0_taglo(t0
);
3826 gen_helper_mtc0_datalo(t0
);
3839 gen_helper_mtc0_taghi(t0
);
3846 gen_helper_mtc0_datahi(t0
);
3857 gen_mtc0_store64(t0
, offsetof(CPUState
, CP0_ErrorEPC
));
3868 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
3874 /* Stop translation as we may have switched the execution mode */
3875 ctx
->bstate
= BS_STOP
;
3880 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3881 /* For simplicity assume that all writes can cause interrupts. */
3884 ctx
->bstate
= BS_STOP
;
3889 LOG_DISAS("mtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
3890 generate_exception(ctx
, EXCP_RI
);
3893 #if defined(TARGET_MIPS64)
3894 static void gen_dmfc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
3896 const char *rn
= "invalid";
3899 check_insn(env
, ctx
, ISA_MIPS64
);
3905 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Index
));
3909 check_insn(env
, ctx
, ASE_MT
);
3910 gen_helper_mfc0_mvpcontrol(t0
);
3914 check_insn(env
, ctx
, ASE_MT
);
3915 gen_helper_mfc0_mvpconf0(t0
);
3919 check_insn(env
, ctx
, ASE_MT
);
3920 gen_helper_mfc0_mvpconf1(t0
);
3930 gen_helper_mfc0_random(t0
);
3934 check_insn(env
, ctx
, ASE_MT
);
3935 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEControl
));
3939 check_insn(env
, ctx
, ASE_MT
);
3940 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf0
));
3944 check_insn(env
, ctx
, ASE_MT
);
3945 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEConf1
));
3949 check_insn(env
, ctx
, ASE_MT
);
3950 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_YQMask
));
3954 check_insn(env
, ctx
, ASE_MT
);
3955 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
3959 check_insn(env
, ctx
, ASE_MT
);
3960 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
3961 rn
= "VPEScheFBack";
3964 check_insn(env
, ctx
, ASE_MT
);
3965 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_VPEOpt
));
3975 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo0
));
3979 check_insn(env
, ctx
, ASE_MT
);
3980 gen_helper_mfc0_tcstatus(t0
);
3984 check_insn(env
, ctx
, ASE_MT
);
3985 gen_helper_mfc0_tcbind(t0
);
3989 check_insn(env
, ctx
, ASE_MT
);
3990 gen_helper_dmfc0_tcrestart(t0
);
3994 check_insn(env
, ctx
, ASE_MT
);
3995 gen_helper_dmfc0_tchalt(t0
);
3999 check_insn(env
, ctx
, ASE_MT
);
4000 gen_helper_dmfc0_tccontext(t0
);
4004 check_insn(env
, ctx
, ASE_MT
);
4005 gen_helper_dmfc0_tcschedule(t0
);
4009 check_insn(env
, ctx
, ASE_MT
);
4010 gen_helper_dmfc0_tcschefback(t0
);
4020 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryLo1
));
4030 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_Context
));
4034 // gen_helper_dmfc0_contextconfig(t0); /* SmartMIPS ASE */
4035 rn
= "ContextConfig";
4044 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageMask
));
4048 check_insn(env
, ctx
, ISA_MIPS32R2
);
4049 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PageGrain
));
4059 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Wired
));
4063 check_insn(env
, ctx
, ISA_MIPS32R2
);
4064 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf0
));
4068 check_insn(env
, ctx
, ISA_MIPS32R2
);
4069 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf1
));
4073 check_insn(env
, ctx
, ISA_MIPS32R2
);
4074 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf2
));
4078 check_insn(env
, ctx
, ISA_MIPS32R2
);
4079 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf3
));
4083 check_insn(env
, ctx
, ISA_MIPS32R2
);
4084 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSConf4
));
4094 check_insn(env
, ctx
, ISA_MIPS32R2
);
4095 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_HWREna
));
4105 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_BadVAddr
));
4115 /* Mark as an IO operation because we read the time. */
4118 gen_helper_mfc0_count(t0
);
4121 ctx
->bstate
= BS_STOP
;
4125 /* 6,7 are implementation dependent */
4133 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EntryHi
));
4143 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Compare
));
4146 /* 6,7 are implementation dependent */
4154 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Status
));
4158 check_insn(env
, ctx
, ISA_MIPS32R2
);
4159 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_IntCtl
));
4163 check_insn(env
, ctx
, ISA_MIPS32R2
);
4164 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSCtl
));
4168 check_insn(env
, ctx
, ISA_MIPS32R2
);
4169 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4179 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Cause
));
4189 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4199 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_PRid
));
4203 check_insn(env
, ctx
, ISA_MIPS32R2
);
4204 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_EBase
));
4214 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config0
));
4218 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config1
));
4222 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config2
));
4226 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config3
));
4229 /* 6,7 are implementation dependent */
4231 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config6
));
4235 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Config7
));
4245 gen_helper_dmfc0_lladdr(t0
);
4255 gen_helper_1i(dmfc0_watchlo
, t0
, sel
);
4265 gen_helper_1i(mfc0_watchhi
, t0
, sel
);
4275 check_insn(env
, ctx
, ISA_MIPS3
);
4276 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_XContext
));
4284 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4287 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Framemask
));
4295 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
4296 rn
= "'Diagnostic"; /* implementation dependent */
4301 gen_helper_mfc0_debug(t0
); /* EJTAG support */
4305 // gen_helper_dmfc0_tracecontrol(t0); /* PDtrace support */
4306 rn
= "TraceControl";
4309 // gen_helper_dmfc0_tracecontrol2(t0); /* PDtrace support */
4310 rn
= "TraceControl2";
4313 // gen_helper_dmfc0_usertracedata(t0); /* PDtrace support */
4314 rn
= "UserTraceData";
4317 // gen_helper_dmfc0_tracebpc(t0); /* PDtrace support */
4328 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4338 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_Performance0
));
4339 rn
= "Performance0";
4342 // gen_helper_dmfc0_performance1(t0);
4343 rn
= "Performance1";
4346 // gen_helper_dmfc0_performance2(t0);
4347 rn
= "Performance2";
4350 // gen_helper_dmfc0_performance3(t0);
4351 rn
= "Performance3";
4354 // gen_helper_dmfc0_performance4(t0);
4355 rn
= "Performance4";
4358 // gen_helper_dmfc0_performance5(t0);
4359 rn
= "Performance5";
4362 // gen_helper_dmfc0_performance6(t0);
4363 rn
= "Performance6";
4366 // gen_helper_dmfc0_performance7(t0);
4367 rn
= "Performance7";
4374 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
4381 tcg_gen_movi_tl(t0
, 0); /* unimplemented */
4394 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagLo
));
4401 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataLo
));
4414 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_TagHi
));
4421 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DataHi
));
4431 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
4442 gen_mfc0_load32(t0
, offsetof(CPUState
, CP0_DESAVE
));
4452 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4456 LOG_DISAS("dmfc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
4457 generate_exception(ctx
, EXCP_RI
);
4460 static void gen_dmtc0 (CPUState
*env
, DisasContext
*ctx
, TCGv t0
, int reg
, int sel
)
4462 const char *rn
= "invalid";
4465 check_insn(env
, ctx
, ISA_MIPS64
);
4474 gen_helper_mtc0_index(t0
);
4478 check_insn(env
, ctx
, ASE_MT
);
4479 gen_helper_mtc0_mvpcontrol(t0
);
4483 check_insn(env
, ctx
, ASE_MT
);
4488 check_insn(env
, ctx
, ASE_MT
);
4503 check_insn(env
, ctx
, ASE_MT
);
4504 gen_helper_mtc0_vpecontrol(t0
);
4508 check_insn(env
, ctx
, ASE_MT
);
4509 gen_helper_mtc0_vpeconf0(t0
);
4513 check_insn(env
, ctx
, ASE_MT
);
4514 gen_helper_mtc0_vpeconf1(t0
);
4518 check_insn(env
, ctx
, ASE_MT
);
4519 gen_helper_mtc0_yqmask(t0
);
4523 check_insn(env
, ctx
, ASE_MT
);
4524 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPESchedule
));
4528 check_insn(env
, ctx
, ASE_MT
);
4529 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_VPEScheFBack
));
4530 rn
= "VPEScheFBack";
4533 check_insn(env
, ctx
, ASE_MT
);
4534 gen_helper_mtc0_vpeopt(t0
);
4544 gen_helper_mtc0_entrylo0(t0
);
4548 check_insn(env
, ctx
, ASE_MT
);
4549 gen_helper_mtc0_tcstatus(t0
);
4553 check_insn(env
, ctx
, ASE_MT
);
4554 gen_helper_mtc0_tcbind(t0
);
4558 check_insn(env
, ctx
, ASE_MT
);
4559 gen_helper_mtc0_tcrestart(t0
);
4563 check_insn(env
, ctx
, ASE_MT
);
4564 gen_helper_mtc0_tchalt(t0
);
4568 check_insn(env
, ctx
, ASE_MT
);
4569 gen_helper_mtc0_tccontext(t0
);
4573 check_insn(env
, ctx
, ASE_MT
);
4574 gen_helper_mtc0_tcschedule(t0
);
4578 check_insn(env
, ctx
, ASE_MT
);
4579 gen_helper_mtc0_tcschefback(t0
);
4589 gen_helper_mtc0_entrylo1(t0
);
4599 gen_helper_mtc0_context(t0
);
4603 // gen_helper_mtc0_contextconfig(t0); /* SmartMIPS ASE */
4604 rn
= "ContextConfig";
4613 gen_helper_mtc0_pagemask(t0
);
4617 check_insn(env
, ctx
, ISA_MIPS32R2
);
4618 gen_helper_mtc0_pagegrain(t0
);
4628 gen_helper_mtc0_wired(t0
);
4632 check_insn(env
, ctx
, ISA_MIPS32R2
);
4633 gen_helper_mtc0_srsconf0(t0
);
4637 check_insn(env
, ctx
, ISA_MIPS32R2
);
4638 gen_helper_mtc0_srsconf1(t0
);
4642 check_insn(env
, ctx
, ISA_MIPS32R2
);
4643 gen_helper_mtc0_srsconf2(t0
);
4647 check_insn(env
, ctx
, ISA_MIPS32R2
);
4648 gen_helper_mtc0_srsconf3(t0
);
4652 check_insn(env
, ctx
, ISA_MIPS32R2
);
4653 gen_helper_mtc0_srsconf4(t0
);
4663 check_insn(env
, ctx
, ISA_MIPS32R2
);
4664 gen_helper_mtc0_hwrena(t0
);
4678 gen_helper_mtc0_count(t0
);
4681 /* 6,7 are implementation dependent */
4685 /* Stop translation as we may have switched the execution mode */
4686 ctx
->bstate
= BS_STOP
;
4691 gen_helper_mtc0_entryhi(t0
);
4701 gen_helper_mtc0_compare(t0
);
4704 /* 6,7 are implementation dependent */
4708 /* Stop translation as we may have switched the execution mode */
4709 ctx
->bstate
= BS_STOP
;
4714 gen_helper_mtc0_status(t0
);
4715 /* BS_STOP isn't good enough here, hflags may have changed. */
4716 gen_save_pc(ctx
->pc
+ 4);
4717 ctx
->bstate
= BS_EXCP
;
4721 check_insn(env
, ctx
, ISA_MIPS32R2
);
4722 gen_helper_mtc0_intctl(t0
);
4723 /* Stop translation as we may have switched the execution mode */
4724 ctx
->bstate
= BS_STOP
;
4728 check_insn(env
, ctx
, ISA_MIPS32R2
);
4729 gen_helper_mtc0_srsctl(t0
);
4730 /* Stop translation as we may have switched the execution mode */
4731 ctx
->bstate
= BS_STOP
;
4735 check_insn(env
, ctx
, ISA_MIPS32R2
);
4736 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_SRSMap
));
4737 /* Stop translation as we may have switched the execution mode */
4738 ctx
->bstate
= BS_STOP
;
4748 gen_helper_mtc0_cause(t0
);
4754 /* Stop translation as we may have switched the execution mode */
4755 ctx
->bstate
= BS_STOP
;
4760 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_EPC
));
4774 check_insn(env
, ctx
, ISA_MIPS32R2
);
4775 gen_helper_mtc0_ebase(t0
);
4785 gen_helper_mtc0_config0(t0
);
4787 /* Stop translation as we may have switched the execution mode */
4788 ctx
->bstate
= BS_STOP
;
4795 gen_helper_mtc0_config2(t0
);
4797 /* Stop translation as we may have switched the execution mode */
4798 ctx
->bstate
= BS_STOP
;
4804 /* 6,7 are implementation dependent */
4806 rn
= "Invalid config selector";
4823 gen_helper_1i(mtc0_watchlo
, t0
, sel
);
4833 gen_helper_1i(mtc0_watchhi
, t0
, sel
);
4843 check_insn(env
, ctx
, ISA_MIPS3
);
4844 gen_helper_mtc0_xcontext(t0
);
4852 /* Officially reserved, but sel 0 is used for R1x000 framemask */
4855 gen_helper_mtc0_framemask(t0
);
4864 rn
= "Diagnostic"; /* implementation dependent */
4869 gen_helper_mtc0_debug(t0
); /* EJTAG support */
4870 /* BS_STOP isn't good enough here, hflags may have changed. */
4871 gen_save_pc(ctx
->pc
+ 4);
4872 ctx
->bstate
= BS_EXCP
;
4876 // gen_helper_mtc0_tracecontrol(t0); /* PDtrace support */
4877 /* Stop translation as we may have switched the execution mode */
4878 ctx
->bstate
= BS_STOP
;
4879 rn
= "TraceControl";
4882 // gen_helper_mtc0_tracecontrol2(t0); /* PDtrace support */
4883 /* Stop translation as we may have switched the execution mode */
4884 ctx
->bstate
= BS_STOP
;
4885 rn
= "TraceControl2";
4888 // gen_helper_mtc0_usertracedata(t0); /* PDtrace support */
4889 /* Stop translation as we may have switched the execution mode */
4890 ctx
->bstate
= BS_STOP
;
4891 rn
= "UserTraceData";
4894 // gen_helper_mtc0_tracebpc(t0); /* PDtrace support */
4895 /* Stop translation as we may have switched the execution mode */
4896 ctx
->bstate
= BS_STOP
;
4907 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_DEPC
));
4917 gen_helper_mtc0_performance0(t0
);
4918 rn
= "Performance0";
4921 // gen_helper_mtc0_performance1(t0);
4922 rn
= "Performance1";
4925 // gen_helper_mtc0_performance2(t0);
4926 rn
= "Performance2";
4929 // gen_helper_mtc0_performance3(t0);
4930 rn
= "Performance3";
4933 // gen_helper_mtc0_performance4(t0);
4934 rn
= "Performance4";
4937 // gen_helper_mtc0_performance5(t0);
4938 rn
= "Performance5";
4941 // gen_helper_mtc0_performance6(t0);
4942 rn
= "Performance6";
4945 // gen_helper_mtc0_performance7(t0);
4946 rn
= "Performance7";
4972 gen_helper_mtc0_taglo(t0
);
4979 gen_helper_mtc0_datalo(t0
);
4992 gen_helper_mtc0_taghi(t0
);
4999 gen_helper_mtc0_datahi(t0
);
5010 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, CP0_ErrorEPC
));
5021 gen_mtc0_store32(t0
, offsetof(CPUState
, CP0_DESAVE
));
5027 /* Stop translation as we may have switched the execution mode */
5028 ctx
->bstate
= BS_STOP
;
5033 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5034 /* For simplicity assume that all writes can cause interrupts. */
5037 ctx
->bstate
= BS_STOP
;
5042 LOG_DISAS("dmtc0 %s (reg %d sel %d)\n", rn
, reg
, sel
);
5043 generate_exception(ctx
, EXCP_RI
);
5045 #endif /* TARGET_MIPS64 */
5047 static void gen_mftr(CPUState
*env
, DisasContext
*ctx
, int rt
, int rd
,
5048 int u
, int sel
, int h
)
5050 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5051 TCGv t0
= tcg_temp_local_new();
5053 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5054 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5055 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5056 tcg_gen_movi_tl(t0
, -1);
5057 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5058 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5059 tcg_gen_movi_tl(t0
, -1);
5065 gen_helper_mftc0_tcstatus(t0
);
5068 gen_helper_mftc0_tcbind(t0
);
5071 gen_helper_mftc0_tcrestart(t0
);
5074 gen_helper_mftc0_tchalt(t0
);
5077 gen_helper_mftc0_tccontext(t0
);
5080 gen_helper_mftc0_tcschedule(t0
);
5083 gen_helper_mftc0_tcschefback(t0
);
5086 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5093 gen_helper_mftc0_entryhi(t0
);
5096 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5102 gen_helper_mftc0_status(t0
);
5105 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5111 gen_helper_mftc0_debug(t0
);
5114 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5119 gen_mfc0(env
, ctx
, t0
, rt
, sel
);
5121 } else switch (sel
) {
5122 /* GPR registers. */
5124 gen_helper_1i(mftgpr
, t0
, rt
);
5126 /* Auxiliary CPU registers */
5130 gen_helper_1i(mftlo
, t0
, 0);
5133 gen_helper_1i(mfthi
, t0
, 0);
5136 gen_helper_1i(mftacx
, t0
, 0);
5139 gen_helper_1i(mftlo
, t0
, 1);
5142 gen_helper_1i(mfthi
, t0
, 1);
5145 gen_helper_1i(mftacx
, t0
, 1);
5148 gen_helper_1i(mftlo
, t0
, 2);
5151 gen_helper_1i(mfthi
, t0
, 2);
5154 gen_helper_1i(mftacx
, t0
, 2);
5157 gen_helper_1i(mftlo
, t0
, 3);
5160 gen_helper_1i(mfthi
, t0
, 3);
5163 gen_helper_1i(mftacx
, t0
, 3);
5166 gen_helper_mftdsp(t0
);
5172 /* Floating point (COP1). */
5174 /* XXX: For now we support only a single FPU context. */
5176 TCGv_i32 fp0
= tcg_temp_new_i32();
5178 gen_load_fpr32(fp0
, rt
);
5179 tcg_gen_ext_i32_tl(t0
, fp0
);
5180 tcg_temp_free_i32(fp0
);
5182 TCGv_i32 fp0
= tcg_temp_new_i32();
5184 gen_load_fpr32h(fp0
, rt
);
5185 tcg_gen_ext_i32_tl(t0
, fp0
);
5186 tcg_temp_free_i32(fp0
);
5190 /* XXX: For now we support only a single FPU context. */
5191 gen_helper_1i(cfc1
, t0
, rt
);
5193 /* COP2: Not implemented. */
5200 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5201 gen_store_gpr(t0
, rd
);
5207 LOG_DISAS("mftr (reg %d u %d sel %d h %d)\n", rt
, u
, sel
, h
);
5208 generate_exception(ctx
, EXCP_RI
);
5211 static void gen_mttr(CPUState
*env
, DisasContext
*ctx
, int rd
, int rt
,
5212 int u
, int sel
, int h
)
5214 int other_tc
= env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
);
5215 TCGv t0
= tcg_temp_local_new();
5217 gen_load_gpr(t0
, rt
);
5218 if ((env
->CP0_VPEConf0
& (1 << CP0VPEC0_MVP
)) == 0 &&
5219 ((env
->tcs
[other_tc
].CP0_TCBind
& (0xf << CP0TCBd_CurVPE
)) !=
5220 (env
->active_tc
.CP0_TCBind
& (0xf << CP0TCBd_CurVPE
))))
5222 else if ((env
->CP0_VPEControl
& (0xff << CP0VPECo_TargTC
)) >
5223 (env
->mvp
->CP0_MVPConf0
& (0xff << CP0MVPC0_PTC
)))
5230 gen_helper_mttc0_tcstatus(t0
);
5233 gen_helper_mttc0_tcbind(t0
);
5236 gen_helper_mttc0_tcrestart(t0
);
5239 gen_helper_mttc0_tchalt(t0
);
5242 gen_helper_mttc0_tccontext(t0
);
5245 gen_helper_mttc0_tcschedule(t0
);
5248 gen_helper_mttc0_tcschefback(t0
);
5251 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5258 gen_helper_mttc0_entryhi(t0
);
5261 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5267 gen_helper_mttc0_status(t0
);
5270 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5276 gen_helper_mttc0_debug(t0
);
5279 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5284 gen_mtc0(env
, ctx
, t0
, rd
, sel
);
5286 } else switch (sel
) {
5287 /* GPR registers. */
5289 gen_helper_1i(mttgpr
, t0
, rd
);
5291 /* Auxiliary CPU registers */
5295 gen_helper_1i(mttlo
, t0
, 0);
5298 gen_helper_1i(mtthi
, t0
, 0);
5301 gen_helper_1i(mttacx
, t0
, 0);
5304 gen_helper_1i(mttlo
, t0
, 1);
5307 gen_helper_1i(mtthi
, t0
, 1);
5310 gen_helper_1i(mttacx
, t0
, 1);
5313 gen_helper_1i(mttlo
, t0
, 2);
5316 gen_helper_1i(mtthi
, t0
, 2);
5319 gen_helper_1i(mttacx
, t0
, 2);
5322 gen_helper_1i(mttlo
, t0
, 3);
5325 gen_helper_1i(mtthi
, t0
, 3);
5328 gen_helper_1i(mttacx
, t0
, 3);
5331 gen_helper_mttdsp(t0
);
5337 /* Floating point (COP1). */
5339 /* XXX: For now we support only a single FPU context. */
5341 TCGv_i32 fp0
= tcg_temp_new_i32();
5343 tcg_gen_trunc_tl_i32(fp0
, t0
);
5344 gen_store_fpr32(fp0
, rd
);
5345 tcg_temp_free_i32(fp0
);
5347 TCGv_i32 fp0
= tcg_temp_new_i32();
5349 tcg_gen_trunc_tl_i32(fp0
, t0
);
5350 gen_store_fpr32h(fp0
, rd
);
5351 tcg_temp_free_i32(fp0
);
5355 /* XXX: For now we support only a single FPU context. */
5356 gen_helper_1i(ctc1
, t0
, rd
);
5358 /* COP2: Not implemented. */
5365 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5371 LOG_DISAS("mttr (reg %d u %d sel %d h %d)\n", rd
, u
, sel
, h
);
5372 generate_exception(ctx
, EXCP_RI
);
5375 static void gen_cp0 (CPUState
*env
, DisasContext
*ctx
, uint32_t opc
, int rt
, int rd
)
5377 const char *opn
= "ldst";
5386 TCGv t0
= tcg_temp_local_new();
5388 gen_mfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5389 gen_store_gpr(t0
, rt
);
5396 TCGv t0
= tcg_temp_local_new();
5398 gen_load_gpr(t0
, rt
);
5399 save_cpu_state(ctx
, 1);
5400 gen_mtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5405 #if defined(TARGET_MIPS64)
5407 check_insn(env
, ctx
, ISA_MIPS3
);
5413 TCGv t0
= tcg_temp_local_new();
5415 gen_dmfc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5416 gen_store_gpr(t0
, rt
);
5422 check_insn(env
, ctx
, ISA_MIPS3
);
5424 TCGv t0
= tcg_temp_local_new();
5426 gen_load_gpr(t0
, rt
);
5427 save_cpu_state(ctx
, 1);
5428 gen_dmtc0(env
, ctx
, t0
, rd
, ctx
->opcode
& 0x7);
5435 check_insn(env
, ctx
, ASE_MT
);
5440 gen_mftr(env
, ctx
, rt
, rd
, (ctx
->opcode
>> 5) & 1,
5441 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5445 check_insn(env
, ctx
, ASE_MT
);
5446 gen_mttr(env
, ctx
, rd
, rt
, (ctx
->opcode
>> 5) & 1,
5447 ctx
->opcode
& 0x7, (ctx
->opcode
>> 4) & 1);
5452 if (!env
->tlb
->helper_tlbwi
)
5458 if (!env
->tlb
->helper_tlbwr
)
5464 if (!env
->tlb
->helper_tlbp
)
5470 if (!env
->tlb
->helper_tlbr
)
5476 check_insn(env
, ctx
, ISA_MIPS2
);
5477 save_cpu_state(ctx
, 1);
5479 ctx
->bstate
= BS_EXCP
;
5483 check_insn(env
, ctx
, ISA_MIPS32
);
5484 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
5486 generate_exception(ctx
, EXCP_RI
);
5488 save_cpu_state(ctx
, 1);
5490 ctx
->bstate
= BS_EXCP
;
5495 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
5496 /* If we get an exception, we want to restart at next instruction */
5498 save_cpu_state(ctx
, 1);
5501 ctx
->bstate
= BS_EXCP
;
5506 generate_exception(ctx
, EXCP_RI
);
5509 MIPS_DEBUG("%s %s %d", opn
, regnames
[rt
], rd
);
5511 #endif /* !CONFIG_USER_ONLY */
5513 /* CP1 Branches (before delay slot) */
5514 static void gen_compute_branch1 (CPUState
*env
, DisasContext
*ctx
, uint32_t op
,
5515 int32_t cc
, int32_t offset
)
5517 target_ulong btarget
;
5518 const char *opn
= "cp1 cond branch";
5519 TCGv_i32 t0
= tcg_temp_new_i32();
5522 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
5524 btarget
= ctx
->pc
+ 4 + offset
;
5529 int l1
= gen_new_label();
5530 int l2
= gen_new_label();
5533 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5534 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5535 tcg_gen_movi_i32(bcond
, 0);
5538 tcg_gen_movi_i32(bcond
, 1);
5545 int l1
= gen_new_label();
5546 int l2
= gen_new_label();
5549 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5550 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5551 tcg_gen_movi_i32(bcond
, 0);
5554 tcg_gen_movi_i32(bcond
, 1);
5561 int l1
= gen_new_label();
5562 int l2
= gen_new_label();
5565 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5566 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5567 tcg_gen_movi_i32(bcond
, 0);
5570 tcg_gen_movi_i32(bcond
, 1);
5577 int l1
= gen_new_label();
5578 int l2
= gen_new_label();
5581 tcg_gen_andi_i32(t0
, t0
, 0x1 << cc
);
5582 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5583 tcg_gen_movi_i32(bcond
, 0);
5586 tcg_gen_movi_i32(bcond
, 1);
5591 ctx
->hflags
|= MIPS_HFLAG_BL
;
5595 int l1
= gen_new_label();
5596 int l2
= gen_new_label();
5599 tcg_gen_andi_i32(t0
, t0
, 0x3 << cc
);
5600 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5601 tcg_gen_movi_i32(bcond
, 0);
5604 tcg_gen_movi_i32(bcond
, 1);
5611 int l1
= gen_new_label();
5612 int l2
= gen_new_label();
5615 tcg_gen_andi_i32(t0
, t0
, 0x3 << cc
);
5616 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5617 tcg_gen_movi_i32(bcond
, 0);
5620 tcg_gen_movi_i32(bcond
, 1);
5627 int l1
= gen_new_label();
5628 int l2
= gen_new_label();
5631 tcg_gen_andi_i32(t0
, t0
, 0xf << cc
);
5632 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
5633 tcg_gen_movi_i32(bcond
, 0);
5636 tcg_gen_movi_i32(bcond
, 1);
5643 int l1
= gen_new_label();
5644 int l2
= gen_new_label();
5647 tcg_gen_andi_i32(t0
, t0
, 0xf << cc
);
5648 tcg_gen_brcondi_i32(TCG_COND_NE
, t0
, 0, l1
);
5649 tcg_gen_movi_i32(bcond
, 0);
5652 tcg_gen_movi_i32(bcond
, 1);
5657 ctx
->hflags
|= MIPS_HFLAG_BC
;
5661 generate_exception (ctx
, EXCP_RI
);
5664 MIPS_DEBUG("%s: cond %02x target " TARGET_FMT_lx
, opn
,
5665 ctx
->hflags
, btarget
);
5666 ctx
->btarget
= btarget
;
5669 tcg_temp_free_i32(t0
);
5672 /* Coprocessor 1 (FPU) */
5674 #define FOP(func, fmt) (((fmt) << 21) | (func))
5676 static void gen_cp1 (DisasContext
*ctx
, uint32_t opc
, int rt
, int fs
)
5678 const char *opn
= "cp1 move";
5679 TCGv t0
= tcg_temp_local_new();
5684 TCGv_i32 fp0
= tcg_temp_new_i32();
5686 gen_load_fpr32(fp0
, fs
);
5687 tcg_gen_ext_i32_tl(t0
, fp0
);
5688 tcg_temp_free_i32(fp0
);
5690 gen_store_gpr(t0
, rt
);
5694 gen_load_gpr(t0
, rt
);
5696 TCGv_i32 fp0
= tcg_temp_new_i32();
5698 tcg_gen_trunc_tl_i32(fp0
, t0
);
5699 gen_store_fpr32(fp0
, fs
);
5700 tcg_temp_free_i32(fp0
);
5705 gen_helper_1i(cfc1
, t0
, fs
);
5706 gen_store_gpr(t0
, rt
);
5710 gen_load_gpr(t0
, rt
);
5711 gen_helper_1i(ctc1
, t0
, fs
);
5716 TCGv_i64 fp0
= tcg_temp_new_i64();
5718 gen_load_fpr64(ctx
, fp0
, fs
);
5719 tcg_gen_trunc_i64_tl(t0
, fp0
);
5720 tcg_temp_free_i64(fp0
);
5722 gen_store_gpr(t0
, rt
);
5726 gen_load_gpr(t0
, rt
);
5728 TCGv_i64 fp0
= tcg_temp_new_i64();
5730 tcg_gen_extu_tl_i64(fp0
, t0
);
5731 gen_store_fpr64(ctx
, fp0
, fs
);
5732 tcg_temp_free_i64(fp0
);
5738 TCGv_i32 fp0
= tcg_temp_new_i32();
5740 gen_load_fpr32h(fp0
, fs
);
5741 tcg_gen_ext_i32_tl(t0
, fp0
);
5742 tcg_temp_free_i32(fp0
);
5744 gen_store_gpr(t0
, rt
);
5748 gen_load_gpr(t0
, rt
);
5750 TCGv_i32 fp0
= tcg_temp_new_i32();
5752 tcg_gen_trunc_tl_i32(fp0
, t0
);
5753 gen_store_fpr32h(fp0
, fs
);
5754 tcg_temp_free_i32(fp0
);
5760 generate_exception (ctx
, EXCP_RI
);
5763 MIPS_DEBUG("%s %s %s", opn
, regnames
[rt
], fregnames
[fs
]);
5769 static void gen_movci (DisasContext
*ctx
, int rd
, int rs
, int cc
, int tf
)
5771 int l1
= gen_new_label();
5774 TCGv t0
= tcg_temp_local_new();
5775 TCGv_i32 r_tmp
= tcg_temp_new_i32();
5778 ccbit
= 1 << (24 + cc
);
5786 gen_load_gpr(t0
, rd
);
5787 tcg_gen_andi_i32(r_tmp
, fpu_fcr31
, ccbit
);
5788 tcg_gen_brcondi_i32(cond
, r_tmp
, 0, l1
);
5789 tcg_temp_free_i32(r_tmp
);
5790 gen_load_gpr(t0
, rs
);
5792 gen_store_gpr(t0
, rd
);
5796 static inline void gen_movcf_s (int fs
, int fd
, int cc
, int tf
)
5800 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
5801 TCGv_i32 fp0
= tcg_temp_local_new_i32();
5802 int l1
= gen_new_label();
5805 ccbit
= 1 << (24 + cc
);
5814 gen_load_fpr32(fp0
, fd
);
5815 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit
);
5816 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5817 tcg_temp_free_i32(r_tmp1
);
5818 gen_load_fpr32(fp0
, fs
);
5820 gen_store_fpr32(fp0
, fd
);
5821 tcg_temp_free_i32(fp0
);
5824 static inline void gen_movcf_d (DisasContext
*ctx
, int fs
, int fd
, int cc
, int tf
)
5828 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
5829 TCGv_i64 fp0
= tcg_temp_local_new_i64();
5830 int l1
= gen_new_label();
5833 ccbit
= 1 << (24 + cc
);
5842 gen_load_fpr64(ctx
, fp0
, fd
);
5843 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit
);
5844 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5845 tcg_temp_free_i32(r_tmp1
);
5846 gen_load_fpr64(ctx
, fp0
, fs
);
5848 gen_store_fpr64(ctx
, fp0
, fd
);
5849 tcg_temp_free_i64(fp0
);
5852 static inline void gen_movcf_ps (int fs
, int fd
, int cc
, int tf
)
5854 uint32_t ccbit1
, ccbit2
;
5856 TCGv_i32 r_tmp1
= tcg_temp_new_i32();
5857 TCGv_i32 fp0
= tcg_temp_local_new_i32();
5858 int l1
= gen_new_label();
5859 int l2
= gen_new_label();
5862 ccbit1
= 1 << (24 + cc
);
5863 ccbit2
= 1 << (25 + cc
);
5874 gen_load_fpr32(fp0
, fd
);
5875 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit1
);
5876 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l1
);
5877 gen_load_fpr32(fp0
, fs
);
5879 gen_store_fpr32(fp0
, fd
);
5881 gen_load_fpr32h(fp0
, fd
);
5882 tcg_gen_andi_i32(r_tmp1
, fpu_fcr31
, ccbit2
);
5883 tcg_gen_brcondi_i32(cond
, r_tmp1
, 0, l2
);
5884 gen_load_fpr32h(fp0
, fs
);
5886 gen_store_fpr32h(fp0
, fd
);
5888 tcg_temp_free_i32(r_tmp1
);
5889 tcg_temp_free_i32(fp0
);
5893 static void gen_farith (DisasContext
*ctx
, uint32_t op1
,
5894 int ft
, int fs
, int fd
, int cc
)
5896 const char *opn
= "farith";
5897 const char *condnames
[] = {
5915 const char *condnames_abs
[] = {
5933 enum { BINOP
, CMPOP
, OTHEROP
} optype
= OTHEROP
;
5934 uint32_t func
= ctx
->opcode
& 0x3f;
5936 switch (ctx
->opcode
& FOP(0x3f, 0x1f)) {
5939 TCGv_i32 fp0
= tcg_temp_new_i32();
5940 TCGv_i32 fp1
= tcg_temp_new_i32();
5942 gen_load_fpr32(fp0
, fs
);
5943 gen_load_fpr32(fp1
, ft
);
5944 gen_helper_float_add_s(fp0
, fp0
, fp1
);
5945 tcg_temp_free_i32(fp1
);
5946 gen_store_fpr32(fp0
, fd
);
5947 tcg_temp_free_i32(fp0
);
5954 TCGv_i32 fp0
= tcg_temp_new_i32();
5955 TCGv_i32 fp1
= tcg_temp_new_i32();
5957 gen_load_fpr32(fp0
, fs
);
5958 gen_load_fpr32(fp1
, ft
);
5959 gen_helper_float_sub_s(fp0
, fp0
, fp1
);
5960 tcg_temp_free_i32(fp1
);
5961 gen_store_fpr32(fp0
, fd
);
5962 tcg_temp_free_i32(fp0
);
5969 TCGv_i32 fp0
= tcg_temp_new_i32();
5970 TCGv_i32 fp1
= tcg_temp_new_i32();
5972 gen_load_fpr32(fp0
, fs
);
5973 gen_load_fpr32(fp1
, ft
);
5974 gen_helper_float_mul_s(fp0
, fp0
, fp1
);
5975 tcg_temp_free_i32(fp1
);
5976 gen_store_fpr32(fp0
, fd
);
5977 tcg_temp_free_i32(fp0
);
5984 TCGv_i32 fp0
= tcg_temp_new_i32();
5985 TCGv_i32 fp1
= tcg_temp_new_i32();
5987 gen_load_fpr32(fp0
, fs
);
5988 gen_load_fpr32(fp1
, ft
);
5989 gen_helper_float_div_s(fp0
, fp0
, fp1
);
5990 tcg_temp_free_i32(fp1
);
5991 gen_store_fpr32(fp0
, fd
);
5992 tcg_temp_free_i32(fp0
);
5999 TCGv_i32 fp0
= tcg_temp_new_i32();
6001 gen_load_fpr32(fp0
, fs
);
6002 gen_helper_float_sqrt_s(fp0
, fp0
);
6003 gen_store_fpr32(fp0
, fd
);
6004 tcg_temp_free_i32(fp0
);
6010 TCGv_i32 fp0
= tcg_temp_new_i32();
6012 gen_load_fpr32(fp0
, fs
);
6013 gen_helper_float_abs_s(fp0
, fp0
);
6014 gen_store_fpr32(fp0
, fd
);
6015 tcg_temp_free_i32(fp0
);
6021 TCGv_i32 fp0
= tcg_temp_new_i32();
6023 gen_load_fpr32(fp0
, fs
);
6024 gen_store_fpr32(fp0
, fd
);
6025 tcg_temp_free_i32(fp0
);
6031 TCGv_i32 fp0
= tcg_temp_new_i32();
6033 gen_load_fpr32(fp0
, fs
);
6034 gen_helper_float_chs_s(fp0
, fp0
);
6035 gen_store_fpr32(fp0
, fd
);
6036 tcg_temp_free_i32(fp0
);
6041 check_cp1_64bitmode(ctx
);
6043 TCGv_i32 fp32
= tcg_temp_new_i32();
6044 TCGv_i64 fp64
= tcg_temp_new_i64();
6046 gen_load_fpr32(fp32
, fs
);
6047 gen_helper_float_roundl_s(fp64
, fp32
);
6048 tcg_temp_free_i32(fp32
);
6049 gen_store_fpr64(ctx
, fp64
, fd
);
6050 tcg_temp_free_i64(fp64
);
6055 check_cp1_64bitmode(ctx
);
6057 TCGv_i32 fp32
= tcg_temp_new_i32();
6058 TCGv_i64 fp64
= tcg_temp_new_i64();
6060 gen_load_fpr32(fp32
, fs
);
6061 gen_helper_float_truncl_s(fp64
, fp32
);
6062 tcg_temp_free_i32(fp32
);
6063 gen_store_fpr64(ctx
, fp64
, fd
);
6064 tcg_temp_free_i64(fp64
);
6069 check_cp1_64bitmode(ctx
);
6071 TCGv_i32 fp32
= tcg_temp_new_i32();
6072 TCGv_i64 fp64
= tcg_temp_new_i64();
6074 gen_load_fpr32(fp32
, fs
);
6075 gen_helper_float_ceill_s(fp64
, fp32
);
6076 tcg_temp_free_i32(fp32
);
6077 gen_store_fpr64(ctx
, fp64
, fd
);
6078 tcg_temp_free_i64(fp64
);
6083 check_cp1_64bitmode(ctx
);
6085 TCGv_i32 fp32
= tcg_temp_new_i32();
6086 TCGv_i64 fp64
= tcg_temp_new_i64();
6088 gen_load_fpr32(fp32
, fs
);
6089 gen_helper_float_floorl_s(fp64
, fp32
);
6090 tcg_temp_free_i32(fp32
);
6091 gen_store_fpr64(ctx
, fp64
, fd
);
6092 tcg_temp_free_i64(fp64
);
6098 TCGv_i32 fp0
= tcg_temp_new_i32();
6100 gen_load_fpr32(fp0
, fs
);
6101 gen_helper_float_roundw_s(fp0
, fp0
);
6102 gen_store_fpr32(fp0
, fd
);
6103 tcg_temp_free_i32(fp0
);
6109 TCGv_i32 fp0
= tcg_temp_new_i32();
6111 gen_load_fpr32(fp0
, fs
);
6112 gen_helper_float_truncw_s(fp0
, fp0
);
6113 gen_store_fpr32(fp0
, fd
);
6114 tcg_temp_free_i32(fp0
);
6120 TCGv_i32 fp0
= tcg_temp_new_i32();
6122 gen_load_fpr32(fp0
, fs
);
6123 gen_helper_float_ceilw_s(fp0
, fp0
);
6124 gen_store_fpr32(fp0
, fd
);
6125 tcg_temp_free_i32(fp0
);
6131 TCGv_i32 fp0
= tcg_temp_new_i32();
6133 gen_load_fpr32(fp0
, fs
);
6134 gen_helper_float_floorw_s(fp0
, fp0
);
6135 gen_store_fpr32(fp0
, fd
);
6136 tcg_temp_free_i32(fp0
);
6141 gen_movcf_s(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6146 int l1
= gen_new_label();
6147 TCGv t0
= tcg_temp_new();
6148 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6150 gen_load_gpr(t0
, ft
);
6151 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6152 gen_load_fpr32(fp0
, fs
);
6153 gen_store_fpr32(fp0
, fd
);
6154 tcg_temp_free_i32(fp0
);
6162 int l1
= gen_new_label();
6163 TCGv t0
= tcg_temp_new();
6164 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6166 gen_load_gpr(t0
, ft
);
6167 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6168 gen_load_fpr32(fp0
, fs
);
6169 gen_store_fpr32(fp0
, fd
);
6170 tcg_temp_free_i32(fp0
);
6179 TCGv_i32 fp0
= tcg_temp_new_i32();
6181 gen_load_fpr32(fp0
, fs
);
6182 gen_helper_float_recip_s(fp0
, fp0
);
6183 gen_store_fpr32(fp0
, fd
);
6184 tcg_temp_free_i32(fp0
);
6191 TCGv_i32 fp0
= tcg_temp_new_i32();
6193 gen_load_fpr32(fp0
, fs
);
6194 gen_helper_float_rsqrt_s(fp0
, fp0
);
6195 gen_store_fpr32(fp0
, fd
);
6196 tcg_temp_free_i32(fp0
);
6201 check_cp1_64bitmode(ctx
);
6203 TCGv_i32 fp0
= tcg_temp_new_i32();
6204 TCGv_i32 fp1
= tcg_temp_new_i32();
6206 gen_load_fpr32(fp0
, fs
);
6207 gen_load_fpr32(fp1
, fd
);
6208 gen_helper_float_recip2_s(fp0
, fp0
, fp1
);
6209 tcg_temp_free_i32(fp1
);
6210 gen_store_fpr32(fp0
, fd
);
6211 tcg_temp_free_i32(fp0
);
6216 check_cp1_64bitmode(ctx
);
6218 TCGv_i32 fp0
= tcg_temp_new_i32();
6220 gen_load_fpr32(fp0
, fs
);
6221 gen_helper_float_recip1_s(fp0
, fp0
);
6222 gen_store_fpr32(fp0
, fd
);
6223 tcg_temp_free_i32(fp0
);
6228 check_cp1_64bitmode(ctx
);
6230 TCGv_i32 fp0
= tcg_temp_new_i32();
6232 gen_load_fpr32(fp0
, fs
);
6233 gen_helper_float_rsqrt1_s(fp0
, fp0
);
6234 gen_store_fpr32(fp0
, fd
);
6235 tcg_temp_free_i32(fp0
);
6240 check_cp1_64bitmode(ctx
);
6242 TCGv_i32 fp0
= tcg_temp_new_i32();
6243 TCGv_i32 fp1
= tcg_temp_new_i32();
6245 gen_load_fpr32(fp0
, fs
);
6246 gen_load_fpr32(fp1
, ft
);
6247 gen_helper_float_rsqrt2_s(fp0
, fp0
, fp1
);
6248 tcg_temp_free_i32(fp1
);
6249 gen_store_fpr32(fp0
, fd
);
6250 tcg_temp_free_i32(fp0
);
6255 check_cp1_registers(ctx
, fd
);
6257 TCGv_i32 fp32
= tcg_temp_new_i32();
6258 TCGv_i64 fp64
= tcg_temp_new_i64();
6260 gen_load_fpr32(fp32
, fs
);
6261 gen_helper_float_cvtd_s(fp64
, fp32
);
6262 tcg_temp_free_i32(fp32
);
6263 gen_store_fpr64(ctx
, fp64
, fd
);
6264 tcg_temp_free_i64(fp64
);
6270 TCGv_i32 fp0
= tcg_temp_new_i32();
6272 gen_load_fpr32(fp0
, fs
);
6273 gen_helper_float_cvtw_s(fp0
, fp0
);
6274 gen_store_fpr32(fp0
, fd
);
6275 tcg_temp_free_i32(fp0
);
6280 check_cp1_64bitmode(ctx
);
6282 TCGv_i32 fp32
= tcg_temp_new_i32();
6283 TCGv_i64 fp64
= tcg_temp_new_i64();
6285 gen_load_fpr32(fp32
, fs
);
6286 gen_helper_float_cvtl_s(fp64
, fp32
);
6287 tcg_temp_free_i32(fp32
);
6288 gen_store_fpr64(ctx
, fp64
, fd
);
6289 tcg_temp_free_i64(fp64
);
6294 check_cp1_64bitmode(ctx
);
6296 TCGv_i64 fp64
= tcg_temp_new_i64();
6297 TCGv_i32 fp32_0
= tcg_temp_new_i32();
6298 TCGv_i32 fp32_1
= tcg_temp_new_i32();
6300 gen_load_fpr32(fp32_0
, fs
);
6301 gen_load_fpr32(fp32_1
, ft
);
6302 tcg_gen_concat_i32_i64(fp64
, fp32_0
, fp32_1
);
6303 tcg_temp_free_i32(fp32_1
);
6304 tcg_temp_free_i32(fp32_0
);
6305 gen_store_fpr64(ctx
, fp64
, fd
);
6306 tcg_temp_free_i64(fp64
);
6327 TCGv_i32 fp0
= tcg_temp_new_i32();
6328 TCGv_i32 fp1
= tcg_temp_new_i32();
6330 gen_load_fpr32(fp0
, fs
);
6331 gen_load_fpr32(fp1
, ft
);
6332 if (ctx
->opcode
& (1 << 6)) {
6334 gen_cmpabs_s(func
-48, fp0
, fp1
, cc
);
6335 opn
= condnames_abs
[func
-48];
6337 gen_cmp_s(func
-48, fp0
, fp1
, cc
);
6338 opn
= condnames
[func
-48];
6340 tcg_temp_free_i32(fp0
);
6341 tcg_temp_free_i32(fp1
);
6345 check_cp1_registers(ctx
, fs
| ft
| fd
);
6347 TCGv_i64 fp0
= tcg_temp_new_i64();
6348 TCGv_i64 fp1
= tcg_temp_new_i64();
6350 gen_load_fpr64(ctx
, fp0
, fs
);
6351 gen_load_fpr64(ctx
, fp1
, ft
);
6352 gen_helper_float_add_d(fp0
, fp0
, fp1
);
6353 tcg_temp_free_i64(fp1
);
6354 gen_store_fpr64(ctx
, fp0
, fd
);
6355 tcg_temp_free_i64(fp0
);
6361 check_cp1_registers(ctx
, fs
| ft
| fd
);
6363 TCGv_i64 fp0
= tcg_temp_new_i64();
6364 TCGv_i64 fp1
= tcg_temp_new_i64();
6366 gen_load_fpr64(ctx
, fp0
, fs
);
6367 gen_load_fpr64(ctx
, fp1
, ft
);
6368 gen_helper_float_sub_d(fp0
, fp0
, fp1
);
6369 tcg_temp_free_i64(fp1
);
6370 gen_store_fpr64(ctx
, fp0
, fd
);
6371 tcg_temp_free_i64(fp0
);
6377 check_cp1_registers(ctx
, fs
| ft
| fd
);
6379 TCGv_i64 fp0
= tcg_temp_new_i64();
6380 TCGv_i64 fp1
= tcg_temp_new_i64();
6382 gen_load_fpr64(ctx
, fp0
, fs
);
6383 gen_load_fpr64(ctx
, fp1
, ft
);
6384 gen_helper_float_mul_d(fp0
, fp0
, fp1
);
6385 tcg_temp_free_i64(fp1
);
6386 gen_store_fpr64(ctx
, fp0
, fd
);
6387 tcg_temp_free_i64(fp0
);
6393 check_cp1_registers(ctx
, fs
| ft
| fd
);
6395 TCGv_i64 fp0
= tcg_temp_new_i64();
6396 TCGv_i64 fp1
= tcg_temp_new_i64();
6398 gen_load_fpr64(ctx
, fp0
, fs
);
6399 gen_load_fpr64(ctx
, fp1
, ft
);
6400 gen_helper_float_div_d(fp0
, fp0
, fp1
);
6401 tcg_temp_free_i64(fp1
);
6402 gen_store_fpr64(ctx
, fp0
, fd
);
6403 tcg_temp_free_i64(fp0
);
6409 check_cp1_registers(ctx
, fs
| fd
);
6411 TCGv_i64 fp0
= tcg_temp_new_i64();
6413 gen_load_fpr64(ctx
, fp0
, fs
);
6414 gen_helper_float_sqrt_d(fp0
, fp0
);
6415 gen_store_fpr64(ctx
, fp0
, fd
);
6416 tcg_temp_free_i64(fp0
);
6421 check_cp1_registers(ctx
, fs
| fd
);
6423 TCGv_i64 fp0
= tcg_temp_new_i64();
6425 gen_load_fpr64(ctx
, fp0
, fs
);
6426 gen_helper_float_abs_d(fp0
, fp0
);
6427 gen_store_fpr64(ctx
, fp0
, fd
);
6428 tcg_temp_free_i64(fp0
);
6433 check_cp1_registers(ctx
, fs
| fd
);
6435 TCGv_i64 fp0
= tcg_temp_new_i64();
6437 gen_load_fpr64(ctx
, fp0
, fs
);
6438 gen_store_fpr64(ctx
, fp0
, fd
);
6439 tcg_temp_free_i64(fp0
);
6444 check_cp1_registers(ctx
, fs
| fd
);
6446 TCGv_i64 fp0
= tcg_temp_new_i64();
6448 gen_load_fpr64(ctx
, fp0
, fs
);
6449 gen_helper_float_chs_d(fp0
, fp0
);
6450 gen_store_fpr64(ctx
, fp0
, fd
);
6451 tcg_temp_free_i64(fp0
);
6456 check_cp1_64bitmode(ctx
);
6458 TCGv_i64 fp0
= tcg_temp_new_i64();
6460 gen_load_fpr64(ctx
, fp0
, fs
);
6461 gen_helper_float_roundl_d(fp0
, fp0
);
6462 gen_store_fpr64(ctx
, fp0
, fd
);
6463 tcg_temp_free_i64(fp0
);
6468 check_cp1_64bitmode(ctx
);
6470 TCGv_i64 fp0
= tcg_temp_new_i64();
6472 gen_load_fpr64(ctx
, fp0
, fs
);
6473 gen_helper_float_truncl_d(fp0
, fp0
);
6474 gen_store_fpr64(ctx
, fp0
, fd
);
6475 tcg_temp_free_i64(fp0
);
6480 check_cp1_64bitmode(ctx
);
6482 TCGv_i64 fp0
= tcg_temp_new_i64();
6484 gen_load_fpr64(ctx
, fp0
, fs
);
6485 gen_helper_float_ceill_d(fp0
, fp0
);
6486 gen_store_fpr64(ctx
, fp0
, fd
);
6487 tcg_temp_free_i64(fp0
);
6492 check_cp1_64bitmode(ctx
);
6494 TCGv_i64 fp0
= tcg_temp_new_i64();
6496 gen_load_fpr64(ctx
, fp0
, fs
);
6497 gen_helper_float_floorl_d(fp0
, fp0
);
6498 gen_store_fpr64(ctx
, fp0
, fd
);
6499 tcg_temp_free_i64(fp0
);
6504 check_cp1_registers(ctx
, fs
);
6506 TCGv_i32 fp32
= tcg_temp_new_i32();
6507 TCGv_i64 fp64
= tcg_temp_new_i64();
6509 gen_load_fpr64(ctx
, fp64
, fs
);
6510 gen_helper_float_roundw_d(fp32
, fp64
);
6511 tcg_temp_free_i64(fp64
);
6512 gen_store_fpr32(fp32
, fd
);
6513 tcg_temp_free_i32(fp32
);
6518 check_cp1_registers(ctx
, fs
);
6520 TCGv_i32 fp32
= tcg_temp_new_i32();
6521 TCGv_i64 fp64
= tcg_temp_new_i64();
6523 gen_load_fpr64(ctx
, fp64
, fs
);
6524 gen_helper_float_truncw_d(fp32
, fp64
);
6525 tcg_temp_free_i64(fp64
);
6526 gen_store_fpr32(fp32
, fd
);
6527 tcg_temp_free_i32(fp32
);
6532 check_cp1_registers(ctx
, fs
);
6534 TCGv_i32 fp32
= tcg_temp_new_i32();
6535 TCGv_i64 fp64
= tcg_temp_new_i64();
6537 gen_load_fpr64(ctx
, fp64
, fs
);
6538 gen_helper_float_ceilw_d(fp32
, fp64
);
6539 tcg_temp_free_i64(fp64
);
6540 gen_store_fpr32(fp32
, fd
);
6541 tcg_temp_free_i32(fp32
);
6546 check_cp1_registers(ctx
, fs
);
6548 TCGv_i32 fp32
= tcg_temp_new_i32();
6549 TCGv_i64 fp64
= tcg_temp_new_i64();
6551 gen_load_fpr64(ctx
, fp64
, fs
);
6552 gen_helper_float_floorw_d(fp32
, fp64
);
6553 tcg_temp_free_i64(fp64
);
6554 gen_store_fpr32(fp32
, fd
);
6555 tcg_temp_free_i32(fp32
);
6560 gen_movcf_d(ctx
, fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6565 int l1
= gen_new_label();
6566 TCGv t0
= tcg_temp_new();
6567 TCGv_i64 fp0
= tcg_temp_local_new_i64();
6569 gen_load_gpr(t0
, ft
);
6570 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6571 gen_load_fpr64(ctx
, fp0
, fs
);
6572 gen_store_fpr64(ctx
, fp0
, fd
);
6573 tcg_temp_free_i64(fp0
);
6581 int l1
= gen_new_label();
6582 TCGv t0
= tcg_temp_new();
6583 TCGv_i64 fp0
= tcg_temp_local_new_i64();
6585 gen_load_gpr(t0
, ft
);
6586 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6587 gen_load_fpr64(ctx
, fp0
, fs
);
6588 gen_store_fpr64(ctx
, fp0
, fd
);
6589 tcg_temp_free_i64(fp0
);
6596 check_cp1_64bitmode(ctx
);
6598 TCGv_i64 fp0
= tcg_temp_new_i64();
6600 gen_load_fpr64(ctx
, fp0
, fs
);
6601 gen_helper_float_recip_d(fp0
, fp0
);
6602 gen_store_fpr64(ctx
, fp0
, fd
);
6603 tcg_temp_free_i64(fp0
);
6608 check_cp1_64bitmode(ctx
);
6610 TCGv_i64 fp0
= tcg_temp_new_i64();
6612 gen_load_fpr64(ctx
, fp0
, fs
);
6613 gen_helper_float_rsqrt_d(fp0
, fp0
);
6614 gen_store_fpr64(ctx
, fp0
, fd
);
6615 tcg_temp_free_i64(fp0
);
6620 check_cp1_64bitmode(ctx
);
6622 TCGv_i64 fp0
= tcg_temp_new_i64();
6623 TCGv_i64 fp1
= tcg_temp_new_i64();
6625 gen_load_fpr64(ctx
, fp0
, fs
);
6626 gen_load_fpr64(ctx
, fp1
, ft
);
6627 gen_helper_float_recip2_d(fp0
, fp0
, fp1
);
6628 tcg_temp_free_i64(fp1
);
6629 gen_store_fpr64(ctx
, fp0
, fd
);
6630 tcg_temp_free_i64(fp0
);
6635 check_cp1_64bitmode(ctx
);
6637 TCGv_i64 fp0
= tcg_temp_new_i64();
6639 gen_load_fpr64(ctx
, fp0
, fs
);
6640 gen_helper_float_recip1_d(fp0
, fp0
);
6641 gen_store_fpr64(ctx
, fp0
, fd
);
6642 tcg_temp_free_i64(fp0
);
6647 check_cp1_64bitmode(ctx
);
6649 TCGv_i64 fp0
= tcg_temp_new_i64();
6651 gen_load_fpr64(ctx
, fp0
, fs
);
6652 gen_helper_float_rsqrt1_d(fp0
, fp0
);
6653 gen_store_fpr64(ctx
, fp0
, fd
);
6654 tcg_temp_free_i64(fp0
);
6659 check_cp1_64bitmode(ctx
);
6661 TCGv_i64 fp0
= tcg_temp_new_i64();
6662 TCGv_i64 fp1
= tcg_temp_new_i64();
6664 gen_load_fpr64(ctx
, fp0
, fs
);
6665 gen_load_fpr64(ctx
, fp1
, ft
);
6666 gen_helper_float_rsqrt2_d(fp0
, fp0
, fp1
);
6667 tcg_temp_free_i64(fp1
);
6668 gen_store_fpr64(ctx
, fp0
, fd
);
6669 tcg_temp_free_i64(fp0
);
6690 TCGv_i64 fp0
= tcg_temp_new_i64();
6691 TCGv_i64 fp1
= tcg_temp_new_i64();
6693 gen_load_fpr64(ctx
, fp0
, fs
);
6694 gen_load_fpr64(ctx
, fp1
, ft
);
6695 if (ctx
->opcode
& (1 << 6)) {
6697 check_cp1_registers(ctx
, fs
| ft
);
6698 gen_cmpabs_d(func
-48, fp0
, fp1
, cc
);
6699 opn
= condnames_abs
[func
-48];
6701 check_cp1_registers(ctx
, fs
| ft
);
6702 gen_cmp_d(func
-48, fp0
, fp1
, cc
);
6703 opn
= condnames
[func
-48];
6705 tcg_temp_free_i64(fp0
);
6706 tcg_temp_free_i64(fp1
);
6710 check_cp1_registers(ctx
, fs
);
6712 TCGv_i32 fp32
= tcg_temp_new_i32();
6713 TCGv_i64 fp64
= tcg_temp_new_i64();
6715 gen_load_fpr64(ctx
, fp64
, fs
);
6716 gen_helper_float_cvts_d(fp32
, fp64
);
6717 tcg_temp_free_i64(fp64
);
6718 gen_store_fpr32(fp32
, fd
);
6719 tcg_temp_free_i32(fp32
);
6724 check_cp1_registers(ctx
, fs
);
6726 TCGv_i32 fp32
= tcg_temp_new_i32();
6727 TCGv_i64 fp64
= tcg_temp_new_i64();
6729 gen_load_fpr64(ctx
, fp64
, fs
);
6730 gen_helper_float_cvtw_d(fp32
, fp64
);
6731 tcg_temp_free_i64(fp64
);
6732 gen_store_fpr32(fp32
, fd
);
6733 tcg_temp_free_i32(fp32
);
6738 check_cp1_64bitmode(ctx
);
6740 TCGv_i64 fp0
= tcg_temp_new_i64();
6742 gen_load_fpr64(ctx
, fp0
, fs
);
6743 gen_helper_float_cvtl_d(fp0
, fp0
);
6744 gen_store_fpr64(ctx
, fp0
, fd
);
6745 tcg_temp_free_i64(fp0
);
6751 TCGv_i32 fp0
= tcg_temp_new_i32();
6753 gen_load_fpr32(fp0
, fs
);
6754 gen_helper_float_cvts_w(fp0
, fp0
);
6755 gen_store_fpr32(fp0
, fd
);
6756 tcg_temp_free_i32(fp0
);
6761 check_cp1_registers(ctx
, fd
);
6763 TCGv_i32 fp32
= tcg_temp_new_i32();
6764 TCGv_i64 fp64
= tcg_temp_new_i64();
6766 gen_load_fpr32(fp32
, fs
);
6767 gen_helper_float_cvtd_w(fp64
, fp32
);
6768 tcg_temp_free_i32(fp32
);
6769 gen_store_fpr64(ctx
, fp64
, fd
);
6770 tcg_temp_free_i64(fp64
);
6775 check_cp1_64bitmode(ctx
);
6777 TCGv_i32 fp32
= tcg_temp_new_i32();
6778 TCGv_i64 fp64
= tcg_temp_new_i64();
6780 gen_load_fpr64(ctx
, fp64
, fs
);
6781 gen_helper_float_cvts_l(fp32
, fp64
);
6782 tcg_temp_free_i64(fp64
);
6783 gen_store_fpr32(fp32
, fd
);
6784 tcg_temp_free_i32(fp32
);
6789 check_cp1_64bitmode(ctx
);
6791 TCGv_i64 fp0
= tcg_temp_new_i64();
6793 gen_load_fpr64(ctx
, fp0
, fs
);
6794 gen_helper_float_cvtd_l(fp0
, fp0
);
6795 gen_store_fpr64(ctx
, fp0
, fd
);
6796 tcg_temp_free_i64(fp0
);
6801 check_cp1_64bitmode(ctx
);
6803 TCGv_i64 fp0
= tcg_temp_new_i64();
6805 gen_load_fpr64(ctx
, fp0
, fs
);
6806 gen_helper_float_cvtps_pw(fp0
, fp0
);
6807 gen_store_fpr64(ctx
, fp0
, fd
);
6808 tcg_temp_free_i64(fp0
);
6813 check_cp1_64bitmode(ctx
);
6815 TCGv_i64 fp0
= tcg_temp_new_i64();
6816 TCGv_i64 fp1
= tcg_temp_new_i64();
6818 gen_load_fpr64(ctx
, fp0
, fs
);
6819 gen_load_fpr64(ctx
, fp1
, ft
);
6820 gen_helper_float_add_ps(fp0
, fp0
, fp1
);
6821 tcg_temp_free_i64(fp1
);
6822 gen_store_fpr64(ctx
, fp0
, fd
);
6823 tcg_temp_free_i64(fp0
);
6828 check_cp1_64bitmode(ctx
);
6830 TCGv_i64 fp0
= tcg_temp_new_i64();
6831 TCGv_i64 fp1
= tcg_temp_new_i64();
6833 gen_load_fpr64(ctx
, fp0
, fs
);
6834 gen_load_fpr64(ctx
, fp1
, ft
);
6835 gen_helper_float_sub_ps(fp0
, fp0
, fp1
);
6836 tcg_temp_free_i64(fp1
);
6837 gen_store_fpr64(ctx
, fp0
, fd
);
6838 tcg_temp_free_i64(fp0
);
6843 check_cp1_64bitmode(ctx
);
6845 TCGv_i64 fp0
= tcg_temp_new_i64();
6846 TCGv_i64 fp1
= tcg_temp_new_i64();
6848 gen_load_fpr64(ctx
, fp0
, fs
);
6849 gen_load_fpr64(ctx
, fp1
, ft
);
6850 gen_helper_float_mul_ps(fp0
, fp0
, fp1
);
6851 tcg_temp_free_i64(fp1
);
6852 gen_store_fpr64(ctx
, fp0
, fd
);
6853 tcg_temp_free_i64(fp0
);
6858 check_cp1_64bitmode(ctx
);
6860 TCGv_i64 fp0
= tcg_temp_new_i64();
6862 gen_load_fpr64(ctx
, fp0
, fs
);
6863 gen_helper_float_abs_ps(fp0
, fp0
);
6864 gen_store_fpr64(ctx
, fp0
, fd
);
6865 tcg_temp_free_i64(fp0
);
6870 check_cp1_64bitmode(ctx
);
6872 TCGv_i64 fp0
= tcg_temp_new_i64();
6874 gen_load_fpr64(ctx
, fp0
, fs
);
6875 gen_store_fpr64(ctx
, fp0
, fd
);
6876 tcg_temp_free_i64(fp0
);
6881 check_cp1_64bitmode(ctx
);
6883 TCGv_i64 fp0
= tcg_temp_new_i64();
6885 gen_load_fpr64(ctx
, fp0
, fs
);
6886 gen_helper_float_chs_ps(fp0
, fp0
);
6887 gen_store_fpr64(ctx
, fp0
, fd
);
6888 tcg_temp_free_i64(fp0
);
6893 check_cp1_64bitmode(ctx
);
6894 gen_movcf_ps(fs
, fd
, (ft
>> 2) & 0x7, ft
& 0x1);
6898 check_cp1_64bitmode(ctx
);
6900 int l1
= gen_new_label();
6901 TCGv t0
= tcg_temp_new();
6902 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6903 TCGv_i32 fph0
= tcg_temp_local_new_i32();
6905 gen_load_gpr(t0
, ft
);
6906 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
6907 gen_load_fpr32(fp0
, fs
);
6908 gen_load_fpr32h(fph0
, fs
);
6909 gen_store_fpr32(fp0
, fd
);
6910 gen_store_fpr32h(fph0
, fd
);
6911 tcg_temp_free_i32(fp0
);
6912 tcg_temp_free_i32(fph0
);
6919 check_cp1_64bitmode(ctx
);
6921 int l1
= gen_new_label();
6922 TCGv t0
= tcg_temp_new();
6923 TCGv_i32 fp0
= tcg_temp_local_new_i32();
6924 TCGv_i32 fph0
= tcg_temp_local_new_i32();
6926 gen_load_gpr(t0
, ft
);
6927 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6928 gen_load_fpr32(fp0
, fs
);
6929 gen_load_fpr32h(fph0
, fs
);
6930 gen_store_fpr32(fp0
, fd
);
6931 gen_store_fpr32h(fph0
, fd
);
6932 tcg_temp_free_i32(fp0
);
6933 tcg_temp_free_i32(fph0
);
6940 check_cp1_64bitmode(ctx
);
6942 TCGv_i64 fp0
= tcg_temp_new_i64();
6943 TCGv_i64 fp1
= tcg_temp_new_i64();
6945 gen_load_fpr64(ctx
, fp0
, ft
);
6946 gen_load_fpr64(ctx
, fp1
, fs
);
6947 gen_helper_float_addr_ps(fp0
, fp0
, fp1
);
6948 tcg_temp_free_i64(fp1
);
6949 gen_store_fpr64(ctx
, fp0
, fd
);
6950 tcg_temp_free_i64(fp0
);
6955 check_cp1_64bitmode(ctx
);
6957 TCGv_i64 fp0
= tcg_temp_new_i64();
6958 TCGv_i64 fp1
= tcg_temp_new_i64();
6960 gen_load_fpr64(ctx
, fp0
, ft
);
6961 gen_load_fpr64(ctx
, fp1
, fs
);
6962 gen_helper_float_mulr_ps(fp0
, fp0
, fp1
);
6963 tcg_temp_free_i64(fp1
);
6964 gen_store_fpr64(ctx
, fp0
, fd
);
6965 tcg_temp_free_i64(fp0
);
6970 check_cp1_64bitmode(ctx
);
6972 TCGv_i64 fp0
= tcg_temp_new_i64();
6973 TCGv_i64 fp1
= tcg_temp_new_i64();
6975 gen_load_fpr64(ctx
, fp0
, fs
);
6976 gen_load_fpr64(ctx
, fp1
, fd
);
6977 gen_helper_float_recip2_ps(fp0
, fp0
, fp1
);
6978 tcg_temp_free_i64(fp1
);
6979 gen_store_fpr64(ctx
, fp0
, fd
);
6980 tcg_temp_free_i64(fp0
);
6985 check_cp1_64bitmode(ctx
);
6987 TCGv_i64 fp0
= tcg_temp_new_i64();
6989 gen_load_fpr64(ctx
, fp0
, fs
);
6990 gen_helper_float_recip1_ps(fp0
, fp0
);
6991 gen_store_fpr64(ctx
, fp0
, fd
);
6992 tcg_temp_free_i64(fp0
);
6997 check_cp1_64bitmode(ctx
);
6999 TCGv_i64 fp0
= tcg_temp_new_i64();
7001 gen_load_fpr64(ctx
, fp0
, fs
);
7002 gen_helper_float_rsqrt1_ps(fp0
, fp0
);
7003 gen_store_fpr64(ctx
, fp0
, fd
);
7004 tcg_temp_free_i64(fp0
);
7009 check_cp1_64bitmode(ctx
);
7011 TCGv_i64 fp0
= tcg_temp_new_i64();
7012 TCGv_i64 fp1
= tcg_temp_new_i64();
7014 gen_load_fpr64(ctx
, fp0
, fs
);
7015 gen_load_fpr64(ctx
, fp1
, ft
);
7016 gen_helper_float_rsqrt2_ps(fp0
, fp0
, fp1
);
7017 tcg_temp_free_i64(fp1
);
7018 gen_store_fpr64(ctx
, fp0
, fd
);
7019 tcg_temp_free_i64(fp0
);
7024 check_cp1_64bitmode(ctx
);
7026 TCGv_i32 fp0
= tcg_temp_new_i32();
7028 gen_load_fpr32h(fp0
, fs
);
7029 gen_helper_float_cvts_pu(fp0
, fp0
);
7030 gen_store_fpr32(fp0
, fd
);
7031 tcg_temp_free_i32(fp0
);
7036 check_cp1_64bitmode(ctx
);
7038 TCGv_i64 fp0
= tcg_temp_new_i64();
7040 gen_load_fpr64(ctx
, fp0
, fs
);
7041 gen_helper_float_cvtpw_ps(fp0
, fp0
);
7042 gen_store_fpr64(ctx
, fp0
, fd
);
7043 tcg_temp_free_i64(fp0
);
7048 check_cp1_64bitmode(ctx
);
7050 TCGv_i32 fp0
= tcg_temp_new_i32();
7052 gen_load_fpr32(fp0
, fs
);
7053 gen_helper_float_cvts_pl(fp0
, fp0
);
7054 gen_store_fpr32(fp0
, fd
);
7055 tcg_temp_free_i32(fp0
);
7060 check_cp1_64bitmode(ctx
);
7062 TCGv_i32 fp0
= tcg_temp_new_i32();
7063 TCGv_i32 fp1
= tcg_temp_new_i32();
7065 gen_load_fpr32(fp0
, fs
);
7066 gen_load_fpr32(fp1
, ft
);
7067 gen_store_fpr32h(fp0
, fd
);
7068 gen_store_fpr32(fp1
, fd
);
7069 tcg_temp_free_i32(fp0
);
7070 tcg_temp_free_i32(fp1
);
7075 check_cp1_64bitmode(ctx
);
7077 TCGv_i32 fp0
= tcg_temp_new_i32();
7078 TCGv_i32 fp1
= tcg_temp_new_i32();
7080 gen_load_fpr32(fp0
, fs
);
7081 gen_load_fpr32h(fp1
, ft
);
7082 gen_store_fpr32(fp1
, fd
);
7083 gen_store_fpr32h(fp0
, fd
);
7084 tcg_temp_free_i32(fp0
);
7085 tcg_temp_free_i32(fp1
);
7090 check_cp1_64bitmode(ctx
);
7092 TCGv_i32 fp0
= tcg_temp_new_i32();
7093 TCGv_i32 fp1
= tcg_temp_new_i32();
7095 gen_load_fpr32h(fp0
, fs
);
7096 gen_load_fpr32(fp1
, ft
);
7097 gen_store_fpr32(fp1
, fd
);
7098 gen_store_fpr32h(fp0
, fd
);
7099 tcg_temp_free_i32(fp0
);
7100 tcg_temp_free_i32(fp1
);
7105 check_cp1_64bitmode(ctx
);
7107 TCGv_i32 fp0
= tcg_temp_new_i32();
7108 TCGv_i32 fp1
= tcg_temp_new_i32();
7110 gen_load_fpr32h(fp0
, fs
);
7111 gen_load_fpr32h(fp1
, ft
);
7112 gen_store_fpr32(fp1
, fd
);
7113 gen_store_fpr32h(fp0
, fd
);
7114 tcg_temp_free_i32(fp0
);
7115 tcg_temp_free_i32(fp1
);
7135 check_cp1_64bitmode(ctx
);
7137 TCGv_i64 fp0
= tcg_temp_new_i64();
7138 TCGv_i64 fp1
= tcg_temp_new_i64();
7140 gen_load_fpr64(ctx
, fp0
, fs
);
7141 gen_load_fpr64(ctx
, fp1
, ft
);
7142 if (ctx
->opcode
& (1 << 6)) {
7143 gen_cmpabs_ps(func
-48, fp0
, fp1
, cc
);
7144 opn
= condnames_abs
[func
-48];
7146 gen_cmp_ps(func
-48, fp0
, fp1
, cc
);
7147 opn
= condnames
[func
-48];
7149 tcg_temp_free_i64(fp0
);
7150 tcg_temp_free_i64(fp1
);
7155 generate_exception (ctx
, EXCP_RI
);
7160 MIPS_DEBUG("%s %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fs
], fregnames
[ft
]);
7163 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fs
], fregnames
[ft
]);
7166 MIPS_DEBUG("%s %s,%s", opn
, fregnames
[fd
], fregnames
[fs
]);
7171 /* Coprocessor 3 (FPU) */
7172 static void gen_flt3_ldst (DisasContext
*ctx
, uint32_t opc
,
7173 int fd
, int fs
, int base
, int index
)
7175 const char *opn
= "extended float load/store";
7177 TCGv t0
= tcg_temp_local_new();
7178 TCGv t1
= tcg_temp_local_new();
7181 gen_load_gpr(t0
, index
);
7182 } else if (index
== 0) {
7183 gen_load_gpr(t0
, base
);
7185 gen_load_gpr(t0
, index
);
7186 gen_op_addr_add(ctx
, t0
, cpu_gpr
[base
]);
7188 /* Don't do NOP if destination is zero: we must perform the actual
7194 TCGv_i32 fp0
= tcg_temp_new_i32();
7196 tcg_gen_qemu_ld32s(t1
, t0
, ctx
->mem_idx
);
7197 tcg_gen_trunc_tl_i32(fp0
, t1
);
7198 gen_store_fpr32(fp0
, fd
);
7199 tcg_temp_free_i32(fp0
);
7205 check_cp1_registers(ctx
, fd
);
7207 TCGv_i64 fp0
= tcg_temp_new_i64();
7209 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7210 gen_store_fpr64(ctx
, fp0
, fd
);
7211 tcg_temp_free_i64(fp0
);
7216 check_cp1_64bitmode(ctx
);
7217 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7219 TCGv_i64 fp0
= tcg_temp_new_i64();
7221 tcg_gen_qemu_ld64(fp0
, t0
, ctx
->mem_idx
);
7222 gen_store_fpr64(ctx
, fp0
, fd
);
7223 tcg_temp_free_i64(fp0
);
7230 TCGv_i32 fp0
= tcg_temp_new_i32();
7232 gen_load_fpr32(fp0
, fs
);
7233 tcg_gen_extu_i32_tl(t1
, fp0
);
7234 tcg_gen_qemu_st32(t1
, t0
, ctx
->mem_idx
);
7235 tcg_temp_free_i32(fp0
);
7242 check_cp1_registers(ctx
, fs
);
7244 TCGv_i64 fp0
= tcg_temp_new_i64();
7246 gen_load_fpr64(ctx
, fp0
, fs
);
7247 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7248 tcg_temp_free_i64(fp0
);
7254 check_cp1_64bitmode(ctx
);
7255 tcg_gen_andi_tl(t0
, t0
, ~0x7);
7257 TCGv_i64 fp0
= tcg_temp_new_i64();
7259 gen_load_fpr64(ctx
, fp0
, fs
);
7260 tcg_gen_qemu_st64(fp0
, t0
, ctx
->mem_idx
);
7261 tcg_temp_free_i64(fp0
);
7268 generate_exception(ctx
, EXCP_RI
);
7275 MIPS_DEBUG("%s %s, %s(%s)", opn
, fregnames
[store
? fs
: fd
],
7276 regnames
[index
], regnames
[base
]);
7279 static void gen_flt3_arith (DisasContext
*ctx
, uint32_t opc
,
7280 int fd
, int fr
, int fs
, int ft
)
7282 const char *opn
= "flt3_arith";
7286 check_cp1_64bitmode(ctx
);
7288 TCGv t0
= tcg_temp_local_new();
7289 TCGv_i32 fp0
= tcg_temp_local_new_i32();
7290 TCGv_i32 fph0
= tcg_temp_local_new_i32();
7291 TCGv_i32 fp1
= tcg_temp_local_new_i32();
7292 TCGv_i32 fph1
= tcg_temp_local_new_i32();
7293 int l1
= gen_new_label();
7294 int l2
= gen_new_label();
7296 gen_load_gpr(t0
, fr
);
7297 tcg_gen_andi_tl(t0
, t0
, 0x7);
7298 gen_load_fpr32(fp0
, fs
);
7299 gen_load_fpr32h(fph0
, fs
);
7300 gen_load_fpr32(fp1
, ft
);
7301 gen_load_fpr32h(fph1
, ft
);
7303 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 0, l1
);
7304 gen_store_fpr32(fp0
, fd
);
7305 gen_store_fpr32h(fph0
, fd
);
7308 tcg_gen_brcondi_tl(TCG_COND_NE
, t0
, 4, l2
);
7310 #ifdef TARGET_WORDS_BIGENDIAN
7311 gen_store_fpr32(fph1
, fd
);
7312 gen_store_fpr32h(fp0
, fd
);
7314 gen_store_fpr32(fph0
, fd
);
7315 gen_store_fpr32h(fp1
, fd
);
7318 tcg_temp_free_i32(fp0
);
7319 tcg_temp_free_i32(fph0
);
7320 tcg_temp_free_i32(fp1
);
7321 tcg_temp_free_i32(fph1
);
7328 TCGv_i32 fp0
= tcg_temp_new_i32();
7329 TCGv_i32 fp1
= tcg_temp_new_i32();
7330 TCGv_i32 fp2
= tcg_temp_new_i32();
7332 gen_load_fpr32(fp0
, fs
);
7333 gen_load_fpr32(fp1
, ft
);
7334 gen_load_fpr32(fp2
, fr
);
7335 gen_helper_float_muladd_s(fp2
, fp0
, fp1
, fp2
);
7336 tcg_temp_free_i32(fp0
);
7337 tcg_temp_free_i32(fp1
);
7338 gen_store_fpr32(fp2
, fd
);
7339 tcg_temp_free_i32(fp2
);
7345 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7347 TCGv_i64 fp0
= tcg_temp_new_i64();
7348 TCGv_i64 fp1
= tcg_temp_new_i64();
7349 TCGv_i64 fp2
= tcg_temp_new_i64();
7351 gen_load_fpr64(ctx
, fp0
, fs
);
7352 gen_load_fpr64(ctx
, fp1
, ft
);
7353 gen_load_fpr64(ctx
, fp2
, fr
);
7354 gen_helper_float_muladd_d(fp2
, fp0
, fp1
, fp2
);
7355 tcg_temp_free_i64(fp0
);
7356 tcg_temp_free_i64(fp1
);
7357 gen_store_fpr64(ctx
, fp2
, fd
);
7358 tcg_temp_free_i64(fp2
);
7363 check_cp1_64bitmode(ctx
);
7365 TCGv_i64 fp0
= tcg_temp_new_i64();
7366 TCGv_i64 fp1
= tcg_temp_new_i64();
7367 TCGv_i64 fp2
= tcg_temp_new_i64();
7369 gen_load_fpr64(ctx
, fp0
, fs
);
7370 gen_load_fpr64(ctx
, fp1
, ft
);
7371 gen_load_fpr64(ctx
, fp2
, fr
);
7372 gen_helper_float_muladd_ps(fp2
, fp0
, fp1
, fp2
);
7373 tcg_temp_free_i64(fp0
);
7374 tcg_temp_free_i64(fp1
);
7375 gen_store_fpr64(ctx
, fp2
, fd
);
7376 tcg_temp_free_i64(fp2
);
7383 TCGv_i32 fp0
= tcg_temp_new_i32();
7384 TCGv_i32 fp1
= tcg_temp_new_i32();
7385 TCGv_i32 fp2
= tcg_temp_new_i32();
7387 gen_load_fpr32(fp0
, fs
);
7388 gen_load_fpr32(fp1
, ft
);
7389 gen_load_fpr32(fp2
, fr
);
7390 gen_helper_float_mulsub_s(fp2
, fp0
, fp1
, fp2
);
7391 tcg_temp_free_i32(fp0
);
7392 tcg_temp_free_i32(fp1
);
7393 gen_store_fpr32(fp2
, fd
);
7394 tcg_temp_free_i32(fp2
);
7400 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7402 TCGv_i64 fp0
= tcg_temp_new_i64();
7403 TCGv_i64 fp1
= tcg_temp_new_i64();
7404 TCGv_i64 fp2
= tcg_temp_new_i64();
7406 gen_load_fpr64(ctx
, fp0
, fs
);
7407 gen_load_fpr64(ctx
, fp1
, ft
);
7408 gen_load_fpr64(ctx
, fp2
, fr
);
7409 gen_helper_float_mulsub_d(fp2
, fp0
, fp1
, fp2
);
7410 tcg_temp_free_i64(fp0
);
7411 tcg_temp_free_i64(fp1
);
7412 gen_store_fpr64(ctx
, fp2
, fd
);
7413 tcg_temp_free_i64(fp2
);
7418 check_cp1_64bitmode(ctx
);
7420 TCGv_i64 fp0
= tcg_temp_new_i64();
7421 TCGv_i64 fp1
= tcg_temp_new_i64();
7422 TCGv_i64 fp2
= tcg_temp_new_i64();
7424 gen_load_fpr64(ctx
, fp0
, fs
);
7425 gen_load_fpr64(ctx
, fp1
, ft
);
7426 gen_load_fpr64(ctx
, fp2
, fr
);
7427 gen_helper_float_mulsub_ps(fp2
, fp0
, fp1
, fp2
);
7428 tcg_temp_free_i64(fp0
);
7429 tcg_temp_free_i64(fp1
);
7430 gen_store_fpr64(ctx
, fp2
, fd
);
7431 tcg_temp_free_i64(fp2
);
7438 TCGv_i32 fp0
= tcg_temp_new_i32();
7439 TCGv_i32 fp1
= tcg_temp_new_i32();
7440 TCGv_i32 fp2
= tcg_temp_new_i32();
7442 gen_load_fpr32(fp0
, fs
);
7443 gen_load_fpr32(fp1
, ft
);
7444 gen_load_fpr32(fp2
, fr
);
7445 gen_helper_float_nmuladd_s(fp2
, fp0
, fp1
, fp2
);
7446 tcg_temp_free_i32(fp0
);
7447 tcg_temp_free_i32(fp1
);
7448 gen_store_fpr32(fp2
, fd
);
7449 tcg_temp_free_i32(fp2
);
7455 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7457 TCGv_i64 fp0
= tcg_temp_new_i64();
7458 TCGv_i64 fp1
= tcg_temp_new_i64();
7459 TCGv_i64 fp2
= tcg_temp_new_i64();
7461 gen_load_fpr64(ctx
, fp0
, fs
);
7462 gen_load_fpr64(ctx
, fp1
, ft
);
7463 gen_load_fpr64(ctx
, fp2
, fr
);
7464 gen_helper_float_nmuladd_d(fp2
, fp0
, fp1
, fp2
);
7465 tcg_temp_free_i64(fp0
);
7466 tcg_temp_free_i64(fp1
);
7467 gen_store_fpr64(ctx
, fp2
, fd
);
7468 tcg_temp_free_i64(fp2
);
7473 check_cp1_64bitmode(ctx
);
7475 TCGv_i64 fp0
= tcg_temp_new_i64();
7476 TCGv_i64 fp1
= tcg_temp_new_i64();
7477 TCGv_i64 fp2
= tcg_temp_new_i64();
7479 gen_load_fpr64(ctx
, fp0
, fs
);
7480 gen_load_fpr64(ctx
, fp1
, ft
);
7481 gen_load_fpr64(ctx
, fp2
, fr
);
7482 gen_helper_float_nmuladd_ps(fp2
, fp0
, fp1
, fp2
);
7483 tcg_temp_free_i64(fp0
);
7484 tcg_temp_free_i64(fp1
);
7485 gen_store_fpr64(ctx
, fp2
, fd
);
7486 tcg_temp_free_i64(fp2
);
7493 TCGv_i32 fp0
= tcg_temp_new_i32();
7494 TCGv_i32 fp1
= tcg_temp_new_i32();
7495 TCGv_i32 fp2
= tcg_temp_new_i32();
7497 gen_load_fpr32(fp0
, fs
);
7498 gen_load_fpr32(fp1
, ft
);
7499 gen_load_fpr32(fp2
, fr
);
7500 gen_helper_float_nmulsub_s(fp2
, fp0
, fp1
, fp2
);
7501 tcg_temp_free_i32(fp0
);
7502 tcg_temp_free_i32(fp1
);
7503 gen_store_fpr32(fp2
, fd
);
7504 tcg_temp_free_i32(fp2
);
7510 check_cp1_registers(ctx
, fd
| fs
| ft
| fr
);
7512 TCGv_i64 fp0
= tcg_temp_new_i64();
7513 TCGv_i64 fp1
= tcg_temp_new_i64();
7514 TCGv_i64 fp2
= tcg_temp_new_i64();
7516 gen_load_fpr64(ctx
, fp0
, fs
);
7517 gen_load_fpr64(ctx
, fp1
, ft
);
7518 gen_load_fpr64(ctx
, fp2
, fr
);
7519 gen_helper_float_nmulsub_d(fp2
, fp0
, fp1
, fp2
);
7520 tcg_temp_free_i64(fp0
);
7521 tcg_temp_free_i64(fp1
);
7522 gen_store_fpr64(ctx
, fp2
, fd
);
7523 tcg_temp_free_i64(fp2
);
7528 check_cp1_64bitmode(ctx
);
7530 TCGv_i64 fp0
= tcg_temp_new_i64();
7531 TCGv_i64 fp1
= tcg_temp_new_i64();
7532 TCGv_i64 fp2
= tcg_temp_new_i64();
7534 gen_load_fpr64(ctx
, fp0
, fs
);
7535 gen_load_fpr64(ctx
, fp1
, ft
);
7536 gen_load_fpr64(ctx
, fp2
, fr
);
7537 gen_helper_float_nmulsub_ps(fp2
, fp0
, fp1
, fp2
);
7538 tcg_temp_free_i64(fp0
);
7539 tcg_temp_free_i64(fp1
);
7540 gen_store_fpr64(ctx
, fp2
, fd
);
7541 tcg_temp_free_i64(fp2
);
7547 generate_exception (ctx
, EXCP_RI
);
7550 MIPS_DEBUG("%s %s, %s, %s, %s", opn
, fregnames
[fd
], fregnames
[fr
],
7551 fregnames
[fs
], fregnames
[ft
]);
7554 /* ISA extensions (ASEs) */
7555 /* MIPS16 extension to MIPS32 */
7556 /* SmartMIPS extension to MIPS32 */
7558 #if defined(TARGET_MIPS64)
7560 /* MDMX extension to MIPS64 */
7564 static void decode_opc (CPUState
*env
, DisasContext
*ctx
)
7568 uint32_t op
, op1
, op2
;
7571 /* make sure instructions are on a word boundary */
7572 if (ctx
->pc
& 0x3) {
7573 env
->CP0_BadVAddr
= ctx
->pc
;
7574 generate_exception(ctx
, EXCP_AdEL
);
7578 /* Handle blikely not taken case */
7579 if ((ctx
->hflags
& MIPS_HFLAG_BMASK
) == MIPS_HFLAG_BL
) {
7580 int l1
= gen_new_label();
7582 MIPS_DEBUG("blikely condition (" TARGET_FMT_lx
")", ctx
->pc
+ 4);
7583 tcg_gen_brcondi_i32(TCG_COND_NE
, bcond
, 0, l1
);
7585 TCGv_i32 r_tmp
= tcg_temp_new_i32();
7587 tcg_gen_movi_i32(r_tmp
, ctx
->hflags
& ~MIPS_HFLAG_BMASK
);
7588 tcg_gen_st_i32(r_tmp
, cpu_env
, offsetof(CPUState
, hflags
));
7589 tcg_temp_free_i32(r_tmp
);
7591 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
7594 op
= MASK_OP_MAJOR(ctx
->opcode
);
7595 rs
= (ctx
->opcode
>> 21) & 0x1f;
7596 rt
= (ctx
->opcode
>> 16) & 0x1f;
7597 rd
= (ctx
->opcode
>> 11) & 0x1f;
7598 sa
= (ctx
->opcode
>> 6) & 0x1f;
7599 imm
= (int16_t)ctx
->opcode
;
7602 op1
= MASK_SPECIAL(ctx
->opcode
);
7604 case OPC_SLL
: /* Arithmetic with immediate */
7605 case OPC_SRL
... OPC_SRA
:
7606 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7608 case OPC_MOVZ
... OPC_MOVN
:
7609 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7610 case OPC_SLLV
: /* Arithmetic */
7611 case OPC_SRLV
... OPC_SRAV
:
7612 case OPC_ADD
... OPC_NOR
:
7613 case OPC_SLT
... OPC_SLTU
:
7614 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7616 case OPC_MULT
... OPC_DIVU
:
7618 check_insn(env
, ctx
, INSN_VR54XX
);
7619 op1
= MASK_MUL_VR54XX(ctx
->opcode
);
7620 gen_mul_vr54xx(ctx
, op1
, rd
, rs
, rt
);
7622 gen_muldiv(ctx
, op1
, rs
, rt
);
7624 case OPC_JR
... OPC_JALR
:
7625 gen_compute_branch(ctx
, op1
, rs
, rd
, sa
);
7627 case OPC_TGE
... OPC_TEQ
: /* Traps */
7629 gen_trap(ctx
, op1
, rs
, rt
, -1);
7631 case OPC_MFHI
: /* Move from HI/LO */
7633 gen_HILO(ctx
, op1
, rd
);
7636 case OPC_MTLO
: /* Move to HI/LO */
7637 gen_HILO(ctx
, op1
, rs
);
7639 case OPC_PMON
: /* Pmon entry point, also R4010 selsl */
7640 #ifdef MIPS_STRICT_STANDARD
7641 MIPS_INVAL("PMON / selsl");
7642 generate_exception(ctx
, EXCP_RI
);
7644 gen_helper_0i(pmon
, sa
);
7648 generate_exception(ctx
, EXCP_SYSCALL
);
7651 generate_exception(ctx
, EXCP_BREAK
);
7654 #ifdef MIPS_STRICT_STANDARD
7656 generate_exception(ctx
, EXCP_RI
);
7658 /* Implemented as RI exception for now. */
7659 MIPS_INVAL("spim (unofficial)");
7660 generate_exception(ctx
, EXCP_RI
);
7668 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7669 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7670 save_cpu_state(ctx
, 1);
7671 check_cp1_enabled(ctx
);
7672 gen_movci(ctx
, rd
, rs
, (ctx
->opcode
>> 18) & 0x7,
7673 (ctx
->opcode
>> 16) & 1);
7675 generate_exception_err(ctx
, EXCP_CpU
, 1);
7679 #if defined(TARGET_MIPS64)
7680 /* MIPS64 specific opcodes */
7682 case OPC_DSRL
... OPC_DSRA
:
7684 case OPC_DSRL32
... OPC_DSRA32
:
7685 check_insn(env
, ctx
, ISA_MIPS3
);
7687 gen_arith_imm(env
, ctx
, op1
, rd
, rt
, sa
);
7690 case OPC_DSRLV
... OPC_DSRAV
:
7691 case OPC_DADD
... OPC_DSUBU
:
7692 check_insn(env
, ctx
, ISA_MIPS3
);
7694 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7696 case OPC_DMULT
... OPC_DDIVU
:
7697 check_insn(env
, ctx
, ISA_MIPS3
);
7699 gen_muldiv(ctx
, op1
, rs
, rt
);
7702 default: /* Invalid */
7703 MIPS_INVAL("special");
7704 generate_exception(ctx
, EXCP_RI
);
7709 op1
= MASK_SPECIAL2(ctx
->opcode
);
7711 case OPC_MADD
... OPC_MADDU
: /* Multiply and add/sub */
7712 case OPC_MSUB
... OPC_MSUBU
:
7713 check_insn(env
, ctx
, ISA_MIPS32
);
7714 gen_muldiv(ctx
, op1
, rs
, rt
);
7717 gen_arith(env
, ctx
, op1
, rd
, rs
, rt
);
7719 case OPC_CLZ
... OPC_CLO
:
7720 check_insn(env
, ctx
, ISA_MIPS32
);
7721 gen_cl(ctx
, op1
, rd
, rs
);
7724 /* XXX: not clear which exception should be raised
7725 * when in debug mode...
7727 check_insn(env
, ctx
, ISA_MIPS32
);
7728 if (!(ctx
->hflags
& MIPS_HFLAG_DM
)) {
7729 generate_exception(ctx
, EXCP_DBp
);
7731 generate_exception(ctx
, EXCP_DBp
);
7735 #if defined(TARGET_MIPS64)
7736 case OPC_DCLZ
... OPC_DCLO
:
7737 check_insn(env
, ctx
, ISA_MIPS64
);
7739 gen_cl(ctx
, op1
, rd
, rs
);
7742 default: /* Invalid */
7743 MIPS_INVAL("special2");
7744 generate_exception(ctx
, EXCP_RI
);
7749 op1
= MASK_SPECIAL3(ctx
->opcode
);
7753 check_insn(env
, ctx
, ISA_MIPS32R2
);
7754 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7757 check_insn(env
, ctx
, ISA_MIPS32R2
);
7758 op2
= MASK_BSHFL(ctx
->opcode
);
7759 gen_bshfl(ctx
, op2
, rt
, rd
);
7762 check_insn(env
, ctx
, ISA_MIPS32R2
);
7764 TCGv t0
= tcg_temp_local_new();
7768 save_cpu_state(ctx
, 1);
7769 gen_helper_rdhwr_cpunum(t0
);
7772 save_cpu_state(ctx
, 1);
7773 gen_helper_rdhwr_synci_step(t0
);
7776 save_cpu_state(ctx
, 1);
7777 gen_helper_rdhwr_cc(t0
);
7780 save_cpu_state(ctx
, 1);
7781 gen_helper_rdhwr_ccres(t0
);
7784 #if defined(CONFIG_USER_ONLY)
7785 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, tls_value
));
7788 /* XXX: Some CPUs implement this in hardware.
7789 Not supported yet. */
7791 default: /* Invalid */
7792 MIPS_INVAL("rdhwr");
7793 generate_exception(ctx
, EXCP_RI
);
7796 gen_store_gpr(t0
, rt
);
7801 check_insn(env
, ctx
, ASE_MT
);
7803 TCGv t0
= tcg_temp_local_new();
7804 TCGv t1
= tcg_temp_local_new();
7806 gen_load_gpr(t0
, rt
);
7807 gen_load_gpr(t1
, rs
);
7808 gen_helper_fork(t0
, t1
);
7814 check_insn(env
, ctx
, ASE_MT
);
7816 TCGv t0
= tcg_temp_local_new();
7818 gen_load_gpr(t0
, rs
);
7819 gen_helper_yield(t0
, t0
);
7820 gen_store_gpr(t0
, rd
);
7824 #if defined(TARGET_MIPS64)
7825 case OPC_DEXTM
... OPC_DEXT
:
7826 case OPC_DINSM
... OPC_DINS
:
7827 check_insn(env
, ctx
, ISA_MIPS64R2
);
7829 gen_bitops(ctx
, op1
, rt
, rs
, sa
, rd
);
7832 check_insn(env
, ctx
, ISA_MIPS64R2
);
7834 op2
= MASK_DBSHFL(ctx
->opcode
);
7835 gen_bshfl(ctx
, op2
, rt
, rd
);
7838 default: /* Invalid */
7839 MIPS_INVAL("special3");
7840 generate_exception(ctx
, EXCP_RI
);
7845 op1
= MASK_REGIMM(ctx
->opcode
);
7847 case OPC_BLTZ
... OPC_BGEZL
: /* REGIMM branches */
7848 case OPC_BLTZAL
... OPC_BGEZALL
:
7849 gen_compute_branch(ctx
, op1
, rs
, -1, imm
<< 2);
7851 case OPC_TGEI
... OPC_TEQI
: /* REGIMM traps */
7853 gen_trap(ctx
, op1
, rs
, -1, imm
);
7856 check_insn(env
, ctx
, ISA_MIPS32R2
);
7859 default: /* Invalid */
7860 MIPS_INVAL("regimm");
7861 generate_exception(ctx
, EXCP_RI
);
7866 check_cp0_enabled(ctx
);
7867 op1
= MASK_CP0(ctx
->opcode
);
7873 #if defined(TARGET_MIPS64)
7877 #ifndef CONFIG_USER_ONLY
7878 gen_cp0(env
, ctx
, op1
, rt
, rd
);
7879 #endif /* !CONFIG_USER_ONLY */
7881 case OPC_C0_FIRST
... OPC_C0_LAST
:
7882 #ifndef CONFIG_USER_ONLY
7883 gen_cp0(env
, ctx
, MASK_C0(ctx
->opcode
), rt
, rd
);
7884 #endif /* !CONFIG_USER_ONLY */
7887 #ifndef CONFIG_USER_ONLY
7889 TCGv t0
= tcg_temp_local_new();
7891 op2
= MASK_MFMC0(ctx
->opcode
);
7894 check_insn(env
, ctx
, ASE_MT
);
7895 gen_helper_dmt(t0
, t0
);
7898 check_insn(env
, ctx
, ASE_MT
);
7899 gen_helper_emt(t0
, t0
);
7902 check_insn(env
, ctx
, ASE_MT
);
7903 gen_helper_dvpe(t0
, t0
);
7906 check_insn(env
, ctx
, ASE_MT
);
7907 gen_helper_evpe(t0
, t0
);
7910 check_insn(env
, ctx
, ISA_MIPS32R2
);
7911 save_cpu_state(ctx
, 1);
7913 /* Stop translation as we may have switched the execution mode */
7914 ctx
->bstate
= BS_STOP
;
7917 check_insn(env
, ctx
, ISA_MIPS32R2
);
7918 save_cpu_state(ctx
, 1);
7920 /* Stop translation as we may have switched the execution mode */
7921 ctx
->bstate
= BS_STOP
;
7923 default: /* Invalid */
7924 MIPS_INVAL("mfmc0");
7925 generate_exception(ctx
, EXCP_RI
);
7928 gen_store_gpr(t0
, rt
);
7931 #endif /* !CONFIG_USER_ONLY */
7934 check_insn(env
, ctx
, ISA_MIPS32R2
);
7935 gen_load_srsgpr(rt
, rd
);
7938 check_insn(env
, ctx
, ISA_MIPS32R2
);
7939 gen_store_srsgpr(rt
, rd
);
7943 generate_exception(ctx
, EXCP_RI
);
7947 case OPC_ADDI
... OPC_LUI
: /* Arithmetic with immediate opcode */
7948 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
7950 case OPC_J
... OPC_JAL
: /* Jump */
7951 offset
= (int32_t)(ctx
->opcode
& 0x3FFFFFF) << 2;
7952 gen_compute_branch(ctx
, op
, rs
, rt
, offset
);
7954 case OPC_BEQ
... OPC_BGTZ
: /* Branch */
7955 case OPC_BEQL
... OPC_BGTZL
:
7956 gen_compute_branch(ctx
, op
, rs
, rt
, imm
<< 2);
7958 case OPC_LB
... OPC_LWR
: /* Load and stores */
7959 case OPC_SB
... OPC_SW
:
7963 gen_ldst(ctx
, op
, rt
, rs
, imm
);
7966 check_insn(env
, ctx
, ISA_MIPS3
| ISA_MIPS32
);
7970 check_insn(env
, ctx
, ISA_MIPS4
| ISA_MIPS32
);
7974 /* Floating point (COP1). */
7979 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7980 save_cpu_state(ctx
, 1);
7981 check_cp1_enabled(ctx
);
7982 gen_flt_ldst(ctx
, op
, rt
, rs
, imm
);
7984 generate_exception_err(ctx
, EXCP_CpU
, 1);
7989 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
7990 save_cpu_state(ctx
, 1);
7991 check_cp1_enabled(ctx
);
7992 op1
= MASK_CP1(ctx
->opcode
);
7996 check_insn(env
, ctx
, ISA_MIPS32R2
);
8001 gen_cp1(ctx
, op1
, rt
, rd
);
8003 #if defined(TARGET_MIPS64)
8006 check_insn(env
, ctx
, ISA_MIPS3
);
8007 gen_cp1(ctx
, op1
, rt
, rd
);
8013 check_insn(env
, ctx
, ASE_MIPS3D
);
8016 gen_compute_branch1(env
, ctx
, MASK_BC1(ctx
->opcode
),
8017 (rt
>> 2) & 0x7, imm
<< 2);
8024 gen_farith(ctx
, MASK_CP1_FUNC(ctx
->opcode
), rt
, rd
, sa
,
8029 generate_exception (ctx
, EXCP_RI
);
8033 generate_exception_err(ctx
, EXCP_CpU
, 1);
8043 /* COP2: Not implemented. */
8044 generate_exception_err(ctx
, EXCP_CpU
, 2);
8048 if (env
->CP0_Config1
& (1 << CP0C1_FP
)) {
8049 save_cpu_state(ctx
, 1);
8050 check_cp1_enabled(ctx
);
8051 op1
= MASK_CP3(ctx
->opcode
);
8059 gen_flt3_ldst(ctx
, op1
, sa
, rd
, rs
, rt
);
8077 gen_flt3_arith(ctx
, op1
, sa
, rs
, rd
, rt
);
8081 generate_exception (ctx
, EXCP_RI
);
8085 generate_exception_err(ctx
, EXCP_CpU
, 1);
8089 #if defined(TARGET_MIPS64)
8090 /* MIPS64 opcodes */
8092 case OPC_LDL
... OPC_LDR
:
8093 case OPC_SDL
... OPC_SDR
:
8098 check_insn(env
, ctx
, ISA_MIPS3
);
8100 gen_ldst(ctx
, op
, rt
, rs
, imm
);
8102 case OPC_DADDI
... OPC_DADDIU
:
8103 check_insn(env
, ctx
, ISA_MIPS3
);
8105 gen_arith_imm(env
, ctx
, op
, rt
, rs
, imm
);
8109 check_insn(env
, ctx
, ASE_MIPS16
);
8110 /* MIPS16: Not implemented. */
8112 check_insn(env
, ctx
, ASE_MDMX
);
8113 /* MDMX: Not implemented. */
8114 default: /* Invalid */
8115 MIPS_INVAL("major opcode");
8116 generate_exception(ctx
, EXCP_RI
);
8119 if (ctx
->hflags
& MIPS_HFLAG_BMASK
) {
8120 int hflags
= ctx
->hflags
& MIPS_HFLAG_BMASK
;
8121 /* Branches completion */
8122 ctx
->hflags
&= ~MIPS_HFLAG_BMASK
;
8123 ctx
->bstate
= BS_BRANCH
;
8124 save_cpu_state(ctx
, 0);
8125 /* FIXME: Need to clear can_do_io. */
8128 /* unconditional branch */
8129 MIPS_DEBUG("unconditional branch");
8130 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8133 /* blikely taken case */
8134 MIPS_DEBUG("blikely branch taken");
8135 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8138 /* Conditional branch */
8139 MIPS_DEBUG("conditional branch");
8141 int l1
= gen_new_label();
8143 tcg_gen_brcondi_i32(TCG_COND_NE
, bcond
, 0, l1
);
8144 gen_goto_tb(ctx
, 1, ctx
->pc
+ 4);
8146 gen_goto_tb(ctx
, 0, ctx
->btarget
);
8150 /* unconditional branch to register */
8151 MIPS_DEBUG("branch to register");
8152 tcg_gen_mov_tl(cpu_PC
, btarget
);
8156 MIPS_DEBUG("unknown branch");
8163 gen_intermediate_code_internal (CPUState
*env
, TranslationBlock
*tb
,
8167 target_ulong pc_start
;
8168 uint16_t *gen_opc_end
;
8175 qemu_log("search pc %d\n", search_pc
);
8178 /* Leave some spare opc slots for branch handling. */
8179 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
- 16;
8183 ctx
.bstate
= BS_NONE
;
8184 /* Restore delay slot state from the tb context. */
8185 ctx
.hflags
= (uint32_t)tb
->flags
; /* FIXME: maybe use 64 bits here? */
8186 restore_cpu_state(env
, &ctx
);
8187 #ifdef CONFIG_USER_ONLY
8188 ctx
.mem_idx
= MIPS_HFLAG_UM
;
8190 ctx
.mem_idx
= ctx
.hflags
& MIPS_HFLAG_KSU
;
8193 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8195 max_insns
= CF_COUNT_MASK
;
8197 qemu_log_mask(CPU_LOG_TB_CPU
, "------------------------------------------------\n");
8198 /* FIXME: This may print out stale hflags from env... */
8199 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
8201 LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb
, ctx
.mem_idx
, ctx
.hflags
);
8203 while (ctx
.bstate
== BS_NONE
) {
8204 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
8205 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8206 if (bp
->pc
== ctx
.pc
) {
8207 save_cpu_state(&ctx
, 1);
8208 ctx
.bstate
= BS_BRANCH
;
8209 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8210 /* Include the breakpoint location or the tb won't
8211 * be flushed when it must be. */
8213 goto done_generating
;
8219 j
= gen_opc_ptr
- gen_opc_buf
;
8223 gen_opc_instr_start
[lj
++] = 0;
8225 gen_opc_pc
[lj
] = ctx
.pc
;
8226 gen_opc_hflags
[lj
] = ctx
.hflags
& MIPS_HFLAG_BMASK
;
8227 gen_opc_instr_start
[lj
] = 1;
8228 gen_opc_icount
[lj
] = num_insns
;
8230 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8232 ctx
.opcode
= ldl_code(ctx
.pc
);
8233 decode_opc(env
, &ctx
);
8237 if (env
->singlestep_enabled
)
8240 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
8243 if (gen_opc_ptr
>= gen_opc_end
)
8246 if (num_insns
>= max_insns
)
8248 #if defined (MIPS_SINGLE_STEP)
8252 if (tb
->cflags
& CF_LAST_IO
)
8254 if (env
->singlestep_enabled
) {
8255 save_cpu_state(&ctx
, ctx
.bstate
== BS_NONE
);
8256 gen_helper_0i(raise_exception
, EXCP_DEBUG
);
8258 switch (ctx
.bstate
) {
8260 gen_helper_interrupt_restart();
8261 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8264 save_cpu_state(&ctx
, 0);
8265 gen_goto_tb(&ctx
, 0, ctx
.pc
);
8268 gen_helper_interrupt_restart();
8277 gen_icount_end(tb
, num_insns
);
8278 *gen_opc_ptr
= INDEX_op_end
;
8280 j
= gen_opc_ptr
- gen_opc_buf
;
8283 gen_opc_instr_start
[lj
++] = 0;
8285 tb
->size
= ctx
.pc
- pc_start
;
8286 tb
->icount
= num_insns
;
8290 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
8291 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
8292 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 0);
8295 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- %d %08x\n", ctx
.bstate
, ctx
.hflags
);
8299 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8301 gen_intermediate_code_internal(env
, tb
, 0);
8304 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8306 gen_intermediate_code_internal(env
, tb
, 1);
8309 static void fpu_dump_state(CPUState
*env
, FILE *f
,
8310 int (*fpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8314 int is_fpu64
= !!(env
->hflags
& MIPS_HFLAG_F64
);
8316 #define printfpr(fp) \
8319 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu: %13g\n", \
8320 (fp)->w[FP_ENDIAN_IDX], (fp)->d, (fp)->fd, \
8321 (fp)->fs[FP_ENDIAN_IDX], (fp)->fs[!FP_ENDIAN_IDX]); \
8324 tmp.w[FP_ENDIAN_IDX] = (fp)->w[FP_ENDIAN_IDX]; \
8325 tmp.w[!FP_ENDIAN_IDX] = ((fp) + 1)->w[FP_ENDIAN_IDX]; \
8326 fpu_fprintf(f, "w:%08x d:%016lx fd:%13g fs:%13g psu:%13g\n", \
8327 tmp.w[FP_ENDIAN_IDX], tmp.d, tmp.fd, \
8328 tmp.fs[FP_ENDIAN_IDX], tmp.fs[!FP_ENDIAN_IDX]); \
8333 fpu_fprintf(f
, "CP1 FCR0 0x%08x FCR31 0x%08x SR.FR %d fp_status 0x%08x(0x%02x)\n",
8334 env
->active_fpu
.fcr0
, env
->active_fpu
.fcr31
, is_fpu64
, env
->active_fpu
.fp_status
,
8335 get_float_exception_flags(&env
->active_fpu
.fp_status
));
8336 for (i
= 0; i
< 32; (is_fpu64
) ? i
++ : (i
+= 2)) {
8337 fpu_fprintf(f
, "%3s: ", fregnames
[i
]);
8338 printfpr(&env
->active_fpu
.fpr
[i
]);
8344 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8345 /* Debug help: The architecture requires 32bit code to maintain proper
8346 sign-extended values on 64bit machines. */
8348 #define SIGN_EXT_P(val) ((((val) & ~0x7fffffff) == 0) || (((val) & ~0x7fffffff) == ~0x7fffffff))
8351 cpu_mips_check_sign_extensions (CPUState
*env
, FILE *f
,
8352 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8357 if (!SIGN_EXT_P(env
->active_tc
.PC
))
8358 cpu_fprintf(f
, "BROKEN: pc=0x" TARGET_FMT_lx
"\n", env
->active_tc
.PC
);
8359 if (!SIGN_EXT_P(env
->active_tc
.HI
[0]))
8360 cpu_fprintf(f
, "BROKEN: HI=0x" TARGET_FMT_lx
"\n", env
->active_tc
.HI
[0]);
8361 if (!SIGN_EXT_P(env
->active_tc
.LO
[0]))
8362 cpu_fprintf(f
, "BROKEN: LO=0x" TARGET_FMT_lx
"\n", env
->active_tc
.LO
[0]);
8363 if (!SIGN_EXT_P(env
->btarget
))
8364 cpu_fprintf(f
, "BROKEN: btarget=0x" TARGET_FMT_lx
"\n", env
->btarget
);
8366 for (i
= 0; i
< 32; i
++) {
8367 if (!SIGN_EXT_P(env
->active_tc
.gpr
[i
]))
8368 cpu_fprintf(f
, "BROKEN: %s=0x" TARGET_FMT_lx
"\n", regnames
[i
], env
->active_tc
.gpr
[i
]);
8371 if (!SIGN_EXT_P(env
->CP0_EPC
))
8372 cpu_fprintf(f
, "BROKEN: EPC=0x" TARGET_FMT_lx
"\n", env
->CP0_EPC
);
8373 if (!SIGN_EXT_P(env
->CP0_LLAddr
))
8374 cpu_fprintf(f
, "BROKEN: LLAddr=0x" TARGET_FMT_lx
"\n", env
->CP0_LLAddr
);
8378 void cpu_dump_state (CPUState
*env
, FILE *f
,
8379 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8384 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",
8385 env
->active_tc
.PC
, env
->active_tc
.HI
[0], env
->active_tc
.LO
[0],
8386 env
->hflags
, env
->btarget
, env
->bcond
);
8387 for (i
= 0; i
< 32; i
++) {
8389 cpu_fprintf(f
, "GPR%02d:", i
);
8390 cpu_fprintf(f
, " %s " TARGET_FMT_lx
, regnames
[i
], env
->active_tc
.gpr
[i
]);
8392 cpu_fprintf(f
, "\n");
8395 cpu_fprintf(f
, "CP0 Status 0x%08x Cause 0x%08x EPC 0x" TARGET_FMT_lx
"\n",
8396 env
->CP0_Status
, env
->CP0_Cause
, env
->CP0_EPC
);
8397 cpu_fprintf(f
, " Config0 0x%08x Config1 0x%08x LLAddr 0x" TARGET_FMT_lx
"\n",
8398 env
->CP0_Config0
, env
->CP0_Config1
, env
->CP0_LLAddr
);
8399 if (env
->hflags
& MIPS_HFLAG_FPU
)
8400 fpu_dump_state(env
, f
, cpu_fprintf
, flags
);
8401 #if defined(TARGET_MIPS64) && defined(MIPS_DEBUG_SIGN_EXTENSIONS)
8402 cpu_mips_check_sign_extensions(env
, f
, cpu_fprintf
, flags
);
8406 static void mips_tcg_init(void)
8411 /* Initialize various static tables. */
8415 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
8416 for (i
= 0; i
< 32; i
++)
8417 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
8418 offsetof(CPUState
, active_tc
.gpr
[i
]),
8420 cpu_PC
= tcg_global_mem_new(TCG_AREG0
,
8421 offsetof(CPUState
, active_tc
.PC
), "PC");
8422 for (i
= 0; i
< MIPS_DSP_ACC
; i
++) {
8423 cpu_HI
[i
] = tcg_global_mem_new(TCG_AREG0
,
8424 offsetof(CPUState
, active_tc
.HI
[i
]),
8426 cpu_LO
[i
] = tcg_global_mem_new(TCG_AREG0
,
8427 offsetof(CPUState
, active_tc
.LO
[i
]),
8429 cpu_ACX
[i
] = tcg_global_mem_new(TCG_AREG0
,
8430 offsetof(CPUState
, active_tc
.ACX
[i
]),
8433 cpu_dspctrl
= tcg_global_mem_new(TCG_AREG0
,
8434 offsetof(CPUState
, active_tc
.DSPControl
),
8436 bcond
= tcg_global_mem_new_i32(TCG_AREG0
,
8437 offsetof(CPUState
, bcond
), "bcond");
8438 btarget
= tcg_global_mem_new(TCG_AREG0
,
8439 offsetof(CPUState
, btarget
), "btarget");
8440 for (i
= 0; i
< 32; i
++)
8441 fpu_fpr32
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
8442 offsetof(CPUState
, active_fpu
.fpr
[i
].w
[FP_ENDIAN_IDX
]),
8444 for (i
= 0; i
< 32; i
++)
8445 fpu_fpr64
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
8446 offsetof(CPUState
, active_fpu
.fpr
[i
]),
8448 for (i
= 0; i
< 32; i
++)
8449 fpu_fpr32h
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
8450 offsetof(CPUState
, active_fpu
.fpr
[i
].w
[!FP_ENDIAN_IDX
]),
8452 fpu_fcr0
= tcg_global_mem_new_i32(TCG_AREG0
,
8453 offsetof(CPUState
, active_fpu
.fcr0
),
8455 fpu_fcr31
= tcg_global_mem_new_i32(TCG_AREG0
,
8456 offsetof(CPUState
, active_fpu
.fcr31
),
8459 /* register helpers */
8460 #define GEN_HELPER 2
8466 #include "translate_init.c"
8468 CPUMIPSState
*cpu_mips_init (const char *cpu_model
)
8471 const mips_def_t
*def
;
8473 def
= cpu_mips_find_by_name(cpu_model
);
8476 env
= qemu_mallocz(sizeof(CPUMIPSState
));
8477 env
->cpu_model
= def
;
8480 env
->cpu_model_str
= cpu_model
;
8486 void cpu_reset (CPUMIPSState
*env
)
8488 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
8489 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
8490 log_cpu_state(env
, 0);
8493 memset(env
, 0, offsetof(CPUMIPSState
, breakpoints
));
8498 #if defined(CONFIG_USER_ONLY)
8499 env
->hflags
= MIPS_HFLAG_UM
;
8501 if (env
->hflags
& MIPS_HFLAG_BMASK
) {
8502 /* If the exception was raised from a delay slot,
8503 come back to the jump. */
8504 env
->CP0_ErrorEPC
= env
->active_tc
.PC
- 4;
8506 env
->CP0_ErrorEPC
= env
->active_tc
.PC
;
8508 env
->active_tc
.PC
= (int32_t)0xBFC00000;
8510 /* SMP not implemented */
8511 env
->CP0_EBase
= 0x80000000;
8512 env
->CP0_Status
= (1 << CP0St_BEV
) | (1 << CP0St_ERL
);
8513 /* vectored interrupts not implemented, timer on int 7,
8514 no performance counters. */
8515 env
->CP0_IntCtl
= 0xe0000000;
8519 for (i
= 0; i
< 7; i
++) {
8520 env
->CP0_WatchLo
[i
] = 0;
8521 env
->CP0_WatchHi
[i
] = 0x80000000;
8523 env
->CP0_WatchLo
[7] = 0;
8524 env
->CP0_WatchHi
[7] = 0;
8526 /* Count register increments in debug mode, EJTAG version 1 */
8527 env
->CP0_Debug
= (1 << CP0DB_CNT
) | (0x1 << CP0DB_VER
);
8528 env
->hflags
= MIPS_HFLAG_CP0
;
8530 env
->exception_index
= EXCP_NONE
;
8531 cpu_mips_register(env
, env
->cpu_model
);
8534 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8535 unsigned long searched_pc
, int pc_pos
, void *puc
)
8537 env
->active_tc
.PC
= gen_opc_pc
[pc_pos
];
8538 env
->hflags
&= ~MIPS_HFLAG_BMASK
;
8539 env
->hflags
|= gen_opc_hflags
[pc_pos
];